PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/source/function/function_post.php

https://github.com/kuaileshike/upload
PHP | 629 lines | 571 code | 52 blank | 6 comment | 157 complexity | 72c9e02f6e5ea12231061f1810a7b574 MD5 | raw file
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: function_post.php 30627 2012-06-07 07:03:04Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function getattach($pid, $posttime = 0, $aids = '') {
  12. global $_G;
  13. require_once libfile('function/attachment');
  14. $attachs = $imgattachs = array();
  15. $aids = $aids ? explode('|', $aids) : array();
  16. if($aids) {
  17. $aidsnew = array();
  18. foreach($aids as $aid) {
  19. if($aid) {
  20. $aidsnew[] = intval($aid);
  21. }
  22. }
  23. $aids = "aid IN (".dimplode($aidsnew).") AND";
  24. } else {
  25. $aids = '';
  26. }
  27. $sqladd1 = $posttime > 0 ? "AND af.dateline>'$posttime'" : '';
  28. if(!empty($_G['fid']) && $_G['forum']['attachextensions']) {
  29. $allowext = str_replace(' ', '', strtolower($_G['forum']['attachextensions']));
  30. $allowext = explode(',', $allowext);
  31. } else {
  32. $allowext = '';
  33. }
  34. foreach(C::t('forum_attachment')->fetch_all_unused_attachment($_G['uid'], empty($aidsnew) ? null : $aidsnew, $posttime > 0 ? $posttime : null) as $attach) {
  35. $attach['filenametitle'] = $attach['filename'];
  36. $attach['ext'] = fileext($attach['filename']);
  37. if($allowext && !in_array($attach['ext'], $allowext)) {
  38. continue;
  39. }
  40. getattach_row($attach, $attachs, $imgattachs);
  41. }
  42. if($pid > 0) {
  43. $attachmentns = C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$_G['tid'], 'pid', $pid);
  44. foreach(C::t('forum_attachment')->fetch_all_by_id('pid', $pid, 'aid') as $attach) {
  45. $attach = array_merge($attach, $attachmentns[$attach['aid']]);
  46. $attach['filenametitle'] = $attach['filename'];
  47. $attach['ext'] = fileext($attach['filename']);
  48. if($allowext && !in_array($attach['ext'], $allowext)) {
  49. continue;
  50. }
  51. getattach_row($attach, $attachs, $imgattachs);
  52. }
  53. }
  54. return array('attachs' => $attachs, 'imgattachs' => $imgattachs);
  55. }
  56. function getattach_row($attach, &$attachs, &$imgattachs) {
  57. global $_G;
  58. $attach['filename'] = cutstr($attach['filename'], $_G['setting']['allowattachurl'] ? 25 : 30);
  59. $attach['attachsize'] = sizecount($attach['filesize']);
  60. $attach['dateline'] = dgmdate($attach['dateline']);
  61. $attach['filetype'] = attachtype($attach['ext']."\t".$attach['filetype']);
  62. if($attach['isimage'] < 1) {
  63. if($attach['isimage']) {
  64. $attach['url'] = $attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl'];
  65. $attach['width'] = $attach['width'] > 300 ? 300 : $attach['width'];
  66. }
  67. if($attach['pid']) {
  68. $attachs['used'][] = $attach;
  69. } else {
  70. $attachs['unused'][] = $attach;
  71. }
  72. } else {
  73. $attach['url'] = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'/forum';
  74. $attach['width'] = $attach['width'] > 300 ? 300 : $attach['width'];
  75. if($attach['pid']) {
  76. $imgattachs['used'][] = $attach;
  77. } else {
  78. $imgattachs['unused'][] = $attach;
  79. }
  80. }
  81. }
  82. function parseattachmedia($attach) {
  83. $attachurl = 'attach://'.$attach['aid'].'.'.$attach['ext'];
  84. switch(strtolower($attach['ext'])) {
  85. case 'mp3':
  86. case 'wma':
  87. case 'ra':
  88. case 'ram':
  89. case 'wav':
  90. case 'mid':
  91. return '[audio]'.$attachurl.'[/audio]';
  92. case 'wmv':
  93. case 'rm':
  94. case 'rmvb':
  95. case 'avi':
  96. case 'asf':
  97. case 'mpg':
  98. case 'mpeg':
  99. case 'mov':
  100. case 'flv':
  101. case 'swf':
  102. return '[media='.$attach['ext'].',400,300]'.$attachurl.'[/media]';
  103. default:
  104. return;
  105. }
  106. }
  107. function ftpupload($aids, $uid = 0) {
  108. global $_G;
  109. $uid = $uid ? $uid : $_G['uid'];
  110. if(!$aids || !$_G['setting']['ftp']['on']) {
  111. return;
  112. }
  113. $attachtables = $pics = array();
  114. foreach(C::t('forum_attachment')->fetch_all($aids) as $attach) {
  115. if($uid != $attach['uid'] && !$_G['forum']['ismoderator']) {
  116. continue;
  117. }
  118. $attachtables[$attach['tableid']][] = $attach['aid'];
  119. }
  120. foreach($attachtables as $attachtable => $aids) {
  121. $remoteaids = array();
  122. foreach(C::t('forum_attachment_n')->fetch_all($attachtable, $aids, 0) as $attach) {
  123. $attach['ext'] = fileext($attach['filename']);
  124. if(((!$_G['setting']['ftp']['allowedexts'] && !$_G['setting']['ftp']['disallowedexts']) || ($_G['setting']['ftp']['allowedexts'] && in_array($attach['ext'], $_G['setting']['ftp']['allowedexts'])) || ($_G['setting']['ftp']['disallowedexts'] && !in_array($attach['ext'], $_G['setting']['ftp']['disallowedexts']) && (!$_G['setting']['ftp']['allowedexts'] || $_G['setting']['ftp']['allowedexts'] && in_array($attach['ext'], $_G['setting']['ftp']['allowedexts'])) )) && (!$_G['setting']['ftp']['minsize'] || $attach['filesize'] >= $_G['setting']['ftp']['minsize'] * 1024)) {
  125. if(ftpcmd('upload', 'forum/'.$attach['attachment']) && (!$attach['thumb'] || ftpcmd('upload', 'forum/'.getimgthumbname($attach['attachment'])))) {
  126. dunlink($attach);
  127. $remoteaids[$attach['aid']] = $attach['aid'];
  128. if($attach['picid']) {
  129. $pics[] = $attach['picid'];
  130. }
  131. }
  132. }
  133. }
  134. if($remoteaids) {
  135. C::t('forum_attachment_n')->update($attachtable, $remoteaids, array('remote' => 1));
  136. }
  137. }
  138. if($pics) {
  139. C::t('home_pic')->update($pics, array('remote' => 3));
  140. }
  141. }
  142. function updateattach($modnewthreads, $tid, $pid, $attachnew, $attachupdate = array(), $uid = 0) {
  143. global $_G;
  144. $thread = C::t('forum_thread')->fetch($tid);
  145. $uid = $uid ? $uid : $_G['uid'];
  146. if($attachnew) {
  147. $newaids = array_keys($attachnew);
  148. $newattach = $newattachfile = $albumattach = array();
  149. foreach(C::t('forum_attachment_unused')->fetch_all($newaids) as $attach) {
  150. if($attach['uid'] != $uid && !$_G['forum']['ismoderator']) {
  151. continue;
  152. }
  153. $newattach[$attach['aid']] = daddslashes($attach);
  154. if($attach['isimage']) {
  155. $newattachfile[$attach['aid']] = $attach['attachment'];
  156. }
  157. }
  158. if($_G['setting']['watermarkstatus'] && empty($_G['forum']['disablewatermark'])) {
  159. require_once libfile('class/image');
  160. $image = new image;
  161. }
  162. if(!empty($_GET['albumaid'])) {
  163. array_unshift($_GET['albumaid'], '');
  164. $_GET['albumaid'] = array_unique($_GET['albumaid']);
  165. unset($_GET['albumaid'][0]);
  166. foreach($_GET['albumaid'] as $aid) {
  167. if(isset($newattach[$aid])) {
  168. $albumattach[$aid] = $newattach[$aid];
  169. }
  170. }
  171. }
  172. foreach($attachnew as $aid => $attach) {
  173. $update = array();
  174. $update['readperm'] = $_G['group']['allowsetattachperm'] ? $attach['readperm'] : 0;
  175. $update['price'] = $_G['group']['maxprice'] ? (intval($attach['price']) <= $_G['group']['maxprice'] ? intval($attach['price']) : $_G['group']['maxprice']) : 0;
  176. $update['tid'] = $tid;
  177. $update['pid'] = $pid;
  178. $update['uid'] = $uid;
  179. $update['description'] = censor(cutstr(dhtmlspecialchars($attach['description']), 100));
  180. C::t('forum_attachment_n')->update('tid:'.$tid, $aid, $update);
  181. if(!$newattach[$aid]) {
  182. continue;
  183. }
  184. $update = array_merge($update, $newattach[$aid]);
  185. if(!empty($newattachfile[$aid])) {
  186. if($_G['setting']['thumbstatus'] && $_G['forum']['disablethumb']) {
  187. $update['thumb'] = 0;
  188. @unlink($_G['setting']['attachdir'].'/forum/'.getimgthumbname($newattachfile[$aid]));
  189. if(!empty($albumattach[$aid])) {
  190. $albumattach[$aid]['thumb'] = 0;
  191. }
  192. }
  193. if($_G['setting']['watermarkstatus'] && empty($_G['forum']['disablewatermark'])) {
  194. $image->Watermark($_G['setting']['attachdir'].'/forum/'.$newattachfile[$aid], '', 'forum');
  195. $update['filesize'] = $image->imginfo['size'];
  196. }
  197. }
  198. if(!empty($_GET['albumaid']) && isset($albumattach[$aid])) {
  199. $newalbum = 0;
  200. if(!$_GET['uploadalbum']) {
  201. require_once libfile('function/spacecp');
  202. $_GET['uploadalbum'] = album_creat(array('albumname' => $_GET['newalbum']));
  203. $newalbum = 1;
  204. }
  205. $picdata = array(
  206. 'albumid' => $_GET['uploadalbum'],
  207. 'uid' => $_G['uid'],
  208. 'username' => $_G['username'],
  209. 'dateline' => $albumattach[$aid]['dateline'],
  210. 'postip' => $_G['clientip'],
  211. 'filename' => censor($albumattach[$aid]['filename']),
  212. 'title' => censor(cutstr(dhtmlspecialchars($attach['description']), 100)),
  213. 'type' => fileext($albumattach[$aid]['attachment']),
  214. 'size' => $albumattach[$aid]['filesize'],
  215. 'filepath' => $albumattach[$aid]['attachment'],
  216. 'thumb' => $albumattach[$aid]['thumb'],
  217. 'remote' => $albumattach[$aid]['remote'] + 2,
  218. );
  219. $update['picid'] = C::t('home_pic')->insert($picdata, 1);
  220. if($newalbum) {
  221. require_once libfile('function/home');
  222. require_once libfile('function/spacecp');
  223. album_update_pic($_GET['uploadalbum']);
  224. }
  225. }
  226. C::t('forum_attachment_n')->insert('tid:'.$tid, $update, false, true);
  227. C::t('forum_attachment')->update($aid, array('tid' => $tid, 'pid' => $pid, 'tableid' => getattachtableid($tid)));
  228. C::t('forum_attachment_unused')->delete($aid);
  229. }
  230. if(!empty($_GET['albumaid'])) {
  231. $albumdata = array(
  232. 'picnum' => C::t('home_pic')->check_albumpic($_GET['uploadalbum']),
  233. 'updatetime' => $_G['timestamp'],
  234. );
  235. C::t('home_album')->update($_GET['uploadalbum'], $albumdata);
  236. require_once libfile('function/home');
  237. require_once libfile('function/spacecp');
  238. album_update_pic($_GET['uploadalbum']);
  239. }
  240. if($newattach) {
  241. ftpupload($newaids, $uid);
  242. }
  243. }
  244. if(!$modnewthreads && $newattach && $uid == $_G['uid']) {
  245. updatecreditbyaction('postattach', $uid, array(), '', count($newattach), 1, $_G['fid']);
  246. }
  247. if($attachupdate) {
  248. $attachs = C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$tid, 'aid', array_keys($attachupdate));
  249. foreach($attachs as $attach) {
  250. if(array_key_exists($attach['aid'], $attachupdate) && $attachupdate[$attach['aid']]) {
  251. dunlink($attach);
  252. }
  253. }
  254. $unusedattachs = C::t('forum_attachment_unused')->fetch_all($attachupdate);
  255. $attachupdate = array_flip($attachupdate);
  256. $unusedaids = array();
  257. foreach($unusedattachs as $attach) {
  258. if($attach['uid'] != $uid && !$_G['forum']['ismoderator']) {
  259. continue;
  260. }
  261. $unusedaids[] = $attach['aid'];
  262. $update = $attach;
  263. $update['dateline'] = TIMESTAMP;
  264. $update['remote'] = 0;
  265. unset($update['aid']);
  266. if($attach['isimage'] && $_G['setting']['watermarkstatus'] && empty($_G['forum']['disablewatermark'])) {
  267. $image->Watermark($_G['setting']['attachdir'].'/forum/'.$attach['attachment'], '', 'forum');
  268. $update['filesize'] = $image->imginfo['size'];
  269. }
  270. C::t('forum_attachment_n')->update('tid:'.$tid, $attachupdate[$attach['aid']], $update);
  271. @unlink($_G['setting']['attachdir'].'image/'.$attach['aid'].'_100_100.jpg');
  272. C::t('forum_attachment_exif')->delete($attachupdate[$attach['aid']]);
  273. C::t('forum_attachment_exif')->update($attach['aid'], array('aid' => $attachupdate[$attach['aid']]));
  274. ftpupload(array($attachupdate[$attach['aid']]), $uid);
  275. }
  276. if($unusedaids) {
  277. C::t('forum_attachment_unused')->delete($unusedaids);
  278. }
  279. }
  280. $attachcount = C::t('forum_attachment_n')->count_by_id('tid:'.$tid, $pid ? 'pid' : 'tid', $pid ? $pid : $tid);
  281. $attachment = 0;
  282. if($attachcount) {
  283. if(C::t('forum_attachment_n')->count_image_by_id('tid:'.$tid, $pid ? 'pid' : 'tid', $pid ? $pid : $tid)) {
  284. $attachment = 2;
  285. } else {
  286. $attachment = 1;
  287. }
  288. } else {
  289. $attachment = 0;
  290. }
  291. C::t('forum_thread')->update($tid, array('attachment'=>$attachment));
  292. C::t('forum_post')->update('tid:'.$tid, $pid, array('attachment' => $attachment), true);
  293. if(!$attachment) {
  294. C::t('forum_threadimage')->delete_by_tid($tid);
  295. }
  296. $_G['forum_attachexist'] = $attachment;
  297. }
  298. function checkflood() {
  299. global $_G;
  300. if(!$_G['group']['disablepostctrl'] && $_G['uid']) {
  301. if($_G['setting']['floodctrl'] && discuz_process::islocked("post_lock_".$_G['uid'], $_G['setting']['floodctrl'])) {
  302. return true;
  303. }
  304. return false;
  305. }
  306. return FALSE;
  307. }
  308. function checkmaxperhour($type) {
  309. global $_G;
  310. $morenumperhour = false;
  311. if(!$_G['group']['disablepostctrl'] && $_G['uid']) {
  312. if($_G['group']['max'.($type == 'pid' ? 'posts' : 'threads').'perhour']) {
  313. $usernum = C::t('common_member_action_log')->count_per_hour($_G['uid'], $type);
  314. $var = $type === 'tid' ? 'maxthreadsperhour' : 'maxpostsperhour';
  315. $isflood = $usernum && ($usernum >= $_G['group'][$var]);
  316. if($isflood) {
  317. $morenumperhour = true;
  318. }
  319. }
  320. }
  321. return $morenumperhour;
  322. }
  323. function checkpost($subject, $message, $special = 0) {
  324. global $_G;
  325. if(dstrlen($subject) > 80) {
  326. return 'post_subject_toolong';
  327. }
  328. if(!$_G['group']['disablepostctrl'] && !$special) {
  329. if($_G['setting']['maxpostsize'] && strlen($message) > $_G['setting']['maxpostsize']) {
  330. return 'post_message_toolong';
  331. } elseif($_G['setting']['minpostsize'] && strlen(preg_replace("/\[quote\].+?\[\/quote\]/is", '', $message)) < $_G['setting']['minpostsize']) {
  332. return 'post_message_tooshort';
  333. }
  334. }
  335. return FALSE;
  336. }
  337. function checkbbcodes($message, $bbcodeoff) {
  338. return !$bbcodeoff && (!strpos($message, '[/') && !strpos($message, '[hr]')) ? -1 : $bbcodeoff;
  339. }
  340. function checksmilies($message, $smileyoff) {
  341. global $_G;
  342. if($smileyoff) {
  343. return 1;
  344. } else {
  345. if(!empty($_G['cache']['smileycodes']) && is_array($_G['cache']['smileycodes'])) {
  346. foreach($_G['cache']['smileycodes'] as $id => $code) {
  347. if(strpos($message, $code) !== FALSE) {
  348. return 0;
  349. }
  350. }
  351. }
  352. return -1;
  353. }
  354. }
  355. function updatepostcredits($operator, $uidarray, $action, $fid = 0) {
  356. global $_G;
  357. $val = $operator == '+' ? 1 : -1;
  358. $extsql = array();
  359. if(empty($uidarray)) {
  360. return false;
  361. }
  362. $uidarray = (array)$uidarray;
  363. $uidarr = array();
  364. foreach($uidarray as $uid) {
  365. $uidarr[$uid] = !isset($uidarr[$uid]) ? 1 : $uidarr[$uid]+1;
  366. }
  367. foreach($uidarr as $uid => $coef) {
  368. $opnum = $val*$coef;
  369. if($action == 'reply') {
  370. $extsql = array('posts' => $opnum);
  371. } elseif($action == 'post') {
  372. $extsql = array('threads' => $opnum, 'posts' => $opnum);
  373. }
  374. if($uid == $_G['uid']) {
  375. updatecreditbyaction($action, $uid, $extsql, '', $opnum, 1, $fid);
  376. } elseif(empty($uid)) {
  377. continue;
  378. } else {
  379. batchupdatecredit($action, $uid, $extsql, $opnum, $fid);
  380. }
  381. }
  382. if($operator == '+' && ($action == 'reply' || $action == 'post')) {
  383. C::t('common_member_status')->update(array_keys($uidarr), array('lastpost' => TIMESTAMP), 'UNBUFFERED');
  384. }
  385. }
  386. function updateattachcredits($operator, $uidarray) {
  387. global $_G;
  388. foreach($uidarray as $uid => $attachs) {
  389. updatecreditbyaction('postattach', $uid, array(), '', $operator == '-' ? -$attachs : $attachs, 1, $_G['fid']);
  390. }
  391. }
  392. function updateforumcount($fid) {
  393. extract(C::t('forum_thread')->count_posts_by_fid($fid));
  394. $thread = C::t('forum_thread')->fetch_by_fid_displayorder($fid, 0, '=');
  395. $thread['subject'] = addslashes($thread['subject']);
  396. $thread['lastposter'] = $thread['author'] ? addslashes($thread['lastposter']) : lang('forum/misc', 'anonymous');
  397. $tid = $thread['closed'] > 1 ? $thread['closed'] : $thread['tid'];
  398. $setarr = array('posts' => $posts, 'threads' => $threads, 'lastpost' => "$tid\t$thread[subject]\t$thread[lastpost]\t$thread[lastposter]");
  399. C::t('forum_forum')->update($fid, $setarr);
  400. }
  401. function updatethreadcount($tid, $updateattach = 0) {
  402. $replycount = C::t('forum_post')->count_visiblepost_by_tid($tid) - 1;
  403. $lastpost = C::t('forum_post')->fetch_visiblepost_by_tid('tid:'.$tid, $tid, 0, 1);
  404. $lastpost['author'] = $lastpost['anonymous'] ? lang('forum/misc', 'anonymous') : addslashes($lastpost['author']);
  405. $lastpost['dateline'] = !empty($lastpost['dateline']) ? $lastpost['dateline'] : TIMESTAMP;
  406. $data = array('replies'=>$replycount, 'lastposter'=>$lastpost['author'], 'lastpost'=>$lastpost['dateline']);
  407. if($updateattach) {
  408. $attach = C::t('forum_post')->fetch_attachment_by_tid($tid);
  409. $data['attachment'] = $attach ? 1 : 0;
  410. }
  411. C::t('forum_thread')->update($tid, $data);
  412. }
  413. function updatemodlog($tids, $action, $expiration = 0, $iscron = 0, $reason = '', $stamp = 0) {
  414. global $_G;
  415. $uid = empty($iscron) ? $_G['uid'] : 0;
  416. $username = empty($iscron) ? $_G['member']['username'] : 0;
  417. $expiration = empty($expiration) ? 0 : intval($expiration);
  418. $data = $comma = '';
  419. $stampadd = $stampaddvalue = '';
  420. if($stamp) {
  421. $stampadd = ', stamp';
  422. $stampaddvalue = ", '$stamp'";
  423. }
  424. foreach(explode(',', str_replace(array('\'', ' '), array('', ''), $tids)) as $tid) {
  425. if($tid) {
  426. $data = array(
  427. 'tid' => $tid,
  428. 'uid' => $uid,
  429. 'username' => $username,
  430. 'dateline' => $_G['timestamp'],
  431. 'action' => $action,
  432. 'expiration' => $expiration,
  433. 'status' => 1,
  434. 'reason' => $reason
  435. );
  436. if($stamp) {
  437. $data['stamp'] = $stamp;
  438. }
  439. C::t('forum_threadmod')->insert($data);
  440. }
  441. }
  442. }
  443. function isopera() {
  444. $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
  445. if(strpos($useragent, 'opera') !== false) {
  446. preg_match('/opera(\/| )([0-9\.]+)/', $useragent, $regs);
  447. return $regs[2];
  448. }
  449. return FALSE;
  450. }
  451. function deletethreadcaches($tids) {
  452. global $_G;
  453. if(!$_G['setting']['cachethreadon']) {
  454. return FALSE;
  455. }
  456. require_once libfile('function/forumlist');
  457. if(!empty($tids)) {
  458. foreach(explode(',', $tids) as $tid) {
  459. $fileinfo = getcacheinfo($tid);
  460. @unlink($fileinfo['filename']);
  461. }
  462. }
  463. return TRUE;
  464. }
  465. function disuploadedfile($file) {
  466. return function_exists('is_uploaded_file') && (is_uploaded_file($file) || is_uploaded_file(str_replace('\\\\', '\\', $file)));
  467. }
  468. function postfeed($feed) {
  469. global $_G;
  470. if($feed) {
  471. require_once libfile('function/feed');
  472. feed_add($feed['icon'], $feed['title_template'], $feed['title_data'], $feed['body_template'], $feed['body_data'], '', $feed['images'], $feed['image_links'], '', '', '', 0, $feed['id'], $feed['idtype']);
  473. }
  474. }
  475. function messagecutstr($str, $length = 0, $dot = ' ...') {
  476. global $_G;
  477. $sppos = strpos($str, chr(0).chr(0).chr(0));
  478. if($sppos !== false) {
  479. $str = substr($str, 0, $sppos);
  480. }
  481. $language = lang('forum/misc');
  482. loadcache(array('bbcodes_display', 'bbcodes', 'smileycodes', 'smilies', 'smileytypes', 'domainwhitelist'));
  483. $bbcodes = 'b|i|u|p|color|size|font|align|list|indent|float';
  484. $bbcodesclear = 'email|code|free|table|tr|td|img|swf|flash|attach|media|audio|payto'.($_G['cache']['bbcodes_display'][$_G['groupid']] ? '|'.implode('|', array_keys($_G['cache']['bbcodes_display'][$_G['groupid']])) : '');
  485. $str = strip_tags(preg_replace(array(
  486. "/\[hide=?\d*\](.*?)\[\/hide\]/is",
  487. "/\[quote](.*?)\[\/quote]/si",
  488. $language['post_edit_regexp'],
  489. "/\[url=?.*?\](.+?)\[\/url\]/si",
  490. "/\[($bbcodesclear)=?.*?\].+?\[\/\\1\]/si",
  491. "/\[($bbcodes)=?.*?\]/i",
  492. "/\[\/($bbcodes)\]/i",
  493. ), array(
  494. "[b]$language[post_hidden][/b]",
  495. '',
  496. '',
  497. '\\1',
  498. '',
  499. '',
  500. '',
  501. ), $str));
  502. if($length) {
  503. $str = cutstr($str, $length, $dot);
  504. }
  505. $str = preg_replace($_G['cache']['smilies']['searcharray'], '', $str);
  506. if($_G['setting']['plugins']['func'][HOOKTYPE]['discuzcode']) {
  507. $_G['discuzcodemessage'] = & $str;
  508. $param = func_get_args();
  509. hookscript('discuzcode', 'global', 'funcs', array('param' => $param, 'caller' => 'messagecutstr'), 'discuzcode');
  510. }
  511. return trim($str);
  512. }
  513. function setthreadcover($pid, $tid = 0, $aid = 0, $countimg = 0, $imgurl = '') {
  514. global $_G;
  515. $cover = 0;
  516. if(empty($_G['uid']) || !intval($_G['setting']['forumpicstyle']['thumbheight']) || !intval($_G['setting']['forumpicstyle']['thumbwidth'])) {
  517. return false;
  518. }
  519. if(($pid || $aid) && empty($countimg)) {
  520. if(empty($imgurl)) {
  521. if($aid) {
  522. $attachtable = 'aid:'.$aid;
  523. $attach = C::t('forum_attachment_n')->fetch('aid:'.$aid, $aid, array(1, -1));
  524. } else {
  525. $attachtable = 'pid:'.$pid;
  526. $attach = C::t('forum_attachment_n')->fetch_max_image('pid:'.$pid, 'pid', $pid);
  527. }
  528. if(!$attach) {
  529. return false;
  530. }
  531. if(empty($_G['forum']['ismoderator']) && $_G['uid'] != $attach['uid']) {
  532. return false;
  533. }
  534. $pid = empty($pid) ? $attach['pid'] : $pid;
  535. $tid = empty($tid) ? $attach['tid'] : $tid;
  536. $picsource = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/'.$attach['attachment'];
  537. } else {
  538. $attachtable = 'pid:'.$pid;
  539. $picsource = $imgurl;
  540. }
  541. $basedir = !$_G['setting']['attachdir'] ? (DISCUZ_ROOT.'./data/attachment/') : $_G['setting']['attachdir'];
  542. $coverdir = 'threadcover/'.substr(md5($tid), 0, 2).'/'.substr(md5($tid), 2, 2).'/';
  543. dmkdir($basedir.'./forum/'.$coverdir);
  544. require_once libfile('class/image');
  545. $image = new image();
  546. if($image->Thumb($picsource, 'forum/'.$coverdir.$tid.'.jpg', $_G['setting']['forumpicstyle']['thumbwidth'], $_G['setting']['forumpicstyle']['thumbheight'], 2)) {
  547. $remote = '';
  548. if(getglobal('setting/ftp/on')) {
  549. if(ftpcmd('upload', 'forum/'.$coverdir.$tid.'.jpg')) {
  550. $remote = '-';
  551. }
  552. }
  553. $cover = C::t('forum_attachment_n')->count_image_by_id($attachtable, 'pid', $pid);
  554. if($imgurl && empty($cover)) {
  555. $cover = 1;
  556. }
  557. $cover = $remote.$cover;
  558. } else {
  559. return false;
  560. }
  561. }
  562. if($countimg) {
  563. if(empty($cover)) {
  564. $thread = C::t('forum_thread')->fetch($tid);
  565. $oldcover = $thread['cover'];
  566. $cover = C::t('forum_attachment_n')->count_image_by_id('tid:'.$tid, 'pid', $pid);
  567. if($cover) {
  568. $cover = $oldcover < 0 ? '-'.$cover : $cover;
  569. }
  570. }
  571. }
  572. if($cover) {
  573. C::t('forum_thread')->update($tid, array('cover' => $cover));
  574. return true;
  575. }
  576. }
  577. ?>