wp/wp-includes/SimplePie/src/Cache/DB.php
changeset 22 8c2e4d02f4ef
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * SimplePie
       
     5  *
       
     6  * A PHP-Based RSS and Atom Feed Framework.
       
     7  * Takes the hard work out of managing a complete RSS/Atom solution.
       
     8  *
       
     9  * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
       
    10  * All rights reserved.
       
    11  *
       
    12  * Redistribution and use in source and binary forms, with or without modification, are
       
    13  * permitted provided that the following conditions are met:
       
    14  *
       
    15  * 	* Redistributions of source code must retain the above copyright notice, this list of
       
    16  * 	  conditions and the following disclaimer.
       
    17  *
       
    18  * 	* Redistributions in binary form must reproduce the above copyright notice, this list
       
    19  * 	  of conditions and the following disclaimer in the documentation and/or other materials
       
    20  * 	  provided with the distribution.
       
    21  *
       
    22  * 	* Neither the name of the SimplePie Team nor the names of its contributors may be used
       
    23  * 	  to endorse or promote products derived from this software without specific prior
       
    24  * 	  written permission.
       
    25  *
       
    26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
       
    27  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
       
    28  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
       
    29  * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
       
    30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
       
    31  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    32  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
       
    33  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
       
    34  * POSSIBILITY OF SUCH DAMAGE.
       
    35  *
       
    36  * @package SimplePie
       
    37  * @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
       
    38  * @author Ryan Parman
       
    39  * @author Sam Sneddon
       
    40  * @author Ryan McCue
       
    41  * @link http://simplepie.org/ SimplePie
       
    42  * @license http://www.opensource.org/licenses/bsd-license.php BSD License
       
    43  */
       
    44 
       
    45 namespace SimplePie\Cache;
       
    46 
       
    47 /**
       
    48  * Base class for database-based caches
       
    49  *
       
    50  * @package SimplePie
       
    51  * @subpackage Caching
       
    52  * @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead
       
    53  */
       
    54 abstract class DB implements Base
       
    55 {
       
    56     /**
       
    57      * Helper for database conversion
       
    58      *
       
    59      * Converts a given {@see SimplePie} object into data to be stored
       
    60      *
       
    61      * @param \SimplePie\SimplePie $data
       
    62      * @return array First item is the serialized data for storage, second item is the unique ID for this item
       
    63      */
       
    64     protected static function prepare_simplepie_object_for_cache($data)
       
    65     {
       
    66         $items = $data->get_items();
       
    67         $items_by_id = [];
       
    68 
       
    69         if (!empty($items)) {
       
    70             foreach ($items as $item) {
       
    71                 $items_by_id[$item->get_id()] = $item;
       
    72             }
       
    73 
       
    74             if (count($items_by_id) !== count($items)) {
       
    75                 $items_by_id = [];
       
    76                 foreach ($items as $item) {
       
    77                     $items_by_id[$item->get_id(true)] = $item;
       
    78                 }
       
    79             }
       
    80 
       
    81             if (isset($data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0])) {
       
    82                 $channel = &$data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0];
       
    83             } elseif (isset($data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0])) {
       
    84                 $channel = &$data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0];
       
    85             } elseif (isset($data->data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0])) {
       
    86                 $channel = &$data->data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0];
       
    87             } elseif (isset($data->data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0]['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['channel'][0])) {
       
    88                 $channel = &$data->data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0]['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['channel'][0];
       
    89             } else {
       
    90                 $channel = null;
       
    91             }
       
    92 
       
    93             if ($channel !== null) {
       
    94                 if (isset($channel['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['entry'])) {
       
    95                     unset($channel['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['entry']);
       
    96                 }
       
    97                 if (isset($channel['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['entry'])) {
       
    98                     unset($channel['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['entry']);
       
    99                 }
       
   100                 if (isset($channel['child'][\SimplePie\SimplePie::NAMESPACE_RSS_10]['item'])) {
       
   101                     unset($channel['child'][\SimplePie\SimplePie::NAMESPACE_RSS_10]['item']);
       
   102                 }
       
   103                 if (isset($channel['child'][\SimplePie\SimplePie::NAMESPACE_RSS_090]['item'])) {
       
   104                     unset($channel['child'][\SimplePie\SimplePie::NAMESPACE_RSS_090]['item']);
       
   105                 }
       
   106                 if (isset($channel['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['item'])) {
       
   107                     unset($channel['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['item']);
       
   108                 }
       
   109             }
       
   110             if (isset($data->data['items'])) {
       
   111                 unset($data->data['items']);
       
   112             }
       
   113             if (isset($data->data['ordered_items'])) {
       
   114                 unset($data->data['ordered_items']);
       
   115             }
       
   116         }
       
   117         return [serialize($data->data), $items_by_id];
       
   118     }
       
   119 }
       
   120 
       
   121 class_alias('SimplePie\Cache\DB', 'SimplePie_Cache_DB');