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
|
|
|
/** |
13
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
14
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
15
|
|
|
* @author trabis <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
// irmtfan copy from xoops26 xoops_lib/Xoops/Module/plugin.php class |
18
|
|
|
// change XoopsLoad -> self |
19
|
|
|
// change $xoops -> $GLOBALS['xoops'] |
20
|
|
|
// change Userlog_Module_Plugin_Abstract , Userlog_Module_Plugin |
21
|
|
|
// change $xoops->getActiveModules() -> xoops_getActiveModules() |
22
|
|
|
|
23
|
|
|
class Userlog_Module_Plugin |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @param string $dirname |
27
|
|
|
* @param string $pluginName |
28
|
|
|
* @param bool $force |
29
|
|
|
* |
30
|
|
|
* @return bool|Xoops_Module_Plugin_Abstract false if plugin does not exist |
31
|
|
|
*/ |
32
|
|
|
public static function getPlugin($dirname, $pluginName = 'system', $force = false) |
33
|
|
|
{ |
34
|
|
|
$inactiveModules = false; |
35
|
|
|
if ($force) { |
36
|
|
|
$inactiveModules = [$dirname]; |
37
|
|
|
} |
38
|
|
|
$available = self::getPlugins($pluginName, $inactiveModules); |
39
|
|
|
if (!in_array($dirname, array_keys($available))) { |
40
|
|
|
return false; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return $available[$dirname]; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $pluginName |
48
|
|
|
* @param array|bool $inactiveModules |
49
|
|
|
* |
50
|
|
|
* @return mixed |
51
|
|
|
*/ |
52
|
|
|
public static function getPlugins($pluginName = 'system', $inactiveModules = false) |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
static $plugins = []; |
55
|
|
|
if (!isset($plugins[$pluginName])) { |
56
|
|
|
$plugins[$pluginName] = []; |
57
|
|
|
//$xoops = Xoops::getInstance(); |
|
|
|
|
58
|
|
|
|
59
|
|
|
//Load interface for this plugin |
60
|
|
|
if (!self::loadFile($GLOBALS['xoops']->path("modules/{$pluginName}/class/plugin/interface.php"))) { |
61
|
|
|
return $plugins[$pluginName]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$dirnames = xoops_getActiveModules(); |
65
|
|
|
if (is_array($inactiveModules)) { |
66
|
|
|
$dirnames = array_merge($dirnames, $inactiveModules); |
67
|
|
|
} |
68
|
|
|
foreach ($dirnames as $dirname) { |
69
|
|
|
if (self::loadFile($GLOBALS['xoops']->path("modules/{$dirname}/class/plugin/{$pluginName}.php")) |
70
|
|
|
|| self::loadFile($GLOBALS['xoops']->path("modules/{$pluginName}/class/plugin/{$dirname}.php"))) { |
71
|
|
|
$className = ucfirst($dirname) . ucfirst($pluginName) . 'Plugin'; |
72
|
|
|
$interface = ucfirst($pluginName) . 'PluginInterface'; |
73
|
|
|
$class = new $className($dirname); |
74
|
|
|
if ($class instanceof Userlog_Module_Plugin_Abstract && $class instanceof $interface) { |
75
|
|
|
$plugins[$pluginName][$dirname] = $class; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $plugins[$pluginName]; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param $file |
86
|
|
|
* @param bool $once |
87
|
|
|
* |
88
|
|
|
* @return bool |
89
|
|
|
*/ |
90
|
|
|
|
91
|
|
|
public static function loadFile($file, $once = true) |
92
|
|
|
{ |
93
|
|
|
self::_securityCheck($file); |
94
|
|
|
if (self::fileExists($file)) { |
95
|
|
|
if ($once) { |
96
|
|
|
require_once $file; |
97
|
|
|
} else { |
98
|
|
|
include $file; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return true; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return false; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param $file |
109
|
|
|
* |
110
|
|
|
* @return mixed |
111
|
|
|
*/ |
112
|
|
|
|
113
|
|
|
public static function fileExists($file) |
114
|
|
|
{ |
115
|
|
|
static $included = []; |
116
|
|
|
if (!isset($included[$file])) { |
117
|
|
|
$included[$file] = file_exists($file); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return $included[$file]; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param $filename |
125
|
|
|
*/ |
126
|
|
|
protected static function _securityCheck($filename) |
127
|
|
|
{ |
128
|
|
|
/** |
129
|
|
|
* Security check |
130
|
|
|
*/ |
131
|
|
|
if (preg_match('/[^a-z0-9\\/\\\\_.:-]/i', $filename)) { |
132
|
|
|
exit('Security check: Illegal character in filename'); |
|
|
|
|
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.