• Hi all. I hope this help to solve the known issue.

    To add the groups’ blog posts to activity stream I first set the group id as a blog option throw $meta when creating a new blog with wpmu_create_blog on bp-groupblog.php (lines 756 and 782). (Will be good create a function to do this to all groups that already have blogs).

    Then I added the follow to the bp-groupblog.php (I use “get_option( ‘group_id’ )” to get the info I added above):

    function bp_groupblog_record_publish_post_activity( $post_id ) {
    	global $bp;
    
    	$post = get_post( $post_id );
    
    	$group_id = get_option( 'group_id' );
    	if ( !$group_id ) return;
    	$group = new BP_Groups_Group( $group_id, true );
    
    	$activity_action = sprintf( __( '%s published the post %s in the group %s:', 'buddypress'), 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_content = bp_create_excerpt( $post->post_content );
    
    	/* Record this in activity streams */
    	$r = groups_record_activity( array(
    		'action' => apply_filters( 'bp_blogs_activity_new_grouppost_action', $activity_action, $post->post_content, &$post ),
    		'content' => apply_filters( 'bp_blogs_activity_new_grouppost_content', $activity_content, $post->post_content, &$post ),
    		'primary_link' => apply_filters( 'bp_blogs_activity_new_grouppost_primary_link', get_permalink( $post->ID ) ),
    		'type' => 'new_groupblog_post',
    		'item_id' => $group_id,
    		'secondary_item_id' => $post->post_author,
    		'hide_sitewide' => 0
    	) );
    
    }
    add_action( 'publish_post', 'bp_groupblog_record_publish_post_activity' );

    That’s all.

    http://wordpress.org/extend/plugins/bp-groupblog/

Viewing 13 replies - 1 through 13 (of 13 total)
  • Wow…excellent, can’t wait to give it spin after dinner! Thanks for collaborating Luiz.

    Luiz, we actually have a template function for that, get_groupblog_group_id( $blog_id ), so no need to hook into meta.

    Only now there is still the original post recorded in the activity stream. This causes duplicates in the sitewide stream. We could set hide_sitewide to true, but that would fork comments and activity post interaction.

    The best way is to delete the original activity item and let the new group activity item be the boss. I tried a few things, but am overlooking something.

    Do you see anthing:

    /**
     * bp_groupblog_record_publish_post_activity( $post_id )
     *
     * Record the blog activity for the group.
     */
    function bp_groupblog_record_publish_post_activity( $post_id ) {
    	global $bp, $blog_id;
    
    	$post = get_post( $post_id );
    
    	$group_id = get_groupblog_group_id( $blog_id );
    	if ( !$group_id ) return;
    	$group = new BP_Groups_Group( $group_id, true );
    
    	$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_content = bp_create_excerpt( $post->post_content );
    
    	/* Record this in activity streams */
    	$r = groups_record_activity( array(
    		'action' => apply_filters( 'bp_blogs_activity_new_grouppost_action', $activity_action, $post->post_content, &$post ),
    		'content' => apply_filters( 'bp_blogs_activity_new_grouppost_content', $activity_content, $post->post_content, &$post ),
    		'primary_link' => apply_filters( 'bp_blogs_activity_new_grouppost_primary_link', get_permalink( $post->ID ) ),
    		'type' => 'new_groupblog_post',
    		'item_id' => $group_id,
    		'secondary_item_id' => $post->post_author,
    		'hide_sitewide' => 0
    	) );
    
    	// Delete activity stream item
    	bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) );
    
    }
    add_action( 'publish_post', 'bp_groupblog_record_publish_post_activity' );
    add_action( 'bp_blogs_remove_post', 'bp_groupblog_record_publish_post_activity' );
    Thread Starter luiz-armesto

    (@luiz-armesto)

    That’s true, with that function we duplicate the entry. I tried to remove the original one, but it will break the “Recent Site Wide Posts” widget.

    Then I used a new approach, ‘why create a new one and remove the original if we can modify the original?’

    So, my new suggestion is to remove and forget the previous function I sent and try this

    /**
     * bp_groupblog_set_group_to_post_activity ( $activity )
     *
     * Record the blog activity for the group.
     */
    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 = new BP_Groups_Group( $group_id, true );
    
    	// 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 = $group_id;
    	$activity->component = 'groups';
    	$activity->hide_sitewide = 0;
    
    }
    add_action( 'bp_activity_before_save', 'bp_groupblog_set_group_to_post_activity');

    Edit: *** Issue fixed ***

    Luiz Armesto who are YOU! You are truly amazing, are you active with BuddyPress in any other way? I’m very impressed, thanks for helping out with this major issue. This will appear in the next update along with other new features and themes.

    I will also make sure to give you credit for this find.

    Greetz,

    Marius Ooms

    Thread Starter luiz-armesto

    (@luiz-armesto)

    Hi Marius Ooms. I’m a Brazilian developer who started to use BuddyPress and WordPress two months ago to implement the social networking site to one local project. Until now I was working creating a theme and studying the BuddyPress/WordPress API and source code.

    I’m not active in BuddyPress community yet, but I’m willing to give back to community all improvements and fixes done by the team I’m working with. As the integration between blogs and groups is a important feature to our project this was the first contribution.

    I’ll credit the team member who worked on each contribution I’ll send, and encourage them to publish their own improvements, but this was done by myself 😀

    By the way, you will have a Brazilian Portuguese translation for this plugin soon.

    Cheers

    Thanks for the work and your team, it is a blessing! You’ll be glad to hear that we have lots of improvements, new features and theme updates coming within the week. I think you will really like it. You will probably want to wait for the new pot file as well regarding translation.

    Let me know if you find any more issues or would like other things implemented and we will look at them.

    Greetz

    Thread Starter luiz-armesto

    (@luiz-armesto)

    Great news. I’ll be waiting the new release 😀

    Sorry to exhume this.
    I’m wondering how I might go about adapting this so that the blog posts of members of a group (that is, posts to their own blogs, not the group blog) are also integrated into the activity stream?

    By the way, I posted a fix to the groupblog subdomain issue over on the buddypress site.

    @lemmy Thanks for providing a fix, I’m really interested to find out how you fixed it. I could not find a fix over on BuddyPress. Do you have a link for me?

    Thanks

    Yes, there is a thread here:
    http://buddypress.org/community/groups/bp-groupblog/forum/topic/fix-for-subdomains/

    In short, the blog name is not available from the path value when using subdomains – it’s necessary to get it from the domain value instead.

    By the way, I’ve customised the External Blog plugin to easily add feeds from all the group members’ blogs. They’re displayed as a list with checkboxes, in addition to the standard text box for external feeds. If anyone’s interested, let me know.
    I’ve excluded any blogs which are also group blogs – as I’m worried about groups getting feeds from other groups in case a feedback loop is set up. (i.e. groups are subscribed to each other.) I’m not sure what would happen but I’m guessing that the internet would eat itself.

    Thanks Lemmy…works like a charm. The new code is included in the latest release.

    Excellent, thanks.

    Thanks a ton Lemmy, i am planning to convert my ‘consumer complaints’ wordpress website curently running on Answers theme to buddypress. Hope to convert it soon, following is the current website http://econsumercomplaints.in

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Plugin: BuddyPress Groupblog] Adding an entry to group activity stream.’ is closed to new replies.