function sp_PostIndexEditHistory($args = '', $label = '', $legend = '', $toolTip = '')
{
    global $spThisPost;
    if (empty($spThisPost->edits) || empty($legend)) {
        return;
    }
    $defs = array('tagId' => 'spPostIndexEditHistory%ID%', 'tagClass' => 'spButton', 'icon' => 'sp_EditHistory.png', 'iconClass' => 'spIcon', 'popup' => 1, 'count' => 0, 'echo' => 1, 'get' => 0);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_PostIndexEditHistory_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $tagId = esc_attr($tagId);
    $tagClass = esc_attr($tagClass);
    $icon = sanitize_file_name($icon);
    $iconClass = esc_attr($iconClass);
    $toolTip = sp_filter_title_display($toolTip);
    $popup = (int) $popup;
    $count = (int) $count;
    $echo = (int) $echo;
    $get = (int) $get;
    $tagId = str_ireplace('%ID%', $spThisPost->post_id, $tagId);
    if ($get) {
        return $spThisPost->edits;
    }
    # build history to show
    $edits = empty($count) ? $spThisPost->edits : array_slice($spThisPost->edits, max(count($spThisPost->edits) - $count, 0), $count);
    # Construct text
    if ($edits) {
        $history = '<p>';
        foreach ($edits as $edit) {
            $thisLegend = str_replace('%USER%', $edit->by, $legend);
            $thisLegend = str_replace('%DATE%', sp_apply_timezone($edit->at), $thisLegend);
            $history .= $thisLegend . '<br />';
        }
        $history .= '</p>';
    }
    if ($popup) {
        $out = "<a class='{$tagClass}' id='{$tagId}' title='{$toolTip}' rel='nofollow' href='javascript:void(null)' ";
        $out .= "onclick='spjDialogHtml(this, \"{$history}\", \"{$toolTip}\", 400, 0, 0);'>";
        if (!empty($icon)) {
            $out .= sp_paint_icon($iconClass, SPTHEMEICONSURL, $icon);
        }
        if (!empty($label)) {
            $out .= sp_filter_title_display($label);
        }
        $out .= "</a>\n";
    } else {
        $out .= "<div id='{$tagId}' class='{$tagClass}'>{$history}</div>\n";
    }
    $out = apply_filters('sph_PostIndexEditHistory', $out, $a);
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}
function sp_destroy_users_newposts($forumid = '')
{
    global $spThisUser;
    if (empty($forumid) || empty($spThisUser->newposts['topics'])) {
        $newPostList = array();
        $newPostList['topics'] = array();
        $newPostList['forums'] = array();
        $spThisUser->newposts = '';
    } else {
        $newPostList = $spThisUser->newposts;
        foreach ($spThisUser->newposts['forums'] as $index => $forum) {
            if ($forum == $forumid) {
                unset($newPostList['topics'][$index]);
                unset($newPostList['forums'][$index]);
            }
        }
        $newPostList['topics'] = array_values($newPostList['topics']);
        $newPostList['forums'] = array_values($newPostList['forums']);
        $spThisUser->newposts = $newPostList;
    }
    sp_update_member_item($spThisUser->ID, 'newposts', $newPostList);
    sp_update_member_item($spThisUser->ID, 'checktime', 0);
    sp_set_server_timezone();
    $spThisUser->checktime = sp_apply_timezone(time(), 'mysql');
}
Esempio n. 3
0
function sp_show_properties()
{
    global $spThisUser;
    $forumid = sp_esc_int($_GET['forum']);
    $topicid = sp_esc_int($_GET['topic']);
    if (empty($forumid) || empty($topicid)) {
        die;
    }
    $thistopic = spdb_table(SFTOPICS, "topic_id={$topicid}", 'row');
    if (!$spThisUser->admin && !$spThisUser->moderator) {
        if (!is_user_logged_in()) {
            sp_etext('Access denied - are you logged in?');
        } else {
            sp_etext('Access denied - you do not have permission');
        }
        die;
    }
    $thisforum = spdb_table(SFFORUMS, "forum_id={$forumid}", 'row');
    if (isset($_GET['post'])) {
        $groupid = sp_esc_int($thisforum->group_id);
        $thisgroup = spdb_table(SFGROUPS, "group_id={$groupid}", 'row');
    } else {
        $groupid = sp_esc_int($_GET['group']);
        if (empty($groupid)) {
            die;
        }
        $thisgroup = spdb_table(SFGROUPS, "group_id={$groupid}", 'row');
    }
    $posts = spdb_table(SFPOSTS, "topic_id={$thistopic->topic_id}", '', 'post_id');
    if ($posts) {
        $first = $posts[0]->post_id;
        $last = $posts[count($posts) - 1]->post_id;
    }
    # set timezone onto the started date
    $topicstart = sp_apply_timezone($thistopic->topic_date);
    ?>
	<div id="spMainContainer">
	<table class="spPopupTable">
		<tr><td class="spLabel" style="width:35%"><?php 
    sp_etext('Group ID');
    ?>
</td><td colspan="2" class="spLabel"><?php 
    echo $thisgroup->group_id;
    ?>
</td></tr>
		<tr><td class="spLabel"><?php 
    sp_etext('Group Title');
    ?>
</td><td colspan="2" class="spLabel"><?php 
    echo sp_filter_title_display($thisgroup->group_name);
    ?>
</td></tr>
		<tr><td class="spLabel"><?php 
    sp_etext('Forum ID');
    ?>
</td><td class="spLabel"><?php 
    echo $thisforum->forum_id;
    ?>
</td><td class="sfdata"><?php 
    echo sp_rebuild_forum_form($thisforum->forum_id, $thistopic->topic_id, $thisforum->forum_slug, $thistopic->topic_slug);
    ?>
</td></tr>
		<tr><td class="spLabel"><?php 
    sp_etext('Forum Title');
    ?>
</td><td colspan="2" class="spLabel"><?php 
    echo sp_filter_title_display($thisforum->forum_name);
    ?>
</td></tr>
		<tr><td class="spLabel"><?php 
    sp_etext('Forum Slug');
    ?>
</td><td colspan="2" class="spLabel"><?php 
    echo $thisforum->forum_slug;
    ?>
</td></tr>
		<tr><td class="spLabel"><?php 
    sp_etext('Topics in Forum');
    ?>
</td><td colspan="2" class="spLabel"><?php 
    echo $thisforum->topic_count;
    ?>
</td></tr>
		<tr><td class="spLabel"><?php 
    sp_etext('Topic ID');
    ?>
</td><td class="spLabel"><?php 
    echo $thistopic->topic_id;
    ?>
</td><td class="sfdata"><?php 
    echo sp_rebuild_topic_form($thisforum->forum_id, $thistopic->topic_id, $thisforum->forum_slug, $thistopic->topic_slug);
    ?>
</td></tr>
		<tr><td class="spLabel"><?php 
    sp_etext('Topic Title');
    ?>
</td><td colspan="2" class="spLabel"><?php 
    echo sp_filter_title_display($thistopic->topic_name);
    ?>
</td></tr>
		<tr><td class="spLabel"><?php 
    sp_etext('Topic Slug');
    ?>
</td><td colspan="2" class="spLabel"><?php 
    echo $thistopic->topic_slug;
    ?>
</td></tr>
		<tr><td class="spLabel"><?php 
    sp_etext('Posts in Topic');
    ?>
</td><td colspan="2" class="spLabel"><?php 
    echo $thistopic->post_count;
    ?>
</td></tr>

		<tr><td class="spLabel"><?php 
    sp_etext('Topic Started');
    ?>
</td><td colspan="2" class="spLabel"><?php 
    echo $topicstart;
    ?>
</td></tr>

		<tr><td class="spLabel"><?php 
    sp_etext('First Post ID');
    ?>
</td><td colspan="2" class="spLabel"><?php 
    echo $first;
    ?>
</td></tr>
		<tr><td class="spLabel"><?php 
    sp_etext('Last Post ID');
    ?>
</td><td colspan="2" class="spLabel"><?php 
    echo $last;
    ?>
</td></tr>
<?php 
    if (isset($_GET['post'])) {
        $postid = sp_esc_int($_GET['post']);
        $post = spdb_table(SFPOSTS, "post_id={$postid}");
        ?>
			<tr><td class="spLabel"><?php 
        sp_etext('This Post ID');
        ?>
</td><td colspan="2" class="spLabel"><?php 
        echo $postid;
        ?>
</td></tr>
			<tr><td class="spLabel"><?php 
        sp_etext('Poster ID');
        ?>
</td><td colspan="2" class="spLabel"><?php 
        echo $post[0]->user_id;
        ?>
</td></tr>
			<tr><td class="spLabel"><?php 
        sp_etext('Poster IP');
        ?>
</td><td colspan="2" class="spLabel"><?php 
        echo $post[0]->poster_ip;
        ?>
</td></tr>
<?php 
    }
    ?>
	</table>
	</div>
<?php 
}
Esempio n. 4
0
function sp_update_member_item($userid, $itemname, $itemdata)
{
    global $wpdb, $spThisUser, $current_user;
    $userid = (int) $userid;
    # hive off for cache updating if current user
    $itemdata = "'" . maybe_serialize($itemdata) . "'";
    # set 'lastvisit' or 'checktime' to 'now'
    if ($itemname == 'lastvisit' || $itemname == 'checktime') {
        sp_set_server_timezone();
        $itemdata = "'" . sp_apply_timezone(time(), 'mysql', $userid) . "'";
    }
    $sql = 'UPDATE ' . SFMEMBERS . " SET {$itemname} = {$itemdata} WHERE user_id={$userid}";
    $sql = apply_filters('sph_memberdata_update_query', $sql, $itemname, $itemdata, $userid);
    $updateditem = $wpdb->query($sql);
    # allow plugins to add data
    do_action('sph_memberdata_update', $userid, $itemname, $itemdata);
    return $updateditem;
}
function sp_nicedate($postdate)
{
    # Passed in post date/time
    if (empty($postdate)) {
        return;
    } else {
        $unix_date = strtotime($postdate);
    }
    # Get current server date.time and adjust for users local timezone
    $now = time();
    $now = sp_apply_timezone($now, 'timestamp');
    $difference = $now - $unix_date;
    # set up period labels
    $periods = array(sp_text('second'), sp_text('minute'), sp_text('hour'), sp_text('yesterday'), sp_text('week'), sp_text('month'), sp_text('year'), sp_text('decade'));
    $lengths = array('60', '60', '24', '7', '4.35', '12', '10');
    $tense = sp_text('ago');
    for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths) - 1; $j++) {
        $difference /= $lengths[$j];
    }
    $difference = round($difference);
    if ($difference != 1) {
        $periods = array(sp_text('seconds'), sp_text('minutes'), sp_text('hours'), sp_text('days'), sp_text('weeks'), sp_text('months'), sp_text('years'), sp_text('decades'));
    }
    # Special conditions
    if ($difference == 1 && $j == 3) {
        return $periods[$j];
    } else {
        $nd = "{$difference} {$periods[$j]} {$tense}";
        return apply_filters('sph_nicedate', $nd, $difference, $periods[$j], $tense);
    }
}
    function sp_memberslist_query($groupBy, $orderBy, $sortBy, $number, $limitUG, $ugids)
    {
        global $spThisUser, $spVars, $wpdb;
        # check for page
        $page = isset($_GET['page']) ? sp_esc_int($_GET['page']) : $spVars['page'];
        # check for member search
        $search = !empty($_POST['msearch']) && !isset($_POST['allmembers']) ? sp_esc_str($_POST['msearch']) : '';
        $search = !empty($_GET['msearch']) ? sp_esc_str($_GET['msearch']) : $search;
        # check for usergroup selection query arg
        $ug_select = !empty($_POST['ug']) && !isset($_POST['allmembers']) ? sp_esc_int($_POST['ug']) : '';
        $ug_select = !empty($_GET['ug']) ? sp_esc_int($_GET['ug']) : $ug_select;
        # check for constructor limiting usergroups
        if ($groupBy == 'usergroup' && !empty($ugids)) {
            $ugids = explode(',', sp_esc_str($ugids));
        }
        $data = new stdClass();
        $data->records = new stdClass();
        $data->count = 0;
        if ($spThisUser->admin || sp_get_auth('view_members_list')) {
            # default to 'no data'
            $this->membersListStatus = 'no data';
            # are we limiting member lists to user group memberships?
            $where = 'posts > -2';
            if ($groupBy == 'usergroup' && !$spThisUser->admin) {
                # if limiting to memberships, get usergroups current user has membership in
                if ($limitUG) {
                    $ugs = sp_get_user_memberships($spThisUser->ID);
                    if (empty($ugs)) {
                        $value = sp_get_sfmeta('default usergroup', 'sfguests');
                        $sql = 'SELECT * FROM ' . SFUSERGROUPS . " WHERE usergroup_id={$value[0]['meta_value']}";
                        $ugs = spdb_select('set', $sql, ARRAY_A);
                    }
                    # Now add any moderator user groups who can moderate the current users forums
                    $forums = sp_get_forum_memberships($spThisUser->ID);
                    $forums = implode(',', $forums);
                    $sql = 'SELECT DISTINCT ' . SFMEMBERSHIPS . '.usergroup_id, usergroup_name, usergroup_desc, usergroup_join, usergroup_badge FROM ' . SFMEMBERSHIPS . '
					JOIN ' . SFUSERGROUPS . ' ON ' . SFUSERGROUPS . '.usergroup_id = ' . SFMEMBERSHIPS . '.usergroup_id
					JOIN ' . SFPERMISSIONS . ' ON ' . SFPERMISSIONS . ".forum_id IN ({$forums})\n\t\t\t\t\tWHERE usergroup_is_moderator=1 ORDER BY " . SFMEMBERSHIPS . '.usergroup_id';
                    $mugs = spdb_select('set', $sql, ARRAY_A);
                    if ($mugs) {
                        $ugs = array_merge($mugs, $ugs);
                    }
                } else {
                    $ugs = spdb_table(SFUSERGROUPS, '', '', '', '', ARRAY_A);
                }
                if (empty($ugs)) {
                    return $data;
                }
                # now build the where clause
                $ug_ids = array();
                foreach ($ugs as $index => $ug) {
                    if (empty($ugids) || in_array($ug['usergroup_id'], $ugids)) {
                        $ug_ids[] = $ug['usergroup_id'];
                    } else {
                        unset($ugs[$index]);
                    }
                }
                if (empty($ug_ids)) {
                    return $data;
                }
                $this->userGroups = array_values($ugs);
                # create where clause based on user memberships
                if (!$limitUG && empty($ugids) && empty($ug_select)) {
                    # not limiting by usergroup or specific ids so grab all users
                    $where .= ' AND (' . SFMEMBERSHIPS . '.usergroup_id IN (' . implode(',', $ug_ids) . ') OR ' . SFMEMBERSHIPS . '.usergroup_id IS NULL)';
                } else {
                    if (empty($ug_select)) {
                        # limiting by usergroup or specific ids, so only grab those users plus admins (skips users with no memmberships)
                        $where .= ' AND (' . SFMEMBERSHIPS . '.usergroup_id IN (' . implode(',', $ug_ids) . ') OR admin=1)';
                    } else {
                        $where .= ' AND (' . SFMEMBERSHIPS . ".usergroup_id = {$ug_select} AND " . SFMEMBERSHIPS . '.usergroup_id IN (' . implode(',', $ug_ids) . '))';
                    }
                }
            } else {
                if (!empty($ug_select)) {
                    $where .= ' AND ' . SFMEMBERSHIPS . ".usergroup_id = {$ug_select}";
                }
                $this->userGroups = spdb_table(SFUSERGROUPS, '', '', '', '', ARRAY_A);
            }
            if ($search != '') {
                $where .= ' AND ' . SFMEMBERS . '.display_name LIKE "' . esc_sql($wpdb->esc_like($search)) . '%"';
            }
            # how many members per page?
            $startlimit = 0;
            if ($page != 1) {
                $startlimit = ($page - 1) * $number;
            }
            $limit = $startlimit . ', ' . $number;
            $order = '';
            if ($groupBy == 'usergroup' && $orderBy == 'id') {
                $order .= "usergroup_id {$sortBy}, " . SFMEMBERS . ".display_name {$sortBy}";
            }
            if ($groupBy == 'usergroup' && $orderBy == 'alpha') {
                $order .= "usergroup_name {$sortBy}, " . SFMEMBERS . ".display_name {$sortBy}";
            }
            if ($groupBy == 'user' && $orderBy == 'id') {
                $order .= SFMEMBERS . ".user_id {$sortBy}";
            }
            if ($groupBy == 'user' && $orderBy == 'alpha') {
                $order .= SFMEMBERS . ".display_name {$sortBy}";
            }
            $join = SFUSERS . ' ON ' . SFMEMBERS . '.user_id=' . SFUSERS . '.ID ';
            if ($groupBy == 'usergroup') {
                $q = 'if (' . SFMEMBERS . '.admin=1, 0, IFNULL(' . SFMEMBERSHIPS . '.usergroup_id, 99999999)) AS usergroup_id,
					  if (' . SFMEMBERS . '.admin=1, "' . sp_text('Admins') . '", IFNULL(' . SFUSERGROUPS . '.usergroup_name, "' . sp_text('No Memberships') . '")) as usergroup_name,
					  if (' . SFMEMBERS . '.admin=1, "' . sp_text('Forum Administrators') . '", IFNULL(' . SFUSERGROUPS . '.usergroup_desc, "' . sp_text('Members without any usergroup memberships') . '")) as usergroup_desc,
					  ' . SFMEMBERS . '.user_id, ' . SFMEMBERS . '.display_name, admin, avatar, posts, lastvisit, user_registered, user_url, user_options';
                $join .= 'LEFT JOIN ' . SFMEMBERSHIPS . ' ON ' . SFMEMBERSHIPS . '.user_id=' . SFMEMBERS . '.user_id
						 LEFT JOIN ' . SFUSERGROUPS . ' ON ' . SFUSERGROUPS . '.usergroup_id=' . SFMEMBERSHIPS . '.usergroup_id';
            } else {
                $q = SFMEMBERS . '.user_id, ' . SFMEMBERS . '.display_name, admin, avatar, posts, lastvisit, user_registered, user_url, user_options';
            }
            # retrieve members list records
            $spdb = new spdbComplex();
            $spdb->table = SFMEMBERS;
            $spdb->fields = $q;
            $spdb->found_rows = true;
            $spdb->distinct = true;
            $spdb->left_join = $join;
            $spdb->where = $where;
            $spdb->orderby = $order;
            $spdb->limits = $limit;
            $spdb = apply_filters('sph_members_list_query', $spdb, $this);
            $records = $spdb->select();
            if ($records) {
                $m = array();
                $ugidx = -1;
                $midx = 0;
                $data->count = spdb_select('var', 'SELECT FOUND_ROWS()');
                foreach ($records as $r) {
                    # for user list only, set up dummy usergroup
                    if ($groupBy != 'usergroup') {
                        $ugidx = 0;
                    }
                    # we have data
                    $this->membersListStatus = 'data';
                    # set up the usergroup outer data and member inner data
                    if ($groupBy == 'usergroup' && ($ugidx == -1 || $m[$ugidx]->usergroup_id != $r->usergroup_id)) {
                        $ugidx++;
                        $midx = 0;
                        $m[$ugidx] = new stdClass();
                        $m[$ugidx]->usergroup_id = $r->usergroup_id;
                        $name = !empty($r->usergroup_name) ? sp_filter_title_display($r->usergroup_name) : sp_text('No Memberships');
                        $desc = !empty($r->usergroup_desc) ? sp_filter_title_display($r->usergroup_desc) : sp_text('Members without any usergroup memberships');
                        $m[$ugidx]->usergroup_name = $name;
                        $m[$ugidx]->usergroup_desc = $desc;
                        $m[$ugidx] = apply_filters('sph_members_list_records', $m[$ugidx], $r);
                    }
                    if (isset($r->user_id)) {
                        $m[$ugidx]->members[$midx] = new stdClass();
                        $m[$ugidx]->members[$midx]->user_id = $r->user_id;
                        $m[$ugidx]->members[$midx]->display_name = sp_filter_title_display($r->display_name);
                        $m[$ugidx]->members[$midx]->posts = $r->posts;
                        $m[$ugidx]->members[$midx]->user_url = $r->user_url;
                        $m[$ugidx]->members[$midx]->admin = $r->admin;
                        $m[$ugidx]->members[$midx]->avatar = unserialize($r->avatar);
                        $m[$ugidx]->members[$midx]->user_options = unserialize($r->user_options);
                        $m[$ugidx]->members[$midx]->lastvisit = sp_apply_timezone(sp_member_lastvisit_to_server_tz($r->lastvisit, $m[$ugidx]->members[$midx]->user_options), 'mysql');
                        $m[$ugidx]->members[$midx]->user_registered = sp_member_registration_to_server_tz($r->user_registered);
                        $m[$ugidx]->members[$midx] = apply_filters('sph_members_list_records', $m[$ugidx]->members[$midx], $r);
                        $midx++;
                    }
                }
                $data->records = $m;
            }
        } else {
            $this->membersListStatus = 'no access';
        }
        return $data;
    }
Esempio n. 7
0
function sp_destroy_users_newposts()
{
    global $spThisUser;
    $newPostList = array();
    $newPostList['topics'] = array();
    $newPostList['forums'] = array();
    sp_update_member_item($spThisUser->ID, 'newposts', $newPostList);
    sp_update_member_item($spThisUser->ID, 'checktime', 0);
    sp_set_server_timezone();
    $spThisUser->checktime = sp_apply_timezone(time(), 'mysql');
    $spThisUser->newposts = '';
}