Smarty
[ class tree: Smarty ] [ index: Smarty ] [ all elements ]

Source for file function.libertypagination.php

Documentation is available at function.libertypagination.php

  1. <?php
  2. /**
  3.  * Smarty {libertypagination} function plugin
  4.  *
  5.  * This provides a means of paging through longer lists of data using an up and down arrow.
  6.  * In addition, if the 'site_direct_pagination' feature is enabled, then a direct page number can be entered jump directly to
  7.  *
  8.  * Type:     function<br>
  9.  * Name:     libertypagination<br>
  10.  * Input:<br>
  11.  *            - numPages                Number of pages in total<br>
  12.  *            - page                    current page<br>
  13.  *            - pgnName (optional)    parameter name used by script to find page you're on. defaults to page<br>
  14.  *            - ianchor (optional)    set an anchor<br>
  15.  *            - ihash   (optional)    you can pass in all the above as an array called ihash or secondary * items common to all links<br>
  16.  *            The ihash option allow the inclusion of additional link values as provided for smartlink navigation<br>
  17.  * Output:   url of the form: $REQUEST_URI?attribute1=value1&attribute2=value2
  18.  * 
  19.  * @package Smarty
  20.  * @subpackage plugins
  21.  * @link http://www.bitweaver.org/wiki/function_libertypagination function.libertypagination
  22.  */
  23.  
  24. /**
  25.  * Smarty {libertypagination} function plugin
  26.  */
  27. function smarty_function_libertypagination($params, &$gBitSmarty) {
  28.     if( isset( $params['ihash'] ) && is_array( $params['ihash'] ) ) {
  29.         $params = array_merge( $params['ihash'], $params );
  30.         $params['ihash'] = NULL;
  31.     }
  32.  
  33.     if( isset( $params['url'] ) ) {
  34.         $urlParams = '';
  35.         parse_str( preg_replace( "/.*\?/", "", $params['url'] ), $urlParams );
  36.         $params = array_merge( $urlParams, $params );
  37.     }
  38.     $pgnName = isset( $params['pgnName'] ) ? $params['pgnName'] : ( isset( $params['curPage'] ) ? 'curPage' : 'page' );
  39.     $pgnVars = '';
  40.  
  41.     $omitParams = array( 'numPages', 'url', $pgnName, 'pgnName', 'ianchor', 'ajaxId' );
  42.     foreach( $params as $form_param => $form_val ) {
  43.         if ( !empty( $form_val ) && !in_array( $form_param, $omitParams ) ) {
  44.             $pgnVars .= ( !empty( $params['ajaxId'] ) ? "&" : "&amp;" ).$form_param."=".$form_val;
  45.             $pgnHidden[$form_param] = $form_val;
  46.         }
  47.     }
  48.     $pgnVars .= ( !empty( $params['ianchor'] ) ? '#'.$params['ianchor'] : '' );
  49.     for( $pageCount = 1; $pageCount < $params['numPages']+1; $pageCount++ ) {
  50.         if( $pageCount != $params[$pgnName] ) {
  51.             if( $params['ajaxId'] ) {
  52.                 $pages[] = '<a href="javascript:void(0);" onclick="BitAjax.updater(\''.$params['ajaxId']."','".$_SERVER['REQUEST_URI']."','".$pgnName.'='.$pageCount.$pgnVars.'\')'.'">'.( $pageCount ).'</a>';
  53.             } else {
  54.                 $pages[] = '<a href="'.$_SERVER['SCRIPT_URL'].'?'.$pgnName.'='.$pageCount.$pgnVars.'">'.( $pageCount ).'</a>';
  55.             }
  56.         } else {
  57.             $pages[] = '<strong>'.$pageCount.'</strong>';
  58.         }
  59.     }
  60.  
  61.     if( $params['numPages'] > 1 ) {
  62.         $gBitSmarty->assign( 'pgnPage', $params[$pgnName] );
  63.         $gBitSmarty->assign( 'pgnName', $pgnName );
  64.         $gBitSmarty->assign( 'pgnVars', $pgnVars );
  65.         $gBitSmarty->assign( 'pgnHidden', $pgnHidden );
  66.         $gBitSmarty->assign( 'pgnPages', $pages );
  67.         $gBitSmarty->assign( 'numPages', $params['numPages'] );
  68.         $gBitSmarty->assign( 'ajaxId', $params['ajaxId'] );
  69.         $gBitSmarty->display( 'bitpackage:liberty/libertypagination.tpl' );
  70.     }
  71. }
  72. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:39 +0000 by phpDocumentor 1.5.0-lsces