Make WordPress Core


Ignore:
Timestamp:
08/25/2016 06:18:01 PM (8 years ago)
Author:
wonderboymusic
Message:

Feed: move 'WP_Feed_Cache', 'WP_Feed_Cache_Transient', WP_SimplePie_File and WP_SimplePie_Sanitize_KSES into their own files via svn cp. If we move forard with autoloading, class-feed.php is useless. We could even remove it now, and just load these new files in wp-settings.php. That can be decided post-mortem. class-feed.php is an interesting name: there is no Feed or WP_Feed class.

See #37827.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-simplepie-sanitize-kses.php

    r38350 r38354  
    11<?php
    2 
    3 if ( ! class_exists( 'SimplePie', false ) )
    4     require_once( ABSPATH . WPINC . '/class-simplepie.php' );
    5 
    62/**
    7  * Core class used to implement a feed cache.
     3 * Feed API: WP_SimplePie_Sanitize_KSES class
    84 *
    9  * @since 2.8.0
    10  *
    11  * @see SimplePie_Cache
     5 * @package WordPress
     6 * @subpackage Feed
     7 * @since 4.7.0
    128 */
    13 class WP_Feed_Cache extends SimplePie_Cache {
    14 
    15     /**
    16      * Creates a new SimplePie_Cache object.
    17      *
    18      * @since 2.8.0
    19      * @access public
    20      *
    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.0
    35  */
    36 class WP_Feed_Cache_Transient {
    37 
    38     /**
    39      * Holds the transient name.
    40      *
    41      * @since 2.8.0
    42      * @access public
    43      * @var string
    44      */
    45     public $name;
    46 
    47     /**
    48      * Holds the transient mod name.
    49      *
    50      * @since 2.8.0
    51      * @access public
    52      * @var string
    53      */
    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.0
    62      * @access public
    63      * @var int
    64      */
    65     public $lifetime = 43200;
    66 
    67     /**
    68      * Constructor.
    69      *
    70      * @since 2.8.0
    71      * @since 3.2.0 Updated to use a PHP5 constructor.
    72      * @access public
    73      *
    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.0
    87          *
    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.0
    98      * @access public
    99      *
    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.0
    117      * @access public
    118      *
    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.0
    129      * @access public
    130      *
    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.0
    141      * @access public
    142      *
    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.0
    153      * @access public
    154      *
    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.0
    168  *
    169  * @see SimplePie_File
    170  */
    171 class WP_SimplePie_File extends SimplePie_File {
    172 
    173     /**
    174      * Constructor.
    175      *
    176      * @since 2.8.0
    177      * @since 3.2.0 Updated to use a PHP5 constructor.
    178      * @access public
    179      *
    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 socket
    188      *                                      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 specified
    209                 $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 }
    2279
    22810/**
Note: See TracChangeset for help on using the changeset viewer.