forum_misc.php 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866
  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 36284 2016-12-12 00:47:50Z nemohou $
  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. list($seccodecheck, $secqaacheck) = seccheck('post', 'reply');
  217. include template('forum/comment');
  218. } elseif($_GET['action'] == 'commentmore') {
  219. function forum_misc_commentmore_callback_1($matches, $action = 0) {
  220. static $cic = 0;
  221. if($action == 1) {
  222. $cic = $matches;
  223. } else {
  224. return '<i class="cmstarv" style="background-position:20px -'.(intval($matches[1]) * 16).'px">'.sprintf('%1.1f', $matches[1]).'</i>'.($cic++ % 2 ? '<br />' : '');
  225. }
  226. }
  227. if(!$_G['setting']['commentnumber'] || !$_G['inajax']) {
  228. showmessage('postcomment_closed');
  229. }
  230. require_once libfile('function/discuzcode');
  231. $commentlimit = intval($_G['setting']['commentnumber']);
  232. $page = max(1, $_G['page']);
  233. $start_limit = ($page - 1) * $commentlimit;
  234. $comments = array();
  235. foreach(C::t('forum_postcomment')->fetch_all_by_search(null, $_GET['pid'], null, null, null, null, null, $start_limit, $commentlimit) as $comment) {
  236. $comment['avatar'] = avatar($comment['authorid'], 'small');
  237. $comment['dateline'] = dgmdate($comment['dateline'], 'u');
  238. $comment['comment'] = str_replace(array('[b]', '[/b]', '[/color]'), array('<b>', '</b>', '</font>'), preg_replace("/\[color=([#\w]+?)\]/i", "<font color=\"\\1\">", $comment['comment']));
  239. $comments[] = $comment;
  240. }
  241. forum_misc_commentmore_callback_1(0, 1);
  242. $totalcomment = C::t('forum_postcomment')->fetch_standpoint_by_pid($_GET['pid']);
  243. $totalcomment = $totalcomment['comment'];
  244. $totalcomment = preg_replace_callback('/<i>([\.\d]+)<\/i>/', 'forum_misc_commentmore_callback_1', $totalcomment);
  245. $count = C::t('forum_postcomment')->count_by_search(null, $_GET['pid']);
  246. $multi = multi($count, $commentlimit, $page, "forum.php?mod=misc&action=commentmore&tid=$_G[tid]&pid=$_GET[pid]");
  247. include template('forum/comment_more');
  248. } elseif($_GET['action'] == 'postappend') {
  249. if(!$_G['setting']['postappend']) {
  250. showmessage('postappend_not_open');
  251. }
  252. $post = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['pid']);
  253. if($post['authorid'] != $_G['uid']) {
  254. showmessage('postappend_only_yourself');
  255. }
  256. if(submitcheck('postappendsubmit')) {
  257. $message = censor($_GET['postappendmessage']);
  258. $sppos = 0;
  259. if($post['first'] && strexists($post['message'], chr(0).chr(0).chr(0))) {
  260. $sppos = strpos($post['message'], chr(0).chr(0).chr(0));
  261. $specialextra = substr($post['message'], $sppos + 3);
  262. $post['message'] = substr($post['message'], 0, $sppos);
  263. }
  264. $message = $post['message'] . "\n\n[b]".lang('forum/misc', 'postappend_content')." (".dgmdate(TIMESTAMP)."):[/b]\n$message";
  265. if($sppos) {
  266. $message .= chr(0).chr(0).chr(0).$specialextra;
  267. }
  268. require_once libfile('function/post');
  269. $bbcodeoff = checkbbcodes($message, 0);
  270. C::t('forum_post')->update('tid:'.$_G['tid'], $_GET['pid'], array(
  271. 'message' => $message,
  272. 'bbcodeoff' => $bbcodeoff,
  273. 'port' => $_G['remoteport']
  274. ));
  275. 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']));
  276. } else {
  277. include template('forum/postappend');
  278. }
  279. } elseif($_GET['action'] == 'pubsave') {
  280. $return = threadpubsave($_G['tid']);
  281. if($return > 0) {
  282. showmessage('post_newthread_succeed', dreferer(), array('coverimg' => ''));
  283. } elseif($return == -1) {
  284. showmessage('post_newthread_mod_succeed', dreferer(), array('coverimg' => ''));
  285. } elseif($return == -2) {
  286. showmessage('post_reply_mod_succeed', dreferer());
  287. } else {
  288. showmessage('thread_nonexistence');
  289. }
  290. } elseif($_GET['action'] == 'loadsave') {
  291. $message = '&nbsp;';
  292. $savepost = C::t('forum_post')->fetch(0, $_GET['pid']);
  293. if($savepost) {
  294. $message = $savepost['message'];
  295. if($_GET['type']) {
  296. require_once libfile('function/discuzcode');
  297. $message = discuzcode($message, $savepost['smileyoff'], $savepost['bbcodeoff'], $savepost['htmlon']);
  298. }
  299. $message = $message ? $message : '&nbsp;';
  300. }
  301. include template('common/header_ajax');
  302. echo $message;
  303. include template('common/footer_ajax');
  304. exit;
  305. } elseif($_GET['action'] == 'replynotice') {
  306. $tid = intval($_GET['tid']);
  307. $status = $_GET['op'] == 'ignore' ? 0 : 1;
  308. if(!empty($tid)) {
  309. $thread = C::t('forum_thread')->fetch_by_tid_displayorder($tid, 0);
  310. if($thread['authorid'] == $_G['uid']) {
  311. $thread['status'] = setstatus(6, $status, $thread['status']);
  312. C::t('forum_thread')->update($tid, array('status'=>$thread['status']), true);
  313. showmessage('replynotice_success_'.$status);
  314. }
  315. }
  316. showmessage('replynotice_error', 'forum.php?mod=viewthread&tid='.$tid);
  317. } elseif($_GET['action'] == 'removeindexheats') {
  318. if($_G['adminid'] != 1) {
  319. showmessage('no_privilege_indexheats');
  320. }
  321. C::t('forum_thread')->update($_G['tid'], array('heats'=>0));
  322. require_once libfile('function/cache');
  323. updatecache('heats');
  324. dheader('Location: '.dreferer());
  325. } elseif($_GET['action'] == 'showdarkroom') {
  326. include_once libfile('class/member');
  327. if($_G['setting']['darkroom']) {
  328. $limit = $_G['tpp'];
  329. $cid = $_GET['cid'] ? dintval($_GET['cid']) : 0;
  330. $crimelist = array();
  331. $i = 0;
  332. foreach(C::t('common_member_crime')->fetch_all_by_cid($cid, array(4, 5), $limit) as $crime) {
  333. $i++;
  334. $cid = $crime['cid'];
  335. if(isset($crimelist[$crime['uid']])) {
  336. continue;
  337. }
  338. $crime['action'] = lang('forum/template', crime_action_ctl::$actions[$crime['action']]);
  339. $crime['dateline'] = dgmdate($crime['dateline'], 'u');
  340. $crimelist[$crime['uid']] = $crime;
  341. }
  342. if($crimelist && $i == $limit) {
  343. $dataexist = 1;
  344. } else {
  345. $dataexist = 0;
  346. }
  347. foreach(C::t('common_member')->fetch_all(array_keys($crimelist)) as $uid => $user) {
  348. if($user['groupid'] == 4 || $user['groupid'] == 5) {
  349. $crimelist[$uid]['username'] = $user['username'];
  350. $crimelist[$uid]['groupexpiry'] = $user['groupexpiry'] ? dgmdate($user['groupexpiry'], 'u') : lang('forum/misc', 'never_expired');
  351. } else {
  352. unset($crimelist[$uid]);
  353. }
  354. }
  355. if($_GET['ajaxdata'] === 'json') {
  356. showmessage(array('dataexist' => $dataexist, 'cid' => $cid), '', $crimelist);
  357. } else {
  358. include_once template("forum/darkroom");
  359. }
  360. exit;
  361. }
  362. showmessage('undefined_action');
  363. } elseif($_GET['action'] == 'shortcut') {
  364. if($_GET['type'] == 'ico') {
  365. $shortcut = @readfile(DISCUZ_ROOT.'favicon.ico');
  366. $filename = 'favicon.ico';
  367. } else {
  368. $shortcut = '[InternetShortcut]
  369. URL='.$_G['siteurl'].'
  370. IconFile='.$_G['siteurl'].'favicon.ico
  371. IconIndex=1
  372. ';
  373. $filename = $_G['setting']['bbname'].'.url';
  374. }
  375. if(!strexists($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
  376. $filename = diconv($filename, CHARSET, 'UTF-8');
  377. } else {
  378. $filename = diconv($filename, CHARSET, 'GBK');
  379. }
  380. dheader('Content-type: application/octet-stream');
  381. dheader('Content-Disposition: attachment; filename="'.$filename.'"');
  382. echo $shortcut;
  383. exit;
  384. } elseif($_GET['action'] == 'livelastpost') {
  385. $fid = dintval($_GET['fid']);
  386. $forum = C::t('forum_forumfield')->fetch($fid);
  387. $livetid = $forum['livetid'];
  388. $postlist = array();
  389. if($livetid) {
  390. $thread = C::t('forum_thread')->fetch($livetid);
  391. $postlist['count'] = $thread['replies'];
  392. $postarr = C::t('forum_post')->fetch_all_by_tid('tid:'.$livetid, $livetid, true, 'DESC', 20);
  393. ksort($postarr);
  394. foreach($postarr as $post) {
  395. if($post['first'] == 1 || getstatus($post['status'], 1)) {
  396. continue;
  397. }
  398. $contentarr = array(
  399. 'authorid' => !$post['anonymous'] ? $post['authorid'] : '',
  400. 'author' => !$post['anonymous'] ? $post['author'] : lang('forum/misc', 'anonymous'),
  401. 'message' => str_replace("\r\n", '<br>', messagecutstr($post['message'])),
  402. 'dateline' => dgmdate($post['dateline'], 'u'),
  403. 'avatar' => !$post['anonymous'] ? avatar($post['authorid'], 'small') : '',
  404. );
  405. $postlist['list'][$post['pid']] = $contentarr;
  406. }
  407. }
  408. showmessage('', '', $postlist);
  409. exit;
  410. } else {
  411. if(empty($_G['forum']['allowview'])) {
  412. if(!$_G['forum']['viewperm'] && !$_G['group']['readaccess']) {
  413. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  414. } elseif($_G['forum']['viewperm'] && !forumperm($_G['forum']['viewperm'])) {
  415. showmessage('forum_nopermission', NULL, array($_G['group']['grouptitle']), array('login' => 1));
  416. }
  417. }
  418. $thread = C::t('forum_thread')->fetch($_G['tid']);
  419. if(!($thread['displayorder']>=0 || $thread['displayorder']==-4 && $thread['authorid']==$_G['uid'])) {
  420. $thread = array();
  421. }
  422. if($thread['readperm'] && $thread['readperm'] > $_G['group']['readaccess'] && !$_G['forum']['ismoderator'] && $thread['authorid'] != $_G['uid']) {
  423. showmessage('thread_nopermission', NULL, array('readperm' => $thread['readperm']), array('login' => 1));
  424. }
  425. if($_G['forum']['password'] && $_G['forum']['password'] != $_G['cookie']['fidpw'.$_G['fid']]) {
  426. showmessage('forum_passwd', "forum.php?mod=forumdisplay&fid=$_G[fid]");
  427. }
  428. if(!$thread) {
  429. showmessage('thread_nonexistence');
  430. }
  431. if($_G['forum']['type'] == 'forum') {
  432. $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> ";
  433. $navtitle = strip_tags($_G['forum']['name']).' - '.$thread['subject'];
  434. } elseif($_G['forum']['type'] == 'sub') {
  435. $fup = C::t('forum_forum')->fetch($_G['forum']['fup']);
  436. $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> ";
  437. $navtitle = strip_tags($fup['name']).' - '.strip_tags($_G['forum']['name']).' - '.$thread['subject'];
  438. }
  439. }
  440. if($_GET['action'] == 'votepoll' && submitcheck('pollsubmit', 1)) {
  441. if(!$_G['group']['allowvote']) {
  442. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  443. } elseif(!empty($thread['closed'])) {
  444. showmessage('thread_poll_closed', NULL, array(), array('login' => 1));
  445. } elseif(empty($_GET['pollanswers'])) {
  446. showmessage('thread_poll_invalid', NULL, array(), array('login' => 1));
  447. }
  448. $pollarray = C::t('forum_poll')->fetch($_G['tid']);
  449. $overt = $pollarray['overt'];
  450. if(!$pollarray) {
  451. showmessage('poll_not_found');
  452. } elseif($pollarray['expiration'] && $pollarray['expiration'] < TIMESTAMP) {
  453. showmessage('poll_overdue', NULL, array(), array('login' => 1));
  454. } elseif($pollarray['maxchoices'] && $pollarray['maxchoices'] < count($_GET['pollanswers'])) {
  455. showmessage('poll_choose_most', NULL, array('maxchoices' => $pollarray['maxchoices']), array('login' => 1));
  456. }
  457. $voterids = $_G['uid'] ? $_G['uid'] : $_G['clientip'];
  458. $polloptionid = array();
  459. $query = C::t('forum_polloption')->fetch_all_by_tid($_G['tid']);
  460. foreach($query as $pollarray) {
  461. if(strexists("\t".$pollarray['voterids']."\t", "\t".$voterids."\t")) {
  462. showmessage('thread_poll_voted', NULL, array(), array('login' => 1));
  463. }
  464. $polloptionid[] = $pollarray['polloptionid'];
  465. }
  466. $polloptionids = array();
  467. foreach($_GET['pollanswers'] as $key => $id) {
  468. if(!in_array($id, $polloptionid)) {
  469. showmessage('parameters_error');
  470. }
  471. unset($polloptionid[$key]);
  472. $polloptionids[] = $id;
  473. }
  474. C::t('forum_polloption')->update_vote($polloptionids, $voterids."\t", 1);
  475. C::t('forum_thread')->update($_G['tid'], array('lastpost'=>$_G['timestamp']), true);
  476. C::t('forum_poll')->update_vote($_G['tid']);
  477. C::t('forum_pollvoter')->insert(array(
  478. 'tid' => $_G['tid'],
  479. 'uid' => $_G['uid'],
  480. 'username' => $_G['username'],
  481. 'options' => implode("\t", $_GET['pollanswers']),
  482. 'dateline' => $_G['timestamp'],
  483. ));
  484. updatecreditbyaction('joinpoll');
  485. $space = array();
  486. space_merge($space, 'field_home');
  487. if($overt && !empty($space['privacy']['feed']['newreply'])) {
  488. $feed['icon'] = 'poll';
  489. $feed['title_template'] = 'feed_thread_votepoll_title';
  490. $feed['title_data'] = array(
  491. 'subject' => "<a href=\"forum.php?mod=viewthread&tid=$_G[tid]\">$thread[subject]</a>",
  492. 'author' => "<a href=\"home.php?mod=space&uid=$thread[authorid]\">$thread[author]</a>",
  493. 'hash_data' => "tid{$_G[tid]}"
  494. );
  495. $feed['id'] = $_G['tid'];
  496. $feed['idtype'] = 'tid';
  497. postfeed($feed);
  498. }
  499. if(!empty($_G['inajax'])) {
  500. showmessage('thread_poll_succeed', "forum.php?mod=viewthread&tid=$_G[tid]".($_GET['from'] ? '&from='.$_GET['from'] : ''), array(), array('location' => true));
  501. } else {
  502. showmessage('thread_poll_succeed', "forum.php?mod=viewthread&tid=$_G[tid]".($_GET['from'] ? '&from='.$_GET['from'] : ''));
  503. }
  504. } elseif($_GET['action'] == 'viewvote') {
  505. if($_G[forum_thread][special] != 1) {
  506. showmessage('thread_poll_none');
  507. }
  508. require_once libfile('function/post');
  509. $polloptionid = is_numeric($_GET['polloptionid']) ? $_GET['polloptionid'] : '';
  510. $page = intval($_GET['page']) ? intval($_GET['page']) : 1;
  511. $perpage = 100;
  512. $pollinfo = C::t('forum_poll')->fetch($_G['tid']);
  513. $overt = $pollinfo['overt'];
  514. $polloptions = array();
  515. $query = C::t('forum_polloption')->fetch_all_by_tid($_G['tid']);
  516. foreach($query as $options) {
  517. if(empty($polloptionid)) {
  518. $polloptionid = $options['polloptionid'];
  519. }
  520. $options['polloption'] = preg_replace("/\[url=(https?){1}:\/\/([^\[\"']+?)\](.+?)\[\/url\]/i",
  521. "<a href=\"\\1://\\2\" target=\"_blank\">\\3</a>", $options['polloption']);
  522. $polloptions[] = $options;
  523. }
  524. $arrvoterids = array();
  525. if($overt || $_G['adminid'] == 1 || $thread['authorid'] == $_G['uid']) {
  526. $polloptioninfo = C::t('forum_polloption')->fetch($polloptionid);
  527. $voterids = $polloptioninfo['voterids'];
  528. $arrvoterids = explode("\t", trim($voterids));
  529. } else {
  530. showmessage('thread_poll_nopermission');
  531. }
  532. if(!empty($arrvoterids)) {
  533. $count = count($arrvoterids);
  534. $multi = $perpage * ($page - 1);
  535. $multipage = multi($count, $perpage, $page, "forum.php?mod=misc&action=viewvote&tid=$_G[tid]&polloptionid=$polloptionid".( $_GET[handlekey] ? "&handlekey=".$_GET[handlekey] : '' ));
  536. $arrvoterids = array_slice($arrvoterids, $multi, $perpage);
  537. }
  538. $voterlist = $voter = array();
  539. if($arrvoterids) {
  540. $voterlist = C::t('common_member')->fetch_all($arrvoterids);
  541. }
  542. include template('forum/viewthread_poll_voter');
  543. } elseif($_GET['action'] == 'rate' && $_GET['pid']) {
  544. $_GET['tid'] = dintval($_GET['tid']);
  545. $_GET['pid'] = dintval($_GET['pid']);
  546. if($_GET['showratetip']) {
  547. include template('forum/rate');
  548. exit();
  549. }
  550. if(!$_G['inajax']) {
  551. showmessage('undefined_action');
  552. }
  553. if(!$_G['group']['raterange']) {
  554. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  555. } elseif($_G['setting']['modratelimit'] && $_G['adminid'] == 3 && !$_G['forum']['ismoderator']) {
  556. showmessage('thread_rate_moderator_invalid', NULL);
  557. }
  558. $reasonpmcheck = $_G['group']['reasonpm'] == 2 || $_G['group']['reasonpm'] == 3 ? 'checked="checked" disabled' : '';
  559. if(($_G['group']['reasonpm'] == 2 || $_G['group']['reasonpm'] == 3) || !empty($_GET['sendreasonpm'])) {
  560. $forumname = strip_tags($_G['forum']['name']);
  561. $sendreasonpm = 1;
  562. } else {
  563. $sendreasonpm = 0;
  564. }
  565. $post = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['pid']);
  566. if($post['invisible'] != 0 || $post['authorid'] == 0) {
  567. $post = array();
  568. }
  569. if(!$post || $post['tid'] != $thread['tid'] || !$post['authorid']) {
  570. showmessage('rate_post_error');
  571. } elseif(!$_G['forum']['ismoderator'] && $_G['setting']['karmaratelimit'] && TIMESTAMP - $post['dateline'] > $_G['setting']['karmaratelimit'] * 3600) {
  572. showmessage('thread_rate_timelimit', NULL, array('karmaratelimit' => $_G['setting']['karmaratelimit']));
  573. } elseif($post['authorid'] == $_G['uid'] || $post['tid'] != $_G['tid']) {
  574. showmessage('thread_rate_member_invalid', NULL);
  575. } elseif($post['anonymous']) {
  576. showmessage('thread_rate_anonymous', NULL);
  577. } elseif($post['status'] & 1) {
  578. showmessage('thread_rate_banned', NULL);
  579. }
  580. $allowrate = TRUE;
  581. if(!$_G['setting']['dupkarmarate']) {
  582. if(C::t('forum_ratelog')->count_by_uid_pid($_G['uid'], $_GET['pid'])) {
  583. showmessage('thread_rate_duplicate', NULL);
  584. }
  585. }
  586. $page = intval($_GET['page']);
  587. require_once libfile('function/misc');
  588. $maxratetoday = getratingleft($_G['group']['raterange']);
  589. if(!submitcheck('ratesubmit')) {
  590. $referer = $_G['siteurl'].'forum.php?mod=viewthread&tid='.$_G['tid'].'&page='.$page.($_GET['from'] ? '&from='.$_GET['from'] : '').'#pid'.$_GET['pid'];
  591. $ratelist = getratelist($_G['group']['raterange']);
  592. include template('forum/rate');
  593. } else {
  594. $reason = checkreasonpm();
  595. $rate = $ratetimes = 0;
  596. $creditsarray = $sub_self_credit = array();
  597. getuserprofile('extcredits1');
  598. foreach($_G['group']['raterange'] as $id => $rating) {
  599. $score = intval($_GET['score'.$id]);
  600. if(isset($_G['setting']['extcredits'][$id]) && !empty($score)) {
  601. if($rating['isself'] && (intval($_G['member']['extcredits'.$id]) - $score < 0)) {
  602. showmessage('thread_rate_range_self_invalid', '', array('extcreditstitle' => $_G['setting']['extcredits'][$id]['title']));
  603. }
  604. if(abs($score) <= $maxratetoday[$id]) {
  605. if($score > $rating['max'] || $score < $rating['min']) {
  606. showmessage('thread_rate_range_invalid');
  607. } else {
  608. $creditsarray[$id] = $score;
  609. if($rating['isself']) {
  610. $sub_self_credit[$id] = -abs($score);
  611. }
  612. $rate += $score;
  613. $ratetimes += ceil(max(abs($rating['min']), abs($rating['max'])) / 5);
  614. }
  615. } else {
  616. showmessage('thread_rate_ctrl');
  617. }
  618. }
  619. }
  620. if(!$creditsarray) {
  621. showmessage('thread_rate_range_invalid', NULL);
  622. }
  623. updatemembercount($post['authorid'], $creditsarray, 1, 'PRC', $_GET['pid']);
  624. if(!empty($sub_self_credit)) {
  625. updatemembercount($_G['uid'], $sub_self_credit, 1, 'RSC', $_GET['pid']);
  626. }
  627. C::t('forum_post')->increase_rate_by_pid('tid:'.$_G['tid'], $_GET['pid'], $rate, $ratetimes);
  628. if($post['first']) {
  629. $threadrate = intval(@($post['rate'] + $rate) / abs($post['rate'] + $rate));
  630. C::t('forum_thread')->update($_G['tid'], array('rate'=>$threadrate));
  631. }
  632. require_once libfile('function/discuzcode');
  633. $sqlvalues = $comma = '';
  634. $sqlreason = censor(trim($_GET['reason']));
  635. $sqlreason = cutstr(dhtmlspecialchars($sqlreason), 40, '.');
  636. foreach($creditsarray as $id => $addcredits) {
  637. $insertarr = array(
  638. 'pid' => $_GET['pid'],
  639. 'uid' => $_G['uid'],
  640. 'username' => $_G['username'],
  641. 'extcredits' => $id,
  642. 'dateline' => $_G['timestamp'],
  643. 'score' => $addcredits,
  644. 'reason' => $sqlreason
  645. );
  646. C::t('forum_ratelog')->insert($insertarr);
  647. }
  648. include_once libfile('function/post');
  649. $_G['forum']['threadcaches'] && @deletethreadcaches($_G['tid']);
  650. $reason = dhtmlspecialchars(censor(trim($reason)));
  651. if($sendreasonpm) {
  652. $ratescore = $slash = '';
  653. foreach($creditsarray as $id => $addcredits) {
  654. $ratescore .= $slash.$_G['setting']['extcredits'][$id]['title'].' '.($addcredits > 0 ? '+'.$addcredits : $addcredits).' '.$_G['setting']['extcredits'][$id]['unit'];
  655. $slash = ' / ';
  656. }
  657. sendreasonpm($post, 'rate_reason', array(
  658. 'tid' => $thread['tid'],
  659. 'pid' => $_GET['pid'],
  660. 'subject' => $thread['subject'],
  661. 'ratescore' => $ratescore,
  662. 'reason' => $reason,
  663. 'from_id' => 0,
  664. 'from_idtype' => 'rate'
  665. ));
  666. }
  667. $logs = array();
  668. foreach($creditsarray as $id => $addcredits) {
  669. $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");
  670. }
  671. update_threadpartake($post['tid']);
  672. C::t('forum_postcache')->delete($_GET['pid']);
  673. writelog('ratelog', $logs);
  674. showmessage('thread_rate_succeed', dreferer());
  675. }
  676. } elseif($_GET['action'] == 'removerate' && $_GET['pid']) {
  677. if(!$_G['forum']['ismoderator'] || !$_G['group']['raterange']) {
  678. showmessage('no_privilege_removerate');
  679. }
  680. $reasonpmcheck = $_G['group']['reasonpm'] == 2 || $_G['group']['reasonpm'] == 3 ? 'checked="checked" disabled' : '';
  681. if(($_G['group']['reasonpm'] == 2 || $_G['group']['reasonpm'] == 3) || !empty($_GET['sendreasonpm'])) {
  682. $forumname = strip_tags($_G['forum']['name']);
  683. $sendreasonpm = 1;
  684. } else {
  685. $sendreasonpm = 0;
  686. }
  687. foreach($_G['group']['raterange'] as $id => $rating) {
  688. $maxratetoday[$id] = $rating['mrpd'];
  689. }
  690. $post = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['pid']);
  691. if($post['invisible'] != 0 || $post['authorid'] == 0) {
  692. $post = array();
  693. }
  694. if(!$post || $post['tid'] != $thread['tid'] || !$post['authorid']) {
  695. showmessage('rate_post_error');
  696. }
  697. require_once libfile('function/misc');
  698. if(!submitcheck('ratesubmit')) {
  699. $referer = $_G['siteurl'].'forum.php?mod=viewthread&tid='.$_G['tid'].'&page='.$page.($_GET['from'] ? '&from='.$_GET['from'] : '').'#pid'.$_GET['pid'];
  700. $ratelogs = array();
  701. foreach(C::t('forum_ratelog')->fetch_all_by_pid($_GET['pid'], 'ASC') as $ratelog) {
  702. $ratelog['dbdateline'] = $ratelog['dateline'];
  703. $ratelog['dateline'] = dgmdate($ratelog['dateline'], 'u');
  704. $ratelog['scoreview'] = $ratelog['score'] > 0 ? '+'.$ratelog['score'] : $ratelog['score'];
  705. $ratelogs[] = $ratelog;
  706. }
  707. include template('forum/rate');
  708. } else {
  709. $reason = checkreasonpm();
  710. if(!empty($_GET['logidarray'])) {
  711. if($sendreasonpm) {
  712. $ratescore = $slash = '';
  713. }
  714. $rate = $ratetimes = 0;
  715. $logs = array();
  716. foreach(C::t('forum_ratelog')->fetch_all_by_pid($_GET['pid']) as $ratelog) {
  717. if(in_array($ratelog['uid'].' '.$ratelog['extcredits'].' '.$ratelog['dateline'], $_GET['logidarray'])) {
  718. $rate += $ratelog['score'] = -$ratelog['score'];
  719. $ratetimes += ceil(max(abs($rating['min']), abs($rating['max'])) / 5);
  720. updatemembercount($post['authorid'], array($ratelog['extcredits'] => $ratelog['score']));
  721. C::t('common_credit_log')->delete_by_uid_operation_relatedid($post['authorid'], 'PRC', $_GET['pid']);
  722. C::t('forum_ratelog')->delete_by_pid_uid_extcredits_dateline($_GET['pid'], $ratelog['uid'], $ratelog['extcredits'], $ratelog['dateline']);
  723. $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");
  724. if($sendreasonpm) {
  725. $ratescore .= $slash.$_G['setting']['extcredits'][$ratelog['extcredits']]['title'].' '.($ratelog['score'] > 0 ? '+'.$ratelog['score'] : $ratelog['score']).' '.$_G['setting']['extcredits'][$ratelog['extcredits']]['unit'];
  726. $slash = ' / ';
  727. }
  728. }
  729. }
  730. C::t('forum_postcache')->delete($_GET['pid']);
  731. writelog('ratelog', $logs);
  732. if($sendreasonpm) {
  733. sendreasonpm($post, 'rate_removereason', array(
  734. 'tid' => $thread['tid'],
  735. 'pid' => $_GET['pid'],
  736. 'subject' => $thread['subject'],
  737. 'ratescore' => $ratescore,
  738. 'reason' => $reason,
  739. 'from_id' => 0,
  740. 'from_idtype' => 'removerate'
  741. ));
  742. }
  743. C::t('forum_post')->increase_rate_by_pid('tid:'.$_G['tid'], $_GET['pid'], $rate, $ratetimes);
  744. if($post['first']) {
  745. $threadrate = @intval(@($post['rate'] + $rate) / abs($post['rate'] + $rate));
  746. C::t('forum_thread')->update($_G['tid'], array('rate'=>$threadrate));
  747. }
  748. }
  749. showmessage('thread_rate_removesucceed', dreferer());
  750. }
  751. } elseif($_GET['action'] == 'viewratings' && $_GET['pid']) {
  752. $loglist = $logcount = array();
  753. $post = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['pid']);
  754. if($post['invisible'] != 0) {
  755. $post = array();
  756. }
  757. if($post) {
  758. $loglist = C::t('forum_ratelog')->fetch_all_by_pid($_GET['pid']);
  759. }
  760. if(empty($post) || empty($loglist)) {
  761. showmessage('thread_rate_log_nonexistence');
  762. }
  763. if($post['tid'] != $thread['tid']) {
  764. showmessage('targetpost_donotbelongto_thisthread');
  765. }
  766. if($_G['setting']['bannedmessages']) {
  767. $postmember = getuserbyuid($post['authorid']);
  768. $post['groupid'] = $postmember['groupid'];
  769. }
  770. foreach($loglist as $k => $log) {
  771. $logcount[$log['extcredits']] += $log['score'];
  772. $log['dateline'] = dgmdate($log['dateline'], 'u');
  773. $log['score'] = $log['score'] > 0 ? '+'.$log['score'] : $log['score'];
  774. $log['reason'] = dhtmlspecialchars($log['reason']);
  775. $loglist[$k] = $log;
  776. }
  777. include template('forum/rate_view');
  778. } elseif($_GET['action'] == 'viewwarning' && $_GET['uid']) {
  779. $warnuser = getuserbyuid($_GET['uid']);
  780. $warnuser = $warnuser['username'];
  781. if(!$warnuser) {
  782. showmessage('member_no_found');
  783. }
  784. $warnings = array();
  785. $warnings = C::t('forum_warning')->fetch_all_by_authorid($_GET['uid']);
  786. if(!$warnings) {
  787. showmessage('thread_warning_nonexistence');
  788. }
  789. foreach($warnings as $key => $warning) {
  790. $warning['dateline'] = dgmdate($warning['dateline'], 'u');
  791. $warning['reason'] = dhtmlspecialchars($warning['reason']);
  792. $warnings[$key] = $warning;
  793. }
  794. $warnnum = count($warnings);
  795. include template('forum/warn_view');
  796. } elseif($_GET['action'] == 'pay') {
  797. if(!isset($_G['setting']['extcredits'][$_G['setting']['creditstransextra'][1]])) {
  798. showmessage('credits_transaction_disabled');
  799. } elseif($thread['price'] <= 0 || $thread['special'] <> 0) {
  800. showmessage('thread_pay_error', NULL);
  801. } elseif(!$_G['uid']) {
  802. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  803. }
  804. if(($balance = getuserprofile('extcredits'.$_G['setting']['creditstransextra'][1]) - $thread['price']) < ($minbalance = 0)) {
  805. if($_G['setting']['creditstrans'][0] == $_G['setting']['creditstransextra'][1]) {
  806. showmessage('credits_balance_insufficient_and_charge', '', array('title' => $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][1]]['title'], 'minbalance' => $thread['price']));
  807. } else {
  808. showmessage('credits_balance_insufficient', '', array('title' => $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][1]]['title'], 'minbalance' => $thread['price']));
  809. }
  810. }
  811. if(C::t('common_credit_log')->count_by_uid_operation_relatedid($_G['uid'], 'BTC', $_G['tid'])) {
  812. showmessage('credits_buy_thread', 'forum.php?mod=viewthread&tid='.$_G['tid'].($_GET['from'] ? '&from='.$_GET['from'] : ''));
  813. }
  814. $thread['netprice'] = floor($thread['price'] * (1 - $_G['setting']['creditstax']));
  815. if(!submitcheck('paysubmit')) {
  816. include template('forum/pay');
  817. } else {
  818. $updateauthor = true;
  819. $authorEarn = $thread['netprice'];
  820. if($_G['setting']['maxincperthread'] > 0) {
  821. $extcredit = 'extcredits'.$_G['setting']['creditstransextra'][1];
  822. $log = C::t('common_credit_log')->count_credit_by_uid_operation_relatedid($thread['authorid'], 'STC', $_G['tid'], $_G['setting']['creditstransextra'][1]);
  823. if($log >= $_G['setting']['maxincperthread']) {
  824. $updateauthor = false;
  825. } else {
  826. $authorEarn = min($_G['setting']['maxincperthread'] - $log['credit'], $thread['netprice']);
  827. }
  828. }
  829. if($updateauthor) {
  830. updatemembercount($thread['authorid'], array($_G['setting']['creditstransextra'][1] => $authorEarn), 1, 'STC', $_G['tid']);
  831. }
  832. updatemembercount($_G['uid'], array($_G['setting']['creditstransextra'][1] => -$thread['price']), 1, 'BTC', $_G['tid']);
  833. showmessage('thread_pay_succeed', "forum.php?mod=viewthread&tid=$_G[tid]".($_GET['from'] ? '&from='.$_GET['from'] : ''));
  834. }
  835. } elseif($_GET['action'] == 'viewpayments') {
  836. $extcreditname = 'extcredits'.$_G['setting']['creditstransextra'][1];
  837. $loglist = array();
  838. $logs = C::t('common_credit_log')->fetch_all_by_uid_operation_relatedid(0, 'BTC', $_G['tid']);
  839. $luids = array();
  840. foreach($logs as $log) {
  841. $luids[$log['uid']] = $log['uid'];
  842. }
  843. $members = C::t('common_member')->fetch_all($luids);
  844. foreach($logs as $log) {
  845. $log['username'] = $members[$log['uid']]['username'];
  846. $log['dateline'] = dgmdate($log['dateline'], 'u');
  847. $log[$extcreditname] = abs($log[$extcreditname]);
  848. $loglist[] = $log;
  849. }
  850. include template('forum/pay_view');
  851. } elseif($_GET['action'] == 'viewthreadmod' && $_G['tid']) {
  852. $modactioncode = lang('forum/modaction');
  853. $loglist = array();
  854. foreach(C::t('forum_threadmod')->fetch_all_by_tid($_G['tid']) as $log) {
  855. $log['dateline'] = dgmdate($log['dateline'], 'u');
  856. $log['expiration'] = !empty($log['expiration']) ? dgmdate($log['expiration'], 'd') : '';
  857. $log['status'] = empty($log['status']) ? 'style="text-decoration: line-through" disabled' : '';
  858. if(!$modactioncode[$log['action']] && preg_match('/S(\d\d)/', $log['action'], $a) || $log['action'] == 'SPA') {
  859. loadcache('stamps');
  860. if($log['action'] == 'SPA') {
  861. $log['action'] = 'SPA'.$log['stamp'];
  862. $stampid = $log['stamp'];
  863. } else {
  864. $stampid = intval($a[1]);
  865. }
  866. $modactioncode[$log['action']] = $modactioncode['SPA'].' '.$_G['cache']['stamps'][$stampid]['text'];
  867. } elseif(preg_match('/L(\d\d)/', $log['action'], $a)) {
  868. loadcache('stamps');
  869. $modactioncode[$log['action']] = $modactioncode['SLA'].' '.$_G['cache']['stamps'][intval($a[1])]['text'];
  870. }
  871. if($log['magicid']) {
  872. loadcache('magics');
  873. $log['magicname'] = $_G['cache']['magics'][$log['magicid']]['name'];
  874. }
  875. $loglist[] = $log;
  876. }
  877. if(empty($loglist)) {
  878. showmessage('threadmod_nonexistence');
  879. }
  880. include template('forum/viewthread_mod');
  881. } elseif($_GET['action'] == 'bestanswer' && $_G['tid'] && $_GET['pid'] && submitcheck('bestanswersubmit')) {
  882. $forward = 'forum.php?mod=viewthread&tid='.$_G['tid'].($_GET['from'] ? '&from='.$_GET['from'] : '');
  883. $post = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['pid'], false);
  884. if($post['tid'] != $_G['tid']) {
  885. $post = array();
  886. }
  887. 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)) {
  888. showmessage('reward_cant_operate');
  889. } elseif($post['authorid'] == $thread['authorid']) {
  890. showmessage('reward_cant_self');
  891. } elseif($thread['price'] < 0) {
  892. showmessage('reward_repeat_selection');
  893. }
  894. updatemembercount($post['authorid'], array($_G['setting']['creditstransextra'][2] => $thread['price']), 1, 'RAC', $_G['tid']);
  895. $thread['price'] = '-'.$thread['price'];
  896. C::t('forum_thread')->update($_G['tid'], array('price'=>$thread['price']));
  897. C::t('forum_post')->update('tid:'.$_G['tid'], $_GET['pid'], array(
  898. 'dateline' => $thread['dateline'] + 1,
  899. ));
  900. $thread['dateline'] = dgmdate($thread['dateline']);
  901. if($_G['uid'] != $thread['authorid']) {
  902. notification_add($thread['authorid'], 'reward', 'reward_question', array(
  903. 'tid' => $thread['tid'],
  904. 'subject' => $thread['subject'],
  905. ));
  906. }
  907. if($thread['authorid'] == $_G['uid']) {
  908. notification_add($post['authorid'], 'reward', 'reward_bestanswer', array(
  909. 'tid' => $thread['tid'],
  910. 'subject' => $thread['subject'],
  911. ));
  912. } else {
  913. notification_add($post['authorid'], 'reward', 'reward_bestanswer_moderator', array(
  914. 'tid' => $thread['tid'],
  915. 'subject' => $thread['subject'],
  916. ));
  917. }
  918. showmessage('reward_completion', $forward);
  919. } elseif($_GET['action'] == 'activityapplies') {
  920. if(!$_G['uid']) {
  921. showmessage('not_loggedin', NULL, array(), array('login' => 1));
  922. }
  923. if(submitcheck('activitysubmit')) {
  924. $activity = C::t('forum_activity')->fetch($_G['tid']);
  925. if($activity['expiration'] && $activity['expiration'] < TIMESTAMP) {
  926. showmessage('activity_stop', NULL, array(), array('login' => 1));
  927. }
  928. $applyinfo = array();
  929. $applyinfo = C::t('forum_activityapply')->fetch_info_for_user($_G['uid'], $_G['tid']);
  930. if($applyinfo && $applyinfo['verified'] < 2) {
  931. showmessage('activity_repeat_apply', NULL, array(), array('login' => 1));
  932. }
  933. $payvalue = intval($_GET['payvalue']);
  934. $payment = $_GET['payment'] ? $payvalue : -1;
  935. $message = cutstr(dhtmlspecialchars($_GET['message']), 200);
  936. $verified = $thread['authorid'] == $_G['uid'] ? 1 : 0;
  937. if($activity['ufield']) {
  938. $ufielddata = array();
  939. $activity['ufield'] = dunserialize($activity['ufield']);
  940. if(!empty($activity['ufield']['userfield'])) {
  941. $censor = discuz_censor::instance();
  942. loadcache('profilesetting');
  943. foreach($activity['ufield']['userfield'] as $filedname) {
  944. $value = $_POST[$filedname];
  945. if(is_array($value)) {
  946. $value = implode(',', $value);
  947. }
  948. $value = cutstr(dhtmlspecialchars(trim($value)), 100, '.');
  949. if($_G['cache']['profilesetting'][$filedname]['formtype'] == 'file' && !preg_match("/^https?:\/\/(.*)?\.(jpg|png|gif|jpeg|bmp)$/i", $value)) {
  950. showmessage('activity_imgurl_error');
  951. }
  952. if(empty($value) && $filedname != 'residedist' && $filedname != 'residecommunity') {
  953. showmessage('activity_exile_field');
  954. }
  955. $ufielddata['userfield'][$filedname] = $value;
  956. }
  957. }
  958. if(!empty($activity['ufield']['extfield'])) {
  959. foreach($activity['ufield']['extfield'] as $fieldid) {
  960. $value = cutstr(dhtmlspecialchars(trim($_GET[''.$fieldid])), 50, '.');
  961. $ufielddata['extfield'][$fieldid] = $value;
  962. }
  963. }
  964. $ufielddata = !empty($ufielddata) ? serialize($ufielddata) : '';
  965. }
  966. if($_G['setting']['activitycredit'] && $activity['credit'] && empty($applyinfo['verified'])) {
  967. checklowerlimit(array('extcredits'.$_G['setting']['activitycredit'] => '-'.$activity['credit']));
  968. updatemembercount($_G['uid'], array($_G['setting']['activitycredit'] => '-'.$activity['credit']), true, 'ACC', $_G['tid']);
  969. }
  970. if($applyinfo && $applyinfo['verified'] == 2) {
  971. $newinfo = array(
  972. 'tid' => $_G['tid'],
  973. 'username' => $_G['username'],
  974. 'uid' => $_G['uid'],
  975. 'message' => $message,
  976. 'verified' => $verified,
  977. 'dateline' => $_G['timestamp'],
  978. 'payment' => $payment,
  979. 'ufielddata' => $ufielddata
  980. );
  981. C::t('forum_activityapply')->update($applyinfo['applyid'], $newinfo);
  982. } else {
  983. $data = array('tid' => $_G['tid'], 'username' => $_G['username'], 'uid' => $_G['uid'], 'message' => $message, 'verified' => $verified, 'dateline' => $_G['timestamp'], 'payment' => $payment, 'ufielddata' => $ufielddata);
  984. C::t('forum_activityapply')->insert($data);
  985. }
  986. $applynumber = C::t('forum_activityapply')->fetch_count_for_thread($_G['tid']);
  987. C::t('forum_activity')->update($_G['tid'], array('applynumber' => $applynumber));
  988. if($thread['authorid'] != $_G['uid']) {
  989. notification_add($thread['authorid'], 'activity', 'activity_notice', array(
  990. 'tid' => $_G['tid'],
  991. 'subject' => $thread['subject'],
  992. ));
  993. $space = array();
  994. space_merge($space, 'field_home');
  995. if(!empty($space['privacy']['feed']['newreply'])) {
  996. $feed['icon'] = 'activity';
  997. $feed['title_template'] = 'feed_reply_activity_title';
  998. $feed['title_data'] = array(
  999. 'subject' => "<a href=\"forum.php?mod=viewthread&tid=$_G[tid]\">$thread[subject]</a>",
  1000. 'hash_data' => "tid{$_G[tid]}"
  1001. );
  1002. $feed['id'] = $_G['tid'];
  1003. $feed['idtype'] = 'tid';
  1004. postfeed($feed);
  1005. }
  1006. }
  1007. 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'));
  1008. } elseif(submitcheck('activitycancel')) {
  1009. C::t('forum_activityapply')->delete_for_user($_G['uid'], $_G['tid']);
  1010. $applynumber = C::t('forum_activityapply')->fetch_count_for_thread($_G['tid']);
  1011. C::t('forum_activity')->update($_G['tid'], array('applynumber' => $applynumber));
  1012. $message = cutstr(dhtmlspecialchars($_GET['message']), 200);
  1013. if($thread['authorid'] != $_G['uid']) {
  1014. notification_add($thread['authorid'], 'activity', 'activity_cancel', array(
  1015. 'tid' => $_G['tid'],
  1016. 'subject' => $thread['subject'],
  1017. 'reason' => $message
  1018. ));
  1019. }
  1020. showmessage('activity_cancel_success', "forum.php?mod=viewthread&tid=$_G[tid]&do=viewapplylist".($_GET['from'] ? '&from='.$_GET['from'] :''), array(), array('showdialog' => 1, 'closetime' => true));
  1021. }
  1022. } elseif($_GET['action'] == 'getactivityapplylist') {
  1023. $pp = $_G['setting']['activitypp'];
  1024. $page = max(1, $_G['page']);
  1025. $start = ($page - 1) * $pp;
  1026. $activity = C::t('forum_activity')->fetch($_G['tid']);
  1027. if(!$activity || $thread['special'] != 4) {
  1028. showmessage('undefined_action');
  1029. }
  1030. $query = C::t('forum_activityapply')->fetch_all_for_thread($_G['tid'], $start, $pp);
  1031. foreach($query as $activityapplies) {
  1032. $activityapplies['dateline'] = dgmdate($activityapplies['dateline']);
  1033. $applylist[] = $activityapplies;
  1034. }
  1035. $multi = multi($activity['applynumber'], $pp, $page, "forum.php?mod=misc&action=getactivityapplylist&tid=$_G[tid]&pid=$_GET[pid]");
  1036. include template('forum/activity_applist_more');
  1037. } elseif($_GET['action'] == 'activityapplylist') {
  1038. $isactivitymaster = $thread['authorid'] == $_G['uid'] ||
  1039. (in_array($_G['group']['radminid'], array(1, 2)) || ($_G['group']['radminid'] == 3 && $_G['forum']['ismoderator'])
  1040. && $_G['group']['alloweditactivity']);
  1041. if(!$isactivitymaster) {
  1042. showmessage('activity_is_not_manager');
  1043. }
  1044. $activity = C::t('forum_activity')->fetch($_G['tid']);
  1045. if(empty($activity) || $thread['special'] != 4) {
  1046. showmessage('activity_is_not_exists');
  1047. }
  1048. if(!submitcheck('applylistsubmit')) {
  1049. $applylist = array();
  1050. $activity['ufield'] = $activity['ufield'] ? dunserialize($activity['ufield']) : array();
  1051. $query = C::t('forum_activityapply')->fetch_all_for_thread($_G['tid'], 0, 500, $_GET['uid'], $isactivitymaster);
  1052. foreach($query as $activityapplies) {
  1053. $ufielddata = '';
  1054. $activityapplies['dateline'] = dgmdate($activityapplies['dateline'], 'u');
  1055. $activityapplies['ufielddata'] = !empty($activityapplies['ufielddata']) ? dunserialize($activityapplies['ufielddata']) : '';
  1056. if($activityapplies['ufielddata']) {
  1057. if($activityapplies['ufielddata']['userfield']) {
  1058. require_once libfile('function/profile');
  1059. loadcache('profilesetting');
  1060. $data = '';
  1061. foreach($activity['ufield']['userfield'] as $fieldid) {
  1062. if($fieldid == 'qq') {
  1063. $fieldid = 'qqnumber';
  1064. }
  1065. $data = profile_show($fieldid, $activityapplies['ufielddata']['userfield']);
  1066. $ufielddata .= '<li>'.$_G['cache']['profilesetting'][$fieldid]['title'].'&nbsp;&nbsp;:&nbsp;&nbsp;';
  1067. if(empty($data)) {
  1068. $ufielddata .= '</li>';
  1069. continue;
  1070. }
  1071. if($_G['cache']['profilesetting'][$fieldid]['formtype'] != 'file') {
  1072. $ufielddata .= $data;
  1073. } else {
  1074. $ufielddata .= '<a href="'.$data.'" target="_blank" onclick="zoom(this, this.href, 0, 0, 0); return false;">'.lang('forum/misc', 'activity_viewimg').'</a>';
  1075. }
  1076. $ufielddata .= '</li>';
  1077. }
  1078. }
  1079. if($activityapplies['ufielddata']['extfield']) {
  1080. foreach($activity['ufield']['extfield'] as $name) {
  1081. $ufielddata .= '<li>'.$name.'&nbsp;&nbsp;:&nbsp;&nbsp;'.$activityapplies['ufielddata']['extfield'][$name].'</li>';
  1082. }
  1083. }
  1084. }
  1085. $activityapplies['ufielddata'] = $ufielddata;
  1086. $applylist[] = $activityapplies;
  1087. }
  1088. $activity['starttimefrom'] = dgmdate($activity['starttimefrom'], 'u');
  1089. $activity['starttimeto'] = $activity['starttimeto'] ? dgmdate($activity['starttimeto'], 'u') : 0;
  1090. $activity['expiration'] = $activity['expiration'] ? dgmdate($activity['expiration'], 'u') : 0;
  1091. include template('forum/activity_applylist');
  1092. } else {
  1093. if(empty($_GET['applyidarray'])) {
  1094. showmessage('activity_choice_applicant');
  1095. } else {
  1096. $reason = cutstr(dhtmlspecialchars($_GET['reason']), 200);
  1097. $tempuid = $uidarray = $unverified = array();
  1098. $query = C::t('forum_activityapply')->fetch_all($_GET['applyidarray']);
  1099. foreach($query as $row) {
  1100. if($row['tid'] == $_G['tid']) {
  1101. $tempusers[$row['uid']] = $row['verified'];
  1102. }
  1103. }
  1104. $query = C::t('common_member')->fetch_all(array_keys($tempusers));
  1105. foreach($query as $user) {
  1106. $uidarray[] = $user['uid'];
  1107. if($tempusers[$user['uid']]['verified'] != 1) {
  1108. $unverified[] = $user['uid'];
  1109. }
  1110. }
  1111. $activity_subject = $thread['subject'];
  1112. if($_GET['operation'] == 'notification') {
  1113. if(empty($uidarray)) {
  1114. showmessage('activity_notification_user');
  1115. }
  1116. if(empty($reason)) {
  1117. showmessage('activity_notification_reason');
  1118. }
  1119. if($uidarray) {
  1120. foreach($uidarray as $uid) {
  1121. notification_add($uid, 'activity', 'activity_notification', array('tid' => $_G['tid'], 'subject' => $activity_subject, 'msg' => $reason));
  1122. }
  1123. showmessage('activity_notification_success', "forum.php?mod=viewthread&tid=$_G[tid]&do=viewapplylist".($_GET['from'] ? '&from='.$_GET['from'] : ''), array(), array('showdialog' => 1, 'closetime' => true));
  1124. }
  1125. } elseif($_GET['operation'] == 'delete') {
  1126. if($uidarray) {
  1127. C::t('forum_activityapply')->delete_for_thread($_G['tid'], $_GET['applyidarray']);
  1128. foreach($uidarray as $uid) {
  1129. notification_add($uid, 'activity', 'activity_delete', array(
  1130. 'tid' => $_G['tid'],
  1131. 'subject' => $activity_subject,
  1132. 'reason' => $reason,
  1133. ));
  1134. }
  1135. }
  1136. $applynumber = C::t('forum_activityapply')->fetch_count_for_thread($_G['tid']);
  1137. C::t('forum_activity')->update($_G['tid'], array('applynumber' => $applynumber));
  1138. showmessage('activity_delete_completion', "forum.php?mod=viewthread&tid=$_G[tid]&do=viewapplylist".($_GET['from'] ? '&from='.$_GET['from'] : ''), array(), array('showdialog' => 1, 'closetime' => true));
  1139. } else {
  1140. if($unverified) {
  1141. $verified = $_GET['operation'] == 'replenish' ? 2 : 1;
  1142. C::t('forum_activityapply')->update_verified_for_thread($verified, $_G['tid'], $_GET['applyidarray']);
  1143. $notification_lang = $verified == 1 ? 'activity_apply' : 'activity_replenish';
  1144. foreach($unverified as $uid) {
  1145. notification_add($uid, 'activity', $notification_lang, array(
  1146. 'tid' => $_G['tid'],
  1147. 'subject' => $activity_subject,
  1148. 'reason' => $reason,
  1149. ));
  1150. }
  1151. }
  1152. $applynumber = C::t('forum_activityapply')->fetch_count_for_thread($_G['tid']);
  1153. C::t('forum_activity')->update($_G['tid'], array('applynumber' => $applynumber));
  1154. showmessage('activity_auditing_completion', "forum.php?mod=viewthread&tid=$_G[tid]&do=viewapplylist".($_GET['from'] ? '&from='.$_GET['from'] : ''), array(), array('showdialog' => 1, 'closetime' => true));
  1155. }
  1156. }
  1157. }
  1158. } elseif($_GET['action'] == 'activityexport') {
  1159. $isactivitymaster = $thread['authorid'] == $_G['uid'] ||
  1160. (in_array($_G['group']['radminid'], array(1, 2)) || ($_G['group']['radminid'] == 3 && $_G['forum']['ismoderator'])
  1161. && $_G['group']['alloweditactivity']);
  1162. if(!$isactivitymaster) {
  1163. showmessage('activity_is_not_manager');
  1164. }
  1165. $activity = C::t('forum_activity')->fetch($_G['tid']);
  1166. $postinfo = C::t('forum_post')->fetch_threadpost_by_tid_invisible($_G['tid']);
  1167. $activity['message'] = $postinfo['message'];
  1168. if(empty($activity) || $thread['special'] != 4) {
  1169. showmessage('activity_is_not_exists');
  1170. }
  1171. $ufield = '';
  1172. if($activity['ufield']) {
  1173. $activity['ufield'] = dunserialize($activity['ufield']);
  1174. if($activity['ufield']['userfield']) {
  1175. loadcache('profilesetting');
  1176. foreach($activity['ufield']['userfield'] as $fieldid) {
  1177. $ufield .= ','.$_G['cache']['profilesetting'][$fieldid]['title'];
  1178. }
  1179. }
  1180. if($activity['ufield']['extfield']) {
  1181. foreach($activity['ufield']['extfield'] as $extname) {
  1182. $ufield .= ','.$extname;
  1183. }
  1184. }
  1185. }
  1186. $activity['starttimefrom'] = dgmdate($activity['starttimefrom'], 'dt');
  1187. $activity['starttimeto'] = $activity['starttimeto'] ? dgmdate($activity['starttimeto'], 'dt') : 0;
  1188. $activity['expiration'] = $activity['expiration'] ? dgmdate($activity['expiration'], 'dt') : 0;
  1189. $activity['message'] = trim(preg_replace('/\[.+?\]/', '', $activity['message']));
  1190. $applynumbers = C::t('forum_activityapply')->fetch_count_for_thread($_G['tid']);
  1191. $applylist = array();
  1192. $query = C::t('forum_activityapply')->fetch_all_for_thread($_G['tid'], 0, 2000, 0, 1);
  1193. foreach($query as $apply) {
  1194. $apply = str_replace(',', lang('forum/thread', 't_comma'), $apply);
  1195. $apply['dateline'] = dgmdate($apply['dateline'], 'dt');
  1196. $apply['ufielddata'] = !empty($apply['ufielddata']) ? dunserialize($apply['ufielddata']) : '';
  1197. $ufielddata = '';
  1198. if($apply['ufielddata'] && $activity['ufield']) {
  1199. if($apply['ufielddata']['userfield'] && $activity['ufield']['userfield']) {
  1200. require_once libfile('function/profile');
  1201. loadcache('profilesetting');
  1202. foreach($activity['ufield']['userfield'] as $fieldid) {
  1203. if($fieldid == 'qq') {
  1204. $fieldid = 'qqnumber';
  1205. }
  1206. $data = profile_show($fieldid, $apply['ufielddata']['userfield']);
  1207. if(strlen($data) > 11 && is_numeric($data)) {
  1208. $data = '['.$data.']';
  1209. }
  1210. $ufielddata .= ','.strip_tags(str_replace('&nbsp;', ' ', $data));
  1211. }
  1212. }
  1213. if($activity['ufield']['extfield']) {
  1214. foreach($activity['ufield']['extfield'] as $extname) {
  1215. if(strlen($apply['ufielddata']['extfield'][$extname]) > 11 && is_numeric($apply['ufielddata']['extfield'][$extname])) {
  1216. $apply['ufielddata']['extfield'][$extname] = '['.$apply['ufielddata']['extfield'][$extname].']';
  1217. }
  1218. $ufielddata .= ','.strip_tags(str_replace('&nbsp;', ' ', $apply['ufielddata']['extfield'][$extname]));
  1219. }
  1220. }
  1221. }
  1222. $apply['fielddata'] = $ufielddata;
  1223. if(strlen($apply['message']) > 11 && is_numeric($apply['message'])) {
  1224. $apply['message'] = '['.$apply['message'].']';
  1225. }
  1226. $applylist[] = $apply;
  1227. }
  1228. $filename = "activity_{$_G[tid]}.csv";
  1229. include template('forum/activity_export');
  1230. $csvstr = ob_get_contents();
  1231. ob_end_clean();
  1232. header('Content-Encoding: none');
  1233. header('Content-Type: application/octet-stream');
  1234. header('Content-Disposition: attachment; filename='.$filename);
  1235. header('Pragma: no-cache');
  1236. header('Expires: 0');
  1237. if($_G['charset'] != 'gbk') {
  1238. $csvstr = diconv($csvstr, $_G['charset'], 'GBK');
  1239. }
  1240. echo $csvstr;
  1241. } elseif($_GET['action'] == 'tradeorder') {
  1242. $trades = array();
  1243. $query = C::t('forum_trade')->fetch_all_thread_goods($_G['tid']);
  1244. if($thread['authorid'] != $_G['uid'] && !$_G['group']['allowedittrade']) {
  1245. showmessage('no_privilege_tradeorder');
  1246. }
  1247. if(!submitcheck('tradesubmit')) {
  1248. $stickcount = 0;$trades = $tradesstick = array();
  1249. foreach($query as $trade) {
  1250. $stickcount = $trade['displayorder'] > 0 ? $stickcount + 1 : $stickcount;
  1251. $trade['displayorderview'] = $trade['displayorder'] < 0 ? 128 + $trade['displayorder'] : $trade['displayorder'];
  1252. if($trade['expiration']) {
  1253. $trade['expiration'] = ($trade['expiration'] - TIMESTAMP) / 86400;
  1254. if($trade['expiration'] > 0) {
  1255. $trade['expirationhour'] = floor(($trade['expiration'] - floor($trade['expiration'])) * 24);
  1256. $trade['expiration'] = floor($trade['expiration']);
  1257. } else {
  1258. $trade['expiration'] = -1;
  1259. }
  1260. }
  1261. if($trade['displayorder'] < 0) {
  1262. $trades[] = $trade;
  1263. } else {
  1264. $tradesstick[] = $trade;
  1265. }
  1266. }
  1267. $trades = array_merge($tradesstick, $trades);
  1268. include template('forum/trade_displayorder');
  1269. } else {
  1270. $count = 0;
  1271. foreach($query as $trade) {
  1272. $displayordernew = abs(intval($_GET['displayorder'][$trade['pid']]));
  1273. $displayordernew = $displayordernew > 128 ? 0 : $displayordernew;
  1274. if($_GET['stick'][$trade['pid']]) {
  1275. $count++;
  1276. $displayordernew = $displayordernew == 0 ? 1 : $displayordernew;
  1277. }
  1278. if(!$_GET['stick'][$trade['pid']] || $displayordernew > 0 && $_G['group']['tradestick'] < $count) {
  1279. $displayordernew = -1 * (128 - $displayordernew);
  1280. }
  1281. C::t('forum_trade')->update($_G['tid'], $trade['pid'], array('displayorder' => $displayordernew));
  1282. }
  1283. showmessage('trade_displayorder_updated', "forum.php?mod=viewthread&tid=$_G[tid]".($_GET['from'] ? '&from='.$_GET['from'] : ''));
  1284. }
  1285. } elseif($_GET['action'] == 'debatevote') {
  1286. if(!empty($thread['closed'])) {
  1287. showmessage('thread_poll_closed');
  1288. }
  1289. if(!$_G['uid']) {
  1290. showmessage('debate_poll_nopermission', NULL, array(), array('login' => 1));
  1291. }
  1292. $isfirst = empty($_GET['pid']) ? TRUE : FALSE;
  1293. $debate = C::t('forum_debate')->fetch($_G['tid']);
  1294. if(empty($debate)) {
  1295. showmessage('debate_nofound');
  1296. }
  1297. if($isfirst) {
  1298. $stand = intval($_GET['stand']);
  1299. if($stand == 1 || $stand == 2) {
  1300. if(strpos("\t".$debate['affirmvoterids'], "\t{$_G['uid']}\t") !== FALSE || strpos("\t".$debate['negavoterids'], "\t{$_G['uid']}\t") !== FALSE) {
  1301. showmessage('debate_poll_voted');
  1302. } elseif($debate['endtime'] && $debate['endtime'] < TIMESTAMP) {
  1303. showmessage('debate_poll_end');
  1304. }
  1305. }
  1306. C::t('forum_debate')->update_voters($_G['tid'], $_G['uid'], $stand);
  1307. showmessage('debate_poll_succeed', 'forum.php?mod=viewthread&tid='.$_G['tid'], array(), array('showmsg' => 1, 'locationtime' => true));
  1308. }
  1309. $debatepost = C::t('forum_debatepost')->fetch($_GET['pid']);
  1310. if(empty($debatepost) || $debatepost['tid'] != $_G['tid']) {
  1311. showmessage('debate_nofound');
  1312. }
  1313. $debate = array_merge($debate, $debatepost);
  1314. unset($debatepost);
  1315. if($debate['uid'] == $_G['uid']) {
  1316. showmessage('debate_poll_myself', "forum.php?mod=viewthread&tid=$_G[tid]".($_GET['from'] ? '&from='.$_GET['from'] : ''), array(), array('showmsg' => 1));
  1317. } elseif(strpos("\t".$debate['voterids'], "\t$_G[uid]\t") !== FALSE) {
  1318. showmessage('debate_poll_voted', "forum.php?mod=viewthread&tid=$_G[tid]".($_GET['from'] ? '&from='.$_GET['from'] : ''), array(), array('showmsg' => 1));
  1319. } elseif($debate['endtime'] && $debate['endtime'] < TIMESTAMP) {
  1320. showmessage('debate_poll_end', "forum.php?mod=viewthread&tid=$_G[tid]".($_GET['from'] ? '&from='.$_GET['from'] : ''), array(), array('showmsg' => 1));
  1321. }
  1322. C::t('forum_debatepost')->update_voters($_GET['pid'], $_G['uid']);
  1323. showmessage('debate_poll_succeed', "forum.php?mod=viewthread&tid=$_G[tid]".($_GET['from'] ? '&from='.$_GET['from'] : ''), array(), array('showmsg' => 1));
  1324. } elseif($_GET['action'] == 'debateumpire') {
  1325. $debate = C::t('forum_debate')->fetch($_G['tid']);
  1326. if(empty($debate)) {
  1327. showmessage('debate_nofound');
  1328. }elseif(!empty($thread['closed']) && TIMESTAMP - $debate['endtime'] > 3600) {
  1329. showmessage('debate_umpire_edit_invalid');
  1330. } elseif($_G['member']['username'] != $debate['umpire']) {
  1331. showmessage('debate_umpire_nopermission');
  1332. }
  1333. $debate = array_merge($debate, $thread);
  1334. if(!submitcheck('umpiresubmit')) {
  1335. $candidates = array();
  1336. $uids = array();
  1337. $voters = C::t('forum_debatepost')->fetch_all_voters($_G['tid'], 30);
  1338. foreach($voters as $candidate) {
  1339. $uids[] = $candidate['uid'];
  1340. }
  1341. $users = C::t('common_member')->fetch_all_username_by_uid($uids);
  1342. foreach($voters as $candidate) {
  1343. $candidate['username'] = dhtmlspecialchars($users[$candidate['uid']]);
  1344. $candidates[$candidate['username']] = $candidate;
  1345. }
  1346. $winnerchecked = array($debate['winner'] => ' checked="checked"');
  1347. list($debate['bestdebater']) = preg_split("/\s/", $debate['bestdebater']);
  1348. include template('forum/debate_umpire');
  1349. } else {
  1350. if(empty($_GET['bestdebater'])) {
  1351. showmessage('debate_umpire_nofound_bestdebater');
  1352. } elseif(empty($_GET['winner'])) {
  1353. showmessage('debate_umpire_nofound_winner');
  1354. } elseif(empty($_GET['umpirepoint'])) {
  1355. showmessage('debate_umpire_nofound_point');
  1356. }
  1357. $bestdebateruid = C::t('common_member')->fetch_uid_by_username($_GET['bestdebater']);
  1358. if(!$bestdebateruid) {
  1359. showmessage('debate_umpire_bestdebater_invalid');
  1360. }
  1361. if(!($bestdebaterstand = C::t('forum_debatepost')->get_stand_by_bestuid($_G['tid'], $bestdebateruid, array($debate['uid'], $_G['uid'])))) {
  1362. showmessage('debate_umpire_bestdebater_invalid');
  1363. }
  1364. list($bestdebatervoters, $bestdebaterreplies) = C::t('forum_debatepost')->get_numbers_by_bestuid($_G['tid'], $bestdebateruid);
  1365. $umpirepoint = dhtmlspecialchars($_GET['umpirepoint']);
  1366. $bestdebater = dhtmlspecialchars($_GET['bestdebater']);
  1367. $winner = intval($_GET['winner']);
  1368. C::t('forum_thread')->update($_G['tid'], array('closed' => 1));
  1369. C::t('forum_debate')->update($_G['tid'], array('umpirepoint' => $umpirepoint, 'winner' => $winner, 'bestdebater' => "$bestdebater\t$bestdebateruid\t$bestdebaterstand\t$bestdebatervoters\t$bestdebaterreplies", 'endtime' => $_G['timestamp']));
  1370. showmessage('debate_umpire_comment_succeed', 'forum.php?mod=viewthread&tid='.$_G['tid'].($_GET['from'] ? '&from='.$_GET['from'] : ''));
  1371. }
  1372. } elseif($_GET['action'] == 'recommend') {
  1373. dsetcookie('discuz_recommend', '', -1, 0);
  1374. if(empty($_G['uid'])) {
  1375. showmessage('to_login', null, array(), array('showmsg' => true, 'login' => 1));
  1376. }
  1377. if(empty($_GET['hash']) || $_GET['hash'] != formhash()) {
  1378. showmessage('submit_invalid');
  1379. }
  1380. if(!$_G['setting']['recommendthread']['status'] || !$_G['group']['allowrecommend']) {
  1381. showmessage('no_privilege_recommend');
  1382. }
  1383. if($thread['authorid'] == $_G['uid'] && !$_G['setting']['recommendthread']['ownthread']) {
  1384. showmessage('recommend_self_disallow', '', array('recommendc' => $thread['recommends']), array('msgtype' => 3));
  1385. }
  1386. if(C::t('forum_memberrecommend')->fetch_by_recommenduid_tid($_G['uid'], $_G['tid'])) {
  1387. showmessage('recommend_duplicate', '', array('recommendc' => $thread['recommends']), array('msgtype' => 3));
  1388. }
  1389. $recommendcount = C::t('forum_memberrecommend')->count_by_recommenduid_dateline($_G['uid'], $_G['timestamp']-86400);
  1390. if($_G['setting']['recommendthread']['daycount'] && $recommendcount >= $_G['setting']['recommendthread']['daycount']) {
  1391. showmessage('recommend_outoftimes', '', array('recommendc' => $thread['recommends']), array('msgtype' => 3));
  1392. }
  1393. $_G['group']['allowrecommend'] = intval($_GET['do'] == 'add' ? $_G['group']['allowrecommend'] : -$_G['group']['allowrecommend']);
  1394. $fieldarr = array();
  1395. if($_GET['do'] == 'add') {
  1396. $heatadd = 'recommend_add=recommend_add+1';
  1397. $fieldarr['recommend_add'] = 1;
  1398. } else {
  1399. $heatadd = 'recommend_sub=recommend_sub+1';
  1400. $fieldarr['recommend_sub'] = 1;
  1401. }
  1402. update_threadpartake($_G['tid']);
  1403. $fieldarr['heats'] = 0;
  1404. $fieldarr['recommends'] = $_G['group']['allowrecommend'];
  1405. C::t('forum_thread')->increase($_G['tid'], $fieldarr);
  1406. C::t('forum_thread')->update($_G['tid'], array('lastpost' => TIMESTAMP));
  1407. C::t('forum_memberrecommend')->insert(array('tid'=>$_G['tid'], 'recommenduid'=>$_G['uid'], 'dateline'=>$_G['timestamp']));
  1408. dsetcookie('recommend', 1, 43200);
  1409. $recommendv = $_G['group']['allowrecommend'] > 0 ? '+'.$_G['group']['allowrecommend'] : $_G['group']['allowrecommend'];
  1410. if($_G['setting']['recommendthread']['daycount']) {
  1411. $daycount = $_G['setting']['recommendthread']['daycount'] - $recommendcount;
  1412. showmessage('recommend_daycount_succeed', '', array('recommendv' => $recommendv, 'recommendc' => $thread['recommends'], 'daycount' => $daycount), array('msgtype' => 3));
  1413. } else {
  1414. showmessage('recommend_succeed', '', array('recommendv' => $recommendv, 'recommendc' => $thread['recommends']), array('msgtype' => 3));
  1415. }
  1416. } elseif($_GET['action'] == 'protectsort') {
  1417. $tid = $_GET['tid'];
  1418. $optionid = $_GET['optionid'];
  1419. include template('common/header_ajax');
  1420. $typeoptionvarvalue = C::t('forum_typeoptionvar')->fetch_all_by_tid_optionid($tid, $optionid);
  1421. $typeoptionvarvalue[0]['expiration'] = $typeoptionvarvalue[0]['expiration'] && $typeoptionvarvalue[0]['expiration'] <= TIMESTAMP ? 1 : 0;
  1422. $option = C::t('forum_typeoption')->fetch($optionid);
  1423. if(($option['expiration'] && !$typeoptionvarvalue[0]['expiration']) || empty($option['expiration'])) {
  1424. $protect = dunserialize($option['protect']);
  1425. include_once libfile('function/threadsort');
  1426. if(protectguard($protect)) {
  1427. if(empty($option['permprompt'])) {
  1428. echo lang('forum/misc', 'view_noperm');
  1429. } else {
  1430. echo $option['permprompt'];
  1431. }
  1432. } else {
  1433. echo nl2br($typeoptionvarvalue[0]['value']);
  1434. }
  1435. } else {
  1436. echo lang('forum/misc', 'has_expired');
  1437. }
  1438. include template('common/footer_ajax');
  1439. } elseif($_GET['action'] == 'usertag') {
  1440. if($_G['tid']) {
  1441. if(!submitcheck('addusertag')) {
  1442. $recent_use_tag = $lastlog = $polloptions = array();
  1443. $i = 0;
  1444. $query = C::t('common_tagitem')->select(0, 0, 'uid', 'tagid', 'DESC', 200);
  1445. foreach($query as $result) {
  1446. if($i > 4) {
  1447. break;
  1448. }
  1449. if($recent_use_tag[$result['tagid']] == '') {
  1450. $i++;
  1451. }
  1452. $recent_use_tag[$result['tagid']] = 1;
  1453. }
  1454. if($recent_use_tag) {
  1455. $query = C::t('common_tag')->fetch_all(array_keys($recent_use_tag));
  1456. foreach($query as $result) {
  1457. $recent_use_tag[$result[tagid]] = $result['tagname'];
  1458. }
  1459. }
  1460. foreach(C::t('forum_threadmod')->fetch_all_by_tid($_G['tid'], 'AUT', 3) as $row) {
  1461. $row['dateline'] = dgmdate($row['dateline'], 'u');
  1462. $lastlog[] = $row;
  1463. }
  1464. if($_G['thread']['special'] == 1) {
  1465. $query = C::t('forum_polloption')->fetch_all_by_tid($_G['tid']);
  1466. foreach($query as $polloption) {
  1467. if($polloption['votes'] > 0) {
  1468. $polloptions[] = $polloption;
  1469. }
  1470. }
  1471. if(empty($polloptions)) {
  1472. showmessage('thread_poll_voter_isnull', '', array('haserror' => 1));
  1473. }
  1474. } elseif($_G['thread']['special'] == 4) {
  1475. $activityapplys = C::t('forum_activityapply')->fetch_all_for_thread($_G['tid'], 0, 1);
  1476. if(empty($activityapplys)) {
  1477. showmessage('thread_activityapply_isnull', '', array('haserror' => 1));
  1478. }
  1479. }
  1480. } else {
  1481. $class_tag = new tag();
  1482. $tagarray = $class_tag->add_tag($_GET['tags'], 0, 'uid', 1);
  1483. if($tagarray) {
  1484. $uids = array();
  1485. if($_G['thread']['special'] == 1) {
  1486. if($_GET['polloptions']) {
  1487. $query = C::t('forum_polloption')->fetch_all($_GET['polloptions']);
  1488. } else {
  1489. $query = C::t('forum_polloption')->fetch_all_by_tid($_G['tid']);
  1490. }
  1491. $uids = '';
  1492. foreach($query as $row) {
  1493. $uids .= $row['voterids'];
  1494. }
  1495. if($uids) {
  1496. $uids = explode("\t", trim($uids));
  1497. }
  1498. } elseif($_G['thread']['special'] == 4) {
  1499. $query = C::t('forum_activityapply')->fetch_all_for_thread($_G['tid'], 0, 2000);
  1500. foreach($query as $row) {
  1501. $uids[] = $row['uid'];
  1502. }
  1503. } else {
  1504. foreach(C::t('forum_post')->fetch_all_by_tid('tid:'.$_G['tid'], $_G['tid'], false) as $author) {
  1505. $uids[] = $author['authorid'];
  1506. }
  1507. }
  1508. $uids = @array_unique($uids);
  1509. $count = count($uids);
  1510. $limit = intval($_GET['limit']);
  1511. $per = 200;
  1512. $uids = @array_slice($uids, $limit, $per);
  1513. if($uids) {
  1514. foreach($uids as $uid) {
  1515. if(empty($uid)) continue;
  1516. foreach($tagarray as $tagid => $tagname) {
  1517. C::t('common_tagitem')->insert(array('tagid' => $tagid, 'itemid' => $uid, 'idtype' => 'uid'), 0, 1);
  1518. }
  1519. }
  1520. updatemodlog($_G['tid'], 'AUT', 0, 0, implode(',', $tagarray));
  1521. showmessage('forum_usertag_set_continue', '', array('limit' => $limit, 'next' => min($limit + $per, $count), 'count' => $count), array('alert' => 'right'));
  1522. }
  1523. showmessage('forum_usertag_succeed', '', array(), array('alert' => 'right'));
  1524. } else {
  1525. showmessage('parameters_error', '', array('haserror' => 1));
  1526. }
  1527. }
  1528. } else {
  1529. showmessage('parameters_error', '', array('haserror' => 1));
  1530. }
  1531. include_once template("forum/usertag");
  1532. } elseif($_GET['action'] == 'postreview') {
  1533. if(!$_G['setting']['repliesrank'] || empty($_G['uid'])) {
  1534. showmessage('to_login', null, array(), array('showmsg' => true, 'login' => 1));
  1535. }
  1536. if(empty($_GET['hash']) || $_GET['hash'] != formhash()) {
  1537. showmessage('submit_invalid');
  1538. }
  1539. $doArray = array('support', 'against');
  1540. $post = C::t('forum_post')->fetch('tid:'.$_GET['tid'], $_GET['pid'], false);
  1541. if(!in_array($_GET['do'], $doArray) || empty($post) || $post['first'] == 1 || ($_G['setting']['threadfilternum'] && $_G['setting']['filterednovote'] && getstatus($post['status'], 11))) {
  1542. showmessage('undefined_action', NULL);
  1543. }
  1544. $hotreply = C::t('forum_hotreply_number')->fetch_by_pid($post['pid']);
  1545. if($_G['uid'] == $post['authorid']) {
  1546. showmessage('noreply_yourself_error', '', array(), array('msgtype' => 3));
  1547. }
  1548. if(empty($hotreply)) {
  1549. $hotreply['pid'] = C::t('forum_hotreply_number')->insert(array(
  1550. 'pid' => $post['pid'],
  1551. 'tid' => $post['tid'],
  1552. 'support' => 0,
  1553. 'against' => 0,
  1554. 'total' => 0,
  1555. ), true);
  1556. } else {
  1557. if(C::t('forum_hotreply_member')->fetch($post['pid'], $_G['uid'])) {
  1558. showmessage('noreply_voted_error', '', array(), array('msgtype' => 3));
  1559. }
  1560. }
  1561. $typeid = $_GET['do'] == 'support' ? 1 : 0;
  1562. C::t('forum_hotreply_number')->update_num($post['pid'], $typeid);
  1563. C::t('forum_hotreply_member')->insert(array(
  1564. 'tid' => $post['tid'],
  1565. 'pid' => $post['pid'],
  1566. 'uid' => $_G['uid'],
  1567. 'attitude' => $typeid,
  1568. ));
  1569. $hotreply[$_GET['do']]++;
  1570. showmessage('thread_poll_succeed', '', array(), array('msgtype' => 3, 'extrajs' => '<script type="text/javascript">postreviewupdate('.$post['pid'].', '.$typeid.');</script>'));
  1571. } elseif($_GET['action'] == 'hidden') {
  1572. if($_GET['formhash'] != FORMHASH) {
  1573. showmessage('undefined_action', NULL);
  1574. }
  1575. if(!$_G['uid']) {
  1576. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  1577. }
  1578. if(in_array($thread['fid'], $_G['setting']['security_forums_white_list']) || $thread['displayorder'] > 0 || $thread['highlight'] || $thread['digest'] || $thread['stamp'] > -1) {
  1579. showmessage('thread_hidden_error', NULL);
  1580. }
  1581. $member = C::t('common_member')->fetch($thread['authorid']);
  1582. if(in_array($member['groupid'], $_G['setting']['security_usergroups_white_list'])) {
  1583. showmessage('thread_hidden_error', NULL);
  1584. }
  1585. if(C::t('forum_forumrecommend')->fetch($thread['tid'])) {
  1586. showmessage('thread_hidden_error', NULL);
  1587. }
  1588. C::t('forum_threadhidelog')->insert($_GET['tid'], $_G['uid']);
  1589. if($thread['hidden'] + 1 == $_G['setting']['threadhidethreshold']) {
  1590. notification_add($thread['authorid'], 'post', 'thread_hidden', array('tid' => $thread['tid'], 'subject' => $thread['subject']), 1);
  1591. }
  1592. $thide = explode('|', $_G['cookie']['thide']);
  1593. $thide = array_slice($thide, -20);
  1594. if(!in_array($_GET['tid'], $thide)) {
  1595. $thide[] = $_GET['tid'];
  1596. }
  1597. dsetcookie('thide', implode('|', $thide), 2592000);
  1598. showmessage('thread_hidden_success', dreferer(), array(), array('showdialog' => true, 'closetime' => true, 'extrajs' => '<script type="text/javascript" reload="1">$(\'normalthread_'.$_GET['tid'].'\').style.display = \'none\'</script>'));
  1599. } elseif($_GET['action'] == 'hiderecover') {
  1600. if($_GET['formhash'] != FORMHASH) {
  1601. showmessage('undefined_action', NULL);
  1602. }
  1603. $seccodecheck = true;
  1604. if(submitcheck('hiderecoversubmit')) {
  1605. C::t('forum_threadhidelog')->delete_by_tid($_GET['tid']);
  1606. showmessage('thread_hiderecover_success', dreferer());
  1607. } else {
  1608. include template('forum/hiderecover');
  1609. }
  1610. }
  1611. function getratelist($raterange) {
  1612. global $_G;
  1613. $maxratetoday = getratingleft($raterange);
  1614. $ratelist = array();
  1615. foreach($raterange as $id => $rating) {
  1616. if(isset($_G['setting']['extcredits'][$id])) {
  1617. $ratelist[$id] = '';
  1618. $rating['max'] = $rating['max'] < $maxratetoday[$id] ? $rating['max'] : $maxratetoday[$id];
  1619. $rating['min'] = -$rating['min'] < $maxratetoday[$id] ? $rating['min'] : -$maxratetoday[$id];
  1620. $offset = abs(ceil(($rating['max'] - $rating['min']) / 10));
  1621. if($rating['max'] > $rating['min']) {
  1622. for($vote = $rating['max']; $vote >= $rating['min']; $vote -= $offset) {
  1623. $ratelist[$id] .= $vote ? '<li>'.($vote > 0 ? '+'.$vote : $vote).'</li>' : '';
  1624. }
  1625. }
  1626. }
  1627. }
  1628. return $ratelist;
  1629. }
  1630. function getratingleft($raterange) {
  1631. global $_G;
  1632. $maxratetoday = array();
  1633. foreach($raterange as $id => $rating) {
  1634. $maxratetoday[$id] = $rating['mrpd'];
  1635. }
  1636. foreach(C::t('forum_ratelog')->fetch_all_sum_score($_G['uid'], $_G['timestamp']-86400) as $rate) {
  1637. $maxratetoday[$rate['extcredits']] = $raterange[$rate['extcredits']]['mrpd'] - $rate['todayrate'];
  1638. }
  1639. return $maxratetoday;
  1640. }
  1641. ?>