/** * Adds the User Admin top-level menu to user pages * * @package BuddyPress * @since 1.5 */ function bp_members_admin_bar_user_admin_menu() { global $bp, $wp_admin_bar; // Only show if viewing a user if (!bp_is_user()) { return false; } // Don't show this menu to non site admins or if you're viewing your own profile if (!current_user_can('edit_users') || bp_is_my_profile()) { return false; } // User avatar $avatar = bp_core_fetch_avatar(array('item_id' => $bp->displayed_user->id, 'email' => $bp->displayed_user->userdata->user_email, 'width' => 16, 'height' => 16)); // Unique ID for the 'My Account' menu $bp->user_admin_menu_id = !empty($avatar) ? 'user-admin-with-avatar' : 'user-admin'; // Add the top-level User Admin button $wp_admin_bar->add_menu(array('id' => $bp->user_admin_menu_id, 'title' => $avatar . bp_get_displayed_user_fullname(), 'href' => bp_displayed_user_domain())); // User Admin > Edit this user's profile $wp_admin_bar->add_menu(array('parent' => $bp->user_admin_menu_id, 'id' => 'edit-profile', 'title' => __("Edit Profile", 'buddypress'), 'href' => bp_get_members_component_link('profile', 'edit'))); // User Admin > Edit this user's avatar $wp_admin_bar->add_menu(array('parent' => $bp->user_admin_menu_id, 'id' => 'change-avatar', 'title' => __("Edit Avatar", 'buddypress'), 'href' => bp_get_members_component_link('profile', 'change-avatar'))); // User Admin > Spam/unspam if (!bp_core_is_user_spammer(bp_displayed_user_id())) { $wp_admin_bar->add_menu(array('parent' => $bp->user_admin_menu_id, 'id' => 'spam-user', 'title' => __('Mark as Spammer', 'buddypress'), 'href' => wp_nonce_url(bp_displayed_user_domain() . 'admin/mark-spammer/', 'mark-unmark-spammer'), 'meta' => array('onclick' => 'confirm(" ' . __('Are you sure you want to mark this user as a spammer?', 'buddypress') . '");'))); } else { $wp_admin_bar->add_menu(array('parent' => $bp->user_admin_menu_id, 'id' => 'unspam-user', 'title' => __('Not a Spammer', 'buddypress'), 'href' => wp_nonce_url(bp_displayed_user_domain() . 'admin/unmark-spammer/', 'mark-unmark-spammer'), 'meta' => array('onclick' => 'confirm(" ' . __('Are you sure you want to mark this user as not a spammer?', 'buddypress') . '");'))); } // User Admin > Delete Account $wp_admin_bar->add_menu(array('parent' => $bp->user_admin_menu_id, 'id' => 'delete-user', 'title' => __('Delete Account', 'buddypress'), 'href' => wp_nonce_url(bp_displayed_user_domain() . 'admin/delete-user/', 'delete-user'), 'meta' => array('onclick' => 'confirm(" ' . __("Are you sure you want to delete this user's account?", 'buddypress') . '");'))); }
/** * Analyzes the URI structure and breaks it down into parts for use in code. * The idea is that BuddyPress can use complete custom friendly URI's without the * user having to add new re-write rules. * * Future custom components would then be able to use their own custom URI structure. * * @package BuddyPress Core * @since BuddyPress (r100) * * The URI's are broken down as follows: * - http:// domain.com / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ... * - OUTSIDE ROOT: http:// domain.com / sites / buddypress / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ... * * Example: * - http://domain.com/members/andy/profile/edit/group/5/ * - $bp->current_component: string 'xprofile' * - $bp->current_action: string 'edit' * - $bp->action_variables: array ['group', 5] * */ function bp_core_set_uri_globals() { global $bp, $bp_unfiltered_uri, $bp_unfiltered_uri_offset; global $current_blog, $nxtdb; // Create global component, action, and item variables $bp->current_component = $bp->current_action = $bp->current_item = ''; $bp->action_variables = $bp->displayed_user->id = ''; // Don't catch URIs on non-root blogs unless multiblog mode is on if (!bp_is_root_blog() && !bp_is_multiblog_mode()) { return false; } // Fetch all the nxt page names for each component if (empty($bp->pages)) { $bp->pages = bp_core_get_directory_pages(); } // Ajax or not? if (strpos($_SERVER['REQUEST_URI'], 'nxt-load.php')) { $path = bp_core_referrer(); } else { $path = esc_url($_SERVER['REQUEST_URI']); } // Filter the path $path = apply_filters('bp_uri', $path); // Take GET variables off the URL to avoid problems, // they are still registered in the global $_GET variable if ($noget = substr($path, 0, strpos($path, '?'))) { $path = $noget; } // Fetch the current URI and explode each part separated by '/' into an array $bp_uri = explode('/', $path); // Loop and remove empties foreach ((array) $bp_uri as $key => $uri_chunk) { if (empty($bp_uri[$key])) { unset($bp_uri[$key]); } } // Running off blog other than root if (is_multisite() && !is_subdomain_install() && (bp_is_multiblog_mode() || 1 != bp_get_root_blog_id())) { // Any subdirectory names must be removed from $bp_uri. // This includes two cases: (1) when nxt is installed in a subdirectory, // and (2) when BP is running on secondary blog of a subdirectory // multisite installation. Phew! if ($chunks = explode('/', $current_blog->path)) { foreach ($chunks as $key => $chunk) { $bkey = array_search($chunk, $bp_uri); if ($bkey !== false) { unset($bp_uri[$bkey]); } $bp_uri = array_values($bp_uri); } } } // Set the indexes, these are incresed by one if we are not on a VHOST install $component_index = 0; $action_index = $component_index + 1; // Get site path items $paths = explode('/', bp_core_get_site_path()); // Take empties off the end of path if (empty($paths[count($paths) - 1])) { array_pop($paths); } // Take empties off the start of path if (empty($paths[0])) { array_shift($paths); } // Unset URI indices if they intersect with the paths foreach ((array) $bp_uri as $key => $uri_chunk) { if (in_array($uri_chunk, $paths)) { unset($bp_uri[$key]); } } // Reset the keys by merging with an empty array $bp_uri = array_merge(array(), $bp_uri); // If a component is set to the front page, force its name into $bp_uri // so that $current_component is populated (unless a specific nxt post is being requested // via a URL parameter, usually signifying Preview mode) if ('page' == get_option('show_on_front') && get_option('page_on_front') && empty($bp_uri) && empty($_GET['p']) && empty($_GET['page_id'])) { $post = get_post(get_option('page_on_front')); if (!empty($post)) { $bp_uri[0] = $post->post_name; } } // Keep the unfiltered URI safe $bp_unfiltered_uri = $bp_uri; // Get slugs of pages into array foreach ((array) $bp->pages as $page_key => $bp_page) { $key_slugs[$page_key] = trailingslashit('/' . $bp_page->slug); } // Bail if keyslugs are empty, as BP is not setup correct if (empty($key_slugs)) { return; } // Loop through page slugs and look for exact match to path foreach ($key_slugs as $key => $slug) { if ($slug == $path) { $match = $bp->pages->{$key}; $match->key = $key; $matches[] = 1; break; } } // No exact match, so look for partials if (empty($match)) { // Loop through each page in the $bp->pages global foreach ((array) $bp->pages as $page_key => $bp_page) { // Look for a match (check members first) if (in_array($bp_page->name, (array) $bp_uri)) { // Match found, now match the slug to make sure. $uri_chunks = explode('/', $bp_page->slug); // Loop through uri_chunks foreach ((array) $uri_chunks as $key => $uri_chunk) { // Make sure chunk is in the correct position if (!empty($bp_uri[$key]) && $bp_uri[$key] == $uri_chunk) { $matches[] = 1; // No match } else { $matches[] = 0; } } // Have a match if (!in_array(0, (array) $matches)) { $match = $bp_page; $match->key = $page_key; break; } // Unset matches unset($matches); } // Unset uri chunks unset($uri_chunks); } } // URLs with BP_ENABLE_ROOT_PROFILES enabled won't be caught above if (empty($matches) && defined('BP_ENABLE_ROOT_PROFILES') && BP_ENABLE_ROOT_PROFILES) { // Make sure there's a user corresponding to $bp_uri[0] if (!empty($bp->pages->members) && !empty($bp_uri[0]) && ($root_profile = get_user_by('login', $bp_uri[0]))) { // Force BP to recognize that this is a members page $matches[] = 1; $match = $bp->pages->members; $match->key = 'members'; // Without the 'members' URL chunk, NXTClass won't know which page to load // This filter intercepts the nxt query and tells it to load the members page add_filter('request', create_function('$query_args', '$query_args["pagename"] = "' . $match->name . '"; return $query_args;')); } } // Search doesn't have an associated page, so we check for it separately if (!empty($bp_uri[0]) && bp_get_search_slug() == $bp_uri[0]) { $matches[] = 1; $match = new stdClass(); $match->key = 'search'; $match->slug = bp_get_search_slug(); } // This is not a BuddyPress page, so just return. if (!isset($matches)) { return false; } // Find the offset. With $root_profile set, we fudge the offset down so later parsing works $slug = !empty($match) ? explode('/', $match->slug) : ''; $uri_offset = empty($root_profile) ? 0 : -1; // Rejig the offset if (!empty($slug) && 1 < count($slug)) { array_pop($slug); $uri_offset = count($slug); } // Global the unfiltered offset to use in bp_core_load_template(). // To avoid PHP warnings in bp_core_load_template(), it must always be >= 0 $bp_unfiltered_uri_offset = $uri_offset >= 0 ? $uri_offset : 0; // We have an exact match if (isset($match->key)) { // Set current component to matched key $bp->current_component = $match->key; // If members component, do more work to find the actual component if ('members' == $match->key) { // Viewing a specific user if (!empty($bp_uri[$uri_offset + 1])) { // Switch the displayed_user based on compatbility mode if (bp_is_username_compatibility_mode()) { $bp->displayed_user->id = (int) bp_core_get_userid(urldecode($bp_uri[$uri_offset + 1])); } else { $bp->displayed_user->id = (int) bp_core_get_userid_from_nicename(urldecode($bp_uri[$uri_offset + 1])); } if (empty($bp->displayed_user->id)) { // Prevent components from loading their templates $bp->current_component = ''; bp_do_404(); return; } // If the displayed user is marked as a spammer, 404 (unless logged- // in user is a super admin) if (!empty($bp->displayed_user->id) && bp_core_is_user_spammer($bp->displayed_user->id)) { if (is_super_admin()) { bp_core_add_message(__('This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress'), 'error'); } else { bp_do_404(); return; } } // Bump the offset if (isset($bp_uri[$uri_offset + 2])) { $bp_uri = array_merge(array(), array_slice($bp_uri, $uri_offset + 2)); $bp->current_component = $bp_uri[0]; // No component, so default will be picked later } else { $bp_uri = array_merge(array(), array_slice($bp_uri, $uri_offset + 2)); $bp->current_component = ''; } // Reset the offset $uri_offset = 0; } } } // Set the current action $bp->current_action = isset($bp_uri[$uri_offset + 1]) ? $bp_uri[$uri_offset + 1] : ''; // Slice the rest of the $bp_uri array and reset offset $bp_uri = array_slice($bp_uri, $uri_offset + 2); $uri_offset = 0; // Set the entire URI as the action variables, we will unset the current_component and action in a second $bp->action_variables = $bp_uri; // Remove the username from action variables if this is not a VHOST install // @todo - move or remove this all together if (defined('VHOST') && 'no' == VHOST && empty($bp->current_component)) { array_shift($bp_uri); } // Reset the keys by merging with an empty array $bp->action_variables = array_merge(array(), $bp->action_variables); }
/** * Post an activity update * * @since 1.2.0 * * @param array $args See docs for $defaults for details * * @global object $bp BuddyPress global settings * @uses nxt_parse_args() * @uses bp_core_is_user_spammer() * @uses bp_core_is_user_deleted() * @uses bp_core_get_userlink() * @uses bp_activity_add() * @uses apply_filters() To call the 'bp_activity_new_update_action' hook * @uses apply_filters() To call the 'bp_activity_new_update_content' hook * @uses apply_filters() To call the 'bp_activity_new_update_primary_link' hook * @uses bp_update_user_meta() * @uses nxt_filter_kses() * @uses do_action() To call the 'bp_activity_posted_update' hook * * @return int $activity_id The activity id */ function bp_activity_post_update($args = '') { global $bp; $defaults = array('content' => false, 'user_id' => $bp->loggedin_user->id); $r = nxt_parse_args($args, $defaults); extract($r, EXTR_SKIP); if (empty($content) || !strlen(trim($content))) { return false; } if (bp_core_is_user_spammer($user_id) || bp_core_is_user_deleted($user_id)) { return false; } // Record this on the user's profile $from_user_link = bp_core_get_userlink($user_id); $activity_action = sprintf(__('%s posted an update', 'buddypress'), $from_user_link); $activity_content = $content; $primary_link = bp_core_get_userlink($user_id, false, true); // Now write the values $activity_id = bp_activity_add(array('user_id' => $user_id, 'action' => apply_filters('bp_activity_new_update_action', $activity_action), 'content' => apply_filters('bp_activity_new_update_content', $activity_content), 'primary_link' => apply_filters('bp_activity_new_update_primary_link', $primary_link), 'component' => $bp->activity->id, 'type' => 'activity_update')); // Add this update to the "latest update" usermeta so it can be fetched anywhere. bp_update_user_meta($bp->loggedin_user->id, 'bp_latest_update', array('id' => $activity_id, 'content' => nxt_filter_kses($content))); do_action('bp_activity_posted_update', $content, $user_id, $activity_id); return $activity_id; }
function bp_forums_insert_post($args = '') { global $bp; do_action('bbpress_init'); $defaults = array('post_id' => false, 'topic_id' => false, 'post_text' => '', 'post_time' => bp_core_current_time(), 'poster_id' => $bp->loggedin_user->id, 'poster_ip' => $_SERVER['REMOTE_ADDR'], 'post_status' => 0, 'post_position' => false); $r = nxt_parse_args($args, $defaults); extract($r, EXTR_SKIP); if (!($post = bp_forums_get_post($post_id))) { $post_id = false; } if (!isset($topic_id)) { $topic_id = $post->topic_id; } if (empty($post_text)) { $post_text = $post->post_text; } if (!isset($post_time)) { $post_time = $post->post_time; } if (!isset($post_position)) { $post_position = $post->post_position; } if (empty($poster_id)) { return false; } if (bp_core_is_user_spammer($bp->loggedin_user->id) || bp_core_is_user_deleted($bp->loggedin_user->id)) { return false; } $post_id = bb_insert_post(array('post_id' => $post_id, 'topic_id' => $topic_id, 'post_text' => stripslashes(trim($post_text)), 'post_time' => $post_time, 'poster_id' => $poster_id, 'poster_ip' => $poster_ip, 'post_status' => $post_status, 'post_position' => $post_position)); if (!empty($post_id)) { do_action('bp_forums_new_post', $post_id); } return $post_id; }
/** * Adds an admin bar menu to any profile page providing site moderator actions * that allow capable users to clean up a users account. * * @package BuddyPress XProfile * @global $bp BuddyPress */ function bp_members_adminbar_admin_menu() { global $bp; // Only show if viewing a user if (!$bp->displayed_user->id) { return false; } // Don't show this menu to non site admins or if you're viewing your own profile if (!current_user_can('edit_users') || bp_is_my_profile()) { return false; } ?> <li id="bp-adminbar-adminoptions-menu"> <a href=""><?php _e('Admin Options', 'buddypress'); ?> </a> <ul> <?php if (bp_is_active('xprofile')) { ?> <li><a href="<?php bp_members_component_link('profile', 'edit'); ?> "><?php printf(__("Edit %s's Profile", 'buddypress'), esc_attr($bp->displayed_user->fullname)); ?> </a></li> <?php } ?> <li><a href="<?php bp_members_component_link('profile', 'change-avatar'); ?> "><?php printf(__("Edit %s's Avatar", 'buddypress'), esc_attr($bp->displayed_user->fullname)); ?> </a></li> <?php if (!bp_core_is_user_spammer($bp->displayed_user->id)) { ?> <li><a href="<?php echo nxt_nonce_url($bp->displayed_user->domain . 'admin/mark-spammer/', 'mark-unmark-spammer'); ?> " class="confirm"><?php printf(__("Mark as Spammer", 'buddypress'), esc_attr($bp->displayed_user->fullname)); ?> </a></li> <?php } else { ?> <li><a href="<?php echo nxt_nonce_url($bp->displayed_user->domain . 'admin/unmark-spammer/', 'mark-unmark-spammer'); ?> " class="confirm"><?php _e("Not a Spammer", 'buddypress'); ?> </a></li> <?php } ?> <li><a href="<?php echo nxt_nonce_url($bp->displayed_user->domain . 'admin/delete-user/', 'delete-user'); ?> " class="confirm"><?php printf(__("Delete %s's Account", 'buddypress'), esc_attr($bp->displayed_user->fullname)); ?> </a></li> <?php do_action('bp_members_adminbar_admin_menu'); ?> </ul> </li> <?php }
/** * Return the activity latest update link. * * @since 1.2.0 * * @param int $user_id Defaults to 0 * * @global object $bp BuddyPress global settings * @uses bp_core_is_user_spammer() * @uses bp_core_is_user_deleted() * @uses bp_get_user_meta() * @uses apply_filters() To call the 'bp_get_activity_latest_update_excerpt' hook * @uses bp_create_excerpt() * @uses bp_get_root_domain() * @uses bp_get_activity_root_slug() * @uses apply_filters() To call the 'bp_get_activity_latest_update' hook * * @return string|bool $latest_update The activity latest update link. False on failure */ function bp_get_activity_latest_update($user_id = 0) { global $bp; if (!$user_id) { $user_id = $bp->displayed_user->id; } if (bp_core_is_user_spammer($user_id) || bp_core_is_user_deleted($user_id)) { return false; } if (!($update = bp_get_user_meta($user_id, 'bp_latest_update', true))) { return false; } $latest_update = apply_filters('bp_get_activity_latest_update_excerpt', trim(strip_tags(bp_create_excerpt($update['content'], 358)))); $latest_update .= ' <a href="' . bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $update['id'] . '/"> ' . __('View', 'buddypress') . '</a>'; return apply_filters('bp_get_activity_latest_update', $latest_update); }
/** * Record user activity to the database. Many functions use a "last active" feature to * show the length of time since the user was last active. * This function will update that time as a usermeta setting for the user every 5 minutes. * * @package BuddyPress Core * @global $userdata NXTClass user data for the current logged in user. * @uses bp_update_user_meta() BP function to update user metadata in the usermeta table. */ function bp_core_record_activity() { global $bp; if (!is_user_logged_in()) { return false; } $user_id = $bp->loggedin_user->id; if (bp_core_is_user_spammer($user_id) || bp_core_is_user_deleted($user_id)) { return false; } $activity = bp_get_user_meta($user_id, 'last_activity', true); if (!is_numeric($activity)) { $activity = strtotime($activity); } // Get current time $current_time = bp_core_current_time(); if (empty($activity) || strtotime($current_time) >= strtotime('+5 minutes', $activity)) { bp_update_user_meta($user_id, 'last_activity', $current_time); } }
/** * Catches invalid access to BuddyPress pages and redirects them accordingly. * * @package BuddyPress Core * @since 1.5 */ function bp_core_catch_no_access() { global $bp, $bp_no_status_set, $wp_query; // If bp_core_redirect() and $bp_no_status_set is true, // we are redirecting to an accessible page, so skip this check. if ($bp_no_status_set) { return false; } // If the displayed user was marked as a spammer and the logged-in user is not a super admin, 404. if (isset($bp->displayed_user->id) && bp_core_is_user_spammer($bp->displayed_user->id)) { if (!$bp->loggedin_user->is_super_admin) { bp_do_404(); return; } else { bp_core_add_message(__('This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress'), 'error'); } } if (!isset($wp_query->queried_object) && !bp_is_blog_page()) { bp_do_404(); } }
function bp_core_catch_no_access() { global $bp, $bp_path, $bp_unfiltered_uri, $bp_no_status_set; // If bp_core_redirect() and $bp_no_status_set is true, // we are redirecting to an accessable page, so skip this check. if ($bp_no_status_set) { return false; } /* If this user has been marked as a spammer and the logged in user is not a site admin, redirect. */ if (isset($bp->displayed_user->id) && bp_core_is_user_spammer($bp->displayed_user->id)) { if (!is_super_admin()) { bp_core_redirect($bp->root_domain); } else { bp_core_add_message(__('This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress'), 'error'); } } // If this user does not exist, redirect to the root domain. if (!$bp->displayed_user->id && $bp_unfiltered_uri[0] == BP_MEMBERS_SLUG && isset($bp_unfiltered_uri[1])) { bp_core_redirect($bp->root_domain); } // Add .php to all options in $bp_path foreach ((array) $bp_path as $template) { $filtered_templates[] = "{$template}.php"; } // If the template file doesn't exist, redirect to the root domain. if (!bp_is_blog_page() && !file_exists(apply_filters('bp_located_template', locate_template($filtered_templates, false), $filtered_templates))) { bp_core_redirect($bp->root_domain); } if (!$bp_path && !bp_is_blog_page()) { if (is_user_logged_in()) { wp_redirect($bp->root_domain); } else { wp_redirect(site_url('wp-login.php?redirect_to=' . site_url() . $_SERVER['REQUEST_URI'])); } } }
/** * Determine which BP component (if any) matches a given transect * * @link http://en.wikipedia.org/wiki/Cycle_(graph_theory) * @link http://en.wikipedia.org/wiki/Cycle_detection * @version 1.0 * @since 1.0 * @param array $intersect | Intersect array * @param array $status | Reason no match was found * @return bool $result | Exception on failure. True on match. False on no match. */ public function matchComponent($intersect, &$status) { $transect = $intersect["transect"]; $route_found = false; // CASE 1: Front-page component // ==================================================================== if ($intersect["endpoint_id"] === null) { // If a component is set to the front page, and the user is not requesting // a specific post via a URL parameter, we have a match $not_preview_mode = empty($_GET['p']) && empty($_GET['page_id']); if ($not_preview_mode) { $show_page_on_front = get_option('show_on_front') == 'page'; // Note comparison operator $post_id = get_option('page_on_front'); if ($show_page_on_front && $post_id) { $post = get_post($post_id); if (!empty($post)) { $this->bp->current_component = (string) $post->post_name; $status = array('numeric' => 1, 'text' => "Successful match on front-page component.", 'data' => array('current_component' => $this->bp->current_component, 'post_id' => $post_id, 'post' => $post), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__); $route_found = true; } else { throw new FOX_exception(array('numeric' => 1, 'text' => "Site front page set to component, but component's post was empty", 'data' => array("post_id" => $post_id), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => null)); } } } if (!$route_found) { $status = array('numeric' => 2, 'text' => "Site front page with no components active on front page.", 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__); return false; } } // CASE 2: Any non-nested component // ==================================================================== if (!$this->bp->current_component) { try { $this->bp->current_component = self::getPrimaryComponentName($intersect["endpoint_name"]); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 2, 'text' => "Error fetching primary component name", 'data' => array("endpoint_name" => $intersect["endpoint_name"]), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } if ($this->bp->current_component) { $status = array('numeric' => 3, 'text' => "Successful match on primary component", 'data' => array('current_component' => $this->bp->current_component), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__); $route_found = true; } } // CASE 3: Root profile // ==================================================================== if (!$this->bp->current_component && !empty($transect) && !empty($this->bp->pages->members) && defined('BP_ENABLE_ROOT_PROFILES') && BP_ENABLE_ROOT_PROFILES) { // Shift the user name off the transect $user_name = array_shift($transect); // Switch the user_id based on compatibility mode if (bp_is_username_compatibility_mode()) { $user_id = (int) bp_core_get_userid(urldecode($user_name)); } else { $user_id = (int) bp_core_get_userid_from_nicename(urldecode($user_name)); } if ($user_id) { $this->bp->current_component = "members"; $this->bp->displayed_user->id = $user_id; $status = array('numeric' => 4, 'text' => "Successful match on root profile", 'data' => array('current_component' => $this->bp->current_component), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__); $route_found = true; // Without the 'members' URL chunk, WordPress won't know which page to load, // so this filter intercepts the WP query and tells it to load the members page $function_string = '$query_args["pagename"] = "'; $function_string .= $this->bp->pages->members->name; $function_string .= '"; return $query_args;'; add_filter('request', create_function('$query_args', $function_string)); } else { $status = array('numeric' => 5, 'text' => "Root profiles enabled. No matching user.", 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__); return false; } } // CASE 4: No match // ==================================================================== if (!$this->bp->current_component) { $status = array('numeric' => 6, 'text' => "No matching components", 'data' => array('intersect' => $this->intersect, 'walk' => $this->walk), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__); return false; } // Members Component secondary processing // ==================================================================== if ($this->bp->current_component == "members" && !empty($transect)) { // If the component is "members", the transect must either contain no tokens (show all users on site), // or the first token in the transect must be a valid user name (show single user) $user_name = array_shift($transect); // Switch the user_id based on compatibility mode if (bp_is_username_compatibility_mode()) { $user_id = (int) bp_core_get_userid(urldecode($user_name)); } else { $user_id = (int) bp_core_get_userid_from_nicename(urldecode($user_name)); } // CASE 1: Token in first transect position isn't a valid user_id // --------------------------------------------------------------------------------------- if (empty($user_id)) { $this->bp->current_component = null; // Prevent components from loading their templates bp_do_404(); $status = array('numeric' => 7, 'text' => "Match on members component, but user_id is not valid.", 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__); return false; } elseif (!empty($user_id)) { $this->bp->displayed_user->id = $user_id; // CASE 2: Token in first transect position matches a user_id that // has been marked as a spammer // --------------------------------------------------------------------------------------- if (bp_core_is_user_spammer($user_id)) { if (is_super_admin()) { bp_core_add_message(__('This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress'), 'error'); } else { // If the user viewing the profile is not a super-admin, hide the page bp_do_404(); $status = array('numeric' => 8, 'text' => "Match on members component, but user_id is marked as a spammer and viewer is not a super-admin.", 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__); return false; } } elseif (count($transect) > 0) { $current_component_slug = array_shift($transect); // CASE 3A: Match against the "primary" components that can exist both as a top-level // page and a secondary page nested beneath the "members" component. External plugins // following the "BuddyPress Example Component" pattern will appear in this array. // // TODO: This creates a cardinality problem. Primary components will appear at // both "example.com/members/membername/slug_name" and "example.com/slug_name". This // is further complicated by the fact that some components use the alias location as a // *context*, for example, "activity" at the root node shows activity for all users on // the site, but "activity" nested in the "members" component shows activity for a user. // There needs to be a set of configuration options on the admin back-end to specify // which location to use for a given component. Note that this is a legacy problem with // the original BP router design and we have emulated it for compatibility. // --------------------------------------------------------------------------------------- try { $this->bp->current_component = self::getPrimaryComponentName($current_component_slug); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 3, 'text' => "Error fetching primary component name", 'data' => array("current_component_slug" => $current_component_slug), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } if ($this->bp->current_component != null) { $status = array('numeric' => 9, 'text' => "Match on members component with primary nested component", 'data' => array('bp_pages' => $this->bp->pages, 'active_components' => $this->bp->active_components, 'current_component_slug' => $current_component_slug, "component" => $this->bp->current_component), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__); $route_found = true; } else { // CASE 3B: Match against the "secondary" components that can only exist as a secondary // page nested beneath the "members" component. Matching is determined by the component's // action functions, which hook on the 'bp_init' action. Action functions are located // in "/component_name/bp-component_name-actions.php". // --------------------------------------------------------------------------------------- $this->bp->current_component = $current_component_slug; $status = array('numeric' => 10, 'text' => "Match on members component, with possible match on secondary nested component", 'data' => array('bp_pages' => $this->bp->pages, 'active_components' => $this->bp->active_components, 'current_component_slug' => $current_component_slug), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__); $route_found = true; } } else { $this->bp->current_component = $this->bp->default_component; $status = array('numeric' => 11, 'text' => "Match on members component with no nested component", 'data' => array("component" => $this->bp->current_component), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__); $route_found = true; } } } // Set BP's global variables // ==================================================================== if (isset($transect[0])) { $this->bp->current_action = array_shift($transect); if (count($transect) > 0) { $this->bp->action_variables = $transect; } } // Set WP's global variables // ==================================================================== // Set WP's internal query variables to the same state they would be in if // WP had loaded the page itself instead of BP intercepting the page load // and replacing it with our own content // TODO: We've emulated this for compatibility. BP should try to avoid // doing this unless actually necessary, because it costs an extra query on // each page load. $this->wp_query->queried_object_id = $this->intersect["endpoint_id"]; $this->wp_query->queried_object =& get_post($this->intersect["endpoint_id"]); return true; }
/** * xprofile_setup_adminbar_menu() * * Adds an admin bar menu to any profile page providing site admin options for that user. * * @package BuddyPress XProfile * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() */ function xprofile_setup_adminbar_menu() { global $bp; if ( !$bp->displayed_user->id ) return false; /* Don't show this menu to non site admins or if you're viewing your own profile */ if ( !is_super_admin() || bp_is_my_profile() ) return false; ?> <li id="bp-adminbar-adminoptions-menu"> <a href=""><?php _e( 'Admin Options', 'buddypress' ) ?></a> <ul> <li><a href="<?php echo $bp->displayed_user->domain . $bp->profile->slug ?>/edit/"><?php printf( __( "Edit %s's Profile", 'buddypress' ), esc_attr( $bp->displayed_user->fullname ) ) ?></a></li> <li><a href="<?php echo $bp->displayed_user->domain . $bp->profile->slug ?>/change-avatar/"><?php printf( __( "Edit %s's Avatar", 'buddypress' ), esc_attr( $bp->displayed_user->fullname ) ) ?></a></li> <?php if ( !bp_core_is_user_spammer( $bp->displayed_user->id ) ) : ?> <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/mark-spammer/', 'mark-unmark-spammer' ) ?>" class="confirm"><?php _e( "Mark as Spammer", 'buddypress' ) ?></a></li> <?php else : ?> <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/unmark-spammer/', 'mark-unmark-spammer' ) ?>" class="confirm"><?php _e( "Not a Spammer", 'buddypress' ) ?></a></li> <?php endif; ?> <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/delete-user/', 'delete-user' ) ?>" class="confirm"><?php printf( __( "Delete %s", 'buddypress' ), esc_attr( $bp->displayed_user->fullname ) ) ?></a></li> <?php do_action( 'xprofile_adminbar_menu_items' ) ?> </ul> </li> <?php }
/** * print users view (custom query + contents table) */ function view_users() { global $bp; $chk = ' checked="checked"'; $sel = ' selected="selected"'; ?> <form id="bpmod-users-query" class="bpmod-form-query" action="admin.php" method="get"> <input type="hidden" name="page" value="bp-moderation"/> <input type="hidden" name="view" value="users"/> <fieldset> <legend><?php _e('Custom Query', 'bp-moderation'); ?> </legend> <div class="column"> <h4><?php _e('Filters', 'bp-moderation'); ?> </h4> <dt> <input id='filter-user' <?php echo isset($_GET['active_filters']['user']) ? $chk : ''; ?> name='active_filters[user]' type='checkbox'/> <label for='filter-user'><?php _e('Specific users', 'bp-moderation'); ?> </label> </dt> <dd> <input id='user' class='line' size='40' type='text' name='filters[user]' value='<?php echo empty($_GET['filters']['user']) ? '' : $_GET['filters']['user']; ?> '/> <label for='user'><?php _e('User ids (comma separeted)', 'bp-moderation'); ?> </label> </dd> <?php $filters = array(array('own_flags', __('Total flags on own contents', 'bp-moderation'), __('Own contents have been flagged for a total of at least %s flags', 'bp-moderation')), array('own_contents', __('Total own contents reported', 'bp-moderation'), __('Own contents have been reported at least %s times', 'bp-moderation')), array('own_ignored', __('Ignored own contents', 'bp-moderation'), __('Own contents have been ignored at least %s times', 'bp-moderation')), array('own_moderated', __('Moderated own contents', 'bp-moderation'), __('Own contents have been moderated at least %s times', 'bp-moderation')), array('others_contents', __('Total contents reported by user', 'bp-moderation'), __('User has been reported at least %s contents', 'bp-moderation')), array('others_ignored', __('Ignored contents reported by user', 'bp-moderation'), __('Contents reported by user have been ignored at least %s times', 'bp-moderation')), array('others_moderated', __('Moderated contents reported by user', 'bp-moderation'), __('Contents reported by user have been moderated at least %s times', 'bp-moderation'))); foreach ($filters as $filter) { list($slug, $title, $desc) = $filter; ?> <dt> <input id='filter-<?php echo $slug; ?> ' <?php echo checked('on', @$_GET['active_filters'][$slug]); ?> name='active_filters[<?php echo $slug; ?> ]' type='checkbox'/> <label for='filter-<?php echo $slug; ?> '><?php echo $title; ?> </label> </dt> <dd> <label for='<?php echo $slug; ?> '><?php echo sprintf($desc, "<input id='{$slug}' size='4' type='text' name='filters[{$slug}]' value='" . (int) @$_GET['filters'][$slug] . "' />"); ?> </label> </dd> <?php } ?> </div> <div class="column"> <h4 class="order-by"><?php _e('Order', 'bp-moderation'); ?> </h4> <ol class="order-by"> <?php $i = 0; while (0 == $i || !empty($_GET['order'][$i])) { ?> <li><?php _e('Order by', 'bp-moderation'); $orby = empty($_GET['order'][$i]['by']) ? 'none' : $_GET['order'][$i]['by']; $asc = 'DESC' == @$_GET['order'][$i]['dir'] ? 'DESC' : 'ASC'; ?> <select name="order[<?php echo $i; ?> ][by]"> <option<?php selected('none', $orby); ?> value="none"><?php _e('none', 'bp-moderation'); ?> </option> <option<?php selected('own_contents', $orby); ?> value="own_contents"><?php _e('total own contents reported', 'bp-moderation'); ?> </option> <option<?php selected('own_new', $orby); ?> value="own_new"><?php _e('pending own contents'); ?> </option> <option<?php selected('own_ignored', $orby); ?> value="own_ignored"><?php _e('ignored own contents'); ?> </option> <option<?php selected('own_moderated', $orby); ?> value="own_moderated"><?php _e('moderated own contents'); ?> </option> <option<?php selected('own_flags', $orby); ?> value="own_flags"><?php _e('total flags on own contents'); ?> </option> <option<?php selected('others_contents', $orby); ?> value="others_contents"><?php _e('total contents reported by user', 'bp-moderation'); ?> </option> <option<?php selected('others_new', $orby); ?> value="others_new"><?php _e('pending contents reported by user', 'bp-moderation'); ?> </option> <option<?php selected('others_ignored', $orby); ?> value="others_ignored"><?php _e('ignored contents reported by user', 'bp-moderation'); ?> </option> <option<?php selected('others_moderated', $orby); ?> value="others_moderated"><?php _e('moderated contents reported by user', 'bp-moderation'); ?> </option> </select> <select name="order[<?php echo $i; ?> ][dir]"> <option<?php selected('ASC', $asc); ?> value="ASC">ASC </option> <option<?php selected('DESC', $asc); ?> value="DESC">DESC </option> </select> </li> <?php $i++; } ?> </ol> <h4><?php _e('Limit', 'bp-moderation'); ?> </h4> <p><label for='limit'><?php $input = "<input id='limit' size='4' type='text' name='per_page' value='" . (empty($_GET['per_page']) ? '20' : $_GET['per_page']) . "' />"; echo sprintf(__('Display at most %s users', 'bp-moderation'), $input); ?> </label> </p> <input name="submit" type="submit" class="button-primary" value="<?php _e('Query Users', 'bp-moderation'); ?> "/> </div> </fieldset> </form> <div class="clear"></div> <?php extract($this->query_users()); if ($total) { $page_links = paginate_links(array('base' => add_query_arg('page', '%#%'), 'format' => '', 'prev_text' => __('«'), 'next_text' => __('»'), 'total' => ceil($total / $per_page), 'current' => $page_index + 1)); ?> <form id="bpmod-users-form" class="bpmod-bulk-form" action="admin.php" method="post"> <div class="tablenav"> <div class="alignleft actions"> <select name="bulk-action"> <option value="-1" selected="selected"><?php _e('Bulk Actions', 'bp-moderation'); ?> </option> <option value="mark_spammer"><?php _e('Mark users as spammers', 'bp-moderation'); ?> </option> <option value="unmark_spammer"><?php _e('Mark users as not spammers', 'bp-moderation'); ?> </option> </select> <input type="hidden" name="bpmod-action" value="bulk_users"/> <?php wp_nonce_field('bulk_users'); ?> <input type="submit" name="doaction" id="doaction" value="<?php esc_attr_e('Apply', 'bp-moderation'); ?> " class="button-secondary apply"/> </div> <div class="tablenav-pages"><?php if ($page_links) { echo '<span class="displaying-num">' . sprintf(__('Displaying %s–%s of %s', 'bp-moderation'), number_format_i18n($page_index * $per_page + 1), number_format_i18n(min(($page_index + 1) * $per_page, $total)), '<span class="total-type-count">' . number_format_i18n($total) . '</span>') . "</span>{$page_links}"; } ?> </div> </div> <div class="clear"></div> <table id="bpmod-users-table" class="widefat bpmod-table fixed" cellspacing="0"> <thead> <tr> <th class="manage-column column-cb check-column" scope="col"><input type="checkbox"></th> <th class="manage-column column-author" scope="col"><?php _e('User', 'bp-moderation'); ?> </th> <th class="manage-column column-own-contents" scope="col"><?php _e('Own contents reported by others', 'bp-moderation'); ?> </th> <th class="manage-column column-other-contents" scope="col"><?php _e('Contents reported by user', 'bp-moderation'); ?> </th> </tr> </thead> <tfoot> <tr> <th class="manage-column column-cb check-column" scope="col"><input type="checkbox"></th> <th class="manage-column column-author" scope="col"><?php _e('User', 'bp-moderation'); ?> </th> <th class="manage-column column-own-contents" scope="col"><?php _e('Own contents reported by others', 'bp-moderation'); ?> </th> <th class="manage-column column-other-contents" scope="col"><?php _e('Contents reported by user', 'bp-moderation'); ?> </th> </tr> </tfoot> <tbody> <?php foreach ($results as $user) { $author = $this->author_details($user->user_id); ?> <tr class=""> <th class="check-column" scope="row"><input type="checkbox" value="<?php echo $user->user_id; ?> " name="bulk_items[]"></th> <td class="column-author"> <strong><?php echo $author['avatar_img'] . $author['user_link']; ?> </strong> <br><?php echo $author['contact_link']; ?> <div class="row-actions"> <?php if (!get_userdata($user->user_id)) { ?> <span class="not-a-member"><?php _e('Unregistered', 'bp-moderation'); ?> </span> <?php } elseif (bp_core_is_user_spammer($user->user_id)) { ?> <a class="unmark-spammer vim-u" href="<?php echo wp_nonce_url("admin.php?bpmod-action=mark_unmark_spammer&user_id={$user->user_id}&set_spam=0", 'mark_unmark_spammer'); ?> " title="<?php _e('Mark the author of this content as not spammer', 'bp-moderation'); ?> "><?php _e('Mark as not spammer', 'bp-moderation'); ?> </a> <?php } else { ?> <a class="mark-spammer vim-s" href="<?php echo wp_nonce_url("admin.php?bpmod-action=mark_unmark_spammer&user_id={$user->user_id}&set_spam=1", 'mark_unmark_spammer'); ?> " title="<?php _e('Mark the author of this content as spammer', 'bp-moderation'); ?> "><?php _e('Mark as spammer', 'bp-moderation'); ?> </a> <?php } ?> </div> </td> <td class="column-own-contents"> <?php echo sprintf(_n('%d content from this user has been reported', '%d contents from this user have been reported', $user->own_contents, 'bp-moderation'), $user->own_contents); if ($user->own_contents) { ?> <br/> <strong><?php _e('New:', 'bp-moderation'); ?> </strong> <?php echo $user->own_new; ?> <strong><?php _e('Ignored:', 'bp-moderation'); ?> </strong> <?php echo $user->own_ignored; ?> <strong><?php _e('Moderated:', 'bp-moderation'); ?> </strong> <?php echo $user->own_moderated; ?> <strong><?php _e('Total flags:', 'bp-moderation'); ?> </strong> <?php echo $user->own_flags; } ?> <div class="row-actions"> <a class="vim-b" href="admin.php?page=bp-moderation&view=contents&filters[active_filters][item_author]=on&filters[item_author]=<?php echo $user->user_id; ?> " title="<?php _e('Show the contents from this user that have been reported in the contents view', 'bp-moderation'); ?> "><?php _e('Show in contents view', 'bp-moderation'); ?> </a> </div> </td> <td class="column-other-contents"> <?php echo sprintf(_n('this user reported %d content', 'this user reported %d contents', $user->others_contents, 'bp-moderation'), $user->others_contents); if ($user->others_contents) { ?> <br/> <strong><?php _e('New:', 'bp-moderation'); ?> </strong> <?php echo $user->others_new; ?> <strong><?php _e('Ignored:', 'bp-moderation'); ?> </strong> <?php echo $user->others_ignored; ?> <strong><?php _e('Moderated:', 'bp-moderation'); ?> </strong> <?php echo $user->others_moderated; } ?> <div class="row-actions"> <a class="vim-g" href="admin.php?page=bp-moderation&view=contents&filters[active_filters][reporters]=on&filters[reporters]=<?php echo $user->user_id; ?> " title="<?php _e('Show the contents from this user that have been reported in the contents view', 'bp-moderation'); ?> "><?php _e('Show in contents view', 'bp-moderation'); ?> </a> </div> </td> </tr> <?php } ?> </tbody> </table> </form> <?php $this->print_hotkeys_toggle(); ?> <?php } else { _e('No users to display, try a different search', 'bp-moderation'); } }