function sp_do_sp_ForumHomeLinkTag($args = '')
{
    #check if forum displayed
    if (sp_abort_display_forum()) {
        return;
    }
    $defs = array('beforeLink' => '', 'afterLink' => '', 'echo' => 1);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_ForumHomeLinkTag_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $beforeLink = sp_filter_title_display($beforeLink);
    $afterLink = sp_filter_title_display($afterLink);
    $echo = (int) $echo;
    if (!empty($beforeLink)) {
        $beforeLink = trim($beforeLink) . ' ';
    }
    if (!empty($afterLink)) {
        $afterLink = ' ' . trim($afterLink);
    }
    $pid = sp_get_option('sfpage');
    $title = spdb_table(SFWPPOSTS, "ID={$pid}", 'post_title');
    $out .= '<span>' . $beforeLink . '<a href="' . get_permalink($pid) . '">' . $title . '</a>' . $afterLink . '</span>';
    $out = apply_filters('sph_ForumHomeLinkTag', $out);
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}
function sp_cron_remove_users()
{
    require_once ABSPATH . 'wp-admin/includes/user.php';
    # make sure auto removal is enabled
    $sfuser = sp_get_option('sfuserremoval');
    if ($sfuser['sfuserremove']) {
        # see if removing users with no posts
        if ($sfuser['sfusernoposts']) {
            $users = spdb_select('set', 'SELECT ' . SFUSERS . '.ID FROM ' . SFUSERS . '
										JOIN ' . SFMEMBERS . ' on ' . SFUSERS . '.ID = ' . SFMEMBERS . '.user_id
										LEFT JOIN ' . SFWPPOSTS . ' ON ' . SFUSERS . '.ID = ' . SFWPPOSTS . '.post_author
										WHERE user_registered < DATE_SUB(NOW(), INTERVAL ' . $sfuser['sfuserperiod'] . ' DAY)
										AND post_author IS NULL
										AND posts < 1');
            if ($users) {
                foreach ($users as $user) {
                    wp_delete_user($user->ID);
                }
            }
        }
        # see if removing inactive users
        if ($sfuser['sfuserinactive']) {
            $users = spdb_table(SFMEMBERS, 'lastvisit < DATE_SUB(NOW(), INTERVAL ' . $sfuser['sfuserperiod'] . ' DAY)');
            if ($users) {
                foreach ($users as $user) {
                    wp_delete_user($user->user_id);
                }
            }
        }
    } else {
        wp_clear_scheduled_hook('sph_cron_user');
    }
    do_action('sph_remove_users_cron');
}
function sp_do_sp_GroupLinkTag($args = '')
{
    #check if forum displayed
    if (sp_abort_display_forum()) {
        return;
    }
    $defs = array('groupId' => '', 'linkText' => '%GROUPNAME%', 'beforeLink' => '', 'afterLink' => '', 'listTags' => 0, 'echo' => 1);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_GroupLinkTag_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $groupId = (int) $groupId;
    $linkText = esc_attr($linkText);
    $beforeLink = sp_filter_title_display($beforeLink);
    $afterLink = sp_filter_title_display($afterLink);
    $listTags = (int) $listTags;
    $echo = (int) $echo;
    if (empty($groupId)) {
        return '';
    }
    sp_forum_api_support();
    if (!empty($beforeLink)) {
        $beforeLink = trim($beforeLink) . ' ';
    }
    if (!empty($afterLink)) {
        $afterLink = ' ' . trim($afterLink);
    }
    # check user has access to at kleast ine forum in group
    $canview = false;
    $forums = spdb_table(SFFORUMS, "group_id={$groupId}");
    if ($forums) {
        foreach ($forums as $forum) {
            if (sp_can_view($forum->forum_id, 'forum-title')) {
                $canview = true;
            }
        }
    }
    if ($forums && $canview) {
        $grouprec = spdb_table(SFGROUPS, "group_id={$groupId}", 'row');
        $out = '';
        $linkText = str_replace("%GROUPNAME%", sp_filter_title_display($grouprec->group_name), $linkText);
        if (empty($linkText)) {
            $linkText = sp_filter_title_display($grouprec->group_name);
        }
        if ($listTags) {
            $out .= '<li>';
        }
        $out .= '<span>' . $beforeLink . '<a href="' . add_query_arg(array('group' => $groupId), sp_url()) . '">' . $linkText . '</a>' . $afterLink . '</span>';
        if ($listTags) {
            $out .= '</li>';
        }
    }
    $out = apply_filters('sph_GroupLinkTag', $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;
    }
}
Exemple #5
0
function sp_email_notifications($newpost)
{
    global $spGlobals, $spThisUser, $spVars;
    $out = '';
    $email_status = array();
    $eol = "\r\n";
    $tab = "\t";
    # create the email address list for admin nptifications
    $admins_email = array();
    $admins = spdb_table(SFMEMBERS, 'admin = 1 OR moderator = 1');
    if ($admins) {
        foreach ($admins as $admin) {
            if ($admin->user_id != $newpost['userid']) {
                $admin_opts = unserialize($admin->admin_options);
                if ($admin_opts['sfnotify'] && sp_get_auth('moderate_posts', $newpost['forumid'], $admin->user_id)) {
                    $email = spdb_table(SFUSERS, "ID = " . $admin->user_id, 'user_email');
                    $admins_email[$admin->user_id] = $email;
                }
            }
        }
    }
    $admins_email = apply_filters('sph_admin_email_addresses', $admins_email);
    # send the emails
    if (!empty($admins_email)) {
        # clean up the content for the plain text email - go get it from database so not in 'save' mode
        $post_content = spdb_table(SFPOSTS, 'post_id=' . $newpost['postid'], 'post_content');
        $post_content = sp_filter_email_content($post_content);
        # create message body
        $msg = sp_text('New forum post on your site') . ': ' . get_option('blogname') . $eol . $eol;
        $msg .= sp_text('From') . ': ' . $tab . $newpost['postername'] . ' [' . $newpost['posteremail'] . ']' . ', ' . sp_text('Poster IP') . ': ' . $newpost['posterip'] . $eol . $eol;
        $msg .= sp_text('Group') . ':' . $tab . sp_filter_title_display($newpost['groupname']) . $eol;
        $msg .= sp_text('Forum') . ':' . $tab . sp_filter_title_display($newpost['forumname']) . $eol;
        $msg .= sp_text('Topic') . ':' . $tab . sp_filter_title_display($newpost['topicname']) . $eol;
        $msg .= urldecode($newpost['url']) . $eol;
        $msg .= sp_text('Post') . ':' . $eol . $post_content . $eol . $eol;
        foreach ($admins_email as $id => $email) {
            $newmsg = apply_filters('sph_admin_email', $msg, $newpost, $id, 'admin');
            $replyto = apply_filters('sph_email_replyto', '', $newpost);
            $subject = sp_text('Forum Post') . ' - ' . get_option('blogname') . ': [' . sp_filter_title_display($newpost['topicname']) . ']';
            $subject = apply_filters('sph_email_subject', $subject, $newpost);
            sp_send_email($email, $subject, $newmsg, $replyto);
        }
        $out = '- ' . sp_text('Notified: Administrators/Moderators');
    }
    $out = apply_filters('sph_new_post_notifications', $out, $newpost);
    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 spa_save_integration_page_data()
{
    check_admin_referer('forum-adminform_integration', 'forum-adminform_integration');
    $mess = '';
    $slugid = sp_esc_int($_POST['slug']);
    if ($slugid == '' || $slugid == 0) {
        $setslug = '';
        $setpage = 0;
    } else {
        $setpage = $slugid;
        $page = spdb_table(SFWPPOSTS, "ID={$slugid}", 'row');
        $setslug = $page->post_name;
        if ($page->post_parent) {
            $parent = $page->post_parent;
            while ($parent) {
                $thispage = spdb_table(SFWPPOSTS, "ID={$parent}", 'row');
                $setslug = $thispage->post_name . '/' . $setslug;
                $parent = $thispage->post_parent;
            }
        }
    }
    sp_update_option('sfpage', $setpage);
    sp_update_option('sfslug', $setslug);
    spa_update_check_option('sfinloop');
    spa_update_check_option('sfmultiplecontent');
    spa_update_check_option('sfwpheadbypass');
    spa_update_check_option('sfwplistpages');
    spa_update_check_option('sfscriptfoot');
    spa_update_check_option('sfuseob');
    spa_update_check_option('spwptexturize');
    sp_update_option('spheaderspace', sp_esc_int($_POST['spheaderspace']));
    if (!$setpage) {
        $mess .= spa_text('Page slug missing');
        $mess .= ' - ' . spa_text('Unable to determine forum permalink without it');
    } else {
        $mess .= spa_text('Forum page and slug updated');
        sp_update_permalink(true);
    }
    do_action('sph_integration_save');
    return $mess;
}
function spa_forums_add_permission_form($forum_id)
{
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	spjAjaxForm('sfpermissionnew<?php 
    echo $forum_id;
    ?>
', 'sfreloadfb');
    });
</script>
<?php 
    $forum = spdb_table(SFFORUMS, "forum_id={$forum_id}", 'row');
    echo '<div class="sfform-panel-spacer"></div>';
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=addperm';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfpermissionnew<?php 
    echo $forum->forum_id;
    ?>
" name="sfpermissionnew<?php 
    echo $forum->forum_id;
    ?>
">
<?php 
    echo sp_create_nonce('forum-adminform_permissionnew');
    spa_paint_open_tab(spa_text('Forums') . ' - ' . spa_text('Manage Groups and Forums'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Add Permission Set'), 'true', 'add-user-group-permission-set');
    ?>
					<table class="form-table">
						<tr>
							<td class="sflabel"><?php 
    spa_display_usergroup_select(true, $forum->forum_id);
    ?>
</td>
						</tr><tr>
							<td class="sflabel"><?php 
    spa_display_permission_select();
    ?>
</td>
						</tr>
					</table>
					<input type="hidden" name="forum_id" value="<?php 
    echo $forum->forum_id;
    ?>
" />
<?php 
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_forums_add_perm_panel');
    spa_paint_close_container();
    ?>
		<div class="sfform-submit-bar">
		<input type="submit" class="button-primary" id="permnew<?php 
    echo $forum->forum_id;
    ?>
" name="permnew<?php 
    echo $forum->forum_id;
    ?>
" value="<?php 
    spa_etext('Add Permission Set');
    ?>
" />
		<input type="button" class="button-primary" onclick="javascript:jQuery('#newperm-<?php 
    echo $forum->forum_id;
    ?>
').html('');" id="sfpermissionnew<?php 
    echo $forum->forum_id;
    ?>
" name="addpermcancel<?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_forumview_query($forumid = 0, $cPage = 1)
    {
        global $spGlobals, $spThisUser;
        # do we have a valid forum id
        if ($forumid == 0) {
            $this->forumViewStatus = 'no data';
            return;
        } else {
            $this->forumViewStatus = 'no access';
            $BASEWHERE = SFFORUMS . ".forum_id={$forumid}";
        }
        # some setup vars
        $startlimit = 0;
        # how many topics per page?
        $tpaged = $spGlobals['display']['topics']['perpage'];
        if (!$tpaged) {
            $tpaged = 20;
        }
        # setup where we are in the topic list (paging)
        if ($cPage != 1) {
            $startlimit = ($cPage - 1) * $tpaged;
        }
        $LIMIT = $startlimit . ', ' . $tpaged;
        # Set up where clause
        if (sp_get_auth('moderate_posts', $forumid)) {
            $COLUMN = SFTOPICS . '.post_id';
            $WHERE = $BASEWHERE;
        } else {
            $COLUMN = SFTOPICS . '.post_id_held';
            $WHERE = $BASEWHERE . ' AND ' . SFTOPICS . '.post_count_held > 0';
        }
        # Set up order by
        $reverse = false;
        $setSort = $spGlobals['display']['topics']['sortnewtop'];
        if (isset($spGlobals['sort_order']['forum'])) {
            $reverse = array_search($forumid, (array) $spGlobals['sort_order']['forum']) !== false ? true : false;
        }
        if (isset($spThisUser->topicASC) && $spThisUser->topicASC) {
            $reverse = !$reverse;
        }
        if ($setSort xor $reverse) {
            $ORDER = 'topic_pinned DESC, ' . $COLUMN . ' DESC';
        } else {
            $ORDER = 'topic_pinned DESC, ' . $COLUMN . ' ASC';
        }
        # retrieve forum and topic records
        $spdb = new spdbComplex();
        $spdb->table = SFTOPICS;
        $spdb->fields = SFTOPICS . '.forum_id, forum_slug, forum_name, forum_status, group_id, topic_count, forum_icon, topic_icon, topic_icon_new, topic_icon_locked, topic_icon_pinned, forum_desc, forum_rss,
							forum_rss_private, parent, children, forum_message, forum_disabled, keywords,
							' . SFTOPICS . '.topic_id, topic_slug, topic_name, topic_status, topic_pinned,
							topic_opened, ' . SFTOPICS . '.post_id, ' . SFTOPICS . '.post_count';
        $spdb->join = array(SFFORUMS . ' ON ' . SFTOPICS . '.forum_id = ' . SFFORUMS . '.forum_id');
        $spdb->where = $WHERE;
        $spdb->orderby = $ORDER;
        $spdb->limits = $LIMIT;
        $spdb = apply_filters('sph_forumview_query', $spdb, $this);
        if (!empty($spThisUser->inspect['q_spForumView'])) {
            $spdb->inspect = 'spForumView';
            $spdb->show = true;
        }
        $records = $spdb->select();
        $f = array();
        if ($records) {
            $this->forumViewStatus = 'no access';
            $fidx = $forumid;
            $tidx = 0;
            # define topic id array to collect forum stats and tags
            $t = array();
            if (sp_can_view($forumid, 'topic-title')) {
                $this->forumViewStatus = 'data';
                # construct the parent forum object
                $r = current($records);
                $f[$fidx] = new stdClass();
                $f[$fidx]->forum_id = $r->forum_id;
                $f[$fidx]->forum_slug = $r->forum_slug;
                $f[$fidx]->forum_name = sp_filter_title_display($r->forum_name);
                $f[$fidx]->forum_permalink = sp_build_url($r->forum_slug, '', 0, 0);
                $f[$fidx]->forum_desc = sp_filter_title_display($r->forum_desc);
                $f[$fidx]->forum_status = $r->forum_status;
                $f[$fidx]->forum_disabled = $r->forum_disabled;
                $f[$fidx]->group_id = $r->group_id;
                $f[$fidx]->topic_count = $r->topic_count;
                $f[$fidx]->forum_icon = sanitize_file_name($r->forum_icon);
                $f[$fidx]->topic_icon = sanitize_file_name($r->topic_icon);
                $f[$fidx]->topic_icon_new = sanitize_file_name($r->topic_icon_new);
                $f[$fidx]->topic_icon_locked = sanitize_file_name($r->topic_icon_locked);
                $f[$fidx]->topic_icon_pinned = sanitize_file_name($r->topic_icon_pinned);
                $f[$fidx]->parent = $r->parent;
                $f[$fidx]->children = $r->children;
                $f[$fidx]->forum_message = sp_filter_text_display($r->forum_message);
                $f[$fidx]->forum_keywords = sp_filter_title_display($r->keywords);
                $f[$fidx]->forum_rss = esc_url($r->forum_rss);
                $f[$fidx]->forum_rss_private = $r->forum_rss_private;
                $f[$fidx]->display_page = $this->forumPage;
                $f[$fidx]->tools_flag = 1;
                $f[$fidx]->unread = 0;
                # Can the user create new topics or should we lock the forum?
                $f[$fidx]->start_topics = sp_get_auth('start_topics', $r->forum_id);
                $f[$fidx] = apply_filters('sph_forumview_forum_record', $f[$fidx], $r);
                reset($records);
                # now loop through the topic records
                $firstTopicPage = 1;
                $pinned = 0;
                foreach ($records as $r) {
                    $tidx = $r->topic_id;
                    $t[] = $tidx;
                    $f[$fidx]->topics[$tidx] = new stdClass();
                    $f[$fidx]->topics[$tidx]->topic_id = $r->topic_id;
                    $f[$fidx]->topics[$tidx]->topic_slug = $r->topic_slug;
                    $f[$fidx]->topics[$tidx]->topic_name = sp_filter_title_display($r->topic_name);
                    $f[$fidx]->topics[$tidx]->topic_permalink = sp_build_url($r->forum_slug, $r->topic_slug, 1, 0);
                    $f[$fidx]->topics[$tidx]->topic_status = $r->topic_status;
                    $f[$fidx]->topics[$tidx]->topic_pinned = $r->topic_pinned;
                    $f[$fidx]->topics[$tidx]->topic_opened = $r->topic_opened;
                    $f[$fidx]->topics[$tidx]->post_id = $r->post_id;
                    $f[$fidx]->topics[$tidx]->post_count = $r->post_count;
                    $f[$fidx]->topics[$tidx]->unread = 0;
                    $f[$fidx]->topics[$tidx]->last_topic_on_page = 0;
                    $f[$fidx]->topics[$tidx]->first_topic_on_page = $firstTopicPage;
                    $f[$fidx]->topics[$tidx]->first_pinned = 0;
                    $f[$fidx]->topics[$tidx]->last_pinned = 0;
                    # Can the user create new topics or should we lock the forum?
                    $f[$fidx]->topics[$tidx]->reply_topics = sp_get_auth('reply_topics', $fidx);
                    # pinned status
                    if ($firstTopicPage == 1 && $r->topic_pinned) {
                        $f[$fidx]->topics[$tidx]->first_pinned = true;
                        $pinned = $tidx;
                    }
                    if ($firstTopicPage == 0 && $pinned > 0 && $r->topic_pinned == false) {
                        $f[$fidx]->topics[$pinned]->last_pinned = true;
                    } elseif ($r->topic_pinned) {
                        $pinned = $tidx;
                    }
                    $firstTopicPage = 0;
                    # See if this topic is in the current users newpost list
                    if ($spThisUser->member && !empty($spThisUser->newposts) && is_array($spThisUser->newposts['topics']) && in_array($tidx, $spThisUser->newposts['topics'])) {
                        $f[$fidx]->topics[$tidx]->unread = 1;
                    }
                    $f[$fidx]->topics[$tidx] = apply_filters('sph_forumview_topic_records', $f[$fidx]->topics[$tidx], $r);
                }
                $f[$fidx]->topics[$tidx]->last_topic_on_page = 1;
                unset($records);
                # Collect any forum subforms that may exist
                if ($f[$fidx]->children) {
                    $topSubs = unserialize($f[$fidx]->children);
                    foreach ($topSubs as $topSub) {
                        $topSubA = array();
                        $topSubA[] = $topSub;
                        $subs = $this->sp_forumview_subforums_query($topSubA, true);
                    }
                    if ($subs) {
                        $f = $this->sp_forumview_build_subforums($forumid, $f, $fidx, $subs);
                    }
                }
                # allow plugins to add more data to combined forum/topic data structure
                $f[$fidx] = apply_filters('sph_forumview_combined_data', $f[$fidx], $t);
                # Collect first and last post stats for each topic
                $stats = $this->sp_forumview_stats_query($t, $forumid);
                if ($stats) {
                    foreach ($stats as $s) {
                        if ($s->post_index == 1) {
                            $f[$fidx]->topics[$s->topic_id]->first_post_id = $s->post_id;
                            $f[$fidx]->topics[$s->topic_id]->first_post_permalink = sp_build_url($f[$fidx]->forum_slug, $f[$fidx]->topics[$s->topic_id]->topic_slug, 0, $s->post_id, $s->post_index);
                            $f[$fidx]->topics[$s->topic_id]->first_post_date = $s->post_date;
                            $f[$fidx]->topics[$s->topic_id]->first_post_status = $s->post_status;
                            $f[$fidx]->topics[$s->topic_id]->first_post_index = $s->post_index;
                            $f[$fidx]->topics[$s->topic_id]->first_user_id = $s->user_id;
                            $f[$fidx]->topics[$s->topic_id]->first_display_name = sp_filter_name_display($s->display_name);
                            $f[$fidx]->topics[$s->topic_id]->first_guest_name = sp_filter_name_display($s->guest_name);
                            # see if we can display the tooltip
                            if (sp_can_view($forumid, 'post-content', $spThisUser->ID, $s->user_id, $s->topic_id, $s->post_id)) {
                                $f[$fidx]->topics[$s->topic_id]->first_post_tip = $s->post_status ? sp_text('Post awaiting moderation') : sp_filter_tooltip_display($s->post_content, $s->post_status);
                            } else {
                                $f[$fidx]->topics[$s->topic_id]->first_post_tip = '';
                            }
                        }
                        if ($s->post_index > 1 || $f[$fidx]->topics[$s->topic_id]->post_count == 1) {
                            $f[$fidx]->topics[$s->topic_id]->last_post_id = $s->post_id;
                            $f[$fidx]->topics[$s->topic_id]->last_post_permalink = sp_build_url($f[$fidx]->forum_slug, $f[$fidx]->topics[$s->topic_id]->topic_slug, 0, $s->post_id, $s->post_index);
                            $f[$fidx]->topics[$s->topic_id]->last_post_date = $s->post_date;
                            $f[$fidx]->topics[$s->topic_id]->last_post_status = $s->post_status;
                            $f[$fidx]->topics[$s->topic_id]->last_post_index = $s->post_index;
                            $f[$fidx]->topics[$s->topic_id]->last_user_id = $s->user_id;
                            $f[$fidx]->topics[$s->topic_id]->last_display_name = sp_filter_name_display($s->display_name);
                            $f[$fidx]->topics[$s->topic_id]->last_guest_name = sp_filter_name_display($s->guest_name);
                            # see if we can display the tooltip
                            if (sp_can_view($forumid, 'post-content', $spThisUser->ID, $s->user_id, $s->topic_id, $s->post_id)) {
                                $f[$fidx]->topics[$s->topic_id]->last_post_tip = $s->post_status ? sp_text('Post awaiting moderation') : sp_filter_tooltip_display($s->post_content, $s->post_status);
                            } else {
                                $f[$fidx]->topics[$s->topic_id]->last_post_tip = '';
                            }
                        }
                        $f[$fidx]->topics[$s->topic_id] = apply_filters('sph_forumview_stats_records', $f[$fidx]->topics[$s->topic_id], $s);
                    }
                    unset($stats);
                }
            } else {
                # check for view forum lists but not topic lists
                if (sp_can_view($forumid, 'forum-title')) {
                    $this->forumViewStatus = 'sneak peek';
                }
            }
        } else {
            $records = spdb_table(SFFORUMS, $BASEWHERE);
            $r = current($records);
            if ($r) {
                if (sp_can_view($forumid, 'topic-title')) {
                    $this->forumViewStatus = 'data';
                    $f[$forumid] = new stdClass();
                    $f[$forumid]->forum_id = $r->forum_id;
                    $f[$forumid]->forum_slug = $r->forum_slug;
                    $f[$forumid]->forum_name = sp_filter_title_display($r->forum_name);
                    $f[$forumid]->forum_permalink = sp_build_url($r->forum_slug, '', 0, 0);
                    $f[$forumid]->forum_desc = sp_filter_title_display($r->forum_desc);
                    $f[$forumid]->forum_status = $r->forum_status;
                    $f[$forumid]->forum_disabled = $r->forum_disabled;
                    $f[$forumid]->group_id = $r->group_id;
                    $f[$forumid]->topic_count = $r->topic_count;
                    $f[$forumid]->forum_icon = sanitize_file_name($r->forum_icon);
                    $f[$forumid]->forum_icon_new = sanitize_file_name($r->forum_icon_new);
                    $f[$forumid]->topic_icon = sanitize_file_name($r->topic_icon);
                    $f[$forumid]->topic_icon_new = sanitize_file_name($r->topic_icon_new);
                    $f[$forumid]->topic_icon_locked = sanitize_file_name($r->topic_icon_locked);
                    $f[$forumid]->topic_icon_pinned = sanitize_file_name($r->topic_icon_pinned);
                    $f[$forumid]->parent = $r->parent;
                    $f[$forumid]->children = $r->children;
                    $f[$forumid]->forum_message = sp_filter_text_display($r->forum_message);
                    $f[$forumid]->forum_keywords = sp_filter_title_display($r->keywords);
                    $f[$forumid]->forum_rss = esc_url($r->forum_rss);
                    $f[$forumid]->forum_rss_private = $r->forum_rss_private;
                    # Can the user create new topics or should we lock the forum?
                    $f[$forumid]->start_topics = sp_get_auth('start_topics', $r->forum_id);
                    $f[$forumid] = apply_filters('sph_forumview_forum_record', $f[$forumid], $r);
                } else {
                    # check for view forum lists but not topic lists
                    if (sp_can_view($forumid, 'forum-title')) {
                        $this->forumViewStatus = 'sneak peek';
                    }
                }
                # Collect any forum subforms that may exist
                if (isset($f[$forumid]->children) && $f[$forumid]->children) {
                    $topSubs = unserialize($f[$forumid]->children);
                    foreach ($topSubs as $topSub) {
                        $topSubA = array();
                        $topSubA[] = $topSub;
                        $subs = $this->sp_forumview_subforums_query($topSubA, true);
                    }
                    if ($subs) {
                        $f = $this->sp_forumview_build_subforums($forumid, $f, $forumid, $subs);
                    }
                }
                # allow plugins to add more data to combined forum/topic data structure
                $f[$forumid] = apply_filters('sph_forumview_combined_data', $f[$forumid], array());
            } else {
                # reset status to 'no data'
                $this->forumViewStatus = 'no data';
            }
        }
        return $f;
    }
function sp_UpdateProfile()
{
    global $spGlobals, $spThisUser;
    # make sure nonce is there
    check_admin_referer('forum-profile', 'forum-profile');
    $message = array();
    # dont update forum if its locked down
    if ($spGlobals['lockdown']) {
        $message['type'] = 'error';
        $message['text'] = sp_text('This forum is currently locked - access is read only - profile not updated');
        return $message;
    }
    # do we have a form to update?
    if (isset($_GET['form'])) {
        $thisForm = sp_esc_str($_GET['form']);
    } else {
        $message['type'] = 'error';
        $message['text'] = sp_text('Profile update aborted - no valid form');
        return $message;
    }
    # do we have an actual user to update?
    if (isset($_GET['userid'])) {
        $thisUser = sp_esc_int($_GET['userid']);
    } else {
        $message['type'] = 'error';
        $message['text'] = sp_text('Profile update aborted - no valid user');
        return $message;
    }
    # Check the user ID for current user of admin edit
    if ($thisUser != $spThisUser->ID && !$spThisUser->admin) {
        $message['type'] = 'error';
        $message['text'] = sp_text('Profile update aborted - no valid user');
        return $message;
    }
    if (isset($spThisUser->sp_change_pw) && $spThisUser->sp_change_pw) {
        $pass1 = $pass2 = '';
        if (isset($_POST['pass1'])) {
            $pass1 = $_POST['pass1'];
        }
        if (isset($_POST['pass2'])) {
            $pass2 = $_POST['pass2'];
        }
        if (empty($pass1) || empty($pass2) || $pass1 != $pass2) {
            $message['type'] = 'error';
            $message['text'] = sp_text('Cannot save profile until password has been changed');
            return $message;
        }
    }
    # form save filter
    $thisForm = apply_filters('sph_profile_save_thisForm', $thisForm);
    # valid save attempt, so lets process the save
    switch ($thisForm) {
        case 'show-memberships':
            # update memberships
            # any usergroup removals?
            if (isset($_POST['usergroup_leave'])) {
                foreach ($_POST['usergroup_leave'] as $membership) {
                    sp_remove_membership(sp_esc_str($membership), $thisUser);
                }
            }
            # any usergroup joins?
            if (isset($_POST['usergroup_join'])) {
                foreach ($_POST['usergroup_join'] as $membership) {
                    sp_add_membership(sp_esc_int($membership), $thisUser);
                }
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileMemberships', $message, $thisUser);
            # output update message
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Memberships updated');
            }
            break;
        case 'account-settings':
            # update account settings
            # check for password update
            $pass1 = $pass2 = '';
            if (isset($_POST['pass1'])) {
                $pass1 = $_POST['pass1'];
            }
            if (isset($_POST['pass2'])) {
                $pass2 = $_POST['pass2'];
            }
            if (!empty($pass1) || !empty($pass2)) {
                if ($pass1 != $pass2) {
                    $message['type'] = 'error';
                    $message['text'] = sp_text('Please enter the same password in the two password fields');
                    return $message;
                } else {
                    # update the password
                    $user = new stdClass();
                    $user->ID = (int) $thisUser;
                    $user->user_pass = $pass1;
                    wp_update_user(get_object_vars($user));
                    if (isset($spThisUser->sp_change_pw) && $spThisUser->sp_change_pw) {
                        delete_user_meta($spThisUser->ID, 'sp_change_pw');
                    }
                }
            }
            # now check the email is valid and unique
            $update = apply_filters('sph_ProfileUserEmailUpdate', true);
            if ($update) {
                $curEmail = sp_filter_email_save($_POST['curemail']);
                $email = sp_filter_email_save($_POST['email']);
                if ($email != $curEmail) {
                    if (empty($email)) {
                        $message['type'] = 'error';
                        $message['text'] = sp_text('Please enter a valid email address');
                        return $message;
                    } elseif (($owner_id = email_exists($email)) && $owner_id != $thisUser) {
                        $message['type'] = 'error';
                        $message['text'] = sp_text('The email address is already registered. Please choose another one');
                        return $message;
                    }
                    # save new email address
                    $sql = 'UPDATE ' . SFUSERS . " SET user_email='{$email}' WHERE ID=" . $thisUser;
                    spdb_query($sql);
                }
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileSettings', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Account settings updated');
            }
            break;
        case 'edit-profile':
            # update profile settings
            # validate any username change
            $update = apply_filters('sph_ProfileUserDisplayNameUpdate', true);
            if ($update) {
                $spProfile = sp_get_option('sfprofile');
                if ($spProfile['nameformat'] || $spThisUser->admin) {
                    $display_name = !empty($_POST['display_name']) ? trim($_POST['display_name']) : spdb_table(SFUSERS, "ID={$thisUser}", 'user_login');
                    $display_name = sp_filter_name_save($display_name);
                    # make sure display name isnt already used
                    if ($_POST['oldname'] != $display_name) {
                        $records = spdb_table(SFMEMBERS, "display_name='{$display_name}'");
                        if ($records) {
                            foreach ($records as $record) {
                                if ($record->user_id != $thisUser) {
                                    $message['type'] = 'error';
                                    $message['text'] = $display_name . ' ' . sp_text('is already in use - please choose a different display name');
                                    return $message;
                                }
                            }
                        }
                        # validate display name
                        $errors = new WP_Error();
                        $user = new stdClass();
                        $user->display_name = $display_name;
                        sp_validate_display_name($errors, true, $user);
                        if ($errors->get_error_codes()) {
                            $message['type'] = 'error';
                            $message['text'] = sp_text('The display name you have chosen is not allowed on this site');
                            return $message;
                        }
                        # now save the display name
                        sp_update_member_item($thisUser, 'display_name', $display_name);
                        # Update new users list with changed display name
                        sp_update_newuser_name(sp_filter_name_save($_POST['oldname']), $display_name);
                        # do we need to sync display name with wp?
                        $options = sp_get_member_item($thisUser, 'user_options');
                        if ($options['namesync']) {
                            spdb_query('UPDATE ' . SFUSERS . ' SET display_name="' . $display_name . '" WHERE ID=' . $thisUser);
                        }
                    }
                }
            }
            # save the url
            $update = apply_filters('sph_ProfileUserWebsiteUpdate', true);
            if ($update) {
                $url = sp_filter_url_save($_POST['website']);
                $sql = 'UPDATE ' . SFUSERS . ' SET user_url="' . $url . '" WHERE ID=' . $thisUser;
                spdb_query($sql);
            }
            # update first name, last name, location and biorgraphy
            $update = apply_filters('sph_ProfileUserFirstNameUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'first_name', sp_filter_name_save(trim($_POST['first_name'])));
            }
            $update = apply_filters('sph_ProfileUserLastNameUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'last_name', sp_filter_name_save(trim($_POST['last_name'])));
            }
            $update = apply_filters('sph_ProfileUserLocationUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'location', sp_filter_title_save(trim($_POST['location'])));
            }
            $update = apply_filters('sph_ProfileUserBiographyUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'description', sp_filter_save_kses($_POST['description']));
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileProfile', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Profile settings updated');
            }
            break;
        case 'edit-identities':
            # update identity settings
            # update the user identities
            $update = apply_filters('sph_ProfileUserAIMUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'aim', sp_filter_title_save(trim($_POST['aim'])));
            }
            $update = apply_filters('sph_ProfileUserYahooUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'yim', sp_filter_title_save(trim($_POST['yim'])));
            }
            $update = apply_filters('sph_ProfileUserGoogleUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'jabber', sp_filter_title_save(trim($_POST['jabber'])));
            }
            $update = apply_filters('sph_ProfileUserMSNUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'msn', sp_filter_title_save(trim($_POST['msn'])));
            }
            $update = apply_filters('sph_ProfileUserICQUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'icq', sp_filter_title_save(trim($_POST['icq'])));
            }
            $update = apply_filters('sph_ProfileUserSkypeUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'skype', sp_filter_title_save(trim($_POST['skype'])));
            }
            $update = apply_filters('sph_ProfileUserFacebookUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'facebook', sp_filter_title_save(trim($_POST['facebook'])));
            }
            $update = apply_filters('sph_ProfileUserMySpaceUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'myspace', sp_filter_title_save(trim($_POST['myspace'])));
            }
            $update = apply_filters('sph_ProfileUserTwitterUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'twitter', sp_filter_title_save(trim($_POST['twitter'])));
            }
            $update = apply_filters('sph_ProfileUserLinkedInUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'linkedin', sp_filter_title_save(trim($_POST['linkedin'])));
            }
            $update = apply_filters('sph_ProfileUserYouTubeUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'youtube', sp_filter_title_save(trim($_POST['youtube'])));
            }
            $update = apply_filters('sph_ProfileUserGooglePlusUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'googleplus', sp_filter_title_save(trim($_POST['googleplus'])));
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileIdentities', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Identities updated');
            }
            break;
        case 'avatar-upload':
            # upload avatar
            # did we get an avatar to upload?
            if (empty($_FILES['avatar-upload']['name'])) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the avatar filename was empty');
                return $message;
            }
            # Verify the file extension
            global $spPaths;
            $uploaddir = SF_STORE_DIR . '/' . $spPaths['avatars'] . '/';
            $filename = basename($_FILES['avatar-upload']['name']);
            $path = pathinfo($filename);
            $ext = strtolower($path['extension']);
            if ($ext != 'jpg' && $ext != 'jpeg' && $ext != 'gif' && $ext != 'png') {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, only JPG, JPEG, PNG, or GIF files are allowed');
                return $message;
            }
            # check image file mimetype
            $mimetype = 0;
            $mimetype = exif_imagetype($_FILES['avatar-upload']['tmp_name']);
            if (empty($mimetype) || $mimetype == 0 || $mimetype > 3) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the avatar file is an invalid format');
                return $message;
            }
            # make sure file extension and mime type actually match
            if ($mimetype == 1 && $ext != 'gif' || $mimetype == 2 && ($ext != 'jpg' && $ext != 'jpeg') || $mimetype == 3 && $ext != 'png') {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the file mime type does not match file extension');
                return $message;
            }
            # Clean up file name just in case
            $filename = date('U') . sp_filter_filename_save(basename($_FILES['avatar-upload']['name']));
            $uploadfile = $uploaddir . $filename;
            # check for existence
            if (file_exists($uploadfile)) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the avatar file already exists');
                return $message;
            }
            # check file size against limit if provided
            $spAvatars = sp_get_option('sfavatars');
            if ($_FILES['avatar-upload']['size'] > $spAvatars['sfavatarfilesize']) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the avatar file exceeds the maximum allowed size');
                return $message;
            }
            # valid avatar, so try moving the uploaded file to the avatar storage directory
            if (move_uploaded_file($_FILES['avatar-upload']['tmp_name'], $uploadfile)) {
                @chmod("{$uploadfile}", 0644);
                # do we need to resize?
                $sfavatars = sp_get_option('sfavatars');
                if ($sfavatars['sfavatarresize']) {
                    $editor = wp_get_image_editor($uploadfile);
                    if (is_wp_error($editor)) {
                        @unlink($uploadfile);
                        $message['type'] = 'error';
                        $message['text'] = sp_text('Sorry, there was a problem resizing the avatar');
                        return $message;
                    } else {
                        $editor->resize($sfavatars['sfavatarsize'], $sfavatars['sfavatarsize'], true);
                        $imageinfo = $editor->save($uploadfile);
                        $filename = $imageinfo['file'];
                    }
                }
                # update member avatar data
                $avatar = sp_get_member_item($thisUser, 'avatar');
                $avatar['uploaded'] = $filename;
                sp_update_member_item($thisUser, 'avatar', $avatar);
            } else {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the avatar file could not be moved to the avatar storage location');
                return $message;
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileAvatarUpload', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Uploaded avatar updated');
            }
            break;
        case 'avatar-pool':
            # pool avatar
            # get pool avatar name
            $filename = sp_filter_filename_save($_POST['spPoolAvatar']);
            # error if no pool avatar provided
            if (empty($filename)) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, you must select a pool avatar before trying to save it');
                return $message;
            }
            # save the pool avatar
            $avatar = sp_get_member_item($thisUser, 'avatar');
            $avatar['pool'] = $filename;
            sp_update_member_item($thisUser, 'avatar', $avatar);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileAvatarPool', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Pool avatar updated');
            }
            break;
        case 'avatar-remote':
            # remote avatar
            # get remote avatar name
            $filename = sp_filter_url_save($_POST['spAvatarRemote']);
            $avatar = sp_get_member_item($thisUser, 'avatar');
            $avatar['remote'] = $filename;
            sp_update_member_item($thisUser, 'avatar', $avatar);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileAvatarRemote', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Remote avatar updated');
            }
            break;
        case 'edit-signature':
            # save signature
            # Check if maxmium links has been exceeded
            $numLinks = substr_count($_POST['postitem'], '</a>');
            $spFilters = sp_get_option('sffilters');
            if (!sp_get_auth('create_links', 'global', $thisUser) && $numLinks > 0 && !$spThisUser->admin) {
                $message['type'] = 'error';
                $message['text'] = sp_text('You are not allowed to put links in signatures');
                return $message;
            }
            if (sp_get_auth('create_links', 'global', $thisUser) && $spFilters['sfmaxlinks'] != 0 && $numLinks > $spFilters['sfmaxlinks'] && !$spThisUser->admin) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Maximum number of allowed links exceeded in signature') . ': ' . $spFilters['sfmaxlinks'] . ' ' . sp_text('allowed');
                return $message;
            }
            //			$sig = esc_sql(sp_filter_save_kses(trim($_POST['postitem'])));
            $sig = sp_filter_content_save($_POST['postitem'], 'edit');
            sp_update_member_item($thisUser, 'signature', $sig);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileSignature', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Signature updated');
            }
            break;
        case 'edit-photos':
            # save photos
            $photos = array();
            $spProfileOptions = sp_get_option('sfprofile');
            for ($x = 0; $x < $spProfileOptions['photosmax']; $x++) {
                $photos[$x] = sp_filter_url_save($_POST['photo' . $x]);
            }
            update_user_meta($thisUser, 'photos', $photos);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfilePhotos', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Photos updated');
            }
            break;
        case 'edit-global-options':
            # save global options
            $options = sp_get_member_item($thisUser, 'user_options');
            $options['hidestatus'] = isset($_POST['hidestatus']) ? true : false;
            $update = apply_filters('sph_ProfileUserSyncNameUpdate', true);
            if ($update) {
                $options['namesync'] = isset($_POST['namesync']) ? true : false;
            }
            sp_update_member_item($thisUser, 'user_options', $options);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileGlobalOptions', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Global options updated');
            }
            break;
        case 'edit-posting-options':
            # save posting options
            $update = apply_filters('sph_ProfileUserEditorUpdate', true);
            if ($update) {
                $options = sp_get_member_item($thisUser, 'user_options');
                if (isset($_POST['editor'])) {
                    $options['editor'] = sp_esc_int($_POST['editor']);
                }
                sp_update_member_item($thisUser, 'user_options', $options);
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfilePostingOptions', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Posting options updated');
            }
            break;
        case 'edit-display-options':
            # save display options
            $options = sp_get_member_item($thisUser, 'user_options');
            if (isset($_POST['timezone'])) {
                if (preg_match('/^UTC[+-]/', $_POST['timezone'])) {
                    # correct for manual UTC offets
                    $userOffset = preg_replace('/UTC\\+?/', '', $_POST['timezone']) * 3600;
                } else {
                    # get timezone offset for user
                    $date_time_zone_selected = new DateTimeZone(sp_esc_str($_POST['timezone']));
                    $userOffset = timezone_offset_get($date_time_zone_selected, date_create());
                }
                # get timezone offset for server based on wp settings
                $wptz = get_option('timezone_string');
                if (empty($wptz)) {
                    $serverOffset = get_option('gmt_offset');
                } else {
                    $date_time_zone_selected = new DateTimeZone($wptz);
                    $serverOffset = timezone_offset_get($date_time_zone_selected, date_create());
                }
                # calculate time offset between user and server
                $options['timezone'] = (int) round(($userOffset - $serverOffset) / 3600, 2);
                $options['timezone_string'] = sp_esc_str($_POST['timezone']);
            } else {
                $options['timezone'] = 0;
                $options['timezone_string'] = 'UTC';
            }
            if (isset($_POST['unreadposts'])) {
                $sfcontrols = sp_get_option('sfcontrols');
                $options['unreadposts'] = is_numeric($_POST['unreadposts']) ? max(min(sp_esc_int($_POST['unreadposts']), $sfcontrols['sfmaxunreadposts']), 0) : $sfcontrols['sfdefunreadposts'];
            }
            $options['topicASC'] = isset($_POST['topicASC']);
            $options['postDESC'] = isset($_POST['postDESC']);
            sp_update_member_item($thisUser, 'user_options', $options);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileDisplayOptions', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Display options updated');
            }
            break;
        default:
            break;
    }
    # let plugins do their thing on success
    $message = apply_filters('sph_ProfileFormSave_' . $thisForm, $message, $thisUser, $thisForm);
    do_action('sph_UpdateProfile', $thisUser, $thisForm);
    # reset the plugin_data just in case
    sp_reset_member_plugindata($thisUser);
    # done saving - return the messages
    return $message;
}
function sp_update_post_urls($old, $new)
{
    global $wpdb;
    if (empty($old) || empty($new)) {
        return;
    }
    $posts = spdb_table(SFPOSTS, 'post_content LIKE "%/' . esc_sql($wpdb->esc_like($old)) . '%"', '');
    if (!empty($posts)) {
        foreach ($posts as $p) {
            $pc = str_replace('/' . $old, '/' . $new, sp_filter_content_edit($p->post_content));
            $pc = sp_filter_content_save($pc, 'edit');
            spdb_query('UPDATE ' . SFPOSTS . " SET post_content = '{$pc}' WHERE post_id=" . $p->post_id);
        }
    }
}
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_delete_auth_cat($id_or_name)
{
    # if its not id, lets get the id for easy removal of auth cat from auths
    if (!is_numeric($id_or_name)) {
        $slug = sp_create_slug($id_or_name, true, SFAUTHCATS, 'authcat_slug');
        $id_or_name = spdb_table(SFAUTHCATS, 'authcat_slug="' . $slug . '"', 'authcat_id');
    }
    # now lets delete the auth cat
    $success = spdb_query('DELETE FROM ' . SFAUTHCATS . " WHERE authcat_id={$id_or_name}");
    # if successful, need to remove that cat from the auths and replace with default
    if ($success) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat=0 WHERE authcat_id={$id_or_name}");
    }
    return $success;
}
Exemple #14
0
    }
    ?>
	<script type="text/javascript">
	jQuery(document).ready(function() {
        spjSetProfileDataHeight();
	})
	</script>
<?php 
    die;
}
if ($action == 'update-nonmemberships') {
    if (empty($userid)) {
        die;
    }
    global $spThisUser;
    $usergroups = spdb_table(SFUSERGROUPS, '', '', '', '', ARRAY_A);
    if ($usergroups && ($spThisUser->ID != $userid || !$spThisUser->admin)) {
        $alt = 'spOdd';
        $first = true;
        foreach ($usergroups as $userGroup) {
            if (!sp_check_membership($userGroup['usergroup_id'], $userid) && ($userGroup['usergroup_join'] == 1 || $spThisUser->admin)) {
                $submit = true;
                if ($first) {
                    echo '<div class="spProfileUsergroupsNonMemberships">';
                    echo '<p class="spHeaderName">' . sp_text('Non-Memberships') . ':</p>';
                    $first = false;
                }
                echo "<div class='spProfileUsergroup {$alt}'>";
                echo '<div class="spColumnSection">';
                echo '<div class="spHeaderName">' . $userGroup['usergroup_name'] . '</div>';
                echo '<div class="spHeaderDescription">' . $userGroup['usergroup_desc'] . '</div>';
function sp_add_notice($nData)
{
    # see if we already have an notice here
    $notice = spdb_table(SFNOTICES, "user_id={$nData['user_id']} AND post_id={$nData['post_id']} AND message='{$nData['message']}'", 'notice_id');
    if (!empty($notice)) {
        return;
    }
    # create the new notice
    $spdb = new spdbComplex();
    $spdb->table = SFNOTICES;
    $spdb->fields = array('user_id', 'guest_email', 'post_id', 'link', 'link_text', 'message', 'expires');
    $spdb->data = array($nData['user_id'], $nData['guest_email'], $nData['post_id'], $nData['link'], sp_filter_title_save($nData['link_text']), sp_filter_title_save($nData['message']), $nData['expires']);
    $spdb = apply_filters('sph_new_notice_data', $spdb);
    $spdb->insert();
}
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 spa_forums_delete_forum_form($forum_id)
{
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	jQuery('#forumrow-<?php 
    echo $forum_id;
    ?>
').addClass('inForm');
    	spjAjaxForm('sfforumdelete<?php 
    echo $forum_id;
    ?>
', 'sfreloadfb');
    });
</script>
<?php 
    $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=deleteforum';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfforumdelete<?php 
    echo $forum->forum_id;
    ?>
" name="sfforumdelete<?php 
    echo $forum->forum_id;
    ?>
">
<?php 
    echo sp_create_nonce('forum-adminform_forumdelete');
    spa_paint_open_tab(spa_text('Forums') . ' - ' . spa_text('Manage Groups and Forums'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Delete Forum'), 'true', 'delete-forum');
    ?>
					<input type="hidden" name="group_id" value="<?php 
    echo $forum->group_id;
    ?>
" />
					<input type="hidden" name="forum_id" value="<?php 
    echo $forum->forum_id;
    ?>
" />
					<input type="hidden" name="cforum_seq" value="<?php 
    echo $forum->forum_seq;
    ?>
" />
					<input type="hidden" name="parent" value="<?php 
    echo $forum->parent;
    ?>
" />
					<input type="hidden" name="children" value="<?php 
    echo $forum->children;
    ?>
" />
<?php 
    echo '<p>';
    spa_etext('Warning! You are about to delete a forum');
    echo '</p>';
    echo '<p>';
    spa_etext('This will remove ALL topics and posts contained in this forum');
    echo '</p>';
    echo '<p>';
    spa_etext('Any Subforums will be promoted');
    echo '</p>';
    echo '<p>';
    echo sprintf(spa_text('Please note that this action %s can NOT be reversed %s'), '<strong>', '</strong>');
    echo '</p>';
    echo '<p>';
    spa_etext('Click on the delete forum button below to proceed');
    echo '</p>';
    echo '<p><strong>';
    spa_etext('IMPORTANT: Be patient. For busy forums this action can take some time');
    echo '</strong></p>';
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_forums_delete_forum_panel');
    spa_paint_close_container();
    ?>
		<div class="sfform-submit-bar">
		<input type="submit" class="button-primary" id="sfforumdelete<?php 
    echo $forum->forum_id;
    ?>
" name="sfforumdelete<?php 
    echo $forum->forum_id;
    ?>
" value="<?php 
    spa_etext('Delete 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="sfforumdelete<?php 
    echo $forum->forum_id;
    ?>
" name="delforumcancel<?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 spa_create_page_select($currentpageid)
{
    $pages = spdb_table(SFWPPOSTS, "post_type='page' && post_status!='trash'", '', 'menu_order');
    if ($pages) {
        $default = '';
        $out = '';
        $spacer = '&nbsp;&nbsp;&nbsp;&nbsp;';
        $out .= '<optgroup label="' . spa_text('Select the WP page') . ':">' . "\n";
        foreach ($pages as $page) {
            $sublevel = 0;
            if ($page->post_parent) {
                $parent = $page->post_parent;
                $pageslug = $page->post_name;
                while ($parent) {
                    $thispage = spdb_table(SFWPPOSTS, "ID={$parent}", 'row');
                    $pageslug = $thispage->post_name . '/' . $pageslug;
                    $parent = $thispage->post_parent;
                    $sublevel++;
                }
            } else {
                $pageslug = $page->post_name;
            }
            if ($currentpageid == $page->ID) {
                $default = 'selected="selected" ';
            } else {
                $default = null;
            }
            $out .= '<option ' . $default . 'value="' . $page->ID . '">' . $spacer . str_repeat('&rarr;&nbsp;', $sublevel) . $pageslug . '</option>' . "\n";
            $default = '';
        }
        $out .= '</optgroup>';
    } else {
        $out .= '<option value="0">' . spa_text('No WP pages found - please create one') . '</option>' . "\n";
    }
    return $out;
}
function spa_deactivate_plugin()
{
    $uninstall = sp_get_option('sfuninstall');
    if ($uninstall) {
        # uninstall - remove all data
        # remove any admin capabilities
        $admins = spdb_table(SFMEMBERS, 'admin=1');
        foreach ($admins as $admin) {
            $user = new WP_User($admin->user_id);
            $user->remove_cap('SPF Manage Options');
            $user->remove_cap('SPF Manage Forums');
            $user->remove_cap('SPF Manage User Groups');
            $user->remove_cap('SPF Manage Permissions');
            $user->remove_cap('SPF Manage Tags');
            $user->remove_cap('SPF Manage Components');
            $user->remove_cap('SPF Manage Admins');
            $user->remove_cap('SPF Manage Profiles');
            $user->remove_cap('SPF Manage Users');
            $user->remove_cap('SPF Manage Toolbox');
            $user->remove_cap('SPF Manage Plugins');
            $user->remove_cap('SPF Manage Themes');
            $user->remove_cap('SPF Manage Integration');
            $user->remove_cap('SPF Manage Configuration');
            # no longer used but some may still have it
        }
        # remove any installed tables
        $tables = sp_get_option('installed_tables');
        if ($tables) {
            foreach ($tables as $table) {
                spdb_query("DROP TABLE IF EXISTS {$table}");
            }
        }
        # since we have removed our tables, need to turn off error logging to prevent onslaught of errors
        global $spGlobals;
        $spGlobals['record-errors'] = false;
        # Remove the Page record
        $sfpage = sp_get_option('sfpage');
        if (!empty($sfpage)) {
            spdb_query('DELETE FROM ' . SFWPPOSTS . ' WHERE ID=' . sp_get_option('sfpage'));
        }
        # remove widget data
        delete_option('widget_spf');
        delete_option('widget_sforum');
        # remove any wp options we might have set
        delete_option('sfInstallID');
        delete_option('sp_storage1');
        delete_option('sp_storage2');
        # Now remove user meta data
        $optionlist = array('sfadmin', 'location', 'msn', 'skype', 'icq', 'facebook', 'myspace', 'twitter', 'linkedin', 'youtube', 'googleplus', 'sfuse_quicktags', 'signature', 'sigimage');
        foreach ($optionlist as $option) {
            spdb_query('DELETE FROM ' . SFUSERMETA . " WHERE meta_key='{$option}';");
        }
        # send our uninstall action
        do_action('sph_uninstalled', $admins);
        # remove storage locations if so directed
        if (sp_get_option('removestorage')) {
            # let's remove our directories and storage
            global $spPaths;
            if (!empty($spPaths)) {
                foreach ($spPaths as $storage => $path) {
                    # lets not remove plugins and themes
                    if ($storage != 'plugins' && $storage != 'themes') {
                        sp_remove_dir(SF_STORE_DIR . '/' . $path);
                    }
                }
            }
            # remove the languages folder if it exists
            # note the sp-resources dire may not exist - but its our default. if user creates other parent dir for languages, we wont know about  it
            sp_remove_dir(SF_STORE_DIR . '/sp-resources/forum-language');
        }
    }
    # remove the combined css and js cache files
    sp_clear_combined_css('all');
    sp_clear_combined_css('mobile');
    sp_clear_combined_css('tablet');
    # remove cron jobs for deactivaton or uninstall
    wp_clear_scheduled_hook('spf_cron_pm');
    # left here for 5.0 who doesnt upgrade
    wp_clear_scheduled_hook('spf_cron_sitemap');
    # left here for 5.0 who doesnt upgrade
    wp_clear_scheduled_hook('sph_cron_user');
    wp_clear_scheduled_hook('sph_transient_cleanup_cron');
    wp_clear_scheduled_hook('sph_stats_cron');
    wp_clear_scheduled_hook('sph_news_cron');
    # send deactivated action
    if (!$uninstall) {
        do_action('sph_deactivated');
    }
}
function spa_forums_ordering_form($groupId = 0)
{
    $where = '';
    if ($groupId) {
        $where = "group_id={$groupId}";
    }
    $groups = spdb_table(SFGROUPS, $where, '', 'group_seq');
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	<?php 
    if ($groupId != 0) {
        ?>
    	jQuery('#grouprow-<?php 
        echo $groupId;
        ?>
').addClass('inForm');
    	<?php 
    }
    ?>
    	jQuery('#groupList').nestedSortable({
    		handle: 'div',
    		items: 'li',
    		tolerance: 'pointer',
    		listType: 'ul',
    		protectRoot: true,
    		placeholder: 'sortable-placeholder',
    		forcePlaceholderSize: true,
    		helper: 'clone',
    		tabSize: 30,
    		maxLevels: 10,
            scroll: true,
            scrollSensitivity: 40,
            scrollSpeed: 5
    	});

    	jQuery('#sfforumorder').ajaxForm({
    		target: '#sfmsgspot',
    		beforeSubmit: function() {
    			jQuery('#sfmsgspot').show();
    			jQuery('#sfmsgspot').html(pWait);
    		},
    		success: function() {
    			jQuery('#sfmsgspot').hide();
    			<?php 
    if ($groupId == 0) {
        ?>
    			jQuery('#sfreloadfo').click();
    			<?php 
    } else {
        ?>
    			jQuery('#sfreloadfb').click();
    			<?php 
    }
    ?>
    			jQuery('#sfmsgspot').fadeIn();
    			jQuery('#sfmsgspot').fadeOut(6000);
    		},
    		beforeSerialize: function() {
    			jQuery("input#spForumsOrder").val(jQuery("#groupList").nestedSortable('serialize'));
    		}
    	});
    });
</script>
<?php 
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=orderforum';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfforumorder" name="sfforumorder">
<?php 
    echo sp_create_nonce('forum-adminform_forumorder');
    spa_paint_open_tab(spa_text('Forums') . ' - ' . spa_text('Group and Forum Ordering'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Order Groups and Forums'), 'true', 'order-forums');
    ?>
				<input type="hidden" id="cgroup" name="cgroup" value="<?php 
    echo $groupId;
    ?>
" />
				<?php 
    echo '<p>' . spa_text('Here you can set the order of Groups, Forums and SubForums by dragging and dropping below. After ordering, push the save button.') . '</p>';
    if (!empty($groups)) {
        echo '<ul id="groupList" class="groupList menu">';
        foreach ($groups as $group) {
            echo "<li id='group-{$group->group_id}' class='menu-item-depth-0'>";
            echo "<div class='alt group-list menu-item'>";
            echo "<span class='item-name'>{$group->group_name}</span>";
            echo '</div>';
            # now output any forums in the group
            $allForums = spa_get_forums_in_group($group->group_id);
            $depth = 1;
            if (!empty($allForums)) {
                echo "<ul id='forumList-{$group->group_id}' class='forumList menu'>";
                foreach ($allForums as $thisForum) {
                    if ($thisForum->parent == 0) {
                        sp_paint_order_forum($thisForum, $allForums, $depth);
                    }
                }
                echo '</ul>';
            }
            echo '</li>';
        }
        echo '</ul>';
    }
    echo '<input type="text" class="inline_edit" size="70" id="spForumsOrder" name="spForumsOrder" />';
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_close_container();
    ?>
		<div class="sfform-submit-bar">
		<input type="submit" class="button-primary" id="saveit" name="saveit" value="<?php 
    spa_etext('Save Ordering');
    ?>
" />
        <?php 
    if ($groupId) {
        ?>
		<input type="button" class="button-primary" onclick="javascript:jQuery('#group-<?php 
        echo $group->group_id;
        ?>
').html('');jQuery('#grouprow-<?php 
        echo $groupId;
        ?>
').removeClass('inForm');" id="sforder<?php 
        echo $group->group_id;
        ?>
" name="groupordercancel<?php 
        echo $group->group_id;
        ?>
" value="<?php 
        spa_etext('Cancel');
        ?>
" />
        <?php 
    }
    ?>

		</div>
	</form>
<?php 
    spa_paint_close_tab();
    ?>
	<div class="sfform-panel-spacer"></div>
<?php 
}
function sp_tidy_install_log()
{
    $log = spdb_table(SFLOG, '', '', 'id DESC');
    $ver = 0;
    if ($log) {
        foreach ($log as $l) {
            if ($l->version != $ver) {
                $ver = $l->version;
            } else {
                spdb_query('DELETE FROM ' . SFLOG . ' WHERE id=' . $l->id);
            }
        }
    }
}
function spa_save_usergroups_delete_usergroup()
{
    check_admin_referer('forum-adminform_usergroupdelete', 'forum-adminform_usergroupdelete');
    $usergroup_id = sp_esc_int($_POST['usergroup_id']);
    # dont allow updates to the default user groups
    $usergroup = spa_get_usergroups_row($usergroup_id);
    if ($usergroup->usergroup_locked) {
        $mess = spa_text('Sorry, the default User Groups cannot be deleted');
        return $mess;
    }
    # remove all memberships for this user group
    spdb_query("DELETE FROM " . SFMEMBERSHIPS . " WHERE usergroup_id=" . $usergroup_id);
    # remove any permission sets using this user group
    $permissions = spdb_table(SFPERMISSIONS, "usergroup_id={$usergroup_id}");
    if ($permissions) {
        foreach ($permissions as $permission) {
            spa_remove_permission_data($permission->permission_id);
        }
    }
    # remove any group default permissions using this user group
    spdb_query("DELETE FROM " . SFDEFPERMISSIONS . " WHERE usergroup_id=" . $usergroup_id);
    # remove the user group
    spdb_query("DELETE FROM " . SFMEMBERSHIPS . " WHERE usergroup_id=" . $usergroup_id);
    $success = spdb_query("DELETE FROM " . SFUSERGROUPS . " WHERE usergroup_id=" . $usergroup_id);
    if ($success == false) {
        $mess = spa_text('User group delete failed');
    } else {
        $mess = spa_text('User group deleted');
        # reset auths and memberships for everyone
        sp_reset_memberships();
        sp_reset_auths();
        do_action('sph_usergroup_del', $usergroup_id);
    }
    return $mess;
}
function spa_forums_check_memberships($forums)
{
    $value = sp_get_sfmeta('default usergroup', 'sfguests');
    $ugid = spdb_table(SFUSERGROUPS, "usergroup_id={$value[0]['meta_value']}", 'usergroup_id');
    if (empty($ugid)) {
        $ugid = 0;
    }
    $noMembers = array();
    foreach ($forums as $forum) {
        $has_members = false;
        $permissions = sp_get_forum_permissions($forum->forum_id);
        if ($permissions) {
            foreach ($permissions as $permission) {
                $members = spdb_table(SFMEMBERSHIPS, "usergroup_id= {$permission->usergroup_id}", 'row', '', '1');
                if ($members || $permission->usergroup_id == $ugid) {
                    $has_members = true;
                    break;
                }
            }
        }
        if (!$has_members) {
            $noMembers[] = $forum->forum_id;
        }
    }
    return $noMembers;
}
function sp_get_metakeywords()
{
    global $spVars;
    $keywords = '';
    $sfmetatags = sp_get_option('sfmetatags');
    $sfmetatags['sfkeywords'] = isset($sfmetatags['sfkeywords']) ? $sfmetatags['sfkeywords'] : '';
    if (!empty($sfmetatags['sfusekeywords'])) {
        if ($sfmetatags['sfusekeywords'] == 3) {
            if ($spVars['pageview'] == 'forum' || $spVars['pageview'] == 'topic') {
                $keywords = sp_filter_title_display(spdb_table(SFFORUMS, 'forum_id=' . $spVars['forumid'], 'keywords'));
            } else {
                $keywords = stripslashes($sfmetatags['sfkeywords']);
            }
        } else {
            if ($sfmetatags['sfusekeywords'] == 2) {
                $keywords = stripslashes($sfmetatags['sfkeywords']);
            }
        }
    }
    return apply_filters('sph_meta_keywords', $keywords);
}
function spa_check_warnings()
{
    global $spGlobals;
    # not perfect but we can use this call tyo perform any minor
    # cleanups that may be necessary... so
    # drop any existing temp members table...
    spdb_query('DROP TABLE IF EXISTS sftempmembers');
    $mess = '';
    # check if sp core, plugins or themes update available
    $update = false;
    $update_msg = '';
    $up = get_site_transient('update_plugins');
    if (!empty($up->response)) {
        foreach ($up->response as $plugin) {
            if ($plugin->slug == 'simple-press') {
                $msg = apply_filters('sph_core_update_notice', spa_text('There is a Simple:Press core update available.'));
                if (!empty($msg)) {
                    $update = true;
                    $update_msg .= $msg . '<br />';
                }
                break;
            }
        }
    }
    $up = get_site_transient('sp_update_plugins');
    if (!empty($up)) {
        $msg = apply_filters('sph_plugins_update_notice', spa_text('There is one or more Simple:Press plugin updates available'));
        if (!empty($msg)) {
            $update = true;
            $update_msg .= $msg . '<br />';
        }
    }
    $up = get_site_transient('sp_update_themes');
    if (!empty($up)) {
        $msg = apply_filters('sph_themes_update_notice', spa_text('There is one or more Simple:Press theme updates available'));
        if (!empty($msg)) {
            $update = true;
            $update_msg .= $msg . '<br />';
        }
    }
    if ($update) {
        if (is_main_site()) {
            $mess .= apply_filters('sph_updates_notice', spa_message($update_msg . '<a href="' . self_admin_url('update-core.php') . '">' . spa_text('Click here to view any updates.') . '</a>'));
        } else {
            $mess .= apply_filters('sph_updates_notice', spa_message(spa_text('There are some Simple:Press updates avaialable. You may want to notify the network site admin.')));
        }
    }
    # output warning if no SPF admins are defined
    $a = $spGlobals['forum-admins'];
    if (empty($a)) {
        $mess .= spa_message(spa_text('Warning - There are no SPF admins defined!	 All WP admins now have SP backend access'), 'error');
    }
    # Check if	desktop, tablet and mobile themes are selected and available
    $cur = sp_get_option('sp_current_theme');
    if (empty($cur)) {
        $mess .= spa_message(spa_text('No main theme has been selected and SP will be unable to display correctly. Please select a theme from the Themes panel'), 'error');
    } else {
        $nostylesheet = !file_exists(SPTHEMEBASEDIR . $cur['theme'] . '/styles/' . $cur['style']);
        $nooverlay = !empty($cur['color']) && !file_exists(SPTHEMEBASEDIR . $cur['theme'] . '/styles/overlays/' . $cur['color'] . '.php');
        $nopoverlay = !empty($cur['color']) && !empty($cur['parent']) && !file_exists(SPTHEMEBASEDIR . $cur['parent'] . '/styles/overlays/' . $cur['color'] . '.php');
        if ($nostylesheet || $nooverlay && $nopoverlay) {
            $mess .= spa_message(spa_text('Either the theme CSS file and/or color Overlay file from the selected theme is missing'), 'error');
        }
    }
    $mobile = sp_get_option('sp_mobile_theme');
    if (!empty($mobile) && $mobile['active']) {
        $nostylesheet = !file_exists(SPTHEMEBASEDIR . $mobile['theme'] . '/styles/' . $mobile['style']);
        $nooverlay = !empty($mobile['color']) && !file_exists(SPTHEMEBASEDIR . $mobile['theme'] . '/styles/overlays/' . $mobile['color'] . '.php');
        $nopoverlay = !empty($mobile['color']) && !empty($mobile['parent']) && !file_exists(SPTHEMEBASEDIR . $mobile['parent'] . '/styles/overlays/' . $mobile['color'] . '.php');
        if ($nostylesheet || $nooverlay && $nopoverlay) {
            $mess .= spa_message(spa_text('Either the mobile theme CSS file and/or color Overlay file from the selected mobile theme is missing'), 'error');
        }
    }
    $tablet = sp_get_option('sp_tablet_theme');
    if (!empty($tablet) && $tablet['active']) {
        $nostylesheet = !file_exists(SPTHEMEBASEDIR . $tablet['theme'] . '/styles/' . $tablet['style']);
        $nooverlay = !empty($tablet['color']) && !file_exists(SPTHEMEBASEDIR . $tablet['theme'] . '/styles/overlays/' . $tablet['color'] . '.php');
        $nopoverlay = !empty($tablet['color']) && !empty($tablet['parent']) && !file_exists(SPTHEMEBASEDIR . $tablet['parent'] . '/styles/overlays/' . $tablet['color'] . '.php');
        if ($nostylesheet || $nooverlay && $nopoverlay) {
            $mess .= spa_message(spa_text('Either the tablet theme CSS file and/or color Overlay file from the selected tablet theme is missing'), 'error');
        }
    }
    # check for missing default members user group
    $value = sp_get_sfmeta('default usergroup', 'sfmembers');
    $ugid = spdb_table(SFUSERGROUPS, "usergroup_id={$value[0]['meta_value']}", 'usergroup_id');
    if (empty($ugid)) {
        $mess .= spa_message(spa_text('Warning - The default user group for new members is undefined!	Please visit the SP usergroups admin page, map users to usergroups tab and set the default user group'), 'error');
    }
    # check for missing default guest user group
    $value = sp_get_sfmeta('default usergroup', 'sfguests');
    $ugid = spdb_table(SFUSERGROUPS, "usergroup_id={$value[0]['meta_value']}", 'usergroup_id');
    if (empty($ugid)) {
        $mess .= spa_message(spa_text('Warning - The default user group for guests is undefined!  Please visit the SP usergroups admin page, map users to usergroups tab and set the default user group'), 'error');
    }
    # check for unreachable forums because of permissions
    $done = 0;
    $usergroups = spdb_table(SFUSERGROUPS);
    if ($usergroups) {
        $has_members = false;
        foreach ($usergroups as $usergroup) {
            $members = spdb_table(SFMEMBERSHIPS, "usergroup_id={$usergroup->usergroup_id}", 'row', '', '1');
            if ($members || $usergroup->usergroup_id == $value[0]['meta_value']) {
                $has_members = true;
                break;
            }
        }
        if (!$has_members) {
            $mess .= spa_message(spa_text('Warning - There are no usergroups that have members!	All forums may only be visible to SP admins'), 'error');
            $done = 1;
        }
    } else {
        $mess .= spa_message(spa_text('Warning - There are no usergroups defined!  All forums may only be visible to SP admins'), 'error');
        $done = 1;
    }
    $roles = sp_get_all_roles();
    if (!$roles) {
        $mess .= spa_message(spa_text('Warning - There are no permission sets defined!  All forums may only be visible to SP admins'), 'error');
        $done = 1;
    }
    # check if compatible with wp super cache
    if (function_exists('wp_cache_edit_rejected')) {
        global $cache_rejected_uri;
        $slug = '/' . sp_get_option('sfslug') . '/';
        if (isset($cache_rejected_uri)) {
            $found = false;
            foreach ($cache_rejected_uri as $value) {
                if ($value == $slug) {
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                $string = spa_text('WP Super Cache is not properly configured to work with Simple:Press. Please visit your WP Super Cache settings page and in the accepted filenames & rejected URIs section for the pages not to be cached input field, add the following string');
                $string .= ':<br /><br />' . $slug . '<br /><br />';
                $string .= spa_text('Then, please clear your WP Super Cache cache to remove any cached Simple:Press pages');
                $mess .= spa_message($string, 'error');
            }
        }
    }
    if ($mess != '') {
        return $mess;
    }
}
function sp_process_profileshow_view()
{
    global $spVars, $spThisUser;
    if (!empty($spVars['member'])) {
        $userid = (int) $spVars['member'];
        $userid = spdb_table(SFMEMBERS, "user_id={$userid}", 'user_id');
    } else {
        $userid = $spThisUser->ID;
    }
    if (!sp_get_auth('view_profiles') || empty($userid) || $userid < 0) {
        sp_notify(SPFAILURE, sp_text('Invalid profile request'));
        return 'spDefault.php';
    } else {
        global $spProfileUser;
        sp_SetupUserProfileData();
        return 'spProfileShow.php';
    }
}
 function __construct($ident = 0, $current = false, $small = false)
 {
     global $spStatus, $spGlobals;
     $id = 0;
     if (is_numeric($ident)) {
         $w = "ID={$ident}";
     } else {
         if ($ident != false) {
             $w = "user_login='******'";
         }
     }
     if ($ident) {
         # Users data
         $d = spdb_table(SFUSERS, $w, 'row');
         if ($d) {
             $this->ID = $d->ID;
             $id = $d->ID;
         }
     }
     $includeList = spUser_build_filter_list();
     if ($id) {
         # Others
         $this->member = true;
         $this->guest = 0;
         $this->guest_name = '';
         $this->guest_email = '';
         $this->offmember = false;
         $this->usertype = 'User';
         # Users data
         foreach ($d as $key => $item) {
             if (array_key_exists($key, $includeList)) {
                 $this->{$key} = $item;
             }
         }
         $this->user_registered = sp_member_registration_to_server_tz($this->user_registered);
         # usermeta data
         $d = spdb_table(SFUSERMETA, "user_id={$id}");
         if ($d) {
             foreach ($d as $m) {
                 $t = $m->meta_key;
                 if (array_key_exists($t, $includeList)) {
                     $this->{$t} = maybe_unserialize($m->meta_value);
                 }
             }
         }
         # If awaiting installation then dive out now to avoid errors
         if ($spStatus == 'Install') {
             return;
         }
         # sfmembers data
         $d = spdb_table(SFMEMBERS, "user_id={$id}", 'row');
         #check for ghost user
         if (empty($d)) {
             #create the member
             sp_create_member_data($id);
             $d = spdb_table(SFMEMBERS, "user_id={$id}", 'row');
         }
         if ($d) {
             foreach ($d as $key => $item) {
                 if ($key == 'admin_options' && !empty($item)) {
                     $opts = unserialize($item);
                     foreach ($opts as $opt => $set) {
                         $this->{$opt} = $set;
                     }
                 } else {
                     if ($key == 'user_options' && !empty($item)) {
                         $opts = unserialize($item);
                         foreach ($opts as $opt => $set) {
                             $this->{$opt} = $set;
                         }
                     } else {
                         if ($key == 'lastvisit') {
                             $this->lastvisit = $item;
                         } else {
                             $this->{$key} = maybe_unserialize($item);
                         }
                     }
                 }
             }
         }
         # Check for new post list size
         if (!isset($this->unreadposts) || empty($this->unreadposts)) {
             $controls = sp_get_option('sfcontrols');
             $this->unreadposts = empty($controls['sfunreadposts']) ? 50 : $controls['sfunreadposts'];
         }
         # usertype for moderators
         if ($this->moderator) {
             $this->usertype = 'Moderator';
         }
         # check for super admins and make admin a moderator as well
         if ($this->admin || is_multisite() && is_super_admin($id)) {
             $this->admin = true;
             $this->moderator = true;
             $this->usertype = 'Admin';
             $ins = sp_get_option('spInspect');
             if (!empty($ins) && array_key_exists($id, $ins)) {
                 $this->inspect = $ins[$id];
             } else {
                 $this->inspect = '';
             }
         }
         # plugins can add iterms for members...
         if (!$small) {
             do_action_ref_array('sph_user_class_member', array(&$this));
         } else {
             do_action_ref_array('sph_user_class_member_small', array(&$this));
         }
     } else {
         # some basics for guests
         $this->ID = 0;
         $this->guest = true;
         $this->member = 0;
         $this->admin = false;
         $this->moderator = false;
         $this->display_name = 'guest';
         $this->guest_name = '';
         $this->guest_email = '';
         $this->usertype = 'Guest';
         $this->offmember = sp_check_unlogged_user();
         $this->timezone = 0;
         $this->timezone_string = '';
         $this->posts = 0;
         $this->avatar = '';
         $this->user_email = '';
         $this->auths = sp_get_option('sf_guest_auths');
         $this->memberships = sp_get_option('sf_guest_memberships');
         # plugins can add iterms for guests...
         if (!$small) {
             do_action_ref_array('sph_user_class_guest', array(&$this));
         } else {
             do_action_ref_array('sph_user_class_guest_small', array(&$this));
         }
     }
     # Only perform this last section if forum is operational
     if ($spStatus == 'ok') {
         # Ranking
         $this->rank = sp_get_user_forum_rank($this->usertype, $id, $this->posts);
         $this->special_rank = $this->member ? sp_get_user_special_ranks($id) : array();
         # if no memberships rebuild them and save
         if (empty($this->memberships)) {
             $memberships = array();
             if (!empty($id)) {
                 if (!$this->admin) {
                     # get the usergroup memberships for the user and save in sfmembers table
                     $memberships = sp_get_user_memberships($id);
                     sp_update_member_item($id, 'memberships', $memberships);
                 }
             } else {
                 # user is a guest or unassigned member so get the global permissions from the guest usergroup and save as option
                 $value = sp_get_sfmeta('default usergroup', 'sfguests');
                 $memberships[] = spdb_table(SFUSERGROUPS, 'usergroup_id=' . $value[0]['meta_value'], 'row', '', '', ARRAY_A);
                 sp_update_option('sf_guest_memberships', $memberships);
             }
             # put in the data
             $this->memberships = $memberships;
         }
         # if no auths rebuild them and save
         if (empty($this->auths)) {
             $this->auths = sp_rebuild_user_auths($id);
         }
     }
     $this->ip = sp_get_ip();
     $this->trackid = -1;
     # Things to do if user is current user
     if ($current) {
         # Set up editor type
         $spGlobals['editor'] = 0;
         # for a user...
         if ($this->member && !empty($this->editor)) {
             $spGlobals['editor'] = $this->editor;
         }
         # and if not defined or is for a guest...
         if ($spGlobals['editor'] == 0) {
             $defeditor = sp_get_option('speditor');
             if (!empty($defeditor)) {
                 $spGlobals['editor'] = $defeditor;
             }
         }
         # final check to ensure selected editor type is indeed available
         if ($spGlobals['editor'] == 0 || $spGlobals['editor'] == 1 && !defined('RICHTEXT') || $spGlobals['editor'] == 2 && !defined('HTML') || $spGlobals['editor'] == 3 && !defined('BBCODE')) {
             $spGlobals['editor'] = PLAINTEXT;
             if (defined('BBCODE')) {
                 $spGlobals['editor'] = BBCODE;
             }
             if (defined('HTML')) {
                 $spGlobals['editor'] = HTML;
             }
             if (defined('RICHTEXT')) {
                 $spGlobals['editor'] = RICHTEXT;
             }
         }
         # Grab any notices present
         if ($this->guest && !empty($this->guest_email)) {
             $this->user_notices = spdb_table(SFNOTICES, "guest_email='" . $this->guest_email . "'", '', $order = 'notice_id');
         } elseif ($this->member && !empty($this->user_email)) {
             $this->user_notices = spdb_table(SFNOTICES, "user_id=" . $this->ID, '', $order = 'notice_id');
         }
         # plugins can add iterms for the current user (so no small allowed here)
         do_action_ref_array('sph_current_user_class', array(&$this));
     }
     # Finally filter the data for display
     foreach ($includeList as $item => $filter) {
         if (property_exists($this, $item)) {
             $this->{$item} = spUser_filter_item($this->{$item}, $filter);
         }
     }
     # allow plugins to add items to user class - regardless small or otherwise, current or otherwise
     do_action_ref_array('sph_user_class', array(&$this));
 }
function spa_admins_manage_admins_form()
{
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	spjAjaxForm('sfupdatecaps', 'sfreloadma');
    	spjAjaxForm('sfaddadmins', 'sfreloadma');
    });
</script>
<?php 
    global $spThisUser, $spGlobals;
    $adminsexist = false;
    $adminrecords = $spGlobals['forum-admins'];
    # get all the moderators
    $modrecords = array();
    $mods = spdb_table(SFMEMBERS, 'moderator=1');
    if ($mods) {
        foreach ($mods as $mod) {
            $modrecords[$mod->user_id] = $mod->display_name;
        }
    }
    spa_paint_options_init();
    if ($adminrecords || $modrecords) {
        $adminsexist = true;
        $ahahURL = SFHOMEURL . 'index.php?sp_ahah=admins-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=manageadmin';
        ?>
		<form action="<?php 
        echo $ahahURL;
        ?>
" method="post" id="sfupdatecaps" name="sfupdatecaps">
		<?php 
        echo sp_create_nonce('forum-adminform_sfupdatecaps');
        spa_paint_open_tab(spa_text('Admins') . " - " . spa_text('Manage Admins and Moderators'), true);
        spa_paint_open_panel();
        spa_paint_open_fieldset(spa_text('Current Admins and Moderators'), 'true', 'manage-admins');
        for ($x = 1; $x < 3; $x++) {
            $records = $x == 1 ? $adminrecords : $modrecords;
            if (empty($records)) {
                continue;
            }
            foreach ($records as $adminId => $adminName) {
                $user = new WP_User($adminId);
                $manage_opts = $user->has_cap('SPF Manage Options') ? 1 : 0;
                $manage_forums = $user->has_cap('SPF Manage Forums') ? 1 : 0;
                $manage_ugs = $user->has_cap('SPF Manage User Groups') ? 1 : 0;
                $manage_perms = $user->has_cap('SPF Manage Permissions') ? 1 : 0;
                $manage_comps = $user->has_cap('SPF Manage Components') ? 1 : 0;
                $manage_users = $user->has_cap('SPF Manage Users') ? 1 : 0;
                $manage_profiles = $user->has_cap('SPF Manage Profiles') ? 1 : 0;
                $manage_admins = $user->has_cap('SPF Manage Admins') ? 1 : 0;
                $manage_tools = $user->has_cap('SPF Manage Toolbox') ? 1 : 0;
                $manage_plugins = $user->has_cap('SPF Manage Plugins') ? 1 : 0;
                $manage_themes = $user->has_cap('SPF Manage Themes') ? 1 : 0;
                $manage_integration = $user->has_cap('SPF Manage Integration') ? 1 : 0;
                $title = $x == 1 ? spa_text('Admin') : spa_text('Moderator');
                spa_paint_open_fieldset($title . ': ' . $adminName, false);
                echo spa_text('ID') . ': ' . $adminId . ' - ' . spa_text('Name') . ': <strong>' . $adminName . '</strong>';
                ?>
								<input type="hidden" name="uids[]" value="<?php 
                echo $adminId;
                ?>
" />

								<ul class='floatList'>
									<li>
										<?php 
                spa_render_caps_checkbox(spa_text('Manage Options'), 'manage-opts[' . $adminId . ']', $manage_opts, $adminId);
                ?>
										<input type="hidden" name="old-opts[<?php 
                echo $adminId;
                ?>
]" value="<?php 
                echo $manage_opts;
                ?>
" />
									</li>
									<li>
										<?php 
                spa_render_caps_checkbox(spa_text('Manage Forums'), 'manage-forums[' . $adminId . ']', $manage_forums, $adminId);
                ?>
										<input type="hidden" name="old-forums[<?php 
                echo $adminId;
                ?>
]" value="<?php 
                echo $manage_forums;
                ?>
" />
									</li>
									<li>
										<?php 
                spa_render_caps_checkbox(spa_text('Manage User Groups'), 'manage-ugs[' . $adminId . ']', $manage_ugs, $adminId);
                ?>
										<input type="hidden" name="old-ugs[<?php 
                echo $adminId;
                ?>
]" value="<?php 
                echo $manage_ugs;
                ?>
" />
									</li>
									<li>
										<?php 
                spa_render_caps_checkbox(spa_text('Manage Permissions'), 'manage-perms[' . $adminId . ']', $manage_perms, $adminId);
                ?>
										<input type="hidden" name="old-perms[<?php 
                echo $adminId;
                ?>
]" value="<?php 
                echo $manage_perms;
                ?>
" />
									</li>
									<li>
										<?php 
                spa_render_caps_checkbox(spa_text('Manage Components'), 'manage-comps[' . $adminId . ']', $manage_comps, $adminId);
                ?>
										<input type="hidden" name="old-comps[<?php 
                echo $adminId;
                ?>
]" value="<?php 
                echo $manage_comps;
                ?>
" />
									</li>
									<li>
										<?php 
                spa_render_caps_checkbox(spa_text('Manage Plugins'), 'manage-plugins[' . $adminId . ']', $manage_plugins, $adminId);
                ?>
										<input type="hidden" name="old-plugins[<?php 
                echo $adminId;
                ?>
]" value="<?php 
                echo $manage_plugins;
                ?>
" />
									</li>
									<li>
										<?php 
                spa_render_caps_checkbox(spa_text('Manage Users'), 'manage-users[' . $adminId . ']', $manage_users, $adminId);
                ?>
										<input type="hidden" name="old-users[<?php 
                echo $adminId;
                ?>
]" value="<?php 
                echo $manage_users;
                ?>
" />
									</li>
									<li>
										<?php 
                spa_render_caps_checkbox(spa_text('Manage Toolbox'), 'manage-tools[' . $adminId . ']', $manage_tools, $adminId);
                ?>
										<input type="hidden" name="old-tools[<?php 
                echo $adminId;
                ?>
]" value="<?php 
                echo $manage_tools;
                ?>
" />
									</li>
									<li>
										<?php 
                spa_render_caps_checkbox(spa_text('Manage Profiles'), 'manage-profiles[' . $adminId . ']', $manage_profiles, $adminId);
                ?>
										<input type="hidden" name="old-profiles[<?php 
                echo $adminId;
                ?>
]" value="<?php 
                echo $manage_profiles;
                ?>
" />
									</li>
									<li>
										<?php 
                spa_render_caps_checkbox(spa_text('Manage Themes'), 'manage-themes[' . $adminId . ']', $manage_themes, $adminId);
                ?>
										<input type="hidden" name="old-themes[<?php 
                echo $adminId;
                ?>
]" value="<?php 
                echo $manage_themes;
                ?>
" />
									</li>
									<li>
										<?php 
                spa_render_caps_checkbox(spa_text('Manage Integration'), 'manage-integration[' . $adminId . ']', $manage_integration, $adminId);
                ?>
										<input type="hidden" name="old-integration[<?php 
                echo $adminId;
                ?>
]" value="<?php 
                echo $manage_integration;
                ?>
" />
									</li>
									<li>
<?php 
                if ($adminId == $spThisUser->ID) {
                    ?>
                                            <span class='floatListLabel'><?php 
                    echo spa_text('Manage Admins');
                    ?>
</span>
											<input type="hidden" name="manage-admins[<?php 
                    echo $adminId;
                    ?>
]" value="<?php 
                    echo $manage_admins;
                    ?>
" />
											<img src="<?php 
                    echo SFADMINIMAGES . 'sp_Locked.png';
                    ?>
" alt="" style="vertical-align:middle;padding:0 0 0 10px;margin:3px 0;" />
<?php 
                } else {
                    spa_render_caps_checkbox(spa_text('Manage Admins'), 'manage-admins[' . $adminId . ']', $manage_admins, $adminId);
                }
                ?>
										<input type="hidden" name="old-admins[<?php 
                echo $adminId;
                ?>
]" value="<?php 
                echo $manage_admins;
                ?>
" />
									</li>
<?php 
                do_action('sph_admin_caps_list', $user);
                ?>
      						</ul>

								<div class="clearboth"></div>
<?php 
                if ($adminId != $spThisUser->ID) {
                    echo '<hr />';
                    spa_render_caps_checkbox(spa_text('Remove All Capabilities from this') . ' ' . $title, 'remove-admin[' . $adminId . ']', '', $adminId);
                }
                spa_paint_close_fieldset();
            }
        }
        spa_paint_close_fieldset();
        spa_paint_close_panel();
        spa_paint_close_container();
    }
    ?>
	<div class="sfform-submit-bar">
	<input type="submit" class="button-primary" id="savecaps" name="savecaps" value="<?php 
    spa_etext('Update Admin Capabilities');
    ?>
" />
	</div>
<?php 
    spa_paint_close_tab();
    ?>
	</form>
	<div class="sfform-panel-spacer"></div>
<?php 
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=admins-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=addadmin';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfaddadmins" name="sfaddadmins">
	<?php 
    echo sp_create_nonce('forum-adminform_sfaddadmins');
    ?>

<?php 
    spa_paint_open_tab(spa_text('Manage Admins') . ' - ' . spa_text('Add Admins'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Add New Admins'), false);
    ?>
	<table style="text-align:center;padding:0;border-spacing:0;border-collapse:separate;" class="forum-table">
		<tr>
			<th style="text-align:center"><?php 
    spa_etext('Select New Admin Users');
    ?>
</th>
		</tr>
		<tr>
			<td style="text-align:center">
				<p style="text-align:center"><?php 
    spa_etext('Select members to make Admins (use CONTROL for multiple users)');
    ?>
</p>
<?php 
    $from = esc_js(spa_text('Eligible Members'));
    $to = esc_js(spa_text('Selected Members'));
    $action = 'addadmin';
    include_once SF_PLUGIN_DIR . '/admin/library/ahah/spa-ahah-multiselect.php';
    ?>
				<div class="clearboth"></div>
			</td>
		</tr>
	</table>

	<p><strong><?php 
    spa_etext('Select New Admin Capabilities');
    ?>
</strong></p>

	<ul class='floatList'>
		<li><?php 
    spa_render_caps_checkbox(spa_text('Manage Options'), 'add-opts', 0);
    ?>
</li>
		<li><?php 
    spa_render_caps_checkbox(spa_text('Manage Forums'), 'add-forums', 0);
    ?>
</li>
		<li><?php 
    spa_render_caps_checkbox(spa_text('Manage User Groups'), 'add-ugs', 0);
    ?>
</li>
		<li><?php 
    spa_render_caps_checkbox(spa_text('Manage Permissions'), 'add-perms', 0);
    ?>
</li>
		<li><?php 
    spa_render_caps_checkbox(spa_text('Manage Components'), 'add-comps', 0);
    ?>
</li>
		<li><?php 
    spa_render_caps_checkbox(spa_text('Manage Users'), 'add-users', 0);
    ?>
</li>
		<li><?php 
    spa_render_caps_checkbox(spa_text('Manage Profiles'), 'add-profiles', 0);
    ?>
</li>
		<li><?php 
    spa_render_caps_checkbox(spa_text('Manage Admins'), 'add-admins', 0);
    ?>
</li>
		<li><?php 
    spa_render_caps_checkbox(spa_text('Manage Toolbox'), 'add-tools', 0);
    ?>
</li>
		<li><?php 
    spa_render_caps_checkbox(spa_text('Manage Plugins'), 'add-plugins', 0);
    ?>
</li>
		<li><?php 
    spa_render_caps_checkbox(spa_text('Manage Themes'), 'add-themes', 0);
    ?>
</li>
		<li><?php 
    spa_render_caps_checkbox(spa_text('Manage Integration'), 'add-integration', 0);
    ?>
</li>
		<?php 
    do_action('sph_admin_caps_form', $user);
    ?>
	</ul>
<?php 
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('WP Admins but not Forum Admins'), false);
    ?>
	<table style="text-align:center;width:auto;padding:0;border-spacing:0;border-collapse:separate;" class="sfmaintable">
		<tr>
			<th style="text-align:center;width:30px" scope="col"></th>
			<th style="text-align:center"><?php 
    spa_etext('User ID');
    ?>
</th>
			<th style="text-align:center" scope="col"><?php 
    spa_etext('Admin Name');
    ?>
</th>
			<th style="text-align:center;width:30px" scope="col"></th>
		</tr>
<?php 
    $wp_admins = new SP_User_Search('', '', 'administrator');
    $is_users = false;
    for ($x = 0; $x < count($wp_admins->results); $x++) {
        $username = spdb_table(SFMEMBERS, 'admin=0 AND user_id=' . $wp_admins->results[$x], 'display_name');
        if ($username) {
            echo '<tr>';
            echo '<td></td>';
            echo '<td style="text-align:center">';
            echo $wp_admins->results[$x];
            echo '</td>';
            echo '<td>';
            echo esc_html($username);
            echo '</td>';
            echo '<td></td>';
            echo '</tr>';
            $is_users = true;
        }
    }
    if (!$is_users) {
        echo '<tr>';
        echo '<td></td>';
        echo '<td colspan="2">';
        spa_etext('No WP administrators that are not SPF admins were found');
        echo '</td>';
        echo '<td></td>';
        echo '</tr>';
    }
    ?>
	</table>
<?php 
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_admins_manage_panel');
    spa_paint_close_container();
    ?>
	<div class="sfform-submit-bar">
	<input type="submit" class="button-primary" id="savenew" name="savenew" value="<?php 
    spa_etext('Add New Admins');
    ?>
" />
	</div>
<?php 
    spa_paint_close_tab();
    ?>
	</form>
<?php 
}
function spa_get_defpermissions_role($group_id, $usergroup_id)
{
    return spdb_table(SFDEFPERMISSIONS, "group_id={$group_id} AND usergroup_id={$usergroup_id}", 'permission_role');
}
<?php

/*
Simple:Press
DESC:
$LastChangedDate: 2014-06-21 20:33:29 -0700 (Sat, 21 Jun 2014) $
$Rev: 11585 $
*/
# ==========================================================================================
#
# 	FORUM PAGE
#	This file loads for forum page loads only
#
# ==========================================================================================
global $spStatus;
$redirect = isset($_SERVER['REDIRECT_URL']) ? $_SERVER['REDIRECT_URL'] : '';
if (!defined('SPMEMBERLIST')) {
    define('SPMEMBERLIST', sp_url('members'));
}
# hack to get around wp_list_pages() bug
if ($spStatus == 'ok') {
    # go for whole row so it gets cached.
    $t = spdb_table(SFWPPOSTS, 'ID=' . sp_get_option('sfpage'), 'row');
    if (!defined('SFPAGETITLE')) {
        define('SFPAGETITLE', $t->post_title);
    }
}
do_action('sph_forum_constants');