Skip to:
Content
Pages
Categories
Search
Top
Bottom

Activity stream commenting

  • Avatar of Marcella
    Marcella
    Participant

    @marcella1981

    Wondering if anyone has a step by step guide on how to enable activity stream commenting without AJAX?

    Having followed the instructions in /developer-docs/custom-buddypress-loops/the-activity-stream-loop/

    Still no joy. When submitting a comment it redirects the form submission to the url domain.com/activity/reply/

    Having compared the bp-default theme activity stream activity/post-form.php output to the this child theme there are no differences.

    Also, took a look at the the bp-default theme with JS disabled and looks like it doesn’t work under these conditions at all.

    Since activity/reply/ returns a 404 my knowledge peaks here without seeing which function runs. Any help would be immensely appreciated.

    Thanks

    *Edit* Also just noticed the edit forum topic form is missing some padding left and right here.

Viewing 25 replies - 1 through 25 (of 35 total)
  • Avatar of Marcella
    Marcella
    Participant

    @marcella1981

    *bump* help please :(

    Avatar of Marcella
    Marcella
    Participant

    @marcella1981

    *nudge*

    Avatar of Marcella
    Marcella
    Participant

    @marcella1981

    Have done some further digging and keep hitting the 404 issue.

    The same issue is effected when adding a user as a friend, joining a group and favoriting.

    Have created a quick and dirty button generator function that can be used throughout this WordPress theme.

    However with the dead landing page these will never work. Are there any other approaches considered a best practice?

    I’ve not seen any such guide, and since it would require someone to figure out it for you, you probably won’t get a quick response. I know one of the core developers of BuddyPress is keen on non -Ajax support, so if it doesn’t work in BPDefault, submit it as an issue to the BuddyPress trac.

    Avatar of Marcella
    Marcella
    Participant

    @marcella1981

    Thanks for the heads up, guess that’s all the clarification was needing.

    Do you know who worked on the activity streams? Maybe they’ll be able to share some inverse knowledge.

    Will take a look for this item in trac, and post solution if found.

    Avatar of Marcella
    Marcella
    Participant

    @marcella1981

    @djpaul it’s already in trac :)

    In ajax.php there is a function

    `function bp_dtheme_new_activity_comment()`

    On line 194

    `check_admin_referer( ‘new_activity_comment’, ‘_wpnonce_new_activity_comment’ );`

    In activity/entry.php The Nonce matches here.

    In buddypress/bp-activity/bp-activity-functions.php Line 912
    function `function bp_activity_new_comment()`

    Which later calls on line 937

    `bp_activity_add($args)`

    $args being sent from the form.

    Within the same file there is the function above which preps the data by merging and ostracising into var names.

    It then used the BP_Activity_Activity class located in buddypress/activity/bp-activity-classes.php

    and checks if the data could not be saved otherwise return the id of the entry.

    BP_Activity_Activity instantiates all expected parameters initially with the id if passed. (i’m guessing for an output method).

    Saving is the issue here and the method save() on line 62 has 3 global vars $wpdb, $bp and $current_user.

    Saving allows for additional filters (to which extent is beyond me here) (… along with the rest).

    *gets hairier here

    Then…
    It checks if some specific filters failed to return a value and if so returns false.
    It checks for more specific filter return values and if false sets them to that of the matched user. (primary_link) specifically. How this is used in saving, can only hazard a guess that it’s for outputing a url to the activity stream for permalink.php

    http://site.com/members/admin/activity/6060842 for example.

    Then using WPDB inserts or updates accordingly.

    Maybe we can gain some movement with this here.

    Anyone else please do chime in with corrections of the above PSEUDO interpretation, where to go from here is the next one.

    Avatar of Marcella
    Marcella
    Participant

    @marcella1981

    Wondering if we can migrate the fore-mentioned into a single-file.php temporarily and set the activity entry form action to the current page and call accordingly? (Which totally goes against the DRY principles, jquery.delegate has its bugs too. ahhhh)

    Will give it a whirl tomorrow.

    Avatar of Alex Githatu
    Alex Githatu
    Participant

    @kalengi

    Hey @Marcella, are you still stuck on this? If so, what’s the structure of your code/pages so far? I may be able to help…

    @Marcella You are way ahead of me in code but I am having the same trouble commenting on any posts using the defalut bp theme. just the form submission to the url domain.com/activity/reply/404 error.

    @kalengi Whats the best way to start?

    What about permalinks?
    Looks like I’m in Numeric and should be Default
    In Default commenting works
    But in Numeric they give me a page not found

    Avatar of Marcella
    Marcella
    Participant

    @marcella1981

    @kalengi – Hello, this is a child theme so the file structure adheres to anything in bp-default.
    So… accessing the stream via the url .

    site.com/activity

    using the file

    theme/activity/index.php

    Calling the loop from index.php

    theme/activity/activity-loop.php

    Calling an entry from within the loop

    theme/activity/entry.php

    Omitting header.php the full loop looks like this.

    `

    <form action="” method=”post”>

    <textarea name="ac_input_”>
    <input type="submit" name="ac_form_submit" class="submit" value="” />
    <input type="hidden" name="comment_form_id" value="” />

    `

    That’s being sent to the 404.

    @allwest – I think this is a known issue, it’s listed over in Trac http://buddypress.trac.wordpress.org/ticket/3705

    `

    Avatar of rokugatsu
    rokugatsu
    Member

    @rokugatsu

    I have the same error when the users reply comments…what is solution? Thanks!

    Avatar of Alex Githatu
    Alex Githatu
    Participant

    @kalengi

    @Marcella, I’ve posted code, but it’s not showing up so I guess there’s something I’m missing or it’s being held for moderation.

    Avatar of Marcella
    Marcella
    Participant

    @marcella1981

    Ah not sure man.

    Avatar of Alex Githatu
    Alex Githatu
    Participant

    @kalengi

    Every time I try to post the comment I get the message “It looks like you’ve already said that! ” and yet nothing is showing. So where is it!

    Avatar of Marcella
    Marcella
    Participant

    @marcella1981

    Bermuda? lol

    Avatar of Alex Githatu
    Alex Githatu
    Participant

    @kalengi

    hahaa! It could as well be.Let me see if splitting up the message sort it out:

    First part:
    It’s my understanding that the problem is arising from the form submitting to /activity/reply/ which isn’t recognized by WordPress and therefore causing the 404. Here’s some code to address that. The idea is to have WordPress accept /reply/ as a valid destination by getting BuddyPress to pick it up as an action.

    Avatar of Alex Githatu
    Alex Githatu
    Participant

    @kalengi

    Second part:
    1. Create the file theme/activity/reply.php and put in the following code:



    global $bp;

    // Check the nonce
    check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );

    if ( !is_user_logged_in() ) {
    bp_core_add_message( __( 'You must be logged in to post a comment', 'buddypress' ), 'error' );
    }
    else {
    if ( empty( _POST ) ) {
    bp_core_add_message( __( 'You left out the comment.', 'buddypress' ), 'error' );
    }
    else {
    if ( empty( _POST ) || !is_numeric( _POST ) ) {
    bp_core_add_message( __( 'There was an error posting that reply, please try again.', 'buddypress' ), 'error' );
    }
    else {
    $comment_id = bp_activity_new_comment( array(
    'activity_id' => _POST,
    'content' => _POST,
    'parent_id' => _POST
    ) );

    if ( !$comment_id ) {
    bp_core_add_message( __( 'There was an error posting that reply, please try again.', 'buddypress' ), 'error' );
    }
    else {
    bp_core_add_message( __( 'Comment posted successfully', 'buddypress' ) );
    }
    }
    }
    }


    2. In functions.php, add the function:



    function bp_activity_action_add_activity_comment( ) {
    global $bp;

    // Not viewing activity or action is not delete
    if ( !bp_is_activity_component() || !bp_is_current_action( 'reply' ) )
    return false;

    locate_template( array( 'activity/reply.php' ), true );

    bp_core_redirect( wp_get_referer() );

    }
    add_action( 'bp_actions', 'bp_activity_action_add_activity_comment' );

    Avatar of Alex Githatu
    Alex Githatu
    Participant

    @kalengi

    So I finally cracked what’s ailing this forum’s comment posting code :) If you include a properly referenced superglobal variable in your comment content, then the system just replies with “It looks like you’ve already said that! ”

    Anyway, in the code that I’ve posted above, you’ll need to replace all occurrences of _POST with the proper superglobal variable reference.

    Avatar of Marcella
    Marcella
    Participant

    @marcella1981

    @davidveldt now this is a considered post http://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/activity-stream-commenting/?topic_page=2&num=15#post-121548

    Thanks @kalengi have to go to the job centre, will let you know how this works out later today.

    Many many thanks!

    Avatar of Marcella
    Marcella
    Participant

    @marcella1981

    Dude, thank you thank you! This is ace.

    Followed your train of thought to the actions and methods involved. Applied the filters as advised in core.

    `global $bp;

    if(!is_user_logged_in()) :

    bp_core_add_message( __(‘You must be logged in to post a comment’, ‘buddypress’ ), ‘error’);

    else :

    if(!check_admin_referer(‘new_activity_comment’, ‘_wpnonce_new_activity_comment’)) :

    bp_core_add_message(__(‘There was an error posting that reply, please try again.’, ‘buddypress’ ), ‘error’);

    else :

    $activity_id = apply_filters(‘bp_activity_post_comment_activity_id’, _POST);
    $content = apply_filters(‘bp_activity_post_comment_content’, _POST);

    $comment_id = bp_activity_new_comment(array(
    ‘content’ => $content,
    ‘activity_id’ => $activity_id,
    ‘parent_id’ => $parent_id));

    if(empty($content)) :
    bp_core_add_message(__(‘Please add a comment.’, ‘buddypress’ ), ‘error’);
    bp_core_redirect(wp_get_referer() . ‘#ac-form-’ . $activity_id);
    endif;

    if(empty($comment_id)) :
    bp_core_add_message(__(‘There was an error posting that reply, please try again.’, ‘buddypress’ ), ‘error’);
    bp_core_redirect(wp_get_referer() . ‘#ac-form-’ . $activity_id);
    else :
    bp_core_add_message(__(‘Comment posted successfully’, ‘buddypress’));
    bp_core_redirect(wp_get_referer() . ‘#ac-form-’ . $activity_id);
    endif;

    endif;

    endif;`

    As this is a theme edit and not core, decided to change the syntax style also. Probably grind against those who work with themes but wouldn’t say my style is ugly.

    Thanks a lot man, this is really good.

    Can I buy you a beer?

    Avatar of Marcella
    Marcella
    Participant

    @marcella1981

    Also the consideration you took here to discovering the issue with _POST was fantastic.

    Well deserved.

    Avatar of Alex Githatu
    Alex Githatu
    Participant

    @kalengi

    Beer! Most definitely!

    You’re right about the template/theme version of the code. It looks a lot friendlier than the core version :)

    Pleasure to have helped!

    hi people, ihave the same problems, but i dont know with ajax enabled or without. i can’t reply nor favourite something. i can post only. i get 404 page for this kind of stuff. i’m not advanced and i have bpress for a while but never tried ro reply or favorite something. i just noticed this errors. now i have a lot sites indexed, if i would deactivate buddypress i would have a lot 404 pages and this is suboptimal for google. i used the codes and created reply.php under my themes activity section. i also put the code you gave me in the funtcions.php section in my theme folder. should i put this code on the main function.php or the one in my theme? or is this a solution for ajax issues only?now it redirects to the activity page when i reply but i don’t see any replies. i think it is a general issue and not only ajax for me. can you please help me out. i can not code, so please tell me in a beginner language? i also can not favorite something.

    Avatar of Marcella
    Marcella
    Participant

    @marcella1981

    If you are using SEO as a metric against using an entirely dynamic system like BuddyPress i suggest you re-consider that metric.

    However the issue you have in regards to the 404 is a known issue and the code above will fix activity stream commenting. @kalengi submitted this fix for a “without javascript use case”.

    To fix commenting running with the above example do the following. (Just re-iterating @kalengi here)

    In the folder /wp-content/themes/your-theme/activity/

    Create the file reply.php

    `<?php
    global $bp;

    if(!is_user_logged_in()) :

    bp_core_add_message( __(‘You must be logged in to post a comment’, ‘buddypress’ ), ‘error’);

    else :

    if(!check_admin_referer(‘new_activity_comment’, ‘_wpnonce_new_activity_comment’)) :

    bp_core_add_message(__(‘There was an error posting that reply, please try again.’, ‘buddypress’ ), ‘error’);

    else :
    // This line should match up with your form field names in entry.php
    $activity_id = apply_filters(‘bp_activity_post_comment_activity_id’, _POST);
    // This line should match up with your form field names in entry.php
    $content = apply_filters(‘bp_activity_post_comment_content’, _POST);

    $comment_id = bp_activity_new_comment(array(
    ‘content’ => $content,
    ‘activity_id’ => $activity_id,
    ‘parent_id’ => $parent_id));

    if(empty($content)) :
    bp_core_add_message(__(‘Please add a comment.’, ‘buddypress’ ), ‘error’);
    bp_core_redirect(wp_get_referer() . ‘#ac-form-’ . $activity_id);
    endif;

    if(empty($comment_id)) :
    bp_core_add_message(__(‘There was an error posting that reply, please try again.’, ‘buddypress’ ), ‘error’);
    bp_core_redirect(wp_get_referer() . ‘#ac-form-’ . $activity_id);
    else :
    bp_core_add_message(__(‘Comment posted successfully’, ‘buddypress’));
    bp_core_redirect(wp_get_referer() . ‘#ac-form-’ . $activity_id);
    endif;

    endif;

    endif;`

    Within that file you should have code that resembles the following. (If you don’t know how to alter accordingly, you need to further assistance.

    /wp-content/themes/your-theme/activity/reply.php

    Then in /wp-content/themes/your-theme/functions.php

    Add this code.

    `function bp_activity_action_add_activity_comment()
    {
    global $bp;

    // Not viewing activity or action is not delete
    if(!bp_is_activity_component() || !bp_is_current_action(‘reply’)) :
    return false;
    endif;

    locate_template(array(‘activity/reply.php’), true);

    bp_core_redirect(wp_get_referer());
    }
    add_action(‘bp_actions’, ‘bp_activity_action_add_activity_comment’);`

    If you then want to add AJAX to this code you could use jQuery and listen for the form submission, onClick or onSubmit.

    You could then run the jQuery AJAX method with GET as the type and the data would be the form fields from the form submitted.

    jQuery will then return for you the return values within reply.php

    Short of writing it specifically for you, that’s what you need.

Viewing 25 replies - 1 through 25 (of 35 total)

You must be logged in to reply to this topic.