model_forum_post.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  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: model_forum_post.php 34819 2014-08-11 06:46:20Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class model_forum_post extends discuz_model {
  12. public $forum;
  13. public $thread;
  14. public $post;
  15. public $pid = 0;
  16. public $feed = array();
  17. public function __construct($tid = null, $pid = null) {
  18. parent::__construct();
  19. require_once libfile('function/post');
  20. require_once libfile('function/forumlist');
  21. if($tid) {
  22. include_once libfile('function/forum');
  23. loadforum(null, $tid);
  24. if($pid) {
  25. $this->post = get_post_by_tid_pid($tid, $pid);
  26. }
  27. }
  28. $this->forum = &$this->app->var['forum'];
  29. $this->thread = &$this->app->var['thread'];
  30. $this->group = &$this->app->var['group'];
  31. }
  32. protected function _init_parameters($parameters) {
  33. $varname = array(
  34. 'member', 'group', 'forum', 'thread', 'extramessage', 'special',//'nauthorid' 'modnewreplies' 'tid'
  35. 'message','clientip', 'invisible', 'isanonymous', 'usesig',
  36. 'htmlon', 'bbcodeoff', 'smileyoff', 'parseurloff', 'pstatus',
  37. 'noticetrimstr', 'noticeauthor', 'from', 'sechash', 'geoloc',
  38. 'subject', 'special', 'sortid', 'typeid', 'isanonymous', 'cronpublish', 'cronpublishdate', 'save',
  39. 'readperm', 'price', 'ordertype', 'hiddenreplies', 'allownoticeauthor', 'audit', 'tags', 'bbcodeoff', 'imgcontent', 'imgcontentwidth',
  40. 'smileyoff', 'parseurloff', 'usesig', 'htmlon', 'extramessage',
  41. );
  42. foreach($varname as $name) {
  43. if(!isset($this->param[$name]) && isset($parameters[$name])) {
  44. $this->param[$name] = $parameters[$name];
  45. }
  46. }
  47. }
  48. public function newreply($parameters) {
  49. $this->_init_parameters($parameters);
  50. if($this->thread['closed'] && !$this->forum['ismoderator'] && !$this->thread['isgroup']) {
  51. return $this->showmessage('post_thread_closed');
  52. } elseif(!$this->thread['isgroup'] && $post_autoclose = checkautoclose($this->thread)) {
  53. return $this->showmessage($post_autoclose, '', array('autoclose' => $this->forum['autoclose']));
  54. } if(trim($this->param['subject']) == '' && trim($this->param['message']) == '' && $this->thread['special'] != 2) {
  55. return $this->showmessage('post_sm_isnull');
  56. } elseif($post_invalid = checkpost($this->param['subject'], $this->param['message'], $this->param['special'] == 2 && $this->group['allowposttrade'])) {
  57. return $this->showmessage($post_invalid, '', array('minpostsize' => $this->setting['minpostsize'], 'maxpostsize' => $this->setting['maxpostsize']));
  58. } elseif(checkflood()) {
  59. return $this->showmessage('post_flood_ctrl', '', array('floodctrl' => $this->setting['floodctrl']));
  60. } elseif(checkmaxperhour('pid')) {
  61. return $this->showmessage('post_flood_ctrl_posts_per_hour', '', array('posts_per_hour' => $this->group['maxpostsperhour']));
  62. }
  63. $heatthreadset = update_threadpartake($this->thread['tid'], true);
  64. $bbcodeoff = checkbbcodes($this->param['message'], !empty($this->param['bbcodeoff']));
  65. $smileyoff = checksmilies($this->param['message'], !empty($this->param['smileyoff']));
  66. $parseurloff = !empty($this->param['parseurloff']);
  67. $htmlon = $this->group['allowhtml'] && !empty($this->param['htmlon']) ? 1 : 0;
  68. $usesig = !empty($this->param['usesig']) && $this->group['maxsigsize'] ? 1 : 0;
  69. $this->param['isanonymous'] = $this->group['allowanonymous'] && !empty($this->param['isanonymous'])? 1 : 0;
  70. $author = empty($this->param['isanonymous']) ? $this->member['username'] : '';
  71. list(, $this->param['modnewreplies']) = threadmodstatus($this->param['subject']."\t".$this->param['message'].$this->param['extramessage']);
  72. if($this->thread['displayorder'] == -4) {
  73. $this->param['modnewreplies'] = 0;
  74. }
  75. $pinvisible = $this->param['modnewreplies'] ? -2 : ($this->thread['displayorder'] == -4 ? -3 : 0);
  76. $this->param['message'] = preg_replace('/\[attachimg\](\d+)\[\/attachimg\]/is', '[attach]\1[/attach]', $this->param['message']);
  77. if(!empty($this->param['noticetrimstr'])) {
  78. $this->param['message'] = $this->param['noticetrimstr']."\n\n".$this->param['message'];
  79. $bbcodeoff = false;
  80. }
  81. $status = (defined('IN_MOBILE') ? 8 : 0);
  82. if($this->param['modstatus']) {
  83. foreach($this->param['modstatus'] as $modbit => $modvalue) {
  84. $status = setstatus($modbit, $modvalue, $status);
  85. }
  86. }
  87. $this->pid = insertpost(array(
  88. 'fid' => $this->forum['fid'],
  89. 'tid' => $this->thread['tid'],
  90. 'first' => '0',
  91. 'author' => $this->member['username'],
  92. 'authorid' => $this->member['uid'],
  93. 'subject' => $this->param['subject'],
  94. 'dateline' => $this->param['timestamp'] ? $this->param['timestamp'] : getglobal('timestamp'),
  95. 'message' => $this->param['message'],
  96. 'useip' => $this->param['clientip'] ? $this->param['clientip'] : getglobal('clientip'),
  97. 'port' => $this->param['remoteport'] ? $this->param['remoteport'] : getglobal('remoteport'),
  98. 'invisible' => $pinvisible,
  99. 'anonymous' => $this->param['isanonymous'],
  100. 'usesig' => $usesig,
  101. 'htmlon' => $htmlon,
  102. 'bbcodeoff' => $bbcodeoff,
  103. 'smileyoff' => $smileyoff,
  104. 'parseurloff' => $parseurloff,
  105. 'attachment' => '0',
  106. 'status' => $status,
  107. ));
  108. $this->param['updatethreaddata'] = $heatthreadset ? $heatthreadset : array();
  109. $this->param['maxposition'] = C::t('forum_post')->fetch_maxposition_by_tid($this->thread['posttableid'], $this->thread['tid']);
  110. $this->param['updatethreaddata'][] = DB::field('maxposition', $this->param['maxposition']);
  111. useractionlog($this->member['uid'], 'pid');
  112. if($this->param['geoloc'] && IN_MOBILE == 2) {
  113. list($mapx, $mapy, $location) = explode('|', $this->param['geoloc']);
  114. if($mapx && $mapy && $location) {
  115. C::t('forum_post_location')->insert(array(
  116. 'pid' => $this->pid,
  117. 'tid' => $this->thread['tid'],
  118. 'uid' => $this->member['uid'],
  119. 'mapx' => $mapx,
  120. 'mapy' => $mapy,
  121. 'location' => $location,
  122. ));
  123. }
  124. }
  125. $nauthorid = 0;
  126. if(!empty($this->param['noticeauthor']) && !$this->param['isanonymous'] && !$this->param['modnewreplies']) {
  127. list($ac, $nauthorid) = explode('|', authcode($this->param['noticeauthor'], 'DECODE'));
  128. if($nauthorid != $this->member['uid']) {
  129. if($ac == 'q') {
  130. notification_add($nauthorid, 'post', 'reppost_noticeauthor', array(
  131. 'tid' => $this->thread['tid'],
  132. 'subject' => $this->thread['subject'],
  133. 'fid' => $this->forum['fid'],
  134. 'pid' => $this->pid,
  135. 'from_id' => $this->pid,
  136. 'from_idtype' => 'quote',
  137. ));
  138. } elseif($ac == 'r') {
  139. notification_add($nauthorid, 'post', 'reppost_noticeauthor', array(
  140. 'tid' => $this->thread['tid'],
  141. 'subject' => $this->thread['subject'],
  142. 'fid' => $this->forum['fid'],
  143. 'pid' => $this->pid,
  144. 'from_id' => $this->thread['tid'],
  145. 'from_idtype' => 'post',
  146. ));
  147. }
  148. }
  149. }
  150. if($this->thread['authorid'] != $this->member['uid'] && getstatus($this->thread['status'], 6) && empty($this->param['noticeauthor']) && !$this->param['isanonymous'] && !$this->param['modnewreplies']) {
  151. $thapost = C::t('forum_post')->fetch_threadpost_by_tid_invisible($this->thread['tid'], 0);
  152. notification_add($thapost['authorid'], 'post', 'reppost_noticeauthor', array(
  153. 'tid' => $this->thread['tid'],
  154. 'subject' => $this->thread['subject'],
  155. 'fid' => $this->forum['fid'],
  156. 'pid' => $this->pid,
  157. 'from_id' => $this->thread['tid'],
  158. 'from_idtype' => 'post',
  159. ));
  160. }
  161. $this->forum['threadcaches'] && deletethreadcaches($this->thread['tid']);
  162. include_once libfile('function/stat');
  163. updatestat($this->thread['isgroup'] ? 'grouppost' : 'post');
  164. $this->param['showmsgparam']['fid'] = $this->forum['fid'];
  165. $this->param['showmsgparam']['tid'] = $this->thread['tid'];
  166. $this->param['showmsgparam']['pid'] = $this->pid;
  167. $this->param['showmsgparam']['from'] = $this->param['from'];
  168. $this->param['showmsgparam']['sechash'] = !empty($this->param['sechash']) ? $this->param['sechash'] : '';
  169. dsetcookie('clearUserdata', 'forum');
  170. if($this->thread['replies'] <= 0) {
  171. C::t('forum_sofa')->delete($this->thread['tid']);
  172. }
  173. if($this->param['modnewreplies']) {
  174. updatemoderate('pid', $this->pid);
  175. unset($this->param['showmsgparam']['pid']);
  176. if($this->param['updatethreaddata']) {
  177. C::t('forum_thread')->update($this->thread['tid'], $this->param['updatethreaddata'], false, false, 0, true);
  178. }
  179. C::t('forum_forum')->update_forum_counter($this->forum['fid'], 0, 0, 1, 1);
  180. manage_addnotify('verifypost');
  181. return 'post_reply_mod_succeed';
  182. } else {
  183. $fieldarr = array(
  184. 'lastposter' => array($author),
  185. 'replies' => 1
  186. );
  187. if($this->thread['lastpost'] < getglobal('timestamp')) {
  188. $fieldarr['lastpost'] = array(getglobal('timestamp'));
  189. }
  190. $row = C::t('forum_threadaddviews')->fetch($this->thread['tid']);
  191. if(!empty($row)) {
  192. C::t('forum_threadaddviews')->update($this->thread['tid'], array('addviews' => 0));
  193. $fieldarr['views'] = $row['addviews'];
  194. }
  195. $this->param['updatethreaddata'] = array_merge($this->param['updatethreaddata'], C::t('forum_thread')->increase($this->thread['tid'], $fieldarr, false, 0, true));
  196. if($this->thread['displayorder'] != -4) {
  197. updatepostcredits('+', $this->member['uid'], 'reply', $this->forum['fid']);
  198. if($this->forum['status'] == 3) {
  199. if($this->forum['closed'] > 1) {
  200. C::t('forum_thread')->increase($this->forum['closed'], $fieldarr, true);
  201. }
  202. C::t('forum_groupuser')->update_counter_for_user($this->member['uid'], $this->forum['fid'], 0, 1);
  203. C::t('forum_forumfield')->update($this->forum['fid'], array('lastupdate' => TIMESTAMP));
  204. require_once libfile('function/grouplog');
  205. updategroupcreditlog($this->forum['fid'], $this->member['uid']);
  206. }
  207. $lastpost = $this->thread['tid']."\t".$this->thread['subject']."\t".getglobal('timestamp')."\t".$author;
  208. C::t('forum_forum')->update($this->forum['fid'], array('lastpost' => $lastpost));
  209. C::t('forum_forum')->update_forum_counter($this->forum['fid'], 0, 1, 1);
  210. if($this->forum['type'] == 'sub') {
  211. C::t('forum_forum')->update($this->forum['fup'], array('lastpost' => $lastpost));
  212. }
  213. }
  214. $this->param['page'] = getstatus($this->thread['status'], 4) ? 1 : @ceil(($this->thread['special'] ? $this->thread['replies'] + 1 : $this->thread['replies'] + 2) / getglobal('ppp'));
  215. if($this->param['updatethreaddata']) {
  216. C::t('forum_thread')->update($this->thread['tid'], $this->param['updatethreaddata'], false, false, 0, true);
  217. }
  218. return 'post_reply_succeed';
  219. }
  220. }
  221. public function replyfeed() {
  222. if(!$this->feed) {
  223. if($this->forum['allowfeed'] && !$this->param['isanonymous']) {
  224. if($this->thread['authorid'] != $this->member['uid']) {
  225. $post_url = "forum.php?mod=redirect&goto=findpost&pid=".$this->pid."&ptid=".$this->thread['tid'];
  226. $this->feed['icon'] = 'post';
  227. $this->feed['title_template'] = !empty($this->thread['author']) ? 'feed_reply_title' : 'feed_reply_title_anonymous';
  228. $this->feed['title_data'] = array(
  229. 'subject' => "<a href=\"$post_url\">".$this->thread['subject']."</a>",
  230. 'author' => "<a href=\"home.php?mod=space&uid=".$this->thread['authorid']."\">".$this->thread['author']."</a>"
  231. );
  232. $forum_attachexist = getglobal('forum_attachexist');
  233. if(!empty($forum_attachexist)) {
  234. $imgattach = C::t('forum_attachment_n')->fetch_max_image('tid:'.$this->thread['tid'], 'pid', $this->pid);
  235. $firstaid = $imgattach['aid'];
  236. unset($imgattach);
  237. if($firstaid) {
  238. $this->feed['images'] = array(getforumimg($firstaid));
  239. $this->feed['image_links'] = array($post_url);
  240. }
  241. }
  242. }
  243. }
  244. }
  245. $this->feed['title_data']['hash_data'] = "tid".$this->thread['tid'];
  246. $this->feed['id'] = $this->pid;
  247. $this->feed['idtype'] = 'pid';
  248. if($this->feed['icon']) {
  249. postfeed($this->feed);
  250. }
  251. }
  252. public function thread($name = null, $val = null) {
  253. if(isset($val)) {
  254. return $this->setvar($this->thread, $name, $val);
  255. } else {
  256. return $this->getvar($this->thread, $name);
  257. }
  258. }
  259. public function forum($name = null, $val = null) {
  260. if(isset($val)) {
  261. return $this->setvar($this->forum, $name, $val);
  262. } else {
  263. return $this->getvar($this->forum, $name);
  264. }
  265. }
  266. public function editpost($parameters) {
  267. $this->_init_parameters($parameters);
  268. $isfirstpost = $this->post['first'] ? 1 : 0;
  269. $isorigauthor = $this->member['uid'] && $this->member['uid'] == $this->post['authorid'];
  270. $this->param['audit'] = $this->post['invisible'] == -2 || $this->thread['displayorder'] == -2 ? $this->param['audit'] : 0;
  271. list($this->param['modnewthreads'], $this->param['modnewreplies']) = threadmodstatus($this->param['subject']."\t".$this->param['message'].$this->param['extramessage']);
  272. if($post_invalid = checkpost($this->param['subject'], $this->param['message'], $isfirstpost && ($this->param['special'] || $this->param['sortid']))) {
  273. showmessage($post_invalid, '', array('minpostsize' => $this->setting['minpostsize'], 'maxpostsize' => $this->setting['maxpostsize']));
  274. }
  275. if(!$isorigauthor && !$this->group['allowanonymous']) {
  276. if($this->post['anonymous'] && !$this->param['isanonymous']) {
  277. $this->param['isanonymous'] = 0;
  278. $this->param['threadupdatearr']['author'] = $this->post['author'];
  279. $anonymousadd = 0;
  280. } else {
  281. $this->param['isanonymous'] = $this->post['anonymous'];
  282. $anonymousadd = '';
  283. }
  284. } else {
  285. $this->param['threadupdatearr']['author'] = $this->param['isanonymous'] ? '' : $this->post['author'];
  286. $anonymousadd = $this->param['isanonymous'];
  287. }
  288. if($isfirstpost) {
  289. if(trim($this->param['subject']) == '' && $this->thread['special'] != 2) {
  290. showmessage('post_sm_isnull');
  291. }
  292. if(!$this->param['sortid'] && !$this->thread['special'] && trim($this->param['message']) == '') {
  293. showmessage('post_sm_isnull');
  294. }
  295. $publishdate = null;
  296. if ($this->group['allowsetpublishdate'] && $this->thread['displayorder'] == -4) {
  297. $cron_publish_ids = dunserialize($this->cache('cronpublish'));
  298. if (!$this->param['cronpublish'] && in_array($this->thread['tid'], $cron_publish_ids) || $this->param['modnewthreads']) {
  299. $this->param['threadupdatearr']['dateline'] = $publishdate = TIMESTAMP;
  300. unset($cron_publish_ids[$this->thread['tid']]);
  301. $cron_publish_ids = serialize($cron_publish_ids);
  302. savecache('cronpublish', $cron_publish_ids);
  303. } elseif ($this->param['cronpublish'] && $this->param['cronpublishdate']) {
  304. $this->param['threadupdatearr']['dateline'] = $publishdate = strtotime($this->param['cronpublishdate']);
  305. $this->param['save'] = 1;
  306. if (!in_array($this->thread['tid'], $cron_publish_ids)) {
  307. $cron_publish_ids[$this->thread['tid']] = $this->thread['tid'];
  308. $cron_publish_ids = serialize($cron_publish_ids);
  309. savecache('cronpublish', $cron_publish_ids);
  310. }
  311. }
  312. }
  313. $this->param['readperm'] = $this->group['allowsetreadperm'] ? intval($this->param['readperm']) : ($isorigauthor ? 0 : 'ignore');
  314. if($this->thread['special'] != 3) {
  315. $this->param['price'] = intval($this->param['price']);
  316. $this->param['price'] = $this->thread['price'] < 0 && !$this->thread['special']
  317. ?($isorigauthor || !$this->param['price'] ? -1 : $this->param['price'])
  318. :($this->group['maxprice'] ? ($this->param['price'] <= $this->group['maxprice'] ? ($this->param['price'] > 0 ? $this->param['price'] : 0) : $this->group['maxprice']) : ($isorigauthor ? $this->param['price'] : $this->thread['price']));
  319. if($this->param['price'] > 0 && floor($this->param['price'] * (1 - $this->setting['creditstax'])) == 0) {
  320. return $this->showmessage('post_net_price_iszero');
  321. }
  322. }
  323. $this->thread['status'] = setstatus(4, $this->param['ordertype'], $this->thread['status']);
  324. $this->thread['status'] = setstatus(15, $this->param['imgcontent'], $this->thread['status']);
  325. if($this->param['imgcontent']) {
  326. stringtopic($this->param['message'], $this->post['tid'], true, $this->param['imgcontentwidth']);
  327. }
  328. $this->thread['status'] = setstatus(2, $this->param['hiddenreplies'], $this->thread['status']);
  329. $this->thread['status'] = setstatus(6, $this->param['allownoticeauthor'] ? 1 : 0, $this->thread['status']);
  330. $displayorder = (empty($this->param['save']) || $this->thread['displayorder'] != -4 ) ? ($this->thread['displayorder'] == -4 ? -4 : $this->thread['displayorder']) : -4;
  331. $this->param['threadupdatearr']['typeid'] = $this->param['typeid'];
  332. $this->param['threadupdatearr']['sortid'] = $this->param['sortid'];
  333. $this->param['threadupdatearr']['subject'] = $this->param['subject'];
  334. if($this->param['readperm'] !== 'ignore') {
  335. $this->param['threadupdatearr']['readperm'] = $this->param['readperm'];
  336. }
  337. $this->param['threadupdatearr']['price'] = $this->param['price'];
  338. $this->param['threadupdatearr']['status'] = $this->thread['status'];
  339. if(getglobal('forum_auditstatuson') && $this->param['audit'] == 1) {
  340. $this->param['threadupdatearr']['displayorder'] = 0;
  341. $this->param['threadupdatearr']['moderated'] = 1;
  342. } else {
  343. $this->param['threadupdatearr']['displayorder'] = $displayorder;
  344. }
  345. C::t('forum_thread')->update($this->thread['tid'], $this->param['threadupdatearr'], true);
  346. if($this->thread['tid'] > 1) {
  347. if($this->thread['closed'] > 1) {
  348. C::t('forum_thread')->update($this->thread['closed'], array('subject' => $this->param['subject']), true);
  349. } elseif(empty($this->thread['isgroup'])) {
  350. $threadclosed = C::t('forum_threadclosed')->fetch($thread['tid']);
  351. if($threadclosed['redirect']) {
  352. C::t('forum_thread')->update($threadclosed['redirect'], array('subject' => $this->param['subject']), true);
  353. }
  354. }
  355. }
  356. $class_tag = new tag();
  357. $tagstr = $class_tag->update_field($this->param['tags'], $this->thread['tid'], 'tid', $this->thread);
  358. } else {
  359. if($this->param['subject'] == '' && $this->param['message'] == '' && $this->thread['special'] != 2) {
  360. showmessage('post_sm_isnull');
  361. }
  362. }
  363. $this->param['htmlon'] = $this->group['allowhtml'] && !empty($this->param['htmlon']) ? 1 : 0;
  364. if($this->setting['editedby'] && (TIMESTAMP - $this->post['dateline']) > 60 && $this->member['adminid'] != 1) {
  365. $editor = $this->param['isanonymous'] && $isorigauthor ? lang('forum/misc', 'anonymous') : $this->member['username'];
  366. $edittime = dgmdate(TIMESTAMP);
  367. $this->param['message'] = lang('forum/misc', $this->param['htmlon'] ? 'post_edithtml' : (!$this->forum['allowbbcode'] || $this->param['bbcodeoff'] ? 'post_editnobbcode' : 'post_edit'), array('editor' => $editor, 'edittime' => $edittime)) . $this->param['message'];
  368. }
  369. $this->param['bbcodeoff'] = checkbbcodes($this->param['message'], !empty($this->param['bbcodeoff']));
  370. $this->param['smileyoff'] = checksmilies($this->param['message'], !empty($this->param['smileyoff']));
  371. $tagoff = $isfirstpost ? !empty($tagoff) : 0;
  372. if(getglobal('forum_auditstatuson') && $this->param['audit'] == 1) {
  373. C::t('forum_post')->update($this->thread['posttableid'], $this->post['pid'], array('status' => 4), false, false, null, -2, null, 0);
  374. updatepostcredits('+', $this->post['authorid'], ($isfirstpost ? 'post' : 'reply'), $this->forum['fid']);
  375. updatemodworks('MOD', 1);
  376. updatemodlog($this->thread['tid'], 'MOD');
  377. }
  378. $displayorder = $pinvisible = 0;
  379. if($isfirstpost) {
  380. $displayorder = $this->param['modnewthreads'] ? -2 : $this->thread['displayorder'];
  381. $pinvisible = $this->param['modnewthreads'] ? -2 : (empty($this->param['save']) ? 0 : -3);
  382. } else {
  383. $pinvisible = $this->param['modnewreplies'] ? -2 : ($this->thread['displayorder'] == -4 ? -3 : 0);
  384. }
  385. $this->param['message'] = preg_replace('/\[attachimg\](\d+)\[\/attachimg\]/is', '[attach]\1[/attach]', $this->param['message']);
  386. $this->param['parseurloff'] = !empty($this->param['parseurloff']);
  387. $setarr = array(
  388. 'message' => $this->param['message'],
  389. 'usesig' => $this->param['usesig'],
  390. 'htmlon' => $this->param['htmlon'],
  391. 'bbcodeoff' => $this->param['bbcodeoff'],
  392. 'parseurloff' => $this->param['parseurloff'],
  393. 'smileyoff' => $this->param['smileyoff'],
  394. 'subject' => $this->param['subject'],
  395. 'tags' => $tagstr,
  396. 'port'=>getglobal('remoteport')
  397. );
  398. $setarr['status'] = $this->post['status'];
  399. if($this->param['modstatus']) {
  400. foreach($this->param['modstatus'] as $modbit => $modvalue) {
  401. $setarr['status'] = setstatus($modbit, $modvalue, $setarr['status']);
  402. }
  403. }
  404. if($anonymousadd !== '') {
  405. $setarr['anonymous'] = $anonymousadd;
  406. }
  407. if($publishdate) {
  408. $setarr['dateline'] = $publishdate;
  409. }
  410. if(getglobal('forum_auditstatuson') && $this->param['audit'] == 1) {
  411. $setarr['invisible'] = 0;
  412. } else {
  413. $setarr['invisible'] = $pinvisible;
  414. }
  415. C::t('forum_post')->update('tid:'.$this->thread['tid'], $this->post['pid'], $setarr);
  416. $this->forum['lastpost'] = explode("\t", $this->forum['lastpost']);
  417. if($this->post['dateline'] == $this->forum['lastpost'][2] && ($this->post['author'] == $this->forum['lastpost'][3] || ($this->forum['lastpost'][3] == '' && $this->post['anonymous']))) {
  418. $lastpost = $this->thread['tid']."\t".($isfirstpost ? $this->param['subject'] : $this->thread['subject'])."\t".$this->post['dateline']."\t".($this->param['isanonymous'] ? '' : $this->post['author']);
  419. C::t('forum_forum')->update($this->forum['fid'], array('lastpost' => $lastpost));
  420. }
  421. if(!getglobal('forum_auditstatuson') || $this->param['audit'] != 1) {
  422. if($isfirstpost && $this->param['modnewthreads']) {
  423. C::t('forum_thread')->update($this->thread['tid'], array('displayorder' => -2));
  424. manage_addnotify('verifythread');
  425. } elseif(!$isfirstpost && $this->param['modnewreplies']) {
  426. C::t('forum_thread')->increase($this->thread['tid'], array('replies' => -1));
  427. manage_addnotify('verifypost');
  428. }
  429. if($this->param['modnewreplies'] || $this->param['modnewthreads']) {
  430. C::t('forum_forum')->update($this->forum['fid'], array('modworks' => '1'));
  431. }
  432. }
  433. if($this->thread['lastpost'] == $this->post['dateline'] && ((!$this->post['anonymous'] && $this->thread['lastposter'] == $this->post['author']) || ($this->post['anonymous'] && $this->thread['lastposter'] == '')) && $this->post['anonymous'] != $this->param['isanonymous']) {
  434. C::t('forum_thread')->update($this->thread['tid'], array('lastposter' => $this->param['isanonymous'] ? '' : $this->post['author']), true);
  435. }
  436. if(!$isorigauthor) {
  437. updatemodworks('EDT', 1);
  438. require_once libfile('function/misc');
  439. modlog($this->thread, 'EDT');
  440. }
  441. if($isfirstpost && $this->thread['displayorder'] == -4 && empty($this->param['save'])) {
  442. threadpubsave($this->thread['tid']);
  443. }
  444. }
  445. public function deletepost($parameters) {
  446. $this->_init_parameters($parameters);
  447. if(!$this->setting['editperdel']) {
  448. return $this->showmessage('post_edit_thread_ban_del', NULL);
  449. }
  450. $isfirstpost = $this->post['first'] ? 1 : 0;
  451. if($isfirstpost && $this->thread['replies'] > 0) {
  452. return $this->showmessage(($this->thread['special'] == 3 ? 'post_edit_reward_already_reply' : 'post_edit_thread_already_reply'), NULL);
  453. }
  454. if($this->thread['displayorder'] >= 0) {
  455. updatepostcredits('-', $this->post['authorid'], ($isfirstpost ? 'post' : 'reply'), $this->forum['fid']);
  456. }
  457. if(!$this->param['handlereplycredit']) {
  458. if(!$isfirstpost && !$this->param['isanonymous']) {
  459. $postreplycredit = C::t('forum_post')->fetch('tid:'.$this->thread['tid'], $this->post['pid']);
  460. $postreplycredit = $postreplycredit['replycredit'];
  461. if($postreplycredit) {
  462. C::t('forum_post')->update('tid:'.$this->thread['tid'], $this->post['pid'], array('replycredit' => 0));
  463. updatemembercount($this->post['authorid'], array($replycredit_rule['extcreditstype'] => '-'.$postreplycredit));
  464. }
  465. }
  466. }
  467. C::t('forum_post')->delete('tid:'.$this->thread['tid'], $this->post['pid']);
  468. $forumcounter = array();
  469. if($isfirstpost) {
  470. $forumcounter['threads'] = $forumcounter['posts'] = -1;
  471. $tablearray = array('forum_relatedthread', 'forum_debate', 'forum_debatepost', 'forum_polloption', 'forum_poll');
  472. foreach ($tablearray as $table) {
  473. C::t($table)->delete_by_tid($this->thread['tid']);
  474. }
  475. C::t('forum_thread')->delete_by_tid($this->thread['tid']);
  476. C::t('common_moderate')->delete($this->thread['tid'], 'tid');
  477. C::t('forum_threadmod')->delete_by_tid($this->thread['tid']);
  478. if($this->setting['globalstick'] && in_array($this->thread['displayorder'], array(2, 3))) {
  479. require_once libfile('function/cache');
  480. updatecache('globalstick');
  481. }
  482. } else {
  483. $forumcounter['posts'] = -1;
  484. $lastpost = C::t('forum_post')->fetch_visiblepost_by_tid('tid:'.$this->thread['tid'], $this->thread['tid'], 0, 1);
  485. $lastpost['author'] = !$lastpost['anonymous'] ? addslashes($lastpost['author']) : '';
  486. $this->param['updatefieldarr']['replies'] = -1;
  487. $this->param['updatefieldarr']['lastposter'] = array($lastpost['author']);
  488. $this->param['updatefieldarr']['lastpost'] = array($lastpost['dateline']);
  489. C::t('forum_thread')->increase($this->thread['tid'], $this->param['updatefieldarr']);
  490. }
  491. $this->forum['lastpost'] = explode("\t", $this->forum['lastpost']);
  492. if($this->post['dateline'] == $this->forum['lastpost'][2] && ($this->post['author'] == $this->forum['lastpost'][3] || ($this->forum['lastpost'][3] == '' && $this->post['anonymous']))) {
  493. $lastthread = C::t('forum_thread')->fetch_by_fid_displayorder($this->forum['fid']);
  494. C::t('forum_forum')->update($this->forum['fid'], array('lastpost' => "$lastthread[tid]\t$lastthread[subject]\t$lastthread[lastpost]\t$lastthread[lastposter]"));
  495. }
  496. C::t('forum_forum')->update_forum_counter($this->forum['fid'], $forumcounter['threads'], $forumcounter['posts']);
  497. }
  498. }
  499. ?>