lib_simplepie.php 354 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585
  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. curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, 0);
  4114. if (!ini_get('open_basedir') && !ini_get('safe_mode') && version_compare(SimplePie_Misc::get_curl_version(), '7.15.2', '>='))
  4115. {
  4116. curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
  4117. curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
  4118. }
  4119. $this->headers = curl_exec($fp);
  4120. if (curl_errno($fp) === 23 || curl_errno($fp) === 61)
  4121. {
  4122. curl_setopt($fp, CURLOPT_ENCODING, 'none');
  4123. $this->headers = curl_exec($fp);
  4124. }
  4125. if (curl_errno($fp))
  4126. {
  4127. $this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
  4128. $this->success = false;
  4129. }
  4130. else
  4131. {
  4132. $info = curl_getinfo($fp);
  4133. curl_close($fp);
  4134. $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 1);
  4135. $this->headers = array_pop($this->headers);
  4136. $parser = new SimplePie_HTTP_Parser($this->headers);
  4137. if ($parser->parse())
  4138. {
  4139. $this->headers = $parser->headers;
  4140. $this->body = $parser->body;
  4141. $this->status_code = $parser->status_code;
  4142. 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)
  4143. {
  4144. $this->redirects++;
  4145. $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
  4146. return $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
  4147. }
  4148. }
  4149. }
  4150. }
  4151. else
  4152. {
  4153. $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_FSOCKOPEN;
  4154. $url_parts = parse_url($url);
  4155. $socket_host = $url_parts['host'];
  4156. if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https')
  4157. {
  4158. $socket_host = "ssl://$url_parts[host]";
  4159. $url_parts['port'] = 443;
  4160. }
  4161. if (!isset($url_parts['port']))
  4162. {
  4163. $url_parts['port'] = 80;
  4164. }
  4165. $fp = @fsockopen($socket_host, $url_parts['port'], $errno, $errstr, $timeout);
  4166. if (!$fp)
  4167. {
  4168. $this->error = 'fsockopen error: ' . $errstr;
  4169. $this->success = false;
  4170. }
  4171. else
  4172. {
  4173. stream_set_timeout($fp, $timeout);
  4174. if (isset($url_parts['path']))
  4175. {
  4176. if (isset($url_parts['query']))
  4177. {
  4178. $get = "$url_parts[path]?$url_parts[query]";
  4179. }
  4180. else
  4181. {
  4182. $get = $url_parts['path'];
  4183. }
  4184. }
  4185. else
  4186. {
  4187. $get = '/';
  4188. }
  4189. $out = "GET $get HTTP/1.1\r\n";
  4190. $out .= "Host: $url_parts[host]\r\n";
  4191. $out .= "User-Agent: $useragent\r\n";
  4192. if (extension_loaded('zlib'))
  4193. {
  4194. $out .= "Accept-Encoding: x-gzip,gzip,deflate\r\n";
  4195. }
  4196. if (isset($url_parts['user']) && isset($url_parts['pass']))
  4197. {
  4198. $out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
  4199. }
  4200. foreach ($headers as $key => $value)
  4201. {
  4202. $out .= "$key: $value\r\n";
  4203. }
  4204. $out .= "Connection: Close\r\n\r\n";
  4205. fwrite($fp, $out);
  4206. $info = stream_get_meta_data($fp);
  4207. $this->headers = '';
  4208. while (!$info['eof'] && !$info['timed_out'])
  4209. {
  4210. $this->headers .= fread($fp, 1160);
  4211. $info = stream_get_meta_data($fp);
  4212. }
  4213. if (!$info['timed_out'])
  4214. {
  4215. $parser = new SimplePie_HTTP_Parser($this->headers);
  4216. if ($parser->parse())
  4217. {
  4218. $this->headers = $parser->headers;
  4219. $this->body = $parser->body;
  4220. $this->status_code = $parser->status_code;
  4221. 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)
  4222. {
  4223. $this->redirects++;
  4224. $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
  4225. return $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
  4226. }
  4227. if (isset($this->headers['content-encoding']))
  4228. {
  4229. // Hey, we act dumb elsewhere, so let's do that here too
  4230. switch (strtolower(trim($this->headers['content-encoding'], "\x09\x0A\x0D\x20")))
  4231. {
  4232. case 'gzip':
  4233. case 'x-gzip':
  4234. $decoder = new SimplePie_gzdecode($this->body);
  4235. if (!$decoder->parse())
  4236. {
  4237. $this->error = 'Unable to decode HTTP "gzip" stream';
  4238. $this->success = false;
  4239. }
  4240. else
  4241. {
  4242. $this->body = $decoder->data;
  4243. }
  4244. break;
  4245. case 'deflate':
  4246. if (($decompressed = gzinflate($this->body)) !== false)
  4247. {
  4248. $this->body = $decompressed;
  4249. }
  4250. else if (($decompressed = gzuncompress($this->body)) !== false)
  4251. {
  4252. $this->body = $decompressed;
  4253. }
  4254. else if (function_exists('gzdecode') && ($decompressed = gzdecode($this->body)) !== false)
  4255. {
  4256. $this->body = $decompressed;
  4257. }
  4258. else
  4259. {
  4260. $this->error = 'Unable to decode HTTP "deflate" stream';
  4261. $this->success = false;
  4262. }
  4263. break;
  4264. default:
  4265. $this->error = 'Unknown content coding';
  4266. $this->success = false;
  4267. }
  4268. }
  4269. }
  4270. }
  4271. else
  4272. {
  4273. $this->error = 'fsocket timed out';
  4274. $this->success = false;
  4275. }
  4276. fclose($fp);
  4277. }
  4278. }
  4279. }
  4280. else
  4281. {
  4282. $this->method = SIMPLEPIE_FILE_SOURCE_LOCAL | SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS;
  4283. if (!$this->body = file_get_contents($url))
  4284. {
  4285. $this->error = 'file_get_contents could not read the file';
  4286. $this->success = false;
  4287. }
  4288. }
  4289. }
  4290. }
  4291. class SimplePie_gzdecode
  4292. {
  4293. var $compressed_data;
  4294. var $compressed_size;
  4295. var $min_compressed_size = 18;
  4296. var $position = 0;
  4297. var $flags;
  4298. var $data;
  4299. var $MTIME;
  4300. var $XFL;
  4301. var $OS;
  4302. var $SI1;
  4303. var $SI2;
  4304. var $extra_field;
  4305. var $filename;
  4306. var $comment;
  4307. public function __set($name, $value)
  4308. {
  4309. trigger_error("Cannot write property $name", E_USER_ERROR);
  4310. }
  4311. public function __construct($data)
  4312. {
  4313. $this->compressed_data = $data;
  4314. $this->compressed_size = strlen($data);
  4315. }
  4316. public function parse()
  4317. {
  4318. if ($this->compressed_size >= $this->min_compressed_size)
  4319. {
  4320. // Check ID1, ID2, and CM
  4321. if (substr($this->compressed_data, 0, 3) !== "\x1F\x8B\x08")
  4322. {
  4323. return false;
  4324. }
  4325. // Get the FLG (FLaGs)
  4326. $this->flags = ord($this->compressed_data[3]);
  4327. // FLG bits above (1 << 4) are reserved
  4328. if ($this->flags > 0x1F)
  4329. {
  4330. return false;
  4331. }
  4332. // Advance the pointer after the above
  4333. $this->position += 4;
  4334. // MTIME
  4335. $mtime = substr($this->compressed_data, $this->position, 4);
  4336. // Reverse the string if we're on a big-endian arch because l is the only signed long and is machine endianness
  4337. if (current(unpack('S', "\x00\x01")) === 1)
  4338. {
  4339. $mtime = strrev($mtime);
  4340. }
  4341. $this->MTIME = current(unpack('l', $mtime));
  4342. $this->position += 4;
  4343. // Get the XFL (eXtra FLags)
  4344. $this->XFL = ord($this->compressed_data[$this->position++]);
  4345. // Get the OS (Operating System)
  4346. $this->OS = ord($this->compressed_data[$this->position++]);
  4347. // Parse the FEXTRA
  4348. if ($this->flags & 4)
  4349. {
  4350. // Read subfield IDs
  4351. $this->SI1 = $this->compressed_data[$this->position++];
  4352. $this->SI2 = $this->compressed_data[$this->position++];
  4353. // SI2 set to zero is reserved for future use
  4354. if ($this->SI2 === "\x00")
  4355. {
  4356. return false;
  4357. }
  4358. // Get the length of the extra field
  4359. $len = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
  4360. $this->position += 2;
  4361. // Check the length of the string is still valid
  4362. $this->min_compressed_size += $len + 4;
  4363. if ($this->compressed_size >= $this->min_compressed_size)
  4364. {
  4365. // Set the extra field to the given data
  4366. $this->extra_field = substr($this->compressed_data, $this->position, $len);
  4367. $this->position += $len;
  4368. }
  4369. else
  4370. {
  4371. return false;
  4372. }
  4373. }
  4374. // Parse the FNAME
  4375. if ($this->flags & 8)
  4376. {
  4377. // Get the length of the filename
  4378. $len = strcspn($this->compressed_data, "\x00", $this->position);
  4379. // Check the length of the string is still valid
  4380. $this->min_compressed_size += $len + 1;
  4381. if ($this->compressed_size >= $this->min_compressed_size)
  4382. {
  4383. // Set the original filename to the given string
  4384. $this->filename = substr($this->compressed_data, $this->position, $len);
  4385. $this->position += $len + 1;
  4386. }
  4387. else
  4388. {
  4389. return false;
  4390. }
  4391. }
  4392. // Parse the FCOMMENT
  4393. if ($this->flags & 16)
  4394. {
  4395. // Get the length of the comment
  4396. $len = strcspn($this->compressed_data, "\x00", $this->position);
  4397. // Check the length of the string is still valid
  4398. $this->min_compressed_size += $len + 1;
  4399. if ($this->compressed_size >= $this->min_compressed_size)
  4400. {
  4401. // Set the original comment to the given string
  4402. $this->comment = substr($this->compressed_data, $this->position, $len);
  4403. $this->position += $len + 1;
  4404. }
  4405. else
  4406. {
  4407. return false;
  4408. }
  4409. }
  4410. // Parse the FHCRC
  4411. if ($this->flags & 2)
  4412. {
  4413. // Check the length of the string is still valid
  4414. $this->min_compressed_size += $len + 2;
  4415. if ($this->compressed_size >= $this->min_compressed_size)
  4416. {
  4417. // Read the CRC
  4418. $crc = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
  4419. // Check the CRC matches
  4420. if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc)
  4421. {
  4422. $this->position += 2;
  4423. }
  4424. else
  4425. {
  4426. return false;
  4427. }
  4428. }
  4429. else
  4430. {
  4431. return false;
  4432. }
  4433. }
  4434. // Decompress the actual data
  4435. if (($this->data = gzinflate(substr($this->compressed_data, $this->position, -8))) === false)
  4436. {
  4437. return false;
  4438. }
  4439. else
  4440. {
  4441. $this->position = $this->compressed_size - 8;
  4442. }
  4443. // Check CRC of data
  4444. $crc = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
  4445. $this->position += 4;
  4446. /*if (extension_loaded('hash') && sprintf('%u', current(unpack('V', hash('crc32b', $this->data)))) !== sprintf('%u', $crc))
  4447. {
  4448. return false;
  4449. }*/
  4450. // Check ISIZE of data
  4451. $isize = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
  4452. $this->position += 4;
  4453. if (sprintf('%u', strlen($this->data) & 0xFFFFFFFF) !== sprintf('%u', $isize))
  4454. {
  4455. return false;
  4456. }
  4457. // Wow, against all odds, we've actually got a valid gzip string
  4458. return true;
  4459. }
  4460. else
  4461. {
  4462. return false;
  4463. }
  4464. }
  4465. }
  4466. class SimplePie_HTTP_Parser
  4467. {
  4468. public $http_version = 0.0;
  4469. public $status_code = 0;
  4470. public $reason = '';
  4471. public $headers = array();
  4472. public $body = '';
  4473. protected $state = 'http_version';
  4474. protected $data = '';
  4475. protected $data_length = 0;
  4476. protected $position = 0;
  4477. protected $name = '';
  4478. protected $value = '';
  4479. public function __construct($data)
  4480. {
  4481. $this->data = $data;
  4482. $this->data_length = strlen($this->data);
  4483. }
  4484. public function parse()
  4485. {
  4486. while ($this->state && $this->state !== 'emit' && $this->has_data())
  4487. {
  4488. $state = $this->state;
  4489. $this->$state();
  4490. }
  4491. $this->data = '';
  4492. if ($this->state === 'emit' || $this->state === 'body')
  4493. {
  4494. return true;
  4495. }
  4496. else
  4497. {
  4498. $this->http_version = '';
  4499. $this->status_code = '';
  4500. $this->reason = '';
  4501. $this->headers = array();
  4502. $this->body = '';
  4503. return false;
  4504. }
  4505. }
  4506. protected function has_data()
  4507. {
  4508. return (bool) ($this->position < $this->data_length);
  4509. }
  4510. protected function is_linear_whitespace()
  4511. {
  4512. return (bool) ($this->data[$this->position] === "\x09"
  4513. || $this->data[$this->position] === "\x20"
  4514. || ($this->data[$this->position] === "\x0A"
  4515. && isset($this->data[$this->position + 1])
  4516. && ($this->data[$this->position + 1] === "\x09" || $this->data[$this->position + 1] === "\x20")));
  4517. }
  4518. protected function http_version()
  4519. {
  4520. if (strpos($this->data, "\x0A") !== false && strtoupper(substr($this->data, 0, 5)) === 'HTTP/')
  4521. {
  4522. $len = strspn($this->data, '0123456789.', 5);
  4523. $this->http_version = substr($this->data, 5, $len);
  4524. $this->position += 5 + $len;
  4525. if (substr_count($this->http_version, '.') <= 1)
  4526. {
  4527. $this->http_version = (float) $this->http_version;
  4528. $this->position += strspn($this->data, "\x09\x20", $this->position);
  4529. $this->state = 'status';
  4530. }
  4531. else
  4532. {
  4533. $this->state = false;
  4534. }
  4535. }
  4536. else
  4537. {
  4538. $this->state = false;
  4539. }
  4540. }
  4541. protected function status()
  4542. {
  4543. if ($len = strspn($this->data, '0123456789', $this->position))
  4544. {
  4545. $this->status_code = (int) substr($this->data, $this->position, $len);
  4546. $this->position += $len;
  4547. $this->state = 'reason';
  4548. }
  4549. else
  4550. {
  4551. $this->state = false;
  4552. }
  4553. }
  4554. protected function reason()
  4555. {
  4556. $len = strcspn($this->data, "\x0A", $this->position);
  4557. $this->reason = trim(substr($this->data, $this->position, $len), "\x09\x0D\x20");
  4558. $this->position += $len + 1;
  4559. $this->state = 'new_line';
  4560. }
  4561. protected function new_line()
  4562. {
  4563. $this->value = trim($this->value, "\x0D\x20");
  4564. if ($this->name !== '' && $this->value !== '')
  4565. {
  4566. $this->name = strtolower($this->name);
  4567. // We should only use the last Content-Type header. c.f. issue #1
  4568. if (isset($this->headers[$this->name]) && $this->name !== 'content-type')
  4569. {
  4570. $this->headers[$this->name] .= ', ' . $this->value;
  4571. }
  4572. else
  4573. {
  4574. $this->headers[$this->name] = $this->value;
  4575. }
  4576. }
  4577. $this->name = '';
  4578. $this->value = '';
  4579. if (substr($this->data[$this->position], 0, 2) === "\x0D\x0A")
  4580. {
  4581. $this->position += 2;
  4582. $this->state = 'body';
  4583. }
  4584. elseif ($this->data[$this->position] === "\x0A")
  4585. {
  4586. $this->position++;
  4587. $this->state = 'body';
  4588. }
  4589. else
  4590. {
  4591. $this->state = 'name';
  4592. }
  4593. }
  4594. protected function name()
  4595. {
  4596. $len = strcspn($this->data, "\x0A:", $this->position);
  4597. if (isset($this->data[$this->position + $len]))
  4598. {
  4599. if ($this->data[$this->position + $len] === "\x0A")
  4600. {
  4601. $this->position += $len;
  4602. $this->state = 'new_line';
  4603. }
  4604. else
  4605. {
  4606. $this->name = substr($this->data, $this->position, $len);
  4607. $this->position += $len + 1;
  4608. $this->state = 'value';
  4609. }
  4610. }
  4611. else
  4612. {
  4613. $this->state = false;
  4614. }
  4615. }
  4616. protected function linear_whitespace()
  4617. {
  4618. do
  4619. {
  4620. if (substr($this->data, $this->position, 2) === "\x0D\x0A")
  4621. {
  4622. $this->position += 2;
  4623. }
  4624. elseif ($this->data[$this->position] === "\x0A")
  4625. {
  4626. $this->position++;
  4627. }
  4628. $this->position += strspn($this->data, "\x09\x20", $this->position);
  4629. } while ($this->has_data() && $this->is_linear_whitespace());
  4630. $this->value .= "\x20";
  4631. }
  4632. protected function value()
  4633. {
  4634. if ($this->is_linear_whitespace())
  4635. {
  4636. $this->linear_whitespace();
  4637. }
  4638. else
  4639. {
  4640. switch ($this->data[$this->position])
  4641. {
  4642. case '"':
  4643. // Workaround for ETags: we have to include the quotes as
  4644. // part of the tag.
  4645. if (strtolower($this->name) === 'etag')
  4646. {
  4647. $this->value .= '"';
  4648. $this->position++;
  4649. $this->state = 'value_char';
  4650. break;
  4651. }
  4652. $this->position++;
  4653. $this->state = 'quote';
  4654. break;
  4655. case "\x0A":
  4656. $this->position++;
  4657. $this->state = 'new_line';
  4658. break;
  4659. default:
  4660. $this->state = 'value_char';
  4661. break;
  4662. }
  4663. }
  4664. }
  4665. protected function value_char()
  4666. {
  4667. $len = strcspn($this->data, "\x09\x20\x0A\"", $this->position);
  4668. $this->value .= substr($this->data, $this->position, $len);
  4669. $this->position += $len;
  4670. $this->state = 'value';
  4671. }
  4672. protected function quote()
  4673. {
  4674. if ($this->is_linear_whitespace())
  4675. {
  4676. $this->linear_whitespace();
  4677. }
  4678. else
  4679. {
  4680. switch ($this->data[$this->position])
  4681. {
  4682. case '"':
  4683. $this->position++;
  4684. $this->state = 'value';
  4685. break;
  4686. case "\x0A":
  4687. $this->position++;
  4688. $this->state = 'new_line';
  4689. break;
  4690. case '\\':
  4691. $this->position++;
  4692. $this->state = 'quote_escaped';
  4693. break;
  4694. default:
  4695. $this->state = 'quote_char';
  4696. break;
  4697. }
  4698. }
  4699. }
  4700. protected function quote_char()
  4701. {
  4702. $len = strcspn($this->data, "\x09\x20\x0A\"\\", $this->position);
  4703. $this->value .= substr($this->data, $this->position, $len);
  4704. $this->position += $len;
  4705. $this->state = 'value';
  4706. }
  4707. protected function quote_escaped()
  4708. {
  4709. $this->value .= $this->data[$this->position];
  4710. $this->position++;
  4711. $this->state = 'quote';
  4712. }
  4713. protected function body()
  4714. {
  4715. $this->body = substr($this->data, $this->position);
  4716. if (!empty($this->headers['transfer-encoding']))
  4717. {
  4718. unset($this->headers['transfer-encoding']);
  4719. $this->state = 'chunked';
  4720. }
  4721. else
  4722. {
  4723. $this->state = 'emit';
  4724. }
  4725. }
  4726. protected function chunked()
  4727. {
  4728. if (!preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', trim($this->body)))
  4729. {
  4730. $this->state = 'emit';
  4731. return;
  4732. }
  4733. $decoded = '';
  4734. $encoded = $this->body;
  4735. while (true)
  4736. {
  4737. $is_chunked = (bool) preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', $encoded, $matches );
  4738. if (!$is_chunked)
  4739. {
  4740. // Looks like it's not chunked after all
  4741. $this->state = 'emit';
  4742. return;
  4743. }
  4744. $length = hexdec(trim($matches[1]));
  4745. if ($length === 0)
  4746. {
  4747. // Ignore trailer headers
  4748. $this->state = 'emit';
  4749. $this->body = $decoded;
  4750. return;
  4751. }
  4752. $chunk_length = strlen($matches[0]);
  4753. $decoded .= $part = substr($encoded, $chunk_length, $length);
  4754. $encoded = substr($encoded, $chunk_length + $length + 2);
  4755. if (trim($encoded) === '0' || empty($encoded))
  4756. {
  4757. $this->state = 'emit';
  4758. $this->body = $decoded;
  4759. return;
  4760. }
  4761. }
  4762. }
  4763. }
  4764. class SimplePie_IRI
  4765. {
  4766. protected $scheme = null;
  4767. protected $iuserinfo = null;
  4768. protected $ihost = null;
  4769. protected $port = null;
  4770. protected $ipath = '';
  4771. protected $iquery = null;
  4772. protected $ifragment = null;
  4773. protected $normalization = array(
  4774. 'acap' => array(
  4775. 'port' => 674
  4776. ),
  4777. 'dict' => array(
  4778. 'port' => 2628
  4779. ),
  4780. 'file' => array(
  4781. 'ihost' => 'localhost'
  4782. ),
  4783. 'http' => array(
  4784. 'port' => 80,
  4785. 'ipath' => '/'
  4786. ),
  4787. 'https' => array(
  4788. 'port' => 443,
  4789. 'ipath' => '/'
  4790. ),
  4791. );
  4792. public function __toString()
  4793. {
  4794. return $this->get_iri();
  4795. }
  4796. public function __set($name, $value)
  4797. {
  4798. if (method_exists($this, 'set_' . $name))
  4799. {
  4800. call_user_func(array($this, 'set_' . $name), $value);
  4801. }
  4802. elseif (
  4803. $name === 'iauthority'
  4804. || $name === 'iuserinfo'
  4805. || $name === 'ihost'
  4806. || $name === 'ipath'
  4807. || $name === 'iquery'
  4808. || $name === 'ifragment'
  4809. )
  4810. {
  4811. call_user_func(array($this, 'set_' . substr($name, 1)), $value);
  4812. }
  4813. }
  4814. public function __get($name)
  4815. {
  4816. // isset() returns false for null, we don't want to do that
  4817. // Also why we use array_key_exists below instead of isset()
  4818. $props = get_object_vars($this);
  4819. if (
  4820. $name === 'iri' ||
  4821. $name === 'uri' ||
  4822. $name === 'iauthority' ||
  4823. $name === 'authority'
  4824. )
  4825. {
  4826. $return = $this->{"get_$name"}();
  4827. }
  4828. elseif (array_key_exists($name, $props))
  4829. {
  4830. $return = $this->$name;
  4831. }
  4832. // host -> ihost
  4833. elseif (($prop = 'i' . $name) && array_key_exists($prop, $props))
  4834. {
  4835. $name = $prop;
  4836. $return = $this->$prop;
  4837. }
  4838. // ischeme -> scheme
  4839. elseif (($prop = substr($name, 1)) && array_key_exists($prop, $props))
  4840. {
  4841. $name = $prop;
  4842. $return = $this->$prop;
  4843. }
  4844. else
  4845. {
  4846. trigger_error('Undefined property: ' . get_class($this) . '::' . $name, E_USER_NOTICE);
  4847. $return = null;
  4848. }
  4849. if ($return === null && isset($this->normalization[$this->scheme][$name]))
  4850. {
  4851. return $this->normalization[$this->scheme][$name];
  4852. }
  4853. else
  4854. {
  4855. return $return;
  4856. }
  4857. }
  4858. public function __isset($name)
  4859. {
  4860. if (method_exists($this, 'get_' . $name) || isset($this->$name))
  4861. {
  4862. return true;
  4863. }
  4864. else
  4865. {
  4866. return false;
  4867. }
  4868. }
  4869. public function __unset($name)
  4870. {
  4871. if (method_exists($this, 'set_' . $name))
  4872. {
  4873. call_user_func(array($this, 'set_' . $name), '');
  4874. }
  4875. }
  4876. public function __construct($iri = null)
  4877. {
  4878. $this->set_iri($iri);
  4879. }
  4880. public static function absolutize($base, $relative)
  4881. {
  4882. if (!($relative instanceof SimplePie_IRI))
  4883. {
  4884. $relative = new SimplePie_IRI($relative);
  4885. }
  4886. if (!$relative->is_valid())
  4887. {
  4888. return false;
  4889. }
  4890. elseif ($relative->scheme !== null)
  4891. {
  4892. return clone $relative;
  4893. }
  4894. else
  4895. {
  4896. if (!($base instanceof SimplePie_IRI))
  4897. {
  4898. $base = new SimplePie_IRI($base);
  4899. }
  4900. if ($base->scheme !== null && $base->is_valid())
  4901. {
  4902. if ($relative->get_iri() !== '')
  4903. {
  4904. if ($relative->iuserinfo !== null || $relative->ihost !== null || $relative->port !== null)
  4905. {
  4906. $target = clone $relative;
  4907. $target->scheme = $base->scheme;
  4908. }
  4909. else
  4910. {
  4911. $target = new SimplePie_IRI;
  4912. $target->scheme = $base->scheme;
  4913. $target->iuserinfo = $base->iuserinfo;
  4914. $target->ihost = $base->ihost;
  4915. $target->port = $base->port;
  4916. if ($relative->ipath !== '')
  4917. {
  4918. if ($relative->ipath[0] === '/')
  4919. {
  4920. $target->ipath = $relative->ipath;
  4921. }
  4922. elseif (($base->iuserinfo !== null || $base->ihost !== null || $base->port !== null) && $base->ipath === '')
  4923. {
  4924. $target->ipath = '/' . $relative->ipath;
  4925. }
  4926. elseif (($last_segment = strrpos($base->ipath, '/')) !== false)
  4927. {
  4928. $target->ipath = substr($base->ipath, 0, $last_segment + 1) . $relative->ipath;
  4929. }
  4930. else
  4931. {
  4932. $target->ipath = $relative->ipath;
  4933. }
  4934. $target->ipath = $target->remove_dot_segments($target->ipath);
  4935. $target->iquery = $relative->iquery;
  4936. }
  4937. else
  4938. {
  4939. $target->ipath = $base->ipath;
  4940. if ($relative->iquery !== null)
  4941. {
  4942. $target->iquery = $relative->iquery;
  4943. }
  4944. elseif ($base->iquery !== null)
  4945. {
  4946. $target->iquery = $base->iquery;
  4947. }
  4948. }
  4949. $target->ifragment = $relative->ifragment;
  4950. }
  4951. }
  4952. else
  4953. {
  4954. $target = clone $base;
  4955. $target->ifragment = null;
  4956. }
  4957. $target->scheme_normalization();
  4958. return $target;
  4959. }
  4960. else
  4961. {
  4962. return false;
  4963. }
  4964. }
  4965. }
  4966. protected function parse_iri($iri)
  4967. {
  4968. $iri = trim($iri, "\x20\x09\x0A\x0C\x0D");
  4969. if (preg_match('/^((?P<scheme>[^:\/?#]+):)?(\/\/(?P<authority>[^\/?#]*))?(?P<path>[^?#]*)(\?(?P<query>[^#]*))?(#(?P<fragment>.*))?$/', $iri, $match))
  4970. {
  4971. if ($match[1] === '')
  4972. {
  4973. $match['scheme'] = null;
  4974. }
  4975. if (!isset($match[3]) || $match[3] === '')
  4976. {
  4977. $match['authority'] = null;
  4978. }
  4979. if (!isset($match[5]))
  4980. {
  4981. $match['path'] = '';
  4982. }
  4983. if (!isset($match[6]) || $match[6] === '')
  4984. {
  4985. $match['query'] = null;
  4986. }
  4987. if (!isset($match[8]) || $match[8] === '')
  4988. {
  4989. $match['fragment'] = null;
  4990. }
  4991. $match['path'] = preg_replace ('#//#', '/', $match['path']); // fix un bug lorsque 2 slashs se suivent
  4992. return $match;
  4993. }
  4994. else
  4995. {
  4996. trigger_error('This should never happen', E_USER_ERROR);
  4997. die;
  4998. }
  4999. }
  5000. protected function remove_dot_segments($input)
  5001. {
  5002. $output = '';
  5003. while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..')
  5004. {
  5005. // A: If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise,
  5006. if (strpos($input, '../') === 0)
  5007. {
  5008. $input = substr($input, 3);
  5009. }
  5010. elseif (strpos($input, './') === 0)
  5011. {
  5012. $input = substr($input, 2);
  5013. }
  5014. // 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,
  5015. elseif (strpos($input, '/./') === 0)
  5016. {
  5017. $input = substr($input, 2);
  5018. }
  5019. elseif ($input === '/.')
  5020. {
  5021. $input = '/';
  5022. }
  5023. // 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,
  5024. elseif (strpos($input, '/../') === 0)
  5025. {
  5026. $input = substr($input, 3);
  5027. $output = substr_replace($output, '', strrpos($output, '/'));
  5028. }
  5029. elseif ($input === '/..')
  5030. {
  5031. $input = '/';
  5032. $output = substr_replace($output, '', strrpos($output, '/'));
  5033. }
  5034. // D: if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise,
  5035. elseif ($input === '.' || $input === '..')
  5036. {
  5037. $input = '';
  5038. }
  5039. // 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
  5040. elseif (($pos = strpos($input, '/', 1)) !== false)
  5041. {
  5042. $output .= substr($input, 0, $pos);
  5043. $input = substr_replace($input, '', 0, $pos);
  5044. }
  5045. else
  5046. {
  5047. $output .= $input;
  5048. $input = '';
  5049. }
  5050. }
  5051. return $output . $input;
  5052. }
  5053. protected function replace_invalid_with_pct_encoding($string, $extra_chars, $iprivate = false)
  5054. {
  5055. // Normalize as many pct-encoded sections as possible
  5056. $string = preg_replace_callback('/(?:%[A-Fa-f0-9]{2})+/', array($this, 'remove_iunreserved_percent_encoded'), $string);
  5057. // Replace invalid percent characters
  5058. $string = preg_replace('/%(?![A-Fa-f0-9]{2})/', '%25', $string);
  5059. // Add unreserved and % to $extra_chars (the latter is safe because all
  5060. // pct-encoded sections are now valid).
  5061. $extra_chars .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~%';
  5062. // Now replace any bytes that aren't allowed with their pct-encoded versions
  5063. $position = 0;
  5064. $strlen = strlen($string);
  5065. while (($position += strspn($string, $extra_chars, $position)) < $strlen)
  5066. {
  5067. $value = ord($string[$position]);
  5068. // Start position
  5069. $start = $position;
  5070. // By default we are valid
  5071. $valid = true;
  5072. // No one byte sequences are valid due to the while.
  5073. // Two byte sequence:
  5074. if (($value & 0xE0) === 0xC0)
  5075. {
  5076. $character = ($value & 0x1F) << 6;
  5077. $length = 2;
  5078. $remaining = 1;
  5079. }
  5080. // Three byte sequence:
  5081. elseif (($value & 0xF0) === 0xE0)
  5082. {
  5083. $character = ($value & 0x0F) << 12;
  5084. $length = 3;
  5085. $remaining = 2;
  5086. }
  5087. // Four byte sequence:
  5088. elseif (($value & 0xF8) === 0xF0)
  5089. {
  5090. $character = ($value & 0x07) << 18;
  5091. $length = 4;
  5092. $remaining = 3;
  5093. }
  5094. // Invalid byte:
  5095. else
  5096. {
  5097. $valid = false;
  5098. $length = 1;
  5099. $remaining = 0;
  5100. }
  5101. if ($remaining)
  5102. {
  5103. if ($position + $length <= $strlen)
  5104. {
  5105. for ($position++; $remaining; $position++)
  5106. {
  5107. $value = ord($string[$position]);
  5108. // Check that the byte is valid, then add it to the character:
  5109. if (($value & 0xC0) === 0x80)
  5110. {
  5111. $character |= ($value & 0x3F) << (--$remaining * 6);
  5112. }
  5113. // If it is invalid, count the sequence as invalid and reprocess the current byte:
  5114. else
  5115. {
  5116. $valid = false;
  5117. $position--;
  5118. break;
  5119. }
  5120. }
  5121. }
  5122. else
  5123. {
  5124. $position = $strlen - 1;
  5125. $valid = false;
  5126. }
  5127. }
  5128. // Percent encode anything invalid or not in ucschar
  5129. if (
  5130. // Invalid sequences
  5131. !$valid
  5132. // Non-shortest form sequences are invalid
  5133. || $length > 1 && $character <= 0x7F
  5134. || $length > 2 && $character <= 0x7FF
  5135. || $length > 3 && $character <= 0xFFFF
  5136. // Outside of range of ucschar codepoints
  5137. // Noncharacters
  5138. || ($character & 0xFFFE) === 0xFFFE
  5139. || $character >= 0xFDD0 && $character <= 0xFDEF
  5140. || (
  5141. // Everything else not in ucschar
  5142. $character > 0xD7FF && $character < 0xF900
  5143. || $character < 0xA0
  5144. || $character > 0xEFFFD
  5145. )
  5146. && (
  5147. // Everything not in iprivate, if it applies
  5148. !$iprivate
  5149. || $character < 0xE000
  5150. || $character > 0x10FFFD
  5151. )
  5152. )
  5153. {
  5154. // If we were a character, pretend we weren't, but rather an error.
  5155. if ($valid)
  5156. $position--;
  5157. for ($j = $start; $j <= $position; $j++)
  5158. {
  5159. $string = substr_replace($string, sprintf('%%%02X', ord($string[$j])), $j, 1);
  5160. $j += 2;
  5161. $position += 2;
  5162. $strlen += 2;
  5163. }
  5164. }
  5165. }
  5166. return $string;
  5167. }
  5168. protected function remove_iunreserved_percent_encoded($match)
  5169. {
  5170. // As we just have valid percent encoded sequences we can just explode
  5171. // and ignore the first member of the returned array (an empty string).
  5172. $bytes = explode('%', $match[0]);
  5173. // Initialize the new string (this is what will be returned) and that
  5174. // there are no bytes remaining in the current sequence (unsurprising
  5175. // at the first byte!).
  5176. $string = '';
  5177. $remaining = 0;
  5178. // Loop over each and every byte, and set $value to its value
  5179. for ($i = 1, $len = count($bytes); $i < $len; $i++)
  5180. {
  5181. $value = hexdec($bytes[$i]);
  5182. // If we're the first byte of sequence:
  5183. if (!$remaining)
  5184. {
  5185. // Start position
  5186. $start = $i;
  5187. // By default we are valid
  5188. $valid = true;
  5189. // One byte sequence:
  5190. if ($value <= 0x7F)
  5191. {
  5192. $character = $value;
  5193. $length = 1;
  5194. }
  5195. // Two byte sequence:
  5196. elseif (($value & 0xE0) === 0xC0)
  5197. {
  5198. $character = ($value & 0x1F) << 6;
  5199. $length = 2;
  5200. $remaining = 1;
  5201. }
  5202. // Three byte sequence:
  5203. elseif (($value & 0xF0) === 0xE0)
  5204. {
  5205. $character = ($value & 0x0F) << 12;
  5206. $length = 3;
  5207. $remaining = 2;
  5208. }
  5209. // Four byte sequence:
  5210. elseif (($value & 0xF8) === 0xF0)
  5211. {
  5212. $character = ($value & 0x07) << 18;
  5213. $length = 4;
  5214. $remaining = 3;
  5215. }
  5216. // Invalid byte:
  5217. else
  5218. {
  5219. $valid = false;
  5220. $remaining = 0;
  5221. }
  5222. }
  5223. // Continuation byte:
  5224. else
  5225. {
  5226. // Check that the byte is valid, then add it to the character:
  5227. if (($value & 0xC0) === 0x80)
  5228. {
  5229. $remaining--;
  5230. $character |= ($value & 0x3F) << ($remaining * 6);
  5231. }
  5232. // If it is invalid, count the sequence as invalid and reprocess the current byte as the start of a sequence:
  5233. else
  5234. {
  5235. $valid = false;
  5236. $remaining = 0;
  5237. $i--;
  5238. }
  5239. }
  5240. // If we've reached the end of the current byte sequence, append it to Unicode::$data
  5241. if (!$remaining)
  5242. {
  5243. // Percent encode anything invalid or not in iunreserved
  5244. if (
  5245. // Invalid sequences
  5246. !$valid
  5247. // Non-shortest form sequences are invalid
  5248. || $length > 1 && $character <= 0x7F
  5249. || $length > 2 && $character <= 0x7FF
  5250. || $length > 3 && $character <= 0xFFFF
  5251. // Outside of range of iunreserved codepoints
  5252. || $character < 0x2D
  5253. || $character > 0xEFFFD
  5254. // Noncharacters
  5255. || ($character & 0xFFFE) === 0xFFFE
  5256. || $character >= 0xFDD0 && $character <= 0xFDEF
  5257. // Everything else not in iunreserved (this is all BMP)
  5258. || $character === 0x2F
  5259. || $character > 0x39 && $character < 0x41
  5260. || $character > 0x5A && $character < 0x61
  5261. || $character > 0x7A && $character < 0x7E
  5262. || $character > 0x7E && $character < 0xA0
  5263. || $character > 0xD7FF && $character < 0xF900
  5264. )
  5265. {
  5266. for ($j = $start; $j <= $i; $j++)
  5267. {
  5268. $string .= '%' . strtoupper($bytes[$j]);
  5269. }
  5270. }
  5271. else
  5272. {
  5273. for ($j = $start; $j <= $i; $j++)
  5274. {
  5275. $string .= chr(hexdec($bytes[$j]));
  5276. }
  5277. }
  5278. }
  5279. }
  5280. // If we have any bytes left over they are invalid (i.e., we are
  5281. // mid-way through a multi-byte sequence)
  5282. if ($remaining)
  5283. {
  5284. for ($j = $start; $j < $len; $j++)
  5285. {
  5286. $string .= '%' . strtoupper($bytes[$j]);
  5287. }
  5288. }
  5289. return $string;
  5290. }
  5291. protected function scheme_normalization()
  5292. {
  5293. if (isset($this->normalization[$this->scheme]['iuserinfo']) && $this->iuserinfo === $this->normalization[$this->scheme]['iuserinfo'])
  5294. {
  5295. $this->iuserinfo = null;
  5296. }
  5297. if (isset($this->normalization[$this->scheme]['ihost']) && $this->ihost === $this->normalization[$this->scheme]['ihost'])
  5298. {
  5299. $this->ihost = null;
  5300. }
  5301. if (isset($this->normalization[$this->scheme]['port']) && $this->port === $this->normalization[$this->scheme]['port'])
  5302. {
  5303. $this->port = null;
  5304. }
  5305. if (isset($this->normalization[$this->scheme]['ipath']) && $this->ipath === $this->normalization[$this->scheme]['ipath'])
  5306. {
  5307. $this->ipath = '';
  5308. }
  5309. if (isset($this->normalization[$this->scheme]['iquery']) && $this->iquery === $this->normalization[$this->scheme]['iquery'])
  5310. {
  5311. $this->iquery = null;
  5312. }
  5313. if (isset($this->normalization[$this->scheme]['ifragment']) && $this->ifragment === $this->normalization[$this->scheme]['ifragment'])
  5314. {
  5315. $this->ifragment = null;
  5316. }
  5317. }
  5318. public function is_valid()
  5319. {
  5320. $isauthority = $this->iuserinfo !== null || $this->ihost !== null || $this->port !== null;
  5321. if ($this->ipath !== '' &&
  5322. (
  5323. $isauthority && (
  5324. $this->ipath[0] !== '/' ||
  5325. substr($this->ipath, 0, 2) === '//'
  5326. ) ||
  5327. (
  5328. $this->scheme === null &&
  5329. !$isauthority &&
  5330. strpos($this->ipath, ':') !== false &&
  5331. (strpos($this->ipath, '/') === false ? true : strpos($this->ipath, ':') < strpos($this->ipath, '/'))
  5332. )
  5333. )
  5334. )
  5335. {
  5336. return false;
  5337. }
  5338. return true;
  5339. }
  5340. public function set_iri($iri)
  5341. {
  5342. static $cache;
  5343. if (!$cache)
  5344. {
  5345. $cache = array();
  5346. }
  5347. if ($iri === null)
  5348. {
  5349. return true;
  5350. }
  5351. elseif (isset($cache[$iri]))
  5352. {
  5353. list($this->scheme,
  5354. $this->iuserinfo,
  5355. $this->ihost,
  5356. $this->port,
  5357. $this->ipath,
  5358. $this->iquery,
  5359. $this->ifragment,
  5360. $return) = $cache[$iri];
  5361. return $return;
  5362. }
  5363. else
  5364. {
  5365. $parsed = $this->parse_iri((string) $iri);
  5366. $return = $this->set_scheme($parsed['scheme'])
  5367. && $this->set_authority($parsed['authority'])
  5368. && $this->set_path($parsed['path'])
  5369. && $this->set_query($parsed['query'])
  5370. && $this->set_fragment($parsed['fragment']);
  5371. $cache[$iri] = array($this->scheme,
  5372. $this->iuserinfo,
  5373. $this->ihost,
  5374. $this->port,
  5375. $this->ipath,
  5376. $this->iquery,
  5377. $this->ifragment,
  5378. $return);
  5379. return $return;
  5380. }
  5381. }
  5382. public function set_scheme($scheme)
  5383. {
  5384. if ($scheme === null)
  5385. {
  5386. $this->scheme = null;
  5387. }
  5388. elseif (!preg_match('/^[A-Za-z][0-9A-Za-z+\-.]*$/', $scheme))
  5389. {
  5390. $this->scheme = null;
  5391. return false;
  5392. }
  5393. else
  5394. {
  5395. $this->scheme = strtolower($scheme);
  5396. }
  5397. return true;
  5398. }
  5399. public function set_authority($authority)
  5400. {
  5401. static $cache;
  5402. if (!$cache)
  5403. $cache = array();
  5404. if ($authority === null)
  5405. {
  5406. $this->iuserinfo = null;
  5407. $this->ihost = null;
  5408. $this->port = null;
  5409. return true;
  5410. }
  5411. elseif (isset($cache[$authority]))
  5412. {
  5413. list($this->iuserinfo,
  5414. $this->ihost,
  5415. $this->port,
  5416. $return) = $cache[$authority];
  5417. return $return;
  5418. }
  5419. else
  5420. {
  5421. $remaining = $authority;
  5422. if (($iuserinfo_end = strrpos($remaining, '@')) !== false)
  5423. {
  5424. $iuserinfo = substr($remaining, 0, $iuserinfo_end);
  5425. $remaining = substr($remaining, $iuserinfo_end + 1);
  5426. }
  5427. else
  5428. {
  5429. $iuserinfo = null;
  5430. }
  5431. if (($port_start = strpos($remaining, ':', strpos($remaining, ']'))) !== false)
  5432. {
  5433. if (($port = substr($remaining, $port_start + 1)) === false)
  5434. {
  5435. $port = null;
  5436. }
  5437. $remaining = substr($remaining, 0, $port_start);
  5438. }
  5439. else
  5440. {
  5441. $port = null;
  5442. }
  5443. $return = $this->set_userinfo($iuserinfo) &&
  5444. $this->set_host($remaining) &&
  5445. $this->set_port($port);
  5446. $cache[$authority] = array($this->iuserinfo,
  5447. $this->ihost,
  5448. $this->port,
  5449. $return);
  5450. return $return;
  5451. }
  5452. }
  5453. public function set_userinfo($iuserinfo)
  5454. {
  5455. if ($iuserinfo === null)
  5456. {
  5457. $this->iuserinfo = null;
  5458. }
  5459. else
  5460. {
  5461. $this->iuserinfo = $this->replace_invalid_with_pct_encoding($iuserinfo, '!$&\'()*+,;=:');
  5462. $this->scheme_normalization();
  5463. }
  5464. return true;
  5465. }
  5466. public function set_host($ihost)
  5467. {
  5468. if ($ihost === null)
  5469. {
  5470. $this->ihost = null;
  5471. return true;
  5472. }
  5473. elseif (substr($ihost, 0, 1) === '[' && substr($ihost, -1) === ']')
  5474. {
  5475. if (SimplePie_Net_IPv6::check_ipv6(substr($ihost, 1, -1)))
  5476. {
  5477. $this->ihost = '[' . SimplePie_Net_IPv6::compress(substr($ihost, 1, -1)) . ']';
  5478. }
  5479. else
  5480. {
  5481. $this->ihost = null;
  5482. return false;
  5483. }
  5484. }
  5485. else
  5486. {
  5487. $ihost = $this->replace_invalid_with_pct_encoding($ihost, '!$&\'()*+,;=');
  5488. // Lowercase, but ignore pct-encoded sections (as they should
  5489. // remain uppercase). This must be done after the previous step
  5490. // as that can add unescaped characters.
  5491. $position = 0;
  5492. $strlen = strlen($ihost);
  5493. while (($position += strcspn($ihost, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ%', $position)) < $strlen)
  5494. {
  5495. if ($ihost[$position] === '%')
  5496. {
  5497. $position += 3;
  5498. }
  5499. else
  5500. {
  5501. $ihost[$position] = strtolower($ihost[$position]);
  5502. $position++;
  5503. }
  5504. }
  5505. $this->ihost = $ihost;
  5506. }
  5507. $this->scheme_normalization();
  5508. return true;
  5509. }
  5510. public function set_port($port)
  5511. {
  5512. if ($port === null)
  5513. {
  5514. $this->port = null;
  5515. return true;
  5516. }
  5517. elseif (strspn($port, '0123456789') === strlen($port))
  5518. {
  5519. $this->port = (int) $port;
  5520. $this->scheme_normalization();
  5521. return true;
  5522. }
  5523. else
  5524. {
  5525. $this->port = null;
  5526. return false;
  5527. }
  5528. }
  5529. public function set_path($ipath)
  5530. {
  5531. static $cache;
  5532. if (!$cache)
  5533. {
  5534. $cache = array();
  5535. }
  5536. $ipath = (string) $ipath;
  5537. if (isset($cache[$ipath]))
  5538. {
  5539. $this->ipath = $cache[$ipath][(int) ($this->scheme !== null)];
  5540. }
  5541. else
  5542. {
  5543. $valid = $this->replace_invalid_with_pct_encoding($ipath, '!$&\'()*+,;=@:/');
  5544. $removed = $this->remove_dot_segments($valid);
  5545. $cache[$ipath] = array($valid, $removed);
  5546. $this->ipath = ($this->scheme !== null) ? $removed : $valid;
  5547. }
  5548. $this->scheme_normalization();
  5549. return true;
  5550. }
  5551. public function set_query($iquery)
  5552. {
  5553. if ($iquery === null)
  5554. {
  5555. $this->iquery = null;
  5556. }
  5557. else
  5558. {
  5559. $this->iquery = $this->replace_invalid_with_pct_encoding($iquery, '!$&\'()*+,;=:@/?', true);
  5560. $this->scheme_normalization();
  5561. }
  5562. return true;
  5563. }
  5564. public function set_fragment($ifragment)
  5565. {
  5566. if ($ifragment === null)
  5567. {
  5568. $this->ifragment = null;
  5569. }
  5570. else
  5571. {
  5572. $this->ifragment = $this->replace_invalid_with_pct_encoding($ifragment, '!$&\'()*+,;=:@/?');
  5573. $this->scheme_normalization();
  5574. }
  5575. return true;
  5576. }
  5577. public function to_uri($string)
  5578. {
  5579. static $non_ascii;
  5580. if (!$non_ascii)
  5581. {
  5582. $non_ascii = implode('', range("\x80", "\xFF"));
  5583. }
  5584. $position = 0;
  5585. $strlen = strlen($string);
  5586. while (($position += strcspn($string, $non_ascii, $position)) < $strlen)
  5587. {
  5588. $string = substr_replace($string, sprintf('%%%02X', ord($string[$position])), $position, 1);
  5589. $position += 3;
  5590. $strlen += 2;
  5591. }
  5592. return $string;
  5593. }
  5594. public function get_iri()
  5595. {
  5596. if (!$this->is_valid())
  5597. {
  5598. return false;
  5599. }
  5600. $iri = '';
  5601. if ($this->scheme !== null)
  5602. {
  5603. $iri .= $this->scheme . ':';
  5604. }
  5605. if (($iauthority = $this->get_iauthority()) !== null)
  5606. {
  5607. $iri .= '//' . $iauthority;
  5608. }
  5609. if ($this->ipath !== '')
  5610. {
  5611. $iri .= $this->ipath;
  5612. }
  5613. elseif (!empty($this->normalization[$this->scheme]['ipath']) && $iauthority !== null && $iauthority !== '')
  5614. {
  5615. $iri .= $this->normalization[$this->scheme]['ipath'];
  5616. }
  5617. if ($this->iquery !== null)
  5618. {
  5619. $iri .= '?' . $this->iquery;
  5620. }
  5621. if ($this->ifragment !== null)
  5622. {
  5623. $iri .= '#' . $this->ifragment;
  5624. }
  5625. return $iri;
  5626. }
  5627. public function get_uri()
  5628. {
  5629. return $this->to_uri($this->get_iri());
  5630. }
  5631. protected function get_iauthority()
  5632. {
  5633. if ($this->iuserinfo !== null || $this->ihost !== null || $this->port !== null)
  5634. {
  5635. $iauthority = '';
  5636. if ($this->iuserinfo !== null)
  5637. {
  5638. $iauthority .= $this->iuserinfo . '@';
  5639. }
  5640. if ($this->ihost !== null)
  5641. {
  5642. $iauthority .= $this->ihost;
  5643. }
  5644. if ($this->port !== null)
  5645. {
  5646. $iauthority .= ':' . $this->port;
  5647. }
  5648. return $iauthority;
  5649. }
  5650. else
  5651. {
  5652. return null;
  5653. }
  5654. }
  5655. protected function get_authority()
  5656. {
  5657. $iauthority = $this->get_iauthority();
  5658. if (is_string($iauthority))
  5659. return $this->to_uri($iauthority);
  5660. else
  5661. return $iauthority;
  5662. }
  5663. }
  5664. class SimplePie_Item
  5665. {
  5666. var $feed;
  5667. var $data = array();
  5668. protected $registry;
  5669. public function __construct($feed, $data)
  5670. {
  5671. $this->feed = $feed;
  5672. $this->data = $data;
  5673. }
  5674. public function set_registry(SimplePie_Registry $registry)
  5675. {
  5676. $this->registry = $registry;
  5677. }
  5678. public function __toString()
  5679. {
  5680. return md5(serialize($this->data));
  5681. }
  5682. public function __destruct()
  5683. {
  5684. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
  5685. {
  5686. unset($this->feed);
  5687. }
  5688. }
  5689. public function get_item_tags($namespace, $tag)
  5690. {
  5691. if (isset($this->data['child'][$namespace][$tag]))
  5692. {
  5693. return $this->data['child'][$namespace][$tag];
  5694. }
  5695. else
  5696. {
  5697. return null;
  5698. }
  5699. }
  5700. public function get_base($element = array())
  5701. {
  5702. return $this->feed->get_base($element);
  5703. }
  5704. public function sanitize($data, $type, $base = '')
  5705. {
  5706. return $this->feed->sanitize($data, $type, $base);
  5707. }
  5708. public function get_feed()
  5709. {
  5710. return $this->feed;
  5711. }
  5712. public function get_id($hash = false)
  5713. {
  5714. if (!$hash)
  5715. {
  5716. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id'))
  5717. {
  5718. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5719. }
  5720. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'id'))
  5721. {
  5722. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5723. }
  5724. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
  5725. {
  5726. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5727. }
  5728. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'identifier'))
  5729. {
  5730. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5731. }
  5732. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'identifier'))
  5733. {
  5734. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5735. }
  5736. elseif (isset($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about']))
  5737. {
  5738. return $this->sanitize($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about'], SIMPLEPIE_CONSTRUCT_TEXT);
  5739. }
  5740. elseif (($return = $this->get_permalink()) !== null)
  5741. {
  5742. return $return;
  5743. }
  5744. elseif (($return = $this->get_title()) !== null)
  5745. {
  5746. return $return;
  5747. }
  5748. }
  5749. if ($this->get_permalink() !== null || $this->get_title() !== null)
  5750. {
  5751. return md5($this->get_permalink() . $this->get_title());
  5752. }
  5753. else
  5754. {
  5755. return md5(serialize($this->data));
  5756. }
  5757. }
  5758. public function get_title()
  5759. {
  5760. if (!isset($this->data['title']))
  5761. {
  5762. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  5763. {
  5764. $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]));
  5765. }
  5766. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  5767. {
  5768. $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]));
  5769. }
  5770. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  5771. {
  5772. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  5773. }
  5774. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  5775. {
  5776. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  5777. }
  5778. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  5779. {
  5780. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  5781. }
  5782. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  5783. {
  5784. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5785. }
  5786. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  5787. {
  5788. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5789. }
  5790. else
  5791. {
  5792. $this->data['title'] = null;
  5793. }
  5794. }
  5795. return $this->data['title'];
  5796. }
  5797. public function get_description($description_only = false)
  5798. {
  5799. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary'))
  5800. {
  5801. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  5802. }
  5803. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary'))
  5804. {
  5805. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  5806. }
  5807. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  5808. {
  5809. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  5810. }
  5811. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
  5812. {
  5813. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  5814. }
  5815. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  5816. {
  5817. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5818. }
  5819. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  5820. {
  5821. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5822. }
  5823. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  5824. {
  5825. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  5826. }
  5827. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  5828. {
  5829. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5830. }
  5831. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
  5832. {
  5833. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
  5834. }
  5835. elseif (!$description_only)
  5836. {
  5837. return $this->get_content(true);
  5838. }
  5839. else
  5840. {
  5841. return null;
  5842. }
  5843. }
  5844. public function get_content($content_only = false)
  5845. {
  5846. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content'))
  5847. {
  5848. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_content_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  5849. }
  5850. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content'))
  5851. {
  5852. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  5853. }
  5854. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded'))
  5855. {
  5856. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  5857. }
  5858. elseif (!$content_only)
  5859. {
  5860. return $this->get_description(true);
  5861. }
  5862. else
  5863. {
  5864. return null;
  5865. }
  5866. }
  5867. public function get_category($key = 0)
  5868. {
  5869. $categories = $this->get_categories();
  5870. if (isset($categories[$key]))
  5871. {
  5872. return $categories[$key];
  5873. }
  5874. else
  5875. {
  5876. return null;
  5877. }
  5878. }
  5879. public function get_categories()
  5880. {
  5881. $categories = array();
  5882. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  5883. {
  5884. $term = null;
  5885. $scheme = null;
  5886. $label = null;
  5887. if (isset($category['attribs']['']['term']))
  5888. {
  5889. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  5890. }
  5891. if (isset($category['attribs']['']['scheme']))
  5892. {
  5893. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5894. }
  5895. if (isset($category['attribs']['']['label']))
  5896. {
  5897. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  5898. }
  5899. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  5900. }
  5901. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
  5902. {
  5903. // This is really the label, but keep this as the term also for BC.
  5904. // Label will also work on retrieving because that falls back to term.
  5905. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5906. if (isset($category['attribs']['']['domain']))
  5907. {
  5908. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  5909. }
  5910. else
  5911. {
  5912. $scheme = null;
  5913. }
  5914. $categories[] = $this->registry->create('Category', array($term, $scheme, null));
  5915. }
  5916. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  5917. {
  5918. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  5919. }
  5920. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  5921. {
  5922. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  5923. }
  5924. if (!empty($categories))
  5925. {
  5926. return array_unique($categories);
  5927. }
  5928. else
  5929. {
  5930. return null;
  5931. }
  5932. }
  5933. public function get_author($key = 0)
  5934. {
  5935. $authors = $this->get_authors();
  5936. if (isset($authors[$key]))
  5937. {
  5938. return $authors[$key];
  5939. }
  5940. else
  5941. {
  5942. return null;
  5943. }
  5944. }
  5945. public function get_contributor($key = 0)
  5946. {
  5947. $contributors = $this->get_contributors();
  5948. if (isset($contributors[$key]))
  5949. {
  5950. return $contributors[$key];
  5951. }
  5952. else
  5953. {
  5954. return null;
  5955. }
  5956. }
  5957. public function get_contributors()
  5958. {
  5959. $contributors = array();
  5960. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  5961. {
  5962. $name = null;
  5963. $uri = null;
  5964. $email = null;
  5965. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  5966. {
  5967. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5968. }
  5969. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  5970. {
  5971. $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]));
  5972. }
  5973. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  5974. {
  5975. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5976. }
  5977. if ($name !== null || $email !== null || $uri !== null)
  5978. {
  5979. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  5980. }
  5981. }
  5982. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  5983. {
  5984. $name = null;
  5985. $url = null;
  5986. $email = null;
  5987. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  5988. {
  5989. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5990. }
  5991. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  5992. {
  5993. $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]));
  5994. }
  5995. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  5996. {
  5997. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5998. }
  5999. if ($name !== null || $email !== null || $url !== null)
  6000. {
  6001. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  6002. }
  6003. }
  6004. if (!empty($contributors))
  6005. {
  6006. return array_unique($contributors);
  6007. }
  6008. else
  6009. {
  6010. return null;
  6011. }
  6012. }
  6013. public function get_authors()
  6014. {
  6015. $authors = array();
  6016. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  6017. {
  6018. $name = null;
  6019. $uri = null;
  6020. $email = null;
  6021. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  6022. {
  6023. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6024. }
  6025. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  6026. {
  6027. $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]));
  6028. }
  6029. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  6030. {
  6031. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6032. }
  6033. if ($name !== null || $email !== null || $uri !== null)
  6034. {
  6035. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  6036. }
  6037. }
  6038. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  6039. {
  6040. $name = null;
  6041. $url = null;
  6042. $email = null;
  6043. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  6044. {
  6045. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6046. }
  6047. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  6048. {
  6049. $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]));
  6050. }
  6051. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  6052. {
  6053. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6054. }
  6055. if ($name !== null || $email !== null || $url !== null)
  6056. {
  6057. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  6058. }
  6059. }
  6060. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'author'))
  6061. {
  6062. $authors[] = $this->registry->create('Author', array(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)));
  6063. }
  6064. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  6065. {
  6066. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  6067. }
  6068. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  6069. {
  6070. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  6071. }
  6072. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  6073. {
  6074. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  6075. }
  6076. if (!empty($authors))
  6077. {
  6078. return array_unique($authors);
  6079. }
  6080. elseif (($source = $this->get_source()) && ($authors = $source->get_authors()))
  6081. {
  6082. return $authors;
  6083. }
  6084. elseif ($authors = $this->feed->get_authors())
  6085. {
  6086. return $authors;
  6087. }
  6088. else
  6089. {
  6090. return null;
  6091. }
  6092. }
  6093. public function get_copyright()
  6094. {
  6095. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  6096. {
  6097. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  6098. }
  6099. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  6100. {
  6101. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6102. }
  6103. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  6104. {
  6105. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6106. }
  6107. else
  6108. {
  6109. return null;
  6110. }
  6111. }
  6112. public function get_date($date_format = 'j F Y, g:i a')
  6113. {
  6114. if (!isset($this->data['date']))
  6115. {
  6116. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'))
  6117. {
  6118. $this->data['date']['raw'] = $return[0]['data'];
  6119. }
  6120. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  6121. {
  6122. $this->data['date']['raw'] = $return[0]['data'];
  6123. }
  6124. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'issued'))
  6125. {
  6126. $this->data['date']['raw'] = $return[0]['data'];
  6127. }
  6128. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'created'))
  6129. {
  6130. $this->data['date']['raw'] = $return[0]['data'];
  6131. }
  6132. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'modified'))
  6133. {
  6134. $this->data['date']['raw'] = $return[0]['data'];
  6135. }
  6136. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'pubDate'))
  6137. {
  6138. $this->data['date']['raw'] = $return[0]['data'];
  6139. }
  6140. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date'))
  6141. {
  6142. $this->data['date']['raw'] = $return[0]['data'];
  6143. }
  6144. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date'))
  6145. {
  6146. $this->data['date']['raw'] = $return[0]['data'];
  6147. }
  6148. if (!empty($this->data['date']['raw']))
  6149. {
  6150. $parser = $this->registry->call('Parse_Date', 'get');
  6151. $this->data['date']['parsed'] = $parser->parse($this->data['date']['raw']);
  6152. }
  6153. else
  6154. {
  6155. $this->data['date'] = null;
  6156. }
  6157. }
  6158. if ($this->data['date'])
  6159. {
  6160. $date_format = (string) $date_format;
  6161. switch ($date_format)
  6162. {
  6163. case '':
  6164. return $this->sanitize($this->data['date']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  6165. case 'U':
  6166. return $this->data['date']['parsed'];
  6167. default:
  6168. return date($date_format, $this->data['date']['parsed']);
  6169. }
  6170. }
  6171. else
  6172. {
  6173. return null;
  6174. }
  6175. }
  6176. public function get_updated_date($date_format = 'j F Y, g:i a')
  6177. {
  6178. if (!isset($this->data['updated']))
  6179. {
  6180. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  6181. {
  6182. $this->data['updated']['raw'] = $return[0]['data'];
  6183. }
  6184. if (!empty($this->data['updated']['raw']))
  6185. {
  6186. $parser = $this->registry->call('Parse_Date', 'get');
  6187. $this->data['updated']['parsed'] = $parser->parse($this->data['date']['raw']);
  6188. }
  6189. else
  6190. {
  6191. $this->data['updated'] = null;
  6192. }
  6193. }
  6194. if ($this->data['updated'])
  6195. {
  6196. $date_format = (string) $date_format;
  6197. switch ($date_format)
  6198. {
  6199. case '':
  6200. return $this->sanitize($this->data['updated']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  6201. case 'U':
  6202. return $this->data['updated']['parsed'];
  6203. default:
  6204. return date($date_format, $this->data['updated']['parsed']);
  6205. }
  6206. }
  6207. else
  6208. {
  6209. return null;
  6210. }
  6211. }
  6212. public function get_local_date($date_format = '%c')
  6213. {
  6214. if (!$date_format)
  6215. {
  6216. return $this->sanitize($this->get_date(''), SIMPLEPIE_CONSTRUCT_TEXT);
  6217. }
  6218. elseif (($date = $this->get_date('U')) !== null && $date !== false)
  6219. {
  6220. return strftime($date_format, $date);
  6221. }
  6222. else
  6223. {
  6224. return null;
  6225. }
  6226. }
  6227. public function get_gmdate($date_format = 'j F Y, g:i a')
  6228. {
  6229. $date = $this->get_date('U');
  6230. if ($date === null)
  6231. {
  6232. return null;
  6233. }
  6234. return gmdate($date_format, $date);
  6235. }
  6236. public function get_updated_gmdate($date_format = 'j F Y, g:i a')
  6237. {
  6238. $date = $this->get_updated_date('U');
  6239. if ($date === null)
  6240. {
  6241. return null;
  6242. }
  6243. return gmdate($date_format, $date);
  6244. }
  6245. public function get_permalink()
  6246. {
  6247. $link = $this->get_link();
  6248. $enclosure = $this->get_enclosure(0);
  6249. if ($link !== null)
  6250. {
  6251. return $link;
  6252. }
  6253. elseif ($enclosure !== null)
  6254. {
  6255. return $enclosure->get_link();
  6256. }
  6257. else
  6258. {
  6259. return null;
  6260. }
  6261. }
  6262. public function get_link($key = 0, $rel = 'alternate')
  6263. {
  6264. $links = $this->get_links($rel);
  6265. if ($links[$key] !== null)
  6266. {
  6267. return $links[$key];
  6268. }
  6269. else
  6270. {
  6271. return null;
  6272. }
  6273. }
  6274. public function get_links($rel = 'alternate')
  6275. {
  6276. if (!isset($this->data['links']))
  6277. {
  6278. $this->data['links'] = array();
  6279. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  6280. {
  6281. if (isset($link['attribs']['']['href']))
  6282. {
  6283. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  6284. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  6285. }
  6286. }
  6287. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
  6288. {
  6289. if (isset($link['attribs']['']['href']))
  6290. {
  6291. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  6292. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  6293. }
  6294. }
  6295. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  6296. {
  6297. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  6298. }
  6299. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  6300. {
  6301. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  6302. }
  6303. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  6304. {
  6305. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  6306. }
  6307. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
  6308. {
  6309. if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) === 'true')
  6310. {
  6311. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  6312. }
  6313. }
  6314. $keys = array_keys($this->data['links']);
  6315. foreach ($keys as $key)
  6316. {
  6317. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
  6318. {
  6319. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  6320. {
  6321. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  6322. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  6323. }
  6324. else
  6325. {
  6326. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  6327. }
  6328. }
  6329. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  6330. {
  6331. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  6332. }
  6333. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  6334. }
  6335. }
  6336. if (isset($this->data['links'][$rel]))
  6337. {
  6338. return $this->data['links'][$rel];
  6339. }
  6340. else
  6341. {
  6342. return null;
  6343. }
  6344. }
  6345. public function get_enclosure($key = 0, $prefer = null)
  6346. {
  6347. $enclosures = $this->get_enclosures();
  6348. if (isset($enclosures[$key]))
  6349. {
  6350. return $enclosures[$key];
  6351. }
  6352. else
  6353. {
  6354. return null;
  6355. }
  6356. }
  6357. public function get_enclosures()
  6358. {
  6359. if (!isset($this->data['enclosures']))
  6360. {
  6361. $this->data['enclosures'] = array();
  6362. // Elements
  6363. $captions_parent = null;
  6364. $categories_parent = null;
  6365. $copyrights_parent = null;
  6366. $credits_parent = null;
  6367. $description_parent = null;
  6368. $duration_parent = null;
  6369. $hashes_parent = null;
  6370. $keywords_parent = null;
  6371. $player_parent = null;
  6372. $ratings_parent = null;
  6373. $restrictions_parent = null;
  6374. $thumbnails_parent = null;
  6375. $title_parent = null;
  6376. // Let's do the channel and item-level ones first, and just re-use them if we need to.
  6377. $parent = $this->get_feed();
  6378. // CAPTIONS
  6379. if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  6380. {
  6381. foreach ($captions as $caption)
  6382. {
  6383. $caption_type = null;
  6384. $caption_lang = null;
  6385. $caption_startTime = null;
  6386. $caption_endTime = null;
  6387. $caption_text = null;
  6388. if (isset($caption['attribs']['']['type']))
  6389. {
  6390. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6391. }
  6392. if (isset($caption['attribs']['']['lang']))
  6393. {
  6394. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  6395. }
  6396. if (isset($caption['attribs']['']['start']))
  6397. {
  6398. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  6399. }
  6400. if (isset($caption['attribs']['']['end']))
  6401. {
  6402. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  6403. }
  6404. if (isset($caption['data']))
  6405. {
  6406. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6407. }
  6408. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  6409. }
  6410. }
  6411. elseif ($captions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  6412. {
  6413. foreach ($captions as $caption)
  6414. {
  6415. $caption_type = null;
  6416. $caption_lang = null;
  6417. $caption_startTime = null;
  6418. $caption_endTime = null;
  6419. $caption_text = null;
  6420. if (isset($caption['attribs']['']['type']))
  6421. {
  6422. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6423. }
  6424. if (isset($caption['attribs']['']['lang']))
  6425. {
  6426. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  6427. }
  6428. if (isset($caption['attribs']['']['start']))
  6429. {
  6430. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  6431. }
  6432. if (isset($caption['attribs']['']['end']))
  6433. {
  6434. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  6435. }
  6436. if (isset($caption['data']))
  6437. {
  6438. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6439. }
  6440. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  6441. }
  6442. }
  6443. if (is_array($captions_parent))
  6444. {
  6445. $captions_parent = array_values(array_unique($captions_parent));
  6446. }
  6447. // CATEGORIES
  6448. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  6449. {
  6450. $term = null;
  6451. $scheme = null;
  6452. $label = null;
  6453. if (isset($category['data']))
  6454. {
  6455. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6456. }
  6457. if (isset($category['attribs']['']['scheme']))
  6458. {
  6459. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6460. }
  6461. else
  6462. {
  6463. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  6464. }
  6465. if (isset($category['attribs']['']['label']))
  6466. {
  6467. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  6468. }
  6469. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  6470. }
  6471. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  6472. {
  6473. $term = null;
  6474. $scheme = null;
  6475. $label = null;
  6476. if (isset($category['data']))
  6477. {
  6478. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6479. }
  6480. if (isset($category['attribs']['']['scheme']))
  6481. {
  6482. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6483. }
  6484. else
  6485. {
  6486. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  6487. }
  6488. if (isset($category['attribs']['']['label']))
  6489. {
  6490. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  6491. }
  6492. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  6493. }
  6494. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'category') as $category)
  6495. {
  6496. $term = null;
  6497. $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
  6498. $label = null;
  6499. if (isset($category['attribs']['']['text']))
  6500. {
  6501. $label = $this->sanitize($category['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  6502. }
  6503. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  6504. if (isset($category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category']))
  6505. {
  6506. foreach ((array) $category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'] as $subcategory)
  6507. {
  6508. if (isset($subcategory['attribs']['']['text']))
  6509. {
  6510. $label = $this->sanitize($subcategory['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  6511. }
  6512. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  6513. }
  6514. }
  6515. }
  6516. if (is_array($categories_parent))
  6517. {
  6518. $categories_parent = array_values(array_unique($categories_parent));
  6519. }
  6520. // COPYRIGHT
  6521. if ($copyright = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  6522. {
  6523. $copyright_url = null;
  6524. $copyright_label = null;
  6525. if (isset($copyright[0]['attribs']['']['url']))
  6526. {
  6527. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  6528. }
  6529. if (isset($copyright[0]['data']))
  6530. {
  6531. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6532. }
  6533. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  6534. }
  6535. elseif ($copyright = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  6536. {
  6537. $copyright_url = null;
  6538. $copyright_label = null;
  6539. if (isset($copyright[0]['attribs']['']['url']))
  6540. {
  6541. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  6542. }
  6543. if (isset($copyright[0]['data']))
  6544. {
  6545. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6546. }
  6547. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  6548. }
  6549. // CREDITS
  6550. if ($credits = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  6551. {
  6552. foreach ($credits as $credit)
  6553. {
  6554. $credit_role = null;
  6555. $credit_scheme = null;
  6556. $credit_name = null;
  6557. if (isset($credit['attribs']['']['role']))
  6558. {
  6559. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  6560. }
  6561. if (isset($credit['attribs']['']['scheme']))
  6562. {
  6563. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6564. }
  6565. else
  6566. {
  6567. $credit_scheme = 'urn:ebu';
  6568. }
  6569. if (isset($credit['data']))
  6570. {
  6571. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6572. }
  6573. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  6574. }
  6575. }
  6576. elseif ($credits = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  6577. {
  6578. foreach ($credits as $credit)
  6579. {
  6580. $credit_role = null;
  6581. $credit_scheme = null;
  6582. $credit_name = null;
  6583. if (isset($credit['attribs']['']['role']))
  6584. {
  6585. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  6586. }
  6587. if (isset($credit['attribs']['']['scheme']))
  6588. {
  6589. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6590. }
  6591. else
  6592. {
  6593. $credit_scheme = 'urn:ebu';
  6594. }
  6595. if (isset($credit['data']))
  6596. {
  6597. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6598. }
  6599. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  6600. }
  6601. }
  6602. if (is_array($credits_parent))
  6603. {
  6604. $credits_parent = array_values(array_unique($credits_parent));
  6605. }
  6606. // DESCRIPTION
  6607. if ($description_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  6608. {
  6609. if (isset($description_parent[0]['data']))
  6610. {
  6611. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6612. }
  6613. }
  6614. elseif ($description_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  6615. {
  6616. if (isset($description_parent[0]['data']))
  6617. {
  6618. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6619. }
  6620. }
  6621. // DURATION
  6622. if ($duration_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'duration'))
  6623. {
  6624. $seconds = null;
  6625. $minutes = null;
  6626. $hours = null;
  6627. if (isset($duration_parent[0]['data']))
  6628. {
  6629. $temp = explode(':', $this->sanitize($duration_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  6630. if (sizeof($temp) > 0)
  6631. {
  6632. $seconds = (int) array_pop($temp);
  6633. }
  6634. if (sizeof($temp) > 0)
  6635. {
  6636. $minutes = (int) array_pop($temp);
  6637. $seconds += $minutes * 60;
  6638. }
  6639. if (sizeof($temp) > 0)
  6640. {
  6641. $hours = (int) array_pop($temp);
  6642. $seconds += $hours * 3600;
  6643. }
  6644. unset($temp);
  6645. $duration_parent = $seconds;
  6646. }
  6647. }
  6648. // HASHES
  6649. if ($hashes_iterator = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  6650. {
  6651. foreach ($hashes_iterator as $hash)
  6652. {
  6653. $value = null;
  6654. $algo = null;
  6655. if (isset($hash['data']))
  6656. {
  6657. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6658. }
  6659. if (isset($hash['attribs']['']['algo']))
  6660. {
  6661. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  6662. }
  6663. else
  6664. {
  6665. $algo = 'md5';
  6666. }
  6667. $hashes_parent[] = $algo.':'.$value;
  6668. }
  6669. }
  6670. elseif ($hashes_iterator = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  6671. {
  6672. foreach ($hashes_iterator as $hash)
  6673. {
  6674. $value = null;
  6675. $algo = null;
  6676. if (isset($hash['data']))
  6677. {
  6678. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6679. }
  6680. if (isset($hash['attribs']['']['algo']))
  6681. {
  6682. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  6683. }
  6684. else
  6685. {
  6686. $algo = 'md5';
  6687. }
  6688. $hashes_parent[] = $algo.':'.$value;
  6689. }
  6690. }
  6691. if (is_array($hashes_parent))
  6692. {
  6693. $hashes_parent = array_values(array_unique($hashes_parent));
  6694. }
  6695. // KEYWORDS
  6696. if ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  6697. {
  6698. if (isset($keywords[0]['data']))
  6699. {
  6700. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  6701. foreach ($temp as $word)
  6702. {
  6703. $keywords_parent[] = trim($word);
  6704. }
  6705. }
  6706. unset($temp);
  6707. }
  6708. elseif ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  6709. {
  6710. if (isset($keywords[0]['data']))
  6711. {
  6712. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  6713. foreach ($temp as $word)
  6714. {
  6715. $keywords_parent[] = trim($word);
  6716. }
  6717. }
  6718. unset($temp);
  6719. }
  6720. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  6721. {
  6722. if (isset($keywords[0]['data']))
  6723. {
  6724. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  6725. foreach ($temp as $word)
  6726. {
  6727. $keywords_parent[] = trim($word);
  6728. }
  6729. }
  6730. unset($temp);
  6731. }
  6732. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  6733. {
  6734. if (isset($keywords[0]['data']))
  6735. {
  6736. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  6737. foreach ($temp as $word)
  6738. {
  6739. $keywords_parent[] = trim($word);
  6740. }
  6741. }
  6742. unset($temp);
  6743. }
  6744. if (is_array($keywords_parent))
  6745. {
  6746. $keywords_parent = array_values(array_unique($keywords_parent));
  6747. }
  6748. // PLAYER
  6749. if ($player_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  6750. {
  6751. if (isset($player_parent[0]['attribs']['']['url']))
  6752. {
  6753. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6754. }
  6755. }
  6756. elseif ($player_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  6757. {
  6758. if (isset($player_parent[0]['attribs']['']['url']))
  6759. {
  6760. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6761. }
  6762. }
  6763. // RATINGS
  6764. if ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  6765. {
  6766. foreach ($ratings as $rating)
  6767. {
  6768. $rating_scheme = null;
  6769. $rating_value = null;
  6770. if (isset($rating['attribs']['']['scheme']))
  6771. {
  6772. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6773. }
  6774. else
  6775. {
  6776. $rating_scheme = 'urn:simple';
  6777. }
  6778. if (isset($rating['data']))
  6779. {
  6780. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6781. }
  6782. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  6783. }
  6784. }
  6785. elseif ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  6786. {
  6787. foreach ($ratings as $rating)
  6788. {
  6789. $rating_scheme = 'urn:itunes';
  6790. $rating_value = null;
  6791. if (isset($rating['data']))
  6792. {
  6793. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6794. }
  6795. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  6796. }
  6797. }
  6798. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  6799. {
  6800. foreach ($ratings as $rating)
  6801. {
  6802. $rating_scheme = null;
  6803. $rating_value = null;
  6804. if (isset($rating['attribs']['']['scheme']))
  6805. {
  6806. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6807. }
  6808. else
  6809. {
  6810. $rating_scheme = 'urn:simple';
  6811. }
  6812. if (isset($rating['data']))
  6813. {
  6814. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6815. }
  6816. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  6817. }
  6818. }
  6819. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  6820. {
  6821. foreach ($ratings as $rating)
  6822. {
  6823. $rating_scheme = 'urn:itunes';
  6824. $rating_value = null;
  6825. if (isset($rating['data']))
  6826. {
  6827. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6828. }
  6829. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  6830. }
  6831. }
  6832. if (is_array($ratings_parent))
  6833. {
  6834. $ratings_parent = array_values(array_unique($ratings_parent));
  6835. }
  6836. // RESTRICTIONS
  6837. if ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  6838. {
  6839. foreach ($restrictions as $restriction)
  6840. {
  6841. $restriction_relationship = null;
  6842. $restriction_type = null;
  6843. $restriction_value = null;
  6844. if (isset($restriction['attribs']['']['relationship']))
  6845. {
  6846. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  6847. }
  6848. if (isset($restriction['attribs']['']['type']))
  6849. {
  6850. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6851. }
  6852. if (isset($restriction['data']))
  6853. {
  6854. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6855. }
  6856. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  6857. }
  6858. }
  6859. elseif ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  6860. {
  6861. foreach ($restrictions as $restriction)
  6862. {
  6863. $restriction_relationship = 'allow';
  6864. $restriction_type = null;
  6865. $restriction_value = 'itunes';
  6866. if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
  6867. {
  6868. $restriction_relationship = 'deny';
  6869. }
  6870. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  6871. }
  6872. }
  6873. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  6874. {
  6875. foreach ($restrictions as $restriction)
  6876. {
  6877. $restriction_relationship = null;
  6878. $restriction_type = null;
  6879. $restriction_value = null;
  6880. if (isset($restriction['attribs']['']['relationship']))
  6881. {
  6882. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  6883. }
  6884. if (isset($restriction['attribs']['']['type']))
  6885. {
  6886. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6887. }
  6888. if (isset($restriction['data']))
  6889. {
  6890. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6891. }
  6892. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  6893. }
  6894. }
  6895. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  6896. {
  6897. foreach ($restrictions as $restriction)
  6898. {
  6899. $restriction_relationship = 'allow';
  6900. $restriction_type = null;
  6901. $restriction_value = 'itunes';
  6902. if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
  6903. {
  6904. $restriction_relationship = 'deny';
  6905. }
  6906. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  6907. }
  6908. }
  6909. if (is_array($restrictions_parent))
  6910. {
  6911. $restrictions_parent = array_values(array_unique($restrictions_parent));
  6912. }
  6913. else
  6914. {
  6915. $restrictions_parent = array(new SimplePie_Restriction('allow', null, 'default'));
  6916. }
  6917. // THUMBNAILS
  6918. if ($thumbnails = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  6919. {
  6920. foreach ($thumbnails as $thumbnail)
  6921. {
  6922. if (isset($thumbnail['attribs']['']['url']))
  6923. {
  6924. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6925. }
  6926. }
  6927. }
  6928. elseif ($thumbnails = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  6929. {
  6930. foreach ($thumbnails as $thumbnail)
  6931. {
  6932. if (isset($thumbnail['attribs']['']['url']))
  6933. {
  6934. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6935. }
  6936. }
  6937. }
  6938. // TITLES
  6939. if ($title_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  6940. {
  6941. if (isset($title_parent[0]['data']))
  6942. {
  6943. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6944. }
  6945. }
  6946. elseif ($title_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  6947. {
  6948. if (isset($title_parent[0]['data']))
  6949. {
  6950. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6951. }
  6952. }
  6953. // Clear the memory
  6954. unset($parent);
  6955. // Attributes
  6956. $bitrate = null;
  6957. $channels = null;
  6958. $duration = null;
  6959. $expression = null;
  6960. $framerate = null;
  6961. $height = null;
  6962. $javascript = null;
  6963. $lang = null;
  6964. $length = null;
  6965. $medium = null;
  6966. $samplingrate = null;
  6967. $type = null;
  6968. $url = null;
  6969. $width = null;
  6970. // Elements
  6971. $captions = null;
  6972. $categories = null;
  6973. $copyrights = null;
  6974. $credits = null;
  6975. $description = null;
  6976. $hashes = null;
  6977. $keywords = null;
  6978. $player = null;
  6979. $ratings = null;
  6980. $restrictions = null;
  6981. $thumbnails = null;
  6982. $title = null;
  6983. // If we have media:group tags, loop through them.
  6984. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group') as $group)
  6985. {
  6986. if(isset($group['child']) && isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
  6987. {
  6988. // If we have media:content tags, loop through them.
  6989. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
  6990. {
  6991. if (isset($content['attribs']['']['url']))
  6992. {
  6993. // Attributes
  6994. $bitrate = null;
  6995. $channels = null;
  6996. $duration = null;
  6997. $expression = null;
  6998. $framerate = null;
  6999. $height = null;
  7000. $javascript = null;
  7001. $lang = null;
  7002. $length = null;
  7003. $medium = null;
  7004. $samplingrate = null;
  7005. $type = null;
  7006. $url = null;
  7007. $width = null;
  7008. // Elements
  7009. $captions = null;
  7010. $categories = null;
  7011. $copyrights = null;
  7012. $credits = null;
  7013. $description = null;
  7014. $hashes = null;
  7015. $keywords = null;
  7016. $player = null;
  7017. $ratings = null;
  7018. $restrictions = null;
  7019. $thumbnails = null;
  7020. $title = null;
  7021. // Start checking the attributes of media:content
  7022. if (isset($content['attribs']['']['bitrate']))
  7023. {
  7024. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  7025. }
  7026. if (isset($content['attribs']['']['channels']))
  7027. {
  7028. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  7029. }
  7030. if (isset($content['attribs']['']['duration']))
  7031. {
  7032. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  7033. }
  7034. else
  7035. {
  7036. $duration = $duration_parent;
  7037. }
  7038. if (isset($content['attribs']['']['expression']))
  7039. {
  7040. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  7041. }
  7042. if (isset($content['attribs']['']['framerate']))
  7043. {
  7044. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  7045. }
  7046. if (isset($content['attribs']['']['height']))
  7047. {
  7048. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  7049. }
  7050. if (isset($content['attribs']['']['lang']))
  7051. {
  7052. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  7053. }
  7054. if (isset($content['attribs']['']['fileSize']))
  7055. {
  7056. $length = ceil($content['attribs']['']['fileSize']);
  7057. }
  7058. if (isset($content['attribs']['']['medium']))
  7059. {
  7060. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  7061. }
  7062. if (isset($content['attribs']['']['samplingrate']))
  7063. {
  7064. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  7065. }
  7066. if (isset($content['attribs']['']['type']))
  7067. {
  7068. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7069. }
  7070. if (isset($content['attribs']['']['width']))
  7071. {
  7072. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  7073. }
  7074. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  7075. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  7076. // CAPTIONS
  7077. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  7078. {
  7079. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  7080. {
  7081. $caption_type = null;
  7082. $caption_lang = null;
  7083. $caption_startTime = null;
  7084. $caption_endTime = null;
  7085. $caption_text = null;
  7086. if (isset($caption['attribs']['']['type']))
  7087. {
  7088. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7089. }
  7090. if (isset($caption['attribs']['']['lang']))
  7091. {
  7092. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  7093. }
  7094. if (isset($caption['attribs']['']['start']))
  7095. {
  7096. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  7097. }
  7098. if (isset($caption['attribs']['']['end']))
  7099. {
  7100. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  7101. }
  7102. if (isset($caption['data']))
  7103. {
  7104. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7105. }
  7106. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  7107. }
  7108. if (is_array($captions))
  7109. {
  7110. $captions = array_values(array_unique($captions));
  7111. }
  7112. }
  7113. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  7114. {
  7115. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  7116. {
  7117. $caption_type = null;
  7118. $caption_lang = null;
  7119. $caption_startTime = null;
  7120. $caption_endTime = null;
  7121. $caption_text = null;
  7122. if (isset($caption['attribs']['']['type']))
  7123. {
  7124. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7125. }
  7126. if (isset($caption['attribs']['']['lang']))
  7127. {
  7128. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  7129. }
  7130. if (isset($caption['attribs']['']['start']))
  7131. {
  7132. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  7133. }
  7134. if (isset($caption['attribs']['']['end']))
  7135. {
  7136. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  7137. }
  7138. if (isset($caption['data']))
  7139. {
  7140. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7141. }
  7142. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  7143. }
  7144. if (is_array($captions))
  7145. {
  7146. $captions = array_values(array_unique($captions));
  7147. }
  7148. }
  7149. else
  7150. {
  7151. $captions = $captions_parent;
  7152. }
  7153. // CATEGORIES
  7154. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  7155. {
  7156. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  7157. {
  7158. $term = null;
  7159. $scheme = null;
  7160. $label = null;
  7161. if (isset($category['data']))
  7162. {
  7163. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7164. }
  7165. if (isset($category['attribs']['']['scheme']))
  7166. {
  7167. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7168. }
  7169. else
  7170. {
  7171. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  7172. }
  7173. if (isset($category['attribs']['']['label']))
  7174. {
  7175. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  7176. }
  7177. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  7178. }
  7179. }
  7180. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  7181. {
  7182. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  7183. {
  7184. $term = null;
  7185. $scheme = null;
  7186. $label = null;
  7187. if (isset($category['data']))
  7188. {
  7189. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7190. }
  7191. if (isset($category['attribs']['']['scheme']))
  7192. {
  7193. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7194. }
  7195. else
  7196. {
  7197. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  7198. }
  7199. if (isset($category['attribs']['']['label']))
  7200. {
  7201. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  7202. }
  7203. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  7204. }
  7205. }
  7206. if (is_array($categories) && is_array($categories_parent))
  7207. {
  7208. $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
  7209. }
  7210. elseif (is_array($categories))
  7211. {
  7212. $categories = array_values(array_unique($categories));
  7213. }
  7214. elseif (is_array($categories_parent))
  7215. {
  7216. $categories = array_values(array_unique($categories_parent));
  7217. }
  7218. // COPYRIGHTS
  7219. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  7220. {
  7221. $copyright_url = null;
  7222. $copyright_label = null;
  7223. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  7224. {
  7225. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  7226. }
  7227. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  7228. {
  7229. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7230. }
  7231. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  7232. }
  7233. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  7234. {
  7235. $copyright_url = null;
  7236. $copyright_label = null;
  7237. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  7238. {
  7239. $copyright_url = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  7240. }
  7241. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  7242. {
  7243. $copyright_label = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7244. }
  7245. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  7246. }
  7247. else
  7248. {
  7249. $copyrights = $copyrights_parent;
  7250. }
  7251. // CREDITS
  7252. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  7253. {
  7254. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  7255. {
  7256. $credit_role = null;
  7257. $credit_scheme = null;
  7258. $credit_name = null;
  7259. if (isset($credit['attribs']['']['role']))
  7260. {
  7261. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  7262. }
  7263. if (isset($credit['attribs']['']['scheme']))
  7264. {
  7265. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7266. }
  7267. else
  7268. {
  7269. $credit_scheme = 'urn:ebu';
  7270. }
  7271. if (isset($credit['data']))
  7272. {
  7273. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7274. }
  7275. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  7276. }
  7277. if (is_array($credits))
  7278. {
  7279. $credits = array_values(array_unique($credits));
  7280. }
  7281. }
  7282. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  7283. {
  7284. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  7285. {
  7286. $credit_role = null;
  7287. $credit_scheme = null;
  7288. $credit_name = null;
  7289. if (isset($credit['attribs']['']['role']))
  7290. {
  7291. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  7292. }
  7293. if (isset($credit['attribs']['']['scheme']))
  7294. {
  7295. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7296. }
  7297. else
  7298. {
  7299. $credit_scheme = 'urn:ebu';
  7300. }
  7301. if (isset($credit['data']))
  7302. {
  7303. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7304. }
  7305. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  7306. }
  7307. if (is_array($credits))
  7308. {
  7309. $credits = array_values(array_unique($credits));
  7310. }
  7311. }
  7312. else
  7313. {
  7314. $credits = $credits_parent;
  7315. }
  7316. // DESCRIPTION
  7317. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  7318. {
  7319. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7320. }
  7321. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  7322. {
  7323. $description = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7324. }
  7325. else
  7326. {
  7327. $description = $description_parent;
  7328. }
  7329. // HASHES
  7330. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  7331. {
  7332. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  7333. {
  7334. $value = null;
  7335. $algo = null;
  7336. if (isset($hash['data']))
  7337. {
  7338. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7339. }
  7340. if (isset($hash['attribs']['']['algo']))
  7341. {
  7342. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  7343. }
  7344. else
  7345. {
  7346. $algo = 'md5';
  7347. }
  7348. $hashes[] = $algo.':'.$value;
  7349. }
  7350. if (is_array($hashes))
  7351. {
  7352. $hashes = array_values(array_unique($hashes));
  7353. }
  7354. }
  7355. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  7356. {
  7357. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  7358. {
  7359. $value = null;
  7360. $algo = null;
  7361. if (isset($hash['data']))
  7362. {
  7363. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7364. }
  7365. if (isset($hash['attribs']['']['algo']))
  7366. {
  7367. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  7368. }
  7369. else
  7370. {
  7371. $algo = 'md5';
  7372. }
  7373. $hashes[] = $algo.':'.$value;
  7374. }
  7375. if (is_array($hashes))
  7376. {
  7377. $hashes = array_values(array_unique($hashes));
  7378. }
  7379. }
  7380. else
  7381. {
  7382. $hashes = $hashes_parent;
  7383. }
  7384. // KEYWORDS
  7385. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  7386. {
  7387. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  7388. {
  7389. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  7390. foreach ($temp as $word)
  7391. {
  7392. $keywords[] = trim($word);
  7393. }
  7394. unset($temp);
  7395. }
  7396. if (is_array($keywords))
  7397. {
  7398. $keywords = array_values(array_unique($keywords));
  7399. }
  7400. }
  7401. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  7402. {
  7403. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  7404. {
  7405. $temp = explode(',', $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  7406. foreach ($temp as $word)
  7407. {
  7408. $keywords[] = trim($word);
  7409. }
  7410. unset($temp);
  7411. }
  7412. if (is_array($keywords))
  7413. {
  7414. $keywords = array_values(array_unique($keywords));
  7415. }
  7416. }
  7417. else
  7418. {
  7419. $keywords = $keywords_parent;
  7420. }
  7421. // PLAYER
  7422. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  7423. {
  7424. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  7425. }
  7426. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  7427. {
  7428. $player = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  7429. }
  7430. else
  7431. {
  7432. $player = $player_parent;
  7433. }
  7434. // RATINGS
  7435. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  7436. {
  7437. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  7438. {
  7439. $rating_scheme = null;
  7440. $rating_value = null;
  7441. if (isset($rating['attribs']['']['scheme']))
  7442. {
  7443. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7444. }
  7445. else
  7446. {
  7447. $rating_scheme = 'urn:simple';
  7448. }
  7449. if (isset($rating['data']))
  7450. {
  7451. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7452. }
  7453. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  7454. }
  7455. if (is_array($ratings))
  7456. {
  7457. $ratings = array_values(array_unique($ratings));
  7458. }
  7459. }
  7460. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  7461. {
  7462. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  7463. {
  7464. $rating_scheme = null;
  7465. $rating_value = null;
  7466. if (isset($rating['attribs']['']['scheme']))
  7467. {
  7468. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7469. }
  7470. else
  7471. {
  7472. $rating_scheme = 'urn:simple';
  7473. }
  7474. if (isset($rating['data']))
  7475. {
  7476. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7477. }
  7478. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  7479. }
  7480. if (is_array($ratings))
  7481. {
  7482. $ratings = array_values(array_unique($ratings));
  7483. }
  7484. }
  7485. else
  7486. {
  7487. $ratings = $ratings_parent;
  7488. }
  7489. // RESTRICTIONS
  7490. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  7491. {
  7492. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  7493. {
  7494. $restriction_relationship = null;
  7495. $restriction_type = null;
  7496. $restriction_value = null;
  7497. if (isset($restriction['attribs']['']['relationship']))
  7498. {
  7499. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  7500. }
  7501. if (isset($restriction['attribs']['']['type']))
  7502. {
  7503. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7504. }
  7505. if (isset($restriction['data']))
  7506. {
  7507. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7508. }
  7509. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  7510. }
  7511. if (is_array($restrictions))
  7512. {
  7513. $restrictions = array_values(array_unique($restrictions));
  7514. }
  7515. }
  7516. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  7517. {
  7518. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  7519. {
  7520. $restriction_relationship = null;
  7521. $restriction_type = null;
  7522. $restriction_value = null;
  7523. if (isset($restriction['attribs']['']['relationship']))
  7524. {
  7525. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  7526. }
  7527. if (isset($restriction['attribs']['']['type']))
  7528. {
  7529. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7530. }
  7531. if (isset($restriction['data']))
  7532. {
  7533. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7534. }
  7535. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  7536. }
  7537. if (is_array($restrictions))
  7538. {
  7539. $restrictions = array_values(array_unique($restrictions));
  7540. }
  7541. }
  7542. else
  7543. {
  7544. $restrictions = $restrictions_parent;
  7545. }
  7546. // THUMBNAILS
  7547. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  7548. {
  7549. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  7550. {
  7551. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  7552. }
  7553. if (is_array($thumbnails))
  7554. {
  7555. $thumbnails = array_values(array_unique($thumbnails));
  7556. }
  7557. }
  7558. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  7559. {
  7560. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  7561. {
  7562. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  7563. }
  7564. if (is_array($thumbnails))
  7565. {
  7566. $thumbnails = array_values(array_unique($thumbnails));
  7567. }
  7568. }
  7569. else
  7570. {
  7571. $thumbnails = $thumbnails_parent;
  7572. }
  7573. // TITLES
  7574. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  7575. {
  7576. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7577. }
  7578. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  7579. {
  7580. $title = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7581. }
  7582. else
  7583. {
  7584. $title = $title_parent;
  7585. }
  7586. $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));
  7587. }
  7588. }
  7589. }
  7590. }
  7591. // If we have standalone media:content tags, loop through them.
  7592. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
  7593. {
  7594. foreach ((array) $this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
  7595. {
  7596. if (isset($content['attribs']['']['url']) || isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  7597. {
  7598. // Attributes
  7599. $bitrate = null;
  7600. $channels = null;
  7601. $duration = null;
  7602. $expression = null;
  7603. $framerate = null;
  7604. $height = null;
  7605. $javascript = null;
  7606. $lang = null;
  7607. $length = null;
  7608. $medium = null;
  7609. $samplingrate = null;
  7610. $type = null;
  7611. $url = null;
  7612. $width = null;
  7613. // Elements
  7614. $captions = null;
  7615. $categories = null;
  7616. $copyrights = null;
  7617. $credits = null;
  7618. $description = null;
  7619. $hashes = null;
  7620. $keywords = null;
  7621. $player = null;
  7622. $ratings = null;
  7623. $restrictions = null;
  7624. $thumbnails = null;
  7625. $title = null;
  7626. // Start checking the attributes of media:content
  7627. if (isset($content['attribs']['']['bitrate']))
  7628. {
  7629. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  7630. }
  7631. if (isset($content['attribs']['']['channels']))
  7632. {
  7633. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  7634. }
  7635. if (isset($content['attribs']['']['duration']))
  7636. {
  7637. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  7638. }
  7639. else
  7640. {
  7641. $duration = $duration_parent;
  7642. }
  7643. if (isset($content['attribs']['']['expression']))
  7644. {
  7645. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  7646. }
  7647. if (isset($content['attribs']['']['framerate']))
  7648. {
  7649. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  7650. }
  7651. if (isset($content['attribs']['']['height']))
  7652. {
  7653. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  7654. }
  7655. if (isset($content['attribs']['']['lang']))
  7656. {
  7657. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  7658. }
  7659. if (isset($content['attribs']['']['fileSize']))
  7660. {
  7661. $length = ceil($content['attribs']['']['fileSize']);
  7662. }
  7663. if (isset($content['attribs']['']['medium']))
  7664. {
  7665. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  7666. }
  7667. if (isset($content['attribs']['']['samplingrate']))
  7668. {
  7669. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  7670. }
  7671. if (isset($content['attribs']['']['type']))
  7672. {
  7673. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7674. }
  7675. if (isset($content['attribs']['']['width']))
  7676. {
  7677. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  7678. }
  7679. if (isset($content['attribs']['']['url']))
  7680. {
  7681. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  7682. }
  7683. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  7684. // CAPTIONS
  7685. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  7686. {
  7687. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  7688. {
  7689. $caption_type = null;
  7690. $caption_lang = null;
  7691. $caption_startTime = null;
  7692. $caption_endTime = null;
  7693. $caption_text = null;
  7694. if (isset($caption['attribs']['']['type']))
  7695. {
  7696. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7697. }
  7698. if (isset($caption['attribs']['']['lang']))
  7699. {
  7700. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  7701. }
  7702. if (isset($caption['attribs']['']['start']))
  7703. {
  7704. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  7705. }
  7706. if (isset($caption['attribs']['']['end']))
  7707. {
  7708. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  7709. }
  7710. if (isset($caption['data']))
  7711. {
  7712. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7713. }
  7714. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  7715. }
  7716. if (is_array($captions))
  7717. {
  7718. $captions = array_values(array_unique($captions));
  7719. }
  7720. }
  7721. else
  7722. {
  7723. $captions = $captions_parent;
  7724. }
  7725. // CATEGORIES
  7726. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  7727. {
  7728. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  7729. {
  7730. $term = null;
  7731. $scheme = null;
  7732. $label = null;
  7733. if (isset($category['data']))
  7734. {
  7735. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7736. }
  7737. if (isset($category['attribs']['']['scheme']))
  7738. {
  7739. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7740. }
  7741. else
  7742. {
  7743. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  7744. }
  7745. if (isset($category['attribs']['']['label']))
  7746. {
  7747. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  7748. }
  7749. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  7750. }
  7751. }
  7752. if (is_array($categories) && is_array($categories_parent))
  7753. {
  7754. $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
  7755. }
  7756. elseif (is_array($categories))
  7757. {
  7758. $categories = array_values(array_unique($categories));
  7759. }
  7760. elseif (is_array($categories_parent))
  7761. {
  7762. $categories = array_values(array_unique($categories_parent));
  7763. }
  7764. else
  7765. {
  7766. $categories = null;
  7767. }
  7768. // COPYRIGHTS
  7769. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  7770. {
  7771. $copyright_url = null;
  7772. $copyright_label = null;
  7773. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  7774. {
  7775. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  7776. }
  7777. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  7778. {
  7779. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7780. }
  7781. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  7782. }
  7783. else
  7784. {
  7785. $copyrights = $copyrights_parent;
  7786. }
  7787. // CREDITS
  7788. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  7789. {
  7790. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  7791. {
  7792. $credit_role = null;
  7793. $credit_scheme = null;
  7794. $credit_name = null;
  7795. if (isset($credit['attribs']['']['role']))
  7796. {
  7797. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  7798. }
  7799. if (isset($credit['attribs']['']['scheme']))
  7800. {
  7801. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7802. }
  7803. else
  7804. {
  7805. $credit_scheme = 'urn:ebu';
  7806. }
  7807. if (isset($credit['data']))
  7808. {
  7809. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7810. }
  7811. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  7812. }
  7813. if (is_array($credits))
  7814. {
  7815. $credits = array_values(array_unique($credits));
  7816. }
  7817. }
  7818. else
  7819. {
  7820. $credits = $credits_parent;
  7821. }
  7822. // DESCRIPTION
  7823. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  7824. {
  7825. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7826. }
  7827. else
  7828. {
  7829. $description = $description_parent;
  7830. }
  7831. // HASHES
  7832. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  7833. {
  7834. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  7835. {
  7836. $value = null;
  7837. $algo = null;
  7838. if (isset($hash['data']))
  7839. {
  7840. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7841. }
  7842. if (isset($hash['attribs']['']['algo']))
  7843. {
  7844. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  7845. }
  7846. else
  7847. {
  7848. $algo = 'md5';
  7849. }
  7850. $hashes[] = $algo.':'.$value;
  7851. }
  7852. if (is_array($hashes))
  7853. {
  7854. $hashes = array_values(array_unique($hashes));
  7855. }
  7856. }
  7857. else
  7858. {
  7859. $hashes = $hashes_parent;
  7860. }
  7861. // KEYWORDS
  7862. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  7863. {
  7864. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  7865. {
  7866. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  7867. foreach ($temp as $word)
  7868. {
  7869. $keywords[] = trim($word);
  7870. }
  7871. unset($temp);
  7872. }
  7873. if (is_array($keywords))
  7874. {
  7875. $keywords = array_values(array_unique($keywords));
  7876. }
  7877. }
  7878. else
  7879. {
  7880. $keywords = $keywords_parent;
  7881. }
  7882. // PLAYER
  7883. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  7884. {
  7885. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  7886. }
  7887. else
  7888. {
  7889. $player = $player_parent;
  7890. }
  7891. // RATINGS
  7892. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  7893. {
  7894. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  7895. {
  7896. $rating_scheme = null;
  7897. $rating_value = null;
  7898. if (isset($rating['attribs']['']['scheme']))
  7899. {
  7900. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  7901. }
  7902. else
  7903. {
  7904. $rating_scheme = 'urn:simple';
  7905. }
  7906. if (isset($rating['data']))
  7907. {
  7908. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7909. }
  7910. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  7911. }
  7912. if (is_array($ratings))
  7913. {
  7914. $ratings = array_values(array_unique($ratings));
  7915. }
  7916. }
  7917. else
  7918. {
  7919. $ratings = $ratings_parent;
  7920. }
  7921. // RESTRICTIONS
  7922. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  7923. {
  7924. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  7925. {
  7926. $restriction_relationship = null;
  7927. $restriction_type = null;
  7928. $restriction_value = null;
  7929. if (isset($restriction['attribs']['']['relationship']))
  7930. {
  7931. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  7932. }
  7933. if (isset($restriction['attribs']['']['type']))
  7934. {
  7935. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7936. }
  7937. if (isset($restriction['data']))
  7938. {
  7939. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7940. }
  7941. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  7942. }
  7943. if (is_array($restrictions))
  7944. {
  7945. $restrictions = array_values(array_unique($restrictions));
  7946. }
  7947. }
  7948. else
  7949. {
  7950. $restrictions = $restrictions_parent;
  7951. }
  7952. // THUMBNAILS
  7953. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  7954. {
  7955. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  7956. {
  7957. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  7958. }
  7959. if (is_array($thumbnails))
  7960. {
  7961. $thumbnails = array_values(array_unique($thumbnails));
  7962. }
  7963. }
  7964. else
  7965. {
  7966. $thumbnails = $thumbnails_parent;
  7967. }
  7968. // TITLES
  7969. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  7970. {
  7971. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  7972. }
  7973. else
  7974. {
  7975. $title = $title_parent;
  7976. }
  7977. $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));
  7978. }
  7979. }
  7980. }
  7981. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  7982. {
  7983. if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure')
  7984. {
  7985. // Attributes
  7986. $bitrate = null;
  7987. $channels = null;
  7988. $duration = null;
  7989. $expression = null;
  7990. $framerate = null;
  7991. $height = null;
  7992. $javascript = null;
  7993. $lang = null;
  7994. $length = null;
  7995. $medium = null;
  7996. $samplingrate = null;
  7997. $type = null;
  7998. $url = null;
  7999. $width = null;
  8000. $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  8001. if (isset($link['attribs']['']['type']))
  8002. {
  8003. $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  8004. }
  8005. if (isset($link['attribs']['']['length']))
  8006. {
  8007. $length = ceil($link['attribs']['']['length']);
  8008. }
  8009. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  8010. $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));
  8011. }
  8012. }
  8013. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
  8014. {
  8015. if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure')
  8016. {
  8017. // Attributes
  8018. $bitrate = null;
  8019. $channels = null;
  8020. $duration = null;
  8021. $expression = null;
  8022. $framerate = null;
  8023. $height = null;
  8024. $javascript = null;
  8025. $lang = null;
  8026. $length = null;
  8027. $medium = null;
  8028. $samplingrate = null;
  8029. $type = null;
  8030. $url = null;
  8031. $width = null;
  8032. $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  8033. if (isset($link['attribs']['']['type']))
  8034. {
  8035. $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  8036. }
  8037. if (isset($link['attribs']['']['length']))
  8038. {
  8039. $length = ceil($link['attribs']['']['length']);
  8040. }
  8041. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  8042. $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));
  8043. }
  8044. }
  8045. if ($enclosure = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'enclosure'))
  8046. {
  8047. if (isset($enclosure[0]['attribs']['']['url']))
  8048. {
  8049. // Attributes
  8050. $bitrate = null;
  8051. $channels = null;
  8052. $duration = null;
  8053. $expression = null;
  8054. $framerate = null;
  8055. $height = null;
  8056. $javascript = null;
  8057. $lang = null;
  8058. $length = null;
  8059. $medium = null;
  8060. $samplingrate = null;
  8061. $type = null;
  8062. $url = null;
  8063. $width = null;
  8064. $url = $this->sanitize($enclosure[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($enclosure[0]));
  8065. if (isset($enclosure[0]['attribs']['']['type']))
  8066. {
  8067. $type = $this->sanitize($enclosure[0]['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  8068. }
  8069. if (isset($enclosure[0]['attribs']['']['length']))
  8070. {
  8071. $length = ceil($enclosure[0]['attribs']['']['length']);
  8072. }
  8073. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  8074. $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));
  8075. }
  8076. }
  8077. 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))
  8078. {
  8079. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  8080. $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));
  8081. }
  8082. $this->data['enclosures'] = array_values(array_unique($this->data['enclosures']));
  8083. }
  8084. if (!empty($this->data['enclosures']))
  8085. {
  8086. return $this->data['enclosures'];
  8087. }
  8088. else
  8089. {
  8090. return null;
  8091. }
  8092. }
  8093. public function get_latitude()
  8094. {
  8095. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  8096. {
  8097. return (float) $return[0]['data'];
  8098. }
  8099. 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))
  8100. {
  8101. return (float) $match[1];
  8102. }
  8103. else
  8104. {
  8105. return null;
  8106. }
  8107. }
  8108. public function get_longitude()
  8109. {
  8110. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  8111. {
  8112. return (float) $return[0]['data'];
  8113. }
  8114. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  8115. {
  8116. return (float) $return[0]['data'];
  8117. }
  8118. 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))
  8119. {
  8120. return (float) $match[2];
  8121. }
  8122. else
  8123. {
  8124. return null;
  8125. }
  8126. }
  8127. public function get_source()
  8128. {
  8129. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'source'))
  8130. {
  8131. return $this->registry->create('Source', array($this, $return[0]));
  8132. }
  8133. else
  8134. {
  8135. return null;
  8136. }
  8137. }
  8138. }
  8139. class SimplePie_Locator
  8140. {
  8141. var $useragent;
  8142. var $timeout;
  8143. var $file;
  8144. var $local = array();
  8145. var $elsewhere = array();
  8146. var $cached_entities = array();
  8147. var $http_base;
  8148. var $base;
  8149. var $base_location = 0;
  8150. var $checked_feeds = 0;
  8151. var $max_checked_feeds = 10;
  8152. protected $registry;
  8153. public function __construct(SimplePie_File $file, $timeout = 10, $useragent = null, $max_checked_feeds = 10)
  8154. {
  8155. $this->file = $file;
  8156. $this->useragent = $useragent;
  8157. $this->timeout = $timeout;
  8158. $this->max_checked_feeds = $max_checked_feeds;
  8159. $this->dom = new DOMDocument();
  8160. set_error_handler(array('SimplePie_Misc', 'silence_errors'));
  8161. $this->dom->loadHTML($this->file->body);
  8162. restore_error_handler();
  8163. }
  8164. public function set_registry(SimplePie_Registry $registry)
  8165. {
  8166. $this->registry = $registry;
  8167. }
  8168. public function find($type = SIMPLEPIE_LOCATOR_ALL, &$working)
  8169. {
  8170. if ($this->is_feed($this->file))
  8171. {
  8172. return $this->file;
  8173. }
  8174. if ($this->file->method & SIMPLEPIE_FILE_SOURCE_REMOTE)
  8175. {
  8176. $sniffer = $this->registry->create('Content_Type_Sniffer', array($this->file));
  8177. if ($sniffer->get_type() !== 'text/html')
  8178. {
  8179. return null;
  8180. }
  8181. }
  8182. if ($type & ~SIMPLEPIE_LOCATOR_NONE)
  8183. {
  8184. $this->get_base();
  8185. }
  8186. if ($type & SIMPLEPIE_LOCATOR_AUTODISCOVERY && $working = $this->autodiscovery())
  8187. {
  8188. return $working[0];
  8189. }
  8190. if ($type & (SIMPLEPIE_LOCATOR_LOCAL_EXTENSION | SIMPLEPIE_LOCATOR_LOCAL_BODY | SIMPLEPIE_LOCATOR_REMOTE_EXTENSION | SIMPLEPIE_LOCATOR_REMOTE_BODY) && $this->get_links())
  8191. {
  8192. if ($type & SIMPLEPIE_LOCATOR_LOCAL_EXTENSION && $working = $this->extension($this->local))
  8193. {
  8194. return $working;
  8195. }
  8196. if ($type & SIMPLEPIE_LOCATOR_LOCAL_BODY && $working = $this->body($this->local))
  8197. {
  8198. return $working;
  8199. }
  8200. if ($type & SIMPLEPIE_LOCATOR_REMOTE_EXTENSION && $working = $this->extension($this->elsewhere))
  8201. {
  8202. return $working;
  8203. }
  8204. if ($type & SIMPLEPIE_LOCATOR_REMOTE_BODY && $working = $this->body($this->elsewhere))
  8205. {
  8206. return $working;
  8207. }
  8208. }
  8209. return null;
  8210. }
  8211. public function is_feed($file)
  8212. {
  8213. if ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE)
  8214. {
  8215. $sniffer = $this->registry->create('Content_Type_Sniffer', array($file));
  8216. $sniffed = $sniffer->get_type();
  8217. if (in_array($sniffed, array('application/rss+xml', 'application/rdf+xml', 'text/rdf', 'application/atom+xml', 'text/xml', 'application/xml')))
  8218. {
  8219. return true;
  8220. }
  8221. else
  8222. {
  8223. return false;
  8224. }
  8225. }
  8226. elseif ($file->method & SIMPLEPIE_FILE_SOURCE_LOCAL)
  8227. {
  8228. return true;
  8229. }
  8230. else
  8231. {
  8232. return false;
  8233. }
  8234. }
  8235. public function get_base()
  8236. {
  8237. $this->http_base = $this->file->url;
  8238. $this->base = $this->http_base;
  8239. $elements = $this->dom->getElementsByTagName('base');
  8240. foreach ($elements as $element)
  8241. {
  8242. if ($element->hasAttribute('href'))
  8243. {
  8244. $this->base = $this->registry->call('Misc', 'absolutize_url', array(trim($element->getAttribute('href')), $this->http_base));
  8245. $this->base_location = method_exists($element, 'getLineNo') ? $element->getLineNo() : 0;
  8246. break;
  8247. }
  8248. }
  8249. }
  8250. public function autodiscovery()
  8251. {
  8252. $done = array();
  8253. $feeds = array();
  8254. $feeds = array_merge($feeds, $this->search_elements_by_tag('link', $done, $feeds));
  8255. $feeds = array_merge($feeds, $this->search_elements_by_tag('a', $done, $feeds));
  8256. $feeds = array_merge($feeds, $this->search_elements_by_tag('area', $done, $feeds));
  8257. if (!empty($feeds))
  8258. {
  8259. return array_values($feeds);
  8260. }
  8261. else
  8262. {
  8263. return null;
  8264. }
  8265. }
  8266. protected function search_elements_by_tag($name, &$done, $feeds)
  8267. {
  8268. $links = $this->dom->getElementsByTagName($name);
  8269. foreach ($links as $link)
  8270. {
  8271. if ($this->checked_feeds === $this->max_checked_feeds)
  8272. {
  8273. break;
  8274. }
  8275. if ($link->hasAttribute('href') && $link->hasAttribute('rel'))
  8276. {
  8277. $rel = array_unique($this->registry->call('Misc', 'space_seperated_tokens', array(strtolower($link->getAttribute('rel')))));
  8278. $line = method_exists($link, 'getLineNo') ? $link->getLineNo() : 1;
  8279. if ($this->base_location < $line)
  8280. {
  8281. $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->base));
  8282. }
  8283. else
  8284. {
  8285. $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->http_base));
  8286. }
  8287. 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]))
  8288. {
  8289. $this->checked_feeds++;
  8290. $headers = array(
  8291. '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',
  8292. );
  8293. $feed = $this->registry->create('File', array($href, $this->timeout, 5, $headers, $this->useragent));
  8294. 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))
  8295. {
  8296. $feeds[$href] = $feed;
  8297. }
  8298. }
  8299. $done[] = $href;
  8300. }
  8301. }
  8302. return $feeds;
  8303. }
  8304. public function get_links()
  8305. {
  8306. $links = $this->dom->getElementsByTagName('a');
  8307. foreach ($links as $link)
  8308. {
  8309. if ($link->hasAttribute('href'))
  8310. {
  8311. $href = trim($link->getAttribute('href'));
  8312. $parsed = $this->registry->call('Misc', 'parse_url', array($href));
  8313. if ($parsed['scheme'] === '' || preg_match('/^(http(s)|feed)?$/i', $parsed['scheme']))
  8314. {
  8315. if ($this->base_location < $link->getLineNo())
  8316. {
  8317. $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->base));
  8318. }
  8319. else
  8320. {
  8321. $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->http_base));
  8322. }
  8323. $current = $this->registry->call('Misc', 'parse_url', array($this->file->url));
  8324. if ($parsed['authority'] === '' || $parsed['authority'] === $current['authority'])
  8325. {
  8326. $this->local[] = $href;
  8327. }
  8328. else
  8329. {
  8330. $this->elsewhere[] = $href;
  8331. }
  8332. }
  8333. }
  8334. }
  8335. $this->local = array_unique($this->local);
  8336. $this->elsewhere = array_unique($this->elsewhere);
  8337. if (!empty($this->local) || !empty($this->elsewhere))
  8338. {
  8339. return true;
  8340. }
  8341. return null;
  8342. }
  8343. public function extension(&$array)
  8344. {
  8345. foreach ($array as $key => $value)
  8346. {
  8347. if ($this->checked_feeds === $this->max_checked_feeds)
  8348. {
  8349. break;
  8350. }
  8351. if (in_array(strtolower(strrchr($value, '.')), array('.rss', '.rdf', '.atom', '.xml')))
  8352. {
  8353. $this->checked_feeds++;
  8354. $headers = array(
  8355. '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',
  8356. );
  8357. $feed = $this->registry->create('File', array($value, $this->timeout, 5, $headers, $this->useragent));
  8358. 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))
  8359. {
  8360. return $feed;
  8361. }
  8362. else
  8363. {
  8364. unset($array[$key]);
  8365. }
  8366. }
  8367. }
  8368. return null;
  8369. }
  8370. public function body(&$array)
  8371. {
  8372. foreach ($array as $key => $value)
  8373. {
  8374. if ($this->checked_feeds === $this->max_checked_feeds)
  8375. {
  8376. break;
  8377. }
  8378. if (preg_match('/(rss|rdf|atom|xml)/i', $value))
  8379. {
  8380. $this->checked_feeds++;
  8381. $headers = array(
  8382. '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',
  8383. );
  8384. $feed = $this->registry->create('File', array($value, $this->timeout, 5, null, $this->useragent));
  8385. 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))
  8386. {
  8387. return $feed;
  8388. }
  8389. else
  8390. {
  8391. unset($array[$key]);
  8392. }
  8393. }
  8394. }
  8395. return null;
  8396. }
  8397. }
  8398. class SimplePie_Misc
  8399. {
  8400. public static function time_hms($seconds)
  8401. {
  8402. $time = '';
  8403. $hours = floor($seconds / 3600);
  8404. $remainder = $seconds % 3600;
  8405. if ($hours > 0)
  8406. {
  8407. $time .= $hours.':';
  8408. }
  8409. $minutes = floor($remainder / 60);
  8410. $seconds = $remainder % 60;
  8411. if ($minutes < 10 && $hours > 0)
  8412. {
  8413. $minutes = '0' . $minutes;
  8414. }
  8415. if ($seconds < 10)
  8416. {
  8417. $seconds = '0' . $seconds;
  8418. }
  8419. $time .= $minutes.':';
  8420. $time .= $seconds;
  8421. return $time;
  8422. }
  8423. public static function absolutize_url($relative, $base)
  8424. {
  8425. $iri = SimplePie_IRI::absolutize(new SimplePie_IRI($base), $relative);
  8426. return $iri->get_uri();
  8427. }
  8428. public static function get_element($realname, $string)
  8429. {
  8430. $return = array();
  8431. $name = preg_quote($realname, '/');
  8432. if (preg_match_all("/<($name)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$name>|(\/)?>)/siU", $string, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE))
  8433. {
  8434. for ($i = 0, $total_matches = count($matches); $i < $total_matches; $i++)
  8435. {
  8436. $return[$i]['tag'] = $realname;
  8437. $return[$i]['full'] = $matches[$i][0][0];
  8438. $return[$i]['offset'] = $matches[$i][0][1];
  8439. if (strlen($matches[$i][3][0]) <= 2)
  8440. {
  8441. $return[$i]['self_closing'] = true;
  8442. }
  8443. else
  8444. {
  8445. $return[$i]['self_closing'] = false;
  8446. $return[$i]['content'] = $matches[$i][4][0];
  8447. }
  8448. $return[$i]['attribs'] = array();
  8449. 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))
  8450. {
  8451. for ($j = 0, $total_attribs = count($attribs); $j < $total_attribs; $j++)
  8452. {
  8453. if (count($attribs[$j]) === 2)
  8454. {
  8455. $attribs[$j][2] = $attribs[$j][1];
  8456. }
  8457. $return[$i]['attribs'][strtolower($attribs[$j][1])]['data'] = SimplePie_Misc::entities_decode(end($attribs[$j]), 'UTF-8');
  8458. }
  8459. }
  8460. }
  8461. }
  8462. return $return;
  8463. }
  8464. public static function element_implode($element)
  8465. {
  8466. $full = "<$element[tag]";
  8467. foreach ($element['attribs'] as $key => $value)
  8468. {
  8469. $key = strtolower($key);
  8470. $full .= " $key=\"" . htmlspecialchars($value['data']) . '"';
  8471. }
  8472. if ($element['self_closing'])
  8473. {
  8474. $full .= ' />';
  8475. }
  8476. else
  8477. {
  8478. $full .= ">$element[content]</$element[tag]>";
  8479. }
  8480. return $full;
  8481. }
  8482. public static function error($message, $level, $file, $line)
  8483. {
  8484. if ((ini_get('error_reporting') & $level) > 0)
  8485. {
  8486. switch ($level)
  8487. {
  8488. case E_USER_ERROR:
  8489. $note = 'PHP Error';
  8490. break;
  8491. case E_USER_WARNING:
  8492. $note = 'PHP Warning';
  8493. break;
  8494. case E_USER_NOTICE:
  8495. $note = 'PHP Notice';
  8496. break;
  8497. default:
  8498. $note = 'Unknown Error';
  8499. break;
  8500. }
  8501. $log_error = true;
  8502. if (!function_exists('error_log'))
  8503. {
  8504. $log_error = false;
  8505. }
  8506. $log_file = @ini_get('error_log');
  8507. if (!empty($log_file) && ('syslog' !== $log_file) && !@is_writable($log_file))
  8508. {
  8509. $log_error = false;
  8510. }
  8511. if ($log_error)
  8512. {
  8513. @error_log("$note: $message in $file on line $line", 0);
  8514. }
  8515. }
  8516. return $message;
  8517. }
  8518. public static function fix_protocol($url, $http = 1)
  8519. {
  8520. $url = SimplePie_Misc::normalize_url($url);
  8521. $parsed = SimplePie_Misc::parse_url($url);
  8522. if ($parsed['scheme'] !== '' && $parsed['scheme'] !== 'http' && $parsed['scheme'] !== 'https')
  8523. {
  8524. return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['authority'], $parsed['path'], $parsed['query'], $parsed['fragment']), $http);
  8525. }
  8526. if ($parsed['scheme'] === '' && $parsed['authority'] === '' && !file_exists($url))
  8527. {
  8528. return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['path'], '', $parsed['query'], $parsed['fragment']), $http);
  8529. }
  8530. if ($http === 2 && $parsed['scheme'] !== '')
  8531. {
  8532. return "feed:$url";
  8533. }
  8534. elseif ($http === 3 && strtolower($parsed['scheme']) === 'http')
  8535. {
  8536. return substr_replace($url, 'podcast', 0, 4);
  8537. }
  8538. elseif ($http === 4 && strtolower($parsed['scheme']) === 'http')
  8539. {
  8540. return substr_replace($url, 'itpc', 0, 4);
  8541. }
  8542. else
  8543. {
  8544. return $url;
  8545. }
  8546. }
  8547. public static function parse_url($url)
  8548. {
  8549. $iri = new SimplePie_IRI($url);
  8550. return array(
  8551. 'scheme' => (string) $iri->scheme,
  8552. 'authority' => (string) $iri->authority,
  8553. 'path' => (string) $iri->path,
  8554. 'query' => (string) $iri->query,
  8555. 'fragment' => (string) $iri->fragment
  8556. );
  8557. }
  8558. public static function compress_parse_url($scheme = '', $authority = '', $path = '', $query = '', $fragment = '')
  8559. {
  8560. $iri = new SimplePie_IRI('');
  8561. $iri->scheme = $scheme;
  8562. $iri->authority = $authority;
  8563. $iri->path = $path;
  8564. $iri->query = $query;
  8565. $iri->fragment = $fragment;
  8566. return $iri->get_uri();
  8567. }
  8568. public static function normalize_url($url)
  8569. {
  8570. $iri = new SimplePie_IRI($url);
  8571. return $iri->get_uri();
  8572. }
  8573. public static function percent_encoding_normalization($match)
  8574. {
  8575. $integer = hexdec($match[1]);
  8576. if ($integer >= 0x41 && $integer <= 0x5A || $integer >= 0x61 && $integer <= 0x7A || $integer >= 0x30 && $integer <= 0x39 || $integer === 0x2D || $integer === 0x2E || $integer === 0x5F || $integer === 0x7E)
  8577. {
  8578. return chr($integer);
  8579. }
  8580. else
  8581. {
  8582. return strtoupper($match[0]);
  8583. }
  8584. }
  8585. public static function windows_1252_to_utf8($string)
  8586. {
  8587. 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");
  8588. return strtr($string, $convert_table);
  8589. }
  8590. public static function change_encoding($data, $input, $output)
  8591. {
  8592. $input = SimplePie_Misc::encoding($input);
  8593. $output = SimplePie_Misc::encoding($output);
  8594. // We fail to fail on non US-ASCII bytes
  8595. if ($input === 'US-ASCII')
  8596. {
  8597. static $non_ascii_octects = '';
  8598. if (!$non_ascii_octects)
  8599. {
  8600. for ($i = 0x80; $i <= 0xFF; $i++)
  8601. {
  8602. $non_ascii_octects .= chr($i);
  8603. }
  8604. }
  8605. $data = substr($data, 0, strcspn($data, $non_ascii_octects));
  8606. }
  8607. // This is first, as behaviour of this is completely predictable
  8608. if ($input === 'windows-1252' && $output === 'UTF-8')
  8609. {
  8610. return SimplePie_Misc::windows_1252_to_utf8($data);
  8611. }
  8612. // This is second, as behaviour of this varies only with PHP version (the middle part of this expression checks the encoding is supported).
  8613. elseif (function_exists('mb_convert_encoding') && ($return = SimplePie_Misc::change_encoding_mbstring($data, $input, $output)))
  8614. {
  8615. return $return;
  8616. }
  8617. // This is last, as behaviour of this varies with OS userland and PHP version
  8618. elseif (function_exists('iconv') && ($return = SimplePie_Misc::change_encoding_iconv($data, $input, $output)))
  8619. {
  8620. return $return;
  8621. }
  8622. // If we can't do anything, just fail
  8623. else
  8624. {
  8625. return false;
  8626. }
  8627. }
  8628. protected static function change_encoding_mbstring($data, $input, $output)
  8629. {
  8630. if ($input === 'windows-949')
  8631. {
  8632. $input = 'EUC-KR';
  8633. }
  8634. if ($output === 'windows-949')
  8635. {
  8636. $output = 'EUC-KR';
  8637. }
  8638. if ($input === 'Windows-31J')
  8639. {
  8640. $input = 'SJIS';
  8641. }
  8642. if ($output === 'Windows-31J')
  8643. {
  8644. $output = 'SJIS';
  8645. }
  8646. // Check that the encoding is supported
  8647. if (@mb_convert_encoding("\x80", 'UTF-16BE', $input) === "\x00\x80")
  8648. {
  8649. return false;
  8650. }
  8651. if (!in_array($input, mb_list_encodings()))
  8652. {
  8653. return false;
  8654. }
  8655. // Let's do some conversion
  8656. if ($return = @mb_convert_encoding($data, $output, $input))
  8657. {
  8658. return $return;
  8659. }
  8660. return false;
  8661. }
  8662. protected static function change_encoding_iconv($data, $input, $output)
  8663. {
  8664. return @iconv($input, $output, $data);
  8665. }
  8666. public static function encoding($charset)
  8667. {
  8668. // Normalization from UTS #22
  8669. switch (strtolower(preg_replace('/(?:[^a-zA-Z0-9]+|([^0-9])0+)/', '\1', $charset)))
  8670. {
  8671. case 'adobestandardencoding':
  8672. case 'csadobestandardencoding':
  8673. return 'Adobe-Standard-Encoding';
  8674. case 'adobesymbolencoding':
  8675. case 'cshppsmath':
  8676. return 'Adobe-Symbol-Encoding';
  8677. case 'ami1251':
  8678. case 'amiga1251':
  8679. return 'Amiga-1251';
  8680. case 'ansix31101983':
  8681. case 'csat5001983':
  8682. case 'csiso99naplps':
  8683. case 'isoir99':
  8684. case 'naplps':
  8685. return 'ANSI_X3.110-1983';
  8686. case 'arabic7':
  8687. case 'asmo449':
  8688. case 'csiso89asmo449':
  8689. case 'iso9036':
  8690. case 'isoir89':
  8691. return 'ASMO_449';
  8692. case 'big5':
  8693. case 'csbig5':
  8694. return 'Big5';
  8695. case 'big5hkscs':
  8696. return 'Big5-HKSCS';
  8697. case 'bocu1':
  8698. case 'csbocu1':
  8699. return 'BOCU-1';
  8700. case 'brf':
  8701. case 'csbrf':
  8702. return 'BRF';
  8703. case 'bs4730':
  8704. case 'csiso4unitedkingdom':
  8705. case 'gb':
  8706. case 'iso646gb':
  8707. case 'isoir4':
  8708. case 'uk':
  8709. return 'BS_4730';
  8710. case 'bsviewdata':
  8711. case 'csiso47bsviewdata':
  8712. case 'isoir47':
  8713. return 'BS_viewdata';
  8714. case 'cesu8':
  8715. case 'cscesu8':
  8716. return 'CESU-8';
  8717. case 'ca':
  8718. case 'csa71':
  8719. case 'csaz243419851':
  8720. case 'csiso121canadian1':
  8721. case 'iso646ca':
  8722. case 'isoir121':
  8723. return 'CSA_Z243.4-1985-1';
  8724. case 'csa72':
  8725. case 'csaz243419852':
  8726. case 'csiso122canadian2':
  8727. case 'iso646ca2':
  8728. case 'isoir122':
  8729. return 'CSA_Z243.4-1985-2';
  8730. case 'csaz24341985gr':
  8731. case 'csiso123csaz24341985gr':
  8732. case 'isoir123':
  8733. return 'CSA_Z243.4-1985-gr';
  8734. case 'csiso139csn369103':
  8735. case 'csn369103':
  8736. case 'isoir139':
  8737. return 'CSN_369103';
  8738. case 'csdecmcs':
  8739. case 'dec':
  8740. case 'decmcs':
  8741. return 'DEC-MCS';
  8742. case 'csiso21german':
  8743. case 'de':
  8744. case 'din66003':
  8745. case 'iso646de':
  8746. case 'isoir21':
  8747. return 'DIN_66003';
  8748. case 'csdkus':
  8749. case 'dkus':
  8750. return 'dk-us';
  8751. case 'csiso646danish':
  8752. case 'dk':
  8753. case 'ds2089':
  8754. case 'iso646dk':
  8755. return 'DS_2089';
  8756. case 'csibmebcdicatde':
  8757. case 'ebcdicatde':
  8758. return 'EBCDIC-AT-DE';
  8759. case 'csebcdicatdea':
  8760. case 'ebcdicatdea':
  8761. return 'EBCDIC-AT-DE-A';
  8762. case 'csebcdiccafr':
  8763. case 'ebcdiccafr':
  8764. return 'EBCDIC-CA-FR';
  8765. case 'csebcdicdkno':
  8766. case 'ebcdicdkno':
  8767. return 'EBCDIC-DK-NO';
  8768. case 'csebcdicdknoa':
  8769. case 'ebcdicdknoa':
  8770. return 'EBCDIC-DK-NO-A';
  8771. case 'csebcdices':
  8772. case 'ebcdices':
  8773. return 'EBCDIC-ES';
  8774. case 'csebcdicesa':
  8775. case 'ebcdicesa':
  8776. return 'EBCDIC-ES-A';
  8777. case 'csebcdicess':
  8778. case 'ebcdicess':
  8779. return 'EBCDIC-ES-S';
  8780. case 'csebcdicfise':
  8781. case 'ebcdicfise':
  8782. return 'EBCDIC-FI-SE';
  8783. case 'csebcdicfisea':
  8784. case 'ebcdicfisea':
  8785. return 'EBCDIC-FI-SE-A';
  8786. case 'csebcdicfr':
  8787. case 'ebcdicfr':
  8788. return 'EBCDIC-FR';
  8789. case 'csebcdicit':
  8790. case 'ebcdicit':
  8791. return 'EBCDIC-IT';
  8792. case 'csebcdicpt':
  8793. case 'ebcdicpt':
  8794. return 'EBCDIC-PT';
  8795. case 'csebcdicuk':
  8796. case 'ebcdicuk':
  8797. return 'EBCDIC-UK';
  8798. case 'csebcdicus':
  8799. case 'ebcdicus':
  8800. return 'EBCDIC-US';
  8801. case 'csiso111ecmacyrillic':
  8802. case 'ecmacyrillic':
  8803. case 'isoir111':
  8804. case 'koi8e':
  8805. return 'ECMA-cyrillic';
  8806. case 'csiso17spanish':
  8807. case 'es':
  8808. case 'iso646es':
  8809. case 'isoir17':
  8810. return 'ES';
  8811. case 'csiso85spanish2':
  8812. case 'es2':
  8813. case 'iso646es2':
  8814. case 'isoir85':
  8815. return 'ES2';
  8816. case 'cseucpkdfmtjapanese':
  8817. case 'eucjp':
  8818. case 'extendedunixcodepackedformatforjapanese':
  8819. return 'EUC-JP';
  8820. case 'cseucfixwidjapanese':
  8821. case 'extendedunixcodefixedwidthforjapanese':
  8822. return 'Extended_UNIX_Code_Fixed_Width_for_Japanese';
  8823. case 'gb18030':
  8824. return 'GB18030';
  8825. case 'chinese':
  8826. case 'cp936':
  8827. case 'csgb2312':
  8828. case 'csiso58gb231280':
  8829. case 'gb2312':
  8830. case 'gb231280':
  8831. case 'gbk':
  8832. case 'isoir58':
  8833. case 'ms936':
  8834. case 'windows936':
  8835. return 'GBK';
  8836. case 'cn':
  8837. case 'csiso57gb1988':
  8838. case 'gb198880':
  8839. case 'iso646cn':
  8840. case 'isoir57':
  8841. return 'GB_1988-80';
  8842. case 'csiso153gost1976874':
  8843. case 'gost1976874':
  8844. case 'isoir153':
  8845. case 'stsev35888':
  8846. return 'GOST_19768-74';
  8847. case 'csiso150':
  8848. case 'csiso150greekccitt':
  8849. case 'greekccitt':
  8850. case 'isoir150':
  8851. return 'greek-ccitt';
  8852. case 'csiso88greek7':
  8853. case 'greek7':
  8854. case 'isoir88':
  8855. return 'greek7';
  8856. case 'csiso18greek7old':
  8857. case 'greek7old':
  8858. case 'isoir18':
  8859. return 'greek7-old';
  8860. case 'cshpdesktop':
  8861. case 'hpdesktop':
  8862. return 'HP-DeskTop';
  8863. case 'cshplegal':
  8864. case 'hplegal':
  8865. return 'HP-Legal';
  8866. case 'cshpmath8':
  8867. case 'hpmath8':
  8868. return 'HP-Math8';
  8869. case 'cshppifont':
  8870. case 'hppifont':
  8871. return 'HP-Pi-font';
  8872. case 'cshproman8':
  8873. case 'hproman8':
  8874. case 'r8':
  8875. case 'roman8':
  8876. return 'hp-roman8';
  8877. case 'hzgb2312':
  8878. return 'HZ-GB-2312';
  8879. case 'csibmsymbols':
  8880. case 'ibmsymbols':
  8881. return 'IBM-Symbols';
  8882. case 'csibmthai':
  8883. case 'ibmthai':
  8884. return 'IBM-Thai';
  8885. case 'cp37':
  8886. case 'csibm37':
  8887. case 'ebcdiccpca':
  8888. case 'ebcdiccpnl':
  8889. case 'ebcdiccpus':
  8890. case 'ebcdiccpwt':
  8891. case 'ibm37':
  8892. return 'IBM037';
  8893. case 'cp38':
  8894. case 'csibm38':
  8895. case 'ebcdicint':
  8896. case 'ibm38':
  8897. return 'IBM038';
  8898. case 'cp273':
  8899. case 'csibm273':
  8900. case 'ibm273':
  8901. return 'IBM273';
  8902. case 'cp274':
  8903. case 'csibm274':
  8904. case 'ebcdicbe':
  8905. case 'ibm274':
  8906. return 'IBM274';
  8907. case 'cp275':
  8908. case 'csibm275':
  8909. case 'ebcdicbr':
  8910. case 'ibm275':
  8911. return 'IBM275';
  8912. case 'csibm277':
  8913. case 'ebcdiccpdk':
  8914. case 'ebcdiccpno':
  8915. case 'ibm277':
  8916. return 'IBM277';
  8917. case 'cp278':
  8918. case 'csibm278':
  8919. case 'ebcdiccpfi':
  8920. case 'ebcdiccpse':
  8921. case 'ibm278':
  8922. return 'IBM278';
  8923. case 'cp280':
  8924. case 'csibm280':
  8925. case 'ebcdiccpit':
  8926. case 'ibm280':
  8927. return 'IBM280';
  8928. case 'cp281':
  8929. case 'csibm281':
  8930. case 'ebcdicjpe':
  8931. case 'ibm281':
  8932. return 'IBM281';
  8933. case 'cp284':
  8934. case 'csibm284':
  8935. case 'ebcdiccpes':
  8936. case 'ibm284':
  8937. return 'IBM284';
  8938. case 'cp285':
  8939. case 'csibm285':
  8940. case 'ebcdiccpgb':
  8941. case 'ibm285':
  8942. return 'IBM285';
  8943. case 'cp290':
  8944. case 'csibm290':
  8945. case 'ebcdicjpkana':
  8946. case 'ibm290':
  8947. return 'IBM290';
  8948. case 'cp297':
  8949. case 'csibm297':
  8950. case 'ebcdiccpfr':
  8951. case 'ibm297':
  8952. return 'IBM297';
  8953. case 'cp420':
  8954. case 'csibm420':
  8955. case 'ebcdiccpar1':
  8956. case 'ibm420':
  8957. return 'IBM420';
  8958. case 'cp423':
  8959. case 'csibm423':
  8960. case 'ebcdiccpgr':
  8961. case 'ibm423':
  8962. return 'IBM423';
  8963. case 'cp424':
  8964. case 'csibm424':
  8965. case 'ebcdiccphe':
  8966. case 'ibm424':
  8967. return 'IBM424';
  8968. case '437':
  8969. case 'cp437':
  8970. case 'cspc8codepage437':
  8971. case 'ibm437':
  8972. return 'IBM437';
  8973. case 'cp500':
  8974. case 'csibm500':
  8975. case 'ebcdiccpbe':
  8976. case 'ebcdiccpch':
  8977. case 'ibm500':
  8978. return 'IBM500';
  8979. case 'cp775':
  8980. case 'cspc775baltic':
  8981. case 'ibm775':
  8982. return 'IBM775';
  8983. case '850':
  8984. case 'cp850':
  8985. case 'cspc850multilingual':
  8986. case 'ibm850':
  8987. return 'IBM850';
  8988. case '851':
  8989. case 'cp851':
  8990. case 'csibm851':
  8991. case 'ibm851':
  8992. return 'IBM851';
  8993. case '852':
  8994. case 'cp852':
  8995. case 'cspcp852':
  8996. case 'ibm852':
  8997. return 'IBM852';
  8998. case '855':
  8999. case 'cp855':
  9000. case 'csibm855':
  9001. case 'ibm855':
  9002. return 'IBM855';
  9003. case '857':
  9004. case 'cp857':
  9005. case 'csibm857':
  9006. case 'ibm857':
  9007. return 'IBM857';
  9008. case 'ccsid858':
  9009. case 'cp858':
  9010. case 'ibm858':
  9011. case 'pcmultilingual850euro':
  9012. return 'IBM00858';
  9013. case '860':
  9014. case 'cp860':
  9015. case 'csibm860':
  9016. case 'ibm860':
  9017. return 'IBM860';
  9018. case '861':
  9019. case 'cp861':
  9020. case 'cpis':
  9021. case 'csibm861':
  9022. case 'ibm861':
  9023. return 'IBM861';
  9024. case '862':
  9025. case 'cp862':
  9026. case 'cspc862latinhebrew':
  9027. case 'ibm862':
  9028. return 'IBM862';
  9029. case '863':
  9030. case 'cp863':
  9031. case 'csibm863':
  9032. case 'ibm863':
  9033. return 'IBM863';
  9034. case 'cp864':
  9035. case 'csibm864':
  9036. case 'ibm864':
  9037. return 'IBM864';
  9038. case '865':
  9039. case 'cp865':
  9040. case 'csibm865':
  9041. case 'ibm865':
  9042. return 'IBM865';
  9043. case '866':
  9044. case 'cp866':
  9045. case 'csibm866':
  9046. case 'ibm866':
  9047. return 'IBM866';
  9048. case 'cp868':
  9049. case 'cpar':
  9050. case 'csibm868':
  9051. case 'ibm868':
  9052. return 'IBM868';
  9053. case '869':
  9054. case 'cp869':
  9055. case 'cpgr':
  9056. case 'csibm869':
  9057. case 'ibm869':
  9058. return 'IBM869';
  9059. case 'cp870':
  9060. case 'csibm870':
  9061. case 'ebcdiccproece':
  9062. case 'ebcdiccpyu':
  9063. case 'ibm870':
  9064. return 'IBM870';
  9065. case 'cp871':
  9066. case 'csibm871':
  9067. case 'ebcdiccpis':
  9068. case 'ibm871':
  9069. return 'IBM871';
  9070. case 'cp880':
  9071. case 'csibm880':
  9072. case 'ebcdiccyrillic':
  9073. case 'ibm880':
  9074. return 'IBM880';
  9075. case 'cp891':
  9076. case 'csibm891':
  9077. case 'ibm891':
  9078. return 'IBM891';
  9079. case 'cp903':
  9080. case 'csibm903':
  9081. case 'ibm903':
  9082. return 'IBM903';
  9083. case '904':
  9084. case 'cp904':
  9085. case 'csibbm904':
  9086. case 'ibm904':
  9087. return 'IBM904';
  9088. case 'cp905':
  9089. case 'csibm905':
  9090. case 'ebcdiccptr':
  9091. case 'ibm905':
  9092. return 'IBM905';
  9093. case 'cp918':
  9094. case 'csibm918':
  9095. case 'ebcdiccpar2':
  9096. case 'ibm918':
  9097. return 'IBM918';
  9098. case 'ccsid924':
  9099. case 'cp924':
  9100. case 'ebcdiclatin9euro':
  9101. case 'ibm924':
  9102. return 'IBM00924';
  9103. case 'cp1026':
  9104. case 'csibm1026':
  9105. case 'ibm1026':
  9106. return 'IBM1026';
  9107. case 'ibm1047':
  9108. return 'IBM1047';
  9109. case 'ccsid1140':
  9110. case 'cp1140':
  9111. case 'ebcdicus37euro':
  9112. case 'ibm1140':
  9113. return 'IBM01140';
  9114. case 'ccsid1141':
  9115. case 'cp1141':
  9116. case 'ebcdicde273euro':
  9117. case 'ibm1141':
  9118. return 'IBM01141';
  9119. case 'ccsid1142':
  9120. case 'cp1142':
  9121. case 'ebcdicdk277euro':
  9122. case 'ebcdicno277euro':
  9123. case 'ibm1142':
  9124. return 'IBM01142';
  9125. case 'ccsid1143':
  9126. case 'cp1143':
  9127. case 'ebcdicfi278euro':
  9128. case 'ebcdicse278euro':
  9129. case 'ibm1143':
  9130. return 'IBM01143';
  9131. case 'ccsid1144':
  9132. case 'cp1144':
  9133. case 'ebcdicit280euro':
  9134. case 'ibm1144':
  9135. return 'IBM01144';
  9136. case 'ccsid1145':
  9137. case 'cp1145':
  9138. case 'ebcdices284euro':
  9139. case 'ibm1145':
  9140. return 'IBM01145';
  9141. case 'ccsid1146':
  9142. case 'cp1146':
  9143. case 'ebcdicgb285euro':
  9144. case 'ibm1146':
  9145. return 'IBM01146';
  9146. case 'ccsid1147':
  9147. case 'cp1147':
  9148. case 'ebcdicfr297euro':
  9149. case 'ibm1147':
  9150. return 'IBM01147';
  9151. case 'ccsid1148':
  9152. case 'cp1148':
  9153. case 'ebcdicinternational500euro':
  9154. case 'ibm1148':
  9155. return 'IBM01148';
  9156. case 'ccsid1149':
  9157. case 'cp1149':
  9158. case 'ebcdicis871euro':
  9159. case 'ibm1149':
  9160. return 'IBM01149';
  9161. case 'csiso143iecp271':
  9162. case 'iecp271':
  9163. case 'isoir143':
  9164. return 'IEC_P27-1';
  9165. case 'csiso49inis':
  9166. case 'inis':
  9167. case 'isoir49':
  9168. return 'INIS';
  9169. case 'csiso50inis8':
  9170. case 'inis8':
  9171. case 'isoir50':
  9172. return 'INIS-8';
  9173. case 'csiso51iniscyrillic':
  9174. case 'iniscyrillic':
  9175. case 'isoir51':
  9176. return 'INIS-cyrillic';
  9177. case 'csinvariant':
  9178. case 'invariant':
  9179. return 'INVARIANT';
  9180. case 'iso2022cn':
  9181. return 'ISO-2022-CN';
  9182. case 'iso2022cnext':
  9183. return 'ISO-2022-CN-EXT';
  9184. case 'csiso2022jp':
  9185. case 'iso2022jp':
  9186. return 'ISO-2022-JP';
  9187. case 'csiso2022jp2':
  9188. case 'iso2022jp2':
  9189. return 'ISO-2022-JP-2';
  9190. case 'csiso2022kr':
  9191. case 'iso2022kr':
  9192. return 'ISO-2022-KR';
  9193. case 'cswindows30latin1':
  9194. case 'iso88591windows30latin1':
  9195. return 'ISO-8859-1-Windows-3.0-Latin-1';
  9196. case 'cswindows31latin1':
  9197. case 'iso88591windows31latin1':
  9198. return 'ISO-8859-1-Windows-3.1-Latin-1';
  9199. case 'csisolatin2':
  9200. case 'iso88592':
  9201. case 'iso885921987':
  9202. case 'isoir101':
  9203. case 'l2':
  9204. case 'latin2':
  9205. return 'ISO-8859-2';
  9206. case 'cswindows31latin2':
  9207. case 'iso88592windowslatin2':
  9208. return 'ISO-8859-2-Windows-Latin-2';
  9209. case 'csisolatin3':
  9210. case 'iso88593':
  9211. case 'iso885931988':
  9212. case 'isoir109':
  9213. case 'l3':
  9214. case 'latin3':
  9215. return 'ISO-8859-3';
  9216. case 'csisolatin4':
  9217. case 'iso88594':
  9218. case 'iso885941988':
  9219. case 'isoir110':
  9220. case 'l4':
  9221. case 'latin4':
  9222. return 'ISO-8859-4';
  9223. case 'csisolatincyrillic':
  9224. case 'cyrillic':
  9225. case 'iso88595':
  9226. case 'iso885951988':
  9227. case 'isoir144':
  9228. return 'ISO-8859-5';
  9229. case 'arabic':
  9230. case 'asmo708':
  9231. case 'csisolatinarabic':
  9232. case 'ecma114':
  9233. case 'iso88596':
  9234. case 'iso885961987':
  9235. case 'isoir127':
  9236. return 'ISO-8859-6';
  9237. case 'csiso88596e':
  9238. case 'iso88596e':
  9239. return 'ISO-8859-6-E';
  9240. case 'csiso88596i':
  9241. case 'iso88596i':
  9242. return 'ISO-8859-6-I';
  9243. case 'csisolatingreek':
  9244. case 'ecma118':
  9245. case 'elot928':
  9246. case 'greek':
  9247. case 'greek8':
  9248. case 'iso88597':
  9249. case 'iso885971987':
  9250. case 'isoir126':
  9251. return 'ISO-8859-7';
  9252. case 'csisolatinhebrew':
  9253. case 'hebrew':
  9254. case 'iso88598':
  9255. case 'iso885981988':
  9256. case 'isoir138':
  9257. return 'ISO-8859-8';
  9258. case 'csiso88598e':
  9259. case 'iso88598e':
  9260. return 'ISO-8859-8-E';
  9261. case 'csiso88598i':
  9262. case 'iso88598i':
  9263. return 'ISO-8859-8-I';
  9264. case 'cswindows31latin5':
  9265. case 'iso88599windowslatin5':
  9266. return 'ISO-8859-9-Windows-Latin-5';
  9267. case 'csisolatin6':
  9268. case 'iso885910':
  9269. case 'iso8859101992':
  9270. case 'isoir157':
  9271. case 'l6':
  9272. case 'latin6':
  9273. return 'ISO-8859-10';
  9274. case 'iso885913':
  9275. return 'ISO-8859-13';
  9276. case 'iso885914':
  9277. case 'iso8859141998':
  9278. case 'isoceltic':
  9279. case 'isoir199':
  9280. case 'l8':
  9281. case 'latin8':
  9282. return 'ISO-8859-14';
  9283. case 'iso885915':
  9284. case 'latin9':
  9285. return 'ISO-8859-15';
  9286. case 'iso885916':
  9287. case 'iso8859162001':
  9288. case 'isoir226':
  9289. case 'l10':
  9290. case 'latin10':
  9291. return 'ISO-8859-16';
  9292. case 'iso10646j1':
  9293. return 'ISO-10646-J-1';
  9294. case 'csunicode':
  9295. case 'iso10646ucs2':
  9296. return 'ISO-10646-UCS-2';
  9297. case 'csucs4':
  9298. case 'iso10646ucs4':
  9299. return 'ISO-10646-UCS-4';
  9300. case 'csunicodeascii':
  9301. case 'iso10646ucsbasic':
  9302. return 'ISO-10646-UCS-Basic';
  9303. case 'csunicodelatin1':
  9304. case 'iso10646':
  9305. case 'iso10646unicodelatin1':
  9306. return 'ISO-10646-Unicode-Latin1';
  9307. case 'csiso10646utf1':
  9308. case 'iso10646utf1':
  9309. return 'ISO-10646-UTF-1';
  9310. case 'csiso115481':
  9311. case 'iso115481':
  9312. case 'isotr115481':
  9313. return 'ISO-11548-1';
  9314. case 'csiso90':
  9315. case 'isoir90':
  9316. return 'iso-ir-90';
  9317. case 'csunicodeibm1261':
  9318. case 'isounicodeibm1261':
  9319. return 'ISO-Unicode-IBM-1261';
  9320. case 'csunicodeibm1264':
  9321. case 'isounicodeibm1264':
  9322. return 'ISO-Unicode-IBM-1264';
  9323. case 'csunicodeibm1265':
  9324. case 'isounicodeibm1265':
  9325. return 'ISO-Unicode-IBM-1265';
  9326. case 'csunicodeibm1268':
  9327. case 'isounicodeibm1268':
  9328. return 'ISO-Unicode-IBM-1268';
  9329. case 'csunicodeibm1276':
  9330. case 'isounicodeibm1276':
  9331. return 'ISO-Unicode-IBM-1276';
  9332. case 'csiso646basic1983':
  9333. case 'iso646basic1983':
  9334. case 'ref':
  9335. return 'ISO_646.basic:1983';
  9336. case 'csiso2intlrefversion':
  9337. case 'irv':
  9338. case 'iso646irv1983':
  9339. case 'isoir2':
  9340. return 'ISO_646.irv:1983';
  9341. case 'csiso2033':
  9342. case 'e13b':
  9343. case 'iso20331983':
  9344. case 'isoir98':
  9345. return 'ISO_2033-1983';
  9346. case 'csiso5427cyrillic':
  9347. case 'iso5427':
  9348. case 'isoir37':
  9349. return 'ISO_5427';
  9350. case 'iso5427cyrillic1981':
  9351. case 'iso54271981':
  9352. case 'isoir54':
  9353. return 'ISO_5427:1981';
  9354. case 'csiso5428greek':
  9355. case 'iso54281980':
  9356. case 'isoir55':
  9357. return 'ISO_5428:1980';
  9358. case 'csiso6937add':
  9359. case 'iso6937225':
  9360. case 'isoir152':
  9361. return 'ISO_6937-2-25';
  9362. case 'csisotextcomm':
  9363. case 'iso69372add':
  9364. case 'isoir142':
  9365. return 'ISO_6937-2-add';
  9366. case 'csiso8859supp':
  9367. case 'iso8859supp':
  9368. case 'isoir154':
  9369. case 'latin125':
  9370. return 'ISO_8859-supp';
  9371. case 'csiso10367box':
  9372. case 'iso10367box':
  9373. case 'isoir155':
  9374. return 'ISO_10367-box';
  9375. case 'csiso15italian':
  9376. case 'iso646it':
  9377. case 'isoir15':
  9378. case 'it':
  9379. return 'IT';
  9380. case 'csiso13jisc6220jp':
  9381. case 'isoir13':
  9382. case 'jisc62201969':
  9383. case 'jisc62201969jp':
  9384. case 'katakana':
  9385. case 'x2017':
  9386. return 'JIS_C6220-1969-jp';
  9387. case 'csiso14jisc6220ro':
  9388. case 'iso646jp':
  9389. case 'isoir14':
  9390. case 'jisc62201969ro':
  9391. case 'jp':
  9392. return 'JIS_C6220-1969-ro';
  9393. case 'csiso42jisc62261978':
  9394. case 'isoir42':
  9395. case 'jisc62261978':
  9396. return 'JIS_C6226-1978';
  9397. case 'csiso87jisx208':
  9398. case 'isoir87':
  9399. case 'jisc62261983':
  9400. case 'jisx2081983':
  9401. case 'x208':
  9402. return 'JIS_C6226-1983';
  9403. case 'csiso91jisc62291984a':
  9404. case 'isoir91':
  9405. case 'jisc62291984a':
  9406. case 'jpocra':
  9407. return 'JIS_C6229-1984-a';
  9408. case 'csiso92jisc62991984b':
  9409. case 'iso646jpocrb':
  9410. case 'isoir92':
  9411. case 'jisc62291984b':
  9412. case 'jpocrb':
  9413. return 'JIS_C6229-1984-b';
  9414. case 'csiso93jis62291984badd':
  9415. case 'isoir93':
  9416. case 'jisc62291984badd':
  9417. case 'jpocrbadd':
  9418. return 'JIS_C6229-1984-b-add';
  9419. case 'csiso94jis62291984hand':
  9420. case 'isoir94':
  9421. case 'jisc62291984hand':
  9422. case 'jpocrhand':
  9423. return 'JIS_C6229-1984-hand';
  9424. case 'csiso95jis62291984handadd':
  9425. case 'isoir95':
  9426. case 'jisc62291984handadd':
  9427. case 'jpocrhandadd':
  9428. return 'JIS_C6229-1984-hand-add';
  9429. case 'csiso96jisc62291984kana':
  9430. case 'isoir96':
  9431. case 'jisc62291984kana':
  9432. return 'JIS_C6229-1984-kana';
  9433. case 'csjisencoding':
  9434. case 'jisencoding':
  9435. return 'JIS_Encoding';
  9436. case 'cshalfwidthkatakana':
  9437. case 'jisx201':
  9438. case 'x201':
  9439. return 'JIS_X0201';
  9440. case 'csiso159jisx2121990':
  9441. case 'isoir159':
  9442. case 'jisx2121990':
  9443. case 'x212':
  9444. return 'JIS_X0212-1990';
  9445. case 'csiso141jusib1002':
  9446. case 'iso646yu':
  9447. case 'isoir141':
  9448. case 'js':
  9449. case 'jusib1002':
  9450. case 'yu':
  9451. return 'JUS_I.B1.002';
  9452. case 'csiso147macedonian':
  9453. case 'isoir147':
  9454. case 'jusib1003mac':
  9455. case 'macedonian':
  9456. return 'JUS_I.B1.003-mac';
  9457. case 'csiso146serbian':
  9458. case 'isoir146':
  9459. case 'jusib1003serb':
  9460. case 'serbian':
  9461. return 'JUS_I.B1.003-serb';
  9462. case 'koi7switched':
  9463. return 'KOI7-switched';
  9464. case 'cskoi8r':
  9465. case 'koi8r':
  9466. return 'KOI8-R';
  9467. case 'koi8u':
  9468. return 'KOI8-U';
  9469. case 'csksc5636':
  9470. case 'iso646kr':
  9471. case 'ksc5636':
  9472. return 'KSC5636';
  9473. case 'cskz1048':
  9474. case 'kz1048':
  9475. case 'rk1048':
  9476. case 'strk10482002':
  9477. return 'KZ-1048';
  9478. case 'csiso19latingreek':
  9479. case 'isoir19':
  9480. case 'latingreek':
  9481. return 'latin-greek';
  9482. case 'csiso27latingreek1':
  9483. case 'isoir27':
  9484. case 'latingreek1':
  9485. return 'Latin-greek-1';
  9486. case 'csiso158lap':
  9487. case 'isoir158':
  9488. case 'lap':
  9489. case 'latinlap':
  9490. return 'latin-lap';
  9491. case 'csmacintosh':
  9492. case 'mac':
  9493. case 'macintosh':
  9494. return 'macintosh';
  9495. case 'csmicrosoftpublishing':
  9496. case 'microsoftpublishing':
  9497. return 'Microsoft-Publishing';
  9498. case 'csmnem':
  9499. case 'mnem':
  9500. return 'MNEM';
  9501. case 'csmnemonic':
  9502. case 'mnemonic':
  9503. return 'MNEMONIC';
  9504. case 'csiso86hungarian':
  9505. case 'hu':
  9506. case 'iso646hu':
  9507. case 'isoir86':
  9508. case 'msz77953':
  9509. return 'MSZ_7795.3';
  9510. case 'csnatsdano':
  9511. case 'isoir91':
  9512. case 'natsdano':
  9513. return 'NATS-DANO';
  9514. case 'csnatsdanoadd':
  9515. case 'isoir92':
  9516. case 'natsdanoadd':
  9517. return 'NATS-DANO-ADD';
  9518. case 'csnatssefi':
  9519. case 'isoir81':
  9520. case 'natssefi':
  9521. return 'NATS-SEFI';
  9522. case 'csnatssefiadd':
  9523. case 'isoir82':
  9524. case 'natssefiadd':
  9525. return 'NATS-SEFI-ADD';
  9526. case 'csiso151cuba':
  9527. case 'cuba':
  9528. case 'iso646cu':
  9529. case 'isoir151':
  9530. case 'ncnc1081':
  9531. return 'NC_NC00-10:81';
  9532. case 'csiso69french':
  9533. case 'fr':
  9534. case 'iso646fr':
  9535. case 'isoir69':
  9536. case 'nfz62010':
  9537. return 'NF_Z_62-010';
  9538. case 'csiso25french':
  9539. case 'iso646fr1':
  9540. case 'isoir25':
  9541. case 'nfz620101973':
  9542. return 'NF_Z_62-010_(1973)';
  9543. case 'csiso60danishnorwegian':
  9544. case 'csiso60norwegian1':
  9545. case 'iso646no':
  9546. case 'isoir60':
  9547. case 'no':
  9548. case 'ns45511':
  9549. return 'NS_4551-1';
  9550. case 'csiso61norwegian2':
  9551. case 'iso646no2':
  9552. case 'isoir61':
  9553. case 'no2':
  9554. case 'ns45512':
  9555. return 'NS_4551-2';
  9556. case 'osdebcdicdf3irv':
  9557. return 'OSD_EBCDIC_DF03_IRV';
  9558. case 'osdebcdicdf41':
  9559. return 'OSD_EBCDIC_DF04_1';
  9560. case 'osdebcdicdf415':
  9561. return 'OSD_EBCDIC_DF04_15';
  9562. case 'cspc8danishnorwegian':
  9563. case 'pc8danishnorwegian':
  9564. return 'PC8-Danish-Norwegian';
  9565. case 'cspc8turkish':
  9566. case 'pc8turkish':
  9567. return 'PC8-Turkish';
  9568. case 'csiso16portuguese':
  9569. case 'iso646pt':
  9570. case 'isoir16':
  9571. case 'pt':
  9572. return 'PT';
  9573. case 'csiso84portuguese2':
  9574. case 'iso646pt2':
  9575. case 'isoir84':
  9576. case 'pt2':
  9577. return 'PT2';
  9578. case 'cp154':
  9579. case 'csptcp154':
  9580. case 'cyrillicasian':
  9581. case 'pt154':
  9582. case 'ptcp154':
  9583. return 'PTCP154';
  9584. case 'scsu':
  9585. return 'SCSU';
  9586. case 'csiso10swedish':
  9587. case 'fi':
  9588. case 'iso646fi':
  9589. case 'iso646se':
  9590. case 'isoir10':
  9591. case 'se':
  9592. case 'sen850200b':
  9593. return 'SEN_850200_B';
  9594. case 'csiso11swedishfornames':
  9595. case 'iso646se2':
  9596. case 'isoir11':
  9597. case 'se2':
  9598. case 'sen850200c':
  9599. return 'SEN_850200_C';
  9600. case 'csiso102t617bit':
  9601. case 'isoir102':
  9602. case 't617bit':
  9603. return 'T.61-7bit';
  9604. case 'csiso103t618bit':
  9605. case 'isoir103':
  9606. case 't61':
  9607. case 't618bit':
  9608. return 'T.61-8bit';
  9609. case 'csiso128t101g2':
  9610. case 'isoir128':
  9611. case 't101g2':
  9612. return 'T.101-G2';
  9613. case 'cstscii':
  9614. case 'tscii':
  9615. return 'TSCII';
  9616. case 'csunicode11':
  9617. case 'unicode11':
  9618. return 'UNICODE-1-1';
  9619. case 'csunicode11utf7':
  9620. case 'unicode11utf7':
  9621. return 'UNICODE-1-1-UTF-7';
  9622. case 'csunknown8bit':
  9623. case 'unknown8bit':
  9624. return 'UNKNOWN-8BIT';
  9625. case 'ansix341968':
  9626. case 'ansix341986':
  9627. case 'ascii':
  9628. case 'cp367':
  9629. case 'csascii':
  9630. case 'ibm367':
  9631. case 'iso646irv1991':
  9632. case 'iso646us':
  9633. case 'isoir6':
  9634. case 'us':
  9635. case 'usascii':
  9636. return 'US-ASCII';
  9637. case 'csusdk':
  9638. case 'usdk':
  9639. return 'us-dk';
  9640. case 'utf7':
  9641. return 'UTF-7';
  9642. case 'utf8':
  9643. return 'UTF-8';
  9644. case 'utf16':
  9645. return 'UTF-16';
  9646. case 'utf16be':
  9647. return 'UTF-16BE';
  9648. case 'utf16le':
  9649. return 'UTF-16LE';
  9650. case 'utf32':
  9651. return 'UTF-32';
  9652. case 'utf32be':
  9653. return 'UTF-32BE';
  9654. case 'utf32le':
  9655. return 'UTF-32LE';
  9656. case 'csventurainternational':
  9657. case 'venturainternational':
  9658. return 'Ventura-International';
  9659. case 'csventuramath':
  9660. case 'venturamath':
  9661. return 'Ventura-Math';
  9662. case 'csventuraus':
  9663. case 'venturaus':
  9664. return 'Ventura-US';
  9665. case 'csiso70videotexsupp1':
  9666. case 'isoir70':
  9667. case 'videotexsuppl':
  9668. return 'videotex-suppl';
  9669. case 'csviqr':
  9670. case 'viqr':
  9671. return 'VIQR';
  9672. case 'csviscii':
  9673. case 'viscii':
  9674. return 'VISCII';
  9675. case 'csshiftjis':
  9676. case 'cswindows31j':
  9677. case 'mskanji':
  9678. case 'shiftjis':
  9679. case 'windows31j':
  9680. return 'Windows-31J';
  9681. case 'iso885911':
  9682. case 'tis620':
  9683. return 'windows-874';
  9684. case 'cseuckr':
  9685. case 'csksc56011987':
  9686. case 'euckr':
  9687. case 'isoir149':
  9688. case 'korean':
  9689. case 'ksc5601':
  9690. case 'ksc56011987':
  9691. case 'ksc56011989':
  9692. case 'windows949':
  9693. return 'windows-949';
  9694. case 'windows1250':
  9695. return 'windows-1250';
  9696. case 'windows1251':
  9697. return 'windows-1251';
  9698. case 'cp819':
  9699. case 'csisolatin1':
  9700. case 'ibm819':
  9701. case 'iso88591':
  9702. case 'iso885911987':
  9703. case 'isoir100':
  9704. case 'l1':
  9705. case 'latin1':
  9706. case 'windows1252':
  9707. return 'windows-1252';
  9708. case 'windows1253':
  9709. return 'windows-1253';
  9710. case 'csisolatin5':
  9711. case 'iso88599':
  9712. case 'iso885991989':
  9713. case 'isoir148':
  9714. case 'l5':
  9715. case 'latin5':
  9716. case 'windows1254':
  9717. return 'windows-1254';
  9718. case 'windows1255':
  9719. return 'windows-1255';
  9720. case 'windows1256':
  9721. return 'windows-1256';
  9722. case 'windows1257':
  9723. return 'windows-1257';
  9724. case 'windows1258':
  9725. return 'windows-1258';
  9726. default:
  9727. return $charset;
  9728. }
  9729. }
  9730. public static function get_curl_version()
  9731. {
  9732. if (is_array($curl = curl_version()))
  9733. {
  9734. $curl = $curl['version'];
  9735. }
  9736. elseif (substr($curl, 0, 5) === 'curl/')
  9737. {
  9738. $curl = substr($curl, 5, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 5));
  9739. }
  9740. elseif (substr($curl, 0, 8) === 'libcurl/')
  9741. {
  9742. $curl = substr($curl, 8, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 8));
  9743. }
  9744. else
  9745. {
  9746. $curl = 0;
  9747. }
  9748. return $curl;
  9749. }
  9750. public static function strip_comments($data)
  9751. {
  9752. $output = '';
  9753. while (($start = strpos($data, '<!--')) !== false)
  9754. {
  9755. $output .= substr($data, 0, $start);
  9756. if (($end = strpos($data, '-->', $start)) !== false)
  9757. {
  9758. $data = substr_replace($data, '', 0, $end + 3);
  9759. }
  9760. else
  9761. {
  9762. $data = '';
  9763. }
  9764. }
  9765. return $output . $data;
  9766. }
  9767. public static function parse_date($dt)
  9768. {
  9769. $parser = SimplePie_Parse_Date::get();
  9770. return $parser->parse($dt);
  9771. }
  9772. public static function entities_decode($data)
  9773. {
  9774. $decoder = new SimplePie_Decode_HTML_Entities($data);
  9775. return $decoder->parse();
  9776. }
  9777. public static function uncomment_rfc822($string)
  9778. {
  9779. $string = (string) $string;
  9780. $position = 0;
  9781. $length = strlen($string);
  9782. $depth = 0;
  9783. $output = '';
  9784. while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
  9785. {
  9786. $output .= substr($string, $position, $pos - $position);
  9787. $position = $pos + 1;
  9788. if ($string[$pos - 1] !== '\\')
  9789. {
  9790. $depth++;
  9791. while ($depth && $position < $length)
  9792. {
  9793. $position += strcspn($string, '()', $position);
  9794. if ($string[$position - 1] === '\\')
  9795. {
  9796. $position++;
  9797. continue;
  9798. }
  9799. elseif (isset($string[$position]))
  9800. {
  9801. switch ($string[$position])
  9802. {
  9803. case '(':
  9804. $depth++;
  9805. break;
  9806. case ')':
  9807. $depth--;
  9808. break;
  9809. }
  9810. $position++;
  9811. }
  9812. else
  9813. {
  9814. break;
  9815. }
  9816. }
  9817. }
  9818. else
  9819. {
  9820. $output .= '(';
  9821. }
  9822. }
  9823. $output .= substr($string, $position);
  9824. return $output;
  9825. }
  9826. public static function parse_mime($mime)
  9827. {
  9828. if (($pos = strpos($mime, ';')) === false)
  9829. {
  9830. return trim($mime);
  9831. }
  9832. else
  9833. {
  9834. return trim(substr($mime, 0, $pos));
  9835. }
  9836. }
  9837. public static function atom_03_construct_type($attribs)
  9838. {
  9839. if (isset($attribs['']['mode']) && strtolower(trim($attribs['']['mode']) === 'base64'))
  9840. {
  9841. $mode = SIMPLEPIE_CONSTRUCT_BASE64;
  9842. }
  9843. else
  9844. {
  9845. $mode = SIMPLEPIE_CONSTRUCT_NONE;
  9846. }
  9847. if (isset($attribs['']['type']))
  9848. {
  9849. switch (strtolower(trim($attribs['']['type'])))
  9850. {
  9851. case 'text':
  9852. case 'text/plain':
  9853. return SIMPLEPIE_CONSTRUCT_TEXT | $mode;
  9854. case 'html':
  9855. case 'text/html':
  9856. return SIMPLEPIE_CONSTRUCT_HTML | $mode;
  9857. case 'xhtml':
  9858. case 'application/xhtml+xml':
  9859. return SIMPLEPIE_CONSTRUCT_XHTML | $mode;
  9860. default:
  9861. return SIMPLEPIE_CONSTRUCT_NONE | $mode;
  9862. }
  9863. }
  9864. else
  9865. {
  9866. return SIMPLEPIE_CONSTRUCT_TEXT | $mode;
  9867. }
  9868. }
  9869. public static function atom_10_construct_type($attribs)
  9870. {
  9871. if (isset($attribs['']['type']))
  9872. {
  9873. switch (strtolower(trim($attribs['']['type'])))
  9874. {
  9875. case 'text':
  9876. return SIMPLEPIE_CONSTRUCT_TEXT;
  9877. case 'html':
  9878. return SIMPLEPIE_CONSTRUCT_HTML;
  9879. case 'xhtml':
  9880. return SIMPLEPIE_CONSTRUCT_XHTML;
  9881. default:
  9882. return SIMPLEPIE_CONSTRUCT_NONE;
  9883. }
  9884. }
  9885. return SIMPLEPIE_CONSTRUCT_TEXT;
  9886. }
  9887. public static function atom_10_content_construct_type($attribs)
  9888. {
  9889. if (isset($attribs['']['type']))
  9890. {
  9891. $type = strtolower(trim($attribs['']['type']));
  9892. switch ($type)
  9893. {
  9894. case 'text':
  9895. return SIMPLEPIE_CONSTRUCT_TEXT;
  9896. case 'html':
  9897. return SIMPLEPIE_CONSTRUCT_HTML;
  9898. case 'xhtml':
  9899. return SIMPLEPIE_CONSTRUCT_XHTML;
  9900. }
  9901. if (in_array(substr($type, -4), array('+xml', '/xml')) || substr($type, 0, 5) === 'text/')
  9902. {
  9903. return SIMPLEPIE_CONSTRUCT_NONE;
  9904. }
  9905. else
  9906. {
  9907. return SIMPLEPIE_CONSTRUCT_BASE64;
  9908. }
  9909. }
  9910. else
  9911. {
  9912. return SIMPLEPIE_CONSTRUCT_TEXT;
  9913. }
  9914. }
  9915. public static function is_isegment_nz_nc($string)
  9916. {
  9917. 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);
  9918. }
  9919. public static function space_seperated_tokens($string)
  9920. {
  9921. $space_characters = "\x20\x09\x0A\x0B\x0C\x0D";
  9922. $string_length = strlen($string);
  9923. $position = strspn($string, $space_characters);
  9924. $tokens = array();
  9925. while ($position < $string_length)
  9926. {
  9927. $len = strcspn($string, $space_characters, $position);
  9928. $tokens[] = substr($string, $position, $len);
  9929. $position += $len;
  9930. $position += strspn($string, $space_characters, $position);
  9931. }
  9932. return $tokens;
  9933. }
  9934. public static function codepoint_to_utf8($codepoint)
  9935. {
  9936. $codepoint = (int) $codepoint;
  9937. if ($codepoint < 0)
  9938. {
  9939. return false;
  9940. }
  9941. else if ($codepoint <= 0x7f)
  9942. {
  9943. return chr($codepoint);
  9944. }
  9945. else if ($codepoint <= 0x7ff)
  9946. {
  9947. return chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3f));
  9948. }
  9949. else if ($codepoint <= 0xffff)
  9950. {
  9951. return chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
  9952. }
  9953. else if ($codepoint <= 0x10ffff)
  9954. {
  9955. return chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
  9956. }
  9957. else
  9958. {
  9959. // U+FFFD REPLACEMENT CHARACTER
  9960. return "\xEF\xBF\xBD";
  9961. }
  9962. }
  9963. public static function parse_str($str)
  9964. {
  9965. $return = array();
  9966. $str = explode('&', $str);
  9967. foreach ($str as $section)
  9968. {
  9969. if (strpos($section, '=') !== false)
  9970. {
  9971. list($name, $value) = explode('=', $section, 2);
  9972. $return[urldecode($name)][] = urldecode($value);
  9973. }
  9974. else
  9975. {
  9976. $return[urldecode($section)][] = null;
  9977. }
  9978. }
  9979. return $return;
  9980. }
  9981. public static function xml_encoding($data, $registry)
  9982. {
  9983. // UTF-32 Big Endian BOM
  9984. if (substr($data, 0, 4) === "\x00\x00\xFE\xFF")
  9985. {
  9986. $encoding[] = 'UTF-32BE';
  9987. }
  9988. // UTF-32 Little Endian BOM
  9989. elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00")
  9990. {
  9991. $encoding[] = 'UTF-32LE';
  9992. }
  9993. // UTF-16 Big Endian BOM
  9994. elseif (substr($data, 0, 2) === "\xFE\xFF")
  9995. {
  9996. $encoding[] = 'UTF-16BE';
  9997. }
  9998. // UTF-16 Little Endian BOM
  9999. elseif (substr($data, 0, 2) === "\xFF\xFE")
  10000. {
  10001. $encoding[] = 'UTF-16LE';
  10002. }
  10003. // UTF-8 BOM
  10004. elseif (substr($data, 0, 3) === "\xEF\xBB\xBF")
  10005. {
  10006. $encoding[] = 'UTF-8';
  10007. }
  10008. // UTF-32 Big Endian Without BOM
  10009. 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")
  10010. {
  10011. if ($pos = strpos($data, "\x00\x00\x00\x3F\x00\x00\x00\x3E"))
  10012. {
  10013. $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32BE', 'UTF-8')));
  10014. if ($parser->parse())
  10015. {
  10016. $encoding[] = $parser->encoding;
  10017. }
  10018. }
  10019. $encoding[] = 'UTF-32BE';
  10020. }
  10021. // UTF-32 Little Endian Without BOM
  10022. 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")
  10023. {
  10024. if ($pos = strpos($data, "\x3F\x00\x00\x00\x3E\x00\x00\x00"))
  10025. {
  10026. $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32LE', 'UTF-8')));
  10027. if ($parser->parse())
  10028. {
  10029. $encoding[] = $parser->encoding;
  10030. }
  10031. }
  10032. $encoding[] = 'UTF-32LE';
  10033. }
  10034. // UTF-16 Big Endian Without BOM
  10035. elseif (substr($data, 0, 10) === "\x00\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C")
  10036. {
  10037. if ($pos = strpos($data, "\x00\x3F\x00\x3E"))
  10038. {
  10039. $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16BE', 'UTF-8')));
  10040. if ($parser->parse())
  10041. {
  10042. $encoding[] = $parser->encoding;
  10043. }
  10044. }
  10045. $encoding[] = 'UTF-16BE';
  10046. }
  10047. // UTF-16 Little Endian Without BOM
  10048. elseif (substr($data, 0, 10) === "\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C\x00")
  10049. {
  10050. if ($pos = strpos($data, "\x3F\x00\x3E\x00"))
  10051. {
  10052. $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16LE', 'UTF-8')));
  10053. if ($parser->parse())
  10054. {
  10055. $encoding[] = $parser->encoding;
  10056. }
  10057. }
  10058. $encoding[] = 'UTF-16LE';
  10059. }
  10060. // US-ASCII (or superset)
  10061. elseif (substr($data, 0, 5) === "\x3C\x3F\x78\x6D\x6C")
  10062. {
  10063. if ($pos = strpos($data, "\x3F\x3E"))
  10064. {
  10065. $parser = $registry->create('XML_Declaration_Parser', array(substr($data, 5, $pos - 5)));
  10066. if ($parser->parse())
  10067. {
  10068. $encoding[] = $parser->encoding;
  10069. }
  10070. }
  10071. $encoding[] = 'UTF-8';
  10072. }
  10073. // Fallback to UTF-8
  10074. else
  10075. {
  10076. $encoding[] = 'UTF-8';
  10077. }
  10078. return $encoding;
  10079. }
  10080. public static function output_javascript()
  10081. {
  10082. if (function_exists('ob_gzhandler'))
  10083. {
  10084. ob_start('ob_gzhandler');
  10085. }
  10086. header('Content-type: text/javascript; charset: UTF-8');
  10087. header('Cache-Control: must-revalidate');
  10088. header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'); // 7 days
  10089. ?>
  10090. function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {
  10091. if (placeholder != '') {
  10092. 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>');
  10093. }
  10094. else {
  10095. 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>');
  10096. }
  10097. }
  10098. function embed_flash(bgcolor, width, height, link, loop, type) {
  10099. 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>');
  10100. }
  10101. function embed_flv(width, height, link, placeholder, loop, player) {
  10102. 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>');
  10103. }
  10104. function embed_wmedia(width, height, link) {
  10105. document.writeln('<embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>');
  10106. }
  10107. <?php
  10108. }
  10109. public static function get_build()
  10110. {
  10111. $root = dirname(dirname(__FILE__));
  10112. if (file_exists($root . '/.git/index'))
  10113. {
  10114. return filemtime($root . '/.git/index');
  10115. }
  10116. elseif (file_exists($root . '/SimplePie'))
  10117. {
  10118. $time = 0;
  10119. foreach (glob($root . '/SimplePie/*.php') as $file)
  10120. {
  10121. if (($mtime = filemtime($file)) > $time)
  10122. {
  10123. $time = $mtime;
  10124. }
  10125. }
  10126. return $time;
  10127. }
  10128. elseif (file_exists(dirname(__FILE__) . '/Core.php'))
  10129. {
  10130. return filemtime(dirname(__FILE__) . '/Core.php');
  10131. }
  10132. else
  10133. {
  10134. return filemtime(__FILE__);
  10135. }
  10136. }
  10137. public static function debug(&$sp)
  10138. {
  10139. $info = 'SimplePie ' . SIMPLEPIE_VERSION . ' Build ' . SIMPLEPIE_BUILD . "\n";
  10140. $info .= 'PHP ' . PHP_VERSION . "\n";
  10141. if ($sp->error() !== null)
  10142. {
  10143. $info .= 'Error occurred: ' . $sp->error() . "\n";
  10144. }
  10145. else
  10146. {
  10147. $info .= "No error found.\n";
  10148. }
  10149. $info .= "Extensions:\n";
  10150. $extensions = array('pcre', 'curl', 'zlib', 'mbstring', 'iconv', 'xmlreader', 'xml');
  10151. foreach ($extensions as $ext)
  10152. {
  10153. if (extension_loaded($ext))
  10154. {
  10155. $info .= " $ext loaded\n";
  10156. switch ($ext)
  10157. {
  10158. case 'pcre':
  10159. $info .= ' Version ' . PCRE_VERSION . "\n";
  10160. break;
  10161. case 'curl':
  10162. $version = curl_version();
  10163. $info .= ' Version ' . $version['version'] . "\n";
  10164. break;
  10165. case 'mbstring':
  10166. $info .= ' Overloading: ' . mb_get_info('func_overload') . "\n";
  10167. break;
  10168. case 'iconv':
  10169. $info .= ' Version ' . ICONV_VERSION . "\n";
  10170. break;
  10171. case 'xml':
  10172. $info .= ' Version ' . LIBXML_DOTTED_VERSION . "\n";
  10173. break;
  10174. }
  10175. }
  10176. else
  10177. {
  10178. $info .= " $ext not loaded\n";
  10179. }
  10180. }
  10181. return $info;
  10182. }
  10183. public static function silence_errors($num, $str)
  10184. {
  10185. // No-op
  10186. }
  10187. }
  10188. class SimplePie_Net_IPv6
  10189. {
  10190. public static function uncompress($ip)
  10191. {
  10192. $c1 = -1;
  10193. $c2 = -1;
  10194. if (substr_count($ip, '::') === 1)
  10195. {
  10196. list($ip1, $ip2) = explode('::', $ip);
  10197. if ($ip1 === '')
  10198. {
  10199. $c1 = -1;
  10200. }
  10201. else
  10202. {
  10203. $c1 = substr_count($ip1, ':');
  10204. }
  10205. if ($ip2 === '')
  10206. {
  10207. $c2 = -1;
  10208. }
  10209. else
  10210. {
  10211. $c2 = substr_count($ip2, ':');
  10212. }
  10213. if (strpos($ip2, '.') !== false)
  10214. {
  10215. $c2++;
  10216. }
  10217. // ::
  10218. if ($c1 === -1 && $c2 === -1)
  10219. {
  10220. $ip = '0:0:0:0:0:0:0:0';
  10221. }
  10222. // ::xxx
  10223. else if ($c1 === -1)
  10224. {
  10225. $fill = str_repeat('0:', 7 - $c2);
  10226. $ip = str_replace('::', $fill, $ip);
  10227. }
  10228. // xxx::
  10229. else if ($c2 === -1)
  10230. {
  10231. $fill = str_repeat(':0', 7 - $c1);
  10232. $ip = str_replace('::', $fill, $ip);
  10233. }
  10234. // xxx::xxx
  10235. else
  10236. {
  10237. $fill = ':' . str_repeat('0:', 6 - $c2 - $c1);
  10238. $ip = str_replace('::', $fill, $ip);
  10239. }
  10240. }
  10241. return $ip;
  10242. }
  10243. public static function compress($ip)
  10244. {
  10245. // Prepare the IP to be compressed
  10246. $ip = self::uncompress($ip);
  10247. $ip_parts = self::split_v6_v4($ip);
  10248. // Replace all leading zeros
  10249. $ip_parts[0] = preg_replace('/(^|:)0+([0-9])/', '\1\2', $ip_parts[0]);
  10250. // Find bunches of zeros
  10251. if (preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE))
  10252. {
  10253. $max = 0;
  10254. $pos = null;
  10255. foreach ($matches[0] as $match)
  10256. {
  10257. if (strlen($match[0]) > $max)
  10258. {
  10259. $max = strlen($match[0]);
  10260. $pos = $match[1];
  10261. }
  10262. }
  10263. $ip_parts[0] = substr_replace($ip_parts[0], '::', $pos, $max);
  10264. }
  10265. if ($ip_parts[1] !== '')
  10266. {
  10267. return implode(':', $ip_parts);
  10268. }
  10269. else
  10270. {
  10271. return $ip_parts[0];
  10272. }
  10273. }
  10274. private static function split_v6_v4($ip)
  10275. {
  10276. if (strpos($ip, '.') !== false)
  10277. {
  10278. $pos = strrpos($ip, ':');
  10279. $ipv6_part = substr($ip, 0, $pos);
  10280. $ipv4_part = substr($ip, $pos + 1);
  10281. return array($ipv6_part, $ipv4_part);
  10282. }
  10283. else
  10284. {
  10285. return array($ip, '');
  10286. }
  10287. }
  10288. public static function check_ipv6($ip)
  10289. {
  10290. $ip = self::uncompress($ip);
  10291. list($ipv6, $ipv4) = self::split_v6_v4($ip);
  10292. $ipv6 = explode(':', $ipv6);
  10293. $ipv4 = explode('.', $ipv4);
  10294. if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4)
  10295. {
  10296. foreach ($ipv6 as $ipv6_part)
  10297. {
  10298. // The section can't be empty
  10299. if ($ipv6_part === '')
  10300. return false;
  10301. // Nor can it be over four characters
  10302. if (strlen($ipv6_part) > 4)
  10303. return false;
  10304. // Remove leading zeros (this is safe because of the above)
  10305. $ipv6_part = ltrim($ipv6_part, '0');
  10306. if ($ipv6_part === '')
  10307. $ipv6_part = '0';
  10308. // Check the value is valid
  10309. $value = hexdec($ipv6_part);
  10310. if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF)
  10311. return false;
  10312. }
  10313. if (count($ipv4) === 4)
  10314. {
  10315. foreach ($ipv4 as $ipv4_part)
  10316. {
  10317. $value = (int) $ipv4_part;
  10318. if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF)
  10319. return false;
  10320. }
  10321. }
  10322. return true;
  10323. }
  10324. else
  10325. {
  10326. return false;
  10327. }
  10328. }
  10329. public static function checkIPv6($ip)
  10330. {
  10331. return self::check_ipv6($ip);
  10332. }
  10333. }
  10334. class SimplePie_Parse_Date
  10335. {
  10336. var $date;
  10337. var $day = array(
  10338. // English
  10339. 'mon' => 1,
  10340. 'monday' => 1,
  10341. 'tue' => 2,
  10342. 'tuesday' => 2,
  10343. 'wed' => 3,
  10344. 'wednesday' => 3,
  10345. 'thu' => 4,
  10346. 'thursday' => 4,
  10347. 'fri' => 5,
  10348. 'friday' => 5,
  10349. 'sat' => 6,
  10350. 'saturday' => 6,
  10351. 'sun' => 7,
  10352. 'sunday' => 7,
  10353. // Dutch
  10354. 'maandag' => 1,
  10355. 'dinsdag' => 2,
  10356. 'woensdag' => 3,
  10357. 'donderdag' => 4,
  10358. 'vrijdag' => 5,
  10359. 'zaterdag' => 6,
  10360. 'zondag' => 7,
  10361. // French
  10362. 'lundi' => 1,
  10363. 'mardi' => 2,
  10364. 'mercredi' => 3,
  10365. 'jeudi' => 4,
  10366. 'vendredi' => 5,
  10367. 'samedi' => 6,
  10368. 'dimanche' => 7,
  10369. // German
  10370. 'montag' => 1,
  10371. 'dienstag' => 2,
  10372. 'mittwoch' => 3,
  10373. 'donnerstag' => 4,
  10374. 'freitag' => 5,
  10375. 'samstag' => 6,
  10376. 'sonnabend' => 6,
  10377. 'sonntag' => 7,
  10378. // Italian
  10379. 'lunedì' => 1,
  10380. 'martedì' => 2,
  10381. 'mercoledì' => 3,
  10382. 'giovedì' => 4,
  10383. 'venerdì' => 5,
  10384. 'sabato' => 6,
  10385. 'domenica' => 7,
  10386. // Spanish
  10387. 'lunes' => 1,
  10388. 'martes' => 2,
  10389. 'miércoles' => 3,
  10390. 'jueves' => 4,
  10391. 'viernes' => 5,
  10392. 'sábado' => 6,
  10393. 'domingo' => 7,
  10394. // Finnish
  10395. 'maanantai' => 1,
  10396. 'tiistai' => 2,
  10397. 'keskiviikko' => 3,
  10398. 'torstai' => 4,
  10399. 'perjantai' => 5,
  10400. 'lauantai' => 6,
  10401. 'sunnuntai' => 7,
  10402. // Hungarian
  10403. 'hétfő' => 1,
  10404. 'kedd' => 2,
  10405. 'szerda' => 3,
  10406. 'csütörtok' => 4,
  10407. 'péntek' => 5,
  10408. 'szombat' => 6,
  10409. 'vasárnap' => 7,
  10410. // Greek
  10411. 'Δευ' => 1,
  10412. 'Τρι' => 2,
  10413. 'Τετ' => 3,
  10414. 'Πεμ' => 4,
  10415. 'Παρ' => 5,
  10416. 'Σαβ' => 6,
  10417. 'Κυρ' => 7,
  10418. );
  10419. var $month = array(
  10420. // English
  10421. 'jan' => 1,
  10422. 'january' => 1,
  10423. 'feb' => 2,
  10424. 'february' => 2,
  10425. 'mar' => 3,
  10426. 'march' => 3,
  10427. 'apr' => 4,
  10428. 'april' => 4,
  10429. 'may' => 5,
  10430. // No long form of May
  10431. 'jun' => 6,
  10432. 'june' => 6,
  10433. 'jul' => 7,
  10434. 'july' => 7,
  10435. 'aug' => 8,
  10436. 'august' => 8,
  10437. 'sep' => 9,
  10438. 'september' => 8,
  10439. 'oct' => 10,
  10440. 'october' => 10,
  10441. 'nov' => 11,
  10442. 'november' => 11,
  10443. 'dec' => 12,
  10444. 'december' => 12,
  10445. // Dutch
  10446. 'januari' => 1,
  10447. 'februari' => 2,
  10448. 'maart' => 3,
  10449. 'april' => 4,
  10450. 'mei' => 5,
  10451. 'juni' => 6,
  10452. 'juli' => 7,
  10453. 'augustus' => 8,
  10454. 'september' => 9,
  10455. 'oktober' => 10,
  10456. 'november' => 11,
  10457. 'december' => 12,
  10458. // French
  10459. 'janvier' => 1,
  10460. 'février' => 2,
  10461. 'mars' => 3,
  10462. 'avril' => 4,
  10463. 'mai' => 5,
  10464. 'juin' => 6,
  10465. 'juillet' => 7,
  10466. 'août' => 8,
  10467. 'septembre' => 9,
  10468. 'octobre' => 10,
  10469. 'novembre' => 11,
  10470. 'décembre' => 12,
  10471. // German
  10472. 'januar' => 1,
  10473. 'februar' => 2,
  10474. 'märz' => 3,
  10475. 'april' => 4,
  10476. 'mai' => 5,
  10477. 'juni' => 6,
  10478. 'juli' => 7,
  10479. 'august' => 8,
  10480. 'september' => 9,
  10481. 'oktober' => 10,
  10482. 'november' => 11,
  10483. 'dezember' => 12,
  10484. // Italian
  10485. 'gennaio' => 1,
  10486. 'febbraio' => 2,
  10487. 'marzo' => 3,
  10488. 'aprile' => 4,
  10489. 'maggio' => 5,
  10490. 'giugno' => 6,
  10491. 'luglio' => 7,
  10492. 'agosto' => 8,
  10493. 'settembre' => 9,
  10494. 'ottobre' => 10,
  10495. 'novembre' => 11,
  10496. 'dicembre' => 12,
  10497. // Spanish
  10498. 'enero' => 1,
  10499. 'febrero' => 2,
  10500. 'marzo' => 3,
  10501. 'abril' => 4,
  10502. 'mayo' => 5,
  10503. 'junio' => 6,
  10504. 'julio' => 7,
  10505. 'agosto' => 8,
  10506. 'septiembre' => 9,
  10507. 'setiembre' => 9,
  10508. 'octubre' => 10,
  10509. 'noviembre' => 11,
  10510. 'diciembre' => 12,
  10511. // Finnish
  10512. 'tammikuu' => 1,
  10513. 'helmikuu' => 2,
  10514. 'maaliskuu' => 3,
  10515. 'huhtikuu' => 4,
  10516. 'toukokuu' => 5,
  10517. 'kesäkuu' => 6,
  10518. 'heinäkuu' => 7,
  10519. 'elokuu' => 8,
  10520. 'suuskuu' => 9,
  10521. 'lokakuu' => 10,
  10522. 'marras' => 11,
  10523. 'joulukuu' => 12,
  10524. // Hungarian
  10525. 'január' => 1,
  10526. 'február' => 2,
  10527. 'március' => 3,
  10528. 'április' => 4,
  10529. 'május' => 5,
  10530. 'június' => 6,
  10531. 'július' => 7,
  10532. 'augusztus' => 8,
  10533. 'szeptember' => 9,
  10534. 'október' => 10,
  10535. 'november' => 11,
  10536. 'december' => 12,
  10537. // Greek
  10538. 'Ιαν' => 1,
  10539. 'Φεβ' => 2,
  10540. 'Μάώ' => 3,
  10541. 'Μαώ' => 3,
  10542. 'Απρ' => 4,
  10543. 'Μάι' => 5,
  10544. 'Μαϊ' => 5,
  10545. 'Μαι' => 5,
  10546. 'Ιούν' => 6,
  10547. 'Ιον' => 6,
  10548. 'Ιούλ' => 7,
  10549. 'Ιολ' => 7,
  10550. 'Αύγ' => 8,
  10551. 'Αυγ' => 8,
  10552. 'Σεπ' => 9,
  10553. 'Οκτ' => 10,
  10554. 'Νοέ' => 11,
  10555. 'Δεκ' => 12,
  10556. );
  10557. var $timezone = array(
  10558. 'ACDT' => 37800,
  10559. 'ACIT' => 28800,
  10560. 'ACST' => 34200,
  10561. 'ACT' => -18000,
  10562. 'ACWDT' => 35100,
  10563. 'ACWST' => 31500,
  10564. 'AEDT' => 39600,
  10565. 'AEST' => 36000,
  10566. 'AFT' => 16200,
  10567. 'AKDT' => -28800,
  10568. 'AKST' => -32400,
  10569. 'AMDT' => 18000,
  10570. 'AMT' => -14400,
  10571. 'ANAST' => 46800,
  10572. 'ANAT' => 43200,
  10573. 'ART' => -10800,
  10574. 'AZOST' => -3600,
  10575. 'AZST' => 18000,
  10576. 'AZT' => 14400,
  10577. 'BIOT' => 21600,
  10578. 'BIT' => -43200,
  10579. 'BOT' => -14400,
  10580. 'BRST' => -7200,
  10581. 'BRT' => -10800,
  10582. 'BST' => 3600,
  10583. 'BTT' => 21600,
  10584. 'CAST' => 18000,
  10585. 'CAT' => 7200,
  10586. 'CCT' => 23400,
  10587. 'CDT' => -18000,
  10588. 'CEDT' => 7200,
  10589. 'CET' => 3600,
  10590. 'CGST' => -7200,
  10591. 'CGT' => -10800,
  10592. 'CHADT' => 49500,
  10593. 'CHAST' => 45900,
  10594. 'CIST' => -28800,
  10595. 'CKT' => -36000,
  10596. 'CLDT' => -10800,
  10597. 'CLST' => -14400,
  10598. 'COT' => -18000,
  10599. 'CST' => -21600,
  10600. 'CVT' => -3600,
  10601. 'CXT' => 25200,
  10602. 'DAVT' => 25200,
  10603. 'DTAT' => 36000,
  10604. 'EADT' => -18000,
  10605. 'EAST' => -21600,
  10606. 'EAT' => 10800,
  10607. 'ECT' => -18000,
  10608. 'EDT' => -14400,
  10609. 'EEST' => 10800,
  10610. 'EET' => 7200,
  10611. 'EGT' => -3600,
  10612. 'EKST' => 21600,
  10613. 'EST' => -18000,
  10614. 'FJT' => 43200,
  10615. 'FKDT' => -10800,
  10616. 'FKST' => -14400,
  10617. 'FNT' => -7200,
  10618. 'GALT' => -21600,
  10619. 'GEDT' => 14400,
  10620. 'GEST' => 10800,
  10621. 'GFT' => -10800,
  10622. 'GILT' => 43200,
  10623. 'GIT' => -32400,
  10624. 'GST' => 14400,
  10625. 'GST' => -7200,
  10626. 'GYT' => -14400,
  10627. 'HAA' => -10800,
  10628. 'HAC' => -18000,
  10629. 'HADT' => -32400,
  10630. 'HAE' => -14400,
  10631. 'HAP' => -25200,
  10632. 'HAR' => -21600,
  10633. 'HAST' => -36000,
  10634. 'HAT' => -9000,
  10635. 'HAY' => -28800,
  10636. 'HKST' => 28800,
  10637. 'HMT' => 18000,
  10638. 'HNA' => -14400,
  10639. 'HNC' => -21600,
  10640. 'HNE' => -18000,
  10641. 'HNP' => -28800,
  10642. 'HNR' => -25200,
  10643. 'HNT' => -12600,
  10644. 'HNY' => -32400,
  10645. 'IRDT' => 16200,
  10646. 'IRKST' => 32400,
  10647. 'IRKT' => 28800,
  10648. 'IRST' => 12600,
  10649. 'JFDT' => -10800,
  10650. 'JFST' => -14400,
  10651. 'JST' => 32400,
  10652. 'KGST' => 21600,
  10653. 'KGT' => 18000,
  10654. 'KOST' => 39600,
  10655. 'KOVST' => 28800,
  10656. 'KOVT' => 25200,
  10657. 'KRAST' => 28800,
  10658. 'KRAT' => 25200,
  10659. 'KST' => 32400,
  10660. 'LHDT' => 39600,
  10661. 'LHST' => 37800,
  10662. 'LINT' => 50400,
  10663. 'LKT' => 21600,
  10664. 'MAGST' => 43200,
  10665. 'MAGT' => 39600,
  10666. 'MAWT' => 21600,
  10667. 'MDT' => -21600,
  10668. 'MESZ' => 7200,
  10669. 'MEZ' => 3600,
  10670. 'MHT' => 43200,
  10671. 'MIT' => -34200,
  10672. 'MNST' => 32400,
  10673. 'MSDT' => 14400,
  10674. 'MSST' => 10800,
  10675. 'MST' => -25200,
  10676. 'MUT' => 14400,
  10677. 'MVT' => 18000,
  10678. 'MYT' => 28800,
  10679. 'NCT' => 39600,
  10680. 'NDT' => -9000,
  10681. 'NFT' => 41400,
  10682. 'NMIT' => 36000,
  10683. 'NOVST' => 25200,
  10684. 'NOVT' => 21600,
  10685. 'NPT' => 20700,
  10686. 'NRT' => 43200,
  10687. 'NST' => -12600,
  10688. 'NUT' => -39600,
  10689. 'NZDT' => 46800,
  10690. 'NZST' => 43200,
  10691. 'OMSST' => 25200,
  10692. 'OMST' => 21600,
  10693. 'PDT' => -25200,
  10694. 'PET' => -18000,
  10695. 'PETST' => 46800,
  10696. 'PETT' => 43200,
  10697. 'PGT' => 36000,
  10698. 'PHOT' => 46800,
  10699. 'PHT' => 28800,
  10700. 'PKT' => 18000,
  10701. 'PMDT' => -7200,
  10702. 'PMST' => -10800,
  10703. 'PONT' => 39600,
  10704. 'PST' => -28800,
  10705. 'PWT' => 32400,
  10706. 'PYST' => -10800,
  10707. 'PYT' => -14400,
  10708. 'RET' => 14400,
  10709. 'ROTT' => -10800,
  10710. 'SAMST' => 18000,
  10711. 'SAMT' => 14400,
  10712. 'SAST' => 7200,
  10713. 'SBT' => 39600,
  10714. 'SCDT' => 46800,
  10715. 'SCST' => 43200,
  10716. 'SCT' => 14400,
  10717. 'SEST' => 3600,
  10718. 'SGT' => 28800,
  10719. 'SIT' => 28800,
  10720. 'SRT' => -10800,
  10721. 'SST' => -39600,
  10722. 'SYST' => 10800,
  10723. 'SYT' => 7200,
  10724. 'TFT' => 18000,
  10725. 'THAT' => -36000,
  10726. 'TJT' => 18000,
  10727. 'TKT' => -36000,
  10728. 'TMT' => 18000,
  10729. 'TOT' => 46800,
  10730. 'TPT' => 32400,
  10731. 'TRUT' => 36000,
  10732. 'TVT' => 43200,
  10733. 'TWT' => 28800,
  10734. 'UYST' => -7200,
  10735. 'UYT' => -10800,
  10736. 'UZT' => 18000,
  10737. 'VET' => -14400,
  10738. 'VLAST' => 39600,
  10739. 'VLAT' => 36000,
  10740. 'VOST' => 21600,
  10741. 'VUT' => 39600,
  10742. 'WAST' => 7200,
  10743. 'WAT' => 3600,
  10744. 'WDT' => 32400,
  10745. 'WEST' => 3600,
  10746. 'WFT' => 43200,
  10747. 'WIB' => 25200,
  10748. 'WIT' => 32400,
  10749. 'WITA' => 28800,
  10750. 'WKST' => 18000,
  10751. 'WST' => 28800,
  10752. 'YAKST' => 36000,
  10753. 'YAKT' => 32400,
  10754. 'YAPT' => 36000,
  10755. 'YEKST' => 21600,
  10756. 'YEKT' => 18000,
  10757. );
  10758. var $day_pcre;
  10759. var $month_pcre;
  10760. var $built_in = array();
  10761. var $user = array();
  10762. public function __construct()
  10763. {
  10764. $this->day_pcre = '(' . implode(array_keys($this->day), '|') . ')';
  10765. $this->month_pcre = '(' . implode(array_keys($this->month), '|') . ')';
  10766. static $cache;
  10767. if (!isset($cache[get_class($this)]))
  10768. {
  10769. $all_methods = get_class_methods($this);
  10770. foreach ($all_methods as $method)
  10771. {
  10772. if (strtolower(substr($method, 0, 5)) === 'date_')
  10773. {
  10774. $cache[get_class($this)][] = $method;
  10775. }
  10776. }
  10777. }
  10778. foreach ($cache[get_class($this)] as $method)
  10779. {
  10780. $this->built_in[] = $method;
  10781. }
  10782. }
  10783. public static function get()
  10784. {
  10785. static $object;
  10786. if (!$object)
  10787. {
  10788. $object = new SimplePie_Parse_Date;
  10789. }
  10790. return $object;
  10791. }
  10792. public function parse($date)
  10793. {
  10794. foreach ($this->user as $method)
  10795. {
  10796. if (($returned = call_user_func($method, $date)) !== false)
  10797. {
  10798. return $returned;
  10799. }
  10800. }
  10801. foreach ($this->built_in as $method)
  10802. {
  10803. if (($returned = call_user_func(array($this, $method), $date)) !== false)
  10804. {
  10805. return $returned;
  10806. }
  10807. }
  10808. return false;
  10809. }
  10810. public function add_callback($callback)
  10811. {
  10812. if (is_callable($callback))
  10813. {
  10814. $this->user[] = $callback;
  10815. }
  10816. else
  10817. {
  10818. trigger_error('User-supplied function must be a valid callback', E_USER_WARNING);
  10819. }
  10820. }
  10821. public function date_w3cdtf($date)
  10822. {
  10823. static $pcre;
  10824. if (!$pcre)
  10825. {
  10826. $year = '([0-9]{4})';
  10827. $month = $day = $hour = $minute = $second = '([0-9]{2})';
  10828. $decimal = '([0-9]*)';
  10829. $zone = '(?:(Z)|([+\-])([0-9]{1,2}):?([0-9]{1,2}))';
  10830. $pcre = '/^' . $year . '(?:-?' . $month . '(?:-?' . $day . '(?:[Tt\x09\x20]+' . $hour . '(?::?' . $minute . '(?::?' . $second . '(?:.' . $decimal . ')?)?)?' . $zone . ')?)?)?$/';
  10831. }
  10832. if (preg_match($pcre, $date, $match))
  10833. {
  10834. /*
  10835. Capturing subpatterns:
  10836. 1: Year
  10837. 2: Month
  10838. 3: Day
  10839. 4: Hour
  10840. 5: Minute
  10841. 6: Second
  10842. 7: Decimal fraction of a second
  10843. 8: Zulu
  10844. 9: Timezone ±
  10845. 10: Timezone hours
  10846. 11: Timezone minutes
  10847. */
  10848. // Fill in empty matches
  10849. for ($i = count($match); $i <= 3; $i++)
  10850. {
  10851. $match[$i] = '1';
  10852. }
  10853. for ($i = count($match); $i <= 7; $i++)
  10854. {
  10855. $match[$i] = '0';
  10856. }
  10857. // Numeric timezone
  10858. if (isset($match[9]) && $match[9] !== '')
  10859. {
  10860. $timezone = $match[10] * 3600;
  10861. $timezone += $match[11] * 60;
  10862. if ($match[9] === '-')
  10863. {
  10864. $timezone = 0 - $timezone;
  10865. }
  10866. }
  10867. else
  10868. {
  10869. $timezone = 0;
  10870. }
  10871. // Convert the number of seconds to an integer, taking decimals into account
  10872. $second = round($match[6] + $match[7] / pow(10, strlen($match[7])));
  10873. return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone;
  10874. }
  10875. else
  10876. {
  10877. return false;
  10878. }
  10879. }
  10880. public function remove_rfc2822_comments($string)
  10881. {
  10882. $string = (string) $string;
  10883. $position = 0;
  10884. $length = strlen($string);
  10885. $depth = 0;
  10886. $output = '';
  10887. while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
  10888. {
  10889. $output .= substr($string, $position, $pos - $position);
  10890. $position = $pos + 1;
  10891. if ($string[$pos - 1] !== '\\')
  10892. {
  10893. $depth++;
  10894. while ($depth && $position < $length)
  10895. {
  10896. $position += strcspn($string, '()', $position);
  10897. if ($string[$position - 1] === '\\')
  10898. {
  10899. $position++;
  10900. continue;
  10901. }
  10902. elseif (isset($string[$position]))
  10903. {
  10904. switch ($string[$position])
  10905. {
  10906. case '(':
  10907. $depth++;
  10908. break;
  10909. case ')':
  10910. $depth--;
  10911. break;
  10912. }
  10913. $position++;
  10914. }
  10915. else
  10916. {
  10917. break;
  10918. }
  10919. }
  10920. }
  10921. else
  10922. {
  10923. $output .= '(';
  10924. }
  10925. }
  10926. $output .= substr($string, $position);
  10927. return $output;
  10928. }
  10929. public function date_rfc2822($date)
  10930. {
  10931. static $pcre;
  10932. if (!$pcre)
  10933. {
  10934. $wsp = '[\x09\x20]';
  10935. $fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)';
  10936. $optional_fws = $fws . '?';
  10937. $day_name = $this->day_pcre;
  10938. $month = $this->month_pcre;
  10939. $day = '([0-9]{1,2})';
  10940. $hour = $minute = $second = '([0-9]{2})';
  10941. $year = '([0-9]{2,4})';
  10942. $num_zone = '([+\-])([0-9]{2})([0-9]{2})';
  10943. $character_zone = '([A-Z]{1,5})';
  10944. $zone = '(?:' . $num_zone . '|' . $character_zone . ')';
  10945. $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';
  10946. }
  10947. if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match))
  10948. {
  10949. /*
  10950. Capturing subpatterns:
  10951. 1: Day name
  10952. 2: Day
  10953. 3: Month
  10954. 4: Year
  10955. 5: Hour
  10956. 6: Minute
  10957. 7: Second
  10958. 8: Timezone ±
  10959. 9: Timezone hours
  10960. 10: Timezone minutes
  10961. 11: Alphabetic timezone
  10962. */
  10963. // Find the month number
  10964. $month = $this->month[strtolower($match[3])];
  10965. // Numeric timezone
  10966. if ($match[8] !== '')
  10967. {
  10968. $timezone = $match[9] * 3600;
  10969. $timezone += $match[10] * 60;
  10970. if ($match[8] === '-')
  10971. {
  10972. $timezone = 0 - $timezone;
  10973. }
  10974. }
  10975. // Character timezone
  10976. elseif (isset($this->timezone[strtoupper($match[11])]))
  10977. {
  10978. $timezone = $this->timezone[strtoupper($match[11])];
  10979. }
  10980. // Assume everything else to be -0000
  10981. else
  10982. {
  10983. $timezone = 0;
  10984. }
  10985. // Deal with 2/3 digit years
  10986. if ($match[4] < 50)
  10987. {
  10988. $match[4] += 2000;
  10989. }
  10990. elseif ($match[4] < 1000)
  10991. {
  10992. $match[4] += 1900;
  10993. }
  10994. // Second is optional, if it is empty set it to zero
  10995. if ($match[7] !== '')
  10996. {
  10997. $second = $match[7];
  10998. }
  10999. else
  11000. {
  11001. $second = 0;
  11002. }
  11003. return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone;
  11004. }
  11005. else
  11006. {
  11007. return false;
  11008. }
  11009. }
  11010. public function date_rfc850($date)
  11011. {
  11012. static $pcre;
  11013. if (!$pcre)
  11014. {
  11015. $space = '[\x09\x20]+';
  11016. $day_name = $this->day_pcre;
  11017. $month = $this->month_pcre;
  11018. $day = '([0-9]{1,2})';
  11019. $year = $hour = $minute = $second = '([0-9]{2})';
  11020. $zone = '([A-Z]{1,5})';
  11021. $pcre = '/^' . $day_name . ',' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i';
  11022. }
  11023. if (preg_match($pcre, $date, $match))
  11024. {
  11025. /*
  11026. Capturing subpatterns:
  11027. 1: Day name
  11028. 2: Day
  11029. 3: Month
  11030. 4: Year
  11031. 5: Hour
  11032. 6: Minute
  11033. 7: Second
  11034. 8: Timezone
  11035. */
  11036. // Month
  11037. $month = $this->month[strtolower($match[3])];
  11038. // Character timezone
  11039. if (isset($this->timezone[strtoupper($match[8])]))
  11040. {
  11041. $timezone = $this->timezone[strtoupper($match[8])];
  11042. }
  11043. // Assume everything else to be -0000
  11044. else
  11045. {
  11046. $timezone = 0;
  11047. }
  11048. // Deal with 2 digit year
  11049. if ($match[4] < 50)
  11050. {
  11051. $match[4] += 2000;
  11052. }
  11053. else
  11054. {
  11055. $match[4] += 1900;
  11056. }
  11057. return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone;
  11058. }
  11059. else
  11060. {
  11061. return false;
  11062. }
  11063. }
  11064. public function date_asctime($date)
  11065. {
  11066. static $pcre;
  11067. if (!$pcre)
  11068. {
  11069. $space = '[\x09\x20]+';
  11070. $wday_name = $this->day_pcre;
  11071. $mon_name = $this->month_pcre;
  11072. $day = '([0-9]{1,2})';
  11073. $hour = $sec = $min = '([0-9]{2})';
  11074. $year = '([0-9]{4})';
  11075. $terminator = '\x0A?\x00?';
  11076. $pcre = '/^' . $wday_name . $space . $mon_name . $space . $day . $space . $hour . ':' . $min . ':' . $sec . $space . $year . $terminator . '$/i';
  11077. }
  11078. if (preg_match($pcre, $date, $match))
  11079. {
  11080. /*
  11081. Capturing subpatterns:
  11082. 1: Day name
  11083. 2: Month
  11084. 3: Day
  11085. 4: Hour
  11086. 5: Minute
  11087. 6: Second
  11088. 7: Year
  11089. */
  11090. $month = $this->month[strtolower($match[2])];
  11091. return gmmktime($match[4], $match[5], $match[6], $month, $match[3], $match[7]);
  11092. }
  11093. else
  11094. {
  11095. return false;
  11096. }
  11097. }
  11098. public function date_strtotime($date)
  11099. {
  11100. $strtotime = strtotime($date);
  11101. if ($strtotime === -1 || $strtotime === false)
  11102. {
  11103. return false;
  11104. }
  11105. else
  11106. {
  11107. return $strtotime;
  11108. }
  11109. }
  11110. }
  11111. class SimplePie_Parser
  11112. {
  11113. var $error_code;
  11114. var $error_string;
  11115. var $current_line;
  11116. var $current_column;
  11117. var $current_byte;
  11118. var $separator = ' ';
  11119. var $namespace = array('');
  11120. var $element = array('');
  11121. var $xml_base = array('');
  11122. var $xml_base_explicit = array(false);
  11123. var $xml_lang = array('');
  11124. var $data = array();
  11125. var $datas = array(array());
  11126. var $current_xhtml_construct = -1;
  11127. var $encoding;
  11128. protected $registry;
  11129. public function set_registry(SimplePie_Registry $registry)
  11130. {
  11131. $this->registry = $registry;
  11132. }
  11133. public function parse(&$data, $encoding)
  11134. {
  11135. // Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
  11136. if (strtoupper($encoding) === 'US-ASCII')
  11137. {
  11138. $this->encoding = 'UTF-8';
  11139. }
  11140. else
  11141. {
  11142. $this->encoding = $encoding;
  11143. }
  11144. // Strip BOM:
  11145. // UTF-32 Big Endian BOM
  11146. if (substr($data, 0, 4) === "\x00\x00\xFE\xFF")
  11147. {
  11148. $data = substr($data, 4);
  11149. }
  11150. // UTF-32 Little Endian BOM
  11151. elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00")
  11152. {
  11153. $data = substr($data, 4);
  11154. }
  11155. // UTF-16 Big Endian BOM
  11156. elseif (substr($data, 0, 2) === "\xFE\xFF")
  11157. {
  11158. $data = substr($data, 2);
  11159. }
  11160. // UTF-16 Little Endian BOM
  11161. elseif (substr($data, 0, 2) === "\xFF\xFE")
  11162. {
  11163. $data = substr($data, 2);
  11164. }
  11165. // UTF-8 BOM
  11166. elseif (substr($data, 0, 3) === "\xEF\xBB\xBF")
  11167. {
  11168. $data = substr($data, 3);
  11169. }
  11170. if (substr($data, 0, 5) === '<?xml' && strspn(substr($data, 5, 1), "\x09\x0A\x0D\x20") && ($pos = strpos($data, '?>')) !== false)
  11171. {
  11172. $declaration = $this->registry->create('XML_Declaration_Parser', array(substr($data, 5, $pos - 5)));
  11173. if ($declaration->parse())
  11174. {
  11175. $data = substr($data, $pos + 2);
  11176. $data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' . $data;
  11177. }
  11178. else
  11179. {
  11180. $this->error_string = 'SimplePie bug! Please report this!';
  11181. return false;
  11182. }
  11183. }
  11184. $return = true;
  11185. static $xml_is_sane = null;
  11186. if ($xml_is_sane === null)
  11187. {
  11188. $parser_check = xml_parser_create();
  11189. xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
  11190. xml_parser_free($parser_check);
  11191. $xml_is_sane = isset($values[0]['value']);
  11192. }
  11193. // Create the parser
  11194. if ($xml_is_sane)
  11195. {
  11196. $xml = xml_parser_create_ns($this->encoding, $this->separator);
  11197. xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
  11198. xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0);
  11199. xml_set_object($xml, $this);
  11200. xml_set_character_data_handler($xml, 'cdata');
  11201. xml_set_element_handler($xml, 'tag_open', 'tag_close');
  11202. // Parse!
  11203. if (!xml_parse($xml, $data, true))
  11204. {
  11205. $this->error_code = xml_get_error_code($xml);
  11206. $this->error_string = xml_error_string($this->error_code);
  11207. $return = false;
  11208. }
  11209. $this->current_line = xml_get_current_line_number($xml);
  11210. $this->current_column = xml_get_current_column_number($xml);
  11211. $this->current_byte = xml_get_current_byte_index($xml);
  11212. xml_parser_free($xml);
  11213. return $return;
  11214. }
  11215. else
  11216. {
  11217. libxml_clear_errors();
  11218. $xml = new XMLReader();
  11219. $xml->xml($data);
  11220. while (@$xml->read())
  11221. {
  11222. switch ($xml->nodeType)
  11223. {
  11224. case constant('XMLReader::END_ELEMENT'):
  11225. if ($xml->namespaceURI !== '')
  11226. {
  11227. $tagName = $xml->namespaceURI . $this->separator . $xml->localName;
  11228. }
  11229. else
  11230. {
  11231. $tagName = $xml->localName;
  11232. }
  11233. $this->tag_close(null, $tagName);
  11234. break;
  11235. case constant('XMLReader::ELEMENT'):
  11236. $empty = $xml->isEmptyElement;
  11237. if ($xml->namespaceURI !== '')
  11238. {
  11239. $tagName = $xml->namespaceURI . $this->separator . $xml->localName;
  11240. }
  11241. else
  11242. {
  11243. $tagName = $xml->localName;
  11244. }
  11245. $attributes = array();
  11246. while ($xml->moveToNextAttribute())
  11247. {
  11248. if ($xml->namespaceURI !== '')
  11249. {
  11250. $attrName = $xml->namespaceURI . $this->separator . $xml->localName;
  11251. }
  11252. else
  11253. {
  11254. $attrName = $xml->localName;
  11255. }
  11256. $attributes[$attrName] = $xml->value;
  11257. }
  11258. $this->tag_open(null, $tagName, $attributes);
  11259. if ($empty)
  11260. {
  11261. $this->tag_close(null, $tagName);
  11262. }
  11263. break;
  11264. case constant('XMLReader::TEXT'):
  11265. case constant('XMLReader::CDATA'):
  11266. $this->cdata(null, $xml->value);
  11267. break;
  11268. }
  11269. }
  11270. if ($error = libxml_get_last_error())
  11271. {
  11272. $this->error_code = $error->code;
  11273. $this->error_string = $error->message;
  11274. $this->current_line = $error->line;
  11275. $this->current_column = $error->column;
  11276. return false;
  11277. }
  11278. else
  11279. {
  11280. return true;
  11281. }
  11282. }
  11283. }
  11284. public function get_error_code()
  11285. {
  11286. return $this->error_code;
  11287. }
  11288. public function get_error_string()
  11289. {
  11290. return $this->error_string;
  11291. }
  11292. public function get_current_line()
  11293. {
  11294. return $this->current_line;
  11295. }
  11296. public function get_current_column()
  11297. {
  11298. return $this->current_column;
  11299. }
  11300. public function get_current_byte()
  11301. {
  11302. return $this->current_byte;
  11303. }
  11304. public function get_data()
  11305. {
  11306. return $this->data;
  11307. }
  11308. public function tag_open($parser, $tag, $attributes)
  11309. {
  11310. list($this->namespace[], $this->element[]) = $this->split_ns($tag);
  11311. $attribs = array();
  11312. foreach ($attributes as $name => $value)
  11313. {
  11314. list($attrib_namespace, $attribute) = $this->split_ns($name);
  11315. $attribs[$attrib_namespace][$attribute] = $value;
  11316. }
  11317. if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['base']))
  11318. {
  11319. $this->xml_base[] = $this->registry->call('Misc', 'absolutize_url', array($attribs[SIMPLEPIE_NAMESPACE_XML]['base'], end($this->xml_base)));
  11320. $this->xml_base_explicit[] = true;
  11321. }
  11322. else
  11323. {
  11324. $this->xml_base[] = end($this->xml_base);
  11325. $this->xml_base_explicit[] = end($this->xml_base_explicit);
  11326. }
  11327. if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['lang']))
  11328. {
  11329. $this->xml_lang[] = $attribs[SIMPLEPIE_NAMESPACE_XML]['lang'];
  11330. }
  11331. else
  11332. {
  11333. $this->xml_lang[] = end($this->xml_lang);
  11334. }
  11335. if ($this->current_xhtml_construct >= 0)
  11336. {
  11337. $this->current_xhtml_construct++;
  11338. if (end($this->namespace) === SIMPLEPIE_NAMESPACE_XHTML)
  11339. {
  11340. $this->data['data'] .= '<' . end($this->element);
  11341. if (isset($attribs['']))
  11342. {
  11343. foreach ($attribs[''] as $name => $value)
  11344. {
  11345. $this->data['data'] .= ' ' . $name . '="' . htmlspecialchars($value, ENT_COMPAT, $this->encoding) . '"';
  11346. }
  11347. }
  11348. $this->data['data'] .= '>';
  11349. }
  11350. }
  11351. else
  11352. {
  11353. $this->datas[] =& $this->data;
  11354. $this->data =& $this->data['child'][end($this->namespace)][end($this->element)][];
  11355. $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));
  11356. 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')
  11357. || (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')
  11358. || (end($this->namespace) === SIMPLEPIE_NAMESPACE_RSS_20 && in_array(end($this->element), array('title')))
  11359. || (end($this->namespace) === SIMPLEPIE_NAMESPACE_RSS_090 && in_array(end($this->element), array('title')))
  11360. || (end($this->namespace) === SIMPLEPIE_NAMESPACE_RSS_10 && in_array(end($this->element), array('title'))))
  11361. {
  11362. $this->current_xhtml_construct = 0;
  11363. }
  11364. }
  11365. }
  11366. public function cdata($parser, $cdata)
  11367. {
  11368. if ($this->current_xhtml_construct >= 0)
  11369. {
  11370. $this->data['data'] .= htmlspecialchars($cdata, ENT_QUOTES, $this->encoding);
  11371. }
  11372. else
  11373. {
  11374. $this->data['data'] .= $cdata;
  11375. }
  11376. }
  11377. public function tag_close($parser, $tag)
  11378. {
  11379. if ($this->current_xhtml_construct >= 0)
  11380. {
  11381. $this->current_xhtml_construct--;
  11382. 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')))
  11383. {
  11384. $this->data['data'] .= '</' . end($this->element) . '>';
  11385. }
  11386. }
  11387. if ($this->current_xhtml_construct === -1)
  11388. {
  11389. $this->data =& $this->datas[count($this->datas) - 1];
  11390. array_pop($this->datas);
  11391. }
  11392. array_pop($this->element);
  11393. array_pop($this->namespace);
  11394. array_pop($this->xml_base);
  11395. array_pop($this->xml_base_explicit);
  11396. array_pop($this->xml_lang);
  11397. }
  11398. public function split_ns($string)
  11399. {
  11400. static $cache = array();
  11401. if (!isset($cache[$string]))
  11402. {
  11403. if ($pos = strpos($string, $this->separator))
  11404. {
  11405. static $separator_length;
  11406. if (!$separator_length)
  11407. {
  11408. $separator_length = strlen($this->separator);
  11409. }
  11410. $namespace = substr($string, 0, $pos);
  11411. $local_name = substr($string, $pos + $separator_length);
  11412. if (strtolower($namespace) === SIMPLEPIE_NAMESPACE_ITUNES)
  11413. {
  11414. $namespace = SIMPLEPIE_NAMESPACE_ITUNES;
  11415. }
  11416. // Normalize the Media RSS namespaces
  11417. if ($namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG ||
  11418. $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2 ||
  11419. $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3 ||
  11420. $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4 ||
  11421. $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5 )
  11422. {
  11423. $namespace = SIMPLEPIE_NAMESPACE_MEDIARSS;
  11424. }
  11425. $cache[$string] = array($namespace, $local_name);
  11426. }
  11427. else
  11428. {
  11429. $cache[$string] = array('', $string);
  11430. }
  11431. }
  11432. return $cache[$string];
  11433. }
  11434. }
  11435. class SimplePie_Rating
  11436. {
  11437. var $scheme;
  11438. var $value;
  11439. public function __construct($scheme = null, $value = null)
  11440. {
  11441. $this->scheme = $scheme;
  11442. $this->value = $value;
  11443. }
  11444. public function __toString()
  11445. {
  11446. // There is no $this->data here
  11447. return md5(serialize($this));
  11448. }
  11449. public function get_scheme()
  11450. {
  11451. if ($this->scheme !== null)
  11452. {
  11453. return $this->scheme;
  11454. }
  11455. else
  11456. {
  11457. return null;
  11458. }
  11459. }
  11460. public function get_value()
  11461. {
  11462. if ($this->value !== null)
  11463. {
  11464. return $this->value;
  11465. }
  11466. else
  11467. {
  11468. return null;
  11469. }
  11470. }
  11471. }
  11472. class SimplePie_Registry
  11473. {
  11474. protected $default = array(
  11475. 'Cache' => 'SimplePie_Cache',
  11476. 'Locator' => 'SimplePie_Locator',
  11477. 'Parser' => 'SimplePie_Parser',
  11478. 'File' => 'SimplePie_File',
  11479. 'Sanitize' => 'SimplePie_Sanitize',
  11480. 'Item' => 'SimplePie_Item',
  11481. 'Author' => 'SimplePie_Author',
  11482. 'Category' => 'SimplePie_Category',
  11483. 'Enclosure' => 'SimplePie_Enclosure',
  11484. 'Caption' => 'SimplePie_Caption',
  11485. 'Copyright' => 'SimplePie_Copyright',
  11486. 'Credit' => 'SimplePie_Credit',
  11487. 'Rating' => 'SimplePie_Rating',
  11488. 'Restriction' => 'SimplePie_Restriction',
  11489. 'Content_Type_Sniffer' => 'SimplePie_Content_Type_Sniffer',
  11490. 'Source' => 'SimplePie_Source',
  11491. 'Misc' => 'SimplePie_Misc',
  11492. 'XML_Declaration_Parser' => 'SimplePie_XML_Declaration_Parser',
  11493. 'Parse_Date' => 'SimplePie_Parse_Date',
  11494. );
  11495. protected $classes = array();
  11496. protected $legacy = array();
  11497. public function __construct() { }
  11498. public function register($type, $class, $legacy = false)
  11499. {
  11500. if (!is_subclass_of($class, $this->default[$type]))
  11501. {
  11502. return false;
  11503. }
  11504. $this->classes[$type] = $class;
  11505. if ($legacy)
  11506. {
  11507. $this->legacy[] = $class;
  11508. }
  11509. return true;
  11510. }
  11511. public function get_class($type)
  11512. {
  11513. if (!empty($this->classes[$type]))
  11514. {
  11515. return $this->classes[$type];
  11516. }
  11517. if (!empty($this->default[$type]))
  11518. {
  11519. return $this->default[$type];
  11520. }
  11521. return null;
  11522. }
  11523. public function &create($type, $parameters = array())
  11524. {
  11525. $class = $this->get_class($type);
  11526. if (in_array($class, $this->legacy))
  11527. {
  11528. switch ($type)
  11529. {
  11530. case 'locator':
  11531. // Legacy: file, timeout, useragent, file_class, max_checked_feeds, content_type_sniffer_class
  11532. // Specified: file, timeout, useragent, max_checked_feeds
  11533. $replacement = array($this->get_class('file'), $parameters[3], $this->get_class('content_type_sniffer'));
  11534. array_splice($parameters, 3, 1, $replacement);
  11535. break;
  11536. }
  11537. }
  11538. if (!method_exists($class, '__construct'))
  11539. {
  11540. $instance = new $class;
  11541. }
  11542. else
  11543. {
  11544. $reflector = new ReflectionClass($class);
  11545. $instance = $reflector->newInstanceArgs($parameters);
  11546. }
  11547. if (method_exists($instance, 'set_registry'))
  11548. {
  11549. $instance->set_registry($this);
  11550. }
  11551. return $instance;
  11552. }
  11553. public function &call($type, $method, $parameters = array())
  11554. {
  11555. $class = $this->get_class($type);
  11556. $result = call_user_func_array(array($class, $method), $parameters);
  11557. return $result;
  11558. }
  11559. }
  11560. class SimplePie_Restriction
  11561. {
  11562. var $relationship;
  11563. var $type;
  11564. var $value;
  11565. public function __construct($relationship = null, $type = null, $value = null)
  11566. {
  11567. $this->relationship = $relationship;
  11568. $this->type = $type;
  11569. $this->value = $value;
  11570. }
  11571. public function __toString()
  11572. {
  11573. // There is no $this->data here
  11574. return md5(serialize($this));
  11575. }
  11576. public function get_relationship()
  11577. {
  11578. if ($this->relationship !== null)
  11579. {
  11580. return $this->relationship;
  11581. }
  11582. else
  11583. {
  11584. return null;
  11585. }
  11586. }
  11587. public function get_type()
  11588. {
  11589. if ($this->type !== null)
  11590. {
  11591. return $this->type;
  11592. }
  11593. else
  11594. {
  11595. return null;
  11596. }
  11597. }
  11598. public function get_value()
  11599. {
  11600. if ($this->value !== null)
  11601. {
  11602. return $this->value;
  11603. }
  11604. else
  11605. {
  11606. return null;
  11607. }
  11608. }
  11609. }
  11610. class SimplePie_Sanitize
  11611. {
  11612. // Private vars
  11613. var $base;
  11614. // Options
  11615. var $remove_div = true;
  11616. var $image_handler = '';
  11617. var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  11618. var $encode_instead_of_strip = false;
  11619. var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
  11620. var $strip_comments = false;
  11621. var $output_encoding = 'UTF-8';
  11622. var $enable_cache = true;
  11623. var $cache_location = './cache';
  11624. var $cache_name_function = 'md5';
  11625. var $timeout = 10;
  11626. var $useragent = '';
  11627. var $force_fsockopen = false;
  11628. var $replace_url_attributes = null;
  11629. public function __construct()
  11630. {
  11631. // Set defaults
  11632. $this->set_url_replacements(null);
  11633. }
  11634. public function remove_div($enable = true)
  11635. {
  11636. $this->remove_div = (bool) $enable;
  11637. }
  11638. public function set_image_handler($page = false)
  11639. {
  11640. if ($page)
  11641. {
  11642. $this->image_handler = (string) $page;
  11643. }
  11644. else
  11645. {
  11646. $this->image_handler = false;
  11647. }
  11648. }
  11649. public function set_registry(SimplePie_Registry $registry)
  11650. {
  11651. $this->registry = $registry;
  11652. }
  11653. public function pass_cache_data($enable_cache = true, $cache_location = './cache', $cache_name_function = 'md5', $cache_class = 'SimplePie_Cache')
  11654. {
  11655. if (isset($enable_cache))
  11656. {
  11657. $this->enable_cache = (bool) $enable_cache;
  11658. }
  11659. if ($cache_location)
  11660. {
  11661. $this->cache_location = (string) $cache_location;
  11662. }
  11663. if ($cache_name_function)
  11664. {
  11665. $this->cache_name_function = (string) $cache_name_function;
  11666. }
  11667. }
  11668. public function pass_file_data($file_class = 'SimplePie_File', $timeout = 10, $useragent = '', $force_fsockopen = false)
  11669. {
  11670. if ($timeout)
  11671. {
  11672. $this->timeout = (string) $timeout;
  11673. }
  11674. if ($useragent)
  11675. {
  11676. $this->useragent = (string) $useragent;
  11677. }
  11678. if ($force_fsockopen)
  11679. {
  11680. $this->force_fsockopen = (string) $force_fsockopen;
  11681. }
  11682. }
  11683. 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'))
  11684. {
  11685. if ($tags)
  11686. {
  11687. if (is_array($tags))
  11688. {
  11689. $this->strip_htmltags = $tags;
  11690. }
  11691. else
  11692. {
  11693. $this->strip_htmltags = explode(',', $tags);
  11694. }
  11695. }
  11696. else
  11697. {
  11698. $this->strip_htmltags = false;
  11699. }
  11700. }
  11701. public function encode_instead_of_strip($encode = false)
  11702. {
  11703. $this->encode_instead_of_strip = (bool) $encode;
  11704. }
  11705. public function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'))
  11706. {
  11707. if ($attribs)
  11708. {
  11709. if (is_array($attribs))
  11710. {
  11711. $this->strip_attributes = $attribs;
  11712. }
  11713. else
  11714. {
  11715. $this->strip_attributes = explode(',', $attribs);
  11716. }
  11717. }
  11718. else
  11719. {
  11720. $this->strip_attributes = false;
  11721. }
  11722. }
  11723. public function strip_comments($strip = false)
  11724. {
  11725. $this->strip_comments = (bool) $strip;
  11726. }
  11727. public function set_output_encoding($encoding = 'UTF-8')
  11728. {
  11729. $this->output_encoding = (string) $encoding;
  11730. }
  11731. public function set_url_replacements($element_attribute = null)
  11732. {
  11733. if ($element_attribute === null)
  11734. {
  11735. $element_attribute = array(
  11736. 'a' => 'href',
  11737. 'area' => 'href',
  11738. 'blockquote' => 'cite',
  11739. 'del' => 'cite',
  11740. 'form' => 'action',
  11741. 'img' => array(
  11742. 'longdesc',
  11743. 'src'
  11744. ),
  11745. 'input' => 'src',
  11746. 'ins' => 'cite',
  11747. 'q' => 'cite'
  11748. );
  11749. }
  11750. $this->replace_url_attributes = (array) $element_attribute;
  11751. }
  11752. public function sanitize($data, $type, $base = '')
  11753. {
  11754. $data = trim($data);
  11755. if ($data !== '' || $type & SIMPLEPIE_CONSTRUCT_IRI)
  11756. {
  11757. if ($type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML)
  11758. {
  11759. 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))
  11760. {
  11761. $type |= SIMPLEPIE_CONSTRUCT_HTML;
  11762. }
  11763. else
  11764. {
  11765. $type |= SIMPLEPIE_CONSTRUCT_TEXT;
  11766. }
  11767. }
  11768. if ($type & SIMPLEPIE_CONSTRUCT_BASE64)
  11769. {
  11770. $data = base64_decode($data);
  11771. }
  11772. if ($type & (SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML))
  11773. {
  11774. $document = new DOMDocument();
  11775. $document->encoding = 'UTF-8';
  11776. $data = $this->preprocess($data, $type);
  11777. set_error_handler(array('SimplePie_Misc', 'silence_errors'));
  11778. $document->loadHTML($data);
  11779. restore_error_handler();
  11780. // Strip comments
  11781. if ($this->strip_comments)
  11782. {
  11783. $xpath = new DOMXPath($document);
  11784. $comments = $xpath->query('//comment()');
  11785. foreach ($comments as $comment)
  11786. {
  11787. $comment->parentNode->removeChild($comment);
  11788. }
  11789. }
  11790. // Strip out HTML tags and attributes that might cause various security problems.
  11791. // Based on recommendations by Mark Pilgrim at:
  11792. // http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely
  11793. if ($this->strip_htmltags)
  11794. {
  11795. foreach ($this->strip_htmltags as $tag)
  11796. {
  11797. $this->strip_tag($tag, $document, $type);
  11798. }
  11799. }
  11800. if ($this->strip_attributes)
  11801. {
  11802. foreach ($this->strip_attributes as $attrib)
  11803. {
  11804. $this->strip_attr($attrib, $document);
  11805. }
  11806. }
  11807. // Replace relative URLs
  11808. $this->base = $base;
  11809. foreach ($this->replace_url_attributes as $element => $attributes)
  11810. {
  11811. $this->replace_urls($document, $element, $attributes);
  11812. }
  11813. // If image handling (caching, etc.) is enabled, cache and rewrite all the image tags.
  11814. if (isset($this->image_handler) && ((string) $this->image_handler) !== '' && $this->enable_cache)
  11815. {
  11816. $images = $document->getElementsByTagName('img');
  11817. foreach ($images as $img)
  11818. {
  11819. if ($img->hasAttribute('src'))
  11820. {
  11821. $image_url = call_user_func($this->cache_name_function, $img->getAttribute('src'));
  11822. $cache = $this->registry->call('Cache', 'create', array($this->cache_location, $image_url, 'spi'));
  11823. if ($cache->load())
  11824. {
  11825. $img->setAttribute('src', $this->image_handler . $image_url);
  11826. }
  11827. else
  11828. {
  11829. $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));
  11830. $headers = $file->headers;
  11831. if ($file->success && ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
  11832. {
  11833. if ($cache->save(array('headers' => $file->headers, 'body' => $file->body)))
  11834. {
  11835. $img->setAttribute('src', $this->image_handler . $image_url);
  11836. }
  11837. else
  11838. {
  11839. 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);
  11840. }
  11841. }
  11842. }
  11843. }
  11844. }
  11845. }
  11846. // Remove the DOCTYPE
  11847. // Seems to cause segfaulting if we don't do this
  11848. if ($document->firstChild instanceof DOMDocumentType)
  11849. {
  11850. $document->removeChild($document->firstChild);
  11851. }
  11852. // Move everything from the body to the root
  11853. $real_body = $document->getElementsByTagName('body')->item(0)->childNodes->item(0);
  11854. $document->replaceChild($real_body, $document->firstChild);
  11855. // Finally, convert to a HTML string
  11856. $data = trim($document->saveHTML());
  11857. if ($this->remove_div)
  11858. {
  11859. $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '', $data);
  11860. $data = preg_replace('/<\/div>$/', '', $data);
  11861. }
  11862. else
  11863. {
  11864. $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '<div>', $data);
  11865. }
  11866. }
  11867. if ($type & SIMPLEPIE_CONSTRUCT_IRI)
  11868. {
  11869. $data = $this->registry->call('Misc', 'absolutize_url', array($data, $base));
  11870. }
  11871. if ($type & (SIMPLEPIE_CONSTRUCT_TEXT | SIMPLEPIE_CONSTRUCT_IRI))
  11872. {
  11873. $data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
  11874. }
  11875. if ($this->output_encoding !== 'UTF-8')
  11876. {
  11877. $data = $this->registry->call('Misc', 'change_encoding', array($data, 'UTF-8', $this->output_encoding));
  11878. }
  11879. }
  11880. return $data;
  11881. }
  11882. protected function preprocess($html, $type)
  11883. {
  11884. $ret = '';
  11885. if ($type & ~SIMPLEPIE_CONSTRUCT_XHTML)
  11886. {
  11887. // Atom XHTML constructs are wrapped with a div by default
  11888. // Note: No protection if $html contains a stray </div>!
  11889. $html = '<div>' . $html . '</div>';
  11890. $ret .= '<!DOCTYPE html>';
  11891. $content_type = 'text/html';
  11892. }
  11893. else
  11894. {
  11895. $ret .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
  11896. $content_type = 'application/xhtml+xml';
  11897. }
  11898. $ret .= '<html><head>';
  11899. $ret .= '<meta http-equiv="Content-Type" content="' . $content_type . '; charset=utf-8" />';
  11900. $ret .= '</head><body>' . $html . '</body></html>';
  11901. return $ret;
  11902. }
  11903. public function replace_urls($document, $tag, $attributes)
  11904. {
  11905. if (!is_array($attributes))
  11906. {
  11907. $attributes = array($attributes);
  11908. }
  11909. if (!is_array($this->strip_htmltags) || !in_array($tag, $this->strip_htmltags))
  11910. {
  11911. $elements = $document->getElementsByTagName($tag);
  11912. foreach ($elements as $element)
  11913. {
  11914. foreach ($attributes as $attribute)
  11915. {
  11916. if ($element->hasAttribute($attribute))
  11917. {
  11918. $value = $this->registry->call('Misc', 'absolutize_url', array($element->getAttribute($attribute), $this->base));
  11919. $element->setAttribute($attribute, $value);
  11920. }
  11921. }
  11922. }
  11923. }
  11924. }
  11925. public function do_strip_htmltags($match)
  11926. {
  11927. if ($this->encode_instead_of_strip)
  11928. {
  11929. if (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
  11930. {
  11931. $match[1] = htmlspecialchars($match[1], ENT_COMPAT, 'UTF-8');
  11932. $match[2] = htmlspecialchars($match[2], ENT_COMPAT, 'UTF-8');
  11933. return "&lt;$match[1]$match[2]&gt;$match[3]&lt;/$match[1]&gt;";
  11934. }
  11935. else
  11936. {
  11937. return htmlspecialchars($match[0], ENT_COMPAT, 'UTF-8');
  11938. }
  11939. }
  11940. elseif (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
  11941. {
  11942. return $match[4];
  11943. }
  11944. else
  11945. {
  11946. return '';
  11947. }
  11948. }
  11949. protected function strip_tag($tag, $document, $type)
  11950. {
  11951. $xpath = new DOMXPath($document);
  11952. $elements = $xpath->query('body//' . $tag);
  11953. if ($this->encode_instead_of_strip)
  11954. {
  11955. foreach ($elements as $element)
  11956. {
  11957. $fragment = $document->createDocumentFragment();
  11958. // For elements which aren't script or style, include the tag itself
  11959. if (!in_array($tag, array('script', 'style')))
  11960. {
  11961. $text = '<' . $tag;
  11962. if ($element->hasAttributes())
  11963. {
  11964. $attrs = array();
  11965. foreach ($element->attributes as $name => $attr)
  11966. {
  11967. $value = $attr->value;
  11968. // In XHTML, empty values should never exist, so we repeat the value
  11969. if (empty($value) && ($type & SIMPLEPIE_CONSTRUCT_XHTML))
  11970. {
  11971. $value = $name;
  11972. }
  11973. // For HTML, empty is fine
  11974. elseif (empty($value) && ($type & SIMPLEPIE_CONSTRUCT_HTML))
  11975. {
  11976. $attrs[] = $name;
  11977. continue;
  11978. }
  11979. // Standard attribute text
  11980. $attrs[] = $name . '="' . $attr->value . '"';
  11981. }
  11982. $text .= ' ' . implode(' ', $attrs);
  11983. }
  11984. $text .= '>';
  11985. $fragment->appendChild(new DOMText($text));
  11986. }
  11987. $number = $element->childNodes->length;
  11988. for ($i = $number; $i > 0; $i--)
  11989. {
  11990. $child = $element->childNodes->item(0);
  11991. $fragment->appendChild($child);
  11992. }
  11993. if (!in_array($tag, array('script', 'style')))
  11994. {
  11995. $fragment->appendChild(new DOMText('</' . $tag . '>'));
  11996. }
  11997. $element->parentNode->replaceChild($fragment, $element);
  11998. }
  11999. return;
  12000. }
  12001. elseif (in_array($tag, array('script', 'style')))
  12002. {
  12003. foreach ($elements as $element)
  12004. {
  12005. $element->parentNode->removeChild($element);
  12006. }
  12007. return;
  12008. }
  12009. else
  12010. {
  12011. foreach ($elements as $element)
  12012. {
  12013. $fragment = $document->createDocumentFragment();
  12014. $number = $element->childNodes->length;
  12015. for ($i = $number; $i > 0; $i--)
  12016. {
  12017. $child = $element->childNodes->item(0);
  12018. $fragment->appendChild($child);
  12019. }
  12020. $element->parentNode->replaceChild($fragment, $element);
  12021. }
  12022. }
  12023. }
  12024. protected function strip_attr($attrib, $document)
  12025. {
  12026. $xpath = new DOMXPath($document);
  12027. $elements = $xpath->query('//*[@' . $attrib . ']');
  12028. foreach ($elements as $element)
  12029. {
  12030. $element->removeAttribute($attrib);
  12031. }
  12032. }
  12033. }
  12034. class SimplePie_Source
  12035. {
  12036. var $item;
  12037. var $data = array();
  12038. protected $registry;
  12039. public function __construct($item, $data)
  12040. {
  12041. $this->item = $item;
  12042. $this->data = $data;
  12043. }
  12044. public function set_registry(SimplePie_Registry $registry)
  12045. {
  12046. $this->registry = $registry;
  12047. }
  12048. public function __toString()
  12049. {
  12050. return md5(serialize($this->data));
  12051. }
  12052. public function get_source_tags($namespace, $tag)
  12053. {
  12054. if (isset($this->data['child'][$namespace][$tag]))
  12055. {
  12056. return $this->data['child'][$namespace][$tag];
  12057. }
  12058. else
  12059. {
  12060. return null;
  12061. }
  12062. }
  12063. public function get_base($element = array())
  12064. {
  12065. return $this->item->get_base($element);
  12066. }
  12067. public function sanitize($data, $type, $base = '')
  12068. {
  12069. return $this->item->sanitize($data, $type, $base);
  12070. }
  12071. public function get_item()
  12072. {
  12073. return $this->item;
  12074. }
  12075. public function get_title()
  12076. {
  12077. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  12078. {
  12079. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  12080. }
  12081. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  12082. {
  12083. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  12084. }
  12085. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  12086. {
  12087. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  12088. }
  12089. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  12090. {
  12091. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  12092. }
  12093. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  12094. {
  12095. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  12096. }
  12097. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  12098. {
  12099. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12100. }
  12101. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  12102. {
  12103. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12104. }
  12105. else
  12106. {
  12107. return null;
  12108. }
  12109. }
  12110. public function get_category($key = 0)
  12111. {
  12112. $categories = $this->get_categories();
  12113. if (isset($categories[$key]))
  12114. {
  12115. return $categories[$key];
  12116. }
  12117. else
  12118. {
  12119. return null;
  12120. }
  12121. }
  12122. public function get_categories()
  12123. {
  12124. $categories = array();
  12125. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  12126. {
  12127. $term = null;
  12128. $scheme = null;
  12129. $label = null;
  12130. if (isset($category['attribs']['']['term']))
  12131. {
  12132. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  12133. }
  12134. if (isset($category['attribs']['']['scheme']))
  12135. {
  12136. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  12137. }
  12138. if (isset($category['attribs']['']['label']))
  12139. {
  12140. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  12141. }
  12142. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  12143. }
  12144. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
  12145. {
  12146. // This is really the label, but keep this as the term also for BC.
  12147. // Label will also work on retrieving because that falls back to term.
  12148. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12149. if (isset($category['attribs']['']['domain']))
  12150. {
  12151. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  12152. }
  12153. else
  12154. {
  12155. $scheme = null;
  12156. }
  12157. $categories[] = $this->registry->create('Category', array($term, $scheme, null));
  12158. }
  12159. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  12160. {
  12161. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  12162. }
  12163. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  12164. {
  12165. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  12166. }
  12167. if (!empty($categories))
  12168. {
  12169. return array_unique($categories);
  12170. }
  12171. else
  12172. {
  12173. return null;
  12174. }
  12175. }
  12176. public function get_author($key = 0)
  12177. {
  12178. $authors = $this->get_authors();
  12179. if (isset($authors[$key]))
  12180. {
  12181. return $authors[$key];
  12182. }
  12183. else
  12184. {
  12185. return null;
  12186. }
  12187. }
  12188. public function get_authors()
  12189. {
  12190. $authors = array();
  12191. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  12192. {
  12193. $name = null;
  12194. $uri = null;
  12195. $email = null;
  12196. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  12197. {
  12198. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12199. }
  12200. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  12201. {
  12202. $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]));
  12203. }
  12204. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  12205. {
  12206. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12207. }
  12208. if ($name !== null || $email !== null || $uri !== null)
  12209. {
  12210. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  12211. }
  12212. }
  12213. if ($author = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  12214. {
  12215. $name = null;
  12216. $url = null;
  12217. $email = null;
  12218. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  12219. {
  12220. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12221. }
  12222. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  12223. {
  12224. $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]));
  12225. }
  12226. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  12227. {
  12228. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12229. }
  12230. if ($name !== null || $email !== null || $url !== null)
  12231. {
  12232. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  12233. }
  12234. }
  12235. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  12236. {
  12237. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  12238. }
  12239. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  12240. {
  12241. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  12242. }
  12243. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  12244. {
  12245. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  12246. }
  12247. if (!empty($authors))
  12248. {
  12249. return array_unique($authors);
  12250. }
  12251. else
  12252. {
  12253. return null;
  12254. }
  12255. }
  12256. public function get_contributor($key = 0)
  12257. {
  12258. $contributors = $this->get_contributors();
  12259. if (isset($contributors[$key]))
  12260. {
  12261. return $contributors[$key];
  12262. }
  12263. else
  12264. {
  12265. return null;
  12266. }
  12267. }
  12268. public function get_contributors()
  12269. {
  12270. $contributors = array();
  12271. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  12272. {
  12273. $name = null;
  12274. $uri = null;
  12275. $email = null;
  12276. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  12277. {
  12278. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12279. }
  12280. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  12281. {
  12282. $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]));
  12283. }
  12284. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  12285. {
  12286. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12287. }
  12288. if ($name !== null || $email !== null || $uri !== null)
  12289. {
  12290. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  12291. }
  12292. }
  12293. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  12294. {
  12295. $name = null;
  12296. $url = null;
  12297. $email = null;
  12298. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  12299. {
  12300. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12301. }
  12302. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  12303. {
  12304. $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]));
  12305. }
  12306. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  12307. {
  12308. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12309. }
  12310. if ($name !== null || $email !== null || $url !== null)
  12311. {
  12312. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  12313. }
  12314. }
  12315. if (!empty($contributors))
  12316. {
  12317. return array_unique($contributors);
  12318. }
  12319. else
  12320. {
  12321. return null;
  12322. }
  12323. }
  12324. public function get_link($key = 0, $rel = 'alternate')
  12325. {
  12326. $links = $this->get_links($rel);
  12327. if (isset($links[$key]))
  12328. {
  12329. return $links[$key];
  12330. }
  12331. else
  12332. {
  12333. return null;
  12334. }
  12335. }
  12336. public function get_permalink()
  12337. {
  12338. return $this->get_link(0);
  12339. }
  12340. public function get_links($rel = 'alternate')
  12341. {
  12342. if (!isset($this->data['links']))
  12343. {
  12344. $this->data['links'] = array();
  12345. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
  12346. {
  12347. foreach ($links as $link)
  12348. {
  12349. if (isset($link['attribs']['']['href']))
  12350. {
  12351. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  12352. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  12353. }
  12354. }
  12355. }
  12356. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
  12357. {
  12358. foreach ($links as $link)
  12359. {
  12360. if (isset($link['attribs']['']['href']))
  12361. {
  12362. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  12363. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  12364. }
  12365. }
  12366. }
  12367. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  12368. {
  12369. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  12370. }
  12371. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  12372. {
  12373. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  12374. }
  12375. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  12376. {
  12377. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  12378. }
  12379. $keys = array_keys($this->data['links']);
  12380. foreach ($keys as $key)
  12381. {
  12382. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
  12383. {
  12384. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  12385. {
  12386. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  12387. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  12388. }
  12389. else
  12390. {
  12391. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  12392. }
  12393. }
  12394. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  12395. {
  12396. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  12397. }
  12398. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  12399. }
  12400. }
  12401. if (isset($this->data['links'][$rel]))
  12402. {
  12403. return $this->data['links'][$rel];
  12404. }
  12405. else
  12406. {
  12407. return null;
  12408. }
  12409. }
  12410. public function get_description()
  12411. {
  12412. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
  12413. {
  12414. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  12415. }
  12416. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
  12417. {
  12418. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  12419. }
  12420. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  12421. {
  12422. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  12423. }
  12424. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
  12425. {
  12426. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  12427. }
  12428. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
  12429. {
  12430. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  12431. }
  12432. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  12433. {
  12434. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12435. }
  12436. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  12437. {
  12438. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12439. }
  12440. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  12441. {
  12442. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  12443. }
  12444. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  12445. {
  12446. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  12447. }
  12448. else
  12449. {
  12450. return null;
  12451. }
  12452. }
  12453. public function get_copyright()
  12454. {
  12455. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  12456. {
  12457. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  12458. }
  12459. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
  12460. {
  12461. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  12462. }
  12463. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
  12464. {
  12465. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12466. }
  12467. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  12468. {
  12469. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12470. }
  12471. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  12472. {
  12473. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12474. }
  12475. else
  12476. {
  12477. return null;
  12478. }
  12479. }
  12480. public function get_language()
  12481. {
  12482. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language'))
  12483. {
  12484. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12485. }
  12486. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
  12487. {
  12488. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12489. }
  12490. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
  12491. {
  12492. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  12493. }
  12494. elseif (isset($this->data['xml_lang']))
  12495. {
  12496. return $this->sanitize($this->data['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  12497. }
  12498. else
  12499. {
  12500. return null;
  12501. }
  12502. }
  12503. public function get_latitude()
  12504. {
  12505. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  12506. {
  12507. return (float) $return[0]['data'];
  12508. }
  12509. 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))
  12510. {
  12511. return (float) $match[1];
  12512. }
  12513. else
  12514. {
  12515. return null;
  12516. }
  12517. }
  12518. public function get_longitude()
  12519. {
  12520. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  12521. {
  12522. return (float) $return[0]['data'];
  12523. }
  12524. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  12525. {
  12526. return (float) $return[0]['data'];
  12527. }
  12528. 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))
  12529. {
  12530. return (float) $match[2];
  12531. }
  12532. else
  12533. {
  12534. return null;
  12535. }
  12536. }
  12537. public function get_image_url()
  12538. {
  12539. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
  12540. {
  12541. return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
  12542. }
  12543. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
  12544. {
  12545. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  12546. }
  12547. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
  12548. {
  12549. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  12550. }
  12551. else
  12552. {
  12553. return null;
  12554. }
  12555. }
  12556. }
  12557. class SimplePie_XML_Declaration_Parser
  12558. {
  12559. var $version = '1.0';
  12560. var $encoding = 'UTF-8';
  12561. var $standalone = false;
  12562. var $state = 'before_version_name';
  12563. var $data = '';
  12564. var $data_length = 0;
  12565. var $position = 0;
  12566. public function __construct($data)
  12567. {
  12568. $this->data = $data;
  12569. $this->data_length = strlen($this->data);
  12570. }
  12571. public function parse()
  12572. {
  12573. while ($this->state && $this->state !== 'emit' && $this->has_data())
  12574. {
  12575. $state = $this->state;
  12576. $this->$state();
  12577. }
  12578. $this->data = '';
  12579. if ($this->state === 'emit')
  12580. {
  12581. return true;
  12582. }
  12583. else
  12584. {
  12585. $this->version = '';
  12586. $this->encoding = '';
  12587. $this->standalone = '';
  12588. return false;
  12589. }
  12590. }
  12591. public function has_data()
  12592. {
  12593. return (bool) ($this->position < $this->data_length);
  12594. }
  12595. public function skip_whitespace()
  12596. {
  12597. $whitespace = strspn($this->data, "\x09\x0A\x0D\x20", $this->position);
  12598. $this->position += $whitespace;
  12599. return $whitespace;
  12600. }
  12601. public function get_value()
  12602. {
  12603. $quote = substr($this->data, $this->position, 1);
  12604. if ($quote === '"' || $quote === "'")
  12605. {
  12606. $this->position++;
  12607. $len = strcspn($this->data, $quote, $this->position);
  12608. if ($this->has_data())
  12609. {
  12610. $value = substr($this->data, $this->position, $len);
  12611. $this->position += $len + 1;
  12612. return $value;
  12613. }
  12614. }
  12615. return false;
  12616. }
  12617. public function before_version_name()
  12618. {
  12619. if ($this->skip_whitespace())
  12620. {
  12621. $this->state = 'version_name';
  12622. }
  12623. else
  12624. {
  12625. $this->state = false;
  12626. }
  12627. }
  12628. public function version_name()
  12629. {
  12630. if (substr($this->data, $this->position, 7) === 'version')
  12631. {
  12632. $this->position += 7;
  12633. $this->skip_whitespace();
  12634. $this->state = 'version_equals';
  12635. }
  12636. else
  12637. {
  12638. $this->state = false;
  12639. }
  12640. }
  12641. public function version_equals()
  12642. {
  12643. if (substr($this->data, $this->position, 1) === '=')
  12644. {
  12645. $this->position++;
  12646. $this->skip_whitespace();
  12647. $this->state = 'version_value';
  12648. }
  12649. else
  12650. {
  12651. $this->state = false;
  12652. }
  12653. }
  12654. public function version_value()
  12655. {
  12656. if ($this->version = $this->get_value())
  12657. {
  12658. $this->skip_whitespace();
  12659. if ($this->has_data())
  12660. {
  12661. $this->state = 'encoding_name';
  12662. }
  12663. else
  12664. {
  12665. $this->state = 'emit';
  12666. }
  12667. }
  12668. else
  12669. {
  12670. $this->state = false;
  12671. }
  12672. }
  12673. public function encoding_name()
  12674. {
  12675. if (substr($this->data, $this->position, 8) === 'encoding')
  12676. {
  12677. $this->position += 8;
  12678. $this->skip_whitespace();
  12679. $this->state = 'encoding_equals';
  12680. }
  12681. else
  12682. {
  12683. $this->state = 'standalone_name';
  12684. }
  12685. }
  12686. public function encoding_equals()
  12687. {
  12688. if (substr($this->data, $this->position, 1) === '=')
  12689. {
  12690. $this->position++;
  12691. $this->skip_whitespace();
  12692. $this->state = 'encoding_value';
  12693. }
  12694. else
  12695. {
  12696. $this->state = false;
  12697. }
  12698. }
  12699. public function encoding_value()
  12700. {
  12701. if ($this->encoding = $this->get_value())
  12702. {
  12703. $this->skip_whitespace();
  12704. if ($this->has_data())
  12705. {
  12706. $this->state = 'standalone_name';
  12707. }
  12708. else
  12709. {
  12710. $this->state = 'emit';
  12711. }
  12712. }
  12713. else
  12714. {
  12715. $this->state = false;
  12716. }
  12717. }
  12718. public function standalone_name()
  12719. {
  12720. if (substr($this->data, $this->position, 10) === 'standalone')
  12721. {
  12722. $this->position += 10;
  12723. $this->skip_whitespace();
  12724. $this->state = 'standalone_equals';
  12725. }
  12726. else
  12727. {
  12728. $this->state = false;
  12729. }
  12730. }
  12731. public function standalone_equals()
  12732. {
  12733. if (substr($this->data, $this->position, 1) === '=')
  12734. {
  12735. $this->position++;
  12736. $this->skip_whitespace();
  12737. $this->state = 'standalone_value';
  12738. }
  12739. else
  12740. {
  12741. $this->state = false;
  12742. }
  12743. }
  12744. public function standalone_value()
  12745. {
  12746. if ($standalone = $this->get_value())
  12747. {
  12748. switch ($standalone)
  12749. {
  12750. case 'yes':
  12751. $this->standalone = true;
  12752. break;
  12753. case 'no':
  12754. $this->standalone = false;
  12755. break;
  12756. default:
  12757. $this->state = false;
  12758. return;
  12759. }
  12760. $this->skip_whitespace();
  12761. if ($this->has_data())
  12762. {
  12763. $this->state = false;
  12764. }
  12765. else
  12766. {
  12767. $this->state = 'emit';
  12768. }
  12769. }
  12770. else
  12771. {
  12772. $this->state = false;
  12773. }
  12774. }
  12775. }