public function __construct() { parent::__construct(); // Let's register the options page form so we can use it with ajax $self = $this; FormUI::register('admin_options', function ($form, $name, $extra_data) use($self) { $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 Email'), '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(DateTime::create()->format()))), 'dateformat' => array('label' => _t('Date Format'), 'type' => 'text', 'helptext' => _t('Current Date: %s', array(DateTime::create()->date))), 'timeformat' => array('label' => _t('Time Format'), 'type' => 'text', 'helptext' => _t('Current Time: %s', array(DateTime::create()->time)))); $option_items[_t('Language')] = array('locale' => array('label' => _t('Locale'), 'type' => 'select', 'selectarray' => array_merge(array('' => 'default'), array_combine(Locale::list_all(), Locale::list_all())), 'helptext' => Config::exists('locale') ? _t('International language code : This value is set in your config.php file, and cannot be changed here.') : _t('International language code'), 'disabled' => Config::exists('locale'), 'value' => Config::get('locale', Options::get('locale', 'en-us'))), '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 = Plugins::filter('admin_option_items', $option_items); $tab_index = 3; foreach ($option_items as $name => $option_fields) { /** @var FormControlFieldset $fieldset */ $fieldset = $form->append(FormControlWrapper::create(Utils::slugify(_u($name)))->set_properties(array('class' => 'container main settings'))); $fieldset->append(FormControlStatic::create($name)->set_static('<h2 class="lead">' . htmlentities($name, ENT_COMPAT, 'UTF-8') . '</h2>')); $fieldset->set_wrap_each('<div>%s</div>'); foreach ($option_fields as $option_name => $option) { /** @var FormControlLabel $label */ $label = $fieldset->append(FormControlLabel::create('label_for_' . $option_name, null)->set_label($option['label'])); /** @var FormControl $field */ $field = $label->append($option['type'], $option_name, $option_name); $label->set_for($field); if (isset($option['value'])) { $field->set_value($option['value']); } if (isset($option['disabled']) && $option['disabled'] == true) { $field->set_properties(array('disabled' => 'disabled')); } if ($option['type'] == 'select' && isset($option['selectarray'])) { $field->set_options($option['selectarray']); } $field->tabindex = $tab_index; $tab_index++; if (isset($option['helptext'])) { $field->set_helptext($option['helptext']); } } } $buttons = $form->append(new FormControlWrapper('buttons', null, array('class' => 'container'))); $buttons->append(FormControlSubmit::create('apply', null, array('tabindex' => $tab_index))->set_caption(_t('Apply'))); $form->on_success(array($self, 'form_options_success')); $form = Plugins::filter('admin_options_form', $form); }); }
/** * 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 = Locale::list_all(); if (isset($_POST['locale']) && $_POST['locale'] != null) { Locale::set($_POST['locale']); } else { Locale::set(Config::get('locale', 'en-us')); } $this->theme->locale = Locale::get(); $this->handler_vars['locale'] = Locale::get(); /** * 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(Method::create('\\Habari\\InstallHandler', 'ajax_check_mysql_credentials'), 'ajax_', 'check_mysql_credentials'); Plugins::register(Method::create('\\Habari\\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('site')); } } 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 (Config::exists('blog_data')) { $blog_data = Config::get('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 ((!Config::exists('db_connection') || Config::get('db_connection')->connection_string == '') && ($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->raw("{$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'); } // don't accept emails with control characters if (!ctype_print($this->handler_vars['admin_email'])) { $this->theme->assign('form_errors', array('admin_email' => _t('Only printable characters are allowed.'))); $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'); } // Try activating plugins and themes $this->activate_plugins(); $this->activate_theme(); // 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('site')); }
public function __construct() { $self = $this; FormUI::register('add_user', function (FormUI $form, $name) use($self) { $form->set_settings(array('use_session_errors' => true)); $form->append(FormControlText::create('username')->set_properties(array('class' => 'columns three', 'placeholder' => _t('Username')))->add_validator('validate_username')->add_validator('validate_required')); $form->append(FormControlText::create('email')->set_properties(array('class' => 'columns four', 'placeholder' => _t('E-Mail')))->add_validator('validate_email')->add_validator('validate_required')); $password = FormControlPassword::create('password')->set_properties(array('class' => 'columns three', 'placeholder' => _t('Password')))->add_validator('validate_required'); $form->append($password); $form->append(FormControlPassword::create('password_again')->set_properties(array('class' => 'columns three', 'placeholder' => _t('Password Again')))->add_validator('validate_same', $password)); $form->append(FormControlSubmit::create('newuser')->set_caption('Add User')); $form->add_validator(array($self, 'validate_add_user')); $form->on_success(array($self, 'do_add_user')); }); FormUI::register('delete_users', function (FormUI $form, $name) use($self) { $form->set_settings(array('use_session_errors' => true)); $form->append(FormControlAggregate::create('deletion_queue')->set_selector('.select_user')->label('Select All')); $author_list = Users::get_all(); $authors[0] = _t('nobody'); foreach ($author_list as $author) { $authors[$author->id] = $author->displayname; } $form->append(FormControlSelect::create('reassign')->set_options($authors)); $form->append(FormControlSubmit::create('delete_selected')->set_caption(_t('Delete Selected'))); $form->add_validator(array($self, 'validate_delete_users')); $form->on_success(array($self, 'do_delete_users')); }); FormUI::register('edit_user', function (FormUI $form, $name, $form_type, $data) use($self) { $form->set_settings(array('use_session_errors' => true)); $edit_user = $data['edit_user']; $field_sections = array('user_info' => _t('User Information'), 'change_password' => _t('Change Password'), 'regional_settings' => _t('Regional Settings'), 'dashboard' => _t('Dashboard')); // Create a tracker for who we are dealing with $form->append(FormControlData::create('edit_user')->set_value($edit_user->id)); // Generate sections foreach ($field_sections as $key => $name) { $fieldset = $form->append('wrapper', $key, $name); $fieldset->add_class('container main settings'); $fieldset->append(FormControlStatic::create($key)->set_static('<h2 class="lead">' . htmlentities($name, ENT_COMPAT, 'UTF-8') . '</h2>')); } // User Info $displayname = FormControlText::create('displayname')->set_value($edit_user->displayname); $form->user_info->append(FormControlLabel::wrap(_t('Display Name'), $displayname)); $username = FormControlText::create('username')->add_validator('validate_username', $edit_user->username)->set_value($edit_user->username); $form->user_info->append(FormControlLabel::wrap(_t('User Name'), $username)); $email = FormControlText::create('email')->add_validator('validate_email')->set_value($edit_user->email); $form->user_info->append(FormControlLabel::wrap(_t('Email'), $email)); $imageurl = FormControlText::create('imageurl')->set_value($edit_user->info->imageurl); $form->user_info->append(FormControlLabel::wrap(_t('Portrait URL'), $imageurl)); // Change Password $password1 = FormControlPassword::create('password1', null, array('autocomplete' => 'off'))->set_value(''); $form->change_password->append(FormControlLabel::wrap(_t('New Password'), $password1)); $password2 = FormControlPassword::create('password2', null, array('autocomplete' => 'off'))->set_value(''); $form->change_password->append(FormControlLabel::wrap(_t('New Password Again'), $password2)); $delete = $self->handler_vars->filter_keys('delete'); // don't validate password match if action is delete if (!isset($delete['delete'])) { $password2->add_validator('validate_same', $password1, _t('Passwords must match.')); } // Regional settings $timezones = \DateTimeZone::listIdentifiers(); $timezones = array_merge(array_combine(array_values($timezones), array_values($timezones))); $locale_tz = FormControlSelect::create('locale_tz', null, array('multiple' => false))->set_options($timezones)->set_value($edit_user->info->locale_tz); $form->regional_settings->append(FormControlLabel::wrap(_t('Timezone'), $locale_tz)); $locale_date_format = FormControlText::create('locale_date_format')->set_value($edit_user->info->locale_date_format); $form->regional_settings->append(FormControlLabel::wrap(_t('Date Format'), $locale_date_format)); $edit_user_info = $edit_user->info; if (isset($edit_user_info->locale_date_format) && $edit_user_info->locale_date_format != '') { $current = DateTime::create()->get($edit_user_info->locale_date_format); } else { $current = DateTime::create()->date; } $locale_date_format->set_helptext(_t('See <a href="%s">php.net/date</a> for details. Current format: %s', array('http://php.net/date', $current))); $locale_time_format = FormControlText::create('locale_time_format')->set_value($edit_user_info->locale_time_format); $form->regional_settings->append(FormControlLabel::wrap(_t('Time Format'), $locale_time_format)); if (isset($edit_user_info->locale_time_format) && $edit_user_info->locale_time_format != '') { $current = DateTime::create()->get($edit_user_info->locale_time_format); } else { $current = DateTime::create()->time; } $locale_time_format->set_helptext(_t('See <a href="%s">php.net/date</a> for details. Current format: %s', array('http://php.net/date', $current))); $locales = array_merge(array('' => _t('System default') . ' (' . Options::get('locale', 'en-us') . ')'), array_combine(Locale::list_all(), Locale::list_all())); $locale_lang = FormcontrolSelect::create('locale_lang', null, array('multiple' => false))->set_options($locales)->set_value($edit_user_info->locale_lang); $form->regional_settings->append(FormControlLabel::wrap(_t(' Language'), $locale_lang)); $spam_count = FormControlCheckbox::create('dashboard_hide_spam_count')->set_helptext(_t('Hide the number of SPAM comments on your dashboard.'))->set_value($edit_user_info->dashboard_hide_spam_count); $form->dashboard->append(FormControlLabel::wrap(_t('Hide Spam Count'), $spam_count)); // Groups if (User::identify()->can('manage_groups')) { $fieldset = $form->append(FormControlWrapper::create('groups')); $fieldset->add_class('container main settings'); $fieldset->append(FormControlStatic::create('groups_title')->set_static('<h2 class="lead">' . htmlentities(_t('Groups'), ENT_COMPAT, 'UTF-8') . '</h2>')); $fieldset->append(FormControlCheckboxes::create('user_group_membership')->set_options(Utils::array_map_field(UserGroups::get_all(), 'name', 'id'))->set_value($edit_user->groups)); } // Controls $controls = $form->append(FormControlWrapper::create('page_controls')->add_class('container controls transparent')); $apply = $controls->append(FormControlSubmit::create('apply')->set_caption(_t('Apply'))); // Get author list $author_list = Users::get_all(); $authors[0] = _t('nobody'); foreach ($author_list as $author) { $authors[$author->id] = $author->displayname; } unset($authors[$edit_user->id]); // We can't reassign this user's posts to themselves if we're deleting them $reassign = FormControlSelect::create('reassign')->set_options($authors); $reassign_label = FormControlLabel::wrap(_t('Reassign posts to:'), $reassign)->set_settings(array('wrap' => '<span class="reassigntext">%s</span>')); $controls->append($reassign_label); $controls->append(FormControlStatic::create('conjunction')->set_static(_t('and'))->set_settings(array('wrap' => '<span class="conjunction">%s</span>'))); $delete = $controls->append(FormControlSubmit::create('delete')->set_caption(_t('Delete'))->set_settings(array('wrap' => '<span>%s</span>'))->add_class('button')); $delete->on_success(array($self, 'edit_user_delete')); $delete->add_validator(array($self, 'validate_delete_user')); $apply->on_success(array($self, 'edit_user_apply')); $apply->add_validator(array($self, 'validate_edit_user')); }); parent::__construct(); }