function sp_TopicIndexLastPost($args = '', $label = '')
{
    global $spThisTopic;
    $defs = array('tagId' => 'spTopicIndexLastPost%ID%', 'tagClass' => 'spInRowPostLink', 'labelClass' => 'spInRowLabel', 'infoClass' => 'spInRowInfo', 'linkClass' => 'spInRowLastPostLink', 'iconClass' => 'spIcon', 'icon' => 'sp_ArrowRight.png', 'tip' => 1, 'nicedate' => 1, 'date' => 0, 'time' => 0, 'user' => 1, 'stackuser' => 1, 'stackdate' => 0, 'truncateUser' => 0, 'itemBreak' => '<br />', 'echo' => 1, 'get' => 0);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_TopicIndexLastPost_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $tagId = esc_attr($tagId);
    $tagClass = esc_attr($tagClass);
    $labelClass = esc_attr($labelClass);
    $infoClass = esc_attr($infoClass);
    $linkClass = esc_attr($linkClass);
    $iconClass = esc_attr($iconClass);
    $icon = sanitize_file_name($icon);
    $tip = (int) $tip;
    $nicedate = (int) $nicedate;
    $date = (int) $date;
    $time = (int) $time;
    $user = (int) $user;
    $stackuser = (int) $stackuser;
    $stackdate = (int) $stackdate;
    $truncateUser = (int) $truncateUser;
    $icon = $icon;
    $echo = (int) $echo;
    $get = (int) $get;
    $tagId = str_ireplace('%ID%', $spThisTopic->topic_id, $tagId);
    if ($tip && !empty($spThisTopic->last_post_tip)) {
        $title = "title='{$spThisTopic->last_post_tip}'";
        $linkClass .= ' vtip';
    } else {
        $title = '';
    }
    $stackuser ? $ulb = '<br />' : ($ulb = '&nbsp;');
    $stackdate ? $dlb = '<br />' : ($dlb = ' - ');
    $out = "<div id='{$tagId}' class='{$tagClass}'>\n";
    $out .= "<span class='{$labelClass}'>" . sp_filter_title_display($label) . "\n";
    # Link to post
    $out .= "<a class='{$linkClass}' {$title} href='{$spThisTopic->last_post_permalink}'>\n";
    if (!empty($icon)) {
        $out .= "<img src='" . sp_find_icon(SPTHEMEICONSURL, $icon) . "' class='{$iconClass}' alt=''/>\n";
    }
    $out .= "</a></span>\n";
    # user
    $poster = sp_build_name_display($spThisTopic->last_user_id, sp_truncate($spThisTopic->last_display_name, $truncateUser));
    if (empty($poster)) {
        $poster = sp_truncate($spThisTopic->last_guest_name, $truncateUser);
    }
    if ($user) {
        $out .= "<span class='{$labelClass}'>{$ulb}{$poster}</span>";
    }
    $out .= $itemBreak;
    if ($get) {
        $getData = new stdClass();
        $getData->permalink = $spThisTopic->first_post_permalink;
        $getData->topic_name = $spThisTopic->topic_name;
        $getData->post_date = $spThisTopic->last_post_date;
        $getData->tooltip = $spThisTopic->last_post_tip;
        $getData->user = $poster;
        return $getData;
    }
    # date/time
    if ($nicedate && isset($spThisTopic->last_post_date)) {
        $out .= "<span class='{$labelClass}'>" . sp_nicedate($spThisTopic->last_post_date) . "</span>\n";
    } else {
        if ($date && isset($spThisTopic->last_post_date)) {
            $out .= "<span class='{$labelClass}'>" . sp_date('d', $spThisTopic->last_post_date);
            if ($time) {
                $out .= $dlb . sp_date('t', $spThisTopic->last_post_date);
            }
            $out .= "</span>\n";
        }
    }
    $out .= "</div>\n";
    $out = apply_filters('sph_TopicIndexLastPost', $out, $a);
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}
function sp_ForumIndexLastPost($args = '', $lastPostLabel = '', $noTopicsLabel = '')
{
    global $spThisForum;
    $defs = array('tagId' => 'spForumIndexLastPost%ID%', 'tagClass' => 'spInRowPostLink', 'labelClass' => 'spInRowLabel', 'infoClass' => 'spInRowInfo', 'linkClass' => 'spInRowLastPostLink', 'includeSubs' => 1, 'tip' => 1, 'order' => 'UTD', 'nicedate' => 1, 'date' => 0, 'time' => 0, 'stackdate' => 0, 'user' => 1, 'truncate' => 0, 'truncateUser' => 0, 'itemBreak' => '<br />', 'echo' => 1, 'get' => 0);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_ForumIndexLastPost_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $tagId = esc_attr($tagId);
    $tagClass = esc_attr($tagClass);
    $labelClass = esc_attr($labelClass);
    $infoClass = esc_attr($infoClass);
    $linkClass = esc_attr($linkClass);
    $includeSubs = (int) $includeSubs;
    $tip = (int) $tip;
    $order = esc_attr($order);
    $nicedate = (int) $nicedate;
    $date = (int) $date;
    $time = (int) $time;
    $stackdate = (int) $stackdate;
    $user = (int) $user;
    $truncate = (int) $truncate;
    $truncateUser = (int) $truncateUser;
    $echo = (int) $echo;
    $get = (int) $get;
    if ($includeSubs && $spThisForum->forum_id_sub == 0) {
        $includeSubs = 0;
    }
    $postCount = $includeSubs ? $spThisForum->post_count_sub : $spThisForum->post_count;
    if ($postCount) {
        $tagId = str_ireplace('%ID%', $spThisForum->forum_id, $tagId);
        $posttip = $includeSubs ? $spThisForum->post_tip_sub : $spThisForum->post_tip;
        if ($tip && !empty($posttip)) {
            $title = "title='{$posttip}'";
            $linkClass .= ' vtip';
        } else {
            $title = '';
        }
        $stackdate ? $dlb = '<br />' : ($dlb = ' - ');
        # user
        $poster = $includeSubs ? sp_build_name_display($spThisForum->user_id_sub, sp_truncate($spThisForum->display_name_sub, $truncateUser)) : sp_build_name_display($spThisForum->user_id, sp_truncate($spThisForum->display_name, $truncateUser));
        if (empty($poster)) {
            $poster = $includeSubs ? sp_truncate($spThisForum->guest_name_sub, $truncateUser) : sp_truncate($spThisForum->guest_name, $truncateUser);
        }
        # other items
        $permalink = $includeSubs ? $spThisForum->post_permalink_sub : $spThisForum->post_permalink;
        $topicname = $includeSubs ? sp_truncate($spThisForum->topic_name_sub, $truncate) : sp_truncate($spThisForum->topic_name, $truncate);
        $postdate = $includeSubs ? $spThisForum->post_date_sub : $spThisForum->post_date;
        if ($get) {
            $getData = new stdClass();
            $getData->permalink = $permalink;
            $getData->topic_name = $topicname;
            $getData->post_date = $postdate;
            $getData->user = $poster;
            return $getData;
        }
        $U = $poster;
        $T = "<a class='{$linkClass}' {$title} href='{$permalink}'>{$topicname}</a>";
        if ($nicedate) {
            $D = sp_nicedate($postdate);
        } else {
            if ($date) {
                $D = sp_date('d', $postdate);
                if ($time) {
                    $D .= $dlb . sp_date('t', $postdate);
                }
            }
        }
    } else {
        if ($get) {
            $getData = new stdClass();
            return $getData;
        }
    }
    $out = "<div id='{$tagId}' class='{$tagClass}'>\n";
    if ($postCount) {
        $out .= "<span class='{$labelClass}'>" . sp_filter_title_display($lastPostLabel) . " \n";
        for ($x = 0; $x < strlen($order); $x++) {
            $i = substr($order, $x, 1);
            switch ($i) {
                case 'U':
                    if ($user) {
                        if ($x != 0) {
                            $out .= "<span class='{$labelClass}'>";
                        }
                        $out .= $U . "</span>\n";
                    }
                    if ($x != strlen($order) - 1) {
                        if (substr($order, $x + 1, 1) != 'L') {
                            $out .= "<span class='{$labelClass}'>{$itemBreak}</span>";
                        }
                    }
                    break;
                case 'T':
                    if ($x == 0) {
                        $out .= $itemBreak . "</span>";
                    }
                    $out .= "<span class='{$linkClass}'>";
                    $out .= $T . "</span>\n";
                    if ($x != strlen($order) - 1) {
                        if (substr($order, $x + 1, 1) != 'L') {
                            $out .= "<span class='{$labelClass}'>{$itemBreak}</span>";
                        }
                    }
                    break;
                case 'D':
                    if ($x != 0) {
                        $out .= "<span class='{$labelClass}'>";
                    }
                    $out .= $D . "</span>\n";
                    if ($x != strlen($order) - 1) {
                        if (substr($order, $x + 1, 1) != 'L') {
                            $out .= "<span class='{$labelClass}'>{$itemBreak}</span>";
                        }
                    }
                    break;
                case 'L':
                    $out .= '<br />';
                    break;
            }
        }
    } else {
        $out .= "<span class='{$labelClass}'>" . sp_filter_title_display($noTopicsLabel) . " \n";
        $out .= "</span>\n";
    }
    $out .= "</div>\n";
    $out = apply_filters('sph_ForumIndexLastPost', $out, $a);
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}
function sp_PostIndexUserDate($args = '')
{
    global $spThisPost, $spThisPostUser;
    $defs = array('tagId' => 'spPostIndexUserDate%ID%', 'tagClass' => 'spPostUserDate', 'nicedate' => 0, 'date' => 1, 'time' => 1, 'stackdate' => 1, 'echo' => 1, 'get' => 0);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_PostIndexUserDate_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $tagId = esc_attr($tagId);
    $tagClass = esc_attr($tagClass);
    $nicedate = (int) $nicedate;
    $date = (int) $date;
    $time = (int) $time;
    $stackdate = (int) $stackdate;
    $echo = (int) $echo;
    $get = (int) $get;
    $stackdate ? $dlb = '<br />' : ($dlb = ' - ');
    $tagId = str_ireplace('%ID%', $spThisPost->post_id, $tagId);
    if ($get) {
        return $spThisPost->post_date;
    }
    $out = "<div id='{$tagId}' class='{$tagClass}'>";
    # date/time
    if ($nicedate) {
        $out .= sp_nicedate($spThisPost->post_date);
    } else {
        if ($date) {
            $out .= sp_date('d', $spThisPost->post_date);
            if ($time) {
                $out .= $dlb . sp_date('t', $spThisPost->post_date);
            }
        }
    }
    $out .= "</div>\n";
    $out = apply_filters('sph_PostIndexUserDate', $out, $a);
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}
function sp_do_sp_UnansweredPostsTag($args = '')
{
    #check if forum displayed
    if (sp_abort_display_forum()) {
        return;
    }
    $defs = array('tagId' => 'spUnansweredPostsTag', 'tagClass' => 'spListTag', 'listId' => 'spListItemTag%ID%', 'listClass' => 'spListItemTag', 'linkClass' => 'spLinkTag', 'textClass' => 'spTextTag', 'avatarClass' => 'spAvatarTag', 'listTags' => 1, 'forumIds' => '', 'limit' => 5, 'itemOrder' => 'FTUD', 'linkScope' => 'forum', 'beforeForum' => __('Forum: ', 'sp-ttags'), 'afterForum' => '<br />', 'beforeTopic' => __('Topic: ', 'sp-ttags'), 'afterTopic' => '<br />', 'beforeUser' => __('By: ', 'sp-ttags'), 'afterUser' => '', 'beforeDate' => '&nbsp;-', 'afterDate' => '', 'avatarSize' => 25, 'niceDate' => 1, 'postTip' => 1, 'truncate' => 0, 'echo' => 1);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_UnansweredPostsTag_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $tagId = esc_attr($tagId);
    $tagClass = esc_attr($tagClass);
    $listClass = esc_attr($listClass);
    $listId = esc_attr($listId);
    $linkClass = esc_attr($linkClass);
    $textClass = esc_attr($textClass);
    $avatarClass = esc_attr($avatarClass);
    $listTags = (int) $listTags;
    $forumIds = esc_attr($forumIds);
    $limit = (int) $limit;
    $itemOrder = esc_attr($itemOrder);
    $linkScope = esc_attr($linkScope);
    $beforeForum = sp_filter_title_display($beforeForum);
    $afterForum = sp_filter_title_display($afterForum);
    $beforeTopic = sp_filter_title_display($beforeTopic);
    $afterTopic = sp_filter_title_display($afterTopic);
    $beforeUser = sp_filter_title_display($beforeUser);
    $afterUser = sp_filter_title_display($afterUser);
    $beforeDate = sp_filter_title_display($beforeDate);
    $afterDate = sp_filter_title_display($afterDate);
    $avatarSize = (int) $avatarSize;
    $niceDate = (int) $niceDate;
    $postTip = (int) $postTip;
    $truncate = (int) $truncate;
    $echo = (int) $echo;
    sp_forum_api_support();
    global $spPostList, $spThisPostList;
    $where = SFTOPICS . '.post_count=1';
    # do we have forum ids specified?
    $where .= !empty($forumIds) ? ' AND ' . SFPOSTS . '.forum_id IN (' . $forumIds . ')' : '';
    $spPostList = new spPostList($where, SFPOSTS . '.post_id DESC', $limit);
    if (empty($spPostList)) {
        return;
    }
    if (!empty($beforeForum)) {
        $beforeForum = trim($beforeForum) . ' ';
    }
    if (!empty($beforeTopic)) {
        $beforeTopic = trim($beforeTopic) . ' ';
    }
    if (!empty($beforeUser)) {
        $beforeUser = trim($beforeUser) . ' ';
    }
    if (!empty($beforeDate)) {
        $beforeDate = trim($beforeDate) . ' ';
    }
    if (!empty($afterForum)) {
        $afterForum = ' ' . trim($afterForum);
    }
    if (!empty($afterTopic)) {
        $afterTopic = ' ' . trim($afterTopic);
    }
    if (!empty($afterUser)) {
        $afterUser = '******' . trim($afterUser);
    }
    if (!empty($afterDate)) {
        $afterDate = ' ' . trim($afterDate);
    }
    $fLink = $tLink = $aLink = false;
    if ($linkScope == 'forum') {
        $fLink = $tLink = true;
    }
    if ($linkScope == 'all') {
        $aLink = true;
    }
    # Start building dislay
    $out = $listTags ? "<ul id='{$tagId}' class='{$tagClass}'>" : "<div id='{$tagId}' class='{$tagClass}'>";
    # start the loop
    if (sp_has_postlist()) {
        while (sp_loop_postlist()) {
            sp_the_postlist();
            $thisId = str_ireplace('%ID%', $spThisPostList->topic_id, $listId);
            $out .= $listTags ? "<li id='{$thisId}' class='{$listClass}'>" : "<div id='{$thisId}' class='{$listClass}'>";
            $title = $postTip ? "title='{$spThisPostList->post_tip}'" : '';
            if ($aLink) {
                $out .= "<a class='{$linkClass}' {$title} href='{$spThisPostList->post_permalink}'>";
            }
            for ($x = 0; $x < strlen($itemOrder); $x++) {
                switch (substr($itemOrder, $x, 1)) {
                    case 'F':
                        # Forum
                        $out .= $beforeForum;
                        if ($fLink) {
                            $out .= "<a class='{$linkClass}' href='{$spThisPostList->forum_permalink}'>";
                        }
                        $out .= sp_truncate($spThisPostList->forum_name, $truncate);
                        if ($fLink) {
                            $out .= '</a>';
                        }
                        $out .= $afterForum;
                        break;
                    case 'T':
                        # Topic
                        $out .= $beforeTopic;
                        if ($tLink) {
                            $out .= "<a class='{$linkClass}' {$title} href='{$spThisPostList->post_permalink}'>";
                        }
                        $out .= sp_truncate($spThisPostList->topic_name, $truncate);
                        if ($tLink) {
                            $out .= '</a>';
                        }
                        $out .= $afterTopic;
                        break;
                    case 'A':
                        # Avatar
                        $spx = $avatarSize + 10 . 'px';
                        $out .= sp_UserAvatar("tagClass={$avatarClass}&size={$avatarSize}&link=none&context=user&echo=0", $spThisPostList);
                        break;
                    case 'U':
                        # user
                        $out .= "<span class='{$textClass}'>{$spThisPostList->display_name}{$afterUser}</span>";
                        break;
                    case 'D':
                        # date
                        if ($niceDate) {
                            $out .= "<span class='{$textClass}'>" . $beforeDate . sp_nicedate($spThisPostList->post_date) . "{$afterDate}</span>\n";
                        } else {
                            $out .= "<span class='{$textClass}'>" . $beforeDate . sp_date('d', $spThisPostList->post_date) . "{$afterDate}</span>\n";
                        }
                        break;
                    default:
                        # Invalid code
                        $out .= '<br />' . __('Invalid Tag Code Found', 'sp-ttags') . '<br />';
                        break;
                }
            }
            if ($aLink) {
                $out .= '</a>';
            }
            $out .= $listTags ? '</li>' : '</div>';
        }
    }
    $out .= $listTags ? '</ul>' : '</div>';
    $out = apply_filters('sph_UnansweredPostsTag', $out);
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}
function sp_ListFirstPost($args = '', $label = '')
{
    global $spThisListTopic;
    $defs = array('tagId' => 'spListFirstPost%ID%', 'tagClass' => 'spListPostLink', 'labelClass' => 'spListLabel', 'linkClass' => 'spLink', 'iconClass' => 'spIcon', 'icon' => 'sp_ArrowRight.png', 'labelLink' => 0, 'tip' => 1, 'niceDate' => 1, 'date' => 0, 'time' => 0, 'user' => 1, 'truncateUser' => 0, 'break' => 0, 'echo' => 1, 'get' => 0);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_ListFirstPost_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $tagId = esc_attr($tagId);
    $tagClass = esc_attr($tagClass);
    $labelClass = esc_attr($labelClass);
    $linkClass = esc_attr($linkClass);
    $iconClass = esc_attr($iconClass);
    $labelLink = (int) $labelLink;
    $tip = (int) $tip;
    $niceDate = (int) $niceDate;
    $date = (int) $date;
    $time = (int) $time;
    $user = (int) $user;
    $truncateUser = (int) $truncateUser;
    $break = (int) $break;
    $icon = sanitize_file_name($icon);
    $echo = (int) $echo;
    $get = (int) $get;
    $tagId = str_ireplace('%ID%', $spThisListTopic->topic_id, $tagId);
    if ($tip && !empty($spThisListTopic->first_post_tip)) {
        $title = "title='{$spThisListTopic->first_post_tip}'";
        $linkClass .= '';
    } else {
        $title = '';
    }
    $sp = '&nbsp;';
    $out = "<div id='{$tagId}' class='{$tagClass}'>\n";
    if ($labelLink) {
        $out .= "<a class='{$linkClass}' {$title} href='{$spThisListTopic->first_post_permalink}'>\n";
    }
    $out .= "<span class='{$labelClass}'>" . sp_filter_title_display($label) . " \n";
    if ($labelLink) {
        $out .= "</a>\n";
    }
    # Link to post
    $out .= "<a class='{$linkClass}' {$title} href='{$spThisListTopic->first_post_permalink}'>\n";
    $out .= sp_paint_icon($iconClass, SPTHEMEICONSURL, $icon);
    $out .= "</a></span>\n";
    # user
    $poster = sp_build_name_display($spThisListTopic->first_user_id, sp_truncate($spThisListTopic->first_display_name, $truncateUser));
    if (empty($poster)) {
        $poster = sp_truncate($spThisListTopic->first_guest_name, $truncateUser);
    }
    if ($user) {
        $out .= "<span class='{$labelClass}'>{$poster}</span>\n";
    }
    if ($get) {
        $getData = new stdClass();
        $getData->permalink = $spThisListTopic->first_post_permalink;
        $getData->topic_name = $spThisListTopic->topic_name;
        $getData->post_date = $spThisListTopic->first_post_date;
        $getData->tooltip = $spThisListTopic->first_post_tip;
        $getData->user = $poster;
        return $getData;
    }
    if ($break) {
        $sp = "<br />";
    }
    # date/time
    if ($niceDate) {
        $out .= "<span class='{$labelClass}'>" . $sp . sp_nicedate($spThisListTopic->first_post_date) . "</span>\n";
    } else {
        if ($date) {
            $out .= "<span class='{$labelClass}'>" . $sp . sp_date('d', $spThisListTopic->first_post_date);
            if ($time) {
                $out .= '-' . sp_date('t', $spThisListTopic->first_post_date);
            }
            $out .= "</span>\n";
        }
    }
    $out .= "</div>\n";
    $out = apply_filters('sph_ListFirstPost', $out, $a);
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}