public function PluginController_Embed_Create($Sender) { $Sender->Permission('Garden.Settings.Manage'); $Sender->Title('Embed Vanilla'); $Sender->AddCssFile($this->GetResource('design/settings.css', FALSE, FALSE)); $Sender->AddSideMenu('plugin/embed'); $Sender->Form = new Gdn_Form(); $ThemeManager = new Gdn_ThemeManager(); $Sender->SetData('AvailableThemes', $ThemeManager->AvailableThemes()); $Sender->SetData('EnabledThemeFolder', $ThemeManager->EnabledTheme()); $Sender->SetData('EnabledTheme', $ThemeManager->EnabledThemeInfo()); $Sender->SetData('EnabledThemeName', $Sender->Data('EnabledTheme.Name', $Sender->Data('EnabledTheme.Folder'))); $Validation = new Gdn_Validation(); $ConfigurationModel = new Gdn_ConfigurationModel($Validation); $ConfigurationModel->SetField(array('Plugins.EmbedVanilla.RemoteUrl', 'Plugins.EmbedVanilla.ForceRemoteUrl', 'Plugins.EmbedVanilla.EmbedDashboard')); $Sender->Form->SetModel($ConfigurationModel); if ($Sender->Form->AuthenticatedPostBack() === FALSE) { // Apply the config settings to the form. $Sender->Form->SetData($ConfigurationModel->Data); } else { // Define some validation rules for the fields being saved $ConfigurationModel->Validation->ApplyRule('Plugins.EmbedVanilla.RemoteUrl', 'WebAddress', 'The remote url you specified could not be validated as a functional url to redirect to.'); if ($Sender->Form->Save() !== FALSE) $Sender->InformMessage(T("Your settings have been saved.")); } // Handle changing the theme to the recommended one $ThemeFolder = GetValue(0, $Sender->RequestArgs); $TransientKey = GetValue(1, $Sender->RequestArgs); $Session = Gdn::Session(); if ($Session->ValidateTransientKey($TransientKey) && $ThemeFolder != '') { try { foreach ($Sender->Data('AvailableThemes') as $ThemeName => $ThemeInfo) { if ($ThemeInfo['Folder'] == $ThemeFolder) $ThemeManager->EnableTheme($ThemeName); } } catch (Exception $Ex) { $Sender->Form->AddError($Ex); } if ($Sender->Form->ErrorCount() == 0) Redirect('/plugin/embed'); } $Sender->Render(PATH_PLUGINS.'/embedvanilla/views/settings.php'); }
public function PreviewTheme($ThemeFolder = '') { $this->Permission('Garden.Themes.Manage'); $ThemeManager = new Gdn_ThemeManager(); $this->AvailableThemes = $ThemeManager->AvailableThemes(); $PreviewThemeName = ''; $PreviewThemeFolder = $ThemeFolder; foreach ($this->AvailableThemes as $ThemeName => $ThemeInfo) { if ($ThemeInfo['Folder'] == $ThemeFolder) { $PreviewThemeName = $ThemeName; } } // If we failed to get the requested theme, default back to the one currently enabled if ($PreviewThemeName == '') { $this->ThemeName = $ThemeManager->EnabledTheme(); foreach ($this->AvailableThemes as $ThemeName => $ThemeInfo) { if ($ThemeName == $PreviewThemeName) { $PreviewThemeFolder = $ThemeInfo['Folder']; } } } Gdn::Session()->SetPreference(array('PreviewThemeName' => $PreviewThemeName, 'PreviewThemeFolder' => $PreviewThemeFolder)); Redirect('/'); }
/** * Manage options for a theme. * * @since 2.0.0 * @access public * @param string $Style Unique ID. * @todo Why is this in a giant try/catch block? */ public function ThemeOptions($Style = NULL) { $this->Permission('Garden.Settings.Manage'); try { $this->AddJsFile('addons.js'); $this->AddSideMenu('dashboard/settings/themeoptions'); $ThemeManager = new Gdn_ThemeManager(); $this->SetData('ThemeInfo', $ThemeManager->EnabledThemeInfo()); if ($this->Form->AuthenticatedPostBack()) { // Save the styles to the config. $StyleKey = $this->Form->GetFormValue('StyleKey'); $ConfigSaveData = array('Garden.ThemeOptions.Styles.Key' => $StyleKey, 'Garden.ThemeOptions.Styles.Value' => $this->Data("ThemeInfo.Options.Styles.{$StyleKey}.Basename")); // Save the text to the locale. $Translations = array(); foreach ($this->Data('ThemeInfo.Options.Text', array()) as $Key => $Default) { $Value = $this->Form->GetFormValue($this->Form->EscapeString('Text_' . $Key)); $ConfigSaveData["ThemeOption.{$Key}"] = $Value; //$this->Form->SetFormValue('Text_'.$Key, $Value); } SaveToConfig($ConfigSaveData); $this->InformMessage(T("Your changes have been saved.")); } elseif ($Style) { SaveToConfig(array('Garden.ThemeOptions.Styles.Key' => $Style, 'Garden.ThemeOptions.Styles.Value' => $this->Data("ThemeInfo.Options.Styles.{$Style}.Basename"))); } $this->SetData('ThemeOptions', C('Garden.ThemeOptions')); $StyleKey = $this->Data('ThemeOptions.Styles.Key'); if (!$this->Form->IsPostBack()) { foreach ($this->Data('ThemeInfo.Options.Text', array()) as $Key => $Options) { $Default = GetValue('Default', $Options, ''); $Value = C("ThemeOption.{$Key}", '#DEFAULT#'); if ($Value === '#DEFAULT#') { $Value = $Default; } $this->Form->SetFormValue($this->Form->EscapeString('Text_' . $Key), $Value); } } $this->SetData('ThemeFolder', $ThemeManager->EnabledTheme()); $this->Title(T('Theme Options')); $this->Form->AddHidden('StyleKey', $StyleKey); } catch (Exception $Ex) { $this->Form->AddError($Ex); } $this->Render(); }
public function PreviewTheme($ThemeFolder = '') { $this->Permission('Garden.Themes.Manage'); $ThemeManager = new Gdn_ThemeManager(); $this->AvailableThemes = $ThemeManager->AvailableThemes(); $PreviewThemeName = ''; $PreviewThemeFolder = $ThemeFolder; foreach ($this->AvailableThemes as $ThemeName => $ThemeInfo) { if ($ThemeInfo['Folder'] == $ThemeFolder) { $PreviewThemeName = $ThemeName; } } // If we failed to get the requested theme, default back to the one currently enabled if ($PreviewThemeName == '') { $this->ThemeName = $ThemeManager->EnabledTheme(); foreach ($this->AvailableThemes as $ThemeName => $ThemeInfo) { if ($ThemeName == $PreviewThemeName) { $PreviewThemeFolder = $ThemeInfo['Folder']; } } } // Check for errors $Session = Gdn::Session(); $Test = ProxyRequest(Url('/dashboard/settings/testaddon/Theme/' . $ThemeName . '/' . $Session->TransientKey() . '?DeliveryType=JSON', TRUE)); if ($Test != 'Success') { $this->Form->AddError(sprintf(T('The theme could not be previewed because it generated a fatal error: <pre>%s</pre>'), strip_tags($Test))); $this->View = 'themes'; $this->Themes(); } else { $Session->SetPreference(array('PreviewThemeName' => $PreviewThemeName, 'PreviewThemeFolder' => $PreviewThemeFolder)); Redirect('/'); } }
public function PreviewTheme($ThemeFolder = '') { $this->Title(Translate('Theme Preview')); // Clear out all css & js and use the "empty" master view $this->MasterView = 'empty'; $this->_CssFiles = array(); $this->Head->ClearScripts(); // Add jquery, custom css & js $this->AddCssFile('previewtheme.css'); $this->AddJsFile('js/library/jquery.js'); $this->AddJsFile('previewtheme.js'); $this->Permission('Garden.Themes.Manage'); $ThemeManager = new Gdn_ThemeManager(); $this->AvailableThemes = $ThemeManager->AvailableThemes(); $this->ThemeName = ''; $this->ThemeFolder = $ThemeFolder; foreach ($this->AvailableThemes as $ThemeName => $ThemeInfo) { if ($ThemeInfo['Folder'] == $ThemeFolder) { $this->ThemeName = $ThemeName; } } // If we failed to get the requested theme, default back to the one currently enabled if ($this->ThemeName == '') { $this->ThemeName = $ThemeManager->EnabledTheme(); foreach ($this->AvailableThemes as $ThemeName => $ThemeInfo) { if ($ThemeName == $this->ThemeName) { $this->ThemeFolder = $ThemeInfo['Folder']; } } } $Session = Gdn::Session(); $UserModel = Gdn::UserModel(); $UserModel->SavePreference($Session->UserID, 'PreviewTheme', $this->ThemeFolder); $this->Render(); }