Item.php 97 KB

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