PageRenderTime 75ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 2ms

/third-party/simplepie.php

https://github.com/UCF/TechTransfer-Theme
PHP | 15123 lines | 12746 code | 713 blank | 1664 comment | 1019 complexity | 5498f0e31ca5c00c663d1a60f15474a6 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  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. * SimplePie class.
  47. *
  48. * Class for backward compatibility.
  49. *
  50. * @package SimplePie
  51. */
  52. class SimplePie extends SimplePie_Core
  53. {
  54. }
  55. class SimplePie_Author
  56. {
  57. var $name;
  58. var $link;
  59. var $email;
  60. // Constructor, used to input the data
  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. public function __toString()
  68. {
  69. // There is no $this->data here
  70. return md5(serialize($this));
  71. }
  72. public function get_name()
  73. {
  74. if ($this->name !== null)
  75. {
  76. return $this->name;
  77. }
  78. else
  79. {
  80. return null;
  81. }
  82. }
  83. public function get_link()
  84. {
  85. if ($this->link !== null)
  86. {
  87. return $this->link;
  88. }
  89. else
  90. {
  91. return null;
  92. }
  93. }
  94. public function get_email()
  95. {
  96. if ($this->email !== null)
  97. {
  98. return $this->email;
  99. }
  100. else
  101. {
  102. return null;
  103. }
  104. }
  105. }
  106. interface SimplePie_Cache_Base
  107. {
  108. /**
  109. * Feed cache type
  110. */
  111. const TYPE_FEED = 'spc';
  112. /**
  113. * Image cache type
  114. */
  115. const TYPE_IMAGE = 'spi';
  116. /**
  117. * Create a new cache object
  118. *
  119. * @param string $location Location string (from SimplePie::$cache_location)
  120. * @param string $name Unique ID for the cache
  121. * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
  122. */
  123. public function __construct($location, $name, $type);
  124. /**
  125. * Save data to the cache
  126. *
  127. * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
  128. */
  129. public function save($data);
  130. /**
  131. * Retrieve the data saved to the cache
  132. *
  133. * @return array Data for SimplePie::$data
  134. */
  135. public function load();
  136. /**
  137. * Retrieve the last modified time for the cache
  138. *
  139. * @return int Timestamp
  140. */
  141. public function mtime();
  142. /**
  143. * Set the last modified time to the current time
  144. *
  145. * @return bool Success status
  146. */
  147. public function touch();
  148. /**
  149. * Remove the cache
  150. *
  151. * @return bool Success status
  152. */
  153. public function unlink();
  154. }
  155. abstract class SimplePie_Cache_DB implements SimplePie_Cache_Base
  156. {
  157. protected static function prepare_simplepie_object_for_cache(&$data)
  158. {
  159. $items = $data->get_items();
  160. $items_by_id = array();
  161. if (!empty($items))
  162. {
  163. foreach ($items as $item)
  164. {
  165. $items_by_id[$item->get_id()] = $item;
  166. }
  167. if (count($items_by_id) !== count($items))
  168. {
  169. $items_by_id = array();
  170. foreach ($items as $item)
  171. {
  172. $items_by_id[$item->get_id(true)] = $item;
  173. }
  174. }
  175. if (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
  176. {
  177. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
  178. }
  179. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
  180. {
  181. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
  182. }
  183. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
  184. {
  185. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
  186. }
  187. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0]))
  188. {
  189. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0];
  190. }
  191. else
  192. {
  193. $channel = null;
  194. }
  195. if ($channel !== null)
  196. {
  197. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']))
  198. {
  199. unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']);
  200. }
  201. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']))
  202. {
  203. unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']);
  204. }
  205. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']))
  206. {
  207. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']);
  208. }
  209. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']))
  210. {
  211. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']);
  212. }
  213. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']))
  214. {
  215. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']);
  216. }
  217. }
  218. if (isset($data->data['items']))
  219. {
  220. unset($data->data['items']);
  221. }
  222. if (isset($data->data['ordered_items']))
  223. {
  224. unset($data->data['ordered_items']);
  225. }
  226. }
  227. return array(serialize($data->data), $items_by_id);
  228. }
  229. }
  230. class SimplePie_Cache_File implements SimplePie_Cache_Base
  231. {
  232. protected $location;
  233. protected $filename;
  234. protected $extension;
  235. protected $name;
  236. public function __construct($location, $filename, $extension)
  237. {
  238. $this->location = $location;
  239. $this->filename = $filename;
  240. $this->extension = $extension;
  241. $this->name = "$this->location/$this->filename.$this->extension";
  242. }
  243. public function save($data)
  244. {
  245. if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
  246. {
  247. if (is_a($data, 'SimplePie'))
  248. {
  249. $data = $data->data;
  250. }
  251. $data = serialize($data);
  252. return (bool) file_put_contents($this->name, $data);
  253. }
  254. return false;
  255. }
  256. public function load()
  257. {
  258. if (file_exists($this->name) && is_readable($this->name))
  259. {
  260. return unserialize(file_get_contents($this->name));
  261. }
  262. return false;
  263. }
  264. public function mtime()
  265. {
  266. if (file_exists($this->name))
  267. {
  268. return filemtime($this->name);
  269. }
  270. return false;
  271. }
  272. public function touch()
  273. {
  274. if (file_exists($this->name))
  275. {
  276. return touch($this->name);
  277. }
  278. return false;
  279. }
  280. public function unlink()
  281. {
  282. if (file_exists($this->name))
  283. {
  284. return unlink($this->name);
  285. }
  286. return false;
  287. }
  288. }
  289. class SimplePie_Cache_Memcache implements SimplePie_Cache_Base
  290. {
  291. protected $cache;
  292. protected $options;
  293. protected $name;
  294. public function __construct($url, $filename, $extension)
  295. {
  296. $this->options = array(
  297. 'host' => '127.0.0.1',
  298. 'port' => 11211,
  299. 'extras' => array(
  300. 'timeout' => 3600, // one hour
  301. 'prefix' => 'simplepie_',
  302. ),
  303. );
  304. $this->options = array_merge_recursive($this->options, SimplePie_Cache::parse_URL($url));
  305. $this->name = $this->options['extras']['prefix'] . md5("$filename:$extension");
  306. $this->cache = new Memcache();
  307. $this->cache->addServer($this->options['host'], (int) $this->options['port']);
  308. }
  309. public function save($data)
  310. {
  311. if (is_a($data, 'SimplePie'))
  312. {
  313. $data = $data->data;
  314. }
  315. return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
  316. }
  317. public function load()
  318. {
  319. $data = $this->cache->get($this->name);
  320. if ($data !== false)
  321. {
  322. return unserialize($data);
  323. }
  324. return false;
  325. }
  326. public function mtime()
  327. {
  328. $data = $this->cache->get($this->name);
  329. if ($data !== false)
  330. {
  331. // essentially ignore the mtime because Memcache expires on it's own
  332. return time();
  333. }
  334. return false;
  335. }
  336. public function touch()
  337. {
  338. $data = $this->cache->get($this->name);
  339. if ($data !== false)
  340. {
  341. return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->duration);
  342. }
  343. return false;
  344. }
  345. public function unlink()
  346. {
  347. return $this->cache->delete($this->name, 0);
  348. }
  349. }
  350. class SimplePie_Cache_MySQL extends SimplePie_Cache_DB
  351. {
  352. protected $mysql;
  353. protected $options;
  354. protected $id;
  355. public function __construct($url, $name, $extension)
  356. {
  357. $this->options = array(
  358. 'user' => null,
  359. 'pass' => null,
  360. 'host' => '127.0.0.1',
  361. 'port' => '3306',
  362. 'path' => '',
  363. 'extras' => array(
  364. 'prefix' => '',
  365. ),
  366. );
  367. $this->options = array_merge_recursive($this->options, SimplePie_Cache::parse_URL($url));
  368. // Path is prefixed with a "/"
  369. $this->options['dbname'] = substr($this->options['path'], 1);
  370. try
  371. {
  372. $this->mysql = new PDO("mysql:dbname={$this->options['dbname']};host={$this->options['host']};port={$this->options['port']}", $this->options['user'], $this->options['pass'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
  373. }
  374. catch (PDOException $e)
  375. {
  376. $this->mysql = null;
  377. return;
  378. }
  379. $this->id = $name . $extension;
  380. if (!$query = $this->mysql->query('SHOW TABLES'))
  381. {
  382. $this->mysql = null;
  383. return;
  384. }
  385. $db = array();
  386. while ($row = $query->fetchColumn())
  387. {
  388. $db[] = $row;
  389. }
  390. if (!in_array($this->options['extras']['prefix'] . 'cache_data', $db))
  391. {
  392. $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . '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)))');
  393. if ($query === false)
  394. {
  395. $this->mysql = null;
  396. }
  397. }
  398. if (!in_array($this->options['extras']['prefix'] . 'items', $db))
  399. {
  400. $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . '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)))');
  401. if ($query === false)
  402. {
  403. $this->mysql = null;
  404. }
  405. }
  406. }
  407. public function save($data)
  408. {
  409. if ($this->mysql === null)
  410. {
  411. return false;
  412. }
  413. if (is_a($data, 'SimplePie'))
  414. {
  415. $data = clone $data;
  416. $prepared = self::prepare_simplepie_object_for_cache($data);
  417. $query = $this->mysql->prepare('SELECT COUNT(*) FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
  418. $query->bindValue(':feed', $this->id);
  419. if ($query->execute())
  420. {
  421. if ($query->fetchColumn() > 0)
  422. {
  423. $items = count($prepared[1]);
  424. if ($items)
  425. {
  426. $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = :items, `data` = :data, `mtime` = :time WHERE `id` = :feed';
  427. $query = $this->mysql->prepare($sql);
  428. $query->bindValue(':items', $items);
  429. }
  430. else
  431. {
  432. $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `data` = :data, `mtime` = :time WHERE `id` = :feed';
  433. $query = $this->mysql->prepare($sql);
  434. }
  435. $query->bindValue(':data', $prepared[0]);
  436. $query->bindValue(':time', time());
  437. $query->bindValue(':feed', $this->id);
  438. if (!$query->execute())
  439. {
  440. return false;
  441. }
  442. }
  443. else
  444. {
  445. $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:feed, :count, :data, :time)');
  446. $query->bindValue(':feed', $this->id);
  447. $query->bindValue(':count', count($prepared[1]));
  448. $query->bindValue(':data', $prepared[0]);
  449. $query->bindValue(':time', time());
  450. if (!$query->execute())
  451. {
  452. return false;
  453. }
  454. }
  455. $ids = array_keys($prepared[1]);
  456. if (!empty($ids))
  457. {
  458. foreach ($ids as $id)
  459. {
  460. $database_ids[] = $this->mysql->quote($id);
  461. }
  462. $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `id` = ' . implode(' OR `id` = ', $database_ids) . ' AND `feed_id` = :feed');
  463. $query->bindValue(':feed', $this->id);
  464. if ($query->execute())
  465. {
  466. $existing_ids = array();
  467. while ($row = $query->fetchColumn())
  468. {
  469. $existing_ids[] = $row;
  470. }
  471. $new_ids = array_diff($ids, $existing_ids);
  472. foreach ($new_ids as $new_id)
  473. {
  474. if (!($date = $prepared[1][$new_id]->get_date('U')))
  475. {
  476. $date = time();
  477. }
  478. $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'items` (`feed_id`, `id`, `data`, `posted`) VALUES(:feed, :id, :data, :date)');
  479. $query->bindValue(':feed', $this->id);
  480. $query->bindValue(':id', $new_id);
  481. $query->bindValue(':data', serialize($prepared[1][$new_id]->data));
  482. $query->bindValue(':date', $date);
  483. if (!$query->execute())
  484. {
  485. return false;
  486. }
  487. }
  488. return true;
  489. }
  490. }
  491. else
  492. {
  493. return true;
  494. }
  495. }
  496. }
  497. else
  498. {
  499. $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
  500. $query->bindValue(':feed', $this->id);
  501. if ($query->execute())
  502. {
  503. if ($query->rowCount() > 0)
  504. {
  505. $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = 0, `data` = :data, `mtime` = :time WHERE `id` = :feed');
  506. $query->bindValue(':data', serialize($data));
  507. $query->bindValue(':time', time());
  508. $query->bindValue(':feed', $this->id);
  509. if ($this->execute())
  510. {
  511. return true;
  512. }
  513. }
  514. else
  515. {
  516. $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:id, 0, :data, :time)');
  517. $query->bindValue(':id', $this->id);
  518. $query->bindValue(':data', serialize($data));
  519. $query->bindValue(':time', time());
  520. if ($query->execute())
  521. {
  522. return true;
  523. }
  524. }
  525. }
  526. }
  527. return false;
  528. }
  529. public function load()
  530. {
  531. if ($this->mysql === null)
  532. {
  533. return false;
  534. }
  535. $query = $this->mysql->prepare('SELECT `items`, `data` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
  536. $query->bindValue(':id', $this->id);
  537. if ($query->execute() && ($row = $query->fetch()))
  538. {
  539. $data = unserialize($row[1]);
  540. if (isset($this->options['items'][0]))
  541. {
  542. $items = (int) $this->options['items'][0];
  543. }
  544. else
  545. {
  546. $items = (int) $row[0];
  547. }
  548. if ($items !== 0)
  549. {
  550. if (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
  551. {
  552. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
  553. }
  554. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
  555. {
  556. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
  557. }
  558. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
  559. {
  560. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
  561. }
  562. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]))
  563. {
  564. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0];
  565. }
  566. else
  567. {
  568. $feed = null;
  569. }
  570. if ($feed !== null)
  571. {
  572. $sql = 'SELECT `data` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :feed ORDER BY `posted` DESC';
  573. if ($items > 0)
  574. {
  575. $sql .= ' LIMIT ' . $items;
  576. }
  577. $query = $this->mysql->prepare($sql);
  578. $query->bindValue(':feed', $this->id);
  579. if ($query->execute())
  580. {
  581. while ($row = $query->fetchColumn())
  582. {
  583. $feed['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry'][] = unserialize($row);
  584. }
  585. }
  586. else
  587. {
  588. return false;
  589. }
  590. }
  591. }
  592. return $data;
  593. }
  594. return false;
  595. }
  596. public function mtime()
  597. {
  598. if ($this->mysql === null)
  599. {
  600. return false;
  601. }
  602. $query = $this->mysql->prepare('SELECT `mtime` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
  603. $query->bindValue(':id', $this->id);
  604. if ($query->execute() && ($time = $query->fetchColumn()))
  605. {
  606. return $time;
  607. }
  608. else
  609. {
  610. return false;
  611. }
  612. }
  613. public function touch()
  614. {
  615. if ($this->mysql === null)
  616. {
  617. return false;
  618. }
  619. $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `mtime` = :time WHERE `id` = :id');
  620. $query->bindValue(':time', time());
  621. $query->bindValue(':id', $this->id);
  622. if ($query->execute() && $query->rowCount() > 0)
  623. {
  624. return true;
  625. }
  626. else
  627. {
  628. return false;
  629. }
  630. }
  631. public function unlink()
  632. {
  633. if ($this->mysql === null)
  634. {
  635. return false;
  636. }
  637. $query = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
  638. $query->bindValue(':id', $this->id);
  639. $query2 = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :id');
  640. $query2->bindValue(':id', $this->id);
  641. if ($query->execute() && $query2->execute())
  642. {
  643. return true;
  644. }
  645. else
  646. {
  647. return false;
  648. }
  649. }
  650. }
  651. class SimplePie_Cache
  652. {
  653. /**
  654. * Cache handler classes
  655. *
  656. * These receive 3 parameters to their constructor, as documented in
  657. * {@see register()}
  658. * @var array
  659. */
  660. protected static $handlers = array(
  661. 'mysql' => 'SimplePie_Cache_MySQL',
  662. 'memcache' => 'SimplePie_Cache_Memcache',
  663. );
  664. /**
  665. * Don't call the constructor. Please.
  666. */
  667. private function __construct() { }
  668. /**
  669. * Create a new SimplePie_Cache object
  670. */
  671. public static function create($location, $filename, $extension)
  672. {
  673. $type = explode(':', $location, 2);
  674. $type = $type[0];
  675. if (!empty(self::$handlers[$type]))
  676. {
  677. $class = self::$handlers[$type];
  678. return new $class($location, $filename, $extension);
  679. }
  680. return new SimplePie_Cache_File($location, $filename, $extension);
  681. }
  682. /**
  683. * Register a handler
  684. *
  685. * @param string $type DSN type to register for
  686. * @param string $class Name of handler class. Must implement SimplePie_Cache_Base
  687. */
  688. public static function register($type, $class)
  689. {
  690. self::$handlers[$type] = $class;
  691. }
  692. /**
  693. * Parse a URL into an array
  694. *
  695. * @param string $url
  696. * @return array
  697. */
  698. public static function parse_URL($url)
  699. {
  700. $params = parse_url($url);
  701. $params['extras'] = array();
  702. if (isset($params['query']))
  703. {
  704. parse_str($params['query'], $params['extras']);
  705. }
  706. return $params;
  707. }
  708. }
  709. class SimplePie_Caption
  710. {
  711. var $type;
  712. var $lang;
  713. var $startTime;
  714. var $endTime;
  715. var $text;
  716. // Constructor, used to input the data
  717. public function __construct($type = null, $lang = null, $startTime = null, $endTime = null, $text = null)
  718. {
  719. $this->type = $type;
  720. $this->lang = $lang;
  721. $this->startTime = $startTime;
  722. $this->endTime = $endTime;
  723. $this->text = $text;
  724. }
  725. public function __toString()
  726. {
  727. // There is no $this->data here
  728. return md5(serialize($this));
  729. }
  730. public function get_endtime()
  731. {
  732. if ($this->endTime !== null)
  733. {
  734. return $this->endTime;
  735. }
  736. else
  737. {
  738. return null;
  739. }
  740. }
  741. public function get_language()
  742. {
  743. if ($this->lang !== null)
  744. {
  745. return $this->lang;
  746. }
  747. else
  748. {
  749. return null;
  750. }
  751. }
  752. public function get_starttime()
  753. {
  754. if ($this->startTime !== null)
  755. {
  756. return $this->startTime;
  757. }
  758. else
  759. {
  760. return null;
  761. }
  762. }
  763. public function get_text()
  764. {
  765. if ($this->text !== null)
  766. {
  767. return $this->text;
  768. }
  769. else
  770. {
  771. return null;
  772. }
  773. }
  774. public function get_type()
  775. {
  776. if ($this->type !== null)
  777. {
  778. return $this->type;
  779. }
  780. else
  781. {
  782. return null;
  783. }
  784. }
  785. }
  786. class SimplePie_Category
  787. {
  788. var $term;
  789. var $scheme;
  790. var $label;
  791. // Constructor, used to input the data
  792. public function __construct($term = null, $scheme = null, $label = null)
  793. {
  794. $this->term = $term;
  795. $this->scheme = $scheme;
  796. $this->label = $label;
  797. }
  798. public function __toString()
  799. {
  800. // There is no $this->data here
  801. return md5(serialize($this));
  802. }
  803. public function get_term()
  804. {
  805. if ($this->term !== null)
  806. {
  807. return $this->term;
  808. }
  809. else
  810. {
  811. return null;
  812. }
  813. }
  814. public function get_scheme()
  815. {
  816. if ($this->scheme !== null)
  817. {
  818. return $this->scheme;
  819. }
  820. else
  821. {
  822. return null;
  823. }
  824. }
  825. public function get_label()
  826. {
  827. if ($this->label !== null)
  828. {
  829. return $this->label;
  830. }
  831. else
  832. {
  833. return $this->get_term();
  834. }
  835. }
  836. }
  837. /**
  838. * Content-type sniffing
  839. *
  840. * Based on the rules in http://tools.ietf.org/html/draft-abarth-mime-sniff-06
  841. * @package SimplePie
  842. */
  843. class SimplePie_Content_Type_Sniffer
  844. {
  845. /**
  846. * File object
  847. *
  848. * @var SimplePie_File
  849. */
  850. var $file;
  851. /**
  852. * Create an instance of the class with the input file
  853. *
  854. * @param SimplePie_Content_Type_Sniffer $file Input file
  855. */
  856. public function __construct($file)
  857. {
  858. $this->file = $file;
  859. }
  860. /**
  861. * Get the Content-Type of the specified file
  862. *
  863. * @return string Actual Content-Type
  864. */
  865. public function get_type()
  866. {
  867. if (isset($this->file->headers['content-type']))
  868. {
  869. if (!isset($this->file->headers['content-encoding'])
  870. && ($this->file->headers['content-type'] === 'text/plain'
  871. || $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1'
  872. || $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1'
  873. || $this->file->headers['content-type'] === 'text/plain; charset=UTF-8'))
  874. {
  875. return $this->text_or_binary();
  876. }
  877. if (($pos = strpos($this->file->headers['content-type'], ';')) !== false)
  878. {
  879. $official = substr($this->file->headers['content-type'], 0, $pos);
  880. }
  881. else
  882. {
  883. $official = $this->file->headers['content-type'];
  884. }
  885. $official = trim(strtolower($official));
  886. if ($official === 'unknown/unknown'
  887. || $official === 'application/unknown')
  888. {
  889. return $this->unknown();
  890. }
  891. elseif (substr($official, -4) === '+xml'
  892. || $official === 'text/xml'
  893. || $official === 'application/xml')
  894. {
  895. return $official;
  896. }
  897. elseif (substr($official, 0, 6) === 'image/')
  898. {
  899. if ($return = $this->image())
  900. {
  901. return $return;
  902. }
  903. else
  904. {
  905. return $official;
  906. }
  907. }
  908. elseif ($official === 'text/html')
  909. {
  910. return $this->feed_or_html();
  911. }
  912. else
  913. {
  914. return $official;
  915. }
  916. }
  917. else
  918. {
  919. return $this->unknown();
  920. }
  921. }
  922. /**
  923. * Sniff text or binary
  924. *
  925. * @return string Actual Content-Type
  926. */
  927. public function text_or_binary()
  928. {
  929. if (substr($this->file->body, 0, 2) === "\xFE\xFF"
  930. || substr($this->file->body, 0, 2) === "\xFF\xFE"
  931. || substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF"
  932. || substr($this->file->body, 0, 3) === "\xEF\xBB\xBF")
  933. {
  934. return 'text/plain';
  935. }
  936. elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body))
  937. {
  938. return 'application/octect-stream';
  939. }
  940. else
  941. {
  942. return 'text/plain';
  943. }
  944. }
  945. /**
  946. * Sniff unknown
  947. *
  948. * @return string Actual Content-Type
  949. */
  950. public function unknown()
  951. {
  952. $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20");
  953. if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html'
  954. || strtolower(substr($this->file->body, $ws, 5)) === '<html'
  955. || strtolower(substr($this->file->body, $ws, 7)) === '<script')
  956. {
  957. return 'text/html';
  958. }
  959. elseif (substr($this->file->body, 0, 5) === '%PDF-')
  960. {
  961. return 'application/pdf';
  962. }
  963. elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-')
  964. {
  965. return 'application/postscript';
  966. }
  967. elseif (substr($this->file->body, 0, 6) === 'GIF87a'
  968. || substr($this->file->body, 0, 6) === 'GIF89a')
  969. {
  970. return 'image/gif';
  971. }
  972. elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
  973. {
  974. return 'image/png';
  975. }
  976. elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
  977. {
  978. return 'image/jpeg';
  979. }
  980. elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
  981. {
  982. return 'image/bmp';
  983. }
  984. elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
  985. {
  986. return 'image/vnd.microsoft.icon';
  987. }
  988. else
  989. {
  990. return $this->text_or_binary();
  991. }
  992. }
  993. /**
  994. * Sniff images
  995. *
  996. * @return string Actual Content-Type
  997. */
  998. public function image()
  999. {
  1000. if (substr($this->file->body, 0, 6) === 'GIF87a'
  1001. || substr($this->file->body, 0, 6) === 'GIF89a')
  1002. {
  1003. return 'image/gif';
  1004. }
  1005. elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
  1006. {
  1007. return 'image/png';
  1008. }
  1009. elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
  1010. {
  1011. return 'image/jpeg';
  1012. }
  1013. elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
  1014. {
  1015. return 'image/bmp';
  1016. }
  1017. elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
  1018. {
  1019. return 'image/vnd.microsoft.icon';
  1020. }
  1021. else
  1022. {
  1023. return false;
  1024. }
  1025. }
  1026. /**
  1027. * Sniff HTML
  1028. *
  1029. * @return string Actual Content-Type
  1030. */
  1031. public function feed_or_html()
  1032. {
  1033. $len = strlen($this->file->body);
  1034. $pos = strspn($this->file->body, "\x09\x0A\x0D\x20");
  1035. while ($pos < $len)
  1036. {
  1037. switch ($this->file->body[$pos])
  1038. {
  1039. case "\x09":
  1040. case "\x0A":
  1041. case "\x0D":
  1042. case "\x20":
  1043. $pos += strspn($this->file->body, "\x09\x0A\x0D\x20", $pos);
  1044. continue 2;
  1045. case '<':
  1046. $pos++;
  1047. break;
  1048. default:
  1049. return 'text/html';
  1050. }
  1051. if (substr($this->file->body, $pos, 3) === '!--')
  1052. {
  1053. $pos += 3;
  1054. if ($pos < $len && ($pos = strpos($this->file->body, '-->', $pos)) !== false)
  1055. {
  1056. $pos += 3;
  1057. }
  1058. else
  1059. {
  1060. return 'text/html';
  1061. }
  1062. }
  1063. elseif (substr($this->file->body, $pos, 1) === '!')
  1064. {
  1065. if ($pos < $len && ($pos = strpos($this->file->body, '>', $pos)) !== false)
  1066. {
  1067. $pos++;
  1068. }
  1069. else
  1070. {
  1071. return 'text/html';
  1072. }
  1073. }
  1074. elseif (substr($this->file->body, $pos, 1) === '?')
  1075. {
  1076. if ($pos < $len && ($pos = strpos($this->file->body, '?>', $pos)) !== false)
  1077. {
  1078. $pos += 2;
  1079. }
  1080. else
  1081. {
  1082. return 'text/html';
  1083. }
  1084. }
  1085. elseif (substr($this->file->body, $pos, 3) === 'rss'
  1086. || substr($this->file->body, $pos, 7) === 'rdf:RDF')
  1087. {
  1088. return 'application/rss+xml';
  1089. }
  1090. elseif (substr($this->file->body, $pos, 4) === 'feed')
  1091. {
  1092. return 'application/atom+xml';
  1093. }
  1094. else
  1095. {
  1096. return 'text/html';
  1097. }
  1098. }
  1099. return 'text/html';
  1100. }
  1101. }
  1102. class SimplePie_Copyright
  1103. {
  1104. var $url;
  1105. var $label;
  1106. // Constructor, used to input the data
  1107. public function __construct($url = null, $label = null)
  1108. {
  1109. $this->url = $url;
  1110. $this->label = $label;
  1111. }
  1112. public function __toString()
  1113. {
  1114. // There is no $this->data here
  1115. return md5(serialize($this));
  1116. }
  1117. public function get_url()
  1118. {
  1119. if ($this->url !== null)
  1120. {
  1121. return $this->url;
  1122. }
  1123. else
  1124. {
  1125. return null;
  1126. }
  1127. }
  1128. public function get_attribution()
  1129. {
  1130. if ($this->label !== null)
  1131. {
  1132. return $this->label;
  1133. }
  1134. else
  1135. {
  1136. return null;
  1137. }
  1138. }
  1139. }
  1140. /**
  1141. * SimplePie Name
  1142. */
  1143. define('SIMPLEPIE_NAME', 'SimplePie');
  1144. /**
  1145. * SimplePie Version
  1146. */
  1147. define('SIMPLEPIE_VERSION', '1.3-dev');
  1148. /**
  1149. * SimplePie Build
  1150. * @todo Hardcode for release (there's no need to have to call SimplePie_Misc::get_build() only every load of simplepie.inc)
  1151. */
  1152. define('SIMPLEPIE_BUILD', gmdate('YmdHis', SimplePie_Misc::get_build()));
  1153. /**
  1154. * SimplePie Website URL
  1155. */
  1156. define('SIMPLEPIE_URL', 'http://simplepie.org');
  1157. /**
  1158. * SimplePie Useragent
  1159. * @see SimplePie::set_useragent()
  1160. */
  1161. define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD);
  1162. /**
  1163. * SimplePie Linkback
  1164. */
  1165. define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>');
  1166. /**
  1167. * No Autodiscovery
  1168. * @see SimplePie::set_autodiscovery_level()
  1169. */
  1170. define('SIMPLEPIE_LOCATOR_NONE', 0);
  1171. /**
  1172. * Feed Link Element Autodiscovery
  1173. * @see SimplePie::set_autodiscovery_level()
  1174. */
  1175. define('SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1);
  1176. /**
  1177. * Local Feed Extension Autodiscovery
  1178. * @see SimplePie::set_autodiscovery_level()
  1179. */
  1180. define('SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2);
  1181. /**
  1182. * Local Feed Body Autodiscovery
  1183. * @see SimplePie::set_autodiscovery_level()
  1184. */
  1185. define('SIMPLEPIE_LOCATOR_LOCAL_BODY', 4);
  1186. /**
  1187. * Remote Feed Extension Autodiscovery
  1188. * @see SimplePie::set_autodiscovery_level()
  1189. */
  1190. define('SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8);
  1191. /**
  1192. * Remote Feed Body Autodiscovery
  1193. * @see SimplePie::set_autodiscovery_level()
  1194. */
  1195. define('SIMPLEPIE_LOCATOR_REMOTE_BODY', 16);
  1196. /**
  1197. * All Feed Autodiscovery
  1198. * @see SimplePie::set_autodiscovery_level()
  1199. */
  1200. define('SIMPLEPIE_LOCATOR_ALL', 31);
  1201. /**
  1202. * No known feed type
  1203. */
  1204. define('SIMPLEPIE_TYPE_NONE', 0);
  1205. /**
  1206. * RSS 0.90
  1207. */
  1208. define('SIMPLEPIE_TYPE_RSS_090', 1);
  1209. /**
  1210. * RSS 0.91 (Netscape)
  1211. */
  1212. define('SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2);
  1213. /**
  1214. * RSS 0.91 (Userland)
  1215. */
  1216. define('SIMPLEPIE_TYPE_RSS_091_USERLAND', 4);
  1217. /**
  1218. * RSS 0.91 (both Netscape and Userland)
  1219. */
  1220. define('SIMPLEPIE_TYPE_RSS_091', 6);
  1221. /**
  1222. * RSS 0.92
  1223. */
  1224. define('SIMPLEPIE_TYPE_RSS_092', 8);
  1225. /**
  1226. * RSS 0.93
  1227. */
  1228. define('SIMPLEPIE_TYPE_RSS_093', 16);
  1229. /**
  1230. * RSS 0.94
  1231. */
  1232. define('SIMPLEPIE_TYPE_RSS_094', 32);
  1233. /**
  1234. * RSS 1.0
  1235. */
  1236. define('SIMPLEPIE_TYPE_RSS_10', 64);
  1237. /**
  1238. * RSS 2.0
  1239. */
  1240. define('SIMPLEPIE_TYPE_RSS_20', 128);
  1241. /**
  1242. * RDF-based RSS
  1243. */
  1244. define('SIMPLEPIE_TYPE_RSS_RDF', 65);
  1245. /**
  1246. * Non-RDF-based RSS (truly intended as syndication format)
  1247. */
  1248. define('SIMPLEPIE_TYPE_RSS_SYNDICATION', 190);
  1249. /**
  1250. * All RSS
  1251. */
  1252. define('SIMPLEPIE_TYPE_RSS_ALL', 255);
  1253. /**
  1254. * Atom 0.3
  1255. */
  1256. define('SIMPLEPIE_TYPE_ATOM_03', 256);
  1257. /**
  1258. * Atom 1.0
  1259. */
  1260. define('SIMPLEPIE_TYPE_ATOM_10', 512);
  1261. /**
  1262. * All Atom
  1263. */
  1264. define('SIMPLEPIE_TYPE_ATOM_ALL', 768);
  1265. /**
  1266. * All feed types
  1267. */
  1268. define('SIMPLEPIE_TYPE_ALL', 1023);
  1269. /**
  1270. * No construct
  1271. */
  1272. define('SIMPLEPIE_CONSTRUCT_NONE', 0);
  1273. /**
  1274. * Text construct
  1275. */
  1276. define('SIMPLEPIE_CONSTRUCT_TEXT', 1);
  1277. /**
  1278. * HTML construct
  1279. */
  1280. define('SIMPLEPIE_CONSTRUCT_HTML', 2);
  1281. /**
  1282. * XHTML construct
  1283. */
  1284. define('SIMPLEPIE_CONSTRUCT_XHTML', 4);
  1285. /**
  1286. * base64-encoded construct
  1287. */
  1288. define('SIMPLEPIE_CONSTRUCT_BASE64', 8);
  1289. /**
  1290. * IRI construct
  1291. */
  1292. define('SIMPLEPIE_CONSTRUCT_IRI', 16);
  1293. /**
  1294. * A construct that might be HTML
  1295. */
  1296. define('SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32);
  1297. /**
  1298. * All constructs
  1299. */
  1300. define('SIMPLEPIE_CONSTRUCT_ALL', 63);
  1301. /**
  1302. * Don't change case
  1303. */
  1304. define('SIMPLEPIE_SAME_CASE', 1);
  1305. /**
  1306. * Change to lowercase
  1307. */
  1308. define('SIMPLEPIE_LOWERCASE', 2);
  1309. /**
  1310. * Change to uppercase
  1311. */
  1312. define('SIMPLEPIE_UPPERCASE', 4);
  1313. /**
  1314. * PCRE for HTML attributes
  1315. */
  1316. 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]*');
  1317. /**
  1318. * PCRE for XML attributes
  1319. */
  1320. define('SIMPLEPIE_PCRE_XML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*');
  1321. /**
  1322. * XML Namespace
  1323. */
  1324. define('SIMPLEPIE_NAMESPACE_XML', 'http://www.w3.org/XML/1998/namespace');
  1325. /**
  1326. * Atom 1.0 Namespace
  1327. */
  1328. define('SIMPLEPIE_NAMESPACE_ATOM_10', 'http://www.w3.org/2005/Atom');
  1329. /**
  1330. * Atom 0.3 Namespace
  1331. */
  1332. define('SIMPLEPIE_NAMESPACE_ATOM_03', 'http://purl.org/atom/ns#');
  1333. /**
  1334. * RDF Namespace
  1335. */
  1336. define('SIMPLEPIE_NAMESPACE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
  1337. /**
  1338. * RSS 0.90 Namespace
  1339. */
  1340. define('SIMPLEPIE_NAMESPACE_RSS_090', 'http://my.netscape.com/rdf/simple/0.9/');
  1341. /**
  1342. * RSS 1.0 Namespace
  1343. */
  1344. define('SIMPLEPIE_NAMESPACE_RSS_10', 'http://purl.org/rss/1.0/');
  1345. /**
  1346. * RSS 1.0 Content Module Namespace
  1347. */
  1348. define('SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT', 'http://purl.org/rss/1.0/modules/content/');
  1349. /**
  1350. * RSS 2.0 Namespace
  1351. * (Stupid, I know, but I'm certain it will confuse people less with support.)
  1352. */
  1353. define('SIMPLEPIE_NAMESPACE_RSS_20', '');
  1354. /**
  1355. * DC 1.0 Namespace
  1356. */
  1357. define('SIMPLEPIE_NAMESPACE_DC_10', 'http://purl.org/dc/elements/1.0/');
  1358. /**
  1359. * DC 1.1 Namespace
  1360. */
  1361. define('SIMPLEPIE_NAMESPACE_DC_11', 'http://purl.org/dc/elements/1.1/');
  1362. /**
  1363. * W3C Basic Geo (WGS84 lat/long) Vocabulary Namespace
  1364. */
  1365. define('SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO', 'http://www.w3.org/2003/01/geo/wgs84_pos#');
  1366. /**
  1367. * GeoRSS Namespace
  1368. */
  1369. define('SIMPLEPIE_NAMESPACE_GEORSS', 'http://www.georss.org/georss');
  1370. /**
  1371. * Media RSS Namespace
  1372. */
  1373. define('SIMPLEPIE_NAMESPACE_MEDIARSS', 'http://search.yahoo.com/mrss/');
  1374. /**
  1375. * Wrong Media RSS Namespace. Caused by a long-standing typo in the spec.
  1376. */
  1377. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG', 'http://search.yahoo.com/mrss');
  1378. /**
  1379. * Wrong Media RSS Namespace #2. New namespace introduced in Media RSS 1.5.
  1380. */
  1381. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2', 'http://video.search.yahoo.com/mrss');
  1382. /**
  1383. * Wrong Media RSS Namespace #3. A possible typo of the Media RSS 1.5 namespace.
  1384. */
  1385. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3', 'http://video.search.yahoo.com/mrss/');
  1386. /**
  1387. * Wrong Media RSS Namespace #4. New spec location after the RSS Advisory Board takes it over, but not a valid namespace.
  1388. */
  1389. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4', 'http://www.rssboard.org/media-rss');
  1390. /**
  1391. * Wrong Media RSS Namespace #5. A possible typo of the RSS Advisory Board URL.
  1392. */
  1393. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5', 'http://www.rssboard.org/media-rss/');
  1394. /**
  1395. * iTunes RSS Namespace
  1396. */
  1397. define('SIMPLEPIE_NAMESPACE_ITUNES', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
  1398. /**
  1399. * XHTML Namespace
  1400. */
  1401. define('SIMPLEPIE_NAMESPACE_XHTML', 'http://www.w3.org/1999/xhtml');
  1402. /**
  1403. * IANA Link Relations Registry
  1404. */
  1405. define('SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY', 'http://www.iana.org/assignments/relation/');
  1406. /**
  1407. * Whether we're running on PHP5
  1408. */
  1409. define('SIMPLEPIE_PHP5', version_compare(PHP_VERSION, '5.0.0', '>='));
  1410. /**
  1411. * No file source
  1412. */
  1413. define('SIMPLEPIE_FILE_SOURCE_NONE', 0);
  1414. /**
  1415. * Remote file source
  1416. */
  1417. define('SIMPLEPIE_FILE_SOURCE_REMOTE', 1);
  1418. /**
  1419. * Local file source
  1420. */
  1421. define('SIMPLEPIE_FILE_SOURCE_LOCAL', 2);
  1422. /**
  1423. * fsockopen() file source
  1424. */
  1425. define('SIMPLEPIE_FILE_SOURCE_FSOCKOPEN', 4);
  1426. /**
  1427. * cURL file source
  1428. */
  1429. define('SIMPLEPIE_FILE_SOURCE_CURL', 8);
  1430. /**
  1431. * file_get_contents() file source
  1432. */
  1433. define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16);
  1434. /**
  1435. * SimplePie
  1436. *
  1437. * @package SimplePie
  1438. */
  1439. class SimplePie_Core
  1440. {
  1441. /**
  1442. * @var array Raw data
  1443. * @access private
  1444. */
  1445. public $data = array();
  1446. /**
  1447. * @var mixed Error string
  1448. * @access private
  1449. */
  1450. public $error;
  1451. /**
  1452. * @var object Instance of SimplePie_Sanitize (or other class)
  1453. * @see SimplePie::set_sanitize_class()
  1454. * @access private
  1455. */
  1456. public $sanitize;
  1457. /**
  1458. * @var string SimplePie Useragent
  1459. * @see SimplePie::set_useragent()
  1460. * @access private
  1461. */
  1462. public $useragent = SIMPLEPIE_USERAGENT;
  1463. /**
  1464. * @var string Feed URL
  1465. * @see SimplePie::set_feed_url()
  1466. * @access private
  1467. */
  1468. public $feed_url;
  1469. /**
  1470. * @var object Instance of SimplePie_File to use as a feed
  1471. * @see SimplePie::set_file()
  1472. * @access private
  1473. */
  1474. public $file;
  1475. /**
  1476. * @var string Raw feed data
  1477. * @see SimplePie::set_raw_data()
  1478. * @access private
  1479. */
  1480. public $raw_data;
  1481. /**
  1482. * @var int Timeout for fetching remote files
  1483. * @see SimplePie::set_timeout()
  1484. * @access private
  1485. */
  1486. public $timeout = 10;
  1487. /**
  1488. * @var bool Forces fsockopen() to be used for remote files instead
  1489. * of cURL, even if a new enough version is installed
  1490. * @see SimplePie::force_fsockopen()
  1491. * @access private
  1492. */
  1493. public $force_fsockopen = false;
  1494. /**
  1495. * @var bool Force the given data/URL to be treated as a feed no matter what
  1496. * it appears like
  1497. * @see SimplePie::force_feed()
  1498. * @access private
  1499. */
  1500. public $force_feed = false;
  1501. /**
  1502. * @var bool Enable/Disable XML dump
  1503. * @see SimplePie::enable_xml_dump()
  1504. * @access private
  1505. */
  1506. public $xml_dump = false;
  1507. /**
  1508. * @var bool Enable/Disable Caching
  1509. * @see SimplePie::enable_cache()
  1510. * @access private
  1511. */
  1512. public $cache = true;
  1513. /**
  1514. * @var int Cache duration (in seconds)
  1515. * @see SimplePie::set_cache_duration()
  1516. * @access private
  1517. */
  1518. public $cache_duration = 3600;
  1519. /**
  1520. * @var int Auto-discovery cache duration (in seconds)
  1521. * @see SimplePie::set_autodiscovery_cache_duration()
  1522. * @access private
  1523. */
  1524. public $autodiscovery_cache_duration = 604800; // 7 Days.
  1525. /**
  1526. * @var string Cache location (relative to executing script)
  1527. * @see SimplePie::set_cache_location()
  1528. * @access private
  1529. */
  1530. public $cache_location = './cache';
  1531. /**
  1532. * @var string Function that creates the cache filename
  1533. * @see SimplePie::set_cache_name_function()
  1534. * @access private
  1535. */
  1536. public $cache_name_function = 'md5';
  1537. /**
  1538. * @var bool Reorder feed by date descending
  1539. * @see SimplePie::enable_order_by_date()
  1540. * @access private
  1541. */
  1542. public $order_by_date = true;
  1543. /**
  1544. * @var mixed Force input encoding to be set to the follow value
  1545. * (false, or anything type-cast to false, disables this feature)
  1546. * @see SimplePie::set_input_encoding()
  1547. * @access private
  1548. */
  1549. public $input_encoding = false;
  1550. /**
  1551. * @var int Feed Autodiscovery Level
  1552. * @see SimplePie::set_autodiscovery_level()
  1553. * @access private
  1554. */
  1555. public $autodiscovery = SIMPLEPIE_LOCATOR_ALL;
  1556. /**
  1557. * @var string Class used for caching feeds
  1558. * @see SimplePie::set_cache_class()
  1559. * @access private
  1560. */
  1561. public $cache_class = 'SimplePie_Cache';
  1562. /**
  1563. * @var string Class used for locating feeds
  1564. * @see SimplePie::set_locator_class()
  1565. * @access private
  1566. */
  1567. public $locator_class = 'SimplePie_Locator';
  1568. /**
  1569. * @var string Class used for parsing feeds
  1570. * @see SimplePie::set_parser_class()
  1571. * @access private
  1572. */
  1573. public $parser_class = 'SimplePie_Parser';
  1574. /**
  1575. * @var string Class used for fetching feeds
  1576. * @see SimplePie::set_file_class()
  1577. * @access private
  1578. */
  1579. public $file_class = 'SimplePie_File';
  1580. /**
  1581. * @var string Class used for items
  1582. * @see SimplePie::set_item_class()
  1583. * @access private
  1584. */
  1585. public $item_class = 'SimplePie_Item';
  1586. /**
  1587. * @var string Class used for authors
  1588. * @see SimplePie::set_author_class()
  1589. * @access private
  1590. */
  1591. public $author_class = 'SimplePie_Author';
  1592. /**
  1593. * @var string Class used for categories
  1594. * @see SimplePie::set_category_class()
  1595. * @access private
  1596. */
  1597. public $category_class = 'SimplePie_Category';
  1598. /**
  1599. * @var string Class used for enclosures
  1600. * @see SimplePie::set_enclosures_class()
  1601. * @access private
  1602. */
  1603. public $enclosure_class = 'SimplePie_Enclosure';
  1604. /**
  1605. * @var string Class used for Media RSS <media:text> captions
  1606. * @see SimplePie::set_caption_class()
  1607. * @access private
  1608. */
  1609. public $caption_class = 'SimplePie_Caption';
  1610. /**
  1611. * @var string Class used for Media RSS <media:copyright>
  1612. * @see SimplePie::set_copyright_class()
  1613. * @access private
  1614. */
  1615. public $copyright_class = 'SimplePie_Copyright';
  1616. /**
  1617. * @var string Class used for Media RSS <media:credit>
  1618. * @see SimplePie::set_credit_class()
  1619. * @access private
  1620. */
  1621. public $credit_class = 'SimplePie_Credit';
  1622. /**
  1623. * @var string Class used for Media RSS <media:rating>
  1624. * @see SimplePie::set_rating_class()
  1625. * @access private
  1626. */
  1627. public $rating_class = 'SimplePie_Rating';
  1628. /**
  1629. * @var string Class used for Media RSS <media:restriction>
  1630. * @see SimplePie::set_restriction_class()
  1631. * @access private
  1632. */
  1633. public $restriction_class = 'SimplePie_Restriction';
  1634. /**
  1635. * @var string Class used for content-type sniffing
  1636. * @see SimplePie::set_content_type_sniffer_class()
  1637. * @access private
  1638. */
  1639. public $content_type_sniffer_class = 'SimplePie_Content_Type_Sniffer';
  1640. /**
  1641. * @var string Class used for item sources.
  1642. * @see SimplePie::set_source_class()
  1643. * @access private
  1644. */
  1645. public $source_class = 'SimplePie_Source';
  1646. /**
  1647. * @var int Maximum number of feeds to check with autodiscovery
  1648. * @see SimplePie::set_max_checked_feeds()
  1649. * @access private
  1650. */
  1651. public $max_checked_feeds = 10;
  1652. /**
  1653. * @var array All the feeds found during the autodiscovery process
  1654. * @see SimplePie::get_all_discovered_feeds()
  1655. * @access private
  1656. */
  1657. public $all_discovered_feeds = array();
  1658. /**
  1659. * @var string Web-accessible path to the handler_image.php file.
  1660. * @see SimplePie::set_image_handler()
  1661. * @access private
  1662. */
  1663. public $image_handler = '';
  1664. /**
  1665. * @var array Stores the URLs when multiple feeds are being initialized.
  1666. * @see SimplePie::set_feed_url()
  1667. * @access private
  1668. */
  1669. public $multifeed_url = array();
  1670. /**
  1671. * @var array Stores SimplePie objects when multiple feeds initialized.
  1672. * @access private
  1673. */
  1674. public $multifeed_objects = array();
  1675. /**
  1676. * @var array Stores the get_object_vars() array for use with multifeeds.
  1677. * @see SimplePie::set_feed_url()
  1678. * @access private
  1679. */
  1680. public $config_settings = null;
  1681. /**
  1682. * @var integer Stores the number of items to return per-feed with multifeeds.
  1683. * @see SimplePie::set_item_limit()
  1684. * @access private
  1685. */
  1686. public $item_limit = 0;
  1687. /**
  1688. * @var array Stores the default attributes to be stripped by strip_attributes().
  1689. * @see SimplePie::strip_attributes()
  1690. * @access private
  1691. */
  1692. public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
  1693. /**
  1694. * @var array Stores the default tags to be stripped by strip_htmltags().
  1695. * @see SimplePie::strip_htmltags()
  1696. * @access private
  1697. */
  1698. public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  1699. /**
  1700. * The SimplePie class contains feed level data and options
  1701. *
  1702. * There are two ways that you can create a new SimplePie object. The first
  1703. * is by passing a feed URL as a parameter to the SimplePie constructor
  1704. * (as well as optionally setting the cache location and cache expiry). This
  1705. * will initialise the whole feed with all of the default settings, and you
  1706. * can begin accessing methods and properties immediately.
  1707. *
  1708. * The second way is to create the SimplePie object with no parameters
  1709. * at all. This will enable you to set configuration options. After setting
  1710. * them, you must initialise the feed using $feed->init(). At that point the
  1711. * object's methods and properties will be available to you. This format is
  1712. * what is used throughout this documentation.
  1713. *
  1714. * @access public
  1715. * @since 1.0 Preview Release
  1716. */
  1717. public function __construct()
  1718. {
  1719. if (version_compare(PHP_VERSION, '5.0', '<'))
  1720. {
  1721. trigger_error('PHP 4.x is no longer supported. Please upgrade to PHP 5.2 or newer.');
  1722. die();
  1723. }
  1724. // Other objects, instances created here so we can set options on them
  1725. $this->sanitize = new SimplePie_Sanitize();
  1726. if (func_num_args() > 0)
  1727. {
  1728. trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_location() directly.');
  1729. }
  1730. }
  1731. /**
  1732. * Used for converting object to a string
  1733. */
  1734. public function __toString()
  1735. {
  1736. return md5(serialize($this->data));
  1737. }
  1738. /**
  1739. * Remove items that link back to this before destroying this object
  1740. */
  1741. public function __destruct()
  1742. {
  1743. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
  1744. {
  1745. if (!empty($this->data['items']))
  1746. {
  1747. foreach ($this->data['items'] as $item)
  1748. {
  1749. $item->__destruct();
  1750. }
  1751. unset($item, $this->data['items']);
  1752. }
  1753. if (!empty($this->data['ordered_items']))
  1754. {
  1755. foreach ($this->data['ordered_items'] as $item)
  1756. {
  1757. $item->__destruct();
  1758. }
  1759. unset($item, $this->data['ordered_items']);
  1760. }
  1761. }
  1762. }
  1763. /**
  1764. * Force the given data/URL to be treated as a feed no matter what it
  1765. * appears like
  1766. *
  1767. * @access public
  1768. * @since 1.1
  1769. * @param bool $enable Force the given data/URL to be treated as a feed
  1770. */
  1771. public function force_feed($enable = false)
  1772. {
  1773. $this->force_feed = (bool) $enable;
  1774. }
  1775. /**
  1776. * This is the URL of the feed you want to parse.
  1777. *
  1778. * This allows you to enter the URL of the feed you want to parse, or the
  1779. * website you want to try to use auto-discovery on. This takes priority
  1780. * over any set raw data.
  1781. *
  1782. * You can set multiple feeds to mash together by passing an array instead
  1783. * of a string for the $url. Remember that with each additional feed comes
  1784. * additional processing and resources.
  1785. *
  1786. * @access public
  1787. * @since 1.0 Preview Release
  1788. * @param mixed $url This is the URL (or array of URLs) that you want to parse.
  1789. * @see SimplePie::set_raw_data()
  1790. */
  1791. public function set_feed_url($url)
  1792. {
  1793. if (is_array($url))
  1794. {
  1795. $this->multifeed_url = array();
  1796. foreach ($url as $value)
  1797. {
  1798. $this->multifeed_url[] = SimplePie_Misc::fix_protocol($value, 1);
  1799. }
  1800. }
  1801. else
  1802. {
  1803. $this->feed_url = SimplePie_Misc::fix_protocol($url, 1);
  1804. }
  1805. }
  1806. /**
  1807. * Provides an instance of SimplePie_File to use as a feed
  1808. *
  1809. * @access public
  1810. * @param object &$file Instance of SimplePie_File (or subclass)
  1811. * @return bool True on success, false on failure
  1812. */
  1813. public function set_file(&$file)
  1814. {
  1815. if (is_a($file, 'SimplePie_File'))
  1816. {
  1817. $this->feed_url = $file->url;
  1818. $this->file =& $file;
  1819. return true;
  1820. }
  1821. return false;
  1822. }
  1823. /**
  1824. * Allows you to use a string of RSS/Atom data instead of a remote feed.
  1825. *
  1826. * If you have a feed available as a string in PHP, you can tell SimplePie
  1827. * to parse that data string instead of a remote feed. Any set feed URL
  1828. * takes precedence.
  1829. *
  1830. * @access public
  1831. * @since 1.0 Beta 3
  1832. * @param string $data RSS or Atom data as a string.
  1833. * @see SimplePie::set_feed_url()
  1834. */
  1835. public function set_raw_data($data)
  1836. {
  1837. $this->raw_data = $data;
  1838. }
  1839. /**
  1840. * Allows you to override the default timeout for fetching remote feeds.
  1841. *
  1842. * This allows you to change the maximum time the feed's server to respond
  1843. * and send the feed back.
  1844. *
  1845. * @access public
  1846. * @since 1.0 Beta 3
  1847. * @param int $timeout The maximum number of seconds to spend waiting to retrieve a feed.
  1848. */
  1849. public function set_timeout($timeout = 10)
  1850. {
  1851. $this->timeout = (int) $timeout;
  1852. }
  1853. /**
  1854. * Forces SimplePie to use fsockopen() instead of the preferred cURL
  1855. * functions.
  1856. *
  1857. * @access public
  1858. * @since 1.0 Beta 3
  1859. * @param bool $enable Force fsockopen() to be used
  1860. */
  1861. public function force_fsockopen($enable = false)
  1862. {
  1863. $this->force_fsockopen = (bool) $enable;
  1864. }
  1865. /**
  1866. * Enables/disables caching in SimplePie.
  1867. *
  1868. * This option allows you to disable caching all-together in SimplePie.
  1869. * However, disabling the cache can lead to longer load times.
  1870. *
  1871. * @access public
  1872. * @since 1.0 Preview Release
  1873. * @param bool $enable Enable caching
  1874. */
  1875. public function enable_cache($enable = true)
  1876. {
  1877. $this->cache = (bool) $enable;
  1878. }
  1879. /**
  1880. * Set the length of time (in seconds) that the contents of a feed
  1881. * will be cached.
  1882. *
  1883. * @access public
  1884. * @param int $seconds The feed content cache duration.
  1885. */
  1886. public function set_cache_duration($seconds = 3600)
  1887. {
  1888. $this->cache_duration = (int) $seconds;
  1889. }
  1890. /**
  1891. * Set the length of time (in seconds) that the autodiscovered feed
  1892. * URL will be cached.
  1893. *
  1894. * @access public
  1895. * @param int $seconds The autodiscovered feed URL cache duration.
  1896. */
  1897. public function set_autodiscovery_cache_duration($seconds = 604800)
  1898. {
  1899. $this->autodiscovery_cache_duration = (int) $seconds;
  1900. }
  1901. /**
  1902. * Set the file system location where the cached files should be stored.
  1903. *
  1904. * @access public
  1905. * @param string $location The file system location.
  1906. */
  1907. public function set_cache_location($location = './cache')
  1908. {
  1909. $this->cache_location = (string) $location;
  1910. }
  1911. /**
  1912. * Determines whether feed items should be sorted into reverse chronological order.
  1913. *
  1914. * @access public
  1915. * @param bool $enable Sort as reverse chronological order.
  1916. */
  1917. public function enable_order_by_date($enable = true)
  1918. {
  1919. $this->order_by_date = (bool) $enable;
  1920. }
  1921. /**
  1922. * Allows you to override the character encoding reported by the feed.
  1923. *
  1924. * @access public
  1925. * @param string $encoding Character encoding.
  1926. */
  1927. public function set_input_encoding($encoding = false)
  1928. {
  1929. if ($encoding)
  1930. {
  1931. $this->input_encoding = (string) $encoding;
  1932. }
  1933. else
  1934. {
  1935. $this->input_encoding = false;
  1936. }
  1937. }
  1938. /**
  1939. * Set how much feed autodiscovery to do
  1940. *
  1941. * @access public
  1942. * @see SIMPLEPIE_LOCATOR_NONE
  1943. * @see SIMPLEPIE_LOCATOR_AUTODISCOVERY
  1944. * @see SIMPLEPIE_LOCATOR_LOCAL_EXTENSION
  1945. * @see SIMPLEPIE_LOCATOR_LOCAL_BODY
  1946. * @see SIMPLEPIE_LOCATOR_REMOTE_EXTENSION
  1947. * @see SIMPLEPIE_LOCATOR_REMOTE_BODY
  1948. * @see SIMPLEPIE_LOCATOR_ALL
  1949. * @param int $level Feed Autodiscovery Level (level can be a
  1950. * combination of the above constants, see bitwise OR operator)
  1951. */
  1952. public function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL)
  1953. {
  1954. $this->autodiscovery = (int) $level;
  1955. }
  1956. /**
  1957. * Allows you to change which class SimplePie uses for caching.
  1958. * Useful when you are overloading or extending SimplePie's default classes.
  1959. *

Large files files are truncated, but you can click here to view the full file