[pLog-svn] r4218 - in plog/trunk: class/action/admin class/controller class/dao class/plugin class/template/smarty/plugins class/view/admin locale templates/admin

oscar at devel.lifetype.net oscar at devel.lifetype.net
Tue Oct 31 17:38:52 GMT 2006


Author: oscar
Date: 2006-10-31 17:38:50 +0000 (Tue, 31 Oct 2006)
New Revision: 4218

Added:
   plog/trunk/class/action/admin/adminpluginsettingsaction.class.php
   plog/trunk/class/action/admin/adminupdatepluginsettingsaction.class.php
   plog/trunk/class/plugin/globalpluginconfig.class.php
   plog/trunk/class/template/smarty/plugins/block.user_cannot_override.php
   plog/trunk/class/template/smarty/plugins/function.assignvar.php
   plog/trunk/class/view/admin/adminpluginsettingsview.class.php
   plog/trunk/templates/admin/pluginsettings.template
Modified:
   plog/trunk/class/controller/admincontrollermap.properties.php
   plog/trunk/class/dao/blogsettings.class.php
   plog/trunk/locale/locale_en_UK.php
   plog/trunk/templates/admin/menus.xml
   plog/trunk/templates/admin/plugincenter.template
Log:
Preliminary support for global plugin setting.

This implementation relies on plugins implementing the method PluginBase::getPluginConfigurationKeys() and returning an array with all the 'public' settings that can be set at a site-wide level. Some plugins will just export the 'plugin_xxx_enabled' setting while others will export some more settings, it will depend on the plugin. The returned array should include the name of the key as well as the type and the validator class, if required. I will commit a modified version of the 'authimage' and 'hostblock' plugin with support for this new feature.

Administrators now have the new "plugin settings" page that will list all plugins and for each one of the plugins, their public settings. Additionally, for each one of the settings it will be possible to tell whether users are allowed to modify the setting or not. Right now the UI of this new page is a bit messy as I don't know how to arrange the fields, so I would appreciate somebody having a look at it...

New blogs will inherit the values configured in the global plugin settings page but dependin on the configuration and the setting, owners of new blogs will be allowed to modify those settings. This means that we can install the 'authimage' plugin, say that plugin_authimage_enabled can be modified by users and set its default value to true.

At the UI level, there is a new Smarty 'block' plugin that will check whether a setting can be overriden by users and disable the field. This is not strictly necessary and it's only for the purpose of visual feedback. If a field value cannot be overriden because administrators have configured it so, deactivating it/activating it at the blog level won't make any difference as the global value will always take precedence.

I'm sure I'm forgetting something about this new feature but I will write about it later on in the wiki :) In the meantime, feel free to have it a look (I will commit the modified plugins shortly)


Added: plog/trunk/class/action/admin/adminpluginsettingsaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminpluginsettingsaction.class.php	2006-10-30 23:09:52 UTC (rev 4217)
+++ plog/trunk/class/action/admin/adminpluginsettingsaction.class.php	2006-10-31 17:38:50 UTC (rev 4218)
@@ -0,0 +1,32 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/view/admin/adminpluginsettingsview.class.php" );
+
+    /**
+     * \ingroup Action
+     * @private
+     */
+    class AdminPluginSettingsAction extends SiteAdminAction 
+	{
+
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function AdminPluginSettingsAction( $actionInfo, $request )
+        {
+        	$this->SiteAdminAction( $actionInfo, $request );
+        }
+
+        /**
+         * Carries out the specified action
+         */
+        function perform()
+        {
+            // create a view and put the plugin objects in the template
+            $this->_view = new AdminPluginSettingsView( $this->_blogInfo, $this->_userInfo );
+            $this->setCommonData();
+        }
+    }
+?>
\ No newline at end of file

Added: plog/trunk/class/action/admin/adminupdatepluginsettingsaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminupdatepluginsettingsaction.class.php	2006-10-30 23:09:52 UTC (rev 4217)
+++ plog/trunk/class/action/admin/adminupdatepluginsettingsaction.class.php	2006-10-31 17:38:50 UTC (rev 4218)
@@ -0,0 +1,86 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/view/admin/adminpluginsettingsview.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/data/validator/emptyvalidator.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/plugin/globalpluginconfig.class.php" );
+
+    /**
+     * \ingroup Action
+     * @private
+     */
+    class AdminUpdatePluginSettingsAction extends SiteAdminAction 
+	{
+		
+		var $pm;
+
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function AdminUpdatePluginSettingsAction( $actionInfo, $request )
+        {
+        	$this->SiteAdminAction( $actionInfo, $request );
+
+        	// initialize the plugin manager and load the plugins
+        	$this->pm =& PluginManager::getPluginManager();			
+
+			// register the validators for all the plugin data
+			$this->registerValidators();
+			$view = new AdminPluginSettingsView( $this->_blogInfo, $this->_userInfo );
+			$view->setData( false );
+			$view->setErrorMessage( $this->_locale->tr("error_updating_global_plugin_settings" ));
+			$this->setValidationErrorView( $view );
+        }
+
+		/**
+		 * @private
+		 */
+		function registerValidators()
+		{
+            // get all the plugins
+	    	$this->pm->refreshPluginList();
+            $this->pm->setBlogInfo( $this->_blogInfo );
+            $this->pm->setUserInfo( $this->_userInfo );
+
+			// now one by one, query their public configuration values and set the validators
+			foreach( $this->pm->getPlugins() as $plugin ) {
+				foreach( $plugin->getPluginConfigurationKeys() as $key ) {
+					isset( $key["validator"] ) ? $validator = $key["validator"] : $validator = new EmptyValidator();
+					$this->registerFieldValidator( $key["name"], $validator );
+				}
+			}
+			
+			// "can override" fields
+			$this->registerField( "canOverride" );
+		}
+
+        /**
+         * Carries out the specified action
+         */
+        function perform()
+        {
+			// load the plugin config values
+			$settings = Array();
+			foreach( $this->pm->getPlugins() as $plugin ) {
+				foreach( $plugin->getPluginConfigurationKeys() as $key ) {
+					$keyName = $key["name"];
+					$settings[$keyName] = $this->_request->getValue( $keyName );
+				}
+			}			
+			// and now save them
+			GlobalPluginConfig::setValues( $settings );
+			
+			// load the override settings and save them
+			GlobalPluginConfig::setOverrideSettings( $this->_request->getValue( "canOverride" ));
+			
+			$this->_view = new AdminPluginSettingsView( $this->_blogInfo, $this->_userInfo );
+			$this->_view->setData( true );
+			$this->_view->setSuccessMessage( $this->_locale->tr( "global_plugin_settings_saved_ok" ));
+			$this->setCommonData();
+			
+			return( true );			
+        }
+    }
+?>
\ No newline at end of file

Modified: plog/trunk/class/controller/admincontrollermap.properties.php
===================================================================
--- plog/trunk/class/controller/admincontrollermap.properties.php	2006-10-30 23:09:52 UTC (rev 4217)
+++ plog/trunk/class/controller/admincontrollermap.properties.php	2006-10-31 17:38:50 UTC (rev 4218)
@@ -313,4 +313,7 @@
 	$actions["updateBlogUser"] = "AdminUpdateBlogUserAction";	
 	// permission required
 	$actions["permissionRequired"] = "AdminPermissionRequiredAction";
+	// global plugin settings
+	$actions["pluginSettings"] = "AdminPluginSettingsAction";
+	$actions["updatePluginSettings"] = "AdminUpdatePluginSettingsAction";	
 ?>
\ No newline at end of file

Modified: plog/trunk/class/dao/blogsettings.class.php
===================================================================
--- plog/trunk/class/dao/blogsettings.class.php	2006-10-30 23:09:52 UTC (rev 4217)
+++ plog/trunk/class/dao/blogsettings.class.php	2006-10-31 17:38:50 UTC (rev 4218)
@@ -12,22 +12,7 @@
 	 * \ingroup DAO
 	 *
 	 * Encapsulation of the settings for each blog
-     *
-     * Default settings available from this object:
-     * <ul>
-     * <li>locale</li>
-     * <li>show_posts_max</li>
-     * <li>template</li>
-     * <li>show_more_enabled</li>
-     * <li>show_more_threshold</li>
-     * <li>recent_posts_max</li>
-     * <li>xmlrpc_ping_hosts</li>
-     * <li>show_more_enabled</li>
-     * <li>htmlarea_enabled</li>
-     * <li>comments_enabled</li>
-     * <li>comments_order</li>
-	 * <li>categories_order</li>
-     * </ul>
+	 *
 	 */
 	class BlogSettings extends Properties 
 	{
@@ -60,5 +45,27 @@
 			$this->setValue( "comments_order", $config->getValue( "comments_order" ));
 			$this->setValue( "time_offset", $config->getValue( "default_time_offset", DEFAULT_TIME_OFFSET ));
 		}
+		
+		function getValue( $key )
+		{
+			// is it a plugin key?
+			if( substr( $key, 0, strlen( "plugin_" )) == "plugin_" ) {
+				include_once( PLOG_CLASS_PATH."class/plugin/globalpluginconfig.class.php" );
+				// check if users can override the plugin setting. If so, return the blog plugin settings
+				// and if not return the global setting
+				if( GlobalPluginConfig::canOverride( $key ) == PLUGIN_SETTINGS_USER_CAN_OVERRIDE ) {
+					// load the value from our settings, but if it isn't available, then return whatever the global
+					// plugin settings say					
+					$value = parent::getValue( $key, GlobalPluginConfig::getValue( $key ));
+				}
+				else
+					$value = GlobalPluginConfig::getValue( $key );
+			}
+			else {
+				$value = parent::getValue( $key );
+			}
+			
+			return( $value );
+		}
 	}
 ?>

Added: plog/trunk/class/plugin/globalpluginconfig.class.php
===================================================================
--- plog/trunk/class/plugin/globalpluginconfig.class.php	2006-10-30 23:09:52 UTC (rev 4217)
+++ plog/trunk/class/plugin/globalpluginconfig.class.php	2006-10-31 17:38:50 UTC (rev 4218)
@@ -0,0 +1,84 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+	
+	define( "PLUGIN_SETTINGS_USER_CAN_OVERRIDE", 1 );
+	define( "PLUGIN_SETTINGS_USER_CANNOT_OVERRIDE", 2 );
+
+	class GlobalPluginConfig
+	{
+
+		/**
+		 * @static
+		 */
+		function getValue( $key )
+		{
+			$config =& Config::getConfig();
+			$pluginConfig = $config->getValue( "global_plugin_settings", Array ());
+			
+			if( isset( $pluginConfig["$key"] ))
+				$value = $pluginConfig["$key"];
+			else
+				$value = null;
+				
+			return( $value );			
+		}
+		
+		/**
+		 * @static
+		 * Saves an array of values
+		 */
+		function setValues( $values )
+		{
+			$config =& Config::getConfig();
+			$config->setValue( "global_plugin_settings", $values );
+			return( true );
+		}
+		
+		/**
+		 * @static
+		 * Save the override settings
+		 */
+		function setOverrideSettings( $list )
+		{
+			$config =& Config::getConfig();
+			$config->setValue( "global_plugin_overrides", $list );
+			return( true );			
+		}	
+		
+		/**
+		 * @static
+		 * Get the override settings
+		 */
+		function getOverrideSettings()
+		{
+			$config =& Config::getConfig();			
+			return( $config->getValue( "global_plugin_overrides" ));
+		}
+		
+		function canOverride( $key )
+		{
+			$config =& Config::getConfig();
+			$overrides = $config->getValue( "global_plugin_overrides" );
+			isset( $overrides[$key] ) ? $canOverride = $overrides[$key] : $canOverride = PLUGIN_SETTINGS_USER_CAN_OVERRIDE;
+			
+			return( $canOverride );
+		}	
+			
+		/** 
+		 * @static
+		 * Returns all the values saved for plugins
+		 */
+		function getValues()
+		{
+			$config =& Config::getConfig();
+			
+			$values = $config->getValue( "global_plugin_settings" );
+			
+			if( !is_array( $values ))
+				$values = Array();
+			
+			return( $values );	
+		}
+	}
+?>
\ No newline at end of file

Added: plog/trunk/class/template/smarty/plugins/block.user_cannot_override.php
===================================================================
--- plog/trunk/class/template/smarty/plugins/block.user_cannot_override.php	2006-10-30 23:09:52 UTC (rev 4217)
+++ plog/trunk/class/template/smarty/plugins/block.user_cannot_override.php	2006-10-31 17:38:50 UTC (rev 4218)
@@ -0,0 +1,25 @@
+<?php
+
+/**
+ * Function used in the admin interface as a shorthand to check whether the user has the given permission
+ *
+ * @param key
+ */
+function smarty_block_user_cannot_override($params, $content, &$smarty)	
+{
+	
+	if( isset( $content )) {
+		// fetch the user
+		if( isset( $params["key"]))
+			$key = $params["key"];
+		else {
+			$smarty->trigger_error( "user_cannot_override: missing 'key' parameter!" );			
+		}
+		
+		if( GlobalPluginConfig::canOverride( $key ) == PLUGIN_SETTINGS_USER_CANNOT_OVERRIDE )
+			return( $content );
+		else
+			return "";
+	}
+}
+?>
\ No newline at end of file

Added: plog/trunk/class/template/smarty/plugins/function.assignvar.php
===================================================================
--- plog/trunk/class/template/smarty/plugins/function.assignvar.php	2006-10-30 23:09:52 UTC (rev 4217)
+++ plog/trunk/class/template/smarty/plugins/function.assignvar.php	2006-10-31 17:38:50 UTC (rev 4218)
@@ -0,0 +1,31 @@
+<?php
+	/**
+	 * Smarty plugin
+	 * @package Smarty
+	 * @subpackage plugins
+	 */
+
+
+	/**
+	 * {assignvar var=key value=$template_var}
+	 *
+	 * Smarty's equivalent to PHP's $key=$$template_var
+	 * 
+	 * @param array
+	 * @param Smarty
+	 */
+	function smarty_function_assignvar($params, &$smarty)
+	{
+	    if (!isset($params['var'])) {
+	        $smarty->trigger_error("assign: missing 'var' parameter");
+	        return;
+	    }
+
+	    if (!isset( $params['value'])) {
+	        $smarty->trigger_error("assign: missing 'value' parameter");
+	        return;
+	    }
+	
+	    $smarty->assign($params['var'], $smarty->_tpl_vars[$params["value"]] );
+	}		
+?>

Added: plog/trunk/class/view/admin/adminpluginsettingsview.class.php
===================================================================
--- plog/trunk/class/view/admin/adminpluginsettingsview.class.php	2006-10-30 23:09:52 UTC (rev 4217)
+++ plog/trunk/class/view/admin/adminpluginsettingsview.class.php	2006-10-31 17:38:50 UTC (rev 4218)
@@ -0,0 +1,56 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/plugin/globalpluginconfig.class.php" );
+
+	class AdminPluginSettingsView extends AdminTemplatedView
+	{
+		var $_userInfo;
+		var $_setData;
+
+		function AdminPluginSettingsView( $blogInfo, $userInfo )
+		{
+			$this->AdminTemplatedView( $blogInfo, "pluginsettings" );
+			
+			$this->_userInfo = $userInfo;
+			$this->_setData = true;
+		}
+		
+		function setData( $set ) 
+		{
+			$this->_setData = $set;
+		}
+		
+		/**
+		 * load the fields and pass them to the view
+		 */
+		function render()
+		{
+        	// initialize the plugin manager and load the plugins
+        	$pluginManager =& PluginManager::getPluginManager();
+
+            // we need to get an array with the plugins
+	    	$pluginManager->refreshPluginList();
+            $pluginManager->setBlogInfo( $this->_blogInfo );
+            $pluginManager->setUserInfo( $this->_userInfo );
+            $plugins = $pluginManager->getPlugins();
+
+            // put the plugin objects in the template
+            $this->setValue( "plugins", $plugins );
+
+			// load the settings unless we were configured not to
+			if( $this->_setData ) {
+				// plugin values
+				$values = GlobalPluginConfig::getValues();
+				foreach( $values as $key => $value ) {
+					$this->setValue( $key, $value );
+				}
+				// and override settings
+				$this->setValue( "canOverride", GlobalPluginConfig::getOverrideSettings());
+			}
+
+			return( parent::render());
+		}
+	}
+?>
\ No newline at end of file

Modified: plog/trunk/locale/locale_en_UK.php
===================================================================
--- plog/trunk/locale/locale_en_UK.php	2006-10-30 23:09:52 UTC (rev 4217)
+++ plog/trunk/locale/locale_en_UK.php	2006-10-31 17:38:50 UTC (rev 4218)
@@ -1161,4 +1161,10 @@
 
 $messages['permissions'] = 'Permissions';
 $messages['blog_user_permissions_help'] = 'Permissions assigned to this user in this blog';
+$messages['pluginSettings'] = 'Plugin Settings';
+$messages['user_can_override'] = 'Users can override';
+$messages['user_cannot_override'] = 'Users cannot override';
+$messages['global_plugin_settings_saved_ok'] = 'Global plugin settings saved successfully';
+$messages['error_updating_global_plugin_settings'] = 'There was an error saving the the global plugin settings';
+$messages['error_incorrect_value'] = 'The value is not correct';
 ?>
\ No newline at end of file

Modified: plog/trunk/templates/admin/menus.xml
===================================================================
--- plog/trunk/templates/admin/menus.xml	2006-10-30 23:09:52 UTC (rev 4217)
+++ plog/trunk/templates/admin/menus.xml	2006-10-31 17:38:50 UTC (rev 4218)
@@ -82,6 +82,7 @@
 		</GlobalSettings>
 		<Plugins ignoreBreadCrumbs="1">
 		  <pluginCenter url="?op=pluginCenter" siteAdmin="1" />
+		  <pluginSettings url="?op=pluginSettings" siteAdmin="1" />		
 		</Plugins>
 		<Miscellaneous ignoreBreadCrums="1">
 			<cleanUp url="?op=cleanUp" siteAdmin="1" />

Modified: plog/trunk/templates/admin/plugincenter.template
===================================================================
--- plog/trunk/templates/admin/plugincenter.template	2006-10-30 23:09:52 UTC (rev 4217)
+++ plog/trunk/templates/admin/plugincenter.template	2006-10-31 17:38:50 UTC (rev 4218)
@@ -5,8 +5,8 @@
             <table class="info">
                 <thead>
                     <tr>
-                        <th style="width:15%;"><a href="#">{$locale->tr("identifier")}</a></th>
-                        <th style="width:20%;"><a href="#">{$locale->tr("author")}</a></th>
+                        <th style="width:25%;"><a href="#">{$locale->tr("identifier")}</a></th>
+                        <th style="width:25%;"><a href="#">{$locale->tr("author")}</a></th>
                         <th style="width:65%;"><a href="#">{$locale->tr("description")}</a></th>                        
                     </tr>
                 </thead>

Added: plog/trunk/templates/admin/pluginsettings.template
===================================================================
--- plog/trunk/templates/admin/pluginsettings.template	2006-10-30 23:09:52 UTC (rev 4217)
+++ plog/trunk/templates/admin/pluginsettings.template	2006-10-31 17:38:50 UTC (rev 4218)
@@ -0,0 +1,41 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=pluginSettings title=$locale->tr("pluginSettings")}
+
+<form id="pluginSettings" method="post" action="admin.php">
+<div id="list">    
+<fieldset class="inputField">
+  <legend>{$locale->tr("pluginSettings")}</legend>
+  {include file="$admintemplatepath/formvalidate.template"}
+  {foreach from=$plugins item=plugin} 
+     <h4>{$plugin->getId()}</h4>
+	{assign var=pluginsettings value=$plugin->getPluginConfigurationKeys()}
+	{foreach from=$pluginsettings item=setting}
+	 <div class="field">
+		{assignvar var=key value=$setting.name}
+		{assign var=name value=$setting.name}
+		{assign var=overrideValue value=$canOverride[$setting.name]}
+		<select name="canOverride[{$setting.name}]">		 
+			<option value="1" {if $overrideValue==1}selected="selected"{/if}>{$locale->tr("user_can_override")}</option>
+			<option value="2" {if $overrideValue==2}selected="selected"{/if}>{$locale->tr("user_cannot_override")}</option>
+		</select>
+		{$setting.name}:
+		{if $setting.type=="boolean"}								 
+		 <input type="checkbox" name="{$setting.name}" value="1" class="checkbox" {if $key}checked="checked"{/if}/>
+		 {elseif $setting.type=="string"}		 
+		 <input type="text" name="{$setting.name}" value="{$key}" />
+		 {elseif $setting.type=="integer"}
+		 <input type="text" name="{$setting.name}" value="{$key}" />
+		{/if}
+		{include file="$admintemplatepath/validate.template" field=$setting.name message=$locale->tr("error_incorrect_value")}
+		</div>
+	 {/foreach}
+   {/foreach}
+</fieldset>
+<div id="list_action_bar">
+<input type="hidden" name="op" value="updatePluginSettings" class="submit" />
+<input type="reset" name="{$locale->tr("reset")}" value="{$locale->tr("reset")}"/>
+<input type="submit" name="{$locale->tr("update")}" value="{$locale->tr("update")}"/>
+</div>
+</form>
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file



More information about the pLog-svn mailing list