PageRenderTime 32ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/miles/GlobalMBA/mba/sns_00/upload/bbs/include/global.func.php

#
PHP | 1854 lines | 1662 code | 172 blank | 20 comment | 527 complexity | 775cf43bf3ba215b1c9f3a26670bbd2c MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. [Discuz!] (C)2001-2009 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: global.func.php 21342 2010-01-06 08:52:53Z zhaoxiongfei $
  6. */
  7. if(!defined('IN_DISCUZ')) {
  8. exit('Access Denied');
  9. }
  10. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  11. $ckey_length = 4;
  12. $key = md5($key ? $key : $GLOBALS['discuz_auth_key']);
  13. $keya = md5(substr($key, 0, 16));
  14. $keyb = md5(substr($key, 16, 16));
  15. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';
  16. $cryptkey = $keya.md5($keya.$keyc);
  17. $key_length = strlen($cryptkey);
  18. $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
  19. $string_length = strlen($string);
  20. $result = '';
  21. $box = range(0, 255);
  22. $rndkey = array();
  23. for($i = 0; $i <= 255; $i++) {
  24. $rndkey[$i] = ord($cryptkey[$i % $key_length]);
  25. }
  26. for($j = $i = 0; $i < 256; $i++) {
  27. $j = ($j + $box[$i] + $rndkey[$i]) % 256;
  28. $tmp = $box[$i];
  29. $box[$i] = $box[$j];
  30. $box[$j] = $tmp;
  31. }
  32. for($a = $j = $i = 0; $i < $string_length; $i++) {
  33. $a = ($a + 1) % 256;
  34. $j = ($j + $box[$a]) % 256;
  35. $tmp = $box[$a];
  36. $box[$a] = $box[$j];
  37. $box[$j] = $tmp;
  38. $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
  39. }
  40. if($operation == 'DECODE') {
  41. if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
  42. return substr($result, 26);
  43. } else {
  44. return '';
  45. }
  46. } else {
  47. return $keyc.str_replace('=', '', base64_encode($result));
  48. }
  49. }
  50. function aidencode($aid) {
  51. static $sidauth = '';
  52. $sidauth = $sidauth != '' ? $sidauth : authcode($GLOBALS['sid'], 'ENCODE', $GLOBALS['authkey']);
  53. return rawurlencode(base64_encode($aid.'|'.substr(md5($aid.md5($GLOBALS['authkey']).$GLOBALS['timestamp']), 0, 8).'|'.$GLOBALS['timestamp'].'|'.$sidauth));
  54. }
  55. function clearcookies() {
  56. global $discuz_uid, $discuz_user, $discuz_pw, $discuz_secques, $adminid, $credits;
  57. foreach(array('sid', 'auth', 'visitedfid', 'onlinedetail', 'loginuser', 'activationauth', 'indextype') as $k) {
  58. dsetcookie($k);
  59. }
  60. $discuz_uid = $adminid = $credits = 0;
  61. $discuz_user = $discuz_pw = $discuz_secques = '';
  62. }
  63. function checklowerlimit($creditsarray, $coef = 1) {
  64. if(is_array($creditsarray)) {
  65. global $extcredits, $id;
  66. foreach($creditsarray as $id => $addcredits) {
  67. $addcredits = $addcredits * $coef;
  68. if($addcredits < 0 && ($GLOBALS['extcredits'.$id] < $extcredits[$id]['lowerlimit'] || (($GLOBALS['extcredits'.$id] + $addcredits) < $extcredits[$id]['lowerlimit']))) {
  69. showmessage('credits_policy_lowerlimit');
  70. }
  71. }
  72. }
  73. }
  74. function checkmd5($md5, $verified, $salt = '') {
  75. if(md5($md5.$salt) == $verified) {
  76. $result = !empty($salt) ? 1 : 2;
  77. } elseif(empty($salt)) {
  78. $result = $md5 == $verified ? 3 : ((strlen($verified) == 16 && substr($md5, 8, 16) == $verified) ? 4 : 0);
  79. } else {
  80. $result = 0;
  81. }
  82. return $result;
  83. }
  84. function checktplrefresh($maintpl, $subtpl, $timecompare, $templateid, $tpldir) {
  85. global $tplrefresh;
  86. if(empty($timecompare) || $tplrefresh == 1 || ($tplrefresh > 1 && !($GLOBALS['timestamp'] % $tplrefresh))) {
  87. if(empty($timecompare) || @filemtime($subtpl) > $timecompare) {
  88. require_once DISCUZ_ROOT.'./include/template.func.php';
  89. parse_template($maintpl, $templateid, $tpldir);
  90. return TRUE;
  91. }
  92. }
  93. return FALSE;
  94. }
  95. function cutstr($string, $length, $dot = ' ...') {
  96. global $charset;
  97. if(strlen($string) <= $length) {
  98. return $string;
  99. }
  100. $string = str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'), $string);
  101. $strcut = '';
  102. if(strtolower($charset) == 'utf-8') {
  103. $n = $tn = $noc = 0;
  104. while($n < strlen($string)) {
  105. $t = ord($string[$n]);
  106. if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
  107. $tn = 1; $n++; $noc++;
  108. } elseif(194 <= $t && $t <= 223) {
  109. $tn = 2; $n += 2; $noc += 2;
  110. } elseif(224 <= $t && $t <= 239) {
  111. $tn = 3; $n += 3; $noc += 2;
  112. } elseif(240 <= $t && $t <= 247) {
  113. $tn = 4; $n += 4; $noc += 2;
  114. } elseif(248 <= $t && $t <= 251) {
  115. $tn = 5; $n += 5; $noc += 2;
  116. } elseif($t == 252 || $t == 253) {
  117. $tn = 6; $n += 6; $noc += 2;
  118. } else {
  119. $n++;
  120. }
  121. if($noc >= $length) {
  122. break;
  123. }
  124. }
  125. if($noc > $length) {
  126. $n -= $tn;
  127. }
  128. $strcut = substr($string, 0, $n);
  129. } else {
  130. for($i = 0; $i < $length; $i++) {
  131. $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
  132. }
  133. }
  134. $strcut = str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $strcut);
  135. return $strcut.$dot;
  136. }
  137. function daddslashes($string, $force = 0) {
  138. !defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
  139. if(!MAGIC_QUOTES_GPC || $force) {
  140. if(is_array($string)) {
  141. foreach($string as $key => $val) {
  142. $string[$key] = daddslashes($val, $force);
  143. }
  144. } else {
  145. $string = addslashes($string);
  146. }
  147. }
  148. return $string;
  149. }
  150. function datecheck($ymd, $sep='-') {
  151. if(!empty($ymd)) {
  152. list($year, $month, $day) = explode($sep, $ymd);
  153. return checkdate($month, $day, $year);
  154. } else {
  155. return FALSE;
  156. }
  157. }
  158. function debuginfo() {
  159. if($GLOBALS['debug']) {
  160. global $db, $discuz_starttime, $debuginfo;
  161. $mtime = explode(' ', microtime());
  162. $debuginfo = array('time' => number_format(($mtime[1] + $mtime[0] - $discuz_starttime), 6), 'queries' => $db->querynum);
  163. return TRUE;
  164. } else {
  165. return FALSE;
  166. }
  167. }
  168. function dexit($message = '') {
  169. echo $message;
  170. output();
  171. exit();
  172. }
  173. function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) {
  174. $return = '';
  175. $matches = parse_url($url);
  176. $host = $matches['host'];
  177. $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
  178. $port = !empty($matches['port']) ? $matches['port'] : 80;
  179. if($post) {
  180. $out = "POST $path HTTP/1.0\r\n";
  181. $out .= "Accept: */*\r\n";
  182. //$out .= "Referer: $boardurl\r\n";
  183. $out .= "Accept-Language: zh-cn\r\n";
  184. $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
  185. $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
  186. $out .= "Host: $host\r\n";
  187. $out .= 'Content-Length: '.strlen($post)."\r\n";
  188. $out .= "Connection: Close\r\n";
  189. $out .= "Cache-Control: no-cache\r\n";
  190. $out .= "Cookie: $cookie\r\n\r\n";
  191. $out .= $post;
  192. } else {
  193. $out = "GET $path HTTP/1.0\r\n";
  194. $out .= "Accept: */*\r\n";
  195. //$out .= "Referer: $boardurl\r\n";
  196. $out .= "Accept-Language: zh-cn\r\n";
  197. $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
  198. $out .= "Host: $host\r\n";
  199. $out .= "Connection: Close\r\n";
  200. $out .= "Cookie: $cookie\r\n\r\n";
  201. }
  202. $fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);
  203. if(!$fp) {
  204. return '';
  205. } else {
  206. stream_set_blocking($fp, $block);
  207. stream_set_timeout($fp, $timeout);
  208. @fwrite($fp, $out);
  209. $status = stream_get_meta_data($fp);
  210. if(!$status['timed_out']) {
  211. while (!feof($fp)) {
  212. if(($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) {
  213. break;
  214. }
  215. }
  216. $stop = false;
  217. while(!feof($fp) && !$stop) {
  218. $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
  219. $return .= $data;
  220. if($limit) {
  221. $limit -= strlen($data);
  222. $stop = $limit <= 0;
  223. }
  224. }
  225. }
  226. @fclose($fp);
  227. return $return;
  228. }
  229. }
  230. function dhtmlspecialchars($string) {
  231. if(is_array($string)) {
  232. foreach($string as $key => $val) {
  233. $string[$key] = dhtmlspecialchars($val);
  234. }
  235. } else {
  236. $string = preg_replace('/&amp;((#(\d{3,5}|x[a-fA-F0-9]{4}));)/', '&\\1',
  237. //$string = preg_replace('/&amp;((#(\d{3,5}|x[a-fA-F0-9]{4})|[a-zA-Z][a-z0-9]{2,5});)/', '&\\1',
  238. str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $string));
  239. }
  240. return $string;
  241. }
  242. function dheader($string, $replace = true, $http_response_code = 0) {
  243. $string = str_replace(array("\r", "\n"), array('', ''), $string);
  244. if(empty($http_response_code) || PHP_VERSION < '4.3' ) {
  245. @header($string, $replace);
  246. } else {
  247. @header($string, $replace, $http_response_code);
  248. }
  249. if(preg_match('/^\s*location:/is', $string)) {
  250. exit();
  251. }
  252. }
  253. function dreferer($default = '') {
  254. global $referer, $indexname;
  255. $default = empty($default) ? $indexname : '';
  256. if(empty($referer) && isset($GLOBALS['_SERVER']['HTTP_REFERER'])) {
  257. $referer = preg_replace("/([\?&])((sid\=[a-z0-9]{6})(&|$))/i", '\\1', $GLOBALS['_SERVER']['HTTP_REFERER']);
  258. $referer = substr($referer, -1) == '?' ? substr($referer, 0, -1) : $referer;
  259. } else {
  260. $referer = dhtmlspecialchars($referer);
  261. }
  262. if(strpos($referer, 'logging.php')) {
  263. $referer = $default;
  264. }
  265. return $referer;
  266. }
  267. function dsetcookie($var, $value = '', $life = 0, $prefix = 1, $httponly = false) {
  268. global $cookiepre, $cookiedomain, $cookiepath, $timestamp, $_SERVER;
  269. $var = ($prefix ? $cookiepre : '').$var;
  270. if($value == '' || $life < 0) {
  271. $value = '';
  272. $life = -1;
  273. }
  274. $life = $life > 0 ? $timestamp + $life : ($life < 0 ? $timestamp - 31536000 : 0);
  275. $path = $httponly && PHP_VERSION < '5.2.0' ? "$cookiepath; HttpOnly" : $cookiepath;
  276. $secure = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0;
  277. if(PHP_VERSION < '5.2.0') {
  278. setcookie($var, $value, $life, $path, $cookiedomain, $secure);
  279. } else {
  280. setcookie($var, $value, $life, $path, $cookiedomain, $secure, $httponly);
  281. }
  282. }
  283. function dunlink($filename, $havethumb = 0, $remote = 0) {
  284. global $authkey, $ftp, $attachdir;
  285. if($remote) {
  286. require_once DISCUZ_ROOT.'./include/ftp.func.php';
  287. if(!$ftp['connid']) {
  288. if(!($ftp['connid'] = dftp_connect($ftp['host'], $ftp['username'], authcode($ftp['password'], 'DECODE', md5($authkey)), $ftp['attachdir'], $ftp['port'], $ftp['ssl']))) {
  289. return;
  290. }
  291. }
  292. dftp_delete($ftp['connid'], $filename);
  293. $havethumb && dftp_delete($ftp['connid'], $filename.'.thumb.jpg');
  294. } else {
  295. @unlink($attachdir.'/'.$filename);
  296. $havethumb && @unlink($attachdir.'/'.$filename.'.thumb.jpg');
  297. }
  298. }
  299. function dgmdate($format, $timestamp, $convert = 1) {
  300. $s = gmdate($format, $timestamp);
  301. if($GLOBALS['dateconvert'] && $convert) {
  302. if($GLOBALS['discuz_uid']) {
  303. if(!isset($GLOBALS['disableddateconvert'])) {
  304. $customshow = str_pad(base_convert($GLOBALS['customshow'], 10, 3), 4, '0', STR_PAD_LEFT);
  305. $GLOBALS['disableddateconvert'] = $customshow{0};
  306. }
  307. if($GLOBALS['disableddateconvert']) {
  308. return $s;
  309. }
  310. }
  311. if(!isset($GLOBALS['todaytimestamp'])) {
  312. $GLOBALS['todaytimestamp'] = $GLOBALS['timestamp'] - ($GLOBALS['timestamp'] + $GLOBALS['timeoffset'] * 3600) % 86400 + $GLOBALS['timeoffset'] * 3600;
  313. }
  314. $lang = $GLOBALS['dlang']['date'];
  315. $time = $GLOBALS['timestamp'] + $GLOBALS['timeoffset'] * 3600 - $timestamp;
  316. if($timestamp >= $GLOBALS['todaytimestamp']) {
  317. if($time > 3600) {
  318. return '<span title="'.$s.'">'.intval($time / 3600).'&nbsp;'.$lang[4].$lang[0].'</span>';
  319. } elseif($time > 1800) {
  320. return '<span title="'.$s.'">'.$lang[5].$lang[4].$lang[0].'</span>';
  321. } elseif($time > 60) {
  322. return '<span title="'.$s.'">'.intval($time / 60).'&nbsp;'.$lang[6].$lang[0].'</span>';
  323. } elseif($time > 0) {
  324. return '<span title="'.$s.'">'.$time.'&nbsp;'.$lang[7].$lang[0].'</span>';
  325. } elseif($time == 0) {
  326. return '<span title="'.$s.'">'.$lang[8].'</span>';
  327. } else {
  328. return $s;
  329. }
  330. } elseif(($days = intval(($GLOBALS['todaytimestamp'] - $timestamp) / 86400)) >= 0 && $days < 7) {
  331. if($days == 0) {
  332. return '<span title="'.$s.'">'.$lang[2].'&nbsp;'.gmdate($GLOBALS['timeformat'], $timestamp).'</span>';
  333. } elseif($days == 1) {
  334. return '<span title="'.$s.'">'.$lang[3].'&nbsp;'.gmdate($GLOBALS['timeformat'], $timestamp).'</span>';
  335. } else {
  336. return '<span title="'.$s.'">'.($days + 1).'&nbsp;'.$lang[1].$lang[0].'&nbsp;'.gmdate($GLOBALS['timeformat'], $timestamp).'</span>';
  337. }
  338. } else {
  339. return $s;
  340. }
  341. } else {
  342. return $s;
  343. }
  344. }
  345. function errorlog($type, $message, $halt = 1) {
  346. global $timestamp, $discuz_userss, $onlineip, $_SERVER;
  347. $user = empty($discuz_userss) ? '' : $discuz_userss.'<br />';
  348. $user .= $onlineip.'|'.$_SERVER['REMOTE_ADDR'];
  349. writelog('errorlog', dhtmlspecialchars("$timestamp\t$type\t$user\t".str_replace(array("\r", "\n"), array(' ', ' '), trim($message))));
  350. if($halt) {
  351. exit();
  352. }
  353. }
  354. function fileext($filename) {
  355. return trim(substr(strrchr($filename, '.'), 1, 10));
  356. }
  357. function formhash($specialadd = '') {
  358. global $discuz_user, $discuz_uid, $discuz_pw, $timestamp, $discuz_auth_key;
  359. $hashadd = defined('IN_ADMINCP') ? 'Only For Discuz! Admin Control Panel' : '';
  360. return substr(md5(substr($timestamp, 0, -7).$discuz_user.$discuz_uid.$discuz_pw.$discuz_auth_key.$hashadd.$specialadd), 8, 8);
  361. }
  362. function forumperm($permstr) {
  363. global $groupid, $extgroupids;
  364. $groupidarray = array($groupid);
  365. foreach(explode("\t", $extgroupids) as $extgroupid) {
  366. if($extgroupid = intval(trim($extgroupid))) {
  367. $groupidarray[] = $extgroupid;
  368. }
  369. }
  370. return preg_match("/(^|\t)(".implode('|', $groupidarray).")(\t|$)/", $permstr);
  371. }
  372. function formulaperm($formula, $type = 0, $wap = FALSE) {
  373. global $db, $tablepre, $_DSESSION, $extcredits, $formulamessage, $usermsg, $forum, $language, $medalstatus, $discuz_uid, $timestamp;
  374. $formula = unserialize($formula);
  375. $medalperm = $formula['medal'];
  376. $permusers = $formula['users'];
  377. $permmessage = $formula['message'];
  378. if(!$type && $medalstatus && $medalperm) {
  379. $exists = 1;
  380. $formulamessage = '';
  381. $medalpermc = $medalperm;
  382. if($discuz_uid) {
  383. $medals = explode("\t", $db->result_first("SELECT medals FROM {$tablepre}memberfields WHERE uid='$discuz_uid'"));
  384. foreach($medalperm as $k => $medal) {
  385. foreach($medals as $r) {
  386. list($medalid) = explode("|", $r);
  387. if($medalid == $medal) {
  388. $exists = 0;
  389. unset($medalpermc[$k]);
  390. }
  391. }
  392. }
  393. } else {
  394. $exists = 0;
  395. }
  396. if($medalpermc) {
  397. if(!$wap) {
  398. @include DISCUZ_ROOT.'./forumdata/cache/cache_medals.php';
  399. foreach($medalpermc as $medal) {
  400. if($_DCACHE['medals'][$medal]) {
  401. $formulamessage .= '<img src="images/common/'.$_DCACHE['medals'][$medal]['image'].'" />'.$_DCACHE['medals'][$medal]['name'].'&nbsp; ';
  402. }
  403. }
  404. showmessage('forum_permforum_nomedal', NULL, 'NOPERM');
  405. } else {
  406. wapmsg('forum_nopermission');
  407. }
  408. }
  409. }
  410. $formula = $formula[1];
  411. if(!$type && ($_DSESSION['adminid'] == 1 || $forum['ismoderator'])) {
  412. return FALSE;
  413. }
  414. if(!$type && $permusers) {
  415. $permusers = str_replace(array("\r\n", "\r"), array("\n", "\n"), $permusers);
  416. $permusers = explode("\n", trim($permusers));
  417. if(!in_array($GLOBALS['discuz_user'], $permusers)) {
  418. showmessage('forum_permforum_disallow', NULL, 'NOPERM');
  419. }
  420. }
  421. if(!$formula) {
  422. return FALSE;
  423. }
  424. if(strexists($formula, '$memberformula[')) {
  425. preg_match_all("/\\\$memberformula\['(\w+?)'\]/", $formula, $a);
  426. $fields = $profilefields = array();
  427. $mfadd = '';
  428. foreach($a[1] as $field) {
  429. switch($field) {
  430. case 'regdate':
  431. $formula = preg_replace("/\{(\d{4})\-(\d{1,2})\-(\d{1,2})\}/e", "'\\1-'.sprintf('%02d', '\\2').'-'.sprintf('%02d', '\\3')", $formula);
  432. case 'regday':
  433. $fields[] = 'm.regdate';break;
  434. case 'regip':
  435. case 'lastip':
  436. $formula = preg_replace("/\{([\d\.]+?)\}/", "'\\1'", $formula);
  437. $fields[] = 'm.'.$field;break;
  438. case substr($field, 0, 6) == 'field_':
  439. $profilefields[] = $field;
  440. case 'buyercredit':
  441. case 'sellercredit':
  442. $mfadd = "LEFT JOIN {$tablepre}memberfields mf ON m.uid=mf.uid";
  443. $fields[] = 'mf.'.$field;break;
  444. }
  445. }
  446. $memberformula = array();
  447. if($discuz_uid) {
  448. $memberformula = $db->fetch_first("SELECT ".implode(',', $fields)." FROM {$tablepre}members m $mfadd WHERE m.uid='$discuz_uid'");
  449. if(in_array('regday', $a[1])) {
  450. $memberformula['regday'] = intval(($timestamp - $memberformula['regdate']) / 86400);
  451. }
  452. if(in_array('regdate', $a[1])) {
  453. $memberformula['regdate'] = date('Y-m-d', $memberformula['regdate']);
  454. }
  455. $memberformula['lastip'] = $memberformula['lastip'] ? $memberformula['lastip'] : $GLOBALS['onlineip'];
  456. } else {
  457. if(isset($memberformula['regip'])) {
  458. $memberformula['regip'] = $GLOBALS['onlineip'];
  459. }
  460. if(isset($memberformula['lastip'])) {
  461. $memberformula['lastip'] = $GLOBALS['onlineip'];
  462. }
  463. }
  464. }
  465. @eval("\$formulaperm = ($formula) ? TRUE : FALSE;");
  466. if(!$formulaperm || $type == 2) {
  467. if(!$permmessage) {
  468. include_once language('misc');
  469. $search = array('$memberformula[\'regdate\']', '$memberformula[\'regday\']', '$memberformula[\'regip\']', '$memberformula[\'lastip\']', '$memberformula[\'buyercredit\']', '$memberformula[\'sellercredit\']', '$_DSESSION[\'digestposts\']', '$_DSESSION[\'posts\']', '$_DSESSION[\'threads\']', '$_DSESSION[\'oltime\']', '$_DSESSION[\'pageviews\']');
  470. $replace = array($language['formulaperm_regdate'], $language['formulaperm_regday'], $language['formulaperm_regip'], $language['formulaperm_lastip'], $language['formulaperm_buyercredit'], $language['formulaperm_sellercredit'], $language['formulaperm_digestposts'], $language['formulaperm_posts'], $language['formulaperm_threads'], $language['formulaperm_oltime'], $language['formulaperm_pageviews']);
  471. for($i = 1; $i <= 8; $i++) {
  472. $search[] = '$_DSESSION[\'extcredits'.$i.'\']';
  473. $replace[] = $extcredits[$i]['title'] ? $extcredits[$i]['title'] : $language['formulaperm_extcredits'].$i;
  474. }
  475. if($profilefields) {
  476. @include DISCUZ_ROOT.'./forumdata/cache/cache_profilefields.php';
  477. foreach($profilefields as $profilefield) {
  478. $search[] = '$memberformula[\''.$profilefield.'\']';
  479. $replace[] = !empty($_DCACHE['fields_optional'][$profilefield]) ? $_DCACHE['fields_optional'][$profilefield]['title'] : $_DCACHE['fields_required'][$profilefield]['title'];
  480. }
  481. }
  482. $i = 0;$usermsg = '';
  483. foreach($search as $s) {
  484. if(!in_array($s, array('$memberformula[\'regdate\']', '$memberformula[\'regip\']', '$memberformula[\'lastip\']'))) {
  485. $usermsg .= strexists($formula, $s) ? '<br />&nbsp;&nbsp;&nbsp;'.$replace[$i].': '.(@eval('return intval('.$s.');')) : '';
  486. } elseif($s == '$memberformula[\'regdate\']') {
  487. $usermsg .= strexists($formula, $s) ? '<br />&nbsp;&nbsp;&nbsp;'.$replace[$i].': '.(@eval('return '.$s.';')) : '';
  488. }
  489. $i++;
  490. }
  491. $search = array_merge($search, array('and', 'or', '>=', '<=', '=='));
  492. $replace = array_merge($replace, array('&nbsp;&nbsp;<b>'.$language['formulaperm_and'].'</b>&nbsp;&nbsp;', '&nbsp;&nbsp;<b>'.$language['formulaperm_or'].'</b>&nbsp;&nbsp;', '&ge;', '&le;', '='));
  493. $formulamessage = str_replace($search, $replace, $formula);
  494. } else {
  495. $formulamessage = nl2br(htmlspecialchars($permmessage));
  496. }
  497. if($type == 1 || $type == 2) {
  498. return $formulamessage;
  499. } elseif(!$wap) {
  500. if(!$permmessage) {
  501. showmessage('forum_permforum_nopermission', NULL, 'NOPERM');
  502. } else {
  503. showmessage('forum_permforum_nopermission_custommsg', NULL, 'NOPERM');
  504. }
  505. } else {
  506. wapmsg('forum_nopermission');
  507. }
  508. }
  509. return TRUE;
  510. }
  511. function getgroupid($uid, $group, &$member) {
  512. global $creditsformula, $db, $tablepre, $dzfeed_limit;
  513. if(!empty($creditsformula)) {
  514. $updatearray = array();
  515. eval("\$credits = round($creditsformula);");
  516. if($credits != $member['credits']) {
  517. $send_feed = false;
  518. if(is_array($dzfeed_limit['user_credit'])) foreach($dzfeed_limit['user_credit'] as $val) {
  519. if($member['credits'] < $val && $credits > $val) {
  520. $send_feed = true;
  521. $count = $val;
  522. }
  523. }
  524. if($send_feed) {
  525. $arg = $data = array();
  526. $arg['type'] = 'user_credit';
  527. $arg['uid'] = $uid;
  528. $arg['username'] = addslashes($member['username'] ? $member['username'] : $member['discuz_user']);
  529. $data['title']['actor'] = "<a href=\"space.php?uid={$arg[uid]}\" target=\"_blank\">".($member['username'] ? $member['username'] : $member['discuz_user'])."</a>";
  530. $data['title']['count'] = $count;
  531. add_feed($arg, $data);
  532. }
  533. $updatearray[] = "credits='$credits'";
  534. $member['credits'] = $credits;
  535. }
  536. if($group['type'] == 'member' && !($member['credits'] >= $group['creditshigher'] && $member['credits'] < $group['creditslower'])) {
  537. $query = $db->query("SELECT groupid FROM {$tablepre}usergroups WHERE type='member' AND $member[credits]>=creditshigher AND $member[credits]<creditslower LIMIT 1");
  538. if($db->num_rows($query)) {
  539. $newgroupid = $db->result($query, 0);
  540. $query = $db->query("SELECT groupid FROM {$tablepre}members WHERE uid='$uid'");
  541. $member['groupid'] = $db->result($query, 0);
  542. if($member['groupid'] != $newgroupid) {
  543. $member['groupid'] = $newgroupid;
  544. $updatearray[] = "groupid='$member[groupid]'";
  545. include language('notice');
  546. $grouptitle = $db->result_first("SELECT grouptitle FROM {$tablepre}usergroups WHERE groupid='$member[groupid]'");
  547. $data = array();
  548. $data['usergroup'] = "<a href=\"faq.php?action=grouppermission&searchgroupid={$member[groupid]}\" target=\"_blank\">{$grouptitle}</a>";
  549. $msg_template = $language['user_usergroup'];
  550. $message = transval($msg_template, $data);
  551. sendnotice($uid, $message, 'systempm');
  552. if(is_array($dzfeed_limit['user_usergroup']) && in_array($member['groupid'], $dzfeed_limit['user_usergroup'])) {
  553. $arg = $data = array();
  554. $arg['type'] = 'user_usergroup';
  555. $arg['uid'] = $uid;
  556. $arg['username'] = addslashes($member['username'] ? $member['username'] : $member['discuz_user']);
  557. $data['title']['actor'] = "<a href=\"space.php?uid={$arg[uid]}\" target=\"_blank\">".($member['username'] ? $member['username'] : $member['discuz_user'])."</a>";
  558. $data['title']['usergroup'] = "<a href=\"faq.php?action=grouppermission&searchgroupid={$member[groupid]}\" target=\"_blank\">{$grouptitle}</a>";
  559. add_feed($arg, $data);
  560. }
  561. }
  562. }
  563. }
  564. if($updatearray) {
  565. $db->query("UPDATE {$tablepre}members SET ".implode(', ', $updatearray)." WHERE uid='$uid'");
  566. }
  567. }
  568. return $member['groupid'];
  569. }
  570. function getrobot() {
  571. if(!defined('IS_ROBOT')) {
  572. $kw_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';
  573. $kw_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla';
  574. if(!strexists($_SERVER['HTTP_USER_AGENT'], 'http://') && preg_match("/($kw_browsers)/i", $_SERVER['HTTP_USER_AGENT'])) {
  575. define('IS_ROBOT', FALSE);
  576. } elseif(preg_match("/($kw_spiders)/i", $_SERVER['HTTP_USER_AGENT'])) {
  577. define('IS_ROBOT', TRUE);
  578. } else {
  579. define('IS_ROBOT', FALSE);
  580. }
  581. }
  582. return IS_ROBOT;
  583. }
  584. function get_home($uid) {
  585. $uid = sprintf("%05d", $uid);
  586. $dir1 = substr($uid, 0, -4);
  587. $dir2 = substr($uid, -4, 2);
  588. $dir3 = substr($uid, -2, 2);
  589. return $dir1.'/'.$dir2.'/'.$dir3;
  590. }
  591. function groupexpiry($terms) {
  592. $terms = is_array($terms) ? $terms : unserialize($terms);
  593. $groupexpiry = isset($terms['main']['time']) ? intval($terms['main']['time']) : 0;
  594. if(is_array($terms['ext'])) {
  595. foreach($terms['ext'] as $expiry) {
  596. if((!$groupexpiry && $expiry) || $expiry < $groupexpiry) {
  597. $groupexpiry = $expiry;
  598. }
  599. }
  600. }
  601. return $groupexpiry;
  602. }
  603. function ipaccess($ip, $accesslist) {
  604. return preg_match("/^(".str_replace(array("\r\n", ' '), array('|', ''), preg_quote($accesslist, '/')).")/", $ip);
  605. }
  606. function implodeids($array) {
  607. if(!empty($array)) {
  608. return "'".implode("','", is_array($array) ? $array : array($array))."'";
  609. } else {
  610. return '';
  611. }
  612. }
  613. function ipbanned($onlineip) {
  614. global $ipaccess, $timestamp, $cachelost;
  615. if($ipaccess && !ipaccess($onlineip, $ipaccess)) {
  616. return TRUE;
  617. }
  618. $cachelost .= (@include DISCUZ_ROOT.'./forumdata/cache/cache_ipbanned.php') ? '' : ' ipbanned';
  619. if(empty($_DCACHE['ipbanned'])) {
  620. return FALSE;
  621. } else {
  622. if($_DCACHE['ipbanned']['expiration'] < $timestamp) {
  623. @unlink(DISCUZ_ROOT.'./forumdata/cache/cache_ipbanned.php');
  624. }
  625. return preg_match("/^(".$_DCACHE['ipbanned']['regexp'].")$/", $onlineip);
  626. }
  627. }
  628. function isemail($email) {
  629. return strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $email);
  630. }
  631. function language($file, $templateid = 0, $tpldir = '') {
  632. $tpldir = $tpldir ? $tpldir : TPLDIR;
  633. $templateid = $templateid ? $templateid : TEMPLATEID;
  634. $languagepack = DISCUZ_ROOT.'./'.$tpldir.'/'.$file.'.lang.php';
  635. if(file_exists($languagepack)) {
  636. return $languagepack;
  637. } elseif($templateid != 1 && $tpldir != './templates/default') {
  638. return language($file, 1, './templates/default');
  639. } else {
  640. return FALSE;
  641. }
  642. }
  643. function modthreadkey($tid) {
  644. global $adminid, $discuz_user, $discuz_uid, $discuz_pw, $timestamp, $discuz_auth_key;
  645. return $adminid > 0 ? md5($discuz_user.$discuz_uid.$discuz_auth_key.substr($timestamp, 0, -7).$tid) : '';
  646. }
  647. function multi($num, $perpage, $curpage, $mpurl, $maxpages = 0, $page = 10, $autogoto = TRUE, $simple = FALSE) {
  648. global $maxpage;
  649. $ajaxtarget = !empty($_GET['ajaxtarget']) ? " ajaxtarget=\"".dhtmlspecialchars($_GET['ajaxtarget'])."\" " : '';
  650. if(defined('IN_ADMINCP')) {
  651. $shownum = $showkbd = TRUE;
  652. $lang['prev'] = '&lsaquo;&lsaquo;';
  653. $lang['next'] = '&rsaquo;&rsaquo;';
  654. } else {
  655. $shownum = $showkbd = FALSE;
  656. $lang['prev'] = '&nbsp';
  657. $lang['next'] = $GLOBALS['dlang']['nextpage'];
  658. }
  659. $multipage = '';
  660. $mpurl .= strpos($mpurl, '?') ? '&amp;' : '?';
  661. $realpages = 1;
  662. if($num > $perpage) {
  663. $offset = 2;
  664. $realpages = @ceil($num / $perpage);
  665. $pages = $maxpages && $maxpages < $realpages ? $maxpages : $realpages;
  666. if($page > $pages) {
  667. $from = 1;
  668. $to = $pages;
  669. } else {
  670. $from = $curpage - $offset;
  671. $to = $from + $page - 1;
  672. if($from < 1) {
  673. $to = $curpage + 1 - $from;
  674. $from = 1;
  675. if($to - $from < $page) {
  676. $to = $page;
  677. }
  678. } elseif($to > $pages) {
  679. $from = $pages - $page + 1;
  680. $to = $pages;
  681. }
  682. }
  683. $multipage = ($curpage - $offset > 1 && $pages > $page ? '<a href="'.$mpurl.'page=1" class="first"'.$ajaxtarget.'>1 ...</a>' : '').
  684. ($curpage > 1 && !$simple ? '<a href="'.$mpurl.'page='.($curpage - 1).'" class="prev"'.$ajaxtarget.'>'.$lang['prev'].'</a>' : '');
  685. for($i = $from; $i <= $to; $i++) {
  686. $multipage .= $i == $curpage ? '<strong>'.$i.'</strong>' :
  687. '<a href="'.$mpurl.'page='.$i.($ajaxtarget && $i == $pages && $autogoto ? '#' : '').'"'.$ajaxtarget.'>'.$i.'</a>';
  688. }
  689. $multipage .= ($to < $pages ? '<a href="'.$mpurl.'page='.$pages.'" class="last"'.$ajaxtarget.'>... '.$realpages.'</a>' : '').
  690. ($curpage < $pages && !$simple ? '<a href="'.$mpurl.'page='.($curpage + 1).'" class="next"'.$ajaxtarget.'>'.$lang['next'].'</a>' : '').
  691. ($showkbd && !$simple && $pages > $page && !$ajaxtarget ? '<kbd><input type="text" name="custompage" size="3" onkeydown="if(event.keyCode==13) {window.location=\''.$mpurl.'page=\'+this.value; return false;}" /></kbd>' : '');
  692. $multipage = $multipage ? '<div class="pages">'.($shownum && !$simple ? '<em>&nbsp;'.$num.'&nbsp;</em>' : '').$multipage.'</div>' : '';
  693. }
  694. $maxpage = $realpages;
  695. return $multipage;
  696. }
  697. function output() {
  698. if(defined('DISCUZ_OUTPUTED')) {
  699. return;
  700. }
  701. define('DISCUZ_OUTPUTED', 1);
  702. global $sid, $transsidstatus, $rewritestatus, $ftp, $advlist, $thread, $inajax, $forumdomains, $binddomains, $indexname;
  703. if($advlist && !defined('IN_ADMINCP') && !$inajax) {
  704. include template('adv');
  705. }
  706. funcstat();
  707. stat_code();
  708. if(($transsidstatus = empty($GLOBALS['_DCOOKIE']['sid']) && $transsidstatus) || $rewritestatus || ($binddomains && $forumdomains)) {
  709. $content = ob_get_contents();
  710. if($transsidstatus) {
  711. $searcharray = array
  712. (
  713. "/\<a(\s*[^\>]+\s*)href\=([\"|\']?)([^\"\'\s]+)/ies",
  714. "/(\<form.+?\>)/is"
  715. );
  716. $replacearray = array
  717. (
  718. "transsid('\\3','<a\\1href=\\2')",
  719. "\\1\n<input type=\"hidden\" name=\"sid\" value=\"$sid\" />"
  720. );
  721. $content = preg_replace($searcharray, $replacearray, $content);
  722. }
  723. if($binddomains && $forumdomains) {
  724. $bindsearcharray = $bindreplacearray = array();
  725. $indexname = basename($indexname);
  726. foreach($forumdomains as $fid => $domain) {
  727. $bindsearcharray[] = "href=\"forumdisplay.php?fid=$fid&amp;";
  728. $bindreplacearray[] = 'href="http://'.$domain.'/'.$indexname.'?';
  729. $bindsearcharray[] = "href=\"forumdisplay.php?fid=$fid";
  730. $bindreplacearray[] = 'href="http://'.$domain.'/'.$indexname;
  731. }
  732. $content = str_replace($bindsearcharray, $bindreplacearray, $content);
  733. }
  734. if($rewritestatus) {
  735. $searcharray = $replacearray = array();
  736. if($rewritestatus & 1) {
  737. $searcharray[] = "/\<a href\=\"forumdisplay\.php\?fid\=(\d+)(&amp;page\=(\d+))?\"([^\>]*)\>/e";
  738. $replacearray[] = "rewrite_forum('\\1', '\\3', '\\4')";
  739. }
  740. if($rewritestatus & 2) {
  741. $searcharray[] = "/\<a href\=\"viewthread\.php\?tid\=(\d+)(&amp;extra\=page\%3D(\d+))?(&amp;page\=(\d+))?\"([^\>]*)\>/e";
  742. $replacearray[] = "rewrite_thread('\\1', '\\5', '\\3', '\\6')";
  743. }
  744. if($rewritestatus & 4) {
  745. $searcharray[] = "/\<a href\=\"space\.php\?(uid\=(\d+)|username\=([^&]+?))\"([^\>]*)\>/e";
  746. $replacearray[] = "rewrite_space('\\2', '\\3', '\\4')";
  747. }
  748. if($rewritestatus & 8) {
  749. $searcharray[] = "/\<a href\=\"tag\.php\?name\=([^&]+?)\"([^\>]*)\>/e";
  750. $replacearray[] = "rewrite_tag('\\1', '\\2')";
  751. }
  752. $content = preg_replace($searcharray, $replacearray, $content);
  753. }
  754. ob_end_clean();
  755. $GLOBALS['gzipcompress'] ? ob_start('ob_gzhandler') : ob_start();
  756. echo $content;
  757. }
  758. if($ftp['connid']) {
  759. @ftp_close($ftp['connid']);
  760. }
  761. $ftp = array();
  762. if(defined('CACHE_FILE') && CACHE_FILE && !defined('CACHE_FORBIDDEN')) {
  763. global $cachethreaddir;
  764. if(diskfreespace(DISCUZ_ROOT.'./'.$cachethreaddir) > 1000000) {
  765. if($fp = @fopen(CACHE_FILE, 'w')) {
  766. flock($fp, LOCK_EX);
  767. fwrite($fp, empty($content) ? ob_get_contents() : $content);
  768. }
  769. @fclose($fp);
  770. chmod(CACHE_FILE, 0777);
  771. }
  772. }
  773. }
  774. function periodscheck($periods, $showmessage = 1) {
  775. global $timestamp, $disableperiodctrl, $_DCACHE, $banperiods;
  776. if(!$disableperiodctrl && $_DCACHE['settings'][$periods]) {
  777. $now = gmdate('G.i', $timestamp + $_DCACHE['settings']['timeoffset'] * 3600);
  778. foreach(explode("\r\n", str_replace(':', '.', $_DCACHE['settings'][$periods])) as $period) {
  779. list($periodbegin, $periodend) = explode('-', $period);
  780. if(($periodbegin > $periodend && ($now >= $periodbegin || $now < $periodend)) || ($periodbegin < $periodend && $now >= $periodbegin && $now < $periodend)) {
  781. $banperiods = str_replace("\r\n", ', ', $_DCACHE['settings'][$periods]);
  782. if($showmessage) {
  783. showmessage('period_nopermission', NULL, 'NOPERM');
  784. } else {
  785. return TRUE;
  786. }
  787. }
  788. }
  789. }
  790. return FALSE;
  791. }
  792. function quescrypt($questionid, $answer) {
  793. return $questionid > 0 && $answer != '' ? substr(md5($answer.md5($questionid)), 16, 8) : '';
  794. }
  795. function rewrite_thread($tid, $page = 0, $prevpage = 0, $extra = '') {
  796. return '<a href="thread-'.$tid.'-'.($page ? $page : 1).'-'.($prevpage && !IS_ROBOT ? $prevpage : 1).'.html"'.stripslashes($extra).'>';
  797. }
  798. function rewrite_forum($fid, $page = 0, $extra = '') {
  799. return '<a href="forum-'.$fid.'-'.($page ? $page : 1).'.html"'.stripslashes($extra).'>';
  800. }
  801. function rewrite_space($uid, $username, $extra = '') {
  802. $GLOBALS['rewritecompatible'] && $username = rawurlencode($username);
  803. return '<a href="space-'.($uid ? 'uid-'.$uid : 'username-'.$username).'.html"'.stripslashes($extra).'>';
  804. }
  805. function rewrite_tag($name, $extra = '') {
  806. $GLOBALS['rewritecompatible'] && $name = rawurlencode($name);
  807. return '<a href="tag-'.$name.'.html"'.stripslashes($extra).'>';
  808. }
  809. function random($length, $numeric = 0) {
  810. PHP_VERSION < '4.2.0' ? mt_srand((double)microtime() * 1000000) : mt_srand();
  811. $seed = base_convert(md5(print_r($_SERVER, 1).microtime()), 16, $numeric ? 10 : 35);
  812. $seed = $numeric ? (str_replace('0', '', $seed).'012340567890') : ($seed.'zZ'.strtoupper($seed));
  813. $hash = '';
  814. $max = strlen($seed) - 1;
  815. for($i = 0; $i < $length; $i++) {
  816. $hash .= $seed[mt_rand(0, $max)];
  817. }
  818. return $hash;
  819. }
  820. function request($cachekey, $fid = 0, $type = 0, $return = 0) {
  821. global $timestamp, $_DCACHE;
  822. $datalist = '';
  823. if($fid && CURSCRIPT == 'forumdisplay') {
  824. $specialfid = $GLOBALS['forum']['fid'];
  825. $key = $cachekey = empty($GLOBALS['infosidestatus']['f'.$specialfid][$type]) ? $GLOBALS['infosidestatus'][$type] : $GLOBALS['infosidestatus']['f'.$specialfid][$type];
  826. $cachekey .= '_fid'.$specialfid;
  827. } else {
  828. $specialfid = 0;
  829. if(!$type) {
  830. $key = $cachekey;
  831. } else {
  832. $key = $cachekey = $cachekey[$type];
  833. }
  834. }
  835. $cachefile = DISCUZ_ROOT.'./forumdata/cache/request_'.md5($cachekey).'.php';
  836. if(((@!include($cachefile)) || $expiration < $timestamp) && (!file_exists($cachefile.'.lock') || $timestamp - filemtime($cachefile.'.lock') > 3600)) {
  837. include_once DISCUZ_ROOT.'./forumdata/cache/cache_request.php';
  838. require_once DISCUZ_ROOT.'./include/request.func.php';
  839. parse_str($_DCACHE['request'][$key]['url'], $requestdata);
  840. $datalist = parse_request($requestdata, $cachefile, 0, $specialfid, $key);
  841. }
  842. if(!empty($nocachedata)) {
  843. include_once DISCUZ_ROOT.'./forumdata/cache/cache_request.php';
  844. require_once DISCUZ_ROOT.'./include/request.func.php';
  845. foreach($nocachedata as $key => $v) {
  846. $cachefile = DISCUZ_ROOT.'./forumdata/cache/request_'.md5($key).'.php';
  847. if(!file_exists($cachefile.'.lock')) {
  848. parse_str($_DCACHE['request'][$key]['url'], $requestdata);
  849. $datalist = str_replace($v, parse_request($requestdata, $cachefile, 0, $specialfid, $key), $datalist);
  850. }
  851. }
  852. }
  853. if(!$return) {
  854. echo $datalist;
  855. } else {
  856. return $datalist;
  857. }
  858. }
  859. function sendmail($email_to, $email_subject, $email_message, $email_from = '') {
  860. extract($GLOBALS, EXTR_SKIP);
  861. require DISCUZ_ROOT.'./include/sendmail.inc.php';
  862. }
  863. function sendnotice($toid, $message, $type, $extraid = 0, $actor = array(), $uselang = 1) {
  864. if(!$toid || $message === '') {
  865. return;
  866. }
  867. extract($GLOBALS, EXTR_SKIP);
  868. if($uselang) {
  869. include language('notice');
  870. if(isset($language[$message])) {
  871. eval("\$message = addslashes(\"".$language[$message]."\");");
  872. }
  873. }
  874. $typeid = $prompts[$type]['id'];
  875. if(!$typeid) {
  876. return;
  877. }
  878. $toids = explode(',', $toid);
  879. foreach($toids as $toid) {
  880. $keysadd = $valuesadd = $statnewnotice = '';
  881. if($extraid && $actor) {
  882. $promptmsg = $db->fetch_first("SELECT actor FROM {$tablepre}promptmsgs WHERE uid='$toid' AND typeid='$typeid' AND extraid='$extraid' LIMIT 1");
  883. if($promptmsg) {
  884. list($actorcount, $actors) = explode("\t", $promptmsg['actor']);
  885. $actorarray = array_unique(explode(',', $actors));
  886. if(!in_array($actor['user'], $actorarray)) {
  887. array_unshift($actorarray, $actor['user']);
  888. $actors = implode(',', array_slice($actorarray, 0, $actor['maxusers']));
  889. $actorcount++;
  890. }
  891. $statnewnotice = 1;
  892. $db->query("UPDATE {$tablepre}promptmsgs SET actor='".addslashes($actorcount."\t".$actors)."', dateline='$timestamp', new='1' WHERE uid='$toid' AND typeid='$typeid' AND extraid='$extraid'");
  893. } else {
  894. $statnewnotice = 1;
  895. $db->query("INSERT INTO {$tablepre}promptmsgs (typeid, uid, new, dateline, message, extraid, actor) VALUES ('$typeid', '$toid', '1', '$timestamp', '$message', '$extraid', '".addslashes("1\t".$actor['user'])."')");
  896. }
  897. } else {
  898. $statnewnotice = 1;
  899. $db->query("INSERT INTO {$tablepre}promptmsgs (typeid, uid, new, dateline, message) VALUES ('$typeid', '$toid', '1', '$timestamp', '$message')");
  900. }
  901. if($statnewnotice) {
  902. write_statlog('', 'action=counttype&typeid='.$typeid, '', '', 'notice.php');
  903. }
  904. $count = $db->result_first("SELECT count(*) FROM {$tablepre}promptmsgs WHERE uid='$toid' AND typeid='$typeid' AND new='1'");
  905. updateprompt($type, $toid, $count);
  906. }
  907. }
  908. function sendpm($toid, $subject, $message, $fromid = '') {
  909. if($fromid === '') {
  910. require_once DISCUZ_ROOT.'./uc_client/client.php';
  911. $fromid = $discuz_uid;
  912. }
  913. if($fromid) {
  914. uc_pm_send($fromid, $toid, $subject, $message);
  915. } else {
  916. global $promptkeys;
  917. if(in_array($subject, $promptkeys)) {
  918. $type = $subject;
  919. } else {
  920. extract($GLOBALS, EXTR_SKIP);
  921. require_once DISCUZ_ROOT.'./include/discuzcode.func.php';
  922. eval("\$message = addslashes(\"".$message."\");");
  923. $type = 'systempm';
  924. $message = '<div>'.$subject.' {time}<br />'.discuzcode($message, 1, 0).'</div>';
  925. }
  926. sendnotice($toid, $message, $type);
  927. }
  928. }
  929. function showmessage($message, $url_forward = '', $extra = '', $forwardtype = 0) {
  930. extract($GLOBALS, EXTR_SKIP);
  931. global $hookscriptmessage, $extrahead, $discuz_uid, $discuz_action, $debuginfo, $seccode, $seccodestatus, $fid, $tid, $charset, $show_message, $inajax, $_DCACHE, $advlist;
  932. define('CACHE_FORBIDDEN', TRUE);
  933. $hookscriptmessage = $show_message = $message;$messagehandle = 0;
  934. $msgforward = unserialize($_DCACHE['settings']['msgforward']);
  935. $refreshtime = intval($msgforward['refreshtime']);
  936. $refreshtime = empty($forwardtype) ? $refreshtime : ($refreshtime ? $refreshtime : 3);
  937. $msgforward['refreshtime'] = $refreshtime * 1000;
  938. $url_forward = empty($url_forward) ? '' : (empty($_DCOOKIE['sid']) && $transsidstatus ? transsid($url_forward) : $url_forward);
  939. $seccodecheck = $seccodestatus & 2;
  940. if($_DCACHE['settings']['funcsiteid'] && $_DCACHE['settings']['funckey'] && $funcstatinfo && !IS_ROBOT) {
  941. $statlogfile = DISCUZ_ROOT.'./forumdata/funcstat.log';
  942. if($fp = @fopen($statlogfile, 'a')) {
  943. @flock($fp, 2);
  944. if(is_array($funcstatinfo)) {
  945. $funcstatinfo = array_unique($funcstatinfo);
  946. foreach($funcstatinfo as $funcinfo) {
  947. fwrite($fp, funcstat_query($funcinfo, $message)."\n");
  948. }
  949. } else {
  950. fwrite($fp, funcstat_query($funcstatinfo, $message)."\n");
  951. }
  952. fclose($fp);
  953. $funcstatinfo = $GLOBALS['funcstatinfo'] = '';
  954. }
  955. }
  956. if(!defined('STAT_DISABLED') && STAT_ID > 0 && !IS_ROBOT) {
  957. write_statlog($message);
  958. }
  959. if($url_forward && (!empty($quickforward) || empty($inajax) && $msgforward['quick'] && $msgforward['messages'] && @in_array($message, $msgforward['messages']))) {
  960. updatesession();
  961. dheader("location: ".str_replace('&amp;', '&', $url_forward));
  962. }
  963. if(!empty($infloat)) {
  964. if($extra) {
  965. $messagehandle = $extra;
  966. }
  967. $extra = '';
  968. }
  969. if(in_array($extra, array('HALTED', 'NOPERM'))) {
  970. $discuz_action = 254;
  971. } else {
  972. $discuz_action = 255;
  973. }
  974. include language('messages');
  975. $vars = explode(':', $message);
  976. if(count($vars) == 2 && isset($scriptlang[$vars[0]][$vars[1]])) {
  977. eval("\$show_message = \"".str_replace('"', '\"', $scriptlang[$vars[0]][$vars[1]])."\";");
  978. } elseif(isset($language[$message])) {
  979. $pre = $inajax ? 'ajax_' : '';
  980. eval("\$show_message = \"".(isset($language[$pre.$message]) ? $language[$pre.$message] : $language[$message])."\";");
  981. unset($pre);
  982. }
  983. if(empty($infloat)) {
  984. $show_message .= $url_forward && empty($inajax) ? '<script>setTimeout("window.location.href =\''.$url_forward.'\';", '.$msgforward['refreshtime'].');</script>' : '';
  985. } elseif($handlekey) {
  986. $show_message = str_replace("'", "\'", $show_message);
  987. if($url_forward) {
  988. $show_message = "<script type=\"text/javascript\" reload=\"1\">\nif($('return_$handlekey')) $('return_$handlekey').className = 'onright';\nif(typeof submithandle_$handlekey =='function') {submithandle_$handlekey('$url_forward', '$show_message');} else {location.href='$url_forward'}\n</script>";
  989. } else {
  990. $show_message .= "<script type=\"text/javascript\" reload=\"1\">\nif(typeof messagehandle_$handlekey =='function') {messagehandle_$handlekey('$messagehandle', '$show_message');}\n</script>";
  991. }
  992. }
  993. if($advlist = array_merge($globaladvs ? $globaladvs['type'] : array(), $redirectadvs ? $redirectadvs['type'] : array())) {
  994. $advitems = ($globaladvs ? $globaladvs['items'] : array()) + ($redirectadvs ? $redirectadvs['items'] : array());
  995. foreach($advlist AS $type => $redirectadvs) {
  996. $advlist[$type] = $advitems[$redirectadvs[array_rand($redirectadvs)]];
  997. }
  998. }
  999. if($extra == 'NOPERM') {
  1000. include template('nopermission');
  1001. } else {
  1002. include template('showmessage');
  1003. }
  1004. dexit();
  1005. }
  1006. function showmessagenoperm($type, $fid) {
  1007. include DISCUZ_ROOT.'./forumdata/cache/cache_nopermission.php';
  1008. include DISCUZ_ROOT.'./forumdata/cache/cache_usergroups.php';
  1009. $v = $noperms[$fid][$type][$GLOBALS['groupid']][0];
  1010. $gids = $noperms[$fid][$type][$GLOBALS['groupid']][1];
  1011. $comma = $GLOBALS['permgroups'] = '';
  1012. foreach($gids as $gid) {
  1013. if($gid && $_DCACHE['usergroups'][$gid]) {
  1014. $GLOBALS['permgroups'] .= $comma.$_DCACHE['usergroups'][$gid]['grouptitle'];
  1015. $comma = ', ';
  1016. }
  1017. }
  1018. showmessage($type.'_'.$v.'_nopermission', NULL, 'NOPERM');
  1019. }
  1020. function site() {
  1021. return $_SERVER['HTTP_HOST'];
  1022. }
  1023. function strexists($haystack, $needle) {
  1024. return !(strpos($haystack, $needle) === FALSE);
  1025. }
  1026. function seccodeconvert(&$seccode) {
  1027. global $seccodedata, $charset;
  1028. $seccode = substr($seccode, -6);
  1029. if($seccodedata['type'] == 1) {
  1030. include_once language('seccode');
  1031. $len = strtoupper($charset) == 'GBK' ? 2 : 3;
  1032. $code = array(substr($seccode, 0, 3), substr($seccode, 3, 3));
  1033. $seccode = '';
  1034. for($i = 0; $i < 2; $i++) {
  1035. $seccode .= substr($lang['chn'], $code[$i] * $len, $len);
  1036. }
  1037. return;
  1038. } elseif($seccodedata['type'] == 3) {
  1039. $s = sprintf('%04s', base_convert($seccode, 10, 20));
  1040. $seccodeunits = 'CEFHKLMNOPQRSTUVWXYZ';
  1041. } else {
  1042. $s = sprintf('%04s', base_convert($seccode, 10, 24));
  1043. $seccodeunits = 'BCEFGHJKMPQRTVWXY2346789';
  1044. }
  1045. $seccode = '';
  1046. for($i = 0; $i < 4; $i++) {
  1047. $unit = ord($s{$i});
  1048. $seccode .= ($unit >= 0x30 && $unit <= 0x39) ? $seccodeunits[$unit - 0x30] : $seccodeunits[$unit - 0x57];
  1049. }
  1050. }
  1051. function submitcheck($var, $allowget = 0, $seccodecheck = 0, $secqaacheck = 0) {
  1052. if(empty($GLOBALS[$var])) {
  1053. return FALSE;
  1054. } else {
  1055. global $_SERVER, $seclevel, $seccode, $seccodedata, $seccodeverify, $secanswer, $_DCACHE, $_DCOOKIE, $timestamp, $discuz_uid;
  1056. if($allowget || ($_SERVER['REQUEST_METHOD'] == 'POST' && $GLOBALS['formhash'] == formhash() && empty($_SERVER['HTTP_X_FLASH_VERSION']) && (empty($_SERVER['HTTP_REFERER']) ||
  1057. preg_replace("/https?:\/\/([^\:\/]+).*/i", "\\1", $_SERVER['HTTP_REFERER']) == preg_replace("/([^\:]+).*/", "\\1", $_SERVER['HTTP_HOST'])))) {
  1058. if($seccodecheck) {
  1059. if(!$seclevel) {
  1060. $key = $seccodedata['type'] != 3 ? '' : $_DCACHE['settings']['authkey'].date('Ymd');
  1061. list($seccode, $expiration, $seccodeuid) = explode("\t", authcode($_DCOOKIE['secc'], 'DECODE', $key));
  1062. if($seccodeuid != $discuz_uid || $timestamp - $expiration > 600) {
  1063. showmessage('submit_seccode_invalid');
  1064. }
  1065. dsetcookie('secc', '');
  1066. } else {
  1067. $tmp = substr($seccode, 0, 1);
  1068. }
  1069. seccodeconvert($seccode);
  1070. if(strtoupper($seccodeverify) != $seccode) {
  1071. showmessage('submit_seccode_invalid');
  1072. }
  1073. $seclevel && $seccode = random(6, 1) + $tmp * 1000000;
  1074. }
  1075. if($secqaacheck) {
  1076. if(!$seclevel) {
  1077. list($seccode, $expiration, $seccodeuid) = explode("\t", authcode($_DCOOKIE['secq'], 'DECODE'));
  1078. if($seccodeuid != $discuz_uid || $timestamp - $expiration > 600) {
  1079. showmessage('submit_secqaa_invalid');
  1080. }
  1081. dsetcookie('secq', '');
  1082. }
  1083. require_once DISCUZ_ROOT.'./forumdata/cache/cache_secqaa.php';
  1084. if(md5($secanswer) != $_DCACHE['secqaa'][substr($seccode, 0, 1)]['answer']) {
  1085. showmessage('submit_secqaa_invalid');
  1086. }
  1087. $seclevel && $seccode = random(1, 1) * 1000000 + substr($seccode, -6);
  1088. }
  1089. return TRUE;
  1090. } else {
  1091. showmessage('submit_invalid');
  1092. }
  1093. }
  1094. }
  1095. function template($file, $templateid = 0, $tpldir = '') {
  1096. global $inajax, $hookscript;
  1097. if(strexists($file, ':')) {
  1098. list($templateid, $file) = explode(':', $file);
  1099. $tpldir = './plugins/'.$templateid.'/templates';
  1100. }
  1101. $file .= $inajax && ($file == 'header' || $file == 'footer') ? '_ajax' : '';
  1102. $tpldir = $tpldir ? $tpldir : TPLDIR;
  1103. $templateid = $templateid ? $templateid : TEMPLATEID;
  1104. $tplfile = DISCUZ_ROOT.'./'.$tpldir.'/'.$file.'.htm';
  1105. $filebak = $file;
  1106. $file == 'header' && CURSCRIPT && $file = 'header_'.CURSCRIPT;
  1107. $objfile = DISCUZ_ROOT.'./forumdata/templates/'.STYLEID.'_'.$templateid.'_'.$file.'.tpl.php';
  1108. if($templateid != 1 && !file_exists($tplfile)) {
  1109. $tplfile = DISCUZ_ROOT.'./templates/default/'.$filebak.'.htm';
  1110. }
  1111. @checktplrefresh($tplfile, $tplfile, filemtime($objfile), $templateid, $tpldir);
  1112. return $objfile;
  1113. }
  1114. function transsid($url, $tag = '', $wml = 0) {
  1115. global $sid;
  1116. $tag = stripslashes($tag);
  1117. if(!$tag || (!preg_match("/^(http:\/\/|mailto:|#|javascript)/i", $url) && !strpos($url, 'sid='))) {
  1118. if($pos = strpos($url, '#')) {
  1119. $urlret = substr($url, $pos);
  1120. $url = substr($url, 0, $pos);
  1121. } else {
  1122. $urlret = '';
  1123. }
  1124. $url .= (strpos($url, '?') ? ($wml ? '&amp;' : '&') : '?').'sid='.$sid.$urlret;
  1125. }
  1126. return $tag.$url;
  1127. }
  1128. function typeselect($curtypeid = 0) {
  1129. if($threadtypes = $GLOBALS['forum']['threadtypes']) {
  1130. $html = '<select name="typeid" id="typeid"><option value="0">&nbsp;</option>';
  1131. foreach($threadtypes['types'] as $typeid => $name) {
  1132. $html .= '<option value="'.$typeid.'" '.($curtypeid == $typeid ? 'selected' : '').'>'.strip_tags($name).'</option>';
  1133. }
  1134. $html .= '</select>';
  1135. return $html;
  1136. } else {
  1137. return '';
  1138. }
  1139. }
  1140. function sortselect($cursortid = 0, $modelid = 0, $onchange = '') {
  1141. global $fid, $sid, $extra;
  1142. if($threadsorts = $GLOBALS['forum']['threadsorts']) {
  1143. $onchange = $onchange ? $onchange : "onchange=\"ajaxget('post.php?action=threadsorts&sortid='+this.options[this.selectedIndex].value+'&fid=$fid&sid=$sid', 'threadsorts', 'threadsortswait')\"";
  1144. $selecthtml = '';
  1145. foreach($threadsorts['types'] as $sortid => $name) {
  1146. $sorthtml = '<option value="'.$sortid.'" '.($cursortid == $sortid ? 'selected="selected"' : '').' class="special">'.strip_tags($name).'</option>';
  1147. $selecthtml .= $modelid ? ($threadsorts['modelid'][$sortid] == $modelid ? $sorthtml : '') : $sorthtml;
  1148. }
  1149. $hiddeninput = $cursortid ? '<input type="hidden" name="sortid" value="'.$cursortid.'" />' : '';
  1150. $html = '<select name="sortid" '.$onchange.'><option value="0">&nbsp;</option>'.$selecthtml.'</select><span id="threadsortswait"></span>'.$hiddeninput;
  1151. return $html;
  1152. } else {
  1153. return '';
  1154. }
  1155. }
  1156. function updatecredits($uids, $creditsarray, $coef = 1, $extrasql = '') {
  1157. if($uids && ((!empty($creditsarray) && is_array($creditsarray)) || $extrasql)) {
  1158. global $db, $tablepre, $discuz_uid, $creditnotice, $cookiecredits;
  1159. $self = $creditnotice && $uids == $discuz_uid;
  1160. if($self && !isset($cookiecredits)) {
  1161. $cookiecredits = !empty($_COOKIE['discuz_creditnotice']) ? explode('D', $_COOKIE['discuz_creditnotice']) : array_fill(0, 9, 0);
  1162. }
  1163. $creditsadd = $comma = '';
  1164. foreach($creditsarray as $id => $addcredits) {
  1165. $creditsadd .= $comma.'extcredits'.$id.'=extcredits'.$id.'+('.intval($addcredits).')*('.$coef.')';
  1166. $comma = ', ';
  1167. if($self) {
  1168. $cookiecredits[$id] += intval($addcredits) * $coef;
  1169. }
  1170. }
  1171. if($self) {
  1172. dsetcookie('discuz_creditnotice', implode('D', $cookiecredits).'D'.$discuz_uid, 43200, 0);
  1173. }
  1174. if($creditsadd || $extrasql) {
  1175. $db->query("UPDATE {$tablepre}members SET $creditsadd ".($creditsadd && $extrasql ? ', ' : '')." $extrasql WHERE uid IN ('$uids')", 'UNBUFFERED');
  1176. }
  1177. }
  1178. }
  1179. function updatesession() {
  1180. if(!empty($GLOBALS['sessionupdated'])) {
  1181. return TRUE;
  1182. }
  1183. global $db, $tablepre, $sessionexists, $sessionupdated, $sid, $onlineip, $discuz_uid, $discuz_user, $timestamp, $lastactivity, $seccode,
  1184. $pvfrequence, $spageviews, $lastolupdate, $oltimespan, $onlinehold, $groupid, $styleid, $invisible, $discuz_action, $fid, $tid;
  1185. $fid = intval($fid);
  1186. $tid = intval($tid);
  1187. if($oltimespan && $discuz_uid && $lastactivity && $timestamp - ($lastolupdate ? $lastolupdate : $lastactivity) > $oltimespan * 60) {
  1188. $lastolupdate = $timestamp;
  1189. $db->query("UPDATE {$tablepre}onlinetime SET total=total+'$oltimespan', thismonth=thismonth+'$oltimespan', lastupdate='$timestamp' WHERE uid='$discuz_uid' AND lastupdate<='".($timestamp - $oltimespan * 60)."'");
  1190. if(!$db->affected_rows()) {
  1191. $db->query("INSERT INTO {$tablepre}onlinetime (uid, thismonth, total, lastupdate)
  1192. VALUES ('$discuz_uid', '$oltimespan', '$oltimespan', '$timestamp')", 'SILENT');
  1193. }
  1194. } else {
  1195. $lastolupdate = intval($lastolupdate);
  1196. }
  1197. if($sessionexists == 1) {
  1198. if($pvfrequence && $discuz_uid) {
  1199. if($spageviews >= $pvfrequence) {
  1200. $pageviewsadd = ', pageviews=\'0\'';
  1201. $db->query("UPDATE {$tablepre}members SET pageviews=pageviews+'$spageviews' WHERE uid='$discuz_uid'", 'UNBUFFERED');
  1202. } else {
  1203. $pageviewsadd = ', pageviews=pageviews+1';
  1204. }
  1205. } else {
  1206. $pageviewsadd = '';
  1207. }
  1208. $db->query("UPDATE {$tablepre}sessions SET uid='$discuz_uid', us…

Large files files are truncated, but you can click here to view the full file