/**
  * Manage list of plugins.
  *
  * @since 2.0.0
  * @access public
  * @param string $Filter 'enabled', 'disabled', or 'all' (default)
  * @param string $PluginName Unique ID of plugin to be modified.
  * @param string $TransientKey Security token.
  */
 public function plugins($Filter = '', $PluginName = '', $TransientKey = '')
 {
     $this->permission('Garden.Settings.Manage');
     // Page setup
     $this->addJsFile('addons.js');
     $this->title(t('Plugins'));
     $this->addSideMenu('dashboard/settings/plugins');
     // Validate and set properties
     $Session = Gdn::session();
     if ($PluginName && !$Session->validateTransientKey($TransientKey)) {
         $PluginName = '';
     }
     if (!in_array($Filter, array('enabled', 'disabled'))) {
         $Filter = 'all';
     }
     $this->Filter = $Filter;
     // Retrieve all available plugins from the plugins directory
     $this->EnabledPlugins = Gdn::pluginManager()->enabledPlugins();
     self::sortAddons($this->EnabledPlugins);
     $this->AvailablePlugins = Gdn::pluginManager()->availablePlugins();
     self::sortAddons($this->AvailablePlugins);
     if ($PluginName != '') {
         try {
             $this->EventArguments['PluginName'] = $PluginName;
             if (array_key_exists($PluginName, $this->EnabledPlugins) === true) {
                 Gdn::pluginManager()->disablePlugin($PluginName);
                 Gdn_LibraryMap::clearCache();
                 $this->fireEvent('AfterDisablePlugin');
             } else {
                 $Validation = new Gdn_Validation();
                 if (!Gdn::pluginManager()->enablePlugin($PluginName, $Validation)) {
                     $this->Form->setValidationResults($Validation->results());
                 } else {
                     Gdn_LibraryMap::ClearCache();
                 }
                 $this->EventArguments['Validation'] = $Validation;
                 $this->fireEvent('AfterEnablePlugin');
             }
         } catch (Exception $e) {
             $this->Form->addError($e);
         }
         if ($this->Form->errorCount() == 0) {
             redirect('/settings/plugins/' . $this->Filter);
         }
     }
     $this->render();
 }
 /**
  * Manage list of plugins.
  *
  * @since 2.0.0
  * @access public
  * @param string $Filter 'enabled', 'disabled', or 'all' (default)
  * @param string $PluginName Unique ID of plugin to be modified.
  * @param string $TransientKey Security token.
  */
 public function Plugins($Filter = '', $PluginName = '', $TransientKey = '')
 {
     $this->Permission('Garden.Settings.Manage');
     // Page setup
     $this->AddJsFile('addons.js');
     $this->Title(T('Plugins'));
     $this->AddSideMenu('dashboard/settings/plugins');
     // Validate and set properties
     $Session = Gdn::Session();
     $PluginName = $Session->ValidateTransientKey($TransientKey) ? $PluginName : '';
     if (!in_array($Filter, array('enabled', 'disabled'))) {
         $Filter = 'all';
     }
     $this->Filter = $Filter;
     // Retrieve all available plugins from the plugins directory
     $this->EnabledPlugins = Gdn::PluginManager()->EnabledPlugins();
     self::SortAddons($this->EnabledPlugins);
     $this->AvailablePlugins = Gdn::PluginManager()->AvailablePlugins();
     self::SortAddons($this->AvailablePlugins);
     // Loop through all of the available plugins and mark them if they have an update available
     // Retrieve the list of plugins 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->AvailablePlugins as $Plugin => $Info) {
                 $CurrentName = ArrayValue('Name', $Info, $Plugin);
                 if ($CurrentName == $Name && $Type == 'Plugin') {
                     $Info['NewVersion'] = $NewVersion;
                     $this->AvailablePlugins[$Plugin] = $Info;
                 }
             }
         }
     }
     if ($PluginName != '') {
         try {
             $this->EventArguments['PluginName'] = $PluginName;
             if (array_key_exists($PluginName, $this->EnabledPlugins) === TRUE) {
                 Gdn::PluginManager()->DisablePlugin($PluginName);
                 Gdn_LibraryMap::ClearCache();
                 $this->FireEvent('AfterDisablePlugin');
             } else {
                 $Validation = new Gdn_Validation();
                 if (!Gdn::PluginManager()->EnablePlugin($PluginName, $Validation)) {
                     $this->Form->SetValidationResults($Validation->Results());
                 } else {
                     Gdn_LibraryMap::ClearCache();
                 }
                 $this->EventArguments['Validation'] = $Validation;
                 $this->FireEvent('AfterEnablePlugin');
             }
         } catch (Exception $e) {
             $this->Form->AddError($e);
         }
         if ($this->Form->ErrorCount() == 0) {
             Redirect('/settings/plugins/' . $this->Filter);
         }
     }
     $this->Render();
 }
Пример #3
0
 public function enablePlugin($pluginName, $filter = 'all')
 {
     if (!Gdn::request()->isAuthenticatedPostBack(true)) {
         throw new Exception('Requires POST', 405);
     }
     $this->permission('Garden.Settings.Manage');
     $action = 'none';
     if ($filter == 'disabled') {
         $action = 'SlideUp';
     }
     $addon = Gdn::addonManager()->lookupAddon($pluginName);
     try {
         $validation = new Gdn_Validation();
         if (!Gdn::pluginManager()->enablePlugin($pluginName, $validation)) {
             $this->Form->setValidationResults($validation->results());
         } else {
             Gdn_LibraryMap::ClearCache();
             $this->informMessage(sprintf(t('%s Enabled.'), val('name', $addon->getInfo(), t('Plugin'))));
         }
         $this->EventArguments['PluginName'] = $pluginName;
         $this->EventArguments['Validation'] = $validation;
         $this->fireEvent('AfterEnablePlugin');
     } catch (Exception $e) {
         $this->Form->addError($e);
     }
     $this->handleAddonToggle($pluginName, $addon->getInfo(), 'plugins', true, $filter, $action);
 }