1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Xoops Functions |
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
|
|
|
|
18
|
|
|
defined('XOOPS_ROOT_PATH') || exit('Restricted access'); |
19
|
|
|
|
20
|
|
|
/** @var \XoopsNotificationHandler $notification_handler */ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* xoops_getHandler() |
24
|
|
|
* |
25
|
|
|
* @param string $name |
26
|
|
|
* @param bool $optional |
27
|
|
|
* |
28
|
|
|
* @return XoopsObjectHandler|false |
29
|
|
|
*/ |
30
|
|
|
function xoops_getHandler($name, $optional = false) |
31
|
|
|
{ |
32
|
|
|
static $handlers; |
33
|
|
|
$name = strtolower(trim($name)); |
34
|
|
|
if (!isset($handlers[$name])) { |
35
|
|
|
if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) { |
36
|
|
|
require_once $hnd_file; |
37
|
|
|
} |
38
|
|
|
$class = 'Xoops' . ucfirst($name) . 'Handler'; |
39
|
|
|
if (class_exists($class)) { |
40
|
|
|
$xoopsDB = XoopsDatabaseFactory::getDatabaseConnection(); |
41
|
|
|
$handlers[$name] = new $class($xoopsDB); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
if (!isset($handlers[$name])) { |
45
|
|
|
trigger_error('Class <strong>' . $class . '</strong> does not exist<br>Handler Name: ' . $name, $optional ? E_USER_WARNING : E_USER_ERROR); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
if (isset($handlers[$name])) { |
48
|
|
|
return $handlers[$name]; |
49
|
|
|
} |
50
|
|
|
$inst = false; |
51
|
|
|
|
52
|
|
|
return $inst; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* xoops_getModuleHandler() |
57
|
|
|
* |
58
|
|
|
* @param string $name |
59
|
|
|
* @param mixed $module_dir |
60
|
|
|
* @param bool $optional |
61
|
|
|
* @return XoopsObjectHandler|false |
62
|
|
|
*/ |
63
|
|
|
function xoops_getModuleHandler($name = null, $module_dir = null, $optional = false) |
64
|
|
|
{ |
65
|
|
|
static $handlers; |
66
|
|
|
// if $module_dir is not specified |
67
|
|
|
if (!isset($module_dir)) { |
68
|
|
|
// if a module is loaded |
69
|
|
|
if (isset($GLOBALS['xoopsModule']) && is_object($GLOBALS['xoopsModule'])) { |
70
|
|
|
$module_dir = $GLOBALS['xoopsModule']->getVar('dirname', 'n'); |
71
|
|
|
} else { |
72
|
|
|
trigger_error('No Module is loaded', E_USER_ERROR); |
73
|
|
|
} |
74
|
|
|
} else { |
75
|
|
|
$module_dir = trim($module_dir); |
76
|
|
|
} |
77
|
|
|
$name = (!isset($name)) ? $module_dir : trim($name); |
78
|
|
|
if (!isset($handlers[$module_dir][$name])) { |
79
|
|
|
if (file_exists($hnd_file = XOOPS_ROOT_PATH . "/modules/{$module_dir}/class/{$name}.php")) { |
80
|
|
|
include_once $hnd_file; |
81
|
|
|
} |
82
|
|
|
$class = ucfirst(strtolower($module_dir)) . ucfirst($name) . 'Handler'; |
83
|
|
|
if (class_exists($class)) { |
84
|
|
|
$xoopsDB = XoopsDatabaseFactory::getDatabaseConnection(); |
85
|
|
|
$handlers[$module_dir][$name] = new $class($xoopsDB); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
if (!isset($handlers[$module_dir][$name])) { |
89
|
|
|
trigger_error('Handler does not exist<br>Module: ' . $module_dir . '<br>Name: ' . $name, $optional ? E_USER_WARNING : E_USER_ERROR); |
90
|
|
|
} |
91
|
|
|
if (isset($handlers[$module_dir][$name])) { |
92
|
|
|
return $handlers[$module_dir][$name]; |
93
|
|
|
} |
94
|
|
|
$inst = false; |
95
|
|
|
|
96
|
|
|
return $inst; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* XOOPS class loader wrapper |
101
|
|
|
* |
102
|
|
|
* Temporay solution for XOOPS 2.3 |
103
|
|
|
* |
104
|
|
|
* @param string $name Name of class to be loaded |
105
|
|
|
* @param string $type domain of the class, potential values: core - located in /class/; |
106
|
|
|
* framework - located in /Frameworks/; |
107
|
|
|
* other - module class, located in /modules/[$type]/class/ |
108
|
|
|
* |
109
|
|
|
* @return boolean |
110
|
|
|
*/ |
111
|
|
|
function xoops_load($name, $type = 'core') |
112
|
|
|
{ |
113
|
|
|
if (!class_exists('XoopsLoad')) { |
114
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopsload.php'; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return XoopsLoad::load($name, $type); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* XOOPS language loader wrapper |
122
|
|
|
* |
123
|
|
|
* Temporay solution, not encouraged to use |
124
|
|
|
* |
125
|
|
|
* @param string $name Name of language file to be loaded, without extension |
126
|
|
|
* @param string $domain Module dirname; global language file will be loaded if $domain is set to 'global' or not specified |
127
|
|
|
* @param string $language Language to be loaded, current language content will be loaded if not specified |
128
|
|
|
* @return boolean |
129
|
|
|
* @todo expand domain to multiple categories, e.g. module:system, framework:filter, etc. |
130
|
|
|
* |
131
|
|
|
*/ |
132
|
|
|
function xoops_loadLanguage($name, $domain = '', $language = null) |
133
|
|
|
{ |
134
|
|
|
/** |
135
|
|
|
* Set pageType |
136
|
|
|
*/ |
137
|
|
|
if ($name === 'pagetype') { |
138
|
|
|
$name = xoops_getOption('pagetype'); |
|
|
|
|
139
|
|
|
} |
140
|
|
|
/** |
141
|
|
|
* We must check later for an empty value. As xoops_getOption could be empty |
142
|
|
|
*/ |
143
|
|
|
if (empty($name)) { |
144
|
|
|
return false; |
145
|
|
|
} |
146
|
|
|
// $language = empty($language) ? $GLOBALS['xoopsConfig']['language'] : $language; |
147
|
|
|
global $xoopsConfig; |
148
|
|
|
$language = empty($language) ? $xoopsConfig['language'] : $language; |
149
|
|
|
$path = ((empty($domain) || 'global' === $domain) ? '' : "modules/{$domain}/") . 'language'; |
150
|
|
|
if (!file_exists($fileinc = $GLOBALS['xoops']->path("{$path}/{$language}/{$name}.php"))) { |
151
|
|
|
if (!file_exists($fileinc = $GLOBALS['xoops']->path("{$path}/english/{$name}.php"))) { |
152
|
|
|
return false; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
$ret = include_once $fileinc; |
156
|
|
|
|
157
|
|
|
return $ret; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* YOU SHOULD BE CAREFUL WITH USING THIS METHOD SINCE IT WILL BE DEPRECATED |
162
|
|
|
*/ |
163
|
|
|
/** |
164
|
|
|
* xoops_getActiveModules() |
165
|
|
|
* |
166
|
|
|
* Get active modules from cache file |
167
|
|
|
* |
168
|
|
|
* @return array |
169
|
|
|
*/ |
170
|
|
|
function xoops_getActiveModules() |
171
|
|
|
{ |
172
|
|
|
static $modules_active; |
173
|
|
|
if (is_array($modules_active)) { |
174
|
|
|
return $modules_active; |
175
|
|
|
} |
176
|
|
|
xoops_load('XoopsCache'); |
177
|
|
|
if (!$modules_active = XoopsCache::read('system_modules_active')) { |
178
|
|
|
$modules_active = xoops_setActiveModules(); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
return $modules_active; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* YOU SHOULD BE CAREFUL WITH USING THIS METHOD SINCE IT WILL BE DEPRECATED |
186
|
|
|
*/ |
187
|
|
|
/** |
188
|
|
|
* xoops_setActiveModules() |
189
|
|
|
* |
190
|
|
|
* Write active modules to cache file |
191
|
|
|
* |
192
|
|
|
* @return array |
193
|
|
|
*/ |
194
|
|
|
function xoops_setActiveModules() |
195
|
|
|
{ |
196
|
|
|
xoops_load('XoopsCache'); |
197
|
|
|
/* @var XoopsModuleHandler $module_handler */ |
198
|
|
|
$module_handler = xoops_getHandler('module'); |
199
|
|
|
$modules_obj = $module_handler->getObjects(new Criteria('isactive', 1)); |
200
|
|
|
$modules_active = array(); |
201
|
|
|
foreach (array_keys($modules_obj) as $key) { |
202
|
|
|
$modules_active[] = $modules_obj[$key]->getVar('dirname'); |
203
|
|
|
} |
204
|
|
|
unset($modules_obj); |
205
|
|
|
XoopsCache::write('system_modules_active', $modules_active); |
206
|
|
|
|
207
|
|
|
return $modules_active; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* YOU SHOULD BE CAREFUL WITH USING THIS METHOD SINCE IT WILL BE DEPRECATED |
212
|
|
|
*/ |
213
|
|
|
/** |
214
|
|
|
* xoops_isActiveModule() |
215
|
|
|
* |
216
|
|
|
* Checks is module is installed and active |
217
|
|
|
* |
218
|
|
|
* @param $dirname |
219
|
|
|
* @return bool |
220
|
|
|
*/ |
221
|
|
|
function xoops_isActiveModule($dirname) |
222
|
|
|
{ |
223
|
|
|
return isset($dirname) && in_array($dirname, xoops_getActiveModules()); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* xoops_header() |
228
|
|
|
* |
229
|
|
|
* @param mixed $closehead |
230
|
|
|
* @return void |
231
|
|
|
*/ |
232
|
|
|
function xoops_header($closehead = true) |
233
|
|
|
{ |
234
|
|
|
global $xoopsConfig; |
235
|
|
|
|
236
|
|
|
$themeSet = $xoopsConfig['theme_set']; |
237
|
|
|
$themePath = XOOPS_THEME_PATH . '/' . $themeSet . '/'; |
238
|
|
|
$themeUrl = XOOPS_THEME_URL . '/' . $themeSet . '/'; |
239
|
|
|
include_once XOOPS_ROOT_PATH . '/class/template.php'; |
240
|
|
|
$headTpl = new \XoopsTpl(); |
241
|
|
|
$GLOBALS['xoopsHeadTpl'] = $headTpl; // expose template for use by caller |
242
|
|
|
$headTpl->assign(array( |
243
|
|
|
'closeHead' => (bool) $closehead, |
244
|
|
|
'themeUrl' => $themeUrl, |
245
|
|
|
'themePath' => $themePath, |
246
|
|
|
'xoops_langcode' => _LANGCODE, |
247
|
|
|
'xoops_charset' => _CHARSET, |
248
|
|
|
'xoops_sitename' => $xoopsConfig['sitename'], |
249
|
|
|
'xoops_url' => XOOPS_URL, |
250
|
|
|
)); |
251
|
|
|
|
252
|
|
|
if (file_exists($themePath . 'theme_autorun.php')) { |
253
|
|
|
include_once($themePath . 'theme_autorun.php'); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
$headItems = array(); |
257
|
|
|
$headItems[] = '<script type="text/javascript" src="' . XOOPS_URL . '/include/xoops.js"></script>'; |
258
|
|
|
$headItems[] = '<link rel="stylesheet" type="text/css" media="all" href="' . XOOPS_URL . '/xoops.css">'; |
259
|
|
|
$headItems[] = '<link rel="stylesheet" type="text/css" media="all" href="' . XOOPS_URL . '/media/font-awesome/css/font-awesome.min.css">'; |
260
|
|
|
$languageFile = 'language/' . $GLOBALS['xoopsConfig']['language'] . '/style.css'; |
261
|
|
|
if (file_exists($GLOBALS['xoops']->path($languageFile))) { |
262
|
|
|
$headItems[] = '<link rel="stylesheet" type="text/css" media="all" href="' . $GLOBALS['xoops']->url($languageFile) . '">'; |
263
|
|
|
} |
264
|
|
|
$themecss = xoops_getcss($xoopsConfig['theme_set']); |
265
|
|
|
if ($themecss!=='') { |
266
|
|
|
$headItems[] = '<link rel="stylesheet" type="text/css" media="all" href="' . $themecss . '">'; |
267
|
|
|
} |
268
|
|
|
$headTpl->assign('headItems', $headItems); |
269
|
|
|
|
270
|
|
|
if (!headers_sent()) { |
271
|
|
|
header('Content-Type:text/html; charset=' . _CHARSET); |
272
|
|
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
273
|
|
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
274
|
|
|
header('Cache-Control: no-store, no-cache, max-age=1, s-maxage=1, must-revalidate, post-check=0, pre-check=0'); |
275
|
|
|
header('Pragma: no-cache'); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
$output = $headTpl->fetch('db:system_popup_header.tpl'); |
279
|
|
|
echo $output; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* xoops_footer |
284
|
|
|
* |
285
|
|
|
* @return void |
286
|
|
|
*/ |
287
|
|
|
function xoops_footer() |
288
|
|
|
{ |
289
|
|
|
global $xoopsConfig; |
290
|
|
|
|
291
|
|
|
$themeSet = $xoopsConfig['theme_set']; |
292
|
|
|
$themePath = XOOPS_THEME_URL . '/' . $themeSet . '/'; |
293
|
|
|
include_once XOOPS_ROOT_PATH . '/class/template.php'; |
294
|
|
|
$footTpl = new \XoopsTpl(); |
295
|
|
|
$footTpl->assign(array( |
296
|
|
|
'themePath' => $themePath, |
297
|
|
|
'xoops_langcode' => _LANGCODE, |
298
|
|
|
'xoops_charset' => _CHARSET, |
299
|
|
|
'xoops_sitename' => $xoopsConfig['sitename'], |
300
|
|
|
'xoops_url' => XOOPS_URL, |
301
|
|
|
)); |
302
|
|
|
$output = $footTpl->fetch('db:system_popup_footer.tpl'); |
303
|
|
|
echo $output; |
304
|
|
|
ob_end_flush(); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* xoops_error |
309
|
|
|
* |
310
|
|
|
* @param mixed $msg |
311
|
|
|
* @param string $title |
312
|
|
|
* @return void |
313
|
|
|
*/ |
314
|
|
|
function xoops_error($msg, $title = '') |
315
|
|
|
{ |
316
|
|
|
echo '<div class="errorMsg">'; |
317
|
|
|
if ($title != '') { |
318
|
|
|
echo '<strong>' . $title . '</strong><br><br>'; |
319
|
|
|
} |
320
|
|
|
if (is_object($msg)) { |
321
|
|
|
$msg = (array)$msg; |
322
|
|
|
} |
323
|
|
|
if (is_array($msg)) { |
324
|
|
|
foreach ($msg as $key => $value) { |
325
|
|
|
if (is_numeric($key)) { |
326
|
|
|
$key = ''; |
327
|
|
|
} |
328
|
|
|
xoops_error($value, $key); |
329
|
|
|
} |
330
|
|
|
} else { |
331
|
|
|
echo "<div>{$msg}</div>"; |
332
|
|
|
} |
333
|
|
|
echo '</div>'; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* xoops_warning |
338
|
|
|
* |
339
|
|
|
* @param mixed $msg |
340
|
|
|
* @param string $title |
341
|
|
|
* @return void |
342
|
|
|
*/ |
343
|
|
|
function xoops_warning($msg, $title = '') |
344
|
|
|
{ |
345
|
|
|
echo '<div class="warningMsg">'; |
346
|
|
|
if ($title != '') { |
347
|
|
|
echo '<strong>' . $title . '</strong><br><br>'; |
348
|
|
|
} |
349
|
|
|
if (is_object($msg)) { |
350
|
|
|
$msg = (array)$msg; |
351
|
|
|
} |
352
|
|
|
if (is_array($msg)) { |
353
|
|
|
foreach ($msg as $key => $value) { |
354
|
|
|
if (is_numeric($key)) { |
355
|
|
|
$key = ''; |
356
|
|
|
} |
357
|
|
|
xoops_warning($value, $key); |
358
|
|
|
} |
359
|
|
|
} else { |
360
|
|
|
echo "<div>{$msg}</div>"; |
361
|
|
|
} |
362
|
|
|
echo '</div>'; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* xoops_result |
367
|
|
|
* |
368
|
|
|
* @param mixed $msg |
369
|
|
|
* @param string $title |
370
|
|
|
* @return void |
371
|
|
|
*/ |
372
|
|
|
function xoops_result($msg, $title = '') |
373
|
|
|
{ |
374
|
|
|
echo '<div class="resultMsg">'; |
375
|
|
|
if ($title != '') { |
376
|
|
|
echo '<strong>' . $title . '</strong><br><br>'; |
377
|
|
|
} |
378
|
|
|
if (is_object($msg)) { |
379
|
|
|
$msg = (array)$msg; |
380
|
|
|
} |
381
|
|
|
if (is_array($msg)) { |
382
|
|
|
foreach ($msg as $key => $value) { |
383
|
|
|
if (is_numeric($key)) { |
384
|
|
|
$key = ''; |
385
|
|
|
} |
386
|
|
|
xoops_result($value, $key); |
387
|
|
|
} |
388
|
|
|
} else { |
389
|
|
|
echo "<div>{$msg}</div>"; |
390
|
|
|
} |
391
|
|
|
echo '</div>'; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* xoops_confirm() |
396
|
|
|
* |
397
|
|
|
* @param mixed $hiddens |
398
|
|
|
* @param mixed $action |
399
|
|
|
* @param mixed $msg |
400
|
|
|
* @param string $submit |
401
|
|
|
* @param mixed $addtoken |
402
|
|
|
* @return void |
403
|
|
|
*/ |
404
|
|
|
function xoops_confirm($hiddens, $action, $msg, $submit = '', $addtoken = true) |
405
|
|
|
{ |
406
|
|
|
if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
407
|
|
|
include_once $GLOBALS['xoops']->path('/class/theme.php'); |
408
|
|
|
$GLOBALS['xoTheme'] = new \xos_opal_Theme(); |
409
|
|
|
} |
410
|
|
|
require_once $GLOBALS['xoops']->path('/class/template.php'); |
411
|
|
|
$confirmTpl = new \XoopsTpl(); |
412
|
|
|
$confirmTpl->assign('msg', $msg); |
413
|
|
|
$confirmTpl->assign('action', $action); |
414
|
|
|
$tempHiddens = ''; |
415
|
|
|
foreach ($hiddens as $name => $value) { |
416
|
|
|
if (is_array($value)) { |
417
|
|
|
foreach ($value as $caption => $newvalue) { |
418
|
|
|
$tempHiddens .= '<input type="radio" name="' . $name . '" value="' . htmlspecialchars($newvalue) . '" /> ' . $caption; |
419
|
|
|
} |
420
|
|
|
$tempHiddens .= '<br>'; |
421
|
|
|
} else { |
422
|
|
|
$tempHiddens .= '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($value) . '" />'; |
423
|
|
|
} |
424
|
|
|
} |
425
|
|
|
$confirmTpl->assign('hiddens', $tempHiddens); |
426
|
|
|
$confirmTpl->assign('addtoken', $addtoken); |
427
|
|
|
if ($addtoken != false) { |
428
|
|
|
$confirmTpl->assign('token', $GLOBALS['xoopsSecurity']->getTokenHTML()); |
429
|
|
|
} |
430
|
|
|
$submit = ($submit != '') ? trim($submit) : _SUBMIT; |
431
|
|
|
$confirmTpl->assign('submit', $submit); |
432
|
|
|
$html = $confirmTpl->fetch("db:system_confirm.tpl"); |
433
|
|
|
if (!empty($html)) { |
434
|
|
|
echo $html; |
435
|
|
|
} else { |
436
|
|
|
$submit = ($submit != '') ? trim($submit) : _SUBMIT; |
437
|
|
|
echo '<div class="confirmMsg">' . $msg . '<br> |
438
|
|
|
<form method="post" action="' . $action . '">'; |
439
|
|
|
foreach ($hiddens as $name => $value) { |
440
|
|
|
if (is_array($value)) { |
441
|
|
|
foreach ($value as $caption => $newvalue) { |
442
|
|
|
echo '<input type="radio" name="' . $name . '" value="' . htmlspecialchars($newvalue) . '" /> ' . $caption; |
443
|
|
|
} |
444
|
|
|
echo '<br>'; |
445
|
|
|
} else { |
446
|
|
|
echo '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($value) . '" />'; |
447
|
|
|
} |
448
|
|
|
} |
449
|
|
|
if ($addtoken != false) { |
450
|
|
|
echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
451
|
|
|
} |
452
|
|
|
// TODO - these buttons should go through formRenderer |
453
|
|
|
echo '<input type="submit" class="btn btn-default btn-secondary" name="confirm_submit" value="' . $submit . '" title="' . $submit . '"/> |
454
|
|
|
<input type="button" class="btn btn-default btn-secondary" name="confirm_back" value="' . _CANCEL . '" onclick="history.go(-1);" title="' . _CANCEL . '" /> |
455
|
|
|
</form> |
456
|
|
|
</div>'; |
457
|
|
|
} |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
/** |
461
|
|
|
* xoops_getUserTimestamp() |
462
|
|
|
* |
463
|
|
|
* @param mixed $time |
464
|
|
|
* @param string $timeoffset |
465
|
|
|
* @return int |
466
|
|
|
*/ |
467
|
|
|
function xoops_getUserTimestamp($time, $timeoffset = '') |
468
|
|
|
{ |
469
|
|
|
global $xoopsConfig, $xoopsUser; |
470
|
|
|
if ($timeoffset == '') { |
471
|
|
|
if ($xoopsUser) { |
472
|
|
|
$timeoffset = $xoopsUser->getVar('timezone_offset'); |
473
|
|
|
} else { |
474
|
|
|
$timeoffset = $xoopsConfig['default_TZ']; |
475
|
|
|
} |
476
|
|
|
} |
477
|
|
|
$usertimestamp = (int)$time + ((float)$timeoffset - $xoopsConfig['server_TZ']) * 3600; |
478
|
|
|
|
479
|
|
|
return (int)$usertimestamp; |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
/** |
483
|
|
|
* Function to display formatted times in user timezone |
484
|
|
|
* @param $time |
485
|
|
|
* @param string $format |
486
|
|
|
* @param string $timeoffset |
487
|
|
|
* @return string |
488
|
|
|
*/ |
489
|
|
|
function formatTimestamp($time, $format = 'l', $timeoffset = '') |
490
|
|
|
{ |
491
|
|
|
xoops_load('XoopsLocal'); |
492
|
|
|
|
493
|
|
|
return XoopsLocal::formatTimestamp($time, $format, $timeoffset); |
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
/** |
497
|
|
|
* Function to calculate server timestamp from user entered time (timestamp) |
498
|
|
|
* @param $timestamp |
499
|
|
|
* @param null $userTZ |
|
|
|
|
500
|
|
|
* @return |
501
|
|
|
*/ |
502
|
|
|
function userTimeToServerTime($timestamp, $userTZ = null) |
503
|
|
|
{ |
504
|
|
|
global $xoopsConfig; |
505
|
|
|
if (!isset($userTZ)) { |
506
|
|
|
$userTZ = $xoopsConfig['default_TZ']; |
507
|
|
|
} |
508
|
|
|
$timestamp -= (($userTZ - $xoopsConfig['server_TZ']) * 3600); |
509
|
|
|
|
510
|
|
|
return $timestamp; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
/** |
514
|
|
|
* xoops_makepass() |
515
|
|
|
* |
516
|
|
|
* @return string |
517
|
|
|
*/ |
518
|
|
|
function xoops_makepass() |
519
|
|
|
{ |
520
|
|
|
$makepass = ''; |
521
|
|
|
$syllables = array( |
522
|
|
|
'er', |
523
|
|
|
'in', |
524
|
|
|
'tia', |
525
|
|
|
'wol', |
526
|
|
|
'fe', |
527
|
|
|
'pre', |
528
|
|
|
'vet', |
529
|
|
|
'jo', |
530
|
|
|
'nes', |
531
|
|
|
'al', |
532
|
|
|
'len', |
533
|
|
|
'son', |
534
|
|
|
'cha', |
535
|
|
|
'ir', |
536
|
|
|
'ler', |
537
|
|
|
'bo', |
538
|
|
|
'ok', |
539
|
|
|
'tio', |
540
|
|
|
'nar', |
541
|
|
|
'sim', |
542
|
|
|
'ple', |
543
|
|
|
'bla', |
544
|
|
|
'ten', |
545
|
|
|
'toe', |
546
|
|
|
'cho', |
547
|
|
|
'co', |
548
|
|
|
'lat', |
549
|
|
|
'spe', |
550
|
|
|
'ak', |
551
|
|
|
'er', |
552
|
|
|
'po', |
553
|
|
|
'co', |
554
|
|
|
'lor', |
555
|
|
|
'pen', |
556
|
|
|
'cil', |
557
|
|
|
'li', |
558
|
|
|
'ght', |
559
|
|
|
'wh', |
560
|
|
|
'at', |
561
|
|
|
'the', |
562
|
|
|
'he', |
563
|
|
|
'ck', |
564
|
|
|
'is', |
565
|
|
|
'mam', |
566
|
|
|
'bo', |
567
|
|
|
'no', |
568
|
|
|
'fi', |
569
|
|
|
've', |
570
|
|
|
'any', |
571
|
|
|
'way', |
572
|
|
|
'pol', |
573
|
|
|
'iti', |
574
|
|
|
'cs', |
575
|
|
|
'ra', |
576
|
|
|
'dio', |
577
|
|
|
'sou', |
578
|
|
|
'rce', |
579
|
|
|
'sea', |
580
|
|
|
'rch', |
581
|
|
|
'pa', |
582
|
|
|
'per', |
583
|
|
|
'com', |
584
|
|
|
'bo', |
585
|
|
|
'sp', |
586
|
|
|
'eak', |
587
|
|
|
'st', |
588
|
|
|
'fi', |
589
|
|
|
'rst', |
590
|
|
|
'gr', |
591
|
|
|
'oup', |
592
|
|
|
'boy', |
593
|
|
|
'ea', |
594
|
|
|
'gle', |
595
|
|
|
'tr', |
596
|
|
|
'ail', |
597
|
|
|
'bi', |
598
|
|
|
'ble', |
599
|
|
|
'brb', |
600
|
|
|
'pri', |
601
|
|
|
'dee', |
602
|
|
|
'kay', |
603
|
|
|
'en', |
604
|
|
|
'be', |
605
|
|
|
'se'); |
606
|
|
|
for ($count = 1; $count <= 4; ++$count) { |
607
|
|
|
if (mt_rand() % 10 == 1) { |
608
|
|
|
$makepass .= sprintf('%0.0f', (mt_rand() % 50) + 1); |
609
|
|
|
} else { |
610
|
|
|
$makepass .= sprintf('%s', $syllables[mt_rand() % 62]); |
611
|
|
|
} |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
return $makepass; |
615
|
|
|
} |
616
|
|
|
|
617
|
|
|
/** |
618
|
|
|
* checkEmail() |
619
|
|
|
* |
620
|
|
|
* @param mixed $email |
621
|
|
|
* @param mixed $antispam |
622
|
|
|
* @return bool|mixed |
623
|
|
|
*/ |
624
|
|
|
function checkEmail($email, $antispam = false) |
625
|
|
|
{ |
626
|
|
|
if (!$email || !preg_match('/^[^@]{1,64}@[^@]{1,255}$/', $email)) { |
627
|
|
|
return false; |
628
|
|
|
} |
629
|
|
|
$email_array = explode('@', $email); |
630
|
|
|
$local_array = explode('.', $email_array[0]); |
631
|
|
|
$local_arrayCount = count($local_array); |
632
|
|
|
for ($i = 0; $i < $local_arrayCount; ++$i) { |
633
|
|
|
if (!preg_match("/^(([A-Za-z0-9!#$%&'*+\/\=?^_`{|}~-][A-Za-z0-9!#$%&'*+\/\=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/", $local_array[$i])) { |
634
|
|
|
return false; |
635
|
|
|
} |
636
|
|
|
} |
637
|
|
|
if (!preg_match("/^\[?[0-9\.]+\]?$/", $email_array[1])) { |
638
|
|
|
$domain_array = explode('.', $email_array[1]); |
639
|
|
|
if (count($domain_array) < 2) { |
640
|
|
|
return false; // Not enough parts to domain |
641
|
|
|
} |
642
|
|
|
for ($i = 0; $i < count($domain_array); ++$i) { |
|
|
|
|
643
|
|
|
if (!preg_match("/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$/", $domain_array[$i])) { |
644
|
|
|
return false; |
645
|
|
|
} |
646
|
|
|
} |
647
|
|
|
} |
648
|
|
|
if ($antispam) { |
649
|
|
|
$email = str_replace('@', ' at ', $email); |
650
|
|
|
$email = str_replace('.', ' dot ', $email); |
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
return $email; |
654
|
|
|
} |
655
|
|
|
|
656
|
|
|
/** |
657
|
|
|
* formatURL() |
658
|
|
|
* |
659
|
|
|
* @param mixed $url |
660
|
|
|
* @return mixed|string |
661
|
|
|
*/ |
662
|
|
|
function formatURL($url) |
663
|
|
|
{ |
664
|
|
|
$url = trim($url); |
665
|
|
|
if ($url != '') { |
666
|
|
|
if ((!preg_match('/^http[s]*:\/\//i', $url)) && (!preg_match('/^ftp*:\/\//i', $url)) && (!preg_match('/^ed2k*:\/\//i', $url))) { |
667
|
|
|
$url = 'http://' . $url; |
668
|
|
|
} |
669
|
|
|
} |
670
|
|
|
|
671
|
|
|
return $url; |
672
|
|
|
} |
673
|
|
|
|
674
|
|
|
/** |
675
|
|
|
* Function to get banner html tags for use in templates |
676
|
|
|
*/ |
677
|
|
|
function xoops_getbanner() |
678
|
|
|
{ |
679
|
|
|
global $xoopsConfig; |
680
|
|
|
|
681
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
682
|
|
|
$sql = 'SELECT COUNT(*) FROM ' . $db->prefix('banner'); |
683
|
|
|
$result = $db->query($sql); |
|
|
|
|
684
|
|
|
if (!$db->isResultSet($result)) { |
685
|
|
|
throw new \RuntimeException( |
686
|
|
|
\sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), E_USER_ERROR |
|
|
|
|
687
|
|
|
); |
688
|
|
|
} |
689
|
|
|
list($numrows) = $db->fetchRow($result); |
|
|
|
|
690
|
|
|
if ($numrows > 1) { |
691
|
|
|
--$numrows; |
692
|
|
|
$bannum = mt_rand(0, $numrows); |
693
|
|
|
} else { |
694
|
|
|
$bannum = 0; |
695
|
|
|
} |
696
|
|
|
if ($numrows > 0) { |
697
|
|
|
$sql = 'SELECT * FROM ' . $db->prefix('banner'); |
698
|
|
|
$result = $db->query($sql, 1, $bannum); |
699
|
|
|
if (!$db->isResultSet($result)) { |
700
|
|
|
throw new \RuntimeException( |
701
|
|
|
\sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), E_USER_ERROR |
702
|
|
|
); |
703
|
|
|
} |
704
|
|
|
list($bid, $cid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date, $htmlbanner, $htmlcode) = $db->fetchRow($result); |
705
|
|
|
if ($xoopsConfig['my_ip'] == xoops_getenv('REMOTE_ADDR')) { |
706
|
|
|
// EMPTY |
707
|
|
|
} else { |
708
|
|
|
++$impmade; |
709
|
|
|
$sql = sprintf('UPDATE %s SET impmade = %u WHERE bid = %u', $db->prefix('banner'), $impmade, $bid); |
710
|
|
|
$db->queryF($sql); |
|
|
|
|
711
|
|
|
/** |
712
|
|
|
* Check if this impression is the last one |
713
|
|
|
*/ |
714
|
|
|
if ($imptotal > 0 && $impmade >= $imptotal) { |
715
|
|
|
$newid = $db->genId($db->prefix('bannerfinish') . '_bid_seq'); |
|
|
|
|
716
|
|
|
$sql = sprintf('INSERT INTO %s (bid, cid, impressions, clicks, datestart, dateend) VALUES (%u, %u, %u, %u, %u, %u)', $db->prefix('bannerfinish'), $newid, $cid, $impmade, $clicks, $date, time()); |
717
|
|
|
$db->queryF($sql); |
718
|
|
|
$db->queryF(sprintf('DELETE FROM %s WHERE bid = %u', $db->prefix('banner'), $bid)); |
719
|
|
|
} |
720
|
|
|
} |
721
|
|
|
/** |
722
|
|
|
* Print the banner |
723
|
|
|
*/ |
724
|
|
|
$bannerobject = ''; |
725
|
|
|
if ($htmlbanner) { |
726
|
|
|
if ($htmlcode) { |
727
|
|
|
$bannerobject = $htmlcode; |
728
|
|
|
} else { |
729
|
|
|
$bannerobject = $bannerobject . '<div id="xo-bannerfix">'; |
730
|
|
|
// $bannerobject = $bannerobject . '<div id="xo-fixbanner">'; |
731
|
|
|
$bannerobject = $bannerobject . ' <iframe src=' . $imageurl . ' border="0" scrolling="no" allowtransparency="true" width="480px" height="60px" style="border:0" alt="' . $clickurl . ';"> </iframe>'; |
732
|
|
|
$bannerobject .= '</div>'; |
733
|
|
|
// $bannerobject .= '</div>'; |
734
|
|
|
} |
735
|
|
|
} else { |
736
|
|
|
$bannerobject = '<div id="xo-bannerfix">'; |
737
|
|
|
if (false !== stripos($imageurl, '.swf')) { |
738
|
|
|
$bannerobject = $bannerobject . '<div id ="xo-fixbanner">' . '<a href="' . XOOPS_URL . '/banners.php?op=click&bid=' . $bid . '" rel="external" title="' . $clickurl . '"></a></div>' . '<object type="application/x-shockwave-flash" width="468" height="60" data="' . $imageurl . '" style="z-index:100;">' . '<param name="movie" value="' . $imageurl . '" />' . '<param name="wmode" value="opaque" />' . '</object>'; |
739
|
|
|
} else { |
740
|
|
|
$bannerobject = $bannerobject . '<a href="' . XOOPS_URL . '/banners.php?op=click&bid=' . $bid . '" rel="external" title="' . $clickurl . '"><img src="' . $imageurl . '" alt="' . $clickurl . '" /></a>'; |
741
|
|
|
} |
742
|
|
|
|
743
|
|
|
$bannerobject .= '</div>'; |
744
|
|
|
} |
745
|
|
|
|
746
|
|
|
return $bannerobject; |
747
|
|
|
} |
748
|
|
|
return null; |
749
|
|
|
} |
750
|
|
|
|
751
|
|
|
/** |
752
|
|
|
* Function to redirect a user to certain pages |
753
|
|
|
* @param $url |
754
|
|
|
* @param int $time |
755
|
|
|
* @param string $message |
756
|
|
|
* @param bool $addredirect |
757
|
|
|
* @param bool $allowExternalLink |
758
|
|
|
*/ |
759
|
|
|
function redirect_header($url, $time = 3, $message = '', $addredirect = true, $allowExternalLink = false) |
760
|
|
|
{ |
761
|
|
|
global $xoopsConfig, $xoopsLogger, $xoopsUserIsAdmin; |
762
|
|
|
|
763
|
|
|
$xoopsPreload = XoopsPreload::getInstance(); |
764
|
|
|
$xoopsPreload->triggerEvent('core.include.functions.redirectheader.start', array($url, $time, $message, $addredirect, $allowExternalLink)); |
765
|
|
|
// under normal circumstance this event will exit, so listen for the .start above |
766
|
|
|
$xoopsPreload->triggerEvent('core.include.functions.redirectheader', array($url, $time, $message, $addredirect, $allowExternalLink)); |
767
|
|
|
|
768
|
|
|
if (preg_match("/[\\0-\\31]|about:|script:/i", $url)) { |
769
|
|
|
if (!preg_match('/^\b(java)?script:([\s]*)history\.go\(-\d*\)([\s]*[;]*[\s]*)$/si', $url)) { |
770
|
|
|
$url = XOOPS_URL; |
771
|
|
|
} |
772
|
|
|
} |
773
|
|
|
if (!$allowExternalLink && $pos = strpos($url, '://')) { |
774
|
|
|
$xoopsLocation = substr(XOOPS_URL, strpos(XOOPS_URL, '://') + 3); |
775
|
|
|
if (strcasecmp(substr($url, $pos + 3, strlen($xoopsLocation)), $xoopsLocation)) { |
776
|
|
|
$url = XOOPS_URL; |
777
|
|
|
} |
778
|
|
|
} |
779
|
|
|
if (defined('XOOPS_CPFUNC_LOADED')) { |
780
|
|
|
$theme = 'default'; |
781
|
|
|
} else { |
782
|
|
|
$theme = $xoopsConfig['theme_set']; |
783
|
|
|
} |
784
|
|
|
|
785
|
|
|
require_once XOOPS_ROOT_PATH . '/class/template.php'; |
786
|
|
|
require_once XOOPS_ROOT_PATH . '/class/theme.php'; |
787
|
|
|
$xoopsThemeFactory = null; |
|
|
|
|
788
|
|
|
$xoopsThemeFactory = new xos_opal_ThemeFactory(); |
789
|
|
|
$xoopsThemeFactory->allowedThemes = $xoopsConfig['theme_set_allowed']; |
790
|
|
|
$xoopsThemeFactory->defaultTheme = $theme; |
791
|
|
|
$xoTheme = $xoopsThemeFactory->createInstance(array( |
792
|
|
|
'plugins' => array(), |
793
|
|
|
'renderBanner' => false)); |
794
|
|
|
$xoopsTpl = $xoTheme->template; |
795
|
|
|
$xoopsTpl->assign(array( |
796
|
|
|
'xoops_theme' => $theme, |
797
|
|
|
'xoops_imageurl' => XOOPS_THEME_URL . '/' . $theme . '/', |
798
|
|
|
'xoops_themecss' => xoops_getcss($theme), |
799
|
|
|
'xoops_requesturi' => htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES), |
800
|
|
|
'xoops_sitename' => htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES), |
801
|
|
|
'xoops_slogan' => htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES), |
802
|
|
|
'xoops_dirname' => isset($xoopsModule) && is_object($xoopsModule) ? $xoopsModule->getVar('dirname') : 'system', |
|
|
|
|
803
|
|
|
'xoops_pagetitle' => isset($xoopsModule) && is_object($xoopsModule) ? $xoopsModule->getVar('name') : htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES))); |
804
|
|
|
if ($xoopsConfig['debug_mode'] == 2 && $xoopsUserIsAdmin) { |
805
|
|
|
$xoopsTpl->assign('time', 300); |
806
|
|
|
$xoopsTpl->assign('xoops_logdump', $xoopsLogger->dump()); |
807
|
|
|
} else { |
808
|
|
|
$xoopsTpl->assign('time', (int)$time); |
809
|
|
|
} |
810
|
|
|
if (!empty($_SERVER['REQUEST_URI']) && $addredirect && false !== strpos($url, 'user.php')) { |
811
|
|
|
if (false === strpos($url, '?')) { |
812
|
|
|
$url .= '?xoops_redirect=' . urlencode($_SERVER['REQUEST_URI']); |
813
|
|
|
} else { |
814
|
|
|
$url .= '&xoops_redirect=' . urlencode($_SERVER['REQUEST_URI']); |
815
|
|
|
} |
816
|
|
|
} |
817
|
|
|
if (defined('SID') && SID && (!isset($_COOKIE[session_name()]) || ($xoopsConfig['use_mysession'] && $xoopsConfig['session_name'] != '' && !isset($_COOKIE[$xoopsConfig['session_name']])))) { |
818
|
|
|
if (false === strpos($url, '?')) { |
819
|
|
|
$url .= '?' . SID; |
820
|
|
|
} else { |
821
|
|
|
$url .= '&' . SID; |
822
|
|
|
} |
823
|
|
|
} |
824
|
|
|
$url = preg_replace('/&/i', '&', htmlspecialchars($url, ENT_QUOTES)); |
825
|
|
|
$xoopsTpl->assign('url', $url); |
826
|
|
|
$message = trim($message) != '' ? $message : _TAKINGBACK; |
827
|
|
|
$xoopsTpl->assign('message', $message); |
828
|
|
|
$xoopsTpl->assign('lang_ifnotreload', sprintf(_IFNOTRELOAD, $url)); |
829
|
|
|
|
830
|
|
|
$xoopsTpl->display('db:system_redirect.tpl'); |
831
|
|
|
exit(); |
|
|
|
|
832
|
|
|
} |
833
|
|
|
|
834
|
|
|
/** |
835
|
|
|
* xoops_getenv() |
836
|
|
|
* |
837
|
|
|
* @param mixed $key |
838
|
|
|
* @return string |
839
|
|
|
*/ |
840
|
|
|
function xoops_getenv($key) |
841
|
|
|
{ |
842
|
|
|
$ret = ''; |
843
|
|
|
if (array_key_exists($key, $_SERVER) && isset($_SERVER[$key])) { |
844
|
|
|
$ret = $_SERVER[$key]; |
845
|
|
|
|
846
|
|
|
return $ret; |
847
|
|
|
} |
848
|
|
|
if (array_key_exists($key, $_ENV) && isset($_ENV[$key])) { |
849
|
|
|
$ret = $_ENV[$key]; |
850
|
|
|
|
851
|
|
|
return $ret; |
852
|
|
|
} |
853
|
|
|
|
854
|
|
|
return $ret; |
855
|
|
|
} |
856
|
|
|
|
857
|
|
|
/** |
858
|
|
|
* Function to get css file for a certain themeset |
859
|
|
|
* @param string $theme |
860
|
|
|
* @return string |
861
|
|
|
*/ |
862
|
|
|
function xoops_getcss($theme = '') |
863
|
|
|
{ |
864
|
|
|
if ($theme == '') { |
865
|
|
|
$theme = $GLOBALS['xoopsConfig']['theme_set']; |
866
|
|
|
} |
867
|
|
|
$uagent = xoops_getenv('HTTP_USER_AGENT'); |
868
|
|
|
$str_css = 'styleNN.css'; |
869
|
|
|
if (false !== stripos($uagent, 'mac')) { |
870
|
|
|
$str_css = 'styleMAC.css'; |
871
|
|
|
} elseif (preg_match("/MSIE (\d\.\d{1,2})/i", $uagent)) { |
872
|
|
|
$str_css = 'style.css'; |
873
|
|
|
} |
874
|
|
|
if (is_dir(XOOPS_THEME_PATH . '/' . $theme)) { |
875
|
|
|
if (file_exists(XOOPS_THEME_PATH . '/' . $theme . '/' . $str_css)) { |
876
|
|
|
return XOOPS_THEME_URL . '/' . $theme . '/' . $str_css; |
877
|
|
|
} elseif (file_exists(XOOPS_THEME_PATH . '/' . $theme . '/style.css')) { |
878
|
|
|
return XOOPS_THEME_URL . '/' . $theme . '/style.css'; |
879
|
|
|
} |
880
|
|
|
} |
881
|
|
|
if (is_dir(XOOPS_THEME_PATH . '/' . $theme . '/css')) { |
882
|
|
|
if (file_exists(XOOPS_THEME_PATH . '/' . $theme . '/css/' . $str_css)) { |
883
|
|
|
return XOOPS_THEME_URL . '/' . $theme . '/css/' . $str_css; |
884
|
|
|
} elseif (file_exists(XOOPS_THEME_PATH . '/' . $theme . '/css/style.css')) { |
885
|
|
|
return XOOPS_THEME_URL . '/' . $theme . '/css/style.css'; |
886
|
|
|
} |
887
|
|
|
} |
888
|
|
|
|
889
|
|
|
return ''; |
890
|
|
|
} |
891
|
|
|
|
892
|
|
|
/** |
893
|
|
|
* xoops_getMailer() |
894
|
|
|
* |
895
|
|
|
* @return \XoopsMailer|\XoopsMailerLocal |
896
|
|
|
*/ |
897
|
|
|
function xoops_getMailer() |
898
|
|
|
{ |
899
|
|
|
static $mailer; |
900
|
|
|
global $xoopsConfig; |
901
|
|
|
if (is_object($mailer)) { |
902
|
|
|
return $mailer; |
903
|
|
|
} |
904
|
|
|
include_once XOOPS_ROOT_PATH . '/class/xoopsmailer.php'; |
905
|
|
|
if (file_exists($file = XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/xoopsmailerlocal.php')) { |
906
|
|
|
include_once $file; |
907
|
|
|
} elseif (file_exists($file = XOOPS_ROOT_PATH . '/language/english/xoopsmailerlocal.php')) { |
908
|
|
|
include_once $file; |
909
|
|
|
} |
910
|
|
|
unset($mailer); |
911
|
|
|
if (class_exists('XoopsMailerLocal')) { |
912
|
|
|
$mailer = new XoopsMailerLocal(); |
913
|
|
|
} else { |
914
|
|
|
$mailer = new XoopsMailer(); |
915
|
|
|
} |
916
|
|
|
|
917
|
|
|
return $mailer; |
918
|
|
|
} |
919
|
|
|
|
920
|
|
|
/** |
921
|
|
|
* xoops_getrank() |
922
|
|
|
* |
923
|
|
|
* @param integer $rank_id |
924
|
|
|
* @param mixed $posts |
925
|
|
|
* @return |
926
|
|
|
*/ |
927
|
|
|
function xoops_getrank($rank_id = 0, $posts = 0) |
928
|
|
|
{ |
929
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
930
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
931
|
|
|
$rank_id = (int)$rank_id; |
932
|
|
|
$posts = (int)$posts; |
933
|
|
|
if ($rank_id != 0) { |
934
|
|
|
$sql = 'SELECT rank_title AS title, rank_image AS image FROM ' . $db->prefix('ranks') . ' WHERE rank_id = ' . $rank_id; |
935
|
|
|
} else { |
936
|
|
|
$sql = 'SELECT rank_title AS title, rank_image AS image FROM ' . $db->prefix('ranks') . ' WHERE rank_min <= ' . $posts . ' AND rank_max >= ' . $posts . ' AND rank_special = 0'; |
937
|
|
|
} |
938
|
|
|
$result = $db->query($sql); |
939
|
|
|
if (!$db->isResultSet($result)) { |
940
|
|
|
throw new \RuntimeException( |
941
|
|
|
\sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), E_USER_ERROR |
942
|
|
|
); |
943
|
|
|
} |
944
|
|
|
$rank = $db->fetchArray($result); |
|
|
|
|
945
|
|
|
$rank['title'] = $myts->htmlSpecialChars($rank['title']); |
946
|
|
|
$rank['id'] = $rank_id; |
947
|
|
|
|
948
|
|
|
return $rank; |
949
|
|
|
} |
950
|
|
|
|
951
|
|
|
/** |
952
|
|
|
* Returns the portion of string specified by the start and length parameters. If $trimmarker is supplied, it is appended to the return string. This function works fine with multibyte characters if mb_* functions exist on the server. |
953
|
|
|
* |
954
|
|
|
* @param string $str |
955
|
|
|
* @param int $start |
956
|
|
|
* @param int $length |
957
|
|
|
* @param string $trimmarker |
958
|
|
|
* @return string |
959
|
|
|
*/ |
960
|
|
|
function xoops_substr($str, $start, $length, $trimmarker = '...') |
961
|
|
|
{ |
962
|
|
|
xoops_load('XoopsLocal'); |
963
|
|
|
|
964
|
|
|
return XoopsLocal::substr($str, $start, $length, $trimmarker); |
965
|
|
|
} |
966
|
|
|
|
967
|
|
|
// RMV-NOTIFY |
968
|
|
|
// ################ Notification Helper Functions ################## |
969
|
|
|
// We want to be able to delete by module, by user, or by item. |
970
|
|
|
// How do we specify this?? |
971
|
|
|
/** |
972
|
|
|
* @param $module_id |
973
|
|
|
* |
974
|
|
|
* @return mixed |
975
|
|
|
*/ |
976
|
|
|
function xoops_notification_deletebymodule($module_id) |
977
|
|
|
{ |
978
|
|
|
$notification_handler = xoops_getHandler('notification'); |
979
|
|
|
|
980
|
|
|
return $notification_handler->unsubscribeByModule($module_id); |
|
|
|
|
981
|
|
|
} |
982
|
|
|
|
983
|
|
|
/** |
984
|
|
|
* xoops_notification_deletebyuser() |
985
|
|
|
* |
986
|
|
|
* @param mixed $user_id |
987
|
|
|
* @return |
988
|
|
|
*/ |
989
|
|
|
function xoops_notification_deletebyuser($user_id) |
990
|
|
|
{ |
991
|
|
|
$notification_handler = xoops_getHandler('notification'); |
992
|
|
|
|
993
|
|
|
return $notification_handler->unsubscribeByUser($user_id); |
|
|
|
|
994
|
|
|
} |
995
|
|
|
|
996
|
|
|
/** |
997
|
|
|
* xoops_notification_deletebyitem() |
998
|
|
|
* |
999
|
|
|
* @param mixed $module_id |
1000
|
|
|
* @param mixed $category |
1001
|
|
|
* @param mixed $item_id |
1002
|
|
|
* @return |
1003
|
|
|
*/ |
1004
|
|
|
function xoops_notification_deletebyitem($module_id, $category, $item_id) |
1005
|
|
|
{ |
1006
|
|
|
$notification_handler = xoops_getHandler('notification'); |
1007
|
|
|
|
1008
|
|
|
return $notification_handler->unsubscribeByItem($module_id, $category, $item_id); |
|
|
|
|
1009
|
|
|
} |
1010
|
|
|
|
1011
|
|
|
/** |
1012
|
|
|
* xoops_comment_count() |
1013
|
|
|
* |
1014
|
|
|
* @param mixed $module_id |
1015
|
|
|
* @param mixed $item_id |
1016
|
|
|
* @return |
1017
|
|
|
*/ |
1018
|
|
|
function xoops_comment_count($module_id, $item_id = null) |
1019
|
|
|
{ |
1020
|
|
|
/** @var \XoopsCommentHandler $comment_handler */ |
1021
|
|
|
$comment_handler = xoops_getHandler('comment'); |
1022
|
|
|
$criteria = new CriteriaCompo(new Criteria('com_modid', (int)$module_id)); |
1023
|
|
|
if (isset($item_id)) { |
1024
|
|
|
$criteria->add(new Criteria('com_itemid', (int)$item_id)); |
1025
|
|
|
} |
1026
|
|
|
|
1027
|
|
|
return $comment_handler->getCount($criteria); |
1028
|
|
|
} |
1029
|
|
|
|
1030
|
|
|
/** |
1031
|
|
|
* xoops_comment_delete() |
1032
|
|
|
* |
1033
|
|
|
* @param mixed $module_id |
1034
|
|
|
* @param mixed $item_id |
1035
|
|
|
* @return bool |
1036
|
|
|
*/ |
1037
|
|
|
function xoops_comment_delete($module_id, $item_id) |
1038
|
|
|
{ |
1039
|
|
|
if ((int)$module_id > 0 && (int)$item_id > 0) { |
1040
|
|
|
/** @var \XoopsCommentHandler $comment_handler */ |
1041
|
|
|
$comment_handler = xoops_getHandler('comment'); |
1042
|
|
|
$comments = $comment_handler->getByItemId($module_id, $item_id); |
1043
|
|
|
if (is_array($comments)) { |
|
|
|
|
1044
|
|
|
$count = count($comments); |
1045
|
|
|
$deleted_num = array(); |
1046
|
|
|
for ($i = 0; $i < $count; ++$i) { |
1047
|
|
|
if (false !== $comment_handler->delete($comments[$i])) { |
1048
|
|
|
// store poster ID and deleted post number into array for later use |
1049
|
|
|
$poster_id = $comments[$i]->getVar('com_uid'); |
1050
|
|
|
if ($poster_id != 0) { |
1051
|
|
|
$deleted_num[$poster_id] = !isset($deleted_num[$poster_id]) ? 1 : ($deleted_num[$poster_id] + 1); |
1052
|
|
|
} |
1053
|
|
|
} |
1054
|
|
|
} |
1055
|
|
|
/* @var XoopsMemberHandler $member_handler */ |
1056
|
|
|
$member_handler = xoops_getHandler('member'); |
1057
|
|
|
foreach ($deleted_num as $user_id => $post_num) { |
1058
|
|
|
// update user posts |
1059
|
|
|
$com_poster = $member_handler->getUser($user_id); |
1060
|
|
|
if (is_object($com_poster)) { |
1061
|
|
|
$member_handler->updateUserByField($com_poster, 'posts', $com_poster->getVar('posts') - $post_num); |
1062
|
|
|
} |
1063
|
|
|
} |
1064
|
|
|
|
1065
|
|
|
return true; |
1066
|
|
|
} |
1067
|
|
|
} |
1068
|
|
|
|
1069
|
|
|
return false; |
1070
|
|
|
} |
1071
|
|
|
|
1072
|
|
|
/** |
1073
|
|
|
* xoops_groupperm_deletebymoditem() |
1074
|
|
|
* |
1075
|
|
|
* Group Permission Helper Functions |
1076
|
|
|
* |
1077
|
|
|
* @param mixed $module_id |
1078
|
|
|
* @param mixed $perm_name |
1079
|
|
|
* @param mixed $item_id |
1080
|
|
|
* @return bool |
1081
|
|
|
*/ |
1082
|
|
|
function xoops_groupperm_deletebymoditem($module_id, $perm_name, $item_id = null) |
1083
|
|
|
{ |
1084
|
|
|
// do not allow system permissions to be deleted |
1085
|
|
|
if ((int)$module_id <= 1) { |
1086
|
|
|
return false; |
1087
|
|
|
} |
1088
|
|
|
/* @var XoopsGroupPermHandler $gperm_handler */ |
1089
|
|
|
$gperm_handler = xoops_getHandler('groupperm'); |
1090
|
|
|
|
1091
|
|
|
return $gperm_handler->deleteByModule($module_id, $perm_name, $item_id); |
1092
|
|
|
} |
1093
|
|
|
|
1094
|
|
|
/** |
1095
|
|
|
* xoops_utf8_encode() |
1096
|
|
|
* |
1097
|
|
|
* @param mixed $text |
1098
|
|
|
* @return string |
1099
|
|
|
*/ |
1100
|
|
|
function xoops_utf8_encode(&$text) |
1101
|
|
|
{ |
1102
|
|
|
xoops_load('XoopsLocal'); |
1103
|
|
|
|
1104
|
|
|
return XoopsLocal::utf8_encode($text); |
1105
|
|
|
} |
1106
|
|
|
|
1107
|
|
|
/** |
1108
|
|
|
* xoops_convert_encoding() |
1109
|
|
|
* |
1110
|
|
|
* @param mixed $text |
1111
|
|
|
* @return string |
1112
|
|
|
*/ |
1113
|
|
|
function xoops_convert_encoding(&$text) |
1114
|
|
|
{ |
1115
|
|
|
return xoops_utf8_encode($text); |
1116
|
|
|
} |
1117
|
|
|
|
1118
|
|
|
/** |
1119
|
|
|
* xoops_trim() |
1120
|
|
|
* |
1121
|
|
|
* @param mixed $text |
1122
|
|
|
* @return string |
1123
|
|
|
*/ |
1124
|
|
|
function xoops_trim($text) |
1125
|
|
|
{ |
1126
|
|
|
xoops_load('XoopsLocal'); |
1127
|
|
|
|
1128
|
|
|
return XoopsLocal::trim($text); |
1129
|
|
|
} |
1130
|
|
|
|
1131
|
|
|
/** |
1132
|
|
|
* YOU SHOULD NOT USE THIS METHOD, IT WILL BE REMOVED |
1133
|
|
|
*/ |
1134
|
|
|
/** |
1135
|
|
|
* xoops_getOption() |
1136
|
|
|
* |
1137
|
|
|
* @param mixed $option |
1138
|
|
|
* @internal param string $type |
1139
|
|
|
* @deprecated |
1140
|
|
|
* @return string |
1141
|
|
|
*/ |
1142
|
|
|
function xoops_getOption($option) |
1143
|
|
|
{ |
1144
|
|
|
$ret = ''; |
1145
|
|
|
if (isset($GLOBALS['xoopsOption'][$option])) { |
1146
|
|
|
$ret = $GLOBALS['xoopsOption'][$option]; |
1147
|
|
|
} |
1148
|
|
|
|
1149
|
|
|
return $ret; |
1150
|
|
|
} |
1151
|
|
|
|
1152
|
|
|
/** |
1153
|
|
|
* YOU SHOULD NOT USE THIS METHOD, IT WILL BE REMOVED |
1154
|
|
|
*/ |
1155
|
|
|
/** |
1156
|
|
|
* xoops_getConfigOption() |
1157
|
|
|
* |
1158
|
|
|
* @param mixed $option |
1159
|
|
|
* @param array|string $type |
1160
|
|
|
* @internal param string $dirname |
1161
|
|
|
* @deprecated |
1162
|
|
|
* @return bool |
1163
|
|
|
*/ |
1164
|
|
|
function xoops_getConfigOption($option, $type = 'XOOPS_CONF') |
1165
|
|
|
{ |
1166
|
|
|
static $coreOptions = array(); |
1167
|
|
|
|
1168
|
|
|
if (is_array($coreOptions) && array_key_exists($option, $coreOptions)) { |
1169
|
|
|
return $coreOptions[$option]; |
1170
|
|
|
} |
1171
|
|
|
$ret = false; |
1172
|
|
|
/* @var XoopsConfigHandler $config_handler */ |
1173
|
|
|
$config_handler = xoops_getHandler('config'); |
1174
|
|
|
$configs = $config_handler->getConfigsByCat(is_array($type) ? $type : constant($type)); |
|
|
|
|
1175
|
|
|
if ($configs) { |
|
|
|
|
1176
|
|
|
if (isset($configs[$option])) { |
1177
|
|
|
$ret = $configs[$option]; |
1178
|
|
|
} |
1179
|
|
|
} |
1180
|
|
|
$coreOptions[$option] = $ret; |
1181
|
|
|
|
1182
|
|
|
return $ret; |
1183
|
|
|
} |
1184
|
|
|
|
1185
|
|
|
/** |
1186
|
|
|
* YOU SHOULD NOT USE THIS METHOD, IT WILL BE REMOVED |
1187
|
|
|
*/ |
1188
|
|
|
/** |
1189
|
|
|
* xoops_setConfigOption() |
1190
|
|
|
* |
1191
|
|
|
* @param mixed $option |
1192
|
|
|
* @param null $new |
|
|
|
|
1193
|
|
|
* @return void |
1194
|
|
|
@deprecated |
1195
|
|
|
*/ |
1196
|
|
|
function xoops_setConfigOption($option, $new = null) |
1197
|
|
|
{ |
1198
|
|
|
if (isset($GLOBALS['xoopsConfig'][$option]) && null !== $new) { |
|
|
|
|
1199
|
|
|
$GLOBALS['xoopsConfig'][$option] = $new; |
1200
|
|
|
} |
1201
|
|
|
} |
1202
|
|
|
|
1203
|
|
|
/** |
1204
|
|
|
* YOU SHOULD NOT USE THIS METHOD, IT WILL BE REMOVED |
1205
|
|
|
*/ |
1206
|
|
|
/** |
1207
|
|
|
* xoops_getModuleOption |
1208
|
|
|
* |
1209
|
|
|
* Method for module developers getting a module config item. This could be from any module requested. |
1210
|
|
|
* |
1211
|
|
|
* @param mixed $option |
1212
|
|
|
* @param string $dirname |
1213
|
|
|
* @return bool |
1214
|
|
|
@deprecated |
1215
|
|
|
*/ |
1216
|
|
|
function xoops_getModuleOption($option, $dirname = '') |
1217
|
|
|
{ |
1218
|
|
|
static $modOptions = array(); |
1219
|
|
|
if (is_array($modOptions) && isset($modOptions[$dirname][$option])) { |
1220
|
|
|
return $modOptions[$dirname][$option]; |
1221
|
|
|
} |
1222
|
|
|
|
1223
|
|
|
$ret = false; |
1224
|
|
|
/* @var XoopsModuleHandler $module_handler */ |
1225
|
|
|
$module_handler = xoops_getHandler('module'); |
1226
|
|
|
$module = $module_handler->getByDirname($dirname); |
1227
|
|
|
/* @var XoopsConfigHandler $config_handler */ |
1228
|
|
|
$config_handler = xoops_getHandler('config'); |
1229
|
|
|
if (is_object($module)) { |
1230
|
|
|
$moduleConfig = $config_handler->getConfigsByCat(0, $module->getVar('mid')); |
1231
|
|
|
if (isset($moduleConfig[$option])) { |
1232
|
|
|
$ret = $moduleConfig[$option]; |
1233
|
|
|
} |
1234
|
|
|
} |
1235
|
|
|
$modOptions[$dirname][$option] = $ret; |
1236
|
|
|
|
1237
|
|
|
return $ret; |
1238
|
|
|
} |
1239
|
|
|
|
1240
|
|
|
/** |
1241
|
|
|
* Determine the base domain name for a URL. The primary use for this is to set the domain |
1242
|
|
|
* used for cookies to represent any subdomains. |
1243
|
|
|
* |
1244
|
|
|
* The registrable domain is determined using the public suffix list. If the domain is not |
1245
|
|
|
* registrable, an empty string is returned. This empty string can be used in setcookie() |
1246
|
|
|
* as the domain, which restricts cookie to just the current host. |
1247
|
|
|
* |
1248
|
|
|
* @param string $url URL or hostname to process |
1249
|
|
|
* |
1250
|
|
|
* @return string the registrable domain or an empty string |
1251
|
|
|
*/ |
1252
|
|
|
function xoops_getBaseDomain($url) |
1253
|
|
|
{ |
1254
|
|
|
$parts = parse_url($url); |
1255
|
|
|
$host = ''; |
1256
|
|
|
if (!empty($parts['host'])) { |
1257
|
|
|
$host = $parts['host']; |
1258
|
|
|
if (strtolower($host) === 'localhost') { |
1259
|
|
|
return 'localhost'; |
1260
|
|
|
} |
1261
|
|
|
// bail if this is an IPv4 address (IPv6 will fail later) |
1262
|
|
|
if (false !== filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
1263
|
|
|
return ''; |
1264
|
|
|
} |
1265
|
|
|
$regdom = new \Geekwright\RegDom\RegisteredDomain(); |
1266
|
|
|
$host = $regdom->getRegisteredDomain($host); |
1267
|
|
|
} |
1268
|
|
|
return (null === $host) ? '' : $host; |
1269
|
|
|
} |
1270
|
|
|
|
1271
|
|
|
/** |
1272
|
|
|
* YOU SHOULD NOT USE THIS METHOD, IT WILL BE REMOVED |
1273
|
|
|
*/ |
1274
|
|
|
/** |
1275
|
|
|
* Function to get the domain from a URL. |
1276
|
|
|
* |
1277
|
|
|
* @param string $url the URL to be stripped. |
1278
|
|
|
* @return string |
1279
|
|
|
* @deprecated |
1280
|
|
|
*/ |
1281
|
|
|
function xoops_getUrlDomain($url) |
1282
|
|
|
{ |
1283
|
|
|
$domain = ''; |
1284
|
|
|
$_URL = parse_url($url); |
1285
|
|
|
|
1286
|
|
|
if (!empty($_URL) || !empty($_URL['host'])) { |
1287
|
|
|
$domain = $_URL['host']; |
1288
|
|
|
} |
1289
|
|
|
|
1290
|
|
|
return $domain; |
1291
|
|
|
} |
1292
|
|
|
|
1293
|
|
|
/** |
1294
|
|
|
* Check that the variable passed as $name is set, and if not, set with the specified $default. |
1295
|
|
|
* |
1296
|
|
|
* Note that $name is passed by reference, so it will be established in the caller's context |
1297
|
|
|
* if not already set. The value of $name is returned for convenience as well. |
1298
|
|
|
* |
1299
|
|
|
* @param mixed $name Passed by reference variable. Will be created if is not set. |
1300
|
|
|
* @param mixed $default The default to use if $name is not set |
1301
|
|
|
* |
1302
|
|
|
* @return mixed the value in $name |
1303
|
|
|
*/ |
1304
|
|
|
function makeSet(&$name, $default) |
1305
|
|
|
{ |
1306
|
|
|
if (!isset($name)) { |
1307
|
|
|
$name = $default; |
1308
|
|
|
} |
1309
|
|
|
return $name; |
1310
|
|
|
} |
1311
|
|
|
|
1312
|
|
|
include_once __DIR__ . '/functions.encoding.php'; |
1313
|
|
|
include_once __DIR__ . '/functions.legacy.php'; |
1314
|
|
|
|