PageRenderTime 63ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/simple-forum/library/sf-post.php

https://bitbucket.org/openfarmtech/weblog-content
PHP | 617 lines | 453 code | 81 blank | 83 comment | 134 complexity | c77bf47f20ad99f4608cd01bffffa457 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.0, LGPL-3.0, BSD-3-Clause, GPL-3.0, LGPL-2.1, AGPL-3.0, CC-BY-SA-3.0
  1. <?php
  2. /*
  3. Simple:Press
  4. Forum Topic/Post Saves
  5. $LastChangedDate: 2010-04-09 06:11:48 -0700 (Fri, 09 Apr 2010) $
  6. $Rev: 3881 $
  7. */
  8. if (preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF']))
  9. {
  10. die('Access Denied');
  11. }
  12. # --------------------------------------------
  13. # set up required globals
  14. global $wpdb, $current_user, $sfglobals;
  15. sf_forum_ahah_support();
  16. sf_setup_forum_hooks();
  17. sf_setup_post_save_includes();
  18. # Initialise the array -------------------------------------------------------------
  19. $newpost = array();
  20. $newpost['forumid'] = 0;
  21. $newpost['forumslug'] = '';
  22. # Validation checks on forum data ---------------------------------------------------
  23. # if the forum is not set then this may be a back door approach
  24. if((!isset($_POST['forumid'])) || (!isset($_POST['forumslug'])))
  25. {
  26. echo (__('Forum not set - Unable to create post', 'sforum'));
  27. die();
  28. } else {
  29. $newpost['forumid'] = sf_esc_int($_POST['forumid']);
  30. $newpost['forumslug'] = sf_esc_str($_POST['forumslug']);
  31. }
  32. # If forum or system locked then refuse post
  33. sf_initialise_globals($newpost['forumid']);
  34. if($current_user->moderator == false)
  35. {
  36. if($sfglobals['lockdown'] || sf_forum_locked($newpost['forumid']))
  37. {
  38. echo (__("This forum is currently locked - access is read only", 'sforum'));
  39. die();
  40. }
  41. }
  42. # clear out the message buffer
  43. delete_sfnotice();
  44. # Check the pre-save hook
  45. if(function_exists('sf_hook_pre_post_save'))
  46. {
  47. if(sf_process_hook('sf_hook_pre_post_save', array($_POST['postitem'])) == false)
  48. {
  49. update_sfnotice('sfmessage', '1@'.__('This post has been refused', "sforum"));
  50. wp_redirect(SFURL);
  51. die();
  52. }
  53. }
  54. # set up the main vars -------------------------------------------------------------
  55. $newpost['topicid'] = 0;
  56. $newpost['topicslug'] = '';
  57. $newpost['postid'] = 0;
  58. $newpost['submsg'] = '';
  59. $action='';
  60. if(isset($_POST['newtopic'])) $action = 'topic';
  61. if(isset($_POST['newpost'])) $action = 'post';
  62. # if this is an existing topic check id and slug is set
  63. if($action == 'post')
  64. {
  65. if((!isset($_POST['topicid'])) || (!isset($_POST['topicslug'])))
  66. {
  67. echo (__('Topic not set - Unable to create post', 'sforum'));
  68. die();
  69. } else {
  70. $newpost['topicid'] = sf_esc_int($_POST['topicid']);
  71. $newpost['topicslug'] = sf_esc_str($_POST['topicslug']);
  72. }
  73. }
  74. # check that current user is actually allowed to do this ---------------------------
  75. if(($action == 'topic' && !$current_user->sfaddnew) || ($action == 'post' && !$current_user->sfreply))
  76. {
  77. echo (__('Access Denied', "sforum"));
  78. die();
  79. }
  80. # set up initial url to return to if save fails ------------------------------------
  81. $returnURL = sf_build_url($newpost['forumslug'], $newpost['topicslug'], 0, $newpost['postid']);
  82. # setup and prepare post data ------------------------------------------------------
  83. if($action == 'topic')
  84. {
  85. # topic specific items
  86. if(empty($_POST['newtopicname']))
  87. {
  88. update_sfnotice('sfmessage', '1@'.__('No Topic Name has been entered! Post can not be saved', "sforum"));
  89. wp_redirect($returnURL);
  90. die();
  91. } else {
  92. $newpost['topicname'] = sf_filter_title_save(trim($_POST['newtopicname']));
  93. }
  94. $newpost['topicslug'] = sf_create_slug($newpost['topicname'], 'topic');
  95. $newpost['topicpin']=0;
  96. $newpost['topicsub']='NULL';
  97. $newpost['statusflag']='0';
  98. $newpost['bloglink']='0';
  99. $newpost['post_category']='NULL';
  100. if(isset($_POST['topiclock'])) $newpost['topiclock']=1;
  101. if(isset($_POST['topicpin'])) $newpost['topicpin']=1;
  102. if(isset($_POST['statusflag'])) $newpost['statusflag']=sf_esc_int($_POST['statusflag']);
  103. if($_POST['bloglink'] == 'on') $newpost['bloglink']=true;
  104. if(isset($_POST['post_category'])) $newpost['post_category'] = $_POST['post_category']; # array so santize later!!
  105. # get the tags for the new topic
  106. if (empty($_POST['topictags']))
  107. {
  108. $newpost['tags'] = '';
  109. } else {
  110. # check for duplicates and limit to max tag option
  111. $newpost['tags'] = sf_filter_title_save(trim($_POST['topictags']));
  112. $newpost['tags'] = trim($newpost['tags'], ','); # no extra commas allowed
  113. $newpost['taglist'] = $newpost['tags']; # save comma separated list for later use
  114. $newpost['tags'] = explode(',', $newpost['tags']);
  115. $newpost['tags'] = array_unique($newpost['tags']); # remove any duplicates
  116. $newpost['tags'] = array_values($newpost['tags']); # put back in order
  117. if ($sfglobals['display']['topics']['maxtags'] > 0 && count($newpost['tags']) > $sfglobals['display']['topics']['maxtags'])
  118. {
  119. $newpost['tags'] = array_slice($newpost['tags'], 0, $sfglobals['display']['topics']['maxtags']); # limit to maxt tags opton
  120. }
  121. }
  122. }
  123. # post specific (needed by new topic and new post)
  124. $newpost['postpin']=0;
  125. $newpost['topiclock']=0;
  126. $newpost['topicsub']='';
  127. $newpost['topicwatch']='';
  128. $newpost['topicsubend']='';
  129. $newpost['topicwatchend']='';
  130. $newpost['statvalue']='';
  131. $newpost['posttimestamp'] = "'" . current_time('mysql') . "'";
  132. if(isset($_POST['postpin'])) $newpost['postpin']=1;
  133. if(isset($_POST['topiclock'])) $newpost['topiclock']=1;
  134. if(isset($_POST['topicsub'])) $newpost['topicsub']=sf_esc_str($_POST['topicsub']);
  135. if(isset($_POST['topicwatch'])) $newpost['topicwatch']=sf_esc_str($_POST['topicwatch']);
  136. if(isset($_POST['topicsubend'])) $newpost['topicsubend']=sf_esc_str($_POST['topicsubend']);
  137. if(isset($_POST['topicwatchend'])) $newpost['topicwatchend']=sf_esc_str($_POST['topicwatchend']);
  138. if(isset($_POST['statvalue'])) $newpost['statvalue']=sf_esc_int($_POST['statvalue']);
  139. if(!empty($_POST['editTimestamp']))
  140. {
  141. $yy = sf_esc_int($_POST['tsYear']);
  142. $mm = sf_esc_int($_POST['tsMonth']);
  143. $dd = sf_esc_int($_POST['tsDay']);
  144. $hh = sf_esc_int($_POST['tsHour']);
  145. $mn = sf_esc_int($_POST['tsMinute']);
  146. $ss = sf_esc_int($_POST['tsSecond']);
  147. $dd = ($dd > 31 ) ? 31 : $dd;
  148. $hh = ($hh > 23 ) ? $hh -24 : $hh;
  149. $mn = ($mn > 59 ) ? $mn -60 : $mn;
  150. $ss = ($ss > 59 ) ? $ss -60 : $ss;
  151. $posttimestamp = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $yy, $mm, $dd, $hh, $mn, $ss );
  152. $newpost['posttimestamp'] = '"'.( $posttimestamp ).'"';
  153. }
  154. $newpost['poststatus'] = 0;
  155. if(empty($_POST['postitem']))
  156. {
  157. update_sfnotice('sfmessage', '1@'.__('No Topic Post has been entered! Post can not be saved', "sforum"));
  158. wp_redirect($returnURL);
  159. die();
  160. } else {
  161. $newpost['postcontent'] = $_POST['postitem'];
  162. $newpost['postcontent'] = sf_filter_content_save($newpost['postcontent'], 'new');
  163. }
  164. # Check if maxmium links has been exceeded
  165. $sffilters = sf_get_option('sffilters');
  166. if($sffilters['sfmaxlinks'] > 0 && !$current_user->forumadmin)
  167. {
  168. if(substr_count($newpost['postcontent'], '</a>') > $sffilters['sfmaxlinks'])
  169. {
  170. update_sfnotice('sfmessage', '1@'.__('Maximum Number of Links Exceeded', "sforum"));
  171. wp_redirect(SFURL);
  172. die();
  173. }
  174. }
  175. $newpost['guestname']='';
  176. $newpost['guestemail']='';
  177. if ($current_user->guest)
  178. {
  179. $sfguests = sf_get_option('sfguests');
  180. $newpost['guestname'] = sf_filter_name_save($_POST['guestname']);
  181. $newpost['guestemail'] = sf_filter_email_save($_POST['guestemail']);
  182. if (empty($newpost['guestname']) || ((empty($newpost['guestemail']) || !is_email($newpost['guestemail'])) && $sfguests['reqemail']))
  183. {
  184. update_sfnotice('sfmessage', '1@'.__('Guest name and valid Email address required', "sforum"));
  185. wp_redirect($returnURL);
  186. die();
  187. }
  188. # force maximum lengths
  189. $newpost['guestname'] = substr($newpost['guestname'], 0, 20);
  190. $newpost['guestemail'] = substr($newpost['guestemail'], 0, 50);
  191. $newpost['postername'] = sf_filter_name_save($newpost['guestname']);
  192. $newpost['posteremail'] = sf_filter_email_save($newpost['guestemail']);
  193. $newpost['userid']='';
  194. } else {
  195. $newpost['postername'] = sf_filter_name_save($current_user->display_name);
  196. $newpost['posteremail'] = sf_filter_email_save($current_user->user_email);
  197. $newpost['userid'] = $current_user->ID;
  198. }
  199. # grab poster IP address and store in db
  200. $newpost['ip'] = $_SERVER['REMOTE_ADDR'];
  201. # Check for duplicate post of option is set
  202. if(($current_user->member && $sffilters['sfdupemember'] == true) || ($current_user->guest && $sffilters['sfdupeguest'] == true))
  203. {
  204. # Bur not admin or moderator
  205. if($current_user->forumadmin == false && $current_user->moderator == false)
  206. {
  207. $dupecheck = $wpdb->get_row("SELECT post_id, forum_id, topic_id FROM ".SFPOSTS." WHERE post_content = '".$newpost['postcontent']."' AND poster_ip = '".$newpost['ip']."';", ARRAY_A);
  208. if($dupecheck)
  209. {
  210. update_sfnotice('sfmessage', '1@'.__('Duplicate Post Refused', "sforum"));
  211. $returnURL = sf_build_url(sf_get_forum_slug($dupecheck['forum_id']), sf_get_topic_slug($dupecheck['topic_id']), 0, $$dupecheck['post_id'], 0);
  212. wp_redirect($returnURL);
  213. die();
  214. }
  215. }
  216. }
  217. # Branch to correct routine --------------------------------------------------------
  218. if($action == 'topic')
  219. {
  220. $newpost = sf_create_topic($newpost, $action);
  221. }
  222. if($action == 'post')
  223. {
  224. $newpost = sf_create_post($newpost, $action);
  225. }
  226. # reset the url now we should have kosher values and re-direct
  227. $returnURL = sf_build_url($newpost['forumslug'], $newpost['topicslug'], 0, $newpost['postid']);
  228. wp_redirect($returnURL);
  229. die();
  230. # ==================================================================================
  231. # CREATION FUNCTIONS
  232. # ==================================================================================
  233. # Create new Topic and First Post --------------------------------------------------
  234. function sf_create_topic($newpost, $action)
  235. {
  236. global $wpdb, $current_user;
  237. # security checks
  238. check_admin_referer('forum-userform_addtopic', 'forum-userform_addtopic');
  239. $spamcheck = sf_check_spammath();
  240. if($spamcheck[0]==true)
  241. {
  242. update_sfnotice('sfmessage', $spamcheck[1]);
  243. return;
  244. }
  245. # save the new topic record to db
  246. $newpost = sf_write_topic($newpost);
  247. if(!$newpost['db'])
  248. {
  249. update_sfnotice('sfmessage', __("Unable to Save New Topic Record", "sforum"));
  250. return;
  251. } else {
  252. # lets grab the new topic id
  253. $newpost['topicid'] = $wpdb->insert_id;
  254. }
  255. # check the topic slug and if empty use the topic id
  256. if(empty($newpost['topicslug']))
  257. {
  258. $newpost['topicslug'] = 'topic-'.$newpost['topicid'];
  259. $wpdb->query("UPDATE ".SFTOPICS." SET topic_slug='".$newpost['topicslug']."' WHERE topic_id=".$newpost['topicid']);
  260. }
  261. # save the tags
  262. if ($newpost['tags'] != '')
  263. {
  264. sfc_add_tags($newpost['topicid'], $newpost['tags']);
  265. }
  266. # Now save the new post record to db
  267. $newpost = sf_write_post($newpost);
  268. if(!$newpost['db'])
  269. {
  270. update_sfnotice('sfmessage', __("Unable to Save New Post Message", "sforum"));
  271. return;
  272. } else {
  273. # lets grab the new post id
  274. $newpost['postid'] = $wpdb->insert_id;
  275. }
  276. $wpdb->flush();
  277. # Post-Save New Post Processing
  278. $newpost = sf_post_save_processing($newpost, $action);
  279. # do we need to create a blog link?
  280. if($newpost['bloglink'])
  281. {
  282. include_once(SF_PLUGIN_DIR.'/linking/sf-links-forum.php');
  283. $catlist = array();
  284. if($newpost['post_category'])
  285. {
  286. foreach ($newpost['post_category'] as $key=>$value)
  287. {
  288. $catlist[] = sf_esc_int($value);
  289. }
  290. } else {
  291. $catlist[] = get_option('default_category');
  292. }
  293. # set up post stuff
  294. $post_content = $newpost['postcontent'];
  295. $post_title = $newpost['topicname'];
  296. $post_status = 'publish';
  297. $tags_input = $newpost['taglist'];
  298. $post = compact('post_content', 'post_title', 'post_status', 'tags_input');
  299. $blog_post_id = wp_insert_post($post);
  300. # save categories
  301. wp_set_post_categories($blog_post_id, $catlist);
  302. # save postmeta
  303. $metadata = $newpost['forumid'].'@'.$newpost['topicid'];
  304. sf_blog_links_control('save', $blog_post_id, $newpost['forumid'], $newpost['topicid']);
  305. # go back and insert blog_post_id in topic record
  306. $wpdb->query("UPDATE ".SFTOPICS." SET blog_post_id = ".$blog_post_id." WHERE topic_id = ".$newpost['topicid'].";");
  307. }
  308. # udpate sitemap if set for every new topic
  309. if (sf_get_option('sfbuildsitemap') == 2)
  310. {
  311. do_action("sm_rebuild");
  312. }
  313. if($newpost['poststatus'])
  314. {
  315. $newpost['submsg'] .= ' - '.__("Placed in Moderation", "sforum").' ';
  316. }
  317. update_sfnotice('sfmessage', '0@'.__("New Topic Saved", "sforum").$newpost['submsg'].' '.$newpost['emailmsg']);
  318. return $newpost;
  319. }
  320. # Create new Post in existing Topic ------------------------------------------------
  321. function sf_create_post($newpost, $action)
  322. {
  323. global $wpdb, $current_user;
  324. check_admin_referer('forum-userform_addpost', 'forum-userform_addpost');
  325. $spamcheck = sf_check_spammath();
  326. if($spamcheck[0]==true)
  327. {
  328. update_sfnotice('sfmessage', $spamcheck[1]);
  329. return;
  330. }
  331. # Write the post
  332. $newpost = sf_write_post($newpost);
  333. if(!$newpost['db'])
  334. {
  335. update_sfnotice('sfmessage', __("Unable to Save New Post Message", "sforum"));
  336. return;
  337. }
  338. $wpdb->flush();
  339. # Post-Save New Post Processing
  340. $newpost = sf_post_save_processing($newpost, $action);
  341. # Is there a topic status flag to save?
  342. if(!empty($newpost['statvalue']))
  343. {
  344. sf_update_topic_status_flag($newpost['statvalue'], $newpost['topicid']);
  345. }
  346. if($newpost['poststatus'])
  347. {
  348. $newpost['submsg'] .= ' - '.__("Placed in Moderation", "sforum").' ';
  349. }
  350. update_sfnotice('sfmessage', '0@'.__("New Post Saved", "sforum").$newpost['submsg'].' '.$newpost['emailmsg']);
  351. return $newpost;
  352. }
  353. # ==================================================================================
  354. # DATABASE WRITE FUNCTIONS
  355. # ==================================================================================
  356. # Save new Topic to database -------------------------------------------------------
  357. function sf_write_topic($newpost)
  358. {
  359. global $wpdb;
  360. $now = "'" . current_time('mysql') . "'";
  361. $sql = "INSERT INTO ".SFTOPICS;
  362. $sql .= " (topic_name, topic_slug, topic_date, forum_id, topic_status, topic_pinned, topic_status_flag, user_id) ";
  363. $sql .= "VALUES (";
  364. $sql .= "'".$newpost['topicname']."', ";
  365. $sql .= "'".$newpost['topicslug']."', ";
  366. $sql .= $now.", ";
  367. $sql .= $newpost['forumid'].", ";
  368. $sql .= $newpost['topiclock'].", ";
  369. $sql .= $newpost['topicpin'].", ";
  370. $sql .= $newpost['statusflag'].", ";
  371. if('' == $newpost['userid'])
  372. {
  373. $sql .= "NULL);";
  374. } else {
  375. $sql .= $newpost['userid'].");";
  376. }
  377. if($wpdb->query($sql) === false)
  378. {
  379. $newpost['db'] = false;
  380. } else {
  381. $newpost['db'] = true;
  382. }
  383. return $newpost;
  384. }
  385. # Save new Post to database --------------------------------------------------------
  386. function sf_write_post($newpost)
  387. {
  388. global $wpdb, $current_user;
  389. # If a Guest posting...
  390. if((($current_user->sfmoderated) || ($current_user->sfmodonce)) && ($current_user->guest))
  391. {
  392. $newpost['poststatus'] = 1;
  393. # unless mod once is on and they have posted before...
  394. if(($current_user->sfmodonce == true) && ($current_user->sfmoderated == false))
  395. {
  396. $prior=$wpdb->get_row("SELECT post_id FROM ".SFPOSTS." WHERE guest_name='".$newpost['guestname']."' AND guest_email='".sf_filter_email_display($newpost['guestemail'])."' AND post_status=0 LIMIT 1");
  397. if($prior) $newpost['poststatus']=0;
  398. }
  399. }
  400. # If a Member posting...
  401. if((($current_user->sfmoderated) || ($current_user->sfmodonce)) && ($current_user->member))
  402. {
  403. $newpost['poststatus'] = 1;
  404. # unless mod once is on and they have posted before...
  405. if(($current_user->sfmodonce == true) && ($current_user->sfmoderated == false))
  406. {
  407. $prior=$wpdb->get_row("SELECT post_id FROM ".SFPOSTS." WHERE user_id=".$newpost['userid']." AND post_status=0 LIMIT 1");
  408. if($prior) $newpost['poststatus']=0;
  409. }
  410. }
  411. # Double check forum id is correct - it has been known for a topic to have just been moved!
  412. $newpost['forumid'] = sf_get_topics_forum_id($newpost['topicid']);
  413. # Get post count in topic to enable index setting
  414. $index=$wpdb->get_var("SELECT COUNT(post_id) FROM ".SFPOSTS." WHERE topic_id = ".$newpost['topicid']);
  415. $index++;
  416. # if topic lock set in post reply update topic
  417. if($newpost['topiclock'])
  418. {
  419. $wpdb->query("UPDATE ".SFTOPICS." SET topic_status=1 WHERE topic_id=".$newpost['topicid']);
  420. }
  421. $sql = "INSERT INTO ".SFPOSTS;
  422. $sql .= " (post_content, post_date, topic_id, forum_id, user_id, guest_name, guest_email, post_pinned, post_index, post_status, poster_ip) ";
  423. $sql .= "VALUES (";
  424. $sql .= "'".$newpost['postcontent']."', ";
  425. $sql .= $newpost['posttimestamp'].", ";
  426. $sql .= $newpost['topicid'].", ";
  427. $sql .= $newpost['forumid'].", ";
  428. if('' == $newpost['userid'])
  429. {
  430. $sql .= "NULL, ";
  431. } else {
  432. $sql .= $newpost['userid'].", ";
  433. }
  434. $sql .= "'".$newpost['guestname']."', ";
  435. $sql .= "'".$newpost['guestemail']."', ";
  436. $sql .= $newpost['postpin']. ", ";
  437. $sql .= $index.", ";
  438. $sql .= $newpost['poststatus'].", ";
  439. $sql .= "'".$newpost['ip']."');";
  440. if($wpdb->query($sql) === false)
  441. {
  442. $newpost['db'] = false;
  443. } else {
  444. $newpost['db'] = true;
  445. $newpost['postid'] = $wpdb->insert_id;
  446. if ($current_user->guest)
  447. {
  448. $sfguests = sf_get_option('sfguests');
  449. if ($sfguests['storecookie']) sf_write_guest_cookie($newpost['guestname'], $newpost['guestemail']);
  450. } else {
  451. $postcount = sf_get_member_item($newpost['userid'], 'posts');
  452. $postcount++;
  453. sf_update_member_item($newpost['userid'], 'posts', $postcount);
  454. # see if postcount qualifies member for new user group membership
  455. # get rankings information
  456. if (!$current_user->forumadmin) # ignore for admins as they dont belong to user groups
  457. {
  458. $rankdata = sf_get_sfmeta('forum_rank');
  459. if ($rankdata)
  460. {
  461. # put into arrays to make easy to sort
  462. foreach ($rankdata as $x => $info)
  463. {
  464. $ranks['title'][$x] = $info['meta_key'];
  465. $data = unserialize($info['meta_value']);
  466. $ranks['posts'][$x] = $data['posts'];
  467. $ranks['usergroup'][$x] = $data['usergroup'];
  468. }
  469. # sort rankings highest to lowest
  470. array_multisort($ranks['posts'], SORT_DESC, $ranks['title'], $ranks['usergroup']);
  471. # check for new ranking
  472. for ($x=0; $x<count($rankdata); $x++)
  473. {
  474. if ($postcount > $ranks['posts'][$x])
  475. {
  476. # if a user group is tied to forum rank add member to the user group
  477. if ($ranks['usergroup'][$x] != 'none')
  478. {
  479. sfc_add_membership($ranks['usergroup'][$x], $newpost['userid']);
  480. break; # only update highest rank
  481. }
  482. }
  483. }
  484. }
  485. }
  486. }
  487. }
  488. return $newpost;
  489. }
  490. # ==================================================================================
  491. # POST-SAVE NEW POST ROUTINES
  492. # ==================================================================================
  493. # Post-Save New Post processing ----------------------------------------------------
  494. function sf_post_save_processing($newpost, $action)
  495. {
  496. global $current_user;
  497. # construct new url
  498. $newpost['url']=sf_build_url($newpost['forumslug'], $newpost['topicslug'], 0, $newpost['postid']);
  499. $newpost['submsg'] = '';
  500. # subscribing?
  501. if ($current_user->sfsubscriptions && !empty($newpost['topicsub']))
  502. {
  503. sf_save_subscription($newpost['topicid'], $newpost['userid'], true);
  504. $newpost['submsg'] .= ' '.__('and Subscribed', 'sforum');
  505. }
  506. # unsubscribing?
  507. if ($current_user->sfsubscriptions && !empty($newpost['topicsubend']))
  508. {
  509. sf_remove_subscription($newpost['topicid'], $newpost['userid']);
  510. $newpost['submsg'] .= ' '.__('and Unsubscribing', 'sforum');
  511. }
  512. # watching?
  513. if ($current_user->sfwatch && !empty($newpost['topicwatch']))
  514. {
  515. sf_save_watch($newpost['topicid'], $newpost['userid'], true);
  516. $newpost['submsg'] .= ' '.__('and Watching', 'sforum');
  517. }
  518. # stop watching?
  519. if ($current_user->sfwatch && !empty($newpost['topicwatchend']))
  520. {
  521. sf_remove_watch($newpost['topicid'], $newpost['userid']);
  522. $newpost['submsg'] .= ' '.__('and Ending Watch', 'sforum');
  523. }
  524. # save hook
  525. sf_process_hook('sf_hook_post_save', array($newpost, $action));
  526. # add to admins new post queue
  527. sf_add_to_waiting($newpost['topicid'], $newpost['forumid'], $newpost['postid'], $newpost['userid']);
  528. # send out email notifications
  529. $newpost['emailmsg']='';
  530. $newpost['emailmsg'] = sf_email_notifications($newpost);
  531. # Update forum, topic and post index data
  532. sf_build_forum_index($newpost['forumid']);
  533. sf_build_post_index($newpost['topicid'], $newpost['topicslug']);
  534. return $newpost;
  535. }
  536. ?>