45 if (0 == strcmp($a->Name, $b->Name)) {
47 $rc = strcmp($a->Version, $b->Version);
56 foreach ($a->Dependency as $val) {
58 if ($val == $b->Name) {
63 foreach ($b->Dependency as $val) {
65 if ($val == $a->Name) {
72 if ($a->PluginLevel > $b->PluginLevel) {
74 } elseif ($a->PluginLevel < $b->PluginLevel) {
79 $rc = count($a->Dependency) - count($b->Dependency);
89 function plugin_disable($Level)
96 $LoginFlag = empty($_SESSION[
'User']);
97 foreach ($Plugins as $pluginName => &$P) {
98 if ($P->State == PLUGIN_STATE_INVALID) {
102 if ($P->DBaccess > $Level) {
107 unset($Plugins[$pluginName]);
135 foreach ($Plugins as &$P) {
136 if (empty($P->Dependency[0])) {
139 $DepArray[$P->Name] = array();
140 $D = &$DepArray[$P->Name];
141 for ($j = 0; $j < count($P->Dependency); $j ++) {
142 $D[$P->Dependency[$j]] = $P->PluginLevel;
149 foreach ($DepArray as $A => $a) {
150 $Aa = &$DepArray[$A];
155 foreach ($DepArray as $B => $b) {
157 if (! empty($Bb[$A])) {
159 $DepArray[$B] = array_merge($Aa, $Bb);
165 foreach ($Plugins as &$P) {
166 if (empty($P->Dependency[0])) {
169 $P->Dependency = array_keys($DepArray[$P->Name]);
174 uasort($Plugins,
'plugin_cmp');
185 function plugin_find_id($pluginName)
191 if (array_key_exists($pluginName, $Plugins)) {
192 $plugin = $Plugins[$pluginName];
193 return $plugin->State === PLUGIN_STATE_READY ? $pluginName : - 1;
210 return array_key_exists($pluginName, $Plugins) ? $Plugins[$pluginName] : null;
220 function plugin_preinstall()
227 foreach (array_keys($Plugins) as $pluginName) {
228 if (array_key_exists($pluginName, $Plugins)) {
229 $Plugins[$pluginName]->preInstall();
237 function plugin_postinstall()
242 foreach ($Plugins as &$plugin) {
243 $plugin->postInstall();
254 $ModsEnabledDir =
"$SYSCONFDIR/mods-enabled";
258 if (is_dir($ModsEnabledDir)) {
259 foreach (glob(
"$ModsEnabledDir/*") as $ModDirPath) {
264 $targetPath = $ModDirPath . $subdir;
266 if (is_dir($targetPath)) {
267 foreach (glob(
"$targetPath/*.php") as $phpFile) {
268 if (! strstr($phpFile,
'ndex.php')) {
269 include_once (
"$phpFile");
282 function plugin_unload()
287 foreach ($Plugins as $key => $plugin) {
291 if (empty($plugin)) {
295 $plugin->unInstall();
304 function register_plugin(
Plugin $plugin)
312 throw new \Exception(
"cannot create module without name");
315 if (array_key_exists($name, $Plugins)) {
316 throw new \Exception(
"duplicate definition of plugin with name $name");
319 $Plugins[$name] = $plugin;
330 $output = $classname .
" {\n";
331 foreach ($vars as $name => $value) {
332 if (! is_object($value)) {
333 $representation = print_r($value,
true);
334 $lines = explode(
"\n", $representation);
335 $lines = array_map(
function ($line){
338 $representation =
trim(implode(
"\n", $lines));
340 $output .=
" $name: " . $representation .
"\n";
plugin_cmp($a, $b)
Sort compare function.
getStringRepresentation($vars, $classname)
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
plugin_load()
Load every module ui found in mods-enabled.
global $Plugins
Global plugins array.
char * trim(char *ptext)
Trimming whitespace.
plugin_sort()
Sort the global $Plugins by dependencies. This way plugins get loaded in the correct order...