forum_ajax.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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_ajax.php 36278 2016-12-09 07:52:35Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. define('NOROBOT', TRUE);
  12. if($_GET['action'] == 'checkusername') {
  13. $username = trim($_GET['username']);
  14. $usernamelen = dstrlen($username);
  15. if($usernamelen < 3) {
  16. showmessage('profile_username_tooshort', '', array(), array('handle' => false));
  17. } elseif($usernamelen > 15) {
  18. showmessage('profile_username_toolong', '', array(), array('handle' => false));
  19. }
  20. loaducenter();
  21. $ucresult = uc_user_checkname($username);
  22. if($ucresult == -1) {
  23. showmessage('profile_username_illegal', '', array(), array('handle' => false));
  24. } elseif($ucresult == -2) {
  25. showmessage('profile_username_protect', '', array(), array('handle' => false));
  26. } elseif($ucresult == -3) {
  27. if(C::t('common_member')->fetch_by_username($username) || C::t('common_member_archive')->fetch_by_username($username)) {
  28. showmessage('register_check_found', '', array(), array('handle' => false));
  29. } else {
  30. showmessage('register_activation', '', array(), array('handle' => false));
  31. }
  32. }
  33. $censorexp = '/^('.str_replace(array('\\*', "\r\n", ' '), array('.*', '|', ''), preg_quote(($_G['setting']['censoruser'] = trim($_G['setting']['censoruser'])), '/')).')$/i';
  34. if($_G['setting']['censoruser'] && @preg_match($censorexp, $username)) {
  35. showmessage('profile_username_protect', '', array(), array('handle' => false));
  36. }
  37. } elseif($_GET['action'] == 'checkemail') {
  38. require_once libfile('function/member');
  39. checkemail($_GET['email']);
  40. } elseif($_GET['action'] == 'checkinvitecode') {
  41. $invitecode = trim($_GET['invitecode']);
  42. if(!$invitecode) {
  43. showmessage('no_invitation_code', '', array(), array('handle' => false));
  44. }
  45. $result = array();
  46. if($invite = C::t('common_invite')->fetch_by_code($invitecode)) {
  47. if(empty($invite['fuid']) && (empty($invite['endtime']) || $_G['timestamp'] < $invite['endtime'])) {
  48. $result['uid'] = $invite['uid'];
  49. $result['id'] = $invite['id'];
  50. $result['appid'] = $invite['appid'];
  51. }
  52. }
  53. if(empty($result)) {
  54. showmessage('wrong_invitation_code', '', array(), array('handle' => false));
  55. }
  56. } elseif($_GET['action'] == 'checkuserexists') {
  57. if(C::t('common_member')->fetch_by_username(trim($_GET['username'])) || C::t('common_member_archive')->fetch_by_username(trim($_GET['username']))) {
  58. showmessage('<img src="'.$_G['style']['imgdir'].'/check_right.gif" width="13" height="13">', '', array(), array('msgtype' => 3));
  59. } else {
  60. showmessage('username_nonexistence', '', array(), array('msgtype' => 3));
  61. }
  62. } elseif($_GET['action'] == 'attachlist') {
  63. require_once libfile('function/post');
  64. loadcache('groupreadaccess');
  65. $attachlist = getattach($_GET['pid'], intval($_GET['posttime']), $_GET['aids']);
  66. $attachlist = $attachlist['attachs']['unused'];
  67. $_G['group']['maxprice'] = isset($_G['setting']['extcredits'][$_G['setting']['creditstrans']]) ? $_G['group']['maxprice'] : 0;
  68. include template('common/header_ajax');
  69. include template('forum/ajax_attachlist');
  70. include template('common/footer_ajax');
  71. dexit();
  72. } elseif($_GET['action'] == 'imagelist') {
  73. require_once libfile('function/post');
  74. $attachlist = getattach($_GET['pid'], intval($_GET['posttime']), $_GET['aids']);
  75. $imagelist = $attachlist['imgattachs']['unused'];
  76. include template('common/header_ajax');
  77. include template('forum/ajax_imagelist');
  78. include template('common/footer_ajax');
  79. dexit();
  80. } elseif($_GET['action'] == 'get_rushreply_membernum') {
  81. $tid = intval($_GET['tid']);
  82. if($tid) {
  83. $membernum = C::t('forum_post')->count_author_by_tid($tid);
  84. showmessage('thread_reshreply_membernum', '', array('membernum' => intval($membernum - 1)), array('alert' => 'info'));
  85. }
  86. dexit();
  87. } elseif($_GET['action'] == 'deleteattach') {
  88. $count = 0;
  89. if($_GET['aids']) {
  90. foreach($_GET['aids'] as $aid) {
  91. $attach = C::t('forum_attachment_n')->fetch('aid:'.$aid, $aid);
  92. if($attach && ($attach['pid'] && $attach['pid'] == $_GET['pid'] && $_G['uid'] == $attach['uid'])) {
  93. updatecreditbyaction('postattach', $attach['uid'], array(), '', -1, 1, $_G['fid']);
  94. }
  95. if($attach && ($attach['pid'] && $attach['pid'] == $_GET['pid'] && $_G['uid'] == $attach['uid'] || $_G['forum']['ismoderator'] || !$attach['pid'] && $_G['uid'] == $attach['uid'])) {
  96. C::t('forum_attachment_n')->delete('aid:'.$aid, $aid);
  97. C::t('forum_attachment')->delete($aid);
  98. dunlink($attach);
  99. $count++;
  100. }
  101. }
  102. }
  103. include template('common/header_ajax');
  104. echo $count;
  105. include template('common/footer_ajax');
  106. dexit();
  107. } elseif($_GET['action'] == 'secondgroup') {
  108. require_once libfile('function/group');
  109. $groupselect = get_groupselect($_GET['fupid'], $_GET['groupid']);
  110. include template('common/header_ajax');
  111. include template('forum/ajax_secondgroup');
  112. include template('common/footer_ajax');
  113. dexit();
  114. } elseif($_GET['action'] == 'displaysearch_adv') {
  115. $display = $_GET['display'] == 1 ? 1 : '';
  116. dsetcookie('displaysearch_adv', $display);
  117. } elseif($_GET['action'] == 'checkgroupname') {
  118. $groupname = trim($_GET['groupname']);
  119. if(empty($groupname)) {
  120. showmessage('group_name_empty', '', array(), array('msgtype' => 3));
  121. }
  122. $tmpname = cutstr($groupname, 20, '');
  123. if($tmpname != $groupname) {
  124. showmessage('group_name_oversize', '', array(), array('msgtype' => 3));
  125. }
  126. if(C::t('forum_forum')->fetch_fid_by_name($groupname)) {
  127. showmessage('group_name_exist', '', array(), array('msgtype' => 3));
  128. }
  129. showmessage('', '', array(), array('msgtype' => 3));
  130. include template('common/header_ajax');
  131. include template('common/footer_ajax');
  132. dexit();
  133. } elseif($_GET['action'] == 'getthreadtypes') {
  134. include template('common/header_ajax');
  135. if(empty($_GET['selectname'])) $_GET['selectname'] = 'threadtypeid';
  136. echo '<select name="'.$_GET['selectname'].'">';
  137. if(!empty($_G['forum']['threadtypes']['types'])) {
  138. if(!$_G['forum']['threadtypes']['required']) {
  139. echo '<option value="0"></option>';
  140. }
  141. foreach($_G['forum']['threadtypes']['types'] as $typeid => $typename) {
  142. if($_G['forum']['threadtypes']['moderators'][$typeid] && $_G['forum'] && !$_G['forum']['ismoderator']) {
  143. continue;
  144. }
  145. echo '<option value="'.$typeid.'">'.$typename.'</option>';
  146. }
  147. } else {
  148. echo '<option value="0" /></option>';
  149. }
  150. echo '</select>';
  151. include template('common/footer_ajax');
  152. } elseif($_GET['action'] == 'getimage') {
  153. $_GET['aid'] = intval($_GET['aid']);
  154. $image = C::t('forum_attachment_n')->fetch('aid:'.$_GET['aid'], $_GET['aid'], 1);
  155. include template('common/header_ajax');
  156. if($image['aid']) {
  157. echo '<img src="'.getforumimg($image['aid'], 1, 300, 300, 'fixnone').'" id="image_'.$image['aid'].'" onclick="insertAttachimgTag(\''.$image['aid'].'\')" width="'.($image['width'] < 110 ? $image['width'] : 110).'" cwidth="'.($image['width'] < 300 ? $image['width'] : 300).'" />';
  158. }
  159. include template('common/footer_ajax');
  160. dexit();
  161. } elseif($_GET['action'] == 'setthreadcover') {
  162. $aid = intval($_GET['aid']);
  163. $imgurl = $_GET['imgurl'];
  164. require_once libfile('function/post');
  165. if($_G['forum'] && ($aid || $imgurl)) {
  166. if($imgurl) {
  167. $tid = intval($_GET['tid']);
  168. $pid = intval($_GET['pid']);
  169. } else {
  170. $threadimage = C::t('forum_attachment_n')->fetch('aid:'.$aid, $aid);
  171. $tid = $threadimage['tid'];
  172. $pid = $threadimage['pid'];
  173. }
  174. if($tid && $pid) {
  175. $thread =get_thread_by_tid($tid);
  176. } else {
  177. $thread = array();
  178. }
  179. if(empty($thread) || (!$_G['forum']['ismoderator'] && $_G['uid'] != $thread['authorid'])) {
  180. if($_GET['newthread']) {
  181. showmessage('set_cover_faild', '', array(), array('msgtype' => 3));
  182. } else {
  183. showmessage('set_cover_faild', '', array(), array('closetime' => 3));
  184. }
  185. }
  186. if(setthreadcover($pid, $tid, $aid, 0, $imgurl)) {
  187. if(empty($imgurl)) {
  188. C::t('forum_threadimage')->delete_by_tid($threadimage['tid']);
  189. C::t('forum_threadimage')->insert(array(
  190. 'tid' => $threadimage['tid'],
  191. 'attachment' => $threadimage['attachment'],
  192. 'remote' => $threadimage['remote'],
  193. ));
  194. }
  195. if($_GET['newthread']) {
  196. showmessage('set_cover_succeed', '', array(), array('msgtype' => 3));
  197. } else {
  198. showmessage('set_cover_succeed', '', array(), array('alert' => 'right', 'closetime' => 1));
  199. }
  200. }
  201. }
  202. if($_GET['newthread']) {
  203. showmessage('set_cover_faild', '', array(), array('msgtype' => 3));
  204. } else {
  205. showmessage('set_cover_faild', '', array(), array('closetime' => 3));
  206. }
  207. } elseif($_GET['action'] == 'updateattachlimit') {
  208. $_G['forum']['allowpostattach'] = isset($_G['forum']['allowpostattach']) ? $_G['forum']['allowpostattach'] : '';
  209. $_G['group']['allowpostattach'] = $_G['forum']['allowpostattach'] != -1 && ($_G['forum']['allowpostattach'] == 1 || (!$_G['forum']['postattachperm'] && $_G['group']['allowpostattach']) || ($_G['forum']['postattachperm'] && forumperm($_G['forum']['postattachperm'])));
  210. $_G['forum']['allowpostimage'] = isset($_G['forum']['allowpostimage']) ? $_G['forum']['allowpostimage'] : '';
  211. $_G['group']['allowpostimage'] = $_G['forum']['allowpostimage'] != -1 && ($_G['forum']['allowpostimage'] == 1 || (!$_G['forum']['postimageperm'] && $_G['group']['allowpostimage']) || ($_G['forum']['postimageperm'] && forumperm($_G['forum']['postimageperm'])));
  212. $allowuploadnum = $allowuploadtoday = TRUE;
  213. if($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) {
  214. if($_G['group']['maxattachnum']) {
  215. $allowuploadnum = $_G['group']['maxattachnum'] - getuserprofile('todayattachs');
  216. $allowuploadnum = $allowuploadnum < 0 ? 0 : $allowuploadnum;
  217. if(!$allowuploadnum) {
  218. $allowuploadtoday = false;
  219. }
  220. }
  221. if($_G['group']['maxsizeperday']) {
  222. $allowuploadsize = $_G['group']['maxsizeperday'] - getuserprofile('todayattachsize');
  223. $allowuploadsize = $allowuploadsize < 0 ? 0 : $allowuploadsize;
  224. if(!$allowuploadsize) {
  225. $allowuploadtoday = false;
  226. }
  227. $allowuploadsize = $allowuploadsize / 1048576 >= 1 ? round(($allowuploadsize / 1048576), 1).'MB' : round(($allowuploadsize / 1024)).'KB';
  228. }
  229. }
  230. include template('common/header_ajax');
  231. include template('forum/post_attachlimit');
  232. include template('common/footer_ajax');
  233. exit;
  234. } elseif($_GET['action'] == 'forumchecknew' && !empty($_GET['fid']) && !empty($_GET['time'])) {
  235. $fid = intval($_GET['fid']);
  236. $time = intval($_GET['time']);
  237. if(!$_GET['uncheck']) {
  238. $foruminfo = C::t('forum_forum')->fetch($fid);
  239. $lastpost_str = $foruminfo['lastpost'];
  240. if($lastpost_str) {
  241. $lastpost = explode("\t", $lastpost_str);
  242. unset($lastpost_str);
  243. }
  244. include template('common/header_ajax');
  245. echo $lastpost['2'] > $time ? 1 : 0 ;
  246. include template('common/footer_ajax');
  247. exit;
  248. } else {
  249. $_G['forum_colorarray'] = array('', '#EE1B2E', '#EE5023', '#996600', '#3C9D40', '#2897C5', '#2B65B7', '#8F2A90', '#EC1282');
  250. $query = C::t('forum_forumfield')->fetch($fid);
  251. $forum_field['threadtypes'] = dunserialize($query['threadtypes']);
  252. $forum_field['threadsorts'] = dunserialize($query['threadsorts']);
  253. if($forum_field['threadtypes']['types']) {
  254. safefilter($forum_field['threadtypes']['types']);
  255. }
  256. if($forum_field['threadtypes']['options']['name']) {
  257. safefilter($forum_field['threadtypes']['options']['name']);
  258. }
  259. if($forum_field['threadsorts']['types']) {
  260. safefilter($forum_field['threadsorts']['types']);
  261. }
  262. unset($query);
  263. $forum_field = daddslashes($forum_field);
  264. $todaytime = strtotime(dgmdate(TIMESTAMP, 'Ymd'));
  265. foreach(C::t('forum_thread')->fetch_all_by_fid_lastpost($fid, $time, TIMESTAMP) as $thread) {
  266. $thread['icontid'] = $thread['forumstick'] || !$thread['moved'] && $thread['isgroup'] != 1 ? $thread['tid'] : $thread['closed'];
  267. if(!$thread['forumstick'] && ($thread['isgroup'] == 1 || $thread['fid'] != $_G['fid'])) {
  268. $thread['icontid'] = $thread['closed'] > 1 ? $thread['closed'] : $thread['tid'];
  269. }
  270. list($thread['subject'], $thread['author'], $thread['lastposter']) = daddslashes(array($thread['subject'], $thread['author'], $thread['lastposter']));
  271. $thread['dateline'] = $thread['dateline'] > $todaytime ? "<span class=\"xi1\">".dgmdate($thread['dateline'], 'd')."</span>" : "<span>".dgmdate($thread['dateline'], 'd')."</span>";
  272. $thread['lastpost'] = dgmdate($thread['lastpost']);
  273. if($forum_field['threadtypes']['prefix']) {
  274. if($forum_field['threadtypes']['prefix'] == 1) {
  275. $thread['threadtype'] = $forum_field['threadtypes']['types'][$thread['typeid']] ? '<em>[<a href="forum.php?mod=forumdisplay&fid='.$fid.'&filter=typeid&typeid='.$thread['typeid'].'">'.$forum_field['threadtypes']['types'][$thread['typeid']].'</a>]</em> ' : '' ;
  276. } elseif($forum_field['threadtypes']['prefix'] == 2) {
  277. $thread['threadtype'] = $forum_field['threadtypes']['icons'][$thread['typeid']] ? '<em><a href="forum.php?mod=forumdisplay&fid='.$fid.'&filter=typeid&typeid='.$thread['typeid'].'"><img src="'.$forum_field['threadtypes']['icons'][$thread['typeid']].'"/></a></em> ' : '' ;
  278. }
  279. }
  280. if($forum_field['threadsorts']['prefix']) {
  281. $thread['threadsort'] = $forum_field['threadsorts']['types'][$thread['sortid']] ? '<em>[<a href="forum.php?mod=forumdisplay&fid='.$fid.'&filter=sortid&typeid='.$thread['sortid'].'">'.$forum_field['threadsorts']['types'][$thread['sortid']].'</a>]</em>' : '' ;
  282. }
  283. if($thread['highlight']) {
  284. $string = sprintf('%02d', $thread['highlight']);
  285. $stylestr = sprintf('%03b', $string[0]);
  286. $thread['highlight'] = ' style="';
  287. $thread['highlight'] .= $stylestr[0] ? 'font-weight: bold;' : '';
  288. $thread['highlight'] .= $stylestr[1] ? 'font-style: italic;' : '';
  289. $thread['highlight'] .= $stylestr[2] ? 'text-decoration: underline;' : '';
  290. $thread['highlight'] .= $string[1] ? 'color: '.$_G['forum_colorarray'][$string[1]].';' : '';
  291. if($thread['bgcolor']) {
  292. $thread['highlight'] .= "background-color: $thread[bgcolor];";
  293. }
  294. $thread['highlight'] .= '"';
  295. } else {
  296. $thread['highlight'] = '';
  297. }
  298. $target = $thread['isgroup'] == 1 || $thread['forumstick'] ? ' target="_blank"' : ' onclick="atarget(this)"';
  299. if(in_array('forum_viewthread', $_G['setting']['rewritestatus'])) {
  300. $thread['threadurl'] = '<a href="'.rewriteoutput('forum_viewthread', 1, '', $thread['tid'], 1, '', '').'"'.$thread['highlight'].$target.'class="s xst">'.$thread['subject'].'</a>';
  301. } else {
  302. $thread['threadurl'] = '<a href="forum.php?mod=viewthread&amp;tid='.$thread['tid'].'"'.$thread['highlight'].$target.'class="s xst">'.$thread['subject'].'</a>';
  303. }
  304. if(in_array($thread['displayorder'], array(1, 2, 3, 4))) {
  305. $thread['id'] = 'stickthread_'.$thread['tid'];
  306. } else {
  307. $thread['id'] = 'normalthread_'.$thread['tid'];
  308. }
  309. $thread['threadurl'] = $thread['threadtype'].$thread['threadsort'].$thread['threadurl'];
  310. if(in_array('home_space', $_G['setting']['rewritestatus'])) {
  311. $thread['authorurl'] = '<a href="'.rewriteoutput('home_space', 1, '', $thread['authorid'], '', '').'">'.$thread['author'].'</a>';
  312. $thread['lastposterurl'] = '<a href="'.rewriteoutput('home_space', 1, '', '', rawurlencode($thread['lastposter']), '').'">'.$thread['lastposter'].'</a>';
  313. } else {
  314. $thread['authorurl'] = '<a href="home.php?mod=space&uid='.$thread['authorid'].'">'.$thread['author'].'</a>';
  315. $thread['lastposterurl'] = '<a href="home.php?mod=space&username='.rawurlencode($thread['lastposter']).'">'.$thread['lastposter'].'</a>';
  316. }
  317. $threadlist[] = $thread;
  318. }
  319. if($threadlist) {
  320. krsort($threadlist);
  321. }
  322. include template('forum/ajax_threadlist');
  323. }
  324. } elseif($_GET['action'] == 'downremoteimg') {
  325. $_GET['message'] = str_replace(array("\r", "\n"), array($_GET['wysiwyg'] ? '<br />' : '', "\\n"), $_GET['message']);
  326. preg_match_all("/\[img\]\s*([^\[\<\r\n]+?)\s*\[\/img\]|\[img=\d{1,4}[x|\,]\d{1,4}\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/is", $_GET['message'], $image1, PREG_SET_ORDER);
  327. preg_match_all("/\<img.+src=('|\"|)?(.*)(\\1)([\s].*)?\>/ismUe", $_GET['message'], $image2, PREG_SET_ORDER);
  328. $temp = $aids = $existentimg = array();
  329. if(is_array($image1) && !empty($image1)) {
  330. foreach($image1 as $value) {
  331. $temp[] = array(
  332. '0' => $value[0],
  333. '1' => trim(!empty($value[1]) ? $value[1] : $value[2])
  334. );
  335. }
  336. }
  337. if(is_array($image2) && !empty($image2)) {
  338. foreach($image2 as $value) {
  339. $temp[] = array(
  340. '0' => $value[0],
  341. '1' => trim($value[2])
  342. );
  343. }
  344. }
  345. require_once libfile('class/image');
  346. if(is_array($temp) && !empty($temp)) {
  347. $upload = new discuz_upload();
  348. $attachaids = array();
  349. foreach($temp as $value) {
  350. $imageurl = $value[1];
  351. $hash = md5($imageurl);
  352. if(strlen($imageurl)) {
  353. $imagereplace['oldimageurl'][] = $value[0];
  354. if(!isset($existentimg[$hash])) {
  355. $existentimg[$hash] = $imageurl;
  356. $attach['ext'] = $upload->fileext($imageurl);
  357. if(!$upload->is_image_ext($attach['ext'])) {
  358. continue;
  359. }
  360. $content = '';
  361. if(preg_match('/^(http:\/\/|\.)/i', $imageurl)) {
  362. $content = dfsockopen($imageurl);
  363. } elseif(preg_match('/^('.preg_quote(getglobal('setting/attachurl'), '/').')/i', $imageurl)) {
  364. $imagereplace['newimageurl'][] = $value[0];
  365. }
  366. if(empty($content)) continue;
  367. $patharr = explode('/', $imageurl);
  368. $attach['name'] = trim($patharr[count($patharr)-1]);
  369. $attach['thumb'] = '';
  370. $attach['isimage'] = $upload -> is_image_ext($attach['ext']);
  371. $attach['extension'] = $upload -> get_target_extension($attach['ext']);
  372. $attach['attachdir'] = $upload -> get_target_dir('forum');
  373. $attach['attachment'] = $attach['attachdir'] . $upload->get_target_filename('forum').'.'.$attach['extension'];
  374. $attach['target'] = getglobal('setting/attachdir').'./forum/'.$attach['attachment'];
  375. if(!@$fp = fopen($attach['target'], 'wb')) {
  376. continue;
  377. } else {
  378. flock($fp, 2);
  379. fwrite($fp, $content);
  380. fclose($fp);
  381. }
  382. if(!$upload->get_image_info($attach['target'])) {
  383. @unlink($attach['target']);
  384. continue;
  385. }
  386. $attach['size'] = filesize($attach['target']);
  387. $upload->attach = $attach;
  388. $thumb = $width = 0;
  389. if($upload->attach['isimage']) {
  390. if($_G['setting']['thumbsource'] && $_G['setting']['sourcewidth'] && $_G['setting']['sourceheight']) {
  391. $image = new image();
  392. $thumb = $image->Thumb($upload->attach['target'], '', $_G['setting']['sourcewidth'], $_G['setting']['sourceheight'], 1, 1) ? 1 : 0;
  393. $width = $image->imginfo['width'];
  394. $upload->attach['size'] = $image->imginfo['size'];
  395. }
  396. if($_G['setting']['thumbstatus']) {
  397. $image = new image();
  398. $thumb = $image->Thumb($upload->attach['target'], '', $_G['setting']['thumbwidth'], $_G['setting']['thumbheight'], $_G['setting']['thumbstatus'], 0) ? 1 : 0;
  399. $width = $image->imginfo['width'];
  400. }
  401. if($_G['setting']['thumbsource'] || !$_G['setting']['thumbstatus']) {
  402. list($width) = @getimagesize($upload->attach['target']);
  403. }
  404. if($_G['setting']['watermarkstatus'] && empty($_G['forum']['disablewatermark'])) {
  405. $image = new image();
  406. $image->Watermark($attach['target'], '', 'forum');
  407. $upload->attach['size'] = $image->imginfo['size'];
  408. }
  409. }
  410. $aids[] = $aid = getattachnewaid();
  411. $setarr = array(
  412. 'aid' => $aid,
  413. 'dateline' => $_G['timestamp'],
  414. 'filename' => $upload->attach['name'],
  415. 'filesize' => $upload->attach['size'],
  416. 'attachment' => $upload->attach['attachment'],
  417. 'isimage' => $upload->attach['isimage'],
  418. 'uid' => $_G['uid'],
  419. 'thumb' => $thumb,
  420. 'remote' => '0',
  421. 'width' => $width
  422. );
  423. C::t("forum_attachment_unused")->insert($setarr);
  424. $attachaids[$hash] = $imagereplace['newimageurl'][] = '[attachimg]'.$aid.'[/attachimg]';
  425. } else {
  426. $imagereplace['newimageurl'][] = $attachaids[$hash];
  427. }
  428. }
  429. }
  430. if(!empty($aids)) {
  431. require_once libfile('function/post');
  432. }
  433. $_GET['message'] = str_replace($imagereplace['oldimageurl'], $imagereplace['newimageurl'], $_GET['message']);
  434. }
  435. $_GET['message'] = addcslashes($_GET['message'], '/"\'');
  436. print <<<EOF
  437. <script type="text/javascript">
  438. parent.ATTACHORIMAGE = 1;
  439. parent.updateDownImageList('$_GET[message]');
  440. </script>
  441. EOF;
  442. dexit();
  443. } elseif($_GET['action'] == 'exif') {
  444. $exif = C::t('forum_attachment_exif')->fetch($_GET['aid']);
  445. $s = $exif['exif'];
  446. if(!$s) {
  447. require_once libfile('function/attachment');
  448. $s = getattachexif($_GET['aid']);
  449. C::t('forum_attachment_exif')->insert($_GET['aid'], $s);
  450. }
  451. include template('common/header_ajax');
  452. echo $s;
  453. include template('common/footer_ajax');
  454. exit;
  455. } elseif($_GET['action'] == 'getthreadclass') {
  456. $fid = intval($_GET['fid']);
  457. $threadclass = '';
  458. if($fid) {
  459. $option = array();
  460. $forumfield = C::t('forum_forumfield')->fetch($fid);
  461. if(!empty($forumfield['threadtypes'])) {
  462. foreach(C::t('forum_threadclass')->fetch_all_by_fid($fid) as $tc) {
  463. $option[] = '<option value="'.$tc['typeid'].'">'.$tc['name'].'</option>';
  464. }
  465. if(!empty($option)) {
  466. $threadclass .= '<option value="">'.lang('forum/template', 'modcp_select_threadclass').'</option>';
  467. $threadclass .= implode('', $option);
  468. }
  469. }
  470. }
  471. if(!empty($threadclass)) {
  472. $threadclass = '<select name="typeid" id="typeid" width="168" class="ps">'.$threadclass.'</select>';
  473. }
  474. include template('common/header_ajax');
  475. echo $threadclass;
  476. include template('common/footer_ajax');
  477. exit;
  478. } elseif($_GET['action'] == 'forumjump') {
  479. require_once libfile('function/forumlist');
  480. $favforums = C::t('home_favorite')->fetch_all_by_uid_idtype($_G['uid'], 'fid');
  481. $visitedforums = array();
  482. if($_G['cookie']['visitedfid']) {
  483. loadcache('forums');
  484. foreach(explode('D', $_G['cookie']['visitedfid']) as $fid) {
  485. $fid = intval($fid);
  486. $visitedforums[$fid] = $_G['cache']['forums'][$fid]['name'];
  487. }
  488. }
  489. $forumlist = forumselect(FALSE, 1);
  490. include template('forum/ajax_forumlist');
  491. } elseif($_GET['action'] == 'quickreply') {
  492. $tid = intval($_GET['tid']);
  493. $fid = intval($_GET['fid']);
  494. if($tid) {
  495. $thread = C::t('forum_thread')->fetch($tid);
  496. if($thread && !getstatus($thread['status'], 2)) {
  497. $list = C::t('forum_post')->fetch_all_by_tid('tid:'.$tid, $tid, true, 'DESC', 0, 10, null, 0);
  498. loadcache('smilies');
  499. foreach($list as $pid => $post) {
  500. if($post['first']) {
  501. unset($list[$pid]);
  502. } else {
  503. $post['message'] = preg_replace($_G['cache']['smilies']['searcharray'], '', $post['message']);
  504. $post['message'] = preg_replace("/\{\:soso_((e\d+)|(_\d+_\d))\:\}/", '', $post['message']);
  505. $list[$pid]['message'] = cutstr(preg_replace("/\[.+?\]/is", '', dhtmlspecialchars($post['message'])), 300) ;
  506. }
  507. }
  508. krsort($list);
  509. }
  510. }
  511. list($seccodecheck, $secqaacheck) = seccheck('post', 'reply');
  512. include template('forum/ajax_quickreply');
  513. } elseif($_GET['action'] == 'getpost') {
  514. $tid = intval($_GET['tid']);
  515. $fid = intval($_GET['fid']);
  516. $pid = intval($_GET['pid']);
  517. $thread = C::t('forum_thread')->fetch($tid);
  518. $post = C::t('forum_post')->fetch($thread['posttableid'], $pid);
  519. include template('forum/ajax_followpost');
  520. } elseif($_GET['action'] == 'quickclear') {
  521. $uid = intval($_GET['uid']);
  522. if($_G['adminid'] != 1) {
  523. showmessage('quickclear_noperm');
  524. }
  525. include_once libfile('function/misc');
  526. include_once libfile('function/member');
  527. if(!submitcheck('qclearsubmit')) {
  528. $crimenum_avatar = crime('getcount', $uid, 'crime_avatar');
  529. $crimenum_sightml = crime('getcount', $uid, 'crime_sightml');
  530. $crimenum_customstatus = crime('getcount', $uid, 'crime_customstatus');
  531. $crimeauthor = getuserbyuid($uid);
  532. $crimeauthor = $crimeauthor['username'];
  533. include template('forum/ajax');
  534. } else {
  535. if(empty($_GET['operations'])) {
  536. showmessage('quickclear_need_operation');
  537. }
  538. $reason = checkreasonpm();
  539. $allowop = array('avatar', 'sightml', 'customstatus');
  540. $cleartype = array();
  541. if(in_array('avatar', $_GET['operations'])) {
  542. C::t('common_member')->update($uid, array('avatarstatus'=>0));
  543. loaducenter();
  544. uc_user_deleteavatar($uid);
  545. $cleartype[] = lang('forum/misc', 'avatar');
  546. crime('recordaction', $uid, 'crime_avatar', lang('forum/misc', 'crime_reason', array('reason' => $reason)));
  547. }
  548. if(in_array('sightml', $_GET['operations'])) {
  549. C::t('common_member_field_forum')->update($uid, array('sightml' => ''), 'UNBUFFERED');
  550. $cleartype[] = lang('forum/misc', 'signature');
  551. crime('recordaction', $uid, 'crime_sightml', lang('forum/misc', 'crime_reason', array('reason' => $reason)));
  552. }
  553. if(in_array('customstatus', $_GET['operations'])) {
  554. C::t('common_member_field_forum')->update($uid, array('customstatus' => ''), 'UNBUFFERED');
  555. $cleartype[] = lang('forum/misc', 'custom_title');
  556. crime('recordaction', $uid, 'crime_customstatus', lang('forum/misc', 'crime_reason', array('reason' => $reason)));
  557. }
  558. if(($_G['group']['reasonpm'] == 2 || $_G['group']['reasonpm'] == 3) || !empty($_GET['sendreasonpm'])) {
  559. sendreasonpm(array('authorid' => $uid), 'reason_quickclear', array(
  560. 'cleartype' => implode(',', $cleartype),
  561. 'reason' => $reason,
  562. 'from_id' => 0,
  563. 'from_idtype' => 'quickclear'
  564. ));
  565. }
  566. showmessage('quickclear_success', $_POST['redirect'], array(), array('showdialog'=>1, 'closetime' => true, 'msgtype' => 2, 'locationtime' => 1));
  567. }
  568. } elseif($_GET['action'] == 'getpostfeed') {
  569. $tid = intval($_GET['tid']);
  570. $pid = intval($_GET['pid']);
  571. $flag = intval($_GET['flag']);
  572. $feed = $thread = array();
  573. if($tid) {
  574. $thread = C::t('forum_thread')->fetch($tid);
  575. if($flag) {
  576. $post = C::t('forum_post')->fetch($thread['posttableid'], $pid);
  577. require_once libfile('function/discuzcode');
  578. require_once libfile('function/followcode');
  579. $post['message'] = followcode($post['message'], $tid, $pid);
  580. } else {
  581. if(!isset($_G['cache']['forums'])) {
  582. loadcache('forums');
  583. }
  584. $feedid = intval($_GET['feedid']);
  585. $feed = C::t('forum_threadpreview')->fetch($tid);
  586. if($feedid) {
  587. $feed = array_merge($feed, C::t('home_follow_feed')->fetch_by_feedid($feedid));
  588. }
  589. $post['message'] = $feed['content'];
  590. }
  591. }
  592. include template('forum/ajax_followpost');
  593. } elseif($_GET['action'] == 'setnav') {
  594. if($_G['adminid'] != 1) {
  595. showmessage('quickclear_noperm');
  596. }
  597. $allowfuntype = array('portal', 'group', 'follow', 'collection', 'guide', 'feed', 'blog', 'doing', 'album', 'share', 'wall', 'homepage', 'ranklist');
  598. $type = in_array($_GET['type'], $allowfuntype) ? trim($_GET['type']) : '';
  599. $do = in_array($_GET['do'], array('open', 'close')) ? $_GET['do'] : 'close';
  600. if(!submitcheck('funcsubmit')) {
  601. $navtitle = lang('spacecp', $do == 'open' ? 'select_the_navigation_position' : 'close_module', array('type' => lang('spacecp', $type)));
  602. $closeprompt = lang('spacecp', 'close_module', array('type' => lang('spacecp', $type)));
  603. include template('forum/ajax');
  604. } else {
  605. if(!empty($type)) {
  606. $funkey = $type.'status';
  607. $funstatus = $do == 'open' ? 1 : 0;
  608. if($type != 'homepage') {
  609. $identifier = array('portal' => 1, 'group' => 3, 'feed' => 4, 'ranklist' => 8, 'follow' => 9, 'guide' => 10, 'collection' => 11, 'blog' => 12, 'album' => 13, 'share' => 14, 'doing' => 15);
  610. $navdata = array('available' => -1);
  611. $navtype = $do == 'open' ? array() : array(0, 3);
  612. if(in_array($type, array('blog', 'album', 'share', 'doing', 'follow'))) {
  613. $navtype[] = 2;
  614. }
  615. if($do == 'open') {
  616. if($_GET['location']['header']) {
  617. $navtype[] = 0;
  618. $navdata['available'] = 1;
  619. }
  620. if($_GET['location']['quick']) {
  621. $navtype[] = 3;
  622. $navdata['available'] = 1;
  623. }
  624. $navdata['available'] = $navdata['available'] == 1 ? 1 : 0;
  625. if(empty($_GET['location']['header']) || empty($_GET['location']['quick'])) {
  626. C::t('common_nav')->update_by_navtype_type_identifier(array(0, 2, 3), 0, array("$type", "$identifier[$type]"), array('available' => 0));
  627. }
  628. }
  629. if($navtype) {
  630. C::t('common_nav')->update_by_navtype_type_identifier($navtype, 0, array("$type", "$identifier[$type]"), $navdata);
  631. if(in_array($type, array('blog', 'album', 'share', 'doing', 'follow')) && !$navdata['available']) {
  632. C::t('common_nav')->update_by_navtype_type_identifier(array(2), 0, array("$type"), array('available' => 1));
  633. }
  634. }
  635. }
  636. C::t('common_setting')->update($funkey, $funstatus);
  637. $setting[$funkey] = $funstatus;
  638. include libfile('function/cache');
  639. updatecache('setting');
  640. }
  641. showmessage('do_success', dreferer(), array(), array('header'=>true));
  642. }
  643. exit;
  644. } elseif($_GET['action'] == 'checkpostrule') {
  645. require_once libfile('function/post');
  646. include template('common/header_ajax');
  647. $_POST = array('action' => $_GET['ac']);
  648. list($seccodecheck, $secqaacheck) = seccheck('post', $_GET['ac']);
  649. if($seccodecheck || $secqaacheck) {
  650. include template('forum/seccheck_post');
  651. }
  652. include template('common/footer_ajax');
  653. exit;
  654. }
  655. showmessage('succeed', '', array(), array('handle' => false));
  656. ?>