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->StatusMessage = 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();
 }
Esempio n. 3
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();
 }
 /**
  * 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();
 }
Esempio n. 5
0
 /**
  * Theme management screen.
  */
 public function Themes($ThemeFolder = '', $TransientKey = '')
 {
     $this->Permission('Garden.Themes.Manage');
     $this->AddSideMenu('garden/settings/themes');
     $Session = Gdn::Session();
     $ThemeManager = new Gdn_ThemeManager();
     $this->AvailableThemes = $ThemeManager->AvailableThemes();
     $this->EnabledTheme = $ThemeManager->EnabledTheme();
     if ($Session->ValidateTransientKey($TransientKey) && $ThemeFolder != '') {
         try {
             foreach ($this->AvailableThemes as $ThemeName => $ThemeInfo) {
                 if ($ThemeInfo['Folder'] == $ThemeFolder) {
                     $UserModel = Gdn::UserModel();
                     $UserModel->SavePreference($Session->UserID, '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();
 }