Ignore:
Timestamp:
08/15/10 18:45:12 (22 months ago)
Author:
vain
Message:
  • several changes to copyright, router, bootstrap, frontcontroller and various other files
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/httprequest.core.php

    r4568 r4578  
    2424    * 
    2525    * @license    GNU/GPL v2 or (at your option) any later version, see "/doc/LICENSE". 
    26     * 
    2726    * @author     Jens-André Koch <vain@clansuite.com> 
    28     * @copyright  Jens-André Koch (2005 - onwards) 
    29     * 
     27    * @copyright  Copyleft: All rights reserved. Jens-André Koch (2005 - onwards) 
    3028    * @link       http://www.clansuite.com 
    31     * @link       http://gna.org/projects/clansuite 
    32     * 
     29    *  
    3330    * @version    SVN: $Id$ 
    3431    */ 
     
    5148    # Parameters 
    5249    public function getParameterNames(); 
    53     public function issetParameter($parametername, $parameterArrayName = 'POST', $where = false); 
    54     public function getParameter($parametername, $parameterArrayName = 'POST'); 
     50    public function issetParameter($name, $arrayname = 'POST', $where = false); 
     51    public function getParameter($name, $arrayname = 'POST'); 
    5552    public static function getHeader($name); 
    56     public function getCookie($name); 
     53 
     54    # Direct Access to individual Parameters Arrays 
     55    public function getParameterFromCookie($name); 
     56    public function getParameterFromGet($name); 
     57    public function getParameterFromPost($name); 
     58    public function getParameterFromServer($name); 
    5759 
    5860    # Request Method 
    5961    public static function getRequestMethod(); 
    6062    public static function setRequestMethod($method); 
     63    public static function isAjax(); 
     64    public static function isPost(); 
     65    public static function isGet(); 
     66    public static function isPut(); 
     67    public static function isDelete(); 
    6168 
    6269    # $_SERVER Stuff 
     
    8087{ 
    8188    /** 
    82      * @var array Contains the cleaned $_POST Parameters 
     89     * @var array Contains the cleaned $_POST Parameters. 
    8390     */ 
    8491    private $post_parameters; 
    8592 
    8693    /** 
    87      * @var array Contains the cleaned $_GET Parameters 
     94     * @var array Contains the cleaned $_GET Parameters. 
    8895     */ 
    8996    private $get_parameters; 
    9097 
    9198    /** 
    92      * @var array Contains the cleaned $_COOKIE Parameters 
     99     * @var array Contains the cleaned $_COOKIE Parameters. 
    93100     */ 
    94101    private $cookie_parameters; 
     
    107114     * @var boolean for magic_quotes_gpc 
    108115     */ 
    109     private $magic_quotes_gpc; 
     116    private static $magic_quotes_gpc; 
     117 
     118    /** 
     119     * @var object Object with pieces of informations about the target route. 
     120     */ 
     121    private static $route; 
    110122 
    111123    /** 
     
    129141        if ((bool) ini_get('register_globals') and mb_strtolower(ini_get('register_globals')) != 'off') 
    130142        { 
    131             $this->cleanGlobals(); 
     143            self::cleanGlobals(); 
    132144        } 
    133145 
     
    138150        if ( 1 == get_magic_quotes_gpc() ) 
    139151        { 
    140             $this->magic_quotes_gpc = true; 
    141             $this->fix_magic_quotes(); 
     152            self::$magic_quotes_gpc = true; 
     153            self::fix_magic_quotes(); 
    142154            ini_set('magic_quotes_gpc', 0); 
    143155        } 
     
    146158         *  3) Additional Security Checks 
    147159         */ 
    148         # Block Proxies 
    149         Clansuite_DoorKeeper::blockProxies(); 
     160        # Clansuite_DoorKeeper::blockProxies(); 
     161 
     162        # block XSS 
     163        $_SERVER['PHP_SELF'] = htmlspecialchars($_SERVER['PHP_SELF']); 
     164        $_SERVER['QUERY_STRING'] = htmlspecialchars($_SERVER['QUERY_STRING']); 
    150165 
    151166        /** 
    152          *  4) Clear Array, Filter and Assign the $_REQUEST Global to it 
     167         *  4) Init Parameter Arrays and Assign the GLOBALS 
    153168         */ 
    154169 
     
    158173        $this->cookie_parameters    = array(); 
    159174 
    160         # Sanitize 
    161         $this->sanitizeRequest(); 
    162  
    163         # Assign the GLOBALS $_REQUEST, $_GET, $_POST, $_COOKIE 
     175        # Assign the GLOBALS $_GET, $_POST, $_COOKIE 
    164176        $this->get_parameters     = $_GET; 
    165177        $this->post_parameters    = $_POST; 
     
    177189     * @return boolean true | false 
    178190     */ 
    179     public function isGet() 
    180     { 
    181         if($this->requestMethod == 'GET') 
     191    public static function isGet() 
     192    { 
     193        if(self::$requestMethod == 'GET') 
    182194        { 
    183195            return true; 
     
    191203     * @return boolean true | false 
    192204     */ 
    193     public function isPost() 
    194     { 
    195         if($this->requestMethod == 'POST') 
     205    public static function isPost() 
     206    { 
     207        if(self::$requestMethod == 'POST') 
    196208        { 
    197209            return true; 
     
    205217     * @return boolean true | false 
    206218     */ 
    207     public function isPut() 
    208     { 
    209         if($this->requestMethod == 'PUT') 
     219    public static function isPut() 
     220    { 
     221        if(self::$requestMethod == 'PUT') 
    210222        { 
    211223            return true; 
     
    219231     * @return boolean true | false 
    220232     */ 
    221     public function isDelete() 
    222     { 
    223         if($this->requestMethod == 'DELETE') 
     233    public static function isDelete() 
     234    { 
     235        if(self::$requestMethod == 'DELETE') 
    224236        { 
    225237            return true; 
     
    232244     * Defaults to Request parameters array 
    233245     * 
    234      * @param string $parameterArrayName R, G, P, C (REQUEST, GET, POST, COOKIE) 
     246     * @param string $arrayname GET, POST, COOKIE 
    235247     * @return array 
    236248     */ 
    237     public function getParameterNames($parameterArrayName = 'REQUEST') 
    238     { 
    239         $parameterArrayName = mb_strtoupper($parameterArrayName); 
    240  
    241         if(in_array($parameterArrayName, $this->{mb_strtolower($parameterArrayName).'_arraynames'})) 
    242         { 
    243             return array_keys($this->{mb_strtolower($parameterArrayName).'_parameters'}); 
     249    public function getParameterNames($arrayname = 'GET') 
     250    { 
     251        $arrayname = mb_strtoupper($arrayname); 
     252 
     253        if(in_array($arrayname, $this->{mb_strtolower($arrayname).'_arraynames'})) 
     254        { 
     255            return array_keys($this->{mb_strtolower($arrayname).'_parameters'}); 
    244256        } 
    245257        else 
     
    252264     * isset, checks if a certain parameter exists in the parameters array 
    253265     * 
    254      * @param string $parametername Name of the Parameter 
    255      * @param string $parameterArrayName G, P, C. Default = POST. 
     266     * @param string $name Name of the Parameter 
     267     * @param string $arrayname G, P, C. Default = POST. 
    256268     * @param boolean $where If set to true, method will return the name of the array the parameter was found in. 
    257269     * @return mixed | boolean true|false | string arrayname 
    258270     */ 
    259     public function issetParameter($parametername, $parameterArrayName = 'POST', $where = false) 
    260     { 
    261         $parameterArrayName = mb_strtoupper($parameterArrayName); 
    262  
    263         if(in_array($parameterArrayName, array ('P', 'POST')) and isset($this->post_parameters[$parametername])) 
     271    public function issetParameter($name, $arrayname = 'POST', $where = false) 
     272    { 
     273        $arrayname = mb_strtoupper($arrayname); 
     274 
     275        if(in_array($arrayname, array ('P', 'POST')) and isset($this->post_parameters[$name])) 
    264276        { 
    265277            if($where == false) 
     
    273285        } 
    274286 
    275         if(in_array($parameterArrayName, array ('G', 'GET')) and isset($this->get_parameters[$parametername])) 
     287        if(in_array($arrayname, array ('G', 'GET')) and isset($this->get_parameters[$name])) 
    276288        { 
    277289            if($where == false) 
     
    285297        } 
    286298 
    287         if(in_array($parameterArrayName, array ('C', 'COOKIE')) and isset($this->cookie_parameters[$parametername])) 
     299        if(in_array($arrayname, array ('C', 'COOKIE')) and isset($this->cookie_parameters[$name])) 
    288300        { 
    289301            if($where == false) 
     
    303315     * get, returns a certain parameter if existing 
    304316     * 
    305      * @param string $parametername Name of the Parameter 
    306      * @param string $parameterArrayName G, P, C. Default = POST. 
     317     * @param string $name Name of the Parameter 
     318     * @param string $arrayname G, P, C. Default = POST. 
    307319     * @param string $default You can set a default value. It's returned if parametername was not found. 
    308320     * 
    309321     * @return mixed data | null 
    310322     */ 
    311     public function getParameter($parametername, $parameterArrayName = 'POST', $default = null) 
     323    public function getParameter($name, $arrayname = 'POST', $default = null) 
    312324    { 
    313325        /** 
    314          * check if the parameter exists in $parameterArrayName 
     326         * check if the parameter exists in $arrayname 
    315327         * the third property of issetParameter is set to true, so that we get the full and correct array name back 
    316          * even if shortcut like R, G, P or C ($parameterArrayName) was used. 
     328         * even if shortcut like G, P or C ($arrayname) was used. 
    317329         */ 
    318         $parameter_array = $this->issetParameter($parametername, $parameterArrayName, true); 
     330        $parameter_array = $this->issetParameter($name, $arrayname, true); 
    319331 
    320332        /** 
     
    324336        { 
    325337            # this returns a value from the parameterarray 
    326             return $this->{mb_strtolower($parameter_array).'_parameters'}[$parametername]; 
     338            return $this->{mb_strtolower($parameter_array).'_parameters'}[$name]; 
    327339        } 
    328340        elseif($default !== null) 
     
    340352     * set, returns a certain parameter if existing 
    341353     * 
    342      * @param string $parametername Name of the Parameter 
    343      * @param string $parameterArrayName G, P, C. Default = POST. 
     354     * @param string $name Name of the Parameter 
     355     * @param string $arrayname G, P, C. Default = POST. 
    344356     * @return mixed data | null 
    345357     */ 
    346     public function setParameter($parametername, $parameterArrayName = 'POST') 
    347     { 
    348         if(true == $this->issetParameter($parametername, $parameterArrayName)) 
    349         { 
    350             return $this->{mb_strtolower($parameterArrayName).'_parameters'}[$parametername]; 
     358    public function setParameter($name, $arrayname = 'POST') 
     359    { 
     360        if(true == $this->issetParameter($name, $arrayname)) 
     361        { 
     362            return $this->{mb_strtolower($arrayname).'_parameters'}[$name]; 
    351363        } 
    352364        else 
     
    359371     * Shortcut to get a Parameter from $_POST 
    360372     * 
    361      * @param string $parametername Name of the Parameter 
     373     * @param string $name Name of the Parameter 
    362374     * @return mixed data | null 
    363375     */ 
    364     public function getParameterFromPost($parametername) 
    365     { 
    366         return $this->getParameter($parametername, 'POST'); 
     376    public function getParameterFromPost($name) 
     377    { 
     378        return $this->getParameter($name, 'POST'); 
    367379    } 
    368380 
     
    370382     * Shortcut to get a Parameter from $_GET 
    371383     * 
    372      * @param string $parametername Name of the Parameter 
     384     * @param string $name Name of the Parameter 
    373385     * @return mixed data | null 
    374386     */ 
    375     public function getParameterFromGet($parametername) 
    376     { 
    377         return $this->getParameter($parametername, 'GET'); 
     387    public function getParameterFromGet($name) 
     388    { 
     389        return $this->getParameter($name, 'GET'); 
    378390    } 
    379391 
     
    381393     * Shortcut to get a Parameter from $_SERVER 
    382394     * 
    383      * @param string $parametername Name of the Parameter 
     395     * @param string $name Name of the Parameter 
    384396     * @return mixed data | null 
    385397     */ 
    386     public function getParameterFromServer($parametername) 
    387     { 
    388         if (in_array($parametername, array_keys($_SERVER))) 
    389         { 
    390             return $_SERVER[$parametername]; 
     398    public function getParameterFromServer($name) 
     399    { 
     400        if (in_array($name, array_keys($_SERVER))) 
     401        { 
     402            return $_SERVER[$name]; 
    391403        } 
    392404        else 
    393405        { 
    394406            return null; 
     407        } 
     408    } 
     409 
     410    /** 
     411     * Get previously set cookies. 
     412     * 
     413     * @param string $name Name of the Cookie 
     414     * @return Returns an associative array containing any previously set cookies. 
     415     */ 
     416    public function getParameterFromCookie($name) 
     417    { 
     418        if(isset($this->cookie_parameters[$name]) == true) 
     419        { 
     420            return $this->cookie_parameters($name); 
    395421        } 
    396422    } 
     
    405431    { 
    406432        $name = 'HTTP_' . mb_strtoupper(str_replace('-','_', $name)); 
     433 
    407434        if (isset($_SERVER[$name])) 
    408435        { 
    409436            return $_SERVER[$name]; 
    410437        } 
     438 
    411439        return null; 
    412440    } 
     
    417445     * 
    418446     * @todo check $_SERVER['SSL_PROTOCOL'] + $_SERVER['HTTP_X_FORWARD_PROTO']? 
     447     * @todo check -> or $_SERVER['SSL_PROTOCOL'] 
     448     * 
    419449     * @return string 
    420450     */ 
    421451    public static function getServerProtocol() 
    422452    { 
    423         if(self::isSecure()) # @todo check -> or $_SERVER['SSL_PROTOCOL'] 
     453        if(self::isSecure()) 
    424454        { 
    425455             return 'https://'; 
     
    646676    } 
    647677 
     678    /** 
     679     * Get Route 
     680     * 
     681     * @return TargetRoute Container 
     682     */ 
     683    public static function getRoute() 
     684    { 
     685        return self::$route; 
     686    } 
     687 
     688    /** 
     689     * Set Route 
     690     * 
     691     * @param $route The route container. 
     692     */ 
     693    public static function setRoute($route) 
     694    { 
     695        self::$route = $route; 
     696    } 
    648697 
    649698    /** 
     
    726775 
    727776    /** 
    728      * Get previously set cookies. 
    729      * 
    730      * @param string $name Name of the Cookie 
    731      * @return Returns an associative array containing any previously set cookies. 
    732      */ 
    733     public function getCookie($name) 
    734     { 
    735         if(isset($this->cookie_parameters[$name]) == true) 
    736         { 
    737             return $this->cookie_parameters($name); 
    738         } 
    739     } 
    740  
    741     /** 
    742      * Checks if a ajax-request is given, by checking 
    743      * X-Requested-With Header for xmlhttprequest. 
     777     * Checks if a ajax(xhr)-request is given, 
     778     * by checking X-Requested-With Header for xmlhttprequest. 
    744779     * 
    745780     * @return bool 
    746781     */ 
    747     public function isXhr() 
     782    public static function isAjax() 
    748783    { 
    749784        if(isset($_SERVER['X-Requested-With']) and mb_strtolower($_SERVER['X-Requested-With']) === 'xmlhttprequest') 
     
    759794            return false; 
    760795        } 
    761     } 
    762  
    763     /** 
    764      * Shorthand for isXhr() 
    765      * 
    766      * @return boolean 
    767      */ 
    768     public function isAjax() 
    769     { 
    770         return $this->isXhr(); 
    771796    } 
    772797 
     
    777802     * This code originally from Richard Heyes and Stefan Esser 
    778803     */ 
    779     private function cleanGlobals() 
     804    private static function cleanGlobals() 
    780805    { 
    781806        # Intercept GLOBALS overwrite 
     
    832857 
    833858    /** 
    834      * Handles possible Injections and clean up of $_REQUEST 
    835      */ 
    836     private function sanitizeRequest() 
    837     { 
    838         # Filter for Request-Parameter: id 
    839         if(isset($_REQUEST['id']) and ctype_digit($_REQUEST['id'])) 
    840         { 
    841             $this->parameters['id'] = (int) $_REQUEST['id']; 
    842         } 
    843  
    844         # Filter for Request-Parameter: items 
    845         if(isset($_REQUEST['items']) and ctype_digit($_REQUEST['items'])) 
    846         { 
    847             $this->parameters['items'] = (int) $_REQUEST['items']; 
    848         } 
    849  
    850         # Filter for Request-Parameter: defaultCol (Smarty Paginate Get Variable) 
    851         if(isset($_REQUEST['defaultCol']) and ctype_digit($_REQUEST['defaultCol'])) 
    852         { 
    853             $this->parameters['defaultCol'] = (int) $_REQUEST['defaultCol']; 
    854         } 
    855  
    856         # Filter for Request-Parameter: defaultSort (Smarty Paginate Get Variable) 
    857         if(isset($_REQUEST['defaultSort']) and ctype_alpha($_REQUEST['defaultSort']) and (($_REQUEST['defaultSort'] == 'desc') or ($_REQUEST['defaultSort'] == 'asc')) ) 
    858         { 
    859             $this->parameters['defaultSort'] = (int) $_REQUEST['defaultSort']; 
    860         } 
    861     } 
    862  
    863     /** 
    864859     * Revert magic_quotes() if still enabled 
    865860     * stripslashes + array_deep + non_recursive 
     
    872867     * @return Returns the magic quotes fixed $var 
    873868     */ 
    874     private function fix_magic_quotes($input = null) 
    875     { 
    876         if($this->magic_quotes_gpc == false) 
     869    private static function fix_magic_quotes($input = null) 
     870    { 
     871        if(self::$magic_quotes_gpc == false) 
    877872        { 
    878873            return $input; 
Note: See TracChangeset for help on using the changeset viewer.