function bp_activity_at_message_notification( $content, $poster_user_id, $activity_id ) { global $bp; /* Scan for @username strings in an activity update. Notify each user. */ $pattern = '/[@]+([A-Za-z0-9-_\.]+)/'; preg_match_all( $pattern, $content, $usernames ); /* Make sure there's only one instance of each username */ if ( !$usernames = array_unique( $usernames[1] ) ) return false; foreach( (array)$usernames as $username ) { if ( !$receiver_user_id = bp_core_get_userid( $username ) ) continue; // Now email the user with the contents of the message (if they have enabled email notifications) if ( 'no' != get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) { $poster_name = bp_core_get_user_displayname( $poster_user_id ); $message_link = bp_activity_get_permalink( $activity_id ); $settings_link = bp_core_get_user_domain( $receiver_user_id ) . BP_SETTINGS_SLUG . '/notifications/'; $poster_name = stripslashes( $poster_name ); $content = bp_activity_filter_kses( stripslashes($content) ); // Set up and send the message $ud = bp_core_get_core_userdata( $receiver_user_id ); $to = $ud->user_email; $sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES ); $subject = '[' . $sitename . '] ' . sprintf( __( '%s mentioned you in an update', 'buddypress' ), $poster_name ); $message = sprintf( __( '%s mentioned you in an update: "%s" To view and respond to the message, log in and visit: %s --------------------- ', 'buddypress' ), $poster_name, $content, $message_link ); $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link ); /* Send the message */ $to = apply_filters( 'bp_activity_at_message_notification_to', $to ); $subject = apply_filters( 'bp_activity_at_message_notification_subject', $subject, $poster_name ); $message = apply_filters( 'bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link ); wp_mail( $to, $subject, $message ); } } }
function bp_links_at_message_notification($content, $poster_user_id, $link_id, $activity_id) { global $bp; /* Scan for @username strings in an activity update. Notify each user. */ $pattern = '/[@]+([A-Za-z0-9-_]+)/'; preg_match_all($pattern, $content, $usernames); /* Make sure there's only one instance of each username */ if (!($usernames = array_unique($usernames[1]))) { return false; } $link = new BP_Links_Link($link_id); foreach ((array) $usernames as $username) { if (!($receiver_user_id = bp_core_get_userid($username))) { continue; } if (!bp_links_is_link_visibile($link, $receiver_user_id)) { continue; } // Now email the user with the contents of the message (if they have enabled email notifications) if ('no' != get_usermeta($user_id, 'notification_activity_new_mention')) { $poster_name = bp_core_get_user_displayname($poster_user_id); $message_link = bp_activity_get_permalink($activity_id); $settings_link = bp_core_get_user_domain($receiver_user_id) . 'settings/notifications/'; // Set up and send the message $ud = bp_core_get_core_userdata($receiver_user_id); $to = $ud->user_email; $subject = '[' . get_blog_option(BP_ROOT_BLOG, 'blogname') . '] ' . sprintf(__('%s mentioned you in the link "%s"', 'buddypress-links'), stripslashes($poster_name), wp_filter_kses(stripslashes($link->name))); $message = sprintf(__('%s mentioned you in the link "%s": "%s" To view and respond to the message, log in and visit: %s --------------------- ', 'buddypress-links'), $poster_name, wp_filter_kses(stripslashes_deep($link->name)), wp_filter_kses(stripslashes_deep($content)), $message_link); $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link); // Send it wp_mail($to, $subject, $message); } } }
/** * For the nxt_login action, manually retrieve the user ID as it won't be conventionally accessible until the next page load. * * @param int $user_id * @param string $action_name * @param array $action_func_args The action's arguments, from func_get_args(). * @return int|bool User ID or, if false is returned, this Achievement will be skipped. * @since 2.0.5 */ function dpa_filter_nxt_login_user_id($user_id, $action_name, $action_func_args) { if ('nxt_login' != $action_name) { return $user_id; } if (empty($action_func_args[0]) || is_nxt_error($action_func_args[0])) { return $user_id; } $the_user_id = bp_core_get_userid($action_func_args[0]); if (!$the_user_id) { return $user_id; } return apply_filters('dpa_filter_nxt_login_user_id', (int) $the_user_id); }
/** * bp_core_get_user_displayname() * * Fetch the display name for a user. This will use the "Name" field in xprofile if it is installed. * Otherwise, it will fall back to the normal WP display_name, or user_nicename, depending on what has been set. * * @package BuddyPress Core * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() * @uses wp_cache_get() Will try and fetch the value from the cache, rather than querying the DB again. * @uses get_userdata() Fetches the WP userdata for a specific user. * @uses xprofile_set_field_data() Will update the field data for a user based on field name and user id. * @uses wp_cache_set() Adds a value to the cache. * @return str The display name for the user in question. */ function bp_core_get_user_displayname( $user_id_or_username ) { global $bp; if ( !$user_id_or_username ) return false; if ( !is_numeric( $user_id_or_username ) ) $user_id = bp_core_get_userid( $user_id_or_username ); else $user_id = $user_id_or_username; if ( !$user_id ) return false; if ( !$fullname = wp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' ) ) { if ( function_exists('xprofile_install') ) { $fullname = xprofile_get_field_data( 1, $user_id ); if ( empty($fullname) ) { $ud = bp_core_get_core_userdata( $user_id ); if ( !empty( $ud->display_name ) ) $fullname = $ud->display_name; else $fullname = $ud->user_nicename; xprofile_set_field_data( 1, $user_id, $fullname ); } } else { $ud = bp_core_get_core_userdata($user_id); if ( !empty( $ud->display_name ) ) $fullname = $ud->display_name; else $fullname = $ud->user_nicename; } if ( !empty( $fullname ) ) wp_cache_set( 'bp_user_fullname_' . $user_id, $fullname, 'bp' ); } return apply_filters( 'bp_core_get_user_displayname', $fullname, $user_id ); }
function devb_aawire_update_activity_action($action, $activity) { //check if this is a wall post? if (!bp_activity_get_meta($activity->id, 'is_wire_post', true)) { return $action; } //if we are here, It must be a wire post //since bp 2.0, I have added a meta key to store the user id on whose wall we are posting if (!($user_id = bp_activity_get_meta($activity->id, 'wire_user_id', true))) { //before 2.0, since the id did not exist, we will be using the @mention finding username $usernames = bp_activity_find_mentions($activity->content); if (is_array($usernames)) { $usernames = array_pop($usernames); } if ($usernames) { $user_id = bp_core_get_userid($usernames); } } if (!$user_id) { //we don't have info about the person on whose wall this poat was made return $action; } //if we are here, let us say something nice really nice $action = sprintf(__('%s posted on %s\'s wall', 'buddypress'), bp_core_get_userlink($activity->user_id), bp_core_get_userlink($user_id)); return $action; }
/** * Analyze the URI and break it down into BuddyPress-usable chunks. * * BuddyPress can use complete custom friendly URIs without the user having to * add new rewrite rules. Custom components are able to use their own custom * URI structures with very little work. * * The URIs are broken down as follows: * - http:// example.com / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ... * - OUTSIDE ROOT: http:// example.com / sites / buddypress / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ... * * Example: * - http://example.com/members/andy/profile/edit/group/5/ * - $bp->current_component: string 'xprofile' * - $bp->current_action: string 'edit' * - $bp->action_variables: array ['group', 5] * * @since 1.0.0 */ function bp_core_set_uri_globals() { global $current_blog, $wp_rewrite; // Don't catch URIs on non-root blogs unless multiblog mode is on. if (!bp_is_root_blog() && !bp_is_multiblog_mode()) { return false; } $bp = buddypress(); // Define local variables. $root_profile = $match = false; $key_slugs = $matches = $uri_chunks = array(); // Fetch all the WP page names for each component. if (empty($bp->pages)) { $bp->pages = bp_core_get_directory_pages(); } // Ajax or not? if (defined('DOING_AJAX') && DOING_AJAX || strpos($_SERVER['REQUEST_URI'], 'wp-load.php')) { $path = bp_get_referer_path(); } else { $path = esc_url($_SERVER['REQUEST_URI']); } /** * Filters the BuddyPress global URI path. * * @since 1.0.0 * * @param string $path Path to set. */ $path = apply_filters('bp_uri', $path); // Take GET variables off the URL to avoid problems. $path = strtok($path, '?'); // Fetch 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]); } } // If running off blog other than root, any subdirectory names must be // removed from $bp_uri. This includes two cases: // // 1. when WP is installed in a subdirectory, // 2. when BP is running on secondary blog of a subdirectory // multisite installation. Phew! if (is_multisite() && !is_subdomain_install() && (bp_is_multiblog_mode() || 1 != bp_get_root_blog_id())) { // Blow chunks. $chunks = explode('/', $current_blog->path); // If chunks exist... if (!empty($chunks)) { // ...loop through them... foreach ($chunks as $key => $chunk) { $bkey = array_search($chunk, $bp_uri); // ...and unset offending keys if (false !== $bkey) { unset($bp_uri[$bkey]); } $bp_uri = array_values($bp_uri); } } } // 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); } // Reset indexes. $bp_uri = array_values($bp_uri); $paths = array_values($paths); // Unset URI indices if they intersect with the paths. foreach ((array) $bp_uri as $key => $uri_chunk) { if (isset($paths[$key]) && $uri_chunk == $paths[$key]) { 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 WP 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; // Don't use $bp_unfiltered_uri, this is only for backpat with old plugins. Use $bp->unfiltered_uri. $GLOBALS['bp_unfiltered_uri'] =& $bp->unfiltered_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) && bp_core_enable_root_profiles()) { // Switch field based on compat. $field = bp_is_username_compatibility_mode() ? 'login' : 'slug'; // 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($field, $bp_uri[0]))) { // Force BP to recognize that this is a members page. $matches[] = 1; $match = $bp->pages->members; $match->key = 'members'; } } // 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 (empty($matches)) { return false; } $wp_rewrite->use_verbose_page_rules = 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)) { // Only offset if not on a root profile. Fixes issue when Members page is nested. if (false === $root_profile) { 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) { $after_member_slug = false; if (!empty($bp_uri[$uri_offset + 1])) { $after_member_slug = $bp_uri[$uri_offset + 1]; } // Are we viewing a specific user? if ($after_member_slug) { // If root profile, we've already queried for the user. if ($root_profile instanceof WP_User) { $bp->displayed_user->id = $root_profile->ID; // Switch the displayed_user based on compatibility mode. } elseif (bp_is_username_compatibility_mode()) { $bp->displayed_user->id = (int) bp_core_get_userid(urldecode($after_member_slug)); } else { $bp->displayed_user->id = (int) bp_core_get_userid_from_nicename($after_member_slug); } } // Is this a member type directory? if (!bp_displayed_user_id() && $after_member_slug === apply_filters('bp_members_member_type_base', _x('type', 'member type URL base', 'buddypress')) && !empty($bp_uri[$uri_offset + 2])) { $matched_types = bp_get_member_types(array('has_directory' => true, 'directory_slug' => $bp_uri[$uri_offset + 2])); if (!empty($matched_types)) { $bp->current_member_type = reset($matched_types); unset($bp_uri[$uri_offset + 1]); } } // If the slug matches neither a member type nor a specific member, 404. if (!bp_displayed_user_id() && !bp_get_current_member_type() && $after_member_slug) { // 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 (bp_displayed_user_id() && bp_is_user_spammer(bp_displayed_user_id())) { if (bp_current_user_can('bp_moderate')) { bp_core_add_message(__('This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress'), 'warning'); } else { bp_do_404(); return; } } // Bump the offset. if (bp_displayed_user_id()) { 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; } } } // Determine the current action. $current_action = isset($bp_uri[$uri_offset + 1]) ? $bp_uri[$uri_offset + 1] : ''; /* * If a BuddyPress directory is set to the WP front page, URLs like example.com/members/?s=foo * shouldn't interfere with blog searches. */ if (empty($current_action) && !empty($_GET['s']) && 'page' == get_option('show_on_front') && !empty($match->id)) { $page_on_front = (int) get_option('page_on_front'); if ((int) $match->id === $page_on_front) { $bp->current_component = ''; return false; } } $bp->current_action = $current_action; // 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; // Reset the keys by merging with an empty array. $bp->action_variables = array_merge(array(), $bp->action_variables); }
/** * Return the user link for the user based on the supplied identifier. * * @since 1.0.0 * * @param string $username If BP_ENABLE_USERNAME_COMPATIBILITY_MODE is set, * this should be user_login, otherwise it should * be user_nicename. * @return string|bool The link to the user's domain, false on no match. */ function bp_core_get_userlink_by_username($username) { if (bp_is_username_compatibility_mode()) { $user_id = bp_core_get_userid($username); } else { $user_id = bp_core_get_userid_from_nicename($username); } /** * Filters the user link for the user based on username. * * @since 1.0.1 * * @param string|bool $value URL for the user if found, otherwise false. */ return apply_filters('bp_core_get_userlink_by_username', bp_core_get_userlink($user_id, false, false, true)); }
/** * Returns the user link for the user based on the supplied identifier * * @param $username str If BP_ENABLE_USERNAME_COMPATIBILITY_MODE is set, this will be user_login, otherwise it will be user_nicename. * @return str The link to the users home base. False on no match. */ function bp_core_get_userlink_by_username($username) { if (bp_is_username_compatibility_mode()) { $user_id = bp_core_get_userid($username); } else { $user_id = bp_core_get_userid_from_nicename($username); } return apply_filters('bp_core_get_userlink_by_username', bp_core_get_userlink($user_id, false, false, true)); }
/** * Output the markup for the message recipient tabs. */ function bp_message_get_recipient_tabs() { $recipients = explode(' ', bp_get_message_get_recipient_usernames()); foreach ($recipients as $recipient) { $user_id = bp_is_username_compatibility_mode() ? bp_core_get_userid($recipient) : bp_core_get_userid_from_nicename($recipient); if (!empty($user_id)) { ?> <li id="un-<?php echo esc_attr($recipient); ?> " class="friend-tab"> <span><?php echo bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'width' => 15, 'height' => 15)); echo bp_core_get_userlink($user_id); ?> </span> </li> <?php } } }
/** * Create a new message. * * @since 2.4.0 Added 'error_type' as an additional $args parameter. * * @param array|string $args { * Array of arguments. * @type int $sender_id Optional. ID of the user who is sending the * message. Default: ID of the logged-in user. * @type int $thread_id Optional. ID of the parent thread. Leave blank to * create a new thread for the message. * @type array $recipients IDs or usernames of message recipients. If this * is an existing thread, it is unnecessary to pass a $recipients * argument - existing thread recipients will be assumed. * @type string $subject Optional. Subject line for the message. For * existing threads, the existing subject will be used. For new * threads, 'No Subject' will be used if no $subject is provided. * @type string $content Content of the message. Cannot be empty. * @type string $date_sent Date sent, in 'Y-m-d H:i:s' format. Default: current date/time. * @type string $error_type Optional. Error type. Either 'bool' or 'wp_error'. Default: 'bool'. * } * @return int|bool ID of the message thread on success, false on failure. */ function messages_new_message($args = '') { // Parse the default arguments. $r = bp_parse_args($args, array('sender_id' => bp_loggedin_user_id(), 'thread_id' => false, 'recipients' => array(), 'subject' => false, 'content' => false, 'date_sent' => bp_core_current_time(), 'error_type' => 'bool'), 'messages_new_message'); // Bail if no sender or no content. if (empty($r['sender_id']) || empty($r['content'])) { if ('wp_error' === $r['error_type']) { if (empty($r['sender_id'])) { $error_code = 'messages_empty_sender'; $feedback = __('Your message was not sent. Please use a valid sender.', 'buddypress'); } else { $error_code = 'messages_empty_content'; $feedback = __('Your message was not sent. Please enter some content.', 'buddypress'); } return new WP_Error($error_code, $feedback); } else { return false; } } // Create a new message object. $message = new BP_Messages_Message(); $message->thread_id = $r['thread_id']; $message->sender_id = $r['sender_id']; $message->subject = $r['subject']; $message->message = $r['content']; $message->date_sent = $r['date_sent']; // If we have a thread ID... if (!empty($r['thread_id'])) { // ...use the existing recipients $thread = new BP_Messages_Thread($r['thread_id']); $message->recipients = $thread->get_recipients(); // Strip the sender from the recipient list, and unset them if they are // not alone. If they are alone, let them talk to themselves. if (isset($message->recipients[$r['sender_id']]) && count($message->recipients) > 1) { unset($message->recipients[$r['sender_id']]); } // Set a default reply subject if none was sent. if (empty($message->subject)) { $message->subject = sprintf(__('Re: %s', 'buddypress'), $thread->messages[0]->subject); } // ...otherwise use the recipients passed } else { // Bail if no recipients. if (empty($r['recipients'])) { if ('wp_error' === $r['error_type']) { return new WP_Error('message_empty_recipients', __('Message could not be sent. Please enter a recipient.', 'buddypress')); } else { return false; } } // Set a default subject if none exists. if (empty($message->subject)) { $message->subject = __('No Subject', 'buddypress'); } // Setup the recipients array. $recipient_ids = array(); // Invalid recipients are added to an array, for future enhancements. $invalid_recipients = array(); // Loop the recipients and convert all usernames to user_ids where needed. foreach ((array) $r['recipients'] as $recipient) { // Trim spaces and skip if empty. $recipient = trim($recipient); if (empty($recipient)) { continue; } // Check user_login / nicename columns first // @see http://buddypress.trac.wordpress.org/ticket/5151. if (bp_is_username_compatibility_mode()) { $recipient_id = bp_core_get_userid(urldecode($recipient)); } else { $recipient_id = bp_core_get_userid_from_nicename($recipient); } // Check against user ID column if no match and if passed recipient is numeric. if (empty($recipient_id) && is_numeric($recipient)) { if (bp_core_get_core_userdata((int) $recipient)) { $recipient_id = (int) $recipient; } } // Decide which group to add this recipient to. if (empty($recipient_id)) { $invalid_recipients[] = $recipient; } else { $recipient_ids[] = (int) $recipient_id; } } // Strip the sender from the recipient list, and unset them if they are // not alone. If they are alone, let them talk to themselves. $self_send = array_search($r['sender_id'], $recipient_ids); if (!empty($self_send) && count($recipient_ids) > 1) { unset($recipient_ids[$self_send]); } // Remove duplicates & bail if no recipients. $recipient_ids = array_unique($recipient_ids); if (empty($recipient_ids)) { if ('wp_error' === $r['error_type']) { return new WP_Error('message_invalid_recipients', __('Message could not be sent because you have entered an invalid username. Please try again.', 'buddypress')); } else { return false; } } // Format this to match existing recipients. foreach ((array) $recipient_ids as $i => $recipient_id) { $message->recipients[$i] = new stdClass(); $message->recipients[$i]->user_id = $recipient_id; } } // Bail if message failed to send. $send = $message->send(); if (false === is_int($send)) { if ('wp_error' === $r['error_type']) { if (is_wp_error($send)) { return $send; } else { return new WP_Error('message_generic_error', __('Message was not sent. Please try again.', 'buddypress')); } } return false; } /** * Fires after a message has been successfully sent. * * @since 1.1.0 * * @param BP_Messages_Message $message Message object. Passed by reference. */ do_action_ref_array('messages_message_sent', array(&$message)); // Return the thread ID. return $message->thread_id; }
function messages_new_message($args = '') { $defaults = array('sender_id' => bp_loggedin_user_id(), 'thread_id' => false, 'recipients' => false, 'subject' => false, 'content' => false, 'date_sent' => bp_core_current_time()); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); if (empty($sender_id) || empty($content)) { return false; } // Create a new message object $message = new BP_Messages_Message(); $message->thread_id = $thread_id; $message->sender_id = $sender_id; $message->subject = $subject; $message->message = $content; $message->date_sent = $date_sent; // If we have a thread ID, use the existing recipients, otherwise use the recipients passed if (!empty($thread_id)) { $thread = new BP_Messages_Thread($thread_id); $message->recipients = $thread->get_recipients(); // Strip the sender from the recipient list if they exist if (isset($message->recipients[$sender_id])) { unset($message->recipients[$sender_id]); } if (empty($message->subject)) { $message->subject = sprintf(__('Re: %s', 'buddypress'), $thread->messages[0]->subject); } // No thread ID, so make some adjustments } else { if (empty($recipients)) { return false; } if (empty($message->subject)) { $message->subject = __('No Subject', 'buddypress'); } $recipient_ids = array(); // Invalid recipients are added to an array, for future enhancements $invalid_recipients = array(); // Loop the recipients and convert all usernames to user_ids where needed foreach ((array) $recipients as $recipient) { $recipient = trim($recipient); if (empty($recipient)) { continue; } $recipient_id = false; // input was numeric if (is_numeric($recipient)) { // do a check against the user ID column first if (bp_core_get_core_userdata((int) $recipient)) { $recipient_id = (int) $recipient; } else { if (bp_is_username_compatibility_mode()) { $recipient_id = bp_core_get_userid((int) $recipient); } else { $recipient_id = bp_core_get_userid_from_nicename((int) $recipient); } } } else { if (bp_is_username_compatibility_mode()) { $recipient_id = bp_core_get_userid($recipient); } else { $recipient_id = bp_core_get_userid_from_nicename($recipient); } } if (!$recipient_id) { $invalid_recipients[] = $recipient; } else { $recipient_ids[] = (int) $recipient_id; } } // Strip the sender from the recipient list if they exist if ($key = array_search($sender_id, (array) $recipient_ids)) { unset($recipient_ids[$key]); } // Remove duplicates $recipient_ids = array_unique((array) $recipient_ids); if (empty($recipient_ids)) { return false; } // Format this to match existing recipients foreach ((array) $recipient_ids as $i => $recipient_id) { $message->recipients[$i] = new stdClass(); $message->recipients[$i]->user_id = $recipient_id; } } if ($message->send()) { // Send screen notifications to the recipients foreach ((array) $message->recipients as $recipient) { bp_core_add_notification($message->id, $recipient->user_id, 'messages', 'new_message'); } // Send email notifications to the recipients messages_notification_new_message(array('message_id' => $message->id, 'sender_id' => $message->sender_id, 'subject' => $message->subject, 'content' => $message->message, 'recipients' => $message->recipients, 'thread_id' => $message->thread_id)); do_action_ref_array('messages_message_sent', array(&$message)); return $message->thread_id; } return false; }
function bp_gtm_do_task_actions() { global $bp, $wpdb; if ($_GET['action_type'] == 'complete') { $wpdb->query($wpdb->prepare("\n UPDATE {$bp->gtm->table_tasks}\n SET `done` = 1\n WHERE `id` = {$_GET['task_id']} OR `parent_id` = {$_GET['task_id']}")); $task = BP_GTM_Tasks::get_task_by_id($_GET['task_id']); $resps = explode(' ', $task['0']->resp_id); foreach ($resps as $resp) { if ($resp != '') { $resp_id = bp_core_get_userid($resp); if ($resp_id != $bp->loggedin_user->id) { bp_core_add_notification($_GET['task_id'], $resp_id, $bp->gtm->slug, 'task_done', $bp->groups->current_group->id); } } } echo 'completed'; } elseif ($_GET['action_type'] == 'delete') { $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_tasks} WHERE `id` = %d AND `group_id` = %d", $_GET['task_id'], $bp->groups->current_group->id)); $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_taxon} WHERE `task_id` = %d AND `group_id` = %d", $_GET['task_id'], $bp->groups->current_group->id)); $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_resps} WHERE `task_id` = %d AND `group_id` = %d", $_GET['task_id'], $bp->groups->current_group->id)); $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_discuss} WHERE `task_id` = %d AND `group_id` = %d", $_GET['task_id'], $bp->groups->current_group->id)); $wpdb->query($wpdb->prepare("DELETE FROM {$bp->core->table_name_notifications} WHERE `item_id` = %d AND `secondary_item_id` = %d AND `component_name` = {$bp->gtm->slug} AND `component_action` LIKE `task_%%`", $_GET['task_id'], $bp->groups->current_group->id)); $task = BP_GTM_Tasks::get_task_by_id($_GET['task_id']); $resps = explode(' ', $task['0']->resp_id); foreach ($resps as $resp) { if ($resp != '') { $resp_id = bp_core_get_userid($resp); if ($resp_id != $bp->loggedin_user->id) { bp_core_add_notification($_GET['task_id'], $resp_id, $bp->gtm->slug, 'task_deleted', $bp->groups->current_group->id); } } } echo 'deleted'; } die; }
function bp_activity_at_name_filter( $content ) { include_once( ABSPATH . WPINC . '/registration.php' ); $pattern = '/[@]+([A-Za-z0-9-_\.]+)/'; preg_match_all( $pattern, $content, $usernames ); // Make sure there's only one instance of each username if ( !$usernames = array_unique( $usernames[1] ) ) return $content; foreach( (array)$usernames as $username ) { if ( !$user_id = username_exists( $username ) ) continue; // Increase the number of new @ mentions for the user $new_mention_count = (int)get_user_meta( $user_id, 'bp_new_mention_count', true ); update_user_meta( $user_id, 'bp_new_mention_count', $new_mention_count + 1 ); $content = str_replace( "@$username", "<a href='" . bp_core_get_user_domain( bp_core_get_userid( $username ) ) . "' rel='nofollow'>@$username</a>", $content ); } return $content; }
function bp_forums_load_bbpress() { global $bp, $wpdb, $wp_roles, $current_user, $wp_users_object; global $bb, $bbdb, $bb_table_prefix, $bb_current_user; global $bb_roles, $wp_taxonomy_object; /* Return if we've already run this function. */ if ( is_object( $bbdb ) && is_object( $bb_roles ) ) return; if ( !bp_forums_is_installed_correctly() ) return false; define( 'BB_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/' ); define( 'BACKPRESS_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-includes/backpress/' ); define( 'BB_URL', BP_PLUGIN_URL . '/bp-forums/bbpress/' ); define( 'BB_INC', 'bb-includes/' ); require_once( BB_PATH . BB_INC . 'class.bb-query.php' ); require_once( BB_PATH . BB_INC . 'class.bb-walker.php' ); require_once( BB_PATH . BB_INC . 'functions.bb-core.php' ); require_once( BB_PATH . BB_INC . 'functions.bb-forums.php' ); require_once( BB_PATH . BB_INC . 'functions.bb-topics.php' ); require_once( BB_PATH . BB_INC . 'functions.bb-posts.php' ); require_once( BB_PATH . BB_INC . 'functions.bb-topic-tags.php' ); require_once( BB_PATH . BB_INC . 'functions.bb-capabilities.php' ); require_once( BB_PATH . BB_INC . 'functions.bb-meta.php' ); require_once( BB_PATH . BB_INC . 'functions.bb-pluggable.php' ); require_once( BB_PATH . BB_INC . 'functions.bb-formatting.php' ); require_once( BB_PATH . BB_INC . 'functions.bb-template.php' ); require_once( BACKPRESS_PATH . 'class.wp-taxonomy.php' ); require_once( BB_PATH . BB_INC . 'class.bb-taxonomy.php' ); $bb = new stdClass(); require_once( $bp->forums->bbconfig ); // Setup the global database connection $bbdb = new BPDB ( BBDB_USER, BBDB_PASSWORD, BBDB_NAME, BBDB_HOST ); /* Set the table names */ $bbdb->forums = $bb_table_prefix . 'forums'; $bbdb->meta = $bb_table_prefix . 'meta'; $bbdb->posts = $bb_table_prefix . 'posts'; $bbdb->terms = $bb_table_prefix . 'terms'; $bbdb->term_relationships = $bb_table_prefix . 'term_relationships'; $bbdb->term_taxonomy = $bb_table_prefix . 'term_taxonomy'; $bbdb->topics = $bb_table_prefix . 'topics'; if ( isset( $bb->custom_user_table ) ) $bbdb->users = $bb->custom_user_table; else $bbdb->users = $wpdb->users; if ( isset( $bb->custom_user_meta_table ) ) $bbdb->usermeta = $bb->custom_user_meta_table; else $bbdb->usermeta = $wpdb->usermeta; $bbdb->prefix = $bb_table_prefix; define( 'BB_INSTALLING', false ); /* This must be loaded before functionss.bb-admin.php otherwise we get a function conflict. */ if ( !$tables_installed = (boolean) $bbdb->get_results( 'DESCRIBE `' . $bbdb->forums . '`;', ARRAY_A ) ) require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); require_once( BB_PATH . 'bb-admin/includes/functions.bb-admin.php' ); if ( is_object( $wp_roles ) ) { $bb_roles = $wp_roles; bb_init_roles( $bb_roles ); } do_action( 'bb_got_roles' ); do_action( 'bb_init' ); do_action( 'init_roles' ); $bb_current_user = $current_user; $wp_users_object = new BP_Forums_BB_Auth; if ( !isset( $wp_taxonomy_object ) ) $wp_taxonomy_object = new BB_Taxonomy( $bbdb ); $wp_taxonomy_object->register_taxonomy( 'bb_topic_tag', 'bb_topic' ); // Set a site id if there isn't one already if ( !isset( $bb->site_id ) ) $bb->site_id = BP_ROOT_BLOG; /* Check if the tables are installed, if not, install them */ if ( !$tables_installed ) { require_once( BB_PATH . 'bb-admin/includes/defaults.bb-schema.php' ); /* Backticks and "IF NOT EXISTS" break the dbDelta function. */ dbDelta( str_replace( ' IF NOT EXISTS', '', str_replace( '`', '', $bb_queries ) ) ); require_once( BB_PATH . 'bb-admin/includes/functions.bb-upgrade.php' ); bb_update_db_version(); /* Set the site admins as the keymasters */ $site_admins = get_site_option( 'site_admins', array('admin') ); foreach ( (array)$site_admins as $site_admin ) update_user_meta( bp_core_get_userid( $site_admin ), $bb_table_prefix . 'capabilities', array( 'keymaster' => true ) ); // Create the first forum. bb_new_forum( array( 'forum_name' => 'Default Forum' ) ); // Set the site URI bb_update_option( 'uri', BB_URL ); } register_shutdown_function( create_function( '', 'do_action("bb_shutdown");' ) ); }
protected function bp_gtm_edit_g_task($data) { global $bp, $wpdb; if (!check_admin_referer('bp_gtm_edit_task')) { return false; } $task_id = $_POST['task_id']; if (!$project_id) { $project_id = $_POST['task_project']; } $name = apply_filters('bp_gtm_task_name_content', $_POST['task_name']); $description = apply_filters('bp_gtm_task_desc_content', $_POST['task_desc']); $status = bp_gtm_get_project_status($project_id); // resps workaround if (!empty($_POST['user_ids'])) { $task_resps_old = $_POST['user_ids']; // array{ slaFFik: 0, bot1: 1, ... } } else { $task_resps_old = array(); } $resps = (array) $task_resps_old; bp_gtm_change_user_group_role($change_roles, $project_id, $task_id); // todo smth with this: if (count($resps) > 0) { bp_gtm_save_g_resps($task_id, $_POST['task_project'], $_POST['task_group'], $resps); $task_resps = implode(' ', $resps); // make resps in a line to save in DB } else { $resps[] = bp_core_get_username($_POST['task_creator']); bp_gtm_save_g_resps($task_id, $_POST['task_project'], $_POST['task_group'], $resps); $task_resps = bp_core_get_username($_POST['task_creator']); } // update task $updated_task = $wpdb->query($wpdb->prepare("\n UPDATE " . $bp->gtm->table_tasks . "\n SET `name` = %s, `desc` = %s, `status` = %s, `resp_id` = %s, `project_id` = %d, `deadline` = %s\n WHERE `group_id` = %d AND `id` = %d\n ", $name, $description, $status, $task_resps, $_POST['task_project'], bp_gtm_covert_date($_POST['task_deadline']), $_POST['task_group'], $task_id)); // delete old tags $updated_tag = $wpdb->query($wpdb->prepare("DELETE FROM " . $bp->gtm->table_taxon . " WHERE `task_id` = %d AND `taxon` = 'tag'", $task_id)); // get rid of unnecessary chars in existed tags $this->bp_gtm_insert_term($_POST['task_tag_names'], '', $project_id, 'tag', $task_id); // update cats $updated_cat = $wpdb->query($wpdb->prepare("DELETE FROM " . $bp->gtm->table_taxon . " WHERE `task_id` = %d AND `taxon` = 'cat'", $task_id)); $this->bp_gtm_insert_term($_POST['task_old_cats'], $_POST['project_cats'], $project_id, 'cat', $task_id); // display user message if ($updated_task != null || $updated_cat != null || $updated_tag != null) { if (count($resps) > 0) { foreach ((array) $resps as $resp) { $resp_id = bp_core_get_userid($resp); bp_core_add_notification($task_id, $resp_id, 'gtm', 'task_edited', $_POST['task_group']); } } } do_action('bp_gtm_save_discussion_post', 'task', $_POST['task_creator'], false, $task_id, false, $bp->groups->current_group->id); bp_core_add_message(__('Task data was successfully updated.', 'bp_gtm')); do_action('bp_gtm_edit_task', $_POST['task_group']); bp_core_redirect(bp_get_group_permalink($bp->groups->current_group) . $bp->gtm->slug . '/tasks/view/' . $task_id . '?action=edited'); }
function bp_gtm_get_group_project_respossibles($project) { $users_logins = explode(' ', $project->resp_id); $arg['width'] = '25'; $arg['height'] = '25'; if (count($users_logins) > 1) { foreach ($users_logins as $users_login) { $arg['item_id'] = bp_core_get_userid($users_login); ?> <div class="poster-name"> <a href="<?php echo bp_core_get_userlink($arg['item_id'], false, true); ?> " title="<?php echo bp_core_get_userlink($arg['item_id'], true, false); ?> "> <?php echo bp_core_fetch_avatar($arg); ?> </a> </div> <?php } } else { $arg['item_id'] = bp_core_get_userid($users_logins['0']); ?> <div class="poster-name"><?php echo bp_core_fetch_avatar($arg); echo bp_core_get_userlink($arg['item_id']); ?> </div> <?php } }
/** * 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; }
function mention_replace($content) { include_once ABSPATH . WPINC . '/registration.php'; $pattern = '/[@]+([A-Za-z0-9-_\\.]+)/'; preg_match_all($pattern, $content, $usernames); // Make sure there's only one instance of each username if (!($usernames = array_unique($usernames[1]))) { return $content; } foreach ((array) $usernames as $username) { if (!($user_id = username_exists($username))) { continue; } $content = str_replace("@{$username}", "<a href='" . bp_core_get_user_domain(bp_core_get_userid($username)) . "' rel='nofollow'>@{$username}</a>", $content); } return $content; }
/** * Bootstrap bbPress 1.x, and manipulate globals to integrate with BuddyPress. * * @return bool|null Returns false on failure. */ function bp_forums_load_bbpress() { global $wpdb, $wp_roles, $current_user, $wp_users_object; global $bb, $bbdb, $bb_table_prefix, $bb_current_user; global $bb_roles, $wp_taxonomy_object, $bb_queries; // Return if we've already run this function. if (is_object($bbdb)) { return; } if (!bp_forums_is_installed_correctly()) { return false; } $bp = buddypress(); define('BB_PATH', $bp->plugin_dir . '/bp-forums/bbpress/'); define('BACKPRESS_PATH', $bp->plugin_dir . '/bp-forums/bbpress/bb-includes/backpress/'); define('BB_URL', $bp->plugin_url . 'bp-forums/bbpress/'); define('BB_INC', 'bb-includes/'); require BB_PATH . BB_INC . 'class.bb-query.php'; require BB_PATH . BB_INC . 'class.bb-walker.php'; require BB_PATH . BB_INC . 'functions.bb-core.php'; require BB_PATH . BB_INC . 'functions.bb-forums.php'; require BB_PATH . BB_INC . 'functions.bb-topics.php'; require BB_PATH . BB_INC . 'functions.bb-posts.php'; require BB_PATH . BB_INC . 'functions.bb-topic-tags.php'; require BB_PATH . BB_INC . 'functions.bb-capabilities.php'; require BB_PATH . BB_INC . 'functions.bb-meta.php'; require BB_PATH . BB_INC . 'functions.bb-pluggable.php'; require BB_PATH . BB_INC . 'functions.bb-formatting.php'; require BB_PATH . BB_INC . 'functions.bb-template.php'; require BACKPRESS_PATH . 'class.wp-taxonomy.php'; require BB_PATH . BB_INC . 'class.bb-taxonomy.php'; require BB_PATH . 'bb-admin/includes/functions.bb-admin.php'; $bb = new stdClass(); require bp_get_option('bb-config-location'); // Setup the global database connection $bbdb = new BPDB(BBDB_USER, BBDB_PASSWORD, BBDB_NAME, BBDB_HOST); // Set the table names $bbdb->forums = $bb_table_prefix . 'forums'; $bbdb->meta = $bb_table_prefix . 'meta'; $bbdb->posts = $bb_table_prefix . 'posts'; $bbdb->terms = $bb_table_prefix . 'terms'; $bbdb->term_relationships = $bb_table_prefix . 'term_relationships'; $bbdb->term_taxonomy = $bb_table_prefix . 'term_taxonomy'; $bbdb->topics = $bb_table_prefix . 'topics'; if (isset($bb->custom_user_table)) { $bbdb->users = $bb->custom_user_table; } else { $bbdb->users = $wpdb->users; } if (isset($bb->custom_user_meta_table)) { $bbdb->usermeta = $bb->custom_user_meta_table; } else { $bbdb->usermeta = $wpdb->usermeta; } $bbdb->prefix = $bb_table_prefix; define('BB_INSTALLING', false); if (is_object($wp_roles)) { $bb_roles = $wp_roles; bb_init_roles($bb_roles); } /** * Fires during the bootstrap setup for bbPress 1.x. * * @since 1.1.0 */ do_action('bb_got_roles'); /** * Fires during the bootstrap setup for bbPress 1.x. * * @since 1.1.0 */ do_action('bb_init'); /** * Fires during the bootstrap setup for bbPress 1.x. * * @since 1.1.0 */ do_action('init_roles'); $bb_current_user = $current_user; $wp_users_object = new BP_Forums_BB_Auth(); if (!isset($wp_taxonomy_object)) { $wp_taxonomy_object = new BB_Taxonomy($bbdb); } $wp_taxonomy_object->register_taxonomy('bb_topic_tag', 'bb_topic'); // Set a site id if there isn't one already if (!isset($bb->site_id)) { $bb->site_id = bp_get_root_blog_id(); } // Check if the tables are installed, if not, install them if (!($tables_installed = (bool) $bbdb->get_results('DESCRIBE `' . $bbdb->forums . '`;', ARRAY_A))) { require BB_PATH . 'bb-admin/includes/defaults.bb-schema.php'; // Backticks and "IF NOT EXISTS" break the dbDelta function. bp_bb_dbDelta(str_replace(' IF NOT EXISTS', '', str_replace('`', '', $bb_queries))); require BB_PATH . 'bb-admin/includes/functions.bb-upgrade.php'; bb_update_db_version(); // Set the site admins as the keymasters $site_admins = get_site_option('site_admins', array('admin')); foreach ((array) $site_admins as $site_admin) { bp_update_user_meta(bp_core_get_userid($site_admin), $bb_table_prefix . 'capabilities', array('keymaster' => true)); } // Create the first forum. bb_new_forum(array('forum_name' => 'Default Forum')); // Set the site URI bb_update_option('uri', BB_URL); } /** * Fires inside an anonymous function that is run on bbPress shutdown. * * @since 1.1.0 */ register_shutdown_function(create_function('', 'do_action("bb_shutdown");')); }
/** * Create a new message. * * @param array $args { * Array of arguments. * @type int $sender_id Optional. ID of the user who is sending the * message. Default: ID of the logged-in user. * @type int $thread_id Optional. ID of the parent thread. Leave blank to * create a new thread for the message. * @type array $recipients IDs or usernames of message recipients. If this * is an existing thread, it is unnecessary to pass a $recipients * argument - existing thread recipients will be assumed. * @type string $subject Optional. Subject line for the message. For * existing threads, the existing subject will be used. For new * threads, 'No Subject' will be used if no $subject is provided. * @type string $content Content of the message. Cannot be empty. * @type string $date_sent Date sent, in 'Y-m-d H:i:s' format. Default: * current date/time. * } * @return int|bool ID of the message thread on success, false on failure. */ function messages_new_message( $args = '' ) { // Parse the default arguments $r = bp_parse_args( $args, array( 'sender_id' => bp_loggedin_user_id(), 'thread_id' => false, // false for a new message, thread id for a reply to a thread. 'recipients' => array(), // Can be an array of usernames, user_ids or mixed. 'subject' => false, 'content' => false, 'date_sent' => bp_core_current_time() ), 'messages_new_message' ); // Bail if no sender or no content if ( empty( $r['sender_id'] ) || empty( $r['content'] ) ) { return false; } // Create a new message object $message = new BP_Messages_Message; $message->thread_id = $r['thread_id']; $message->sender_id = $r['sender_id']; $message->subject = $r['subject']; $message->message = $r['content']; $message->date_sent = $r['date_sent']; // If we have a thread ID... if ( ! empty( $r['thread_id'] ) ) { // ...use the existing recipients $thread = new BP_Messages_Thread( $r['thread_id'] ); $message->recipients = $thread->get_recipients(); // Strip the sender from the recipient list, and unset them if they are // not alone. If they are alone, let them talk to themselves. if ( isset( $message->recipients[ $r['sender_id'] ] ) && ( count( $message->recipients ) > 1 ) ) { unset( $message->recipients[ $r['sender_id'] ] ); } // Set a default reply subject if none was sent if ( empty( $message->subject ) ) { $message->subject = sprintf( __( 'Re: %s', 'buddypress' ), $thread->messages[0]->subject ); } // ...otherwise use the recipients passed } else { // Bail if no recipients if ( empty( $r['recipients'] ) ) { return false; } // Set a default subject if none exists if ( empty( $message->subject ) ) { $message->subject = __( 'No Subject', 'buddypress' ); } // Setup the recipients array $recipient_ids = array(); // Invalid recipients are added to an array, for future enhancements $invalid_recipients = array(); // Loop the recipients and convert all usernames to user_ids where needed foreach( (array) $r['recipients'] as $recipient ) { // Trim spaces and skip if empty $recipient = trim( $recipient ); if ( empty( $recipient ) ) { continue; } // Check user_login / nicename columns first // @see http://buddypress.trac.wordpress.org/ticket/5151 if ( bp_is_username_compatibility_mode() ) { $recipient_id = bp_core_get_userid( urldecode( $recipient ) ); } else { $recipient_id = bp_core_get_userid_from_nicename( $recipient ); } // Check against user ID column if no match and if passed recipient is numeric if ( empty( $recipient_id ) && is_numeric( $recipient ) ) { if ( bp_core_get_core_userdata( (int) $recipient ) ) { $recipient_id = (int) $recipient; } } // Decide which group to add this recipient to if ( empty( $recipient_id ) ) { $invalid_recipients[] = $recipient; } else { $recipient_ids[] = (int) $recipient_id; } } // Strip the sender from the recipient list, and unset them if they are // not alone. If they are alone, let them talk to themselves. $self_send = array_search( $r['sender_id'], $recipient_ids ); if ( ! empty( $self_send ) && ( count( $recipient_ids ) > 1 ) ) { unset( $recipient_ids[ $self_send ] ); } // Remove duplicates & bail if no recipients $recipient_ids = array_unique( $recipient_ids ); if ( empty( $recipient_ids ) ) { return false; } // Format this to match existing recipients foreach( (array) $recipient_ids as $i => $recipient_id ) { $message->recipients[$i] = new stdClass; $message->recipients[$i]->user_id = $recipient_id; } } // Bail if message failed to send if ( ! $message->send() ) { return false; } /** * Fires after a message has been successfully sent. * * @since BuddyPress (1.1.0) * * @param BP_Messages_Message $message Message object. Passed by reference. */ do_action_ref_array( 'messages_message_sent', array( &$message ) ); // Return the thread ID return $message->thread_id; }
function bp_core_signup_disable_inactive($auth_obj, $username) { global $bp, $wpdb; if (!($user_id = bp_core_get_userid($username))) { return $auth_obj; } $user_status = (int) $wpdb->get_var($wpdb->prepare("SELECT user_status FROM {$wpdb->users} WHERE ID = %d", $user_id)); if (2 == $user_status) { return new WP_Error('bp_account_not_activated', __('<strong>ERROR</strong>: Your account has not been activated. Check your email for the activation link.', 'buddypress')); } else { return $auth_obj; } }
function get_recipient_ids( $recipient_usernames ) { if ( !$recipient_usernames ) return false; if ( is_array( $recipient_usernames ) ) { for ( $i = 0; $i < count($recipient_usernames); $i++ ) { if ( $rid = bp_core_get_userid( trim($recipient_usernames[$i]) ) ) $recipient_ids[] = $rid; } } return $recipient_ids; }
/** * 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); }
function bp_core_signup_disable_inactive( $auth_obj, $username ) { global $bp, $wpdb; if ( !$user_id = bp_core_get_userid( $username ) ) return $auth_obj; $user_status = (int) $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM $wpdb->users WHERE ID = %d", $user_id ) ); if ( 2 == $user_status ) bp_core_redirect( $bp->root_domain ); else return $auth_obj; }
/** * Send an email and a BP notification on receipt of an @-mention in a group * * @deprecated 1.5 * @deprecated Deprecated in favor of the more general bp_activity_at_message_notification() */ function groups_at_message_notification($content, $poster_user_id, $group_id, $activity_id) { global $bp; _deprecated_function(__FUNCTION__, '1.5', 'bp_activity_at_message_notification()'); /* Scan for @username strings in an activity update. Notify each user. */ $pattern = '/[@]+([A-Za-z0-9-_\\.@]+)/'; preg_match_all($pattern, $content, $usernames); /* Make sure there's only one instance of each username */ if (!($usernames = array_unique($usernames[1]))) { return false; } $group = new BP_Groups_Group($group_id); foreach ((array) $usernames as $username) { if (!($receiver_user_id = bp_core_get_userid($username))) { continue; } /* Check the user is a member of the group before sending the update. */ if (!groups_is_user_member($receiver_user_id, $group_id)) { continue; } // Now email the user with the contents of the message (if they have enabled email notifications) if ('no' != bp_get_user_meta($receiver_user_id, 'notification_activity_new_mention', true)) { $poster_name = bp_core_get_user_displayname($poster_user_id); $message_link = bp_activity_get_permalink($activity_id); $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings'; $settings_link = bp_core_get_user_domain($receiver_user_id) . $settings_slug . '/notifications/'; $poster_name = stripslashes($poster_name); $content = bp_groups_filter_kses(stripslashes($content)); // Set up and send the message $ud = bp_core_get_core_userdata($receiver_user_id); $to = $ud->user_email; $sitename = nxt_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES); $subject = '[' . $sitename . '] ' . sprintf(__('%1$s mentioned you in the group "%2$s"', 'buddypress'), $poster_name, $group->name); $message = sprintf(__('%1$s mentioned you in the group "%2$s": "%3$s" To view and respond to the message, log in and visit: %4$s --------------------- ', 'buddypress'), $poster_name, $group->name, $content, $message_link); $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link); /* Send the message */ $to = apply_filters('groups_at_message_notification_to', $to); $subject = apply_filters('groups_at_message_notification_subject', $subject, $group, $poster_name); $message = apply_filters('groups_at_message_notification_message', $message, $group, $poster_name, $content, $message_link, $settings_link); nxt_mail($to, $subject, $message); } } do_action('bp_groups_sent_mention_email', $usernames, $subject, $message, $content, $poster_user_id, $group_id, $activity_id); }
function bp_gtm_done_item() { global $bp, $wpdb; if ($_GET['doneAction'] == 'done') { if ($_GET['doneType'] == 'projects') { $wpdb->query($wpdb->prepare("UPDATE " . $bp->gtm->table_projects . " SET `done` = '1' WHERE `id` = %d AND `group_id` = %d", $_GET['doneID'], $bp->groups->current_group->id)); $wpdb->query($wpdb->prepare("UPDATE " . $bp->gtm->table_tasks . " SET `done` = '1' WHERE `project_id` = %d AND `group_id` = %d", $_GET['doneID'], $bp->groups->current_group->id)); $project = BP_GTM_Projects::get_project_by_id($_GET['doneID']); $resps = explode(' ', $project['0']->resp_id); foreach ($resps as $resp) { if ($resp != '') { $resp_id = bp_core_get_userid($resp); if ($resp_id != $bp->loggedin_user->id) { bp_core_add_notification($_GET['doneID'], $resp_id, $bp->gtm->slug, 'project_done', $bp->groups->current_group->id); } } } } elseif ($_GET['doneType'] == 'tasks') { $wpdb->query($wpdb->prepare("UPDATE " . $bp->gtm->table_tasks . " SET `done` = '1' WHERE `id` = %d AND `group_id` = %d", $_GET['doneID'], $bp->groups->current_group->id)); $wpdb->query($wpdb->prepare("UPDATE " . $bp->gtm->table_tasks . " SET `done` = '1' WHERE `parent_id` = %d AND `group_id` = %d", $_GET['doneID'], $bp->groups->current_group->id)); $task = BP_GTM_Tasks::get_task_by_id($_GET['doneID']); $resps = explode(' ', $task['0']->resp_id); foreach ($resps as $resp) { if ($resp != '') { $resp_id = bp_core_get_userid($resp); if ($resp_id != $bp->loggedin_user->id) { bp_core_add_notification($_GET['doneID'], $resp_id, $bp->gtm->slug, 'task_done', $bp->groups->current_group->id); } } } } } elseif ($_GET['doneAction'] == 'undone') { if ($_GET['doneType'] == 'projects') { $wpdb->query($wpdb->prepare("UPDATE " . $bp->gtm->table_projects . " SET `done` = '0' WHERE `id` = %d AND `group_id` = %d", $_GET['doneID'], $bp->groups->current_group->id)); // $wpdb->query( $wpdb->prepare("UPDATE ".$bp->gtm->table_tasks." SET `done` = '0' WHERE `project_id` = %d AND `group_id` = %d", $_GET['doneID'], $bp->groups->current_group->id)); $project = BP_GTM_Projects::get_project_by_id($_GET['doneID']); $resps = explode(' ', $project['0']->resp_id); foreach ($resps as $resp) { if ($resp != '') { $resp_id = bp_core_get_userid($resp); if ($resp_id != $bp->loggedin_user->id) { bp_core_add_notification($_GET['doneID'], $resp_id, $bp->gtm->slug, 'project_undone', $bp->groups->current_group->id); } } } } elseif ($_GET['doneType'] == 'tasks') { $wpdb->query($wpdb->prepare("UPDATE " . $bp->gtm->table_tasks . " SET `done` = '0' WHERE `id` = %d AND `group_id` = %d", $_GET['doneID'], $bp->groups->current_group->id)); $task = BP_GTM_Tasks::get_task_by_id($_GET['doneID']); $resps = explode(' ', $task['0']->resp_id); foreach ($resps as $resp) { if ($resp != '') { $resp_id = bp_core_get_userid($resp); if ($resp_id != $bp->loggedin_user->id) { bp_core_add_notification($_GET['doneID'], $resp_id, $bp->gtm->slug, 'task_undone', $bp->groups->current_group->id); } } } } } return true; }
function get_recipient_ids($recipient_usernames) { if (!$recipient_usernames) { return false; } if (is_array($recipient_usernames)) { for ($i = 0, $count = count($recipient_usernames); $i < $count; ++$i) { if ($rid = bp_core_get_userid(trim($recipient_usernames[$i]))) { $recipient_ids[] = $rid; } } } return $recipient_ids; }
function bp_message_get_recipient_tabs() { global $bp; if ( isset( $_GET['r'] ) ) { $user_id = bp_core_get_userid( $_GET['r'] ); if ( $user_id ) { ?> <li id="un-<?php echo $_GET['r'] ?>" class="friend-tab"> <span> <?php echo bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'width' => 15, 'height' => 15 ) ) ?> <?php echo bp_core_get_userlink( $user_id ) ?> </span> </li> <?php } } }
function messages_new_message( $args = '' ) { global $bp; $defaults = array( 'thread_id' => false, // false for a new message, thread id for a reply to a thread. 'sender_id' => $bp->loggedin_user->id, 'recipients' => false, // Can be an array of usernames, user_ids or mixed. 'subject' => false, 'content' => false, 'date_sent' => bp_core_current_time() ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); if ( !$sender_id || !$content ) return false; /* Create a new message object */ $message = new BP_Messages_Message; $message->thread_id = $thread_id; $message->sender_id = $sender_id; $message->subject = $subject; $message->message = $content; $message->date_sent = $date_sent; // If we have a thread ID, use the existing recipients, otherwise use the recipients passed if ( $thread_id ) { $thread = new BP_Messages_Thread( $thread_id ); $message->recipients = $thread->get_recipients(); // Strip the sender from the recipient list if they exist if ( isset( $message->recipients[$sender_id] ) ) unset( $message->recipients[$sender_id] ); if ( empty( $message->subject ) ) $message->subject = sprintf( __( 'Re: %s', 'buddypress' ), $thread->messages[0]->subject ); // No thread ID, so make some adjustments } else { if ( empty( $recipients ) ) return false; if ( empty( $message->subject ) ) $message->subject = __( 'No Subject', 'buddypress' ); /* Loop the recipients and convert all usernames to user_ids where needed */ foreach( (array) $recipients as $recipient ) { if ( is_numeric( trim( $recipient ) ) ) $recipient_ids[] = (int)trim( $recipient ); if ( $recipient_id = bp_core_get_userid( trim( $recipient ) ) ) $recipient_ids[] = (int)$recipient_id; } /* Strip the sender from the recipient list if they exist */ if ( $key = array_search( $sender_id, (array)$recipient_ids ) ) unset( $recipient_ids[$key] ); /* Remove duplicates */ $recipient_ids = array_unique( (array)$recipient_ids ); if ( empty( $recipient_ids ) ) return false; /* Format this to match existing recipients */ foreach( (array)$recipient_ids as $i => $recipient_id ) { $message->recipients[$i] = new stdClass; $message->recipients[$i]->user_id = $recipient_id; } } if ( $message->send() ) { require_once( BP_PLUGIN_DIR . '/bp-messages/bp-messages-notifications.php' ); // Send screen notifications to the recipients foreach ( (array)$message->recipients as $recipient ) bp_core_add_notification( $message->id, $recipient->user_id, 'messages', 'new_message' ); // Send email notifications to the recipients messages_notification_new_message( array( 'message_id' => $message->id, 'sender_id' => $message->sender_id, 'subject' => $message->subject, 'content' => $message->message, 'recipients' => $message->recipients, 'thread_id' => $message->thread_id) ); do_action( 'messages_message_sent', &$message ); return $message->thread_id; } return false; }
/** * bp_core_set_uri_globals() * * 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. * * 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 'profile' * - $bp->current_action: string 'edit' * - $bp->action_variables: array ['group', 5] * * @package BuddyPress Core */ function bp_core_set_uri_globals() { global $current_component, $current_action, $action_variables; global $displayed_user_id; global $is_member_page; global $bp_unfiltered_uri; global $bp, $current_blog; // Only catch URI's on the root blog if we are not running BP on multiple blogs if (!defined('BP_ENABLE_MULTIBLOG') && bp_core_is_multisite()) { if (BP_ROOT_BLOG != (int) $current_blog->blog_id) { return false; } } // Ajax or not? if (strpos($_SERVER['REQUEST_URI'], 'wp-load.php')) { $path = bp_core_referrer(); } else { $path = esc_url($_SERVER['REQUEST_URI']); } $path = apply_filters('bp_uri', $path); // Take GET variables off the URL to avoid problems, // they are still registered in the global $_GET variable $noget = substr($path, 0, strpos($path, '?')); if ($noget != '') { $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 (defined('BP_ENABLE_MULTIBLOG') || 1 != BP_ROOT_BLOG) { // Any subdirectory names must be removed from $bp_uri. // This includes two cases: (1) when WP 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; // If this is a WordPress page, return from the function. if (is_page($bp_uri[$component_index])) { return false; } // 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); } 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); $bp_unfiltered_uri = $bp_uri; // If we are under anything with a members slug, set the correct globals if ($bp_uri[0] == BP_MEMBERS_SLUG) { $is_member_page = true; $is_root_component = true; } // Catch a member page and set the current member ID if (!defined('BP_ENABLE_ROOT_PROFILES')) { if ($bp_uri[0] == BP_MEMBERS_SLUG && !empty($bp_uri[1]) || in_array('wp-load.php', $bp_uri)) { // We are within a member page, set up user id globals if (defined('BP_ENABLE_USERNAME_COMPATIBILITY_MODE')) { $displayed_user_id = bp_core_get_userid(urldecode($bp_uri[1])); } else { $displayed_user_id = bp_core_get_userid_from_nicename(urldecode($bp_uri[1])); } unset($bp_uri[0]); unset($bp_uri[1]); // Reset the keys by merging with an empty array $bp_uri = array_merge(array(), $bp_uri); } } else { if (get_userdatabylogin($bp_uri[0]) || in_array('wp-load.php', $bp_uri)) { $is_member_page = true; $is_root_component = true; // We are within a member page, set up user id globals if (defined('BP_ENABLE_USERNAME_COMPATIBILITY_MODE')) { $displayed_user_id = bp_core_get_userid(urldecode($bp_uri[0])); } else { $displayed_user_id = bp_core_get_userid_from_nicename(urldecode($bp_uri[0])); } unset($bp_uri[0]); // Reset the keys by merging with an empty array $bp_uri = array_merge(array(), $bp_uri); } } if (!isset($is_root_component)) { $is_root_component = in_array($bp_uri[0], $bp->root_components); } if (!is_subdomain_install() && !$is_root_component) { $component_index++; $action_index++; } // Set the current component $current_component = $bp_uri[$component_index]; // Set the current action $current_action = $bp_uri[$action_index]; // Set the entire URI as the action variables, we will unset the current_component and action in a second $action_variables = $bp_uri; // Unset the current_component and action from action_variables unset($action_variables[$component_index]); unset($action_variables[$action_index]); // Remove the username from action variables if this is not a VHOST install if (!is_subdomain_install() && !$is_root_component) { array_shift($action_variables); } // Reset the keys by merging with an empty array $action_variables = array_merge(array(), $action_variables); }