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

Source for file function.pageurl.php

Documentation is available at function.pageurl.php

  1. <?php
  2. /**
  3.  * Smarty {pageurl} function plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  * @link http://www.bitweaver.org/wiki/function_pageurl function_pageurl
  7.  */
  8.  
  9. /**
  10.  * Smarty {pagination} function plugin
  11.  *
  12.  * Type:     function<br>
  13.  * Name:     pageurl<br>
  14.  * Input:
  15.  *           - <listHash>=<attribute=>value>  (optional) - pass in any attributes and they will be added to the url string<br>
  16.  * Output:   url of the form: $_SERVER[SCRIPT_NAME]?attribute1=value1&attribute2=value2
  17.  
  18. /* Build up URL variable string */
  19. function smarty_function_pageurl( $params, &$gBitSmarty ) {
  20.     extract( $params );
  21.  
  22.     if( !isset( $pgnUrl ) ) {
  23.         $pgnUrl = $gBitSmarty->get_template_vars('returnURL');
  24.         if ( isset( $params['url'] ) ) {
  25.             $pgnUrl = $params['url'];
  26.             unset( $params['url'] );
  27.         }
  28.         if( empty( $pgnUrl ) ) {
  29.             $pgnUrl = $_SERVER['SCRIPT_NAME'];
  30.         }
  31.     }
  32.  
  33.     $str = '';
  34.  
  35.     if( !empty( $listInfo['parameters'] ) ){
  36.         $str .= pageurl_hash_to_string( $listInfo['parameters'] );
  37.     }
  38.     if( !empty( $listInfo['ihash'] ) ){
  39.         $str .= pageurl_hash_to_string( $listInfo['ihash'] );
  40.         // find can show up in two places
  41.         $foundFind = !empty( $listInfo['ihash']['find'] );
  42.     }
  43.     if( !empty( $pgnHidden ) ){
  44.         $str .= pageurl_hash_to_string( $pgnHidden );
  45.     }
  46.     if ( !empty( $listInfo['sort_mode'] ) ){
  47.         if ( is_array( $listInfo['sort_mode']) ){
  48.             foreach( $listInfo['sort_mode'] as $sort ){
  49.                 $str .= "&amp;sort_mode[]=".$sort;
  50.             }
  51.         }else{
  52.             $str .= "&amp;sort_mode=".$listInfo['sort_mode'];
  53.         }
  54.     }
  55.     if( !$foundFind && isset($listInfo['find']) && $listInfo['find'] != '' ){
  56.         $str .= "&amp;find=".$listInfo['find'];
  57.     }
  58.  
  59.     $pageUrlVar = preg_replace( '/^\&amp;/', '', $str );
  60.  
  61.     $pageUrl = $pgnUrl . "?" . $pageUrlVar;
  62.     
  63.     return $pageUrl;
  64. }
  65.  
  66. function pageurl_hash_to_string( $pParamHash ){
  67.     $str = "";
  68.  
  69.     foreach( $pParamHash as $param=>$value ){
  70.         if( is_array( $value ) ){
  71.             foreach ( $value as $v ){
  72.                 if ( $value != '' ){
  73.                     $str .= "&amp;".$param."[]=".$v;
  74.                 }
  75.             }
  76.         }elseif ( $value != '' ){
  77.             $str .= "&amp;".$param."=".$value;
  78.         }
  79.     }
  80.  
  81.     return $str;
  82. }

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