public function index() { $view = $this->getView(); $request = $this->getPageRequest(); if (!\Core\user()->checkAccess('g:admin')) { return View::ERROR_ACCESSDENIED; } if ($request->isPost()) { // Update/save the site id. ConfigHandler::Set('/livefyre/siteid', $_POST['siteid']); \Core\set_message('Set Site ID Successfully!', 'success'); \Core\reload(); } // Pull the configuration options to see if livefyre is currently setup. $siteid = ConfigHandler::Get('/livefyre/siteid'); // Generate the form to either set or update the siteid. $form = new Form(); $form->set('method', 'POST'); $form->addElement('text', ['name' => 'siteid', 'title' => 'Site ID', 'value' => $siteid]); $view->assign('siteid', $siteid); $view->assign('url', ROOT_URL_NOSSL); $view->assign('form', $form); // Setup instructions: // http://www.livefyre.com/install/ }
public function configure() { $view = $this->getView(); $request = $this->getPageRequest(); if (!\Core\user()->checkAccess('g:admin')) { return View::ERROR_ACCESSDENIED; } if ($request->isPost()) { \ConfigHandler::Set('/piwik/server/host', $_POST['server_host']); \ConfigHandler::Set('/piwik/siteid', $_POST['site_id']); \ConfigHandler::Set('/piwik/tracking/all_subdomains', $_POST['all_domains']); \ConfigHandler::Set('/piwik/tracking/domain_title', $_POST['domain_title']); \Core\set_message('Updated Piwik settings successfully', 'success'); \Core\reload(); } $form = new Form(); $form->addElement('text', ['name' => 'server_host', 'title' => 'Server Host', 'required' => false, 'value' => \ConfigHandler::Get('/piwik/server/host'), 'description' => 'Enter the hostname of your Piwik server without the protocol']); $form->addElement('text', ['name' => 'site_id', 'title' => 'Site ID', 'required' => false, 'value' => \ConfigHandler::Get('/piwik/siteid'), 'description' => 'Enter the Site ID of this installation']); $form->addElement('checkbox', ['name' => 'all_domains', 'title' => 'Track visitors across all subdomains of your site', 'description' => 'So if one visitor visits x.corepl.us and y.corepl.us, they will be counted as a single unique visitor.', 'value' => '1', 'checked' => \ConfigHandler::Get('/piwik/tracking/all_subdomains')]); $form->addElement('checkbox', ['name' => 'domain_title', 'title' => 'Prepend the site domain to the page title when tracking', 'description' => 'So if someone visits the "About" page on blog.corepl.us it will be recorded as "blog / About". This is the easiest way to get an overview of your traffic by sub-domain. ', 'value' => '1', 'checked' => \ConfigHandler::Get('/piwik/tracking/domain_title')]); $form->addElement('submit', ['name' => 'submit', 'value' => 'Update']); $view->title = 'Piwik Analytics'; $view->assign('form', $form); }
public static function SpamKeywordsSave(Form $form) { ConfigHandler::Set('/security/spam_threshold', $form->getElementValue('threshold')); foreach ($form->getElements() as $el) { /** @var FormElement $el */ $n = $el->get('name'); if (strpos($n, 'score[') === 0) { $n = substr($n, 6, -1); $s = $el->get('value'); if ($s == '') { $s = 1; } $model = SpamHamKeywordModel::Construct($n); $model->set('score', $s); $model->save(); } } if ($form->getElementValue('new_keyword')) { $n = $form->getElementValue('new_keyword'); $s = $form->getElementValue('new_score'); if ($s == '') { $s = 1; } $model = SpamHamKeywordModel::Construct($n); $model->set('score', $s); $model->save(); } return true; }
/** * Internal function to set the default skins based on this theme * * Returns false if nothing changed, else will return the configuration options changed. * * @param boolean $install Set to false to force uninstall/disable mode. * @param int $verbosity (default 0) 0: standard output, 1: real-time, 2: real-time verbose output. * * @return false | array * * @throws \InstallerException */ public function _parseSkins($install = true, $verbosity = 0) { // Keep track of if this changed anything. $changes = array(); $action = $install ? 'Installing' : 'Uninstalling'; $set = $install ? 'Set' : 'Unset'; \Core\Utilities\Logger\write_debug($action . ' skins for ' . $this->getName()); // I need to get the schema definitions first. $node = $this->_xmlloader->getElement('skins'); // If requested, set those skins as the site default. $defaultFrontend = $node->getAttribute('default'); $adminFrontend = $node->getAttribute('admindefault'); $emailNode = $this->_xmlloader->getElement('emailskins'); $defaultEmail = $emailNode->getAttribute('default'); if ($defaultFrontend) { \ConfigHandler::Set('/theme/default_template', $defaultFrontend); $changes[] = 'Set default template'; } if ($adminFrontend) { \ConfigHandler::Set('/theme/default_admin_template', $adminFrontend); $changes[] = 'Set default admin template'; } if ($defaultEmail) { \ConfigHandler::Set('/theme/default_email_template', $defaultEmail); $changes[] = 'Set default email template'; } return sizeof($changes) ? $changes : false; }
public static function ConfigureSave(Form $form) { foreach ($form->getElements() as $el) { /** @var $el FormElement */ $n = $el->get('name'); // I only want config options here. if (strpos($n, 'config[') !== 0) { continue; } // Trim off the "config[]" wrapper. $k = substr($n, 7, -1); ConfigHandler::Set($k, $el->get('value')); } \Core\set_message('Saved configuration options', 'success'); return true; }
public static function SaveSiteSkins(Form $form) { foreach ($form->getElements() as $el) { /** @var FormElement $el */ $n = $el->get('name'); $v = $el->get('value'); if (strpos($n, 'config[') === 0) { $k = substr($n, 7, -1); ConfigHandler::Set($k, $v); } } return true; }
public static function _i18nSaveHandler(Form $form) { // NEW IDEA! // Instead of setting the override for keys, (possibly useful, just somewhere else)... // Set the enabled languages for this site. // This allows site administrators to NOT have every language under the sun appear if they're running SuSE. $selected = $form->getElement('languages[]')->get('value'); // Implode them into a single string. $enabled = implode('|', $selected); // Strip out any invalid character. $enabled = preg_replace('/[^a-zA-Z_|]/', '', $enabled); // And save! ConfigHandler::Set('/core/language/languages_enabled', $enabled); return true; // Create a custom ini for just these options. // This will allow the site admin to change a string without worrying about it getting overridden from an update. $lang = $form->getElementValue('lang'); $ini = "[$lang]\n; Custom locale strings set by the site manager!\n\n"; foreach($form->getElements() as $el){ /** @var FormElement $el */ $name = $el->get('name'); $val = $el->get('value'); if(strpos($name, 'MESSAGE') === 0 || strpos($name, 'FORMAT') === 0 || strpos($name, 'STRING') === 0){ $ini .= $name . ' = "' . str_replace('"', '\\"', $val) . '";' . "\n"; } } // Save this ini out to a custom i18n file. $fileout = \Core\Filestore\Factory::File(ROOT_PDIR . 'themes/custom/i18n/' . $lang . '.ini'); $fileout->putContents($ini); \Core\set_message('t:MESSAGE_SUCCESS_UPDATED_TRANSLATION_STRINGS'); return true; }
/** * The main configuration for any user option on the site. * * Displayed under the "Configure" menu. * * @return int */ public function admin() { $view = $this->getView(); $request = $this->getPageRequest(); // This is a super-admin-only page! if(!\Core\user()->checkAccess('g:admin')){ return View::ERROR_ACCESSDENIED; } $userConfigs = []; $userSchema = UserModel::GetSchema(); foreach($userSchema as $k => $dat){ if( $dat['type'] == Model::ATT_TYPE_UUID || $dat['type'] == Model::ATT_TYPE_UUID_FK || $dat['type'] == Model::ATT_TYPE_ID || $dat['type'] == Model::ATT_TYPE_ID_FK || (isset($dat['formtype']) && $dat['formtype'] == 'disabled') || (isset($dat['form']) && isset($dat['form']['type']) && $dat['form']['type'] == 'disabled') ){ // Skip these columns. continue; } $title = t('STRING_MODEL_USERMODEL_' . strtoupper($k)); $userConfigs[$k] = $title; } // Pull a list of options currently enabled for both registration and edit. $onReg = []; $onEdits = []; $curReg = explode('|', ConfigHandler::Get('/user/register/form_elements')); $curEdits = explode('|', ConfigHandler::Get('/user/edit/form_elements')); foreach($curReg as $k){ if(isset($userConfigs[$k])){ // It's a valid key in the current application! $onReg[] = [ 'key' => $k, 'checked' => true, 'title' => $userConfigs[$k], ]; } } foreach($curEdits as $k){ if(isset($userConfigs[$k])){ // It's a valid key in the current application! $onEdits[] = [ 'key' => $k, 'checked' => true, 'title' => $userConfigs[$k], ]; } } foreach($userConfigs as $k => $title) { // If any key isn't in either curReg and curEdit, tack it to the end of the respective array. if(!in_array($k, $curReg)) { $onReg[] = [ 'key' => $k, 'checked' => false, 'title' => $title, ]; } if(!in_array($k, $curEdits)) { $onEdits[] = [ 'key' => $k, 'checked' => false, 'title' => $title, ]; } } // Build a form to handle the config options themselves. // These will include password strength, whether or not captcha is enabled, etc. $configs = [ '/user/displayas', '/user/displayname/anonymous', '/user/email/allowchanging', '/user/enableavatar', '/user/password/minlength', '/user/password/requirecapitals', '/user/password/requiresymbols', '/user/password/requirenumbers', '/user/profileedits/requireapproval', '/user/register/allowpublic', '/user/register/requireapproval', '/user/register/requirecaptcha', ]; $configform = new Form(); foreach($configs as $key){ $el = ConfigHandler::GetConfig($key)->getAsFormElement(); // I don't need this, (Everything from this group will be on the root-level form). $el->set('group', null); $configform->addElement($el); } $authbackends = ConfigHandler::Get('/user/authdrivers'); if(!$authbackends){ $authbackendsenabled = []; } else{ $authbackendsenabled = explode('|', $authbackends); } $authbackends = []; $available = []; foreach(Core::GetComponents() as $c){ /** @var Component_2_1 $c */ $available = array_merge($available, $c->getUserAuthDrivers()); } foreach($authbackendsenabled as $k){ if(!isset($available[$k])){ continue; } $classname = $available[$k]; if(!class_exists($classname)){ continue; } try{ /** @var \Core\User\AuthDriverInterface $class */ $class = new $classname(); } catch(Exception $e){ continue; } $authbackends[] = [ 'name' => $k, 'class' => $classname, 'title' => $class->getAuthTitle(), 'enabled' => true, ]; unset($available[$k]); } foreach($available as $k => $classname){ if(!class_exists($classname)){ continue; } try{ /** @var \Core\User\AuthDriverInterface $class */ $class = new $classname(); } catch(Exception $e){ continue; } $authbackends[] = [ 'name' => $k, 'class' => $classname, 'title' => $class->getAuthTitle(), 'enabled' => false, ]; } if($request->isPost()){ $onEditSelected = (isset($_POST['onedit'])) ? implode('|', $_POST['onedit']) : ''; $onRegSelected = (isset($_POST['onregister'])) ? implode('|', $_POST['onregister']) : ''; $authSelected = (isset($_POST['authbackend'])) ? implode('|', $_POST['authbackend']) : ''; if($authSelected == ''){ \Core\set_message('At least one auth backend is required, re-enabling datastore.', 'info'); $authSelected = 'datastore'; } ConfigHandler::Set('/user/register/form_elements', $onRegSelected); ConfigHandler::Set('/user/edit/form_elements', $onEditSelected); ConfigHandler::Set('/user/authdrivers', $authSelected); // Handle the actual config options too! foreach($configs as $key){ ConfigHandler::Set($key, $_POST['config'][$key]); } \Core\set_message('Saved configuration options successfully', 'success'); \Core\reload(); } $view->mastertemplate = 'admin'; $view->title = 'User Options'; $view->assign('configform', $configform); $view->assign('auth_backends', $authbackends); $view->assign('on_register_elements', $onReg); $view->assign('on_edit_elements', $onEdits); }
/** * Administrative page for configuring the Captcha settings. */ public function admin() { $view = $this->getView(); $request = $this->getPageRequest(); // This is an admin-only page. if (!\Core\user()->checkAccess('g:admin')) { return View::ERROR_ACCESSDENIED; } // width, height // colors $presets = ['simple' => ['name' => 'I trust and like my visitors', 'alt' => 'Simple and easy', 'configs' => ['/captcha/minlength' => 4, '/captcha/maxlength' => 5, '/captcha/linethrough' => 0, '/captcha/yperiod' => 12, '/captcha/yamplitude' => 14, '/captcha/xperiod' => 11, '/captcha/xamplitude' => 2, '/captcha/maxrotation' => 4, '/captcha/blur' => false]], 'med' => ['name' => 'Meh...', 'alt' => 'Moderate level of difficulty', 'configs' => ['/captcha/minlength' => 5, '/captcha/maxlength' => 7, '/captcha/linethrough' => 1, '/captcha/yperiod' => 12, '/captcha/yamplitude' => 14, '/captcha/xperiod' => 11, '/captcha/xamplitude' => 2, '/captcha/maxrotation' => 8, '/captcha/blur' => true]], 'hard' => ['name' => 'All visitors deserve to be punished!', 'alt' => 'Hieroglyphics are easier', 'configs' => ['/captcha/minlength' => 6, '/captcha/maxlength' => 9, '/captcha/linethrough' => 4, '/captcha/yperiod' => 12, '/captcha/yamplitude' => 20, '/captcha/xperiod' => 11, '/captcha/xamplitude' => 6, '/captcha/maxrotation' => 12, '/captcha/blur' => true]]]; // See if there's a preset option selected. $current = null; foreach ($presets as $key => $preset) { // This will skim through each preset and if all the options are set to this preset, then it must be the current. foreach ($preset['configs'] as $k => $v) { if (ConfigHandler::Get($k) != $v) { continue 2; } } // Did it not continue? Must be the current preset. //$current = $preset; $current = $key; break; } // This page uses a traditional form post. if ($request->isPost()) { // See if there's a preset $postpreset = $request->getPost('preset'); if ($postpreset && $postpreset != $current && isset($presets[$postpreset])) { foreach ($presets[$postpreset]['configs'] as $k => $v) { ConfigHandler::Set($k, $v); } \Core\set_message('Switched to ' . $presets[$postpreset]['name'] . ' preset.', 'success'); } // And the blah post options. $postwidth = $request->getPost('width'); $postheight = $request->getPost('height'); $posttext = $request->getPost('formtext'); if ($postwidth <= 0) { $postwidth = 100; } if ($postwidth > 400) { $postwidth = 400; } if ($postheight <= 0) { $postheight = 100; } if ($postheight > 200) { $postheight = 200; } if (!$posttext) { $posttext = 'Are you a Human?'; } ConfigHandler::Set('/captcha/width', $postwidth); ConfigHandler::Set('/captcha/height', $postheight); ConfigHandler::Set('/captcha/formtext', $posttext); \Core\reload(); } // Build the form. This will be pretty simple :p $form = new Form(); $presetoptions = array(); if (!$current) { // Add the custom settings option. $presetoptions[''] = '-- Custom Settings --'; } foreach ($presets as $key => $preset) { $presetoptions[$key] = $preset['name'] . ' (' . $preset['alt'] . ')'; } $form->addElement('select', ['name' => 'preset', 'title' => 'Difficulty Level', 'options' => $presetoptions, 'value' => $current ? $current : '']); $form->addElement('text', ['name' => 'width', 'title' => 'Image Width', 'value' => ConfigHandler::Get('/captcha/width')]); $form->addElement('text', ['name' => 'height', 'title' => 'Image Height', 'value' => ConfigHandler::Get('/captcha/height')]); $form->addElement('text', ['name' => 'formtext', 'title' => 'Form Text', 'value' => ConfigHandler::Get('/captcha/formtext')]); // @todo Colors for foreground and background. $form->addElement('submit', ['name' => 'submit', 'value' => 'Save Settings']); $view->mastertemplate = 'admin'; $view->title = 'Captcha Tweaks'; $view->assign('form', $form); }