function sp_post_notification($user, $message, $postid) { global $spThisUser; if (!$spThisUser->admin && !$spThisUser->moderator) { return; } $userid = spdb_table(SFMEMBERS, "display_name='{$user}'", 'user_id'); if (empty($userid)) { return; } $topic_id = spdb_table(SFPOSTS, "post_id={$postid}", 'topic_id'); $nData = array(); $nData['user_id'] = $userid; $nData['guest_email'] = ''; $nData['post_id'] = $postid; $nData['link'] = sp_permalink_from_postid($postid); $nData['link_text'] = spdb_table(SFTOPICS, "topic_id={$topic_id}", 'topic_name'); $nData['message'] = sp_filter_title_save($message); $nData['expires'] = $time; # 30 days; 24 hours; 60 mins; 60secs sp_add_notice($nData); }
function saveData() { global $spVars, $spGlobals; $this->abort = false; $this->newpost['action'] = $this->action; # make the entire class object available for modification before saving # warning: note the passing by reference. other end could wreak havoc do_action_ref_array('sph_new_post_pre_save', array(&$this)); # Write the topic if needed if ($this->action == 'topic') { $this->newpost = apply_filters('sph_new_topic_pre_data_saved', $this->newpost); $spdb = new spdbComplex(); $spdb->table = SFTOPICS; $spdb->fields = array('topic_name', 'topic_slug', 'topic_date', 'forum_id', 'topic_status', 'topic_pinned', 'user_id'); $spdb->data = array($this->newpost['topicname'], $this->newpost['topicslug'], $this->newpost['postdate'], $this->newpost['forumid'], $this->newpost['topicstatus'], $this->newpost['topicpinned'], $this->newpost['userid']); $spdb = apply_filters('sph_new_topic_data', $spdb); $this->newpost['db'] = $spdb->insert(); if ($this->newpost['db'] == true) { $this->newpost['topicid'] = $spVars['insertid']; $this->newpost = apply_filters('sph_new_topic_data_saved', $this->newpost); } else { $this->abort = true; $this->message = sp_text('Unable to save new topic record'); return; } # failsafe: check the topic slug and if empty use the topic id if (empty($this->newpost['topicslug'])) { $this->newpost['topicslug'] = 'topic-' . $this->newpost['topicid']; spdb_query('UPDATE ' . SFTOPICS . " SET topic_slug='" . $this->newpost['topicslug'] . "' WHERE topic_id=" . $this->newpost['topicid']); } } # Write the post # Double check forum id is correct - it has been known for a topic to have just been moved! $this->newpost['forumid'] = spdb_table(SFTOPICS, 'topic_id=' . $this->newpost['topicid'], 'forum_id'); # Get post count in topic to enable post index setting $index = spdb_count(SFPOSTS, 'topic_id = ' . $this->newpost['topicid']); $index++; $this->newpost['postindex'] = $index; # if topic lock set in post reply update topic (post only) if ($this->action == 'post' && $this->newpost['topicstatus']) { spdb_query('UPDATE ' . SFTOPICS . ' SET topic_status=1 WHERE topic_id=' . $this->newpost['topicid']); } $this->newpost = apply_filters('sph_new_post_pre_data_saved', $this->newpost); $spdb = new spdbComplex(); $spdb->table = SFPOSTS; $spdb->fields = array('post_content', 'post_date', 'topic_id', 'forum_id', 'user_id', 'guest_name', 'guest_email', 'post_pinned', 'post_index', 'post_status', 'poster_ip', 'source'); $spdb->data = array($this->newpost['postcontent'], $this->newpost['postdate'], $this->newpost['topicid'], $this->newpost['forumid'], $this->newpost['userid'], $this->newpost['guestname'], $this->newpost['guestemail'], $this->newpost['postpinned'], $this->newpost['postindex'], $this->newpost['poststatus'], $this->newpost['posterip'], $this->newpost['source']); $spdb = apply_filters('sph_new_post_data', $spdb); $this->newpost['db'] = $spdb->insert(); if ($this->newpost['db'] == true) { $this->newpost['postid'] = $spVars['insertid']; $this->newpost = apply_filters('sph_new_post_data_saved', $this->newpost); } else { $this->abort = true; $this->message = sp_text('Unable to save new post message'); return; } # Update the timestamp of the last post sp_update_option('poststamp', $this->newpost['postdate']); $this->returnURL = sp_build_url($this->newpost['forumslug'], $this->newpost['topicslug'], 0, $this->newpost['postid']); if ($this->newpost['poststatus']) { $this->newpost['submsg'] .= ' - ' . sp_text('placed in moderation') . ' '; } # Now for all that post-save processing required if ($this->guest) { $sfguests = sp_get_option('sfguests'); if ($sfguests['storecookie']) { sp_write_guest_cookie($this->newpost['guestname'], $this->newpost['guestemail']); } } else { $postcount = sp_get_member_item($this->newpost['userid'], 'posts'); $postcount++; sp_update_member_item($this->newpost['userid'], 'posts', $postcount); # see if postcount qualifies member for new user group membership # get rankings information if (!$this->admin) { # ignore for admins as they dont belong to user groups global $spGlobals; if (!empty($spGlobals['forum_rank'])) { $index = 0; foreach ($spGlobals['forum_rank'] as $x => $info) { $rankdata['title'][$index] = $x; $rankdata['posts'][$index] = $info['posts']; $rankdata['usergroup'][$index] = $info['usergroup']; $index++; } # sort rankings array_multisort($rankdata['posts'], SORT_ASC, $rankdata['title'], $rankdata['usergroup']); # check for new ranking for ($x = 0; $x < count($rankdata['posts']); $x++) { if ($postcount <= $rankdata['posts'][$x] && !empty($rankdata['usergroup'][$x])) { # if a user group is tied to forum rank add member to the user group if ($rankdata['usergroup'][$x] != 'none') { sp_add_membership($rankdata['usergroup'][$x], $this->newpost['userid']); } break; # only update highest rank } } } } } # set new url for email $this->newpost['url'] = $this->returnURL; # allow plugins to add to post message $this->newpost['submsg'] = apply_filters('sph_post_message', $this->newpost['submsg'], $this->newpost); # add to or remove from admins new post queue if ($this->admin || $this->moderator) { # remove topic from waiting... sp_remove_from_waiting(false, $this->newpost['topicid']); } else { # add topic to waiting sp_add_to_waiting($this->newpost['topicid'], $this->newpost['forumid'], $this->newpost['postid'], $this->newpost['userid']); } # if a new post remove topic from the users new post list if in it if ($this->action == 'post') { sp_remove_users_newposts($this->newpost['topicid'], $this->newpost['userid']); } # do we need to approve any posts in moderation in this topic? if ($this->admin && $spGlobals['admin']['sfadminapprove'] || $this->moderator && $spGlobals['admin']['sfmoderapprove']) { sp_approve_post(true, 0, $this->newpost['topicid'], false, $this->newpost['forumid']); } # if post in moderatiuon then add entry to notices if ($this->newpost['poststatus'] != 0) { $nData = array(); $nData['user_id'] = $this->newpost['userid']; $nData['guest_email'] = $this->newpost['guestemail']; $nData['post_id'] = $this->newpost['postid']; $nData['link'] = $this->newpost['url']; $nData['link_text'] = $this->newpost['topicname']; $nData['message'] = sp_text('Your post is awaiting moderation in the topic'); $nData['expires'] = time() + 30 * 24 * 60 * 60; # 30 days; 24 hours; 60 mins; 60secs sp_add_notice($nData); } # Add this new item to the new tpic/post cache $meta = sp_get_sfmeta_key('topic_cache', 'new'); $cacheSize = sp_get_option('topic_cache'); $a = array(); $a[LISTFORUM] = (int) $this->newpost['forumid']; $a[LISTTOPIC] = (int) $this->newpost['topicid']; $a[LISTPOST] = (int) $this->newpost['postid']; $a[LISTSTATUS] = (int) $this->newpost['poststatus']; if (isset($spGlobals['topic_cache']['new']) && !empty($spGlobals['topic_cache']['new'])) { array_unshift($spGlobals['topic_cache']['new'], $a); if (count($spGlobals['topic_cache']['new']) > $cacheSize) { array_pop($spGlobals['topic_cache']['new']); } } sp_update_sfmeta('topic_cache', 'new', $spGlobals['topic_cache']['new'], $meta, true); # remove group level caches to accommodate new post spdb_query('DELETE FROM ' . SFCACHE . " WHERE cache_id LIKE '%*group'"); # save post in cache for flood control sp_add_cache('floodcontrol', time() + sp_get_option('floodcontrol')); # Update forum, topic and post index data sp_build_post_index($this->newpost['topicid']); sp_build_forum_index($this->newpost['forumid']); # send out email notifications sp_email_notifications($this->newpost); # one final filter - just in case do_action_ref_array('sph_post_new_completed', array(&$this)); # and a final action hook do_action('sph_new_post', $this->newpost); do_action('sph_post_create', $this->newpost); }