function sp_do_sp_TopicLinkTag($args = '')
{
    #check if forum displayed
    if (sp_abort_display_forum()) {
        return;
    }
    $defs = array('topicId' => '', 'linkText' => '%TOPICNAME%', 'beforeLink' => '', 'afterLink' => '', 'listTags' => 0, 'echo' => 1);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_TopicLinkTag_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $topicId = (int) $topicId;
    $linkText = esc_attr($linkText);
    $beforeLink = sp_filter_title_display($beforeLink);
    $afterLink = sp_filter_title_display($afterLink);
    $listTags = (int) $listTags;
    $echo = (int) $echo;
    if (empty($topicId)) {
        return '';
    }
    sp_forum_api_support();
    if (!empty($beforeLink)) {
        $beforeLink = trim($beforeLink) . ' ';
    }
    if (!empty($afterLink)) {
        $afterLink = ' ' . trim($afterLink);
    }
    $spdb = new spdbComplex();
    $spdb->table = SFTOPICS;
    $spdb->fields = SFTOPICS . '.topic_id, ' . SFTOPICS . '.forum_id, topic_slug, topic_name, forum_name, forum_slug';
    $spdb->join = array(SFFORUMS . ' ON ' . SFTOPICS . '.forum_id = ' . SFFORUMS . '.forum_id');
    $spdb->where = SFTOPICS . '.topic_id=' . $topicId;
    $thistopic = $spdb->select();
    $out = '';
    if ($thistopic) {
        if (sp_can_view($thistopic[0]->forum_id, 'topic-title')) {
            $out = '';
            $linkText = str_replace("%TOPICNAME%", sp_filter_title_display($thistopic[0]->topic_name), $linkText);
            if (empty($linkText)) {
                $linkText = sp_filter_title_display($thistopic[0]->topic_name);
            }
            if ($listTags) {
                $out .= '<li>';
            }
            $out .= '<span>' . $beforeLink . '<a href="' . sp_build_url($thistopic[0]->forum_slug, $thistopic[0]->topic_slug, 0, 0) . '">' . $linkText . '</a>' . $afterLink . '</span>';
            if ($listTags) {
                $out .= '</li>';
            }
        }
    } else {
        $out = sprintf(__('Topic %s not found', 'sp-ttags'), $topicId);
    }
    $out = apply_filters('sph_TopicLinkTag', $out);
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}
function sp_do_sp_ForumLinkTag($args = '')
{
    #check if forum displayed
    if (sp_abort_display_forum()) {
        return;
    }
    $defs = array('forumId' => '', 'linkText' => '%FORUMNAME%', 'beforeLink' => '', 'afterLink' => '', 'listTags' => 0, 'echo' => 1);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_ForumLinkTag_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $forumId = (int) $forumId;
    $linkText = esc_attr($linkText);
    $beforeLink = sp_filter_title_display($beforeLink);
    $afterLink = sp_filter_title_display($afterLink);
    $listTags = (int) $listTags;
    $echo = (int) $echo;
    if (empty($forumId)) {
        return '';
    }
    sp_forum_api_support();
    if (!empty($beforeLink)) {
        $beforeLink = trim($beforeLink) . ' ';
    }
    if (!empty($afterLink)) {
        $afterLink = ' ' . trim($afterLink);
    }
    if (sp_can_view($forumId, 'forum-title')) {
        $forumrec = spdb_table(SFFORUMS, "forum_id={$forumId}", 'row');
        if ($forumrec) {
            $out = '';
            $linkText = str_replace("%FORUMNAME%", sp_filter_title_display($forumrec->forum_name), $linkText);
            if (empty($linkText)) {
                $linkText = sp_filter_title_display($forumrec->forum_name);
            }
            if ($listTags) {
                $out .= '<li>';
            }
            $out .= '<span>' . $beforeLink . '<a href="' . sp_build_url($forumrec->forum_slug, '', 0, 0) . '">' . $linkText . '</a>' . $afterLink . '</span>';
            if ($listTags) {
                $out .= '</li>';
            }
        } else {
            $out = sprintf(__('Forum %s not found', 'sp-ttags'), $forumId);
        }
    }
    $out = apply_filters('sph_ForumLinkTag', $out);
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}
function sp_featured_do_post_tool($out, $forum, $topic, $post, $page, $postnum)
{
    global $spThisUser, $spGlobals;
    if ($spThisUser->admin || $spThisUser->moderator) {
        $out .= '<div class="spTopicToolsFeatured">';
        $out .= '<img class="spIcon" src="' . sp_find_icon(SPFEATUREDIMAGES, 'sp_ToolsFeaturedAdd.png') . '" alt="" title="" />';
        $featured = in_array($post['post_id'], $spGlobals['featured']['posts']);
        $featuretext = $featured ? __('Unfeature this post', 'sp-featured') : __('Feature this post', 'sp-featured');
        $featureaction = $featured ? 'remove' : 'add';
        $out .= '<a href="javascript:document.featurepost' . $post['post_id'] . '.submit();">' . $featuretext . '</a>';
        $out .= '<form action="' . sp_build_url($forum['forum_slug'], $topic['topic_slug'], $page, 0) . '" method="post" name="featurepost' . $post['post_id'] . '">';
        $out .= '<input type="hidden" name="featurepost" value="' . $post['post_id'] . '" />';
        $out .= "<input type='hidden' name='featurepostaction' value='{$featureaction}' />";
        $out .= '</form>';
        $out .= '</div>';
    }
    return $out;
}
function sp_do_sp_AddNewTopicLinkTag($args = '')
{
    #check if forum displayed
    if (sp_abort_display_forum()) {
        return;
    }
    $defs = array('tagId' => 'spAddNewTopicLinkTag', 'tagClass' => 'spLinkTag', 'forumId' => '', 'linkText' => '%FORUMNAME%', 'beforeLink' => __('Add new topic in the ', 'sp-ttags'), 'afterLink' => __(' forum', 'sp-ttags'), 'echo' => 1);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_AddNewTopicLinkTag_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $tagId = esc_attr($tagId);
    $tagClass = esc_attr($tagClass);
    $forumId = (int) $forumId;
    $linkText = esc_attr($linkText);
    $beforeLink = sp_filter_title_display($beforeLink);
    $afterLink = sp_filter_title_display($afterLink);
    $echo = (int) $echo;
    if (!$forumId) {
        return;
    }
    if (!empty($beforeLink)) {
        $beforeLink = trim($beforeLink) . ' ';
    }
    if (!empty($afterLink)) {
        $afterLink = ' ' . trim($afterLink);
    }
    sp_forum_api_support();
    if (sp_get_auth('start_topics', $forumId)) {
        $forum = spdb_table(SFFORUMS, "forum_id={$forumId}", 'row');
        $linkText = str_replace("%FORUMNAME%", sp_filter_title_display($forum->forum_name), $linkText);
        $url = sp_build_url($forum->forum_slug, '', 0, 0);
        $url = sp_get_sfqurl($url) . 'new=topic';
        $out = "<span id='{$tagId}' class='{$tagClass}'>";
        $out .= $beforeLink . '<a href="' . $url . '">' . $linkText . '</a>' . $afterLink;
        $out .= '</span>';
        $out = apply_filters('sph_AddNewTopicLinkTag', $out);
        if ($echo) {
            echo $out;
        } else {
            return $out;
        }
    }
}
function sp_render_edit_post_form($args, $postid, $postcontent)
{
    global $spVars, $spThisUser, $spThisTopic, $spGlobals;
    $defs = array('tagClass' => 'spForm', 'hide' => 1, 'controlFieldset' => 'spEditorFieldset', 'controlInput' => 'spControl', 'controlSubmit' => 'spSubmit', 'controlOrder' => 'cancel|save', 'labelHeading' => sp_text('Edit Post'), 'labelSmileys' => sp_text('Smileys'), 'labelOptions' => sp_text('Options'), 'labelOptionTime' => sp_text('Edit post timestamp'), 'labelPostButton' => sp_text('Save Edited Post'), 'labelPostCancel' => sp_text('Cancel'), 'tipSmileysButton' => sp_text('Open/Close to Add a Smiley'), 'tipOptionsButton' => sp_text('Open/Close to select Posting Options'), 'tipSubmitButton' => sp_text('Save the Edited Post'), 'tipCancelButton' => sp_text('Cancel the Post Edits'));
    $a = wp_parse_args($args, $defs);
    extract($a, EXTR_SKIP);
    # sanitize
    $tagClass = esc_attr($tagClass);
    $hide = (int) $hide;
    $controlFieldset = esc_attr($controlFieldset);
    $labelHeading = sp_filter_title_display($labelHeading);
    include_once SF_PLUGIN_DIR . '/forum/content/forms/sp-form-components.php';
    $toolbar = $spGlobals['display']['editor']['toolbar'];
    $captchaValue = sp_get_option('captcha-value');
    $out = '';
    $out .= "<div id='spPostForm'>\n";
    $out .= "<form class='{$tagClass}' action='" . sp_build_url($spThisTopic->forum_slug, $spThisTopic->topic_slug, $spThisTopic->display_page, $postid) . "' method='post' name='editpostform' onsubmit='return spjSetProcessFlag(this);'>\n";
    $out .= "<input type='hidden' name='forumid' value='{$spThisTopic->forum_id}' />\n";
    $out .= "<input type='hidden' name='forumslug' value='{$spThisTopic->forum_slug}' />\n";
    $out .= "<input type='hidden' name='topicid' value='{$spThisTopic->topic_id}' />\n";
    $out .= "<input type='hidden' name='topicslug' value='{$spThisTopic->topic_slug}' />\n";
    $out .= "<input type='hidden' name='pid' value='{$postid}' />\n";
    $out .= "<input type='hidden' name='captcha' value='{$captchaValue}' />\n";
    $out .= "<div class='spEditor'>\n";
    $out = apply_filters('sph_post_edit_top', $out, $postid, $a);
    $out .= "<fieldset class='{$controlFieldset}'>\n";
    $out .= "<legend>{$labelHeading}</legend>\n";
    # Display the selected editor
    $tout = '';
    $tout .= '<div id="spEditorContent">' . "\n";
    $tout .= sp_setup_editor(1, str_replace('&', '&amp;', $postcontent));
    $tout .= '</div>' . "\n";
    $out .= apply_filters('sph_post_editor_content', $tout, $spThisTopic, $postid, $a);
    # allow plugins to insert stuff before editor footer
    $out = apply_filters('sph_post_before_editor_footer', $out, $spThisTopic, $postid, $a);
    # define area above toolbar for plugins to add components
    $section = apply_filters('sph_post_editor_edit_above_toolbar', '', $spThisTopic, $a);
    if (!empty($section)) {
        $tout = '';
        $tout .= '<div class="spEditorSection">';
        $tout .= $section;
        $tout .= '</div>' . "\n";
        $out .= apply_filters('sph_post_editor_edit_above_toolbar_end', $tout, $spThisTopic, $a);
    }
    # DEFINE NEW FAILURE AREA HERE
    # define validation failure notice area
    $out .= "<div class='spClear'></div>\n";
    $out .= "<div id='spPostNotifications'></div>\n";
    # TOOLBAR
    # define toolbar - submit buttons on right, plugin extensions on left
    $toolbarRight = apply_filters('sph_post_editor_edit_toolbar_submit', '', $spThisTopic, $a, 'toolbar');
    $toolbarLeft = apply_filters('sph_post_editor_toolbar_buttons', '', $spThisTopic, $a, 'toolbar');
    if (!empty($toolbarRight) || !empty($toolbarLeft)) {
        # Submit section
        $tout = '';
        $tout .= '<div class="spEditorSection spEditorToolbar">';
        $tout .= $toolbarRight;
        # toolbar for plugins to add buttons
        $tout .= $toolbarLeft;
        $out .= apply_filters('sph_post_editor_toolbar', $tout, $spThisTopic, $a, 'toolbar');
        $out .= '<div style="clear:both"></div>';
        $out .= '</div>' . "\n";
    }
    # let plugins add stuff at top of editor footer
    $tout = '';
    $tout = apply_filters('sph_post_edit_footer_top', $tout, $spThisTopic, $postid, $a);
    # smileys and options
    $tout = apply_filters('sp_post_editor_inline_footer', $tout, $spThisTopic, $a, 'inline');
    # let plugins add stuff at top of editor footer
    $tout = apply_filters('sph_post_edit_footer_bottom', $tout, $postid, $a);
    # plugins can remove or adjust whole footer
    $out .= apply_filters('sph_post_editor_footer', $tout, $spThisTopic, $a);
    # allow plugins to insert stuff after editor footer
    $out = apply_filters('sph_post_after_editor_footer', $out, $spThisTopic, $a);
    # START SUBMIT SECTION
    # define submit section of no toolbar in use
    if (!$toolbar) {
        $out .= '<div class="spEditorSubmit">' . "\n";
        $out = apply_filters('sph_post_edit_submit_top', $out, $spThisTopic, $a);
        # let plugins add/remove the controls area
        $tout = apply_filters('sp_post_editor_edit_inline_submit', '', $spThisTopic, $a, 'inline');
        # let plugins add stuff at end of editor submit bottom
        $out .= apply_filters('sph_post_edit_submit_bottom', $tout, $spThisTopic, $a);
        $out .= '</div>' . "\n";
    }
    $out .= '</fieldset>' . "\n";
    $out = apply_filters('sph_post_edit_bottom', $out, $postid, $a);
    $out .= '</div>' . "\n";
    $out .= '</form>' . "\n";
    $out .= '</div>' . "\n";
    # let plugins add stuff beneath the editor
    $out = apply_filters('sph_post_editor_beneath', $out, $spThisTopic, $a);
    return $out;
}
function sp_ForumIndexAddIcon($args = '', $toolTip = '')
{
    global $spThisForum, $spGlobals, $spThisUser;
    $defs = array('tagId' => 'spForumIndexAddIcon%ID%', 'tagClass' => 'spIcon', 'icon' => 'sp_ForumStatusAdd.png', 'echo' => 1, 'get' => 0);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_ForumIndexAddIcon_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $tagId = esc_attr($tagId);
    $tagClass = esc_attr($tagClass);
    $icon = sanitize_file_name($icon);
    $echo = (int) $echo;
    $tagId = str_ireplace('%ID%', $spThisForum->forum_id, $tagId);
    $out = '';
    # add new topic icon
    if (sp_get_auth('start_topics', $spThisForum->forum_id) && (!$spThisForum->forum_status && !$spGlobals['lockdown'] || $spThisUser->admin)) {
        $url = sp_build_url($spThisForum->forum_slug, '', 1, 0) . sp_add_get() . 'new=topic';
        $out .= "<a id='{$tagId}' class='{$tagClass} vtip' title='{$toolTip}' href='{$url}'>\n";
        if (!empty($icon)) {
            $out .= "<img src='" . sp_find_icon(SPTHEMEICONSURL, "{$icon}") . "' alt='' />\n";
        }
        $out .= "</a>\n";
        $out = apply_filters('sph_ForumIndexAddIcon', $out, $a);
    }
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}
    function sp_topicview_query($topicid = 0, $cPage = 1, $forumid = 0)
    {
        global $spGlobals, $spThisUser, $spVars;
        # do we have a valid topic id
        if ($topicid == 0) {
            $this->topicViewStatus = 'no data';
            return;
        } else {
            $WHERE = SFTOPICS . '.topic_id=' . $topicid;
        }
        # default to no access
        $this->topicViewStatus = 'no access';
        # some setup vars
        $startlimit = 0;
        $lastpage = 0;
        # how many posts per page?
        $ppaged = $spGlobals['display']['posts']['perpage'];
        if (!$ppaged) {
            $ppaged = 10;
        }
        # setup where we are in the post list (paging)
        if ($cPage != 1) {
            $startlimit = ($cPage - 1) * $ppaged;
        }
        $LIMIT = $startlimit . ', ' . $ppaged;
        # Set up order by
        $setSort = false;
        $reverse = false;
        $setSort = $spGlobals['display']['posts']['sortdesc'];
        if (isset($spGlobals['sort_order']['topic'])) {
            $reverse = array_search($topicid, (array) $spGlobals['sort_order']['topic']) !== false ? true : false;
        }
        if (isset($spThisUser->postDESC) && $spThisUser->postDESC) {
            $reverse = !$reverse;
        }
        if ($setSort xor $reverse) {
            $ORDER = 'post_pinned DESC, ' . SFPOSTS . ".post_id DESC";
        } else {
            $ORDER = 'post_pinned DESC, ' . SFPOSTS . ".post_id ASC";
        }
        # add newpost/sfwaiting support for admins
        $waitCheck = ', NULL AS new_post';
        if ($spThisUser->admin || $spThisUser->moderator) {
            $waitCheck = ', ' . SFWAITING . '.post_count AS new_post';
        }
        # Discover if this topic is in users new post list
        $maybeNewPost = false;
        if ($spThisUser->member && sp_is_in_users_newposts($topicid)) {
            $maybeNewPost = true;
        }
        # retrieve topic and post records
        $spdb = new spdbComplex();
        $spdb->table = SFTOPICS;
        $spdb->found_rows = true;
        $spdb->fields = 'group_id, ' . SFTOPICS . '.topic_id, ' . SFTOPICS . '.forum_id, topic_name, topic_slug, topic_status, topic_pinned, topic_icon, topic_opened, ' . SFTOPICS . '.post_count, forum_name, forum_slug, forum_status,
							  forum_disabled, forum_rss_private, ' . SFPOSTS . '.post_id, ' . spdb_zone_datetime('post_date') . ', ' . SFPOSTS . '.user_id, ' . SFTOPICS . '.user_id AS topic_starter,
							  guest_name, guest_email, post_status, post_pinned, post_index, post_edit, poster_ip, source, post_content' . $waitCheck;
        $spdb->join = array(SFPOSTS . ' ON ' . SFTOPICS . '.topic_id=' . SFPOSTS . '.topic_id', SFFORUMS . ' ON ' . SFTOPICS . '.forum_id=' . SFFORUMS . '.forum_id');
        if ($spThisUser->admin || $spThisUser->moderator) {
            $spdb->left_join = array(SFWAITING . ' ON ' . SFPOSTS . '.post_id=' . SFWAITING . '.post_id');
        }
        $spdb->where = $WHERE;
        $spdb->orderby = $ORDER;
        $spdb->limits = $LIMIT;
        $spdb = apply_filters('sph_topicview_query', $spdb, $this);
        if (!empty($spThisUser->inspect['q_spTopicView'])) {
            $spdb->inspect = 'spTopicView';
            $spdb->show = true;
        }
        $records = $spdb->select();
        $t = array();
        if ($records) {
            $tidx = $topicid;
            $pidx = 0;
            $r = current($records);
            if (sp_get_auth('view_forum', $r->forum_id)) {
                $this->topicViewStatus = 'data';
                # construct the parent topic object
                $t[$tidx] = new stdClass();
                $t[$tidx]->topic_id = $r->topic_id;
                $t[$tidx]->forum_id = $r->forum_id;
                $t[$tidx]->group_id = $r->group_id;
                $t[$tidx]->forum_name = sp_filter_title_display($r->forum_name);
                $t[$tidx]->topic_name = sp_filter_title_display($r->topic_name);
                $t[$tidx]->topic_slug = $r->topic_slug;
                $t[$tidx]->topic_opened = $r->topic_opened;
                $t[$tidx]->forum_status = $r->forum_status;
                $t[$tidx]->topic_pinned = $r->topic_pinned;
                $t[$tidx]->forum_disabled = $r->forum_disabled;
                $t[$tidx]->forum_slug = $r->forum_slug;
                $t[$tidx]->forum_rss_private = $r->forum_rss_private;
                $t[$tidx]->topic_permalink = sp_build_url($r->forum_slug, $r->topic_slug, 1, 0);
                $t[$tidx]->topic_status = $r->topic_status;
                $t[$tidx]->topic_icon = sanitize_file_name($r->topic_icon);
                $t[$tidx]->rss = '';
                $t[$tidx]->editmode = 0;
                $t[$tidx]->tools_flag = 1;
                $t[$tidx]->display_page = $this->topicPage;
                $t[$tidx]->posts_per_page = $ppaged;
                $t[$tidx]->unread = 0;
                # user calc_rows and nor post_count as - for example - some posts may be hiodden by choice.
                $t[$tidx]->post_count = spdb_select('var', 'SELECT FOUND_ROWS()');
                # Can the user create new topics or should we lock the forum?
                $t[$tidx]->start_topics = sp_get_auth('start_topics', $r->forum_id);
                $t[$tidx]->reply_topics = sp_get_auth('reply_topics', $r->forum_id);
                $t[$tidx]->reply_own_topics = sp_get_auth('reply_own_topics', $r->forum_id);
                # grab topic start info
                $t[$tidx]->topic_starter = $r->topic_starter;
                $totalPages = $r->post_count / $ppaged;
                if (!is_int($totalPages)) {
                    $totalPages = intval($totalPages) + 1;
                }
                $t[$tidx]->total_pages = $totalPages;
                if ($setSort xor $reverse) {
                    if ($cPage == 1) {
                        $lastpage = true;
                    }
                } else {
                    if ($cPage == $totalPages) {
                        $lastpage = true;
                    }
                }
                $t[$tidx]->last_page = $lastpage;
                $t[$tidx] = apply_filters('sph_topicview_topic_record', $t[$tidx], $r);
                reset($records);
                unset($r);
                # now loop through the post records
                $newPostFlag = false;
                $firstPostPage = 1;
                $pinned = 0;
                # define post id and post user id arrays for plugins to use in combined filter
                $p = array();
                $u = array();
                foreach ($records as $r) {
                    $pidx = $r->post_id;
                    $p[] = $pidx;
                    # prepare for user object
                    $cUser = $spThisUser->ID == $r->user_id;
                    $cSmall = !$cUser;
                    $t[$tidx]->posts[$pidx] = new stdClass();
                    $t[$tidx]->posts[$pidx]->post_id = $r->post_id;
                    $t[$tidx]->posts[$pidx]->post_date = $r->post_date;
                    $t[$tidx]->posts[$pidx]->user_id = $r->user_id;
                    $t[$tidx]->posts[$pidx]->guest_name = sp_filter_name_display($r->guest_name);
                    $t[$tidx]->posts[$pidx]->guest_email = sp_filter_email_display($r->guest_email);
                    $t[$tidx]->posts[$pidx]->post_status = $r->post_status;
                    $t[$tidx]->posts[$pidx]->post_pinned = $r->post_pinned;
                    $t[$tidx]->posts[$pidx]->post_index = $r->post_index;
                    $t[$tidx]->posts[$pidx]->poster_ip = $r->poster_ip;
                    $t[$tidx]->posts[$pidx]->source = $r->source;
                    $t[$tidx]->posts[$pidx]->post_permalink = sp_build_url($r->forum_slug, $r->topic_slug, $cPage, $r->post_id);
                    $t[$tidx]->posts[$pidx]->edits = '';
                    $t[$tidx]->posts[$pidx]->last_post = 0;
                    $t[$tidx]->posts[$pidx]->last_post_on_page = 0;
                    $t[$tidx]->posts[$pidx]->first_post_on_page = $firstPostPage;
                    $t[$tidx]->posts[$pidx]->editmode = 0;
                    $t[$tidx]->posts[$pidx]->post_content = sp_filter_content_display($r->post_content);
                    $t[$tidx]->posts[$pidx]->first_pinned = 0;
                    $t[$tidx]->posts[$pidx]->last_pinned = 0;
                    $t[$tidx]->posts[$pidx]->postUser = new stdClass();
                    $t[$tidx]->posts[$pidx]->postUser = clone sp_get_user($r->user_id, $cUser, $cSmall);
                    # populate the user guest name and email in case the poster is a guest
                    if ($r->user_id == 0) {
                        $t[$tidx]->posts[$pidx]->postUser->guest_name = $t[$tidx]->posts[$pidx]->guest_name;
                        $t[$tidx]->posts[$pidx]->postUser->guest_email = $t[$tidx]->posts[$pidx]->guest_email;
                        $t[$tidx]->posts[$pidx]->postUser->display_name = $t[$tidx]->posts[$pidx]->guest_name;
                        $t[$tidx]->posts[$pidx]->postUser->ip = $t[$tidx]->posts[$pidx]->poster_ip;
                    }
                    # pinned status
                    if ($firstPostPage == 1 && $r->post_pinned) {
                        $t[$tidx]->posts[$pidx]->first_pinned = true;
                        $pinned = $pidx;
                    }
                    if ($firstPostPage == 0 && $pinned > 0 && $r->post_pinned == false) {
                        $t[$tidx]->posts[$pinned]->last_pinned = true;
                    } elseif ($r->post_pinned) {
                        $pinned = $pidx;
                    }
                    $firstPostPage = 0;
                    # Is this a new post for the current user?
                    if ($spThisUser->guest) {
                        $newPostFlag = false;
                    } else {
                        if ($maybeNewPost && strtotime($r->post_date) > strtotime($spThisUser->lastvisit)) {
                            $newPostFlag = true;
                        }
                        if (isset($r->new_post)) {
                            $newPostFlag = true;
                        }
                    }
                    $t[$tidx]->posts[$pidx]->new_post = $newPostFlag;
                    # do we need to hide an admin post?
                    if (!sp_get_auth('view_admin_posts', $r->forum_id) && sp_is_forum_admin($r->user_id)) {
                        $adminview = sp_get_sfmeta('adminview', 'message');
                        if ($adminview) {
                            $t[$tidx]->posts[$pidx]->post_content = '<div class="spMessage">';
                            $t[$tidx]->posts[$pidx]->post_content .= sp_filter_text_display($adminview[0]['meta_value']);
                            $t[$tidx]->posts[$pidx]->post_content .= '</div>';
                        } else {
                            $t[$tidx]->posts[$pidx]->post_content = '';
                        }
                    }
                    # do we need to hide an others posts?
                    if (sp_get_auth('view_own_admin_posts', $r->forum_id) && !sp_is_forum_admin($r->user_id) && !sp_is_forum_mod($r->user_id) && $spThisUser->ID != $r->user_id) {
                        $userview = sp_get_sfmeta('userview', 'message');
                        if ($userview) {
                            $t[$tidx]->posts[$pidx]->post_content = '<div class="spMessage">';
                            $t[$tidx]->posts[$pidx]->post_content .= sp_filter_text_display($userview[0]['meta_value']);
                            $t[$tidx]->posts[$pidx]->post_content .= '</div>';
                        } else {
                            $t[$tidx]->posts[$pidx]->post_content = '';
                        }
                    }
                    # Is this post to be edited?
                    if ($spVars['displaymode'] == 'edit' && $spVars['postedit'] == $r->post_id) {
                        $t[$tidx]->editmode = 1;
                        $t[$tidx]->editpost_id = $r->post_id;
                        $t[$tidx]->editpost_content = sp_filter_content_edit($r->post_content);
                        $t[$tidx]->posts[$pidx]->editmode = 1;
                    }
                    # Add edit history
                    if (!empty($r->post_edit) && is_serialized($r->post_edit)) {
                        $edits = unserialize($r->post_edit);
                        $eidx = 0;
                        foreach ($edits as $e) {
                            $t[$tidx]->posts[$pidx]->edits[$eidx] = new stdClass();
                            $t[$tidx]->posts[$pidx]->edits[$eidx]->by = $e['by'];
                            $t[$tidx]->posts[$pidx]->edits[$eidx]->at = $e['at'];
                            $eidx++;
                        }
                    }
                    if (!in_array($r->user_id, $u)) {
                        $u[] = $r->user_id;
                    }
                    $t[$tidx]->posts[$pidx] = apply_filters('sph_topicview_post_records', $t[$tidx]->posts[$pidx], $r);
                }
                # index of post IDs with position in listing
                $t[$tidx]->post_keys = $p;
                $t[$tidx]->posts[$pidx]->last_post = $lastpage;
                $t[$tidx]->posts[$pidx]->last_post_on_page = 1;
                # save last post on page id
                $t[$tidx]->last_post_id = $r->post_id;
                # allow plugins to add more data to combined topic/post data structure
                $t[$tidx] = apply_filters('sph_topicview_combined_data', $t[$tidx], $p, $u);
                unset($records);
            } else {
                # check for view forum lists but not topic lists
                if (sp_can_view($r->forum_id, 'forum-title')) {
                    $this->topicViewStatus = 'sneak peek';
                }
            }
        }
        return $t;
    }
 function sp_forumview_build_subforums($forumid, $f, $fidx, $subs)
 {
     global $spThisUser;
     ksort($subs);
     foreach ($subs as $sub) {
         if (sp_can_view($sub->forum_id, 'topic-title')) {
             $f[$fidx]->subforums[$sub->forum_id] = new stdClass();
             $f[$fidx]->subforums[$sub->forum_id]->top_parent = $fidx;
             $f[$fidx]->subforums[$sub->forum_id]->top_sub_parent = $sub->topSubParent;
             $f[$fidx]->subforums[$sub->forum_id]->forum_id = $sub->forum_id;
             $f[$fidx]->subforums[$sub->forum_id]->forum_id_sub = 0;
             $f[$fidx]->subforums[$sub->forum_id]->forum_name = sp_filter_title_display($sub->forum_name);
             $f[$fidx]->subforums[$sub->forum_id]->forum_permalink = sp_build_url($sub->forum_slug, '', 1, 0);
             $f[$fidx]->subforums[$sub->forum_id]->forum_slug = $sub->forum_slug;
             $f[$fidx]->subforums[$sub->forum_id]->forum_desc = sp_filter_title_display($sub->forum_desc);
             $f[$fidx]->subforums[$sub->forum_id]->forum_status = $sub->forum_status;
             $f[$fidx]->subforums[$sub->forum_id]->forum_disabled = $sub->forum_disabled;
             $f[$fidx]->subforums[$sub->forum_id]->forum_icon = sanitize_file_name($sub->forum_icon);
             $f[$fidx]->subforums[$sub->forum_id]->forum_icon_new = sanitize_file_name($sub->forum_icon_new);
             $f[$fidx]->subforums[$sub->forum_id]->topic_icon = sanitize_file_name($sub->topic_icon);
             $f[$fidx]->subforums[$sub->forum_id]->topic_icon_new = sanitize_file_name($sub->topic_icon_new);
             $f[$fidx]->subforums[$sub->forum_id]->topic_icon_locked = sanitize_file_name($sub->topic_icon_locked);
             $f[$fidx]->subforums[$sub->forum_id]->topic_icon_pinned = sanitize_file_name($sub->topic_icon_pinned);
             $f[$fidx]->subforums[$sub->forum_id]->forum_rss_private = $sub->forum_rss_private;
             $f[$fidx]->subforums[$sub->forum_id]->post_id = $sub->post_id;
             $f[$fidx]->subforums[$sub->forum_id]->post_id_held = $sub->post_id_held;
             $f[$fidx]->subforums[$sub->forum_id]->topic_count = $sub->topic_count;
             $f[$fidx]->subforums[$sub->forum_id]->topic_count_sub = $sub->topic_count;
             $f[$fidx]->subforums[$sub->forum_id]->post_count = $sub->post_count;
             $f[$fidx]->subforums[$sub->forum_id]->post_count_sub = $sub->post_count;
             $f[$fidx]->subforums[$sub->forum_id]->post_count_held = $sub->post_count_held;
             $f[$fidx]->subforums[$sub->forum_id]->parent = $sub->parent;
             $f[$fidx]->subforums[$sub->forum_id]->children = $sub->children;
             $f[$fidx]->subforums[$sub->forum_id]->unread = 0;
             # Can the user create new topics or should we lock the forum?
             $f[$fidx]->subforums[$sub->forum_id]->start_topics = sp_get_auth('start_topics', $sub->forum_id);
             # See if any forums are in the current users newpost list
             if ($spThisUser->member) {
                 $c = 0;
                 if ($spThisUser->newposts && $spThisUser->newposts['forums']) {
                     foreach ($spThisUser->newposts['forums'] as $fnp) {
                         if ($fnp == $sub->forum_id) {
                             $c++;
                         }
                     }
                 }
                 $f[$fidx]->subforums[$sub->forum_id]->unread = $c;
             }
             # check if we can look at posts in moderation - if not swap for 'held' values
             if (!sp_get_auth('moderate_posts', $sub->forum_id)) {
                 $f[$fidx]->subforums[$sub->forum_id]->post_id = $sub->post_id_held;
                 $f[$fidx]->subforums[$sub->forum_id]->post_count = $sub->post_count_held;
                 $f[$fidx]->subforums[$sub->forum_id]->post_count_sub = $sub->post_count_held;
                 $thisPostid = $sub->post_id_held;
             } else {
                 $thisPostid = $sub->post_id;
             }
             # Build post id array for collecting stats at the end
             if (!empty($thisPostid)) {
                 $p[$sub->forum_id] = $thisPostid;
             }
             # if this subforum has a parent that is differemt to the main forum being dislayed in the view
             # then it has to be a nested subforum so do we need to merge the numbers?
             if ($sub->parent != $forumid) {
                 $f[$fidx]->subforums[$sub->parent]->topic_count_sub += $f[$fidx]->subforums[$sub->forum_id]->topic_count;
                 $f[$fidx]->subforums[$sub->parent]->post_count_sub += $f[$fidx]->subforums[$sub->forum_id]->post_count;
                 # and what about the most recent post? Is this in a nested subforum?
                 if ($f[$fidx]->subforums[$sub->forum_id]->post_id > $f[$fidx]->subforums[$sub->parent]->post_id) {
                     # store the alternative forum id in case we need to display the topic data for this one if inc. subs
                     $f[$fidx]->subforums[$sub->parent]->forum_id_sub = $sub->forum_id;
                 }
             }
         }
     }
     # Go grab the sub forum stats and data
     if (!empty($p)) {
         $stats = $this->sp_subforumview_stats_query($p);
         if ($stats) {
             $s = '';
             foreach ($subs as $sub) {
                 if (!empty($stats[$sub->forum_id])) {
                     $s = $stats[$sub->forum_id];
                     $f[$fidx]->subforums[$sub->forum_id]->topic_id = $s->topic_id;
                     $f[$fidx]->subforums[$sub->forum_id]->topic_name = sp_filter_title_display($s->topic_name);
                     $f[$fidx]->subforums[$sub->forum_id]->topic_slug = $s->topic_slug;
                     $f[$fidx]->subforums[$sub->forum_id]->post_id = $s->post_id;
                     $f[$fidx]->subforums[$sub->forum_id]->post_permalink = sp_build_url($f[$fidx]->subforums[$sub->forum_id]->forum_slug, $s->topic_slug, 0, $s->post_id, $s->post_index);
                     $f[$fidx]->subforums[$sub->forum_id]->post_date = $s->post_date;
                     $f[$fidx]->subforums[$sub->forum_id]->post_status = $s->post_status;
                     $f[$fidx]->subforums[$sub->forum_id]->post_index = $s->post_index;
                     # see if we can display the tooltip
                     if (sp_can_view($sub->forum_id, 'post-content', $spThisUser->ID, $s->user_id, $s->topic_id, $s->post_id)) {
                         $f[$fidx]->subforums[$sub->forum_id]->post_tip = $s->post_status ? sp_text('Post awaiting moderation') : sp_filter_tooltip_display($s->post_content, $s->post_status);
                     } else {
                         $f[$fidx]->subforums[$sub->forum_id]->post_tip = '';
                     }
                     $f[$fidx]->subforums[$sub->forum_id]->user_id = $s->user_id;
                     $f[$fidx]->subforums[$sub->forum_id]->display_name = sp_filter_name_display($s->display_name);
                     $f[$fidx]->subforums[$sub->forum_id]->guest_name = sp_filter_name_display($s->guest_name);
                 }
                 # do we need to record a possible subforum substitute topic?
                 $fsub = isset($f[$fidx]->subforums[$sub->forum_id]->forum_id_sub) ? $f[$fidx]->subforums[$sub->forum_id]->forum_id_sub : 0;
                 if ($fsub != 0 && !empty($stats[$fsub])) {
                     $s = $stats[$fsub];
                     $f[$fidx]->subforums[$sub->forum_id]->topic_id_sub = $s->topic_id;
                     $f[$fidx]->subforums[$sub->forum_id]->topic_name_sub = sp_filter_title_display($s->topic_name);
                     $f[$fidx]->subforums[$sub->forum_id]->topic_slug_sub = $s->topic_slug;
                     $f[$fidx]->subforums[$sub->forum_id]->post_id_sub = $s->post_id;
                     $f[$fidx]->subforums[$sub->forum_id]->post_permalink_sub = sp_build_url($f[$fidx]->subforums[$fsub]->forum_slug, $s->topic_slug, 0, $s->post_id, $s->post_index);
                     $f[$fidx]->subforums[$sub->forum_id]->post_date_sub = $s->post_date;
                     $f[$fidx]->subforums[$sub->forum_id]->post_status_sub = $s->post_status;
                     $f[$fidx]->subforums[$sub->forum_id]->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[$fidx]->subforums[$sub->forum_id]->post_tip_sub = $s->post_status ? sp_text('Post awaiting moderation') : sp_filter_tooltip_display($s->post_content, $s->post_status);
                     } else {
                         $f[$fidx]->subforums[$sub->forum_id]->post_tip_sub = '';
                     }
                     $f[$fidx]->subforums[$sub->forum_id]->user_id_sub = $s->user_id;
                     $f[$fidx]->subforums[$sub->forum_id]->display_name_sub = sp_filter_name_display($s->display_name);
                     $f[$fidx]->subforums[$sub->forum_id]->guest_name_sub = sp_filter_name_display($s->guest_name);
                 }
                 # allow plugins to add more data to combined subforum/post data structure
                 $f[$fidx]->subforums[$sub->forum_id] = apply_filters('sph_forumview_subforum_records', $f[$fidx]->subforums[$sub->forum_id], $s);
             }
         }
         unset($subs);
         unset($stats);
     }
     return $f;
 }
    function sp_listview_query($topicIds, $count, $group, $forumIds, $firstPost, $popup)
    {
        global $spThisUser, $spGlobals;
        # If no topic ids and no count then nothjing to do - return empty
        if (empty($topicIds) && $count == 0) {
            return;
        }
        # set popup flag for new posts
        $this->popup = $popup;
        # Do we have enough topic ids to satisfy count?
        if (empty($topicIds) || $count != 0 && count($topicIds) < $count) {
            $topicIds = $this->sp_listview_populate_topicids($topicIds, $forumIds, $count);
        }
        # Do we havwe too many topic ids?
        if ($topicIds && ($count != 0 && count($topicIds) > $count)) {
            $topicIds = array_slice($topicIds, 0, $count, true);
        }
        if (empty($topicIds)) {
            return;
        }
        # Construct the main WHERE clause and then main query
        $where = SFTOPICS . '.topic_id IN (' . implode(',', $topicIds) . ')';
        if ($group) {
            $orderby = 'group_seq, forum_seq, ' . SFTOPICS . '.post_id DESC';
        } else {
            $orderby = SFTOPICS . '.post_id DESC';
        }
        $spdb = new spdbComplex();
        $spdb->table = SFTOPICS;
        $spdb->fields = SFTOPICS . '.forum_id, forum_name, forum_slug, forum_disabled, ' . SFTOPICS . '.topic_id, topic_name, topic_slug, topic_icon, topic_icon_new, ' . SFTOPICS . '.post_count,
								' . SFTOPICS . '.post_id, post_status, post_index, ' . spdb_zone_datetime('post_date') . ',
								guest_name, ' . SFPOSTS . '.user_id, post_content, display_name';
        $spdb->join = array(SFFORUMS . ' ON ' . SFFORUMS . '.forum_id = ' . SFTOPICS . '.forum_id', SFGROUPS . ' ON ' . SFGROUPS . '.group_id = ' . SFFORUMS . '.group_id', SFPOSTS . ' ON ' . SFPOSTS . '.post_id = ' . SFTOPICS . '.post_id');
        $spdb->left_join = array(SFMEMBERS . ' ON ' . SFMEMBERS . '.user_id = ' . SFPOSTS . '.user_id');
        $spdb->where = $where;
        $spdb->orderby = $orderby;
        $spdb = apply_filters('sph_topic_list_query', $spdb, $this);
        $records = $spdb->select();
        # add filters where required plus extra data
        # And the new array
        $list = array();
        if ($records) {
            # check if all forum ids are the same
            $x = current($records);
            $f = $x->forum_id;
            $single = 1;
            foreach ($records as $r) {
                if ($r->forum_id != $f) {
                    $single = 0;
                }
            }
            reset($records);
            $new = '';
            $first = '';
            # Now we can grab the supplementary post records where there may be new posts...
            if ($spThisUser->member) {
                $new = $this->sp_listview_populate_newposts($topicIds);
            }
            # go and grab the first post info if desired
            if ($firstPost) {
                $first = $this->sp_listview_populate_firstposts($topicIds);
            }
            # Some values we need
            # How many topics to a page?
            $ppaged = $spGlobals['display']['posts']['perpage'];
            if (empty($ppaged) || $ppaged == 0) {
                $ppaged = 20;
            }
            # establish topic sort order
            $order = 'ASC';
            # default
            if ($spGlobals['display']['posts']['sortdesc']) {
                $order = 'DESC';
            }
            # global override
            $listPos = 1;
            foreach ($records as $r) {
                $show = true;
                # can the user see this forum?
                if (!sp_can_view($r->forum_id, 'topic-title')) {
                    $show = false;
                }
                # if in moderattion can this user approve posts?
                if ($r->post_status != 0 && !sp_get_auth('moderate_posts', $r->forum_id)) {
                    $show = false;
                }
                if ($show) {
                    $t = $r->topic_id;
                    $list[$t] = new stdClass();
                    $list[$t]->forum_id = $r->forum_id;
                    $list[$t]->forum_name = sp_filter_title_display($r->forum_name);
                    $list[$t]->forum_disabled = $r->forum_disabled;
                    $list[$t]->forum_permalink = sp_build_url($r->forum_slug, '', 1, 0);
                    $list[$t]->topic_id = $r->topic_id;
                    $list[$t]->topic_name = sp_filter_title_display($r->topic_name);
                    $list[$t]->topic_permalink = sp_build_url($r->forum_slug, $r->topic_slug, 1, 0);
                    $list[$t]->topic_icon = sanitize_file_name($r->topic_icon);
                    $list[$t]->topic_icon_new = sanitize_file_name($r->topic_icon_new);
                    $list[$t]->post_count = $r->post_count;
                    $list[$t]->post_id = $r->post_id;
                    $list[$t]->post_status = $r->post_status;
                    $list[$t]->post_date = $r->post_date;
                    $list[$t]->user_id = $r->user_id;
                    $list[$t]->guest_name = sp_filter_name_display($r->guest_name);
                    $list[$t]->display_name = sp_filter_name_display($r->display_name);
                    if (sp_can_view($r->forum_id, 'post-content', $spThisUser->ID, $r->user_id)) {
                        $list[$t]->post_tip = $r->post_status ? sp_text('Post awaiting moderation') : sp_filter_tooltip_display($r->post_content, $r->post_status);
                    } else {
                        $list[$t]->post_tip = '';
                    }
                    $list[$t]->list_position = $listPos;
                    if (empty($r->display_name)) {
                        $list[$t]->display_name = $list[$t]->guest_name;
                    }
                    # Lastly determine the page for the post permalink
                    if ($order == 'ASC') {
                        $page = $r->post_index / $ppaged;
                        if (!is_int($page)) {
                            $page = intval($page + 1);
                        }
                    } else {
                        $page = $r->post_count - $r->post_index;
                        $page = $page / $ppaged;
                        $page = intval($page + 1);
                    }
                    $r->page = $page;
                    $list[$t]->post_permalink = sp_build_url($r->forum_slug, $r->topic_slug, $r->page, $r->post_id, $r->post_index);
                    $list[$t]->single_forum = $single;
                    # add in any new post details if they exist
                    if (!empty($new) && array_key_exists($t, $new)) {
                        $list[$t]->new_post_count = $new[$t]->new_post_count;
                        $list[$t]->new_post_post_id = $new[$t]->new_post_post_id;
                        $list[$t]->new_post_post_index = $new[$t]->new_post_post_index;
                        $list[$t]->new_post_post_date = $new[$t]->new_post_post_date;
                        $list[$t]->new_post_user_id = $new[$t]->new_post_user_id;
                        $list[$t]->new_post_display_name = $new[$t]->new_post_display_name;
                        $list[$t]->new_post_guest_name = $new[$t]->new_post_guest_name;
                        $list[$t]->new_post_permalink = sp_build_url($r->forum_slug, $r->topic_slug, 0, $new[$t]->new_post_post_id, $new[$t]->new_post_post_index);
                        if (empty($new[$t]->new_post_display_name)) {
                            $list[$t]->new_post_display_name = $new[$t]->new_post_guest_name;
                        }
                    }
                    # add the first post info if desired
                    if ($firstPost) {
                        $list[$t]->first_post_permalink = sp_build_url($r->forum_slug, $r->topic_slug, 0, $first[$t]->post_id, 1);
                        $list[$t]->first_post_date = $first[$t]->post_date;
                        $list[$t]->first_user_id = $first[$t]->user_id;
                        $list[$t]->first_guest_name = sp_filter_name_display($first[$t]->guest_name);
                        $list[$t]->first_display_name = sp_filter_name_display($first[$t]->display_name);
                        if (sp_can_view($r->forum_id, 'post-content', $spThisUser->ID, $first[$t]->user_id)) {
                            $list[$t]->first_post_tip = $first[$t]->post_status ? sp_text('Post awaiting moderation') : sp_filter_tooltip_display($first[$t]->post_content, $first[$t]->post_status);
                        } else {
                            $list[$t]->first_post_tip = '';
                        }
                        if (empty($list[$t]->first_display_name)) {
                            $list[$t]->first_display_name = $list[$t]->first_guest_name;
                        }
                    }
                    $list[$t] = apply_filters('sph_topic_list_record', $list[$t], $r);
                    $listPos++;
                }
            }
            unset($records);
            unset($new);
            unset($first);
        }
        return $list;
    }
function sp_PostNewTopicButton($args = '', $label = '', $toolTip = '', $toolTipLock = '')
{
    global $spThisTopic, $spGlobals, $spThisUser;
    # can be empty if request is for a bogus topic slug
    if (empty($spThisTopic)) {
        return;
    }
    if (!sp_get_auth('start_topics', $spThisTopic->forum_id)) {
        return;
    }
    $defs = array('tagId' => 'spPostNewTopicButton', 'tagClass' => 'spButton', 'icon' => 'sp_NewTopic.png', 'iconLock' => 'sp_ForumStatusLock.png', 'iconClass' => 'spIcon', 'iconStatusClass' => 'spIcon', 'echo' => 1);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_PostNewTopicButton_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $tagId = esc_attr($tagId);
    $tagClass = esc_attr($tagClass);
    $icon = sanitize_file_name($icon);
    $iconClass = esc_attr($iconClass);
    $iconStatusClass = esc_attr($iconStatusClass);
    $toolTip = esc_attr($toolTip);
    $toolTipLock = esc_attr($toolTipLock);
    $echo = (int) $echo;
    # is the forum locked?
    $out = '';
    $lock = false;
    if ($spGlobals['lockdown'] || $spThisTopic->forum_status) {
        if (!empty($iconLock)) {
            $out .= sp_paint_icon($tagClass . ' ' . $iconStatusClass, SPTHEMEICONSURL, sanitize_file_name($iconLock), $toolTipLock);
        }
        if (!$spThisUser->admin) {
            $lock = true;
        }
    }
    if (!$lock && sp_get_auth('start_topics', $spThisTopic->forum_id)) {
        $url = sp_build_url($spThisTopic->forum_slug, '', 1, 0) . sp_add_get() . 'new=topic';
        $out .= "<a href='{$url}' class='{$tagClass}' id='{$tagId}' title='{$toolTip}'>\n";
        if (!empty($icon)) {
            $out .= sp_paint_icon($iconClass, SPTHEMEICONSURL, $icon);
        }
        if (!empty($label)) {
            $out .= sp_filter_title_display($label);
        }
        $out .= "</a>\n";
    }
    $out = apply_filters('sph_PostNewTopicButton', $out, $a);
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}
function sp_topic_delete()
{
    sp_delete_topic(sp_esc_int($_GET['killtopic']), sp_esc_int($_GET['killtopicforum']), false);
    $view = sp_esc_str($_GET['view']);
    if ($view == 'topic') {
        $forumslug = spdb_table(SFFORUMS, 'forum_id=' . sp_esc_int($_GET['killtopicforum']), 'forum_slug');
        $returnURL = sp_build_url($forumslug, '', 0);
        echo $returnURL;
    } else {
        if ($_GET['count'] == 1) {
            $forumslug = spdb_table(SFFORUMS, 'forum_id=' . sp_esc_int($_GET['killtopicforum']), 'forum_slug');
            $page = sp_esc_int($_GET['page']);
            if ($page == 1) {
                $returnURL = sp_build_url($forumslug, '', 0);
            } else {
                $page = $page - 1;
                $returnURL = sp_build_url($forumslug, '', $page);
            }
            echo $returnURL;
        }
    }
    die;
}
function sp_do_sp_ForumDropdownTag($args = '')
{
    #check if forum displayed
    if (sp_abort_display_forum()) {
        return;
    }
    $defs = array('tagId' => 'spForumDropdownTag', 'tagClass' => 'spLinkTag', 'selectClass' => 'spSelectTag', 'forumList' => 0, 'label' => __("Select forum", 'sp-ttags'), 'length' => 30, 'echo' => 1);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_ForumDropdownTag_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $tagId = esc_attr($tagId);
    $tagClass = esc_attr($tagClass);
    $selectClass = esc_attr($selectClass);
    $forumList = esc_attr($forumList);
    $label = sp_filter_title_display($label);
    $length = (int) $length;
    $echo = (int) $echo;
    global $spThisUser;
    sp_forum_api_support();
    $forum_ids = array();
    if ($forumList == 0) {
        $forum_ids = sp_get_forum_memberships($spThisUser->ID);
    } else {
        $allforums = explode(',', $forumList);
        foreach ($allforums as $thisforum) {
            if (sp_can_view($thisforum, 'forum-title')) {
                $forum_ids[] = $thisforum;
            }
        }
    }
    if (empty($forum_ids)) {
        return;
    }
    # create where clause based on forums that current user can view
    $where = "forum_id IN (" . implode(",", $forum_ids) . ")";
    $spdb = new spdbComplex();
    $spdb->table = SFFORUMS;
    $spdb->fields = 'forum_slug, forum_name';
    $spdb->join = array(SFGROUPS . ' ON ' . SFFORUMS . '.group_id = ' . SFGROUPS . '.group_id');
    $spdb->where = $where;
    $spdb->orderby = 'group_seq, forum_seq';
    $forums = $spdb->select();
    $out = "<div id='{$tagId}' class='{$tagClass}'>";
    $out .= '<select name="forumselect" class="' . $selectClass . '" onChange="javascript:spjChangeForumURL(this)">' . "\n";
    $out .= '<option>' . $label . '</option>' . "\n";
    foreach ($forums as $forum) {
        $out .= '<option value="' . sp_build_url($forum->forum_slug, '', 0, 0) . '">&nbsp;&nbsp;' . sp_create_name_extract(sp_filter_title_display($forum->forum_name), $length) . '</option>' . "\n";
    }
    $out .= '</select>' . "\n";
    $out .= '</div>';
    $out .= '<script type="text/javascript">';
    $out .= 'function spjChangeForumURL(menuObj) {';
    $out .= 'var i = menuObj.selectedIndex;';
    $out .= 'if(i > 0) {';
    $out .= 'if(menuObj.options[i].value != "#") {';
    $out .= 'window.location = menuObj.options[i].value;';
    $out .= '}}}';
    $out .= '</script>';
    $out = apply_filters('sph_ForumDropdownTag', $out);
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}
function spa_forums_global_rss_form()
{
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	spjAjaxForm('sfnewglobalrss', 'sfreloadfd');
    });
</script>
<?php 
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=globalrss';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfnewglobalrss" name="sfnewglobalrss">
<?php 
    echo sp_create_nonce('forum-adminform_globalrss');
    spa_paint_open_tab(spa_text('Forums') . ' - ' . spa_text('Global RSS Settings'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Globally Enable/Disable RSS Feeds'), true, 'global-rss');
    spa_paint_input(spa_text('Replacement external RSS URL for all RSS') . '<br />' . spa_text('Default') . ': <strong><small>' . sp_build_url('', '', 0, 0, 0, 1) . '</small></strong>', 'sfallrssurl', sp_get_option('sfallRSSurl'));
    $base = SFHOMEURL . 'index.php?sp_ahah=forums-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah');
    $target = 'sfallrss';
    $image = SFADMINIMAGES;
    $rss_count = spdb_count(SFFORUMS, 'forum_rss_private=0');
    echo spa_text('Enabled Forum RSS feeds') . ': ' . $rss_count . '&nbsp;&nbsp;&nbsp;&nbsp;';
    $rss_count = spdb_count(SFFORUMS, 'forum_rss_private=1');
    echo spa_text('Disabled Forum RSS feeds') . ': ' . $rss_count . '<hr />';
    ?>
				<input type="button" class="button-secondary" value="<?php 
    echo spa_text('Disable All RSS Feeds');
    ?>
" onclick="spjLoadForm('globalrssset', '<?php 
    echo $base;
    ?>
', '<?php 
    echo $target;
    ?>
', '<?php 
    echo $image;
    ?>
', '1', '1');" />
				<input type="button" class="button-secondary" value="<?php 
    echo spa_text('Enable All RSS Feeds');
    ?>
" onclick="spjLoadForm('globalrssset', '<?php 
    echo $base;
    ?>
', '<?php 
    echo $target;
    ?>
', '<?php 
    echo $image;
    ?>
', '0', '1');" />

				<div class="sfinline-form">  <!-- This row will hold ahah forms for the all rss -->
				<div id="sfallrss"></div>
				</div>

<?php 
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_forums_global_rss_panel');
    spa_paint_close_container();
    ?>
		<div class="sfform-submit-bar">
		<input type="submit" class="button-primary" id="saveit" name="saveit" value="<?php 
    spa_etext('Update Global RSS Settings');
    ?>
" />
		</div>
	</form>
	<?php 
    spa_paint_close_tab();
    ?>

	<div class="sfform-panel-spacer"></div>
<?php 
}
function sp_get_topic_newpost_url($forumslug, $topicslug, $topicname, $postid, $postindex = 0)
{
    $out = '<a href="' . sp_build_url($forumslug, $topicslug, 0, $postid, $postindex) . '">' . $topicname . '</a>' . "\n";
    return $out;
}
Exemple #15
0
     case 'forum':
         $rssTitle = get_bloginfo('name') . ' - ' . sp_text('Forum') . ': ' . $first->forum_name;
         $rssLink = sp_build_url($first->forum_slug, '', 0, 0);
         if (isset($rssopt['sfrssfeedkey']) && $rssopt['sfrssfeedkey'] && isset($spThisUser->feedkey)) {
             $atomLink = trailingslashit(sp_build_url($first->forum_slug, '', 0, 0, 0, 1)) . user_trailingslashit($spThisUser->feedkey);
         } else {
             $atomLink = sp_build_url($first->forum_slug, '', 0, 0, 0, 1);
         }
         break;
     case 'topic':
         $rssTitle = get_bloginfo('name') . ' - ' . sp_text('Topic') . ': ' . $first->topic_name;
         $rssLink = sp_build_url($first->forum_slug, $first->topic_slug, 0, 0);
         if (isset($rssopt['sfrssfeedkey']) && $rssopt['sfrssfeedkey'] && isset($spThisUser->feedkey)) {
             $atomLink = trailingslashit(sp_build_url($first->forum_slug, $first->topic_slug, 0, 0, 0, 1)) . user_trailingslashit($spThisUser->feedkey);
         } else {
             $atomLink = sp_build_url($first->forum_slug, $first->topic_slug, 0, 0, 0, 1);
         }
         break;
 }
 # init rss info with filters
 $rssTitle = apply_filters('sph_feed_title', $rssTitle, $first);
 $rssDescription = apply_filters('sph_feed_description', get_bloginfo('description'));
 $rssGenerator = apply_filters('sph_feed_generator', sp_text('Simple:Press Version') . ' ' . SPVERSION);
 # set up time for current user timezone
 $tz = get_option('timezone_string');
 if (empty($tz) || substr($tz, 0, 3) == 'UTC') {
     $tz = 'UTC';
 }
 $tzUser = !empty($spThisUser->timezone_string) ? $spThisUser->timezone_string : $tz;
 if (substr($tzUser, 0, 3) == 'UTC') {
     $tzUser = '******';
    function sp_postlistview_query($where, $order, $count, $view, $type)
    {
        global $spGlobals, $spThisUser;
        # If no WHERE clause then return empty
        if (empty($where)) {
            return;
        }
        # build list of forums user can view
        $fids = sp_user_visible_forums($view);
        if (!empty($fids)) {
            $fids = implode(',', $fids);
            $where .= ' AND ' . SFPOSTS . ".forum_id IN ({$fids})";
        }
        # Check order
        if (empty($order)) {
            $order = SFPOSTS . '.post_id DESC';
        }
        $spdb = new spdbComplex();
        $spdb->table = SFPOSTS;
        $spdb->fields = SFPOSTS . '.post_id, post_content, ' . spdb_zone_datetime('post_date') . ', ' . SFPOSTS . '.topic_id, ' . SFPOSTS . '.forum_id,
								  ' . SFPOSTS . '.user_id, guest_name, post_status, post_index, forum_name, forum_slug, forum_disabled, ' . SFFORUMS . '.group_id, group_name,
								  topic_name, topic_slug, ' . SFTOPICS . '.post_count, topic_opened, display_name';
        $spdb->join = array(SFFORUMS . ' ON ' . SFFORUMS . '.forum_id = ' . SFPOSTS . '.forum_id', SFGROUPS . ' ON ' . SFGROUPS . '.group_id = ' . SFFORUMS . '.group_id', SFTOPICS . ' ON ' . SFTOPICS . '.topic_id = ' . SFPOSTS . '.topic_id');
        $spdb->left_join = array(SFMEMBERS . ' ON ' . SFMEMBERS . '.user_id = ' . SFPOSTS . '.user_id');
        $spdb->where = $where;
        $spdb->orderby = $order;
        if ($count) {
            $spdb->limits = $count;
        }
        $spdb = apply_filters('sph_post_list_query', $spdb, $this, $type);
        if (!empty($spThisUser->inspect['q_spPostListView'])) {
            $spdb->inspect = 'spPostListView';
            $spdb->show = true;
        }
        $records = $spdb->select();
        # Now check authorisations and clean up the object
        $list = array();
        # Some values we need
        # How many topics to a page?
        $ppaged = $spGlobals['display']['posts']['perpage'];
        if (empty($ppaged) || $ppaged == 0) {
            $ppaged = 20;
        }
        # establish topic sort order
        $porder = 'ASC';
        # default
        if ($spGlobals['display']['posts']['sortdesc']) {
            $porder = 'DESC';
        }
        # global override
        if ($records) {
            $listPos = 1;
            foreach ($records as $r) {
                if (sp_can_view($r->forum_id, 'forum-title')) {
                    if ($r->post_status == 0 || sp_get_auth('moderate_posts', $r->forum_id)) {
                        $p = $r->post_id;
                        $list[$p] = $r;
                        # Now apply any necessary filters and data changes
                        $list[$p]->post_content = sp_filter_content_display($r->post_content);
                        $list[$p]->post_content_raw = $r->post_content;
                        $list[$p]->forum_name = sp_filter_title_display($r->forum_name);
                        $list[$p]->forum_disabled = $r->forum_disabled;
                        $list[$p]->forum_permalink = sp_build_url($r->forum_slug, '', 1, 0);
                        $list[$p]->topic_permalink = sp_build_url($r->forum_slug, $r->topic_slug, 1, 0);
                        $list[$p]->topic_name = sp_filter_title_display($r->topic_name);
                        $list[$p]->topic_opened = $r->topic_opened;
                        $list[$p]->group_name = sp_filter_title_display($r->group_name);
                        if (sp_can_view($r->forum_id, 'post-content', $spThisUser->ID, $r->user_id, $r->topic_id, $r->post_id)) {
                            $list[$p]->post_tip = $r->post_status ? sp_text('Post awaiting moderation') : sp_filter_tooltip_display($r->post_content, $r->post_status);
                        } else {
                            $list[$p]->post_tip = '';
                        }
                        # Ensure display name is populated
                        if (empty($r->display_name)) {
                            $list[$p]->display_name = $list[$p]->guest_name;
                        }
                        $list[$p]->display_name = sp_filter_name_display($list[$p]->display_name);
                        # determine the page for the post permalink
                        if ($porder == 'ASC') {
                            $page = $r->post_index / $ppaged;
                            if (!is_int($page)) {
                                $page = intval($page + 1);
                            }
                        } else {
                            $page = $r->post_count - $r->post_index;
                            $page = $page / $ppaged;
                            $page = intval($page + 1);
                        }
                        $list[$p]->post_permalink = sp_build_url($r->forum_slug, $r->topic_slug, $page, $r->post_id, $r->post_index);
                        $list[$p]->list_position = $listPos;
                        $list[$p] = apply_filters('sph_post_list_record', $list[$p], $r, $type);
                    }
                }
                $listPos++;
            }
        }
        return $list;
    }
function spa_get_members_info($userid)
{
    $data = sp_get_member_row($userid);
    if (empty($data)) {
        return '';
    }
    $first = spdb_select('row', '
			SELECT ' . SFPOSTS . '.forum_id, forum_name, forum_slug, ' . SFPOSTS . '.topic_id, topic_name, topic_slug, post_date
			FROM ' . SFPOSTS . '
			JOIN ' . SFTOPICS . ' ON ' . SFTOPICS . '.topic_id = ' . SFPOSTS . '.topic_id
			JOIN ' . SFFORUMS . ' ON ' . SFFORUMS . '.forum_id = ' . SFPOSTS . '.forum_id
			WHERE ' . SFPOSTS . ".user_id={$userid}\n\t\t\tORDER BY post_date ASC\n\t\t\tLIMIT 1");
    if ($first) {
        $url = '<a href="' . sp_build_url($first->forum_slug, $first->topic_slug, 1, 0) . '">' . sp_filter_title_display($first->topic_name) . '</a>';
        $data['first'] = sp_filter_title_display($first->forum_name) . '<br />' . $url . '<br />' . sp_date('d', $first->post_date);
    } else {
        $data['first'] = spa_text('No Posts');
    }
    $last = spdb_select('row', '
			SELECT ' . SFPOSTS . '.forum_id, forum_name, forum_slug, ' . SFPOSTS . '.topic_id, topic_name, topic_slug, post_date
			FROM ' . SFPOSTS . '
			JOIN ' . SFTOPICS . ' ON ' . SFTOPICS . '.topic_id = ' . SFPOSTS . '.topic_id
			JOIN ' . SFFORUMS . ' ON ' . SFFORUMS . '.forum_id = ' . SFPOSTS . '.forum_id
			WHERE ' . SFPOSTS . ".user_id={$userid}\n\t\t\tORDER BY post_date DESC\n\t\t\tLIMIT 1");
    if ($last) {
        $url = '<a href="' . sp_build_url($last->forum_slug, $last->topic_slug, 1, 0) . '">' . sp_filter_title_display($last->topic_name) . '</a>';
        $data['last'] = sp_filter_title_display($last->forum_name) . '<br />' . $url . '<br />' . sp_date('d', $last->post_date);
    } else {
        $data['last'] = spa_text('No posts');
    }
    if ($data['admin']) {
        $user_memberships = 'Admin';
        $status = 'Admin';
        $start = 0;
    } else {
        if ($data['moderator']) {
            $status = 'Moderator';
            $start = 1;
        } else {
            $status = 'User';
            $start = 1;
        }
    }
    $memberships = spdb_table(SFMEMBERSHIPS, "user_id={$userid}", '', '', '', ARRAY_A);
    if ($memberships) {
        foreach ($memberships as $membership) {
            $name = spdb_table(SFUSERGROUPS, 'usergroup_id=' . $membership['usergroup_id'], 'usergroup_name');
            if ($start) {
                $user_memberships = $name;
                $start = 0;
            } else {
                $user_memberships .= ', ' . $name;
            }
        }
    } else {
        if ($start) {
            $user_memberships = 'No Memberships';
        }
    }
    $data['memberships'] = $user_memberships;
    $rank = sp_get_user_forum_rank($status, $userid, $data['posts']);
    $data['rank'] = $rank[0]['name'];
    $user = get_userdata($userid);
    $data['login'] = $user->user_login;
    return $data;
}
function sp_AllRSSButton($args = '', $label = '', $toolTip = '')
{
    global $spThisUser;
    if (!sp_get_auth('view_forum')) {
        return;
    }
    $defs = array('tagId' => 'spAllRSSButton', 'tagClass' => 'spLink', 'icon' => 'sp_Feed.png', 'iconClass' => 'spIcon', 'echo' => 1);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_AllRSSButton_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $tagId = esc_attr($tagId);
    $tagClass = esc_attr($tagClass);
    $icon = sanitize_file_name($icon);
    $iconClass = esc_attr($iconClass);
    $toolTip = esc_attr($toolTip);
    $echo = (int) $echo;
    # only display all rss feed if at least one forum has rss on
    $forums = spdb_table(SFFORUMS, 'forum_rss_private=0');
    if ($forums) {
        $rssUrl = sp_get_option('sfallRSSurl');
        if (empty($rssUrl)) {
            $rssopt = sp_get_option('sfrss');
            if ($rssopt['sfrssfeedkey'] && isset($spThisUser->feedkey)) {
                $rssUrl = trailingslashit(sp_build_url('', '', 0, 0, 0, 1)) . user_trailingslashit($spThisUser->feedkey);
            } else {
                $rssUrl = sp_build_url('', '', 0, 0, 0, 1);
            }
        }
    } else {
        return;
    }
    $out = "<a class='{$tagClass} vtip' id='{$tagId}' title='{$toolTip}' rel='nofollow' href='{$rssUrl}'>";
    if (!empty($icon)) {
        $out .= "<img class='{$iconClass}' src='" . sp_find_icon(SPTHEMEICONSURL, $icon) . "' alt=''/>";
    }
    if (!empty($label)) {
        $out .= sp_filter_title_display($label);
    }
    $out .= "</a>\n";
    $out = apply_filters('sph_AllRSSButton', $out, $a);
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}
function sp_get_topic_url($forumslug, $topicslug, $topicname)
{
    global $spVars;
    $out = '';
    $topicname = sp_filter_title_display($topicname);
    if (isset($spVars['searchvalue']) && $spVars['searchvalue']) {
        $out .= '<a href="' . sp_build_url($forumslug, $topicslug, 1, 0);
        if (strpos(sp_url(), '?') === false) {
            $out .= '?value';
        } else {
            $out .= '&amp;value';
        }
        $out .= '=' . $spVars['searchvalue'] . '&amp;type=' . $spVars['searchtype'] . '&amp;include=' . $spVars['searchinclude'] . '&amp;scope=' . '&amp;search=' . $spVars['searchpage'] . '">' . $topicname . "</a>\n";
    } else {
        $out = '<a href="' . sp_build_url($forumslug, $topicslug, 1, 0) . '">' . sp_filter_title_display($topicname) . "</a>\n";
    }
    return $out;
}
 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_canonical_url()
{
    global $spVars;
    if ($spVars['pageview'] == 'profileshow' || $spVars['pageview'] == 'profileedit') {
        $url = sp_url('profile');
    } else {
        if ($spVars['pageview'] == 'list') {
            $page = '';
            if ($spVars['page'] > 0) {
                $page = '/page-' . $spVars['page'];
            }
            $url = sp_url('members' . $page);
        } else {
            if (!empty($spVars['topicslug'])) {
                $url = sp_build_url($spVars['forumslug'], $spVars['topicslug'], $spVars['page'], 0);
            } else {
                if (!empty($spVars['forumslug'])) {
                    $url = sp_build_url($spVars['forumslug'], '', $spVars['page'], 0);
                } else {
                    $url = sp_url();
                }
            }
        }
    }
    return apply_filters('sph_canonical_url', $url);
}
function spa_forums_edit_group_form($group_id)
{
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	jQuery('#grouprow-<?php 
    echo $group_id;
    ?>
').addClass('inForm');
    	spjAjaxForm('sfgroupedit<?php 
    echo $group_id;
    ?>
', 'sfreloadfb');
    });
</script>
<?php 
    global $spPaths;
    $group = $group = spdb_table(SFGROUPS, "group_id={$group_id}", 'row');
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=editgroup';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfgroupedit<?php 
    echo $group->group_id;
    ?>
" name="sfgroupedit<?php 
    echo $group->group_id;
    ?>
">
<?php 
    echo sp_create_nonce('forum-adminform_groupedit');
    spa_paint_open_tab(spa_text('Forums') . ' - ' . spa_text('Manage Groups and Forums'), false);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Edit Group'), 'true', 'edit-forum-group');
    ?>
					<input type="hidden" name="group_id" value="<?php 
    echo $group->group_id;
    ?>
" />
					<input type="hidden" name="cgroup_name" value="<?php 
    echo sp_filter_title_display($group->group_name);
    ?>
" />
					<input type="hidden" name="cgroup_desc" value="<?php 
    echo sp_filter_text_edit($group->group_desc);
    ?>
" />
					<input type="hidden" name="cgroup_seq" value="<?php 
    echo $group->group_seq;
    ?>
" />
					<input type="hidden" name="cgroup_icon" value="<?php 
    echo esc_attr($group->group_icon);
    ?>
" />
					<input type="hidden" name="cgroup_rss" value="<?php 
    echo $group->group_rss;
    ?>
" />
					<input type="hidden" name="cgroup_message" value="<?php 
    echo sp_filter_text_edit($group->group_message);
    ?>
" />
<?php 
    spa_paint_input(spa_text('Group Name'), 'group_name', sp_filter_title_display($group->group_name), false, true);
    spa_paint_input(spa_text('Description'), 'group_desc', sp_filter_text_edit($group->group_desc), false, true);
    spa_paint_select_start(spa_text('Select Custom Icon'), 'group_icon', '');
    spa_select_icon_dropdown('group_icon', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', $group->group_icon, false);
    spa_paint_select_end();
    spa_paint_input(spa_text('Replacement external RSS URL') . '<br />' . spa_text('Default') . ': <strong>' . sp_get_sfqurl(sp_build_url('', '', 0, 0, 0, 1)) . 'group=' . $group->group_id . '</strong>', 'group_rss', sp_filter_url_display($group->group_rss), false, true);
    spa_paint_wide_textarea('Special group message to be displayed above forums', 'group_message', sp_filter_text_edit($group->group_message));
    do_action('sph_forums_edit_group_panel');
    spa_paint_close_fieldset();
    echo '<div class="sfoptionerror spaceabove">';
    echo sprintf(sp_text('To re-order your Groups, Forums and SubForums use the %s Order Groups and Forums %s option from the Forums Menu'), '<b>', '</b>');
    echo '</div>';
    spa_paint_close_panel();
    spa_paint_tab_right_cell();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Default User Group Permissions'), false);
    echo '<strong>' . spa_text('Set default usergroup permission sets for this group') . '</strong><br />';
    echo spa_text('Note - This will not will add or modify any current permissions. It is only a default setting for future forums created in this group.  Existing default usergroup settings will be shown in the drop down menus');
    # Permissions
    $usergroups = spa_get_usergroups_all();
    $roles = sp_get_all_roles();
    foreach ($usergroups as $usergroup) {
        echo '<input type="hidden" name="usergroup_id[]" value="' . $usergroup->usergroup_id . '" />';
        spa_paint_select_start(sp_filter_title_display($usergroup->usergroup_name), 'role[]', '');
        $defrole = spa_get_defpermissions_role($group->group_id, $usergroup->usergroup_id);
        if ($defrole == -1 || $defrole == '') {
            echo '<option value="-1">' . spa_text('Select permission set') . '</option>';
        }
        foreach ($roles as $role) {
            $selected = '';
            if ($defrole == $role->role_id) {
                $selected = 'selected="selected" ';
            }
            echo '<option ' . $selected . 'value="' . $role->role_id . '">' . sp_filter_title_display($role->role_name) . '</option>' . "\n";
        }
        spa_paint_select_end();
    }
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_close_container();
    ?>
		<div class="sfform-submit-bar">
		<input type="submit" class="button-primary" id="groupedit<?php 
    echo $group->group_id;
    ?>
" name="groupedit<?php 
    echo $group->group_id;
    ?>
" value="<?php 
    spa_etext('Update Group');
    ?>
" />
		<input type="button" class="button-primary" onclick="javascript:jQuery('#group-<?php 
    echo $group->group_id;
    ?>
').html('');jQuery('#grouprow-<?php 
    echo $group_id;
    ?>
').removeClass('inForm');" id="sfgroupedit<?php 
    echo $group->group_id;
    ?>
" name="groupeditcancel<?php 
    echo $group->group_id;
    ?>
" value="<?php 
    spa_etext('Cancel');
    ?>
" />
		</div>
	</form>

	<?php 
    spa_paint_close_tab();
    ?>

	<div class="sfform-panel-spacer"></div>
<?php 
}
function sp_permalink_from_postid($postid)
{
    $url = '';
    if (!empty($postid)) {
        $slugs = sp_get_slugs_from_postid($postid);
        $url = sp_build_url($slugs->forum_slug, $slugs->topic_slug, 0, $postid, $slugs->post_index);
    }
    return $url;
}
function sp_render_post_tools($post, $forum, $topic, $page, $postnum, $useremail, $guestemail, $displayname, $last)
{
    global $spThisUser;
    $out = '';
    $out .= '<div id="spMainContainer" class="spForumToolsPopup">';
    $out .= '<div class="spForumToolsHeader">';
    $out .= '<div class="spForumToolsHeaderTitle">' . sp_filter_title_display($topic['topic_name']) . '</div>';
    $out .= '<div class="spForumToolsHeaderTitle">' . sp_text('Post') . ' #' . $postnum . '</div>';
    $out .= '</div>';
    $out .= sp_render_common_tools($forum, $topic, $post, $page);
    if ($post['post_status'] != 0 && sp_get_auth('moderate_posts', $forum['forum_id'])) {
        $out .= '<div class="spForumToolsModerate">';
        $out .= '<img class="spIcon" src="' . sp_find_icon(SPTHEMEICONSURL, 'sp_ToolsApprove.png') . '" alt="" title="" />';
        $out .= '<a href="javascript:document.postapprove' . $post['post_id'] . '.submit();">' . sp_text('Approve this post') . '</a>';
        $out .= '<form action="' . sp_build_url($forum['forum_slug'], $topic['topic_slug'], $page, $post['post_id'], $post['post_index']) . '" method="post" name="postapprove' . $post['post_id'] . '">';
        $out .= '<input type="hidden" name="approvepost" value="' . $post['post_id'] . '" />';
        $out .= '</form>';
        $out .= '</div>';
    }
    if ($post['post_status'] == 0 && sp_get_auth('moderate_posts', $forum['forum_id'])) {
        $out .= '<div class="spForumToolsModerate">';
        $out .= '<img class="spIcon" src="' . sp_find_icon(SPTHEMEICONSURL, 'sp_ToolsUnapprove.png') . '" alt="" title="" />';
        $out .= '<a href="javascript:document.unapprovepost' . $post['post_id'] . '.submit();">' . sp_text('Unapprove this post') . '</a>';
        $out .= '<form action="' . sp_build_url($forum['forum_slug'], $topic['topic_slug'], $page, $post['post_id'], $post['post_index']) . '" method="post" name="unapprovepost' . $post['post_id'] . '">';
        $out .= '<input type="hidden" name="unapprovepost" value="' . $post['post_id'] . '" />';
        $out .= '</form>';
        $out .= '</div>';
    }
    if (sp_get_auth('view_email', $forum['forum_id'])) {
        $email = !empty($useremail) ? $useremail : $guestemail;
        $content = '';
        if ($post['user_id']) {
            $content .= '<div>' . sp_text('User ID') . ': ' . $post['user_id'] . ' - ' . $displayname . '</div>';
        } else {
            $content .= '<div>' . sp_text('Guest') . '</div>';
        }
        $content .= '<div>' . $email . '</div><div>' . $post['poster_ip'] . '</div>';
        $out .= '<div class="spForumToolsEmail">';
        $out .= '<img class="spIcon" src="' . sp_find_icon(SPTHEMEICONSURL, 'sp_ToolsEmail.png') . '" alt="" title="" />';
        $title = sp_text("Users email and IP");
        $out .= '<a href="javascript:void(null)" onclick="spjDialogHtml(this, \'' . $content . '\', \'' . esc_js($title) . '\', 300, 0, \'center\');">' . $title . '</a>';
        $out .= '</div>';
    }
    if (sp_get_auth('pin_posts', $forum['forum_id'])) {
        $pintext = $post['post_pinned'] ? sp_text('Unpin this post') : sp_text('Pin this post');
        $out .= '<div class="spForumToolsPin">';
        $out .= '<img class="spIcon" src="' . sp_find_icon(SPTHEMEICONSURL, 'sp_ToolsPin.png') . '" alt="" title="" />';
        $ajaxUrl = SFHOMEURL . 'index.php?sp_ahah=admintools&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;action=pin-post&amp;post=' . $post['post_id'];
        $out .= "<a href='javascript:void(null)' onclick='spjPinPost(\"{$ajaxUrl}\");'>{$pintext}</a>";
        $out .= '</div>';
    }
    if ($spThisUser->admin) {
        $out .= '<div class="spForumToolsOrder">';
        $out .= '<img class="spIcon" src="' . sp_find_icon(SPTHEMEICONSURL, 'sp_ToolsSort.png') . '" alt="" title="" />';
        $site = SFHOMEURL . 'index.php?sp_ahah=admintools&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;action=sort-topic&amp;topicid=' . $topic['topic_id'];
        $out .= '<a href="javascript:void(null)" onclick="spjLoadTool(\'' . $site . '\', \'spMainContainer\', \'\');">' . sp_text('Reverse sort this topic') . '</a>';
        $out .= '</div>';
    }
    if (sp_get_auth('edit_any_post', $forum['forum_id']) || $post['user_id'] == $spThisUser->ID && (sp_get_auth('edit_own_posts_forever', $forum['forum_id']) || sp_get_auth('edit_own_posts_reply', $forum['forum_id']) && $last)) {
        $out .= '<div class="spForumToolsEdit">';
        $out .= '<img class="spIcon" src="' . sp_find_icon(SPTHEMEICONSURL, 'sp_ToolsEdit.png') . '" alt="" title="" />';
        $out .= '<a href="javascript:document.admineditpost' . $post['post_id'] . '.submit();">' . sp_text('Edit this post') . '</a>';
        $out .= '<form action="' . sp_build_url($forum['forum_slug'], $topic['topic_slug'], $page, $post['post_id'], $post['post_index']) . '" method="post" name="admineditpost' . $post['post_id'] . '">';
        $out .= '<input type="hidden" name="postedit" value="' . $post['post_id'] . '" />';
        $out .= '</form>';
        $out .= '</div>';
    }
    if (sp_get_auth('delete_any_post', $post['forum_id']) || sp_get_auth('delete_own_posts', $forum['forum_id']) && $spThisUser->ID == $post['user_id']) {
        $out .= '<div class="spForumToolsDelete">';
        $out .= '<img class="spIcon" src="' . sp_find_icon(SPTHEMEICONSURL, 'sp_ToolsDelete.png') . '" alt="" title="" />';
        $msg = esc_js(sp_text('Are you sure you want to delete this post?'));
        $ajaxUrl = SFHOMEURL . 'index.php?sp_ahah=admintools&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;action=delete-post&amp;killpost=' . $post['post_id'] . '&amp;killposttopic=' . $post['topic_id'] . '&amp;killpostforum=' . $post['forum_id'] . '&amp;killpostposter=' . $post['user_id'] . '&amp;page=' . $page;
        $out .= "<a href='javascript:void(null)' onclick='spjDeletePost(\"{$ajaxUrl}\", {$post['post_id']}, {$post['topic_id']});'>";
        $out .= sp_text('Delete this post');
        $out .= '</a>';
        $out .= '</div>';
    }
    if (sp_get_auth('move_posts', $post['forum_id'])) {
        $out .= '<div class="spForumToolsMove">';
        $out .= '<img class="spIcon" src="' . sp_find_icon(SPTHEMEICONSURL, 'sp_ToolsMove.png') . '" alt="" title="" />';
        $site = SFHOMEURL . 'index.php?sp_ahah=admintools&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;action=move-post&amp;id=' . $post['topic_id'] . '&amp;pid=' . $post['post_id'] . '&amp;pix=' . $post['post_index'];
        $title = sp_text('Move this post');
        $out .= '<a rel="nofollow" href="javascript:void(null)" onclick="spjDialogAjax(this, \'' . $site . '\', \'' . esc_js($title) . '\', 400, 0, \'center\');">' . $title . '</a>';
        $out .= '</div>';
    }
    if (sp_get_auth('reassign_posts', $post['forum_id'])) {
        $out .= '<div class="spForumToolsReassign">';
        $out .= '<img class="spIcon" src="' . sp_find_icon(SPTHEMEICONSURL, 'sp_ToolsReassign.png') . '" alt="" title="" />';
        $site = SFHOMEURL . 'index.php?sp_ahah=admintools&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;action=reassign&amp;id=' . $post['topic_id'] . '&amp;pid=' . $post['post_id'] . '&amp;uid=' . $post['user_id'];
        $title = sp_text('Reassign This Post');
        $out .= '<a rel="nofollow" href="javascript:void(null)" onclick="spjDialogAjax(this, \'' . $site . '\', \'' . esc_js($title) . '\', 400, 0, \'center\');">' . $title . '</a>';
        $out .= '</div>';
    }
    if ($spThisUser->admin || $spThisUser->moderator) {
        $out .= '<div class="spForumToolsNofity">';
        $out .= '<img class="spIcon" src="' . sp_find_icon(SPTHEMEICONSURL, 'sp_ToolsNotify.png') . '" alt="" title="" />';
        $site = SFHOMEURL . 'index.php?sp_ahah=admintools&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;action=notify&amp;pid=' . $post['post_id'];
        $title = sp_text('Notify User');
        $out .= '<a rel="nofollow" href="javascript:void(null)" onclick="spjDialogAjax(this, \'' . $site . '\', \'' . esc_js($title) . '\', 400, 0, \'center\');">' . $title . '</a>';
        $out .= '</div>';
    }
    if ($spThisUser->admin || $spThisUser->moderator) {
        $out .= '<div class="spForumToolsProperties">';
        $out .= '<img class="spIcon" src="' . sp_find_icon(SPTHEMEICONSURL, 'sp_ToolsProperties.png') . '" alt="" title="" />';
        $site = SFHOMEURL . 'index.php?sp_ahah=admintools&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;action=properties&amp;forum=' . $post['forum_id'] . '&amp;topic=' . $post['topic_id'] . '&amp;post=' . $post['post_id'];
        $title = sp_text('View properties');
        $out .= '<a rel="nofollow" href="javascript:void(null)" onclick="spjDialogAjax(this, \'' . $site . '\', \'' . esc_js($title) . '\', 400, 0, \'center\');">' . $title . '</a>';
        $out .= '</div>';
    }
    $out = apply_filters('sph_add_post_tool', $out, $post, $forum, $topic, $page, $postnum, $useremail, $guestemail, $displayname);
    $out .= '</div>';
    $out = apply_filters('sph_post_tools', $out, $post, $forum, $topic, $page, $postnum, $useremail, $guestemail, $displayname);
    return $out;
}
function spa_forums_edit_forum_form($forum_id)
{
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	jQuery('#forumrow-<?php 
    echo $forum_id;
    ?>
').addClass('inForm');
    	spjAjaxForm('sfforumedit<?php 
    echo $forum_id;
    ?>
', 'sfreloadfb');
    });
</script>
<?php 
    global $spPaths, $tab;
    $forum = spdb_table(SFFORUMS, "forum_id={$forum_id}", 'row');
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=editforum';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfforumedit<?php 
    echo $forum->forum_id;
    ?>
" name="sfforumedit<?php 
    echo $forum->forum_id;
    ?>
">
<?php 
    echo sp_create_nonce('forum-adminform_forumedit');
    spa_paint_open_tab(spa_text('Forums') . ' - ' . spa_text('Manage Groups and Forums'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Forum Details'), false);
    $subforum = $forum->parent ? true : false;
    echo "<input type='hidden' name='cgroup_id' value='{$forum->group_id}' />";
    echo "<input type='hidden' name='cparent' value='{$forum->parent}' />";
    echo "<input type='hidden' name='cchildren' value='{$forum->children}' />";
    if (!$subforum && empty($forum->children)) {
        $mess = sp_text('This is a top-level forum with no sub-forums and on this panel you can change the forum Group it is a member of. If changed it will be moved to the target Forum Group.');
    } elseif (!$subforum && !empty($forum->children)) {
        $mess = sp_text('This is a top level forum with designated sub-forums and on this panel you can change the forum Group it is a member of. If changed it will be moved, along with the sub-forums, to the target Forum Group.');
    } elseif ($subforum && empty($forum->children)) {
        $mess = sp_text('This is a sub-forum and on this panel you can change the forum parent it belongs to. If changed it will be moved to become a sub-forum of the target Forum.');
    } else {
        $mess = sp_text('This is a sub-forum and also a parent to other sub-forums and on this panel you can change the forum parent it belongs to. If changed it will be moved, along with the sub-forums, to the target Forum.');
    }
    echo '<div class="sfoptionerror spaceabove">';
    echo "<p><b>{$mess}</b></br>";
    echo sp_text('For more flexible Group/Forum ordering and sub-forum promotion and demotion, please use the drag and drop interface on the Order Groups and Forums admin panel from the Forums Menu - or the Order Forums panel at Group level.') . '</p>';
    echo '</div>';
    # Top level forum...
    $style = $subforum ? ' style="display:none"' : ' style="display:block"';
    echo "<div {$style}>";
    spa_paint_select_start(spa_text('The group this forum belongs to'), 'group_id', '');
    echo spa_create_group_select($forum->group_id);
    spa_paint_select_end();
    echo '</div>';
    # sub-forum...
    $style = $subforum ? ' style="display:block"' : ' style="display:none"';
    echo "<div {$style}>";
    spa_paint_select_start(spa_text('Parent forum this subforum belongs to'), 'parent', '');
    echo spa_create_forum_select($forum->parent);
    spa_paint_select_end();
    echo '</div>';
    spa_paint_input(spa_text('Forum name'), 'forum_name', sp_filter_title_display($forum->forum_name), false, true);
    echo '<input type="hidden" name="forum_id" value="' . $forum->forum_id . '" />';
    $target = 'cforum_slug';
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums&amp;sfnonce=' . wp_create_nonce('forum-ahah');
    echo "<div class='sp-form-row'>\n";
    echo "<div class='wp-core-ui sflabel sp-label-40'>" . spa_text('Forum slug') . ':</div>';
    echo '<input type="text" class="wp-core-ui sp-input-60" tabindex="' . $tab . '" name="cforum_slug" id="cforum_slug" value="' . esc_attr($forum->forum_slug) . '" onchange="spjSetForumSlug(this, \'' . $ahahURL . '\', \'' . $target . '\', \'edit\');" />';
    echo '<div class="clearboth"></div>';
    echo '</div>';
    $tab++;
    spa_paint_input(spa_text('Description'), 'forum_desc', sp_filter_text_edit($forum->forum_desc), false, true);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Forum Options'), false);
    $target = 'cforum_slug';
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums&amp;sfnonce=' . wp_create_nonce('forum-ahah');
    spa_paint_checkbox(spa_text('Locked'), 'forum_status', $forum->forum_status);
    spa_paint_checkbox(spa_text('Disable forum RSS feed so feed will not be generated'), 'forum_private', $forum->forum_rss_private);
    spa_paint_select_start(sprintf(spa_text('Featured Image for this forum %s(200px x 200px recommended)'), '<br>'), 'feature_image', '');
    spa_select_icon_dropdown('feature_image', spa_text('Select Feature Image'), SF_STORE_DIR . '/' . $spPaths['forum-images'] . '/', $forum->feature_image, false);
    spa_paint_select_end();
    echo '<div class="sfoptionerror spaceabove">';
    echo '<p><b>' . sp_text('Custom Icon Ordering') . '</b></br>';
    echo sp_text('When using custom forum or topic icons and multiple conditions exist, the following precedence is used:') . '</p>';
    echo sp_text('Locked') . '<br />';
    echo sp_text('Pinned') . '<br />';
    echo sp_text('Unread') . '<br />';
    echo sp_text('Custom') . '<br />';
    echo sp_text('Theme Default') . '<br />';
    echo '</div>';
    spa_paint_select_start(spa_text('Custom forum icon'), 'forum_icon', '');
    spa_select_icon_dropdown('forum_icon', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', $forum->forum_icon, false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom forum icon when new posts'), 'forum_icon_new', '');
    spa_select_icon_dropdown('forum_icon_new', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', $forum->forum_icon_new, false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom forum icon when locked'), 'forum_icon_locked', '');
    spa_select_icon_dropdown('forum_icon_locked', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', $forum->forum_icon_locked, false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom topic icon'), 'topic_icon', '');
    spa_select_icon_dropdown('topic_icon', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', $forum->topic_icon, false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom topic icon when new posts'), 'topic_icon_new', '');
    spa_select_icon_dropdown('topic_icon_new', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', $forum->topic_icon_new, false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom topic icon when locked'), 'topic_icon_locked', '');
    spa_select_icon_dropdown('topic_icon_locked', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', $forum->topic_icon_locked, false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom topic icon when pinned'), 'topic_icon_pinned', '');
    spa_select_icon_dropdown('topic_icon_pinned', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', $forum->topic_icon_pinned, false);
    spa_paint_select_end();
    spa_paint_input(spa_text('Replacement external RSS URL') . '<br />' . spa_text('Default') . ': <strong>' . sp_build_url($forum->forum_slug, '', 0, 0, 0, 1) . '</strong>', 'forum_rss', sp_filter_url_display($forum->forum_rss), false, true);
    spa_paint_input(spa_text('Custom meta keywords (SEO option must be enabled)'), 'forum_keywords', '', false, true);
    spa_paint_wide_textarea('Special forum message to be displayed above forums', 'forum_message', sp_filter_text_edit($forum->forum_message));
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Extended Forum Options'), false);
    # As added by plugins
    do_action('sph_forum_edit_forum_options', $forum);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_close_container();
    ?>
		<div class="sfform-submit-bar">
    		<input type="submit" class="button-primary" id="sfforumedit<?php 
    echo $forum->forum_id;
    ?>
" name="sfforumedit<?php 
    echo $forum->forum_id;
    ?>
" value="<?php 
    spa_etext('Update Forum');
    ?>
" />
    		<input type="button" class="button-primary" onclick="javascript:jQuery('#forum-<?php 
    echo $forum->forum_id;
    ?>
').html('');jQuery('#forumrow-<?php 
    echo $forum_id;
    ?>
').removeClass('inForm');" id="sfforumedit<?php 
    echo $forum->forum_id;
    ?>
" name="editforumcancel<?php 
    echo $forum->forum_id;
    ?>
" value="<?php 
    spa_etext('Cancel');
    ?>
" />
		</div>
	<?php 
    spa_paint_close_tab();
    ?>
	</form>
	<div class="sfform-panel-spacer"></div>
<?php 
}
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
        # 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;
    }
}
    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;
    }
Exemple #28
0
function sp_move_post_notice($m, $a)
{
    global $spGlobals, $spVars, $spThisUser;
    if (array_key_exists('post_move', $spGlobals) && sp_get_auth('move_posts', $spVars['forumid'])) {
        $m .= "<div id='spPostMove'>\n";
        $m .= "<p class='" . $a['textClass'] . "'>";
        if ($spVars['pageview'] != 'topic' || $spVars['pageview'] == 'topic' && $spVars['topicid'] == $spGlobals['post_move']['post_move']['oldtopicid']) {
            $m .= sp_text('You have posts queued to be moved') . ' - ' . sp_text('Navigate to the target topic to complete the move operation');
            $m .= '</p>';
            $m .= '<form action="' . sp_build_url($spVars['forumslug'], $spVars['topicslug'], 1, 0) . '" method="post" name="movepostform">';
            $m .= '<span>';
            $m .= '<input type="submit" class="spSubmit" name="cancelpostmove" value="' . sp_text('Cancel') . '" />';
            $m .= '</span></form></div>';
        } else {
            $p = $spGlobals['post_move']['post_move'];
            $m .= sp_text('You have posts queued to be moved') . ' - ' . sp_text('Click on the move button to move to this topic');
            $m .= "</p>\n";
            # create hidden form
            $m .= '<form action="' . sp_build_url($spVars['forumslug'], $spVars['topicslug'], 1, 0) . '" method="post" name="movepostform">';
            $m .= '<input type="hidden" name="postid" value="' . $p['postid'] . '" />';
            $m .= '<input type="hidden" name="oldtopicid" value="' . $p['oldtopicid'] . '" />';
            $m .= '<input type="hidden" name="oldforumid" value="' . $p['oldforumid'] . '" />';
            $m .= '<input type="hidden" name="oldpostindex" value="' . $p['oldpostindex'] . '" />';
            $m .= '<input type="hidden" name="moveop" value="' . $p['moveop'] . '" />';
            $m .= '<input type="hidden" name="idlist" value="' . $p['idlist'] . '" />';
            $m .= '<input type="hidden" name="moveop" value="' . $p['moveop'] . '" />';
            $m .= '<input type="hidden" name="forumid" value="' . $spVars['forumid'] . '" />';
            $m .= '<input type="hidden" name="newtopicid" value="' . $spVars['topicid'] . '" />';
            $m .= '<span>';
            $m .= '<input type="submit" class="spSubmit" name="makepostmove3" value="' . sp_text('Move') . '" />';
            $m .= '<input type="submit" class="spSubmit" name="cancelpostmove" value="' . sp_text('Cancel') . '" />';
            $m .= '</span></form></div>';
        }
    }
    return $m;
}
function sp_TopicIndexPostPageLinks($args = '', $toolTip = '')
{
    global $spThisForum, $spThisTopic, $spGlobals;
    $posts_per_page = $spGlobals['display']['posts']['perpage'];
    if ($posts_per_page >= $spThisTopic->post_count) {
        return '';
    }
    $defs = array('tagId' => 'spTopicIndexPostPageLinks%ID%', 'tagClass' => 'spInRowPageLinks', 'icon' => 'sp_ArrowRightSmall.png', 'iconClass' => 'spIconSmall', 'pageLinkClass' => 'spInRowForumPageLink', 'showLinks' => 4, 'echo' => 1);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_TopicIndexPostPageLinks_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $tagId = esc_attr($tagId);
    $tagClass = esc_attr($tagClass);
    $icon = sanitize_file_name($icon);
    $iconClass = esc_attr($iconClass);
    $pageLinkClass = esc_attr($pageLinkClass);
    $showLinks = (int) $showLinks;
    $toolTip = esc_attr($toolTip);
    $echo = (int) $echo;
    $tagId = str_ireplace('%ID%', $spThisTopic->topic_id, $tagId);
    $out = "<div id='{$tagId}' class='{$tagClass}'>\n";
    $total_pages = $spThisTopic->post_count / $posts_per_page;
    if (!is_int($total_pages)) {
        $total_pages = intval($total_pages) + 1;
    }
    $total_pages > $showLinks ? $max_count = $showLinks : ($max_count = $total_pages);
    for ($x = 1; $x <= $max_count; $x++) {
        $out .= "<a class='{$pageLinkClass} vtip' href='" . sp_build_url($spThisForum->forum_slug, $spThisTopic->topic_slug, $x, 0) . "' title='" . str_ireplace('%PAGE%', $x, $toolTip) . "'>{$x}</a>\n";
    }
    if ($total_pages > $showLinks) {
        if (!empty($icon)) {
            $out .= "<img src='" . sp_find_icon(SPTHEMEICONSURL, $icon) . "' class='{$iconClass}' alt=''/>\n";
        }
        $out .= "<a class='{$pageLinkClass} vtip' href='" . sp_build_url($spThisForum->forum_slug, $spThisTopic->topic_slug, $total_pages, 0) . "' title='" . str_ireplace('%PAGE%', $total_pages, $toolTip) . "'>{$total_pages}</a>\n";
    }
    $out .= "</div>\n";
    $out = apply_filters('sph_TopicIndexPostPageLinks', $out, $a);
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}
function sp_do_sp_AuthorPostsTag($args = '')
{
    #check if forum displayed
    if (sp_abort_display_forum()) {
        return;
    }
    $defs = array('tagId' => 'spAuthorPostsTag', 'tagClass' => 'spLinkTag', 'authorId' => '', 'showForum' => 1, 'showDate' => 1, 'limit' => 5, 'listTags' => 0, 'echo' => 1);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_AuthorPostsTag_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $tagId = esc_attr($tagId);
    $tagClass = esc_attr($tagClass);
    $authorId = (int) $authorId;
    $showForum = (int) $showForum;
    $showDate = (int) $showDate;
    $limit = (int) $limit;
    $listTags = (int) $listTags;
    $echo = (int) $echo;
    if (empty($authorId)) {
        return;
    }
    sp_forum_api_support();
    if ($limit == 0) {
        $limit = '';
    }
    # limit to viewable forums based on permissions
    $where = SFPOSTS . '.user_id = ' . $authorId . ' AND ' . SFPOSTS . '.post_status=0 ';
    $forum_ids = sp_get_forum_memberships();
    # create where clause based on forums that current user can view
    if ($forum_ids != '') {
        $where .= "AND " . SFPOSTS . ".forum_id IN (" . implode(",", $forum_ids) . ")";
    } else {
        return '';
    }
    $spdb = new spdbComplex();
    $spdb->table = SFPOSTS;
    $spdb->distinct = true;
    $spdb->fields = SFPOSTS . '.post_id, ' . SFPOSTS . '.forum_id, ' . SFPOSTS . '.topic_id, ' . spdb_zone_datetime('post_date') . ',
							  post_index, forum_slug, forum_name, topic_slug, topic_name';
    $spdb->join = array(SFTOPICS . ' ON ' . SFPOSTS . '.topic_id = ' . SFTOPICS . '.topic_id', SFFORUMS . ' ON ' . SFPOSTS . '.forum_id = ' . SFFORUMS . '.forum_id');
    $spdb->where = $where;
    $spdb->orderby = 'post_date DESC';
    $spdb->limits = $limit;
    $sfposts = $spdb->select();
    if (!$listTags) {
        $out = "<div id='{$tagId}' class='{$tagClass}'>";
        $open = '<div>';
        $close = '</div>';
    } else {
        $out = "<ul id='{$tagId}' class='{$tagClass}'>";
        $open = '<li>';
        $close = '</li>';
    }
    if ($sfposts) {
        foreach ($sfposts as $sfpost) {
            $out .= $open;
            if ($showForum) {
                $out .= sp_filter_title_display($sfpost->forum_name) . '<br />';
            }
            $out .= '<a href="' . sp_build_url($sfpost->forum_slug, $sfpost->topic_slug, 0, $sfpost->post_id, $sfpost->post_index) . '">' . sp_filter_title_display($sfpost->topic_name) . '</a><br />' . "\n";
            if ($showDate) {
                $out .= sp_date('d', $sfpost->post_date) . '<br />';
            }
            $out .= $close;
        }
    } else {
        $out .= $open . __('No posts by this author', 'sp-ttags') . $close;
    }
    if (!$listTags) {
        $out .= '</div>';
    } else {
        $out .= '</ul>';
    }
    $out = apply_filters('sph_AuthorPostsTag', $out);
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}