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