Author: sevein
Date: Fri Aug 5 16:54:32 2011
New Revision: 9442
Log:
Separate themes and plugins in two different actions/templates
Added:
trunk/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/actions/pluginsAction.class.php
- copied, changed from r9439,
trunk/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/actions/indexAction.class.php
trunk/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/actions/themesAction.class.php
trunk/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/templates/pluginsSuccess.php
trunk/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/templates/themesSuccess.php
Deleted:
trunk/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/actions/indexAction.class.php
trunk/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/templates/indexSuccess.php
Copied and modified:
trunk/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/actions/pluginsAction.class.php
(from r9439,
trunk/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/actions/indexAction.class.php)
==============================================================================
---
trunk/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/actions/indexAction.class.php
Fri Aug 5 12:50:06 2011 (r9439, copy source)
+++
trunk/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/actions/pluginsAction.class.php
Fri Aug 5 16:54:32 2011 (r9442)
@@ -17,7 +17,7 @@
* along with Qubit Toolkit. If not, see <http://www.gnu.org/licenses/>.
*/
-class sfPluginAdminPluginIndexAction extends sfAction
+class sfPluginAdminPluginPluginsAction extends sfAction
{
public function execute($request)
{
@@ -53,7 +53,14 @@
$this->installPluginAssets($name, $path);
require_once $classPath;
- $this->plugins[$name] = new $className($configuration);
+
+ $class = new $className($configuration);
+
+ // Build a list of plugins
+ if (isset($class::$summary) && 0 === preg_match('/theme/i',
$class::$summary))
+ {
+ $this->plugins[$name] = $class;
+ }
}
}
@@ -72,10 +79,25 @@
$setting->name = 'plugins';
}
- $setting->__set('value', serialize($this->form->getValue('enabled')),
array('sourceCulture' => true));
+ $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
+ {
+ $key = array_search($item, $settings);
+ unset($settings[$key]);
+ }
+ }
+
+ $setting->__set('value', serialize(array_unique($settings)));
$setting->save();
- $this->redirect(array('module' => 'sfPluginAdminPlugin'));
+ $this->redirect(array('module' => 'sfPluginAdminPlugin', 'action' =>
'plugins'));
}
}
}
Added:
trunk/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/actions/themesAction.class.php
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++
trunk/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/actions/themesAction.class.php
Fri Aug 5 16:54:32 2011 (r9442)
@@ -0,0 +1,116 @@
+<?php
+
+/*
+ * This file is part of Qubit Toolkit.
+ *
+ * Qubit Toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Qubit Toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qubit Toolkit. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+class sfPluginAdminPluginThemesAction extends sfAction
+{
+ 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
+ {
+ $key = array_search($item, $settings);
+ unset($settings[$key]);
+ }
+ }
+
+ $setting->__set('value', serialize(array_unique($settings)));
+ $setting->save();
+
+ $this->redirect(array('module' => 'sfPluginAdminPlugin', 'action' =>
'themes'));
+ }
+ }
+ }
+
+ // Copied from sfPluginPublishAssetsTask
+ protected function installPluginAssets($name, $path)
+ {
+ $webDir = $path.'/web';
+
+ if (is_dir($webDir))
+ {
+ $filesystem = new sfFilesystem;
+ $filesystem->relativeSymlink($webDir,
sfConfig::get('sf_web_dir').'/'.$name, true);
+ }
+ }
+}
Added:
trunk/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/templates/pluginsSuccess.php
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++
trunk/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/templates/pluginsSuccess.php
Fri Aug 5 16:54:32 2011 (r9442)
@@ -0,0 +1,52 @@
+<h1><?php echo __('List plugins') ?></h1>
+
+<?php echo $form->renderGlobalErrors() ?>
+
+<?php echo $form->renderFormTag(url_for(array('module' =>
'sfPluginAdminPlugin', 'action' => 'plugins'))) ?>
+
+ <table class="sticky-enabled">
+ <thead>
+ <tr>
+ <th>
+ Name
+ </th><th>
+ Version
+ </th><th>
+ Enabled
+ </th>
+ </tr>
+ </thead><tbody>
+ <?php foreach ($plugins as $name => $plugin): ?>
+ <tr class="<?php echo 0 == ++$row % 2 ? 'even' : 'odd' ?>">
+
+ <td>
+
+ <?php if (file_exists($plugin->getRootDir().'/images/image.png')):
?>
+ <?php echo image_tag('/plugins/'.$name.'/images/image',
array('alt' => $name)) ?>
+ <?php endif; ?>
+
+ <h2><?php echo $name ?></h2>
+
+ <div class="description">
+ <?php $class = new ReflectionClass($plugin); echo
$class->getStaticPropertyValue('summary') // HACK Use $plugin::$summary in PHP
5.3 http://php.net/oop5.late-static-bindings ?>
+ </div>
+
+ </td>
+
+ <td>
+ <?php echo $class->getStaticPropertyValue('version') // HACK Use
$plugin::$version in PHP 5.3 ?>
+ </td>
+
+ <?php // TODO Should redisplay tainted value ?>
+ <td align="center">
+ <input<?php if ($form->isBound() && in_array($name,
$form->getValue('enabled')) || !$form->isBound() && in_array($name,
$form->getDefault('enabled'))): ?> checked="checked"<?php endif; ?>
name="enabled[]" type="checkbox" value="<?php echo $name ?>"
+ </td>
+
+ </tr>
+ <?php endforeach; ?>
+ </tbody>
+ </table>
+
+ <input class="form-submit" type="submit" value="<?php echo __('Save') ?>"/>
+
+</form>
Added:
trunk/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/templates/themesSuccess.php
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++
trunk/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/templates/themesSuccess.php
Fri Aug 5 16:54:32 2011 (r9442)
@@ -0,0 +1,52 @@
+<h1><?php echo __('List themes') ?></h1>
+
+<?php echo $form->renderGlobalErrors() ?>
+
+<?php echo $form->renderFormTag(url_for(array('module' =>
'sfPluginAdminPlugin', 'action' => 'themes'))) ?>
+
+ <table class="sticky-enabled">
+ <thead>
+ <tr>
+ <th>
+ Name
+ </th><th>
+ Version
+ </th><th>
+ Enabled
+ </th>
+ </tr>
+ </thead><tbody>
+ <?php foreach ($plugins as $name => $plugin): ?>
+ <tr class="<?php echo 0 == ++$row % 2 ? 'even' : 'odd' ?>">
+
+ <td>
+
+ <?php if (file_exists($plugin->getRootDir().'/images/image.png')):
?>
+ <?php echo image_tag('/plugins/'.$name.'/images/image',
array('alt' => $name)) ?>
+ <?php endif; ?>
+
+ <h2><?php echo $name ?></h2>
+
+ <div class="description">
+ <?php $class = new ReflectionClass($plugin); echo
$class->getStaticPropertyValue('summary') // HACK Use $plugin::$summary in PHP
5.3 http://php.net/oop5.late-static-bindings ?>
+ </div>
+
+ </td>
+
+ <td>
+ <?php echo $class->getStaticPropertyValue('version') // HACK Use
$plugin::$version in PHP 5.3 ?>
+ </td>
+
+ <?php // TODO Should redisplay tainted value ?>
+ <td align="center">
+ <input<?php if ($form->isBound() && in_array($name,
$form->getValue('enabled')) || !$form->isBound() && in_array($name,
$form->getDefault('enabled'))): ?> checked="checked"<?php endif; ?>
name="enabled[]" type="checkbox" value="<?php echo $name ?>"
+ </td>
+
+ </tr>
+ <?php endforeach; ?>
+ </tbody>
+ </table>
+
+ <input class="form-submit" type="submit" value="<?php echo __('Save') ?>"/>
+
+</form>
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.