Exemplo n.º 1
0
 /**
  * @ticket BP4488
  */
 public function test_thumbnail_content_images()
 {
     // No images
     $post_content = 'foo bar';
     $this->assertEquals(bp_activity_thumbnail_content_images($post_content), 'foo bar');
     // Image first, no caption. See #BP4488
     $post_content = '<img src="http://example.com/foo.jpg" alt="foo" width="40" height="40" class="alignnone size-full wp-image-236" /> foo bar';
     $this->assertEquals(bp_activity_thumbnail_content_images($post_content), '<img src="http://example.com/foo.jpg" width="40" height="40" alt="Thumbnail" class="align-left thumbnail" /> foo bar');
     // Image first, caption. See #BP4488
     $post_content = '[caption id="attachment_236" align="alignnone" width="40"]<img src="http://example.com/foo.jpg" alt="FOO!" width="40" height="40" class="size-full wp-image-236" /> FOO![/caption] Awesome.';
     $this->assertEquals(bp_activity_thumbnail_content_images($post_content), '<img src="http://example.com/foo.jpg" width="40" height="40" alt="Thumbnail" class="align-left thumbnail" /> Awesome.');
 }
Exemplo n.º 2
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));
}
Exemplo n.º 3
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'] ) );
}
Exemplo n.º 4
0
 /**
  * Add or edit activities so that they are private
  *
  * @package WP Idea Stream
  * @subpackage buddypress/activity
  *
  * @since 2.0.0
  *
  * @param  int     $idea_id     the idea ID
  * @param  WP_Post $idea        the idea object
  * @uses   get_post()           to get the idea object if not set
  * @uses   WP_Idea_Stream_Activity->get_idea_and_comments() to get activities to manage
  * @uses   self::bulk_edit_activity to mark activities as private
  * @uses   get_current_blog_id() to get the current blog ID
  * @uses   buddypress() to get BuddyPress instance
  * @uses   add_query_arg(), get_home_url() to build the link to the idea.
  * @uses   bp_activity_thumbnail_content_images() to take content, remove images, and replace them with a single thumbnail image
  * @uses   bp_create_excerpt() to generate the content of the activity
  * @uses   bp_activity_add() to save the private activity
  * @uses   apply_filters() call 'bp_blogs_record_activity_content' to apply the filters on blog posts for private ideas
  *                         call 'wp_idea_stream_buddypress_activity_post_private' to override the private activity args
  */
 public function mark_activity_private($idea_id = 0, $idea = null)
 {
     if (empty($idea)) {
         $idea = get_post($idea_id);
     }
     // Get activities
     $activities = $this->get_idea_and_comments($idea_id, $idea->post_status);
     // If activities, then update their visibility status
     if (!empty($activities)) {
         // Do not update activities if they all are already marked as private.
         if (!empty($this->private_activities[$idea_id]) && !array_diff($activities, $this->private_activities[$idea_id])) {
             return;
         }
         self::bulk_edit_activity($activities, 1);
         // Otherwise, we need to create the activity
     } else {
         /**
          * Here we can't use bp_blogs_record_activity() as we need
          * to allow the groups component to eventually override the
          * component argument. As a result, we need to set a fiew vars
          */
         $bp = buddypress();
         $bp_activity_actions = new stdClass();
         $bp_activity_actions = $bp->activity->actions;
         // First the item id: the current blog
         $blog_id = get_current_blog_id();
         // Then all needed args except content
         $args = array('component' => buddypress()->blogs->id, 'type' => 'new_' . $this->post_type, 'primary_link' => add_query_arg('p', $idea_id, trailingslashit(get_home_url($blog_id))), 'user_id' => (int) $idea->post_author, 'item_id' => $blog_id, 'secondary_item_id' => $idea_id, 'recorded_time' => $idea->post_date_gmt, 'hide_sitewide' => 1);
         // The content will require to use functions that bp_blogs_record_activity()
         // is using to format it.
         $content = '';
         if (!empty($idea->post_content)) {
             $content = bp_activity_thumbnail_content_images($idea->post_content, $args['primary_link'], $args);
             $content = bp_create_excerpt($content);
         }
         // Add the content to the activity args
         $args['content'] = $content;
         /**
          * Filter is used internally to override ideas posted within a private or hidden group
          *
          * @param array   $args    the private activity arguments
          * @param WP_Post $idea    the idea object
          */
         $args = apply_filters('wp_idea_stream_buddypress_activity_post_private', $args, $idea);
         // Define the corresponding index
         $activity_type = $args['type'];
         $activity_component = $args['component'];
         // override the activity type
         $args['type'] = $this->activity_actions[$activity_type]->type;
         if (empty($bp->activity->actions->{$activity_component}->{$activity_type}['format_callback'])) {
             bp_activity_set_action($this->activity_actions[$activity_type]->component, $this->activity_actions[$activity_type]->type, $this->activity_actions[$activity_type]->admin_caption, $this->activity_actions[$activity_type]->action_callback);
         }
         /**
          * Finally publish the private activity
          * and reset BuddyPress activity actions
          */
         $private_activity_id = bp_activity_add($args);
         // Check for comments
         if (!empty($private_activity_id)) {
             $activities = $this->get_idea_and_comments($idea_id, $idea->post_status);
             $activities = array_diff($activities, array($private_activity_id));
             // Update comments visibility
             if (!empty($activities)) {
                 $test = self::bulk_edit_activity($activities, 1);
             }
         }
         $bp->activity->actions = $bp_activity_actions;
         // Reset edited activities
         $this->edit_activities = array();
     }
 }
Exemplo n.º 5
0
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 ) );
}
/**
 * Update the activity item for a custom post type entry.
 *
 * @since BuddyPress (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 ) {
	$bp = buddypress();

	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 ) ) {
		// Make sure to update the thumbnail image.
		$post_content = bp_activity_thumbnail_content_images( $post->post_content, $activity->primary_link, (array) $activity );

		// Generate an excerpt.
		$activity_excerpt = bp_create_excerpt( $post_content );

		// Backward compatibility filter for the blogs component.
		if ( 'blogs' == $activity_post_object->component_id ) {
			$activity->content = apply_filters( 'bp_blogs_record_activity_content', $activity_excerpt, $post_content, (array) $activity, $post->post_type );
		} else {
			$activity->content = $activity_excerpt;
		}
	}

	// Save the updated activity.
	$updated = $activity->save();

	/**
	 * Fires after the updating of an activity item for a custom post type entry.
	 *
	 * @since BuddyPress (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;
}
Exemplo n.º 7
0
/**
 * Updates a blog post's corresponding activity entry during a post edit.
 *
 * @since BuddyPress (2.0.0)
 *
 * @see bp_blogs_catch_transition_post_status()
 *
 * @param WP_Post $post
 */
function bp_blogs_update_post($post)
{
    if (!bp_is_active('activity')) {
        return;
    }
    $activity_id = bp_activity_get_activity_id(array('component' => buddypress()->blogs->id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $post->ID, 'type' => 'new_blog_post'));
    // activity ID doesn't exist, so stop!
    if (empty($activity_id)) {
        return;
    }
    // update the activity entry
    $activity = new BP_Activity_Activity($activity_id);
    if (!empty($post->post_content)) {
        // Make sure to update the thumbnail image
        $post_content = bp_activity_thumbnail_content_images($post->post_content, $activity->primary_link, (array) $activity);
        // Make sure to apply the blop post excerpt
        $activity->content = apply_filters('bp_blogs_record_activity_content', bp_create_excerpt($post_content), $post_content, (array) $activity);
    }
    // Save the updated activity
    $activity->save();
    // update post title in activity meta
    $existing_title = bp_activity_get_meta($activity_id, 'post_title');
    if ($post->post_title !== $existing_title) {
        bp_activity_update_meta($activity_id, 'post_title', $post->post_title);
        // now update activity meta for post comments... sigh
        add_filter('comments_clauses', 'bp_blogs_comments_clauses_select_by_id');
        $comments = get_comments(array('post_id' => $post->ID));
        remove_filter('comments_clauses', 'bp_blogs_comments_clauses_select_by_id');
        if (!empty($comments)) {
            $activity_ids = array();
            $comment_ids = wp_list_pluck($comments, 'comment_ID');
            // setup activity args
            $args = array('update_meta_cache' => false, 'show_hidden' => true, 'per_page' => 99999);
            // query for old-style "new_blog_comment" activity items
            $args['filter'] = array('object' => buddypress()->blogs->id, 'action' => 'new_blog_comment', 'secondary_id' => implode(',', $comment_ids));
            $activities = bp_activity_get($args);
            if (!empty($activities['activities'])) {
                $activity_ids = (array) wp_list_pluck($activities['activities'], 'id');
            }
            // query for activity comments connected to a blog post
            unset($args['filter']);
            $args['meta_query'] = array(array('key' => 'bp_blogs_post_comment_id', 'value' => $comment_ids, 'compare' => 'IN'));
            $args['type'] = 'activity_comment';
            $args['display_comments'] = 'stream';
            $activities = bp_activity_get($args);
            if (!empty($activities['activities'])) {
                $activity_ids = array_merge($activity_ids, (array) wp_list_pluck($activities['activities'], 'id'));
            }
            // update activity meta for all found activity items
            if (!empty($activity_ids)) {
                foreach ($activity_ids as $aid) {
                    bp_activity_update_meta($aid, 'post_title', $post->post_title);
                }
            }
            unset($activities, $activity_ids, $comment_ids, $comments);
        }
    }
    // add post comment status to activity meta if closed
    if ('closed' == $post->comment_status) {
        bp_activity_update_meta($activity_id, 'post_comment_status', $post->comment_status);
    } else {
        bp_activity_delete_meta($activity_id, 'post_comment_status');
    }
}
Exemplo n.º 8
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'])) {
        $r['action'] = apply_filters('bp_blogs_record_activity_action', $r['action']);
    }
    if (!empty($r['content'])) {
        $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']));
}