예제 #1
0
 /**
  * @goup bp_blogs_record_comment_sync_activity_comment
  * @group post_type_comment_activities
  */
 public function test_bp_blogs_record_comment_sync_activity_comment()
 {
     $u = $this->factory->user->create();
     $user = $this->factory->user->get_object_by_id($u);
     add_filter('bp_disable_blogforum_comments', '__return_false');
     $post_id = $this->factory->post->create(array('post_status' => 'publish', 'post_type' => 'using_old_filter', 'post_author' => $u));
     $parent_activity_id = bp_activity_get_activity_id(array('component' => 'blogs', 'type' => 'new_blog_post', 'item_id' => get_current_blog_id(), 'secondary_item_id' => $post_id));
     $comment_id = $this->factory->comment->create(array('user_id' => $u, 'comment_author_email' => $user->user_email, 'comment_post_ID' => $post_id));
     // Approve the comment
     $this->factory->comment->update_object($comment_id, array('comment_approved' => 1));
     $this->assertTrue($this->activity_exists_for_post_type($parent_activity_id, '', 'activity_comment', 'stream'), 'Generated activity for comments about a post type registering using the bp_blogs_record_post_post_types filter having sync on should have a activity_comment action');
     remove_filter('bp_disable_blogforum_comments', '__return_false');
 }
예제 #2
0
 /**
  * @group bp_activity_catch_transition_post_type_status
  * @group activity_tracking
  */
 public function test_bp_activity_catch_transition_post_type_status_publish_existing_post()
 {
     $u = $this->factory->user->create();
     $labels = array('bp_activity_admin_filter' => 'New Foo', 'bp_activity_front_filter' => 'Foos', 'bp_activity_new_post' => '%1$s posted a new <a href="%2$s">foo</a>', 'bp_activity_new_post_ms' => '%1$s posted a new <a href="%2$s">foo</a>, on the site %3$s');
     /**
      * 'public' must be set to true, otherwise bp_activity_get_post_types_tracking_args() fails.
      */
     register_post_type('foo', array('labels' => $labels, 'public' => true, 'supports' => array('buddypress-activity'), 'bp_activity' => array('action_id' => 'new_foo', 'contexts' => array('activity'), 'position' => 40)));
     // Temporarily remove post type activity hook so activity item isn't created.
     remove_action('transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3);
     // Create the initial post.
     $p = $this->factory->post->create(array('post_author' => $u, 'post_type' => 'foo'));
     $this->assertEmpty(bp_activity_get_activity_id(array('type' => 'new_foo')));
     // Add the post type activity hook back.
     add_action('transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3);
     // Emulate updating a post; this should create an activity item.
     wp_update_post(array('ID' => $p, 'post_title' => 'This is an edit'));
     // Assert!
     $this->assertNotEmpty(bp_activity_get_activity_id(array('type' => 'new_foo')), 'Activity item was not created during an edit of an existing WordPress post.');
     // Clean up.
     _unregister_post_type('foo');
 }
예제 #3
0
function bp_blogs_record_activity($args = '')
{
    global $bp;
    if (!bp_is_active('activity')) {
        return false;
    }
    $defaults = array('user_id' => bp_loggedin_user_id(), 'action' => '', 'content' => '', 'primary_link' => '', 'component' => $bp->blogs->id, 'type' => false, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // Remove large images and replace them with just one image thumbnail
    if (bp_is_active('activity') && !empty($content)) {
        $content = bp_activity_thumbnail_content_images($content, $primary_link);
    }
    if (!empty($action)) {
        $action = apply_filters('bp_blogs_record_activity_action', $action);
    }
    if (!empty($content)) {
        $content = apply_filters('bp_blogs_record_activity_content', bp_create_excerpt($content), $content);
    }
    // Check for an existing entry and update if one exists.
    $id = bp_activity_get_activity_id(array('user_id' => $user_id, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id));
    return bp_activity_add(array('id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide));
}
예제 #4
0
 /**
  * @group bp_blogs_transition_activity_status
  * @group bp_blogs_remove_comment
  */
 public function test_bp_blogs_remove_comment_should_remove_spammed_activity_comment()
 {
     // save the current user and override logged-in user
     $old_user = get_current_user_id();
     $u = $this->factory->user->create();
     $this->set_current_user($u);
     $userdata = get_userdata($u);
     // create the blog post
     $post_id = $this->factory->post->create(array('post_status' => 'publish', 'post_type' => 'post', 'post_title' => 'First title'));
     // let's use activity comments instead of single "new_blog_comment" activity items
     add_filter('bp_disable_blogforum_comments', '__return_false');
     $c1 = wp_new_comment(array('comment_post_ID' => $post_id, 'comment_author' => $userdata->user_nicename, 'comment_author_url' => 'http://buddypress.org', 'comment_author_email' => $userdata->user_email, 'comment_content' => 'this is a blog comment', 'comment_type' => '', 'comment_parent' => 0, 'user_id' => $u));
     // save the corresponding activity comment ID
     $a1 = bp_activity_get_activity_id(array('type' => 'activity_comment', 'display_comments' => 'stream', 'meta_query' => array(array('key' => 'bp_blogs_post_comment_id', 'value' => $c1))));
     // trash the parent comment.
     // corresponding activity comment should now be marked as spam
     // @see bp_blogs_transition_activity_status()
     wp_trash_comment($c1);
     // now permanently delete the comment
     wp_delete_comment($c1, true);
     // activity comment should no longer exist
     $a = bp_activity_get(array('in' => $a1, 'display_comments' => 'stream', 'spam' => 'all'));
     // this is a convoluted way of testing if the activity comment still exists
     $this->assertTrue(empty($a['activities'][0]));
     // reset
     $this->set_current_user($old_user);
     remove_filter('bp_disable_blogforum_comments', '__return_false');
 }
예제 #5
0
/**
 * Update an existing group forum post.
 *
 * Uses the bundled version of bbPress packaged with BuddyPress.
 *
 * @since BuddyPress (1.1.0)
 *
 * @param int    $post_id   The post ID of the existing forum post.
 * @param string $post_text The text for the forum post.
 * @param int    $topic_id  The topic ID of the existing forum topic.
 * @param mixed  $page      The page number where the new forum post should reside. Optional.
 *
 * @return mixed The forum post ID on success. Boolean false on failure.
 */
function groups_update_group_forum_post($post_id, $post_text, $topic_id, $page = false)
{
    $bp = buddypress();
    /** This filter is documented in bp-groups/bp-groups-forums.php */
    $post_text = apply_filters('group_forum_post_text_before_save', $post_text);
    /** This filter is documented in bp-groups/bp-groups-forums.php */
    $topic_id = apply_filters('group_forum_post_topic_id_before_save', $topic_id);
    $post = bp_forums_get_post($post_id);
    $post_id = bp_forums_insert_post(array('post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id, 'poster_id' => $post->poster_id));
    if (empty($post_id)) {
        return false;
    }
    $topic = bp_forums_get_topic_details($topic_id);
    $activity_action = sprintf(__('%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink($post->poster_id), '<a href="' . bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '">' . esc_attr($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink(groups_get_current_group()) . '">' . esc_attr(bp_get_current_group_name()) . '</a>');
    $activity_content = bp_create_excerpt($post_text);
    $primary_link = bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '/';
    if (!empty($page)) {
        $primary_link .= "?topic_page=" . $page;
    }
    // Get the corresponding activity item
    if (bp_is_active('activity')) {
        $id = bp_activity_get_activity_id(array('user_id' => $post->poster_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post', 'item_id' => bp_get_current_group_id(), 'secondary_item_id' => $post_id));
    }
    /** This filter is documented in bp-groups/bp-groups-forums.php */
    $action = apply_filters_ref_array('groups_activity_new_forum_post_action', array($activity_action, $post_text, &$topic, &$topic));
    /** This filter is documented in bp-groups/bp-groups-forums.php */
    $content = apply_filters_ref_array('groups_activity_new_forum_post_content', array($activity_content, $post_text, &$topic, &$topic));
    /** This filter is documented in bp-groups/bp-groups-forums.php */
    $filtered_primary_link = apply_filters('groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id);
    groups_record_activity(array('id' => $id, 'action' => $action, 'content' => $content, 'primary_link' => $filtered_primary_link, 'type' => 'new_forum_post', 'item_id' => (int) bp_get_current_group_id(), 'user_id' => (int) $post->poster_id, 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_time));
    /**
     * Fires after the update of a group forum post.
     *
     * @since BuddyPress (1.1.0)
     *
     * @param object $post  Object holding current post being updated.
     * @param object $topic Object holding current topic details. Passed by reference.
     */
    do_action_ref_array('groups_update_group_forum_post', array($post, &$topic));
    return $post_id;
}
 /**
  * Function to fetch group feeds and save RSS entries as BP activity items.
  *
  * @param int $group_id The group ID.
  */
 function bp_groupblogs_fetch_group_feeds($group_id = false)
 {
     if (empty($group_id)) {
         $group_id = bp_get_current_group_id();
     }
     if ($group_id == bp_get_current_group_id()) {
         $group = groups_get_current_group();
     } else {
         $group = new BP_Groups_Group($group_id);
     }
     if (!$group) {
         return false;
     }
     $group_blogs = groups_get_groupmeta($group_id, 'blogfeeds');
     $items = array();
     foreach ((array) $group_blogs as $feed_url) {
         $feed_url = trim($feed_url);
         if (empty($feed_url)) {
             continue;
         }
         // Make sure the feed is accessible
         $test = wp_remote_get($feed_url);
         if (is_wp_error($test)) {
             continue;
         }
         try {
             $rss = new SimpleXmlElement($test['body']);
         } catch (Exception $e) {
             continue;
         }
         $rss = fetch_feed(trim($feed_url));
         if (!is_wp_error($rss)) {
             $maxitems = $rss->get_item_quantity(10);
             $rss_items = $rss->get_items(0, $maxitems);
             foreach ($rss_items as $item) {
                 $key = $item->get_date('U');
                 $items[$key]['title'] = $item->get_title();
                 $items[$key]['subtitle'] = $item->get_title();
                 //$items[$key]['author'] = $item->get_author()->get_name();
                 $items[$key]['blogname'] = $item->get_feed()->get_title();
                 $items[$key]['link'] = $item->get_permalink();
                 $items[$key]['blogurl'] = $item->get_feed()->get_link();
                 $items[$key]['description'] = $item->get_description();
                 $items[$key]['source'] = $item->get_source();
                 $items[$key]['copyright'] = $item->get_copyright();
                 $items[$key]['primary_link'] = $item->get_link();
                 $items[$key]['guid'] = $item->get_id();
                 $items[$key]['feedurl'] = $feed_url;
             }
         }
     }
     if (!empty($items)) {
         ksort($items);
         $items = array_reverse($items, true);
     } else {
         return false;
     }
     /* Set the visibility */
     $hide_sitewide = 'public' != $group->status ? true : false;
     /* Record found blog posts in activity streams */
     foreach ((array) $items as $post_date => $post) {
         $activity_action = sprintf(__('Blog: %s from %s in the group %s', 'bp-groups-externalblogs'), '<a class="feed-link" href="' . esc_attr($post['link']) . '">' . esc_attr($post['title']) . '</a>', '<a class="feed-author" href="' . esc_attr($post['blogurl']) . '">' . esc_attr($post['blogname']) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>');
         $activity_content = '<div>' . strip_tags(bp_create_excerpt($post['description'], 175)) . '</div>';
         $activity_content = apply_filters('bp_groupblogs_activity_content', $activity_content, $post, $group);
         /* Fetch an existing activity_id if one exists. */
         // backpat
         $id = bp_activity_get_activity_id(array('user_id' => false, 'action' => $activity_action, 'component' => 'groups', 'type' => 'exb', 'item_id' => $group_id, 'secondary_item_id' => wp_hash($post['blogurl'])));
         // new method
         if (empty($id)) {
             $existing = bp_activity_get(array('user_id' => false, 'component' => 'groups', 'type' => 'exb', 'item_id' => $group_id, 'update_meta_cache' => false, 'display_comments' => false, 'meta_query' => array(array('key' => 'exb_guid', 'value' => $post['guid']))));
             // we've found an existing entry
             if (!empty($existing['activities'])) {
                 $id = (int) $existing['activities'][0]->id;
             }
         }
         /* Record or update in activity streams. */
         // Skip if it already exists
         if (empty($id)) {
             $aid = groups_record_activity(array('id' => $id, 'user_id' => false, 'action' => $activity_action, 'content' => $activity_content, 'primary_link' => $post['primary_link'], 'type' => 'exb', 'item_id' => $group_id, 'recorded_time' => gmdate("Y-m-d H:i:s", $post_date), 'hide_sitewide' => $hide_sitewide));
             // save rss guid as activity meta
             bp_activity_update_meta($aid, 'exb_guid', $post['guid']);
             bp_activity_update_meta($aid, 'exb_feedurl', $post['feedurl']);
         }
     }
     return $items;
 }
/**
 * Record blog-related activity to the activity stream.
 *
 * @since 1.0.0
 *
 * @see bp_activity_add() for description of parameters.
 *
 * @param array|string $args {
 *     See {@link bp_activity_add()} for complete description of arguments.
 *     The arguments listed here have different default values from
 *     bp_activity_add().
 *     @type string $component Default: 'blogs'.
 * }
 * @return int|bool On success, returns the activity ID. False on failure.
 */
function bp_blogs_record_activity($args = '')
{
    $defaults = array('user_id' => bp_loggedin_user_id(), 'action' => '', 'content' => '', 'primary_link' => '', 'component' => buddypress()->blogs->id, 'type' => false, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false);
    $r = wp_parse_args($args, $defaults);
    if (!empty($r['action'])) {
        /**
         * Filters the action associated with activity for activity stream.
         *
         * @since 1.2.0
         *
         * @param string $value Action for the activity stream.
         */
        $r['action'] = apply_filters('bp_blogs_record_activity_action', $r['action']);
    }
    if (!empty($r['content'])) {
        /**
         * Filters the content associated with activity for activity stream.
         *
         * @since 1.2.0
         *
         * @param string $value Generated summary from content for the activity stream.
         * @param string $value Content for the activity stream.
         * @param array  $r     Array of arguments used for the activity stream item.
         */
        $r['content'] = apply_filters('bp_blogs_record_activity_content', bp_activity_create_summary($r['content'], $r), $r['content'], $r);
    }
    // Check for an existing entry and update if one exists.
    $id = bp_activity_get_activity_id(array('user_id' => $r['user_id'], 'component' => $r['component'], 'type' => $r['type'], 'item_id' => $r['item_id'], 'secondary_item_id' => $r['secondary_item_id']));
    return bp_activity_add(array('id' => $id, 'user_id' => $r['user_id'], 'action' => $r['action'], 'content' => $r['content'], 'primary_link' => $r['primary_link'], 'component' => $r['component'], 'type' => $r['type'], 'item_id' => $r['item_id'], 'secondary_item_id' => $r['secondary_item_id'], 'recorded_time' => $r['recorded_time'], 'hide_sitewide' => $r['hide_sitewide']));
}
예제 #8
0
/**
 * bp_like_remove_user_like()
 *
 * Registers that the user has unliked a given item.
 *
 */
function bp_like_remove_user_like($item_id = '', $type = 'activity')
{
    global $bp;
    if (!$item_id) {
        return false;
    }
    if (!isset($user_id)) {
        $user_id = $bp->loggedin_user->id;
    }
    if ($user_id == 0) {
        echo bp_like_get_text('must_be_logged_in');
        return false;
    }
    if ($type == 'activity') {
        /* Remove this from the users liked activities. */
        $user_likes = get_user_meta($user_id, 'bp_liked_activities', true);
        unset($user_likes[$item_id]);
        update_user_meta($user_id, 'bp_liked_activities', $user_likes);
        /* Update the total number of users who have liked this activity. */
        $users_who_like = bp_activity_get_meta($item_id, 'liked_count', true);
        unset($users_who_like[$user_id]);
        /* If nobody likes the activity, delete the meta for it to save space, otherwise, update the meta */
        if (empty($users_who_like)) {
            bp_activity_delete_meta($item_id, 'liked_count');
        } else {
            bp_activity_update_meta($item_id, 'liked_count', $users_who_like);
        }
        $liked_count = count($users_who_like);
        /* Remove the update on the users profile from when they liked the activity. */
        $update_id = bp_activity_get_activity_id(array('item_id' => $item_id, 'component' => 'bp-like', 'type' => 'activity_liked', 'user_id' => $user_id));
        bp_activity_delete(array('id' => $update_id, 'item_id' => $item_id, 'component' => 'bp-like', 'type' => 'activity_liked', 'user_id' => $user_id));
    } elseif ($type == 'blogpost') {
        /* Remove this from the users liked activities. */
        $user_likes = get_user_meta($user_id, 'bp_liked_blogposts', true);
        unset($user_likes[$item_id]);
        update_user_meta($user_id, 'bp_liked_blogposts', $user_likes);
        /* Update the total number of users who have liked this blog post. */
        $users_who_like = get_post_meta($item_id, 'liked_count', true);
        unset($users_who_like[$user_id]);
        /* If nobody likes the blog post, delete the meta for it to save space, otherwise, update the meta */
        if (empty($users_who_like)) {
            delete_post_meta($item_id, 'liked_count');
        } else {
            update_post_meta($item_id, 'liked_count', $users_who_like);
        }
        $liked_count = count($users_who_like);
        /* Remove the update on the users profile from when they liked the activity. */
        $update_id = bp_activity_get_activity_id(array('item_id' => $item_id, 'component' => 'bp-like', 'type' => 'blogpost_liked', 'user_id' => $user_id));
        bp_activity_delete(array('id' => $update_id, 'item_id' => $item_id, 'component' => 'bp-like', 'type' => 'blogpost_liked', 'user_id' => $user_id));
    }
    echo bp_like_get_text('like');
    if ($liked_count) {
        echo ' (' . $liked_count . ')';
    }
}
예제 #9
0
 /**
  * 2/ Catch the idea in order to use it just before the activity is saved
  * @see  $this->adjust_activity_args();
  *
  * We won't change anything to the $activity_content.
  *
  * @package WP Idea Stream
  * @subpackage buddypress/activity
  *
  * @since 2.1.0
  *
  * @param  string  $activity_content the excerpt created by BuddyPress
  * @param  WP_Post $post             the post object (can be an idea)
  * @param  string  $post_permalink   the permalink to this object
  * @uses   bp_activity_get_activity_id() to get an activity id
  * @uses   bp_activity_delete()      to delete an activity
  * @return string                    the activity content unchanged
  */
 public function catch_idea_comment($activity_content = '', $post = null, $post_permalink = '')
 {
     // If it's a comment, BuddyPress is attaching it into the post var of the comment object
     if (empty($post->post->post_type) || $this->post_type != $post->post->post_type) {
         return $activity_content;
     }
     $this->idea = $post->post;
     $this->secondary_item_id = $post->comment_ID;
     /**
      * For this particular case, we need to check for a previous entry to delete it
      * As a the 'edit_comment' hook will be fired if the comment was edited from the
      * 'wp-admin/comment.php?action=editcomment..' screen, bp_blogs_record_comment()
      * will not find the new_blog_comment activity to edit and will post a new one
      */
     $id = bp_activity_get_activity_id(array('type' => 'new_' . $this->post_type . '_comment', 'secondary_item_id' => $this->secondary_item_id));
     // Found one, delete it to prevent duplicates
     if (!empty($id)) {
         bp_activity_delete(array('id' => $id));
     }
     // return without editing.
     return $activity_content;
 }
예제 #10
0
/**
 * Return the deposit activity id.
 *
 * @uses apply_filters() To call the 'humcore_get_deposit_activity_id' hook.
 *
 * @return The deposit id.
 */
function humcore_get_deposit_activity_id()
{
    global $bp;
    $activity_id = bp_activity_get_activity_id(array('type' => 'new_deposit', 'component' => $bp->humcore_deposits->id, 'secondary_item_id' => humcore_get_deposit_record_identifier()));
    return apply_filters('humcore_get_deposit_activity_id', $activity_id);
}
function ccgn_create_activity_items($post_id)
{
    $bp = buddypress();
    // We want to fetch the saved post, because WP has done some filtering on save.
    $post_object = get_post($post_id);
    $author_id = (int) $post_object->post_author;
    $user_link = bp_core_get_userlink($author_id);
    $post_type_object = get_post_type_object($post_object->post_type);
    $post_type_label = strtolower($post_type_object->labels->singular_name);
    // A single narrative may be associated with more than one group
    $origin_group_id = ccgn_get_origin_group($post_id);
    $associated_groups = ccgn_get_associated_group_ids($post_id);
    $type = $post_object->post_type . '_created';
    foreach ($associated_groups as $group_id) {
        // Does an activity item already exist?
        $exists = bp_activity_get_activity_id(array('component' => $bp->groups->id, 'type' => $type, 'item_id' => $group_id, 'secondary_item_id' => $post_id));
        if (!empty($exists)) {
            continue;
        }
        // Create a post url that is relative to this group.
        $post_url = trailingslashit(ccgn_get_home_permalink($group_id)) . $post_object->post_name;
        $post_link = sprintf('<a href="%s">%s</a>', $post_url, $post_object->post_title);
        $group = groups_get_group(array('group_id' => $group_id));
        $group_url = bp_get_group_permalink($group);
        $group_link = '<a href="' . $group_url . '">' . $group->name . '</a>';
        // Only set hide_sitewide to false if this is the origin group and it is a public group.
        if ($group_id == $origin_group_id && 'public' == bp_get_group_status($group)) {
            $hide_sitewide = false;
        } else {
            $hide_sitewide = true;
        }
        $action = sprintf(__('%1$s published the %2$s %3$s in the Hub %4$s', 'cc-group-narratives'), $user_link, $post_type_label, $post_link, $group_link);
        $args = array('user_id' => $author_id, 'action' => $action, 'primary_link' => $post_link, 'component' => $bp->groups->id, 'type' => $type, 'item_id' => $group_id, 'secondary_item_id' => $post_id, 'recorded_time' => $post_object->post_date, 'hide_sitewide' => $hide_sitewide, 'content' => bp_create_excerpt($post_object->post_content, 358));
        do_action($post_object->post_type . '_before_activity_save', $args);
        $activity_id = bp_activity_add(apply_filters($post_object->post_type . '_activity_args', $args, $post_id));
    }
}
예제 #12
0
 /**
  * @group bp_activity_get_activity_id
  */
 public function test_bp_activity_get_activity_id()
 {
     $args = array('user_id' => 5, 'component' => 'foo', 'type' => 'bar', 'item_id' => 12, 'secondary_item_id' => 44);
     $a = $this->factory->activity->create($args);
     $this->assertEquals($a, bp_activity_get_activity_id($args));
 }
예제 #13
0
/**
 * @since 1.0.3
 * it is not used any more because qwe are linking to threaded view
 * Remove notification for group forum posts/new topic
 */
function ac_notifier_remove_notification_for_topic()
{
    global $bp;
    //is group & group forum active ?
    if (!(bp_is_active("groups") && bp_is_active("forums"))) {
        return;
    }
    //if either group or forum is not actuive do not do anything
    //check if we are on single topic screen, right?
    if (bp_is_group_forum_topic() && is_user_logged_in()) {
        $topic_id = bp_forums_get_topic_id_from_slug($bp->action_variables[1]);
        //get id from slug
        $topic = get_topic($topic_id);
        $group_id = $bp->groups->current_group->id;
        //find activity id for this topic
        $activity_id = bp_activity_get_activity_id(array('user_id' => $topic->poster_id, 'component' => $bp->groups->id, 'type' => "new_forum_topic", "item_id" => $group_id, 'secondary_item_id' => $topic_id));
        //remove notification for new topic comments: easy
        if (!empty($activity_id)) {
            bp_core_delete_notifications_by_item_id($bp->loggedin_user->id, $activity_id, $bp->ac_notifier->id, 'new_activity_comment_' . $activity_id);
        }
        $posts = ac_notifier_get_forum_post_ids($topic_id);
        if (!empty($posts)) {
            //find all activities for the post
            $activities = ac_notifier_get_activity_ids(array("item_id" => $group_id, "secondary_ids" => $posts, "component" => $bp->groups->id, "type" => "new_forum_post"));
            //pass the array
            foreach ((array) $activities as $ac_id) {
                bp_core_delete_notifications_by_item_id($bp->loggedin_user->id, $ac_id, $bp->ac_notifier->id, 'new_activity_comment_' . $ac_id);
            }
        }
    }
}
 function bp_groupblogs_fetch_group_feeds($group_id = false)
 {
     global $bp;
     include_once ABSPATH . 'wp-includes/rss.php';
     if (empty($group_id)) {
         $group_id = $bp->groups->current_group->id;
     }
     if ($group_id == $bp->groups->current_group->id) {
         $group = $bp->groups->current_group;
     } else {
         $group = new BP_Groups_Group($group_id);
     }
     if (!$group) {
         return false;
     }
     $group_blogs = groups_get_groupmeta($group_id, 'blogfeeds');
     $group_blogs = explode(";", $group_blogs[0]);
     /* Set the visibility */
     $hide_sitewide = 'public' != $group->status ? true : false;
     foreach ((array) $group_blogs as $feed_url) {
         $rss = fetch_feed(trim($feed_url));
         if (!is_wp_error($rss)) {
             foreach ($rss->get_items(0, 10) as $item) {
                 $key = $item->get_date('U');
                 $items[$key]['title'] = $item->get_title();
                 $items[$key]['subtitle'] = $item->get_title();
                 //$items[$key]['author'] = $item->get_author()->get_name();
                 $items[$key]['blogname'] = $item->get_feed()->get_title();
                 $items[$key]['link'] = $item->get_permalink();
                 $items[$key]['blogurl'] = $item->get_feed()->get_link();
                 $items[$key]['description'] = $item->get_description();
                 $items[$key]['source'] = $item->get_source();
                 $items[$key]['copyright'] = $item->get_copyright();
             }
         }
     }
     if ($items) {
         ksort($items);
         $items = array_reverse($items, true);
     } else {
         return false;
     }
     /* Record found blog posts in activity streams */
     foreach ((array) $items as $post_date => $post) {
         //var_dump($post);
         if (substr($post['blogname'], 0, 7) == "Twitter") {
             $activity_action = sprintf(__('%s from %s in the group %s', 'bp-groups-externalblogs'), '<a class="feed-link" href="' . esc_attr($post['link']) . '">Tweet</a>', '<a class="feed-author" href="' . esc_attr($post['blogurl']) . '">' . attribute_escape($post['blogname']) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . attribute_escape($group->name) . '</a>');
         } else {
             $activity_action = sprintf(__('Blog: %s from %s in the group %s', 'bp-groups-externalblogs'), '<a class="feed-link" href="' . esc_attr($post['link']) . '">' . esc_attr($post['title']) . '</a>', '<a class="feed-author" href="' . esc_attr($post['blogurl']) . '">' . attribute_escape($post['blogname']) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . attribute_escape($group->name) . '</a>');
         }
         $activity_content = '<div>' . strip_tags(bp_create_excerpt($post['description'], 175)) . '</div>';
         $activity_content = apply_filters('bp_groupblogs_activity_content', $activity_content, $post, $group);
         /* Fetch an existing activity_id if one exists. */
         if (function_exists('bp_activity_get_activity_id')) {
             $id = bp_activity_get_activity_id(array('user_id' => false, 'action' => $activity_action, 'component' => $bp->groups->id, 'type' => 'exb', 'item_id' => $group_id, 'secondary_item_id' => wp_hash($post['blogurl'])));
         }
         /* Record or update in activity streams. */
         groups_record_activity(array('id' => $id, 'user_id' => false, 'action' => $activity_action, 'content' => $activity_content, 'primary_link' => $item->get_link(), 'type' => 'exb', 'item_id' => $group_id, 'secondary_item_id' => wp_hash($post['blogurl']), 'recorded_time' => gmdate("Y-m-d H:i:s", $post_date), 'hide_sitewide' => $hide_sitewide));
     }
     return $items;
 }
/**
 * Update Activity and blogs meta and eventually sync comment with activity comment
 *
 * @since  2.5.0
 *
 * @param  int|bool        $activity_id          ID of recorded activity, or false if sync is active.
 * @param  WP_Comment|null $comment              The comment object.
 * @param  array           $activity_args        Array of activity arguments.
 * @param  object|null     $activity_post_object The post type tracking args object.
 * @return int|bool Returns false if no activity, the activity id otherwise.
 */
function bp_blogs_comment_sync_activity_comment(&$activity_id, $comment = null, $activity_args = array(), $activity_post_object = null)
{
    if (empty($activity_args) || empty($comment->post->ID) || empty($activity_post_object->comment_action_id)) {
        return false;
    }
    // Set the current blog id.
    $blog_id = get_current_blog_id();
    // These activity metadatas are used to build the new_blog_comment action string
    if (!empty($activity_id) && !empty($activity_args['item_id']) && 'new_blog_comment' === $activity_post_object->comment_action_id) {
        // add some post info in activity meta
        bp_activity_update_meta($activity_id, 'post_title', $comment->post->post_title);
        bp_activity_update_meta($activity_id, 'post_url', esc_url_raw(add_query_arg('p', $comment->post->ID, home_url('/'))));
    }
    // Sync comment - activity comment
    if (!bp_disable_blogforum_comments()) {
        if (!empty($_REQUEST['action'])) {
            $existing_activity_id = get_comment_meta($comment->comment_ID, 'bp_activity_comment_id', true);
            if (!empty($existing_activity_id)) {
                $activity_args['id'] = $existing_activity_id;
            }
        }
        if (empty($activity_post_object)) {
            $activity_post_object = bp_activity_get_post_type_tracking_args($comment->post->post_type);
        }
        if (isset($activity_post_object->action_id) && isset($activity_post_object->component_id)) {
            // find the parent 'new_post_type' activity entry
            $parent_activity_id = bp_activity_get_activity_id(array('component' => $activity_post_object->component_id, 'type' => $activity_post_object->action_id, 'item_id' => $blog_id, 'secondary_item_id' => $comment->comment_post_ID));
            // Try to create a new activity item for the parent blog post.
            if (empty($parent_activity_id)) {
                $parent_activity_id = bp_activity_post_type_publish($comment->post->ID, $comment->post);
            }
        }
        // we found the parent activity entry
        // so let's go ahead and reconfigure some activity args
        if (!empty($parent_activity_id)) {
            // set the parent activity entry ID
            $activity_args['activity_id'] = $parent_activity_id;
            // now see if the WP parent comment has a BP activity ID
            $comment_parent = 0;
            if (!empty($comment->comment_parent)) {
                $comment_parent = get_comment_meta($comment->comment_parent, 'bp_activity_comment_id', true);
            }
            // WP parent comment does not have a BP activity ID
            // so set to 'new_' . post_type activity ID
            if (empty($comment_parent)) {
                $comment_parent = $parent_activity_id;
            }
            $activity_args['parent_id'] = $comment_parent;
            $activity_args['skip_notification'] = true;
            // could not find corresponding parent activity entry
            // so wipe out $args array
        } else {
            $activity_args = array();
        }
        // Record in activity streams
        if (!empty($activity_args)) {
            $activity_id = bp_activity_new_comment($activity_args);
            if (empty($activity_args['id'])) {
                // The activity metadata to inform about the corresponding comment ID
                bp_activity_update_meta($activity_id, "bp_blogs_{$comment->post->post_type}_comment_id", $comment->comment_ID);
                // The comment metadata to inform about the corresponding activity ID
                add_comment_meta($comment->comment_ID, 'bp_activity_comment_id', $activity_id);
                // These activity metadatas are used to build the new_blog_comment action string
                if ('new_blog_comment' === $activity_post_object->comment_action_id) {
                    bp_activity_update_meta($activity_id, 'post_title', $comment->post->post_title);
                    bp_activity_update_meta($activity_id, 'post_url', esc_url_raw(add_query_arg('p', $comment->post->ID, home_url('/'))));
                }
            }
            /**
             * Fires after an activity comment is added from a WP post comment.
             *
             * @since 2.6.0
             *
             * @param int        $activity_id          The activity comment ID.
             * @param WP_Comment $post_type_comment    WP Comment object.
             * @param array      $activity_args        Activity comment arguments.
             * @param object     $activity_post_object The post type tracking args object.
             */
            do_action('bp_blogs_comment_sync_activity_comment', $activity_id, $comment, $activity_args, $activity_post_object);
        }
    }
    // Update the blogs last active date
    bp_blogs_update_blogmeta($blog_id, 'last_activity', bp_core_current_time());
    if ('new_blog_comment' === $activity_post_object->comment_action_id) {
        /**
         * Fires after BuddyPress has recorded metadata about a published blog post comment.
         *
         * @since 2.5.0
         *
         * @param int     $value    Comment ID of the blog post comment being recorded.
         * @param WP_Post $post  WP_Comment object for the current blog post.
         * @param string  $value ID of the user associated with the current blog post comment.
         */
        do_action('bp_blogs_new_blog_comment', $comment->comment_ID, $comment, bp_loggedin_user_id());
    }
    return $activity_id;
}
예제 #16
0
/**
 * bp_album_record_activity()
 *
 * @version 0.1.8.12
 * @since 0.1.8.0
 */
function bp_album_record_activity($pic_data)
{
    global $bp;
    if (!function_exists('bp_activity_add') || !$bp->album->bp_album_enable_wire) {
        return false;
    }
    $id = bp_activity_get_activity_id(array('component' => $bp->album->id, 'item_id' => $pic_data->id));
    $primary_link = bp_core_get_user_domain($pic_data->owner_id) . $bp->album->slug . '/' . $bp->album->single_slug . '/' . $pic_data->id . '/';
    $title = $pic_data->title;
    $desc = $pic_data->description;
    // Using mb_strlen adds support for unicode (asian languages). Unicode uses TWO bytes per character, and is not
    // accurately counted in most string length functions
    // ========================================================================================================
    if (function_exists('mb_strlen')) {
        $title = mb_strlen($title) <= 20 ? $title : mb_substr($title, 0, 20 - 1) . '&#8230;';
        $desc = mb_strlen($desc) <= 400 ? $desc : mb_substr($desc, 0, 400 - 1) . '&#8230;';
    } else {
        $title = strlen($title) <= 20 ? $title : substr($title, 0, 20 - 1) . '&#8230;';
        $desc = strlen($desc) <= 400 ? $desc : substr($desc, 0, 400 - 1) . '&#8230;';
    }
    $action = sprintf(__('%s uploaded a new picture: %s', 'bp-album'), bp_core_get_userlink($pic_data->owner_id), '<a href="' . $primary_link . '">' . $title . '</a>');
    // Image path workaround for virtual servers that do not return correct base URL
    // ===========================================================================================================
    if ($bp->album->bp_album_url_remap == true) {
        $filename = substr($pic_data->pic_thumb_url, strrpos($pic_data->pic_thumb_url, '/') + 1);
        $owner_id = $pic_data->owner_id;
        $image_path = $bp->album->bp_album_base_url . '/' . $owner_id . '/' . $filename;
    } else {
        $image_path = bp_get_root_domain() . $pic_data->pic_thumb_url;
    }
    // ===========================================================================================================
    $content = '<p> <a href="' . $primary_link . '" class="picture-activity-thumb" title="' . $title . '"><img src="' . $image_path . '" /></a>' . $desc . '</p>';
    $type = 'bp_album_picture';
    $item_id = $pic_data->id;
    $hide_sitewide = $pic_data->privacy != 0;
    return bp_activity_add(array('id' => $id, 'user_id' => $pic_data->owner_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $bp->album->id, 'type' => $type, 'item_id' => $item_id, 'recorded_time' => $pic_data->date_uploaded, 'hide_sitewide' => $hide_sitewide));
}
예제 #17
0
파일: bp-blogs.php 프로젝트: n-sane/zaroka
function bp_blogs_record_activity( $args = '' ) {
	global $bp;

	if ( !function_exists( 'bp_activity_add' ) )
		return false;

	/* Because blog, comment, and blog post code execution happens before anything else
	   we may need to manually instantiate the activity component globals */
	if ( !$bp->activity && function_exists('bp_activity_setup_globals') )
		bp_activity_setup_globals();

	$defaults = array(
		'user_id' => $bp->loggedin_user->id,
		'action' => '',
		'content' => '',
		'primary_link' => '',
		'component' => $bp->blogs->id,
		'type' => false,
		'item_id' => false,
		'secondary_item_id' => false,
		'recorded_time' => bp_core_current_time(),
		'hide_sitewide' => false
	);

	$r = wp_parse_args( $args, $defaults );
	extract( $r, EXTR_SKIP );

	/* Remove large images and replace them with just one image thumbnail */
 	if ( function_exists( 'bp_activity_thumbnail_content_images' ) && !empty( $content ) )
		$content = bp_activity_thumbnail_content_images( $content );

	if ( !empty( $action ) )
		$action = apply_filters( 'bp_blogs_record_activity_action', $action );

	if ( !empty( $content ) )
		$content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ), $content );

	/* Check for an existing entry and update if one exists. */
	$id = bp_activity_get_activity_id( array(
		'user_id' => $user_id,
		'component' => $component,
		'type' => $type,
		'item_id' => $item_id,
		'secondary_item_id' => $secondary_item_id
	) );

	return bp_activity_add( array( 'id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
}
예제 #18
0
파일: bp-groups.php 프로젝트: n-sane/zaroka
function groups_update_group_forum_post( $post_id, $post_text, $topic_id, $page = false ) {
	global $bp;

	$post_text = apply_filters( 'group_forum_post_text_before_save', $post_text );
	$topic_id = apply_filters( 'group_forum_post_topic_id_before_save', $topic_id );

	$post = bp_forums_get_post( $post_id );

	if ( $post_id = bp_forums_insert_post( array( 'post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id, 'poster_id' => $post->poster_id ) ) ) {
		$topic = bp_forums_get_topic_details( $topic_id );

		$activity_action = sprintf( __( '%s posted on the forum topic %s in the group %s:', 'buddypress'), bp_core_get_userlink( $post->poster_id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug .'">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' );
		$activity_content = bp_create_excerpt( $post_text );
		$primary_link = bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/';

		if ( $page )
			$primary_link .= "?topic_page=" . $page;

		/* Fetch an existing entry and update if one exists. */
		if ( function_exists( 'bp_activity_get_activity_id' ) )
			$id = bp_activity_get_activity_id( array( 'user_id' => $post->poster_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post', 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $post_id ) );

		/* Update the entry in activity streams */
		groups_record_activity( array(
			'id' => $id,
			'action' => apply_filters( 'groups_activity_new_forum_post_action', $activity_action, $post_text, &$topic, &$forum_post ),
			'content' => apply_filters( 'groups_activity_new_forum_post_content', $activity_content, $post_text, &$topic, &$forum_post ),
			'primary_link' => apply_filters( 'groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id ),
			'type' => 'new_forum_post',
			'item_id' => (int)$bp->groups->current_group->id,
			'user_id' => (int)$post->poster_id,
			'secondary_item_id' => $post_id,
			'recorded_time' => $post->post_time
		) );

		do_action( 'groups_update_group_forum_post', &$post, &$topic );

		return $post_id;
	}

	return false;
}
예제 #19
0
/**
 * Update an existing group forum post.
 *
 * Uses the bundled version of bbPress packaged with BuddyPress.
 *
 * @since BuddyPress (1.1.0)
 *
 * @param int $post_id The post ID of the existing forum post.
 * @param string $post_text The text for the forum post.
 * @param int $topic_id The topic ID of the existing forum topic.
 * @param mixed $page The page number where the new forum post should reside.
 *	  Optional.
 * @return mixed The forum post ID on success. Boolean false on failure.
 */
function groups_update_group_forum_post($post_id, $post_text, $topic_id, $page = false)
{
    $bp = buddypress();
    $post_text = apply_filters('group_forum_post_text_before_save', $post_text);
    $topic_id = apply_filters('group_forum_post_topic_id_before_save', $topic_id);
    $post = bp_forums_get_post($post_id);
    $post_id = bp_forums_insert_post(array('post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id, 'poster_id' => $post->poster_id));
    if (empty($post_id)) {
        return false;
    }
    $topic = bp_forums_get_topic_details($topic_id);
    $activity_action = sprintf(__('%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink($post->poster_id), '<a href="' . bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '">' . esc_attr($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink(groups_get_current_group()) . '">' . esc_attr(bp_get_current_group_name()) . '</a>');
    $activity_content = bp_create_excerpt($post_text);
    $primary_link = bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '/';
    if (!empty($page)) {
        $primary_link .= "?topic_page=" . $page;
    }
    // Get the corresponding activity item
    if (bp_is_active('activity')) {
        $id = bp_activity_get_activity_id(array('user_id' => $post->poster_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post', 'item_id' => bp_get_current_group_id(), 'secondary_item_id' => $post_id));
    }
    // Update the entry in activity streams
    groups_record_activity(array('id' => $id, 'action' => apply_filters_ref_array('groups_activity_new_forum_post_action', array($activity_action, $post_text, &$topic, &$topic)), 'content' => apply_filters_ref_array('groups_activity_new_forum_post_content', array($activity_content, $post_text, &$topic, &$topic)), 'primary_link' => apply_filters('groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id), 'type' => 'new_forum_post', 'item_id' => (int) bp_get_current_group_id(), 'user_id' => (int) $post->poster_id, 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_time));
    do_action_ref_array('groups_update_group_forum_post', array($post, &$topic));
    return $post_id;
}
예제 #20
0
 /**
  * @group bp_blogs_comment_sync_activity_comment
  * @group post_type_comment_activities
  */
 public function test_bp_blogs_comment_sync_activity_comment_for_custom_post_type()
 {
     if (is_multisite()) {
         $b = $this->factory->blog->create();
         switch_to_blog($b);
         add_filter('comment_flood_filter', '__return_false');
     } else {
         $b = get_current_blog_id();
     }
     $u = $this->factory->user->create();
     $userdata = get_userdata($u);
     $labels = array('name' => 'bars', 'singular_name' => 'bar');
     register_post_type('foo', array('labels' => $labels, 'public' => true, 'supports' => array('comments')));
     add_post_type_support('foo', 'buddypress-activity');
     bp_activity_set_post_type_tracking_args('foo', array('comment_action_id' => 'new_foo_comment'));
     add_filter('bp_disable_blogforum_comments', '__return_false');
     $p = $this->factory->post->create(array('post_author' => $u, 'post_type' => 'foo'));
     $a1 = bp_activity_get_activity_id(array('type' => 'new_foo', 'filter' => array('item_id' => $b, 'secondary_item_id' => $p)));
     $c = wp_new_comment(array('comment_post_ID' => $p, 'comment_author' => $userdata->user_nicename, 'comment_author_url' => 'http://buddypress.org', 'comment_author_email' => $userdata->user_email, 'comment_content' => 'this is a foo comment', 'comment_type' => '', 'comment_parent' => 0, 'user_id' => $u));
     $a2 = bp_activity_new_comment(array('content' => 'this should generate a new foo comment', 'user_id' => $u, 'activity_id' => $a1));
     $activity_args = array('type' => 'activity_comment', 'display_comments' => 'stream', 'meta_query' => array(array('key' => 'bp_blogs_foo_comment_id', 'compare' => 'exists')));
     $a = bp_activity_get($activity_args);
     $aids = wp_list_pluck($a['activities'], 'id');
     $cids = wp_list_pluck(get_approved_comments($p), 'comment_ID');
     foreach ($aids as $aid) {
         $this->assertTrue(in_array(bp_activity_get_meta($aid, 'bp_blogs_foo_comment_id'), $cids), 'The comment ID should be in the activity meta');
     }
     foreach ($cids as $cid) {
         $this->assertTrue(in_array(get_comment_meta($cid, 'bp_activity_comment_id', true), $aids), 'The activity ID should be in the comment meta');
     }
     _unregister_post_type('foo');
     if (is_multisite()) {
         restore_current_blog();
         remove_filter('comment_flood_filter', '__return_false');
     }
     remove_filter('bp_disable_blogforum_comments', '__return_false');
 }
예제 #21
0
/**
 * Create an activity item for a newly posted post type comment.
 *
 * @since 2.5.0
 *
 * @param  int  $comment_id  ID of the comment.
 * @param  bool $is_approved Whether the comment is approved or not.
 * @param  object $activity_post_object the post type tracking args object.
 *
 * @return int|bool The ID of the activity on success. False on error.
 */
function bp_activity_post_type_comment($comment_id = 0, $is_approved = true, $activity_post_object = null)
{
    // Get the users comment
    $post_type_comment = get_comment($comment_id);
    // Don't record activity if the comment hasn't been approved
    if (empty($is_approved)) {
        return false;
    }
    // Don't record activity if no email address has been included
    if (empty($post_type_comment->comment_author_email)) {
        return false;
    }
    // Don't record activity if the comment has already been marked as spam
    if ('spam' === $is_approved) {
        return false;
    }
    // Get the user by the comment author email.
    $user = get_user_by('email', $post_type_comment->comment_author_email);
    // If user isn't registered, don't record activity
    if (empty($user)) {
        return false;
    }
    // Get the user_id
    $user_id = (int) $user->ID;
    // Get blog and post data
    $blog_id = get_current_blog_id();
    // Get the post
    $post_type_comment->post = get_post($post_type_comment->comment_post_ID);
    if (!is_a($post_type_comment->post, 'WP_Post')) {
        return false;
    }
    /**
     * Filters whether to publish activities about the comment regarding the post status
     *
     * @since 2.5.0
     *
     * @param bool true to bail, false otherwise.
     */
    $is_post_status_not_allowed = (bool) apply_filters('bp_activity_post_type_is_post_status_allowed', 'publish' !== $post_type_comment->post->post_status || !empty($post_type_comment->post->post_password));
    // If this is a password protected post, or not a public post don't record the comment
    if ($is_post_status_not_allowed) {
        return false;
    }
    // Set post type
    $post_type = $post_type_comment->post->post_type;
    if (empty($activity_post_object)) {
        // Get the post type tracking args.
        $activity_post_object = bp_activity_get_post_type_tracking_args($post_type);
        // Bail if the activity type does not exist
        if (empty($activity_post_object->comments_tracking->action_id)) {
            return false;
        }
    }
    // Set the $activity_comment_object
    $activity_comment_object = $activity_post_object->comments_tracking;
    /**
     * Filters whether or not to post the activity about the comment.
     *
     * This is a variable filter, dependent on the post type,
     * that lets components or plugins bail early if needed.
     *
     * @since 2.5.0
     *
     * @param bool $value      Whether or not to continue.
     * @param int  $blog_id    ID of the current site.
     * @param int  $post_id    ID of the current post being commented.
     * @param int  $user_id    ID of the current user.
     * @param int  $comment_id ID of the current comment being posted.
     */
    if (false === apply_filters("bp_activity_{$post_type}_pre_comment", true, $blog_id, $post_type_comment->post->ID, $user_id, $comment_id)) {
        return false;
    }
    // Is this an update ?
    $activity_id = bp_activity_get_activity_id(array('user_id' => $user_id, 'component' => $activity_comment_object->component_id, 'type' => $activity_comment_object->action_id, 'item_id' => $blog_id, 'secondary_item_id' => $comment_id));
    // Record this in activity streams.
    $comment_link = get_comment_link($post_type_comment->comment_ID);
    // Backward compatibility filters for the 'blogs' component.
    if ('blogs' == $activity_comment_object->component_id) {
        $activity_content = apply_filters_ref_array('bp_blogs_activity_new_comment_content', array($post_type_comment->comment_content, &$post_type_comment, $comment_link));
        $activity_primary_link = apply_filters_ref_array('bp_blogs_activity_new_comment_primary_link', array($comment_link, &$post_type_comment));
    } else {
        $activity_content = $post_type_comment->comment_content;
        $activity_primary_link = $comment_link;
    }
    $activity_args = array('id' => $activity_id, 'user_id' => $user_id, 'content' => $activity_content, 'primary_link' => $activity_primary_link, 'component' => $activity_comment_object->component_id, 'recorded_time' => $post_type_comment->comment_date_gmt);
    if (bp_disable_blogforum_comments()) {
        $blog_url = get_home_url($blog_id);
        $post_url = add_query_arg('p', $post_type_comment->post->ID, trailingslashit($blog_url));
        $activity_args['type'] = $activity_comment_object->action_id;
        $activity_args['item_id'] = $blog_id;
        $activity_args['secondary_item_id'] = $post_type_comment->comment_ID;
        if (!empty($activity_args['content'])) {
            // Create the excerpt.
            $activity_summary = bp_activity_create_summary($activity_args['content'], $activity_args);
            // Backward compatibility filter for blog comments.
            if ('blogs' == $activity_post_object->component_id) {
                $activity_args['content'] = apply_filters('bp_blogs_record_activity_content', $activity_summary, $activity_args['content'], $activity_args, $post_type);
            } else {
                $activity_args['content'] = $activity_summary;
            }
        }
        // Set up the action by using the format functions.
        $action_args = array_merge($activity_args, array('post_title' => $post_type_comment->post->post_title, 'post_url' => $post_url, 'blog_url' => $blog_url, 'blog_name' => get_blog_option($blog_id, 'blogname')));
        $activity_args['action'] = call_user_func_array($activity_comment_object->format_callback, array('', (object) $action_args));
        // Make sure the action is set.
        if (empty($activity_args['action'])) {
            return;
        } else {
            // Backward compatibility filter for the blogs component.
            if ('blogs' === $activity_post_object->component_id) {
                $activity_args['action'] = apply_filters('bp_blogs_record_activity_action', $activity_args['action']);
            }
        }
        $activity_id = bp_activity_add($activity_args);
    }
    /**
     * Fires after the publishing of an activity item for a newly published post type post.
     *
     * @since 2.5.0
     *
     * @param int        $activity_id          ID of the newly published activity item.
     * @param WP_Comment $post_type_comment    Comment object.
     * @param array      $activity_args        Array of activity arguments.
     * @param object     $activity_post_object the post type tracking args object.
     */
    do_action_ref_array('bp_activity_post_type_comment', array(&$activity_id, $post_type_comment, $activity_args, $activity_post_object));
    return $activity_id;
}
/**
 * When a post type comment status transition occurs, update the relevant activity's status.
 *
 * @since 2.5.0
 *
 * @param string     $new_status New comment status.
 * @param string     $old_status Previous comment status.
 * @param WP_Comment $comment Comment data.
 */
function bp_activity_transition_post_type_comment_status($new_status, $old_status, $comment)
{
    $post_type = get_post_type($comment->comment_post_ID);
    if (!$post_type) {
        return;
    }
    // Get the post type tracking args.
    $activity_post_object = bp_activity_get_post_type_tracking_args($post_type);
    // Bail if the activity type does not exist
    if (empty($activity_post_object->comments_tracking->action_id)) {
        return false;
        // Set the $activity_comment_object
    } else {
        $activity_comment_object = $activity_post_object->comments_tracking;
    }
    // Init an empty activity ID
    $activity_id = 0;
    /**
     * Activity currently doesn't have any concept of a trash, or an unapproved/approved state.
     *
     * If a blog comment transitions to a "delete" or "hold" status, delete the activity item.
     * If a blog comment transitions to trashed, or spammed, mark the activity as spam.
     * If a blog comment transitions to approved (and the activity exists), mark the activity as ham.
     * If a blog comment transitions to unapproved (and the activity exists), mark the activity as spam.
     * Otherwise, record the comment into the activity stream.
     */
    // This clause handles delete/hold.
    if (in_array($new_status, array('delete', 'hold'))) {
        return bp_activity_post_type_remove_comment($comment->comment_ID, $activity_post_object);
        // These clauses handle trash, spam, and un-spams.
    } elseif (in_array($new_status, array('trash', 'spam', 'unapproved'))) {
        $action = 'spam_activity';
    } elseif ('approved' == $new_status) {
        $action = 'ham_activity';
    }
    // Get the activity
    if (bp_disable_blogforum_comments()) {
        $activity_id = bp_activity_get_activity_id(array('component' => $activity_comment_object->component_id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $comment->comment_ID, 'type' => $activity_comment_object->action_id));
    } else {
        $activity_id = get_comment_meta($comment->comment_ID, 'bp_activity_comment_id', true);
    }
    /**
     * Leave a chance to plugins to manage activity comments differently.
     *
     * @since  2.5.0
     *
     * @param bool        $value       True to override BuddyPress management.
     * @param string      $post_type   The post type name.
     * @param int         $activity_id The post type activity (0 if not found).
     * @param string      $new_status  The new status of the post type comment.
     * @param string      $old_status  The old status of the post type comment.
     * @param WP_Comment  $comment Comment data.
     */
    if (true === apply_filters('bp_activity_pre_transition_post_type_comment_status', false, $post_type, $activity_id, $new_status, $old_status, $comment)) {
        return false;
    }
    // Check activity item exists
    if (empty($activity_id)) {
        // If no activity exists, but the comment has been approved, record it into the activity table.
        if ('approved' == $new_status) {
            return bp_activity_post_type_comment($comment->comment_ID, true, $activity_post_object);
        }
        return;
    }
    // Create an activity object
    $activity = new BP_Activity_Activity($activity_id);
    if (empty($activity->component)) {
        return;
    }
    // Spam/ham the activity if it's not already in that state
    if ('spam_activity' === $action && !$activity->is_spam) {
        bp_activity_mark_as_spam($activity);
    } elseif ('ham_activity' == $action) {
        bp_activity_mark_as_ham($activity);
    }
    // Add "new_post_type_comment" to the whitelisted activity types, so that the activity's Akismet history is generated
    $post_type_comment_action = $activity_comment_object->action_id;
    $comment_akismet_history = create_function('$t', '$t[] = $post_type_comment_action; return $t;');
    add_filter('bp_akismet_get_activity_types', $comment_akismet_history);
    // Make sure the activity change won't edit the comment if sync is on
    remove_action('bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20);
    // Save the updated activity
    $activity->save();
    // Restore the action
    add_action('bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20);
    // Remove the "new_blog_comment" activity type whitelist so we don't break anything
    remove_filter('bp_akismet_get_activity_types', $comment_akismet_history);
}
예제 #23
0
/**
 * bp_groupblog_set_group_to_post_activity ( $activity )
 *
 * Record the blog activity for the group - by Luiz Armesto
 */
function bp_groupblog_set_group_to_post_activity($activity)
{
    if ($activity->type != 'new_blog_post') {
        return;
    }
    $blog_id = $activity->item_id;
    $post_id = $activity->secondary_item_id;
    $post = get_post($post_id);
    $group_id = get_groupblog_group_id($blog_id);
    if (!$group_id) {
        return;
    }
    $group = groups_get_group(array('group_id' => $group_id));
    // Verify if we already have the modified activity for this blog post
    $id = bp_activity_get_activity_id(array('user_id' => $activity->user_id, 'type' => $activity->type, 'item_id' => $group_id, 'secondary_item_id' => $activity->secondary_item_id));
    // if we don't have, verify if we have an original activity
    if (!$id) {
        $id = bp_activity_get_activity_id(array('user_id' => $activity->user_id, 'type' => $activity->type, 'item_id' => $activity->item_id, 'secondary_item_id' => $activity->secondary_item_id));
    }
    // If we found an activity for this blog post then overwrite that to avoid have multiple activities for every blog post edit
    if ($id) {
        $activity->id = $id;
    }
    // Replace the necessary values to display in group activity stream
    $activity->action = sprintf(__('%s wrote a new blog post %s in the group %s:', 'groupblog'), bp_core_get_userlink($post->post_author), '<a href="' . get_permalink($post->ID) . '">' . attribute_escape($post->post_title) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . attribute_escape($group->name) . '</a>');
    $activity->item_id = (int) $group_id;
    $activity->component = 'groups';
    $activity->hide_sitewide = 0;
    remove_action('bp_activity_before_save', 'bp_groupblog_set_group_to_post_activity');
    return $activity;
}
/**
 * Update the activity item for a custom post type entry.
 *
 * @since 2.2.0
 *
 * @param WP_Post $post Post item.
 * @return bool True on success, false on failure.
 */
function bp_activity_post_type_update($post = null)
{
    if (!is_a($post, 'WP_Post')) {
        return;
    }
    // Get the post type tracking args.
    $activity_post_object = bp_activity_get_post_type_tracking_args($post->post_type);
    if (empty($activity_post_object->action_id)) {
        return;
    }
    $activity_id = bp_activity_get_activity_id(array('component' => $activity_post_object->component_id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $post->ID, 'type' => $activity_post_object->action_id));
    // Activity ID doesn't exist, so stop!
    if (empty($activity_id)) {
        return;
    }
    // Delete the activity if the post was updated with a password.
    if (!empty($post->post_password)) {
        bp_activity_delete(array('id' => $activity_id));
    }
    // Update the activity entry.
    $activity = new BP_Activity_Activity($activity_id);
    if (!empty($post->post_content)) {
        $activity_summary = bp_activity_create_summary($post->post_content, (array) $activity);
        // Backward compatibility filter for the blogs component.
        if ('blogs' == $activity_post_object->component_id) {
            $activity->content = apply_filters('bp_blogs_record_activity_content', $activity_summary, $post->post_content, (array) $activity, $post->post_type);
        } else {
            $activity->content = $activity_summary;
        }
    }
    // Save the updated activity.
    $updated = $activity->save();
    /**
     * Fires after the updating of an activity item for a custom post type entry.
     *
     * @since 2.2.0
     *
     * @param WP_Post              $post     Post object.
     * @param BP_Activity_Activity $activity Activity object.
     */
    do_action('bp_activity_post_type_updated', $post, $activity);
    return $updated;
}
예제 #25
0
 /**
  * Save or update a new event
  * @version 2.0
  */
 function save_event($post_id, $post = '')
 {
     // Don't do anything if it's not an event
     if ('event' != $post->post_type) {
         return;
     }
     // Verify the nonce before proceeding.
     if (!isset($_POST['event-details-box']) || !wp_verify_nonce($_POST['event-details-box'], basename(__FILE__))) {
         return $post_id;
     }
     /* -----------------------------------
     			SAVE EVENT TIME 
     		------------------------------------*/
     // Retrieve the event time
     $event_time = date('Y-m-d H:i:s', strtotime($_POST['event-time']));
     $prior_time = $post->post_date;
     // Update the post object
     $post->post_date = $event_time;
     remove_action('save_post', array($this, 'save_event'));
     wp_update_post($post);
     add_action('save_post', array($this, 'save_event'), 10, 2);
     /* -----------------------------------
     			SAVE META INFORMATION 
     		------------------------------------ */
     // Define the meta to look for
     $meta = array('event_duration' => $_POST['event-duration'], 'event_capacity' => $_POST['event-capacity'], 'event_rsvp' => $_POST['event-rsvp'], 'event_role' => $_POST['event-role']);
     // Loop through each meta, saving it to the database
     foreach ($meta as $meta_key => $new_meta_value) {
         // Get the meta value of the custom field key.
         $meta_value = get_post_meta($post_id, $meta_key, true);
         // If there is no new meta value but an old value exists, delete it.
         if (current_user_can('delete_post_meta', $post_id, $meta_key) && '' == $new_meta_value && $meta_value) {
             delete_post_meta($post_id, $meta_key, $meta_value);
         } elseif (current_user_can('add_post_meta', $post_id, $meta_key) && $new_meta_value && '' == $meta_value) {
             add_post_meta($post_id, $meta_key, $new_meta_value, true);
         } elseif (current_user_can('edit_post_meta', $post_id, $meta_key) && $new_meta_value && $new_meta_value != $meta_value) {
             update_post_meta($post_id, $meta_key, $new_meta_value);
         }
     }
     // Delete the RSVP meta if the date has changed
     if ($event_time != $prior_time) {
         delete_post_meta($post_id, 'event_rsvps');
     }
     /* -----------------------------------
     			BUDDYPRESS NOTIFICATION
     		------------------------------------ */
     // Get event data
     global $bp, $wpdb;
     if (!$user_id) {
         $user_id = $post->post_author;
     }
     // Figure out which calendars this event belongs to
     $calendars = wp_get_post_terms($post_id, 'calendar');
     $group_slugs = array();
     // For each calendar, check if it's a group calendar
     foreach ($calendars as $calendar) {
         if (is_group_calendar($calendar->term_id)) {
             $groups[] = $calendar;
         }
     }
     // If this event does not belong to a group, we can stop here
     if (empty($groups)) {
         return $post_id;
     }
     // Only register notifications for future or published events
     if (!in_array($post->post_status, array('publish', 'future'))) {
         return $post_id;
     }
     // Loop through each group, adding an activity entry for each one
     foreach ($groups as $group) {
         // Get the group data
         $group_id = groups_get_id($group->slug);
         $group_name = $group->name;
         // Configure the activity entry
         $post_permalink = get_permalink($post_id);
         $activity_action = sprintf('%1$s added the event %2$s to the %3$s.', bp_core_get_userlink($post->post_author), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', $group_name . ' <a href="' . SITEURL . '/calendar/' . $group->slug . '">group calendar</a>');
         $activity_content = $post->post_content;
         // Check for existing entry
         $activity_id = bp_activity_get_activity_id(array('user_id' => $user_id, 'component' => $bp->groups->id, 'type' => 'new_calendar_event', 'item_id' => $group_id, 'secondary_item_id' => $post_id));
         // Record the entry
         groups_record_activity(array('id' => $activity_id, 'user_id' => $user_id, 'action' => $activity_action, 'content' => $activity_content, 'primary_link' => $post_permalink, 'type' => 'new_calendar_event', 'item_id' => $group_id, 'secondary_item_id' => $post_id));
         // Update the group's last activity meta
         groups_update_groupmeta($group_id, 'last_activity', bp_core_current_time());
         // Maybe notify every group member
         if ($_POST['event-rsvp']) {
             if (bp_group_has_members($args = array('group_id' => $group_id, 'exclude_admins_mods' => false, 'per_page' => 99999))) {
                 while (bp_members()) {
                     bp_the_member();
                     // Remove any existing notifications ( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false )
                     bp_notifications_delete_notifications_by_item_id(bp_get_group_member_id(), $group_id, $bp->groups->id, 'new_calendar_event', $post_id);
                     // Send a notification ( itemid , groupid , component, action , secondary )
                     bp_notifications_add_notification(array('user_id' => bp_get_group_member_id(), 'item_id' => $group_id, 'secondary_item_id' => $post_id, 'component_name' => $bp->groups->id, 'component_action' => 'new_calendar_event'));
                 }
             }
         }
     }
 }
예제 #26
0
 /**
  * @group bp_blogs_catch_transition_post_status
  */
 public function test_update_blog_post_and_new_blog_comment_and_activity_comment_meta()
 {
     // save the current user and override logged-in user
     $old_user = get_current_user_id();
     $u = $this->factory->user->create();
     $this->set_current_user($u);
     $userdata = get_userdata($u);
     // create the blog post
     $post_id = $this->factory->post->create(array('post_status' => 'publish', 'post_type' => 'post', 'post_title' => 'First title'));
     // remove comment flood protection temporarily
     add_filter('comment_flood_filter', '__return_false');
     // let's use activity comments instead of single "new_blog_comment" activity items
     add_filter('bp_disable_blogforum_comments', '__return_false');
     $c1 = wp_new_comment(array('comment_post_ID' => $post_id, 'comment_author' => $userdata->user_nicename, 'comment_author_url' => 'http://buddypress.org', 'comment_author_email' => $userdata->user_email, 'comment_content' => 'this is a blog comment', 'comment_type' => '', 'comment_parent' => 0, 'user_id' => $u));
     remove_filter('bp_disable_blogforum_comments', '__return_false');
     // let's also add a "new_blog_comment" activity entry
     $c2 = wp_new_comment(array('comment_post_ID' => $post_id, 'comment_author' => $userdata->user_nicename, 'comment_author_url' => 'http://buddypress.org', 'comment_author_email' => $userdata->user_email, 'comment_content' => 'this is another blog comment', 'comment_type' => '', 'comment_parent' => 0, 'user_id' => $u));
     // bring back flood protection
     remove_filter('comment_flood_filter', '__return_false');
     // update the initial blog post
     wp_update_post(array('ID' => $post_id, 'post_title' => 'Second title'));
     // grab the activity ID for the activity comment
     $a1 = bp_activity_get_activity_id(array('type' => 'activity_comment', 'display_comments' => 'stream', 'meta_query' => array(array('key' => 'bp_blogs_post_comment_id', 'value' => $c1))));
     // grab the activity ID for the blog comment
     $a2 = bp_activity_get_activity_id(array('component' => buddypress()->blogs->id, 'type' => 'new_blog_comment', 'secondary_item_id' => $c2));
     // see if blog comment activity meta matches the post items
     $this->assertEquals('Second title', bp_activity_get_meta($a1, 'post_title'));
     $this->assertEquals(add_query_arg('p', $post_id, home_url('/')), bp_activity_get_meta($a1, 'post_url'));
     $this->assertEquals('Second title', bp_activity_get_meta($a2, 'post_title'));
     $this->assertEquals(add_query_arg('p', $post_id, home_url('/')), bp_activity_get_meta($a2, 'post_url'));
     // reset
     $this->set_current_user($old_user);
 }
예제 #27
0
/**
 * When a blog comment status transition occurs, update the relevant activity's status.
 *
 * @global object $bp BuddyPress global settings
 * @param string $new_status New comment status.
 * @param string $old_status Previous comment status.
 * @param object $comment Comment data.
 * @since 1.6
 */
function bp_blogs_transition_activity_status($new_status, $old_status, $comment)
{
    global $bp;
    // Check the Activity component is active
    if (!bp_is_active('activity')) {
        return;
    }
    /**
     * Activity currently doesn't have any concept of a trash, or an unapproved/approved state.
     *
     * If a blog comment transitions to a "delete" or "hold" status, delete the activity item.
     * If a blog comment transitions to trashed, or spammed, mark the activity as spam.
     * If a blog comment transitions to approved (and the activity exists), mark the activity as ham.
     * Otherwise, record the comment into the activity stream.
     */
    // This clause was moved in from bp_blogs_remove_comment() in BuddyPress 1.6. It handles delete/hold.
    if (in_array($new_status, array('delete', 'hold'))) {
        return bp_blogs_remove_comment($comment->comment_ID);
    } elseif (in_array($new_status, array('trash', 'spam'))) {
        $action = 'spam_activity';
    } elseif ('approved' == $new_status) {
        $action = 'ham_activity';
    }
    // Get the activity
    $activity_id = bp_activity_get_activity_id(array('component' => $bp->blogs->id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $comment->comment_ID, 'type' => 'new_blog_comment'));
    // Check activity item exists
    if (!$activity_id) {
        // If no activity exists, but the comment has been approved, record it into the activity table.
        if ('approved' == $new_status) {
            return bp_blogs_record_comment($comment->comment_ID, true);
        }
        return;
    }
    // Create an activity object
    $activity = new BP_Activity_Activity($activity_id);
    if (empty($activity->component)) {
        return;
    }
    // Spam/ham the activity if it's not already in that state
    if ('spam_activity' == $action && !$activity->is_spam) {
        bp_activity_mark_as_spam($activity);
    } elseif ('ham_activity' == $action) {
        bp_activity_mark_as_ham($activity);
    }
    // Add "new_blog_comment" to the whitelisted activity types, so that the activity's Akismet history is generated
    $comment_akismet_history = create_function('$t', '$t[] = "new_blog_comment"; return $t;');
    add_filter('bp_akismet_get_activity_types', $comment_akismet_history);
    // Save the updated activity
    $activity->save();
    // Remove the "new_blog_comment" activity type whitelist so we don't break anything
    remove_filter('bp_akismet_get_activity_types', $comment_akismet_history);
}
예제 #28
0
 /**
  * @group bp_blogs_record_comment
  */
 public function test_bp_blogs_record_comment_should_record_parent_blog_post_activity_if_not_found()
 {
     // Save the current user and override logged-in user
     $old_user = get_current_user_id();
     $u = $this->factory->user->create();
     $this->set_current_user($u);
     // Get user details
     $user = get_userdata($u);
     // Let's use activity comments instead of single "new_blog_comment" activity items
     add_filter('bp_disable_blogforum_comments', '__return_false');
     // Create the blog post
     $post_id = $this->factory->post->create(array('post_status' => 'publish', 'post_type' => 'post'));
     // Now, delete the activity item for the blog post
     bp_activity_delete(array('component' => buddypress()->blogs->id, 'type' => 'new_blog_post', 'item_id' => get_current_blog_id(), 'secondary_item_id' => $post_id));
     // Add a comment to blog post
     wp_new_comment(array('comment_post_ID' => $post_id, 'user_id' => $u, 'comment_content' => 'Dummy comment', 'comment_author' => 'Dumbo', 'comment_author_url' => 'http://buddypress.org', 'comment_author_email' => $user->user_email));
     // Fetch the activity ID for the blog post to see if it exists
     $a1 = bp_activity_get_activity_id(array('type' => 'new_blog_post', 'component' => buddypress()->blogs->id, 'filter' => array('item_id' => get_current_blog_id(), 'secondary_item_id' => $post_id)));
     // Assert that activity item for blog post was created after adding a comment
     $this->assertNotNull($a1, 'Activity item was not created for existing blog post when recording post comment.');
     $this->set_current_user($old_user);
 }
예제 #29
0
/**
 * Record blog-related activity to the activity stream.
 *
 * @since BuddyPress (1.0.0)
 *
 * @see bp_activity_add() for description of parameters.
 * @global object $bp The BuddyPress global settings object.
 *
 * @param array $args {
 *     See {@link bp_activity_add()} for complete description of arguments.
 *     The arguments listed here have different default values from
 *     bp_activity_add().
 *     @type string $component Default: 'blogs'.
 * }
 * @return int|bool On success, returns the activity ID. False on failure.
 */
function bp_blogs_record_activity( $args = '' ) {
	global $bp;

	// Bail if activity is not active
	if ( ! bp_is_active( 'activity' ) ) {
		return false;
	}

	$defaults = array(
		'user_id'           => bp_loggedin_user_id(),
		'action'            => '',
		'content'           => '',
		'primary_link'      => '',
		'component'         => $bp->blogs->id,
		'type'              => false,
		'item_id'           => false,
		'secondary_item_id' => false,
		'recorded_time'     => bp_core_current_time(),
		'hide_sitewide'     => false
	);

	$r = wp_parse_args( $args, $defaults );

	// Remove large images and replace them with just one image thumbnail
	if ( ! empty( $r['content'] ) ) {
		$r['content'] = bp_activity_thumbnail_content_images( $r['content'], $r['primary_link'], $r );
	}

	if ( ! empty( $r['action'] ) ) {

		/**
		 * Filters the action associated with activity for activity stream.
		 *
		 * @since BuddyPress (1.2.0)
		 *
		 * @param string $value Action for the activity stream.
		 */
		$r['action'] = apply_filters( 'bp_blogs_record_activity_action', $r['action'] );
	}

	if ( ! empty( $r['content'] ) ) {

		/**
		 * Filters the content associated with activity for activity stream.
		 *
		 * @since BuddyPress (1.2.0)
		 *
		 * @param string $value Generated excerpt from content for the activity stream.
		 * @param string $value Content for the activity stream.
		 * @param array  $r     Array of arguments used for the activity stream item.
		 */
		$r['content'] = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $r['content'] ), $r['content'], $r );
	}

	// Check for an existing entry and update if one exists.
	$id = bp_activity_get_activity_id( array(
		'user_id'           => $r['user_id'],
		'component'         => $r['component'],
		'type'              => $r['type'],
		'item_id'           => $r['item_id'],
		'secondary_item_id' => $r['secondary_item_id'],
	) );

	return bp_activity_add( array( 'id' => $id, 'user_id' => $r['user_id'], 'action' => $r['action'], 'content' => $r['content'], 'primary_link' => $r['primary_link'], 'component' => $r['component'], 'type' => $r['type'], 'item_id' => $r['item_id'], 'secondary_item_id' => $r['secondary_item_id'], 'recorded_time' => $r['recorded_time'], 'hide_sitewide' => $r['hide_sitewide'] ) );
}
예제 #30
0
 /**
  * @group bp_blogs_sync_activity_edit_to_post_comment
  * @group post_type_comment_activities
  */
 public function test_spammed_activity_comment_should_not_create_post_comment()
 {
     $old_user = get_current_user_id();
     $u = $this->factory->user->create();
     $this->set_current_user($u);
     $userdata = get_userdata($u);
     // let's use activity comments instead of single "new_blog_comment" activity items.
     add_filter('bp_disable_blogforum_comments', '__return_false');
     // create the blog post.
     $post_id = $this->factory->post->create(array('post_status' => 'publish', 'post_type' => 'post', 'post_title' => 'Test activity comment to post comment'));
     // Grab the activity ID for the activity comment.
     $a1 = bp_activity_get_activity_id(array('type' => 'new_blog_post', 'component' => buddypress()->blogs->id, 'filter' => array('item_id' => get_current_blog_id(), 'secondary_item_id' => $post_id)));
     // Set activity item to spam.
     add_action('bp_activity_before_save', array($this, 'set_activity_to_spam'));
     // Create spammed activity comment.
     $a2 = bp_activity_new_comment(array('content' => 'this activity comment shoud not be created as a new post comment. yolo.', 'user_id' => $u, 'activity_id' => $a1));
     // Grab post comments.
     $approved_comments = get_approved_comments($post_id);
     $comment = reset($approved_comments);
     // Assert that post comment wasn't created.
     $this->assertEmpty($comment);
     // Reset.
     remove_filter('bp_disable_blogforum_comments', '__return_false');
     remove_action('bp_activity_before_save', array($this, 'set_activity_to_spam'));
     $this->set_current_user($old_user);
 }