soo_page_numbers Page 2 of 2

soo_page_numbers source code

  1 : require_plugin('soo_txp_obj');
  2 : 
  3 : function soo_page_links $atts ) {
  4 : 
  5 :     extract(lAtts(array(
  6 :         'placeholder'   =>  '…',
  7 :         'window_size'   =>  5,
  8 :         'active_class'  =>  'here',
  9 :         'wraptag'       =>  '',
 10 :         'class'         =>  '',
 11 :         'html_id'       =>  '',
 12 :         'break'         =>  '',
 13 :         'showalways'    =>  false,
 14 :     ), $atts));
 15 : 
 16 :     global $thispage;
 17 : 
 18 :     if ( is_array($thispage) ) extract($thispage);
 19 :     else return _soo_page_numbers_secondpass(__FUNCTION__$atts);
 20 : 
 21 :     if ( ! $showalways and $numPages <= ) return;
 22 : 
 23 :     $w_start max(1,
 24 :         min($pg floor($window_size 2), $numPages $window_size 1));
 25 :     $w_end min($w_start $window_size 1$numPages);
 26 : 
 27 :     $pgs array_unique(array_merge(
 28 :         array(1), range($w_start$w_end), array($numPages)
 29 :     ));
 30 : 
 31 :     $break_text $wraptag '' $break;
 32 :     $text_tag = ( $break and $wraptag ) ? '' 'span';
 33 :     $active_class $active_class " class=\"$active_class\"" '';
 34 : 
 35 :     $uri = new soo_uri;
 36 :     while ( $pgs ) {
 37 :         $n array_shift($pgs);
 38 :         $uri->set_query_param('pg', ( $n $n null ));
 39 :         $fill $pgs ? ( $pgs[0] > $n $placeholder $break_text ) : '';
 40 :         if ( $n == $pg )
 41 :             $items[] = $text_tag ?
 42 :                 tag($n$text_tag$active_class) : $n;
 43 :         else
 44 :             $items[] = href($n$uri->full" title='Page $n'");
 45 :         if ( $n $numPages and $fill )
 46 :             $items[] = $text_tag ?
 47 :                 tag($fill$text_tag) : $fill;
 48 :     }
 49 :     $uri->set_query_param('pg', ( $pg $pg null ));
 50 :     if ( isset($items) )
 51 :         return $wraptag str_replace("<$break>$pg<""<$break$active_class>$pg<",
 52 :             doWrap($items$wraptag$break$class''''''$html_id))
 53 :             : implode($break_text '' n$items);
 54 : }
 55 : 
 56 : function soo_page_count $atts ) {
 57 : 
 58 :     extract(lAtts(array(
 59 :         'format'        =>  '{prev} Page {current} of {total} {next}',
 60 :         'prev'          =>  '&laquo;',
 61 :         'next'          =>  '&raquo;',
 62 :         'first'         =>  '|&laquo;',
 63 :         'last'          =>  '&raquo;|',
 64 :         'showalways'    =>  false,
 65 :         'wraptag'       =>  '',
 66 :     ), $atts));
 67 : 
 68 :     global $thispage;
 69 : 
 70 :     if ( is_array($thispage) ) extract($thispage);
 71 :     else return _soo_page_numbers_secondpass(__FUNCTION__$atts);
 72 : 
 73 :     if ( ! $showalways and $numPages <= ) return;
 74 : 
 75 :     $uri = new soo_uri;
 76 :     if ( $pg ) {
 77 :         $uri->set_query_param('pg'null);
 78 :         $first href($first$uri->full' title="Page 1"');
 79 :     }
 80 :     elseif ( ! $showalways )
 81 :         $first '';
 82 : 
 83 :     if ( $pg $numPages ) {
 84 :         $uri->set_query_param('pg'$numPages);
 85 :         $last href($last$uri->full" title='Page $numPages'");
 86 :     }
 87 :     elseif ( ! $showalways )
 88 :         $last '';
 89 : 
 90 :     $prev $pg newer(array(), $prev) :
 91 :         ( $showalways $prev '' );
 92 :     $next $pg $numPages older(array(), $next) :
 93 :         ( $showalways $next '' );
 94 : 
 95 :     $out str_replace(
 96 :         array('{prev}''{next}''{first}''{last}''{current}''{total}'),
 97 :         array($prev$next$first$last$pg$numPages), $format);
 98 :     return $wraptag tag($out$wraptag) : $out;
 99 : }
100 : 
101 : function soo_prev_page $atts ) {
102 :     if ( isset($atts['text']) ) {
103 :         $atts['prev'] = $atts['text'];
104 :         unset($atts['text']);
105 :     }
106 :     $atts['format'] = '{prev}';
107 :     return soo_page_count($atts);
108 : }
109 : 
110 : function soo_next_page $atts ) {
111 :     if ( isset($atts['text']) ) {
112 :         $atts['next'] = $atts['text'];
113 :         unset($atts['text']);
114 :     }
115 :     $atts['format'] = '{next}';
116 :     return soo_page_count($atts);
117 : }
118 : 
119 : function _soo_page_numbers_secondpass $func$atts ) {
120 : // in case $func's associated tag comes before an article tag,
121 : // this runs the tag again during textpattern()'s second parse() pass
122 :     global $pretext;
123 :     if ( $pretext['secondpass'] ) return; // you only live twice
124 :     foreach ( $atts as $k => $v )
125 :         $a[] = $k '="' $v '" ';
126 :     return "<txp:$func " . ( isset($a) ? implode(''$a) : '' ) . '/>';
127 : }