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 Xmf\Module; |
13
|
|
|
|
14
|
|
|
use Xmf\Language; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Xmf\Module\Admin provides helpful methods for module administration |
18
|
|
|
* uses. |
19
|
|
|
* |
20
|
|
|
* Xmf\Module\Admin provides a method compatible subset of the Xoops\Module\Admin class |
21
|
|
|
* (introduced in 2.6) and other convenience methods useful in transition |
22
|
|
|
* |
23
|
|
|
* @category Xmf\Module\Admin |
24
|
|
|
* @package Xmf |
25
|
|
|
* @author Richard Griffith <[email protected]> |
26
|
|
|
* @copyright 2011-2021 XOOPS Project (https://xoops.org) |
27
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
28
|
|
|
*/ |
29
|
|
|
class Admin |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The real ModuleAdmin object |
34
|
|
|
* |
35
|
|
|
* @var object |
36
|
|
|
*/ |
37
|
|
|
protected static $ModuleAdmin = null; |
38
|
|
|
protected $lastInfoBoxTitle = null; |
39
|
|
|
protected static $paypal = ''; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Constructor |
43
|
|
|
*/ |
44
|
|
|
protected function __construct() |
45
|
|
|
{ |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Retrieve a module admin instance |
50
|
|
|
* |
51
|
|
|
* If we are on a next generation system this will be the a native Xoops\Module\Admin instance. |
52
|
|
|
* Older systems with the Frameworks based admin class will get an instance of this class which |
53
|
|
|
* provides compatible methods built from the old Frameworks version. |
54
|
|
|
* |
55
|
|
|
* @return object a ModuleAdmin or Xoops\Module\Admin instance. |
56
|
|
|
*/ |
57
|
|
|
public static function getInstance() |
58
|
|
|
{ |
59
|
|
|
|
60
|
|
|
static $instance; |
61
|
|
|
|
62
|
|
|
if ($instance === null) { |
63
|
|
|
if (class_exists('\Xoops\Module\Admin', true)) { |
64
|
|
|
$instance = new \Xoops\Module\Admin; |
|
|
|
|
65
|
|
|
static::$ModuleAdmin = $instance; |
66
|
|
|
} else { |
67
|
|
|
include_once $GLOBALS['xoops']->path('Frameworks/moduleclasses/moduleadmin/moduleadmin.php'); |
68
|
|
|
static::$ModuleAdmin = new \ModuleAdmin; |
69
|
|
|
Language::load('xmf'); |
70
|
|
|
$instance = new static(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $instance; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Add config line |
79
|
|
|
* |
80
|
|
|
* @param string $value message to include in config box |
81
|
|
|
* @param string $type type of line to add |
82
|
|
|
* minimal set of acceptable types and value expectation |
83
|
|
|
* 'default' - value is message displayed directly (also used for unknown types) |
84
|
|
|
* 'folder' - value is directory name, will display accept if exists, error if not |
85
|
|
|
* 'chmod' - value is array(directory, permission) accept if exists with permission, |
86
|
|
|
* else error |
87
|
|
|
* 'module' - value is string module name, or array(module name, errortype) |
88
|
|
|
* If module is active, an accept line displays, otherwise, a warning |
89
|
|
|
* (if value is array(module, "warning") or an error displays. |
90
|
|
|
* |
91
|
|
|
* @return bool |
92
|
|
|
*/ |
93
|
|
|
public function addConfigBoxLine($value = '', $type = 'default') |
94
|
|
|
{ |
95
|
|
|
if ($type === 'module') { |
96
|
|
|
$mod = (is_array($value)) ? $value[0] : $value; |
|
|
|
|
97
|
|
|
if (xoops_isActiveModule($mod)) { |
98
|
|
|
return $this->addConfigAccept(sprintf(_AM_XMF_MODULE_INSTALLED, $mod)); |
99
|
|
|
} else { |
100
|
|
|
$nomod = (is_array($value)) ? $value[1] : 'error'; |
|
|
|
|
101
|
|
|
$line = sprintf(_AM_XMF_MODULE_NOT_INSTALLED, $mod); |
102
|
|
|
if ($nomod === 'warning') { |
103
|
|
|
return $this->addConfigWarning($line); |
104
|
|
|
} else { |
105
|
|
|
return $this->addConfigError($line); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
return static::$ModuleAdmin->addConfigBoxLine($value, $type); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Add Info box |
114
|
|
|
* |
115
|
|
|
* @param string $title info box title |
116
|
|
|
* @param string $type for compatibility only |
117
|
|
|
* @param string $extra for compatibility only |
118
|
|
|
* |
119
|
|
|
* @return bool |
120
|
|
|
*/ |
121
|
|
|
public function addInfoBox($title, $type = 'default', $extra = '') |
|
|
|
|
122
|
|
|
{ |
123
|
|
|
$this->lastInfoBoxTitle = $title; |
124
|
|
|
|
125
|
|
|
return static::$ModuleAdmin->addInfoBox($title); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Add line to the info box |
130
|
|
|
* |
131
|
|
|
* @param string $text text to add to info box |
132
|
|
|
* @param string $type type of infobox line |
133
|
|
|
* @param string $color color for infobox line |
134
|
|
|
* |
135
|
|
|
* @return bool |
136
|
|
|
*/ |
137
|
|
|
public function addInfoBoxLine($text = '', $type = 'default', $color = 'inherit') |
138
|
|
|
{ |
139
|
|
|
return static::$ModuleAdmin->addInfoBoxLine( |
140
|
|
|
$this->lastInfoBoxTitle, |
141
|
|
|
$text, |
142
|
|
|
'', |
143
|
|
|
$color, |
144
|
|
|
$type |
145
|
|
|
); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Add Item button |
150
|
|
|
* |
151
|
|
|
* @param string $title title of button |
152
|
|
|
* @param string $link link for button |
153
|
|
|
* @param string $icon icon for button |
154
|
|
|
* @param string $extra extra |
155
|
|
|
* |
156
|
|
|
* @return bool |
157
|
|
|
*/ |
158
|
|
|
public function addItemButton($title, $link, $icon = 'add', $extra = '') |
159
|
|
|
{ |
160
|
|
|
return static::$ModuleAdmin->addItemButton($title, $link, $icon, $extra); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Render all items buttons |
165
|
|
|
* |
166
|
|
|
* @param string $position button position (left, right) |
167
|
|
|
* @param string $delimiter delimiter between buttons |
168
|
|
|
* |
169
|
|
|
* @return string |
170
|
|
|
*/ |
171
|
|
|
public function renderButton($position = null, $delimiter = " ") |
172
|
|
|
{ |
173
|
|
|
if (null === $position) { |
174
|
|
|
$position = 'right'; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
return static::$ModuleAdmin->renderButton($position, $delimiter); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Display all item buttons |
182
|
|
|
* |
183
|
|
|
* @param string $position button position (left, right) |
184
|
|
|
* @param string $delimiter delimiter between buttons |
185
|
|
|
* |
186
|
|
|
* @return void |
187
|
|
|
*/ |
188
|
|
|
public function displayButton($position = null, $delimiter = " ") |
189
|
|
|
{ |
190
|
|
|
echo $this->renderButton($position, $delimiter); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Render InfoBox |
195
|
|
|
* |
196
|
|
|
* @return string HTML rendered info box |
197
|
|
|
*/ |
198
|
|
|
public function renderInfoBox() |
199
|
|
|
{ |
200
|
|
|
return static::$ModuleAdmin->renderInfoBox(); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Display InfoBox |
205
|
|
|
* |
206
|
|
|
* @return void |
207
|
|
|
*/ |
208
|
|
|
public function displayInfoBox() |
209
|
|
|
{ |
210
|
|
|
echo $this->renderInfoBox(); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Render index page for admin |
215
|
|
|
* |
216
|
|
|
* @return string HTML rendered info box |
217
|
|
|
*/ |
218
|
|
|
public function renderIndex() |
219
|
|
|
{ |
220
|
|
|
return static::$ModuleAdmin->renderIndex(); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Display index page for admin |
225
|
|
|
* |
226
|
|
|
* @return void |
227
|
|
|
*/ |
228
|
|
|
public function displayIndex() |
229
|
|
|
{ |
230
|
|
|
echo $this->renderIndex(); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Render the navigation menu |
235
|
|
|
* |
236
|
|
|
* @param string $menu menu key (script name, i.e. index.php) |
237
|
|
|
* |
238
|
|
|
* @return string |
239
|
|
|
*/ |
240
|
|
|
public function renderNavigation($menu = '') |
241
|
|
|
{ |
242
|
|
|
return static::$ModuleAdmin->addNavigation($menu); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* Display the navigation menu |
247
|
|
|
* |
248
|
|
|
* @param string $menu menu key (script name, i.e. index.php) |
249
|
|
|
* |
250
|
|
|
* @return void |
251
|
|
|
*/ |
252
|
|
|
public function displayNavigation($menu = '') |
253
|
|
|
{ |
254
|
|
|
echo static::$ModuleAdmin->addNavigation($menu); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Render about page |
259
|
|
|
* |
260
|
|
|
* @param bool $logo_xoops display XOOPS logo |
261
|
|
|
* |
262
|
|
|
* @return bool|mixed|string |
263
|
|
|
*/ |
264
|
|
|
public function renderAbout($logo_xoops = true) |
265
|
|
|
{ |
266
|
|
|
return static::$ModuleAdmin->renderAbout(static::$paypal, $logo_xoops); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Display about page |
271
|
|
|
* |
272
|
|
|
* @param bool $logo_xoops display XOOPS logo |
273
|
|
|
* |
274
|
|
|
* @return void |
275
|
|
|
*/ |
276
|
|
|
public function displayAbout($logo_xoops = true) |
277
|
|
|
{ |
278
|
|
|
echo $this->renderAbout($logo_xoops); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* Add error to config box |
283
|
|
|
* |
284
|
|
|
* @param string $value the error message |
285
|
|
|
* |
286
|
|
|
* @return bool |
287
|
|
|
*/ |
288
|
|
|
public function addConfigError($value = '') |
289
|
|
|
{ |
290
|
|
|
$path = XOOPS_URL . '/Frameworks/moduleclasses/icons/16/'; |
291
|
|
|
$line = ""; |
292
|
|
|
$line .= "<span style='color : red; font-weight : bold;'>"; |
293
|
|
|
$line .= "<img src='" . $path . "0.png' >"; |
294
|
|
|
$line .= $value; |
295
|
|
|
$line .= "</span>"; |
296
|
|
|
$value = $line; |
297
|
|
|
$type = 'default'; |
298
|
|
|
|
299
|
|
|
return static::$ModuleAdmin->addConfigBoxLine($value, $type); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* Add accept (OK) message to config box |
304
|
|
|
* |
305
|
|
|
* @param string $value the OK message |
306
|
|
|
* |
307
|
|
|
* @return bool |
308
|
|
|
*/ |
309
|
|
|
public function addConfigAccept($value = '') |
310
|
|
|
{ |
311
|
|
|
$path = XOOPS_URL . '/Frameworks/moduleclasses/icons/16/'; |
312
|
|
|
$line = ""; |
313
|
|
|
$line .= "<span style='color : green;'>"; |
314
|
|
|
$line .= "<img src='" . $path . "1.png' >"; |
315
|
|
|
$line .= $value; |
316
|
|
|
$line .= "</span>"; |
317
|
|
|
$value = $line; |
318
|
|
|
$type = 'default'; |
319
|
|
|
|
320
|
|
|
return static::$ModuleAdmin->addConfigBoxLine($value, $type); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* Add warning to config box |
325
|
|
|
* |
326
|
|
|
* @param string $value the warning message |
327
|
|
|
* |
328
|
|
|
* @return bool |
329
|
|
|
*/ |
330
|
|
|
public function addConfigWarning($value = '') |
331
|
|
|
{ |
332
|
|
|
$path = XOOPS_URL . '/Frameworks/moduleclasses/icons/16/'; |
333
|
|
|
$line = ""; |
334
|
|
|
$line .= "<span style='color : orange; font-weight : bold;'>"; |
335
|
|
|
$line .= "<img src='" . $path . "warning.png' >"; |
336
|
|
|
$line .= $value; |
337
|
|
|
$line .= "</span>"; |
338
|
|
|
$value = $line; |
339
|
|
|
$type = 'default'; |
340
|
|
|
|
341
|
|
|
return static::$ModuleAdmin->addConfigBoxLine($value, $type); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* Check for installed module and version and do addConfigBoxLine() |
347
|
|
|
* |
348
|
|
|
* @param string $moddir - module directory name |
349
|
|
|
* @param integer $minversion - minimum acceptable module version (100 = V1.00) |
350
|
|
|
* |
351
|
|
|
* @return bool true if requested version of the module is available |
352
|
|
|
*/ |
353
|
|
|
public function addConfigModuleVersion($moddir, $minversion) |
354
|
|
|
{ |
355
|
|
|
$return = false; |
356
|
|
|
$helper = Helper::getHelper($moddir); |
357
|
|
|
if (is_object($helper) && is_object($helper->getModule())) { |
358
|
|
|
$mod_modversion = $helper->getModule()->getVar('version'); |
359
|
|
|
$mod_version_f = $mod_modversion / 100; |
360
|
|
|
$min_version_f = $minversion / 100; |
361
|
|
|
$value = sprintf( |
362
|
|
|
_AM_XMF_MODULE_VERSION, |
363
|
|
|
strtoupper($moddir), |
364
|
|
|
$min_version_f, |
365
|
|
|
$mod_version_f |
366
|
|
|
); |
367
|
|
|
if ($mod_modversion >= $minversion) { |
368
|
|
|
$this->addConfigAccept($value); |
369
|
|
|
$return = true; |
370
|
|
|
} else { |
371
|
|
|
$this->addConfigError($value); |
372
|
|
|
} |
373
|
|
|
} else { |
374
|
|
|
$value = sprintf( |
375
|
|
|
_AM_XMF_MODULE_NOTFOUND, |
376
|
|
|
strtoupper($moddir), |
377
|
|
|
$minversion / 100 |
378
|
|
|
); |
379
|
|
|
$this->addConfigError($value); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
return $return; |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
// the following not part of next generation Xoops\Module\Admin |
386
|
|
|
|
387
|
|
|
/** |
388
|
|
|
* Are we in a next generation environment? |
389
|
|
|
* |
390
|
|
|
* not part of next generation Xoops\Module\Admin |
391
|
|
|
* |
392
|
|
|
* @return bool true if we are in a post XOOPS 2.5.x environment |
393
|
|
|
*/ |
394
|
|
|
protected static function isXng() |
395
|
|
|
{ |
396
|
|
|
return class_exists('\Xoops', false); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* Get an appropriate imagePath for menu.php use. |
401
|
|
|
* |
402
|
|
|
* just to help with other admin things than ModuleAdmin |
403
|
|
|
* |
404
|
|
|
* not part of next generation Xoops\Module\Admin |
405
|
|
|
* |
406
|
|
|
* @param string $image icon name to prepend with path |
407
|
|
|
* |
408
|
|
|
* @return string the icon path |
409
|
|
|
*/ |
410
|
|
|
public static function menuIconPath($image) |
411
|
|
|
{ |
412
|
|
|
if (static::isXng()) { |
413
|
|
|
return($image); |
414
|
|
|
} else { |
415
|
|
|
$path = '../../Frameworks/moduleclasses/icons/32/'; |
416
|
|
|
|
417
|
|
|
return($path . $image); |
418
|
|
|
} |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* Get an appropriate URL for system provided icons. |
423
|
|
|
* |
424
|
|
|
* Things which were in Frameworks in 2.5 are in media in later versions, |
425
|
|
|
* making it harder to use and rely on the standard icons. |
426
|
|
|
* |
427
|
|
|
* not part of next generation Xoops\Module\Admin |
428
|
|
|
* |
429
|
|
|
* @param string $name the image name to provide URL for, or blank |
430
|
|
|
* to just get the URL path. |
431
|
|
|
* @param string $size the icon size (directory). Valid values are |
432
|
|
|
* 16, 32 or /. A '/' slash will simply set the |
433
|
|
|
* path to the icon directory and append $image. |
434
|
|
|
* |
435
|
|
|
* @return string path to icons |
436
|
|
|
*/ |
437
|
|
|
public static function iconUrl($name = '', $size = '32') |
438
|
|
|
{ |
439
|
|
|
switch ($size) { |
440
|
|
|
case '16': |
441
|
|
|
$path = '16/'; |
442
|
|
|
break; |
443
|
|
|
case '/': |
444
|
|
|
$path = ''; |
445
|
|
|
break; |
446
|
|
|
case '32': |
447
|
|
|
default: |
448
|
|
|
$path = '32/'; |
449
|
|
|
break; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
if (static::isXng()) { |
453
|
|
|
$path = '/media/xoops/images/icons/' . $path; |
454
|
|
|
} else { |
455
|
|
|
$path = '/Frameworks/moduleclasses/icons/' . $path; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
return(XOOPS_URL . $path . $name); |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
/** |
462
|
|
|
* set paypal for 2.5.x renderAbout |
463
|
|
|
* |
464
|
|
|
* not part of next generation Xoops\Module\Admin |
465
|
|
|
* |
466
|
|
|
* @param string $paypal PayPal identifier for donate button |
467
|
|
|
* |
468
|
|
|
* @return void |
469
|
|
|
*/ |
470
|
|
|
public static function setPaypal($paypal = '') |
471
|
|
|
{ |
472
|
|
|
static::$paypal = $paypal; |
473
|
|
|
} |
474
|
|
|
} |
475
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths