xref: /dokuwiki/vendor/simplepie/simplepie/library/SimplePie/Cache/DB.php (revision ab0a890215a63de8e7fa87cabb58ea30949afe42)
159b616ccSAndreas Gohr<?php
259b616ccSAndreas Gohr/**
359b616ccSAndreas Gohr * SimplePie
459b616ccSAndreas Gohr *
559b616ccSAndreas Gohr * A PHP-Based RSS and Atom Feed Framework.
659b616ccSAndreas Gohr * Takes the hard work out of managing a complete RSS/Atom solution.
759b616ccSAndreas Gohr *
8*ab0a8902SAndreas Gohr * Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
959b616ccSAndreas Gohr * All rights reserved.
1059b616ccSAndreas Gohr *
1159b616ccSAndreas Gohr * Redistribution and use in source and binary forms, with or without modification, are
1259b616ccSAndreas Gohr * permitted provided that the following conditions are met:
1359b616ccSAndreas Gohr *
1459b616ccSAndreas Gohr * 	* Redistributions of source code must retain the above copyright notice, this list of
1559b616ccSAndreas Gohr * 	  conditions and the following disclaimer.
1659b616ccSAndreas Gohr *
1759b616ccSAndreas Gohr * 	* Redistributions in binary form must reproduce the above copyright notice, this list
1859b616ccSAndreas Gohr * 	  of conditions and the following disclaimer in the documentation and/or other materials
1959b616ccSAndreas Gohr * 	  provided with the distribution.
2059b616ccSAndreas Gohr *
2159b616ccSAndreas Gohr * 	* Neither the name of the SimplePie Team nor the names of its contributors may be used
2259b616ccSAndreas Gohr * 	  to endorse or promote products derived from this software without specific prior
2359b616ccSAndreas Gohr * 	  written permission.
2459b616ccSAndreas Gohr *
2559b616ccSAndreas Gohr * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
2659b616ccSAndreas Gohr * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
2759b616ccSAndreas Gohr * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
2859b616ccSAndreas Gohr * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2959b616ccSAndreas Gohr * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
3059b616ccSAndreas Gohr * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3159b616ccSAndreas Gohr * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
3259b616ccSAndreas Gohr * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3359b616ccSAndreas Gohr * POSSIBILITY OF SUCH DAMAGE.
3459b616ccSAndreas Gohr *
3559b616ccSAndreas Gohr * @package SimplePie
36*ab0a8902SAndreas Gohr * @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
3759b616ccSAndreas Gohr * @author Ryan Parman
38*ab0a8902SAndreas Gohr * @author Sam Sneddon
3959b616ccSAndreas Gohr * @author Ryan McCue
4059b616ccSAndreas Gohr * @link http://simplepie.org/ SimplePie
4159b616ccSAndreas Gohr * @license http://www.opensource.org/licenses/bsd-license.php BSD License
4259b616ccSAndreas Gohr */
4359b616ccSAndreas Gohr
4459b616ccSAndreas Gohr/**
4559b616ccSAndreas Gohr * Base class for database-based caches
4659b616ccSAndreas Gohr *
4759b616ccSAndreas Gohr * @package SimplePie
4859b616ccSAndreas Gohr * @subpackage Caching
4959b616ccSAndreas Gohr */
5059b616ccSAndreas Gohrabstract class SimplePie_Cache_DB implements SimplePie_Cache_Base
5159b616ccSAndreas Gohr{
5259b616ccSAndreas Gohr	/**
5359b616ccSAndreas Gohr	 * Helper for database conversion
5459b616ccSAndreas Gohr	 *
5559b616ccSAndreas Gohr	 * Converts a given {@see SimplePie} object into data to be stored
5659b616ccSAndreas Gohr	 *
5759b616ccSAndreas Gohr	 * @param SimplePie $data
5859b616ccSAndreas Gohr	 * @return array First item is the serialized data for storage, second item is the unique ID for this item
5959b616ccSAndreas Gohr	 */
6059b616ccSAndreas Gohr	protected static function prepare_simplepie_object_for_cache($data)
6159b616ccSAndreas Gohr	{
6259b616ccSAndreas Gohr		$items = $data->get_items();
6359b616ccSAndreas Gohr		$items_by_id = array();
6459b616ccSAndreas Gohr
6559b616ccSAndreas Gohr		if (!empty($items))
6659b616ccSAndreas Gohr		{
6759b616ccSAndreas Gohr			foreach ($items as $item)
6859b616ccSAndreas Gohr			{
6959b616ccSAndreas Gohr				$items_by_id[$item->get_id()] = $item;
7059b616ccSAndreas Gohr			}
7159b616ccSAndreas Gohr
7259b616ccSAndreas Gohr			if (count($items_by_id) !== count($items))
7359b616ccSAndreas Gohr			{
7459b616ccSAndreas Gohr				$items_by_id = array();
7559b616ccSAndreas Gohr				foreach ($items as $item)
7659b616ccSAndreas Gohr				{
7759b616ccSAndreas Gohr					$items_by_id[$item->get_id(true)] = $item;
7859b616ccSAndreas Gohr				}
7959b616ccSAndreas Gohr			}
8059b616ccSAndreas Gohr
8159b616ccSAndreas Gohr			if (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
8259b616ccSAndreas Gohr			{
8359b616ccSAndreas Gohr				$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
8459b616ccSAndreas Gohr			}
8559b616ccSAndreas Gohr			elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
8659b616ccSAndreas Gohr			{
8759b616ccSAndreas Gohr				$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
8859b616ccSAndreas Gohr			}
8959b616ccSAndreas Gohr			elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
9059b616ccSAndreas Gohr			{
9159b616ccSAndreas Gohr				$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
9259b616ccSAndreas Gohr			}
9359b616ccSAndreas Gohr			elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0]))
9459b616ccSAndreas Gohr			{
9559b616ccSAndreas Gohr				$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0];
9659b616ccSAndreas Gohr			}
9759b616ccSAndreas Gohr			else
9859b616ccSAndreas Gohr			{
9959b616ccSAndreas Gohr				$channel = null;
10059b616ccSAndreas Gohr			}
10159b616ccSAndreas Gohr
10259b616ccSAndreas Gohr			if ($channel !== null)
10359b616ccSAndreas Gohr			{
10459b616ccSAndreas Gohr				if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']))
10559b616ccSAndreas Gohr				{
10659b616ccSAndreas Gohr					unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']);
10759b616ccSAndreas Gohr				}
10859b616ccSAndreas Gohr				if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']))
10959b616ccSAndreas Gohr				{
11059b616ccSAndreas Gohr					unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']);
11159b616ccSAndreas Gohr				}
11259b616ccSAndreas Gohr				if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']))
11359b616ccSAndreas Gohr				{
11459b616ccSAndreas Gohr					unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']);
11559b616ccSAndreas Gohr				}
11659b616ccSAndreas Gohr				if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']))
11759b616ccSAndreas Gohr				{
11859b616ccSAndreas Gohr					unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']);
11959b616ccSAndreas Gohr				}
12059b616ccSAndreas Gohr				if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']))
12159b616ccSAndreas Gohr				{
12259b616ccSAndreas Gohr					unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']);
12359b616ccSAndreas Gohr				}
12459b616ccSAndreas Gohr			}
12559b616ccSAndreas Gohr			if (isset($data->data['items']))
12659b616ccSAndreas Gohr			{
12759b616ccSAndreas Gohr				unset($data->data['items']);
12859b616ccSAndreas Gohr			}
12959b616ccSAndreas Gohr			if (isset($data->data['ordered_items']))
13059b616ccSAndreas Gohr			{
13159b616ccSAndreas Gohr				unset($data->data['ordered_items']);
13259b616ccSAndreas Gohr			}
13359b616ccSAndreas Gohr		}
13459b616ccSAndreas Gohr		return array(serialize($data->data), $items_by_id);
13559b616ccSAndreas Gohr	}
13659b616ccSAndreas Gohr}
137