Exemple #1
0
<?php

require_once './bb-load.php';
bb_repermalink();
// The magic happens here.
if ($self) {
    if (strpos($self, '.php') !== false) {
        require $self;
    } else {
        require BB_PATH . 'profile-base.php';
    }
    return;
}
$reg_time = bb_gmtstrtotime($user->user_registered);
$profile_info_keys = bb_get_profile_info_keys();
if (!isset($_GET['updated'])) {
    $updated = false;
} else {
    $updated = true;
}
do_action('bb_profile.php_pre_db', $user_id);
if (isset($user->is_bozo) && $user->is_bozo && $user->ID != bb_get_current_user_info('id') && !bb_current_user_can('moderate')) {
    $profile_info_keys = array();
}
$posts = bb_get_recent_user_replies($user_id);
$topics = get_recent_user_threads($user_id);
bb_load_template('profile.php', array('reg_time', 'profile_info_keys', 'updated', 'threads'), $user_id);
/**
 * Send status headers for clients supporting Conditional Get
 *
 * The function sends the Last-Modified and ETag headers for all clients. It
 * then checks both the If-None-Match and If-Modified-Since headers to see if
 * the client has used them. If so, and the ETag does matches the client ETag
 * or the last modified date sent by the client is newer or the same as the
 * generated last modified, the function sends a 304 Not Modified and exits.
 *
 * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3
 * @param string $bb_last_modified Last modified time. Must be a HTTP-date
 */
function bb_send_304($bb_last_modified)
{
    $bb_etag = '"' . md5($bb_last_modified) . '"';
    @header("Last-Modified: {$bb_last_modified}");
    @header("ETag: {$bb_etag}");
    // Support for Conditional GET
    if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
        $client_etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
    } else {
        $client_etag = false;
    }
    $client_last_modified = trim($_SERVER['HTTP_IF_MODIFIED_SINCE']);
    // If string is empty, return 0. If not, attempt to parse into a timestamp
    $client_modified_timestamp = $client_last_modified ? bb_gmtstrtotime($client_last_modified) : 0;
    // Make a timestamp for our most recent modification...
    $bb_modified_timestamp = bb_gmtstrtotime($bb_last_modified);
    if ($client_last_modified && $client_etag ? $client_modified_timestamp >= $bb_modified_timestamp && $client_etag == $bb_etag : $client_modified_timestamp >= $bb_modified_timestamp || $client_etag == $bb_etag) {
        status_header(304);
        exit;
    }
}
function bb_user_row($user, $role = '', $email = false)
{
    $actions = "<a href='" . esc_attr(get_user_profile_link($user->ID)) . "'>" . __('View') . "</a>";
    $title = '';
    if (bb_current_user_can('edit_user', $user_id)) {
        $actions .= " | <a href='" . esc_attr(bb_get_user_admin_link($user->ID)) . "'>" . __('Edit') . "</a>";
        $title = " title='" . esc_attr(sprintf(__('User ID: %d'), $user->ID)) . "'";
    }
    $r = "\t<tr id='user-{$user->ID}'" . get_alt_class("user-{$role}") . ">\n";
    $r .= "\t\t<td class=\"user\">" . bb_get_avatar($user->ID, 32) . "<span class=\"row-title\"><a href='" . get_user_profile_link($user->ID) . "'" . $title . ">" . get_user_name($user->ID) . "</a></span><div><span class=\"row-actions\">{$actions}</span>&nbsp;</div></td>\n";
    $r .= "\t\t<td><a href='" . get_user_profile_link($user->ID) . "'>" . get_user_display_name($user->ID) . "</a></td>\n";
    if ($email) {
        $email = bb_get_user_email($user->ID);
        $r .= "\t\t<td><a href='mailto:{$email}'>{$email}</a></td>\n";
    }
    $registered_time = bb_gmtstrtotime($user->user_registered);
    if ($registered_time < time() - 86400) {
        $time = date('Y/m/d\\<\\b\\r \\/\\>H:i:s', bb_offset_time($registered_time));
    } else {
        $time = sprintf(__('%s ago'), bb_since($registered_time));
    }
    $r .= "\t\t<td>" . $time . "</td>\n";
    if (!isset($user->capabilities) || !is_array($user->capabilities) || empty($user->capabilities)) {
        $role = array(__('Inactive (no role)'));
    } else {
        global $nxt_roles;
        $_roles = $nxt_roles->get_names();
        $role = array();
        foreach ($user->capabilities as $cap => $cap_set) {
            if (!$cap_set) {
                continue;
            }
            $role[] = $_roles[$cap];
        }
        if (!count($role)) {
            $role[] = __('None');
        }
    }
    $r .= "\t\t<td>" . join(', ', $role) . "</td>\n\t</tr>";
    return $r;
}
function get_post_timestamp()
{
    bb_log_deprecated('function', __FUNCTION__, 'bb_gmtstrtotime( $bb_post->post_time )');
    global $bb_post;
    return bb_gmtstrtotime($bb_post->post_time);
}
function _bb_time_function_return($time, $args)
{
    $time = bb_gmtstrtotime($time);
    switch ($format = $args['format']) {
        case 'since':
            return bb_since($time, $args['more']);
            break;
        case 'timestamp':
            $format = 'U';
            break;
        case 'mysql':
            $format = 'Y-m-d H:i:s';
            break;
    }
    if ($args['localize']) {
        return bb_gmdate_i18n($format, $time);
    } else {
        return gmdate($format, $time);
    }
}
function _bb_time_function_return($time, $args)
{
    $time = bb_gmtstrtotime($time);
    switch ($format = $args['format']) {
        case 'since':
            return bb_since($time, $args['more']);
            break;
        case 'timestamp':
            $format = 'U';
            break;
        case 'mysql':
            $format = 'Y-m-d H:i:s';
            break;
        case 'datetime':
            $format = bb_get_option('datetime_format');
            break;
    }
    return $args['localize'] ? bb_gmdate_i18n($format, $time) : gmdate($format, $time);
}
        function display($show_search = true, $show_email = false)
        {
            global $wp_roles;
            $r = '';
            $now = date('Y-m-d H:i:s');
            if (isset($this->title)) {
                $title = $this->title;
            } elseif ($this->is_search()) {
                $title = sprintf(__('Users Matching "%s" by Role'), esc_html($this->search_term));
            }
            $h2_role = $this->roles[0];
            $roles = $wp_roles->get_names();
            if (in_array($h2_role, array_keys($roles))) {
                $h2_role = $roles[$h2_role];
            }
            $h2_span = apply_filters('bb_user_search_description', sprintf(__('%1$s%2$s'), $h2_search, $h2_role), $h2_search, $h2_role, $this);
            echo "<h2 class=\"first left\">" . apply_filters('bb_user_search_title', __('Users Waiting for Approval')) . $h2_span . "</h2>\n";
            do_action('bb_admin_notices');
            if ($this->get_results()) {
                if ($this->results_are_paged()) {
                    $r .= "<div class='tablenav'>\n" . $this->paging_text . "</div><div class=\"clear\"></div>\n\n";
                }
                $r .= "<table class='widefat'>\n";
                $r .= "<thead>\n";
                $r .= "\t<tr>\n";
                $r .= "\t\t<th style='width:10;'>&nbsp;</th>\n";
                $r .= "\t\t<th>" . __('Username') . "</th>\n";
                $r .= "\t\t<th>" . __('Email') . "</th>\n";
                $r .= "\t\t<th>" . __('Registered') . "</th>\n";
                $r .= "\t\t<th>" . __('Elapsed') . "</th>\n";
                $r .= "\t</tr>\n";
                $r .= "</thead>\n\n";
                $r .= "<tbody id='role-{$role}'>\n";
                foreach ((array) $this->get_results() as $user_object) {
                    //$r .= bb_user_row($user_object->ID, $role, $show_email);
                    $user = bb_get_user($user_object->ID);
                    $registered = date('Y/m/d H:i:s', bb_offset_time(bb_gmtstrtotime($user->user_registered)));
                    $date_eng = date('H:i:s - d/m/Y', bb_offset_time(bb_gmtstrtotime($user->user_registered)));
                    $difference = strtotime($now) - strtotime($registered);
                    $hours_ago = number_format($difference / 60 / 60, 0);
                    if ($hours_ago < '15') {
                        $reg_compare = '"color: red"';
                        $checked = '';
                    }
                    if ($hours_ago >= '15' && $hours_ago < '24') {
                        $reg_compare = '"color: blue"';
                        $checked = 'checked';
                    }
                    if ($hours_ago >= '24') {
                        $reg_compare = '"color: purple"';
                        $checked = 'checked';
                    }
                    $r .= "\t<tr id='user-{$user->ID}'" . get_alt_class("user-{$role}") . ">\n";
                    $r .= "\t\t<td><input type='checkbox' value='{$user->ID}' name='userids[]' {$checked}/></td>\n";
                    $r .= "\t\t<td><a href='" . get_user_profile_link($user->ID) . "' style=" . $reg_compare . ">" . get_user_name($user->ID) . "</a></td>\n";
                    $email = bb_get_user_email($user->ID);
                    $r .= "\t\t<td><a href='mailto:{$email}'>{$email}</a></td>\n";
                    $r .= "\t\t<td>" . $date_eng . "</td>\n";
                    $r .= "\t\t<td>" . $hours_ago . " hours</td>\n";
                    $r .= "\n\t</tr>";
                }
                $r .= "</tbody>\n";
                $r .= "<tfoot>\n";
                $r .= "\t<tr>\n";
                $r .= "\t\t<th>&nbsp;</th>\n";
                $r .= "\t\t<th>" . __('Username') . "</th>\n";
                $r .= "\t\t<th>" . __('Email') . "</th>\n";
                $r .= "\t\t<th>" . __('Registered') . "</th>\n";
                $r .= "\t\t<th>" . __('Elapsed') . "</th>\n";
                $r .= "\t</tr>\n";
                $r .= "</tfoot>\n\n";
                $r .= "</table>\n";
                $r .= "<p style=\"text-align: right; color: #9f9f9f; font-size: small; font-style: normal;\">Registered: Red: < 15 hours ago. Blue: > 15 hours ago. Purple: > 24 hours ago.</p>";
                if ($this->results_are_paged()) {
                    $r .= "<div class='tablenav bottom'>\n" . $this->paging_text_bottom . "</div><div class=\"clear\"></div>\n\n";
                }
            }
            ?>
			<form class="settings" method="post" name="approve_user_registration_form">
			<?php 
            echo $r;
            ?>
	       	<fieldset class="submit">
	          <input type="submit" class="submit left" name="approve_user_registration_button_approve" value="Approve" />
	          <input type="submit" class="submit left" name="approve_user_registration_button_reject" value="Reject" />
	        </fieldset>
	        </form>
			<?php 
            //			}
        }
/**
 * Map meta capabilities to primitive capabilities.
 *
 * This does not actually compare whether the user ID has the actual capability,
 * just what the capability or capabilities are. Meta capability list value can
 * be 'delete_user', 'edit_user', 'delete_post', 'delete_page', 'edit_post',
 * 'edit_page', 'read_post', or 'read_page'.
 *
 * @since 0.7.2
 *
 * @param array $caps Previously existing capabilities
 * @param string $cap Capability name.
 * @param int $user_id User ID.
 * @return array Actual capabilities for meta capability.
 */
function bb_map_meta_cap($caps, $cap, $user_id, $args)
{
    // Unset the meta cap
    if (false !== ($cap_pos = array_search($cap, $caps))) {
        unset($caps[$cap_pos]);
    }
    switch ($cap) {
        case 'write_post':
            $caps[] = 'write_posts';
            break;
        case 'edit_post':
            // edit_posts, edit_others_posts, edit_deleted, edit_closed, ignore_edit_lock
            if (!($bb_post = bb_get_post($args[0]))) {
                $caps[] = 'magically_provide_data_given_bad_input';
                return $caps;
            }
            if ($user_id == $bb_post->poster_id) {
                $caps[] = 'edit_posts';
            } else {
                $caps[] = 'edit_others_posts';
            }
            if ($bb_post->post_status == '1') {
                $caps[] = 'edit_deleted';
            }
            if (!topic_is_open($bb_post->topic_id)) {
                $caps[] = 'edit_closed';
            }
            $post_time = bb_gmtstrtotime($bb_post->post_time);
            $curr_time = time() + 1;
            $edit_lock = bb_get_option('edit_lock');
            if ($edit_lock >= 0 && $curr_time - $post_time > $edit_lock * 60) {
                $caps[] = 'ignore_edit_lock';
            }
            break;
        case 'delete_post':
            // edit_deleted, delete_posts
            if (!($bb_post = bb_get_post($args[0]))) {
                $caps[] = 'magically_provide_data_given_bad_input';
                return $caps;
            }
            if (0 != $bb_post->post_status) {
                $caps[] = 'edit_deleted';
            }
            // NO BREAK
        // NO BREAK
        case 'manage_posts':
            // back compat
            $caps[] = 'delete_posts';
            break;
        case 'write_topic':
            $caps[] = 'write_topics';
            break;
        case 'edit_topic':
            // edit_closed, edit_deleted, edit_topics, edit_others_topics
            if (!($topic = get_topic($args[0]))) {
                $caps[] = 'magically_provide_data_given_bad_input';
                return $caps;
            }
            if (!topic_is_open($args[0])) {
                $caps[] = 'edit_closed';
            }
            if ('1' == $topic->topic_status) {
                $caps[] = 'edit_deleted';
            }
            if ($user_id == $topic->topic_poster) {
                $caps[] = 'edit_topics';
            } else {
                $caps[] = 'edit_others_topics';
            }
            break;
        case 'move_topic':
            $caps[] = 'move_topics';
            break;
        case 'stick_topic':
            $caps[] = 'stick_topics';
            break;
        case 'close_topic':
            $caps[] = 'close_topics';
            break;
        case 'delete_topic':
            $caps[] = 'delete_topics';
            add_filter('get_topic_where', 'bb_no_where', 9999);
            if (!($topic = get_topic($args[0]))) {
                $caps[] = 'magically_provide_data_given_bad_input';
                return $caps;
            }
            if (0 != $topic->topic_status) {
                $caps[] = 'edit_deleted';
            }
            remove_filter('get_topic_where', 'bb_no_where', 9999);
            break;
        case 'manage_topics':
            // back compat
            $caps[] = 'move_topics';
            $caps[] = 'stick_topics';
            $caps[] = 'close_topics';
            $caps[] = 'delete_topics';
            break;
        case 'add_tag_to':
            // edit_closed, edit_deleted, edit_tags;
            if (!($topic = get_topic($args[0]))) {
                $caps[] = 'magically_provide_data_given_bad_input';
                return $caps;
            }
            if (!topic_is_open($topic->topic_id)) {
                $caps[] = 'edit_closed';
            }
            if ('1' == $topic->topic_status) {
                $caps[] = 'edit_deleted';
            }
            $caps[] = 'edit_tags';
            break;
        case 'edit_tag_by_on':
            // edit_closed, edit_deleted, edit_tags, edit_others_tags
            if (!($topic = get_topic($args[1]))) {
                $caps[] = 'magically_provide_data_given_bad_input';
                return $caps;
            }
            if (!topic_is_open($topic->topic_id)) {
                $caps[] = 'edit_closed';
            }
            if ('1' == $topic->topic_status) {
                $caps[] = 'edit_deleted';
            }
            if ($user_id == $args[0]) {
                $caps[] = 'edit_tags';
            } else {
                $caps[] = 'edit_others_tags';
            }
            break;
        case 'edit_user':
            // edit_profile, edit_users;
            if ($user_id == $args[0]) {
                $caps[] = 'edit_profile';
            } else {
                $caps[] = 'edit_users';
            }
            break;
        case 'edit_favorites_of':
            // edit_favorites, edit_others_favorites;
            if ($user_id == $args[0]) {
                $caps[] = 'edit_favorites';
            } else {
                $caps[] = 'edit_others_favorites';
            }
            break;
        case 'delete_forum':
            $caps[] = 'delete_forums';
            break;
        case 'change_user_password':
            // change_password, edit_users
            $caps[] = 'change_password';
            if ($user_id != $args[0]) {
                $caps[] = 'edit_users';
            }
            break;
        default:
            // If no meta caps match, return the original cap.
            $caps[] = $cap;
    }
    return $caps;
}