|
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
|
|
|
|
|
14
|
|
|
use Xoops\Module\Plugin\PluginAbstract; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @copyright 2013-2015 XOOPS Project (http://xoops.org) |
|
18
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
19
|
|
|
* @author trabis <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
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
|
|
|
|
|
68
|
1 |
|
\Xoops::getInstance()->events()->triggerEvent('core.module.plugin.get.plugins', array(&$dirnames, $pluginName)); |
|
69
|
|
|
|
|
70
|
1 |
|
if (is_array($inactiveModules)) { |
|
71
|
|
|
$dirnames = array_merge($dirnames, $inactiveModules); |
|
72
|
|
|
} |
|
73
|
1 |
|
foreach ($dirnames as $dirname) { |
|
74
|
1 |
|
if (\XoopsLoad::loadFile($xoops->path("modules/{$dirname}/class/plugin/{$pluginName}.php"))) { |
|
75
|
1 |
|
$className = '\\' . ucfirst($dirname) . ucfirst($pluginName) . 'Plugin'; |
|
76
|
1 |
|
$interface = '\\' . ucfirst($pluginName) . 'PluginInterface'; |
|
77
|
1 |
|
$class = new $className($dirname); |
|
78
|
1 |
|
if ($class instanceof PluginAbstract && $class instanceof $interface) { |
|
79
|
1 |
|
static::$plugins[$pluginName][$dirname] = $class; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
2 |
|
return static::$plugins[$pluginName]; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Clear cache of plugins |
|
89
|
|
|
* return void |
|
90
|
|
|
*/ |
|
91
|
|
|
public static function resetPluginsCache() |
|
92
|
|
|
{ |
|
93
|
|
|
static::$plugins = array(); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|