1: <?php
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30: 31: 32:
33: function xoops_getrequest($name)
34: {
35: $root =& XCube_Root::getSingleton();
36: return $root->mContext->mRequest->getRequest($name);
37: }
38:
39: 40: 41:
42: function xoops_header($closehead = true)
43: {
44: $root =& XCube_Root::getSingleton();
45: $renderSystem =& $root->getRenderSystem('Legacy_RenderSystem');
46: if ($renderSystem != null) {
47: $renderSystem->showXoopsHeader($closehead);
48: }
49: }
50:
51: 52: 53:
54: function xoops_footer()
55: {
56: $root =& XCube_Root::getSingleton();
57: $renderSystem =& $root->getRenderSystem('Legacy_RenderSystem');
58: if ($renderSystem != null) {
59: $renderSystem->showXoopsFooter();
60: }
61: }
62:
63: function xoops_error($message, $title='', $style='errorMsg')
64: {
65: $root =& XCube_Root::getSingleton();
66: $renderSystem =& $root->getRenderSystem($root->mContext->mBaseRenderSystemName);
67:
68: $renderTarget =& $renderSystem->createRenderTarget('main');
69:
70: $renderTarget->setAttribute('legacy_module', 'legacy');
71: $renderTarget->setTemplateName('legacy_xoops_error.html');
72:
73: $renderTarget->setAttribute('style', $style);
74: $renderTarget->setAttribute('title', $title);
75: $renderTarget->setAttribute('message', $message);
76:
77: $renderSystem->render($renderTarget);
78:
79: print $renderTarget->getResult();
80: }
81:
82: 83: 84:
85: function xoops_result($message, $title='')
86: {
87: $root =& XCube_Root::getSingleton();
88: $renderSystem =& $root->getRenderSystem($root->mContext->mBaseRenderSystemName);
89:
90: $renderTarget =& $renderSystem->createRenderTarget('main');
91:
92: $renderTarget->setAttribute('legacy_module', 'legacy');
93: $renderTarget->setTemplateName('legacy_xoops_result.html');
94:
95: $renderTarget->setAttribute('title', $title);
96: $renderTarget->setAttribute('message', $message);
97:
98: $renderSystem->render($renderTarget);
99:
100: print $renderTarget->getResult();
101: }
102:
103: function xoops_confirm($hiddens, $action, $message, $submit = '', $addToken = true)
104: {
105:
106:
107:
108: $tokenHandler = new XoopsMultiTokenHandler();
109: $token =& $tokenHandler->create(XOOPS_TOKEN_DEFAULT);
110:
111:
112:
113:
114: $tokenHandler->register($token);
115:
116: $root =& XCube_Root::getSingleton();
117: $renderSystem =& $root->getRenderSystem($root->mContext->mBaseRenderSystemName);
118:
119: $renderTarget =& $renderSystem->createRenderTarget('main');
120:
121: $renderTarget->setAttribute('legacy_module', 'legacy');
122: $renderTarget->setTemplateName('legacy_xoops_confirm.html');
123:
124: $renderTarget->setAttribute('action', $action);
125: $renderTarget->setAttribute('message', $message);
126: $renderTarget->setAttribute('hiddens', $hiddens);
127: $renderTarget->setAttribute('submit', $submit);
128: $renderTarget->setAttribute('tokenName', $token->getTokenName());
129: $renderTarget->setAttribute('tokenValue', $token->getTokenValue());
130:
131: $renderSystem->render($renderTarget);
132:
133: print $renderTarget->getResult();
134: }
135:
136: 137: 138:
139: function xoops_token_confirm($hiddens, $action, $msg, $submit='')
140: {
141: return xoops_confirm($hiddens, $action, $msg, $submit, true);
142: }
143:
144: function xoops_confirm_validate()
145: {
146: return XoopsMultiTokenHandler::quickValidate(XOOPS_TOKEN_DEFAULT);
147: }
148:
149: function xoops_refcheck($docheck=1)
150: {
151: $ref = xoops_getenv('HTTP_REFERER');
152: if ($docheck == 0) {
153: return true;
154: }
155: if ($ref == '') {
156: return false;
157: }
158: if (strpos($ref, XOOPS_URL) !== 0 ) {
159: return false;
160: }
161: return true;
162: }
163:
164: function xoops_getUserTimestamp($time, $timeoffset='')
165: {
166: global $xoopsConfig, $xoopsUser;
167: if ($timeoffset === '') {
168: if ($xoopsUser) {
169: static $offset;
170: $timeoffset = isset($offset)?$offset:$offset = $xoopsUser->getVar('timezone_offset', 'n');
171: } else {
172: $timeoffset = $xoopsConfig['default_TZ'];
173: }
174: }
175:
176: return (int)$time + ((int)$timeoffset - $xoopsConfig['server_TZ'])*3600;
177: }
178:
179: 180: 181:
182: function formatTimestamp($time, $format='l', $timeoffset='')
183: {
184: $usertimestamp = xoops_getUserTimestamp($time, $timeoffset);
185: return _formatTimeStamp($usertimestamp, $format);
186: }
187:
188: 189: 190:
191: function formatTimestampGMT($time, $format='l', $timeoffset='')
192: {
193: if ($timeoffset === '') {
194: global $xoopsUser;
195: if ($xoopsUser) {
196: $timeoffset = $xoopsUser->getVar('timezone_offset', 'n');
197: } else {
198: $timeoffset = $GLOBALS['xoopsConfig']['default_TZ'];
199: }
200: }
201:
202: $usertimestamp = (int)$time + ((int)$timeoffset)*3600;
203: return _formatTimeStamp($usertimestamp, $format);
204: }
205:
206: function _formatTimeStamp($time, $format='l')
207: {
208: switch (strtolower($format)) {
209: case 's':
210: $datestring = _SHORTDATESTRING;
211: break;
212: case 'm':
213: $datestring = _MEDIUMDATESTRING;
214: break;
215: case 'mysql':
216: $datestring = 'Y-m-d H:i:s';
217: break;
218: case 'rss':
219: $datestring = 'r';
220: break;
221: case 'l':
222: $datestring = _DATESTRING;
223: break;
224: default:
225: if ($format != '') {
226: $datestring = $format;
227: } else {
228: $datestring = _DATESTRING;
229: }
230: break;
231: }
232: return ucfirst(date($datestring, $time));
233: }
234:
235: 236: 237:
238: function userTimeToServerTime($timestamp, $userTZ=null)
239: {
240: global $xoopsConfig;
241: if (!isset($userTZ)) {
242: $userTZ = $xoopsConfig['default_TZ'];
243: }
244: $timestamp = $timestamp - (($userTZ - $xoopsConfig['server_TZ']) * 3600);
245: return $timestamp;
246: }
247:
248: function xoops_makepass() {
249: $makepass = '';
250: $syllables = array('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');
251: srand((double)microtime()*1000000);
252: for ($count = 1; $count <= 4; $count++) {
253: if (rand()%10 == 1) {
254: $makepass .= sprintf('%0.0f',(rand()%50)+1);
255: } else {
256: $makepass .= sprintf('%s',$syllables[rand()%62]);
257: }
258: }
259: return $makepass;
260: }
261:
262: 263: 264:
265: function OpenWaitBox()
266: {
267: echo '<div id="waitDiv" style="position:absolute;left:40%;top:50%;visibility:hidden;text-align: center;">
268: <table cellpadding="6" border="2" class="bg2">
269: <tr>
270: <td align="center"><b><big>' ._FETCHING.'</big></b><br /><img src="'.XOOPS_URL.'/images/await.gif" alt="" /><br />' ._PLEASEWAIT.'</td>
271: </tr>
272: </table>
273: </div>
274: <script type="text/javascript">
275: <!--//
276: var DHTML = (document.getElementById || document.all || document.layers);
277: function ap_getObj(name) {
278: if (document.getElementById) {
279: return document.getElementById(name).style;
280: } else if (document.all) {
281: return document.all[name].style;
282: } else if (document.layers) {
283: return document.layers[name];
284: }
285: }
286: function ap_showWaitMessage(div,flag) {
287: if (!DHTML) {
288: return;
289: }
290: var x = ap_getObj(div);
291: x.visibility = (flag) ? "visible" : "hidden";
292: if (!document.getElementById) {
293: if (document.layers) {
294: x.left=280/2;
295: }
296: }
297: return true;
298: }
299: ap_showWaitMessage("waitDiv", 1);
300: //-->
301: </script>';
302: }
303:
304: function CloseWaitBox()
305: {
306: echo '<script type="text/javascript">
307: <!--//
308: ap_showWaitMessage("waitDiv", 0);
309: //-->
310: </script>
311: ';
312: }
313:
314: function checkEmail($email,$antispam = false)
315: {
316: if (!$email || !preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i',$email)){
317: return false;
318: }
319: if ($antispam) {
320: $email = str_replace('@', ' at ', $email);
321: $email = str_replace('.', ' dot ', $email);
322: return $email;
323: } else {
324: return true;
325: }
326: }
327:
328: function formatURL($url)
329: {
330: $url = trim($url);
331: if ($url != '') {
332: if ((!preg_match('/^http[s]*:\/\//i', $url)) && (!preg_match('/^ftp*:\/\//i', $url)) && (!preg_match('/^ed2k*:\/\//i', $url)) ) {
333: $url = 'http://'.$url;
334: }
335: }
336: return $url;
337: }
338:
339: 340: 341:
342: function showbanner()
343: {
344: echo xoops_getbanner();
345: }
346:
347: 348: 349:
350: function xoops_getbanner()
351: {
352: global $xoopsConfig;
353: $db =& Database::getInstance();
354: $bresult = $db->query("SELECT COUNT(*) FROM ".$db->prefix("banner"));
355: list ($numrows) = $db->fetchRow($bresult);
356: if ( $numrows > 1 ) {
357: $numrows = $numrows-1;
358: mt_srand((double)microtime()*1000000);
359: $bannum = mt_rand(0, $numrows);
360: } else {
361: $bannum = 0;
362: }
363: if ( $numrows > 0 ) {
364: $bresult = $db->query("SELECT * FROM ".$db->prefix("banner"), 1, $bannum);
365: list ($bid, $cid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date, $htmlbanner, $htmlcode) = $db->fetchRow($bresult);
366: if ($xoopsConfig['my_ip'] == xoops_getenv('REMOTE_ADDR')) {
367:
368: } else {
369: $db->queryF(sprintf("UPDATE %s SET impmade = impmade+1 WHERE bid = %u", $db->prefix("banner"), $bid));
370: }
371:
372: if ( $imptotal != 0 && $imptotal == $impmade ) {
373: $newid = $db->genId($db->prefix("bannerfinish")."_bid_seq");
374: $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());
375: $db->queryF($sql);
376: $db->queryF(sprintf("DELETE FROM %s WHERE bid = %u", $db->prefix("banner"), $bid));
377: }
378: if ($htmlbanner){
379: $bannerobject = $htmlcode;
380: }else{
381: $bannerobject = '<div><a href="'.XOOPS_URL.'/banners.php?op=click&bid='.$bid.'" rel="external">';
382: if (stristr($imageurl, '.swf')) {
383: $bannerobject = $bannerobject
384: .'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="468" height="60">'
385: .'<param name="movie" value="'.$imageurl.'"></param>'
386: .'<param name="quality" value="high"></param>'
387: .'<embed src="'.$imageurl.'" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"; type="application/x-shockwave-flash" width="468" height="60">'
388: .'</embed>'
389: .'</object>';
390: } else {
391: $bannerobject = $bannerobject.'<img src="'.$imageurl.'" alt="" />';
392: }
393:
394: $bannerobject = $bannerobject.'</a></div>';
395: }
396: return $bannerobject;
397: }
398: }
399:
400: 401: 402:
403: function redirect_header($url, $time = 3, $message = '', $addredirect = true)
404: {
405: global $xoopsConfig, $xoopsRequestUri;
406: if (preg_match('/[\\0-\\31]/', $url) || preg_match('/^(javascript|vbscript|about):/i', $url)) {
407: $url = XOOPS_URL;
408: }
409: if (!defined('XOOPS_CPFUNC_LOADED')) {
410: require_once XOOPS_ROOT_PATH.'/class/template.php';
411: $xoopsTpl = new XoopsTpl();
412: $xoopsTpl->assign('xoops_sitename', htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES));
413: $xoopsTpl->assign('sitename', htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES));
414: $xoopsTpl->assign('langcode', _LANGCODE);
415: $xoopsTpl->assign('charset', _CHARSET);
416: $xoopsTpl->assign('time', $time);
417: if ($addredirect && strstr($url, 'user.php')) {
418: if (!strstr($url, '?')) {
419: $url .= '?xoops_redirect='.urlencode($xoopsRequestUri);
420: } else {
421: $url .= '&xoops_redirect='.urlencode($xoopsRequestUri);
422: }
423: }
424: if (defined('SID') && (! isset($_COOKIE[session_name()]) || ($xoopsConfig['use_mysession'] && $xoopsConfig['session_name'] != '' && !isset($_COOKIE[$xoopsConfig['session_name']])))) {
425: if ( strpos($url, XOOPS_URL) === 0 ) {
426: if (!strstr($url, '?')) {
427: $connector = '?';
428: }
429: else {
430: $connector = '&';
431: }
432: if (strstr($url, '#')) {
433: $urlArray = explode( '#', $url );
434: $url = $urlArray[0] . $connector . SID;
435: if ( ! empty($urlArray[1]) ) {
436: $url .= '#' . $urlArray[1];
437: }
438: }
439: else {
440: $url .= $connector . SID;
441: }
442: }
443: }
444: $url = preg_replace("/&/i", '&', htmlspecialchars($url, ENT_QUOTES));
445: $xoopsTpl->assign('url', $url);
446: $message = trim($message) != '' ? $message : _TAKINGBACK;
447: $xoopsTpl->assign('message', $message);
448: $xoopsTpl->assign('lang_ifnotreload', sprintf(_IFNOTRELOAD, $url));
449: $GLOBALS['xoopsModuleUpdate'] = 1;
450: $xoopsTpl->display('db:system_redirect.html');
451: exit();
452: } else {
453: $url = preg_replace("/&/i", '&', htmlspecialchars($url, ENT_QUOTES));
454: echo '
455: <html>
456: <head>
457: <title>'.htmlspecialchars($xoopsConfig['sitename']).'</title>
458: <meta http-equiv="Content-Type" content="text/html; charset='._CHARSET.'" />
459: <meta http-equiv="Refresh" content="'.$time.'; url='.$url.'" />
460: <style type="text/css">
461: body {background-color : #fcfcfc; font-size: 12px; font-family: Trebuchet MS,Verdana, Arial, Helvetica, sans-serif; margin: 0px;}
462: .redirect {width: 70%; margin: 110px; text-align: center; padding: 15px; border: #e0e0e0 1px solid; color: #666666; background-color: #f6f6f6;}
463: .redirect a:link {color: #666666; text-decoration: none; font-weight: bold;}
464: .redirect a:visited {color: #666666; text-decoration: none; font-weight: bold;}
465: .redirect a:hover {color: #999999; text-decoration: underline; font-weight: bold;}
466: </style>
467: </head>
468: <body>
469: <div align="center">
470: <div class="redirect">
471: <span style="font-size: 16px; font-weight: bold;">'.$message.'</span>
472: <hr style="height: 3px; border: 3px #E18A00 solid; width: 95%;" />
473: <p>'.sprintf(_IFNOTRELOAD, $url).'</p>
474: </div>
475: </div>
476: </body>
477: </html>';
478: }
479: exit();
480: }
481:
482: function xoops_getenv($key)
483: {
484: $ret = null;
485:
486:
487:
488:
489: if (isset($_SERVER[$key]) || isset($_ENV[$key])) {
490: $ret = isset($_SERVER[$key]) ? $_SERVER[$key] : $_ENV[$key];
491: }
492:
493:
494: switch($key) {
495: case 'PHP_SELF':
496: case 'PATH_INFO':
497: case 'PATH_TRANSLATED':
498: $ret = htmlspecialchars($ret,ENT_QUOTES);
499: break;
500: }
501:
502: return $ret;
503: }
504:
505: 506: 507:
508: function getTheme()
509: {
510: $root =& XCube_Root::getSingleton();
511: return $root->mContext->getXoopsConfig('theme_set');
512: }
513:
514: 515: 516: 517:
518: function getcss($theme = '')
519: {
520: return xoops_getcss($theme);
521: }
522:
523: 524: 525:
526: function xoops_getcss($theme = '')
527: {
528: if ($theme == '') {
529: $theme = $GLOBALS['xoopsConfig']['theme_set'];
530: }
531: $uagent = xoops_getenv('HTTP_USER_AGENT');
532: if (stristr($uagent, 'mac')) {
533: $str_css = '/styleMAC.css';
534: } elseif (preg_match('/MSIE ([0-9]\.[0-9]{1,2})/i', $uagent)) {
535: $str_css = '/style.css';
536: } else {
537: $str_css = '/styleNN.css';
538: }
539: if (is_dir($path = XOOPS_THEME_PATH.'/'.$theme)) {
540: if (file_exists($path.$str_css)) {
541: return XOOPS_THEME_URL.'/'.$theme.$str_css;
542: } elseif (file_exists($path.'/style.css')) {
543: return XOOPS_THEME_URL.'/'.$theme.'/style.css';
544: }
545: }
546: return '';
547: }
548:
549: function &getMailer()
550: {
551: global $xoopsConfig;
552: $ret = null;
553: require_once XOOPS_ROOT_PATH.'/class/xoopsmailer.php';
554: if ( file_exists(XOOPS_ROOT_PATH.'/language/'.$xoopsConfig['language'].'/xoopsmailerlocal.php') ) {
555: require_once XOOPS_ROOT_PATH.'/language/'.$xoopsConfig['language'].'/xoopsmailerlocal.php';
556: if ( XC_CLASS_EXISTS('XoopsMailerLocal') ) {
557: $ret = new XoopsMailerLocal();
558: return $ret;
559: }
560: }
561: $ret = new XoopsMailer();
562: return $ret;
563: }
564:
565: 566: 567: 568:
569: function &xoops_gethandler($name, $optional = false )
570: {
571: static $handlers=array();
572: $name = strtolower(trim($name));
573: if (isset($handlers[$name])) return $handlers[$name];
574:
575:
576:
577:
578: $handler = null;
579: XCube_DelegateUtils::call('Legacy.Event.GetHandler', new XCube_Ref($handler), $name, $optional);
580: if ($handler) return $handlers[$name] =& $handler;
581:
582: require_once XOOPS_ROOT_PATH.'/kernel/'.$name.'.php';
583: if (XC_CLASS_EXISTS($class = 'Xoops'.ucfirst($name).'Handler')) {
584: $handlers[$name] = $handler = new $class($GLOBALS['xoopsDB']);
585: return $handler;
586: }
587:
588: if (!$optional) {
589: trigger_error('Class <b>'.$class.'</b> does not exist<br />Handler Name: '.$name, E_USER_ERROR);
590: }
591:
592: $falseRet = false;
593: return $falseRet;
594: }
595:
596: function &xoops_getmodulehandler($name = null, $module_dir = null, $optional = false)
597: {
598: static $handlers;
599:
600: if ($module_dir) {
601: $module_dir = trim($module_dir);
602: } else {
603:
604: global $xoopsModule;
605: if ($xoopsModule) {
606: $module_dir = $xoopsModule->getVar('dirname', 'n');
607: } else {
608: trigger_error('No Module is loaded', E_USER_ERROR);
609: }
610: }
611: $name = $name ? trim($name) : $module_dir;
612: $mhdr = &$handlers[$module_dir];
613: if (isset($mhdr[$name])) return $mhdr[$name];
614:
615:
616:
617:
618: if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/modules/'.$module_dir.'/class/handler/' . ($ucname = ucfirst($name)) . '.class.php')) {
619: include_once $hnd_file;
620: }
621: elseif ( file_exists( $hnd_file = XOOPS_ROOT_PATH . '/modules/'.$module_dir.'/class/'.$name.'.php' ) ) {
622: include_once $hnd_file;
623: }
624:
625: $className = ($ucdir = ucfirst(strtolower($module_dir))) . '_' . $ucname . 'Handler';
626: if (XC_CLASS_EXISTS($className)) {
627: $mhdr[$name] = new $className($GLOBALS['xoopsDB']);
628: }
629: else {
630: $className = $ucdir . $ucname . 'Handler';
631: if (XC_CLASS_EXISTS($className)) {
632: $mhdr[$name] = new $className($GLOBALS['xoopsDB']);
633: }
634: }
635:
636: if (!isset($mhdr[$name]) && !$optional) {
637: trigger_error('Handler does not exist<br />Module: '.$module_dir.'<br />Name: '.$name, E_USER_ERROR);
638: }
639:
640: return $mhdr[$name];
641: }
642:
643: function xoops_getrank($rank_id =0, $posts = 0)
644: {
645: $db =& Database::getInstance();
646: $myts =& MyTextSanitizer::getInstance();
647: $rank_id = (int)$rank_id;
648: if ($rank_id != 0) {
649: $sql = 'SELECT rank_title AS title, rank_image AS image, rank_id AS id FROM '.$db->prefix('ranks').' WHERE rank_id = '.$rank_id;
650: } else {
651: $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';
652: }
653: $rank = $db->fetchArray($db->query($sql));
654: $rank['title'] = $myts->makeTboxData4Show($rank['title']);
655:
656: return $rank;
657: }
658:
659:
660: 661: 662: 663: 664: 665: 666: 667: 668: 669:
670: function xoops_substr($str, $start, $length, $trimmarker = '...')
671: {
672: if ( !XOOPS_USE_MULTIBYTES ) {
673: return ( strlen($str) - $start <= $length ) ? substr( $str, $start, $length ) : substr( $str, $start, $length - strlen($trimmarker) ) . $trimmarker;
674: }
675: if (function_exists('mb_internal_encoding') && @mb_internal_encoding(_CHARSET)) {
676: $str2 = mb_strcut( $str , $start , $length - strlen( $trimmarker ) );
677: return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : '' );
678: }
679:
680: $DEP_CHAR=127;
681: $pos_st=0;
682: $action = false;
683: for ( $pos_i = 0; $pos_i < strlen($str); $pos_i++ ) {
684: if ( ord( substr( $str, $pos_i, 1) ) > 127 ) {
685: $pos_i++;
686: }
687: if ($pos_i<=$start) {
688: $pos_st=$pos_i;
689: }
690: if ($pos_i>=$pos_st+$length) {
691: $action = true;
692: break;
693: }
694: }
695: return ($action) ? substr( $str, $pos_st, $pos_i - $pos_st - strlen($trimmarker) ) . $trimmarker : $str;
696: }
697:
698:
699:
700:
701:
702:
703:
704: function xoops_notification_deletebymodule ($module_id)
705: {
706: $notification_handler =& xoops_gethandler('notification');
707: return $notification_handler->unsubscribeByModule ($module_id);
708: }
709:
710: function xoops_notification_deletebyuser ($user_id)
711: {
712: $notification_handler =& xoops_gethandler('notification');
713: return $notification_handler->unsubscribeByUser ($user_id);
714: }
715:
716: function xoops_notification_deletebyitem ($module_id, $category, $item_id)
717: {
718: $notification_handler =& xoops_gethandler('notification');
719: return $notification_handler->unsubscribeByItem ($module_id, $category, $item_id);
720: }
721:
722:
723:
724: function xoops_comment_count($module_id, $item_id = null)
725: {
726: $comment_handler =& xoops_gethandler('comment');
727: $criteria = new CriteriaCompo(new Criteria('com_modid', (int)$module_id));
728: if (isset($item_id)) {
729: $criteria->add(new Criteria('com_itemid', (int)$item_id));
730: }
731: return $comment_handler->getCount($criteria);
732: }
733:
734: function xoops_comment_delete($module_id, $item_id)
735: {
736: if ((int)$module_id > 0 && (int)$item_id > 0) {
737: $comment_handler =& xoops_gethandler('comment');
738: $comments =& $comment_handler->getByItemId($module_id, $item_id);
739: if (is_array($comments)) {
740: $count = count($comments);
741: $deleted_num = array();
742: for ($i = 0; $i < $count; $i++) {
743: if (false != $comment_handler->delete($comments[$i])) {
744:
745: $poster_id = $comments[$i]->getVar('com_uid', 'n');
746: if ($poster_id != 0) {
747: $deleted_num[$poster_id] = !isset($deleted_num[$poster_id]) ? 1 : ($deleted_num[$poster_id] + 1);
748: }
749: }
750: }
751: $member_handler =& xoops_gethandler('member');
752: foreach ($deleted_num as $user_id => $post_num) {
753:
754: $com_poster = $member_handler->getUser($user_id);
755: if (is_object($com_poster)) {
756: $member_handler->updateUserByField($com_poster, 'posts', $com_poster->getVar('posts', 'n') - $post_num);
757: }
758: }
759: return true;
760: }
761: }
762: return false;
763: }
764:
765:
766:
767: function xoops_groupperm_deletebymoditem($module_id, $perm_name, $item_id = null)
768: {
769:
770: if ((int)$module_id <= 1) {
771: return false;
772: }
773: $gperm_handler =& xoops_gethandler('groupperm');
774: return $gperm_handler->deleteByModule($module_id, $perm_name, $item_id);
775: }
776:
777: function &xoops_utf8_encode(&$text)
778: {
779: if (XOOPS_USE_MULTIBYTES == 1) {
780: if (function_exists('mb_convert_encoding')) {
781: $out_text = mb_convert_encoding($text, 'UTF-8', 'auto');
782: return $out_text;
783: }
784: return $out_text;
785: }
786: $out_text = utf8_encode($text);
787: return $out_text;
788: }
789:
790: function &xoops_convert_encoding(&$text)
791: {
792: return xoops_utf8_encode($text);
793: }
794:
795: function xoops_getLinkedUnameFromId($userid)
796: {
797: $userid = (int)$userid;
798: if ($userid > 0) {
799: $member_handler =& xoops_gethandler('member');
800: $user =& $member_handler->getUser($userid);
801: if (is_object($user)) {
802: $linkeduser = '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$userid.'">'. $user->getVar('uname').'</a>';
803: return $linkeduser;
804: }
805: }
806: return $GLOBALS['xoopsConfig']['anonymous'];
807: }
808:
809: function xoops_trim($text)
810: {
811: if (function_exists('xoops_language_trim')) {
812: return xoops_language_trim($text);
813: }
814: return trim($text);
815: }
816:
817: if (!function_exists('htmlspecialchars_decode')) {
818: function htmlspecialchars_decode($text)
819: {
820: return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
821: }
822: }
823:
824: if (!function_exists('session_regenerate_id')) {
825:
826: function session_regenerate_id() {
827: srand(microtime() * 100000);
828: $random = md5(XOOPS_SALT . uniqid(rand(), true));
829: if (session_id($random)) {
830: return true;
831: } else {
832: return false;
833: }
834: }
835: }
836: ?>
837: