XOOPS  2.6.0
Plugin.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  */
11 
12 namespace Xoops\Module;
13 
21 class Plugin
22 {
30  public static function getPlugin($dirname, $pluginName = 'system', $force = false)
31  {
32  $inactiveModules = false;
33  if ($force) {
34  $inactiveModules = array($dirname);
35  }
36  $available = self::getPlugins($pluginName, $inactiveModules);
37  if (!in_array($dirname, array_keys($available))) {
38  return false;
39  }
40  return $available[$dirname];
41  }
42 
49  public static function getPlugins($pluginName = 'system', $inactiveModules = false)
50  {
51  static $plugins = array();
52  if (!isset($plugins[$pluginName])) {
53  $plugins[$pluginName] = array();
55 
56  //Load interface for this plugin
57  if (!\XoopsLoad::loadFile($xoops->path("modules/{$pluginName}/class/plugin/interface.php"))) {
58  return $plugins[$pluginName];
59  }
60 
61  $dirnames = $xoops->getActiveModules();
62  if (is_array($inactiveModules)) {
63  $dirnames = array_merge($dirnames, $inactiveModules);
64  }
65  foreach ($dirnames as $dirname) {
66  if (\XoopsLoad::loadFile($xoops->path("modules/{$dirname}/class/plugin/{$pluginName}.php"))) {
67  $className = '\\' . ucfirst($dirname) . ucfirst($pluginName) . 'Plugin';
68  $interface = '\\' . ucfirst($pluginName) . 'PluginInterface';
69  $class = new $className($dirname);
70  if ($class instanceof \Xoops\Module\Plugin\PluginAbstract && $class instanceof $interface) {
71  $plugins[$pluginName][$dirname] = $class;
72  }
73  }
74  }
75  }
76  return $plugins[$pluginName];
77  }
78 }
static getInstance()
Definition: Xoops.php:160
static getPlugin($dirname, $pluginName= 'system', $force=false)
Definition: Plugin.php:30
$xoops
Definition: admin.php:25
static getPlugins($pluginName= 'system', $inactiveModules=false)
Definition: Plugin.php:49
$dirname
Definition: backend.php:38
static loadFile($file, $once=true)
Definition: xoopsload.php:454