/includes/plugins/function.pager.php
PHP | 66 lines | 47 code | 13 blank | 6 comment | 20 complexity | 3156839f99d2f2f6c2f132e7f3a91b30 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0
- <?php
- function smarty_function_pager($params, &$smarty)
- {
- $startnum = $params['startnum'];
- $numitems = $params['numitems'];
- // Going to be common so let's use it
- $searchphrase = $params['searchphrase'];
- if (!$numitems) {
- return null;
- }
- $max = $params['numitems'];
- $split = $params['limit'];
- $html = "<p><strong>[</strong> ";
- $endpage = ceil($max / $split);
- $page = Eve::VarCleanFromInput('page');
- $qstring = Eve::ServerGetVar('QUERY_STRING');
- $script = Eve::ServerGetVar('SCRIPT_NAME');
- //$script = substr($script, -1, strlen($script));
- if ($page) {
- $url = preg_replace("/&page=([0-9]?[0-9]?[0-9])/", "", $qstring);//return $url;
- if ($url == $qstring) { $url = preg_replace("/page=([0-9]?[0-9]?[0-9])/", "", $qstring); }
- } else {
- $url = $qstring;//urlencode($qstring);
- $page = 1;
- }
- //if (eregi('.html', $url)) {
- //$url = 'a='.Eve::SessionGetVar('kburl');
- //}
- // Fixing damn & for validation
- $url = preg_replace("/&/", "&", $url);
- for ($i = 1; $i <= $endpage; $i++) {
- if ($i != $page) {
- if ($i == 1 || $i == $endpage || (($i >= $page - 1 && $i <= $page + 1))) {
- if ($i != 1) {
- $html .= "<a href=\"".$script."?".$url.((empty($url)) ? "" : "&")."page=".$i.((!empty($searchphrase)) ? "&searchphrase=".urlencode($searchphrase) : "")."\" title=\"Page ".$i."\">".$i."</a> ";
- } else {
- $html .= "<a href=\"".$script."?".$url."\" title=\"Page ".$i."\">".$i."</a> ";
- }
- } elseif ($i < $page && !$dotted) {
- $dotted = true;
- $html .= "<strong>.. </strong>";
- } elseif ($i > $page && !$ldotted) {
- $ldotted = true;
- $html .= "<strong>.. </strong>";
- }
- } else {
- $html .= "<strong>".$i."</strong> ";
- }
- }
- $html .= "<strong>]</strong></p>";
- return $html;
- }
- ?>