CWIS Developer Documentation

- Home
- Main Page
- Classes
- Files

- File List
- File Members

PluginManager.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: PluginManager.php
4 #
5 # Part of the ScoutLib application support library
6 # Copyright 2009-2013 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu
8 #
9
13 class PluginManager {
14
15 # ---- PUBLIC INTERFACE --------------------------------------------------
16
24 function __construct($AppFramework, $PluginDirectories)
25 {
26 # save framework and directory list for later use
27 $this->AF = $AppFramework;
28 $this->DirsToSearch = $PluginDirectories;
29
30 # get our own database handle
31 $this->DB = new Database();
32
33 # hook into events to load plugin PHP and HTML files
34 $this->AF->HookEvent("EVENT_PHP_FILE_LOAD", array($this, "FindPluginPhpFile"),
35 ApplicationFramework::ORDER_LAST);
36 $this->AF->HookEvent("EVENT_HTML_FILE_LOAD", array($this, "FindPluginHtmlFile"),
37 ApplicationFramework::ORDER_LAST);
38
39 # tell PluginCaller helper object how to get to us
40 PluginCaller::$Manager = $this;
41 }
42
53 function LoadPlugins($ForcePluginConfigOptLoad = FALSE)
54 {
55 # clear any existing errors/status
56 $this->ErrMsgs = array();
57 $this->StatusMsgs = array();
58
59 # load list of all base plugin files
60 $this->FindPlugins($this->DirsToSearch);
61
62 # for each plugin found
63 foreach ($this->PluginNames as $PluginName)
64 {
65 # bring in plugin class file
66 include_once($this->PluginFiles[$PluginName]);
67
68 # if plugin class was defined by file
69 if (class_exists($PluginName))
70 {
71 # if plugin class is a valid descendant of base plugin class
72 $Plugin = new $PluginName;
73 if (is_subclass_of($Plugin, "Plugin"))
74 {
75 # set hooks needed for plugin to access plugin manager services
76 $Plugin->SetCfgSaveCallback(array(__CLASS__, "CfgSaveCallback"));
77
78 # register the plugin
79 $this->Plugins[$PluginName] = $Plugin;
80 $this->PluginEnabled[$PluginName] = TRUE;
81 $this->Plugins[$PluginName]->Register();
82
83 # check required plugin attributes
84 $Attribs[$PluginName] = $this->Plugins[$PluginName]->GetAttributes();
85 if (!strlen($Attribs[$PluginName]["Name"]))
86 {
87 $this->ErrMsgs[$PluginName][] = "Plugin <b>".$PluginName."</b>"
88 ." could not be loaded because it"
89 ." did not have a <i>Name</i> attribute set.";
90 unset($this->PluginEnabled[$PluginName]);
91 unset($this->Plugins[$PluginName]);
92 }
93 if (!strlen($Attribs[$PluginName]["Version"]))
94 {
95 $this->ErrMsgs[$PluginName][] = "Plugin <b>".$PluginName."</b>"
96 ." could not be loaded because it"
97 ." did not have a <i>Version</i> attribute set.";
98 unset($this->PluginEnabled[$PluginName]);
99 unset($this->Plugins[$PluginName]);
100 }
101 }
102 else
103 {
104 $this->ErrMsgs[$PluginName][] = "Plugin <b>".$PluginName."</b>"
105 ." could not be loaded because <i>".$PluginName."</i> was"
106 ." not a subclass of base <i>Plugin</i> class";
107 }
108 }
109 else
110 {
111 $this->ErrMsgs[$PluginName][] = "Expected class <i>".$PluginName
112 ."</i> not found in plugin file <i>"
113 .$this->PluginFiles[$PluginName]."</i>";
114 }
115 }
116
117 # check plugin dependencies
118 $this->CheckDependencies();
119
120 # load plugin configurations
121 $this->DB->Query("SELECT BaseName,Cfg FROM PluginInfo");
122 $Cfgs = $this->DB->FetchColumn("Cfg", "BaseName");
123
124 # for each plugin
125 foreach ($this->Plugins as $PluginName => $Plugin)
126 {
127 # if plugin is enabled
128 if ($this->PluginEnabled[$PluginName])
129 {
130 # if plugin has its own subdirectory
131 if ($this->PluginHasDir[$PluginName])
132 {
133 # if plugin has its own object directory
134 $Dir = dirname($this->PluginFiles[$PluginName]);
135 if (is_dir($Dir."/objects"))
136 {
137 # add object directory to class autoloading list
138 ApplicationFramework::AddObjectDirectory($Dir."/objects");
139 }
140 else
141 {
142 # add plugin directory to class autoloading list
143 ApplicationFramework::AddObjectDirectory($Dir);
144 }
145 }
146
147 # set configuration values if available
148 if (isset($Cfgs[$PluginName]))
149 {
150 $Plugin->SetAllCfg(unserialize($Cfgs[$PluginName]));
151 }
152
153 # install or upgrade plugins if needed
154 $this->InstallPlugin($Plugin);
155 }
156 }
157
158 # check plugin dependencies again in case an install or upgrade failed
159 $this->CheckDependencies();
160
161 # set up plugin configuration options
162 foreach ($this->Plugins as $PluginName => $Plugin)
163 {
164 if ($ForcePluginConfigOptLoad || $this->PluginEnabled[$PluginName])
165 {
166 $ErrMsg = $Plugin->SetUpConfigOptions();
167 if ($ErrMsg !== NULL)
168 {
169 $this->ErrMsgs[$PluginName][] = "Configuration option setup"
170 ." failed for plugin <b>".$PluginName."</b>: <i>"
171 .$ErrMsg."</i>";
172 $this->PluginEnabled[$PluginName] = FALSE;
173 }
174 }
175 }
176
177 # initialize enabled plugins
178 foreach ($this->Plugins as $PluginName => $Plugin)
179 {
180 if ($this->PluginEnabled[$PluginName])
181 {
182 $ErrMsg = $Plugin->Initialize();
183 if ($ErrMsg !== NULL)
184 {
185 $this->ErrMsgs[$PluginName][] = "Initialization failed for"
186 ." plugin <b>".$PluginName."</b>: <i>".$ErrMsg."</i>";
187 $this->PluginEnabled[$PluginName] = FALSE;
188 }
189 }
190 }
191
192 # register any events declared by enabled plugins
193 foreach ($this->Plugins as $PluginName => $Plugin)
194 {
195 if ($this->PluginEnabled[$PluginName])
196 {
197 $Events = $Plugin->DeclareEvents();
198 if (count($Events)) { $this->AF->RegisterEvent($Events); }
199 }
200 }
201
202 # hook enabled plugins to events
203 foreach ($this->Plugins as $PluginName => $Plugin)
204 {
205 if ($this->PluginEnabled[$PluginName])
206 {
207 $EventsToHook = $Plugin->HookEvents();
208 if (count($EventsToHook))
209 {
210 foreach ($EventsToHook as $EventName => $PluginMethods)
211 {
212 if (!is_array($PluginMethods))
213 { $PluginMethods = array($PluginMethods); }
214
215 foreach ($PluginMethods as $PluginMethod)
216 {
217 if ($this->AF->IsStaticOnlyEvent($EventName))
218 {
219 $Caller = new PluginCaller($PluginName, $PluginMethod);
220 $Result = $this->AF->HookEvent(
221 $EventName, array($Caller, "CallPluginMethod"));
222 }
223 else
224 {
225 $Result = $this->AF->HookEvent(
226 $EventName, array($Plugin, $PluginMethod));
227 }
228 if ($Result === FALSE)
229 {
230 $this->ErrMsgs[$PluginName][] =
231 "Unable to hook requested event <i>"
232 .$EventName."</i> for plugin <b>"
233 .$PluginName."</b>";
234 }
235 }
236 }
237 }
238 }
239 }
240
241 # report to caller whether any problems were encountered
242 return count($this->ErrMsgs) ? FALSE : TRUE;
243 }
244
250 function GetErrorMessages()
251 {
252 return $this->ErrMsgs;
253 }
254
261 function GetStatusMessages()
262 {
263 return $this->StatusMsgs;
264 }
265
271 function GetPlugin($PluginName)
272 {
273 return isset($this->Plugins[$PluginName])
274 ? $this->Plugins[$PluginName] : NULL;
275 }
276
284 function GetPluginForCurrentPage()
285 {
286 return $this->GetPlugin($this->PageFilePlugin);
287 }
288
293 function GetPluginAttributes()
294 {
295 $Info = array();
296 foreach ($this->Plugins as $PluginName => $Plugin)
297 {
298 $Info[$PluginName] = $Plugin->GetAttributes();
299 $Info[$PluginName]["Enabled"] =
300 isset($this->PluginInfo[$PluginName]["Enabled"])
301 ? $this->PluginInfo[$PluginName]["Enabled"] : FALSE;
302 $Info[$PluginName]["Installed"] =
303 isset($this->PluginInfo[$PluginName]["Installed"])
304 ? $this->PluginInfo[$PluginName]["Installed"] : FALSE;
305 $Info[$PluginName]["ClassFile"] = $this->PluginFiles[$PluginName];
306 }
307 return $Info;
308 }
309
315 function GetDependents($PluginName)
316 {
317 $Dependents = array();
318 $AllAttribs = $this->GetPluginAttributes();
319 foreach ($AllAttribs as $Name => $Attribs)
320 {
321 if (array_key_exists($PluginName, $Attribs["Requires"]))
322 {
323 $Dependents[] = $Name;
324 $SubDependents = $this->GetDependents($Name);
325 $Dependents = array_merge($Dependents, $SubDependents);
326 }
327 }
328 return $Dependents;
329 }
330
335 function GetActivePluginList()
336 {
337 return array_keys($this->PluginEnabled, 1);
338 }
339
346 function PluginEnabled($PluginName, $NewValue = NULL)
347 {
348 # if an enabled/disabled value was supplied
349 if ($NewValue !== NULL)
350 {
351 # if enabled/disabled status has changed for plugin
352 if (($NewValue && !$this->PluginEnabled[$PluginName]["Enabled"])
353 || (!$NewValue && $this->PluginEnabled[$PluginName]["Enabled"]))
354 {
355 $Info = $this->Plugins[$PluginName]->GetAttributes();
356 $this->DB->Query("UPDATE PluginInfo"
357 ." SET Enabled = ".($NewValue ? "1" : "0")
358 ." WHERE BaseName = '".addslashes($PluginName)."'");
359 $this->PluginEnabled[$PluginName] = $NewValue;
360 $this->PluginInfo[$PluginName]["Enabled"] = $NewValue;
361 $this->StatusMsgs[$PluginName][] = "Plugin <i>"
362 .$Info["Name"]."</i> "
363 .($NewValue ? "enabled" : "disabled").".";
364 }
365 }
366 return array_key_exists($PluginName, $this->PluginEnabled)
367 && $this->PluginEnabled[$PluginName];
368 }
369
375 function UninstallPlugin($PluginName)
376 {
377 # assume success
378 $Result = NULL;
379
380 # if plugin is installed
381 if ($this->PluginInfo[$PluginName]["Installed"])
382 {
383 # call uninstall method for plugin
384 $Result = $this->Plugins[$PluginName]->Uninstall();
385
386 # if plugin uninstall method succeeded
387 if ($Result === NULL)
388 {
389 # remove plugin info from database
390 $this->DB->Query("DELETE FROM PluginInfo"
391 ." WHERE BaseName = '".addslashes($PluginName)."'");
392
393 # drop our data for the plugin
394 unset($this->Plugins[$PluginName]);
395 unset($this->PluginInfo[$PluginName]);
396 unset($this->PluginEnabled[$PluginName]);
397 unset($this->PluginNames[$PluginName]);
398 unset($this->PluginFiles[$PluginName]);
399 }
400 }
401
402 # report results (if any) to caller
403 return $Result;
404 }
405
406
407 # ---- PRIVATE INTERFACE -------------------------------------------------
408
409 private $Plugins = array();
410 private $PluginFiles = array();
411 private $PluginNames = array();
412 private $PluginHasDir = array();
413 private $PluginInfo = array();
414 private $PluginEnabled = array();
415 private $PageFilePlugin = NULL;
416 private $AF;
417 private $DirsToSearch;
418 private $ErrMsgs = array();
419 private $StatusMsgs = array();
420 private $DB;
421
427 private function FindPlugins($DirsToSearch)
428 {
429 # for each directory
430 foreach ($DirsToSearch as $Dir)
431 {
432 # if directory exists
433 if (is_dir($Dir))
434 {
435 # for each file in directory
436 $FileNames = scandir($Dir);
437 foreach ($FileNames as $FileName)
438 {
439 # if file looks like base plugin file
440 if (preg_match("/^[a-zA-Z_][a-zA-Z0-9_]*\.php$/", $FileName))
441 {
442 # add file to list
443 $PluginName = preg_replace("/\.php$/", "", $FileName);
444 $this->PluginNames[$PluginName] = $PluginName;
445 $this->PluginFiles[$PluginName] = $Dir."/".$FileName;
446 $this->PluginHasDir[$PluginName] = FALSE;
447 }
448 # else if file looks like plugin directory
449 elseif (is_dir($Dir."/".$FileName)
450 && preg_match("/^[a-zA-Z_][a-zA-Z0-9_]*/", $FileName))
451 {
452 # if there is a base plugin file in the directory
453 $PluginName = $FileName;
454 $PluginFile = $Dir."/".$PluginName."/".$PluginName.".php";
455 if (file_exists($PluginFile))
456 {
457 # add plugin and directory to lists
458 $this->PluginNames[$PluginName] = $PluginName;
459 $this->PluginFiles[$PluginName] = $PluginFile;
460 $this->PluginHasDir[$PluginName] = TRUE;
461 }
462 # else if we don't already have a base plugin file
463 elseif (!array_key_exists($PluginName, $this->PluginFiles))
464 {
465 $this->ErrMsgs[$PluginName][] =
466 "Expected plugin file <i>".$PluginName.".php</i> not"
467 ." found in plugin subdirectory <i>"
468 .$Dir."/".$PluginName."</i>";
469 }
470 }
471 }
472 }
473 }
474 }
475
481 private function InstallPlugin($Plugin)
482 {
483 # cache all plugin info from database
484 if (count($this->PluginInfo) == 0)
485 {
486 $this->DB->Query("SELECT * FROM PluginInfo");
487 while ($Row = $this->DB->FetchRow())
488 {
489 $this->PluginInfo[$Row["BaseName"]] = $Row;
490 }
491 }
492
493 # if plugin was not found in database
494 $PluginName = get_class($Plugin);
495 $Attribs = $Plugin->GetAttributes();
496 if (!isset($this->PluginInfo[$PluginName]))
497 {
498 # add plugin to database
499 $this->DB->Query("INSERT INTO PluginInfo"
500 ." (BaseName, Version, Installed, Enabled)"
501 ." VALUES ('".addslashes($PluginName)."', "
502 ." '".addslashes($Attribs["Version"])."', "
503 ."0, "
504 ." ".($Attribs["EnabledByDefault"] ? 1 : 0).")");
505
506 # read plugin settings back in
507 $this->DB->Query("SELECT * FROM PluginInfo"
508 ." WHERE BaseName = '".addslashes($PluginName)."'");
509 $this->PluginInfo[$PluginName] = $this->DB->FetchRow();
510 }
511
512 # store plugin settings for later use
513 $this->PluginEnabled[$PluginName] = $this->PluginInfo[$PluginName]["Enabled"];
514
515 # if plugin is enabled
516 if ($this->PluginEnabled[$PluginName])
517 {
518 # if plugin has not been installed
519 if (!$this->PluginInfo[$PluginName]["Installed"])
520 {
521 # set default values if present
522 $Attribs = $Plugin->GetAttributes();
523 if (isset($Attribs["CfgSetup"]))
524 {
525 foreach ($Attribs["CfgSetup"] as $CfgValName => $CfgSetup)
526 {
527 if (isset($CfgSetup["Default"]))
528 {
529 $Plugin->ConfigSetting($CfgValName,
530 $CfgSetup["Default"]);
531 }
532 }
533 }
534
535 # install plugin
536 $ErrMsg = $Plugin->Install();
537
538 # if install succeeded
539 if ($ErrMsg == NULL)
540 {
541 # mark plugin as installed
542 $this->DB->Query("UPDATE PluginInfo SET Installed = 1"
543 ." WHERE BaseName = '".addslashes($PluginName)."'");
544 $this->PluginInfo[$PluginName]["Installed"] = 1;
545 }
546 else
547 {
548 # disable plugin
549 $this->PluginEnabled[$PluginName] = FALSE;
550
551 # record error message about installation failure
552 $this->ErrMsgs[$PluginName][] = "Installation of plugin <b>"
553 .$PluginName."</b> failed: <i>".$ErrMsg."</i>";;
554 }
555 }
556 else
557 {
558 # if plugin version is newer than version in database
559 if (version_compare($Attribs["Version"],
560 $this->PluginInfo[$PluginName]["Version"]) == 1)
561 {
562 # set default values for any new configuration settings
563 $Attribs = $Plugin->GetAttributes();
564 if (isset($Attribs["CfgSetup"]))
565 {
566 foreach ($Attribs["CfgSetup"] as $CfgValName => $CfgSetup)
567 {
568 if (isset($CfgSetup["Default"])
569 && ($Plugin->ConfigSetting(
570 $CfgValName) === NULL))
571 {
572 $Plugin->ConfigSetting($CfgValName,
573 $CfgSetup["Default"]);
574 }
575 }
576 }
577
578 # upgrade plugin
579 $ErrMsg = $Plugin->Upgrade(
580 $this->PluginInfo[$PluginName]["Version"]);
581
582 # if upgrade succeeded
583 if ($ErrMsg == NULL)
584 {
585 # update plugin version in database
586 $this->DB->Query("UPDATE PluginInfo"
587 ." SET Version = '".addslashes($Attribs["Version"])."'"
588 ." WHERE BaseName = '".addslashes($PluginName)."'");
589 $this->PluginInfo[$PluginName]["Version"] = $Attribs["Version"];
590 }
591 else
592 {
593 # disable plugin
594 $this->PluginEnabled[$PluginName] = FALSE;
595
596 # record error message about upgrade failure
597 $this->ErrMsgs[$PluginName][] = "Upgrade of plugin <b>"
598 .$PluginName."</b> from version <i>"
599 .addslashes($this->PluginInfo[$PluginName]["Version"])
600 ."</i> to version <i>"
601 .addslashes($Attribs["Version"])."</i> failed: <i>"
602 .$ErrMsg."</i>";
603 }
604 }
605 # else if plugin version is older than version in database
606 elseif (version_compare($Attribs["Version"],
607 $this->PluginInfo[$PluginName]["Version"]) == -1)
608 {
609 # disable plugin
610 $this->PluginEnabled[$PluginName] = FALSE;
611
612 # record error message about version conflict
613 $this->ErrMsgs[$PluginName][] = "Plugin <b>"
614 .$PluginName."</b> is older (<i>"
615 .addslashes($Attribs["Version"])
616 ."</i>) than previously-installed version (<i>"
617 .addslashes($this->PluginInfo[$PluginName]["Version"])."</i>).";
618 }
619 }
620 }
621 }
622
627 private function CheckDependencies()
628 {
629 # look until all enabled plugins check out okay
630 do
631 {
632 # start out assuming all plugins are okay
633 $AllOkay = TRUE;
634
635 # for each plugin
636 foreach ($this->Plugins as $PluginName => $Plugin)
637 {
638 # if plugin is currently enabled
639 if ($this->PluginEnabled[$PluginName])
640 {
641 # load plugin attributes
642 if (!isset($Attribs[$PluginName]))
643 {
644 $Attribs[$PluginName] =
645 $this->Plugins[$PluginName]->GetAttributes();
646 }
647
648 # for each dependency for this plugin
649 foreach ($Attribs[$PluginName]["Requires"]
650 as $ReqName => $ReqVersion)
651 {
652 # handle PHP version requirements
653 if ($ReqName == "PHP")
654 {
655 if (version_compare($ReqVersion, phpversion(), ">"))
656 {
657 $this->ErrMsgs[$PluginName][] = "PHP version "
658 ."<i>".$ReqVersion."</i>"
659 ." required by <b>".$PluginName."</b>"
660 ." was not available. (Current PHP version"
661 ." is <i>".phpversion()."</i>.)";
662 }
663 }
664 # handle PHP extension requirements
665 elseif (preg_match("/^PHPX_/", $ReqName))
666 {
667 list($Dummy, $ExtensionName) = explode("_", $ReqName, 2);
668 if (!extension_loaded($ExtensionName))
669 {
670 $this->ErrMsgs[$PluginName][] = "PHP extension "
671 ."<i>".$ExtensionName."</i>"
672 ." required by <b>".$PluginName."</b>"
673 ." was not available.";
674 }
675 }
676 # handle dependencies on other plugins
677 else
678 {
679 # load plugin attributes if not already loaded
680 if (isset($this->Plugins[$ReqName])
681 && !isset($Attribs[$ReqName]))
682 {
683 $Attribs[$ReqName] =
684 $this->Plugins[$ReqName]->GetAttributes();
685 }
686
687 # if target plugin is not present or is disabled or is too old
688 if (!isset($this->PluginEnabled[$ReqName])
689 || !$this->PluginEnabled[$ReqName]
690 || (version_compare($ReqVersion,
691 $Attribs[$ReqName]["Version"], ">")))
692 {
693 # add error message and disable plugin
694 $this->ErrMsgs[$PluginName][] = "Plugin <i>"
695 .$ReqName." ".$ReqVersion."</i>"
696 ." required by <b>".$PluginName."</b>"
697 ." was not available.";
698 $this->PluginEnabled[$PluginName] = FALSE;
699
700 # set flag indicating plugin did not check out
701 $AllOkay = FALSE;
702 }
703 }
704 }
705 }
706 }
707 } while ($AllOkay == FALSE);
708 }
709
718 function FindPluginPhpFile($PageName)
719 {
720 # build list of possible locations for file
721 $Locations = array(
722 "local/plugins/%PLUGIN%/pages/%PAGE%.php",
723 "plugins/%PLUGIN%/pages/%PAGE%.php",
724 "local/plugins/%PLUGIN%/%PAGE%.php",
725 "plugins/%PLUGIN%/%PAGE%.php",
726 );
727
728 # look for file and return (possibly) updated page to caller
729 return $this->FindPluginPageFile($PageName, $Locations);
730 }
741 function FindPluginHtmlFile($PageName)
742 {
743 # build list of possible locations for file
744 $Locations = array(
745 "local/plugins/%PLUGIN%/interface/%ACTIVEUI%/%PAGE%.html",
746 "plugins/%PLUGIN%/interface/%ACTIVEUI%/%PAGE%.html",
747 "local/plugins/%PLUGIN%/interface/default/%PAGE%.html",
748 "plugins/%PLUGIN%/interface/default/%PAGE%.html",
749 "local/plugins/%PLUGIN%/%PAGE%.html",
750 "plugins/%PLUGIN%/%PAGE%.html",
751 );
752
753 # find HTML file
754 $Params = $this->FindPluginPageFile($PageName, $Locations);
755
756 # if plugin HTML file was found
757 if ($Params["PageName"] != $PageName)
758 {
759 # add subdirectories for plugin to search paths
760 $Dir = preg_replace("%^local/%", "", dirname($Params["PageName"]));
761 $GLOBALS["AF"]->AddImageDirectories(array(
762 "local/".$Dir."/images",
763 $Dir."/images",
764 ));
765 $GLOBALS["AF"]->AddIncludeDirectories(array(
766 "local/".$Dir."/include",
767 $Dir."/include",
768 ));
769 $GLOBALS["AF"]->AddFunctionDirectories(array(
770 "local/".$Dir."/include",
771 $Dir."/include",
772 ));
773 }
774
775 # return possibly revised HTML file name to caller
776 return $Params;
777 }
788 private function FindPluginPageFile($PageName, $Locations)
789 {
790 # set up return value assuming we will not find plugin page file
791 $ReturnValue["PageName"] = $PageName;
792
793 # look for plugin name and plugin page name in base page name
794 preg_match("/P_([A-Za-z].[A-Za-z0-9]*)_([A-Za-z0-9_-]+)/", $PageName, $Matches);
795
796 # if base page name contained name of enabled plugin with its own subdirectory
797 if ((count($Matches) == 3)
798 && $this->PluginEnabled[$Matches[1]]
799 && $this->PluginHasDir[$Matches[1]])
800 {
801 # for each possible location
802 $ActiveUI = $GLOBALS["AF"]->ActiveUserInterface();
803 $PluginName = $Matches[1];
804 $PageName = $Matches[2];
805 foreach ($Locations as $Loc)
806 {
807 # make any needed substitutions into path
808 $FileName = str_replace(array("%ACTIVEUI%", "%PLUGIN%", "%PAGE%"),
809 array($ActiveUI, $PluginName, $PageName), $Loc);
810
811 # if file exists in this location
812 if (file_exists($FileName))
813 {
814 # set return value to contain full plugin page file name
815 $ReturnValue["PageName"] = $FileName;
816
817 # save plugin name as home of current page
818 $this->PageFilePlugin = $PluginName;
819
820 # set G_Plugin to plugin associated with current page
821 $GLOBALS["G_Plugin"] = $this->GetPluginForCurrentPage();
822
823 # stop looking
824 break;
825 }
826 }
827 }
828
829 # return array containing page name or page file name to caller
830 return $ReturnValue;
831 }
832
840 static function CfgSaveCallback($BaseName, $Cfg)
841 {
842 $DB = new Database();
843 $DB->Query("UPDATE PluginInfo SET Cfg = '".addslashes(serialize($Cfg))
844 ."' WHERE BaseName = '".addslashes($BaseName)."'");
845 }
847 }
848
860 class PluginCaller {
861
868 function __construct($PluginName, $MethodName)
869 {
870 $this->PluginName = $PluginName;
871 $this->MethodName = $MethodName;
872 }
873
879 function CallPluginMethod()
880 {
881 $Args = func_get_args();
882 $Plugin = self::$Manager->GetPlugin($this->PluginName);
883 return call_user_func_array(array($Plugin, $this->MethodName), $Args);
884 }
885
890 function GetCallbackAsText()
891 {
892 return $this->PluginName."::".$this->MethodName;
893 }
894
900 function __sleep()
901 {
902 return array("PluginName", "MethodName");
903 }
904
906 static public $Manager;
907
908 private $PluginName;
909 private $MethodName;
910 }
913 ?>
PluginManager\LoadPlugins
LoadPlugins($ForcePluginConfigOptLoad=FALSE)
Load and initialize plugins.
Definition: PluginManager.php:53
PluginManager\GetErrorMessages
GetErrorMessages()
Retrieve any error messages generated during plugin loading.
Definition: PluginManager.php:250
PluginCaller\__sleep
__sleep()
Sleep method, specifying which values are to be saved when we are serialized.
Definition: PluginManager.php:900
PluginCaller\__construct
__construct($PluginName, $MethodName)
Class constructor, which stores the plugin name and the name of the method to be called.
Definition: PluginManager.php:868
PluginManager
Manager to load and invoke plugins.
Definition: PluginManager.php:13
PluginManager\CfgSaveCallback
static CfgSaveCallback($BaseName, $Cfg)
Definition: PluginManager.php:840
Database
SQL database abstraction object with smart query caching.
Definition: Axis--Database.php:22
PluginManager\UninstallPlugin
UninstallPlugin($PluginName)
Uninstall plugin and (optionally) delete any associated data.
Definition: PluginManager.php:375
PluginManager\GetDependents
GetDependents($PluginName)
Returns a list of plugins dependent on the specified plugin.
Definition: PluginManager.php:315
PluginManager\FindPluginPhpFile
FindPluginPhpFile($PageName)
Definition: PluginManager.php:718
ApplicationFramework\AddObjectDirectory
static AddObjectDirectory($Dir, $Prefix="", $ClassPattern=NULL, $ClassReplacement=NULL)
Add directory to be searched for object files when autoloading.
Definition: ApplicationFramework.php:148
PluginManager\GetActivePluginList
GetActivePluginList()
Get list of active (i.e.
Definition: PluginManager.php:335
PluginManager\FindPluginHtmlFile
FindPluginHtmlFile($PageName)
Definition: PluginManager.php:741
PluginManager\GetPluginAttributes
GetPluginAttributes()
Retrieve info about currently loaded plugins.
Definition: PluginManager.php:293
PluginManager\GetPlugin
GetPlugin($PluginName)
Retrieve specified plugin.
Definition: PluginManager.php:271
PHP
PHP
Definition: OAIClient.php:39
PluginManager\PluginEnabled
PluginEnabled($PluginName, $NewValue=NULL)
Get/set whether specified plugin is enabled.
Definition: PluginManager.php:346
PluginManager\__construct
__construct($AppFramework, $PluginDirectories)
PluginManager class constructor.
Definition: PluginManager.php:24
PluginManager\GetPluginForCurrentPage
GetPluginForCurrentPage()
Retrieve plugin for current page (if any).
Definition: PluginManager.php:284
PluginCaller\GetCallbackAsText
GetCallbackAsText()
Get full method name as a text string.
Definition: PluginManager.php:890
PluginCaller
Definition: PluginManager.php:860
ApplicationFramework\ORDER_LAST
const ORDER_LAST
Run hooked function last (i.e.
Definition: ApplicationFramework.php:1412
PluginManager\GetStatusMessages
GetStatusMessages()
Get/set any status messages generated during plugin loading or via plugin method calls.
Definition: PluginManager.php:261
PluginCaller\$Manager
static $Manager
PluginManager to use to retrieve appropriate plugins.
Definition: PluginManager.php:906
PluginCaller\CallPluginMethod
CallPluginMethod()
Call the method that was specified in our constructor.
Definition: PluginManager.php:879