Changeset 2813

Show
Ignore:
Timestamp:
11/14/08 17:52:39 (8 weeks ago)
Author:
freakerz
Message:

FormUIze Installer, allow schemas to hook it and add their db-specific fields. InstallSchema extends Pluggable so actions/filters/etc are registered in schemas... many more changes

Location:
branches/081018-handlers/htdocs/system
Files:
27 added
11 modified

Legend:

Unmodified
Added
Removed
  • branches/081018-handlers/htdocs/system/classes/adminhandler.php

    r2754 r2813  
    17571757    } 
    17581758 
    1759     /** 
    1760      * Function used to set theme variables to the add module dashboard widget 
    1761      * TODO make this form use an AJAX call instead of reloading the page 
    1762      */ 
    1763     public function filter_dash_module_add_item( $module, $id, $theme ) 
    1764     { 
    1765         $modules = Modules::get_all(); 
    1766         if ( $modules ) { 
    1767             $modules = array_combine( array_values( $modules ), array_values( $modules ) ); 
    1768         } 
    1769  
    1770         $form = new FormUI( 'dash_additem' ); 
    1771         $form->append( 'select', 'module', 'null:unused' ); 
    1772         $form->module->options = $modules; 
    1773         $form->append( 'submit', 'submit', _t('+') ); 
    1774         //$form->on_success( array( $this, 'dash_additem' ) ); 
    1775         $form->properties['onsubmit'] = "dashboard.add(); return false;"; 
    1776         $theme->additem_form = $form->get(); 
    1777  
    1778         $module['content'] = $theme->fetch( 'dash_additem' ); 
    1779         return $module; 
    1780     } 
    1781  
    1782     /** 
    1783      * Adds a module to the user's dashboard 
    1784      * @param object form FormUI object 
    1785      */ 
    1786     public function dash_additem( $form ) 
    1787     { 
    1788         $new_module = $form->module->value; 
    1789         Modules::add( $new_module ); 
    1790  
    1791         // return false to redisplay the form 
    1792         return false; 
    1793     } 
    17941759} 
    17951760 
  • branches/081018-handlers/htdocs/system/classes/ajaxadminhandler.php

    r2754 r2813  
    507507        echo json_encode( $output ); 
    508508    } 
     509     
     510    /** 
     511     * Function used to set theme variables to the add module dashboard widget 
     512     */ 
     513    public function ajax_dash_module_add_item( $module, $id, $theme ) 
     514    { 
     515        $modules = Modules::get_all(); 
     516        if ( $modules ) { 
     517            $modules = array_combine( array_values( $modules ), array_values( $modules ) ); 
     518        } 
     519 
     520        $form = new FormUI( 'dash_additem' ); 
     521        $form->append( 'select', 'module', 'null:unused' ); 
     522        $form->module->options = $modules; 
     523        $form->append( 'submit', 'submit', _t('+') ); 
     524        //$form->on_success( array( $this, 'dash_additem' ) ); 
     525        $form->properties['onsubmit'] = "dashboard.add(); return false;"; 
     526        $theme->additem_form = $form->get(); 
     527 
     528        $module['content'] = $theme->fetch( 'dash_additem' ); 
     529        return $module; 
     530    } 
    509531} 
    510532?> 
  • branches/081018-handlers/htdocs/system/classes/formui.php

    r2603 r2813  
    2222    protected $checksum; 
    2323    public $template = 'formcontainer'; 
    24     public $properties = array(); 
     24    protected $properties = array(); 
    2525 
    2626    /** 
     
    158158            $contents.= $control->get($forvalidation); 
    159159        } 
    160         $theme->contents = $contents; 
    161         // Do not move before $contents 
    162         // Else, these variables will contain the last control's values 
    163         $theme->class = $this->class; 
    164         $theme->id = $this->name; 
    165         $theme->caption = $this->caption; 
    166  
    167         return $theme->fetch( $this->template ); 
     160         
     161        foreach($this->properties as $prop => $value) { 
     162            $theme->assign($prop, $value); 
     163        } 
     164         
     165        $theme->assign('contents', $contents); 
     166        $theme->assign('class', $this->class); 
     167        $theme->assign('id', $this->name); 
     168        $theme->assign('caption', $this->caption); 
     169         
     170        return $theme->fetch( $this->template, true ); 
    168171    } 
    169172 
     
    181184            $this->theme_obj = Themes::create( 'admin', 'RawPHPEngine', $theme_dir ); 
    182185        } 
    183         if($control instanceof FormControl) { 
    184             // PHP doesn't allow __get() to return pointers, and passing this array to foreach directly generates an error. 
    185             $properties = $control->properties; 
    186             foreach($properties as $name => $value) { 
    187                 $this->theme_obj->$name = $value; 
    188             } 
    189             $this->theme_obj->field = $control->field; 
    190             $this->theme_obj->value = $control->value; 
    191             $this->theme_obj->caption = $control->caption; 
    192             $this->theme_obj->id = (string) $control->id; 
     186        if($control instanceof FormControl) {    
     187            $this->theme_obj->start_buffer(); 
     188             
     189            foreach($control->properties as $name => $value) { 
     190                $this->theme_obj->assign($name, $value); 
     191            } 
     192             
     193            $this->theme_obj->assign('field', $control->field); 
     194            $this->theme_obj->assign('value', $control->value); 
     195            $this->theme_obj->assign('caption', $control->caption); 
     196            $this->theme_obj->assign('id', (string) $control->id); 
     197             
    193198            $class = $control->class; 
    194  
    195199            $message = ''; 
    196200            if($forvalidation) { 
     
    201205                } 
    202206            } 
    203             $this->theme_obj->class = implode( ' ', (array) $class ); 
    204             $this->theme_obj->message = $message; 
     207             
     208            $this->theme_obj->assign('class', implode( ' ', (array) $class )); 
     209            $this->theme_obj->assign('message', $message); 
    205210        } 
    206211        return $this->theme_obj; 
     
    313318                } 
    314319            } 
     320        } 
     321    } 
     322     
     323    /** 
     324     * Magic property setter for FormContainer and its descendants 
     325     * 
     326     * @param string $name The name of the property 
     327     * @param mixed $value The value to set the property to 
     328     */ 
     329    public function __set($name, $value) 
     330    { 
     331        switch($name) { 
     332            case 'contents': 
     333            case 'class': 
     334            case 'id': 
     335            case 'caption': 
     336            case 'template': 
     337            case 'controls': 
     338            case 'checksum': 
     339            case 'container': 
     340            case 'theme_obj': 
     341                $this->$name = $value; 
     342                break; 
     343            default: 
     344                $this->properties[$name] = $value; 
     345                break; 
    315346        } 
    316347    } 
     
    405436    public function salted_name() 
    406437    { 
    407         return md5(Options::get('secret') . 'added salt, for taste' . $this->checksum()); 
     438        //return md5(Options::get('secret') . 'added salt, for taste' . $this->checksum()); 
     439        return md5('added salt, for taste' . $this->checksum()); 
    408440    } 
    409441 
     
    419451 
    420452        $theme = $this->get_theme($forvalidation, $this); 
    421         $theme->start_buffer(); 
    422         $theme->success = false; 
     453         
     454        $theme->assign('success', false); 
    423455 
    424456        // Should we be validating? 
     
    432464                    } 
    433465                } 
    434                 $theme->success = true; 
    435                 $theme->message = $this->options['success_message']; 
     466                $theme->assign('success', true); 
     467                $theme->assign('message', $this->options['success_message']); 
    436468            } 
    437469            else { 
     
    440472        } 
    441473 
    442         $out = ''; 
    443  
    444         $theme->controls = $this->output_controls($forvalidation); 
    445  
     474        $theme->assign('controls', $this->output_controls($forvalidation)); 
     475        $theme->assign('id', Utils::slugify($this->name)); 
     476        $theme->assign('class', implode( " ", (array) $this->class )); 
     477        $theme->assign('action', $this->options['form_action']); 
     478        $theme->assign('onsubmit', ($this->properties['onsubmit'] == '') ? '' : "onsubmit=\"{$this->properties['onsubmit']}\""); 
     479        $theme->assign('salted_name', $this->salted_name()); 
     480        $theme->assign('pre_out', $this->pre_out_controls()); 
     481         
    446482        foreach($this->properties as $prop => $value) { 
    447             $theme->$prop = $value; 
    448         } 
    449  
    450         $theme->id = Utils::slugify($this->name); 
    451         $theme->class = implode( " ", (array) $this->class ); 
    452         $theme->action = $this->options['form_action']; 
    453         $theme->onsubmit = ($this->properties['onsubmit'] == '') ? '' : "onsubmit=\"{$this->properties['onsubmit']}\""; 
    454         $theme->salted_name = $this->salted_name(); 
    455         $theme->pre_out = $this->pre_out_controls(); 
    456  
    457         $out = $theme->fetch($this->options['template']); 
    458         $theme->end_buffer(); 
    459  
    460         return $out; 
     483            $theme->assign($prop, $value); 
     484        } 
     485         
     486        return $theme->fetch($this->options['template'], true); 
    461487    } 
    462488 
     
    480506    { 
    481507        $out = ''; 
    482         $this->get_theme( $forvalidation )->start_buffer(); 
    483508        foreach($this->controls as $control) { 
    484509            $out.= $control->get( $forvalidation ); 
    485510        } 
    486         $this->get_theme( $forvalidation )->end_buffer(); 
    487511        return $out; 
    488512    } 
     
    829853    { 
    830854        $theme = $this->get_theme($forvalidation); 
    831         $theme->start_buffer(); 
    832  
    833         foreach($this->properties as $prop => $value) { 
    834             $theme->$prop = $value; 
    835         } 
    836  
    837         $theme->caption = $this->caption; 
    838         $theme->id = $this->name; 
    839         $theme->value = $this->value; 
    840  
    841         return $theme->fetch( $this->get_template(), true ); 
     855 
     856        foreach($this->properties as $prop => $value) {          
     857            $theme->assign($prop, $value); 
     858        } 
     859         
     860        $theme->assign('caption', $this->caption); 
     861        $theme->assign('id', $this->name); 
     862        $theme->assign('value', $this->value); 
     863                     
     864        return $theme->fetch( $this->get_template() ); 
    842865    } 
    843866 
     
    10081031    protected function get_theme($forvalidation) 
    10091032    { 
    1010         $theme = $this->container->get_theme($forvalidation, $this); 
    1011         foreach($this->properties as $name => $value) { 
    1012             $theme->name = $value; 
    1013         } 
    1014         return $theme; 
     1033        return $this->container->get_theme($forvalidation, $this); 
    10151034    } 
    10161035 
     
    11541173class FormControlTag extends FormContainer 
    11551174{ 
     1175    public $tag; 
     1176     
    11561177    /** 
    11571178     * Override the FormControl constructor to support more parameters 
     
    11841205        $tag = $this->tag; 
    11851206         
    1186         $theme->class = 'tag_'.$tag->slug; 
    1187         $theme->id = $tag->id; 
    1188         $theme->weight = $max > 0 ? round(($tag->count * 10)/$max) : 0; 
    1189         $theme->caption = $tag->tag; 
    1190         $theme->count = $tag->count; 
    1191                  
    1192         return $theme->fetch( 'tabcontrol_tag' ); 
     1207        $theme->assign('class', 'tag_'.$tag->slug); 
     1208        $theme->assign('id', $tag->id); 
     1209        $theme->assign('weight', $max > 0 ? round(($tag->count * 10)/$max) : 0); 
     1210        $theme->assign('caption', $tag->tag); 
     1211        $theme->assign('count', $tag->count); 
     1212         
     1213        return $theme->fetch( 'tabcontrol_tag', true ); 
    11931214    } 
    11941215 
     
    12101231    { 
    12111232        $theme = $this->get_theme($forvalidation); 
    1212         $theme->outvalue = $this->value == '' ? '' : substr(md5($this->value), 0, 8); 
    1213  
    1214         return $theme->fetch( $this->get_template() ); 
     1233 
     1234        $theme->assign('id', $this->name); 
     1235        $theme->assign('outvalue', $this->value == '' ? '' : substr(md5($this->value), 0, 8)); 
     1236         
     1237        return $theme->fetch( $this->get_template(), true ); 
    12151238    } 
    12161239 
     
    13241347    { 
    13251348        $theme = $this->get_theme($forvalidation); 
    1326         $theme->options = $this->options; 
    1327         $theme->multiple = $this->multiple; 
    1328         $theme->size = $this->size; 
    1329         $theme->id = $this->name; 
    1330  
    1331         return $theme->fetch( $this->get_template() ); 
     1349 
     1350        $theme->assign('options', $this->options); 
     1351        $theme->assign('multiple', $this->multiple); 
     1352        $theme->assign('size', $this->size); 
     1353        $theme->assign('id', $this->name); 
     1354     
     1355        return $theme->fetch( $this->get_template(), true ); 
    13321356    } 
    13331357} 
     
    13471371    { 
    13481372        $theme = $this->get_theme($forvalidation); 
    1349         $theme->options = $this->options; 
    1350         $theme->id = $this->name; 
    1351  
    1352         return $theme->fetch( $this->get_template() ); 
     1373         
     1374        $theme->assign('options', $this->options); 
     1375        $theme->assign('id', $this->name); 
     1376 
     1377        return $theme->fetch( $this->get_template(), true ); 
    13531378    } 
    13541379     
     
    15021527    function get( $forvalidation = true ) 
    15031528    { 
    1504         $out = '<div' . (($this->class) ? ' class="' . implode( " ", (array) $this->class ) . '"' : '') . (($this->id) ? ' id="' . $this->id . '"' : '') .'><label for="' . $this->name . '">' . $this->caption . '</label></div>'; 
    1505         return $out; 
     1529        return '<div' . (($this->class) ? ' class="' . implode( " ", (array) $this->class ) . '"' : '') . (($this->id) ? ' id="' . $this->id . '"' : '') .'><label for="' . $this->name . '">' . $this->caption . '</label></div>'; 
    15061530    } 
    15071531 
     
    15671591            } 
    15681592        } 
    1569         $theme->controls = $controls; 
    1570         // Do not move before $contents 
    1571         // Else, these variables will contain the last control's values 
    1572         $theme->class = $this->class; 
    1573         $theme->id = $this->name; 
    1574         $theme->caption = $this->caption; 
    1575  
    1576         return $theme->fetch( $this->template ); 
     1593        $theme->assign('controls', $controls); 
     1594 
     1595        $theme->assign('class', $this->class); 
     1596        $theme->assign('id', $this->name); 
     1597        $theme->assign('caption', $this->caption); 
     1598         
     1599        return $theme->fetch( $this->template, true ); 
    15771600    } 
    15781601 
  • branches/081018-handlers/htdocs/system/classes/installhandler.php

    r2724 r2813  
    66 */ 
    77class InstallHandler extends ActionHandler { 
     8     
     9    // Cached theme object for handling templates and presentation 
     10    private $theme = NULL; 
     11    // Cached schema object for db-specific install steps 
     12    private $schemas = array(); 
    813 
    914    /** 
     
    1823 
    1924        // Create a new theme to handle the display of the installer 
    20         $this->theme = Themes::create('installer', 'RawPHPEngine', HABARI_PATH . '/system/installer/'); 
     25        $this->theme = Themes::create('installer', 'RawPHPEngine', HABARI_PATH . '/system/themes/installer/'); 
    2126         
    2227        /** 
     
    4348        } 
    4449 
    45         // Dispatch AJAX requests. 
    46         if ( isset( $_POST['ajax_action'] ) ) { 
    47             switch ( $_POST['ajax_action'] ) { 
    48                 case 'check_mysql_credentials': 
    49                     self::ajax_check_mysql_credentials(); 
    50                     exit; 
    51                     break; 
    52                 case 'check_pgsql_credentials': 
    53                     self::ajax_check_pgsql_credentials(); 
    54                     exit; 
    55                     break; 
    56                 case 'check_sqlite_credentials': 
    57                     self::ajax_check_sqlite_credentials(); 
    58                     exit; 
    59                     break; 
    60             } 
    61         } 
    6250        // set the default values now, which will be overriden as we go 
    6351        $this->form_defaults(); 
     
    6654            $this->display('requirements'); 
    6755        } 
    68  
    69         /* 
    70          * Add the AJAX hooks 
    71          */ 
    72         Plugins::register( array('InstallHandler', 'ajax_check_mysql_credentials'), 'ajax_', 'check_mysql_credentials' ); 
    73         Plugins::register( array('InstallHandler', 'ajax_check_pgsql_credentials'), 'ajax_', 'check_pgsql_credentials' ); 
    7456 
    7557        /* 
     
    8668            if ( isset( $db_connection ) ) { 
    8769                list( $this->handler_vars['db_type'], $remainder )= explode( ':', $db_connection['connection_string'] ); 
    88                 switch( $this->handler_vars['db_type'] ) { 
    89                 case 'sqlite': 
    90                     // SQLite uses less info. 
    91                     // we stick the path in db_host 
    92                     $this->handler_vars['db_file']= $remainder; 
    93                     break; 
    94                 case 'mysql': 
    95                     list($host,$name)= explode(';', $remainder); 
    96                     list($discard, $this->handler_vars['db_host'])= explode('=', $host); 
    97                     list($discard, $this->handler_vars['db_schema'])= explode('=', $name); 
    98                     break; 
    99                 case 'pgsql': 
    100                     list($host,$name)= explode(' ', $remainder); 
    101                     list($discard, $this->handler_vars['db_host'])= explode('=', $host); 
    102                     list($discard, $this->handler_vars['db_schema'])= explode('=', $name); 
    103                     break; 
    104                 } 
     70                Plugins::act( 'install_existing_config', $this, $remainder ); 
    10571                $this->handler_vars['db_user']= $db_connection['username']; 
    10672                $this->handler_vars['db_pass']= $db_connection['password']; 
     
    13197        } 
    13298 
     99        // This will use formUI 
    133100        $db_type = $this->handler_vars['db_type']; 
    134101        if ( $db_type == 'mysql' || $db_type == 'pgsql' ) { 
     
    165132        } 
    166133 
    167          
    168  
    169134        // Installation complete. Secure sqlite if it was chosen as the database type to use 
    170         if ( $db_type == 'sqlite' ) { 
    171             if ( !$this->secure_sqlite() ) { 
    172                 $this->handler_vars['sqlite_contents'] = implode( "\n", $this->sqlite_contents() ); 
    173                 $this->display( 'sqlite' ); 
    174             } 
    175         } 
     135        Plugins::act('install_complete', $this); 
    176136 
    177137        EventLog::log(_t('Habari successfully installed.'), 'info', 'default', 'habari'); 
     
    322282            ); 
    323283        } 
    324  
     284         
     285        // Load available schemas' install script 
     286        foreach ($pdo_drivers as $pdo_driver) { 
     287            $file_path = HABARI_PATH . '/system/schema/' . $pdo_driver . '/install.php'; 
     288            if (file_exists($file_path)) { 
     289                include_once($file_path); 
     290            } 
     291            $classname = $pdo_driver.'Install'; 
     292            if (class_exists($pdo_driver.'Install')) { 
     293                $this->schemas[$pdo_driver] = new $classname(); 
     294                // Register plugin hooks 
     295                $this->schemas[$pdo_driver]->load(); 
     296            } 
     297        } 
     298                         
    325299        $pdo_drivers_ok = count( $pdo_drivers ); 
    326300        $this->theme->assign( 'pdo_drivers_ok', $pdo_drivers_ok ); 
     
    903877        } 
    904878 
    905         return true; 
    906     } 
    907  
    908     /** 
    909      * returns an array of Files declarations used by Habari 
    910      */ 
    911     public function sqlite_contents() 
    912     { 
    913         $db_file = basename( $this->handler_vars['db_file'] ); 
    914         $contents = array( 
    915             '### HABARI SQLITE START', 
    916             '<Files "' . $db_file . '">', 
    917             'Order deny,allow', 
    918             'deny from all', 
    919             '</Files>', 
    920             '### HABARI SQLITE END' 
    921         ); 
    922  
    923         return $contents; 
    924     } 
    925  
    926     /** 
    927      * attempts to write the Files clause to the .htaccess file  
    928      * if the clause for this sqlite doesn't exist. 
    929      * @return bool success or failure 
    930     **/ 
    931     public function secure_sqlite() 
    932     { 
    933         if ( FALSE === strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) ) { 
    934             // .htaccess is only needed on Apache 
    935             return false; 
    936         } 
    937         if ( !file_exists( HABARI_PATH . '/.htaccess') ) { 
    938             // no .htaccess to write to 
    939             return false; 
    940         } 
    941         if ( !is_writable( HABARI_PATH . DIRECTORY_SEPARATOR . '.htaccess' ) ) { 
    942             // we can't update the file 
    943             return false; 
    944         } 
    945  
    946         // Get the files clause 
    947         $sqlite_contents = $this->sqlite_contents(); 
    948         $files_contents = "\n" . implode( "\n", $sqlite_contents ) . "\n"; 
    949  
    950         // See if it already exists 
    951         $current_files_contents = file_get_contents( HABARI_PATH . DIRECTORY_SEPARATOR . '.htaccess'); 
    952         if ( FALSE === strpos( $current_files_contents, $files_contents ) ) { 
    953             // If not, append the files clause to the .htaccess file 
    954             if ( $fh = fopen( HABARI_PATH . DIRECTORY_SEPARATOR . '.htaccess', 'a' ) ) { 
    955                 if ( FALSE === fwrite( $fh, $files_contents ) ) { 
    956                     // Can't write to the file 
    957           &nbs