35 if (0 == strcmp($a->Name, $b->Name)) {
37 $rc = strcmp($a->Version, $b->Version);
46 foreach ($a->Dependency as $val) {
48 if ($val == $b->Name) {
53 foreach ($b->Dependency as $val) {
55 if ($val == $a->Name) {
62 if ($a->PluginLevel > $b->PluginLevel) {
64 } elseif ($a->PluginLevel < $b->PluginLevel) {
69 $rc = count($a->Dependency) - count($b->Dependency);
79 function plugin_disable($Level)
86 $LoginFlag = empty($_SESSION[
'User']);
87 foreach (
$Plugins as $pluginName => &$P) {
88 if ($P->State == PLUGIN_STATE_INVALID) {
92 if ($P->DBaccess > $Level) {
126 if (empty($P->Dependency[0])) {
129 $DepArray[$P->Name] = array();
130 $D = &$DepArray[$P->Name];
131 for ($j = 0; $j < count($P->Dependency); $j ++) {
132 $D[$P->Dependency[$j]] = $P->PluginLevel;
139 foreach ($DepArray as $A => $a) {
140 $Aa = &$DepArray[$A];
145 foreach ($DepArray as $B => $b) {
147 if (! empty($Bb[$A])) {
149 $DepArray[$B] = array_merge($Aa, $Bb);
156 if (empty($P->Dependency[0])) {
159 $P->Dependency = array_keys($DepArray[$P->Name]);
175 function plugin_find_id($pluginName)
181 if (array_key_exists($pluginName,
$Plugins)) {
183 return $plugin->State === PLUGIN_STATE_READY ? $pluginName : - 1;
200 return array_key_exists($pluginName,
$Plugins) ?
$Plugins[$pluginName] :
null;
210 function plugin_preinstall()
217 foreach (array_keys(
$Plugins) as $pluginName) {
218 if (array_key_exists($pluginName,
$Plugins)) {
219 $Plugins[$pluginName]->preInstall();
227 function plugin_postinstall()
233 $plugin->postInstall();
244 $ModsEnabledDir =
"$SYSCONFDIR/mods-enabled";
248 if (is_dir($ModsEnabledDir)) {
249 foreach (glob(
"$ModsEnabledDir/*") as $ModDirPath) {
254 $targetPath = $ModDirPath . $subdir;
256 if (is_dir($targetPath)) {
257 foreach (glob(
"$targetPath/*.php") as $phpFile) {
258 if (! strstr($phpFile,
'ndex.php')) {
259 include_once (
"$phpFile");
272 function plugin_unload()
277 foreach (
$Plugins as $key => $plugin) {
281 if (empty($plugin)) {
285 $plugin->unInstall();
294 function register_plugin(
Plugin $plugin)
299 $name = $plugin->getName();
302 throw new \Exception(
"cannot create module without name");
305 if (array_key_exists($name,
$Plugins)) {
306 throw new \Exception(
"duplicate definition of plugin with name $name");
320 $output = $classname .
" {\n";
321 foreach ($vars as $name => $value) {
322 if (! is_object($value)) {
323 $representation = print_r($value,
true);
324 $lines = explode(
"\n", $representation);
325 $lines = array_map(
function ($line){
328 $representation =
trim(implode(
"\n", $lines));
330 $output .=
" $name: " . $representation .
"\n";
global $Plugins
Global plugins array.
plugin_cmp($a, $b)
Sort compare function.
plugin_load()
Load every module ui found in mods-enabled.
getStringRepresentation($vars, $classname)
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
plugin_sort()
Sort the global $Plugins by dependencies. This way plugins get loaded in the correct order.
char * trim(char *ptext)
Trimming whitespace.