- Timestamp:
- 08/25/2016 06:18:01 PM (8 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-simplepie-sanitize-kses.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_Sanitize_KSES 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 164 /**165 * Core class for fetching remote files and reading local files with SimplePie.166 *167 * @since 2.8.0168 *169 * @see SimplePie_File170 */171 class WP_SimplePie_File extends SimplePie_File {172 173 /**174 * Constructor.175 *176 * @since 2.8.0177 * @since 3.2.0 Updated to use a PHP5 constructor.178 * @access public179 *180 * @param string $url Remote file URL.181 * @param integer $timeout Optional. How long the connection should stay open in seconds.182 * Default 10.183 * @param integer $redirects Optional. The number of allowed redirects. Default 5.184 * @param string|array $headers Optional. Array or string of headers to send with the request.185 * Default null.186 * @param string $useragent Optional. User-agent value sent. Default null.187 * @param boolean $force_fsockopen Optional. Whether to force opening internet or unix domain socket188 * connection or not. Default false.189 */190 public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) {191 $this->url = $url;192 $this->timeout = $timeout;193 $this->redirects = $redirects;194 $this->headers = $headers;195 $this->useragent = $useragent;196 197 $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;198 199 if ( preg_match('/^http(s)?:\/\//i', $url) ) {200 $args = array(201 'timeout' => $this->timeout,202 'redirection' => $this->redirects,203 );204 205 if ( !empty($this->headers) )206 $args['headers'] = $this->headers;207 208 if ( SIMPLEPIE_USERAGENT != $this->useragent ) //Use default WP user agent unless custom has been specified209 $args['user-agent'] = $this->useragent;210 211 $res = wp_safe_remote_request($url, $args);212 213 if ( is_wp_error($res) ) {214 $this->error = 'WP HTTP Error: ' . $res->get_error_message();215 $this->success = false;216 } else {217 $this->headers = wp_remote_retrieve_headers( $res );218 $this->body = wp_remote_retrieve_body( $res );219 $this->status_code = wp_remote_retrieve_response_code( $res );220 }221 } else {222 $this->error = '';223 $this->success = false;224 }225 }226 }227 9 228 10 /**
Note: See TracChangeset
for help on using the changeset viewer.