public function execute($request) { $this->form = new sfForm(); if (!$this->context->user->hasCredential('administrator')) { QubitAcl::forwardUnauthorized(); } $criteria = new Criteria(); $criteria->add(QubitSetting::NAME, 'plugins'); if (1 == count($query = QubitSetting::get($criteria))) { $setting = $query[0]; $this->form->setDefault('enabled', unserialize($setting->__get('value', array('sourceCulture' => true)))); } $configuration = ProjectConfiguration::getActive(); $pluginPaths = $configuration->getAllPluginPaths(); foreach (sfPluginAdminPluginConfiguration::$pluginNames as $name) { unset($pluginPaths[$name]); } $this->plugins = array(); foreach ($pluginPaths as $name => $path) { $className = $name . 'Configuration'; if (sfConfig::get('sf_plugins_dir') == substr($path, 0, strlen(sfConfig::get('sf_plugins_dir'))) && is_readable($classPath = $path . '/config/' . $className . '.class.php')) { $this->installPluginAssets($name, $path); require_once $classPath; $class = new $className($configuration); // Build a list of themes if (isset($class::$summary) && 1 === preg_match('/theme/i', $class::$summary)) { $this->plugins[$name] = $class; } } } if ($request->isMethod('post')) { $this->form->setValidators(array('enabled' => new sfValidatorChoice(array('choices' => array_keys($this->plugins), 'empty_value' => array(), 'multiple' => true)))); $this->form->bind($request->getPostParameters()); if ($this->form->isValid()) { if (1 != count($query)) { $setting = new QubitSetting(); $setting->name = 'plugins'; } $settings = unserialize($setting->__get('value', array('sourceCulture' => true))); foreach (array_keys($this->plugins) as $item) { if (in_array($item, (array) $this->form->getValue('enabled'))) { $settings[] = $item; } else { if (false !== ($key = array_search($item, $settings))) { unset($settings[$key]); } } } $setting->__set('value', serialize(array_unique($settings))); $setting->save(); // Clear cache $cacheClear = new sfCacheClearTask(sfContext::getInstance()->getEventDispatcher(), new sfFormatter()); $cacheClear->run(); $this->redirect(array('module' => 'sfPluginAdminPlugin', 'action' => 'themes')); } } }