Make WordPress Core


Ignore:
Timestamp:
09/30/2024 10:48:16 PM (6 months ago)
Author:
SergeyBiryukov
Message:

External Libraries: Update the SimplePie library to version 1.8.0.

The most notable change in this update is that all code is now namespaced and uses PSR-4 classes, though there is a compatibility layer available for extenders using the older class names, so plugin or theme authors directly using SimplePie can decide for themselves when they want to change to using the namespaced names for SimplePie classes.

Note: This commit includes additional fixes for PHP 8.4 compatibility (PR 875, PR 888) from the one-dot-eight branch of SimplePie, which is expected to be released as SimplePie 1.8.1 soon.

References:

Follow-up to [47733], [49176], [52393], [52413].

Props jrf, peterwilsoncc, chaion07, cu121, markparnell, audrasjb, costdev, Presskopp, desrosj, faisal03, mukesh27, SergeyBiryukov.
See #55604.

Location:
trunk/src/wp-includes/SimplePie/src
Files:
1 added
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/SimplePie/src/Cache/Memcache.php

    r47733 r59141  
    11<?php
     2
    23/**
    34 * SimplePie
     
    67 * Takes the hard work out of managing a complete RSS/Atom solution.
    78 *
    8  * Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
     9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
    910 * All rights reserved.
    1011 *
     
    4243 */
    4344
     45namespace SimplePie\Cache;
     46
     47use Memcache as NativeMemcache;
     48
    4449/**
    4550 * Caches data to memcache
     
    5459 * @subpackage Caching
    5560 * @uses Memcache
     61 * @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead
    5662 */
    57 class SimplePie_Cache_Memcache implements SimplePie_Cache_Base
     63class Memcache implements Base
    5864{
    59     /**
    60     * Memcache instance
    61     *
    62     * @var Memcache
    63     */
    64     protected $cache;
     65    /**
     66    * Memcache instance
     67    *
     68    * @var Memcache
     69    */
     70    protected $cache;
    6571
    66     /**
    67     * Options
    68     *
    69     * @var array
    70     */
    71     protected $options;
     72    /**
     73    * Options
     74    *
     75    * @var array
     76    */
     77    protected $options;
    7278
    73     /**
    74     * Cache name
    75     *
    76     * @var string
    77     */
    78     protected $name;
     79    /**
     80    * Cache name
     81    *
     82    * @var string
     83    */
     84    protected $name;
    7985
    80     /**
    81     * Create a new cache object
    82     *
    83     * @param string $location Location string (from SimplePie::$cache_location)
    84     * @param string $name Unique ID for the cache
    85      * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
    86     */
    87     public function __construct($location, $name, $type)
    88     {
    89         $this->options = array(
    90             'host' => '127.0.0.1',
    91             'port' => 11211,
    92             'extras' => array(
    93                 'timeout' => 3600, // one hour
    94                 'prefix' => 'simplepie_',
    95             ),
    96         );
    97         $this->options = SimplePie_Misc::array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));
     86    /**
     87    * Create a new cache object
     88    *
     89    * @param string $location Location string (from SimplePie::$cache_location)
     90    * @param string $name Unique ID for the cache
     91     * @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
     92    */
     93    public function __construct($location, $name, $type)
     94    {
     95        $this->options = [
     96            'host' => '127.0.0.1',
     97            'port' => 11211,
     98            'extras' => [
     99                'timeout' => 3600, // one hour
     100                'prefix' => 'simplepie_',
     101            ],
     102        ];
     103        $this->options = array_replace_recursive($this->options, \SimplePie\Cache::parse_URL($location));
    98104
    99         $this->name = $this->options['extras']['prefix'] . md5("$name:$type");
     105        $this->name = $this->options['extras']['prefix'] . md5("$name:$type");
    100106
    101         $this->cache = new Memcache();
    102         $this->cache->addServer($this->options['host'], (int) $this->options['port']);
    103     }
     107        $this->cache = new NativeMemcache();
     108        $this->cache->addServer($this->options['host'], (int) $this->options['port']);
     109    }
    104110
    105     /**
    106      * Save data to the cache
    107      *
    108      * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
    109      * @return bool Successfulness
    110      */
    111     public function save($data)
    112     {
    113         if ($data instanceof SimplePie)
    114         {
    115             $data = $data->data;
    116         }
    117         return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
    118     }
     111    /**
     112     * Save data to the cache
     113     *
     114     * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
     115     * @return bool Successfulness
     116     */
     117    public function save($data)
     118    {
     119        if ($data instanceof \SimplePie\SimplePie) {
     120            $data = $data->data;
     121        }
     122        return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
     123    }
    119124
    120     /**
    121     * Retrieve the data saved to the cache
    122     *
    123     * @return array Data for SimplePie::$data
    124     */
    125     public function load()
    126     {
    127         $data = $this->cache->get($this->name);
     125    /**
     126    * Retrieve the data saved to the cache
     127    *
     128    * @return array Data for SimplePie::$data
     129    */
     130    public function load()
     131    {
     132        $data = $this->cache->get($this->name);
    128133
    129         if ($data !== false)
    130         {
    131             return unserialize($data);
    132         }
    133         return false;
    134     }
     134        if ($data !== false) {
     135            return unserialize($data);
     136        }
     137        return false;
     138    }
    135139
    136     /**
    137     * Retrieve the last modified time for the cache
    138     *
    139     * @return int Timestamp
    140     */
    141     public function mtime()
    142     {
    143         $data = $this->cache->get($this->name);
     140    /**
     141    * Retrieve the last modified time for the cache
     142    *
     143    * @return int Timestamp
     144    */
     145    public function mtime()
     146    {
     147        $data = $this->cache->get($this->name);
    144148
    145         if ($data !== false)
    146         {
    147             // essentially ignore the mtime because Memcache expires on its own
    148             return time();
    149         }
     149        if ($data !== false) {
     150            // essentially ignore the mtime because Memcache expires on its own
     151            return time();
     152        }
    150153
    151         return false;
    152     }
     154        return false;
     155    }
    153156
    154     /**
    155     * Set the last modified time to the current time
    156     *
    157     * @return bool Success status
    158     */
    159     public function touch()
    160     {
    161         $data = $this->cache->get($this->name);
     157    /**
     158    * Set the last modified time to the current time
     159    *
     160    * @return bool Success status
     161    */
     162    public function touch()
     163    {
     164        $data = $this->cache->get($this->name);
    162165
    163         if ($data !== false)
    164         {
    165             return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
    166         }
     166        if ($data !== false) {
     167            return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
     168        }
    167169
    168         return false;
    169     }
     170        return false;
     171    }
    170172
    171     /**
    172     * Remove the cache
    173     *
    174     * @return bool Success status
    175     */
    176     public function unlink()
    177     {
    178         return $this->cache->delete($this->name, 0);
    179     }
     173    /**
     174    * Remove the cache
     175    *
     176    * @return bool Success status
     177    */
     178    public function unlink()
     179    {
     180        return $this->cache->delete($this->name, 0);
     181    }
    180182}
     183
     184class_alias('SimplePie\Cache\Memcache', 'SimplePie_Cache_Memcache');
Note: See TracChangeset for help on using the changeset viewer.