Make WordPress Core

Ticket #50159: #50159-v2.patch

File #50159-v2.patch, 4.7 KB (added by arena, 5 years ago)

new patch as required by @SergeyBiryukov

  • wp-includes/class-wp-feed-cache-transient.php

     
    1212 *
    1313 * @since 2.8.0
    1414 */
    15 class WP_Feed_Cache_Transient {
     15class WP_Feed_Cache_Transient implements SimplePie_Cache_Base {
    1616
    1717        /**
    1818         * Holds the transient name.
     
    4848         *
    4949         * @param string $location  URL location (scheme is used to determine handler).
    5050         * @param string $filename  Unique identifier for cache object.
    51          * @param string $extension 'spi' or 'spc'.
     51         * @param string $extension 'spc' (Feed cache type) or 'spi' (Image cache type)
    5252         */
    5353        public function __construct( $location, $filename, $extension ) {
    54                 $this->name     = 'feed_' . $filename;
    55                 $this->mod_name = 'feed_mod_' . $filename;
     54                $this->name     = 'feed_' . md5( "$filename:$extension" );
     55                $this->mod_name = 'feed_mod_' . md5( "$filename:$extension" );
    5656
    57                 $lifetime = $this->lifetime;
    58                 /**
    59                  * Filters the transient lifetime of the feed cache.
    60                  *
    61                  * @since 2.8.0
    62                  *
    63                  * @param int    $lifetime Cache duration in seconds. Default is 43200 seconds (12 hours).
    64                  * @param string $filename Unique identifier for the cache object.
    65                  */
    66                 $this->lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', $lifetime, $filename );
     57                $options = $this->parse_location( $location );
     58                $this->lifetime = $options['extras']['lifetime'];
    6759        }
    6860
    6961        /**
     
    129121                delete_transient( $this->mod_name );
    130122                return true;
    131123        }
     124
     125        /**
     126         * Parse location.
     127         *
     128         * @since 5.5.0
     129         *
     130         * @param string $location  URL location (scheme is used to determine handler).
     131         * @return array location parameters
     132         */
     133        public function parse_location( $location ) {
     134                $params = parse_url( $location );
     135                $params['extras'] = array();
     136                if ( isset( $params['query'] ) )
     137                {
     138                        parse_str( $params['query'], $params['extras'] );
     139                }
     140                return $params;
     141        }
    132142}
  • wp-includes/class-wp-feed-cache.php

     
    1717class WP_Feed_Cache extends SimplePie_Cache {
    1818
    1919        /**
     20         * Cache handler class
     21         *
     22         * @var array
     23         */
     24        protected static $handlers = array(
     25                'wordpress' => 'WP_Feed_Cache_Transient',
     26        );
     27
     28        /**
    2029         * Creates a new SimplePie_Cache object.
    2130         *
    2231         * @since 2.8.0
     
    2635         * @param string $extension 'spi' or 'spc'.
    2736         * @return WP_Feed_Cache_Transient Feed cache handler object that uses transients.
    2837         */
    29         public function create( $location, $filename, $extension ) {
     38        public static function get_handler( $location, $filename, $extension ) {
    3039                return new WP_Feed_Cache_Transient( $location, $filename, $extension );
    3140        }
     41
     42        /**
     43         * Creates a new SimplePie_Cache object.
     44         *
     45         * see get_handler()
     46         */
     47        public function create( $location, $filename, $extension ) {
     48                return self::get_handler($location, $filename, $extension);
     49        }
    3250}
     51
  • wp-includes/feed.php

     
    760760
    761761        $feed = new SimplePie();
    762762
    763         $feed->set_sanitize_class( 'WP_SimplePie_Sanitize_KSES' );
    764         // We must manually overwrite $feed->sanitize because SimplePie's
    765         // constructor sets it before we have a chance to set the sanitization class.
    766         $feed->sanitize = new WP_SimplePie_Sanitize_KSES();
     763        // No need to overwrite $feed->sanitize anymore, SimplePie do it right now
     764        $feed->registry->register( 'Sanitize', 'WP_SimplePie_Sanitize_KSES', true );
     765        $feed->registry->register( 'File', 'WP_SimplePie_File', true );
     766        $feed->registry->register( 'Cache', 'WP_Feed_Cache', true );
    767767
    768         $feed->set_cache_class( 'WP_Feed_Cache' );
    769         $feed->set_file_class( 'WP_SimplePie_File' );
     768        /**
     769         * Filters the transient lifetime of the feed cache.
     770         *
     771         * @since 2.8.0
     772         *
     773         * @param int    $lifetime Cache duration in seconds. Default is 12 hours.
     774         * @param string $filename Unique identifier for the cache object.
     775         */
     776        $lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url );
    770777
     778        $feed->set_cache_duration( $lifetime );
     779        $feed->set_cache_location( 'wordpress://transient?lifetime=' . $lifetime );
    771780        $feed->set_feed_url( $url );
    772         /** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */
    773         $feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url ) );
     781
    774782        /**
    775783         * Fires just before processing the SimplePie feed object.
    776784         *