|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright (c) 2018 Justin Kuenzel (jukusoft.com) |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Project: JuKuCMS |
|
22
|
|
|
* License: Apache 2.0 license |
|
23
|
|
|
* User: Justin |
|
24
|
|
|
* Date: 07.04.2018 |
|
25
|
|
|
* Time: 19:12 |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
class Plugins { |
|
29
|
|
|
|
|
30
|
|
|
public static function listAvailablePluginNames () : array { |
|
31
|
|
|
$names = array(); |
|
32
|
|
|
|
|
33
|
|
|
//use directory iterator |
|
34
|
|
|
$dir = new DirectoryIterator(PLUGIN_PATH); |
|
35
|
|
|
|
|
36
|
|
|
foreach ($dir as $fileinfo) { |
|
37
|
|
|
if ($fileinfo->isDir() && !$fileinfo->isDot()) { |
|
38
|
|
|
$names[] = $fileinfo->getFilename(); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
return $names; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public static function listInstalledPluginNames () : array { |
|
46
|
|
|
if (Cache::contains("plugins", "installed_plugin_names")) { |
|
47
|
|
|
return Cache::get("plugins", "installed_plugin_names"); |
|
48
|
|
|
} else { |
|
49
|
|
|
$rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugins` WHERE `installed` = '1'; "); |
|
50
|
|
|
|
|
51
|
|
|
$array = array(); |
|
52
|
|
|
|
|
53
|
|
|
foreach ($rows as $row) { |
|
54
|
|
|
$array[] = $row['name']; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
//cache rows |
|
58
|
|
|
Cache::put("plugins", "installed_plugin_names", $array); |
|
59
|
|
|
|
|
60
|
|
|
return $rows; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public static function listInstalledPlugins () : array { |
|
65
|
|
|
if (Cache::contains("plugins", "installed_plugins")) { |
|
66
|
|
|
return Cache::get("plugins", "installed_plugins"); |
|
67
|
|
|
} else { |
|
68
|
|
|
//read installed plugins from database |
|
69
|
|
|
$rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugins` WHERE `installed` = '1'; "); |
|
70
|
|
|
|
|
71
|
|
|
$plugins = array(); |
|
72
|
|
|
|
|
73
|
|
|
foreach ($rows as $row) { |
|
74
|
|
|
//create new plugin instance |
|
75
|
|
|
$plugin = new Plugin($row['name'], $row); |
|
76
|
|
|
|
|
77
|
|
|
//load plugin |
|
78
|
|
|
$plugin->load(); |
|
79
|
|
|
|
|
80
|
|
|
$plugins[$plugin->getName()] = $plugin; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
//cache plugins |
|
84
|
|
|
Cache::put("plugins", "installed_plugins", $plugins); |
|
85
|
|
|
|
|
86
|
|
|
return $plugins; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public static function listUninstalledPlugins () : array { |
|
91
|
|
|
$installed_plugin_names = self::listInstalledPluginNames(); |
|
92
|
|
|
|
|
93
|
|
|
//create new empty list |
|
94
|
|
|
$list = array(); |
|
95
|
|
|
|
|
96
|
|
|
$dir = new DirectoryIterator(PLUGIN_PATH); |
|
97
|
|
|
|
|
98
|
|
|
foreach ($dir as $fileInfo) { |
|
99
|
|
|
if ($fileInfo->isDot()) { |
|
100
|
|
|
//dont parse directory "." |
|
101
|
|
|
continue; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
if (!$fileInfo->isDir()) { |
|
105
|
|
|
//we only search for directories |
|
106
|
|
|
continue; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
//get directory name |
|
110
|
|
|
$name = $fileInfo->getFilename(); |
|
111
|
|
|
|
|
112
|
|
|
//check, if plugin is already installed |
|
113
|
|
|
if (self::isPluginInArray($name, $installed_plugin_names)) { |
|
114
|
|
|
continue; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
//create and load new plugin |
|
118
|
|
|
$plugin = new Plugin($name); |
|
119
|
|
|
$plugin->load(); |
|
120
|
|
|
|
|
121
|
|
|
//add plugin to list |
|
122
|
|
|
$list[] = $plugin; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
return $list; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
protected static function isPluginInArray (string $plugin_name, array $installed_plugins) : bool { |
|
|
|
|
|
|
129
|
|
|
var_dump($installed_plugins); |
|
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
foreach ($installed_plugins as $plugin) { |
|
132
|
|
|
// |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
return false; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public static function clearCache () { |
|
139
|
|
|
Cache::clear("plugins"); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
?> |
|
|
|
|
|
|
145
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.