23function xoops_getrequest($name)
25 $root =& XCube_Root::getSingleton();
26 return $root->mContext->mRequest->getRequest($name);
33function xoops_header($closehead =
true)
35 $root =& XCube_Root::getSingleton();
36 $renderSystem =& $root->getRenderSystem(
'Legacy_RenderSystem');
40 if ($renderSystem !==
null) {
41 $renderSystem->showXoopsHeader($closehead);
48function xoops_footer()
50 $root =& XCube_Root::getSingleton();
51 $renderSystem =& $root->getRenderSystem(
'Legacy_RenderSystem');
55 if ($renderSystem !==
null) {
56 $renderSystem->showXoopsFooter();
60function xoops_error($message, $title=
'', $style=
'errorMsg')
62 $root =& XCube_Root::getSingleton();
63 $renderSystem =& $root->getRenderSystem($root->mContext->mBaseRenderSystemName);
65 $renderTarget =& $renderSystem->createRenderTarget(
'main');
67 $renderTarget->setAttribute(
'legacy_module',
'legacy');
68 $renderTarget->setTemplateName(
'legacy_xoops_error.html');
70 $renderTarget->setAttribute(
'style', $style);
71 $renderTarget->setAttribute(
'title', $title);
72 $renderTarget->setAttribute(
'message', $message);
74 $renderSystem->render($renderTarget);
76 print $renderTarget->getResult();
84function xoops_result($message, $title=
'')
86 $root =& XCube_Root::getSingleton();
87 $renderSystem =& $root->getRenderSystem($root->mContext->mBaseRenderSystemName);
89 $renderTarget =& $renderSystem->createRenderTarget(
'main');
91 $renderTarget->setAttribute(
'legacy_module',
'legacy');
92 $renderTarget->setTemplateName(
'legacy_xoops_result.html');
94 $renderTarget->setAttribute(
'title', $title);
95 $renderTarget->setAttribute(
'message', $message);
97 $renderSystem->render($renderTarget);
99 print $renderTarget->getResult();
102function xoops_confirm($hiddens, $action, $message, $submit =
'', $addToken =
true)
108 $token =& $tokenHandler->create(XOOPS_TOKEN_DEFAULT);
113 $tokenHandler->register($token);
115 $root =& XCube_Root::getSingleton();
116 $renderSystem =& $root->getRenderSystem($root->mContext->mBaseRenderSystemName);
118 $renderTarget =& $renderSystem->createRenderTarget(
'main');
120 $renderTarget->setAttribute(
'legacy_module',
'legacy');
121 $renderTarget->setTemplateName(
'legacy_xoops_confirm.html');
123 $renderTarget->setAttribute(
'action', $action);
124 $renderTarget->setAttribute(
'message', $message);
125 $renderTarget->setAttribute(
'hiddens', $hiddens);
126 $renderTarget->setAttribute(
'submit', $submit);
127 $renderTarget->setAttribute(
'tokenName', $token->getTokenName());
128 $renderTarget->setAttribute(
'tokenValue', $token->getTokenValue());
130 $renderSystem->render($renderTarget);
132 print $renderTarget->getResult();
142function xoops_token_confirm($hiddens, $action, $msg, $submit=
'')
144 return xoops_confirm($hiddens, $action, $msg, $submit,
true);
147function xoops_confirm_validate()
152function xoops_refcheck($docheck=1)
154 $ref = xoops_getenv(
'HTTP_REFERER');
155 if ($docheck === 0) {
162 if (substr(XOOPS_URL, 0, 1)===
'/') $ref = preg_replace(
'/^https?:/',
'', $ref);
164 if (strpos($ref, (
string) XOOPS_URL) !== 0) {
170function xoops_getUserTimestamp($time, $timeoffset=
'')
172 global $xoopsConfig, $xoopsUser;
173 if ($timeoffset ===
'') {
176 $timeoffset = $offset ?? $offset = $xoopsUser->getVar(
'timezone_offset',
'n');
178 $timeoffset = $xoopsConfig[
'default_TZ'];
182 return (
int)$time + ((int)$timeoffset - $xoopsConfig[
'server_TZ'])*3600;
188function formatTimestamp($time, $format=
'l', $timeoffset=
'')
190 $usertimestamp = xoops_getUserTimestamp($time, $timeoffset);
191 return _formatTimeStamp($usertimestamp, $format);
197function formatTimestampGMT($time, $format=
'l', $timeoffset=
'')
199 if ($timeoffset ===
'') {
202 $timeoffset = $xoopsUser->getVar(
'timezone_offset',
'n');
204 $timeoffset = $GLOBALS[
'xoopsConfig'][
'default_TZ'];
208 $usertimestamp = (int)$time + ((
int)$timeoffset)*3600;
209 return _formatTimeStamp($usertimestamp, $format);
212function _formatTimeStamp($time, $format=
'l')
214 switch (strtolower($format)) {
216 $datestring = _SHORTDATESTRING;
219 $datestring = _MEDIUMDATESTRING;
222 $datestring =
'Y-m-d H:i:s';
228 $datestring = _DATESTRING;
231 if ($format !==
'') {
232 $datestring = $format;
234 $datestring = _DATESTRING;
238 return ucfirst(date($datestring, $time));
244function userTimeToServerTime($timestamp, $userTZ=
null)
247 if (!isset($userTZ)) {
248 $userTZ = $xoopsConfig[
'default_TZ'];
251 $timestamp -= (($userTZ - $xoopsConfig[
'server_TZ']) * 3600);
255function xoops_makepass()
258 $syllables = [
'er',
'in',
'tia',
'wol',
'fe',
'pre',
'vet',
'jo',
'nes',
'al',
'len',
'son',
'cha',
'ir',
'ler',
'bo',
'ok',
'tio',
'nar',
'sim',
'ple',
'bla',
'ten',
'toe',
'cho',
'co',
'lat',
'spe',
'ak',
'er',
'po',
'co',
'lor',
'pen',
'cil',
'li',
'ght',
'wh',
'at',
'the',
'he',
'ck',
'is',
'mam',
'bo',
'no',
'fi',
've',
'any',
'way',
'pol',
'iti',
'cs',
'ra',
'dio',
'sou',
'rce',
'sea',
'rch',
'pa',
'per',
'com',
'bo',
'sp',
'eak',
'st',
'fi',
'rst',
'gr',
'oup',
'boy',
'ea',
'gle',
'tr',
'ail',
'bi',
'ble',
'brb',
'pri',
'dee',
'kay',
'en',
'be',
'se'];
259 mt_srand((
double)microtime() * 1_000_000);
260 for ($count = 1; $count <= 4; $count++) {
261 if (random_int(0, mt_getrandmax()) % 10 === 1) {
262 $makepass .= sprintf(
'%0.0f', (random_int(0, mt_getrandmax()) % 50) + 1);
264 $makepass .= sprintf(
'%s', $syllables[random_int(0, mt_getrandmax()) % 62]);
273function OpenWaitBox()
275 $GLOBALS[
'xoopsLogger']->addDeprecated(
'Function ' . __FUNCTION__ .
'() is deprecated');
276 echo
'<div id="waitDiv" style="position:absolute;left:40%;top:50%;visibility:hidden;text-align: center;">
277 <table class="table outer">
279 <td align="center"><b>' ._FETCHING.
'</b><br><img src="'.XOOPS_URL.
'/images/icons/info.svg" width="1em" height="1em" alt=""><br>' ._PLEASEWAIT.
'</td>
283 <script type="text/javascript">
285 var DHTML = (document.getElementById || document.all || document.layers);
286 function ap_getObj(name) {
287 if (document.getElementById) {
288 return document.getElementById(name).style;
289 } else if (document.all) {
290 return document.all[name].style;
291 } else if (document.layers) {
292 return document.layers[name];
295 function ap_showWaitMessage(div,flag) {
299 var x = ap_getObj(div);
300 x.visibility = (flag) ? "visible" : "hidden";
301 if (!document.getElementById) {
302 if (document.layers) {
308 ap_showWaitMessage("waitDiv", 1);
313function CloseWaitBox()
315 echo
'<script type="text/javascript">
317 ap_showWaitMessage("waitDiv", 0);
323function checkEmail($email, $antispam =
false)
325 if (!$email || !preg_match(
'/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i', $email)) {
329 $email = str_replace(
'@',
' at ', $email);
330 $email = str_replace(
'.',
' dot ', $email);
337function formatURL($url)
341 if ((!preg_match(
'/^http[s]*:\/\//i', $url))
342 && (!preg_match(
'/^ftp*:\/\//i', $url))
344 && (!preg_match(
'/^ipfs*:\/\//i', $url))
345 && (!preg_match(
'/^ed2k*:\/\//i', $url))) {
346 $url =
'https://'.$url;
357 echo xoops_getbanner();
363function xoops_getbanner()
366 $db =& Database::getInstance();
367 $bresult = $db->query(
'SELECT COUNT(*) FROM ' . $db->prefix(
'banner'));
368 [$numrows] = $db->fetchRow($bresult);
370 $numrows = $numrows-1;
371 mt_srand((
double)microtime()*1_000_000);
376 $bannum = random_int(0, $numrows);
387 $bresult = $db->query(
'SELECT * FROM ' . $db->prefix(
'banner'), 1, $bannum);
388 [$bid, $cid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date, $htmlbanner, $htmlcode] = $db->fetchRow($bresult);
389 if ($xoopsConfig[
'my_ip'] == xoops_getenv(
'REMOTE_ADDR')) {
392 $db->queryF(sprintf(
'UPDATE %s SET impmade = impmade+1 WHERE bid = %u', $db->prefix(
'banner'), $bid));
395 if ($imptotal !== 0 && $imptotal == $impmade) {
396 $newid = $db->genId($db->prefix(
'bannerfinish') .
'_bid_seq');
397 $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());
400 $db->queryF(sprintf(
'DELETE FROM %s WHERE bid = %u', $db->prefix(
'banner'), $bid));
403 $bannerobject =
'<div class="banner"><a href="'.XOOPS_URL.
'/banners.php?op=click&bid='.$bid.
'" rel="noopener">';
404 $bannerobject .= $htmlcode;
405 $bannerobject .=
'</a></div>';
407 $bannerobject =
'<div class="banner"><a href="'.XOOPS_URL.
'/banners.php?op=click&bid='.$bid.
'" rel="noopener">';
408 $bannerobject .=
'<img src="' . $imageurl .
'" alt="banner" loading="lazy">';
409 $bannerobject .=
'</a></div>';
411 return $bannerobject;
418function redirect_header($url, $time = 1, $message =
'', $addredirect =
true)
420 global $xoopsConfig, $xoopsRequestUri;
421 if (preg_match(
'/[\\0-\\31]/', $url) || preg_match(
'/^(javascript|vbscript|about):/i', $url)) {
424 if (!defined(
'XOOPS_CPFUNC_LOADED')) {
425 require_once XOOPS_ROOT_PATH.
'/class/template.php';
428 if ($addredirect && strpos($url,
'user.php') !==
false) {
429 if (strpos($url,
'?') ===
false) {
430 $url .=
'?xoops_redirect='.urlencode($xoopsRequestUri);
432 $url .=
'&xoops_redirect='.urlencode($xoopsRequestUri);
435 if (defined(
'SID') && (! isset($_COOKIE[session_name()]) || ($xoopsConfig[
'use_mysession'] &&
'' !== $xoopsConfig[
'session_name'] && !isset($_COOKIE[$xoopsConfig[
'session_name']])))) {
437if (strpos($url, (
string) XOOPS_URL) === 0) {
439 if (strpos($url,
'?') ===
false) {
442 $connector =
'&';
445 if (strpos($url,
'#') !==
false) {
446 $urlArray = explode(
'#', $url);
447 $url = $urlArray[0] . $connector . SID;
448 if (! empty($urlArray[1])) {
449 $url .=
'#' . $urlArray[1];
452 $url .= $connector . SID;
458 $moduleHandler = xoops_gethandler(
'module');
459 $legacyRender =& $moduleHandler->getByDirname(
'legacyRender');
460 $configHandler = xoops_gethandler(
'config');
461 $configs =& $configHandler->getConfigsByCat(0, $legacyRender->get(
'mid'));
464 $url = preg_replace(
'/&/i',
'&', htmlspecialchars($url, ENT_QUOTES));
465 $message = trim($message) !==
'' ? $message : _TAKINGBACK;
468 'xoops_sitename' =>htmlspecialchars($xoopsConfig[
'sitename'], ENT_QUOTES),
469 'sitename' =>htmlspecialchars($xoopsConfig[
'sitename'], ENT_QUOTES),
470 'xoops_theme' =>htmlspecialchars($xoopsConfig[
'theme_set'], ENT_QUOTES),
471 'xoops_imageurl' =>XOOPS_THEME_URL .
'/' . $xoopsConfig[
'theme_set'] .
'/',
472 'theme_url' =>XOOPS_THEME_URL .
'/' . $xoopsConfig[
'theme_set'],
473 'theme_css' =>XOOPS_THEME_URL .
'/' . $xoopsConfig[
'theme_set'] .
'/style.css',
474 'langcode' =>_LANGCODE,
475 'charset' =>_CHARSET,
478 'message' =>$message,
479 'logotype' =>$configs[
'logotype'],
480 'favicon' =>$configs[
'favicon'],
481 'lang_ifnotreload' =>sprintf(_IFNOTRELOAD, $url)
484 $GLOBALS[
'xoopsModuleUpdate'] = 1;
485 $xoopsTpl->display(
'db:system_redirect.html');
489 $url = preg_replace(
'/&/i',
'&', htmlspecialchars($url, ENT_QUOTES));
491 $file = XOOPS_ROOT_PATH.
'/modules/legacy/templates/legacy_redirect_function.html';
492 if (file_exists($file)) {
495 $message = urlencode(
"Unable to load redirect template! The form Redirect to the previous page.");
497 header(
"Location:".$_SERVER[
'HTTP_REFERER'].
"?message=".$message);
503function xoops_getenv($key)
507 if (isset($_SERVER[$key]) || isset($_ENV[$key])) {
508 $ret = $_SERVER[$key] ?? $_ENV[$key];
515 case 'PATH_TRANSLATED':
516 if ($ret) $ret = htmlspecialchars($ret, ENT_QUOTES);
528 $root =& XCube_Root::getSingleton();
529 return $root->mContext->getXoopsConfig(
'theme_set');
536function getcss($theme =
'')
538 return xoops_getcss($theme);
544function xoops_getcss($theme =
'')
547 $theme = $GLOBALS[
'xoopsConfig'][
'theme_set'];
549 $uagent = xoops_getenv(
'HTTP_USER_AGENT');
551 $str_css =
'/style.css';
553 if (is_dir($path = XOOPS_THEME_PATH.
'/'.$theme)) {
554 if (file_exists($path.$str_css)) {
555 return XOOPS_THEME_URL.
'/'.$theme.$str_css;
558 if (file_exists($path.
'/style.css')) {
559 return XOOPS_THEME_URL.
'/'.$theme.
'/style.css';
569 require_once XOOPS_ROOT_PATH.
'/class/xoopsmailer.php';
570 if (file_exists(XOOPS_ROOT_PATH.
'/language/'.$xoopsConfig[
'language'].
'/xoopsmailerlocal.php')) {
571 require_once XOOPS_ROOT_PATH.
'/language/'.$xoopsConfig[
'language'].
'/xoopsmailerlocal.php';
572 if (XC_CLASS_EXISTS(
'XoopsMailerLocal')) {
573 $ret =
new XoopsMailerLocal();
577 $ret =
new XoopsMailer();
588function &xoops_gethandler($name, $optional =
false)
590 static $handlers= [];
591 $name = strtolower(trim($name));
592 if (isset($handlers[$name])) {
593 return $handlers[$name];
600 XCube_DelegateUtils::call(
'Legacy.Event.GetHandler',
new XCube_Ref($handler), $name, $optional);
602 $var = $handlers[ $name ] =& $handler;
607 if (XC_CLASS_EXISTS($class =
'Xoops'.ucfirst($name).
'Handler')) {
608 $handler =
new $class($GLOBALS[
'xoopsDB' ]);
609 $handlers[ $name ] = $handler;
612 include_once XOOPS_ROOT_PATH.
'/kernel/'.$name.
'.php';
613 if (XC_CLASS_EXISTS($class)) {
614 $handler =
new $class($GLOBALS[
'xoopsDB' ]);
615 $handlers[ $name ] = $handler;
620 trigger_error(
'Class <b>'.$class.
'</b> does not exist<br>Handler Name: '.$name, E_USER_ERROR);
627function &xoops_getmodulehandler($name =
null, $module_dir =
null, $optional =
false)
632 $module_dir = trim($module_dir);
637 $module_dir = $xoopsModule->getVar(
'dirname',
'n');
639 trigger_error(
'No Module is loaded', E_USER_ERROR);
642 $name = $name ? trim($name) : $module_dir;
643 $mhdr = &$handlers[$module_dir];
644 if (isset($mhdr[$name])) {
650 if (file_exists($hnd_file = XOOPS_ROOT_PATH .
'/modules/'.$module_dir.
'/class/handler/' . ($ucname = ucfirst($name)) .
'.class.php')) {
651 include_once $hnd_file;
652 } elseif (file_exists($hnd_file = XOOPS_ROOT_PATH .
'/modules/'.$module_dir.
'/class/'.$name.
'.php')) {
653 include_once $hnd_file;
656 $className = ($ucdir = ucfirst(strtolower($module_dir))) .
'_' . $ucname .
'Handler';
657 if (XC_CLASS_EXISTS($className)) {
658 $mhdr[$name] =
new $className($GLOBALS[
'xoopsDB']);
660 $className = $ucdir . $ucname .
'Handler';
661 if (XC_CLASS_EXISTS($className)) {
662 $mhdr[$name] =
new $className($GLOBALS[
'xoopsDB']);
666 if (!isset($mhdr[$name]) && !$optional) {
667 trigger_error(
'Handler does not exist<br>Module: '.$module_dir.
'<br>Name: '.$name, E_USER_ERROR);
673function xoops_getrank($rank_id =0, $posts = 0)
675 $db =& Database::getInstance();
677 $rank_id = (int)$rank_id;
678 if ($rank_id !== 0) {
679 $sql =
'SELECT rank_title AS title, rank_image AS image, rank_id AS id FROM '.$db->prefix(
'ranks').
' WHERE rank_id = '.$rank_id;
681 $sql =
'SELECT rank_title AS title, rank_image AS image, rank_id AS id FROM '.$db->prefix(
'ranks').
' WHERE rank_min <= '.$posts.
' AND rank_max >= '.$posts.
' AND rank_special = 0';
683 $rank = $db->fetchArray($db->query($sql));
684 $rank[
'title'] = $myts->makeTboxData4Show($rank[
'title']);
701function xoops_substr($str, $start, $length, $trimmarker =
'...')
703 if (!XOOPS_USE_MULTIBYTES) {
704 return (strlen($str) ??
'' - $start <= $length) ? substr($str, $start, $length) : substr($str, $start, $length - strlen($trimmarker)) . $trimmarker;
706 if (function_exists(
'mb_internal_encoding') && @mb_internal_encoding(_CHARSET)) {
707 $str2 = mb_strcut($str, $start, $length - strlen($trimmarker));
708 return $str2 . (mb_strlen($str)!==mb_strlen($str2) ? $trimmarker :
'');
714 for ($pos_i = 0, $pos_iMax = strlen($str); $pos_i < $pos_iMax; $pos_i++) {
716 if (ord($str[$pos_i]) > 127) {
719 if ($pos_i<=$start) {
722 if ($pos_i>=$pos_st+$length) {
727 return ($action) ? substr($str, $pos_st, $pos_i - $pos_st - strlen($trimmarker)) . $trimmarker : $str;
736function xoops_notification_deletebymodule($module_id)
738 $notification_handler =& xoops_gethandler(
'notification');
739 return $notification_handler->unsubscribeByModule($module_id);
742function xoops_notification_deletebyuser($user_id)
744 $notification_handler =& xoops_gethandler(
'notification');
745 return $notification_handler->unsubscribeByUser($user_id);
748function xoops_notification_deletebyitem($module_id, $category, $item_id)
750 $notification_handler =& xoops_gethandler(
'notification');
751 return $notification_handler->unsubscribeByItem($module_id, $category, $item_id);
756function xoops_comment_count($module_id, $item_id =
null)
758 $comment_handler =& xoops_gethandler(
'comment');
760 if (isset($item_id)) {
761 $criteria->add(
new Criteria(
'com_itemid', (
int)$item_id));
763 return $comment_handler->getCount($criteria);
766function xoops_comment_delete($module_id, $item_id)
768 if ((
int)$module_id > 0 && (
int)$item_id > 0) {
769 $comment_handler =& xoops_gethandler(
'comment');
770 $comments =& $comment_handler->getByItemId($module_id, $item_id);
771 if (is_array($comments)) {
774 foreach ($comments as $i => $iValue) {
775 if ($comment_handler->delete($comments[$i]) !==
false) {
777 $poster_id = $iValue->getVar(
'com_uid',
'n');
778 if ($poster_id !== 0) {
779 $deleted_num[$poster_id] = !isset($deleted_num[$poster_id]) ? 1 : ($deleted_num[$poster_id] + 1);
783 $member_handler =& xoops_gethandler(
'member');
784 foreach ($deleted_num as $user_id => $post_num) {
786 $com_poster = $member_handler->getUser($user_id);
787 if (is_object($com_poster)) {
788 $member_handler->updateUserByField($com_poster,
'posts', $com_poster->getVar(
'posts',
'n') - $post_num);
799function xoops_groupperm_deletebymoditem($module_id, $perm_name, $item_id =
null)
802 if ((
int)$module_id <= 1) {
805 $gperm_handler =& xoops_gethandler(
'groupperm');
806 return $gperm_handler->deleteByModule($module_id, $perm_name, $item_id);
809function &xoops_utf8_encode(&$text)
812 if (XOOPS_USE_MULTIBYTES === 1) {
813 if (function_exists(
'mb_convert_encoding')) {
814 $out_text = mb_convert_encoding($text,
'UTF-8',
'auto');
819 $out_text = utf8_encode($text);
823function &xoops_convert_encoding(&$text)
825 return xoops_utf8_encode($text);
828function xoops_getLinkedUnameFromId($userid)
830 $userid = (int)$userid;
832 $member_handler =& xoops_gethandler(
'member');
833 $user =& $member_handler->getUser($userid);
834 if (is_object($user)) {
835 $linkeduser =
'<a href="'.XOOPS_URL.
'/userinfo.php?uid='.$userid.
'">'. $user->getVar(
'uname').
'</a>';
839 return $GLOBALS[
'xoopsConfig'][
'anonymous'];
842function xoops_trim($text)
844 if (function_exists(
'xoops_language_trim')) {
845 return xoops_language_trim($text);
850if (!function_exists(
'htmlspecialchars_decode')) {
851 function htmlspecialchars_decode($text)
853 return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
static quickValidate($name, $clearIfValid=true)