/** * The Index method of the VWP setting page. * * @param SettingsController $sender */ public function Controller_Index($sender) { // Set required permission. $sender->permission('Garden.Settings.Manage'); // Set up the configuration module. $configModule = new ConfigurationModule($sender); $configModule->initialize(array('VWP.Database.User' => array('LabelCode' => 'WordPress Database User', 'Control' => 'TextBox'), 'VWP.Database.Password' => array('LabelCode' => 'WordPress Database Password', 'Control' => 'TextBox'), 'VWP.Database.Name' => array('LabelCode' => 'WordPress Database Name', 'Control' => 'TextBox'), 'VWP.Database.Prefix' => array('LabelCode' => 'WordPress Database Prefix', 'Control' => 'TextBox'))); $sender->ConfigurationModule = $configModule; $sender->title(T('VWP Settings')); $sender->addSideMenu('/settings/vwp'); $sender->View = $sender->fetchViewLocation('vwp', 'settings', 'vwp'); $sender->render(); }
/** * @param SettingsController $sender * @param array $Args */ protected function settings_addEdit($sender, $Args) { $client_id = $sender->Request->Get('client_id'); Gdn::Locale()->SetTranslation('AuthenticationKey', 'Client ID'); Gdn::Locale()->SetTranslation('AssociationSecret', 'Secret'); Gdn::Locale()->SetTranslation('AuthenticateUrl', 'Authentication Url'); /* @var Gdn_Form $form */ $form = $sender->Form; $model = new Gdn_AuthenticationProviderModel(); $form->setModel($model); if ($form->authenticatedPostBack()) { if ($form->getFormValue('Generate') || $sender->Request->post('Generate')) { $form->setFormValue('AuthenticationKey', mt_rand()); $form->setFormValue('AssociationSecret', md5(mt_rand())); $sender->setFormSaved(FALSE); } else { $form->validateRule('AuthenticationKey', 'ValidateRequired'); $form->validateRule('AuthenticationKey', 'regex:`^[a-z0-9_-]+$`i', T('The client id must contain only letters, numbers and dashes.')); $form->validateRule('AssociationSecret', 'ValidateRequired'); $form->validateRule('AuthenticateUrl', 'ValidateRequired'); $form->setFormValue('AuthenticationSchemeAlias', 'jsconnect'); if ($form->save(['ID' => $client_id])) { $sender->RedirectUrl = url('/settings/jsconnect'); } } } else { if ($client_id) { $provider = self::getProvider($client_id); touchValue('Trusted', $provider, 1); } else { $provider = array(); } $form->setData($provider); } // Set up the form controls for editing the connection. $hashTypes = hash_algos(); $hashTypes = array_combine($hashTypes, $hashTypes); $controls = ['AuthenticationKey' => ['LabelCode' => 'Client ID', 'Description' => T('The client ID uniquely identifies the site.', 'The client ID uniquely identifies the site. You can generate a new ID with the button at the bottom of this page.')], 'AssociationSecret' => ['LabelCode' => 'Secret', 'Description' => T('The secret secures the sign in process.', 'The secret secures the sign in process. Do <b>NOT</b> give the secret out to anyone.')], 'Name' => ['LabelCode' => 'Site Name', 'Description' => T('Enter a short name for the site.', 'Enter a short name for the site. This is displayed on the signin buttons.')], 'AuthenticateUrl' => ['LabelCode' => 'Authentication URL', 'Description' => T('The location of the JSONP formatted authentication data.'), 'Options' => ['class' => 'InputBox BigInput']], 'SignInUrl' => ['LabelCode' => 'Sign In URL', 'Description' => T('The url that users use to sign in.') . ' ' . T('Use {target} to specify a redirect.'), 'Options' => ['class' => 'InputBox BigInput']], 'RegisterUrl' => ['LabelCode' => 'Registration URL', 'Description' => T('The url that users use to register for a new account.'), 'Options' => ['class' => 'InputBox BigInput']], 'SignOutUrl' => ['LabelCode' => 'Sign Out URL', 'Description' => T('The url that users use to sign out of your site.'), 'Options' => ['class' => 'InputBox BigInput']], 'Trusted' => ['Control' => 'checkbox', 'LabelCode' => 'This is trusted connection and can sync roles & permissions.'], 'IsDefault' => ['Control' => 'checkbox', 'LabelCode' => 'Make this connection your default signin method.'], 'Advanced' => ['Control' => 'callback', 'Callback' => function ($form) { return '<h2>' . T('Advanced') . '</h2>'; }], 'HashType' => ['Control' => 'dropdown', 'LabelCode' => 'Hash Algorithm', 'Items' => $hashTypes, 'Description' => T('Choose md5 if you\'re not sure what to choose.', "You can select a custom hash algorithm to sign your requests. The hash algorithm must also be used in your client library. Choose md5 if you're not sure what to choose."), 'Options' => ['Default' => 'md5']], 'TestMode' => ['Control' => 'checkbox', 'LabelCode' => 'This connection is in test-mode.']]; $sender->setData('_Controls', $controls); $sender->setData('Title', sprintf(T($client_id ? 'Edit %s' : 'Add %s'), T('Connection'))); // Throw a render event as this plugin so that handlers can call our methods. Gdn::pluginManager()->callEventHandlers($this, __CLASS__, 'addedit', 'render'); $sender->render('Settings_AddEdit', '', 'plugins/jsconnect'); }
/** * List all tags and allow searching * * @param SettingsController $Sender */ public function settingsController_tagging_create($Sender, $Search = null, $Type = null, $Page = null) { $Sender->title('Tagging'); $Sender->addSideMenu('settings/tagging'); $Sender->addJSFile('tagadmin.js', 'plugins/Tagging'); $SQL = Gdn::sql(); // Get all tag types $TagModel = TagModel::instance(); $TagTypes = $TagModel->getTagTypes(); $Sender->Form->Method = 'get'; $Sender->Form->InputPrefix = ''; list($Offset, $Limit) = offsetLimit($Page, 100); $Sender->setData('_Limit', $Limit); if ($Search) { $SQL->like('FullName', $Search, 'right'); } // This type doesn't actually exist, but it will represent the // blank types in the column. if (strtolower($Type) == 'tags') { $Type = ''; } if (!$Search) { if ($Type !== null) { if ($Type === 'null') { $Type = null; } $SQL->where('Type', $Type); } elseif ($Type == '') { $SQL->where('Type', ''); } } else { $Type = 'Search Results'; // This is made up, and exists so search results can be placed in // their own tab. $TagTypes[$Type] = array('key' => $Type); } $TagTypes = array_change_key_case($TagTypes, CASE_LOWER); // Store type for view $TagType = !empty($Type) ? $Type : 'Tags'; $Sender->setData('_TagType', $TagType); // Store tag types $Sender->setData('_TagTypes', $TagTypes); // Determine if new tags can be added for the current type. $CanAddTags = !empty($TagTypes[$Type]['addtag']) && $TagTypes[$Type]['addtag'] ? 1 : 0; $CanAddTags &= CheckPermission('Plugins.Tagging.Add'); $Sender->setData('_CanAddTags', $CanAddTags); $Data = $SQL->select('t.*')->from('Tag t')->orderBy('t.FullName', 'asc')->orderBy('t.CountDiscussions', 'desc')->limit($Limit, $Offset)->get()->resultArray(); $Sender->setData('Tags', $Data); if ($Search) { $SQL->like('Name', $Search, 'right'); } // Make sure search uses its own search type, so results appear // in their own tab. $Sender->Form->Action = url('/settings/tagging/?type=' . $TagType); // Search results pagination will mess up a bit, so don't provide a type // in the count. $RecordCountWhere = array('Type' => $Type); if ($Type == '') { $RecordCountWhere = array('Type' => ''); } if ($Search) { $RecordCountWhere = array(); } $Sender->setData('RecordCount', $SQL->getCount('Tag', $RecordCountWhere)); $Sender->render('tagging', '', 'plugins/Tagging'); }
/** * AgeGate settings page. * * @param SettingsController $sender */ public function settingsController_ageGate_create($sender) { $sender->permission('Garden.Settings.Manage'); $sender->setData('Title', T('Age Gate Settings')); $sender->addSideMenu(); if ($sender->Form->authenticatedPostBack()) { $minimumAge = $sender->Form->getValue('MinimumAge'); $addConfirmation = $sender->Form->getValue('AddConfirmation'); if (!is_numeric($minimumAge)) { $sender->Form->addError('Please enter a valid number.'); } if ($sender->Form->errorCount() == 0) { saveToConfig('Plugins.AgeGate.MinimumAge', $minimumAge); saveToConfig('Plugins.AgeGate.AddConfirmation', $addConfirmation); $sender->informMessage(T('Saved')); } } else { $sender->Form->setData(array('MinimumAge' => C('Plugins.AgeGate.MinimumAge'), 'AddConfirmation' => C('Plugins.AgeGate.AddConfirmation'))); } $sender->render($sender->fetchViewLocation('settings', '', 'plugins/AgeGate')); }
/** * Override the index of the dashboard's settings controller in the to render new statistics. * * @param SettingsController $sender Instance of the dashboard's settings controller. */ public function settingsController_home_create($sender) { $statsUrl = $this->AnalyticsServer; if (!stringBeginsWith($statsUrl, 'http:') && !stringBeginsWith($statsUrl, 'https:')) { $statsUrl = Gdn::request()->scheme() . "://{$statsUrl}"; } Gdn_Theme::section('DashboardHome'); $sender->setData('IsWidePage', true); // Tell the page where to find the Vanilla Analytics provider $sender->addDefinition('VanillaStatsUrl', $statsUrl); $sender->setData('VanillaStatsUrl', $statsUrl); // Load javascript & css, check permissions, and load side menu for this page. $sender->addJsFile('settings.js'); $sender->title(t('Dashboard')); $sender->RequiredAdminPermissions = ['Garden.Settings.View', 'Garden.Settings.Manage', 'Garden.Community.Manage']; $sender->fireEvent('DefineAdminPermissions'); $sender->permission($sender->RequiredAdminPermissions, '', false); $sender->setHighlightRoute('dashboard/settings'); if (!Gdn_Statistics::checkIsEnabled() && Gdn_Statistics::checkIsLocalhost()) { $sender->render('dashboardlocalhost', '', 'plugins/VanillaStats'); } else { $sender->addCssFile('picker.css', 'plugins/VanillaStats'); $sender->addCssFile('vendors/c3.min.css', 'plugins/VanillaStats'); $sender->addJsFile('vanillastats.js', 'plugins/VanillaStats'); $sender->addJsFile('picker.js', 'plugins/VanillaStats'); $sender->addJsFile('d3.min.js'); $sender->addJsFile('c3.min.js'); $sender->addDefinition('VanillaID', Gdn::installationID()); $sender->addDefinition('AuthToken', Gdn_Statistics::generateToken()); $sender->addDefinition('ExpandText', t('more')); $sender->addDefinition('CollapseText', t('less')); // Render the custom dashboard view $sender->render('dashboard', '', 'plugins/VanillaStats'); } }
/** * * * @param SettingsController $Sender * @param type $Args */ public function settingsController_disqus_create($Sender, $Args) { $Sender->permission('Garden.Settings.Manage'); if ($Sender->Form->authenticatedPostBack()) { $Model = new Gdn_AuthenticationProviderModel(); $Sender->Form->setFormValue(Gdn_AuthenticationProviderModel::COLUMN_ALIAS, 'disqus'); $Sender->Form->setFormValue(Gdn_AuthenticationProviderModel::COLUMN_NAME, 'Disqus'); $Sender->Form->setModel($Model); if ($Sender->Form->save(array('PK' => Gdn_AuthenticationProviderModel::COLUMN_ALIAS))) { $Sender->informMessage(t("Your settings have been saved.")); } } else { $Provider = (array) $this->provider(); $Sender->Form->setData($Provider); } $Sender->addSideMenu(); $Sender->setData('Title', sprintf(t('%s Settings'), 'Disqus')); $Sender->render('Settings', '', 'plugins/Disqus'); }
/** * Render the settings menu in the dashboard * * This function sets up and renders a settings page where the API * configuration can be changed. * * @since 0.1.0 * @access public * @param SettingsController $sender * @return void */ public function SettingsController_API_create($sender) { $sender->permission("Garden.Settings.Manage"); $form = $sender->Form; if ($form->authenticatedPostBack()) { $secret = c("API.Secret"); $regen = $form->buttonExists(t("API.Settings.Refresh.Label")); if ($regen) { $secret = APIAuth::generateUniqueID(); } $save = []; $save["API.Secret"] = $secret; if ($form->errorCount() == 0) { saveToConfig($save); if ($regen) { $icon = "<span class=\"InformSprite Refresh\"></span>"; $text = t("API.Settings.Refresh.Notification"); $class = "Dismissable HasSprite"; $sender->informMessage($icon . $text, $class); } } } else { $data = []; $data["Secret"] = c("API.Secret"); $form->setData($data); } $sender->addSideMenu(); $sender->setData("Title", t("API.Settings.Title")); $sender->render("API", "settings", "api"); }