Changeset 2851

Show
Ignore:
Timestamp:
11/24/08 01:06:07 (7 weeks ago)
Author:
ringmaster
Message:

Replace the $_GET, $_POST, $_COOKIE, and $_SERVER superglobals with an instance of the new SuperGlobal class. Requesting array values via the SuperGlobal class returns an InputFilter'ed version of the value. To obtain the raw value, use the ->get() method. For example:
// $_GETfoo? submitted as 'one <script>two</script> three'
echo $_GETfoo?; // Outputs 'one three'
echo $_GET->raw('foo'); // Outputs 'one <script>two</script> three'
Yes, this may break previously working features.

Files:
12 modified

Legend:

Unmodified
Added
Removed
  • makaanga/0.x/htdocs/index.php

    r2214 r2851  
    2222 * Start the profile time 
    2323 */ 
    24 $profile_start= microtime(true);  
     24$profile_start= microtime(true); 
    2525 
    2626/** 
     
    4343// as well as the ability to dynamically change HTTP headers after output has started. 
    4444ob_start(); 
     45 
     46// Replace all of the $_GET, $_POST and $_SERVER superglobals with object 
     47// representations of each.  Unset $_REQUEST, which is evil. 
     48// $_COOKIE must be set after sessions start 
     49SuperGlobal::process_gps(); 
    4550 
    4651/** 
     
    122127if ( file_exists( $config ) ) { 
    123128    require_once $config; 
    124      
     129 
    125130    // Set the default locale. 
    126131    Locale::set( isset($locale) ? $locale : 'en-us' ); 
    127      
     132 
    128133    if ( !defined( 'DEBUG' ) ) define( 'DEBUG', false ); 
    129134 
     
    191196 * Include all the active plugins. 
    192197 * By loading them here they'll have global scope. 
    193  *  
     198 * 
    194199 * We loop through them twice so we can cache all plugin classes on the first load() call. 
    195200 * This gives about 60% improvement. 
     
    208213// Start the session. 
    209214Session::init(); 
     215 
     216// Replace the $_COOKIE superglobal with an object representation 
     217SuperGlobal::process_c(); 
    210218 
    211219// Initiating request handling, tell the plugins. 
  • trunk/htdocs/system/admin/css/admin.css

    r2846 r2851  
    18211821 
    18221822body.page-tags .container span { 
    1823     white-space: nowrap; 
     1823    display: inline-block; 
    18241824} 
    18251825 
  • trunk/htdocs/system/classes/actionhandler.php

    r2825 r2851  
    22 
    33/** 
    4  * A base class handler for URL-based actions. All ActionHandlers must  
     4 * A base class handler for URL-based actions. All ActionHandlers must 
    55 * extend this class for the Controller to call their actions. 
    6  *   
     6 * 
    77 * @package Habari 
    8  */   
     8 */ 
    99class ActionHandler 
    1010{ 
    1111    /** 
    1212     * Name of action to trigger 
    13      *  
     13     * 
    1414     * @var string 
    1515     * @see act() 
    1616     */ 
    1717    public $action = ''; 
    18      
     18 
    1919    /** 
    2020     * Internal array of handler variables (state info) 
    21      *  
     21     * 
    2222     * @var array 
    2323     */ 
     
    3131     * 
    3232     * @param string $action the action that was in the URL rule 
    33      */               
     33     */ 
    3434    public function act($action) { 
    3535        $this->action = $action; 
    36          
     36 
    3737        $action_method = 'act_' . $action; 
    3838        $before_action_method = 'before_' . $action_method; 
    3939        $after_action_method = 'after_' . $action_method; 
    40          
     40 
    4141        if (method_exists($this, $action_method)) { 
    4242            if (method_exists($this, $before_action_method)) { 
     
    4646             * Plugin action to allow plugins to execute before a certain 
    4747             * action is triggered 
    48              *  
     48             * 
    4949             * @see ActionHandler::$action 
    5050             * @action before_act_{$action} 
    5151             */ 
    5252            Plugins::act( $before_action_method, $this ); 
    53              
     53 
    5454            $this->$action_method(); 
    55              
     55 
    5656            /** 
    5757             * Plugin action to allow plugins to execute after a certain 
    5858             * action is triggered 
    59              *  
     59             * 
    6060             * @see ActionHandler::$action 
    6161             * @action before_act_{$action} 
     
    7171     * Helper method to convert calls to $handler->my_action() 
    7272     * to $handler->act('my_action'); 
    73      *  
     73     * 
    7474     * @param string $function function name 
    7575     * @param array $args function arguments 
    7676     */ 
    7777    public function __call($function, $args) { 
    78         $this->handler_vars = array_merge($this->handler_vars, $args); 
    7978        return $this->act($function); 
    8079    } 
    81      
     80 
    8281    /** 
    83      * Helper method to allow RewriteRules to send a redirect. The method will  
     82     * Helper method to allow RewriteRules to send a redirect. The method will 
    8483     * redirect to the build_str of the RewriteRule if matched. 
    8584     */ 
  • trunk/htdocs/system/classes/adminhandler.php

    r2845 r2851  
    4747        /* At this point, Controller has not created handler_vars, so we have to modify $_POST/$_GET. */ 
    4848        if ( isset( $last_form_data['post'] ) ) { 
    49             $_POST = array_merge( $_POST, $last_form_data['post'] ); 
     49            $_POST = $_POST->merge( $last_form_data['post'] ); 
    5050            $_SERVER['REQUEST_METHOD']= 'POST'; // This will trigger the proper act_admin switches. 
    5151            Session::remove_error( 'expired_form_submission' ); 
    5252        } 
    5353        if ( isset( $last_form_data['get'] ) ) { 
    54             $_GET = array_merge( $_GET, $last_form_data['get'] ); 
     54            $_GET = $_GET->merge( $last_form_data['get'] ); 
    5555            Session::remove_error( 'expired_form_submission' ); 
    5656            // No need to change REQUEST_METHOD since GET is the default. 
     
    420420    public function post_publish() 
    421421    { 
    422         extract( $this->handler_vars ); 
    423  
    424422        $form = $this->form_publish( new Post(), false ); 
    425423 
     
    486484    public function get_publish( $template = 'publish') 
    487485    { 
    488         extract( $this->handler_vars ); 
     486        $extract = $this->handler_vars->filter_keys('id', 'content_type'); 
     487        foreach($extract as $key => $value) { 
     488            $$key = $value; 
     489        } 
     490 
    489491        if ( isset( $id ) ) { 
    490492            $post = Post::get( array( 'id' => $id, 'status' => Post::status( 'any' ) ) ); 
     
    540542        $form->content->tabindex = 2; 
    541543        $form->content->value = $post->content; 
     544        $form->content->raw = true; 
    542545 
    543546        // Create the tags field 
     
    616619    public function post_delete_post() 
    617620    { 
    618         extract( $this->handler_vars ); 
     621        $extract = $this->handler_vars->filter_keys('id', 'nonce', 'timestamp', 'PasswordDigest'); 
     622        foreach($extract as $key => $value) { 
     623            $$key = $value; 
     624        } 
     625 
    619626        $okay = TRUE; 
    620627        if ( empty( $id ) || empty( $nonce ) || empty( $timestamp ) || empty( $PasswordDigest ) ) { 
     
    657664    public function post_user() 
    658665    { 
    659         extract( $this->handler_vars ); 
     666        $extract = $this->handler_vars->filter_keys('nonce', 'timestamp', 'PasswordDigest'); 
     667        foreach($extract as $key => $value) { 
     668            $$key = $value; 
     669        } 
    660670 
    661671        $wsse = Utils::WSSE( $nonce, $timestamp ); 
     
    671681        $fields = array( 'user_id' => 'id', 'delete' => NULL, 'username' => 'username', 'displayname' => 'displayname', 'email' => 'email', 'imageurl' => 'imageurl', 'pass1' => NULL, 'locale_tz' => 'locale_tz', 'locale_date_format' => 'locale_date_format', 'locale_time_format' => 'locale_time_format' ); 
    672682        $fields = Plugins::filter( 'adminhandler_post_user_fields', $fields ); 
    673         $posted_fields = array_intersect_key( $this->handler_vars, $fields ); 
     683        $posted_fields = $this->handler_vars->filter_keys( array_keys( $fields ) ); 
    674684 
    675685        // Editing someone else's profile? If so, load that user's profile 
     
    743753                    break; 
    744754                default: 
    745                     if ( isset( ${$fields[$posted_field]} ) && ( $user->info->$fields[$posted_field] != ${$fields[$posted_field]} ) ) { 
    746                         $user->info->$fields[$posted_field]= ${$fields[$posted_field]}; 
     755                    if ( isset( $this->handler_vars[$fields[$posted_field]] ) && ( $user->info->$fields[$posted_field] != $this->handler_vars[$fields[$posted_field]] ) ) { 
     756                        $user->info->$fields[$posted_field]= $this->handler_vars[$fields[$posted_field]]; 
    747757                        Session::notice( _t( 'Userinfo updated!' ) ); 
    748758                        $update = TRUE; 
     
    875885        $this->fetch_users(); 
    876886 
    877         extract( $this->handler_vars ); 
     887        $extract = $this->handler_vars->filter_keys('newuser', 'delete', 'new_pass1', 'new_pass2', 'new_email', 'new_username'); 
     888        foreach($extract as $key => $value) { 
     889            $$key = $value; 
     890        } 
    878891 
    879892        if(isset($newuser)) { 
    880893            $action = 'newuser'; 
    881         } elseif(isset($delete)) { 
     894        } 
     895        elseif(isset($delete)) { 
    882896            $action = 'delete'; 
    883897        } 
     
    936950    public function get_plugin_toggle() 
    937951    { 
    938         extract( $this->handler_vars ); 
     952        $extract = $this->handler_vars->filter_keys('plugin_id', 'action'); 
     953        foreach($extract as $key => $value) { 
     954            $$key = $value; 
     955        } 
     956 
    939957        $plugins = Plugins::list_all(); 
    940958        foreach($plugins as $file) { 
     
    10201038    public function get_activate_theme() 
    10211039    { 
    1022         extract( $this->handler_vars ); 
     1040        $theme_name = $this->handler_vars['theme_name']; 
     1041        $theme_dir = $this->handler_vars['theme_dir']; 
    10231042        if ( isset($theme_name)  && isset($theme_dir) ) { 
    10241043            Themes::activate_theme( $theme_name,  $theme_dir ); 
  • trunk/htdocs/system/classes/controller.php

    r2592 r2851  
    119119        $start_url = trim($start_url, '/'); 
    120120 
    121         /* Remove the querystring from the URL */ 
    122         if ( strpos($start_url, '?') !== FALSE ) { 
    123             list($start_url, $query_string)= explode('?', $start_url); 
    124         } 
    125  
    126         /* Return $_GET values to their proper place */ 
    127         if( !empty($query_string) ) { 
    128             parse_str($query_string, $_GET); 
    129         } 
    130  
    131         /* Undo what magic_quotes_gpc might have wrought */ 
    132         Utils::revert_magic_quotes_gpc(); 
    133  
    134121        /* Allow plugins to rewrite the stub before it's passed through the rules */ 
    135122        $start_url = Plugins::filter('rewrite_request', $start_url); 
     
    154141 
    155142        /* Also, we musn't forget to add the GET and POST vars into the action's settings array */ 
    156         $controller->handler->handler_vars = array_merge($controller->handler->handler_vars, $_GET, $_POST); 
     143        $handler_vars = new SuperGlobal($controller->handler->handler_vars); 
     144        $handler_vars = $handler_vars->merge($_GET, $_POST); 
     145        $controller->handler->handler_vars = $handler_vars; 
    157146        return true; 
    158147    } 
  • trunk/htdocs/system/classes/formui.php

    r2755 r2851  
    699699    protected $properties = array(); 
    700700    protected $template = null; 
     701    protected $raw = false; 
    701702 
    702703    /** 
     
    922923            case 'value': 
    923924                if(isset($_POST[$this->field])) { 
    924                     return $_POST[$this->field]; 
     925                    return $this->raw ? $_POST->raw($this->field) : $_POST[$this->field]; 
    925926                } 
    926927                else { 
     
    995996                $this->template = $value; 
    996997                break; 
     998            case 'raw': 
     999                $this->raw = $value; 
     1000                break; 
    9971001            default: 
    9981002                $this->properties[$name] = $value; 
     
    10751079        $this->container->move_after( $this, $target ); 
    10761080    } 
    1077      
     1081 
    10781082    /** 
    10791083     * Remove this controls from the form 
     
    11821186        $theme = $this->get_theme($forvalidation, $this); 
    11831187        $max = Tags::max_count(); 
    1184          
     1188 
    11851189        $tag = $this->tag; 
    1186          
     1190 
    11871191        $theme->class = 'tag_'.$tag->slug; 
    11881192        $theme->id = $tag->id; 
     
    11901194        $theme->caption = $tag->tag; 
    11911195        $theme->count = $tag->count; 
    1192                  
     1196 
    11931197        return $theme->fetch( 'tabcontrol_tag' ); 
    11941198    } 
     
    13531357        return $theme->fetch( $this->get_template() ); 
    13541358    } 
    1355      
     1359 
    13561360    /** 
    13571361     * Magic __get method for returning property values 
     
    13791383        return parent::__get($name); 
    13801384    } 
    1381      
     1385 
    13821386} 
    13831387 
  • trunk/htdocs/system/classes/hiengine.php

    r2705 r2851  
    237237                case 'url': 
    238238                    return '<?php URL::out( \'' . $cmd_matches[2] . '\' ); ?>'; 
     239                case 'session': 
     240                    switch($cmd_matches[2]) { 
     241                        case 'messages': 
     242                            return '<?php if(Session::has_messages()){Session::messages_out();} ?>'; 
     243                        case 'errors': 
     244                            return '<?php if(Session::has_errors()){Session::messages_out();} ?>'; 
     245                    } 
    239246            } 
    240247        } 
  • trunk/htdocs/system/classes/installhandler.php

    r2820 r2851  
    1414    public function act_begin_install() 
    1515    { 
    16         // Revert magic quotes, normally Controller calls this. 
    17         Utils::revert_magic_quotes_gpc(); 
    18  
    1916        // Create a new theme to handle the display of the installer 
    2017        $this->theme = Themes::create('installer', 'RawPHPEngine', HABARI_PATH . '/system/installer/'); 
    21          
     18 
    2219        /** 
    2320         * Set user selected Locale or default 
     
    119116        // now merge in any HTTP POST values that might have been sent 
    120117        // these will override the defaults and the config.php values 
    121         $this->handler_vars = array_merge($this->handler_vars, $_POST); 
     118        $this->handler_vars = $this->handler_vars->merge($_POST); 
    122119 
    123120        // we need details for the admin user to install 
     
    165162        } 
    166163 
    167          
     164 
    168165 
    169166        // Installation complete. Secure sqlite if it was chosen as the database type to use 
     
    178175        return true; 
    179176    } 
    180      
     177 
    181178    /* 
    182179     * Helper function to grab list of plugins 
     
    217214                $plugin['active']= false; 
    218215            } 
    219              
     216 
    220217            $plugins[$plugin_id]= $plugin; 
    221218        } 
    222          
     219 
    223220        return $plugins; 
    224221    } 
    225      
     222 
    226223    /** 
    227224     * Helper function to remove code repetition 
     
    234231            $this->theme->assign($key, $value); 
    235232        } 
    236          
     233 
    237234        $this->theme->assign('plugins', $this->get_plugins()); 
    238          
     235 
    239236        $this->theme->display($template_name); 
    240237        exit; 
     
    305302        } 
    306303        $this->theme->assign('missing_extensions',  $missing_extensions); 
    307          
     304 
    308305        if ( extension_loaded('pdo') ) { 
    309306            /* Check for PDO drivers */ 
     
    333330            } 
    334331        } 
    335          
     332 
    336333        /** 
    337334         * $local_writable is used in the template, but never set in Habari 
     
    341338         */ 
    342339        $this->theme->assign( 'local_writable', true ); 
    343          
     340 
    344341        return $requirements_met; 
    345342    } 
     
    449446            DB::begin_transaction(); 
    450447        } 
    451          
     448 
    452449        /* Store current DB version so we don't immediately run dbdelta. */ 
    453450        Version::save_dbversion(); 
     
    824821            'rewrite_base' => '#RewriteBase /', 
    825822            'rewrite_rule' => 'RewriteRule . index.php [PT]', 
     823            'hide_habari' => 'RewriteRule ^(system/(classes|locale|schema|$)) index.php [PT]', 
    826824            'close_block' => '### HABARI END', 
    827825        ); 
     
    956954 
    957955    /** 
    958      * attempts to write the Files clause to the .htaccess file  
     956     * attempts to write the Files clause to the .htaccess file 
    959957     * if the clause for this sqlite doesn't exist. 
    960958     * @return bool success or failure 
     
    998996        return true; 
    999997    } 
    1000      
     998 
    1001999    private function upgrade_db_pre ( $current_version ) { 
    1002          
     1000 
    10031001        // this is actually a stripped-down version of DatabaseConnection::upgrade() - it doesn't support files 
    1004          
     1002 
    10051003        $upgrade_functions = get_class_methods( $this ); 
    1006          
     1004 
    10071005        $upgrades = array(); 
    1008          
     1006 
    10091007        foreach ( $upgrade_functions as $fn ) { 
    1010              
     1008 
    10111009            // match all methods named "upgrade_db_pre_<rev#>" 
    10121010            if ( preg_match( '%^upgrade_db_pre_([0-9]+)$%i', $fn, $matches ) ) { 
    1013                  
     1011 
    10141012                $upgrade_version = intval( $matches[1] ); 
    1015                  
     1013 
    10161014                if ( $upgrade_version > $current_version ) { 
    1017                      
     1015 
    10181016                    $upgrades[ sprintf( '%010s_1', $upgrade_version ) ] = $fn; 
    1019                      
    1020                 } 
    1021                  
    1022             } 
    1023              
    1024         } 
    1025          
     1017 
     1018                } 
     1019 
     1020            } 
     1021 
     1022        } 
     1023 
    10261024        // sort the upgrades by revision, ascending 
    10271025        ksort( $upgrades ); 
    1028                  
    1029          
     1026 
     1027 
    10301028        foreach ( $upgrades as $upgrade ) { 
    1031              
     1029 
    10321030            $result =& call_user_func( array( $this, $upgrade ) ); 
    1033              
     1031 
    10341032            // if we failed, abort 
    10351033            if ( $result === false ) { 
    10361034                break; 
    10371035            } 
    1038              
    1039         } 
    1040          
    1041     } 
    1042      
     1036 
     1037        } 
     1038 
     1039    } 
     1040 
    10431041    private function upgrade_db_post ( $current_version ) { 
    1044          
     1042 
    10451043        // this is actually a stripped-down version of DatabaseConnection::upgrade() - it doesn't support files 
    1046          
     1044 
    10471045        $upgrade_functions = get_class_methods( $this ); 
    1048          
     1046 
    10491047        $upgrades = array(); 
    1050          
     1048 
    10511049        foreach ( $upgrade_functions as $fn ) { 
    1052              
     1050 
    10531051            // match all methods named "upgrade_db_post_<rev#>" 
    10541052            if ( preg_match( '%^upgrade_db_post_([0-9]+)$%i', $fn, $matches ) ) { 
    1055                  
     1053 
    10561054<