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: $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: * xoops_getModuleHandler()
58: *
59: * @param string $name
60: * @param mixed $module_dir
61: * @param bool $optional
62: * @return XoopsObjectHandler|false
63: */
64: function xoops_getModuleHandler($name = null, $module_dir = null, $optional = false)
65: {
66: static $handlers;
67: // if $module_dir is not specified
68: if (!isset($module_dir)) {
69: // if a module is loaded
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: * XOOPS class loader wrapper
102: *
103: * Temporay solution for XOOPS 2.3
104: *
105: * @param string $name Name of class to be loaded
106: * @param string $type domain of the class, potential values: core - located in /class/;
107: * framework - located in /Frameworks/;
108: * other - module class, located in /modules/[$type]/class/
109: *
110: * @return boolean
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: * XOOPS language loader wrapper
123: *
124: * Temporay solution, not encouraged to use
125: *
126: * @param string $name Name of language file to be loaded, without extension
127: * @param string $domain Module dirname; global language file will be loaded if $domain is set to 'global' or not specified
128: * @param string $language Language to be loaded, current language content will be loaded if not specified
129: * @return boolean
130: * @todo expand domain to multiple categories, e.g. module:system, framework:filter, etc.
131: *
132: */
133: function xoops_loadLanguage($name, $domain = '', $language = null)
134: {
135: /**
136: * Set pageType
137: */
138: if ($name === 'pagetype') {
139: $name = xoops_getOption('pagetype');
140: }
141: /**
142: * We must check later for an empty value. As xoops_getOption could be empty
143: */
144: if (empty($name)) {
145: return false;
146: }
147: // $language = empty($language) ? $GLOBALS['xoopsConfig']['language'] : $language;
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: * YOU SHOULD BE CAREFUL WITH USING THIS METHOD SINCE IT WILL BE DEPRECATED
163: */
164: /**
165: * xoops_getActiveModules()
166: *
167: * Get active modules from cache file
168: *
169: * @return array
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: * YOU SHOULD BE CAREFUL WITH USING THIS METHOD SINCE IT WILL BE DEPRECATED
187: */
188: /**
189: * xoops_setActiveModules()
190: *
191: * Write active modules to cache file
192: *
193: * @return array
194: */
195: function xoops_setActiveModules()
196: {
197: xoops_load('XoopsCache');
198: /** @var XoopsModuleHandler $module_handler */
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: * YOU SHOULD BE CAREFUL WITH USING THIS METHOD SINCE IT WILL BE DEPRECATED
213: */
214: /**
215: * xoops_isActiveModule()
216: *
217: * Checks is module is installed and active
218: *
219: * @param $dirname
220: * @return bool
221: */
222: function xoops_isActiveModule($dirname)
223: {
224: return isset($dirname) && in_array($dirname, xoops_getActiveModules());
225: }
226:
227: /**
228: * xoops_header()
229: *
230: * @param mixed $closehead
231: * @return void
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; // expose template for use by caller
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: * xoops_footer
285: *
286: * @return void
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: * xoops_error
310: *
311: * @param mixed $msg
312: * @param string $title
313: * @return void
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: * xoops_warning
339: *
340: * @param mixed $msg
341: * @param string $title
342: * @return void
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: * xoops_result
368: *
369: * @param mixed $msg
370: * @param string $title
371: * @return void
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: * xoops_confirm()
397: *
398: * @param mixed $hiddens
399: * @param mixed $action
400: * @param mixed $msg
401: * @param string $submit
402: * @param mixed $addtoken
403: * @return void
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: // TODO - these buttons should go through formRenderer
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: * xoops_getUserTimestamp()
463: *
464: * @param mixed $time
465: * @param string $timeoffset
466: * @return int
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: * Function to display formatted times in user timezone
485: * @param $time
486: * @param string $format
487: * @param string $timeoffset
488: * @return string
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: * Function to calculate server timestamp from user entered time (timestamp)
499: * @param $timestamp
500: * @param null $userTZ
501: * @return
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: * xoops_makepass()
516: *
517: * @return string
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: * checkEmail()
620: *
621: * @param mixed $email
622: * @param mixed $antispam
623: * @return bool|mixed
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; // Not enough parts to domain
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: * formatURL()
659: *
660: * @param mixed $url
661: * @return mixed|string
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: * Function to get banner html tags for use in templates
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: // EMPTY
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: * Check if this impression is the last one
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: * Print the banner
724: */
725: $bannerobject = '';
726: if ($htmlbanner) {
727: if ($htmlcode) {
728: $bannerobject = $htmlcode;
729: } else {
730: $bannerobject = $bannerobject . '<div id="xo-bannerfix">';
731: // $bannerobject = $bannerobject . '<div id="xo-fixbanner">';
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: // $bannerobject .= '</div>';
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&amp;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&amp;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: * Function to redirect a user to certain pages
754: * @param $url
755: * @param int $time
756: * @param string $message
757: * @param bool $addredirect
758: * @param bool $allowExternalLink
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: // under normal circumstance this event will exit, so listen for the .start above
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 .= '&amp;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 .= '&amp;' . SID;
823: }
824: }
825: $url = preg_replace('/&amp;/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: * xoops_getenv()
837: *
838: * @param mixed $key
839: * @return string
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: * Function to get css file for a certain themeset
860: * @param string $theme
861: * @return string
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: * xoops_getMailer()
895: *
896: * @return \XoopsMailer|\XoopsMailerLocal
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: * xoops_getrank()
923: *
924: * @param integer $rank_id
925: * @param mixed $posts
926: * @return
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: * 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.
954: *
955: * @param string $str
956: * @param int $start
957: * @param int $length
958: * @param string $trimmarker
959: * @return string
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: // RMV-NOTIFY
969: // ################ Notification Helper Functions ##################
970: // We want to be able to delete by module, by user, or by item.
971: // How do we specify this??
972: /**
973: * @param $module_id
974: *
975: * @return mixed
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: * xoops_notification_deletebyuser()
986: *
987: * @param mixed $user_id
988: * @return
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: * xoops_notification_deletebyitem()
999: *
1000: * @param mixed $module_id
1001: * @param mixed $category
1002: * @param mixed $item_id
1003: * @return
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: * xoops_comment_count()
1014: *
1015: * @param mixed $module_id
1016: * @param mixed $item_id
1017: * @return
1018: */
1019: function xoops_comment_count($module_id, $item_id = null)
1020: {
1021: /** @var \XoopsCommentHandler $comment_handler */
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: * xoops_comment_delete()
1033: *
1034: * @param mixed $module_id
1035: * @param mixed $item_id
1036: * @return bool
1037: */
1038: function xoops_comment_delete($module_id, $item_id)
1039: {
1040: if ((int)$module_id > 0 && (int)$item_id > 0) {
1041: /** @var \XoopsCommentHandler $comment_handler */
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: // store poster ID and deleted post number into array for later use
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: /** @var XoopsMemberHandler $member_handler */
1057: $member_handler = xoops_getHandler('member');
1058: foreach ($deleted_num as $user_id => $post_num) {
1059: // update user posts
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: * xoops_groupperm_deletebymoditem()
1075: *
1076: * Group Permission Helper Functions
1077: *
1078: * @param mixed $module_id
1079: * @param mixed $perm_name
1080: * @param mixed $item_id
1081: * @return bool
1082: */
1083: function xoops_groupperm_deletebymoditem($module_id, $perm_name, $item_id = null)
1084: {
1085: // do not allow system permissions to be deleted
1086: if ((int)$module_id <= 1) {
1087: return false;
1088: }
1089: /** @var XoopsGroupPermHandler $gperm_handler */
1090: $gperm_handler = xoops_getHandler('groupperm');
1091:
1092: return $gperm_handler->deleteByModule($module_id, $perm_name, $item_id);
1093: }
1094:
1095: /**
1096: * xoops_utf8_encode()
1097: *
1098: * @param mixed $text
1099: * @return string
1100: */
1101: function xoops_utf8_encode(&$text)
1102: {
1103: xoops_load('XoopsLocal');
1104:
1105: return XoopsLocal::utf8_encode($text);
1106: }
1107:
1108: /**
1109: * xoops_utf8_decode()
1110: *
1111: * @param mixed $text
1112: * @return string
1113: */
1114: function xoops_utf8_decode(&$text)
1115: {
1116: xoops_load('XoopsLocal');
1117:
1118: return XoopsLocal::utf8_decode($text);
1119: }
1120:
1121: /**
1122: * xoops_convert_encoding()
1123: *
1124: * @param mixed $text
1125: * @return string
1126: */
1127: function xoops_convert_encoding(&$text)
1128: {
1129: return xoops_utf8_encode($text);
1130: }
1131:
1132: /**
1133: * xoops_trim()
1134: *
1135: * @param mixed $text
1136: * @return string
1137: */
1138: function xoops_trim($text)
1139: {
1140: xoops_load('XoopsLocal');
1141:
1142: return XoopsLocal::trim($text);
1143: }
1144:
1145: /**
1146: * YOU SHOULD NOT USE THIS METHOD, IT WILL BE REMOVED
1147: */
1148: /**
1149: * xoops_getOption()
1150: *
1151: * @param mixed $option
1152: * @internal param string $type
1153: * @deprecated
1154: * @return string
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: * YOU SHOULD NOT USE THIS METHOD, IT WILL BE REMOVED
1168: */
1169: /**
1170: * xoops_getConfigOption()
1171: *
1172: * @param mixed $option
1173: * @param array|string $type
1174: * @internal param string $dirname
1175: * @deprecated
1176: * @return bool
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: /** @var XoopsConfigHandler $config_handler */
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: * YOU SHOULD NOT USE THIS METHOD, IT WILL BE REMOVED
1201: */
1202: /**
1203: * xoops_setConfigOption()
1204: *
1205: * @param mixed $option
1206: * @param null $new
1207: * @return void
1208: @deprecated
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: * YOU SHOULD NOT USE THIS METHOD, IT WILL BE REMOVED
1219: */
1220: /**
1221: * xoops_getModuleOption
1222: *
1223: * Method for module developers getting a module config item. This could be from any module requested.
1224: *
1225: * @param mixed $option
1226: * @param string $dirname
1227: * @return bool
1228: @deprecated
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: /** @var XoopsModuleHandler $module_handler */
1239: $module_handler = xoops_getHandler('module');
1240: $module = $module_handler->getByDirname($dirname);
1241: /** @var XoopsConfigHandler $config_handler */
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: * Determine the base domain name for a URL. The primary use for this is to set the domain
1256: * used for cookies to represent any subdomains.
1257: *
1258: * The registrable domain is determined using the public suffix list. If the domain is not
1259: * registrable, an empty string is returned. This empty string can be used in setcookie()
1260: * as the domain, which restricts cookie to just the current host.
1261: *
1262: * @param string $url URL or hostname to process
1263: *
1264: * @return string the registrable domain or an empty string
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: // bail if this is an IPv4 address (IPv6 will fail later)
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: * YOU SHOULD NOT USE THIS METHOD, IT WILL BE REMOVED
1287: */
1288: /**
1289: * Function to get the domain from a URL.
1290: *
1291: * @param string $url the URL to be stripped.
1292: * @return string
1293: * @deprecated
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: * Check that the variable passed as $name is set, and if not, set with the specified $default.
1309: *
1310: * Note that $name is passed by reference, so it will be established in the caller's context
1311: * if not already set. The value of $name is returned for convenience as well.
1312: *
1313: * @param mixed $name Passed by reference variable. Will be created if is not set.
1314: * @param mixed $default The default to use if $name is not set
1315: *
1316: * @return mixed the value in $name
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: