Skip to:
Content

BuddyPress.org

Changeset 2692


Ignore:
Timestamp:
02/12/2010 01:17:56 AM (15 years ago)
Author:
apeatling
Message:

Fixed support for specific actions such as new update, new reply and favoriting activities when JS is turned off.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r2691 r2692  
    361361add_action( 'wp', 'bp_activity_action_delete_activity', 3 );
    362362
     363function bp_activity_action_post_update() {
     364    global $bp;
     365
     366    if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'post' )
     367        return false;
     368
     369    /* Check the nonce */
     370    check_admin_referer( 'post_update', '_wpnonce_post_update' );
     371
     372    $content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] );
     373    $object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] );
     374    $item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] );
     375
     376    if ( empty( $content ) ) {
     377        bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' );
     378        bp_core_redirect( wp_get_referer() );
     379    }
     380
     381    if ( !(int)$item_id ) {
     382        $activity_id = bp_activity_post_update( array( 'content' => $content ) );
     383
     384    } else if ( 'groups' == $object && function_exists( 'groups_post_update' ) ) {
     385        if ( (int)$item_id ) {
     386            $activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $item_id ) );
     387        }
     388    } else
     389        $activity_id = apply_filters( 'bp_activity_custom_update', $object, $item_id, $content );
     390
     391    if ( !empty( $activity_id ) )
     392        bp_core_add_message( __( 'Update Posted!', 'buddypress' ) );
     393    else
     394        bp_core_add_message( __( 'There was an error when posting your update, please try again.', 'buddypress' ), 'error' );
     395
     396    bp_core_redirect( wp_get_referer() );
     397}
     398add_action( 'wp', 'bp_activity_action_post_update', 3 );
     399
     400function bp_activity_action_post_comment() {
     401    global $bp;
     402
     403    if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'reply' )
     404        return false;
     405
     406    /* Check the nonce */
     407    check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
     408
     409    $activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] );
     410    $content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] );
     411
     412    if ( empty( $content ) ) {
     413        bp_core_add_message( __( 'Please do not leave the comment area blank.', 'buddypress' ), 'error' );
     414        bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
     415    }
     416
     417    $comment_id = bp_activity_new_comment( array(
     418        'content' => $content,
     419        'activity_id' => $activity_id,
     420        'parent_id' => $parent_id
     421    ));
     422
     423    if ( !empty( $comment_id ) )
     424        bp_core_add_message( __( 'Reply Posted!', 'buddypress' ) );
     425    else
     426        bp_core_add_message( __( 'There was an error posting that reply, please try again.', 'buddypress' ), 'error' );
     427
     428    bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
     429}
     430add_action( 'wp', 'bp_activity_action_post_comment', 3 );
     431
     432function bp_activity_action_mark_favorite() {
     433    global $bp;
     434
     435    if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'favorite' )
     436        return false;
     437
     438    /* Check the nonce */
     439    check_admin_referer( 'mark_favorite' );
     440
     441    if ( bp_activity_add_user_favorite( $bp->action_variables[0] ) )
     442        bp_core_add_message( __( 'Activity marked as favorite.', 'buddypress' ) );
     443    else
     444        bp_core_add_message( __( 'There was an error marking that activity as a favorite, please try again.', 'buddypress' ), 'error' );
     445
     446    bp_core_redirect( wp_get_referer() . '#activity-' . $bp->action_variables[0] );
     447}
     448add_action( 'wp', 'bp_activity_action_mark_favorite', 3 );
     449
     450function bp_activity_action_remove_favorite() {
     451    global $bp;
     452
     453    if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'unfavorite' )
     454        return false;
     455
     456    /* Check the nonce */
     457    check_admin_referer( 'unmark_favorite' );
     458
     459    if ( bp_activity_remove_user_favorite( $bp->action_variables[0] ) )
     460        bp_core_add_message( __( 'Activity removed as favorite.', 'buddypress' ) );
     461    else
     462        bp_core_add_message( __( 'There was an error removing that activity as a favorite, please try again.', 'buddypress' ), 'error' );
     463
     464    bp_core_redirect( wp_get_referer() . '#activity-' . $bp->action_variables[0] );
     465}
     466add_action( 'wp', 'bp_activity_action_remove_favorite', 3 );
     467
    363468function bp_activity_action_sitewide_feed() {
    364469    global $bp, $wp_query;
     
    8951000    /* Update the user's personal favorites */
    8961001    $my_favs = maybe_unserialize( get_usermeta( $bp->loggedin_user->id, 'bp_favorite_activities' ) );
    897     $my_favs[] = $_POST['id'];
     1002    $my_favs[] = $activity_id;
    8981003
    8991004    /* Update the total number of users who have favorited this activity */
    900     $fav_count = bp_activity_get_meta( $_POST['id'], 'favorite_count' );
     1005    $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
    9011006
    9021007    if ( !empty( $fav_count ) )
     
    9061011
    9071012    update_usermeta( $bp->loggedin_user->id, 'bp_favorite_activities', $my_favs );
    908     bp_activity_update_meta( $_POST['id'], 'favorite_count', $fav_count );
     1013    bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count );
    9091014
    9101015    return true;
     
    9201025    $my_favs = maybe_unserialize( get_usermeta( $user_id, 'bp_favorite_activities' ) );
    9211026    $my_favs = array_flip( (array) $my_favs );
    922     unset( $my_favs[$_POST['id']] );
     1027    unset( $my_favs[$activity_id] );
    9231028    $my_favs = array_unique( array_flip( $my_favs ) );
    9241029
    9251030    /* Update the total number of users who have favorited this activity */
    926     $fav_count = bp_activity_get_meta( $_POST['id'], 'favorite_count' );
     1031    $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
    9271032
    9281033    if ( !empty( $fav_count ) ) {
    9291034        $fav_count = (int)$fav_count - 1;
    930         bp_activity_update_meta( $_POST['id'], 'favorite_count', $fav_count );
     1035        bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count );
    9311036    }
    9321037
  • trunk/bp-activity/bp-activity-classes.php

    r2686 r2692  
    248248            'item_id' => false,
    249249            'secondary_item_id' => false,
    250             'recorded_time' => false,
     250            'date_recorded' => false,
    251251            'hide_sitewide' => false
    252252        );
     
    281281            $where_args[] = $wpdb->prepare( "secondary_item_id = %s", $secondary_item_id );
    282282
    283         if ( !empty( $recorded_time ) )
    284             $where_args[] = $wpdb->prepare( "recorded_time = %s", $recorded_time );
     283        if ( !empty( $date_recorded ) )
     284            $where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
    285285
    286286        if ( !empty( $hide_sitewide ) )
    287             $where_args[] = $wpdb->prepare( "recorded_time = %d", $hide_sitewide );
     287            $where_args[] = $wpdb->prepare( "hide_sitewide = %d", $hide_sitewide );
    288288
    289289        if ( !empty( $where_args ) )
  • trunk/bp-activity/bp-activity-templatetags.php

    r2681 r2692  
    569569                $content .= '<div class="acomment-meta"><a href="' . bp_core_get_user_domain( $comment->user_id, $comment->user_nicename, $comment->user_login ) . '">' . apply_filters( 'bp_get_member_name', $comment->user_fullname ) . '</a> &middot; ' . sprintf( __( '%s ago', 'buddypress' ), bp_core_time_since( strtotime( $comment->date_recorded ) ) );
    570570
    571                 /* Reply link */
     571                /* Reply link - the span is so that threaded reply links can be hidden when JS is off. */
    572572                if ( is_user_logged_in() )
    573                     $content .= ' &middot; <a href="#acomment-' . $comment->id . '" class="acomment-reply" id="acomment-reply-' . $activities_template->activity->id . '">' . __( 'Reply', 'buddypress' ) . '</a>';
     573                    $content .= '<span class="acomment-replylink"> &middot; <a href="#acomment-' . $comment->id . '" class="acomment-reply" id="acomment-reply-' . $activities_template->activity->id . '">' . __( 'Reply', 'buddypress' ) . '</a></span>';
    574574
    575575                /* Delete link */
     
    615615        }
    616616
     617function bp_activity_comment_link() {
     618    echo bp_get_activity_comment_link();
     619}
     620    function bp_get_activity_comment_link() {
     621        global $activities_template;
     622        return apply_filters( 'bp_get_activity_comment_link', '?ac=' . $activities_template->activity->id . '/#ac-form-' . $activities_template->activity->id );
     623    }
     624
     625function bp_activity_comment_form_nojs_display() {
     626    echo bp_get_activity_comment_form_nojs_display();
     627}
     628    function bp_get_activity_comment_form_nojs_display() {
     629        global $activities_template;
     630        if ( $_GET['ac'] == $activities_template->activity->id . '/' )
     631            return 'style="display: block"';
     632
     633        return false;
     634    }
     635
     636function bp_activity_comment_form_action() {
     637    echo bp_get_activity_comment_form_action();
     638}
     639    function bp_get_activity_comment_form_action() {
     640        return apply_filters( 'bp_get_activity_comment_form_action', site_url( BP_ACTIVITY_SLUG . '/reply/' ) );
     641    }
     642
    617643function bp_activity_permalink_id() {
    618644    echo bp_get_activity_permalink_id();
     
    633659
    634660        return apply_filters( 'bp_get_activity_thread_permalink', $link );
     661    }
     662
     663function bp_activity_favorite_link() {
     664    echo bp_get_activity_favorite_link();
     665}
     666    function bp_get_activity_favorite_link() {
     667        global $activities_template;
     668        return apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( site_url( BP_ACTIVITY_SLUG . '/favorite/' . $activities_template->activity->id . '/' ), 'mark_favorite' ) );
     669    }
     670
     671function bp_activity_unfavorite_link() {
     672    echo bp_get_activity_unfavorite_link();
     673}
     674    function bp_get_activity_unfavorite_link() {
     675        global $activities_template;
     676        return apply_filters( 'bp_get_activity_unfavorite_link', wp_nonce_url( site_url( BP_ACTIVITY_SLUG . '/unfavorite/' . $activities_template->activity->id . '/' ), 'unmark_favorite' ) );
    635677    }
    636678
     
    792834    }
    793835
     836function bp_activity_post_form_action() {
     837    echo bp_get_activity_post_form_action();
     838}
     839    function bp_get_activity_post_form_action() {
     840        return apply_filters( 'bp_get_activity_post_form_action', site_url( BP_ACTIVITY_SLUG . '/post/' ) );
     841    }
    794842
    795843/* RSS Feed Template Tags ***************************/
  • trunk/bp-themes/bp-default/_inc/ajax.php

    r2666 r2692  
    1111
    1212/***
    13  * Each object loop (activity/members/groups/blogs/forums) contains parameters to
     13 * This function looks scarier than it actually is. :)
     14 * Each object loop (activity/members/groups/blogs/forums) contains default parameters to
    1415 * show specific information based on the page we are currently looking at.
    1516 * The following function will take into account any cookies set in the JS and allow us
    1617 * to override the parameters sent. That way we can change the results returned without reloading the page.
     18 * By using cookies we can also make sure that user settings are retained across page loads.
    1719 */
    1820function bp_dtheme_ajax_querystring( $object = false ) {
     
    6163}
    6264
     65/* This function will simply load the template loop for the current object. On an AJAX request */
    6366function bp_dtheme_object_template_loader() {
    6467    $object = esc_attr( $_POST['object'] );
     
    7073add_action( 'wp_ajax_forums_filter', 'bp_dtheme_object_template_loader' );
    7174
     75/* This function will load the activity loop template when activity is requested via AJAX */
    7276function bp_dtheme_activity_template_loader() {
    7377    global $bp;
     
    104108add_action( 'wp_ajax_activity_get_older_updates', 'bp_dtheme_activity_template_loader' );
    105109
     110/* AJAX update posting */
    106111function bp_dtheme_post_update() {
    107112    global $bp;
     
    120125    }
    121126
    122     if ( empty( $_POST['object'] ) ) {
    123         $activity_id = bp_activity_post_update( array(
    124             'content' => $_POST['content']
    125         ));
     127    if ( empty( $_POST['object'] ) && function_exists( 'bp_activity_post_update' ) ) {
     128        $activity_id = bp_activity_post_update( array( 'content' => $_POST['content'] ) );
    126129    } elseif ( $_POST['object'] == 'groups' ) {
    127         if ( !empty( $_POST['item_id'] ) ) {
    128         $activity_id = groups_post_update( array(
    129             'content' => $_POST['content'],
    130                 'group_id' => $_POST['item_id']
    131         ));
    132         }
    133     } else {
     130        if ( !empty( $_POST['item_id'] ) && function_exists( 'groups_post_update' ) )
     131            $activity_id = groups_post_update( array( 'content' => $_POST['content'], 'group_id' => $_POST['item_id'] ) );
     132    } else
    134133        $activity_id = apply_filters( 'bp_activity_custom_update', $_POST['object'], $_POST['item_id'], $_POST['content'] );
    135     }
    136134
    137135    if ( !$activity_id ) {
     
    148146add_action( 'wp_ajax_post_update', 'bp_dtheme_post_update' );
    149147
     148/* AJAX activity comment posting */
    150149function bp_dtheme_new_activity_comment() {
    151150    global $bp;
     
    202201add_action( 'wp_ajax_new_activity_comment', 'bp_dtheme_new_activity_comment' );
    203202
     203/* AJAX delete an activity */
    204204function bp_dtheme_delete_activity() {
    205205    global $bp;
     
    228228add_action( 'wp_ajax_delete_activity', 'bp_dtheme_delete_activity' );
    229229
     230/* AJAX delete an activity comment */
    230231function bp_dtheme_delete_activity_comment() {
    231232    global $bp;
     
    254255add_action( 'wp_ajax_delete_activity_comment', 'bp_dtheme_delete_activity_comment' );
    255256
     257/* AJAX mark an activity as a favorite */
    256258function bp_dtheme_mark_activity_favorite() {
    257259    global $bp;
     
    262264add_action( 'wp_ajax_activity_mark_fav', 'bp_dtheme_mark_activity_favorite' );
    263265
     266/* AJAX mark an activity as not a favorite */
    264267function bp_dtheme_unmark_activity_favorite() {
    265268    global $bp;
     
    270273add_action( 'wp_ajax_activity_mark_unfav', 'bp_dtheme_unmark_activity_favorite' );
    271274
     275/* AJAX invite a friend to a group functionality */
    272276function bp_dtheme_ajax_invite_user() {
    273277    global $bp;
     
    313317add_action( 'wp_ajax_groups_invite_user', 'bp_dtheme_ajax_invite_user' );
    314318
     319/* AJAX add/remove a user as a friend when clicking the button */
    315320function bp_dtheme_ajax_addremove_friend() {
    316321    global $bp;
     
    343348add_action( 'wp_ajax_addremove_friend', 'bp_dtheme_ajax_addremove_friend' );
    344349
     350/* AJAX accept a user as a friend when clicking the "accept" button */
    345351function bp_dtheme_ajax_accept_friendship() {
    346352    check_admin_referer( 'friends_accept_friendship' );
     
    353359add_action( 'wp_ajax_accept_friendship', 'bp_dtheme_ajax_accept_friendship' );
    354360
     361/* AJAX reject a user as a friend when clicking the "reject" button */
    355362function bp_dtheme_ajax_reject_friendship() {
    356363    check_admin_referer( 'friends_reject_friendship' );
     
    363370add_action( 'wp_ajax_reject_friendship', 'bp_dtheme_ajax_reject_friendship' );
    364371
     372/* AJAX join or leave a group when clicking the "join/leave" button */
    365373function bp_dtheme_ajax_joinleave_group() {
    366374    global $bp;
     
    415423add_action( 'wp_ajax_joinleave_group', 'bp_dtheme_ajax_joinleave_group' );
    416424
     425/* AJAX close and keep closed site wide notices from an admin in the sidebar */
    417426function bp_dtheme_ajax_close_notice() {
    418427    global $userdata;
     
    430439add_action( 'wp_ajax_messages_close_notice', 'bp_dtheme_ajax_close_notice' );
    431440
     441/* AJAX send a private message reply to a thread */
    432442function bp_dtheme_ajax_messages_send_reply() {
    433443    global $bp;
     
    465475add_action( 'wp_ajax_messages_send_reply', 'bp_dtheme_ajax_messages_send_reply' );
    466476
     477/* AJAX mark a private message as unread in your inbox */
    467478function bp_dtheme_ajax_message_markunread() {
    468479    global $bp;
     
    480491add_action( 'wp_ajax_messages_markunread', 'bp_dtheme_ajax_message_markunread' );
    481492
     493/* AJAX mark a private message as read in your inbox */
    482494function bp_dtheme_ajax_message_markread() {
    483495    global $bp;
     
    495507add_action( 'wp_ajax_messages_markread', 'bp_dtheme_ajax_message_markread' );
    496508
     509/* AJAX delete a private message or array of messages in your inbox */
    497510function bp_dtheme_ajax_messages_delete() {
    498511    global $bp;
     
    511524add_action( 'wp_ajax_messages_delete', 'bp_dtheme_ajax_messages_delete' );
    512525
     526/* AJAX autocomplete your friends names on the compose screen */
    513527function bp_dtheme_ajax_messages_autocomplete_results() {
    514528    global $bp;
  • trunk/bp-themes/bp-default/_inc/css/default.css

    r2684 r2692  
    12961296        }
    12971297
     1298        div.activity-comments span.acomment-replylink { display: none; }
     1299
    12981300        div.activity-comments ul li p:last-child {
    12991301            margin-bottom: 0;
  • trunk/bp-themes/bp-default/_inc/global.js

    r2688 r2692  
    77j(document).ready( function() {
    88    /**** Page Load Actions *******************************************************/
     9
     10    /* Hide Forums Post Form */
     11    if ( j('div.forums').length )
     12        j('div#new-topic-post').hide();
     13
     14    /* Show threaded reply links */
     15    if ( j('span.acomment-replylink').length )
     16        j('span.acomment-replylink').show();
    917
    1018    /* Activity filter and scope set */
     
    1422    var objects = [ 'members', 'groups', 'blogs', 'forums' ];
    1523    bp_init_objects( objects );
    16 
    17     /* Hide Forums Post Form */
    18     if ( j('div.forums').length )
    19         j('div#new-topic-post').hide();
    2024
    2125    /* @mention Compose Scrolling */
     
    308312
    309313        /* Activity comment posting */
    310         if ( target.attr('name') == 'ac-form-submit' ) {
     314        if ( target.attr('name') == 'ac_form_submit' ) {
    311315            var form = target.parent().parent();
    312316            var form_parent = form.parent();
  • trunk/bp-themes/bp-default/activity/entry.php

    r2683 r2692  
    2626        <div class="activity-meta">
    2727            <?php if ( is_user_logged_in() && bp_activity_can_comment() ) : ?>
    28                 <a href="#acomment-<?php bp_activity_id() ?>" class="acomment-reply" id="acomment-comment-<?php bp_activity_id() ?>"><?php _e( 'Reply', 'buddypress' ) ?> (<span><?php bp_activity_comment_count() ?></span>)</a>
     28                <a href="<?php bp_activity_comment_link() ?>" class="acomment-reply" id="acomment-comment-<?php bp_activity_id() ?>"><?php _e( 'Reply', 'buddypress' ) ?> (<span><?php bp_activity_comment_count() ?></span>)</a>
    2929            <?php endif; ?>
    3030
    3131            <?php if ( is_user_logged_in() ) : ?>
    3232                <?php if ( !bp_get_activity_is_favorite() ) : ?>
    33                     <a href="" class="fav" title="<?php _e( 'Mark as Favorite', 'buddypress' ) ?>"><?php _e( 'Favorite', 'buddypress' ) ?></a>
     33                    <a href="<?php bp_activity_favorite_link() ?>" class="fav" title="<?php _e( 'Mark as Favorite', 'buddypress' ) ?>"><?php _e( 'Favorite', 'buddypress' ) ?></a>
    3434                <?php else : ?>
    35                     <a href="" class="unfav" title="<?php _e( 'Remove Favorite', 'buddypress' ) ?>"><?php _e( 'Remove Favorite', 'buddypress' ) ?></a>
     35                    <a href="<?php bp_activity_unfavorite_link() ?>" class="unfav" title="<?php _e( 'Remove Favorite', 'buddypress' ) ?>"><?php _e( 'Remove Favorite', 'buddypress' ) ?></a>
    3636                <?php endif; ?>
    3737            <?php endif;?>
     
    5555
    5656            <?php if ( is_user_logged_in() ) : ?>
    57             <form action="" method="post" name="activity-comment-form" id="ac-form-<?php bp_activity_id() ?>" class="ac-form">
     57            <form action="<?php bp_activity_comment_form_action() ?>" method="post" id="ac-form-<?php bp_activity_id() ?>" class="ac-form"<?php bp_activity_comment_form_nojs_display() ?>>
    5858                <div class="ac-reply-avatar"><?php bp_loggedin_user_avatar( 'width=25&height=25' ) ?></div>
    5959                <div class="ac-reply-content">
    6060                    <div class="ac-textarea">
    61                         <textarea id="ac-input-<?php bp_activity_id() ?>" class="ac-input" name="ac-input-<?php bp_activity_id() ?>"></textarea>
     61                        <textarea id="ac-input-<?php bp_activity_id() ?>" class="ac-input" name="ac_input_<?php bp_activity_id() ?>"></textarea>
    6262                    </div>
    63                     <input type="submit" name="ac-form-submit" value="<?php _e( 'Post', 'buddypress' ) ?> &rarr;" /> &nbsp; <?php _e( 'or press esc to cancel.', 'buddypress' ) ?>
     63                    <input type="submit" name="ac_form_submit" value="<?php _e( 'Post', 'buddypress' ) ?> &rarr;" /> &nbsp; <?php _e( 'or press esc to cancel.', 'buddypress' ) ?>
     64                    <input type="hidden" name="comment_form_id" value="<?php bp_activity_id() ?>" />
    6465                </div>
    6566                <?php wp_nonce_field( 'new_activity_comment', '_wpnonce_new_activity_comment' ) ?>
  • trunk/bp-themes/bp-default/activity/post-form.php

    r2622 r2692  
    1 <form action="" method="post" id="whats-new-form" name="whats-new-form">
     1<form action="<?php bp_activity_post_form_action() ?>" method="post" id="whats-new-form" name="whats-new-form">
    22
    33    <?php do_action( 'bp_before_activity_post_form' ) ?>
Note: See TracChangeset for help on using the changeset viewer.