Changeset:
        0c7a8ece7592
        
https://sourceforge.net/p/mrbs/hg-code/ci/0c7a8ece75929761f5d8ea5f494551e81c2a9fab
Author:
        Campbell Morrison <cimorri...@hg.code.sf.net>
Date:
        Thu Mar 16 12:00:52 2017 +0000
Log message:

Restructured code

diffstat:

 web/grab_globals.inc.php |  32 ++++++++++++++++----------------
 1 files changed, 16 insertions(+), 16 deletions(-)

diffs (86 lines):

diff -r 553b69e54c49 -r 0c7a8ece7592 web/grab_globals.inc.php
--- a/web/grab_globals.inc.php  Thu Mar 16 11:11:16 2017 +0000
+++ b/web/grab_globals.inc.php  Thu Mar 16 12:00:52 2017 +0000
@@ -32,7 +32,7 @@
 
 // Gets a form variable.   Takes an optional third parameter which
 // is the default value if nothing is found from the form.
-function get_form_var($variable, $type = 'string')
+function get_form_var($var, $var_type='string', $default=null)
 {
   // We use some functions from here
   require_once "functions.inc";
@@ -40,51 +40,50 @@
   global $cli_params, $allow_cli, $get, $post;
   
   // Set the default value, and make sure it's the right type
-  if (func_num_args() > 2)
+  if ($var_type == 'array')
   {
-    $value = func_get_arg(2);
-    $value = ($type == 'array') ? (array)$value : $value;
+    $value = isset($default) ? (array) $default : array();
   }
   else
   {
-    $value = ($type == 'array') ? array() : NULL;
+    $value = $default;
   }
   
    // Get the command line arguments if any (and we're allowed to),
    // otherwise get the POST variables
-  if ($allow_cli && (!empty($cli_params) && isset($cli_params[$variable])))
+  if ($allow_cli && (!empty($cli_params) && isset($cli_params[$var])))
   {
-    $value = $cli_params[$variable];
+    $value = $cli_params[$var];
   }
-  else if (!empty($post) && isset($post[$variable]))
+  else if (!empty($post) && isset($post[$var]))
   {
-    $value = $post[$variable];
+    $value = $post[$var];
   }
   
   // Then get the GET variables
-  if (!empty($get) && isset($get[$variable]))
+  if (!empty($get) && isset($get[$var]))
   {
-    $value = $get[$variable];
+    $value = $get[$var];
   }
   
   // Cast to an array if necessary
-  if ($type == 'array')
+  if ($var_type == 'array')
   {
-    $value = (array)$value;
+    $value = (array) $value;
   }
   
   // Clean up the variable
   if ($value != NULL)
   {
-    if ($type == 'int')
+    if ($var_type == 'int')
     {
       $value = intval(unslashes($value));
     }
-    else if ($type == 'string')
+    else if ($var_type == 'string')
     {
       $value = unslashes($value);
     }
-    else if ($type == 'array')
+    else if ($var_type == 'array')
     {
       foreach ($value as $arrkey => $arrvalue)
       {
@@ -92,6 +91,7 @@
       }
     }
   }
+  
   return $value;
 }
 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mrbs-commits mailing list
Mrbs-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to