function sp_groupview_query($groupids = '', $idOrder = false) { global $spThisUser; # can we get the results from the cache? $records = array(); if (empty($spThisUser->inspect['q_spGroupView'])) { $records = sp_get_cache('group'); } if (!$records) { $WHERE = ''; if (!empty($groupids)) { $gcount = count($groupids); $done = 0; foreach ($groupids as $id) { $WHERE .= '(' . SFGROUPS . ".group_id={$id})"; $done++; if ($done < $gcount) { $WHERE .= ' OR '; } } } $this->groupViewStatus = empty($groupids) ? 'no data' : 'no access'; # retrieve group and forum records $spdb = new spdbComplex(); $spdb->table = SFGROUPS; $spdb->fields = SFGROUPS . '.group_id, group_name, group_desc, group_rss, group_icon, group_message, forum_id, forum_name, forum_slug, forum_desc, forum_status, forum_disabled, forum_icon, forum_icon_new, forum_icon_locked, forum_rss_private, post_id, post_id_held, topic_count, post_count, post_count_held, parent, children'; $spdb->join = array(SFFORUMS . ' ON ' . SFGROUPS . '.group_id = ' . SFFORUMS . '.group_id'); $spdb->where = $WHERE; $spdb->orderby = 'group_seq, forum_seq'; $spdb = apply_filters('sph_groupview_query', $spdb, $this); if (!empty($spThisUser->inspect['q_spGroupView'])) { $spdb->inspect = 'spGroupView'; $spdb->show = true; $spThisUser->inspect['q_spGroupView'] = false; } $records = $spdb->select(); if ($records) { sp_add_cache('group', $records); } } $g = ''; if ($records) { # Set status initially to 'no access' in case current user can view no forums $this->groupViewStatus = 'no access'; $gidx = 0; $fidx = 0; $sidx = 0; $cparent = 0; $subPostId = 0; # define array to collect data $p = array(); $g = array(); foreach ($records as $r) { $groupid = $r->group_id; $forumid = $r->forum_id; if (sp_can_view($forumid, 'forum-title')) { if ($gidx == 0 || $g[$gidx]->group_id != $groupid) { # reset status to 'data' $this->groupViewStatus = 'data'; $gidx = $groupid; $fidx = 0; $g[$gidx] = new stdClass(); $g[$gidx]->group_id = $r->group_id; $g[$gidx]->group_name = sp_filter_title_display($r->group_name); $g[$gidx]->group_desc = sp_filter_title_display($r->group_desc); $g[$gidx]->group_rss = esc_url($r->group_rss); $g[$gidx]->group_icon = sanitize_file_name($r->group_icon); $g[$gidx]->group_message = sp_filter_text_display($r->group_message); $g[$gidx]->group_rss_active = 0; $g[$gidx] = apply_filters('sph_groupview_group_records', $g[$gidx], $r); } if (isset($r->forum_id)) { # Is this a subform? if ($r->parent != 0) { $sidx = $r->forum_id; $g[$gidx]->forums[$cparent]->subforums[$sidx] = new stdClass(); $g[$gidx]->forums[$cparent]->subforums[$sidx]->forum_id = $r->forum_id; $g[$gidx]->forums[$cparent]->subforums[$sidx]->forum_name = sp_filter_title_display($r->forum_name); $g[$gidx]->forums[$cparent]->subforums[$sidx]->forum_slug = $r->forum_slug; $g[$gidx]->forums[$cparent]->subforums[$sidx]->forum_icon = sanitize_file_name($r->forum_icon); $g[$gidx]->forums[$cparent]->subforums[$sidx]->forum_icon_new = sanitize_file_name($r->forum_icon_new); $g[$gidx]->forums[$cparent]->subforums[$sidx]->forum_icon_locked = sanitize_file_name($r->forum_icon_locked); $g[$gidx]->forums[$cparent]->subforums[$sidx]->forum_disabled = $r->forum_disabled; $g[$gidx]->forums[$cparent]->subforums[$sidx]->forum_permalink = sp_build_url($r->forum_slug, '', 1, 0); $g[$gidx]->forums[$cparent]->subforums[$sidx]->topic_count = $r->topic_count; $g[$gidx]->forums[$cparent]->subforums[$sidx]->post_count = $r->post_count; $g[$gidx]->forums[$cparent]->subforums[$sidx]->parent = $r->parent; $g[$gidx]->forums[$cparent]->subforums[$sidx]->children = $r->children; $g[$gidx]->forums[$cparent]->subforums[$sidx]->post_id = $r->post_id; $g[$gidx]->forums[$cparent]->subforums[$sidx]->unread = 0; # check if we can look at posts in moderation - if not swap for 'held' values if (!sp_get_auth('moderate_posts', $r->forum_id)) { $g[$gidx]->forums[$cparent]->subforums[$sidx]->post_count = $r->post_count_held; $g[$gidx]->forums[$cparent]->subforums[$sidx]->post_id = $r->post_id_held; } # See if any forums are in the current users newpost list if ($spThisUser->member && isset($spThisUser->newposts['forums'])) { $c = 0; if ($spThisUser->newposts['forums']) { foreach ($spThisUser->newposts['forums'] as $fnp) { if ($fnp == $sidx) { $c++; } } } # set the subforum unread count $g[$gidx]->forums[$cparent]->subforums[$sidx]->unread = $c; } # Update top parent counts with subforum counts $g[$gidx]->forums[$cparent]->topic_count_sub += $g[$gidx]->forums[$cparent]->subforums[$sidx]->topic_count; $g[$gidx]->forums[$cparent]->post_count_sub += $g[$gidx]->forums[$cparent]->subforums[$sidx]->post_count; # and what about the most recent post? Is this in a subforum? if ($g[$gidx]->forums[$cparent]->subforums[$sidx]->post_id > $g[$gidx]->forums[$cparent]->post_id && $g[$gidx]->forums[$cparent]->subforums[$sidx]->post_id > $subPostId) { # store the alternative forum id in case we need to display the topic data for this one if inc. subs $g[$gidx]->forums[$cparent]->forum_id_sub = $r->forum_id; # add the last post in subforum to the list for stats retrieval $subPostId = $g[$gidx]->forums[$cparent]->subforums[$sidx]->post_id; $p[$r->forum_id] = $subPostId; } } else { # it's a top level forum $subPostId = 0; $fidx = $forumid; $g[$gidx]->forums[$fidx] = new stdClass(); $g[$gidx]->forums[$fidx]->forum_id = $r->forum_id; $g[$gidx]->forums[$fidx]->forum_id_sub = 0; $g[$gidx]->forums[$fidx]->forum_name = sp_filter_title_display($r->forum_name); $g[$gidx]->forums[$fidx]->forum_slug = $r->forum_slug; $g[$gidx]->forums[$fidx]->forum_permalink = sp_build_url($r->forum_slug, '', 1, 0); $g[$gidx]->forums[$fidx]->forum_desc = sp_filter_title_display($r->forum_desc); $g[$gidx]->forums[$fidx]->forum_status = $r->forum_status; $g[$gidx]->forums[$fidx]->forum_disabled = $r->forum_disabled; $g[$gidx]->forums[$fidx]->forum_icon = sanitize_file_name($r->forum_icon); $g[$gidx]->forums[$fidx]->forum_icon_new = sanitize_file_name($r->forum_icon_new); $g[$gidx]->forums[$fidx]->forum_icon_locked = sanitize_file_name($r->forum_icon_locked); $g[$gidx]->forums[$fidx]->forum_rss_private = $r->forum_rss_private; $g[$gidx]->forums[$fidx]->post_id = $r->post_id; $g[$gidx]->forums[$fidx]->topic_count = $r->topic_count; $g[$gidx]->forums[$fidx]->topic_count_sub = $r->topic_count; $g[$gidx]->forums[$fidx]->post_count = $r->post_count; $g[$gidx]->forums[$fidx]->post_count_sub = $r->post_count; $g[$gidx]->forums[$fidx]->parent = $r->parent; $g[$gidx]->forums[$fidx]->children = $r->children; $g[$gidx]->forums[$fidx]->unread = 0; if (empty($g[$gidx]->forums[$fidx]->post_id)) { $g[$gidx]->forums[$fidx]->post_id = 0; } # Can the user create new topics or should we lock the forum? $g[$gidx]->forums[$fidx]->start_topics = sp_get_auth('start_topics', $r->forum_id); # check if we can look at posts in moderation - if not swap for 'held' values if (!sp_get_auth('moderate_posts', $r->forum_id)) { $g[$gidx]->forums[$fidx]->post_id = $r->post_id_held; $g[$gidx]->forums[$fidx]->post_count = $r->post_count_held; $g[$gidx]->forums[$fidx]->post_count_sub = $r->post_count_held; $thisPostid = $r->post_id_held; } else { $thisPostid = $r->post_id; } # See if any forums are in the current users newpost list if ($spThisUser->member && isset($spThisUser->newposts['forums'])) { $c = 0; if ($spThisUser->newposts['forums']) { foreach ($spThisUser->newposts['forums'] as $fnp) { if ($fnp == $fidx) { $c++; } } } $g[$gidx]->forums[$fidx]->unread = $c; } if (empty($r->children)) { $cparent = 0; } else { $cparent = $fidx; $sidx = 0; } # Build post id array for collecting stats at the end if (!empty($thisPostid)) { $p[$fidx] = $thisPostid; } $g[$gidx]->forums[$fidx] = apply_filters('sph_groupview_forum_records', $g[$gidx]->forums[$fidx], $r); } # Build special Group level flag on whether to show group RSS button or not (based on any forum in group having RSS access if (sp_get_auth('view_forum', $r->forum_id) && !$r->forum_rss_private) { $g[$gidx]->group_rss_active = 1; } } } } } if ($this->includeStats == true) { # Go grab the forum stats and data if (!empty($p)) { $stats = $this->sp_groupview_stats_query($p); if ($stats) { foreach ($g as $gr) { foreach ($gr->forums as $f) { if (!empty($stats[$f->forum_id])) { $s = $stats[$f->forum_id]; $f->topic_id = $s->topic_id; $f->topic_name = sp_filter_title_display($s->topic_name); $f->topic_slug = $s->topic_slug; $f->post_id = $s->post_id; $f->post_permalink = sp_build_url($f->forum_slug, $s->topic_slug, 0, $s->post_id, $s->post_index); $f->post_date = $s->post_date; $f->post_status = $s->post_status; $f->post_index = $s->post_index; # see if we can display the tooltip if (sp_can_view($f->forum_id, 'post-content', $spThisUser->ID, $s->user_id, $s->topic_id, $s->post_id)) { $f->post_tip = $s->post_status ? sp_text('Post awaiting moderation') : sp_filter_tooltip_display($s->post_content, $s->post_status); } else { $f->post_tip = ''; } $f->user_id = $s->user_id; $f->display_name = sp_filter_name_display($s->display_name); $f->guest_name = sp_filter_name_display($s->guest_name); } # do we need to record a possible subforum substitute topic? $fsub = $f->forum_id_sub; if ($fsub != 0 && !empty($stats[$fsub])) { $s = $stats[$fsub]; $f->topic_id_sub = $s->topic_id; $f->topic_name_sub = sp_filter_title_display($s->topic_name); $f->topic_slug_sub = $s->topic_slug; $f->post_id_sub = $s->post_id; $f->post_permalink_sub = sp_build_url($f->subforums[$fsub]->forum_slug, $s->topic_slug, 0, $s->post_id, $s->post_index); $f->post_date_sub = $s->post_date; $f->post_status_sub = $s->post_status; $f->post_index_sub = $s->post_index; # see if we can display the tooltip if (sp_can_view($fsub, 'post-content', $spThisUser->ID, $s->user_id, $s->topic_id, $s->post_id)) { $f->post_tip_sub = $s->post_status ? sp_text('Post awaiting moderation') : sp_filter_tooltip_display($s->post_content, $s->post_status); } else { $f->post_tip_sub = ''; } $f->user_id_sub = $s->user_id; $f->display_name_sub = sp_filter_name_display($s->display_name); $f->guest_name_sub = sp_filter_name_display($s->guest_name); } $f = apply_filters('sph_groupview_stats_records', $f, $s); } } unset($stats); } } } # Do we need to re-order IDs based on passed in IDs if ($groupids && $idOrder) { $n = array(); foreach ($groupids as $gid) { if (array_key_exists($gid, $g)) { $n[$gid] = $g[$gid]; } } $g = $n; unset($n); } return $g; }
function sp_post_display_processing($pageview) { global $spThisTopic; if ($pageview == 'topic' && !empty($spThisTopic)) { $tid = sp_get_cache('topic'); if (empty($tid) || $tid != $spThisTopic->topic_id) { sp_update_opened($spThisTopic->topic_id); sp_add_cache('topic', $spThisTopic->topic_id); } } }
function sp_push_topic_page($forumid, $page) { sp_add_cache('bookmark', $forumid . '@' . $page); }
function sp_return_to_post($returnURL, $message) { # place details in the cache $failure = array(); $failure['message'] = sp_text('Unable to save') . '<br>' . $message; if (isset($_POST['newtopicname']) ? $failure['newtopicname'] = $_POST['newtopicname'] : ($failure['newtopicname'] = '')) { } if (isset($_POST['guestname']) ? $failure['guestname'] = $_POST['guestname'] : ($failure['guestname'] = '')) { } if (isset($_POST['guestemail']) ? $failure['guestemail'] = $_POST['guestemail'] : ($failure['guestemail'] = '')) { } $failure['postitem'] = $_POST['postitem']; sp_add_cache('post', $failure); wp_redirect($returnURL); }
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_searchview_control($count) { global $spVars; $searchType = $spVars['searchtype']; $searchInclude = $spVars['searchinclude']; # (LIMIT) how many topics per page? if (!$count) { $count = 30; } $this->searchShow = $count; if ($spVars['searchpage'] == 1) { $startlimit = 0; } else { $startlimit = ($spVars['searchpage'] - 1) * $count; } # For this page? $this->limit = $startlimit . ', ' . $count; # (WHERE) All or specific forum? if ($spVars['forumslug'] == 'all') { # create forumIds list and where clause $forumIds = sp_user_visible_forums('post-content'); if (empty($forumIds)) { return; } $this->forumWhere = 'forum_id IN (' . implode(',', $forumIds) . ') '; } else { # check we can see this forum and create where clause if (!sp_get_auth('view_forum', $spVars['forumid'])) { return; } $this->forumWhere = 'forum_id=' . $spVars['forumid']; } if (empty($spVars['searchvalue'])) { return ''; } if ($searchType == 4 || $searchType == 5) { $this->searchTermRaw = sp_get_member_item((int) $spVars['searchvalue'], 'display_name'); } else { $this->searchTermRaw = $spVars['searchvalue']; } $this->searchTerm = $this->sp_construct_search_term($spVars['searchvalue'], $searchType, $searchInclude); # if search type is 1,2 or 3 (i.e., normal data searches) and we are looking for page 1 then we need to run # the query. Note - if posts and titles then we need to run it twice! # If we are not loading page 1 however then we can grab the results from the cache. # For all other searchtypes - just rin the standard routine if ($searchType > 3) { $r = $this->sp_searchview_query($searchType, $searchInclude); return $r; } if ($spVars['searchpage'] == 1 && $spVars['newsearch'] == true) { $r = $this->sp_searchview_query($searchType, $searchInclude); # Remove dupes and re-sort if ($r) { $r = array_unique($r); rsort($r, SORT_NUMERIC); # Now hive off into a transient $d = array(); $d['url'] = $this->searchPermalink; $d['page'] = $spVars['searchpage']; $t = array(); $t[0] = $d; $t[1] = $r; sp_add_cache('search', $t); } } else { # Get the data from the cache if not page 1 for first time $r = sp_get_cache('search'); if ($r) { $d = $r[0]; $r = $r[1]; $d['url'] = $this->searchPermalink; $d['page'] = $spVars['searchpage']; $t = array(); $t[0] = $d; $t[1] = $r; # update the transient with the new url sp_add_cache('search', $t); } } # Now work out which part of the $r array to return if ($r) { $spVars['searchresults'] = count($r); $this->searchCount = $spVars['searchresults']; $this->searchInclude = $searchInclude; $this->searchType = $searchType; return array_slice($r, $startlimit, $count); } }