Exemplo n.º 1
0
 /**
  * Handles POST requests from the options admin page
  */
 public function post_options()
 {
     $option_items = array();
     $timezones = DateTimeZone::listIdentifiers();
     $timezones = array_merge(array('' => ''), array_combine(array_values($timezones), array_values($timezones)));
     $option_items[_t('Name & Tagline')] = array('title' => array('label' => _t('Site Name'), 'type' => 'text', 'helptext' => ''), 'tagline' => array('label' => _t('Site Tagline'), 'type' => 'text', 'helptext' => ''), 'about' => array('label' => _t('About'), 'type' => 'textarea', 'helptext' => ''));
     $option_items[_t('Publishing')] = array('pagination' => array('label' => _t('Items per Page'), 'type' => 'text', 'helptext' => ''), 'atom_entries' => array('label' => _t('Entries to show in Atom feed'), 'type' => 'text', 'helptext' => ''), 'comments_require_id' => array('label' => _t('Require Comment Author Info'), 'type' => 'checkbox', 'helptext' => ''), 'spam_percentage' => array('label' => _t('Comment SPAM Threshold'), 'type' => 'text', 'helptext' => _t('The likelihood a comment is considered SPAM, in percent.')));
     $option_items[_t('Time & Date')] = array('timezone' => array('label' => _t('Time Zone'), 'type' => 'select', 'selectarray' => $timezones, 'helptext' => _t('Current Date Time: %s', array(HabariDateTime::date_create()->format()))), 'dateformat' => array('label' => _t('Date Format'), 'type' => 'text', 'helptext' => _t('Current Date: %s', array(HabariDateTime::date_create()->date))), 'timeformat' => array('label' => _t('Time Format'), 'type' => 'text', 'helptext' => _t('Current Time: %s', array(HabariDateTime::date_create()->time))));
     $option_items[_t('Language')] = array('locale' => array('label' => _t('Locale'), 'type' => 'select', 'selectarray' => array_merge(array('' => 'default'), array_combine(HabariLocale::list_all(), HabariLocale::list_all())), 'helptext' => _t('International language code')), 'system_locale' => array('label' => _t('System Locale'), 'type' => 'text', 'helptext' => _t('The appropriate locale code for your server')));
     $option_items[_t('Troubleshooting')] = array('log_min_severity' => array('label' => _t('Minimum Severity'), 'type' => 'select', 'selectarray' => LogEntry::list_severities(), 'helptext' => _t('Only log entries with a this or higher severity.')), 'log_backtraces' => array('label' => _t('Log Backtraces'), 'type' => 'checkbox', 'helptext' => _t('Logs error backtraces to the log table\'s data column. Can drastically increase log size!')));
     /*$option_items[_t('Presentation')] = array(
     		'encoding' => array(
     			'label' => _t('Encoding'),
     			'type' => 'select',
     			'selectarray' => array(
     				'UTF-8' => 'UTF-8'
     				),
     			'helptext' => '',
     			),
     		);*/
     $option_items = Plugins::filter('admin_option_items', $option_items);
     $form = new FormUI('Admin Options');
     $tab_index = 3;
     foreach ($option_items as $name => $option_fields) {
         $fieldset = $form->append('wrapper', Utils::slugify(_u($name)), $name);
         $fieldset->class = 'container settings';
         $fieldset->append('static', $name, '<h2>' . htmlentities($name, ENT_COMPAT, 'UTF-8') . '</h2>');
         foreach ($option_fields as $option_name => $option) {
             $field = $fieldset->append($option['type'], $option_name, $option_name, $option['label']);
             $field->template = 'optionscontrol_' . $option['type'];
             $field->class = 'item clear';
             if ($option['type'] == 'select' && isset($option['selectarray'])) {
                 $field->options = $option['selectarray'];
             }
             $field->tabindex = $tab_index;
             $tab_index++;
             if (isset($option['helptext'])) {
                 $field->helptext = $option['helptext'];
             } else {
                 $field->helptext = '';
             }
         }
     }
     /* @todo: filter for additional options from plugins
      * We could either use existing config forms and simply extract
      * the form controls, or we could create something different
      */
     $submit = $form->append('submit', 'apply', _t('Apply'), 'admincontrol_submit');
     $submit->tabindex = $tab_index;
     $form->on_success(array($this, 'form_options_success'));
     $this->theme->form = $form->get();
     $this->theme->option_names = array_keys($option_items);
     $this->theme->display('options');
 }
Exemplo n.º 2
0
 /**
  * Entry point for installation.  The reason there is a begin_install
  * method to handle is that conceivably, the user can stop installation
  * mid-install and need an alternate entry point action at a later time.
  */
 public function act_begin_install()
 {
     // Create a new theme to handle the display of the installer
     $this->theme = Themes::create('installer', 'RawPHPEngine', HABARI_PATH . '/system/installer/');
     /**
      * Set user selected Locale or default
      */
     $this->theme->locales = HabariLocale::list_all();
     if (isset($_POST['locale']) && $_POST['locale'] != null) {
         HabariLocale::set($_POST['locale']);
         $this->theme->locale = $_POST['locale'];
         $this->handler_vars['locale'] = $_POST['locale'];
     } else {
         HabariLocale::set('en-us');
         $this->theme->locale = 'en-us';
         $this->handler_vars['locale'] = 'en-us';
     }
     /*
      * Check .htaccess first because ajax doesn't work without it.
      */
     if (!$this->check_htaccess()) {
         $this->handler_vars['file_contents'] = htmlentities(implode("\n", $this->htaccess()));
         $this->display('htaccess');
     }
     // Dispatch AJAX requests.
     if (isset($_POST['ajax_action'])) {
         switch ($_POST['ajax_action']) {
             case 'check_mysql_credentials':
                 self::ajax_check_mysql_credentials();
                 exit;
                 break;
             case 'check_pgsql_credentials':
                 self::ajax_check_pgsql_credentials();
                 exit;
                 break;
             case 'check_sqlite_credentials':
                 self::ajax_check_sqlite_credentials();
                 exit;
                 break;
         }
     }
     // set the default values now, which will be overriden as we go
     $this->form_defaults();
     if (!$this->meets_all_requirements()) {
         $this->display('requirements');
     }
     /*
      * Add the AJAX hooks
      */
     Plugins::register(array('InstallHandler', 'ajax_check_mysql_credentials'), 'ajax_', 'check_mysql_credentials');
     Plugins::register(array('InstallHandler', 'ajax_check_pgsql_credentials'), 'ajax_', 'check_pgsql_credentials');
     /*
      * Let's check the config.php file if no POST data was submitted
      */
     if (!file_exists(Site::get_dir('config_file')) && !isset($_POST['admin_username'])) {
         // no config file, and no HTTP POST
         $this->display('db_setup');
     }
     // try to load any values that might be defined in config.php
     if (file_exists(Site::get_dir('config_file'))) {
         include Site::get_dir('config_file');
         // check for old style config (global variable, pre-dates registry based config
         if (!Config::exists('db_connection') && isset($db_connection)) {
             // found old style config...
             // set up registry:
             Config::set('db_connection', $db_connection);
             // assign handler vars (for config file write)
             $this->set_handler_vars_from_db_connection();
             // write new config file
             if ($this->write_config_file(true)) {
                 // successful, so redirect:
                 Utils::redirect(Site::get_url('habari'));
             }
         }
         if (Config::exists('db_connection')) {
             $this->set_handler_vars_from_db_connection();
         }
         // if a $blog_data array exists in config.php, use it
         // to pre-load values for the installer
         // ** this is completely optional **
         if (isset($blog_data)) {
             foreach ($blog_data as $blog_datum => $value) {
                 $this->handler_vars[$blog_datum] = $value;
             }
         }
     }
     // now merge in any HTTP POST values that might have been sent
     // these will override the defaults and the config.php values
     $this->handler_vars = $this->handler_vars->merge($_POST);
     // we need details for the admin user to install
     if ('' == $this->handler_vars['admin_username'] || '' == $this->handler_vars['admin_pass1'] || '' == $this->handler_vars['admin_pass2'] || '' == $this->handler_vars['admin_email']) {
         // if none of the above are set, display the form
         $this->display('db_setup');
     }
     $db_type = $this->handler_vars['db_type'];
     if ($db_type == 'mysql' || $db_type == 'pgsql') {
         $this->handler_vars['db_host'] = $_POST["{$db_type}_db_host"];
         $this->handler_vars['db_user'] = $_POST["{$db_type}_db_user"];
         $this->handler_vars['db_pass'] = $_POST["{$db_type}_db_pass"];
         $this->handler_vars['db_schema'] = $_POST["{$db_type}_db_schema"];
     }
     // we got here, so we have all the info we need to install
     // make sure the admin password is correct
     if ($this->handler_vars['admin_pass1'] !== $this->handler_vars['admin_pass2']) {
         $this->theme->assign('form_errors', array('password_mismatch' => _t('Password mis-match.')));
         $this->display('db_setup');
     }
     // check whether prefix is valid
     if (isset($this->handler_vars['table_prefix']) && preg_replace('/[^a-zA-Z_]/', '', $this->handler_vars['table_prefix']) !== $this->handler_vars['table_prefix']) {
         $this->theme->assign('form_errors', array('table_prefix' => _t('Allowed characters are A-Z, a-z and "_".')));
         $this->display('db_setup');
     }
     // Make sure we still have a valid connection
     if (!call_user_func(array($this, "check_{$db_type}"))) {
         $this->display('db_setup');
     }
     // try to write the config file
     if (!$this->write_config_file()) {
         $this->theme->assign('form_errors', array('write_file' => _t('Could not write config.php file...')));
         $this->display('db_setup');
     }
     // try to install the database
     if (!$this->install_db()) {
         // the installation failed for some reason.
         // re-display the form
         $this->display('db_setup');
     }
     // activate plugins on POST
     if (count($_POST) > 0) {
         $this->activate_plugins();
     }
     // Installation complete. Secure sqlite if it was chosen as the database type to use
     if ($db_type == 'sqlite') {
         if (!$this->secure_sqlite()) {
             $this->theme->sqlite_contents = implode("\n", $this->sqlite_contents());
             $this->display('sqlite');
         }
     }
     EventLog::log(_t('Habari successfully installed.'), 'info', 'default', 'habari');
     Utils::redirect(Site::get_url('habari'));
 }