Пример #1
0
 /**
  * @group mentions
  * @group bp_activity_at_name_filter
  */
 public function test_bp_activity_at_name_filter()
 {
     $u1 = $this->factory->user->create(array('user_login' => 'foobarbaz', 'user_nicename' => 'foobarbaz'));
     $u2 = $this->factory->user->create(array('user_login' => 'foo2', 'user_nicename' => 'foo2'));
     $u1_mention_name = bp_activity_get_user_mentionname($u1);
     $u1_domain = bp_core_get_user_domain($u1);
     $u2_mention_name = bp_activity_get_user_mentionname($u2);
     $u2_domain = bp_core_get_user_domain($u2);
     // mentions normal text should be replaced
     $at_name_in_text = sprintf('Hello @%s', $u1_mention_name);
     $at_name_in_text_final = "Hello <a href='" . $u1_domain . "' rel='nofollow'>@{$u1_mention_name}</a>";
     $this->assertEquals($at_name_in_text_final, bp_activity_at_name_filter($at_name_in_text));
     // mentions inside links sholudn't be replaced
     // inside href
     $at_name_in_mailto = sprintf("Send messages to <a href='mail@%s.com'>Foo Bar Baz</a>", $u1_mention_name);
     $at_name_in_mailto_final = sprintf("Send messages to <a href='mail@%s.com'>Foo Bar Baz</a>", $u1_mention_name);
     $this->assertEquals($at_name_in_mailto_final, bp_activity_at_name_filter($at_name_in_mailto));
     // inside linked text
     $at_name_in_link = sprintf('<a href="https://twitter.com/%1$s">@%1$s</a>', $u1_mention_name);
     $at_name_in_link_final = sprintf('<a href="https://twitter.com/%1$s">@%1$s</a>', $u1_mention_name);
     $this->assertEquals($at_name_in_link_final, bp_activity_at_name_filter($at_name_in_link));
     // Don't link non-existent users
     $text = "Don't link @non @existent @users";
     $this->assertSame($text, bp_activity_at_name_filter($text));
     // Don't link the domain name of the site
     preg_match('|https?://([^/]+)|', home_url(), $matches);
     if (!empty($matches[1])) {
         $text = $matches[1] . " Don't link the domain name " . $matches[1];
     }
     $this->assertSame($text, bp_activity_at_name_filter($text));
     // Multiples
     $at_name_in_mailto = sprintf("Send messages to @%s <a href='mail@%s.com'>Foo Bar Baz</a>. Please CC <a href='http://twitter.com/foo2'>@foo2</a>.", $u1_mention_name, $u1_mention_name, $u2_mention_name, $u2_mention_name);
     $at_name_in_mailto_final = sprintf('Send messages to <a href=\'%s\' rel=\'nofollow\'>@%s</a> <a href=\'mail@%s.com\'>Foo Bar Baz</a>. Please CC <a href=\'http://twitter.com/%s\'>@%s</a>.', $u1_domain, $u1_mention_name, $u1_mention_name, $u2_mention_name, $u2_mention_name);
     $this->assertEquals($at_name_in_mailto_final, bp_activity_at_name_filter($at_name_in_mailto));
 }
 /**
  * Mark activity item as ham
  *
  * @param BP_Activity_Activity $activity
  * @param string $source Either "by_a_person" (e.g. a person has manually marked the activity as ham) or "by_akismet" (automatically hammed).
  * @since BuddyPress (1.6)
  */
 public function mark_as_ham($activity, $source)
 {
     // If the activity was, originally, automatically marked as spam by Akismet, run the @mentions filter as it would have been skipped.
     if ('true' == bp_activity_get_meta($activity->id, '_bp_akismet_result') && !bp_activity_get_meta($activity->id, '_bp_akismet_user_result')) {
         $activity->content = bp_activity_at_name_filter($activity->content, $activity->id);
     }
     do_action('bp_activity_akismet_mark_as_ham', $activity, $source);
 }
Пример #3
0
 public function ap_the_answer_content($content)
 {
     global $post;
     if (!function_exists('bp_activity_at_name_filter')) {
         require_once WP_PLUGIN_DIR . '/buddypress/bp-activity/bp-activity-filters.php';
     }
     if ($post->post_type == 'answer') {
         return bp_activity_at_name_filter($content);
     }
     return $content;
 }
 /**
  * Mark activity item as ham.
  *
  * @since 1.6.0
  *
  * @param BP_Activity_Activity $activity Activity item being hammed.
  * @param string               $source   Either "by_a_person" (e.g. a person has
  *                                       manually marked the activity as ham) or
  *                                       "by_akismet" (automatically hammed).
  */
 public function mark_as_ham($activity, $source)
 {
     // If the activity was, originally, automatically marked as spam by Akismet, run the @mentions filter as it would have been skipped.
     if ('true' == bp_activity_get_meta($activity->id, '_bp_akismet_result') && !bp_activity_get_meta($activity->id, '_bp_akismet_user_result')) {
         $activity->content = bp_activity_at_name_filter($activity->content, $activity->id);
     }
     /**
      * Fires after marking an activity item has been marked as ham.
      *
      * @since 1.6.0
      *
      * @param BP_Activity_Activity $activity Activity object being marked as ham.
      * @param string               $source   Source of the whom marked as ham.
      *                                       Either "by_a_person" (e.g. a person has
      *                                       manually marked the activity as ham) or
      *                                       "by_akismet" (automatically hammed).
      */
     do_action('bp_activity_akismet_mark_as_ham', $activity, $source);
 }
Пример #5
0
/**
 * Catch mentions in saved activity items
 *
 * @since 1.5.0
 *
 * @param obj $activity
 *
 * @uses remove_filter() To remove the 'bp_activity_at_name_filter_updates' hook.
 * @uses bp_activity_at_name_filter()
 * @uses BP_Activity_Activity::save() {@link BP_Activity_Activity}
 */
function bp_activity_at_name_filter_updates($activity)
{
    // Only run this function once for a given activity item
    remove_filter('bp_activity_after_save', 'bp_activity_at_name_filter_updates');
    // Run the content through the linking filter, making sure to increment mention count
    $activity->content = bp_activity_at_name_filter($activity->content, $activity->id);
    // Resave the activity with the new content
    $activity->save();
}
Пример #6
0
 /** 
  * Modify reply content when it is passed to the activity stream
  * Includes quote mentions before stripping quotes
  * @version 2.0
  */
 function quote_mention($reply_content)
 {
     // Match the pattern for quote shortcodes
     $thequote = '#\\[quote(.*)\\](.*)\\[\\/quote\\]#is';
     if (preg_match($thequote, $reply_content)) {
         // If there are quotes found, match the quoted usernames
         $author_pattern = '#(?<=\\[quote author=")(.+?)(?=\\|)#i';
         preg_match_all($author_pattern, $reply_content, $authors);
         // For each username, turn it into a mention
         if (isset($authors)) {
             $authors = array_unique($authors[0]);
             count($authors) > 1 ? $grammar = ' were quoted:' : ($grammar = ' was quoted:');
             $mentions = implode(",@", $authors);
             $mentions = str_replace(" ", "-", $mentions);
             $mentions = str_replace(".", "-", $mentions);
             $mentions = '<p><span class="activity-quote-mention">@' . $mentions . $grammar . '</span></p>';
         }
         // Add the mentions to the content and register them with BuddyPress
         $reply_content = $mentions . $reply_content;
         $reply_content = strip_shortcodes($reply_content);
         $reply_content = bp_activity_at_name_filter($reply_content);
     }
     // Return the excerpt
     return $reply_content;
 }
function bp_ning_import_process_profiles()
{
    $ning_id_array = get_option('bp_ning_user_array', array());
    $field_key = get_option('bp_ning_profile_mapping', array());
    if (empty($_POST['pf']) && empty($field_key)) {
        return true;
    }
    if (empty($field_key)) {
        $fields = $_POST['pf'];
        // Keep track of renamed fields
        foreach ((array) $fields as $key => $field) {
            // Check to see if the user provided an alternative name for the field
            if ($_POST['pfn'][$key]) {
                $newfield = $_POST['pfn'][$key];
                $fields[$key] = $newfield;
                $field_key[$field] = $newfield;
            } else {
                $field_key[$field] = $field;
                $newfield = $field;
            }
            // Create the field
            $args = array('field_group_id' => 1, 'name' => $newfield, 'type' => 'textbox', 'is_required' => false);
            if (!xprofile_get_field_id_from_name($newfield)) {
                xprofile_insert_field($args);
            }
        }
        // Get the field ids for the just-created fields. Todo: patch the core so that xprofile_insert_field() returns the id
        foreach ((array) $fields as $field) {
            $field_ids[$field] = xprofile_get_field_id_from_name($field);
        }
        update_option('bp_ning_profile_mapping', $field_key);
    }
    // Populate the new fields
    $members = bp_ning_import_prepare_json('members');
    $imported = get_option('bp_ning_profiles_imported', array());
    $counter = 0;
    foreach ((array) $members as $member) {
        $member = (array) $member;
        $ncommented_id = $member['contributorName'];
        if (isset($imported[$ncommented_id])) {
            continue;
        }
        if ($counter >= 600) {
            update_option('bp_ning_profiles_imported', $imported);
            printf(__('%d out of %d member profiles done.'), count($imported), count($members));
            return false;
        }
        $commented_id = $ning_id_array[$ncommented_id];
        $commented_username = bp_core_get_username($commented_id);
        // Create @replies for all comments
        if (isset($member['comments']) && !get_user_meta($commented_id, 'ning_comments_imported') && function_exists('bp_activity_at_name_filter')) {
            global $bp;
            $comments = $member['comments'];
            $ncommented_id = $member['contributorName'];
            $commented_id = $ning_id_array[$ncommented_id];
            $commented_username = bp_core_get_username($commented_id);
            foreach ((array) $comments as $comment) {
                $ncommenter_id = $comment->contributorName;
                $commenter_id = $ning_id_array[$ncommenter_id];
                $ndate = strtotime($comment->createdDate);
                $date_created = date("Y-m-d H:i:s", $ndate);
                $from_user_link = bp_core_get_userlink($commenter_id);
                $activity_action = sprintf(__('%s posted an update:', 'buddypress'), $from_user_link);
                $activity_content = '@' . $commented_username . ' ' . $comment->description;
                $primary_link = bp_core_get_userlink($commenter_id, false, true);
                $args = array('user_id' => $commenter_id, 'action' => $activity_action, 'content' => bp_activity_at_name_filter($activity_content), 'primary_link' => $primary_link, 'component' => $bp->activity->id, 'type' => 'activity_update', 'recorded_time' => $date_created);
                bp_activity_add($args);
            }
            update_user_meta($commented_id, 'ning_comments_imported', 1);
        } else {
            update_user_meta($commented_id, 'ning_comments_imported', 1);
        }
        $profile_imported = get_user_meta($commented_id, 'ning_profile_imported');
        if (isset($member['profileQuestions']) && !$profile_imported) {
            $questions = (array) $member['profileQuestions'];
            foreach ($questions as $q => $a) {
                $member[$q] = $a;
            }
            unset($member['profileQuestions']);
        }
        if (!$profile_imported) {
            xprofile_set_field_data(get_option('bp-xprofile-fullname-field-name'), $commented_id, $member['fullName']);
            foreach ((array) $member as $key => $value) {
                if (!array_key_exists($key, $field_key)) {
                    continue;
                }
                $bp_field_name = $field_key[$key];
                $user = get_user_by('email', $member['email']);
                if (!xprofile_get_field_data($bp_field_name, $user->ID)) {
                    xprofile_set_field_data($bp_field_name, $user->ID, $value);
                }
            }
        }
        update_user_meta($commented_id, 'ning_profile_imported', 1);
        $counter++;
        $imported[$ncommented_id] = true;
    }
    update_option('bp_ning_profiles_imported', $imported);
    unset($members);
    return true;
}
Пример #8
0
 function c_item_content($c_item)
 {
     if (qa_opt('buddypress_integration_enable') && qa_opt('buddypress_mentions') && isset($c_item['content'])) {
         $c_item['content'] = bp_activity_at_name_filter($c_item['content']);
     }
     qa_html_theme_base::c_item_content($c_item);
 }