Changeset 2580 for trunk/bp-themes/bp-default/_inc/ajax.php
- Timestamp:
- 02/04/2010 10:09:40 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-themes/bp-default/_inc/ajax.php
r2576 r2580 10 10 */ 11 11 12 function bp_dtheme_object_filter() { 13 global $bp; 14 12 /*** 13 * Each object loop (activity/members/groups/blogs/forums) contains parameters to 14 * show specific information based on the page we are currently looking at. 15 * The following function will take into account any cookies set in the JS and allow us 16 * to override the parameters sent. That way we can change the results returned without reloading the page. 17 */ 18 function bp_dtheme_ajax_querystring( $object = false ) { 19 global $bp; 20 21 if ( empty( $object ) ) 22 return false; 23 24 /* Set up the cookies passed on this AJAX request. Store a local var to avoid conflicts */ 25 if ( !empty( $_POST['cookie'] ) ) 26 $_BP_COOKIE = wp_parse_args( str_replace( '; ', '&', urldecode( $_POST['cookie'] ) ) ); 27 else 28 $_BP_COOKIE = &$_COOKIE; 29 30 $qs = false; 31 32 /*** 33 * Check if any cookie values are set. If there are then override the default params passed to the 34 * template loop 35 */ 36 if ( !empty( $_BP_COOKIE['bp-' . $object . '-filter'] ) && '-1' != $_BP_COOKIE['bp-' . $object . '-filter'] ) { 37 $qs[] = 'type=' . $_BP_COOKIE['bp-' . $object . '-filter']; 38 $qs[] = 'action=' . $_BP_COOKIE['bp-' . $object . '-filter']; // Activity stream filtering on action 39 } 40 41 if ( !empty( $_BP_COOKIE['bp-' . $object . '-scope'] ) ) { 42 if ( 'personal' == $_BP_COOKIE['bp-' . $object . '-scope'] ) { 43 $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id; 44 $qs[] = 'user_id=' . $user_id; 45 } 46 $qs[] = 'scope=' . $_BP_COOKIE['bp-' . $object . '-scope']; // Activity stream scope 47 } 48 49 if ( !empty( $_BP_COOKIE['bp-' . $object . '-page'] ) && '-1' != $_BP_COOKIE['bp-' . $object . '-page'] ) 50 $qs[] = 'page=' . $_BP_COOKIE['bp-' . $object . '-page']; 51 52 if ( !empty( $_BP_COOKIE['bp-' . $object . '-search-terms'] ) && __( 'Search anything...', 'buddypress' ) != $_BP_COOKIE['bp-' . $object . '-search-terms'] && 'false' != $_BP_COOKIE['bp-' . $object . '-search-terms'] ) 53 $qs[] = 'search_terms=' . $_BP_COOKIE['bp-' . $object . '-search-terms']; 54 55 /* Now pass the querystring to override default values. */ 56 if ( !empty( $qs ) ) 57 return apply_filters( 'bp_dtheme_ajax_querystring', join( '&', (array)$qs ), $object, $_BP_COOKIE['bp-' . $object . '-filter'], $_BP_COOKIE['bp-' . $object . '-scope'], $_BP_COOKIE['bp-' . $object . '-page'], $_BP_COOKIE['bp-' . $object . '-search-terms'], $_BP_COOKIE['bp-' . $object . '-extras'] ); 58 } 59 60 function bp_dtheme_object_template_loader() { 15 61 $object = esc_attr( $_POST['object'] ); 16 $filter = esc_attr( $_POST['filter'] );17 $page = esc_attr( $_POST['page'] );18 $search_terms = esc_attr( $_POST['search_terms'] );19 20 /**21 * Scope is the scope of results to use, either all (everything) or personal (just mine).22 * For example if the object is groups, it would be all groups, or just groups I belong to.23 */24 $scope = esc_attr( $_POST['scope'] );25 26 /* Plugins can pass extra parameters and use the bp_dtheme_ajax_querystring_content_filter filter to parse them */27 $extras = esc_attr( $_POST['extras'] );28 29 if ( __( 'Search anything...', 'buddypress' ) == $search_terms || 'false' == $search_terms )30 $search_terms = false;31 32 /* Build the querystring */33 if ( empty( $filter ) )34 $filter = 'active';35 36 $bp->ajax_querystring = 'type=' . $filter . '&page=' . $page;37 38 if ( !empty( $search_terms ) )39 $bp->ajax_querystring .= '&search_terms=' . $search_terms;40 41 if ( $scope == 'personal' || $bp->displayed_user->id ) {42 $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;43 $bp->ajax_querystring .= '&user_id=' . $user_id;44 }45 46 $bp->ajax_querystring = apply_filters( 'bp_dtheme_ajax_querystring_content_filter', $bp->ajax_querystring, $extras );47 48 62 locate_template( array( "$object/$object-loop.php" ), true ); 49 63 } 50 add_action( 'wp_ajax_members_filter', 'bp_dtheme_object_filter' ); 51 add_action( 'wp_ajax_groups_filter', 'bp_dtheme_object_filter' ); 52 add_action( 'wp_ajax_blogs_filter', 'bp_dtheme_object_filter' ); 53 add_action( 'wp_ajax_forums_filter', 'bp_dtheme_object_filter' ); 64 add_action( 'wp_ajax_members_filter', 'bp_dtheme_object_template_loader' ); 65 add_action( 'wp_ajax_groups_filter', 'bp_dtheme_object_template_loader' ); 66 add_action( 'wp_ajax_blogs_filter', 'bp_dtheme_object_template_loader' ); 67 add_action( 'wp_ajax_forums_filter', 'bp_dtheme_object_template_loader' ); 68 69 function bp_dtheme_activity_template_loader() { 70 global $bp; 71 72 /* Buffer the loop in the template to a var for JS to spit out. */ 73 ob_start(); 74 locate_template( array( 'activity/activity-loop.php' ), true ); 75 $result['contents'] = ob_get_contents(); 76 ob_end_clean(); 77 78 echo json_encode( $result ); 79 } 80 add_action( 'wp_ajax_activity_widget_filter', 'bp_dtheme_activity_template_loader' ); 81 add_action( 'wp_ajax_activity_get_older_updates', 'bp_dtheme_activity_template_loader' ); 54 82 55 83 function bp_dtheme_post_update() { … … 178 206 add_action( 'wp_ajax_delete_activity', 'bp_dtheme_delete_activity' ); 179 207 180 function bp_dtheme_activity_loop( $scope = false, $filter = false, $per_page = 20, $page = 1 ) {181 global $bp;182 183 /* If we are on a profile page we only want to show that users activity */184 if ( $bp->displayed_user->id ) {185 $query_string = 'user_id=' . $bp->displayed_user->id;186 } else {187 if ( !empty( $bp->groups->current_group ) )188 $scope = 'all';189 190 $feed_url = site_url( BP_ACTIVITY_SLUG . '/feed/' );191 192 switch ( $scope ) {193 case BP_FRIENDS_SLUG:194 $friend_ids = implode( ',', friends_get_friend_user_ids( $bp->loggedin_user->id ) );195 $query_string = 'user_id=' . $friend_ids;196 $feed_url = $bp->loggedin_user->domain . BP_ACTIVITY_SLUG . '/' . BP_FRIENDS_SLUG . '/feed/';197 break;198 case BP_GROUPS_SLUG:199 $groups = groups_get_user_groups( $bp->loggedin_user->id );200 $group_ids = implode( ',', $groups['groups'] );201 $query_string = 'object=groups&primary_id=' . $group_ids . '&show_hidden=1';202 $feed_url = $bp->loggedin_user->domain . BP_ACTIVITY_SLUG . '/' . BP_GROUPS_SLUG . '/feed/';203 break;204 case 'favorites':205 $favs = bp_activity_get_user_favorites( $bp->loggedin_user->id );206 207 if ( empty( $favs ) )208 $favorite_ids = false;209 210 $favorite_ids = implode( ',', (array)$favs );211 $query_string = 'include=' . $favorite_ids;212 $feed_url = $bp->loggedin_user->domain . BP_ACTIVITY_SLUG . '/favorites/feed/';213 break;214 case 'mentions':215 $query_string = 'show_hidden=1&search_terms=@' . bp_core_get_username( $bp->loggedin_user->id, $bp->loggedin_user->userdata->user_nicename, $bp->loggedin_user->userdata->user_login );216 $feed_url = $bp->loggedin_user->domain . BP_ACTIVITY_SLUG . '/mentions/feed/';217 218 /* Reset the number of new @ mentions for the user */219 delete_usermeta( $bp->loggedin_user->id, 'bp_new_mention_count' );220 break;221 }222 }223 224 /* Build the filter */225 if ( $filter && $filter != '-1' )226 $query_string .= '&action=' . $filter;227 228 /* If we are viewing a group then filter the activity just for this group */229 if ( !empty( $bp->groups->current_group ) ) {230 $query_string .= '&object=' . $bp->groups->id . '&primary_id=' . $bp->groups->current_group->id;231 232 /* If we're viewing a non-private group and the user is a member, show the hidden activity for the group */233 if ( 'public' != $bp->groups->current_group->status && groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )234 $query_string .= '&show_hidden=1';235 }236 237 /* Add the per_page param */238 $query_string .= '&per_page=' . $per_page;239 240 /* Add the comments param */241 if ( $bp->displayed_user->id || 'mentions' == $scope )242 $query_string .= '&display_comments=stream';243 else244 $query_string .= '&display_comments=threaded';245 246 /* Add the new page param */247 $args = explode( '&', trim( $query_string ) );248 foreach( (array)$args as $arg ) {249 if ( false === strpos( $arg, 'page' ) )250 $new_args[] = $arg;251 }252 $query_string = implode( '&', $new_args ) . '&page=' . $page;253 254 $bp->ajax_querystring = apply_filters( 'bp_dtheme_ajax_querystring_activity_filter', $query_string, $scope );255 $result['query_string'] = $bp->ajax_querystring;256 $result['feed_url'] = apply_filters( 'bp_dtheme_ajax_feed_url', $feed_url );257 258 /* Buffer the loop in the template to a var for JS to spit out. */259 ob_start();260 locate_template( array( 'activity/activity-loop.php' ), true );261 $result['contents'] = ob_get_contents();262 ob_end_clean();263 264 echo json_encode( $result );265 }266 267 function bp_dtheme_ajax_widget_filter() {268 bp_dtheme_activity_loop( $_POST['scope'], $_POST['filter'] );269 }270 add_action( 'wp_ajax_activity_widget_filter', 'bp_dtheme_ajax_widget_filter' );271 272 function bp_dtheme_ajax_load_older_updates() {273 bp_dtheme_activity_loop( false, false, 20, $_POST['page'] );274 }275 add_action( 'wp_ajax_activity_get_older_updates', 'bp_dtheme_ajax_load_older_updates' );276 277 208 function bp_dtheme_mark_activity_favorite() { 278 209 global $bp;
Note: See TracChangeset
for help on using the changeset viewer.