Changeset 38354 for trunk/src/wp-includes/class-wp-simplepie-file.php
- Timestamp:
- 08/25/2016 06:18:01 PM (10 years ago)
- File:
-
- 1 copied
-
trunk/src/wp-includes/class-wp-simplepie-file.php (copied) (copied from trunk/src/wp-includes/class-feed.php ) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-simplepie-file.php
r38350 r38354 1 1 <?php 2 3 if ( ! class_exists( 'SimplePie', false ) )4 require_once( ABSPATH . WPINC . '/class-simplepie.php' );5 6 2 /** 7 * Core class used to implement a feed cache.3 * Feed API: WP_SimplePie_File class 8 4 * 9 * @ since 2.8.010 * 11 * @s ee SimplePie_Cache5 * @package WordPress 6 * @subpackage Feed 7 * @since 4.7.0 12 8 */ 13 class WP_Feed_Cache extends SimplePie_Cache {14 15 /**16 * Creates a new SimplePie_Cache object.17 *18 * @since 2.8.019 * @access public20 *21 * @param string $location URL location (scheme is used to determine handler).22 * @param string $filename Unique identifier for cache object.23 * @param string $extension 'spi' or 'spc'.24 * @return WP_Feed_Cache_Transient Feed cache handler object that uses transients.25 */26 public function create($location, $filename, $extension) {27 return new WP_Feed_Cache_Transient($location, $filename, $extension);28 }29 }30 31 /**32 * Core class used to implement feed cache transients.33 *34 * @since 2.8.035 */36 class WP_Feed_Cache_Transient {37 38 /**39 * Holds the transient name.40 *41 * @since 2.8.042 * @access public43 * @var string44 */45 public $name;46 47 /**48 * Holds the transient mod name.49 *50 * @since 2.8.051 * @access public52 * @var string53 */54 public $mod_name;55 56 /**57 * Holds the cache duration in seconds.58 *59 * Defaults to 43200 seconds (12 hours).60 *61 * @since 2.8.062 * @access public63 * @var int64 */65 public $lifetime = 43200;66 67 /**68 * Constructor.69 *70 * @since 2.8.071 * @since 3.2.0 Updated to use a PHP5 constructor.72 * @access public73 *74 * @param string $location URL location (scheme is used to determine handler).75 * @param string $filename Unique identifier for cache object.76 * @param string $extension 'spi' or 'spc'.77 */78 public function __construct($location, $filename, $extension) {79 $this->name = 'feed_' . $filename;80 $this->mod_name = 'feed_mod_' . $filename;81 82 $lifetime = $this->lifetime;83 /**84 * Filters the transient lifetime of the feed cache.85 *86 * @since 2.8.087 *88 * @param int $lifetime Cache duration in seconds. Default is 43200 seconds (12 hours).89 * @param string $filename Unique identifier for the cache object.90 */91 $this->lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', $lifetime, $filename);92 }93 94 /**95 * Sets the transient.96 *97 * @since 2.8.098 * @access public99 *100 * @param SimplePie $data Data to save.101 * @return true Always true.102 */103 public function save($data) {104 if ( $data instanceof SimplePie ) {105 $data = $data->data;106 }107 108 set_transient($this->name, $data, $this->lifetime);109 set_transient($this->mod_name, time(), $this->lifetime);110 return true;111 }112 113 /**114 * Gets the transient.115 *116 * @since 2.8.0117 * @access public118 *119 * @return mixed Transient value.120 */121 public function load() {122 return get_transient($this->name);123 }124 125 /**126 * Gets mod transient.127 *128 * @since 2.8.0129 * @access public130 *131 * @return mixed Transient value.132 */133 public function mtime() {134 return get_transient($this->mod_name);135 }136 137 /**138 * Sets mod transient.139 *140 * @since 2.8.0141 * @access public142 *143 * @return bool False if value was not set and true if value was set.144 */145 public function touch() {146 return set_transient($this->mod_name, time(), $this->lifetime);147 }148 149 /**150 * Deletes transients.151 *152 * @since 2.8.0153 * @access public154 *155 * @return true Always true.156 */157 public function unlink() {158 delete_transient($this->name);159 delete_transient($this->mod_name);160 return true;161 }162 }163 9 164 10 /** … … 225 71 } 226 72 } 227 228 /**229 * Core class used to implement SimpliePie feed sanitization.230 *231 * Extends the SimplePie_Sanitize class to use KSES, because232 * we cannot universally count on DOMDocument being available.233 *234 * @since 3.5.0235 *236 * @see SimplePie_Sanitize237 */238 class WP_SimplePie_Sanitize_KSES extends SimplePie_Sanitize {239 240 /**241 * WordPress SimplePie sanitization using KSES.242 *243 * Sanitizes the incoming data, to ensure that it matches the type of data expected, using KSES.244 *245 * @since 3.5.0246 * @access public247 *248 * @param mixed $data The data that needs to be sanitized.249 * @param integer $type The type of data that it's supposed to be.250 * @param string $base Optional. The `xml:base` value to use when converting relative251 * URLs to absolute ones. Default empty.252 * @return mixed Sanitized data.253 */254 public function sanitize( $data, $type, $base = '' ) {255 $data = trim( $data );256 if ( $type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML ) {257 if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data)) {258 $type |= SIMPLEPIE_CONSTRUCT_HTML;259 }260 else {261 $type |= SIMPLEPIE_CONSTRUCT_TEXT;262 }263 }264 if ( $type & SIMPLEPIE_CONSTRUCT_BASE64 ) {265 $data = base64_decode( $data );266 }267 if ( $type & ( SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML ) ) {268 $data = wp_kses_post( $data );269 if ( $this->output_encoding !== 'UTF-8' ) {270 $data = $this->registry->call( 'Misc', 'change_encoding', array( $data, 'UTF-8', $this->output_encoding ) );271 }272 return $data;273 } else {274 return parent::sanitize( $data, $type, $base );275 }276 }277 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)