PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/source/function/function_post.php

https://github.com/jinbo51/DiscuzX
PHP | 675 lines | 623 code | 46 blank | 6 comment | 135 complexity | e0f7b1ef967888384b7354d0cf571c8c MD5 | raw file
Possible License(s): BSD-3-Clause
  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 33291 2013-05-22 05:59:13Z nemohou $
  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. $attach['uid'] = $uid;
  154. $newattach[$attach['aid']] = daddslashes($attach);
  155. if($attach['isimage']) {
  156. $newattachfile[$attach['aid']] = $attach['attachment'];
  157. }
  158. }
  159. if($_G['setting']['watermarkstatus'] && empty($_G['forum']['disablewatermark']) || !$_G['setting']['thumbdisabledmobile']) {
  160. require_once libfile('class/image');
  161. $image = new image;
  162. }
  163. if(!empty($_GET['albumaid'])) {
  164. array_unshift($_GET['albumaid'], '');
  165. $_GET['albumaid'] = array_unique($_GET['albumaid']);
  166. unset($_GET['albumaid'][0]);
  167. foreach($_GET['albumaid'] as $aid) {
  168. if(isset($newattach[$aid])) {
  169. $albumattach[$aid] = $newattach[$aid];
  170. }
  171. }
  172. }
  173. foreach($attachnew as $aid => $attach) {
  174. $update = array();
  175. $update['readperm'] = $_G['group']['allowsetattachperm'] ? $attach['readperm'] : 0;
  176. $update['price'] = $_G['group']['maxprice'] ? (intval($attach['price']) <= $_G['group']['maxprice'] ? intval($attach['price']) : $_G['group']['maxprice']) : 0;
  177. $update['tid'] = $tid;
  178. $update['pid'] = $pid;
  179. $update['uid'] = $uid;
  180. $update['description'] = censor(cutstr(dhtmlspecialchars($attach['description']), 100));
  181. C::t('forum_attachment_n')->update('tid:'.$tid, $aid, $update);
  182. if(!$newattach[$aid]) {
  183. continue;
  184. }
  185. $update = array_merge($update, $newattach[$aid]);
  186. if(!empty($newattachfile[$aid])) {
  187. if($_G['setting']['thumbstatus'] && $_G['forum']['disablethumb']) {
  188. $update['thumb'] = 0;
  189. @unlink($_G['setting']['attachdir'].'/forum/'.getimgthumbname($newattachfile[$aid]));
  190. if(!empty($albumattach[$aid])) {
  191. $albumattach[$aid]['thumb'] = 0;
  192. }
  193. } elseif(!$_G['setting']['thumbdisabledmobile']) {
  194. $_daid = sprintf("%09d", $aid);
  195. $dir1 = substr($_daid, 0, 3);
  196. $dir2 = substr($_daid, 3, 2);
  197. $dir3 = substr($_daid, 5, 2);
  198. $dw = 320;
  199. $dh = 320;
  200. $thumbfile = 'image/'.$dir1.'/'.$dir2.'/'.$dir3.'/'.substr($_daid, -2).'_'.$dw.'_'.$dh.'.jpg';
  201. $image->Thumb($_G['setting']['attachdir'].'/forum/'.$newattachfile[$aid], $thumbfile, $dw, $dh, 'fixwr');
  202. $dw = 720;
  203. $dh = 720;
  204. $thumbfile = 'image/'.$dir1.'/'.$dir2.'/'.$dir3.'/'.substr($_daid, -2).'_'.$dw.'_'.$dh.'.jpg';
  205. $image->Thumb($_G['setting']['attachdir'].'/forum/'.$newattachfile[$aid], $thumbfile, $dw, $dh, 'fixwr');
  206. }
  207. if($_G['setting']['watermarkstatus'] && empty($_G['forum']['disablewatermark'])) {
  208. $image->Watermark($_G['setting']['attachdir'].'/forum/'.$newattachfile[$aid], '', 'forum');
  209. $update['filesize'] = $image->imginfo['size'];
  210. }
  211. }
  212. if(!empty($_GET['albumaid']) && isset($albumattach[$aid])) {
  213. $newalbum = 0;
  214. if(!$_GET['uploadalbum']) {
  215. require_once libfile('function/spacecp');
  216. $_GET['uploadalbum'] = album_creat(array('albumname' => $_GET['newalbum']));
  217. $newalbum = 1;
  218. }
  219. $picdata = array(
  220. 'albumid' => $_GET['uploadalbum'],
  221. 'uid' => $uid,
  222. 'username' => $_G['username'],
  223. 'dateline' => $albumattach[$aid]['dateline'],
  224. 'postip' => $_G['clientip'],
  225. 'filename' => censor($albumattach[$aid]['filename']),
  226. 'title' => censor(cutstr(dhtmlspecialchars($attach['description']), 100)),
  227. 'type' => fileext($albumattach[$aid]['attachment']),
  228. 'size' => $albumattach[$aid]['filesize'],
  229. 'filepath' => $albumattach[$aid]['attachment'],
  230. 'thumb' => $albumattach[$aid]['thumb'],
  231. 'remote' => $albumattach[$aid]['remote'] + 2,
  232. );
  233. $update['picid'] = C::t('home_pic')->insert($picdata, 1);
  234. if($newalbum) {
  235. require_once libfile('function/home');
  236. require_once libfile('function/spacecp');
  237. album_update_pic($_GET['uploadalbum']);
  238. }
  239. }
  240. C::t('forum_attachment_n')->insert('tid:'.$tid, $update, false, true);
  241. C::t('forum_attachment')->update($aid, array('tid' => $tid, 'pid' => $pid, 'tableid' => getattachtableid($tid)));
  242. C::t('forum_attachment_unused')->delete($aid);
  243. }
  244. if(!empty($_GET['albumaid'])) {
  245. $albumdata = array(
  246. 'picnum' => C::t('home_pic')->check_albumpic($_GET['uploadalbum']),
  247. 'updatetime' => $_G['timestamp'],
  248. );
  249. C::t('home_album')->update($_GET['uploadalbum'], $albumdata);
  250. require_once libfile('function/home');
  251. require_once libfile('function/spacecp');
  252. album_update_pic($_GET['uploadalbum']);
  253. }
  254. if($newattach) {
  255. ftpupload($newaids, $uid);
  256. }
  257. }
  258. if(!$modnewthreads && $newattach && $uid == $_G['uid']) {
  259. updatecreditbyaction('postattach', $uid, array(), '', count($newattach), 1, $_G['fid']);
  260. }
  261. if($attachupdate) {
  262. $attachs = C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$tid, 'aid', array_keys($attachupdate));
  263. foreach($attachs as $attach) {
  264. if(array_key_exists($attach['aid'], $attachupdate) && $attachupdate[$attach['aid']]) {
  265. dunlink($attach);
  266. }
  267. }
  268. $unusedattachs = C::t('forum_attachment_unused')->fetch_all($attachupdate);
  269. $attachupdate = array_flip($attachupdate);
  270. $unusedaids = array();
  271. foreach($unusedattachs as $attach) {
  272. if($attach['uid'] != $uid && !$_G['forum']['ismoderator']) {
  273. continue;
  274. }
  275. $unusedaids[] = $attach['aid'];
  276. $update = $attach;
  277. $update['dateline'] = TIMESTAMP;
  278. $update['remote'] = 0;
  279. unset($update['aid']);
  280. if($attach['isimage'] && $_G['setting']['watermarkstatus'] && empty($_G['forum']['disablewatermark'])) {
  281. $image->Watermark($_G['setting']['attachdir'].'/forum/'.$attach['attachment'], '', 'forum');
  282. $update['filesize'] = $image->imginfo['size'];
  283. }
  284. C::t('forum_attachment_n')->update('tid:'.$tid, $attachupdate[$attach['aid']], $update);
  285. @unlink($_G['setting']['attachdir'].'image/'.$attach['aid'].'_100_100.jpg');
  286. C::t('forum_attachment_exif')->delete($attachupdate[$attach['aid']]);
  287. C::t('forum_attachment_exif')->update($attach['aid'], array('aid' => $attachupdate[$attach['aid']]));
  288. ftpupload(array($attachupdate[$attach['aid']]), $uid);
  289. }
  290. if($unusedaids) {
  291. C::t('forum_attachment_unused')->delete($unusedaids);
  292. }
  293. }
  294. $attachcount = C::t('forum_attachment_n')->count_by_id('tid:'.$tid, $pid ? 'pid' : 'tid', $pid ? $pid : $tid);
  295. $attachment = 0;
  296. if($attachcount) {
  297. if(C::t('forum_attachment_n')->count_image_by_id('tid:'.$tid, $pid ? 'pid' : 'tid', $pid ? $pid : $tid)) {
  298. $attachment = 2;
  299. } else {
  300. $attachment = 1;
  301. }
  302. } else {
  303. $attachment = 0;
  304. }
  305. C::t('forum_thread')->update($tid, array('attachment'=>$attachment));
  306. C::t('forum_post')->update('tid:'.$tid, $pid, array('attachment' => $attachment), true);
  307. if(!$attachment) {
  308. C::t('forum_threadimage')->delete_by_tid($tid);
  309. }
  310. $_G['forum_attachexist'] = $attachment;
  311. }
  312. function checkflood() {
  313. global $_G;
  314. if(!$_G['group']['disablepostctrl'] && $_G['uid']) {
  315. if($_G['setting']['floodctrl'] && discuz_process::islocked("post_lock_".$_G['uid'], $_G['setting']['floodctrl'])) {
  316. return true;
  317. }
  318. return false;
  319. }
  320. return FALSE;
  321. }
  322. function checkmaxperhour($type) {
  323. global $_G;
  324. $morenumperhour = false;
  325. if(!$_G['group']['disablepostctrl'] && $_G['uid']) {
  326. if($_G['group']['max'.($type == 'pid' ? 'posts' : 'threads').'perhour']) {
  327. $usernum = C::t('common_member_action_log')->count_per_hour($_G['uid'], $type);
  328. $var = $type === 'tid' ? 'maxthreadsperhour' : 'maxpostsperhour';
  329. $isflood = $usernum && ($usernum >= $_G['group'][$var]);
  330. if($isflood) {
  331. $morenumperhour = true;
  332. }
  333. }
  334. }
  335. return $morenumperhour;
  336. }
  337. function checkpost($subject, $message, $special = 0) {
  338. global $_G;
  339. if(dstrlen($subject) > 80) {
  340. return 'post_subject_toolong';
  341. }
  342. if(!$_G['group']['disablepostctrl'] && !$special) {
  343. if($_G['setting']['maxpostsize'] && strlen($message) > $_G['setting']['maxpostsize']) {
  344. return 'post_message_toolong';
  345. } elseif($_G['setting']['minpostsize']) {
  346. $minpostsize = !IN_MOBILE || !$_G['setting']['minpostsize_mobile'] ? $_G['setting']['minpostsize'] : $_G['setting']['minpostsize_mobile'];
  347. if(strlen(preg_replace("/\[quote\].+?\[\/quote\]/is", '', $message)) < $minpostsize || strlen(preg_replace("/\[postbg\].+?\[\/postbg\]/is", '', $message)) < $minpostsize) {
  348. return 'post_message_tooshort';
  349. }
  350. }
  351. }
  352. return FALSE;
  353. }
  354. function checkbbcodes($message, $bbcodeoff) {
  355. return !$bbcodeoff && (!strpos($message, '[/') && !strpos($message, '[hr]')) ? -1 : $bbcodeoff;
  356. }
  357. function checksmilies($message, $smileyoff) {
  358. global $_G;
  359. if($smileyoff) {
  360. return 1;
  361. } else {
  362. if(!empty($_G['cache']['smileycodes']) && is_array($_G['cache']['smileycodes'])) {
  363. foreach($_G['cache']['smileycodes'] as $id => $code) {
  364. if(strpos($message, $code) !== FALSE) {
  365. return 0;
  366. }
  367. }
  368. }
  369. return -1;
  370. }
  371. }
  372. function updatepostcredits($operator, $uidarray, $action, $fid = 0) {
  373. global $_G;
  374. $val = $operator == '+' ? 1 : -1;
  375. $extsql = array();
  376. if(empty($uidarray)) {
  377. return false;
  378. }
  379. $uidarray = (array)$uidarray;
  380. $uidarr = array();
  381. foreach($uidarray as $uid) {
  382. $uidarr[$uid] = !isset($uidarr[$uid]) ? 1 : $uidarr[$uid]+1;
  383. }
  384. foreach($uidarr as $uid => $coef) {
  385. $opnum = $val*$coef;
  386. if($action == 'reply') {
  387. $extsql = array('posts' => $opnum);
  388. } elseif($action == 'post') {
  389. $extsql = array('threads' => $opnum, 'posts' => $opnum);
  390. }
  391. if($uid == $_G['uid']) {
  392. updatecreditbyaction($action, $uid, $extsql, '', $opnum, 1, $fid);
  393. } elseif(empty($uid)) {
  394. continue;
  395. } else {
  396. batchupdatecredit($action, $uid, $extsql, $opnum, $fid);
  397. }
  398. }
  399. if($operator == '+' && ($action == 'reply' || $action == 'post')) {
  400. C::t('common_member_status')->update(array_keys($uidarr), array('lastpost' => TIMESTAMP), 'UNBUFFERED');
  401. }
  402. }
  403. function updateattachcredits($operator, $uidarray) {
  404. global $_G;
  405. foreach($uidarray as $uid => $attachs) {
  406. updatecreditbyaction('postattach', $uid, array(), '', $operator == '-' ? -$attachs : $attachs, 1, $_G['fid']);
  407. }
  408. }
  409. function updateforumcount($fid) {
  410. extract(C::t('forum_thread')->count_posts_by_fid($fid));
  411. $thread = C::t('forum_thread')->fetch_by_fid_displayorder($fid, 0, '=');
  412. $thread['subject'] = addslashes($thread['subject']);
  413. $thread['lastposter'] = $thread['author'] ? addslashes($thread['lastposter']) : lang('forum/misc', 'anonymous');
  414. $tid = $thread['closed'] > 1 ? $thread['closed'] : $thread['tid'];
  415. $setarr = array('posts' => $posts, 'threads' => $threads, 'lastpost' => "$tid\t$thread[subject]\t$thread[lastpost]\t$thread[lastposter]");
  416. C::t('forum_forum')->update($fid, $setarr);
  417. }
  418. function updatethreadcount($tid, $updateattach = 0) {
  419. $replycount = C::t('forum_post')->count_visiblepost_by_tid($tid) - 1;
  420. $lastpost = C::t('forum_post')->fetch_visiblepost_by_tid('tid:'.$tid, $tid, 0, 1);
  421. $lastpost['author'] = $lastpost['anonymous'] ? lang('forum/misc', 'anonymous') : addslashes($lastpost['author']);
  422. $lastpost['dateline'] = !empty($lastpost['dateline']) ? $lastpost['dateline'] : TIMESTAMP;
  423. $data = array('replies'=>$replycount, 'lastposter'=>$lastpost['author'], 'lastpost'=>$lastpost['dateline']);
  424. if($updateattach) {
  425. $attach = C::t('forum_post')->fetch_attachment_by_tid($tid);
  426. $data['attachment'] = $attach ? 1 : 0;
  427. }
  428. C::t('forum_thread')->update($tid, $data);
  429. }
  430. function updatemodlog($tids, $action, $expiration = 0, $iscron = 0, $reason = '', $stamp = 0) {
  431. global $_G;
  432. $uid = empty($iscron) ? $_G['uid'] : 0;
  433. $username = empty($iscron) ? $_G['member']['username'] : 0;
  434. $expiration = empty($expiration) ? 0 : intval($expiration);
  435. $data = $comma = '';
  436. $stampadd = $stampaddvalue = '';
  437. if($stamp) {
  438. $stampadd = ', stamp';
  439. $stampaddvalue = ", '$stamp'";
  440. }
  441. foreach(explode(',', str_replace(array('\'', ' '), array('', ''), $tids)) as $tid) {
  442. if($tid) {
  443. $data = array(
  444. 'tid' => $tid,
  445. 'uid' => $uid,
  446. 'username' => $username,
  447. 'dateline' => $_G['timestamp'],
  448. 'action' => $action,
  449. 'expiration' => $expiration,
  450. 'status' => 1,
  451. 'reason' => $reason
  452. );
  453. if($stamp) {
  454. $data['stamp'] = $stamp;
  455. }
  456. C::t('forum_threadmod')->insert($data);
  457. }
  458. }
  459. }
  460. function isopera() {
  461. $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
  462. if(strpos($useragent, 'opera') !== false) {
  463. preg_match('/opera(\/| )([0-9\.]+)/', $useragent, $regs);
  464. return $regs[2];
  465. }
  466. return FALSE;
  467. }
  468. function deletethreadcaches($tids) {
  469. global $_G;
  470. if(!$_G['setting']['cachethreadon']) {
  471. return FALSE;
  472. }
  473. require_once libfile('function/forumlist');
  474. if(!empty($tids)) {
  475. foreach(explode(',', $tids) as $tid) {
  476. $fileinfo = getcacheinfo($tid);
  477. @unlink($fileinfo['filename']);
  478. }
  479. }
  480. return TRUE;
  481. }
  482. function disuploadedfile($file) {
  483. return function_exists('is_uploaded_file') && (is_uploaded_file($file) || is_uploaded_file(str_replace('\\\\', '\\', $file)));
  484. }
  485. function postfeed($feed) {
  486. global $_G;
  487. if($feed) {
  488. require_once libfile('function/feed');
  489. 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']);
  490. }
  491. }
  492. function messagesafeclear($message) {
  493. if(strpos($message, '[/password]') !== FALSE) {
  494. $message = '';
  495. }
  496. if(strpos($message, '[/postbg]') !== FALSE) {
  497. $message = preg_replace("/\s?\[postbg\]\s*([^\[\<\r\n;'\"\?\(\)]+?)\s*\[\/postbg\]\s?/is", '', $message);
  498. }
  499. if(strpos($message, '[/begin]') !== FALSE) {
  500. $message = preg_replace("/\[begin(=\s*([^\[\<\r\n]*?)\s*,(\d*),(\d*),(\d*),(\d*))?\]\s*([^\[\<\r\n]+?)\s*\[\/begin\]/is", '', $message);
  501. }
  502. if(strpos($message, '[page]') !== FALSE) {
  503. $message = preg_replace("/\s?\[page\]\s?/is", '', $message);
  504. }
  505. if(strpos($message, '[/index]') !== FALSE) {
  506. $message = preg_replace("/\s?\[index\](.+?)\[\/index\]\s?/is", '', $message);
  507. }
  508. if(strpos($message, '[/begin]') !== FALSE) {
  509. $message = preg_replace("/\[begin(=\s*([^\[\<\r\n]*?)\s*,(\d*),(\d*),(\d*),(\d*))?\]\s*([^\[\<\r\n]+?)\s*\[\/begin\]/is", '', $message);
  510. }
  511. if(strpos($message, '[/groupid]') !== FALSE) {
  512. $message = preg_replace("/\[groupid=\d+\].*\[\/groupid\]/i", '', $message);
  513. }
  514. $language = lang('forum/misc');
  515. $message = preg_replace(array($language['post_edithtml_regexp'],$language['post_editnobbcode_regexp'],$language['post_edit_regexp']), '', $message);
  516. return $message;
  517. }
  518. function messagecutstr($str, $length = 0, $dot = ' ...') {
  519. global $_G;
  520. $str = messagesafeclear($str);
  521. $sppos = strpos($str, chr(0).chr(0).chr(0));
  522. if($sppos !== false) {
  523. $str = substr($str, 0, $sppos);
  524. }
  525. $language = lang('forum/misc');
  526. loadcache(array('bbcodes_display', 'bbcodes', 'smileycodes', 'smilies', 'smileytypes', 'domainwhitelist'));
  527. $bbcodes = 'b|i|u|p|color|size|font|align|list|indent|float';
  528. $bbcodesclear = 'email|code|free|table|tr|td|img|swf|flash|attach|media|audio|groupid|payto'.($_G['cache']['bbcodes_display'][$_G['groupid']] ? '|'.implode('|', array_keys($_G['cache']['bbcodes_display'][$_G['groupid']])) : '');
  529. $str = strip_tags(preg_replace(array(
  530. "/\[hide=?\d*\](.*?)\[\/hide\]/is",
  531. "/\[quote](.*?)\[\/quote]/si",
  532. $language['post_edit_regexp'],
  533. "/\[url=?.*?\](.+?)\[\/url\]/si",
  534. "/\[($bbcodesclear)=?.*?\].+?\[\/\\1\]/si",
  535. "/\[($bbcodes)=?.*?\]/i",
  536. "/\[\/($bbcodes)\]/i",
  537. ), array(
  538. "[b]$language[post_hidden][/b]",
  539. '',
  540. '',
  541. '\\1',
  542. '',
  543. '',
  544. '',
  545. ), $str));
  546. if($length) {
  547. $str = cutstr($str, $length, $dot);
  548. }
  549. $str = preg_replace($_G['cache']['smilies']['searcharray'], '', $str);
  550. if($_G['setting']['plugins']['func'][HOOKTYPE]['discuzcode']) {
  551. $_G['discuzcodemessage'] = & $str;
  552. $param = func_get_args();
  553. hookscript('discuzcode', 'global', 'funcs', array('param' => $param, 'caller' => 'messagecutstr'), 'discuzcode');
  554. }
  555. return trim($str);
  556. }
  557. function setthreadcover($pid, $tid = 0, $aid = 0, $countimg = 0, $imgurl = '') {
  558. global $_G;
  559. $cover = 0;
  560. if(empty($_G['uid']) || !intval($_G['setting']['forumpicstyle']['thumbheight']) || !intval($_G['setting']['forumpicstyle']['thumbwidth'])) {
  561. return false;
  562. }
  563. if(($pid || $aid) && empty($countimg)) {
  564. if(empty($imgurl)) {
  565. if($aid) {
  566. $attachtable = 'aid:'.$aid;
  567. $attach = C::t('forum_attachment_n')->fetch('aid:'.$aid, $aid, array(1, -1));
  568. } else {
  569. $attachtable = 'pid:'.$pid;
  570. $attach = C::t('forum_attachment_n')->fetch_max_image('pid:'.$pid, 'pid', $pid);
  571. }
  572. if(!$attach) {
  573. return false;
  574. }
  575. if(empty($_G['forum']['ismoderator']) && $_G['uid'] != $attach['uid']) {
  576. return false;
  577. }
  578. $pid = empty($pid) ? $attach['pid'] : $pid;
  579. $tid = empty($tid) ? $attach['tid'] : $tid;
  580. $picsource = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/'.$attach['attachment'];
  581. } else {
  582. $attachtable = 'pid:'.$pid;
  583. $picsource = $imgurl;
  584. }
  585. $basedir = !$_G['setting']['attachdir'] ? (DISCUZ_ROOT.'./data/attachment/') : $_G['setting']['attachdir'];
  586. $coverdir = 'threadcover/'.substr(md5($tid), 0, 2).'/'.substr(md5($tid), 2, 2).'/';
  587. dmkdir($basedir.'./forum/'.$coverdir);
  588. require_once libfile('class/image');
  589. $image = new image();
  590. if($image->Thumb($picsource, 'forum/'.$coverdir.$tid.'.jpg', $_G['setting']['forumpicstyle']['thumbwidth'], $_G['setting']['forumpicstyle']['thumbheight'], 2)) {
  591. $remote = '';
  592. if(getglobal('setting/ftp/on')) {
  593. if(ftpcmd('upload', 'forum/'.$coverdir.$tid.'.jpg')) {
  594. $remote = '-';
  595. }
  596. }
  597. $cover = C::t('forum_attachment_n')->count_image_by_id($attachtable, 'pid', $pid);
  598. if($imgurl && empty($cover)) {
  599. $cover = 1;
  600. }
  601. $cover = $remote.$cover;
  602. } else {
  603. return false;
  604. }
  605. }
  606. if($countimg) {
  607. if(empty($cover)) {
  608. $thread = C::t('forum_thread')->fetch($tid);
  609. $oldcover = $thread['cover'];
  610. $cover = C::t('forum_attachment_n')->count_image_by_id('tid:'.$tid, 'pid', $pid);
  611. if($cover) {
  612. $cover = $oldcover < 0 ? '-'.$cover : $cover;
  613. }
  614. }
  615. }
  616. if($cover) {
  617. C::t('forum_thread')->update($tid, array('cover' => $cover));
  618. return true;
  619. }
  620. }
  621. ?>