- Timestamp:
- Sep 3, 2019 7:35:42 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Utilities.inc.php
r696 r701 1053 1053 * quotes if necessary. 1054 1054 * 1055 * @param string $ var (optional) The name of the form variable to look for.1055 * @param string $key (optional) The name of a $_REQUEST key. 1056 1056 * @param string $default (optional) The value to return if the 1057 1057 * variable is not there. 1058 * @return mixed A cleaned GET or POST if no $varspecified.1059 * @return string A cleaned form $varif found, or $default.1060 */ 1061 function getFormData($ var=null, $default=null)1058 * @return mixed A cleaned GET or POST array if no key specified. 1059 * @return string A cleaned form value if found, or $default. 1060 */ 1061 function getFormData($key=null, $default=null) 1062 1062 { 1063 1063 $app =& App::getInstance(); 1064 1064 1065 if ('POST' == getenv('REQUEST_METHOD') && is_null($var)) {1065 if ('POST' == getenv('REQUEST_METHOD') && null === $key) { 1066 1066 return dispelMagicQuotes($_POST, $app->getParam('always_dispel_magicquotes')); 1067 } else if ('GET' == getenv('REQUEST_METHOD') && is_null($var)) {1067 } else if ('GET' == getenv('REQUEST_METHOD') && null === $key) { 1068 1068 return dispelMagicQuotes($_GET, $app->getParam('always_dispel_magicquotes')); 1069 1069 } 1070 if (isset($_POST[$var])) { 1071 return dispelMagicQuotes($_POST[$var], $app->getParam('always_dispel_magicquotes')); 1072 } else if (isset($_GET[$var])) { 1073 return dispelMagicQuotes($_GET[$var], $app->getParam('always_dispel_magicquotes')); 1070 1071 if (isset($_REQUEST[$key])) { 1072 // $key is found in the flat array of REQUEST. 1073 return dispelMagicQuotes($_REQUEST[$key], $app->getParam('always_dispel_magicquotes')); 1074 } else if (mb_strpos($key, '[') !== false && isset($_REQUEST[strtok($key, '[')]) && preg_match_all('/\[([a-z0-9._~-]+)\]/', $key, $matches)) { 1075 // $key is formatted with sub-keys, e.g., getFormData('foo[bar][baz]') and top level key (`foo`) exists in REQUEST. 1076 // Extract these as sub-keys and access REQUEST as a multi-dimensional array, e.g., $_REQUEST[foo][bar][baz]. 1077 $leaf = $_REQUEST[strtok($key, '[')]; 1078 foreach ($matches[1] as $subkey) { 1079 if (is_array($leaf) && isset($leaf[$subkey])) { 1080 $leaf = $leaf[$subkey]; 1081 } else { 1082 $leaf = null; 1083 } 1084 } 1085 return $leaf; 1074 1086 } else { 1075 1087 return $default; … … 1077 1089 } 1078 1090 1079 function getPost($ var=null, $default=null)1091 function getPost($key=null, $default=null) 1080 1092 { 1081 1093 $app =& App::getInstance(); 1082 1094 1083 if ( is_null($var)) {1095 if (null === $key) { 1084 1096 return dispelMagicQuotes($_POST, $app->getParam('always_dispel_magicquotes')); 1085 1097 } 1086 if (isset($_POST[$ var])) {1087 return dispelMagicQuotes($_POST[$ var], $app->getParam('always_dispel_magicquotes'));1098 if (isset($_POST[$key])) { 1099 return dispelMagicQuotes($_POST[$key], $app->getParam('always_dispel_magicquotes')); 1088 1100 } else { 1089 1101 return $default; … … 1091 1103 } 1092 1104 1093 function getGet($ var=null, $default=null)1105 function getGet($key=null, $default=null) 1094 1106 { 1095 1107 $app =& App::getInstance(); 1096 if (is_null($var)) { 1108 1109 if (null === $key) { 1097 1110 return dispelMagicQuotes($_GET, $app->getParam('always_dispel_magicquotes')); 1098 1111 } 1099 if (isset($_GET[$ var])) {1100 return dispelMagicQuotes($_GET[$ var], $app->getParam('always_dispel_magicquotes'));1112 if (isset($_GET[$key])) { 1113 return dispelMagicQuotes($_GET[$key], $app->getParam('always_dispel_magicquotes')); 1101 1114 } else { 1102 1115 return $default;
Note: See TracChangeset
for help on using the changeset viewer.