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: 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:   55:   56:   57:   58:   59:   60: 
  61: function xoops_getModuleHandler($name = null, $module_dir = null, $optional = false)
  62: {
  63:     static $handlers;
  64:     
  65:     if (!isset($module_dir)) {
  66:         
  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:   99:  100:  101:  102:  103:  104:  105:  106:  107:  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:  120:  121:  122:  123:  124:  125:  126:  127:  128:  129: 
 130: function xoops_loadLanguage($name, $domain = '', $language = null)
 131: {
 132:      133:  134: 
 135:     if ($name === 'pagetype') {
 136:         $name = xoops_getOption('pagetype');
 137:     }
 138:      139:  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:  158: 
 159:  160:  161:  162:  163:  164:  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:  182: 
 183:  184:  185:  186:  187:  188:  189: 
 190: function xoops_setActiveModules()
 191: {
 192:     xoops_load('XoopsCache');
 193:     
 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:  208: 
 209:  210:  211:  212:  213:  214:  215:  216: 
 217: function xoops_isActiveModule($dirname)
 218: {
 219:     return isset($dirname) && in_array($dirname, xoops_getActiveModules());
 220: }
 221: 
 222:  223:  224:  225:  226:  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:  278:  279:  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:  303:  304:  305:  306:  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:  332:  333:  334:  335:  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:  361:  362:  363:  364:  365:  366:  367:  368: 
 369: function xoops_confirm($hiddens, $action, $msg, $submit = '', $addtoken = true)
 370: {
 371:     $submit = ($submit != '') ? trim($submit) : _SUBMIT;
 372:     echo '<div class="confirmMsg">' . $msg . '<br>
 373:           <form method="post" action="' . $action . '">';
 374:     foreach ($hiddens as $name => $value) {
 375:         if (is_array($value)) {
 376:             foreach ($value as $caption => $newvalue) {
 377:                 echo '<input type="radio" name="' . $name . '" value="' . htmlspecialchars($newvalue) . '" /> ' . $caption;
 378:             }
 379:             echo '<br>';
 380:         } else {
 381:             echo '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($value) . '" />';
 382:         }
 383:     }
 384:     if ($addtoken != false) {
 385:         echo $GLOBALS['xoopsSecurity']->getTokenHTML();
 386:     }
 387:     echo '<input type="submit" class="btn btn-default" name="confirm_submit" value="' . $submit . '" title="' . $submit . '"/>
 388:           <input type="button" class="btn btn-default" name="confirm_back" value="' . _CANCEL . '" onclick="history.go(-1);" title="' . _CANCEL . '" />
 389:           </form>
 390:           </div>';
 391: }
 392: 
 393:  394:  395:  396:  397:  398:  399: 
 400: function xoops_getUserTimestamp($time, $timeoffset = '')
 401: {
 402:     global $xoopsConfig, $xoopsUser;
 403:     if ($timeoffset == '') {
 404:         if ($xoopsUser) {
 405:             $timeoffset = $xoopsUser->getVar('timezone_offset');
 406:         } else {
 407:             $timeoffset = $xoopsConfig['default_TZ'];
 408:         }
 409:     }
 410:     $usertimestamp = (int)$time + ((float)$timeoffset - $xoopsConfig['server_TZ']) * 3600;
 411: 
 412:     return $usertimestamp;
 413: }
 414: 
 415:  416:  417:  418:  419:  420:  421: 
 422: function formatTimestamp($time, $format = 'l', $timeoffset = '')
 423: {
 424:     xoops_load('XoopsLocal');
 425: 
 426:     return XoopsLocal::formatTimestamp($time, $format, $timeoffset);
 427: }
 428: 
 429:  430:  431:  432:  433:  434: 
 435: function userTimeToServerTime($timestamp, $userTZ = null)
 436: {
 437:     global $xoopsConfig;
 438:     if (!isset($userTZ)) {
 439:         $userTZ = $xoopsConfig['default_TZ'];
 440:     }
 441:     $timestamp -= (($userTZ - $xoopsConfig['server_TZ']) * 3600);
 442: 
 443:     return $timestamp;
 444: }
 445: 
 446:  447:  448:  449:  450: 
 451: function xoops_makepass()
 452: {
 453:     $makepass  = '';
 454:     $syllables = array(
 455:         'er',
 456:         'in',
 457:         'tia',
 458:         'wol',
 459:         'fe',
 460:         'pre',
 461:         'vet',
 462:         'jo',
 463:         'nes',
 464:         'al',
 465:         'len',
 466:         'son',
 467:         'cha',
 468:         'ir',
 469:         'ler',
 470:         'bo',
 471:         'ok',
 472:         'tio',
 473:         'nar',
 474:         'sim',
 475:         'ple',
 476:         'bla',
 477:         'ten',
 478:         'toe',
 479:         'cho',
 480:         'co',
 481:         'lat',
 482:         'spe',
 483:         'ak',
 484:         'er',
 485:         'po',
 486:         'co',
 487:         'lor',
 488:         'pen',
 489:         'cil',
 490:         'li',
 491:         'ght',
 492:         'wh',
 493:         'at',
 494:         'the',
 495:         'he',
 496:         'ck',
 497:         'is',
 498:         'mam',
 499:         'bo',
 500:         'no',
 501:         'fi',
 502:         've',
 503:         'any',
 504:         'way',
 505:         'pol',
 506:         'iti',
 507:         'cs',
 508:         'ra',
 509:         'dio',
 510:         'sou',
 511:         'rce',
 512:         'sea',
 513:         'rch',
 514:         'pa',
 515:         'per',
 516:         'com',
 517:         'bo',
 518:         'sp',
 519:         'eak',
 520:         'st',
 521:         'fi',
 522:         'rst',
 523:         'gr',
 524:         'oup',
 525:         'boy',
 526:         'ea',
 527:         'gle',
 528:         'tr',
 529:         'ail',
 530:         'bi',
 531:         'ble',
 532:         'brb',
 533:         'pri',
 534:         'dee',
 535:         'kay',
 536:         'en',
 537:         'be',
 538:         'se');
 539:     mt_srand((double)microtime() * 1000000);
 540:     for ($count = 1; $count <= 4; ++$count) {
 541:         if (mt_rand() % 10 == 1) {
 542:             $makepass .= sprintf('%0.0f', (mt_rand() % 50) + 1);
 543:         } else {
 544:             $makepass .= sprintf('%s', $syllables[mt_rand() % 62]);
 545:         }
 546:     }
 547: 
 548:     return $makepass;
 549: }
 550: 
 551:  552:  553:  554:  555:  556:  557: 
 558: function checkEmail($email, $antispam = false)
 559: {
 560:     if (!$email || !preg_match('/^[^@]{1,64}@[^@]{1,255}$/', $email)) {
 561:         return false;
 562:     }
 563:     $email_array      = explode('@', $email);
 564:     $local_array      = explode('.', $email_array[0]);
 565:     $local_arrayCount = count($local_array);
 566:     for ($i = 0; $i < $local_arrayCount; ++$i) {
 567:         if (!preg_match("/^(([A-Za-z0-9!#$%&'*+\/\=?^_`{|}~-][A-Za-z0-9!#$%&'*+\/\=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/", $local_array[$i])) {
 568:             return false;
 569:         }
 570:     }
 571:     if (!preg_match("/^\[?[0-9\.]+\]?$/", $email_array[1])) {
 572:         $domain_array = explode('.', $email_array[1]);
 573:         if (count($domain_array) < 2) {
 574:             return false; 
 575:         }
 576:         for ($i = 0; $i < count($domain_array); ++$i) {
 577:             if (!preg_match("/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$/", $domain_array[$i])) {
 578:                 return false;
 579:             }
 580:         }
 581:     }
 582:     if ($antispam) {
 583:         $email = str_replace('@', ' at ', $email);
 584:         $email = str_replace('.', ' dot ', $email);
 585:     }
 586: 
 587:     return $email;
 588: }
 589: 
 590:  591:  592:  593:  594:  595: 
 596: function formatURL($url)
 597: {
 598:     $url = trim($url);
 599:     if ($url != '') {
 600:         if ((!preg_match('/^http[s]*:\/\//i', $url)) && (!preg_match('/^ftp*:\/\//i', $url)) && (!preg_match('/^ed2k*:\/\//i', $url))) {
 601:             $url = 'http://' . $url;
 602:         }
 603:     }
 604: 
 605:     return $url;
 606: }
 607: 
 608:  609:  610: 
 611: function xoops_getbanner()
 612: {
 613:     global $xoopsConfig;
 614: 
 615:     $db      = XoopsDatabaseFactory::getDatabaseConnection();
 616:     $bresult = $db->query('SELECT COUNT(*) FROM ' . $db->prefix('banner'));
 617:     list($numrows) = $db->fetchRow($bresult);
 618:     if ($numrows > 1) {
 619:         --$numrows;
 620:         mt_srand((double)microtime() * 1000000);
 621:         $bannum = mt_rand(0, $numrows);
 622:     } else {
 623:         $bannum = 0;
 624:     }
 625:     if ($numrows > 0) {
 626:         $bresult = $db->query('SELECT * FROM ' . $db->prefix('banner'), 1, $bannum);
 627:         list($bid, $cid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date, $htmlbanner, $htmlcode) = $db->fetchRow($bresult);
 628:         if ($xoopsConfig['my_ip'] == xoops_getenv('REMOTE_ADDR')) {
 629:             
 630:         } else {
 631:             ++$impmade;
 632:             $db->queryF(sprintf('UPDATE %s SET impmade = %u WHERE bid = %u', $db->prefix('banner'), $impmade, $bid));
 633:              634:  635: 
 636:             if ($imptotal > 0 && $impmade >= $imptotal) {
 637:                 $newid = $db->genId($db->prefix('bannerfinish') . '_bid_seq');
 638:                 $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());
 639:                 $db->queryF($sql);
 640:                 $db->queryF(sprintf('DELETE FROM %s WHERE bid = %u', $db->prefix('banner'), $bid));
 641:             }
 642:         }
 643:          644:  645: 
 646:         $bannerobject = '';
 647:         if ($htmlbanner) {
 648:             if ($htmlcode) {
 649:                 $bannerobject = $htmlcode;
 650:             } else {
 651:                 $bannerobject = $bannerobject . '<div id="xo-bannerfix">';
 652:                 
 653:                 $bannerobject = $bannerobject . ' <iframe src=' . $imageurl . ' border="0" scrolling="no" allowtransparency="true" width="480px" height="60px" style="border:0" alt="' . $clickurl . ';"> </iframe>';
 654:                 $bannerobject .= '</div>';
 655:                 
 656:             }
 657:         } else {
 658:             $bannerobject = '<div id="xo-bannerfix">';
 659:             if (false !== stripos($imageurl, '.swf')) {
 660:                 $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>';
 661:             } else {
 662:                 $bannerobject = $bannerobject . '<a href="' . XOOPS_URL . '/banners.php?op=click&bid=' . $bid . '" rel="external" title="' . $clickurl . '"><img src="' . $imageurl . '" alt="' . $clickurl . '" /></a>';
 663:             }
 664: 
 665:             $bannerobject .= '</div>';
 666:         }
 667: 
 668:         return $bannerobject;
 669:     }
 670:     return null;
 671: }
 672: 
 673:  674:  675:  676:  677:  678:  679:  680: 
 681: function redirect_header($url, $time = 3, $message = '', $addredirect = true, $allowExternalLink = false)
 682: {
 683:     global $xoopsConfig, $xoopsLogger, $xoopsUserIsAdmin;
 684: 
 685:     $xoopsPreload = XoopsPreload::getInstance();
 686:     $xoopsPreload->triggerEvent('core.include.functions.redirectheader.start', array($url, $time, $message, $addredirect, $allowExternalLink));
 687:     
 688:     $xoopsPreload->triggerEvent('core.include.functions.redirectheader', array($url, $time, $message, $addredirect, $allowExternalLink));
 689: 
 690:     if (preg_match("/[\\0-\\31]|about:|script:/i", $url)) {
 691:         if (!preg_match('/^\b(java)?script:([\s]*)history\.go\(-\d*\)([\s]*[;]*[\s]*)$/si', $url)) {
 692:             $url = XOOPS_URL;
 693:         }
 694:     }
 695:     if (!$allowExternalLink && $pos = strpos($url, '://')) {
 696:         $xoopsLocation = substr(XOOPS_URL, strpos(XOOPS_URL, '://') + 3);
 697:         if (strcasecmp(substr($url, $pos + 3, strlen($xoopsLocation)), $xoopsLocation)) {
 698:             $url = XOOPS_URL;
 699:         }
 700:     }
 701:     if (defined('XOOPS_CPFUNC_LOADED')) {
 702:         $theme = 'default';
 703:     } else {
 704:         $theme = $xoopsConfig['theme_set'];
 705:     }
 706: 
 707:     require_once XOOPS_ROOT_PATH . '/class/template.php';
 708:     require_once XOOPS_ROOT_PATH . '/class/theme.php';
 709:     $xoopsThemeFactory                = null;
 710:     $xoopsThemeFactory                = new xos_opal_ThemeFactory();
 711:     $xoopsThemeFactory->allowedThemes = $xoopsConfig['theme_set_allowed'];
 712:     $xoopsThemeFactory->defaultTheme  = $theme;
 713:     $xoTheme                          = $xoopsThemeFactory->createInstance(array(
 714:                                                                                 'plugins'      => array(),
 715:                                                                                 'renderBanner' => false));
 716:     $xoopsTpl                         = $xoTheme->template;
 717:     $xoopsTpl->assign(array(
 718:                           'xoops_theme'      => $theme,
 719:                           'xoops_imageurl'   => XOOPS_THEME_URL . '/' . $theme . '/',
 720:                           'xoops_themecss'   => xoops_getcss($theme),
 721:                           'xoops_requesturi' => htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES),
 722:                           'xoops_sitename'   => htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES),
 723:                           'xoops_slogan'     => htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES),
 724:                           'xoops_dirname'    => isset($xoopsModule) && is_object($xoopsModule) ? $xoopsModule->getVar('dirname') : 'system',
 725:                           'xoops_pagetitle'  => isset($xoopsModule) && is_object($xoopsModule) ? $xoopsModule->getVar('name') : htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES)));
 726:     if ($xoopsConfig['debug_mode'] == 2 && $xoopsUserIsAdmin) {
 727:         $xoopsTpl->assign('time', 300);
 728:         $xoopsTpl->assign('xoops_logdump', $xoopsLogger->dump());
 729:     } else {
 730:         $xoopsTpl->assign('time', (int)$time);
 731:     }
 732:     if (!empty($_SERVER['REQUEST_URI']) && $addredirect && false !== strpos($url, 'user.php')) {
 733:         if (false === strpos($url, '?')) {
 734:             $url .= '?xoops_redirect=' . urlencode($_SERVER['REQUEST_URI']);
 735:         } else {
 736:             $url .= '&xoops_redirect=' . urlencode($_SERVER['REQUEST_URI']);
 737:         }
 738:     }
 739:     if (defined('SID') && SID && (!isset($_COOKIE[session_name()]) || ($xoopsConfig['use_mysession'] && $xoopsConfig['session_name'] != '' && !isset($_COOKIE[$xoopsConfig['session_name']])))) {
 740:         if (false === strpos($url, '?')) {
 741:             $url .= '?' . SID;
 742:         } else {
 743:             $url .= '&' . SID;
 744:         }
 745:     }
 746:     $url = preg_replace('/&/i', '&', htmlspecialchars($url, ENT_QUOTES));
 747:     $xoopsTpl->assign('url', $url);
 748:     $message = trim($message) != '' ? $message : _TAKINGBACK;
 749:     $xoopsTpl->assign('message', $message);
 750:     $xoopsTpl->assign('lang_ifnotreload', sprintf(_IFNOTRELOAD, $url));
 751: 
 752:     $xoopsTpl->display('db:system_redirect.tpl');
 753:     exit();
 754: }
 755: 
 756:  757:  758:  759:  760:  761: 
 762: function xoops_getenv($key)
 763: {
 764:     $ret = '';
 765:     if (array_key_exists($key, $_SERVER) && isset($_SERVER[$key])) {
 766:         $ret = $_SERVER[$key];
 767: 
 768:         return $ret;
 769:     }
 770:     if (array_key_exists($key, $_ENV) && isset($_ENV[$key])) {
 771:         $ret = $_ENV[$key];
 772: 
 773:         return $ret;
 774:     }
 775: 
 776:     return $ret;
 777: }
 778: 
 779:  780:  781:  782:  783: 
 784: function xoops_getcss($theme = '')
 785: {
 786:     if ($theme == '') {
 787:         $theme = $GLOBALS['xoopsConfig']['theme_set'];
 788:     }
 789:     $uagent  = xoops_getenv('HTTP_USER_AGENT');
 790:     $str_css = 'styleNN.css';
 791:     if (false !== stripos($uagent, 'mac')) {
 792:         $str_css = 'styleMAC.css';
 793:     } elseif (preg_match("/MSIE (\d\.\d{1,2})/i", $uagent)) {
 794:         $str_css = 'style.css';
 795:     }
 796:     if (is_dir(XOOPS_THEME_PATH . '/' . $theme)) {
 797:         if (file_exists(XOOPS_THEME_PATH . '/' . $theme . '/' . $str_css)) {
 798:             return XOOPS_THEME_URL . '/' . $theme . '/' . $str_css;
 799:         } elseif (file_exists(XOOPS_THEME_PATH . '/' . $theme . '/style.css')) {
 800:             return XOOPS_THEME_URL . '/' . $theme . '/style.css';
 801:         }
 802:     }
 803:     if (is_dir(XOOPS_THEME_PATH . '/' . $theme . '/css')) {
 804:         if (file_exists(XOOPS_THEME_PATH . '/' . $theme . '/css/' . $str_css)) {
 805:             return XOOPS_THEME_URL . '/' . $theme . '/css/' . $str_css;
 806:         } elseif (file_exists(XOOPS_THEME_PATH . '/' . $theme . '/css/style.css')) {
 807:             return XOOPS_THEME_URL . '/' . $theme . '/css/style.css';
 808:         }
 809:     }
 810: 
 811:     return '';
 812: }
 813: 
 814:  815:  816:  817:  818: 
 819: function xoops_getMailer()
 820: {
 821:     static $mailer;
 822:     global $xoopsConfig;
 823:     if (is_object($mailer)) {
 824:         return $mailer;
 825:     }
 826:     include_once XOOPS_ROOT_PATH . '/class/xoopsmailer.php';
 827:     if (file_exists($file = XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/xoopsmailerlocal.php')) {
 828:         include_once $file;
 829:     } elseif (file_exists($file = XOOPS_ROOT_PATH . '/language/english/xoopsmailerlocal.php')) {
 830:         include_once $file;
 831:     }
 832:     unset($mailer);
 833:     if (class_exists('XoopsMailerLocal')) {
 834:         $mailer = new XoopsMailerLocal();
 835:     } else {
 836:         $mailer = new XoopsMailer();
 837:     }
 838: 
 839:     return $mailer;
 840: }
 841: 
 842:  843:  844:  845:  846:  847:  848: 
 849: function xoops_getrank($rank_id = 0, $posts = 0)
 850: {
 851:     $db      = XoopsDatabaseFactory::getDatabaseConnection();
 852:     $myts    = MyTextSanitizer::getInstance();
 853:     $rank_id = (int)$rank_id;
 854:     $posts   = (int)$posts;
 855:     if ($rank_id != 0) {
 856:         $sql = 'SELECT rank_title AS title, rank_image AS image FROM ' . $db->prefix('ranks') . ' WHERE rank_id = ' . $rank_id;
 857:     } else {
 858:         $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';
 859:     }
 860:     $rank          = $db->fetchArray($db->query($sql));
 861:     $rank['title'] = $myts->htmlspecialchars($rank['title']);
 862:     $rank['id']    = $rank_id;
 863: 
 864:     return $rank;
 865: }
 866: 
 867:  868:  869:  870:  871:  872:  873:  874:  875: 
 876: function xoops_substr($str, $start, $length, $trimmarker = '...')
 877: {
 878:     xoops_load('XoopsLocal');
 879: 
 880:     return XoopsLocal::substr($str, $start, $length, $trimmarker);
 881: }
 882: 
 883: 
 884: 
 885: 
 886: 
 887:  888:  889:  890:  891: 
 892: function xoops_notification_deletebymodule($module_id)
 893: {
 894:     $notification_handler = xoops_getHandler('notification');
 895: 
 896:     return $notification_handler->unsubscribeByModule($module_id);
 897: }
 898: 
 899:  900:  901:  902:  903:  904: 
 905: function xoops_notification_deletebyuser($user_id)
 906: {
 907:     $notification_handler = xoops_getHandler('notification');
 908: 
 909:     return $notification_handler->unsubscribeByUser($user_id);
 910: }
 911: 
 912:  913:  914:  915:  916:  917:  918:  919: 
 920: function xoops_notification_deletebyitem($module_id, $category, $item_id)
 921: {
 922:     $notification_handler = xoops_getHandler('notification');
 923: 
 924:     return $notification_handler->unsubscribeByItem($module_id, $category, $item_id);
 925: }
 926: 
 927:  928:  929:  930:  931:  932:  933: 
 934: function xoops_comment_count($module_id, $item_id = null)
 935: {
 936:     $comment_handler = xoops_getHandler('comment');
 937:     $criteria        = new CriteriaCompo(new Criteria('com_modid', (int)$module_id));
 938:     if (isset($item_id)) {
 939:         $criteria->add(new Criteria('com_itemid', (int)$item_id));
 940:     }
 941: 
 942:     return $comment_handler->getCount($criteria);
 943: }
 944: 
 945:  946:  947:  948:  949:  950:  951: 
 952: function xoops_comment_delete($module_id, $item_id)
 953: {
 954:     if ((int)$module_id > 0 && (int)$item_id > 0) {
 955:         $comment_handler = xoops_getHandler('comment');
 956:         $comments        = $comment_handler->getByItemId($module_id, $item_id);
 957:         if (is_array($comments)) {
 958:             $count       = count($comments);
 959:             $deleted_num = array();
 960:             for ($i = 0; $i < $count; ++$i) {
 961:                 if (false !== $comment_handler->delete($comments[$i])) {
 962:                     
 963:                     $poster_id = $comments[$i]->getVar('com_uid');
 964:                     if ($poster_id != 0) {
 965:                         $deleted_num[$poster_id] = !isset($deleted_num[$poster_id]) ? 1 : ($deleted_num[$poster_id] + 1);
 966:                     }
 967:                 }
 968:             }
 969:             
 970:             $member_handler = xoops_getHandler('member');
 971:             foreach ($deleted_num as $user_id => $post_num) {
 972:                 
 973:                 $com_poster = $member_handler->getUser($user_id);
 974:                 if (is_object($com_poster)) {
 975:                     $member_handler->updateUserByField($com_poster, 'posts', $com_poster->getVar('posts') - $post_num);
 976:                 }
 977:             }
 978: 
 979:             return true;
 980:         }
 981:     }
 982: 
 983:     return false;
 984: }
 985: 
 986:  987:  988:  989:  990:  991:  992:  993:  994:  995: 
 996: function xoops_groupperm_deletebymoditem($module_id, $perm_name, $item_id = null)
 997: {
 998:     
 999:     if ((int)$module_id <= 1) {
1000:         return false;
1001:     }
1002:     
1003:     $gperm_handler = xoops_getHandler('groupperm');
1004: 
1005:     return $gperm_handler->deleteByModule($module_id, $perm_name, $item_id);
1006: }
1007: 
1008: 1009: 1010: 1011: 1012: 1013: 
1014: function xoops_utf8_encode(&$text)
1015: {
1016:     xoops_load('XoopsLocal');
1017: 
1018:     return XoopsLocal::utf8_encode($text);
1019: }
1020: 
1021: 1022: 1023: 1024: 1025: 1026: 
1027: function xoops_convert_encoding(&$text)
1028: {
1029:     return xoops_utf8_encode($text);
1030: }
1031: 
1032: 1033: 1034: 1035: 1036: 1037: 
1038: function xoops_trim($text)
1039: {
1040:     xoops_load('XoopsLocal');
1041: 
1042:     return XoopsLocal::trim($text);
1043: }
1044: 
1045: 1046: 1047: 
1048: 1049: 1050: 1051: 1052: 1053: 1054: 1055: 
1056: function xoops_getOption($option)
1057: {
1058:     $ret = '';
1059:     if (isset($GLOBALS['xoopsOption'][$option])) {
1060:         $ret = $GLOBALS['xoopsOption'][$option];
1061:     }
1062: 
1063:     return $ret;
1064: }
1065: 
1066: 1067: 1068: 
1069: 1070: 1071: 1072: 1073: 1074: 1075: 1076: 1077: 
1078: function xoops_getConfigOption($option, $type = 'XOOPS_CONF')
1079: {
1080:     static $coreOptions = array();
1081: 
1082:     if (is_array($coreOptions) && array_key_exists($option, $coreOptions)) {
1083:         return $coreOptions[$option];
1084:     }
1085:     $ret            = false;
1086:     
1087:     $config_handler = xoops_getHandler('config');
1088:     $configs        = $config_handler->getConfigsByCat(is_array($type) ? $type : constant($type));
1089:     if ($configs) {
1090:         if (isset($configs[$option])) {
1091:             $ret = $configs[$option];
1092:         }
1093:     }
1094:     $coreOptions[$option] = $ret;
1095: 
1096:     return $ret;
1097: }
1098: 
1099: 1100: 1101: 
1102: 1103: 1104: 1105: 1106: 1107: 1108: 1109: 
1110: function xoops_setConfigOption($option, $new = null)
1111: {
1112:     if (isset($GLOBALS['xoopsConfig'][$option]) && null !== $new) {
1113:         $GLOBALS['xoopsConfig'][$option] = $new;
1114:     }
1115: }
1116: 
1117: 1118: 1119: 
1120: 1121: 1122: 1123: 1124: 1125: 1126: 1127: 1128: 1129: 
1130: function xoops_getModuleOption($option, $dirname = '')
1131: {
1132:     static $modOptions = array();
1133:     if (is_array($modOptions) && isset($modOptions[$dirname][$option])) {
1134:         return $modOptions[$dirname][$option];
1135:     }
1136: 
1137:     $ret            = false;
1138:     
1139:     $module_handler = xoops_getHandler('module');
1140:     $module         = $module_handler->getByDirname($dirname);
1141:     
1142:     $config_handler = xoops_getHandler('config');
1143:     if (is_object($module)) {
1144:         $moduleConfig = $config_handler->getConfigsByCat(0, $module->getVar('mid'));
1145:         if (isset($moduleConfig[$option])) {
1146:             $ret = $moduleConfig[$option];
1147:         }
1148:     }
1149:     $modOptions[$dirname][$option] = $ret;
1150: 
1151:     return $ret;
1152: }
1153: 
1154: 1155: 1156: 1157: 1158: 1159: 1160: 1161: 1162: 1163: 1164: 1165: 
1166: function xoops_getBaseDomain($url)
1167: {
1168:     $parts = parse_url($url);
1169:     $host = '';
1170:     if (!empty($parts['host'])) {
1171:         $host = $parts['host'];
1172:         if (strtolower($host) === 'localhost') {
1173:             return 'localhost';
1174:         }
1175:         
1176:         if (false !== filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
1177:             return '';
1178:         }
1179:         $regdom = new \Geekwright\RegDom\RegisteredDomain();
1180:         $host = $regdom->getRegisteredDomain($host);
1181:     }
1182:     return (null === $host) ? '' : $host;
1183: }
1184: 
1185: 1186: 1187: 
1188: 1189: 1190: 1191: 1192: 1193: 1194: 
1195: function xoops_getUrlDomain($url)
1196: {
1197:     $domain = '';
1198:     $_URL   = parse_url($url);
1199: 
1200:     if (!empty($_URL) || !empty($_URL['host'])) {
1201:         $domain = $_URL['host'];
1202:     }
1203: 
1204:     return $domain;
1205: }
1206: 
1207: include_once __DIR__ . '/functions.encoding.php';
1208: include_once __DIR__ . '/functions.legacy.php';
1209: