public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
Search Repo:
Added optional filtering to coalesce_key
Few little formatting and header fixes

Signed-off-by: Ted Kulp <ted@cmsmadesimple.org>


git-svn-id: http://svn.cmsmadesimple.org/svn/cmsmadesimple/trunk@4403 
3d254a34-79dc-0310-9e5f-be208747d8a0
tedkulp (author)
Wed Apr 02 05:48:27 -0700 2008
commit  5bec334e11d4fcca8b91bab4f49f1c0f6129b1bb
tree    40a14e0c2a26b5fd2c4fee76e0f9141138f4e62e
parent  ded5978926fec49c7ba3106cede94b7277db8a7f
...
258
259
260
261
 
 
 
262
 
 
 
 
 
263
264
265
266
267
 
268
269
270
271
 
 
 
 
272
273
274
...
258
259
260
 
261
262
263
264
265
266
267
268
269
270
271
272
273
 
274
275
276
277
 
278
279
280
281
282
283
284
0
@@ -258,17 +258,27 @@ function humanize($lowerCaseAndUnderscoredWord)
0
 
0
 /**
0
  * Looks through the hash given. If a key named val1 exists, then it's value is
0
- * returned. If not, then val2 is returned.
0
+ * returned. If not, then val2 is returned. Furthermore, passing one of the php
0
+ * filter ids (http://www.php.net/manual/en/ref.filter.php) will filter the
0
+ * returned value.
0
  *
0
+ * @param array The has to parse through
0
+ * @param string The key to look for
0
+ * @param mixed The value to return if the key isn't found
0
+ * @param integer An optional filter id to pass the returned value through
0
+ * @param array Optional parameters for the filter_var call
0
  * @return mixed The result of the coalesce
0
  * @author Ted Kulp
0
  * @since 1.1
0
  **/
0
-function coalesce_key($array, $val1, $val2)
0
+function coalesce_key($array, $val1, $val2, $filter = -1, $filter_options = array())
0
 {
0
   if (isset($array[$val1]))
0
   {
0
- return $array[$val1];
0
+ if ($filter > -1)
0
+ return filter_var($array[$val1], $filter, $filter_options);
0
+ else
0
+ return $array[$val1];
0
   }
0
   return $val2;
0
 }
...
23
24
25
26
 
27
28
29
...
23
24
25
 
26
27
28
29
0
@@ -23,7 +23,7 @@ function smarty_cms_function_mod_dropdown($params, &$smarty)
0
 
0
   return $module->create_input_dropdown($id, $params['name'], coalesce_key($params, 'items', $params['values']),
0
     coalesce_key($params, 'selected_index', '-1'), coalesce_key($params, 'selected_value', ''),
0
- coalesce_key($params, 'additional_text', ''), coalesce_key($params, 'flip_array', false), coalesce_key($params, 'id', ''));
0
+ coalesce_key($params, 'additional_text', ''), coalesce_key($params, 'flip_array', false, FILTER_VALIDATE_BOOLEAN), coalesce_key($params, 'id', ''));
0
 }
0
 
0
 ?>
...
1
 
2
3
 
4
5
6
...
20
21
22
23
 
24
25
26
27
28
29
 
30
...
 
1
2
 
3
4
5
6
...
20
21
22
 
23
24
25
26
27
28
29
30
31
0
@@ -1,6 +1,6 @@
0
-<?php
0
+<?php // -*- mode:php; tab-width:4; indent-tabs-mode:t; c-basic-offset:4; -*-
0
 #CMS - CMS Made Simple
0
-#(c)2004-2006 by Ted Kulp (ted@cmsmadesimple.org)
0
+#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
0
 #This project's homepage is: http://cmsmadesimple.org
0
 #
0
 #This program is free software; you can redistribute it and/or modify
0
@@ -20,11 +20,12 @@ function smarty_cms_function_mod_label($params, &$smarty)
0
 {
0
   $module =& $smarty->get_template_vars('cms_mapi_module');
0
   $id = $smarty->get_template_vars('cms_mapi_id');
0
- $translate = coalesce_key($params,'translate',true);
0
+ $translate = coalesce_key($params, 'translate', true, FILTER_VALIDATE_BOOLEAN);
0
 
0
   $value = ($translate === true) ? $module->lang($params['value']) : $params['value'];
0
   
0
   return $module->create_label_for_input($id, $params['name'], $value, coalesce_key($params, 'addttext', ''), coalesce_key($params, 'id', ''));
0
 }
0
 
0
+# vim:ts=4 sw=4 noet
0
 ?>
...
1
 
2
3
 
4
5
6
...
21
22
23
24
 
25
26
27
...
29
30
31
32
33
34
 
 
 
35
36
37
38
 
 
 
39
40
41
42
43
44
45
46
47
 
 
 
48
49
50
51
 
52
...
 
1
2
 
3
4
5
6
...
21
22
23
 
24
25
26
27
...
29
30
31
 
 
 
32
33
34
35
 
 
 
36
37
38
39
40
41
42
43
44
 
 
 
45
46
47
48
49
50
51
52
53
0
@@ -1,6 +1,6 @@
0
-<?php
0
+<?php // -*- mode:php; tab-width:4; indent-tabs-mode:t; c-basic-offset:4; -*-
0
 #CMS - CMS Made Simple
0
-#(c)2004-2006 by Ted Kulp (ted@cmsmadesimple.org)
0
+#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
0
 #This project's homepage is: http://cmsmadesimple.org
0
 #
0
 #This program is free software; you can redistribute it and/or modify
0
@@ -21,7 +21,7 @@ function smarty_cms_function_mod_link($params, &$smarty)
0
   $module =& $smarty->get_template_vars('cms_mapi_module');
0
   $id = $smarty->get_template_vars('cms_mapi_id');
0
   $return_id = $smarty->get_template_vars('cms_mapi_return_id');
0
- $translate = coalesce_key($params,'translate',true);
0
+ $translate = coalesce_key($params, 'translate', true, FILTER_VALIDATE_BOOLEAN);
0
 
0
   $value = ($translate === true) ? $module->lang($params['value']) : $params['value'];
0
   if (isset($params['theme_image']))
0
@@ -29,24 +29,25 @@ function smarty_cms_function_mod_link($params, &$smarty)
0
     $themeObject = CmsAdminTheme::get_instance();
0
     $image = $themeObject->display_image($params['theme_image'], $value,'','','systemicon');
0
     if( isset($params['showtext']) )
0
- {
0
- $value = $image.'&nbsp;'.$value;
0
- }
0
+ {
0
+ $value = $image.'&nbsp;'.$value;
0
+ }
0
     else
0
- {
0
- $value = $image;
0
- }
0
+ {
0
+ $value = $image;
0
+ }
0
   }
0
 
0
   $other_params = remove_keys($params, array('action', 'value', 'warn_message', 'translate', 'only_href',
0
             'inline', 'additional_text', 'target_container_only', 'pretty_url', 'theme_image'));
0
 
0
   $blah = $module->create_link($id, $params['action'], $return_id, $value,
0
- $other_params, coalesce_key($params, 'warn_message', ''), coalesce_key($params, 'only_href', false),
0
- coalesce_key($params, 'inline', false), coalesce_key($params, 'additional_text', ''),
0
- coalesce_key($params, 'target_container_only', false), coalesce_key($params, 'pretty_url', ''));
0
+ $other_params, coalesce_key($params, 'warn_message', ''), coalesce_key($params, 'only_href', false, FILTER_VALIDATE_BOOLEAN),
0
+ coalesce_key($params, 'inline', false, FILTER_VALIDATE_BOOLEAN), coalesce_key($params, 'additional_text', ''),
0
+ coalesce_key($params, 'target_container_only', false, FILTER_VALIDATE_BOOLEAN), coalesce_key($params, 'pretty_url', ''));
0
             
0
   return $blah;
0
 }
0
 
0
+# vim:ts=4 sw=4 noet
0
 ?>
...
1
 
2
3
 
4
5
6
...
20
21
22
23
 
 
24
25
 
26
27
28
29
30
31
 
 
32
...
 
1
2
 
3
4
5
6
...
20
21
22
 
23
24
25
26
27
28
29
30
31
32
 
33
34
35
0
@@ -1,6 +1,6 @@
0
-<?php
0
+<?php // -*- mode:php; tab-width:4; indent-tabs-mode:t; c-basic-offset:4; -*-
0
 #CMS - CMS Made Simple
0
-#(c)2004-2006 by Ted Kulp (ted@cmsmadesimple.org)
0
+#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
0
 #This project's homepage is: http://cmsmadesimple.org
0
 #
0
 #This program is free software; you can redistribute it and/or modify
0
@@ -20,12 +20,15 @@ function smarty_cms_function_mod_submit($params, &$smarty)
0
 {
0
   $module =& $smarty->get_template_vars('cms_mapi_module');
0
   $id = $smarty->get_template_vars('cms_mapi_id');
0
- $translate = coalesce_key($params,'translate',true);
0
+ $translate = coalesce_key($params, 'translate', true, FILTER_VALIDATE_BOOLEAN);
0
+
0
   $value = ($translate === true) ? $module->lang($params['value']) : $params['value'];
0
   $confirm_text = ($translate === true) ? $module->Lang($params['confirm_text']) : $params['confirm_text'];
0
+
0
   return $module->create_input_submit($id, $params['name'], $value,
0
         coalesce_key($params, 'additional_text', ''), coalesce_key($params, 'image', ''),
0
         $confirm_text, coalesce_key($params, 'id', ''));
0
 }
0
 
0
-?>
0
+# vim:ts=4 sw=4 noet
0
+?>
0
\ No newline at end of file
...
1
 
2
3
4
 
5
6
7
...
16
17
18
19
 
20
21
22
 
 
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
43
44
 
45
...
 
1
2
3
 
4
5
6
7
...
16
17
18
 
19
20
 
 
21
22
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 
44
45
0
@@ -1,7 +1,7 @@
0
-<?php
0
+<?php // -*- mode:php; tab-width:4; indent-tabs-mode:t; c-basic-offset:4; -*-
0
 #CMS - CMS Made Simple
0
 #(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
0
-#This project's homepage is: http://cmsmadesimple.sf.net
0
+#This project's homepage is: http://cmsmadesimple.org
0
 #
0
 #This program is free software; you can redistribute it and/or modify
0
 #it under the terms of the GNU General Public License as published by
0
@@ -16,30 +16,30 @@
0
 #along with this program; if not, write to the Free Software
0
 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0
 
0
-function smarty_cms_block_tr($params,$content,&$smarty)
0
+function smarty_cms_block_tr($params, $content, &$smarty)
0
 {
0
- if( is_null($content) ) return;
0
- $module =& $smarty->get_template_vars('cms_mapi_module');
0
+ if (is_null($content)) return;
0
+ $module = $smarty->get_template_vars('cms_mapi_module');
0
 
0
- $txt = '';
0
- if( !is_object($module) )
0
- {
0
- $txt = CmsLanguage::translate(trim($content));
0
- }
0
- else
0
- {
0
- $txt = $module->Lang(trim($content));
0
- }
0
-
0
- if( isset($params['assign']) )
0
- {
0
- $smarty->assign($params['assign'],$txt);
0
- }
0
- else
0
- {
0
- return $txt;
0
- }
0
+ $txt = '';
0
+ if (!is_object($module))
0
+ {
0
+ $txt = CmsLanguage::translate(trim($content));
0
+ }
0
+ else
0
+ {
0
+ $txt = $module->Lang(trim($content));
0
+ }
0
+
0
+ if (isset($params['assign']))
0
+ {
0
+ $smarty->assign($params['assign'], $txt);
0
+ }
0
+ else
0
+ {
0
+ return $txt;
0
+ }
0
 }
0
 
0
-// EOF
0
+# vim:ts=4 sw=4 noet
0
 ?>

Comments

    No one has commented yet.