当前位置: 首页>>代码示例>>PHP>>正文


PHP bp_is_username_compatibility_mode函数代码示例

本文整理汇总了PHP中bp_is_username_compatibility_mode函数的典型用法代码示例。如果您正苦于以下问题:PHP bp_is_username_compatibility_mode函数的具体用法?PHP bp_is_username_compatibility_mode怎么用?PHP bp_is_username_compatibility_mode使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了bp_is_username_compatibility_mode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: bp_activity_find_mentions

/**
 * Searches through the content of an activity item to locate usernames,
 * designated by an @ sign.
 *
 * @since BuddyPress (1.5)
 *
 * @param string $content The content of the activity, usually found in $activity->content.
 * @return mixed Associative array with user ID as key and username as value. Boolean false if no mentions found.
 */
function bp_activity_find_mentions($content)
{
    $pattern = '/[@]+([A-Za-z0-9-_\\.@]+)\\b/';
    preg_match_all($pattern, $content, $usernames);
    // Make sure there's only one instance of each username
    if (!($usernames = array_unique($usernames[1]))) {
        return false;
    }
    $mentioned_users = array();
    // We've found some mentions! Check to see if users exist
    foreach ((array) $usernames as $key => $username) {
        if (bp_is_username_compatibility_mode()) {
            $user_id = username_exists($username);
        } else {
            $user_id = bp_core_get_userid_from_nicename($username);
        }
        // user ID exists, so let's add it to our array
        if (!empty($user_id)) {
            $mentioned_users[$user_id] = $username;
        }
    }
    if (empty($mentioned_users)) {
        return false;
    }
    return $mentioned_users;
}
开发者ID:novichkovv,项目名称:candoweightloss,代码行数:35,代码来源:bp-activity-functions.php

示例2: bp_activity_adjust_mention_count

/**
 * Adjusts new mention count for mentioned users when activity items are deleted or created
 *
 * @since 1.5.0
 *
 * @param int $activity_id The unique id for the activity item
 * @param string $action Can be 'delete' or 'add'. Defaults to 'add'
 *
 * @uses BP_Activity_Activity() {@link BP_Activity_Activity}
 * @uses bp_activity_find_mentions()
 * @uses bp_is_username_compatibility_mode()
 * @uses bp_core_get_userid_from_nicename()
 * @uses bp_get_user_meta()
 * @uses bp_update_user_meta()
 */
function bp_activity_adjust_mention_count($activity_id, $action = 'add')
{
    $activity = new BP_Activity_Activity($activity_id);
    if ($usernames = bp_activity_find_mentions(strip_tags($activity->content))) {
        foreach ((array) $usernames as $username) {
            if (bp_is_username_compatibility_mode()) {
                $user_id = username_exists($username);
            } else {
                $user_id = bp_core_get_userid_from_nicename($username);
            }
            if (empty($user_id)) {
                continue;
            }
            // Adjust the mention list and count for the member
            $new_mention_count = (int) bp_get_user_meta($user_id, 'bp_new_mention_count', true);
            if (!($new_mentions = bp_get_user_meta($user_id, 'bp_new_mentions', true))) {
                $new_mentions = array();
            }
            switch ($action) {
                case 'delete':
                    $key = array_search($activity_id, $new_mentions);
                    if ($key !== false) {
                        unset($new_mentions[$key]);
                    }
                    break;
                case 'add':
                default:
                    if (!in_array($activity_id, $new_mentions)) {
                        $new_mentions[] = (int) $activity_id;
                    }
                    break;
            }
            // Get an updated mention count
            $new_mention_count = count($new_mentions);
            // Resave the user_meta
            bp_update_user_meta($user_id, 'bp_new_mention_count', $new_mention_count);
            bp_update_user_meta($user_id, 'bp_new_mentions', $new_mentions);
        }
    }
}
开发者ID:nxtclass,项目名称:NXTClass,代码行数:55,代码来源:bp-activity-functions.php

示例3: bp_activity_at_name_filter

/**
 * Finds and links @-mentioned users in the contents of activity items
 *
 * @since 1.2.0
 *
 * @param string $content The activity content
 * @param int $activity_id The activity id
 *
 * @uses bp_activity_find_mentions()
 * @uses bp_is_username_compatibility_mode()
 * @uses bp_core_get_userid_from_nicename()
 * @uses bp_activity_at_message_notification()
 * @uses bp_core_get_user_domain()
 * @uses bp_activity_adjust_mention_count()
 *
 * @return string $content Content filtered for mentions
 */
function bp_activity_at_name_filter($content, $activity_id = 0)
{
    if ($activity_id & bp_is_active('activity')) {
        $activity = new BP_Activity_Activity($activity_id);
        // If this activity has been marked as spam, don't do anything. This prevents @notifications being sent.
        if (!empty($activity) && $activity->is_spam) {
            return $content;
        }
    }
    $usernames = bp_activity_find_mentions($content);
    foreach ((array) $usernames as $username) {
        if (bp_is_username_compatibility_mode()) {
            $user_id = username_exists($username);
        } else {
            $user_id = bp_core_get_userid_from_nicename($username);
        }
        if (empty($user_id)) {
            continue;
        }
        // If an activity_id is provided, we can send email and BP notifications
        if ($activity_id) {
            bp_activity_at_message_notification($activity_id, $user_id);
        }
        $content = preg_replace('/(@' . $username . '\\b)/', "<a href='" . bp_core_get_user_domain($user_id) . "' rel='nofollow'>@{$username}</a>", $content);
    }
    // Adjust the activity count for this item
    if ($activity_id) {
        bp_activity_adjust_mention_count($activity_id, 'add');
    }
    return $content;
}
开发者ID:newington,项目名称:buddypress,代码行数:48,代码来源:bp-activity-filters.php

示例4: messages_new_message

/**
 * 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;
                }
//.........这里部分代码省略.........
开发者ID:CompositeUK,项目名称:clone.BuddyPress,代码行数:101,代码来源:bp-messages-functions.php

示例5: sp_build_profile_formlink

function sp_build_profile_formlink($userid)
{
    global $spThisUser;
    $sfprofile = sp_get_option('sfprofile');
    $mode = $sfprofile['formmode'];
    # if profile mode is BP or Mingle but they are not active, switch back to popup profile
    include_once ABSPATH . 'wp-admin/includes/plugin.php';
    if ($mode == 3 && !is_plugin_active('buddypress/bp-loader.php') || $mode == 5 && !is_plugin_active('mingle/mingle.php')) {
        $mode = 1;
    }
    switch ($mode) {
        case 1:
            # SPF form
            $edit = '';
            if ($userid != $spThisUser->ID) {
                $user = new WP_User($userid);
                $edit = $user->ID . '/edit';
            }
            $site = sp_url('profile/' . $edit);
            return $site;
        case 2:
            # WordPress form
            return SFHOMEURL . 'wp-admin/user-edit.php?user_id=' . $userid;
        case 3:
            # BuddyPress profile page
            $user = new WP_User($userid);
            # try to handle BP switches between username and login ussge
            $username = bp_is_username_compatibility_mode() ? $user->user_login : $user->user_nicename;
            if (strstr($username, ' ')) {
                $username = $user->user_nicename;
            } else {
                $username = urlencode($username);
            }
            # build BP user profile based on bp options
            $bp = get_option('bp-pages');
            $baseurl = get_permalink($bp['members']);
            $site = user_trailingslashit($baseurl . str_replace(' ', '', $username) . '/profile');
            $site = apply_filters('sph_buddypress_profile', $site, $user);
            return $site;
        case 4:
            # Handoff to user specified form
            if ($sfprofile['formpage']) {
                $out = $sfprofile['formpage'];
                if ($sfprofile['formquery']) {
                    $out .= '?' . sp_filter_title_display($sfprofile['formquery']) . '=' . $userid;
                }
            } else {
                $out = '';
            }
            return $out;
        case 5:
            # Mingle account page
            $user = new WP_User($userid);
            $site = SFSITEURL . user_trailingslashit('account');
            $site = apply_filters('sph_mingle_profile', $site, $user);
            return $site;
    }
}
开发者ID:ashanrupasinghe,项目名称:govforuminstalledlocal,代码行数:58,代码来源:sp-api-common-display.php

示例6: bp_core_get_userlink_by_username

/**
 * Return the user link for the user based on the supplied identifier.
 *
 * @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);
    }
    return apply_filters('bp_core_get_userlink_by_username', bp_core_get_userlink($user_id, false, false, true));
}
开发者ID:eresyyl,项目名称:mk,代码行数:16,代码来源:bp-members-functions.php

示例7: ray_get_the_author_display_name

/**
 * Used in the bbPress plugin
 *
 * @since 0.6
 */
function ray_get_the_author_display_name($name, $user_id)
{
    // test to see if we're on a BP group forum page or on any bbPress page
    if (bp_is_group_forum() || function_exists('bbpress') && is_bbpress()) {
        // cache username queries with static variable
        //
        // tried stuffing in $bp global but didn't work properly
        // probably due to object buffering in bbP
        static $bp_uso_data = array();
        $name = false;
        // try to get locally-cached value first
        if (!empty($bp_uso_data[$user_id])) {
            $name = $bp_uso_data[$user_id];
        }
        // no cached value, so query for it
        if ($name === false) {
            $field = bp_is_username_compatibility_mode() ? 'user_login' : 'user_nicename';
            $name = get_the_author_meta($field, $user_id);
            // cache it for later use in the loop
            $bp_uso_data[$user_id] = $name;
        }
    }
    return $name;
}
开发者ID:r-a-y,项目名称:buddypress-usernames-only,代码行数:29,代码来源:bp-usernames-only.php

示例8: bp_groups_admin_autocomplete_handler

/**
 * AJAX handler for group member autocomplete requests.
 *
 * @since BuddyPress (1.7.0)
 */
function bp_groups_admin_autocomplete_handler()
{
    // Bail if user user shouldn't be here, or is a large network
    if (!current_user_can('bp_moderate') || is_multisite() && wp_is_large_network('users')) {
        wp_die(-1);
    }
    $return = array();
    // Exclude current group members
    $group_id = isset($_GET['group_id']) ? wp_parse_id_list($_GET['group_id']) : array();
    $group_member_query = new BP_Group_Member_Query(array('group_id' => $group_id, 'per_page' => 0, 'group_role' => array('member', 'mod', 'admin'), 'populate_extras' => false, 'count_total' => false));
    $group_members = !empty($group_member_query->results) ? wp_list_pluck($group_member_query->results, 'ID') : array();
    $terms = isset($_GET['term']) ? $_GET['term'] : '';
    $users = bp_core_get_users(array('type' => 'alphabetical', 'search_terms' => $terms, 'exclude' => $group_members, 'per_page' => 10, 'populate_extras' => false));
    foreach ((array) $users['users'] as $user) {
        $return[] = array('label' => sprintf(__('%1$s (%2$s)', 'buddypress'), bp_is_username_compatibility_mode() ? $user->user_login : $user->user_nicename, $user->user_email), 'value' => $user->user_nicename);
    }
    wp_die(json_encode($return));
}
开发者ID:danielcoats,项目名称:schoolpress,代码行数:23,代码来源:bp-groups-admin.php

示例9: sp_build_profile_formlink

function sp_build_profile_formlink($userid)
{
    global $spThisUser;
    $sfprofile = sp_get_option('sfprofile');
    switch ($sfprofile['formmode']) {
        case 1:
            # SPF form
            $edit = '';
            if ($userid != $spThisUser->ID) {
                $user = new WP_User($userid);
                $edit = $user->ID . '/edit';
            }
            $site = sp_url('profile/' . $edit);
            return $site;
        case 2:
            # WordPress form
            return SFHOMEURL . 'wp-admin/user-edit.php?user_id=' . $userid;
        case 3:
            # BuddyPress profile page
            $user = new WP_User($userid);
            # try to handle BP switches between username and login ussge
            $username = bp_is_username_compatibility_mode() ? $user->user_login : $user->user_nicename;
            if (strstr($username, ' ')) {
                $username = $user->user_nicename;
            } else {
                $username = urlencode($username);
            }
            $site = SFSITEURL . 'members/' . str_replace(' ', '', $username) . '/profile/edit/';
            $site = apply_filters('sph_buddypress_profile', $site, $user);
            return $site;
        case 4:
            # Handoff to user specified form
            if ($sfprofile['formpage']) {
                $out = $sfprofile['formpage'];
                if ($sfprofile['formquery']) {
                    $out .= '?' . sp_filter_title_display($sfprofile['formquery']) . '=' . $userid;
                }
            } else {
                $out = '';
            }
            return $out;
        case 5:
            # Mingle account page
            $user = new WP_User($userid);
            $site = SFSITEURL . user_trailingslashit('account');
            $site = apply_filters('sph_mingle_profile', $site, $user);
            return $site;
    }
}
开发者ID:brooklyntri,项目名称:btc-plugins,代码行数:49,代码来源:sp-api-common-display.php

示例10: mention_autosuggest

 /**
  * AJAX receiver for the @mention autosuggest jQuery library. Performs a search on the string provided and returns matches.
  *
  * @global object $bp BuddyPress global settings
  * @return mixed Either HTML or JSON. If error, "-1" for missing parameters, "0" for no matches.
  * @see bp-labs/beakers/js/jquery.mentions.dev.js
  * @since 1.0
  */
 public function mention_autosuggest()
 {
     global $bp;
     if (empty($_POST['limit']) || empty($_POST['search'])) {
         exit('-1');
     }
     // Sanitise input
     $search_query = implode('', (array) preg_replace(array('|^https?://|i', '|\\*|', '|@|'), '', $_POST['search']));
     if (empty($search_query)) {
         exit('-1');
     }
     $args = array('count_total' => false, 'number' => (int) $_POST['limit'], 'search' => "{$search_query}*");
     if (!empty($bp->loggedin_user->id)) {
         $args['exclude'] = array($bp->loggedin_user->id);
     }
     if (bp_is_username_compatibility_mode()) {
         $args['fields'] = array('ID', 'user_login');
         $args['orderby'] = 'login';
     } else {
         $args['fields'] = array('ID', 'user_nicename');
         $args['orderby'] = 'nicename';
     }
     $args = apply_filters('bpl_mention_autosuggest_args', $args);
     // Search users
     $user_search_results = get_users($args);
     if (empty($user_search_results)) {
         // Return JSON
         if (!empty($_POST['format']) && 'json' == $_POST['format']) {
             exit(json_encode(false));
             // Return HTML
         } else {
             printf('<li class="section error"><p><span>%s</span> %s</p></li>', _x('No matches found.', 'no search results', 'bpl'), _x('Please check your spelling.', 'no search results', 'bpl'));
             exit;
         }
     }
     // If logged in, get user's friends
     $friend_ids = array();
     if (!empty($bp->loggedin_user->id) && bp_is_active('friends')) {
         $friend_ids = friends_get_friend_user_ids($bp->loggedin_user->id);
     }
     $search_results = array('friends' => array(), 'others' => array());
     // Build results
     foreach ((array) $user_search_results as $user) {
         $result = new stdClass();
         $result->avatar = bp_core_fetch_avatar(array('item_id' => $user->ID, 'width' => 30, 'height' => 30, 'type' => 'thumb', 'alt' => __('Profile picture of %s', 'bpl')));
         $result->name = bp_core_get_user_displayname($user->ID);
         if (bp_is_username_compatibility_mode()) {
             $result->id = $user->user_login;
         } else {
             $result->id = $user->user_nicename;
         }
         if (in_array($user->ID, (array) $friend_ids)) {
             $search_results['friends'][] = $result;
         } else {
             $search_results['others'][] = $result;
         }
     }
     apply_filters_ref_array('bpl_mention_autosuggest', array(&$search_results, $args));
     // Return JSON
     if (!empty($_POST['format']) && 'json' == $_POST['format']) {
         exit(json_encode($search_results));
         // Return HTML
     } else {
         $html = array();
         foreach ($search_results as $section => $items) {
             if (empty($items)) {
                 continue;
             }
             // Friends and other users
             if ('friends' == $section || 'others' == $section) {
                 if ('friends' == $section) {
                     $html[] = sprintf('<li class="section friends"><p>%s</p></li>', __('Your friends', 'bpl'));
                 } elseif ('others' == $section) {
                     if (!empty($search_results['friends'])) {
                         $html[] = sprintf('<li class="section other"><p>%s</p></li>', sprintf(__('Other people on %s', 'bpl'), get_bloginfo('name', 'display')));
                     } else {
                         $html[] = sprintf('<li class="section other"><p>%s</p></li>', sprintf(__('People on %s', 'bpl'), get_bloginfo('name', 'display')));
                     }
                 }
                 foreach ($items as $item) {
                     $html[] = sprintf('<li class=%s><p>%s</p></li>', esc_attr($item->id), $item->avatar . esc_html($item->name));
                 }
                 // For third-party extensions
             } else {
                 $custom_section = apply_filters('bpl_mention_autosuggest_custom_section', false, $section, $items);
                 if (!empty($custom_section)) {
                     $html = array_merge($html, (array) $custom_section);
                 }
             }
         }
         // Safety net
         if (empty($html)) {
//.........这里部分代码省略.........
开发者ID:rmccue,项目名称:BP-Labs,代码行数:101,代码来源:class-bplabs-autosuggest.php

示例11: messages_new_message

/**
 * 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 );
			}

//.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:101,代码来源:bp-messages-functions.php

示例12: messages_new_message

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;
}
开发者ID:pyropictures,项目名称:wordpress-plugins,代码行数:96,代码来源:bp-messages-functions.php

示例13: bp_activity_at_name_filter

/**
 * Finds and links @-mentioned users in the contents of activity items
 *
 * @since 1.2.0
 *
 * @param string $content The activity content
 * @param int $activity_id The activity id
 *
 * @uses bp_activity_find_mentions()
 * @uses bp_is_username_compatibility_mode()
 * @uses bp_core_get_userid_from_nicename()
 * @uses bp_activity_at_message_notification()
 * @uses bp_core_get_user_domain()
 * @uses bp_activity_adjust_mention_count()
 *
 * @return string $content Content filtered for mentions
 */
function bp_activity_at_name_filter($content, $activity_id = 0)
{
    $usernames = bp_activity_find_mentions($content);
    foreach ((array) $usernames as $username) {
        if (bp_is_username_compatibility_mode()) {
            $user_id = username_exists($username);
        } else {
            $user_id = bp_core_get_userid_from_nicename($username);
        }
        if (empty($user_id)) {
            continue;
        }
        // If an activity_id is provided, we can send email and BP notifications
        if ($activity_id) {
            bp_activity_at_message_notification($activity_id, $user_id);
        }
        $content = preg_replace('/(@' . $username . '\\b)/', "<a href='" . bp_core_get_user_domain($user_id) . "' rel='nofollow'>@{$username}</a>", $content);
    }
    // Adjust the activity count for this item
    if ($activity_id) {
        bp_activity_adjust_mention_count($activity_id, 'add');
    }
    return $content;
}
开发者ID:nxtclass,项目名称:NXTClass,代码行数:41,代码来源:bp-activity-filters.php

示例14: bp_dtheme_ajax_messages_autocomplete_results

/**
 * bp_dtheme_ajax_messages_autocomplete_results()
 *
 * AJAX handler for autocomplete. Displays friends only, unless BP_MESSAGES_AUTOCOMPLETE_ALL is defined
 *
 * @global object object $bp Global BuddyPress settings object
 * @return none
 */
function bp_dtheme_ajax_messages_autocomplete_results()
{
    global $bp;
    // Include everyone in the autocomplete, or just friends?
    if ($bp->messages->slug == $bp->current_component) {
        $autocomplete_all = $bp->messages->autocomplete_all;
    }
    $friends = false;
    $pag_page = 1;
    $limit = $_GET['limit'] ? $_GET['limit'] : apply_filters('bp_autocomplete_max_results', 10);
    // Get the user ids based on the search terms
    if (!empty($autocomplete_all)) {
        $users = BP_Core_User::search_users($_GET['q'], $limit, $pag_page);
        if (!empty($users['users'])) {
            // Build an array with the correct format
            $user_ids = array();
            foreach ($users['users'] as $user) {
                if ($user->id != $bp->loggedin_user->id) {
                    $user_ids[] = $user->id;
                }
            }
            $user_ids = apply_filters('bp_core_autocomplete_ids', $user_ids, $_GET['q'], $limit);
        }
    } else {
        if (bp_is_active('friends')) {
            $users = friends_search_friends($_GET['q'], $bp->loggedin_user->id, $limit, 1);
            // Keeping the bp_friends_autocomplete_list filter for backward compatibility
            $users = apply_filters('bp_friends_autocomplete_list', $users, $_GET['q'], $limit);
            if (!empty($users['friends'])) {
                $user_ids = apply_filters('bp_friends_autocomplete_ids', $users['friends'], $_GET['q'], $limit);
            }
        }
    }
    if (!empty($user_ids)) {
        foreach ($user_ids as $user_id) {
            $ud = get_userdata($user_id);
            if (!$ud) {
                continue;
            }
            if (bp_is_username_compatibility_mode()) {
                $username = $ud->user_login;
            } else {
                $username = $ud->user_nicename;
            }
            echo '<span id="link-' . $username . '" href="' . bp_core_get_user_domain($user_id) . '"></span>' . bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'width' => 15, 'height' => 15)) . ' &nbsp;' . bp_core_get_user_displayname($user_id) . ' (' . $username . ')
			';
        }
    }
}
开发者ID:hscale,项目名称:webento,代码行数:57,代码来源:ajax.php

示例15: bp_core_get_userlink_by_username

/**
 * 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));
}
开发者ID:CompositeUK,项目名称:clone.BuddyPress,代码行数:26,代码来源:bp-members-functions.php


注:本文中的bp_is_username_compatibility_mode函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。