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


PHP bp_activity_find_mentions函数代码示例

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


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

示例1: 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

示例2: extract_mentions

 /**
  * Extract @mentions tags from text.
  *
  * If the Activity component is enabled, it is used to parse @mentions.
  * The mentioned "name" must match a user account, otherwise it is discarded.
  *
  * If the Activity component is disabled, any @mentions are extracted.
  *
  * @since 2.3.0
  *
  * @param string $richtext   Content to parse.
  * @param string $plaintext  Sanitized version of the content.
  * @param array  $extra_args Bespoke data for a particular extractor.
  *
  * @return array {
  *     @type array $has Extracted media counts. {
  *         @type int $mentions
  *     }
  *     @type array $mentions Extracted mentions. {
  *         Array of extracted media.
  *
  *         @type string $name    @mention.
  *         @type string $user_id User ID. Optional, only set if Activity component enabled.
  *     }
  * }
  */
 protected function extract_mentions($richtext, $plaintext, $extra_args = array())
 {
     $data = array('has' => array('mentions' => 0), 'mentions' => array());
     $mentions = array();
     // If the Activity component is active, use it to parse @mentions.
     if (bp_is_active('activity')) {
         $mentions = bp_activity_find_mentions($plaintext);
         if (!$mentions) {
             $mentions = array();
         }
         // If the Activity component is disabled, instead do a basic parse.
     } else {
         if (strpos($plaintext, '@') !== false) {
             preg_match_all('/[@]+([A-Za-z0-9-_\\.@]+)\\b/', $plaintext, $matches);
             if (!empty($matches[1])) {
                 $mentions = array_unique(array_map('strtolower', $matches[1]));
             }
         }
     }
     // Build results
     foreach ($mentions as $user_id => $mention_name) {
         $mention = array('name' => strtolower($mention_name));
         // If the Activity component is active, store the User ID, too.
         if (bp_is_active('activity')) {
             $mention['user_id'] = (int) $user_id;
         }
         $data['mentions'][] = $mention;
     }
     $data['has']['mentions'] = count($data['mentions']);
     /**
      * Filters @mentions extracted from text.
      *
      * @since 2.3.0
      *
      * @param array  $data       Extracted @mentions. See {@link BP_Media_Extractor::extract_mentions()} for format.
      * @param string $richtext   Content to parse.
      * @param string $plaintext  Copy of $richtext without any markup.
      * @param array  $extra_args Bespoke data for a particular extractor (optional).
      */
     return apply_filters('bp_media_extractor_mentions', $data, $richtext, $plaintext, $extra_args);
 }
开发者ID:mawilliamson,项目名称:wordpress,代码行数:67,代码来源:class-bp-media-extractor.php

示例3: bp_activity_adjust_mention_count

/**
 * Adjusts mention count for mentioned users in activity items.
 *
 * This function is useful if you only have the activity ID handy and you
 * haven't parsed an activity item for @mentions yet.
 *
 * Currently, only used in {@link bp_activity_delete()}.
 *
 * @since BuddyPress (1.5.0)
 *
 * @uses bp_activity_find_mentions()
 * @uses bp_activity_update_mention_count_for_user()
 *
 * @param int $activity_id The unique id for the activity item.
 * @param string $action Can be 'delete' or 'add'. Defaults to 'add'.
 */
function bp_activity_adjust_mention_count($activity_id = 0, $action = 'add')
{
    // Bail if no activity ID passed
    if (empty($activity_id)) {
        return false;
    }
    // Get activity object
    $activity = new BP_Activity_Activity((int) $activity_id);
    // Try to find mentions
    $usernames = bp_activity_find_mentions(strip_tags($activity->content));
    // Still empty? Stop now
    if (empty($usernames)) {
        return false;
    }
    // Increment mention count foreach mentioned user
    foreach ((array) array_keys($usernames) as $user_id) {
        bp_activity_update_mention_count_for_user($user_id, $activity_id, $action);
    }
}
开发者ID:eresyyl,项目名称:mk,代码行数:35,代码来源:bp-activity-functions.php

示例4: bp_activity_at_name_filter_updates

/**
 * Catch mentions in an activity item before it is saved into the database.
 *
 * If mentions are found, replace @mention text with user links and add our
 * hook to send mention notifications after the activity item is saved.
 *
 * @since 1.5.0
 *
 * @uses bp_activity_find_mentions()
 *
 * @param BP_Activity_Activity $activity Activity Object.
 */
function bp_activity_at_name_filter_updates($activity)
{
    // Are mentions disabled?
    if (!bp_activity_do_mentions()) {
        return;
    }
    // If activity was marked as spam, stop the rest of this function.
    if (!empty($activity->is_spam)) {
        return;
    }
    // Try to find mentions.
    $usernames = bp_activity_find_mentions($activity->content);
    // We have mentions!
    if (!empty($usernames)) {
        // Replace @mention text with userlinks.
        foreach ((array) $usernames as $user_id => $username) {
            $activity->content = preg_replace('/(@' . $username . '\\b)/', "<a href='" . bp_core_get_user_domain($user_id) . "' rel='nofollow'>@{$username}</a>", $activity->content);
        }
        // Add our hook to send @mention emails after the activity item is saved.
        add_action('bp_activity_after_save', 'bp_activity_at_name_send_emails');
        // Temporary variable to avoid having to run bp_activity_find_mentions() again.
        buddypress()->activity->mentioned_users = $usernames;
    }
}
开发者ID:mawilliamson,项目名称:wordpress,代码行数:36,代码来源:bp-activity-filters.php

示例5: 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

示例6: devb_aawire_update_activity_action

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;
}
开发者ID:poweronio,项目名称:mbsite,代码行数:26,代码来源:bp-activity-as-wire.php

示例7: 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

示例8: prepare_metadata

/**
 * Prepare the metadata sent to Fedora and Solr from $_POST input.
 *
 * @param array $nextPids Array of fedora pids.
 * @return array metadata content
 */
function prepare_metadata($nextPids)
{
    global $fedora_api;
    /**
     * Prepare the metadata to be sent to Fedora and Solr.
     */
    $metadata = array();
    $metadata['id'] = $nextPids[0];
    $metadata['pid'] = $nextPids[0];
    $metadata['creator'] = 'HumCORE';
    $metadata['title'] = wp_strip_all_tags(stripslashes($_POST['deposit-title-unchanged']));
    $metadata['title_unchanged'] = wp_kses(stripslashes($_POST['deposit-title-unchanged']), array('b' => array(), 'em' => array(), 'strong' => array()));
    $metadata['abstract'] = wp_strip_all_tags(stripslashes($_POST['deposit-abstract-unchanged']));
    $metadata['abstract_unchanged'] = wp_kses(stripslashes($_POST['deposit-abstract-unchanged']), array('b' => array(), 'em' => array(), 'strong' => array()));
    $metadata['genre'] = sanitize_text_field($_POST['deposit-genre']);
    $metadata['committee_deposit'] = sanitize_text_field($_POST['deposit-on-behalf-flag']);
    $metadata['committee_id'] = sanitize_text_field($_POST['deposit-committee']);
    $metadata['submitter'] = bp_loggedin_user_id();
    /**
     * Get committee or author metadata.
     */
    if ('yes' === $metadata['committee_deposit']) {
        $committee = groups_get_group(array('group_id' => $metadata['committee_id']));
        $metadata['organization'] = 'MLA';
        $metadata['authors'][] = array('fullname' => $committee->name, 'given' => '', 'family' => '', 'uni' => $committee->slug, 'role' => 'creator', 'affiliation' => 'MLA');
    } else {
        $user_id = bp_loggedin_user_id();
        $user_firstname = get_the_author_meta('first_name', $user_id);
        $user_lastname = get_the_author_meta('last_name', $user_id);
        $user_affiliation = bp_get_profile_field_data(array('field' => 2, 'user_id' => $user_id));
        $metadata['organization'] = $user_affiliation;
        $metadata['authors'][] = array('fullname' => bp_get_loggedin_user_fullname(), 'given' => $user_firstname, 'family' => $user_lastname, 'uni' => bp_get_loggedin_user_username(), 'role' => 'author', 'affiliation' => $user_affiliation);
    }
    if ((empty($metadata['committee_deposit']) || 'yes' !== $metadata['committee_deposit']) && (!empty($_POST['deposit-other-authors-first-name']) && !empty($_POST['deposit-other-authors-last-name']))) {
        $other_authors = array_map(function ($first_name, $last_name) {
            return array('first_name' => sanitize_text_field($first_name), 'last_name' => sanitize_text_field($last_name));
        }, $_POST['deposit-other-authors-first-name'], $_POST['deposit-other-authors-last-name']);
        foreach ($other_authors as $author_array) {
            if (!empty($author_array['first_name']) && !empty($author_array['last_name'])) {
                $mla_user = bp_activity_find_mentions($author_array['first_name'] . $author_array['last_name']);
                if (!empty($mla_user)) {
                    foreach ($mla_user as $mla_userid => $mla_username) {
                        break;
                    }
                    // Only one, right?
                    $author_name = bp_core_get_user_displayname($mla_userid);
                    $author_firstname = get_the_author_meta('first_name', $mla_userid);
                    $author_lastname = get_the_author_meta('last_name', $mla_userid);
                    $author_affiliation = bp_get_profile_field_data(array('field' => 2, 'user_id' => $mla_userid));
                    $author_uni = $mla_username;
                } else {
                    $author_firstname = $author_array['first_name'];
                    $author_lastname = $author_array['last_name'];
                    $author_name = trim($author_firstname . ' ' . $author_lastname);
                    $author_uni = '';
                    $author_affiliation = '';
                }
                $metadata['authors'][] = array('fullname' => $author_name, 'given' => $author_firstname, 'family' => $author_lastname, 'uni' => $author_uni, 'role' => 'author', 'affiliation' => $author_affiliation);
            }
        }
    }
    usort($metadata['authors'], function ($a, $b) {
        return strcasecmp($a['family'], $b['family']);
    });
    /**
     * Format author info for solr.
     */
    $metadata['author_info'] = humcore_deposits_format_author_info($metadata['authors']);
    if (!empty($metadata['genre']) && in_array($metadata['genre'], array('Dissertation', 'Technical Report', 'Thesis')) && !empty($_POST['deposit-institution'])) {
        $metadata['institution'] = sanitize_text_field($_POST['deposit-institution']);
    } else {
        if (!empty($metadata['genre']) && in_array($metadata['genre'], array('Dissertation', 'Technical Report', 'Thesis')) && empty($_POST['deposit-institution'])) {
            $metadata['institution'] = $metadata['organization'];
        }
    }
    if (!empty($metadata['genre']) && ('Conference proceeding' == $metadata['genre'] || 'Conference paper' == $metadata['genre']) && !empty($_POST['deposit-conference-title'])) {
        $metadata['conference_title'] = sanitize_text_field($_POST['deposit-conference-title']);
        $metadata['conference_organization'] = sanitize_text_field($_POST['deposit-organization']);
    }
    $metadata['group'] = array();
    if (!empty($_POST['deposit-group'])) {
        foreach ($_POST['deposit-group'] as $group_id) {
            $group = groups_get_group(array('group_id' => sanitize_text_field($group_id)));
            $metadata['group'][] = $group->name;
            $metadata['group_ids'][] = $group_id;
        }
    }
    $metadata['subject'] = array();
    if (!empty($_POST['deposit-subject'])) {
        foreach ($_POST['deposit-subject'] as $subject) {
            $metadata['subject'][] = sanitize_text_field(stripslashes($subject));
            // Subject ids will be set later.
        }
    }
//.........这里部分代码省略.........
开发者ID:MartinPaulEve,项目名称:humcore,代码行数:101,代码来源:deposit.php

示例9: wall_input_filter

/**
 * This will save wall related data to the activity meta table when a new wall post happens
 *
 * @since BuddyBoss 2.0
 */
function wall_input_filter(&$activity)
{
    global $bp, $buddy_boss_wall;
    $user = $bp->loggedin_user;
    $tgt = $bp->displayed_user;
    $new_action = false;
    // If we're on an activity page (user's own profile or a friends), check for a target ID
    if ($bp->current_action == 'just-me' && (!isset($tgt->id) || $tgt->id == 0)) {
        return;
    }
    // It's either an @ mention, status update, or forum post.
    if ($bp->current_action == 'just-me' && $user->id == $tgt->id || $bp->current_action == 'forum') {
        if (!empty($activity->content)) {
            $mentioned = bp_activity_find_mentions($activity->content);
            $uids = array();
            $usernames = array();
            // Get all the mentions and store valid usernames in a new array
            foreach ((array) $mentioned as $mention) {
                if (bp_is_username_compatibility_mode()) {
                    $user_id = username_exists($mention);
                } else {
                    $user_id = bp_core_get_userid_from_nicename($mention);
                }
                if (empty($user_id)) {
                    continue;
                }
                $uids[] = $user_id;
                $usernames[] = $mention;
            }
            $len = count($uids);
            $mentions_action = '';
            // It's mentioning one person
            if ($len == 1) {
                $user_id = $tgt = bp_core_get_core_userdata((int) $uids[0]);
                $user_url = '<a href="' . $user->domain . '">' . $user->fullname . '</a>';
                $tgt_url = '<a href="' . bp_core_get_userlink($uids[0], false, true) . '">@' . $tgt->user_login . '</a>';
                $mentions_action = " " . __('mentioned', 'buddyboss') . " " . $tgt_url;
            } elseif ($len > 1) {
                $user_url = '<a href="' . $user->domain . '">' . $user->fullname . '</a>';
                $un = '@' . join(',@', $usernames);
                $mentions_action = $user_url . " " . __('mentioned', 'buddyboss') . " " . $len . " " . __('people', 'buddyboss');
            }
            // If it's a forum post let's define some forum topic text
            if ($bp->current_action == 'forum') {
                $new_action = str_replace(' replied to the forum topic', $mentions_action . ' in the forum topic', $activity->action);
            } elseif ($len > 0) {
                $new_action = $user_url . " " . $mentions_action . ' ' . __('in a public message', 'buddyboss');
            } else {
                $new_action = false;
            }
        }
    } elseif ($bp->current_action == 'just-me' && $user->id != $tgt->id) {
        $user_url = '<a href="' . $user->domain . '">' . $user->fullname . '</a>';
        $tgt_url = '<a href="' . $tgt->domain . '">' . $tgt->fullname . '\'s</a>';
        // if a user is on his own page it is an update
        $new_action = sprintf(__('%s wrote on %s Wall', 'buddyboss'), $user_url, $tgt_url);
    }
    if ($new_action) {
        bp_activity_update_meta($activity->id, 'bboss_wall_action', $new_action);
    }
}
开发者ID:par-orillonsoft,项目名称:Wishmagnet,代码行数:66,代码来源:buddy_boss_wall.php


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