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_get_members_info($userid) { $data = sp_get_member_row($userid); if (empty($data)) { return ''; } $first = spdb_select('row', ' SELECT ' . SFPOSTS . '.forum_id, forum_name, forum_slug, ' . SFPOSTS . '.topic_id, topic_name, topic_slug, post_date FROM ' . SFPOSTS . ' JOIN ' . SFTOPICS . ' ON ' . SFTOPICS . '.topic_id = ' . SFPOSTS . '.topic_id JOIN ' . SFFORUMS . ' ON ' . SFFORUMS . '.forum_id = ' . SFPOSTS . '.forum_id WHERE ' . SFPOSTS . ".user_id={$userid}\n\t\t\tORDER BY post_date ASC\n\t\t\tLIMIT 1"); if ($first) { $url = '<a href="' . sp_build_url($first->forum_slug, $first->topic_slug, 1, 0) . '">' . sp_filter_title_display($first->topic_name) . '</a>'; $data['first'] = sp_filter_title_display($first->forum_name) . '<br />' . $url . '<br />' . sp_date('d', $first->post_date); } else { $data['first'] = spa_text('No Posts'); } $last = spdb_select('row', ' SELECT ' . SFPOSTS . '.forum_id, forum_name, forum_slug, ' . SFPOSTS . '.topic_id, topic_name, topic_slug, post_date FROM ' . SFPOSTS . ' JOIN ' . SFTOPICS . ' ON ' . SFTOPICS . '.topic_id = ' . SFPOSTS . '.topic_id JOIN ' . SFFORUMS . ' ON ' . SFFORUMS . '.forum_id = ' . SFPOSTS . '.forum_id WHERE ' . SFPOSTS . ".user_id={$userid}\n\t\t\tORDER BY post_date DESC\n\t\t\tLIMIT 1"); if ($last) { $url = '<a href="' . sp_build_url($last->forum_slug, $last->topic_slug, 1, 0) . '">' . sp_filter_title_display($last->topic_name) . '</a>'; $data['last'] = sp_filter_title_display($last->forum_name) . '<br />' . $url . '<br />' . sp_date('d', $last->post_date); } else { $data['last'] = spa_text('No posts'); } if ($data['admin']) { $user_memberships = 'Admin'; $status = 'Admin'; $start = 0; } else { if ($data['moderator']) { $status = 'Moderator'; $start = 1; } else { $status = 'User'; $start = 1; } } $memberships = spdb_table(SFMEMBERSHIPS, "user_id={$userid}", '', '', '', ARRAY_A); if ($memberships) { foreach ($memberships as $membership) { $name = spdb_table(SFUSERGROUPS, 'usergroup_id=' . $membership['usergroup_id'], 'usergroup_name'); if ($start) { $user_memberships = $name; $start = 0; } else { $user_memberships .= ', ' . $name; } } } else { if ($start) { $user_memberships = 'No Memberships'; } } $data['memberships'] = $user_memberships; $rank = sp_get_user_forum_rank($status, $userid, $data['posts']); $data['rank'] = $rank[0]['name']; $user = get_userdata($userid); $data['login'] = $user->user_login; return $data; }
function sp_MemberListRank($args = '', $label = '') { global $spThisUser, $spThisMember; if (!sp_get_auth('view_members_list')) { return; } $defs = array('tagId' => 'spMembersListRank%ID%', 'tagClass' => 'spInRowCount', 'labelClass' => 'spInRowLabel', 'rank' => 1, 'rankClass' => 'spInRowRank', 'badge' => 1, 'badgeClass' => 'spImg', 'stack' => 1, 'echo' => 1, 'get' => 0); $a = wp_parse_args($args, $defs); $a = apply_filters('sph_MemberListRank_args', $a); extract($a, EXTR_SKIP); # sanitize before use $tagId = esc_attr($tagId); $tagClass = esc_attr($tagClass); $labelClass = esc_attr($labelClass); $rankClass = esc_attr($rankClass); $badgeClass = esc_attr($badgeClass); $rank = (int) $rank; $badge = (int) $badge; $stack = (int) $stack; $echo = (int) $echo; $get = (int) $get; $tagId = str_ireplace('%ID%', $spThisMember->user_id, $tagId); $att = $stack ? '<br />' : ': '; # grab the user rank info $ranks = sp_get_user_special_ranks($spThisMember->user_id); if (empty($ranks)) { $usertype = $spThisMember->admin ? 'Admin' : 'User'; $ranks = sp_get_user_forum_rank($usertype, $spThisMember->user_id, $spThisMember->posts); } if ($get) { return $ranks; } # now render it $out = "<div id='{$tagId}' class='{$tagClass}'>"; if (!empty($label)) { $out .= "<span class='{$labelClass}'>" . sp_filter_title_display($label) . "{$att}</span>"; } foreach ($ranks as $thisRank) { if ($badge && !empty($thisRank['badge'])) { $out .= "<img class='{$badgeClass}' src='" . $thisRank['badge'] . "' alt='' />{$att}"; } if ($rank) { $out .= "<span class='{$rankClass}'>" . $thisRank['name'] . "</span>{$att}"; } } $out .= "</div>\n"; $out = apply_filters('sph_MemberListRank', $out, $a); if ($echo) { echo $out; } else { return $out; } }
function sp_MemberListRank($args = '', $label = '') { global $spThisUser, $spThisMember, $spPaths; if (!sp_get_auth('view_members_list')) { return; } $defs = array('tagId' => 'spMembersListRank%ID%', 'tagClass' => 'spInRowCount', 'labelClass' => 'spInRowLabel', 'rank' => 1, 'rankClass' => 'spInRowRank', 'badge' => 1, 'badgeClass' => 'spImg', 'stack' => 1, 'order' => 'SNU', 'showAll' => 0, 'echo' => 1, 'get' => 0); $a = wp_parse_args($args, $defs); $a = apply_filters('sph_MemberListRank_args', $a); extract($a, EXTR_SKIP); # sanitize before use $tagId = esc_attr($tagId); $tagClass = esc_attr($tagClass); $labelClass = esc_attr($labelClass); $rankClass = esc_attr($rankClass); $badgeClass = esc_attr($badgeClass); $rank = (int) $rank; $badge = (int) $badge; $stack = (int) $stack; $order = esc_attr($order); $showAll = (int) $showAll; $echo = (int) $echo; $get = (int) $get; $tagId = str_ireplace('%ID%', $spThisMember->user_id, $tagId); $att = $stack ? '<br />' : ''; $ranks = array(); $idx = 0; for ($x = 0; $x < strlen($order); $x++) { $xRank = substr($order, $x, 1); switch ($xRank) { case 'S': # Special Rank $rankData = sp_get_user_special_ranks($spThisMember->user_id); if ($rankData) { foreach ($rankData as $r) { $ranks[$idx]['name'] = $r['name']; if ($r['badge']) { $ranks[$idx]['badge'] = $r['badge']; } $idx++; } } break; case 'N': # Normal Rank $usertype = $spThisMember->admin ? 'Admin' : 'User'; $rankData = sp_get_user_forum_rank($usertype, $spThisMember->user_id, $spThisMember->posts); if ($rankData) { $ranks[$idx]['name'] = $rankData[0]['name']; if ($rankData[0]['badge']) { $ranks[$idx]['badge'] = $rankData[0]['badge']; } $idx++; } break; case 'U': # UserGroup badge $rankData = sp_get_user_memberships($spThisMember->user_id); if ($rankData) { foreach ($rankData as $r) { if ($r['usergroup_badge']) { $ranks[$idx]['badge'] = SF_STORE_URL . '/' . $spPaths['ranks'] . '/' . $r['usergroup_badge']; } $ranks[$idx]['name'] = $r['usergroup_name']; $idx++; } } break; } if (!$showAll) { if (!empty($ranks)) { break; } } } if ($get) { return $ranks; } # now render it $out = "<div id='{$tagId}' class='{$tagClass}'>"; if (!empty($label)) { $out .= "<span class='{$labelClass}'>" . sp_filter_title_display($label) . "{$att}</span>"; } foreach ($ranks as $thisRank) { if ($badge && !empty($thisRank['badge'])) { $out .= "<img class='{$badgeClass}' src='" . $thisRank['badge'] . "' alt='' />{$att}"; } if ($rank) { $out .= "<span class='{$rankClass}'>" . $thisRank['name'] . "</span>{$att}"; } } $out .= "</div>\n"; $out = apply_filters('sph_MemberListRank', $out, $a); if ($echo) { echo $out; } else { return $out; } }