Ticket #50159: #50159.patch
File #50159.patch, 11.7 KB (added by , 4 years ago) |
---|
-
wp-includes/class-wp-feed-cache-transient.php
1 1 <?php 2 2 /** 3 * Feed API : WP_Feed_Cache_Transient class3 * Feed API 4 4 * 5 * This file is deprecated, use 'wp-includes/class-wp-simplepie-cache-transient.php' instead. 6 * 7 * @deprecated 5.5.0 5 8 * @package WordPress 6 9 * @subpackage Feed 7 * @since 4.7.08 10 */ 9 11 10 /** 11 * Core class used to implement feed cache transients. 12 * 13 * @since 2.8.0 14 */ 15 class WP_Feed_Cache_Transient { 12 _deprecated_file( basename( __FILE__ ), '5.5.0', 'wp-includes/class-wp-simplepie-cache-transient.php' ); 16 13 17 /** 18 * Holds the transient name. 19 * 20 * @since 2.8.0 21 * @var string 22 */ 23 public $name; 14 /** WordPress Feed API: Includes Core class used to implement a feed cache transients. */ 15 require_once ABSPATH . 'wp-includes/class-wp-simplepie-cache-transient.php'; 24 16 25 /** 26 * Holds the transient mod name. 27 * 28 * @since 2.8.0 29 * @var string 30 */ 31 public $mod_name; 32 33 /** 34 * Holds the cache duration in seconds. 35 * 36 * Defaults to 43200 seconds (12 hours). 37 * 38 * @since 2.8.0 39 * @var int 40 */ 41 public $lifetime = 43200; 42 43 /** 44 * Constructor. 45 * 46 * @since 2.8.0 47 * @since 3.2.0 Updated to use a PHP5 constructor. 48 * 49 * @param string $location URL location (scheme is used to determine handler). 50 * @param string $filename Unique identifier for cache object. 51 * @param string $extension 'spi' or 'spc'. 52 */ 53 public function __construct( $location, $filename, $extension ) { 54 $this->name = 'feed_' . $filename; 55 $this->mod_name = 'feed_mod_' . $filename; 56 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 ); 67 } 68 69 /** 70 * Sets the transient. 71 * 72 * @since 2.8.0 73 * 74 * @param SimplePie $data Data to save. 75 * @return true Always true. 76 */ 77 public function save( $data ) { 78 if ( $data instanceof SimplePie ) { 79 $data = $data->data; 80 } 81 82 set_transient( $this->name, $data, $this->lifetime ); 83 set_transient( $this->mod_name, time(), $this->lifetime ); 84 return true; 85 } 86 87 /** 88 * Gets the transient. 89 * 90 * @since 2.8.0 91 * 92 * @return mixed Transient value. 93 */ 94 public function load() { 95 return get_transient( $this->name ); 96 } 97 98 /** 99 * Gets mod transient. 100 * 101 * @since 2.8.0 102 * 103 * @return mixed Transient value. 104 */ 105 public function mtime() { 106 return get_transient( $this->mod_name ); 107 } 108 109 /** 110 * Sets mod transient. 111 * 112 * @since 2.8.0 113 * 114 * @return bool False if value was not set and true if value was set. 115 */ 116 public function touch() { 117 return set_transient( $this->mod_name, time(), $this->lifetime ); 118 } 119 120 /** 121 * Deletes transients. 122 * 123 * @since 2.8.0 124 * 125 * @return true Always true. 126 */ 127 public function unlink() { 128 delete_transient( $this->name ); 129 delete_transient( $this->mod_name ); 130 return true; 131 } 132 } 17 class_alias( 'WP_SimplePie_Cache_Transient', 'WP_Feed_Cache_Transient' ); -
wp-includes/class-wp-feed-cache.php
1 1 <?php 2 2 /** 3 * Feed API : WP_Feed_Cache class3 * Feed API 4 4 * 5 * This file is deprecated, use 'wp-includes/class-wp-simplepie-cache.php' instead. 6 * 7 * @deprecated 5.5.0 5 8 * @package WordPress 6 9 * @subpackage Feed 7 * @since 4.7.08 10 */ 9 11 10 /** 11 * Core class used to implement a feed cache. 12 * 13 * @since 2.8.0 14 * 15 * @see SimplePie_Cache 16 */ 17 class WP_Feed_Cache extends SimplePie_Cache { 12 _deprecated_file( basename( __FILE__ ), '5.5.0', 'wp-includes/class-wp-simplepie-cache.php' ); 18 13 19 /** 20 * Creates a new SimplePie_Cache object. 21 * 22 * @since 2.8.0 23 * 24 * @param string $location URL location (scheme is used to determine handler). 25 * @param string $filename Unique identifier for cache object. 26 * @param string $extension 'spi' or 'spc'. 27 * @return WP_Feed_Cache_Transient Feed cache handler object that uses transients. 28 */ 29 public function create( $location, $filename, $extension ) { 30 return new WP_Feed_Cache_Transient( $location, $filename, $extension ); 31 } 32 } 14 /** WordPress Feed API: Includes Core class used to implement a feed cache. */ 15 require_once ABSPATH . 'wp-includes/class-wp-simplepie-cache.php'; 16 17 class_alias( 'WP_SimplePie_Cache', 'WP_Feed_Cache' ); -
wp-includes/class-wp-simplepie-cache-transient.php
1 <?php 2 /** 3 * Feed API: WP_SimplePie_Cache_Transient class 4 * 5 * @package WordPress 6 * @subpackage Feed 7 * @since 4.7.0 8 */ 9 10 /** 11 * Core class used to implement feed cache transients. 12 * 13 * @since 2.8.0 14 */ 15 class WP_SimplePie_Cache_Transient implements SimplePie_Cache_Base { 16 17 /** 18 * Holds the transient name. 19 * 20 * @since 2.8.0 21 * @var string 22 */ 23 public $name; 24 25 /** 26 * Holds the transient mod name. 27 * 28 * @since 2.8.0 29 * @var string 30 */ 31 public $mod_name; 32 33 /** 34 * Holds the cache duration in seconds. 35 * 36 * Defaults to 43200 seconds (12 hours). 37 * 38 * @since 2.8.0 39 * @var int 40 */ 41 public $lifetime = 43200; 42 43 /** 44 * Constructor. 45 * 46 * @since 2.8.0 47 * @since 3.2.0 Updated to use a PHP5 constructor. 48 * 49 * @param string $location URL location (scheme is used to determine handler). 50 * @param string $filename Unique identifier for cache object. 51 * @param string $extension 'spi' or 'spc'. 52 */ 53 public function __construct( $location, $filename, $extension ) { 54 $this->name = 'feed_' . md5( "$filename:$extension" ); 55 $this->mod_name = 'feed_mod_' . md5( "$filename:$extension" ); 56 57 $options = $this->parse_location( $location ); 58 $this->lifetime = $options['extras']['lifetime']; 59 } 60 61 /** 62 * Sets the transient. 63 * 64 * @since 2.8.0 65 * 66 * @param SimplePie $data Data to save. 67 * @return true Always true. 68 */ 69 public function save( $data ) { 70 if ( $data instanceof SimplePie ) { 71 $data = $data->data; 72 } 73 74 set_transient( $this->name, $data, $this->lifetime ); 75 set_transient( $this->mod_name, time(), $this->lifetime ); 76 return true; 77 } 78 79 /** 80 * Gets the transient. 81 * 82 * @since 2.8.0 83 * 84 * @return mixed Transient value. 85 */ 86 public function load() { 87 return get_transient( $this->name ); 88 } 89 90 /** 91 * Gets mod transient. 92 * 93 * @since 2.8.0 94 * 95 * @return mixed Transient value. 96 */ 97 public function mtime() { 98 return get_transient( $this->mod_name ); 99 } 100 101 /** 102 * Sets mod transient. 103 * 104 * @since 2.8.0 105 * 106 * @return bool False if value was not set and true if value was set. 107 */ 108 public function touch() { 109 return set_transient( $this->mod_name, time(), $this->lifetime ); 110 } 111 112 /** 113 * Deletes transients. 114 * 115 * @since 2.8.0 116 * 117 * @return true Always true. 118 */ 119 public function unlink() { 120 delete_transient( $this->name ); 121 delete_transient( $this->mod_name ); 122 return true; 123 } 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 { 135 $params = parse_url( $location ); 136 $params['extras'] = array(); 137 if ( isset( $params['query'] ) ) 138 { 139 parse_str( $params['query'], $params['extras'] ); 140 } 141 return $params; 142 } 143 } -
wp-includes/class-wp-simplepie-cache.php
1 <?php 2 /** 3 * Feed API: WP_SimplePie_Cache class 4 * 5 * @package WordPress 6 * @subpackage Feed 7 * @since 5.5.0 8 */ 9 10 /** 11 * Core class used to implement a feed cache. 12 * 13 * @since 5.5.0 14 * 15 * @see SimplePie_Cache 16 */ 17 class WP_SimplePie_Cache extends SimplePie_Cache { 18 19 /** 20 * Cache handler class 21 * 22 * These receive 3 parameters to their constructor, as documented in 23 * {@see SimplePie_Registry->register()} 24 * @var array 25 */ 26 protected static $handlers = array( 27 'wordpress' => 'WP_SimplePie_Cache_Transient', 28 ); 29 30 /** 31 * Creates a new SimplePie_Cache object. 32 * 33 * @param string $location URL location (scheme is used to determine handler) 34 * @param string $filename Unique identifier for cache object 35 * @param string $extension 'spi' or 'spc' 36 * @return WP_SimplePie_Cache_Transient SimplePie cache handler object that uses transients. 37 */ 38 public static function get_handler( $location, $filename, $extension ) { 39 return new WP_SimplePie_Cache_Transient( $location, $filename, $extension ); 40 } 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 } 50 } -
wp-includes/feed.php
753 753 require_once ABSPATH . WPINC . '/class-simplepie.php'; 754 754 } 755 755 756 require_once ABSPATH . WPINC . '/class-wp- feed-cache.php';757 require_once ABSPATH . WPINC . '/class-wp- feed-cache-transient.php';756 require_once ABSPATH . WPINC . '/class-wp-simplepie-cache.php'; 757 require_once ABSPATH . WPINC . '/class-wp-simplepie-cache-transient.php'; 758 758 require_once ABSPATH . WPINC . '/class-wp-simplepie-file.php'; 759 759 require_once ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.php'; 760 760 761 761 $feed = new SimplePie(); 762 762 763 $feed->set_sanitize_class( 'WP_SimplePie_Sanitize_KSES' );764 // We must manually overwrite $feed->sanitize because SimplePie's765 // 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_SimplePie_Cache', true ); 767 767 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 ); 770 777 778 $feed->set_cache_duration( $lifetime ); 779 $feed->set_cache_location( 'wordpress://transient?lifetime=' . $lifetime ); 771 780 $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 774 782 /** 775 783 * Fires just before processing the SimplePie feed object. 776 784 *