PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Feed/Reader.php

https://bitbucket.org/bigstylee/zend-framework
PHP | 756 lines | 503 code | 59 blank | 194 comment | 66 complexity | 85346a572c4bf8bff9d3737d44a47525 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Feed_Reader
  17. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Reader.php 25033 2012-08-17 19:50:08Z matthew $
  20. */
  21. /**
  22. * @see Zend_Feed
  23. */
  24. require_once 'Zend/Feed.php';
  25. /**
  26. * @see Zend_Feed_Reader_Feed_Rss
  27. */
  28. require_once 'Zend/Feed/Reader/Feed/Rss.php';
  29. /**
  30. * @see Zend_Feed_Reader_Feed_Atom
  31. */
  32. require_once 'Zend/Feed/Reader/Feed/Atom.php';
  33. /**
  34. * @see Zend_Feed_Reader_FeedSet
  35. */
  36. require_once 'Zend/Feed/Reader/FeedSet.php';
  37. /**
  38. * @category Zend
  39. * @package Zend_Feed_Reader
  40. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  41. * @license http://framework.zend.com/license/new-bsd New BSD License
  42. */
  43. class Zend_Feed_Reader
  44. {
  45. /**
  46. * Namespace constants
  47. */
  48. const NAMESPACE_ATOM_03 = 'http://purl.org/atom/ns#';
  49. const NAMESPACE_ATOM_10 = 'http://www.w3.org/2005/Atom';
  50. const NAMESPACE_RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
  51. const NAMESPACE_RSS_090 = 'http://my.netscape.com/rdf/simple/0.9/';
  52. const NAMESPACE_RSS_10 = 'http://purl.org/rss/1.0/';
  53. /**
  54. * Feed type constants
  55. */
  56. const TYPE_ANY = 'any';
  57. const TYPE_ATOM_03 = 'atom-03';
  58. const TYPE_ATOM_10 = 'atom-10';
  59. const TYPE_ATOM_10_ENTRY = 'atom-10-entry';
  60. const TYPE_ATOM_ANY = 'atom';
  61. const TYPE_RSS_090 = 'rss-090';
  62. const TYPE_RSS_091 = 'rss-091';
  63. const TYPE_RSS_091_NETSCAPE = 'rss-091n';
  64. const TYPE_RSS_091_USERLAND = 'rss-091u';
  65. const TYPE_RSS_092 = 'rss-092';
  66. const TYPE_RSS_093 = 'rss-093';
  67. const TYPE_RSS_094 = 'rss-094';
  68. const TYPE_RSS_10 = 'rss-10';
  69. const TYPE_RSS_20 = 'rss-20';
  70. const TYPE_RSS_ANY = 'rss';
  71. /**
  72. * Cache instance
  73. *
  74. * @var Zend_Cache_Core
  75. */
  76. protected static $_cache = null;
  77. /**
  78. * HTTP client object to use for retrieving feeds
  79. *
  80. * @var Zend_Http_Client
  81. */
  82. protected static $_httpClient = null;
  83. /**
  84. * Override HTTP PUT and DELETE request methods?
  85. *
  86. * @var boolean
  87. */
  88. protected static $_httpMethodOverride = false;
  89. protected static $_httpConditionalGet = false;
  90. protected static $_pluginLoader = null;
  91. protected static $_prefixPaths = array();
  92. protected static $_extensions = array(
  93. 'feed' => array(
  94. 'DublinCore_Feed',
  95. 'Atom_Feed'
  96. ),
  97. 'entry' => array(
  98. 'Content_Entry',
  99. 'DublinCore_Entry',
  100. 'Atom_Entry'
  101. ),
  102. 'core' => array(
  103. 'DublinCore_Feed',
  104. 'Atom_Feed',
  105. 'Content_Entry',
  106. 'DublinCore_Entry',
  107. 'Atom_Entry'
  108. )
  109. );
  110. /**
  111. * Get the Feed cache
  112. *
  113. * @return Zend_Cache_Core
  114. */
  115. public static function getCache()
  116. {
  117. return self::$_cache;
  118. }
  119. /**
  120. * Set the feed cache
  121. *
  122. * @param Zend_Cache_Core $cache
  123. * @return void
  124. */
  125. public static function setCache(Zend_Cache_Core $cache)
  126. {
  127. self::$_cache = $cache;
  128. }
  129. /**
  130. * Set the HTTP client instance
  131. *
  132. * Sets the HTTP client object to use for retrieving the feeds.
  133. *
  134. * @param Zend_Http_Client $httpClient
  135. * @return void
  136. */
  137. public static function setHttpClient(Zend_Http_Client $httpClient)
  138. {
  139. self::$_httpClient = $httpClient;
  140. }
  141. /**
  142. * Gets the HTTP client object. If none is set, a new Zend_Http_Client will be used.
  143. *
  144. * @return Zend_Http_Client_Abstract
  145. */
  146. public static function getHttpClient()
  147. {
  148. if (!self::$_httpClient instanceof Zend_Http_Client) {
  149. /**
  150. * @see Zend_Http_Client
  151. */
  152. require_once 'Zend/Http/Client.php';
  153. self::$_httpClient = new Zend_Http_Client();
  154. }
  155. return self::$_httpClient;
  156. }
  157. /**
  158. * Toggle using POST instead of PUT and DELETE HTTP methods
  159. *
  160. * Some feed implementations do not accept PUT and DELETE HTTP
  161. * methods, or they can't be used because of proxies or other
  162. * measures. This allows turning on using POST where PUT and
  163. * DELETE would normally be used; in addition, an
  164. * X-Method-Override header will be sent with a value of PUT or
  165. * DELETE as appropriate.
  166. *
  167. * @param boolean $override Whether to override PUT and DELETE.
  168. * @return void
  169. */
  170. public static function setHttpMethodOverride($override = true)
  171. {
  172. self::$_httpMethodOverride = $override;
  173. }
  174. /**
  175. * Get the HTTP override state
  176. *
  177. * @return boolean
  178. */
  179. public static function getHttpMethodOverride()
  180. {
  181. return self::$_httpMethodOverride;
  182. }
  183. /**
  184. * Set the flag indicating whether or not to use HTTP conditional GET
  185. *
  186. * @param bool $bool
  187. * @return void
  188. */
  189. public static function useHttpConditionalGet($bool = true)
  190. {
  191. self::$_httpConditionalGet = $bool;
  192. }
  193. /**
  194. * Import a feed by providing a URL
  195. *
  196. * @param string $url The URL to the feed
  197. * @param string $etag OPTIONAL Last received ETag for this resource
  198. * @param string $lastModified OPTIONAL Last-Modified value for this resource
  199. * @return Zend_Feed_Reader_FeedInterface
  200. */
  201. public static function import($uri, $etag = null, $lastModified = null)
  202. {
  203. $cache = self::getCache();
  204. $feed = null;
  205. $responseXml = '';
  206. $client = self::getHttpClient();
  207. $client->resetParameters();
  208. $client->setHeaders('If-None-Match', null);
  209. $client->setHeaders('If-Modified-Since', null);
  210. $client->setUri($uri);
  211. $cacheId = 'Zend_Feed_Reader_' . md5($uri);
  212. if (self::$_httpConditionalGet && $cache) {
  213. $data = $cache->load($cacheId);
  214. if ($data) {
  215. if ($etag === null) {
  216. $etag = $cache->load($cacheId.'_etag');
  217. }
  218. if ($lastModified === null) {
  219. $lastModified = $cache->load($cacheId.'_lastmodified');;
  220. }
  221. if ($etag) {
  222. $client->setHeaders('If-None-Match', $etag);
  223. }
  224. if ($lastModified) {
  225. $client->setHeaders('If-Modified-Since', $lastModified);
  226. }
  227. }
  228. $response = $client->request('GET');
  229. if ($response->getStatus() !== 200 && $response->getStatus() !== 304) {
  230. require_once 'Zend/Feed/Exception.php';
  231. throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus());
  232. }
  233. if ($response->getStatus() == 304) {
  234. $responseXml = $data;
  235. } else {
  236. $responseXml = $response->getBody();
  237. $cache->save($responseXml, $cacheId);
  238. if ($response->getHeader('ETag')) {
  239. $cache->save($response->getHeader('ETag'), $cacheId.'_etag');
  240. }
  241. if ($response->getHeader('Last-Modified')) {
  242. $cache->save($response->getHeader('Last-Modified'), $cacheId.'_lastmodified');
  243. }
  244. }
  245. if (empty($responseXml)) {
  246. require_once 'Zend/Feed/Exception.php';
  247. throw new Zend_Feed_Exception('Feed failed to load, got empty response body');
  248. }
  249. return self::importString($responseXml);
  250. } elseif ($cache) {
  251. $data = $cache->load($cacheId);
  252. if ($data !== false) {
  253. return self::importString($data);
  254. }
  255. $response = $client->request('GET');
  256. if ($response->getStatus() !== 200) {
  257. require_once 'Zend/Feed/Exception.php';
  258. throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus());
  259. }
  260. $responseXml = $response->getBody();
  261. $cache->save($responseXml, $cacheId);
  262. if (empty($responseXml)) {
  263. require_once 'Zend/Feed/Exception.php';
  264. throw new Zend_Feed_Exception('Feed failed to load, got empty response body');
  265. }
  266. return self::importString($responseXml);
  267. } else {
  268. $response = $client->request('GET');
  269. if ($response->getStatus() !== 200) {
  270. require_once 'Zend/Feed/Exception.php';
  271. throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus());
  272. }
  273. $responseXml = $response->getBody();
  274. if (empty($responseXml)) {
  275. require_once 'Zend/Feed/Exception.php';
  276. throw new Zend_Feed_Exception('Feed failed to load, got empty response body');
  277. }
  278. $reader = self::importString($responseXml);
  279. $reader->setOriginalSourceUri($uri);
  280. return $reader;
  281. }
  282. }
  283. /**
  284. * Import a feed by providing a Zend_Feed_Abstract object
  285. *
  286. * @param Zend_Feed_Abstract $feed A fully instantiated Zend_Feed object
  287. * @return Zend_Feed_Reader_FeedInterface
  288. */
  289. public static function importFeed(Zend_Feed_Abstract $feed)
  290. {
  291. $dom = $feed->getDOM()->ownerDocument;
  292. $type = self::detectType($dom);
  293. self::_registerCoreExtensions();
  294. if (substr($type, 0, 3) == 'rss') {
  295. $reader = new Zend_Feed_Reader_Feed_Rss($dom, $type);
  296. } else {
  297. $reader = new Zend_Feed_Reader_Feed_Atom($dom, $type);
  298. }
  299. return $reader;
  300. }
  301. /**
  302. * Import a feed froma string
  303. *
  304. * @param string $string
  305. * @return Zend_Feed_Reader_FeedInterface
  306. */
  307. public static function importString($string)
  308. {
  309. $libxml_errflag = libxml_use_internal_errors(true);
  310. $oldValue = libxml_disable_entity_loader(true);
  311. $dom = new DOMDocument;
  312. $status = $dom->loadXML($string);
  313. foreach ($dom->childNodes as $child) {
  314. if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
  315. require_once 'Zend/Feed/Exception.php';
  316. throw new Zend_Feed_Exception(
  317. 'Invalid XML: Detected use of illegal DOCTYPE'
  318. );
  319. }
  320. }
  321. libxml_disable_entity_loader($oldValue);
  322. libxml_use_internal_errors($libxml_errflag);
  323. if (!$status) {
  324. // Build error message
  325. $error = libxml_get_last_error();
  326. if ($error && $error->message) {
  327. $errormsg = "DOMDocument cannot parse XML: {$error->message}";
  328. } else {
  329. $errormsg = "DOMDocument cannot parse XML: Please check the XML document's validity";
  330. }
  331. require_once 'Zend/Feed/Exception.php';
  332. throw new Zend_Feed_Exception($errormsg);
  333. }
  334. $type = self::detectType($dom);
  335. self::_registerCoreExtensions();
  336. if (substr($type, 0, 3) == 'rss') {
  337. $reader = new Zend_Feed_Reader_Feed_Rss($dom, $type);
  338. } elseif (substr($type, 8, 5) == 'entry') {
  339. $reader = new Zend_Feed_Reader_Entry_Atom($dom->documentElement, 0, Zend_Feed_Reader::TYPE_ATOM_10);
  340. } elseif (substr($type, 0, 4) == 'atom') {
  341. $reader = new Zend_Feed_Reader_Feed_Atom($dom, $type);
  342. } else {
  343. require_once 'Zend/Feed/Exception.php';
  344. throw new Zend_Feed_Exception('The URI used does not point to a '
  345. . 'valid Atom, RSS or RDF feed that Zend_Feed_Reader can parse.');
  346. }
  347. return $reader;
  348. }
  349. /**
  350. * Imports a feed from a file located at $filename.
  351. *
  352. * @param string $filename
  353. * @throws Zend_Feed_Exception
  354. * @return Zend_Feed_Reader_FeedInterface
  355. */
  356. public static function importFile($filename)
  357. {
  358. @ini_set('track_errors', 1);
  359. $feed = @file_get_contents($filename);
  360. @ini_restore('track_errors');
  361. if ($feed === false) {
  362. /**
  363. * @see Zend_Feed_Exception
  364. */
  365. require_once 'Zend/Feed/Exception.php';
  366. throw new Zend_Feed_Exception("File could not be loaded: $php_errormsg");
  367. }
  368. return self::importString($feed);
  369. }
  370. public static function findFeedLinks($uri)
  371. {
  372. // Get the HTTP response from $uri and save the contents
  373. $client = self::getHttpClient();
  374. $client->setUri($uri);
  375. $response = $client->request();
  376. if ($response->getStatus() !== 200) {
  377. /**
  378. * @see Zend_Feed_Exception
  379. */
  380. require_once 'Zend/Feed/Exception.php';
  381. throw new Zend_Feed_Exception("Failed to access $uri, got response code " . $response->getStatus());
  382. }
  383. $responseHtml = $response->getBody();
  384. $libxml_errflag = libxml_use_internal_errors(true);
  385. $oldValue = libxml_disable_entity_loader(true);
  386. $dom = new DOMDocument;
  387. $status = $dom->loadHTML($responseHtml);
  388. libxml_disable_entity_loader($oldValue);
  389. libxml_use_internal_errors($libxml_errflag);
  390. if (!$status) {
  391. // Build error message
  392. $error = libxml_get_last_error();
  393. if ($error && $error->message) {
  394. $errormsg = "DOMDocument cannot parse HTML: {$error->message}";
  395. } else {
  396. $errormsg = "DOMDocument cannot parse HTML: Please check the XML document's validity";
  397. }
  398. require_once 'Zend/Feed/Exception.php';
  399. throw new Zend_Feed_Exception($errormsg);
  400. }
  401. $feedSet = new Zend_Feed_Reader_FeedSet;
  402. $links = $dom->getElementsByTagName('link');
  403. $feedSet->addLinks($links, $uri);
  404. return $feedSet;
  405. }
  406. /**
  407. * Detect the feed type of the provided feed
  408. *
  409. * @param Zend_Feed_Abstract|DOMDocument|string $feed
  410. * @return string
  411. */
  412. public static function detectType($feed, $specOnly = false)
  413. {
  414. if ($feed instanceof Zend_Feed_Reader_FeedInterface) {
  415. $dom = $feed->getDomDocument();
  416. } elseif($feed instanceof DOMDocument) {
  417. $dom = $feed;
  418. } elseif(is_string($feed) && !empty($feed)) {
  419. @ini_set('track_errors', 1);
  420. $oldValue = libxml_disable_entity_loader(true);
  421. $dom = new DOMDocument;
  422. $status = @$dom->loadXML($feed);
  423. foreach ($dom->childNodes as $child) {
  424. if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
  425. require_once 'Zend/Feed/Exception.php';
  426. throw new Zend_Feed_Exception(
  427. 'Invalid XML: Detected use of illegal DOCTYPE'
  428. );
  429. }
  430. }
  431. libxml_disable_entity_loader($oldValue);
  432. @ini_restore('track_errors');
  433. if (!$status) {
  434. if (!isset($php_errormsg)) {
  435. if (function_exists('xdebug_is_enabled')) {
  436. $php_errormsg = '(error message not available, when XDebug is running)';
  437. } else {
  438. $php_errormsg = '(error message not available)';
  439. }
  440. }
  441. require_once 'Zend/Feed/Exception.php';
  442. throw new Zend_Feed_Exception("DOMDocument cannot parse XML: $php_errormsg");
  443. }
  444. } else {
  445. require_once 'Zend/Feed/Exception.php';
  446. throw new Zend_Feed_Exception('Invalid object/scalar provided: must'
  447. . ' be of type Zend_Feed_Reader_FeedInterface, DomDocument or string');
  448. }
  449. $xpath = new DOMXPath($dom);
  450. if ($xpath->query('/rss')->length) {
  451. $type = self::TYPE_RSS_ANY;
  452. $version = $xpath->evaluate('string(/rss/@version)');
  453. if (strlen($version) > 0) {
  454. switch($version) {
  455. case '2.0':
  456. $type = self::TYPE_RSS_20;
  457. break;
  458. case '0.94':
  459. $type = self::TYPE_RSS_094;
  460. break;
  461. case '0.93':
  462. $type = self::TYPE_RSS_093;
  463. break;
  464. case '0.92':
  465. $type = self::TYPE_RSS_092;
  466. break;
  467. case '0.91':
  468. $type = self::TYPE_RSS_091;
  469. break;
  470. }
  471. }
  472. return $type;
  473. }
  474. $xpath->registerNamespace('rdf', self::NAMESPACE_RDF);
  475. if ($xpath->query('/rdf:RDF')->length) {
  476. $xpath->registerNamespace('rss', self::NAMESPACE_RSS_10);
  477. if ($xpath->query('/rdf:RDF/rss:channel')->length
  478. || $xpath->query('/rdf:RDF/rss:image')->length
  479. || $xpath->query('/rdf:RDF/rss:item')->length
  480. || $xpath->query('/rdf:RDF/rss:textinput')->length
  481. ) {
  482. return self::TYPE_RSS_10;
  483. }
  484. $xpath->registerNamespace('rss', self::NAMESPACE_RSS_090);
  485. if ($xpath->query('/rdf:RDF/rss:channel')->length
  486. || $xpath->query('/rdf:RDF/rss:image')->length
  487. || $xpath->query('/rdf:RDF/rss:item')->length
  488. || $xpath->query('/rdf:RDF/rss:textinput')->length
  489. ) {
  490. return self::TYPE_RSS_090;
  491. }
  492. }
  493. $type = self::TYPE_ATOM_ANY;
  494. $xpath->registerNamespace('atom', self::NAMESPACE_ATOM_10);
  495. if ($xpath->query('//atom:feed')->length) {
  496. return self::TYPE_ATOM_10;
  497. }
  498. if ($xpath->query('//atom:entry')->length) {
  499. if ($specOnly == true) {
  500. return self::TYPE_ATOM_10;
  501. } else {
  502. return self::TYPE_ATOM_10_ENTRY;
  503. }
  504. }
  505. $xpath->registerNamespace('atom', self::NAMESPACE_ATOM_03);
  506. if ($xpath->query('//atom:feed')->length) {
  507. return self::TYPE_ATOM_03;
  508. }
  509. return self::TYPE_ANY;
  510. }
  511. /**
  512. * Set plugin loader for use with Extensions
  513. *
  514. * @param Zend_Loader_PluginLoader_Interface $loader
  515. */
  516. public static function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader)
  517. {
  518. self::$_pluginLoader = $loader;
  519. }
  520. /**
  521. * Get plugin loader for use with Extensions
  522. *
  523. * @return Zend_Loader_PluginLoader_Interface $loader
  524. */
  525. public static function getPluginLoader()
  526. {
  527. if (!isset(self::$_pluginLoader)) {
  528. require_once 'Zend/Loader/PluginLoader.php';
  529. self::$_pluginLoader = new Zend_Loader_PluginLoader(array(
  530. 'Zend_Feed_Reader_Extension_' => 'Zend/Feed/Reader/Extension/',
  531. ));
  532. }
  533. return self::$_pluginLoader;
  534. }
  535. /**
  536. * Add prefix path for loading Extensions
  537. *
  538. * @param string $prefix
  539. * @param string $path
  540. * @return void
  541. */
  542. public static function addPrefixPath($prefix, $path)
  543. {
  544. $prefix = rtrim($prefix, '_');
  545. $path = rtrim($path, DIRECTORY_SEPARATOR);
  546. self::getPluginLoader()->addPrefixPath($prefix, $path);
  547. }
  548. /**
  549. * Add multiple Extension prefix paths at once
  550. *
  551. * @param array $spec
  552. * @return void
  553. */
  554. public static function addPrefixPaths(array $spec)
  555. {
  556. if (isset($spec['prefix']) && isset($spec['path'])) {
  557. self::addPrefixPath($spec['prefix'], $spec['path']);
  558. }
  559. foreach ($spec as $prefixPath) {
  560. if (isset($prefixPath['prefix']) && isset($prefixPath['path'])) {
  561. self::addPrefixPath($prefixPath['prefix'], $prefixPath['path']);
  562. }
  563. }
  564. }
  565. /**
  566. * Register an Extension by name
  567. *
  568. * @param string $name
  569. * @return void
  570. * @throws Zend_Feed_Exception if unable to resolve Extension class
  571. */
  572. public static function registerExtension($name)
  573. {
  574. $feedName = $name . '_Feed';
  575. $entryName = $name . '_Entry';
  576. if (self::isRegistered($name)) {
  577. if (self::getPluginLoader()->isLoaded($feedName) ||
  578. self::getPluginLoader()->isLoaded($entryName)) {
  579. return;
  580. }
  581. }
  582. try {
  583. self::getPluginLoader()->load($feedName);
  584. self::$_extensions['feed'][] = $feedName;
  585. } catch (Zend_Loader_PluginLoader_Exception $e) {
  586. }
  587. try {
  588. self::getPluginLoader()->load($entryName);
  589. self::$_extensions['entry'][] = $entryName;
  590. } catch (Zend_Loader_PluginLoader_Exception $e) {
  591. }
  592. if (!self::getPluginLoader()->isLoaded($feedName)
  593. && !self::getPluginLoader()->isLoaded($entryName)
  594. ) {
  595. require_once 'Zend/Feed/Exception.php';
  596. throw new Zend_Feed_Exception('Could not load extension: ' . $name
  597. . 'using Plugin Loader. Check prefix paths are configured and extension exists.');
  598. }
  599. }
  600. /**
  601. * Is a given named Extension registered?
  602. *
  603. * @param string $extensionName
  604. * @return boolean
  605. */
  606. public static function isRegistered($extensionName)
  607. {
  608. $feedName = $extensionName . '_Feed';
  609. $entryName = $extensionName . '_Entry';
  610. if (in_array($feedName, self::$_extensions['feed'])
  611. || in_array($entryName, self::$_extensions['entry'])
  612. ) {
  613. return true;
  614. }
  615. return false;
  616. }
  617. /**
  618. * Get a list of extensions
  619. *
  620. * @return array
  621. */
  622. public static function getExtensions()
  623. {
  624. return self::$_extensions;
  625. }
  626. /**
  627. * Reset class state to defaults
  628. *
  629. * @return void
  630. */
  631. public static function reset()
  632. {
  633. self::$_cache = null;
  634. self::$_httpClient = null;
  635. self::$_httpMethodOverride = false;
  636. self::$_httpConditionalGet = false;
  637. self::$_pluginLoader = null;
  638. self::$_prefixPaths = array();
  639. self::$_extensions = array(
  640. 'feed' => array(
  641. 'DublinCore_Feed',
  642. 'Atom_Feed'
  643. ),
  644. 'entry' => array(
  645. 'Content_Entry',
  646. 'DublinCore_Entry',
  647. 'Atom_Entry'
  648. ),
  649. 'core' => array(
  650. 'DublinCore_Feed',
  651. 'Atom_Feed',
  652. 'Content_Entry',
  653. 'DublinCore_Entry',
  654. 'Atom_Entry'
  655. )
  656. );
  657. }
  658. /**
  659. * Register core (default) extensions
  660. *
  661. * @return void
  662. */
  663. protected static function _registerCoreExtensions()
  664. {
  665. self::registerExtension('DublinCore');
  666. self::registerExtension('Content');
  667. self::registerExtension('Atom');
  668. self::registerExtension('Slash');
  669. self::registerExtension('WellFormedWeb');
  670. self::registerExtension('Thread');
  671. self::registerExtension('Podcast');
  672. }
  673. /**
  674. * Utility method to apply array_unique operation to a multidimensional
  675. * array.
  676. *
  677. * @param array
  678. * @return array
  679. */
  680. public static function arrayUnique(array $array)
  681. {
  682. foreach ($array as &$value) {
  683. $value = serialize($value);
  684. }
  685. $array = array_unique($array);
  686. foreach ($array as &$value) {
  687. $value = unserialize($value);
  688. }
  689. return $array;
  690. }
  691. }