function sp_remove_waiting_queue() { $rows = spdb_select('col', 'SELECT topic_id FROM ' . SFWAITING); if ($rows) { $queued = array(); foreach ($rows as $row) { $queued[] = $row; } foreach ($queued as $topic) { sp_remove_from_waiting(true, $topic); } } }
function sp_GetAdminsQueuedPosts() { global $spVars; $newposts = ''; $clause = ''; $records = spdb_select('set', 'SELECT ' . SFWAITING . '.forum_id, forum_slug, forum_name, forum_icon, topic_id, ' . SFWAITING . '.post_count, ' . SFWAITING . '.post_id FROM ' . SFWAITING . ' LEFT JOIN ' . SFFORUMS . ' ON ' . SFWAITING . '.forum_id = ' . SFFORUMS . '.forum_id ORDER BY forum_id'); if ($records) { # now grab all of the post record we are going to need in one query $pcount = count($records); $done = 0; foreach ($records as $record) { $clause .= '(' . SFTOPICS . '.topic_id = ' . $record->topic_id . ' AND ' . SFPOSTS . '.post_id >= ' . $record->post_id . ')'; $done++; if ($done < $pcount) { $clause .= ' OR '; } } $preparedpostrecords = spdb_select('set', 'SELECT ' . SFPOSTS . '.topic_id, post_content, post_index, ' . SFPOSTS . '.post_id, post_status, ' . SFPOSTS . '.user_id, ' . SFMEMBERS . '.display_name, guest_name, topic_slug, topic_name FROM ' . SFPOSTS . ' LEFT JOIN ' . SFTOPICS . ' ON ' . SFPOSTS . '.topic_id = ' . SFTOPICS . '.topic_id LEFT JOIN ' . SFMEMBERS . ' ON ' . SFPOSTS . '.user_id = ' . SFMEMBERS . ".user_id\n\t\t\t\t WHERE {$clause}\n\t\t\t\t AND (admin = 0 OR admin IS NULL) AND (moderator = 0 OR moderator IS NULL)\n\t\t\t\t ORDER BY post_id"); $spVars['queue'] = count($preparedpostrecords); $newposts = array(); $findex = -1; $pindex = 0; $tindex = 0; foreach ($records as $record) { # Check this still has posts in it and they were not removed (it happens) $postrecords = ''; foreach ($preparedpostrecords as $prepared) { if ($prepared->topic_id == $record->topic_id) { $postrecords[] = $prepared; } } # So - were they removed? if so donlt add them to the array and remove them from sfwaiting if ($postrecords == '') { sp_remove_from_waiting(true, $record->topic_id, $record->post_id); continue; } $forumid = $record->forum_id; if ($findex == -1 || $newposts[$findex]['forum_id'] != $forumid) { $findex++; $tindex = 0; $pindex = 0; $newposts[$findex]['forum_id'] = $record->forum_id; $newposts[$findex]['forum_name'] = $record->forum_name; $newposts[$findex]['forum_slug'] = $record->forum_slug; $newposts[$findex]['forum_icon'] = $record->forum_icon; } $newposts[$findex]['topics'][$tindex]['topic_id'] = $record->topic_id; $newposts[$findex]['topics'][$tindex]['post_id'] = $record->post_id; # isolate the post records for current topic $postrecords = ''; foreach ($preparedpostrecords as $prepared) { if ($prepared->topic_id == $record->topic_id) { $postrecords[] = $prepared; } } if ($postrecords) { $newposts[$findex]['topics'][$tindex]['post_count'] = count($postrecords); $pindex = 0; foreach ($postrecords as $postrecord) { $newposts[$findex]['topics'][$tindex]['topic_slug'] = $postrecord->topic_slug; $newposts[$findex]['topics'][$tindex]['topic_name'] = $postrecord->topic_name; $newposts[$findex]['topics'][$tindex]['posts'][$pindex]['post_id'] = $postrecord->post_id; $newposts[$findex]['topics'][$tindex]['posts'][$pindex]['post_status'] = $postrecord->post_status; $newposts[$findex]['topics'][$tindex]['posts'][$pindex]['post_index'] = $postrecord->post_index; $newposts[$findex]['topics'][$tindex]['posts'][$pindex]['post_content'] = $postrecord->post_content; $newposts[$findex]['topics'][$tindex]['posts'][$pindex]['user_id'] = $postrecord->user_id; if (empty($postrecord->user_id)) { $newposts[$findex]['topics'][$tindex]['posts'][$pindex]['display_name'] = $postrecord->guest_name; $thisuser = '******'; } else { $newposts[$findex]['topics'][$tindex]['posts'][$pindex]['display_name'] = $postrecord->display_name; $thisuser = '******'; } $newposts[$findex]['topics'][$tindex]['posts'][$pindex]['user_type'] = $thisuser; $pindex++; } } $tindex++; } } # if no new posts then housekeep sfwaiting if (!$newposts) { spdb_query('TRUNCATE ' . SFWAITING); } return $newposts; }
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); }
function sp_render_forum($content) { global $spIsForum, $spContentLoaded, $spVars, $spGlobals, $spThisUser, $spStatus; # make sure we are at least in the html body before outputting any content if (!sp_get_option('sfwpheadbypass') && !did_action('wp_head')) { return ''; } if ($spIsForum && !post_password_required(get_post(sp_get_option('sfpage')))) { # Limit forum display to within the wp loop? if (sp_get_option('sfinloop') && !in_the_loop()) { return $content; } # Has forum content already been loaded and are we limiting? if (!sp_get_option('sfmultiplecontent') && $spContentLoaded) { return $content; } $spContentLoaded = true; sp_set_server_timezone(); # offer a way for forum display to be short circuited but always show for admins unless an upgrade $message = sp_abort_display_forum(); $content .= $message; if (!empty($message) && (!$spThisUser->admin || $spStatus != 'ok')) { return $content; } # process query arg actions if (isset($_GET['mark'])) { sp_remove_from_waiting(true, $spVars['topicid'], 0); } # check for edit operation. Need tp check for '_x' in case using mobile as buttin is an image if (isset($_POST['editpost']) || isset($_POST['editpost_x'])) { sp_save_edited_post(); } if (isset($_POST['edittopic'])) { sp_save_edited_topic(); } if (isset($_POST['ordertopicpins'])) { sp_promote_pinned_topic(); } if (isset($_POST['makepostreassign'])) { sp_reassign_post(); } if (isset($_POST['approvepost'])) { sp_approve_post(false, sp_esc_int($_POST['approvepost']), $spVars['topicid']); } if (isset($_POST['unapprovepost'])) { sp_unapprove_post(sp_esc_int($_POST['unapprovepost'])); } if (isset($_POST['doqueue'])) { sp_remove_waiting_queue(); } if (isset($_POST['notifyuser'])) { sp_post_notification(sp_esc_str($_POST['sp_notify_user']), sp_esc_str($_POST['message']), sp_esc_int($_POST['postid'])); } # move a topic and redirect to that topic if (isset($_POST['maketopicmove'])) { if (empty($_POST['forumid'])) { sp_notify(1, sp_text('Destination forum not selected')); return; } sp_move_topic(); $forumslug = spdb_table(SFFORUMS, 'forum_id=' . sp_esc_int(sp_esc_int($_POST['forumid'])), 'forum_slug'); $topicslug = spdb_table(SFTOPICS, 'topic_id=' . sp_esc_int(sp_esc_int($_POST['currenttopicid'])), 'topic_slug'); $returnURL = sp_build_url($forumslug, $topicslug, 0); sp_redirect($returnURL); } # move a post and redirect to the post if (isset($_POST['makepostmove1']) || isset($_POST['makepostmove2']) || isset($_POST['makepostmove3'])) { sp_move_post(); if (isset($_POST['makepostmove1'])) { $returnURL = sp_permalink_from_postid(sp_esc_int($_POST['postid'])); sp_redirect($returnURL); } } # cancel a post move if (isset($_POST['cancelpostmove'])) { $meta = sp_get_sfmeta('post_move', 'post_move'); if ($meta) { $id = $meta[0]['meta_id']; sp_delete_sfmeta($id); unset($spGlobals['post_move']); } } # rebuild the forum and post indexes if (isset($_POST['rebuildforum']) || isset($_POST['rebuildtopic'])) { sp_build_post_index(sp_esc_int($_POST['topicid']), true); sp_build_forum_index(sp_esc_int($_POST['forumid']), false); } # Set display mode if topic view (for editing posts) if ($spVars['pageview'] == 'topic' && isset($_POST['postedit'])) { $spVars['displaymode'] = 'edit'; $spVars['postedit'] = $_POST['postedit']; } else { $spVars['displaymode'] = 'posts'; } # clean cache of timed our records sp_clean_cache(); #--Scratch Pad Area---Please Leave Here--------- #--End Scratch Pad Area------------------------- # let other plugins check for posted actions do_action('sph_setup_forum'); # do we use output buffering? $ob = sp_get_option('sfuseob'); if ($ob) { ob_start(); } # set up some stuff before wp page content $content .= sp_display_banner(); $content = apply_filters('sph_before_wp_page_content', $content); # run any other wp filters on page content but exclude ours if (!$ob) { remove_filter('the_content', 'sp_render_forum', 1); $content = apply_filters('the_content', $content); $content = wpautop($content); add_filter('the_content', 'sp_render_forum', 1); } # set up some stuff after wp page content $content = apply_filters('sph_after_wp_page_content', $content); $content .= '<div id="dialogcontainer" style="display:none;"></div>'; $content .= sp_js_check(); # echo any wp page content echo $content; # now add our content do_action('sph_before_template_processing'); sp_process_template(); do_action('sph_after_template_processing'); # Return if using output buffering if ($ob) { $forum = ob_get_contents(); ob_end_clean(); return $forum; } } # not returning any content since we output it already unless password needed if (post_password_required(get_post(sp_get_option('sfpage')))) { return $content; } }