PageRenderTime 72ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/source/module/forum/forum_misc.php

https://github.com/jinbo51/DiscuzX
PHP | 1806 lines | 1578 code | 222 blank | 6 comment | 562 complexity | c5b88d9f2fc8d84c5ce3dd83d9b02536 MD5 | raw file
Possible License(s): 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-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: forum_misc.php 33347 2013-05-30 08:24:40Z jeffjzhang $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. define('NOROBOT', TRUE);
  12. require_once libfile('function/post');
  13. $feed = array();
  14. if($_GET['action'] == 'paysucceed') {
  15. $orderid = trim($_GET['orderid']);
  16. $url = !empty($orderid) ? 'forum.php?mod=trade&orderid='.$orderid : 'home.php?mod=spacecp&ac=credit';
  17. showmessage('payonline_succeed', $url);
  18. } elseif($_GET['action'] == 'nav') {
  19. require_once libfile('misc/forumselect', 'include');
  20. exit;
  21. } elseif($_GET['action'] == 'attachcredit') {
  22. if($_GET['formhash'] != FORMHASH) {
  23. showmessage('undefined_action', NULL);
  24. }
  25. $aid = intval($_GET['aid']);
  26. $attach = C::t('forum_attachment_n')->fetch('aid:'.$aid, $aid);
  27. $thread = C::t('forum_thread')->fetch_by_tid_displayorder($attach['tid'], 0);
  28. checklowerlimit('getattach', 0, 1, $thread['fid']);
  29. $getattachcredits = updatecreditbyaction('getattach', $_G['uid'], array(), '', 1, 1, $thread['fid']);
  30. $_G['policymsg'] = $p = '';
  31. if($getattachcredits['updatecredit']) {
  32. if($getattachcredits['updatecredit']) for($i = 1;$i <= 8;$i++) {
  33. if($policy = $getattachcredits['extcredits'.$i]) {
  34. $_G['policymsg'] .= $p.($_G['setting']['extcredits'][$i]['img'] ? $_G['setting']['extcredits'][$i]['img'].' ' : '').$_G['setting']['extcredits'][$i]['title'].' '.$policy.' '.$_G['setting']['extcredits'][$i]['unit'];
  35. $p = ', ';
  36. }
  37. }
  38. }
  39. $ck = substr(md5($aid.TIMESTAMP.md5($_G['config']['security']['authkey'])), 0, 8);
  40. $aidencode = aidencode($aid, 0, $attach['tid']);
  41. showmessage('attachment_credit', "forum.php?mod=attachment&aid=$aidencode&ck=$ck", array('policymsg' => $_G['policymsg'], 'filename' => $attach['filename']), array('redirectmsg' => 1, 'login' => 1));
  42. } elseif($_GET['action'] == 'attachpay') {
  43. $aid = intval($_GET['aid']);
  44. if(!$aid) {
  45. showmessage('parameters_error');
  46. } elseif(!isset($_G['setting']['extcredits'][$_G['setting']['creditstransextra'][1]])) {
  47. showmessage('credits_transaction_disabled');
  48. } elseif(!$_G['uid']) {
  49. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  50. } else {
  51. $attachtable = !empty($_GET['tid']) ? 'tid:'.dintval($_GET['tid']) : 'aid:'.$aid;
  52. $attach = C::t('forum_attachment_n')->fetch($attachtable, $aid);
  53. $attachmember = getuserbyuid($attach['uid']);
  54. $attach['author'] = $attachmember['username'];
  55. if($attach['price'] <= 0) {
  56. showmessage('undefined_action');
  57. }
  58. }
  59. if($attach['readperm'] && $attach['readperm'] > $_G['group']['readaccess']) {
  60. showmessage('attachment_forum_nopermission', NULL, array(), array('login' => 1));
  61. }
  62. $balance = getuserprofile('extcredits'.$_G['setting']['creditstransextra'][1]);
  63. $status = $balance < $attach['price'] ? 1 : 0;
  64. if($_G['adminid'] == 3) {
  65. $fid = C::t('forum_thread')->fetch($attach['tid']);
  66. $fid = $fid['fid'];
  67. $ismoderator = C::t('forum_moderator')->fetch_uid_by_fid_uid($fid, $_G['uid']);
  68. } elseif(in_array($_G['adminid'], array(1, 2))) {
  69. $ismoderator = 1;
  70. } else {
  71. $ismoderator = 0;
  72. }
  73. $exemptvalue = $ismoderator ? 64 : 8;
  74. if($_G['uid'] == $attach['uid'] || $_G['group']['exempt'] & $exemptvalue) {
  75. $status = 2;
  76. } else {
  77. $payrequired = $_G['uid'] ? !C::t('common_credit_log')->count_by_uid_operation_relatedid($_G['uid'], 'BAC', $attach['aid']) : 1;
  78. $status = $payrequired ? $status : 2;
  79. }
  80. $balance = $status != 2 ? $balance - $attach['price'] : $balance;
  81. $sidauth = rawurlencode(authcode($_G['sid'], 'ENCODE', $_G['authkey']));
  82. $aidencode = aidencode($aid, 0, $attach['tid']);
  83. if(C::t('common_credit_log')->count_by_uid_operation_relatedid($_G['uid'], 'BAC', $aid)) {
  84. showmessage('attachment_yetpay', "forum.php?mod=attachment&aid=$aidencode", array(), array('redirectmsg' => 1));
  85. }
  86. $attach['netprice'] = $status != 2 ? round($attach['price'] * (1 - $_G['setting']['creditstax'])) : 0;
  87. $lockid = 'attachpay_'.$_G['uid'];
  88. if(!submitcheck('paysubmit')) {
  89. include template('forum/attachpay');
  90. } elseif(!discuz_process::islocked($lockid)) {
  91. if(!empty($_GET['buyall'])) {
  92. $aids = $prices = array();
  93. $tprice = 0;
  94. foreach(C::t('forum_attachment_n')->fetch_all_by_id('aid:'.$aid, 'pid', $attach['pid'], '', false, true) as $tmp) {
  95. $aids[$tmp['aid']] = $tmp['aid'];
  96. $prices[$tmp['aid']] = $status != 2 ? array($tmp['price'], round($tmp['price'] * (1 - $_G['setting']['creditstax']))) : array(0, 0);
  97. }
  98. if($aids) {
  99. foreach(C::t('common_credit_log')->fetch_all_by_uid_operation_relatedid($_G['uid'], 'BAC', $aids) as $tmp) {
  100. unset($aids[$tmp['relatedid']]);
  101. }
  102. }
  103. foreach($aids as $aid) {
  104. $tprice += $prices[$aid][0];
  105. }
  106. $status = getuserprofile('extcredits'.$_G['setting']['creditstransextra'][1]) < $tprice ? 1 : 0;
  107. } else {
  108. $aids = array($aid);
  109. $prices[$aid] = $status != 2 ? array($attach['price'], $attach['netprice']) : array(0, 0);
  110. }
  111. if($status == 1) {
  112. showmessage('credits_balance_insufficient', '', array('title' => $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][1]]['title'], 'minbalance' => $attach['price']));
  113. }
  114. foreach($aids as $aid) {
  115. $updateauthor = 1;
  116. $authorEarn = $prices[$aid][1];
  117. if($_G['setting']['maxincperthread'] > 0) {
  118. $extcredit = 'extcredits'.$_G['setting']['creditstransextra'][1];
  119. $alog = C::t('common_credit_log')->count_credit_by_uid_operation_relatedid($attach['uid'], 'SAC', $aid, $_G['setting']['creditstransextra'][1]);
  120. if($alog >= $_G['setting']['maxincperthread']) {
  121. $updateauthor = 0;
  122. } else {
  123. $authorEarn = min($_G['setting']['maxincperthread'] - $alog['credit'], $prices[$aid][1]);
  124. }
  125. }
  126. if($updateauthor) {
  127. updatemembercount($attach['uid'], array($_G['setting']['creditstransextra'][1] => $authorEarn), 1, 'SAC', $aid);
  128. }
  129. updatemembercount($_G['uid'], array($_G['setting']['creditstransextra'][1] => -$prices[$aid][0]), 1, 'BAC', $aid);
  130. $aidencode = aidencode($aid, 0, $_GET['tid']);
  131. }
  132. discuz_process::unlock($lockid);
  133. if(count($aids) > 1) {
  134. showmessage('attachment_buyall', 'forum.php?mod=redirect&goto=findpost&ptid='.$attach['tid'].'&pid='.$attach['pid']);
  135. } else {
  136. $_G['forum_attach_filename'] = $attach['filename'];
  137. showmessage('attachment_buy', "forum.php?mod=attachment&aid=$aidencode", array('filename' => $_G['forum_attach_filename']), array('redirectmsg' => 1));
  138. }
  139. }
  140. } elseif($_GET['action'] == 'viewattachpayments') {
  141. $aid = intval($_GET['aid']);
  142. $extcreditname = 'extcredits'.$_G['setting']['creditstransextra'][1];
  143. $loglist = array();
  144. $logs = C::t('common_credit_log')->fetch_all_by_uid_operation_relatedid(0, 'BAC', $aid);
  145. $luids = array();
  146. foreach($logs as $log) {
  147. $luids[$log['uid']] = $log['uid'];
  148. }
  149. $members = C::t('common_member')->fetch_all($luids);
  150. foreach($logs as $log) {
  151. $log['username'] = $members[$log['uid']]['username'];
  152. $log['dateline'] = dgmdate($log['dateline'], 'u');
  153. $log[$extcreditname] = abs($log[$extcreditname]);
  154. $loglist[] = $log;
  155. }
  156. include template('forum/attachpay_view');
  157. } elseif($_GET['action'] == 'getonlines') {
  158. $num = C::app()->session->count();
  159. showmessage($num);
  160. } elseif($_GET['action'] == 'upload') {
  161. $type = !empty($_GET['type']) && in_array($_GET['type'], array('image', 'file')) ? $_GET['type'] : 'image';
  162. $attachexts = $imgexts = '';
  163. $_G['group']['allowpostattach'] = $_G['forum']['allowpostattach'] != -1 && ($_G['forum']['allowpostattach'] == 1 || (!$_G['forum']['postattachperm'] && $_G['group']['allowpostattach']) || ($_G['forum']['postattachperm'] && forumperm($_G['forum']['postattachperm'])));
  164. $_G['group']['allowpostimage'] = $_G['forum']['allowpostimage'] != -1 && ($_G['forum']['allowpostimage'] == 1 || (!$_G['forum']['postimageperm'] && $_G['group']['allowpostimage']) || ($_G['forum']['postimageperm'] && forumperm($_G['forum']['postimageperm'])));
  165. $_G['group']['attachextensions'] = $_G['forum']['attachextensions'] ? $_G['forum']['attachextensions'] : $_G['group']['attachextensions'];
  166. if($_G['group']['attachextensions']) {
  167. $imgexts = explode(',', str_replace(' ', '', $_G['group']['attachextensions']));
  168. $imgexts = array_intersect(array('jpg','jpeg','gif','png','bmp'), $imgexts);
  169. $imgexts = implode(', ', $imgexts);
  170. } else {
  171. $imgexts = 'jpg, jpeg, gif, png, bmp';
  172. }
  173. if($type == 'image' && (!$_G['group']['allowpostimage'] || !$imgexts)) {
  174. showmessage('no_privilege_postimage');
  175. }
  176. if($type == 'file' && !$_G['group']['allowpostattach']) {
  177. showmessage('no_privilege_postattach');
  178. }
  179. include template('forum/upload');
  180. } elseif($_GET['action'] == 'comment') {
  181. if(!$_G['setting']['commentnumber']) {
  182. showmessage('postcomment_closed');
  183. }
  184. $thread = C::t('forum_thread')->fetch($_GET['tid']);
  185. if($thread['closed'] && !$_G['forum']['ismoderator']) {
  186. showmessage('thread_closed');
  187. }
  188. $post = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['pid']);
  189. if($_G['group']['allowcommentitem'] && !empty($_G['uid']) && $post['authorid'] != $_G['uid']) {
  190. $thread = C::t('forum_thread')->fetch($post['tid']);
  191. $itemi = $thread['special'];
  192. if($thread['special'] > 0) {
  193. if($thread['special'] == 2){
  194. $thread['special'] = $post['first'] || C::t('forum_trade')->check_goods($post['pid']) ? 2 : 0;
  195. } elseif($thread['special'] == 127) {
  196. $thread['special'] = $_GET['special'];
  197. } else {
  198. $thread['special'] = $post['first'] ? $thread['special'] : 0;
  199. }
  200. }
  201. $_G['setting']['commentitem'] = $_G['setting']['commentitem'][$thread['special']];
  202. if($thread['special'] == 0) {
  203. loadcache('forums');
  204. if($_G['cache']['forums'][$post['fid']]['commentitem']) {
  205. $_G['setting']['commentitem'] = $_G['cache']['forums'][$post['fid']]['commentitem'];
  206. }
  207. }
  208. if($_G['setting']['commentitem'] && !C::t('forum_postcomment')->count_by_pid($_GET['pid'], $_G['uid'], 1)) {
  209. $commentitem = explode("\n", $_G['setting']['commentitem']);
  210. }
  211. }
  212. if(!$post || !($_G['setting']['commentpostself'] || $post['authorid'] != $_G['uid']) || !(($post['first'] && $_G['setting']['commentfirstpost'] && in_array($_G['group']['allowcommentpost'], array(1, 3)) || (!$post['first'] && in_array($_G['group']['allowcommentpost'], array(2, 3)))))) {
  213. showmessage('postcomment_error');
  214. }
  215. $extra = !empty($_GET['extra']) ? rawurlencode($_GET['extra']) : '';
  216. $seccodecheck = ($_G['setting']['seccodestatus'] & 4) && (!$_G['setting']['seccodedata']['minposts'] || getuserprofile('posts') < $_G['setting']['seccodedata']['minposts']);
  217. $secqaacheck = $_G['setting']['secqaa']['status'] & 2 && (!$_G['setting']['secqaa']['minposts'] || getuserprofile('posts') < $_G['setting']['secqaa']['minposts']);
  218. include template('forum/comment');
  219. } elseif($_GET['action'] == 'commentmore') {
  220. if(!$_G['setting']['commentnumber'] || !$_G['inajax']) {
  221. showmessage('postcomment_closed');
  222. }
  223. require_once libfile('function/discuzcode');
  224. $commentlimit = intval($_G['setting']['commentnumber']);
  225. $page = max(1, $_G['page']);
  226. $start_limit = ($page - 1) * $commentlimit;
  227. $comments = array();
  228. foreach(C::t('forum_postcomment')->fetch_all_by_search(null, $_GET['pid'], null, null, null, null, null, $start_limit, $commentlimit) as $comment) {
  229. $comment['avatar'] = avatar($comment['authorid'], 'small');
  230. $comment['dateline'] = dgmdate($comment['dateline'], 'u');
  231. $comment['comment'] = str_replace(array('[b]', '[/b]', '[/color]'), array('<b>', '</b>', '</font>'), preg_replace("/\[color=([#\w]+?)\]/i", "<font color=\"\\1\">", $comment['comment']));
  232. $comments[] = $comment;
  233. }
  234. $totalcomment = C::t('forum_postcomment')->fetch_standpoint_by_pid($_GET['pid']);
  235. $totalcomment = $totalcomment['comment'];
  236. $totalcomment = preg_replace('/<i>([\.\d]+)<\/i>/e', "'<i class=\"cmstarv\" style=\"background-position:20px -'.(intval(\\1) * 16).'px\">'.sprintf('%1.1f', \\1).'</i>'.(\$cic++ % 2 ? '<br />' : '');", $totalcomment);
  237. $count = C::t('forum_postcomment')->count_by_search(null, $_GET['pid']);
  238. $multi = multi($count, $commentlimit, $page, "forum.php?mod=misc&action=commentmore&tid=$_G[tid]&pid=$_GET[pid]");
  239. include template('forum/comment_more');
  240. } elseif($_GET['action'] == 'postappend') {
  241. if(!$_G['setting']['postappend']) {
  242. showmessage('postappend_not_open');
  243. }
  244. $post = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['pid']);
  245. if($post['authorid'] != $_G['uid']) {
  246. showmessage('postappend_only_yourself');
  247. }
  248. if(submitcheck('postappendsubmit')) {
  249. $message = censor($_GET['postappendmessage']);
  250. $sppos = 0;
  251. if($post['first'] && strexists($post['message'], chr(0).chr(0).chr(0))) {
  252. $sppos = strpos($post['message'], chr(0).chr(0).chr(0));
  253. $specialextra = substr($post['message'], $sppos + 3);
  254. $post['message'] = substr($post['message'], 0, $sppos);
  255. }
  256. $message = $post['message'] . "\n\n[b]".lang('forum/misc', 'postappend_content')." (".dgmdate(TIMESTAMP)."):[/b]\n$message";
  257. if($sppos) {
  258. $message .= chr(0).chr(0).chr(0).$specialextra;
  259. }
  260. require_once libfile('function/post');
  261. $bbcodeoff = checkbbcodes($message, 0);
  262. C::t('forum_post')->update('tid:'.$_G['tid'], $_GET['pid'], array(
  263. 'message' => $message,
  264. 'bbcodeoff' => $bbcodeoff,
  265. ));
  266. showmessage('postappend_add_succeed', "forum.php?mod=viewthread&tid=$post[tid]&pid=$post[pid]&page=$_GET[page]&extra=$_GET[extra]#pid$post[pid]", array('tid' => $post['tid'], 'pid' => $post['pid']));
  267. } else {
  268. include template('forum/postappend');
  269. }
  270. } elseif($_GET['action'] == 'pubsave') {
  271. $return = threadpubsave($_G['tid']);
  272. if($return > 0) {
  273. showmessage('post_newthread_succeed', dreferer(), array('coverimg' => ''));
  274. } elseif($return == -1) {
  275. showmessage('post_newthread_mod_succeed', dreferer(), array('coverimg' => ''));
  276. } elseif($return == -2) {
  277. showmessage('post_reply_mod_succeed', dreferer());
  278. } else {
  279. showmessage('thread_nonexistence');
  280. }
  281. } elseif($_GET['action'] == 'loadsave') {
  282. $message = '&nbsp;';
  283. $savepost = C::t('forum_post')->fetch(0, $_GET['pid']);
  284. if($savepost) {
  285. $message = $savepost['message'];
  286. if($_GET['type']) {
  287. require_once libfile('function/discuzcode');
  288. $message = discuzcode($message, $savepost['smileyoff'], $savepost['bbcodeoff'], $savepost['htmlon']);
  289. }
  290. $message = $message ? $message : '&nbsp;';
  291. }
  292. include template('common/header_ajax');
  293. echo $message;
  294. include template('common/footer_ajax');
  295. exit;
  296. } elseif($_GET['action'] == 'replynotice') {
  297. $tid = intval($_GET['tid']);
  298. $status = $_GET['op'] == 'ignore' ? 0 : 1;
  299. if(!empty($tid)) {
  300. $thread = C::t('forum_thread')->fetch_by_tid_displayorder($tid, 0);
  301. if($thread['authorid'] == $_G['uid']) {
  302. $thread['status'] = setstatus(6, $status, $thread['status']);
  303. C::t('forum_thread')->update($tid, array('status'=>$thread['status']), true);
  304. showmessage('replynotice_success_'.$status);
  305. }
  306. }
  307. showmessage('replynotice_error', 'forum.php?mod=viewthread&tid='.$tid);
  308. } elseif($_GET['action'] == 'removeindexheats') {
  309. if($_G['adminid'] != 1) {
  310. showmessage('no_privilege_indexheats');
  311. }
  312. C::t('forum_thread')->update($_G['tid'], array('heats'=>0));
  313. require_once libfile('function/cache');
  314. updatecache('heats');
  315. dheader('Location: '.dreferer());
  316. } elseif($_GET['action'] == 'showdarkroom') {
  317. include_once libfile('class/member');
  318. if($_G['setting']['darkroom']) {
  319. $limit = $_G['tpp'];
  320. $cid = $_GET['cid'] ? dintval($_GET['cid']) : 0;
  321. $crimelist = array();
  322. $i = 0;
  323. foreach(C::t('common_member_crime')->fetch_all_by_cid($cid, array(4, 5), $limit) as $crime) {
  324. $i++;
  325. $cid = $crime['cid'];
  326. if(isset($crimelist[$crime['uid']])) {
  327. continue;
  328. }
  329. $crime['action'] = lang('forum/template', crime_action_ctl::$actions[$crime['action']]);
  330. $crime['dateline'] = dgmdate($crime['dateline'], 'u');
  331. $crimelist[$crime['uid']] = $crime;
  332. }
  333. if($crimelist && $i == $limit) {
  334. $dataexist = 1;
  335. } else {
  336. $dataexist = 0;
  337. }
  338. foreach(C::t('common_member')->fetch_all(array_keys($crimelist)) as $uid => $user) {
  339. if($user['groupid'] == 4 || $user['groupid'] == 5) {
  340. $crimelist[$uid]['username'] = $user['username'];
  341. $crimelist[$uid]['groupexpiry'] = $user['groupexpiry'] ? dgmdate($user['groupexpiry'], 'u') : lang('forum/misc', 'never_expired');
  342. } else {
  343. unset($crimelist[$uid]);
  344. }
  345. }
  346. if($_GET['ajaxdata'] === 'json') {
  347. showmessage(array('dataexist' => $dataexist, 'cid' => $cid), '', $crimelist);
  348. } else {
  349. include_once template("forum/darkroom");
  350. }
  351. exit;
  352. }
  353. showmessage('undefined_action');
  354. } elseif($_GET['action'] == 'shortcut') {
  355. if($_GET['type'] == 'ico') {
  356. $shortcut = @readfile(DISCUZ_ROOT.'favicon.ico');
  357. $filename = 'favicon.ico';
  358. } else {
  359. $shortcut = '[InternetShortcut]
  360. URL='.$_G['siteurl'].'
  361. IconFile='.$_G['siteurl'].'favicon.ico
  362. IconIndex=1
  363. ';
  364. $filename = $_G['setting']['bbname'].'.url';
  365. }
  366. if(!strexists($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
  367. $filename = diconv($filename, CHARSET, 'UTF-8');
  368. } else {
  369. $filename = diconv($filename, CHARSET, 'GBK');
  370. }
  371. dheader('Content-type: application/octet-stream');
  372. dheader('Content-Disposition: attachment; filename="'.$filename.'"');
  373. echo $shortcut;
  374. exit;
  375. } elseif($_GET['action'] == 'livelastpost') {
  376. $fid = dintval($_GET['fid']);
  377. $forum = C::t('forum_forumfield')->fetch($fid);
  378. $livetid = $forum['livetid'];
  379. $postlist = array();
  380. if($livetid) {
  381. $thread = C::t('forum_thread')->fetch($livetid);
  382. $postlist['count'] = $thread['replies'];
  383. $postarr = C::t('forum_post')->fetch_all_by_tid('tid:'.$livetid, $livetid, true, 'DESC', 20);
  384. ksort($postarr);
  385. foreach($postarr as $post) {
  386. if($post['first'] == 1 || getstatus($post['status'], 1)) {
  387. continue;
  388. }
  389. $contentarr = array(
  390. 'authorid' => !$post['anonymous'] ? $post['authorid'] : '',
  391. 'author' => !$post['anonymous'] ? $post['author'] : lang('forum/misc', 'anonymous'),
  392. 'message' => str_replace("\r\n", '<br>', messagecutstr($post['message'])),
  393. 'dateline' => dgmdate($post['dateline'], 'u'),
  394. 'avatar' => !$post['anonymous'] ? avatar($post['authorid'], 'small') : '',
  395. );
  396. $postlist['list'][$post['pid']] = $contentarr;
  397. }
  398. }
  399. showmessage('', '', $postlist);
  400. exit;
  401. } else {
  402. if(empty($_G['forum']['allowview'])) {
  403. if(!$_G['forum']['viewperm'] && !$_G['group']['readaccess']) {
  404. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  405. } elseif($_G['forum']['viewperm'] && !forumperm($_G['forum']['viewperm'])) {
  406. showmessage('forum_nopermission', NULL, array($_G['group']['grouptitle']), array('login' => 1));
  407. }
  408. }
  409. $thread = C::t('forum_thread')->fetch($_G['tid']);
  410. if(!($thread['displayorder']>=0 || $thread['displayorder']==-4 && $thread['authorid']==$_G['uid'])) {
  411. $thread = array();
  412. }
  413. if($thread['readperm'] && $thread['readperm'] > $_G['group']['readaccess'] && !$_G['forum']['ismoderator'] && $thread['authorid'] != $_G['uid']) {
  414. showmessage('thread_nopermission', NULL, array('readperm' => $thread['readperm']), array('login' => 1));
  415. }
  416. if($_G['forum']['password'] && $_G['forum']['password'] != $_G['cookie']['fidpw'.$_G['fid']]) {
  417. showmessage('forum_passwd', "forum.php?mod=forumdisplay&fid=$_G[fid]");
  418. }
  419. if(!$thread) {
  420. showmessage('thread_nonexistence');
  421. }
  422. if($_G['forum']['type'] == 'forum') {
  423. $navigation = '<a href="forum.php">'.$_G['setting']['navs'][2]['navname']."</a> <em>&rsaquo;</em> <a href=\"forum.php?mod=forumdisplay&fid=$_G[fid]\">".$_G['forum']['name']."</a> <em>&rsaquo;</em> <a href=\"forum.php?mod=viewthread&tid=$_G[tid]\">$thread[subject]</a> ";
  424. $navtitle = strip_tags($_G['forum']['name']).' - '.$thread['subject'];
  425. } elseif($_G['forum']['type'] == 'sub') {
  426. $fup = C::t('forum_forum')->fetch($_G['forum']['fup']);
  427. $navigation = '<a href="forum.php">'.$_G['setting']['navs'][2]['navname']."</a> <em>&rsaquo;</em> <a href=\"forum.php?mod=forumdisplay&fid=$fup[fid]\">$fup[name]</a> &raquo; <a href=\"forum.php?mod=forumdisplay&fid=$_G[fid]\">".$_G['forum']['name']."</a> <em>&rsaquo;</em> <a href=\"forum.php?mod=viewthread&tid=$_G[tid]\">$thread[subject]</a> ";
  428. $navtitle = strip_tags($fup['name']).' - '.strip_tags($_G['forum']['name']).' - '.$thread['subject'];
  429. }
  430. }
  431. if($_GET['action'] == 'votepoll' && submitcheck('pollsubmit', 1)) {
  432. if(!$_G['group']['allowvote']) {
  433. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  434. } elseif(!empty($thread['closed'])) {
  435. showmessage('thread_poll_closed', NULL, array(), array('login' => 1));
  436. } elseif(empty($_GET['pollanswers'])) {
  437. showmessage('thread_poll_invalid', NULL, array(), array('login' => 1));
  438. }
  439. $pollarray = C::t('forum_poll')->fetch($_G['tid']);
  440. $overt = $pollarray['overt'];
  441. if(!$pollarray) {
  442. showmessage('poll_not_found');
  443. } elseif($pollarray['expiration'] && $pollarray['expiration'] < TIMESTAMP) {
  444. showmessage('poll_overdue', NULL, array(), array('login' => 1));
  445. } elseif($pollarray['maxchoices'] && $pollarray['maxchoices'] < count($_GET['pollanswers'])) {
  446. showmessage('poll_choose_most', NULL, array('maxchoices' => $pollarray['maxchoices']), array('login' => 1));
  447. }
  448. $voterids = $_G['uid'] ? $_G['uid'] : $_G['clientip'];
  449. $polloptionid = array();
  450. $query = C::t('forum_polloption')->fetch_all_by_tid($_G['tid']);
  451. foreach($query as $pollarray) {
  452. if(strexists("\t".$pollarray['voterids']."\t", "\t".$voterids."\t")) {
  453. showmessage('thread_poll_voted', NULL, array(), array('login' => 1));
  454. }
  455. $polloptionid[] = $pollarray['polloptionid'];
  456. }
  457. $polloptionids = '';
  458. foreach($_GET['pollanswers'] as $key => $id) {
  459. if(!in_array($id, $polloptionid)) {
  460. showmessage('parameters_error');
  461. }
  462. unset($polloptionid[$key]);
  463. $polloptionids[] = $id;
  464. }
  465. C::t('forum_polloption')->update_vote($polloptionids, $voterids."\t", 1);
  466. C::t('forum_thread')->update($_G['tid'], array('lastpost'=>$_G['timestamp']), true);
  467. C::t('forum_poll')->update_vote($_G['tid']);
  468. C::t('forum_pollvoter')->insert(array(
  469. 'tid' => $_G['tid'],
  470. 'uid' => $_G['uid'],
  471. 'username' => $_G['username'],
  472. 'options' => implode("\t", $_GET['pollanswers']),
  473. 'dateline' => $_G['timestamp'],
  474. ));
  475. updatecreditbyaction('joinpoll');
  476. $space = array();
  477. space_merge($space, 'field_home');
  478. if($overt && !empty($space['privacy']['feed']['newreply'])) {
  479. $feed['icon'] = 'poll';
  480. $feed['title_template'] = 'feed_thread_votepoll_title';
  481. $feed['title_data'] = array(
  482. 'subject' => "<a href=\"forum.php?mod=viewthread&tid=$_G[tid]\">$thread[subject]</a>",
  483. 'author' => "<a href=\"home.php?mod=space&uid=$thread[authorid]\">$thread[author]</a>",
  484. 'hash_data' => "tid{$_G[tid]}"
  485. );
  486. $feed['id'] = $_G['tid'];
  487. $feed['idtype'] = 'tid';
  488. postfeed($feed);
  489. }
  490. if(!empty($_G['inajax'])) {
  491. showmessage('thread_poll_succeed', "forum.php?mod=viewthread&tid=$_G[tid]".($_GET['from'] ? '&from='.$_GET['from'] : ''), array(), array('location' => true));
  492. } else {
  493. showmessage('thread_poll_succeed', "forum.php?mod=viewthread&tid=$_G[tid]".($_GET['from'] ? '&from='.$_GET['from'] : ''));
  494. }
  495. } elseif($_GET['action'] == 'viewvote') {
  496. if($_G[forum_thread][special] != 1) {
  497. showmessage('thread_poll_none');
  498. }
  499. require_once libfile('function/post');
  500. $polloptionid = is_numeric($_GET['polloptionid']) ? $_GET['polloptionid'] : '';
  501. $page = intval($_GET['page']) ? intval($_GET['page']) : 1;
  502. $perpage = 100;
  503. $pollinfo = C::t('forum_poll')->fetch($_G['tid']);
  504. $overt = $pollinfo['overt'];
  505. $polloptions = array();
  506. $query = C::t('forum_polloption')->fetch_all_by_tid($_G['tid']);
  507. foreach($query as $options) {
  508. if(empty($polloptionid)) {
  509. $polloptionid = $options['polloptionid'];
  510. }
  511. $options['polloption'] = preg_replace("/\[url=(https?){1}:\/\/([^\[\"']+?)\](.+?)\[\/url\]/i",
  512. "<a href=\"\\1://\\2\" target=\"_blank\">\\3</a>", $options['polloption']);
  513. $polloptions[] = $options;
  514. }
  515. $arrvoterids = array();
  516. if($overt || $_G['adminid'] == 1 || $thread['authorid'] == $_G['uid']) {
  517. $polloptioninfo = C::t('forum_polloption')->fetch($polloptionid);
  518. $voterids = $polloptioninfo['voterids'];
  519. $arrvoterids = explode("\t", trim($voterids));
  520. } else {
  521. showmessage('thread_poll_nopermission');
  522. }
  523. if(!empty($arrvoterids)) {
  524. $count = count($arrvoterids);
  525. $multi = $perpage * ($page - 1);
  526. $multipage = multi($count, $perpage, $page, "forum.php?mod=misc&action=viewvote&tid=$_G[tid]&polloptionid=$polloptionid".( $_GET[handlekey] ? "&handlekey=".$_GET[handlekey] : '' ));
  527. $arrvoterids = array_slice($arrvoterids, $multi, $perpage);
  528. }
  529. $voterlist = $voter = array();
  530. if($arrvoterids) {
  531. $voterlist = C::t('common_member')->fetch_all($arrvoterids);
  532. }
  533. include template('forum/viewthread_poll_voter');
  534. } elseif($_GET['action'] == 'rate' && $_GET['pid']) {
  535. if($_GET['showratetip']) {
  536. include template('forum/rate');
  537. exit();
  538. }
  539. if(!$_G['inajax']) {
  540. showmessage('undefined_action');
  541. }
  542. if(!$_G['group']['raterange']) {
  543. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  544. } elseif($_G['setting']['modratelimit'] && $_G['adminid'] == 3 && !$_G['forum']['ismoderator']) {
  545. showmessage('thread_rate_moderator_invalid', NULL);
  546. }
  547. $reasonpmcheck = $_G['group']['reasonpm'] == 2 || $_G['group']['reasonpm'] == 3 ? 'checked="checked" disabled' : '';
  548. if(($_G['group']['reasonpm'] == 2 || $_G['group']['reasonpm'] == 3) || !empty($_GET['sendreasonpm'])) {
  549. $forumname = strip_tags($_G['forum']['name']);
  550. $sendreasonpm = 1;
  551. } else {
  552. $sendreasonpm = 0;
  553. }
  554. $post = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['pid']);
  555. if($post['invisible'] != 0 || $post['authorid'] == 0) {
  556. $post = array();
  557. }
  558. if(!$post || $post['tid'] != $thread['tid'] || !$post['authorid']) {
  559. showmessage('rate_post_error');
  560. } elseif(!$_G['forum']['ismoderator'] && $_G['setting']['karmaratelimit'] && TIMESTAMP - $post['dateline'] > $_G['setting']['karmaratelimit'] * 3600) {
  561. showmessage('thread_rate_timelimit', NULL, array('karmaratelimit' => $_G['setting']['karmaratelimit']));
  562. } elseif($post['authorid'] == $_G['uid'] || $post['tid'] != $_G['tid']) {
  563. showmessage('thread_rate_member_invalid', NULL);
  564. } elseif($post['anonymous']) {
  565. showmessage('thread_rate_anonymous', NULL);
  566. } elseif($post['status'] & 1) {
  567. showmessage('thread_rate_banned', NULL);
  568. }
  569. $allowrate = TRUE;
  570. if(!$_G['setting']['dupkarmarate']) {
  571. if(C::t('forum_ratelog')->count_by_uid_pid($_G['uid'], $_GET['pid'])) {
  572. showmessage('thread_rate_duplicate', NULL);
  573. }
  574. }
  575. $page = intval($_GET['page']);
  576. require_once libfile('function/misc');
  577. $maxratetoday = getratingleft($_G['group']['raterange']);
  578. if(!submitcheck('ratesubmit')) {
  579. $referer = $_G['siteurl'].'forum.php?mod=viewthread&tid='.$_G['tid'].'&page='.$page.($_GET['from'] ? '&from='.$_GET['from'] : '').'#pid'.$_GET['pid'];
  580. $ratelist = getratelist($_G['group']['raterange']);
  581. include template('forum/rate');
  582. } else {
  583. $reason = checkreasonpm();
  584. $rate = $ratetimes = 0;
  585. $creditsarray = $sub_self_credit = array();
  586. getuserprofile('extcredits1');
  587. foreach($_G['group']['raterange'] as $id => $rating) {
  588. $score = intval($_GET['score'.$id]);
  589. if(isset($_G['setting']['extcredits'][$id]) && !empty($score)) {
  590. if($rating['isself'] && (intval($_G['member']['extcredits'.$id]) - $score < 0)) {
  591. showmessage('thread_rate_range_self_invalid', '', array('extcreditstitle' => $_G['setting']['extcredits'][$id]['title']));
  592. }
  593. if(abs($score) <= $maxratetoday[$id]) {
  594. if($score > $rating['max'] || $score < $rating['min']) {
  595. showmessage('thread_rate_range_invalid');
  596. } else {
  597. $creditsarray[$id] = $score;
  598. if($rating['isself']) {
  599. $sub_self_credit[$id] = -abs($score);
  600. }
  601. $rate += $score;
  602. $ratetimes += ceil(max(abs($rating['min']), abs($rating['max'])) / 5);
  603. }
  604. } else {
  605. showmessage('thread_rate_ctrl');
  606. }
  607. }
  608. }
  609. if(!$creditsarray) {
  610. showmessage('thread_rate_range_invalid', NULL);
  611. }
  612. updatemembercount($post['authorid'], $creditsarray, 1, 'PRC', $_GET['pid']);
  613. if(!empty($sub_self_credit)) {
  614. updatemembercount($_G['uid'], $sub_self_credit, 1, 'RSC', $_GET['pid']);
  615. }
  616. C::t('forum_post')->increase_rate_by_pid('tid:'.$_G['tid'], $_GET['pid'], $rate, $ratetimes);
  617. if($post['first']) {
  618. $threadrate = intval(@($post['rate'] + $rate) / abs($post['rate'] + $rate));
  619. C::t('forum_thread')->update($_G['tid'], array('rate'=>$threadrate));
  620. }
  621. require_once libfile('function/discuzcode');
  622. $sqlvalues = $comma = '';
  623. $sqlreason = censor(trim($_GET['reason']));
  624. $sqlreason = cutstr(dhtmlspecialchars($sqlreason), 40, '.');
  625. foreach($creditsarray as $id => $addcredits) {
  626. $insertarr = array(
  627. 'pid' => $_GET['pid'],
  628. 'uid' => $_G['uid'],
  629. 'username' => $_G['username'],
  630. 'extcredits' => $id,
  631. 'dateline' => $_G['timestamp'],
  632. 'score' => $addcredits,
  633. 'reason' => $sqlreason
  634. );
  635. C::t('forum_ratelog')->insert($insertarr);
  636. }
  637. include_once libfile('function/post');
  638. $_G['forum']['threadcaches'] && @deletethreadcaches($_G['tid']);
  639. $reason = dhtmlspecialchars(censor(trim($reason)));
  640. if($sendreasonpm) {
  641. $ratescore = $slash = '';
  642. foreach($creditsarray as $id => $addcredits) {
  643. $ratescore .= $slash.$_G['setting']['extcredits'][$id]['title'].' '.($addcredits > 0 ? '+'.$addcredits : $addcredits).' '.$_G['setting']['extcredits'][$id]['unit'];
  644. $slash = ' / ';
  645. }
  646. sendreasonpm($post, 'rate_reason', array(
  647. 'tid' => $thread['tid'],
  648. 'pid' => $_GET['pid'],
  649. 'subject' => $thread['subject'],
  650. 'ratescore' => $ratescore,
  651. 'reason' => $reason,
  652. 'from_id' => 0,
  653. 'from_idtype' => 'rate'
  654. ));
  655. }
  656. $logs = array();
  657. foreach($creditsarray as $id => $addcredits) {
  658. $logs[] = dhtmlspecialchars("$_G[timestamp]\t{$_G[member][username]}\t$_G[adminid]\t$post[author]\t$id\t$addcredits\t$_G[tid]\t$thread[subject]\t$reason");
  659. }
  660. update_threadpartake($post['tid']);
  661. C::t('forum_postcache')->delete($_GET['pid']);
  662. writelog('ratelog', $logs);
  663. showmessage('thread_rate_succeed', dreferer());
  664. }
  665. } elseif($_GET['action'] == 'removerate' && $_GET['pid']) {
  666. if(!$_G['forum']['ismoderator'] || !$_G['group']['raterange']) {
  667. showmessage('no_privilege_removerate');
  668. }
  669. $reasonpmcheck = $_G['group']['reasonpm'] == 2 || $_G['group']['reasonpm'] == 3 ? 'checked="checked" disabled' : '';
  670. if(($_G['group']['reasonpm'] == 2 || $_G['group']['reasonpm'] == 3) || !empty($_GET['sendreasonpm'])) {
  671. $forumname = strip_tags($_G['forum']['name']);
  672. $sendreasonpm = 1;
  673. } else {
  674. $sendreasonpm = 0;
  675. }
  676. foreach($_G['group']['raterange'] as $id => $rating) {
  677. $maxratetoday[$id] = $rating['mrpd'];
  678. }
  679. $post = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['pid']);
  680. if($post['invisible'] != 0 || $post['authorid'] == 0) {
  681. $post = array();
  682. }
  683. if(!$post || $post['tid'] != $thread['tid'] || !$post['authorid']) {
  684. showmessage('rate_post_error');
  685. }
  686. require_once libfile('function/misc');
  687. if(!submitcheck('ratesubmit')) {
  688. $referer = $_G['siteurl'].'forum.php?mod=viewthread&tid='.$_G['tid'].'&page='.$page.($_GET['from'] ? '&from='.$_GET['from'] : '').'#pid'.$_GET['pid'];
  689. $ratelogs = array();
  690. foreach(C::t('forum_ratelog')->fetch_all_by_pid($_GET['pid'], 'ASC') as $ratelog) {
  691. $ratelog['dbdateline'] = $ratelog['dateline'];
  692. $ratelog['dateline'] = dgmdate($ratelog['dateline'], 'u');
  693. $ratelog['scoreview'] = $ratelog['score'] > 0 ? '+'.$ratelog['score'] : $ratelog['score'];
  694. $ratelogs[] = $ratelog;
  695. }
  696. include template('forum/rate');
  697. } else {
  698. $reason = checkreasonpm();
  699. if(!empty($_GET['logidarray'])) {
  700. if($sendreasonpm) {
  701. $ratescore = $slash = '';
  702. }
  703. $rate = $ratetimes = 0;
  704. $logs = array();
  705. foreach(C::t('forum_ratelog')->fetch_all_by_pid($_GET['pid']) as $ratelog) {
  706. if(in_array($ratelog['uid'].' '.$ratelog['extcredits'].' '.$ratelog['dateline'], $_GET['logidarray'])) {
  707. $rate += $ratelog['score'] = -$ratelog['score'];
  708. $ratetimes += ceil(max(abs($rating['min']), abs($rating['max'])) / 5);
  709. updatemembercount($post['authorid'], array($ratelog['extcredits'] => $ratelog['score']));
  710. C::t('common_credit_log')->delete_by_uid_operation_relatedid($post['authorid'], 'PRC', $_GET['pid']);
  711. C::t('forum_ratelog')->delete_by_pid_uid_extcredits_dateline($_GET['pid'], $ratelog['uid'], $ratelog['extcredits'], $ratelog['dateline']);
  712. $logs[] = dhtmlspecialchars("$_G[timestamp]\t{$_G[member][username]}\t$_G[adminid]\t$ratelog[username]\t$ratelog[extcredits]\t$ratelog[score]\t$_G[tid]\t$thread[subject]\t$reason\tD");
  713. if($sendreasonpm) {
  714. $ratescore .= $slash.$_G['setting']['extcredits'][$ratelog['extcredits']]['title'].' '.($ratelog['score'] > 0 ? '+'.$ratelog['score'] : $ratelog['score']).' '.$_G['setting']['extcredits'][$ratelog['extcredits']]['unit'];
  715. $slash = ' / ';
  716. }
  717. }
  718. }
  719. C::t('forum_postcache')->delete($_GET['pid']);
  720. writelog('ratelog', $logs);
  721. if($sendreasonpm) {
  722. sendreasonpm($post, 'rate_removereason', array(
  723. 'tid' => $thread['tid'],
  724. 'pid' => $_GET['pid'],
  725. 'subject' => $thread['subject'],
  726. 'ratescore' => $ratescore,
  727. 'reason' => $reason,
  728. 'from_id' => 0,
  729. 'from_idtype' => 'removerate'
  730. ));
  731. }
  732. C::t('forum_post')->increase_rate_by_pid('tid:'.$_G['tid'], $_GET['pid'], $rate, $ratetimes);
  733. if($post['first']) {
  734. $threadrate = @intval(@($post['rate'] + $rate) / abs($post['rate'] + $rate));
  735. C::t('forum_thread')->update($_G['tid'], array('rate'=>$threadrate));
  736. }
  737. }
  738. showmessage('thread_rate_removesucceed', dreferer());
  739. }
  740. } elseif($_GET['action'] == 'viewratings' && $_GET['pid']) {
  741. $loglist = $logcount = array();
  742. $post = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['pid']);
  743. if($post['invisible'] != 0) {
  744. $post = array();
  745. }
  746. if($post) {
  747. $loglist = C::t('forum_ratelog')->fetch_all_by_pid($_GET['pid']);
  748. }
  749. if(empty($post) || empty($loglist)) {
  750. showmessage('thread_rate_log_nonexistence');
  751. }
  752. if($post['tid'] != $thread['tid']) {
  753. showmessage('targetpost_donotbelongto_thisthread');
  754. }
  755. if($_G['setting']['bannedmessages']) {
  756. $postmember = getuserbyuid($post['authorid']);
  757. $post['groupid'] = $postmember['groupid'];
  758. }
  759. foreach($loglist as $k => $log) {
  760. $logcount[$log['extcredits']] += $log['score'];
  761. $log['dateline'] = dgmdate($log['dateline'], 'u');
  762. $log['score'] = $log['score'] > 0 ? '+'.$log['score'] : $log['score'];
  763. $log['reason'] = dhtmlspecialchars($log['reason']);
  764. $loglist[$k] = $log;
  765. }
  766. include template('forum/rate_view');
  767. } elseif($_GET['action'] == 'viewwarning' && $_GET['uid']) {
  768. $warnuser = getuserbyuid($_GET['uid']);
  769. $warnuser = $warnuser['username'];
  770. if(!$warnuser) {
  771. showmessage('member_no_found');
  772. }
  773. $warnings = array();
  774. $warnings = C::t('forum_warning')->fetch_all_by_authorid($_GET['uid']);
  775. if(!$warnings) {
  776. showmessage('thread_warning_nonexistence');
  777. }
  778. foreach($warnings as $key => $warning) {
  779. $warning['dateline'] = dgmdate($warning['dateline'], 'u');
  780. $warning['reason'] = dhtmlspecialchars($warning['reason']);
  781. $warnings[$key] = $warning;
  782. }
  783. $warnnum = count($warnings);
  784. include template('forum/warn_view');
  785. } elseif($_GET['action'] == 'pay') {
  786. if(!isset($_G['setting']['extcredits'][$_G['setting']['creditstransextra'][1]])) {
  787. showmessage('credits_transaction_disabled');
  788. } elseif($thread['price'] <= 0 || $thread['special'] <> 0) {
  789. showmessage('thread_pay_error', NULL);
  790. } elseif(!$_G['uid']) {
  791. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  792. }
  793. if(($balance = getuserprofile('extcredits'.$_G['setting']['creditstransextra'][1]) - $thread['price']) < ($minbalance = 0)) {
  794. if($_G['setting']['creditstrans'][0] == $_G['setting']['creditstransextra'][1]) {
  795. showmessage('credits_balance_insufficient_and_charge', '', array('title' => $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][1]]['title'], 'minbalance' => $thread['price']));
  796. } else {
  797. showmessage('credits_balance_insufficient', '', array('title' => $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][1]]['title'], 'minbalance' => $thread['price']));
  798. }
  799. }
  800. if(C::t('common_credit_log')->count_by_uid_operation_relatedid($_G['uid'], 'BTC', $_G['tid'])) {
  801. showmessage('credits_buy_thread', 'forum.php?mod=viewthread&tid='.$_G['tid'].($_GET['from'] ? '&from='.$_GET['from'] : ''));
  802. }
  803. $thread['netprice'] = floor($thread['price'] * (1 - $_G['setting']['creditstax']));
  804. if(!submitcheck('paysubmit')) {
  805. include template('forum/pay');
  806. } else {
  807. $updateauthor = true;
  808. $authorEarn = $thread['netprice'];
  809. if($_G['setting']['maxincperthread'] > 0) {
  810. $extcredit = 'extcredits'.$_G['setting']['creditstransextra'][1];
  811. $log = C::t('common_credit_log')->count_credit_by_uid_operation_relatedid($thread['authorid'], 'STC', $_G['tid'], $_G['setting']['creditstransextra'][1]);
  812. if($log >= $_G['setting']['maxincperthread']) {
  813. $updateauthor = false;
  814. } else {
  815. $authorEarn = min($_G['setting']['maxincperthread'] - $log['credit'], $thread['netprice']);
  816. }
  817. }
  818. if($updateauthor) {
  819. updatemembercount($thread['authorid'], array($_G['setting']['creditstransextra'][1] => $authorEarn), 1, 'STC', $_G['tid']);
  820. }
  821. updatemembercount($_G['uid'], array($_G['setting']['creditstransextra'][1] => -$thread['price']), 1, 'BTC', $_G['tid']);
  822. showmessage('thread_pay_succeed', "forum.php?mod=viewthread&tid=$_G[tid]".($_GET['from'] ? '&from='.$_GET['from'] : ''));
  823. }
  824. } elseif($_GET['action'] == 'viewpayments') {
  825. $extcreditname = 'extcredits'.$_G['setting']['creditstransextra'][1];
  826. $loglist = array();
  827. $logs = C::t('common_credit_log')->fetch_all_by_uid_operation_relatedid(0, 'BTC', $_G['tid']);
  828. $luids = array();
  829. foreach($logs as $log) {
  830. $luids[$log['uid']] = $log['uid'];
  831. }
  832. $members = C::t('common_member')->fetch_all($luids);
  833. foreach($logs as $log) {
  834. $log['username'] = $members[$log['uid']]['username'];
  835. $log['dateline'] = dgmdate($log['dateline'], 'u');
  836. $log[$extcreditname] = abs($log[$extcreditname]);
  837. $loglist[] = $log;
  838. }
  839. include template('forum/pay_view');
  840. } elseif($_GET['action'] == 'viewthreadmod' && $_G['tid']) {
  841. $modactioncode = lang('forum/modaction');
  842. $loglist = array();
  843. foreach(C::t('forum_threadmod')->fetch_all_by_tid($_G['tid']) as $log) {
  844. $log['dateline'] = dgmdate($log['dateline'], 'u');
  845. $log['expiration'] = !empty($log['expiration']) ? dgmdate($log['expiration'], 'd') : '';
  846. $log['status'] = empty($log['status']) ? 'style="text-decoration: line-through" disabled' : '';
  847. if(!$modactioncode[$log['action']] && preg_match('/S(\d\d)/', $log['action'], $a) || $log['action'] == 'SPA') {
  848. loadcache('stamps');
  849. if($log['action'] == 'SPA') {
  850. $log['action'] = 'SPA'.$log['stamp'];
  851. $stampid = $log['stamp'];
  852. } else {
  853. $stampid = intval($a[1]);
  854. }
  855. $modactioncode[$log['action']] = $modactioncode['SPA'].' '.$_G['cache']['stamps'][$stampid]['text'];
  856. } elseif(preg_match('/L(\d\d)/', $log['action'], $a)) {
  857. loadcache('stamps');
  858. $modactioncode[$log['action']] = $modactioncode['SLA'].' '.$_G['cache']['stamps'][intval($a[1])]['text'];
  859. }
  860. if($log['magicid']) {
  861. loadcache('magics');
  862. $log['magicname'] = $_G['cache']['magics'][$log['magicid']]['name'];
  863. }
  864. $loglist[] = $log;
  865. }
  866. if(empty($loglist)) {
  867. showmessage('threadmod_nonexistence');
  868. }
  869. include template('forum/viewthread_mod');
  870. } elseif($_GET['action'] == 'bestanswer' && $_G['tid'] && $_GET['pid'] && submitcheck('bestanswersubmit')) {
  871. $forward = 'forum.php?mod=viewthread&tid='.$_G['tid'].($_GET['from'] ? '&from='.$_GET['from'] : '');
  872. $post = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['pid'], false);
  873. if($post['tid'] != $_G['tid']) {
  874. $post = array();
  875. }
  876. if(!($thread['special'] == 3 && $post && ($_G['forum']['ismoderator'] && (!$_G['setting']['rewardexpiration'] || $_G['setting']['rewardexpiration'] > 0 && ($_G['timestamp'] - $thread['dateline']) / 86400 > $_G['setting']['rewardexpiration']) || $thread['authorid'] == $_G['uid']) && $post['authorid'] != $thread['authorid'] && $post['first'] == 0 && $_G['uid'] != $post['authorid'] && $thread['price'] > 0)) {
  877. showmessage('reward_cant_operate');
  878. } elseif($post['authorid'] == $thread['authorid']) {
  879. showmessage('reward_cant_self');
  880. } elseif($thread['price'] < 0) {
  881. showmessage('reward_repeat_selection');
  882. }
  883. updatemembercount($post['authorid'], array($_G['setting']['creditstransextra'][2] => $thread['price']), 1, 'RAC', $_G['tid']);
  884. $thread['price'] = '-'.$thread['price'];
  885. C::t('forum_thread')->update($_G['tid'], array('price'=>$thread['price']));
  886. C::t('forum_post')->update('tid:'.$_G['tid'], $_GET['pid'], array(
  887. 'dateline' => $thread['dateline'] + 1,
  888. ));
  889. $thread['dateline'] = dgmdate($thread['dateline']);
  890. if($_G['uid'] != $thread['authorid']) {
  891. notification_add($thread['authorid'], 'reward', 'reward_question', array(
  892. 'tid' => $thread['tid'],
  893. 'subject' => $thread['subject'],
  894. ));
  895. }
  896. if($thread['authorid'] == $_G['uid']) {
  897. notification_add($post['authorid'], 'reward', 'reward_bestanswer', array(
  898. 'tid' => $thread['tid'],
  899. 'subject' => $thread['subject'],
  900. ));
  901. } else {
  902. notification_add($post['authorid'], 'reward', 'reward_bestanswer_moderator', array(
  903. 'tid' => $thread['tid'],
  904. 'subject' => $thread['subject'],
  905. ));
  906. }
  907. showmessage('reward_completion', $forward);
  908. } elseif($_GET['action'] == 'activityapplies') {
  909. if(!$_G['uid']) {
  910. showmessage('not_loggedin', NULL, array(), array('login' => 1));
  911. }
  912. if(submitcheck('activitysubmit')) {
  913. $activity = C::t('forum_activity')->fetch($_G['tid']);
  914. if($activity['expiration'] && $activity['expiration'] < TIMESTAMP) {
  915. showmessage('activity_stop', NULL, array(), array('login' => 1));
  916. }
  917. $applyinfo = array();
  918. $applyinfo = C::t('forum_activityapply')->fetch_info_for_user($_G['uid'], $_G['tid']);
  919. if($applyinfo && $applyinfo['verified'] < 2) {
  920. showmessage('activity_repeat_apply', NULL, array(), array('login' => 1));
  921. }
  922. $payvalue = intval($_GET['payvalue']);
  923. $payment = $_GET['payment'] ? $payvalue : -1;
  924. $message = cutstr(dhtmlspecialchars($_GET['message']), 200);
  925. $verified = $thread['authorid'] == $_G['uid'] ? 1 : 0;
  926. if($activity['ufield']) {
  927. $ufielddata = array();
  928. $activity['ufield'] = dunserialize($activity['ufield']);
  929. if(!empty($activity['ufield']['userfield'])) {
  930. $censor = discuz_censor::instance();
  931. loadcache('profilesetting');
  932. foreach($activity['ufield']['userfield'] as $filedname) {
  933. $value = $_POST[$filedname];
  934. if(is_array($value)) {
  935. $value = implode(',', $value);
  936. }
  937. $value = cutstr(dhtmlspecialchars(trim($value)), 100, '.');
  938. if($_G['cache']['profilesetting'][$filedname]['formtype'] == 'file' && !preg_match("/^https?:\/\/(.*)?\.(jpg|png|gif|jpeg|bmp)$/i", $value)) {
  939. showmessage('activity_imgurl_error');
  940. }
  941. if(empty($value) && $filedname != 'residedist' && $filedname != 'residecommunity') {
  942. showmessage('activity_exile_field');
  943. }
  944. $ufielddata['userfield'][$filedname] = $value;
  945. }
  946. }
  947. if(!empty($activity['ufield']['extfield'])) {
  948. foreach($activity['ufield']['extfield'] as $fieldid) {
  949. $value = cutstr(dhtmlspecialchars(trim($_GET[''.$fieldid])), 50, '.');
  950. $ufielddata['extfield'][$fieldid] = $value;
  951. }
  952. }
  953. $ufielddata = !empty($ufielddata) ? serialize($ufielddata) : '';
  954. }
  955. if($_G['setting']['activitycredit'] && $activity['credit'] && empty($applyinfo['verified'])) {
  956. checklowerlimit(array('extcredits'.$_G['setting']['activitycredit'] => '-'.$activity['credit']));
  957. updatemembercount($_G['uid'], array($_G['setting']['activitycredit'] => '-'.$activity['credit']), true, 'ACC', $_G['tid']);
  958. }
  959. if($applyinfo && $applyinfo['verified'] == 2) {
  960. $newinfo = array(
  961. 'tid' => $_G['tid'],
  962. 'username' => $_G['username'],
  963. 'uid' => $_G['uid'],
  964. 'message' => $message,
  965. 'verified' => $verified,
  966. 'dateline' => $_G['timestamp'],
  967. 'payment' => $payment,
  968. 'ufielddata' => $ufielddata
  969. );
  970. C::t('forum_activityapply')->update($applyinfo['applyid'], $newinfo);
  971. } else {
  972. $data = array('tid' => $_G['tid'], 'username' => $_G['username'], 'uid' => $_G['uid'], 'message' => $message, 'verified' => $verified, 'dateline' => $_G['timestamp'], 'payment' => $payment, 'ufielddata' => $ufielddata);
  973. C::t('forum_activityapply')->insert($data);
  974. }
  975. $applynumber = C::t('forum_activityapply')->fetch_count_for_thread($_G['tid']);
  976. C::t('forum_activity')->update($_G['tid'], array('applynumber' => $applynumber));
  977. if($thread['authorid'] != $_G['uid']) {
  978. notification_add($thread['authorid'], 'activity', 'activity_notice', array(
  979. 'tid' => $_G['tid'],
  980. 'subject' => $thread['subject'],
  981. ));
  982. $space = array();
  983. space_merge($space, 'field_home');
  984. if(!empty($space['privacy']['feed']['newreply'])) {
  985. $feed['icon'] = 'activity';
  986. $feed['title_template'] = 'feed_reply_activity_title';
  987. $feed['title_data'] = array(
  988. 'subject' => "<a href=\"forum.php?mod=viewthread&tid=$_G[tid]\">$thread[subject]</a>",
  989. 'hash_data' => "tid{$_G[tid]}"
  990. );
  991. $feed['id'] = $_G['tid'];
  992. $feed['idtype'] = 'tid';
  993. postfeed($feed);
  994. }
  995. }
  996. showmessage('activity_completion', "forum.php?mod=viewthread&tid=$_G[tid]".($_GET['from'] ? '&from='.$_GET['from'] : ''), array(), array('showdialog' => 1, 'showmsg' => true, 'locationtime' => true, 'alert' => 'right'));
  997. } elseif(submitcheck('activitycancel')) {
  998. C::t('forum_activityapply')->delete_for_user($_G['uid'], $_G['tid']);
  999. $applynumber = C::t('forum_activityapply')->fetch_count_for_thread($_G['tid']);
  1000. C::t('forum_activity')->update($_G['tid'], array('applynumber' => $applynumber));
  1001. $message = cutstr(dhtmlspecialchars($_GET['message']), 200);
  1002. if($thread['authorid'] != $_G['uid']) {
  1003. notification_add($thread['authorid'], 'activity', 'activity_cancel', array(
  1004. 'tid' => $_G['tid'],
  1005. 'subject' => $thread['subject'],
  1006. 'reason' => $message
  1007. ));
  1008. }
  1009. showmessage('activity_cancel_success', "forum.php?mod=viewthread&tid=$_G[tid]&do=viewapplylist".($_GET['from'] ? '&from='.$_GET['from'] :''), array(), array('showdialog' => 1, 'closetime' => true));
  1010. }
  1011. } elseif($_GET['action'] == 'getactivityapplylist') {
  1012. $pp = $_G['setting']['activitypp'];
  1013. $page = max(1, $_G['page']);
  1014. $start = ($page - 1) * $pp;
  1015. $activity = C::t('forum_activity')->fetch($_G['tid']);
  1016. if(!$activity || $thread['special'] != 4) {
  1017. showmessage('undefined_action');
  1018. }
  1019. $query = C::t('forum_activityapply')->fetch_all_for_thread($_G['tid'], $start, $pp);
  1020. foreach($query as $activityapplies) {
  1021. $activityapplies['dateline'] = dgmdate($activityapplies['dateline']);
  1022. $applylist[] = $activityapplies;
  1023. }
  1024. $multi = multi($activity['applynumber'], $pp, $page, "forum.php?mod=misc&action=getactivityapplylist&tid=$_G[tid]&pid=$_GET[pid]");
  1025. include template('forum/activity_applist_more');
  1026. } elseif($_GET['action'] == 'activityapplylist') {
  1027. $isactivitymaster = $thread['authorid'] == $_G['uid'] ||
  1028. (in_array($_G['group']['radminid'], array(1, 2)) || ($_G['group']['radminid'] == 3 && $_G['forum']['ismoderator'])
  1029. && $_G['group']['alloweditactivity']);
  1030. if(!$isactivitymaster) {
  1031. showmessage('activity_is_not_manager');
  1032. }
  1033. $activity = C::t('forum_activity')->fetch($_G['tid']);
  1034. if(empty($activity) || $thread['special'] != 4) {
  1035. showmessage('activity_is_not_exists');
  1036. }
  1037. if(!submitcheck('applylistsubmit')) {
  1038. $applylist = array();
  1039. $activity['ufield'] = $activity['ufield'] ? dunserialize($activity['ufield']) : array();
  1040. $query = C::t('forum_activityapply')->fetch_all_for_thread($_G['tid'], 0, 500, $_GET['uid'], $isactivitymaster);
  1041. foreach($query as $activityapplies) {
  1042. $ufielddata = '';
  1043. $activityapplies['dateline'] = dgmdate($activityapplies['dateline'], 'u');
  1044. $activityapplies['ufielddata'] = !empty($activityapplies['ufielddata']) ? dunserialize($activityapplies['ufielddata']) : '';
  1045. if($activityapplies['ufielddata']) {
  1046. if($activityapplies['ufielddata']['userfield']) {
  1047. require_once libfile('function/profile');
  1048. loadcache('profilesetting');
  1049. $data = '';
  1050. foreach($activity['ufield']['userfield'] as $fieldid) {
  1051. $data = profile_show($fieldid, $activityapplies['ufielddata']['userfield']);
  1052. $ufielddata .= '<li>'.$_G['cache']['profilesetting'][$fieldid]['title'].'&nbsp;&nbsp;:&nbsp;&nbsp;';
  1053. if(empty($data)) {
  1054. $ufielddata .= '</li>';
  1055. continue;
  1056. }
  1057. if($_G['cache']['profilesetting'][$fieldid]['formtype'] != 'file') {
  1058. $ufielddata .= $data;
  1059. } else {
  1060. $ufielddata .= '<a href="'.$data.'" target="_blank" onclick="zoom(this, this.href, 0, 0, 0); return false;">'.lang('forum/misc', 'activity_viewimg').'</a>';
  1061. }
  1062. $ufielddata .= '</li>';
  1063. }
  1064. }
  1065. if($activityapplies['ufielddata']['extfield']) {
  1066. foreach($activity['ufield']['extfield'] as $name) {
  1067. $ufielddata .= '<li>'.$name.'&nbsp;&nbsp;:&nbsp;&nbsp;'.$activityapplies['ufielddata']['extfield'][$name].'</li>';
  1068. }
  1069. }
  1070. }
  1071. $activityapplies['ufielddata'] = $ufielddata;
  1072. $applylist[] = $activityapplies;
  1073. }
  1074. $activity['starttimefrom'] = dgmdate($activity['starttimefrom'], 'u');
  1075. $activity['starttimeto'] = $activity['starttimeto'] ? dgmdate($activity['starttimeto'], 'u') : 0;
  1076. $activity['expiration'] = $activity['expiration'] ? dgmdate($activity['expiration'], 'u') : 0;
  1077. include template('forum/activity_applylist');
  1078. } else {
  1079. if(empty($_GET['applyidarray'])) {
  1080. showmessage('activity_choice_applicant');
  1081. } else {
  1082. $reason = cutstr(dhtmlspecialchars($_GET['reason']), 200);
  1083. $tempuid = $uidarray = $unverified = array();
  1084. $query = C::t('forum_activityapply')->fetch_all($_GET['applyidarray']);
  1085. foreach($query as $row) {
  1086. if($row['tid'] == $_G['tid']) {
  1087. $tempusers[$row['uid']] = $row['verified'];
  1088. }
  1089. }
  1090. $query = C::t('common_member')->fe

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