What is it? BuddyPressDEV.org is the community of BuddyPress' developers that creates and extend this platform.
[ Index ]

PHP Cross Reference of BuddyPress SVN Code

title

Body

[close]

/ -> bp-status.php (source)

   1  <?php
   2  define ( 'BP_STATUS_IS_INSTALLED', 1 );
   3  
   4  if ( !defined( 'BP_STATUS_SLUG' ) )
   5      define ( 'BP_STATUS_SLUG', 'status' );
   6  
   7  require  ( BP_PLUGIN_DIR . '/bp-status/bp-status-templatetags.php' );
   8  require  ( BP_PLUGIN_DIR . '/bp-status/bp-status-filters.php' );
   9  
  10  function bp_status_record_activity( $user_id, $content, $primary_link ) {
  11      if ( !function_exists( 'bp_activity_add' ) )
  12          return false;
  13      
  14      return bp_activity_add( array( 
  15              'user_id' => $user_id, 
  16              'content' => $content, 
  17              'primary_link' => $primary_link, 
  18              'component_name' => 'status',
  19              'component_action' => 'new_status'
  20             ) );
  21  }
  22  
  23  function bp_status_delete_activity( $user_id, $content ) {
  24      if ( !function_exists( 'bp_activity_delete_by_content' ) )
  25          return false;
  26          
  27      return bp_activity_delete_by_content( $user_id, $content, 'status', 'new_status' );
  28  }
  29  
  30  function bp_status_format_activity( $user_id, $content, $component_action = false ) {
  31      global $bp;
  32      
  33      if ( !$component_action )
  34          $component_action = 'new_status';
  35      
  36      $user_link = bp_core_get_userlink( $user_id );
  37      
  38      switch( $component_action ) {
  39          case 'new_status':
  40              $stream_item = sprintf( __( '%s posted a new status update:', 'buddypress' ), $user_link ) . '<span class="time-since">%s</span>';
  41              $stream_item .= "<blockquote>$content</blockquote>";
  42              break;
  43      }
  44      
  45      return apply_filters( 'bp_status_format_activity', $stream_item, $user_id, $content, $component_action );
  46  }
  47  
  48  
  49  /********************************************************************************
  50   * Action Functions
  51   *
  52   * Action functions are exactly the same as screen functions, however they do not
  53   * have a template screen associated with them. Usually they will send the user
  54   * back to the default screen after execution.
  55   */
  56  
  57  function bp_status_action_add() {
  58      global $bp;
  59  
  60      if ( $bp->current_component != BP_STATUS_SLUG && 'add' != $bp->current_action )
  61          return false;
  62      
  63      if ( !check_admin_referer( 'bp_status_add_status', '_wpnonce_add_status' ) )
  64          return false;
  65  
  66      if ( bp_status_add_status( $bp->loggedin_user->id, $_POST['status-update-input'] ) )
  67          bp_core_add_message( __( 'Your status was updated successfully!', 'buddypress' ) );
  68      else
  69          bp_core_add_message( __( 'There was a problem updating your status. Please try again.', 'buddypress' ), 'error' );
  70      
  71      bp_core_redirect( $bp->loggedin_user->domain );
  72  }
  73  add_action( 'init', 'bp_status_action_add' );
  74  
  75  
  76  /********************************************************************************
  77   * Business Functions
  78   *
  79   * Business functions are where all the magic happens in BuddyPress. They will
  80   * handle the actual saving or manipulation of information. Usually they will
  81   * hand off to a database class for data access, then return
  82   * true or false on success or failure.
  83   */
  84  
  85  function bp_status_add_status( $user_id, $content ) {
  86      global $bp;
  87      
  88      $content = apply_filters( 'bp_status_content', $content );
  89      $recorded_time = time();
  90      
  91      if ( !$content || empty($content) )
  92          return false;
  93      
  94      bp_status_clear_existing_activity( $user_id );
  95      
  96      if ( update_usermeta( $user_id, 'bp_status', array( 'content' => $content, 'recorded_time' => $recorded_time ) ) ) {
  97          bp_status_record_activity( $user_id, bp_status_format_activity( $user_id, $content ), bp_core_get_user_domain( $user_id ) );
  98          
  99          do_action( 'bp_status_add_status', $user_id, $content );
 100          return true;
 101      }
 102      
 103      return false;
 104  }
 105  
 106  function bp_status_clear_status( $user_id = false ) {
 107      global $bp;
 108      
 109      if ( !$user_id )
 110          $user_id = $bp->loggedin_user->id;
 111      
 112      bp_status_clear_existing_activity( $user_id );
 113      
 114      return delete_usermeta( $user_id, 'bp_status' );
 115  }
 116  
 117  function bp_status_clear_existing_activity( $user_id ) {
 118      /* Fetch existing status update if there is one. */
 119      $existing_status = get_usermeta( $user_id, 'bp_status');
 120      
 121      if ( '' != $existing_status ) {
 122          if ( strtotime( '+5 minutes', $existing_status['recorded_time'] ) >= time() ) {
 123              /***
 124               * The last status was updated less than 5 minutes ago, so lets delete the activity stream item for that
 125               * status update, to prevent flooding and allow users to change their mind about recording a status.
 126               */
 127              bp_status_delete_activity( $user_id, bp_status_format_activity( $user_id, $existing_status['content'] ) );
 128          }
 129      }
 130  }
 131  
 132  ?>


Generated: Sat Aug 22 14:49:03 2009 Cross-referenced by PHPXref 0.7 Thanks to