Skip to:
Content
Pages
Categories
Search
Top
Bottom

Buddypress Like – Notification Hack


  • bobemil
    Participant

    @bobemil

    I’m working on sending out screen notifications when a user likes my blog post. I’ve found some code that should work but doesn’t here: http://pastebin.com/r9cgigH5 (the hack begins at line 263 to 320 and also line 417 in the “bp_like_add_user_like” function).

    Is there anyone here that could give me some feedback for this hack? Should it work in theory?

    Update: It’s loaded into database but it’s not spitting it out to bp_adminbar_notifications_menu

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

  • meg@info
    Participant

    @megainfo

    the bp_like_send_notification function is commented ? mybe if your remove the // in line 564 it work


    bobemil
    Participant

    @bobemil

    No sorry, that was just a old test snippet that I forgot to delete from the source. Thanks for pointing it out!


    black key
    Participant

    @fadinho

    // the problem with your code:
    $bp->bp_like->slug = ‘bp_like’;
    ——————————————————
    function bp_like_setup_globals() {
    global $bp, $current_blog;
    $bp->bp_like=new stdClass();
    $bp->bp_like->id = ‘bp-like’;
    $bp->bp_like->slug = ‘bp_like’;
    $bp->bp_like->notification_callback = ‘bp_like_format_notifications’;
    $bp->active_components[$bp->bp_like->slug] = $bp->bp_like->id;
    do_action( ‘bp_like_setup_globals’ );
    }
    add_action( ‘bp_setup_globals’, ‘bp_like_setup_globals’ );

    function bp_like_format_notifications( $action, $item_id, $secondary_item_id, $total_items,$format=’string’) {
    global $bp;
    $glue=”;
    $user_names=array();
    $activity = new BP_Activity_Activity( $activity_id );
    $link=ac_notifier_activity_get_permalink2( $activity_id );

    //si c’est le posteur d’origine, dites que vous êtes, d’autre dire de% s après
    if($activity->user_id==$bp->loggedin_user->id){
    $text=__(“your”);
    $also=””;
    }
    else{
    $text=sprintf(__(“%s’s”), bp_core_get_user_displayname ($activity->user_id));//quelqu’un
    $also=” also”;
    }
    $ac_action=’new_bp_like_’.$item_id;

    if($action==$ac_action){
    //if ( (int)$total_items > 1 ) {
    // $users=ac_notifier_find_involved_persons($activity_id);
    $total_user= $count=count($users);//montrent de nombreux utilisateurs uniques ont commenté
    if($count>2){
    $users=array_slice($users, $count-2);//simplement indiquer le nom de deux affiches, le repos doit être aussi et ‘n’ autre a également commenté
    $count=$count-2;
    $glue=”, “;
    }
    else if($total_user==2)
    $glue=” xxxxxxxxx “;//si il ya 2 utilisateurs uniques, disons x et y commenté

    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.” xxxxxxxxxxxxxxxx “.$count.” xxxxxxxxx”.$also.” xxxxxxxxxxxxxxxx on “.$text. ” post”;//peut-on changer la poste à quelque chose de significatif en fonction de l’élément d’activité?
    else
    $text=$commenting_users.$also .” xxxxxxxxxxxx on “.$text. ” post”;

    if($format==’string’)
    return apply_filters( ‘bp_activity_multiple_new_likes_notification’, ‘‘ . $text . ‘‘);
    else{
    return array(‘link’=>$link,
    ‘text’=>$text);
    }
    return false;
    }

    }


    minto
    Participant

    @minto

    Best hack I could find, so far! (component works, database-entry work, notif appears – sometimes)
    Some few issues though…
    see pastebin..

    1. The Notification appears in the bar, but firstly it appears in the likers-notifications (quite earlier than in the liked-profile)

    2. Theres no text/link, the Notifs are empty

    3. In the likers-notifs, the live-notification(-plugin) appears (but also without text), but this doesnt happen on the liked-profile (with no appearing “notifications”-wording, right before the count + with no live-notification-popup)

    Would be great to have some more explanation!

    Thank you very much!


    minto
    Participant

    @minto

    edit:

    The text from “users who like / who likes this” also disappeared..


    minto
    Participant

    @minto

    @bobemil + @fadinho

    would it be possible that you paste the working code?
    because even my corrections of BP_LIKE_SLUG did not work..


    minto
    Participant

    @minto

    Here’s what I did meanwhile:

    1. removed all those junkcode, I had originally in 😉

    2. found that display-issue in the above + corrected it in the code, which seemed responsible for no text/ no links being given (I inserted the missing a-href):
    return apply_filters( ‘bp_activity_multiple_new_likes_notification’, ‘‘ . $text . ‘‘);
    … but this also did not bring up the link + text …

    3. wonder about that line:
    $link=ac_notifier_activity_get_permalink2( $activity_id );
    …removed the “2”, because with that in, my toolbar disappears…
    Should that be noticed in the ac_notifier too, with the need to keep the “2”?

    4. any notifications (even the live-notification-popup) still only appear on the likers-side, still not yet on the liked-user-profile!

    So this is, what it looks like atm:

    
    function bp_like_setup_globals() {
    global $bp, $current_blog;
    $bp->bp_like=new stdClass();
    $bp->bp_like->id = 'bp-like';
    $bp->bp_like->slug = 'bp_like';
    $bp->bp_like->notification_callback = 'bp_like_format_notifications';
    $bp->active_components[$bp->bp_like->slug] = $bp->bp_like->id;
    do_action( 'bp_like_setup_globals' );
    }
    add_action( 'bp_setup_globals', 'bp_like_setup_globals' );
    
    function bp_like_format_notifications( $action, $item_id, $secondary_item_id, $total_items,$format='string') {
    global $bp;
    $glue='';
    $user_names=array();
    $activity = new BP_Activity_Activity( $activity_id );
    $link=ac_notifier_activity_get_permalink( $activity_id );
    
    //si c’est le posteur d’origine, dites que vous êtes, d’autre dire de% s après
    if($activity->user_id==$bp->loggedin_user->id){
    $text=__("your");
    $also="";
    }
    else{
    $text=sprintf(__("%s’s"), bp_core_get_user_displayname ($activity->user_id));//quelqu’un
    $also=" also";
    }
    $ac_action='new_bp_like_'.$item_id;
    
    if($action==$ac_action){
    // if ( (int)$total_items > 1 ) {
    // $users=ac_notifier_find_involved_persons($activity_id);
    $total_user=$count=count($users);//montrent de nombreux utilisateurs uniques ont commenté
    if($count>2){
    $users=array_slice($users, $count-2);//simplement indiquer le nom de deux affiches, le repos doit être aussi et ‘n’ autre a également commenté
    $count=$count-2;
    $glue=", ";
    }
    else if($total_user==2)
    $glue=" xxxx1xxxx ";//si il ya 2 utilisateurs uniques, disons x et y commenté
    
    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." xxxxxxxx2xxxxxxx ".$count." xxxx3xxxx".$also." xxxxxxxx4xxxxxxx on ".$text." post";//peut-on changer la poste à quelque chose de significatif en fonction de l’élément d’activité?
    else
    $text=$commenting_users.$also." xxxxxx5xxxxx on ".$text." post";
    
    if($format=='string')
    return apply_filters( 'bp_activity_multiple_new_likes_notification', '<a href="'.$link.'">'.$text.'</a>');
    else{
    return array('link'=>$link,
    'text'=>$text);
    }
    return false;
    }
    
    }
    

    any suggestions?

    thx in advance!


    minto
    Participant

    @minto

    Now I’ve put this in, but it still doesn’t work out:

    ‘//get the thread permalink for activity
    function ac_notifier_activity_get_permalink2( $activity_id, $activity_obj = false ) {
    global $bp;

    if ( !$activity_obj )
    $activity_obj = new BP_Activity_Activity( $activity_id );

    if ( ‘activity_comment’ == $activity_obj->type )
    $link = bp_get_activity_directory_permalink(). ‘p/’ . $activity_obj->item_id . ‘/’;
    else
    $link = bp_get_activity_directory_permalink() . ‘p/’ . $activity_obj->id . ‘/’;

    return apply_filters( ‘ac_notifier_activity_get_permalink2′, $link );
    }’


    minto
    Participant

    @minto

    still looking for a solution!


    Carco
    Participant

    @carco

    function bp_like_check_installed() {
    global $wpdb;

    if ( !is_site_admin() )
    return false;

    if ( !get_site_option( ‘bp_like_settings’ ) || get_site_option( ‘bp-like-db-version’ ) )
    bp_like_install();

    if ( get_site_option( ‘bp_like_db_version’ ) < BP_LIKE_DB_VERSION )
    bp_like_install();
    }
    add_action( ‘admin_menu’, ‘bp_like_check_installed’ );
    add_action( ‘network_admin_menu’, ‘bp_like_check_installed’ );

    /**
    * for notifications
    */

    function bp_like_setup_globals() {
    global $bp, $current_blog;
    $bp->bp_like=new stdClass();
    $bp->bp_like->id = ‘bp-like’;
    $bp->bp_like->slug = ‘bp_like’;
    $bp->bp_like->notification_callback = ‘bp_like_format_notifications’;
    $bp->active_components[$bp->bp_like->slug] = $bp->bp_like->id;
    do_action( ‘bp_like_setup_globals’ );
    }
    add_action( ‘bp_setup_globals’, ‘bp_like_setup_globals’ );

    function bp_like_format_notifications( $action, $item_id, $secondary_item_id, $total_items,$format=’string’) {
    global $bp;
    $glue=”;
    $user_names=array();
    $activity = new BP_Activity_Activity( $item_id );
    $link=like_notifier_activity_get_permalink( $item_id );

    if($activity->user_id==$bp->loggedin_user->id){
    $text=__(“your”);
    $also=””;
    }
    else{
    $text=sprintf(__(“%s’s”), bp_core_get_user_displayname ($activity->user_id));//somone’s
    $also=” also”;
    }

    $users = array_keys( bp_activity_get_meta( $item_id, ‘liked_count’ ) );
    $total_user= $count=count($users);

    if ($count==0){
    bp_core_delete_notifications_by_item_id( $bp->loggedin_user->id, $activity->id, $bp->bp_like->slug, ‘new_bp_like_’.$activity->id);
    }

    if($count>2){
    $users=array_slice($users, $count-2);
    $count=$count-2;
    $glue=”, “;
    }

    else if($total_user==2)
    $glue=” and “;

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

    if(!empty($user_names))
    $commenting_users=join ($glue, $user_names);
    else
    $commenting_users=”Somebody remove it after”;

    if($total_user>2)
    $text=$commenting_users.” and “.$count.” others”.$also.” liked on “.$text. ” post”;
    else
    $text=$commenting_users.$also .” liked on “.$text. ” post”;

    return array(‘link’=>$link,
    ‘text’=>$text);

    }

    function like_notifier_activity_get_permalink( $activity_id, $activity_obj = false ) {
    global $bp;

    if ( !$activity_obj )
    $activity_obj = new BP_Activity_Activity( $activity_id );

    $link = bp_get_activity_directory_permalink() . ‘p/’ . $activity_obj->id . ‘/’;

    return apply_filters( ‘like_notifier_activity_get_permalink’, $link );
    }

    function like_notifier_remove_notification($activity,$has_access){
    global $bp;
    if($has_access)
    bp_core_delete_notifications_by_item_id( $bp->loggedin_user->id, $activity->id, $bp->bp_like->slug, ‘new_bp_like_’.$activity->id);

    }
    add_action(“bp_activity_screen_single_activity_permalink”,”like_notifier_remove_notification”,10,2);

    ….

    bp_core_add_notification( $item_id, $activity[‘activities’][0]->user_id, $bp->bp_like->slug, ‘new_bp_like_’.$item_id );


    minto
    Participant

    @minto

    @carco
    nice hack, as i could say intuitively! 😀

    but for some reason still no notifs appearing!
    + the user_id-tables in the database give 0 for all entries!

    thx anyway!


    minto
    Participant

    @minto

    as i just found out, also the “show-users-who-like”-display doesnt
    work anymore, in this setup..


    Carco
    Participant

    @carco

    all right on my site
    here is the complete code
    maybe this will help

    http://pastebin.com/LiyXA2WS


    minto
    Participant

    @minto

    Thanks for pasting, @carco

    Strangewise the issue remains, even with your entire script.
    Still no entries for user_id in db
    (which then might cause, that no notifs appear, probably?)
    but “users-who-like” works again^^

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Buddypress Like – Notification Hack’ is closed to new replies.
Skip to toolbar