3 # FILE: PluginManager.php 5 # Part of the ScoutLib application support library 6 # Copyright 2009-2013 Edward Almasy and Internet Scout Research Group 7 # http://scout.wisc.edu 16 # ----- PUBLIC INTERFACE ------------------------------------------------- 121 "Author" => $this->Author,
122 "CfgPage" => $this->CfgPage,
123 "CfgSetup" => $this->CfgSetup,
124 "Description" => $this->Description,
125 "Email" => $this->
Email,
126 "EnabledByDefault" => $this->EnabledByDefault,
127 "InitializeAfter" => is_array($this->InitializeAfter)
128 ? $this->InitializeAfter : array($this->InitializeAfter),
129 "InitializeBefore" => is_array($this->InitializeBefore)
130 ? $this->InitializeBefore : array($this->InitializeBefore),
131 "Instructions" => $this->Instructions,
132 "Name" => $this->Name,
133 "Requires" => $this->Requires,
135 "Version" => $this->Version,
145 return get_class($this);
157 # if a new value was supplied for the setting 158 if (func_num_args() > 1)
160 # if this setting has a filter function specified 161 if (array_key_exists($SettingName, $this->CfgSetup)
162 && array_key_exists(
"SettingFilter",
163 $this->CfgSetup[$SettingName]))
165 # pass new value through filter function 166 $FilterMethod = $this->CfgSetup[$SettingName][
"SettingFilter"];
167 $NewValue = $this->$FilterMethod($SettingName, $NewValue);
170 # if caller requested that setting be cleared 171 if ($NewValue === NULL)
174 unset($this->Cfg[$SettingName]);
178 # save new value for setting 179 $this->Cfg[$SettingName] = $NewValue;
182 # save new configuration settings 184 $DB->Query(
"UPDATE PluginInfo SET Cfg = '" 185 .addslashes(serialize($this->Cfg))
186 .
"' WHERE BaseName = '" 190 # return current value of setting to caller 191 return isset($this->Cfg[$SettingName]) ? $this->Cfg[$SettingName] : NULL;
202 # if new ready status was supplied 203 if ($NewValue !== NULL)
205 # make sure we are being called from the plugin manager 207 "Attempt to update plugin ready status at %FILE%:%LINE%." 208 .
" (Plugin ready status can only be set by PluginManager.)");
210 # update plugin ready status 211 $this->Ready = $NewValue ? TRUE : FALSE;
214 # return current ready status to caller 226 # if new enabled status was suppled 227 if ($NewValue !== NULL)
229 # update enabled status in database 230 $this->Enabled = $NewValue ? TRUE : FALSE;
232 $DB->Query(
"UPDATE PluginInfo" 233 .
" SET Enabled = ".($NewValue ?
"1" :
"0")
234 .
" WHERE BaseName = '".addslashes($this->
GetBaseName()).
"'");
237 # return current enabled status to caller 238 return $this->Enabled;
250 # if new install status was supplied 251 if ($NewValue !== NULL)
253 # make sure we are being called from the plugin manager 255 "Attempt to update plugin install status at %FILE%:%LINE%." 256 .
" (Plugin install status can only be set by PluginManager.)");
258 # update installation setting in database 259 $this->Installed = $NewValue ? TRUE : FALSE;
261 $DB->Query(
"UPDATE PluginInfo" 262 .
" SET Installed = ".($NewValue ?
"1" :
"0")
263 .
" WHERE BaseName = '".addslashes($this->
GetBaseName()).
"'");
266 # return installed status to caller 267 return $this->Installed;
278 # if new version was supplied 279 if ($NewValue !== NULL)
281 # make sure we are being called from the plugin manager 283 "Attempt to set installed version of plugin at %FILE%:%LINE%." 284 .
" (Plugin installed version can only be set by PluginManager.)");
286 # update version in database 289 $DB->Query(
"UPDATE PluginInfo" 290 .
" SET Version = '".addslashes($NewValue).
"'" 291 .
" WHERE BaseName = '".addslashes($this->
GetBaseName()).
"'");
294 # return current installed version to caller 295 return $this->InstalledVersion;
325 # make sure we are being called from the plugin manager 327 "Attempt to create plugin object at %FILE%:%LINE%." 328 .
" (Plugins can only be instantiated by PluginManager.)");
333 # load plugin info from database if necessary 334 if (!isset(self::$PluginInfoCache))
337 $DB->Query(
"SELECT * FROM PluginInfo");
338 while ($Row = $DB->FetchRow())
340 self::$PluginInfoCache[$Row[
"BaseName"]] = $Row;
344 # add plugin to database if not already in there 345 $BaseName = get_class($this);
346 if (!isset(self::$PluginInfoCache[$BaseName]))
353 $DB->Query(
"INSERT INTO PluginInfo" 354 .
" (BaseName, Version, Enabled)" 355 .
" VALUES ('".addslashes($BaseName).
"', " 357 $Attribs[
"Version"]).
"', " 358 .
" ".($Attribs[
"EnabledByDefault"]
360 $DB->Query(
"SELECT * FROM PluginInfo WHERE BaseName = '" 361 .addslashes($BaseName).
"'");
362 self::$PluginInfoCache[$BaseName] = $DB->FetchRow();
366 $Info = self::$PluginInfoCache[$BaseName];
367 $this->Enabled = $Info[
"Enabled"];
368 $this->Installed = $Info[
"Installed"];
370 $this->Cfg = unserialize($Info[
"Cfg"]);
384 # ----- PROTECTED INTERFACE ---------------------------------------------- 436 # ----- PRIVATE INTERFACE ------------------------------------------------ 441 private $Enabled = FALSE;
443 private $Installed = FALSE;
445 private $InstalledVersion = FALSE;
447 private $Ready = FALSE;
450 private static $PluginInfoCache;
457 final public function SetAllCfg($NewValues)
459 $this->Cfg = $NewValues;
Install()
Perform any work needed when the plugin is first installed (for example, creating database tables)...
IsReady($NewValue=NULL)
Get/set whether the plugin is ready for use.
$InitializeAfter
Plugins that should be initialized before us.
static CheckMyCaller($DesiredCaller, $ExceptionMsg=NULL)
Check the caller of the current function.
GetName()
Get full name of plugin.
$Email
Contact email for the plugin's author.
SQL database abstraction object with smart query caching.
Register()
Set the plugin attributes.
InstalledVersion($NewValue=NULL)
Get/set the last version recorded as installed.
Upgrade($PreviousVersion)
Perform any work needed when the plugin is upgraded to a new version (for example, adding fields to database tables).
IsInstalled($NewValue=NULL)
Get/set whether the plugin is installed.
$EnabledByDefault
Whether the plugin should be enabled by default when installed.
$Version
Version number of plugin in the format X.X.X (for example: 1.2.12).
GetBaseName()
Get plugin base name.
$Author
Name of the plugin's author.
$InitializeBefore
Plugins that should be initialized after us.
__construct()
Class constructor – FOR PLUGIN MANAGER USE ONLY.
HookEvents()
Hook methods to be called when specific events occur.
GetDependencies()
Get list of plugins upon which this plugin depends (if any).
$CfgSetup
Associative array describing the configuration values for the plugin.
$Requires
Array with plugin base (class) names for the index and minimum version numbers for the values...
SetUpConfigOptions()
Set up plugin configuration options.
DeclareEvents()
Declare events defined by this plugin.
Base class for all plugins.
GetAttributes()
Retrieve plugin information.
$CfgPage
Name of configuration page for plugin.
$Description
Text description of the plugin.
static $AF
Application framework.
$Name
Proper (human-readable) name of plugin.
Initialize()
Initialize the plugin.
$Url
Web address for more information about the plugin.
static SetApplicationFramework($AF)
Set the application framework to be referenced within plugins.
IsEnabled($NewValue=NULL)
Get/set whether the plugin is enabled.
ConfigSetting($SettingName, $NewValue=NULL)
Get/set plugin configuration setting.
$Instructions
Instructions for configuring the plugin (displayed on the automatically-generated configuration page ...
Uninstall()
Perform any work needed when the plugin is uninstalled.