Simplepie with fixed Cache directory handling


/ Published in: PHP
Save to your folder(s)

Simplepie per default uses relative paths to generate the cache filename. Whenever I use Simplepie I run into the same problem, that the cache directory can't be located. This is why I modify the file everytime. Here's my version (with a hardcoded path which you'll want to replace with your desired location).


Copy this code and paste it in your HTML
  1. <?php
  2. /**
  3.  * SimplePie
  4.  *
  5.  * A PHP-Based RSS and Atom Feed Framework.
  6.  * Takes the hard work out of managing a complete RSS/Atom solution.
  7.  *
  8.  * Copyright (c) 2004-2010, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
  9.  * All rights reserved.
  10.  *
  11.  * Redistribution and use in source and binary forms, with or without modification, are
  12.  * permitted provided that the following conditions are met:
  13.  *
  14.  * * Redistributions of source code must retain the above copyright notice, this list of
  15.  * conditions and the following disclaimer.
  16.  *
  17.  * * Redistributions in binary form must reproduce the above copyright notice, this list
  18.  * of conditions and the following disclaimer in the documentation and/or other materials
  19.  * provided with the distribution.
  20.  *
  21.  * * Neither the name of the SimplePie Team nor the names of its contributors may be used
  22.  * to endorse or promote products derived from this software without specific prior
  23.  * written permission.
  24.  *
  25.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  26.  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  27.  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
  28.  * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30.  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  32.  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33.  * POSSIBILITY OF SUCH DAMAGE.
  34.  *
  35.  * @package SimplePie
  36.  * @version 1.3-dev
  37.  * @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
  38.  * @author Ryan Parman
  39.  * @author Geoffrey Sneddon
  40.  * @author Ryan McCue
  41.  * @link http://simplepie.org/ SimplePie
  42.  * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  43.  * @todo phpDoc comments
  44.  */
  45.  
  46.  
  47. class SimplePie extends SimplePie_Core
  48. {
  49.  
  50. }
  51.  
  52.  
  53.  
  54.  
  55. class SimplePie_Author
  56. {
  57. var $name;
  58. var $link;
  59. var $email;
  60.  
  61. public function __construct($name = null, $link = null, $email = null)
  62. {
  63. $this->name = $name;
  64. $this->link = $link;
  65. $this->email = $email;
  66. }
  67.  
  68. public function __toString()
  69. {
  70. return md5(serialize($this));
  71. }
  72.  
  73. public function get_name()
  74. {
  75. if ($this->name !== null)
  76. {
  77. return $this->name;
  78. }
  79. else
  80. {
  81. return null;
  82. }
  83. }
  84.  
  85. public function get_link()
  86. {
  87. if ($this->link !== null)
  88. {
  89. return $this->link;
  90. }
  91. else
  92. {
  93. return null;
  94. }
  95. }
  96.  
  97. public function get_email()
  98. {
  99. if ($this->email !== null)
  100. {
  101. return $this->email;
  102. }
  103. else
  104. {
  105. return null;
  106. }
  107. }
  108. }
  109.  
  110.  
  111.  
  112.  
  113.  
  114. class SimplePie_Cache_DB
  115. {
  116. public function prepare_simplepie_object_for_cache($data)
  117. {
  118. $items = $data->get_items();
  119. $items_by_id = array();
  120.  
  121. if (!empty($items))
  122. {
  123. foreach ($items as $item)
  124. {
  125. $items_by_id[$item->get_id()] = $item;
  126. }
  127.  
  128. if (count($items_by_id) !== count($items))
  129. {
  130. $items_by_id = array();
  131. foreach ($items as $item)
  132. {
  133. $items_by_id[$item->get_id(true)] = $item;
  134. }
  135. }
  136.  
  137. if (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
  138. {
  139. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
  140. }
  141. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
  142. {
  143. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
  144. }
  145. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
  146. {
  147. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
  148. }
  149. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0]))
  150. {
  151. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0];
  152. }
  153. else
  154. {
  155. $channel = null;
  156. }
  157.  
  158. if ($channel !== null)
  159. {
  160. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']))
  161. {
  162. unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']);
  163. }
  164. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']))
  165. {
  166. unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']);
  167. }
  168. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']))
  169. {
  170. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']);
  171. }
  172. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']))
  173. {
  174. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']);
  175. }
  176. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']))
  177. {
  178. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']);
  179. }
  180. }
  181. if (isset($data->data['items']))
  182. {
  183. unset($data->data['items']);
  184. }
  185. if (isset($data->data['ordered_items']))
  186. {
  187. unset($data->data['ordered_items']);
  188. }
  189. }
  190. return array(serialize($data->data), $items_by_id);
  191. }
  192. }
  193.  
  194.  
  195.  
  196.  
  197. class SimplePie_Cache_File
  198. {
  199. var $location;
  200. var $filename;
  201. var $extension;
  202. var $name;
  203.  
  204. public function __construct($location, $filename, $extension)
  205. {
  206. if (substr($location,0,1)!=="/") $location = "/$location";
  207. $this->location = $_SERVER["DOCUMENT_ROOT"].$location;
  208. $this->filename = $filename;
  209. $this->extension = $extension;
  210. $this->name = "$this->location/$this->filename.$this->extension";
  211. }
  212.  
  213. public function save($data)
  214. {
  215. if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
  216. {
  217. if (is_a($data, 'SimplePie'))
  218. {
  219. $data = $data->data;
  220. }
  221.  
  222. $data = serialize($data);
  223. return (bool) file_put_contents($this->name, $data);
  224. }
  225. return false;
  226. }
  227.  
  228. public function load()
  229. {
  230. if (file_exists($this->name) && is_readable($this->name))
  231. {
  232. return unserialize(file_get_contents($this->name));
  233. }
  234. return false;
  235. }
  236.  
  237. public function mtime()
  238. {
  239. if (file_exists($this->name))
  240. {
  241. return filemtime($this->name);
  242. }
  243. return false;
  244. }
  245.  
  246. public function touch()
  247. {
  248. if (file_exists($this->name))
  249. {
  250. return touch($this->name);
  251. }
  252. return false;
  253. }
  254.  
  255. public function unlink()
  256. {
  257. if (file_exists($this->name))
  258. {
  259. return unlink($this->name);
  260. }
  261. return false;
  262. }
  263. }
  264.  
  265.  
  266.  
  267.  
  268. class SimplePie_Cache_MySQL extends SimplePie_Cache_DB
  269. {
  270. var $mysql;
  271. var $options;
  272. var $id;
  273.  
  274. public function __construct($mysql_location, $name, $extension)
  275. {
  276. $host = $mysql_location->get_host();
  277. if (stripos($host, 'unix(') === 0 && substr($host, -1) === ')')
  278. {
  279. $server = ':' . substr($host, 5, -1);
  280. }
  281. else
  282. {
  283. $server = $host;
  284. if ($mysql_location->get_port() !== null)
  285. {
  286. $server .= ':' . $mysql_location->get_port();
  287. }
  288. }
  289.  
  290. if (strpos($mysql_location->get_userinfo(), ':') !== false)
  291. {
  292. list($username, $password) = explode(':', $mysql_location->get_userinfo(), 2);
  293. }
  294. else
  295. {
  296. $username = $mysql_location->get_userinfo();
  297. $password = null;
  298. }
  299.  
  300. if ($this->mysql = mysql_connect($server, $username, $password))
  301. {
  302. $this->id = $name . $extension;
  303. $this->options = SimplePie_Misc::parse_str($mysql_location->get_query());
  304. if (!isset($this->options['prefix'][0]))
  305. {
  306. $this->options['prefix'][0] = '';
  307. }
  308.  
  309. if (mysql_select_db(ltrim($mysql_location->get_path(), '/'))
  310. && mysql_query('SET NAMES utf8')
  311. && ($query = mysql_unbuffered_query('SHOW TABLES')))
  312. {
  313. $db = array();
  314. while ($row = mysql_fetch_row($query))
  315. {
  316. $db[] = $row[0];
  317. }
  318.  
  319. if (!in_array($this->options['prefix'][0] . 'cache_data', $db))
  320. {
  321. if (!mysql_query('CREATE TABLE `' . $this->options['prefix'][0] . 'cache_data` (`id` TEXT CHARACTER SET utf8 NOT NULL, `items` SMALLINT NOT NULL DEFAULT 0, `data` BLOB NOT NULL, `mtime` INT UNSIGNED NOT NULL, UNIQUE (`id`(125)))'))
  322. {
  323. $this->mysql = null;
  324. }
  325. }
  326.  
  327. if (!in_array($this->options['prefix'][0] . 'items', $db))
  328. {
  329. if (!mysql_query('CREATE TABLE `' . $this->options['prefix'][0] . 'items` (`feed_id` TEXT CHARACTER SET utf8 NOT NULL, `id` TEXT CHARACTER SET utf8 NOT NULL, `data` TEXT CHARACTER SET utf8 NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))'))
  330. {
  331. $this->mysql = null;
  332. }
  333. }
  334. }
  335. else
  336. {
  337. $this->mysql = null;
  338. }
  339. }
  340. }
  341.  
  342. public function save($data)
  343. {
  344. if ($this->mysql)
  345. {
  346. $feed_id = "'" . mysql_real_escape_string($this->id) . "'";
  347.  
  348. if (is_a($data, 'SimplePie'))
  349. {
  350. $data = clone $data;
  351.  
  352. $prepared = $this->prepare_simplepie_object_for_cache($data);
  353.  
  354. if ($query = mysql_query('SELECT `id` FROM `' . $this->options['prefix'][0] . 'cache_data` WHERE `id` = ' . $feed_id, $this->mysql))
  355. {
  356. if (mysql_num_rows($query))
  357. {
  358. $items = count($prepared[1]);
  359. if ($items)
  360. {
  361. $sql = 'UPDATE `' . $this->options['prefix'][0] . 'cache_data` SET `items` = ' . $items . ', `data` = \'' . mysql_real_escape_string($prepared[0]) . '\', `mtime` = ' . time() . ' WHERE `id` = ' . $feed_id;
  362. }
  363. else
  364. {
  365. $sql = 'UPDATE `' . $this->options['prefix'][0] . 'cache_data` SET `data` = \'' . mysql_real_escape_string($prepared[0]) . '\', `mtime` = ' . time() . ' WHERE `id` = ' . $feed_id;
  366. }
  367.  
  368. if (!mysql_query($sql, $this->mysql))
  369. {
  370. return false;
  371. }
  372. }
  373. elseif (!mysql_query('INSERT INTO `' . $this->options['prefix'][0] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(' . $feed_id . ', ' . count($prepared[1]) . ', \'' . mysql_real_escape_string($prepared[0]) . '\', ' . time() . ')', $this->mysql))
  374. {
  375. return false;
  376. }
  377.  
  378. $ids = array_keys($prepared[1]);
  379. if (!empty($ids))
  380. {
  381. foreach ($ids as $id)
  382. {
  383. $database_ids[] = mysql_real_escape_string($id);
  384. }
  385.  
  386. if ($query = mysql_unbuffered_query('SELECT `id` FROM `' . $this->options['prefix'][0] . 'items` WHERE `id` = \'' . implode('\' OR `id` = \'', $database_ids) . '\' AND `feed_id` = ' . $feed_id, $this->mysql))
  387. {
  388. $existing_ids = array();
  389. while ($row = mysql_fetch_row($query))
  390. {
  391. $existing_ids[] = $row[0];
  392. }
  393.  
  394. $new_ids = array_diff($ids, $existing_ids);
  395.  
  396. foreach ($new_ids as $new_id)
  397. {
  398. if (!($date = $prepared[1][$new_id]->get_date('U')))
  399. {
  400. $date = time();
  401. }
  402.  
  403. if (!mysql_query('INSERT INTO `' . $this->options['prefix'][0] . 'items` (`feed_id`, `id`, `data`, `posted`) VALUES(' . $feed_id . ', \'' . mysql_real_escape_string($new_id) . '\', \'' . mysql_real_escape_string(serialize($prepared[1][$new_id]->data)) . '\', ' . $date . ')', $this->mysql))
  404. {
  405. return false;
  406. }
  407. }
  408. return true;
  409. }
  410. }
  411. else
  412. {
  413. return true;
  414. }
  415. }
  416. }
  417. elseif ($query = mysql_query('SELECT `id` FROM `' . $this->options['prefix'][0] . 'cache_data` WHERE `id` = ' . $feed_id, $this->mysql))
  418. {
  419. if (mysql_num_rows($query))
  420. {
  421. if (mysql_query('UPDATE `' . $this->options['prefix'][0] . 'cache_data` SET `items` = 0, `data` = \'' . mysql_real_escape_string(serialize($data)) . '\', `mtime` = ' . time() . ' WHERE `id` = ' . $feed_id, $this->mysql))
  422. {
  423. return true;
  424. }
  425. }
  426. elseif (mysql_query('INSERT INTO `' . $this->options['prefix'][0] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(\'' . mysql_real_escape_string($this->id) . '\', 0, \'' . mysql_real_escape_string(serialize($data)) . '\', ' . time() . ')', $this->mysql))
  427. {
  428. return true;
  429. }
  430. }
  431. }
  432. return false;
  433. }
  434.  
  435. public function load()
  436. {
  437. if ($this->mysql && ($query = mysql_query('SELECT `items`, `data` FROM `' . $this->options['prefix'][0] . 'cache_data` WHERE `id` = \'' . mysql_real_escape_string($this->id) . "'", $this->mysql)) && ($row = mysql_fetch_row($query)))
  438. {
  439. $data = unserialize($row[1]);
  440.  
  441. if (isset($this->options['items'][0]))
  442. {
  443. $items = (int) $this->options['items'][0];
  444. }
  445. else
  446. {
  447. $items = (int) $row[0];
  448. }
  449.  
  450. if ($items !== 0)
  451. {
  452. if (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
  453. {
  454. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
  455. }
  456. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
  457. {
  458. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
  459. }
  460. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
  461. {
  462. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
  463. }
  464. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]))
  465. {
  466. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0];
  467. }
  468. else
  469. {
  470. $feed = null;
  471. }
  472.  
  473. if ($feed !== null)
  474. {
  475. $sql = 'SELECT `data` FROM `' . $this->options['prefix'][0] . 'items` WHERE `feed_id` = \'' . mysql_real_escape_string($this->id) . '\' ORDER BY `posted` DESC';
  476. if ($items > 0)
  477. {
  478. $sql .= ' LIMIT ' . $items;
  479. }
  480.  
  481. if ($query = mysql_unbuffered_query($sql, $this->mysql))
  482. {
  483. while ($row = mysql_fetch_row($query))
  484. {
  485. $feed['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry'][] = unserialize($row[0]);
  486. }
  487. }
  488. else
  489. {
  490. return false;
  491. }
  492. }
  493. }
  494. return $data;
  495. }
  496. return false;
  497. }
  498.  
  499. public function mtime()
  500. {
  501. if ($this->mysql && ($query = mysql_query('SELECT `mtime` FROM `' . $this->options['prefix'][0] . 'cache_data` WHERE `id` = \'' . mysql_real_escape_string($this->id) . "'", $this->mysql)) && ($row = mysql_fetch_row($query)))
  502. {
  503. return $row[0];
  504. }
  505. else
  506. {
  507. return false;
  508. }
  509. }
  510.  
  511. public function touch()
  512. {
  513. if ($this->mysql && ($query = mysql_query('UPDATE `' . $this->options['prefix'][0] . 'cache_data` SET `mtime` = ' . time() . ' WHERE `id` = \'' . mysql_real_escape_string($this->id) . "'", $this->mysql)) && mysql_affected_rows($this->mysql))
  514. {
  515. return true;
  516. }
  517. else
  518. {
  519. return false;
  520. }
  521. }
  522.  
  523. public function unlink()
  524. {
  525. if ($this->mysql && ($query = mysql_query('DELETE FROM `' . $this->options['prefix'][0] . 'cache_data` WHERE `id` = \'' . mysql_real_escape_string($this->id) . "'", $this->mysql)) && ($query2 = mysql_query('DELETE FROM `' . $this->options['prefix'][0] . 'items` WHERE `feed_id` = \'' . mysql_real_escape_string($this->id) . "'", $this->mysql)))
  526. {
  527. return true;
  528. }
  529. else
  530. {
  531. return false;
  532. }
  533. }
  534. }
  535.  
  536.  
  537.  
  538.  
  539. class SimplePie_Cache
  540. {
  541.  
  542. private function __construct()
  543. {
  544. trigger_error('Please call SimplePie_Cache::create() instead of the constructor', E_USER_ERROR);
  545. }
  546.  
  547.  
  548. public static function create($location, $filename, $extension)
  549. {
  550. $location_iri = new SimplePie_IRI($location);
  551. switch ($location_iri->get_scheme())
  552. {
  553. case 'mysql':
  554. if (extension_loaded('mysql'))
  555. {
  556. return new SimplePie_Cache_MySQL($location_iri, $filename, $extension);
  557. }
  558. break;
  559.  
  560. default:
  561. return new SimplePie_Cache_File($location, $filename, $extension);
  562. }
  563. }
  564. }
  565.  
  566.  
  567.  
  568.  
  569.  
  570. class SimplePie_Caption
  571. {
  572. var $type;
  573. var $lang;
  574. var $startTime;
  575. var $endTime;
  576. var $text;
  577.  
  578. public function __construct($type = null, $lang = null, $startTime = null, $endTime = null, $text = null)
  579. {
  580. $this->type = $type;
  581. $this->lang = $lang;
  582. $this->startTime = $startTime;
  583. $this->endTime = $endTime;
  584. $this->text = $text;
  585. }
  586.  
  587. public function __toString()
  588. {
  589. return md5(serialize($this));
  590. }
  591.  
  592. public function get_endtime()
  593. {
  594. if ($this->endTime !== null)
  595. {
  596. return $this->endTime;
  597. }
  598. else
  599. {
  600. return null;
  601. }
  602. }
  603.  
  604. public function get_language()
  605. {
  606. if ($this->lang !== null)
  607. {
  608. return $this->lang;
  609. }
  610. else
  611. {
  612. return null;
  613. }
  614. }
  615.  
  616. public function get_starttime()
  617. {
  618. if ($this->startTime !== null)
  619. {
  620. return $this->startTime;
  621. }
  622. else
  623. {
  624. return null;
  625. }
  626. }
  627.  
  628. public function get_text()
  629. {
  630. if ($this->text !== null)
  631. {
  632. return $this->text;
  633. }
  634. else
  635. {
  636. return null;
  637. }
  638. }
  639.  
  640. public function get_type()
  641. {
  642. if ($this->type !== null)
  643. {
  644. return $this->type;
  645. }
  646. else
  647. {
  648. return null;
  649. }
  650. }
  651. }
  652.  
  653.  
  654.  
  655.  
  656.  
  657. class SimplePie_Category
  658. {
  659. var $term;
  660. var $scheme;
  661. var $label;
  662.  
  663. public function __construct($term = null, $scheme = null, $label = null)
  664. {
  665. $this->term = $term;
  666. $this->scheme = $scheme;
  667. $this->label = $label;
  668. }
  669.  
  670. public function __toString()
  671. {
  672. return md5(serialize($this));
  673. }
  674.  
  675. public function get_term()
  676. {
  677. if ($this->term !== null)
  678. {
  679. return $this->term;
  680. }
  681. else
  682. {
  683. return null;
  684. }
  685. }
  686.  
  687. public function get_scheme()
  688. {
  689. if ($this->scheme !== null)
  690. {
  691. return $this->scheme;
  692. }
  693. else
  694. {
  695. return null;
  696. }
  697. }
  698.  
  699. public function get_label()
  700. {
  701. if ($this->label !== null)
  702. {
  703. return $this->label;
  704. }
  705. else
  706. {
  707. return $this->get_term();
  708. }
  709. }
  710. }
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717. class SimplePie_Content_Type_Sniffer
  718. {
  719.  
  720. var $file;
  721.  
  722.  
  723. public function __construct($file)
  724. {
  725. $this->file = $file;
  726. }
  727.  
  728.  
  729. public function get_type()
  730. {
  731. if (isset($this->file->headers['content-type']))
  732. {
  733. if (!isset($this->file->headers['content-encoding'])
  734. && ($this->file->headers['content-type'] === 'text/plain'
  735. || $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1'
  736. || $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1'))
  737. {
  738. return $this->text_or_binary();
  739. }
  740.  
  741. if (($pos = strpos($this->file->headers['content-type'], ';')) !== false)
  742. {
  743. $official = substr($this->file->headers['content-type'], 0, $pos);
  744. }
  745. else
  746. {
  747. $official = $this->file->headers['content-type'];
  748. }
  749. $official = strtolower($official);
  750.  
  751. if ($official === 'unknown/unknown'
  752. || $official === 'application/unknown')
  753. {
  754. return $this->unknown();
  755. }
  756. elseif (substr($official, -4) === '+xml'
  757. || $official === 'text/xml'
  758. || $official === 'application/xml')
  759. {
  760. return $official;
  761. }
  762. elseif (substr($official, 0, 6) === 'image/')
  763. {
  764. if ($return = $this->image())
  765. {
  766. return $return;
  767. }
  768. else
  769. {
  770. return $official;
  771. }
  772. }
  773. elseif ($official === 'text/html')
  774. {
  775. return $this->feed_or_html();
  776. }
  777. else
  778. {
  779. return $official;
  780. }
  781. }
  782. else
  783. {
  784. return $this->unknown();
  785. }
  786. }
  787.  
  788.  
  789. public function text_or_binary()
  790. {
  791. if (substr($this->file->body, 0, 2) === "\xFE\xFF"
  792. || substr($this->file->body, 0, 2) === "\xFF\xFE"
  793. || substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF"
  794. || substr($this->file->body, 0, 3) === "\xEF\xBB\xBF")
  795. {
  796. return 'text/plain';
  797. }
  798. elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body))
  799. {
  800. return 'application/octect-stream';
  801. }
  802. else
  803. {
  804. return 'text/plain';
  805. }
  806. }
  807.  
  808.  
  809. public function unknown()
  810. {
  811. $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20");
  812. if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html'
  813. || strtolower(substr($this->file->body, $ws, 5)) === '<html'
  814. || strtolower(substr($this->file->body, $ws, 7)) === '<script')
  815. {
  816. return 'text/html';
  817. }
  818. elseif (substr($this->file->body, 0, 5) === '%PDF-')
  819. {
  820. return 'application/pdf';
  821. }
  822. elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-')
  823. {
  824. return 'application/postscript';
  825. }
  826. elseif (substr($this->file->body, 0, 6) === 'GIF87a'
  827. || substr($this->file->body, 0, 6) === 'GIF89a')
  828. {
  829. return 'image/gif';
  830. }
  831. elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
  832. {
  833. return 'image/png';
  834. }
  835. elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
  836. {
  837. return 'image/jpeg';
  838. }
  839. elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
  840. {
  841. return 'image/bmp';
  842. }
  843. else
  844. {
  845. return $this->text_or_binary();
  846. }
  847. }
  848.  
  849.  
  850. public function image()
  851. {
  852. if (substr($this->file->body, 0, 6) === 'GIF87a'
  853. || substr($this->file->body, 0, 6) === 'GIF89a')
  854. {
  855. return 'image/gif';
  856. }
  857. elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
  858. {
  859. return 'image/png';
  860. }
  861. elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
  862. {
  863. return 'image/jpeg';
  864. }
  865. elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
  866. {
  867. return 'image/bmp';
  868. }
  869. else
  870. {
  871. return false;
  872. }
  873. }
  874.  
  875.  
  876. public function feed_or_html()
  877. {
  878. $len = strlen($this->file->body);
  879. $pos = strspn($this->file->body, "\x09\x0A\x0D\x20");
  880.  
  881. while ($pos < $len)
  882. {
  883. switch ($this->file->body[$pos])
  884. {
  885. case "\x09":
  886. case "\x0A":
  887. case "\x0D":
  888. case "\x20":
  889. $pos += strspn($this->file->body, "\x09\x0A\x0D\x20", $pos);
  890. continue 2;
  891.  
  892. case '<':
  893. $pos++;
  894. break;
  895.  
  896. default:
  897. return 'text/html';
  898. }
  899.  
  900. if (substr($this->file->body, $pos, 3) === '!--')
  901. {
  902. $pos += 3;
  903. if ($pos < $len && ($pos = strpos($this->file->body, '-->', $pos)) !== false)
  904. {
  905. $pos += 3;
  906. }
  907. else
  908. {
  909. return 'text/html';
  910. }
  911. }
  912. elseif (substr($this->file->body, $pos, 1) === '!')
  913. {
  914. if ($pos < $len && ($pos = strpos($this->file->body, '>', $pos)) !== false)
  915. {
  916. $pos++;
  917. }
  918. else
  919. {
  920. return 'text/html';
  921. }
  922. }
  923. elseif (substr($this->file->body, $pos, 1) === '?')
  924. {
  925. if ($pos < $len && ($pos = strpos($this->file->body, '?>', $pos)) !== false)
  926. {
  927. $pos += 2;
  928. }
  929. else
  930. {
  931. return 'text/html';
  932. }
  933. }
  934. elseif (substr($this->file->body, $pos, 3) === 'rss'
  935. || substr($this->file->body, $pos, 7) === 'rdf:RDF')
  936. {
  937. return 'application/rss+xml';
  938. }
  939. elseif (substr($this->file->body, $pos, 4) === 'feed')
  940. {
  941. return 'application/atom+xml';
  942. }
  943. else
  944. {
  945. return 'text/html';
  946. }
  947. }
  948.  
  949. return 'text/html';
  950. }
  951. }
  952.  
  953.  
  954.  
  955.  
  956.  
  957. class SimplePie_Copyright
  958. {
  959. var $url;
  960. var $label;
  961.  
  962. public function __construct($url = null, $label = null)
  963. {
  964. $this->url = $url;
  965. $this->label = $label;
  966. }
  967.  
  968. public function __toString()
  969. {
  970. return md5(serialize($this));
  971. }
  972.  
  973. public function get_url()
  974. {
  975. if ($this->url !== null)
  976. {
  977. return $this->url;
  978. }
  979. else
  980. {
  981. return null;
  982. }
  983. }
  984.  
  985. public function get_attribution()
  986. {
  987. if ($this->label !== null)
  988. {
  989. return $this->label;
  990. }
  991. else
  992. {
  993. return null;
  994. }
  995. }
  996. }
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002. define('SIMPLEPIE_NAME', 'SimplePie');
  1003.  
  1004.  
  1005. define('SIMPLEPIE_VERSION', '1.3-dev');
  1006.  
  1007.  
  1008. define('SIMPLEPIE_BUILD', gmdate('YmdHis', SimplePie_Misc::parse_date(substr('$Date$', 7, 25)) ? SimplePie_Misc::parse_date(substr('$Date$', 7, 25)) : filemtime(__FILE__)));
  1009.  
  1010.  
  1011. define('SIMPLEPIE_URL', 'http://simplepie.org');
  1012.  
  1013.  
  1014. define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD);
  1015.  
  1016.  
  1017. define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>');
  1018.  
  1019.  
  1020. define('SIMPLEPIE_LOCATOR_NONE', 0);
  1021.  
  1022.  
  1023. define('SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1);
  1024.  
  1025.  
  1026. define('SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2);
  1027.  
  1028.  
  1029. define('SIMPLEPIE_LOCATOR_LOCAL_BODY', 4);
  1030.  
  1031.  
  1032. define('SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8);
  1033.  
  1034.  
  1035. define('SIMPLEPIE_LOCATOR_REMOTE_BODY', 16);
  1036.  
  1037.  
  1038. define('SIMPLEPIE_LOCATOR_ALL', 31);
  1039.  
  1040.  
  1041. define('SIMPLEPIE_TYPE_NONE', 0);
  1042.  
  1043.  
  1044. define('SIMPLEPIE_TYPE_RSS_090', 1);
  1045.  
  1046.  
  1047. define('SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2);
  1048.  
  1049.  
  1050. define('SIMPLEPIE_TYPE_RSS_091_USERLAND', 4);
  1051.  
  1052.  
  1053. define('SIMPLEPIE_TYPE_RSS_091', 6);
  1054.  
  1055.  
  1056. define('SIMPLEPIE_TYPE_RSS_092', 8);
  1057.  
  1058.  
  1059. define('SIMPLEPIE_TYPE_RSS_093', 16);
  1060.  
  1061.  
  1062. define('SIMPLEPIE_TYPE_RSS_094', 32);
  1063.  
  1064.  
  1065. define('SIMPLEPIE_TYPE_RSS_10', 64);
  1066.  
  1067.  
  1068. define('SIMPLEPIE_TYPE_RSS_20', 128);
  1069.  
  1070.  
  1071. define('SIMPLEPIE_TYPE_RSS_RDF', 65);
  1072.  
  1073.  
  1074. define('SIMPLEPIE_TYPE_RSS_SYNDICATION', 190);
  1075.  
  1076.  
  1077. define('SIMPLEPIE_TYPE_RSS_ALL', 255);
  1078.  
  1079.  
  1080. define('SIMPLEPIE_TYPE_ATOM_03', 256);
  1081.  
  1082.  
  1083. define('SIMPLEPIE_TYPE_ATOM_10', 512);
  1084.  
  1085.  
  1086. define('SIMPLEPIE_TYPE_ATOM_ALL', 768);
  1087.  
  1088.  
  1089. define('SIMPLEPIE_TYPE_ALL', 1023);
  1090.  
  1091.  
  1092. define('SIMPLEPIE_CONSTRUCT_NONE', 0);
  1093.  
  1094.  
  1095. define('SIMPLEPIE_CONSTRUCT_TEXT', 1);
  1096.  
  1097.  
  1098. define('SIMPLEPIE_CONSTRUCT_HTML', 2);
  1099.  
  1100.  
  1101. define('SIMPLEPIE_CONSTRUCT_XHTML', 4);
  1102.  
  1103.  
  1104. define('SIMPLEPIE_CONSTRUCT_BASE64', 8);
  1105.  
  1106.  
  1107. define('SIMPLEPIE_CONSTRUCT_IRI', 16);
  1108.  
  1109.  
  1110. define('SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32);
  1111.  
  1112.  
  1113. define('SIMPLEPIE_CONSTRUCT_ALL', 63);
  1114.  
  1115.  
  1116. define('SIMPLEPIE_SAME_CASE', 1);
  1117.  
  1118.  
  1119. define('SIMPLEPIE_LOWERCASE', 2);
  1120.  
  1121.  
  1122. define('SIMPLEPIE_UPPERCASE', 4);
  1123.  
  1124.  
  1125. define('SIMPLEPIE_PCRE_HTML_ATTRIBUTE', '((?:[\x09\x0A\x0B\x0C\x0D\x20]+[^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3D\x3E]*(?:[\x09\x0A\x0B\x0C\x0D\x20]*=[\x09\x0A\x0B\x0C\x0D\x20]*(?:"(?:[^"]*)"|\'(?:[^\']*)\'|(?:[^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?)*)[\x09\x0A\x0B\x0C\x0D\x20]*');
  1126.  
  1127.  
  1128. define('SIMPLEPIE_PCRE_XML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*');
  1129.  
  1130.  
  1131. define('SIMPLEPIE_NAMESPACE_XML', 'http://www.w3.org/XML/1998/namespace');
  1132.  
  1133.  
  1134. define('SIMPLEPIE_NAMESPACE_ATOM_10', 'http://www.w3.org/2005/Atom');
  1135.  
  1136.  
  1137. define('SIMPLEPIE_NAMESPACE_ATOM_03', 'http://purl.org/atom/ns#');
  1138.  
  1139.  
  1140. define('SIMPLEPIE_NAMESPACE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
  1141.  
  1142.  
  1143. define('SIMPLEPIE_NAMESPACE_RSS_090', 'http://my.netscape.com/rdf/simple/0.9/');
  1144.  
  1145.  
  1146. define('SIMPLEPIE_NAMESPACE_RSS_10', 'http://purl.org/rss/1.0/');
  1147.  
  1148.  
  1149. define('SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT', 'http://purl.org/rss/1.0/modules/content/');
  1150.  
  1151.  
  1152. define('SIMPLEPIE_NAMESPACE_RSS_20', '');
  1153.  
  1154.  
  1155. define('SIMPLEPIE_NAMESPACE_DC_10', 'http://purl.org/dc/elements/1.0/');
  1156.  
  1157.  
  1158. define('SIMPLEPIE_NAMESPACE_DC_11', 'http://purl.org/dc/elements/1.1/');
  1159.  
  1160.  
  1161. define('SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO', 'http://www.w3.org/2003/01/geo/wgs84_pos#');
  1162.  
  1163.  
  1164. define('SIMPLEPIE_NAMESPACE_GEORSS', 'http://www.georss.org/georss');
  1165.  
  1166.  
  1167. define('SIMPLEPIE_NAMESPACE_MEDIARSS', 'http://search.yahoo.com/mrss/');
  1168.  
  1169.  
  1170. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG', 'http://search.yahoo.com/mrss');
  1171.  
  1172.  
  1173. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2', 'http://video.search.yahoo.com/mrss');
  1174.  
  1175.  
  1176. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3', 'http://video.search.yahoo.com/mrss/');
  1177.  
  1178.  
  1179. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4', 'http://www.rssboard.org/media-rss');
  1180.  
  1181.  
  1182. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5', 'http://www.rssboard.org/media-rss/');
  1183.  
  1184.  
  1185. define('SIMPLEPIE_NAMESPACE_ITUNES', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
  1186.  
  1187.  
  1188. define('SIMPLEPIE_NAMESPACE_XHTML', 'http://www.w3.org/1999/xhtml');
  1189.  
  1190.  
  1191. define('SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY', 'http://www.iana.org/assignments/relation/');
  1192.  
  1193.  
  1194. define('SIMPLEPIE_PHP5', version_compare(PHP_VERSION, '5.0.0', '>='));
  1195.  
  1196.  
  1197. define('SIMPLEPIE_FILE_SOURCE_NONE', 0);
  1198.  
  1199.  
  1200. define('SIMPLEPIE_FILE_SOURCE_REMOTE', 1);
  1201.  
  1202.  
  1203. define('SIMPLEPIE_FILE_SOURCE_LOCAL', 2);
  1204.  
  1205.  
  1206. define('SIMPLEPIE_FILE_SOURCE_FSOCKOPEN', 4);
  1207.  
  1208.  
  1209. define('SIMPLEPIE_FILE_SOURCE_CURL', 8);
  1210.  
  1211.  
  1212. define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16);
  1213.  
  1214.  
  1215.  
  1216.  
  1217. class SimplePie_Core
  1218. {
  1219.  
  1220. public $data = array();
  1221.  
  1222.  
  1223. public $error;
  1224.  
  1225.  
  1226. public $sanitize;
  1227.  
  1228.  
  1229. public $useragent = SIMPLEPIE_USERAGENT;
  1230.  
  1231.  
  1232. public $feed_url;
  1233.  
  1234.  
  1235. public $file;
  1236.  
  1237.  
  1238. public $raw_data;
  1239.  
  1240.  
  1241. public $timeout = 10;
  1242.  
  1243.  
  1244. public $force_fsockopen = false;
  1245.  
  1246.  
  1247. public $force_feed = false;
  1248.  
  1249.  
  1250. public $xml_dump = false;
  1251.  
  1252.  
  1253. public $cache = true;
  1254.  
  1255.  
  1256. public $cache_duration = 3600;
  1257.  
  1258.  
  1259. public $autodiscovery_cache_duration = 604800;
  1260.  
  1261. public $cache_location = '/system/cms/cache/default/simplepie';
  1262.  
  1263.  
  1264. public $cache_name_function = 'md5';
  1265.  
  1266.  
  1267. public $order_by_date = true;
  1268.  
  1269.  
  1270. public $input_encoding = false;
  1271.  
  1272.  
  1273. public $autodiscovery = SIMPLEPIE_LOCATOR_ALL;
  1274.  
  1275.  
  1276. public $cache_class = 'SimplePie_Cache';
  1277.  
  1278.  
  1279. public $locator_class = 'SimplePie_Locator';
  1280.  
  1281.  
  1282. public $parser_class = 'SimplePie_Parser';
  1283.  
  1284.  
  1285. public $file_class = 'SimplePie_File';
  1286.  
  1287.  
  1288. public $item_class = 'SimplePie_Item';
  1289.  
  1290.  
  1291. public $author_class = 'SimplePie_Author';
  1292.  
  1293.  
  1294. public $category_class = 'SimplePie_Category';
  1295.  
  1296.  
  1297. public $enclosure_class = 'SimplePie_Enclosure';
  1298.  
  1299.  
  1300. public $caption_class = 'SimplePie_Caption';
  1301.  
  1302.  
  1303. public $copyright_class = 'SimplePie_Copyright';
  1304.  
  1305.  
  1306. public $credit_class = 'SimplePie_Credit';
  1307.  
  1308.  
  1309. public $rating_class = 'SimplePie_Rating';
  1310.  
  1311.  
  1312. public $restriction_class = 'SimplePie_Restriction';
  1313.  
  1314.  
  1315. public $content_type_sniffer_class = 'SimplePie_Content_Type_Sniffer';
  1316.  
  1317.  
  1318. public $source_class = 'SimplePie_Source';
  1319.  
  1320.  
  1321. public $javascript = 'js';
  1322.  
  1323.  
  1324. public $max_checked_feeds = 10;
  1325.  
  1326.  
  1327. public $all_discovered_feeds = array();
  1328.  
  1329.  
  1330. public $image_handler = '';
  1331.  
  1332.  
  1333. public $multifeed_url = array();
  1334.  
  1335.  
  1336. public $multifeed_objects = array();
  1337.  
  1338.  
  1339. public $config_settings = null;
  1340.  
  1341.  
  1342. public $item_limit = 0;
  1343.  
  1344.  
  1345. public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
  1346.  
  1347.  
  1348. public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  1349.  
  1350.  
  1351. public function __construct()
  1352. {
  1353. if (version_compare(PHP_VERSION, '5.0', '<'))
  1354. {
  1355. trigger_error('PHP 4.x is no longer supported. Please upgrade to PHP 5.2 or newer.');
  1356. die();
  1357. }
  1358.  
  1359. $this->sanitize = new SimplePie_Sanitize();
  1360.  
  1361. if (func_num_args() > 0)
  1362. {
  1363. trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_location() directly.');
  1364. }
  1365. }
  1366.  
  1367.  
  1368. public function __toString()
  1369. {
  1370. return md5(serialize($this->data));
  1371. }
  1372.  
  1373.  
  1374. public function __destruct()
  1375. {
  1376. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
  1377. {
  1378. if (!empty($this->data['items']))
  1379. {
  1380. foreach ($this->data['items'] as $item)
  1381. {
  1382. $item->__destruct();
  1383. }
  1384. unset($item, $this->data['items']);
  1385. }
  1386. if (!empty($this->data['ordered_items']))
  1387. {
  1388. foreach ($this->data['ordered_items'] as $item)
  1389. {
  1390. $item->__destruct();
  1391. }
  1392. unset($item, $this->data['ordered_items']);
  1393. }
  1394. }
  1395. }
  1396.  
  1397.  
  1398. public function force_feed($enable = false)
  1399. {
  1400. $this->force_feed = (bool) $enable;
  1401. }
  1402.  
  1403.  
  1404. public function set_feed_url($url)
  1405. {
  1406. if (is_array($url))
  1407. {
  1408. $this->multifeed_url = array();
  1409. foreach ($url as $value)
  1410. {
  1411. $this->multifeed_url[] = SimplePie_Misc::fix_protocol($value, 1);
  1412. }
  1413. }
  1414. else
  1415. {
  1416. $this->feed_url = SimplePie_Misc::fix_protocol($url, 1);
  1417. }
  1418. }
  1419.  
  1420.  
  1421. public function set_file(&$file)
  1422. {
  1423. if (is_a($file, 'SimplePie_File'))
  1424. {
  1425. $this->feed_url = $file->url;
  1426. $this->file =& $file;
  1427. return true;
  1428. }
  1429. return false;
  1430. }
  1431.  
  1432.  
  1433. public function set_raw_data($data)
  1434. {
  1435. $this->raw_data = $data;
  1436. }
  1437.  
  1438.  
  1439. public function set_timeout($timeout = 10)
  1440. {
  1441. $this->timeout = (int) $timeout;
  1442. }
  1443.  
  1444.  
  1445. public function force_fsockopen($enable = false)
  1446. {
  1447. $this->force_fsockopen = (bool) $enable;
  1448. }
  1449.  
  1450.  
  1451. public function enable_cache($enable = true)
  1452. {
  1453. $this->cache = (bool) $enable;
  1454. }
  1455.  
  1456.  
  1457. public function set_cache_duration($seconds = 3600)
  1458. {
  1459. $this->cache_duration = (int) $seconds;
  1460. }
  1461.  
  1462.  
  1463. public function set_autodiscovery_cache_duration($seconds = 604800)
  1464. {
  1465. $this->autodiscovery_cache_duration = (int) $seconds;
  1466. }
  1467.  
  1468.  
  1469. public function set_cache_location($location = '/system/cms/cache/default/simplepie')
  1470. {
  1471. $this->cache_location = (string) $location;
  1472. }
  1473.  
  1474.  
  1475. public function enable_order_by_date($enable = true)
  1476. {
  1477. $this->order_by_date = (bool) $enable;
  1478. }
  1479.  
  1480.  
  1481. public function set_input_encoding($encoding = false)
  1482. {
  1483. if ($encoding)
  1484. {
  1485. $this->input_encoding = (string) $encoding;
  1486. }
  1487. else
  1488. {
  1489. $this->input_encoding = false;
  1490. }
  1491. }
  1492.  
  1493.  
  1494. public function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL)
  1495. {
  1496. $this->autodiscovery = (int) $level;
  1497. }
  1498.  
  1499.  
  1500. public function set_cache_class($class = 'SimplePie_Cache')
  1501. {
  1502. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Cache'))
  1503. {
  1504. $this->cache_class = $class;
  1505. return true;
  1506. }
  1507. return false;
  1508. }
  1509.  
  1510.  
  1511. public function set_locator_class($class = 'SimplePie_Locator')
  1512. {
  1513. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Locator'))
  1514. {
  1515. $this->locator_class = $class;
  1516. return true;
  1517. }
  1518. return false;
  1519. }
  1520.  
  1521.  
  1522. public function set_parser_class($class = 'SimplePie_Parser')
  1523. {
  1524. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Parser'))
  1525. {
  1526. $this->parser_class = $class;
  1527. return true;
  1528. }
  1529. return false;
  1530. }
  1531.  
  1532.  
  1533. public function set_file_class($class = 'SimplePie_File')
  1534. {
  1535. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_File'))
  1536. {
  1537. $this->file_class = $class;
  1538. return true;
  1539. }
  1540. return false;
  1541. }
  1542.  
  1543.  
  1544. public function set_sanitize_class($class = 'SimplePie_Sanitize')
  1545. {
  1546. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Sanitize'))
  1547. {
  1548. $this->sanitize = new $class();
  1549. return true;
  1550. }
  1551. return false;
  1552. }
  1553.  
  1554.  
  1555. public function set_item_class($class = 'SimplePie_Item')
  1556. {
  1557. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Item'))
  1558. {
  1559. $this->item_class = $class;
  1560. return true;
  1561. }
  1562. return false;
  1563. }
  1564.  
  1565.  
  1566. public function set_author_class($class = 'SimplePie_Author')
  1567. {
  1568. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Author'))
  1569. {
  1570. $this->author_class = $class;
  1571. return true;
  1572. }
  1573. return false;
  1574. }
  1575.  
  1576.  
  1577. public function set_category_class($class = 'SimplePie_Category')
  1578. {
  1579. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Category'))
  1580. {
  1581. $this->category_class = $class;
  1582. return true;
  1583. }
  1584. return false;
  1585. }
  1586.  
  1587.  
  1588. public function set_enclosure_class($class = 'SimplePie_Enclosure')
  1589. {
  1590. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Enclosure'))
  1591. {
  1592. $this->enclosure_class = $class;
  1593. return true;
  1594. }
  1595. return false;
  1596. }
  1597.  
  1598.  
  1599. public function set_caption_class($class = 'SimplePie_Caption')
  1600. {
  1601. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Caption'))
  1602. {
  1603. $this->caption_class = $class;
  1604. return true;
  1605. }
  1606. return false;
  1607. }
  1608.  
  1609.  
  1610. public function set_copyright_class($class = 'SimplePie_Copyright')
  1611. {
  1612. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Copyright'))
  1613. {
  1614. $this->copyright_class = $class;
  1615. return true;
  1616. }
  1617. return false;
  1618. }
  1619.  
  1620.  
  1621. public function set_credit_class($class = 'SimplePie_Credit')
  1622. {
  1623. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Credit'))
  1624. {
  1625. $this->credit_class = $class;
  1626. return true;
  1627. }
  1628. return false;
  1629. }
  1630.  
  1631.  
  1632. public function set_rating_class($class = 'SimplePie_Rating')
  1633. {
  1634. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Rating'))
  1635. {
  1636. $this->rating_class = $class;
  1637. return true;
  1638. }
  1639. return false;
  1640. }
  1641.  
  1642.  
  1643. public function set_restriction_class($class = 'SimplePie_Restriction')
  1644. {
  1645. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Restriction'))
  1646. {
  1647. $this->restriction_class = $class;
  1648. return true;
  1649. }
  1650. return false;
  1651. }
  1652.  
  1653.  
  1654. public function set_content_type_sniffer_class($class = 'SimplePie_Content_Type_Sniffer')
  1655. {
  1656. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Content_Type_Sniffer'))
  1657. {
  1658. $this->content_type_sniffer_class = $class;
  1659. return true;
  1660. }
  1661. return false;
  1662. }
  1663.  
  1664.  
  1665. public function set_source_class($class = 'SimplePie_Source')
  1666. {
  1667. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Source'))
  1668. {
  1669. $this->source_class = $class;
  1670. return true;
  1671. }
  1672. return false;
  1673. }
  1674.  
  1675.  
  1676. public function set_useragent($ua = SIMPLEPIE_USERAGENT)
  1677. {
  1678. $this->useragent = (string) $ua;
  1679. }
  1680.  
  1681.  
  1682. public function set_cache_name_function($function = 'md5')
  1683. {
  1684. if (is_callable($function))
  1685. {
  1686. $this->cache_name_function = $function;
  1687. }
  1688. }
  1689.  
  1690.  
  1691. public function set_javascript($get = 'js')
  1692. {
  1693. if ($get)
  1694. {
  1695. $this->javascript = (string) $get;
  1696. }
  1697. else
  1698. {
  1699. $this->javascript = false;
  1700. }
  1701. }
  1702.  
  1703.  
  1704. public function set_stupidly_fast($set = false)
  1705. {
  1706. if ($set)
  1707. {
  1708. $this->enable_order_by_date(false);
  1709. $this->remove_div(false);
  1710. $this->strip_comments(false);
  1711. $this->strip_htmltags(false);
  1712. $this->strip_attributes(false);
  1713. $this->set_image_handler(false);
  1714. }
  1715. }
  1716.  
  1717.  
  1718. public function set_max_checked_feeds($max = 10)
  1719. {
  1720. $this->max_checked_feeds = (int) $max;
  1721. }
  1722.  
  1723. public function remove_div($enable = true)
  1724. {
  1725. $this->sanitize->remove_div($enable);
  1726. }
  1727.  
  1728. public function strip_htmltags($tags = '', $encode = null)
  1729. {
  1730. if ($tags === '')
  1731. {
  1732. $tags = $this->strip_htmltags;
  1733. }
  1734. $this->sanitize->strip_htmltags($tags);
  1735. if ($encode !== null)
  1736. {
  1737. $this->sanitize->encode_instead_of_strip($tags);
  1738. }
  1739. }
  1740.  
  1741. public function encode_instead_of_strip($enable = true)
  1742. {
  1743. $this->sanitize->encode_instead_of_strip($enable);
  1744. }
  1745.  
  1746. public function strip_attributes($attribs = '')
  1747. {
  1748. if ($attribs === '')
  1749. {
  1750. $attribs = $this->strip_attributes;
  1751. }
  1752. $this->sanitize->strip_attributes($attribs);
  1753. }
  1754.  
  1755. public function set_output_encoding($encoding = 'UTF-8')
  1756. {
  1757. $this->sanitize->set_output_encoding($encoding);
  1758. }
  1759.  
  1760. public function strip_comments($strip = false)
  1761. {
  1762. $this->sanitize->strip_comments($strip);
  1763. }
  1764.  
  1765.  
  1766. public function set_url_replacements($element_attribute = array('a' => 'href', 'area' => 'href', 'blockquote' => 'cite', 'del' => 'cite', 'form' => 'action', 'img' => array('longdesc', 'src'), 'input' => 'src', 'ins' => 'cite', 'q' => 'cite'))
  1767. {
  1768. $this->sanitize->set_url_replacements($element_attribute);
  1769. }
  1770.  
  1771.  
  1772. public function set_image_handler($page = false, $qs = 'i')
  1773. {
  1774. if ($page !== false)
  1775. {
  1776. $this->sanitize->set_image_handler($page . '?' . $qs . '=');
  1777. }
  1778. else
  1779. {
  1780. $this->image_handler = '';
  1781. }
  1782. }
  1783.  
  1784.  
  1785. public function set_item_limit($limit = 0)
  1786. {
  1787. $this->item_limit = (int) $limit;
  1788. }
  1789.  
  1790. public function init()
  1791. {
  1792. if ((function_exists('version_compare') && version_compare(PHP_VERSION, '5.0', '<')) || !extension_loaded('xml') || !extension_loaded('pcre'))
  1793. {
  1794. return false;
  1795. }
  1796. elseif (!extension_loaded('xmlreader'))
  1797. {
  1798. static $xml_is_sane = null;
  1799. if ($xml_is_sane === null)
  1800. {
  1801. $parser_check = xml_parser_create();
  1802. xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
  1803. xml_parser_free($parser_check);
  1804. $xml_is_sane = isset($values[0]['value']);
  1805. }
  1806. if (!$xml_is_sane)
  1807. {
  1808. return false;
  1809. }
  1810. }
  1811.  
  1812. if (isset($_GET[$this->javascript]))
  1813. {
  1814. SimplePie_Misc::output_javascript();
  1815. }
  1816.  
  1817. $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->cache_class);
  1818. $this->sanitize->pass_file_data($this->file_class, $this->timeout, $this->useragent, $this->force_fsockopen);
  1819.  
  1820. if ($this->feed_url !== null || $this->raw_data !== null)
  1821. {
  1822. $this->error = null;
  1823. $this->data = array();
  1824. $this->multifeed_objects = array();
  1825. $cache = false;
  1826.  
  1827. if ($this->feed_url !== null)
  1828. {
  1829. $parsed_feed_url = SimplePie_Misc::parse_url($this->feed_url);
  1830. if ($this->cache && $parsed_feed_url['scheme'] !== '')
  1831. {
  1832. $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc');
  1833. }
  1834. if ($cache && !$this->xml_dump)
  1835. {
  1836. $this->data = $cache->load();
  1837. if (!empty($this->data))
  1838. {
  1839. if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD)
  1840. {
  1841. $cache->unlink();
  1842. $this->data = array();
  1843. }
  1844. elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url)
  1845. {
  1846. $cache = false;
  1847. $this->data = array();
  1848. }
  1849. elseif (isset($this->data['feed_url']))
  1850. {
  1851. if ($cache->mtime() + $this->autodiscovery_cache_duration > time())
  1852. {
  1853. if ($this->data['feed_url'] === $this->data['url'])
  1854. {
  1855. $cache->unlink();
  1856. $this->data = array();
  1857. }
  1858. else
  1859. {
  1860. $this->set_feed_url($this->data['feed_url']);
  1861. return $this->init();
  1862. }
  1863. }
  1864. }
  1865. elseif ($cache->mtime() + $this->cache_duration < time())
  1866. {
  1867. if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag']))
  1868. {
  1869. $headers = array();
  1870. if (isset($this->data['headers']['last-modified']))
  1871. {
  1872. $headers['if-modified-since'] = $this->data['headers']['last-modified'];
  1873. }
  1874. if (isset($this->data['headers']['etag']))
  1875. {
  1876. $headers['if-none-match'] = '"' . $this->data['headers']['etag'] . '"';
  1877. }
  1878.  
  1879. $file = new $this->file_class($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen);
  1880.  
  1881. if ($file->success)
  1882. {
  1883. if ($file->status_code === 304)
  1884. {
  1885. $cache->touch();
  1886. return true;
  1887. }
  1888. else
  1889. {
  1890. $headers = $file->headers;
  1891. }
  1892. }
  1893. else
  1894. {
  1895. unset($file);
  1896. }
  1897. }
  1898. }
  1899. else
  1900. {
  1901. return true;
  1902. }
  1903. }
  1904. else
  1905. {
  1906. $cache->unlink();
  1907. $this->data = array();
  1908. }
  1909. }
  1910. if (!isset($file))
  1911. {
  1912. if (is_a($this->file, 'SimplePie_File') && $this->file->url === $this->feed_url)
  1913. {
  1914. $file =& $this->file;
  1915. }
  1916. else
  1917. {
  1918. $file = new $this->file_class($this->feed_url, $this->timeout, 5, null, $this->useragent, $this->force_fsockopen);
  1919. }
  1920. }
  1921. if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
  1922. {
  1923. $this->error = $file->error;
  1924. if (!empty($this->data))
  1925. {
  1926. return true;
  1927. }
  1928. else
  1929. {
  1930. return false;
  1931. }
  1932. }
  1933.  
  1934. if (!$this->force_feed)
  1935. {
  1936. $locate = new $this->locator_class($file, $this->timeout, $this->useragent, $this->file_class, $this->max_checked_feeds, $this->content_type_sniffer_class);
  1937.  
  1938. if (!$locate->is_feed($file))
  1939. {
  1940. unset($file);
  1941. if ($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds))
  1942. {
  1943. if ($cache)
  1944. {
  1945. $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD);
  1946. // die(var_dump($this));
  1947. if (!$cache->save($this))
  1948. {
  1949. trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
  1950. }
  1951. $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc');
  1952. }
  1953. $this->feed_url = $file->url;
  1954. }
  1955. else
  1956. {
  1957. $this->error = "A feed could not be found at $this->feed_url. A feed with an invalid mime type may fall victim to this error, or " . SIMPLEPIE_NAME . " was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed.";
  1958. SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
  1959. return false;
  1960. }
  1961. }
  1962. $locate = null;
  1963. }
  1964.  
  1965. $headers = $file->headers;
  1966. $data = $file->body;
  1967. $sniffer = new $this->content_type_sniffer_class($file);
  1968. $sniffed = $sniffer->get_type();
  1969. }
  1970. else
  1971. {
  1972. $data = $this->raw_data;
  1973. }
  1974.  
  1975. $encodings = array();
  1976.  
  1977. if ($this->input_encoding !== false)
  1978. {
  1979. $encodings[] = $this->input_encoding;
  1980. }
  1981.  
  1982. $application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
  1983. $text_types = array('text/xml', 'text/xml-external-parsed-entity');
  1984.  
  1985. if (isset($sniffed))
  1986. {
  1987. if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml')
  1988. {
  1989. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
  1990. {
  1991. $encodings[] = strtoupper($charset[1]);
  1992. }
  1993. $encodings = array_merge($encodings, SimplePie_Misc::xml_encoding($data));
  1994. $encodings[] = 'UTF-8';
  1995. }
  1996. elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml')
  1997. {
  1998. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
  1999. {
  2000. $encodings[] = $charset[1];
  2001. }
  2002. $encodings[] = 'US-ASCII';
  2003. }
  2004. elseif (substr($sniffed, 0, 5) === 'text/')
  2005. {
  2006. $encodings[] = 'US-ASCII';
  2007. }
  2008. }
  2009.  
  2010. $encodings = array_merge($encodings, SimplePie_Misc::xml_encoding($data));
  2011. $encodings[] = 'UTF-8';
  2012. $encodings[] = 'ISO-8859-1';
  2013.  
  2014. $encodings = array_unique($encodings);
  2015.  
  2016. if ($this->xml_dump)
  2017. {
  2018. header('Content-type: text/xml; charset=' . $encodings[0]);
  2019. echo $data;
  2020. }
  2021.  
  2022. foreach ($encodings as $encoding)
  2023. {
  2024. if ($utf8_data = SimplePie_Misc::change_encoding($data, $encoding, 'UTF-8'))
  2025. {
  2026. $parser = new $this->parser_class();
  2027.  
  2028. if ($parser->parse($utf8_data, 'UTF-8'))
  2029. {
  2030. $this->data = $parser->get_data();
  2031. if ($this->get_type() & ~SIMPLEPIE_TYPE_NONE)
  2032. {
  2033. if (isset($headers))
  2034. {
  2035. $this->data['headers'] = $headers;
  2036. }
  2037. $this->data['build'] = SIMPLEPIE_BUILD;
  2038.  
  2039. if ($cache && !$cache->save($this))
  2040. {
  2041. trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
  2042. }
  2043. return true;
  2044. }
  2045. else
  2046. {
  2047. $this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed.";
  2048. SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
  2049. return false;
  2050. }
  2051. }
  2052. }
  2053. }
  2054.  
  2055. if (isset($parser))
  2056. {
  2057. $this->error = sprintf('This XML document is invalid, likely due to invalid characters. XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column());
  2058. }
  2059. else
  2060. {
  2061. $this->error = 'The data could not be converted to UTF-8. You MUST have either the iconv or mbstring extension installed. Upgrading to PHP 5.x (which includes iconv) is highly recommended.';
  2062. }
  2063.  
  2064. SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
  2065.  
  2066. return false;
  2067. }
  2068. elseif (!empty($this->multifeed_url))
  2069. {
  2070. $i = 0;
  2071. $success = 0;
  2072. $this->multifeed_objects = array();
  2073. foreach ($this->multifeed_url as $url)
  2074. {
  2075. $this->multifeed_objects[$i] = clone $this;
  2076. $this->multifeed_objects[$i]->set_feed_url($url);
  2077. $success |= $this->multifeed_objects[$i]->init();
  2078. $i++;
  2079. }
  2080. return (bool) $success;
  2081. }
  2082. else
  2083. {
  2084. return false;
  2085. }
  2086. }
  2087.  
  2088.  
  2089. public function error()
  2090. {
  2091. return $this->error;
  2092. }
  2093.  
  2094. public function get_encoding()
  2095. {
  2096. return $this->sanitize->output_encoding;
  2097. }
  2098.  
  2099. public function handle_content_type($mime = 'text/html')
  2100. {
  2101. if (!headers_sent())
  2102. {
  2103. $header = "Content-type: $mime;";
  2104. if ($this->get_encoding())
  2105. {
  2106. $header .= ' charset=' . $this->get_encoding();
  2107. }
  2108. else
  2109. {
  2110. $header .= ' charset=UTF-8';
  2111. }
  2112. header($header);
  2113. }
  2114. }
  2115.  
  2116. public function get_type()
  2117. {
  2118. if (!isset($this->data['type']))
  2119. {
  2120. $this->data['type'] = SIMPLEPIE_TYPE_ALL;
  2121. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed']))
  2122. {
  2123. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10;
  2124. }
  2125. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed']))
  2126. {
  2127. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03;
  2128. }
  2129. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF']))
  2130. {
  2131. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel'])
  2132. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image'])
  2133. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item'])
  2134. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput']))
  2135. {
  2136. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10;
  2137. }
  2138. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel'])
  2139. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image'])
  2140. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item'])
  2141. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput']))
  2142. {
  2143. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090;
  2144. }
  2145. }
  2146. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss']))
  2147. {
  2148. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL;
  2149. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
  2150. {
  2151. switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
  2152. {
  2153. case '0.91':
  2154. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091;
  2155. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
  2156. {
  2157. switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
  2158. {
  2159. case '0':
  2160. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE;
  2161. break;
  2162.  
  2163. case '24':
  2164. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND;
  2165. break;
  2166. }
  2167. }
  2168. break;
  2169.  
  2170. case '0.92':
  2171. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092;
  2172. break;
  2173.  
  2174. case '0.93':
  2175. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093;
  2176. break;
  2177.  
  2178. case '0.94':
  2179. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094;
  2180. break;
  2181.  
  2182. case '2.0':
  2183. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20;
  2184. break;
  2185. }
  2186. }
  2187. }
  2188. else
  2189. {
  2190. $this->data['type'] = SIMPLEPIE_TYPE_NONE;
  2191. }
  2192. }
  2193. return $this->data['type'];
  2194. }
  2195.  
  2196.  
  2197. public function subscribe_url()
  2198. {
  2199. if ($this->feed_url !== null)
  2200. {
  2201. return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI);
  2202. }
  2203. else
  2204. {
  2205. return null;
  2206. }
  2207. }
  2208.  
  2209. public function get_feed_tags($namespace, $tag)
  2210. {
  2211. $type = $this->get_type();
  2212. if ($type & SIMPLEPIE_TYPE_ATOM_10)
  2213. {
  2214. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag]))
  2215. {
  2216. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag];
  2217. }
  2218. }
  2219. if ($type & SIMPLEPIE_TYPE_ATOM_03)
  2220. {
  2221. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag]))
  2222. {
  2223. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag];
  2224. }
  2225. }
  2226. if ($type & SIMPLEPIE_TYPE_RSS_RDF)
  2227. {
  2228. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag]))
  2229. {
  2230. return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag];
  2231. }
  2232. }
  2233. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  2234. {
  2235. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag]))
  2236. {
  2237. return $this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag];
  2238. }
  2239. }
  2240. return null;
  2241. }
  2242.  
  2243. public function get_channel_tags($namespace, $tag)
  2244. {
  2245. $type = $this->get_type();
  2246. if ($type & SIMPLEPIE_TYPE_ATOM_ALL)
  2247. {
  2248. if ($return = $this->get_feed_tags($namespace, $tag))
  2249. {
  2250. return $return;
  2251. }
  2252. }
  2253. if ($type & SIMPLEPIE_TYPE_RSS_10)
  2254. {
  2255. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel'))
  2256. {
  2257. if (isset($channel[0]['child'][$namespace][$tag]))
  2258. {
  2259. return $channel[0]['child'][$namespace][$tag];
  2260. }
  2261. }
  2262. }
  2263. if ($type & SIMPLEPIE_TYPE_RSS_090)
  2264. {
  2265. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel'))
  2266. {
  2267. if (isset($channel[0]['child'][$namespace][$tag]))
  2268. {
  2269. return $channel[0]['child'][$namespace][$tag];
  2270. }
  2271. }
  2272. }
  2273. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  2274. {
  2275. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'channel'))
  2276. {
  2277. if (isset($channel[0]['child'][$namespace][$tag]))
  2278. {
  2279. return $channel[0]['child'][$namespace][$tag];
  2280. }
  2281. }
  2282. }
  2283. return null;
  2284. }
  2285.  
  2286. public function get_image_tags($namespace, $tag)
  2287. {
  2288. $type = $this->get_type();
  2289. if ($type & SIMPLEPIE_TYPE_RSS_10)
  2290. {
  2291. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image'))
  2292. {
  2293. if (isset($image[0]['child'][$namespace][$tag]))
  2294. {
  2295. return $image[0]['child'][$namespace][$tag];
  2296. }
  2297. }
  2298. }
  2299. if ($type & SIMPLEPIE_TYPE_RSS_090)
  2300. {
  2301. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image'))
  2302. {
  2303. if (isset($image[0]['child'][$namespace][$tag]))
  2304. {
  2305. return $image[0]['child'][$namespace][$tag];
  2306. }
  2307. }
  2308. }
  2309. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  2310. {
  2311. if ($image = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'image'))
  2312. {
  2313. if (isset($image[0]['child'][$namespace][$tag]))
  2314. {
  2315. return $image[0]['child'][$namespace][$tag];
  2316. }
  2317. }
  2318. }
  2319. return null;
  2320. }
  2321.  
  2322. public function get_base($element = array())
  2323. {
  2324. if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base']))
  2325. {
  2326. return $element['xml_base'];
  2327. }
  2328. elseif ($this->get_link() !== null)
  2329. {
  2330. return $this->get_link();
  2331. }
  2332. else
  2333. {
  2334. return $this->subscribe_url();
  2335. }
  2336. }
  2337.  
  2338. public function sanitize($data, $type, $base = '')
  2339. {
  2340. return $this->sanitize->sanitize($data, $type, $base);
  2341. }
  2342.  
  2343. public function get_title()
  2344. {
  2345. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  2346. {
  2347. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2348. }
  2349. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  2350. {
  2351. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2352. }
  2353. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  2354. {
  2355. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2356. }
  2357. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  2358. {
  2359. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2360. }
  2361. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  2362. {
  2363. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2364. }
  2365. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  2366. {
  2367. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2368. }
  2369. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  2370. {
  2371. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2372. }
  2373. else
  2374. {
  2375. return null;
  2376. }
  2377. }
  2378.  
  2379. public function get_category($key = 0)
  2380. {
  2381. $categories = $this->get_categories();
  2382. if (isset($categories[$key]))
  2383. {
  2384. return $categories[$key];
  2385. }
  2386. else
  2387. {
  2388. return null;
  2389. }
  2390. }
  2391.  
  2392. public function get_categories()
  2393. {
  2394. $categories = array();
  2395.  
  2396. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  2397. {
  2398. $term = null;
  2399. $scheme = null;
  2400. $label = null;
  2401. if (isset($category['attribs']['']['term']))
  2402. {
  2403. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  2404. }
  2405. if (isset($category['attribs']['']['scheme']))
  2406. {
  2407. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2408. }
  2409. if (isset($category['attribs']['']['label']))
  2410. {
  2411. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  2412. }
  2413. $categories[] = new $this->category_class($term, $scheme, $label);
  2414. }
  2415. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
  2416. {
  2417. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2418. if (isset($category['attribs']['']['domain']))
  2419. {
  2420. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  2421. }
  2422. else
  2423. {
  2424. $scheme = null;
  2425. }
  2426. $categories[] = new $this->category_class($term, $scheme, null);
  2427. }
  2428. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  2429. {
  2430. $categories[] = new $this->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  2431. }
  2432. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  2433. {
  2434. $categories[] = new $this->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  2435. }
  2436.  
  2437. if (!empty($categories))
  2438. {
  2439. return SimplePie_Misc::array_unique($categories);
  2440. }
  2441. else
  2442. {
  2443. return null;
  2444. }
  2445. }
  2446.  
  2447. public function get_author($key = 0)
  2448. {
  2449. $authors = $this->get_authors();
  2450. if (isset($authors[$key]))
  2451. {
  2452. return $authors[$key];
  2453. }
  2454. else
  2455. {
  2456. return null;
  2457. }
  2458. }
  2459.  
  2460. public function get_authors()
  2461. {
  2462. $authors = array();
  2463. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  2464. {
  2465. $name = null;
  2466. $uri = null;
  2467. $email = null;
  2468. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  2469. {
  2470. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2471. }
  2472. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  2473. {
  2474. $uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  2475. }
  2476. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  2477. {
  2478. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2479. }
  2480. if ($name !== null || $email !== null || $uri !== null)
  2481. {
  2482. $authors[] = new $this->author_class($name, $uri, $email);
  2483. }
  2484. }
  2485. if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  2486. {
  2487. $name = null;
  2488. $url = null;
  2489. $email = null;
  2490. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  2491. {
  2492. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2493. }
  2494. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  2495. {
  2496. $url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  2497. }
  2498. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  2499. {
  2500. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2501. }
  2502. if ($name !== null || $email !== null || $url !== null)
  2503. {
  2504. $authors[] = new $this->author_class($name, $url, $email);
  2505. }
  2506. }
  2507. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  2508. {
  2509. $authors[] = new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  2510. }
  2511. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  2512. {
  2513. $authors[] = new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  2514. }
  2515. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  2516. {
  2517. $authors[] = new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  2518. }
  2519.  
  2520. if (!empty($authors))
  2521. {
  2522. return SimplePie_Misc::array_unique($authors);
  2523. }
  2524. else
  2525. {
  2526. return null;
  2527. }
  2528. }
  2529.  
  2530. public function get_contributor($key = 0)
  2531. {
  2532. $contributors = $this->get_contributors();
  2533. if (isset($contributors[$key]))
  2534. {
  2535. return $contributors[$key];
  2536. }
  2537. else
  2538. {
  2539. return null;
  2540. }
  2541. }
  2542.  
  2543. public function get_contributors()
  2544. {
  2545. $contributors = array();
  2546. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  2547. {
  2548. $name = null;
  2549. $uri = null;
  2550. $email = null;
  2551. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  2552. {
  2553. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2554. }
  2555. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  2556. {
  2557. $uri = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  2558. }
  2559. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  2560. {
  2561. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2562. }
  2563. if ($name !== null || $email !== null || $uri !== null)
  2564. {
  2565. $contributors[] = new $this->author_class($name, $uri, $email);
  2566. }
  2567. }
  2568. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  2569. {
  2570. $name = null;
  2571. $url = null;
  2572. $email = null;
  2573. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  2574. {
  2575. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2576. }
  2577. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  2578. {
  2579. $url = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  2580. }
  2581. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  2582. {
  2583. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2584. }
  2585. if ($name !== null || $email !== null || $url !== null)
  2586. {
  2587. $contributors[] = new $this->author_class($name, $url, $email);
  2588. }
  2589. }
  2590.  
  2591. if (!empty($contributors))
  2592. {
  2593. return SimplePie_Misc::array_unique($contributors);
  2594. }
  2595. else
  2596. {
  2597. return null;
  2598. }
  2599. }
  2600.  
  2601. public function get_link($key = 0, $rel = 'alternate')
  2602. {
  2603. $links = $this->get_links($rel);
  2604. if (isset($links[$key]))
  2605. {
  2606. return $links[$key];
  2607. }
  2608. else
  2609. {
  2610. return null;
  2611. }
  2612. }
  2613.  
  2614.  
  2615. public function get_permalink()
  2616. {
  2617. return $this->get_link(0);
  2618. }
  2619.  
  2620. public function get_links($rel = 'alternate')
  2621. {
  2622. if (!isset($this->data['links']))
  2623. {
  2624. $this->data['links'] = array();
  2625. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
  2626. {
  2627. foreach ($links as $link)
  2628. {
  2629. if (isset($link['attribs']['']['href']))
  2630. {
  2631. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']

URL: http://simplepie.org

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.