http://www.kjetil-hartveit.com * @version 1.2 */ class PageLister { protected $allItems = array(); protected $page = 1; protected $pageList = array(); /** * Default options * * @var array */ protected $opts = array( 'itemsPerPage' => 5, 'urlFormat' => '%d', 'customFormatting' => false, 'urlCallback' => null, 'urlCallbackArgs' => array(), 'varPage' => '{pagenum}', 'pageLabels' => array(), 'prevAndNext' => true, 'prev' => '«', 'next' => '»' ); /** *
* Note that you can only use either normal url formatting, custom formatting or * callback formatting. Presedence order is: callback, custom formatting, normal formatting. *
* *Type | *Option | *Default | *Description | *
---|---|---|---|
string | *itemsPerPage | *5 | *Number of items shown per page | *
string | *urlFormat | *%d | *
* Here you can choose the format of the url. A replacement value for the pagenumber is
* required. The syntax of the replacement value and how to set it depends on different
* options. * If the customFormatting option is set then the value of varPage is used. * If the urlCallback option is set then at least one of the callback arguments must * contain the value of varPage. * Lastly if neither of the mentioned options are set then urlFormat uses the sprintf * argument syntax (ie. %d). * |
*
boolean | *customFormatting | *false | ** With custom formatting enabled you can define your own syntax for the pagenumber format. * This is handy in case your url format accidently includes format arguments * (like url characters encoded in utf-8) and which collides with the pagenumber argument. * | *
string|array | *urlCallback | *null | ** If a callback is given then the pageurl will be formatted based on the result of this * callback. * | *
array | *urlCallbackArgs | *array() | *
* If the urlCallback option is set then you can specify additional callback arguments
* with this option. * At least one of the callback arguments should contain the varPage value so the * corresponding pagenumber can be injected into the callback. * |
*
string | *varPage | *{pagenum} | *
* The value of this option will be replaced by the pagenumber in numerous settings. * It will be used when the option customFormatting is set, as well as when * a urlCallback is set. In the latter case then one of the callback arguments * should contain this value. * |
*
array | *pageLabels | *array() | *Each individual page can be given a specific page label with this option. Each key in the array is the pagenumber and the value is the page label. | *
boolean | *prevAndNext | *true | *Whether or not to include the "previous" and "next" items in the page list | *
string | *prev | *« | *The text shown as "previous page" | *
string | *next | *» | *The text shown as "next page" | *
The page list is an associative array consisting of the following key pairs:
*Type | *Key | *Value | *
---|---|---|
string | *url | *The formatted url for the page. Note that when using the prevAndNext option and there is no valid previous or next page, then the url will be null. This is also the case if a pagelink points to the current page. You can use this info to remove links that the user should not click on. | *
int | *page | *The pagenumber | *
string | *label | *The page label | *