PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/source/class/model/model_forum_post.php

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