Skip to:
Content

BuddyPress.org

Ticket #1793: move_theme_content_cookies_to_ajax.patch

File move_theme_content_cookies_to_ajax.patch, 13.6 KB (added by MrMaz, 16 years ago)
  • bp-blogs/bp-blogs-templatetags.php

    # This patch file was generated by NetBeans IDE
    # Following Index: paths are relative to: \\UBU\www\sandbox2\public_html\wp-content\plugins\buddypress
    # This patch can be applied using context Tools: Patch action on respective folder.
    # It uses platform neutral UTF-8 encoding and \n newlines.
    # Above lines and this line are ignored by the patching process.
     
    109109function bp_has_blogs( $args = '' ) {
    110110        global $bp, $blogs_template;
    111111
    112         /***
    113          * Set the defaults based on the current page. Any of these will be overridden
    114          * if arguments are directly passed into the loop. Custom plugins should always
    115          * pass their parameters directly to the loop.
    116          */
    117         $type = 'active';
    118         $user_id = false;
    119         $page = 1;
    120 
    121         /* User filtering */
    122         if ( !empty( $bp->displayed_user->id ) || 'personal' == $_COOKIE['bp-blogs-scope'] )
    123                 $user_id = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
    124 
    125         /* Action filtering */
    126         if ( !empty( $_COOKIE['bp-blogs-filter'] ) && '-1' != $_COOKIE['bp-blogs-filter'] )
    127                 $type = $_COOKIE['bp-blogs-filter'];
    128 
    129         if ( !empty( $_COOKIE['bp-blogs-page'] ) && '-1' != $_COOKIE['bp-blogs-page'] )
    130                 $page = $_COOKIE['bp-blogs-page'];
    131 
    132112        $defaults = array(
    133                 'type' => $type,
    134                 'page' => $page,
     113                'type' => 'active',
     114                'page' => 1,
    135115                'per_page' => 20,
    136116                'max' => false,
    137117
    138                 'user_id' => $user_id, // Pass a user_id to limit to only blogs this user has higher than subscriber access to
    139  No newline at end of file
     118                'user_id' => false, // Pass a user_id to limit to only blogs this user has higher than subscriber access to
     119 No newline at end of file
    140120                'search_terms' => false // Pass search terms to filter on the blog title or description.
    141121        );
  • bp-core/bp-core-templatetags.php

     
     
    117117function bp_has_members( $args = '' ) {
    118118        global $bp, $members_template;
    119119
    120         /***
    121          * Set the defaults based on the current page. Any of these will be overridden
    122          * if arguments are directly passed into the loop. Custom plugins should always
    123          * pass their parameters directly to the loop.
    124          */
    125         $type = 'active';
    126         $user_id = false;
    127         $page = 1;
    128 
    129         /* User filtering */
    130         if ( !empty( $bp->displayed_user->id ) || 'personal' == $_COOKIE['bp-members-scope'] )
    131                 $user_id = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
    132 
    133         /* Action filtering */
    134         if ( !empty( $_COOKIE['bp-members-filter'] ) && '-1' != $_COOKIE['bp-members-filter'] )
    135                 $type = $_COOKIE['bp-members-filter'];
    136 
    137         if ( !empty( $_COOKIE['bp-members-page'] ) && '-1' != $_COOKIE['bp-members-page'] )
    138                 $page = $_COOKIE['bp-members-page'];
    139 
    140120        // type: active ( default ) | random | newest | popular | online | alphabetical
    141121        $defaults = array(
    142                 'type' => $type,
    143                 'page' => $page,
     122                'type' => 'active',
     123                'page' => 1,
    144124                'per_page' => 20,
    145125                'max' => false,
    146126
    147127                'include' => false, // Pass a user_id or comma separated list of user_ids to only show these users
    148128
    149                 'user_id' => $user_id, // Pass a user_id to only show friends of this user
     129                'user_id' => false, // Pass a user_id to only show friends of this user
    150130                'search_terms' => false, // Pass search_terms to filter users by their profile data
    151131
    152132                'populate_extras' => true // Fetch usermeta? Friend count, last active etc.
     
    13991379        return apply_filters( 'bp_ajax_querystring', $bp->ajax_querystring );
    14001380}
    14011381
     1382function bp_set_ajax_querystring( $string ) {
     1383        global $bp;
     1384
     1385        $bp->ajax_querystring = apply_filters( 'bp_set_ajax_querystring', $string );
     1386}
     1387
     1388 No newline at end of file
    14021389/* Template is_() functions to determine the current page */
    14031390
    14041391function bp_is_active( $component ) {
  • bp-forums/bp-forums-templatetags.php

     
    155155function bp_has_forum_topics( $args = '' ) {
    156156        global $forum_template, $bp;
    157157
    158         /***
    159          * Set the defaults based on the current page. Any of these will be overridden
    160          * if arguments are directly passed into the loop. Custom plugins should always
    161          * pass their parameters directly to the loop.
    162          */
    163         $type = 'newest';
    164         $user_id = false;
    165         $page = 1;
    166 
    167         /* User filtering */
    168         if ( !empty( $bp->displayed_user->id ) || 'personal' == $_COOKIE['bp-forums-scope'] )
    169                 $user_id = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
    170 
    171         /* Action filtering */
    172         if ( !empty( $_COOKIE['bp-forums-filter'] ) && '-1' != $_COOKIE['bp-forums-filter'] )
    173                 $type = $_COOKIE['bp-forums-filter'];
    174 
    175         if ( !empty( $_COOKIE['bp-forums-page'] ) && '-1' != $_COOKIE['bp-forums-page'] )
    176                 $page = $_COOKIE['bp-forums-page'];
    177 
    178158        $defaults = array(
    179                 'type' => $type,
     159                'type' => 'newest',
    180160                'forum_id' => false,
    181                 'user_id' => $user_id,
    182                 'page' => $page,
    183  No newline at end of file
     161                'user_id' => false,
     162                'page' => 1,
     163 No newline at end of file
    184164                'per_page' => 20,
    185165                'max' => false,
  • bp-groups/bp-groups-templatetags.php

     		'no_stickies' => false,
     
    170170function bp_has_groups( $args = '' ) {
    171171        global $groups_template, $bp;
    172172
    173         /***
    174          * Set the defaults based on the current page. Any of these will be overridden
    175          * if arguments are directly passed into the loop. Custom plugins should always
    176          * pass their parameters directly to the loop.
    177          */
    178         $type = 'active';
    179         $user_id = false;
    180         $page = 1;
    181 
    182         /* User filtering */
    183         if ( !empty( $bp->displayed_user->id ) || 'personal' == $_COOKIE['bp-groups-scope'] )
    184                 $user_id = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
    185 
    186         /* Action filtering */
    187         if ( !empty( $_COOKIE['bp-groups-filter'] ) && '-1' != $_COOKIE['bp-groups-filter'] )
    188                 $type = $_COOKIE['bp-groups-filter'];
    189 
    190         if ( !empty( $_COOKIE['bp-groups-page'] ) && '-1' != $_COOKIE['bp-groups-page'] )
    191                 $page = $_COOKIE['bp-groups-page'];
    192 
    193173        $defaults = array(
    194                 'type' => $type,
    195                 'page' => $page,
     174                'type' => 'active',
     175                'page' => 1,
    196176                'per_page' => 20,
    197177                'max' => false,
    198178
    199                 'user_id' => $user_id, // Pass a user ID to limit to groups this user has joined
    200  No newline at end of file
     179                'user_id' => false, // Pass a user ID to limit to groups this user has joined
     180 No newline at end of file
    201181                'slug' => false, // Pass a group slug to only return that group
    202182                'search_terms' => false // Pass search terms to return only matching groups
  • bp-themes/bp-default/_inc/ajax.php

     	);
     
    99 * your own _inc/ajax.php file and add/remove AJAX functionality as you see fit.
    1010 */
    1111
     12function bp_dtheme_ajax_querystring( $object = null ) {
     13        global $bp;
     14
     15        /* Backwards and forwards compatibility */
     16        if ( empty( $object ) ) {
     17                // no object? just return it
     18                return apply_filters( 'bp_dtheme_ajax_querystring', bp_ajax_querystring() );
     19        } elseif ( 'activity' == $object ) {
     20                // activity filtering not completed yet, but here is what the filter will be
     21                $pre_filtered_querystring = apply_filters( 'bp_dtheme_ajax_querystring_activity_filter', bp_ajax_querystring() );
     22                return apply_filters( 'bp_dtheme_ajax_querystring', $pre_filtered_querystring );
     23        }
     24
     25        /* Handle content filtering for the THEME */
     26        $c_scope = 'bp-' . $object . '-scope';
     27        $c_filter = 'bp-' . $object . '-filter';
     28
     29        $scope = ( !empty( $_COOKIE[$c_scope] ) ) ? $_COOKIE[$c_scope] : null;
     30        $filter = ( !empty( $_COOKIE[$c_filter] ) && '-1' != $_COOKIE[$c_filter] ) ? $_COOKIE[$c_filter] : null;
     31
     32        $defaults = array(
     33                'object' => $object,
     34                'scope' => $scope,
     35                'type' => $filter
     36        );
     37
     38        // Do pre-filtering
     39        $r = wp_parse_args( bp_ajax_querystring(), $defaults );
     40        $pre_filtered_querystring = apply_filters( 'bp_dtheme_ajax_querystring_' . $object . '_filter', http_build_query($r) );
     41
     42        // Return after global filter applied
     43        return apply_filters( 'bp_dtheme_ajax_querystring', $pre_filtered_querystring );
     44}
     45
     46/* Personal filtering */
     47function bp_dtheme_ajax_querystring_filter_personal( $query_string ) {
     48        global $bp;
     49
     50        $r = wp_parse_args( $query_string );
     51        extract($r);
     52
     53        if ( !empty( $bp->displayed_user->id ) || 'personal' == $scope ) {
     54                $r['user_id'] = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
     55                return http_build_query($r);
     56        } else {
     57                return $query_string;
     58        }
     59}
     60add_filter( 'bp_dtheme_ajax_querystring_groups_filter', 'bp_dtheme_ajax_querystring_filter_personal', 1 );
     61add_filter( 'bp_dtheme_ajax_querystring_forums_filter', 'bp_dtheme_ajax_querystring_filter_personal', 1 );
     62add_filter( 'bp_dtheme_ajax_querystring_members_filter', 'bp_dtheme_ajax_querystring_filter_personal', 1 );
     63add_filter( 'bp_dtheme_ajax_querystring_blogs_filter', 'bp_dtheme_ajax_querystring_filter_personal', 1 );
     64
    1265function bp_dtheme_object_filter() {
    1366        global $bp;
    1467
     
    3083                $search_terms = false;
    3184
    3285        /* Build the querystring */
    33         if ( empty( $filter ) )
    34                 $filter = 'active';
     86        $querystring_args =
     87                array(
     88                        'object' => $object,
     89                        'scope' => $scope,
     90                        'filter' => empty( $filter ) ? 'active' : $filter,
     91                        'page' => empty( $page ) ? 1 : $page,
     92                );
    3593
    36         $bp->ajax_querystring = 'type=' . $filter . '&page=' . $page;
    37 
    3894        if ( !empty( $search_terms ) )
    39                 $bp->ajax_querystring .= '&search_terms=' . $search_terms;
     95                $querystring_args['search_terms'] = $search_terms;
    4096
    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         }
     97        bp_set_ajax_querystring( apply_filters( 'bp_dtheme_ajax_querystring_content_filter', http_build_query($querystring_args), $extras ) );
    4598
    46         $bp->ajax_querystring = apply_filters( 'bp_dtheme_ajax_querystring_content_filter', $bp->ajax_querystring, $extras );
    47 
    4899        locate_template( array( "$object/$object-loop.php" ), true );
    49100}
    50101add_action( 'wp_ajax_members_filter', 'bp_dtheme_object_filter' );
     
    251302        }
    252303        $query_string = implode( '&', $new_args ) . '&page=' . $page;
    253304
    254         $bp->ajax_querystring = apply_filters( 'bp_dtheme_ajax_querystring_activity_filter', $query_string, $scope );
    255         $result['query_string'] = $bp->ajax_querystring;
    256  No newline at end of file
     305        bp_set_ajax_querystring( apply_filters( 'bp_dtheme_ajax_querystring_activity_filter', $query_string, $scope ) );
     306        $result['query_string'] = bp_ajax_querystring();
     307 No newline at end of file
    257308        $result['feed_url'] = apply_filters( 'bp_dtheme_ajax_feed_url', $feed_url );
    258309
  • bp-themes/bp-default/activity/activity-loop.php

     	/* Buffer the loop in the template to a var for JS to spit out. */
     
    22
    33<?php do_action( 'bp_before_activity_loop' ) ?>
    44
    5 <?php if ( bp_has_activities( bp_ajax_querystring() ) ) : ?>
    6  No newline at end of file
     5<?php if ( bp_has_activities( bp_dtheme_ajax_querystring( 'activity' ) ) ) : ?>
     6 No newline at end of file
    77
    88        <?php /* Show pagination if JS is not enabled, since the "Load More" link will do nothing */ ?>
  • bp-themes/bp-default/blogs/blogs-loop.php

     	<noscript>
     
    22
    33<?php do_action( 'bp_before_blogs_loop' ) ?>
    44
    5 <?php if ( bp_has_blogs( bp_ajax_querystring() ) ) : ?>
     5<?php if ( bp_has_blogs( bp_dtheme_ajax_querystring( 'blogs' ) ) ) : ?>
    66
    77        <div class="pagination">
    88
  • bp-themes/bp-default/forums/forums-loop.php

     
    1 <?php if ( bp_has_forum_topics( bp_ajax_querystring() ) ) : ?>
    2  No newline at end of file
     1<?php if ( bp_has_forum_topics( bp_dtheme_ajax_querystring( 'forums' ) ) ) : ?>
     2 No newline at end of file
    33
    44        <div class="pagination">
  • bp-themes/bp-default/groups/groups-loop.php

     
     
    22
    33<?php do_action( 'bp_before_groups_loop' ) ?>
    44
    5 <?php if ( bp_has_groups( bp_ajax_querystring() ) ) : ?>
    6  No newline at end of file
     5<?php if ( bp_has_groups( bp_dtheme_ajax_querystring( 'groups' ) ) ) : ?>
     6 No newline at end of file
    77
    88        <div class="pagination">
  • bp-themes/bp-default/members/members-loop.php

     
     
    22
    33<?php do_action( 'bp_before_members_loop' ) ?>
    44
    5 <?php if ( bp_has_members( bp_ajax_querystring() ) ) : ?>
    6  No newline at end of file
     5<?php if ( bp_has_members( bp_dtheme_ajax_querystring( 'members' ) ) ) : ?>
     6 No newline at end of file
    77
    88        <div class="pagination">