1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* XOOPS Kernel Class |
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
|
|
|
* @package kernel |
15
|
|
|
* @since 2.0.0 |
16
|
|
|
*/ |
17
|
|
|
defined('XOOPS_ROOT_PATH') || exit('Restricted access'); |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* A Module |
21
|
|
|
* |
22
|
|
|
* @package kernel |
23
|
|
|
* @author Kazumi Ono <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class XoopsModule extends XoopsObject |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
public $modinfo; |
32
|
|
|
/** |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
public $adminmenu; |
37
|
|
|
/** |
38
|
|
|
* |
39
|
|
|
* @var array |
40
|
|
|
*/ |
41
|
|
|
public $_msg; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Constructor |
45
|
|
|
*/ |
46
|
|
|
public function __construct() |
47
|
|
|
{ |
48
|
|
|
parent::__construct(); |
49
|
|
|
$this->initVar('mid', XOBJ_DTYPE_INT, null, false); |
50
|
|
|
$this->initVar('name', XOBJ_DTYPE_TXTBOX, null, true, 150); |
51
|
|
|
$this->initVar('version', XOBJ_DTYPE_TXTBOX, null, false); |
52
|
|
|
$this->initVar('last_update', XOBJ_DTYPE_INT, null, false); |
53
|
|
|
$this->initVar('weight', XOBJ_DTYPE_INT, 0, false); |
54
|
|
|
$this->initVar('isactive', XOBJ_DTYPE_INT, 1, false); |
55
|
|
|
$this->initVar('dirname', XOBJ_DTYPE_OTHER, null, true); |
56
|
|
|
$this->initVar('hasmain', XOBJ_DTYPE_INT, 0, false); |
57
|
|
|
$this->initVar('hasadmin', XOBJ_DTYPE_INT, 0, false); |
58
|
|
|
$this->initVar('hassearch', XOBJ_DTYPE_INT, 0, false); |
59
|
|
|
$this->initVar('hasconfig', XOBJ_DTYPE_INT, 0, false); |
60
|
|
|
$this->initVar('hascomments', XOBJ_DTYPE_INT, 0, false); |
61
|
|
|
// RMV-NOTIFY |
62
|
|
|
$this->initVar('hasnotification', XOBJ_DTYPE_INT, 0, false); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Load module info |
67
|
|
|
* |
68
|
|
|
* @param string $dirname Directory Name |
69
|
|
|
* @param boolean $verbose |
70
|
|
|
*/ |
71
|
|
|
public function loadInfoAsVar($dirname, $verbose = true) |
72
|
|
|
{ |
73
|
|
|
$dirname = basename($dirname); |
74
|
|
|
if (!isset($this->modinfo)) { |
75
|
|
|
$this->loadInfo($dirname, $verbose); |
76
|
|
|
} |
77
|
|
|
$this->setVar('name', $this->modinfo['name'], true); |
78
|
|
|
$this->setVar('version', $this->modinfo['version'], true); |
79
|
|
|
$this->setVar('dirname', $this->modinfo['dirname'], true); |
80
|
|
|
$hasmain = (isset($this->modinfo['hasMain']) && $this->modinfo['hasMain'] == 1) ? 1 : 0; |
81
|
|
|
$hasadmin = (isset($this->modinfo['hasAdmin']) && $this->modinfo['hasAdmin'] == 1) ? 1 : 0; |
82
|
|
|
$hassearch = (isset($this->modinfo['hasSearch']) && $this->modinfo['hasSearch'] == 1) ? 1 : 0; |
83
|
|
|
$hasconfig = ((isset($this->modinfo['config']) && is_array($this->modinfo['config'])) || !empty($this->modinfo['hasComments'])) ? 1 : 0; |
84
|
|
|
$hascomments = (isset($this->modinfo['hasComments']) && $this->modinfo['hasComments'] == 1) ? 1 : 0; |
85
|
|
|
// RMV-NOTIFY |
86
|
|
|
$hasnotification = (isset($this->modinfo['hasNotification']) && $this->modinfo['hasNotification'] == 1) ? 1 : 0; |
87
|
|
|
$this->setVar('hasmain', $hasmain); |
88
|
|
|
$this->setVar('hasadmin', $hasadmin); |
89
|
|
|
$this->setVar('hassearch', $hassearch); |
90
|
|
|
$this->setVar('hasconfig', $hasconfig); |
91
|
|
|
$this->setVar('hascomments', $hascomments); |
92
|
|
|
// RMV-NOTIFY |
93
|
|
|
$this->setVar('hasnotification', $hasnotification); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* add a message |
98
|
|
|
* |
99
|
|
|
* @param string $str message to add |
100
|
|
|
* @access public |
101
|
|
|
*/ |
102
|
|
|
public function setMessage($str) |
103
|
|
|
{ |
104
|
|
|
$this->_msg[] = trim($str); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* return the messages for this object as an array |
109
|
|
|
* |
110
|
|
|
* @return array an array of messages |
111
|
|
|
* @access public |
112
|
|
|
*/ |
113
|
|
|
public function getMessages() |
114
|
|
|
{ |
115
|
|
|
return $this->_msg; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Set module info |
120
|
|
|
* |
121
|
|
|
* @param string $name |
122
|
|
|
* @param mixed $value |
123
|
|
|
* @return bool |
124
|
|
|
**/ |
125
|
|
|
public function setInfo($name, $value) |
126
|
|
|
{ |
127
|
|
|
if (empty($name)) { |
128
|
|
|
$this->modinfo = $value; |
129
|
|
|
} else { |
130
|
|
|
$this->modinfo[$name] = $value; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
return true; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Get module info |
138
|
|
|
* |
139
|
|
|
* @param string $name |
140
|
|
|
* @return array|string Array of module information. |
141
|
|
|
* If {@link $name} is set, returns a single module information item as string. |
142
|
|
|
*/ |
143
|
|
|
public function &getInfo($name = null) |
144
|
|
|
{ |
145
|
|
|
if (!isset($this->modinfo)) { |
146
|
|
|
$this->loadInfo($this->getVar('dirname')); |
|
|
|
|
147
|
|
|
} |
148
|
|
|
if (isset($name)) { |
149
|
|
|
if (isset($this->modinfo[$name])) { |
150
|
|
|
return $this->modinfo[$name]; |
151
|
|
|
} |
152
|
|
|
$return = false; |
153
|
|
|
|
154
|
|
|
return $return; |
|
|
|
|
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
return $this->modinfo; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Get statut |
162
|
|
|
* |
163
|
|
|
* @return string |
164
|
|
|
*/ |
165
|
|
|
public function getStatus() |
166
|
|
|
{ |
167
|
|
|
return substr(strrchr($this->getVar('version'), '-'), 1); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Compares two "XOOPS-standardized" version number strings. |
172
|
|
|
* |
173
|
|
|
* @param string $version1 |
174
|
|
|
* @param string $version2 |
175
|
|
|
* @param string $operator |
176
|
|
|
* @return boolean The function will return true if the relationship is the one specified by the operator, false otherwise. |
177
|
|
|
*/ |
178
|
|
|
public function versionCompare($version1 = '',$version2 = '', $operator = '<') |
179
|
|
|
{ |
180
|
|
|
$version1 = strtolower($version1); |
181
|
|
|
$version2 = strtolower($version2); |
182
|
|
|
if (true == strpos($version2, '-stable')){ |
|
|
|
|
183
|
|
|
$version2 = substr($version2, 0, strpos($version2, '-stable')); |
184
|
|
|
} |
185
|
|
|
if (true == strpos($version1, '-stable')){ |
|
|
|
|
186
|
|
|
$version1 = substr($version1, 0, strpos($version1, '-stable')); |
187
|
|
|
} |
188
|
|
|
return version_compare($version1, $version2, $operator); |
|
|
|
|
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Get a link to the modules main page |
193
|
|
|
* |
194
|
|
|
* @return string FALSE on fail |
195
|
|
|
*/ |
196
|
|
|
public function mainLink() |
197
|
|
|
{ |
198
|
|
|
if ($this->getVar('hasmain') == 1) { |
199
|
|
|
$ret = '<a href="' . XOOPS_URL . '/modules/' . $this->getVar('dirname') . '/">' . $this->getVar('name') . '</a>'; |
200
|
|
|
|
201
|
|
|
return $ret; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
return false; |
|
|
|
|
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Get links to the subpages |
209
|
|
|
* |
210
|
|
|
* @return string |
211
|
|
|
*/ |
212
|
|
|
public function subLink() |
213
|
|
|
{ |
214
|
|
|
$ret = array(); |
215
|
|
|
if ($this->getInfo('sub') && is_array($this->getInfo('sub'))) { |
216
|
|
|
foreach ($this->getInfo('sub') as $submenu) { |
217
|
|
|
$ret[] = array( |
218
|
|
|
'name' => $submenu['name'], |
219
|
|
|
'url' => $submenu['url']); |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
return $ret; |
|
|
|
|
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Load the admin menu for the module |
228
|
|
|
*/ |
229
|
|
|
public function loadAdminMenu() |
230
|
|
|
{ |
231
|
|
|
$adminmenu = array(); |
232
|
|
|
if ($this->getInfo('adminmenu') && $this->getInfo('adminmenu') != '' && file_exists(XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/' . $this->getInfo('adminmenu'))) { |
|
|
|
|
233
|
|
|
include XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/' . $this->getInfo('adminmenu'); |
234
|
|
|
} |
235
|
|
|
$this->adminmenu =& $adminmenu; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Get the admin menu for the module |
240
|
|
|
* |
241
|
|
|
* @return string |
242
|
|
|
*/ |
243
|
|
|
public function &getAdminMenu() |
244
|
|
|
{ |
245
|
|
|
if (!isset($this->adminmenu)) { |
246
|
|
|
$this->loadAdminMenu(); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
return $this->adminmenu; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Load the module info for this module |
254
|
|
|
* |
255
|
|
|
* @param string $dirname Module directory |
256
|
|
|
* @param bool $verbose Give an error on fail? |
257
|
|
|
* |
258
|
|
|
* @return bool true if loaded |
259
|
|
|
*/ |
260
|
|
|
public function loadInfo($dirname, $verbose = true) |
261
|
|
|
{ |
262
|
|
|
static $modVersions; |
263
|
|
|
$dirname = basename($dirname); |
264
|
|
|
if (isset($modVersions[$dirname])) { |
265
|
|
|
$this->modinfo = $modVersions[$dirname]; |
266
|
|
|
|
267
|
|
|
return true; |
268
|
|
|
} |
269
|
|
|
global $xoopsConfig; |
270
|
|
|
if (file_exists($file = $GLOBALS['xoops']->path('modules/' . $dirname . '/language/' . $xoopsConfig['language'] . '/modinfo.php'))) { |
271
|
|
|
include_once $file; |
272
|
|
|
} elseif (file_exists($file = $GLOBALS['xoops']->path('modules/' . $dirname . '/language/english/modinfo.php'))) { |
273
|
|
|
include_once $file; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
if (!file_exists($file = $GLOBALS['xoops']->path('modules/' . $dirname . '/xoops_version.php'))) { |
277
|
|
|
if (false !== (bool)$verbose) { |
278
|
|
|
echo "Module File for $dirname Not Found!"; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
return false; |
282
|
|
|
} |
283
|
|
|
include $file; |
284
|
|
|
$modVersions[$dirname] = $modversion; |
|
|
|
|
285
|
|
|
$this->modinfo = $modVersions[$dirname]; |
286
|
|
|
|
287
|
|
|
return true; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Search contents within a module |
292
|
|
|
* |
293
|
|
|
* @param string $term |
294
|
|
|
* @param string $andor 'AND' or 'OR' |
295
|
|
|
* @param integer $limit |
296
|
|
|
* @param integer $offset |
297
|
|
|
* @param integer $userid |
298
|
|
|
* @return mixed Search result. |
299
|
|
|
*/ |
300
|
|
|
public function search($term = '', $andor = 'AND', $limit = 0, $offset = 0, $userid = 0) |
301
|
|
|
{ |
302
|
|
|
if ($this->getVar('hassearch') != 1) { |
303
|
|
|
return false; |
304
|
|
|
} |
305
|
|
|
$search =& $this->getInfo('search'); |
306
|
|
|
if ($this->getVar('hassearch') != 1 || !isset($search['file']) || !isset($search['func']) || $search['func'] == '' || $search['file'] == '') { |
307
|
|
|
return false; |
308
|
|
|
} |
309
|
|
|
if (file_exists($file = $GLOBALS['xoops']->path('modules/' . $this->getVar('dirname') . '/' . $search['file']))) { |
310
|
|
|
include_once $file; |
311
|
|
|
} else { |
312
|
|
|
return false; |
313
|
|
|
} |
314
|
|
|
if (function_exists($search['func'])) { |
315
|
|
|
$func = $search['func']; |
316
|
|
|
|
317
|
|
|
return $func($term, $andor, $limit, $offset, $userid); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
return false; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* Returns Class Base Variable mid |
325
|
|
|
* @param string $format |
326
|
|
|
* @return mixed |
327
|
|
|
*/ |
328
|
|
|
public function id($format = 'N') |
329
|
|
|
{ |
330
|
|
|
return $this->getVar('mid', $format); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* Returns Class Base Variable mid |
335
|
|
|
* @param string $format |
336
|
|
|
* @return mixed |
337
|
|
|
*/ |
338
|
|
|
public function mid($format = '') |
339
|
|
|
{ |
340
|
|
|
return $this->getVar('mid', $format); |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* Returns Class Base Variable name |
345
|
|
|
* @param string $format |
346
|
|
|
* @return mixed |
347
|
|
|
*/ |
348
|
|
|
public function name($format = '') |
349
|
|
|
{ |
350
|
|
|
return $this->getVar('name', $format); |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* Returns Class Base Variable version |
355
|
|
|
* @param string $format |
356
|
|
|
* @return mixed |
357
|
|
|
*/ |
358
|
|
|
public function version($format = '') |
359
|
|
|
{ |
360
|
|
|
return $this->getVar('version', $format); |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* Returns Class Base Variable last_update |
365
|
|
|
* @param string $format |
366
|
|
|
* @return mixed |
367
|
|
|
*/ |
368
|
|
|
public function last_update($format = '') |
369
|
|
|
{ |
370
|
|
|
return $this->getVar('last_update', $format); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* Returns Class Base Variable weight |
375
|
|
|
* @param string $format |
376
|
|
|
* @return mixed |
377
|
|
|
*/ |
378
|
|
|
public function weight($format = '') |
379
|
|
|
{ |
380
|
|
|
return $this->getVar('weight', $format); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* Returns Class Base Variable isactive |
385
|
|
|
* @param string $format |
386
|
|
|
* @return mixed |
387
|
|
|
*/ |
388
|
|
|
public function isactive($format = '') |
389
|
|
|
{ |
390
|
|
|
return $this->getVar('isactive', $format); |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* Returns Class Base Variable dirname |
395
|
|
|
* @param string $format |
396
|
|
|
* @return mixed |
397
|
|
|
*/ |
398
|
|
|
public function dirname($format = '') |
399
|
|
|
{ |
400
|
|
|
return $this->getVar('dirname', $format); |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* Returns Class Base Variable hasmain |
405
|
|
|
* @param string $format |
406
|
|
|
* @return mixed |
407
|
|
|
*/ |
408
|
|
|
public function hasmain($format = '') |
409
|
|
|
{ |
410
|
|
|
return $this->getVar('hasmain', $format); |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
/** |
414
|
|
|
* Returns Class Base Variable hasadmin |
415
|
|
|
* @param string $format |
416
|
|
|
* @return mixed |
417
|
|
|
*/ |
418
|
|
|
public function hasadmin($format = '') |
419
|
|
|
{ |
420
|
|
|
return $this->getVar('hasadmin', $format); |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
/** |
424
|
|
|
* Returns Class Base Variable hassearch |
425
|
|
|
* @param string $format |
426
|
|
|
* @return mixed |
427
|
|
|
*/ |
428
|
|
|
public function hassearch($format = '') |
429
|
|
|
{ |
430
|
|
|
return $this->getVar('hassearch', $format); |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
/** |
434
|
|
|
* Returns Class Base Variable hasconfig |
435
|
|
|
* @param string $format |
436
|
|
|
* @return mixed |
437
|
|
|
*/ |
438
|
|
|
public function hasconfig($format = '') |
439
|
|
|
{ |
440
|
|
|
return $this->getVar('hasconfig', $format); |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
/** |
444
|
|
|
* Returns Class Base Variable hascomments |
445
|
|
|
* @param string $format |
446
|
|
|
* @return mixed |
447
|
|
|
*/ |
448
|
|
|
public function hascomments($format = '') |
449
|
|
|
{ |
450
|
|
|
return $this->getVar('hascomments', $format); |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
/** |
454
|
|
|
* Returns Class Base Variable hasnotification |
455
|
|
|
* @param string $format |
456
|
|
|
* @return mixed |
457
|
|
|
*/ |
458
|
|
|
public function hasnotification($format = '') |
459
|
|
|
{ |
460
|
|
|
return $this->getVar('hasnotification', $format); |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* @param $dirname |
465
|
|
|
* |
466
|
|
|
* @return mixed |
467
|
|
|
*/ |
468
|
|
|
public static function getByDirname($dirname) |
469
|
|
|
{ |
470
|
|
|
/* @var XoopsModuleHandler $modhandler */ |
471
|
|
|
$modhandler = xoops_getHandler('module'); |
472
|
|
|
$inst = $modhandler->getByDirname($dirname); |
473
|
|
|
|
474
|
|
|
return $inst; |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
##################### Deprecated Methods ###################### |
478
|
|
|
|
479
|
|
|
/**#@+ |
480
|
|
|
* @deprecated |
481
|
|
|
*/ |
482
|
|
|
public function checkAccess() |
483
|
|
|
{ |
484
|
|
|
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING); |
485
|
|
|
|
486
|
|
|
return false; |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
/** |
490
|
|
|
* @param string $type |
491
|
|
|
* |
492
|
|
|
* @return bool |
493
|
|
|
*/ |
494
|
|
|
public function loadLanguage($type = 'main') |
|
|
|
|
495
|
|
|
{ |
496
|
|
|
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING); |
497
|
|
|
|
498
|
|
|
return false; |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
/** |
502
|
|
|
* @return bool |
503
|
|
|
*/ |
504
|
|
|
public function loadErrorMessages() |
505
|
|
|
{ |
506
|
|
|
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING); |
507
|
|
|
|
508
|
|
|
return false; |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
/** |
512
|
|
|
* @return bool |
513
|
|
|
*/ |
514
|
|
|
public function getCurrentPage() |
515
|
|
|
{ |
516
|
|
|
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING); |
517
|
|
|
|
518
|
|
|
return false; |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
/** |
522
|
|
|
* @param array $admingroups |
523
|
|
|
* @param array $accessgroups |
524
|
|
|
* |
525
|
|
|
* @return bool |
526
|
|
|
*/ |
527
|
|
|
public function install($admingroups = array(), $accessgroups = array()) |
|
|
|
|
528
|
|
|
{ |
529
|
|
|
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING); |
530
|
|
|
|
531
|
|
|
return false; |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
/** |
535
|
|
|
* @return bool |
536
|
|
|
*/ |
537
|
|
|
public function update() |
538
|
|
|
{ |
539
|
|
|
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING); |
540
|
|
|
|
541
|
|
|
return false; |
542
|
|
|
} |
543
|
|
|
|
544
|
|
|
/** |
545
|
|
|
* @return bool |
546
|
|
|
*/ |
547
|
|
|
public function insert() |
548
|
|
|
{ |
549
|
|
|
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING); |
550
|
|
|
|
551
|
|
|
return false; |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
/** |
555
|
|
|
* @return bool |
556
|
|
|
*/ |
557
|
|
|
public function executeSQL() |
558
|
|
|
{ |
559
|
|
|
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING); |
560
|
|
|
|
561
|
|
|
return false; |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
/** |
565
|
|
|
* @return bool |
566
|
|
|
*/ |
567
|
|
|
public function insertTemplates() |
568
|
|
|
{ |
569
|
|
|
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING); |
570
|
|
|
|
571
|
|
|
return false; |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
/** |
575
|
|
|
* @param $template |
576
|
|
|
* @param bool $block |
577
|
|
|
* |
578
|
|
|
* @return bool |
579
|
|
|
*/ |
580
|
|
|
public function gettemplate($template, $block = false) |
|
|
|
|
581
|
|
|
{ |
582
|
|
|
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING); |
583
|
|
|
|
584
|
|
|
return false; |
585
|
|
|
} |
586
|
|
|
|
587
|
|
|
/** |
588
|
|
|
* @return bool |
589
|
|
|
*/ |
590
|
|
|
public function insertBlocks() |
591
|
|
|
{ |
592
|
|
|
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING); |
593
|
|
|
|
594
|
|
|
return false; |
595
|
|
|
} |
596
|
|
|
|
597
|
|
|
/** |
598
|
|
|
* @return bool |
599
|
|
|
*/ |
600
|
|
|
public function insertConfigCategories() |
601
|
|
|
{ |
602
|
|
|
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING); |
603
|
|
|
|
604
|
|
|
return false; |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
/** |
608
|
|
|
* @return bool |
609
|
|
|
*/ |
610
|
|
|
public function insertConfig() |
611
|
|
|
{ |
612
|
|
|
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING); |
613
|
|
|
|
614
|
|
|
return false; |
615
|
|
|
} |
616
|
|
|
|
617
|
|
|
/** |
618
|
|
|
* @return bool |
619
|
|
|
*/ |
620
|
|
|
public function insertProfileFields() |
621
|
|
|
{ |
622
|
|
|
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING); |
623
|
|
|
|
624
|
|
|
return false; |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
/** |
628
|
|
|
* @param $type |
629
|
|
|
* @param int $state |
630
|
|
|
* |
631
|
|
|
* @return bool |
632
|
|
|
*/ |
633
|
|
|
public function executeScript($type, $state = 2) |
|
|
|
|
634
|
|
|
{ |
635
|
|
|
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING); |
636
|
|
|
|
637
|
|
|
return false; |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
/** |
641
|
|
|
* @param $groups |
642
|
|
|
* @param $type |
643
|
|
|
* |
644
|
|
|
* @return bool |
645
|
|
|
*/ |
646
|
|
|
public function insertGroupPermissions($groups, $type) |
|
|
|
|
647
|
|
|
{ |
648
|
|
|
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING); |
649
|
|
|
|
650
|
|
|
return false; |
651
|
|
|
} |
652
|
|
|
/**#@-*/ |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
/** |
656
|
|
|
* XOOPS module handler class. |
657
|
|
|
* |
658
|
|
|
* This class is responsible for providing data access mechanisms to the data source |
659
|
|
|
* of XOOPS module class objects. |
660
|
|
|
* |
661
|
|
|
* @package kernel |
662
|
|
|
* @author Kazumi Ono <[email protected]> |
663
|
|
|
* @copyright (c) 2000-2016 XOOPS Project - www.xoops.org |
664
|
|
|
* |
665
|
|
|
* @todo Why is this not a XoopsPersistableObjectHandler? |
666
|
|
|
*/ |
667
|
|
|
class XoopsModuleHandler extends XoopsObjectHandler |
668
|
|
|
{ |
669
|
|
|
/** |
670
|
|
|
* holds an array of cached module references, indexed by module id |
671
|
|
|
* |
672
|
|
|
* @var array |
673
|
|
|
* @access private |
674
|
|
|
*/ |
675
|
|
|
public $_cachedModule_mid = array(); |
676
|
|
|
|
677
|
|
|
/** |
678
|
|
|
* holds an array of cached module references, indexed by module dirname |
679
|
|
|
* |
680
|
|
|
* @var array |
681
|
|
|
* @access private |
682
|
|
|
*/ |
683
|
|
|
public $_cachedModule_dirname = array(); |
684
|
|
|
|
685
|
|
|
/** |
686
|
|
|
* Create a new {@link XoopsModule} object |
687
|
|
|
* |
688
|
|
|
* @param boolean $isNew Flag the new object as "new" |
689
|
|
|
* @return XoopsModule |
690
|
|
|
*/ |
691
|
|
|
public function create($isNew = true) |
692
|
|
|
{ |
693
|
|
|
$module = new XoopsModule(); |
694
|
|
|
if ($isNew) { |
695
|
|
|
$module->setNew(); |
696
|
|
|
} |
697
|
|
|
|
698
|
|
|
return $module; |
699
|
|
|
} |
700
|
|
|
|
701
|
|
|
/** |
702
|
|
|
* Load a module from the database |
703
|
|
|
* |
704
|
|
|
* @param int $id ID of the module |
705
|
|
|
* @return object FALSE on fail |
706
|
|
|
*/ |
707
|
|
|
public function get($id) |
708
|
|
|
{ |
709
|
|
|
static $_cachedModule_dirname; |
710
|
|
|
static $_cachedModule_mid; |
711
|
|
|
$id = (int)$id; |
712
|
|
|
$module = false; |
713
|
|
|
if ($id > 0) { |
714
|
|
|
if (!empty($_cachedModule_mid[$id])) { |
715
|
|
|
return $_cachedModule_mid[$id]; |
716
|
|
|
} else { |
717
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('modules') . ' WHERE mid = ' . $id; |
718
|
|
|
if (!$result = $this->db->query($sql)) { |
|
|
|
|
719
|
|
|
return $module; |
|
|
|
|
720
|
|
|
} |
721
|
|
|
$numrows = $this->db->getRowsNum($result); |
|
|
|
|
722
|
|
|
if ($numrows == 1) { |
723
|
|
|
$module = new XoopsModule(); |
724
|
|
|
$myrow = $this->db->fetchArray($result); |
|
|
|
|
725
|
|
|
$module->assignVars($myrow); |
726
|
|
|
$_cachedModule_mid[$id] = &$module; |
727
|
|
|
$_cachedModule_dirname[$module->getVar('dirname')] = &$module; |
728
|
|
|
|
729
|
|
|
return $module; |
730
|
|
|
} |
731
|
|
|
} |
732
|
|
|
} |
733
|
|
|
|
734
|
|
|
return $module; |
|
|
|
|
735
|
|
|
} |
736
|
|
|
|
737
|
|
|
/** |
738
|
|
|
* Load a module by its dirname |
739
|
|
|
* |
740
|
|
|
* @param string $dirname |
741
|
|
|
* @return XoopsModule|FALSE on fail |
742
|
|
|
*/ |
743
|
|
|
public function getByDirname($dirname) |
744
|
|
|
{ |
745
|
|
|
$dirname = basename($dirname); |
746
|
|
|
//could not we check for spaces instead?? |
747
|
|
|
if (strpos(strtolower($dirname), ' union ')) { |
748
|
|
|
return false; |
749
|
|
|
} |
750
|
|
|
static $_cachedModule_mid; |
751
|
|
|
static $_cachedModule_dirname; |
752
|
|
|
if (!empty($_cachedModule_dirname[$dirname])) { |
753
|
|
|
return $_cachedModule_dirname[$dirname]; |
754
|
|
|
} else { |
755
|
|
|
$module = false; |
756
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('modules') . " WHERE dirname = '" . trim($dirname) . "'"; |
757
|
|
|
if (!$result = $this->db->query($sql)) { |
758
|
|
|
return $module; |
759
|
|
|
} |
760
|
|
|
$numrows = $this->db->getRowsNum($result); |
761
|
|
|
if ($numrows == 1) { |
762
|
|
|
$module = new XoopsModule(); |
763
|
|
|
$myrow = $this->db->fetchArray($result); |
764
|
|
|
$module->assignVars($myrow); |
765
|
|
|
$_cachedModule_dirname[$dirname] =& $module; |
766
|
|
|
$_cachedModule_mid[$module->getVar('mid')] =& $module; |
767
|
|
|
} |
768
|
|
|
|
769
|
|
|
return $module; |
770
|
|
|
} |
771
|
|
|
} |
772
|
|
|
|
773
|
|
|
/** |
774
|
|
|
* Write a module to the database |
775
|
|
|
* |
776
|
|
|
* @param XoopsObject|XoopsModule $module a XoopsModule object |
777
|
|
|
* |
778
|
|
|
* @return bool true on success, otherwise false |
779
|
|
|
*/ |
780
|
|
|
public function insert(XoopsObject $module) |
781
|
|
|
{ |
782
|
|
|
$className = 'XoopsModule'; |
783
|
|
|
if (!($module instanceof $className)) { |
784
|
|
|
return false; |
785
|
|
|
} |
786
|
|
|
if (!$module->isDirty()) { |
787
|
|
|
return true; |
788
|
|
|
} |
789
|
|
|
if (!$module->cleanVars()) { |
790
|
|
|
return false; |
791
|
|
|
} |
792
|
|
|
foreach ($module->cleanVars as $k => $v) { |
793
|
|
|
${$k} = $v; |
794
|
|
|
} |
795
|
|
|
if ($module->isNew()) { |
796
|
|
|
$mid = $this->db->genId('modules_mid_seq'); |
|
|
|
|
797
|
|
|
$sql = sprintf('INSERT INTO %s (mid, name, version, last_update, weight, isactive, dirname, hasmain, hasadmin, hassearch, hasconfig, hascomments, hasnotification) VALUES (%u, %s, %s, %u, %u, %u, %s, %u, %u, %u, %u, %u, %u)', $this->db->prefix('modules'), $mid, $this->db->quoteString($name), $this->db->quoteString($version), time(), $weight, 1, $this->db->quoteString($dirname), $hasmain, $hasadmin, $hassearch, $hasconfig, $hascomments, $hasnotification); |
|
|
|
|
798
|
|
|
} else { |
799
|
|
|
$sql = sprintf('UPDATE %s SET name = %s, dirname = %s, version = %s, last_update = %u, weight = %u, isactive = %u, hasmain = %u, hasadmin = %u, hassearch = %u, hasconfig = %u, hascomments = %u, hasnotification = %u WHERE mid = %u', $this->db->prefix('modules'), $this->db->quoteString($name), $this->db->quoteString($dirname), $this->db->quoteString($version), time(), $weight, $isactive, $hasmain, $hasadmin, $hassearch, $hasconfig, $hascomments, $hasnotification, $mid); |
|
|
|
|
800
|
|
|
} |
801
|
|
|
if (!$result = $this->db->query($sql)) { |
|
|
|
|
802
|
|
|
return false; |
803
|
|
|
} |
804
|
|
|
if (empty($mid)) { |
805
|
|
|
$mid = $this->db->getInsertId(); |
|
|
|
|
806
|
|
|
} |
807
|
|
|
$module->assignVar('mid', $mid); |
808
|
|
|
if (!empty($this->_cachedModule_dirname[$dirname])) { |
809
|
|
|
unset($this->_cachedModule_dirname[$dirname]); |
810
|
|
|
} |
811
|
|
|
if (!empty($this->_cachedModule_mid[$mid])) { |
812
|
|
|
unset($this->_cachedModule_mid[$mid]); |
813
|
|
|
} |
814
|
|
|
|
815
|
|
|
return true; |
816
|
|
|
} |
817
|
|
|
|
818
|
|
|
/** |
819
|
|
|
* Delete a module from the database |
820
|
|
|
* |
821
|
|
|
* @param XoopsObject|XoopsModule $module a XoopsModule object |
822
|
|
|
* |
823
|
|
|
* @return bool true on success, otherwise false |
824
|
|
|
*/ |
825
|
|
|
public function delete(XoopsObject $module) |
826
|
|
|
{ |
827
|
|
|
$className = 'XoopsModule'; |
828
|
|
|
if (!($module instanceof $className)) { |
829
|
|
|
return false; |
830
|
|
|
} |
831
|
|
|
$sql = sprintf('DELETE FROM %s WHERE mid = %u', $this->db->prefix('modules'), $module->getVar('mid')); |
|
|
|
|
832
|
|
|
if (!$result = $this->db->query($sql)) { |
|
|
|
|
833
|
|
|
return false; |
834
|
|
|
} |
835
|
|
|
// delete admin permissions assigned for this module |
836
|
|
|
$sql = sprintf("DELETE FROM %s WHERE gperm_name = 'module_admin' AND gperm_itemid = %u", $this->db->prefix('group_permission'), $module->getVar('mid')); |
837
|
|
|
$this->db->query($sql); |
838
|
|
|
// delete read permissions assigned for this module |
839
|
|
|
$sql = sprintf("DELETE FROM %s WHERE gperm_name = 'module_read' AND gperm_itemid = %u", $this->db->prefix('group_permission'), $module->getVar('mid')); |
840
|
|
|
$this->db->query($sql); |
841
|
|
|
|
842
|
|
|
$sql = sprintf('SELECT block_id FROM %s WHERE module_id = %u', $this->db->prefix('block_module_link'), $module->getVar('mid')); |
843
|
|
|
if ($result = $this->db->query($sql)) { |
844
|
|
|
$block_id_arr = array(); |
845
|
|
|
while (false !== ($myrow = $this->db->fetchArray($result))) { |
846
|
|
|
$block_id_arr[] = $myrow['block_id']; |
847
|
|
|
} |
848
|
|
|
} |
849
|
|
|
// loop through block_id_arr |
850
|
|
|
if (isset($block_id_arr)) { |
851
|
|
|
foreach ($block_id_arr as $i) { |
852
|
|
|
$sql = sprintf('SELECT block_id FROM %s WHERE module_id != %u AND block_id = %u', $this->db->prefix('block_module_link'), $module->getVar('mid'), $i); |
853
|
|
|
if ($result2 = $this->db->query($sql)) { |
854
|
|
|
if (0 < $this->db->getRowsNum($result2)) { |
855
|
|
|
// this block has other entries, so delete the entry for this module |
856
|
|
|
$sql = sprintf('DELETE FROM %s WHERE (module_id = %u) AND (block_id = %u)', $this->db->prefix('block_module_link'), $module->getVar('mid'), $i); |
857
|
|
|
$this->db->query($sql); |
858
|
|
|
} else { |
859
|
|
|
// this block doesnt have other entries, so disable the block and let it show on top page only. otherwise, this block will not display anymore on block admin page! |
860
|
|
|
$sql = sprintf('UPDATE %s SET visible = 0 WHERE bid = %u', $this->db->prefix('newblocks'), $i); |
861
|
|
|
$this->db->query($sql); |
862
|
|
|
$sql = sprintf('UPDATE %s SET module_id = -1 WHERE module_id = %u', $this->db->prefix('block_module_link'), $module->getVar('mid')); |
863
|
|
|
$this->db->query($sql); |
864
|
|
|
} |
865
|
|
|
} |
866
|
|
|
} |
867
|
|
|
} |
868
|
|
|
|
869
|
|
|
if (!empty($this->_cachedModule_dirname[$module->getVar('dirname')])) { |
870
|
|
|
unset($this->_cachedModule_dirname[$module->getVar('dirname')]); |
871
|
|
|
} |
872
|
|
|
if (!empty($this->_cachedModule_mid[$module->getVar('mid')])) { |
873
|
|
|
unset($this->_cachedModule_mid[$module->getVar('mid')]); |
874
|
|
|
} |
875
|
|
|
|
876
|
|
|
return true; |
877
|
|
|
} |
878
|
|
|
|
879
|
|
|
/** |
880
|
|
|
* Load some modules |
881
|
|
|
* |
882
|
|
|
* @param CriteriaElement|CriteriaCompo $criteria {@link CriteriaElement} |
883
|
|
|
* @param boolean $id_as_key Use the ID as key into the array |
884
|
|
|
* @return array |
885
|
|
|
*/ |
886
|
|
|
public function getObjects(CriteriaElement $criteria = null, $id_as_key = false) |
887
|
|
|
{ |
888
|
|
|
$ret = array(); |
889
|
|
|
$limit = $start = 0; |
890
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('modules'); |
891
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
892
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
|
|
|
|
893
|
|
|
$sql .= ' ORDER BY weight ' . $criteria->getOrder() . ', mid ASC'; |
894
|
|
|
$limit = $criteria->getLimit(); |
895
|
|
|
$start = $criteria->getStart(); |
896
|
|
|
} |
897
|
|
|
$result = $this->db->query($sql, $limit, $start); |
898
|
|
|
if (!$result) { |
899
|
|
|
return $ret; |
900
|
|
|
} |
901
|
|
|
while (false !== ($myrow = $this->db->fetchArray($result))) { |
902
|
|
|
$module = new XoopsModule(); |
903
|
|
|
$module->assignVars($myrow); |
904
|
|
|
if (!$id_as_key) { |
905
|
|
|
$ret[] =& $module; |
906
|
|
|
} else { |
907
|
|
|
$ret[$myrow['mid']] =& $module; |
908
|
|
|
} |
909
|
|
|
unset($module); |
910
|
|
|
} |
911
|
|
|
|
912
|
|
|
return $ret; |
913
|
|
|
} |
914
|
|
|
|
915
|
|
|
/** |
916
|
|
|
* Count some modules |
917
|
|
|
* |
918
|
|
|
* @param CriteriaElement|CriteriaCompo $criteria {@link CriteriaElement} |
919
|
|
|
* @return int |
920
|
|
|
*/ |
921
|
|
|
public function getCount(CriteriaElement $criteria = null) |
922
|
|
|
{ |
923
|
|
|
$sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('modules'); |
924
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
925
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
926
|
|
|
} |
927
|
|
|
if (!$result = $this->db->query($sql)) { |
928
|
|
|
return 0; |
929
|
|
|
} |
930
|
|
|
list($count) = $this->db->fetchRow($result); |
|
|
|
|
931
|
|
|
|
932
|
|
|
return $count; |
933
|
|
|
} |
934
|
|
|
|
935
|
|
|
/** |
936
|
|
|
* returns an array of module names |
937
|
|
|
* |
938
|
|
|
* @param CriteriaElement $criteria |
939
|
|
|
* @param boolean $dirname_as_key if true, array keys will be module directory names |
940
|
|
|
* if false, array keys will be module id |
941
|
|
|
* @return array |
942
|
|
|
*/ |
943
|
|
|
public function getList(CriteriaElement $criteria = null, $dirname_as_key = false) |
944
|
|
|
{ |
945
|
|
|
$ret = array(); |
946
|
|
|
$modules = $this->getObjects($criteria, true); |
947
|
|
|
foreach (array_keys($modules) as $i) { |
948
|
|
|
if (!$dirname_as_key) { |
949
|
|
|
$ret[$i] = $modules[$i]->getVar('name'); |
950
|
|
|
} else { |
951
|
|
|
$ret[$modules[$i]->getVar('dirname')] = $modules[$i]->getVar('name'); |
952
|
|
|
} |
953
|
|
|
} |
954
|
|
|
|
955
|
|
|
return $ret; |
956
|
|
|
} |
957
|
|
|
} |
958
|
|
|
|