|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Smarty plugin |
| 4 | + * |
| 5 | + * @package Smarty |
| 6 | + * @subpackage PluginsFunction |
| 7 | + * @author Jambik <> idea and creations |
| 8 | + * alex Roosso <http://www.roocms.com> - mod: added flag noentitys |
| 9 | + */ |
| 10 | + |
| 11 | +/** |
| 12 | + * Smarty {get_params} function plugin |
| 13 | + * |
| 14 | + * Type: function<br> |
| 15 | + * Name: get_params<br> |
| 16 | + * Purpose: generate get parameters |
| 17 | + * Input: |
| 18 | + * - prefix = before string |
| 19 | + * - suffix = after string |
| 20 | + * - exclude = GET params wich should be excluded |
| 21 | + * |
| 22 | + * @author Jambik <> idea and creations |
| 23 | + * alex Roosso <http://www.roocms.com> - mod: added flag noentitys |
| 24 | + * @param array $params parameters |
| 25 | + * @param Smarty_Internal_Template $template template object |
| 26 | + * @return string |
| 27 | + */ |
| 28 | +function smarty_function_get_params($params, $template) |
| 29 | +{ |
| 30 | + $prefix = isset($params['prefix']) ? trim($params['prefix']) : ""; |
| 31 | + $forcePrefix = isset($params['forcePrefix']) ? $params['forcePrefix'] : false; |
| 32 | + $suffix = isset($params['suffix']) ? trim($params['suffix']) : ""; |
| 33 | + $excludeParams = isset($params['exclude']) ? trim($params['exclude']) : false; |
| 34 | + $noentity = isset($params['noentity']) ? true : false; |
| 35 | + $output = ""; |
| 36 | + |
| 37 | + if($excludeParams) { |
| 38 | + $excludeParams = explode(",", $excludeParams); |
| 39 | + foreach($excludeParams as $key => $value) $excludeParams[$key] = trim($value); |
| 40 | + } |
| 41 | + |
| 42 | + if($_GET) { |
| 43 | + |
| 44 | + $entity = ($noentity) ? "&" : "&" ; |
| 45 | + |
| 46 | + if($excludeParams) { |
| 47 | + foreach($_GET as $key=>$value) { |
| 48 | + if(!in_array($key, $excludeParams)) { |
| 49 | + $output .= $entity.$key."=".$value; |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + else { |
| 54 | + foreach($_GET as $key=>$value) { |
| 55 | + $output .= $entity.$key."=".$value; |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + $output = $output ? substr($output, 5) : ""; |
| 60 | + } |
| 61 | + |
| 62 | + $output = $output ? $prefix.$output.$suffix : ( $forcePrefix ? $prefix : "" ); |
| 63 | + |
| 64 | + return $output; |
| 65 | +} |
0 commit comments