Example #1
0
 /**
  * Widget callback for template vars.
  *
  * This allows to replace template vars, see {@link Widget::replace_callback()}.
  *
  * @return string
  */
 function replace_callback($matches)
 {
     // echo '['.$matches[1].']';
     switch ($matches[1]) {
         case 'start':
             return ($this->page - 1) * $this->limit + 1;
         case 'end':
             return min($this->total_rows, $this->page * $this->limit);
         case 'total_rows':
             //total number of rows in the sql query
             return $this->total_rows;
         case 'page':
             //current page number
             return $this->page;
         case 'total_pages':
             //total number of pages
             return $this->total_pages;
         case 'prev':
             // inits the link to previous page
             if ($this->page <= 1) {
                 return $this->params['no_prev_text'];
             }
             $r = '<a href="' . regenerate_url($this->page_param, $this->page > 2 ? $this->page_param . '=' . ($this->page - 1) : '', $this->params['page_url']) . '"';
             if ($this->nofollow_pagenav) {
                 // We want to NOFOLLOW page navigation
                 $r .= ' rel="nofollow"';
             }
             $r .= '>' . $this->params['prev_text'] . '</a>';
             return $r;
         case 'next':
             // inits the link to next page
             if ($this->page >= $this->total_pages) {
                 return $this->params['no_next_text'];
             }
             $r = '<a href="' . regenerate_url($this->page_param, $this->page_param . '=' . ($this->page + 1), $this->params['page_url']) . '"';
             if ($this->nofollow_pagenav) {
                 // We want to NOFOLLOW page navigation
                 $r .= ' rel="nofollow"';
             }
             $r .= '>' . $this->params['next_text'] . '</a>';
             return $r;
         case 'list':
             //inits the page list
             return $this->page_list($this->first(), $this->last(), $this->params['page_url']);
         case 'scroll_list':
             //inits the scrolling list of pages
             return $this->page_scroll_list();
         case 'first':
             //inits the link to first page
             return $this->display_first($this->params['page_url']);
         case 'last':
             //inits the link to last page
             return $this->display_last($this->params['page_url']);
         case 'list_prev':
             //inits the link to previous page range
             return $this->display_prev($this->params['page_url']);
         case 'list_next':
             //inits the link to next page range
             return $this->display_next($this->params['page_url']);
         default:
             return parent::replace_callback($matches);
     }
 }
Example #2
0
 /**
  * Widget callback for template vars.
  *
  * This allows to replace template vars, see {@link Widget::replace_callback()}.
  *
  * @return string
  */
 function replace_callback($matches)
 {
     // echo '['.$matches[1].']';
     switch ($matches[1]) {
         case 'start':
             return ($this->page - 1) * $this->limit + 1;
         case 'end':
             return min($this->total_rows, $this->page * $this->limit);
         case 'total_rows':
             //total number of rows in the sql query
             return $this->total_rows;
         case 'page':
             //current page number
             return $this->page;
         case 'total_pages':
             //total number of pages
             return $this->total_pages;
         case 'prev':
             // inits the link to previous page
             if ($this->page <= 1) {
                 return $this->params['no_prev_text'];
             }
             $r = '';
             if (isset($this->params['page_item_before'])) {
                 $r .= $this->params['page_item_before'];
             }
             $r .= '<a href="' . regenerate_url($this->page_param, $this->page > 2 ? $this->page_param . '=' . ($this->page - 1) : '', $this->params['page_url']) . '"';
             $attr_rel = array();
             if ($this->nofollow_pagenav) {
                 // We want to NOFOLLOW page navigation
                 $attr_rel[] = 'nofollow';
             }
             // Add attribute rel="prev" for previous page
             $attr_rel[] = 'prev';
             if (!empty($attr_rel)) {
                 $r .= ' rel="' . implode(' ', $attr_rel) . '"';
             }
             if (!empty($this->params['prev_class'])) {
                 // Add "class" for prev link
                 $r .= ' class="' . $this->params['prev_class'] . '"';
             }
             $r .= '>' . $this->params['prev_text'] . '</a>';
             if (isset($this->params['page_item_after'])) {
                 $r .= $this->params['page_item_after'];
             }
             return $r;
         case 'next':
             // inits the link to next page
             if ($this->page >= $this->total_pages) {
                 return $this->params['no_next_text'];
             }
             $r = '';
             if (isset($this->params['page_item_before'])) {
                 $r .= $this->params['page_item_before'];
             }
             $r .= '<a href="' . regenerate_url($this->page_param, $this->page_param . '=' . ($this->page + 1), $this->params['page_url']) . '"';
             $attr_rel = array();
             if ($this->nofollow_pagenav) {
                 // We want to NOFOLLOW page navigation
                 $attr_rel[] = 'nofollow';
             }
             // Add attribute rel="next" for next page
             $attr_rel[] = 'next';
             if (!empty($attr_rel)) {
                 $r .= ' rel="' . implode(' ', $attr_rel) . '"';
             }
             if (!empty($this->params['next_class'])) {
                 // Add "class" for prev link
                 $r .= ' class="' . $this->params['next_class'] . '"';
             }
             $r .= '>' . $this->params['next_text'] . '</a>';
             if (isset($this->params['page_item_after'])) {
                 $r .= $this->params['page_item_after'];
             }
             return $r;
         case 'list':
             //inits the page list
             return $this->page_list($this->first(), $this->last(), $this->params['page_url']);
         case 'scroll_list':
             //inits the scrolling list of pages
             return $this->page_scroll_list();
         case 'first':
             //inits the link to first page
             return $this->display_first($this->params['page_url']);
         case 'last':
             //inits the link to last page
             return $this->display_last($this->params['page_url']);
         case 'list_prev':
             //inits the link to previous page range
             return $this->display_prev($this->params['page_url']);
         case 'list_next':
             //inits the link to next page range
             return $this->display_next($this->params['page_url']);
         case 'page_size':
             //inits the list to select page size
             return $this->display_page_size($this->params['page_url']);
         case 'prefix':
             //prefix
             return $this->param_prefix;
         default:
             return parent::replace_callback($matches);
     }
 }