Item.php 97 KB

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