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'));
         }
     }
 }
 /**
  * @see sfPluginConfiguration
  */
 public function initialize()
 {
     // Project classes, e.g. QubitSetting, not loaded unless
     // sfApplicationConfiguration,
     // http://qubit-toolkit.org/wiki/index.php?title=Autoload#Plugins
     if (!$this->configuration instanceof sfApplicationConfiguration) {
         return;
     }
     $enabledModules = sfConfig::get('sf_enabled_modules');
     $enabledModules[] = 'sfPluginAdminPlugin';
     sfConfig::set('sf_enabled_modules', $enabledModules);
     // Stash plugin names enabled in ProjectConfiguration.class.php for
     // sfPluginAdminPluginIndexAction. Where is the best place to stash it?
     // This is probably not the best place : P
     sfPluginAdminPluginConfiguration::$pluginNames = $this->configuration->getPlugins();
     new sfDatabaseManager($this->configuration);
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'plugins');
     try {
         if (1 == count($query = QubitSetting::get($criteria))) {
             // http://qubit-toolkit.org/wiki/index.php?title=Autoload
             $this->dispatcher->disconnect('autoload.filter_config', array($this->configuration, 'filterAutoloadConfig'));
             $pluginNames = unserialize($query[0]->__get('value', array('sourceCulture' => true)));
             $this->configuration->enablePlugins($pluginNames);
             $pluginPaths = $this->configuration->getAllPluginPaths();
             foreach ($pluginNames as $name) {
                 if (!isset($pluginPaths[$name])) {
                     throw new InvalidArgumentException('The plugin "' . $name . '" does not exist.');
                 }
                 // Copied from sfProjectConfiguration::loadPlugins()
                 $className = $name . 'Configuration';
                 if (!is_readable($path = $pluginPaths[$name] . '/config/' . $className . '.class.php')) {
                     $configuration = new sfPluginConfigurationGeneric($this->configuration, $pluginPaths[$name], $name);
                 } else {
                     require_once $path;
                     $configuration = new $className($this->configuration, $pluginPaths[$name], $name);
                 }
                 // Is this cached?
                 $configuration->initializeAutoload();
                 $configuration->initialize();
                 $this->configuration->pluginConfigurations[$name] = $configuration;
             }
             $this->dispatcher->connect('autoload.filter_config', array($this->configuration, 'filterAutoloadConfig'));
         }
     } catch (PropelException $e) {
         // Silently swallow PropelException because we can't tell at this point
         // if we are in install, and install plugin can't listen for an exception
         // thrown at this point, is this the best solution?
     }
 }
 public function execute($request)
 {
     $this->form = new sfForm();
     $this->form->setWidgets(array('toggleDescription' => new sfWidgetFormInputCheckbox(), 'toggleLogo' => new sfWidgetFormInputCheckbox(), 'toggleTitle' => new sfWidgetFormInputCheckbox()));
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'toggleDescription');
     if (1 == count($toggleDescriptionQuery = QubitSetting::get($criteria))) {
         $toggleDescriptionSetting = $toggleDescriptionQuery[0];
         $this->form->setDefault('toggleDescription', $toggleDescriptionSetting->__get('value', array('sourceCulture' => true)));
     }
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'toggleLogo');
     if (1 == count($toggleLogoQuery = QubitSetting::get($criteria))) {
         $toggleLogoSetting = $toggleLogoQuery[0];
         $this->form->setDefault('toggleLogo', $toggleLogoSetting->__get('value', array('sourceCulture' => true)));
     }
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'toggleTitle');
     if (1 == count($toggleTitleQuery = QubitSetting::get($criteria))) {
         $toggleTitleSetting = $toggleTitleQuery[0];
         $this->form->setDefault('toggleTitle', $toggleTitleSetting->__get('value', array('sourceCulture' => true)));
     }
     if ($request->isMethod('post')) {
         $this->form->setValidators(array('toggleDescription' => new sfValidatorBoolean(), 'toggleLogo' => new sfValidatorBoolean(), 'toggleTitle' => new sfValidatorBoolean()));
         $this->form->bind($request->getPostParameters());
         if ($this->form->isValid()) {
             if (1 != count($toggleDescriptionQuery)) {
                 $toggleDescriptionSetting = new QubitSetting();
                 $toggleDescriptionSetting->name = 'toggleDescription';
             }
             $toggleDescriptionSetting->__set('value', $this->form->getValue('toggleDescription'), array('sourceCulture' => true));
             $toggleDescriptionSetting->save();
             if (1 != count($toggleLogoQuery)) {
                 $toggleLogoSetting = new QubitSetting();
                 $toggleLogoSetting->name = 'toggleLogo';
             }
             $toggleLogoSetting->__set('value', $this->form->getValue('toggleLogo'), array('sourceCulture' => true));
             $toggleLogoSetting->save();
             if (1 != count($toggleTitleQuery)) {
                 $toggleTitleSetting = new QubitSetting();
                 $toggleTitleSetting->name = 'toggleTitle';
             }
             $toggleTitleSetting->__set('value', $this->form->getValue('toggleTitle'), array('sourceCulture' => true));
             $toggleTitleSetting->save();
             $this->redirect(array('module' => 'settings', 'action' => 'list'));
         }
     }
 }
 public function contextLoadFactories(sfEvent $event)
 {
     $context = $event->getSubject();
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'siteTitle');
     try {
         if (1 == count($query = QubitSetting::get($criteria))) {
             $context->response->addMeta('title', $query[0]->__get('value', array('cultureFallback' => true)));
         }
     } catch (PropelException $e) {
         // Silently swallow PropelException in install
         if ('sfInstallPlugin' != $context->request->module) {
             throw $e;
         }
     }
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'siteDescription');
     try {
         if (1 == count($query = QubitSetting::get($criteria))) {
             $context->response->addMeta('description', $query[0]->__get('value', array('cultureFallback' => true)));
         }
     } catch (PropelException $e) {
         // Silently swallow PropelException in install
         if ('sfInstallPlugin' != $context->request->module) {
             throw $e;
         }
     }
     foreach (array('actor_template', 'informationobject_template', 'repository_template') as $name) {
         if (isset($context->request[$name])) {
             $context->routing->setDefaultParameter($name, $context->request[$name]);
         } else {
             $criteria = new Criteria();
             $criteria->add(QubitSetting::NAME, substr($name, 0, -9));
             $criteria->add(QubitSetting::SCOPE, 'default_template');
             try {
                 if (1 == count($query = QubitSetting::get($criteria))) {
                     $context->routing->setDefaultParameter($name, $query[0]->__get('value', array('sourceCulture' => true)));
                 }
             } catch (PropelException $e) {
                 // Silently swallow PropelException in install
                 if ('sfInstallPlugin' != $context->request->module) {
                     throw $e;
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 protected function initializeDefaultPageElementsForm()
 {
     $this->defaultPageElementsForm = new sfForm();
     $this->defaultPageElementsForm->setWidgets(array('toggleDescription' => new sfWidgetFormInputCheckbox(), 'toggleLogo' => new sfWidgetFormInputCheckbox(), 'toggleTitle' => new sfWidgetFormInputCheckbox()));
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'toggleDescription');
     if (1 == count($toggleDescriptionQuery = QubitSetting::get($criteria))) {
         $toggleDescriptionSetting = $toggleDescriptionQuery[0];
         $this->defaultPageElementsForm->setDefault('toggleDescription', $toggleDescriptionSetting->__get('value', array('sourceCulture' => true)));
     }
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'toggleLogo');
     if (1 == count($toggleLogoQuery = QubitSetting::get($criteria))) {
         $toggleLogoSetting = $toggleLogoQuery[0];
         $this->defaultPageElementsForm->setDefault('toggleLogo', $toggleLogoSetting->__get('value', array('sourceCulture' => true)));
     }
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'toggleTitle');
     if (1 == count($toggleTitleQuery = QubitSetting::get($criteria))) {
         $toggleTitleSetting = $toggleTitleQuery[0];
         $this->defaultPageElementsForm->setDefault('toggleTitle', $toggleTitleSetting->__get('value', array('sourceCulture' => true)));
     }
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * Get all settings matching $scope parameter.
  *
  * @param string $scope
  */
 public static function getByScope($scope = null)
 {
     $criteria = new Criteria();
     if (null !== $scope) {
         $criteria->add(QubitSetting::SCOPE, $scope);
     } else {
         $criteria->add(QubitSetting::SCOPE, null, Criteria::ISNULL);
     }
     return QubitSetting::get($criteria);
 }