Changeset 2813
- Timestamp:
- 11/14/08 17:52:39 (8 weeks ago)
- Location:
- branches/081018-handlers/htdocs/system
- Files:
-
- 27 added
- 11 modified
-
classes/adminhandler.php (modified) (1 diff)
-
classes/ajaxadminhandler.php (modified) (1 diff)
-
classes/formui.php (modified) (19 diffs)
-
classes/installhandler.php (modified) (10 diffs)
-
classes/installschema.php (added)
-
classes/rewriterules.php (modified) (1 diff)
-
classes/site.php (modified) (2 diffs)
-
classes/templateengine.php (modified) (1 diff)
-
classes/theme.php (modified) (1 diff)
-
schema/sqlite/install.php (added)
-
themes/admin/theme.php (modified) (2 diffs)
-
themes/installer/db_setup.php (modified) (2 diffs)
-
themes/installer/formcontrols (added)
-
themes/installer/formcontrols/formcontrol_checkbox.php (added)
-
themes/installer/formcontrols/formcontrol_checkboxes.php (added)
-
themes/installer/formcontrols/formcontrol_fieldset.php (added)
-
themes/installer/formcontrols/formcontrol_form.php (added)
-
themes/installer/formcontrols/formcontrol_password.php (added)
-
themes/installer/formcontrols/formcontrol_radio.php (added)
-
themes/installer/formcontrols/formcontrol_select.php (added)
-
themes/installer/formcontrols/formcontrol_silos.php (added)
-
themes/installer/formcontrols/formcontrol_submit.php (added)
-
themes/installer/formcontrols/formcontrol_tabs.php (added)
-
themes/installer/formcontrols/formcontrol_text.php (added)
-
themes/installer/formcontrols/formcontrol_textarea.php (added)
-
themes/installer/formcontrols/formcontrol_textmulti.php (added)
-
themes/installer/formcontrols/formcontrol_wrapper.php (added)
-
themes/installer/formcontrols/installer_advancedoptions.php (added)
-
themes/installer/formcontrols/installer_checkboxes.php (added)
-
themes/installer/formcontrols/installer_installstep.php (added)
-
themes/installer/formcontrols/installer_installstep_nohelp.php (added)
-
themes/installer/formcontrols/installer_nextstep.php (added)
-
themes/installer/formcontrols/installer_options.php (added)
-
themes/installer/formcontrols/installer_password.php (added)
-
themes/installer/formcontrols/installer_password_wrapper.php (added)
-
themes/installer/formcontrols/installer_submit.php (added)
-
themes/installer/script.js (modified) (2 diffs)
-
themes/installer/theme.php (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/081018-handlers/htdocs/system/classes/adminhandler.php
r2754 r2813 1757 1757 } 1758 1758 1759 /**1760 * Function used to set theme variables to the add module dashboard widget1761 * TODO make this form use an AJAX call instead of reloading the page1762 */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 dashboard1784 * @param object form FormUI object1785 */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 form1792 return false;1793 }1794 1759 } 1795 1760 -
branches/081018-handlers/htdocs/system/classes/ajaxadminhandler.php
r2754 r2813 507 507 echo json_encode( $output ); 508 508 } 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 } 509 531 } 510 532 ?> -
branches/081018-handlers/htdocs/system/classes/formui.php
r2603 r2813 22 22 protected $checksum; 23 23 public $template = 'formcontainer'; 24 p ublic$properties = array();24 protected $properties = array(); 25 25 26 26 /** … … 158 158 $contents.= $control->get($forvalidation); 159 159 } 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 ); 168 171 } 169 172 … … 181 184 $this->theme_obj = Themes::create( 'admin', 'RawPHPEngine', $theme_dir ); 182 185 } 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 193 198 $class = $control->class; 194 195 199 $message = ''; 196 200 if($forvalidation) { … … 201 205 } 202 206 } 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); 205 210 } 206 211 return $this->theme_obj; … … 313 318 } 314 319 } 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; 315 346 } 316 347 } … … 405 436 public function salted_name() 406 437 { 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()); 408 440 } 409 441 … … 419 451 420 452 $theme = $this->get_theme($forvalidation, $this); 421 $theme->start_buffer();422 $theme-> success = false;453 454 $theme->assign('success', false); 423 455 424 456 // Should we be validating? … … 432 464 } 433 465 } 434 $theme-> success = true;435 $theme-> message = $this->options['success_message'];466 $theme->assign('success', true); 467 $theme->assign('message', $this->options['success_message']); 436 468 } 437 469 else { … … 440 472 } 441 473 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 446 482 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); 461 487 } 462 488 … … 480 506 { 481 507 $out = ''; 482 $this->get_theme( $forvalidation )->start_buffer();483 508 foreach($this->controls as $control) { 484 509 $out.= $control->get( $forvalidation ); 485 510 } 486 $this->get_theme( $forvalidation )->end_buffer();487 511 return $out; 488 512 } … … 829 853 { 830 854 $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() ); 842 865 } 843 866 … … 1008 1031 protected function get_theme($forvalidation) 1009 1032 { 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); 1015 1034 } 1016 1035 … … 1154 1173 class FormControlTag extends FormContainer 1155 1174 { 1175 public $tag; 1176 1156 1177 /** 1157 1178 * Override the FormControl constructor to support more parameters … … 1184 1205 $tag = $this->tag; 1185 1206 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 ); 1193 1214 } 1194 1215 … … 1210 1231 { 1211 1232 $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 ); 1215 1238 } 1216 1239 … … 1324 1347 { 1325 1348 $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 ); 1332 1356 } 1333 1357 } … … 1347 1371 { 1348 1372 $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 ); 1353 1378 } 1354 1379 … … 1502 1527 function get( $forvalidation = true ) 1503 1528 { 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>'; 1506 1530 } 1507 1531 … … 1567 1591 } 1568 1592 } 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 ); 1577 1600 } 1578 1601 -
branches/081018-handlers/htdocs/system/classes/installhandler.php
r2724 r2813 6 6 */ 7 7 class 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(); 8 13 9 14 /** … … 18 23 19 24 // 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/'); 21 26 22 27 /** … … 43 48 } 44 49 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 }62 50 // set the default values now, which will be overriden as we go 63 51 $this->form_defaults(); … … 66 54 $this->display('requirements'); 67 55 } 68 69 /*70 * Add the AJAX hooks71 */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' );74 56 75 57 /* … … 86 68 if ( isset( $db_connection ) ) { 87 69 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 ); 105 71 $this->handler_vars['db_user']= $db_connection['username']; 106 72 $this->handler_vars['db_pass']= $db_connection['password']; … … 131 97 } 132 98 99 // This will use formUI 133 100 $db_type = $this->handler_vars['db_type']; 134 101 if ( $db_type == 'mysql' || $db_type == 'pgsql' ) { … … 165 132 } 166 133 167 168 169 134 // 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); 176 136 177 137 EventLog::log(_t('Habari successfully installed.'), 'info', 'default', 'habari'); … … 322 282 ); 323 283 } 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 325 299 $pdo_drivers_ok = count( $pdo_drivers ); 326 300 $this->theme->assign( 'pdo_drivers_ok', $pdo_drivers_ok ); … … 903 877 } 904 878 905 return true;906 }907 908 /**909 * returns an array of Files declarations used by Habari910 */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 file928 * if the clause for this sqlite doesn't exist.929 * @return bool success or failure930 **/931 public function secure_sqlite()932 {933 if ( FALSE === strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) ) {934 // .htaccess is only needed on Apache935 return false;936 }937 if ( !file_exists( HABARI_PATH . '/.htaccess') ) {938 // no .htaccess to write to939 return false;940 }941 if ( !is_writable( HABARI_PATH . DIRECTORY_SEPARATOR . '.htaccess' ) ) {942 // we can't update the file943 return false;944 }945 946 // Get the files clause947 $sqlite_contents = $this->sqlite_contents();948 $files_contents = "\n" . implode( "\n", $sqlite_contents ) . "\n";949 950 // See if it already exists951 $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 file954 if ( $fh = fopen( HABARI_PATH . DIRECTORY_SEPARATOR . '.htaccess', 'a' ) ) {955 if ( FALSE === fwrite( $fh, $files_contents ) ) {956 // Can't write to the file957 &nbs
