Helpers are similar to plugins: they are separate pieces of code which extend Wolf CMS's functionality. However, helpers are never loaded unless specifically called by an outside piece of code.
They are found in the
To call a single helper, use:
<?php use_helper('Helpername'); ?>
You can call more than one helper at a time by listing them as parameters:
<?php use_helper('Email', 'Pagination', 'Zip'); ?>
The functionality provided by the helper will only be available on the page(s) where it is specifically called by this code.
Helpers currently supplied with Wolf CMS
|BigInteger||Arbitrary precision integer arithmetic library; adapted from phphseclib.|
|Simple Email library that permits email to be sent using Mail, Sendmail, or SMTP.|
|I18n||Simple internationalisation library used by Wolf CMS core for translations.|
|Hash||Keyed-hash message authentication codes; adapted from phphseclib.|
|Kses||HTML/XHTML filter that only allows some elements and attributes.|
|Pagination||Simple Pagination helper based on the CodeIgniter pagination helper.|
|Upload||Simple upload library.|
|Validate||Functions to help validate data of different kinds; based on Kohana 2.x helper.|
|Zip||Simple Zip library that allows creation and downloading of zip files.|
The default pagination helper which comes with Wolf is a light revision of the the Code Igniter pagination helper. It allows multiple pages to be listed as a set of page links in the form:
Pages: 1 2 3 4
The notes that follow explain how to set up Pagination.php for use with the default "Articles" page in Wolf CMS, but can be modified for use with other pages as well. Be aware that for the Set up (#3, below), the code varies depending on whether
mod_rewrite is enabled or disabled.
These instructions assume
mod_rewrite is enabled, with the disabled version given as a variation.
1. Call objects to Paginate
Open the **Articles** page for editing: this is the **only** page used for these instructions. This first thing to do at the top of the page, is call the "page objects" you wish to paginate:
<?php $last_articles = $this->children(array( 'limit'=>5, 'offset'=>($pagination->cur_page)*($pagination->per_page), 'order'=>'page.created_on DESC' )); ?>
Here, note that
limit should be the same value as the
per_page value in the set up of step #3, below. The
offset code is required by the helper to form the links properly, but takes its values from the pagination set up.
2. Loop through the pages
<?php foreach ($last_articles as $article): ?> <div class="entry"> <h3><?php echo $article->link($article->title()); ?></h3> <?php // Whatever else you want to include: teaser? meta? etc. ?> </div><!-- end .entry --> <?php endforeach; ?>
3. Set up helper
At this point, call the helper, and set the options (if this code block is put at the top of the page, the offset will not work properly):
<?php use_helper('Pagination'); $pagination = new Pagination(array( 'base_url' => '/articles?page=', 'total_rows' => $this->childrenCount(), 'per_page' => 5, 'num_links' => 8, 'cur_page' => (isset($_GET['page']) ? $_GET['page']: 1) )); ?>
Only three of those lines might require adjustment:
Include the slug of the current page (in this case, "articles"), which is the parent of the pages you wish to paginate, followed by
?page=. If you have mod_rewrite disabled, then add another "?" after the initial slash:
The number of sub-pages linked on each paginated page.
When this number of page links is exceeded, a "First" and "Last" link will be added to the left and right of the number list.
4. Call pagination links
<?php if ($pagination->total_rows > $pagination->per_page) echo '<p><br />Pages: '.$pagination->createLinks().'</p>'; ?>
You can of course vary the
<br /> markup to suit your layout. Now save the Articles page. Done!
The Upload helper is a way for you to add simple file upload functionality to Wolf CMS.
This helper is still under development, and does not yet work.
The Validate helper is for validating fields. In this example it is used to check for a valid email address:
<form action="<?php echo $this->url(); ?>" method="post"> E-mail: <input type="text" name="email" /> <input name="submit" type="submit" value="Submit" /> </form> <?php use_helper('Validate'); $email = isset($_POST['email']) ? htmlentities($_POST['email'], ENT_QUOTES, "UTF-8") : ''; if(isset($_POST['submit'])): if(Validate::email($email)== true): echo '<h3>Valid e-mail</h3>'; else: echo '<h3>Invalid e-mail!</h3>'; endif; endif; ?>
It also has support for: