Item.php 96 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990
  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-2012, 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.4-dev
  37. * @copyright 2004-2012 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. */
  44. /**
  45. * Manages all item-related data
  46. *
  47. * Used by {@see SimplePie::get_item()} and {@see SimplePie::get_items()}
  48. *
  49. * This class can be overloaded with {@see SimplePie::set_item_class()}
  50. *
  51. * @package SimplePie
  52. * @subpackage API
  53. */
  54. class SimplePie_Item
  55. {
  56. /**
  57. * Parent feed
  58. *
  59. * @access private
  60. * @var SimplePie
  61. */
  62. var $feed;
  63. /**
  64. * Raw data
  65. *
  66. * @access private
  67. * @var array
  68. */
  69. var $data = array();
  70. /**
  71. * Registry object
  72. *
  73. * @see set_registry
  74. * @var SimplePie_Registry
  75. */
  76. protected $registry;
  77. /**
  78. * Create a new item object
  79. *
  80. * This is usually used by {@see SimplePie::get_items} and
  81. * {@see SimplePie::get_item}. Avoid creating this manually.
  82. *
  83. * @param SimplePie $feed Parent feed
  84. * @param array $data Raw data
  85. */
  86. public function __construct($feed, $data)
  87. {
  88. $this->feed = $feed;
  89. $this->data = $data;
  90. }
  91. /**
  92. * Set the registry handler
  93. *
  94. * This is usually used by {@see SimplePie_Registry::create}
  95. *
  96. * @since 1.3
  97. * @param SimplePie_Registry $registry
  98. */
  99. public function set_registry(SimplePie_Registry $registry)
  100. {
  101. $this->registry = $registry;
  102. }
  103. /**
  104. * Get a string representation of the item
  105. *
  106. * @return string
  107. */
  108. public function __toString()
  109. {
  110. return md5(serialize($this->data));
  111. }
  112. /**
  113. * Remove items that link back to this before destroying this object
  114. */
  115. public function __destruct()
  116. {
  117. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
  118. {
  119. unset($this->feed);
  120. }
  121. }
  122. /**
  123. * Get data for an item-level element
  124. *
  125. * This method allows you to get access to ANY element/attribute that is a
  126. * sub-element of the item/entry tag.
  127. *
  128. * See {@see SimplePie::get_feed_tags()} for a description of the return value
  129. *
  130. * @since 1.0
  131. * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
  132. * @param string $namespace The URL of the XML namespace of the elements you're trying to access
  133. * @param string $tag Tag name
  134. * @return array
  135. */
  136. public function get_item_tags($namespace, $tag)
  137. {
  138. if (isset($this->data['child'][$namespace][$tag]))
  139. {
  140. return $this->data['child'][$namespace][$tag];
  141. }
  142. else
  143. {
  144. return null;
  145. }
  146. }
  147. /**
  148. * Get the base URL value from the parent feed
  149. *
  150. * Uses `<xml:base>`
  151. *
  152. * @param array $element
  153. * @return string
  154. */
  155. public function get_base($element = array())
  156. {
  157. return $this->feed->get_base($element);
  158. }
  159. /**
  160. * Sanitize feed data
  161. *
  162. * @access private
  163. * @see SimplePie::sanitize()
  164. * @param string $data Data to sanitize
  165. * @param int $type One of the SIMPLEPIE_CONSTRUCT_* constants
  166. * @param string $base Base URL to resolve URLs against
  167. * @return string Sanitized data
  168. */
  169. public function sanitize($data, $type, $base = '')
  170. {
  171. return $this->feed->sanitize($data, $type, $base);
  172. }
  173. /**
  174. * Get the parent feed
  175. *
  176. * Note: this may not work as you think for multifeeds!
  177. *
  178. * @link http://simplepie.org/faq/typical_multifeed_gotchas#missing_data_from_feed
  179. * @since 1.0
  180. * @return SimplePie
  181. */
  182. public function get_feed()
  183. {
  184. return $this->feed;
  185. }
  186. /**
  187. * Get the unique identifier for the item
  188. *
  189. * This is usually used when writing code to check for new items in a feed.
  190. *
  191. * Uses `<atom:id>`, `<guid>`, `<dc:identifier>` or the `about` attribute
  192. * for RDF. If none of these are supplied (or `$hash` is true), creates an
  193. * MD5 hash based on the permalink and title. If either of those are not
  194. * supplied, creates a hash based on the full feed data.
  195. *
  196. * @since Beta 2
  197. * @param boolean $hash Should we force using a hash instead of the supplied ID?
  198. * @return string
  199. */
  200. public function get_id($hash = false)
  201. {
  202. if (!$hash)
  203. {
  204. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id'))
  205. {
  206. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  207. }
  208. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'id'))
  209. {
  210. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  211. }
  212. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
  213. {
  214. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  215. }
  216. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'identifier'))
  217. {
  218. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  219. }
  220. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'identifier'))
  221. {
  222. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  223. }
  224. elseif (isset($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about']))
  225. {
  226. return $this->sanitize($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about'], SIMPLEPIE_CONSTRUCT_TEXT);
  227. }
  228. elseif (($return = $this->get_permalink()) !== null)
  229. {
  230. return $return;
  231. }
  232. elseif (($return = $this->get_title()) !== null)
  233. {
  234. return $return;
  235. }
  236. }
  237. if ($this->get_permalink() !== null || $this->get_title() !== null)
  238. {
  239. return md5($this->get_permalink() . $this->get_title());
  240. }
  241. else
  242. {
  243. return md5(serialize($this->data));
  244. }
  245. }
  246. /**
  247. * Get the title of the item
  248. *
  249. * Uses `<atom:title>`, `<title>` or `<dc:title>`
  250. *
  251. * @since Beta 2 (previously called `get_item_title` since 0.8)
  252. * @return string|null
  253. */
  254. public function get_title()
  255. {
  256. if (!isset($this->data['title']))
  257. {
  258. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  259. {
  260. $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  261. }
  262. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  263. {
  264. $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  265. }
  266. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  267. {
  268. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  269. }
  270. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  271. {
  272. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  273. }
  274. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  275. {
  276. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  277. }
  278. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  279. {
  280. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  281. }
  282. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  283. {
  284. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  285. }
  286. else
  287. {
  288. $this->data['title'] = null;
  289. }
  290. }
  291. return $this->data['title'];
  292. }
  293. /**
  294. * Get the content for the item
  295. *
  296. * Prefers summaries over full content , but will return full content if a
  297. * summary does not exist.
  298. *
  299. * To prefer full content instead, use {@see get_content}
  300. *
  301. * Uses `<atom:summary>`, `<description>`, `<dc:description>` or
  302. * `<itunes:subtitle>`
  303. *
  304. * @since 0.8
  305. * @param boolean $description_only Should we avoid falling back to the content?
  306. * @return string|null
  307. */
  308. public function get_description($description_only = false)
  309. {
  310. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary'))
  311. {
  312. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  313. }
  314. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary'))
  315. {
  316. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  317. }
  318. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  319. {
  320. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  321. }
  322. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
  323. {
  324. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  325. }
  326. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  327. {
  328. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  329. }
  330. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  331. {
  332. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  333. }
  334. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  335. {
  336. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  337. }
  338. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  339. {
  340. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  341. }
  342. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
  343. {
  344. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
  345. }
  346. elseif (!$description_only)
  347. {
  348. return $this->get_content(true);
  349. }
  350. else
  351. {
  352. return null;
  353. }
  354. }
  355. /**
  356. * Get the content for the item
  357. *
  358. * Prefers full content over summaries, but will return a summary if full
  359. * content does not exist.
  360. *
  361. * To prefer summaries instead, use {@see get_description}
  362. *
  363. * Uses `<atom:content>` or `<content:encoded>` (RSS 1.0 Content Module)
  364. *
  365. * @since 1.0
  366. * @param boolean $content_only Should we avoid falling back to the description?
  367. * @return string|null
  368. */
  369. public function get_content($content_only = false)
  370. {
  371. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content'))
  372. {
  373. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_content_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  374. }
  375. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content'))
  376. {
  377. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  378. }
  379. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded'))
  380. {
  381. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  382. }
  383. elseif (!$content_only)
  384. {
  385. return $this->get_description(true);
  386. }
  387. else
  388. {
  389. return null;
  390. }
  391. }
  392. /**
  393. * Get the media:thumbnail of the item
  394. *
  395. * Uses `<media:thumbnail>`
  396. *
  397. *
  398. * @return array|null
  399. */
  400. public function get_thumbnail()
  401. {
  402. if (!isset($this->data['thumbnail']))
  403. {
  404. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  405. {
  406. $this->data['thumbnail'] = $return[0]['attribs'][''];
  407. }
  408. else
  409. {
  410. $this->data['thumbnail'] = null;
  411. }
  412. }
  413. return $this->data['thumbnail'];
  414. }
  415. /**
  416. * Get a category for the item
  417. *
  418. * @since Beta 3 (previously called `get_categories()` since Beta 2)
  419. * @param int $key The category that you want to return. Remember that arrays begin with 0, not 1
  420. * @return SimplePie_Category|null
  421. */
  422. public function get_category($key = 0)
  423. {
  424. $categories = $this->get_categories();
  425. if (isset($categories[$key]))
  426. {
  427. return $categories[$key];
  428. }
  429. else
  430. {
  431. return null;
  432. }
  433. }
  434. /**
  435. * Get all categories for the item
  436. *
  437. * Uses `<atom:category>`, `<category>` or `<dc:subject>`
  438. *
  439. * @since Beta 3
  440. * @return array|null List of {@see SimplePie_Category} objects
  441. */
  442. public function get_categories()
  443. {
  444. $categories = array();
  445. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  446. {
  447. $term = null;
  448. $scheme = null;
  449. $label = null;
  450. if (isset($category['attribs']['']['term']))
  451. {
  452. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  453. }
  454. if (isset($category['attribs']['']['scheme']))
  455. {
  456. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  457. }
  458. if (isset($category['attribs']['']['label']))
  459. {
  460. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  461. }
  462. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  463. }
  464. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
  465. {
  466. // This is really the label, but keep this as the term also for BC.
  467. // Label will also work on retrieving because that falls back to term.
  468. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  469. if (isset($category['attribs']['']['domain']))
  470. {
  471. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  472. }
  473. else
  474. {
  475. $scheme = null;
  476. }
  477. $categories[] = $this->registry->create('Category', array($term, $scheme, null));
  478. }
  479. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  480. {
  481. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  482. }
  483. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  484. {
  485. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  486. }
  487. if (!empty($categories))
  488. {
  489. return array_unique($categories);
  490. }
  491. else
  492. {
  493. return null;
  494. }
  495. }
  496. /**
  497. * Get an author for the item
  498. *
  499. * @since Beta 2
  500. * @param int $key The author that you want to return. Remember that arrays begin with 0, not 1
  501. * @return SimplePie_Author|null
  502. */
  503. public function get_author($key = 0)
  504. {
  505. $authors = $this->get_authors();
  506. if (isset($authors[$key]))
  507. {
  508. return $authors[$key];
  509. }
  510. else
  511. {
  512. return null;
  513. }
  514. }
  515. /**
  516. * Get a contributor for the item
  517. *
  518. * @since 1.1
  519. * @param int $key The contrbutor that you want to return. Remember that arrays begin with 0, not 1
  520. * @return SimplePie_Author|null
  521. */
  522. public function get_contributor($key = 0)
  523. {
  524. $contributors = $this->get_contributors();
  525. if (isset($contributors[$key]))
  526. {
  527. return $contributors[$key];
  528. }
  529. else
  530. {
  531. return null;
  532. }
  533. }
  534. /**
  535. * Get all contributors for the item
  536. *
  537. * Uses `<atom:contributor>`
  538. *
  539. * @since 1.1
  540. * @return array|null List of {@see SimplePie_Author} objects
  541. */
  542. public function get_contributors()
  543. {
  544. $contributors = array();
  545. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  546. {
  547. $name = null;
  548. $uri = null;
  549. $email = null;
  550. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  551. {
  552. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  553. }
  554. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  555. {
  556. $uri = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  557. }
  558. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  559. {
  560. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  561. }
  562. if ($name !== null || $email !== null || $uri !== null)
  563. {
  564. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  565. }
  566. }
  567. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  568. {
  569. $name = null;
  570. $url = null;
  571. $email = null;
  572. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  573. {
  574. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  575. }
  576. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  577. {
  578. $url = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  579. }
  580. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  581. {
  582. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  583. }
  584. if ($name !== null || $email !== null || $url !== null)
  585. {
  586. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  587. }
  588. }
  589. if (!empty($contributors))
  590. {
  591. return array_unique($contributors);
  592. }
  593. else
  594. {
  595. return null;
  596. }
  597. }
  598. /**
  599. * Get all authors for the item
  600. *
  601. * Uses `<atom:author>`, `<author>`, `<dc:creator>` or `<itunes:author>`
  602. *
  603. * @since Beta 2
  604. * @return array|null List of {@see SimplePie_Author} objects
  605. */
  606. public function get_authors()
  607. {
  608. $authors = array();
  609. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  610. {
  611. $name = null;
  612. $uri = null;
  613. $email = null;
  614. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  615. {
  616. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  617. }
  618. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  619. {
  620. $uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  621. }
  622. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  623. {
  624. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  625. }
  626. if ($name !== null || $email !== null || $uri !== null)
  627. {
  628. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  629. }
  630. }
  631. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  632. {
  633. $name = null;
  634. $url = null;
  635. $email = null;
  636. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  637. {
  638. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  639. }
  640. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  641. {
  642. $url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  643. }
  644. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  645. {
  646. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  647. }
  648. if ($name !== null || $email !== null || $url !== null)
  649. {
  650. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  651. }
  652. }
  653. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'author'))
  654. {
  655. $authors[] = $this->registry->create('Author', array(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)));
  656. }
  657. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  658. {
  659. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  660. }
  661. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  662. {
  663. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  664. }
  665. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  666. {
  667. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  668. }
  669. if (!empty($authors))
  670. {
  671. return array_unique($authors);
  672. }
  673. elseif (($source = $this->get_source()) && ($authors = $source->get_authors()))
  674. {
  675. return $authors;
  676. }
  677. elseif ($authors = $this->feed->get_authors())
  678. {
  679. return $authors;
  680. }
  681. else
  682. {
  683. return null;
  684. }
  685. }
  686. /**
  687. * Get the copyright info for the item
  688. *
  689. * Uses `<atom:rights>` or `<dc:rights>`
  690. *
  691. * @since 1.1
  692. * @return string
  693. */
  694. public function get_copyright()
  695. {
  696. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  697. {
  698. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  699. }
  700. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  701. {
  702. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  703. }
  704. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  705. {
  706. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  707. }
  708. else
  709. {
  710. return null;
  711. }
  712. }
  713. /**
  714. * Get the posting date/time for the item
  715. *
  716. * Uses `<atom:published>`, `<atom:updated>`, `<atom:issued>`,
  717. * `<atom:modified>`, `<pubDate>` or `<dc:date>`
  718. *
  719. * Note: obeys PHP's timezone setting. To get a UTC date/time, use
  720. * {@see get_gmdate}
  721. *
  722. * @since Beta 2 (previously called `get_item_date` since 0.8)
  723. *
  724. * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data)
  725. * @return int|string|null
  726. */
  727. public function get_date($date_format = 'j F Y, g:i a')
  728. {
  729. if (!isset($this->data['date']))
  730. {
  731. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'))
  732. {
  733. $this->data['date']['raw'] = $return[0]['data'];
  734. }
  735. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'pubDate'))
  736. {
  737. $this->data['date']['raw'] = $return[0]['data'];
  738. }
  739. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date'))
  740. {
  741. $this->data['date']['raw'] = $return[0]['data'];
  742. }
  743. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date'))
  744. {
  745. $this->data['date']['raw'] = $return[0]['data'];
  746. }
  747. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  748. {
  749. $this->data['date']['raw'] = $return[0]['data'];
  750. }
  751. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'issued'))
  752. {
  753. $this->data['date']['raw'] = $return[0]['data'];
  754. }
  755. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'created'))
  756. {
  757. $this->data['date']['raw'] = $return[0]['data'];
  758. }
  759. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'modified'))
  760. {
  761. $this->data['date']['raw'] = $return[0]['data'];
  762. }
  763. if (!empty($this->data['date']['raw']))
  764. {
  765. $parser = $this->registry->call('Parse_Date', 'get');
  766. $this->data['date']['parsed'] = $parser->parse($this->data['date']['raw']);
  767. }
  768. else
  769. {
  770. $this->data['date'] = null;
  771. }
  772. }
  773. if ($this->data['date'])
  774. {
  775. $date_format = (string) $date_format;
  776. switch ($date_format)
  777. {
  778. case '':
  779. return $this->sanitize($this->data['date']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  780. case 'U':
  781. return $this->data['date']['parsed'];
  782. default:
  783. return date($date_format, $this->data['date']['parsed']);
  784. }
  785. }
  786. else
  787. {
  788. return null;
  789. }
  790. }
  791. /**
  792. * Get the update date/time for the item
  793. *
  794. * Uses `<atom:updated>`
  795. *
  796. * Note: obeys PHP's timezone setting. To get a UTC date/time, use
  797. * {@see get_gmdate}
  798. *
  799. * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data)
  800. * @return int|string|null
  801. */
  802. public function get_updated_date($date_format = 'j F Y, g:i a')
  803. {
  804. if (!isset($this->data['updated']))
  805. {
  806. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  807. {
  808. $this->data['updated']['raw'] = $return[0]['data'];
  809. }
  810. if (!empty($this->data['updated']['raw']))
  811. {
  812. $parser = $this->registry->call('Parse_Date', 'get');
  813. $this->data['updated']['parsed'] = $parser->parse($this->data['updated']['raw']);
  814. }
  815. else
  816. {
  817. $this->data['updated'] = null;
  818. }
  819. }
  820. if ($this->data['updated'])
  821. {
  822. $date_format = (string) $date_format;
  823. switch ($date_format)
  824. {
  825. case '':
  826. return $this->sanitize($this->data['updated']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  827. case 'U':
  828. return $this->data['updated']['parsed'];
  829. default:
  830. return date($date_format, $this->data['updated']['parsed']);
  831. }
  832. }
  833. else
  834. {
  835. return null;
  836. }
  837. }
  838. /**
  839. * Get the localized posting date/time for the item
  840. *
  841. * Returns the date formatted in the localized language. To display in
  842. * languages other than the server's default, you need to change the locale
  843. * with {@link http://php.net/setlocale setlocale()}. The available
  844. * localizations depend on which ones are installed on your web server.
  845. *
  846. * @since 1.0
  847. *
  848. * @param string $date_format Supports any PHP date format from {@see http://php.net/strftime} (empty for the raw data)
  849. * @return int|string|null
  850. */
  851. public function get_local_date($date_format = '%c')
  852. {
  853. if (!$date_format)
  854. {
  855. return $this->sanitize($this->get_date(''), SIMPLEPIE_CONSTRUCT_TEXT);
  856. }
  857. elseif (($date = $this->get_date('U')) !== null && $date !== false)
  858. {
  859. return strftime($date_format, $date);
  860. }
  861. else
  862. {
  863. return null;
  864. }
  865. }
  866. /**
  867. * Get the posting date/time for the item (UTC time)
  868. *
  869. * @see get_date
  870. * @param string $date_format Supports any PHP date format from {@see http://php.net/date}
  871. * @return int|string|null
  872. */
  873. public function get_gmdate($date_format = 'j F Y, g:i a')
  874. {
  875. $date = $this->get_date('U');
  876. if ($date === null)
  877. {
  878. return null;
  879. }
  880. return gmdate($date_format, $date);
  881. }
  882. /**
  883. * Get the update date/time for the item (UTC time)
  884. *
  885. * @see get_updated_date
  886. * @param string $date_format Supports any PHP date format from {@see http://php.net/date}
  887. * @return int|string|null
  888. */
  889. public function get_updated_gmdate($date_format = 'j F Y, g:i a')
  890. {
  891. $date = $this->get_updated_date('U');
  892. if ($date === null)
  893. {
  894. return null;
  895. }
  896. return gmdate($date_format, $date);
  897. }
  898. /**
  899. * Get the permalink for the item
  900. *
  901. * Returns the first link available with a relationship of "alternate".
  902. * Identical to {@see get_link()} with key 0
  903. *
  904. * @see get_link
  905. * @since 0.8
  906. * @return string|null Permalink URL
  907. */
  908. public function get_permalink()
  909. {
  910. $link = $this->get_link();
  911. $enclosure = $this->get_enclosure(0);
  912. if ($link !== null)
  913. {
  914. return $link;
  915. }
  916. elseif ($enclosure !== null)
  917. {
  918. return $enclosure->get_link();
  919. }
  920. else
  921. {
  922. return null;
  923. }
  924. }
  925. /**
  926. * Get a single link for the item
  927. *
  928. * @since Beta 3
  929. * @param int $key The link that you want to return. Remember that arrays begin with 0, not 1
  930. * @param string $rel The relationship of the link to return
  931. * @return string|null Link URL
  932. */
  933. public function get_link($key = 0, $rel = 'alternate')
  934. {
  935. $links = $this->get_links($rel);
  936. if ($links[$key] !== null)
  937. {
  938. return $links[$key];
  939. }
  940. else
  941. {
  942. return null;
  943. }
  944. }
  945. /**
  946. * Get all links for the item
  947. *
  948. * Uses `<atom:link>`, `<link>` or `<guid>`
  949. *
  950. * @since Beta 2
  951. * @param string $rel The relationship of links to return
  952. * @return array|null Links found for the item (strings)
  953. */
  954. public function get_links($rel = 'alternate')
  955. {
  956. if (!isset($this->data['links']))
  957. {
  958. $this->data['links'] = array();
  959. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  960. {
  961. if (isset($link['attribs']['']['href']))
  962. {
  963. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  964. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  965. }
  966. }
  967. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
  968. {
  969. if (isset($link['attribs']['']['href']))
  970. {
  971. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  972. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  973. }
  974. }
  975. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  976. {
  977. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  978. }
  979. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  980. {
  981. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  982. }
  983. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  984. {
  985. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  986. }
  987. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
  988. {
  989. if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) === 'true')
  990. {
  991. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  992. }
  993. }
  994. $keys = array_keys($this->data['links']);
  995. foreach ($keys as $key)
  996. {
  997. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
  998. {
  999. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  1000. {
  1001. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  1002. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  1003. }
  1004. else
  1005. {
  1006. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  1007. }
  1008. }
  1009. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  1010. {
  1011. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  1012. }
  1013. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  1014. }
  1015. }
  1016. if (isset($this->data['links'][$rel]))
  1017. {
  1018. return $this->data['links'][$rel];
  1019. }
  1020. else
  1021. {
  1022. return null;
  1023. }
  1024. }
  1025. /**
  1026. * Get an enclosure from the item
  1027. *
  1028. * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
  1029. *
  1030. * @since Beta 2
  1031. * @todo Add ability to prefer one type of content over another (in a media group).
  1032. * @param int $key The enclosure that you want to return. Remember that arrays begin with 0, not 1
  1033. * @return SimplePie_Enclosure|null
  1034. */
  1035. public function get_enclosure($key = 0, $prefer = null)
  1036. {
  1037. $enclosures = $this->get_enclosures();
  1038. if (isset($enclosures[$key]))
  1039. {
  1040. return $enclosures[$key];
  1041. }
  1042. else
  1043. {
  1044. return null;
  1045. }
  1046. }
  1047. /**
  1048. * Get all available enclosures (podcasts, etc.)
  1049. *
  1050. * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
  1051. *
  1052. * At this point, we're pretty much assuming that all enclosures for an item
  1053. * are the same content. Anything else is too complicated to
  1054. * properly support.
  1055. *
  1056. * @since Beta 2
  1057. * @todo Add support for end-user defined sorting of enclosures by type/handler (so we can prefer the faster-loading FLV over MP4).
  1058. * @todo If an element exists at a level, but its value is empty, we should fall back to the value from the parent (if it exists).
  1059. * @return array|null List of SimplePie_Enclosure items
  1060. */
  1061. public function get_enclosures()
  1062. {
  1063. if (!isset($this->data['enclosures']))
  1064. {
  1065. $this->data['enclosures'] = array();
  1066. // Elements
  1067. $captions_parent = null;
  1068. $categories_parent = null;
  1069. $copyrights_parent = null;
  1070. $credits_parent = null;
  1071. $description_parent = null;
  1072. $duration_parent = null;
  1073. $hashes_parent = null;
  1074. $keywords_parent = null;
  1075. $player_parent = null;
  1076. $ratings_parent = null;
  1077. $restrictions_parent = null;
  1078. $thumbnails_parent = null;
  1079. $title_parent = null;
  1080. // Let's do the channel and item-level ones first, and just re-use them if we need to.
  1081. $parent = $this->get_feed();
  1082. // CAPTIONS
  1083. if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  1084. {
  1085. foreach ($captions as $caption)
  1086. {
  1087. $caption_type = null;
  1088. $caption_lang = null;
  1089. $caption_startTime = null;
  1090. $caption_endTime = null;
  1091. $caption_text = null;
  1092. if (isset($caption['attribs']['']['type']))
  1093. {
  1094. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1095. }
  1096. if (isset($caption['attribs']['']['lang']))
  1097. {
  1098. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1099. }
  1100. if (isset($caption['attribs']['']['start']))
  1101. {
  1102. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  1103. }
  1104. if (isset($caption['attribs']['']['end']))
  1105. {
  1106. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  1107. }
  1108. if (isset($caption['data']))
  1109. {
  1110. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1111. }
  1112. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  1113. }
  1114. }
  1115. elseif ($captions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  1116. {
  1117. foreach ($captions as $caption)
  1118. {
  1119. $caption_type = null;
  1120. $caption_lang = null;
  1121. $caption_startTime = null;
  1122. $caption_endTime = null;
  1123. $caption_text = null;
  1124. if (isset($caption['attribs']['']['type']))
  1125. {
  1126. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1127. }
  1128. if (isset($caption['attribs']['']['lang']))
  1129. {
  1130. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1131. }
  1132. if (isset($caption['attribs']['']['start']))
  1133. {
  1134. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  1135. }
  1136. if (isset($caption['attribs']['']['end']))
  1137. {
  1138. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  1139. }
  1140. if (isset($caption['data']))
  1141. {
  1142. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1143. }
  1144. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  1145. }
  1146. }
  1147. if (is_array($captions_parent))
  1148. {
  1149. $captions_parent = array_values(array_unique($captions_parent));
  1150. }
  1151. // CATEGORIES
  1152. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  1153. {
  1154. $term = null;
  1155. $scheme = null;
  1156. $label = null;
  1157. if (isset($category['data']))
  1158. {
  1159. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1160. }
  1161. if (isset($category['attribs']['']['scheme']))
  1162. {
  1163. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1164. }
  1165. else
  1166. {
  1167. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  1168. }
  1169. if (isset($category['attribs']['']['label']))
  1170. {
  1171. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1172. }
  1173. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  1174. }
  1175. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  1176. {
  1177. $term = null;
  1178. $scheme = null;
  1179. $label = null;
  1180. if (isset($category['data']))
  1181. {
  1182. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1183. }
  1184. if (isset($category['attribs']['']['scheme']))
  1185. {
  1186. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1187. }
  1188. else
  1189. {
  1190. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  1191. }
  1192. if (isset($category['attribs']['']['label']))
  1193. {
  1194. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1195. }
  1196. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  1197. }
  1198. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'category') as $category)
  1199. {
  1200. $term = null;
  1201. $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
  1202. $label = null;
  1203. if (isset($category['attribs']['']['text']))
  1204. {
  1205. $label = $this->sanitize($category['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  1206. }
  1207. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  1208. if (isset($category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category']))
  1209. {
  1210. foreach ((array) $category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'] as $subcategory)
  1211. {
  1212. if (isset($subcategory['attribs']['']['text']))
  1213. {
  1214. $label = $this->sanitize($subcategory['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  1215. }
  1216. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  1217. }
  1218. }
  1219. }
  1220. if (is_array($categories_parent))
  1221. {
  1222. $categories_parent = array_values(array_unique($categories_parent));
  1223. }
  1224. // COPYRIGHT
  1225. if ($copyright = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  1226. {
  1227. $copyright_url = null;
  1228. $copyright_label = null;
  1229. if (isset($copyright[0]['attribs']['']['url']))
  1230. {
  1231. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  1232. }
  1233. if (isset($copyright[0]['data']))
  1234. {
  1235. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1236. }
  1237. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  1238. }
  1239. elseif ($copyright = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  1240. {
  1241. $copyright_url = null;
  1242. $copyright_label = null;
  1243. if (isset($copyright[0]['attribs']['']['url']))
  1244. {
  1245. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  1246. }
  1247. if (isset($copyright[0]['data']))
  1248. {
  1249. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1250. }
  1251. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  1252. }
  1253. // CREDITS
  1254. if ($credits = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  1255. {
  1256. foreach ($credits as $credit)
  1257. {
  1258. $credit_role = null;
  1259. $credit_scheme = null;
  1260. $credit_name = null;
  1261. if (isset($credit['attribs']['']['role']))
  1262. {
  1263. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  1264. }
  1265. if (isset($credit['attribs']['']['scheme']))
  1266. {
  1267. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1268. }
  1269. else
  1270. {
  1271. $credit_scheme = 'urn:ebu';
  1272. }
  1273. if (isset($credit['data']))
  1274. {
  1275. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1276. }
  1277. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  1278. }
  1279. }
  1280. elseif ($credits = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  1281. {
  1282. foreach ($credits as $credit)
  1283. {
  1284. $credit_role = null;
  1285. $credit_scheme = null;
  1286. $credit_name = null;
  1287. if (isset($credit['attribs']['']['role']))
  1288. {
  1289. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  1290. }
  1291. if (isset($credit['attribs']['']['scheme']))
  1292. {
  1293. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1294. }
  1295. else
  1296. {
  1297. $credit_scheme = 'urn:ebu';
  1298. }
  1299. if (isset($credit['data']))
  1300. {
  1301. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1302. }
  1303. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  1304. }
  1305. }
  1306. if (is_array($credits_parent))
  1307. {
  1308. $credits_parent = array_values(array_unique($credits_parent));
  1309. }
  1310. // DESCRIPTION
  1311. if ($description_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  1312. {
  1313. if (isset($description_parent[0]['data']))
  1314. {
  1315. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1316. }
  1317. }
  1318. elseif ($description_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  1319. {
  1320. if (isset($description_parent[0]['data']))
  1321. {
  1322. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1323. }
  1324. }
  1325. // DURATION
  1326. if ($duration_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'duration'))
  1327. {
  1328. $seconds = null;
  1329. $minutes = null;
  1330. $hours = null;
  1331. if (isset($duration_parent[0]['data']))
  1332. {
  1333. $temp = explode(':', $this->sanitize($duration_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1334. if (sizeof($temp) > 0)
  1335. {
  1336. $seconds = (int) array_pop($temp);
  1337. }
  1338. if (sizeof($temp) > 0)
  1339. {
  1340. $minutes = (int) array_pop($temp);
  1341. $seconds += $minutes * 60;
  1342. }
  1343. if (sizeof($temp) > 0)
  1344. {
  1345. $hours = (int) array_pop($temp);
  1346. $seconds += $hours * 3600;
  1347. }
  1348. unset($temp);
  1349. $duration_parent = $seconds;
  1350. }
  1351. }
  1352. // HASHES
  1353. if ($hashes_iterator = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  1354. {
  1355. foreach ($hashes_iterator as $hash)
  1356. {
  1357. $value = null;
  1358. $algo = null;
  1359. if (isset($hash['data']))
  1360. {
  1361. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1362. }
  1363. if (isset($hash['attribs']['']['algo']))
  1364. {
  1365. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  1366. }
  1367. else
  1368. {
  1369. $algo = 'md5';
  1370. }
  1371. $hashes_parent[] = $algo.':'.$value;
  1372. }
  1373. }
  1374. elseif ($hashes_iterator = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  1375. {
  1376. foreach ($hashes_iterator as $hash)
  1377. {
  1378. $value = null;
  1379. $algo = null;
  1380. if (isset($hash['data']))
  1381. {
  1382. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1383. }
  1384. if (isset($hash['attribs']['']['algo']))
  1385. {
  1386. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  1387. }
  1388. else
  1389. {
  1390. $algo = 'md5';
  1391. }
  1392. $hashes_parent[] = $algo.':'.$value;
  1393. }
  1394. }
  1395. if (is_array($hashes_parent))
  1396. {
  1397. $hashes_parent = array_values(array_unique($hashes_parent));
  1398. }
  1399. // KEYWORDS
  1400. if ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  1401. {
  1402. if (isset($keywords[0]['data']))
  1403. {
  1404. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1405. foreach ($temp as $word)
  1406. {
  1407. $keywords_parent[] = trim($word);
  1408. }
  1409. }
  1410. unset($temp);
  1411. }
  1412. elseif ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  1413. {
  1414. if (isset($keywords[0]['data']))
  1415. {
  1416. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1417. foreach ($temp as $word)
  1418. {
  1419. $keywords_parent[] = trim($word);
  1420. }
  1421. }
  1422. unset($temp);
  1423. }
  1424. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  1425. {
  1426. if (isset($keywords[0]['data']))
  1427. {
  1428. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1429. foreach ($temp as $word)
  1430. {
  1431. $keywords_parent[] = trim($word);
  1432. }
  1433. }
  1434. unset($temp);
  1435. }
  1436. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  1437. {
  1438. if (isset($keywords[0]['data']))
  1439. {
  1440. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1441. foreach ($temp as $word)
  1442. {
  1443. $keywords_parent[] = trim($word);
  1444. }
  1445. }
  1446. unset($temp);
  1447. }
  1448. if (is_array($keywords_parent))
  1449. {
  1450. $keywords_parent = array_values(array_unique($keywords_parent));
  1451. }
  1452. // PLAYER
  1453. if ($player_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  1454. {
  1455. if (isset($player_parent[0]['attribs']['']['url']))
  1456. {
  1457. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1458. }
  1459. }
  1460. elseif ($player_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  1461. {
  1462. if (isset($player_parent[0]['attribs']['']['url']))
  1463. {
  1464. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1465. }
  1466. }
  1467. // RATINGS
  1468. if ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  1469. {
  1470. foreach ($ratings as $rating)
  1471. {
  1472. $rating_scheme = null;
  1473. $rating_value = null;
  1474. if (isset($rating['attribs']['']['scheme']))
  1475. {
  1476. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1477. }
  1478. else
  1479. {
  1480. $rating_scheme = 'urn:simple';
  1481. }
  1482. if (isset($rating['data']))
  1483. {
  1484. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1485. }
  1486. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1487. }
  1488. }
  1489. elseif ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  1490. {
  1491. foreach ($ratings as $rating)
  1492. {
  1493. $rating_scheme = 'urn:itunes';
  1494. $rating_value = null;
  1495. if (isset($rating['data']))
  1496. {
  1497. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1498. }
  1499. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1500. }
  1501. }
  1502. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  1503. {
  1504. foreach ($ratings as $rating)
  1505. {
  1506. $rating_scheme = null;
  1507. $rating_value = null;
  1508. if (isset($rating['attribs']['']['scheme']))
  1509. {
  1510. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1511. }
  1512. else
  1513. {
  1514. $rating_scheme = 'urn:simple';
  1515. }
  1516. if (isset($rating['data']))
  1517. {
  1518. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1519. }
  1520. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1521. }
  1522. }
  1523. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  1524. {
  1525. foreach ($ratings as $rating)
  1526. {
  1527. $rating_scheme = 'urn:itunes';
  1528. $rating_value = null;
  1529. if (isset($rating['data']))
  1530. {
  1531. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1532. }
  1533. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1534. }
  1535. }
  1536. if (is_array($ratings_parent))
  1537. {
  1538. $ratings_parent = array_values(array_unique($ratings_parent));
  1539. }
  1540. // RESTRICTIONS
  1541. if ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  1542. {
  1543. foreach ($restrictions as $restriction)
  1544. {
  1545. $restriction_relationship = null;
  1546. $restriction_type = null;
  1547. $restriction_value = null;
  1548. if (isset($restriction['attribs']['']['relationship']))
  1549. {
  1550. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  1551. }
  1552. if (isset($restriction['attribs']['']['type']))
  1553. {
  1554. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1555. }
  1556. if (isset($restriction['data']))
  1557. {
  1558. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1559. }
  1560. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  1561. }
  1562. }
  1563. elseif ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  1564. {
  1565. foreach ($restrictions as $restriction)
  1566. {
  1567. $restriction_relationship = 'allow';
  1568. $restriction_type = null;
  1569. $restriction_value = 'itunes';
  1570. if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
  1571. {
  1572. $restriction_relationship = 'deny';
  1573. }
  1574. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  1575. }
  1576. }
  1577. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  1578. {
  1579. foreach ($restrictions as $restriction)
  1580. {
  1581. $restriction_relationship = null;
  1582. $restriction_type = null;
  1583. $restriction_value = null;
  1584. if (isset($restriction['attribs']['']['relationship']))
  1585. {
  1586. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  1587. }
  1588. if (isset($restriction['attribs']['']['type']))
  1589. {
  1590. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1591. }
  1592. if (isset($restriction['data']))
  1593. {
  1594. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1595. }
  1596. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  1597. }
  1598. }
  1599. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  1600. {
  1601. foreach ($restrictions as $restriction)
  1602. {
  1603. $restriction_relationship = 'allow';
  1604. $restriction_type = null;
  1605. $restriction_value = 'itunes';
  1606. if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
  1607. {
  1608. $restriction_relationship = 'deny';
  1609. }
  1610. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  1611. }
  1612. }
  1613. if (is_array($restrictions_parent))
  1614. {
  1615. $restrictions_parent = array_values(array_unique($restrictions_parent));
  1616. }
  1617. else
  1618. {
  1619. $restrictions_parent = array(new SimplePie_Restriction('allow', null, 'default'));
  1620. }
  1621. // THUMBNAILS
  1622. if ($thumbnails = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  1623. {
  1624. foreach ($thumbnails as $thumbnail)
  1625. {
  1626. if (isset($thumbnail['attribs']['']['url']))
  1627. {
  1628. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1629. }
  1630. }
  1631. }
  1632. elseif ($thumbnails = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  1633. {
  1634. foreach ($thumbnails as $thumbnail)
  1635. {
  1636. if (isset($thumbnail['attribs']['']['url']))
  1637. {
  1638. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1639. }
  1640. }
  1641. }
  1642. // TITLES
  1643. if ($title_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  1644. {
  1645. if (isset($title_parent[0]['data']))
  1646. {
  1647. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1648. }
  1649. }
  1650. elseif ($title_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  1651. {
  1652. if (isset($title_parent[0]['data']))
  1653. {
  1654. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1655. }
  1656. }
  1657. // Clear the memory
  1658. unset($parent);
  1659. // Attributes
  1660. $bitrate = null;
  1661. $channels = null;
  1662. $duration = null;
  1663. $expression = null;
  1664. $framerate = null;
  1665. $height = null;
  1666. $javascript = null;
  1667. $lang = null;
  1668. $length = null;
  1669. $medium = null;
  1670. $samplingrate = null;
  1671. $type = null;
  1672. $url = null;
  1673. $width = null;
  1674. // Elements
  1675. $captions = null;
  1676. $categories = null;
  1677. $copyrights = null;
  1678. $credits = null;
  1679. $description = null;
  1680. $hashes = null;
  1681. $keywords = null;
  1682. $player = null;
  1683. $ratings = null;
  1684. $restrictions = null;
  1685. $thumbnails = null;
  1686. $title = null;
  1687. // If we have media:group tags, loop through them.
  1688. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group') as $group)
  1689. {
  1690. if(isset($group['child']) && isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
  1691. {
  1692. // If we have media:content tags, loop through them.
  1693. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
  1694. {
  1695. if (isset($content['attribs']['']['url']))
  1696. {
  1697. // Attributes
  1698. $bitrate = null;
  1699. $channels = null;
  1700. $duration = null;
  1701. $expression = null;
  1702. $framerate = null;
  1703. $height = null;
  1704. $javascript = null;
  1705. $lang = null;
  1706. $length = null;
  1707. $medium = null;
  1708. $samplingrate = null;
  1709. $type = null;
  1710. $url = null;
  1711. $width = null;
  1712. // Elements
  1713. $captions = null;
  1714. $categories = null;
  1715. $copyrights = null;
  1716. $credits = null;
  1717. $description = null;
  1718. $hashes = null;
  1719. $keywords = null;
  1720. $player = null;
  1721. $ratings = null;
  1722. $restrictions = null;
  1723. $thumbnails = null;
  1724. $title = null;
  1725. // Start checking the attributes of media:content
  1726. if (isset($content['attribs']['']['bitrate']))
  1727. {
  1728. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  1729. }
  1730. if (isset($content['attribs']['']['channels']))
  1731. {
  1732. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  1733. }
  1734. if (isset($content['attribs']['']['duration']))
  1735. {
  1736. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  1737. }
  1738. else
  1739. {
  1740. $duration = $duration_parent;
  1741. }
  1742. if (isset($content['attribs']['']['expression']))
  1743. {
  1744. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  1745. }
  1746. if (isset($content['attribs']['']['framerate']))
  1747. {
  1748. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  1749. }
  1750. if (isset($content['attribs']['']['height']))
  1751. {
  1752. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  1753. }
  1754. if (isset($content['attribs']['']['lang']))
  1755. {
  1756. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1757. }
  1758. if (isset($content['attribs']['']['fileSize']))
  1759. {
  1760. $length = ceil($content['attribs']['']['fileSize']);
  1761. }
  1762. if (isset($content['attribs']['']['medium']))
  1763. {
  1764. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  1765. }
  1766. if (isset($content['attribs']['']['samplingrate']))
  1767. {
  1768. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  1769. }
  1770. if (isset($content['attribs']['']['type']))
  1771. {
  1772. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1773. }
  1774. if (isset($content['attribs']['']['width']))
  1775. {
  1776. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  1777. }
  1778. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1779. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  1780. // CAPTIONS
  1781. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  1782. {
  1783. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  1784. {
  1785. $caption_type = null;
  1786. $caption_lang = null;
  1787. $caption_startTime = null;
  1788. $caption_endTime = null;
  1789. $caption_text = null;
  1790. if (isset($caption['attribs']['']['type']))
  1791. {
  1792. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1793. }
  1794. if (isset($caption['attribs']['']['lang']))
  1795. {
  1796. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1797. }
  1798. if (isset($caption['attribs']['']['start']))
  1799. {
  1800. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  1801. }
  1802. if (isset($caption['attribs']['']['end']))
  1803. {
  1804. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  1805. }
  1806. if (isset($caption['data']))
  1807. {
  1808. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1809. }
  1810. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  1811. }
  1812. if (is_array($captions))
  1813. {
  1814. $captions = array_values(array_unique($captions));
  1815. }
  1816. }
  1817. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  1818. {
  1819. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  1820. {
  1821. $caption_type = null;
  1822. $caption_lang = null;
  1823. $caption_startTime = null;
  1824. $caption_endTime = null;
  1825. $caption_text = null;
  1826. if (isset($caption['attribs']['']['type']))
  1827. {
  1828. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1829. }
  1830. if (isset($caption['attribs']['']['lang']))
  1831. {
  1832. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1833. }
  1834. if (isset($caption['attribs']['']['start']))
  1835. {
  1836. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  1837. }
  1838. if (isset($caption['attribs']['']['end']))
  1839. {
  1840. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  1841. }
  1842. if (isset($caption['data']))
  1843. {
  1844. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1845. }
  1846. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  1847. }
  1848. if (is_array($captions))
  1849. {
  1850. $captions = array_values(array_unique($captions));
  1851. }
  1852. }
  1853. else
  1854. {
  1855. $captions = $captions_parent;
  1856. }
  1857. // CATEGORIES
  1858. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  1859. {
  1860. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  1861. {
  1862. $term = null;
  1863. $scheme = null;
  1864. $label = null;
  1865. if (isset($category['data']))
  1866. {
  1867. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1868. }
  1869. if (isset($category['attribs']['']['scheme']))
  1870. {
  1871. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1872. }
  1873. else
  1874. {
  1875. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  1876. }
  1877. if (isset($category['attribs']['']['label']))
  1878. {
  1879. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1880. }
  1881. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  1882. }
  1883. }
  1884. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  1885. {
  1886. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  1887. {
  1888. $term = null;
  1889. $scheme = null;
  1890. $label = null;
  1891. if (isset($category['data']))
  1892. {
  1893. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1894. }
  1895. if (isset($category['attribs']['']['scheme']))
  1896. {
  1897. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1898. }
  1899. else
  1900. {
  1901. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  1902. }
  1903. if (isset($category['attribs']['']['label']))
  1904. {
  1905. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1906. }
  1907. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  1908. }
  1909. }
  1910. if (is_array($categories) && is_array($categories_parent))
  1911. {
  1912. $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
  1913. }
  1914. elseif (is_array($categories))
  1915. {
  1916. $categories = array_values(array_unique($categories));
  1917. }
  1918. elseif (is_array($categories_parent))
  1919. {
  1920. $categories = array_values(array_unique($categories_parent));
  1921. }
  1922. // COPYRIGHTS
  1923. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  1924. {
  1925. $copyright_url = null;
  1926. $copyright_label = null;
  1927. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  1928. {
  1929. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  1930. }
  1931. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  1932. {
  1933. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1934. }
  1935. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  1936. }
  1937. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  1938. {
  1939. $copyright_url = null;
  1940. $copyright_label = null;
  1941. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  1942. {
  1943. $copyright_url = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  1944. }
  1945. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  1946. {
  1947. $copyright_label = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1948. }
  1949. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  1950. }
  1951. else
  1952. {
  1953. $copyrights = $copyrights_parent;
  1954. }
  1955. // CREDITS
  1956. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  1957. {
  1958. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  1959. {
  1960. $credit_role = null;
  1961. $credit_scheme = null;
  1962. $credit_name = null;
  1963. if (isset($credit['attribs']['']['role']))
  1964. {
  1965. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  1966. }
  1967. if (isset($credit['attribs']['']['scheme']))
  1968. {
  1969. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1970. }
  1971. else
  1972. {
  1973. $credit_scheme = 'urn:ebu';
  1974. }
  1975. if (isset($credit['data']))
  1976. {
  1977. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1978. }
  1979. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  1980. }
  1981. if (is_array($credits))
  1982. {
  1983. $credits = array_values(array_unique($credits));
  1984. }
  1985. }
  1986. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  1987. {
  1988. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  1989. {
  1990. $credit_role = null;
  1991. $credit_scheme = null;
  1992. $credit_name = null;
  1993. if (isset($credit['attribs']['']['role']))
  1994. {
  1995. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  1996. }
  1997. if (isset($credit['attribs']['']['scheme']))
  1998. {
  1999. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2000. }
  2001. else
  2002. {
  2003. $credit_scheme = 'urn:ebu';
  2004. }
  2005. if (isset($credit['data']))
  2006. {
  2007. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2008. }
  2009. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  2010. }
  2011. if (is_array($credits))
  2012. {
  2013. $credits = array_values(array_unique($credits));
  2014. }
  2015. }
  2016. else
  2017. {
  2018. $credits = $credits_parent;
  2019. }
  2020. // DESCRIPTION
  2021. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  2022. {
  2023. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2024. }
  2025. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  2026. {
  2027. $description = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2028. }
  2029. else
  2030. {
  2031. $description = $description_parent;
  2032. }
  2033. // HASHES
  2034. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  2035. {
  2036. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  2037. {
  2038. $value = null;
  2039. $algo = null;
  2040. if (isset($hash['data']))
  2041. {
  2042. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2043. }
  2044. if (isset($hash['attribs']['']['algo']))
  2045. {
  2046. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  2047. }
  2048. else
  2049. {
  2050. $algo = 'md5';
  2051. }
  2052. $hashes[] = $algo.':'.$value;
  2053. }
  2054. if (is_array($hashes))
  2055. {
  2056. $hashes = array_values(array_unique($hashes));
  2057. }
  2058. }
  2059. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  2060. {
  2061. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  2062. {
  2063. $value = null;
  2064. $algo = null;
  2065. if (isset($hash['data']))
  2066. {
  2067. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2068. }
  2069. if (isset($hash['attribs']['']['algo']))
  2070. {
  2071. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  2072. }
  2073. else
  2074. {
  2075. $algo = 'md5';
  2076. }
  2077. $hashes[] = $algo.':'.$value;
  2078. }
  2079. if (is_array($hashes))
  2080. {
  2081. $hashes = array_values(array_unique($hashes));
  2082. }
  2083. }
  2084. else
  2085. {
  2086. $hashes = $hashes_parent;
  2087. }
  2088. // KEYWORDS
  2089. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  2090. {
  2091. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  2092. {
  2093. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  2094. foreach ($temp as $word)
  2095. {
  2096. $keywords[] = trim($word);
  2097. }
  2098. unset($temp);
  2099. }
  2100. if (is_array($keywords))
  2101. {
  2102. $keywords = array_values(array_unique($keywords));
  2103. }
  2104. }
  2105. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  2106. {
  2107. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  2108. {
  2109. $temp = explode(',', $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  2110. foreach ($temp as $word)
  2111. {
  2112. $keywords[] = trim($word);
  2113. }
  2114. unset($temp);
  2115. }
  2116. if (is_array($keywords))
  2117. {
  2118. $keywords = array_values(array_unique($keywords));
  2119. }
  2120. }
  2121. else
  2122. {
  2123. $keywords = $keywords_parent;
  2124. }
  2125. // PLAYER
  2126. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  2127. {
  2128. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2129. }
  2130. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  2131. {
  2132. $player = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2133. }
  2134. else
  2135. {
  2136. $player = $player_parent;
  2137. }
  2138. // RATINGS
  2139. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  2140. {
  2141. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  2142. {
  2143. $rating_scheme = null;
  2144. $rating_value = null;
  2145. if (isset($rating['attribs']['']['scheme']))
  2146. {
  2147. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2148. }
  2149. else
  2150. {
  2151. $rating_scheme = 'urn:simple';
  2152. }
  2153. if (isset($rating['data']))
  2154. {
  2155. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2156. }
  2157. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  2158. }
  2159. if (is_array($ratings))
  2160. {
  2161. $ratings = array_values(array_unique($ratings));
  2162. }
  2163. }
  2164. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  2165. {
  2166. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  2167. {
  2168. $rating_scheme = null;
  2169. $rating_value = null;
  2170. if (isset($rating['attribs']['']['scheme']))
  2171. {
  2172. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2173. }
  2174. else
  2175. {
  2176. $rating_scheme = 'urn:simple';
  2177. }
  2178. if (isset($rating['data']))
  2179. {
  2180. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2181. }
  2182. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  2183. }
  2184. if (is_array($ratings))
  2185. {
  2186. $ratings = array_values(array_unique($ratings));
  2187. }
  2188. }
  2189. else
  2190. {
  2191. $ratings = $ratings_parent;
  2192. }
  2193. // RESTRICTIONS
  2194. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  2195. {
  2196. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  2197. {
  2198. $restriction_relationship = null;
  2199. $restriction_type = null;
  2200. $restriction_value = null;
  2201. if (isset($restriction['attribs']['']['relationship']))
  2202. {
  2203. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  2204. }
  2205. if (isset($restriction['attribs']['']['type']))
  2206. {
  2207. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2208. }
  2209. if (isset($restriction['data']))
  2210. {
  2211. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2212. }
  2213. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  2214. }
  2215. if (is_array($restrictions))
  2216. {
  2217. $restrictions = array_values(array_unique($restrictions));
  2218. }
  2219. }
  2220. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  2221. {
  2222. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  2223. {
  2224. $restriction_relationship = null;
  2225. $restriction_type = null;
  2226. $restriction_value = null;
  2227. if (isset($restriction['attribs']['']['relationship']))
  2228. {
  2229. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  2230. }
  2231. if (isset($restriction['attribs']['']['type']))
  2232. {
  2233. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2234. }
  2235. if (isset($restriction['data']))
  2236. {
  2237. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2238. }
  2239. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  2240. }
  2241. if (is_array($restrictions))
  2242. {
  2243. $restrictions = array_values(array_unique($restrictions));
  2244. }
  2245. }
  2246. else
  2247. {
  2248. $restrictions = $restrictions_parent;
  2249. }
  2250. // THUMBNAILS
  2251. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  2252. {
  2253. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  2254. {
  2255. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2256. }
  2257. if (is_array($thumbnails))
  2258. {
  2259. $thumbnails = array_values(array_unique($thumbnails));
  2260. }
  2261. }
  2262. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  2263. {
  2264. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  2265. {
  2266. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2267. }
  2268. if (is_array($thumbnails))
  2269. {
  2270. $thumbnails = array_values(array_unique($thumbnails));
  2271. }
  2272. }
  2273. else
  2274. {
  2275. $thumbnails = $thumbnails_parent;
  2276. }
  2277. // TITLES
  2278. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  2279. {
  2280. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2281. }
  2282. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  2283. {
  2284. $title = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2285. }
  2286. else
  2287. {
  2288. $title = $title_parent;
  2289. }
  2290. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width));
  2291. }
  2292. }
  2293. }
  2294. }
  2295. // If we have standalone media:content tags, loop through them.
  2296. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
  2297. {
  2298. foreach ((array) $this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
  2299. {
  2300. if (isset($content['attribs']['']['url']) || isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  2301. {
  2302. // Attributes
  2303. $bitrate = null;
  2304. $channels = null;
  2305. $duration = null;
  2306. $expression = null;
  2307. $framerate = null;
  2308. $height = null;
  2309. $javascript = null;
  2310. $lang = null;
  2311. $length = null;
  2312. $medium = null;
  2313. $samplingrate = null;
  2314. $type = null;
  2315. $url = null;
  2316. $width = null;
  2317. // Elements
  2318. $captions = null;
  2319. $categories = null;
  2320. $copyrights = null;
  2321. $credits = null;
  2322. $description = null;
  2323. $hashes = null;
  2324. $keywords = null;
  2325. $player = null;
  2326. $ratings = null;
  2327. $restrictions = null;
  2328. $thumbnails = null;
  2329. $title = null;
  2330. // Start checking the attributes of media:content
  2331. if (isset($content['attribs']['']['bitrate']))
  2332. {
  2333. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  2334. }
  2335. if (isset($content['attribs']['']['channels']))
  2336. {
  2337. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  2338. }
  2339. if (isset($content['attribs']['']['duration']))
  2340. {
  2341. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  2342. }
  2343. else
  2344. {
  2345. $duration = $duration_parent;
  2346. }
  2347. if (isset($content['attribs']['']['expression']))
  2348. {
  2349. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  2350. }
  2351. if (isset($content['attribs']['']['framerate']))
  2352. {
  2353. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  2354. }
  2355. if (isset($content['attribs']['']['height']))
  2356. {
  2357. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  2358. }
  2359. if (isset($content['attribs']['']['lang']))
  2360. {
  2361. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2362. }
  2363. if (isset($content['attribs']['']['fileSize']))
  2364. {
  2365. $length = ceil($content['attribs']['']['fileSize']);
  2366. }
  2367. if (isset($content['attribs']['']['medium']))
  2368. {
  2369. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  2370. }
  2371. if (isset($content['attribs']['']['samplingrate']))
  2372. {
  2373. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  2374. }
  2375. if (isset($content['attribs']['']['type']))
  2376. {
  2377. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2378. }
  2379. if (isset($content['attribs']['']['width']))
  2380. {
  2381. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  2382. }
  2383. if (isset($content['attribs']['']['url']))
  2384. {
  2385. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2386. }
  2387. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  2388. // CAPTIONS
  2389. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  2390. {
  2391. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  2392. {
  2393. $caption_type = null;
  2394. $caption_lang = null;
  2395. $caption_startTime = null;
  2396. $caption_endTime = null;
  2397. $caption_text = null;
  2398. if (isset($caption['attribs']['']['type']))
  2399. {
  2400. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2401. }
  2402. if (isset($caption['attribs']['']['lang']))
  2403. {
  2404. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2405. }
  2406. if (isset($caption['attribs']['']['start']))
  2407. {
  2408. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  2409. }
  2410. if (isset($caption['attribs']['']['end']))
  2411. {
  2412. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  2413. }
  2414. if (isset($caption['data']))
  2415. {
  2416. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2417. }
  2418. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  2419. }
  2420. if (is_array($captions))
  2421. {
  2422. $captions = array_values(array_unique($captions));
  2423. }
  2424. }
  2425. else
  2426. {
  2427. $captions = $captions_parent;
  2428. }
  2429. // CATEGORIES
  2430. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  2431. {
  2432. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  2433. {
  2434. $term = null;
  2435. $scheme = null;
  2436. $label = null;
  2437. if (isset($category['data']))
  2438. {
  2439. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2440. }
  2441. if (isset($category['attribs']['']['scheme']))
  2442. {
  2443. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2444. }
  2445. else
  2446. {
  2447. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  2448. }
  2449. if (isset($category['attribs']['']['label']))
  2450. {
  2451. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  2452. }
  2453. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  2454. }
  2455. }
  2456. if (is_array($categories) && is_array($categories_parent))
  2457. {
  2458. $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
  2459. }
  2460. elseif (is_array($categories))
  2461. {
  2462. $categories = array_values(array_unique($categories));
  2463. }
  2464. elseif (is_array($categories_parent))
  2465. {
  2466. $categories = array_values(array_unique($categories_parent));
  2467. }
  2468. else
  2469. {
  2470. $categories = null;
  2471. }
  2472. // COPYRIGHTS
  2473. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  2474. {
  2475. $copyright_url = null;
  2476. $copyright_label = null;
  2477. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  2478. {
  2479. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  2480. }
  2481. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  2482. {
  2483. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2484. }
  2485. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  2486. }
  2487. else
  2488. {
  2489. $copyrights = $copyrights_parent;
  2490. }
  2491. // CREDITS
  2492. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  2493. {
  2494. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  2495. {
  2496. $credit_role = null;
  2497. $credit_scheme = null;
  2498. $credit_name = null;
  2499. if (isset($credit['attribs']['']['role']))
  2500. {
  2501. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  2502. }
  2503. if (isset($credit['attribs']['']['scheme']))
  2504. {
  2505. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2506. }
  2507. else
  2508. {
  2509. $credit_scheme = 'urn:ebu';
  2510. }
  2511. if (isset($credit['data']))
  2512. {
  2513. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2514. }
  2515. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  2516. }
  2517. if (is_array($credits))
  2518. {
  2519. $credits = array_values(array_unique($credits));
  2520. }
  2521. }
  2522. else
  2523. {
  2524. $credits = $credits_parent;
  2525. }
  2526. // DESCRIPTION
  2527. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  2528. {
  2529. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2530. }
  2531. else
  2532. {
  2533. $description = $description_parent;
  2534. }
  2535. // HASHES
  2536. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  2537. {
  2538. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  2539. {
  2540. $value = null;
  2541. $algo = null;
  2542. if (isset($hash['data']))
  2543. {
  2544. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2545. }
  2546. if (isset($hash['attribs']['']['algo']))
  2547. {
  2548. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  2549. }
  2550. else
  2551. {
  2552. $algo = 'md5';
  2553. }
  2554. $hashes[] = $algo.':'.$value;
  2555. }
  2556. if (is_array($hashes))
  2557. {
  2558. $hashes = array_values(array_unique($hashes));
  2559. }
  2560. }
  2561. else
  2562. {
  2563. $hashes = $hashes_parent;
  2564. }
  2565. // KEYWORDS
  2566. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  2567. {
  2568. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  2569. {
  2570. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  2571. foreach ($temp as $word)
  2572. {
  2573. $keywords[] = trim($word);
  2574. }
  2575. unset($temp);
  2576. }
  2577. if (is_array($keywords))
  2578. {
  2579. $keywords = array_values(array_unique($keywords));
  2580. }
  2581. }
  2582. else
  2583. {
  2584. $keywords = $keywords_parent;
  2585. }
  2586. // PLAYER
  2587. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  2588. {
  2589. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2590. }
  2591. else
  2592. {
  2593. $player = $player_parent;
  2594. }
  2595. // RATINGS
  2596. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  2597. {
  2598. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  2599. {
  2600. $rating_scheme = null;
  2601. $rating_value = null;
  2602. if (isset($rating['attribs']['']['scheme']))
  2603. {
  2604. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2605. }
  2606. else
  2607. {
  2608. $rating_scheme = 'urn:simple';
  2609. }
  2610. if (isset($rating['data']))
  2611. {
  2612. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2613. }
  2614. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  2615. }
  2616. if (is_array($ratings))
  2617. {
  2618. $ratings = array_values(array_unique($ratings));
  2619. }
  2620. }
  2621. else
  2622. {
  2623. $ratings = $ratings_parent;
  2624. }
  2625. // RESTRICTIONS
  2626. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  2627. {
  2628. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  2629. {
  2630. $restriction_relationship = null;
  2631. $restriction_type = null;
  2632. $restriction_value = null;
  2633. if (isset($restriction['attribs']['']['relationship']))
  2634. {
  2635. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  2636. }
  2637. if (isset($restriction['attribs']['']['type']))
  2638. {
  2639. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2640. }
  2641. if (isset($restriction['data']))
  2642. {
  2643. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2644. }
  2645. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  2646. }
  2647. if (is_array($restrictions))
  2648. {
  2649. $restrictions = array_values(array_unique($restrictions));
  2650. }
  2651. }
  2652. else
  2653. {
  2654. $restrictions = $restrictions_parent;
  2655. }
  2656. // THUMBNAILS
  2657. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  2658. {
  2659. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  2660. {
  2661. if (isset($thumbnail['attribs']['']['url'])) {
  2662. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2663. }
  2664. }
  2665. if (is_array($thumbnails))
  2666. {
  2667. $thumbnails = array_values(array_unique($thumbnails));
  2668. }
  2669. }
  2670. else
  2671. {
  2672. $thumbnails = $thumbnails_parent;
  2673. }
  2674. // TITLES
  2675. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  2676. {
  2677. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2678. }
  2679. else
  2680. {
  2681. $title = $title_parent;
  2682. }
  2683. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width));
  2684. }
  2685. }
  2686. }
  2687. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  2688. {
  2689. if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure')
  2690. {
  2691. // Attributes
  2692. $bitrate = null;
  2693. $channels = null;
  2694. $duration = null;
  2695. $expression = null;
  2696. $framerate = null;
  2697. $height = null;
  2698. $javascript = null;
  2699. $lang = null;
  2700. $length = null;
  2701. $medium = null;
  2702. $samplingrate = null;
  2703. $type = null;
  2704. $url = null;
  2705. $width = null;
  2706. $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  2707. if (isset($link['attribs']['']['type']))
  2708. {
  2709. $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2710. }
  2711. if (isset($link['attribs']['']['length']))
  2712. {
  2713. $length = ceil($link['attribs']['']['length']);
  2714. }
  2715. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  2716. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width));
  2717. }
  2718. }
  2719. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
  2720. {
  2721. if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure')
  2722. {
  2723. // Attributes
  2724. $bitrate = null;
  2725. $channels = null;
  2726. $duration = null;
  2727. $expression = null;
  2728. $framerate = null;
  2729. $height = null;
  2730. $javascript = null;
  2731. $lang = null;
  2732. $length = null;
  2733. $medium = null;
  2734. $samplingrate = null;
  2735. $type = null;
  2736. $url = null;
  2737. $width = null;
  2738. $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  2739. if (isset($link['attribs']['']['type']))
  2740. {
  2741. $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2742. }
  2743. if (isset($link['attribs']['']['length']))
  2744. {
  2745. $length = ceil($link['attribs']['']['length']);
  2746. }
  2747. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  2748. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width));
  2749. }
  2750. }
  2751. if ($enclosure = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'enclosure'))
  2752. {
  2753. if (isset($enclosure[0]['attribs']['']['url']))
  2754. {
  2755. // Attributes
  2756. $bitrate = null;
  2757. $channels = null;
  2758. $duration = null;
  2759. $expression = null;
  2760. $framerate = null;
  2761. $height = null;
  2762. $javascript = null;
  2763. $lang = null;
  2764. $length = null;
  2765. $medium = null;
  2766. $samplingrate = null;
  2767. $type = null;
  2768. $url = null;
  2769. $width = null;
  2770. $url = $this->sanitize($enclosure[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($enclosure[0]));
  2771. if (isset($enclosure[0]['attribs']['']['type']))
  2772. {
  2773. $type = $this->sanitize($enclosure[0]['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2774. }
  2775. if (isset($enclosure[0]['attribs']['']['length']))
  2776. {
  2777. $length = ceil($enclosure[0]['attribs']['']['length']);
  2778. }
  2779. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  2780. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width));
  2781. }
  2782. }
  2783. if (sizeof($this->data['enclosures']) === 0 && ($url || $type || $length || $bitrate || $captions_parent || $categories_parent || $channels || $copyrights_parent || $credits_parent || $description_parent || $duration_parent || $expression || $framerate || $hashes_parent || $height || $keywords_parent || $lang || $medium || $player_parent || $ratings_parent || $restrictions_parent || $samplingrate || $thumbnails_parent || $title_parent || $width))
  2784. {
  2785. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  2786. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width));
  2787. }
  2788. $this->data['enclosures'] = array_values(array_unique($this->data['enclosures']));
  2789. }
  2790. if (!empty($this->data['enclosures']))
  2791. {
  2792. return $this->data['enclosures'];
  2793. }
  2794. else
  2795. {
  2796. return null;
  2797. }
  2798. }
  2799. /**
  2800. * Get the latitude coordinates for the item
  2801. *
  2802. * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
  2803. *
  2804. * Uses `<geo:lat>` or `<georss:point>`
  2805. *
  2806. * @since 1.0
  2807. * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
  2808. * @link http://www.georss.org/ GeoRSS
  2809. * @return string|null
  2810. */
  2811. public function get_latitude()
  2812. {
  2813. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  2814. {
  2815. return (float) $return[0]['data'];
  2816. }
  2817. elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  2818. {
  2819. return (float) $match[1];
  2820. }
  2821. else
  2822. {
  2823. return null;
  2824. }
  2825. }
  2826. /**
  2827. * Get the longitude coordinates for the item
  2828. *
  2829. * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
  2830. *
  2831. * Uses `<geo:long>`, `<geo:lon>` or `<georss:point>`
  2832. *
  2833. * @since 1.0
  2834. * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
  2835. * @link http://www.georss.org/ GeoRSS
  2836. * @return string|null
  2837. */
  2838. public function get_longitude()
  2839. {
  2840. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  2841. {
  2842. return (float) $return[0]['data'];
  2843. }
  2844. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  2845. {
  2846. return (float) $return[0]['data'];
  2847. }
  2848. elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  2849. {
  2850. return (float) $match[2];
  2851. }
  2852. else
  2853. {
  2854. return null;
  2855. }
  2856. }
  2857. /**
  2858. * Get the `<atom:source>` for the item
  2859. *
  2860. * @since 1.1
  2861. * @return SimplePie_Source|null
  2862. */
  2863. public function get_source()
  2864. {
  2865. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'source'))
  2866. {
  2867. return $this->registry->create('Source', array($this, $return[0]));
  2868. }
  2869. else
  2870. {
  2871. return null;
  2872. }
  2873. }
  2874. }