Changeset 2326

Show
Ignore:
Timestamp:
12/24/10 07:22:18 (17 months ago)
Author:
petsagouris
Message:

[Branch 1.5] General code care. Nothing fancy changed.

Location:
branches/1.5
Files:
15 modified

Legend:

Unmodified
Added
Removed
  • branches/1.5/Hotaru.php

    r2319 r2326  
    265265                // The file must contain a class titled PluginNameSettings 
    266266                // The class must have a method called "settings". 
    267                 if (($this->cage->get->testAlnumLines('plugin') != $this->plugin->folder) 
    268                         && ($this->cage->post->testAlnumLines('plugin') != $this->plugin->folder)) 
    269                 { 
     267                if (($this->cage->get->testAlnumLines('plugin') != $this->plugin->folder) && ($this->cage->post->testAlnumLines('plugin') != $this->plugin->folder)) { 
    270268                        return false; 
    271269                } 
    272270 
    273                 if (file_exists(PLUGINS . $this->plugin->folder . '/' . $this->plugin->folder . '_settings.php')) { 
    274                     include_once(PLUGINS . $this->plugin->folder . '/' . $this->plugin->folder . '_settings.php'); 
    275  
    276                     $settings_class = make_name($this->plugin->folder, '_') . 'Settings'; // e.g. CategoriesSettings 
    277                     $settings_class = str_replace(' ', '', $settings_class); // strip spaces 
    278                     $settings_object = new $settings_class(); 
    279                     $settings_object->settings($this);   // call the settings function 
     271                if (file_exists(PLUGINS.$this->plugin->folder.'/'.$this->plugin->folder.'_settings.php')) { 
     272                        include_once(PLUGINS.$this->plugin->folder.'/'.$this->plugin->folder.'_settings.php'); 
     273 
     274                        $settings_class = make_name($this->plugin->folder, '_').'Settings'; // e.g. CategoriesSettings 
     275                        $settings_class = str_replace(' ', '', $settings_class); // strip spaces 
     276                        $settings_object = new $settings_class(); 
     277                        $settings_object->settings($this);   // call the settings function 
     278                } else { 
     279                        trigger_error( $this->lang["admin_theme_plugins_filenotfound"]." - ".$this->lang["admin_theme_plugins_checkforfile"].PLUGINS.$this->plugin->folder.'/'.$this->plugin->folder.'_settings.php', E_USER_NOTICE); 
    280280                } 
    281                 else { 
    282                     echo $this->lang["admin_theme_plugins_filenotfound"] . "<br/><br/>"; 
    283                     echo $this->lang["admin_theme_plugins_checkforfile"] . PLUGINS . $this->plugin->folder . '/' . $this->plugin->folder . '_settings.php'; 
    284                 } 
     281                 
    285282                return true; 
    286283        } 
  • branches/1.5/content/admin_language.php

    r2259 r2326  
    8888$lang['admin_plugins_order_zero'] = "Error: The order value is zero."; 
    8989$lang['admin_plugins_order_first'] = "is already first."; 
    90 $lang['admin_plugins_order_last'] = "is already last."; 
    9190$lang['admin_plugins_order_above'] = "Error: The plugin to move above has the same order value."; 
    9291$lang['admin_plugins_order_below'] = "Error: The plugin to move below has the same order value."; 
     
    222221$lang["admin_theme_blocked_all"] = "All"; 
    223222 
    224 /* Pagination */ 
    225 $lang['pagination_first'] = "First"; 
    226 $lang['pagination_last'] = "Last"; 
    227 $lang['pagination_previous'] = "Previous"; 
    228 $lang['pagination_next'] = "Next"; 
    229  
    230223/* header */ 
    231224$lang["admin_theme_header_admin"] = "ADMIN"; 
  • branches/1.5/content/admin_themes/admin_default/blocked.php

    r2160 r2326  
    4141                <tr class='table_headers'> 
    4242                        <td> 
    43                                 <select name='blocked_type'> 
     43                                <select name='blocked_block_type'> 
    4444                                        <option value='ip'><?php echo $h->lang["admin_theme_blocked_ip"]; ?></option> 
    4545                                        <option value='url'><?php echo $h->lang["admin_theme_blocked_url"]; ?></option> 
     
    4848                                </select> 
    4949                        </td> 
    50                         <td><input type='text' size=30 name='value' value='' /></td> 
     50                        <td><input type='text' size=30 name='blocked_block_value' value='' /></td> 
    5151                        <td><input class='submit' type='submit' value='<?php echo $h->lang['admin_theme_blocked_submit_add']; ?>' /></td> 
    5252                </tr> 
  • branches/1.5/functions/funcs.strings.php

    r2314 r2326  
    118118 * 
    119119 * @param string $var the string to sanitize 
    120  * @param string $santype type of sanitation: 'all', 'ents', 'tags' 
    121  * @param string $allowable_tags 
     120 * @param string $type type of sanitation: 'all', 'ents', 'tags' 
     121 * @param string $allowed_tags 
    122122 * @return string|false 
    123123 * 
    124124 * Note: Borrowed from SWCMS 
    125125 */ 
    126 function sanitize($var, $santype = 'all', $allowable_tags = '') 
    127 { 
    128         // htmlentities & Strip tags 
    129         if ($santype == 'all') { 
    130                 if (!get_magic_quotes_gpc()) { 
    131                         return htmlentities(strip_tags($var, $allowable_tags), ENT_QUOTES, 'UTF-8'); 
    132                 } 
    133                 return stripslashes(htmlentities(strip_tags($var, $allowable_tags), ENT_QUOTES, 'UTF-8')); 
    134         } 
    135  
    136         // Strip tags 
    137         if ($santype == 'tags') { 
    138                 if (!get_magic_quotes_gpc()) { 
    139                         return strip_tags($var, $allowable_tags); 
    140                 } 
    141                 return stripslashes(strip_tags($var, $allowable_tags)); 
    142         } 
    143  
    144         // htmlentities 
    145         if ($santype == 'ents') { 
    146                 if (!get_magic_quotes_gpc()) { 
    147                         return htmlentities($var, ENT_QUOTES, 'UTF-8'); 
    148                 } 
    149                 return stripslashes(htmlentities($var, ENT_QUOTES, 'UTF-8')); 
    150         } 
    151  
    152         return false; 
     126function sanitize($var, $type = 'all', $allowed_tags = '') 
     127{ 
     128        switch($type) { 
     129                case 'tags': 
     130                        // Strip tags 
     131                        return strip_tags($var, $allowed_tags); 
     132                case 'ents' : 
     133                        // htmlentities 
     134                        return htmlspecialchars($var, ENT_QUOTES, 'UTF-8', FALSE); 
     135                default: 
     136                        // htmlentities & Strip tags 
     137                        return htmlspecialchars(strip_tags($var, $allowed_tags), ENT_QUOTES, 'UTF-8', FALSE); 
     138        } 
     139         
     140        return FALSE; 
    153141} 
    154142 
     
    187175function replace_symbols($input) 
    188176{ 
    189         // FOR THIS TO WORK, THIS FUNCS.STRINGS.PHP FILE MUST BE SAVED  
    190         // IN UTF-8 CHARACTER ENCODING !!! 
    191177        // Replace spaces with hyphens 
    192178        // Replace other characters 
  • branches/1.5/libs/AdminPages.php

    r2315 r2326  
    142142 
    143143                        foreach ($loaded_settings as $setting_name) { 
    144                                 if ($h->cage->post->keyExists($setting_name->settings_name)) { 
    145                                         $setting_value = $h->cage->post->getRaw($setting_name->settings_name); 
     144                                if ($setting_value = $h->cage->post->keyExists($setting_name->settings_name,TRUE)) { 
    146145                                        if (!$error && $setting_value && $setting_value != $setting_name->settings_value) { 
    147146                                                $this->adminSettingUpdate($h, $setting_name->settings_name, $setting_value); 
     
    224223                if (!$exists) { 
    225224                        $sql = "INSERT INTO ".TABLE_SETTINGS." (settings_name, settings_value, settings_updateby) VALUES (%s, %s, %d)"; 
    226                         $h->db->query($h->db->prepare($sql, $setting, $value, $h->currentUser->id)); 
     225                        $h->db->query($h->db->prepare($sql, $setting, ($value == 'on' || $value =='true')?'true':'false', $h->currentUser->id)); 
    227226                } else { 
    228227                        $sql = "UPDATE ".TABLE_SETTINGS." SET settings_name = %s, settings_value = %s, settings_updateby = %d WHERE (settings_name = %s)"; 
  • branches/1.5/libs/Blocked.php

    r1918 r2326  
    4646                if ($safe && $h->cage->post->getAlpha('type') == 'new') 
    4747                { 
    48                         $type = $h->cage->post->testAlnumLines('blocked_type'); 
    49                         $value = $h->cage->post->sanitizeTags('value'); 
     48                        $type = $h->cage->post->testAlnumLines('blocked_block_type'); 
     49                        $value = $h->cage->post->sanitizeTags('blocked_block_value'); 
    5050                         
    5151                        if (!$value) { 
     
    8787                        $search_term = $h->cage->post->sanitizeTags('search_value'); 
    8888                        $where_clause = " WHERE blocked_value LIKE %s"; 
    89                         $count_sql = "SELECT count(*) AS number FROM " . TABLE_BLOCKED . $where_clause; 
     89                        $count_sql = "SELECT count(blocked_id) AS number FROM " . TABLE_BLOCKED . $where_clause; 
    9090                        $count = $h->db->get_var($h->db->prepare($count_sql, '%' . trim($search_term) . '%')); 
    91                         $sql = "SELECT * FROM " . TABLE_BLOCKED . $where_clause . $sort_clause; 
     91                        $sql = "SELECT blocked_id,blocked_type,blocked_value FROM " . TABLE_BLOCKED . $where_clause . $sort_clause; 
    9292                        $query = $h->db->prepare($sql, '%' . trim($search_term) . '%'); 
    9393                } 
     
    9898                        $filter = $h->cage->post->testAlnumLines('blocked_type'); 
    9999                        if ($filter == 'all') {  
    100                                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_BLOCKED; 
     100                                $count_sql = "SELECT count(blocked_id) AS number FROM " . TABLE_BLOCKED; 
    101101                                $count = $h->db->get_var($h->db->prepare($count_sql)); 
    102                                 $sql = "SELECT * FROM " . TABLE_BLOCKED . $sort_clause; 
     102                                $sql = "SELECT blocked_id,blocked_type,blocked_value FROM " . TABLE_BLOCKED . $sort_clause; 
    103103                                $query = $h->db->prepare($sql); 
    104104                        } else { 
    105                                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_BLOCKED . " WHERE blocked_type = %s"; 
     105                                $count_sql = "SELECT count(blocked_id) AS number FROM " . TABLE_BLOCKED . " WHERE blocked_type = %s"; 
    106106                                $count = $h->db->get_var($h->db->prepare($count_sql, $filter)); 
    107                                 $sql = "SELECT * FROM " . TABLE_BLOCKED . " WHERE blocked_type = %s" . $sort_clause; 
     107                                $sql = "SELECT blocked_id,blocked_type,blocked_value FROM " . TABLE_BLOCKED . " WHERE blocked_type = %s" . $sort_clause; 
    108108                                $query = $h->db->prepare($sql, $filter); 
    109109                        } 
     
    112112                // SQL 
    113113                if (!$query) {  
    114                         $count_sql = "SELECT count(*) AS number FROM " . TABLE_BLOCKED; 
     114                        $count_sql = "SELECT count(blocked_id) AS number FROM " . TABLE_BLOCKED; 
    115115                        $count = $h->db->get_var($h->db->prepare($count_sql)); 
    116                         $sql = "SELECT * FROM " . TABLE_BLOCKED . $sort_clause; 
     116                        $sql = "SELECT blocked_id,blocked_type,blocked_value FROM " . TABLE_BLOCKED . $sort_clause; 
    117117                        $query = $h->db->prepare($sql); 
    118118                } 
     
    171171                        } 
    172172                } 
    173                  
    174                 $blocked_array = array('blocked_items' => $output, 'pagedResults' => $pagedResults); 
     173                $blocked_array = array('blocked_items' => $output, 'pagedResults' => (count($pagedResults->items) > 1)?$pagedResults:FALSE); 
    175174                 
    176175                return $blocked_array; 
     
    249248                // if both type and value provided... 
    250249                if ($type && $value) { 
    251                         $sql = "SELECT count(blocked_value) FROM " . TABLE_BLOCKED . " WHERE blocked_type = %s AND blocked_value " . $operator . " %s";  
     250                        $sql = "SELECT count(blocked_id) FROM " . TABLE_BLOCKED . " WHERE blocked_type = %s AND blocked_value " . $operator . " %s"; 
    252251                        $exists = $db->get_var($db->prepare($sql, $type, $value)); 
    253252                }  
     
    255254                elseif ($value)  
    256255                { 
    257                         $sql = "SELECT count(blocked_value) FROM " . TABLE_BLOCKED . " WHERE blocked_value " . $operator . " %s";  
     256                        $sql = "SELECT count(blocked_id) FROM " . TABLE_BLOCKED . " WHERE blocked_value " . $operator . " %s"; 
    258257                        $exists = $db->get_var($db->prepare($sql, $value)); 
    259258                } 
  • branches/1.5/libs/Breadcrumbs.php

    r2266 r2326  
    3535        public function buildBreadcrumbs(Hotaru $h) 
    3636        { 
    37                 $output = '<a href="'.SITEURL.'">'.$h->lang['main_theme_breadcrumbs_home'].'</a>'.(($h->isAdmin) ? ' &raquo; <a href="'.$h->url(array(), 'admin').'">'.$h->lang['admin_theme_main_admin_cp'].'</a>' : ''); 
     37                $output = (!$h->isAdmin) ? '<a href="'.SITEURL.'">'.$h->lang['main_theme_breadcrumbs_home'].'</a>' : '<a href="'.$h->url(array(), 'admin').'">'.$h->lang['admin_theme_main_admin_cp'].'</a>'; 
     38 
     39                if ($h->isAdmin && $h->pageName == 'plugin_settings') { 
     40                        return $output.' &raquo; '.make_name($h->cage->get->keyExists('plugin', TRUE)).' '.$h->pageTitle; 
     41                } 
    3842 
    3943                $crumbs = $h->pluginHook('breadcrumbs'); 
    40                 if ($crumbs) { 
    41                         return $output.' &raquo; '.array_pop($crumbs); 
     44 
     45                if (!$crumbs) { 
     46                        return $output.' &raquo; '.$h->pageTitle; 
    4247                } 
    43                 return $output." &raquo; ".$h->pageTitle; 
     48                 
     49                return $output.' &raquo; '.array_pop($crumbs); 
    4450        } 
    4551 
  • branches/1.5/libs/Database.php

    r2312 r2326  
    149149                        // Store Query Results 
    150150                        if ($this->result instanceof mysqli_result) { 
    151                                 while ($row = $this->result->fetch_object()) { 
     151                                while ($row = mysqli_fetch_object($this->result)) { 
    152152                                        // Store relults as an objects within main array 
    153153                                        $this->last_result[] = $row; 
     
    155155 
    156156                                // Store and return the number of rows the query returned 
    157                                 $return_val = $this->num_rows = $this->result->num_rows; 
    158  
    159                                 $this->result->free(); 
     157                                $return_val = $this->num_rows = mysqli_num_rows($this->result); 
     158 
     159                                mysqli_free_result($this->result); 
    160160                        } 
    161161                } 
     
    317317                // Send back array of objects. Each row is an object 
    318318                if ($output == 'OBJECT') { 
     319 
    319320                        return $this->last_result; 
    320321                } 
  • branches/1.5/libs/InspektExtras.php

    r2292 r2326  
    150150 
    151151        /** 
    152          * a function to sanitize with htmlentities 
     152         * a function to sanitize with htmlspecialchars 
    153153         * 
    154154         * @return string 
  • branches/1.5/libs/extensions/Inspekt/Inspekt.php

    r2295 r2326  
    88 * @package Inspekt 
    99 */ 
    10  
    1110/** 
    1211 * Inspekt_Error 
    1312 */ 
    14 require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Inspekt/Error.php'); 
     13require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'Inspekt/Error.php'); 
    1514 
    1615/** 
    1716 * Inspekt_Cage 
    1817 */ 
    19 require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Inspekt/Cage.php'); 
     18require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'Inspekt/Cage.php'); 
    2019 
    2120/** 
     
    2726 * Inspekt_Supercage 
    2827 */ 
    29 require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Inspekt/Supercage.php'); 
     28require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'Inspekt/Supercage.php'); 
    3029 
    3130 
     
    9291class Inspekt 
    9392{ 
    94     protected static $useFilterExtension = true; 
    95  
    96     /** 
    97      * Returns the $_SERVER data wrapped in an Inspekt_Cage object 
    98      * 
    99      * This utilizes a singleton pattern to get around scoping issues 
    100      * 
    101      * @param string  $config_file 
    102      * @param boolean $strict whether or not to nullify the superglobal array 
    103      * @return Inspekt_Cage 
    104      * 
    105      * @assert() 
    106      */ 
    107     static public function makeServerCage($config_file = null, $strict = true) 
    108     { 
    109         /** 
    110          * @staticvar $_instance 
    111          */ 
    112         static $_instance; 
    113  
    114         if (!isset($_instance)) { 
    115             $_instance = Inspekt_Cage::Factory($_SERVER, $config_file, '_SERVER', $strict); 
    116         } 
    117         $GLOBALS['HTTP_SERVER_VARS'] = null; 
    118         return $_instance; 
    119     } 
    120  
    121     /** 
    122      * Returns the $_GET data wrapped in an Inspekt_Cage object 
    123      * 
    124      * This utilizes a singleton pattern to get around scoping issues 
    125      * 
    126      * @param string  $config_file 
    127      * @param boolean $strict whether or not to nullify the superglobal array 
    128      * @return Inspekt_Cage 
    129      */ 
    130     static public function makeGetCage($config_file = null, $strict = true) 
    131     { 
    132         /** 
    133          * @staticvar $_instance 
    134          */ 
    135         static $_instance; 
    136  
    137         if (!isset($_instance)) { 
    138             $_instance = Inspekt_Cage::Factory($_GET, $config_file, '_GET', $strict); 
    139         } 
    140         $GLOBALS['HTTP_GET_VARS'] = null; 
    141         return $_instance; 
    142     } 
    143  
    144     /** 
    145      * Returns the $_POST data wrapped in an Inspekt_Cage object 
    146      * 
    147      * This utilizes a singleton pattern to get around scoping issues 
    148      * 
    149      * @param string  $config_file 
    150      * @param boolean $strict whether or not to nullify the superglobal array 
    151      * @return Inspekt_Cage 
    152      */ 
    153     static public function makePostCage($config_file = null, $strict = true) 
    154     { 
    155         /** 
    156          * @staticvar $_instance 
    157          */ 
    158         static $_instance; 
    159  
    160         if (!isset($_instance)) { 
    161             $_instance = Inspekt_Cage::Factory($_POST, $config_file, '_POST', $strict); 
    162         } 
    163         $GLOBALS['HTTP_POST_VARS'] = null; 
    164         return $_instance; 
    165     } 
    166  
    167     /** 
    168      * Returns the $_COOKIE data wrapped in an Inspekt_Cage object 
    169      * 
    170      * This utilizes a singleton pattern to get around scoping issues 
    171      * 
    172      * @param string  $config_file 
    173      * @param boolean $strict whether or not to nullify the superglobal array 
    174      * @return Inspekt_Cage 
    175      */ 
    176     static public function makeCookieCage($config_file = null, $strict = true) 
    177     { 
    178         /** 
    179          * @staticvar $_instance 
    180          */ 
    181         static $_instance; 
    182  
    183         if (!isset($_instance)) { 
    184             $_instance = Inspekt_Cage::Factory($_COOKIE, $config_file, '_COOKIE', $strict); 
    185         } 
    186         $GLOBALS['HTTP_COOKIE_VARS'] = null; 
    187         return $_instance; 
    188     } 
    189  
    190     /** 
    191      * Returns the $_ENV data wrapped in an Inspekt_Cage object 
    192      * 
    193      * This utilizes a singleton pattern to get around scoping issues 
    194      * 
    195      * @param string  $config_file 
    196      * @param boolean $strict whether or not to nullify the superglobal array 
    197      * @return Inspekt_Cage 
    198      */ 
    199     static public function makeEnvCage($config_file = null, $strict = true) 
    200     { 
    201         /** 
    202          * @staticvar $_instance 
    203          */ 
    204         static $_instance; 
    205  
    206         if (!isset($_instance)) { 
    207             $_instance = Inspekt_Cage::Factory($_ENV, $config_file, '_ENV', $strict); 
    208         } 
    209         $GLOBALS['HTTP_ENV_VARS'] = null; 
    210         return $_instance; 
    211     } 
    212  
    213     /** 
    214      * Returns the $_FILES data wrapped in an Inspekt_Cage object 
    215      * 
    216      * This utilizes a singleton pattern to get around scoping issues 
    217      * 
    218      * @param string  $config_file 
    219      * @param boolean $strict whether or not to nullify the superglobal array 
    220      * @return Inspekt_Cage 
    221      */ 
    222     static public function makeFilesCage($config_file = null, $strict = true) 
    223     { 
    224         /** 
    225          * @staticvar $_instance 
    226          */ 
    227         static $_instance; 
    228  
    229         if (!isset($_instance)) { 
    230             $_instance = Inspekt_Cage::Factory($_FILES, $config_file, '_FILES', $strict); 
    231         } 
    232         $GLOBALS['HTTP_POST_FILES'] = null; 
    233         return $_instance; 
    234     } 
    235  
    236     /** 
    237      * Returns the $_SESSION data wrapped in an Inspekt_Cage object 
    238      * 
    239      * This utilizes a singleton pattern to get around scoping issues 
    240      * 
    241      * @param string  $config_file 
    242      * @param boolean $strict whether or not to nullify the superglobal array 
    243      * @return Inspekt_Cage 
    244      * @deprecated 
    245      */ 
    246     static public function makeSessionCage($config_file = null, $strict = true) 
    247     { 
    248         Inspekt_Error::raiseError('makeSessionCage is disabled in this version', E_USER_ERROR); 
    249  
    250         /** 
    251          * @staticvar $_instance 
    252          */ 
    253         static $_instance; 
    254  
    255         if (!isset($_SESSION)) { 
    256             return null; 
    257         } 
    258  
    259         if (!isset($_instance)) { 
    260             $_instance = Inspekt_Cage_Session::Factory($_SESSION, $config_file, '_SESSION', $strict); 
    261         } 
    262         $GLOBALS['HTTP_SESSION_VARS'] = null; 
    263         return $_instance; 
    264     } 
    265  
    266     /** 
    267      * Returns a Supercage object, which wraps ALL input superglobals 
    268      * 
    269      * @param string  $config_file 
    270      * @param boolean $strict whether or not to nullify the superglobal 
    271      * @return Inspekt_Supercage 
    272      */ 
    273     static public function makeSuperCage($config_file = null, $strict = true) 
    274     { 
    275         /** 
    276          * @staticvar $_instance 
    277          */ 
    278         static $_scinstance; 
    279  
    280         if (!isset($_scinstance)) { 
    281             $_scinstance = Inspekt_Supercage::Factory($config_file, $strict); 
    282         } 
    283         return $_scinstance; 
    284     } 
    285  
    286     /** 
    287      * Sets and/or retrieves whether we should use the PHP filter extensions where possible 
    288      * If a param is passed, it will set the state in addition to returning it 
    289      * 
    290      * We use this method of storing in a static class property so that we can access the value outside of class instances 
    291      * 
    292      * @param boolean $state optional 
    293      * @return boolean 
    294      */ 
    295     static public function useFilterExt($state = null) 
    296     { 
    297         if (isset($state)) { 
    298             Inspekt::$useFilterExtension = (bool) $state; 
    299         } 
    300         return Inspekt::$useFilterExtension; 
    301     } 
    302  
    303     /** 
    304      * Recursively walks an array and applies a given filter method to 
    305      * every value in the array. 
    306      * 
    307      * This should be considered a "protected" method, and not be called 
    308      * outside of the class 
    309      * 
    310      * @param array|ArrayObject $input 
    311      * @param string $inspektor  The name of a static filtering method, like get* or no* 
    312      * @return array 
    313      */ 
    314     static protected function _walkArray($input, $method, $classname = null) 
    315     { 
    316         if (!isset($classname)) { 
    317             $classname = __CLASS__; 
    318         } 
    319  
    320         if (!self::isArrayOrArrayObject($input) ) { 
    321             Inspekt_Error::raiseError('$input must be an array or ArrayObject', E_USER_ERROR); 
    322             return false; 
    323         } 
    324  
    325         if (!is_callable(array($classname, $method))) { 
    326             Inspekt_Error::raiseError('Inspektor ' . $classname . '::' . $method . ' is invalid', E_USER_ERROR); 
    327             return false; 
    328         } 
    329  
    330         foreach ($input as $key => $val) { 
    331             if (is_array($val)) { 
    332                 $input[$key]=self::_walkArray($val, $method, $classname); 
    333             } else { 
    334                 $val = call_user_func(array($classname, $method), $val); 
    335                 $input[$key] = $val; 
    336             } 
    337         } 
    338         return $input; 
    339     } 
    340  
    341     /** 
    342      * Checks to see if this is an ArrayObject 
    343      * @param mixed 
    344      * @return boolean 
    345      * @deprecated 
    346      * @link http://php.net/arrayobject 
    347      */ 
    348     static public function isArrayObject($obj) 
    349     { 
    350         $is = false; 
    351         //$is = (is_object($obj) && get_class($obj) === 'ArrayObject'); 
    352         $is = $obj instanceof ArrayObject; 
    353         return $is; 
    354     } 
    355  
    356     /** 
    357      * Checks to see if this is an array or an ArrayObject 
    358      * @param mixed 
    359      * @return boolean 
    360      * @link http://php.net/arrayobject 
    361      * @link http://php.net/array 
    362      */ 
    363     static public function isArrayOrArrayObject($arr) 
    364     { 
    365         $is = false; 
    366         $is = $arr instanceof ArrayObject || is_array($arr); 
    367         return $is; 
    368     } 
    369  
    370     /** 
    371      * Converts an array into an ArrayObject. We use ArrayObjects when walking arrays in Inspekt 
    372      * @param array 
    373      * @return ArrayObject 
    374      */ 
    375     static public function convertArrayToArrayObject(&$arr) 
    376     { 
    377         foreach ($arr as $key => $value) { 
    378             if (is_array($value)) { 
    379                 $value = new ArrayObject($value); 
    380                 $arr[$key] = $value; 
    381                 //echo $key." is an array\n"; 
    382                 Inspekt::convertArrayToArrayObject($arr[$key]); 
    383             } 
    384         } 
    385  
    386         return new ArrayObject($arr); 
    387     } 
    388  
    389     /** 
    390      * Returns only the alphabetic characters in value. 
    391      * 
    392      * @param mixed $value 
    393      * @return mixed 
    394      * 
    395      * @tag filter 
    396      */ 
    397     static public function getAlpha($value) 
    398     { 
    399         if (Inspekt::isArrayOrArrayObject($value)) { 
    400             return Inspekt::_walkArray($value, 'getAlpha'); 
    401         } else { 
    402             return preg_replace('/[^[:alpha:]]/', '', $value); 
    403         } 
    404     } 
    405  
    406     /** 
    407      * Returns only the alphabetic characters and digits in value. 
    408      * 
    409      * @param mixed $value 
    410      * @return mixed 
    411      * 
    412      * @tag filter 
    413      * 
    414      * @assert('1)@*(&UR)HQ)W(*(HG))') === '1URHQWHG' 
    415      */ 
    416     static public function getAlnum($value) 
    417     { 
    418         if (Inspekt::isArrayOrArrayObject($value)) { 
    419             return Inspekt::_walkArray($value, 'getAlnum'); 
    420         } else { 
    421             return preg_replace('/[^[:alnum:]]/', '', $value); 
    422         } 
    423     } 
    424  
    425     /** 
    426      * Returns only the digits in value. 
    427      * 
    428      * @param mixed $value 
    429      * @return mixed 
    430      * 
    431      * @tag filter 
    432      * 
    433      * @assert('1)@*(&UR)HQ)56W(*(HG))') === '156' 
    434      */ 
    435     static public function getDigits($value) 
    436     { 
    437         if (Inspekt::isArrayOrArrayObject($value)) { 
    438             return Inspekt::_walkArray($value, 'getDigits'); 
    439         } else { 
    440             return preg_replace('/[^[:digit:]]/', '', $value); 
    441         } 
    442     } 
    443  
    444     /** 
    445      * Returns dirname(value). 
    446      * 
    447      * @param mixed $value 
    448      * @return mixed 
    449      * 
    450      * @tag filter 
    451      * 
    452      * @assert('/usr/lib/php/Pear.php') === '/usr/lib/php' 
    453      */ 
    454     static public function getDir($value) 
    455     { 
    456         if (Inspekt::isArrayOrArrayObject($value)) { 
    457             return Inspekt::_walkArray($value, 'getDir'); 
    458         } else { 
    459             return dirname($value); 
    460         } 
    461     } 
    462  
    463     /** 
    464      * Returns (int) value. 
    465      * 
    466      * @param mixed $value 
    467      * @return int 
    468      * 
    469      * @tag filter 
    470      * 
    471      * @assert('1)45@*(&UR)HQ)W.0000(*(HG))') === 1 
    472      * @assert('A1)45@*(&UR)HQ)W.0000(*(HG))') === 0 
    473      */ 
    474     static public function getInt($value) 
    475     { 
    476         if (Inspekt::isArrayOrArrayObject($value)) { 
    477             return Inspekt::_walkArray($value, 'getInt'); 
    478         } else { 
    479             return (int) $value; 
    480         } 
    481     } 
    482  
    483     /** 
    484      * Returns realpath(value). 
    485      * 
    486      * @param mixed $value 
    487      * @return mixed 
    488      * 
    489      * @tag filter 
    490      */ 
    491     static public function getPath($value) 
    492     { 
    493         if (Inspekt::isArrayOrArrayObject($value)) { 
    494             return Inspekt::_walkArray($value, 'getPath'); 
    495         } else { 
    496             return realpath($value); 
    497         } 
    498     } 
    499  
    500     /** 
    501      * Returns the value encoded as ROT13 (or decoded, if already was ROT13) 
    502      * 
    503      * @param mixed $value 
    504      * @return mixed 
    505      * 
    506      * @link http://php.net/manual/en/function.str-rot13.php 
    507      */ 
    508     static public function getROT13($value) 
    509     { 
    510         if (Inspekt::isArrayOrArrayObject($value)) { 
    511             return Inspekt::_walkArray($value, 'getROT13'); 
    512         } else { 
    513             return str_rot13($value); 
    514         } 
    515     } 
    516  
    517     /** 
    518      * Returns true if every character is alphabetic or a digit, 
    519      * false otherwise. 
    520      * 
    521      * @param mixed $value 
    522      * @return boolean 
    523      * 
    524      * @tag validator 
    525      * 
    526      * @assert('NCOFWIERNVOWIEBHV12047057y0650ytg0314') === true 
    527      * @assert('NCOFWIERNVOWIEBHV2@12047057y0650ytg0314') === false 
    528      * @assert('funkatron') === true 
    529      * @assert('funkatron_user') === false 
    530      * @assert('funkatron-user') === false 
    531      * @assert('_funkatronuser') === false 
    532      */ 
    533     static public function isAlnum($value) 
    534     { 
    535         return ctype_alnum($value); 
    536     } 
    537  
    538     /** 
    539      * Returns true if every character is alphabetic, false 
    540      * otherwise. 
    541      * 
    542      * @param mixed $value 
    543      * @return boolean 
    544      * 
    545      * @tag validator 
    546      * 
    547      * @assert('NCOFWIERNVOWIEBHV12047057y0650ytg0314') === false 
    548      * @assert('NCOFWIERNVOWIEBHV2@12047057y0650ytg0314') === false 
    549      * @assert('funkatron') === true 
    550      * @assert('funkatron_user') === false 
    551      * @assert('funkatron-user') === false 
    552      * @assert('_funkatronuser') === false 
    553      */ 
    554     static public function isAlpha($value) 
    555     { 
    556         return ctype_alpha($value); 
    557     } 
    558  
    559     /** 
    560      * Returns true if value is greater than or equal to $min and less 
    561      * than or equal to $max, false otherwise. If $inc is set to 
    562      * false, then the value must be strictly greater than $min and 
    563      * strictly less than $max. 
    564      * 
    565      * @param mixed $value 
    566      * @param mixed $min 
    567      * @param mixed $max 
    568      * @return boolean 
    569      * 
    570      * @tag validator 
    571      * 
    572      * @assert(12, 0, 12) === true 
    573      * @assert(12, 0, 12, false) === false 
    574      * @assert('f', 'a', 'm', false) === true 
    575      * @assert('p', 'a', 'm', false) === false 
    576      */ 
    577     static public function isBetween($value, $min, $max, $inc = true) 
    578     { 
    579         if ($value > $min && 
    580             $value < $max) { 
    581             return true; 
    582         } 
    583  
    584         if ($inc && 
    585             $value >= $min && 
    586             $value <= $max) { 
    587             return true; 
    588         } 
    589  
    590         return false; 
    591     } 
    592  
    593     /** 
    594      * Returns true if it is a valid credit card number format. The 
    595      * optional second argument allows developers to indicate the 
    596      * type. 
    597      * 
    598      * @param mixed $value 
    599      * @param mixed $type 
    600      * @return boolean 
    601      * 
    602      * @tag validator 
    603      */ 
    604     static public function isCcnum($value, $type = null) 
    605     { 
    606         /** 
    607          * @todo Type-specific checks 
    608          */ 
    609         if (isset($type)) { 
    610             Inspekt_Error::raiseError('Type-specific cc checks are not yet supported'); 
    611         } 
    612  
    613         $value = self::getDigits($value); 
    614         $length = strlen($value); 
    615  
    616         if ($length < 13 || $length > 19) { 
    617             return false; 
    618         } 
    619  
    620         $sum = 0; 
    621         $weight = 2; 
    622  
    623         for ($i = $length - 2; $i >= 0; $i--) { 
    624             $digit = $weight * $value[$i]; 
    625             $sum += floor($digit / 10) + $digit % 10; 
    626             $weight = $weight % 2 + 1; 
    627         } 
    628  
    629         $mod = (10 - $sum % 10) % 10; 
    630  
    631         return ($mod == $value[$length - 1]); 
    632     } 
    633  
    634     /** 
    635      * Returns true if value is a valid date, false otherwise. The 
    636      * date is required to be in ISO 8601 format. 
    637      * 
    638      * @param mixed $value 
    639      * @return boolean 
    640      * 
    641      * @tag validator 
    642      * 
    643      * @assert('2009-06-30') === true 
    644      * @assert('2009-06-31') === false 
    645      * @assert('2009-6-30') === true 
    646      * @assert('2-6-30') === true 
    647      */ 
    648     static public function isDate($value) 
    649     { 
    650         list($year, $month, $day) = sscanf($value, '%d-%d-%d'); 
    651  
    652         return checkdate($month, $day, $year); 
    653     } 
    654  
    655     /** 
    656      * Returns true if every character is a digit, false otherwise. 
    657      * This is just like isInt(), except there is no upper limit. 
    658      * 
    659      * @param mixed $value 
    660      * @return boolean 
    661      * 
    662      * @tag validator 
    663      * 
    664      * @assert('1029438750192730t91740987023948') === false 
    665      * @assert('102943875019273091740987023948') === true 
    666      * @assert(102943875019273091740987023948) === false 
    667      */ 
    668     static public function isDigits($value) 
    669     { 
    670         return ctype_digit((string) $value); 
    671     } 
    672  
    673     /** 
    674      * Returns true if value is a valid email format, false otherwise. 
    675      * 
    676      * @param string $value 
    677      * @return boolean 
    678      * @see http://www.regular-expressions.info/email.html 
    679      * @see ISPK_EMAIL_VALID 
    680      * 
    681      * @tag validator 
    682      * 
    683      * @assert('coj@poop.com') === true 
    684      * @assert('coj+booboo@poop.com') === true 
    685      * @assert('coj!booboo@poop.com') === false 
    686      * @assert('@poop.com') === false 
    687      * @assert('a@b') === false 
    688      * @assert('webmaster') === false 
    689      */ 
    690     static public function isEmail($value) 
    691     { 
    692         return (bool) preg_match(ISPK_EMAIL_VALID, $value); 
    693     } 
    694  
    695     /** 
    696      * Returns true if value is a valid float value, false otherwise. 
    697      * 
    698      * @param string $value 
    699      * @return boolean 
    700      * 
    701      * @assert(10244578109.234451) === true 
    702      * @assert('10244578109.234451') === false 
    703      * @assert('10,244,578,109.234451') === false 
    704      * 
    705      * @tag validator 
    706      */ 
    707     static public function isFloat($value) 
    708     { 
    709         $locale = localeconv(); 
    710         $value = str_replace($locale['decimal_point'], '.', $value); 
    711         $value = str_replace($locale['thousands_sep'], '', $value); 
    712  
    713         return (strval(floatval($value)) == $value); 
    714     } 
    715  
    716     /** 
    717      * Returns true if value is greater than $min, false otherwise. 
    718      * 
    719      * @param mixed $value 
    720      * @param mixed $min 
    721      * @return boolean 
    722      * 
    723      * @tag validator 
    724      * 
    725      * @assert(5, 0) === true 
    726      * @assert(2, 10) === false 
    727      * @assert('b', 'a') === true 
    728      * @assert('a', 'b') === false 
    729      */ 
    730     static public function isGreaterThan($value, $min) 
    731     { 
    732         return ($value > $min); 
    733     } 
    734  
    735     /** 
    736      * Returns true if value is a valid hexadecimal format, false 
    737      * otherwise. 
    738      * 
    739      * @param mixed $value 
    740      * @return boolean 
    741      * 
    742      * @tag validator 
    743      * 
    744      * @assert('6F') === true 
    745      * @assert('F6') === true 
    746      * 
    747      */ 
    748     static public function isHex($value) 
    749     { 
    750         return ctype_xdigit($value); 
    751     } 
    752  
    753     /** 
    754      * Returns true if value is a valid hostname, false otherwise. 
    755      * Depending upon the value of $allow, Internet domain names, IP 
    756      * addresses, and/or local network names are considered valid. 
    757      * The default is HOST_ALLOW_ALL, which considers all of the 
    758      * above to be valid. 
    759      * 
    760      * @param mixed $value 
    761      * @param integer $allow bitfield for ISPK_HOST_ALLOW_DNS, ISPK_HOST_ALLOW_IP, ISPK_HOST_ALLOW_LOCAL 
    762      * @return boolean 
    763      * 
    764      * @tag validator 
    765      */ 
    766     static public function isHostname($value, $allow = ISPK_HOST_ALLOW_ALL) 
    767     { 
    768         if (!is_numeric($allow) || !is_int($allow)) { 
    769             Inspekt_Error::raiseError('Illegal value for $allow; expected an integer', E_USER_WARNING); 
    770         } 
    771  
    772         if ($allow < ISPK_HOST_ALLOW_DNS || ISPK_HOST_ALLOW_ALL < $allow) { 
    773             Inspekt_Error::raiseError('Illegal value for $allow; expected integer between ' . ISPK_HOST_ALLOW_DNS . ' and ' . ISPK_HOST_ALLOW_ALL, E_USER_WARNING); 
    774         } 
    775  
    776         // determine whether the input is formed as an IP address 
    777         $status = self::isIp($value); 
    778  
    779         // if the input looks like an IP address 
    780         if ($status) { 
    781             // if IP addresses are not allowed, then fail validation 
    782             if (($allow & ISPK_HOST_ALLOW_IP) == 0) { 
     93 
     94        protected static $useFilterExtension = true; 
     95 
     96        /** 
     97         * Returns the $_SERVER data wrapped in an Inspekt_Cage object 
     98         * 
     99         * This utilizes a singleton pattern to get around scoping issues 
     100         * 
     101         * @param string  $config_file 
     102         * @param boolean $strict whether or not to nullify the superglobal array 
     103         * @return Inspekt_Cage 
     104         * 
     105         * @assert() 
     106         */ 
     107        static public function makeServerCage($config_file = null, $strict = true) 
     108        { 
     109                /** 
     110                 * @staticvar $_instance 
     111                 */ 
     112                static $_instance; 
     113 
     114                if (!isset($_instance)) { 
     115                        $_instance = Inspekt_Cage::Factory($_SERVER, $config_file, '_SERVER', $strict); 
     116                } 
     117                $GLOBALS['HTTP_SERVER_VARS'] = null; 
     118                return $_instance; 
     119        } 
     120 
     121        /** 
     122         * Returns the $_GET data wrapped in an Inspekt_Cage object 
     123         * 
     124         * This utilizes a singleton pattern to get around scoping issues 
     125         * 
     126         * @param string  $config_file 
     127         * @param boolean $strict whether or not to nullify the superglobal array 
     128         * @return Inspekt_Cage 
     129         */ 
     130        static public function makeGetCage($config_file = null, $strict = true) 
     131        { 
     132                /** 
     133                 * @staticvar $_instance 
     134                 */ 
     135                static $_instance; 
     136 
     137                if (!isset($_instance)) { 
     138                        $_instance = Inspekt_Cage::Factory($_GET, $config_file, '_GET', $strict); 
     139                } 
     140                $GLOBALS['HTTP_GET_VARS'] = null; 
     141                return $_instance; 
     142        } 
     143 
     144        /** 
     145         * Returns the $_POST data wrapped in an Inspekt_Cage object 
     146         * 
     147         * This utilizes a singleton pattern to get around scoping issues 
     148         * 
     149         * @param string  $config_file 
     150         * @param boolean $strict whether or not to nullify the superglobal array 
     151         * @return Inspekt_Cage 
     152         */ 
     153        static public function makePostCage($config_file = null, $strict = true) 
     154        { 
     155                /** 
     156                 * @staticvar $_instance 
     157                 */ 
     158                static $_instance; 
     159 
     160                if (!isset($_instance)) { 
     161                        $_instance = Inspekt_Cage::Factory($_POST, $config_file, '_POST', $strict); 
     162                } 
     163                $GLOBALS['HTTP_POST_VARS'] = null; 
     164                return $_instance; 
     165        } 
     166 
     167        /** 
     168         * Returns the $_COOKIE data wrapped in an Inspekt_Cage object 
     169         * 
     170         * This utilizes a singleton pattern to get around scoping issues 
     171         * 
     172         * @param string  $config_file 
     173         * @param boolean $strict whether or not to nullify the superglobal array 
     174         * @return Inspekt_Cage 
     175         */ 
     176        static public function makeCookieCage($config_file = null, $strict = true) 
     177        { 
     178                /** 
     179                 * @staticvar $_instance 
     180                 */ 
     181                static $_instance; 
     182 
     183                if (!isset($_instance)) { 
     184                        $_instance = Inspekt_Cage::Factory($_COOKIE, $config_file, '_COOKIE', $strict); 
     185                } 
     186                $GLOBALS['HTTP_COOKIE_VARS'] = null; 
     187                return $_instance; 
     188        } 
     189 
     190        /** 
     191         * Returns the $_ENV data wrapped in an Inspekt_Cage object 
     192         * 
     193         * This utilizes a singleton pattern to get around scoping issues 
     194         * 
     195         * @param string  $config_file 
     196         * @param boolean $strict whether or not to nullify the superglobal array 
     197         * @return Inspekt_Cage 
     198         */ 
     199        static public function makeEnvCage($config_file = null, $strict = true) 
     200        { 
     201                /** 
     202                 * @staticvar $_instance 
     203                 */ 
     204                static $_instance; 
     205 
     206                if (!isset($_instance)) { 
     207                        $_instance = Inspekt_Cage::Factory($_ENV, $config_file, '_ENV', $strict); 
     208                } 
     209                $GLOBALS['HTTP_ENV_VARS'] = null; 
     210                return $_instance; 
     211        } 
     212 
     213        /** 
     214         * Returns the $_FILES data wrapped in an Inspekt_Cage object 
     215         * 
     216         * This utilizes a singleton pattern to get around scoping issues 
     217         * 
     218         * @param string  $config_file 
     219         * @param boolean $strict whether or not to nullify the superglobal array 
     220         * @return Inspekt_Cage 
     221         */ 
     222        static public function makeFilesCage($config_file = null, $strict = true) 
     223        { 
     224                /** 
     225                 * @staticvar $_instance 
     226                 */ 
     227                static $_instance; 
     228 
     229                if (!isset($_instance)) { 
     230                        $_instance = Inspekt_Cage::Factory($_FILES, $config_file, '_FILES', $strict); 
     231                } 
     232                $GLOBALS['HTTP_POST_FILES'] = null; 
     233                return $_instance; 
     234        } 
     235 
     236        /** 
     237         * Returns the $_SESSION data wrapped in an Inspekt_Cage object 
     238         * 
     239         * This utilizes a singleton pattern to get around scoping issues 
     240         * 
     241         * @param string  $config_file 
     242         * @param boolean $strict whether or not to nullify the superglobal array 
     243         * @return Inspekt_Cage 
     244         * @deprecated 
     245         */ 
     246        static public function makeSessionCage($config_file = null, $strict = true) 
     247        { 
     248                Inspekt_Error::raiseError('makeSessionCage is disabled in this version', E_USER_ERROR); 
     249 
     250                /** 
     251                 * @staticvar $_instance 
     252                 */ 
     253                static $_instance; 
     254 
     255                if (!isset($_SESSION)) { 
     256                        return null; 
     257                } 
     258 
     259                if (!isset($_instance)) { 
     260                        $_instance = Inspekt_Cage_Session::Factory($_SESSION, $config_file, '_SESSION', $strict); 
     261                } 
     262                $GLOBALS['HTTP_SESSION_VARS'] = null; 
     263                return $_instance; 
     264        } 
     265 
     266        /** 
     267         * Returns a Supercage object, which wraps ALL input superglobals 
     268         * 
     269         * @param string  $config_file 
     270         * @param boolean $strict whether or not to nullify the superglobal 
     271         * @return Inspekt_Supercage 
     272         */ 
     273        static public function makeSuperCage($config_file = null, $strict = true) 
     274        { 
     275                /** 
     276                 * @staticvar $_instance 
     277                 */ 
     278                static $_scinstance; 
     279 
     280                if (!isset($_scinstance)) { 
     281                        $_scinstance = Inspekt_Supercage::Factory($config_file, $strict); 
     282                } 
     283                return $_scinstance; 
     284        } 
     285 
     286        /** 
     287         * Sets and/or retrieves whether we should use the PHP filter extensions where possible 
     288         * If a param is passed, it will set the state in addition to returning it 
     289         * 
     290         * We use this method of storing in a static class property so that we can access the value outside of class instances 
     291         * 
     292         * @param boolean $state optional 
     293         * @return boolean 
     294         */ 
     295        static public function useFilterExt($state = null) 
     296        { 
     297                if (isset($state)) { 
     298                        Inspekt::$useFilterExtension = (bool) $state; 
     299                } 
     300                return Inspekt::$useFilterExtension; 
     301        } 
     302 
     303        /** 
     304         * Recursively walks an array and applies a given filter method to 
     305         * every value in the array. 
     306         * 
     307         * This should be considered a "protected" method, and not be called 
     308         * outside of the class 
     309         * 
     310         * @param array|ArrayObject $input 
     311         * @param string $inspektor  The name of a static filtering method, like get* or no* 
     312         * @return array 
     313         */ 
     314        static protected function _walkArray($input, $method, $classname = null) 
     315        { 
     316                if (!isset($classname)) { 
     317                        $classname = __CLASS__; 
     318                } 
     319 
     320                if (!self::isArrayOrArrayObject($input)) { 
     321                        Inspekt_Error::raiseError('$input must be an array or ArrayObject', E_USER_ERROR); 
     322                        return false; 
     323                } 
     324 
     325                if (!is_callable(array($classname, $method))) { 
     326                        Inspekt_Error::raiseError('Inspektor '.$classname.'::'.$method.' is invalid', E_USER_ERROR); 
     327                        return false; 
     328                } 
     329 
     330                foreach ($input as $key => $val) { 
     331                        if (is_array($val)) { 
     332                                $input[$key] = self::_walkArray($val, $method, $classname); 
     333                        } else { 
     334                                $val = call_user_func(array($classname, $method), $val); 
     335                                $input[$key] = $val; 
     336                        } 
     337                } 
     338                return $input; 
     339        } 
     340 
     341        /** 
     342         * Checks to see if this is an ArrayObject 
     343         * @param mixed 
     344         * @return boolean 
     345         * @deprecated 
     346         * @link http://php.net/arrayobject 
     347         */ 
     348        static public function isArrayObject($obj) 
     349        { 
     350                $is = false; 
     351                //$is = (is_object($obj) && get_class($obj) === 'ArrayObject'); 
     352                $is = $obj instanceof ArrayObject; 
     353                return $is; 
     354        } 
     355 
     356        /** 
     357         * Checks to see if this is an array or an ArrayObject 
     358         * @param mixed 
     359         * @return boolean 
     360         * @link http://php.net/arrayobject 
     361         * @link http://php.net/array 
     362         */ 
     363        static public function isArrayOrArrayObject($arr) 
     364        { 
     365                $is = false; 
     366                $is = $arr instanceof ArrayObject || is_array($arr); 
     367                return $is; 
     368        } 
     369 
     370        /** 
     371         * Converts an array into an ArrayObject. We use ArrayObjects when walking arrays in Inspekt 
     372         * @param array 
     373         * @return ArrayObject 
     374         */ 
     375        static public function convertArrayToArrayObject(&$arr) 
     376        { 
     377                foreach ($arr as $key => $value) { 
     378                        if (is_array($value)) { 
     379                                $value = new ArrayObject($value); 
     380                                $arr[$key] = $value; 
     381                                //echo $key." is an array\n"; 
     382                                Inspekt::convertArrayToArrayObject($arr[$key]); 
     383                        } 
     384                } 
     385 
     386                return new ArrayObject($arr); 
     387        } 
     388 
     389        /** 
     390         * Returns only the alphabetic characters in value. 
     391         * 
     392         * @param mixed $value 
     393         * @return mixed 
     394         * 
     395         * @tag filter 
     396         */ 
     397        static public function getAlpha($value) 
     398        { 
     399                if (Inspekt::isArrayOrArrayObject($value)) { 
     400                        return Inspekt::_walkArray($value, 'getAlpha'); 
     401                } else { 
     402                        return preg_replace('/[^[:alpha:]]/', '', $value); 
     403                } 
     404        } 
     405 
     406        /** 
     407         * Returns only the alphabetic characters and digits in value. 
     408         * 
     409         * @param mixed $value 
     410         * @return mixed 
     411         * 
     412         * @tag filter 
     413         * 
     414         * @assert('1)@*(&UR)HQ)W(*(HG))') === '1URHQWHG' 
     415         */ 
     416        static public function getAlnum($value) 
     417        { 
     418                if (Inspekt::isArrayOrArrayObject($value)) { 
     419                        return Inspekt::_walkArray($value, 'getAlnum'); 
     420                } else { 
     421                        return preg_replace('/[^[:alnum:]]/', '', $value); 
     422                } 
     423        } 
     424 
     425        /** 
     426         * Returns only the digits in value. 
     427         * 
     428         * @param mixed $value 
     429         * @return mixed 
     430         * 
     431         * @tag filter 
     432         * 
     433         * @assert('1)@*(&UR)HQ)56W(*(HG))') === '156' 
     434         */ 
     435        static public function getDigits($value) 
     436        { 
     437                if (Inspekt::isArrayOrArrayObject($value)) { 
     438                        return Inspekt::_walkArray($value, 'getDigits'); 
     439                } else { 
     440                        return preg_replace('/[^[:digit:]]/', '', $value); 
     441                } 
     442        } 
     443 
     444        /** 
     445         * Returns dirname(value). 
     446         * 
     447         * @param mixed $value 
     448         * @return mixed 
     449         * 
     450         * @tag filter 
     451         * 
     452         * @assert('/usr/lib/php/Pear.php') === '/usr/lib/php' 
     453         */ 
     454        static public function getDir($value) 
     455        { 
     456                if (Inspekt::isArrayOrArrayObject($value)) { 
     457                        return Inspekt::_walkArray($value, 'getDir'); 
     458                } else { 
     459                        return dirname($value); 
     460                } 
     461        } 
     462 
     463        /** 
     464         * Returns (int) value. 
     465         * 
     466         * @param mixed $value 
     467         * @return int 
     468         * 
     469         * @tag filter 
     470         * 
     471         * @assert('1)45@*(&UR)HQ)W.0000(*(HG))') === 1 
     472         * @assert('A1)45@*(&UR)HQ)W.0000(*(HG))') === 0 
     473         */ 
     474        static public function getInt($value) 
     475        { 
     476                if (Inspekt::isArrayOrArrayObject($value)) { 
     477                        return Inspekt::_walkArray($value, 'getInt'); 
     478                } else { 
     479                        return (int) $value; 
     480                } 
     481        } 
     482 
     483        /** 
     484         * Returns realpath(value). 
     485         * 
     486         * @param mixed $value 
     487         * @return mixed 
     488         * 
     489         * @tag filter 
     490         */ 
     491        static public function getPath($value) 
     492        { 
     493                if (Inspekt::isArrayOrArrayObject($value)) { 
     494                        return Inspekt::_walkArray($value, 'getPath'); 
     495                } else { 
     496                        return realpath($value); 
     497                } 
     498        } 
     499 
     500        /** 
     501         * Returns the value encoded as ROT13 (or decoded, if already was ROT13) 
     502         * 
     503         * @param mixed $value 
     504         * @return mixed 
     505         * 
     506         * @link http://php.net/manual/en/function.str-rot13.php 
     507         */ 
     508        static public function getROT13($value) 
     509        { 
     510                if (Inspekt::isArrayOrArrayObject($value)) { 
     511                        return Inspekt::_walkArray($value, 'getROT13'); 
     512                } else { 
     513                        return str_rot13($value); 
     514                } 
     515        } 
     516 
     517        /** 
     518         * Returns true if every character is alphabetic or a digit, 
     519         * false otherwise. 
     520         * 
     521         * @param mixed $value 
     522         * @return boolean 
     523         * 
     524         * @tag validator 
     525         * 
     526         * @assert('NCOFWIERNVOWIEBHV12047057y0650ytg0314') === true 
     527         * @assert('NCOFWIERNVOWIEBHV2@12047057y0650ytg0314') === false 
     528         * @assert('funkatron') === true 
     529         * @assert('funkatron_user') === false 
     530         * @assert('funkatron-user') === false 
     531         * @assert('_funkatronuser') === false 
     532         */ 
     533        static public function isAlnum($value) 
     534        { 
     535                return ctype_alnum($value); 
     536        } 
     537 
     538        /** 
     539         * Returns true if every character is alphabetic, false 
     540         * otherwise. 
     541         * 
     542         * @param mixed $value 
     543         * @return boolean 
     544         * 
     545         * @tag validator 
     546         * 
     547         * @assert('NCOFWIERNVOWIEBHV12047057y0650ytg0314') === false 
     548         * @assert('NCOFWIERNVOWIEBHV2@12047057y0650ytg0314') === false 
     549         * @assert('funkatron') === true 
     550         * @assert('funkatron_user') === false 
     551         * @assert('funkatron-user') === false 
     552         * @assert('_funkatronuser') === false 
     553         */ 
     554        static public function isAlpha($value) 
     555        { 
     556                return ctype_alpha($value); 
     557        } 
     558 
     559        /** 
     560         * Returns true if value is greater than or equal to $min and less 
     561         * than or equal to $max, false otherwise. If $inc is set to 
     562         * false, then the value must be strictly greater than $min and 
     563         * strictly less than $max. 
     564         * 
     565         * @param mixed $value 
     566         * @param mixed $min 
     567         * @param mixed $max 
     568         * @return boolean 
     569         * 
     570         * @tag validator 
     571         * 
     572         * @assert(12, 0, 12) === true 
     573         * @assert(12, 0, 12, false) === false 
     574         * @assert('f', 'a', 'm', false) === true 
     575         * @assert('p', 'a', 'm', false) === false 
     576         */ 
     577        static public function isBetween($value, $min, $max, $inc = true) 
     578        { 
     579                if ($value > $min && $value < $max) { 
     580                        return true; 
     581                } 
     582 
     583                if ($inc && $value >= $min && $value <= $max) { 
     584                        return true; 
     585                } 
     586 
    783587                return false; 
    784             } 
    785  
    786             // IP passed validation 
    787             return true; 
    788         } 
    789  
    790         // check input against domain name schema 
    791         $status = @preg_match('/^(?:[^\W_]((?:[^\W_]|-){0,61}[^\W_])?\.)+[a-zA-Z]{2,6}\.?$/', $value); 
    792         if ($status === false) { 
    793             Inspekt_Error::raiseError('Internal error: DNS validation failed', E_USER_WARNING); 
    794         } 
    795  
    796         // if the input passes as an Internet domain name, and domain names are allowed, then the hostname 
    797         // passes validation 
    798         if ($status == 1 && ($allow & ISPK_HOST_ALLOW_DNS) != 0) { 
    799             return true; 
    800         } 
    801  
    802         // if local network names are not allowed, then fail validation 
    803         if (($allow & ISPK_HOST_ALLOW_LOCAL) == 0) { 
    804             return false; 
    805         } 
    806  
    807         // check input against local network name schema; last chance to pass validation 
    808         $status = @preg_match('/^(?:[^\W_](?:[^\W_]|-){0,61}[^\W_]\.)*(?:[^\W_](?:[^\W_]|-){0,61}[^\W_])\.?$/', 
    809             $value); 
    810         if ($status === false) { 
    811             Inspekt_Error::raiseError('Internal error: local network name validation failed', E_USER_WARNING); 
    812         } 
    813  
    814         if ($status == 0) { 
    815             return false; 
    816         } else { 
    817             return true; 
    818         } 
    819     } 
    820  
    821     /** 
    822      * Returns true if value is a valid integer value, false otherwise. 
    823      * 
    824      * @param string|array $value 
    825      * @return boolean 
    826      * 
    827      * @tag validator 
    828      * 
    829      * @todo better handling of diffs b/t 32-bit and 64-bit 
    830      */ 
    831     static public function isInt($value) 
    832     { 
    833         $locale = localeconv(); 
    834  
    835         $value = str_replace($locale['decimal_point'], '.', $value); 
    836         $value = str_replace($locale['thousands_sep'], '', $value); 
    837  
    838 /*      $is_valid = ( 
    839             is_numeric($value)  // Must be able to be converted to a number 
    840                 && preg_replace("/^-?([0-9]+)$/", "", $value) == ""  // Must be an integer (no floats or e-powers) 
    841                 && bccomp($value, "-9223372036854775807") >= 0  // Must be greater than than min of 64-bit 
    842                 && bccomp($value, "9223372036854775807") <= 0  // Must be less than max of 64-bit 
    843                 );*/ 
     588        } 
     589 
     590        /** 
     591         * Returns true if it is a valid credit card number format. The 
     592         * optional second argument allows developers to indicate the 
     593         * type. 
     594         * 
     595         * @param mixed $value 
     596         * @param mixed $type 
     597         * @return boolean 
     598         * 
     599         * @tag validator 
     600         */ 
     601        static public function isCcnum($value, $type = null) 
     602        { 
     603                /** 
     604                 * @todo Type-specific checks 
     605                 */ 
     606                if (isset($type)) { 
     607                        Inspekt_Error::raiseError('Type-specific cc checks are not yet supported'); 
     608                } 
     609 
     610                $value = self::getDigits($value); 
     611                $length = strlen($value); 
     612 
     613                if ($length < 13 || $length > 19) { 
     614                        return false; 
     615                } 
     616 
     617                $sum = 0; 
     618                $weight = 2; 
     619 
     620                for ($i = $length - 2; $i >= 0; $i--) { 
     621                        $digit = $weight * $value[$i]; 
     622                        $sum += floor($digit / 10) + $digit % 10; 
     623                        $weight = $weight % 2 + 1; 
     624                } 
     625 
     626                $mod = (10 - $sum % 10) % 10; 
     627 
     628                return ($mod == $value[$length - 1]); 
     629        } 
     630 
     631        /** 
     632         * Returns true if value is a valid date, false otherwise. The 
     633         * date is required to be in ISO 8601 format. 
     634         * 
     635         * @param mixed $value 
     636         * @return boolean 
     637         * 
     638         * @tag validator 
     639         * 
     640         * @assert('2009-06-30') === true 
     641         * @assert('2009-06-31') === false 
     642         * @assert('2009-6-30') === true 
     643         * @assert('2-6-30') === true 
     644         */ 
     645        static public function isDate($value) 
     646        { 
     647                list($year, $month, $day) = sscanf($value, '%d-%d-%d'); 
     648 
     649                return checkdate($month, $day, $year); 
     650        } 
     651 
     652        /** 
     653         * Returns true if every character is a digit, false otherwise. 
     654         * This is just like isInt(), except there is no upper limit. 
     655         * 
     656         * @param mixed $value 
     657         * @return boolean 
     658         * 
     659         * @tag validator 
     660         * 
     661         * @assert('1029438750192730t91740987023948') === false 
     662         * @assert('102943875019273091740987023948') === true 
     663         * @assert(102943875019273091740987023948) === false 
     664         */ 
     665        static public function isDigits($value) 
     666        { 
     667                return ctype_digit((string) $value); 
     668        } 
     669 
     670        /** 
     671         * Returns true if value is a valid email format, false otherwise. 
     672         * 
     673         * @param string $value 
     674         * @return boolean 
     675         * @see http://www.regular-expressions.info/email.html 
     676         * @see ISPK_EMAIL_VALID 
     677         * 
     678         * @tag validator 
     679         * 
     680         * @assert('coj@poop.com') === true 
     681         * @assert('coj+booboo@poop.com') === true 
     682         * @assert('coj!booboo@poop.com') === false 
     683         * @assert('@poop.com') === false 
     684         * @assert('a@b') === false 
     685         * @assert('webmaster') === false 
     686         */ 
     687        static public function isEmail($value) 
     688        { 
     689                return (bool) preg_match(ISPK_EMAIL_VALID, $value); 
     690        } 
     691 
     692        /** 
     693         * Returns true if value is a valid float value, false otherwise. 
     694         * 
     695         * @param string $value 
     696         * @return boolean 
     697         * 
     698         * @assert(10244578109.234451) === true 
     699         * @assert('10244578109.234451') === false 
     700         * @assert('10,244,578,109.234451') === false 
     701         * 
     702         * @tag validator 
     703         */ 
     704        static public function isFloat($value) 
     705        { 
     706                $locale = localeconv(); 
     707                $value = str_replace($locale['decimal_point'], '.', $value); 
     708                $value = str_replace($locale['thousands_sep'], '', $value); 
     709 
     710                return (strval(floatval($value)) == $value); 
     711        } 
     712 
     713        /** 
     714         * Returns true if value is greater than $min, false otherwise. 
     715         * 
     716         * @param mixed $value 
     717         * @param mixed $min 
     718         * @return boolean 
     719         * 
     720         * @tag validator 
     721         * 
     722         * @assert(5, 0) === true 
     723         * @assert(2, 10) === false 
     724         * @assert('b', 'a') === true 
     725         * @assert('a', 'b') === false 
     726         */ 
     727        static public function isGreaterThan($value, $min) 
     728        { 
     729                return ($value > $min); 
     730        } 
     731 
     732        /** 
     733         * Returns true if value is a valid hexadecimal format, false 
     734         * otherwise. 
     735         * 
     736         * @param mixed $value 
     737         * @return boolean 
     738         * 
     739         * @tag validator 
     740         * 
     741         * @assert('6F') === true 
     742         * @assert('F6') === true 
     743         * 
     744         */ 
     745        static public function isHex($value) 
     746        { 
     747                return ctype_xdigit($value); 
     748        } 
     749 
     750        /** 
     751         * Returns true if value is a valid hostname, false otherwise. 
     752         * Depending upon the value of $allow, Internet domain names, IP 
     753         * addresses, and/or local network names are considered valid. 
     754         * The default is HOST_ALLOW_ALL, which considers all of the 
     755         * above to be valid. 
     756         * 
     757         * @param mixed $value 
     758         * @param integer $allow bitfield for ISPK_HOST_ALLOW_DNS, ISPK_HOST_ALLOW_IP, ISPK_HOST_ALLOW_LOCAL 
     759         * @return boolean 
     760         * 
     761         * @tag validator 
     762         */ 
     763        static public function isHostname($value, $allow = ISPK_HOST_ALLOW_ALL) 
     764        { 
     765                if (!is_numeric($allow) || !is_int($allow)) { 
     766                        Inspekt_Error::raiseError('Illegal value for $allow; expected an integer', E_USER_WARNING); 
     767                } 
     768 
     769                if ($allow < ISPK_HOST_ALLOW_DNS || ISPK_HOST_ALLOW_ALL < $allow) { 
     770                        Inspekt_Error::raiseError('Illegal value for $allow; expected integer between '.ISPK_HOST_ALLOW_DNS.' and '.ISPK_HOST_ALLOW_ALL, E_USER_WARNING); 
     771                } 
     772 
     773                // determine whether the input is formed as an IP address 
     774                $status = self::isIp($value); 
     775 
     776                // if the input looks like an IP address 
     777                if ($status) { 
     778                        // if IP addresses are not allowed, then fail validation 
     779                        if (($allow & ISPK_HOST_ALLOW_IP) == 0) { 
     780                                return false; 
     781                        } 
     782 
     783                        // IP passed validation 
     784                        return true; 
     785                } 
     786 
     787                // check input against domain name schema 
     788                $status = @preg_match('/^(?:[^\W_]((?:[^\W_]|-){0,61}[^\W_])?\.)+[a-zA-Z]{2,6}\.?$/', $value); 
     789                if ($status === false) { 
     790                        Inspekt_Error::raiseError('Internal error: DNS validation failed', E_USER_WARNING); 
     791                } 
     792 
     793                // if the input passes as an Internet domain name, and domain names are allowed, then the hostname 
     794                // passes validation 
     795                if ($status == 1 && ($allow & ISPK_HOST_ALLOW_DNS) != 0) { 
     796                        return true; 
     797                } 
     798 
     799                // if local network names are not allowed, then fail validation 
     800                if (($allow & ISPK_HOST_ALLOW_LOCAL) == 0) { 
     801                        return false; 
     802                } 
     803 
     804                // check input against local network name schema; last chance to pass validation 
     805                $status = @preg_match('/^(?:[^\W_](?:[^\W_]|-){0,61}[^\W_]\.)*(?:[^\W_](?:[^\W_]|-){0,61}[^\W_])\.?$/', 
     806                                                $value); 
     807                if ($status === false) { 
     808                        Inspekt_Error::raiseError('Internal error: local network name validation failed', E_USER_WARNING); 
     809                } 
     810 
     811                if ($status == 0) { 
     812                        return false; 
     813                } else { 
     814                        return true; 
     815                } 
     816        } 
     817 
     818        /** 
     819         * Returns true if value is a valid integer value, false otherwise. 
     820         * 
     821         * @param string|array $value 
     822         * @return boolean 
     823         * 
     824         * @tag validator 
     825         * 
     826         * @todo better handling of diffs b/t 32-bit and 64-bit 
     827         */ 
     828        static public function isInt($value) 
     829        { 
     830                $locale = localeconv(); 
     831 
     832                $value = str_replace($locale['decimal_point'], '.', $value); 
     833                $value = str_replace($locale['thousands_sep'], '', $value); 
     834 
     835                /*      $is_valid = ( 
     836                  is_numeric($value)  // Must be able to be converted to a number 
     837                  && preg_replace("/^-?([0-9]+)$/", "", $value) == ""  // Must be an integer (no floats or e-powers) 
     838                  && bccomp($value, "-9223372036854775807") >= 0  // Must be greater than than min of 64-bit 
     839                  && bccomp($value, "9223372036854775807") <= 0  // Must be less than max of 64-bit 
     840                  ); */ 
    844841 
    845842                /* remove Hotaru's dependency on BC Math */ 
    846843                $is_valid = ( 
    847                         is_numeric($value)  // Must be able to be converted to a number 
    848                         && preg_replace("/^-?([0-9]+)$/", "", $value) == ""  // Must be an integer (no floats or e-powers) 
    849                         && ($value >= -9223372036854775807)  // Must be greater than than min of 64-bit 
    850                         && ($value <= 9223372036854775807)  // Must be less than max of 64-bit 
    851         ); 
    852         if (!$is_valid) { 
    853             return false; 
    854         } else { 
    855             return true; 
    856         } 
    857         // return (strval(intval($value)) === $value); 
    858     } 
    859  
    860     /** 
    861      * Returns true if value is a valid IP format, false otherwise. 
    862      * 
    863      * @param mixed $value 
    864      * @return boolean 
    865      * 
    866      * @tag validator 
    867      */ 
    868     static public function isIp($value) 
    869     { 
    870         return (bool) ip2long($value); 
    871     } 
    872  
    873     /** 
    874      * Returns true if value is less than $max, false otherwise. 
    875      * 
    876      * @param mixed $value 
    877      * @param mixed $max 
    878      * @return boolean 
    879      * 
    880      * @tag validator 
    881      */ 
    882     static public function isLessThan($value, $max) 
    883     { 
    884         return ($value < $max); 
    885     } 
    886  
    887     /** 
    888      * Returns true if value is one of $allowed, false otherwise. 
    889      * 
    890      * @param mixed $value 
    891      * @param array|string $allowed 
    892      * @return boolean 
    893      * 
    894      * @tag validator 
    895      */ 
    896     static public function isOneOf($value, $allowed) 
    897     { 
    898         /** 
    899          * @todo: Consider allowing a string for $allowed, where each 
    900          * character in the string is an allowed character in the 
    901          * value. 
    902          */ 
    903  
    904         if (is_string($allowed)) { 
    905             $allowed = str_split($allowed); 
    906         } 
    907  
    908         return in_array($value, $allowed); 
    909     } 
    910  
    911     /** 
    912      * Returns true if value is a valid phone number format, false 
    913      * otherwise. The optional second argument indicates the country. 
    914      * This method requires that the value consist of only digits. 
    915      * 
    916      * @param mixed $value 
    917      * @return boolean 
    918      * 
    919      * @tag validator 
    920      */ 
    921     static public function isPhone($value, $country = 'US') 
    922     { 
    923         if (!ctype_digit($value)) { 
    924             return false; 
    925         } 
    926  
    927         switch ($country) { 
    928             case 'US': 
    929                 if (strlen($value) != 10) { 
    930                     return false; 
    931                 } 
    932  
    933                 $areaCode = substr($value, 0, 3); 
    934  
    935                 $areaCodes = array(201, 202, 203, 204, 205, 206, 207, 208, 
    936                     209, 210, 212, 213, 214, 215, 216, 217, 
    937                     218, 219, 224, 225, 226, 228, 229, 231, 
    938                     234, 239, 240, 242, 246, 248, 250, 251, 
    939                     252, 253, 254, 256, 260, 262, 264, 267, 
    940                     268, 269, 270, 276, 281, 284, 289, 301, 
    941                     302, 303, 304, 305, 306, 307, 308, 309, 
    942                     310, 312, 313, 314, 315, 316, 317, 318, 
    943                     319, 320, 321, 323, 325, 330, 334, 336, 
    944                     337, 339, 340, 345, 347, 351, 352, 360, 
    945                     361, 386, 401, 402, 403, 404, 405, 406, 
    946                     407, 408, 409, 410, 412, 413, 414, 415, 
    947                     416, 417, 418, 419, 423, 424, 425, 430, 
    948                     432, 434, 435, 438, 440, 441, 443, 445, 
    949                     450, 469, 470, 473, 475, 478, 479, 480, 
    950                     484, 501, 502, 503, 504, 505, 506, 507, 
    951                     508, 509, 510, 512, 513, 514, 515, 516, 
    952                     517, 518, 519, 520, 530, 540, 541, 555, 
    953                     559, 561, 562, 563, 564, 567, 570, 571, 
    954                     573, 574, 580, 585, 586, 600, 601, 602, 
    955                     603, 604, 605, 606, 607, 608, 609, 610, 
    956                     612, 613, 614, 615, 616, 617, 618, 619, 
    957                     620, 623, 626, 630, 631, 636, 641, 646, 
    958                     647, 649, 650, 651, 660, 661, 662, 664, 
    959                     670, 671, 678, 682, 684, 700, 701, 702, 
    960                     703, 704, 705, 706, 707, 708, 709, 710, 
    961                     712, 713, 714, 715, 716, 717, 718, 719, 
    962                     720, 724, 727, 731, 732, 734, 740, 754, 
    963                     757, 758, 760, 763, 765, 767, 769, 770, 
    964                     772, 773, 774, 775, 778, 780, 781, 784, 
    965                     785, 786, 787, 800, 801, 802, 803, 804, 
    966                     805, 806, 807, 808, 809, 810, 812, 813, 
    967                     814, 815, 816, 817, 818, 819, 822, 828, 
    968                     829, 830, 831, 832, 833, 835, 843, 844, 
    969                     845, 847, 848, 850, 855, 856, 857, 858, 
    970                     859, 860, 863, 864, 865, 866, 867, 868, 
    971                     869, 870, 876, 877, 878, 888, 900, 901, 
    972                     902, 903, 904, 905, 906, 907, 908, 909, 
    973                     910, 912, 913, 914, 915, 916, 917, 918, 
    974                     919, 920, 925, 928, 931, 936, 937, 939, 
    975                     940, 941, 947, 949, 951, 952, 954, 956, 
    976                     959, 970, 971, 972, 973, 978, 979, 980, 
    977                     985, 989); 
    978  
    979                 return in_array($areaCode, $areaCodes); 
    980                 break; 
    981             default: 
    982                 Inspekt_Error::raiseError('isPhone() does not yet support this country.', E_USER_WARNING); 
    983                 return false; 
    984                 break; 
    985         } 
    986     } 
    987  
    988     /** 
    989      * Returns true if value matches $pattern, false otherwise. Uses 
    990      * preg_match() for the matching. 
    991      * 
    992      * @param mixed $value 
    993      * @param mixed $pattern 
    994      * @return mixed 
    995      * 
    996      * @tag validator 
    997      */ 
    998     static public function isRegex($value, $pattern) 
    999     { 
    1000         return (bool) preg_match($pattern, $value); 
    1001     } 
    1002  
    1003     /** 
    1004      * Enter description here... 
    1005      * 
    1006      * @param string $value 
    1007      * @param integer $mode 
    1008      * @return boolean 
    1009      * 
    1010      * @link http://www.ietf.org/rfc/rfc2396.txt 
    1011      * 
    1012      * @tag validator 
    1013      */ 
    1014     static public function isUri($value, $mode = ISPK_URI_ALLOW_COMMON) 
    1015     { 
    1016         /** 
    1017          * @todo 
    1018          */ 
    1019         $regex = ''; 
    1020         switch ($mode) { 
    1021  
    1022             // a common absolute URI: ftp, http or https 
    1023             case ISPK_URI_ALLOW_COMMON: 
    1024  
    1025                 $regex .= '&'; 
    1026                 $regex .= '^(ftp|http|https):';                                 // protocol 
    1027                 $regex .= '(//)';                                                               // authority-start 
    1028                 $regex .= '([-a-z0-9/~;:@=+$,.!*()\']+@)?';             // userinfo 
    1029                 $regex .= '('; 
    1030                 $regex .= '((?:[^\W_]((?:[^\W_]|-){0,61}[^\W_])?\.)+[a-zA-Z]{2,6}\.?)';         // domain name 
    1031                 $regex .= '|'; 
    1032                 $regex .= '([0-9]{1,3}(\.[0-9]{1,3})?(\.[0-9]{1,3})?(\.[0-9]{1,3})?)';  // OR ipv4 
    1033                 $regex .= ')'; 
    1034                 $regex .= '(:([0-9]*))?';                                               // port 
    1035                 $regex .= '(/((%[0-9a-f]{2}|[-_a-z0-9/~;:@=+$,.!*()\'\&]*)*)/?)?';      // path 
    1036                 $regex .= '(\?[^#]*)?';                                                 // query 
    1037                 $regex .= '(#([-a-z0-9_]*))?';                                  // anchor (fragment) 
    1038                 $regex .= '$&i'; 
    1039                 //echo "<pre>"; echo print_r($regex, true); echo "</pre>\n"; 
    1040  
    1041                 break; 
    1042  
    1043             case ISPK_URI_ALLOW_ABSOLUTE: 
    1044  
    1045                 Inspekt_Error::raiseError('isUri() for ISPK_URI_ALLOW_ABSOLUTE has not been implemented.', E_USER_WARNING); 
    1046                 return false; 
    1047  
    1048 //                              $regex .= '&'; 
    1049 //                              $regex .= '^(ftp|http|https):';                                 // protocol 
    1050 //                              $regex .= '(//)';                                                               // authority-start 
    1051 //                              $regex .= '([-a-z0-9/~;:@=+$,.!*()\']+@)?';             // userinfo 
    1052 //                              $regex .= '('; 
    1053 //                                      $regex .= '((?:[^\W_]((?:[^\W_]|-){0,61}[^\W_])?\.)+[a-zA-Z]{2,6}\.?)';         // domain name 
    1054 //                              $regex .= '|'; 
    1055 //                                      $regex .= '([0-9]{1,3}(\.[0-9]{1,3})?(\.[0-9]{1,3})?(\.[0-9]{1,3})?)';  // OR ipv4 
    1056 //                              $regex .= ')'; 
    1057 //                              $regex .= '(:([0-9]*))?';                                               // port 
    1058 //                              $regex .= '(/((%[0-9a-f]{2}|[-a-z0-9/~;:@=+$,.!*()\'\&]*)*)/?)?';       // path 
    1059 //                              $regex .= '(\?[^#]*)?';                                                 // query 
    1060 //                              $regex .= '(#([-a-z0-9_]*))?';                                  // anchor (fragment) 
    1061 //                              $regex .= '$&i'; 
    1062                 //echo "<pre>"; echo print_r($regex, true); echo "</pre>\n"; 
    1063  
    1064                 break; 
    1065  
    1066         } 
    1067         $result = preg_match($regex, $value); 
    1068  
    1069         if ($result === 1) { 
     844                                is_numeric($value)  // Must be able to be converted to a number 
     845                                && preg_replace("/^-?([0-9]+)$/", "", $value) == ""  // Must be an integer (no floats or e-powers) 
     846                                && ($value >= -9223372036854775807)  // Must be greater than than min of 64-bit 
     847                                && ($value <= 9223372036854775807)  // Must be less than max of 64-bit 
     848                                ); 
     849                if (!$is_valid) { 
     850                        return false; 
     851                } else { 
     852                        return true; 
     853                } 
     854                // return (strval(intval($value)) === $value); 
     855        } 
     856 
     857        /** 
     858         * Returns true if value is a valid IP format, false otherwise. 
     859         * 
     860         * @param mixed $value 
     861         * @return boolean 
     862         * 
     863         * @tag validator 
     864         */ 
     865        static public function isIp($value) 
     866        { 
     867                return (bool) ip2long($value); 
     868        } 
     869 
     870        /** 
     871         * Returns true if value is less than $max, false otherwise. 
     872         * 
     873         * @param mixed $value 
     874         * @param mixed $max 
     875         * @return boolean 
     876         * 
     877         * @tag validator 
     878         */ 
     879        static public function isLessThan($value, $max) 
     880        { 
     881                return ($value < $max); 
     882        } 
     883 
     884        /** 
     885         * Returns true if value is one of $allowed, false otherwise. 
     886         * 
     887         * @param mixed $value 
     888         * @param array|string $allowed 
     889         * @return boolean 
     890         * 
     891         * @tag validator 
     892         */ 
     893        static public function isOneOf($value, $allowed) 
     894        { 
     895                /** 
     896                 * @todo: Consider allowing a string for $allowed, where each 
     897                 * character in the string is an allowed character in the 
     898                 * value. 
     899                 */ 
     900                if (is_string($allowed)) { 
     901                        $allowed = str_split($allowed); 
     902                } 
     903 
     904                return in_array($value, $allowed); 
     905        } 
     906 
     907        /** 
     908         * Returns true if value is a valid phone number format, false 
     909         * otherwise. The optional second argument indicates the country. 
     910         * This method requires that the value consist of only digits. 
     911         * 
     912         * @param mixed $value 
     913         * @return boolean 
     914         * 
     915         * @tag validator 
     916         */ 
     917        static public function isPhone($value, $country = 'US') 
     918        { 
     919                if (!ctype_digit($value)) { 
     920                        return false; 
     921                } 
     922 
     923                switch ($country) { 
     924                        case 'US': 
     925                                if (strlen($value) != 10) { 
     926                                        return false; 
     927                                } 
     928 
     929                                $areaCode = substr($value, 0, 3); 
     930 
     931                                $areaCodes = array(201, 202, 203, 204, 205, 206, 207, 208, 
     932                                        209, 210, 212, 213, 214, 215, 216, 217, 
     933                                        218, 219, 224, 225, 226, 228, 229, 231, 
     934                                        234, 239, 240, 242, 246, 248, 250, 251, 
     935                                        252, 253, 254, 256, 260, 262, 264, 267, 
     936                                        268, 269, 270, 276, 281, 284, 289, 301, 
     937                                        302, 303, 304, 305, 306, 307, 308, 309, 
     938                                        310, 312, 313, 314, 315, 316, 317, 318, 
     939                                        319, 320, 321, 323, 325, 330, 334, 336, 
     940                                        337, 339, 340, 345, 347, 351, 352, 360, 
     941                                        361, 386, 401, 402, 403, 404, 405, 406, 
     942                                        407, 408, 409, 410, 412, 413, 414, 415, 
     943                                        416, 417, 418, 419, 423, 424, 425, 430, 
     944                                        432, 434, 435, 438, 440, 441, 443, 445, 
     945                                        450, 469, 470, 473, 475, 478, 479, 480, 
     946                                        484, 501, 502, 503, 504, 505, 506, 507, 
     947                                        508, 509, 510, 512, 513, 514, 515, 516, 
     948                                        517, 518, 519, 520, 530, 540, 541, 555, 
     949                                        559, 561, 562, 563, 564, 567, 570, 571, 
     950                                        573, 574, 580, 585, 586, 600, 601, 602, 
     951                                        603, 604, 605, 606, 607, 608, 609, 610, 
     952                                        612, 613, 614, 615, 616, 617, 618, 619, 
     953                                        620, 623, 626, 630, 631, 636, 641, 646, 
     954                                        647, 649, 650, 651, 660, 661, 662, 664, 
     955                                        670, 671, 678, 682, 684, 700, 701, 702, 
     956                                        703, 704, 705, 706, 707, 708, 709, 710, 
     957                                        712, 713, 714, 715, 716, 717, 718, 719, 
     958                                        720, 724, 727, 731, 732, 734, 740, 754, 
     959                                        757, 758, 760, 763, 765, 767, 769, 770, 
     960                                        772, 773, 774, 775, 778, 780, 781, 784, 
     961                                        785, 786, 787, 800, 801, 802, 803, 804, 
     962                                        805, 806, 807, 808, 809, 810, 812, 813, 
     963                                        814, 815, 816, 817, 818, 819, 822, 828, 
     964                                        829, 830, 831, 832, 833, 835, 843, 844, 
     965                                        845, 847, 848, 850, 855, 856, 857, 858, 
     966                                        859, 860, 863, 864, 865, 866, 867, 868, 
     967                                        869, 870, 876, 877, 878, 888, 900, 901, 
     968                                        902, 903, 904, 905, 906, 907, 908, 909, 
     969                                        910, 912, 913, 914, 915, 916, 917, 918, 
     970                                        919, 920, 925, 928, 931, 936, 937, 939, 
     971                                        940, 941, 947, 949, 951, 952, 954, 956, 
     972                                        959, 970, 971, 972, 973, 978, 979, 980, 
     973                                        985, 989); 
     974 
     975                                return in_array($areaCode, $areaCodes); 
     976                                break; 
     977                        default: 
     978                                Inspekt_Error::raiseError('isPhone() does not yet support this country.', E_USER_WARNING); 
     979                                return false; 
     980                                break; 
     981                } 
     982        } 
     983 
     984        /** 
     985         * Returns true if value matches $pattern, false otherwise. Uses 
     986         * preg_match() for the matching. 
     987         * 
     988         * @param mixed $value 
     989         * @param mixed $pattern 
     990         * @return mixed 
     991         * 
     992         * @tag validator 
     993         */ 
     994        static public function isRegex($value, $pattern) 
     995        { 
     996                return (bool) preg_match($pattern, $value); 
     997        } 
     998 
     999        /** 
     1000         * Enter description here... 
     1001         * 
     1002         * @param string $value 
     1003         * @param integer $mode 
     1004         * @return boolean 
     1005         * 
     1006         * @link http://www.ietf.org/rfc/rfc2396.txt 
     1007         * 
     1008         * @tag validator 
     1009         */ 
     1010        static public function isUri($value, $mode = ISPK_URI_ALLOW_COMMON) 
     1011        { 
     1012                /** 
     1013                 * @todo 
     1014                 */ 
     1015                $regex = ''; 
     1016                switch ($mode) { 
     1017 
     1018                        // a common absolute URI: ftp, http or https 
     1019                        case ISPK_URI_ALLOW_COMMON: 
     1020 
     1021                                $regex .= '&'; 
     1022                                $regex .= '^(ftp|http|https):';  // protocol 
     1023                                $regex .= '(//)';               // authority-start 
     1024                                $regex .= '([-a-z0-9/~;:@=+$,.!*()\']+@)?';  // userinfo 
     1025                                $regex .= '('; 
     1026                                $regex .= '((?:[^\W_]((?:[^\W_]|-){0,61}[^\W_])?\.)+[a-zA-Z]{2,6}\.?)';  // domain name 
     1027                                $regex .= '|'; 
     1028                                $regex .= '([0-9]{1,3}(\.[0-9]{1,3})?(\.[0-9]{1,3})?(\.[0-9]{1,3})?)'; // OR ipv4 
     1029                                $regex .= ')'; 
     1030                                $regex .= '(:([0-9]*))?';         // port 
     1031                                $regex .= '(/((%[0-9a-f]{2}|[-_a-z0-9/~;:@=+$,.!*()\'\&]*)*)/?)?'; // path 
     1032                                $regex .= '(\?[^#]*)?';    // query 
     1033                                $regex .= '(#([-a-z0-9_]*))?';   // anchor (fragment) 
     1034                                $regex .= '$&i'; 
     1035                                //echo "<pre>"; echo print_r($regex, true); echo "</pre>\n"; 
     1036 
     1037                                break; 
     1038 
     1039                        case ISPK_URI_ALLOW_ABSOLUTE: 
     1040 
     1041                                Inspekt_Error::raiseError('isUri() for ISPK_URI_ALLOW_ABSOLUTE has not been implemented.', E_USER_WARNING); 
     1042                                return false; 
     1043                                break; 
     1044                } 
     1045                $result = preg_match($regex, $value); 
     1046 
     1047                if ($result === 1) { 
    10701048                        return true; 
    10711049                } elseif (strstr($value, "http://localhost")) { // allow urls from localhost 
    1072             return true; 
    1073         } else { 
    1074             return false; 
    1075         } 
    1076     } 
    1077  
    1078     /** 
    1079      * Returns true if value is a valid US ZIP, false otherwise. 
    1080      * 
    1081      * @param mixed $value 
    1082      * @return boolean 
    1083      * 
    1084      * @tag validator 
    1085      */ 
    1086     static public function isZip($value) 
    1087     { 
    1088         return (bool) preg_match('/(^\d{5}$)|(^\d{5}-\d{4}$)/', $value); 
    1089     } 
    1090  
    1091     /** 
    1092      * Returns value with all tags removed. 
    1093      * 
    1094      * This will utilize the PHP Filter extension if available 
    1095      * 
    1096      * @param mixed $value 
    1097      * @return mixed 
    1098      * 
    1099      * @tag filter 
    1100      */ 
    1101     static public function noTags($value) 
    1102     { 
    1103         if (Inspekt::isArrayOrArrayObject($value)) { 
    1104             return Inspekt::_walkArray($value, 'noTags'); 
    1105         } else { 
    1106             if (Inspekt::useFilterExt()) { 
    1107                 return filter_var($value, FILTER_SANITIZE_STRING); 
    1108             } else { 
    1109                 return strip_tags($value); 
    1110             } 
    1111         } 
    1112     } 
    1113  
    1114     /** 
    1115      * returns value with tags stripped and the chars '"&<> and all ascii chars under 32 encoded as html entities 
    1116      * 
    1117      * This will utilize the PHP Filter extension if available 
    1118      * 
    1119      * @param mixed $value 
    1120      * @return @mixed 
    1121      * 
    1122      * @tag filter 
    1123      * 
    1124      */ 
    1125     static public function noTagsOrSpecial($value) 
    1126     { 
    1127         if (Inspekt::isArrayOrArrayObject($value)) { 
    1128             return Inspekt::_walkArray($value, 'noTagsOrSpecial'); 
    1129         } else { 
    1130             if (Inspekt::useFilterExt()) { 
    1131                 $newval = filter_var($value, FILTER_SANITIZE_STRING); 
    1132                 $newval = filter_var($newval, FILTER_SANITIZE_SPECIAL_CHARS); 
    1133                 return $newval; 
    1134             } else { 
    1135                 $newval = strip_tags($value); 
    1136                 $newval = htmlspecialchars($newval, ENT_QUOTES, 'UTF-8'); // for sake of simplicity and safety we assume UTF-8 
    1137  
    1138                 /* 
    1139                                         convert low ascii chars to entities 
    1140                 */ 
    1141                 $newval = str_split($newval); 
    1142                 for ($i=0; $i < count($newval); $i++) { 
    1143                     $ascii_code = ord($newval[$i]); 
    1144                     if ($ascii_code < 32) { 
    1145                         $newval[$i] = "&#{$ascii_code};"; 
    1146                     } 
    1147                 } 
    1148                 $newval = implode($newval); 
    1149  
    1150                 return $newval; 
    1151             } 
    1152         } 
    1153     } 
    1154  
    1155     /** 
    1156      * Returns basename(value). 
    1157      * 
    1158      * @param mixed $value 
    1159      * @return mixed 
    1160      * 
    1161      * @tag filter 
    1162      */ 
    1163     static public function noPath($value) 
    1164     { 
    1165         if (Inspekt::isArrayOrArrayObject($value)) { 
    1166             return Inspekt::_walkArray($value, 'noPath'); 
    1167         } else { 
    1168             return basename($value); 
    1169         } 
    1170     } 
    1171  
    1172     /** 
    1173      * Escapes the value given with mysql_real_escape_string 
    1174      * 
    1175      * @param mixed $value 
    1176      * @param resource $conn the mysql connection. If none is given, it will use the last link opened, per behavior of mysql_real_escape_string 
    1177      * @return mixed 
    1178      * 
    1179      * @link http://php.net/manual/en/function.mysql-real-escape-string.php 
    1180      * 
    1181      * @tag filter 
    1182      */ 
    1183     static public function escMySQL($value, $conn = null) 
    1184     { 
    1185         if (Inspekt::isArrayOrArrayObject($value)) { 
    1186             return Inspekt::_walkArray($value, 'escMySQL'); 
    1187         } else { 
    1188             //no explicit func to check if the connection is live, but if it's not $conn would be false 
    1189             if (isset($conn) && is_resource($conn)) { 
    1190                 return mysqli_real_escape_string( $conn, $value); 
    1191             } 
    1192         } 
    1193     } 
    1194  
    1195     /** 
    1196      * Escapes the value given with pg_escape_string 
    1197      * 
    1198      * If the data is for a column of the type bytea, use Inspekt::escPgSQLBytea() 
    1199      * 
    1200      * @param mixed $value 
    1201      * @param resource $conn the postgresql connection. If none is given, it will use the last link opened, per behavior of pg_escape_string 
    1202      * @return mixed 
    1203      * 
    1204      * @link http://php.net/manual/en/function.pg-escape-string.php 
    1205      */ 
    1206     static public function escPgSQL($value, $conn = null) 
    1207     { 
    1208         if (Inspekt::isArrayOrArrayObject($value)) { 
    1209             return Inspekt::_walkArray($value, 'escPgSQL'); 
    1210         } else { 
    1211             //might also check is_resource if pg_connection_status is too much 
    1212             if (isset($conn) && pg_connection_status($conn) === PGSQL_CONNECTION_OK) { 
    1213                 return pg_escape_string($conn, $value); 
    1214             } else { 
    1215                 return pg_escape_string($value); 
    1216             } 
    1217         } 
    1218     } 
    1219  
    1220     /** 
    1221      * Escapes the value given with pg_escape_bytea 
    1222      * 
    1223      * @param mixed $value 
    1224      * @param resource $conn the postgresql connection. If none is given, it will use the last link opened, per behavior of pg_escape_bytea 
    1225      * @return mixed 
    1226      * 
    1227      * @link http://php.net/manual/en/function.pg-escape-bytea.php 
    1228      */ 
    1229     static public function escPgSQLBytea($value, $conn = null) 
    1230     { 
    1231         if (Inspekt::isArrayOrArrayObject($value)) { 
    1232             return Inspekt::_walkArray($value, 'escPgSQL'); 
    1233         } else { 
    1234             //might also check is_resource if pg_connection_status is too much 
    1235             if (isset($conn) && pg_connection_status($conn) === PGSQL_CONNECTION_OK) { 
    1236                 return pg_escape_bytea($conn, $value); 
    1237             } else { 
    1238                 return pg_escape_bytea($value); 
    1239             } 
    1240         } 
    1241     } 
     1050                        return true; 
     1051                } else { 
     1052                        return false; 
     1053                } 
     1054        } 
     1055 
     1056        /** 
     1057         * Returns value with all tags removed. 
     1058         * 
     1059         * This will utilize the PHP Filter extension if available 
     1060         * 
     1061         * @param mixed $value 
     1062         * @return mixed 
     1063         * 
     1064         * @tag filter 
     1065         */ 
     1066        static public function noTags($value) 
     1067        { 
     1068                if (Inspekt::isArrayOrArrayObject($value)) { 
     1069                        return Inspekt::_walkArray($value, 'noTags'); 
     1070                } else { 
     1071                        if (Inspekt::useFilterExt()) { 
     1072                                return filter_var($value, FILTER_SANITIZE_STRING); 
     1073                        } else { 
     1074                                return strip_tags($value); 
     1075                        } 
     1076                } 
     1077        } 
     1078 
     1079        /** 
     1080         * returns value with tags stripped and the chars '"&<> and all ascii chars under 32 encoded as html entities 
     1081         * 
     1082         * This will utilize the PHP Filter extension if available 
     1083         * 
     1084         * @param mixed $value 
     1085         * @return @mixed 
     1086         * 
     1087         * @tag filter 
     1088         * 
     1089         */ 
     1090        static public function noTagsOrSpecial($value) 
     1091        { 
     1092                if (Inspekt::isArrayOrArrayObject($value)) { 
     1093                        return Inspekt::_walkArray($value, 'noTagsOrSpecial'); 
     1094                } else { 
     1095                        if (Inspekt::useFilterExt()) { 
     1096                                $newval = filter_var($value, FILTER_SANITIZE_STRING); 
     1097                                $newval = filter_var($newval, FILTER_SANITIZE_SPECIAL_CHARS); 
     1098                                return $newval; 
     1099                        } else { 
     1100                                $newval = strip_tags($value); 
     1101                                $newval = htmlspecialchars($newval, ENT_QUOTES, 'UTF-8'); // for sake of simplicity and safety we assume UTF-8 
     1102 
     1103                                /* 
     1104                                  convert low ascii chars to entities 
     1105                                 */ 
     1106                                $newval = str_split($newval); 
     1107                                for ($i = 0; $i < count($newval); $i++) { 
     1108                                        $ascii_code = ord($newval[$i]); 
     1109                                        if ($ascii_code < 32) { 
     1110                                                $newval[$i] = "&#{$ascii_code};"; 
     1111                                        } 
     1112                                } 
     1113                                $newval = implode($newval); 
     1114 
     1115                                return $newval; 
     1116                        } 
     1117                } 
     1118        } 
     1119 
     1120        /** 
     1121         * Returns basename(value). 
     1122         * 
     1123         * @param mixed $value 
     1124         * @return mixed 
     1125         * 
     1126         * @tag filter 
     1127         */ 
     1128        static public function noPath($value) 
     1129        { 
     1130                if (Inspekt::isArrayOrArrayObject($value)) { 
     1131                        return Inspekt::_walkArray($value, 'noPath'); 
     1132                } else { 
     1133                        return basename($value); 
     1134                } 
     1135        } 
     1136 
    12421137} 
  • branches/1.5/libs/extensions/Inspekt/Inspekt/AccessorAbstract.php

    r2164 r2326  
    9898         
    9999} 
    100  
    101  
    102  
    103  
    104 ?> 
  • branches/1.5/libs/extensions/Inspekt/Inspekt/Cage.php

    r2164 r2326  
    88 * @package Inspekt 
    99 */ 
    10  
    1110/** 
    1211 * require main Inspekt file 
     
    1514 
    1615 
    17 define ('ISPK_ARRAY_PATH_SEPARATOR', '/'); 
    18  
    19 define ('ISPK_RECURSION_MAX', 15); 
     16define('ISPK_ARRAY_PATH_SEPARATOR', '/'); 
     17 
     18define('ISPK_RECURSION_MAX', 15); 
    2019 
    2120/** 
    2221 * @package Inspekt 
    2322 */ 
    24 class Inspekt_Cage implements IteratorAggregate, ArrayAccess, Countable { 
    25 /** 
    26  * {@internal The raw source data.  Although tempting, NEVER EVER 
    27  * EVER access the data directly using this property!}} 
    28  * 
    29  * Don't try to access this.  ever.  Now that we're safely on PHP5, we'll 
    30  * enforce this with the "protected" keyword. 
    31  * 
    32  * @var array 
    33  */ 
     23class Inspekt_Cage implements IteratorAggregate, ArrayAccess, Countable 
     24{ 
     25 
     26        /** 
     27         * {@internal The raw source data.  Although tempting, NEVER EVER 
     28         * EVER access the data directly using this property!}} 
     29         * 
     30         * Don't try to access this.  ever.  Now that we're safely on PHP5, we'll 
     31         * enforce this with the "protected" keyword. 
     32         * 
     33         * @var array 
     34         */ 
    3435        protected $_source = NULL; 
    35  
    3636        /** 
    3737         * where we store user-defined methods 
     
    4040         */ 
    4141        public $_user_accessors = array(); 
    42  
    4342        /** 
    4443         * the holding property for autofilter config 
     
    4746         */ 
    4847        public $_autofilter_conf = NULL; 
    49  
    5048        /** 
    5149         * 
     
    5452        public $purifier = NULL; 
    5553 
    56  
    5754        /** 
    5855         * 
    5956         * @return Inspekt_Cage 
    6057         */ 
    61         public function Inspekt_Cage() { 
     58        public function Inspekt_Cage() 
     59        { 
    6260                // placeholder -- we're using a factory here 
    6361        } 
    64  
    65  
    6662 
    6763        /** 
     
    7874         * @static 
    7975         */ 
    80         static public function Factory(&$source, $conf_file = NULL, $conf_section = NULL, $strict = TRUE) { 
     76        static public function Factory(&$source, $conf_file = NULL, $conf_section = NULL, $strict = TRUE) 
     77        { 
    8178 
    8279                if (!is_array($source)) { 
     
    9592        } 
    9693 
    97  
    9894        /** 
    9995         * {@internal we use this to set the data array in Factory()}} 
     
    10298         * @param array $newsource 
    10399         */ 
    104         private function _setSource(&$newsource) { 
     100        private function _setSource(&$newsource) 
     101        { 
    105102 
    106103                $this->_source = Inspekt::convertArrayToArrayObject($newsource); 
    107  
    108         } 
    109  
     104        } 
    110105 
    111106        /** 
     
    115110         * @return ArrayIterator 
    116111         */ 
    117         public function getIterator() { 
     112        public function getIterator() 
     113        { 
    118114                return $this->_source->getIterator(); 
    119115        } 
    120  
    121116 
    122117        /** 
     
    129124         * @return void 
    130125         */ 
    131         public function offsetSet($offset, $value) { 
     126        public function offsetSet($offset, $value) 
     127        { 
    132128                $this->_source->offsetSet($offset, $value); 
    133129        } 
    134  
    135130 
    136131        /** 
     
    141136         * @return bool 
    142137         */ 
    143         public function offsetExists($offset) { 
     138        public function offsetExists($offset) 
     139        { 
    144140                return $this->_source->offsetExists($offset); 
    145141        } 
    146  
    147142 
    148143        /** 
     
    153148         * @return void 
    154149         */ 
    155         public function offsetUnset($offset) { 
     150        public function offsetUnset($offset) 
     151        { 
    156152                $this->_source->offsetUnset($offset); 
    157153        } 
    158  
    159154 
    160155        /** 
     
    165160         * @return void 
    166161         */ 
    167         public function offsetGet($offset) { 
     162        public function offsetGet($offset) 
     163        { 
    168164                return $this->_source->offsetGet($offset); 
    169165        } 
    170  
    171166 
    172167        /** 
     
    176171         * @return int 
    177172         */ 
    178         public function count() { 
     173        public function count() 
     174        { 
    179175                return $this->_source->count(); 
    180176        } 
    181  
    182177 
    183178        /** 
     
    185180         * @param string $path the full path to the HTMLPurifier.auto.php base file. Optional if HTMLPurifier is already in your include_path 
    186181         */ 
    187         public function loadHTMLPurifier($path=null, $opts=null) { 
     182        public function loadHTMLPurifier($path=null, $opts=null) 
     183        { 
    188184                if (isset($path)) { 
    189185                        include_once($path); 
     
    201197        } 
    202198 
    203  
    204199        /** 
    205200         * 
    206201         * @param HTMLPurifer $pobj an HTMLPurifer Object 
    207202         */ 
    208         public function setHTMLPurifier($pobj) { 
     203        public function setHTMLPurifier($pobj) 
     204        { 
    209205                $this->purifier = $pobj; 
    210206        } 
     
    213209         * @return HTMLPurifier 
    214210         */ 
    215         public function getHTMLPurifier() { 
     211        public function getHTMLPurifier() 
     212        { 
    216213                return $this->purifier; 
    217214        } 
    218215 
    219  
    220         protected function _buildHTMLPurifierConfig($opts) { 
     216        protected function _buildHTMLPurifierConfig($opts) 
     217        { 
    221218                $config = HTMLPurifier_Config::createDefault(); 
    222                 foreach ($opts as $key=>$val) { 
     219                foreach ($opts as $key => $val) { 
    223220                        $config->set($key, $val); 
    224221                } 
     
    226223        } 
    227224 
    228  
    229         protected function _parseAndApplyAutoFilters($conf_file, $conf_section) { 
     225        protected function _parseAndApplyAutoFilters($conf_file, $conf_section) 
     226        { 
    230227                if (isset($conf_file)) { 
    231228                        $conf = parse_ini_file($conf_file, true); 
     
    242239        } 
    243240 
    244  
    245         protected function _applyAutoFilters() { 
    246  
    247                 if ( isset($this->_autofilter_conf) && is_array($this->_autofilter_conf)) { 
    248  
    249                         foreach($this->_autofilter_conf as $key=>$filters) { 
    250  
    251                         // get universal filter key 
     241        protected function _applyAutoFilters() 
     242        { 
     243 
     244                if (isset($this->_autofilter_conf) && is_array($this->_autofilter_conf)) { 
     245 
     246                        foreach ($this->_autofilter_conf as $key => $filters) { 
     247 
     248                                // get universal filter key 
    252249                                if ($key == '*') { 
    253250 
    254                                 // get filters for this key 
     251                                        // get filters for this key 
    255252                                        $uni_filters = explode(',', $this->_autofilter_conf[$key]); 
    256253                                        array_walk($uni_filters, 'trim'); 
    257254 
    258255                                        // apply uni filters 
    259                                         foreach($uni_filters as $this_filter) { 
    260                                                 foreach($this->_source as $key=>$val) { 
     256                                        foreach ($uni_filters as $this_filter) { 
     257                                                foreach ($this->_source as $key => $val) { 
    261258                                                        $this->_source[$key] = $this->$this_filter($key); 
    262259                                                } 
    263260                                        } 
    264                                 //echo "<pre>UNI FILTERS"; echo var_dump($this->_source); echo "</pre>\n"; 
    265  
    266                                 } elseif($val == $this->keyExists($key)) { 
    267  
    268                                 // get filters for this key 
     261                                        //echo "<pre>UNI FILTERS"; echo var_dump($this->_source); echo "</pre>\n"; 
     262                                } elseif ($val == $this->keyExists($key)) { 
     263 
     264                                        // get filters for this key 
    269265                                        $filters = explode(',', $this->_autofilter_conf[$key]); 
    270266                                        array_walk($filters, 'trim'); 
    271267 
    272268                                        // apply filters 
    273                                         foreach($filters as $this_filter) { 
     269                                        foreach ($filters as $this_filter) { 
    274270                                                $this->_setValue($key, $this->$this_filter($key)); 
    275271                                        } 
    276                                 //echo "<pre> Filter $this_filter/$key: "; echo var_dump($this->_source); echo "</pre>\n"; 
    277  
     272                                        //echo "<pre> Filter $this_filter/$key: "; echo var_dump($this->_source); echo "</pre>\n"; 
    278273                                } 
    279274                        } 
     
    281276        } 
    282277 
    283  
    284  
    285         public function __call($name, $args) { 
    286                 if (in_array($name, $this->_user_accessors) ) { 
     278        public function __call($name, $args) 
     279        { 
     280                if (in_array($name, $this->_user_accessors)) { 
    287281 
    288282                        $acc = new $name($this, $args); 
    289283                        /* 
    290                                 this first argument should always be the key we're accessing 
    291                         */ 
     284                          this first argument should always be the key we're accessing 
     285                         */ 
    292286                        return $acc->run($args[0]); 
    293  
    294287                } else { 
    295288                        Inspekt_Error::raiseError("The accessor $name does not exist and is not registered", E_USER_ERROR); 
    296289                        return false; 
    297290                } 
    298  
    299291        } 
    300292 
     
    316308         * @author Ed Finkler 
    317309         */ 
    318         public function addAccessor($accessor_name) { 
     310        public function addAccessor($accessor_name) 
     311        { 
    319312                $this->_user_accessors[] = $accessor_name; 
    320313        } 
    321314 
    322  
    323315        /** 
    324316         * Returns only the alphabetic characters in value. 
     
    329321         * @tag filter 
    330322         */ 
    331         public function getAlpha($key) { 
     323        public function getAlpha($key) 
     324        { 
    332325                if (!$this->keyExists($key)) { 
    333326                        return false; 
     
    344337         * @tag filter 
    345338         */ 
    346         public function getAlnum($key) { 
     339        public function getAlnum($key) 
     340        { 
    347341                if (!$this->keyExists($key)) { 
    348342                        return false; 
     
    359353         * @tag filter 
    360354         */ 
    361         public function getDigits($key) { 
     355        public function getDigits($key) 
     356        { 
    362357                if (!$this->keyExists($key)) { 
    363358                        return false; 
     
    374369         * @tag filter 
    375370         */ 
    376         public function getDir($key) { 
     371        public function getDir($key) 
     372        { 
    377373                if (!$this->keyExists($key)) { 
    378374                        return false; 
     
    389385         * @tag filter 
    390386         */ 
    391         public function getInt($key) { 
     387        public function getInt($key) 
     388        { 
    392389                if (!$this->keyExists($key)) { 
    393390                        return false; 
     
    404401         * @tag filter 
    405402         */ 
    406         public function getPath($key) { 
     403        public function getPath($key) 
     404        { 
    407405                if (!$this->keyExists($key)) { 
    408406                        return false; 
     
    411409        } 
    412410 
    413  
    414411        /** 
    415412         * Returns ROT13-encoded version 
     
    419416         * @tag hash 
    420417         */ 
    421         public function getROT13($key) { 
     418        public function getROT13($key) 
     419        { 
    422420                if (!$this->keyExists($key)) { 
    423421                        return false; 
     
    425423                return Inspekt::getROT13($this->_getValue($key)); 
    426424        } 
    427          
    428425 
    429426        /** 
     
    435432         * @tag filter 
    436433         */ 
    437         public function getPurifiedHTML($key) { 
     434        public function getPurifiedHTML($key) 
     435        { 
    438436                if (!isset($this->purifier)) { 
    439437                        Inspekt_Error::raiseError("HTMLPurifier was not loaded", E_USER_WARNING); 
     
    452450        } 
    453451 
    454  
    455452        /** 
    456453         * Returns value. 
     
    461458         * @tag filter 
    462459         */ 
    463         public function getRaw($key) { 
     460        public function getRaw($key) 
     461        { 
    464462                if (!$this->keyExists($key)) { 
    465463                        return false; 
     
    477475         * @tag validator 
    478476         */ 
    479         public function testAlnum($key) { 
     477        public function testAlnum($key) 
     478        { 
    480479                if (!$this->keyExists($key)) { 
    481480                        return false; 
     
    497496         * @tag validator 
    498497         */ 
    499         public function testAlpha($key) { 
     498        public function testAlpha($key) 
     499        { 
    500500                if (!$this->keyExists($key)) { 
    501501                        return false; 
     
    522522         * @tag validator 
    523523         */ 
    524         public function testBetween($key, $min, $max, $inc = TRUE) { 
     524        public function testBetween($key, $min, $max, $inc = TRUE) 
     525        { 
    525526                if (!$this->keyExists($key)) { 
    526527                        return false; 
     
    544545         * @tag validator 
    545546         */ 
    546         public function testCcnum($key, $type = NULL) { 
     547        public function testCcnum($key, $type = NULL) 
     548        { 
    547549                if (!$this->keyExists($key)) { 
    548550                        return false; 
     
    564566         * @tag validator 
    565567         */ 
    566         public function testDate($key) { 
     568        public function testDate($key) 
     569        { 
    567570                if (!$this->keyExists($key)) { 
    568571                        return false; 
     
    584587         * @tag validator 
    585588         */ 
    586         public function testDigits($key) { 
     589        public function testDigits($key) 
     590        { 
    587591                if (!$this->keyExists($key)) { 
    588592                        return false; 
     
    603607         * @tag validator 
    604608         */ 
    605         public function testEmail($key) { 
     609        public function testEmail($key) 
     610        { 
    606611                if (!$this->keyExists($key)) { 
    607612                        return false; 
     
    622627         * @tag validator 
    623628         */ 
    624         public function testFloat($key) { 
     629        public function testFloat($key) 
     630        { 
    625631                if (!$this->keyExists($key)) { 
    626632                        return false; 
     
    642648         * @tag validator 
    643649         */ 
    644         public function testGreaterThan($key, $min = NULL) { 
     650        public function testGreaterThan($key, $min = NULL) 
     651        { 
    645652                if (!$this->keyExists($key)) { 
    646653                        return false; 
     
    662669         * @tag validator 
    663670         */ 
    664         public function testHex($key) { 
     671        public function testHex($key) 
     672        { 
    665673                if (!$this->keyExists($key)) { 
    666674                        return false; 
     
    686694         * @tag validator 
    687695         */ 
    688         public function testHostname($key, $allow = ISPK_HOST_ALLOW_ALL) { 
     696        public function testHostname($key, $allow = ISPK_HOST_ALLOW_ALL) 
     697        { 
    689698                if (!$this->keyExists($key)) { 
    690699                        return false; 
     
    705714         * @tag validator 
    706715         */ 
    707         public function testInt($key) { 
     716        public function testInt($key) 
     717        { 
    708718                if (!$this->keyExists($key)) { 
    709719                        return false; 
     
    724734         * @tag validator 
    725735         */ 
    726         public function testIp($key) { 
     736        public function testIp($key) 
     737        { 
    727738                if (!$this->keyExists($key)) { 
    728739                        return false; 
     
    744755         * @tag validator 
    745756         */ 
    746         public function testLessThan($key, $max = NULL) { 
     757        public function testLessThan($key, $max = NULL) 
     758        { 
    747759                if (!$this->keyExists($key)) { 
    748760                        return false; 
     
    763775         * @tag validator 
    764776         */ 
    765         public function testOneOf($key, $allowed = NULL) { 
     777        public function testOneOf($key, $allowed = NULL) 
     778        { 
    766779                if (!$this->keyExists($key)) { 
    767780                        return false; 
     
    783796         * @tag validator 
    784797         */ 
    785         public function testPhone($key, $country = 'US') { 
     798        public function testPhone($key, $country = 'US') 
     799        { 
    786800                if (!$this->keyExists($key)) { 
    787801                        return false; 
     
    804818         * @tag validator 
    805819         */ 
    806         public function testRegex($key, $pattern = NULL) { 
     820        public function testRegex($key, $pattern = NULL) 
     821        { 
    807822                if (!$this->keyExists($key)) { 
    808823                        return false; 
     
    814829                return FALSE; 
    815830        } 
    816  
    817831 
    818832        /** 
     
    824838         * @tag validator 
    825839         */ 
    826         public function testUri($key) { 
     840        public function testUri($key) 
     841        { 
    827842                if (!$this->keyExists($key)) { 
    828843                        return false; 
     
    843858         * @tag validator 
    844859         */ 
    845         public function testZip($key) { 
     860        public function testZip($key) 
     861        { 
    846862                if (!$this->keyExists($key)) { 
    847863                        return false; 
     
    862878         * @tag filter 
    863879         */ 
    864         public function noTags($key) { 
     880        public function noTags($key) 
     881        { 
    865882                if (!$this->keyExists($key)) { 
    866883                        return false; 
     
    877894         * @tag filter 
    878895         */ 
    879         public function noPath($key) { 
     896        public function noPath($key) 
     897        { 
    880898                if (!$this->keyExists($key)) { 
    881899                        return false; 
     
    884902        } 
    885903 
    886  
    887         public function noTagsOrSpecial($key) { 
     904        public function noTagsOrSpecial($key) 
     905        { 
    888906                if (!$this->keyExists($key)) { 
    889907                        return false; 
     
    892910        } 
    893911 
    894  
    895  
    896         public function escMySQL($key, $conn=null) { 
     912        public function escMySQL($key, $conn=null) 
     913        { 
    897914                if (!$this->keyExists($key)) { 
    898915                        return false; 
     
    903920                        return Inspekt::escMySQL($this->_getValue($key)); 
    904921                } 
    905  
    906         } 
    907  
    908  
    909         public function escPgSQL($key, $conn=null) { 
     922        } 
     923 
     924        public function escPgSQL($key, $conn=null) 
     925        { 
    910926                if (!$this->keyExists($key)) { 
    911927                        return false; 
     
    916932                        return Inspekt::escPgSQL($this->_getValue($key)); 
    917933                } 
    918  
    919         } 
    920  
    921  
    922         public function escPgSQLBytea($key, $conn=null) { 
     934        } 
     935 
     936        public function escPgSQLBytea($key, $conn=null) 
     937        { 
    923938                if (!$this->keyExists($key)) { 
    924939                        return false; 
     
    929944                        return Inspekt::escPgSQLBytea($this->_getValue($key)); 
    930945                } 
    931  
    932         } 
    933  
    934  
    935  
    936  
     946        } 
    937947 
    938948        /** 
     
    944954         * 
    945955         */ 
    946         public function keyExists($key, $return_value=false) { 
     956        public function keyExists($key, $return_value=false) 
     957        { 
    947958                if (strpos($key, ISPK_ARRAY_PATH_SEPARATOR) !== FALSE) { 
    948959                        $key = trim($key, ISPK_ARRAY_PATH_SEPARATOR); 
     
    959970                                return FALSE; 
    960971                        } 
    961                          
    962                 } 
    963         } 
    964  
    965  
    966  
    967         protected function _keyExistsRecursive($keys, $data_array) { 
     972                } 
     973        } 
     974 
     975        protected function _keyExistsRecursive($keys, $data_array) 
     976        { 
    968977                $thiskey = current($keys); 
    969978 
    970979                if (is_numeric($thiskey)) { // force numeric strings to be integers 
    971                         $thiskey = (int)$thiskey; 
    972                 } 
    973  
    974                 if (array_key_exists($thiskey, $data_array) ) { 
     980                        $thiskey = (int) $thiskey; 
     981                } 
     982 
     983                if (array_key_exists($thiskey, $data_array)) { 
    975984                        if (sizeof($keys) == 1) { 
    976985                                return true; 
     
    9921001         * @private 
    9931002         */ 
    994         public function _getValue($key) { 
    995                 if (strpos($key, ISPK_ARRAY_PATH_SEPARATOR)!== FALSE) { 
     1003        public function _getValue($key) 
     1004        { 
     1005                if (strpos($key, ISPK_ARRAY_PATH_SEPARATOR) !== FALSE) { 
    9961006                        $key = trim($key, ISPK_ARRAY_PATH_SEPARATOR); 
    9971007                        $keys = explode(ISPK_ARRAY_PATH_SEPARATOR, $key); 
     
    10021012        } 
    10031013 
    1004  
    1005          
    1006         protected function _getValueRecursive($keys, $data_array, $level=0) { 
     1014        protected function _getValueRecursive($keys, $data_array, $level=0) 
     1015        { 
    10071016                $thiskey = current($keys); 
    10081017 
    10091018                if (is_numeric($thiskey)) { // force numeric strings to be integers 
    1010                         $thiskey = (int)$thiskey; 
    1011                 } 
    1012  
    1013                 if (array_key_exists($thiskey, $data_array) ) { 
     1019                        $thiskey = (int) $thiskey; 
     1020                } 
     1021 
     1022                if (array_key_exists($thiskey, $data_array)) { 
    10141023                        if (sizeof($keys) == 1) { 
    10151024                                return $data_array[$thiskey]; 
     
    10171026                                if ($level < ISPK_RECURSION_MAX) { 
    10181027                                        unset($keys[key($keys)]); 
    1019                                         return $this->_getValueRecursive($keys, $data_array[$thiskey], $level+1); 
     1028                                        return $this->_getValueRecursive($keys, $data_array[$thiskey], $level + 1); 
    10201029                                } else { 
    10211030                                        Inspekt_Error::raiseError('Inspekt recursion limit met', E_USER_WARNING); 
     
    10281037        } 
    10291038 
    1030  
    10311039        /** 
    10321040         * Sets a value in the _source array 
     
    10361044         * @return mixed 
    10371045         */ 
    1038         protected function _setValue($key, $val) { 
    1039                 if (strpos($key, ISPK_ARRAY_PATH_SEPARATOR)!== FALSE) { 
     1046        protected function _setValue($key, $val) 
     1047        { 
     1048                if (strpos($key, ISPK_ARRAY_PATH_SEPARATOR) !== FALSE) { 
    10401049                        $key = trim($key, ISPK_ARRAY_PATH_SEPARATOR); 
    10411050                        $keys = explode(ISPK_ARRAY_PATH_SEPARATOR, $key); 
     
    10471056        } 
    10481057 
    1049  
    1050         protected function _setValueRecursive($keys, $val, $data_array, $level=0) { 
     1058        protected function _setValueRecursive($keys, $val, $data_array, $level=0) 
     1059        { 
    10511060                $thiskey = current($keys); 
    10521061 
    10531062                if (is_numeric($thiskey)) { // force numeric strings to be integers 
    1054                         $thiskey = (int)$thiskey; 
    1055                 } 
    1056  
    1057                 if ( array_key_exists($thiskey, $data_array) ) { 
     1063                        $thiskey = (int) $thiskey; 
     1064                } 
     1065 
     1066                if (array_key_exists($thiskey, $data_array)) { 
    10581067                        if (sizeof($keys) == 1) { 
    10591068                                $data_array[$thiskey] = $val; 
     
    10621071                                if ($level < ISPK_RECURSION_MAX) { 
    10631072                                        unset($keys[key($keys)]); 
    1064                                         return $this->_setValueRecursive($keys, $val, $data_array[$thiskey], $level+1); 
     1073                                        return $this->_setValueRecursive($keys, $val, $data_array[$thiskey], $level + 1); 
    10651074                                } else { 
    10661075                                        Inspekt_Error::raiseError('Inspekt recursion limit met', E_USER_WARNING); 
     
    10721081                } 
    10731082        } 
     1083 
    10741084} 
  • branches/1.5/libs/extensions/Inspekt/Inspekt/Cage/Session.php

    r2164 r2326  
    1010 * @deprecated 
    1111 */ 
    12  
    1312require_once dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'Cage.php'; 
    1413 
     
    1615 * @package Inspekt 
    1716 */ 
    18 class Inspekt_Cage_Session extends Inspekt_Cage { 
    19          
    20         static public function Factory(&$source, $conf_file = NULL, $conf_section = NULL, $strict = TRUE) { 
     17class Inspekt_Cage_Session extends Inspekt_Cage 
     18{ 
     19 
     20        static public function Factory(&$source, $conf_file = NULL, $conf_section = NULL, $strict = TRUE) 
     21        { 
    2122 
    2223                if (!is_array($source)) { 
     
    2728                $cage->_setSource($source); 
    2829                $cage->_parseAndApplyAutoFilters($conf_file); 
    29                  
    30                 if (ini_get('session.use_cookies') || ini_get('session.use_only_cookies') ) { 
     30 
     31                if (ini_get('session.use_cookies') || ini_get('session.use_only_cookies')) { 
    3132                        if (isset($_COOKIE) && isset($_COOKIE[session_name()])) { 
    3233                                session_id($_COOKIE[session_name()]); 
     
    4142                        } 
    4243                } 
    43                  
    44                  
     44 
     45 
    4546                if ($strict) { 
    4647                        $source = NULL; 
     
    4849 
    4950                return $cage; 
    50                  
     51 
    5152                register_shutdown_function(); 
    52                  
    53                 register_shutdown_function( array($this, '_repopulateSession') ); 
    54                  
     53 
     54                register_shutdown_function(array($this, '_repopulateSession')); 
    5555        } 
    56          
    57          
    58          
    59         protected function _repopulateSession() { 
     56 
     57        protected function _repopulateSession() 
     58        { 
    6059                $_SESSION = array(); 
    6160                $_SESSION = $this->_source; 
    6261        } 
    63          
    6462 
    65          
    6663} 
  • branches/1.5/libs/extensions/Inspekt/Inspekt/Error.php

    r2164 r2326  
    1313 * 
    1414 */ 
    15 class Inspekt_Error { 
     15class Inspekt_Error 
     16{ 
    1617 
    17     /** 
    18      * Constructor 
    19      * 
    20      * @return Inspekt_Error 
    21      */ 
    22     public function  __construct() { 
     18        /** 
     19         * Constructor 
     20         * 
     21         * @return Inspekt_Error 
     22         */ 
     23        public function __construct() 
     24        { 
     25                 
     26        } 
    2327 
    24     } 
     28        /** 
     29         * Raises an error.  In >= PHP5, this will throw an exception. 
     30         * 
     31         * @param string $msg 
     32         * @param integer $type One of the PHP Error Constants (E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE) 
     33         * 
     34         * @link http://www.php.net/manual/en/ref.errorfunc.php#errorfunc.constants 
     35         */ 
     36        public static function raiseError($msg, $type = E_USER_WARNING) 
     37        { 
     38                throw new Exception($msg, $type); 
     39        } 
    2540 
    26     /** 
    27      * Raises an error.  In >= PHP5, this will throw an exception. 
    28      * 
    29      * @param string $msg 
    30      * @param integer $type One of the PHP Error Constants (E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE) 
    31      * 
    32      * @link http://www.php.net/manual/en/ref.errorfunc.php#errorfunc.constants 
    33      */ 
    34     public static function raiseError($msg, $type = E_USER_WARNING) 
    35     { 
    36         throw new Exception($msg, $type); 
    37     } 
    3841} 
  • branches/1.5/libs/extensions/Inspekt/Inspekt/Supercage.php

    r2164 r2326  
    77 * @package Inspekt 
    88 */ 
    9  
    109/** 
    1110 * require main Inspekt class 
     
    2423 * 
    2524 */ 
    26 Class Inspekt_Supercage { 
     25Class Inspekt_Supercage 
     26{ 
    2727 
    2828        /** 
     
    3232         */ 
    3333        var $get; 
    34  
    3534        /** 
    3635         * The post cage 
     
    3938         */ 
    4039        var $post; 
    41  
    4240        /** 
    4341         * The cookie cage 
     
    4644         */ 
    4745        var $cookie; 
    48  
    4946        /** 
    5047         * The env cage 
     
    5350         */ 
    5451        var $env; 
    55  
    5652        /** 
    5753         * The files cage 
     
    6056         */ 
    6157        var $files; 
    62  
    6358        /** 
    6459         * The session cage 
     
    6762         */ 
    6863        var $session; 
    69  
    7064        var $server; 
    7165 
     
    7569         * @return Inspekt_Supercage 
    7670         */ 
    77         public function Inspekt_Supercage() { 
     71        public function Inspekt_Supercage() 
     72        { 
    7873                // placeholder 
    7974        } 
     
    8681         * @return Inspekt_Supercage 
    8782         */ 
    88         static public function Factory($config_file = NULL, $strict = TRUE) { 
     83        static public function Factory($config_file = NULL, $strict = TRUE) 
     84        { 
    8985 
    90                 $sc     = new Inspekt_Supercage(); 
     86                $sc = new Inspekt_Supercage(); 
    9187                $sc->_makeCages($config_file, $strict); 
    9288 
     
    9793 
    9894                return $sc; 
    99  
    10095        } 
    10196 
     
    107102         * @param boolean $strict 
    108103         */ 
    109         protected function _makeCages($config_file=NULL, $strict=TRUE) { 
    110                 $this->get              = Inspekt::makeGetCage($config_file, $strict); 
    111                 $this->post             = Inspekt::makePostCage($config_file, $strict); 
    112                 $this->cookie   = Inspekt::makeCookieCage($config_file, $strict); 
    113                 $this->env              = Inspekt::makeEnvCage($config_file, $strict); 
    114                 $this->files    = Inspekt::makeFilesCage($config_file, $strict); 
     104        protected function _makeCages($config_file=NULL, $strict=TRUE) 
     105        { 
     106                $this->get = Inspekt::makeGetCage($config_file, $strict); 
     107                $this->post = Inspekt::makePostCage($config_file, $strict); 
     108                $this->cookie = Inspekt::makeCookieCage($config_file, $strict); 
     109                $this->env = Inspekt::makeEnvCage($config_file, $strict); 
     110                $this->files = Inspekt::makeFilesCage($config_file, $strict); 
    115111                // $this->session       = Inspekt::makeSessionCage($config_file, $strict); 
    116                 $this->server   = Inspekt::makeServerCage($config_file, $strict); 
     112                $this->server = Inspekt::makeServerCage($config_file, $strict); 
    117113        } 
    118          
    119          
    120         public function addAccessor($name) { 
     114 
     115        public function addAccessor($name) 
     116        { 
    121117                $this->get->addAccessor($name); 
    122118                $this->post->addAccessor($name);