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 Xoops\Module; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Xoops ModuleAdmin Classes |
16
|
|
|
* |
17
|
|
|
* @category Xoops\Module\Admin |
18
|
|
|
* @package Admin |
19
|
|
|
* @author Mage Grégory (AKA Mage) |
20
|
|
|
* @copyright 2013-2015 XOOPS Project (http://xoops.org) |
21
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
22
|
|
|
* @link xoops.org |
23
|
|
|
* @since 2.6.0 |
24
|
|
|
*/ |
25
|
|
|
class Admin |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Set module directory |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
public $tplModule = 'system'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Template call for each render parts |
36
|
|
|
* |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
public $tplFile = array( |
40
|
|
|
'index' => 'admin_index.tpl', |
41
|
|
|
'about' => 'admin_about.tpl', |
42
|
|
|
'infobox' => 'admin_infobox.tpl', |
43
|
|
|
'bread' => 'admin_breadcrumb.tpl', |
44
|
|
|
'button' => 'admin_buttons.tpl', |
45
|
|
|
'tips' => 'admin_tips.tpl', |
46
|
|
|
'nav' => 'admin_navigation.tpl', |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Tips to display in admin page |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
private $tips = ''; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* List of button |
58
|
|
|
* |
59
|
|
|
* @var array |
60
|
|
|
*/ |
61
|
|
|
private $itemButton = array(); |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* List of Info Box |
65
|
|
|
* |
66
|
|
|
* @var array |
67
|
|
|
*/ |
68
|
|
|
private $itemInfoBox = array(); |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* List of line of an Info Box |
72
|
|
|
* |
73
|
|
|
* @var array |
74
|
|
|
*/ |
75
|
|
|
private $itemConfigBoxLine = array(); |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Breadcrumb data |
79
|
|
|
* |
80
|
|
|
* @var array |
81
|
|
|
*/ |
82
|
|
|
private $bread = array(); |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Current module object |
86
|
|
|
* |
87
|
|
|
* @var \Xoops\Core\Kernel\Handlers\XoopsModule $module |
88
|
|
|
*/ |
89
|
|
|
private $module = null; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Constructor |
93
|
|
|
*/ |
94
|
|
|
public function __construct() |
95
|
|
|
{ |
96
|
|
|
$xoops = \Xoops::getInstance(); |
97
|
|
|
$this->module = $xoops->module; |
98
|
|
|
$xoops->theme()->addStylesheet('media/xoops/css/moduladmin.css'); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Add breadcrumb menu |
103
|
|
|
* |
104
|
|
|
* @param string $title title |
105
|
|
|
* @param string $link url |
106
|
|
|
* @param bool $home is home |
107
|
|
|
* |
108
|
|
|
* @return void |
109
|
|
|
*/ |
110
|
|
|
public function addBreadcrumbLink($title = '', $link = '', $home = false) |
111
|
|
|
{ |
112
|
|
|
if ($title != '') { |
113
|
|
|
$this->bread[] = array( |
114
|
|
|
'link' => $link, 'title' => $title, 'home' => $home |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Add config line |
121
|
|
|
* |
122
|
|
|
* @param string $value line value - a string or array of values |
123
|
|
|
* @param string $type type of line default, folder, chmod, extension, module |
124
|
|
|
* Or, type value for itemConfigBoxLine -- accept, warning, error |
125
|
|
|
* |
126
|
|
|
* @return bool |
127
|
|
|
*/ |
128
|
|
|
public function addConfigBoxLine($value = '', $type = 'default') |
129
|
|
|
{ |
130
|
|
|
switch ($type) { |
131
|
|
|
default: |
132
|
|
|
case "default": |
133
|
|
|
$this->itemConfigBoxLine[] = array('type' => $type, 'text' => $value); |
134
|
|
|
break; |
135
|
|
|
|
136
|
|
|
case "folder": |
137
|
|
|
if (!is_dir($value)) { |
138
|
|
|
$this->itemConfigBoxLine[] = array( |
139
|
|
|
'type' => 'error', 'text' => sprintf(\XoopsLocale::EF_FOLDER_DOES_NOT_EXIST, $value) |
140
|
|
|
); |
141
|
|
|
} else { |
142
|
|
|
$this->itemConfigBoxLine[] = array( |
143
|
|
|
'type' => 'accept', 'text' => sprintf(\XoopsLocale::SF_FOLDER_EXISTS, $value) |
144
|
|
|
); |
145
|
|
|
} |
146
|
|
|
break; |
147
|
|
|
|
148
|
|
|
case "chmod": |
149
|
|
|
if (is_dir($value[0])) { |
150
|
|
|
if (substr(decoct(fileperms($value[0])), 2) != $value[1]) { |
151
|
|
|
$this->itemConfigBoxLine[] = array( |
152
|
|
|
'type' => 'error', |
153
|
|
|
'text' => sprintf( |
154
|
|
|
\XoopsLocale::EF_FOLDER_MUST_BE_WITH_CHMOD, |
155
|
|
|
$value[0], |
156
|
|
|
$value[1], |
157
|
|
|
substr(decoct(fileperms($value[0])), 2) |
158
|
|
|
) |
159
|
|
|
); |
160
|
|
|
} else { |
161
|
|
|
$this->itemConfigBoxLine[] = array( |
162
|
|
|
'type' => 'accept', |
163
|
|
|
'text' => sprintf( |
164
|
|
|
\XoopsLocale::EF_FOLDER_MUST_BE_WITH_CHMOD, |
165
|
|
|
$value[0], |
166
|
|
|
$value[1], |
167
|
|
|
substr(decoct(fileperms($value[0])), 2) |
168
|
|
|
) |
169
|
|
|
); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
break; |
173
|
|
|
|
174
|
|
|
case "extension": |
175
|
|
|
$xoops = \Xoops::getInstance(); |
176
|
|
|
if (is_array($value)) { |
|
|
|
|
177
|
|
|
$text = $value[0]; |
178
|
|
|
$type = $value[1]; |
179
|
|
|
} else { |
180
|
|
|
$text = $value; |
181
|
|
|
$type = 'error'; |
182
|
|
|
} |
183
|
|
|
if ($xoops->isActiveModule($text) == false) { |
|
|
|
|
184
|
|
|
$this->itemConfigBoxLine[] = array( |
185
|
|
|
'type' => $type, 'text' => sprintf(\XoopsLocale::EF_EXTENSION_IS_NOT_INSTALLED, $text) |
186
|
|
|
); |
187
|
|
|
} else { |
188
|
|
|
$this->itemConfigBoxLine[] = array( |
189
|
|
|
'type' => 'accept', 'text' => sprintf(\XoopsLocale::SF_EXTENSION_IS_INSTALLED, $text) |
190
|
|
|
); |
191
|
|
|
} |
192
|
|
|
break; |
193
|
|
|
|
194
|
|
|
case "module": |
195
|
|
|
$xoops = \Xoops::getInstance(); |
196
|
|
|
if (is_array($value)) { |
|
|
|
|
197
|
|
|
$text = $value[0]; |
198
|
|
|
$type = $value[1]; |
199
|
|
|
} else { |
200
|
|
|
$text = $value; |
201
|
|
|
$type = 'error'; |
202
|
|
|
} |
203
|
|
|
if ($xoops->isActiveModule($text) == false) { |
|
|
|
|
204
|
|
|
$this->itemConfigBoxLine[] = array( |
205
|
|
|
'type' => $type, 'text' => sprintf(\XoopsLocale::F_MODULE_IS_NOT_INSTALLED, $text) |
206
|
|
|
); |
207
|
|
|
} else { |
208
|
|
|
$this->itemConfigBoxLine[] = array( |
209
|
|
|
'type' => 'accept', 'text' => sprintf(\XoopsLocale::F_MODULE_IS_INSTALLED, $text) |
210
|
|
|
); |
211
|
|
|
} |
212
|
|
|
break; |
213
|
|
|
|
214
|
|
|
case "service": |
215
|
|
|
$xoops = \Xoops::getInstance(); |
216
|
|
|
if (is_array($value)) { |
|
|
|
|
217
|
|
|
$text = $value[0]; |
218
|
|
|
$type = $value[1]; |
219
|
|
|
} else { |
220
|
|
|
$text = $value; |
221
|
|
|
$type = 'error'; |
222
|
|
|
} |
223
|
|
|
if ($xoops->service($text)->isAvailable()) { |
224
|
|
|
$this->itemConfigBoxLine[] = array( |
225
|
|
|
'type' => 'accept', 'text' => sprintf(\XoopsLocale::SF_SERVICE_IS_INSTALLED, $text) |
226
|
|
|
); |
227
|
|
|
} else { |
228
|
|
|
$this->itemConfigBoxLine[] = array( |
229
|
|
|
'type' => $type, 'text' => sprintf(\XoopsLocale::EF_SERVICE_IS_NOT_INSTALLED, $text) |
230
|
|
|
); |
231
|
|
|
} |
232
|
|
|
break; |
233
|
|
|
|
234
|
|
|
} |
235
|
|
|
return true; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
// simplified config aliases |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Add error to config box |
242
|
|
|
* |
243
|
|
|
* @param string $value the error message |
244
|
|
|
* |
245
|
|
|
* @return bool |
246
|
|
|
*/ |
247
|
|
|
public function addConfigError($value = '') |
248
|
|
|
{ |
249
|
|
|
return $this->addConfigBoxLine($value, 'error'); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Add accept (OK) message to config box |
254
|
|
|
* |
255
|
|
|
* @param string $value the OK message |
256
|
|
|
* |
257
|
|
|
* @return bool |
258
|
|
|
*/ |
259
|
|
|
public function addConfigAccept($value = '') |
260
|
|
|
{ |
261
|
|
|
return $this->addConfigBoxLine($value, 'accept'); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Add warning to config box |
266
|
|
|
* |
267
|
|
|
* @param string $value the warning message |
268
|
|
|
* |
269
|
|
|
* @return bool |
270
|
|
|
*/ |
271
|
|
|
public function addConfigWarning($value = '') |
272
|
|
|
{ |
273
|
|
|
return $this->addConfigBoxLine($value, 'warning'); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Check for installed module and version and to configuration box |
278
|
|
|
* |
279
|
|
|
* @param string $moddir module directory name |
280
|
|
|
* @param integer $minversion minimum acceptable module version (100 = V1.00) |
281
|
|
|
* |
282
|
|
|
* @return bool true if requested version of the module is available |
283
|
|
|
*/ |
284
|
|
|
public function addConfigModuleVersion($moddir, $minversion) |
285
|
|
|
{ |
286
|
|
|
$return=false; |
287
|
|
|
$helper= \Xoops::getInstance()->getModuleHelper($moddir); |
288
|
|
|
if (is_object($helper) && is_object($helper->getModule())) { |
289
|
|
|
$mod_modversion=$helper->getModule()->getVar('version'); |
290
|
|
|
$mod_version_f = $mod_modversion/100; |
291
|
|
|
$min_version_f = $minversion/100; |
292
|
|
|
$value = sprintf( |
293
|
|
|
\XoopsLocale::EF_MODULE_VERSION, |
294
|
|
|
strtoupper($moddir), |
295
|
|
|
$min_version_f, |
296
|
|
|
$mod_version_f |
297
|
|
|
); |
298
|
|
|
if ($mod_modversion>=$minversion) { |
299
|
|
|
$this->addConfigAccept($value); |
300
|
|
|
$return=true; |
301
|
|
|
} else { |
302
|
|
|
$this->addConfigError($value); |
303
|
|
|
} |
304
|
|
|
} else { |
305
|
|
|
$value = sprintf( |
306
|
|
|
\XoopsLocale::EF_MODULE_NOTFOUND, |
307
|
|
|
strtoupper($moddir), |
308
|
|
|
$minversion/100 |
309
|
|
|
); |
310
|
|
|
$this->addConfigError($value); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
return $return; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* Add Info box |
318
|
|
|
* Template in htdocs/modules/system/templates/admin/admin_infobox.tpl |
319
|
|
|
* |
320
|
|
|
* @param string $title title |
321
|
|
|
* @param string $type type will be used as icon name in title in template |
322
|
|
|
* @param string $extra extra added to the div element that surrounds the box |
323
|
|
|
* |
324
|
|
|
* @return bool |
325
|
|
|
*/ |
326
|
|
|
public function addInfoBox($title, $type = 'default', $extra = '') |
327
|
|
|
{ |
328
|
|
|
$ret['title'] = $title; |
|
|
|
|
329
|
|
|
$ret['type'] = $type; |
330
|
|
|
$ret['extra'] = $extra; |
331
|
|
|
$this->itemInfoBox[] = $ret; |
332
|
|
|
return true; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* Add line to the info box |
337
|
|
|
* |
338
|
|
|
* @param string $text line text |
339
|
|
|
* @param string $type icon |
340
|
|
|
* @param string $color css class |
341
|
|
|
* |
342
|
|
|
* @return bool |
343
|
|
|
*/ |
344
|
|
|
public function addInfoBoxLine($text = '', $type = 'default', $color = 'inherit') |
345
|
|
|
{ |
346
|
|
|
$ret = array(); |
347
|
|
|
$ret['text'] = $text; |
348
|
|
|
$ret['color'] = $color; |
349
|
|
|
|
350
|
|
|
foreach (array_keys($this->itemInfoBox) as $i) { |
351
|
|
|
if ($this->itemInfoBox[$i]['type'] == $type) { |
352
|
|
|
$this->itemInfoBox[$i]['line'][] = $ret; |
353
|
|
|
} |
354
|
|
|
} |
355
|
|
|
return true; |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* Add Item button |
360
|
|
|
* |
361
|
|
|
* @param string $title title |
362
|
|
|
* @param string $link link |
363
|
|
|
* @param string $icon icon |
364
|
|
|
* @param string $extra extra |
365
|
|
|
* |
366
|
|
|
* @return bool |
367
|
|
|
*/ |
368
|
|
|
public function addItemButton($title, $link, $icon = 'add', $extra = '') |
369
|
|
|
{ |
370
|
|
|
$ret['title'] = $title; |
|
|
|
|
371
|
|
|
$ret['link'] = $link; |
372
|
|
|
$ret['icon'] = $icon; |
373
|
|
|
$ret['extra'] = $extra; |
374
|
|
|
$this->itemButton[] = $ret; |
375
|
|
|
return true; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* Add a tips |
380
|
|
|
* |
381
|
|
|
* @param string $text text |
382
|
|
|
* |
383
|
|
|
* @return void |
384
|
|
|
*/ |
385
|
|
|
public function addTips($text = '') |
386
|
|
|
{ |
387
|
|
|
$this->tips = $text; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* Construct template path |
392
|
|
|
* |
393
|
|
|
* @param string $type type |
394
|
|
|
* |
395
|
|
|
* @return string |
396
|
|
|
*/ |
397
|
|
|
private function getTplPath($type = '') |
398
|
|
|
{ |
399
|
|
|
return 'admin:' . $this->tplModule . '/' . $this->tplFile[$type]; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* renderBreadcrumb |
404
|
|
|
* |
405
|
|
|
* @return string |
406
|
|
|
*/ |
407
|
|
|
public function renderBreadcrumb() |
408
|
|
|
{ |
409
|
|
|
$xoops = \Xoops::getInstance(); |
410
|
|
|
$xoops->tpl()->assign('xo_admin_breadcrumb', $this->bread); |
411
|
|
|
return $xoops->tpl()->fetch($this->getTplPath('bread')); |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* displayBreadcrumb |
416
|
|
|
* |
417
|
|
|
* @return void |
418
|
|
|
*/ |
419
|
|
|
public function displayBreadcrumb() |
420
|
|
|
{ |
421
|
|
|
echo $this->renderBreadcrumb(); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* Render all items buttons |
426
|
|
|
* |
427
|
|
|
* @param string $position position |
428
|
|
|
* @param string $delimiter delimiter |
429
|
|
|
* |
430
|
|
|
* @return string |
431
|
|
|
*/ |
432
|
|
|
public function renderButton($position = "floatright", $delimiter = " ") |
433
|
|
|
{ |
434
|
|
|
$xoops = \Xoops::getInstance(); |
435
|
|
|
|
436
|
|
|
$xoops->tpl()->assign('xo_admin_buttons_position', $position); |
437
|
|
|
$xoops->tpl()->assign('xo_admin_buttons_delim', $delimiter); |
438
|
|
|
$xoops->tpl()->assign('xo_admin_buttons', $this->itemButton); |
439
|
|
|
return $xoops->tpl()->fetch($this->getTplPath('button')); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* displayButton |
444
|
|
|
* |
445
|
|
|
* @param string $position position |
446
|
|
|
* @param string $delimiter delimiter |
447
|
|
|
* |
448
|
|
|
* @return void |
449
|
|
|
*/ |
450
|
|
|
public function displayButton($position = "floatright", $delimiter = " ") |
451
|
|
|
{ |
452
|
|
|
echo $this->renderButton($position, $delimiter); |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
/** |
456
|
|
|
* Render InfoBox |
457
|
|
|
* |
458
|
|
|
* @return string |
459
|
|
|
*/ |
460
|
|
|
public function renderInfoBox() |
461
|
|
|
{ |
462
|
|
|
$xoops = \Xoops::getInstance(); |
463
|
|
|
$xoops->tpl()->assign('xo_admin_box', $this->itemInfoBox); |
464
|
|
|
return $xoops->tpl()->fetch($this->getTplPath('infobox')); |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
/** |
468
|
|
|
* displayInfoBox |
469
|
|
|
* |
470
|
|
|
* @return void |
471
|
|
|
*/ |
472
|
|
|
public function displayInfoBox() |
473
|
|
|
{ |
474
|
|
|
echo $this->renderInfoBox(); |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* Render index page for admin |
479
|
|
|
* |
480
|
|
|
* @return string |
481
|
|
|
*/ |
482
|
|
|
public function renderIndex() |
483
|
|
|
{ |
484
|
|
|
$xoops = \Xoops::getInstance(); |
485
|
|
|
$this->module->loadAdminMenu(); |
486
|
|
|
foreach (array_keys($this->module->adminmenu) as $i) { |
487
|
|
|
if (\XoopsLoad::fileExists($xoops->path("media/xoops/images/icons/32/" . $this->module->adminmenu[$i]['icon']))) { |
488
|
|
|
$this->module->adminmenu[$i]['icon'] = $xoops->url("media/xoops/images/icons/32/" . $this->module->adminmenu[$i]['icon']); |
489
|
|
|
} elseif (\XoopsLoad::fileExists($xoops->path("modules/" . $xoops->module->dirname() . "/assets/icons/32/" . $this->module->adminmenu[$i]['icon']))) { |
|
|
|
|
490
|
|
|
$this->module->adminmenu[$i]['icon'] = $xoops->url("modules/" . $xoops->module->dirname() . "/assets/icons/32/" . $this->module->adminmenu[$i]['icon']); |
491
|
|
|
} else { |
492
|
|
|
$this->module->adminmenu[$i]['icon'] = $xoops->url("modules/" . $xoops->module->dirname() . "/icons/32/" . $this->module->adminmenu[$i]['icon']); |
493
|
|
|
} |
494
|
|
|
$xoops->tpl()->append('xo_admin_index_menu', $this->module->adminmenu[$i]); |
495
|
|
|
} |
496
|
|
|
if ($this->module->getInfo('help')) { |
497
|
|
|
$help = array(); |
498
|
|
|
$help['link'] = '../system/help.php?mid=' . $this->module->getVar('mid', 's') |
499
|
|
|
. "&" . $this->module->getInfo('help'); |
|
|
|
|
500
|
|
|
$help['icon'] = $xoops->url("/media/xoops/images/icons/32/help.png"); |
501
|
|
|
$help['title'] = \XoopsLocale::HELP; |
502
|
|
|
$xoops->tpl()->append('xo_admin_index_menu', $help); |
503
|
|
|
} |
504
|
|
|
$xoops->tpl()->assign('xo_admin_box', $this->itemInfoBox); |
505
|
|
|
|
506
|
|
|
// If you use a config label |
507
|
|
|
if ($this->module->getInfo('min_php') || $this->module->getInfo('min_xoops') |
508
|
|
|
|| $this->module->getInfo('min_db') || !empty($this->itemConfigBoxLine) |
509
|
|
|
) { |
510
|
|
|
// PHP version |
511
|
|
|
if ($this->module->getInfo('min_php')) { |
512
|
|
|
if (0 >= version_compare(phpversion(), $this->module->getInfo('min_php'))) { |
|
|
|
|
513
|
|
|
$this->addConfigBoxLine( |
514
|
|
|
sprintf( |
515
|
|
|
\XoopsLocale::F_MINIMUM_PHP_VERSION_REQUIRED, |
516
|
|
|
$this->module->getInfo('min_php'), |
|
|
|
|
517
|
|
|
phpversion() |
518
|
|
|
), |
519
|
|
|
'error' |
520
|
|
|
); |
521
|
|
|
} else { |
522
|
|
|
$this->addConfigBoxLine( |
523
|
|
|
sprintf( |
524
|
|
|
\XoopsLocale::F_MINIMUM_PHP_VERSION_REQUIRED, |
525
|
|
|
$this->module->getInfo('min_php'), |
526
|
|
|
phpversion() |
527
|
|
|
), |
528
|
|
|
'accept' |
529
|
|
|
); |
530
|
|
|
} |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
// Database version |
534
|
|
|
// Validate that the current system is acceptable for the module by checking a set of specific |
535
|
|
|
// databases and versions if specified in min_db key. |
536
|
|
|
// |
537
|
|
|
// An array of minimum versions keyed by platform can be optionally specified in xoops_version.php: |
538
|
|
|
// $modversion['min_db'] = array('mysql' => '5.0.7', 'sqlite' => '3.0.8'); |
539
|
|
|
// |
540
|
|
|
// If min_db is specified, and the current database is included in the array, the version will be |
541
|
|
|
// compared to the specified minimum. If the reported database version is equal or greater, an OK |
542
|
|
|
// message will be generated. If the version is lower, an error message will be issued. |
543
|
|
|
// |
544
|
|
|
// If min_db is specified, and the current platform is not included in the array, an error message |
545
|
|
|
// will indicate the module does not support the database current platform. |
546
|
|
|
// |
547
|
|
|
// If at all possible, modules should NOT specify this, as with Doctrine DBAL we should be able to |
548
|
|
|
// support many different databases, and thus portable modules are prefered. The supported databases |
549
|
|
|
// and versions are set by XoopsCore and Doctrine, and should not be restricted without reason. |
550
|
|
|
|
551
|
|
|
$dbarray = $this->module->getInfo('min_db'); |
552
|
|
|
if ($dbarray !== false) { |
|
|
|
|
553
|
|
|
$dbCurrentPlatform = $xoops->db()->getDatabasePlatform()->getName(); |
554
|
|
|
$dbCurrentVersion = $xoops->db()->getWrappedConnection()->getServerVersion(); |
555
|
|
|
if (isset($dbarray[$dbCurrentPlatform])) { |
556
|
|
|
$dbRequiredVersion = $dbarray[$dbCurrentPlatform]; |
557
|
|
|
if (0 >= version_compare($dbCurrentVersion, $dbRequiredVersion)) { |
558
|
|
|
$this->addConfigBoxLine( |
559
|
|
|
sprintf( |
560
|
|
|
strtoupper(\XoopsBaseConfig::get('db-type')) . ' ' |
|
|
|
|
561
|
|
|
. \XoopsLocale::F_MINIMUM_DATABASE_VERSION_REQUIRED, |
562
|
|
|
$dbRequiredVersion, |
563
|
|
|
$dbCurrentVersion |
564
|
|
|
), |
565
|
|
|
'error' |
566
|
|
|
); |
567
|
|
|
} else { |
568
|
|
|
$this->addConfigBoxLine( |
569
|
|
|
sprintf( |
570
|
|
|
strtoupper(\XoopsBaseConfig::get('db-type')) . ' ' . \XoopsLocale::F_MINIMUM_DATABASE_VERSION_REQUIRED, |
571
|
|
|
$dbRequiredVersion, |
572
|
|
|
$dbCurrentVersion |
573
|
|
|
), |
574
|
|
|
'accept' |
575
|
|
|
); |
576
|
|
|
} |
577
|
|
|
} else { |
578
|
|
|
$this->addConfigBoxLine( |
579
|
|
|
sprintf(\XoopsLocale::EF_DATABASE_NOT_SUPPORTED, $dbCurrentPlatform), |
580
|
|
|
'error' |
581
|
|
|
); |
582
|
|
|
} |
583
|
|
|
} |
584
|
|
|
|
585
|
|
|
// xoops version |
586
|
|
|
if ($this->module->getInfo('min_xoops')) { |
587
|
|
|
$xoopsVersion = substr(\Xoops::VERSION, 6); // skip 'XOOPS ' prefix |
588
|
|
|
$xoopsCmpVersion = str_ireplace(['Alpha', 'Beta', 'RC'], ['0Alpha', '0Beta', '0RC'], $xoopsVersion); |
589
|
|
|
if (0 >= version_compare($xoopsCmpVersion, $this->module->getInfo('min_xoops'))) { |
|
|
|
|
590
|
|
|
$this->addConfigBoxLine( |
591
|
|
|
sprintf( |
592
|
|
|
\XoopsLocale::F_MINIMUM_XOOPS_VERSION_REQUIRED, |
593
|
|
|
$this->module->getInfo('min_xoops'), |
594
|
|
|
$xoopsVersion |
595
|
|
|
), |
596
|
|
|
'error' |
597
|
|
|
); |
598
|
|
|
} else { |
599
|
|
|
$this->addConfigBoxLine( |
600
|
|
|
sprintf( |
601
|
|
|
\XoopsLocale::F_MINIMUM_XOOPS_VERSION_REQUIRED, |
602
|
|
|
$this->module->getInfo('min_xoops'), |
603
|
|
|
$xoopsVersion |
604
|
|
|
), |
605
|
|
|
'accept' |
606
|
|
|
); |
607
|
|
|
} |
608
|
|
|
} |
609
|
|
|
$xoops->tpl()->assign('xo_admin_index_config', $this->itemConfigBoxLine); |
610
|
|
|
} |
611
|
|
|
return $xoops->tpl()->fetch($this->getTplPath('index')); |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
/** |
615
|
|
|
* displayIndex |
616
|
|
|
* |
617
|
|
|
* @return void |
618
|
|
|
*/ |
619
|
|
|
public function displayIndex() |
620
|
|
|
{ |
621
|
|
|
echo $this->renderIndex(); |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
/** |
625
|
|
|
* Render navigation to admin page |
626
|
|
|
* |
627
|
|
|
* @param string $menu current menu |
628
|
|
|
* |
629
|
|
|
* @return array |
630
|
|
|
*/ |
631
|
|
|
public function renderNavigation($menu = '') |
632
|
|
|
{ |
633
|
|
|
$xoops = \Xoops::getInstance(); |
634
|
|
|
$ret = array(); |
635
|
|
|
|
636
|
|
|
$this->module->loadAdminMenu(); |
637
|
|
|
foreach (array_keys($this->module->adminmenu) as $i) { |
638
|
|
|
if ($this->module->adminmenu[$i]['link'] == "admin/" . $menu) { |
639
|
|
|
if (\XoopsLoad::fileExists($xoops->path("media/xoops/images/icons/32/" . $this->module->adminmenu[$i]['icon']))) { |
640
|
|
|
$this->module->adminmenu[$i]['icon'] = $xoops->url("media/xoops/images/icons/32/". $this->module->adminmenu[$i]['icon']); |
641
|
|
|
} elseif (\XoopsLoad::fileExists($xoops->path("modules/" . $xoops->module->dirname() . "/assets/icons/32/" . $this->module->adminmenu[$i]['icon']))) { |
642
|
|
|
$this->module->adminmenu[$i]['icon'] = $xoops->url("modules/" . $xoops->module->dirname() . "/assets/icons/32/" . $this->module->adminmenu[$i]['icon']); |
643
|
|
|
} else { |
644
|
|
|
$this->module->adminmenu[$i]['icon'] = $xoops->url("modules/" . $xoops->module->dirname() . "/icons/32/". $this->module->adminmenu[$i]['icon']); |
645
|
|
|
} |
646
|
|
|
$xoops->tpl()->assign('xo_sys_navigation', $this->module->adminmenu[$i]); |
647
|
|
|
$ret[] = $xoops->tpl()->fetch($this->getTplPath('nav')); |
648
|
|
|
} |
649
|
|
|
} |
650
|
|
|
return $ret; |
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
/** |
654
|
|
|
* displayNavigation |
655
|
|
|
* |
656
|
|
|
* @param string $menu current menu |
657
|
|
|
* |
658
|
|
|
* @return void |
659
|
|
|
*/ |
660
|
|
|
public function displayNavigation($menu = '') |
661
|
|
|
{ |
662
|
|
|
$items = $this->renderNavigation($menu); |
663
|
|
|
foreach ($items as $item) { |
664
|
|
|
echo $item; |
665
|
|
|
} |
666
|
|
|
} |
667
|
|
|
|
668
|
|
|
/** |
669
|
|
|
* Render tips to admin page |
670
|
|
|
* |
671
|
|
|
* @return string |
672
|
|
|
*/ |
673
|
|
|
public function renderTips() |
674
|
|
|
{ |
675
|
|
|
$xoops = \Xoops::getInstance(); |
676
|
|
|
$xoops->tpl()->assign('xo_admin_tips', $this->tips); |
677
|
|
|
return $xoops->tpl()->fetch($this->getTplPath('tips')); |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
/** |
681
|
|
|
* displayTips |
682
|
|
|
* |
683
|
|
|
* @return void |
684
|
|
|
*/ |
685
|
|
|
public function displayTips() |
686
|
|
|
{ |
687
|
|
|
echo $this->renderTips(); |
688
|
|
|
} |
689
|
|
|
|
690
|
|
|
/** |
691
|
|
|
* Render about page |
692
|
|
|
* |
693
|
|
|
* @param bool $logo_xoops show logo |
694
|
|
|
* |
695
|
|
|
* @return bool|mixed|string |
696
|
|
|
*/ |
697
|
|
|
public function renderAbout($logo_xoops = true) |
698
|
|
|
{ |
699
|
|
|
$xoops = \Xoops::getInstance(); |
700
|
|
|
|
701
|
|
|
$date = explode('/', $this->module->getInfo('release_date')); |
|
|
|
|
702
|
|
|
$author = explode(',', $this->module->getInfo('author')); |
703
|
|
|
$nickname = explode(',', $this->module->getInfo('nickname')); |
704
|
|
|
$release_date = \XoopsLocale::formatTimestamp(mktime(0, 0, 0, $date[1], $date[2], $date[0]), 's'); |
|
|
|
|
705
|
|
|
|
706
|
|
|
$author_list = ''; |
707
|
|
|
foreach (array_keys($author) as $i) { |
708
|
|
|
$author_list .= $author[$i]; |
709
|
|
|
if (isset($nickname[$i]) && $nickname[$i] != '') { |
710
|
|
|
$author_list .= " (" . $nickname[$i] . "), "; |
711
|
|
|
} else { |
712
|
|
|
$author_list .= ", "; |
713
|
|
|
} |
714
|
|
|
} |
715
|
|
|
$changelog = ''; |
716
|
|
|
$language = $xoops->getConfig('locale'); |
717
|
|
|
if (!is_file( |
718
|
|
|
\XoopsBaseConfig::get('root-path') . "/modules/" . $this->module->getVar("dirname") |
719
|
|
|
. "/locale/" . $language . "/changelog.txt" |
720
|
|
|
)) { |
721
|
|
|
$language = 'en_US'; |
722
|
|
|
} |
723
|
|
|
$file = \XoopsBaseConfig::get('root-path') . "/modules/" . $this->module->getVar("dirname") |
724
|
|
|
. "/locale/" . $language . "/changelog.txt"; |
725
|
|
|
if (is_readable($file)) { |
726
|
|
|
$changelog = utf8_encode(implode("<br />", file($file))) . "\n"; |
727
|
|
|
} else { |
728
|
|
|
$file = \XoopsBaseConfig::get('root-path') . "/modules/" . $this->module->getVar("dirname") . "/docs/changelog.txt"; |
729
|
|
|
if (is_readable($file)) { |
730
|
|
|
$changelog = utf8_encode(implode("<br />", file($file))) . "\n"; |
731
|
|
|
} |
732
|
|
|
} |
733
|
|
|
$author_list = substr($author_list, 0, -2); |
734
|
|
|
|
735
|
|
|
$this->module->setInfo('release_date', $release_date); |
736
|
|
|
$this->module->setInfo('author_list', $author_list); |
737
|
|
|
if (is_array($this->module->getInfo('paypal'))) { |
738
|
|
|
$this->module->setInfo('paypal', $this->module->getInfo('paypal')); |
739
|
|
|
} |
740
|
|
|
$this->module->setInfo('changelog', $changelog); |
741
|
|
|
$xoops->tpl()->assign('module', $this->module); |
742
|
|
|
|
743
|
|
|
$this->addInfoBox(\XoopsLocale::MODULE_INFORMATION, 'info', 'id="xo-about"'); |
744
|
|
|
$this->addInfoBoxLine( |
745
|
|
|
\XoopsLocale::C_DESCRIPTION . ' ' . $this->module->getInfo("description"), |
|
|
|
|
746
|
|
|
'info' |
747
|
|
|
); |
748
|
|
|
$this->addInfoBoxLine( |
749
|
|
|
\XoopsLocale::C_UPDATE_DATE . ' <span class="bold">' |
750
|
|
|
. \XoopsLocale::formatTimestamp($this->module->getVar("last_update"), "m") |
751
|
|
|
. '</span>', |
752
|
|
|
'info' |
753
|
|
|
); |
754
|
|
|
$this->addInfoBoxLine( |
755
|
|
|
\XoopsLocale::C_WEBSITE . ' <a class="xo-tooltip" href="http://' |
756
|
|
|
. $this->module->getInfo("module_website_url") |
|
|
|
|
757
|
|
|
. '" rel="external" title="' |
758
|
|
|
. $this->module->getInfo("module_website_name") . ' - ' |
|
|
|
|
759
|
|
|
. $this->module->getInfo("module_website_url") . '">' |
760
|
|
|
. $this->module->getInfo("module_website_name") . '</a>', |
761
|
|
|
'info' |
762
|
|
|
); |
763
|
|
|
|
764
|
|
|
$xoops->tpl()->assign('xoops_logo', $logo_xoops); |
765
|
|
|
$xoops->tpl()->assign('xo_admin_box', $this->itemInfoBox); |
766
|
|
|
return $xoops->tpl()->fetch($this->getTplPath('about')); |
767
|
|
|
} |
768
|
|
|
|
769
|
|
|
/** |
770
|
|
|
* displayAbout |
771
|
|
|
* |
772
|
|
|
* @param bool $logo_xoops display logo |
773
|
|
|
* |
774
|
|
|
* @return void |
775
|
|
|
*/ |
776
|
|
|
public function displayAbout($logo_xoops = true) |
777
|
|
|
{ |
778
|
|
|
echo $this->renderAbout($logo_xoops); |
779
|
|
|
} |
780
|
|
|
} |
781
|
|
|
|