diff options
author | Yuchen Pei <me@ypei.me> | 2021-07-29 14:17:20 +1000 |
---|---|---|
committer | Yuchen Pei <me@ypei.me> | 2021-07-29 14:17:20 +1000 |
commit | 3ff03dc4f0a72432b34c00da620272cf011e4ddd (patch) | |
tree | 5746711ba17a91aed56c6529ea8cceb06c3ad16a /h-source/admin/Library/ArrayExt.php | |
parent | cd4534aa10ba3b122963992741721289fa50d0ab (diff) |
Publishing h-node.org code.
- this is the h-node.org code, except
- removed a js file (3x copies at three different locations) without license / copyright headers
- /Js/linkToForm.js
- /Public/Js/linkToForm.js
- /admin/Public/Js/linkToForm.js
- removed config files containing credentials
- /Application/Include/params.php
- /Config/Config.php
- /admin/Application/Include/params.php
- /admin/Config/Config.php
- added license and copyright header to one php file
- /admin/Library/ErrorReporting.php (almost identical to /Library/ErrorReporting.php which has the headers)
Diffstat (limited to 'h-source/admin/Library/ArrayExt.php')
-rwxr-xr-x | h-source/admin/Library/ArrayExt.php | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/h-source/admin/Library/ArrayExt.php b/h-source/admin/Library/ArrayExt.php new file mode 100755 index 0000000..93eca91 --- /dev/null +++ b/h-source/admin/Library/ArrayExt.php @@ -0,0 +1,63 @@ +<?php + +// All EasyGiant code is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +// See COPYRIGHT.txt and LICENSE.txt. + +if (!defined('EG')) die('Direct access not allowed!'); + +//class to manage arrays +class ArrayExt { + + public $errorString = null; //string containing the list fields not found + public $errorsNumb = null; //numbers of errors + + //get the subset of the associative array $associativeArray defined by the keys in the string $keyString (keys separated by comma) + public function subset($associativeArray,$keyString,$func = 'none') { + if (!in_array($func,explode(',',Params::$allowedSanitizeFunc))) { + throw new Exception('"'.$func. '" argument not allowed in '.__METHOD__.' method'); + } + $tempArray = array(); + if (strcmp($keyString,'') !== 0) { + $keyArray=explode(',',$keyString); + for ($i = 0; $i < count($keyArray); $i++) + { + $temp = array(); + //extract the function after the colon + if (strstr($keyArray[$i],':')) { + $temp = explode(':',$keyArray[$i]); + } else { + $temp[0] = $keyArray[$i]; + $temp[1] = 'none'; + } + //exception + if (!in_array($temp[1],explode(',',Params::$allowedSanitizeFunc))) { + throw new Exception('"'.$temp[1]. '" function not allowed'); + } + if (array_key_exists($temp[0],$associativeArray)) { + $tempArray[$temp[0]] = call_user_func($temp[1],$associativeArray[$temp[0]]); + } else { + $tempArray[$temp[0]] = ''; + } + } + } + return call_user_func($func.'Deep',$tempArray); //clean the array values + } + + //exctract the complementary subset from an associative array ($associativeArray) of the subset identified by the keys $keyString + public function subsetComplementary($associativeArray,$keyString,$func = 'none') { + if (!in_array($func,explode(',',Params::$allowedSanitizeFunc))) { + throw new Exception('"'.$func. '" argument not allowed in '.__METHOD__.' method'); + } + $keyArray=explode(',',$keyString); + $complementaryKeyArray = array(); + $keys = array_keys($associativeArray); + foreach ($keys as $key) { + if (!in_array($key,$keyArray)) { + $complementaryKeyArray[] = $key; + } + } + $complementaryKeyString = implode(',',$complementaryKeyArray); + return $this->subset($associativeArray,$complementaryKeyString,$func); + } + +} |