Skip to content

Commit 1f4684a

Browse files
authored
Create function.get_params.php
1 parent 18bec54 commit 1f4684a

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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) ? "&" : "&amp;" ;
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

Comments
 (0)