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('/'); }
/** * * * @param bool $Enabled * @return array */ public function getAddons($Enabled = false) { $Addons = array(); // Get the core. self::_AddAddon(array('AddonKey' => 'vanilla', 'AddonType' => 'core', 'Version' => APPLICATION_VERSION, 'Folder' => '/'), $Addons); // Get a list of all of the applications. $ApplicationManager = new Gdn_ApplicationManager(); if ($Enabled) { $Applications = $ApplicationManager->AvailableApplications(); } else { $Applications = $ApplicationManager->EnabledApplications(); } foreach ($Applications as $Key => $Info) { // Exclude core applications. if (in_array(strtolower($Key), array('conversations', 'dashboard', 'skeleton', 'vanilla'))) { continue; } $Addon = array('AddonKey' => $Key, 'AddonType' => 'application', 'Version' => val('Version', $Info, '0.0'), 'Folder' => '/applications/' . GetValue('Folder', $Info, strtolower($Key))); self::_AddAddon($Addon, $Addons); } // Get a list of all of the plugins. $PluginManager = Gdn::pluginManager(); if ($Enabled) { $Plugins = $PluginManager->EnabledPlugins(); } else { $Plugins = $PluginManager->AvailablePlugins(); } foreach ($Plugins as $Key => $Info) { // Exclude core plugins. if (in_array(strtolower($Key), array())) { continue; } $Addon = array('AddonKey' => $Key, 'AddonType' => 'plugin', 'Version' => val('Version', $Info, '0.0'), 'Folder' => '/applications/' . GetValue('Folder', $Info, $Key)); self::_AddAddon($Addon, $Addons); } // Get a list of all the themes. $ThemeManager = new Gdn_ThemeManager(); if ($Enabled) { $Themes = $ThemeManager->EnabledThemeInfo(true); } else { $Themes = $ThemeManager->AvailableThemes(); } foreach ($Themes as $Key => $Info) { // Exclude core themes. if (in_array(strtolower($Key), array('default'))) { continue; } $Addon = array('AddonKey' => $Key, 'AddonType' => 'theme', 'Version' => val('Version', $Info, '0.0'), 'Folder' => '/themes/' . GetValue('Folder', $Info, $Key)); self::_AddAddon($Addon, $Addons); } // Get a list of all locales. $LocaleModel = new LocaleModel(); if ($Enabled) { $Locales = $LocaleModel->EnabledLocalePacks(true); } else { $Locales = $LocaleModel->AvailableLocalePacks(); } foreach ($Locales as $Key => $Info) { // Exclude core themes. if (in_array(strtolower($Key), array('skeleton'))) { continue; } $Addon = array('AddonKey' => $Key, 'AddonType' => 'locale', 'Version' => val('Version', $Info, '0.0'), 'Folder' => '/locales/' . GetValue('Folder', $Info, $Key)); self::_AddAddon($Addon, $Addons); } return $Addons; }
/** * 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(); }
/** * Manage options for a theme. * * @since 2.0.0 * @access public * @todo Why is this in a giant try/catch block? */ public function themeOptions() { $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->fireEvent['AfterSaveThemeOptions']; $this->informMessage(t("Your changes have been saved.")); } $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 = val('Default', $Options, ''); $Value = c("ThemeOption.{$Key}", '#DEFAULT#'); if ($Value === '#DEFAULT#') { $Value = $Default; } $this->Form->setValue($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(); }
/** * Test to see if a plugin throws fatal errors. */ public function TestPlugin($PluginName, &$Validation, $Setup = FALSE) { // Make sure that the plugin's requirements are met // Required Plugins $AvailablePlugins = $this->AvailablePlugins(); $RequiredPlugins = ArrayValue('RequiredPlugins', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredPlugins, $this->EnabledPlugins, 'plugin'); // Required Themes $ThemeManager = new Gdn_ThemeManager(); $EnabledThemes = $ThemeManager->EnabledThemeInfo(TRUE); $RequiredThemes = ArrayValue('RequiredTheme', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredThemes, $EnabledThemes, 'theme'); // Required Applications $ApplicationManager = new Gdn_ApplicationManager(); $EnabledApplications = $ApplicationManager->EnabledApplications(); $RequiredApplications = ArrayValue('RequiredApplications', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredApplications, $EnabledApplications, 'application'); // Include the plugin, instantiate it, and call its setup method $PluginInfo = ArrayValue($PluginName, $AvailablePlugins, FALSE); $PluginClassName = ArrayValue('ClassName', $PluginInfo, FALSE); $PluginFolder = ArrayValue('Folder', $PluginInfo, FALSE); if ($PluginFolder == '') { throw new Exception(T('The plugin folder was not properly defined.')); } $this->_PluginHook($PluginName, self::ACTION_ENABLE, $Setup); // If setup succeeded, register any specified permissions $PermissionName = ArrayValue('RegisterPermissions', $PluginInfo, FALSE); if ($PermissionName != FALSE) { $PermissionModel = Gdn::PermissionModel(); $PermissionModel->Define($PermissionName); } return TRUE; }
public function EnablePlugin($PluginName, $Validation, $Setup = FALSE) { // 1. Make sure that the plugin's requirements are met // Required Plugins $AvailablePlugins = $this->AvailablePlugins(); $RequiredPlugins = ArrayValue('RequiredPlugins', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredPlugins, $this->EnabledPlugins, 'plugin'); // Required Themes $ThemeManager = new Gdn_ThemeManager(); $EnabledThemes = $ThemeManager->EnabledThemeInfo(); $RequiredThemes = ArrayValue('RequiredTheme', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredThemes, $EnabledThemes, 'theme'); // Required Applications $ApplicationManager = new Gdn_ApplicationManager(); $EnabledApplications = $ApplicationManager->EnabledApplications(); $RequiredApplications = ArrayValue('RequiredApplications', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredApplications, $EnabledApplications, 'application'); // 2. Include the plugin, instantiate it, and call its setup method $PluginInfo = ArrayValue($PluginName, $AvailablePlugins, FALSE); $PluginFolder = ArrayValue('Folder', $PluginInfo, FALSE); if ($PluginFolder == '') { throw new Exception(Gdn::Translate('The plugin folder was not properly defined.')); } $this->_PluginHook($PluginName, self::ACTION_ENABLE, $Setup); // 3. If setup succeeded, register any specified permissions $PermissionName = ArrayValue('RegisterPermissions', $PluginInfo, FALSE); if ($PermissionName != FALSE) { $PermissionModel = Gdn::PermissionModel(); $PermissionModel->Define($PermissionName); } if (is_object($Validation) && count($Validation->Results()) > 0) { return FALSE; } // 4. If everything succeeded, add the plugin to the // $EnabledPlugins array in conf/plugins.php // $EnabledPlugins['PluginClassName'] = 'Plugin Folder Name'; SaveToConfig('EnabledPlugins' . '.' . $PluginName, $PluginFolder); $ApplicationManager = new Gdn_ApplicationManager(); $Locale = Gdn::Locale(); $Locale->Set($Locale->Current(), $ApplicationManager->EnabledApplicationFolders(), $this->EnabledPluginFolders(), TRUE); return TRUE; }
public function EnablePlugin($PluginName, $Validation, $Setup = FALSE) { // 1. Make sure that the plugin's requirements are met // Required Plugins $AvailablePlugins = $this->AvailablePlugins(); $RequiredPlugins = ArrayValue('RequiredPlugins', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredPlugins, $this->EnabledPlugins, 'plugin'); // Required Themes $ThemeManager = new Gdn_ThemeManager(); $EnabledThemes = $ThemeManager->EnabledThemeInfo(); $RequiredThemes = ArrayValue('RequiredTheme', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredThemes, $EnabledThemes, 'theme'); // Required Applications $ApplicationManager = new Gdn_ApplicationManager(); $EnabledApplications = $ApplicationManager->EnabledApplications(); $RequiredApplications = ArrayValue('RequiredApplications', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredApplications, $EnabledApplications, 'application'); // 2. Include the plugin, instantiate it, and call it's setup method $PluginInfo = ArrayValue($PluginName, $AvailablePlugins, FALSE); $PluginFolder = ArrayValue('Folder', $PluginInfo, FALSE); if ($PluginFolder == '') { throw new Exception(Gdn::Translate('The plugin folder was not properly defined.')); } $PluginClassName = ArrayValue('ClassName', $PluginInfo, FALSE); if ($PluginFolder !== FALSE && $PluginClassName !== FALSE && class_exists($PluginClassName) === FALSE) { $this->IncludePlugins(array($PluginName => $PluginFolder)); if (class_exists($PluginClassName)) { $Plugin = new $PluginClassName(); $Plugin->Setup(); } } elseif (class_exists($PluginClassName, FALSE) !== FALSE && $Setup === TRUE) { $Plugin = new $PluginClassName(); $Plugin->Setup(); } // 3. If setup succeeded, register any specified permissions $PermissionName = ArrayValue('RegisterPermissions', $PluginInfo, FALSE); if ($PermissionName != FALSE) { $PermissionModel = Gdn::PermissionModel(); $PermissionModel->Define($PermissionName); } if (is_object($Validation) && count($Validation->Results()) > 0) { return FALSE; } // 4. If everything succeeded, add the plugin to the // $EnabledPlugins array in conf/plugins.php // $EnabledPlugins['PluginClassName'] = 'Plugin Folder Name'; $Config = Gdn::Factory(Gdn::AliasConfig); $Config->Load(PATH_CONF . DS . 'config.php', 'Save'); $Config->Set('EnabledPlugins' . '.' . $PluginName, $PluginFolder); $Config->Save(); $ApplicationManager = new Gdn_ApplicationManager(); $Locale = Gdn::Locale(); $Locale->Set($Locale->Current(), $ApplicationManager->EnabledApplicationFolders(), $this->EnabledPluginFolders(), TRUE); return TRUE; }
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(); }