Item.php 98 KB

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