Item.php 97 KB

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