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