1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Module Admin |
4
|
|
|
* |
5
|
|
|
* You may not change or alter any portion of this comment or credits |
6
|
|
|
* of supporting developers from this source code or any supporting source code |
7
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
8
|
|
|
* This program is distributed in the hope that it will be useful, |
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
* |
12
|
|
|
* @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
13
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html) |
14
|
|
|
* @author Grégory Mage (Aka Mage) |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
class ModuleAdmin { |
18
|
|
|
|
19
|
|
|
private $_itemButton = []; |
20
|
|
|
private $_itemInfoBox = []; |
|
|
|
|
21
|
|
|
private $_itemInfoBoxLine = []; |
|
|
|
|
22
|
|
|
private $_itemConfigBoxLine = []; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var XoopsModule |
26
|
|
|
*/ |
27
|
|
|
private $_obj; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Constructor |
31
|
|
|
*/ |
32
|
|
|
public function __construct() |
33
|
|
|
{ |
34
|
|
|
global $xoopsModule; |
35
|
|
|
$this->_obj =& $xoopsModule; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* addAssets - add assets to theme, if it is established |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
|
private function addAssets() |
44
|
|
|
{ |
45
|
|
|
static $added; |
46
|
|
|
|
47
|
|
|
if (empty($added) && !empty($GLOBALS['xoTheme'])) { |
48
|
|
|
$added = true; |
49
|
|
|
$GLOBALS['xoTheme']->addStylesheet("modules/system/css/admin.css"); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Add Config Line |
55
|
|
|
* |
56
|
|
|
* @param string $value |
57
|
|
|
* @param string $status |
58
|
|
|
* @param string $type |
59
|
|
|
* |
60
|
|
|
* @return bool |
61
|
|
|
*/ |
62
|
|
|
public function addConfigBoxLine($value = '', $status = '', $type = 'default') |
63
|
|
|
{ |
64
|
|
|
$line = ''; |
|
|
|
|
65
|
|
|
|
66
|
|
|
switch ($type) { |
67
|
|
|
default: |
68
|
|
|
case 'default': |
69
|
|
|
$this->_itemConfigBoxLine['items'][] = [ |
70
|
|
|
'type' => $status, |
71
|
|
|
'msg' => $value, |
72
|
|
|
]; |
73
|
|
|
break; |
74
|
|
|
|
75
|
|
|
case 'folder': |
76
|
|
|
if (!is_dir($value)) { |
77
|
|
|
$this->_itemConfigBoxLine['items'][] = [ |
78
|
|
|
'type' => 'error', |
79
|
|
|
'msg' => sprintf(_AM_MODULEADMIN_CONFIG_FOLDERKO, $value), |
80
|
|
|
]; |
81
|
|
|
} else { |
82
|
|
|
$this->_itemConfigBoxLine['items'][] = [ |
83
|
|
|
'type' => 'success', |
84
|
|
|
'msg' => sprintf(_AM_MODULEADMIN_CONFIG_FOLDERKO, $value), |
85
|
|
|
]; |
86
|
|
|
} |
87
|
|
|
break; |
88
|
|
|
|
89
|
|
|
case 'chmod': |
90
|
|
|
if (is_dir($value[0])) { |
91
|
|
|
if (substr(decoct(fileperms($value[0])), 2) != $value[1]) { |
92
|
|
|
$this->_itemConfigBoxLine['items'][] = [ |
93
|
|
|
'type' => 'error', |
94
|
|
|
'msg' => sprintf(_AM_MODULEADMIN_CONFIG_CHMOD, $value[0], $value[1], substr(decoct(fileperms($value[0])), 2)), |
95
|
|
|
]; |
96
|
|
|
} else { |
97
|
|
|
$this->_itemConfigBoxLine['items'][] = [ |
98
|
|
|
'type' => 'success', |
99
|
|
|
'msg' => sprintf(_AM_MODULEADMIN_CONFIG_CHMOD, $value[0], $value[1], substr(decoct(fileperms($value[0])), 2)), |
100
|
|
|
]; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
break; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return true; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param $title |
111
|
|
|
* @param $link |
112
|
|
|
* @param string $icon |
113
|
|
|
* @param string $extra |
114
|
|
|
* |
115
|
|
|
* @return bool |
116
|
|
|
*/ |
117
|
|
|
public function addItemButton($title, $link, $icon = 'add', $extra = '') |
118
|
|
|
{ |
119
|
|
|
$ret = []; |
120
|
|
|
$ret['title'] = $title; |
121
|
|
|
$ret['link'] = $link; |
122
|
|
|
$ret['icon'] = $icon . '.png'; |
123
|
|
|
$ret['extra'] = $extra; |
124
|
|
|
$this->_itemButton[] = $ret; |
125
|
|
|
|
126
|
|
|
return true; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Add Nivagition Menu |
131
|
|
|
* |
132
|
|
|
* @param string $menu |
133
|
|
|
* @return void |
134
|
|
|
*/ |
135
|
|
|
public function addNavigation($menu = '') |
136
|
|
|
{ |
137
|
|
|
global $xoops, $xoopsTpl; |
138
|
|
|
|
139
|
|
|
$this->addAssets(); |
140
|
|
|
$path = $xoops->url('modules/' . $this->_obj->getVar('dirname') . '/'); |
141
|
|
|
|
142
|
|
|
$this->_obj->loadAdminMenu(); |
143
|
|
|
|
144
|
|
|
$xoopsTpl->assign('path', $path); |
145
|
|
|
$xoopsTpl->assign('menu', $menu); |
146
|
|
|
|
147
|
|
|
|
148
|
|
|
foreach (array_keys((array) $this->_obj->adminmenu) as $i) { |
149
|
|
|
if ($this->_obj->adminmenu[$i]['link'] == 'admin/' . $menu) { |
150
|
|
|
$xoopsTpl->assign('icon', $this->_obj->adminmenu[$i]['icon']); |
151
|
|
|
$xoopsTpl->assign('title', $this->_obj->adminmenu[$i]['title']); |
152
|
|
|
$xoopsTpl->assign('link', $this->_obj->adminmenu[$i]['link']); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
// Display Navigation |
156
|
|
|
$xoopsTpl->display('db:system_modules_navigation.tpl'); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Display Admin About page |
161
|
|
|
* |
162
|
|
|
* @param string $business the PAYPAL business email or Merchant Account ID |
163
|
|
|
* @param bool $logo_xoops true to display XOOPS logo and link on page |
164
|
|
|
* @return void |
165
|
|
|
*/ |
166
|
|
|
public function renderAbout($business = '', $logo_xoops = true) |
|
|
|
|
167
|
|
|
{ |
168
|
|
|
global $xoops, $xoopsTpl; |
169
|
|
|
|
170
|
|
|
$this->addAssets(); |
171
|
|
|
|
172
|
|
|
$date = preg_replace('/-\\\/', '/', $this->_obj->getInfo('release_date')); // make format a little more forgiving |
173
|
|
|
$date = explode('/', $date); |
174
|
|
|
$author = explode(',', $this->_obj->getInfo('author')); |
|
|
|
|
175
|
|
|
$nickname = explode(',', $this->_obj->getInfo('nickname')); |
176
|
|
|
$release_date = formatTimestamp(mktime(0, 0, 0, $date[1], $date[2], $date[0]), 's'); |
|
|
|
|
177
|
|
|
$module_dir = $this->_obj->getVar('dirname'); |
178
|
|
|
|
179
|
|
|
$license_url = $this->_obj->getInfo('license_url'); |
180
|
|
|
$license_url = preg_match('%^(https?:)?//%', $license_url) ? $license_url : 'http://' . $license_url; |
|
|
|
|
181
|
|
|
$website = $this->_obj->getInfo('website'); |
182
|
|
|
$website = preg_match('%^(https?:)?//%', $website) ? $website : 'http://' . $website; |
|
|
|
|
183
|
|
|
|
184
|
|
|
$xoopsTpl->assign('module_dir', $module_dir); |
185
|
|
|
$xoopsTpl->assign('module_name', $this->_obj->getVar('name')); |
186
|
|
|
$xoopsTpl->assign('module_version', $this->_obj->getVar('version')); |
187
|
|
|
$xoopsTpl->assign('module_img', $xoops->url('modules/' . $module_dir . '/' . $this->_obj->getInfo('image'))); |
|
|
|
|
188
|
|
|
|
189
|
|
|
// Author |
190
|
|
|
$authorArray = []; |
191
|
|
|
foreach ( $author as $k => $aName ) { |
192
|
|
|
$authorArray[$k] = ( isset( $nickname[$k] ) && ( '' != $nickname[$k] ) ) ? "{$aName} ({$nickname[$k]})" : (string)($aName); |
193
|
|
|
} |
194
|
|
|
$xoopsTpl->assign('author', implode(', ', $authorArray)); |
195
|
|
|
$xoopsTpl->assign('release_date', $release_date); |
196
|
|
|
$xoopsTpl->assign('license', $this->_obj->getInfo('license')); |
197
|
|
|
$xoopsTpl->assign('license_url', $license_url); |
198
|
|
|
|
199
|
|
|
// Module Info |
200
|
|
|
$xoopsTpl->assign('module_description', $this->_obj->getInfo('description')); |
201
|
|
|
$xoopsTpl->assign('module_last_update', formatTimestamp($this->_obj->getVar('last_update'), 'm')); |
202
|
|
|
$xoopsTpl->assign('module_status', $this->_obj->getStatus()); |
203
|
|
|
$xoopsTpl->assign('module_website_name', $this->_obj->getInfo('module_website_name')); |
204
|
|
|
$xoopsTpl->assign('module_website_url', $this->_obj->getInfo('module_website_url')); |
205
|
|
|
|
206
|
|
|
// Donation |
207
|
|
|
if ((1 !== preg_match('/[^a-zA-Z0-9]/', $business)) || (false !== checkEmail($business))) { |
208
|
|
|
$xoopsTpl->assign('business', $business); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
// Changelog |
212
|
|
|
$changelog = ''; |
213
|
|
|
$language = empty( $GLOBALS['xoopsConfig']['language'] ) ? 'english' : $GLOBALS['xoopsConfig']['language']; |
214
|
|
|
$file = XOOPS_ROOT_PATH . "/modules/{$module_dir}/language/{$language}/changelog.txt"; |
215
|
|
|
if ( !is_file( $file ) && ( 'english' !== $language ) ) { |
216
|
|
|
$file = XOOPS_ROOT_PATH . "/modules/{$module_dir}/language/english/changelog.txt"; |
217
|
|
|
} |
218
|
|
|
if ( is_readable( $file ) ) { |
219
|
|
|
$changelog .= ( implode( '<br>', file( $file ) ) ) . "\n"; |
220
|
|
|
} else { |
221
|
|
|
$file = XOOPS_ROOT_PATH . "/modules/{$module_dir}/docs/changelog.txt"; |
222
|
|
|
if ( is_readable( $file ) ) { |
223
|
|
|
$changelog .= implode( '<br>', file( $file ) ) . "\n"; |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
$xoopsTpl->assign('changelog', $changelog); |
227
|
|
|
|
228
|
|
|
// Display page |
229
|
|
|
$xoopsTpl->display('db:system_modules_about.tpl'); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @param string $position |
234
|
|
|
* @param string $delimeter |
235
|
|
|
* |
236
|
|
|
* @return string |
237
|
|
|
*/ |
238
|
|
|
public function renderButton($position = 'right', $delimeter = ' ') |
|
|
|
|
239
|
|
|
{ |
240
|
|
|
global $xoops, $xoopsTpl; |
241
|
|
|
|
242
|
|
|
$icons = xoops_getModuleOption('typeicons', 'system'); |
|
|
|
|
243
|
|
|
if ($icons == '') { |
244
|
|
|
$icons = 'default'; |
245
|
|
|
} |
246
|
|
|
$path = $xoops->url('modules/system/images/icons/' . $icons . '/'); |
247
|
|
|
|
248
|
|
|
|
249
|
|
|
$this->addAssets(); |
250
|
|
|
|
251
|
|
|
$xoopsTpl->assign('path', $path); |
252
|
|
|
$xoopsTpl->assign('buttons', $this->_itemButton ); |
253
|
|
|
$xoopsTpl->assign('position', $position); |
254
|
|
|
|
255
|
|
|
$xoopsTpl->display('db:system_modules_button.tpl'); |
256
|
|
|
|
257
|
|
|
$path = XOOPS_URL . '/Frameworks/moduleclasses/icons/32/'; |
|
|
|
|
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Display Admin Index page |
262
|
|
|
* |
263
|
|
|
* @return void |
264
|
|
|
*/ |
265
|
|
|
public function renderIndex() |
266
|
|
|
{ |
267
|
|
|
global $xoops, $xoopsTpl; |
268
|
|
|
|
269
|
|
|
$this->addAssets(); |
270
|
|
|
$path = XOOPS_URL . '/modules/' . $this->_obj->getVar('dirname') . '/'; |
271
|
|
|
$pathsystem = XOOPS_URL . '/modules/system/'; |
|
|
|
|
272
|
|
|
|
273
|
|
|
$this->_obj->loadAdminMenu(); |
274
|
|
|
|
275
|
|
|
// Help page |
276
|
|
|
if ($this->_obj->getInfo('help')) { |
277
|
|
|
$icons = xoops_getModuleOption('typeicons', 'system'); |
|
|
|
|
278
|
|
|
if ($icons == '') { |
279
|
|
|
$icons = 'default'; |
280
|
|
|
} |
281
|
|
|
$xoopsTpl->assign('helpurl',$xoops->url('modules/system/help.php?mid=' . $this->_obj->getVar('mid', 's') . '&page=' . $this->_obj->getInfo('help'))); |
|
|
|
|
282
|
|
|
$xoopsTpl->assign('helpicon', $xoops->url('modules/system/images/icons/' . $icons . '/help.png')); |
283
|
|
|
$xoopsTpl->assign('help', $this->_obj->getInfo('help')); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
// Menu |
287
|
|
|
$xoopsTpl->assign('path', $path); |
288
|
|
|
$xoopsTpl->assign('modulenmenu', $this->_obj->adminmenu); |
289
|
|
|
|
290
|
|
|
// Info Box |
291
|
|
|
if ($this->_obj->getInfo('min_php') || $this->_obj->getInfo('min_xoops') || !empty($this->_itemConfigBoxLine)) { |
292
|
|
|
|
293
|
|
|
// PHP version |
294
|
|
|
if ($this->_obj->getInfo('min_php')) { |
295
|
|
|
if (version_compare(phpversion(), strtolower($this->_obj->getInfo('min_php')), '<')) { |
|
|
|
|
296
|
|
|
$this->addConfigBoxLine( sprintf(_AM_MODULEADMIN_CONFIG_PHP, $this->_obj->getInfo('min_php'), phpversion()), 'error'); |
|
|
|
|
297
|
|
|
} else { |
298
|
|
|
$this->addConfigBoxLine( sprintf(_AM_MODULEADMIN_CONFIG_PHP, $this->_obj->getInfo('min_php'), phpversion()), 'success'); |
299
|
|
|
} |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
// Database version |
303
|
|
|
$dbarray = $this->_obj->getInfo('min_db'); |
304
|
|
|
if ($dbarray!=false) { |
305
|
|
|
// changes from redheadedrod to use connector specific version info |
306
|
|
|
switch (XOOPS_DB_TYPE) { |
307
|
|
|
// server should be the same in both cases |
308
|
|
|
case 'mysql': |
309
|
|
|
case 'mysqli': |
310
|
|
|
global $xoopsDB; |
311
|
|
|
$dbCurrentVersion = $xoopsDB->getServerVersion(); |
312
|
|
|
break; |
313
|
|
|
default: // don't really support anything other than mysql |
314
|
|
|
$dbCurrentVersion = '0'; |
315
|
|
|
break; |
316
|
|
|
} |
317
|
|
|
$currentVerParts = explode('.', (string)$dbCurrentVersion); |
318
|
|
|
$iCurrentVerParts = array_map('intval', $currentVerParts); |
319
|
|
|
$dbRequiredVersion = $dbarray[XOOPS_DB_TYPE]; |
320
|
|
|
$reqVerParts = explode('.', (string)$dbRequiredVersion); |
321
|
|
|
$iReqVerParts = array_map('intval', $reqVerParts); |
322
|
|
|
$icount = $j = count($iReqVerParts); |
323
|
|
|
$reqVer = $curVer = 0; |
324
|
|
|
for ($i = 0; $i < $icount; ++$i) { |
325
|
|
|
$j--; |
326
|
|
|
$reqVer += $iReqVerParts[$i] * 10 ** $j; |
327
|
|
|
if (isset($iCurrentVerParts[$i])) { |
328
|
|
|
$curVer += $iCurrentVerParts[$i] * 10 ** $j; |
329
|
|
|
} else { |
330
|
|
|
$curVer *= 10 ** $j; |
331
|
|
|
} |
332
|
|
|
} |
333
|
|
|
if ($reqVer > $curVer) { |
334
|
|
|
$this->addConfigBoxLine( sprintf(XOOPS_DB_TYPE . ' ' . _AM_MODULEADMIN_CONFIG_DB, $dbRequiredVersion, $dbCurrentVersion), 'error'); |
335
|
|
|
} else { |
336
|
|
|
$this->addConfigBoxLine( sprintf(XOOPS_DB_TYPE . ' ' . _AM_MODULEADMIN_CONFIG_DB, $dbRequiredVersion, $dbCurrentVersion), 'success'); |
337
|
|
|
} |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
// Xoops version |
341
|
|
|
if ($this->_obj->getInfo('min_xoops')) { |
342
|
|
|
$currentXoopsVersion = strtolower(str_replace('XOOPS ', '', XOOPS_VERSION)); |
343
|
|
|
if ($this->_obj->versionCompare($currentXoopsVersion, strtolower($this->_obj->getInfo('min_xoops')), '<')) { |
344
|
|
|
$this->addConfigBoxLine( sprintf(_AM_MODULEADMIN_CONFIG_XOOPS, $this->_obj->getInfo('min_xoops'), substr(XOOPS_VERSION, 6, strlen(XOOPS_VERSION) - 6)), 'error'); |
345
|
|
|
} else { |
346
|
|
|
$this->addConfigBoxLine( sprintf(_AM_MODULEADMIN_CONFIG_XOOPS, $this->_obj->getInfo('min_xoops'), substr(XOOPS_VERSION, 6)), 'success'); |
347
|
|
|
} |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
$xoopsTpl->assign('ret_info', $this->_itemConfigBoxLine); |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
// Display page |
354
|
|
|
$xoopsTpl->display('db:system_modules_index.tpl'); |
355
|
|
|
} |
356
|
|
|
} |