Skip to:
Content

BuddyPress.org

Ticket #5213: 5213.01.patch

File 5213.01.patch, 3.2 KB (added by r-a-y, 11 years ago)
  • bp-activity/bp-activity-classes.php

    class BP_Activity_Feed { 
    12701270                }
    12711271        }
    12721272
    1273         /** OUTPUT ***************************************************************/
    1274 
    12751273        /**
    1276          * Output the RSS feed.
     1274         * Sets various HTTP headers related to Content-Type and browser caching.
     1275         *
     1276         * Most of this class method is derived from {@link WP::send_headers()}.
     1277         *
     1278         * @since BuddyPress (1.9.0)
    12771279         *
    12781280         * @access protected
    12791281         */
    1280         protected function output() {
     1282        protected function http_headers() {
    12811283                // set up some additional headers if not on a directory page
    12821284                // this is done b/c BP uses pseudo-pages
    12831285                if ( ! bp_is_directory() ) {
    class BP_Activity_Feed { 
    12871289                        status_header( 200 );
    12881290                }
    12891291
    1290                 header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
     1292                // Set content-type
     1293                @header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
     1294
     1295                // Cache-related variables
     1296                $last_modified      = mysql2date( 'D, d M Y H:i:s O', bp_activity_get_last_updated(), false );
     1297                $modified_timestamp = strtotime( $last_modified );
     1298                $etag               = md5( $last_modified );
     1299       
     1300                // Set cache-related headers
     1301                @header( 'Last-Modified: ' . $last_modified );
     1302                @header( 'Pragma: no-cache' );
     1303                @header( 'ETag: ' . '"' . $etag . '"' );
     1304       
     1305                // First commit of BuddyPress! (Easter egg)
     1306                @header( 'Expires: Tue, 25 Mar 2008 17:13:55 GMT');
     1307       
     1308                // Get ETag from supported user agents
     1309                if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) {
     1310                        $client_etag = wp_unslash( $_SERVER['HTTP_IF_NONE_MATCH'] );
     1311       
     1312                        // Remove quotes from ETag
     1313                        $client_etag = trim( $client_etag, '"' );
     1314       
     1315                        // Strip suffixes from ETag if they exist (eg. "-gzip")
     1316                        if ( $etag_suffix_pos = strpos( $client_etag, '-' ) ) {
     1317                                $client_etag = substr( $client_etag, 0, $etag_suffix_pos );
     1318                        }
     1319
     1320                // No ETag found
     1321                } else {
     1322                        $client_etag = false;
     1323                }
     1324       
     1325                // Get client last modified timestamp from supported user agents
     1326                $client_last_modified      = empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ? '' : trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
     1327                $client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0;
     1328       
     1329                // Set 304 status if feed hasn't been updated since last fetch
     1330                if ( ( $client_last_modified && $client_etag ) ?
     1331                                 ( ( $client_modified_timestamp >= $modified_timestamp ) && ( $client_etag == $etag ) ) :
     1332                                 ( ( $client_modified_timestamp >= $modified_timestamp ) || ( $client_etag == $etag ) ) ) {
     1333                        $status = 304;
     1334                } else {
     1335                        $status = false;
     1336                }
     1337       
     1338                // If feed hasn't changed as reported by the user agent, set 304 status header
     1339                if ( ! empty( $status ) ) {
     1340                        status_header( $status );
     1341       
     1342                        // cached response, so stop now!
     1343                        if ( $status == 304 ) {
     1344                                exit();
     1345                        }
     1346                }
     1347        }
     1348
     1349        /** OUTPUT ***************************************************************/
     1350
     1351        /**
     1352         * Output the RSS feed.
     1353         *
     1354         * @access protected
     1355         */
     1356        protected function output() {
     1357                $this->http_headers();
    12911358                echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?'.'>';
    12921359        ?>
    12931360