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');
   }
 /**
  * Theme management screen.
  */
 public function Themes($ThemeFolder = '', $TransientKey = '')
 {
     $this->AddJsFile('addons.js');
     $this->SetData('Title', T('Themes'));
     $this->Permission('Garden.Themes.Manage');
     $this->AddSideMenu('dashboard/settings/themes');
     $Session = Gdn::Session();
     $ThemeManager = new Gdn_ThemeManager();
     $AvailableThemes = $ThemeManager->AvailableThemes();
     $this->SetData('EnabledThemeFolder', $ThemeManager->EnabledTheme());
     $this->SetData('EnabledTheme', $ThemeManager->EnabledThemeInfo());
     $this->SetData('EnabledThemeName', $this->Data('EnabledTheme.Name', $this->Data('EnabledTheme.Folder')));
     // Loop through all of the available themes and mark them if they have an update available
     // Retrieve the list of themes that require updates from the config file
     $RequiredUpdates = Gdn_Format::Unserialize(Gdn::Config('Garden.RequiredUpdates', ''));
     if (is_array($RequiredUpdates)) {
         foreach ($RequiredUpdates as $UpdateInfo) {
             if (is_object($UpdateInfo)) {
                 $UpdateInfo = Gdn_Format::ObjectAsArray($UpdateInfo);
             }
             $NewVersion = ArrayValue('Version', $UpdateInfo, '');
             $Name = ArrayValue('Name', $UpdateInfo, '');
             $Type = ArrayValue('Type', $UpdateInfo, '');
             foreach ($AvailableThemes as $Theme => $Info) {
                 $CurrentName = ArrayValue('Name', $Info, $Theme);
                 if ($CurrentName == $Name && $Type == 'Theme') {
                     $Info['NewVersion'] = $NewVersion;
                     $AvailableThemes[$Theme] = $Info;
                 }
             }
         }
     }
     $this->SetData('AvailableThemes', $AvailableThemes);
     if ($Session->ValidateTransientKey($TransientKey) && $ThemeFolder != '') {
         try {
             foreach ($this->Data('AvailableThemes') as $ThemeName => $ThemeInfo) {
                 if ($ThemeInfo['Folder'] == $ThemeFolder) {
                     $Session->SetPreference(array('PreviewThemeName' => '', 'PreviewThemeFolder' => ''));
                     // Clear out the preview
                     $ThemeManager->EnableTheme($ThemeName);
                     $this->EventArguments['ThemeName'] = $ThemeName;
                     $this->EventArguments['ThemeInfo'] = $ThemeInfo;
                     $this->FireEvent('AfterEnableTheme');
                 }
             }
         } catch (Exception $Ex) {
             $this->Form->AddError($Ex);
         }
         if ($this->Form->ErrorCount() == 0) {
             Redirect('/settings/themes');
         }
     }
     $this->Render();
 }
Ejemplo n.º 3
0
 /**
  *
  *
  * @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();
 }
Ejemplo n.º 5
0
 /**
  * Theme management screen.
  */
 public function Themes($ThemeFolder = '', $TransientKey = '')
 {
     $this->Title(Translate('Themes'));
     $this->Permission('Garden.Themes.Manage');
     $this->AddSideMenu('garden/settings/themes');
     $Session = Gdn::Session();
     $ThemeManager = new Gdn_ThemeManager();
     $this->AvailableThemes = $ThemeManager->AvailableThemes();
     $this->EnabledThemeFolder = $ThemeManager->EnabledTheme();
     $this->EnabledTheme = $ThemeManager->EnabledThemeInfo();
     $Name = array_keys($this->EnabledTheme);
     $Name = ArrayValue(0, $Name, 'undefined');
     $this->EnabledTheme = ArrayValue($Name, $this->EnabledTheme);
     $this->EnabledThemeName = ArrayValue('Name', $this->EnabledTheme, $Name);
     // Loop through all of the available themes and mark them if they have an update available
     // Retrieve the list of themes that require updates from the config file
     $RequiredUpdates = Format::Unserialize(Gdn::Config('Garden.RequiredUpdates', ''));
     if (is_array($RequiredUpdates)) {
         foreach ($RequiredUpdates as $UpdateInfo) {
             if (is_object($UpdateInfo)) {
                 $UpdateInfo = Format::ObjectAsArray($UpdateInfo);
             }
             $NewVersion = ArrayValue('Version', $UpdateInfo, '');
             $Name = ArrayValue('Name', $UpdateInfo, '');
             $Type = ArrayValue('Type', $UpdateInfo, '');
             foreach ($this->AvailableThemes as $Theme => $Info) {
                 $CurrentName = ArrayValue('Name', $Info, $Theme);
                 if ($CurrentName == $Name && $Type == 'Theme') {
                     $Info['NewVersion'] = $NewVersion;
                     $this->AvailableThemes[$Theme] = $Info;
                 }
             }
         }
     }
     if ($Session->ValidateTransientKey($TransientKey) && $ThemeFolder != '') {
         try {
             foreach ($this->AvailableThemes as $ThemeName => $ThemeInfo) {
                 if ($ThemeInfo['Folder'] == $ThemeFolder) {
                     $Session->SetPreference('PreviewTheme', '');
                     // Clear out the preview
                     $ThemeManager->EnableTheme($ThemeName);
                 }
             }
         } catch (Exception $e) {
             $this->Form->AddError(strip_tags($e->getMessage()));
         }
         if ($this->Form->ErrorCount() == 0) {
             Redirect('/settings/themes');
         }
     }
     $this->Render();
 }
Ejemplo n.º 6
0
 /**
  * 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;
 }
Ejemplo n.º 7
0
 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;
 }
Ejemplo n.º 8
0
 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;
 }
Ejemplo n.º 9
0
 /**
  * Theme management screen.
  */
 public function Themes($ThemeFolder = '', $TransientKey = '')
 {
     $this->Title(T('Themes'));
     $this->Permission('Garden.Themes.Manage');
     $this->AddSideMenu('dashboard/settings/themes');
     $Session = Gdn::Session();
     $ThemeManager = new Gdn_ThemeManager();
     $this->AvailableThemes = $ThemeManager->AvailableThemes();
     $this->EnabledThemeFolder = $ThemeManager->EnabledTheme();
     $this->EnabledTheme = $ThemeManager->EnabledThemeInfo();
     $Name = array_keys($this->EnabledTheme);
     $Name = ArrayValue(0, $Name, 'undefined');
     $this->EnabledTheme = ArrayValue($Name, $this->EnabledTheme);
     $this->EnabledThemeName = ArrayValue('Name', $this->EnabledTheme, $Name);
     // Loop through all of the available themes and mark them if they have an update available
     // Retrieve the list of themes that require updates from the config file
     $RequiredUpdates = Gdn_Format::Unserialize(Gdn::Config('Garden.RequiredUpdates', ''));
     if (is_array($RequiredUpdates)) {
         foreach ($RequiredUpdates as $UpdateInfo) {
             if (is_object($UpdateInfo)) {
                 $UpdateInfo = Gdn_Format::ObjectAsArray($UpdateInfo);
             }
             $NewVersion = ArrayValue('Version', $UpdateInfo, '');
             $Name = ArrayValue('Name', $UpdateInfo, '');
             $Type = ArrayValue('Type', $UpdateInfo, '');
             foreach ($this->AvailableThemes as $Theme => $Info) {
                 $CurrentName = ArrayValue('Name', $Info, $Theme);
                 if ($CurrentName == $Name && $Type == 'Theme') {
                     $Info['NewVersion'] = $NewVersion;
                     $this->AvailableThemes[$Theme] = $Info;
                 }
             }
         }
     }
     if ($Session->ValidateTransientKey($TransientKey) && $ThemeFolder != '') {
         try {
             foreach ($this->AvailableThemes as $ThemeName => $ThemeInfo) {
                 if ($ThemeInfo['Folder'] == $ThemeFolder) {
                     $Session->SetPreference('PreviewTheme', '');
                     // Clear out the preview
                     $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 enabled because it generated a fatal error: <pre>%s</pre>'), strip_tags($Test)));
                     } else {
                         $ThemeManager->EnableTheme($ThemeName);
                     }
                 }
             }
         } catch (Exception $e) {
             $this->Form->AddError(strip_tags($e->getMessage()));
         }
         if ($this->Form->ErrorCount() == 0) {
             Redirect('/settings/themes');
         }
     }
     $this->Render();
 }