|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Xhelp; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* You may not change or alter any portion of this comment or credits |
|
7
|
|
|
* of supporting developers from this source code or any supporting source code |
|
8
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
|
17
|
|
|
* @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
|
18
|
|
|
* @author Brian Wahoff <[email protected]> |
|
19
|
|
|
* @author XOOPS Development Team |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Manages the retrieval, loading, and unloading of plugins |
|
24
|
|
|
* |
|
25
|
|
|
* @author Brian Wahoff <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
class PluginHandler |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Database connection |
|
31
|
|
|
* |
|
32
|
|
|
* @var object |
|
33
|
|
|
*/ |
|
34
|
|
|
public $db; |
|
35
|
|
|
public $active; |
|
36
|
|
|
public $plugins; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* PluginHandler constructor. |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(\XoopsDatabase $db = null) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->db = $db; |
|
44
|
|
|
$this->active = \unserialize(Utility::getMeta('plugins')); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
|
|
private function pluginList(): array |
|
51
|
|
|
{ |
|
52
|
|
|
$plugins = []; |
|
53
|
|
|
//Open Directory |
|
54
|
|
|
$d = @\dir(XHELP_PLUGIN_PATH); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
if ($d) { |
|
57
|
|
|
while (false !== ($entry = $d->read())) { |
|
58
|
|
|
if (!\preg_match('|^\.+$|', $entry) && \preg_match('|\.php$|', $entry)) { |
|
59
|
|
|
$plugins[] = \basename(XHELP_PLUGIN_PATH . '/' . $entry, '.php'); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return $plugins; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getActivePlugins(): void |
|
68
|
|
|
{ |
|
69
|
|
|
$plugin_files = $this->pluginList(); |
|
70
|
|
|
|
|
71
|
|
|
foreach ($plugin_files as $plugin) { |
|
72
|
|
|
if (\in_array($plugin, $this->active)) { |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param string $script |
|
79
|
|
|
*/ |
|
80
|
|
|
public function activatePlugin(string $script): void |
|
|
|
|
|
|
81
|
|
|
{ |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param string $script |
|
86
|
|
|
*/ |
|
87
|
|
|
public function deactivatePlugin(string $script): void |
|
|
|
|
|
|
88
|
|
|
{ |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @param string $filename |
|
93
|
|
|
* @return bool |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getPluginInstance(string $filename): bool |
|
96
|
|
|
{ |
|
97
|
|
|
if (!isset($this->plugins[$filename])) { |
|
98
|
|
|
if (\is_file($plug_file = XHELP_PLUGIN_PATH . '/' . $filename . '.php')) { |
|
|
|
|
|
|
99
|
|
|
require_once $plug_file; |
|
100
|
|
|
} |
|
101
|
|
|
$class = \mb_strtolower(XHELP_DIRNAME) . \ucfirst($filename); |
|
|
|
|
|
|
102
|
|
|
if (\class_exists($class)) { |
|
103
|
|
|
$this->plugins[$filename] = new $class($GLOBALS['_eventsrv']); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
if (!isset($this->plugins[$filename])) { |
|
107
|
|
|
\trigger_error('Plugin does not exist<br>Module: ' . XHELP_DIRNAME . '<br>Name: ' . $filename, \E_USER_ERROR); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
return $this->plugins[$filename] ?? false; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|