Rev 150 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
148 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
5 | * Copyright 2019 Daniel Marschall, ViaThinkSoft |
||
6 | * |
||
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
20 | if (!defined('IN_OIDPLUS')) die(); |
||
21 | |||
22 | class OIDplusPageAdminPlugins extends OIDplusPagePlugin { |
||
23 | public function type() { |
||
24 | return 'admin'; |
||
25 | } |
||
26 | |||
27 | public function priority() { |
||
28 | return 800; |
||
29 | } |
||
30 | |||
31 | public function action(&$handled) { |
||
32 | } |
||
33 | |||
34 | public function init($html=true) { |
||
35 | } |
||
36 | |||
37 | public function cfgSetValue($name, $value) { |
||
38 | } |
||
39 | |||
40 | public function gui($id, &$out, &$handled) { |
||
151 | daniel-mar | 41 | $parts = explode('.',$id,2); |
42 | if (!isset($parts[1])) $parts[1] = ''; |
||
43 | if ($parts[0] != 'oidplus:system_plugins') return; |
||
44 | $handled = true; |
||
148 | daniel-mar | 45 | |
151 | daniel-mar | 46 | if (!OIDplus::authUtils()::isAdminLoggedIn()) { |
47 | $out['icon'] = 'img/error_big.png'; |
||
48 | $out['text'] .= '<p>You need to <a '.oidplus_link('oidplus:login').'>log in</a> as administrator.</p>'; |
||
49 | return $out; |
||
50 | } |
||
51 | |||
52 | if (substr($parts[1],0,1) == '$') { |
||
53 | $classname = substr($parts[1],1); |
||
54 | $out['title'] = htmlentities($classname); |
||
55 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : ''; |
||
56 | |||
57 | $reflector = new \ReflectionClass($classname); |
||
58 | |||
59 | $out['text'] .= "<p>Plugin class name $classname</p>". |
||
60 | "<p>Plugin installed in " . dirname($reflector->getFileName())."</p>". |
||
61 | "<p>Plugin type " . get_parent_class($classname)."</p>"; |
||
62 | } else { |
||
63 | $show_pages_public = false; |
||
64 | $show_pages_ra = false; |
||
65 | $show_pages_admin = false; |
||
66 | $show_db_active = false; |
||
67 | $show_db_inactive = false; |
||
68 | $show_obj_active = false; |
||
69 | $show_obj_inactive = false; |
||
70 | |||
71 | if ($parts[1] == '') { |
||
72 | $out['title'] = "Installed plugins"; |
||
73 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : ''; |
||
74 | $show_pages_public = true; |
||
75 | $show_pages_ra = true; |
||
76 | $show_pages_admin = true; |
||
77 | $show_db_active = true; |
||
78 | $show_db_inactive = true; |
||
79 | $show_obj_active = true; |
||
80 | $show_obj_inactive = true; |
||
81 | } else if ($parts[1] == 'pages') { |
||
82 | $out['title'] = "Page plugins"; |
||
83 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : ''; |
||
84 | $show_pages_public = true; |
||
85 | $show_pages_ra = true; |
||
86 | $show_pages_admin = true; |
||
87 | } else if ($parts[1] == 'pages.public') { |
||
88 | $out['title'] = "Public page plugins"; |
||
89 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : ''; |
||
90 | $show_pages_public = true; |
||
91 | } else if ($parts[1] == 'pages.ra') { |
||
92 | $out['title'] = "RA page plugins"; |
||
93 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : ''; |
||
94 | $show_pages_ra = true; |
||
95 | } else if ($parts[1] == 'pages.admin') { |
||
96 | $out['title'] = "Admin page plugins"; |
||
97 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : ''; |
||
98 | $show_pages_admin = true; |
||
99 | } else if ($parts[1] == 'objects') { |
||
100 | $out['title'] = "Object type plugins"; |
||
101 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : ''; |
||
102 | $show_obj_active = true; |
||
103 | $show_obj_inactive = true; |
||
104 | } else if ($parts[1] == 'objects.enabled') { |
||
105 | $out['title'] = "Object type plugins (enabled)"; |
||
106 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : ''; |
||
107 | $show_obj_active = true; |
||
108 | } else if ($parts[1] == 'objects.disabled') { |
||
109 | $out['title'] = "Object type plugins (disabled)"; |
||
110 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : ''; |
||
111 | $show_obj_inactive = true; |
||
112 | } else if ($parts[1] == 'database') { |
||
113 | $out['title'] = "Database provider plugins"; |
||
114 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : ''; |
||
115 | $show_db_active = true; |
||
116 | $show_db_inactive = true; |
||
117 | } else if ($parts[1] == 'database.enabled') { |
||
118 | $out['title'] = "Database provider plugins (active)"; |
||
119 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : ''; |
||
120 | $show_db_active = true; |
||
121 | } else if ($parts[1] == 'database.disabled') { |
||
122 | $out['title'] = "Database provider plugins (inactive)"; |
||
123 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : ''; |
||
124 | $show_db_inactive = true; |
||
125 | } else { |
||
148 | daniel-mar | 126 | $out['icon'] = 'img/error_big.png'; |
151 | daniel-mar | 127 | $out['text'] .= '<p>Invalid arguments.</p>'; |
148 | daniel-mar | 128 | return $out; |
129 | } |
||
130 | |||
151 | daniel-mar | 131 | if ($show_pages_public) { |
132 | if (count($plugins = OIDplus::getPagePlugins('public')) > 0) { |
||
133 | $out['text'] .= '<p><u>Public page plugins:</u></p><ul>'; |
||
134 | foreach ($plugins as $plugin) { |
||
135 | $out['text'] .= '<li><a '.oidplus_link('oidplus:system_plugins.$'.get_class($plugin)).'>'.htmlentities(get_class($plugin)).'</a></li>'; // TODO: human friendly names |
||
136 | } |
||
137 | $out['text'] .= '</ul>'; |
||
148 | daniel-mar | 138 | } |
139 | } |
||
140 | |||
151 | daniel-mar | 141 | if ($show_pages_ra) { |
142 | if (count($plugins = OIDplus::getPagePlugins('ra')) > 0) { |
||
143 | $out['text'] .= '<p><u>RA page plugins:</u></p><ul>'; |
||
144 | foreach ($plugins as $plugin) { |
||
145 | $out['text'] .= '<li><a '.oidplus_link('oidplus:system_plugins.$'.get_class($plugin)).'>'.htmlentities(get_class($plugin)).'</a></li>'; // TODO: human friendly names |
||
146 | } |
||
147 | $out['text'] .= '</ul>'; |
||
148 | daniel-mar | 148 | } |
149 | } |
||
150 | |||
151 | daniel-mar | 151 | if ($show_pages_admin) { |
152 | if (count($plugins = OIDplus::getPagePlugins('admin')) > 0) { |
||
153 | $out['text'] .= '<p><u>Admin page plugins:</u></p><ul>'; |
||
154 | foreach ($plugins as $plugin) { |
||
155 | $out['text'] .= '<li><a '.oidplus_link('oidplus:system_plugins.$'.get_class($plugin)).'>'.htmlentities(get_class($plugin)).'</a></li>'; // TODO: human friendly names |
||
156 | } |
||
157 | $out['text'] .= '</ul>'; |
||
148 | daniel-mar | 158 | } |
159 | } |
||
160 | |||
151 | daniel-mar | 161 | $enabled = $show_obj_active ? OIDplus::getRegisteredObjectTypes() : array(); |
162 | $disabled = $show_obj_inactive ? OIDplus::getDisabledObjectTypes() : array(); |
||
150 | daniel-mar | 163 | $plugins = array_merge($enabled, $disabled); |
164 | if (count($plugins) > 0) { |
||
165 | $out['text'] .= '<p><u>Object types:</u></p><ul>'; |
||
148 | daniel-mar | 166 | foreach ($plugins as $ot) { |
150 | daniel-mar | 167 | if (in_array($ot, $enabled)) { |
151 | daniel-mar | 168 | $out['text'] .= '<li><a '.oidplus_link('oidplus:system_plugins.$'.$ot).'>'.htmlentities($ot::objectTypeTitle()).' ('.htmlentities($ot::ns()).')</a></li>'; |
150 | daniel-mar | 169 | } else { |
151 | daniel-mar | 170 | $out['text'] .= '<li><a '.oidplus_link('oidplus:system_plugins.$'.$ot).'><font color="gray">'.htmlentities($ot::objectTypeTitle()).' ('.htmlentities($ot::ns()).', disabled)</font></a></li>'; |
150 | daniel-mar | 171 | } |
148 | daniel-mar | 172 | } |
173 | $out['text'] .= '</ul>'; |
||
174 | } |
||
175 | |||
151 | daniel-mar | 176 | if ($show_db_active || $show_db_inactive) { |
177 | if (count($plugins = OIDplus::getDatabasePlugins()) > 0) { |
||
178 | $out['text'] .= '<p><u>Database plugins:</u></p><ul>'; |
||
179 | foreach ($plugins as $plugin) { |
||
180 | if ($plugin::name() == OIDPLUS_DATABASE_PLUGIN) { |
||
181 | $out['text'] .= $show_db_active ? '<li><a '.oidplus_link('oidplus:system_plugins.$'.get_class($plugin)).'><b>'.htmlentities($plugin::name()).'</b></a></li>' : ''; |
||
182 | } else { |
||
183 | $out['text'] .= $show_db_inactive ? '<li><a '.oidplus_link('oidplus:system_plugins.$'.get_class($plugin)).'>'.htmlentities($plugin::name()).'</a></li>' : ''; |
||
184 | } |
||
150 | daniel-mar | 185 | } |
151 | daniel-mar | 186 | $out['text'] .= '</ul>'; |
148 | daniel-mar | 187 | } |
188 | } |
||
189 | } |
||
190 | } |
||
191 | |||
192 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
||
193 | if (file_exists(__DIR__.'/treeicon.png')) { |
||
194 | $tree_icon = 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/treeicon.png'; |
||
195 | } else { |
||
196 | $tree_icon = null; // default icon (folder) |
||
197 | } |
||
198 | |||
151 | daniel-mar | 199 | $tree_icon_pages = $tree_icon; // TODO |
200 | $tree_icon_pages_public = $tree_icon; // TODO |
||
201 | $tree_icon_pages_ra = $tree_icon; // TODO |
||
202 | $tree_icon_pages_admin = $tree_icon; // TODO |
||
203 | $tree_icon_db_active = $tree_icon; // TODO |
||
204 | $tree_icon_db_inactive = $tree_icon; // TODO |
||
205 | $tree_icon_obj_active = $tree_icon; // TODO |
||
206 | $tree_icon_obj_inactive = $tree_icon; // TODO |
||
207 | |||
208 | $public_plugins = array(); |
||
209 | foreach (OIDplus::getPagePlugins('public') as $plugin) { |
||
210 | $public_plugins[] = array( |
||
211 | 'id' => 'oidplus:system_plugins.$'.get_class($plugin), |
||
212 | 'icon' => $tree_icon_pages_public, |
||
213 | 'text' => get_class($plugin), |
||
214 | ); |
||
215 | } |
||
216 | $ra_plugins = array(); |
||
217 | foreach (OIDplus::getPagePlugins('ra') as $plugin) { |
||
218 | $ra_plugins[] = array( |
||
219 | 'id' => 'oidplus:system_plugins.$'.get_class($plugin), |
||
220 | 'icon' => $tree_icon_pages_ra, |
||
221 | 'text' => get_class($plugin), |
||
222 | ); |
||
223 | } |
||
224 | $admin_plugins = array(); |
||
225 | foreach (OIDplus::getPagePlugins('admin') as $plugin) { |
||
226 | $admin_plugins[] = array( |
||
227 | 'id' => 'oidplus:system_plugins.$'.get_class($plugin), |
||
228 | 'icon' => $tree_icon_pages_admin, |
||
229 | 'text' => get_class($plugin), |
||
230 | ); |
||
231 | } |
||
232 | $db_plugins = array(); |
||
233 | foreach (OIDplus::getDatabasePlugins() as $plugin) { |
||
234 | $txt = get_class($plugin); |
||
235 | if ($plugin::name() == OIDPLUS_DATABASE_PLUGIN) { |
||
236 | $db_plugins[] = array( |
||
237 | 'id' => 'oidplus:system_plugins.$'.get_class($plugin), |
||
238 | 'icon' => $tree_icon_db_active, |
||
239 | 'text' => $txt, |
||
240 | ); |
||
241 | } else { |
||
242 | $db_plugins[] = array( |
||
243 | 'id' => 'oidplus:system_plugins.$'.get_class($plugin), |
||
244 | 'icon' => $tree_icon_db_inactive, |
||
245 | 'text' => '<font color="gray">'.$txt.'</font>', |
||
246 | ); |
||
247 | } |
||
248 | } |
||
249 | $obj_plugins = array(); |
||
250 | $enabled = OIDplus::getRegisteredObjectTypes(); |
||
251 | $disabled = OIDplus::getDisabledObjectTypes(); |
||
252 | foreach (array_merge($enabled, $disabled) as $ot) { |
||
253 | $txt = htmlentities($ot::objectTypeTitle()).' ('.htmlentities($ot::ns()).')'; |
||
254 | if (in_array($ot, $enabled)) { |
||
255 | $obj_plugins[] = array( |
||
256 | 'id' => 'oidplus:system_plugins.$'.get_class(new $ot('')), |
||
257 | 'icon' => $tree_icon_obj_active, |
||
258 | 'text' => $txt, |
||
259 | ); |
||
260 | } else { |
||
261 | $obj_plugins[] = array( |
||
262 | 'id' => 'oidplus:system_plugins.$'.get_class(new $ot('')), |
||
263 | 'icon' => $tree_icon_obj_inactive, |
||
264 | 'text' => '<font color="gray">'.$txt.'</font>', |
||
265 | ); |
||
266 | } |
||
267 | } |
||
148 | daniel-mar | 268 | $json[] = array( |
269 | 'id' => 'oidplus:system_plugins', |
||
270 | 'icon' => $tree_icon, |
||
151 | daniel-mar | 271 | 'text' => 'Plugins', |
272 | 'children' => array( |
||
273 | array( |
||
274 | 'id' => 'oidplus:system_plugins.pages', |
||
275 | 'icon' => $tree_icon, |
||
276 | 'text' => 'Page plugins', |
||
277 | 'children' => array( |
||
278 | array( |
||
279 | 'id' => 'oidplus:system_plugins.pages.public', |
||
280 | 'icon' => $tree_icon, |
||
281 | 'text' => 'Public', |
||
282 | 'children' => $public_plugins |
||
283 | ), |
||
284 | array( |
||
285 | 'id' => 'oidplus:system_plugins.pages.ra', |
||
286 | 'icon' => $tree_icon, |
||
287 | 'text' => 'RA', |
||
288 | 'children' => $ra_plugins |
||
289 | ), |
||
290 | array( |
||
291 | 'id' => 'oidplus:system_plugins.pages.admin', |
||
292 | 'icon' => $tree_icon, |
||
293 | 'text' => 'Admin', |
||
294 | 'children' => $admin_plugins |
||
295 | ) |
||
296 | ) |
||
297 | ), |
||
298 | array( |
||
299 | 'id' => 'oidplus:system_plugins.objects', |
||
300 | 'icon' => $tree_icon, |
||
301 | 'text' => 'Object types', |
||
302 | 'children' => $obj_plugins |
||
303 | ), |
||
304 | array( |
||
305 | 'id' => 'oidplus:system_plugins.database', |
||
306 | 'icon' => $tree_icon, |
||
307 | 'text' => 'Database providers', |
||
308 | 'children' => $db_plugins |
||
309 | ) |
||
310 | ) |
||
148 | daniel-mar | 311 | ); |
312 | |||
313 | return true; |
||
314 | } |
||
315 | |||
316 | public function tree_search($request) { |
||
317 | return false; |
||
318 | } |
||
319 | } |
||
320 | |||
321 | OIDplus::registerPagePlugin(new OIDplusPageAdminPlugins()); |