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);
159 # if a new value was supplied for the setting 160 if (func_num_args() > 1)
162 # if this setting has a filter function specified 163 if (array_key_exists($SettingName, $this->CfgSetup)
164 && array_key_exists(
"SettingFilter",
165 $this->CfgSetup[$SettingName]))
167 # pass new value through filter function 168 $FilterMethod = $this->CfgSetup[$SettingName][
"SettingFilter"];
169 $NewValue = $this->$FilterMethod($SettingName, $NewValue);
172 # if caller requested that setting be cleared 173 if ($NewValue === NULL)
176 unset($this->Cfg[$SettingName]);
180 # save new value for setting 181 $this->Cfg[$SettingName] = $NewValue;
184 # save new configuration settings 186 $DB->Query(
"UPDATE PluginInfo SET Cfg = '" 187 .addslashes(serialize($this->Cfg))
188 .
"' WHERE BaseName = '" 192 # return current value of setting to caller 193 return isset($this->CfgOver[$SettingName]) ? $this->CfgOver[$SettingName]
194 : (isset($this->Cfg[$SettingName]) ? $this->Cfg[$SettingName] : NULL);
205 # return current saved value of setting to caller 206 return isset($this->Cfg[$SettingName]) ? $this->Cfg[$SettingName] : NULL;
217 return isset($this->CfgSetup[$SettingName])
218 ? $this->CfgSetup[$SettingName][
"Type"] : NULL;
230 return isset($this->CfgSetup[$SettingName])
231 ? $this->CfgSetup[$SettingName] : NULL;
244 # check that setting name was valid 245 if (!isset($this->Cfg[$SettingName]))
247 throw new InvalidArgumentException(
248 "Unknown setting name (".$SettingName.
").");
251 # save override value 252 $this->CfgOver[$SettingName] = $Value;
263 # if new ready status was supplied 264 if ($NewValue !== NULL)
266 # make sure we are being called from the plugin manager 268 "Attempt to update plugin ready status at %FILE%:%LINE%." 269 .
" (Plugin ready status can only be set by PluginManager.)");
271 # update plugin ready status 272 $this->Ready = $NewValue ? TRUE : FALSE;
275 # return current ready status to caller 288 public function IsEnabled($NewValue = NULL, $Persistent = TRUE)
290 # if new enabled status was suppled 291 if ($NewValue !== NULL)
293 # save new status locally 294 $this->Enabled = $NewValue ? TRUE : FALSE;
296 # update enabled status in database if appropriate 300 $DB->Query(
"UPDATE PluginInfo" 301 .
" SET Enabled = ".($NewValue ?
"1" :
"0")
302 .
" WHERE BaseName = '".addslashes($this->
GetBaseName()).
"'");
306 # return current enabled status to caller 307 return $this->Enabled;
319 # if new install status was supplied 320 if ($NewValue !== NULL)
322 # make sure we are being called from the plugin manager 324 "Attempt to update plugin install status at %FILE%:%LINE%." 325 .
" (Plugin install status can only be set by PluginManager.)");
327 # update installation setting in database 328 $this->Installed = $NewValue ? TRUE : FALSE;
330 $DB->Query(
"UPDATE PluginInfo" 331 .
" SET Installed = ".($NewValue ?
"1" :
"0")
332 .
" WHERE BaseName = '".addslashes($this->
GetBaseName()).
"'");
335 # return installed status to caller 336 return $this->Installed;
347 # if new version was supplied 348 if ($NewValue !== NULL)
350 # make sure we are being called from the plugin manager 352 "Attempt to set installed version of plugin at %FILE%:%LINE%." 353 .
" (Plugin installed version can only be set by PluginManager.)");
355 # update version in database 358 $DB->Query(
"UPDATE PluginInfo" 359 .
" SET Version = '".addslashes($NewValue).
"'" 360 .
" WHERE BaseName = '".addslashes($this->
GetBaseName()).
"'");
363 # return current installed version to caller 364 return $this->InstalledVersion;
394 # make sure we are being called from the plugin manager 396 "Attempt to create plugin object at %FILE%:%LINE%." 397 .
" (Plugins can only be instantiated by PluginManager.)");
402 # load plugin info from database if necessary 403 if (!isset(self::$PluginInfoCache))
406 $DB->Query(
"SELECT * FROM PluginInfo");
407 while ($Row = $DB->FetchRow())
409 self::$PluginInfoCache[$Row[
"BaseName"]] = $Row;
413 # add plugin to database if not already in there 414 $BaseName = get_class($this);
415 if (!isset(self::$PluginInfoCache[$BaseName]))
422 $DB->Query(
"INSERT INTO PluginInfo" 423 .
" (BaseName, Version, Enabled)" 424 .
" VALUES ('".addslashes($BaseName).
"', " 426 $Attribs[
"Version"]).
"', " 427 .
" ".($Attribs[
"EnabledByDefault"]
429 $DB->Query(
"SELECT * FROM PluginInfo WHERE BaseName = '" 430 .addslashes($BaseName).
"'");
431 self::$PluginInfoCache[$BaseName] = $DB->FetchRow();
435 $Info = self::$PluginInfoCache[$BaseName];
436 $this->Enabled = $Info[
"Enabled"];
437 $this->Installed = $Info[
"Installed"];
439 $this->Cfg = unserialize($Info[
"Cfg"]);
453 # ----- PROTECTED INTERFACE ---------------------------------------------- 505 # ----- PRIVATE INTERFACE ------------------------------------------------ 512 private $Enabled = FALSE;
514 private $Installed = FALSE;
516 private $InstalledVersion = FALSE;
518 private $Ready = FALSE;
521 private static $PluginInfoCache;
528 final public function SetAllCfg($NewValues)
530 $this->Cfg = $NewValues;
Install()
Perform any work needed when the plugin is first installed (for example, creating database tables)...
ConfigSettingOverride($SettingName, $Value)
Set override for configuration setting, that will be returned regardless of the current saved configu...
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.
GetConfigSettingType($SettingName)
Get type of a plugin configuration setting.
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.
GetConfigSettingParameters($SettingName)
Get plugin configuration setting parameters.
$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.
GetSavedConfigSetting($SettingName)
Get plugin configuration setting, ignoring any override value.
$CfgPage
Name of configuration page for plugin.
IsEnabled($NewValue=NULL, $Persistent=TRUE)
Get/set whether the plugin is enabled.
$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.
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.