sbrajesh

Brajesh Singh

May 17th, 2010
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.51 KB | None | 0 0
  1. <?php
  2. /** wire message will become private, please note that */
  3.  
  4. /* AJAX update posting */
  5. function bp_mytheme_post_update() {
  6.     global $bp;
  7.  
  8.     /* Check the nonce */
  9.     check_admin_referer( 'post_update', '_wpnonce_post_update' );
  10.  
  11.     if ( !is_user_logged_in() ) {
  12.         echo '-1';
  13.         return false;
  14.     }
  15.  
  16.     if ( empty( $_POST['content'] ) ) {
  17.         echo '-1<div id="message" class="error"><p>' . __( 'Please enter some content to post.', 'buddypress' ) . '</p></div>';
  18.         return false;
  19.     }
  20.  
  21.     if ( empty( $_POST['object'] ) && function_exists( 'bp_activity_post_update' ) ) {
  22.        
  23.         if(!bp_is_home()&&bp_is_member()){
  24.             $content="@". bp_get_displayed_user_username()." ".$_POST['content'];
  25.                  $activity_id=bpdev_activity_post_update (array( 'content' => $content ));
  26.                 }
  27.         else{
  28.             $content=$_POST['content'];
  29.         $activity_id = bp_activity_post_update( array( 'content' => $content ) );
  30.                 }
  31.     } elseif ( $_POST['object'] == 'groups' ) {
  32.         if ( !empty( $_POST['item_id'] ) && function_exists( 'groups_post_update' ) )
  33.             $activity_id = groups_post_update( array( 'content' => $_POST['content'], 'group_id' => $_POST['item_id'] ) );
  34.     } else
  35.         $activity_id = apply_filters( 'bp_activity_custom_update', $_POST['object'], $_POST['item_id'], $_POST['content'] );
  36.  
  37.     if ( !$activity_id ) {
  38.         echo '-1<div id="message" class="error"><p>' . __( 'There was a problem posting your update, please try again.', 'buddypress' ) . '</p></div>';
  39.         return false;
  40.     }
  41.  
  42.     if ( bp_has_activities ( 'include=' . $activity_id ) ) : ?>
  43.         <?php while ( bp_activities() ) : bp_the_activity(); ?>
  44.             <?php locate_template( array( 'activity/entry.php' ), true ) ?>
  45.         <?php endwhile; ?>
  46.      <?php endif;
  47. }
  48. add_action( 'wp_ajax_post_update', 'bp_mytheme_post_update' );
  49.  
  50. add_action("init","mytheme_remove_original_update_func",5);
  51. function mytheme_remove_original_update_func(){
  52. remove_action( 'wp_ajax_post_update', 'bp_dtheme_post_update' );
  53. }
  54.  
  55.  
  56. function bpdev_activity_post_update( $args = '' ) {
  57.     global $bp;
  58.  
  59.     $defaults = array(
  60.         'content' => false,
  61.         'user_id' => $bp->loggedin_user->id
  62.     );
  63.  
  64.     $r = wp_parse_args( $args, $defaults );
  65.     extract( $r, EXTR_SKIP );
  66.  
  67.     if ( empty( $content ) || !strlen( trim( $content ) ) )
  68.         return false;
  69.  
  70.     /* Record this on the user's profile */
  71.     $from_user_link = bp_core_get_userlink( $user_id );
  72.     $activity_action = sprintf( __( '%s posted an update:', 'buddypress' ), $from_user_link );
  73.     $activity_content = $content;
  74.  
  75.     $primary_link = bp_core_get_userlink( $user_id, false, true );
  76.  
  77.     /* Now write the values */
  78.     $activity_id = bp_activity_add( array(
  79.         'user_id' => $user_id,
  80.         'action' => apply_filters( 'bp_activity_new_update_action', $activity_action ),
  81.         'content' => apply_filters( 'bp_activity_new_update_content', $activity_content ),
  82.         'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ),
  83.         'component' => $bp->activity->id,
  84.         'type' => 'activity_update',
  85.                 'hide_sitewide'=>1
  86.     ) );
  87.  
  88.     /* Add this update to the "latest update" usermeta so it can be fetched anywhere. */
  89.     //update_usermeta( $bp->loggedin_user->id, 'bp_latest_update', array( 'id' => $activity_id, 'content' => wp_filter_kses( $content ) ) );
  90.  
  91.     /* Require the notifications code so email notifications can be set on the 'bp_activity_posted_update' action. */
  92.     require_once( BP_PLUGIN_DIR . '/bp-activity/bp-activity-notifications.php' );
  93.  
  94.     do_action( 'bp_activity_posted_update', $content, $user_id, $activity_id );
  95.  
  96.     return $activity_id;
  97. }
  98.  
  99. ?>
Add Comment
Please, Sign In to add comment