Advertisement
pbowers

UserSpice: Input.php - allow arrays and hashes

Sep 19th, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.92 KB | None | 0 0
  1. <?php
  2. /*
  3. UserSpice 4
  4. An Open Source PHP User Management System
  5. by the UserSpice Team at http://UserSpice.com
  6.  
  7. This program is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. class Input {
  21.     public static function exists($type = 'post'){
  22.         switch ($type) {
  23.             case 'post':
  24.                 return (!empty($_POST)) ? true : false;
  25.                 break;
  26.  
  27.             case 'get':
  28.                 return (!empty($_GET)) ? true : false;
  29.  
  30.             default:
  31.                 return false;
  32.                 break;
  33.         }
  34.     }
  35.  
  36.     public static function get($item){
  37.         #echo "DEBUG: Input::get($item): Entering<br />\n";
  38.         if (isset($_POST[$item])) {
  39.             $myItem = $_POST[$item];
  40.         } elseif(isset($_GET[$item])){
  41.             $myItem = $_GET[$item];
  42.         } else {
  43.             return '';
  44.         }
  45.         #echo "DEBUG: Input::get($item): myItem=<pre>".print_r($myItem,true)."</pre><br />\n";
  46.         /*
  47.         If the item is an array, process each item independently, and return array of sanitized items.
  48.         */
  49.         if (is_array($myItem)){
  50.             $myItems=array();
  51.             foreach ($myItem as $k => $elem){
  52.                 $myItems[$k]=self::sanitize($elem);
  53.             }
  54.             #echo "DEBUG: Input::get($item): returning myItems=<pre>".print_r($myItems,true)."</pre><br />\n";
  55.             return $myItems;
  56.         }else{
  57.             #echo "DEBUG: Input::get($item): returning myItem=$myItem<br />\n";
  58.             return self::sanitize($myItem);
  59.         }
  60.     }
  61.  
  62.     public static function sanitize($string){
  63.         return trim(htmlentities($string, ENT_QUOTES, 'UTF-8'));
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement