lib_simplepie.php 354 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584
  1. <?php
  2. /**
  3. * SimplePie
  4. *
  5. * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without modification, are
  9. * permitted provided that the following conditions are met:
  10. *
  11. * * Redistributions of source code must retain the above copyright notice, this list of
  12. * conditions and the following disclaimer.
  13. *
  14. * * Redistributions in binary form must reproduce the above copyright notice, this list
  15. * of conditions and the following disclaimer in the documentation and/or other materials
  16. * provided with the distribution.
  17. *
  18. * * Neither the name of the SimplePie Team nor the names of its contributors may be used
  19. * to endorse or promote products derived from this software without specific prior
  20. * written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  23. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  24. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
  25. * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. * POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. * @version 1.3
  33. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  34. */
  35. define('SIMPLEPIE_NAME', 'SimplePie');
  36. define('SIMPLEPIE_VERSION', '1.3');
  37. define('SIMPLEPIE_BUILD', '20120707113013');
  38. define('SIMPLEPIE_URL', 'http://simplepie.org');
  39. define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD);
  40. define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>');
  41. define('SIMPLEPIE_LOCATOR_NONE', 0);
  42. define('SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1);
  43. define('SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2);
  44. define('SIMPLEPIE_LOCATOR_LOCAL_BODY', 4);
  45. define('SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8);
  46. define('SIMPLEPIE_LOCATOR_REMOTE_BODY', 16);
  47. define('SIMPLEPIE_LOCATOR_ALL', 31);
  48. define('SIMPLEPIE_TYPE_NONE', 0);
  49. define('SIMPLEPIE_TYPE_RSS_090', 1);
  50. define('SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2);
  51. define('SIMPLEPIE_TYPE_RSS_091_USERLAND', 4);
  52. define('SIMPLEPIE_TYPE_RSS_091', 6);
  53. define('SIMPLEPIE_TYPE_RSS_092', 8);
  54. define('SIMPLEPIE_TYPE_RSS_093', 16);
  55. define('SIMPLEPIE_TYPE_RSS_094', 32);
  56. define('SIMPLEPIE_TYPE_RSS_10', 64);
  57. define('SIMPLEPIE_TYPE_RSS_20', 128);
  58. define('SIMPLEPIE_TYPE_RSS_RDF', 65);
  59. define('SIMPLEPIE_TYPE_RSS_SYNDICATION', 190);
  60. define('SIMPLEPIE_TYPE_RSS_ALL', 255);
  61. define('SIMPLEPIE_TYPE_ATOM_03', 256);
  62. define('SIMPLEPIE_TYPE_ATOM_10', 512);
  63. define('SIMPLEPIE_TYPE_ATOM_ALL', 768);
  64. define('SIMPLEPIE_TYPE_ALL', 1023);
  65. define('SIMPLEPIE_CONSTRUCT_NONE', 0);
  66. define('SIMPLEPIE_CONSTRUCT_TEXT', 1);
  67. define('SIMPLEPIE_CONSTRUCT_HTML', 2);
  68. define('SIMPLEPIE_CONSTRUCT_XHTML', 4);
  69. define('SIMPLEPIE_CONSTRUCT_BASE64', 8);
  70. define('SIMPLEPIE_CONSTRUCT_IRI', 16);
  71. define('SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32);
  72. define('SIMPLEPIE_CONSTRUCT_ALL', 63);
  73. define('SIMPLEPIE_SAME_CASE', 1);
  74. define('SIMPLEPIE_LOWERCASE', 2);
  75. define('SIMPLEPIE_UPPERCASE', 4);
  76. 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]*');
  77. define('SIMPLEPIE_PCRE_XML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*');
  78. define('SIMPLEPIE_NAMESPACE_XML', 'http://www.w3.org/XML/1998/namespace');
  79. define('SIMPLEPIE_NAMESPACE_ATOM_10', 'http://www.w3.org/2005/Atom');
  80. define('SIMPLEPIE_NAMESPACE_ATOM_03', 'http://purl.org/atom/ns#');
  81. define('SIMPLEPIE_NAMESPACE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
  82. define('SIMPLEPIE_NAMESPACE_RSS_090', 'http://my.netscape.com/rdf/simple/0.9/');
  83. define('SIMPLEPIE_NAMESPACE_RSS_10', 'http://purl.org/rss/1.0/');
  84. define('SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT', 'http://purl.org/rss/1.0/modules/content/');
  85. define('SIMPLEPIE_NAMESPACE_RSS_20', '');
  86. define('SIMPLEPIE_NAMESPACE_DC_10', 'http://purl.org/dc/elements/1.0/');
  87. define('SIMPLEPIE_NAMESPACE_DC_11', 'http://purl.org/dc/elements/1.1/');
  88. define('SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO', 'http://www.w3.org/2003/01/geo/wgs84_pos#');
  89. define('SIMPLEPIE_NAMESPACE_GEORSS', 'http://www.georss.org/georss');
  90. define('SIMPLEPIE_NAMESPACE_MEDIARSS', 'http://search.yahoo.com/mrss/');
  91. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG', 'http://search.yahoo.com/mrss');
  92. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2', 'http://video.search.yahoo.com/mrss');
  93. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3', 'http://video.search.yahoo.com/mrss/');
  94. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4', 'http://www.rssboard.org/media-rss');
  95. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5', 'http://www.rssboard.org/media-rss/');
  96. define('SIMPLEPIE_NAMESPACE_ITUNES', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
  97. define('SIMPLEPIE_NAMESPACE_XHTML', 'http://www.w3.org/1999/xhtml');
  98. define('SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY', 'http://www.iana.org/assignments/relation/');
  99. define('SIMPLEPIE_FILE_SOURCE_NONE', 0);
  100. define('SIMPLEPIE_FILE_SOURCE_REMOTE', 1);
  101. define('SIMPLEPIE_FILE_SOURCE_LOCAL', 2);
  102. define('SIMPLEPIE_FILE_SOURCE_FSOCKOPEN', 4);
  103. define('SIMPLEPIE_FILE_SOURCE_CURL', 8);
  104. define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16);
  105. class SimplePie
  106. {
  107. public $data = array();
  108. public $error;
  109. public $sanitize;
  110. public $useragent = SIMPLEPIE_USERAGENT;
  111. public $feed_url;
  112. public $file;
  113. public $raw_data;
  114. public $timeout = 10;
  115. public $force_fsockopen = false;
  116. public $force_feed = false;
  117. public $cache = true;
  118. public $cache_duration = 3600;
  119. public $autodiscovery_cache_duration = 604800; // 7 Days.
  120. public $cache_location = './cache';
  121. public $cache_name_function = 'md5';
  122. public $order_by_date = true;
  123. public $input_encoding = false;
  124. public $autodiscovery = SIMPLEPIE_LOCATOR_ALL;
  125. public $registry;
  126. public $max_checked_feeds = 10;
  127. public $all_discovered_feeds = array();
  128. public $image_handler = '';
  129. public $multifeed_url = array();
  130. public $multifeed_objects = array();
  131. public $config_settings = null;
  132. public $item_limit = 0;
  133. public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
  134. public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  135. public function __construct()
  136. {
  137. if (version_compare(PHP_VERSION, '5.2', '<'))
  138. {
  139. trigger_error('PHP 4.x, 5.0 and 5.1 are no longer supported. Please upgrade to PHP 5.2 or newer.');
  140. die();
  141. }
  142. // Other objects, instances created here so we can set options on them
  143. $this->sanitize = new SimplePie_Sanitize();
  144. $this->registry = new SimplePie_Registry();
  145. if (func_num_args() > 0)
  146. {
  147. trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_location() directly.');
  148. }
  149. }
  150. public function __toString()
  151. {
  152. return md5(serialize($this->data));
  153. }
  154. public function __destruct()
  155. {
  156. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
  157. {
  158. if (!empty($this->data['items']))
  159. {
  160. foreach ($this->data['items'] as $item)
  161. {
  162. $item->__destruct();
  163. }
  164. unset($item, $this->data['items']);
  165. }
  166. if (!empty($this->data['ordered_items']))
  167. {
  168. foreach ($this->data['ordered_items'] as $item)
  169. {
  170. $item->__destruct();
  171. }
  172. unset($item, $this->data['ordered_items']);
  173. }
  174. }
  175. }
  176. public function force_feed($enable = false)
  177. {
  178. $this->force_feed = (bool) $enable;
  179. }
  180. public function set_feed_url($url)
  181. {
  182. $this->multifeed_url = array();
  183. if (is_array($url))
  184. {
  185. foreach ($url as $value)
  186. {
  187. $this->multifeed_url[] = $this->registry->call('Misc', 'fix_protocol', array($value, 1));
  188. }
  189. }
  190. else
  191. {
  192. $this->feed_url = $this->registry->call('Misc', 'fix_protocol', array($url, 1));
  193. }
  194. }
  195. public function set_file(&$file)
  196. {
  197. if ($file instanceof SimplePie_File)
  198. {
  199. $this->feed_url = $file->url;
  200. $this->file =& $file;
  201. return true;
  202. }
  203. return false;
  204. }
  205. public function set_raw_data($data)
  206. {
  207. $this->raw_data = $data;
  208. }
  209. public function set_timeout($timeout = 10)
  210. {
  211. $this->timeout = (int) $timeout;
  212. }
  213. public function force_fsockopen($enable = false)
  214. {
  215. $this->force_fsockopen = (bool) $enable;
  216. }
  217. public function enable_cache($enable = true)
  218. {
  219. $this->cache = (bool) $enable;
  220. }
  221. public function set_cache_duration($seconds = 3600)
  222. {
  223. $this->cache_duration = (int) $seconds;
  224. }
  225. public function set_autodiscovery_cache_duration($seconds = 604800)
  226. {
  227. $this->autodiscovery_cache_duration = (int) $seconds;
  228. }
  229. public function set_cache_location($location = './cache')
  230. {
  231. $this->cache_location = (string) $location;
  232. }
  233. public function enable_order_by_date($enable = true)
  234. {
  235. $this->order_by_date = (bool) $enable;
  236. }
  237. public function set_input_encoding($encoding = false)
  238. {
  239. if ($encoding)
  240. {
  241. $this->input_encoding = (string) $encoding;
  242. }
  243. else
  244. {
  245. $this->input_encoding = false;
  246. }
  247. }
  248. public function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL)
  249. {
  250. $this->autodiscovery = (int) $level;
  251. }
  252. public function &get_registry()
  253. {
  254. return $this->registry;
  255. }
  256. /**
  257. * Set which class SimplePie uses for caching
  258. */
  259. public function set_cache_class($class = 'SimplePie_Cache')
  260. {
  261. return $this->registry->register('Cache', $class, true);
  262. }
  263. public function set_locator_class($class = 'SimplePie_Locator')
  264. {
  265. return $this->registry->register('Locator', $class, true);
  266. }
  267. public function set_parser_class($class = 'SimplePie_Parser')
  268. {
  269. return $this->registry->register('Parser', $class, true);
  270. }
  271. public function set_file_class($class = 'SimplePie_File')
  272. {
  273. return $this->registry->register('File', $class, true);
  274. }
  275. public function set_sanitize_class($class = 'SimplePie_Sanitize')
  276. {
  277. return $this->registry->register('Sanitize', $class, true);
  278. }
  279. public function set_item_class($class = 'SimplePie_Item')
  280. {
  281. return $this->registry->register('Item', $class, true);
  282. }
  283. public function set_author_class($class = 'SimplePie_Author')
  284. {
  285. return $this->registry->register('Author', $class, true);
  286. }
  287. public function set_category_class($class = 'SimplePie_Category')
  288. {
  289. return $this->registry->register('Category', $class, true);
  290. }
  291. public function set_enclosure_class($class = 'SimplePie_Enclosure')
  292. {
  293. return $this->registry->register('Enclosure', $class, true);
  294. }
  295. public function set_caption_class($class = 'SimplePie_Caption')
  296. {
  297. return $this->registry->register('Caption', $class, true);
  298. }
  299. public function set_copyright_class($class = 'SimplePie_Copyright')
  300. {
  301. return $this->registry->register('Copyright', $class, true);
  302. }
  303. public function set_credit_class($class = 'SimplePie_Credit')
  304. {
  305. return $this->registry->register('Credit', $class, true);
  306. }
  307. public function set_rating_class($class = 'SimplePie_Rating')
  308. {
  309. return $this->registry->register('Rating', $class, true);
  310. }
  311. public function set_restriction_class($class = 'SimplePie_Restriction')
  312. {
  313. return $this->registry->register('Restriction', $class, true);
  314. }
  315. public function set_content_type_sniffer_class($class = 'SimplePie_Content_Type_Sniffer')
  316. {
  317. return $this->registry->register('Content_Type_Sniffer', $class, true);
  318. }
  319. public function set_source_class($class = 'SimplePie_Source')
  320. {
  321. return $this->registry->register('Source', $class, true);
  322. }
  323. public function set_useragent($ua = SIMPLEPIE_USERAGENT)
  324. {
  325. $this->useragent = (string) $ua;
  326. }
  327. public function set_cache_name_function($function = 'md5')
  328. {
  329. if (is_callable($function))
  330. {
  331. $this->cache_name_function = $function;
  332. }
  333. }
  334. public function set_stupidly_fast($set = false)
  335. {
  336. if ($set)
  337. {
  338. $this->enable_order_by_date(false);
  339. $this->remove_div(false);
  340. $this->strip_comments(false);
  341. $this->strip_htmltags(false);
  342. $this->strip_attributes(false);
  343. $this->set_image_handler(false);
  344. }
  345. }
  346. public function set_max_checked_feeds($max = 10)
  347. {
  348. $this->max_checked_feeds = (int) $max;
  349. }
  350. public function remove_div($enable = true)
  351. {
  352. $this->sanitize->remove_div($enable);
  353. }
  354. public function strip_htmltags($tags = '', $encode = null)
  355. {
  356. if ($tags === '')
  357. {
  358. $tags = $this->strip_htmltags;
  359. }
  360. $this->sanitize->strip_htmltags($tags);
  361. if ($encode !== null)
  362. {
  363. $this->sanitize->encode_instead_of_strip($tags);
  364. }
  365. }
  366. public function encode_instead_of_strip($enable = true)
  367. {
  368. $this->sanitize->encode_instead_of_strip($enable);
  369. }
  370. public function strip_attributes($attribs = '')
  371. {
  372. if ($attribs === '')
  373. {
  374. $attribs = $this->strip_attributes;
  375. }
  376. $this->sanitize->strip_attributes($attribs);
  377. }
  378. public function set_output_encoding($encoding = 'UTF-8')
  379. {
  380. $this->sanitize->set_output_encoding($encoding);
  381. }
  382. public function strip_comments($strip = false)
  383. {
  384. $this->sanitize->strip_comments($strip);
  385. }
  386. public function set_url_replacements($element_attribute = null)
  387. {
  388. $this->sanitize->set_url_replacements($element_attribute);
  389. }
  390. public function set_image_handler($page = false, $qs = 'i')
  391. {
  392. if ($page !== false)
  393. {
  394. $this->sanitize->set_image_handler($page . '?' . $qs . '=');
  395. }
  396. else
  397. {
  398. $this->image_handler = '';
  399. }
  400. }
  401. public function set_item_limit($limit = 0)
  402. {
  403. $this->item_limit = (int) $limit;
  404. }
  405. public function init()
  406. {
  407. // Check absolute bare minimum requirements.
  408. if (!extension_loaded('xml') || !extension_loaded('pcre'))
  409. {
  410. return false;
  411. }
  412. // 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.
  413. elseif (!extension_loaded('xmlreader'))
  414. {
  415. static $xml_is_sane = null;
  416. if ($xml_is_sane === null)
  417. {
  418. $parser_check = xml_parser_create();
  419. xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
  420. xml_parser_free($parser_check);
  421. $xml_is_sane = isset($values[0]['value']);
  422. }
  423. if (!$xml_is_sane)
  424. {
  425. return false;
  426. }
  427. }
  428. if (method_exists($this->sanitize, 'set_registry'))
  429. {
  430. $this->sanitize->set_registry($this->registry);
  431. }
  432. // Pass whatever was set with config options over to the sanitizer.
  433. // Pass the classes in for legacy support; new classes should use the registry instead
  434. $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache'));
  435. $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen);
  436. if (!empty($this->multifeed_url))
  437. {
  438. $i = 0;
  439. $success = 0;
  440. $this->multifeed_objects = array();
  441. $this->error = array();
  442. foreach ($this->multifeed_url as $url)
  443. {
  444. $this->multifeed_objects[$i] = clone $this;
  445. $this->multifeed_objects[$i]->set_feed_url($url);
  446. $single_success = $this->multifeed_objects[$i]->init();
  447. $success |= $single_success;
  448. if (!$single_success)
  449. {
  450. $this->error[$i] = $this->multifeed_objects[$i]->error();
  451. }
  452. $i++;
  453. }
  454. return (bool) $success;
  455. }
  456. elseif ($this->feed_url === null && $this->raw_data === null)
  457. {
  458. return false;
  459. }
  460. $this->error = null;
  461. $this->data = array();
  462. $this->multifeed_objects = array();
  463. $cache = false;
  464. if ($this->feed_url !== null)
  465. {
  466. $parsed_feed_url = $this->registry->call('Misc', 'parse_url', array($this->feed_url));
  467. // Decide whether to enable caching
  468. if ($this->cache && $parsed_feed_url['scheme'] !== '')
  469. {
  470. $cache = $this->registry->call('Cache', 'create', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc'));
  471. }
  472. // Fetch the data via SimplePie_File into $this->raw_data
  473. if (($fetched = $this->fetch_data($cache)) === true)
  474. {
  475. return true;
  476. }
  477. elseif ($fetched === false) {
  478. return false;
  479. }
  480. list($headers, $sniffed) = $fetched;
  481. }
  482. // Set up array of possible encodings
  483. $encodings = array();
  484. // First check to see if input has been overridden.
  485. if ($this->input_encoding !== false)
  486. {
  487. $encodings[] = $this->input_encoding;
  488. }
  489. $application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
  490. $text_types = array('text/xml', 'text/xml-external-parsed-entity');
  491. // RFC 3023 (only applies to sniffed content)
  492. if (isset($sniffed))
  493. {
  494. if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml')
  495. {
  496. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
  497. {
  498. $encodings[] = strtoupper($charset[1]);
  499. }
  500. $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
  501. $encodings[] = 'UTF-8';
  502. }
  503. elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml')
  504. {
  505. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
  506. {
  507. $encodings[] = $charset[1];
  508. }
  509. $encodings[] = 'US-ASCII';
  510. }
  511. // Text MIME-type default
  512. elseif (substr($sniffed, 0, 5) === 'text/')
  513. {
  514. $encodings[] = 'US-ASCII';
  515. }
  516. }
  517. // Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1
  518. $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
  519. $encodings[] = 'UTF-8';
  520. $encodings[] = 'ISO-8859-1';
  521. // There's no point in trying an encoding twice
  522. $encodings = array_unique($encodings);
  523. // Loop through each possible encoding, till we return something, or run out of possibilities
  524. foreach ($encodings as $encoding)
  525. {
  526. // Change the encoding to UTF-8 (as we always use UTF-8 internally)
  527. if ($utf8_data = $this->registry->call('Misc', 'change_encoding', array($this->raw_data, $encoding, 'UTF-8')))
  528. {
  529. // Create new parser
  530. $parser = $this->registry->create('Parser');
  531. // If it's parsed fine
  532. if ($parser->parse($utf8_data, 'UTF-8'))
  533. {
  534. $this->data = $parser->get_data();
  535. if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE))
  536. {
  537. $this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed.";
  538. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
  539. return false;
  540. }
  541. if (isset($headers))
  542. {
  543. $this->data['headers'] = $headers;
  544. }
  545. $this->data['build'] = SIMPLEPIE_BUILD;
  546. // Cache the file if caching is enabled
  547. if ($cache && !$cache->save($this))
  548. {
  549. 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);
  550. }
  551. return true;
  552. }
  553. }
  554. }
  555. if (isset($parser))
  556. {
  557. // We have an error, just set SimplePie_Misc::error to it and quit
  558. $this->error = sprintf('This XML document is invalid, 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());
  559. }
  560. else
  561. {
  562. $this->error = 'The data could not be converted to UTF-8. You MUST have either the iconv or mbstring extension installed. Upgrading to PHP 5.x (which includes iconv) is highly recommended.';
  563. }
  564. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
  565. return false;
  566. }
  567. protected function fetch_data(&$cache)
  568. {
  569. // If it's enabled, use the cache
  570. if ($cache)
  571. {
  572. // Load the Cache
  573. $this->data = $cache->load();
  574. if (!empty($this->data))
  575. {
  576. // If the cache is for an outdated build of SimplePie
  577. if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD)
  578. {
  579. $cache->unlink();
  580. $this->data = array();
  581. }
  582. // If we've hit a collision just rerun it with caching disabled
  583. elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url)
  584. {
  585. $cache = false;
  586. $this->data = array();
  587. }
  588. // If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL.
  589. elseif (isset($this->data['feed_url']))
  590. {
  591. // If the autodiscovery cache is still valid use it.
  592. if ($cache->mtime() + $this->autodiscovery_cache_duration > time())
  593. {
  594. // Do not need to do feed autodiscovery yet.
  595. if ($this->data['feed_url'] !== $this->data['url'])
  596. {
  597. $this->set_feed_url($this->data['feed_url']);
  598. return $this->init();
  599. }
  600. $cache->unlink();
  601. $this->data = array();
  602. }
  603. }
  604. // Check if the cache has been updated
  605. elseif ($cache->mtime() + $this->cache_duration < time())
  606. {
  607. // If we have last-modified and/or etag set
  608. if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag']))
  609. {
  610. $headers = array(
  611. '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',
  612. );
  613. if (isset($this->data['headers']['last-modified']))
  614. {
  615. $headers['if-modified-since'] = $this->data['headers']['last-modified'];
  616. }
  617. if (isset($this->data['headers']['etag']))
  618. {
  619. $headers['if-none-match'] = $this->data['headers']['etag'];
  620. }
  621. $file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen));
  622. if ($file->success)
  623. {
  624. if ($file->status_code === 304)
  625. {
  626. $cache->touch();
  627. return true;
  628. }
  629. }
  630. else
  631. {
  632. unset($file);
  633. }
  634. }
  635. }
  636. // If the cache is still valid, just return true
  637. else
  638. {
  639. $this->raw_data = false;
  640. return true;
  641. }
  642. }
  643. // If the cache is empty, delete it
  644. else
  645. {
  646. $cache->unlink();
  647. $this->data = array();
  648. }
  649. }
  650. // 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.
  651. if (!isset($file))
  652. {
  653. if ($this->file instanceof SimplePie_File && $this->file->url === $this->feed_url)
  654. {
  655. $file =& $this->file;
  656. }
  657. else
  658. {
  659. $headers = array(
  660. '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',
  661. );
  662. $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen));
  663. }
  664. }
  665. // If the file connection has an error, set SimplePie::error to that and quit
  666. if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
  667. {
  668. $this->error = $file->error;
  669. return !empty($this->data);
  670. }
  671. if (!$this->force_feed)
  672. {
  673. // Check if the supplied URL is a feed, if it isn't, look for it.
  674. $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds));
  675. if (!$locate->is_feed($file))
  676. {
  677. // We need to unset this so that if SimplePie::set_file() has been called that object is untouched
  678. unset($file);
  679. if (!($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds)))
  680. {
  681. $this->error = "A feed could not be found at $this->feed_url. A feed with an invalid mime type may fall victim to this error, or " . SIMPLEPIE_NAME . " was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed.";
  682. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
  683. return false;
  684. }
  685. if ($cache)
  686. {
  687. $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD);
  688. if (!$cache->save($this))
  689. {
  690. 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);
  691. }
  692. $cache = $this->registry->call('Cache', 'create', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc'));
  693. }
  694. $this->feed_url = $file->url;
  695. }
  696. $locate = null;
  697. }
  698. $this->raw_data = $file->body;
  699. $headers = $file->headers;
  700. $sniffer = $this->registry->create('Content_Type_Sniffer', array(&$file));
  701. $sniffed = $sniffer->get_type();
  702. return array($headers, $sniffed);
  703. }
  704. public function error()
  705. {
  706. return $this->error;
  707. }
  708. public function get_raw_data()
  709. {
  710. return $this->raw_data;
  711. }
  712. public function get_encoding()
  713. {
  714. return $this->sanitize->output_encoding;
  715. }
  716. public function handle_content_type($mime = 'text/html')
  717. {
  718. if (!headers_sent())
  719. {
  720. $header = "Content-type: $mime;";
  721. if ($this->get_encoding())
  722. {
  723. $header .= ' charset=' . $this->get_encoding();
  724. }
  725. else
  726. {
  727. $header .= ' charset=UTF-8';
  728. }
  729. header($header);
  730. }
  731. }
  732. public function get_type()
  733. {
  734. if (!isset($this->data['type']))
  735. {
  736. $this->data['type'] = SIMPLEPIE_TYPE_ALL;
  737. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed']))
  738. {
  739. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10;
  740. }
  741. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed']))
  742. {
  743. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03;
  744. }
  745. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF']))
  746. {
  747. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel'])
  748. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image'])
  749. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item'])
  750. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput']))
  751. {
  752. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10;
  753. }
  754. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel'])
  755. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image'])
  756. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item'])
  757. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput']))
  758. {
  759. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090;
  760. }
  761. }
  762. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss']))
  763. {
  764. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL;
  765. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
  766. {
  767. switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
  768. {
  769. case '0.91':
  770. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091;
  771. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
  772. {
  773. switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
  774. {
  775. case '0':
  776. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE;
  777. break;
  778. case '24':
  779. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND;
  780. break;
  781. }
  782. }
  783. break;
  784. case '0.92':
  785. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092;
  786. break;
  787. case '0.93':
  788. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093;
  789. break;
  790. case '0.94':
  791. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094;
  792. break;
  793. case '2.0':
  794. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20;
  795. break;
  796. }
  797. }
  798. }
  799. else
  800. {
  801. $this->data['type'] = SIMPLEPIE_TYPE_NONE;
  802. }
  803. }
  804. return $this->data['type'];
  805. }
  806. public function subscribe_url()
  807. {
  808. if ($this->feed_url !== null)
  809. {
  810. return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI);
  811. }
  812. else
  813. {
  814. return null;
  815. }
  816. }
  817. public function get_feed_tags($namespace, $tag)
  818. {
  819. $type = $this->get_type();
  820. if ($type & SIMPLEPIE_TYPE_ATOM_10)
  821. {
  822. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag]))
  823. {
  824. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag];
  825. }
  826. }
  827. if ($type & SIMPLEPIE_TYPE_ATOM_03)
  828. {
  829. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag]))
  830. {
  831. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag];
  832. }
  833. }
  834. if ($type & SIMPLEPIE_TYPE_RSS_RDF)
  835. {
  836. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag]))
  837. {
  838. return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag];
  839. }
  840. }
  841. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  842. {
  843. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag]))
  844. {
  845. return $this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag];
  846. }
  847. }
  848. return null;
  849. }
  850. public function get_channel_tags($namespace, $tag)
  851. {
  852. $type = $this->get_type();
  853. if ($type & SIMPLEPIE_TYPE_ATOM_ALL)
  854. {
  855. if ($return = $this->get_feed_tags($namespace, $tag))
  856. {
  857. return $return;
  858. }
  859. }
  860. if ($type & SIMPLEPIE_TYPE_RSS_10)
  861. {
  862. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel'))
  863. {
  864. if (isset($channel[0]['child'][$namespace][$tag]))
  865. {
  866. return $channel[0]['child'][$namespace][$tag];
  867. }
  868. }
  869. }
  870. if ($type & SIMPLEPIE_TYPE_RSS_090)
  871. {
  872. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel'))
  873. {
  874. if (isset($channel[0]['child'][$namespace][$tag]))
  875. {
  876. return $channel[0]['child'][$namespace][$tag];
  877. }
  878. }
  879. }
  880. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  881. {
  882. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'channel'))
  883. {
  884. if (isset($channel[0]['child'][$namespace][$tag]))
  885. {
  886. return $channel[0]['child'][$namespace][$tag];
  887. }
  888. }
  889. }
  890. return null;
  891. }
  892. public function get_image_tags($namespace, $tag)
  893. {
  894. $type = $this->get_type();
  895. if ($type & SIMPLEPIE_TYPE_RSS_10)
  896. {
  897. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image'))
  898. {
  899. if (isset($image[0]['child'][$namespace][$tag]))
  900. {
  901. return $image[0]['child'][$namespace][$tag];
  902. }
  903. }
  904. }
  905. if ($type & SIMPLEPIE_TYPE_RSS_090)
  906. {
  907. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image'))
  908. {
  909. if (isset($image[0]['child'][$namespace][$tag]))
  910. {
  911. return $image[0]['child'][$namespace][$tag];
  912. }
  913. }
  914. }
  915. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  916. {
  917. if ($image = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'image'))
  918. {
  919. if (isset($image[0]['child'][$namespace][$tag]))
  920. {
  921. return $image[0]['child'][$namespace][$tag];
  922. }
  923. }
  924. }
  925. return null;
  926. }
  927. public function get_base($element = array())
  928. {
  929. if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base']))
  930. {
  931. return $element['xml_base'];
  932. }
  933. elseif ($this->get_link() !== null)
  934. {
  935. return $this->get_link();
  936. }
  937. else
  938. {
  939. return $this->subscribe_url();
  940. }
  941. }
  942. public function sanitize($data, $type, $base = '')
  943. {
  944. return $this->sanitize->sanitize($data, $type, $base);
  945. }
  946. public function get_title()
  947. {
  948. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  949. {
  950. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  951. }
  952. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  953. {
  954. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  955. }
  956. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  957. {
  958. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  959. }
  960. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  961. {
  962. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  963. }
  964. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  965. {
  966. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  967. }
  968. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  969. {
  970. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  971. }
  972. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  973. {
  974. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  975. }
  976. else
  977. {
  978. return null;
  979. }
  980. }
  981. public function get_category($key = 0)
  982. {
  983. $categories = $this->get_categories();
  984. if (isset($categories[$key]))
  985. {
  986. return $categories[$key];
  987. }
  988. else
  989. {
  990. return null;
  991. }
  992. }
  993. public function get_categories()
  994. {
  995. $categories = array();
  996. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  997. {
  998. $term = null;
  999. $scheme = null;
  1000. $label = null;
  1001. if (isset($category['attribs']['']['term']))
  1002. {
  1003. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  1004. }
  1005. if (isset($category['attribs']['']['scheme']))
  1006. {
  1007. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1008. }
  1009. if (isset($category['attribs']['']['label']))
  1010. {
  1011. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1012. }
  1013. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  1014. }
  1015. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
  1016. {
  1017. // This is really the label, but keep this as the term also for BC.
  1018. // Label will also work on retrieving because that falls back to term.
  1019. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1020. if (isset($category['attribs']['']['domain']))
  1021. {
  1022. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  1023. }
  1024. else
  1025. {
  1026. $scheme = null;
  1027. }
  1028. $categories[] = $this->registry->create('Category', array($term, $scheme, null));
  1029. }
  1030. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  1031. {
  1032. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  1033. }
  1034. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  1035. {
  1036. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  1037. }
  1038. if (!empty($categories))
  1039. {
  1040. return array_unique($categories);
  1041. }
  1042. else
  1043. {
  1044. return null;
  1045. }
  1046. }
  1047. public function get_author($key = 0)
  1048. {
  1049. $authors = $this->get_authors();
  1050. if (isset($authors[$key]))
  1051. {
  1052. return $authors[$key];
  1053. }
  1054. else
  1055. {
  1056. return null;
  1057. }
  1058. }
  1059. public function get_authors()
  1060. {
  1061. $authors = array();
  1062. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  1063. {
  1064. $name = null;
  1065. $uri = null;
  1066. $email = null;
  1067. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  1068. {
  1069. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1070. }
  1071. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  1072. {
  1073. $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]));
  1074. }
  1075. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  1076. {
  1077. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1078. }
  1079. if ($name !== null || $email !== null || $uri !== null)
  1080. {
  1081. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  1082. }
  1083. }
  1084. if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  1085. {
  1086. $name = null;
  1087. $url = null;
  1088. $email = null;
  1089. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  1090. {
  1091. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1092. }
  1093. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  1094. {
  1095. $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]));
  1096. }
  1097. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  1098. {
  1099. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1100. }
  1101. if ($name !== null || $email !== null || $url !== null)
  1102. {
  1103. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  1104. }
  1105. }
  1106. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  1107. {
  1108. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  1109. }
  1110. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  1111. {
  1112. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  1113. }
  1114. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  1115. {
  1116. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  1117. }
  1118. if (!empty($authors))
  1119. {
  1120. return array_unique($authors);
  1121. }
  1122. else
  1123. {
  1124. return null;
  1125. }
  1126. }
  1127. public function get_contributor($key = 0)
  1128. {
  1129. $contributors = $this->get_contributors();
  1130. if (isset($contributors[$key]))
  1131. {
  1132. return $contributors[$key];
  1133. }
  1134. else
  1135. {
  1136. return null;
  1137. }
  1138. }
  1139. public function get_contributors()
  1140. {
  1141. $contributors = array();
  1142. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  1143. {
  1144. $name = null;
  1145. $uri = null;
  1146. $email = null;
  1147. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  1148. {
  1149. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1150. }
  1151. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  1152. {
  1153. $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]));
  1154. }
  1155. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  1156. {
  1157. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1158. }
  1159. if ($name !== null || $email !== null || $uri !== null)
  1160. {
  1161. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  1162. }
  1163. }
  1164. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  1165. {
  1166. $name = null;
  1167. $url = null;
  1168. $email = null;
  1169. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  1170. {
  1171. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1172. }
  1173. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  1174. {
  1175. $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]));
  1176. }
  1177. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  1178. {
  1179. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1180. }
  1181. if ($name !== null || $email !== null || $url !== null)
  1182. {
  1183. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  1184. }
  1185. }
  1186. if (!empty($contributors))
  1187. {
  1188. return array_unique($contributors);
  1189. }
  1190. else
  1191. {
  1192. return null;
  1193. }
  1194. }
  1195. public function get_link($key = 0, $rel = 'alternate')
  1196. {
  1197. $links = $this->get_links($rel);
  1198. if (isset($links[$key]))
  1199. {
  1200. return $links[$key];
  1201. }
  1202. else
  1203. {
  1204. return null;
  1205. }
  1206. }
  1207. public function get_permalink()
  1208. {
  1209. return $this->get_link(0);
  1210. }
  1211. public function get_links($rel = 'alternate')
  1212. {
  1213. if (!isset($this->data['links']))
  1214. {
  1215. $this->data['links'] = array();
  1216. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
  1217. {
  1218. foreach ($links as $link)
  1219. {
  1220. if (isset($link['attribs']['']['href']))
  1221. {
  1222. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  1223. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  1224. }
  1225. }
  1226. }
  1227. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
  1228. {
  1229. foreach ($links as $link)
  1230. {
  1231. if (isset($link['attribs']['']['href']))
  1232. {
  1233. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  1234. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  1235. }
  1236. }
  1237. }
  1238. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  1239. {
  1240. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  1241. }
  1242. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  1243. {
  1244. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  1245. }
  1246. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  1247. {
  1248. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  1249. }
  1250. $keys = array_keys($this->data['links']);
  1251. foreach ($keys as $key)
  1252. {
  1253. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
  1254. {
  1255. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  1256. {
  1257. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  1258. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  1259. }
  1260. else
  1261. {
  1262. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  1263. }
  1264. }
  1265. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  1266. {
  1267. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  1268. }
  1269. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  1270. }
  1271. }
  1272. if (isset($this->data['links'][$rel]))
  1273. {
  1274. return $this->data['links'][$rel];
  1275. }
  1276. else
  1277. {
  1278. return null;
  1279. }
  1280. }
  1281. public function get_all_discovered_feeds()
  1282. {
  1283. return $this->all_discovered_feeds;
  1284. }
  1285. public function get_description()
  1286. {
  1287. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
  1288. {
  1289. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  1290. }
  1291. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
  1292. {
  1293. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  1294. }
  1295. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  1296. {
  1297. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  1298. }
  1299. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
  1300. {
  1301. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  1302. }
  1303. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
  1304. {
  1305. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  1306. }
  1307. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  1308. {
  1309. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1310. }
  1311. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  1312. {
  1313. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1314. }
  1315. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  1316. {
  1317. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  1318. }
  1319. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  1320. {
  1321. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  1322. }
  1323. else
  1324. {
  1325. return null;
  1326. }
  1327. }
  1328. public function get_copyright()
  1329. {
  1330. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  1331. {
  1332. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  1333. }
  1334. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
  1335. {
  1336. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  1337. }
  1338. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
  1339. {
  1340. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1341. }
  1342. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  1343. {
  1344. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1345. }
  1346. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  1347. {
  1348. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1349. }
  1350. else
  1351. {
  1352. return null;
  1353. }
  1354. }
  1355. public function get_language()
  1356. {
  1357. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language'))
  1358. {
  1359. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1360. }
  1361. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
  1362. {
  1363. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1364. }
  1365. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
  1366. {
  1367. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1368. }
  1369. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang']))
  1370. {
  1371. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1372. }
  1373. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang']))
  1374. {
  1375. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1376. }
  1377. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang']))
  1378. {
  1379. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1380. }
  1381. elseif (isset($this->data['headers']['content-language']))
  1382. {
  1383. return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT);
  1384. }
  1385. else
  1386. {
  1387. return null;
  1388. }
  1389. }
  1390. public function get_latitude()
  1391. {
  1392. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  1393. {
  1394. return (float) $return[0]['data'];
  1395. }
  1396. 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))
  1397. {
  1398. return (float) $match[1];
  1399. }
  1400. else
  1401. {
  1402. return null;
  1403. }
  1404. }
  1405. public function get_longitude()
  1406. {
  1407. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  1408. {
  1409. return (float) $return[0]['data'];
  1410. }
  1411. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  1412. {
  1413. return (float) $return[0]['data'];
  1414. }
  1415. 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))
  1416. {
  1417. return (float) $match[2];
  1418. }
  1419. else
  1420. {
  1421. return null;
  1422. }
  1423. }
  1424. public function get_image_title()
  1425. {
  1426. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  1427. {
  1428. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1429. }
  1430. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  1431. {
  1432. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1433. }
  1434. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  1435. {
  1436. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1437. }
  1438. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  1439. {
  1440. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1441. }
  1442. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  1443. {
  1444. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1445. }
  1446. else
  1447. {
  1448. return null;
  1449. }
  1450. }
  1451. public function get_image_url()
  1452. {
  1453. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
  1454. {
  1455. return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
  1456. }
  1457. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
  1458. {
  1459. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1460. }
  1461. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
  1462. {
  1463. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1464. }
  1465. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url'))
  1466. {
  1467. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1468. }
  1469. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url'))
  1470. {
  1471. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1472. }
  1473. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
  1474. {
  1475. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1476. }
  1477. else
  1478. {
  1479. return null;
  1480. }
  1481. }
  1482. public function get_image_link()
  1483. {
  1484. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  1485. {
  1486. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1487. }
  1488. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  1489. {
  1490. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1491. }
  1492. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  1493. {
  1494. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1495. }
  1496. else
  1497. {
  1498. return null;
  1499. }
  1500. }
  1501. public function get_image_width()
  1502. {
  1503. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'width'))
  1504. {
  1505. return round($return[0]['data']);
  1506. }
  1507. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
  1508. {
  1509. return 88.0;
  1510. }
  1511. else
  1512. {
  1513. return null;
  1514. }
  1515. }
  1516. public function get_image_height()
  1517. {
  1518. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'height'))
  1519. {
  1520. return round($return[0]['data']);
  1521. }
  1522. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
  1523. {
  1524. return 31.0;
  1525. }
  1526. else
  1527. {
  1528. return null;
  1529. }
  1530. }
  1531. public function get_item_quantity($max = 0)
  1532. {
  1533. $max = (int) $max;
  1534. $qty = count($this->get_items());
  1535. if ($max === 0)
  1536. {
  1537. return $qty;
  1538. }
  1539. else
  1540. {
  1541. return ($qty > $max) ? $max : $qty;
  1542. }
  1543. }
  1544. public function get_item($key = 0)
  1545. {
  1546. $items = $this->get_items();
  1547. if (isset($items[$key]))
  1548. {
  1549. return $items[$key];
  1550. }
  1551. else
  1552. {
  1553. return null;
  1554. }
  1555. }
  1556. public function get_items($start = 0, $end = 0)
  1557. {
  1558. if (!isset($this->data['items']))
  1559. {
  1560. if (!empty($this->multifeed_objects))
  1561. {
  1562. $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit);
  1563. }
  1564. else
  1565. {
  1566. $this->data['items'] = array();
  1567. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry'))
  1568. {
  1569. $keys = array_keys($items);
  1570. foreach ($keys as $key)
  1571. {
  1572. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  1573. }
  1574. }
  1575. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry'))
  1576. {
  1577. $keys = array_keys($items);
  1578. foreach ($keys as $key)
  1579. {
  1580. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  1581. }
  1582. }
  1583. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item'))
  1584. {
  1585. $keys = array_keys($items);
  1586. foreach ($keys as $key)
  1587. {
  1588. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  1589. }
  1590. }
  1591. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item'))
  1592. {
  1593. $keys = array_keys($items);
  1594. foreach ($keys as $key)
  1595. {
  1596. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  1597. }
  1598. }
  1599. if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'item'))
  1600. {
  1601. $keys = array_keys($items);
  1602. foreach ($keys as $key)
  1603. {
  1604. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  1605. }
  1606. }
  1607. }
  1608. }
  1609. if (!empty($this->data['items']))
  1610. {
  1611. // If we want to order it by date, check if all items have a date, and then sort it
  1612. if ($this->order_by_date && empty($this->multifeed_objects))
  1613. {
  1614. if (!isset($this->data['ordered_items']))
  1615. {
  1616. $do_sort = true;
  1617. foreach ($this->data['items'] as $item)
  1618. {
  1619. if (!$item->get_date('U'))
  1620. {
  1621. $do_sort = false;
  1622. break;
  1623. }
  1624. }
  1625. $item = null;
  1626. $this->data['ordered_items'] = $this->data['items'];
  1627. if ($do_sort)
  1628. {
  1629. usort($this->data['ordered_items'], array(get_class($this), 'sort_items'));
  1630. }
  1631. }
  1632. $items = $this->data['ordered_items'];
  1633. }
  1634. else
  1635. {
  1636. $items = $this->data['items'];
  1637. }
  1638. // Slice the data as desired
  1639. if ($end === 0)
  1640. {
  1641. return array_slice($items, $start);
  1642. }
  1643. else
  1644. {
  1645. return array_slice($items, $start, $end);
  1646. }
  1647. }
  1648. else
  1649. {
  1650. return array();
  1651. }
  1652. }
  1653. public static function sort_items($a, $b)
  1654. {
  1655. return $a->get_date('U') <= $b->get_date('U');
  1656. }
  1657. public static function merge_items($urls, $start = 0, $end = 0, $limit = 0)
  1658. {
  1659. if (is_array($urls) && sizeof($urls) > 0)
  1660. {
  1661. $items = array();
  1662. foreach ($urls as $arg)
  1663. {
  1664. if ($arg instanceof SimplePie)
  1665. {
  1666. $items = array_merge($items, $arg->get_items(0, $limit));
  1667. }
  1668. else
  1669. {
  1670. trigger_error('Arguments must be SimplePie objects', E_USER_WARNING);
  1671. }
  1672. }
  1673. $do_sort = true;
  1674. foreach ($items as $item)
  1675. {
  1676. if (!$item->get_date('U'))
  1677. {
  1678. $do_sort = false;
  1679. break;
  1680. }
  1681. }
  1682. $item = null;
  1683. if ($do_sort)
  1684. {
  1685. usort($items, array(get_class($urls[0]), 'sort_items'));
  1686. }
  1687. if ($end === 0)
  1688. {
  1689. return array_slice($items, $start);
  1690. }
  1691. else
  1692. {
  1693. return array_slice($items, $start, $end);
  1694. }
  1695. }
  1696. else
  1697. {
  1698. trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING);
  1699. return array();
  1700. }
  1701. }
  1702. }
  1703. class SimplePie_Author
  1704. {
  1705. var $name;
  1706. var $link;
  1707. var $email;
  1708. public function __construct($name = null, $link = null, $email = null)
  1709. {
  1710. $this->name = $name;
  1711. $this->link = $link;
  1712. $this->email = $email;
  1713. }
  1714. public function __toString()
  1715. {
  1716. // There is no $this->data here
  1717. return md5(serialize($this));
  1718. }
  1719. public function get_name()
  1720. {
  1721. if ($this->name !== null)
  1722. {
  1723. return $this->name;
  1724. }
  1725. else
  1726. {
  1727. return null;
  1728. }
  1729. }
  1730. public function get_link()
  1731. {
  1732. if ($this->link !== null)
  1733. {
  1734. return $this->link;
  1735. }
  1736. else
  1737. {
  1738. return null;
  1739. }
  1740. }
  1741. public function get_email()
  1742. {
  1743. if ($this->email !== null)
  1744. {
  1745. return $this->email;
  1746. }
  1747. else
  1748. {
  1749. return null;
  1750. }
  1751. }
  1752. }
  1753. interface SimplePie_Cache_Base
  1754. {
  1755. const TYPE_FEED = 'spc';
  1756. const TYPE_IMAGE = 'spi';
  1757. public function __construct($location, $name, $type);
  1758. public function save($data);
  1759. public function load();
  1760. public function mtime();
  1761. public function touch();
  1762. public function unlink();
  1763. }
  1764. abstract class SimplePie_Cache_DB implements SimplePie_Cache_Base
  1765. {
  1766. protected static function prepare_simplepie_object_for_cache($data)
  1767. {
  1768. $items = $data->get_items();
  1769. $items_by_id = array();
  1770. if (!empty($items))
  1771. {
  1772. foreach ($items as $item)
  1773. {
  1774. $items_by_id[$item->get_id()] = $item;
  1775. }
  1776. if (count($items_by_id) !== count($items))
  1777. {
  1778. $items_by_id = array();
  1779. foreach ($items as $item)
  1780. {
  1781. $items_by_id[$item->get_id(true)] = $item;
  1782. }
  1783. }
  1784. if (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
  1785. {
  1786. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
  1787. }
  1788. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
  1789. {
  1790. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
  1791. }
  1792. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
  1793. {
  1794. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
  1795. }
  1796. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0]))
  1797. {
  1798. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0];
  1799. }
  1800. else
  1801. {
  1802. $channel = null;
  1803. }
  1804. if ($channel !== null)
  1805. {
  1806. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']))
  1807. {
  1808. unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']);
  1809. }
  1810. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']))
  1811. {
  1812. unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']);
  1813. }
  1814. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']))
  1815. {
  1816. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']);
  1817. }
  1818. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']))
  1819. {
  1820. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']);
  1821. }
  1822. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']))
  1823. {
  1824. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']);
  1825. }
  1826. }
  1827. if (isset($data->data['items']))
  1828. {
  1829. unset($data->data['items']);
  1830. }
  1831. if (isset($data->data['ordered_items']))
  1832. {
  1833. unset($data->data['ordered_items']);
  1834. }
  1835. }
  1836. return array(serialize($data->data), $items_by_id);
  1837. }
  1838. }
  1839. class SimplePie_Cache_File implements SimplePie_Cache_Base
  1840. {
  1841. protected $location;
  1842. protected $filename;
  1843. protected $extension;
  1844. protected $name;
  1845. public function __construct($location, $name, $type)
  1846. {
  1847. $this->location = $location;
  1848. $this->filename = $name;
  1849. $this->extension = $type;
  1850. $this->name = "$this->location/$this->filename.$this->extension";
  1851. }
  1852. public function save($data)
  1853. {
  1854. if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
  1855. {
  1856. if ($data instanceof SimplePie)
  1857. {
  1858. $data = $data->data;
  1859. }
  1860. $data = serialize($data);
  1861. return (bool) file_put_contents($this->name, $data);
  1862. }
  1863. return false;
  1864. }
  1865. public function load()
  1866. {
  1867. if (file_exists($this->name) && is_readable($this->name))
  1868. {
  1869. return unserialize(file_get_contents($this->name));
  1870. }
  1871. return false;
  1872. }
  1873. public function mtime()
  1874. {
  1875. if (file_exists($this->name))
  1876. {
  1877. return filemtime($this->name);
  1878. }
  1879. return false;
  1880. }
  1881. public function touch()
  1882. {
  1883. if (file_exists($this->name))
  1884. {
  1885. return touch($this->name);
  1886. }
  1887. return false;
  1888. }
  1889. public function unlink()
  1890. {
  1891. if (file_exists($this->name))
  1892. {
  1893. return unlink($this->name);
  1894. }
  1895. return false;
  1896. }
  1897. }
  1898. class SimplePie_Cache_Memcache implements SimplePie_Cache_Base
  1899. {
  1900. protected $cache;
  1901. protected $options;
  1902. protected $name;
  1903. public function __construct($location, $name, $type)
  1904. {
  1905. $this->options = array(
  1906. 'host' => '127.0.0.1',
  1907. 'port' => 11211,
  1908. 'extras' => array(
  1909. 'timeout' => 3600, // one hour
  1910. 'prefix' => 'simplepie_',
  1911. ),
  1912. );
  1913. $parsed = SimplePie_Cache::parse_URL($location);
  1914. $this->options['host'] = empty($parsed['host']) ? $this->options['host'] : $parsed['host'];
  1915. $this->options['port'] = empty($parsed['port']) ? $this->options['port'] : $parsed['port'];
  1916. $this->options['extras'] = array_merge($this->options['extras'], $parsed['extras']);
  1917. $this->name = $this->options['extras']['prefix'] . md5("$name:$type");
  1918. $this->cache = new Memcache();
  1919. $this->cache->addServer($this->options['host'], (int) $this->options['port']);
  1920. }
  1921. public function save($data)
  1922. {
  1923. if ($data instanceof SimplePie)
  1924. {
  1925. $data = $data->data;
  1926. }
  1927. return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
  1928. }
  1929. public function load()
  1930. {
  1931. $data = $this->cache->get($this->name);
  1932. if ($data !== false)
  1933. {
  1934. return unserialize($data);
  1935. }
  1936. return false;
  1937. }
  1938. public function mtime()
  1939. {
  1940. $data = $this->cache->get($this->name);
  1941. if ($data !== false)
  1942. {
  1943. // essentially ignore the mtime because Memcache expires on it's own
  1944. return time();
  1945. }
  1946. return false;
  1947. }
  1948. public function touch()
  1949. {
  1950. $data = $this->cache->get($this->name);
  1951. if ($data !== false)
  1952. {
  1953. return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->duration);
  1954. }
  1955. return false;
  1956. }
  1957. public function unlink()
  1958. {
  1959. return $this->cache->delete($this->name, 0);
  1960. }
  1961. }
  1962. class SimplePie_Cache_MySQL extends SimplePie_Cache_DB
  1963. {
  1964. protected $mysql;
  1965. protected $options;
  1966. protected $id;
  1967. public function __construct($location, $name, $type)
  1968. {
  1969. $this->options = array(
  1970. 'user' => null,
  1971. 'pass' => null,
  1972. 'host' => '127.0.0.1',
  1973. 'port' => '3306',
  1974. 'path' => '',
  1975. 'extras' => array(
  1976. 'prefix' => '',
  1977. ),
  1978. );
  1979. $this->options = array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));
  1980. // Path is prefixed with a "/"
  1981. $this->options['dbname'] = substr($this->options['path'], 1);
  1982. try
  1983. {
  1984. $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'));
  1985. }
  1986. catch (PDOException $e)
  1987. {
  1988. $this->mysql = null;
  1989. return;
  1990. }
  1991. $this->id = $name . $type;
  1992. if (!$query = $this->mysql->query('SHOW TABLES'))
  1993. {
  1994. $this->mysql = null;
  1995. return;
  1996. }
  1997. $db = array();
  1998. while ($row = $query->fetchColumn())
  1999. {
  2000. $db[] = $row;
  2001. }
  2002. if (!in_array($this->options['extras']['prefix'] . 'cache_data', $db))
  2003. {
  2004. $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)))');
  2005. if ($query === false)
  2006. {
  2007. $this->mysql = null;
  2008. }
  2009. }
  2010. if (!in_array($this->options['extras']['prefix'] . 'items', $db))
  2011. {
  2012. $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` TEXT CHARACTER SET utf8 NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))');
  2013. if ($query === false)
  2014. {
  2015. $this->mysql = null;
  2016. }
  2017. }
  2018. }
  2019. public function save($data)
  2020. {
  2021. if ($this->mysql === null)
  2022. {
  2023. return false;
  2024. }
  2025. if ($data instanceof SimplePie)
  2026. {
  2027. $data = clone $data;
  2028. $prepared = self::prepare_simplepie_object_for_cache($data);
  2029. $query = $this->mysql->prepare('SELECT COUNT(*) FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
  2030. $query->bindValue(':feed', $this->id);
  2031. if ($query->execute())
  2032. {
  2033. if ($query->fetchColumn() > 0)
  2034. {
  2035. $items = count($prepared[1]);
  2036. if ($items)
  2037. {
  2038. $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = :items, `data` = :data, `mtime` = :time WHERE `id` = :feed';
  2039. $query = $this->mysql->prepare($sql);
  2040. $query->bindValue(':items', $items);
  2041. }
  2042. else
  2043. {
  2044. $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `data` = :data, `mtime` = :time WHERE `id` = :feed';
  2045. $query = $this->mysql->prepare($sql);
  2046. }
  2047. $query->bindValue(':data', $prepared[0]);
  2048. $query->bindValue(':time', time());
  2049. $query->bindValue(':feed', $this->id);
  2050. if (!$query->execute())
  2051. {
  2052. return false;
  2053. }
  2054. }
  2055. else
  2056. {
  2057. $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:feed, :count, :data, :time)');
  2058. $query->bindValue(':feed', $this->id);
  2059. $query->bindValue(':count', count($prepared[1]));
  2060. $query->bindValue(':data', $prepared[0]);
  2061. $query->bindValue(':time', time());
  2062. if (!$query->execute())
  2063. {
  2064. return false;
  2065. }
  2066. }
  2067. $ids = array_keys($prepared[1]);
  2068. if (!empty($ids))
  2069. {
  2070. foreach ($ids as $id)
  2071. {
  2072. $database_ids[] = $this->mysql->quote($id);
  2073. }
  2074. $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `id` = ' . implode(' OR `id` = ', $database_ids) . ' AND `feed_id` = :feed');
  2075. $query->bindValue(':feed', $this->id);
  2076. if ($query->execute())
  2077. {
  2078. $existing_ids = array();
  2079. while ($row = $query->fetchColumn())
  2080. {
  2081. $existing_ids[] = $row;
  2082. }
  2083. $new_ids = array_diff($ids, $existing_ids);
  2084. foreach ($new_ids as $new_id)
  2085. {
  2086. if (!($date = $prepared[1][$new_id]->get_date('U')))
  2087. {
  2088. $date = time();
  2089. }
  2090. $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'items` (`feed_id`, `id`, `data`, `posted`) VALUES(:feed, :id, :data, :date)');
  2091. $query->bindValue(':feed', $this->id);
  2092. $query->bindValue(':id', $new_id);
  2093. $query->bindValue(':data', serialize($prepared[1][$new_id]->data));
  2094. $query->bindValue(':date', $date);
  2095. if (!$query->execute())
  2096. {
  2097. return false;
  2098. }
  2099. }
  2100. return true;
  2101. }
  2102. }
  2103. else
  2104. {
  2105. return true;
  2106. }
  2107. }
  2108. }
  2109. else
  2110. {
  2111. $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
  2112. $query->bindValue(':feed', $this->id);
  2113. if ($query->execute())
  2114. {
  2115. if ($query->rowCount() > 0)
  2116. {
  2117. $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = 0, `data` = :data, `mtime` = :time WHERE `id` = :feed');
  2118. $query->bindValue(':data', serialize($data));
  2119. $query->bindValue(':time', time());
  2120. $query->bindValue(':feed', $this->id);
  2121. if ($this->execute())
  2122. {
  2123. return true;
  2124. }
  2125. }
  2126. else
  2127. {
  2128. $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:id, 0, :data, :time)');
  2129. $query->bindValue(':id', $this->id);
  2130. $query->bindValue(':data', serialize($data));
  2131. $query->bindValue(':time', time());
  2132. if ($query->execute())
  2133. {
  2134. return true;
  2135. }
  2136. }
  2137. }
  2138. }
  2139. return false;
  2140. }
  2141. public function load()
  2142. {
  2143. if ($this->mysql === null)
  2144. {
  2145. return false;
  2146. }
  2147. $query = $this->mysql->prepare('SELECT `items`, `data` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
  2148. $query->bindValue(':id', $this->id);
  2149. if ($query->execute() && ($row = $query->fetch()))
  2150. {
  2151. $data = unserialize($row[1]);
  2152. if (isset($this->options['items'][0]))
  2153. {
  2154. $items = (int) $this->options['items'][0];
  2155. }
  2156. else
  2157. {
  2158. $items = (int) $row[0];
  2159. }
  2160. if ($items !== 0)
  2161. {
  2162. if (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
  2163. {
  2164. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
  2165. }
  2166. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
  2167. {
  2168. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
  2169. }
  2170. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
  2171. {
  2172. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
  2173. }
  2174. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]))
  2175. {
  2176. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0];
  2177. }
  2178. else
  2179. {
  2180. $feed = null;
  2181. }
  2182. if ($feed !== null)
  2183. {
  2184. $sql = 'SELECT `data` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :feed ORDER BY `posted` DESC';
  2185. if ($items > 0)
  2186. {
  2187. $sql .= ' LIMIT ' . $items;
  2188. }
  2189. $query = $this->mysql->prepare($sql);
  2190. $query->bindValue(':feed', $this->id);
  2191. if ($query->execute())
  2192. {
  2193. while ($row = $query->fetchColumn())
  2194. {
  2195. $feed['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry'][] = unserialize($row);
  2196. }
  2197. }
  2198. else
  2199. {
  2200. return false;
  2201. }
  2202. }
  2203. }
  2204. return $data;
  2205. }
  2206. return false;
  2207. }
  2208. public function mtime()
  2209. {
  2210. if ($this->mysql === null)
  2211. {
  2212. return false;
  2213. }
  2214. $query = $this->mysql->prepare('SELECT `mtime` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
  2215. $query->bindValue(':id', $this->id);
  2216. if ($query->execute() && ($time = $query->fetchColumn()))
  2217. {
  2218. return $time;
  2219. }
  2220. else
  2221. {
  2222. return false;
  2223. }
  2224. }
  2225. public function touch()
  2226. {
  2227. if ($this->mysql === null)
  2228. {
  2229. return false;
  2230. }
  2231. $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `mtime` = :time WHERE `id` = :id');
  2232. $query->bindValue(':time', time());
  2233. $query->bindValue(':id', $this->id);
  2234. if ($query->execute() && $query->rowCount() > 0)
  2235. {
  2236. return true;
  2237. }
  2238. else
  2239. {
  2240. return false;
  2241. }
  2242. }
  2243. public function unlink()
  2244. {
  2245. if ($this->mysql === null)
  2246. {
  2247. return false;
  2248. }
  2249. $query = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
  2250. $query->bindValue(':id', $this->id);
  2251. $query2 = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :id');
  2252. $query2->bindValue(':id', $this->id);
  2253. if ($query->execute() && $query2->execute())
  2254. {
  2255. return true;
  2256. }
  2257. else
  2258. {
  2259. return false;
  2260. }
  2261. }
  2262. }
  2263. class SimplePie_Cache
  2264. {
  2265. protected static $handlers = array(
  2266. 'mysql' => 'SimplePie_Cache_MySQL',
  2267. 'memcache' => 'SimplePie_Cache_Memcache',
  2268. );
  2269. private function __construct() { }
  2270. public static function create($location, $filename, $extension)
  2271. {
  2272. $type = explode(':', $location, 2);
  2273. $type = $type[0];
  2274. if (!empty(self::$handlers[$type]))
  2275. {
  2276. $class = self::$handlers[$type];
  2277. return new $class($location, $filename, $extension);
  2278. }
  2279. return new SimplePie_Cache_File($location, $filename, $extension);
  2280. }
  2281. public static function register($type, $class)
  2282. {
  2283. self::$handlers[$type] = $class;
  2284. }
  2285. public static function parse_URL($url)
  2286. {
  2287. $params = parse_url($url);
  2288. $params['extras'] = array();
  2289. if (isset($params['query']))
  2290. {
  2291. parse_str($params['query'], $params['extras']);
  2292. }
  2293. return $params;
  2294. }
  2295. }
  2296. class SimplePie_Caption
  2297. {
  2298. var $type;
  2299. var $lang;
  2300. var $startTime;
  2301. var $endTime;
  2302. var $text;
  2303. public function __construct($type = null, $lang = null, $startTime = null, $endTime = null, $text = null)
  2304. {
  2305. $this->type = $type;
  2306. $this->lang = $lang;
  2307. $this->startTime = $startTime;
  2308. $this->endTime = $endTime;
  2309. $this->text = $text;
  2310. }
  2311. public function __toString()
  2312. {
  2313. // There is no $this->data here
  2314. return md5(serialize($this));
  2315. }
  2316. public function get_endtime()
  2317. {
  2318. if ($this->endTime !== null)
  2319. {
  2320. return $this->endTime;
  2321. }
  2322. else
  2323. {
  2324. return null;
  2325. }
  2326. }
  2327. public function get_language()
  2328. {
  2329. if ($this->lang !== null)
  2330. {
  2331. return $this->lang;
  2332. }
  2333. else
  2334. {
  2335. return null;
  2336. }
  2337. }
  2338. public function get_starttime()
  2339. {
  2340. if ($this->startTime !== null)
  2341. {
  2342. return $this->startTime;
  2343. }
  2344. else
  2345. {
  2346. return null;
  2347. }
  2348. }
  2349. public function get_text()
  2350. {
  2351. if ($this->text !== null)
  2352. {
  2353. return $this->text;
  2354. }
  2355. else
  2356. {
  2357. return null;
  2358. }
  2359. }
  2360. public function get_type()
  2361. {
  2362. if ($this->type !== null)
  2363. {
  2364. return $this->type;
  2365. }
  2366. else
  2367. {
  2368. return null;
  2369. }
  2370. }
  2371. }
  2372. class SimplePie_Category
  2373. {
  2374. var $term;
  2375. var $scheme;
  2376. var $label;
  2377. public function __construct($term = null, $scheme = null, $label = null)
  2378. {
  2379. $this->term = $term;
  2380. $this->scheme = $scheme;
  2381. $this->label = $label;
  2382. }
  2383. public function __toString()
  2384. {
  2385. // There is no $this->data here
  2386. return md5(serialize($this));
  2387. }
  2388. public function get_term()
  2389. {
  2390. if ($this->term !== null)
  2391. {
  2392. return $this->term;
  2393. }
  2394. else
  2395. {
  2396. return null;
  2397. }
  2398. }
  2399. public function get_scheme()
  2400. {
  2401. if ($this->scheme !== null)
  2402. {
  2403. return $this->scheme;
  2404. }
  2405. else
  2406. {
  2407. return null;
  2408. }
  2409. }
  2410. public function get_label()
  2411. {
  2412. if ($this->label !== null)
  2413. {
  2414. return $this->label;
  2415. }
  2416. else
  2417. {
  2418. return $this->get_term();
  2419. }
  2420. }
  2421. }
  2422. class SimplePie_Content_Type_Sniffer
  2423. {
  2424. var $file;
  2425. public function __construct($file)
  2426. {
  2427. $this->file = $file;
  2428. }
  2429. public function get_type()
  2430. {
  2431. if (isset($this->file->headers['content-type']))
  2432. {
  2433. if (!isset($this->file->headers['content-encoding'])
  2434. && ($this->file->headers['content-type'] === 'text/plain'
  2435. || $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1'
  2436. || $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1'
  2437. || $this->file->headers['content-type'] === 'text/plain; charset=UTF-8'))
  2438. {
  2439. return $this->text_or_binary();
  2440. }
  2441. if (($pos = strpos($this->file->headers['content-type'], ';')) !== false)
  2442. {
  2443. $official = substr($this->file->headers['content-type'], 0, $pos);
  2444. }
  2445. else
  2446. {
  2447. $official = $this->file->headers['content-type'];
  2448. }
  2449. $official = trim(strtolower($official));
  2450. if ($official === 'unknown/unknown'
  2451. || $official === 'application/unknown')
  2452. {
  2453. return $this->unknown();
  2454. }
  2455. elseif (substr($official, -4) === '+xml'
  2456. || $official === 'text/xml'
  2457. || $official === 'application/xml')
  2458. {
  2459. return $official;
  2460. }
  2461. elseif (substr($official, 0, 6) === 'image/')
  2462. {
  2463. if ($return = $this->image())
  2464. {
  2465. return $return;
  2466. }
  2467. else
  2468. {
  2469. return $official;
  2470. }
  2471. }
  2472. elseif ($official === 'text/html')
  2473. {
  2474. return $this->feed_or_html();
  2475. }
  2476. else
  2477. {
  2478. return $official;
  2479. }
  2480. }
  2481. else
  2482. {
  2483. return $this->unknown();
  2484. }
  2485. }
  2486. public function text_or_binary()
  2487. {
  2488. if (substr($this->file->body, 0, 2) === "\xFE\xFF"
  2489. || substr($this->file->body, 0, 2) === "\xFF\xFE"
  2490. || substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF"
  2491. || substr($this->file->body, 0, 3) === "\xEF\xBB\xBF")
  2492. {
  2493. return 'text/plain';
  2494. }
  2495. elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body))
  2496. {
  2497. return 'application/octect-stream';
  2498. }
  2499. else
  2500. {
  2501. return 'text/plain';
  2502. }
  2503. }
  2504. public function unknown()
  2505. {
  2506. $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20");
  2507. if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html'
  2508. || strtolower(substr($this->file->body, $ws, 5)) === '<html'
  2509. || strtolower(substr($this->file->body, $ws, 7)) === '<script')
  2510. {
  2511. return 'text/html';
  2512. }
  2513. elseif (substr($this->file->body, 0, 5) === '%PDF-')
  2514. {
  2515. return 'application/pdf';
  2516. }
  2517. elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-')
  2518. {
  2519. return 'application/postscript';
  2520. }
  2521. elseif (substr($this->file->body, 0, 6) === 'GIF87a'
  2522. || substr($this->file->body, 0, 6) === 'GIF89a')
  2523. {
  2524. return 'image/gif';
  2525. }
  2526. elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
  2527. {
  2528. return 'image/png';
  2529. }
  2530. elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
  2531. {
  2532. return 'image/jpeg';
  2533. }
  2534. elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
  2535. {
  2536. return 'image/bmp';
  2537. }
  2538. elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
  2539. {
  2540. return 'image/vnd.microsoft.icon';
  2541. }
  2542. else
  2543. {
  2544. return $this->text_or_binary();
  2545. }
  2546. }
  2547. public function image()
  2548. {
  2549. if (substr($this->file->body, 0, 6) === 'GIF87a'
  2550. || substr($this->file->body, 0, 6) === 'GIF89a')
  2551. {
  2552. return 'image/gif';
  2553. }
  2554. elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
  2555. {
  2556. return 'image/png';
  2557. }
  2558. elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
  2559. {
  2560. return 'image/jpeg';
  2561. }
  2562. elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
  2563. {
  2564. return 'image/bmp';
  2565. }
  2566. elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
  2567. {
  2568. return 'image/vnd.microsoft.icon';
  2569. }
  2570. else
  2571. {
  2572. return false;
  2573. }
  2574. }
  2575. public function feed_or_html()
  2576. {
  2577. $len = strlen($this->file->body);
  2578. $pos = strspn($this->file->body, "\x09\x0A\x0D\x20");
  2579. while ($pos < $len)
  2580. {
  2581. switch ($this->file->body[$pos])
  2582. {
  2583. case "\x09":
  2584. case "\x0A":
  2585. case "\x0D":
  2586. case "\x20":
  2587. $pos += strspn($this->file->body, "\x09\x0A\x0D\x20", $pos);
  2588. continue 2;
  2589. case '<':
  2590. $pos++;
  2591. break;
  2592. default:
  2593. return 'text/html';
  2594. }
  2595. if (substr($this->file->body, $pos, 3) === '!--')
  2596. {
  2597. $pos += 3;
  2598. if ($pos < $len && ($pos = strpos($this->file->body, '-->', $pos)) !== false)
  2599. {
  2600. $pos += 3;
  2601. }
  2602. else
  2603. {
  2604. return 'text/html';
  2605. }
  2606. }
  2607. elseif (substr($this->file->body, $pos, 1) === '!')
  2608. {
  2609. if ($pos < $len && ($pos = strpos($this->file->body, '>', $pos)) !== false)
  2610. {
  2611. $pos++;
  2612. }
  2613. else
  2614. {
  2615. return 'text/html';
  2616. }
  2617. }
  2618. elseif (substr($this->file->body, $pos, 1) === '?')
  2619. {
  2620. if ($pos < $len && ($pos = strpos($this->file->body, '?>', $pos)) !== false)
  2621. {
  2622. $pos += 2;
  2623. }
  2624. else
  2625. {
  2626. return 'text/html';
  2627. }
  2628. }
  2629. elseif (substr($this->file->body, $pos, 3) === 'rss'
  2630. || substr($this->file->body, $pos, 7) === 'rdf:RDF')
  2631. {
  2632. return 'application/rss+xml';
  2633. }
  2634. elseif (substr($this->file->body, $pos, 4) === 'feed')
  2635. {
  2636. return 'application/atom+xml';
  2637. }
  2638. else
  2639. {
  2640. return 'text/html';
  2641. }
  2642. }
  2643. return 'text/html';
  2644. }
  2645. }
  2646. class SimplePie_Copyright
  2647. {
  2648. var $url;
  2649. var $label;
  2650. public function __construct($url = null, $label = null)
  2651. {
  2652. $this->url = $url;
  2653. $this->label = $label;
  2654. }
  2655. public function __toString()
  2656. {
  2657. // There is no $this->data here
  2658. return md5(serialize($this));
  2659. }
  2660. public function get_url()
  2661. {
  2662. if ($this->url !== null)
  2663. {
  2664. return $this->url;
  2665. }
  2666. else
  2667. {
  2668. return null;
  2669. }
  2670. }
  2671. public function get_attribution()
  2672. {
  2673. if ($this->label !== null)
  2674. {
  2675. return $this->label;
  2676. }
  2677. else
  2678. {
  2679. return null;
  2680. }
  2681. }
  2682. }
  2683. class SimplePie_Core extends SimplePie
  2684. {
  2685. }
  2686. class SimplePie_Credit
  2687. {
  2688. var $role;
  2689. var $scheme;
  2690. var $name;
  2691. public function __construct($role = null, $scheme = null, $name = null)
  2692. {
  2693. $this->role = $role;
  2694. $this->scheme = $scheme;
  2695. $this->name = $name;
  2696. }
  2697. public function __toString()
  2698. {
  2699. // There is no $this->data here
  2700. return md5(serialize($this));
  2701. }
  2702. public function get_role()
  2703. {
  2704. if ($this->role !== null)
  2705. {
  2706. return $this->role;
  2707. }
  2708. else
  2709. {
  2710. return null;
  2711. }
  2712. }
  2713. public function get_scheme()
  2714. {
  2715. if ($this->scheme !== null)
  2716. {
  2717. return $this->scheme;
  2718. }
  2719. else
  2720. {
  2721. return null;
  2722. }
  2723. }
  2724. public function get_name()
  2725. {
  2726. if ($this->name !== null)
  2727. {
  2728. return $this->name;
  2729. }
  2730. else
  2731. {
  2732. return null;
  2733. }
  2734. }
  2735. }
  2736. class SimplePie_Decode_HTML_Entities
  2737. {
  2738. var $data = '';
  2739. var $consumed = '';
  2740. var $position = 0;
  2741. public function __construct($data)
  2742. {
  2743. $this->data = $data;
  2744. }
  2745. public function parse()
  2746. {
  2747. while (($this->position = strpos($this->data, '&', $this->position)) !== false)
  2748. {
  2749. $this->consume();
  2750. $this->entity();
  2751. $this->consumed = '';
  2752. }
  2753. return $this->data;
  2754. }
  2755. public function consume()
  2756. {
  2757. if (isset($this->data[$this->position]))
  2758. {
  2759. $this->consumed .= $this->data[$this->position];
  2760. return $this->data[$this->position++];
  2761. }
  2762. else
  2763. {
  2764. return false;
  2765. }
  2766. }
  2767. public function consume_range($chars)
  2768. {
  2769. if ($len = strspn($this->data, $chars, $this->position))
  2770. {
  2771. $data = substr($this->data, $this->position, $len);
  2772. $this->consumed .= $data;
  2773. $this->position += $len;
  2774. return $data;
  2775. }
  2776. else
  2777. {
  2778. return false;
  2779. }
  2780. }
  2781. public function unconsume()
  2782. {
  2783. $this->consumed = substr($this->consumed, 0, -1);
  2784. $this->position--;
  2785. }
  2786. public function entity()
  2787. {
  2788. switch ($this->consume())
  2789. {
  2790. case "\x09":
  2791. case "\x0A":
  2792. case "\x0B":
  2793. case "\x0B":
  2794. case "\x0C":
  2795. case "\x20":
  2796. case "\x3C":
  2797. case "\x26":
  2798. case false:
  2799. break;
  2800. case "\x23":
  2801. switch ($this->consume())
  2802. {
  2803. case "\x78":
  2804. case "\x58":
  2805. $range = '0123456789ABCDEFabcdef';
  2806. $hex = true;
  2807. break;
  2808. default:
  2809. $range = '0123456789';
  2810. $hex = false;
  2811. $this->unconsume();
  2812. break;
  2813. }
  2814. if ($codepoint = $this->consume_range($range))
  2815. {
  2816. 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");
  2817. if ($hex)
  2818. {
  2819. $codepoint = hexdec($codepoint);
  2820. }
  2821. else
  2822. {
  2823. $codepoint = intval($codepoint);
  2824. }
  2825. if (isset($windows_1252_specials[$codepoint]))
  2826. {
  2827. $replacement = $windows_1252_specials[$codepoint];
  2828. }
  2829. else
  2830. {
  2831. $replacement = SimplePie_Misc::codepoint_to_utf8($codepoint);
  2832. }
  2833. if (!in_array($this->consume(), array(';', false), true))
  2834. {
  2835. $this->unconsume();
  2836. }
  2837. $consumed_length = strlen($this->consumed);
  2838. $this->data = substr_replace($this->data, $replacement, $this->position - $consumed_length, $consumed_length);
  2839. $this->position += strlen($replacement) - $consumed_length;
  2840. }
  2841. break;
  2842. default:
  2843. static $entities = array(
  2844. 'Aacute' => "\xC3\x81",
  2845. 'aacute' => "\xC3\xA1",
  2846. 'Aacute;' => "\xC3\x81",
  2847. 'aacute;' => "\xC3\xA1",
  2848. 'Acirc' => "\xC3\x82",
  2849. 'acirc' => "\xC3\xA2",
  2850. 'Acirc;' => "\xC3\x82",
  2851. 'acirc;' => "\xC3\xA2",
  2852. 'acute' => "\xC2\xB4",
  2853. 'acute;' => "\xC2\xB4",
  2854. 'AElig' => "\xC3\x86",
  2855. 'aelig' => "\xC3\xA6",
  2856. 'AElig;' => "\xC3\x86",
  2857. 'aelig;' => "\xC3\xA6",
  2858. 'Agrave' => "\xC3\x80",
  2859. 'agrave' => "\xC3\xA0",
  2860. 'Agrave;' => "\xC3\x80",
  2861. 'agrave;' => "\xC3\xA0",
  2862. 'alefsym;' => "\xE2\x84\xB5",
  2863. 'Alpha;' => "\xCE\x91",
  2864. 'alpha;' => "\xCE\xB1",
  2865. 'AMP' => "\x26",
  2866. 'amp' => "\x26",
  2867. 'AMP;' => "\x26",
  2868. 'amp;' => "\x26",
  2869. 'and;' => "\xE2\x88\xA7",
  2870. 'ang;' => "\xE2\x88\xA0",
  2871. 'apos;' => "\x27",
  2872. 'Aring' => "\xC3\x85",
  2873. 'aring' => "\xC3\xA5",
  2874. 'Aring;' => "\xC3\x85",
  2875. 'aring;' => "\xC3\xA5",
  2876. 'asymp;' => "\xE2\x89\x88",
  2877. 'Atilde' => "\xC3\x83",
  2878. 'atilde' => "\xC3\xA3",
  2879. 'Atilde;' => "\xC3\x83",
  2880. 'atilde;' => "\xC3\xA3",
  2881. 'Auml' => "\xC3\x84",
  2882. 'auml' => "\xC3\xA4",
  2883. 'Auml;' => "\xC3\x84",
  2884. 'auml;' => "\xC3\xA4",
  2885. 'bdquo;' => "\xE2\x80\x9E",
  2886. 'Beta;' => "\xCE\x92",
  2887. 'beta;' => "\xCE\xB2",
  2888. 'brvbar' => "\xC2\xA6",
  2889. 'brvbar;' => "\xC2\xA6",
  2890. 'bull;' => "\xE2\x80\xA2",
  2891. 'cap;' => "\xE2\x88\xA9",
  2892. 'Ccedil' => "\xC3\x87",
  2893. 'ccedil' => "\xC3\xA7",
  2894. 'Ccedil;' => "\xC3\x87",
  2895. 'ccedil;' => "\xC3\xA7",
  2896. 'cedil' => "\xC2\xB8",
  2897. 'cedil;' => "\xC2\xB8",
  2898. 'cent' => "\xC2\xA2",
  2899. 'cent;' => "\xC2\xA2",
  2900. 'Chi;' => "\xCE\xA7",
  2901. 'chi;' => "\xCF\x87",
  2902. 'circ;' => "\xCB\x86",
  2903. 'clubs;' => "\xE2\x99\xA3",
  2904. 'cong;' => "\xE2\x89\x85",
  2905. 'COPY' => "\xC2\xA9",
  2906. 'copy' => "\xC2\xA9",
  2907. 'COPY;' => "\xC2\xA9",
  2908. 'copy;' => "\xC2\xA9",
  2909. 'crarr;' => "\xE2\x86\xB5",
  2910. 'cup;' => "\xE2\x88\xAA",
  2911. 'curren' => "\xC2\xA4",
  2912. 'curren;' => "\xC2\xA4",
  2913. 'Dagger;' => "\xE2\x80\xA1",
  2914. 'dagger;' => "\xE2\x80\xA0",
  2915. 'dArr;' => "\xE2\x87\x93",
  2916. 'darr;' => "\xE2\x86\x93",
  2917. 'deg' => "\xC2\xB0",
  2918. 'deg;' => "\xC2\xB0",
  2919. 'Delta;' => "\xCE\x94",
  2920. 'delta;' => "\xCE\xB4",
  2921. 'diams;' => "\xE2\x99\xA6",
  2922. 'divide' => "\xC3\xB7",
  2923. 'divide;' => "\xC3\xB7",
  2924. 'Eacute' => "\xC3\x89",
  2925. 'eacute' => "\xC3\xA9",
  2926. 'Eacute;' => "\xC3\x89",
  2927. 'eacute;' => "\xC3\xA9",
  2928. 'Ecirc' => "\xC3\x8A",
  2929. 'ecirc' => "\xC3\xAA",
  2930. 'Ecirc;' => "\xC3\x8A",
  2931. 'ecirc;' => "\xC3\xAA",
  2932. 'Egrave' => "\xC3\x88",
  2933. 'egrave' => "\xC3\xA8",
  2934. 'Egrave;' => "\xC3\x88",
  2935. 'egrave;' => "\xC3\xA8",
  2936. 'empty;' => "\xE2\x88\x85",
  2937. 'emsp;' => "\xE2\x80\x83",
  2938. 'ensp;' => "\xE2\x80\x82",
  2939. 'Epsilon;' => "\xCE\x95",
  2940. 'epsilon;' => "\xCE\xB5",
  2941. 'equiv;' => "\xE2\x89\xA1",
  2942. 'Eta;' => "\xCE\x97",
  2943. 'eta;' => "\xCE\xB7",
  2944. 'ETH' => "\xC3\x90",
  2945. 'eth' => "\xC3\xB0",
  2946. 'ETH;' => "\xC3\x90",
  2947. 'eth;' => "\xC3\xB0",
  2948. 'Euml' => "\xC3\x8B",
  2949. 'euml' => "\xC3\xAB",
  2950. 'Euml;' => "\xC3\x8B",
  2951. 'euml;' => "\xC3\xAB",
  2952. 'euro;' => "\xE2\x82\xAC",
  2953. 'exist;' => "\xE2\x88\x83",
  2954. 'fnof;' => "\xC6\x92",
  2955. 'forall;' => "\xE2\x88\x80",
  2956. 'frac12' => "\xC2\xBD",
  2957. 'frac12;' => "\xC2\xBD",
  2958. 'frac14' => "\xC2\xBC",
  2959. 'frac14;' => "\xC2\xBC",
  2960. 'frac34' => "\xC2\xBE",
  2961. 'frac34;' => "\xC2\xBE",
  2962. 'frasl;' => "\xE2\x81\x84",
  2963. 'Gamma;' => "\xCE\x93",
  2964. 'gamma;' => "\xCE\xB3",
  2965. 'ge;' => "\xE2\x89\xA5",
  2966. 'GT' => "\x3E",
  2967. 'gt' => "\x3E",
  2968. 'GT;' => "\x3E",
  2969. 'gt;' => "\x3E",
  2970. 'hArr;' => "\xE2\x87\x94",
  2971. 'harr;' => "\xE2\x86\x94",
  2972. 'hearts;' => "\xE2\x99\xA5",
  2973. 'hellip;' => "\xE2\x80\xA6",
  2974. 'Iacute' => "\xC3\x8D",
  2975. 'iacute' => "\xC3\xAD",
  2976. 'Iacute;' => "\xC3\x8D",
  2977. 'iacute;' => "\xC3\xAD",
  2978. 'Icirc' => "\xC3\x8E",
  2979. 'icirc' => "\xC3\xAE",
  2980. 'Icirc;' => "\xC3\x8E",
  2981. 'icirc;' => "\xC3\xAE",
  2982. 'iexcl' => "\xC2\xA1",
  2983. 'iexcl;' => "\xC2\xA1",
  2984. 'Igrave' => "\xC3\x8C",
  2985. 'igrave' => "\xC3\xAC",
  2986. 'Igrave;' => "\xC3\x8C",
  2987. 'igrave;' => "\xC3\xAC",
  2988. 'image;' => "\xE2\x84\x91",
  2989. 'infin;' => "\xE2\x88\x9E",
  2990. 'int;' => "\xE2\x88\xAB",
  2991. 'Iota;' => "\xCE\x99",
  2992. 'iota;' => "\xCE\xB9",
  2993. 'iquest' => "\xC2\xBF",
  2994. 'iquest;' => "\xC2\xBF",
  2995. 'isin;' => "\xE2\x88\x88",
  2996. 'Iuml' => "\xC3\x8F",
  2997. 'iuml' => "\xC3\xAF",
  2998. 'Iuml;' => "\xC3\x8F",
  2999. 'iuml;' => "\xC3\xAF",
  3000. 'Kappa;' => "\xCE\x9A",
  3001. 'kappa;' => "\xCE\xBA",
  3002. 'Lambda;' => "\xCE\x9B",
  3003. 'lambda;' => "\xCE\xBB",
  3004. 'lang;' => "\xE3\x80\x88",
  3005. 'laquo' => "\xC2\xAB",
  3006. 'laquo;' => "\xC2\xAB",
  3007. 'lArr;' => "\xE2\x87\x90",
  3008. 'larr;' => "\xE2\x86\x90",
  3009. 'lceil;' => "\xE2\x8C\x88",
  3010. 'ldquo;' => "\xE2\x80\x9C",
  3011. 'le;' => "\xE2\x89\xA4",
  3012. 'lfloor;' => "\xE2\x8C\x8A",
  3013. 'lowast;' => "\xE2\x88\x97",
  3014. 'loz;' => "\xE2\x97\x8A",
  3015. 'lrm;' => "\xE2\x80\x8E",
  3016. 'lsaquo;' => "\xE2\x80\xB9",
  3017. 'lsquo;' => "\xE2\x80\x98",
  3018. 'LT' => "\x3C",
  3019. 'lt' => "\x3C",
  3020. 'LT;' => "\x3C",
  3021. 'lt;' => "\x3C",
  3022. 'macr' => "\xC2\xAF",
  3023. 'macr;' => "\xC2\xAF",
  3024. 'mdash;' => "\xE2\x80\x94",
  3025. 'micro' => "\xC2\xB5",
  3026. 'micro;' => "\xC2\xB5",
  3027. 'middot' => "\xC2\xB7",
  3028. 'middot;' => "\xC2\xB7",
  3029. 'minus;' => "\xE2\x88\x92",
  3030. 'Mu;' => "\xCE\x9C",
  3031. 'mu;' => "\xCE\xBC",
  3032. 'nabla;' => "\xE2\x88\x87",
  3033. 'nbsp' => "\xC2\xA0",
  3034. 'nbsp;' => "\xC2\xA0",
  3035. 'ndash;' => "\xE2\x80\x93",
  3036. 'ne;' => "\xE2\x89\xA0",
  3037. 'ni;' => "\xE2\x88\x8B",
  3038. 'not' => "\xC2\xAC",
  3039. 'not;' => "\xC2\xAC",
  3040. 'notin;' => "\xE2\x88\x89",
  3041. 'nsub;' => "\xE2\x8A\x84",
  3042. 'Ntilde' => "\xC3\x91",
  3043. 'ntilde' => "\xC3\xB1",
  3044. 'Ntilde;' => "\xC3\x91",
  3045. 'ntilde;' => "\xC3\xB1",
  3046. 'Nu;' => "\xCE\x9D",
  3047. 'nu;' => "\xCE\xBD",
  3048. 'Oacute' => "\xC3\x93",
  3049. 'oacute' => "\xC3\xB3",
  3050. 'Oacute;' => "\xC3\x93",
  3051. 'oacute;' => "\xC3\xB3",
  3052. 'Ocirc' => "\xC3\x94",
  3053. 'ocirc' => "\xC3\xB4",
  3054. 'Ocirc;' => "\xC3\x94",
  3055. 'ocirc;' => "\xC3\xB4",
  3056. 'OElig;' => "\xC5\x92",
  3057. 'oelig;' => "\xC5\x93",
  3058. 'Ograve' => "\xC3\x92",
  3059. 'ograve' => "\xC3\xB2",
  3060. 'Ograve;' => "\xC3\x92",
  3061. 'ograve;' => "\xC3\xB2",
  3062. 'oline;' => "\xE2\x80\xBE",
  3063. 'Omega;' => "\xCE\xA9",
  3064. 'omega;' => "\xCF\x89",
  3065. 'Omicron;' => "\xCE\x9F",
  3066. 'omicron;' => "\xCE\xBF",
  3067. 'oplus;' => "\xE2\x8A\x95",
  3068. 'or;' => "\xE2\x88\xA8",
  3069. 'ordf' => "\xC2\xAA",
  3070. 'ordf;' => "\xC2\xAA",
  3071. 'ordm' => "\xC2\xBA",
  3072. 'ordm;' => "\xC2\xBA",
  3073. 'Oslash' => "\xC3\x98",
  3074. 'oslash' => "\xC3\xB8",
  3075. 'Oslash;' => "\xC3\x98",
  3076. 'oslash;' => "\xC3\xB8",
  3077. 'Otilde' => "\xC3\x95",
  3078. 'otilde' => "\xC3\xB5",
  3079. 'Otilde;' => "\xC3\x95",
  3080. 'otilde;' => "\xC3\xB5",
  3081. 'otimes;' => "\xE2\x8A\x97",
  3082. 'Ouml' => "\xC3\x96",
  3083. 'ouml' => "\xC3\xB6",
  3084. 'Ouml;' => "\xC3\x96",
  3085. 'ouml;' => "\xC3\xB6",
  3086. 'para' => "\xC2\xB6",
  3087. 'para;' => "\xC2\xB6",
  3088. 'part;' => "\xE2\x88\x82",
  3089. 'permil;' => "\xE2\x80\xB0",
  3090. 'perp;' => "\xE2\x8A\xA5",
  3091. 'Phi;' => "\xCE\xA6",
  3092. 'phi;' => "\xCF\x86",
  3093. 'Pi;' => "\xCE\xA0",
  3094. 'pi;' => "\xCF\x80",
  3095. 'piv;' => "\xCF\x96",
  3096. 'plusmn' => "\xC2\xB1",
  3097. 'plusmn;' => "\xC2\xB1",
  3098. 'pound' => "\xC2\xA3",
  3099. 'pound;' => "\xC2\xA3",
  3100. 'Prime;' => "\xE2\x80\xB3",
  3101. 'prime;' => "\xE2\x80\xB2",
  3102. 'prod;' => "\xE2\x88\x8F",
  3103. 'prop;' => "\xE2\x88\x9D",
  3104. 'Psi;' => "\xCE\xA8",
  3105. 'psi;' => "\xCF\x88",
  3106. 'QUOT' => "\x22",
  3107. 'quot' => "\x22",
  3108. 'QUOT;' => "\x22",
  3109. 'quot;' => "\x22",
  3110. 'radic;' => "\xE2\x88\x9A",
  3111. 'rang;' => "\xE3\x80\x89",
  3112. 'raquo' => "\xC2\xBB",
  3113. 'raquo;' => "\xC2\xBB",
  3114. 'rArr;' => "\xE2\x87\x92",
  3115. 'rarr;' => "\xE2\x86\x92",
  3116. 'rceil;' => "\xE2\x8C\x89",
  3117. 'rdquo;' => "\xE2\x80\x9D",
  3118. 'real;' => "\xE2\x84\x9C",
  3119. 'REG' => "\xC2\xAE",
  3120. 'reg' => "\xC2\xAE",
  3121. 'REG;' => "\xC2\xAE",
  3122. 'reg;' => "\xC2\xAE",
  3123. 'rfloor;' => "\xE2\x8C\x8B",
  3124. 'Rho;' => "\xCE\xA1",
  3125. 'rho;' => "\xCF\x81",
  3126. 'rlm;' => "\xE2\x80\x8F",
  3127. 'rsaquo;' => "\xE2\x80\xBA",
  3128. 'rsquo;' => "\xE2\x80\x99",
  3129. 'sbquo;' => "\xE2\x80\x9A",
  3130. 'Scaron;' => "\xC5\xA0",
  3131. 'scaron;' => "\xC5\xA1",
  3132. 'sdot;' => "\xE2\x8B\x85",
  3133. 'sect' => "\xC2\xA7",
  3134. 'sect;' => "\xC2\xA7",
  3135. 'shy' => "\xC2\xAD",
  3136. 'shy;' => "\xC2\xAD",
  3137. 'Sigma;' => "\xCE\xA3",
  3138. 'sigma;' => "\xCF\x83",
  3139. 'sigmaf;' => "\xCF\x82",
  3140. 'sim;' => "\xE2\x88\xBC",
  3141. 'spades;' => "\xE2\x99\xA0",
  3142. 'sub;' => "\xE2\x8A\x82",
  3143. 'sube;' => "\xE2\x8A\x86",
  3144. 'sum;' => "\xE2\x88\x91",
  3145. 'sup;' => "\xE2\x8A\x83",
  3146. 'sup1' => "\xC2\xB9",
  3147. 'sup1;' => "\xC2\xB9",
  3148. 'sup2' => "\xC2\xB2",
  3149. 'sup2;' => "\xC2\xB2",
  3150. 'sup3' => "\xC2\xB3",
  3151. 'sup3;' => "\xC2\xB3",
  3152. 'supe;' => "\xE2\x8A\x87",
  3153. 'szlig' => "\xC3\x9F",
  3154. 'szlig;' => "\xC3\x9F",
  3155. 'Tau;' => "\xCE\xA4",
  3156. 'tau;' => "\xCF\x84",
  3157. 'there4;' => "\xE2\x88\xB4",
  3158. 'Theta;' => "\xCE\x98",
  3159. 'theta;' => "\xCE\xB8",
  3160. 'thetasym;' => "\xCF\x91",
  3161. 'thinsp;' => "\xE2\x80\x89",
  3162. 'THORN' => "\xC3\x9E",
  3163. 'thorn' => "\xC3\xBE",
  3164. 'THORN;' => "\xC3\x9E",
  3165. 'thorn;' => "\xC3\xBE",
  3166. 'tilde;' => "\xCB\x9C",
  3167. 'times' => "\xC3\x97",
  3168. 'times;' => "\xC3\x97",
  3169. 'TRADE;' => "\xE2\x84\xA2",
  3170. 'trade;' => "\xE2\x84\xA2",
  3171. 'Uacute' => "\xC3\x9A",
  3172. 'uacute' => "\xC3\xBA",
  3173. 'Uacute;' => "\xC3\x9A",
  3174. 'uacute;' => "\xC3\xBA",
  3175. 'uArr;' => "\xE2\x87\x91",
  3176. 'uarr;' => "\xE2\x86\x91",
  3177. 'Ucirc' => "\xC3\x9B",
  3178. 'ucirc' => "\xC3\xBB",
  3179. 'Ucirc;' => "\xC3\x9B",
  3180. 'ucirc;' => "\xC3\xBB",
  3181. 'Ugrave' => "\xC3\x99",
  3182. 'ugrave' => "\xC3\xB9",
  3183. 'Ugrave;' => "\xC3\x99",
  3184. 'ugrave;' => "\xC3\xB9",
  3185. 'uml' => "\xC2\xA8",
  3186. 'uml;' => "\xC2\xA8",
  3187. 'upsih;' => "\xCF\x92",
  3188. 'Upsilon;' => "\xCE\xA5",
  3189. 'upsilon;' => "\xCF\x85",
  3190. 'Uuml' => "\xC3\x9C",
  3191. 'uuml' => "\xC3\xBC",
  3192. 'Uuml;' => "\xC3\x9C",
  3193. 'uuml;' => "\xC3\xBC",
  3194. 'weierp;' => "\xE2\x84\x98",
  3195. 'Xi;' => "\xCE\x9E",
  3196. 'xi;' => "\xCE\xBE",
  3197. 'Yacute' => "\xC3\x9D",
  3198. 'yacute' => "\xC3\xBD",
  3199. 'Yacute;' => "\xC3\x9D",
  3200. 'yacute;' => "\xC3\xBD",
  3201. 'yen' => "\xC2\xA5",
  3202. 'yen;' => "\xC2\xA5",
  3203. 'yuml' => "\xC3\xBF",
  3204. 'Yuml;' => "\xC5\xB8",
  3205. 'yuml;' => "\xC3\xBF",
  3206. 'Zeta;' => "\xCE\x96",
  3207. 'zeta;' => "\xCE\xB6",
  3208. 'zwj;' => "\xE2\x80\x8D",
  3209. 'zwnj;' => "\xE2\x80\x8C"
  3210. );
  3211. for ($i = 0, $match = null; $i < 9 && $this->consume() !== false; $i++)
  3212. {
  3213. $consumed = substr($this->consumed, 1);
  3214. if (isset($entities[$consumed]))
  3215. {
  3216. $match = $consumed;
  3217. }
  3218. }
  3219. if ($match !== null)
  3220. {
  3221. $this->data = substr_replace($this->data, $entities[$match], $this->position - strlen($consumed) - 1, strlen($match) + 1);
  3222. $this->position += strlen($entities[$match]) - strlen($consumed) - 1;
  3223. }
  3224. break;
  3225. }
  3226. }
  3227. }
  3228. class SimplePie_Enclosure
  3229. {
  3230. var $bitrate;
  3231. var $captions;
  3232. var $categories;
  3233. var $channels;
  3234. var $copyright;
  3235. var $credits;
  3236. var $description;
  3237. var $duration;
  3238. var $expression;
  3239. var $framerate;
  3240. var $handler;
  3241. var $hashes;
  3242. var $height;
  3243. var $javascript;
  3244. var $keywords;
  3245. var $lang;
  3246. var $length;
  3247. var $link;
  3248. var $medium;
  3249. var $player;
  3250. var $ratings;
  3251. var $restrictions;
  3252. var $samplingrate;
  3253. var $thumbnails;
  3254. var $title;
  3255. var $type;
  3256. var $width;
  3257. 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)
  3258. {
  3259. $this->bitrate = $bitrate;
  3260. $this->captions = $captions;
  3261. $this->categories = $categories;
  3262. $this->channels = $channels;
  3263. $this->copyright = $copyright;
  3264. $this->credits = $credits;
  3265. $this->description = $description;
  3266. $this->duration = $duration;
  3267. $this->expression = $expression;
  3268. $this->framerate = $framerate;
  3269. $this->hashes = $hashes;
  3270. $this->height = $height;
  3271. $this->keywords = $keywords;
  3272. $this->lang = $lang;
  3273. $this->length = $length;
  3274. $this->link = $link;
  3275. $this->medium = $medium;
  3276. $this->player = $player;
  3277. $this->ratings = $ratings;
  3278. $this->restrictions = $restrictions;
  3279. $this->samplingrate = $samplingrate;
  3280. $this->thumbnails = $thumbnails;
  3281. $this->title = $title;
  3282. $this->type = $type;
  3283. $this->width = $width;
  3284. if (class_exists('idna_convert'))
  3285. {
  3286. $idn = new idna_convert();
  3287. $parsed = SimplePie_Misc::parse_url($link);
  3288. $this->link = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
  3289. }
  3290. $this->handler = $this->get_handler(); // Needs to load last
  3291. }
  3292. public function __toString()
  3293. {
  3294. // There is no $this->data here
  3295. return md5(serialize($this));
  3296. }
  3297. public function get_bitrate()
  3298. {
  3299. if ($this->bitrate !== null)
  3300. {
  3301. return $this->bitrate;
  3302. }
  3303. else
  3304. {
  3305. return null;
  3306. }
  3307. }
  3308. public function get_caption($key = 0)
  3309. {
  3310. $captions = $this->get_captions();
  3311. if (isset($captions[$key]))
  3312. {
  3313. return $captions[$key];
  3314. }
  3315. else
  3316. {
  3317. return null;
  3318. }
  3319. }
  3320. public function get_captions()
  3321. {
  3322. if ($this->captions !== null)
  3323. {
  3324. return $this->captions;
  3325. }
  3326. else
  3327. {
  3328. return null;
  3329. }
  3330. }
  3331. public function get_category($key = 0)
  3332. {
  3333. $categories = $this->get_categories();
  3334. if (isset($categories[$key]))
  3335. {
  3336. return $categories[$key];
  3337. }
  3338. else
  3339. {
  3340. return null;
  3341. }
  3342. }
  3343. public function get_categories()
  3344. {
  3345. if ($this->categories !== null)
  3346. {
  3347. return $this->categories;
  3348. }
  3349. else
  3350. {
  3351. return null;
  3352. }
  3353. }
  3354. public function get_channels()
  3355. {
  3356. if ($this->channels !== null)
  3357. {
  3358. return $this->channels;
  3359. }
  3360. else
  3361. {
  3362. return null;
  3363. }
  3364. }
  3365. public function get_copyright()
  3366. {
  3367. if ($this->copyright !== null)
  3368. {
  3369. return $this->copyright;
  3370. }
  3371. else
  3372. {
  3373. return null;
  3374. }
  3375. }
  3376. public function get_credit($key = 0)
  3377. {
  3378. $credits = $this->get_credits();
  3379. if (isset($credits[$key]))
  3380. {
  3381. return $credits[$key];
  3382. }
  3383. else
  3384. {
  3385. return null;
  3386. }
  3387. }
  3388. public function get_credits()
  3389. {
  3390. if ($this->credits !== null)
  3391. {
  3392. return $this->credits;
  3393. }
  3394. else
  3395. {
  3396. return null;
  3397. }
  3398. }
  3399. public function get_description()
  3400. {
  3401. if ($this->description !== null)
  3402. {
  3403. return $this->description;
  3404. }
  3405. else
  3406. {
  3407. return null;
  3408. }
  3409. }
  3410. public function get_duration($convert = false)
  3411. {
  3412. if ($this->duration !== null)
  3413. {
  3414. if ($convert)
  3415. {
  3416. $time = SimplePie_Misc::time_hms($this->duration);
  3417. return $time;
  3418. }
  3419. else
  3420. {
  3421. return $this->duration;
  3422. }
  3423. }
  3424. else
  3425. {
  3426. return null;
  3427. }
  3428. }
  3429. public function get_expression()
  3430. {
  3431. if ($this->expression !== null)
  3432. {
  3433. return $this->expression;
  3434. }
  3435. else
  3436. {
  3437. return 'full';
  3438. }
  3439. }
  3440. public function get_extension()
  3441. {
  3442. if ($this->link !== null)
  3443. {
  3444. $url = SimplePie_Misc::parse_url($this->link);
  3445. if ($url['path'] !== '')
  3446. {
  3447. return pathinfo($url['path'], PATHINFO_EXTENSION);
  3448. }
  3449. }
  3450. return null;
  3451. }
  3452. public function get_framerate()
  3453. {
  3454. if ($this->framerate !== null)
  3455. {
  3456. return $this->framerate;
  3457. }
  3458. else
  3459. {
  3460. return null;
  3461. }
  3462. }
  3463. public function get_handler()
  3464. {
  3465. return $this->get_real_type(true);
  3466. }
  3467. public function get_hash($key = 0)
  3468. {
  3469. $hashes = $this->get_hashes();
  3470. if (isset($hashes[$key]))
  3471. {
  3472. return $hashes[$key];
  3473. }
  3474. else
  3475. {
  3476. return null;
  3477. }
  3478. }
  3479. public function get_hashes()
  3480. {
  3481. if ($this->hashes !== null)
  3482. {
  3483. return $this->hashes;
  3484. }
  3485. else
  3486. {
  3487. return null;
  3488. }
  3489. }
  3490. public function get_height()
  3491. {
  3492. if ($this->height !== null)
  3493. {
  3494. return $this->height;
  3495. }
  3496. else
  3497. {
  3498. return null;
  3499. }
  3500. }
  3501. public function get_language()
  3502. {
  3503. if ($this->lang !== null)
  3504. {
  3505. return $this->lang;
  3506. }
  3507. else
  3508. {
  3509. return null;
  3510. }
  3511. }
  3512. public function get_keyword($key = 0)
  3513. {
  3514. $keywords = $this->get_keywords();
  3515. if (isset($keywords[$key]))
  3516. {
  3517. return $keywords[$key];
  3518. }
  3519. else
  3520. {
  3521. return null;
  3522. }
  3523. }
  3524. public function get_keywords()
  3525. {
  3526. if ($this->keywords !== null)
  3527. {
  3528. return $this->keywords;
  3529. }
  3530. else
  3531. {
  3532. return null;
  3533. }
  3534. }
  3535. public function get_length()
  3536. {
  3537. if ($this->length !== null)
  3538. {
  3539. return $this->length;
  3540. }
  3541. else
  3542. {
  3543. return null;
  3544. }
  3545. }
  3546. public function get_link()
  3547. {
  3548. if ($this->link !== null)
  3549. {
  3550. return urldecode($this->link);
  3551. }
  3552. else
  3553. {
  3554. return null;
  3555. }
  3556. }
  3557. public function get_medium()
  3558. {
  3559. if ($this->medium !== null)
  3560. {
  3561. return $this->medium;
  3562. }
  3563. else
  3564. {
  3565. return null;
  3566. }
  3567. }
  3568. public function get_player()
  3569. {
  3570. if ($this->player !== null)
  3571. {
  3572. return $this->player;
  3573. }
  3574. else
  3575. {
  3576. return null;
  3577. }
  3578. }
  3579. public function get_rating($key = 0)
  3580. {
  3581. $ratings = $this->get_ratings();
  3582. if (isset($ratings[$key]))
  3583. {
  3584. return $ratings[$key];
  3585. }
  3586. else
  3587. {
  3588. return null;
  3589. }
  3590. }
  3591. public function get_ratings()
  3592. {
  3593. if ($this->ratings !== null)
  3594. {
  3595. return $this->ratings;
  3596. }
  3597. else
  3598. {
  3599. return null;
  3600. }
  3601. }
  3602. public function get_restriction($key = 0)
  3603. {
  3604. $restrictions = $this->get_restrictions();
  3605. if (isset($restrictions[$key]))
  3606. {
  3607. return $restrictions[$key];
  3608. }
  3609. else
  3610. {
  3611. return null;
  3612. }
  3613. }
  3614. public function get_restrictions()
  3615. {
  3616. if ($this->restrictions !== null)
  3617. {
  3618. return $this->restrictions;
  3619. }
  3620. else
  3621. {
  3622. return null;
  3623. }
  3624. }
  3625. public function get_sampling_rate()
  3626. {
  3627. if ($this->samplingrate !== null)
  3628. {
  3629. return $this->samplingrate;
  3630. }
  3631. else
  3632. {
  3633. return null;
  3634. }
  3635. }
  3636. public function get_size()
  3637. {
  3638. $length = $this->get_length();
  3639. if ($length !== null)
  3640. {
  3641. return round($length/1048576, 2);
  3642. }
  3643. else
  3644. {
  3645. return null;
  3646. }
  3647. }
  3648. public function get_thumbnail($key = 0)
  3649. {
  3650. $thumbnails = $this->get_thumbnails();
  3651. if (isset($thumbnails[$key]))
  3652. {
  3653. return $thumbnails[$key];
  3654. }
  3655. else
  3656. {
  3657. return null;
  3658. }
  3659. }
  3660. public function get_thumbnails()
  3661. {
  3662. if ($this->thumbnails !== null)
  3663. {
  3664. return $this->thumbnails;
  3665. }
  3666. else
  3667. {
  3668. return null;
  3669. }
  3670. }
  3671. public function get_title()
  3672. {
  3673. if ($this->title !== null)
  3674. {
  3675. return $this->title;
  3676. }
  3677. else
  3678. {
  3679. return null;
  3680. }
  3681. }
  3682. public function get_type()
  3683. {
  3684. if ($this->type !== null)
  3685. {
  3686. return $this->type;
  3687. }
  3688. else
  3689. {
  3690. return null;
  3691. }
  3692. }
  3693. public function get_width()
  3694. {
  3695. if ($this->width !== null)
  3696. {
  3697. return $this->width;
  3698. }
  3699. else
  3700. {
  3701. return null;
  3702. }
  3703. }
  3704. public function native_embed($options='')
  3705. {
  3706. return $this->embed($options, true);
  3707. }
  3708. public function embed($options = '', $native = false)
  3709. {
  3710. // Set up defaults
  3711. $audio = '';
  3712. $video = '';
  3713. $alt = '';
  3714. $altclass = '';
  3715. $loop = 'false';
  3716. $width = 'auto';
  3717. $height = 'auto';
  3718. $bgcolor = '#ffffff';
  3719. $mediaplayer = '';
  3720. $widescreen = false;
  3721. $handler = $this->get_handler();
  3722. $type = $this->get_real_type();
  3723. // Process options and reassign values as necessary
  3724. if (is_array($options))
  3725. {
  3726. extract($options);
  3727. }
  3728. else
  3729. {
  3730. $options = explode(',', $options);
  3731. foreach($options as $option)
  3732. {
  3733. $opt = explode(':', $option, 2);
  3734. if (isset($opt[0], $opt[1]))
  3735. {
  3736. $opt[0] = trim($opt[0]);
  3737. $opt[1] = trim($opt[1]);
  3738. switch ($opt[0])
  3739. {
  3740. case 'audio':
  3741. $audio = $opt[1];
  3742. break;
  3743. case 'video':
  3744. $video = $opt[1];
  3745. break;
  3746. case 'alt':
  3747. $alt = $opt[1];
  3748. break;
  3749. case 'altclass':
  3750. $altclass = $opt[1];
  3751. break;
  3752. case 'loop':
  3753. $loop = $opt[1];
  3754. break;
  3755. case 'width':
  3756. $width = $opt[1];
  3757. break;
  3758. case 'height':
  3759. $height = $opt[1];
  3760. break;
  3761. case 'bgcolor':
  3762. $bgcolor = $opt[1];
  3763. break;
  3764. case 'mediaplayer':
  3765. $mediaplayer = $opt[1];
  3766. break;
  3767. case 'widescreen':
  3768. $widescreen = $opt[1];
  3769. break;
  3770. }
  3771. }
  3772. }
  3773. }
  3774. $mime = explode('/', $type, 2);
  3775. $mime = $mime[0];
  3776. // Process values for 'auto'
  3777. if ($width === 'auto')
  3778. {
  3779. if ($mime === 'video')
  3780. {
  3781. if ($height === 'auto')
  3782. {
  3783. $width = 480;
  3784. }
  3785. elseif ($widescreen)
  3786. {
  3787. $width = round((intval($height)/9)*16);
  3788. }
  3789. else
  3790. {
  3791. $width = round((intval($height)/3)*4);
  3792. }
  3793. }
  3794. else
  3795. {
  3796. $width = '100%';
  3797. }
  3798. }
  3799. if ($height === 'auto')
  3800. {
  3801. if ($mime === 'audio')
  3802. {
  3803. $height = 0;
  3804. }
  3805. elseif ($mime === 'video')
  3806. {
  3807. if ($width === 'auto')
  3808. {
  3809. if ($widescreen)
  3810. {
  3811. $height = 270;
  3812. }
  3813. else
  3814. {
  3815. $height = 360;
  3816. }
  3817. }
  3818. elseif ($widescreen)
  3819. {
  3820. $height = round((intval($width)/16)*9);
  3821. }
  3822. else
  3823. {
  3824. $height = round((intval($width)/4)*3);
  3825. }
  3826. }
  3827. else
  3828. {
  3829. $height = 376;
  3830. }
  3831. }
  3832. elseif ($mime === 'audio')
  3833. {
  3834. $height = 0;
  3835. }
  3836. // Set proper placeholder value
  3837. if ($mime === 'audio')
  3838. {
  3839. $placeholder = $audio;
  3840. }
  3841. elseif ($mime === 'video')
  3842. {
  3843. $placeholder = $video;
  3844. }
  3845. $embed = '';
  3846. // Flash
  3847. if ($handler === 'flash')
  3848. {
  3849. if ($native)
  3850. {
  3851. $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>";
  3852. }
  3853. else
  3854. {
  3855. $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>";
  3856. }
  3857. }
  3858. // Flash Media Player file types.
  3859. // Preferred handler for MP3 file types.
  3860. elseif ($handler === 'fmedia' || ($handler === 'mp3' && $mediaplayer !== ''))
  3861. {
  3862. $height += 20;
  3863. if ($native)
  3864. {
  3865. $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>";
  3866. }
  3867. else
  3868. {
  3869. $embed .= "<script type='text/javascript'>embed_flv('$width', '$height', '" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "', '$placeholder', '$loop', '$mediaplayer');</script>";
  3870. }
  3871. }
  3872. // QuickTime 7 file types. Need to test with QuickTime 6.
  3873. // Only handle MP3's if the Flash Media Player is not present.
  3874. elseif ($handler === 'quicktime' || ($handler === 'mp3' && $mediaplayer === ''))
  3875. {
  3876. $height += 16;
  3877. if ($native)
  3878. {
  3879. if ($placeholder !== '')
  3880. {
  3881. $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>";
  3882. }
  3883. else
  3884. {
  3885. $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>";
  3886. }
  3887. }
  3888. else
  3889. {
  3890. $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>";
  3891. }
  3892. }
  3893. // Windows Media
  3894. elseif ($handler === 'wmedia')
  3895. {
  3896. $height += 45;
  3897. if ($native)
  3898. {
  3899. $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>";
  3900. }
  3901. else
  3902. {
  3903. $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>";
  3904. }
  3905. }
  3906. // Everything else
  3907. else $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>';
  3908. return $embed;
  3909. }
  3910. public function get_real_type($find_handler = false)
  3911. {
  3912. // Mime-types by handler.
  3913. $types_flash = array('application/x-shockwave-flash', 'application/futuresplash'); // Flash
  3914. $types_fmedia = array('video/flv', 'video/x-flv','flv-application/octet-stream'); // Flash Media Player
  3915. $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
  3916. $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
  3917. $types_mp3 = array('audio/mp3', 'audio/x-mp3', 'audio/mpeg', 'audio/x-mpeg'); // MP3
  3918. if ($this->get_type() !== null)
  3919. {
  3920. $type = strtolower($this->type);
  3921. }
  3922. else
  3923. {
  3924. $type = null;
  3925. }
  3926. // If we encounter an unsupported mime-type, check the file extension and guess intelligently.
  3927. if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3)))
  3928. {
  3929. switch (strtolower($this->get_extension()))
  3930. {
  3931. // Audio mime-types
  3932. case 'aac':
  3933. case 'adts':
  3934. $type = 'audio/acc';
  3935. break;
  3936. case 'aif':
  3937. case 'aifc':
  3938. case 'aiff':
  3939. case 'cdda':
  3940. $type = 'audio/aiff';
  3941. break;
  3942. case 'bwf':
  3943. $type = 'audio/wav';
  3944. break;
  3945. case 'kar':
  3946. case 'mid':
  3947. case 'midi':
  3948. case 'smf':
  3949. $type = 'audio/midi';
  3950. break;
  3951. case 'm4a':
  3952. $type = 'audio/x-m4a';
  3953. break;
  3954. case 'mp3':
  3955. case 'swa':
  3956. $type = 'audio/mp3';
  3957. break;
  3958. case 'wav':
  3959. $type = 'audio/wav';
  3960. break;
  3961. case 'wax':
  3962. $type = 'audio/x-ms-wax';
  3963. break;
  3964. case 'wma':
  3965. $type = 'audio/x-ms-wma';
  3966. break;
  3967. // Video mime-types
  3968. case '3gp':
  3969. case '3gpp':
  3970. $type = 'video/3gpp';
  3971. break;
  3972. case '3g2':
  3973. case '3gp2':
  3974. $type = 'video/3gpp2';
  3975. break;
  3976. case 'asf':
  3977. $type = 'video/x-ms-asf';
  3978. break;
  3979. case 'flv':
  3980. $type = 'video/x-flv';
  3981. break;
  3982. case 'm1a':
  3983. case 'm1s':
  3984. case 'm1v':
  3985. case 'm15':
  3986. case 'm75':
  3987. case 'mp2':
  3988. case 'mpa':
  3989. case 'mpeg':
  3990. case 'mpg':
  3991. case 'mpm':
  3992. case 'mpv':
  3993. $type = 'video/mpeg';
  3994. break;
  3995. case 'm4v':
  3996. $type = 'video/x-m4v';
  3997. break;
  3998. case 'mov':
  3999. case 'qt':
  4000. $type = 'video/quicktime';
  4001. break;
  4002. case 'mp4':
  4003. case 'mpg4':
  4004. $type = 'video/mp4';
  4005. break;
  4006. case 'sdv':
  4007. $type = 'video/sd-video';
  4008. break;
  4009. case 'wm':
  4010. $type = 'video/x-ms-wm';
  4011. break;
  4012. case 'wmv':
  4013. $type = 'video/x-ms-wmv';
  4014. break;
  4015. case 'wvx':
  4016. $type = 'video/x-ms-wvx';
  4017. break;
  4018. // Flash mime-types
  4019. case 'spl':
  4020. $type = 'application/futuresplash';
  4021. break;
  4022. case 'swf':
  4023. $type = 'application/x-shockwave-flash';
  4024. break;
  4025. }
  4026. }
  4027. if ($find_handler)
  4028. {
  4029. if (in_array($type, $types_flash))
  4030. {
  4031. return 'flash';
  4032. }
  4033. elseif (in_array($type, $types_fmedia))
  4034. {
  4035. return 'fmedia';
  4036. }
  4037. elseif (in_array($type, $types_quicktime))
  4038. {
  4039. return 'quicktime';
  4040. }
  4041. elseif (in_array($type, $types_wmedia))
  4042. {
  4043. return 'wmedia';
  4044. }
  4045. elseif (in_array($type, $types_mp3))
  4046. {
  4047. return 'mp3';
  4048. }
  4049. else
  4050. {
  4051. return null;
  4052. }
  4053. }
  4054. else
  4055. {
  4056. return $type;
  4057. }
  4058. }
  4059. }
  4060. class SimplePie_File
  4061. {
  4062. var $url;
  4063. var $useragent;
  4064. var $success = true;
  4065. var $headers = array();
  4066. var $body;
  4067. var $status_code;
  4068. var $redirects = 0;
  4069. var $error;
  4070. var $method = SIMPLEPIE_FILE_SOURCE_NONE;
  4071. public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
  4072. {
  4073. if (class_exists('idna_convert'))
  4074. {
  4075. $idn = new idna_convert();
  4076. $parsed = SimplePie_Misc::parse_url($url);
  4077. $url = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
  4078. }
  4079. $this->url = $url;
  4080. $this->useragent = $useragent;
  4081. if (preg_match('/^http(s)?:\/\//i', $url))
  4082. {
  4083. if ($useragent === null)
  4084. {
  4085. $useragent = ini_get('user_agent');
  4086. $this->useragent = $useragent;
  4087. }
  4088. if (!is_array($headers))
  4089. {
  4090. $headers = array();
  4091. }
  4092. if (!$force_fsockopen && function_exists('curl_exec'))
  4093. {
  4094. $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_CURL;
  4095. $fp = curl_init();
  4096. $headers2 = array();
  4097. foreach ($headers as $key => $value)
  4098. {
  4099. $headers2[] = "$key: $value";
  4100. }
  4101. if (version_compare(SimplePie_Misc::get_curl_version(), '7.10.5', '>='))
  4102. {
  4103. curl_setopt($fp, CURLOPT_ENCODING, '');
  4104. }
  4105. curl_setopt($fp, CURLOPT_URL, $url);
  4106. curl_setopt($fp, CURLOPT_HEADER, 1);
  4107. curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
  4108. curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
  4109. curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout);
  4110. curl_setopt($fp, CURLOPT_REFERER, $url);
  4111. curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
  4112. curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
  4113. if (!ini_get('open_basedir') && !ini_get('safe_mode') && version_compare(SimplePie_Misc::get_curl_version(), '7.15.2', '>='))
  4114. {
  4115. curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
  4116. curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
  4117. }
  4118. $this->headers = curl_exec($fp);
  4119. if (curl_errno($fp) === 23 || curl_errno($fp) === 61)
  4120. {
  4121. curl_setopt($fp, CURLOPT_ENCODING, 'none');
  4122. $this->headers = curl_exec($fp);
  4123. }
  4124. if (curl_errno($fp))
  4125. {
  4126. $this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
  4127. $this->success = false;
  4128. }
  4129. else
  4130. {
  4131. $info = curl_getinfo($fp);
  4132. curl_close($fp);
  4133. $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 1);
  4134. $this->headers = array_pop($this->headers);
  4135. $parser = new SimplePie_HTTP_Parser($this->headers);
  4136. if ($parser->parse())
  4137. {
  4138. $this->headers = $parser->headers;
  4139. $this->body = $parser->body;
  4140. $this->status_code = $parser->status_code;
  4141. 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)
  4142. {
  4143. $this->redirects++;
  4144. $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
  4145. return $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
  4146. }
  4147. }
  4148. }
  4149. }
  4150. else
  4151. {
  4152. $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_FSOCKOPEN;
  4153. $url_parts = parse_url($url);
  4154. $socket_host = $url_parts['host'];
  4155. if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https')
  4156. {
  4157. $socket_host = "ssl://$url_parts[host]";
  4158. $url_parts['port'] = 443;
  4159. }
  4160. if (!isset($url_parts['port']))
  4161. {
  4162. $url_parts['port'] = 80;
  4163. }
  4164. $fp = @fsockopen($socket_host, $url_parts['port'], $errno, $errstr, $timeout);
  4165. if (!$fp)
  4166. {
  4167. $this->error = 'fsockopen error: ' . $errstr;
  4168. $this->success = false;
  4169. }
  4170. else
  4171. {
  4172. stream_set_timeout($fp, $timeout);
  4173. if (isset($url_parts['path']))
  4174. {
  4175. if (isset($url_parts['query']))
  4176. {
  4177. $get = "$url_parts[path]?$url_parts[query]";
  4178. }
  4179. else
  4180. {
  4181. $get = $url_parts['path'];
  4182. }
  4183. }
  4184. else
  4185. {
  4186. $get = '/';
  4187. }
  4188. $out = "GET $get HTTP/1.1\r\n";
  4189. $out .= "Host: $url_parts[host]\r\n";
  4190. $out .= "User-Agent: $useragent\r\n";
  4191. if (extension_loaded('zlib'))
  4192. {
  4193. $out .= "Accept-Encoding: x-gzip,gzip,deflate\r\n";
  4194. }
  4195. if (isset($url_parts['user']) && isset($url_parts['pass']))
  4196. {
  4197. $out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
  4198. }
  4199. foreach ($headers as $key => $value)
  4200. {
  4201. $out .= "$key: $value\r\n";
  4202. }
  4203. $out .= "Connection: Close\r\n\r\n";
  4204. fwrite($fp, $out);
  4205. $info = stream_get_meta_data($fp);
  4206. $this->headers = '';
  4207. while (!$info['eof'] && !$info['timed_out'])
  4208. {
  4209. $this->headers .= fread($fp, 1160);
  4210. $info = stream_get_meta_data($fp);
  4211. }
  4212. if (!$info['timed_out'])
  4213. {
  4214. $parser = new SimplePie_HTTP_Parser($this->headers);
  4215. if ($parser->parse())
  4216. {
  4217. $this->headers = $parser->headers;
  4218. $this->body = $parser->body;
  4219. $this->status_code = $parser->status_code;
  4220. 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)
  4221. {
  4222. $this->redirects++;
  4223. $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
  4224. return $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
  4225. }
  4226. if (isset($this->headers['content-encoding']))
  4227. {
  4228. // Hey, we act dumb elsewhere, so let's do that here too
  4229. switch (strtolower(trim($this->headers['content-encoding'], "\x09\x0A\x0D\x20")))
  4230. {
  4231. case 'gzip':
  4232. case 'x-gzip':
  4233. $decoder = new SimplePie_gzdecode($this->body);
  4234. if (!$decoder->parse())
  4235. {
  4236. $this->error = 'Unable to decode HTTP "gzip" stream';
  4237. $this->success = false;
  4238. }
  4239. else
  4240. {
  4241. $this->body = $decoder->data;
  4242. }
  4243. break;
  4244. case 'deflate':
  4245. if (($decompressed = gzinflate($this->body)) !== false)
  4246. {
  4247. $this->body = $decompressed;
  4248. }
  4249. else if (($decompressed = gzuncompress($this->body)) !== false)
  4250. {
  4251. $this->body = $decompressed;
  4252. }
  4253. else if (function_exists('gzdecode') && ($decompressed = gzdecode($this->body)) !== false)
  4254. {
  4255. $this->body = $decompressed;
  4256. }
  4257. else
  4258. {
  4259. $this->error = 'Unable to decode HTTP "deflate" stream';
  4260. $this->success = false;
  4261. }
  4262. break;
  4263. default:
  4264. $this->error = 'Unknown content coding';
  4265. $this->success = false;
  4266. }
  4267. }
  4268. }
  4269. }
  4270. else
  4271. {
  4272. $this->error = 'fsocket timed out';
  4273. $this->success = false;
  4274. }
  4275. fclose($fp);
  4276. }
  4277. }
  4278. }
  4279. else
  4280. {
  4281. $this->method = SIMPLEPIE_FILE_SOURCE_LOCAL | SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS;
  4282. if (!$this->body = file_get_contents($url))
  4283. {
  4284. $this->error = 'file_get_contents could not read the file';
  4285. $this->success = false;
  4286. }
  4287. }
  4288. }
  4289. }
  4290. class SimplePie_gzdecode
  4291. {
  4292. var $compressed_data;
  4293. var $compressed_size;
  4294. var $min_compressed_size = 18;
  4295. var $position = 0;
  4296. var $flags;
  4297. var $data;
  4298. var $MTIME;
  4299. var $XFL;
  4300. var $OS;
  4301. var $SI1;
  4302. var $SI2;
  4303. var $extra_field;
  4304. var $filename;
  4305. var $comment;
  4306. public function __set($name, $value)
  4307. {
  4308. trigger_error("Cannot write property $name", E_USER_ERROR);
  4309. }
  4310. public function __construct($data)
  4311. {
  4312. $this->compressed_data = $data;
  4313. $this->compressed_size = strlen($data);
  4314. }
  4315. public function parse()
  4316. {
  4317. if ($this->compressed_size >= $this->min_compressed_size)
  4318. {
  4319. // Check ID1, ID2, and CM
  4320. if (substr($this->compressed_data, 0, 3) !== "\x1F\x8B\x08")
  4321. {
  4322. return false;
  4323. }
  4324. // Get the FLG (FLaGs)
  4325. $this->flags = ord($this->compressed_data[3]);
  4326. // FLG bits above (1 << 4) are reserved
  4327. if ($this->flags > 0x1F)
  4328. {
  4329. return false;
  4330. }
  4331. // Advance the pointer after the above
  4332. $this->position += 4;
  4333. // MTIME
  4334. $mtime = substr($this->compressed_data, $this->position, 4);
  4335. // Reverse the string if we're on a big-endian arch because l is the only signed long and is machine endianness
  4336. if (current(unpack('S', "\x00\x01")) === 1)
  4337. {
  4338. $mtime = strrev($mtime);
  4339. }
  4340. $this->MTIME = current(unpack('l', $mtime));
  4341. $this->position += 4;
  4342. // Get the XFL (eXtra FLags)
  4343. $this->XFL = ord($this->compressed_data[$this->position++]);
  4344. // Get the OS (Operating System)
  4345. $this->OS = ord($this->compressed_data[$this->position++]);
  4346. // Parse the FEXTRA
  4347. if ($this->flags & 4)
  4348. {
  4349. // Read subfield IDs
  4350. $this->SI1 = $this->compressed_data[$this->position++];
  4351. $this->SI2 = $this->compressed_data[$this->position++];
  4352. // SI2 set to zero is reserved for future use
  4353. if ($this->SI2 === "\x00")
  4354. {
  4355. return false;
  4356. }
  4357. // Get the length of the extra field
  4358. $len = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
  4359. $this->position += 2;
  4360. // Check the length of the string is still valid
  4361. $this->min_compressed_size += $len + 4;
  4362. if ($this->compressed_size >= $this->min_compressed_size)
  4363. {
  4364. // Set the extra field to the given data
  4365. $this->extra_field = substr($this->compressed_data, $this->position, $len);
  4366. $this->position += $len;
  4367. }
  4368. else
  4369. {
  4370. return false;
  4371. }
  4372. }
  4373. // Parse the FNAME
  4374. if ($this->flags & 8)
  4375. {
  4376. // Get the length of the filename
  4377. $len = strcspn($this->compressed_data, "\x00", $this->position);
  4378. // Check the length of the string is still valid
  4379. $this->min_compressed_size += $len + 1;
  4380. if ($this->compressed_size >= $this->min_compressed_size)
  4381. {
  4382. // Set the original filename to the given string
  4383. $this->filename = substr($this->compressed_data, $this->position, $len);
  4384. $this->position += $len + 1;
  4385. }
  4386. else
  4387. {
  4388. return false;
  4389. }
  4390. }
  4391. // Parse the FCOMMENT
  4392. if ($this->flags & 16)
  4393. {
  4394. // Get the length of the comment
  4395. $len = strcspn($this->compressed_data, "\x00", $this->position);
  4396. // Check the length of the string is still valid
  4397. $this->min_compressed_size += $len + 1;
  4398. if ($this->compressed_size >= $this->min_compressed_size)
  4399. {
  4400. // Set the original comment to the given string
  4401. $this->comment = substr($this->compressed_data, $this->position, $len);
  4402. $this->position += $len + 1;
  4403. }
  4404. else
  4405. {
  4406. return false;
  4407. }
  4408. }
  4409. // Parse the FHCRC
  4410. if ($this->flags & 2)
  4411. {
  4412. // Check the length of the string is still valid
  4413. $this->min_compressed_size += $len + 2;
  4414. if ($this->compressed_size >= $this->min_compressed_size)
  4415. {
  4416. // Read the CRC
  4417. $crc = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
  4418. // Check the CRC matches
  4419. if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc)
  4420. {
  4421. $this->position += 2;
  4422. }
  4423. else
  4424. {
  4425. return false;
  4426. }
  4427. }
  4428. else
  4429. {
  4430. return false;
  4431. }
  4432. }
  4433. // Decompress the actual data
  4434. if (($this->data = gzinflate(substr($this->compressed_data, $this->position, -8))) === false)
  4435. {
  4436. return false;
  4437. }
  4438. else
  4439. {
  4440. $this->position = $this->compressed_size - 8;
  4441. }
  4442. // Check CRC of data
  4443. $crc = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
  4444. $this->position += 4;
  4445. /*if (extension_loaded('hash') && sprintf('%u', current(unpack('V', hash('crc32b', $this->data)))) !== sprintf('%u', $crc))
  4446. {
  4447. return false;
  4448. }*/
  4449. // Check ISIZE of data
  4450. $isize = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
  4451. $this->position += 4;
  4452. if (sprintf('%u', strlen($this->data) & 0xFFFFFFFF) !== sprintf('%u', $isize))
  4453. {
  4454. return false;
  4455. }
  4456. // Wow, against all odds, we've actually got a valid gzip string
  4457. return true;
  4458. }
  4459. else
  4460. {
  4461. return false;
  4462. }
  4463. }
  4464. }
  4465. class SimplePie_HTTP_Parser
  4466. {
  4467. public $http_version = 0.0;
  4468. public $status_code = 0;
  4469. public $reason = '';
  4470. public $headers = array();
  4471. public $body = '';
  4472. protected $state = 'http_version';
  4473. protected $data = '';
  4474. protected $data_length = 0;
  4475. protected $position = 0;
  4476. protected $name = '';
  4477. protected $value = '';
  4478. public function __construct($data)
  4479. {
  4480. $this->data = $data;
  4481. $this->data_length = strlen($this->data);
  4482. }
  4483. public function parse()
  4484. {
  4485. while ($this->state && $this->state !== 'emit' && $this->has_data())
  4486. {
  4487. $state = $this->state;
  4488. $this->$state();
  4489. }
  4490. $this->data = '';
  4491. if ($this->state === 'emit' || $this->state === 'body')
  4492. {
  4493. return true;
  4494. }
  4495. else
  4496. {
  4497. $this->http_version = '';
  4498. $this->status_code = '';
  4499. $this->reason = '';
  4500. $this->headers = array();
  4501. $this->body = '';
  4502. return false;
  4503. }
  4504. }
  4505. protected function has_data()
  4506. {
  4507. return (bool) ($this->position < $this->data_length);
  4508. }
  4509. protected function is_linear_whitespace()
  4510. {
  4511. return (bool) ($this->data[$this->position] === "\x09"
  4512. || $this->data[$this->position] === "\x20"
  4513. || ($this->data[$this->position] === "\x0A"
  4514. && isset($this->data[$this->position + 1])
  4515. && ($this->data[$this->position + 1] === "\x09" || $this->data[$this->position + 1] === "\x20")));
  4516. }
  4517. protected function http_version()
  4518. {
  4519. if (strpos($this->data, "\x0A") !== false && strtoupper(substr($this->data, 0, 5)) === 'HTTP/')
  4520. {
  4521. $len = strspn($this->data, '0123456789.', 5);
  4522. $this->http_version = substr($this->data, 5, $len);
  4523. $this->position += 5 + $len;
  4524. if (substr_count($this->http_version, '.') <= 1)
  4525. {
  4526. $this->http_version = (float) $this->http_version;
  4527. $this->position += strspn($this->data, "\x09\x20", $this->position);
  4528. $this->state = 'status';
  4529. }
  4530. else
  4531. {
  4532. $this->state = false;
  4533. }
  4534. }
  4535. else
  4536. {
  4537. $this->state = false;
  4538. }
  4539. }
  4540. protected function status()
  4541. {
  4542. if ($len = strspn($this->data, '0123456789', $this->position))
  4543. {
  4544. $this->status_code = (int) substr($this->data, $this->position, $len);
  4545. $this->position += $len;
  4546. $this->state = 'reason';
  4547. }
  4548. else
  4549. {
  4550. $this->state = false;
  4551. }
  4552. }
  4553. protected function reason()
  4554. {
  4555. $len = strcspn($this->data, "\x0A", $this->position);
  4556. $this->reason = trim(substr($this->data, $this->position, $len), "\x09\x0D\x20");
  4557. $this->position += $len + 1;
  4558. $this->state = 'new_line';
  4559. }
  4560. protected function new_line()
  4561. {
  4562. $this->value = trim($this->value, "\x0D\x20");
  4563. if ($this->name !== '' && $this->value !== '')
  4564. {
  4565. $this->name = strtolower($this->name);
  4566. // We should only use the last Content-Type header. c.f. issue #1
  4567. if (isset($this->headers[$this->name]) && $this->name !== 'content-type')
  4568. {
  4569. $this->headers[$this->name] .= ', ' . $this->value;
  4570. }
  4571. else
  4572. {
  4573. $this->headers[$this->name] = $this->value;
  4574. }
  4575. }
  4576. $this->name = '';
  4577. $this->value = '';
  4578. if (substr($this->data[$this->position], 0, 2) === "\x0D\x0A")
  4579. {
  4580. $this->position += 2;
  4581. $this->state = 'body';
  4582. }
  4583. elseif ($this->data[$this->position] === "\x0A")
  4584. {
  4585. $this->position++;
  4586. $this->state = 'body';
  4587. }
  4588. else
  4589. {
  4590. $this->state = 'name';
  4591. }
  4592. }
  4593. protected function name()
  4594. {
  4595. $len = strcspn($this->data, "\x0A:", $this->position);
  4596. if (isset($this->data[$this->position + $len]))
  4597. {
  4598. if ($this->data[$this->position + $len] === "\x0A")
  4599. {
  4600. $this->position += $len;
  4601. $this->state = 'new_line';
  4602. }
  4603. else
  4604. {
  4605. $this->name = substr($this->data, $this->position, $len);
  4606. $this->position += $len + 1;
  4607. $this->state = 'value';
  4608. }
  4609. }
  4610. else
  4611. {
  4612. $this->state = false;
  4613. }
  4614. }
  4615. protected function linear_whitespace()
  4616. {
  4617. do
  4618. {
  4619. if (substr($this->data, $this->position, 2) === "\x0D\x0A")
  4620. {
  4621. $this->position += 2;
  4622. }
  4623. elseif ($this->data[$this->position] === "\x0A")
  4624. {
  4625. $this->position++;
  4626. }
  4627. $this->position += strspn($this->data, "\x09\x20", $this->position);
  4628. } while ($this->has_data() && $this->is_linear_whitespace());
  4629. $this->value .= "\x20";
  4630. }
  4631. protected function value()
  4632. {
  4633. if ($this->is_linear_whitespace())
  4634. {
  4635. $this->linear_whitespace();
  4636. }
  4637. else
  4638. {
  4639. switch ($this->data[$this->position])
  4640. {
  4641. case '"':
  4642. // Workaround for ETags: we have to include the quotes as
  4643. // part of the tag.
  4644. if (strtolower($this->name) === 'etag')
  4645. {
  4646. $this->value .= '"';
  4647. $this->position++;
  4648. $this->state = 'value_char';
  4649. break;
  4650. }
  4651. $this->position++;
  4652. $this->state = 'quote';
  4653. break;
  4654. case "\x0A":
  4655. $this->position++;
  4656. $this->state = 'new_line';
  4657. break;
  4658. default:
  4659. $this->state = 'value_char';
  4660. break;
  4661. }
  4662. }
  4663. }
  4664. protected function value_char()
  4665. {
  4666. $len = strcspn($this->data, "\x09\x20\x0A\"", $this->position);
  4667. $this->value .= substr($this->data, $this->position, $len);
  4668. $this->position += $len;
  4669. $this->state = 'value';
  4670. }
  4671. protected function quote()
  4672. {
  4673. if ($this->is_linear_whitespace())
  4674. {
  4675. $this->linear_whitespace();
  4676. }
  4677. else
  4678. {
  4679. switch ($this->data[$this->position])
  4680. {
  4681. case '"':
  4682. $this->position++;
  4683. $this->state = 'value';
  4684. break;
  4685. case "\x0A":
  4686. $this->position++;
  4687. $this->state = 'new_line';
  4688. break;
  4689. case '\\':
  4690. $this->position++;
  4691. $this->state = 'quote_escaped';
  4692. break;
  4693. default:
  4694. $this->state = 'quote_char';
  4695. break;
  4696. }
  4697. }
  4698. }
  4699. protected function quote_char()
  4700. {
  4701. $len = strcspn($this->data, "\x09\x20\x0A\"\\", $this->position);
  4702. $this->value .= substr($this->data, $this->position, $len);
  4703. $this->position += $len;
  4704. $this->state = 'value';
  4705. }
  4706. protected function quote_escaped()
  4707. {
  4708. $this->value .= $this->data[$this->position];
  4709. $this->position++;
  4710. $this->state = 'quote';
  4711. }
  4712. protected function body()
  4713. {
  4714. $this->body = substr($this->data, $this->position);
  4715. if (!empty($this->headers['transfer-encoding']))
  4716. {
  4717. unset($this->headers['transfer-encoding']);
  4718. $this->state = 'chunked';
  4719. }
  4720. else
  4721. {
  4722. $this->state = 'emit';
  4723. }
  4724. }
  4725. protected function chunked()
  4726. {
  4727. if (!preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', trim($this->body)))
  4728. {
  4729. $this->state = 'emit';
  4730. return;
  4731. }
  4732. $decoded = '';
  4733. $encoded = $this->body;
  4734. while (true)
  4735. {
  4736. $is_chunked = (bool) preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', $encoded, $matches );
  4737. if (!$is_chunked)
  4738. {
  4739. // Looks like it's not chunked after all
  4740. $this->state = 'emit';
  4741. return;
  4742. }
  4743. $length = hexdec(trim($matches[1]));
  4744. if ($length === 0)
  4745. {
  4746. // Ignore trailer headers
  4747. $this->state = 'emit';
  4748. $this->body = $decoded;
  4749. return;
  4750. }
  4751. $chunk_length = strlen($matches[0]);
  4752. $decoded .= $part = substr($encoded, $chunk_length, $length);
  4753. $encoded = substr($encoded, $chunk_length + $length + 2);
  4754. if (trim($encoded) === '0' || empty($encoded))
  4755. {
  4756. $this->state = 'emit';
  4757. $this->body = $decoded;
  4758. return;
  4759. }
  4760. }
  4761. }
  4762. }
  4763. class SimplePie_IRI
  4764. {
  4765. protected $scheme = null;
  4766. protected $iuserinfo = null;
  4767. protected $ihost = null;
  4768. protected $port = null;
  4769. protected $ipath = '';
  4770. protected $iquery = null;
  4771. protected $ifragment = null;
  4772. protected $normalization = array(
  4773. 'acap' => array(
  4774. 'port' => 674
  4775. ),
  4776. 'dict' => array(
  4777. 'port' => 2628
  4778. ),
  4779. 'file' => array(
  4780. 'ihost' => 'localhost'
  4781. ),
  4782. 'http' => array(
  4783. 'port' => 80,
  4784. 'ipath' => '/'
  4785. ),
  4786. 'https' => array(
  4787. 'port' => 443,
  4788. 'ipath' => '/'
  4789. ),
  4790. );
  4791. public function __toString()
  4792. {
  4793. return $this->get_iri();
  4794. }
  4795. public function __set($name, $value)
  4796. {
  4797. if (method_exists($this, 'set_' . $name))
  4798. {
  4799. call_user_func(array($this, 'set_' . $name), $value);
  4800. }
  4801. elseif (
  4802. $name === 'iauthority'
  4803. || $name === 'iuserinfo'
  4804. || $name === 'ihost'
  4805. || $name === 'ipath'
  4806. || $name === 'iquery'
  4807. || $name === 'ifragment'
  4808. )
  4809. {
  4810. call_user_func(array($this, 'set_' . substr($name, 1)), $value);
  4811. }
  4812. }
  4813. public function __get($name)
  4814. {
  4815. // isset() returns false for null, we don't want to do that
  4816. // Also why we use array_key_exists below instead of isset()
  4817. $props = get_object_vars($this);
  4818. if (
  4819. $name === 'iri' ||
  4820. $name === 'uri' ||
  4821. $name === 'iauthority' ||
  4822. $name === 'authority'
  4823. )
  4824. {
  4825. $return = $this->{"get_$name"}();
  4826. }
  4827. elseif (array_key_exists($name, $props))
  4828. {
  4829. $return = $this->$name;
  4830. }
  4831. // host -> ihost
  4832. elseif (($prop = 'i' . $name) && array_key_exists($prop, $props))
  4833. {
  4834. $name = $prop;
  4835. $return = $this->$prop;
  4836. }
  4837. // ischeme -> scheme
  4838. elseif (($prop = substr($name, 1)) && array_key_exists($prop, $props))
  4839. {
  4840. $name = $prop;
  4841. $return = $this->$prop;
  4842. }
  4843. else
  4844. {
  4845. trigger_error('Undefined property: ' . get_class($this) . '::' . $name, E_USER_NOTICE);
  4846. $return = null;
  4847. }
  4848. if ($return === null && isset($this->normalization[$this->scheme][$name]))
  4849. {
  4850. return $this->normalization[$this->scheme][$name];
  4851. }
  4852. else
  4853. {
  4854. return $return;
  4855. }
  4856. }
  4857. public function __isset($name)
  4858. {
  4859. if (method_exists($this, 'get_' . $name) || isset($this->$name))
  4860. {
  4861. return true;
  4862. }
  4863. else
  4864. {
  4865. return false;
  4866. }
  4867. }
  4868. public function __unset($name)
  4869. {
  4870. if (method_exists($this, 'set_' . $name))
  4871. {
  4872. call_user_func(array($this, 'set_' . $name), '');
  4873. }
  4874. }
  4875. public function __construct($iri = null)
  4876. {
  4877. $this->set_iri($iri);
  4878. }
  4879. public static function absolutize($base, $relative)
  4880. {
  4881. if (!($relative instanceof SimplePie_IRI))
  4882. {
  4883. $relative = new SimplePie_IRI($relative);
  4884. }
  4885. if (!$relative->is_valid())
  4886. {
  4887. return false;
  4888. }
  4889. elseif ($relative->scheme !== null)
  4890. {
  4891. return clone $relative;
  4892. }
  4893. else
  4894. {
  4895. if (!($base instanceof SimplePie_IRI))
  4896. {
  4897. $base = new SimplePie_IRI($base);
  4898. }
  4899. if ($base->scheme !== null && $base->is_valid())
  4900. {
  4901. if ($relative->get_iri() !== '')
  4902. {
  4903. if ($relative->iuserinfo !== null || $relative->ihost !== null || $relative->port !== null)
  4904. {
  4905. $target = clone $relative;
  4906. $target->scheme = $base->scheme;
  4907. }
  4908. else
  4909. {
  4910. $target = new SimplePie_IRI;
  4911. $target->scheme = $base->scheme;
  4912. $target->iuserinfo = $base->iuserinfo;
  4913. $target->ihost = $base->ihost;
  4914. $target->port = $base->port;
  4915. if ($relative->ipath !== '')
  4916. {
  4917. if ($relative->ipath[0] === '/')
  4918. {
  4919. $target->ipath = $relative->ipath;
  4920. }
  4921. elseif (($base->iuserinfo !== null || $base->ihost !== null || $base->port !== null) && $base->ipath === '')
  4922. {
  4923. $target->ipath = '/' . $relative->ipath;
  4924. }
  4925. elseif (($last_segment = strrpos($base->ipath, '/')) !== false)
  4926. {
  4927. $target->ipath = substr($base->ipath, 0, $last_segment + 1) . $relative->ipath;
  4928. }
  4929. else
  4930. {
  4931. $target->ipath = $relative->ipath;
  4932. }
  4933. $target->ipath = $target->remove_dot_segments($target->ipath);
  4934. $target->iquery = $relative->iquery;
  4935. }
  4936. else
  4937. {
  4938. $target->ipath = $base->ipath;
  4939. if ($relative->iquery !== null)
  4940. {
  4941. $target->iquery = $relative->iquery;
  4942. }
  4943. elseif ($base->iquery !== null)
  4944. {
  4945. $target->iquery = $base->iquery;
  4946. }
  4947. }
  4948. $target->ifragment = $relative->ifragment;
  4949. }
  4950. }
  4951. else
  4952. {
  4953. $target = clone $base;
  4954. $target->ifragment = null;
  4955. }
  4956. $target->scheme_normalization();
  4957. return $target;
  4958. }
  4959. else
  4960. {
  4961. return false;
  4962. }
  4963. }
  4964. }
  4965. protected function parse_iri($iri)
  4966. {
  4967. $iri = trim($iri, "\x20\x09\x0A\x0C\x0D");
  4968. if (preg_match('/^((?P<scheme>[^:\/?#]+):)?(\/\/(?P<authority>[^\/?#]*))?(?P<path>[^?#]*)(\?(?P<query>[^#]*))?(#(?P<fragment>.*))?$/', $iri, $match))
  4969. {
  4970. if ($match[1] === '')
  4971. {
  4972. $match['scheme'] = null;
  4973. }
  4974. if (!isset($match[3]) || $match[3] === '')
  4975. {
  4976. $match['authority'] = null;
  4977. }
  4978. if (!isset($match[5]))
  4979. {
  4980. $match['path'] = '';
  4981. }
  4982. if (!isset($match[6]) || $match[6] === '')
  4983. {
  4984. $match['query'] = null;
  4985. }
  4986. if (!isset($match[8]) || $match[8] === '')
  4987. {
  4988. $match['fragment'] = null;
  4989. }
  4990. $match['path'] = preg_replace ('#//#', '/', $match['path']); // fix un bug lorsque 2 slashs se suivent
  4991. return $match;
  4992. }
  4993. else
  4994. {
  4995. trigger_error('This should never happen', E_USER_ERROR);
  4996. die;
  4997. }
  4998. }
  4999. protected function remove_dot_segments($input)
  5000. {
  5001. $output = '';
  5002. while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..')
  5003. {
  5004. // A: If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise,
  5005. if (strpos($input, '../') === 0)
  5006. {
  5007. $input = substr($input, 3);
  5008. }
  5009. elseif (strpos($input, './') === 0)
  5010. {
  5011. $input = substr($input, 2);
  5012. }
  5013. // B: if the input buffer begins with a prefix of "/./" or "/.", where "." is a complete path segment, then replace that prefix with "/" in the input buffer; otherwise,
  5014. elseif (strpos($input, '/./') === 0)
  5015. {
  5016. $input = substr($input, 2);
  5017. }
  5018. elseif ($input === '/.')
  5019. {
  5020. $input = '/';
  5021. }
  5022. // C: if the input buffer begins with a prefix of "/../" or "/..", where ".." is a complete path segment, then replace that prefix with "/" in the input buffer and remove the last segment and its preceding "/" (if any) from the output buffer; otherwise,
  5023. elseif (strpos($input, '/../') === 0)
  5024. {
  5025. $input = substr($input, 3);
  5026. $output = substr_replace($output, '', strrpos($output, '/'));
  5027. }
  5028. elseif ($input === '/..')
  5029. {
  5030. $input = '/';
  5031. $output = substr_replace($output, '', strrpos($output, '/'));
  5032. }
  5033. // D: if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise,
  5034. elseif ($input === '.' || $input === '..')
  5035. {
  5036. $input = '';
  5037. }
  5038. // E: move the first path segment in the input buffer to the end of the output buffer, including the initial "/" character (if any) and any subsequent characters up to, but not including, the next "/" character or the end of the input buffer
  5039. elseif (($pos = strpos($input, '/', 1)) !== false)
  5040. {
  5041. $output .= substr($input, 0, $pos);
  5042. $input = substr_replace($input, '', 0, $pos);
  5043. }
  5044. else
  5045. {
  5046. $output .= $input;
  5047. $input = '';
  5048. }
  5049. }
  5050. return $output . $input;
  5051. }
  5052. protected function replace_invalid_with_pct_encoding($string, $extra_chars, $iprivate = false)
  5053. {
  5054. // Normalize as many pct-encoded sections as possible
  5055. $string = preg_replace_callback('/(?:%[A-Fa-f0-9]{2})+/', array($this, 'remove_iunreserved_percent_encoded'), $string);
  5056. // Replace invalid percent characters
  5057. $string = preg_replace('/%(?![A-Fa-f0-9]{2})/', '%25', $string);
  5058. // Add unreserved and % to $extra_chars (the latter is safe because all
  5059. // pct-encoded sections are now valid).
  5060. $extra_chars .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~%';
  5061. // Now replace any bytes that aren't allowed with their pct-encoded versions
  5062. $position = 0;
  5063. $strlen = strlen($string);
  5064. while (($position += strspn($string, $extra_chars, $position)) < $strlen)
  5065. {
  5066. $value = ord($string[$position]);
  5067. // Start position
  5068. $start = $position;
  5069. // By default we are valid
  5070. $valid = true;
  5071. // No one byte sequences are valid due to the while.
  5072. // Two byte sequence:
  5073. if (($value & 0xE0) === 0xC0)
  5074. {
  5075. $character = ($value & 0x1F) << 6;
  5076. $length = 2;
  5077. $remaining = 1;
  5078. }
  5079. // Three byte sequence:
  5080. elseif (($value & 0xF0) === 0xE0)
  5081. {
  5082. $character = ($value & 0x0F) << 12;
  5083. $length = 3;
  5084. $remaining = 2;
  5085. }
  5086. // Four byte sequence:
  5087. elseif (($value & 0xF8) === 0xF0)
  5088. {
  5089. $character = ($value & 0x07) << 18;
  5090. $length = 4;
  5091. $remaining = 3;
  5092. }
  5093. // Invalid byte:
  5094. else
  5095. {
  5096. $valid = false;
  5097. $length = 1;
  5098. $remaining = 0;
  5099. }
  5100. if ($remaining)
  5101. {
  5102. if ($position + $length <= $strlen)
  5103. {
  5104. for ($position++; $remaining; $position++)
  5105. {
  5106. $value = ord($string[$position]);
  5107. // Check that the byte is valid, then add it to the character:
  5108. if (($value & 0xC0) === 0x80)
  5109. {
  5110. $character |= ($value & 0x3F) << (--$remaining * 6);
  5111. }
  5112. // If it is invalid, count the sequence as invalid and reprocess the current byte:
  5113. else
  5114. {
  5115. $valid = false;
  5116. $position--;
  5117. break;
  5118. }
  5119. }
  5120. }
  5121. else
  5122. {
  5123. $position = $strlen - 1;
  5124. $valid = false;
  5125. }
  5126. }
  5127. // Percent encode anything invalid or not in ucschar
  5128. if (
  5129. // Invalid sequences
  5130. !$valid
  5131. // Non-shortest form sequences are invalid
  5132. || $length > 1 && $character <= 0x7F
  5133. || $length > 2 && $character <= 0x7FF
  5134. || $length > 3 && $character <= 0xFFFF
  5135. // Outside of range of ucschar codepoints
  5136. // Noncharacters
  5137. || ($character & 0xFFFE) === 0xFFFE
  5138. || $character >= 0xFDD0 && $character <= 0xFDEF
  5139. || (
  5140. // Everything else not in ucschar
  5141. $character > 0xD7FF && $character < 0xF900
  5142. || $character < 0xA0
  5143. || $character > 0xEFFFD
  5144. )
  5145. && (
  5146. // Everything not in iprivate, if it applies
  5147. !$iprivate
  5148. || $character < 0xE000
  5149. || $character > 0x10FFFD
  5150. )
  5151. )
  5152. {
  5153. // If we were a character, pretend we weren't, but rather an error.
  5154. if ($valid)
  5155. $position--;
  5156. for ($j = $start; $j <= $position; $j++)
  5157. {
  5158. $string = substr_replace($string, sprintf('%%%02X', ord($string[$j])), $j, 1);
  5159. $j += 2;
  5160. $position += 2;
  5161. $strlen += 2;
  5162. }
  5163. }
  5164. }
  5165. return $string;
  5166. }
  5167. protected function remove_iunreserved_percent_encoded($match)
  5168. {
  5169. // As we just have valid percent encoded sequences we can just explode
  5170. // and ignore the first member of the returned array (an empty string).
  5171. $bytes = explode('%', $match[0]);
  5172. // Initialize the new string (this is what will be returned) and that
  5173. // there are no bytes remaining in the current sequence (unsurprising
  5174. // at the first byte!).
  5175. $string = '';
  5176. $remaining = 0;
  5177. // Loop over each and every byte, and set $value to its value
  5178. for ($i = 1, $len = count($bytes); $i < $len; $i++)
  5179. {
  5180. $value = hexdec($bytes[$i]);
  5181. // If we're the first byte of sequence:
  5182. if (!$remaining)
  5183. {
  5184. // Start position
  5185. $start = $i;
  5186. // By default we are valid
  5187. $valid = true;
  5188. // One byte sequence:
  5189. if ($value <= 0x7F)
  5190. {
  5191. $character = $value;
  5192. $length = 1;
  5193. }
  5194. // Two byte sequence:
  5195. elseif (($value & 0xE0) === 0xC0)
  5196. {
  5197. $character = ($value & 0x1F) << 6;
  5198. $length = 2;
  5199. $remaining = 1;
  5200. }
  5201. // Three byte sequence:
  5202. elseif (($value & 0xF0) === 0xE0)
  5203. {
  5204. $character = ($value & 0x0F) << 12;
  5205. $length = 3;
  5206. $remaining = 2;
  5207. }
  5208. // Four byte sequence:
  5209. elseif (($value & 0xF8) === 0xF0)
  5210. {
  5211. $character = ($value & 0x07) << 18;
  5212. $length = 4;
  5213. $remaining = 3;
  5214. }
  5215. // Invalid byte:
  5216. else
  5217. {
  5218. $valid = false;
  5219. $remaining = 0;
  5220. }
  5221. }
  5222. // Continuation byte:
  5223. else
  5224. {
  5225. // Check that the byte is valid, then add it to the character:
  5226. if (($value & 0xC0) === 0x80)
  5227. {
  5228. $remaining--;
  5229. $character |= ($value & 0x3F) << ($remaining * 6);
  5230. }
  5231. // If it is invalid, count the sequence as invalid and reprocess the current byte as the start of a sequence:
  5232. else
  5233. {
  5234. $valid = false;
  5235. $remaining = 0;
  5236. $i--;
  5237. }
  5238. }
  5239. // If we've reached the end of the current byte sequence, append it to Unicode::$data
  5240. if (!$remaining)
  5241. {
  5242. // Percent encode anything invalid or not in iunreserved
  5243. if (
  5244. // Invalid sequences
  5245. !$valid
  5246. // Non-shortest form sequences are invalid
  5247. || $length > 1 && $character <= 0x7F
  5248. || $length > 2 && $character <= 0x7FF
  5249. || $length > 3 && $character <= 0xFFFF
  5250. // Outside of range of iunreserved codepoints
  5251. || $character < 0x2D
  5252. || $character > 0xEFFFD
  5253. // Noncharacters
  5254. || ($character & 0xFFFE) === 0xFFFE
  5255. || $character >= 0xFDD0 && $character <= 0xFDEF
  5256. // Everything else not in iunreserved (this is all BMP)
  5257. || $character === 0x2F
  5258. || $character > 0x39 && $character < 0x41
  5259. || $character > 0x5A && $character < 0x61
  5260. || $character > 0x7A && $character < 0x7E
  5261. || $character > 0x7E && $character < 0xA0
  5262. || $character > 0xD7FF && $character < 0xF900
  5263. )
  5264. {
  5265. for ($j = $start; $j <= $i; $j++)
  5266. {
  5267. $string .= '%' . strtoupper($bytes[$j]);
  5268. }
  5269. }
  5270. else
  5271. {
  5272. for ($j = $start; $j <= $i; $j++)
  5273. {
  5274. $string .= chr(hexdec($bytes[$j]));
  5275. }
  5276. }
  5277. }
  5278. }
  5279. // If we have any bytes left over they are invalid (i.e., we are
  5280. // mid-way through a multi-byte sequence)
  5281. if ($remaining)
  5282. {
  5283. for ($j = $start; $j < $len; $j++)
  5284. {
  5285. $string .= '%' . strtoupper($bytes[$j]);
  5286. }
  5287. }
  5288. return $string;
  5289. }
  5290. protected function scheme_normalization()
  5291. {
  5292. if (isset($this->normalization[$this->scheme]['iuserinfo']) && $this->iuserinfo === $this->normalization[$this->scheme]['iuserinfo'])
  5293. {
  5294. $this->iuserinfo = null;
  5295. }
  5296. if (isset($this->normalization[$this->scheme]['ihost']) && $this->ihost === $this->normalization[$this->scheme]['ihost'])
  5297. {
  5298. $this->ihost = null;
  5299. }
  5300. if (isset($this->normalization[$this->scheme]['port']) && $this->port === $this->normalization[$this->scheme]['port'])
  5301. {
  5302. $this->port = null;
  5303. }
  5304. if (isset($this->normalization[$this->scheme]['ipath']) && $this->ipath === $this->normalization[$this->scheme]['ipath'])
  5305. {
  5306. $this->ipath = '';
  5307. }
  5308. if (isset($this->normalization[$this->scheme]['iquery']) && $this->iquery === $this->normalization[$this->scheme]['iquery'])
  5309. {
  5310. $this->iquery = null;
  5311. }
  5312. if (isset($this->normalization[$this->scheme]['ifragment']) && $this->ifragment === $this->normalization[$this->scheme]['ifragment'])
  5313. {
  5314. $this->ifragment = null;
  5315. }
  5316. }
  5317. public function is_valid()
  5318. {
  5319. $isauthority = $this->iuserinfo !== null || $this->ihost !== null || $this->port !== null;
  5320. if ($this->ipath !== '' &&
  5321. (
  5322. $isauthority && (
  5323. $this->ipath[0] !== '/' ||
  5324. substr($this->ipath, 0, 2) === '//'
  5325. ) ||
  5326. (
  5327. $this->scheme === null &&
  5328. !$isauthority &&
  5329. strpos($this->ipath, ':') !== false &&
  5330. (strpos($this->ipath, '/') === false ? true : strpos($this->ipath, ':') < strpos($this->ipath, '/'))
  5331. )
  5332. )
  5333. )
  5334. {
  5335. return false;
  5336. }
  5337. return true;
  5338. }
  5339. public function set_iri($iri)
  5340. {
  5341. static $cache;
  5342. if (!$cache)
  5343. {
  5344. $cache = array();
  5345. }
  5346. if ($iri === null)
  5347. {
  5348. return true;
  5349. }
  5350. elseif (isset($cache[$iri]))
  5351. {
  5352. list($this->scheme,
  5353. $this->iuserinfo,
  5354. $this->ihost,
  5355. $this->port,
  5356. $this->ipath,
  5357. $this->iquery,
  5358. $this->ifragment,
  5359. $return) = $cache[$iri];
  5360. return $return;
  5361. }
  5362. else
  5363. {
  5364. $parsed = $this->parse_iri((string) $iri);
  5365. $return = $this->set_scheme($parsed['scheme'])
  5366. && $this->set_authority($parsed['authority'])
  5367. && $this->set_path($parsed['path'])
  5368. && $this->set_query($parsed['query'])
  5369. && $this->set_fragment($parsed['fragment']);
  5370. $cache[$iri] = array($this->scheme,
  5371. $this->iuserinfo,
  5372. $this->ihost,
  5373. $this->port,
  5374. $this->ipath,
  5375. $this->iquery,
  5376. $this->ifragment,
  5377. $return);
  5378. return $return;
  5379. }
  5380. }
  5381. public function set_scheme($scheme)
  5382. {
  5383. if ($scheme === null)
  5384. {
  5385. $this->scheme = null;
  5386. }
  5387. elseif (!preg_match('/^[A-Za-z][0-9A-Za-z+\-.]*$/', $scheme))
  5388. {
  5389. $this->scheme = null;
  5390. return false;
  5391. }
  5392. else
  5393. {
  5394. $this->scheme = strtolower($scheme);
  5395. }
  5396. return true;
  5397. }
  5398. public function set_authority($authority)
  5399. {
  5400. static $cache;
  5401. if (!$cache)
  5402. $cache = array();
  5403. if ($authority === null)
  5404. {
  5405. $this->iuserinfo = null;
  5406. $this->ihost = null;
  5407. $this->port = null;
  5408. return true;
  5409. }
  5410. elseif (isset($cache[$authority]))
  5411. {
  5412. list($this->iuserinfo,
  5413. $this->ihost,
  5414. $this->port,
  5415. $return) = $cache[$authority];
  5416. return $return;
  5417. }
  5418. else
  5419. {
  5420. $remaining = $authority;
  5421. if (($iuserinfo_end = strrpos($remaining, '@')) !== false)
  5422. {
  5423. $iuserinfo = substr($remaining, 0, $iuserinfo_end);
  5424. $remaining = substr($remaining, $iuserinfo_end + 1);
  5425. }
  5426. else
  5427. {
  5428. $iuserinfo = null;
  5429. }
  5430. if (($port_start = strpos($remaining, ':', strpos($remaining, ']'))) !== false)
  5431. {
  5432. if (($port = substr($remaining, $port_start + 1)) === false)
  5433. {
  5434. $port = null;
  5435. }
  5436. $remaining = substr($remaining, 0, $port_start);
  5437. }
  5438. else
  5439. {
  5440. $port = null;
  5441. }
  5442. $return = $this->set_userinfo($iuserinfo) &&
  5443. $this->set_host($remaining) &&
  5444. $this->set_port($port);
  5445. $cache[$authority] = array($this->iuserinfo,
  5446. $this->ihost,
  5447. $this->port,
  5448. $return);
  5449. return $return;
  5450. }
  5451. }
  5452. public function set_userinfo($iuserinfo)
  5453. {
  5454. if ($iuserinfo === null)
  5455. {
  5456. $this->iuserinfo = null;
  5457. }
  5458. else
  5459. {
  5460. $this->iuserinfo = $this->replace_invalid_with_pct_encoding($iuserinfo, '!$&\'()*+,;=:');
  5461. $this->scheme_normalization();
  5462. }
  5463. return true;
  5464. }
  5465. public function set_host($ihost)
  5466. {
  5467. if ($ihost === null)
  5468. {
  5469. $this->ihost = null;
  5470. return true;
  5471. }
  5472. elseif (substr($ihost, 0, 1) === '[' && substr($ihost, -1) === ']')
  5473. {
  5474. if (SimplePie_Net_IPv6::check_ipv6(substr($ihost, 1, -1)))
  5475. {
  5476. $this->ihost = '[' . SimplePie_Net_IPv6::compress(substr($ihost, 1, -1)) . ']';
  5477. }
  5478. else
  5479. {
  5480. $this->ihost = null;
  5481. return false;
  5482. }
  5483. }
  5484. else
  5485. {
  5486. $ihost = $this->replace_invalid_with_pct_encoding($ihost, '!$&\'()*+,;=');
  5487. // Lowercase, but ignore pct-encoded sections (as they should
  5488. // remain uppercase). This must be done after the previous step
  5489. // as that can add unescaped characters.
  5490. $position = 0;
  5491. $strlen = strlen($ihost);
  5492. while (($position += strcspn($ihost, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ%', $position)) < $strlen)
  5493. {
  5494. if ($ihost[$position] === '%')
  5495. {
  5496. $position += 3;
  5497. }
  5498. else
  5499. {
  5500. $ihost[$position] = strtolower($ihost[$position]);
  5501. $position++;
  5502. }
  5503. }
  5504. $this->ihost = $ihost;
  5505. }
  5506. $this->scheme_normalization();
  5507. return true;
  5508. }
  5509. public function set_port($port)
  5510. {
  5511. if ($port === null)
  5512. {
  5513. $this->port = null;
  5514. return true;
  5515. }
  5516. elseif (strspn($port, '0123456789') === strlen($port))
  5517. {
  5518. $this->port = (int) $port;
  5519. $this->scheme_normalization();
  5520. return true;
  5521. }
  5522. else
  5523. {
  5524. $this->port = null;
  5525. return false;
  5526. }
  5527. }
  5528. public function set_path($ipath)
  5529. {
  5530. static $cache;
  5531. if (!$cache)
  5532. {
  5533. $cache = array();
  5534. }
  5535. $ipath = (string) $ipath;
  5536. if (isset($cache[$ipath]))
  5537. {
  5538. $this->ipath = $cache[$ipath][(int) ($this->scheme !== null)];
  5539. }
  5540. else
  5541. {
  5542. $valid = $this->replace_invalid_with_pct_encoding($ipath, '!$&\'()*+,;=@:/');
  5543. $removed = $this->remove_dot_segments($valid);
  5544. $cache[$ipath] = array($valid, $removed);
  5545. $this->ipath = ($this->scheme !== null) ? $removed : $valid;
  5546. }
  5547. $this->scheme_normalization();
  5548. return true;
  5549. }
  5550. public function set_query($iquery)
  5551. {
  5552. if ($iquery === null)
  5553. {
  5554. $this->iquery = null;
  5555. }
  5556. else
  5557. {
  5558. $this->iquery = $this->replace_invalid_with_pct_encoding($iquery, '!$&\'()*+,;=:@/?', true);
  5559. $this->scheme_normalization();
  5560. }
  5561. return true;
  5562. }
  5563. public function set_fragment($ifragment)
  5564. {
  5565. if ($ifragment === null)
  5566. {
  5567. $this->ifragment = null;
  5568. }
  5569. else
  5570. {
  5571. $this->ifragment = $this->replace_invalid_with_pct_encoding($ifragment, '!$&\'()*+,;=:@/?');
  5572. $this->scheme_normalization();
  5573. }
  5574. return true;
  5575. }
  5576. public function to_uri($string)
  5577. {
  5578. static $non_ascii;
  5579. if (!$non_ascii)
  5580. {
  5581. $non_ascii = implode('', range("\x80", "\xFF"));
  5582. }
  5583. $position = 0;
  5584. $strlen = strlen($string);
  5585. while (($position += strcspn($string, $non_ascii, $position)) < $strlen)
  5586. {
  5587. $string = substr_replace($string, sprintf('%%%02X', ord($string[$position])), $position, 1);
  5588. $position += 3;
  5589. $strlen += 2;
  5590. }
  5591. return $string;
  5592. }
  5593. public function get_iri()
  5594. {
  5595. if (!$this->is_valid())
  5596. {
  5597. return false;
  5598. }
  5599. $iri = '';
  5600. if ($this->scheme !== null)
  5601. {
  5602. $iri .= $this->scheme . ':';
  5603. }
  5604. if (($iauthority = $this->get_iauthority()) !== null)
  5605. {
  5606. $iri .= '//' . $iauthority;
  5607. }
  5608. if ($this->ipath !== '')
  5609. {
  5610. $iri .= $this->ipath;
  5611. }
  5612. elseif (!empty($this->normalization[$this->scheme]['ipath']) && $iauthority !== null && $iauthority !== '')
  5613. {
  5614. $iri .= $this->normalization[$this->scheme]['ipath'];
  5615. }
  5616. if ($this->iquery !== null)
  5617. {
  5618. $iri .= '?' . $this->iquery;
  5619. }
  5620. if ($this->ifragment !== null)
  5621. {
  5622. $iri .= '#' . $this->ifragment;
  5623. }
  5624. return $iri;
  5625. }
  5626. public function get_uri()
  5627. {
  5628. return $this->to_uri($this->get_iri());
  5629. }
  5630. protected function get_iauthority()
  5631. {
  5632. if ($this->iuserinfo !== null || $this->ihost !== null || $this->port !== null)
  5633. {
  5634. $iauthority = '';
  5635. if ($this->iuserinfo !== null)
  5636. {
  5637. $iauthority .= $this->iuserinfo . '@';
  5638. }
  5639. if ($this->ihost !== null)
  5640. {
  5641. $iauthority .= $this->ihost;
  5642. }
  5643. if ($this->port !== null)
  5644. {
  5645. $iauthority .= ':' . $this->port;
  5646. }
  5647. return $iauthority;
  5648. }
  5649. else
  5650. {
  5651. return null;
  5652. }
  5653. }
  5654. protected function get_authority()
  5655. {
  5656. $iauthority = $this->get_iauthority();
  5657. if (is_string($iauthority))
  5658. return $this->to_uri($iauthority);
  5659. else
  5660. return $iauthority;
  5661. }
  5662. }
  5663. class SimplePie_Item
  5664. {
  5665. var $feed;
  5666. var $data = array();
  5667. protected $registry;
  5668. public function __construct($feed, $data)
  5669. {
  5670. $this->feed = $feed;
  5671. $this->data = $data;
  5672. }
  5673. public function set_registry(SimplePie_Registry $registry)
  5674. {
  5675. $this->registry = $registry;
  5676. }
  5677. public function __toString()
  5678. {
  5679. return md5(serialize($this->data));
  5680. }
  5681. public function __destruct()
  5682. {
  5683. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
  5684. {
  5685. unset($this->feed);
  5686. }
  5687. }
  5688. public function get_item_tags($namespace, $tag)
  5689. {
  5690. if (isset($this->data['child'][$namespace][$tag]))
  5691. {
  5692. return $this->data['child'][$namespace][$tag];
  5693. }
  5694. else
  5695. {
  5696. return null;
  5697. }
  5698. }
  5699. public function get_base($element = array())
  5700. {
  5701. return $this->feed->get_base($element);
  5702. }
  5703. public function sanitize($data, $type, $base = '')
  5704. {
  5705. return $this->feed->sanitize($data, $type, $base);
  5706. }
  5707. public function get_feed()
  5708. {
  5709. return $this->feed;
  5710. }
  5711. public function get_id($hash = false)
  5712. {
  5713. if (!$hash)
  5714. {
  5715. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id'))
  5716. {
  5717. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5718. }
  5719. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'id'))
  5720. {
  5721. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5722. }
  5723. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
  5724. {
  5725. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5726. }
  5727. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'identifier'))
  5728. {
  5729. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5730. }
  5731. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'identifier'))
  5732. {
  5733. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5734. }
  5735. elseif (isset($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about']))
  5736. {
  5737. return $this->sanitize($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about'], SIMPLEPIE_CONSTRUCT_TEXT);
  5738. }
  5739. elseif (($return = $this->get_permalink()) !== null)
  5740. {
  5741. return $return;
  5742. }
  5743. elseif (($return = $this->get_title()) !== null)
  5744. {
  5745. return $return;
  5746. }
  5747. }
  5748. if ($this->get_permalink() !== null || $this->get_title() !== null)
  5749. {
  5750. return md5($this->get_permalink() . $this->get_title());
  5751. }
  5752. else
  5753. {
  5754. return md5(serialize($this->data));
  5755. }
  5756. }
  5757. public function get_title()
  5758. {
  5759. if (!isset($this->data['title']))
  5760. {
  5761. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  5762. {
  5763. $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  5764. }
  5765. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  5766. {
  5767. $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  5768. }
  5769. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  5770. {
  5771. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  5772. }
  5773. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  5774. {
  5775. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  5776. }
  5777. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  5778. {
  5779. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  5780. }
  5781. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  5782. {
  5783. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5784. }
  5785. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  5786. {
  5787. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5788. }
  5789. else
  5790. {
  5791. $this->data['title'] = null;
  5792. }
  5793. }
  5794. return $this->data['title'];
  5795. }
  5796. public function get_description($description_only = false)
  5797. {
  5798. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary'))
  5799. {
  5800. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  5801. }
  5802. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary'))
  5803. {
  5804. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  5805. }
  5806. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  5807. {
  5808. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  5809. }
  5810. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
  5811. {
  5812. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  5813. }
  5814. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  5815. {
  5816. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5817. }
  5818. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  5819. {
  5820. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5821. }
  5822. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  5823. {
  5824. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  5825. }
  5826. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  5827. {
  5828. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5829. }
  5830. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
  5831. {
  5832. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
  5833. }
  5834. elseif (!$description_only)
  5835. {
  5836. return $this->get_content(true);
  5837. }
  5838. else
  5839. {
  5840. return null;
  5841. }
  5842. }
  5843. public function get_content($content_only = false)
  5844. {
  5845. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content'))
  5846. {
  5847. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_content_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  5848. }
  5849. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content'))
  5850. {
  5851. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  5852. }
  5853. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded'))
  5854. {
  5855. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  5856. }
  5857. elseif (!$content_only)
  5858. {
  5859. return $this->get_description(true);
  5860. }
  5861. else
  5862. {
  5863. return null;
  5864. }
  5865. }
  5866. public function get_category($key = 0)
  5867. {
  5868. $categories = $this->get_categories();
  5869. if (isset($categories[$key]))
  5870. {
  5871. return $categories[$key];
  5872. }
  5873. else
  5874. {
  5875. return null;
  5876. }
  5877. }
  5878. public function get_categories()
  5879. {
  5880. $categories = array();
  5881. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  5882. {
  5883. $term = null;
  5884. $scheme = null;
  5885. $label = null;
  5886. if (isset($category['attribs']['']['term']))
  5887. {
  5888. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  5889. }
  5890. if (isset($category['attribs']['']['scheme']))
  5891. {
  5892. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5893. }
  5894. if (isset($category['attribs']['']['label']))
  5895. {
  5896. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  5897. }
  5898. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  5899. }
  5900. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
  5901. {
  5902. // This is really the label, but keep this as the term also for BC.
  5903. // Label will also work on retrieving because that falls back to term.
  5904. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5905. if (isset($category['attribs']['']['domain']))
  5906. {
  5907. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  5908. }
  5909. else
  5910. {
  5911. $scheme = null;
  5912. }
  5913. $categories[] = $this->registry->create('Category', array($term, $scheme, null));
  5914. }
  5915. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  5916. {
  5917. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  5918. }
  5919. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  5920. {
  5921. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  5922. }
  5923. if (!empty($categories))
  5924. {
  5925. return array_unique($categories);
  5926. }
  5927. else
  5928. {
  5929. return null;
  5930. }
  5931. }
  5932. public function get_author($key = 0)
  5933. {
  5934. $authors = $this->get_authors();
  5935. if (isset($authors[$key]))
  5936. {
  5937. return $authors[$key];
  5938. }
  5939. else
  5940. {
  5941. return null;
  5942. }
  5943. }
  5944. public function get_contributor($key = 0)
  5945. {
  5946. $contributors = $this->get_contributors();
  5947. if (isset($contributors[$key]))
  5948. {
  5949. return $contributors[$key];
  5950. }
  5951. else
  5952. {
  5953. return null;
  5954. }
  5955. }
  5956. public function get_contributors()
  5957. {
  5958. $contributors = array();
  5959. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  5960. {
  5961. $name = null;
  5962. $uri = null;
  5963. $email = null;
  5964. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  5965. {
  5966. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5967. }
  5968. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  5969. {
  5970. $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]));
  5971. }
  5972. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  5973. {
  5974. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5975. }
  5976. if ($name !== null || $email !== null || $uri !== null)
  5977. {
  5978. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  5979. }
  5980. }
  5981. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  5982. {
  5983. $name = null;
  5984. $url = null;
  5985. $email = null;
  5986. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  5987. {
  5988. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5989. }
  5990. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  5991. {
  5992. $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]));
  5993. }
  5994. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  5995. {
  5996. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5997. }
  5998. if ($name !== null || $email !== null || $url !== null)
  5999. {
  6000. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  6001. }
  6002. }
  6003. if (!empty($contributors))
  6004. {
  6005. return array_unique($contributors);
  6006. }
  6007. else
  6008. {
  6009. return null;
  6010. }
  6011. }
  6012. public function get_authors()
  6013. {
  6014. $authors = array();
  6015. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  6016. {
  6017. $name = null;
  6018. $uri = null;
  6019. $email = null;
  6020. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  6021. {
  6022. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6023. }
  6024. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  6025. {
  6026. $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]));
  6027. }
  6028. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  6029. {
  6030. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6031. }
  6032. if ($name !== null || $email !== null || $uri !== null)
  6033. {
  6034. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  6035. }
  6036. }
  6037. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  6038. {
  6039. $name = null;
  6040. $url = null;
  6041. $email = null;
  6042. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  6043. {
  6044. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6045. }
  6046. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  6047. {
  6048. $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]));
  6049. }
  6050. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  6051. {
  6052. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6053. }
  6054. if ($name !== null || $email !== null || $url !== null)
  6055. {
  6056. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  6057. }
  6058. }
  6059. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'author'))
  6060. {
  6061. $authors[] = $this->registry->create('Author', array(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)));
  6062. }
  6063. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  6064. {
  6065. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  6066. }
  6067. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  6068. {
  6069. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  6070. }
  6071. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  6072. {
  6073. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  6074. }
  6075. if (!empty($authors))
  6076. {
  6077. return array_unique($authors);
  6078. }
  6079. elseif (($source = $this->get_source()) && ($authors = $source->get_authors()))
  6080. {
  6081. return $authors;
  6082. }
  6083. elseif ($authors = $this->feed->get_authors())
  6084. {
  6085. return $authors;
  6086. }
  6087. else
  6088. {
  6089. return null;
  6090. }
  6091. }
  6092. public function get_copyright()
  6093. {
  6094. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  6095. {
  6096. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  6097. }
  6098. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  6099. {
  6100. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6101. }
  6102. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  6103. {
  6104. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6105. }
  6106. else
  6107. {
  6108. return null;
  6109. }
  6110. }
  6111. public function get_date($date_format = 'j F Y, g:i a')
  6112. {
  6113. if (!isset($this->data['date']))
  6114. {
  6115. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'))
  6116. {
  6117. $this->data['date']['raw'] = $return[0]['data'];
  6118. }
  6119. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  6120. {
  6121. $this->data['date']['raw'] = $return[0]['data'];
  6122. }
  6123. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'issued'))
  6124. {
  6125. $this->data['date']['raw'] = $return[0]['data'];
  6126. }
  6127. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'created'))
  6128. {
  6129. $this->data['date']['raw'] = $return[0]['data'];
  6130. }
  6131. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'modified'))
  6132. {
  6133. $this->data['date']['raw'] = $return[0]['data'];
  6134. }
  6135. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'pubDate'))
  6136. {
  6137. $this->data['date']['raw'] = $return[0]['data'];
  6138. }
  6139. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date'))
  6140. {
  6141. $this->data['date']['raw'] = $return[0]['data'];
  6142. }
  6143. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date'))
  6144. {
  6145. $this->data['date']['raw'] = $return[0]['data'];
  6146. }
  6147. if (!empty($this->data['date']['raw']))
  6148. {
  6149. $parser = $this->registry->call('Parse_Date', 'get');
  6150. $this->data['date']['parsed'] = $parser->parse($this->data['date']['raw']);
  6151. }
  6152. else
  6153. {
  6154. $this->data['date'] = null;
  6155. }
  6156. }
  6157. if ($this->data['date'])
  6158. {
  6159. $date_format = (string) $date_format;
  6160. switch ($date_format)
  6161. {
  6162. case '':
  6163. return $this->sanitize($this->data['date']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  6164. case 'U':
  6165. return $this->data['date']['parsed'];
  6166. default:
  6167. return date($date_format, $this->data['date']['parsed']);
  6168. }
  6169. }
  6170. else
  6171. {
  6172. return null;
  6173. }
  6174. }
  6175. public function get_updated_date($date_format = 'j F Y, g:i a')
  6176. {
  6177. if (!isset($this->data['updated']))
  6178. {
  6179. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  6180. {
  6181. $this->data['updated']['raw'] = $return[0]['data'];
  6182. }
  6183. if (!empty($this->data['updated']['raw']))
  6184. {
  6185. $parser = $this->registry->call('Parse_Date', 'get');
  6186. $this->data['updated']['parsed'] = $parser->parse($this->data['date']['raw']);
  6187. }
  6188. else
  6189. {
  6190. $this->data['updated'] = null;
  6191. }
  6192. }
  6193. if ($this->data['updated'])
  6194. {
  6195. $date_format = (string) $date_format;
  6196. switch ($date_format)
  6197. {
  6198. case '':
  6199. return $this->sanitize($this->data['updated']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  6200. case 'U':
  6201. return $this->data['updated']['parsed'];
  6202. default:
  6203. return date($date_format, $this->data['updated']['parsed']);
  6204. }
  6205. }
  6206. else
  6207. {
  6208. return null;
  6209. }
  6210. }
  6211. public function get_local_date($date_format = '%c')
  6212. {
  6213. if (!$date_format)
  6214. {
  6215. return $this->sanitize($this->get_date(''), SIMPLEPIE_CONSTRUCT_TEXT);
  6216. }
  6217. elseif (($date = $this->get_date('U')) !== null && $date !== false)
  6218. {
  6219. return strftime($date_format, $date);
  6220. }
  6221. else
  6222. {
  6223. return null;
  6224. }
  6225. }
  6226. public function get_gmdate($date_format = 'j F Y, g:i a')
  6227. {
  6228. $date = $this->get_date('U');
  6229. if ($date === null)
  6230. {
  6231. return null;
  6232. }
  6233. return gmdate($date_format, $date);
  6234. }
  6235. public function get_updated_gmdate($date_format = 'j F Y, g:i a')
  6236. {
  6237. $date = $this->get_updated_date('U');
  6238. if ($date === null)
  6239. {
  6240. return null;
  6241. }
  6242. return gmdate($date_format, $date);
  6243. }
  6244. public function get_permalink()
  6245. {
  6246. $link = $this->get_link();
  6247. $enclosure = $this->get_enclosure(0);
  6248. if ($link !== null)
  6249. {
  6250. return $link;
  6251. }
  6252. elseif ($enclosure !== null)
  6253. {
  6254. return $enclosure->get_link();
  6255. }
  6256. else
  6257. {
  6258. return null;
  6259. }
  6260. }
  6261. public function get_link($key = 0, $rel = 'alternate')
  6262. {
  6263. $links = $this->get_links($rel);
  6264. if ($links[$key] !== null)
  6265. {
  6266. return $links[$key];
  6267. }
  6268. else
  6269. {
  6270. return null;
  6271. }
  6272. }
  6273. public function get_links($rel = 'alternate')
  6274. {
  6275. if (!isset($this->data['links']))
  6276. {
  6277. $this->data['links'] = array();
  6278. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  6279. {
  6280. if (isset($link['attribs']['']['href']))
  6281. {
  6282. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  6283. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  6284. }
  6285. }
  6286. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
  6287. {
  6288. if (isset($link['attribs']['']['href']))
  6289. {
  6290. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  6291. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  6292. }
  6293. }
  6294. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  6295. {
  6296. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  6297. }
  6298. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  6299. {
  6300. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  6301. }
  6302. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  6303. {
  6304. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  6305. }
  6306. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
  6307. {
  6308. if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) === 'true')
  6309. {
  6310. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  6311. }
  6312. }
  6313. $keys = array_keys($this->data['links']);
  6314. foreach ($keys as $key)
  6315. {
  6316. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
  6317. {
  6318. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  6319. {
  6320. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  6321. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  6322. }
  6323. else
  6324. {
  6325. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  6326. }
  6327. }
  6328. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  6329. {
  6330. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  6331. }
  6332. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  6333. }
  6334. }
  6335. if (isset($this->data['links'][$rel]))
  6336. {
  6337. return $this->data['links'][$rel];
  6338. }
  6339. else
  6340. {
  6341. return null;
  6342. }
  6343. }
  6344. public function get_enclosure($key = 0, $prefer = null)
  6345. {
  6346. $enclosures = $this->get_enclosures();
  6347. if (isset($enclosures[$key]))
  6348. {
  6349. return $enclosures[$key];
  6350. }
  6351. else
  6352. {
  6353. return null;
  6354. }
  6355. }
  6356. public function get_enclosures()
  6357. {
  6358. if (!isset($this->data['enclosures']))
  6359. {
  6360. $this->data['enclosures'] = array();
  6361. // Elements
  6362. $captions_parent = null;
  6363. $categories_parent = null;
  6364. $copyrights_parent = null;
  6365. $credits_parent = null;
  6366. $description_parent = null;
  6367. $duration_parent = null;
  6368. $hashes_parent = null;
  6369. $keywords_parent = null;
  6370. $player_parent = null;
  6371. $ratings_parent = null;
  6372. $restrictions_parent = null;
  6373. $thumbnails_parent = null;
  6374. $title_parent = null;
  6375. // Let's do the channel and item-level ones first, and just re-use them if we need to.
  6376. $parent = $this->get_feed();
  6377. // CAPTIONS
  6378. if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  6379. {
  6380. foreach ($captions as $caption)
  6381. {
  6382. $caption_type = null;
  6383. $caption_lang = null;
  6384. $caption_startTime = null;
  6385. $caption_endTime = null;
  6386. $caption_text = null;
  6387. if (isset($caption['attribs']['']['type']))
  6388. {
  6389. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6390. }
  6391. if (isset($caption['attribs']['']['lang']))
  6392. {
  6393. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  6394. }
  6395. if (isset($caption['attribs']['']['start']))
  6396. {
  6397. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  6398. }
  6399. if (isset($caption['attribs']['']['end']))
  6400. {
  6401. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  6402. }
  6403. if (isset($caption['data']))
  6404. {
  6405. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6406. }
  6407. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  6408. }
  6409. }
  6410. elseif ($captions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  6411. {
  6412. foreach ($captions as $caption)
  6413. {
  6414. $caption_type = null;
  6415. $caption_lang = null;
  6416. $caption_startTime = null;
  6417. $caption_endTime = null;
  6418. $caption_text = null;
  6419. if (isset($caption['attribs']['']['type']))
  6420. {
  6421. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6422. }
  6423. if (isset($caption['attribs']['']['lang']))
  6424. {
  6425. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  6426. }
  6427. if (isset($caption['attribs']['']['start']))
  6428. {
  6429. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  6430. }
  6431. if (isset($caption['attribs']['']['end']))
  6432. {
  6433. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  6434. }
  6435. if (isset($caption['data']))
  6436. {
  6437. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6438. }
  6439. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  6440. }
  6441. }
  6442. if (is_array($captions_parent))
  6443. {
  6444. $captions_parent = array_values(array_unique($captions_parent));
  6445. }
  6446. // CATEGORIES
  6447. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  6448. {
  6449. $term = null;
  6450. $scheme = null;
  6451. $label = null;
  6452. if (isset($category['data']))
  6453. {
  6454. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6455. }
  6456. if (isset($category['attribs']['']['scheme']))
  6457. {
  6458. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6459. }
  6460. else
  6461. {
  6462. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  6463. }
  6464. if (isset($category['attribs']['']['label']))
  6465. {
  6466. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  6467. }
  6468. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  6469. }
  6470. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  6471. {
  6472. $term = null;
  6473. $scheme = null;
  6474. $label = null;
  6475. if (isset($category['data']))
  6476. {
  6477. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6478. }
  6479. if (isset($category['attribs']['']['scheme']))
  6480. {
  6481. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6482. }
  6483. else
  6484. {
  6485. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  6486. }
  6487. if (isset($category['attribs']['']['label']))
  6488. {
  6489. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  6490. }
  6491. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  6492. }
  6493. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'category') as $category)
  6494. {
  6495. $term = null;
  6496. $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
  6497. $label = null;
  6498. if (isset($category['attribs']['']['text']))
  6499. {
  6500. $label = $this->sanitize($category['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  6501. }
  6502. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  6503. if (isset($category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category']))
  6504. {
  6505. foreach ((array) $category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'] as $subcategory)
  6506. {
  6507. if (isset($subcategory['attribs']['']['text']))
  6508. {
  6509. $label = $this->sanitize($subcategory['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  6510. }
  6511. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  6512. }
  6513. }
  6514. }
  6515. if (is_array($categories_parent))
  6516. {
  6517. $categories_parent = array_values(array_unique($categories_parent));
  6518. }
  6519. // COPYRIGHT
  6520. if ($copyright = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  6521. {
  6522. $copyright_url = null;
  6523. $copyright_label = null;
  6524. if (isset($copyright[0]['attribs']['']['url']))
  6525. {
  6526. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  6527. }
  6528. if (isset($copyright[0]['data']))
  6529. {
  6530. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6531. }
  6532. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  6533. }
  6534. elseif ($copyright = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  6535. {
  6536. $copyright_url = null;
  6537. $copyright_label = null;
  6538. if (isset($copyright[0]['attribs']['']['url']))
  6539. {
  6540. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  6541. }
  6542. if (isset($copyright[0]['data']))
  6543. {
  6544. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6545. }
  6546. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  6547. }
  6548. // CREDITS
  6549. if ($credits = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  6550. {
  6551. foreach ($credits as $credit)
  6552. {
  6553. $credit_role = null;
  6554. $credit_scheme = null;
  6555. $credit_name = null;
  6556. if (isset($credit['attribs']['']['role']))
  6557. {
  6558. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  6559. }
  6560. if (isset($credit['attribs']['']['scheme']))
  6561. {
  6562. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6563. }
  6564. else
  6565. {
  6566. $credit_scheme = 'urn:ebu';
  6567. }
  6568. if (isset($credit['data']))
  6569. {
  6570. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6571. }
  6572. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  6573. }
  6574. }
  6575. elseif ($credits = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  6576. {
  6577. foreach ($credits as $credit)
  6578. {
  6579. $credit_role = null;
  6580. $credit_scheme = null;
  6581. $credit_name = null;
  6582. if (isset($credit['attribs']['']['role']))
  6583. {
  6584. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  6585. }
  6586. if (isset($credit['attribs']['']['scheme']))
  6587. {
  6588. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6589. }
  6590. else
  6591. {
  6592. $credit_scheme = 'urn:ebu';
  6593. }
  6594. if (isset($credit['data']))
  6595. {
  6596. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6597. }
  6598. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  6599. }
  6600. }
  6601. if (is_array($credits_parent))
  6602. {
  6603. $credits_parent = array_values(array_unique($credits_parent));
  6604. }
  6605. // DESCRIPTION
  6606. if ($description_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  6607. {
  6608. if (isset($description_parent[0]['data']))
  6609. {
  6610. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6611. }
  6612. }
  6613. elseif ($description_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  6614. {
  6615. if (isset($description_parent[0]['data']))
  6616. {
  6617. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6618. }
  6619. }
  6620. // DURATION
  6621. if ($duration_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'duration'))
  6622. {
  6623. $seconds = null;
  6624. $minutes = null;
  6625. $hours = null;
  6626. if (isset($duration_parent[0]['data']))
  6627. {
  6628. $temp = explode(':', $this->sanitize($duration_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  6629. if (sizeof($temp) > 0)
  6630. {
  6631. $seconds = (int) array_pop($temp);
  6632. }
  6633. if (sizeof($temp) > 0)
  6634. {
  6635. $minutes = (int) array_pop($temp);
  6636. $seconds += $minutes * 60;
  6637. }
  6638. if (sizeof($temp) > 0)
  6639. {
  6640. $hours = (int) array_pop($temp);
  6641. $seconds += $hours * 3600;
  6642. }
  6643. unset($temp);
  6644. $duration_parent = $seconds;
  6645. }
  6646. }
  6647. // HASHES
  6648. if ($hashes_iterator = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  6649. {
  6650. foreach ($hashes_iterator as $hash)
  6651. {
  6652. $value = null;
  6653. $algo = null;
  6654. if (isset($hash['data']))
  6655. {
  6656. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6657. }
  6658. if (isset($hash['attribs']['']['algo']))
  6659. {
  6660. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  6661. }
  6662. else
  6663. {
  6664. $algo = 'md5';
  6665. }
  6666. $hashes_parent[] = $algo.':'.$value;
  6667. }
  6668. }
  6669. elseif ($hashes_iterator = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  6670. {
  6671. foreach ($hashes_iterator as $hash)
  6672. {
  6673. $value = null;
  6674. $algo = null;
  6675. if (isset($hash['data']))
  6676. {
  6677. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6678. }
  6679. if (isset($hash['attribs']['']['algo']))
  6680. {
  6681. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  6682. }
  6683. else
  6684. {
  6685. $algo = 'md5';
  6686. }
  6687. $hashes_parent[] = $algo.':'.$value;
  6688. }
  6689. }
  6690. if (is_array($hashes_parent))
  6691. {
  6692. $hashes_parent = array_values(array_unique($hashes_parent));
  6693. }
  6694. // KEYWORDS
  6695. if ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  6696. {
  6697. if (isset($keywords[0]['data']))
  6698. {
  6699. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  6700. foreach ($temp as $word)
  6701. {
  6702. $keywords_parent[] = trim($word);
  6703. }
  6704. }
  6705. unset($temp);
  6706. }
  6707. elseif ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  6708. {
  6709. if (isset($keywords[0]['data']))
  6710. {
  6711. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  6712. foreach ($temp as $word)
  6713. {
  6714. $keywords_parent[] = trim($word);
  6715. }
  6716. }
  6717. unset($temp);
  6718. }
  6719. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  6720. {
  6721. if (isset($keywords[0]['data']))
  6722. {
  6723. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  6724. foreach ($temp as $word)
  6725. {
  6726. $keywords_parent[] = trim($word);
  6727. }
  6728. }
  6729. unset($temp);
  6730. }
  6731. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  6732. {
  6733. if (isset($keywords[0]['data']))
  6734. {
  6735. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  6736. foreach ($temp as $word)
  6737. {
  6738. $keywords_parent[] = trim($word);
  6739. }
  6740. }
  6741. unset($temp);
  6742. }
  6743. if (is_array($keywords_parent))
  6744. {
  6745. $keywords_parent = array_values(array_unique($keywords_parent));
  6746. }
  6747. // PLAYER
  6748. if ($player_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  6749. {
  6750. if (isset($player_parent[0]['attribs']['']['url']))
  6751. {
  6752. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6753. }
  6754. }
  6755. elseif ($player_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  6756. {
  6757. if (isset($player_parent[0]['attribs']['']['url']))
  6758. {
  6759. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6760. }
  6761. }
  6762. // RATINGS
  6763. if ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  6764. {
  6765. foreach ($ratings as $rating)
  6766. {
  6767. $rating_scheme = null;
  6768. $rating_value = null;
  6769. if (isset($rating['attribs']['']['scheme']))
  6770. {
  6771. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6772. }
  6773. else
  6774. {
  6775. $rating_scheme = 'urn:simple';
  6776. }
  6777. if (isset($rating['data']))
  6778. {
  6779. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6780. }
  6781. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  6782. }
  6783. }
  6784. elseif ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  6785. {
  6786. foreach ($ratings as $rating)
  6787. {
  6788. $rating_scheme = 'urn:itunes';
  6789. $rating_value = null;
  6790. if (isset($rating['data']))
  6791. {
  6792. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6793. }
  6794. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  6795. }
  6796. }
  6797. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  6798. {
  6799. foreach ($ratings as $rating)
  6800. {
  6801. $rating_scheme = null;
  6802. $rating_value = null;
  6803. if (isset($rating['attribs']['']['scheme']))
  6804. {
  6805. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6806. }
  6807. else
  6808. {
  6809. $rating_scheme = 'urn:simple';
  6810. }
  6811. if (isset($rating['data']))
  6812. {
  6813. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6814. }
  6815. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  6816. }
  6817. }
  6818. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  6819. {
  6820. foreach ($ratings as $rating)
  6821. {
  6822. $rating_scheme = 'urn:itunes';
  6823. $rating_value = null;
  6824. if (isset($rating['data']))
  6825. {
  6826. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6827. }
  6828. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  6829. }
  6830. }
  6831. if (is_array($ratings_parent))
  6832. {
  6833. $ratings_parent = array_values(array_unique($ratings_parent));
  6834. }
  6835. // RESTRICTIONS
  6836. if ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  6837. {
  6838. foreach ($restrictions as $restriction)
  6839. {
  6840. $restriction_relationship = null;
  6841. $restriction_type = null;
  6842. $restriction_value = null;
  6843. if (isset($restriction['attribs']['']['relationship']))
  6844. {
  6845. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  6846. }
  6847. if (isset($restriction['attribs']['']['type']))
  6848. {
  6849. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6850. }
  6851. if (isset($restriction['data']))
  6852. {
  6853. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6854. }
  6855. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  6856. }
  6857. }
  6858. elseif ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  6859. {
  6860. foreach ($restrictions as $restriction)
  6861. {
  6862. $restriction_relationship = 'allow';
  6863. $restriction_type = null;
  6864. $restriction_value = 'itunes';
  6865. if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
  6866. {
  6867. $restriction_relationship = 'deny';
  6868. }
  6869. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  6870. }
  6871. }
  6872. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  6873. {
  6874. foreach ($restrictions as $restriction)
  6875. {
  6876. $restriction_relationship = null;
  6877. $restriction_type = null;
  6878. $restriction_value = null;
  6879. if (isset($restriction['attribs']['']['relationship']))
  6880. {
  6881. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  6882. }
  6883. if (isset($restriction['attribs']['']['type']))
  6884. {
  6885. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6886. }
  6887. if (isset($restriction['data']))
  6888. {
  6889. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6890. }
  6891. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  6892. }
  6893. }
  6894. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  6895. {
  6896. foreach ($restrictions as $restriction)
  6897. {
  6898. $restriction_relationship = 'allow';
  6899. $restriction_type = null;
  6900. $restriction_value = 'itunes';
  6901. if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
  6902. {
  6903. $restriction_relationship = 'deny';
  6904. }
  6905. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  6906. }
  6907. }
  6908. if (is_array($restrictions_parent))
  6909. {
  6910. $restrictions_parent = array_values(array_unique($restrictions_parent));
  6911. }
  6912. else
  6913. {
  6914. $restrictions_parent = array(new SimplePie_Restriction('allow', null, 'default'));
  6915. }
  6916. // THUMBNAILS
  6917. if ($thumbnails = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  6918. {
  6919. foreach ($thumbnails as $thumbnail)
  6920. {
  6921. if (isset($thumbnail['attribs']['']['url']))
  6922. {
  6923. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6924. }
  6925. }
  6926. }
  6927. elseif ($thumbnails = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  6928. {
  6929. foreach ($thumbnails as $thumbnail)
  6930. {
  6931. if (isset($thumbnail['attribs']['']['url']))
  6932. {
  6933. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6934. }
  6935. }
  6936. }
  6937. // TITLES
  6938. if ($title_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  6939. {
  6940. if (isset($title_parent[0]['data']))
  6941. {
  6942. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6943. }
  6944. }
  6945. elseif ($title_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  6946. {
  6947. if (isset($title_parent[0]['data']))
  6948. {
  6949. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6950. }
  6951. }
  6952. // Clear the memory
  6953. unset($parent);
  6954. // Attributes
  6955. $bitrate = null;
  6956. $channels = null;
  6957. $duration = null;
  6958. $expression = null;
  6959. $framerate = null;
  6960. $height = null;
  6961. $javascript = null;
  6962. $lang = null;
  6963. $length = null;
  6964. $medium = null;
  6965. $samplingrate = null;
  6966. $type = null;
  6967. $url = null;
  6968. $width = null;
  6969. // Elements
  6970. $captions = null;
  6971. $categories = null;
  6972. $copyrights = null;
  6973. $credits = null;
  6974. $description = null;
  6975. $hashes = null;
  6976. $keywords = null;
  6977. $player = null;
  6978. $ratings = null;
  6979. $restrictions = null;
  6980. $thumbnails = null;
  6981. $title = null;
  6982. // If we have media:group tags, loop through them.
  6983. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group') as $group)
  6984. {
  6985. if(isset($group['child']) && isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
  6986. {
  6987. // If we have media:content tags, loop through them.
  6988. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
  6989. {
  6990. if (isset($content['attribs']['']['url']))
  6991. {
  6992. // Attributes
  6993. $bitrate = null;
  6994. $channels = null;
  6995. $duration = null;
  6996. $expression = null;
  6997. $framerate = null;
  6998. $height = null;
  6999. $javascript = null;
  7000. $lang = null;
  7001. $length = null;
  7002. $medium = null;
  7003. $samplingrate = null;
  7004. $type = null;
  7005. $url = null;
  7006. $width = null;
  7007. // Elements
  7008. $captions = null;
  7009. $categories = null;
  7010. $copyrights = null;
  7011. $credits = null;
  7012. $description = null;
  7013. $hashes = null;
  7014. $keywords = null;
  7015. $player = null;
  7016. $ratings = null;
  7017. $restrictions = null;
  7018. $thumbnails = null;
  7019. $title = null;
  7020. // Start checking the attributes of media:content
  7021. if (isset($content['attribs']['']['bitrate']))
  7022. {
  7023. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  7024. }
  7025. if (isset($content['attribs']['']['channels']))
  7026. {
  7027. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  7028. }
  7029. if (isset($content['attribs']['']['duration']))
  7030. {
  7031. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  7032. }
  7033. else
  7034. {
  7035. $duration = $duration_parent;
  7036. }
  7037. if (isset($content['attribs']['']['expression']))
  7038. {
  7039. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  7040. }
  7041. if (isset($content['attribs']['']['framerate']))
  7042. {
  7043. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  7044. }
  7045. if (isset($content['attribs']['']['height']))
  7046. {
  7047. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  7048. }
  7049. if (isset($content['attribs']['']['lang']))
  7050. {
  7051. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  7052. }
  7053. if (isset($content['attribs']['']['fileSize']))
  7054. {
  7055. $length = ceil($content['attribs']['']['fileSize']);
  7056. }
  7057. if (isset($content['attribs']['']['medium']))
  7058. {
  7059. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  7060. }
  7061. if (isset($content['attribs']['']['samplingrate']))
  7062. {
  7063. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  7064. }
  7065. if (isset($content['attribs']['']['type']))
  7066. {
  7067. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7068. }
  7069. if (isset($content['attribs']['']['width']))
  7070. {
  7071. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  7072. }
  7073. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  7074. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  7075. // CAPTIONS
  7076. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  7077. {
  7078. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  7079. {
  7080. $caption_type = null;
  7081. $caption_lang = null;
  7082. $caption_startTime = null;
  7083. $caption_endTime = null;
  7084. $caption_text = null;
  7085. if (isset($caption['attribs']['']['type']))
  7086. {
  7087. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7088. }
  7089. if (isset($caption['attribs']['']['lang']))
  7090. {
  7091. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  7092. }
  7093. if (isset($caption['attribs']['']['start']))
  7094. {
  7095. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  7096. }
  7097. if (isset($caption['attribs']['']['end']))
  7098. {
  7099. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  7100. }
  7101. if (isset($caption['data']))
  7102. {
  7103. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7104. }
  7105. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  7106. }
  7107. if (is_array($captions))
  7108. {
  7109. $captions = array_values(array_unique($captions));
  7110. }
  7111. }
  7112. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  7113. {
  7114. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  7115. {
  7116. $caption_type = null;
  7117. $caption_lang = null;
  7118. $caption_startTime = null;
  7119. $caption_endTime = null;
  7120. $caption_text = null;
  7121. if (isset($caption['attribs']['']['type']))
  7122. {
  7123. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7124. }
  7125. if (isset($caption['attribs']['']['lang']))
  7126. {
  7127. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  7128. }
  7129. if (isset($caption['attribs']['']['start']))
  7130. {
  7131. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  7132. }
  7133. if (isset($caption['attribs']['']['end']))
  7134. {
  7135. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  7136. }
  7137. if (isset($caption['data']))
  7138. {
  7139. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7140. }
  7141. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  7142. }
  7143. if (is_array($captions))
  7144. {
  7145. $captions = array_values(array_unique($captions));
  7146. }
  7147. }
  7148. else
  7149. {
  7150. $captions = $captions_parent;
  7151. }
  7152. // CATEGORIES
  7153. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  7154. {
  7155. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  7156. {
  7157. $term = null;
  7158. $scheme = null;
  7159. $label = null;
  7160. if (isset($category['data']))
  7161. {
  7162. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7163. }
  7164. if (isset($category['attribs']['']['scheme']))
  7165. {
  7166. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7167. }
  7168. else
  7169. {
  7170. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  7171. }
  7172. if (isset($category['attribs']['']['label']))
  7173. {
  7174. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  7175. }
  7176. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  7177. }
  7178. }
  7179. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  7180. {
  7181. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  7182. {
  7183. $term = null;
  7184. $scheme = null;
  7185. $label = null;
  7186. if (isset($category['data']))
  7187. {
  7188. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7189. }
  7190. if (isset($category['attribs']['']['scheme']))
  7191. {
  7192. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7193. }
  7194. else
  7195. {
  7196. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  7197. }
  7198. if (isset($category['attribs']['']['label']))
  7199. {
  7200. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  7201. }
  7202. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  7203. }
  7204. }
  7205. if (is_array($categories) && is_array($categories_parent))
  7206. {
  7207. $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
  7208. }
  7209. elseif (is_array($categories))
  7210. {
  7211. $categories = array_values(array_unique($categories));
  7212. }
  7213. elseif (is_array($categories_parent))
  7214. {
  7215. $categories = array_values(array_unique($categories_parent));
  7216. }
  7217. // COPYRIGHTS
  7218. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  7219. {
  7220. $copyright_url = null;
  7221. $copyright_label = null;
  7222. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  7223. {
  7224. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  7225. }
  7226. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  7227. {
  7228. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7229. }
  7230. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  7231. }
  7232. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  7233. {
  7234. $copyright_url = null;
  7235. $copyright_label = null;
  7236. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  7237. {
  7238. $copyright_url = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  7239. }
  7240. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  7241. {
  7242. $copyright_label = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7243. }
  7244. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  7245. }
  7246. else
  7247. {
  7248. $copyrights = $copyrights_parent;
  7249. }
  7250. // CREDITS
  7251. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  7252. {
  7253. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  7254. {
  7255. $credit_role = null;
  7256. $credit_scheme = null;
  7257. $credit_name = null;
  7258. if (isset($credit['attribs']['']['role']))
  7259. {
  7260. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  7261. }
  7262. if (isset($credit['attribs']['']['scheme']))
  7263. {
  7264. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7265. }
  7266. else
  7267. {
  7268. $credit_scheme = 'urn:ebu';
  7269. }
  7270. if (isset($credit['data']))
  7271. {
  7272. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7273. }
  7274. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  7275. }
  7276. if (is_array($credits))
  7277. {
  7278. $credits = array_values(array_unique($credits));
  7279. }
  7280. }
  7281. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  7282. {
  7283. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  7284. {
  7285. $credit_role = null;
  7286. $credit_scheme = null;
  7287. $credit_name = null;
  7288. if (isset($credit['attribs']['']['role']))
  7289. {
  7290. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  7291. }
  7292. if (isset($credit['attribs']['']['scheme']))
  7293. {
  7294. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7295. }
  7296. else
  7297. {
  7298. $credit_scheme = 'urn:ebu';
  7299. }
  7300. if (isset($credit['data']))
  7301. {
  7302. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7303. }
  7304. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  7305. }
  7306. if (is_array($credits))
  7307. {
  7308. $credits = array_values(array_unique($credits));
  7309. }
  7310. }
  7311. else
  7312. {
  7313. $credits = $credits_parent;
  7314. }
  7315. // DESCRIPTION
  7316. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  7317. {
  7318. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7319. }
  7320. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  7321. {
  7322. $description = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7323. }
  7324. else
  7325. {
  7326. $description = $description_parent;
  7327. }
  7328. // HASHES
  7329. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  7330. {
  7331. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  7332. {
  7333. $value = null;
  7334. $algo = null;
  7335. if (isset($hash['data']))
  7336. {
  7337. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7338. }
  7339. if (isset($hash['attribs']['']['algo']))
  7340. {
  7341. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  7342. }
  7343. else
  7344. {
  7345. $algo = 'md5';
  7346. }
  7347. $hashes[] = $algo.':'.$value;
  7348. }
  7349. if (is_array($hashes))
  7350. {
  7351. $hashes = array_values(array_unique($hashes));
  7352. }
  7353. }
  7354. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  7355. {
  7356. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  7357. {
  7358. $value = null;
  7359. $algo = null;
  7360. if (isset($hash['data']))
  7361. {
  7362. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7363. }
  7364. if (isset($hash['attribs']['']['algo']))
  7365. {
  7366. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  7367. }
  7368. else
  7369. {
  7370. $algo = 'md5';
  7371. }
  7372. $hashes[] = $algo.':'.$value;
  7373. }
  7374. if (is_array($hashes))
  7375. {
  7376. $hashes = array_values(array_unique($hashes));
  7377. }
  7378. }
  7379. else
  7380. {
  7381. $hashes = $hashes_parent;
  7382. }
  7383. // KEYWORDS
  7384. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  7385. {
  7386. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  7387. {
  7388. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  7389. foreach ($temp as $word)
  7390. {
  7391. $keywords[] = trim($word);
  7392. }
  7393. unset($temp);
  7394. }
  7395. if (is_array($keywords))
  7396. {
  7397. $keywords = array_values(array_unique($keywords));
  7398. }
  7399. }
  7400. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  7401. {
  7402. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  7403. {
  7404. $temp = explode(',', $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  7405. foreach ($temp as $word)
  7406. {
  7407. $keywords[] = trim($word);
  7408. }
  7409. unset($temp);
  7410. }
  7411. if (is_array($keywords))
  7412. {
  7413. $keywords = array_values(array_unique($keywords));
  7414. }
  7415. }
  7416. else
  7417. {
  7418. $keywords = $keywords_parent;
  7419. }
  7420. // PLAYER
  7421. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  7422. {
  7423. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  7424. }
  7425. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  7426. {
  7427. $player = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  7428. }
  7429. else
  7430. {
  7431. $player = $player_parent;
  7432. }
  7433. // RATINGS
  7434. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  7435. {
  7436. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  7437. {
  7438. $rating_scheme = null;
  7439. $rating_value = null;
  7440. if (isset($rating['attribs']['']['scheme']))
  7441. {
  7442. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7443. }
  7444. else
  7445. {
  7446. $rating_scheme = 'urn:simple';
  7447. }
  7448. if (isset($rating['data']))
  7449. {
  7450. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7451. }
  7452. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  7453. }
  7454. if (is_array($ratings))
  7455. {
  7456. $ratings = array_values(array_unique($ratings));
  7457. }
  7458. }
  7459. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  7460. {
  7461. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  7462. {
  7463. $rating_scheme = null;
  7464. $rating_value = null;
  7465. if (isset($rating['attribs']['']['scheme']))
  7466. {
  7467. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7468. }
  7469. else
  7470. {
  7471. $rating_scheme = 'urn:simple';
  7472. }
  7473. if (isset($rating['data']))
  7474. {
  7475. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7476. }
  7477. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  7478. }
  7479. if (is_array($ratings))
  7480. {
  7481. $ratings = array_values(array_unique($ratings));
  7482. }
  7483. }
  7484. else
  7485. {
  7486. $ratings = $ratings_parent;
  7487. }
  7488. // RESTRICTIONS
  7489. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  7490. {
  7491. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  7492. {
  7493. $restriction_relationship = null;
  7494. $restriction_type = null;
  7495. $restriction_value = null;
  7496. if (isset($restriction['attribs']['']['relationship']))
  7497. {
  7498. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  7499. }
  7500. if (isset($restriction['attribs']['']['type']))
  7501. {
  7502. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7503. }
  7504. if (isset($restriction['data']))
  7505. {
  7506. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7507. }
  7508. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  7509. }
  7510. if (is_array($restrictions))
  7511. {
  7512. $restrictions = array_values(array_unique($restrictions));
  7513. }
  7514. }
  7515. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  7516. {
  7517. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  7518. {
  7519. $restriction_relationship = null;
  7520. $restriction_type = null;
  7521. $restriction_value = null;
  7522. if (isset($restriction['attribs']['']['relationship']))
  7523. {
  7524. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  7525. }
  7526. if (isset($restriction['attribs']['']['type']))
  7527. {
  7528. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7529. }
  7530. if (isset($restriction['data']))
  7531. {
  7532. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7533. }
  7534. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  7535. }
  7536. if (is_array($restrictions))
  7537. {
  7538. $restrictions = array_values(array_unique($restrictions));
  7539. }
  7540. }
  7541. else
  7542. {
  7543. $restrictions = $restrictions_parent;
  7544. }
  7545. // THUMBNAILS
  7546. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  7547. {
  7548. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  7549. {
  7550. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  7551. }
  7552. if (is_array($thumbnails))
  7553. {
  7554. $thumbnails = array_values(array_unique($thumbnails));
  7555. }
  7556. }
  7557. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  7558. {
  7559. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  7560. {
  7561. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  7562. }
  7563. if (is_array($thumbnails))
  7564. {
  7565. $thumbnails = array_values(array_unique($thumbnails));
  7566. }
  7567. }
  7568. else
  7569. {
  7570. $thumbnails = $thumbnails_parent;
  7571. }
  7572. // TITLES
  7573. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  7574. {
  7575. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7576. }
  7577. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  7578. {
  7579. $title = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7580. }
  7581. else
  7582. {
  7583. $title = $title_parent;
  7584. }
  7585. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width));
  7586. }
  7587. }
  7588. }
  7589. }
  7590. // If we have standalone media:content tags, loop through them.
  7591. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
  7592. {
  7593. foreach ((array) $this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
  7594. {
  7595. if (isset($content['attribs']['']['url']) || isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  7596. {
  7597. // Attributes
  7598. $bitrate = null;
  7599. $channels = null;
  7600. $duration = null;
  7601. $expression = null;
  7602. $framerate = null;
  7603. $height = null;
  7604. $javascript = null;
  7605. $lang = null;
  7606. $length = null;
  7607. $medium = null;
  7608. $samplingrate = null;
  7609. $type = null;
  7610. $url = null;
  7611. $width = null;
  7612. // Elements
  7613. $captions = null;
  7614. $categories = null;
  7615. $copyrights = null;
  7616. $credits = null;
  7617. $description = null;
  7618. $hashes = null;
  7619. $keywords = null;
  7620. $player = null;
  7621. $ratings = null;
  7622. $restrictions = null;
  7623. $thumbnails = null;
  7624. $title = null;
  7625. // Start checking the attributes of media:content
  7626. if (isset($content['attribs']['']['bitrate']))
  7627. {
  7628. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  7629. }
  7630. if (isset($content['attribs']['']['channels']))
  7631. {
  7632. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  7633. }
  7634. if (isset($content['attribs']['']['duration']))
  7635. {
  7636. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  7637. }
  7638. else
  7639. {
  7640. $duration = $duration_parent;
  7641. }
  7642. if (isset($content['attribs']['']['expression']))
  7643. {
  7644. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  7645. }
  7646. if (isset($content['attribs']['']['framerate']))
  7647. {
  7648. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  7649. }
  7650. if (isset($content['attribs']['']['height']))
  7651. {
  7652. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  7653. }
  7654. if (isset($content['attribs']['']['lang']))
  7655. {
  7656. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  7657. }
  7658. if (isset($content['attribs']['']['fileSize']))
  7659. {
  7660. $length = ceil($content['attribs']['']['fileSize']);
  7661. }
  7662. if (isset($content['attribs']['']['medium']))
  7663. {
  7664. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  7665. }
  7666. if (isset($content['attribs']['']['samplingrate']))
  7667. {
  7668. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  7669. }
  7670. if (isset($content['attribs']['']['type']))
  7671. {
  7672. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7673. }
  7674. if (isset($content['attribs']['']['width']))
  7675. {
  7676. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  7677. }
  7678. if (isset($content['attribs']['']['url']))
  7679. {
  7680. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  7681. }
  7682. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  7683. // CAPTIONS
  7684. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  7685. {
  7686. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  7687. {
  7688. $caption_type = null;
  7689. $caption_lang = null;
  7690. $caption_startTime = null;
  7691. $caption_endTime = null;
  7692. $caption_text = null;
  7693. if (isset($caption['attribs']['']['type']))
  7694. {
  7695. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7696. }
  7697. if (isset($caption['attribs']['']['lang']))
  7698. {
  7699. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  7700. }
  7701. if (isset($caption['attribs']['']['start']))
  7702. {
  7703. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  7704. }
  7705. if (isset($caption['attribs']['']['end']))
  7706. {
  7707. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  7708. }
  7709. if (isset($caption['data']))
  7710. {
  7711. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7712. }
  7713. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  7714. }
  7715. if (is_array($captions))
  7716. {
  7717. $captions = array_values(array_unique($captions));
  7718. }
  7719. }
  7720. else
  7721. {
  7722. $captions = $captions_parent;
  7723. }
  7724. // CATEGORIES
  7725. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  7726. {
  7727. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  7728. {
  7729. $term = null;
  7730. $scheme = null;
  7731. $label = null;
  7732. if (isset($category['data']))
  7733. {
  7734. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7735. }
  7736. if (isset($category['attribs']['']['scheme']))
  7737. {
  7738. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7739. }
  7740. else
  7741. {
  7742. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  7743. }
  7744. if (isset($category['attribs']['']['label']))
  7745. {
  7746. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  7747. }
  7748. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  7749. }
  7750. }
  7751. if (is_array($categories) && is_array($categories_parent))
  7752. {
  7753. $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
  7754. }
  7755. elseif (is_array($categories))
  7756. {
  7757. $categories = array_values(array_unique($categories));
  7758. }
  7759. elseif (is_array($categories_parent))
  7760. {
  7761. $categories = array_values(array_unique($categories_parent));
  7762. }
  7763. else
  7764. {
  7765. $categories = null;
  7766. }
  7767. // COPYRIGHTS
  7768. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  7769. {
  7770. $copyright_url = null;
  7771. $copyright_label = null;
  7772. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  7773. {
  7774. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  7775. }
  7776. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  7777. {
  7778. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7779. }
  7780. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  7781. }
  7782. else
  7783. {
  7784. $copyrights = $copyrights_parent;
  7785. }
  7786. // CREDITS
  7787. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  7788. {
  7789. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  7790. {
  7791. $credit_role = null;
  7792. $credit_scheme = null;
  7793. $credit_name = null;
  7794. if (isset($credit['attribs']['']['role']))
  7795. {
  7796. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  7797. }
  7798. if (isset($credit['attribs']['']['scheme']))
  7799. {
  7800. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7801. }
  7802. else
  7803. {
  7804. $credit_scheme = 'urn:ebu';
  7805. }
  7806. if (isset($credit['data']))
  7807. {
  7808. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7809. }
  7810. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  7811. }
  7812. if (is_array($credits))
  7813. {
  7814. $credits = array_values(array_unique($credits));
  7815. }
  7816. }
  7817. else
  7818. {
  7819. $credits = $credits_parent;
  7820. }
  7821. // DESCRIPTION
  7822. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  7823. {
  7824. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7825. }
  7826. else
  7827. {
  7828. $description = $description_parent;
  7829. }
  7830. // HASHES
  7831. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  7832. {
  7833. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  7834. {
  7835. $value = null;
  7836. $algo = null;
  7837. if (isset($hash['data']))
  7838. {
  7839. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7840. }
  7841. if (isset($hash['attribs']['']['algo']))
  7842. {
  7843. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  7844. }
  7845. else
  7846. {
  7847. $algo = 'md5';
  7848. }
  7849. $hashes[] = $algo.':'.$value;
  7850. }
  7851. if (is_array($hashes))
  7852. {
  7853. $hashes = array_values(array_unique($hashes));
  7854. }
  7855. }
  7856. else
  7857. {
  7858. $hashes = $hashes_parent;
  7859. }
  7860. // KEYWORDS
  7861. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  7862. {
  7863. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  7864. {
  7865. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  7866. foreach ($temp as $word)
  7867. {
  7868. $keywords[] = trim($word);
  7869. }
  7870. unset($temp);
  7871. }
  7872. if (is_array($keywords))
  7873. {
  7874. $keywords = array_values(array_unique($keywords));
  7875. }
  7876. }
  7877. else
  7878. {
  7879. $keywords = $keywords_parent;
  7880. }
  7881. // PLAYER
  7882. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  7883. {
  7884. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  7885. }
  7886. else
  7887. {
  7888. $player = $player_parent;
  7889. }
  7890. // RATINGS
  7891. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  7892. {
  7893. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  7894. {
  7895. $rating_scheme = null;
  7896. $rating_value = null;
  7897. if (isset($rating['attribs']['']['scheme']))
  7898. {
  7899. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7900. }
  7901. else
  7902. {
  7903. $rating_scheme = 'urn:simple';
  7904. }
  7905. if (isset($rating['data']))
  7906. {
  7907. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7908. }
  7909. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  7910. }
  7911. if (is_array($ratings))
  7912. {
  7913. $ratings = array_values(array_unique($ratings));
  7914. }
  7915. }
  7916. else
  7917. {
  7918. $ratings = $ratings_parent;
  7919. }
  7920. // RESTRICTIONS
  7921. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  7922. {
  7923. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  7924. {
  7925. $restriction_relationship = null;
  7926. $restriction_type = null;
  7927. $restriction_value = null;
  7928. if (isset($restriction['attribs']['']['relationship']))
  7929. {
  7930. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  7931. }
  7932. if (isset($restriction['attribs']['']['type']))
  7933. {
  7934. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7935. }
  7936. if (isset($restriction['data']))
  7937. {
  7938. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7939. }
  7940. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  7941. }
  7942. if (is_array($restrictions))
  7943. {
  7944. $restrictions = array_values(array_unique($restrictions));
  7945. }
  7946. }
  7947. else
  7948. {
  7949. $restrictions = $restrictions_parent;
  7950. }
  7951. // THUMBNAILS
  7952. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  7953. {
  7954. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  7955. {
  7956. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  7957. }
  7958. if (is_array($thumbnails))
  7959. {
  7960. $thumbnails = array_values(array_unique($thumbnails));
  7961. }
  7962. }
  7963. else
  7964. {
  7965. $thumbnails = $thumbnails_parent;
  7966. }
  7967. // TITLES
  7968. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  7969. {
  7970. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7971. }
  7972. else
  7973. {
  7974. $title = $title_parent;
  7975. }
  7976. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width));
  7977. }
  7978. }
  7979. }
  7980. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  7981. {
  7982. if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure')
  7983. {
  7984. // Attributes
  7985. $bitrate = null;
  7986. $channels = null;
  7987. $duration = null;
  7988. $expression = null;
  7989. $framerate = null;
  7990. $height = null;
  7991. $javascript = null;
  7992. $lang = null;
  7993. $length = null;
  7994. $medium = null;
  7995. $samplingrate = null;
  7996. $type = null;
  7997. $url = null;
  7998. $width = null;
  7999. $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  8000. if (isset($link['attribs']['']['type']))
  8001. {
  8002. $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  8003. }
  8004. if (isset($link['attribs']['']['length']))
  8005. {
  8006. $length = ceil($link['attribs']['']['length']);
  8007. }
  8008. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  8009. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width));
  8010. }
  8011. }
  8012. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
  8013. {
  8014. if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure')
  8015. {
  8016. // Attributes
  8017. $bitrate = null;
  8018. $channels = null;
  8019. $duration = null;
  8020. $expression = null;
  8021. $framerate = null;
  8022. $height = null;
  8023. $javascript = null;
  8024. $lang = null;
  8025. $length = null;
  8026. $medium = null;
  8027. $samplingrate = null;
  8028. $type = null;
  8029. $url = null;
  8030. $width = null;
  8031. $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  8032. if (isset($link['attribs']['']['type']))
  8033. {
  8034. $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  8035. }
  8036. if (isset($link['attribs']['']['length']))
  8037. {
  8038. $length = ceil($link['attribs']['']['length']);
  8039. }
  8040. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  8041. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width));
  8042. }
  8043. }
  8044. if ($enclosure = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'enclosure'))
  8045. {
  8046. if (isset($enclosure[0]['attribs']['']['url']))
  8047. {
  8048. // Attributes
  8049. $bitrate = null;
  8050. $channels = null;
  8051. $duration = null;
  8052. $expression = null;
  8053. $framerate = null;
  8054. $height = null;
  8055. $javascript = null;
  8056. $lang = null;
  8057. $length = null;
  8058. $medium = null;
  8059. $samplingrate = null;
  8060. $type = null;
  8061. $url = null;
  8062. $width = null;
  8063. $url = $this->sanitize($enclosure[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($enclosure[0]));
  8064. if (isset($enclosure[0]['attribs']['']['type']))
  8065. {
  8066. $type = $this->sanitize($enclosure[0]['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  8067. }
  8068. if (isset($enclosure[0]['attribs']['']['length']))
  8069. {
  8070. $length = ceil($enclosure[0]['attribs']['']['length']);
  8071. }
  8072. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  8073. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width));
  8074. }
  8075. }
  8076. if (sizeof($this->data['enclosures']) === 0 && ($url || $type || $length || $bitrate || $captions_parent || $categories_parent || $channels || $copyrights_parent || $credits_parent || $description_parent || $duration_parent || $expression || $framerate || $hashes_parent || $height || $keywords_parent || $lang || $medium || $player_parent || $ratings_parent || $restrictions_parent || $samplingrate || $thumbnails_parent || $title_parent || $width))
  8077. {
  8078. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  8079. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width));
  8080. }
  8081. $this->data['enclosures'] = array_values(array_unique($this->data['enclosures']));
  8082. }
  8083. if (!empty($this->data['enclosures']))
  8084. {
  8085. return $this->data['enclosures'];
  8086. }
  8087. else
  8088. {
  8089. return null;
  8090. }
  8091. }
  8092. public function get_latitude()
  8093. {
  8094. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  8095. {
  8096. return (float) $return[0]['data'];
  8097. }
  8098. elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  8099. {
  8100. return (float) $match[1];
  8101. }
  8102. else
  8103. {
  8104. return null;
  8105. }
  8106. }
  8107. public function get_longitude()
  8108. {
  8109. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  8110. {
  8111. return (float) $return[0]['data'];
  8112. }
  8113. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  8114. {
  8115. return (float) $return[0]['data'];
  8116. }
  8117. elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  8118. {
  8119. return (float) $match[2];
  8120. }
  8121. else
  8122. {
  8123. return null;
  8124. }
  8125. }
  8126. public function get_source()
  8127. {
  8128. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'source'))
  8129. {
  8130. return $this->registry->create('Source', array($this, $return[0]));
  8131. }
  8132. else
  8133. {
  8134. return null;
  8135. }
  8136. }
  8137. }
  8138. class SimplePie_Locator
  8139. {
  8140. var $useragent;
  8141. var $timeout;
  8142. var $file;
  8143. var $local = array();
  8144. var $elsewhere = array();
  8145. var $cached_entities = array();
  8146. var $http_base;
  8147. var $base;
  8148. var $base_location = 0;
  8149. var $checked_feeds = 0;
  8150. var $max_checked_feeds = 10;
  8151. protected $registry;
  8152. public function __construct(SimplePie_File $file, $timeout = 10, $useragent = null, $max_checked_feeds = 10)
  8153. {
  8154. $this->file = $file;
  8155. $this->useragent = $useragent;
  8156. $this->timeout = $timeout;
  8157. $this->max_checked_feeds = $max_checked_feeds;
  8158. $this->dom = new DOMDocument();
  8159. set_error_handler(array('SimplePie_Misc', 'silence_errors'));
  8160. $this->dom->loadHTML($this->file->body);
  8161. restore_error_handler();
  8162. }
  8163. public function set_registry(SimplePie_Registry $registry)
  8164. {
  8165. $this->registry = $registry;
  8166. }
  8167. public function find($type = SIMPLEPIE_LOCATOR_ALL, &$working)
  8168. {
  8169. if ($this->is_feed($this->file))
  8170. {
  8171. return $this->file;
  8172. }
  8173. if ($this->file->method & SIMPLEPIE_FILE_SOURCE_REMOTE)
  8174. {
  8175. $sniffer = $this->registry->create('Content_Type_Sniffer', array($this->file));
  8176. if ($sniffer->get_type() !== 'text/html')
  8177. {
  8178. return null;
  8179. }
  8180. }
  8181. if ($type & ~SIMPLEPIE_LOCATOR_NONE)
  8182. {
  8183. $this->get_base();
  8184. }
  8185. if ($type & SIMPLEPIE_LOCATOR_AUTODISCOVERY && $working = $this->autodiscovery())
  8186. {
  8187. return $working[0];
  8188. }
  8189. if ($type & (SIMPLEPIE_LOCATOR_LOCAL_EXTENSION | SIMPLEPIE_LOCATOR_LOCAL_BODY | SIMPLEPIE_LOCATOR_REMOTE_EXTENSION | SIMPLEPIE_LOCATOR_REMOTE_BODY) && $this->get_links())
  8190. {
  8191. if ($type & SIMPLEPIE_LOCATOR_LOCAL_EXTENSION && $working = $this->extension($this->local))
  8192. {
  8193. return $working;
  8194. }
  8195. if ($type & SIMPLEPIE_LOCATOR_LOCAL_BODY && $working = $this->body($this->local))
  8196. {
  8197. return $working;
  8198. }
  8199. if ($type & SIMPLEPIE_LOCATOR_REMOTE_EXTENSION && $working = $this->extension($this->elsewhere))
  8200. {
  8201. return $working;
  8202. }
  8203. if ($type & SIMPLEPIE_LOCATOR_REMOTE_BODY && $working = $this->body($this->elsewhere))
  8204. {
  8205. return $working;
  8206. }
  8207. }
  8208. return null;
  8209. }
  8210. public function is_feed($file)
  8211. {
  8212. if ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE)
  8213. {
  8214. $sniffer = $this->registry->create('Content_Type_Sniffer', array($file));
  8215. $sniffed = $sniffer->get_type();
  8216. if (in_array($sniffed, array('application/rss+xml', 'application/rdf+xml', 'text/rdf', 'application/atom+xml', 'text/xml', 'application/xml')))
  8217. {
  8218. return true;
  8219. }
  8220. else
  8221. {
  8222. return false;
  8223. }
  8224. }
  8225. elseif ($file->method & SIMPLEPIE_FILE_SOURCE_LOCAL)
  8226. {
  8227. return true;
  8228. }
  8229. else
  8230. {
  8231. return false;
  8232. }
  8233. }
  8234. public function get_base()
  8235. {
  8236. $this->http_base = $this->file->url;
  8237. $this->base = $this->http_base;
  8238. $elements = $this->dom->getElementsByTagName('base');
  8239. foreach ($elements as $element)
  8240. {
  8241. if ($element->hasAttribute('href'))
  8242. {
  8243. $this->base = $this->registry->call('Misc', 'absolutize_url', array(trim($element->getAttribute('href')), $this->http_base));
  8244. $this->base_location = method_exists($element, 'getLineNo') ? $element->getLineNo() : 0;
  8245. break;
  8246. }
  8247. }
  8248. }
  8249. public function autodiscovery()
  8250. {
  8251. $done = array();
  8252. $feeds = array();
  8253. $feeds = array_merge($feeds, $this->search_elements_by_tag('link', $done, $feeds));
  8254. $feeds = array_merge($feeds, $this->search_elements_by_tag('a', $done, $feeds));
  8255. $feeds = array_merge($feeds, $this->search_elements_by_tag('area', $done, $feeds));
  8256. if (!empty($feeds))
  8257. {
  8258. return array_values($feeds);
  8259. }
  8260. else
  8261. {
  8262. return null;
  8263. }
  8264. }
  8265. protected function search_elements_by_tag($name, &$done, $feeds)
  8266. {
  8267. $links = $this->dom->getElementsByTagName($name);
  8268. foreach ($links as $link)
  8269. {
  8270. if ($this->checked_feeds === $this->max_checked_feeds)
  8271. {
  8272. break;
  8273. }
  8274. if ($link->hasAttribute('href') && $link->hasAttribute('rel'))
  8275. {
  8276. $rel = array_unique($this->registry->call('Misc', 'space_seperated_tokens', array(strtolower($link->getAttribute('rel')))));
  8277. $line = method_exists($link, 'getLineNo') ? $link->getLineNo() : 1;
  8278. if ($this->base_location < $line)
  8279. {
  8280. $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->base));
  8281. }
  8282. else
  8283. {
  8284. $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->http_base));
  8285. }
  8286. if (!in_array($href, $done) && in_array('feed', $rel) || (in_array('alternate', $rel) && !in_array('stylesheet', $rel) && $link->hasAttribute('type') && in_array(strtolower($this->registry->call('Misc', 'parse_mime', array($link->getAttribute('type')))), array('application/rss+xml', 'application/atom+xml'))) && !isset($feeds[$href]))
  8287. {
  8288. $this->checked_feeds++;
  8289. $headers = array(
  8290. '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',
  8291. );
  8292. $feed = $this->registry->create('File', array($href, $this->timeout, 5, $headers, $this->useragent));
  8293. if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed))
  8294. {
  8295. $feeds[$href] = $feed;
  8296. }
  8297. }
  8298. $done[] = $href;
  8299. }
  8300. }
  8301. return $feeds;
  8302. }
  8303. public function get_links()
  8304. {
  8305. $links = $this->dom->getElementsByTagName('a');
  8306. foreach ($links as $link)
  8307. {
  8308. if ($link->hasAttribute('href'))
  8309. {
  8310. $href = trim($link->getAttribute('href'));
  8311. $parsed = $this->registry->call('Misc', 'parse_url', array($href));
  8312. if ($parsed['scheme'] === '' || preg_match('/^(http(s)|feed)?$/i', $parsed['scheme']))
  8313. {
  8314. if ($this->base_location < $link->getLineNo())
  8315. {
  8316. $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->base));
  8317. }
  8318. else
  8319. {
  8320. $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->http_base));
  8321. }
  8322. $current = $this->registry->call('Misc', 'parse_url', array($this->file->url));
  8323. if ($parsed['authority'] === '' || $parsed['authority'] === $current['authority'])
  8324. {
  8325. $this->local[] = $href;
  8326. }
  8327. else
  8328. {
  8329. $this->elsewhere[] = $href;
  8330. }
  8331. }
  8332. }
  8333. }
  8334. $this->local = array_unique($this->local);
  8335. $this->elsewhere = array_unique($this->elsewhere);
  8336. if (!empty($this->local) || !empty($this->elsewhere))
  8337. {
  8338. return true;
  8339. }
  8340. return null;
  8341. }
  8342. public function extension(&$array)
  8343. {
  8344. foreach ($array as $key => $value)
  8345. {
  8346. if ($this->checked_feeds === $this->max_checked_feeds)
  8347. {
  8348. break;
  8349. }
  8350. if (in_array(strtolower(strrchr($value, '.')), array('.rss', '.rdf', '.atom', '.xml')))
  8351. {
  8352. $this->checked_feeds++;
  8353. $headers = array(
  8354. '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',
  8355. );
  8356. $feed = $this->registry->create('File', array($value, $this->timeout, 5, $headers, $this->useragent));
  8357. if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed))
  8358. {
  8359. return $feed;
  8360. }
  8361. else
  8362. {
  8363. unset($array[$key]);
  8364. }
  8365. }
  8366. }
  8367. return null;
  8368. }
  8369. public function body(&$array)
  8370. {
  8371. foreach ($array as $key => $value)
  8372. {
  8373. if ($this->checked_feeds === $this->max_checked_feeds)
  8374. {
  8375. break;
  8376. }
  8377. if (preg_match('/(rss|rdf|atom|xml)/i', $value))
  8378. {
  8379. $this->checked_feeds++;
  8380. $headers = array(
  8381. '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',
  8382. );
  8383. $feed = $this->registry->create('File', array($value, $this->timeout, 5, null, $this->useragent));
  8384. if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed))
  8385. {
  8386. return $feed;
  8387. }
  8388. else
  8389. {
  8390. unset($array[$key]);
  8391. }
  8392. }
  8393. }
  8394. return null;
  8395. }
  8396. }
  8397. class SimplePie_Misc
  8398. {
  8399. public static function time_hms($seconds)
  8400. {
  8401. $time = '';
  8402. $hours = floor($seconds / 3600);
  8403. $remainder = $seconds % 3600;
  8404. if ($hours > 0)
  8405. {
  8406. $time .= $hours.':';
  8407. }
  8408. $minutes = floor($remainder / 60);
  8409. $seconds = $remainder % 60;
  8410. if ($minutes < 10 && $hours > 0)
  8411. {
  8412. $minutes = '0' . $minutes;
  8413. }
  8414. if ($seconds < 10)
  8415. {
  8416. $seconds = '0' . $seconds;
  8417. }
  8418. $time .= $minutes.':';
  8419. $time .= $seconds;
  8420. return $time;
  8421. }
  8422. public static function absolutize_url($relative, $base)
  8423. {
  8424. $iri = SimplePie_IRI::absolutize(new SimplePie_IRI($base), $relative);
  8425. return $iri->get_uri();
  8426. }
  8427. public static function get_element($realname, $string)
  8428. {
  8429. $return = array();
  8430. $name = preg_quote($realname, '/');
  8431. if (preg_match_all("/<($name)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$name>|(\/)?>)/siU", $string, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE))
  8432. {
  8433. for ($i = 0, $total_matches = count($matches); $i < $total_matches; $i++)
  8434. {
  8435. $return[$i]['tag'] = $realname;
  8436. $return[$i]['full'] = $matches[$i][0][0];
  8437. $return[$i]['offset'] = $matches[$i][0][1];
  8438. if (strlen($matches[$i][3][0]) <= 2)
  8439. {
  8440. $return[$i]['self_closing'] = true;
  8441. }
  8442. else
  8443. {
  8444. $return[$i]['self_closing'] = false;
  8445. $return[$i]['content'] = $matches[$i][4][0];
  8446. }
  8447. $return[$i]['attribs'] = array();
  8448. if (isset($matches[$i][2][0]) && preg_match_all('/[\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]*)?))?/', ' ' . $matches[$i][2][0] . ' ', $attribs, PREG_SET_ORDER))
  8449. {
  8450. for ($j = 0, $total_attribs = count($attribs); $j < $total_attribs; $j++)
  8451. {
  8452. if (count($attribs[$j]) === 2)
  8453. {
  8454. $attribs[$j][2] = $attribs[$j][1];
  8455. }
  8456. $return[$i]['attribs'][strtolower($attribs[$j][1])]['data'] = SimplePie_Misc::entities_decode(end($attribs[$j]), 'UTF-8');
  8457. }
  8458. }
  8459. }
  8460. }
  8461. return $return;
  8462. }
  8463. public static function element_implode($element)
  8464. {
  8465. $full = "<$element[tag]";
  8466. foreach ($element['attribs'] as $key => $value)
  8467. {
  8468. $key = strtolower($key);
  8469. $full .= " $key=\"" . htmlspecialchars($value['data']) . '"';
  8470. }
  8471. if ($element['self_closing'])
  8472. {
  8473. $full .= ' />';
  8474. }
  8475. else
  8476. {
  8477. $full .= ">$element[content]</$element[tag]>";
  8478. }
  8479. return $full;
  8480. }
  8481. public static function error($message, $level, $file, $line)
  8482. {
  8483. if ((ini_get('error_reporting') & $level) > 0)
  8484. {
  8485. switch ($level)
  8486. {
  8487. case E_USER_ERROR:
  8488. $note = 'PHP Error';
  8489. break;
  8490. case E_USER_WARNING:
  8491. $note = 'PHP Warning';
  8492. break;
  8493. case E_USER_NOTICE:
  8494. $note = 'PHP Notice';
  8495. break;
  8496. default:
  8497. $note = 'Unknown Error';
  8498. break;
  8499. }
  8500. $log_error = true;
  8501. if (!function_exists('error_log'))
  8502. {
  8503. $log_error = false;
  8504. }
  8505. $log_file = @ini_get('error_log');
  8506. if (!empty($log_file) && ('syslog' !== $log_file) && !@is_writable($log_file))
  8507. {
  8508. $log_error = false;
  8509. }
  8510. if ($log_error)
  8511. {
  8512. @error_log("$note: $message in $file on line $line", 0);
  8513. }
  8514. }
  8515. return $message;
  8516. }
  8517. public static function fix_protocol($url, $http = 1)
  8518. {
  8519. $url = SimplePie_Misc::normalize_url($url);
  8520. $parsed = SimplePie_Misc::parse_url($url);
  8521. if ($parsed['scheme'] !== '' && $parsed['scheme'] !== 'http' && $parsed['scheme'] !== 'https')
  8522. {
  8523. return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['authority'], $parsed['path'], $parsed['query'], $parsed['fragment']), $http);
  8524. }
  8525. if ($parsed['scheme'] === '' && $parsed['authority'] === '' && !file_exists($url))
  8526. {
  8527. return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['path'], '', $parsed['query'], $parsed['fragment']), $http);
  8528. }
  8529. if ($http === 2 && $parsed['scheme'] !== '')
  8530. {
  8531. return "feed:$url";
  8532. }
  8533. elseif ($http === 3 && strtolower($parsed['scheme']) === 'http')
  8534. {
  8535. return substr_replace($url, 'podcast', 0, 4);
  8536. }
  8537. elseif ($http === 4 && strtolower($parsed['scheme']) === 'http')
  8538. {
  8539. return substr_replace($url, 'itpc', 0, 4);
  8540. }
  8541. else
  8542. {
  8543. return $url;
  8544. }
  8545. }
  8546. public static function parse_url($url)
  8547. {
  8548. $iri = new SimplePie_IRI($url);
  8549. return array(
  8550. 'scheme' => (string) $iri->scheme,
  8551. 'authority' => (string) $iri->authority,
  8552. 'path' => (string) $iri->path,
  8553. 'query' => (string) $iri->query,
  8554. 'fragment' => (string) $iri->fragment
  8555. );
  8556. }
  8557. public static function compress_parse_url($scheme = '', $authority = '', $path = '', $query = '', $fragment = '')
  8558. {
  8559. $iri = new SimplePie_IRI('');
  8560. $iri->scheme = $scheme;
  8561. $iri->authority = $authority;
  8562. $iri->path = $path;
  8563. $iri->query = $query;
  8564. $iri->fragment = $fragment;
  8565. return $iri->get_uri();
  8566. }
  8567. public static function normalize_url($url)
  8568. {
  8569. $iri = new SimplePie_IRI($url);
  8570. return $iri->get_uri();
  8571. }
  8572. public static function percent_encoding_normalization($match)
  8573. {
  8574. $integer = hexdec($match[1]);
  8575. if ($integer >= 0x41 && $integer <= 0x5A || $integer >= 0x61 && $integer <= 0x7A || $integer >= 0x30 && $integer <= 0x39 || $integer === 0x2D || $integer === 0x2E || $integer === 0x5F || $integer === 0x7E)
  8576. {
  8577. return chr($integer);
  8578. }
  8579. else
  8580. {
  8581. return strtoupper($match[0]);
  8582. }
  8583. }
  8584. public static function windows_1252_to_utf8($string)
  8585. {
  8586. static $convert_table = array("\x80" => "\xE2\x82\xAC", "\x81" => "\xEF\xBF\xBD", "\x82" => "\xE2\x80\x9A", "\x83" => "\xC6\x92", "\x84" => "\xE2\x80\x9E", "\x85" => "\xE2\x80\xA6", "\x86" => "\xE2\x80\xA0", "\x87" => "\xE2\x80\xA1", "\x88" => "\xCB\x86", "\x89" => "\xE2\x80\xB0", "\x8A" => "\xC5\xA0", "\x8B" => "\xE2\x80\xB9", "\x8C" => "\xC5\x92", "\x8D" => "\xEF\xBF\xBD", "\x8E" => "\xC5\xBD", "\x8F" => "\xEF\xBF\xBD", "\x90" => "\xEF\xBF\xBD", "\x91" => "\xE2\x80\x98", "\x92" => "\xE2\x80\x99", "\x93" => "\xE2\x80\x9C", "\x94" => "\xE2\x80\x9D", "\x95" => "\xE2\x80\xA2", "\x96" => "\xE2\x80\x93", "\x97" => "\xE2\x80\x94", "\x98" => "\xCB\x9C", "\x99" => "\xE2\x84\xA2", "\x9A" => "\xC5\xA1", "\x9B" => "\xE2\x80\xBA", "\x9C" => "\xC5\x93", "\x9D" => "\xEF\xBF\xBD", "\x9E" => "\xC5\xBE", "\x9F" => "\xC5\xB8", "\xA0" => "\xC2\xA0", "\xA1" => "\xC2\xA1", "\xA2" => "\xC2\xA2", "\xA3" => "\xC2\xA3", "\xA4" => "\xC2\xA4", "\xA5" => "\xC2\xA5", "\xA6" => "\xC2\xA6", "\xA7" => "\xC2\xA7", "\xA8" => "\xC2\xA8", "\xA9" => "\xC2\xA9", "\xAA" => "\xC2\xAA", "\xAB" => "\xC2\xAB", "\xAC" => "\xC2\xAC", "\xAD" => "\xC2\xAD", "\xAE" => "\xC2\xAE", "\xAF" => "\xC2\xAF", "\xB0" => "\xC2\xB0", "\xB1" => "\xC2\xB1", "\xB2" => "\xC2\xB2", "\xB3" => "\xC2\xB3", "\xB4" => "\xC2\xB4", "\xB5" => "\xC2\xB5", "\xB6" => "\xC2\xB6", "\xB7" => "\xC2\xB7", "\xB8" => "\xC2\xB8", "\xB9" => "\xC2\xB9", "\xBA" => "\xC2\xBA", "\xBB" => "\xC2\xBB", "\xBC" => "\xC2\xBC", "\xBD" => "\xC2\xBD", "\xBE" => "\xC2\xBE", "\xBF" => "\xC2\xBF", "\xC0" => "\xC3\x80", "\xC1" => "\xC3\x81", "\xC2" => "\xC3\x82", "\xC3" => "\xC3\x83", "\xC4" => "\xC3\x84", "\xC5" => "\xC3\x85", "\xC6" => "\xC3\x86", "\xC7" => "\xC3\x87", "\xC8" => "\xC3\x88", "\xC9" => "\xC3\x89", "\xCA" => "\xC3\x8A", "\xCB" => "\xC3\x8B", "\xCC" => "\xC3\x8C", "\xCD" => "\xC3\x8D", "\xCE" => "\xC3\x8E", "\xCF" => "\xC3\x8F", "\xD0" => "\xC3\x90", "\xD1" => "\xC3\x91", "\xD2" => "\xC3\x92", "\xD3" => "\xC3\x93", "\xD4" => "\xC3\x94", "\xD5" => "\xC3\x95", "\xD6" => "\xC3\x96", "\xD7" => "\xC3\x97", "\xD8" => "\xC3\x98", "\xD9" => "\xC3\x99", "\xDA" => "\xC3\x9A", "\xDB" => "\xC3\x9B", "\xDC" => "\xC3\x9C", "\xDD" => "\xC3\x9D", "\xDE" => "\xC3\x9E", "\xDF" => "\xC3\x9F", "\xE0" => "\xC3\xA0", "\xE1" => "\xC3\xA1", "\xE2" => "\xC3\xA2", "\xE3" => "\xC3\xA3", "\xE4" => "\xC3\xA4", "\xE5" => "\xC3\xA5", "\xE6" => "\xC3\xA6", "\xE7" => "\xC3\xA7", "\xE8" => "\xC3\xA8", "\xE9" => "\xC3\xA9", "\xEA" => "\xC3\xAA", "\xEB" => "\xC3\xAB", "\xEC" => "\xC3\xAC", "\xED" => "\xC3\xAD", "\xEE" => "\xC3\xAE", "\xEF" => "\xC3\xAF", "\xF0" => "\xC3\xB0", "\xF1" => "\xC3\xB1", "\xF2" => "\xC3\xB2", "\xF3" => "\xC3\xB3", "\xF4" => "\xC3\xB4", "\xF5" => "\xC3\xB5", "\xF6" => "\xC3\xB6", "\xF7" => "\xC3\xB7", "\xF8" => "\xC3\xB8", "\xF9" => "\xC3\xB9", "\xFA" => "\xC3\xBA", "\xFB" => "\xC3\xBB", "\xFC" => "\xC3\xBC", "\xFD" => "\xC3\xBD", "\xFE" => "\xC3\xBE", "\xFF" => "\xC3\xBF");
  8587. return strtr($string, $convert_table);
  8588. }
  8589. public static function change_encoding($data, $input, $output)
  8590. {
  8591. $input = SimplePie_Misc::encoding($input);
  8592. $output = SimplePie_Misc::encoding($output);
  8593. // We fail to fail on non US-ASCII bytes
  8594. if ($input === 'US-ASCII')
  8595. {
  8596. static $non_ascii_octects = '';
  8597. if (!$non_ascii_octects)
  8598. {
  8599. for ($i = 0x80; $i <= 0xFF; $i++)
  8600. {
  8601. $non_ascii_octects .= chr($i);
  8602. }
  8603. }
  8604. $data = substr($data, 0, strcspn($data, $non_ascii_octects));
  8605. }
  8606. // This is first, as behaviour of this is completely predictable
  8607. if ($input === 'windows-1252' && $output === 'UTF-8')
  8608. {
  8609. return SimplePie_Misc::windows_1252_to_utf8($data);
  8610. }
  8611. // This is second, as behaviour of this varies only with PHP version (the middle part of this expression checks the encoding is supported).
  8612. elseif (function_exists('mb_convert_encoding') && ($return = SimplePie_Misc::change_encoding_mbstring($data, $input, $output)))
  8613. {
  8614. return $return;
  8615. }
  8616. // This is last, as behaviour of this varies with OS userland and PHP version
  8617. elseif (function_exists('iconv') && ($return = SimplePie_Misc::change_encoding_iconv($data, $input, $output)))
  8618. {
  8619. return $return;
  8620. }
  8621. // If we can't do anything, just fail
  8622. else
  8623. {
  8624. return false;
  8625. }
  8626. }
  8627. protected static function change_encoding_mbstring($data, $input, $output)
  8628. {
  8629. if ($input === 'windows-949')
  8630. {
  8631. $input = 'EUC-KR';
  8632. }
  8633. if ($output === 'windows-949')
  8634. {
  8635. $output = 'EUC-KR';
  8636. }
  8637. if ($input === 'Windows-31J')
  8638. {
  8639. $input = 'SJIS';
  8640. }
  8641. if ($output === 'Windows-31J')
  8642. {
  8643. $output = 'SJIS';
  8644. }
  8645. // Check that the encoding is supported
  8646. if (@mb_convert_encoding("\x80", 'UTF-16BE', $input) === "\x00\x80")
  8647. {
  8648. return false;
  8649. }
  8650. if (!in_array($input, mb_list_encodings()))
  8651. {
  8652. return false;
  8653. }
  8654. // Let's do some conversion
  8655. if ($return = @mb_convert_encoding($data, $output, $input))
  8656. {
  8657. return $return;
  8658. }
  8659. return false;
  8660. }
  8661. protected static function change_encoding_iconv($data, $input, $output)
  8662. {
  8663. return @iconv($input, $output, $data);
  8664. }
  8665. public static function encoding($charset)
  8666. {
  8667. // Normalization from UTS #22
  8668. switch (strtolower(preg_replace('/(?:[^a-zA-Z0-9]+|([^0-9])0+)/', '\1', $charset)))
  8669. {
  8670. case 'adobestandardencoding':
  8671. case 'csadobestandardencoding':
  8672. return 'Adobe-Standard-Encoding';
  8673. case 'adobesymbolencoding':
  8674. case 'cshppsmath':
  8675. return 'Adobe-Symbol-Encoding';
  8676. case 'ami1251':
  8677. case 'amiga1251':
  8678. return 'Amiga-1251';
  8679. case 'ansix31101983':
  8680. case 'csat5001983':
  8681. case 'csiso99naplps':
  8682. case 'isoir99':
  8683. case 'naplps':
  8684. return 'ANSI_X3.110-1983';
  8685. case 'arabic7':
  8686. case 'asmo449':
  8687. case 'csiso89asmo449':
  8688. case 'iso9036':
  8689. case 'isoir89':
  8690. return 'ASMO_449';
  8691. case 'big5':
  8692. case 'csbig5':
  8693. return 'Big5';
  8694. case 'big5hkscs':
  8695. return 'Big5-HKSCS';
  8696. case 'bocu1':
  8697. case 'csbocu1':
  8698. return 'BOCU-1';
  8699. case 'brf':
  8700. case 'csbrf':
  8701. return 'BRF';
  8702. case 'bs4730':
  8703. case 'csiso4unitedkingdom':
  8704. case 'gb':
  8705. case 'iso646gb':
  8706. case 'isoir4':
  8707. case 'uk':
  8708. return 'BS_4730';
  8709. case 'bsviewdata':
  8710. case 'csiso47bsviewdata':
  8711. case 'isoir47':
  8712. return 'BS_viewdata';
  8713. case 'cesu8':
  8714. case 'cscesu8':
  8715. return 'CESU-8';
  8716. case 'ca':
  8717. case 'csa71':
  8718. case 'csaz243419851':
  8719. case 'csiso121canadian1':
  8720. case 'iso646ca':
  8721. case 'isoir121':
  8722. return 'CSA_Z243.4-1985-1';
  8723. case 'csa72':
  8724. case 'csaz243419852':
  8725. case 'csiso122canadian2':
  8726. case 'iso646ca2':
  8727. case 'isoir122':
  8728. return 'CSA_Z243.4-1985-2';
  8729. case 'csaz24341985gr':
  8730. case 'csiso123csaz24341985gr':
  8731. case 'isoir123':
  8732. return 'CSA_Z243.4-1985-gr';
  8733. case 'csiso139csn369103':
  8734. case 'csn369103':
  8735. case 'isoir139':
  8736. return 'CSN_369103';
  8737. case 'csdecmcs':
  8738. case 'dec':
  8739. case 'decmcs':
  8740. return 'DEC-MCS';
  8741. case 'csiso21german':
  8742. case 'de':
  8743. case 'din66003':
  8744. case 'iso646de':
  8745. case 'isoir21':
  8746. return 'DIN_66003';
  8747. case 'csdkus':
  8748. case 'dkus':
  8749. return 'dk-us';
  8750. case 'csiso646danish':
  8751. case 'dk':
  8752. case 'ds2089':
  8753. case 'iso646dk':
  8754. return 'DS_2089';
  8755. case 'csibmebcdicatde':
  8756. case 'ebcdicatde':
  8757. return 'EBCDIC-AT-DE';
  8758. case 'csebcdicatdea':
  8759. case 'ebcdicatdea':
  8760. return 'EBCDIC-AT-DE-A';
  8761. case 'csebcdiccafr':
  8762. case 'ebcdiccafr':
  8763. return 'EBCDIC-CA-FR';
  8764. case 'csebcdicdkno':
  8765. case 'ebcdicdkno':
  8766. return 'EBCDIC-DK-NO';
  8767. case 'csebcdicdknoa':
  8768. case 'ebcdicdknoa':
  8769. return 'EBCDIC-DK-NO-A';
  8770. case 'csebcdices':
  8771. case 'ebcdices':
  8772. return 'EBCDIC-ES';
  8773. case 'csebcdicesa':
  8774. case 'ebcdicesa':
  8775. return 'EBCDIC-ES-A';
  8776. case 'csebcdicess':
  8777. case 'ebcdicess':
  8778. return 'EBCDIC-ES-S';
  8779. case 'csebcdicfise':
  8780. case 'ebcdicfise':
  8781. return 'EBCDIC-FI-SE';
  8782. case 'csebcdicfisea':
  8783. case 'ebcdicfisea':
  8784. return 'EBCDIC-FI-SE-A';
  8785. case 'csebcdicfr':
  8786. case 'ebcdicfr':
  8787. return 'EBCDIC-FR';
  8788. case 'csebcdicit':
  8789. case 'ebcdicit':
  8790. return 'EBCDIC-IT';
  8791. case 'csebcdicpt':
  8792. case 'ebcdicpt':
  8793. return 'EBCDIC-PT';
  8794. case 'csebcdicuk':
  8795. case 'ebcdicuk':
  8796. return 'EBCDIC-UK';
  8797. case 'csebcdicus':
  8798. case 'ebcdicus':
  8799. return 'EBCDIC-US';
  8800. case 'csiso111ecmacyrillic':
  8801. case 'ecmacyrillic':
  8802. case 'isoir111':
  8803. case 'koi8e':
  8804. return 'ECMA-cyrillic';
  8805. case 'csiso17spanish':
  8806. case 'es':
  8807. case 'iso646es':
  8808. case 'isoir17':
  8809. return 'ES';
  8810. case 'csiso85spanish2':
  8811. case 'es2':
  8812. case 'iso646es2':
  8813. case 'isoir85':
  8814. return 'ES2';
  8815. case 'cseucpkdfmtjapanese':
  8816. case 'eucjp':
  8817. case 'extendedunixcodepackedformatforjapanese':
  8818. return 'EUC-JP';
  8819. case 'cseucfixwidjapanese':
  8820. case 'extendedunixcodefixedwidthforjapanese':
  8821. return 'Extended_UNIX_Code_Fixed_Width_for_Japanese';
  8822. case 'gb18030':
  8823. return 'GB18030';
  8824. case 'chinese':
  8825. case 'cp936':
  8826. case 'csgb2312':
  8827. case 'csiso58gb231280':
  8828. case 'gb2312':
  8829. case 'gb231280':
  8830. case 'gbk':
  8831. case 'isoir58':
  8832. case 'ms936':
  8833. case 'windows936':
  8834. return 'GBK';
  8835. case 'cn':
  8836. case 'csiso57gb1988':
  8837. case 'gb198880':
  8838. case 'iso646cn':
  8839. case 'isoir57':
  8840. return 'GB_1988-80';
  8841. case 'csiso153gost1976874':
  8842. case 'gost1976874':
  8843. case 'isoir153':
  8844. case 'stsev35888':
  8845. return 'GOST_19768-74';
  8846. case 'csiso150':
  8847. case 'csiso150greekccitt':
  8848. case 'greekccitt':
  8849. case 'isoir150':
  8850. return 'greek-ccitt';
  8851. case 'csiso88greek7':
  8852. case 'greek7':
  8853. case 'isoir88':
  8854. return 'greek7';
  8855. case 'csiso18greek7old':
  8856. case 'greek7old':
  8857. case 'isoir18':
  8858. return 'greek7-old';
  8859. case 'cshpdesktop':
  8860. case 'hpdesktop':
  8861. return 'HP-DeskTop';
  8862. case 'cshplegal':
  8863. case 'hplegal':
  8864. return 'HP-Legal';
  8865. case 'cshpmath8':
  8866. case 'hpmath8':
  8867. return 'HP-Math8';
  8868. case 'cshppifont':
  8869. case 'hppifont':
  8870. return 'HP-Pi-font';
  8871. case 'cshproman8':
  8872. case 'hproman8':
  8873. case 'r8':
  8874. case 'roman8':
  8875. return 'hp-roman8';
  8876. case 'hzgb2312':
  8877. return 'HZ-GB-2312';
  8878. case 'csibmsymbols':
  8879. case 'ibmsymbols':
  8880. return 'IBM-Symbols';
  8881. case 'csibmthai':
  8882. case 'ibmthai':
  8883. return 'IBM-Thai';
  8884. case 'cp37':
  8885. case 'csibm37':
  8886. case 'ebcdiccpca':
  8887. case 'ebcdiccpnl':
  8888. case 'ebcdiccpus':
  8889. case 'ebcdiccpwt':
  8890. case 'ibm37':
  8891. return 'IBM037';
  8892. case 'cp38':
  8893. case 'csibm38':
  8894. case 'ebcdicint':
  8895. case 'ibm38':
  8896. return 'IBM038';
  8897. case 'cp273':
  8898. case 'csibm273':
  8899. case 'ibm273':
  8900. return 'IBM273';
  8901. case 'cp274':
  8902. case 'csibm274':
  8903. case 'ebcdicbe':
  8904. case 'ibm274':
  8905. return 'IBM274';
  8906. case 'cp275':
  8907. case 'csibm275':
  8908. case 'ebcdicbr':
  8909. case 'ibm275':
  8910. return 'IBM275';
  8911. case 'csibm277':
  8912. case 'ebcdiccpdk':
  8913. case 'ebcdiccpno':
  8914. case 'ibm277':
  8915. return 'IBM277';
  8916. case 'cp278':
  8917. case 'csibm278':
  8918. case 'ebcdiccpfi':
  8919. case 'ebcdiccpse':
  8920. case 'ibm278':
  8921. return 'IBM278';
  8922. case 'cp280':
  8923. case 'csibm280':
  8924. case 'ebcdiccpit':
  8925. case 'ibm280':
  8926. return 'IBM280';
  8927. case 'cp281':
  8928. case 'csibm281':
  8929. case 'ebcdicjpe':
  8930. case 'ibm281':
  8931. return 'IBM281';
  8932. case 'cp284':
  8933. case 'csibm284':
  8934. case 'ebcdiccpes':
  8935. case 'ibm284':
  8936. return 'IBM284';
  8937. case 'cp285':
  8938. case 'csibm285':
  8939. case 'ebcdiccpgb':
  8940. case 'ibm285':
  8941. return 'IBM285';
  8942. case 'cp290':
  8943. case 'csibm290':
  8944. case 'ebcdicjpkana':
  8945. case 'ibm290':
  8946. return 'IBM290';
  8947. case 'cp297':
  8948. case 'csibm297':
  8949. case 'ebcdiccpfr':
  8950. case 'ibm297':
  8951. return 'IBM297';
  8952. case 'cp420':
  8953. case 'csibm420':
  8954. case 'ebcdiccpar1':
  8955. case 'ibm420':
  8956. return 'IBM420';
  8957. case 'cp423':
  8958. case 'csibm423':
  8959. case 'ebcdiccpgr':
  8960. case 'ibm423':
  8961. return 'IBM423';
  8962. case 'cp424':
  8963. case 'csibm424':
  8964. case 'ebcdiccphe':
  8965. case 'ibm424':
  8966. return 'IBM424';
  8967. case '437':
  8968. case 'cp437':
  8969. case 'cspc8codepage437':
  8970. case 'ibm437':
  8971. return 'IBM437';
  8972. case 'cp500':
  8973. case 'csibm500':
  8974. case 'ebcdiccpbe':
  8975. case 'ebcdiccpch':
  8976. case 'ibm500':
  8977. return 'IBM500';
  8978. case 'cp775':
  8979. case 'cspc775baltic':
  8980. case 'ibm775':
  8981. return 'IBM775';
  8982. case '850':
  8983. case 'cp850':
  8984. case 'cspc850multilingual':
  8985. case 'ibm850':
  8986. return 'IBM850';
  8987. case '851':
  8988. case 'cp851':
  8989. case 'csibm851':
  8990. case 'ibm851':
  8991. return 'IBM851';
  8992. case '852':
  8993. case 'cp852':
  8994. case 'cspcp852':
  8995. case 'ibm852':
  8996. return 'IBM852';
  8997. case '855':
  8998. case 'cp855':
  8999. case 'csibm855':
  9000. case 'ibm855':
  9001. return 'IBM855';
  9002. case '857':
  9003. case 'cp857':
  9004. case 'csibm857':
  9005. case 'ibm857':
  9006. return 'IBM857';
  9007. case 'ccsid858':
  9008. case 'cp858':
  9009. case 'ibm858':
  9010. case 'pcmultilingual850euro':
  9011. return 'IBM00858';
  9012. case '860':
  9013. case 'cp860':
  9014. case 'csibm860':
  9015. case 'ibm860':
  9016. return 'IBM860';
  9017. case '861':
  9018. case 'cp861':
  9019. case 'cpis':
  9020. case 'csibm861':
  9021. case 'ibm861':
  9022. return 'IBM861';
  9023. case '862':
  9024. case 'cp862':
  9025. case 'cspc862latinhebrew':
  9026. case 'ibm862':
  9027. return 'IBM862';
  9028. case '863':
  9029. case 'cp863':
  9030. case 'csibm863':
  9031. case 'ibm863':
  9032. return 'IBM863';
  9033. case 'cp864':
  9034. case 'csibm864':
  9035. case 'ibm864':
  9036. return 'IBM864';
  9037. case '865':
  9038. case 'cp865':
  9039. case 'csibm865':
  9040. case 'ibm865':
  9041. return 'IBM865';
  9042. case '866':
  9043. case 'cp866':
  9044. case 'csibm866':
  9045. case 'ibm866':
  9046. return 'IBM866';
  9047. case 'cp868':
  9048. case 'cpar':
  9049. case 'csibm868':
  9050. case 'ibm868':
  9051. return 'IBM868';
  9052. case '869':
  9053. case 'cp869':
  9054. case 'cpgr':
  9055. case 'csibm869':
  9056. case 'ibm869':
  9057. return 'IBM869';
  9058. case 'cp870':
  9059. case 'csibm870':
  9060. case 'ebcdiccproece':
  9061. case 'ebcdiccpyu':
  9062. case 'ibm870':
  9063. return 'IBM870';
  9064. case 'cp871':
  9065. case 'csibm871':
  9066. case 'ebcdiccpis':
  9067. case 'ibm871':
  9068. return 'IBM871';
  9069. case 'cp880':
  9070. case 'csibm880':
  9071. case 'ebcdiccyrillic':
  9072. case 'ibm880':
  9073. return 'IBM880';
  9074. case 'cp891':
  9075. case 'csibm891':
  9076. case 'ibm891':
  9077. return 'IBM891';
  9078. case 'cp903':
  9079. case 'csibm903':
  9080. case 'ibm903':
  9081. return 'IBM903';
  9082. case '904':
  9083. case 'cp904':
  9084. case 'csibbm904':
  9085. case 'ibm904':
  9086. return 'IBM904';
  9087. case 'cp905':
  9088. case 'csibm905':
  9089. case 'ebcdiccptr':
  9090. case 'ibm905':
  9091. return 'IBM905';
  9092. case 'cp918':
  9093. case 'csibm918':
  9094. case 'ebcdiccpar2':
  9095. case 'ibm918':
  9096. return 'IBM918';
  9097. case 'ccsid924':
  9098. case 'cp924':
  9099. case 'ebcdiclatin9euro':
  9100. case 'ibm924':
  9101. return 'IBM00924';
  9102. case 'cp1026':
  9103. case 'csibm1026':
  9104. case 'ibm1026':
  9105. return 'IBM1026';
  9106. case 'ibm1047':
  9107. return 'IBM1047';
  9108. case 'ccsid1140':
  9109. case 'cp1140':
  9110. case 'ebcdicus37euro':
  9111. case 'ibm1140':
  9112. return 'IBM01140';
  9113. case 'ccsid1141':
  9114. case 'cp1141':
  9115. case 'ebcdicde273euro':
  9116. case 'ibm1141':
  9117. return 'IBM01141';
  9118. case 'ccsid1142':
  9119. case 'cp1142':
  9120. case 'ebcdicdk277euro':
  9121. case 'ebcdicno277euro':
  9122. case 'ibm1142':
  9123. return 'IBM01142';
  9124. case 'ccsid1143':
  9125. case 'cp1143':
  9126. case 'ebcdicfi278euro':
  9127. case 'ebcdicse278euro':
  9128. case 'ibm1143':
  9129. return 'IBM01143';
  9130. case 'ccsid1144':
  9131. case 'cp1144':
  9132. case 'ebcdicit280euro':
  9133. case 'ibm1144':
  9134. return 'IBM01144';
  9135. case 'ccsid1145':
  9136. case 'cp1145':
  9137. case 'ebcdices284euro':
  9138. case 'ibm1145':
  9139. return 'IBM01145';
  9140. case 'ccsid1146':
  9141. case 'cp1146':
  9142. case 'ebcdicgb285euro':
  9143. case 'ibm1146':
  9144. return 'IBM01146';
  9145. case 'ccsid1147':
  9146. case 'cp1147':
  9147. case 'ebcdicfr297euro':
  9148. case 'ibm1147':
  9149. return 'IBM01147';
  9150. case 'ccsid1148':
  9151. case 'cp1148':
  9152. case 'ebcdicinternational500euro':
  9153. case 'ibm1148':
  9154. return 'IBM01148';
  9155. case 'ccsid1149':
  9156. case 'cp1149':
  9157. case 'ebcdicis871euro':
  9158. case 'ibm1149':
  9159. return 'IBM01149';
  9160. case 'csiso143iecp271':
  9161. case 'iecp271':
  9162. case 'isoir143':
  9163. return 'IEC_P27-1';
  9164. case 'csiso49inis':
  9165. case 'inis':
  9166. case 'isoir49':
  9167. return 'INIS';
  9168. case 'csiso50inis8':
  9169. case 'inis8':
  9170. case 'isoir50':
  9171. return 'INIS-8';
  9172. case 'csiso51iniscyrillic':
  9173. case 'iniscyrillic':
  9174. case 'isoir51':
  9175. return 'INIS-cyrillic';
  9176. case 'csinvariant':
  9177. case 'invariant':
  9178. return 'INVARIANT';
  9179. case 'iso2022cn':
  9180. return 'ISO-2022-CN';
  9181. case 'iso2022cnext':
  9182. return 'ISO-2022-CN-EXT';
  9183. case 'csiso2022jp':
  9184. case 'iso2022jp':
  9185. return 'ISO-2022-JP';
  9186. case 'csiso2022jp2':
  9187. case 'iso2022jp2':
  9188. return 'ISO-2022-JP-2';
  9189. case 'csiso2022kr':
  9190. case 'iso2022kr':
  9191. return 'ISO-2022-KR';
  9192. case 'cswindows30latin1':
  9193. case 'iso88591windows30latin1':
  9194. return 'ISO-8859-1-Windows-3.0-Latin-1';
  9195. case 'cswindows31latin1':
  9196. case 'iso88591windows31latin1':
  9197. return 'ISO-8859-1-Windows-3.1-Latin-1';
  9198. case 'csisolatin2':
  9199. case 'iso88592':
  9200. case 'iso885921987':
  9201. case 'isoir101':
  9202. case 'l2':
  9203. case 'latin2':
  9204. return 'ISO-8859-2';
  9205. case 'cswindows31latin2':
  9206. case 'iso88592windowslatin2':
  9207. return 'ISO-8859-2-Windows-Latin-2';
  9208. case 'csisolatin3':
  9209. case 'iso88593':
  9210. case 'iso885931988':
  9211. case 'isoir109':
  9212. case 'l3':
  9213. case 'latin3':
  9214. return 'ISO-8859-3';
  9215. case 'csisolatin4':
  9216. case 'iso88594':
  9217. case 'iso885941988':
  9218. case 'isoir110':
  9219. case 'l4':
  9220. case 'latin4':
  9221. return 'ISO-8859-4';
  9222. case 'csisolatincyrillic':
  9223. case 'cyrillic':
  9224. case 'iso88595':
  9225. case 'iso885951988':
  9226. case 'isoir144':
  9227. return 'ISO-8859-5';
  9228. case 'arabic':
  9229. case 'asmo708':
  9230. case 'csisolatinarabic':
  9231. case 'ecma114':
  9232. case 'iso88596':
  9233. case 'iso885961987':
  9234. case 'isoir127':
  9235. return 'ISO-8859-6';
  9236. case 'csiso88596e':
  9237. case 'iso88596e':
  9238. return 'ISO-8859-6-E';
  9239. case 'csiso88596i':
  9240. case 'iso88596i':
  9241. return 'ISO-8859-6-I';
  9242. case 'csisolatingreek':
  9243. case 'ecma118':
  9244. case 'elot928':
  9245. case 'greek':
  9246. case 'greek8':
  9247. case 'iso88597':
  9248. case 'iso885971987':
  9249. case 'isoir126':
  9250. return 'ISO-8859-7';
  9251. case 'csisolatinhebrew':
  9252. case 'hebrew':
  9253. case 'iso88598':
  9254. case 'iso885981988':
  9255. case 'isoir138':
  9256. return 'ISO-8859-8';
  9257. case 'csiso88598e':
  9258. case 'iso88598e':
  9259. return 'ISO-8859-8-E';
  9260. case 'csiso88598i':
  9261. case 'iso88598i':
  9262. return 'ISO-8859-8-I';
  9263. case 'cswindows31latin5':
  9264. case 'iso88599windowslatin5':
  9265. return 'ISO-8859-9-Windows-Latin-5';
  9266. case 'csisolatin6':
  9267. case 'iso885910':
  9268. case 'iso8859101992':
  9269. case 'isoir157':
  9270. case 'l6':
  9271. case 'latin6':
  9272. return 'ISO-8859-10';
  9273. case 'iso885913':
  9274. return 'ISO-8859-13';
  9275. case 'iso885914':
  9276. case 'iso8859141998':
  9277. case 'isoceltic':
  9278. case 'isoir199':
  9279. case 'l8':
  9280. case 'latin8':
  9281. return 'ISO-8859-14';
  9282. case 'iso885915':
  9283. case 'latin9':
  9284. return 'ISO-8859-15';
  9285. case 'iso885916':
  9286. case 'iso8859162001':
  9287. case 'isoir226':
  9288. case 'l10':
  9289. case 'latin10':
  9290. return 'ISO-8859-16';
  9291. case 'iso10646j1':
  9292. return 'ISO-10646-J-1';
  9293. case 'csunicode':
  9294. case 'iso10646ucs2':
  9295. return 'ISO-10646-UCS-2';
  9296. case 'csucs4':
  9297. case 'iso10646ucs4':
  9298. return 'ISO-10646-UCS-4';
  9299. case 'csunicodeascii':
  9300. case 'iso10646ucsbasic':
  9301. return 'ISO-10646-UCS-Basic';
  9302. case 'csunicodelatin1':
  9303. case 'iso10646':
  9304. case 'iso10646unicodelatin1':
  9305. return 'ISO-10646-Unicode-Latin1';
  9306. case 'csiso10646utf1':
  9307. case 'iso10646utf1':
  9308. return 'ISO-10646-UTF-1';
  9309. case 'csiso115481':
  9310. case 'iso115481':
  9311. case 'isotr115481':
  9312. return 'ISO-11548-1';
  9313. case 'csiso90':
  9314. case 'isoir90':
  9315. return 'iso-ir-90';
  9316. case 'csunicodeibm1261':
  9317. case 'isounicodeibm1261':
  9318. return 'ISO-Unicode-IBM-1261';
  9319. case 'csunicodeibm1264':
  9320. case 'isounicodeibm1264':
  9321. return 'ISO-Unicode-IBM-1264';
  9322. case 'csunicodeibm1265':
  9323. case 'isounicodeibm1265':
  9324. return 'ISO-Unicode-IBM-1265';
  9325. case 'csunicodeibm1268':
  9326. case 'isounicodeibm1268':
  9327. return 'ISO-Unicode-IBM-1268';
  9328. case 'csunicodeibm1276':
  9329. case 'isounicodeibm1276':
  9330. return 'ISO-Unicode-IBM-1276';
  9331. case 'csiso646basic1983':
  9332. case 'iso646basic1983':
  9333. case 'ref':
  9334. return 'ISO_646.basic:1983';
  9335. case 'csiso2intlrefversion':
  9336. case 'irv':
  9337. case 'iso646irv1983':
  9338. case 'isoir2':
  9339. return 'ISO_646.irv:1983';
  9340. case 'csiso2033':
  9341. case 'e13b':
  9342. case 'iso20331983':
  9343. case 'isoir98':
  9344. return 'ISO_2033-1983';
  9345. case 'csiso5427cyrillic':
  9346. case 'iso5427':
  9347. case 'isoir37':
  9348. return 'ISO_5427';
  9349. case 'iso5427cyrillic1981':
  9350. case 'iso54271981':
  9351. case 'isoir54':
  9352. return 'ISO_5427:1981';
  9353. case 'csiso5428greek':
  9354. case 'iso54281980':
  9355. case 'isoir55':
  9356. return 'ISO_5428:1980';
  9357. case 'csiso6937add':
  9358. case 'iso6937225':
  9359. case 'isoir152':
  9360. return 'ISO_6937-2-25';
  9361. case 'csisotextcomm':
  9362. case 'iso69372add':
  9363. case 'isoir142':
  9364. return 'ISO_6937-2-add';
  9365. case 'csiso8859supp':
  9366. case 'iso8859supp':
  9367. case 'isoir154':
  9368. case 'latin125':
  9369. return 'ISO_8859-supp';
  9370. case 'csiso10367box':
  9371. case 'iso10367box':
  9372. case 'isoir155':
  9373. return 'ISO_10367-box';
  9374. case 'csiso15italian':
  9375. case 'iso646it':
  9376. case 'isoir15':
  9377. case 'it':
  9378. return 'IT';
  9379. case 'csiso13jisc6220jp':
  9380. case 'isoir13':
  9381. case 'jisc62201969':
  9382. case 'jisc62201969jp':
  9383. case 'katakana':
  9384. case 'x2017':
  9385. return 'JIS_C6220-1969-jp';
  9386. case 'csiso14jisc6220ro':
  9387. case 'iso646jp':
  9388. case 'isoir14':
  9389. case 'jisc62201969ro':
  9390. case 'jp':
  9391. return 'JIS_C6220-1969-ro';
  9392. case 'csiso42jisc62261978':
  9393. case 'isoir42':
  9394. case 'jisc62261978':
  9395. return 'JIS_C6226-1978';
  9396. case 'csiso87jisx208':
  9397. case 'isoir87':
  9398. case 'jisc62261983':
  9399. case 'jisx2081983':
  9400. case 'x208':
  9401. return 'JIS_C6226-1983';
  9402. case 'csiso91jisc62291984a':
  9403. case 'isoir91':
  9404. case 'jisc62291984a':
  9405. case 'jpocra':
  9406. return 'JIS_C6229-1984-a';
  9407. case 'csiso92jisc62991984b':
  9408. case 'iso646jpocrb':
  9409. case 'isoir92':
  9410. case 'jisc62291984b':
  9411. case 'jpocrb':
  9412. return 'JIS_C6229-1984-b';
  9413. case 'csiso93jis62291984badd':
  9414. case 'isoir93':
  9415. case 'jisc62291984badd':
  9416. case 'jpocrbadd':
  9417. return 'JIS_C6229-1984-b-add';
  9418. case 'csiso94jis62291984hand':
  9419. case 'isoir94':
  9420. case 'jisc62291984hand':
  9421. case 'jpocrhand':
  9422. return 'JIS_C6229-1984-hand';
  9423. case 'csiso95jis62291984handadd':
  9424. case 'isoir95':
  9425. case 'jisc62291984handadd':
  9426. case 'jpocrhandadd':
  9427. return 'JIS_C6229-1984-hand-add';
  9428. case 'csiso96jisc62291984kana':
  9429. case 'isoir96':
  9430. case 'jisc62291984kana':
  9431. return 'JIS_C6229-1984-kana';
  9432. case 'csjisencoding':
  9433. case 'jisencoding':
  9434. return 'JIS_Encoding';
  9435. case 'cshalfwidthkatakana':
  9436. case 'jisx201':
  9437. case 'x201':
  9438. return 'JIS_X0201';
  9439. case 'csiso159jisx2121990':
  9440. case 'isoir159':
  9441. case 'jisx2121990':
  9442. case 'x212':
  9443. return 'JIS_X0212-1990';
  9444. case 'csiso141jusib1002':
  9445. case 'iso646yu':
  9446. case 'isoir141':
  9447. case 'js':
  9448. case 'jusib1002':
  9449. case 'yu':
  9450. return 'JUS_I.B1.002';
  9451. case 'csiso147macedonian':
  9452. case 'isoir147':
  9453. case 'jusib1003mac':
  9454. case 'macedonian':
  9455. return 'JUS_I.B1.003-mac';
  9456. case 'csiso146serbian':
  9457. case 'isoir146':
  9458. case 'jusib1003serb':
  9459. case 'serbian':
  9460. return 'JUS_I.B1.003-serb';
  9461. case 'koi7switched':
  9462. return 'KOI7-switched';
  9463. case 'cskoi8r':
  9464. case 'koi8r':
  9465. return 'KOI8-R';
  9466. case 'koi8u':
  9467. return 'KOI8-U';
  9468. case 'csksc5636':
  9469. case 'iso646kr':
  9470. case 'ksc5636':
  9471. return 'KSC5636';
  9472. case 'cskz1048':
  9473. case 'kz1048':
  9474. case 'rk1048':
  9475. case 'strk10482002':
  9476. return 'KZ-1048';
  9477. case 'csiso19latingreek':
  9478. case 'isoir19':
  9479. case 'latingreek':
  9480. return 'latin-greek';
  9481. case 'csiso27latingreek1':
  9482. case 'isoir27':
  9483. case 'latingreek1':
  9484. return 'Latin-greek-1';
  9485. case 'csiso158lap':
  9486. case 'isoir158':
  9487. case 'lap':
  9488. case 'latinlap':
  9489. return 'latin-lap';
  9490. case 'csmacintosh':
  9491. case 'mac':
  9492. case 'macintosh':
  9493. return 'macintosh';
  9494. case 'csmicrosoftpublishing':
  9495. case 'microsoftpublishing':
  9496. return 'Microsoft-Publishing';
  9497. case 'csmnem':
  9498. case 'mnem':
  9499. return 'MNEM';
  9500. case 'csmnemonic':
  9501. case 'mnemonic':
  9502. return 'MNEMONIC';
  9503. case 'csiso86hungarian':
  9504. case 'hu':
  9505. case 'iso646hu':
  9506. case 'isoir86':
  9507. case 'msz77953':
  9508. return 'MSZ_7795.3';
  9509. case 'csnatsdano':
  9510. case 'isoir91':
  9511. case 'natsdano':
  9512. return 'NATS-DANO';
  9513. case 'csnatsdanoadd':
  9514. case 'isoir92':
  9515. case 'natsdanoadd':
  9516. return 'NATS-DANO-ADD';
  9517. case 'csnatssefi':
  9518. case 'isoir81':
  9519. case 'natssefi':
  9520. return 'NATS-SEFI';
  9521. case 'csnatssefiadd':
  9522. case 'isoir82':
  9523. case 'natssefiadd':
  9524. return 'NATS-SEFI-ADD';
  9525. case 'csiso151cuba':
  9526. case 'cuba':
  9527. case 'iso646cu':
  9528. case 'isoir151':
  9529. case 'ncnc1081':
  9530. return 'NC_NC00-10:81';
  9531. case 'csiso69french':
  9532. case 'fr':
  9533. case 'iso646fr':
  9534. case 'isoir69':
  9535. case 'nfz62010':
  9536. return 'NF_Z_62-010';
  9537. case 'csiso25french':
  9538. case 'iso646fr1':
  9539. case 'isoir25':
  9540. case 'nfz620101973':
  9541. return 'NF_Z_62-010_(1973)';
  9542. case 'csiso60danishnorwegian':
  9543. case 'csiso60norwegian1':
  9544. case 'iso646no':
  9545. case 'isoir60':
  9546. case 'no':
  9547. case 'ns45511':
  9548. return 'NS_4551-1';
  9549. case 'csiso61norwegian2':
  9550. case 'iso646no2':
  9551. case 'isoir61':
  9552. case 'no2':
  9553. case 'ns45512':
  9554. return 'NS_4551-2';
  9555. case 'osdebcdicdf3irv':
  9556. return 'OSD_EBCDIC_DF03_IRV';
  9557. case 'osdebcdicdf41':
  9558. return 'OSD_EBCDIC_DF04_1';
  9559. case 'osdebcdicdf415':
  9560. return 'OSD_EBCDIC_DF04_15';
  9561. case 'cspc8danishnorwegian':
  9562. case 'pc8danishnorwegian':
  9563. return 'PC8-Danish-Norwegian';
  9564. case 'cspc8turkish':
  9565. case 'pc8turkish':
  9566. return 'PC8-Turkish';
  9567. case 'csiso16portuguese':
  9568. case 'iso646pt':
  9569. case 'isoir16':
  9570. case 'pt':
  9571. return 'PT';
  9572. case 'csiso84portuguese2':
  9573. case 'iso646pt2':
  9574. case 'isoir84':
  9575. case 'pt2':
  9576. return 'PT2';
  9577. case 'cp154':
  9578. case 'csptcp154':
  9579. case 'cyrillicasian':
  9580. case 'pt154':
  9581. case 'ptcp154':
  9582. return 'PTCP154';
  9583. case 'scsu':
  9584. return 'SCSU';
  9585. case 'csiso10swedish':
  9586. case 'fi':
  9587. case 'iso646fi':
  9588. case 'iso646se':
  9589. case 'isoir10':
  9590. case 'se':
  9591. case 'sen850200b':
  9592. return 'SEN_850200_B';
  9593. case 'csiso11swedishfornames':
  9594. case 'iso646se2':
  9595. case 'isoir11':
  9596. case 'se2':
  9597. case 'sen850200c':
  9598. return 'SEN_850200_C';
  9599. case 'csiso102t617bit':
  9600. case 'isoir102':
  9601. case 't617bit':
  9602. return 'T.61-7bit';
  9603. case 'csiso103t618bit':
  9604. case 'isoir103':
  9605. case 't61':
  9606. case 't618bit':
  9607. return 'T.61-8bit';
  9608. case 'csiso128t101g2':
  9609. case 'isoir128':
  9610. case 't101g2':
  9611. return 'T.101-G2';
  9612. case 'cstscii':
  9613. case 'tscii':
  9614. return 'TSCII';
  9615. case 'csunicode11':
  9616. case 'unicode11':
  9617. return 'UNICODE-1-1';
  9618. case 'csunicode11utf7':
  9619. case 'unicode11utf7':
  9620. return 'UNICODE-1-1-UTF-7';
  9621. case 'csunknown8bit':
  9622. case 'unknown8bit':
  9623. return 'UNKNOWN-8BIT';
  9624. case 'ansix341968':
  9625. case 'ansix341986':
  9626. case 'ascii':
  9627. case 'cp367':
  9628. case 'csascii':
  9629. case 'ibm367':
  9630. case 'iso646irv1991':
  9631. case 'iso646us':
  9632. case 'isoir6':
  9633. case 'us':
  9634. case 'usascii':
  9635. return 'US-ASCII';
  9636. case 'csusdk':
  9637. case 'usdk':
  9638. return 'us-dk';
  9639. case 'utf7':
  9640. return 'UTF-7';
  9641. case 'utf8':
  9642. return 'UTF-8';
  9643. case 'utf16':
  9644. return 'UTF-16';
  9645. case 'utf16be':
  9646. return 'UTF-16BE';
  9647. case 'utf16le':
  9648. return 'UTF-16LE';
  9649. case 'utf32':
  9650. return 'UTF-32';
  9651. case 'utf32be':
  9652. return 'UTF-32BE';
  9653. case 'utf32le':
  9654. return 'UTF-32LE';
  9655. case 'csventurainternational':
  9656. case 'venturainternational':
  9657. return 'Ventura-International';
  9658. case 'csventuramath':
  9659. case 'venturamath':
  9660. return 'Ventura-Math';
  9661. case 'csventuraus':
  9662. case 'venturaus':
  9663. return 'Ventura-US';
  9664. case 'csiso70videotexsupp1':
  9665. case 'isoir70':
  9666. case 'videotexsuppl':
  9667. return 'videotex-suppl';
  9668. case 'csviqr':
  9669. case 'viqr':
  9670. return 'VIQR';
  9671. case 'csviscii':
  9672. case 'viscii':
  9673. return 'VISCII';
  9674. case 'csshiftjis':
  9675. case 'cswindows31j':
  9676. case 'mskanji':
  9677. case 'shiftjis':
  9678. case 'windows31j':
  9679. return 'Windows-31J';
  9680. case 'iso885911':
  9681. case 'tis620':
  9682. return 'windows-874';
  9683. case 'cseuckr':
  9684. case 'csksc56011987':
  9685. case 'euckr':
  9686. case 'isoir149':
  9687. case 'korean':
  9688. case 'ksc5601':
  9689. case 'ksc56011987':
  9690. case 'ksc56011989':
  9691. case 'windows949':
  9692. return 'windows-949';
  9693. case 'windows1250':
  9694. return 'windows-1250';
  9695. case 'windows1251':
  9696. return 'windows-1251';
  9697. case 'cp819':
  9698. case 'csisolatin1':
  9699. case 'ibm819':
  9700. case 'iso88591':
  9701. case 'iso885911987':
  9702. case 'isoir100':
  9703. case 'l1':
  9704. case 'latin1':
  9705. case 'windows1252':
  9706. return 'windows-1252';
  9707. case 'windows1253':
  9708. return 'windows-1253';
  9709. case 'csisolatin5':
  9710. case 'iso88599':
  9711. case 'iso885991989':
  9712. case 'isoir148':
  9713. case 'l5':
  9714. case 'latin5':
  9715. case 'windows1254':
  9716. return 'windows-1254';
  9717. case 'windows1255':
  9718. return 'windows-1255';
  9719. case 'windows1256':
  9720. return 'windows-1256';
  9721. case 'windows1257':
  9722. return 'windows-1257';
  9723. case 'windows1258':
  9724. return 'windows-1258';
  9725. default:
  9726. return $charset;
  9727. }
  9728. }
  9729. public static function get_curl_version()
  9730. {
  9731. if (is_array($curl = curl_version()))
  9732. {
  9733. $curl = $curl['version'];
  9734. }
  9735. elseif (substr($curl, 0, 5) === 'curl/')
  9736. {
  9737. $curl = substr($curl, 5, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 5));
  9738. }
  9739. elseif (substr($curl, 0, 8) === 'libcurl/')
  9740. {
  9741. $curl = substr($curl, 8, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 8));
  9742. }
  9743. else
  9744. {
  9745. $curl = 0;
  9746. }
  9747. return $curl;
  9748. }
  9749. public static function strip_comments($data)
  9750. {
  9751. $output = '';
  9752. while (($start = strpos($data, '<!--')) !== false)
  9753. {
  9754. $output .= substr($data, 0, $start);
  9755. if (($end = strpos($data, '-->', $start)) !== false)
  9756. {
  9757. $data = substr_replace($data, '', 0, $end + 3);
  9758. }
  9759. else
  9760. {
  9761. $data = '';
  9762. }
  9763. }
  9764. return $output . $data;
  9765. }
  9766. public static function parse_date($dt)
  9767. {
  9768. $parser = SimplePie_Parse_Date::get();
  9769. return $parser->parse($dt);
  9770. }
  9771. public static function entities_decode($data)
  9772. {
  9773. $decoder = new SimplePie_Decode_HTML_Entities($data);
  9774. return $decoder->parse();
  9775. }
  9776. public static function uncomment_rfc822($string)
  9777. {
  9778. $string = (string) $string;
  9779. $position = 0;
  9780. $length = strlen($string);
  9781. $depth = 0;
  9782. $output = '';
  9783. while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
  9784. {
  9785. $output .= substr($string, $position, $pos - $position);
  9786. $position = $pos + 1;
  9787. if ($string[$pos - 1] !== '\\')
  9788. {
  9789. $depth++;
  9790. while ($depth && $position < $length)
  9791. {
  9792. $position += strcspn($string, '()', $position);
  9793. if ($string[$position - 1] === '\\')
  9794. {
  9795. $position++;
  9796. continue;
  9797. }
  9798. elseif (isset($string[$position]))
  9799. {
  9800. switch ($string[$position])
  9801. {
  9802. case '(':
  9803. $depth++;
  9804. break;
  9805. case ')':
  9806. $depth--;
  9807. break;
  9808. }
  9809. $position++;
  9810. }
  9811. else
  9812. {
  9813. break;
  9814. }
  9815. }
  9816. }
  9817. else
  9818. {
  9819. $output .= '(';
  9820. }
  9821. }
  9822. $output .= substr($string, $position);
  9823. return $output;
  9824. }
  9825. public static function parse_mime($mime)
  9826. {
  9827. if (($pos = strpos($mime, ';')) === false)
  9828. {
  9829. return trim($mime);
  9830. }
  9831. else
  9832. {
  9833. return trim(substr($mime, 0, $pos));
  9834. }
  9835. }
  9836. public static function atom_03_construct_type($attribs)
  9837. {
  9838. if (isset($attribs['']['mode']) && strtolower(trim($attribs['']['mode']) === 'base64'))
  9839. {
  9840. $mode = SIMPLEPIE_CONSTRUCT_BASE64;
  9841. }
  9842. else
  9843. {
  9844. $mode = SIMPLEPIE_CONSTRUCT_NONE;
  9845. }
  9846. if (isset($attribs['']['type']))
  9847. {
  9848. switch (strtolower(trim($attribs['']['type'])))
  9849. {
  9850. case 'text':
  9851. case 'text/plain':
  9852. return SIMPLEPIE_CONSTRUCT_TEXT | $mode;
  9853. case 'html':
  9854. case 'text/html':
  9855. return SIMPLEPIE_CONSTRUCT_HTML | $mode;
  9856. case 'xhtml':
  9857. case 'application/xhtml+xml':
  9858. return SIMPLEPIE_CONSTRUCT_XHTML | $mode;
  9859. default:
  9860. return SIMPLEPIE_CONSTRUCT_NONE | $mode;
  9861. }
  9862. }
  9863. else
  9864. {
  9865. return SIMPLEPIE_CONSTRUCT_TEXT | $mode;
  9866. }
  9867. }
  9868. public static function atom_10_construct_type($attribs)
  9869. {
  9870. if (isset($attribs['']['type']))
  9871. {
  9872. switch (strtolower(trim($attribs['']['type'])))
  9873. {
  9874. case 'text':
  9875. return SIMPLEPIE_CONSTRUCT_TEXT;
  9876. case 'html':
  9877. return SIMPLEPIE_CONSTRUCT_HTML;
  9878. case 'xhtml':
  9879. return SIMPLEPIE_CONSTRUCT_XHTML;
  9880. default:
  9881. return SIMPLEPIE_CONSTRUCT_NONE;
  9882. }
  9883. }
  9884. return SIMPLEPIE_CONSTRUCT_TEXT;
  9885. }
  9886. public static function atom_10_content_construct_type($attribs)
  9887. {
  9888. if (isset($attribs['']['type']))
  9889. {
  9890. $type = strtolower(trim($attribs['']['type']));
  9891. switch ($type)
  9892. {
  9893. case 'text':
  9894. return SIMPLEPIE_CONSTRUCT_TEXT;
  9895. case 'html':
  9896. return SIMPLEPIE_CONSTRUCT_HTML;
  9897. case 'xhtml':
  9898. return SIMPLEPIE_CONSTRUCT_XHTML;
  9899. }
  9900. if (in_array(substr($type, -4), array('+xml', '/xml')) || substr($type, 0, 5) === 'text/')
  9901. {
  9902. return SIMPLEPIE_CONSTRUCT_NONE;
  9903. }
  9904. else
  9905. {
  9906. return SIMPLEPIE_CONSTRUCT_BASE64;
  9907. }
  9908. }
  9909. else
  9910. {
  9911. return SIMPLEPIE_CONSTRUCT_TEXT;
  9912. }
  9913. }
  9914. public static function is_isegment_nz_nc($string)
  9915. {
  9916. return (bool) preg_match('/^([A-Za-z0-9\-._~\x{A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}\x{10000}-\x{1FFFD}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}\x{40000}-\x{4FFFD}\x{50000}-\x{5FFFD}\x{60000}-\x{6FFFD}\x{70000}-\x{7FFFD}\x{80000}-\x{8FFFD}\x{90000}-\x{9FFFD}\x{A0000}-\x{AFFFD}\x{B0000}-\x{BFFFD}\x{C0000}-\x{CFFFD}\x{D0000}-\x{DFFFD}\x{E1000}-\x{EFFFD}!$&\'()*+,;=@]|(%[0-9ABCDEF]{2}))+$/u', $string);
  9917. }
  9918. public static function space_seperated_tokens($string)
  9919. {
  9920. $space_characters = "\x20\x09\x0A\x0B\x0C\x0D";
  9921. $string_length = strlen($string);
  9922. $position = strspn($string, $space_characters);
  9923. $tokens = array();
  9924. while ($position < $string_length)
  9925. {
  9926. $len = strcspn($string, $space_characters, $position);
  9927. $tokens[] = substr($string, $position, $len);
  9928. $position += $len;
  9929. $position += strspn($string, $space_characters, $position);
  9930. }
  9931. return $tokens;
  9932. }
  9933. public static function codepoint_to_utf8($codepoint)
  9934. {
  9935. $codepoint = (int) $codepoint;
  9936. if ($codepoint < 0)
  9937. {
  9938. return false;
  9939. }
  9940. else if ($codepoint <= 0x7f)
  9941. {
  9942. return chr($codepoint);
  9943. }
  9944. else if ($codepoint <= 0x7ff)
  9945. {
  9946. return chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3f));
  9947. }
  9948. else if ($codepoint <= 0xffff)
  9949. {
  9950. return chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
  9951. }
  9952. else if ($codepoint <= 0x10ffff)
  9953. {
  9954. return chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
  9955. }
  9956. else
  9957. {
  9958. // U+FFFD REPLACEMENT CHARACTER
  9959. return "\xEF\xBF\xBD";
  9960. }
  9961. }
  9962. public static function parse_str($str)
  9963. {
  9964. $return = array();
  9965. $str = explode('&', $str);
  9966. foreach ($str as $section)
  9967. {
  9968. if (strpos($section, '=') !== false)
  9969. {
  9970. list($name, $value) = explode('=', $section, 2);
  9971. $return[urldecode($name)][] = urldecode($value);
  9972. }
  9973. else
  9974. {
  9975. $return[urldecode($section)][] = null;
  9976. }
  9977. }
  9978. return $return;
  9979. }
  9980. public static function xml_encoding($data, $registry)
  9981. {
  9982. // UTF-32 Big Endian BOM
  9983. if (substr($data, 0, 4) === "\x00\x00\xFE\xFF")
  9984. {
  9985. $encoding[] = 'UTF-32BE';
  9986. }
  9987. // UTF-32 Little Endian BOM
  9988. elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00")
  9989. {
  9990. $encoding[] = 'UTF-32LE';
  9991. }
  9992. // UTF-16 Big Endian BOM
  9993. elseif (substr($data, 0, 2) === "\xFE\xFF")
  9994. {
  9995. $encoding[] = 'UTF-16BE';
  9996. }
  9997. // UTF-16 Little Endian BOM
  9998. elseif (substr($data, 0, 2) === "\xFF\xFE")
  9999. {
  10000. $encoding[] = 'UTF-16LE';
  10001. }
  10002. // UTF-8 BOM
  10003. elseif (substr($data, 0, 3) === "\xEF\xBB\xBF")
  10004. {
  10005. $encoding[] = 'UTF-8';
  10006. }
  10007. // UTF-32 Big Endian Without BOM
  10008. elseif (substr($data, 0, 20) === "\x00\x00\x00\x3C\x00\x00\x00\x3F\x00\x00\x00\x78\x00\x00\x00\x6D\x00\x00\x00\x6C")
  10009. {
  10010. if ($pos = strpos($data, "\x00\x00\x00\x3F\x00\x00\x00\x3E"))
  10011. {
  10012. $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32BE', 'UTF-8')));
  10013. if ($parser->parse())
  10014. {
  10015. $encoding[] = $parser->encoding;
  10016. }
  10017. }
  10018. $encoding[] = 'UTF-32BE';
  10019. }
  10020. // UTF-32 Little Endian Without BOM
  10021. elseif (substr($data, 0, 20) === "\x3C\x00\x00\x00\x3F\x00\x00\x00\x78\x00\x00\x00\x6D\x00\x00\x00\x6C\x00\x00\x00")
  10022. {
  10023. if ($pos = strpos($data, "\x3F\x00\x00\x00\x3E\x00\x00\x00"))
  10024. {
  10025. $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32LE', 'UTF-8')));
  10026. if ($parser->parse())
  10027. {
  10028. $encoding[] = $parser->encoding;
  10029. }
  10030. }
  10031. $encoding[] = 'UTF-32LE';
  10032. }
  10033. // UTF-16 Big Endian Without BOM
  10034. elseif (substr($data, 0, 10) === "\x00\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C")
  10035. {
  10036. if ($pos = strpos($data, "\x00\x3F\x00\x3E"))
  10037. {
  10038. $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16BE', 'UTF-8')));
  10039. if ($parser->parse())
  10040. {
  10041. $encoding[] = $parser->encoding;
  10042. }
  10043. }
  10044. $encoding[] = 'UTF-16BE';
  10045. }
  10046. // UTF-16 Little Endian Without BOM
  10047. elseif (substr($data, 0, 10) === "\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C\x00")
  10048. {
  10049. if ($pos = strpos($data, "\x3F\x00\x3E\x00"))
  10050. {
  10051. $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16LE', 'UTF-8')));
  10052. if ($parser->parse())
  10053. {
  10054. $encoding[] = $parser->encoding;
  10055. }
  10056. }
  10057. $encoding[] = 'UTF-16LE';
  10058. }
  10059. // US-ASCII (or superset)
  10060. elseif (substr($data, 0, 5) === "\x3C\x3F\x78\x6D\x6C")
  10061. {
  10062. if ($pos = strpos($data, "\x3F\x3E"))
  10063. {
  10064. $parser = $registry->create('XML_Declaration_Parser', array(substr($data, 5, $pos - 5)));
  10065. if ($parser->parse())
  10066. {
  10067. $encoding[] = $parser->encoding;
  10068. }
  10069. }
  10070. $encoding[] = 'UTF-8';
  10071. }
  10072. // Fallback to UTF-8
  10073. else
  10074. {
  10075. $encoding[] = 'UTF-8';
  10076. }
  10077. return $encoding;
  10078. }
  10079. public static function output_javascript()
  10080. {
  10081. if (function_exists('ob_gzhandler'))
  10082. {
  10083. ob_start('ob_gzhandler');
  10084. }
  10085. header('Content-type: text/javascript; charset: UTF-8');
  10086. header('Cache-Control: must-revalidate');
  10087. header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'); // 7 days
  10088. ?>
  10089. function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {
  10090. if (placeholder != '') {
  10091. document.writeln('<embed type="'+type+'" style="cursor:hand; cursor:pointer;" href="'+link+'" src="'+placeholder+'" width="'+width+'" height="'+height+'" autoplay="false" target="myself" controller="false" loop="'+loop+'" scale="aspect" bgcolor="'+bgcolor+'" pluginspage="http://www.apple.com/quicktime/download/"></embed>');
  10092. }
  10093. else {
  10094. document.writeln('<embed type="'+type+'" style="cursor:hand; cursor:pointer;" src="'+link+'" width="'+width+'" height="'+height+'" autoplay="false" target="myself" controller="true" loop="'+loop+'" scale="aspect" bgcolor="'+bgcolor+'" pluginspage="http://www.apple.com/quicktime/download/"></embed>');
  10095. }
  10096. }
  10097. function embed_flash(bgcolor, width, height, link, loop, type) {
  10098. document.writeln('<embed src="'+link+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="'+type+'" quality="high" width="'+width+'" height="'+height+'" bgcolor="'+bgcolor+'" loop="'+loop+'"></embed>');
  10099. }
  10100. function embed_flv(width, height, link, placeholder, loop, player) {
  10101. document.writeln('<embed src="'+player+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="'+width+'" height="'+height+'" wmode="transparent" flashvars="file='+link+'&autostart=false&repeat='+loop+'&showdigits=true&showfsbutton=false"></embed>');
  10102. }
  10103. function embed_wmedia(width, height, link) {
  10104. document.writeln('<embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>');
  10105. }
  10106. <?php
  10107. }
  10108. public static function get_build()
  10109. {
  10110. $root = dirname(dirname(__FILE__));
  10111. if (file_exists($root . '/.git/index'))
  10112. {
  10113. return filemtime($root . '/.git/index');
  10114. }
  10115. elseif (file_exists($root . '/SimplePie'))
  10116. {
  10117. $time = 0;
  10118. foreach (glob($root . '/SimplePie/*.php') as $file)
  10119. {
  10120. if (($mtime = filemtime($file)) > $time)
  10121. {
  10122. $time = $mtime;
  10123. }
  10124. }
  10125. return $time;
  10126. }
  10127. elseif (file_exists(dirname(__FILE__) . '/Core.php'))
  10128. {
  10129. return filemtime(dirname(__FILE__) . '/Core.php');
  10130. }
  10131. else
  10132. {
  10133. return filemtime(__FILE__);
  10134. }
  10135. }
  10136. public static function debug(&$sp)
  10137. {
  10138. $info = 'SimplePie ' . SIMPLEPIE_VERSION . ' Build ' . SIMPLEPIE_BUILD . "\n";
  10139. $info .= 'PHP ' . PHP_VERSION . "\n";
  10140. if ($sp->error() !== null)
  10141. {
  10142. $info .= 'Error occurred: ' . $sp->error() . "\n";
  10143. }
  10144. else
  10145. {
  10146. $info .= "No error found.\n";
  10147. }
  10148. $info .= "Extensions:\n";
  10149. $extensions = array('pcre', 'curl', 'zlib', 'mbstring', 'iconv', 'xmlreader', 'xml');
  10150. foreach ($extensions as $ext)
  10151. {
  10152. if (extension_loaded($ext))
  10153. {
  10154. $info .= " $ext loaded\n";
  10155. switch ($ext)
  10156. {
  10157. case 'pcre':
  10158. $info .= ' Version ' . PCRE_VERSION . "\n";
  10159. break;
  10160. case 'curl':
  10161. $version = curl_version();
  10162. $info .= ' Version ' . $version['version'] . "\n";
  10163. break;
  10164. case 'mbstring':
  10165. $info .= ' Overloading: ' . mb_get_info('func_overload') . "\n";
  10166. break;
  10167. case 'iconv':
  10168. $info .= ' Version ' . ICONV_VERSION . "\n";
  10169. break;
  10170. case 'xml':
  10171. $info .= ' Version ' . LIBXML_DOTTED_VERSION . "\n";
  10172. break;
  10173. }
  10174. }
  10175. else
  10176. {
  10177. $info .= " $ext not loaded\n";
  10178. }
  10179. }
  10180. return $info;
  10181. }
  10182. public static function silence_errors($num, $str)
  10183. {
  10184. // No-op
  10185. }
  10186. }
  10187. class SimplePie_Net_IPv6
  10188. {
  10189. public static function uncompress($ip)
  10190. {
  10191. $c1 = -1;
  10192. $c2 = -1;
  10193. if (substr_count($ip, '::') === 1)
  10194. {
  10195. list($ip1, $ip2) = explode('::', $ip);
  10196. if ($ip1 === '')
  10197. {
  10198. $c1 = -1;
  10199. }
  10200. else
  10201. {
  10202. $c1 = substr_count($ip1, ':');
  10203. }
  10204. if ($ip2 === '')
  10205. {
  10206. $c2 = -1;
  10207. }
  10208. else
  10209. {
  10210. $c2 = substr_count($ip2, ':');
  10211. }
  10212. if (strpos($ip2, '.') !== false)
  10213. {
  10214. $c2++;
  10215. }
  10216. // ::
  10217. if ($c1 === -1 && $c2 === -1)
  10218. {
  10219. $ip = '0:0:0:0:0:0:0:0';
  10220. }
  10221. // ::xxx
  10222. else if ($c1 === -1)
  10223. {
  10224. $fill = str_repeat('0:', 7 - $c2);
  10225. $ip = str_replace('::', $fill, $ip);
  10226. }
  10227. // xxx::
  10228. else if ($c2 === -1)
  10229. {
  10230. $fill = str_repeat(':0', 7 - $c1);
  10231. $ip = str_replace('::', $fill, $ip);
  10232. }
  10233. // xxx::xxx
  10234. else
  10235. {
  10236. $fill = ':' . str_repeat('0:', 6 - $c2 - $c1);
  10237. $ip = str_replace('::', $fill, $ip);
  10238. }
  10239. }
  10240. return $ip;
  10241. }
  10242. public static function compress($ip)
  10243. {
  10244. // Prepare the IP to be compressed
  10245. $ip = self::uncompress($ip);
  10246. $ip_parts = self::split_v6_v4($ip);
  10247. // Replace all leading zeros
  10248. $ip_parts[0] = preg_replace('/(^|:)0+([0-9])/', '\1\2', $ip_parts[0]);
  10249. // Find bunches of zeros
  10250. if (preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE))
  10251. {
  10252. $max = 0;
  10253. $pos = null;
  10254. foreach ($matches[0] as $match)
  10255. {
  10256. if (strlen($match[0]) > $max)
  10257. {
  10258. $max = strlen($match[0]);
  10259. $pos = $match[1];
  10260. }
  10261. }
  10262. $ip_parts[0] = substr_replace($ip_parts[0], '::', $pos, $max);
  10263. }
  10264. if ($ip_parts[1] !== '')
  10265. {
  10266. return implode(':', $ip_parts);
  10267. }
  10268. else
  10269. {
  10270. return $ip_parts[0];
  10271. }
  10272. }
  10273. private static function split_v6_v4($ip)
  10274. {
  10275. if (strpos($ip, '.') !== false)
  10276. {
  10277. $pos = strrpos($ip, ':');
  10278. $ipv6_part = substr($ip, 0, $pos);
  10279. $ipv4_part = substr($ip, $pos + 1);
  10280. return array($ipv6_part, $ipv4_part);
  10281. }
  10282. else
  10283. {
  10284. return array($ip, '');
  10285. }
  10286. }
  10287. public static function check_ipv6($ip)
  10288. {
  10289. $ip = self::uncompress($ip);
  10290. list($ipv6, $ipv4) = self::split_v6_v4($ip);
  10291. $ipv6 = explode(':', $ipv6);
  10292. $ipv4 = explode('.', $ipv4);
  10293. if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4)
  10294. {
  10295. foreach ($ipv6 as $ipv6_part)
  10296. {
  10297. // The section can't be empty
  10298. if ($ipv6_part === '')
  10299. return false;
  10300. // Nor can it be over four characters
  10301. if (strlen($ipv6_part) > 4)
  10302. return false;
  10303. // Remove leading zeros (this is safe because of the above)
  10304. $ipv6_part = ltrim($ipv6_part, '0');
  10305. if ($ipv6_part === '')
  10306. $ipv6_part = '0';
  10307. // Check the value is valid
  10308. $value = hexdec($ipv6_part);
  10309. if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF)
  10310. return false;
  10311. }
  10312. if (count($ipv4) === 4)
  10313. {
  10314. foreach ($ipv4 as $ipv4_part)
  10315. {
  10316. $value = (int) $ipv4_part;
  10317. if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF)
  10318. return false;
  10319. }
  10320. }
  10321. return true;
  10322. }
  10323. else
  10324. {
  10325. return false;
  10326. }
  10327. }
  10328. public static function checkIPv6($ip)
  10329. {
  10330. return self::check_ipv6($ip);
  10331. }
  10332. }
  10333. class SimplePie_Parse_Date
  10334. {
  10335. var $date;
  10336. var $day = array(
  10337. // English
  10338. 'mon' => 1,
  10339. 'monday' => 1,
  10340. 'tue' => 2,
  10341. 'tuesday' => 2,
  10342. 'wed' => 3,
  10343. 'wednesday' => 3,
  10344. 'thu' => 4,
  10345. 'thursday' => 4,
  10346. 'fri' => 5,
  10347. 'friday' => 5,
  10348. 'sat' => 6,
  10349. 'saturday' => 6,
  10350. 'sun' => 7,
  10351. 'sunday' => 7,
  10352. // Dutch
  10353. 'maandag' => 1,
  10354. 'dinsdag' => 2,
  10355. 'woensdag' => 3,
  10356. 'donderdag' => 4,
  10357. 'vrijdag' => 5,
  10358. 'zaterdag' => 6,
  10359. 'zondag' => 7,
  10360. // French
  10361. 'lundi' => 1,
  10362. 'mardi' => 2,
  10363. 'mercredi' => 3,
  10364. 'jeudi' => 4,
  10365. 'vendredi' => 5,
  10366. 'samedi' => 6,
  10367. 'dimanche' => 7,
  10368. // German
  10369. 'montag' => 1,
  10370. 'dienstag' => 2,
  10371. 'mittwoch' => 3,
  10372. 'donnerstag' => 4,
  10373. 'freitag' => 5,
  10374. 'samstag' => 6,
  10375. 'sonnabend' => 6,
  10376. 'sonntag' => 7,
  10377. // Italian
  10378. 'lunedì' => 1,
  10379. 'martedì' => 2,
  10380. 'mercoledì' => 3,
  10381. 'giovedì' => 4,
  10382. 'venerdì' => 5,
  10383. 'sabato' => 6,
  10384. 'domenica' => 7,
  10385. // Spanish
  10386. 'lunes' => 1,
  10387. 'martes' => 2,
  10388. 'miércoles' => 3,
  10389. 'jueves' => 4,
  10390. 'viernes' => 5,
  10391. 'sábado' => 6,
  10392. 'domingo' => 7,
  10393. // Finnish
  10394. 'maanantai' => 1,
  10395. 'tiistai' => 2,
  10396. 'keskiviikko' => 3,
  10397. 'torstai' => 4,
  10398. 'perjantai' => 5,
  10399. 'lauantai' => 6,
  10400. 'sunnuntai' => 7,
  10401. // Hungarian
  10402. 'hétfő' => 1,
  10403. 'kedd' => 2,
  10404. 'szerda' => 3,
  10405. 'csütörtok' => 4,
  10406. 'péntek' => 5,
  10407. 'szombat' => 6,
  10408. 'vasárnap' => 7,
  10409. // Greek
  10410. 'Δευ' => 1,
  10411. 'Τρι' => 2,
  10412. 'Τετ' => 3,
  10413. 'Πεμ' => 4,
  10414. 'Παρ' => 5,
  10415. 'Σαβ' => 6,
  10416. 'Κυρ' => 7,
  10417. );
  10418. var $month = array(
  10419. // English
  10420. 'jan' => 1,
  10421. 'january' => 1,
  10422. 'feb' => 2,
  10423. 'february' => 2,
  10424. 'mar' => 3,
  10425. 'march' => 3,
  10426. 'apr' => 4,
  10427. 'april' => 4,
  10428. 'may' => 5,
  10429. // No long form of May
  10430. 'jun' => 6,
  10431. 'june' => 6,
  10432. 'jul' => 7,
  10433. 'july' => 7,
  10434. 'aug' => 8,
  10435. 'august' => 8,
  10436. 'sep' => 9,
  10437. 'september' => 8,
  10438. 'oct' => 10,
  10439. 'october' => 10,
  10440. 'nov' => 11,
  10441. 'november' => 11,
  10442. 'dec' => 12,
  10443. 'december' => 12,
  10444. // Dutch
  10445. 'januari' => 1,
  10446. 'februari' => 2,
  10447. 'maart' => 3,
  10448. 'april' => 4,
  10449. 'mei' => 5,
  10450. 'juni' => 6,
  10451. 'juli' => 7,
  10452. 'augustus' => 8,
  10453. 'september' => 9,
  10454. 'oktober' => 10,
  10455. 'november' => 11,
  10456. 'december' => 12,
  10457. // French
  10458. 'janvier' => 1,
  10459. 'février' => 2,
  10460. 'mars' => 3,
  10461. 'avril' => 4,
  10462. 'mai' => 5,
  10463. 'juin' => 6,
  10464. 'juillet' => 7,
  10465. 'août' => 8,
  10466. 'septembre' => 9,
  10467. 'octobre' => 10,
  10468. 'novembre' => 11,
  10469. 'décembre' => 12,
  10470. // German
  10471. 'januar' => 1,
  10472. 'februar' => 2,
  10473. 'märz' => 3,
  10474. 'april' => 4,
  10475. 'mai' => 5,
  10476. 'juni' => 6,
  10477. 'juli' => 7,
  10478. 'august' => 8,
  10479. 'september' => 9,
  10480. 'oktober' => 10,
  10481. 'november' => 11,
  10482. 'dezember' => 12,
  10483. // Italian
  10484. 'gennaio' => 1,
  10485. 'febbraio' => 2,
  10486. 'marzo' => 3,
  10487. 'aprile' => 4,
  10488. 'maggio' => 5,
  10489. 'giugno' => 6,
  10490. 'luglio' => 7,
  10491. 'agosto' => 8,
  10492. 'settembre' => 9,
  10493. 'ottobre' => 10,
  10494. 'novembre' => 11,
  10495. 'dicembre' => 12,
  10496. // Spanish
  10497. 'enero' => 1,
  10498. 'febrero' => 2,
  10499. 'marzo' => 3,
  10500. 'abril' => 4,
  10501. 'mayo' => 5,
  10502. 'junio' => 6,
  10503. 'julio' => 7,
  10504. 'agosto' => 8,
  10505. 'septiembre' => 9,
  10506. 'setiembre' => 9,
  10507. 'octubre' => 10,
  10508. 'noviembre' => 11,
  10509. 'diciembre' => 12,
  10510. // Finnish
  10511. 'tammikuu' => 1,
  10512. 'helmikuu' => 2,
  10513. 'maaliskuu' => 3,
  10514. 'huhtikuu' => 4,
  10515. 'toukokuu' => 5,
  10516. 'kesäkuu' => 6,
  10517. 'heinäkuu' => 7,
  10518. 'elokuu' => 8,
  10519. 'suuskuu' => 9,
  10520. 'lokakuu' => 10,
  10521. 'marras' => 11,
  10522. 'joulukuu' => 12,
  10523. // Hungarian
  10524. 'január' => 1,
  10525. 'február' => 2,
  10526. 'március' => 3,
  10527. 'április' => 4,
  10528. 'május' => 5,
  10529. 'június' => 6,
  10530. 'július' => 7,
  10531. 'augusztus' => 8,
  10532. 'szeptember' => 9,
  10533. 'október' => 10,
  10534. 'november' => 11,
  10535. 'december' => 12,
  10536. // Greek
  10537. 'Ιαν' => 1,
  10538. 'Φεβ' => 2,
  10539. 'Μάώ' => 3,
  10540. 'Μαώ' => 3,
  10541. 'Απρ' => 4,
  10542. 'Μάι' => 5,
  10543. 'Μαϊ' => 5,
  10544. 'Μαι' => 5,
  10545. 'Ιούν' => 6,
  10546. 'Ιον' => 6,
  10547. 'Ιούλ' => 7,
  10548. 'Ιολ' => 7,
  10549. 'Αύγ' => 8,
  10550. 'Αυγ' => 8,
  10551. 'Σεπ' => 9,
  10552. 'Οκτ' => 10,
  10553. 'Νοέ' => 11,
  10554. 'Δεκ' => 12,
  10555. );
  10556. var $timezone = array(
  10557. 'ACDT' => 37800,
  10558. 'ACIT' => 28800,
  10559. 'ACST' => 34200,
  10560. 'ACT' => -18000,
  10561. 'ACWDT' => 35100,
  10562. 'ACWST' => 31500,
  10563. 'AEDT' => 39600,
  10564. 'AEST' => 36000,
  10565. 'AFT' => 16200,
  10566. 'AKDT' => -28800,
  10567. 'AKST' => -32400,
  10568. 'AMDT' => 18000,
  10569. 'AMT' => -14400,
  10570. 'ANAST' => 46800,
  10571. 'ANAT' => 43200,
  10572. 'ART' => -10800,
  10573. 'AZOST' => -3600,
  10574. 'AZST' => 18000,
  10575. 'AZT' => 14400,
  10576. 'BIOT' => 21600,
  10577. 'BIT' => -43200,
  10578. 'BOT' => -14400,
  10579. 'BRST' => -7200,
  10580. 'BRT' => -10800,
  10581. 'BST' => 3600,
  10582. 'BTT' => 21600,
  10583. 'CAST' => 18000,
  10584. 'CAT' => 7200,
  10585. 'CCT' => 23400,
  10586. 'CDT' => -18000,
  10587. 'CEDT' => 7200,
  10588. 'CET' => 3600,
  10589. 'CGST' => -7200,
  10590. 'CGT' => -10800,
  10591. 'CHADT' => 49500,
  10592. 'CHAST' => 45900,
  10593. 'CIST' => -28800,
  10594. 'CKT' => -36000,
  10595. 'CLDT' => -10800,
  10596. 'CLST' => -14400,
  10597. 'COT' => -18000,
  10598. 'CST' => -21600,
  10599. 'CVT' => -3600,
  10600. 'CXT' => 25200,
  10601. 'DAVT' => 25200,
  10602. 'DTAT' => 36000,
  10603. 'EADT' => -18000,
  10604. 'EAST' => -21600,
  10605. 'EAT' => 10800,
  10606. 'ECT' => -18000,
  10607. 'EDT' => -14400,
  10608. 'EEST' => 10800,
  10609. 'EET' => 7200,
  10610. 'EGT' => -3600,
  10611. 'EKST' => 21600,
  10612. 'EST' => -18000,
  10613. 'FJT' => 43200,
  10614. 'FKDT' => -10800,
  10615. 'FKST' => -14400,
  10616. 'FNT' => -7200,
  10617. 'GALT' => -21600,
  10618. 'GEDT' => 14400,
  10619. 'GEST' => 10800,
  10620. 'GFT' => -10800,
  10621. 'GILT' => 43200,
  10622. 'GIT' => -32400,
  10623. 'GST' => 14400,
  10624. 'GST' => -7200,
  10625. 'GYT' => -14400,
  10626. 'HAA' => -10800,
  10627. 'HAC' => -18000,
  10628. 'HADT' => -32400,
  10629. 'HAE' => -14400,
  10630. 'HAP' => -25200,
  10631. 'HAR' => -21600,
  10632. 'HAST' => -36000,
  10633. 'HAT' => -9000,
  10634. 'HAY' => -28800,
  10635. 'HKST' => 28800,
  10636. 'HMT' => 18000,
  10637. 'HNA' => -14400,
  10638. 'HNC' => -21600,
  10639. 'HNE' => -18000,
  10640. 'HNP' => -28800,
  10641. 'HNR' => -25200,
  10642. 'HNT' => -12600,
  10643. 'HNY' => -32400,
  10644. 'IRDT' => 16200,
  10645. 'IRKST' => 32400,
  10646. 'IRKT' => 28800,
  10647. 'IRST' => 12600,
  10648. 'JFDT' => -10800,
  10649. 'JFST' => -14400,
  10650. 'JST' => 32400,
  10651. 'KGST' => 21600,
  10652. 'KGT' => 18000,
  10653. 'KOST' => 39600,
  10654. 'KOVST' => 28800,
  10655. 'KOVT' => 25200,
  10656. 'KRAST' => 28800,
  10657. 'KRAT' => 25200,
  10658. 'KST' => 32400,
  10659. 'LHDT' => 39600,
  10660. 'LHST' => 37800,
  10661. 'LINT' => 50400,
  10662. 'LKT' => 21600,
  10663. 'MAGST' => 43200,
  10664. 'MAGT' => 39600,
  10665. 'MAWT' => 21600,
  10666. 'MDT' => -21600,
  10667. 'MESZ' => 7200,
  10668. 'MEZ' => 3600,
  10669. 'MHT' => 43200,
  10670. 'MIT' => -34200,
  10671. 'MNST' => 32400,
  10672. 'MSDT' => 14400,
  10673. 'MSST' => 10800,
  10674. 'MST' => -25200,
  10675. 'MUT' => 14400,
  10676. 'MVT' => 18000,
  10677. 'MYT' => 28800,
  10678. 'NCT' => 39600,
  10679. 'NDT' => -9000,
  10680. 'NFT' => 41400,
  10681. 'NMIT' => 36000,
  10682. 'NOVST' => 25200,
  10683. 'NOVT' => 21600,
  10684. 'NPT' => 20700,
  10685. 'NRT' => 43200,
  10686. 'NST' => -12600,
  10687. 'NUT' => -39600,
  10688. 'NZDT' => 46800,
  10689. 'NZST' => 43200,
  10690. 'OMSST' => 25200,
  10691. 'OMST' => 21600,
  10692. 'PDT' => -25200,
  10693. 'PET' => -18000,
  10694. 'PETST' => 46800,
  10695. 'PETT' => 43200,
  10696. 'PGT' => 36000,
  10697. 'PHOT' => 46800,
  10698. 'PHT' => 28800,
  10699. 'PKT' => 18000,
  10700. 'PMDT' => -7200,
  10701. 'PMST' => -10800,
  10702. 'PONT' => 39600,
  10703. 'PST' => -28800,
  10704. 'PWT' => 32400,
  10705. 'PYST' => -10800,
  10706. 'PYT' => -14400,
  10707. 'RET' => 14400,
  10708. 'ROTT' => -10800,
  10709. 'SAMST' => 18000,
  10710. 'SAMT' => 14400,
  10711. 'SAST' => 7200,
  10712. 'SBT' => 39600,
  10713. 'SCDT' => 46800,
  10714. 'SCST' => 43200,
  10715. 'SCT' => 14400,
  10716. 'SEST' => 3600,
  10717. 'SGT' => 28800,
  10718. 'SIT' => 28800,
  10719. 'SRT' => -10800,
  10720. 'SST' => -39600,
  10721. 'SYST' => 10800,
  10722. 'SYT' => 7200,
  10723. 'TFT' => 18000,
  10724. 'THAT' => -36000,
  10725. 'TJT' => 18000,
  10726. 'TKT' => -36000,
  10727. 'TMT' => 18000,
  10728. 'TOT' => 46800,
  10729. 'TPT' => 32400,
  10730. 'TRUT' => 36000,
  10731. 'TVT' => 43200,
  10732. 'TWT' => 28800,
  10733. 'UYST' => -7200,
  10734. 'UYT' => -10800,
  10735. 'UZT' => 18000,
  10736. 'VET' => -14400,
  10737. 'VLAST' => 39600,
  10738. 'VLAT' => 36000,
  10739. 'VOST' => 21600,
  10740. 'VUT' => 39600,
  10741. 'WAST' => 7200,
  10742. 'WAT' => 3600,
  10743. 'WDT' => 32400,
  10744. 'WEST' => 3600,
  10745. 'WFT' => 43200,
  10746. 'WIB' => 25200,
  10747. 'WIT' => 32400,
  10748. 'WITA' => 28800,
  10749. 'WKST' => 18000,
  10750. 'WST' => 28800,
  10751. 'YAKST' => 36000,
  10752. 'YAKT' => 32400,
  10753. 'YAPT' => 36000,
  10754. 'YEKST' => 21600,
  10755. 'YEKT' => 18000,
  10756. );
  10757. var $day_pcre;
  10758. var $month_pcre;
  10759. var $built_in = array();
  10760. var $user = array();
  10761. public function __construct()
  10762. {
  10763. $this->day_pcre = '(' . implode(array_keys($this->day), '|') . ')';
  10764. $this->month_pcre = '(' . implode(array_keys($this->month), '|') . ')';
  10765. static $cache;
  10766. if (!isset($cache[get_class($this)]))
  10767. {
  10768. $all_methods = get_class_methods($this);
  10769. foreach ($all_methods as $method)
  10770. {
  10771. if (strtolower(substr($method, 0, 5)) === 'date_')
  10772. {
  10773. $cache[get_class($this)][] = $method;
  10774. }
  10775. }
  10776. }
  10777. foreach ($cache[get_class($this)] as $method)
  10778. {
  10779. $this->built_in[] = $method;
  10780. }
  10781. }
  10782. public static function get()
  10783. {
  10784. static $object;
  10785. if (!$object)
  10786. {
  10787. $object = new SimplePie_Parse_Date;
  10788. }
  10789. return $object;
  10790. }
  10791. public function parse($date)
  10792. {
  10793. foreach ($this->user as $method)
  10794. {
  10795. if (($returned = call_user_func($method, $date)) !== false)
  10796. {
  10797. return $returned;
  10798. }
  10799. }
  10800. foreach ($this->built_in as $method)
  10801. {
  10802. if (($returned = call_user_func(array($this, $method), $date)) !== false)
  10803. {
  10804. return $returned;
  10805. }
  10806. }
  10807. return false;
  10808. }
  10809. public function add_callback($callback)
  10810. {
  10811. if (is_callable($callback))
  10812. {
  10813. $this->user[] = $callback;
  10814. }
  10815. else
  10816. {
  10817. trigger_error('User-supplied function must be a valid callback', E_USER_WARNING);
  10818. }
  10819. }
  10820. public function date_w3cdtf($date)
  10821. {
  10822. static $pcre;
  10823. if (!$pcre)
  10824. {
  10825. $year = '([0-9]{4})';
  10826. $month = $day = $hour = $minute = $second = '([0-9]{2})';
  10827. $decimal = '([0-9]*)';
  10828. $zone = '(?:(Z)|([+\-])([0-9]{1,2}):?([0-9]{1,2}))';
  10829. $pcre = '/^' . $year . '(?:-?' . $month . '(?:-?' . $day . '(?:[Tt\x09\x20]+' . $hour . '(?::?' . $minute . '(?::?' . $second . '(?:.' . $decimal . ')?)?)?' . $zone . ')?)?)?$/';
  10830. }
  10831. if (preg_match($pcre, $date, $match))
  10832. {
  10833. /*
  10834. Capturing subpatterns:
  10835. 1: Year
  10836. 2: Month
  10837. 3: Day
  10838. 4: Hour
  10839. 5: Minute
  10840. 6: Second
  10841. 7: Decimal fraction of a second
  10842. 8: Zulu
  10843. 9: Timezone ±
  10844. 10: Timezone hours
  10845. 11: Timezone minutes
  10846. */
  10847. // Fill in empty matches
  10848. for ($i = count($match); $i <= 3; $i++)
  10849. {
  10850. $match[$i] = '1';
  10851. }
  10852. for ($i = count($match); $i <= 7; $i++)
  10853. {
  10854. $match[$i] = '0';
  10855. }
  10856. // Numeric timezone
  10857. if (isset($match[9]) && $match[9] !== '')
  10858. {
  10859. $timezone = $match[10] * 3600;
  10860. $timezone += $match[11] * 60;
  10861. if ($match[9] === '-')
  10862. {
  10863. $timezone = 0 - $timezone;
  10864. }
  10865. }
  10866. else
  10867. {
  10868. $timezone = 0;
  10869. }
  10870. // Convert the number of seconds to an integer, taking decimals into account
  10871. $second = round($match[6] + $match[7] / pow(10, strlen($match[7])));
  10872. return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone;
  10873. }
  10874. else
  10875. {
  10876. return false;
  10877. }
  10878. }
  10879. public function remove_rfc2822_comments($string)
  10880. {
  10881. $string = (string) $string;
  10882. $position = 0;
  10883. $length = strlen($string);
  10884. $depth = 0;
  10885. $output = '';
  10886. while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
  10887. {
  10888. $output .= substr($string, $position, $pos - $position);
  10889. $position = $pos + 1;
  10890. if ($string[$pos - 1] !== '\\')
  10891. {
  10892. $depth++;
  10893. while ($depth && $position < $length)
  10894. {
  10895. $position += strcspn($string, '()', $position);
  10896. if ($string[$position - 1] === '\\')
  10897. {
  10898. $position++;
  10899. continue;
  10900. }
  10901. elseif (isset($string[$position]))
  10902. {
  10903. switch ($string[$position])
  10904. {
  10905. case '(':
  10906. $depth++;
  10907. break;
  10908. case ')':
  10909. $depth--;
  10910. break;
  10911. }
  10912. $position++;
  10913. }
  10914. else
  10915. {
  10916. break;
  10917. }
  10918. }
  10919. }
  10920. else
  10921. {
  10922. $output .= '(';
  10923. }
  10924. }
  10925. $output .= substr($string, $position);
  10926. return $output;
  10927. }
  10928. public function date_rfc2822($date)
  10929. {
  10930. static $pcre;
  10931. if (!$pcre)
  10932. {
  10933. $wsp = '[\x09\x20]';
  10934. $fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)';
  10935. $optional_fws = $fws . '?';
  10936. $day_name = $this->day_pcre;
  10937. $month = $this->month_pcre;
  10938. $day = '([0-9]{1,2})';
  10939. $hour = $minute = $second = '([0-9]{2})';
  10940. $year = '([0-9]{2,4})';
  10941. $num_zone = '([+\-])([0-9]{2})([0-9]{2})';
  10942. $character_zone = '([A-Z]{1,5})';
  10943. $zone = '(?:' . $num_zone . '|' . $character_zone . ')';
  10944. $pcre = '/(?:' . $optional_fws . $day_name . $optional_fws . ',)?' . $optional_fws . $day . $fws . $month . $fws . $year . $fws . $hour . $optional_fws . ':' . $optional_fws . $minute . '(?:' . $optional_fws . ':' . $optional_fws . $second . ')?' . $fws . $zone . '/i';
  10945. }
  10946. if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match))
  10947. {
  10948. /*
  10949. Capturing subpatterns:
  10950. 1: Day name
  10951. 2: Day
  10952. 3: Month
  10953. 4: Year
  10954. 5: Hour
  10955. 6: Minute
  10956. 7: Second
  10957. 8: Timezone ±
  10958. 9: Timezone hours
  10959. 10: Timezone minutes
  10960. 11: Alphabetic timezone
  10961. */
  10962. // Find the month number
  10963. $month = $this->month[strtolower($match[3])];
  10964. // Numeric timezone
  10965. if ($match[8] !== '')
  10966. {
  10967. $timezone = $match[9] * 3600;
  10968. $timezone += $match[10] * 60;
  10969. if ($match[8] === '-')
  10970. {
  10971. $timezone = 0 - $timezone;
  10972. }
  10973. }
  10974. // Character timezone
  10975. elseif (isset($this->timezone[strtoupper($match[11])]))
  10976. {
  10977. $timezone = $this->timezone[strtoupper($match[11])];
  10978. }
  10979. // Assume everything else to be -0000
  10980. else
  10981. {
  10982. $timezone = 0;
  10983. }
  10984. // Deal with 2/3 digit years
  10985. if ($match[4] < 50)
  10986. {
  10987. $match[4] += 2000;
  10988. }
  10989. elseif ($match[4] < 1000)
  10990. {
  10991. $match[4] += 1900;
  10992. }
  10993. // Second is optional, if it is empty set it to zero
  10994. if ($match[7] !== '')
  10995. {
  10996. $second = $match[7];
  10997. }
  10998. else
  10999. {
  11000. $second = 0;
  11001. }
  11002. return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone;
  11003. }
  11004. else
  11005. {
  11006. return false;
  11007. }
  11008. }
  11009. public function date_rfc850($date)
  11010. {
  11011. static $pcre;
  11012. if (!$pcre)
  11013. {
  11014. $space = '[\x09\x20]+';
  11015. $day_name = $this->day_pcre;
  11016. $month = $this->month_pcre;
  11017. $day = '([0-9]{1,2})';
  11018. $year = $hour = $minute = $second = '([0-9]{2})';
  11019. $zone = '([A-Z]{1,5})';
  11020. $pcre = '/^' . $day_name . ',' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i';
  11021. }
  11022. if (preg_match($pcre, $date, $match))
  11023. {
  11024. /*
  11025. Capturing subpatterns:
  11026. 1: Day name
  11027. 2: Day
  11028. 3: Month
  11029. 4: Year
  11030. 5: Hour
  11031. 6: Minute
  11032. 7: Second
  11033. 8: Timezone
  11034. */
  11035. // Month
  11036. $month = $this->month[strtolower($match[3])];
  11037. // Character timezone
  11038. if (isset($this->timezone[strtoupper($match[8])]))
  11039. {
  11040. $timezone = $this->timezone[strtoupper($match[8])];
  11041. }
  11042. // Assume everything else to be -0000
  11043. else
  11044. {
  11045. $timezone = 0;
  11046. }
  11047. // Deal with 2 digit year
  11048. if ($match[4] < 50)
  11049. {
  11050. $match[4] += 2000;
  11051. }
  11052. else
  11053. {
  11054. $match[4] += 1900;
  11055. }
  11056. return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone;
  11057. }
  11058. else
  11059. {
  11060. return false;
  11061. }
  11062. }
  11063. public function date_asctime($date)
  11064. {
  11065. static $pcre;
  11066. if (!$pcre)
  11067. {
  11068. $space = '[\x09\x20]+';
  11069. $wday_name = $this->day_pcre;
  11070. $mon_name = $this->month_pcre;
  11071. $day = '([0-9]{1,2})';
  11072. $hour = $sec = $min = '([0-9]{2})';
  11073. $year = '([0-9]{4})';
  11074. $terminator = '\x0A?\x00?';
  11075. $pcre = '/^' . $wday_name . $space . $mon_name . $space . $day . $space . $hour . ':' . $min . ':' . $sec . $space . $year . $terminator . '$/i';
  11076. }
  11077. if (preg_match($pcre, $date, $match))
  11078. {
  11079. /*
  11080. Capturing subpatterns:
  11081. 1: Day name
  11082. 2: Month
  11083. 3: Day
  11084. 4: Hour
  11085. 5: Minute
  11086. 6: Second
  11087. 7: Year
  11088. */
  11089. $month = $this->month[strtolower($match[2])];
  11090. return gmmktime($match[4], $match[5], $match[6], $month, $match[3], $match[7]);
  11091. }
  11092. else
  11093. {
  11094. return false;
  11095. }
  11096. }
  11097. public function date_strtotime($date)
  11098. {
  11099. $strtotime = strtotime($date);
  11100. if ($strtotime === -1 || $strtotime === false)
  11101. {
  11102. return false;
  11103. }
  11104. else
  11105. {
  11106. return $strtotime;
  11107. }
  11108. }
  11109. }
  11110. class SimplePie_Parser
  11111. {
  11112. var $error_code;
  11113. var $error_string;
  11114. var $current_line;
  11115. var $current_column;
  11116. var $current_byte;
  11117. var $separator = ' ';
  11118. var $namespace = array('');
  11119. var $element = array('');
  11120. var $xml_base = array('');
  11121. var $xml_base_explicit = array(false);
  11122. var $xml_lang = array('');
  11123. var $data = array();
  11124. var $datas = array(array());
  11125. var $current_xhtml_construct = -1;
  11126. var $encoding;
  11127. protected $registry;
  11128. public function set_registry(SimplePie_Registry $registry)
  11129. {
  11130. $this->registry = $registry;
  11131. }
  11132. public function parse(&$data, $encoding)
  11133. {
  11134. // Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
  11135. if (strtoupper($encoding) === 'US-ASCII')
  11136. {
  11137. $this->encoding = 'UTF-8';
  11138. }
  11139. else
  11140. {
  11141. $this->encoding = $encoding;
  11142. }
  11143. // Strip BOM:
  11144. // UTF-32 Big Endian BOM
  11145. if (substr($data, 0, 4) === "\x00\x00\xFE\xFF")
  11146. {
  11147. $data = substr($data, 4);
  11148. }
  11149. // UTF-32 Little Endian BOM
  11150. elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00")
  11151. {
  11152. $data = substr($data, 4);
  11153. }
  11154. // UTF-16 Big Endian BOM
  11155. elseif (substr($data, 0, 2) === "\xFE\xFF")
  11156. {
  11157. $data = substr($data, 2);
  11158. }
  11159. // UTF-16 Little Endian BOM
  11160. elseif (substr($data, 0, 2) === "\xFF\xFE")
  11161. {
  11162. $data = substr($data, 2);
  11163. }
  11164. // UTF-8 BOM
  11165. elseif (substr($data, 0, 3) === "\xEF\xBB\xBF")
  11166. {
  11167. $data = substr($data, 3);
  11168. }
  11169. if (substr($data, 0, 5) === '<?xml' && strspn(substr($data, 5, 1), "\x09\x0A\x0D\x20") && ($pos = strpos($data, '?>')) !== false)
  11170. {
  11171. $declaration = $this->registry->create('XML_Declaration_Parser', array(substr($data, 5, $pos - 5)));
  11172. if ($declaration->parse())
  11173. {
  11174. $data = substr($data, $pos + 2);
  11175. $data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' . $data;
  11176. }
  11177. else
  11178. {
  11179. $this->error_string = 'SimplePie bug! Please report this!';
  11180. return false;
  11181. }
  11182. }
  11183. $return = true;
  11184. static $xml_is_sane = null;
  11185. if ($xml_is_sane === null)
  11186. {
  11187. $parser_check = xml_parser_create();
  11188. xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
  11189. xml_parser_free($parser_check);
  11190. $xml_is_sane = isset($values[0]['value']);
  11191. }
  11192. // Create the parser
  11193. if ($xml_is_sane)
  11194. {
  11195. $xml = xml_parser_create_ns($this->encoding, $this->separator);
  11196. xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
  11197. xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0);
  11198. xml_set_object($xml, $this);
  11199. xml_set_character_data_handler($xml, 'cdata');
  11200. xml_set_element_handler($xml, 'tag_open', 'tag_close');
  11201. // Parse!
  11202. if (!xml_parse($xml, $data, true))
  11203. {
  11204. $this->error_code = xml_get_error_code($xml);
  11205. $this->error_string = xml_error_string($this->error_code);
  11206. $return = false;
  11207. }
  11208. $this->current_line = xml_get_current_line_number($xml);
  11209. $this->current_column = xml_get_current_column_number($xml);
  11210. $this->current_byte = xml_get_current_byte_index($xml);
  11211. xml_parser_free($xml);
  11212. return $return;
  11213. }
  11214. else
  11215. {
  11216. libxml_clear_errors();
  11217. $xml = new XMLReader();
  11218. $xml->xml($data);
  11219. while (@$xml->read())
  11220. {
  11221. switch ($xml->nodeType)
  11222. {
  11223. case constant('XMLReader::END_ELEMENT'):
  11224. if ($xml->namespaceURI !== '')
  11225. {
  11226. $tagName = $xml->namespaceURI . $this->separator . $xml->localName;
  11227. }
  11228. else
  11229. {
  11230. $tagName = $xml->localName;
  11231. }
  11232. $this->tag_close(null, $tagName);
  11233. break;
  11234. case constant('XMLReader::ELEMENT'):
  11235. $empty = $xml->isEmptyElement;
  11236. if ($xml->namespaceURI !== '')
  11237. {
  11238. $tagName = $xml->namespaceURI . $this->separator . $xml->localName;
  11239. }
  11240. else
  11241. {
  11242. $tagName = $xml->localName;
  11243. }
  11244. $attributes = array();
  11245. while ($xml->moveToNextAttribute())
  11246. {
  11247. if ($xml->namespaceURI !== '')
  11248. {
  11249. $attrName = $xml->namespaceURI . $this->separator . $xml->localName;
  11250. }
  11251. else
  11252. {
  11253. $attrName = $xml->localName;
  11254. }
  11255. $attributes[$attrName] = $xml->value;
  11256. }
  11257. $this->tag_open(null, $tagName, $attributes);
  11258. if ($empty)
  11259. {
  11260. $this->tag_close(null, $tagName);
  11261. }
  11262. break;
  11263. case constant('XMLReader::TEXT'):
  11264. case constant('XMLReader::CDATA'):
  11265. $this->cdata(null, $xml->value);
  11266. break;
  11267. }
  11268. }
  11269. if ($error = libxml_get_last_error())
  11270. {
  11271. $this->error_code = $error->code;
  11272. $this->error_string = $error->message;
  11273. $this->current_line = $error->line;
  11274. $this->current_column = $error->column;
  11275. return false;
  11276. }
  11277. else
  11278. {
  11279. return true;
  11280. }
  11281. }
  11282. }
  11283. public function get_error_code()
  11284. {
  11285. return $this->error_code;
  11286. }
  11287. public function get_error_string()
  11288. {
  11289. return $this->error_string;
  11290. }
  11291. public function get_current_line()
  11292. {
  11293. return $this->current_line;
  11294. }
  11295. public function get_current_column()
  11296. {
  11297. return $this->current_column;
  11298. }
  11299. public function get_current_byte()
  11300. {
  11301. return $this->current_byte;
  11302. }
  11303. public function get_data()
  11304. {
  11305. return $this->data;
  11306. }
  11307. public function tag_open($parser, $tag, $attributes)
  11308. {
  11309. list($this->namespace[], $this->element[]) = $this->split_ns($tag);
  11310. $attribs = array();
  11311. foreach ($attributes as $name => $value)
  11312. {
  11313. list($attrib_namespace, $attribute) = $this->split_ns($name);
  11314. $attribs[$attrib_namespace][$attribute] = $value;
  11315. }
  11316. if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['base']))
  11317. {
  11318. $this->xml_base[] = $this->registry->call('Misc', 'absolutize_url', array($attribs[SIMPLEPIE_NAMESPACE_XML]['base'], end($this->xml_base)));
  11319. $this->xml_base_explicit[] = true;
  11320. }
  11321. else
  11322. {
  11323. $this->xml_base[] = end($this->xml_base);
  11324. $this->xml_base_explicit[] = end($this->xml_base_explicit);
  11325. }
  11326. if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['lang']))
  11327. {
  11328. $this->xml_lang[] = $attribs[SIMPLEPIE_NAMESPACE_XML]['lang'];
  11329. }
  11330. else
  11331. {
  11332. $this->xml_lang[] = end($this->xml_lang);
  11333. }
  11334. if ($this->current_xhtml_construct >= 0)
  11335. {
  11336. $this->current_xhtml_construct++;
  11337. if (end($this->namespace) === SIMPLEPIE_NAMESPACE_XHTML)
  11338. {
  11339. $this->data['data'] .= '<' . end($this->element);
  11340. if (isset($attribs['']))
  11341. {
  11342. foreach ($attribs[''] as $name => $value)
  11343. {
  11344. $this->data['data'] .= ' ' . $name . '="' . htmlspecialchars($value, ENT_COMPAT, $this->encoding) . '"';
  11345. }
  11346. }
  11347. $this->data['data'] .= '>';
  11348. }
  11349. }
  11350. else
  11351. {
  11352. $this->datas[] =& $this->data;
  11353. $this->data =& $this->data['child'][end($this->namespace)][end($this->element)][];
  11354. $this->data = array('data' => '', 'attribs' => $attribs, 'xml_base' => end($this->xml_base), 'xml_base_explicit' => end($this->xml_base_explicit), 'xml_lang' => end($this->xml_lang));
  11355. if ((end($this->namespace) === SIMPLEPIE_NAMESPACE_ATOM_03 && in_array(end($this->element), array('title', 'tagline', 'copyright', 'info', 'summary', 'content')) && isset($attribs['']['mode']) && $attribs['']['mode'] === 'xml')
  11356. || (end($this->namespace) === SIMPLEPIE_NAMESPACE_ATOM_10 && in_array(end($this->element), array('rights', 'subtitle', 'summary', 'info', 'title', 'content')) && isset($attribs['']['type']) && $attribs['']['type'] === 'xhtml')
  11357. || (end($this->namespace) === SIMPLEPIE_NAMESPACE_RSS_20 && in_array(end($this->element), array('title')))
  11358. || (end($this->namespace) === SIMPLEPIE_NAMESPACE_RSS_090 && in_array(end($this->element), array('title')))
  11359. || (end($this->namespace) === SIMPLEPIE_NAMESPACE_RSS_10 && in_array(end($this->element), array('title'))))
  11360. {
  11361. $this->current_xhtml_construct = 0;
  11362. }
  11363. }
  11364. }
  11365. public function cdata($parser, $cdata)
  11366. {
  11367. if ($this->current_xhtml_construct >= 0)
  11368. {
  11369. $this->data['data'] .= htmlspecialchars($cdata, ENT_QUOTES, $this->encoding);
  11370. }
  11371. else
  11372. {
  11373. $this->data['data'] .= $cdata;
  11374. }
  11375. }
  11376. public function tag_close($parser, $tag)
  11377. {
  11378. if ($this->current_xhtml_construct >= 0)
  11379. {
  11380. $this->current_xhtml_construct--;
  11381. if (end($this->namespace) === SIMPLEPIE_NAMESPACE_XHTML && !in_array(end($this->element), array('area', 'base', 'basefont', 'br', 'col', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param')))
  11382. {
  11383. $this->data['data'] .= '</' . end($this->element) . '>';
  11384. }
  11385. }
  11386. if ($this->current_xhtml_construct === -1)
  11387. {
  11388. $this->data =& $this->datas[count($this->datas) - 1];
  11389. array_pop($this->datas);
  11390. }
  11391. array_pop($this->element);
  11392. array_pop($this->namespace);
  11393. array_pop($this->xml_base);
  11394. array_pop($this->xml_base_explicit);
  11395. array_pop($this->xml_lang);
  11396. }
  11397. public function split_ns($string)
  11398. {
  11399. static $cache = array();
  11400. if (!isset($cache[$string]))
  11401. {
  11402. if ($pos = strpos($string, $this->separator))
  11403. {
  11404. static $separator_length;
  11405. if (!$separator_length)
  11406. {
  11407. $separator_length = strlen($this->separator);
  11408. }
  11409. $namespace = substr($string, 0, $pos);
  11410. $local_name = substr($string, $pos + $separator_length);
  11411. if (strtolower($namespace) === SIMPLEPIE_NAMESPACE_ITUNES)
  11412. {
  11413. $namespace = SIMPLEPIE_NAMESPACE_ITUNES;
  11414. }
  11415. // Normalize the Media RSS namespaces
  11416. if ($namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG ||
  11417. $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2 ||
  11418. $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3 ||
  11419. $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4 ||
  11420. $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5 )
  11421. {
  11422. $namespace = SIMPLEPIE_NAMESPACE_MEDIARSS;
  11423. }
  11424. $cache[$string] = array($namespace, $local_name);
  11425. }
  11426. else
  11427. {
  11428. $cache[$string] = array('', $string);
  11429. }
  11430. }
  11431. return $cache[$string];
  11432. }
  11433. }
  11434. class SimplePie_Rating
  11435. {
  11436. var $scheme;
  11437. var $value;
  11438. public function __construct($scheme = null, $value = null)
  11439. {
  11440. $this->scheme = $scheme;
  11441. $this->value = $value;
  11442. }
  11443. public function __toString()
  11444. {
  11445. // There is no $this->data here
  11446. return md5(serialize($this));
  11447. }
  11448. public function get_scheme()
  11449. {
  11450. if ($this->scheme !== null)
  11451. {
  11452. return $this->scheme;
  11453. }
  11454. else
  11455. {
  11456. return null;
  11457. }
  11458. }
  11459. public function get_value()
  11460. {
  11461. if ($this->value !== null)
  11462. {
  11463. return $this->value;
  11464. }
  11465. else
  11466. {
  11467. return null;
  11468. }
  11469. }
  11470. }
  11471. class SimplePie_Registry
  11472. {
  11473. protected $default = array(
  11474. 'Cache' => 'SimplePie_Cache',
  11475. 'Locator' => 'SimplePie_Locator',
  11476. 'Parser' => 'SimplePie_Parser',
  11477. 'File' => 'SimplePie_File',
  11478. 'Sanitize' => 'SimplePie_Sanitize',
  11479. 'Item' => 'SimplePie_Item',
  11480. 'Author' => 'SimplePie_Author',
  11481. 'Category' => 'SimplePie_Category',
  11482. 'Enclosure' => 'SimplePie_Enclosure',
  11483. 'Caption' => 'SimplePie_Caption',
  11484. 'Copyright' => 'SimplePie_Copyright',
  11485. 'Credit' => 'SimplePie_Credit',
  11486. 'Rating' => 'SimplePie_Rating',
  11487. 'Restriction' => 'SimplePie_Restriction',
  11488. 'Content_Type_Sniffer' => 'SimplePie_Content_Type_Sniffer',
  11489. 'Source' => 'SimplePie_Source',
  11490. 'Misc' => 'SimplePie_Misc',
  11491. 'XML_Declaration_Parser' => 'SimplePie_XML_Declaration_Parser',
  11492. 'Parse_Date' => 'SimplePie_Parse_Date',
  11493. );
  11494. protected $classes = array();
  11495. protected $legacy = array();
  11496. public function __construct() { }
  11497. public function register($type, $class, $legacy = false)
  11498. {
  11499. if (!is_subclass_of($class, $this->default[$type]))
  11500. {
  11501. return false;
  11502. }
  11503. $this->classes[$type] = $class;
  11504. if ($legacy)
  11505. {
  11506. $this->legacy[] = $class;
  11507. }
  11508. return true;
  11509. }
  11510. public function get_class($type)
  11511. {
  11512. if (!empty($this->classes[$type]))
  11513. {
  11514. return $this->classes[$type];
  11515. }
  11516. if (!empty($this->default[$type]))
  11517. {
  11518. return $this->default[$type];
  11519. }
  11520. return null;
  11521. }
  11522. public function &create($type, $parameters = array())
  11523. {
  11524. $class = $this->get_class($type);
  11525. if (in_array($class, $this->legacy))
  11526. {
  11527. switch ($type)
  11528. {
  11529. case 'locator':
  11530. // Legacy: file, timeout, useragent, file_class, max_checked_feeds, content_type_sniffer_class
  11531. // Specified: file, timeout, useragent, max_checked_feeds
  11532. $replacement = array($this->get_class('file'), $parameters[3], $this->get_class('content_type_sniffer'));
  11533. array_splice($parameters, 3, 1, $replacement);
  11534. break;
  11535. }
  11536. }
  11537. if (!method_exists($class, '__construct'))
  11538. {
  11539. $instance = new $class;
  11540. }
  11541. else
  11542. {
  11543. $reflector = new ReflectionClass($class);
  11544. $instance = $reflector->newInstanceArgs($parameters);
  11545. }
  11546. if (method_exists($instance, 'set_registry'))
  11547. {
  11548. $instance->set_registry($this);
  11549. }
  11550. return $instance;
  11551. }
  11552. public function &call($type, $method, $parameters = array())
  11553. {
  11554. $class = $this->get_class($type);
  11555. $result = call_user_func_array(array($class, $method), $parameters);
  11556. return $result;
  11557. }
  11558. }
  11559. class SimplePie_Restriction
  11560. {
  11561. var $relationship;
  11562. var $type;
  11563. var $value;
  11564. public function __construct($relationship = null, $type = null, $value = null)
  11565. {
  11566. $this->relationship = $relationship;
  11567. $this->type = $type;
  11568. $this->value = $value;
  11569. }
  11570. public function __toString()
  11571. {
  11572. // There is no $this->data here
  11573. return md5(serialize($this));
  11574. }
  11575. public function get_relationship()
  11576. {
  11577. if ($this->relationship !== null)
  11578. {
  11579. return $this->relationship;
  11580. }
  11581. else
  11582. {
  11583. return null;
  11584. }
  11585. }
  11586. public function get_type()
  11587. {
  11588. if ($this->type !== null)
  11589. {
  11590. return $this->type;
  11591. }
  11592. else
  11593. {
  11594. return null;
  11595. }
  11596. }
  11597. public function get_value()
  11598. {
  11599. if ($this->value !== null)
  11600. {
  11601. return $this->value;
  11602. }
  11603. else
  11604. {
  11605. return null;
  11606. }
  11607. }
  11608. }
  11609. class SimplePie_Sanitize
  11610. {
  11611. // Private vars
  11612. var $base;
  11613. // Options
  11614. var $remove_div = true;
  11615. var $image_handler = '';
  11616. var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  11617. var $encode_instead_of_strip = false;
  11618. var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
  11619. var $strip_comments = false;
  11620. var $output_encoding = 'UTF-8';
  11621. var $enable_cache = true;
  11622. var $cache_location = './cache';
  11623. var $cache_name_function = 'md5';
  11624. var $timeout = 10;
  11625. var $useragent = '';
  11626. var $force_fsockopen = false;
  11627. var $replace_url_attributes = null;
  11628. public function __construct()
  11629. {
  11630. // Set defaults
  11631. $this->set_url_replacements(null);
  11632. }
  11633. public function remove_div($enable = true)
  11634. {
  11635. $this->remove_div = (bool) $enable;
  11636. }
  11637. public function set_image_handler($page = false)
  11638. {
  11639. if ($page)
  11640. {
  11641. $this->image_handler = (string) $page;
  11642. }
  11643. else
  11644. {
  11645. $this->image_handler = false;
  11646. }
  11647. }
  11648. public function set_registry(SimplePie_Registry $registry)
  11649. {
  11650. $this->registry = $registry;
  11651. }
  11652. public function pass_cache_data($enable_cache = true, $cache_location = './cache', $cache_name_function = 'md5', $cache_class = 'SimplePie_Cache')
  11653. {
  11654. if (isset($enable_cache))
  11655. {
  11656. $this->enable_cache = (bool) $enable_cache;
  11657. }
  11658. if ($cache_location)
  11659. {
  11660. $this->cache_location = (string) $cache_location;
  11661. }
  11662. if ($cache_name_function)
  11663. {
  11664. $this->cache_name_function = (string) $cache_name_function;
  11665. }
  11666. }
  11667. public function pass_file_data($file_class = 'SimplePie_File', $timeout = 10, $useragent = '', $force_fsockopen = false)
  11668. {
  11669. if ($timeout)
  11670. {
  11671. $this->timeout = (string) $timeout;
  11672. }
  11673. if ($useragent)
  11674. {
  11675. $this->useragent = (string) $useragent;
  11676. }
  11677. if ($force_fsockopen)
  11678. {
  11679. $this->force_fsockopen = (string) $force_fsockopen;
  11680. }
  11681. }
  11682. public function strip_htmltags($tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'))
  11683. {
  11684. if ($tags)
  11685. {
  11686. if (is_array($tags))
  11687. {
  11688. $this->strip_htmltags = $tags;
  11689. }
  11690. else
  11691. {
  11692. $this->strip_htmltags = explode(',', $tags);
  11693. }
  11694. }
  11695. else
  11696. {
  11697. $this->strip_htmltags = false;
  11698. }
  11699. }
  11700. public function encode_instead_of_strip($encode = false)
  11701. {
  11702. $this->encode_instead_of_strip = (bool) $encode;
  11703. }
  11704. public function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'))
  11705. {
  11706. if ($attribs)
  11707. {
  11708. if (is_array($attribs))
  11709. {
  11710. $this->strip_attributes = $attribs;
  11711. }
  11712. else
  11713. {
  11714. $this->strip_attributes = explode(',', $attribs);
  11715. }
  11716. }
  11717. else
  11718. {
  11719. $this->strip_attributes = false;
  11720. }
  11721. }
  11722. public function strip_comments($strip = false)
  11723. {
  11724. $this->strip_comments = (bool) $strip;
  11725. }
  11726. public function set_output_encoding($encoding = 'UTF-8')
  11727. {
  11728. $this->output_encoding = (string) $encoding;
  11729. }
  11730. public function set_url_replacements($element_attribute = null)
  11731. {
  11732. if ($element_attribute === null)
  11733. {
  11734. $element_attribute = array(
  11735. 'a' => 'href',
  11736. 'area' => 'href',
  11737. 'blockquote' => 'cite',
  11738. 'del' => 'cite',
  11739. 'form' => 'action',
  11740. 'img' => array(
  11741. 'longdesc',
  11742. 'src'
  11743. ),
  11744. 'input' => 'src',
  11745. 'ins' => 'cite',
  11746. 'q' => 'cite'
  11747. );
  11748. }
  11749. $this->replace_url_attributes = (array) $element_attribute;
  11750. }
  11751. public function sanitize($data, $type, $base = '')
  11752. {
  11753. $data = trim($data);
  11754. if ($data !== '' || $type & SIMPLEPIE_CONSTRUCT_IRI)
  11755. {
  11756. if ($type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML)
  11757. {
  11758. if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data))
  11759. {
  11760. $type |= SIMPLEPIE_CONSTRUCT_HTML;
  11761. }
  11762. else
  11763. {
  11764. $type |= SIMPLEPIE_CONSTRUCT_TEXT;
  11765. }
  11766. }
  11767. if ($type & SIMPLEPIE_CONSTRUCT_BASE64)
  11768. {
  11769. $data = base64_decode($data);
  11770. }
  11771. if ($type & (SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML))
  11772. {
  11773. $document = new DOMDocument();
  11774. $document->encoding = 'UTF-8';
  11775. $data = $this->preprocess($data, $type);
  11776. set_error_handler(array('SimplePie_Misc', 'silence_errors'));
  11777. $document->loadHTML($data);
  11778. restore_error_handler();
  11779. // Strip comments
  11780. if ($this->strip_comments)
  11781. {
  11782. $xpath = new DOMXPath($document);
  11783. $comments = $xpath->query('//comment()');
  11784. foreach ($comments as $comment)
  11785. {
  11786. $comment->parentNode->removeChild($comment);
  11787. }
  11788. }
  11789. // Strip out HTML tags and attributes that might cause various security problems.
  11790. // Based on recommendations by Mark Pilgrim at:
  11791. // http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely
  11792. if ($this->strip_htmltags)
  11793. {
  11794. foreach ($this->strip_htmltags as $tag)
  11795. {
  11796. $this->strip_tag($tag, $document, $type);
  11797. }
  11798. }
  11799. if ($this->strip_attributes)
  11800. {
  11801. foreach ($this->strip_attributes as $attrib)
  11802. {
  11803. $this->strip_attr($attrib, $document);
  11804. }
  11805. }
  11806. // Replace relative URLs
  11807. $this->base = $base;
  11808. foreach ($this->replace_url_attributes as $element => $attributes)
  11809. {
  11810. $this->replace_urls($document, $element, $attributes);
  11811. }
  11812. // If image handling (caching, etc.) is enabled, cache and rewrite all the image tags.
  11813. if (isset($this->image_handler) && ((string) $this->image_handler) !== '' && $this->enable_cache)
  11814. {
  11815. $images = $document->getElementsByTagName('img');
  11816. foreach ($images as $img)
  11817. {
  11818. if ($img->hasAttribute('src'))
  11819. {
  11820. $image_url = call_user_func($this->cache_name_function, $img->getAttribute('src'));
  11821. $cache = $this->registry->call('Cache', 'create', array($this->cache_location, $image_url, 'spi'));
  11822. if ($cache->load())
  11823. {
  11824. $img->setAttribute('src', $this->image_handler . $image_url);
  11825. }
  11826. else
  11827. {
  11828. $file = $this->registry->create('File', array($img['attribs']['src']['data'], $this->timeout, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen));
  11829. $headers = $file->headers;
  11830. if ($file->success && ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
  11831. {
  11832. if ($cache->save(array('headers' => $file->headers, 'body' => $file->body)))
  11833. {
  11834. $img->setAttribute('src', $this->image_handler . $image_url);
  11835. }
  11836. else
  11837. {
  11838. 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);
  11839. }
  11840. }
  11841. }
  11842. }
  11843. }
  11844. }
  11845. // Remove the DOCTYPE
  11846. // Seems to cause segfaulting if we don't do this
  11847. if ($document->firstChild instanceof DOMDocumentType)
  11848. {
  11849. $document->removeChild($document->firstChild);
  11850. }
  11851. // Move everything from the body to the root
  11852. $real_body = $document->getElementsByTagName('body')->item(0)->childNodes->item(0);
  11853. $document->replaceChild($real_body, $document->firstChild);
  11854. // Finally, convert to a HTML string
  11855. $data = trim($document->saveHTML());
  11856. if ($this->remove_div)
  11857. {
  11858. $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '', $data);
  11859. $data = preg_replace('/<\/div>$/', '', $data);
  11860. }
  11861. else
  11862. {
  11863. $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '<div>', $data);
  11864. }
  11865. }
  11866. if ($type & SIMPLEPIE_CONSTRUCT_IRI)
  11867. {
  11868. $data = $this->registry->call('Misc', 'absolutize_url', array($data, $base));
  11869. }
  11870. if ($type & (SIMPLEPIE_CONSTRUCT_TEXT | SIMPLEPIE_CONSTRUCT_IRI))
  11871. {
  11872. $data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
  11873. }
  11874. if ($this->output_encoding !== 'UTF-8')
  11875. {
  11876. $data = $this->registry->call('Misc', 'change_encoding', array($data, 'UTF-8', $this->output_encoding));
  11877. }
  11878. }
  11879. return $data;
  11880. }
  11881. protected function preprocess($html, $type)
  11882. {
  11883. $ret = '';
  11884. if ($type & ~SIMPLEPIE_CONSTRUCT_XHTML)
  11885. {
  11886. // Atom XHTML constructs are wrapped with a div by default
  11887. // Note: No protection if $html contains a stray </div>!
  11888. $html = '<div>' . $html . '</div>';
  11889. $ret .= '<!DOCTYPE html>';
  11890. $content_type = 'text/html';
  11891. }
  11892. else
  11893. {
  11894. $ret .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
  11895. $content_type = 'application/xhtml+xml';
  11896. }
  11897. $ret .= '<html><head>';
  11898. $ret .= '<meta http-equiv="Content-Type" content="' . $content_type . '; charset=utf-8" />';
  11899. $ret .= '</head><body>' . $html . '</body></html>';
  11900. return $ret;
  11901. }
  11902. public function replace_urls($document, $tag, $attributes)
  11903. {
  11904. if (!is_array($attributes))
  11905. {
  11906. $attributes = array($attributes);
  11907. }
  11908. if (!is_array($this->strip_htmltags) || !in_array($tag, $this->strip_htmltags))
  11909. {
  11910. $elements = $document->getElementsByTagName($tag);
  11911. foreach ($elements as $element)
  11912. {
  11913. foreach ($attributes as $attribute)
  11914. {
  11915. if ($element->hasAttribute($attribute))
  11916. {
  11917. $value = $this->registry->call('Misc', 'absolutize_url', array($element->getAttribute($attribute), $this->base));
  11918. $element->setAttribute($attribute, $value);
  11919. }
  11920. }
  11921. }
  11922. }
  11923. }
  11924. public function do_strip_htmltags($match)
  11925. {
  11926. if ($this->encode_instead_of_strip)
  11927. {
  11928. if (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
  11929. {
  11930. $match[1] = htmlspecialchars($match[1], ENT_COMPAT, 'UTF-8');
  11931. $match[2] = htmlspecialchars($match[2], ENT_COMPAT, 'UTF-8');
  11932. return "&lt;$match[1]$match[2]&gt;$match[3]&lt;/$match[1]&gt;";
  11933. }
  11934. else
  11935. {
  11936. return htmlspecialchars($match[0], ENT_COMPAT, 'UTF-8');
  11937. }
  11938. }
  11939. elseif (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
  11940. {
  11941. return $match[4];
  11942. }
  11943. else
  11944. {
  11945. return '';
  11946. }
  11947. }
  11948. protected function strip_tag($tag, $document, $type)
  11949. {
  11950. $xpath = new DOMXPath($document);
  11951. $elements = $xpath->query('body//' . $tag);
  11952. if ($this->encode_instead_of_strip)
  11953. {
  11954. foreach ($elements as $element)
  11955. {
  11956. $fragment = $document->createDocumentFragment();
  11957. // For elements which aren't script or style, include the tag itself
  11958. if (!in_array($tag, array('script', 'style')))
  11959. {
  11960. $text = '<' . $tag;
  11961. if ($element->hasAttributes())
  11962. {
  11963. $attrs = array();
  11964. foreach ($element->attributes as $name => $attr)
  11965. {
  11966. $value = $attr->value;
  11967. // In XHTML, empty values should never exist, so we repeat the value
  11968. if (empty($value) && ($type & SIMPLEPIE_CONSTRUCT_XHTML))
  11969. {
  11970. $value = $name;
  11971. }
  11972. // For HTML, empty is fine
  11973. elseif (empty($value) && ($type & SIMPLEPIE_CONSTRUCT_HTML))
  11974. {
  11975. $attrs[] = $name;
  11976. continue;
  11977. }
  11978. // Standard attribute text
  11979. $attrs[] = $name . '="' . $attr->value . '"';
  11980. }
  11981. $text .= ' ' . implode(' ', $attrs);
  11982. }
  11983. $text .= '>';
  11984. $fragment->appendChild(new DOMText($text));
  11985. }
  11986. $number = $element->childNodes->length;
  11987. for ($i = $number; $i > 0; $i--)
  11988. {
  11989. $child = $element->childNodes->item(0);
  11990. $fragment->appendChild($child);
  11991. }
  11992. if (!in_array($tag, array('script', 'style')))
  11993. {
  11994. $fragment->appendChild(new DOMText('</' . $tag . '>'));
  11995. }
  11996. $element->parentNode->replaceChild($fragment, $element);
  11997. }
  11998. return;
  11999. }
  12000. elseif (in_array($tag, array('script', 'style')))
  12001. {
  12002. foreach ($elements as $element)
  12003. {
  12004. $element->parentNode->removeChild($element);
  12005. }
  12006. return;
  12007. }
  12008. else
  12009. {
  12010. foreach ($elements as $element)
  12011. {
  12012. $fragment = $document->createDocumentFragment();
  12013. $number = $element->childNodes->length;
  12014. for ($i = $number; $i > 0; $i--)
  12015. {
  12016. $child = $element->childNodes->item(0);
  12017. $fragment->appendChild($child);
  12018. }
  12019. $element->parentNode->replaceChild($fragment, $element);
  12020. }
  12021. }
  12022. }
  12023. protected function strip_attr($attrib, $document)
  12024. {
  12025. $xpath = new DOMXPath($document);
  12026. $elements = $xpath->query('//*[@' . $attrib . ']');
  12027. foreach ($elements as $element)
  12028. {
  12029. $element->removeAttribute($attrib);
  12030. }
  12031. }
  12032. }
  12033. class SimplePie_Source
  12034. {
  12035. var $item;
  12036. var $data = array();
  12037. protected $registry;
  12038. public function __construct($item, $data)
  12039. {
  12040. $this->item = $item;
  12041. $this->data = $data;
  12042. }
  12043. public function set_registry(SimplePie_Registry $registry)
  12044. {
  12045. $this->registry = $registry;
  12046. }
  12047. public function __toString()
  12048. {
  12049. return md5(serialize($this->data));
  12050. }
  12051. public function get_source_tags($namespace, $tag)
  12052. {
  12053. if (isset($this->data['child'][$namespace][$tag]))
  12054. {
  12055. return $this->data['child'][$namespace][$tag];
  12056. }
  12057. else
  12058. {
  12059. return null;
  12060. }
  12061. }
  12062. public function get_base($element = array())
  12063. {
  12064. return $this->item->get_base($element);
  12065. }
  12066. public function sanitize($data, $type, $base = '')
  12067. {
  12068. return $this->item->sanitize($data, $type, $base);
  12069. }
  12070. public function get_item()
  12071. {
  12072. return $this->item;
  12073. }
  12074. public function get_title()
  12075. {
  12076. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  12077. {
  12078. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  12079. }
  12080. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  12081. {
  12082. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  12083. }
  12084. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  12085. {
  12086. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  12087. }
  12088. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  12089. {
  12090. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  12091. }
  12092. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  12093. {
  12094. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  12095. }
  12096. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  12097. {
  12098. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12099. }
  12100. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  12101. {
  12102. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12103. }
  12104. else
  12105. {
  12106. return null;
  12107. }
  12108. }
  12109. public function get_category($key = 0)
  12110. {
  12111. $categories = $this->get_categories();
  12112. if (isset($categories[$key]))
  12113. {
  12114. return $categories[$key];
  12115. }
  12116. else
  12117. {
  12118. return null;
  12119. }
  12120. }
  12121. public function get_categories()
  12122. {
  12123. $categories = array();
  12124. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  12125. {
  12126. $term = null;
  12127. $scheme = null;
  12128. $label = null;
  12129. if (isset($category['attribs']['']['term']))
  12130. {
  12131. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  12132. }
  12133. if (isset($category['attribs']['']['scheme']))
  12134. {
  12135. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  12136. }
  12137. if (isset($category['attribs']['']['label']))
  12138. {
  12139. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  12140. }
  12141. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  12142. }
  12143. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
  12144. {
  12145. // This is really the label, but keep this as the term also for BC.
  12146. // Label will also work on retrieving because that falls back to term.
  12147. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12148. if (isset($category['attribs']['']['domain']))
  12149. {
  12150. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  12151. }
  12152. else
  12153. {
  12154. $scheme = null;
  12155. }
  12156. $categories[] = $this->registry->create('Category', array($term, $scheme, null));
  12157. }
  12158. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  12159. {
  12160. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  12161. }
  12162. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  12163. {
  12164. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  12165. }
  12166. if (!empty($categories))
  12167. {
  12168. return array_unique($categories);
  12169. }
  12170. else
  12171. {
  12172. return null;
  12173. }
  12174. }
  12175. public function get_author($key = 0)
  12176. {
  12177. $authors = $this->get_authors();
  12178. if (isset($authors[$key]))
  12179. {
  12180. return $authors[$key];
  12181. }
  12182. else
  12183. {
  12184. return null;
  12185. }
  12186. }
  12187. public function get_authors()
  12188. {
  12189. $authors = array();
  12190. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  12191. {
  12192. $name = null;
  12193. $uri = null;
  12194. $email = null;
  12195. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  12196. {
  12197. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12198. }
  12199. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  12200. {
  12201. $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]));
  12202. }
  12203. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  12204. {
  12205. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12206. }
  12207. if ($name !== null || $email !== null || $uri !== null)
  12208. {
  12209. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  12210. }
  12211. }
  12212. if ($author = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  12213. {
  12214. $name = null;
  12215. $url = null;
  12216. $email = null;
  12217. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  12218. {
  12219. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12220. }
  12221. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  12222. {
  12223. $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]));
  12224. }
  12225. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  12226. {
  12227. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12228. }
  12229. if ($name !== null || $email !== null || $url !== null)
  12230. {
  12231. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  12232. }
  12233. }
  12234. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  12235. {
  12236. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  12237. }
  12238. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  12239. {
  12240. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  12241. }
  12242. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  12243. {
  12244. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  12245. }
  12246. if (!empty($authors))
  12247. {
  12248. return array_unique($authors);
  12249. }
  12250. else
  12251. {
  12252. return null;
  12253. }
  12254. }
  12255. public function get_contributor($key = 0)
  12256. {
  12257. $contributors = $this->get_contributors();
  12258. if (isset($contributors[$key]))
  12259. {
  12260. return $contributors[$key];
  12261. }
  12262. else
  12263. {
  12264. return null;
  12265. }
  12266. }
  12267. public function get_contributors()
  12268. {
  12269. $contributors = array();
  12270. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  12271. {
  12272. $name = null;
  12273. $uri = null;
  12274. $email = null;
  12275. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  12276. {
  12277. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12278. }
  12279. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  12280. {
  12281. $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]));
  12282. }
  12283. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  12284. {
  12285. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12286. }
  12287. if ($name !== null || $email !== null || $uri !== null)
  12288. {
  12289. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  12290. }
  12291. }
  12292. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  12293. {
  12294. $name = null;
  12295. $url = null;
  12296. $email = null;
  12297. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  12298. {
  12299. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12300. }
  12301. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  12302. {
  12303. $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]));
  12304. }
  12305. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  12306. {
  12307. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12308. }
  12309. if ($name !== null || $email !== null || $url !== null)
  12310. {
  12311. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  12312. }
  12313. }
  12314. if (!empty($contributors))
  12315. {
  12316. return array_unique($contributors);
  12317. }
  12318. else
  12319. {
  12320. return null;
  12321. }
  12322. }
  12323. public function get_link($key = 0, $rel = 'alternate')
  12324. {
  12325. $links = $this->get_links($rel);
  12326. if (isset($links[$key]))
  12327. {
  12328. return $links[$key];
  12329. }
  12330. else
  12331. {
  12332. return null;
  12333. }
  12334. }
  12335. public function get_permalink()
  12336. {
  12337. return $this->get_link(0);
  12338. }
  12339. public function get_links($rel = 'alternate')
  12340. {
  12341. if (!isset($this->data['links']))
  12342. {
  12343. $this->data['links'] = array();
  12344. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
  12345. {
  12346. foreach ($links as $link)
  12347. {
  12348. if (isset($link['attribs']['']['href']))
  12349. {
  12350. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  12351. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  12352. }
  12353. }
  12354. }
  12355. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
  12356. {
  12357. foreach ($links as $link)
  12358. {
  12359. if (isset($link['attribs']['']['href']))
  12360. {
  12361. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  12362. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  12363. }
  12364. }
  12365. }
  12366. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  12367. {
  12368. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  12369. }
  12370. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  12371. {
  12372. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  12373. }
  12374. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  12375. {
  12376. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  12377. }
  12378. $keys = array_keys($this->data['links']);
  12379. foreach ($keys as $key)
  12380. {
  12381. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
  12382. {
  12383. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  12384. {
  12385. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  12386. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  12387. }
  12388. else
  12389. {
  12390. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  12391. }
  12392. }
  12393. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  12394. {
  12395. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  12396. }
  12397. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  12398. }
  12399. }
  12400. if (isset($this->data['links'][$rel]))
  12401. {
  12402. return $this->data['links'][$rel];
  12403. }
  12404. else
  12405. {
  12406. return null;
  12407. }
  12408. }
  12409. public function get_description()
  12410. {
  12411. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
  12412. {
  12413. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  12414. }
  12415. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
  12416. {
  12417. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  12418. }
  12419. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  12420. {
  12421. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  12422. }
  12423. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
  12424. {
  12425. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  12426. }
  12427. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
  12428. {
  12429. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  12430. }
  12431. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  12432. {
  12433. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12434. }
  12435. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  12436. {
  12437. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12438. }
  12439. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  12440. {
  12441. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  12442. }
  12443. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  12444. {
  12445. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  12446. }
  12447. else
  12448. {
  12449. return null;
  12450. }
  12451. }
  12452. public function get_copyright()
  12453. {
  12454. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  12455. {
  12456. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  12457. }
  12458. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
  12459. {
  12460. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  12461. }
  12462. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
  12463. {
  12464. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12465. }
  12466. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  12467. {
  12468. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12469. }
  12470. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  12471. {
  12472. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12473. }
  12474. else
  12475. {
  12476. return null;
  12477. }
  12478. }
  12479. public function get_language()
  12480. {
  12481. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language'))
  12482. {
  12483. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12484. }
  12485. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
  12486. {
  12487. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12488. }
  12489. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
  12490. {
  12491. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12492. }
  12493. elseif (isset($this->data['xml_lang']))
  12494. {
  12495. return $this->sanitize($this->data['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  12496. }
  12497. else
  12498. {
  12499. return null;
  12500. }
  12501. }
  12502. public function get_latitude()
  12503. {
  12504. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  12505. {
  12506. return (float) $return[0]['data'];
  12507. }
  12508. elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  12509. {
  12510. return (float) $match[1];
  12511. }
  12512. else
  12513. {
  12514. return null;
  12515. }
  12516. }
  12517. public function get_longitude()
  12518. {
  12519. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  12520. {
  12521. return (float) $return[0]['data'];
  12522. }
  12523. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  12524. {
  12525. return (float) $return[0]['data'];
  12526. }
  12527. elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  12528. {
  12529. return (float) $match[2];
  12530. }
  12531. else
  12532. {
  12533. return null;
  12534. }
  12535. }
  12536. public function get_image_url()
  12537. {
  12538. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
  12539. {
  12540. return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
  12541. }
  12542. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
  12543. {
  12544. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  12545. }
  12546. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
  12547. {
  12548. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  12549. }
  12550. else
  12551. {
  12552. return null;
  12553. }
  12554. }
  12555. }
  12556. class SimplePie_XML_Declaration_Parser
  12557. {
  12558. var $version = '1.0';
  12559. var $encoding = 'UTF-8';
  12560. var $standalone = false;
  12561. var $state = 'before_version_name';
  12562. var $data = '';
  12563. var $data_length = 0;
  12564. var $position = 0;
  12565. public function __construct($data)
  12566. {
  12567. $this->data = $data;
  12568. $this->data_length = strlen($this->data);
  12569. }
  12570. public function parse()
  12571. {
  12572. while ($this->state && $this->state !== 'emit' && $this->has_data())
  12573. {
  12574. $state = $this->state;
  12575. $this->$state();
  12576. }
  12577. $this->data = '';
  12578. if ($this->state === 'emit')
  12579. {
  12580. return true;
  12581. }
  12582. else
  12583. {
  12584. $this->version = '';
  12585. $this->encoding = '';
  12586. $this->standalone = '';
  12587. return false;
  12588. }
  12589. }
  12590. public function has_data()
  12591. {
  12592. return (bool) ($this->position < $this->data_length);
  12593. }
  12594. public function skip_whitespace()
  12595. {
  12596. $whitespace = strspn($this->data, "\x09\x0A\x0D\x20", $this->position);
  12597. $this->position += $whitespace;
  12598. return $whitespace;
  12599. }
  12600. public function get_value()
  12601. {
  12602. $quote = substr($this->data, $this->position, 1);
  12603. if ($quote === '"' || $quote === "'")
  12604. {
  12605. $this->position++;
  12606. $len = strcspn($this->data, $quote, $this->position);
  12607. if ($this->has_data())
  12608. {
  12609. $value = substr($this->data, $this->position, $len);
  12610. $this->position += $len + 1;
  12611. return $value;
  12612. }
  12613. }
  12614. return false;
  12615. }
  12616. public function before_version_name()
  12617. {
  12618. if ($this->skip_whitespace())
  12619. {
  12620. $this->state = 'version_name';
  12621. }
  12622. else
  12623. {
  12624. $this->state = false;
  12625. }
  12626. }
  12627. public function version_name()
  12628. {
  12629. if (substr($this->data, $this->position, 7) === 'version')
  12630. {
  12631. $this->position += 7;
  12632. $this->skip_whitespace();
  12633. $this->state = 'version_equals';
  12634. }
  12635. else
  12636. {
  12637. $this->state = false;
  12638. }
  12639. }
  12640. public function version_equals()
  12641. {
  12642. if (substr($this->data, $this->position, 1) === '=')
  12643. {
  12644. $this->position++;
  12645. $this->skip_whitespace();
  12646. $this->state = 'version_value';
  12647. }
  12648. else
  12649. {
  12650. $this->state = false;
  12651. }
  12652. }
  12653. public function version_value()
  12654. {
  12655. if ($this->version = $this->get_value())
  12656. {
  12657. $this->skip_whitespace();
  12658. if ($this->has_data())
  12659. {
  12660. $this->state = 'encoding_name';
  12661. }
  12662. else
  12663. {
  12664. $this->state = 'emit';
  12665. }
  12666. }
  12667. else
  12668. {
  12669. $this->state = false;
  12670. }
  12671. }
  12672. public function encoding_name()
  12673. {
  12674. if (substr($this->data, $this->position, 8) === 'encoding')
  12675. {
  12676. $this->position += 8;
  12677. $this->skip_whitespace();
  12678. $this->state = 'encoding_equals';
  12679. }
  12680. else
  12681. {
  12682. $this->state = 'standalone_name';
  12683. }
  12684. }
  12685. public function encoding_equals()
  12686. {
  12687. if (substr($this->data, $this->position, 1) === '=')
  12688. {
  12689. $this->position++;
  12690. $this->skip_whitespace();
  12691. $this->state = 'encoding_value';
  12692. }
  12693. else
  12694. {
  12695. $this->state = false;
  12696. }
  12697. }
  12698. public function encoding_value()
  12699. {
  12700. if ($this->encoding = $this->get_value())
  12701. {
  12702. $this->skip_whitespace();
  12703. if ($this->has_data())
  12704. {
  12705. $this->state = 'standalone_name';
  12706. }
  12707. else
  12708. {
  12709. $this->state = 'emit';
  12710. }
  12711. }
  12712. else
  12713. {
  12714. $this->state = false;
  12715. }
  12716. }
  12717. public function standalone_name()
  12718. {
  12719. if (substr($this->data, $this->position, 10) === 'standalone')
  12720. {
  12721. $this->position += 10;
  12722. $this->skip_whitespace();
  12723. $this->state = 'standalone_equals';
  12724. }
  12725. else
  12726. {
  12727. $this->state = false;
  12728. }
  12729. }
  12730. public function standalone_equals()
  12731. {
  12732. if (substr($this->data, $this->position, 1) === '=')
  12733. {
  12734. $this->position++;
  12735. $this->skip_whitespace();
  12736. $this->state = 'standalone_value';
  12737. }
  12738. else
  12739. {
  12740. $this->state = false;
  12741. }
  12742. }
  12743. public function standalone_value()
  12744. {
  12745. if ($standalone = $this->get_value())
  12746. {
  12747. switch ($standalone)
  12748. {
  12749. case 'yes':
  12750. $this->standalone = true;
  12751. break;
  12752. case 'no':
  12753. $this->standalone = false;
  12754. break;
  12755. default:
  12756. $this->state = false;
  12757. return;
  12758. }
  12759. $this->skip_whitespace();
  12760. if ($this->has_data())
  12761. {
  12762. $this->state = false;
  12763. }
  12764. else
  12765. {
  12766. $this->state = 'emit';
  12767. }
  12768. }
  12769. else
  12770. {
  12771. $this->state = false;
  12772. }
  12773. }
  12774. }