XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
functions.php
1<?php
15
16// ################## Various functions from here ################
17
23function xoops_getrequest($name)
24{
25 $root =& XCube_Root::getSingleton();
26 return $root->mContext->mRequest->getRequest($name);
27}
28
33function xoops_header($closehead = true)
34{
35 $root =& XCube_Root::getSingleton();
36 $renderSystem =& $root->getRenderSystem('Legacy_RenderSystem');
37// PHP 8 only - null safe operator
38/* $renderSystem?->showXoopsHeader($closehead); */
39// PHP 74
40 if ($renderSystem !== null) {
41 $renderSystem->showXoopsHeader($closehead);
42 }
43}
44
48function xoops_footer()
49{
50 $root =& XCube_Root::getSingleton();
51 $renderSystem =& $root->getRenderSystem('Legacy_RenderSystem');
52// PHP 8 only - null safe operator
53/* $renderSystem?->showXoopsFooter(); */
54// PHP 74
55 if ($renderSystem !== null) {
56 $renderSystem->showXoopsFooter();
57 }
58}
59
60function xoops_error($message, $title='', $style='errorMsg')
61{
62 $root =& XCube_Root::getSingleton();
63 $renderSystem =& $root->getRenderSystem($root->mContext->mBaseRenderSystemName);
64
65 $renderTarget =& $renderSystem->createRenderTarget('main');
66
67 $renderTarget->setAttribute('legacy_module', 'legacy');
68 $renderTarget->setTemplateName('legacy_xoops_error.html');
69
70 $renderTarget->setAttribute('style', $style);
71 $renderTarget->setAttribute('title', $title);
72 $renderTarget->setAttribute('message', $message);
73
74 $renderSystem->render($renderTarget);
75
76 print $renderTarget->getResult();
77}
78
84function xoops_result($message, $title='')
85{
86 $root =& XCube_Root::getSingleton();
87 $renderSystem =& $root->getRenderSystem($root->mContext->mBaseRenderSystemName);
88
89 $renderTarget =& $renderSystem->createRenderTarget('main');
90
91 $renderTarget->setAttribute('legacy_module', 'legacy');
92 $renderTarget->setTemplateName('legacy_xoops_result.html');
93
94 $renderTarget->setAttribute('title', $title);
95 $renderTarget->setAttribute('message', $message);
96
97 $renderSystem->render($renderTarget);
98
99 print $renderTarget->getResult();
100}
101
102function xoops_confirm($hiddens, $action, $message, $submit = '', $addToken = true)
103{
104 //
105 // Create token.
106 //
107 $tokenHandler = new XoopsMultiTokenHandler();
108 $token =& $tokenHandler->create(XOOPS_TOKEN_DEFAULT);
109
110 //
111 // Register to session. And, set it to own property.
112 //
113 $tokenHandler->register($token);
114
115 $root =& XCube_Root::getSingleton();
116 $renderSystem =& $root->getRenderSystem($root->mContext->mBaseRenderSystemName);
117
118 $renderTarget =& $renderSystem->createRenderTarget('main');
119
120 $renderTarget->setAttribute('legacy_module', 'legacy');
121 $renderTarget->setTemplateName('legacy_xoops_confirm.html');
122
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());
129
130 $renderSystem->render($renderTarget);
131
132 print $renderTarget->getResult();
133}
134
142function xoops_token_confirm($hiddens, $action, $msg, $submit='')
143{
144 return xoops_confirm($hiddens, $action, $msg, $submit, true);
145}
146
147function xoops_confirm_validate()
148{
149 return XoopsMultiTokenHandler::quickValidate(XOOPS_TOKEN_DEFAULT);
150}
151
152function xoops_refcheck($docheck=1)
153{
154 $ref = xoops_getenv('HTTP_REFERER');
155 if ($docheck === 0) {
156 return true;
157 }
158 if ($ref === '') {
159 return false;
160 }
161 // Allow protocol part to be omitted
162 if (substr(XOOPS_URL, 0, 1)==='/') $ref = preg_replace('/^https?:/', '', $ref);
163 //TODO PHP8 'strpos' call can be converted to 'str_starts_with'
164 if (strpos($ref, (string) XOOPS_URL) !== 0) {
165 return false;
166 }
167 return true;
168}
169
170function xoops_getUserTimestamp($time, $timeoffset='')
171{
172 global $xoopsConfig, $xoopsUser;
173 if ($timeoffset === '') {
174 if ($xoopsUser) {
175 static $offset;
176 $timeoffset = $offset ?? $offset = $xoopsUser->getVar('timezone_offset', 'n');
177 } else {
178 $timeoffset = $xoopsConfig['default_TZ'];
179 }
180 }
181
182 return (int)$time + ((int)$timeoffset - $xoopsConfig['server_TZ'])*3600;
183}
184
185/*
186 * Function to display formatted times in user timezone
187 */
188function formatTimestamp($time, $format='l', $timeoffset='')
189{
190 $usertimestamp = xoops_getUserTimestamp($time, $timeoffset);
191 return _formatTimeStamp($usertimestamp, $format);
192}
193
194/*
195 * Function to display formatted times in user timezone
196 */
197function formatTimestampGMT($time, $format='l', $timeoffset='')
198{
199 if ($timeoffset === '') {
200 global $xoopsUser;
201 if ($xoopsUser) {
202 $timeoffset = $xoopsUser->getVar('timezone_offset', 'n');
203 } else {
204 $timeoffset = $GLOBALS['xoopsConfig']['default_TZ'];
205 }
206 }
207
208 $usertimestamp = (int)$time + ((int)$timeoffset)*3600;
209 return _formatTimeStamp($usertimestamp, $format);
210}
211
212function _formatTimeStamp($time, $format='l')
213{
214 switch (strtolower($format)) {
215 case 's':
216 $datestring = _SHORTDATESTRING;
217 break;
218 case 'm':
219 $datestring = _MEDIUMDATESTRING;
220 break;
221 case 'mysql':
222 $datestring = 'Y-m-d H:i:s';
223 break;
224 case 'rss':
225 $datestring = 'r';
226 break;
227 case 'l':
228 $datestring = _DATESTRING;
229 break;
230 default:
231 if ($format !== '') {
232 $datestring = $format;
233 } else {
234 $datestring = _DATESTRING;
235 }
236 break;
237 }
238 return ucfirst(date($datestring, $time));
239}
240
241/*
242 * Function to calculate server timestamp from user entered time (timestamp)
243 */
244function userTimeToServerTime($timestamp, $userTZ=null)
245{
246 global $xoopsConfig;
247 if (!isset($userTZ)) {
248 $userTZ = $xoopsConfig['default_TZ'];
249 }
250 //@gigamaster changed short this : $timestamp = $timestamp - (($userTZ - $xoopsConfig['server_TZ']) * 3600);
251 $timestamp -= (($userTZ - $xoopsConfig['server_TZ']) * 3600);
252 return $timestamp;
253}
254
255function xoops_makepass()
256{
257 $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);
263 } else {
264 $makepass .= sprintf('%s', $syllables[random_int(0, mt_getrandmax()) % 62]);
265 }
266 }
267 return $makepass;
268}
269
270/*
271 * Functions to display dhtml loading image box
272 */
273function OpenWaitBox()
274{
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">
278 <tr>
279 <td align="center"><b>' ._FETCHING.'</b><br><img src="'.XOOPS_URL.'/images/icons/info.svg" width="1em" height="1em" alt=""><br>' ._PLEASEWAIT.'</td>
280 </tr>
281 </table>
282 </div>
283 <script type="text/javascript">
284 <!--//
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];
293 }
294 }
295 function ap_showWaitMessage(div,flag) {
296 if (!DHTML) {
297 return;
298 }
299 var x = ap_getObj(div);
300 x.visibility = (flag) ? "visible" : "hidden";
301 if (!document.getElementById) {
302 if (document.layers) {
303 x.left=280/2;
304 }
305 }
306 return true;
307 }
308 ap_showWaitMessage("waitDiv", 1);
309 //-->
310 </script>';
311}
312
313function CloseWaitBox()
314{
315 echo '<script type="text/javascript">
316 <!--//
317 ap_showWaitMessage("waitDiv", 0);
318 //-->
319 </script>
320 ';
321}
322
323function checkEmail($email, $antispam = false)
324{
325 if (!$email || !preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i', $email)) {
326 return false;
327 }
328 if ($antispam) {
329 $email = str_replace('@', ' at ', $email);
330 $email = str_replace('.', ' dot ', $email);
331 return $email;
332 }
333
334 return true;
335}
336
337function formatURL($url)
338{
339 $url = trim($url);
340 if ($url !== '') {
341 if ((!preg_match('/^http[s]*:\/\//i', $url))
342 && (!preg_match('/^ftp*:\/\//i', $url))
343 /* InterPlanetary File System (IPFS) is a protocol and peer-to-peer network */
344 && (!preg_match('/^ipfs*:\/\//i', $url))
345 && (!preg_match('/^ed2k*:\/\//i', $url))) {
346 $url = 'https://'.$url;
347 }
348 }
349 return $url;
350}
351
352/*
353 * Function to display banners in all pages
354 */
355function showbanner()
356{
357 echo xoops_getbanner();
358}
359
360/*
361 * Function to get the banner html tags for templates
362 */
363function xoops_getbanner()
364{
365 global $xoopsConfig;
366 $db =& Database::getInstance();
367 $bresult = $db->query('SELECT COUNT(*) FROM ' . $db->prefix('banner'));
368 [$numrows] = $db->fetchRow($bresult);
369 if ($numrows > 1) {
370 $numrows = $numrows-1;
371 mt_srand((double)microtime()*1_000_000);
372 /*use rand() unless you need a securely randomized integer,
373 then use random_int() . If you don't know if you need the latter,
374 you probably don't (it impacts "guessability", so imagine where that's useful).
375 If you're trying to randomize a slideshow, for instance, rand() is just fine */
376 $bannum = random_int(0, $numrows);
377 /*
378 try {
379 $bannum = random_int (0, $numrows);
380 } catch (Exception $e) {
381 }
382 */
383 } else {
384 $bannum = 0;
385 }
386 if ($numrows > 0) {
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')) {
390 // EMPTY
391 } else {
392 $db->queryF(sprintf('UPDATE %s SET impmade = impmade+1 WHERE bid = %u', $db->prefix('banner'), $bid));
393 }
394 /* Check if this impression is the last one and print the banner */
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());
398 $db->queryF($sql);
399 // Delete banner finished impressions
400 $db->queryF(sprintf('DELETE FROM %s WHERE bid = %u', $db->prefix('banner'), $bid));
401 }
402 if ($htmlbanner) {
403 $bannerobject = '<div class="banner"><a href="'.XOOPS_URL.'/banners.php?op=click&amp;bid='.$bid.'" rel="noopener">';
404 $bannerobject .= $htmlcode;
405 $bannerobject .= '</a></div>';
406 } else {
407 $bannerobject = '<div class="banner"><a href="'.XOOPS_URL.'/banners.php?op=click&amp;bid='.$bid.'" rel="noopener">';
408 $bannerobject .= '<img src="' . $imageurl . '" alt="banner" loading="lazy">';
409 $bannerobject .= '</a></div>';
410 }
411 return $bannerobject;
412 }
413}
414
415/*
416* Function to redirect user to certain pages
417*/
418function redirect_header($url, $time = 1, $message = '', $addredirect = true)
419{
420 global $xoopsConfig, $xoopsRequestUri;
421 if (preg_match('/[\\0-\\31]/', $url) || preg_match('/^(javascript|vbscript|about):/i', $url)) {
422 $url = XOOPS_URL;
423 }
424 if (!defined('XOOPS_CPFUNC_LOADED')) {
425 require_once XOOPS_ROOT_PATH.'/class/template.php';
426 $xoopsTpl = new XoopsTpl();
427 //TODO PHP8 'strpos' call can be converted to 'str_contains'
428 if ($addredirect && strpos($url, 'user.php') !== false) {
429 if (strpos($url, '?') === false) {
430 $url .= '?xoops_redirect='.urlencode($xoopsRequestUri);
431 } else {
432 $url .= '&amp;xoops_redirect='.urlencode($xoopsRequestUri);
433 }
434 }
435 if (defined('SID') && (! isset($_COOKIE[session_name()]) || ($xoopsConfig['use_mysession'] && '' !== $xoopsConfig['session_name'] && !isset($_COOKIE[$xoopsConfig['session_name']])))) {
436// TODO Goodbye strpos and strstr: str_contains in PHP8
437if (strpos($url, (string) XOOPS_URL) === 0) {
438 //@gigamaster changed this to save memory
439 if (strpos($url, '?') === false) {
440 $connector = '?';
441 } else {
442 $connector = '&amp;';
443 }
444 //@gigamaster changed this to save memory
445 if (strpos($url, '#') !== false) {
446 $urlArray = explode('#', $url);
447 $url = $urlArray[0] . $connector . SID;
448 if (! empty($urlArray[1])) {
449 $url .= '#' . $urlArray[1];
450 }
451 } else {
452 $url .= $connector . SID;
453 }
454 }
455 }
456
457 // RENDER configs
458 $moduleHandler = xoops_gethandler('module');
459 $legacyRender =& $moduleHandler->getByDirname('legacyRender');
460 $configHandler = xoops_gethandler('config');
461 $configs =& $configHandler->getConfigsByCat(0, $legacyRender->get('mid'));
462
463 //@gigamaster added theme_set and theme_url, logotype and favicon
464 $url = preg_replace('/&amp;/i', '&', htmlspecialchars($url, ENT_QUOTES));
465 $message = trim($message) !== '' ? $message : _TAKINGBACK;
466 $xoopsTpl->assign(
467 [
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,
476 'time' =>$time,
477 'url' =>$url,
478 'message' =>$message,
479 'logotype' =>$configs['logotype'],
480 'favicon' =>$configs['favicon'],
481 'lang_ifnotreload' =>sprintf(_IFNOTRELOAD, $url)
482 ]
483 );
484 $GLOBALS['xoopsModuleUpdate'] = 1;
485 $xoopsTpl->display('db:system_redirect.html');
486 exit();
487 }
488 //@gigamaster split workflow
489 $url = preg_replace('/&amp;/i', '&', htmlspecialchars($url, ENT_QUOTES));
490 //File from module templates for ease of customization
491 $file = XOOPS_ROOT_PATH.'/modules/legacy/templates/legacy_redirect_function.html';
492 if (file_exists($file)) {
493 include $file;
494 } else {
495 $message = urlencode("Unable to load redirect template! The form Redirect to the previous page.");
496 // $_SERVER['HTTP_REFERER'], Returns the complete URL of the current page
497 header("Location:".$_SERVER['HTTP_REFERER']."?message=".$message);
498 }
499 exit;
500
501}
502
503function xoops_getenv($key)
504{
505 $ret = null;
506
507 if (isset($_SERVER[$key]) || isset($_ENV[$key])) {
508 $ret = $_SERVER[$key] ?? $_ENV[$key];
509 }
510
511
512 switch ($key) {
513 case 'PHP_SELF':
514 case 'PATH_INFO':
515 case 'PATH_TRANSLATED':
516 if ($ret) $ret = htmlspecialchars($ret, ENT_QUOTES);
517 break;
518 }
519
520 return $ret;
521}
522
523/*
524 * This function is deprecated. Do not use!
525 */
526function getTheme()
527{
528 $root =& XCube_Root::getSingleton();
529 return $root->mContext->getXoopsConfig('theme_set');
530}
531
532/*
533 * Function to get css file for a certain theme
534 * This function will be deprecated.
535 */
536function getcss($theme = '')
537{
538 return xoops_getcss($theme);
539}
540
541/*
542 * Function to get css file for a certain themeset
543 */
544function xoops_getcss($theme = '')
545{
546 if ($theme === '') {
547 $theme = $GLOBALS['xoopsConfig']['theme_set'];
548 }
549 $uagent = xoops_getenv('HTTP_USER_AGENT');
550 //@gigamaster removed MAC.css MSIE.css
551 $str_css = '/style.css';
552
553 if (is_dir($path = XOOPS_THEME_PATH.'/'.$theme)) {
554 if (file_exists($path.$str_css)) {
555 return XOOPS_THEME_URL.'/'.$theme.$str_css;
556 }
557 //@gigamaster split workflows
558 if (file_exists($path.'/style.css')) {
559 return XOOPS_THEME_URL.'/'.$theme.'/style.css';
560 }
561 }
562 return '';
563}
564
565function &getMailer()
566{
567 global $xoopsConfig;
568 $ret = null;
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();
574 return $ret;
575 }
576 }
577 $ret = new XoopsMailer();
578 return $ret;
579}
580
588function &xoops_gethandler($name, $optional = false)
589{
590 static $handlers= [];
591 $name = strtolower(trim($name));
592 if (isset($handlers[$name])) {
593 return $handlers[$name];
594 }
595
596 //
597 // The following delegate was tested with version Alpha4-c.
598 //
599 $handler = null;
600 XCube_DelegateUtils::call('Legacy.Event.GetHandler', new XCube_Ref($handler), $name, $optional);
601 if ($handler) {
602 $var = $handlers[ $name ] =& $handler;
603 return $var;
604 }
605
606 // internal Class handler exist
607 if (XC_CLASS_EXISTS($class = 'Xoops'.ucfirst($name).'Handler')) {
608 $handler = new $class($GLOBALS[ 'xoopsDB' ]);
609 $handlers[ $name ] = $handler;
610 return $handler;
611 }
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;
616 return $handler;
617 }
618
619 if (!$optional) {
620 trigger_error('Class <b>'.$class.'</b> does not exist<br>Handler Name: '.$name, E_USER_ERROR);
621 }
622
623 $falseRet = false;
624 return $falseRet;
625}
626
627function &xoops_getmodulehandler($name = null, $module_dir = null, $optional = false)
628{
629 static $handlers;
630 // if $module_dir is not specified
631 if ($module_dir) {
632 $module_dir = trim($module_dir);
633 } else {
634 //if a module is loaded
635 global $xoopsModule;
636 if ($xoopsModule) {
637 $module_dir = $xoopsModule->getVar('dirname', 'n');
638 } else {
639 trigger_error('No Module is loaded', E_USER_ERROR);
640 }
641 }
642 $name = $name ? trim($name) : $module_dir;
643 $mhdr = &$handlers[$module_dir];
644 if (isset($mhdr[$name])) {
645 return $mhdr[$name];
646 }
647 //
648 // Cube Style load class
649 //
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;
654 }
655
656 $className = ($ucdir = ucfirst(strtolower($module_dir))) . '_' . $ucname . 'Handler';
657 if (XC_CLASS_EXISTS($className)) {
658 $mhdr[$name] = new $className($GLOBALS['xoopsDB']);
659 } else {
660 $className = $ucdir . $ucname . 'Handler';
661 if (XC_CLASS_EXISTS($className)) {
662 $mhdr[$name] = new $className($GLOBALS['xoopsDB']);
663 }
664 }
665
666 if (!isset($mhdr[$name]) && !$optional) {
667 trigger_error('Handler does not exist<br>Module: '.$module_dir.'<br>Name: '.$name, E_USER_ERROR);
668 }
669
670 return $mhdr[$name];
671}
672
673function xoops_getrank($rank_id =0, $posts = 0)
674{
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;
680 } else {
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';
682 }
683 $rank = $db->fetchArray($db->query($sql));
684 $rank['title'] = $myts->makeTboxData4Show($rank['title']);
685
686 return $rank;
687}
688
689
701function xoops_substr($str, $start, $length, $trimmarker = '...')
702{
703 if (!XOOPS_USE_MULTIBYTES) {
704 return (strlen($str) ?? '' - $start <= $length) ? substr($str, $start, $length) : substr($str, $start, $length - strlen($trimmarker)) . $trimmarker;
705 }
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 : '');
709 }
710 // phppp patch
711 $DEP_CHAR=127;
712 $pos_st=0;
713 $action = false;
714 for ($pos_i = 0, $pos_iMax = strlen($str); $pos_i < $pos_iMax; $pos_i++) {
715 //@gigamaster changed to array
716 if (ord($str[$pos_i]) > 127) {
717 $pos_i++;
718 }
719 if ($pos_i<=$start) {
720 $pos_st=$pos_i;
721 }
722 if ($pos_i>=$pos_st+$length) {
723 $action = true;
724 break;
725 }
726 }
727 return ($action) ? substr($str, $pos_st, $pos_i - $pos_st - strlen($trimmarker)) . $trimmarker : $str;
728}
729
730// RMV-NOTIFY
731// ################ Notification Helper Functions ##################
732
733// We want to be able to delete by module, by user, or by item.
734// How do we specify this??
735
736function xoops_notification_deletebymodule($module_id)
737{
738 $notification_handler =& xoops_gethandler('notification');
739 return $notification_handler->unsubscribeByModule($module_id);
740}
741
742function xoops_notification_deletebyuser($user_id)
743{
744 $notification_handler =& xoops_gethandler('notification');
745 return $notification_handler->unsubscribeByUser($user_id);
746}
747
748function xoops_notification_deletebyitem($module_id, $category, $item_id)
749{
750 $notification_handler =& xoops_gethandler('notification');
751 return $notification_handler->unsubscribeByItem($module_id, $category, $item_id);
752}
753
754// ################### Comment helper functions ####################
755
756function xoops_comment_count($module_id, $item_id = null)
757{
758 $comment_handler =& xoops_gethandler('comment');
759 $criteria = new CriteriaCompo(new Criteria('com_modid', (int)$module_id));
760 if (isset($item_id)) {
761 $criteria->add(new Criteria('com_itemid', (int)$item_id));
762 }
763 return $comment_handler->getCount($criteria);
764}
765
766function xoops_comment_delete($module_id, $item_id)
767{
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)) {
772 $deleted_num = [];
773 //@gigamaster changed to foreach
774 foreach ($comments as $i => $iValue) {
775 if ($comment_handler->delete($comments[$i]) !== false) {
776 // store poster ID and deleted post number into array for later use
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);
780 }
781 }
782 }
783 $member_handler =& xoops_gethandler('member');
784 foreach ($deleted_num as $user_id => $post_num) {
785 // update user posts
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);
789 }
790 }
791 return true;
792 }
793 }
794 return false;
795}
796
797// ################ Group Permission Helper Functions ##################
798
799function xoops_groupperm_deletebymoditem($module_id, $perm_name, $item_id = null)
800{
801 // do not allow system permissions to be deleted
802 if ((int)$module_id <= 1) {
803 return false;
804 }
805 $gperm_handler =& xoops_gethandler('groupperm');
806 return $gperm_handler->deleteByModule($module_id, $perm_name, $item_id);
807}
808
809function &xoops_utf8_encode(&$text)
810{
811 $out_text = null;
812 if (XOOPS_USE_MULTIBYTES === 1) {
813 if (function_exists('mb_convert_encoding')) {
814 $out_text = mb_convert_encoding($text, 'UTF-8', 'auto');
815 return $out_text;
816 }
817 return $out_text;
818 }
819 $out_text = utf8_encode($text);
820 return $out_text;
821}
822
823function &xoops_convert_encoding(&$text)
824{
825 return xoops_utf8_encode($text);
826}
827
828function xoops_getLinkedUnameFromId($userid)
829{
830 $userid = (int)$userid;
831 if ($userid > 0) {
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>';
836 return $linkeduser;
837 }
838 }
839 return $GLOBALS['xoopsConfig']['anonymous'];
840}
841
842function xoops_trim($text)
843{
844 if (function_exists('xoops_language_trim')) {
845 return xoops_language_trim($text);
846 }
847 return trim($text);
848}
849
850if (!function_exists('htmlspecialchars_decode')) {
851 function htmlspecialchars_decode($text)
852 {
853 return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
854 }
855}
static quickValidate($name, $clearIfValid=true)
Definition token.php:401