PageRenderTime 28ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/source/module/forum/forum_misc.php

https://github.com/kuaileshike/upload
PHP | 1663 lines | 1448 code | 209 blank | 6 comment | 517 complexity | e2f56ef2675063b11a0c45db4d694329 MD5 | raw file

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

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