PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Zend/Feed/Reader.php

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