1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Xoops\Module;
13:
14: use Xoops\Module\Plugin\PluginAbstract;
15:
16: 17: 18: 19: 20:
21:
22: class Plugin
23: {
24: 25: 26:
27: protected static $plugins = array();
28:
29: 30: 31: 32: 33: 34: 35:
36: public static function getPlugin($dirname, $pluginName = 'system', $force = false)
37: {
38: $inactiveModules = false;
39: if ($force) {
40: $inactiveModules = array($dirname);
41: }
42: $available = self::getPlugins($pluginName, $inactiveModules);
43: if (!in_array($dirname, array_keys($available))) {
44: return false;
45: }
46: return $available[$dirname];
47: }
48:
49: 50: 51: 52: 53: 54:
55: public static function getPlugins($pluginName = 'system', $inactiveModules = false)
56: {
57: if (!isset(static::$plugins[$pluginName])) {
58: static::$plugins[$pluginName] = array();
59: $xoops = \Xoops::getInstance();
60:
61:
62: if (!\XoopsLoad::loadFile($xoops->path("modules/{$pluginName}/class/plugin/interface.php"))) {
63: return static::$plugins[$pluginName];
64: }
65:
66: $dirnames = $xoops->getActiveModules();
67: if (is_array($inactiveModules)) {
68: $dirnames = array_merge($dirnames, $inactiveModules);
69: }
70: foreach ($dirnames as $dirname) {
71: if (\XoopsLoad::loadFile($xoops->path("modules/{$dirname}/class/plugin/{$pluginName}.php"))) {
72: $className = '\\' . ucfirst($dirname) . ucfirst($pluginName) . 'Plugin';
73: $interface = '\\' . ucfirst($pluginName) . 'PluginInterface';
74: $class = new $className($dirname);
75: if ($class instanceof PluginAbstract && $class instanceof $interface) {
76: static::$plugins[$pluginName][$dirname] = $class;
77: }
78: }
79: }
80: }
81: return static::$plugins[$pluginName];
82: }
83:
84: 85: 86: 87:
88: public static function resetPluginsCache()
89: {
90: static::$plugins = array();
91: }
92: }
93: