| 1 | <?php |
|---|
| 2 | // $Id: functions.php,v 1.7 2006/05/01 02:37:26 onokazu Exp $ |
|---|
| 3 | // ------------------------------------------------------------------------ // |
|---|
| 4 | // XOOPS - PHP Content Management System // |
|---|
| 5 | // Copyright (c) 2000 XOOPS.org // |
|---|
| 6 | // <http://www.xoops.org/> // |
|---|
| 7 | // ------------------------------------------------------------------------ // |
|---|
| 8 | // This program is free software; you can redistribute it and/or modify // |
|---|
| 9 | // it under the terms of the GNU General Public License as published by // |
|---|
| 10 | // the Free Software Foundation; either version 2 of the License, or // |
|---|
| 11 | // (at your option) any later version. // |
|---|
| 12 | // // |
|---|
| 13 | // You may not change or alter any portion of this comment or credits // |
|---|
| 14 | // of supporting developers from this source code or any supporting // |
|---|
| 15 | // source code which is considered copyrighted (c) material of the // |
|---|
| 16 | // original comment or credit authors. // |
|---|
| 17 | // // |
|---|
| 18 | // This program is distributed in the hope that it will be useful, // |
|---|
| 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|---|
| 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|---|
| 21 | // GNU General Public License for more details. // |
|---|
| 22 | // // |
|---|
| 23 | // You should have received a copy of the GNU General Public License // |
|---|
| 24 | // along with this program; if not, write to the Free Software // |
|---|
| 25 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|---|
| 26 | // ------------------------------------------------------------------------ // |
|---|
| 27 | |
|---|
| 28 | // ################## Various functions from here ################ |
|---|
| 29 | |
|---|
| 30 | function xoops_header($closehead=true) |
|---|
| 31 | { |
|---|
| 32 | global $xoopsConfig, $xoopsTheme, $xoopsConfigMetaFooter; |
|---|
| 33 | $myts =& MyTextSanitizer::getInstance(); |
|---|
| 34 | if ($xoopsConfig['gzip_compression'] == 1) { |
|---|
| 35 | ob_start("ob_gzhandler"); |
|---|
| 36 | } else { |
|---|
| 37 | ob_start(); |
|---|
| 38 | } |
|---|
| 39 | if (!headers_sent()) { |
|---|
| 40 | header ('Content-Type:text/html; charset='._CHARSET); |
|---|
| 41 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
|---|
| 42 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
|---|
| 43 | header('Cache-Control: no-store, no-cache, max-age=1, s-maxage=1, must-revalidate, post-check=0, pre-check=0'); |
|---|
| 44 | header("Pragma: no-cache"); |
|---|
| 45 | } |
|---|
| 46 | echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"; |
|---|
| 47 | |
|---|
| 48 | echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'._LANGCODE.'" lang="'._LANGCODE.'"> |
|---|
| 49 | <head> |
|---|
| 50 | <meta http-equiv="content-type" content="text/html; charset='._CHARSET.'" /> |
|---|
| 51 | <meta http-equiv="content-language" content="'._LANGCODE.'" /> |
|---|
| 52 | <meta name="robots" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_robots']).'" /> |
|---|
| 53 | <meta name="keywords" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_keywords']).'" /> |
|---|
| 54 | <meta name="description" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_desc']).'" /> |
|---|
| 55 | <meta name="rating" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_rating']).'" /> |
|---|
| 56 | <meta name="author" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_author']).'" /> |
|---|
| 57 | <meta name="copyright" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_copyright']).'" /> |
|---|
| 58 | <meta name="generator" content="XOOPS" /> |
|---|
| 59 | <title>'.htmlspecialchars($xoopsConfig['sitename']).'</title> |
|---|
| 60 | <script type="text/javascript" src="'.XOOPS_URL.'/include/xoops.js"></script> |
|---|
| 61 | '; |
|---|
| 62 | $themecss = getcss($xoopsConfig['theme_set']); |
|---|
| 63 | echo '<link rel="stylesheet" type="text/css" media="all" href="'.XOOPS_URL.'/xoops.css" />'; |
|---|
| 64 | if ($themecss) { |
|---|
| 65 | echo '<link rel="stylesheet" type="text/css" media="all" href="'.$themecss.'" />'; |
|---|
| 66 | //echo '<style type="text/css" media="all"><!-- @import url('.$themecss.'); --></style>'; |
|---|
| 67 | } |
|---|
| 68 | if ($closehead) { |
|---|
| 69 | echo '</head><body>'; |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | function xoops_footer() |
|---|
| 74 | { |
|---|
| 75 | echo '</body></html>'; |
|---|
| 76 | ob_end_flush(); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | function xoops_error($msg, $title='') |
|---|
| 80 | { |
|---|
| 81 | echo ' |
|---|
| 82 | <div class="errorMsg">'; |
|---|
| 83 | if ($title != '') { |
|---|
| 84 | echo '<h4>'.$title.'</h4>'; |
|---|
| 85 | } |
|---|
| 86 | if (is_array($msg)) { |
|---|
| 87 | foreach ($msg as $m) { |
|---|
| 88 | echo $m.'<br />'; |
|---|
| 89 | } |
|---|
| 90 | } else { |
|---|
| 91 | echo $msg; |
|---|
| 92 | } |
|---|
| 93 | echo '</div>'; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | function xoops_result($msg, $title='') |
|---|
| 97 | { |
|---|
| 98 | echo ' |
|---|
| 99 | <div class="resultMsg">'; |
|---|
| 100 | if ($title != '') { |
|---|
| 101 | echo '<h4>'.$title.'</h4>'; |
|---|
| 102 | } |
|---|
| 103 | if (is_array($msg)) { |
|---|
| 104 | foreach ($msg as $m) { |
|---|
| 105 | echo $m.'<br />'; |
|---|
| 106 | } |
|---|
| 107 | } else { |
|---|
| 108 | echo $msg; |
|---|
| 109 | } |
|---|
| 110 | echo '</div>'; |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | function xoops_confirm($hiddens, $action, $msg, $submit = '', $addToken = true) |
|---|
| 114 | { |
|---|
| 115 | $submit = ($submit != '') ? trim($submit) : _SUBMIT; |
|---|
| 116 | echo ' |
|---|
| 117 | <div class="confirmMsg"> |
|---|
| 118 | <h4>'.$msg.'</h4> |
|---|
| 119 | <form method="post" action="'.$action.'"> |
|---|
| 120 | '; |
|---|
| 121 | foreach ($hiddens as $name => $value) { |
|---|
| 122 | if (is_array($value)) { |
|---|
| 123 | foreach ($value as $caption => $newvalue) { |
|---|
| 124 | echo '<input type="radio" name="'.$name.'" value="'.htmlspecialchars($newvalue).'" /> '.$caption; |
|---|
| 125 | } |
|---|
| 126 | echo '<br />'; |
|---|
| 127 | } else { |
|---|
| 128 | echo '<input type="hidden" name="'.$name.'" value="'.htmlspecialchars($value).'" />'; |
|---|
| 129 | } |
|---|
| 130 | } |
|---|
| 131 | if ($addToken != false) { |
|---|
| 132 | $token=&XoopsMultiTokenHandler::quickCreate(XOOPS_TOKEN_DEFAULT); |
|---|
| 133 | echo $token->getHtml(); |
|---|
| 134 | } |
|---|
| 135 | echo ' |
|---|
| 136 | <input type="submit" name="confirm_submit" value="'.$submit.'" /> <input type="button" name="confirm_back" value="'._CANCEL.'" onclick="javascript:history.go(-1);" /> |
|---|
| 137 | </form> |
|---|
| 138 | </div> |
|---|
| 139 | '; |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | /** |
|---|
| 143 | * @brief xoops_confirm alias [test] |
|---|
| 144 | */ |
|---|
| 145 | function xoops_token_confirm($hiddens, $action, $msg, $submit='') |
|---|
| 146 | { |
|---|
| 147 | return xoops_confirm($hiddens, $action, $msg, $submit, true); |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | function xoops_confirm_validate() |
|---|
| 151 | { |
|---|
| 152 | return XoopsMultiTokenHandler::quickValidate(XOOPS_TOKEN_DEFAULT); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | function xoops_refcheck($docheck=1) |
|---|
| 156 | { |
|---|
| 157 | $ref = xoops_getenv('HTTP_REFERER'); |
|---|
| 158 | if ($docheck == 0) { |
|---|
| 159 | return true; |
|---|
| 160 | } |
|---|
| 161 | if ($ref == '') { |
|---|
| 162 | return false; |
|---|
| 163 | } |
|---|
| 164 | if (strpos($ref, XOOPS_URL) !== 0 ) { |
|---|
| 165 | return false; |
|---|
| 166 | } |
|---|
| 167 | return true; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | function xoops_getUserTimestamp($time, $timeoffset="") |
|---|
| 171 | { |
|---|
| 172 | global $xoopsConfig, $xoopsUser; |
|---|
| 173 | if ($timeoffset == '') { |
|---|
| 174 | if ($xoopsUser) { |
|---|
| 175 | $timeoffset = $xoopsUser->getVar("timezone_offset"); |
|---|
| 176 | } else { |
|---|
| 177 | $timeoffset = $xoopsConfig['default_TZ']; |
|---|
| 178 | } |
|---|
| 179 | } |
|---|
| 180 | $usertimestamp = intval($time) + (intval($timeoffset) - $xoopsConfig['server_TZ'])*3600; |
|---|
| 181 | return $usertimestamp; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | /* |
|---|
| 187 | * Function to display formatted times in user timezone |
|---|
| 188 | */ |
|---|
| 189 | function formatTimestamp($time, $format="l", $timeoffset="") |
|---|
| 190 | { |
|---|
| 191 | global $xoopsConfig, $xoopsUser; |
|---|
| 192 | $usertimestamp = xoops_getUserTimestamp($time, $timeoffset); |
|---|
| 193 | switch (strtolower($format)) { |
|---|
| 194 | case 's': |
|---|
| 195 | $datestring = _SHORTDATESTRING; |
|---|
| 196 | break; |
|---|
| 197 | case 'm': |
|---|
| 198 | $datestring = _MEDIUMDATESTRING; |
|---|
| 199 | break; |
|---|
| 200 | case 'mysql': |
|---|
| 201 | $datestring = "Y-m-d H:i:s"; |
|---|
| 202 | break; |
|---|
| 203 | case 'rss': |
|---|
| 204 | $datestring = "r"; |
|---|
| 205 | break; |
|---|
| 206 | case 'l': |
|---|
| 207 | $datestring = _DATESTRING; |
|---|
| 208 | break; |
|---|
| 209 | default: |
|---|
| 210 | if ($format != '') { |
|---|
| 211 | $datestring = $format; |
|---|
| 212 | } else { |
|---|
| 213 | $datestring = _DATESTRING; |
|---|
| 214 | } |
|---|
| 215 | break; |
|---|
| 216 | } |
|---|
| 217 | return ucfirst(date($datestring, $usertimestamp)); |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | /* |
|---|
| 221 | * Function to calculate server timestamp from user entered time (timestamp) |
|---|
| 222 | */ |
|---|
| 223 | function userTimeToServerTime($timestamp, $userTZ=null) |
|---|
| 224 | { |
|---|
| 225 | global $xoopsConfig; |
|---|
| 226 | if (!isset($userTZ)) { |
|---|
| 227 | $userTZ = $xoopsConfig['default_TZ']; |
|---|
| 228 | } |
|---|
| 229 | $timestamp = $timestamp - (($userTZ - $xoopsConfig['server_TZ']) * 3600); |
|---|
| 230 | return $timestamp; |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | function xoops_makepass() { |
|---|
| 234 | $makepass = ''; |
|---|
| 235 | $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"); |
|---|
| 236 | srand((double)microtime()*1000000); |
|---|
| 237 | for ($count = 1; $count <= 4; $count++) { |
|---|
| 238 | if (rand()%10 == 1) { |
|---|
| 239 | $makepass .= sprintf("%0.0f",(rand()%50)+1); |
|---|
| 240 | } else { |
|---|
| 241 | $makepass .= sprintf("%s",$syllables[rand()%62]); |
|---|
| 242 | } |
|---|
| 243 | } |
|---|
| 244 | return $makepass; |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | /* |
|---|
| 248 | * Functions to display dhtml loading image box |
|---|
| 249 | */ |
|---|
| 250 | function OpenWaitBox() |
|---|
| 251 | { |
|---|
| 252 | echo "<div id='waitDiv' style='position:absolute;left:40%;top:50%;visibility:hidden;text-align: center;'> |
|---|
| 253 | <table cellpadding='6' border='2' class='bg2'> |
|---|
| 254 | <tr> |
|---|
| 255 | <td align='center'><b><big>" ._FETCHING."</big></b><br /><img src='".XOOPS_URL."/images/await.gif' alt='' /><br />" ._PLEASEWAIT."</td> |
|---|
| 256 | </tr> |
|---|
| 257 | </table> |
|---|
| 258 | </div> |
|---|
| 259 | <script type='text/javascript'> |
|---|
| 260 | <!--// |
|---|
| 261 | var DHTML = (document.getElementById || document.all || document.layers); |
|---|
| 262 | function ap_getObj(name) { |
|---|
| 263 | if (document.getElementById) { |
|---|
| 264 | return document.getElementById(name).style; |
|---|
| 265 | } else if (document.all) { |
|---|
| 266 | return document.all[name].style; |
|---|
| 267 | } else if (document.layers) { |
|---|
| 268 | return document.layers[name]; |
|---|
| 269 | } |
|---|
| 270 | } |
|---|
| 271 | function ap_showWaitMessage(div,flag) { |
|---|
| 272 | if (!DHTML) { |
|---|
| 273 | return; |
|---|
| 274 | } |
|---|
| 275 | var x = ap_getObj(div); |
|---|
| 276 | x.visibility = (flag) ? 'visible' : 'hidden'; |
|---|
| 277 | if (!document.getElementById) { |
|---|
| 278 | if (document.layers) { |
|---|
| 279 | x.left=280/2; |
|---|
| 280 | } |
|---|
| 281 | } |
|---|
| 282 | return true; |
|---|
| 283 | } |
|---|
| 284 | ap_showWaitMessage('waitDiv', 1); |
|---|
| 285 | //--> |
|---|
| 286 | </script>"; |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | function CloseWaitBox() |
|---|
| 290 | { |
|---|
| 291 | echo "<script type='text/javascript'> |
|---|
| 292 | <!--// |
|---|
| 293 | ap_showWaitMessage('waitDiv', 0); |
|---|
| 294 | //--> |
|---|
| 295 | </script> |
|---|
| 296 | "; |
|---|
| 297 | } |
|---|
| 298 | |
|---|
| 299 | function checkEmail($email,$antispam = false) |
|---|
| 300 | { |
|---|
| 301 | if (!$email || !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i",$email)){ |
|---|
| 302 | return false; |
|---|
| 303 | } |
|---|
| 304 | if ($antispam) { |
|---|
| 305 | $email = str_replace("@", " at ", $email); |
|---|
| 306 | $email = str_replace(".", " dot ", $email); |
|---|
| 307 | return $email; |
|---|
| 308 | } else { |
|---|
| 309 | return true; |
|---|
| 310 | } |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | function formatURL($url) |
|---|
| 314 | { |
|---|
| 315 | $url = trim($url); |
|---|
| 316 | if ($url != '') { |
|---|
| 317 | if ((!preg_match("/^http[s]*:\/\//i", $url)) && (!preg_match("/^ftp*:\/\//i", $url)) && (!preg_match("/^ed2k*:\/\//i", $url)) ) { |
|---|
| 318 | $url = 'http://'.$url; |
|---|
| 319 | } |
|---|
| 320 | } |
|---|
| 321 | return $url; |
|---|
| 322 | } |
|---|
| 323 | |
|---|
| 324 | /* |
|---|
| 325 | * Function to display banners in all pages |
|---|
| 326 | */ |
|---|
| 327 | function showbanner() |
|---|
| 328 | { |
|---|
| 329 | echo xoops_getbanner(); |
|---|
| 330 | } |
|---|
| 331 | |
|---|
| 332 | /* |
|---|
| 333 | * Function to get banner html tags for use in templates |
|---|
| 334 | */ |
|---|
| 335 | function xoops_getbanner() |
|---|
| 336 | { |
|---|
| 337 | global $xoopsConfig; |
|---|
| 338 | $db =& Database::getInstance(); |
|---|
| 339 | $bresult = $db->query("SELECT COUNT(*) FROM ".$db->prefix("banner")); |
|---|
| 340 | list ($numrows) = $db->fetchRow($bresult); |
|---|
| 341 | if ( $numrows > 1 ) { |
|---|
| 342 | $numrows = $numrows-1; |
|---|
| 343 | mt_srand((double)microtime()*1000000); |
|---|
| 344 | $bannum = mt_rand(0, $numrows); |
|---|
| 345 | } else { |
|---|
| 346 | $bannum = 0; |
|---|
| 347 | } |
|---|
| 348 | if ( $numrows > 0 ) { |
|---|
| 349 | $bresult = $db->query("SELECT * FROM ".$db->prefix("banner"), 1, $bannum); |
|---|
| 350 | list ($bid, $cid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date, $htmlbanner, $htmlcode) = $db->fetchRow($bresult); |
|---|
| 351 | if ($xoopsConfig['my_ip'] == xoops_getenv('REMOTE_ADDR')) { |
|---|
| 352 | // EMPTY |
|---|
| 353 | } else { |
|---|
| 354 | $db->queryF(sprintf("UPDATE %s SET impmade = impmade+1 WHERE bid = %u", $db->prefix("banner"), $bid)); |
|---|
| 355 | } |
|---|
| 356 | /* Check if this impression is the last one and print the banner */ |
|---|
| 357 | if ( $imptotal == $impmade ) { |
|---|
| 358 | $newid = $db->genId($db->prefix("bannerfinish")."_bid_seq"); |
|---|
| 359 | $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()); |
|---|
| 360 | $db->queryF($sql); |
|---|
| 361 | $db->queryF(sprintf("DELETE FROM %s WHERE bid = %u", $db->prefix("banner"), $bid)); |
|---|
| 362 | } |
|---|
| 363 | if ($htmlbanner){ |
|---|
| 364 | $bannerobject = $htmlcode; |
|---|
| 365 | }else{ |
|---|
| 366 | $bannerobject = '<div><a href="'.XOOPS_URL.'/banners.php?op=click&bid='.$bid.'" target="_blank">'; |
|---|
| 367 | if (stristr($imageurl, '.swf')) { |
|---|
| 368 | $bannerobject = $bannerobject |
|---|
| 369 | .'<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">' |
|---|
| 370 | .'<param name="movie" value="'.$imageurl.'"></param>' |
|---|
| 371 | .'<param name="quality" value="high"></param>' |
|---|
| 372 | .'<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">' |
|---|
| 373 | .'</embed>' |
|---|
| 374 | .'</object>'; |
|---|
| 375 | } else { |
|---|
| 376 | $bannerobject = $bannerobject.'<img src="'.$imageurl.'" alt="" />'; |
|---|
| 377 | } |
|---|
| 378 | |
|---|
| 379 | $bannerobject = $bannerobject.'</a></div>'; |
|---|
| 380 | } |
|---|
| 381 | return $bannerobject; |
|---|
| 382 | } |
|---|
| 383 | } |
|---|
| 384 | |
|---|
| 385 | /* |
|---|
| 386 | * Function to redirect a user to certain pages |
|---|
| 387 | */ |
|---|
| 388 | function redirect_header($url, $time = 3, $message = '', $addredirect = true) |
|---|
| 389 | { |
|---|
| 390 | global $xoopsConfig, $xoopsRequestUri; |
|---|
| 391 | if (preg_match("/[\\0-\\31]/", $url) || preg_match("/^(javascript|vbscript|about):/i", $url)) { |
|---|
| 392 | $url = XOOPS_URL; |
|---|
| 393 | } |
|---|
| 394 | if (!defined('XOOPS_CPFUNC_LOADED')) { |
|---|
| 395 | require_once XOOPS_ROOT_PATH.'/class/template.php'; |
|---|
| 396 | $xoopsTpl = new XoopsTpl(); |
|---|
| 397 | $xoopsTpl->assign('sitename', htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES)); |
|---|
| 398 | $xoopsTpl->assign('langcode', _LANGCODE); |
|---|
| 399 | $xoopsTpl->assign('charset', _CHARSET); |
|---|
| 400 | $xoopsTpl->assign('time', $time); |
|---|
| 401 | if ($addredirect && strstr($url, 'user.php')) { |
|---|
| 402 | if (!strstr($url, '?')) { |
|---|
| 403 | $url .= '?xoops_redirect='.urlencode($xoopsRequestUri); |
|---|
| 404 | } else { |
|---|
| 405 | $url .= '&xoops_redirect='.urlencode($xoopsRequestUri); |
|---|
| 406 | } |
|---|
| 407 | } |
|---|
| 408 | if (defined('SID') && (! isset($_COOKIE[session_name()]) || ($xoopsConfig['use_mysession'] && $xoopsConfig['session_name'] != '' && !isset($_COOKIE[$xoopsConfig['session_name']])))) { |
|---|
| 409 | if (!strstr($url, '?')) { |
|---|
| 410 | $url .= '?' . SID; |
|---|
| 411 | } |
|---|
| 412 | else { |
|---|
| 413 | $url .= '&'.SID; |
|---|
| 414 | } |
|---|
| 415 | } |
|---|
| 416 | $url = preg_replace("/&/i", '&', htmlspecialchars($url, ENT_QUOTES)); |
|---|
| 417 | $xoopsTpl->assign('url', $url); |
|---|
| 418 | $message = trim($message) != '' ? $message : _TAKINGBACK; |
|---|
| 419 | $xoopsTpl->assign('message', $message); |
|---|
| 420 | $xoopsTpl->assign('lang_ifnotreload', sprintf(_IFNOTRELOAD, $url)); |
|---|
| 421 | $GLOBALS['xoopsModuleUpdate'] = 1; |
|---|
| 422 | $xoopsTpl->display('db:system_redirect.html'); |
|---|
| 423 | exit(); |
|---|
| 424 | } else { |
|---|
| 425 | $url = preg_replace("/&/i", '&', htmlspecialchars($url, ENT_QUOTES)); |
|---|
| 426 | echo ' |
|---|
| 427 | <html> |
|---|
| 428 | <head> |
|---|
| 429 | <title>'.htmlspecialchars($xoopsConfig['sitename']).'</title> |
|---|
| 430 | <meta http-equiv="Content-Type" content="text/html; charset='._CHARSET.'" /> |
|---|
| 431 | <meta http-equiv="Refresh" content="'.$time.'; url='.$url.'" /> |
|---|
| 432 | <style type="text/css"> |
|---|
| 433 | body {background-color : #fcfcfc; font-size: 12px; font-family: Trebuchet MS,Verdana, Arial, Helvetica, sans-serif; margin: 0px;} |
|---|
| 434 | .redirect {width: 70%; margin: 110px; text-align: center; padding: 15px; border: #e0e0e0 1px solid; color: #666666; background-color: #f6f6f6;} |
|---|
| 435 | .redirect a:link {color: #666666; text-decoration: none; font-weight: bold;} |
|---|
| 436 | .redirect a:visited {color: #666666; text-decoration: none; font-weight: bold;} |
|---|
| 437 | .redirect a:hover {color: #999999; text-decoration: underline; font-weight: bold;} |
|---|
| 438 | </style> |
|---|
| 439 | </head> |
|---|
| 440 | <body> |
|---|
| 441 | <div align="center"> |
|---|
| 442 | <div class="redirect"> |
|---|
| 443 | <span style="font-size: 16px; font-weight: bold;">'.$message.'</span> |
|---|
| 444 | <hr style="height: 3px; border: 3px #E18A00 solid; width: 95%;" /> |
|---|
| 445 | <p>'.sprintf(_IFNOTRELOAD, $url).'</p> |
|---|
| 446 | </div> |
|---|
| 447 | </div> |
|---|
| 448 | </body> |
|---|
| 449 | </html>'; |
|---|
| 450 | } |
|---|
| 451 | exit(); |
|---|
| 452 | } |
|---|
| 453 | |
|---|
| 454 | function xoops_getenv($key) |
|---|
| 455 | { |
|---|
| 456 | $ret = ''; |
|---|
| 457 | //$phpv = explode(".", PHP_VERSION); |
|---|
| 458 | //if ($phpv[0] > 3 && $phpv[1] > 0) { |
|---|
| 459 | // $ret = isset($_SERVER[$key]) ? $_SERVER[$key] : $_ENV[$key]; |
|---|
| 460 | //} else { |
|---|
| 461 | $ret = isset($_SERVER[$key]) ? $_SERVER[$key] : $_ENV[$key]; |
|---|
| 462 | //} |
|---|
| 463 | |
|---|
| 464 | switch($key) { |
|---|
| 465 | case 'PHP_SELF': |
|---|
| 466 | case 'PATH_INFO': |
|---|
| 467 | case 'PATH_TRANSLATED': |
|---|
| 468 | $ret = htmlspecialchars($ret,ENT_QUOTES); |
|---|
| 469 | break; |
|---|
| 470 | } |
|---|
| 471 | |
|---|
| 472 | return $ret; |
|---|
| 473 | } |
|---|
| 474 | |
|---|
| 475 | /* |
|---|
| 476 | * This function is deprecated. Do not use! |
|---|
| 477 | */ |
|---|
| 478 | function getTheme() |
|---|
| 479 | { |
|---|
| 480 | return $GLOBALS['xoopsConfig']['theme_set']; |
|---|
| 481 | } |
|---|
| 482 | |
|---|
| 483 | /* |
|---|
| 484 | * Function to get css file for a certain theme |
|---|
| 485 | * This function will be deprecated. |
|---|
| 486 | */ |
|---|
| 487 | function getcss($theme = '') |
|---|
| 488 | { |
|---|
| 489 | return xoops_getcss($theme); |
|---|
| 490 | } |
|---|
| 491 | |
|---|
| 492 | /* |
|---|
| 493 | * Function to get css file for a certain themeset |
|---|
| 494 | */ |
|---|
| 495 | function xoops_getcss($theme = '') |
|---|
| 496 | { |
|---|
| 497 | if ($theme == '') { |
|---|
| 498 | $theme = $GLOBALS['xoopsConfig']['theme_set']; |
|---|
| 499 | } |
|---|
| 500 | $uagent = xoops_getenv('HTTP_USER_AGENT'); |
|---|
| 501 | if (stristr($uagent, 'mac')) { |
|---|
| 502 | $str_css = 'styleMAC.css'; |
|---|
| 503 | } elseif (preg_match("/MSIE ([0-9]\.[0-9]{1,2})/i", $uagent)) { |
|---|
| 504 | $str_css = 'style.css'; |
|---|
| 505 | } else { |
|---|
| 506 | $str_css = 'styleNN.css'; |
|---|
| 507 | } |
|---|
| 508 | if (is_dir(XOOPS_THEME_PATH.'/'.$theme)) { |
|---|
| 509 | if (file_exists(XOOPS_THEME_PATH.'/'.$theme.'/'.$str_css)) { |
|---|
| 510 | return XOOPS_THEME_URL.'/'.$theme.'/'.$str_css; |
|---|
| 511 | } elseif (file_exists(XOOPS_THEME_PATH.'/'.$theme.'/style.css')) { |
|---|
| 512 | return XOOPS_THEME_URL.'/'.$theme.'/style.css'; |
|---|
| 513 | } |
|---|
| 514 | } |
|---|
| 515 | return ''; |
|---|
| 516 | } |
|---|
| 517 | |
|---|
| 518 | function &getMailer() |
|---|
| 519 | { |
|---|
| 520 | global $xoopsConfig; |
|---|
| 521 | include_once XOOPS_ROOT_PATH."/class/xoopsmailer.php"; |
|---|
| 522 | if ( file_exists(XOOPS_ROOT_PATH."/language/".$xoopsConfig['language']."/xoopsmailerlocal.php") ) { |
|---|
| 523 | include_once XOOPS_ROOT_PATH."/language/".$xoopsConfig['language']."/xoopsmailerlocal.php"; |
|---|
| 524 | if ( class_exists("XoopsMailerLocal") ) { |
|---|
| 525 | $ret =& new XoopsMailerLocal(); |
|---|
| 526 | return $ret; |
|---|
| 527 | } |
|---|
| 528 | } |
|---|
| 529 | $ret =& new XoopsMailer(); |
|---|
| 530 | return $ret; |
|---|
| 531 | } |
|---|
| 532 | |
|---|
| 533 | function &xoops_gethandler($name, $optional = false ) |
|---|
| 534 | { |
|---|
| 535 | static $handlers; |
|---|
| 536 | $name = strtolower(trim($name)); |
|---|
| 537 | if (!isset($handlers[$name])) { |
|---|
| 538 | if ( file_exists( $hnd_file = XOOPS_ROOT_PATH.'/kernel/'.$name.'.php' ) ) { |
|---|
| 539 | require_once $hnd_file; |
|---|
| 540 | } |
|---|
| 541 | $class = 'Xoops'.ucfirst($name).'Handler'; |
|---|
| 542 | if (class_exists($class)) { |
|---|
| 543 | $handlers[$name] = new $class($GLOBALS['xoopsDB']); |
|---|
| 544 | } |
|---|
| 545 | } |
|---|
| 546 | if (!isset($handlers[$name]) && !$optional ) { |
|---|
| 547 | trigger_error('Class <b>'.$class.'</b> does not exist<br />Handler Name: '.$name, E_USER_ERROR); |
|---|
| 548 | } |
|---|
| 549 | $ret = false; |
|---|
| 550 | if (isset($handlers[$name])) { |
|---|
| 551 | $ret =& $handlers[$name]; |
|---|
| 552 | } |
|---|
| 553 | return $ret; |
|---|
| 554 | } |
|---|
| 555 | |
|---|
| 556 | function &xoops_getmodulehandler($name = null, $module_dir = null, $optional = false) |
|---|
| 557 | { |
|---|
| 558 | static $handlers; |
|---|
| 559 | // if $module_dir is not specified |
|---|
| 560 | if (!isset($module_dir)) { |
|---|
| 561 | //if a module is loaded |
|---|
| 562 | if (isset($GLOBALS['xoopsModule']) && is_object($GLOBALS['xoopsModule'])) { |
|---|
| 563 | $module_dir = $GLOBALS['xoopsModule']->getVar('dirname'); |
|---|
| 564 | } else { |
|---|
| 565 | trigger_error('No Module is loaded', E_USER_ERROR); |
|---|
| 566 | } |
|---|
| 567 | } else { |
|---|
| 568 | $module_dir = trim($module_dir); |
|---|
| 569 | } |
|---|
| 570 | $name = (!isset($name)) ? $module_dir : trim($name); |
|---|
| 571 | if (!isset($handlers[$module_dir][$name])) { |
|---|
| 572 | if ( file_exists( $hnd_file = XOOPS_ROOT_PATH . "/modules/{$module_dir}/class/{$name}.php" ) ) { |
|---|
| 573 | include_once $hnd_file; |
|---|
| 574 | } |
|---|
| 575 | $class = ucfirst(strtolower($module_dir)).ucfirst($name).'Handler'; |
|---|
| 576 | if (class_exists($class)) { |
|---|
| 577 | $handlers[$module_dir][$name] = new $class($GLOBALS['xoopsDB']); |
|---|
| 578 | } |
|---|
| 579 | } |
|---|
| 580 | if (!isset($handlers[$module_dir][$name]) && !$optional) { |
|---|
| 581 | trigger_error('Handler does not exist<br />Module: '.$module_dir.'<br />Name: '.$name, E_USER_ERROR); |
|---|
| 582 | } |
|---|
| 583 | $ret = false; |
|---|
| 584 | if (isset($handlers[$module_dir][$name])) { |
|---|
| 585 | $ret =& $handlers[$module_dir][$name]; |
|---|
| 586 | } |
|---|
| 587 | return $ret; |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | function xoops_getrank($rank_id =0, $posts = 0) |
|---|
| 591 | { |
|---|
| 592 | $db =& Database::getInstance(); |
|---|
| 593 | $myts =& MyTextSanitizer::getInstance(); |
|---|
| 594 | $rank_id = intval($rank_id); |
|---|
| 595 | if ($rank_id != 0) { |
|---|
| 596 | $sql = "SELECT rank_title AS title, rank_image AS image FROM ".$db->prefix('ranks')." WHERE rank_id = ".$rank_id; |
|---|
| 597 | } else { |
|---|
| 598 | $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"; |
|---|
| 599 | } |
|---|
| 600 | $rank = $db->fetchArray($db->query($sql)); |
|---|
| 601 | $rank['title'] = $myts->makeTboxData4Show($rank['title']); |
|---|
| 602 | $rank['id'] = $rank_id; |
|---|
| 603 | return $rank; |
|---|
| 604 | } |
|---|
| 605 | |
|---|
| 606 | |
|---|
| 607 | /** |
|---|
| 608 | * Returns the portion of string specified by the start and length parameters. If $trimmarker is supplied, it is appended to the return string. This function works fine with multi-byte characters if mb_* functions exist on the server. |
|---|
| 609 | * |
|---|
| 610 | * @param string $str |
|---|
| 611 | * @param int $start |
|---|
| 612 | * @param int $length |
|---|
| 613 | * @param string $trimmarker |
|---|
| 614 | * |
|---|
| 615 | * @return string |
|---|
| 616 | */ |
|---|
| 617 | function xoops_substr($str, $start, $length, $trimmarker = '...') |
|---|
| 618 | { |
|---|
| 619 | if ( !XOOPS_USE_MULTIBYTES ) { |
|---|
| 620 | return ( strlen($str) - $start <= $length ) ? substr( $str, $start, $length ) : substr( $str, $start, $length - strlen($trimmarker) ) . $trimmarker; |
|---|
| 621 | } |
|---|
| 622 | if (function_exists('mb_internal_encoding') && @mb_internal_encoding(_CHARSET)) { |
|---|
| 623 | $str2 = mb_strcut( $str , $start , $length - strlen( $trimmarker ) ); |
|---|
| 624 | return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : '' ); |
|---|
| 625 | } |
|---|
| 626 | // phppp patch |
|---|
| 627 | $DEP_CHAR=127; |
|---|
| 628 | $pos_st=0; |
|---|
| 629 | $action = false; |
|---|
| 630 | for ( $pos_i = 0; $pos_i < strlen($str); $pos_i++ ) { |
|---|
| 631 | if ( ord( substr( $str, $pos_i, 1) ) > 127 ) { |
|---|
| 632 | $pos_i++; |
|---|
| 633 | } |
|---|
| 634 | if ($pos_i<=$start) { |
|---|
| 635 | $pos_st=$pos_i; |
|---|
| 636 | } |
|---|
| 637 | if ($pos_i>=$pos_st+$length) { |
|---|
| 638 | $action = true; |
|---|
| 639 | break; |
|---|
| 640 | } |
|---|
| 641 | } |
|---|
| 642 | return ($action) ? substr( $str, $pos_st, $pos_i - $pos_st - strlen($trimmarker) ) . $trimmarker : $str; |
|---|
| 643 | } |
|---|
| 644 | |
|---|
| 645 | // RMV-NOTIFY |
|---|
| 646 | // ################ Notification Helper Functions ################## |
|---|
| 647 | |
|---|
| 648 | // We want to be able to delete by module, by user, or by item. |
|---|
| 649 | // How do we specify this?? |
|---|
| 650 | |
|---|
| 651 | function xoops_notification_deletebymodule ($module_id) |
|---|
| 652 | { |
|---|
| 653 | $notification_handler =& xoops_gethandler('notification'); |
|---|
| 654 | return $notification_handler->unsubscribeByModule ($module_id); |
|---|
| 655 | } |
|---|
| 656 | |
|---|
| 657 | function xoops_notification_deletebyuser ($user_id) |
|---|
| 658 | { |
|---|
| 659 | $notification_handler =& xoops_gethandler('notification'); |
|---|
| 660 | return $notification_handler->unsubscribeByUser ($user_id); |
|---|
| 661 | } |
|---|
| 662 | |
|---|
| 663 | function xoops_notification_deletebyitem ($module_id, $category, $item_id) |
|---|
| 664 | { |
|---|
| 665 | $notification_handler =& xoops_gethandler('notification'); |
|---|
| 666 | return $notification_handler->unsubscribeByItem ($module_id, $category, $item_id); |
|---|
| 667 | } |
|---|
| 668 | |
|---|
| 669 | // ################### Comment helper functions #################### |
|---|
| 670 | |
|---|
| 671 | function xoops_comment_count($module_id, $item_id = null) |
|---|
| 672 | { |
|---|
| 673 | $comment_handler =& xoops_gethandler('comment'); |
|---|
| 674 | $criteria = new CriteriaCompo(new Criteria('com_modid', intval($module_id))); |
|---|
| 675 | if (isset($item_id)) { |
|---|
| 676 | $criteria->add(new Criteria('com_itemid', intval($item_id))); |
|---|
| 677 | } |
|---|
| 678 | return $comment_handler->getCount($criteria); |
|---|
| 679 | } |
|---|
| 680 | |
|---|
| 681 | function xoops_comment_delete($module_id, $item_id) |
|---|
| 682 | { |
|---|
| 683 | if (intval($module_id) > 0 && intval($item_id) > 0) { |
|---|
| 684 | $comment_handler =& xoops_gethandler('comment'); |
|---|
| 685 | $comments =& $comment_handler->getByItemId($module_id, $item_id); |
|---|
| 686 | if (is_array($comments)) { |
|---|
| 687 | $count = count($comments); |
|---|
| 688 | $deleted_num = array(); |
|---|
| 689 | for ($i = 0; $i < $count; $i++) { |
|---|
| 690 | if (false != $comment_handler->delete($comments[$i])) { |
|---|
| 691 | // store poster ID and deleted post number into array for later use |
|---|
| 692 | $poster_id = $comments[$i]->getVar('com_uid'); |
|---|
| 693 | if ($poster_id != 0) { |
|---|
| 694 | $deleted_num[$poster_id] = !isset($deleted_num[$poster_id]) ? 1 : ($deleted_num[$poster_id] + 1); |
|---|
| 695 | } |
|---|
| 696 | } |
|---|
| 697 | } |
|---|
| 698 | $member_handler =& xoops_gethandler('member'); |
|---|
| 699 | foreach ($deleted_num as $user_id => $post_num) { |
|---|
| 700 | // update user posts |
|---|
| 701 | $com_poster = $member_handler->getUser($user_id); |
|---|
| 702 | if (is_object($com_poster)) { |
|---|
| 703 | $member_handler->updateUserByField($com_poster, 'posts', $com_poster->getVar('posts') - $post_num); |
|---|
| 704 | } |
|---|
| 705 | } |
|---|
| 706 | return true; |
|---|
| 707 | } |
|---|
| 708 | } |
|---|
| 709 | return false; |
|---|
| 710 | } |
|---|
| 711 | |
|---|
| 712 | // ################ Group Permission Helper Functions ################## |
|---|
| 713 | |
|---|
| 714 | function xoops_groupperm_deletebymoditem($module_id, $perm_name, $item_id = null) |
|---|
| 715 | { |
|---|
| 716 | // do not allow system permissions to be deleted |
|---|
| 717 | if (intval($module_id) <= 1) { |
|---|
| 718 | return false; |
|---|
| 719 | } |
|---|
| 720 | $gperm_handler =& xoops_gethandler('groupperm'); |
|---|
| 721 | return $gperm_handler->deleteByModule($module_id, $perm_name, $item_id); |
|---|
| 722 | } |
|---|
| 723 | |
|---|
| 724 | function &xoops_utf8_encode(&$text) |
|---|
| 725 | { |
|---|
| 726 | if (XOOPS_USE_MULTIBYTES == 1) { |
|---|
| 727 | if (function_exists('mb_convert_encoding')) { |
|---|
| 728 | return mb_convert_encoding($text, 'UTF-8', 'auto'); |
|---|
| 729 | } |
|---|
| 730 | return $text; |
|---|
| 731 | } |
|---|
| 732 | return utf8_encode($text); |
|---|
| 733 | } |
|---|
| 734 | |
|---|
| 735 | function &xoops_convert_encoding(&$text) |
|---|
| 736 | { |
|---|
| 737 | return xoops_utf8_encode($text); |
|---|
| 738 | } |
|---|
| 739 | |
|---|
| 740 | function xoops_getLinkedUnameFromId($userid) |
|---|
| 741 | { |
|---|
| 742 | $userid = intval($userid); |
|---|
| 743 | if ($userid > 0) { |
|---|
| 744 | $member_handler =& xoops_gethandler('member'); |
|---|
| 745 | $user =& $member_handler->getUser($userid); |
|---|
| 746 | if (is_object($user)) { |
|---|
| 747 | $linkeduser = '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$userid.'">'. $user->getVar('uname').'</a>'; |
|---|
| 748 | return $linkeduser; |
|---|
| 749 | } |
|---|
| 750 | } |
|---|
| 751 | return $GLOBALS['xoopsConfig']['anonymous']; |
|---|
| 752 | } |
|---|
| 753 | |
|---|
| 754 | function xoops_trim($text) |
|---|
| 755 | { |
|---|
| 756 | if (function_exists('xoops_language_trim')) { |
|---|
| 757 | return xoops_language_trim($text); |
|---|
| 758 | } |
|---|
| 759 | return trim($text); |
|---|
| 760 | } |
|---|
| 761 | |
|---|
| 762 | ?> |
|---|