diff options
Diffstat (limited to 'smartyplugins/function.pageurl.php')
| -rw-r--r-- | smartyplugins/function.pageurl.php | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/smartyplugins/function.pageurl.php b/smartyplugins/function.pageurl.php new file mode 100644 index 0000000..0ee7540 --- /dev/null +++ b/smartyplugins/function.pageurl.php @@ -0,0 +1,82 @@ +<?php +/** + * Smarty {pageurl} function plugin + * @package Smarty + * @subpackage plugins + * @link http://www.bitweaver.org/wiki/function_pageurl function_pageurl + */ + +/** + * Smarty {pagination} function plugin + * + * Type: function<br> + * Name: pageurl<br> + * Input: + * - <listHash>=<attribute=>value> (optional) - pass in any attributes and they will be added to the url string<br> + * Output: url of the form: $PHP_SELF?attribute1=value1&attribute2=value2 + +/* Build up URL variable string */ +function smarty_function_pageurl( $params, &$gBitSmarty ) { + extract( $params ); + + if( !isset( $pgnUrl ) ) { + $pgnUrl = $gBitSmarty->get_template_vars('returnURL'); + if ( isset( $params['url'] ) ) { + $pgnUrl = $params['url']; + unset( $params['url'] ); + } + if( empty( $pgnUrl ) ) { + $pgnUrl = $_SERVER['PHP_SELF']; + } + } + + $str = ''; + + if( !empty( $listInfo['parameters'] ) ){ + $str .= pageurl_hash_to_string( $listInfo['parameters'] ); + } + if( !empty( $listInfo['ihash'] ) ){ + $str .= pageurl_hash_to_string( $listInfo['ihash'] ); + // find can show up in two places + $foundFind = !empty( $listInfo['ihash']['find'] ); + } + if( !empty( $pgnHidden ) ){ + $str .= pageurl_hash_to_string( $pgnHidden ); + } + if ( !empty( $listInfo['sort_mode'] ) ){ + if ( is_array( $listInfo['sort_mode']) ){ + foreach( $listInfo['sort_mode'] as $sort ){ + $str .= "&sort_mode[]=".$sort; + } + }else{ + $str .= "&sort_mode=".$listInfo['sort_mode']; + } + } + if( !$foundFind && isset($listInfo['find']) && $listInfo['find'] != '' ){ + $str .= "&find=".$listInfo['find']; + } + + $pageUrlVar = preg_replace( '/^\&/', '', $str ); + + $pageUrl = $pgnUrl . "?" . $pageUrlVar; + + return $pageUrl; +} + +function pageurl_hash_to_string( $pParamHash ){ + $str = ""; + + foreach( $pParamHash as $param=>$value ){ + if( is_array( $value ) ){ + foreach ( $value as $v ){ + if ( $value != '' ){ + $str .= "&".$param."[]=".$v; + } + } + }elseif ( $value != '' ){ + $str .= "&".$param."=".$value; + } + } + + return $str; +} |
