1 | <?php |
||
22 | class Plugin |
||
23 | { |
||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | protected static $plugins = array(); |
||
28 | |||
29 | /** |
||
30 | * @param string $dirname module dirname |
||
31 | * @param string $pluginName plugin name i.e. system, menus, etc. |
||
32 | * @param bool $force get plugin even if module is inactive |
||
33 | * |
||
34 | * @return bool|PluginAbstract plugin, or false if plugin does not exist |
||
35 | */ |
||
36 | 1 | public static function getPlugin($dirname, $pluginName = 'system', $force = false) |
|
37 | { |
||
38 | 1 | $inactiveModules = false; |
|
39 | 1 | if ($force) { |
|
40 | $inactiveModules = array($dirname); |
||
41 | } |
||
42 | 1 | $available = self::getPlugins($pluginName, $inactiveModules); |
|
43 | 1 | if (!in_array($dirname, array_keys($available))) { |
|
44 | 1 | return false; |
|
45 | } |
||
46 | 1 | return $available[$dirname]; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string $pluginName |
||
51 | * @param array|bool $inactiveModules |
||
52 | * |
||
53 | * @return mixed |
||
54 | */ |
||
55 | 2 | public static function getPlugins($pluginName = 'system', $inactiveModules = false) |
|
56 | { |
||
57 | 2 | if (!isset(static::$plugins[$pluginName])) { |
|
58 | 1 | static::$plugins[$pluginName] = array(); |
|
59 | 1 | $xoops = \Xoops::getInstance(); |
|
60 | |||
61 | //Load interface for this plugin |
||
62 | 1 | if (!\XoopsLoad::loadFile($xoops->path("modules/{$pluginName}/class/plugin/interface.php"))) { |
|
63 | return static::$plugins[$pluginName]; |
||
64 | } |
||
65 | |||
66 | 1 | $dirnames = $xoops->getActiveModules(); |
|
67 | 1 | if (is_array($inactiveModules)) { |
|
68 | $dirnames = array_merge($dirnames, $inactiveModules); |
||
69 | } |
||
70 | 1 | foreach ($dirnames as $dirname) { |
|
71 | 1 | if (\XoopsLoad::loadFile($xoops->path("modules/{$dirname}/class/plugin/{$pluginName}.php"))) { |
|
72 | 1 | $className = '\\' . ucfirst($dirname) . ucfirst($pluginName) . 'Plugin'; |
|
73 | 1 | $interface = '\\' . ucfirst($pluginName) . 'PluginInterface'; |
|
74 | 1 | $class = new $className($dirname); |
|
75 | 1 | if ($class instanceof PluginAbstract && $class instanceof $interface) { |
|
76 | 1 | static::$plugins[$pluginName][$dirname] = $class; |
|
77 | } |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | 2 | return static::$plugins[$pluginName]; |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * Clear cache of plugins |
||
86 | * return void |
||
87 | */ |
||
88 | public static function resetPluginsCache() |
||
92 | } |
||
93 |