A tumblelog CMS built on AJAX, PHP and MySQL.

simplepie.class.php 164KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549
  1. <?php
  2. /****************************************************
  3. SIMPLEPIE
  4. A PHP-Based RSS and Atom Feed Framework
  5. Takes the hard work out of managing a complete RSS/Atom solution.
  6. Version: "Lemon Meringue"
  7. Updated: 24 November 2006
  8. Copyright: 2004-2006 Ryan Parman, Geoffrey Sneddon
  9. http://simplepie.org
  10. *****************************************************
  11. LICENSE:
  12. GNU Lesser General Public License 2.1 (LGPL)
  13. http://creativecommons.org/licenses/LGPL/2.1/
  14. *****************************************************
  15. Please submit all bug reports and feature requests to the SimplePie forums.
  16. http://simplepie.org/support/
  17. ****************************************************/
  18. class SimplePie
  19. {
  20. // SimplePie Info
  21. public $name = 'SimplePie';
  22. public $version = '1.0 b3.2';
  23. public $build = '20061124';
  24. public $url = 'http://simplepie.org/';
  25. public $useragent;
  26. public $linkback;
  27. // Other objects, instances created here so we can set options on them
  28. public $sanitize;
  29. // Options
  30. public $rss_url;
  31. public $file;
  32. public $timeout = 10;
  33. public $xml_dump = false;
  34. public $enable_cache = true;
  35. public $max_minutes = 60;
  36. public $cache_location = './cache';
  37. public $order_by_date = true;
  38. public $input_encoding = false;
  39. public $cache_class = 'SimplePie_Cache';
  40. public $locator_class = 'SimplePie_Locator';
  41. public $parser_class = 'SimplePie_Parser';
  42. public $file_class = 'SimplePie_File';
  43. public $force_fsockopen = false;
  44. public $cache_name_type = 'sha1';
  45. // Misc. variables
  46. public $data;
  47. public $error;
  48. public function __construct($feed_url = null, $cache_location = null, $cache_max_minutes = null)
  49. {
  50. // Couple of variables built up from other variables
  51. $this->useragent = $this->name . '/' . $this->version . ' (Feed Parser; ' . $this->url . '; Allow like Gecko) Build/' . $this->build;
  52. $this->linkback = '<a href="' . $this->url . '" title="' . $this->name . ' ' . $this->version . '">' . $this->name . '</a>';
  53. // Other objects, instances created here so we can set options on them
  54. $this->sanitize = new SimplePie_Sanitize;
  55. // Set options if they're passed to the constructor
  56. if (!is_null($feed_url)) {
  57. $this->feed_url($feed_url);
  58. }
  59. if (!is_null($cache_location)) {
  60. $this->cache_location($cache_location);
  61. }
  62. if (!is_null($cache_max_minutes)) {
  63. $this->cache_max_minutes($cache_max_minutes);
  64. }
  65. // If we've passed an xmldump variable in the URL, snap into XMLdump mode
  66. if (isset($_GET['xmldump'])) {
  67. $this->enable_xmldump(true);
  68. }
  69. // Only init the script if we're passed a feed URL
  70. if (!is_null($feed_url)) {
  71. return $this->init();
  72. }
  73. }
  74. public function feed_url($url)
  75. {
  76. $this->rss_url = (new SimplePie_Misc)->fix_protocol($url, 1);
  77. }
  78. public function set_file(&$file)
  79. {
  80. if (is_a($file, 'SimplePie_File')) {
  81. $this->rss_url = $file->url;
  82. $this->file =& $file;
  83. }
  84. }
  85. public function set_timeout($timeout = 10)
  86. {
  87. $this->timeout = (int) $timeout;
  88. }
  89. public function set_raw_data($data)
  90. {
  91. $this->raw_data = trim((string) $data);
  92. }
  93. public function enable_xmldump($enable = false)
  94. {
  95. $this->xml_dump = (bool) $enable;
  96. }
  97. public function enable_caching($enable = true)
  98. {
  99. $this->enable_cache = (bool) $enable;
  100. }
  101. public function cache_max_minutes($minutes = 60)
  102. {
  103. $this->max_minutes = (float) $minutes;
  104. }
  105. public function cache_location($location = './cache')
  106. {
  107. $this->cache_location = (string) $location;
  108. }
  109. public function order_by_date($enable = true)
  110. {
  111. $this->order_by_date = (bool) $enable;
  112. }
  113. public function input_encoding($encoding = false)
  114. {
  115. if ($encoding) {
  116. $this->input_encoding = (string) $encoding;
  117. } else {
  118. $this->input_encoding = false;
  119. }
  120. }
  121. public function set_cache_class($class = 'SimplePie_Cache')
  122. {
  123. if ((new SimplePie_Misc)->is_a_class($class, 'SimplePie_Cache')) {
  124. $this->cache_class = $class;
  125. return true;
  126. }
  127. return false;
  128. }
  129. public function set_locator_class($class = 'SimplePie_Locator')
  130. {
  131. if ((new SimplePie_Misc)->is_a_class($class, 'SimplePie_Locator')) {
  132. $this->locator_class = $class;
  133. return true;
  134. }
  135. return false;
  136. }
  137. public function set_parser_class($class = 'SimplePie_Parser')
  138. {
  139. if ((new SimplePie_Misc)->is_a_class($class, 'SimplePie_Parser')) {
  140. $this->parser_class = $class;
  141. return true;
  142. }
  143. return false;
  144. }
  145. public function set_file_class($class = 'SimplePie_File')
  146. {
  147. if ((new SimplePie_Misc)->is_a_class($class, 'SimplePie_File')) {
  148. $this->file_class = $class;
  149. return true;
  150. }
  151. return false;
  152. }
  153. public function set_sanitize_class($object = 'SimplePie_Sanitize')
  154. {
  155. if (class_exists($object)) {
  156. $this->sanitize = new $object;
  157. return true;
  158. }
  159. return false;
  160. }
  161. public function set_useragent($ua)
  162. {
  163. $this->useragent = (string) $ua;
  164. }
  165. public function force_fsockopen($enable = false)
  166. {
  167. $this->force_fsockopen = (bool) $enable;
  168. }
  169. public function set_cache_name_type($type = 'sha1')
  170. {
  171. $type = strtolower(trim($type));
  172. switch ($type) {
  173. case 'crc32':
  174. $this->cache_name_type = 'crc32';
  175. break;
  176. case 'md5':
  177. $this->cache_name_type = 'md5';
  178. break;
  179. case 'rawurlencode':
  180. $this->cache_name_type = 'rawurlencode';
  181. break;
  182. case 'urlencode':
  183. $this->cache_name_type = 'urlencode';
  184. break;
  185. default:
  186. $this->cache_name_type = 'sha1';
  187. break;
  188. }
  189. }
  190. public function bypass_image_hotlink($get = false)
  191. {
  192. $this->sanitize->bypass_image_hotlink($get);
  193. }
  194. public function bypass_image_hotlink_page($page = false)
  195. {
  196. $this->sanitize->bypass_image_hotlink_page($page);
  197. }
  198. public function replace_headers($enable = false)
  199. {
  200. $this->sanitize->replace_headers($enable);
  201. }
  202. public function remove_div($enable = true)
  203. {
  204. $this->sanitize->remove_div($enable);
  205. }
  206. public function strip_ads($enable = false)
  207. {
  208. $this->sanitize->strip_ads($enable);
  209. }
  210. public function strip_htmltags($tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'), $encode = null)
  211. {
  212. $this->sanitize->strip_htmltags($tags);
  213. if (!is_null($encode)) {
  214. $this->sanitize->encode_instead_of_strip($tags);
  215. }
  216. }
  217. public function encode_instead_of_strip($enable = true)
  218. {
  219. $this->sanitize->encode_instead_of_strip($enable);
  220. }
  221. public function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur'))
  222. {
  223. $this->sanitize->strip_attributes($attribs);
  224. }
  225. public function output_encoding($encoding = 'UTF-8')
  226. {
  227. $this->sanitize->output_encoding($encoding);
  228. }
  229. public function set_item_class($class = 'SimplePie_Item')
  230. {
  231. return $this->sanitize->set_item_class($class);
  232. }
  233. public function set_author_class($class = 'SimplePie_Author')
  234. {
  235. return $this->sanitize->set_author_class($class);
  236. }
  237. public function set_enclosure_class($class = 'SimplePie_Enclosure')
  238. {
  239. return $this->sanitize->set_enclosure_class($class);
  240. }
  241. public function init()
  242. {
  243. if (!(function_exists('version_compare') && ((version_compare(phpversion(), '4.3.2', '>=') && version_compare(phpversion(), '5', '<')) || version_compare(phpversion(), '5.0.3', '>='))) || !extension_loaded('xml') || !extension_loaded('pcre')) {
  244. return false;
  245. }
  246. if ($this->sanitize->bypass_image_hotlink && !empty($_GET[$this->sanitize->bypass_image_hotlink])) {
  247. if (get_magic_quotes_gpc()) {
  248. $_GET[$this->sanitize->bypass_image_hotlink] = stripslashes($_GET[$this->sanitize->bypass_image_hotlink]);
  249. }
  250. (new SimplePie_Misc)->display_file($_GET[$this->sanitize->bypass_image_hotlink], 10, $this->useragent);
  251. }
  252. if (isset($_GET['js'])) {
  253. $embed = <<<EOT
  254. function embed_odeo(link) {
  255. document.writeln('<embed src="http://odeo.com/flash/audio_player_fullsize.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="440" height="80" wmode="transparent" allowScriptAccess="any" flashvars="valid_sample_rate=true&external_url='+link+'"></embed>');
  256. }
  257. function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {
  258. if (placeholder != '') {
  259. document.writeln('<embed type="'+type+'" style="cursor:hand; cursor:pointer;" href="'+link+'" src="'+placeholder+'" width="'+width+'" height="'+height+'" autoplay="false" target="myself" controller="false" loop="'+loop+'" scale="aspect" bgcolor="'+bgcolor+'" pluginspage="http://www.apple.com/quicktime/download/"></embed>');
  260. }
  261. else {
  262. document.writeln('<embed type="'+type+'" style="cursor:hand; cursor:pointer;" src="'+link+'" width="'+width+'" height="'+height+'" autoplay="false" target="myself" controller="true" loop="'+loop+'" scale="aspect" bgcolor="'+bgcolor+'" pluginspage="http://www.apple.com/quicktime/download/"></embed>');
  263. }
  264. }
  265. function embed_flash(bgcolor, width, height, link, loop, type) {
  266. document.writeln('<embed src="'+link+'" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="'+type+'" quality="high" width="'+width+'" height="'+height+'" bgcolor="'+bgcolor+'" loop="'+loop+'"></embed>');
  267. }
  268. function embed_wmedia(width, height, link) {
  269. document.writeln('<embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>');
  270. }
  271. EOT;
  272. if (function_exists('ob_gzhandler')) {
  273. ob_start('ob_gzhandler');
  274. }
  275. header('Content-type: text/javascript; charset: UTF-8');
  276. header('Cache-Control: must-revalidate');
  277. header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 86400) . ' GMT');
  278. echo $embed;
  279. exit;
  280. }
  281. if (!empty($this->rss_url) || !empty($this->raw_data)) {
  282. $this->data = array();
  283. $cache = false;
  284. if (!empty($this->rss_url)) {
  285. // Decide whether to enable caching
  286. if ($this->enable_cache && preg_match('/^http(s)?:\/\//i', $this->rss_url)) {
  287. $cache = new $this->cache_class($this->cache_location, call_user_func($this->cache_name_type, $this->rss_url), 'spc');
  288. }
  289. // If it's enabled and we don't want an XML dump, use the cache
  290. if ($cache && !$this->xml_dump) {
  291. // Load the Cache
  292. $this->data = $cache->load();
  293. if (!empty($this->data)) {
  294. // If we've hit a collision just rerun it with caching disabled
  295. if (isset($this->data['url']) && $this->data['url'] != $this->rss_url) {
  296. $cache = false;
  297. }
  298. // If we've got a feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL
  299. elseif (!empty($this->data['feed_url'])) {
  300. if ($this->data['feed_url'] == $this->data['url']) {
  301. $cache->unlink();
  302. } else {
  303. $this->feed_url($this->data['feed_url']);
  304. return $this->init();
  305. }
  306. }
  307. // If the cache is new enough
  308. elseif ($cache->mtime() + $this->max_minutes * 60 < time()) {
  309. // If we have last-modified and/or etag set
  310. if (!empty($this->data['last-modified']) || !empty($this->data['etag'])) {
  311. $headers = array();
  312. if (!empty($this->data['last-modified'])) {
  313. $headers['if-modified-since'] = $this->data['last-modified'];
  314. }
  315. if (!empty($this->data['etag'])) {
  316. $headers['if-none-match'] = $this->data['etag'];
  317. }
  318. $file = new $this->file_class($this->rss_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen);
  319. if ($file->success) {
  320. $headers = $file->headers();
  321. if ($headers['status']['code'] == 304) {
  322. $cache->touch();
  323. return true;
  324. }
  325. } else {
  326. unset($file);
  327. }
  328. }
  329. // If we don't have last-modified or etag set, just clear the cache
  330. else {
  331. $cache->unlink();
  332. }
  333. }
  334. // If the cache is still valid, just return true
  335. else {
  336. return true;
  337. }
  338. }
  339. // If the cache is empty, delete it
  340. else {
  341. $cache->unlink();
  342. }
  343. }
  344. $this->data = array();
  345. // If we don't already have the file (it'll only exist if we've opened it to check if the cache has been modified), open it.
  346. if (!isset($file)) {
  347. if (is_a($this->file, 'SimplePie_File') && $this->file->url == $this->rss_url) {
  348. $file =& $this->file;
  349. } else {
  350. $file = new $this->file_class($this->rss_url, $this->timeout, 5, null, $this->useragent, $this->force_fsockopen);
  351. }
  352. }
  353. // If the file connection has an error, set SimplePie::error to that and quit
  354. if (!$file->success) {
  355. $this->error = $file->error;
  356. return false;
  357. }
  358. // Check if the supplied URL is a feed, if it isn't, look for it.
  359. $locate = new $this->locator_class($file, $this->timeout, $this->useragent);
  360. if (!$locate->is_feed($file)) {
  361. $feed = $locate->find();
  362. if ($feed) {
  363. if ($cache && !$cache->save(array('url' => $this->rss_url, 'feed_url' => $feed))) {
  364. $this->error = "$cache->name is not writeable";
  365. (new SimplePie_Misc)->error($this->error, E_USER_WARNING, __FILE__, __LINE__);
  366. }
  367. $this->rss_url = $feed;
  368. return $this->init();
  369. } else {
  370. $this->error = "A feed could not be found at $this->rss_url";
  371. (new SimplePie_Misc)->error($this->error, E_USER_WARNING, __FILE__, __LINE__);
  372. return false;
  373. }
  374. }
  375. $headers = $file->headers();
  376. $data = trim($file->body());
  377. $file->close();
  378. unset($file);
  379. } else {
  380. $data = $this->raw_data;
  381. }
  382. // First check to see if input has been overridden.
  383. if (!empty($this->input_encoding)) {
  384. $encoding = $this->input_encoding;
  385. }
  386. // Second try HTTP headers
  387. elseif (!empty($headers['content-type']) && preg_match('/charset\s*=\s*([^;]*)/i', $headers['content-type'], $charset)) {
  388. $encoding = $charset[1];
  389. }
  390. // Then prolog, if at the very start of the document
  391. elseif (preg_match('/^<\?xml(.*)?>/msiU', $data, $prolog) && preg_match('/encoding\s*=\s*("([^"]*)"|\'([^\']*)\')/Ui', $prolog[1], $encoding)) {
  392. $encoding = substr($encoding[1], 1, -1);
  393. }
  394. // UTF-32 Big Endian BOM
  395. elseif (strpos($data, sprintf('%c%c%c%c', 0x00, 0x00, 0xFE, 0xFF)) === 0) {
  396. $encoding = 'UTF-32be';
  397. }
  398. // UTF-32 Little Endian BOM
  399. elseif (strpos($data, sprintf('%c%c%c%c', 0xFF, 0xFE, 0x00, 0x00)) === 0) {
  400. $encoding = 'UTF-32';
  401. }
  402. // UTF-16 Big Endian BOM
  403. elseif (strpos($data, sprintf('%c%c', 0xFE, 0xFF)) === 0) {
  404. $encoding = 'UTF-16be';
  405. }
  406. // UTF-16 Little Endian BOM
  407. elseif (strpos($data, sprintf('%c%c', 0xFF, 0xFE)) === 0) {
  408. $encoding = 'UTF-16le';
  409. }
  410. // UTF-8 BOM
  411. elseif (strpos($data, sprintf('%c%c%c', 0xEF, 0xBB, 0xBF)) === 0) {
  412. $encoding = 'UTF-8';
  413. }
  414. // Fallback to the default
  415. else {
  416. $encoding = null;
  417. }
  418. // Change the encoding to UTF-8 (as we always use UTF-8 internally)
  419. $data = (new SimplePie_Misc)->change_encoding($data, $encoding, 'UTF-8');
  420. // Strip illegal characters (if on less than PHP5, as on PHP5 expat can manage fine)
  421. if (version_compare(phpversion(), '5', '<')) {
  422. if (function_exists('iconv')) {
  423. $data = iconv('UTF-8', 'UTF-8//IGNORE', $data);
  424. } elseif (function_exists('mb_convert_encoding')) {
  425. $data = mb_convert_encoding($data, 'UTF-8', 'UTF-8');
  426. } else {
  427. $data = (new SimplePie_Misc)->utf8_bad_replace($data);
  428. }
  429. }
  430. // Start parsing
  431. $data = new $this->parser_class($data, 'UTF-8', $this->xml_dump);
  432. // If we want the XML, just output that and quit
  433. if ($this->xml_dump) {
  434. header('Content-type: text/xml; charset=UTF-8');
  435. echo $data->data;
  436. exit;
  437. }
  438. // If it's parsed fine
  439. elseif (!$data->error_code) {
  440. // Parse the data, and make it sane
  441. $this->sanitize->parse_data_array($data->data, $this->rss_url);
  442. unset($data);
  443. // Get the sane data
  444. $this->data['feedinfo'] = $this->sanitize->feedinfo;
  445. unset($this->sanitize->feedinfo);
  446. $this->data['info'] = $this->sanitize->info;
  447. unset($this->sanitize->info);
  448. $this->data['items'] = $this->sanitize->items;
  449. unset($this->sanitize->items);
  450. $this->data['feedinfo']['encoding'] = $this->sanitize->output_encoding;
  451. $this->data['url'] = $this->rss_url;
  452. // Store the headers that we need
  453. if (!empty($headers['last-modified'])) {
  454. $this->data['last-modified'] = $headers['last-modified'];
  455. }
  456. if (!empty($headers['etag'])) {
  457. $this->data['etag'] = $headers['etag'];
  458. }
  459. // If we want to order it by date, check if all items have a date, and then sort it
  460. if ($this->order_by_date && !empty($this->data['items'])) {
  461. $do_sort = true;
  462. foreach ($this->data['items'] as $item) {
  463. if (!$item->get_date('U')) {
  464. $do_sort = false;
  465. break;
  466. }
  467. }
  468. if ($do_sort) {
  469. usort($this->data['items'], create_function('$a, $b', 'if ($a->get_date(\'U\') == $b->get_date(\'U\')) return 1; return ($a->get_date(\'U\') < $b->get_date(\'U\')) ? 1 : -1;'));
  470. }
  471. }
  472. // Cache the file if caching is enabled
  473. if ($cache && !$cache->save($this->data)) {
  474. $this->error = "$cache->name is not writeable";
  475. (new SimplePie_Misc)->error($this->error, E_USER_WARNING, __FILE__, __LINE__);
  476. }
  477. return true;
  478. }
  479. // If we have an error, just set SimplePie::error to it and quit
  480. else {
  481. $this->error = "XML error: $data->error_string at line $data->current_line, column $data->current_column";
  482. (new SimplePie_Misc)->error($this->error, E_USER_WARNING, __FILE__, __LINE__);
  483. return false;
  484. }
  485. }
  486. }
  487. public function get_encoding()
  488. {
  489. if (!empty($this->data['feedinfo']['encoding'])) {
  490. return $this->data['feedinfo']['encoding'];
  491. } else {
  492. return false;
  493. }
  494. }
  495. public function handle_content_type($mime = 'text/html')
  496. {
  497. if (!headers_sent()) {
  498. $header = "Content-type: $mime;";
  499. if ($this->get_encoding()) {
  500. $header .= ' charset=' . $this->get_encoding();
  501. } else {
  502. $header .= ' charset=UTF-8';
  503. }
  504. header($header);
  505. }
  506. }
  507. public function get_type()
  508. {
  509. if (!empty($this->data['feedinfo']['type'])) {
  510. return $this->data['feedinfo']['type'];
  511. } else {
  512. return false;
  513. }
  514. }
  515. public function get_version()
  516. {
  517. if (!empty($this->data['feedinfo']['version'])) {
  518. return $this->data['feedinfo']['version'];
  519. } else {
  520. return false;
  521. }
  522. }
  523. public function get_favicon($check = false, $alternate = null)
  524. {
  525. if (!empty($this->data['info']['link']['alternate'][0])) {
  526. $favicon = (new SimplePie_Misc)->absolutize_url('/favicon.ico', $this->get_feed_link());
  527. if ($check) {
  528. $file = new $this->file_class($favicon, $this->timeout/10, 5, null, $this->useragent, $this->force_fsockopen);
  529. $headers = $file->headers();
  530. $file->close();
  531. if ($headers['status']['code'] == 200) {
  532. return $favicon;
  533. }
  534. } else {
  535. return $favicon;
  536. }
  537. }
  538. if (!is_null($alternate)) {
  539. return $alternate;
  540. } else {
  541. return false;
  542. }
  543. }
  544. public function subscribe_url()
  545. {
  546. if (!empty($this->rss_url)) {
  547. return $this->rss_url;
  548. } else {
  549. return false;
  550. }
  551. }
  552. public function subscribe_feed()
  553. {
  554. if (!empty($this->rss_url)) {
  555. return (new SimplePie_Misc)->fix_protocol($this->rss_url, 2);
  556. } else {
  557. return false;
  558. }
  559. }
  560. public function subscribe_outlook()
  561. {
  562. if (!empty($this->rss_url)) {
  563. return 'outlook' . (new SimplePie_Misc)->fix_protocol($this->rss_url, 2);
  564. } else {
  565. return false;
  566. }
  567. }
  568. public function subscribe_podcast()
  569. {
  570. if (!empty($this->rss_url)) {
  571. return (new SimplePie_Misc)->fix_protocol($this->rss_url, 3);
  572. } else {
  573. return false;
  574. }
  575. }
  576. public function subscribe_aol()
  577. {
  578. if ($this->subscribe_url()) {
  579. return 'http://feeds.my.aol.com/add.jsp?url=' . rawurlencode($this->subscribe_url());
  580. } else {
  581. return false;
  582. }
  583. }
  584. public function subscribe_bloglines()
  585. {
  586. if ($this->subscribe_url()) {
  587. return 'http://www.bloglines.com/sub/' . rawurlencode($this->subscribe_url());
  588. } else {
  589. return false;
  590. }
  591. }
  592. public function subscribe_eskobo()
  593. {
  594. if ($this->subscribe_url()) {
  595. return 'http://www.eskobo.com/?AddToMyPage=' . rawurlencode($this->subscribe_url());
  596. } else {
  597. return false;
  598. }
  599. }
  600. public function subscribe_feedfeeds()
  601. {
  602. if ($this->subscribe_url()) {
  603. return 'http://www.feedfeeds.com/add?feed=' . rawurlencode($this->subscribe_url());
  604. } else {
  605. return false;
  606. }
  607. }
  608. public function subscribe_feedlounge()
  609. {
  610. if ($this->subscribe_url()) {
  611. return 'http://my.feedlounge.com/external/subscribe?url=' . rawurlencode($this->subscribe_url());
  612. } else {
  613. return false;
  614. }
  615. }
  616. public function subscribe_feedster()
  617. {
  618. if ($this->subscribe_url()) {
  619. return 'http://www.feedster.com/myfeedster.php?action=addrss&amp;confirm=no&amp;rssurl=' . rawurlencode($this->subscribe_url());
  620. } else {
  621. return false;
  622. }
  623. }
  624. public function subscribe_google()
  625. {
  626. if ($this->subscribe_url()) {
  627. return 'http://fusion.google.com/add?feedurl=' . rawurlencode($this->subscribe_url());
  628. } else {
  629. return false;
  630. }
  631. }
  632. public function subscribe_gritwire()
  633. {
  634. if ($this->subscribe_url()) {
  635. return 'http://my.gritwire.com/feeds/addExternalFeed.aspx?FeedUrl=' . rawurlencode($this->subscribe_url());
  636. } else {
  637. return false;
  638. }
  639. }
  640. public function subscribe_msn()
  641. {
  642. if ($this->subscribe_url()) {
  643. $url = 'http://my.msn.com/addtomymsn.armx?id=rss&amp;ut=' . rawurlencode($this->subscribe_url());
  644. if ($this->get_feed_link()) {
  645. $url .= '&amp;ru=' . rawurlencode($this->get_feed_link());
  646. }
  647. return $url;
  648. } else {
  649. return false;
  650. }
  651. }
  652. public function subscribe_netvibes()
  653. {
  654. if ($this->subscribe_url()) {
  655. return 'http://www.netvibes.com/subscribe.php?url=' . rawurlencode($this->subscribe_url());
  656. } else {
  657. return false;
  658. }
  659. }
  660. public function subscribe_newsburst()
  661. {
  662. if ($this->subscribe_url()) {
  663. return 'http://www.newsburst.com/Source/?add=' . rawurlencode($this->subscribe_url());
  664. } else {
  665. return false;
  666. }
  667. }
  668. public function subscribe_newsgator()
  669. {
  670. if ($this->subscribe_url()) {
  671. return 'http://www.newsgator.com/ngs/subscriber/subext.aspx?url=' . rawurlencode($this->subscribe_url());
  672. } else {
  673. return false;
  674. }
  675. }
  676. public function subscribe_odeo()
  677. {
  678. if ($this->subscribe_url()) {
  679. return 'http://www.odeo.com/listen/subscribe?feed=' . rawurlencode($this->subscribe_url());
  680. } else {
  681. return false;
  682. }
  683. }
  684. public function subscribe_pluck()
  685. {
  686. if ($this->subscribe_url()) {
  687. return 'http://client.pluck.com/pluckit/prompt.aspx?GCID=C12286x053&amp;a=' . rawurlencode($this->subscribe_url());
  688. } else {
  689. return false;
  690. }
  691. }
  692. public function subscribe_podnova()
  693. {
  694. if ($this->subscribe_url()) {
  695. return 'http://www.podnova.com/index_your_podcasts.srf?action=add&amp;url=' . rawurlencode($this->subscribe_url());
  696. } else {
  697. return false;
  698. }
  699. }
  700. public function subscribe_rojo()
  701. {
  702. if ($this->subscribe_url()) {
  703. return 'http://www.rojo.com/add-subscription?resource=' . rawurlencode($this->subscribe_url());
  704. } else {
  705. return false;
  706. }
  707. }
  708. public function subscribe_yahoo()
  709. {
  710. if ($this->subscribe_url()) {
  711. return 'http://add.my.yahoo.com/rss?url=' . rawurlencode($this->subscribe_url());
  712. } else {
  713. return false;
  714. }
  715. }
  716. public function get_feed_title()
  717. {
  718. if (!empty($this->data['info']['title'])) {
  719. return $this->data['info']['title'];
  720. } else {
  721. return false;
  722. }
  723. }
  724. public function get_feed_link()
  725. {
  726. if (!empty($this->data['info']['link']['alternate'][0])) {
  727. return $this->data['info']['link']['alternate'][0];
  728. } else {
  729. return false;
  730. }
  731. }
  732. public function get_feed_links()
  733. {
  734. if (!empty($this->data['info']['link'])) {
  735. return $this->data['info']['link'];
  736. } else {
  737. return false;
  738. }
  739. }
  740. public function get_feed_description()
  741. {
  742. if (!empty($this->data['info']['description'])) {
  743. return $this->data['info']['description'];
  744. } elseif (!empty($this->data['info']['dc:description'])) {
  745. return $this->data['info']['dc:description'];
  746. } elseif (!empty($this->data['info']['tagline'])) {
  747. return $this->data['info']['tagline'];
  748. } elseif (!empty($this->data['info']['subtitle'])) {
  749. return $this->data['info']['subtitle'];
  750. } else {
  751. return false;
  752. }
  753. }
  754. public function get_feed_copyright()
  755. {
  756. if (!empty($this->data['info']['copyright'])) {
  757. return $this->data['info']['copyright'];
  758. } else {
  759. return false;
  760. }
  761. }
  762. public function get_feed_language()
  763. {
  764. if (!empty($this->data['info']['language'])) {
  765. return $this->data['info']['language'];
  766. } elseif (!empty($this->data['info']['xml:lang'])) {
  767. return $this->data['info']['xml:lang'];
  768. } else {
  769. return false;
  770. }
  771. }
  772. public function get_image_exist()
  773. {
  774. if (!empty($this->data['info']['image']['url']) || !empty($this->data['info']['image']['logo'])) {
  775. return true;
  776. } else {
  777. return false;
  778. }
  779. }
  780. public function get_image_title()
  781. {
  782. if (!empty($this->data['info']['image']['title'])) {
  783. return $this->data['info']['image']['title'];
  784. } else {
  785. return false;
  786. }
  787. }
  788. public function get_image_url()
  789. {
  790. if (!empty($this->data['info']['image']['url'])) {
  791. return $this->data['info']['image']['url'];
  792. } elseif (!empty($this->data['info']['image']['logo'])) {
  793. return $this->data['info']['image']['logo'];
  794. } else {
  795. return false;
  796. }
  797. }
  798. public function get_image_link()
  799. {
  800. if (!empty($this->data['info']['image']['link'])) {
  801. return $this->data['info']['image']['link'];
  802. } else {
  803. return false;
  804. }
  805. }
  806. public function get_image_width()
  807. {
  808. if (!empty($this->data['info']['image']['width'])) {
  809. return $this->data['info']['image']['width'];
  810. } else {
  811. return false;
  812. }
  813. }
  814. public function get_image_height()
  815. {
  816. if (!empty($this->data['info']['image']['height'])) {
  817. return $this->data['info']['image']['height'];
  818. } else {
  819. return false;
  820. }
  821. }
  822. public function get_item_quantity($max = 0)
  823. {
  824. if (!empty($this->data['items'])) {
  825. $qty = sizeof($this->data['items']);
  826. } else {
  827. $qty = 0;
  828. }
  829. if ($max == 0) {
  830. return $qty;
  831. } else {
  832. return ($qty > $max) ? $max : $qty;
  833. }
  834. }
  835. public function get_item($key = 0)
  836. {
  837. if (!empty($this->data['items'][$key])) {
  838. return $this->data['items'][$key];
  839. } else {
  840. return false;
  841. }
  842. }
  843. public function get_items($start = 0, $end = 0)
  844. {
  845. if ($this->get_item_quantity() > 0) {
  846. if ($end == 0) {
  847. return array_slice($this->data['items'], $start);
  848. } else {
  849. return array_slice($this->data['items'], $start, $end);
  850. }
  851. } else {
  852. return false;
  853. }
  854. }
  855. }
  856. class SimplePie_Item
  857. {
  858. public $data;
  859. public function __construct($data)
  860. {
  861. $this->data =& $data;
  862. }
  863. public function get_id()
  864. {
  865. if (!empty($this->data['guid']['data'])) {
  866. return $this->data['guid']['data'];
  867. } elseif (!empty($this->data['id'])) {
  868. return $this->data['id'];
  869. } else {
  870. return false;
  871. }
  872. }
  873. public function get_title()
  874. {
  875. if (!empty($this->data['title'])) {
  876. return $this->data['title'];
  877. } elseif (!empty($this->data['dc:title'])) {
  878. return $this->data['dc:title'];
  879. } else {
  880. return false;
  881. }
  882. }
  883. public function get_description()
  884. {
  885. if (!empty($this->data['content'])) {
  886. return $this->data['content'];
  887. } elseif (!empty($this->data['encoded'])) {
  888. return $this->data['encoded'];
  889. } elseif (!empty($this->data['summary'])) {
  890. return $this->data['summary'];
  891. } elseif (!empty($this->data['description'])) {
  892. return $this->data['description'];
  893. } elseif (!empty($this->data['dc:description'])) {
  894. return $this->data['dc:description'];
  895. } elseif (!empty($this->data['longdesc'])) {
  896. return $this->data['longdesc'];
  897. } else {
  898. return false;
  899. }
  900. }
  901. public function get_category($key = 0)
  902. {
  903. $categories = $this->get_categories();
  904. if (!empty($categories[$key])) {
  905. return $categories[$key];
  906. } else {
  907. return false;
  908. }
  909. }
  910. public function get_categories()
  911. {
  912. $categories = array();
  913. if (!empty($this->data['category'])) {
  914. $categories = array_merge($categories, $this->data['category']);
  915. }
  916. if (!empty($this->data['subject'])) {
  917. $categories = array_merge($categories, $this->data['subject']);
  918. }
  919. if (!empty($this->data['term'])) {
  920. $categories = array_merge($categories, $this->data['term']);
  921. }
  922. if (!empty($categories)) {
  923. return array_unique($categories);
  924. } else {
  925. return false;
  926. }
  927. }
  928. public function get_author($key = 0)
  929. {
  930. $authors = $this->get_authors();
  931. if (!empty($authors[$key])) {
  932. return $authors[$key];
  933. } else {
  934. return false;
  935. }
  936. }
  937. public function get_authors()
  938. {
  939. $authors = array();
  940. if (!empty($this->data['author'])) {
  941. $authors = array_merge($authors, $this->data['author']);
  942. }
  943. if (!empty($this->data['creator'])) {
  944. $authors = array_merge($authors, $this->data['creator']);
  945. }
  946. if (!empty($authors)) {
  947. return array_unique($authors);
  948. } else {
  949. return false;
  950. }
  951. }
  952. public function get_date($date_format = 'j F Y, g:i a')
  953. {
  954. if (!empty($this->data['pubdate'])) {
  955. return date($date_format, $this->data['pubdate']);
  956. } elseif (!empty($this->data['dc:date'])) {
  957. return date($date_format, $this->data['dc:date']);
  958. } elseif (!empty($this->data['issued'])) {
  959. return date($date_format, $this->data['issued']);
  960. } elseif (!empty($this->data['published'])) {
  961. return date($date_format, $this->data['published']);
  962. } elseif (!empty($this->data['modified'])) {
  963. return date($date_format, $this->data['modified']);
  964. } elseif (!empty($this->data['updated'])) {
  965. return date($date_format, $this->data['updated']);
  966. } else {
  967. return false;
  968. }
  969. }
  970. public function get_permalink()
  971. {
  972. $link = $this->get_link(0);
  973. $enclosure = $this->get_enclosure(0);
  974. if (!empty($link)) {
  975. return $link;
  976. } elseif (!empty($enclosure)) {
  977. return $enclosure->get_link();
  978. } else {
  979. return false;
  980. }
  981. }
  982. public function get_link($key = 0, $rel = 'alternate')
  983. {
  984. $links = $this->get_links($rel);
  985. if (!empty($links[$key])) {
  986. return $links[$key];
  987. } else {
  988. return false;
  989. }
  990. }
  991. public function get_links($rel = 'alternate')
  992. {
  993. if ($rel == 'alternate') {
  994. $links = array();
  995. if (!empty($this->data['link'][$rel])) {
  996. $links = $this->data['link'][$rel];
  997. }
  998. if (!empty($this->data['guid']['data']) && $this->data['guid']['permalink'] == true) {
  999. $links[] = $this->data['guid']['data'];
  1000. }
  1001. return $links;
  1002. } elseif (!empty($this->data['link'][$rel])) {
  1003. return $this->data['link'][$rel];
  1004. } else {
  1005. return false;
  1006. }
  1007. }
  1008. public function get_enclosure($key = 0)
  1009. {
  1010. $enclosures = $this->get_enclosures();
  1011. if (!empty($enclosures[$key])) {
  1012. return $enclosures[$key];
  1013. } else {
  1014. return false;
  1015. }
  1016. }
  1017. public function get_enclosures()
  1018. {
  1019. $enclosures = array();
  1020. $links = $this->get_links('enclosure');
  1021. if (!empty($this->data['enclosures'])) {
  1022. $enclosures = array_merge($enclosures, $this->data['enclosures']);
  1023. }
  1024. if (!empty($links)) {
  1025. $enclosures = array_merge($enclosures, $links);
  1026. }
  1027. if (!empty($enclosures)) {
  1028. return array_unique($enclosures);
  1029. } else {
  1030. return false;
  1031. }
  1032. }
  1033. public function add_to_blinklist()
  1034. {
  1035. if ($this->get_permalink()) {
  1036. $url = 'http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=' . rawurlencode($this->get_permalink());
  1037. if ($this->get_title()) {
  1038. $url .= '&amp;Title=' . rawurlencode($this->get_title());
  1039. }
  1040. return $url;
  1041. } else {
  1042. return false;
  1043. }
  1044. }
  1045. public function add_to_blogmarks()
  1046. {
  1047. if ($this->get_permalink()) {
  1048. $url = 'http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=' . rawurlencode($this->get_permalink());
  1049. if ($this->get_title()) {
  1050. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1051. }
  1052. return $url;
  1053. } else {
  1054. return false;
  1055. }
  1056. }
  1057. public function add_to_delicious()
  1058. {
  1059. if ($this->get_permalink()) {
  1060. $url = 'http://del.icio.us/post/?v=3&amp;url=' . rawurlencode($this->get_permalink());
  1061. if ($this->get_title()) {
  1062. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1063. }
  1064. return $url;
  1065. } else {
  1066. return false;
  1067. }
  1068. }
  1069. public function add_to_digg()
  1070. {
  1071. if ($this->get_permalink()) {
  1072. return 'http://digg.com/submit?phase=2&amp;URL=' . rawurlencode($this->get_permalink());
  1073. } else {
  1074. return false;
  1075. }
  1076. }
  1077. public function add_to_furl()
  1078. {
  1079. if ($this->get_permalink()) {
  1080. $url = 'http://www.furl.net/storeIt.jsp?u=' . rawurlencode($this->get_permalink());
  1081. if ($this->get_title()) {
  1082. $url .= '&amp;t=' . rawurlencode($this->get_title());
  1083. }
  1084. return $url;
  1085. } else {
  1086. return false;
  1087. }
  1088. }
  1089. public function add_to_magnolia()
  1090. {
  1091. if ($this->get_permalink()) {
  1092. $url = 'http://ma.gnolia.com/bookmarklet/add?url=' . rawurlencode($this->get_permalink());
  1093. if ($this->get_title()) {
  1094. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1095. }
  1096. return $url;
  1097. } else {
  1098. return false;
  1099. }
  1100. }
  1101. public function add_to_myweb20()
  1102. {
  1103. if ($this->get_permalink()) {
  1104. $url = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=' . rawurlencode($this->get_permalink());
  1105. if ($this->get_title()) {
  1106. $url .= '&amp;t=' . rawurlencode($this->get_title());
  1107. }
  1108. return $url;
  1109. } else {
  1110. return false;
  1111. }
  1112. }
  1113. public function add_to_newsvine()
  1114. {
  1115. if ($this->get_permalink()) {
  1116. $url = 'http://www.newsvine.com/_wine/save?u=' . rawurlencode($this->get_permalink());
  1117. if ($this->get_title()) {
  1118. $url .= '&amp;h=' . rawurlencode($this->get_title());
  1119. }
  1120. return $url;
  1121. } else {
  1122. return false;
  1123. }
  1124. }
  1125. public function add_to_reddit()
  1126. {
  1127. if ($this->get_permalink()) {
  1128. $url = 'http://reddit.com/submit?url=' . rawurlencode($this->get_permalink());
  1129. if ($this->get_title()) {
  1130. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1131. }
  1132. return $url;
  1133. } else {
  1134. return false;
  1135. }
  1136. }
  1137. public function add_to_segnalo()
  1138. {
  1139. if ($this->get_permalink()) {
  1140. $url = 'http://segnalo.com/post.html.php?url=' . rawurlencode($this->get_permalink());
  1141. if ($this->get_title()) {
  1142. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1143. }
  1144. return $url;
  1145. } else {
  1146. return false;
  1147. }
  1148. }
  1149. public function add_to_simpy()
  1150. {
  1151. if ($this->get_permalink()) {
  1152. $url = 'http://www.simpy.com/simpy/LinkAdd.do?href=' . rawurlencode($this->get_permalink());
  1153. if ($this->get_title()) {
  1154. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1155. }
  1156. return $url;
  1157. } else {
  1158. return false;
  1159. }
  1160. }
  1161. public function add_to_smarking()
  1162. {
  1163. if ($this->get_permalink()) {
  1164. return 'http://smarking.com/editbookmark/?url=' . rawurlencode($this->get_permalink());
  1165. } else {
  1166. return false;
  1167. }
  1168. }
  1169. public function add_to_spurl()
  1170. {
  1171. if ($this->get_permalink()) {
  1172. $url = 'http://www.spurl.net/spurl.php?v=3&amp;url=' . rawurlencode($this->get_permalink());
  1173. if ($this->get_title()) {
  1174. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1175. }
  1176. return $url;
  1177. } else {
  1178. return false;
  1179. }
  1180. }
  1181. public function add_to_wists()
  1182. {
  1183. if ($this->get_permalink()) {
  1184. $url = 'http://wists.com/r.php?c=&amp;r=' . rawurlencode($this->get_permalink());
  1185. if ($this->get_title()) {
  1186. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1187. }
  1188. return $url;
  1189. } else {
  1190. return false;
  1191. }
  1192. }
  1193. public function search_technorati()
  1194. {
  1195. if ($this->get_permalink()) {
  1196. return 'http://www.technorati.com/search/' . rawurlencode($this->get_permalink());
  1197. } else {
  1198. return false;
  1199. }
  1200. }
  1201. }
  1202. class SimplePie_Author
  1203. {
  1204. public $name;
  1205. public $link;
  1206. public $email;
  1207. // Constructor, used to input the data
  1208. public function __construct($name, $link, $email)
  1209. {
  1210. $this->name = $name;
  1211. $this->link = $link;
  1212. $this->email = $email;
  1213. }
  1214. public function get_name()
  1215. {
  1216. if (!empty($this->name)) {
  1217. return $this->name;
  1218. } else {
  1219. return false;
  1220. }
  1221. }
  1222. public function get_link()
  1223. {
  1224. if (!empty($this->link)) {
  1225. return $this->link;
  1226. } else {
  1227. return false;
  1228. }
  1229. }
  1230. public function get_email()
  1231. {
  1232. if (!empty($this->email)) {
  1233. return $this->email;
  1234. } else {
  1235. return false;
  1236. }
  1237. }
  1238. }
  1239. class SimplePie_Enclosure
  1240. {
  1241. public $link;
  1242. public $type;
  1243. public $length;
  1244. // Constructor, used to input the data
  1245. public function __construct($link, $type, $length)
  1246. {
  1247. $this->link = $link;
  1248. $this->type = $type;
  1249. $this->length = $length;
  1250. }
  1251. public function get_link()
  1252. {
  1253. if (!empty($this->link)) {
  1254. if (class_exists('idna_convert')) {
  1255. $idn = new idna_convert;
  1256. $this->link = $idn->encode($this->link);
  1257. }
  1258. return $this->link;
  1259. } else {
  1260. return false;
  1261. }
  1262. }
  1263. public function get_extension()
  1264. {
  1265. if (!empty($this->link)) {
  1266. return pathinfo($this->link, PATHINFO_EXTENSION);
  1267. } else {
  1268. return false;
  1269. }
  1270. }
  1271. public function get_type()
  1272. {
  1273. if (!empty($this->type)) {
  1274. return $this->type;
  1275. } else {
  1276. return false;
  1277. }
  1278. }
  1279. public function get_length()
  1280. {
  1281. if (!empty($this->length)) {
  1282. return $this->length;
  1283. } else {
  1284. return false;
  1285. }
  1286. }
  1287. public function get_size()
  1288. {
  1289. $length = $this->get_length();
  1290. if (!empty($length)) {
  1291. return round($length/1048576, 2);
  1292. } else {
  1293. return false;
  1294. }
  1295. }
  1296. public function native_embed($options='')
  1297. {
  1298. return $this->embed($options, true);
  1299. }
  1300. public function embed($options = '', $native = false)
  1301. {
  1302. // Set up defaults
  1303. $audio = '';
  1304. $video = '';
  1305. $alt = '';
  1306. $altclass = '';
  1307. $loop = 'false';
  1308. $width = 'auto';
  1309. $height = 'auto';
  1310. $bgcolor = '#ffffff';
  1311. // Process options and reassign values as necessary
  1312. if (is_array($options)) {
  1313. extract($options);
  1314. } else {
  1315. $options = explode(',', $options);
  1316. foreach ($options as $option) {
  1317. $opt = explode(':', $option, 2);
  1318. if (isset($opt[0], $opt[1])) {
  1319. $opt[0] = trim($opt[0]);
  1320. $opt[1] = trim($opt[1]);
  1321. switch ($opt[0]) {
  1322. case 'audio':
  1323. $audio = $opt[1];
  1324. break;
  1325. case 'video':
  1326. $video = $opt[1];
  1327. break;
  1328. case 'alt':
  1329. $alt = $opt[1];
  1330. break;
  1331. case 'altclass':
  1332. $altclass = $opt[1];
  1333. break;
  1334. case 'loop':
  1335. $loop = $opt[1];
  1336. break;
  1337. case 'width':
  1338. $width = $opt[1];
  1339. break;
  1340. case 'height':
  1341. $height = $opt[1];
  1342. break;
  1343. case 'bgcolor':
  1344. $bgcolor = $opt[1];
  1345. break;
  1346. }
  1347. }
  1348. }
  1349. }
  1350. $type = strtolower($this->get_type());
  1351. // If we encounter an unsupported mime-type, check the file extension and guess intelligently.
  1352. if (!in_array($type, array('audio/3gpp', 'audio/3gpp2', 'audio/aac', 'audio/x-aac', 'audio/aiff', 'audio/x-aiff', 'audio/mid', 'audio/midi', 'audio/x-midi', 'audio/mpeg', 'audio/x-mpeg', 'audio/mp3', 'x-audio/mp3', 'audio/mp4', 'audio/m4a', 'audio/x-m4a', 'audio/wav', 'audio/x-wav', 'video/3gpp', 'video/3gpp2', 'video/m4v', 'video/x-m4v', 'video/mp4', 'video/mpeg', 'video/x-mpeg', 'video/quicktime', 'video/sd-video', 'application/x-shockwave-flash', 'application/futuresplash', 'application/asx', 'application/x-mplayer2', 'audio/x-ms-wma', 'audio/x-ms-wax', 'video/x-ms-asf-plugin', 'video/x-ms-asf', 'video/x-ms-wm', 'video/x-ms-wmv', 'video/x-ms-wvx'))) {
  1353. switch (strtolower($this->get_extension())) {
  1354. // Audio mime-types
  1355. case 'aac':
  1356. case 'adts':
  1357. $type = 'audio/acc';
  1358. break;
  1359. case 'aif':
  1360. case 'aifc':
  1361. case 'aiff':
  1362. case 'cdda':
  1363. $type = 'audio/aiff';
  1364. break;
  1365. case 'bwf':
  1366. $type = 'audio/wav';
  1367. break;
  1368. case 'kar':
  1369. case 'mid':
  1370. case 'midi':
  1371. case 'smf':
  1372. $type = 'audio/midi';
  1373. break;
  1374. case 'm4a':
  1375. $type = 'audio/x-m4a';
  1376. break;
  1377. case 'mp3':
  1378. case 'swa':
  1379. $type = 'audio/mp3';
  1380. break;
  1381. case 'wav':
  1382. $type = 'audio/wav';
  1383. break;
  1384. case 'wax':
  1385. $type = 'audio/x-ms-wax';
  1386. break;
  1387. case 'wma':
  1388. $type = 'audio/x-ms-wma';
  1389. break;
  1390. // Video mime-types
  1391. case '3gp':
  1392. case '3gpp':
  1393. $type = 'video/3gpp';
  1394. break;
  1395. case '3g2':
  1396. case '3gp2':
  1397. $type = 'video/3gpp2';
  1398. break;
  1399. case 'asf':
  1400. $type = 'video/x-ms-asf';
  1401. break;
  1402. case 'm1a':
  1403. case 'm1s':
  1404. case 'm1v':
  1405. case 'm15':
  1406. case 'm75':
  1407. case 'mp2':
  1408. case 'mpa':
  1409. case 'mpeg':
  1410. case 'mpg':
  1411. case 'mpm':
  1412. case 'mpv':
  1413. $type = 'video/mpeg';
  1414. break;
  1415. case 'm4v':
  1416. $type = 'video/x-m4v';
  1417. break;
  1418. case 'mov':
  1419. case 'qt':
  1420. $type = 'video/quicktime';
  1421. break;
  1422. case 'mp4':
  1423. case 'mpg4':
  1424. $type = 'video/mp4';
  1425. break;
  1426. case 'sdv':
  1427. $type = 'video/sd-video';
  1428. break;
  1429. case 'wm':
  1430. $type = 'video/x-ms-wm';
  1431. break;
  1432. case 'wmv':
  1433. $type = 'video/x-ms-wmv';
  1434. break;
  1435. case 'wvx':
  1436. $type = 'video/x-ms-wvx';
  1437. break;
  1438. // Flash mime-types
  1439. case 'spl':
  1440. $type = 'application/futuresplash';
  1441. break;
  1442. case 'swf':
  1443. $type = 'application/x-shockwave-flash';
  1444. break;
  1445. }
  1446. }
  1447. $mime = explode('/', $type, 2);
  1448. $mime = $mime[0];
  1449. // Process values for 'auto'
  1450. if ($width == 'auto') {
  1451. if ($mime == 'video') {
  1452. $width = '320';
  1453. } else {
  1454. $width = '100%';
  1455. }
  1456. }
  1457. if ($height == 'auto') {
  1458. if ($mime == 'audio') {
  1459. $height = 0;
  1460. } elseif ($mime == 'video') {
  1461. $height = 240;
  1462. } else {
  1463. $height = 256;
  1464. }
  1465. }
  1466. // Set proper placeholder value
  1467. if ($mime == 'audio') {
  1468. $placeholder = $audio;
  1469. } elseif ($mime == 'video') {
  1470. $placeholder = $video;
  1471. }
  1472. $embed = '';
  1473. // Make sure the JS library is included
  1474. // (I know it'll be included multiple times, but I can't think of a better way to do this automatically)
  1475. if (!$native) {
  1476. $embed .= '<script type="text/javascript" src="?js"></script>';
  1477. }
  1478. // Odeo Feed MP3's
  1479. if (substr(strtolower($this->get_link()), 0, 15) == 'http://odeo.com') {
  1480. if ($native) {
  1481. $embed .= '<embed src="http://odeo.com/flash/audio_player_fullsize.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="440" height="80" wmode="transparent" allowScriptAccess="any" flashvars="valid_sample_rate=true&external_url=' . $this->get_link() . '"></embed>';
  1482. } else {
  1483. $embed .= '<script type="text/javascript">embed_odeo("' . $this->get_link() . '");</script>';
  1484. }
  1485. }
  1486. // QuickTime 7 file types. Need to test with QuickTime 6.
  1487. elseif (in_array($type, array('audio/3gpp', 'audio/3gpp2', 'audio/aac', 'audio/x-aac', 'audio/aiff', 'audio/x-aiff', 'audio/mid', 'audio/midi', 'audio/x-midi', 'audio/mpeg', 'audio/x-mpeg', 'audio/mp3', 'x-audio/mp3', 'audio/mp4', 'audio/m4a', 'audio/x-m4a', 'audio/wav', 'audio/x-wav', 'video/3gpp', 'video/3gpp2', 'video/m4v', 'video/x-m4v', 'video/mp4', 'video/mpeg', 'video/x-mpeg', 'video/quicktime', 'video/sd-video'))) {
  1488. $height += 16;
  1489. if ($native) {
  1490. if ($placeholder != "") {
  1491. $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" href=\"" . $this->get_link() . "\" src=\"$placeholder\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"false\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://www.apple.com/quicktime/download/\"></embed>";
  1492. } else {
  1493. $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" src=\"" . $this->get_link() . "\" width=\"$width+\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"true\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://www.apple.com/quicktime/download/\"></embed>";
  1494. }
  1495. } else {
  1496. $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>";
  1497. }
  1498. }
  1499. // Flash
  1500. elseif (in_array($type, array('application/x-shockwave-flash', 'application/futuresplash'))) {
  1501. if ($native) {
  1502. $embed .= "<embed src=\"" . $this->get_link() . "\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"$type\" quality=\"high\" width=\"$width\" height=\"$height\" bgcolor=\"$bgcolor\" loop=\"$loop\"></embed>";
  1503. } else {
  1504. $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>";
  1505. }
  1506. }
  1507. // Windows Media
  1508. elseif (in_array($type, array('application/asx', 'application/x-mplayer2', 'audio/x-ms-wma', 'audio/x-ms-wax', 'video/x-ms-asf-plugin', 'video/x-ms-asf', 'video/x-ms-wm', 'video/x-ms-wmv', 'video/x-ms-wvx'))) {
  1509. $height += 45;
  1510. if ($native) {
  1511. $embed .= "<embed type=\"application/x-mplayer2\" src=\"" . $this->get_link() . "\" autosize=\"1\" width=\"$width\" height=\"$height\" showcontrols=\"1\" showstatusbar=\"0\" showdisplay=\"0\" autostart=\"0\"></embed>";
  1512. } else {
  1513. $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>";
  1514. }
  1515. }
  1516. // Everything else
  1517. else {
  1518. $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>';
  1519. }
  1520. return $embed;
  1521. }
  1522. }
  1523. class SimplePie_File
  1524. {
  1525. public $url;
  1526. public $useragent;
  1527. public $success = true;
  1528. public $headers = array();
  1529. public $body;
  1530. public $fp;
  1531. public $redirects = 0;
  1532. public $error;
  1533. public $method;
  1534. public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
  1535. {
  1536. if (class_exists('idna_convert')) {
  1537. $idn = new idna_convert;
  1538. $url = $idn->encode($url);
  1539. }
  1540. $this->url = $url;
  1541. $this->useragent = $useragent;
  1542. if (preg_match('/^http(s)?:\/\//i', $url)) {
  1543. if (empty($useragent)) {
  1544. $useragent = ini_get('user_agent');
  1545. $this->useragent = $useragent;
  1546. }
  1547. if (!is_array($headers)) {
  1548. $headers = array();
  1549. }
  1550. if (extension_loaded('curl') && version_compare((new SimplePie_Misc)->get_curl_version(), '7.10.5', '>=') && !$force_fsockopen) {
  1551. $this->method = 'curl';
  1552. $fp = curl_init();
  1553. $headers2 = array();
  1554. foreach ($headers as $key => $value) {
  1555. $headers2[] = "$key: $value";
  1556. }
  1557. curl_setopt($fp, CURLOPT_ENCODING, '');
  1558. curl_setopt($fp, CURLOPT_URL, $url);
  1559. curl_setopt($fp, CURLOPT_HEADER, 1);
  1560. curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
  1561. curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
  1562. curl_setopt($fp, CURLOPT_REFERER, $url);
  1563. curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
  1564. curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
  1565. if (!ini_get('open_basedir') && !ini_get('safe_mode')) {
  1566. curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
  1567. curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
  1568. }
  1569. $this->headers = trim(curl_exec($fp));
  1570. if (curl_errno($fp) == 23 || curl_errno($fp) == 61) {
  1571. curl_setopt($fp, CURLOPT_ENCODING, 'none');
  1572. $this->headers = trim(curl_exec($fp));
  1573. }
  1574. if (curl_errno($fp)) {
  1575. $this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
  1576. $this->success = false;
  1577. return false;
  1578. }
  1579. $info = curl_getinfo($fp);
  1580. $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 2);
  1581. if (count($this->headers) == $info['redirect_count'] + 1) {
  1582. $this->headers = array_pop($this->headers);
  1583. $this->body = '';
  1584. } else {
  1585. $this->body = array_pop($this->headers);
  1586. $this->headers = array_pop($this->headers);
  1587. }
  1588. $this->headers = $this->parse_headers($this->headers);
  1589. if (($this->headers['status']['code'] == 301 || $this->headers['status']['code'] == 302 || $this->headers['status']['code'] == 303 || $this->headers['status']['code'] == 307) && !empty($this->headers['location']) && $this->redirects < $redirects) {
  1590. $this->redirects++;
  1591. return $this->SimplePie_File($this->headers['location'], $timeout, $redirects, $headers, $useragent, $force_fsockopen);
  1592. }
  1593. } else {
  1594. $this->method = 'fsockopen';
  1595. $url_parts = parse_url($url);
  1596. if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) == 'https') {
  1597. $url_parts['host'] = "ssl://$url_parts[host]";
  1598. $url_parts['port'] = 443;
  1599. }
  1600. if (!isset($url_parts['port'])) {
  1601. $url_parts['port'] = 80;
  1602. }
  1603. $this->fp = @fsockopen($url_parts['host'], $url_parts['port'], $errno, $errstr, $timeout);
  1604. if (!$this->fp) {
  1605. $this->error = 'fsockopen error: ' . $errstr;
  1606. $this->success = false;
  1607. return false;
  1608. } else {
  1609. stream_set_timeout($this->fp, $timeout);
  1610. $get = (isset($url_parts['query'])) ? "$url_parts[path]?$url_parts[query]" : $url_parts['path'];
  1611. $out = "GET $get HTTP/1.0\r\n";
  1612. $out .= "Host: $url_parts[host]\r\n";
  1613. $out .= "User-Agent: $useragent\r\n";
  1614. if (function_exists('gzinflate')) {
  1615. $out .= "Accept-Encoding: gzip,deflate\r\n";
  1616. }
  1617. if (!empty($url_parts['user']) && !empty($url_parts['pass'])) {
  1618. $out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
  1619. }
  1620. foreach ($headers as $key => $value) {
  1621. $out .= "$key: $value\r\n";
  1622. }
  1623. $out .= "Connection: Close\r\n\r\n";
  1624. fwrite($this->fp, $out);
  1625. $info = stream_get_meta_data($this->fp);
  1626. $data = '';
  1627. while (strpos($data, "\r\n\r\n") === false && !$info['timed_out']) {
  1628. $data .= fgets($this->fp, 128);
  1629. $info = @stream_get_meta_data($this->fp);
  1630. }
  1631. if (!$info['timed_out']) {
  1632. $this->headers = $this->parse_headers($data);
  1633. if (($this->headers['status']['code'] == 301 || $this->headers['status']['code'] == 302 || $this->headers['status']['code'] == 303 || $this->headers['status']['code'] == 307) && !empty($this->headers['location']) && $this->redirects < $redirects) {
  1634. $this->redirects++;
  1635. return $this->SimplePie_File($this->headers['location'], $timeout, $redirects, $headers, $useragent, $force_fsockopen);
  1636. }
  1637. } else {
  1638. $this->close();
  1639. $this->error = 'fsocket timed out';
  1640. $this->success = false;
  1641. return false;
  1642. }
  1643. }
  1644. }
  1645. return $this->headers['status']['code'];
  1646. } else {
  1647. $this->method = 'fopen';
  1648. if ($this->fp = fopen($url, 'r')) {
  1649. return true;
  1650. } else {
  1651. $this->error = 'fopen could not open the file';
  1652. $this->success = false;
  1653. return false;
  1654. }
  1655. }
  1656. }
  1657. public function headers()
  1658. {
  1659. return $this->headers;
  1660. }
  1661. public function body()
  1662. {
  1663. if (is_null($this->body)) {
  1664. if ($this->fp) {
  1665. $info = stream_get_meta_data($this->fp);
  1666. $this->body = '';
  1667. while (!$info['eof'] && !$info['timed_out']) {
  1668. $this->body .= fread($this->fp, 1024);
  1669. $info = stream_get_meta_data($this->fp);
  1670. }
  1671. if (!$info['timed_out']) {
  1672. $this->body = trim($this->body);
  1673. if ($this->method == 'fsockopen' && !empty($this->headers['content-encoding']) && ($this->headers['content-encoding'] == 'gzip' || $this->headers['content-encoding'] == 'deflate')) {
  1674. if (substr($this->body, 0, 8) == "\x1f\x8b\x08\x00\x00\x00\x00\x00") {
  1675. $this->body = substr($this->body, 10);
  1676. }
  1677. $this->body = gzinflate($this->body);
  1678. }
  1679. $this->close();
  1680. } else {
  1681. return false;
  1682. }
  1683. } else {
  1684. return false;
  1685. }
  1686. }
  1687. return $this->body;
  1688. }
  1689. public function close()
  1690. {
  1691. if (!is_null($this->fp)) {
  1692. if (fclose($this->fp)) {
  1693. $this->fp = null;
  1694. return true;
  1695. } else {
  1696. return false;
  1697. }
  1698. } else {
  1699. return false;
  1700. }
  1701. }
  1702. public function parse_headers($headers)
  1703. {
  1704. $headers = explode("\r\n", trim($headers));
  1705. $status = array_shift($headers);
  1706. foreach ($headers as $header) {
  1707. $data = explode(':', $header, 2);
  1708. $head[strtolower(trim($data[0]))] = trim($data[1]);
  1709. }
  1710. if (preg_match('/HTTP\/[0-9\.]+ ([0-9]+)(.*)$/i', $status, $matches)) {
  1711. if (isset($head['status'])) {
  1712. unset($head['status']);
  1713. }
  1714. $head['status']['code'] = $matches[1];
  1715. $head['status']['name'] = trim($matches[2]);
  1716. }
  1717. return $head;
  1718. }
  1719. }
  1720. class SimplePie_Cache
  1721. {
  1722. public $location;
  1723. public $filename;
  1724. public $extension;
  1725. public $name;
  1726. public function __construct($location, $filename, $extension)
  1727. {
  1728. $this->location = $location;
  1729. $this->filename = rawurlencode($filename);
  1730. $this->extension = rawurlencode($extension);
  1731. $this->name = "$location/$this->filename.$this->extension";
  1732. }
  1733. public function save($data)
  1734. {
  1735. if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location)) {
  1736. $fp = fopen($this->name, 'w');
  1737. if ($fp) {
  1738. fwrite($fp, serialize($data));
  1739. fclose($fp);
  1740. return true;
  1741. }
  1742. }
  1743. return false;
  1744. }
  1745. public function load()
  1746. {
  1747. if (file_exists($this->name) && is_readable($this->name)) {
  1748. return unserialize(file_get_contents($this->name));
  1749. }
  1750. return false;
  1751. }
  1752. public function mtime()
  1753. {
  1754. if (file_exists($this->name)) {
  1755. return filemtime($this->name);
  1756. }
  1757. return false;
  1758. }
  1759. public function touch()
  1760. {
  1761. if (file_exists($this->name)) {
  1762. return touch($this->name);
  1763. }
  1764. return false;
  1765. }
  1766. public function unlink()
  1767. {
  1768. if (file_exists($this->name)) {
  1769. return unlink($this->name);
  1770. }
  1771. return false;
  1772. }
  1773. }
  1774. class SimplePie_Misc
  1775. {
  1776. public function absolutize_url($relative, $base)
  1777. {
  1778. $relative = trim($relative);
  1779. $base = trim($base);
  1780. if (!empty($relative)) {
  1781. $relative = (new SimplePie_Misc)->parse_url($relative, false);
  1782. $relative = array('scheme' => $relative[2], 'authority' => $relative[3], 'path' => $relative[5], 'query' => $relative[7], 'fragment' => $relative[9]);
  1783. if (!empty($relative['scheme'])) {
  1784. $target = $relative;
  1785. } elseif (!empty($base)) {
  1786. $base = (new SimplePie_Misc)->parse_url($base, false);
  1787. $base = array('scheme' => $base[2], 'authority' => $base[3], 'path' => $base[5], 'query' => $base[7], 'fragment' => $base[9]);
  1788. $target['scheme'] = $base['scheme'];
  1789. if (!empty($relative['authority'])) {
  1790. $target = array_merge($relative, $target);
  1791. } else {
  1792. $target['authority'] = $base['authority'];
  1793. if (!empty($relative['path'])) {
  1794. if (strpos($relative['path'], '/') === 0) {
  1795. $target['path'] = $relative['path'];
  1796. } else {
  1797. if (!empty($base['path'])) {
  1798. $target['path'] = dirname("$base[path].") . '/' . $relative['path'];
  1799. } else {
  1800. $target['path'] = '/' . $relative['path'];
  1801. }
  1802. }
  1803. if (!empty($relative['query'])) {
  1804. $target['query'] = $relative['query'];
  1805. }
  1806. $input = $target['path'];
  1807. $target['path'] = '';
  1808. while (!empty($input)) {
  1809. if (strpos($input, '../') === 0) {
  1810. $input = substr($input, 3);
  1811. } elseif (strpos($input, './') === 0) {
  1812. $input = substr($input, 2);
  1813. } elseif (strpos($input, '/./') === 0) {
  1814. $input = substr_replace($input, '/', 0, 3);
  1815. } elseif (strpos($input, '/.') === 0 && (new SimplePie_Misc)->strendpos($input, '/.') === 0) {
  1816. $input = substr_replace($input, '/', -2);
  1817. } elseif (strpos($input, '/../') === 0) {
  1818. $input = substr_replace($input, '/', 0, 4);
  1819. $target['path'] = preg_replace('/(\/)?([^\/]+)$/msiU', '', $target['path']);
  1820. } elseif (strpos($input, '/..') === 0 && (new SimplePie_Misc)->strendpos($input, '/..') === 0) {
  1821. $input = substr_replace($input, '/', 0, 3);
  1822. $target['path'] = preg_replace('/(\/)?([^\/]+)$/msiU', '', $target['path']);
  1823. } elseif ($input == '.' || $input == '..') {
  1824. $input = '';
  1825. } else {
  1826. if (preg_match('/^(.+)(\/|$)/msiU', $input, $match)) {
  1827. $target['path'] .= $match[1];
  1828. $input = substr_replace($input, '', 0, strlen($match[1]));
  1829. }
  1830. }
  1831. }
  1832. } else {
  1833. if (!empty($base['path'])) {
  1834. $target['path'] = $base['path'];
  1835. } else {
  1836. $target['path'] = '/';
  1837. }
  1838. if (!empty($relative['query'])) {
  1839. $target['query'] = $relative['query'];
  1840. } elseif (!empty($base['query'])) {
  1841. $target['query'] = $base['query'];
  1842. }
  1843. }
  1844. }
  1845. if (!empty($relative['fragment'])) {
  1846. $target['fragment'] = $relative['fragment'];
  1847. }
  1848. } else {
  1849. return false;
  1850. }
  1851. $return = '';
  1852. if (!empty($target['scheme'])) {
  1853. $return .= "$target[scheme]:";
  1854. }
  1855. if (!empty($target['authority'])) {
  1856. $return .= $target['authority'];
  1857. }
  1858. if (!empty($target['path'])) {
  1859. $return .= $target['path'];
  1860. }
  1861. if (!empty($target['query'])) {
  1862. $return .= "?$target[query]";
  1863. }
  1864. if (!empty($target['fragment'])) {
  1865. $return .= "#$target[fragment]";
  1866. }
  1867. } else {
  1868. $return = $base;
  1869. }
  1870. return $return;
  1871. }
  1872. public function strendpos($haystack, $needle)
  1873. {
  1874. return strlen($haystack) - strpos($haystack, $needle) - strlen($needle);
  1875. }
  1876. public function get_element($realname, $string)
  1877. {
  1878. $return = array();
  1879. $name = preg_quote($realname, '/');
  1880. preg_match_all("/<($name)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'|(.*)))*)\s*((\/)?>|>(.*)<\/$name>)/msiU", $string, $matches, PREG_SET_ORDER);
  1881. for ($i = 0; $i < count($matches); $i++) {
  1882. $return[$i]['tag'] = $realname;
  1883. $return[$i]['full'] = $matches[$i][0];
  1884. if (strlen($matches[$i][10]) <= 2) {
  1885. $return[$i]['self_closing'] = true;
  1886. } else {
  1887. $return[$i]['self_closing'] = false;
  1888. $return[$i]['content'] = $matches[$i][12];
  1889. }
  1890. $return[$i]['attribs'] = array();
  1891. if (!empty($matches[$i][2])) {
  1892. preg_match_all('/((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(\S+))\s/msiU', ' ' . $matches[$i][2] . ' ', $attribs, PREG_SET_ORDER);
  1893. for ($j = 0; $j < count($attribs); $j++) {
  1894. $return[$i]['attribs'][strtoupper($attribs[$j][1])]['data'] = $attribs[$j][count($attribs[$j])-1];
  1895. $first = substr($attribs[$j][2], 0, 1);
  1896. $return[$i]['attribs'][strtoupper($attribs[$j][1])]['split'] = ($first == '"' || $first == "'") ? $first : '"';
  1897. }
  1898. }
  1899. }
  1900. return $return;
  1901. }
  1902. public function element_implode($element)
  1903. {
  1904. $full = "<$element[tag]";
  1905. foreach ($element['attribs'] as $key => $value) {
  1906. $key = strtolower($key);
  1907. $full .= " $key=$value[split]$value[data]$value[split]";
  1908. }
  1909. if ($element['self_closing']) {
  1910. $full .= ' />';
  1911. } else {
  1912. $full .= ">$element[content]</$element[tag]>";
  1913. }
  1914. return $full;
  1915. }
  1916. public function error($message, $level, $file, $line)
  1917. {
  1918. switch ($level) {
  1919. case E_USER_ERROR:
  1920. $note = 'PHP Error';
  1921. break;
  1922. case E_USER_WARNING:
  1923. $note = 'PHP Warning';
  1924. break;
  1925. case E_USER_NOTICE:
  1926. $note = 'PHP Notice';
  1927. break;
  1928. default:
  1929. $note = 'Unknown Error';
  1930. break;
  1931. }
  1932. error_log("$note: $message in $file on line $line", 0);
  1933. return $message;
  1934. }
  1935. public function display_file($url, $timeout = 10, $useragent = null)
  1936. {
  1937. $file = new SimplePie_File($url, $timeout, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $useragent);
  1938. $headers = $file->headers();
  1939. if ($file->body() !== false) {
  1940. header('Content-type: ' . $headers['content-type']);
  1941. echo $file->body();
  1942. exit;
  1943. }
  1944. }
  1945. public function fix_protocol($url, $http = 1)
  1946. {
  1947. $parsed = (new SimplePie_Misc)->parse_url($url);
  1948. if (!empty($parsed['scheme']) && strtolower($parsed['scheme']) != 'http' && strtolower($parsed['scheme']) != 'https') {
  1949. return (new SimplePie_Misc)->fix_protocol("$parsed[authority]$parsed[path]$parsed[query]$parsed[fragment]", $http);
  1950. }
  1951. if (!file_exists($url) && empty($parsed['scheme'])) {
  1952. return (new SimplePie_Misc)->fix_protocol("http://$url", $http);
  1953. }
  1954. if ($http == 2 && !empty($parsed['scheme'])) {
  1955. return "feed:$url";
  1956. } elseif ($http == 3 && strtolower($parsed['scheme']) == 'http') {
  1957. return substr_replace($url, 'podcast', 0, 4);
  1958. } else {
  1959. return $url;
  1960. }
  1961. }
  1962. public function parse_url($url, $parse_match = true)
  1963. {
  1964. preg_match('/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/i', $url, $match);
  1965. if (empty($match[0])) {
  1966. return false;
  1967. } else {
  1968. for ($i = 6; $i < 10; $i++) {
  1969. if (!isset($match[$i])) {
  1970. $match[$i] = '';
  1971. }
  1972. }
  1973. if ($parse_match) {
  1974. $match = array('scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5], 'query' => $match[6], 'fragment' => $match[8]);
  1975. }
  1976. return $match;
  1977. }
  1978. }
  1979. /**
  1980. * Replace bad bytes
  1981. *
  1982. * PCRE Pattern to locate bad bytes in a UTF-8 string
  1983. * Comes from W3 FAQ: Multilingual Forms
  1984. * Note: modified to include full ASCII range including control chars
  1985. *
  1986. * Modified by Geoffrey Sneddon 2006-11-19 to remove functionality
  1987. * to choose what the replace string is, and to use a variable for
  1988. * the output instead of PHP's output buffer
  1989. */
  1990. public function utf8_bad_replace($str)
  1991. {
  1992. $UTF8_BAD =
  1993. '([\x00-\x7F]' . # ASCII (including control chars)
  1994. '|[\xC2-\xDF][\x80-\xBF]' . # non-overlong 2-byte
  1995. '|\xE0[\xA0-\xBF][\x80-\xBF]' . # excluding overlongs
  1996. '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' . # straight 3-byte
  1997. '|\xED[\x80-\x9F][\x80-\xBF]' . # excluding surrogates
  1998. '|\xF0[\x90-\xBF][\x80-\xBF]{2}' . # planes 1-3
  1999. '|[\xF1-\xF3][\x80-\xBF]{3}' . # planes 4-15
  2000. '|\xF4[\x80-\x8F][\x80-\xBF]{2}' . # plane 16
  2001. '|(.{1}))'; # invalid byte
  2002. $output = '';
  2003. while (preg_match('/' . $UTF8_BAD . '/S', $str, $matches)) {
  2004. if (!isset($matches[2])) {
  2005. $output .= $matches[0];
  2006. }
  2007. $str = substr($str, strlen($matches[0]));
  2008. }
  2009. return $output;
  2010. }
  2011. public function change_encoding($data, $input, $output)
  2012. {
  2013. $input = (new SimplePie_Misc)->encoding($input);
  2014. $output = (new SimplePie_Misc)->encoding($output);
  2015. if ($input != $output) {
  2016. if (function_exists('iconv') && $input['use_iconv'] && $output['use_iconv'] && iconv($input['encoding'], "$output[encoding]//TRANSLIT", $data)) {
  2017. return iconv($input['encoding'], "$output[encoding]//TRANSLIT", $data);
  2018. } elseif (function_exists('iconv') && $input['use_iconv'] && $output['use_iconv'] && iconv($input['encoding'], $output['encoding'], $data)) {
  2019. return iconv($input['encoding'], $output['encoding'], $data);
  2020. } elseif (function_exists('mb_convert_encoding') && $input['use_mbstring'] && $output['use_mbstring']) {
  2021. return mb_convert_encoding($data, $output['encoding'], $input['encoding']);
  2022. } elseif ($input['encoding'] == 'ISO-8859-1' && $output['encoding'] == 'UTF-8') {
  2023. return utf8_encode($data);
  2024. } elseif ($input['encoding'] == 'UTF-8' && $output['encoding'] == 'ISO-8859-1') {
  2025. return utf8_decode($data);
  2026. }
  2027. }
  2028. return $data;
  2029. }
  2030. public function encoding($encoding)
  2031. {
  2032. $return['use_mbstring'] = false;
  2033. $return['use_iconv'] = false;
  2034. switch (strtolower($encoding)) {
  2035. // 7bit
  2036. case '7bit':
  2037. case '7-bit':
  2038. $return['encoding'] = '7bit';
  2039. $return['use_mbstring'] = true;
  2040. break;
  2041. // 8bit
  2042. case '8bit':
  2043. case '8-bit':
  2044. $return['encoding'] = '8bit';
  2045. $return['use_mbstring'] = true;
  2046. break;
  2047. // ARMSCII-8
  2048. case 'armscii-8':
  2049. case 'armscii':
  2050. $return['encoding'] = 'ARMSCII-8';
  2051. $return['use_iconv'] = true;
  2052. break;
  2053. // ASCII
  2054. case 'us-ascii':
  2055. case 'ascii':
  2056. $return['encoding'] = 'US-ASCII';
  2057. $return['use_iconv'] = true;
  2058. $return['use_mbstring'] = true;
  2059. break;
  2060. // BASE64
  2061. case 'base64':
  2062. case 'base-64':
  2063. $return['encoding'] = 'BASE64';
  2064. $return['use_mbstring'] = true;
  2065. break;
  2066. // Big5 - Traditional Chinese, mainly used in Taiwan
  2067. case 'big5':
  2068. case '950':
  2069. $return['encoding'] = 'BIG5';
  2070. $return['use_iconv'] = true;
  2071. $return['use_mbstring'] = true;
  2072. break;
  2073. // Big5 with Hong Kong extensions, Traditional Chinese
  2074. case 'big5-hkscs':
  2075. $return['encoding'] = 'BIG5-HKSCS';
  2076. $return['use_iconv'] = true;
  2077. $return['use_mbstring'] = true;
  2078. break;
  2079. // byte2be
  2080. case 'byte2be':
  2081. $return['encoding'] = 'byte2be';
  2082. $return['use_mbstring'] = true;
  2083. break;
  2084. // byte2le
  2085. case 'byte2le':
  2086. $return['encoding'] = 'byte2le';
  2087. $return['use_mbstring'] = true;
  2088. break;
  2089. // byte4be
  2090. case 'byte4be':
  2091. $return['encoding'] = 'byte4be';
  2092. $return['use_mbstring'] = true;
  2093. break;
  2094. // byte4le
  2095. case 'byte4le':
  2096. $return['encoding'] = 'byte4le';
  2097. $return['use_mbstring'] = true;
  2098. break;
  2099. // EUC-CN
  2100. case 'euc-cn':
  2101. case 'euccn':
  2102. $return['encoding'] = 'EUC-CN';
  2103. $return['use_iconv'] = true;
  2104. $return['use_mbstring'] = true;
  2105. break;
  2106. // EUC-JISX0213
  2107. case 'euc-jisx0213':
  2108. case 'eucjisx0213':
  2109. $return['encoding'] = 'EUC-JISX0213';
  2110. $return['use_iconv'] = true;
  2111. break;
  2112. // EUC-JP
  2113. case 'euc-jp':
  2114. case 'eucjp':
  2115. $return['encoding'] = 'EUC-JP';
  2116. $return['use_iconv'] = true;
  2117. $return['use_mbstring'] = true;
  2118. break;
  2119. // EUCJP-win
  2120. case 'euc-jp-win':
  2121. case 'eucjp-win':
  2122. case 'eucjpwin':
  2123. $return['encoding'] = 'EUCJP-win';
  2124. $return['use_iconv'] = true;
  2125. $return['use_mbstring'] = true;
  2126. break;
  2127. // EUC-KR
  2128. case 'euc-kr':
  2129. case 'euckr':
  2130. $return['encoding'] = 'EUC-KR';
  2131. $return['use_iconv'] = true;
  2132. $return['use_mbstring'] = true;
  2133. break;
  2134. // EUC-TW
  2135. case 'euc-tw':
  2136. case 'euctw':
  2137. $return['encoding'] = 'EUC-TW';
  2138. $return['use_iconv'] = true;
  2139. $return['use_mbstring'] = true;
  2140. break;
  2141. // GB18030 - Simplified Chinese, national standard character set
  2142. case 'gb18030-2000':
  2143. case 'gb18030':
  2144. $return['encoding'] = 'GB18030';
  2145. $return['use_iconv'] = true;
  2146. break;
  2147. // GB2312 - Simplified Chinese, national standard character set
  2148. case 'gb2312':
  2149. case '936':
  2150. $return['encoding'] = 'GB2312';
  2151. $return['use_mbstring'] = true;
  2152. break;
  2153. // GBK
  2154. case 'gbk':
  2155. $return['encoding'] = 'GBK';
  2156. $return['use_iconv'] = true;
  2157. break;
  2158. // Georgian-Academy
  2159. case 'georgian-academy':
  2160. $return['encoding'] = 'Georgian-Academy';
  2161. $return['use_iconv'] = true;
  2162. break;
  2163. // Georgian-PS
  2164. case 'georgian-ps':
  2165. $return['encoding'] = 'Georgian-PS';
  2166. $return['use_iconv'] = true;
  2167. break;
  2168. // HTML-ENTITIES
  2169. case 'html-entities':
  2170. case 'htmlentities':
  2171. $return['encoding'] = 'HTML-ENTITIES';
  2172. $return['use_mbstring'] = true;
  2173. break;
  2174. // HZ
  2175. case 'hz':
  2176. $return['encoding'] = 'HZ';
  2177. $return['use_iconv'] = true;
  2178. $return['use_mbstring'] = true;
  2179. break;
  2180. // ISO-2022-CN
  2181. case 'iso-2022-cn':
  2182. case 'iso2022-cn':
  2183. case 'iso2022cn':
  2184. $return['encoding'] = 'ISO-2022-CN';
  2185. $return['use_iconv'] = true;
  2186. break;
  2187. // ISO-2022-CN-EXT
  2188. case 'iso-2022-cn-ext':
  2189. case 'iso2022-cn-ext':
  2190. case 'iso2022cn-ext':
  2191. case 'iso2022cnext':
  2192. $return['encoding'] = 'ISO-2022-CN';
  2193. $return['use_iconv'] = true;
  2194. break;
  2195. // ISO-2022-JP
  2196. case 'iso-2022-jp':
  2197. case 'iso2022-jp':
  2198. case 'iso2022jp':
  2199. $return['encoding'] = 'ISO-2022-JP';
  2200. $return['use_iconv'] = true;
  2201. $return['use_mbstring'] = true;
  2202. break;
  2203. // ISO-2022-JP-1
  2204. case 'iso-2022-jp-1':
  2205. case 'iso2022-jp-1':
  2206. case 'iso2022jp-1':
  2207. case 'iso2022jp1':
  2208. $return['encoding'] = 'ISO-2022-JP-1';
  2209. $return['use_iconv'] = true;
  2210. break;
  2211. // ISO-2022-JP-2
  2212. case 'iso-2022-jp-2':
  2213. case 'iso2022-jp-2':
  2214. case 'iso2022jp-2':
  2215. case 'iso2022jp2':
  2216. $return['encoding'] = 'ISO-2022-JP-2';
  2217. $return['use_iconv'] = true;
  2218. break;
  2219. // ISO-2022-JP-3
  2220. case 'iso-2022-jp-3':
  2221. case 'iso2022-jp-3':
  2222. case 'iso2022jp-3':
  2223. case 'iso2022jp3':
  2224. $return['encoding'] = 'ISO-2022-JP-3';
  2225. $return['use_iconv'] = true;
  2226. break;
  2227. // ISO-2022-KR
  2228. case 'iso-2022-kr':
  2229. case 'iso2022-kr':
  2230. case 'iso2022kr':
  2231. $return['encoding'] = 'ISO-2022-KR';
  2232. $return['use_iconv'] = true;
  2233. $return['use_mbstring'] = true;
  2234. break;
  2235. // ISO-8859-1
  2236. case 'iso-8859-1':
  2237. case 'iso8859-1':
  2238. $return['encoding'] = 'ISO-8859-1';
  2239. $return['use_iconv'] = true;
  2240. $return['use_mbstring'] = true;
  2241. break;
  2242. // ISO-8859-2
  2243. case 'iso-8859-2':
  2244. case 'iso8859-2':
  2245. $return['encoding'] = 'ISO-8859-2';
  2246. $return['use_iconv'] = true;
  2247. $return['use_mbstring'] = true;
  2248. break;
  2249. // ISO-8859-3
  2250. case 'iso-8859-3':
  2251. case 'iso8859-3':
  2252. $return['encoding'] = 'ISO-8859-3';
  2253. $return['use_iconv'] = true;
  2254. $return['use_mbstring'] = true;
  2255. break;
  2256. // ISO-8859-4
  2257. case 'iso-8859-4':
  2258. case 'iso8859-4':
  2259. $return['encoding'] = 'ISO-8859-4';
  2260. $return['use_iconv'] = true;
  2261. $return['use_mbstring'] = true;
  2262. break;
  2263. // ISO-8859-5
  2264. case 'iso-8859-5':
  2265. case 'iso8859-5':
  2266. $return['encoding'] = 'ISO-8859-5';
  2267. $return['use_iconv'] = true;
  2268. $return['use_mbstring'] = true;
  2269. break;
  2270. // ISO-8859-6
  2271. case 'iso-8859-6':
  2272. case 'iso8859-6':
  2273. $return['encoding'] = 'ISO-8859-6';
  2274. $return['use_iconv'] = true;
  2275. $return['use_mbstring'] = true;
  2276. break;
  2277. // ISO-8859-7
  2278. case 'iso-8859-7':
  2279. case 'iso8859-7':
  2280. $return['encoding'] = 'ISO-8859-7';
  2281. $return['use_iconv'] = true;
  2282. $return['use_mbstring'] = true;
  2283. break;
  2284. // ISO-8859-8
  2285. case 'iso-8859-8':
  2286. case 'iso8859-8':
  2287. $return['encoding'] = 'ISO-8859-8';
  2288. $return['use_iconv'] = true;
  2289. $return['use_mbstring'] = true;
  2290. break;
  2291. // ISO-8859-9
  2292. case 'iso-8859-9':
  2293. case 'iso8859-9':
  2294. $return['encoding'] = 'ISO-8859-9';
  2295. $return['use_iconv'] = true;
  2296. $return['use_mbstring'] = true;
  2297. break;
  2298. // ISO-8859-10
  2299. case 'iso-8859-10':
  2300. case 'iso8859-10':
  2301. $return['encoding'] = 'ISO-8859-10';
  2302. $return['use_iconv'] = true;
  2303. $return['use_mbstring'] = true;
  2304. break;
  2305. // mbstring/iconv functions don't appear to support 11 & 12
  2306. // ISO-8859-13
  2307. case 'iso-8859-13':
  2308. case 'iso8859-13':
  2309. $return['encoding'] = 'ISO-8859-13';
  2310. $return['use_iconv'] = true;
  2311. $return['use_mbstring'] = true;
  2312. break;
  2313. // ISO-8859-14
  2314. case 'iso-8859-14':
  2315. case 'iso8859-14':
  2316. $return['encoding'] = 'ISO-8859-14';
  2317. $return['use_iconv'] = true;
  2318. $return['use_mbstring'] = true;
  2319. break;
  2320. // ISO-8859-15
  2321. case 'iso-8859-15':
  2322. case 'iso8859-15':
  2323. $return['encoding'] = 'ISO-8859-15';
  2324. $return['use_iconv'] = true;
  2325. $return['use_mbstring'] = true;
  2326. break;
  2327. // ISO-8859-16
  2328. case 'iso-8859-16':
  2329. case 'iso8859-16':
  2330. $return['encoding'] = 'ISO-8859-16';
  2331. $return['use_iconv'] = true;
  2332. break;
  2333. // JIS
  2334. case 'jis':
  2335. $return['encoding'] = 'JIS';
  2336. $return['use_mbstring'] = true;
  2337. break;
  2338. // JOHAB - Korean
  2339. case 'johab':
  2340. $return['encoding'] = 'JOHAB';
  2341. $return['use_iconv'] = true;
  2342. break;
  2343. // Russian
  2344. case 'koi8-r':
  2345. case 'koi8r':
  2346. $return['encoding'] = 'KOI8-R';
  2347. $return['use_iconv'] = true;
  2348. $return['use_mbstring'] = true;
  2349. break;
  2350. // Turkish
  2351. case 'koi8-t':
  2352. case 'koi8t':
  2353. $return['encoding'] = 'KOI8-T';
  2354. $return['use_iconv'] = true;
  2355. break;
  2356. // Ukrainian
  2357. case 'koi8-u':
  2358. case 'koi8u':
  2359. $return['encoding'] = 'KOI8-U';
  2360. $return['use_iconv'] = true;
  2361. break;
  2362. // Russian+Ukrainian
  2363. case 'koi8-ru':
  2364. case 'koi8ru':
  2365. $return['encoding'] = 'KOI8-RU';
  2366. $return['use_iconv'] = true;
  2367. break;
  2368. // Macintosh (Mac OS Classic)
  2369. case 'macintosh':
  2370. $return['encoding'] = 'Macintosh';
  2371. $return['use_iconv'] = true;
  2372. break;
  2373. // MacArabic (Mac OS Classic)
  2374. case 'macarabic':
  2375. $return['encoding'] = 'MacArabic';
  2376. $return['use_iconv'] = true;
  2377. break;
  2378. // MacCentralEurope (Mac OS Classic)
  2379. case 'maccentraleurope':
  2380. $return['encoding'] = 'MacCentralEurope';
  2381. $return['use_iconv'] = true;
  2382. break;
  2383. // MacCroatian (Mac OS Classic)
  2384. case 'maccroatian':
  2385. $return['encoding'] = 'MacCroatian';
  2386. $return['use_iconv'] = true;
  2387. break;
  2388. // MacCyrillic (Mac OS Classic)
  2389. case 'maccyrillic':
  2390. $return['encoding'] = 'MacCyrillic';
  2391. $return['use_iconv'] = true;
  2392. break;
  2393. // MacGreek (Mac OS Classic)
  2394. case 'macgreek':
  2395. $return['encoding'] = 'MacGreek';
  2396. $return['use_iconv'] = true;
  2397. break;
  2398. // MacHebrew (Mac OS Classic)
  2399. case 'machebrew':
  2400. $return['encoding'] = 'MacHebrew';
  2401. $return['use_iconv'] = true;
  2402. break;
  2403. // MacIceland (Mac OS Classic)
  2404. case 'maciceland':
  2405. $return['encoding'] = 'MacIceland';
  2406. $return['use_iconv'] = true;
  2407. break;
  2408. // MacRoman (Mac OS Classic)
  2409. case 'macroman':
  2410. $return['encoding'] = 'MacRoman';
  2411. $return['use_iconv'] = true;
  2412. break;
  2413. // MacRomania (Mac OS Classic)
  2414. case 'macromania':
  2415. $return['encoding'] = 'MacRomania';
  2416. $return['use_iconv'] = true;
  2417. break;
  2418. // MacThai (Mac OS Classic)
  2419. case 'macthai':
  2420. $return['encoding'] = 'MacThai';
  2421. $return['use_iconv'] = true;
  2422. break;
  2423. // MacTurkish (Mac OS Classic)
  2424. case 'macturkish':
  2425. $return['encoding'] = 'MacTurkish';
  2426. $return['use_iconv'] = true;
  2427. break;
  2428. // MacUkraine (Mac OS Classic)
  2429. case 'macukraine':
  2430. $return['encoding'] = 'MacUkraine';
  2431. $return['use_iconv'] = true;
  2432. break;
  2433. // MuleLao-1
  2434. case 'mulelao-1':
  2435. case 'mulelao1':
  2436. $return['encoding'] = 'MuleLao-1';
  2437. $return['use_iconv'] = true;
  2438. break;
  2439. // Shift_JIS
  2440. case 'shift_jis':
  2441. case 'sjis':
  2442. case '932':
  2443. $return['encoding'] = 'Shift_JIS';
  2444. $return['use_iconv'] = true;
  2445. $return['use_mbstring'] = true;
  2446. break;
  2447. // Shift_JISX0213
  2448. case 'shift-jisx0213':
  2449. case 'shiftjisx0213':
  2450. $return['encoding'] = 'Shift_JISX0213';
  2451. $return['use_iconv'] = true;
  2452. break;
  2453. // SJIS-win
  2454. case 'sjis-win':
  2455. case 'sjiswin':
  2456. case 'shift_jis-win':
  2457. $return['encoding'] = 'SJIS-win';
  2458. $return['use_iconv'] = true;
  2459. $return['use_mbstring'] = true;
  2460. break;
  2461. // TCVN - Vietnamese
  2462. case 'tcvn':
  2463. $return['encoding'] = 'TCVN';
  2464. $return['use_iconv'] = true;
  2465. break;
  2466. // TDS565 - Turkish
  2467. case 'tds565':
  2468. $return['encoding'] = 'TDS565';
  2469. $return['use_iconv'] = true;
  2470. break;
  2471. // TIS-620 Thai
  2472. case 'tis-620':
  2473. case 'tis620':
  2474. $return['encoding'] = 'TIS-620';
  2475. $return['use_iconv'] = true;
  2476. $return['use_mbstring'] = true;
  2477. break;
  2478. // UCS-2
  2479. case 'ucs-2':
  2480. case 'ucs2':
  2481. case 'utf-16':
  2482. case 'utf16':
  2483. $return['encoding'] = 'UCS-2';
  2484. $return['use_iconv'] = true;
  2485. $return['use_mbstring'] = true;
  2486. break;
  2487. // UCS-2BE
  2488. case 'ucs-2be':
  2489. case 'ucs2be':
  2490. case 'utf-16be':
  2491. case 'utf16be':
  2492. $return['encoding'] = 'UCS-2BE';
  2493. $return['use_iconv'] = true;
  2494. $return['use_mbstring'] = true;
  2495. break;
  2496. // UCS-2LE
  2497. case 'ucs-2le':
  2498. case 'ucs2le':
  2499. case 'utf-16le':
  2500. case 'utf16le':
  2501. $return['encoding'] = 'UCS-2LE';
  2502. $return['use_iconv'] = true;
  2503. $return['use_mbstring'] = true;
  2504. break;
  2505. // UCS-2-INTERNAL
  2506. case 'ucs-2-internal':
  2507. case 'ucs2internal':
  2508. $return['encoding'] = 'UCS-2-INTERNAL';
  2509. $return['use_iconv'] = true;
  2510. break;
  2511. // UCS-4
  2512. case 'ucs-4':
  2513. case 'ucs4':
  2514. case 'utf-32':
  2515. case 'utf32':
  2516. $return['encoding'] = 'UCS-4';
  2517. $return['use_iconv'] = true;
  2518. $return['use_mbstring'] = true;
  2519. break;
  2520. // UCS-4BE
  2521. case 'ucs-4be':
  2522. case 'ucs4be':
  2523. case 'utf-32be':
  2524. case 'utf32be':
  2525. $return['encoding'] = 'UCS-4BE';
  2526. $return['use_iconv'] = true;
  2527. $return['use_mbstring'] = true;
  2528. break;
  2529. // UCS-4LE
  2530. case 'ucs-4le':
  2531. case 'ucs4le':
  2532. case 'utf-32le':
  2533. case 'utf32le':
  2534. $return['encoding'] = 'UCS-4LE';
  2535. $return['use_iconv'] = true;
  2536. $return['use_mbstring'] = true;
  2537. break;
  2538. // UCS-4-INTERNAL
  2539. case 'ucs-4-internal':
  2540. case 'ucs4internal':
  2541. $return['encoding'] = 'UCS-4-INTERNAL';
  2542. $return['use_iconv'] = true;
  2543. break;
  2544. // UCS-16
  2545. case 'ucs-16':
  2546. case 'ucs16':
  2547. $return['encoding'] = 'UCS-16';
  2548. $return['use_iconv'] = true;
  2549. $return['use_mbstring'] = true;
  2550. break;
  2551. // UCS-16BE
  2552. case 'ucs-16be':
  2553. case 'ucs16be':
  2554. $return['encoding'] = 'UCS-16BE';
  2555. $return['use_iconv'] = true;
  2556. $return['use_mbstring'] = true;
  2557. break;
  2558. // UCS-16LE
  2559. case 'ucs-16le':
  2560. case 'ucs16le':
  2561. $return['encoding'] = 'UCS-16LE';
  2562. $return['use_iconv'] = true;
  2563. $return['use_mbstring'] = true;
  2564. break;
  2565. // UCS-32
  2566. case 'ucs-32':
  2567. case 'ucs32':
  2568. $return['encoding'] = 'UCS-32';
  2569. $return['use_iconv'] = true;
  2570. $return['use_mbstring'] = true;
  2571. break;
  2572. // UCS-32BE
  2573. case 'ucs-32be':
  2574. case 'ucs32be':
  2575. $return['encoding'] = 'UCS-32BE';
  2576. $return['use_iconv'] = true;
  2577. $return['use_mbstring'] = true;
  2578. break;
  2579. // UCS-32LE
  2580. case 'ucs-32le':
  2581. case 'ucs32le':
  2582. $return['encoding'] = 'UCS-32LE';
  2583. $return['use_iconv'] = true;
  2584. $return['use_mbstring'] = true;
  2585. break;
  2586. // UTF-7
  2587. case 'utf-7':
  2588. case 'utf7':
  2589. $return['encoding'] = 'UTF-7';
  2590. $return['use_iconv'] = true;
  2591. $return['use_mbstring'] = true;
  2592. break;
  2593. // UTF7-IMAP
  2594. case 'utf-7-imap':
  2595. case 'utf7-imap':
  2596. case 'utf7imap':
  2597. $return['encoding'] = 'UTF7-IMAP';
  2598. $return['use_mbstring'] = true;
  2599. break;
  2600. // VISCII - Vietnamese ASCII
  2601. case 'viscii':
  2602. $return['encoding'] = 'VISCII';
  2603. $return['use_iconv'] = true;
  2604. break;
  2605. // Windows-specific Central & Eastern Europe
  2606. case 'cp1250':
  2607. case 'windows-1250':
  2608. case 'win-1250':
  2609. case '1250':
  2610. $return['encoding'] = 'Windows-1250';
  2611. $return['use_iconv'] = true;
  2612. break;
  2613. // Windows-specific Cyrillic
  2614. case 'cp1251':
  2615. case 'windows-1251':
  2616. case 'win-1251':
  2617. case '1251':
  2618. $return['encoding'] = 'Windows-1251';
  2619. $return['use_iconv'] = true;
  2620. $return['use_mbstring'] = true;
  2621. break;
  2622. // Windows-specific Western Europe
  2623. case 'cp1252':
  2624. case 'windows-1252':
  2625. case '1252':
  2626. $return['encoding'] = 'Windows-1252';
  2627. $return['use_iconv'] = true;
  2628. $return['use_mbstring'] = true;
  2629. break;
  2630. // Windows-specific Greek
  2631. case 'cp1253':
  2632. case 'windows-1253':
  2633. case '1253':
  2634. $return['encoding'] = 'Windows-1253';
  2635. $return['use_iconv'] = true;
  2636. break;
  2637. // Windows-specific Turkish
  2638. case 'cp1254':
  2639. case 'windows-1254':
  2640. case '1254':
  2641. $return['encoding'] = 'Windows-1254';
  2642. $return['use_iconv'] = true;
  2643. break;
  2644. // Windows-specific Hebrew
  2645. case 'cp1255':
  2646. case 'windows-1255':
  2647. case '1255':
  2648. $return['encoding'] = 'Windows-1255';
  2649. $return['use_iconv'] = true;
  2650. break;
  2651. // Windows-specific Arabic
  2652. case 'cp1256':
  2653. case 'windows-1256':
  2654. case '1256':
  2655. $return['encoding'] = 'Windows-1256';
  2656. $return['use_iconv'] = true;
  2657. break;
  2658. // Windows-specific Baltic
  2659. case 'cp1257':
  2660. case 'windows-1257':
  2661. case '1257':
  2662. $return['encoding'] = 'Windows-1257';
  2663. $return['use_iconv'] = true;
  2664. break;
  2665. // Windows-specific Vietnamese
  2666. case 'cp1258':
  2667. case 'windows-1258':
  2668. case '1258':
  2669. $return['encoding'] = 'Windows-1258';
  2670. $return['use_iconv'] = true;
  2671. break;
  2672. // Default to UTF-8
  2673. default:
  2674. $return['encoding'] = 'UTF-8';
  2675. $return['use_iconv'] = true;
  2676. $return['use_mbstring'] = true;
  2677. break;
  2678. }
  2679. // Then, return it.
  2680. return $return;
  2681. }
  2682. public function get_curl_version()
  2683. {
  2684. $curl = 0;
  2685. if (is_array(curl_version())) {
  2686. $curl = curl_version();
  2687. $curl = $curl['version'];
  2688. } else {
  2689. $curl = curl_version();
  2690. $curl = explode(' ', $curl);
  2691. $curl = explode('/', $curl[0]);
  2692. $curl = $curl[1];
  2693. }
  2694. return $curl;
  2695. }
  2696. public function is_a_class($class1, $class2)
  2697. {
  2698. if (class_exists($class1)) {
  2699. $classes = array(strtolower($class1));
  2700. while ($class1 = get_parent_class($class1)) {
  2701. $classes[] = strtolower($class1);
  2702. }
  2703. return in_array(strtolower($class2), $classes);
  2704. } else {
  2705. return false;
  2706. }
  2707. }
  2708. }
  2709. class SimplePie_Locator
  2710. {
  2711. public $useragent;
  2712. public $timeout;
  2713. public $file;
  2714. public $local;
  2715. public $elsewhere;
  2716. public $file_class = 'SimplePie_File';
  2717. public function __construct(&$file, $timeout = 10, $useragent = null, $file_class = 'SimplePie_File')
  2718. {
  2719. if (!is_a($file, 'SimplePie_File')) {
  2720. $this->file = new $this->file_class($file, $timeout, $useragent);
  2721. } else {
  2722. $this->file =& $file;
  2723. }
  2724. $this->file_class = $file_class;
  2725. $this->useragent = $useragent;
  2726. $this->timeout = $timeout;
  2727. }
  2728. public function find()
  2729. {
  2730. if ($this->is_feed($this->file)) {
  2731. return $this->file->url;
  2732. }
  2733. $autodiscovery = $this->autodiscovery($this->file);
  2734. if ($autodiscovery) {
  2735. return $autodiscovery;
  2736. }
  2737. if ($this->get_links($this->file)) {
  2738. if (!empty($this->local)) {
  2739. $extension_local = $this->extension($this->local);
  2740. if ($extension_local) {
  2741. return $extension_local;
  2742. }
  2743. $body_local = $this->body($this->local);
  2744. if ($body_local) {
  2745. return $body_local;
  2746. }
  2747. }
  2748. if (!empty($this->elsewhere)) {
  2749. $extension_elsewhere = $this->extension($this->elsewhere);
  2750. if ($extension_elsewhere) {
  2751. return $extension_elsewhere;
  2752. }
  2753. $body_elsewhere = $this->body($this->elsewhere);
  2754. if ($body_elsewhere) {
  2755. return $body_elsewhere;
  2756. }
  2757. }
  2758. }
  2759. return false;
  2760. }
  2761. public function is_feed(&$file)
  2762. {
  2763. if (!is_a($file, 'SimplePie_File')) {
  2764. if (isset($this)) {
  2765. $file2 = new $this->file_class($file, $this->timeout, 5, null, $this->useragent);
  2766. } else {
  2767. $file2 = new $this->file_class($file);
  2768. }
  2769. $file2->body();
  2770. $file2->close();
  2771. } else {
  2772. $file2 =& $file;
  2773. }
  2774. $body = preg_replace('/<\!-(.*)-\>/msiU', '', $file2->body());
  2775. if (preg_match('/<(\w+\:)?rss/msiU', $body) || preg_match('/<(\w+\:)?RDF/mi', $body) || preg_match('/<(\w+\:)?feed/mi', $body)) {
  2776. return true;
  2777. }
  2778. return false;
  2779. }
  2780. public function autodiscovery(&$file)
  2781. {
  2782. $links = (new SimplePie_Misc)->get_element('link', $file->body());
  2783. $done = array();
  2784. foreach ($links as $link) {
  2785. if (!empty($link['attribs']['TYPE']['data']) && !empty($link['attribs']['HREF']['data']) && !empty($link['attribs']['REL']['data'])) {
  2786. $rel = preg_split('/\s+/', strtolower(trim($link['attribs']['REL']['data'])));
  2787. $type = preg_match('/^(application\/rss\+xml|application\/atom\+xml|application\/rdf\+xml|application\/xml\+rss|application\/xml\+atom|application\/xml\+rdf|application\/xml|application\/x\.atom\+xml|text\/xml)(;|$)/msiU', trim($link['attribs']['TYPE']['data']));
  2788. $href = (new SimplePie_Misc)->absolutize_url(trim($link['attribs']['HREF']['data']), $this->file->url);
  2789. if (!in_array($href, $done) && in_array('alternate', $rel) && $type) {
  2790. $feed = $this->is_feed($href);
  2791. if ($feed) {
  2792. return $href;
  2793. }
  2794. }
  2795. $done[] = $href;
  2796. }
  2797. }
  2798. return false;
  2799. }
  2800. public function get_links(&$file)
  2801. {
  2802. $links = (new SimplePie_Misc)->get_element('a', $file->body());
  2803. foreach ($links as $link) {
  2804. if (!empty($link['attribs']['HREF']['data'])) {
  2805. $href = trim($link['attribs']['HREF']['data']);
  2806. $parsed = (new SimplePie_Misc)->parse_url($href);
  2807. if (empty($parsed['scheme']) || $parsed['scheme'] != 'javascript') {
  2808. $current = (new SimplePie_Misc)->parse_url($this->file->url);
  2809. if (empty($parsed['authority']) || $parsed['authority'] == $current['authority']) {
  2810. $this->local[] = (new SimplePie_Misc)->absolutize_url($href, $this->file->url);
  2811. } else {
  2812. $this->elsewhere[] = (new SimplePie_Misc)->absolutize_url($href, $this->file->url);
  2813. }
  2814. }
  2815. }
  2816. }
  2817. if (!empty($this->local)) {
  2818. $this->local = array_unique($this->local);
  2819. }
  2820. if (!empty($this->elsewhere)) {
  2821. $this->elsewhere = array_unique($this->elsewhere);
  2822. }
  2823. if (!empty($this->local) || !empty($this->elsewhere)) {
  2824. return true;
  2825. }
  2826. return false;
  2827. }
  2828. public function extension(&$array)
  2829. {
  2830. foreach ($array as $key => $value) {
  2831. $value = (new SimplePie_Misc)->absolutize_url($value, $this->file->url);
  2832. if (in_array(strrchr($value, '.'), array('.rss', '.rdf', '.atom', '.xml'))) {
  2833. if ($this->is_feed($value)) {
  2834. return $value;
  2835. } else {
  2836. unset($array[$key]);
  2837. }
  2838. }
  2839. }
  2840. return false;
  2841. }
  2842. public function body(&$array)
  2843. {
  2844. foreach ($array as $key => $value) {
  2845. $value = (new SimplePie_Misc)->absolutize_url($value, $this->file->url);
  2846. if (preg_match('/(rss|rdf|atom|xml)/i', $value)) {
  2847. if ($this->is_feed($value)) {
  2848. return $value;
  2849. } else {
  2850. unset($array[$key]);
  2851. }
  2852. }
  2853. }
  2854. return false;
  2855. }
  2856. }
  2857. class SimplePie_Parser
  2858. {
  2859. public $encoding;
  2860. public $data;
  2861. public $namespaces = array('xml' => 'HTTP://WWW.W3.ORG/XML/1998/NAMESPACE', 'atom' => 'ATOM', 'rss2' => 'RSS', 'rdf' => 'RDF', 'rss1' => 'RSS', 'dc' => 'DC', 'xhtml' => 'XHTML', 'content' => 'CONTENT');
  2862. public $xml;
  2863. public $error_code;
  2864. public $error_string;
  2865. public $current_line;
  2866. public $current_column;
  2867. public $current_byte;
  2868. public $tag_name;
  2869. public $inside_item;
  2870. public $item_number = 0;
  2871. public $inside_channel;
  2872. public $author_number= 0;
  2873. public $category_number = 0;
  2874. public $enclosure_number = 0;
  2875. public $link_number = 0;
  2876. public $item_link_number = 0;
  2877. public $inside_image;
  2878. public $attribs;
  2879. public $is_first;
  2880. public $inside_author;
  2881. public $depth_inside_item = 0;
  2882. public function __construct($data, $encoding, $return_xml = false)
  2883. {
  2884. $this->encoding = $encoding;
  2885. // Strip BOM:
  2886. // UTF-32 Big Endian BOM
  2887. if (strpos($data, sprintf('%c%c%c%c', 0x00, 0x00, 0xFE, 0xFF)) === 0) {
  2888. $data = substr($data, 4);
  2889. }
  2890. // UTF-32 Little Endian BOM
  2891. elseif (strpos($data, sprintf('%c%c%c%c', 0xFF, 0xFE, 0x00, 0x00)) === 0) {
  2892. $data = substr($data, 4);
  2893. }
  2894. // UTF-16 Big Endian BOM
  2895. elseif (strpos($data, sprintf('%c%c', 0xFE, 0xFF)) === 0) {
  2896. $data = substr($data, 2);
  2897. }
  2898. // UTF-16 Little Endian BOM
  2899. elseif (strpos($data, sprintf('%c%c', 0xFF, 0xFE)) === 0) {
  2900. $data = substr($data, 2);
  2901. }
  2902. // UTF-8 BOM
  2903. elseif (strpos($data, sprintf('%c%c%c', 0xEF, 0xBB, 0xBF)) === 0) {
  2904. $data = substr($data, 3);
  2905. }
  2906. // Make sure the XML prolog is sane and has the correct encoding
  2907. if (preg_match('/^<\?xml(.*)?>/msiU', $data, $prolog)) {
  2908. $data = substr_replace($data, '', 0, strlen($prolog[0]));
  2909. }
  2910. $data = "<?xml version='1.0' encoding='$encoding'?>\n" . $data;
  2911. // Put some data into CDATA blocks
  2912. // If we're RSS
  2913. if ((stristr($data, '<rss') || preg_match('/<([a-z0-9]+\:)?RDF/mi', $data)) && (preg_match('/<([a-z0-9]+\:)?channel/mi', $data) || preg_match('/<([a-z0-9]+\:)?item/mi', $data))) {
  2914. $sp_elements = array(
  2915. 'author',
  2916. 'category',
  2917. 'copyright',
  2918. 'description',
  2919. 'docs',
  2920. 'generator',
  2921. 'guid',
  2922. 'language',
  2923. 'lastBuildDate',
  2924. 'link',
  2925. 'managingEditor',
  2926. 'pubDate',
  2927. 'title',
  2928. 'url',
  2929. 'webMaster',
  2930. );
  2931. }
  2932. // Or if we're Atom
  2933. else {
  2934. $sp_elements = array(
  2935. 'content',
  2936. 'copyright',
  2937. 'name',
  2938. 'subtitle',
  2939. 'summary',
  2940. 'tagline',
  2941. 'title',
  2942. );
  2943. }
  2944. foreach ($sp_elements as $full) {
  2945. $data = preg_replace_callback("/<($full)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'))*)\s*(\/>|>(.*)<\/$full>)/msiU", array(&$this, 'add_cdata'), $data);
  2946. }
  2947. foreach ($sp_elements as $full) {
  2948. // Deal with CDATA within CDATA (this can be caused by us inserting CDATA above)
  2949. $data = preg_replace_callback("/<($full)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'))*)\s*(\/>|><!\[CDATA\[(.*)\]\]><\/$full>)/msiU", array(&$this, 'cdata_in_cdata'), $data);
  2950. }
  2951. // Return the XML, if so desired
  2952. if ($return_xml) {
  2953. $this->data =& $data;
  2954. return;
  2955. }
  2956. // Create the parser
  2957. $this->xml = xml_parser_create_ns($encoding);
  2958. xml_parser_set_option($this->xml, XML_OPTION_SKIP_WHITE, 1);
  2959. xml_set_object($this->xml, $this);
  2960. xml_set_character_data_handler($this->xml, 'data_handler');
  2961. xml_set_element_handler($this->xml, 'start_handler', 'end_handler');
  2962. xml_set_start_namespace_decl_handler($this->xml, 'start_name_space');
  2963. xml_set_end_namespace_decl_handler($this->xml, 'end_name_space');
  2964. // Parse!
  2965. if (!xml_parse($this->xml, $data)) {
  2966. $this->data = null;
  2967. $this->error_code = xml_get_error_code($this->xml);
  2968. $this->error_string = xml_error_string($this->error_code);
  2969. }
  2970. $this->current_line = xml_get_current_line_number($this->xml);
  2971. $this->current_column = xml_get_current_column_number($this->xml);
  2972. $this->current_byte = xml_get_current_byte_index($this->xml);
  2973. xml_parser_free($this->xml);
  2974. return;
  2975. }
  2976. public function add_cdata($match)
  2977. {
  2978. if (isset($match[10])) {
  2979. return "<$match[1]$match[2]><![CDATA[$match[10]]]></$match[1]>";
  2980. }
  2981. return $match[0];
  2982. }
  2983. public function cdata_in_cdata($match)
  2984. {
  2985. if (isset($match[10])) {
  2986. $match[10] = preg_replace_callback('/<!\[CDATA\[(.*)\]\]>/msiU', array(&$this, 'real_cdata_in_cdata'), $match[10]);
  2987. return "<$match[1]$match[2]><![CDATA[$match[10]]]></$match[1]>";
  2988. }
  2989. return $match[0];
  2990. }
  2991. public function real_cdata_in_cdata($match)
  2992. {
  2993. return htmlspecialchars($match[1], ENT_NOQUOTES);
  2994. }
  2995. public function do_add_content(&$array, $data)
  2996. {
  2997. if ($this->is_first) {
  2998. $array['data'] = $data;
  2999. $array['attribs'] = $this->attribs;
  3000. } else {
  3001. $array['data'] .= $data;
  3002. }
  3003. }
  3004. public function start_handler($parser, $name, $attribs)
  3005. {
  3006. $this->tag_name = $name;
  3007. $this->attribs = $attribs;
  3008. $this->is_first = true;
  3009. if ($this->inside_item) {
  3010. $this->depth_inside_item++;
  3011. }
  3012. switch ($this->tag_name) {
  3013. case 'ITEM':
  3014. case $this->namespaces['rss2'] . ':ITEM':
  3015. case $this->namespaces['rss1'] . ':ITEM':
  3016. case 'ENTRY':
  3017. case $this->namespaces['atom'] . ':ENTRY':
  3018. $this->inside_item = true;
  3019. $this->do_add_content($this->data['items'][$this->item_number], '');
  3020. break;
  3021. case 'CHANNEL':
  3022. case $this->namespaces['rss2'] . ':CHANNEL':
  3023. case $this->namespaces['rss1'] . ':CHANNEL':
  3024. $this->inside_channel = true;
  3025. break;
  3026. case 'RSS':
  3027. case $this->namespaces['rss2'] . ':RSS':
  3028. $this->data['feedinfo']['type'] = 'RSS';
  3029. $this->do_add_content($this->data['feeddata'], '');
  3030. if (!empty($attribs['VERSION'])) {
  3031. $this->data['feedinfo']['version'] = trim($attribs['VERSION']);
  3032. }
  3033. break;
  3034. case $this->namespaces['rdf'] . ':RDF':
  3035. $this->data['feedinfo']['type'] = 'RSS';
  3036. $this->do_add_content($this->data['feeddata'], '');
  3037. $this->data['feedinfo']['version'] = 1;
  3038. break;
  3039. case 'FEED':
  3040. case $this->namespaces['atom'] . ':FEED':
  3041. $this->data['feedinfo']['type'] = 'Atom';
  3042. $this->do_add_content($this->data['feeddata'], '');
  3043. if (!empty($attribs['VERSION'])) {
  3044. $this->data['feedinfo']['version'] = trim($attribs['VERSION']);
  3045. }
  3046. break;
  3047. case 'IMAGE':
  3048. case $this->namespaces['rss2'] . ':IMAGE':
  3049. case $this->namespaces['rss1'] . ':IMAGE':
  3050. if ($this->inside_channel) {
  3051. $this->inside_image = true;
  3052. }
  3053. break;
  3054. }
  3055. if (!empty($this->data['feedinfo']['type']) && $this->data['feedinfo']['type'] == 'Atom' && ($this->tag_name == 'AUTHOR' || $this->tag_name == $this->namespaces['atom'] . ':AUTHOR')) {
  3056. $this->inside_author = true;
  3057. }
  3058. $this->data_handler($this->xml, '');
  3059. }
  3060. public function data_handler($parser, $data)
  3061. {
  3062. if ($this->inside_item && $this->depth_inside_item == 1) {
  3063. switch ($this->tag_name) {
  3064. case 'TITLE':
  3065. case $this->namespaces['rss1'] . ':TITLE':
  3066. case $this->namespaces['rss2'] . ':TITLE':
  3067. case $this->namespaces['atom'] . ':TITLE':
  3068. $this->do_add_content($this->data['items'][$this->item_number]['title'], $data);
  3069. break;
  3070. case $this->namespaces['dc'] . ':TITLE':
  3071. $this->do_add_content($this->data['items'][$this->item_number]['dc:title'], $data);
  3072. break;
  3073. case 'CONTENT':
  3074. case $this->namespaces['atom'] . ':CONTENT':
  3075. $this->do_add_content($this->data['items'][$this->item_number]['content'], $data);
  3076. break;
  3077. case $this->namespaces['content'] . ':ENCODED':
  3078. $this->do_add_content($this->data['items'][$this->item_number]['encoded'], $data);
  3079. break;
  3080. case 'SUMMARY':
  3081. case $this->namespaces['atom'] . ':SUMMARY':
  3082. $this->do_add_content($this->data['items'][$this->item_number]['summary'], $data);
  3083. break;
  3084. case 'LONGDESC':
  3085. $this->do_add_content($this->data['items'][$this->item_number]['longdesc'], $data);
  3086. break;
  3087. case 'DESCRIPTION':
  3088. case $this->namespaces['rss1'] . ':DESCRIPTION':
  3089. case $this->namespaces['rss2'] . ':DESCRIPTION':
  3090. $this->do_add_content($this->data['items'][$this->item_number]['description'], $data);
  3091. break;
  3092. case $this->namespaces['dc'] . ':DESCRIPTION':
  3093. $this->do_add_content($this->data['items'][$this->item_number]['dc:description'], $data);
  3094. break;
  3095. case 'LINK':
  3096. case $this->namespaces['rss1'] . ':LINK':
  3097. case $this->namespaces['rss2'] . ':LINK':
  3098. case $this->namespaces['atom'] . ':LINK':
  3099. $this->do_add_content($this->data['items'][$this->item_number]['link'][$this->item_link_number], $data);
  3100. break;
  3101. case 'ENCLOSURE':
  3102. case $this->namespaces['rss1'] . ':ENCLOSURE':
  3103. case $this->namespaces['rss2'] . ':ENCLOSURE':
  3104. case $this->namespaces['atom'] . ':ENCLOSURE':
  3105. $this->do_add_content($this->data['items'][$this->item_number]['enclosure'][$this->enclosure_number], $data);
  3106. break;
  3107. case 'GUID':
  3108. case $this->namespaces['rss1'] . ':GUID':
  3109. case $this->namespaces['rss2'] . ':GUID':
  3110. $this->do_add_content($this->data['items'][$this->item_number]['guid'], $data);
  3111. break;
  3112. case 'ID':
  3113. case $this->namespaces['atom'] . ':ID':
  3114. $this->do_add_content($this->data['items'][$this->item_number]['id'], $data);
  3115. break;
  3116. case 'PUBDATE':
  3117. case $this->namespaces['rss1'] . ':PUBDATE':
  3118. case $this->namespaces['rss2'] . ':PUBDATE':
  3119. $this->do_add_content($this->data['items'][$this->item_number]['pubdate'], $data);
  3120. break;
  3121. case $this->namespaces['dc'] . ':DATE':
  3122. $this->do_add_content($this->data['items'][$this->item_number]['dc:date'], $data);
  3123. break;
  3124. case 'ISSUED':
  3125. case $this->namespaces['atom'] . ':ISSUED':
  3126. $this->do_add_content($this->data['items'][$this->item_number]['issued'], $data);
  3127. break;
  3128. case 'PUBLISHED':
  3129. case $this->namespaces['atom'] . ':PUBLISHED':
  3130. $this->do_add_content($this->data['items'][$this->item_number]['published'], $data);
  3131. break;
  3132. case 'MODIFIED':
  3133. case $this->namespaces['atom'] . ':MODIFIED':
  3134. $this->do_add_content($this->data['items'][$this->item_number]['modified'], $data);
  3135. break;
  3136. case 'UPDATED':
  3137. case $this->namespaces['atom'] . ':UPDATED':
  3138. $this->do_add_content($this->data['items'][$this->item_number]['updated'], $data);
  3139. break;
  3140. case 'CATEGORY':
  3141. case $this->namespaces['rss1'] . ':CATEGORY':
  3142. case $this->namespaces['rss2'] . ':CATEGORY':
  3143. case $this->namespaces['atom'] . ':CATEGORY':
  3144. $this->do_add_content($this->data['items'][$this->item_number]['category'][$this->category_number], $data);
  3145. break;
  3146. case $this->namespaces['dc'] . ':SUBJECT':
  3147. $this->do_add_content($this->data['items'][$this->item_number]['subject'][$this->category_number], $data);
  3148. break;
  3149. case $this->namespaces['dc'] . ':CREATOR':
  3150. $this->do_add_content($this->data['items'][$this->item_number]['creator'][$this->author_number], $data);
  3151. break;
  3152. case 'AUTHOR':
  3153. case $this->namespaces['rss1'] . ':AUTHOR':
  3154. case $this->namespaces['rss2'] . ':AUTHOR':
  3155. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['rss'], $data);
  3156. break;
  3157. }
  3158. if ($this->inside_author) {
  3159. switch ($this->tag_name) {
  3160. case 'NAME':
  3161. case $this->namespaces['atom'] . ':NAME':
  3162. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['name'], $data);
  3163. break;
  3164. case 'URL':
  3165. case $this->namespaces['atom'] . ':URL':
  3166. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['url'], $data);
  3167. break;
  3168. case 'URI':
  3169. case $this->namespaces['atom'] . ':URI':
  3170. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['uri'], $data);
  3171. break;
  3172. case 'HOMEPAGE':
  3173. case $this->namespaces['atom'] . ':HOMEPAGE':
  3174. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['homepage'], $data);
  3175. break;
  3176. case 'EMAIL':
  3177. case $this->namespaces['atom'] . ':EMAIL':
  3178. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['email'], $data);
  3179. break;
  3180. }
  3181. }
  3182. } elseif (($this->inside_channel && !$this->inside_image) || (isset($this->data['feedinfo']['type']) && $this->data['feedinfo']['type'] == 'Atom')) {
  3183. switch ($this->tag_name) {
  3184. case 'TITLE':
  3185. case $this->namespaces['rss1'] . ':TITLE':
  3186. case $this->namespaces['rss2'] . ':TITLE':
  3187. case $this->namespaces['atom'] . ':TITLE':
  3188. $this->do_add_content($this->data['info']['title'], $data);
  3189. break;
  3190. case 'LINK':
  3191. case $this->namespaces['rss1'] . ':LINK':
  3192. case $this->namespaces['rss2'] . ':LINK':
  3193. case $this->namespaces['atom'] . ':LINK':
  3194. $this->do_add_content($this->data['info']['link'][$this->link_number], $data);
  3195. break;
  3196. case 'DESCRIPTION':
  3197. case $this->namespaces['rss1'] . ':DESCRIPTION':
  3198. case $this->namespaces['rss2'] . ':DESCRIPTION':
  3199. $this->do_add_content($this->data['info']['description'], $data);
  3200. break;
  3201. case $this->namespaces['dc'] . ':DESCRIPTION':
  3202. $this->do_add_content($this->data['info']['dc:description'], $data);
  3203. break;
  3204. case 'TAGLINE':
  3205. case $this->namespaces['atom'] . ':TAGLINE':
  3206. $this->do_add_content($this->data['info']['tagline'], $data);
  3207. break;
  3208. case 'SUBTITLE':
  3209. case $this->namespaces['atom'] . ':SUBTITLE':
  3210. $this->do_add_content($this->data['info']['subtitle'], $data);
  3211. break;
  3212. case 'COPYRIGHT':
  3213. case $this->namespaces['rss1'] . ':COPYRIGHT':
  3214. case $this->namespaces['rss2'] . ':COPYRIGHT':
  3215. case $this->namespaces['atom'] . ':COPYRIGHT':
  3216. $this->do_add_content($this->data['info']['copyright'], $data);
  3217. break;
  3218. case 'LANGUAGE':
  3219. case $this->namespaces['rss1'] . ':LANGUAGE':
  3220. case $this->namespaces['rss2'] . ':LANGUAGE':
  3221. $this->do_add_content($this->data['info']['language'], $data);
  3222. break;
  3223. case 'LOGO':
  3224. case $this->namespaces['atom'] . ':LOGO':
  3225. $this->do_add_content($this->data['info']['logo'], $data);
  3226. break;
  3227. }
  3228. } elseif ($this->inside_channel && $this->inside_image) {
  3229. switch ($this->tag_name) {
  3230. case 'TITLE':
  3231. case $this->namespaces['rss1'] . ':TITLE':
  3232. case $this->namespaces['rss2'] . ':TITLE':
  3233. $this->do_add_content($this->data['info']['image']['title'], $data);
  3234. break;
  3235. case 'URL':
  3236. case $this->namespaces['rss1'] . ':URL':
  3237. case $this->namespaces['rss2'] . ':URL':
  3238. $this->do_add_content($this->data['info']['image']['url'], $data);
  3239. break;
  3240. case 'LINK':
  3241. case $this->namespaces['rss1'] . ':LINK':
  3242. case $this->namespaces['rss2'] . ':LINK':
  3243. $this->do_add_content($this->data['info']['image']['link'], $data);
  3244. break;
  3245. case 'WIDTH':
  3246. case $this->namespaces['rss1'] . ':WIDTH':
  3247. case $this->namespaces['rss2'] . ':WIDTH':
  3248. $this->do_add_content($this->data['info']['image']['width'], $data);
  3249. break;
  3250. case 'HEIGHT':
  3251. case $this->namespaces['rss1'] . ':HEIGHT':
  3252. case $this->namespaces['rss2'] . ':HEIGHT':
  3253. $this->do_add_content($this->data['info']['image']['height'], $data);
  3254. break;
  3255. }
  3256. }
  3257. $this->is_first = false;
  3258. }
  3259. public function end_handler($parser, $name)
  3260. {
  3261. $this->tag_name = '';
  3262. switch ($name) {
  3263. case 'ITEM':
  3264. case $this->namespaces['rss1'] . ':ITEM':
  3265. case $this->namespaces['rss2'] . ':ITEM':
  3266. case 'ENTRY':
  3267. case $this->namespaces['atom'] . ':ENTRY':
  3268. $this->inside_item = false;
  3269. $this->item_number++;
  3270. $this->author_number = 0;
  3271. $this->category_number = 0;
  3272. $this->enclosure_number = 0;
  3273. $this->item_link_number = 0;
  3274. break;
  3275. case 'CHANNEL':
  3276. case $this->namespaces['rss1'] . ':CHANNEL':
  3277. case $this->namespaces['rss2'] . ':CHANNEL':
  3278. $this->inside_channel = false;
  3279. break;
  3280. case 'IMAGE':
  3281. case $this->namespaces['rss1'] . ':IMAGE':
  3282. case $this->namespaces['rss2'] . ':IMAGE':
  3283. $this->inside_image = false;
  3284. break;
  3285. case 'AUTHOR':
  3286. case $this->namespaces['rss1'] . ':AUTHOR':
  3287. case $this->namespaces['rss2'] . ':AUTHOR':
  3288. case $this->namespaces['atom'] . ':AUTHOR':
  3289. $this->author_number++;
  3290. $this->inside_author = false;
  3291. break;
  3292. case 'CATEGORY':
  3293. case $this->namespaces['rss1'] . ':CATEGORY':
  3294. case $this->namespaces['rss2'] . ':CATEGORY':
  3295. case $this->namespaces['atom'] . ':CATEGORY':
  3296. case $this->namespaces['dc'] . ':SUBJECT':
  3297. $this->category_number++;
  3298. break;
  3299. case 'ENCLOSURE':
  3300. case $this->namespaces['rss1'] . ':ENCLOSURE':
  3301. case $this->namespaces['rss2'] . ':ENCLOSURE':
  3302. $this->enclosure_number++;
  3303. break;
  3304. case 'LINK':
  3305. case $this->namespaces['rss1'] . ':LINK':
  3306. case $this->namespaces['rss2'] . ':LINK':
  3307. case $this->namespaces['atom'] . ':LINK':
  3308. if ($this->inside_item) {
  3309. $this->item_link_number++;
  3310. } else {
  3311. $this->link_number++;
  3312. }
  3313. break;
  3314. }
  3315. if ($this->inside_item) {
  3316. $this->depth_inside_item--;
  3317. }
  3318. }
  3319. public function start_name_space($parser, $prefix, $uri = null)
  3320. {
  3321. $prefix = strtoupper($prefix);
  3322. $uri = strtoupper($uri);
  3323. if ($prefix == 'ATOM' || $uri == 'HTTP://WWW.W3.ORG/2005/ATOM' || $uri == 'HTTP://PURL.ORG/ATOM/NS#') {
  3324. $this->namespaces['atom'] = $uri;
  3325. } elseif ($prefix == 'RSS2' || $uri == 'HTTP://BACKEND.USERLAND.COM/RSS2') {
  3326. $this->namespaces['rss2'] = $uri;
  3327. } elseif ($prefix == 'RDF' || $uri == 'HTTP://WWW.W3.ORG/1999/02/22-RDF-SYNTAX-NS#') {
  3328. $this->namespaces['rdf'] = $uri;
  3329. } elseif ($prefix == 'RSS' || $uri == 'HTTP://PURL.ORG/RSS/1.0/' || $uri == 'HTTP://MY.NETSCAPE.COM/RDF/SIMPLE/0.9/') {
  3330. $this->namespaces['rss1'] = $uri;
  3331. } elseif ($prefix == 'DC' || $uri == 'HTTP://PURL.ORG/DC/ELEMENTS/1.1/') {
  3332. $this->namespaces['dc'] = $uri;
  3333. } elseif ($prefix == 'XHTML' || $uri == 'HTTP://WWW.W3.ORG/1999/XHTML') {
  3334. $this->namespaces['xhtml'] = $uri;
  3335. $this->xhtml_prefix = $prefix;
  3336. } elseif ($prefix == 'CONTENT' || $uri == 'HTTP://PURL.ORG/RSS/1.0/MODULES/CONTENT/') {
  3337. $this->namespaces['content'] = $uri;
  3338. }
  3339. }
  3340. public function end_name_space($parser, $prefix)
  3341. {
  3342. if ($key = array_search(strtoupper($prefix), $this->namespaces)) {
  3343. if ($key == 'atom') {
  3344. $this->namespaces['atom'] = 'ATOM';
  3345. } elseif ($key == 'rss2') {
  3346. $this->namespaces['rss2'] = 'RSS';
  3347. } elseif ($key == 'rdf') {
  3348. $this->namespaces['rdf'] = 'RDF';
  3349. } elseif ($key == 'rss1') {
  3350. $this->namespaces['rss1'] = 'RSS';
  3351. } elseif ($key == 'dc') {
  3352. $this->namespaces['dc'] = 'DC';
  3353. } elseif ($key == 'xhtml') {
  3354. $this->namespaces['xhtml'] = 'XHTML';
  3355. $this->xhtml_prefix = 'XHTML';
  3356. } elseif ($key == 'content') {
  3357. $this->namespaces['content'] = 'CONTENT';
  3358. }
  3359. }
  3360. }
  3361. }
  3362. class SimplePie_Sanitize
  3363. {
  3364. // Private vars
  3365. public $feedinfo;
  3366. public $info;
  3367. public $items;
  3368. public $feed_xmlbase;
  3369. public $item_xmlbase;
  3370. public $attribs;
  3371. public $cached_entities;
  3372. public $cache_convert_entities;
  3373. // Options
  3374. public $remove_div = true;
  3375. public $strip_ads = false;
  3376. public $replace_headers = false;
  3377. public $bypass_image_hotlink = false;
  3378. public $bypass_image_hotlink_page = false;
  3379. public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  3380. public $encode_instead_of_strip = false;
  3381. public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur');
  3382. public $input_encoding = 'UTF-8';
  3383. public $output_encoding = 'UTF-8';
  3384. public $item_class = 'SimplePie_Item';
  3385. public $author_class = 'SimplePie_Author';
  3386. public $enclosure_class = 'SimplePie_Enclosure';
  3387. public function remove_div($enable = true)
  3388. {
  3389. $this->remove_div = (bool) $enable;
  3390. }
  3391. public function strip_ads($enable = false)
  3392. {
  3393. $this->strip_ads = (bool) $enable;
  3394. }
  3395. public function replace_headers($enable = false)
  3396. {
  3397. $this->enable_headers = (bool) $enable;
  3398. }
  3399. public function bypass_image_hotlink($get = false)
  3400. {
  3401. if ($get) {
  3402. $this->bypass_image_hotlink = (string) $get;
  3403. } else {
  3404. $this->bypass_image_hotlink = false;
  3405. }
  3406. }
  3407. public function bypass_image_hotlink_page($page = false)
  3408. {
  3409. if ($page) {
  3410. $this->bypass_image_hotlink_page = (string) $page;
  3411. } else {
  3412. $this->bypass_image_hotlink_page = false;
  3413. }
  3414. }
  3415. public function strip_htmltags($tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'))
  3416. {
  3417. if ($tags) {
  3418. if (is_array($tags)) {
  3419. $this->strip_htmltags = $tags;
  3420. } else {
  3421. $this->strip_htmltags = explode(',', $tags);
  3422. }
  3423. } else {
  3424. $this->strip_htmltags = false;
  3425. }
  3426. }
  3427. public function encode_instead_of_strip($enable = false)
  3428. {
  3429. $this->encode_instead_of_strip = (bool) $enable;
  3430. }
  3431. public function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur'))
  3432. {
  3433. if ($attribs) {
  3434. if (is_array($attribs)) {
  3435. $this->strip_attributes = $attribs;
  3436. } else {
  3437. $this->strip_attributes = explode(',', $attribs);
  3438. }
  3439. } else {
  3440. $this->strip_attributes = false;
  3441. }
  3442. }
  3443. public function input_encoding($encoding = 'UTF-8')
  3444. {
  3445. $this->input_encoding = (string) $encoding;
  3446. }
  3447. public function output_encoding($encoding = 'UTF-8')
  3448. {
  3449. $this->output_encoding = (string) $encoding;
  3450. }
  3451. public function set_item_class($class = 'SimplePie_Item')
  3452. {
  3453. if ((new SimplePie_Misc)->is_a_class($class, 'SimplePie_Item')) {
  3454. $this->item_class = $class;
  3455. return true;
  3456. }
  3457. return false;
  3458. }
  3459. public function set_author_class($class = 'SimplePie_Author')
  3460. {
  3461. if ((new SimplePie_Misc)->is_a_class($class, 'SimplePie_Author')) {
  3462. $this->author_class = $class;
  3463. return true;
  3464. }
  3465. return false;
  3466. }
  3467. public function set_enclosure_class($class = 'SimplePie_Enclosure')
  3468. {
  3469. if ((new SimplePie_Misc)->is_a_class($class, 'SimplePie_Enclosure')) {
  3470. $this->enclosure_class = $class;
  3471. return true;
  3472. }
  3473. return false;
  3474. }
  3475. public function parse_data_array(&$data, $url)
  3476. {
  3477. // Feed Info (Type and Version)
  3478. if (!empty($data['feedinfo']['type'])) {
  3479. $this->feedinfo = $data['feedinfo'];
  3480. }
  3481. // Feed level xml:base
  3482. if (!empty($data['feeddata']['attribs']['XML:BASE'])) {
  3483. $this->feed_xmlbase = $data['feeddata']['attribs']['XML:BASE'];
  3484. } elseif (!empty($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'])) {
  3485. $this->feed_xmlbase = $data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'];
  3486. }
  3487. // FeedBurner feeds use alternate link
  3488. elseif (strpos($url, 'http://feeds.feedburner.com/') !== 0) {
  3489. $this->feed_xmlbase = (new SimplePie_Misc)->parse_url($url);
  3490. if (empty($this->feed_xmlbase['authority'])) {
  3491. $this->feed_xmlbase = preg_replace('/^' . preg_quote(realpath($_SERVER['DOCUMENT_ROOT']), '/') . '/', '', realpath($url));
  3492. } else {
  3493. $this->feed_xmlbase = $url;
  3494. }
  3495. }
  3496. // Feed link(s)
  3497. if (!empty($data['info']['link'])) {
  3498. foreach ($data['info']['link'] as $link) {
  3499. if (empty($link['attribs']['REL'])) {
  3500. $rel = 'alternate';
  3501. } else {
  3502. $rel = strtolower($link['attribs']['REL']);
  3503. }
  3504. if ($rel == 'enclosure') {
  3505. $href = null;
  3506. $type = null;
  3507. $length = null;
  3508. if (!empty($link['data'])) {
  3509. $href = $this->sanitize($link['data'], $link['attribs'], true);
  3510. } elseif (!empty($link['attribs']['HREF'])) {
  3511. $href = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
  3512. }
  3513. if (!empty($link['attribs']['TYPE'])) {
  3514. $type = $this->sanitize($link['attribs']['TYPE'], $link['attribs']);
  3515. }
  3516. if (!empty($link['attribs']['LENGTH'])) {
  3517. $length = $this->sanitize($link['attribs']['LENGTH'], $link['attribs']);
  3518. }
  3519. $this->info['link']['enclosure'][] = new $this->enclosure_class($href, $type, $length);
  3520. } else {
  3521. if (!empty($link['data'])) {
  3522. $this->info['link'][$rel][] = $this->sanitize($link['data'], $link['attribs'], true);
  3523. } elseif (!empty($link['attribs']['HREF'])) {
  3524. $this->info['link'][$rel][] = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
  3525. }
  3526. }
  3527. }
  3528. }
  3529. // Use the first alternate link if we don't have any feed xml:base
  3530. if (empty($this->feed_xmlbase) && !empty($this->info['link']['alternate'][0])) {
  3531. $this->feed_xmlbase = $this->info['link']['alternate'][0];
  3532. }
  3533. // Feed Title
  3534. if (!empty($data['info']['title']['data'])) {
  3535. $this->info['title'] = $this->sanitize($data['info']['title']['data'], $data['info']['title']['attribs']);
  3536. }
  3537. // Feed Descriptions
  3538. if (!empty($data['info']['description']['data'])) {
  3539. $this->info['description'] = $this->sanitize($data['info']['description']['data'], $data['info']['description']['attribs'], false, true);
  3540. }
  3541. if (!empty($data['info']['dc:description']['data'])) {
  3542. $this->info['dc:description'] = $this->sanitize($data['info']['dc:description']['data'], $data['info']['dc:description']['attribs']);
  3543. }
  3544. if (!empty($data['info']['tagline']['data'])) {
  3545. $this->info['tagline'] = $this->sanitize($data['info']['tagline']['data'], $data['info']['tagline']['attribs']);
  3546. }
  3547. if (!empty($data['info']['subtitle']['data'])) {
  3548. $this->info['subtitle'] = $this->sanitize($data['info']['subtitle']['data'], $data['info']['subtitle']['attribs']);
  3549. }
  3550. // Feed Language
  3551. if (!empty($data['info']['language']['data'])) {
  3552. $this->info['language'] = $this->sanitize($data['info']['language']['data'], $data['info']['language']['attribs']);
  3553. }
  3554. if (!empty($data['feeddata']['attribs']['XML:LANG'])) {
  3555. $this->info['xml:lang'] = $this->sanitize($data['feeddata']['attribs']['XML:LANG'], null);
  3556. } elseif (!empty($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:LANG'])) {
  3557. $this->info['xml:lang'] = $this->sanitize($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:LANG'], null);
  3558. }
  3559. // Feed Copyright
  3560. if (!empty($data['info']['copyright']['data'])) {
  3561. $this->info['copyright'] = $this->sanitize($data['info']['copyright']['data'], $data['info']['copyright']['attribs']);
  3562. }
  3563. // Feed Image
  3564. if (!empty($data['info']['image']['title']['data'])) {
  3565. $this->info['image']['title'] = $this->sanitize($data['info']['image']['title']['data'], $data['info']['image']['title']['attribs']);
  3566. }
  3567. if (!empty($data['info']['image']['url']['data'])) {
  3568. $this->info['image']['url'] = $this->sanitize($data['info']['image']['url']['data'], $data['info']['image']['url']['attribs'], true);
  3569. }
  3570. if (!empty($data['info']['logo']['data'])) {
  3571. $this->info['image']['logo'] = $this->sanitize($data['info']['logo']['data'], $data['info']['logo']['attribs'], true);
  3572. }
  3573. if (!empty($data['info']['image']['link']['data'])) {
  3574. $this->info['image']['link'] = $this->sanitize($data['info']['image']['link']['data'], $data['info']['image']['link']['attribs'], true);
  3575. }
  3576. if (!empty($data['info']['image']['width']['data'])) {
  3577. $this->info['image']['width'] = $this->sanitize($data['info']['image']['width']['data'], $data['info']['image']['width']['attribs']);
  3578. }
  3579. if (!empty($data['info']['image']['height']['data'])) {
  3580. $this->info['image']['height'] = $this->sanitize($data['info']['image']['height']['data'], $data['info']['image']['height']['attribs']);
  3581. }
  3582. // Items
  3583. if (!empty($data['items'])) {
  3584. foreach ($data['items'] as $key => $item) {
  3585. $newitem = null;
  3586. // Item level xml:base
  3587. if (!empty($item['attribs']['XML:BASE'])) {
  3588. $this->item_xmlbase = (new SimplePie_Misc)->absolutize_url($item['attribs']['XML:BASE'], $this->feed_xmlbase);
  3589. } elseif (!empty($item['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'])) {
  3590. $this->item_xmlbase = (new SimplePie_Misc)->absolutize_url($item['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'], $this->feed_xmlbase);
  3591. } else {
  3592. $this->item_xmlbase = null;
  3593. }
  3594. // Title
  3595. if (!empty($item['title']['data'])) {
  3596. $newitem['title'] = $this->sanitize($item['title']['data'], $item['title']['attribs']);
  3597. }
  3598. if (!empty($item['dc:title']['data'])) {
  3599. $newitem['dc:title'] = $this->sanitize($item['dc:title']['data'], $item['dc:title']['attribs']);
  3600. }
  3601. // Description
  3602. if (!empty($item['content']['data'])) {
  3603. $newitem['content'] = $this->sanitize($item['content']['data'], $item['content']['attribs']);
  3604. }
  3605. if (!empty($item['encoded']['data'])) {
  3606. $newitem['encoded'] = $this->sanitize($item['encoded']['data'], $item['encoded']['attribs']);
  3607. }
  3608. if (!empty($item['summary']['data'])) {
  3609. $newitem['summary'] = $this->sanitize($item['summary']['data'], $item['summary']['attribs']);
  3610. }
  3611. if (!empty($item['description']['data'])) {
  3612. $newitem['description'] = $this->sanitize($item['description']['data'], $item['description']['attribs'], false, true);
  3613. }
  3614. if (!empty($item['dc:description']['data'])) {
  3615. $newitem['dc:description'] = $this->sanitize($item['dc:description']['data'], $item['dc:description']['attribs']);
  3616. }
  3617. if (!empty($item['longdesc']['data'])) {
  3618. $newitem['longdesc'] = $this->sanitize($item['longdesc']['data'], $item['longdesc']['attribs']);
  3619. }
  3620. // Link(s)
  3621. if (!empty($item['link'])) {
  3622. foreach ($item['link'] as $link) {
  3623. if (empty($link['attribs']['REL'])) {
  3624. $rel = 'alternate';
  3625. } else {
  3626. $rel = strtolower($link['attribs']['REL']);
  3627. }
  3628. if ($rel == 'enclosure') {
  3629. $href = null;
  3630. $type = null;
  3631. $length = null;
  3632. if (!empty($link['data'])) {
  3633. $href = $this->sanitize($link['data'], $link['attribs'], true);
  3634. } elseif (!empty($link['attribs']['HREF'])) {
  3635. $href = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
  3636. }
  3637. if (!empty($link['attribs']['TYPE'])) {
  3638. $type = $this->sanitize($link['attribs']['TYPE'], $link['attribs']);
  3639. }
  3640. if (!empty($link['attribs']['LENGTH'])) {
  3641. $length = $this->sanitize($link['attribs']['LENGTH'], $link['attribs']);
  3642. }
  3643. if (!empty($href)) {
  3644. $newitem['link'][$rel][] = new $this->enclosure_class($href, $type, $length);
  3645. }
  3646. } else {
  3647. if (!empty($link['data'])) {
  3648. $newitem['link'][$rel][] = $this->sanitize($link['data'], $link['attribs'], true);
  3649. } elseif (!empty($link['attribs']['HREF'])) {
  3650. $newitem['link'][$rel][] = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
  3651. }
  3652. }
  3653. }
  3654. }
  3655. // Enclosure(s)
  3656. if (!empty($item['enclosure'])) {
  3657. foreach ($item['enclosure'] as $enclosure) {
  3658. if (!empty($enclosure['attribs']['URL'])) {
  3659. $type = null;
  3660. $length = null;
  3661. $href = $this->sanitize($enclosure['attribs']['URL'], $enclosure['attribs'], true);
  3662. if (!empty($enclosure['attribs']['TYPE'])) {
  3663. $type = $this->sanitize($enclosure['attribs']['TYPE'], $enclosure['attribs']);
  3664. }
  3665. if (!empty($enclosure['attribs']['LENGTH'])) {
  3666. $length = $this->sanitize($enclosure['attribs']['LENGTH'], $enclosure['attribs']);
  3667. }
  3668. $newitem['enclosures'][] = new $this->enclosure_class($href, $type, $length);
  3669. }
  3670. }
  3671. }
  3672. // ID
  3673. if (!empty($item['guid']['data'])) {
  3674. if (!empty($item['guid']['attribs']['ISPERMALINK']) && strtolower($item['guid']['attribs']['ISPERMALINK']) == 'false') {
  3675. $newitem['guid']['permalink'] = false;
  3676. } else {
  3677. $newitem['guid']['permalink'] = true;
  3678. }
  3679. $newitem['guid']['data'] = $this->sanitize($item['guid']['data'], $item['guid']['attribs']);
  3680. }
  3681. if (!empty($item['id']['data'])) {
  3682. $newitem['id'] = $this->sanitize($item['id']['data'], $item['id']['attribs']);
  3683. }
  3684. // Date
  3685. if (!empty($item['pubdate']['data'])) {
  3686. $newitem['pubdate'] = $this->parse_date($this->sanitize($item['pubdate']['data'], $item['pubdate']['attribs']));
  3687. }
  3688. if (!empty($item['dc:date']['data'])) {
  3689. $newitem['dc:date'] = $this->parse_date($this->sanitize($item['dc:date']['data'], $item['dc:date']['attribs']));
  3690. }
  3691. if (!empty($item['issued']['data'])) {
  3692. $newitem['issued'] = $this->parse_date($this->sanitize($item['issued']['data'], $item['issued']['attribs']));
  3693. }
  3694. if (!empty($item['published']['data'])) {
  3695. $newitem['published'] = $this->parse_date($this->sanitize($item['published']['data'], $item['published']['attribs']));
  3696. }
  3697. if (!empty($item['modified']['data'])) {
  3698. $newitem['modified'] = $this->parse_date($this->sanitize($item['modified']['data'], $item['modified']['attribs']));
  3699. }
  3700. if (!empty($item['updated']['data'])) {
  3701. $newitem['updated'] = $this->parse_date($this->sanitize($item['updated']['data'], $item['updated']['attribs']));
  3702. }
  3703. // Categories
  3704. if (!empty($item['category'])) {
  3705. foreach ($item['category'] as $category) {
  3706. if (!empty($category['data'])) {
  3707. $newitem['category'][] = $this->sanitize($category['data'], $category['attribs']);
  3708. } elseif (!empty($category['attribs']['TERM'])) {
  3709. $newitem['term'][] = $this->sanitize($category['attribs']['TERM'], $category['attribs']);
  3710. }
  3711. }
  3712. }
  3713. if (!empty($item['subject'])) {
  3714. foreach ($item['subject'] as $category) {
  3715. if (!empty($category['data'])) {
  3716. $newitem['subject'][] = $this->sanitize($category['data'], $category['attribs']);
  3717. }
  3718. }
  3719. }
  3720. // Author
  3721. if (!empty($item['creator'])) {
  3722. foreach ($item['creator'] as $creator) {
  3723. if (!empty($creator['data'])) {
  3724. $newitem['creator'][] = new $this->author_class($this->sanitize($creator['data'], $creator['attribs']), null, null);
  3725. }
  3726. }
  3727. }
  3728. if (!empty($item['author'])) {
  3729. foreach ($item['author'] as $author) {
  3730. $name = null;
  3731. $link = null;
  3732. $email = null;
  3733. if (!empty($author['rss'])) {
  3734. $sane = $this->sanitize($author['rss']['data'], $author['rss']['attribs']);
  3735. if (preg_match('/(.*)@(.*) \((.*)\)/msiU', $sane, $matches)) {
  3736. $name = trim($matches[3]);
  3737. $email = trim("$matches[1]@$matches[2]");
  3738. } else {
  3739. $email = $sane;
  3740. }
  3741. } else {
  3742. if (!empty($author['name'])) {
  3743. $name = $this->sanitize($author['name']['data'], $author['name']['attribs']);
  3744. }
  3745. if (!empty($author['url'])) {
  3746. $link = $this->sanitize($author['url']['data'], $author['url']['attribs'], true);
  3747. } elseif (!empty($author['uri'])) {
  3748. $link = $this->sanitize($author['uri']['data'], $author['uri']['attribs'], true);
  3749. } elseif (!empty($author['homepage'])) {
  3750. $link = $this->sanitize($author['homepage']['data'], $author['homepage']['attribs'], true);
  3751. }
  3752. if (!empty($author['email'])) {
  3753. $email = $this->sanitize($author['email']['data'], $author['email']['attribs']);
  3754. }
  3755. }
  3756. $newitem['author'][] = new $this->author_class($name, $link, $email);
  3757. }
  3758. }
  3759. unset($data['items'][$key]);
  3760. $this->items[] = new $this->item_class($newitem);
  3761. }
  3762. }
  3763. }
  3764. public function sanitize($data, $attribs, $is_url = false, $force_decode = false)
  3765. {
  3766. $this->attribs = $attribs;
  3767. if (isset($this->feedinfo['type']) && $this->feedinfo['type'] == 'Atom') {
  3768. if ((!empty($attribs['MODE']) && $attribs['MODE'] == 'base64') || (!empty($attribs['TYPE']) && $attribs['TYPE'] == 'application/octet-stream')) {
  3769. $data = trim($data);
  3770. $data = base64_decode($data);
  3771. } elseif ((!empty($attribs['MODE']) && $attribs['MODE'] == 'escaped' || !empty($attribs['TYPE']) && ($attribs['TYPE'] == 'html' || $attribs['TYPE'] == 'text/html'))) {
  3772. $data = $this->entities_decode($data);
  3773. }
  3774. if (!empty($attribs['TYPE']) && ($attribs['TYPE'] == 'xhtml' || $attribs['TYPE'] == 'application/xhtml+xml')) {
  3775. if ($this->remove_div) {
  3776. $data = preg_replace('/<div( .*)?>/msiU', '', strrev(preg_replace('/>vid\/</i', '', strrev($data), 1)), 1);
  3777. } else {
  3778. $data = preg_replace('/<div( .*)?>/msiU', '<div>', $data, 1);
  3779. }
  3780. $data = $this->convert_entities($data);
  3781. }
  3782. } else {
  3783. $data = $this->convert_entities($data);
  3784. }
  3785. if ($force_decode) {
  3786. $data = $this->entities_decode($data);
  3787. }
  3788. $data = trim($data);
  3789. $data = preg_replace('/<\!--([^-]|-[^-])*-->/msiU', '', $data);
  3790. // If Strip Ads is enabled, strip them.
  3791. if ($this->strip_ads) {
  3792. $data = preg_replace('/<a (.*)href=(.*)click\.phdo\?s=(.*)<\/a>/msiU', '', $data); // Pheedo links (tested with Dooce.com)
  3793. $data = preg_replace('/<p(.*)>(.*)<a href="http:\/\/ad.doubleclick.net\/jump\/(.*)<\/p>/msiU', '', $data); // Doubleclick links (tested with InfoWorld.com)
  3794. $data = preg_replace('/<p><map (.*)name=(.*)google_ad_map(.*)<\/p>/msiU', '', $data); // Google AdSense for Feeds (tested with tuaw.com).
  3795. // Feedflare, from Feedburner
  3796. }
  3797. // Replace H1, H2, and H3 tags with the less important H4 tags.
  3798. // This is because on a site, the more important headers might make sense,
  3799. // but it most likely doesn't fit in the context of RSS-in-a-webpage.
  3800. if ($this->replace_headers) {
  3801. $data = preg_replace('/<h[1-3]((\s*((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(.*)))*)\s*>/msiU', '<h4\\1>', $data);
  3802. $data = preg_replace('/<\/h[1-3]>/i', '</h4>', $data);
  3803. }
  3804. if ($is_url) {
  3805. $data = $this->replace_urls($data, true);
  3806. } else {
  3807. $data = preg_replace_callback('/<(\S+)((\s*((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(.*)))*)\s*(\/>|>(.*)<\/\S+>)/msiU', array(&$this, 'replace_urls'), $data);
  3808. }
  3809. // If Bypass Image Hotlink is enabled, rewrite all the image tags.
  3810. if ($this->bypass_image_hotlink) {
  3811. $images = (new SimplePie_Misc)->get_element('img', $data);
  3812. foreach ($images as $img) {
  3813. if (!empty($img['attribs']['SRC']['data'])) {
  3814. $pre = '';
  3815. if ($this->bypass_image_hotlink_page) {
  3816. $pre = $this->bypass_image_hotlink_page;
  3817. }
  3818. $pre .= "?$this->bypass_image_hotlink=";
  3819. $img['attribs']['SRC']['data'] = $pre . rawurlencode(strtr($img['attribs']['SRC']['data'], array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES))));
  3820. $data = str_replace($img['full'], (new SimplePie_Misc)->element_implode($img), $data);
  3821. }
  3822. }
  3823. }
  3824. // Strip out HTML tags and attributes that might cause various security problems.
  3825. // Based on recommendations by Mark Pilgrim at:
  3826. // http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely
  3827. if ($this->strip_htmltags) {
  3828. foreach ($this->strip_htmltags as $tag) {
  3829. $data = preg_replace_callback("/<($tag)((\s*((\w+:)?\w+)(\s*=\s*(\"([^\"]*)\"|'([^']*)'|(.*)))?)*)\s*(\/>|>(.*)<\/($tag)((\s*((\w+:)?\w+)(\s*=\s*(\"([^\"]*)\"|'([^']*)'|(.*)))?)*)\s*>)/msiU", array(&$this, 'do_strip_htmltags'), $data);
  3830. }
  3831. }
  3832. if ($this->strip_attributes) {
  3833. foreach ($this->strip_attributes as $attrib) {
  3834. $data = preg_replace('/ '. trim($attrib) .'=("|&quot;)(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|\'|&apos;|<|>|\+|{|})*("|&quot;)/i', '', $data);
  3835. $data = preg_replace('/ '. trim($attrib) .'=(\'|&apos;)(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|"|&quot;|<|>|\+|{|})*(\'|&apos;)/i', '', $data);
  3836. $data = preg_replace('/ '. trim($attrib) .'=(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|\+|{|})*/i', '', $data);
  3837. }
  3838. }
  3839. // Convert encoding
  3840. $data = (new SimplePie_Misc)->change_encoding($data, $this->input_encoding, $this->output_encoding);
  3841. return $data;
  3842. }
  3843. public function do_strip_htmltags($match)
  3844. {
  3845. if ($this->encode_instead_of_strip) {
  3846. if (isset($match[12]) && !in_array(strtolower($match[1]), array('script', 'style'))) {
  3847. return "&lt;$match[1]$match[2]&gt;$match[12]&lt;/$match[1]&gt;";
  3848. } elseif (isset($match[12])) {
  3849. return "&lt;$match[1]$match[2]&gt;&lt;/$match[1]&gt;";
  3850. } else {
  3851. return "&lt;$match[1]$match[2]/&gt;";
  3852. }
  3853. } else {
  3854. if (isset($match[12]) && !in_array(strtolower($match[1]), array('script', 'style'))) {
  3855. return $match[12];
  3856. } else {
  3857. return '';
  3858. }
  3859. }
  3860. }
  3861. public function replace_urls($data, $raw_url = false)
  3862. {
  3863. if (!empty($this->attribs['XML:BASE'])) {
  3864. $xmlbase = $attribs['XML:BASE'];
  3865. } elseif (!empty($this->attribs['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'])) {
  3866. $xmlbase = $this->attribs['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'];
  3867. }
  3868. if (!empty($xmlbase)) {
  3869. if (!empty($this->item_xmlbase)) {
  3870. $xmlbase = (new SimplePie_Misc)->absolutize_url($xmlbase, $this->item_xmlbase);
  3871. } else {
  3872. $xmlbase = (new SimplePie_Misc)->absolutize_url($xmlbase, $this->feed_xmlbase);
  3873. }
  3874. } elseif (!empty($this->item_xmlbase)) {
  3875. $xmlbase = $this->item_xmlbase;
  3876. } else {
  3877. $xmlbase = $this->feed_xmlbase;
  3878. }
  3879. if ($raw_url) {
  3880. return (new SimplePie_Misc)->absolutize_url($data, $xmlbase);
  3881. } else {
  3882. $attributes = array(
  3883. 'background',
  3884. 'href',
  3885. 'src',
  3886. 'longdesc',
  3887. 'usemap',
  3888. 'codebase',
  3889. 'data',
  3890. 'classid',
  3891. 'cite',
  3892. 'action',
  3893. 'profile',
  3894. 'for'
  3895. );
  3896. foreach ($attributes as $attribute) {
  3897. if (preg_match("/$attribute='(.*)'/siU", $data[0], $attrib) || preg_match("/$attribute=\"(.*)\"/siU", $data[0], $attrib) || preg_match("/$attribute=(.*)[ |\/|>]/siU", $data[0], $attrib)) {
  3898. $new_tag = str_replace($attrib[1], (new SimplePie_Misc)->absolutize_url($attrib[1], $xmlbase), $attrib[0]);
  3899. $data[0] = str_replace($attrib[0], $new_tag, $data[0]);
  3900. }
  3901. }
  3902. return $data[0];
  3903. }
  3904. }
  3905. public function entities_decode($data)
  3906. {
  3907. return preg_replace_callback('/&(#)?(x)?([0-9a-z]+);/mi', array(&$this, 'do_entites_decode'), $data);
  3908. }
  3909. public function do_entites_decode($data)
  3910. {
  3911. if (isset($this->cached_entities[$data[0]])) {
  3912. return $this->cached_entities[$data[0]];
  3913. } else {
  3914. $return = (new SimplePie_Misc)->change_encoding(html_entity_decode($data[0], ENT_QUOTES), 'ISO-8859-1', $this->input_encoding);
  3915. if ($return == $data[0]) {
  3916. $return = (new SimplePie_Misc)->change_encoding(preg_replace_callback('/&#([x]?[0-9a-f]+);/mi', array(&$this, 'replace_num_entity'), $data[0]), 'UTF-8', $this->input_encoding);
  3917. }
  3918. $this->cached_entities[$data[0]] = $return;
  3919. return $return;
  3920. }
  3921. }
  3922. public function convert_entities($data)
  3923. {
  3924. return preg_replace_callback('/&#(x)?([0-9a-z]+);/mi', array(&$this, 'do_convert_entities'), $data);
  3925. }
  3926. public function do_convert_entities($data)
  3927. {
  3928. if (isset($this->cache_convert_entities[$data[0]])) {
  3929. return $this->cache_convert_entities[$data[0]];
  3930. } elseif (isset($this->cached_entities[$data[0]])) {
  3931. $return = htmlentities($this->cached_entities[$data[0]], ENT_QUOTES, 'UTF-8');
  3932. } else {
  3933. $return = htmlentities(preg_replace_callback('/&#([x]?[0-9a-f]+);/mi', array(&$this, 'replace_num_entity'), $data[0]), ENT_QUOTES, 'UTF-8');
  3934. }
  3935. $this->cache_convert_entities[$data[0]] = $return;
  3936. return $return;
  3937. }
  3938. /*
  3939. * Escape numeric entities
  3940. * From a PHP Manual note (on html_entity_decode())
  3941. * Copyright (c) 2005 by "php dot net at c dash ovidiu dot tk",
  3942. * "emilianomartinezluque at yahoo dot com" and "hurricane at cyberworldz dot org".
  3943. *
  3944. * This material may be distributed only subject to the terms and conditions set forth in
  3945. * the Open Publication License, v1.0 or later (the latest version is presently available at
  3946. * http://www.opencontent.org/openpub/).
  3947. */
  3948. public function replace_num_entity($ord)
  3949. {
  3950. $ord = $ord[1];
  3951. if (preg_match('/^x([0-9a-f]+)$/i', $ord, $match)) {
  3952. $ord = hexdec($match[1]);
  3953. } else {
  3954. $ord = intval($ord);
  3955. }
  3956. $no_bytes = 0;
  3957. $byte = array();
  3958. if ($ord < 128) {
  3959. return chr($ord);
  3960. }
  3961. if ($ord < 2048) {
  3962. $no_bytes = 2;
  3963. } elseif ($ord < 65536) {
  3964. $no_bytes = 3;
  3965. } elseif ($ord < 1114112) {
  3966. $no_bytes = 4;
  3967. } else {
  3968. return;
  3969. }
  3970. switch ($no_bytes) {
  3971. case 2:
  3972. $prefix = array(31, 192);
  3973. break;
  3974. case 3:
  3975. $prefix = array(15, 224);
  3976. break;
  3977. case 4:
  3978. $prefix = array(7, 240);
  3979. break;
  3980. }
  3981. for ($i = 0; $i < $no_bytes; $i++) {
  3982. $byte[$no_bytes-$i-1] = (($ord & (63 * pow(2, 6*$i))) / pow(2, 6*$i)) & 63 | 128;
  3983. }
  3984. $byte[0] = ($byte[0] & $prefix[0]) | $prefix[1];
  3985. $ret = '';
  3986. for ($i = 0; $i < $no_bytes; $i++) {
  3987. $ret .= chr($byte[$i]);
  3988. }
  3989. return $ret;
  3990. }
  3991. public function parse_date($date)
  3992. {
  3993. $military_timezone = array('A' => '-0100', 'B' => '-0200', 'C' => '-0300', 'D' => '-0400', 'E' => '-0500', 'F' => '-0600', 'G' => '-0700', 'H' => '-0800', 'I' => '-0900', 'K' => '-1000', 'L' => '-1100', 'M' => '-1200', 'N' => '+0100', 'O' => '+0200', 'P' => '+0300', 'Q' => '+0400', 'R' => '+0500', 'S' => '+0600', 'T' => '+0700', 'U' => '+0800', 'V' => '+0900', 'W' => '+1000', 'X' => '+1100', 'Y' => '+1200', 'Z' => '-0000');
  3994. $north_american_timezone = array('GMT' => '-0000', 'EST' => '-0500', 'EDT' => '-0400', 'CST' => '-0600', 'CDT' => '-0500', 'MST' => '-0700', 'MDT' => '-0600', 'PST' => '-0800', 'PDT' => '-0700');
  3995. if (preg_match('/([0-9]{2,4})-?([0-9]{2})-?([0-9]{2})T([0-9]{2}):?([0-9]{2})(:?([0-9]{2}(\.[0-9]*)?))?(UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|[a-z]|(\\+|-)[0-9]{4}|(\\+|-)[0-9]{2}:[0-9]{2})?/i', $date, $matches)) {
  3996. if (!isset($matches[7])) {
  3997. $matches[7] = '';
  3998. }
  3999. if (!isset($matches[9])) {
  4000. $matches[9] = '';
  4001. }
  4002. $matches[7] = str_pad(round($matches[7]), 2, '0', STR_PAD_LEFT);
  4003. switch (strlen($matches[9])) {
  4004. case 0:
  4005. $timezone = '';
  4006. break;
  4007. case 1:
  4008. $timezone = $military_timezone[strtoupper($matches[9])];
  4009. break;
  4010. case 2:
  4011. $timezone = '-0000';
  4012. break;
  4013. case 3:
  4014. $timezone = $north_american_timezone[strtoupper($matches[9])];
  4015. break;
  4016. case 5:
  4017. $timezone = $matches[9];
  4018. break;
  4019. case 6:
  4020. $timezone = substr_replace($matches[9], '', 3, 1);
  4021. break;
  4022. }
  4023. $date = strtotime("$matches[1]-$matches[2]-$matches[3] $matches[4]:$matches[5]:$matches[7] $timezone");
  4024. } elseif (preg_match('/([0-9]{1,2})\s*(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s*([0-9]{2}|[0-9]{4})\s*([0-9]{2}):([0-9]{2})(:([0-9]{2}(\.[0-9]*)?))?\s*(UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|[a-z]|(\\+|-)[0-9]{4}|(\\+|-)[0-9]{2}:[0-9]{2})?/i', $date, $matches)) {
  4025. $three_month = array('Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4, 'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12);
  4026. $month = $three_month[$matches[2]];
  4027. if (strlen($matches[3]) == 2) {
  4028. $year = ($matches[3] < 70) ? "20$matches[3]" : "19$matches[3]";
  4029. } else {
  4030. $year = $matches[3];
  4031. }
  4032. if (!isset($matches[7])) {
  4033. $matches[7] = '';
  4034. }
  4035. if (!isset($matches[9])) {
  4036. $matches[9] = '';
  4037. }
  4038. $second = str_pad(round($matches[7]), 2, '0', STR_PAD_LEFT);
  4039. switch (strlen($matches[9])) {
  4040. case 0:
  4041. $timezone = '';
  4042. break;
  4043. case 1:
  4044. $timezone = $military_timezone[strtoupper($matches[9])];
  4045. break;
  4046. case 2:
  4047. $timezone = '-0000';
  4048. break;
  4049. case 3:
  4050. $timezone = $north_american_timezone[strtoupper($matches[9])];
  4051. break;
  4052. case 5:
  4053. $timezone = $matches[9];
  4054. break;
  4055. case 6:
  4056. $timezone = substr_replace($matches[9], '', 3, 1);
  4057. break;
  4058. }
  4059. $date = strtotime("$year-$month-$matches[1] $matches[4]:$matches[5]:$second $timezone");
  4060. } else {
  4061. $date = strtotime($date);
  4062. }
  4063. if ($date !== false && $date !== -1) {
  4064. return $date;
  4065. } else {
  4066. return false;
  4067. }
  4068. }
  4069. }