Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 17 replies - 1 through 17 (of 17 total)
  • Avatar of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Decided to give up modifying my existing plugin and just modify the Skeleton plugin that r-a-y recommended—much better idea. I now have the notification count displaying! No notification text but I’m pretty sure I’ll get there. Thanks all!

    Avatar of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Thanks everyone, I’m on my way. But, now I’m getting a 500 error on plugin activation. I replaced out the deprecated component creation function above with the following:

    define( 'BP_PCN_IS_INSTALLED', 1 );
    define( 'BP_PCN_PLUGIN_DIR', dirname( __FILE__ ) );

    /* Only load the component if BuddyPress is loaded and initialized. */
    function bp_pcn_init() {
    // Because the loader file uses BP_Component, it requires BP 1.5 or greater.
    if ( version_compare( BP_VERSION, '1.5', 'active_components[$this->id] = '1';

    }

    function setup_globals() {
    global $bp;

    // Defining the slug in this way makes it possible for site admins to override it
    if ( !defined( 'BP_PCN_SLUG' ) )
    define( 'BP_PCN_SLUG', $this->id );

    // Set up the $globals array to be passed along to parent::setup_globals()
    $globals = array(
    'slug' => BP_PCN_SLUG,
    'root_slug' => isset( $bp->pages->{$this->id}->slug ) ? $bp->pages->{$this->id}->slug : BP_PCN_SLUG,
    'has_directory' => false, // Set to false if not required
    'notification_callback' => 'bp_pcn_format_notifications'
    );

    // Let BP_Component::setup_globals() do its work.
    parent::setup_globals( $globals );

    }

    }

    /* load component into $bp global */
    function bp_pcn_load_core_component() {
    global $bp;

    $bp->pcn = new BP_PCN_Component;
    }
    add_action( 'bp_loaded', 'bp_pcn_load_core_component' );

    Anyone know what I’m missing?

    Avatar of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Are there any existing situations in the code I can look at?

    Avatar of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    It seems that screen notifications in Buddypress 1.6.1 are busted. I’ve been struggling with this for days,weeks,months—also found this: http://buddypress.org/support/topic/notifications-do-not-seem-to-work/ Can anyone confirm or deny?

    Avatar of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Okaaay, the plugin IS working. Does anyone know why an entry in wp_bp_notifications would not be showing up in notifications?

    entry in wp_bp_notifications:

    id user_id item_id secondary_item_id component_name component_action date_notified is_new

    196 4 209 0 pc_notifier new_post_comment_209 2012-12-07 17:08:16 1

    User id#3 is creating the comment and user id#4 is not receiving the notification in the top bar. Anyone know why?

    Avatar of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Ok, I think I’ve narrowed it down to this function in the plugin. I know that the function that it is hooking into works. Anyone know why this would fail?

    function pc_notifier_notify($activity_id) {
    global $bp;

    $activity = new BP_Activity_Activity($activity_id);
    $comment = get_comment($activity->secondary_item_id);
    $users = pc_notifier_find_involved_persons($comment->comment_post_ID);
    $link = get_permalink($comment->comment_post_ID);

    if($activity->hide_sitewide) return;

    if(!in_array($activity->user_id, $users)&&($bp->loggedin_user->id!=$activity->user_id)) array_push ($users, $activity->user_id);

    foreach((array)$users as $user_id){
    bp_core_add_notification( $activity_id, $user_id, $bp->pc_notifier->id, 'new_post_comment_'.$activity_id );
    }

    }
    add_action("bp_blogs_comment_recorded","pc_notifier_notify",10,1); // hook to bp_blogs_comment_recorded for adding notification

    Avatar of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Actually, this function is working—it is creating activity items based on blog posts and comments. I found out that it’s my custom plugin that is supposed to hook into this custom post or comment action to create a notification. Here is the plugin. I know no one will even try to tackle this but I have to post this because it’s my only option and I one for due diligence…

    /**
    * Plugin Name:BuddyPress Post Comment Notifier
    * Description: Mod of Brajesh Singh's BuddyPress Activity Comment Notifier to work for Blog Post Comments
    *
    */

    // we are not much concerned with the slug, it is not visible
    define("BP_COMMENT_NOTIFIER_SLUG","pc_notification");

    //register a dummy notifier component, I don't want to do it, but bp has no other mechanism for passing the notification data to function, so we need the format_notification_function
    function pc_notifier_setup_globals() {
    global $bp, $current_blog;
    $bp->pc_notifier=new stdClass();
    $bp->pc_notifier->id = 'pc_notifier';//I asume others are not going to use this is
    $bp->pc_notifier->slug = BP_COMMENT_NOTIFIER_SLUG;
    $bp->pc_notifier->notification_callback = 'pc_notifier_format_notifications';//show the notification
    /* Register this in the active components array */
    $bp->active_components[$bp->pc_notifier->slug] = $bp->pc_notifier->id;

    do_action( 'pc_notifier_setup_globals' );
    }
    add_action( 'bp_setup_globals', 'pc_notifier_setup_globals' );

    /**
    * storing notification for users
    * notify all the users who have commented, or who was the original poster of the update, when someone comments
    * hook to bp_blogs_comment_recorded action
    */
    function pc_notifier_notify($activity_id) {
    global $bp;

    $activity = new BP_Activity_Activity($activity_id);
    $comment = get_comment($activity->secondary_item_id);
    $users = pc_notifier_find_involved_persons($comment->comment_post_ID);
    $link = get_permalink($comment->comment_post_ID);

    if($activity->hide_sitewide) return;

    if(!in_array($activity->user_id, $users)&&($bp->loggedin_user->id!=$activity->user_id)) array_push ($users, $activity->user_id);

    foreach((array)$users as $user_id){
    bp_core_add_notification( $activity_id, $user_id, $bp->pc_notifier->id, 'new_post_comment_'.$activity_id );
    }

    }
    add_action("bp_blogs_comment_recorded","pc_notifier_notify",10,1); // hook to bp_blogs_comment_recorded for adding notification

    /** our notification format function which shows notification to user
    *
    * @global $bp
    * @param $action
    * @param $activity_id
    * @param $secondary_item_id
    * @param $total_items
    * @return
    * @since 1.0.2
    * @desc format and show the notification to the user
    */
    function pc_notifier_format_notifications( $action, $activity_id, $secondary_item_id, $total_items, $format='string' ) {

    global $bp;
    $glue = '';
    $user_names = array();
    $activity = new BP_Activity_Activity( $activity_id );
    $comment = get_comment($activity->secondary_item_id);
    $link = get_permalink($comment->comment_post_ID);
    $comment_post = get_post($comment->comment_post_ID);

    if ( $activity->user_id == $bp->loggedin_user->id ) $text = __("your post");
    else $text = sprintf(__("%s"), $comment_post->post_title);

    $pc_action = 'new_post_comment_'.$activity_id;

    if ( $action == $pc_action ) {

    $users = pc_notifier_find_involved_persons($comment->comment_post_ID);

    $total_user = $count = count($users);//how many unique users have commented

    if ( $count > 2 ) {
    $users = array_slice($users, $count-2);//just show name of two poster, rest should be as and 'n' other also commeted
    $count = $count-2;
    $glue=", ";
    }
    else if ( $total_user == 2 ) $glue = " and ";//if there are 2 unique users , say x and y commented

    foreach ( (array)$users as $user_id )
    $user_names[] = bp_core_get_user_displayname($user_id);

    if ( !empty($user_names) )
    $commenting_users = join($glue,$user_names);

    if ( $total_user > 2 )
    $text = $commenting_users." and ".$count." others commented on ".$comment_post->post_title;
    else
    $text = $commenting_users." commented on ".$comment_post->post_title;

    if ( $format == 'string' )
    return apply_filters('bp_activity_multiple_new_comment_notification','comment_ID.'">'.$text.'');
    else {
    $link .= '#comment-'.$comment->comment_ID;
    return array('link'=>$link,'text'=>$text);
    }

    }

    return false;

    }

    /*
    * Remove activity for the comments on new_blog_post & new_blog_comment activity item.
    * Since these items do not have a single activity view and are linked to the single post screen, we will do the needed on single post view
    */

    function pc_notifier_remove_notification_for_blog_posts(){
    if( !( is_user_logged_in() && is_singular() ) )
    return;

    global $bp,$wpdb;
    $blog_id = (int)$wpdb->blogid;
    $post = wp_get_single_post();
    $activity_id = bp_activity_get_activity_id(
    array(
    'user_id' => $post->post_author,
    'component' => $bp->blogs->id,
    'type' => "new_blog_post",
    'item_id' => $blog_id,
    'secondary_item_id' => $post->ID
    )
    );
    //delete the notification for activity comment on new_blog_post
    if( !empty($activity_id) )
    bp_core_delete_notifications_by_item_id( $bp->loggedin_user->id, $activity_id, $bp->pc_notifier->id, 'new_post_comment_'.$activity_id );

    //for replies on blog comments in activity stream
    $comments = pc_notifier_get_all_blog_post_comment_ids($post->ID);//get all the comment ids as array

    //added in v 1.0.3 for better database performance, no more looping to get individual activity ids
    $activities = pc_notifier_get_activity_ids(
    array(
    "type"=>"new_blog_comment",
    "component" => $bp->blogs->id,
    "item_id"=>$blog_id,
    "secondary_ids"=>$comments
    )
    );

    foreach( (array)$activities as $pc_id )
    bp_core_delete_notifications_by_item_id( $bp->loggedin_user->id, $pc_id, $bp->pc_notifier->id, 'new_post_comment_'.$pc_id );

    }
    add_action("wp_head","pc_notifier_remove_notification_for_blog_posts");

    /**
    * @since v 1.0.2
    * @desc delete notification when an activity is deleted, thanks to @kat_uk for pointing the issue
    * @param pc_ids:we get an arry of activity ids
    */
    function bp_pc_clear_notification_on_activity_delete($pc_ids){
    global $bp;

    foreach ( (array)$pc_ids as $activity_id )
    bp_core_delete_all_notifications_by_type( $activity_id, $bp->pc_notifier->id, 'new_post_comment_'.$activity_id, $secondary_item_id = false );
    }
    add_action("bp_activity_deleted_activities","bp_pc_clear_notification_on_activity_delete");

    /************************************ HELPER FUNCTIONS ********************************************************/

    // find all users who commented on the post
    function pc_notifier_find_involved_persons($comment_post_ID){
    global $bp,$wpdb;

    return $wpdb->get_col($wpdb->prepare("SELECT DISTINCT(user_id) from {$wpdb->comments} where comment_post_ID=%d and user_id!=%d",$comment_post_ID,$bp->loggedin_user->id));
    }

    // return an array of comment ids for the post
    function pc_notifier_get_all_blog_post_comment_ids($post_id) {
    global $wpdb;

    return $wpdb->get_col($wpdb->prepare("SELECT comment_ID as id FROM {$wpdb->comments} WHERE comment_post_ID = %d AND comment_approved = '1' ORDER BY comment_date", $post_id));
    }

    // get activity ids when type, component, secondary_ids, item_id is specified
    function pc_notifier_get_activity_ids($params){
    global $bp,$wpdb;
    extract($params);
    $list="(".join(",", $secondary_ids).")";//create a set to use in the query;

    return $wpdb->get_col($wpdb->prepare("SELECT id from {$bp->activity->table_name} where type=%s and component=%s and item_id=%d and secondary_item_id in {$list}",$type,$component,$item_id));
    }

    Avatar of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Anyone in the know with the new BP guts wanna take a crack at this? It may be a useful plugin…

    Avatar of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Yikes! Sorry, Bob, I just realized I was not subscribed to this thread. Anyway, the functions that I had gotten to work for creating activity notifications from actual blog comments (not activity comments) was working but is now broken. :\ Here is the new thread I have created to tackle this new situation. Feel free to add a “bump”. ;) http://buddypress.org/support/topic/help-me-fix-a-function-that-adds-blog-comments-to-activity/

    Avatar of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    I am experiencing the same thing. If I am logged in as an admin, I can see and visit any user’s settings—but not if I am logged in as an author. Also, I have a few modifications in bp-custom.php (bp_core_remove_subnav_item( 'settings', 'general' );,bp_core_new_nav_default(array('parent_slug' => $bp->settings->slug,'screen_function' => 'bp_core_screen_notification_settings','subnav_slug' => 'notifications'));) that are ignored on the “other user’s” ill-accessed settings nav.

    Avatar of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Holy shitake mushrooms…I’m an idiot. The user I’m working with didn’t have any values in any of the fields. Please ignore. Keep moving. Nothing to see here.

    Avatar of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    bp_profile_field_data(‘field=Company’); works in my desktop theme, not in mobile. I tried bp_member_profile_data(‘field=Company’);, still nothing.

    Avatar of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    I also am getting nothing with bp_profile_field_data. It is spitting out the values in my regular theme’s member-header.php but when I plunk it into the BPMobile theme, nothing. Any ideas?

    Avatar of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Thanks for the help Looper and Shane.
    I got it working!
    Had to redeclare some functions and modify an already existing plugin but it works…whew.

    Avatar of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Thanks for the reply Shane.
    The problem I’m having is reconciling the params that WP post comments use and the params that BP activity comments use.
    The simplest route (that I can glean) to get the functionality I want is to programmatically insert an activity post comment every time a comment is made on the actual post.
    So, how do I grab the necessary params from a regular post comment and pass them to a function that will create an activity post comment?
    I can (hopefully) figure out how to redirect the activity post comment to link to the post and not the activity item once I get this initial part working.
    (The reason I think faking an activity comment is so that I can utilize preexisting functions that find all the involved members that are commenting on the post, which only exist in BP activity and not in WP—correct me if I’m wrong)

    Avatar of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Thanks modemlooper.
    I have been looking though the code for over a month now and I’m getting nowhere.
    I am trying to modify the “BuddyPress Activity Comment Notifier” plugin to do what I want—it takes activity update comments and makes a screen notification for them.
    This is exactly what I want to do but for post comments, not activity update comments.
    A possible solution that I’m stuck on is how to trigger an activity comment when someone creates a post comment.
    Well, I’m stuck on everything; even how to approach this, and most likely, I’m going about this all wrong.
    If any kind soul can take a minute to provide details, it would be greatly appreciated—otherwise it might be nuts to the client.

    Avatar of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Anyone? Bueller?

Viewing 17 replies - 1 through 17 (of 17 total)