Reader.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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-2010 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  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-2010 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. return self::importString($responseXml);
  246. } elseif ($cache) {
  247. $data = $cache->load($cacheId);
  248. if ($data !== false) {
  249. return self::importString($data);
  250. }
  251. $response = $client->request('GET');
  252. if ($response->getStatus() !== 200) {
  253. require_once 'Zend/Feed/Exception.php';
  254. throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus());
  255. }
  256. $responseXml = $response->getBody();
  257. $cache->save($responseXml, $cacheId);
  258. return self::importString($responseXml);
  259. } else {
  260. $response = $client->request('GET');
  261. if ($response->getStatus() !== 200) {
  262. require_once 'Zend/Feed/Exception.php';
  263. throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus());
  264. }
  265. $reader = self::importString($response->getBody());
  266. $reader->setOriginalSourceUri($uri);
  267. return $reader;
  268. }
  269. }
  270. /**
  271. * Import a feed by providing a Zend_Feed_Abstract object
  272. *
  273. * @param Zend_Feed_Abstract $feed A fully instantiated Zend_Feed object
  274. * @return Zend_Feed_Reader_FeedInterface
  275. */
  276. public static function importFeed(Zend_Feed_Abstract $feed)
  277. {
  278. $dom = $feed->getDOM()->ownerDocument;
  279. $type = self::detectType($dom);
  280. self::_registerCoreExtensions();
  281. if (substr($type, 0, 3) == 'rss') {
  282. $reader = new Zend_Feed_Reader_Feed_Rss($dom, $type);
  283. } else {
  284. $reader = new Zend_Feed_Reader_Feed_Atom($dom, $type);
  285. }
  286. return $reader;
  287. }
  288. /**
  289. * Import a feed froma string
  290. *
  291. * @param string $string
  292. * @return Zend_Feed_Reader_FeedInterface
  293. */
  294. public static function importString($string)
  295. {
  296. $libxml_errflag = libxml_use_internal_errors(true);
  297. $dom = new DOMDocument;
  298. $status = $dom->loadXML($string);
  299. libxml_use_internal_errors($libxml_errflag);
  300. if (!$status) {
  301. // Build error message
  302. $error = libxml_get_last_error();
  303. if ($error && $error->message) {
  304. $errormsg = "DOMDocument cannot parse XML: {$error->message}";
  305. } else {
  306. $errormsg = "DOMDocument cannot parse XML: Please check the XML document's validity";
  307. }
  308. require_once 'Zend/Feed/Exception.php';
  309. throw new Zend_Feed_Exception($errormsg);
  310. }
  311. $type = self::detectType($dom);
  312. self::_registerCoreExtensions();
  313. if (substr($type, 0, 3) == 'rss') {
  314. $reader = new Zend_Feed_Reader_Feed_Rss($dom, $type);
  315. } elseif (substr($type, 8, 5) == 'entry') {
  316. $reader = new Zend_Feed_Reader_Entry_Atom($dom->documentElement, 0, Zend_Feed_Reader::TYPE_ATOM_10);
  317. } elseif (substr($type, 0, 4) == 'atom') {
  318. $reader = new Zend_Feed_Reader_Feed_Atom($dom, $type);
  319. } else {
  320. require_once 'Zend/Feed/Exception.php';
  321. throw new Zend_Feed_Exception('The URI used does not point to a '
  322. . 'valid Atom, RSS or RDF feed that Zend_Feed_Reader can parse.');
  323. }
  324. return $reader;
  325. }
  326. /**
  327. * Imports a feed from a file located at $filename.
  328. *
  329. * @param string $filename
  330. * @throws Zend_Feed_Exception
  331. * @return Zend_Feed_Reader_FeedInterface
  332. */
  333. public static function importFile($filename)
  334. {
  335. @ini_set('track_errors', 1);
  336. $feed = @file_get_contents($filename);
  337. @ini_restore('track_errors');
  338. if ($feed === false) {
  339. /**
  340. * @see Zend_Feed_Exception
  341. */
  342. require_once 'Zend/Feed/Exception.php';
  343. throw new Zend_Feed_Exception("File could not be loaded: $php_errormsg");
  344. }
  345. return self::importString($feed);
  346. }
  347. public static function findFeedLinks($uri)
  348. {
  349. // Get the HTTP response from $uri and save the contents
  350. $client = self::getHttpClient();
  351. $client->setUri($uri);
  352. $response = $client->request();
  353. if ($response->getStatus() !== 200) {
  354. /**
  355. * @see Zend_Feed_Exception
  356. */
  357. require_once 'Zend/Feed/Exception.php';
  358. throw new Zend_Feed_Exception("Failed to access $uri, got response code " . $response->getStatus());
  359. }
  360. $responseHtml = $response->getBody();
  361. $libxml_errflag = libxml_use_internal_errors(true);
  362. $dom = new DOMDocument;
  363. $status = $dom->loadHTML($responseHtml);
  364. libxml_use_internal_errors($libxml_errflag);
  365. if (!$status) {
  366. // Build error message
  367. $error = libxml_get_last_error();
  368. if ($error && $error->message) {
  369. $errormsg = "DOMDocument cannot parse HTML: {$error->message}";
  370. } else {
  371. $errormsg = "DOMDocument cannot parse HTML: Please check the XML document's validity";
  372. }
  373. require_once 'Zend/Feed/Exception.php';
  374. throw new Zend_Feed_Exception($errormsg);
  375. }
  376. $feedSet = new Zend_Feed_Reader_FeedSet;
  377. $links = $dom->getElementsByTagName('link');
  378. $feedSet->addLinks($links, $uri);
  379. return $feedSet;
  380. }
  381. /**
  382. * Detect the feed type of the provided feed
  383. *
  384. * @param Zend_Feed_Abstract|DOMDocument|string $feed
  385. * @return string
  386. */
  387. public static function detectType($feed, $specOnly = false)
  388. {
  389. if ($feed instanceof Zend_Feed_Reader_FeedInterface) {
  390. $dom = $feed->getDomDocument();
  391. } elseif($feed instanceof DOMDocument) {
  392. $dom = $feed;
  393. } elseif(is_string($feed) && !empty($feed)) {
  394. @ini_set('track_errors', 1);
  395. $dom = new DOMDocument;
  396. $status = @$dom->loadXML($feed);
  397. @ini_restore('track_errors');
  398. if (!$status) {
  399. if (!isset($php_errormsg)) {
  400. if (function_exists('xdebug_is_enabled')) {
  401. $php_errormsg = '(error message not available, when XDebug is running)';
  402. } else {
  403. $php_errormsg = '(error message not available)';
  404. }
  405. }
  406. require_once 'Zend/Feed/Exception.php';
  407. throw new Zend_Feed_Exception("DOMDocument cannot parse XML: $php_errormsg");
  408. }
  409. } else {
  410. require_once 'Zend/Feed/Exception.php';
  411. throw new Zend_Feed_Exception('Invalid object/scalar provided: must'
  412. . ' be of type Zend_Feed_Reader_FeedInterface, DomDocument or string');
  413. }
  414. $xpath = new DOMXPath($dom);
  415. if ($xpath->query('/rss')->length) {
  416. $type = self::TYPE_RSS_ANY;
  417. $version = $xpath->evaluate('string(/rss/@version)');
  418. if (strlen($version) > 0) {
  419. switch($version) {
  420. case '2.0':
  421. $type = self::TYPE_RSS_20;
  422. break;
  423. case '0.94':
  424. $type = self::TYPE_RSS_094;
  425. break;
  426. case '0.93':
  427. $type = self::TYPE_RSS_093;
  428. break;
  429. case '0.92':
  430. $type = self::TYPE_RSS_092;
  431. break;
  432. case '0.91':
  433. $type = self::TYPE_RSS_091;
  434. break;
  435. }
  436. }
  437. return $type;
  438. }
  439. $xpath->registerNamespace('rdf', self::NAMESPACE_RDF);
  440. if ($xpath->query('/rdf:RDF')->length) {
  441. $xpath->registerNamespace('rss', self::NAMESPACE_RSS_10);
  442. if ($xpath->query('/rdf:RDF/rss:channel')->length
  443. || $xpath->query('/rdf:RDF/rss:image')->length
  444. || $xpath->query('/rdf:RDF/rss:item')->length
  445. || $xpath->query('/rdf:RDF/rss:textinput')->length
  446. ) {
  447. return self::TYPE_RSS_10;
  448. }
  449. $xpath->registerNamespace('rss', self::NAMESPACE_RSS_090);
  450. if ($xpath->query('/rdf:RDF/rss:channel')->length
  451. || $xpath->query('/rdf:RDF/rss:image')->length
  452. || $xpath->query('/rdf:RDF/rss:item')->length
  453. || $xpath->query('/rdf:RDF/rss:textinput')->length
  454. ) {
  455. return self::TYPE_RSS_090;
  456. }
  457. }
  458. $type = self::TYPE_ATOM_ANY;
  459. $xpath->registerNamespace('atom', self::NAMESPACE_ATOM_10);
  460. if ($xpath->query('//atom:feed')->length) {
  461. return self::TYPE_ATOM_10;
  462. }
  463. if ($xpath->query('//atom:entry')->length) {
  464. if ($specOnly == true) {
  465. return self::TYPE_ATOM_10;
  466. } else {
  467. return self::TYPE_ATOM_10_ENTRY;
  468. }
  469. }
  470. $xpath->registerNamespace('atom', self::NAMESPACE_ATOM_03);
  471. if ($xpath->query('//atom:feed')->length) {
  472. return self::TYPE_ATOM_03;
  473. }
  474. return self::TYPE_ANY;
  475. }
  476. /**
  477. * Set plugin loader for use with Extensions
  478. *
  479. * @param Zend_Loader_PluginLoader_Interface $loader
  480. */
  481. public static function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader)
  482. {
  483. self::$_pluginLoader = $loader;
  484. }
  485. /**
  486. * Get plugin loader for use with Extensions
  487. *
  488. * @return Zend_Loader_PluginLoader_Interface $loader
  489. */
  490. public static function getPluginLoader()
  491. {
  492. if (!isset(self::$_pluginLoader)) {
  493. require_once 'Zend/Loader/PluginLoader.php';
  494. self::$_pluginLoader = new Zend_Loader_PluginLoader(array(
  495. 'Zend_Feed_Reader_Extension_' => 'Zend/Feed/Reader/Extension/',
  496. ));
  497. }
  498. return self::$_pluginLoader;
  499. }
  500. /**
  501. * Add prefix path for loading Extensions
  502. *
  503. * @param string $prefix
  504. * @param string $path
  505. * @return void
  506. */
  507. public static function addPrefixPath($prefix, $path)
  508. {
  509. $prefix = rtrim($prefix, '_');
  510. $path = rtrim($path, DIRECTORY_SEPARATOR);
  511. self::getPluginLoader()->addPrefixPath($prefix, $path);
  512. }
  513. /**
  514. * Add multiple Extension prefix paths at once
  515. *
  516. * @param array $spec
  517. * @return void
  518. */
  519. public static function addPrefixPaths(array $spec)
  520. {
  521. if (isset($spec['prefix']) && isset($spec['path'])) {
  522. self::addPrefixPath($spec['prefix'], $spec['path']);
  523. }
  524. foreach ($spec as $prefixPath) {
  525. if (isset($prefixPath['prefix']) && isset($prefixPath['path'])) {
  526. self::addPrefixPath($prefixPath['prefix'], $prefixPath['path']);
  527. }
  528. }
  529. }
  530. /**
  531. * Register an Extension by name
  532. *
  533. * @param string $name
  534. * @return void
  535. * @throws Zend_Feed_Exception if unable to resolve Extension class
  536. */
  537. public static function registerExtension($name)
  538. {
  539. $feedName = $name . '_Feed';
  540. $entryName = $name . '_Entry';
  541. if (self::isRegistered($name)) {
  542. if (self::getPluginLoader()->isLoaded($feedName) ||
  543. self::getPluginLoader()->isLoaded($entryName)) {
  544. return;
  545. }
  546. }
  547. try {
  548. self::getPluginLoader()->load($feedName);
  549. self::$_extensions['feed'][] = $feedName;
  550. } catch (Zend_Loader_PluginLoader_Exception $e) {
  551. }
  552. try {
  553. self::getPluginLoader()->load($entryName);
  554. self::$_extensions['entry'][] = $entryName;
  555. } catch (Zend_Loader_PluginLoader_Exception $e) {
  556. }
  557. if (!self::getPluginLoader()->isLoaded($feedName)
  558. && !self::getPluginLoader()->isLoaded($entryName)
  559. ) {
  560. require_once 'Zend/Feed/Exception.php';
  561. throw new Zend_Feed_Exception('Could not load extension: ' . $name
  562. . 'using Plugin Loader. Check prefix paths are configured and extension exists.');
  563. }
  564. }
  565. /**
  566. * Is a given named Extension registered?
  567. *
  568. * @param string $extensionName
  569. * @return boolean
  570. */
  571. public static function isRegistered($extensionName)
  572. {
  573. $feedName = $extensionName . '_Feed';
  574. $entryName = $extensionName . '_Entry';
  575. if (in_array($feedName, self::$_extensions['feed'])
  576. || in_array($entryName, self::$_extensions['entry'])
  577. ) {
  578. return true;
  579. }
  580. return false;
  581. }
  582. /**
  583. * Get a list of extensions
  584. *
  585. * @return array
  586. */
  587. public static function getExtensions()
  588. {
  589. return self::$_extensions;
  590. }
  591. /**
  592. * Reset class state to defaults
  593. *
  594. * @return void
  595. */
  596. public static function reset()
  597. {
  598. self::$_cache = null;
  599. self::$_httpClient = null;
  600. self::$_httpMethodOverride = false;
  601. self::$_httpConditionalGet = false;
  602. self::$_pluginLoader = null;
  603. self::$_prefixPaths = array();
  604. self::$_extensions = array(
  605. 'feed' => array(
  606. 'DublinCore_Feed',
  607. 'Atom_Feed'
  608. ),
  609. 'entry' => array(
  610. 'Content_Entry',
  611. 'DublinCore_Entry',
  612. 'Atom_Entry'
  613. ),
  614. 'core' => array(
  615. 'DublinCore_Feed',
  616. 'Atom_Feed',
  617. 'Content_Entry',
  618. 'DublinCore_Entry',
  619. 'Atom_Entry'
  620. )
  621. );
  622. }
  623. /**
  624. * Register core (default) extensions
  625. *
  626. * @return void
  627. */
  628. protected static function _registerCoreExtensions()
  629. {
  630. self::registerExtension('DublinCore');
  631. self::registerExtension('Content');
  632. self::registerExtension('Atom');
  633. self::registerExtension('Slash');
  634. self::registerExtension('WellFormedWeb');
  635. self::registerExtension('Thread');
  636. self::registerExtension('Podcast');
  637. }
  638. /**
  639. * Utility method to apply array_unique operation to a multidimensional
  640. * array.
  641. *
  642. * @param array
  643. * @return array
  644. */
  645. public static function arrayUnique(array $array)
  646. {
  647. foreach ($array as &$value) {
  648. $value = serialize($value);
  649. }
  650. $array = array_unique($array);
  651. foreach ($array as &$value) {
  652. $value = unserialize($value);
  653. }
  654. return $array;
  655. }
  656. }