SimplePie.class.php 472 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746
  1. <?php
  2. /**
  3. * SimplePie
  4. *
  5. * A PHP-Based RSS and Atom Feed Framework.
  6. * Takes the hard work out of managing a complete RSS/Atom solution.
  7. *
  8. * Please note: This file is automatically generated by a build script. The
  9. * full original source is always available from http://simplepie.org/
  10. *
  11. * Copyright (c) 2004-2016, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without modification, are
  15. * permitted provided that the following conditions are met:
  16. *
  17. * * Redistributions of source code must retain the above copyright notice, this list of
  18. * conditions and the following disclaimer.
  19. *
  20. * * Redistributions in binary form must reproduce the above copyright notice, this list
  21. * of conditions and the following disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * * Neither the name of the SimplePie Team nor the names of its contributors may be used
  25. * to endorse or promote products derived from this software without specific prior
  26. * written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  30. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
  31. * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  33. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  34. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  35. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * @package SimplePie
  39. * @copyright 2004-2016 Ryan Parman, Geoffrey Sneddon, Ryan McCue
  40. * @author Ryan Parman
  41. * @author Geoffrey Sneddon
  42. * @author Ryan McCue
  43. * @link http://simplepie.org/ SimplePie
  44. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  45. */
  46. /**
  47. * SimplePie Name
  48. */
  49. define('SIMPLEPIE_NAME', 'SimplePie');
  50. /**
  51. * SimplePie Version
  52. */
  53. define('SIMPLEPIE_VERSION', '1.4.3');
  54. /**
  55. * SimplePie Build
  56. * @todo Hardcode for release (there's no need to have to call SimplePie_Misc::get_build() only every load of simplepie.inc)
  57. */
  58. define('SIMPLEPIE_BUILD', '20170309151520');
  59. /**
  60. * SimplePie Website URL
  61. */
  62. define('SIMPLEPIE_URL', 'http://simplepie.org');
  63. /**
  64. * SimplePie Useragent
  65. * @see SimplePie::set_useragent()
  66. */
  67. define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD);
  68. /**
  69. * SimplePie Linkback
  70. */
  71. define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>');
  72. /**
  73. * No Autodiscovery
  74. * @see SimplePie::set_autodiscovery_level()
  75. */
  76. define('SIMPLEPIE_LOCATOR_NONE', 0);
  77. /**
  78. * Feed Link Element Autodiscovery
  79. * @see SimplePie::set_autodiscovery_level()
  80. */
  81. define('SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1);
  82. /**
  83. * Local Feed Extension Autodiscovery
  84. * @see SimplePie::set_autodiscovery_level()
  85. */
  86. define('SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2);
  87. /**
  88. * Local Feed Body Autodiscovery
  89. * @see SimplePie::set_autodiscovery_level()
  90. */
  91. define('SIMPLEPIE_LOCATOR_LOCAL_BODY', 4);
  92. /**
  93. * Remote Feed Extension Autodiscovery
  94. * @see SimplePie::set_autodiscovery_level()
  95. */
  96. define('SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8);
  97. /**
  98. * Remote Feed Body Autodiscovery
  99. * @see SimplePie::set_autodiscovery_level()
  100. */
  101. define('SIMPLEPIE_LOCATOR_REMOTE_BODY', 16);
  102. /**
  103. * All Feed Autodiscovery
  104. * @see SimplePie::set_autodiscovery_level()
  105. */
  106. define('SIMPLEPIE_LOCATOR_ALL', 31);
  107. /**
  108. * No known feed type
  109. */
  110. define('SIMPLEPIE_TYPE_NONE', 0);
  111. /**
  112. * RSS 0.90
  113. */
  114. define('SIMPLEPIE_TYPE_RSS_090', 1);
  115. /**
  116. * RSS 0.91 (Netscape)
  117. */
  118. define('SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2);
  119. /**
  120. * RSS 0.91 (Userland)
  121. */
  122. define('SIMPLEPIE_TYPE_RSS_091_USERLAND', 4);
  123. /**
  124. * RSS 0.91 (both Netscape and Userland)
  125. */
  126. define('SIMPLEPIE_TYPE_RSS_091', 6);
  127. /**
  128. * RSS 0.92
  129. */
  130. define('SIMPLEPIE_TYPE_RSS_092', 8);
  131. /**
  132. * RSS 0.93
  133. */
  134. define('SIMPLEPIE_TYPE_RSS_093', 16);
  135. /**
  136. * RSS 0.94
  137. */
  138. define('SIMPLEPIE_TYPE_RSS_094', 32);
  139. /**
  140. * RSS 1.0
  141. */
  142. define('SIMPLEPIE_TYPE_RSS_10', 64);
  143. /**
  144. * RSS 2.0
  145. */
  146. define('SIMPLEPIE_TYPE_RSS_20', 128);
  147. /**
  148. * RDF-based RSS
  149. */
  150. define('SIMPLEPIE_TYPE_RSS_RDF', 65);
  151. /**
  152. * Non-RDF-based RSS (truly intended as syndication format)
  153. */
  154. define('SIMPLEPIE_TYPE_RSS_SYNDICATION', 190);
  155. /**
  156. * All RSS
  157. */
  158. define('SIMPLEPIE_TYPE_RSS_ALL', 255);
  159. /**
  160. * Atom 0.3
  161. */
  162. define('SIMPLEPIE_TYPE_ATOM_03', 256);
  163. /**
  164. * Atom 1.0
  165. */
  166. define('SIMPLEPIE_TYPE_ATOM_10', 512);
  167. /**
  168. * All Atom
  169. */
  170. define('SIMPLEPIE_TYPE_ATOM_ALL', 768);
  171. /**
  172. * All feed types
  173. */
  174. define('SIMPLEPIE_TYPE_ALL', 1023);
  175. /**
  176. * No construct
  177. */
  178. define('SIMPLEPIE_CONSTRUCT_NONE', 0);
  179. /**
  180. * Text construct
  181. */
  182. define('SIMPLEPIE_CONSTRUCT_TEXT', 1);
  183. /**
  184. * HTML construct
  185. */
  186. define('SIMPLEPIE_CONSTRUCT_HTML', 2);
  187. /**
  188. * XHTML construct
  189. */
  190. define('SIMPLEPIE_CONSTRUCT_XHTML', 4);
  191. /**
  192. * base64-encoded construct
  193. */
  194. define('SIMPLEPIE_CONSTRUCT_BASE64', 8);
  195. /**
  196. * IRI construct
  197. */
  198. define('SIMPLEPIE_CONSTRUCT_IRI', 16);
  199. /**
  200. * A construct that might be HTML
  201. */
  202. define('SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32);
  203. /**
  204. * All constructs
  205. */
  206. define('SIMPLEPIE_CONSTRUCT_ALL', 63);
  207. /**
  208. * Don't change case
  209. */
  210. define('SIMPLEPIE_SAME_CASE', 1);
  211. /**
  212. * Change to lowercase
  213. */
  214. define('SIMPLEPIE_LOWERCASE', 2);
  215. /**
  216. * Change to uppercase
  217. */
  218. define('SIMPLEPIE_UPPERCASE', 4);
  219. /**
  220. * PCRE for HTML attributes
  221. */
  222. define('SIMPLEPIE_PCRE_HTML_ATTRIBUTE', '((?:[\x09\x0A\x0B\x0C\x0D\x20]+[^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3D\x3E]*(?:[\x09\x0A\x0B\x0C\x0D\x20]*=[\x09\x0A\x0B\x0C\x0D\x20]*(?:"(?:[^"]*)"|\'(?:[^\']*)\'|(?:[^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?)*)[\x09\x0A\x0B\x0C\x0D\x20]*');
  223. /**
  224. * PCRE for XML attributes
  225. */
  226. define('SIMPLEPIE_PCRE_XML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*');
  227. /**
  228. * XML Namespace
  229. */
  230. define('SIMPLEPIE_NAMESPACE_XML', 'http://www.w3.org/XML/1998/namespace');
  231. /**
  232. * Atom 1.0 Namespace
  233. */
  234. define('SIMPLEPIE_NAMESPACE_ATOM_10', 'http://www.w3.org/2005/Atom');
  235. /**
  236. * Atom 0.3 Namespace
  237. */
  238. define('SIMPLEPIE_NAMESPACE_ATOM_03', 'http://purl.org/atom/ns#');
  239. /**
  240. * RDF Namespace
  241. */
  242. define('SIMPLEPIE_NAMESPACE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
  243. /**
  244. * RSS 0.90 Namespace
  245. */
  246. define('SIMPLEPIE_NAMESPACE_RSS_090', 'http://my.netscape.com/rdf/simple/0.9/');
  247. /**
  248. * RSS 1.0 Namespace
  249. */
  250. define('SIMPLEPIE_NAMESPACE_RSS_10', 'http://purl.org/rss/1.0/');
  251. /**
  252. * RSS 1.0 Content Module Namespace
  253. */
  254. define('SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT', 'http://purl.org/rss/1.0/modules/content/');
  255. /**
  256. * RSS 2.0 Namespace
  257. * (Stupid, I know, but I'm certain it will confuse people less with support.)
  258. */
  259. define('SIMPLEPIE_NAMESPACE_RSS_20', '');
  260. /**
  261. * DC 1.0 Namespace
  262. */
  263. define('SIMPLEPIE_NAMESPACE_DC_10', 'http://purl.org/dc/elements/1.0/');
  264. /**
  265. * DC 1.1 Namespace
  266. */
  267. define('SIMPLEPIE_NAMESPACE_DC_11', 'http://purl.org/dc/elements/1.1/');
  268. /**
  269. * W3C Basic Geo (WGS84 lat/long) Vocabulary Namespace
  270. */
  271. define('SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO', 'http://www.w3.org/2003/01/geo/wgs84_pos#');
  272. /**
  273. * GeoRSS Namespace
  274. */
  275. define('SIMPLEPIE_NAMESPACE_GEORSS', 'http://www.georss.org/georss');
  276. /**
  277. * Media RSS Namespace
  278. */
  279. define('SIMPLEPIE_NAMESPACE_MEDIARSS', 'http://search.yahoo.com/mrss/');
  280. /**
  281. * Wrong Media RSS Namespace. Caused by a long-standing typo in the spec.
  282. */
  283. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG', 'http://search.yahoo.com/mrss');
  284. /**
  285. * Wrong Media RSS Namespace #2. New namespace introduced in Media RSS 1.5.
  286. */
  287. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2', 'http://video.search.yahoo.com/mrss');
  288. /**
  289. * Wrong Media RSS Namespace #3. A possible typo of the Media RSS 1.5 namespace.
  290. */
  291. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3', 'http://video.search.yahoo.com/mrss/');
  292. /**
  293. * Wrong Media RSS Namespace #4. New spec location after the RSS Advisory Board takes it over, but not a valid namespace.
  294. */
  295. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4', 'http://www.rssboard.org/media-rss');
  296. /**
  297. * Wrong Media RSS Namespace #5. A possible typo of the RSS Advisory Board URL.
  298. */
  299. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5', 'http://www.rssboard.org/media-rss/');
  300. /**
  301. * iTunes RSS Namespace
  302. */
  303. define('SIMPLEPIE_NAMESPACE_ITUNES', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
  304. /**
  305. * XHTML Namespace
  306. */
  307. define('SIMPLEPIE_NAMESPACE_XHTML', 'http://www.w3.org/1999/xhtml');
  308. /**
  309. * IANA Link Relations Registry
  310. */
  311. define('SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY', 'http://www.iana.org/assignments/relation/');
  312. /**
  313. * No file source
  314. */
  315. define('SIMPLEPIE_FILE_SOURCE_NONE', 0);
  316. /**
  317. * Remote file source
  318. */
  319. define('SIMPLEPIE_FILE_SOURCE_REMOTE', 1);
  320. /**
  321. * Local file source
  322. */
  323. define('SIMPLEPIE_FILE_SOURCE_LOCAL', 2);
  324. /**
  325. * fsockopen() file source
  326. */
  327. define('SIMPLEPIE_FILE_SOURCE_FSOCKOPEN', 4);
  328. /**
  329. * cURL file source
  330. */
  331. define('SIMPLEPIE_FILE_SOURCE_CURL', 8);
  332. /**
  333. * file_get_contents() file source
  334. */
  335. define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16);
  336. /**
  337. * SimplePie
  338. *
  339. * @package SimplePie
  340. * @subpackage API
  341. */
  342. class SimplePie
  343. {
  344. /**
  345. * @var array Raw data
  346. * @access private
  347. */
  348. public $data = array();
  349. /**
  350. * @var mixed Error string
  351. * @access private
  352. */
  353. public $error;
  354. /**
  355. * @var object Instance of SimplePie_Sanitize (or other class)
  356. * @see SimplePie::set_sanitize_class()
  357. * @access private
  358. */
  359. public $sanitize;
  360. /**
  361. * @var string SimplePie Useragent
  362. * @see SimplePie::set_useragent()
  363. * @access private
  364. */
  365. public $useragent = SIMPLEPIE_USERAGENT;
  366. /**
  367. * @var string Feed URL
  368. * @see SimplePie::set_feed_url()
  369. * @access private
  370. */
  371. public $feed_url;
  372. /**
  373. * @var string Original feed URL, or new feed URL iff HTTP 301 Moved Permanently
  374. * @see SimplePie::subscribe_url()
  375. * @access private
  376. */
  377. public $permanent_url = null;
  378. /**
  379. * @var object Instance of SimplePie_File to use as a feed
  380. * @see SimplePie::set_file()
  381. * @access private
  382. */
  383. public $file;
  384. /**
  385. * @var string Raw feed data
  386. * @see SimplePie::set_raw_data()
  387. * @access private
  388. */
  389. public $raw_data;
  390. /**
  391. * @var int Timeout for fetching remote files
  392. * @see SimplePie::set_timeout()
  393. * @access private
  394. */
  395. public $timeout = 10;
  396. /**
  397. * @var array Custom curl options
  398. * @see SimplePie::set_curl_options()
  399. * @access private
  400. */
  401. public $curl_options = array();
  402. /**
  403. * @var bool Forces fsockopen() to be used for remote files instead
  404. * of cURL, even if a new enough version is installed
  405. * @see SimplePie::force_fsockopen()
  406. * @access private
  407. */
  408. public $force_fsockopen = false;
  409. /**
  410. * @var bool Force the given data/URL to be treated as a feed no matter what
  411. * it appears like
  412. * @see SimplePie::force_feed()
  413. * @access private
  414. */
  415. public $force_feed = false;
  416. /**
  417. * @var bool Enable/Disable Caching
  418. * @see SimplePie::enable_cache()
  419. * @access private
  420. */
  421. public $cache = true;
  422. /**
  423. * @var bool Force SimplePie to fallback to expired cache, if enabled,
  424. * when feed is unavailable.
  425. * @see SimplePie::force_cache_fallback()
  426. * @access private
  427. */
  428. public $force_cache_fallback = false;
  429. /**
  430. * @var int Cache duration (in seconds)
  431. * @see SimplePie::set_cache_duration()
  432. * @access private
  433. */
  434. public $cache_duration = 3600;
  435. /**
  436. * @var int Auto-discovery cache duration (in seconds)
  437. * @see SimplePie::set_autodiscovery_cache_duration()
  438. * @access private
  439. */
  440. public $autodiscovery_cache_duration = 604800; // 7 Days.
  441. /**
  442. * @var string Cache location (relative to executing script)
  443. * @see SimplePie::set_cache_location()
  444. * @access private
  445. */
  446. public $cache_location = './cache';
  447. /**
  448. * @var string Function that creates the cache filename
  449. * @see SimplePie::set_cache_name_function()
  450. * @access private
  451. */
  452. public $cache_name_function = 'md5';
  453. /**
  454. * @var bool Reorder feed by date descending
  455. * @see SimplePie::enable_order_by_date()
  456. * @access private
  457. */
  458. public $order_by_date = true;
  459. /**
  460. * @var mixed Force input encoding to be set to the follow value
  461. * (false, or anything type-cast to false, disables this feature)
  462. * @see SimplePie::set_input_encoding()
  463. * @access private
  464. */
  465. public $input_encoding = false;
  466. /**
  467. * @var int Feed Autodiscovery Level
  468. * @see SimplePie::set_autodiscovery_level()
  469. * @access private
  470. */
  471. public $autodiscovery = SIMPLEPIE_LOCATOR_ALL;
  472. /**
  473. * Class registry object
  474. *
  475. * @var SimplePie_Registry
  476. */
  477. public $registry;
  478. /**
  479. * @var int Maximum number of feeds to check with autodiscovery
  480. * @see SimplePie::set_max_checked_feeds()
  481. * @access private
  482. */
  483. public $max_checked_feeds = 10;
  484. /**
  485. * @var array All the feeds found during the autodiscovery process
  486. * @see SimplePie::get_all_discovered_feeds()
  487. * @access private
  488. */
  489. public $all_discovered_feeds = array();
  490. /**
  491. * @var string Web-accessible path to the handler_image.php file.
  492. * @see SimplePie::set_image_handler()
  493. * @access private
  494. */
  495. public $image_handler = '';
  496. /**
  497. * @var array Stores the URLs when multiple feeds are being initialized.
  498. * @see SimplePie::set_feed_url()
  499. * @access private
  500. */
  501. public $multifeed_url = array();
  502. /**
  503. * @var array Stores SimplePie objects when multiple feeds initialized.
  504. * @access private
  505. */
  506. public $multifeed_objects = array();
  507. /**
  508. * @var array Stores the get_object_vars() array for use with multifeeds.
  509. * @see SimplePie::set_feed_url()
  510. * @access private
  511. */
  512. public $config_settings = null;
  513. /**
  514. * @var integer Stores the number of items to return per-feed with multifeeds.
  515. * @see SimplePie::set_item_limit()
  516. * @access private
  517. */
  518. public $item_limit = 0;
  519. /**
  520. * @var bool Stores if last-modified and/or etag headers were sent with the
  521. * request when checking a feed.
  522. */
  523. public $check_modified = false;
  524. /**
  525. * @var array Stores the default attributes to be stripped by strip_attributes().
  526. * @see SimplePie::strip_attributes()
  527. * @access private
  528. */
  529. public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
  530. /**
  531. * @var array Stores the default attributes to add to different tags by add_attributes().
  532. * @see SimplePie::add_attributes()
  533. * @access private
  534. */
  535. public $add_attributes = array('audio' => array('preload' => 'none'), 'iframe' => array('sandbox' => 'allow-scripts allow-same-origin'), 'video' => array('preload' => 'none'));
  536. /**
  537. * @var array Stores the default tags to be stripped by strip_htmltags().
  538. * @see SimplePie::strip_htmltags()
  539. * @access private
  540. */
  541. public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  542. /**
  543. * @var bool Should we throw exceptions, or use the old-style error property?
  544. * @access private
  545. */
  546. public $enable_exceptions = false;
  547. /**
  548. * The SimplePie class contains feed level data and options
  549. *
  550. * To use SimplePie, create the SimplePie object with no parameters. You can
  551. * then set configuration options using the provided methods. After setting
  552. * them, you must initialise the feed using $feed->init(). At that point the
  553. * object's methods and properties will be available to you.
  554. *
  555. * Previously, it was possible to pass in the feed URL along with cache
  556. * options directly into the constructor. This has been removed as of 1.3 as
  557. * it caused a lot of confusion.
  558. *
  559. * @since 1.0 Preview Release
  560. */
  561. public function __construct()
  562. {
  563. if (version_compare(PHP_VERSION, '5.3', '<'))
  564. {
  565. trigger_error('Please upgrade to PHP 5.3 or newer.');
  566. die();
  567. }
  568. // Other objects, instances created here so we can set options on them
  569. $this->sanitize = new SimplePie_Sanitize();
  570. $this->registry = new SimplePie_Registry();
  571. if (func_num_args() > 0)
  572. {
  573. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
  574. trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_duration() directly.', $level);
  575. $args = func_get_args();
  576. switch (count($args)) {
  577. case 3:
  578. $this->set_cache_duration($args[2]);
  579. case 2:
  580. $this->set_cache_location($args[1]);
  581. case 1:
  582. $this->set_feed_url($args[0]);
  583. $this->init();
  584. }
  585. }
  586. }
  587. /**
  588. * Used for converting object to a string
  589. */
  590. public function __toString()
  591. {
  592. return md5(serialize($this->data));
  593. }
  594. /**
  595. * Remove items that link back to this before destroying this object
  596. */
  597. public function __destruct()
  598. {
  599. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
  600. {
  601. if (!empty($this->data['items']))
  602. {
  603. foreach ($this->data['items'] as $item)
  604. {
  605. $item->__destruct();
  606. }
  607. unset($item, $this->data['items']);
  608. }
  609. if (!empty($this->data['ordered_items']))
  610. {
  611. foreach ($this->data['ordered_items'] as $item)
  612. {
  613. $item->__destruct();
  614. }
  615. unset($item, $this->data['ordered_items']);
  616. }
  617. }
  618. }
  619. /**
  620. * Force the given data/URL to be treated as a feed
  621. *
  622. * This tells SimplePie to ignore the content-type provided by the server.
  623. * Be careful when using this option, as it will also disable autodiscovery.
  624. *
  625. * @since 1.1
  626. * @param bool $enable Force the given data/URL to be treated as a feed
  627. */
  628. public function force_feed($enable = false)
  629. {
  630. $this->force_feed = (bool) $enable;
  631. }
  632. /**
  633. * Set the URL of the feed you want to parse
  634. *
  635. * This allows you to enter the URL of the feed you want to parse, or the
  636. * website you want to try to use auto-discovery on. This takes priority
  637. * over any set raw data.
  638. *
  639. * You can set multiple feeds to mash together by passing an array instead
  640. * of a string for the $url. Remember that with each additional feed comes
  641. * additional processing and resources.
  642. *
  643. * @since 1.0 Preview Release
  644. * @see set_raw_data()
  645. * @param string|array $url This is the URL (or array of URLs) that you want to parse.
  646. */
  647. public function set_feed_url($url)
  648. {
  649. $this->multifeed_url = array();
  650. if (is_array($url))
  651. {
  652. foreach ($url as $value)
  653. {
  654. $this->multifeed_url[] = $this->registry->call('Misc', 'fix_protocol', array($value, 1));
  655. }
  656. }
  657. else
  658. {
  659. $this->feed_url = $this->registry->call('Misc', 'fix_protocol', array($url, 1));
  660. $this->permanent_url = $this->feed_url;
  661. }
  662. }
  663. /**
  664. * Set an instance of {@see SimplePie_File} to use as a feed
  665. *
  666. * @param SimplePie_File &$file
  667. * @return bool True on success, false on failure
  668. */
  669. public function set_file(&$file)
  670. {
  671. if ($file instanceof SimplePie_File)
  672. {
  673. $this->feed_url = $file->url;
  674. $this->permanent_url = $this->feed_url;
  675. $this->file =& $file;
  676. return true;
  677. }
  678. return false;
  679. }
  680. /**
  681. * Set the raw XML data to parse
  682. *
  683. * Allows you to use a string of RSS/Atom data instead of a remote feed.
  684. *
  685. * If you have a feed available as a string in PHP, you can tell SimplePie
  686. * to parse that data string instead of a remote feed. Any set feed URL
  687. * takes precedence.
  688. *
  689. * @since 1.0 Beta 3
  690. * @param string $data RSS or Atom data as a string.
  691. * @see set_feed_url()
  692. */
  693. public function set_raw_data($data)
  694. {
  695. $this->raw_data = $data;
  696. }
  697. /**
  698. * Set the the default timeout for fetching remote feeds
  699. *
  700. * This allows you to change the maximum time the feed's server to respond
  701. * and send the feed back.
  702. *
  703. * @since 1.0 Beta 3
  704. * @param int $timeout The maximum number of seconds to spend waiting to retrieve a feed.
  705. */
  706. public function set_timeout($timeout = 10)
  707. {
  708. $this->timeout = (int) $timeout;
  709. }
  710. /**
  711. * Set custom curl options
  712. *
  713. * This allows you to change default curl options
  714. *
  715. * @since 1.0 Beta 3
  716. * @param array $curl_options Curl options to add to default settings
  717. */
  718. public function set_curl_options(array $curl_options = array())
  719. {
  720. $this->curl_options = $curl_options;
  721. }
  722. /**
  723. * Force SimplePie to use fsockopen() instead of cURL
  724. *
  725. * @since 1.0 Beta 3
  726. * @param bool $enable Force fsockopen() to be used
  727. */
  728. public function force_fsockopen($enable = false)
  729. {
  730. $this->force_fsockopen = (bool) $enable;
  731. }
  732. /**
  733. * Enable/disable caching in SimplePie.
  734. *
  735. * This option allows you to disable caching all-together in SimplePie.
  736. * However, disabling the cache can lead to longer load times.
  737. *
  738. * @since 1.0 Preview Release
  739. * @param bool $enable Enable caching
  740. */
  741. public function enable_cache($enable = true)
  742. {
  743. $this->cache = (bool) $enable;
  744. }
  745. /**
  746. * SimplePie to continue to fall back to expired cache, if enabled, when
  747. * feed is unavailable.
  748. *
  749. * This tells SimplePie to ignore any file errors and fall back to cache
  750. * instead. This only works if caching is enabled and cached content
  751. * still exists.
  752. * @param bool $enable Force use of cache on fail.
  753. */
  754. public function force_cache_fallback($enable = false)
  755. {
  756. $this->force_cache_fallback= (bool) $enable;
  757. }
  758. /**
  759. * Set the length of time (in seconds) that the contents of a feed will be
  760. * cached
  761. *
  762. * @param int $seconds The feed content cache duration
  763. */
  764. public function set_cache_duration($seconds = 3600)
  765. {
  766. $this->cache_duration = (int) $seconds;
  767. }
  768. /**
  769. * Set the length of time (in seconds) that the autodiscovered feed URL will
  770. * be cached
  771. *
  772. * @param int $seconds The autodiscovered feed URL cache duration.
  773. */
  774. public function set_autodiscovery_cache_duration($seconds = 604800)
  775. {
  776. $this->autodiscovery_cache_duration = (int) $seconds;
  777. }
  778. /**
  779. * Set the file system location where the cached files should be stored
  780. *
  781. * @param string $location The file system location.
  782. */
  783. public function set_cache_location($location = './cache')
  784. {
  785. $this->cache_location = (string) $location;
  786. }
  787. /**
  788. * Set whether feed items should be sorted into reverse chronological order
  789. *
  790. * @param bool $enable Sort as reverse chronological order.
  791. */
  792. public function enable_order_by_date($enable = true)
  793. {
  794. $this->order_by_date = (bool) $enable;
  795. }
  796. /**
  797. * Set the character encoding used to parse the feed
  798. *
  799. * This overrides the encoding reported by the feed, however it will fall
  800. * back to the normal encoding detection if the override fails
  801. *
  802. * @param string $encoding Character encoding
  803. */
  804. public function set_input_encoding($encoding = false)
  805. {
  806. if ($encoding)
  807. {
  808. $this->input_encoding = (string) $encoding;
  809. }
  810. else
  811. {
  812. $this->input_encoding = false;
  813. }
  814. }
  815. /**
  816. * Set how much feed autodiscovery to do
  817. *
  818. * @see SIMPLEPIE_LOCATOR_NONE
  819. * @see SIMPLEPIE_LOCATOR_AUTODISCOVERY
  820. * @see SIMPLEPIE_LOCATOR_LOCAL_EXTENSION
  821. * @see SIMPLEPIE_LOCATOR_LOCAL_BODY
  822. * @see SIMPLEPIE_LOCATOR_REMOTE_EXTENSION
  823. * @see SIMPLEPIE_LOCATOR_REMOTE_BODY
  824. * @see SIMPLEPIE_LOCATOR_ALL
  825. * @param int $level Feed Autodiscovery Level (level can be a combination of the above constants, see bitwise OR operator)
  826. */
  827. public function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL)
  828. {
  829. $this->autodiscovery = (int) $level;
  830. }
  831. /**
  832. * Get the class registry
  833. *
  834. * Use this to override SimplePie's default classes
  835. * @see SimplePie_Registry
  836. * @return SimplePie_Registry
  837. */
  838. public function &get_registry()
  839. {
  840. return $this->registry;
  841. }
  842. /**#@+
  843. * Useful when you are overloading or extending SimplePie's default classes.
  844. *
  845. * @deprecated Use {@see get_registry()} instead
  846. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  847. * @param string $class Name of custom class
  848. * @return boolean True on success, false otherwise
  849. */
  850. /**
  851. * Set which class SimplePie uses for caching
  852. */
  853. public function set_cache_class($class = 'SimplePie_Cache')
  854. {
  855. return $this->registry->register('Cache', $class, true);
  856. }
  857. /**
  858. * Set which class SimplePie uses for auto-discovery
  859. */
  860. public function set_locator_class($class = 'SimplePie_Locator')
  861. {
  862. return $this->registry->register('Locator', $class, true);
  863. }
  864. /**
  865. * Set which class SimplePie uses for XML parsing
  866. */
  867. public function set_parser_class($class = 'SimplePie_Parser')
  868. {
  869. return $this->registry->register('Parser', $class, true);
  870. }
  871. /**
  872. * Set which class SimplePie uses for remote file fetching
  873. */
  874. public function set_file_class($class = 'SimplePie_File')
  875. {
  876. return $this->registry->register('File', $class, true);
  877. }
  878. /**
  879. * Set which class SimplePie uses for data sanitization
  880. */
  881. public function set_sanitize_class($class = 'SimplePie_Sanitize')
  882. {
  883. return $this->registry->register('Sanitize', $class, true);
  884. }
  885. /**
  886. * Set which class SimplePie uses for handling feed items
  887. */
  888. public function set_item_class($class = 'SimplePie_Item')
  889. {
  890. return $this->registry->register('Item', $class, true);
  891. }
  892. /**
  893. * Set which class SimplePie uses for handling author data
  894. */
  895. public function set_author_class($class = 'SimplePie_Author')
  896. {
  897. return $this->registry->register('Author', $class, true);
  898. }
  899. /**
  900. * Set which class SimplePie uses for handling category data
  901. */
  902. public function set_category_class($class = 'SimplePie_Category')
  903. {
  904. return $this->registry->register('Category', $class, true);
  905. }
  906. /**
  907. * Set which class SimplePie uses for feed enclosures
  908. */
  909. public function set_enclosure_class($class = 'SimplePie_Enclosure')
  910. {
  911. return $this->registry->register('Enclosure', $class, true);
  912. }
  913. /**
  914. * Set which class SimplePie uses for `<media:text>` captions
  915. */
  916. public function set_caption_class($class = 'SimplePie_Caption')
  917. {
  918. return $this->registry->register('Caption', $class, true);
  919. }
  920. /**
  921. * Set which class SimplePie uses for `<media:copyright>`
  922. */
  923. public function set_copyright_class($class = 'SimplePie_Copyright')
  924. {
  925. return $this->registry->register('Copyright', $class, true);
  926. }
  927. /**
  928. * Set which class SimplePie uses for `<media:credit>`
  929. */
  930. public function set_credit_class($class = 'SimplePie_Credit')
  931. {
  932. return $this->registry->register('Credit', $class, true);
  933. }
  934. /**
  935. * Set which class SimplePie uses for `<media:rating>`
  936. */
  937. public function set_rating_class($class = 'SimplePie_Rating')
  938. {
  939. return $this->registry->register('Rating', $class, true);
  940. }
  941. /**
  942. * Set which class SimplePie uses for `<media:restriction>`
  943. */
  944. public function set_restriction_class($class = 'SimplePie_Restriction')
  945. {
  946. return $this->registry->register('Restriction', $class, true);
  947. }
  948. /**
  949. * Set which class SimplePie uses for content-type sniffing
  950. */
  951. public function set_content_type_sniffer_class($class = 'SimplePie_Content_Type_Sniffer')
  952. {
  953. return $this->registry->register('Content_Type_Sniffer', $class, true);
  954. }
  955. /**
  956. * Set which class SimplePie uses item sources
  957. */
  958. public function set_source_class($class = 'SimplePie_Source')
  959. {
  960. return $this->registry->register('Source', $class, true);
  961. }
  962. /**#@-*/
  963. /**
  964. * Set the user agent string
  965. *
  966. * @param string $ua New user agent string.
  967. */
  968. public function set_useragent($ua = SIMPLEPIE_USERAGENT)
  969. {
  970. $this->useragent = (string) $ua;
  971. }
  972. /**
  973. * Set callback function to create cache filename with
  974. *
  975. * @param mixed $function Callback function
  976. */
  977. public function set_cache_name_function($function = 'md5')
  978. {
  979. if (is_callable($function))
  980. {
  981. $this->cache_name_function = $function;
  982. }
  983. }
  984. /**
  985. * Set options to make SP as fast as possible
  986. *
  987. * Forgoes a substantial amount of data sanitization in favor of speed. This
  988. * turns SimplePie into a dumb parser of feeds.
  989. *
  990. * @param bool $set Whether to set them or not
  991. */
  992. public function set_stupidly_fast($set = false)
  993. {
  994. if ($set)
  995. {
  996. $this->enable_order_by_date(false);
  997. $this->remove_div(false);
  998. $this->strip_comments(false);
  999. $this->strip_htmltags(false);
  1000. $this->strip_attributes(false);
  1001. $this->add_attributes(false);
  1002. $this->set_image_handler(false);
  1003. }
  1004. }
  1005. /**
  1006. * Set maximum number of feeds to check with autodiscovery
  1007. *
  1008. * @param int $max Maximum number of feeds to check
  1009. */
  1010. public function set_max_checked_feeds($max = 10)
  1011. {
  1012. $this->max_checked_feeds = (int) $max;
  1013. }
  1014. public function remove_div($enable = true)
  1015. {
  1016. $this->sanitize->remove_div($enable);
  1017. }
  1018. public function strip_htmltags($tags = '', $encode = null)
  1019. {
  1020. if ($tags === '')
  1021. {
  1022. $tags = $this->strip_htmltags;
  1023. }
  1024. $this->sanitize->strip_htmltags($tags);
  1025. if ($encode !== null)
  1026. {
  1027. $this->sanitize->encode_instead_of_strip($tags);
  1028. }
  1029. }
  1030. public function encode_instead_of_strip($enable = true)
  1031. {
  1032. $this->sanitize->encode_instead_of_strip($enable);
  1033. }
  1034. public function strip_attributes($attribs = '')
  1035. {
  1036. if ($attribs === '')
  1037. {
  1038. $attribs = $this->strip_attributes;
  1039. }
  1040. $this->sanitize->strip_attributes($attribs);
  1041. }
  1042. public function add_attributes($attribs = '')
  1043. {
  1044. if ($attribs === '')
  1045. {
  1046. $attribs = $this->add_attributes;
  1047. }
  1048. $this->sanitize->add_attributes($attribs);
  1049. }
  1050. /**
  1051. * Set the output encoding
  1052. *
  1053. * Allows you to override SimplePie's output to match that of your webpage.
  1054. * This is useful for times when your webpages are not being served as
  1055. * UTF-8. This setting will be obeyed by {@see handle_content_type()}, and
  1056. * is similar to {@see set_input_encoding()}.
  1057. *
  1058. * It should be noted, however, that not all character encodings can support
  1059. * all characters. If your page is being served as ISO-8859-1 and you try
  1060. * to display a Japanese feed, you'll likely see garbled characters.
  1061. * Because of this, it is highly recommended to ensure that your webpages
  1062. * are served as UTF-8.
  1063. *
  1064. * The number of supported character encodings depends on whether your web
  1065. * host supports {@link http://php.net/mbstring mbstring},
  1066. * {@link http://php.net/iconv iconv}, or both. See
  1067. * {@link http://simplepie.org/wiki/faq/Supported_Character_Encodings} for
  1068. * more information.
  1069. *
  1070. * @param string $encoding
  1071. */
  1072. public function set_output_encoding($encoding = 'UTF-8')
  1073. {
  1074. $this->sanitize->set_output_encoding($encoding);
  1075. }
  1076. public function strip_comments($strip = false)
  1077. {
  1078. $this->sanitize->strip_comments($strip);
  1079. }
  1080. /**
  1081. * Set element/attribute key/value pairs of HTML attributes
  1082. * containing URLs that need to be resolved relative to the feed
  1083. *
  1084. * Defaults to |a|@href, |area|@href, |blockquote|@cite, |del|@cite,
  1085. * |form|@action, |img|@longdesc, |img|@src, |input|@src, |ins|@cite,
  1086. * |q|@cite
  1087. *
  1088. * @since 1.0
  1089. * @param array|null $element_attribute Element/attribute key/value pairs, null for default
  1090. */
  1091. public function set_url_replacements($element_attribute = null)
  1092. {
  1093. $this->sanitize->set_url_replacements($element_attribute);
  1094. }
  1095. /**
  1096. * Set the handler to enable the display of cached images.
  1097. *
  1098. * @param str $page Web-accessible path to the handler_image.php file.
  1099. * @param str $qs The query string that the value should be passed to.
  1100. */
  1101. public function set_image_handler($page = false, $qs = 'i')
  1102. {
  1103. if ($page !== false)
  1104. {
  1105. $this->sanitize->set_image_handler($page . '?' . $qs . '=');
  1106. }
  1107. else
  1108. {
  1109. $this->image_handler = '';
  1110. }
  1111. }
  1112. /**
  1113. * Set the limit for items returned per-feed with multifeeds
  1114. *
  1115. * @param integer $limit The maximum number of items to return.
  1116. */
  1117. public function set_item_limit($limit = 0)
  1118. {
  1119. $this->item_limit = (int) $limit;
  1120. }
  1121. /**
  1122. * Enable throwing exceptions
  1123. *
  1124. * @param boolean $enable Should we throw exceptions, or use the old-style error property?
  1125. */
  1126. public function enable_exceptions($enable = true)
  1127. {
  1128. $this->enable_exceptions = $enable;
  1129. }
  1130. /**
  1131. * Initialize the feed object
  1132. *
  1133. * This is what makes everything happen. Period. This is where all of the
  1134. * configuration options get processed, feeds are fetched, cached, and
  1135. * parsed, and all of that other good stuff.
  1136. *
  1137. * @return boolean True if successful, false otherwise
  1138. */
  1139. public function init()
  1140. {
  1141. // Check absolute bare minimum requirements.
  1142. if (!extension_loaded('xml') || !extension_loaded('pcre'))
  1143. {
  1144. $this->error = 'XML or PCRE extensions not loaded!';
  1145. return false;
  1146. }
  1147. // Then check the xml extension is sane (i.e., libxml 2.7.x issue on PHP < 5.2.9 and libxml 2.7.0 to 2.7.2 on any version) if we don't have xmlreader.
  1148. elseif (!extension_loaded('xmlreader'))
  1149. {
  1150. static $xml_is_sane = null;
  1151. if ($xml_is_sane === null)
  1152. {
  1153. $parser_check = xml_parser_create();
  1154. xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
  1155. xml_parser_free($parser_check);
  1156. $xml_is_sane = isset($values[0]['value']);
  1157. }
  1158. if (!$xml_is_sane)
  1159. {
  1160. return false;
  1161. }
  1162. }
  1163. if (method_exists($this->sanitize, 'set_registry'))
  1164. {
  1165. $this->sanitize->set_registry($this->registry);
  1166. }
  1167. // Pass whatever was set with config options over to the sanitizer.
  1168. // Pass the classes in for legacy support; new classes should use the registry instead
  1169. $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache'));
  1170. $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen, $this->curl_options);
  1171. if (!empty($this->multifeed_url))
  1172. {
  1173. $i = 0;
  1174. $success = 0;
  1175. $this->multifeed_objects = array();
  1176. $this->error = array();
  1177. foreach ($this->multifeed_url as $url)
  1178. {
  1179. $this->multifeed_objects[$i] = clone $this;
  1180. $this->multifeed_objects[$i]->set_feed_url($url);
  1181. $single_success = $this->multifeed_objects[$i]->init();
  1182. $success |= $single_success;
  1183. if (!$single_success)
  1184. {
  1185. $this->error[$i] = $this->multifeed_objects[$i]->error();
  1186. }
  1187. $i++;
  1188. }
  1189. return (bool) $success;
  1190. }
  1191. elseif ($this->feed_url === null && $this->raw_data === null)
  1192. {
  1193. return false;
  1194. }
  1195. $this->error = null;
  1196. $this->data = array();
  1197. $this->check_modified = false;
  1198. $this->multifeed_objects = array();
  1199. $cache = false;
  1200. if ($this->feed_url !== null)
  1201. {
  1202. $parsed_feed_url = $this->registry->call('Misc', 'parse_url', array($this->feed_url));
  1203. // Decide whether to enable caching
  1204. if ($this->cache && $parsed_feed_url['scheme'] !== '')
  1205. {
  1206. $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc'));
  1207. }
  1208. // Fetch the data via SimplePie_File into $this->raw_data
  1209. if (($fetched = $this->fetch_data($cache)) === true)
  1210. {
  1211. return true;
  1212. }
  1213. elseif ($fetched === false) {
  1214. return false;
  1215. }
  1216. list($headers, $sniffed) = $fetched;
  1217. }
  1218. // Empty response check
  1219. if(empty($this->raw_data)){
  1220. $this->error = "A feed could not be found at `$this->feed_url`. Empty body.";
  1221. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
  1222. return false;
  1223. }
  1224. // Set up array of possible encodings
  1225. $encodings = array();
  1226. // First check to see if input has been overridden.
  1227. if ($this->input_encoding !== false)
  1228. {
  1229. $encodings[] = strtoupper($this->input_encoding);
  1230. }
  1231. $application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
  1232. $text_types = array('text/xml', 'text/xml-external-parsed-entity');
  1233. // RFC 3023 (only applies to sniffed content)
  1234. if (isset($sniffed))
  1235. {
  1236. if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml')
  1237. {
  1238. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
  1239. {
  1240. $encodings[] = strtoupper($charset[1]);
  1241. }
  1242. $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
  1243. $encodings[] = 'UTF-8';
  1244. }
  1245. elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml')
  1246. {
  1247. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
  1248. {
  1249. $encodings[] = strtoupper($charset[1]);
  1250. }
  1251. $encodings[] = 'US-ASCII';
  1252. }
  1253. // Text MIME-type default
  1254. elseif (substr($sniffed, 0, 5) === 'text/')
  1255. {
  1256. $encodings[] = 'UTF-8';
  1257. }
  1258. }
  1259. // Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1
  1260. $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
  1261. $encodings[] = 'UTF-8';
  1262. $encodings[] = 'ISO-8859-1';
  1263. // There's no point in trying an encoding twice
  1264. $encodings = array_unique($encodings);
  1265. // Loop through each possible encoding, till we return something, or run out of possibilities
  1266. foreach ($encodings as $encoding)
  1267. {
  1268. // Change the encoding to UTF-8 (as we always use UTF-8 internally)
  1269. if ($utf8_data = $this->registry->call('Misc', 'change_encoding', array($this->raw_data, $encoding, 'UTF-8')))
  1270. {
  1271. // Create new parser
  1272. $parser = $this->registry->create('Parser');
  1273. // If it's parsed fine
  1274. if ($parser->parse($utf8_data, 'UTF-8', $this->permanent_url))
  1275. {
  1276. $this->data = $parser->get_data();
  1277. if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE))
  1278. {
  1279. $this->error = "A feed could not be found at `$this->feed_url`. This does not appear to be a valid RSS or Atom feed.";
  1280. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
  1281. return false;
  1282. }
  1283. if (isset($headers))
  1284. {
  1285. $this->data['headers'] = $headers;
  1286. }
  1287. $this->data['build'] = SIMPLEPIE_BUILD;
  1288. // Cache the file if caching is enabled
  1289. if ($cache && !$cache->save($this))
  1290. {
  1291. trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
  1292. }
  1293. return true;
  1294. }
  1295. }
  1296. }
  1297. if (isset($parser))
  1298. {
  1299. // We have an error, just set SimplePie_Misc::error to it and quit
  1300. $this->error = $this->feed_url;
  1301. $this->error .= sprintf(' is invalid XML, likely due to invalid characters. XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column());
  1302. }
  1303. else
  1304. {
  1305. $this->error = 'The data could not be converted to UTF-8.';
  1306. if (!extension_loaded('mbstring') && !extension_loaded('iconv') && !class_exists('\UConverter')) {
  1307. $this->error .= ' You MUST have either the iconv, mbstring or intl (PHP 5.5+) extension installed and enabled.';
  1308. } else {
  1309. $missingExtensions = array();
  1310. if (!extension_loaded('iconv')) {
  1311. $missingExtensions[] = 'iconv';
  1312. }
  1313. if (!extension_loaded('mbstring')) {
  1314. $missingExtensions[] = 'mbstring';
  1315. }
  1316. if (!class_exists('\UConverter')) {
  1317. $missingExtensions[] = 'intl (PHP 5.5+)';
  1318. }
  1319. $this->error .= ' Try installing/enabling the ' . implode(' or ', $missingExtensions) . ' extension.';
  1320. }
  1321. }
  1322. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
  1323. return false;
  1324. }
  1325. /**
  1326. * Fetch the data via SimplePie_File
  1327. *
  1328. * If the data is already cached, attempt to fetch it from there instead
  1329. * @param SimplePie_Cache|false $cache Cache handler, or false to not load from the cache
  1330. * @return array|true Returns true if the data was loaded from the cache, or an array of HTTP headers and sniffed type
  1331. */
  1332. protected function fetch_data(&$cache)
  1333. {
  1334. // If it's enabled, use the cache
  1335. if ($cache)
  1336. {
  1337. // Load the Cache
  1338. $this->data = $cache->load();
  1339. if (!empty($this->data))
  1340. {
  1341. // If the cache is for an outdated build of SimplePie
  1342. if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD)
  1343. {
  1344. $cache->unlink();
  1345. $this->data = array();
  1346. }
  1347. // If we've hit a collision just rerun it with caching disabled
  1348. elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url)
  1349. {
  1350. $cache = false;
  1351. $this->data = array();
  1352. }
  1353. // If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL.
  1354. elseif (isset($this->data['feed_url']))
  1355. {
  1356. // If the autodiscovery cache is still valid use it.
  1357. if ($cache->mtime() + $this->autodiscovery_cache_duration > time())
  1358. {
  1359. // Do not need to do feed autodiscovery yet.
  1360. if ($this->data['feed_url'] !== $this->data['url'])
  1361. {
  1362. $this->set_feed_url($this->data['feed_url']);
  1363. return $this->init();
  1364. }
  1365. $cache->unlink();
  1366. $this->data = array();
  1367. }
  1368. }
  1369. // Check if the cache has been updated
  1370. elseif ($cache->mtime() + $this->cache_duration < time())
  1371. {
  1372. // Want to know if we tried to send last-modified and/or etag headers
  1373. // when requesting this file. (Note that it's up to the file to
  1374. // support this, but we don't always send the headers either.)
  1375. $this->check_modified = true;
  1376. if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag']))
  1377. {
  1378. $headers = array(
  1379. 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
  1380. );
  1381. if (isset($this->data['headers']['last-modified']))
  1382. {
  1383. $headers['if-modified-since'] = $this->data['headers']['last-modified'];
  1384. }
  1385. if (isset($this->data['headers']['etag']))
  1386. {
  1387. $headers['if-none-match'] = $this->data['headers']['etag'];
  1388. }
  1389. $file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options));
  1390. if ($file->success)
  1391. {
  1392. if ($file->status_code === 304)
  1393. {
  1394. // Set raw_data to false here too, to signify that the cache
  1395. // is still valid.
  1396. $this->raw_data = false;
  1397. $cache->touch();
  1398. return true;
  1399. }
  1400. }
  1401. else
  1402. {
  1403. $this->check_modified = false;
  1404. if($this->force_cache_fallback)
  1405. {
  1406. $cache->touch();
  1407. return true;
  1408. }
  1409. unset($file);
  1410. }
  1411. }
  1412. }
  1413. // If the cache is still valid, just return true
  1414. else
  1415. {
  1416. $this->raw_data = false;
  1417. return true;
  1418. }
  1419. }
  1420. // If the cache is empty, delete it
  1421. else
  1422. {
  1423. $cache->unlink();
  1424. $this->data = array();
  1425. }
  1426. }
  1427. // 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.
  1428. if (!isset($file))
  1429. {
  1430. if ($this->file instanceof SimplePie_File && $this->file->url === $this->feed_url)
  1431. {
  1432. $file =& $this->file;
  1433. }
  1434. else
  1435. {
  1436. $headers = array(
  1437. 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
  1438. );
  1439. $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options));
  1440. }
  1441. }
  1442. // If the file connection has an error, set SimplePie::error to that and quit
  1443. if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
  1444. {
  1445. $this->error = $file->error;
  1446. return !empty($this->data);
  1447. }
  1448. if (!$this->force_feed)
  1449. {
  1450. // Check if the supplied URL is a feed, if it isn't, look for it.
  1451. $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds));
  1452. if (!$locate->is_feed($file))
  1453. {
  1454. $copyStatusCode = $file->status_code;
  1455. $copyContentType = $file->headers['content-type'];
  1456. try
  1457. {
  1458. $microformats = false;
  1459. if (function_exists('Mf2\parse')) {
  1460. // Check for both h-feed and h-entry, as both a feed with no entries
  1461. // and a list of entries without an h-feed wrapper are both valid.
  1462. $position = 0;
  1463. while ($position = strpos($file->body, 'h-feed', $position))
  1464. {
  1465. $start = $position < 200 ? 0 : $position - 200;
  1466. $check = substr($file->body, $start, 400);
  1467. if ($microformats = preg_match('/class="[^"]*h-feed/', $check))
  1468. {
  1469. break;
  1470. }
  1471. $position += 7;
  1472. }
  1473. $position = 0;
  1474. while ($position = strpos($file->body, 'h-entry', $position))
  1475. {
  1476. $start = $position < 200 ? 0 : $position - 200;
  1477. $check = substr($file->body, $start, 400);
  1478. if ($microformats = preg_match('/class="[^"]*h-entry/', $check))
  1479. {
  1480. break;
  1481. }
  1482. $position += 7;
  1483. }
  1484. }
  1485. // Now also do feed discovery, but if an h-entry was found don't
  1486. // overwrite the current value of file.
  1487. $discovered = $locate->find($this->autodiscovery,
  1488. $this->all_discovered_feeds);
  1489. if ($microformats)
  1490. {
  1491. if ($hub = $locate->get_rel_link('hub'))
  1492. {
  1493. $self = $locate->get_rel_link('self');
  1494. $this->store_links($file, $hub, $self);
  1495. }
  1496. // Push the current file onto all_discovered feeds so the user can
  1497. // be shown this as one of the options.
  1498. if (isset($this->all_discovered_feeds)) {
  1499. $this->all_discovered_feeds[] = $file;
  1500. }
  1501. }
  1502. else
  1503. {
  1504. if ($discovered)
  1505. {
  1506. $file = $discovered;
  1507. }
  1508. else
  1509. {
  1510. // We need to unset this so that if SimplePie::set_file() has
  1511. // been called that object is untouched
  1512. unset($file);
  1513. $this->error = "A feed could not be found at `$this->feed_url`; the status code is `$copyStatusCode` and content-type is `$copyContentType`";
  1514. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
  1515. return false;
  1516. }
  1517. }
  1518. }
  1519. catch (SimplePie_Exception $e)
  1520. {
  1521. // We need to unset this so that if SimplePie::set_file() has been called that object is untouched
  1522. unset($file);
  1523. // This is usually because DOMDocument doesn't exist
  1524. $this->error = $e->getMessage();
  1525. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, $e->getFile(), $e->getLine()));
  1526. return false;
  1527. }
  1528. if ($cache)
  1529. {
  1530. $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD);
  1531. if (!$cache->save($this))
  1532. {
  1533. trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
  1534. }
  1535. $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc'));
  1536. }
  1537. $this->feed_url = $file->url;
  1538. }
  1539. $locate = null;
  1540. }
  1541. $this->raw_data = $file->body;
  1542. $this->permanent_url = $file->permanent_url;
  1543. $headers = $file->headers;
  1544. $sniffer = $this->registry->create('Content_Type_Sniffer', array(&$file));
  1545. $sniffed = $sniffer->get_type();
  1546. return array($headers, $sniffed);
  1547. }
  1548. /**
  1549. * Get the error message for the occured error
  1550. *
  1551. * @return string|array Error message, or array of messages for multifeeds
  1552. */
  1553. public function error()
  1554. {
  1555. return $this->error;
  1556. }
  1557. /**
  1558. * Get the raw XML
  1559. *
  1560. * This is the same as the old `$feed->enable_xml_dump(true)`, but returns
  1561. * the data instead of printing it.
  1562. *
  1563. * @return string|boolean Raw XML data, false if the cache is used
  1564. */
  1565. public function get_raw_data()
  1566. {
  1567. return $this->raw_data;
  1568. }
  1569. /**
  1570. * Get the character encoding used for output
  1571. *
  1572. * @since Preview Release
  1573. * @return string
  1574. */
  1575. public function get_encoding()
  1576. {
  1577. return $this->sanitize->output_encoding;
  1578. }
  1579. /**
  1580. * Send the content-type header with correct encoding
  1581. *
  1582. * This method ensures that the SimplePie-enabled page is being served with
  1583. * the correct {@link http://www.iana.org/assignments/media-types/ mime-type}
  1584. * and character encoding HTTP headers (character encoding determined by the
  1585. * {@see set_output_encoding} config option).
  1586. *
  1587. * This won't work properly if any content or whitespace has already been
  1588. * sent to the browser, because it relies on PHP's
  1589. * {@link http://php.net/header header()} function, and these are the
  1590. * circumstances under which the function works.
  1591. *
  1592. * Because it's setting these settings for the entire page (as is the nature
  1593. * of HTTP headers), this should only be used once per page (again, at the
  1594. * top).
  1595. *
  1596. * @param string $mime MIME type to serve the page as
  1597. */
  1598. public function handle_content_type($mime = 'text/html')
  1599. {
  1600. if (!headers_sent())
  1601. {
  1602. $header = "Content-type: $mime;";
  1603. if ($this->get_encoding())
  1604. {
  1605. $header .= ' charset=' . $this->get_encoding();
  1606. }
  1607. else
  1608. {
  1609. $header .= ' charset=UTF-8';
  1610. }
  1611. header($header);
  1612. }
  1613. }
  1614. /**
  1615. * Get the type of the feed
  1616. *
  1617. * This returns a SIMPLEPIE_TYPE_* constant, which can be tested against
  1618. * using {@link http://php.net/language.operators.bitwise bitwise operators}
  1619. *
  1620. * @since 0.8 (usage changed to using constants in 1.0)
  1621. * @see SIMPLEPIE_TYPE_NONE Unknown.
  1622. * @see SIMPLEPIE_TYPE_RSS_090 RSS 0.90.
  1623. * @see SIMPLEPIE_TYPE_RSS_091_NETSCAPE RSS 0.91 (Netscape).
  1624. * @see SIMPLEPIE_TYPE_RSS_091_USERLAND RSS 0.91 (Userland).
  1625. * @see SIMPLEPIE_TYPE_RSS_091 RSS 0.91.
  1626. * @see SIMPLEPIE_TYPE_RSS_092 RSS 0.92.
  1627. * @see SIMPLEPIE_TYPE_RSS_093 RSS 0.93.
  1628. * @see SIMPLEPIE_TYPE_RSS_094 RSS 0.94.
  1629. * @see SIMPLEPIE_TYPE_RSS_10 RSS 1.0.
  1630. * @see SIMPLEPIE_TYPE_RSS_20 RSS 2.0.x.
  1631. * @see SIMPLEPIE_TYPE_RSS_RDF RDF-based RSS.
  1632. * @see SIMPLEPIE_TYPE_RSS_SYNDICATION Non-RDF-based RSS (truly intended as syndication format).
  1633. * @see SIMPLEPIE_TYPE_RSS_ALL Any version of RSS.
  1634. * @see SIMPLEPIE_TYPE_ATOM_03 Atom 0.3.
  1635. * @see SIMPLEPIE_TYPE_ATOM_10 Atom 1.0.
  1636. * @see SIMPLEPIE_TYPE_ATOM_ALL Any version of Atom.
  1637. * @see SIMPLEPIE_TYPE_ALL Any known/supported feed type.
  1638. * @return int SIMPLEPIE_TYPE_* constant
  1639. */
  1640. public function get_type()
  1641. {
  1642. if (!isset($this->data['type']))
  1643. {
  1644. $this->data['type'] = SIMPLEPIE_TYPE_ALL;
  1645. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed']))
  1646. {
  1647. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10;
  1648. }
  1649. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed']))
  1650. {
  1651. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03;
  1652. }
  1653. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF']))
  1654. {
  1655. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel'])
  1656. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image'])
  1657. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item'])
  1658. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput']))
  1659. {
  1660. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10;
  1661. }
  1662. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel'])
  1663. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image'])
  1664. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item'])
  1665. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput']))
  1666. {
  1667. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090;
  1668. }
  1669. }
  1670. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss']))
  1671. {
  1672. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL;
  1673. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
  1674. {
  1675. switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
  1676. {
  1677. case '0.91':
  1678. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091;
  1679. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
  1680. {
  1681. switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
  1682. {
  1683. case '0':
  1684. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE;
  1685. break;
  1686. case '24':
  1687. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND;
  1688. break;
  1689. }
  1690. }
  1691. break;
  1692. case '0.92':
  1693. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092;
  1694. break;
  1695. case '0.93':
  1696. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093;
  1697. break;
  1698. case '0.94':
  1699. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094;
  1700. break;
  1701. case '2.0':
  1702. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20;
  1703. break;
  1704. }
  1705. }
  1706. }
  1707. else
  1708. {
  1709. $this->data['type'] = SIMPLEPIE_TYPE_NONE;
  1710. }
  1711. }
  1712. return $this->data['type'];
  1713. }
  1714. /**
  1715. * Get the URL for the feed
  1716. *
  1717. * When the 'permanent' mode is enabled, returns the original feed URL,
  1718. * except in the case of an `HTTP 301 Moved Permanently` status response,
  1719. * in which case the location of the first redirection is returned.
  1720. *
  1721. * When the 'permanent' mode is disabled (default),
  1722. * may or may not be different from the URL passed to {@see set_feed_url()},
  1723. * depending on whether auto-discovery was used.
  1724. *
  1725. * @since Preview Release (previously called `get_feed_url()` since SimplePie 0.8.)
  1726. * @todo Support <itunes:new-feed-url>
  1727. * @todo Also, |atom:link|@rel=self
  1728. * @param bool $permanent Permanent mode to return only the original URL or the first redirection
  1729. * iff it is a 301 redirection
  1730. * @return string|null
  1731. */
  1732. public function subscribe_url($permanent = false)
  1733. {
  1734. if ($permanent)
  1735. {
  1736. if ($this->permanent_url !== null)
  1737. {
  1738. // sanitize encodes ampersands which are required when used in a url.
  1739. return str_replace('&amp;', '&',
  1740. $this->sanitize($this->permanent_url,
  1741. SIMPLEPIE_CONSTRUCT_IRI));
  1742. }
  1743. }
  1744. else
  1745. {
  1746. if ($this->feed_url !== null)
  1747. {
  1748. return str_replace('&amp;', '&',
  1749. $this->sanitize($this->feed_url,
  1750. SIMPLEPIE_CONSTRUCT_IRI));
  1751. }
  1752. }
  1753. return null;
  1754. }
  1755. /**
  1756. * Get data for an feed-level element
  1757. *
  1758. * This method allows you to get access to ANY element/attribute that is a
  1759. * sub-element of the opening feed tag.
  1760. *
  1761. * The return value is an indexed array of elements matching the given
  1762. * namespace and tag name. Each element has `attribs`, `data` and `child`
  1763. * subkeys. For `attribs` and `child`, these contain namespace subkeys.
  1764. * `attribs` then has one level of associative name => value data (where
  1765. * `value` is a string) after the namespace. `child` has tag-indexed keys
  1766. * after the namespace, each member of which is an indexed array matching
  1767. * this same format.
  1768. *
  1769. * For example:
  1770. * <pre>
  1771. * // This is probably a bad example because we already support
  1772. * // <media:content> natively, but it shows you how to parse through
  1773. * // the nodes.
  1774. * $group = $item->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group');
  1775. * $content = $group[0]['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'];
  1776. * $file = $content[0]['attribs']['']['url'];
  1777. * echo $file;
  1778. * </pre>
  1779. *
  1780. * @since 1.0
  1781. * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
  1782. * @param string $namespace The URL of the XML namespace of the elements you're trying to access
  1783. * @param string $tag Tag name
  1784. * @return array
  1785. */
  1786. public function get_feed_tags($namespace, $tag)
  1787. {
  1788. $type = $this->get_type();
  1789. if ($type & SIMPLEPIE_TYPE_ATOM_10)
  1790. {
  1791. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag]))
  1792. {
  1793. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag];
  1794. }
  1795. }
  1796. if ($type & SIMPLEPIE_TYPE_ATOM_03)
  1797. {
  1798. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag]))
  1799. {
  1800. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag];
  1801. }
  1802. }
  1803. if ($type & SIMPLEPIE_TYPE_RSS_RDF)
  1804. {
  1805. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag]))
  1806. {
  1807. return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag];
  1808. }
  1809. }
  1810. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  1811. {
  1812. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag]))
  1813. {
  1814. return $this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag];
  1815. }
  1816. }
  1817. return null;
  1818. }
  1819. /**
  1820. * Get data for an channel-level element
  1821. *
  1822. * This method allows you to get access to ANY element/attribute in the
  1823. * channel/header section of the feed.
  1824. *
  1825. * See {@see SimplePie::get_feed_tags()} for a description of the return value
  1826. *
  1827. * @since 1.0
  1828. * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
  1829. * @param string $namespace The URL of the XML namespace of the elements you're trying to access
  1830. * @param string $tag Tag name
  1831. * @return array
  1832. */
  1833. public function get_channel_tags($namespace, $tag)
  1834. {
  1835. $type = $this->get_type();
  1836. if ($type & SIMPLEPIE_TYPE_ATOM_ALL)
  1837. {
  1838. if ($return = $this->get_feed_tags($namespace, $tag))
  1839. {
  1840. return $return;
  1841. }
  1842. }
  1843. if ($type & SIMPLEPIE_TYPE_RSS_10)
  1844. {
  1845. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel'))
  1846. {
  1847. if (isset($channel[0]['child'][$namespace][$tag]))
  1848. {
  1849. return $channel[0]['child'][$namespace][$tag];
  1850. }
  1851. }
  1852. }
  1853. if ($type & SIMPLEPIE_TYPE_RSS_090)
  1854. {
  1855. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel'))
  1856. {
  1857. if (isset($channel[0]['child'][$namespace][$tag]))
  1858. {
  1859. return $channel[0]['child'][$namespace][$tag];
  1860. }
  1861. }
  1862. }
  1863. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  1864. {
  1865. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'channel'))
  1866. {
  1867. if (isset($channel[0]['child'][$namespace][$tag]))
  1868. {
  1869. return $channel[0]['child'][$namespace][$tag];
  1870. }
  1871. }
  1872. }
  1873. return null;
  1874. }
  1875. /**
  1876. * Get data for an channel-level element
  1877. *
  1878. * This method allows you to get access to ANY element/attribute in the
  1879. * image/logo section of the feed.
  1880. *
  1881. * See {@see SimplePie::get_feed_tags()} for a description of the return value
  1882. *
  1883. * @since 1.0
  1884. * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
  1885. * @param string $namespace The URL of the XML namespace of the elements you're trying to access
  1886. * @param string $tag Tag name
  1887. * @return array
  1888. */
  1889. public function get_image_tags($namespace, $tag)
  1890. {
  1891. $type = $this->get_type();
  1892. if ($type & SIMPLEPIE_TYPE_RSS_10)
  1893. {
  1894. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image'))
  1895. {
  1896. if (isset($image[0]['child'][$namespace][$tag]))
  1897. {
  1898. return $image[0]['child'][$namespace][$tag];
  1899. }
  1900. }
  1901. }
  1902. if ($type & SIMPLEPIE_TYPE_RSS_090)
  1903. {
  1904. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image'))
  1905. {
  1906. if (isset($image[0]['child'][$namespace][$tag]))
  1907. {
  1908. return $image[0]['child'][$namespace][$tag];
  1909. }
  1910. }
  1911. }
  1912. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  1913. {
  1914. if ($image = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'image'))
  1915. {
  1916. if (isset($image[0]['child'][$namespace][$tag]))
  1917. {
  1918. return $image[0]['child'][$namespace][$tag];
  1919. }
  1920. }
  1921. }
  1922. return null;
  1923. }
  1924. /**
  1925. * Get the base URL value from the feed
  1926. *
  1927. * Uses `<xml:base>` if available, otherwise uses the first link in the
  1928. * feed, or failing that, the URL of the feed itself.
  1929. *
  1930. * @see get_link
  1931. * @see subscribe_url
  1932. *
  1933. * @param array $element
  1934. * @return string
  1935. */
  1936. public function get_base($element = array())
  1937. {
  1938. if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base']))
  1939. {
  1940. return $element['xml_base'];
  1941. }
  1942. elseif ($this->get_link() !== null)
  1943. {
  1944. return $this->get_link();
  1945. }
  1946. else
  1947. {
  1948. return $this->subscribe_url();
  1949. }
  1950. }
  1951. /**
  1952. * Sanitize feed data
  1953. *
  1954. * @access private
  1955. * @see SimplePie_Sanitize::sanitize()
  1956. * @param string $data Data to sanitize
  1957. * @param int $type One of the SIMPLEPIE_CONSTRUCT_* constants
  1958. * @param string $base Base URL to resolve URLs against
  1959. * @return string Sanitized data
  1960. */
  1961. public function sanitize($data, $type, $base = '')
  1962. {
  1963. try
  1964. {
  1965. return $this->sanitize->sanitize($data, $type, $base);
  1966. }
  1967. catch (SimplePie_Exception $e)
  1968. {
  1969. if (!$this->enable_exceptions)
  1970. {
  1971. $this->error = $e->getMessage();
  1972. $this->registry->call('Misc', 'error', array($this->error, E_USER_WARNING, $e->getFile(), $e->getLine()));
  1973. return '';
  1974. }
  1975. throw $e;
  1976. }
  1977. }
  1978. /**
  1979. * Get the title of the feed
  1980. *
  1981. * Uses `<atom:title>`, `<title>` or `<dc:title>`
  1982. *
  1983. * @since 1.0 (previously called `get_feed_title` since 0.8)
  1984. * @return string|null
  1985. */
  1986. public function get_title()
  1987. {
  1988. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  1989. {
  1990. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  1991. }
  1992. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  1993. {
  1994. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  1995. }
  1996. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  1997. {
  1998. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  1999. }
  2000. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  2001. {
  2002. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2003. }
  2004. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  2005. {
  2006. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2007. }
  2008. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  2009. {
  2010. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2011. }
  2012. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  2013. {
  2014. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2015. }
  2016. else
  2017. {
  2018. return null;
  2019. }
  2020. }
  2021. /**
  2022. * Get a category for the feed
  2023. *
  2024. * @since Unknown
  2025. * @param int $key The category that you want to return. Remember that arrays begin with 0, not 1
  2026. * @return SimplePie_Category|null
  2027. */
  2028. public function get_category($key = 0)
  2029. {
  2030. $categories = $this->get_categories();
  2031. if (isset($categories[$key]))
  2032. {
  2033. return $categories[$key];
  2034. }
  2035. else
  2036. {
  2037. return null;
  2038. }
  2039. }
  2040. /**
  2041. * Get all categories for the feed
  2042. *
  2043. * Uses `<atom:category>`, `<category>` or `<dc:subject>`
  2044. *
  2045. * @since Unknown
  2046. * @return array|null List of {@see SimplePie_Category} objects
  2047. */
  2048. public function get_categories()
  2049. {
  2050. $categories = array();
  2051. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  2052. {
  2053. $term = null;
  2054. $scheme = null;
  2055. $label = null;
  2056. if (isset($category['attribs']['']['term']))
  2057. {
  2058. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  2059. }
  2060. if (isset($category['attribs']['']['scheme']))
  2061. {
  2062. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2063. }
  2064. if (isset($category['attribs']['']['label']))
  2065. {
  2066. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  2067. }
  2068. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  2069. }
  2070. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
  2071. {
  2072. // This is really the label, but keep this as the term also for BC.
  2073. // Label will also work on retrieving because that falls back to term.
  2074. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2075. if (isset($category['attribs']['']['domain']))
  2076. {
  2077. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  2078. }
  2079. else
  2080. {
  2081. $scheme = null;
  2082. }
  2083. $categories[] = $this->registry->create('Category', array($term, $scheme, null));
  2084. }
  2085. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  2086. {
  2087. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  2088. }
  2089. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  2090. {
  2091. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  2092. }
  2093. if (!empty($categories))
  2094. {
  2095. return array_unique($categories);
  2096. }
  2097. else
  2098. {
  2099. return null;
  2100. }
  2101. }
  2102. /**
  2103. * Get an author for the feed
  2104. *
  2105. * @since 1.1
  2106. * @param int $key The author that you want to return. Remember that arrays begin with 0, not 1
  2107. * @return SimplePie_Author|null
  2108. */
  2109. public function get_author($key = 0)
  2110. {
  2111. $authors = $this->get_authors();
  2112. if (isset($authors[$key]))
  2113. {
  2114. return $authors[$key];
  2115. }
  2116. else
  2117. {
  2118. return null;
  2119. }
  2120. }
  2121. /**
  2122. * Get all authors for the feed
  2123. *
  2124. * Uses `<atom:author>`, `<author>`, `<dc:creator>` or `<itunes:author>`
  2125. *
  2126. * @since 1.1
  2127. * @return array|null List of {@see SimplePie_Author} objects
  2128. */
  2129. public function get_authors()
  2130. {
  2131. $authors = array();
  2132. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  2133. {
  2134. $name = null;
  2135. $uri = null;
  2136. $email = null;
  2137. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  2138. {
  2139. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2140. }
  2141. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  2142. {
  2143. $uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  2144. }
  2145. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  2146. {
  2147. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2148. }
  2149. if ($name !== null || $email !== null || $uri !== null)
  2150. {
  2151. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  2152. }
  2153. }
  2154. if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  2155. {
  2156. $name = null;
  2157. $url = null;
  2158. $email = null;
  2159. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  2160. {
  2161. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2162. }
  2163. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  2164. {
  2165. $url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  2166. }
  2167. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  2168. {
  2169. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2170. }
  2171. if ($name !== null || $email !== null || $url !== null)
  2172. {
  2173. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  2174. }
  2175. }
  2176. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  2177. {
  2178. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  2179. }
  2180. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  2181. {
  2182. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  2183. }
  2184. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  2185. {
  2186. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  2187. }
  2188. if (!empty($authors))
  2189. {
  2190. return array_unique($authors);
  2191. }
  2192. else
  2193. {
  2194. return null;
  2195. }
  2196. }
  2197. /**
  2198. * Get a contributor for the feed
  2199. *
  2200. * @since 1.1
  2201. * @param int $key The contrbutor that you want to return. Remember that arrays begin with 0, not 1
  2202. * @return SimplePie_Author|null
  2203. */
  2204. public function get_contributor($key = 0)
  2205. {
  2206. $contributors = $this->get_contributors();
  2207. if (isset($contributors[$key]))
  2208. {
  2209. return $contributors[$key];
  2210. }
  2211. else
  2212. {
  2213. return null;
  2214. }
  2215. }
  2216. /**
  2217. * Get all contributors for the feed
  2218. *
  2219. * Uses `<atom:contributor>`
  2220. *
  2221. * @since 1.1
  2222. * @return array|null List of {@see SimplePie_Author} objects
  2223. */
  2224. public function get_contributors()
  2225. {
  2226. $contributors = array();
  2227. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  2228. {
  2229. $name = null;
  2230. $uri = null;
  2231. $email = null;
  2232. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  2233. {
  2234. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2235. }
  2236. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  2237. {
  2238. $uri = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  2239. }
  2240. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  2241. {
  2242. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2243. }
  2244. if ($name !== null || $email !== null || $uri !== null)
  2245. {
  2246. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  2247. }
  2248. }
  2249. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  2250. {
  2251. $name = null;
  2252. $url = null;
  2253. $email = null;
  2254. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  2255. {
  2256. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2257. }
  2258. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  2259. {
  2260. $url = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  2261. }
  2262. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  2263. {
  2264. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2265. }
  2266. if ($name !== null || $email !== null || $url !== null)
  2267. {
  2268. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  2269. }
  2270. }
  2271. if (!empty($contributors))
  2272. {
  2273. return array_unique($contributors);
  2274. }
  2275. else
  2276. {
  2277. return null;
  2278. }
  2279. }
  2280. /**
  2281. * Get a single link for the feed
  2282. *
  2283. * @since 1.0 (previously called `get_feed_link` since Preview Release, `get_feed_permalink()` since 0.8)
  2284. * @param int $key The link that you want to return. Remember that arrays begin with 0, not 1
  2285. * @param string $rel The relationship of the link to return
  2286. * @return string|null Link URL
  2287. */
  2288. public function get_link($key = 0, $rel = 'alternate')
  2289. {
  2290. $links = $this->get_links($rel);
  2291. if (isset($links[$key]))
  2292. {
  2293. return $links[$key];
  2294. }
  2295. else
  2296. {
  2297. return null;
  2298. }
  2299. }
  2300. /**
  2301. * Get the permalink for the item
  2302. *
  2303. * Returns the first link available with a relationship of "alternate".
  2304. * Identical to {@see get_link()} with key 0
  2305. *
  2306. * @see get_link
  2307. * @since 1.0 (previously called `get_feed_link` since Preview Release, `get_feed_permalink()` since 0.8)
  2308. * @internal Added for parity between the parent-level and the item/entry-level.
  2309. * @return string|null Link URL
  2310. */
  2311. public function get_permalink()
  2312. {
  2313. return $this->get_link(0);
  2314. }
  2315. /**
  2316. * Get all links for the feed
  2317. *
  2318. * Uses `<atom:link>` or `<link>`
  2319. *
  2320. * @since Beta 2
  2321. * @param string $rel The relationship of links to return
  2322. * @return array|null Links found for the feed (strings)
  2323. */
  2324. public function get_links($rel = 'alternate')
  2325. {
  2326. if (!isset($this->data['links']))
  2327. {
  2328. $this->data['links'] = array();
  2329. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
  2330. {
  2331. foreach ($links as $link)
  2332. {
  2333. if (isset($link['attribs']['']['href']))
  2334. {
  2335. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  2336. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  2337. }
  2338. }
  2339. }
  2340. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
  2341. {
  2342. foreach ($links as $link)
  2343. {
  2344. if (isset($link['attribs']['']['href']))
  2345. {
  2346. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  2347. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  2348. }
  2349. }
  2350. }
  2351. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  2352. {
  2353. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  2354. }
  2355. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  2356. {
  2357. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  2358. }
  2359. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  2360. {
  2361. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  2362. }
  2363. $keys = array_keys($this->data['links']);
  2364. foreach ($keys as $key)
  2365. {
  2366. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
  2367. {
  2368. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  2369. {
  2370. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  2371. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  2372. }
  2373. else
  2374. {
  2375. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  2376. }
  2377. }
  2378. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  2379. {
  2380. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  2381. }
  2382. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  2383. }
  2384. }
  2385. if (isset($this->data['links'][$rel]))
  2386. {
  2387. return $this->data['links'][$rel];
  2388. }
  2389. else if (isset($this->data['headers']['link']) &&
  2390. preg_match('/<([^>]+)>; rel='.preg_quote($rel).'/',
  2391. $this->data['headers']['link'], $match))
  2392. {
  2393. return array($match[1]);
  2394. }
  2395. else
  2396. {
  2397. return null;
  2398. }
  2399. }
  2400. public function get_all_discovered_feeds()
  2401. {
  2402. return $this->all_discovered_feeds;
  2403. }
  2404. /**
  2405. * Get the content for the item
  2406. *
  2407. * Uses `<atom:subtitle>`, `<atom:tagline>`, `<description>`,
  2408. * `<dc:description>`, `<itunes:summary>` or `<itunes:subtitle>`
  2409. *
  2410. * @since 1.0 (previously called `get_feed_description()` since 0.8)
  2411. * @return string|null
  2412. */
  2413. public function get_description()
  2414. {
  2415. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
  2416. {
  2417. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  2418. }
  2419. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
  2420. {
  2421. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  2422. }
  2423. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  2424. {
  2425. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2426. }
  2427. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
  2428. {
  2429. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2430. }
  2431. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
  2432. {
  2433. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  2434. }
  2435. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  2436. {
  2437. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2438. }
  2439. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  2440. {
  2441. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2442. }
  2443. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  2444. {
  2445. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  2446. }
  2447. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  2448. {
  2449. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  2450. }
  2451. else
  2452. {
  2453. return null;
  2454. }
  2455. }
  2456. /**
  2457. * Get the copyright info for the feed
  2458. *
  2459. * Uses `<atom:rights>`, `<atom:copyright>` or `<dc:rights>`
  2460. *
  2461. * @since 1.0 (previously called `get_feed_copyright()` since 0.8)
  2462. * @return string|null
  2463. */
  2464. public function get_copyright()
  2465. {
  2466. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  2467. {
  2468. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  2469. }
  2470. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
  2471. {
  2472. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  2473. }
  2474. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
  2475. {
  2476. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2477. }
  2478. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  2479. {
  2480. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2481. }
  2482. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  2483. {
  2484. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2485. }
  2486. else
  2487. {
  2488. return null;
  2489. }
  2490. }
  2491. /**
  2492. * Get the language for the feed
  2493. *
  2494. * Uses `<language>`, `<dc:language>`, or @xml_lang
  2495. *
  2496. * @since 1.0 (previously called `get_feed_language()` since 0.8)
  2497. * @return string|null
  2498. */
  2499. public function get_language()
  2500. {
  2501. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language'))
  2502. {
  2503. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2504. }
  2505. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
  2506. {
  2507. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2508. }
  2509. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
  2510. {
  2511. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2512. }
  2513. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang']))
  2514. {
  2515. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2516. }
  2517. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang']))
  2518. {
  2519. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2520. }
  2521. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang']))
  2522. {
  2523. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2524. }
  2525. elseif (isset($this->data['headers']['content-language']))
  2526. {
  2527. return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT);
  2528. }
  2529. else
  2530. {
  2531. return null;
  2532. }
  2533. }
  2534. /**
  2535. * Get the latitude coordinates for the item
  2536. *
  2537. * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
  2538. *
  2539. * Uses `<geo:lat>` or `<georss:point>`
  2540. *
  2541. * @since 1.0
  2542. * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
  2543. * @link http://www.georss.org/ GeoRSS
  2544. * @return string|null
  2545. */
  2546. public function get_latitude()
  2547. {
  2548. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  2549. {
  2550. return (float) $return[0]['data'];
  2551. }
  2552. elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  2553. {
  2554. return (float) $match[1];
  2555. }
  2556. else
  2557. {
  2558. return null;
  2559. }
  2560. }
  2561. /**
  2562. * Get the longitude coordinates for the feed
  2563. *
  2564. * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
  2565. *
  2566. * Uses `<geo:long>`, `<geo:lon>` or `<georss:point>`
  2567. *
  2568. * @since 1.0
  2569. * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
  2570. * @link http://www.georss.org/ GeoRSS
  2571. * @return string|null
  2572. */
  2573. public function get_longitude()
  2574. {
  2575. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  2576. {
  2577. return (float) $return[0]['data'];
  2578. }
  2579. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  2580. {
  2581. return (float) $return[0]['data'];
  2582. }
  2583. elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  2584. {
  2585. return (float) $match[2];
  2586. }
  2587. else
  2588. {
  2589. return null;
  2590. }
  2591. }
  2592. /**
  2593. * Get the feed logo's title
  2594. *
  2595. * RSS 0.9.0, 1.0 and 2.0 feeds are allowed to have a "feed logo" title.
  2596. *
  2597. * Uses `<image><title>` or `<image><dc:title>`
  2598. *
  2599. * @return string|null
  2600. */
  2601. public function get_image_title()
  2602. {
  2603. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  2604. {
  2605. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2606. }
  2607. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  2608. {
  2609. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2610. }
  2611. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  2612. {
  2613. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2614. }
  2615. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  2616. {
  2617. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2618. }
  2619. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  2620. {
  2621. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2622. }
  2623. else
  2624. {
  2625. return null;
  2626. }
  2627. }
  2628. /**
  2629. * Get the feed logo's URL
  2630. *
  2631. * RSS 0.9.0, 2.0, Atom 1.0, and feeds with iTunes RSS tags are allowed to
  2632. * have a "feed logo" URL. This points directly to the image itself.
  2633. *
  2634. * Uses `<itunes:image>`, `<atom:logo>`, `<atom:icon>`,
  2635. * `<image><title>` or `<image><dc:title>`
  2636. *
  2637. * @return string|null
  2638. */
  2639. public function get_image_url()
  2640. {
  2641. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
  2642. {
  2643. return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
  2644. }
  2645. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
  2646. {
  2647. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2648. }
  2649. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
  2650. {
  2651. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2652. }
  2653. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url'))
  2654. {
  2655. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2656. }
  2657. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url'))
  2658. {
  2659. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2660. }
  2661. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
  2662. {
  2663. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2664. }
  2665. else
  2666. {
  2667. return null;
  2668. }
  2669. }
  2670. /**
  2671. * Get the feed logo's link
  2672. *
  2673. * RSS 0.9.0, 1.0 and 2.0 feeds are allowed to have a "feed logo" link. This
  2674. * points to a human-readable page that the image should link to.
  2675. *
  2676. * Uses `<itunes:image>`, `<atom:logo>`, `<atom:icon>`,
  2677. * `<image><title>` or `<image><dc:title>`
  2678. *
  2679. * @return string|null
  2680. */
  2681. public function get_image_link()
  2682. {
  2683. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  2684. {
  2685. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2686. }
  2687. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  2688. {
  2689. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2690. }
  2691. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  2692. {
  2693. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2694. }
  2695. else
  2696. {
  2697. return null;
  2698. }
  2699. }
  2700. /**
  2701. * Get the feed logo's link
  2702. *
  2703. * RSS 2.0 feeds are allowed to have a "feed logo" width.
  2704. *
  2705. * Uses `<image><width>` or defaults to 88.0 if no width is specified and
  2706. * the feed is an RSS 2.0 feed.
  2707. *
  2708. * @return int|float|null
  2709. */
  2710. public function get_image_width()
  2711. {
  2712. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'width'))
  2713. {
  2714. return round($return[0]['data']);
  2715. }
  2716. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
  2717. {
  2718. return 88.0;
  2719. }
  2720. else
  2721. {
  2722. return null;
  2723. }
  2724. }
  2725. /**
  2726. * Get the feed logo's height
  2727. *
  2728. * RSS 2.0 feeds are allowed to have a "feed logo" height.
  2729. *
  2730. * Uses `<image><height>` or defaults to 31.0 if no height is specified and
  2731. * the feed is an RSS 2.0 feed.
  2732. *
  2733. * @return int|float|null
  2734. */
  2735. public function get_image_height()
  2736. {
  2737. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'height'))
  2738. {
  2739. return round($return[0]['data']);
  2740. }
  2741. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
  2742. {
  2743. return 31.0;
  2744. }
  2745. else
  2746. {
  2747. return null;
  2748. }
  2749. }
  2750. /**
  2751. * Get the number of items in the feed
  2752. *
  2753. * This is well-suited for {@link http://php.net/for for()} loops with
  2754. * {@see get_item()}
  2755. *
  2756. * @param int $max Maximum value to return. 0 for no limit
  2757. * @return int Number of items in the feed
  2758. */
  2759. public function get_item_quantity($max = 0)
  2760. {
  2761. $max = (int) $max;
  2762. $qty = count($this->get_items());
  2763. if ($max === 0)
  2764. {
  2765. return $qty;
  2766. }
  2767. else
  2768. {
  2769. return ($qty > $max) ? $max : $qty;
  2770. }
  2771. }
  2772. /**
  2773. * Get a single item from the feed
  2774. *
  2775. * This is better suited for {@link http://php.net/for for()} loops, whereas
  2776. * {@see get_items()} is better suited for
  2777. * {@link http://php.net/foreach foreach()} loops.
  2778. *
  2779. * @see get_item_quantity()
  2780. * @since Beta 2
  2781. * @param int $key The item that you want to return. Remember that arrays begin with 0, not 1
  2782. * @return SimplePie_Item|null
  2783. */
  2784. public function get_item($key = 0)
  2785. {
  2786. $items = $this->get_items();
  2787. if (isset($items[$key]))
  2788. {
  2789. return $items[$key];
  2790. }
  2791. else
  2792. {
  2793. return null;
  2794. }
  2795. }
  2796. /**
  2797. * Get all items from the feed
  2798. *
  2799. * This is better suited for {@link http://php.net/for for()} loops, whereas
  2800. * {@see get_items()} is better suited for
  2801. * {@link http://php.net/foreach foreach()} loops.
  2802. *
  2803. * @see get_item_quantity
  2804. * @since Beta 2
  2805. * @param int $start Index to start at
  2806. * @param int $end Number of items to return. 0 for all items after `$start`
  2807. * @return SimplePie_Item[]|null List of {@see SimplePie_Item} objects
  2808. */
  2809. public function get_items($start = 0, $end = 0)
  2810. {
  2811. if (!isset($this->data['items']))
  2812. {
  2813. if (!empty($this->multifeed_objects))
  2814. {
  2815. $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit);
  2816. if (empty($this->data['items']))
  2817. {
  2818. return array();
  2819. }
  2820. return $this->data['items'];
  2821. }
  2822. $this->data['items'] = array();
  2823. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry'))
  2824. {
  2825. $keys = array_keys($items);
  2826. foreach ($keys as $key)
  2827. {
  2828. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  2829. }
  2830. }
  2831. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry'))
  2832. {
  2833. $keys = array_keys($items);
  2834. foreach ($keys as $key)
  2835. {
  2836. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  2837. }
  2838. }
  2839. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item'))
  2840. {
  2841. $keys = array_keys($items);
  2842. foreach ($keys as $key)
  2843. {
  2844. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  2845. }
  2846. }
  2847. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item'))
  2848. {
  2849. $keys = array_keys($items);
  2850. foreach ($keys as $key)
  2851. {
  2852. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  2853. }
  2854. }
  2855. if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'item'))
  2856. {
  2857. $keys = array_keys($items);
  2858. foreach ($keys as $key)
  2859. {
  2860. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  2861. }
  2862. }
  2863. }
  2864. if (empty($this->data['items']))
  2865. {
  2866. return array();
  2867. }
  2868. if ($this->order_by_date)
  2869. {
  2870. if (!isset($this->data['ordered_items']))
  2871. {
  2872. $this->data['ordered_items'] = $this->data['items'];
  2873. usort($this->data['ordered_items'], array(get_class($this), 'sort_items'));
  2874. }
  2875. $items = $this->data['ordered_items'];
  2876. }
  2877. else
  2878. {
  2879. $items = $this->data['items'];
  2880. }
  2881. // Slice the data as desired
  2882. if ($end === 0)
  2883. {
  2884. return array_slice($items, $start);
  2885. }
  2886. else
  2887. {
  2888. return array_slice($items, $start, $end);
  2889. }
  2890. }
  2891. /**
  2892. * Set the favicon handler
  2893. *
  2894. * @deprecated Use your own favicon handling instead
  2895. */
  2896. public function set_favicon_handler($page = false, $qs = 'i')
  2897. {
  2898. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
  2899. trigger_error('Favicon handling has been removed, please use your own handling', $level);
  2900. return false;
  2901. }
  2902. /**
  2903. * Get the favicon for the current feed
  2904. *
  2905. * @deprecated Use your own favicon handling instead
  2906. */
  2907. public function get_favicon()
  2908. {
  2909. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
  2910. trigger_error('Favicon handling has been removed, please use your own handling', $level);
  2911. if (($url = $this->get_link()) !== null)
  2912. {
  2913. return 'http://g.etfv.co/' . urlencode($url);
  2914. }
  2915. return false;
  2916. }
  2917. /**
  2918. * Magic method handler
  2919. *
  2920. * @param string $method Method name
  2921. * @param array $args Arguments to the method
  2922. * @return mixed
  2923. */
  2924. public function __call($method, $args)
  2925. {
  2926. if (strpos($method, 'subscribe_') === 0)
  2927. {
  2928. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
  2929. trigger_error('subscribe_*() has been deprecated, implement the callback yourself', $level);
  2930. return '';
  2931. }
  2932. if ($method === 'enable_xml_dump')
  2933. {
  2934. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
  2935. trigger_error('enable_xml_dump() has been deprecated, use get_raw_data() instead', $level);
  2936. return false;
  2937. }
  2938. $class = get_class($this);
  2939. $trace = debug_backtrace();
  2940. $file = $trace[0]['file'];
  2941. $line = $trace[0]['line'];
  2942. trigger_error("Call to undefined method $class::$method() in $file on line $line", E_USER_ERROR);
  2943. }
  2944. /**
  2945. * Sorting callback for items
  2946. *
  2947. * @access private
  2948. * @param SimplePie $a
  2949. * @param SimplePie $b
  2950. * @return boolean
  2951. */
  2952. public static function sort_items($a, $b)
  2953. {
  2954. $a_date = $a->get_date('U');
  2955. $b_date = $b->get_date('U');
  2956. if ($a_date && $b_date) {
  2957. return $a_date > $b_date ? -1 : 1;
  2958. }
  2959. // Sort items without dates to the top.
  2960. if ($a_date) {
  2961. return 1;
  2962. }
  2963. if ($b_date) {
  2964. return -1;
  2965. }
  2966. return 0;
  2967. }
  2968. /**
  2969. * Merge items from several feeds into one
  2970. *
  2971. * If you're merging multiple feeds together, they need to all have dates
  2972. * for the items or else SimplePie will refuse to sort them.
  2973. *
  2974. * @link http://simplepie.org/wiki/tutorial/sort_multiple_feeds_by_time_and_date#if_feeds_require_separate_per-feed_settings
  2975. * @param array $urls List of SimplePie feed objects to merge
  2976. * @param int $start Starting item
  2977. * @param int $end Number of items to return
  2978. * @param int $limit Maximum number of items per feed
  2979. * @return array
  2980. */
  2981. public static function merge_items($urls, $start = 0, $end = 0, $limit = 0)
  2982. {
  2983. if (is_array($urls) && sizeof($urls) > 0)
  2984. {
  2985. $items = array();
  2986. foreach ($urls as $arg)
  2987. {
  2988. if ($arg instanceof SimplePie)
  2989. {
  2990. $items = array_merge($items, $arg->get_items(0, $limit));
  2991. }
  2992. else
  2993. {
  2994. trigger_error('Arguments must be SimplePie objects', E_USER_WARNING);
  2995. }
  2996. }
  2997. usort($items, array(get_class($urls[0]), 'sort_items'));
  2998. if ($end === 0)
  2999. {
  3000. return array_slice($items, $start);
  3001. }
  3002. else
  3003. {
  3004. return array_slice($items, $start, $end);
  3005. }
  3006. }
  3007. else
  3008. {
  3009. trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING);
  3010. return array();
  3011. }
  3012. }
  3013. /**
  3014. * Store PubSubHubbub links as headers
  3015. *
  3016. * There is no way to find PuSH links in the body of a microformats feed,
  3017. * so they are added to the headers when found, to be used later by get_links.
  3018. * @param SimplePie_File $file
  3019. * @param string $hub
  3020. * @param string $self
  3021. */
  3022. private function store_links(&$file, $hub, $self) {
  3023. if (isset($file->headers['link']['hub']) ||
  3024. (isset($file->headers['link']) &&
  3025. preg_match('/rel=hub/', $file->headers['link'])))
  3026. {
  3027. return;
  3028. }
  3029. if ($hub)
  3030. {
  3031. if (isset($file->headers['link']))
  3032. {
  3033. if ($file->headers['link'] !== '')
  3034. {
  3035. $file->headers['link'] = ', ';
  3036. }
  3037. }
  3038. else
  3039. {
  3040. $file->headers['link'] = '';
  3041. }
  3042. $file->headers['link'] .= '<'.$hub.'>; rel=hub';
  3043. if ($self)
  3044. {
  3045. $file->headers['link'] .= ', <'.$self.'>; rel=self';
  3046. }
  3047. }
  3048. }
  3049. }
  3050. /**
  3051. * Manages all author-related data
  3052. *
  3053. * Used by {@see SimplePie_Item::get_author()} and {@see SimplePie::get_authors()}
  3054. *
  3055. * This class can be overloaded with {@see SimplePie::set_author_class()}
  3056. *
  3057. * @package SimplePie
  3058. * @subpackage API
  3059. */
  3060. class SimplePie_Author
  3061. {
  3062. /**
  3063. * Author's name
  3064. *
  3065. * @var string
  3066. * @see get_name()
  3067. */
  3068. var $name;
  3069. /**
  3070. * Author's link
  3071. *
  3072. * @var string
  3073. * @see get_link()
  3074. */
  3075. var $link;
  3076. /**
  3077. * Author's email address
  3078. *
  3079. * @var string
  3080. * @see get_email()
  3081. */
  3082. var $email;
  3083. /**
  3084. * Constructor, used to input the data
  3085. *
  3086. * @param string $name
  3087. * @param string $link
  3088. * @param string $email
  3089. */
  3090. public function __construct($name = null, $link = null, $email = null)
  3091. {
  3092. $this->name = $name;
  3093. $this->link = $link;
  3094. $this->email = $email;
  3095. }
  3096. /**
  3097. * String-ified version
  3098. *
  3099. * @return string
  3100. */
  3101. public function __toString()
  3102. {
  3103. // There is no $this->data here
  3104. return md5(serialize($this));
  3105. }
  3106. /**
  3107. * Author's name
  3108. *
  3109. * @return string|null
  3110. */
  3111. public function get_name()
  3112. {
  3113. if ($this->name !== null)
  3114. {
  3115. return $this->name;
  3116. }
  3117. else
  3118. {
  3119. return null;
  3120. }
  3121. }
  3122. /**
  3123. * Author's link
  3124. *
  3125. * @return string|null
  3126. */
  3127. public function get_link()
  3128. {
  3129. if ($this->link !== null)
  3130. {
  3131. return $this->link;
  3132. }
  3133. else
  3134. {
  3135. return null;
  3136. }
  3137. }
  3138. /**
  3139. * Author's email address
  3140. *
  3141. * @return string|null
  3142. */
  3143. public function get_email()
  3144. {
  3145. if ($this->email !== null)
  3146. {
  3147. return $this->email;
  3148. }
  3149. else
  3150. {
  3151. return null;
  3152. }
  3153. }
  3154. }
  3155. /**
  3156. * Used to create cache objects
  3157. *
  3158. * This class can be overloaded with {@see SimplePie::set_cache_class()},
  3159. * although the preferred way is to create your own handler
  3160. * via {@see register()}
  3161. *
  3162. * @package SimplePie
  3163. * @subpackage Caching
  3164. */
  3165. class SimplePie_Cache
  3166. {
  3167. /**
  3168. * Cache handler classes
  3169. *
  3170. * These receive 3 parameters to their constructor, as documented in
  3171. * {@see register()}
  3172. * @var array
  3173. */
  3174. protected static $handlers = array(
  3175. 'mysql' => 'SimplePie_Cache_MySQL',
  3176. 'memcache' => 'SimplePie_Cache_Memcache',
  3177. 'memcached' => 'SimplePie_Cache_Memcached',
  3178. 'redis' => 'SimplePie_Cache_Redis'
  3179. );
  3180. /**
  3181. * Don't call the constructor. Please.
  3182. */
  3183. private function __construct() { }
  3184. /**
  3185. * Create a new SimplePie_Cache object
  3186. *
  3187. * @param string $location URL location (scheme is used to determine handler)
  3188. * @param string $filename Unique identifier for cache object
  3189. * @param string $extension 'spi' or 'spc'
  3190. * @return SimplePie_Cache_Base Type of object depends on scheme of `$location`
  3191. */
  3192. public static function get_handler($location, $filename, $extension)
  3193. {
  3194. $type = explode(':', $location, 2);
  3195. $type = $type[0];
  3196. if (!empty(self::$handlers[$type]))
  3197. {
  3198. $class = self::$handlers[$type];
  3199. return new $class($location, $filename, $extension);
  3200. }
  3201. return new SimplePie_Cache_File($location, $filename, $extension);
  3202. }
  3203. /**
  3204. * Create a new SimplePie_Cache object
  3205. *
  3206. * @deprecated Use {@see get_handler} instead
  3207. */
  3208. public function create($location, $filename, $extension)
  3209. {
  3210. trigger_error('Cache::create() has been replaced with Cache::get_handler(). Switch to the registry system to use this.', E_USER_DEPRECATED);
  3211. return self::get_handler($location, $filename, $extension);
  3212. }
  3213. /**
  3214. * Register a handler
  3215. *
  3216. * @param string $type DSN type to register for
  3217. * @param string $class Name of handler class. Must implement SimplePie_Cache_Base
  3218. */
  3219. public static function register($type, $class)
  3220. {
  3221. self::$handlers[$type] = $class;
  3222. }
  3223. /**
  3224. * Parse a URL into an array
  3225. *
  3226. * @param string $url
  3227. * @return array
  3228. */
  3229. public static function parse_URL($url)
  3230. {
  3231. $params = parse_url($url);
  3232. $params['extras'] = array();
  3233. if (isset($params['query']))
  3234. {
  3235. parse_str($params['query'], $params['extras']);
  3236. }
  3237. return $params;
  3238. }
  3239. }
  3240. /**
  3241. * Base for cache objects
  3242. *
  3243. * Classes to be used with {@see SimplePie_Cache::register()} are expected
  3244. * to implement this interface.
  3245. *
  3246. * @package SimplePie
  3247. * @subpackage Caching
  3248. */
  3249. interface SimplePie_Cache_Base
  3250. {
  3251. /**
  3252. * Feed cache type
  3253. *
  3254. * @var string
  3255. */
  3256. const TYPE_FEED = 'spc';
  3257. /**
  3258. * Image cache type
  3259. *
  3260. * @var string
  3261. */
  3262. const TYPE_IMAGE = 'spi';
  3263. /**
  3264. * Create a new cache object
  3265. *
  3266. * @param string $location Location string (from SimplePie::$cache_location)
  3267. * @param string $name Unique ID for the cache
  3268. * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
  3269. */
  3270. public function __construct($location, $name, $type);
  3271. /**
  3272. * Save data to the cache
  3273. *
  3274. * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
  3275. * @return bool Successfulness
  3276. */
  3277. public function save($data);
  3278. /**
  3279. * Retrieve the data saved to the cache
  3280. *
  3281. * @return array Data for SimplePie::$data
  3282. */
  3283. public function load();
  3284. /**
  3285. * Retrieve the last modified time for the cache
  3286. *
  3287. * @return int Timestamp
  3288. */
  3289. public function mtime();
  3290. /**
  3291. * Set the last modified time to the current time
  3292. *
  3293. * @return bool Success status
  3294. */
  3295. public function touch();
  3296. /**
  3297. * Remove the cache
  3298. *
  3299. * @return bool Success status
  3300. */
  3301. public function unlink();
  3302. }
  3303. /**
  3304. * Base class for database-based caches
  3305. *
  3306. * @package SimplePie
  3307. * @subpackage Caching
  3308. */
  3309. abstract class SimplePie_Cache_DB implements SimplePie_Cache_Base
  3310. {
  3311. /**
  3312. * Helper for database conversion
  3313. *
  3314. * Converts a given {@see SimplePie} object into data to be stored
  3315. *
  3316. * @param SimplePie $data
  3317. * @return array First item is the serialized data for storage, second item is the unique ID for this item
  3318. */
  3319. protected static function prepare_simplepie_object_for_cache($data)
  3320. {
  3321. $items = $data->get_items();
  3322. $items_by_id = array();
  3323. if (!empty($items))
  3324. {
  3325. foreach ($items as $item)
  3326. {
  3327. $items_by_id[$item->get_id()] = $item;
  3328. }
  3329. if (count($items_by_id) !== count($items))
  3330. {
  3331. $items_by_id = array();
  3332. foreach ($items as $item)
  3333. {
  3334. $items_by_id[$item->get_id(true)] = $item;
  3335. }
  3336. }
  3337. if (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
  3338. {
  3339. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
  3340. }
  3341. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
  3342. {
  3343. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
  3344. }
  3345. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
  3346. {
  3347. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
  3348. }
  3349. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0]))
  3350. {
  3351. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0];
  3352. }
  3353. else
  3354. {
  3355. $channel = null;
  3356. }
  3357. if ($channel !== null)
  3358. {
  3359. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']))
  3360. {
  3361. unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']);
  3362. }
  3363. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']))
  3364. {
  3365. unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']);
  3366. }
  3367. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']))
  3368. {
  3369. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']);
  3370. }
  3371. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']))
  3372. {
  3373. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']);
  3374. }
  3375. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']))
  3376. {
  3377. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']);
  3378. }
  3379. }
  3380. if (isset($data->data['items']))
  3381. {
  3382. unset($data->data['items']);
  3383. }
  3384. if (isset($data->data['ordered_items']))
  3385. {
  3386. unset($data->data['ordered_items']);
  3387. }
  3388. }
  3389. return array(serialize($data->data), $items_by_id);
  3390. }
  3391. }
  3392. /**
  3393. * Caches data to the filesystem
  3394. *
  3395. * @package SimplePie
  3396. * @subpackage Caching
  3397. */
  3398. class SimplePie_Cache_File implements SimplePie_Cache_Base
  3399. {
  3400. /**
  3401. * Location string
  3402. *
  3403. * @see SimplePie::$cache_location
  3404. * @var string
  3405. */
  3406. protected $location;
  3407. /**
  3408. * Filename
  3409. *
  3410. * @var string
  3411. */
  3412. protected $filename;
  3413. /**
  3414. * File extension
  3415. *
  3416. * @var string
  3417. */
  3418. protected $extension;
  3419. /**
  3420. * File path
  3421. *
  3422. * @var string
  3423. */
  3424. protected $name;
  3425. /**
  3426. * Create a new cache object
  3427. *
  3428. * @param string $location Location string (from SimplePie::$cache_location)
  3429. * @param string $name Unique ID for the cache
  3430. * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
  3431. */
  3432. public function __construct($location, $name, $type)
  3433. {
  3434. $this->location = $location;
  3435. $this->filename = $name;
  3436. $this->extension = $type;
  3437. $this->name = "$this->location/$this->filename.$this->extension";
  3438. }
  3439. /**
  3440. * Save data to the cache
  3441. *
  3442. * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
  3443. * @return bool Successfulness
  3444. */
  3445. public function save($data)
  3446. {
  3447. if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
  3448. {
  3449. if ($data instanceof SimplePie)
  3450. {
  3451. $data = $data->data;
  3452. }
  3453. $data = serialize($data);
  3454. return (bool) file_put_contents($this->name, $data);
  3455. }
  3456. return false;
  3457. }
  3458. /**
  3459. * Retrieve the data saved to the cache
  3460. *
  3461. * @return array Data for SimplePie::$data
  3462. */
  3463. public function load()
  3464. {
  3465. if (file_exists($this->name) && is_readable($this->name))
  3466. {
  3467. return unserialize(file_get_contents($this->name));
  3468. }
  3469. return false;
  3470. }
  3471. /**
  3472. * Retrieve the last modified time for the cache
  3473. *
  3474. * @return int Timestamp
  3475. */
  3476. public function mtime()
  3477. {
  3478. return @filemtime($this->name);
  3479. }
  3480. /**
  3481. * Set the last modified time to the current time
  3482. *
  3483. * @return bool Success status
  3484. */
  3485. public function touch()
  3486. {
  3487. return @touch($this->name);
  3488. }
  3489. /**
  3490. * Remove the cache
  3491. *
  3492. * @return bool Success status
  3493. */
  3494. public function unlink()
  3495. {
  3496. if (file_exists($this->name))
  3497. {
  3498. return unlink($this->name);
  3499. }
  3500. return false;
  3501. }
  3502. }
  3503. /**
  3504. * Caches data to memcache
  3505. *
  3506. * Registered for URLs with the "memcache" protocol
  3507. *
  3508. * For example, `memcache://localhost:11211/?timeout=3600&prefix=sp_` will
  3509. * connect to memcache on `localhost` on port 11211. All tables will be
  3510. * prefixed with `sp_` and data will expire after 3600 seconds
  3511. *
  3512. * @package SimplePie
  3513. * @subpackage Caching
  3514. * @uses Memcache
  3515. */
  3516. class SimplePie_Cache_Memcache implements SimplePie_Cache_Base
  3517. {
  3518. /**
  3519. * Memcache instance
  3520. *
  3521. * @var Memcache
  3522. */
  3523. protected $cache;
  3524. /**
  3525. * Options
  3526. *
  3527. * @var array
  3528. */
  3529. protected $options;
  3530. /**
  3531. * Cache name
  3532. *
  3533. * @var string
  3534. */
  3535. protected $name;
  3536. /**
  3537. * Create a new cache object
  3538. *
  3539. * @param string $location Location string (from SimplePie::$cache_location)
  3540. * @param string $name Unique ID for the cache
  3541. * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
  3542. */
  3543. public function __construct($location, $name, $type)
  3544. {
  3545. $this->options = array(
  3546. 'host' => '127.0.0.1',
  3547. 'port' => 11211,
  3548. 'extras' => array(
  3549. 'timeout' => 3600, // one hour
  3550. 'prefix' => 'simplepie_',
  3551. ),
  3552. );
  3553. $this->options = SimplePie_Misc::array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));
  3554. $this->name = $this->options['extras']['prefix'] . md5("$name:$type");
  3555. $this->cache = new Memcache();
  3556. $this->cache->addServer($this->options['host'], (int) $this->options['port']);
  3557. }
  3558. /**
  3559. * Save data to the cache
  3560. *
  3561. * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
  3562. * @return bool Successfulness
  3563. */
  3564. public function save($data)
  3565. {
  3566. if ($data instanceof SimplePie)
  3567. {
  3568. $data = $data->data;
  3569. }
  3570. return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
  3571. }
  3572. /**
  3573. * Retrieve the data saved to the cache
  3574. *
  3575. * @return array Data for SimplePie::$data
  3576. */
  3577. public function load()
  3578. {
  3579. $data = $this->cache->get($this->name);
  3580. if ($data !== false)
  3581. {
  3582. return unserialize($data);
  3583. }
  3584. return false;
  3585. }
  3586. /**
  3587. * Retrieve the last modified time for the cache
  3588. *
  3589. * @return int Timestamp
  3590. */
  3591. public function mtime()
  3592. {
  3593. $data = $this->cache->get($this->name);
  3594. if ($data !== false)
  3595. {
  3596. // essentially ignore the mtime because Memcache expires on its own
  3597. return time();
  3598. }
  3599. return false;
  3600. }
  3601. /**
  3602. * Set the last modified time to the current time
  3603. *
  3604. * @return bool Success status
  3605. */
  3606. public function touch()
  3607. {
  3608. $data = $this->cache->get($this->name);
  3609. if ($data !== false)
  3610. {
  3611. return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
  3612. }
  3613. return false;
  3614. }
  3615. /**
  3616. * Remove the cache
  3617. *
  3618. * @return bool Success status
  3619. */
  3620. public function unlink()
  3621. {
  3622. return $this->cache->delete($this->name, 0);
  3623. }
  3624. }
  3625. /**
  3626. * Caches data to memcached
  3627. *
  3628. * Registered for URLs with the "memcached" protocol
  3629. *
  3630. * For example, `memcached://localhost:11211/?timeout=3600&prefix=sp_` will
  3631. * connect to memcached on `localhost` on port 11211. All tables will be
  3632. * prefixed with `sp_` and data will expire after 3600 seconds
  3633. *
  3634. * @package SimplePie
  3635. * @subpackage Caching
  3636. * @author Paul L. McNeely
  3637. * @uses Memcached
  3638. */
  3639. class SimplePie_Cache_Memcached implements SimplePie_Cache_Base
  3640. {
  3641. /**
  3642. * Memcached instance
  3643. * @var Memcached
  3644. */
  3645. protected $cache;
  3646. /**
  3647. * Options
  3648. * @var array
  3649. */
  3650. protected $options;
  3651. /**
  3652. * Cache name
  3653. * @var string
  3654. */
  3655. protected $name;
  3656. /**
  3657. * Create a new cache object
  3658. * @param string $location Location string (from SimplePie::$cache_location)
  3659. * @param string $name Unique ID for the cache
  3660. * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
  3661. */
  3662. public function __construct($location, $name, $type) {
  3663. $this->options = array(
  3664. 'host' => '127.0.0.1',
  3665. 'port' => 11211,
  3666. 'extras' => array(
  3667. 'timeout' => 3600, // one hour
  3668. 'prefix' => 'simplepie_',
  3669. ),
  3670. );
  3671. $this->options = SimplePie_Misc::array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));
  3672. $this->name = $this->options['extras']['prefix'] . md5("$name:$type");
  3673. $this->cache = new Memcached();
  3674. $this->cache->addServer($this->options['host'], (int)$this->options['port']);
  3675. }
  3676. /**
  3677. * Save data to the cache
  3678. * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
  3679. * @return bool Successfulness
  3680. */
  3681. public function save($data) {
  3682. if ($data instanceof SimplePie) {
  3683. $data = $data->data;
  3684. }
  3685. return $this->setData(serialize($data));
  3686. }
  3687. /**
  3688. * Retrieve the data saved to the cache
  3689. * @return array Data for SimplePie::$data
  3690. */
  3691. public function load() {
  3692. $data = $this->cache->get($this->name);
  3693. if ($data !== false) {
  3694. return unserialize($data);
  3695. }
  3696. return false;
  3697. }
  3698. /**
  3699. * Retrieve the last modified time for the cache
  3700. * @return int Timestamp
  3701. */
  3702. public function mtime() {
  3703. $data = $this->cache->get($this->name . '_mtime');
  3704. return (int) $data;
  3705. }
  3706. /**
  3707. * Set the last modified time to the current time
  3708. * @return bool Success status
  3709. */
  3710. public function touch() {
  3711. $data = $this->cache->get($this->name);
  3712. return $this->setData($data);
  3713. }
  3714. /**
  3715. * Remove the cache
  3716. * @return bool Success status
  3717. */
  3718. public function unlink() {
  3719. return $this->cache->delete($this->name, 0);
  3720. }
  3721. /**
  3722. * Set the last modified time and data to Memcached
  3723. * @return bool Success status
  3724. */
  3725. private function setData($data) {
  3726. if ($data !== false) {
  3727. $this->cache->set($this->name . '_mtime', time(), (int)$this->options['extras']['timeout']);
  3728. return $this->cache->set($this->name, $data, (int)$this->options['extras']['timeout']);
  3729. }
  3730. return false;
  3731. }
  3732. }
  3733. /**
  3734. * Caches data to a MySQL database
  3735. *
  3736. * Registered for URLs with the "mysql" protocol
  3737. *
  3738. * For example, `mysql://root:password@localhost:3306/mydb?prefix=sp_` will
  3739. * connect to the `mydb` database on `localhost` on port 3306, with the user
  3740. * `root` and the password `password`. All tables will be prefixed with `sp_`
  3741. *
  3742. * @package SimplePie
  3743. * @subpackage Caching
  3744. */
  3745. class SimplePie_Cache_MySQL extends SimplePie_Cache_DB
  3746. {
  3747. /**
  3748. * PDO instance
  3749. *
  3750. * @var PDO
  3751. */
  3752. protected $mysql;
  3753. /**
  3754. * Options
  3755. *
  3756. * @var array
  3757. */
  3758. protected $options;
  3759. /**
  3760. * Cache ID
  3761. *
  3762. * @var string
  3763. */
  3764. protected $id;
  3765. /**
  3766. * Create a new cache object
  3767. *
  3768. * @param string $location Location string (from SimplePie::$cache_location)
  3769. * @param string $name Unique ID for the cache
  3770. * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
  3771. */
  3772. public function __construct($location, $name, $type)
  3773. {
  3774. $this->options = array(
  3775. 'user' => null,
  3776. 'pass' => null,
  3777. 'host' => '127.0.0.1',
  3778. 'port' => '3306',
  3779. 'path' => '',
  3780. 'extras' => array(
  3781. 'prefix' => '',
  3782. 'cache_purge_time' => 2592000
  3783. ),
  3784. );
  3785. $this->options = SimplePie_Misc::array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));
  3786. // Path is prefixed with a "/"
  3787. $this->options['dbname'] = substr($this->options['path'], 1);
  3788. try
  3789. {
  3790. $this->mysql = new PDO("mysql:dbname={$this->options['dbname']};host={$this->options['host']};port={$this->options['port']}", $this->options['user'], $this->options['pass'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
  3791. }
  3792. catch (PDOException $e)
  3793. {
  3794. $this->mysql = null;
  3795. return;
  3796. }
  3797. $this->id = $name . $type;
  3798. if (!$query = $this->mysql->query('SHOW TABLES'))
  3799. {
  3800. $this->mysql = null;
  3801. return;
  3802. }
  3803. $db = array();
  3804. while ($row = $query->fetchColumn())
  3805. {
  3806. $db[] = $row;
  3807. }
  3808. if (!in_array($this->options['extras']['prefix'] . 'cache_data', $db))
  3809. {
  3810. $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'cache_data` (`id` TEXT CHARACTER SET utf8 NOT NULL, `items` SMALLINT NOT NULL DEFAULT 0, `data` BLOB NOT NULL, `mtime` INT UNSIGNED NOT NULL, UNIQUE (`id`(125)))');
  3811. if ($query === false)
  3812. {
  3813. trigger_error("Can't create " . $this->options['extras']['prefix'] . "cache_data table, check permissions", E_USER_WARNING);
  3814. $this->mysql = null;
  3815. return;
  3816. }
  3817. }
  3818. if (!in_array($this->options['extras']['prefix'] . 'items', $db))
  3819. {
  3820. $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'items` (`feed_id` TEXT CHARACTER SET utf8 NOT NULL, `id` TEXT CHARACTER SET utf8 NOT NULL, `data` MEDIUMBLOB NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))');
  3821. if ($query === false)
  3822. {
  3823. trigger_error("Can't create " . $this->options['extras']['prefix'] . "items table, check permissions", E_USER_WARNING);
  3824. $this->mysql = null;
  3825. return;
  3826. }
  3827. }
  3828. }
  3829. /**
  3830. * Save data to the cache
  3831. *
  3832. * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
  3833. * @return bool Successfulness
  3834. */
  3835. public function save($data)
  3836. {
  3837. if ($this->mysql === null)
  3838. {
  3839. return false;
  3840. }
  3841. $query = $this->mysql->prepare('DELETE i, cd FROM `' . $this->options['extras']['prefix'] . 'cache_data` cd, ' .
  3842. '`' . $this->options['extras']['prefix'] . 'items` i ' .
  3843. 'WHERE cd.id = i.feed_id ' .
  3844. 'AND cd.mtime < (unix_timestamp() - :purge_time)');
  3845. $query->bindValue(':purge_time', $this->options['extras']['cache_purge_time']);
  3846. if (!$query->execute())
  3847. {
  3848. return false;
  3849. }
  3850. if ($data instanceof SimplePie)
  3851. {
  3852. $data = clone $data;
  3853. $prepared = self::prepare_simplepie_object_for_cache($data);
  3854. $query = $this->mysql->prepare('SELECT COUNT(*) FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
  3855. $query->bindValue(':feed', $this->id);
  3856. if ($query->execute())
  3857. {
  3858. if ($query->fetchColumn() > 0)
  3859. {
  3860. $items = count($prepared[1]);
  3861. if ($items)
  3862. {
  3863. $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = :items, `data` = :data, `mtime` = :time WHERE `id` = :feed';
  3864. $query = $this->mysql->prepare($sql);
  3865. $query->bindValue(':items', $items);
  3866. }
  3867. else
  3868. {
  3869. $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `data` = :data, `mtime` = :time WHERE `id` = :feed';
  3870. $query = $this->mysql->prepare($sql);
  3871. }
  3872. $query->bindValue(':data', $prepared[0]);
  3873. $query->bindValue(':time', time());
  3874. $query->bindValue(':feed', $this->id);
  3875. if (!$query->execute())
  3876. {
  3877. return false;
  3878. }
  3879. }
  3880. else
  3881. {
  3882. $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:feed, :count, :data, :time)');
  3883. $query->bindValue(':feed', $this->id);
  3884. $query->bindValue(':count', count($prepared[1]));
  3885. $query->bindValue(':data', $prepared[0]);
  3886. $query->bindValue(':time', time());
  3887. if (!$query->execute())
  3888. {
  3889. return false;
  3890. }
  3891. }
  3892. $ids = array_keys($prepared[1]);
  3893. if (!empty($ids))
  3894. {
  3895. foreach ($ids as $id)
  3896. {
  3897. $database_ids[] = $this->mysql->quote($id);
  3898. }
  3899. $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `id` = ' . implode(' OR `id` = ', $database_ids) . ' AND `feed_id` = :feed');
  3900. $query->bindValue(':feed', $this->id);
  3901. if ($query->execute())
  3902. {
  3903. $existing_ids = array();
  3904. while ($row = $query->fetchColumn())
  3905. {
  3906. $existing_ids[] = $row;
  3907. }
  3908. $new_ids = array_diff($ids, $existing_ids);
  3909. foreach ($new_ids as $new_id)
  3910. {
  3911. if (!($date = $prepared[1][$new_id]->get_date('U')))
  3912. {
  3913. $date = time();
  3914. }
  3915. $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'items` (`feed_id`, `id`, `data`, `posted`) VALUES(:feed, :id, :data, :date)');
  3916. $query->bindValue(':feed', $this->id);
  3917. $query->bindValue(':id', $new_id);
  3918. $query->bindValue(':data', serialize($prepared[1][$new_id]->data));
  3919. $query->bindValue(':date', $date);
  3920. if (!$query->execute())
  3921. {
  3922. return false;
  3923. }
  3924. }
  3925. return true;
  3926. }
  3927. }
  3928. else
  3929. {
  3930. return true;
  3931. }
  3932. }
  3933. }
  3934. else
  3935. {
  3936. $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
  3937. $query->bindValue(':feed', $this->id);
  3938. if ($query->execute())
  3939. {
  3940. if ($query->rowCount() > 0)
  3941. {
  3942. $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = 0, `data` = :data, `mtime` = :time WHERE `id` = :feed');
  3943. $query->bindValue(':data', serialize($data));
  3944. $query->bindValue(':time', time());
  3945. $query->bindValue(':feed', $this->id);
  3946. if ($this->execute())
  3947. {
  3948. return true;
  3949. }
  3950. }
  3951. else
  3952. {
  3953. $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:id, 0, :data, :time)');
  3954. $query->bindValue(':id', $this->id);
  3955. $query->bindValue(':data', serialize($data));
  3956. $query->bindValue(':time', time());
  3957. if ($query->execute())
  3958. {
  3959. return true;
  3960. }
  3961. }
  3962. }
  3963. }
  3964. return false;
  3965. }
  3966. /**
  3967. * Retrieve the data saved to the cache
  3968. *
  3969. * @return array Data for SimplePie::$data
  3970. */
  3971. public function load()
  3972. {
  3973. if ($this->mysql === null)
  3974. {
  3975. return false;
  3976. }
  3977. $query = $this->mysql->prepare('SELECT `items`, `data` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
  3978. $query->bindValue(':id', $this->id);
  3979. if ($query->execute() && ($row = $query->fetch()))
  3980. {
  3981. $data = unserialize($row[1]);
  3982. if (isset($this->options['items'][0]))
  3983. {
  3984. $items = (int) $this->options['items'][0];
  3985. }
  3986. else
  3987. {
  3988. $items = (int) $row[0];
  3989. }
  3990. if ($items !== 0)
  3991. {
  3992. if (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
  3993. {
  3994. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
  3995. }
  3996. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
  3997. {
  3998. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
  3999. }
  4000. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
  4001. {
  4002. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
  4003. }
  4004. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]))
  4005. {
  4006. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0];
  4007. }
  4008. else
  4009. {
  4010. $feed = null;
  4011. }
  4012. if ($feed !== null)
  4013. {
  4014. $sql = 'SELECT `data` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :feed ORDER BY `posted` DESC';
  4015. if ($items > 0)
  4016. {
  4017. $sql .= ' LIMIT ' . $items;
  4018. }
  4019. $query = $this->mysql->prepare($sql);
  4020. $query->bindValue(':feed', $this->id);
  4021. if ($query->execute())
  4022. {
  4023. while ($row = $query->fetchColumn())
  4024. {
  4025. $feed['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry'][] = unserialize($row);
  4026. }
  4027. }
  4028. else
  4029. {
  4030. return false;
  4031. }
  4032. }
  4033. }
  4034. return $data;
  4035. }
  4036. return false;
  4037. }
  4038. /**
  4039. * Retrieve the last modified time for the cache
  4040. *
  4041. * @return int Timestamp
  4042. */
  4043. public function mtime()
  4044. {
  4045. if ($this->mysql === null)
  4046. {
  4047. return false;
  4048. }
  4049. $query = $this->mysql->prepare('SELECT `mtime` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
  4050. $query->bindValue(':id', $this->id);
  4051. if ($query->execute() && ($time = $query->fetchColumn()))
  4052. {
  4053. return $time;
  4054. }
  4055. else
  4056. {
  4057. return false;
  4058. }
  4059. }
  4060. /**
  4061. * Set the last modified time to the current time
  4062. *
  4063. * @return bool Success status
  4064. */
  4065. public function touch()
  4066. {
  4067. if ($this->mysql === null)
  4068. {
  4069. return false;
  4070. }
  4071. $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `mtime` = :time WHERE `id` = :id');
  4072. $query->bindValue(':time', time());
  4073. $query->bindValue(':id', $this->id);
  4074. if ($query->execute() && $query->rowCount() > 0)
  4075. {
  4076. return true;
  4077. }
  4078. else
  4079. {
  4080. return false;
  4081. }
  4082. }
  4083. /**
  4084. * Remove the cache
  4085. *
  4086. * @return bool Success status
  4087. */
  4088. public function unlink()
  4089. {
  4090. if ($this->mysql === null)
  4091. {
  4092. return false;
  4093. }
  4094. $query = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
  4095. $query->bindValue(':id', $this->id);
  4096. $query2 = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :id');
  4097. $query2->bindValue(':id', $this->id);
  4098. if ($query->execute() && $query2->execute())
  4099. {
  4100. return true;
  4101. }
  4102. else
  4103. {
  4104. return false;
  4105. }
  4106. }
  4107. }
  4108. /**
  4109. * Caches data to redis
  4110. *
  4111. * Registered for URLs with the "redis" protocol
  4112. *
  4113. * For example, `redis://localhost:6379/?timeout=3600&prefix=sp_&dbIndex=0` will
  4114. * connect to redis on `localhost` on port 6379. All tables will be
  4115. * prefixed with `simple_primary-` and data will expire after 3600 seconds
  4116. *
  4117. * @package SimplePie
  4118. * @subpackage Caching
  4119. * @uses Redis
  4120. */
  4121. class SimplePie_Cache_Redis implements SimplePie_Cache_Base {
  4122. /**
  4123. * Redis instance
  4124. *
  4125. * @var \Redis
  4126. */
  4127. protected $cache;
  4128. /**
  4129. * Options
  4130. *
  4131. * @var array
  4132. */
  4133. protected $options;
  4134. /**
  4135. * Cache name
  4136. *
  4137. * @var string
  4138. */
  4139. protected $name;
  4140. /**
  4141. * Cache Data
  4142. *
  4143. * @var type
  4144. */
  4145. protected $data;
  4146. /**
  4147. * Create a new cache object
  4148. *
  4149. * @param string $location Location string (from SimplePie::$cache_location)
  4150. * @param string $name Unique ID for the cache
  4151. * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
  4152. */
  4153. public function __construct($location, $name, $options = null) {
  4154. //$this->cache = \flow\simple\cache\Redis::getRedisClientInstance();
  4155. $parsed = SimplePie_Cache::parse_URL($location);
  4156. $redis = new Redis();
  4157. $redis->connect($parsed['host'], $parsed['port']);
  4158. $this->cache = $redis;
  4159. if (!is_null($options) && is_array($options)) {
  4160. $this->options = $options;
  4161. } else {
  4162. $this->options = array (
  4163. 'prefix' => 'rss:simple_primary:',
  4164. 'expire' => 0,
  4165. );
  4166. }
  4167. $this->name = $this->options['prefix'] . $name;
  4168. }
  4169. /**
  4170. * @param \Redis $cache
  4171. */
  4172. public function setRedisClient(\Redis $cache) {
  4173. $this->cache = $cache;
  4174. }
  4175. /**
  4176. * Save data to the cache
  4177. *
  4178. * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
  4179. * @return bool Successfulness
  4180. */
  4181. public function save($data) {
  4182. if ($data instanceof SimplePie) {
  4183. $data = $data->data;
  4184. }
  4185. $response = $this->cache->set($this->name, serialize($data));
  4186. if ($this->options['expire']) {
  4187. $this->cache->expire($this->name, $this->options['expire']);
  4188. }
  4189. return $response;
  4190. }
  4191. /**
  4192. * Retrieve the data saved to the cache
  4193. *
  4194. * @return array Data for SimplePie::$data
  4195. */
  4196. public function load() {
  4197. $data = $this->cache->get($this->name);
  4198. if ($data !== false) {
  4199. return unserialize($data);
  4200. }
  4201. return false;
  4202. }
  4203. /**
  4204. * Retrieve the last modified time for the cache
  4205. *
  4206. * @return int Timestamp
  4207. */
  4208. public function mtime() {
  4209. $data = $this->cache->get($this->name);
  4210. if ($data !== false) {
  4211. return time();
  4212. }
  4213. return false;
  4214. }
  4215. /**
  4216. * Set the last modified time to the current time
  4217. *
  4218. * @return bool Success status
  4219. */
  4220. public function touch() {
  4221. $data = $this->cache->get($this->name);
  4222. if ($data !== false) {
  4223. $return = $this->cache->set($this->name, $data);
  4224. if ($this->options['expire']) {
  4225. return $this->cache->expire($this->name, $this->ttl);
  4226. }
  4227. return $return;
  4228. }
  4229. return false;
  4230. }
  4231. /**
  4232. * Remove the cache
  4233. *
  4234. * @return bool Success status
  4235. */
  4236. public function unlink() {
  4237. return $this->cache->set($this->name, null);
  4238. }
  4239. }
  4240. /**
  4241. * Handles `<media:text>` captions as defined in Media RSS.
  4242. *
  4243. * Used by {@see SimplePie_Enclosure::get_caption()} and {@see SimplePie_Enclosure::get_captions()}
  4244. *
  4245. * This class can be overloaded with {@see SimplePie::set_caption_class()}
  4246. *
  4247. * @package SimplePie
  4248. * @subpackage API
  4249. */
  4250. class SimplePie_Caption
  4251. {
  4252. /**
  4253. * Content type
  4254. *
  4255. * @var string
  4256. * @see get_type()
  4257. */
  4258. var $type;
  4259. /**
  4260. * Language
  4261. *
  4262. * @var string
  4263. * @see get_language()
  4264. */
  4265. var $lang;
  4266. /**
  4267. * Start time
  4268. *
  4269. * @var string
  4270. * @see get_starttime()
  4271. */
  4272. var $startTime;
  4273. /**
  4274. * End time
  4275. *
  4276. * @var string
  4277. * @see get_endtime()
  4278. */
  4279. var $endTime;
  4280. /**
  4281. * Caption text
  4282. *
  4283. * @var string
  4284. * @see get_text()
  4285. */
  4286. var $text;
  4287. /**
  4288. * Constructor, used to input the data
  4289. *
  4290. * For documentation on all the parameters, see the corresponding
  4291. * properties and their accessors
  4292. */
  4293. public function __construct($type = null, $lang = null, $startTime = null, $endTime = null, $text = null)
  4294. {
  4295. $this->type = $type;
  4296. $this->lang = $lang;
  4297. $this->startTime = $startTime;
  4298. $this->endTime = $endTime;
  4299. $this->text = $text;
  4300. }
  4301. /**
  4302. * String-ified version
  4303. *
  4304. * @return string
  4305. */
  4306. public function __toString()
  4307. {
  4308. // There is no $this->data here
  4309. return md5(serialize($this));
  4310. }
  4311. /**
  4312. * Get the end time
  4313. *
  4314. * @return string|null Time in the format 'hh:mm:ss.SSS'
  4315. */
  4316. public function get_endtime()
  4317. {
  4318. if ($this->endTime !== null)
  4319. {
  4320. return $this->endTime;
  4321. }
  4322. else
  4323. {
  4324. return null;
  4325. }
  4326. }
  4327. /**
  4328. * Get the language
  4329. *
  4330. * @link http://tools.ietf.org/html/rfc3066
  4331. * @return string|null Language code as per RFC 3066
  4332. */
  4333. public function get_language()
  4334. {
  4335. if ($this->lang !== null)
  4336. {
  4337. return $this->lang;
  4338. }
  4339. else
  4340. {
  4341. return null;
  4342. }
  4343. }
  4344. /**
  4345. * Get the start time
  4346. *
  4347. * @return string|null Time in the format 'hh:mm:ss.SSS'
  4348. */
  4349. public function get_starttime()
  4350. {
  4351. if ($this->startTime !== null)
  4352. {
  4353. return $this->startTime;
  4354. }
  4355. else
  4356. {
  4357. return null;
  4358. }
  4359. }
  4360. /**
  4361. * Get the text of the caption
  4362. *
  4363. * @return string|null
  4364. */
  4365. public function get_text()
  4366. {
  4367. if ($this->text !== null)
  4368. {
  4369. return $this->text;
  4370. }
  4371. else
  4372. {
  4373. return null;
  4374. }
  4375. }
  4376. /**
  4377. * Get the content type (not MIME type)
  4378. *
  4379. * @return string|null Either 'text' or 'html'
  4380. */
  4381. public function get_type()
  4382. {
  4383. if ($this->type !== null)
  4384. {
  4385. return $this->type;
  4386. }
  4387. else
  4388. {
  4389. return null;
  4390. }
  4391. }
  4392. }
  4393. /**
  4394. * Manages all category-related data
  4395. *
  4396. * Used by {@see SimplePie_Item::get_category()} and {@see SimplePie_Item::get_categories()}
  4397. *
  4398. * This class can be overloaded with {@see SimplePie::set_category_class()}
  4399. *
  4400. * @package SimplePie
  4401. * @subpackage API
  4402. */
  4403. class SimplePie_Category
  4404. {
  4405. /**
  4406. * Category identifier
  4407. *
  4408. * @var string
  4409. * @see get_term
  4410. */
  4411. var $term;
  4412. /**
  4413. * Categorization scheme identifier
  4414. *
  4415. * @var string
  4416. * @see get_scheme()
  4417. */
  4418. var $scheme;
  4419. /**
  4420. * Human readable label
  4421. *
  4422. * @var string
  4423. * @see get_label()
  4424. */
  4425. var $label;
  4426. /**
  4427. * Constructor, used to input the data
  4428. *
  4429. * @param string $term
  4430. * @param string $scheme
  4431. * @param string $label
  4432. */
  4433. public function __construct($term = null, $scheme = null, $label = null)
  4434. {
  4435. $this->term = $term;
  4436. $this->scheme = $scheme;
  4437. $this->label = $label;
  4438. }
  4439. /**
  4440. * String-ified version
  4441. *
  4442. * @return string
  4443. */
  4444. public function __toString()
  4445. {
  4446. // There is no $this->data here
  4447. return md5(serialize($this));
  4448. }
  4449. /**
  4450. * Get the category identifier
  4451. *
  4452. * @return string|null
  4453. */
  4454. public function get_term()
  4455. {
  4456. if ($this->term !== null)
  4457. {
  4458. return $this->term;
  4459. }
  4460. else
  4461. {
  4462. return null;
  4463. }
  4464. }
  4465. /**
  4466. * Get the categorization scheme identifier
  4467. *
  4468. * @return string|null
  4469. */
  4470. public function get_scheme()
  4471. {
  4472. if ($this->scheme !== null)
  4473. {
  4474. return $this->scheme;
  4475. }
  4476. else
  4477. {
  4478. return null;
  4479. }
  4480. }
  4481. /**
  4482. * Get the human readable label
  4483. *
  4484. * @return string|null
  4485. */
  4486. public function get_label()
  4487. {
  4488. if ($this->label !== null)
  4489. {
  4490. return $this->label;
  4491. }
  4492. else
  4493. {
  4494. return $this->get_term();
  4495. }
  4496. }
  4497. }
  4498. /**
  4499. * Content-type sniffing
  4500. *
  4501. * Based on the rules in http://tools.ietf.org/html/draft-abarth-mime-sniff-06
  4502. *
  4503. * This is used since we can't always trust Content-Type headers, and is based
  4504. * upon the HTML5 parsing rules.
  4505. *
  4506. *
  4507. * This class can be overloaded with {@see SimplePie::set_content_type_sniffer_class()}
  4508. *
  4509. * @package SimplePie
  4510. * @subpackage HTTP
  4511. */
  4512. class SimplePie_Content_Type_Sniffer
  4513. {
  4514. /**
  4515. * File object
  4516. *
  4517. * @var SimplePie_File
  4518. */
  4519. var $file;
  4520. /**
  4521. * Create an instance of the class with the input file
  4522. *
  4523. * @param SimplePie_Content_Type_Sniffer $file Input file
  4524. */
  4525. public function __construct($file)
  4526. {
  4527. $this->file = $file;
  4528. }
  4529. /**
  4530. * Get the Content-Type of the specified file
  4531. *
  4532. * @return string Actual Content-Type
  4533. */
  4534. public function get_type()
  4535. {
  4536. if (isset($this->file->headers['content-type']))
  4537. {
  4538. if (!isset($this->file->headers['content-encoding'])
  4539. && ($this->file->headers['content-type'] === 'text/plain'
  4540. || $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1'
  4541. || $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1'
  4542. || $this->file->headers['content-type'] === 'text/plain; charset=UTF-8'))
  4543. {
  4544. return $this->text_or_binary();
  4545. }
  4546. if (($pos = strpos($this->file->headers['content-type'], ';')) !== false)
  4547. {
  4548. $official = substr($this->file->headers['content-type'], 0, $pos);
  4549. }
  4550. else
  4551. {
  4552. $official = $this->file->headers['content-type'];
  4553. }
  4554. $official = trim(strtolower($official));
  4555. if ($official === 'unknown/unknown'
  4556. || $official === 'application/unknown')
  4557. {
  4558. return $this->unknown();
  4559. }
  4560. elseif (substr($official, -4) === '+xml'
  4561. || $official === 'text/xml'
  4562. || $official === 'application/xml')
  4563. {
  4564. return $official;
  4565. }
  4566. elseif (substr($official, 0, 6) === 'image/')
  4567. {
  4568. if ($return = $this->image())
  4569. {
  4570. return $return;
  4571. }
  4572. else
  4573. {
  4574. return $official;
  4575. }
  4576. }
  4577. elseif ($official === 'text/html')
  4578. {
  4579. return $this->feed_or_html();
  4580. }
  4581. else
  4582. {
  4583. return $official;
  4584. }
  4585. }
  4586. else
  4587. {
  4588. return $this->unknown();
  4589. }
  4590. }
  4591. /**
  4592. * Sniff text or binary
  4593. *
  4594. * @return string Actual Content-Type
  4595. */
  4596. public function text_or_binary()
  4597. {
  4598. if (substr($this->file->body, 0, 2) === "\xFE\xFF"
  4599. || substr($this->file->body, 0, 2) === "\xFF\xFE"
  4600. || substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF"
  4601. || substr($this->file->body, 0, 3) === "\xEF\xBB\xBF")
  4602. {
  4603. return 'text/plain';
  4604. }
  4605. elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body))
  4606. {
  4607. return 'application/octect-stream';
  4608. }
  4609. else
  4610. {
  4611. return 'text/plain';
  4612. }
  4613. }
  4614. /**
  4615. * Sniff unknown
  4616. *
  4617. * @return string Actual Content-Type
  4618. */
  4619. public function unknown()
  4620. {
  4621. $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20");
  4622. if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html'
  4623. || strtolower(substr($this->file->body, $ws, 5)) === '<html'
  4624. || strtolower(substr($this->file->body, $ws, 7)) === '<script')
  4625. {
  4626. return 'text/html';
  4627. }
  4628. elseif (substr($this->file->body, 0, 5) === '%PDF-')
  4629. {
  4630. return 'application/pdf';
  4631. }
  4632. elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-')
  4633. {
  4634. return 'application/postscript';
  4635. }
  4636. elseif (substr($this->file->body, 0, 6) === 'GIF87a'
  4637. || substr($this->file->body, 0, 6) === 'GIF89a')
  4638. {
  4639. return 'image/gif';
  4640. }
  4641. elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
  4642. {
  4643. return 'image/png';
  4644. }
  4645. elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
  4646. {
  4647. return 'image/jpeg';
  4648. }
  4649. elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
  4650. {
  4651. return 'image/bmp';
  4652. }
  4653. elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
  4654. {
  4655. return 'image/vnd.microsoft.icon';
  4656. }
  4657. else
  4658. {
  4659. return $this->text_or_binary();
  4660. }
  4661. }
  4662. /**
  4663. * Sniff images
  4664. *
  4665. * @return string Actual Content-Type
  4666. */
  4667. public function image()
  4668. {
  4669. if (substr($this->file->body, 0, 6) === 'GIF87a'
  4670. || substr($this->file->body, 0, 6) === 'GIF89a')
  4671. {
  4672. return 'image/gif';
  4673. }
  4674. elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
  4675. {
  4676. return 'image/png';
  4677. }
  4678. elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
  4679. {
  4680. return 'image/jpeg';
  4681. }
  4682. elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
  4683. {
  4684. return 'image/bmp';
  4685. }
  4686. elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
  4687. {
  4688. return 'image/vnd.microsoft.icon';
  4689. }
  4690. else
  4691. {
  4692. return false;
  4693. }
  4694. }
  4695. /**
  4696. * Sniff HTML
  4697. *
  4698. * @return string Actual Content-Type
  4699. */
  4700. public function feed_or_html()
  4701. {
  4702. $len = strlen($this->file->body);
  4703. $pos = strspn($this->file->body, "\x09\x0A\x0D\x20\xEF\xBB\xBF");
  4704. while ($pos < $len)
  4705. {
  4706. switch ($this->file->body[$pos])
  4707. {
  4708. case "\x09":
  4709. case "\x0A":
  4710. case "\x0D":
  4711. case "\x20":
  4712. $pos += strspn($this->file->body, "\x09\x0A\x0D\x20", $pos);
  4713. continue 2;
  4714. case '<':
  4715. $pos++;
  4716. break;
  4717. default:
  4718. return 'text/html';
  4719. }
  4720. if (substr($this->file->body, $pos, 3) === '!--')
  4721. {
  4722. $pos += 3;
  4723. if ($pos < $len && ($pos = strpos($this->file->body, '-->', $pos)) !== false)
  4724. {
  4725. $pos += 3;
  4726. }
  4727. else
  4728. {
  4729. return 'text/html';
  4730. }
  4731. }
  4732. elseif (substr($this->file->body, $pos, 1) === '!')
  4733. {
  4734. if ($pos < $len && ($pos = strpos($this->file->body, '>', $pos)) !== false)
  4735. {
  4736. $pos++;
  4737. }
  4738. else
  4739. {
  4740. return 'text/html';
  4741. }
  4742. }
  4743. elseif (substr($this->file->body, $pos, 1) === '?')
  4744. {
  4745. if ($pos < $len && ($pos = strpos($this->file->body, '?>', $pos)) !== false)
  4746. {
  4747. $pos += 2;
  4748. }
  4749. else
  4750. {
  4751. return 'text/html';
  4752. }
  4753. }
  4754. elseif (substr($this->file->body, $pos, 3) === 'rss'
  4755. || substr($this->file->body, $pos, 7) === 'rdf:RDF')
  4756. {
  4757. return 'application/rss+xml';
  4758. }
  4759. elseif (substr($this->file->body, $pos, 4) === 'feed')
  4760. {
  4761. return 'application/atom+xml';
  4762. }
  4763. else
  4764. {
  4765. return 'text/html';
  4766. }
  4767. }
  4768. return 'text/html';
  4769. }
  4770. }
  4771. /**
  4772. * Manages `<media:copyright>` copyright tags as defined in Media RSS
  4773. *
  4774. * Used by {@see SimplePie_Enclosure::get_copyright()}
  4775. *
  4776. * This class can be overloaded with {@see SimplePie::set_copyright_class()}
  4777. *
  4778. * @package SimplePie
  4779. * @subpackage API
  4780. */
  4781. class SimplePie_Copyright
  4782. {
  4783. /**
  4784. * Copyright URL
  4785. *
  4786. * @var string
  4787. * @see get_url()
  4788. */
  4789. var $url;
  4790. /**
  4791. * Attribution
  4792. *
  4793. * @var string
  4794. * @see get_attribution()
  4795. */
  4796. var $label;
  4797. /**
  4798. * Constructor, used to input the data
  4799. *
  4800. * For documentation on all the parameters, see the corresponding
  4801. * properties and their accessors
  4802. */
  4803. public function __construct($url = null, $label = null)
  4804. {
  4805. $this->url = $url;
  4806. $this->label = $label;
  4807. }
  4808. /**
  4809. * String-ified version
  4810. *
  4811. * @return string
  4812. */
  4813. public function __toString()
  4814. {
  4815. // There is no $this->data here
  4816. return md5(serialize($this));
  4817. }
  4818. /**
  4819. * Get the copyright URL
  4820. *
  4821. * @return string|null URL to copyright information
  4822. */
  4823. public function get_url()
  4824. {
  4825. if ($this->url !== null)
  4826. {
  4827. return $this->url;
  4828. }
  4829. else
  4830. {
  4831. return null;
  4832. }
  4833. }
  4834. /**
  4835. * Get the attribution text
  4836. *
  4837. * @return string|null
  4838. */
  4839. public function get_attribution()
  4840. {
  4841. if ($this->label !== null)
  4842. {
  4843. return $this->label;
  4844. }
  4845. else
  4846. {
  4847. return null;
  4848. }
  4849. }
  4850. }
  4851. /**
  4852. * SimplePie class.
  4853. *
  4854. * Class for backward compatibility.
  4855. *
  4856. * @deprecated Use {@see SimplePie} directly
  4857. * @package SimplePie
  4858. * @subpackage API
  4859. */
  4860. class SimplePie_Core extends SimplePie
  4861. {
  4862. }
  4863. /**
  4864. * Handles `<media:credit>` as defined in Media RSS
  4865. *
  4866. * Used by {@see SimplePie_Enclosure::get_credit()} and {@see SimplePie_Enclosure::get_credits()}
  4867. *
  4868. * This class can be overloaded with {@see SimplePie::set_credit_class()}
  4869. *
  4870. * @package SimplePie
  4871. * @subpackage API
  4872. */
  4873. class SimplePie_Credit
  4874. {
  4875. /**
  4876. * Credited role
  4877. *
  4878. * @var string
  4879. * @see get_role()
  4880. */
  4881. var $role;
  4882. /**
  4883. * Organizational scheme
  4884. *
  4885. * @var string
  4886. * @see get_scheme()
  4887. */
  4888. var $scheme;
  4889. /**
  4890. * Credited name
  4891. *
  4892. * @var string
  4893. * @see get_name()
  4894. */
  4895. var $name;
  4896. /**
  4897. * Constructor, used to input the data
  4898. *
  4899. * For documentation on all the parameters, see the corresponding
  4900. * properties and their accessors
  4901. */
  4902. public function __construct($role = null, $scheme = null, $name = null)
  4903. {
  4904. $this->role = $role;
  4905. $this->scheme = $scheme;
  4906. $this->name = $name;
  4907. }
  4908. /**
  4909. * String-ified version
  4910. *
  4911. * @return string
  4912. */
  4913. public function __toString()
  4914. {
  4915. // There is no $this->data here
  4916. return md5(serialize($this));
  4917. }
  4918. /**
  4919. * Get the role of the person receiving credit
  4920. *
  4921. * @return string|null
  4922. */
  4923. public function get_role()
  4924. {
  4925. if ($this->role !== null)
  4926. {
  4927. return $this->role;
  4928. }
  4929. else
  4930. {
  4931. return null;
  4932. }
  4933. }
  4934. /**
  4935. * Get the organizational scheme
  4936. *
  4937. * @return string|null
  4938. */
  4939. public function get_scheme()
  4940. {
  4941. if ($this->scheme !== null)
  4942. {
  4943. return $this->scheme;
  4944. }
  4945. else
  4946. {
  4947. return null;
  4948. }
  4949. }
  4950. /**
  4951. * Get the credited person/entity's name
  4952. *
  4953. * @return string|null
  4954. */
  4955. public function get_name()
  4956. {
  4957. if ($this->name !== null)
  4958. {
  4959. return $this->name;
  4960. }
  4961. else
  4962. {
  4963. return null;
  4964. }
  4965. }
  4966. }
  4967. /**
  4968. * Decode HTML Entities
  4969. *
  4970. * This implements HTML5 as of revision 967 (2007-06-28)
  4971. *
  4972. * @deprecated Use DOMDocument instead!
  4973. * @package SimplePie
  4974. */
  4975. class SimplePie_Decode_HTML_Entities
  4976. {
  4977. /**
  4978. * Data to be parsed
  4979. *
  4980. * @access private
  4981. * @var string
  4982. */
  4983. var $data = '';
  4984. /**
  4985. * Currently consumed bytes
  4986. *
  4987. * @access private
  4988. * @var string
  4989. */
  4990. var $consumed = '';
  4991. /**
  4992. * Position of the current byte being parsed
  4993. *
  4994. * @access private
  4995. * @var int
  4996. */
  4997. var $position = 0;
  4998. /**
  4999. * Create an instance of the class with the input data
  5000. *
  5001. * @access public
  5002. * @param string $data Input data
  5003. */
  5004. public function __construct($data)
  5005. {
  5006. $this->data = $data;
  5007. }
  5008. /**
  5009. * Parse the input data
  5010. *
  5011. * @access public
  5012. * @return string Output data
  5013. */
  5014. public function parse()
  5015. {
  5016. while (($this->position = strpos($this->data, '&', $this->position)) !== false)
  5017. {
  5018. $this->consume();
  5019. $this->entity();
  5020. $this->consumed = '';
  5021. }
  5022. return $this->data;
  5023. }
  5024. /**
  5025. * Consume the next byte
  5026. *
  5027. * @access private
  5028. * @return mixed The next byte, or false, if there is no more data
  5029. */
  5030. public function consume()
  5031. {
  5032. if (isset($this->data[$this->position]))
  5033. {
  5034. $this->consumed .= $this->data[$this->position];
  5035. return $this->data[$this->position++];
  5036. }
  5037. else
  5038. {
  5039. return false;
  5040. }
  5041. }
  5042. /**
  5043. * Consume a range of characters
  5044. *
  5045. * @access private
  5046. * @param string $chars Characters to consume
  5047. * @return mixed A series of characters that match the range, or false
  5048. */
  5049. public function consume_range($chars)
  5050. {
  5051. if ($len = strspn($this->data, $chars, $this->position))
  5052. {
  5053. $data = substr($this->data, $this->position, $len);
  5054. $this->consumed .= $data;
  5055. $this->position += $len;
  5056. return $data;
  5057. }
  5058. else
  5059. {
  5060. return false;
  5061. }
  5062. }
  5063. /**
  5064. * Unconsume one byte
  5065. *
  5066. * @access private
  5067. */
  5068. public function unconsume()
  5069. {
  5070. $this->consumed = substr($this->consumed, 0, -1);
  5071. $this->position--;
  5072. }
  5073. /**
  5074. * Decode an entity
  5075. *
  5076. * @access private
  5077. */
  5078. public function entity()
  5079. {
  5080. switch ($this->consume())
  5081. {
  5082. case "\x09":
  5083. case "\x0A":
  5084. case "\x0B":
  5085. case "\x0C":
  5086. case "\x20":
  5087. case "\x3C":
  5088. case "\x26":
  5089. case false:
  5090. break;
  5091. case "\x23":
  5092. switch ($this->consume())
  5093. {
  5094. case "\x78":
  5095. case "\x58":
  5096. $range = '0123456789ABCDEFabcdef';
  5097. $hex = true;
  5098. break;
  5099. default:
  5100. $range = '0123456789';
  5101. $hex = false;
  5102. $this->unconsume();
  5103. break;
  5104. }
  5105. if ($codepoint = $this->consume_range($range))
  5106. {
  5107. static $windows_1252_specials = array(0x0D => "\x0A", 0x80 => "\xE2\x82\xAC", 0x81 => "\xEF\xBF\xBD", 0x82 => "\xE2\x80\x9A", 0x83 => "\xC6\x92", 0x84 => "\xE2\x80\x9E", 0x85 => "\xE2\x80\xA6", 0x86 => "\xE2\x80\xA0", 0x87 => "\xE2\x80\xA1", 0x88 => "\xCB\x86", 0x89 => "\xE2\x80\xB0", 0x8A => "\xC5\xA0", 0x8B => "\xE2\x80\xB9", 0x8C => "\xC5\x92", 0x8D => "\xEF\xBF\xBD", 0x8E => "\xC5\xBD", 0x8F => "\xEF\xBF\xBD", 0x90 => "\xEF\xBF\xBD", 0x91 => "\xE2\x80\x98", 0x92 => "\xE2\x80\x99", 0x93 => "\xE2\x80\x9C", 0x94 => "\xE2\x80\x9D", 0x95 => "\xE2\x80\xA2", 0x96 => "\xE2\x80\x93", 0x97 => "\xE2\x80\x94", 0x98 => "\xCB\x9C", 0x99 => "\xE2\x84\xA2", 0x9A => "\xC5\xA1", 0x9B => "\xE2\x80\xBA", 0x9C => "\xC5\x93", 0x9D => "\xEF\xBF\xBD", 0x9E => "\xC5\xBE", 0x9F => "\xC5\xB8");
  5108. if ($hex)
  5109. {
  5110. $codepoint = hexdec($codepoint);
  5111. }
  5112. else
  5113. {
  5114. $codepoint = intval($codepoint);
  5115. }
  5116. if (isset($windows_1252_specials[$codepoint]))
  5117. {
  5118. $replacement = $windows_1252_specials[$codepoint];
  5119. }
  5120. else
  5121. {
  5122. $replacement = SimplePie_Misc::codepoint_to_utf8($codepoint);
  5123. }
  5124. if (!in_array($this->consume(), array(';', false), true))
  5125. {
  5126. $this->unconsume();
  5127. }
  5128. $consumed_length = strlen($this->consumed);
  5129. $this->data = substr_replace($this->data, $replacement, $this->position - $consumed_length, $consumed_length);
  5130. $this->position += strlen($replacement) - $consumed_length;
  5131. }
  5132. break;
  5133. default:
  5134. static $entities = array(
  5135. 'Aacute' => "\xC3\x81",
  5136. 'aacute' => "\xC3\xA1",
  5137. 'Aacute;' => "\xC3\x81",
  5138. 'aacute;' => "\xC3\xA1",
  5139. 'Acirc' => "\xC3\x82",
  5140. 'acirc' => "\xC3\xA2",
  5141. 'Acirc;' => "\xC3\x82",
  5142. 'acirc;' => "\xC3\xA2",
  5143. 'acute' => "\xC2\xB4",
  5144. 'acute;' => "\xC2\xB4",
  5145. 'AElig' => "\xC3\x86",
  5146. 'aelig' => "\xC3\xA6",
  5147. 'AElig;' => "\xC3\x86",
  5148. 'aelig;' => "\xC3\xA6",
  5149. 'Agrave' => "\xC3\x80",
  5150. 'agrave' => "\xC3\xA0",
  5151. 'Agrave;' => "\xC3\x80",
  5152. 'agrave;' => "\xC3\xA0",
  5153. 'alefsym;' => "\xE2\x84\xB5",
  5154. 'Alpha;' => "\xCE\x91",
  5155. 'alpha;' => "\xCE\xB1",
  5156. 'AMP' => "\x26",
  5157. 'amp' => "\x26",
  5158. 'AMP;' => "\x26",
  5159. 'amp;' => "\x26",
  5160. 'and;' => "\xE2\x88\xA7",
  5161. 'ang;' => "\xE2\x88\xA0",
  5162. 'apos;' => "\x27",
  5163. 'Aring' => "\xC3\x85",
  5164. 'aring' => "\xC3\xA5",
  5165. 'Aring;' => "\xC3\x85",
  5166. 'aring;' => "\xC3\xA5",
  5167. 'asymp;' => "\xE2\x89\x88",
  5168. 'Atilde' => "\xC3\x83",
  5169. 'atilde' => "\xC3\xA3",
  5170. 'Atilde;' => "\xC3\x83",
  5171. 'atilde;' => "\xC3\xA3",
  5172. 'Auml' => "\xC3\x84",
  5173. 'auml' => "\xC3\xA4",
  5174. 'Auml;' => "\xC3\x84",
  5175. 'auml;' => "\xC3\xA4",
  5176. 'bdquo;' => "\xE2\x80\x9E",
  5177. 'Beta;' => "\xCE\x92",
  5178. 'beta;' => "\xCE\xB2",
  5179. 'brvbar' => "\xC2\xA6",
  5180. 'brvbar;' => "\xC2\xA6",
  5181. 'bull;' => "\xE2\x80\xA2",
  5182. 'cap;' => "\xE2\x88\xA9",
  5183. 'Ccedil' => "\xC3\x87",
  5184. 'ccedil' => "\xC3\xA7",
  5185. 'Ccedil;' => "\xC3\x87",
  5186. 'ccedil;' => "\xC3\xA7",
  5187. 'cedil' => "\xC2\xB8",
  5188. 'cedil;' => "\xC2\xB8",
  5189. 'cent' => "\xC2\xA2",
  5190. 'cent;' => "\xC2\xA2",
  5191. 'Chi;' => "\xCE\xA7",
  5192. 'chi;' => "\xCF\x87",
  5193. 'circ;' => "\xCB\x86",
  5194. 'clubs;' => "\xE2\x99\xA3",
  5195. 'cong;' => "\xE2\x89\x85",
  5196. 'COPY' => "\xC2\xA9",
  5197. 'copy' => "\xC2\xA9",
  5198. 'COPY;' => "\xC2\xA9",
  5199. 'copy;' => "\xC2\xA9",
  5200. 'crarr;' => "\xE2\x86\xB5",
  5201. 'cup;' => "\xE2\x88\xAA",
  5202. 'curren' => "\xC2\xA4",
  5203. 'curren;' => "\xC2\xA4",
  5204. 'Dagger;' => "\xE2\x80\xA1",
  5205. 'dagger;' => "\xE2\x80\xA0",
  5206. 'dArr;' => "\xE2\x87\x93",
  5207. 'darr;' => "\xE2\x86\x93",
  5208. 'deg' => "\xC2\xB0",
  5209. 'deg;' => "\xC2\xB0",
  5210. 'Delta;' => "\xCE\x94",
  5211. 'delta;' => "\xCE\xB4",
  5212. 'diams;' => "\xE2\x99\xA6",
  5213. 'divide' => "\xC3\xB7",
  5214. 'divide;' => "\xC3\xB7",
  5215. 'Eacute' => "\xC3\x89",
  5216. 'eacute' => "\xC3\xA9",
  5217. 'Eacute;' => "\xC3\x89",
  5218. 'eacute;' => "\xC3\xA9",
  5219. 'Ecirc' => "\xC3\x8A",
  5220. 'ecirc' => "\xC3\xAA",
  5221. 'Ecirc;' => "\xC3\x8A",
  5222. 'ecirc;' => "\xC3\xAA",
  5223. 'Egrave' => "\xC3\x88",
  5224. 'egrave' => "\xC3\xA8",
  5225. 'Egrave;' => "\xC3\x88",
  5226. 'egrave;' => "\xC3\xA8",
  5227. 'empty;' => "\xE2\x88\x85",
  5228. 'emsp;' => "\xE2\x80\x83",
  5229. 'ensp;' => "\xE2\x80\x82",
  5230. 'Epsilon;' => "\xCE\x95",
  5231. 'epsilon;' => "\xCE\xB5",
  5232. 'equiv;' => "\xE2\x89\xA1",
  5233. 'Eta;' => "\xCE\x97",
  5234. 'eta;' => "\xCE\xB7",
  5235. 'ETH' => "\xC3\x90",
  5236. 'eth' => "\xC3\xB0",
  5237. 'ETH;' => "\xC3\x90",
  5238. 'eth;' => "\xC3\xB0",
  5239. 'Euml' => "\xC3\x8B",
  5240. 'euml' => "\xC3\xAB",
  5241. 'Euml;' => "\xC3\x8B",
  5242. 'euml;' => "\xC3\xAB",
  5243. 'euro;' => "\xE2\x82\xAC",
  5244. 'exist;' => "\xE2\x88\x83",
  5245. 'fnof;' => "\xC6\x92",
  5246. 'forall;' => "\xE2\x88\x80",
  5247. 'frac12' => "\xC2\xBD",
  5248. 'frac12;' => "\xC2\xBD",
  5249. 'frac14' => "\xC2\xBC",
  5250. 'frac14;' => "\xC2\xBC",
  5251. 'frac34' => "\xC2\xBE",
  5252. 'frac34;' => "\xC2\xBE",
  5253. 'frasl;' => "\xE2\x81\x84",
  5254. 'Gamma;' => "\xCE\x93",
  5255. 'gamma;' => "\xCE\xB3",
  5256. 'ge;' => "\xE2\x89\xA5",
  5257. 'GT' => "\x3E",
  5258. 'gt' => "\x3E",
  5259. 'GT;' => "\x3E",
  5260. 'gt;' => "\x3E",
  5261. 'hArr;' => "\xE2\x87\x94",
  5262. 'harr;' => "\xE2\x86\x94",
  5263. 'hearts;' => "\xE2\x99\xA5",
  5264. 'hellip;' => "\xE2\x80\xA6",
  5265. 'Iacute' => "\xC3\x8D",
  5266. 'iacute' => "\xC3\xAD",
  5267. 'Iacute;' => "\xC3\x8D",
  5268. 'iacute;' => "\xC3\xAD",
  5269. 'Icirc' => "\xC3\x8E",
  5270. 'icirc' => "\xC3\xAE",
  5271. 'Icirc;' => "\xC3\x8E",
  5272. 'icirc;' => "\xC3\xAE",
  5273. 'iexcl' => "\xC2\xA1",
  5274. 'iexcl;' => "\xC2\xA1",
  5275. 'Igrave' => "\xC3\x8C",
  5276. 'igrave' => "\xC3\xAC",
  5277. 'Igrave;' => "\xC3\x8C",
  5278. 'igrave;' => "\xC3\xAC",
  5279. 'image;' => "\xE2\x84\x91",
  5280. 'infin;' => "\xE2\x88\x9E",
  5281. 'int;' => "\xE2\x88\xAB",
  5282. 'Iota;' => "\xCE\x99",
  5283. 'iota;' => "\xCE\xB9",
  5284. 'iquest' => "\xC2\xBF",
  5285. 'iquest;' => "\xC2\xBF",
  5286. 'isin;' => "\xE2\x88\x88",
  5287. 'Iuml' => "\xC3\x8F",
  5288. 'iuml' => "\xC3\xAF",
  5289. 'Iuml;' => "\xC3\x8F",
  5290. 'iuml;' => "\xC3\xAF",
  5291. 'Kappa;' => "\xCE\x9A",
  5292. 'kappa;' => "\xCE\xBA",
  5293. 'Lambda;' => "\xCE\x9B",
  5294. 'lambda;' => "\xCE\xBB",
  5295. 'lang;' => "\xE3\x80\x88",
  5296. 'laquo' => "\xC2\xAB",
  5297. 'laquo;' => "\xC2\xAB",
  5298. 'lArr;' => "\xE2\x87\x90",
  5299. 'larr;' => "\xE2\x86\x90",
  5300. 'lceil;' => "\xE2\x8C\x88",
  5301. 'ldquo;' => "\xE2\x80\x9C",
  5302. 'le;' => "\xE2\x89\xA4",
  5303. 'lfloor;' => "\xE2\x8C\x8A",
  5304. 'lowast;' => "\xE2\x88\x97",
  5305. 'loz;' => "\xE2\x97\x8A",
  5306. 'lrm;' => "\xE2\x80\x8E",
  5307. 'lsaquo;' => "\xE2\x80\xB9",
  5308. 'lsquo;' => "\xE2\x80\x98",
  5309. 'LT' => "\x3C",
  5310. 'lt' => "\x3C",
  5311. 'LT;' => "\x3C",
  5312. 'lt;' => "\x3C",
  5313. 'macr' => "\xC2\xAF",
  5314. 'macr;' => "\xC2\xAF",
  5315. 'mdash;' => "\xE2\x80\x94",
  5316. 'micro' => "\xC2\xB5",
  5317. 'micro;' => "\xC2\xB5",
  5318. 'middot' => "\xC2\xB7",
  5319. 'middot;' => "\xC2\xB7",
  5320. 'minus;' => "\xE2\x88\x92",
  5321. 'Mu;' => "\xCE\x9C",
  5322. 'mu;' => "\xCE\xBC",
  5323. 'nabla;' => "\xE2\x88\x87",
  5324. 'nbsp' => "\xC2\xA0",
  5325. 'nbsp;' => "\xC2\xA0",
  5326. 'ndash;' => "\xE2\x80\x93",
  5327. 'ne;' => "\xE2\x89\xA0",
  5328. 'ni;' => "\xE2\x88\x8B",
  5329. 'not' => "\xC2\xAC",
  5330. 'not;' => "\xC2\xAC",
  5331. 'notin;' => "\xE2\x88\x89",
  5332. 'nsub;' => "\xE2\x8A\x84",
  5333. 'Ntilde' => "\xC3\x91",
  5334. 'ntilde' => "\xC3\xB1",
  5335. 'Ntilde;' => "\xC3\x91",
  5336. 'ntilde;' => "\xC3\xB1",
  5337. 'Nu;' => "\xCE\x9D",
  5338. 'nu;' => "\xCE\xBD",
  5339. 'Oacute' => "\xC3\x93",
  5340. 'oacute' => "\xC3\xB3",
  5341. 'Oacute;' => "\xC3\x93",
  5342. 'oacute;' => "\xC3\xB3",
  5343. 'Ocirc' => "\xC3\x94",
  5344. 'ocirc' => "\xC3\xB4",
  5345. 'Ocirc;' => "\xC3\x94",
  5346. 'ocirc;' => "\xC3\xB4",
  5347. 'OElig;' => "\xC5\x92",
  5348. 'oelig;' => "\xC5\x93",
  5349. 'Ograve' => "\xC3\x92",
  5350. 'ograve' => "\xC3\xB2",
  5351. 'Ograve;' => "\xC3\x92",
  5352. 'ograve;' => "\xC3\xB2",
  5353. 'oline;' => "\xE2\x80\xBE",
  5354. 'Omega;' => "\xCE\xA9",
  5355. 'omega;' => "\xCF\x89",
  5356. 'Omicron;' => "\xCE\x9F",
  5357. 'omicron;' => "\xCE\xBF",
  5358. 'oplus;' => "\xE2\x8A\x95",
  5359. 'or;' => "\xE2\x88\xA8",
  5360. 'ordf' => "\xC2\xAA",
  5361. 'ordf;' => "\xC2\xAA",
  5362. 'ordm' => "\xC2\xBA",
  5363. 'ordm;' => "\xC2\xBA",
  5364. 'Oslash' => "\xC3\x98",
  5365. 'oslash' => "\xC3\xB8",
  5366. 'Oslash;' => "\xC3\x98",
  5367. 'oslash;' => "\xC3\xB8",
  5368. 'Otilde' => "\xC3\x95",
  5369. 'otilde' => "\xC3\xB5",
  5370. 'Otilde;' => "\xC3\x95",
  5371. 'otilde;' => "\xC3\xB5",
  5372. 'otimes;' => "\xE2\x8A\x97",
  5373. 'Ouml' => "\xC3\x96",
  5374. 'ouml' => "\xC3\xB6",
  5375. 'Ouml;' => "\xC3\x96",
  5376. 'ouml;' => "\xC3\xB6",
  5377. 'para' => "\xC2\xB6",
  5378. 'para;' => "\xC2\xB6",
  5379. 'part;' => "\xE2\x88\x82",
  5380. 'permil;' => "\xE2\x80\xB0",
  5381. 'perp;' => "\xE2\x8A\xA5",
  5382. 'Phi;' => "\xCE\xA6",
  5383. 'phi;' => "\xCF\x86",
  5384. 'Pi;' => "\xCE\xA0",
  5385. 'pi;' => "\xCF\x80",
  5386. 'piv;' => "\xCF\x96",
  5387. 'plusmn' => "\xC2\xB1",
  5388. 'plusmn;' => "\xC2\xB1",
  5389. 'pound' => "\xC2\xA3",
  5390. 'pound;' => "\xC2\xA3",
  5391. 'Prime;' => "\xE2\x80\xB3",
  5392. 'prime;' => "\xE2\x80\xB2",
  5393. 'prod;' => "\xE2\x88\x8F",
  5394. 'prop;' => "\xE2\x88\x9D",
  5395. 'Psi;' => "\xCE\xA8",
  5396. 'psi;' => "\xCF\x88",
  5397. 'QUOT' => "\x22",
  5398. 'quot' => "\x22",
  5399. 'QUOT;' => "\x22",
  5400. 'quot;' => "\x22",
  5401. 'radic;' => "\xE2\x88\x9A",
  5402. 'rang;' => "\xE3\x80\x89",
  5403. 'raquo' => "\xC2\xBB",
  5404. 'raquo;' => "\xC2\xBB",
  5405. 'rArr;' => "\xE2\x87\x92",
  5406. 'rarr;' => "\xE2\x86\x92",
  5407. 'rceil;' => "\xE2\x8C\x89",
  5408. 'rdquo;' => "\xE2\x80\x9D",
  5409. 'real;' => "\xE2\x84\x9C",
  5410. 'REG' => "\xC2\xAE",
  5411. 'reg' => "\xC2\xAE",
  5412. 'REG;' => "\xC2\xAE",
  5413. 'reg;' => "\xC2\xAE",
  5414. 'rfloor;' => "\xE2\x8C\x8B",
  5415. 'Rho;' => "\xCE\xA1",
  5416. 'rho;' => "\xCF\x81",
  5417. 'rlm;' => "\xE2\x80\x8F",
  5418. 'rsaquo;' => "\xE2\x80\xBA",
  5419. 'rsquo;' => "\xE2\x80\x99",
  5420. 'sbquo;' => "\xE2\x80\x9A",
  5421. 'Scaron;' => "\xC5\xA0",
  5422. 'scaron;' => "\xC5\xA1",
  5423. 'sdot;' => "\xE2\x8B\x85",
  5424. 'sect' => "\xC2\xA7",
  5425. 'sect;' => "\xC2\xA7",
  5426. 'shy' => "\xC2\xAD",
  5427. 'shy;' => "\xC2\xAD",
  5428. 'Sigma;' => "\xCE\xA3",
  5429. 'sigma;' => "\xCF\x83",
  5430. 'sigmaf;' => "\xCF\x82",
  5431. 'sim;' => "\xE2\x88\xBC",
  5432. 'spades;' => "\xE2\x99\xA0",
  5433. 'sub;' => "\xE2\x8A\x82",
  5434. 'sube;' => "\xE2\x8A\x86",
  5435. 'sum;' => "\xE2\x88\x91",
  5436. 'sup;' => "\xE2\x8A\x83",
  5437. 'sup1' => "\xC2\xB9",
  5438. 'sup1;' => "\xC2\xB9",
  5439. 'sup2' => "\xC2\xB2",
  5440. 'sup2;' => "\xC2\xB2",
  5441. 'sup3' => "\xC2\xB3",
  5442. 'sup3;' => "\xC2\xB3",
  5443. 'supe;' => "\xE2\x8A\x87",
  5444. 'szlig' => "\xC3\x9F",
  5445. 'szlig;' => "\xC3\x9F",
  5446. 'Tau;' => "\xCE\xA4",
  5447. 'tau;' => "\xCF\x84",
  5448. 'there4;' => "\xE2\x88\xB4",
  5449. 'Theta;' => "\xCE\x98",
  5450. 'theta;' => "\xCE\xB8",
  5451. 'thetasym;' => "\xCF\x91",
  5452. 'thinsp;' => "\xE2\x80\x89",
  5453. 'THORN' => "\xC3\x9E",
  5454. 'thorn' => "\xC3\xBE",
  5455. 'THORN;' => "\xC3\x9E",
  5456. 'thorn;' => "\xC3\xBE",
  5457. 'tilde;' => "\xCB\x9C",
  5458. 'times' => "\xC3\x97",
  5459. 'times;' => "\xC3\x97",
  5460. 'TRADE;' => "\xE2\x84\xA2",
  5461. 'trade;' => "\xE2\x84\xA2",
  5462. 'Uacute' => "\xC3\x9A",
  5463. 'uacute' => "\xC3\xBA",
  5464. 'Uacute;' => "\xC3\x9A",
  5465. 'uacute;' => "\xC3\xBA",
  5466. 'uArr;' => "\xE2\x87\x91",
  5467. 'uarr;' => "\xE2\x86\x91",
  5468. 'Ucirc' => "\xC3\x9B",
  5469. 'ucirc' => "\xC3\xBB",
  5470. 'Ucirc;' => "\xC3\x9B",
  5471. 'ucirc;' => "\xC3\xBB",
  5472. 'Ugrave' => "\xC3\x99",
  5473. 'ugrave' => "\xC3\xB9",
  5474. 'Ugrave;' => "\xC3\x99",
  5475. 'ugrave;' => "\xC3\xB9",
  5476. 'uml' => "\xC2\xA8",
  5477. 'uml;' => "\xC2\xA8",
  5478. 'upsih;' => "\xCF\x92",
  5479. 'Upsilon;' => "\xCE\xA5",
  5480. 'upsilon;' => "\xCF\x85",
  5481. 'Uuml' => "\xC3\x9C",
  5482. 'uuml' => "\xC3\xBC",
  5483. 'Uuml;' => "\xC3\x9C",
  5484. 'uuml;' => "\xC3\xBC",
  5485. 'weierp;' => "\xE2\x84\x98",
  5486. 'Xi;' => "\xCE\x9E",
  5487. 'xi;' => "\xCE\xBE",
  5488. 'Yacute' => "\xC3\x9D",
  5489. 'yacute' => "\xC3\xBD",
  5490. 'Yacute;' => "\xC3\x9D",
  5491. 'yacute;' => "\xC3\xBD",
  5492. 'yen' => "\xC2\xA5",
  5493. 'yen;' => "\xC2\xA5",
  5494. 'yuml' => "\xC3\xBF",
  5495. 'Yuml;' => "\xC5\xB8",
  5496. 'yuml;' => "\xC3\xBF",
  5497. 'Zeta;' => "\xCE\x96",
  5498. 'zeta;' => "\xCE\xB6",
  5499. 'zwj;' => "\xE2\x80\x8D",
  5500. 'zwnj;' => "\xE2\x80\x8C"
  5501. );
  5502. for ($i = 0, $match = null; $i < 9 && $this->consume() !== false; $i++)
  5503. {
  5504. $consumed = substr($this->consumed, 1);
  5505. if (isset($entities[$consumed]))
  5506. {
  5507. $match = $consumed;
  5508. }
  5509. }
  5510. if ($match !== null)
  5511. {
  5512. $this->data = substr_replace($this->data, $entities[$match], $this->position - strlen($consumed) - 1, strlen($match) + 1);
  5513. $this->position += strlen($entities[$match]) - strlen($consumed) - 1;
  5514. }
  5515. break;
  5516. }
  5517. }
  5518. }
  5519. /**
  5520. * Handles everything related to enclosures (including Media RSS and iTunes RSS)
  5521. *
  5522. * Used by {@see SimplePie_Item::get_enclosure()} and {@see SimplePie_Item::get_enclosures()}
  5523. *
  5524. * This class can be overloaded with {@see SimplePie::set_enclosure_class()}
  5525. *
  5526. * @package SimplePie
  5527. * @subpackage API
  5528. */
  5529. class SimplePie_Enclosure
  5530. {
  5531. /**
  5532. * @var string
  5533. * @see get_bitrate()
  5534. */
  5535. var $bitrate;
  5536. /**
  5537. * @var array
  5538. * @see get_captions()
  5539. */
  5540. var $captions;
  5541. /**
  5542. * @var array
  5543. * @see get_categories()
  5544. */
  5545. var $categories;
  5546. /**
  5547. * @var int
  5548. * @see get_channels()
  5549. */
  5550. var $channels;
  5551. /**
  5552. * @var SimplePie_Copyright
  5553. * @see get_copyright()
  5554. */
  5555. var $copyright;
  5556. /**
  5557. * @var array
  5558. * @see get_credits()
  5559. */
  5560. var $credits;
  5561. /**
  5562. * @var string
  5563. * @see get_description()
  5564. */
  5565. var $description;
  5566. /**
  5567. * @var int
  5568. * @see get_duration()
  5569. */
  5570. var $duration;
  5571. /**
  5572. * @var string
  5573. * @see get_expression()
  5574. */
  5575. var $expression;
  5576. /**
  5577. * @var string
  5578. * @see get_framerate()
  5579. */
  5580. var $framerate;
  5581. /**
  5582. * @var string
  5583. * @see get_handler()
  5584. */
  5585. var $handler;
  5586. /**
  5587. * @var array
  5588. * @see get_hashes()
  5589. */
  5590. var $hashes;
  5591. /**
  5592. * @var string
  5593. * @see get_height()
  5594. */
  5595. var $height;
  5596. /**
  5597. * @deprecated
  5598. * @var null
  5599. */
  5600. var $javascript;
  5601. /**
  5602. * @var array
  5603. * @see get_keywords()
  5604. */
  5605. var $keywords;
  5606. /**
  5607. * @var string
  5608. * @see get_language()
  5609. */
  5610. var $lang;
  5611. /**
  5612. * @var string
  5613. * @see get_length()
  5614. */
  5615. var $length;
  5616. /**
  5617. * @var string
  5618. * @see get_link()
  5619. */
  5620. var $link;
  5621. /**
  5622. * @var string
  5623. * @see get_medium()
  5624. */
  5625. var $medium;
  5626. /**
  5627. * @var string
  5628. * @see get_player()
  5629. */
  5630. var $player;
  5631. /**
  5632. * @var array
  5633. * @see get_ratings()
  5634. */
  5635. var $ratings;
  5636. /**
  5637. * @var array
  5638. * @see get_restrictions()
  5639. */
  5640. var $restrictions;
  5641. /**
  5642. * @var string
  5643. * @see get_sampling_rate()
  5644. */
  5645. var $samplingrate;
  5646. /**
  5647. * @var array
  5648. * @see get_thumbnails()
  5649. */
  5650. var $thumbnails;
  5651. /**
  5652. * @var string
  5653. * @see get_title()
  5654. */
  5655. var $title;
  5656. /**
  5657. * @var string
  5658. * @see get_type()
  5659. */
  5660. var $type;
  5661. /**
  5662. * @var string
  5663. * @see get_width()
  5664. */
  5665. var $width;
  5666. /**
  5667. * Constructor, used to input the data
  5668. *
  5669. * For documentation on all the parameters, see the corresponding
  5670. * properties and their accessors
  5671. *
  5672. * @uses idna_convert If available, this will convert an IDN
  5673. */
  5674. public function __construct($link = null, $type = null, $length = null, $javascript = null, $bitrate = null, $captions = null, $categories = null, $channels = null, $copyright = null, $credits = null, $description = null, $duration = null, $expression = null, $framerate = null, $hashes = null, $height = null, $keywords = null, $lang = null, $medium = null, $player = null, $ratings = null, $restrictions = null, $samplingrate = null, $thumbnails = null, $title = null, $width = null)
  5675. {
  5676. $this->bitrate = $bitrate;
  5677. $this->captions = $captions;
  5678. $this->categories = $categories;
  5679. $this->channels = $channels;
  5680. $this->copyright = $copyright;
  5681. $this->credits = $credits;
  5682. $this->description = $description;
  5683. $this->duration = $duration;
  5684. $this->expression = $expression;
  5685. $this->framerate = $framerate;
  5686. $this->hashes = $hashes;
  5687. $this->height = $height;
  5688. $this->keywords = $keywords;
  5689. $this->lang = $lang;
  5690. $this->length = $length;
  5691. $this->link = $link;
  5692. $this->medium = $medium;
  5693. $this->player = $player;
  5694. $this->ratings = $ratings;
  5695. $this->restrictions = $restrictions;
  5696. $this->samplingrate = $samplingrate;
  5697. $this->thumbnails = $thumbnails;
  5698. $this->title = $title;
  5699. $this->type = $type;
  5700. $this->width = $width;
  5701. if (class_exists('idna_convert'))
  5702. {
  5703. $idn = new idna_convert();
  5704. $parsed = SimplePie_Misc::parse_url($link);
  5705. $this->link = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
  5706. }
  5707. $this->handler = $this->get_handler(); // Needs to load last
  5708. }
  5709. /**
  5710. * String-ified version
  5711. *
  5712. * @return string
  5713. */
  5714. public function __toString()
  5715. {
  5716. // There is no $this->data here
  5717. return md5(serialize($this));
  5718. }
  5719. /**
  5720. * Get the bitrate
  5721. *
  5722. * @return string|null
  5723. */
  5724. public function get_bitrate()
  5725. {
  5726. if ($this->bitrate !== null)
  5727. {
  5728. return $this->bitrate;
  5729. }
  5730. else
  5731. {
  5732. return null;
  5733. }
  5734. }
  5735. /**
  5736. * Get a single caption
  5737. *
  5738. * @param int $key
  5739. * @return SimplePie_Caption|null
  5740. */
  5741. public function get_caption($key = 0)
  5742. {
  5743. $captions = $this->get_captions();
  5744. if (isset($captions[$key]))
  5745. {
  5746. return $captions[$key];
  5747. }
  5748. else
  5749. {
  5750. return null;
  5751. }
  5752. }
  5753. /**
  5754. * Get all captions
  5755. *
  5756. * @return array|null Array of {@see SimplePie_Caption} objects
  5757. */
  5758. public function get_captions()
  5759. {
  5760. if ($this->captions !== null)
  5761. {
  5762. return $this->captions;
  5763. }
  5764. else
  5765. {
  5766. return null;
  5767. }
  5768. }
  5769. /**
  5770. * Get a single category
  5771. *
  5772. * @param int $key
  5773. * @return SimplePie_Category|null
  5774. */
  5775. public function get_category($key = 0)
  5776. {
  5777. $categories = $this->get_categories();
  5778. if (isset($categories[$key]))
  5779. {
  5780. return $categories[$key];
  5781. }
  5782. else
  5783. {
  5784. return null;
  5785. }
  5786. }
  5787. /**
  5788. * Get all categories
  5789. *
  5790. * @return array|null Array of {@see SimplePie_Category} objects
  5791. */
  5792. public function get_categories()
  5793. {
  5794. if ($this->categories !== null)
  5795. {
  5796. return $this->categories;
  5797. }
  5798. else
  5799. {
  5800. return null;
  5801. }
  5802. }
  5803. /**
  5804. * Get the number of audio channels
  5805. *
  5806. * @return int|null
  5807. */
  5808. public function get_channels()
  5809. {
  5810. if ($this->channels !== null)
  5811. {
  5812. return $this->channels;
  5813. }
  5814. else
  5815. {
  5816. return null;
  5817. }
  5818. }
  5819. /**
  5820. * Get the copyright information
  5821. *
  5822. * @return SimplePie_Copyright|null
  5823. */
  5824. public function get_copyright()
  5825. {
  5826. if ($this->copyright !== null)
  5827. {
  5828. return $this->copyright;
  5829. }
  5830. else
  5831. {
  5832. return null;
  5833. }
  5834. }
  5835. /**
  5836. * Get a single credit
  5837. *
  5838. * @param int $key
  5839. * @return SimplePie_Credit|null
  5840. */
  5841. public function get_credit($key = 0)
  5842. {
  5843. $credits = $this->get_credits();
  5844. if (isset($credits[$key]))
  5845. {
  5846. return $credits[$key];
  5847. }
  5848. else
  5849. {
  5850. return null;
  5851. }
  5852. }
  5853. /**
  5854. * Get all credits
  5855. *
  5856. * @return array|null Array of {@see SimplePie_Credit} objects
  5857. */
  5858. public function get_credits()
  5859. {
  5860. if ($this->credits !== null)
  5861. {
  5862. return $this->credits;
  5863. }
  5864. else
  5865. {
  5866. return null;
  5867. }
  5868. }
  5869. /**
  5870. * Get the description of the enclosure
  5871. *
  5872. * @return string|null
  5873. */
  5874. public function get_description()
  5875. {
  5876. if ($this->description !== null)
  5877. {
  5878. return $this->description;
  5879. }
  5880. else
  5881. {
  5882. return null;
  5883. }
  5884. }
  5885. /**
  5886. * Get the duration of the enclosure
  5887. *
  5888. * @param bool $convert Convert seconds into hh:mm:ss
  5889. * @return string|int|null 'hh:mm:ss' string if `$convert` was specified, otherwise integer (or null if none found)
  5890. */
  5891. public function get_duration($convert = false)
  5892. {
  5893. if ($this->duration !== null)
  5894. {
  5895. if ($convert)
  5896. {
  5897. $time = SimplePie_Misc::time_hms($this->duration);
  5898. return $time;
  5899. }
  5900. else
  5901. {
  5902. return $this->duration;
  5903. }
  5904. }
  5905. else
  5906. {
  5907. return null;
  5908. }
  5909. }
  5910. /**
  5911. * Get the expression
  5912. *
  5913. * @return string Probably one of 'sample', 'full', 'nonstop', 'clip'. Defaults to 'full'
  5914. */
  5915. public function get_expression()
  5916. {
  5917. if ($this->expression !== null)
  5918. {
  5919. return $this->expression;
  5920. }
  5921. else
  5922. {
  5923. return 'full';
  5924. }
  5925. }
  5926. /**
  5927. * Get the file extension
  5928. *
  5929. * @return string|null
  5930. */
  5931. public function get_extension()
  5932. {
  5933. if ($this->link !== null)
  5934. {
  5935. $url = SimplePie_Misc::parse_url($this->link);
  5936. if ($url['path'] !== '')
  5937. {
  5938. return pathinfo($url['path'], PATHINFO_EXTENSION);
  5939. }
  5940. }
  5941. return null;
  5942. }
  5943. /**
  5944. * Get the framerate (in frames-per-second)
  5945. *
  5946. * @return string|null
  5947. */
  5948. public function get_framerate()
  5949. {
  5950. if ($this->framerate !== null)
  5951. {
  5952. return $this->framerate;
  5953. }
  5954. else
  5955. {
  5956. return null;
  5957. }
  5958. }
  5959. /**
  5960. * Get the preferred handler
  5961. *
  5962. * @return string|null One of 'flash', 'fmedia', 'quicktime', 'wmedia', 'mp3'
  5963. */
  5964. public function get_handler()
  5965. {
  5966. return $this->get_real_type(true);
  5967. }
  5968. /**
  5969. * Get a single hash
  5970. *
  5971. * @link http://www.rssboard.org/media-rss#media-hash
  5972. * @param int $key
  5973. * @return string|null Hash as per `media:hash`, prefixed with "$algo:"
  5974. */
  5975. public function get_hash($key = 0)
  5976. {
  5977. $hashes = $this->get_hashes();
  5978. if (isset($hashes[$key]))
  5979. {
  5980. return $hashes[$key];
  5981. }
  5982. else
  5983. {
  5984. return null;
  5985. }
  5986. }
  5987. /**
  5988. * Get all credits
  5989. *
  5990. * @return array|null Array of strings, see {@see get_hash()}
  5991. */
  5992. public function get_hashes()
  5993. {
  5994. if ($this->hashes !== null)
  5995. {
  5996. return $this->hashes;
  5997. }
  5998. else
  5999. {
  6000. return null;
  6001. }
  6002. }
  6003. /**
  6004. * Get the height
  6005. *
  6006. * @return string|null
  6007. */
  6008. public function get_height()
  6009. {
  6010. if ($this->height !== null)
  6011. {
  6012. return $this->height;
  6013. }
  6014. else
  6015. {
  6016. return null;
  6017. }
  6018. }
  6019. /**
  6020. * Get the language
  6021. *
  6022. * @link http://tools.ietf.org/html/rfc3066
  6023. * @return string|null Language code as per RFC 3066
  6024. */
  6025. public function get_language()
  6026. {
  6027. if ($this->lang !== null)
  6028. {
  6029. return $this->lang;
  6030. }
  6031. else
  6032. {
  6033. return null;
  6034. }
  6035. }
  6036. /**
  6037. * Get a single keyword
  6038. *
  6039. * @param int $key
  6040. * @return string|null
  6041. */
  6042. public function get_keyword($key = 0)
  6043. {
  6044. $keywords = $this->get_keywords();
  6045. if (isset($keywords[$key]))
  6046. {
  6047. return $keywords[$key];
  6048. }
  6049. else
  6050. {
  6051. return null;
  6052. }
  6053. }
  6054. /**
  6055. * Get all keywords
  6056. *
  6057. * @return array|null Array of strings
  6058. */
  6059. public function get_keywords()
  6060. {
  6061. if ($this->keywords !== null)
  6062. {
  6063. return $this->keywords;
  6064. }
  6065. else
  6066. {
  6067. return null;
  6068. }
  6069. }
  6070. /**
  6071. * Get length
  6072. *
  6073. * @return float Length in bytes
  6074. */
  6075. public function get_length()
  6076. {
  6077. if ($this->length !== null)
  6078. {
  6079. return $this->length;
  6080. }
  6081. else
  6082. {
  6083. return null;
  6084. }
  6085. }
  6086. /**
  6087. * Get the URL
  6088. *
  6089. * @return string|null
  6090. */
  6091. public function get_link()
  6092. {
  6093. if ($this->link !== null)
  6094. {
  6095. return urldecode($this->link);
  6096. }
  6097. else
  6098. {
  6099. return null;
  6100. }
  6101. }
  6102. /**
  6103. * Get the medium
  6104. *
  6105. * @link http://www.rssboard.org/media-rss#media-content
  6106. * @return string|null Should be one of 'image', 'audio', 'video', 'document', 'executable'
  6107. */
  6108. public function get_medium()
  6109. {
  6110. if ($this->medium !== null)
  6111. {
  6112. return $this->medium;
  6113. }
  6114. else
  6115. {
  6116. return null;
  6117. }
  6118. }
  6119. /**
  6120. * Get the player URL
  6121. *
  6122. * Typically the same as {@see get_permalink()}
  6123. * @return string|null Player URL
  6124. */
  6125. public function get_player()
  6126. {
  6127. if ($this->player !== null)
  6128. {
  6129. return $this->player;
  6130. }
  6131. else
  6132. {
  6133. return null;
  6134. }
  6135. }
  6136. /**
  6137. * Get a single rating
  6138. *
  6139. * @param int $key
  6140. * @return SimplePie_Rating|null
  6141. */
  6142. public function get_rating($key = 0)
  6143. {
  6144. $ratings = $this->get_ratings();
  6145. if (isset($ratings[$key]))
  6146. {
  6147. return $ratings[$key];
  6148. }
  6149. else
  6150. {
  6151. return null;
  6152. }
  6153. }
  6154. /**
  6155. * Get all ratings
  6156. *
  6157. * @return array|null Array of {@see SimplePie_Rating} objects
  6158. */
  6159. public function get_ratings()
  6160. {
  6161. if ($this->ratings !== null)
  6162. {
  6163. return $this->ratings;
  6164. }
  6165. else
  6166. {
  6167. return null;
  6168. }
  6169. }
  6170. /**
  6171. * Get a single restriction
  6172. *
  6173. * @param int $key
  6174. * @return SimplePie_Restriction|null
  6175. */
  6176. public function get_restriction($key = 0)
  6177. {
  6178. $restrictions = $this->get_restrictions();
  6179. if (isset($restrictions[$key]))
  6180. {
  6181. return $restrictions[$key];
  6182. }
  6183. else
  6184. {
  6185. return null;
  6186. }
  6187. }
  6188. /**
  6189. * Get all restrictions
  6190. *
  6191. * @return array|null Array of {@see SimplePie_Restriction} objects
  6192. */
  6193. public function get_restrictions()
  6194. {
  6195. if ($this->restrictions !== null)
  6196. {
  6197. return $this->restrictions;
  6198. }
  6199. else
  6200. {
  6201. return null;
  6202. }
  6203. }
  6204. /**
  6205. * Get the sampling rate (in kHz)
  6206. *
  6207. * @return string|null
  6208. */
  6209. public function get_sampling_rate()
  6210. {
  6211. if ($this->samplingrate !== null)
  6212. {
  6213. return $this->samplingrate;
  6214. }
  6215. else
  6216. {
  6217. return null;
  6218. }
  6219. }
  6220. /**
  6221. * Get the file size (in MiB)
  6222. *
  6223. * @return float|null File size in mebibytes (1048 bytes)
  6224. */
  6225. public function get_size()
  6226. {
  6227. $length = $this->get_length();
  6228. if ($length !== null)
  6229. {
  6230. return round($length/1048576, 2);
  6231. }
  6232. else
  6233. {
  6234. return null;
  6235. }
  6236. }
  6237. /**
  6238. * Get a single thumbnail
  6239. *
  6240. * @param int $key
  6241. * @return string|null Thumbnail URL
  6242. */
  6243. public function get_thumbnail($key = 0)
  6244. {
  6245. $thumbnails = $this->get_thumbnails();
  6246. if (isset($thumbnails[$key]))
  6247. {
  6248. return $thumbnails[$key];
  6249. }
  6250. else
  6251. {
  6252. return null;
  6253. }
  6254. }
  6255. /**
  6256. * Get all thumbnails
  6257. *
  6258. * @return array|null Array of thumbnail URLs
  6259. */
  6260. public function get_thumbnails()
  6261. {
  6262. if ($this->thumbnails !== null)
  6263. {
  6264. return $this->thumbnails;
  6265. }
  6266. else
  6267. {
  6268. return null;
  6269. }
  6270. }
  6271. /**
  6272. * Get the title
  6273. *
  6274. * @return string|null
  6275. */
  6276. public function get_title()
  6277. {
  6278. if ($this->title !== null)
  6279. {
  6280. return $this->title;
  6281. }
  6282. else
  6283. {
  6284. return null;
  6285. }
  6286. }
  6287. /**
  6288. * Get mimetype of the enclosure
  6289. *
  6290. * @see get_real_type()
  6291. * @return string|null MIME type
  6292. */
  6293. public function get_type()
  6294. {
  6295. if ($this->type !== null)
  6296. {
  6297. return $this->type;
  6298. }
  6299. else
  6300. {
  6301. return null;
  6302. }
  6303. }
  6304. /**
  6305. * Get the width
  6306. *
  6307. * @return string|null
  6308. */
  6309. public function get_width()
  6310. {
  6311. if ($this->width !== null)
  6312. {
  6313. return $this->width;
  6314. }
  6315. else
  6316. {
  6317. return null;
  6318. }
  6319. }
  6320. /**
  6321. * Embed the enclosure using `<embed>`
  6322. *
  6323. * @deprecated Use the second parameter to {@see embed} instead
  6324. *
  6325. * @param array|string $options See first paramter to {@see embed}
  6326. * @return string HTML string to output
  6327. */
  6328. public function native_embed($options='')
  6329. {
  6330. return $this->embed($options, true);
  6331. }
  6332. /**
  6333. * Embed the enclosure using Javascript
  6334. *
  6335. * `$options` is an array or comma-separated key:value string, with the
  6336. * following properties:
  6337. *
  6338. * - `alt` (string): Alternate content for when an end-user does not have
  6339. * the appropriate handler installed or when a file type is
  6340. * unsupported. Can be any text or HTML. Defaults to blank.
  6341. * - `altclass` (string): If a file type is unsupported, the end-user will
  6342. * see the alt text (above) linked directly to the content. That link
  6343. * will have this value as its class name. Defaults to blank.
  6344. * - `audio` (string): This is an image that should be used as a
  6345. * placeholder for audio files before they're loaded (QuickTime-only).
  6346. * Can be any relative or absolute URL. Defaults to blank.
  6347. * - `bgcolor` (string): The background color for the media, if not
  6348. * already transparent. Defaults to `#ffffff`.
  6349. * - `height` (integer): The height of the embedded media. Accepts any
  6350. * numeric pixel value (such as `360`) or `auto`. Defaults to `auto`,
  6351. * and it is recommended that you use this default.
  6352. * - `loop` (boolean): Do you want the media to loop when it's done?
  6353. * Defaults to `false`.
  6354. * - `mediaplayer` (string): The location of the included
  6355. * `mediaplayer.swf` file. This allows for the playback of Flash Video
  6356. * (`.flv`) files, and is the default handler for non-Odeo MP3's.
  6357. * Defaults to blank.
  6358. * - `video` (string): This is an image that should be used as a
  6359. * placeholder for video files before they're loaded (QuickTime-only).
  6360. * Can be any relative or absolute URL. Defaults to blank.
  6361. * - `width` (integer): The width of the embedded media. Accepts any
  6362. * numeric pixel value (such as `480`) or `auto`. Defaults to `auto`,
  6363. * and it is recommended that you use this default.
  6364. * - `widescreen` (boolean): Is the enclosure widescreen or standard?
  6365. * This applies only to video enclosures, and will automatically resize
  6366. * the content appropriately. Defaults to `false`, implying 4:3 mode.
  6367. *
  6368. * Note: Non-widescreen (4:3) mode with `width` and `height` set to `auto`
  6369. * will default to 480x360 video resolution. Widescreen (16:9) mode with
  6370. * `width` and `height` set to `auto` will default to 480x270 video resolution.
  6371. *
  6372. * @todo If the dimensions for media:content are defined, use them when width/height are set to 'auto'.
  6373. * @param array|string $options Comma-separated key:value list, or array
  6374. * @param bool $native Use `<embed>`
  6375. * @return string HTML string to output
  6376. */
  6377. public function embed($options = '', $native = false)
  6378. {
  6379. // Set up defaults
  6380. $audio = '';
  6381. $video = '';
  6382. $alt = '';
  6383. $altclass = '';
  6384. $loop = 'false';
  6385. $width = 'auto';
  6386. $height = 'auto';
  6387. $bgcolor = '#ffffff';
  6388. $mediaplayer = '';
  6389. $widescreen = false;
  6390. $handler = $this->get_handler();
  6391. $type = $this->get_real_type();
  6392. // Process options and reassign values as necessary
  6393. if (is_array($options))
  6394. {
  6395. extract($options);
  6396. }
  6397. else
  6398. {
  6399. $options = explode(',', $options);
  6400. foreach($options as $option)
  6401. {
  6402. $opt = explode(':', $option, 2);
  6403. if (isset($opt[0], $opt[1]))
  6404. {
  6405. $opt[0] = trim($opt[0]);
  6406. $opt[1] = trim($opt[1]);
  6407. switch ($opt[0])
  6408. {
  6409. case 'audio':
  6410. $audio = $opt[1];
  6411. break;
  6412. case 'video':
  6413. $video = $opt[1];
  6414. break;
  6415. case 'alt':
  6416. $alt = $opt[1];
  6417. break;
  6418. case 'altclass':
  6419. $altclass = $opt[1];
  6420. break;
  6421. case 'loop':
  6422. $loop = $opt[1];
  6423. break;
  6424. case 'width':
  6425. $width = $opt[1];
  6426. break;
  6427. case 'height':
  6428. $height = $opt[1];
  6429. break;
  6430. case 'bgcolor':
  6431. $bgcolor = $opt[1];
  6432. break;
  6433. case 'mediaplayer':
  6434. $mediaplayer = $opt[1];
  6435. break;
  6436. case 'widescreen':
  6437. $widescreen = $opt[1];
  6438. break;
  6439. }
  6440. }
  6441. }
  6442. }
  6443. $mime = explode('/', $type, 2);
  6444. $mime = $mime[0];
  6445. // Process values for 'auto'
  6446. if ($width === 'auto')
  6447. {
  6448. if ($mime === 'video')
  6449. {
  6450. if ($height === 'auto')
  6451. {
  6452. $width = 480;
  6453. }
  6454. elseif ($widescreen)
  6455. {
  6456. $width = round((intval($height)/9)*16);
  6457. }
  6458. else
  6459. {
  6460. $width = round((intval($height)/3)*4);
  6461. }
  6462. }
  6463. else
  6464. {
  6465. $width = '100%';
  6466. }
  6467. }
  6468. if ($height === 'auto')
  6469. {
  6470. if ($mime === 'audio')
  6471. {
  6472. $height = 0;
  6473. }
  6474. elseif ($mime === 'video')
  6475. {
  6476. if ($width === 'auto')
  6477. {
  6478. if ($widescreen)
  6479. {
  6480. $height = 270;
  6481. }
  6482. else
  6483. {
  6484. $height = 360;
  6485. }
  6486. }
  6487. elseif ($widescreen)
  6488. {
  6489. $height = round((intval($width)/16)*9);
  6490. }
  6491. else
  6492. {
  6493. $height = round((intval($width)/4)*3);
  6494. }
  6495. }
  6496. else
  6497. {
  6498. $height = 376;
  6499. }
  6500. }
  6501. elseif ($mime === 'audio')
  6502. {
  6503. $height = 0;
  6504. }
  6505. // Set proper placeholder value
  6506. if ($mime === 'audio')
  6507. {
  6508. $placeholder = $audio;
  6509. }
  6510. elseif ($mime === 'video')
  6511. {
  6512. $placeholder = $video;
  6513. }
  6514. $embed = '';
  6515. // Flash
  6516. if ($handler === 'flash')
  6517. {
  6518. if ($native)
  6519. {
  6520. $embed .= "<embed src=\"" . $this->get_link() . "\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"$type\" quality=\"high\" width=\"$width\" height=\"$height\" bgcolor=\"$bgcolor\" loop=\"$loop\"></embed>";
  6521. }
  6522. else
  6523. {
  6524. $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>";
  6525. }
  6526. }
  6527. // Flash Media Player file types.
  6528. // Preferred handler for MP3 file types.
  6529. elseif ($handler === 'fmedia' || ($handler === 'mp3' && $mediaplayer !== ''))
  6530. {
  6531. $height += 20;
  6532. if ($native)
  6533. {
  6534. $embed .= "<embed src=\"$mediaplayer\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" quality=\"high\" width=\"$width\" height=\"$height\" wmode=\"transparent\" flashvars=\"file=" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "&autostart=false&repeat=$loop&showdigits=true&showfsbutton=false\"></embed>";
  6535. }
  6536. else
  6537. {
  6538. $embed .= "<script type='text/javascript'>embed_flv('$width', '$height', '" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "', '$placeholder', '$loop', '$mediaplayer');</script>";
  6539. }
  6540. }
  6541. // QuickTime 7 file types. Need to test with QuickTime 6.
  6542. // Only handle MP3's if the Flash Media Player is not present.
  6543. elseif ($handler === 'quicktime' || ($handler === 'mp3' && $mediaplayer === ''))
  6544. {
  6545. $height += 16;
  6546. if ($native)
  6547. {
  6548. if ($placeholder !== '')
  6549. {
  6550. $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://apple.com/quicktime/download/\"></embed>";
  6551. }
  6552. else
  6553. {
  6554. $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://apple.com/quicktime/download/\"></embed>";
  6555. }
  6556. }
  6557. else
  6558. {
  6559. $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>";
  6560. }
  6561. }
  6562. // Windows Media
  6563. elseif ($handler === 'wmedia')
  6564. {
  6565. $height += 45;
  6566. if ($native)
  6567. {
  6568. $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>";
  6569. }
  6570. else
  6571. {
  6572. $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>";
  6573. }
  6574. }
  6575. // Everything else
  6576. else $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>';
  6577. return $embed;
  6578. }
  6579. /**
  6580. * Get the real media type
  6581. *
  6582. * Often, feeds lie to us, necessitating a bit of deeper inspection. This
  6583. * converts types to their canonical representations based on the file
  6584. * extension
  6585. *
  6586. * @see get_type()
  6587. * @param bool $find_handler Internal use only, use {@see get_handler()} instead
  6588. * @return string MIME type
  6589. */
  6590. public function get_real_type($find_handler = false)
  6591. {
  6592. // Mime-types by handler.
  6593. $types_flash = array('application/x-shockwave-flash', 'application/futuresplash'); // Flash
  6594. $types_fmedia = array('video/flv', 'video/x-flv','flv-application/octet-stream'); // Flash Media Player
  6595. $types_quicktime = array('audio/3gpp', 'audio/3gpp2', 'audio/aac', 'audio/x-aac', 'audio/aiff', 'audio/x-aiff', 'audio/mid', 'audio/midi', 'audio/x-midi', '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'); // QuickTime
  6596. $types_wmedia = 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'); // Windows Media
  6597. $types_mp3 = array('audio/mp3', 'audio/x-mp3', 'audio/mpeg', 'audio/x-mpeg'); // MP3
  6598. if ($this->get_type() !== null)
  6599. {
  6600. $type = strtolower($this->type);
  6601. }
  6602. else
  6603. {
  6604. $type = null;
  6605. }
  6606. // If we encounter an unsupported mime-type, check the file extension and guess intelligently.
  6607. if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3)))
  6608. {
  6609. switch (strtolower($this->get_extension()))
  6610. {
  6611. // Audio mime-types
  6612. case 'aac':
  6613. case 'adts':
  6614. $type = 'audio/acc';
  6615. break;
  6616. case 'aif':
  6617. case 'aifc':
  6618. case 'aiff':
  6619. case 'cdda':
  6620. $type = 'audio/aiff';
  6621. break;
  6622. case 'bwf':
  6623. $type = 'audio/wav';
  6624. break;
  6625. case 'kar':
  6626. case 'mid':
  6627. case 'midi':
  6628. case 'smf':
  6629. $type = 'audio/midi';
  6630. break;
  6631. case 'm4a':
  6632. $type = 'audio/x-m4a';
  6633. break;
  6634. case 'mp3':
  6635. case 'swa':
  6636. $type = 'audio/mp3';
  6637. break;
  6638. case 'wav':
  6639. $type = 'audio/wav';
  6640. break;
  6641. case 'wax':
  6642. $type = 'audio/x-ms-wax';
  6643. break;
  6644. case 'wma':
  6645. $type = 'audio/x-ms-wma';
  6646. break;
  6647. // Video mime-types
  6648. case '3gp':
  6649. case '3gpp':
  6650. $type = 'video/3gpp';
  6651. break;
  6652. case '3g2':
  6653. case '3gp2':
  6654. $type = 'video/3gpp2';
  6655. break;
  6656. case 'asf':
  6657. $type = 'video/x-ms-asf';
  6658. break;
  6659. case 'flv':
  6660. $type = 'video/x-flv';
  6661. break;
  6662. case 'm1a':
  6663. case 'm1s':
  6664. case 'm1v':
  6665. case 'm15':
  6666. case 'm75':
  6667. case 'mp2':
  6668. case 'mpa':
  6669. case 'mpeg':
  6670. case 'mpg':
  6671. case 'mpm':
  6672. case 'mpv':
  6673. $type = 'video/mpeg';
  6674. break;
  6675. case 'm4v':
  6676. $type = 'video/x-m4v';
  6677. break;
  6678. case 'mov':
  6679. case 'qt':
  6680. $type = 'video/quicktime';
  6681. break;
  6682. case 'mp4':
  6683. case 'mpg4':
  6684. $type = 'video/mp4';
  6685. break;
  6686. case 'sdv':
  6687. $type = 'video/sd-video';
  6688. break;
  6689. case 'wm':
  6690. $type = 'video/x-ms-wm';
  6691. break;
  6692. case 'wmv':
  6693. $type = 'video/x-ms-wmv';
  6694. break;
  6695. case 'wvx':
  6696. $type = 'video/x-ms-wvx';
  6697. break;
  6698. // Flash mime-types
  6699. case 'spl':
  6700. $type = 'application/futuresplash';
  6701. break;
  6702. case 'swf':
  6703. $type = 'application/x-shockwave-flash';
  6704. break;
  6705. }
  6706. }
  6707. if ($find_handler)
  6708. {
  6709. if (in_array($type, $types_flash))
  6710. {
  6711. return 'flash';
  6712. }
  6713. elseif (in_array($type, $types_fmedia))
  6714. {
  6715. return 'fmedia';
  6716. }
  6717. elseif (in_array($type, $types_quicktime))
  6718. {
  6719. return 'quicktime';
  6720. }
  6721. elseif (in_array($type, $types_wmedia))
  6722. {
  6723. return 'wmedia';
  6724. }
  6725. elseif (in_array($type, $types_mp3))
  6726. {
  6727. return 'mp3';
  6728. }
  6729. else
  6730. {
  6731. return null;
  6732. }
  6733. }
  6734. else
  6735. {
  6736. return $type;
  6737. }
  6738. }
  6739. }
  6740. /**
  6741. * General SimplePie exception class
  6742. *
  6743. * @package SimplePie
  6744. */
  6745. class SimplePie_Exception extends Exception
  6746. {
  6747. }
  6748. /**
  6749. * Used for fetching remote files and reading local files
  6750. *
  6751. * Supports HTTP 1.0 via cURL or fsockopen, with spotty HTTP 1.1 support
  6752. *
  6753. * This class can be overloaded with {@see SimplePie::set_file_class()}
  6754. *
  6755. * @package SimplePie
  6756. * @subpackage HTTP
  6757. * @todo Move to properly supporting RFC2616 (HTTP/1.1)
  6758. */
  6759. class SimplePie_File
  6760. {
  6761. var $url;
  6762. var $useragent;
  6763. var $success = true;
  6764. var $headers = array();
  6765. var $body;
  6766. var $status_code;
  6767. var $redirects = 0;
  6768. var $error;
  6769. var $method = SIMPLEPIE_FILE_SOURCE_NONE;
  6770. var $permanent_url;
  6771. public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false, $curl_options = array())
  6772. {
  6773. if (class_exists('idna_convert'))
  6774. {
  6775. $idn = new idna_convert();
  6776. $parsed = SimplePie_Misc::parse_url($url);
  6777. $url = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
  6778. }
  6779. $this->url = $url;
  6780. $this->permanent_url = $url;
  6781. $this->useragent = $useragent;
  6782. if (preg_match('/^http(s)?:\/\//i', $url))
  6783. {
  6784. if ($useragent === null)
  6785. {
  6786. $useragent = ini_get('user_agent');
  6787. $this->useragent = $useragent;
  6788. }
  6789. if (!is_array($headers))
  6790. {
  6791. $headers = array();
  6792. }
  6793. if (!$force_fsockopen && function_exists('curl_exec'))
  6794. {
  6795. $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_CURL;
  6796. $fp = curl_init();
  6797. $headers2 = array();
  6798. foreach ($headers as $key => $value)
  6799. {
  6800. $headers2[] = "$key: $value";
  6801. }
  6802. if (version_compare(SimplePie_Misc::get_curl_version(), '7.10.5', '>='))
  6803. {
  6804. curl_setopt($fp, CURLOPT_ENCODING, '');
  6805. }
  6806. curl_setopt($fp, CURLOPT_URL, $url);
  6807. curl_setopt($fp, CURLOPT_HEADER, 1);
  6808. curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
  6809. curl_setopt($fp, CURLOPT_FAILONERROR, 1);
  6810. curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
  6811. curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout);
  6812. curl_setopt($fp, CURLOPT_REFERER, $url);
  6813. curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
  6814. curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
  6815. if (!ini_get('open_basedir') && !ini_get('safe_mode') && version_compare(SimplePie_Misc::get_curl_version(), '7.15.2', '>='))
  6816. {
  6817. curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
  6818. curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
  6819. }
  6820. foreach ($curl_options as $curl_param => $curl_value) {
  6821. curl_setopt($fp, $curl_param, $curl_value);
  6822. }
  6823. $this->headers = curl_exec($fp);
  6824. if (curl_errno($fp) === 23 || curl_errno($fp) === 61)
  6825. {
  6826. curl_setopt($fp, CURLOPT_ENCODING, 'none');
  6827. $this->headers = curl_exec($fp);
  6828. }
  6829. if (curl_errno($fp))
  6830. {
  6831. $this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
  6832. $this->success = false;
  6833. }
  6834. else
  6835. {
  6836. // Use the updated url provided by curl_getinfo after any redirects.
  6837. if ($info = curl_getinfo($fp)) {
  6838. $this->url = $info['url'];
  6839. }
  6840. curl_close($fp);
  6841. $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 1);
  6842. $this->headers = array_pop($this->headers);
  6843. $parser = new SimplePie_HTTP_Parser($this->headers);
  6844. if ($parser->parse())
  6845. {
  6846. $this->headers = $parser->headers;
  6847. $this->body = trim($parser->body);
  6848. $this->status_code = $parser->status_code;
  6849. if ((in_array($this->status_code, array(300, 301, 302, 303, 307)) || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects)
  6850. {
  6851. $this->redirects++;
  6852. $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
  6853. $previousStatusCode = $this->status_code;
  6854. $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
  6855. $this->permanent_url = ($previousStatusCode == 301) ? $location : $url;
  6856. return;
  6857. }
  6858. }
  6859. }
  6860. }
  6861. else
  6862. {
  6863. $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_FSOCKOPEN;
  6864. $url_parts = parse_url($url);
  6865. $socket_host = $url_parts['host'];
  6866. if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https')
  6867. {
  6868. $socket_host = "ssl://$url_parts[host]";
  6869. $url_parts['port'] = 443;
  6870. }
  6871. if (!isset($url_parts['port']))
  6872. {
  6873. $url_parts['port'] = 80;
  6874. }
  6875. $fp = @fsockopen($socket_host, $url_parts['port'], $errno, $errstr, $timeout);
  6876. if (!$fp)
  6877. {
  6878. $this->error = 'fsockopen error: ' . $errstr;
  6879. $this->success = false;
  6880. }
  6881. else
  6882. {
  6883. stream_set_timeout($fp, $timeout);
  6884. if (isset($url_parts['path']))
  6885. {
  6886. if (isset($url_parts['query']))
  6887. {
  6888. $get = "$url_parts[path]?$url_parts[query]";
  6889. }
  6890. else
  6891. {
  6892. $get = $url_parts['path'];
  6893. }
  6894. }
  6895. else
  6896. {
  6897. $get = '/';
  6898. }
  6899. $out = "GET $get HTTP/1.1\r\n";
  6900. $out .= "Host: $url_parts[host]\r\n";
  6901. $out .= "User-Agent: $useragent\r\n";
  6902. if (extension_loaded('zlib'))
  6903. {
  6904. $out .= "Accept-Encoding: x-gzip,gzip,deflate\r\n";
  6905. }
  6906. if (isset($url_parts['user']) && isset($url_parts['pass']))
  6907. {
  6908. $out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
  6909. }
  6910. foreach ($headers as $key => $value)
  6911. {
  6912. $out .= "$key: $value\r\n";
  6913. }
  6914. $out .= "Connection: Close\r\n\r\n";
  6915. fwrite($fp, $out);
  6916. $info = stream_get_meta_data($fp);
  6917. $this->headers = '';
  6918. while (!$info['eof'] && !$info['timed_out'])
  6919. {
  6920. $this->headers .= fread($fp, 1160);
  6921. $info = stream_get_meta_data($fp);
  6922. }
  6923. if (!$info['timed_out'])
  6924. {
  6925. $parser = new SimplePie_HTTP_Parser($this->headers);
  6926. if ($parser->parse())
  6927. {
  6928. $this->headers = $parser->headers;
  6929. $this->body = $parser->body;
  6930. $this->status_code = $parser->status_code;
  6931. if ((in_array($this->status_code, array(300, 301, 302, 303, 307)) || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects)
  6932. {
  6933. $this->redirects++;
  6934. $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
  6935. $previousStatusCode = $this->status_code;
  6936. $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
  6937. $this->permanent_url = ($previousStatusCode == 301) ? $location : $url;
  6938. return;
  6939. }
  6940. if (isset($this->headers['content-encoding']))
  6941. {
  6942. // Hey, we act dumb elsewhere, so let's do that here too
  6943. switch (strtolower(trim($this->headers['content-encoding'], "\x09\x0A\x0D\x20")))
  6944. {
  6945. case 'gzip':
  6946. case 'x-gzip':
  6947. $decoder = new SimplePie_gzdecode($this->body);
  6948. if (!$decoder->parse())
  6949. {
  6950. $this->error = 'Unable to decode HTTP "gzip" stream';
  6951. $this->success = false;
  6952. }
  6953. else
  6954. {
  6955. $this->body = trim($decoder->data);
  6956. }
  6957. break;
  6958. case 'deflate':
  6959. if (($decompressed = gzinflate($this->body)) !== false)
  6960. {
  6961. $this->body = $decompressed;
  6962. }
  6963. else if (($decompressed = gzuncompress($this->body)) !== false)
  6964. {
  6965. $this->body = $decompressed;
  6966. }
  6967. else if (function_exists('gzdecode') && ($decompressed = gzdecode($this->body)) !== false)
  6968. {
  6969. $this->body = $decompressed;
  6970. }
  6971. else
  6972. {
  6973. $this->error = 'Unable to decode HTTP "deflate" stream';
  6974. $this->success = false;
  6975. }
  6976. break;
  6977. default:
  6978. $this->error = 'Unknown content coding';
  6979. $this->success = false;
  6980. }
  6981. }
  6982. }
  6983. }
  6984. else
  6985. {
  6986. $this->error = 'fsocket timed out';
  6987. $this->success = false;
  6988. }
  6989. fclose($fp);
  6990. }
  6991. }
  6992. }
  6993. else
  6994. {
  6995. $this->method = SIMPLEPIE_FILE_SOURCE_LOCAL | SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS;
  6996. if (empty($url) || !($this->body = trim(file_get_contents($url))))
  6997. {
  6998. $this->error = 'file_get_contents could not read the file';
  6999. $this->success = false;
  7000. }
  7001. }
  7002. }
  7003. }
  7004. /**
  7005. * HTTP Response Parser
  7006. *
  7007. * @package SimplePie
  7008. * @subpackage HTTP
  7009. */
  7010. class SimplePie_HTTP_Parser
  7011. {
  7012. /**
  7013. * HTTP Version
  7014. *
  7015. * @var float
  7016. */
  7017. public $http_version = 0.0;
  7018. /**
  7019. * Status code
  7020. *
  7021. * @var int
  7022. */
  7023. public $status_code = 0;
  7024. /**
  7025. * Reason phrase
  7026. *
  7027. * @var string
  7028. */
  7029. public $reason = '';
  7030. /**
  7031. * Key/value pairs of the headers
  7032. *
  7033. * @var array
  7034. */
  7035. public $headers = array();
  7036. /**
  7037. * Body of the response
  7038. *
  7039. * @var string
  7040. */
  7041. public $body = '';
  7042. /**
  7043. * Current state of the state machine
  7044. *
  7045. * @var string
  7046. */
  7047. protected $state = 'http_version';
  7048. /**
  7049. * Input data
  7050. *
  7051. * @var string
  7052. */
  7053. protected $data = '';
  7054. /**
  7055. * Input data length (to avoid calling strlen() everytime this is needed)
  7056. *
  7057. * @var int
  7058. */
  7059. protected $data_length = 0;
  7060. /**
  7061. * Current position of the pointer
  7062. *
  7063. * @var int
  7064. */
  7065. protected $position = 0;
  7066. /**
  7067. * Name of the hedaer currently being parsed
  7068. *
  7069. * @var string
  7070. */
  7071. protected $name = '';
  7072. /**
  7073. * Value of the hedaer currently being parsed
  7074. *
  7075. * @var string
  7076. */
  7077. protected $value = '';
  7078. /**
  7079. * Create an instance of the class with the input data
  7080. *
  7081. * @param string $data Input data
  7082. */
  7083. public function __construct($data)
  7084. {
  7085. $this->data = $data;
  7086. $this->data_length = strlen($this->data);
  7087. }
  7088. /**
  7089. * Parse the input data
  7090. *
  7091. * @return bool true on success, false on failure
  7092. */
  7093. public function parse()
  7094. {
  7095. while ($this->state && $this->state !== 'emit' && $this->has_data())
  7096. {
  7097. $state = $this->state;
  7098. $this->$state();
  7099. }
  7100. $this->data = '';
  7101. if ($this->state === 'emit' || $this->state === 'body')
  7102. {
  7103. return true;
  7104. }
  7105. else
  7106. {
  7107. $this->http_version = '';
  7108. $this->status_code = '';
  7109. $this->reason = '';
  7110. $this->headers = array();
  7111. $this->body = '';
  7112. return false;
  7113. }
  7114. }
  7115. /**
  7116. * Check whether there is data beyond the pointer
  7117. *
  7118. * @return bool true if there is further data, false if not
  7119. */
  7120. protected function has_data()
  7121. {
  7122. return (bool) ($this->position < $this->data_length);
  7123. }
  7124. /**
  7125. * See if the next character is LWS
  7126. *
  7127. * @return bool true if the next character is LWS, false if not
  7128. */
  7129. protected function is_linear_whitespace()
  7130. {
  7131. return (bool) ($this->data[$this->position] === "\x09"
  7132. || $this->data[$this->position] === "\x20"
  7133. || ($this->data[$this->position] === "\x0A"
  7134. && isset($this->data[$this->position + 1])
  7135. && ($this->data[$this->position + 1] === "\x09" || $this->data[$this->position + 1] === "\x20")));
  7136. }
  7137. /**
  7138. * Parse the HTTP version
  7139. */
  7140. protected function http_version()
  7141. {
  7142. if (strpos($this->data, "\x0A") !== false && strtoupper(substr($this->data, 0, 5)) === 'HTTP/')
  7143. {
  7144. $len = strspn($this->data, '0123456789.', 5);
  7145. $this->http_version = substr($this->data, 5, $len);
  7146. $this->position += 5 + $len;
  7147. if (substr_count($this->http_version, '.') <= 1)
  7148. {
  7149. $this->http_version = (float) $this->http_version;
  7150. $this->position += strspn($this->data, "\x09\x20", $this->position);
  7151. $this->state = 'status';
  7152. }
  7153. else
  7154. {
  7155. $this->state = false;
  7156. }
  7157. }
  7158. else
  7159. {
  7160. $this->state = false;
  7161. }
  7162. }
  7163. /**
  7164. * Parse the status code
  7165. */
  7166. protected function status()
  7167. {
  7168. if ($len = strspn($this->data, '0123456789', $this->position))
  7169. {
  7170. $this->status_code = (int) substr($this->data, $this->position, $len);
  7171. $this->position += $len;
  7172. $this->state = 'reason';
  7173. }
  7174. else
  7175. {
  7176. $this->state = false;
  7177. }
  7178. }
  7179. /**
  7180. * Parse the reason phrase
  7181. */
  7182. protected function reason()
  7183. {
  7184. $len = strcspn($this->data, "\x0A", $this->position);
  7185. $this->reason = trim(substr($this->data, $this->position, $len), "\x09\x0D\x20");
  7186. $this->position += $len + 1;
  7187. $this->state = 'new_line';
  7188. }
  7189. /**
  7190. * Deal with a new line, shifting data around as needed
  7191. */
  7192. protected function new_line()
  7193. {
  7194. $this->value = trim($this->value, "\x0D\x20");
  7195. if ($this->name !== '' && $this->value !== '')
  7196. {
  7197. $this->name = strtolower($this->name);
  7198. // We should only use the last Content-Type header. c.f. issue #1
  7199. if (isset($this->headers[$this->name]) && $this->name !== 'content-type')
  7200. {
  7201. $this->headers[$this->name] .= ', ' . $this->value;
  7202. }
  7203. else
  7204. {
  7205. $this->headers[$this->name] = $this->value;
  7206. }
  7207. }
  7208. $this->name = '';
  7209. $this->value = '';
  7210. if (substr($this->data[$this->position], 0, 2) === "\x0D\x0A")
  7211. {
  7212. $this->position += 2;
  7213. $this->state = 'body';
  7214. }
  7215. elseif ($this->data[$this->position] === "\x0A")
  7216. {
  7217. $this->position++;
  7218. $this->state = 'body';
  7219. }
  7220. else
  7221. {
  7222. $this->state = 'name';
  7223. }
  7224. }
  7225. /**
  7226. * Parse a header name
  7227. */
  7228. protected function name()
  7229. {
  7230. $len = strcspn($this->data, "\x0A:", $this->position);
  7231. if (isset($this->data[$this->position + $len]))
  7232. {
  7233. if ($this->data[$this->position + $len] === "\x0A")
  7234. {
  7235. $this->position += $len;
  7236. $this->state = 'new_line';
  7237. }
  7238. else
  7239. {
  7240. $this->name = substr($this->data, $this->position, $len);
  7241. $this->position += $len + 1;
  7242. $this->state = 'value';
  7243. }
  7244. }
  7245. else
  7246. {
  7247. $this->state = false;
  7248. }
  7249. }
  7250. /**
  7251. * Parse LWS, replacing consecutive LWS characters with a single space
  7252. */
  7253. protected function linear_whitespace()
  7254. {
  7255. do
  7256. {
  7257. if (substr($this->data, $this->position, 2) === "\x0D\x0A")
  7258. {
  7259. $this->position += 2;
  7260. }
  7261. elseif ($this->data[$this->position] === "\x0A")
  7262. {
  7263. $this->position++;
  7264. }
  7265. $this->position += strspn($this->data, "\x09\x20", $this->position);
  7266. } while ($this->has_data() && $this->is_linear_whitespace());
  7267. $this->value .= "\x20";
  7268. }
  7269. /**
  7270. * See what state to move to while within non-quoted header values
  7271. */
  7272. protected function value()
  7273. {
  7274. if ($this->is_linear_whitespace())
  7275. {
  7276. $this->linear_whitespace();
  7277. }
  7278. else
  7279. {
  7280. switch ($this->data[$this->position])
  7281. {
  7282. case '"':
  7283. // Workaround for ETags: we have to include the quotes as
  7284. // part of the tag.
  7285. if (strtolower($this->name) === 'etag')
  7286. {
  7287. $this->value .= '"';
  7288. $this->position++;
  7289. $this->state = 'value_char';
  7290. break;
  7291. }
  7292. $this->position++;
  7293. $this->state = 'quote';
  7294. break;
  7295. case "\x0A":
  7296. $this->position++;
  7297. $this->state = 'new_line';
  7298. break;
  7299. default:
  7300. $this->state = 'value_char';
  7301. break;
  7302. }
  7303. }
  7304. }
  7305. /**
  7306. * Parse a header value while outside quotes
  7307. */
  7308. protected function value_char()
  7309. {
  7310. $len = strcspn($this->data, "\x09\x20\x0A\"", $this->position);
  7311. $this->value .= substr($this->data, $this->position, $len);
  7312. $this->position += $len;
  7313. $this->state = 'value';
  7314. }
  7315. /**
  7316. * See what state to move to while within quoted header values
  7317. */
  7318. protected function quote()
  7319. {
  7320. if ($this->is_linear_whitespace())
  7321. {
  7322. $this->linear_whitespace();
  7323. }
  7324. else
  7325. {
  7326. switch ($this->data[$this->position])
  7327. {
  7328. case '"':
  7329. $this->position++;
  7330. $this->state = 'value';
  7331. break;
  7332. case "\x0A":
  7333. $this->position++;
  7334. $this->state = 'new_line';
  7335. break;
  7336. case '\\':
  7337. $this->position++;
  7338. $this->state = 'quote_escaped';
  7339. break;
  7340. default:
  7341. $this->state = 'quote_char';
  7342. break;
  7343. }