[Fusionforge-commits] r11624 - trunk/src/common/include
Franck VILLAUME
nerville at libremir.placard.fr.eu.org
Fri Nov 26 11:21:36 CET 2010
Author: nerville
Date: 2010-11-26 11:21:36 +0100 (Fri, 26 Nov 2010)
New Revision: 11624
Modified:
trunk/src/common/include/PluginManager.class.php
Log:
cleanup
Modified: trunk/src/common/include/PluginManager.class.php
===================================================================
--- trunk/src/common/include/PluginManager.class.php 2010-11-26 10:10:17 UTC (rev 11623)
+++ trunk/src/common/include/PluginManager.class.php 2010-11-26 10:21:36 UTC (rev 11624)
@@ -3,6 +3,7 @@
* FusionForge plugin system
*
* Copyright 2002, 2009, Roland Mas
+ * http://fusionforge.org
*
* This file is part of FusionForge.
*
@@ -23,26 +24,26 @@
*/
class PluginManager extends Error {
- var $plugins_objects ;
- var $plugins_to_hooks ;
- var $hooks_to_plugins ;
+ var $plugins_objects;
+ var $plugins_to_hooks;
+ var $hooks_to_plugins;
var $returned_value = array();
/**
* PluginManager() - constructor
*
*/
- function PluginManager () {
- $this->Error() ;
- $this->plugins_objects = array () ;
- $this->plugins_to_hooks = array () ;
- $this->hooks_to_plugins = array () ;
+ function PluginManager() {
+ $this->Error();
+ $this->plugins_objects = array();
+ $this->plugins_to_hooks = array();
+ $this->hooks_to_plugins = array();
}
//to work with Codendi files
static function instance() {
global $PLUGINMANAGER_OBJ;
if (!isset($PLUGINMANAGER_OBJ) || !$PLUGINMANAGER_OBJ) {
- $PLUGINMANAGER_OBJ = new PluginManager ;
+ $PLUGINMANAGER_OBJ = new PluginManager;
}
return $PLUGINMANAGER_OBJ ;
@@ -50,47 +51,47 @@
/**
* GetPlugins() - get a list of installed plugins
*
- * @return hash of plugin id => plugin names
+ * @return hash of plugin id => plugin names
*/
- function GetPlugins () {
+ function GetPlugins() {
if (!isset($this->plugins_data)) {
- $this->plugins_data = array () ;
- $res = db_query_params ('SELECT plugin_id, plugin_name FROM plugins',
- array ());
+ $this->plugins_data = array();
+ $res = db_query_params('SELECT plugin_id, plugin_name FROM plugins',
+ array());
$rows = db_numrows($res);
for ($i=0; $i<$rows; $i++) {
- $plugin_id = db_result($res,$i,'plugin_id');
- $this->plugins_data[$plugin_id] = db_result($res,$i,'plugin_name');
+ $plugin_id = db_result($res, $i, 'plugin_id');
+ $this->plugins_data[$plugin_id] = db_result($res, $i, 'plugin_name');
}
}
- return $this->plugins_data ;
+ return $this->plugins_data;
}
/**
* GetPluginObject() - get a particular plugin object
*
- * @param pluginname - name of plugin
- * @return a plugin object or false if not available
+ * @param string name of plugin
+ * @return object plugin object or false if not available
*/
- function GetPluginObject ($pluginname) {
- if (!isset($this->plugins_objects [$pluginname])) {
+ function GetPluginObject($pluginname) {
+ if (!isset($this->plugins_objects[$pluginname])) {
return false;
}
- return $this->plugins_objects [$pluginname] ;
+ return $this->plugins_objects[$pluginname];
}
//Added for Codendi compatibility
- function getPluginByName ($pluginname) {
- return @$this->plugins_objects [$pluginname] ;
+ function getPluginByName($pluginname) {
+ return @$this->plugins_objects[$pluginname];
}
/**
* PluginIsInstalled() - is a plugin installed?
*
- * @param pluginname - name of plugin
- * @return boolean, true if installed
+ * @param string name of plugin
+ * @return boolean true if installed
*/
function PluginIsInstalled ($pluginname) {
- $plugins_data = $this->getPlugins() ;
+ $plugins_data = $this->getPlugins();
foreach ($plugins_data as $p_id => $p_name) {
if ($p_name == $pluginname) {
return true ;
@@ -100,13 +101,13 @@
}
function isPluginAvailable ($plugin) {
$pluginname = $plugin->GetName();
- $plugins_data = $this->getPlugins() ;
+ $plugins_data = $this->getPlugins();
foreach ($plugins_data as $p_id => $p_name) {
if ($p_name == $pluginname) {
- return true ;
+ return true;
}
}
- return false ;
+ return false;
}
function activate($pluginname) {
$res = db_query_params('INSERT INTO plugins (plugin_name,plugin_desc) VALUES ($1,$2)',
@@ -115,7 +116,7 @@
$res = db_query_params ('SELECT plugin_id, plugin_name FROM plugins WHERE plugin_name=$1',
array ($pluginname));
if (db_numrows($res) == 1) {
- $plugin_id = db_result($res,0,'plugin_id');
+ $plugin_id = db_result($res, 0, 'plugin_id');
$this->plugins_data[$plugin_id] = db_result($res,0,'plugin_name');
} else {
return false;
@@ -126,7 +127,7 @@
function deactivate($pluginname) {
$res = db_query_params('DELETE FROM plugins WHERE plugin_name = $1', array($pluginname));
- $p_id = NULL ;
+ $p_id = NULL;
foreach ($this->plugins_data as $i => $n) {
if ($n == $pluginname) {
@@ -143,24 +144,24 @@
* LoadPlugin() - load a specific plugin
*
*/
- function LoadPlugin ($p_name) {
+ function LoadPlugin($p_name) {
global $gfplugins, $gfcommon, $gfwww;
- $plugins_data = $this->GetPlugins() ;
- $include_path = forge_get_config('plugins_path') ;
- $filename = $include_path . '/'. $p_name . "/common/".$p_name."-init.php" ;
+ $plugins_data = $this->GetPlugins();
+ $include_path = forge_get_config('plugins_path');
+ $filename = $include_path . '/'. $p_name . "/common/".$p_name."-init.php";
if (file_exists ($filename)) {
- require_once ($filename) ;
+ require_once ($filename);
} else {
$filename = $include_path . '/'. $p_name . "/common/".$p_name."Plugin.class.php" ;
if (file_exists($filename)) {
require_once($filename);
$p_class = $p_name.'Plugin';
- register_plugin (new $p_class) ;
+ register_plugin (new $p_class);
} else { //if we didn't found it in common/ it may be an old plugin that has it's files in include/
$filename = $include_path . '/' . $p_name . "/include/".$p_name."-init.php" ;
if (file_exists ($filename)) {
- require_once ($filename) ;
+ require_once ($filename);
} else {
// we can't find the plugin so we remove it from the array
foreach ($plugins_data as $i => $n) {
@@ -172,54 +173,54 @@
}
}
}
- return true ;
+ return true;
}
/**
* LoadPlugins() - load available plugins
*
*/
- function LoadPlugins () {
- $plugins_data = $this->GetPlugins() ;
+ function LoadPlugins() {
+ $plugins_data = $this->GetPlugins();
foreach ($plugins_data as $p_id => $p_name) {
if (!$this->LoadPlugin($p_name)) {
// we can't find the plugin so we remove it from the array
unset($this->plugins_data[$p_id]);
}
}
- return true ;
+ return true;
}
/**
* SetupHooks() - setup all hooks for installed plugins
*
*/
- function SetupHooks () {
+ function SetupHooks() {
$this->hooks_to_plugins = array();
foreach ($this->plugins_to_hooks as $p_name => $hook_list) {
foreach ($hook_list as $hook_name) {
if (!isset ($this->hooks_to_plugins[$hook_name])) {
- $this->hooks_to_plugins[$hook_name] = array () ;
+ $this->hooks_to_plugins[$hook_name] = array();
}
- $this->hooks_to_plugins[$hook_name][] = $p_name ;
+ $this->hooks_to_plugins[$hook_name][] = $p_name;
}
}
- return true ;
+ return true;
}
/**
* RegisterPlugin() - register a plugin
*
- * @param pluginobject - an object of a subclass of the Plugin class
+ * @param object an object of a subclass of the Plugin class
*/
- function RegisterPlugin (&$pluginobject) {
- if (!$pluginobject->GetName ()) {
- exit_error (_("Some plugin did not provide a name. I'd gladly tell you which one, but obviously I can't. Sorry."),'') ;
+ function RegisterPlugin(&$pluginobject) {
+ if (!$pluginobject->GetName()) {
+ exit_error(_("Some plugin did not provide a name. I'd gladly tell you which one, but obviously I can't. Sorry."),'');
}
- $p_name = $pluginobject->GetName () ;
- $this->plugins_objects [$p_name] =& $pluginobject ;
- $this->plugins_to_hooks [$p_name] = $pluginobject->GetHooks () ;
- return true ;
+ $p_name = $pluginobject->GetName() ;
+ $this->plugins_objects[$p_name] =& $pluginobject;
+ $this->plugins_to_hooks[$p_name] = $pluginobject->GetHooks();
+ return true;
}
/**
@@ -230,7 +231,7 @@
*
* @return boolean, true if all returned true.
*/
- function RunHooks ($hookname, & $params) {
+ function RunHooks($hookname, & $params) {
$result = true;
if (isset($this->hooks_to_plugins[$hookname])) {
$p_list = $this->hooks_to_plugins[$hookname];
@@ -239,13 +240,12 @@
if (method_exists($p_obj, $hookname)) {
$returned = $p_obj->$hookname($params);
} else {
- $returned = $p_obj->CallHook ($hookname, $params);
+ $returned = $p_obj->CallHook($hookname, $params);
}
$this->returned_value[$hookname] = $returned;
- $result = $result && $returned ;
+ $result = $result && $returned;
}
}
-
// Return true only if all the plugins have returned true.
return $result;
}
@@ -257,17 +257,18 @@
/**
* CountHookListeners() - number of listeners on a particular hook
*
- * @param hookname - name of the hook
+ * @param string name of the hook
+ * @return int nb of listeners for this hookname
*/
- function CountHookListeners ($hookname) {
+ function CountHookListeners($hookname) {
if (isset($this->hooks_to_plugins[$hookname])) {
$p_list = $this->hooks_to_plugins[$hookname];
- return count ($p_list) ;
+ return count ($p_list);
} else {
- return 0 ;
+ return 0;
}
+ }
- }
function isPluginAllowedForProject($p, $group_id) {
$Group = group_get_object($group_id);
return $Group->usesPlugin($p->getName());
@@ -345,11 +346,11 @@
* setup_plugin_manager () - initialise the plugin infrastructure
*
*/
-function setup_plugin_manager () {
+function setup_plugin_manager() {
$pm =& plugin_manager_get_object() ;
- $pm->LoadPlugins () ;
- $pm->SetupHooks () ;
- return true ;
+ $pm->LoadPlugins();
+ $pm->SetupHooks();
+ return true;
}
// Local Variables:
More information about the Fusionforge-commits
mailing list