lib_simplepie.php 347 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312
  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. public $data = array();
  107. public $error;
  108. public $sanitize;
  109. public $useragent = SIMPLEPIE_USERAGENT;
  110. public $feed_url;
  111. public $file;
  112. public $raw_data;
  113. public $timeout = 10;
  114. public $force_fsockopen = false;
  115. public $force_feed = false;
  116. public $cache = true;
  117. public $cache_duration = 3600;
  118. public $autodiscovery_cache_duration = 604800; // 7 Days.
  119. public $cache_location = './cache';
  120. public $cache_name_function = 'md5';
  121. public $order_by_date = true;
  122. public $input_encoding = false;
  123. public $autodiscovery = SIMPLEPIE_LOCATOR_ALL;
  124. public $registry;
  125. public $max_checked_feeds = 10;
  126. public $all_discovered_feeds = array();
  127. public $image_handler = '';
  128. public $multifeed_url = array();
  129. public $multifeed_objects = array();
  130. public $config_settings = null;
  131. public $item_limit = 0;
  132. public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
  133. public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  134. public function __construct() {
  135. if (version_compare(PHP_VERSION, '5.2', '<')) {
  136. trigger_error('PHP 4.x, 5.0 and 5.1 are no longer supported. Please upgrade to PHP 5.2 or newer.');
  137. die();
  138. }
  139. // Other objects, instances created here so we can set options on them
  140. $this->sanitize = new SimplePie_Sanitize();
  141. $this->registry = new SimplePie_Registry();
  142. if (func_num_args() > 0) {
  143. trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_location() directly.');
  144. }
  145. }
  146. public function __toString() {
  147. return md5(serialize($this->data));
  148. }
  149. public function __destruct() {
  150. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode')) {
  151. if (!empty($this->data['items'])) {
  152. foreach ($this->data['items'] as $item) {
  153. $item->__destruct();
  154. }
  155. unset($item, $this->data['items']);
  156. }
  157. if (!empty($this->data['ordered_items'])) {
  158. foreach ($this->data['ordered_items'] as $item) {
  159. $item->__destruct();
  160. }
  161. unset($item, $this->data['ordered_items']);
  162. }
  163. }
  164. }
  165. public function force_feed($enable = false) {
  166. $this->force_feed = (bool) $enable;
  167. }
  168. public function set_feed_url($url) {
  169. $this->multifeed_url = array();
  170. if (is_array($url)) {
  171. foreach ($url as $value) {
  172. $this->multifeed_url[] = $this->registry->call('Misc', 'fix_protocol', array($value, 1));
  173. }
  174. }
  175. else {
  176. $this->feed_url = $this->registry->call('Misc', 'fix_protocol', array($url, 1));
  177. }
  178. }
  179. public function set_file(&$file) {
  180. if ($file instanceof SimplePie_File) {
  181. $this->feed_url = $file->url;
  182. $this->file =& $file;
  183. return true;
  184. }
  185. return false;
  186. }
  187. public function set_raw_data($data) {
  188. $this->raw_data = $data;
  189. }
  190. public function set_timeout($timeout = 10) {
  191. $this->timeout = (int) $timeout;
  192. }
  193. public function force_fsockopen($enable = false) {
  194. $this->force_fsockopen = (bool) $enable;
  195. }
  196. public function enable_cache($enable = true) {
  197. $this->cache = (bool) $enable;
  198. }
  199. public function set_cache_duration($seconds = 3600) {
  200. $this->cache_duration = (int) $seconds;
  201. }
  202. public function set_autodiscovery_cache_duration($seconds = 604800) {
  203. $this->autodiscovery_cache_duration = (int) $seconds;
  204. }
  205. public function set_cache_location($location = './cache') {
  206. $this->cache_location = (string) $location;
  207. }
  208. public function enable_order_by_date($enable = true) {
  209. $this->order_by_date = (bool) $enable;
  210. }
  211. public function set_input_encoding($encoding = false) {
  212. if ($encoding) {
  213. $this->input_encoding = (string) $encoding;
  214. }
  215. else {
  216. $this->input_encoding = false;
  217. }
  218. }
  219. public function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL) {
  220. $this->autodiscovery = (int) $level;
  221. }
  222. public function &get_registry() {
  223. return $this->registry;
  224. }
  225. /**
  226. * Set which class SimplePie uses for caching
  227. */
  228. public function set_cache_class($class = 'SimplePie_Cache') {
  229. return $this->registry->register('Cache', $class, true);
  230. }
  231. public function set_locator_class($class = 'SimplePie_Locator') {
  232. return $this->registry->register('Locator', $class, true);
  233. }
  234. public function set_parser_class($class = 'SimplePie_Parser') {
  235. return $this->registry->register('Parser', $class, true);
  236. }
  237. public function set_file_class($class = 'SimplePie_File') {
  238. return $this->registry->register('File', $class, true);
  239. }
  240. public function set_sanitize_class($class = 'SimplePie_Sanitize') {
  241. return $this->registry->register('Sanitize', $class, true);
  242. }
  243. public function set_item_class($class = 'SimplePie_Item') {
  244. return $this->registry->register('Item', $class, true);
  245. }
  246. public function set_author_class($class = 'SimplePie_Author') {
  247. return $this->registry->register('Author', $class, true);
  248. }
  249. public function set_category_class($class = 'SimplePie_Category') {
  250. return $this->registry->register('Category', $class, true);
  251. }
  252. public function set_enclosure_class($class = 'SimplePie_Enclosure') {
  253. return $this->registry->register('Enclosure', $class, true);
  254. }
  255. public function set_caption_class($class = 'SimplePie_Caption') {
  256. return $this->registry->register('Caption', $class, true);
  257. }
  258. public function set_copyright_class($class = 'SimplePie_Copyright') {
  259. return $this->registry->register('Copyright', $class, true);
  260. }
  261. public function set_credit_class($class = 'SimplePie_Credit') {
  262. return $this->registry->register('Credit', $class, true);
  263. }
  264. public function set_rating_class($class = 'SimplePie_Rating') {
  265. return $this->registry->register('Rating', $class, true);
  266. }
  267. public function set_restriction_class($class = 'SimplePie_Restriction') {
  268. return $this->registry->register('Restriction', $class, true);
  269. }
  270. public function set_content_type_sniffer_class($class = 'SimplePie_Content_Type_Sniffer') {
  271. return $this->registry->register('Content_Type_Sniffer', $class, true);
  272. }
  273. public function set_source_class($class = 'SimplePie_Source') {
  274. return $this->registry->register('Source', $class, true);
  275. }
  276. public function set_useragent($ua = SIMPLEPIE_USERAGENT) {
  277. $this->useragent = (string) $ua;
  278. }
  279. public function set_cache_name_function($function = 'md5') {
  280. if (is_callable($function)) {
  281. $this->cache_name_function = $function;
  282. }
  283. }
  284. public function set_stupidly_fast($set = false) {
  285. if ($set) {
  286. $this->enable_order_by_date(false);
  287. $this->remove_div(false);
  288. $this->strip_comments(false);
  289. $this->strip_htmltags(false);
  290. $this->strip_attributes(false);
  291. $this->set_image_handler(false);
  292. }
  293. }
  294. public function set_max_checked_feeds($max = 10) {
  295. $this->max_checked_feeds = (int) $max;
  296. }
  297. public function remove_div($enable = true) {
  298. $this->sanitize->remove_div($enable);
  299. }
  300. public function strip_htmltags($tags = '', $encode = null) {
  301. if ($tags === '') {
  302. $tags = $this->strip_htmltags;
  303. }
  304. $this->sanitize->strip_htmltags($tags);
  305. if ($encode !== null) {
  306. $this->sanitize->encode_instead_of_strip($tags);
  307. }
  308. }
  309. public function encode_instead_of_strip($enable = true) {
  310. $this->sanitize->encode_instead_of_strip($enable);
  311. }
  312. public function strip_attributes($attribs = '') {
  313. if ($attribs === '') {
  314. $attribs = $this->strip_attributes;
  315. }
  316. $this->sanitize->strip_attributes($attribs);
  317. }
  318. public function set_output_encoding($encoding = 'UTF-8') {
  319. $this->sanitize->set_output_encoding($encoding);
  320. }
  321. public function strip_comments($strip = false) {
  322. $this->sanitize->strip_comments($strip);
  323. }
  324. public function set_url_replacements($element_attribute = null) {
  325. $this->sanitize->set_url_replacements($element_attribute);
  326. }
  327. public function set_image_handler($page = false, $qs = 'i') {
  328. if ($page !== false) {
  329. $this->sanitize->set_image_handler($page . '?' . $qs . '=');
  330. }
  331. else {
  332. $this->image_handler = '';
  333. }
  334. }
  335. public function set_item_limit($limit = 0) {
  336. $this->item_limit = (int) $limit;
  337. }
  338. public function init() {
  339. // Check absolute bare minimum requirements.
  340. if (!extension_loaded('xml') || !extension_loaded('pcre')) {
  341. return false;
  342. }
  343. // 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.
  344. elseif (!extension_loaded('xmlreader')) {
  345. static $xml_is_sane = null;
  346. if ($xml_is_sane === null) {
  347. $parser_check = xml_parser_create();
  348. xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
  349. xml_parser_free($parser_check);
  350. $xml_is_sane = isset($values[0]['value']);
  351. }
  352. if (!$xml_is_sane) {
  353. return false;
  354. }
  355. }
  356. if (method_exists($this->sanitize, 'set_registry')) {
  357. $this->sanitize->set_registry($this->registry);
  358. }
  359. // Pass whatever was set with config options over to the sanitizer.
  360. // Pass the classes in for legacy support; new classes should use the registry instead
  361. $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache'));
  362. $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen);
  363. if (!empty($this->multifeed_url)) {
  364. $i = 0;
  365. $success = 0;
  366. $this->multifeed_objects = array();
  367. $this->error = array();
  368. foreach ($this->multifeed_url as $url) {
  369. $this->multifeed_objects[$i] = clone $this;
  370. $this->multifeed_objects[$i]->set_feed_url($url);
  371. $single_success = $this->multifeed_objects[$i]->init();
  372. $success |= $single_success;
  373. if (!$single_success) {
  374. $this->error[$i] = $this->multifeed_objects[$i]->error();
  375. }
  376. $i++;
  377. }
  378. return (bool) $success;
  379. }
  380. elseif ($this->feed_url === null && $this->raw_data === null) {
  381. return false;
  382. }
  383. $this->error = null;
  384. $this->data = array();
  385. $this->multifeed_objects = array();
  386. $cache = false;
  387. if ($this->feed_url !== null) {
  388. $parsed_feed_url = $this->registry->call('Misc', 'parse_url', array($this->feed_url));
  389. // Decide whether to enable caching
  390. if ($this->cache && $parsed_feed_url['scheme'] !== '') {
  391. $cache = $this->registry->call('Cache', 'create', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc'));
  392. }
  393. // Fetch the data via SimplePie_File into $this->raw_data
  394. if (($fetched = $this->fetch_data($cache)) === true) {
  395. return true;
  396. }
  397. elseif ($fetched === false) {
  398. return false;
  399. }
  400. list($headers, $sniffed) = $fetched;
  401. }
  402. // Set up array of possible encodings
  403. $encodings = array();
  404. // First check to see if input has been overridden.
  405. if ($this->input_encoding !== false) {
  406. $encodings[] = $this->input_encoding;
  407. }
  408. $application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
  409. $text_types = array('text/xml', 'text/xml-external-parsed-entity');
  410. // RFC 3023 (only applies to sniffed content)
  411. if (isset($sniffed)) {
  412. if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml') {
  413. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) {
  414. $encodings[] = strtoupper($charset[1]);
  415. }
  416. $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
  417. $encodings[] = 'UTF-8';
  418. }
  419. elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml') {
  420. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) {
  421. $encodings[] = $charset[1];
  422. }
  423. $encodings[] = 'US-ASCII';
  424. }
  425. // Text MIME-type default
  426. elseif (substr($sniffed, 0, 5) === 'text/') {
  427. $encodings[] = 'US-ASCII';
  428. }
  429. }
  430. // Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1
  431. $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
  432. $encodings[] = 'UTF-8';
  433. $encodings[] = 'ISO-8859-1';
  434. // There's no point in trying an encoding twice
  435. $encodings = array_unique($encodings);
  436. // Loop through each possible encoding, till we return something, or run out of possibilities
  437. foreach ($encodings as $encoding) {
  438. // Change the encoding to UTF-8 (as we always use UTF-8 internally)
  439. if ($utf8_data = $this->registry->call('Misc', 'change_encoding', array($this->raw_data, $encoding, 'UTF-8'))) {
  440. // Create new parser
  441. $parser = $this->registry->create('Parser');
  442. // If it's parsed fine
  443. if ($parser->parse($utf8_data, 'UTF-8')) {
  444. $this->data = $parser->get_data();
  445. if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE)) {
  446. $this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed.";
  447. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
  448. return false;
  449. }
  450. if (isset($headers)) {
  451. $this->data['headers'] = $headers;
  452. }
  453. $this->data['build'] = SIMPLEPIE_BUILD;
  454. // Cache the file if caching is enabled
  455. if ($cache && !$cache->save($this)) {
  456. 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);
  457. }
  458. return true;
  459. }
  460. }
  461. }
  462. if (isset($parser)) {
  463. // We have an error, just set SimplePie_Misc::error to it and quit
  464. $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());
  465. }
  466. else {
  467. $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.';
  468. }
  469. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
  470. return false;
  471. }
  472. protected function fetch_data(&$cache) {
  473. // If it's enabled, use the cache
  474. if ($cache) {
  475. // Load the Cache
  476. $this->data = $cache->load();
  477. if (!empty($this->data)) {
  478. // If the cache is for an outdated build of SimplePie
  479. if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD) {
  480. $cache->unlink();
  481. $this->data = array();
  482. }
  483. // If we've hit a collision just rerun it with caching disabled
  484. elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url) {
  485. $cache = false;
  486. $this->data = array();
  487. }
  488. // If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL.
  489. elseif (isset($this->data['feed_url'])) {
  490. // If the autodiscovery cache is still valid use it.
  491. if ($cache->mtime() + $this->autodiscovery_cache_duration > time()) {
  492. // Do not need to do feed autodiscovery yet.
  493. if ($this->data['feed_url'] !== $this->data['url']) {
  494. $this->set_feed_url($this->data['feed_url']);
  495. return $this->init();
  496. }
  497. $cache->unlink();
  498. $this->data = array();
  499. }
  500. }
  501. // Check if the cache has been updated
  502. elseif ($cache->mtime() + $this->cache_duration < time()) {
  503. // If we have last-modified and/or etag set
  504. if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag'])) {
  505. $headers = array(
  506. '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',
  507. );
  508. if (isset($this->data['headers']['last-modified'])) {
  509. $headers['if-modified-since'] = $this->data['headers']['last-modified'];
  510. }
  511. if (isset($this->data['headers']['etag'])) {
  512. $headers['if-none-match'] = $this->data['headers']['etag'];
  513. }
  514. $file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen));
  515. if ($file->success) {
  516. if ($file->status_code === 304) {
  517. $cache->touch();
  518. return true;
  519. }
  520. }
  521. else {
  522. unset($file);
  523. }
  524. }
  525. }
  526. // If the cache is still valid, just return true
  527. else {
  528. $this->raw_data = false;
  529. return true;
  530. }
  531. }
  532. // If the cache is empty, delete it
  533. else {
  534. $cache->unlink();
  535. $this->data = array();
  536. }
  537. }
  538. // 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.
  539. if (!isset($file)) {
  540. if ($this->file instanceof SimplePie_File && $this->file->url === $this->feed_url) {
  541. $file =& $this->file;
  542. }
  543. else {
  544. $headers = array(
  545. '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',
  546. );
  547. $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen));
  548. }
  549. }
  550. // If the file connection has an error, set SimplePie::error to that and quit
  551. if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300))) {
  552. $this->error = $file->error;
  553. return !empty($this->data);
  554. }
  555. if (!$this->force_feed) {
  556. // Check if the supplied URL is a feed, if it isn't, look for it.
  557. $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds));
  558. if (!$locate->is_feed($file)) {
  559. // We need to unset this so that if SimplePie::set_file() has been called that object is untouched
  560. unset($file);
  561. if (!($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds))) {
  562. $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.";
  563. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
  564. return false;
  565. }
  566. if ($cache) {
  567. $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD);
  568. if (!$cache->save($this)) {
  569. 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);
  570. }
  571. $cache = $this->registry->call('Cache', 'create', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc'));
  572. }
  573. $this->feed_url = $file->url;
  574. }
  575. $locate = null;
  576. }
  577. $this->raw_data = $file->body;
  578. $headers = $file->headers;
  579. $sniffer = $this->registry->create('Content_Type_Sniffer', array(&$file));
  580. $sniffed = $sniffer->get_type();
  581. return array($headers, $sniffed);
  582. }
  583. public function error() {
  584. return $this->error;
  585. }
  586. public function get_raw_data() {
  587. return $this->raw_data;
  588. }
  589. public function get_encoding() {
  590. return $this->sanitize->output_encoding;
  591. }
  592. public function handle_content_type($mime = 'text/html') {
  593. if (!headers_sent()) {
  594. $header = "Content-type: $mime;";
  595. if ($this->get_encoding()) {
  596. $header .= ' charset=' . $this->get_encoding();
  597. }
  598. else {
  599. $header .= ' charset=UTF-8';
  600. }
  601. header($header);
  602. }
  603. }
  604. public function get_type() {
  605. if (!isset($this->data['type'])) {
  606. $this->data['type'] = SIMPLEPIE_TYPE_ALL;
  607. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'])) {
  608. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10;
  609. }
  610. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'])) {
  611. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03;
  612. }
  613. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'])) {
  614. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel'])
  615. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image'])
  616. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item'])
  617. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput'])) {
  618. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10;
  619. }
  620. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel'])
  621. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image'])
  622. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item'])
  623. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput'])) {
  624. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090;
  625. }
  626. }
  627. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'])) {
  628. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL;
  629. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version'])) {
  630. switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version'])) {
  631. case '0.91':
  632. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091;
  633. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data'])) {
  634. switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data'])) {
  635. case '0':
  636. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE;
  637. break;
  638. case '24':
  639. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND;
  640. break;
  641. }
  642. }
  643. break;
  644. case '0.92':
  645. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092;
  646. break;
  647. case '0.93':
  648. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093;
  649. break;
  650. case '0.94':
  651. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094;
  652. break;
  653. case '2.0':
  654. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20;
  655. break;
  656. }
  657. }
  658. }
  659. else {
  660. $this->data['type'] = SIMPLEPIE_TYPE_NONE;
  661. }
  662. }
  663. return $this->data['type'];
  664. }
  665. public function subscribe_url() {
  666. if ($this->feed_url !== null) {
  667. return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI);
  668. }
  669. else {
  670. return null;
  671. }
  672. }
  673. public function get_feed_tags($namespace, $tag) {
  674. $type = $this->get_type();
  675. if ($type & SIMPLEPIE_TYPE_ATOM_10) {
  676. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag])) {
  677. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag];
  678. }
  679. }
  680. if ($type & SIMPLEPIE_TYPE_ATOM_03) {
  681. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag])) {
  682. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag];
  683. }
  684. }
  685. if ($type & SIMPLEPIE_TYPE_RSS_RDF) {
  686. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag])) {
  687. return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag];
  688. }
  689. }
  690. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION) {
  691. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag])) {
  692. return $this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag];
  693. }
  694. }
  695. return null;
  696. }
  697. public function get_channel_tags($namespace, $tag) {
  698. $type = $this->get_type();
  699. if ($type & SIMPLEPIE_TYPE_ATOM_ALL) {
  700. if ($return = $this->get_feed_tags($namespace, $tag)) {
  701. return $return;
  702. }
  703. }
  704. if ($type & SIMPLEPIE_TYPE_RSS_10) {
  705. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel')) {
  706. if (isset($channel[0]['child'][$namespace][$tag])) {
  707. return $channel[0]['child'][$namespace][$tag];
  708. }
  709. }
  710. }
  711. if ($type & SIMPLEPIE_TYPE_RSS_090) {
  712. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel')) {
  713. if (isset($channel[0]['child'][$namespace][$tag])) {
  714. return $channel[0]['child'][$namespace][$tag];
  715. }
  716. }
  717. }
  718. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION) {
  719. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'channel')) {
  720. if (isset($channel[0]['child'][$namespace][$tag])) {
  721. return $channel[0]['child'][$namespace][$tag];
  722. }
  723. }
  724. }
  725. return null;
  726. }
  727. public function get_image_tags($namespace, $tag) {
  728. $type = $this->get_type();
  729. if ($type & SIMPLEPIE_TYPE_RSS_10) {
  730. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image')) {
  731. if (isset($image[0]['child'][$namespace][$tag])) {
  732. return $image[0]['child'][$namespace][$tag];
  733. }
  734. }
  735. }
  736. if ($type & SIMPLEPIE_TYPE_RSS_090) {
  737. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image')) {
  738. if (isset($image[0]['child'][$namespace][$tag])) {
  739. return $image[0]['child'][$namespace][$tag];
  740. }
  741. }
  742. }
  743. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION) {
  744. if ($image = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'image')) {
  745. if (isset($image[0]['child'][$namespace][$tag])) {
  746. return $image[0]['child'][$namespace][$tag];
  747. }
  748. }
  749. }
  750. return null;
  751. }
  752. public function get_base($element = array()) {
  753. if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base'])) {
  754. return $element['xml_base'];
  755. }
  756. elseif ($this->get_link() !== null) {
  757. return $this->get_link();
  758. }
  759. else {
  760. return $this->subscribe_url();
  761. }
  762. }
  763. public function sanitize($data, $type, $base = '') {
  764. return $this->sanitize->sanitize($data, $type, $base);
  765. }
  766. public function get_title() {
  767. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title')) {
  768. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  769. }
  770. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title')) {
  771. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  772. }
  773. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) {
  774. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  775. }
  776. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) {
  777. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  778. }
  779. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) {
  780. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  781. }
  782. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) {
  783. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  784. }
  785. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) {
  786. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  787. }
  788. else {
  789. return null;
  790. }
  791. }
  792. public function get_category($key = 0) {
  793. $categories = $this->get_categories();
  794. if (isset($categories[$key])) {
  795. return $categories[$key];
  796. }
  797. else {
  798. return null;
  799. }
  800. }
  801. public function get_categories() {
  802. $categories = array();
  803. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category) {
  804. $term = null;
  805. $scheme = null;
  806. $label = null;
  807. if (isset($category['attribs']['']['term'])) {
  808. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  809. }
  810. if (isset($category['attribs']['']['scheme'])) {
  811. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  812. }
  813. if (isset($category['attribs']['']['label'])) {
  814. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  815. }
  816. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  817. }
  818. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category) {
  819. // This is really the label, but keep this as the term also for BC.
  820. // Label will also work on retrieving because that falls back to term.
  821. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  822. if (isset($category['attribs']['']['domain'])) {
  823. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  824. }
  825. else {
  826. $scheme = null;
  827. }
  828. $categories[] = $this->registry->create('Category', array($term, $scheme, null));
  829. }
  830. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category) {
  831. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  832. }
  833. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category) {
  834. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  835. }
  836. if (!empty($categories)) {
  837. return array_unique($categories);
  838. }
  839. else {
  840. return null;
  841. }
  842. }
  843. public function get_author($key = 0) {
  844. $authors = $this->get_authors();
  845. if (isset($authors[$key])) {
  846. return $authors[$key];
  847. }
  848. else {
  849. return null;
  850. }
  851. }
  852. public function get_authors() {
  853. $authors = array();
  854. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author) {
  855. $name = null;
  856. $uri = null;
  857. $email = null;
  858. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) {
  859. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  860. }
  861. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) {
  862. $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]));
  863. }
  864. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) {
  865. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  866. }
  867. if ($name !== null || $email !== null || $uri !== null) {
  868. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  869. }
  870. }
  871. if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author')) {
  872. $name = null;
  873. $url = null;
  874. $email = null;
  875. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) {
  876. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  877. }
  878. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) {
  879. $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]));
  880. }
  881. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) {
  882. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  883. }
  884. if ($name !== null || $email !== null || $url !== null) {
  885. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  886. }
  887. }
  888. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author) {
  889. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  890. }
  891. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author) {
  892. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  893. }
  894. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author) {
  895. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  896. }
  897. if (!empty($authors)) {
  898. return array_unique($authors);
  899. }
  900. else {
  901. return null;
  902. }
  903. }
  904. public function get_contributor($key = 0) {
  905. $contributors = $this->get_contributors();
  906. if (isset($contributors[$key])) {
  907. return $contributors[$key];
  908. }
  909. else {
  910. return null;
  911. }
  912. }
  913. public function get_contributors() {
  914. $contributors = array();
  915. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor) {
  916. $name = null;
  917. $uri = null;
  918. $email = null;
  919. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) {
  920. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  921. }
  922. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) {
  923. $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]));
  924. }
  925. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) {
  926. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  927. }
  928. if ($name !== null || $email !== null || $uri !== null) {
  929. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  930. }
  931. }
  932. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor) {
  933. $name = null;
  934. $url = null;
  935. $email = null;
  936. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) {
  937. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  938. }
  939. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) {
  940. $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]));
  941. }
  942. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) {
  943. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  944. }
  945. if ($name !== null || $email !== null || $url !== null) {
  946. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  947. }
  948. }
  949. if (!empty($contributors)) {
  950. return array_unique($contributors);
  951. }
  952. else {
  953. return null;
  954. }
  955. }
  956. public function get_link($key = 0, $rel = 'alternate') {
  957. $links = $this->get_links($rel);
  958. if (isset($links[$key])) {
  959. return $links[$key];
  960. }
  961. else {
  962. return null;
  963. }
  964. }
  965. public function get_permalink() {
  966. return $this->get_link(0);
  967. }
  968. public function get_links($rel = 'alternate') {
  969. if (!isset($this->data['links'])) {
  970. $this->data['links'] = array();
  971. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link')) {
  972. foreach ($links as $link) {
  973. if (isset($link['attribs']['']['href'])) {
  974. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  975. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  976. }
  977. }
  978. }
  979. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link')) {
  980. foreach ($links as $link) {
  981. if (isset($link['attribs']['']['href'])) {
  982. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  983. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  984. }
  985. }
  986. }
  987. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) {
  988. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  989. }
  990. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) {
  991. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  992. }
  993. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) {
  994. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  995. }
  996. $keys = array_keys($this->data['links']);
  997. foreach ($keys as $key) {
  998. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key))) {
  999. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key])) {
  1000. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  1001. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  1002. }
  1003. else {
  1004. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  1005. }
  1006. }
  1007. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) {
  1008. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  1009. }
  1010. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  1011. }
  1012. }
  1013. if (isset($this->data['links'][$rel])) {
  1014. return $this->data['links'][$rel];
  1015. }
  1016. else {
  1017. return null;
  1018. }
  1019. }
  1020. public function get_all_discovered_feeds() {
  1021. return $this->all_discovered_feeds;
  1022. }
  1023. public function get_description() {
  1024. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle')) {
  1025. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  1026. }
  1027. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline')) {
  1028. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  1029. }
  1030. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) {
  1031. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  1032. }
  1033. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) {
  1034. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  1035. }
  1036. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) {
  1037. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  1038. }
  1039. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) {
  1040. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1041. }
  1042. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) {
  1043. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1044. }
  1045. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) {
  1046. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  1047. }
  1048. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) {
  1049. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  1050. }
  1051. else {
  1052. return null;
  1053. }
  1054. }
  1055. public function get_copyright() {
  1056. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights')) {
  1057. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  1058. }
  1059. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright')) {
  1060. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  1061. }
  1062. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright')) {
  1063. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1064. }
  1065. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights')) {
  1066. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1067. }
  1068. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights')) {
  1069. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1070. }
  1071. else {
  1072. return null;
  1073. }
  1074. }
  1075. public function get_language() {
  1076. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language')) {
  1077. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1078. }
  1079. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language')) {
  1080. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1081. }
  1082. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language')) {
  1083. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1084. }
  1085. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'])) {
  1086. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1087. }
  1088. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'])) {
  1089. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1090. }
  1091. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'])) {
  1092. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1093. }
  1094. elseif (isset($this->data['headers']['content-language'])) {
  1095. return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT);
  1096. }
  1097. else {
  1098. return null;
  1099. }
  1100. }
  1101. public function get_latitude() {
  1102. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat')) {
  1103. return (float) $return[0]['data'];
  1104. }
  1105. 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)) {
  1106. return (float) $match[1];
  1107. }
  1108. else {
  1109. return null;
  1110. }
  1111. }
  1112. public function get_longitude() {
  1113. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long')) {
  1114. return (float) $return[0]['data'];
  1115. }
  1116. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon')) {
  1117. return (float) $return[0]['data'];
  1118. }
  1119. 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)) {
  1120. return (float) $match[2];
  1121. }
  1122. else {
  1123. return null;
  1124. }
  1125. }
  1126. public function get_image_title() {
  1127. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) {
  1128. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1129. }
  1130. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) {
  1131. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1132. }
  1133. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) {
  1134. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1135. }
  1136. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) {
  1137. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1138. }
  1139. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) {
  1140. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1141. }
  1142. else {
  1143. return null;
  1144. }
  1145. }
  1146. public function get_image_url() {
  1147. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image')) {
  1148. return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
  1149. }
  1150. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo')) {
  1151. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1152. }
  1153. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon')) {
  1154. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1155. }
  1156. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url')) {
  1157. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1158. }
  1159. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url')) {
  1160. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1161. }
  1162. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) {
  1163. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1164. }
  1165. else {
  1166. return null;
  1167. }
  1168. }
  1169. public function get_image_link() {
  1170. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) {
  1171. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1172. }
  1173. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) {
  1174. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1175. }
  1176. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) {
  1177. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1178. }
  1179. else {
  1180. return null;
  1181. }
  1182. }
  1183. public function get_image_width() {
  1184. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'width')) {
  1185. return round($return[0]['data']);
  1186. }
  1187. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) {
  1188. return 88.0;
  1189. }
  1190. else {
  1191. return null;
  1192. }
  1193. }
  1194. public function get_image_height() {
  1195. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'height')) {
  1196. return round($return[0]['data']);
  1197. }
  1198. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) {
  1199. return 31.0;
  1200. }
  1201. else {
  1202. return null;
  1203. }
  1204. }
  1205. public function get_item_quantity($max = 0) {
  1206. $max = (int) $max;
  1207. $qty = count($this->get_items());
  1208. if ($max === 0) {
  1209. return $qty;
  1210. }
  1211. else {
  1212. return ($qty > $max) ? $max : $qty;
  1213. }
  1214. }
  1215. public function get_item($key = 0) {
  1216. $items = $this->get_items();
  1217. if (isset($items[$key])) {
  1218. return $items[$key];
  1219. }
  1220. else {
  1221. return null;
  1222. }
  1223. }
  1224. public function get_items($start = 0, $end = 0) {
  1225. if (!isset($this->data['items'])) {
  1226. if (!empty($this->multifeed_objects)) {
  1227. $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit);
  1228. }
  1229. else {
  1230. $this->data['items'] = array();
  1231. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry')) {
  1232. $keys = array_keys($items);
  1233. foreach ($keys as $key) {
  1234. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  1235. }
  1236. }
  1237. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry')) {
  1238. $keys = array_keys($items);
  1239. foreach ($keys as $key) {
  1240. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  1241. }
  1242. }
  1243. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item')) {
  1244. $keys = array_keys($items);
  1245. foreach ($keys as $key) {
  1246. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  1247. }
  1248. }
  1249. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item')) {
  1250. $keys = array_keys($items);
  1251. foreach ($keys as $key) {
  1252. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  1253. }
  1254. }
  1255. if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'item')) {
  1256. $keys = array_keys($items);
  1257. foreach ($keys as $key) {
  1258. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  1259. }
  1260. }
  1261. }
  1262. }
  1263. if (!empty($this->data['items'])) {
  1264. // If we want to order it by date, check if all items have a date, and then sort it
  1265. if ($this->order_by_date && empty($this->multifeed_objects)) {
  1266. if (!isset($this->data['ordered_items'])) {
  1267. $do_sort = true;
  1268. foreach ($this->data['items'] as $item) {
  1269. if (!$item->get_date('U')) {
  1270. $do_sort = false;
  1271. break;
  1272. }
  1273. }
  1274. $item = null;
  1275. $this->data['ordered_items'] = $this->data['items'];
  1276. if ($do_sort) {
  1277. usort($this->data['ordered_items'], array(get_class($this), 'sort_items'));
  1278. }
  1279. }
  1280. $items = $this->data['ordered_items'];
  1281. }
  1282. else {
  1283. $items = $this->data['items'];
  1284. }
  1285. // Slice the data as desired
  1286. if ($end === 0) {
  1287. return array_slice($items, $start);
  1288. }
  1289. else {
  1290. return array_slice($items, $start, $end);
  1291. }
  1292. }
  1293. else {
  1294. return array();
  1295. }
  1296. }
  1297. public static function sort_items($a, $b) {
  1298. return $a->get_date('U') <= $b->get_date('U');
  1299. }
  1300. public static function merge_items($urls, $start = 0, $end = 0, $limit = 0) {
  1301. if (is_array($urls) && sizeof($urls) > 0) {
  1302. $items = array();
  1303. foreach ($urls as $arg) {
  1304. if ($arg instanceof SimplePie) {
  1305. $items = array_merge($items, $arg->get_items(0, $limit));
  1306. }
  1307. else {
  1308. trigger_error('Arguments must be SimplePie objects', E_USER_WARNING);
  1309. }
  1310. }
  1311. $do_sort = true;
  1312. foreach ($items as $item) {
  1313. if (!$item->get_date('U')) {
  1314. $do_sort = false;
  1315. break;
  1316. }
  1317. }
  1318. $item = null;
  1319. if ($do_sort) {
  1320. usort($items, array(get_class($urls[0]), 'sort_items'));
  1321. }
  1322. if ($end === 0) {
  1323. return array_slice($items, $start);
  1324. }
  1325. else {
  1326. return array_slice($items, $start, $end);
  1327. }
  1328. }
  1329. else {
  1330. trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING);
  1331. return array();
  1332. }
  1333. }
  1334. }
  1335. class SimplePie_Author {
  1336. var $name;
  1337. var $link;
  1338. var $email;
  1339. public function __construct($name = null, $link = null, $email = null) {
  1340. $this->name = $name;
  1341. $this->link = $link;
  1342. $this->email = $email;
  1343. }
  1344. public function __toString() {
  1345. // There is no $this->data here
  1346. return md5(serialize($this));
  1347. }
  1348. public function get_name() {
  1349. if ($this->name !== null) {
  1350. return $this->name;
  1351. }
  1352. else {
  1353. return null;
  1354. }
  1355. }
  1356. public function get_link() {
  1357. if ($this->link !== null) {
  1358. return $this->link;
  1359. }
  1360. else {
  1361. return null;
  1362. }
  1363. }
  1364. public function get_email() {
  1365. if ($this->email !== null) {
  1366. return $this->email;
  1367. }
  1368. else {
  1369. return null;
  1370. }
  1371. }
  1372. }
  1373. interface SimplePie_Cache_Base {
  1374. const TYPE_FEED = 'spc';
  1375. const TYPE_IMAGE = 'spi';
  1376. public function __construct($location, $name, $type);
  1377. public function save($data);
  1378. public function load();
  1379. public function mtime();
  1380. public function touch();
  1381. public function unlink();
  1382. }
  1383. abstract class SimplePie_Cache_DB implements SimplePie_Cache_Base {
  1384. protected static function prepare_simplepie_object_for_cache($data) {
  1385. $items = $data->get_items();
  1386. $items_by_id = array();
  1387. if (!empty($items)) {
  1388. foreach ($items as $item) {
  1389. $items_by_id[$item->get_id()] = $item;
  1390. }
  1391. if (count($items_by_id) !== count($items)) {
  1392. $items_by_id = array();
  1393. foreach ($items as $item) {
  1394. $items_by_id[$item->get_id(true)] = $item;
  1395. }
  1396. }
  1397. if (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0])) {
  1398. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
  1399. }
  1400. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0])) {
  1401. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
  1402. }
  1403. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0])) {
  1404. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
  1405. }
  1406. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0])) {
  1407. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0];
  1408. }
  1409. else {
  1410. $channel = null;
  1411. }
  1412. if ($channel !== null) {
  1413. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry'])) {
  1414. unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']);
  1415. }
  1416. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry'])) {
  1417. unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']);
  1418. }
  1419. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item'])) {
  1420. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']);
  1421. }
  1422. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item'])) {
  1423. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']);
  1424. }
  1425. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item'])) {
  1426. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']);
  1427. }
  1428. }
  1429. if (isset($data->data['items'])) {
  1430. unset($data->data['items']);
  1431. }
  1432. if (isset($data->data['ordered_items'])) {
  1433. unset($data->data['ordered_items']);
  1434. }
  1435. }
  1436. return array(serialize($data->data), $items_by_id);
  1437. }
  1438. }
  1439. class SimplePie_Cache_File implements SimplePie_Cache_Base {
  1440. protected $location;
  1441. protected $filename;
  1442. protected $extension;
  1443. protected $name;
  1444. public function __construct($location, $name, $type) {
  1445. $this->location = $location;
  1446. $this->filename = $name;
  1447. $this->extension = $type;
  1448. $this->name = "$this->location/$this->filename.$this->extension";
  1449. }
  1450. public function save($data) {
  1451. if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location)) {
  1452. if ($data instanceof SimplePie) {
  1453. $data = $data->data;
  1454. }
  1455. $data = serialize($data);
  1456. return (bool) file_put_contents($this->name, $data);
  1457. }
  1458. return false;
  1459. }
  1460. public function load() {
  1461. if (file_exists($this->name) && is_readable($this->name)) {
  1462. return unserialize(file_get_contents($this->name));
  1463. }
  1464. return false;
  1465. }
  1466. public function mtime() {
  1467. if (file_exists($this->name)) {
  1468. return filemtime($this->name);
  1469. }
  1470. return false;
  1471. }
  1472. public function touch() {
  1473. if (file_exists($this->name)) {
  1474. return touch($this->name);
  1475. }
  1476. return false;
  1477. }
  1478. public function unlink() {
  1479. if (file_exists($this->name)) {
  1480. return unlink($this->name);
  1481. }
  1482. return false;
  1483. }
  1484. }
  1485. class SimplePie_Cache_Memcache implements SimplePie_Cache_Base {
  1486. protected $cache;
  1487. protected $options;
  1488. protected $name;
  1489. public function __construct($location, $name, $type) {
  1490. $this->options = array(
  1491. 'host' => '127.0.0.1',
  1492. 'port' => 11211,
  1493. 'extras' => array(
  1494. 'timeout' => 3600, // one hour
  1495. 'prefix' => 'simplepie_',
  1496. ),
  1497. );
  1498. $parsed = SimplePie_Cache::parse_URL($location);
  1499. $this->options['host'] = empty($parsed['host']) ? $this->options['host'] : $parsed['host'];
  1500. $this->options['port'] = empty($parsed['port']) ? $this->options['port'] : $parsed['port'];
  1501. $this->options['extras'] = array_merge($this->options['extras'], $parsed['extras']);
  1502. $this->name = $this->options['extras']['prefix'] . md5("$name:$type");
  1503. $this->cache = new Memcache();
  1504. $this->cache->addServer($this->options['host'], (int) $this->options['port']);
  1505. }
  1506. public function save($data) {
  1507. if ($data instanceof SimplePie) {
  1508. $data = $data->data;
  1509. }
  1510. return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
  1511. }
  1512. public function load() {
  1513. $data = $this->cache->get($this->name);
  1514. if ($data !== false) {
  1515. return unserialize($data);
  1516. }
  1517. return false;
  1518. }
  1519. public function mtime() {
  1520. $data = $this->cache->get($this->name);
  1521. if ($data !== false) {
  1522. // essentially ignore the mtime because Memcache expires on it's own
  1523. return time();
  1524. }
  1525. return false;
  1526. }
  1527. public function touch() {
  1528. $data = $this->cache->get($this->name);
  1529. if ($data !== false) {
  1530. return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->duration);
  1531. }
  1532. return false;
  1533. }
  1534. public function unlink() {
  1535. return $this->cache->delete($this->name, 0);
  1536. }
  1537. }
  1538. class SimplePie_Cache_MySQL extends SimplePie_Cache_DB {
  1539. protected $mysql;
  1540. protected $options;
  1541. protected $id;
  1542. public function __construct($location, $name, $type) {
  1543. $this->options = array(
  1544. 'user' => null,
  1545. 'pass' => null,
  1546. 'host' => '127.0.0.1',
  1547. 'port' => '3306',
  1548. 'path' => '',
  1549. 'extras' => array(
  1550. 'prefix' => '',
  1551. ),
  1552. );
  1553. $this->options = array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));
  1554. // Path is prefixed with a "/"
  1555. $this->options['dbname'] = substr($this->options['path'], 1);
  1556. try {
  1557. $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'));
  1558. }
  1559. catch (PDOException $e) {
  1560. $this->mysql = null;
  1561. return;
  1562. }
  1563. $this->id = $name . $type;
  1564. if (!$query = $this->mysql->query('SHOW TABLES')) {
  1565. $this->mysql = null;
  1566. return;
  1567. }
  1568. $db = array();
  1569. while ($row = $query->fetchColumn()) {
  1570. $db[] = $row;
  1571. }
  1572. if (!in_array($this->options['extras']['prefix'] . 'cache_data', $db)) {
  1573. $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)))');
  1574. if ($query === false) {
  1575. $this->mysql = null;
  1576. }
  1577. }
  1578. if (!in_array($this->options['extras']['prefix'] . 'items', $db)) {
  1579. $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)))');
  1580. if ($query === false) {
  1581. $this->mysql = null;
  1582. }
  1583. }
  1584. }
  1585. public function save($data) {
  1586. if ($this->mysql === null) {
  1587. return false;
  1588. }
  1589. if ($data instanceof SimplePie) {
  1590. $data = clone $data;
  1591. $prepared = self::prepare_simplepie_object_for_cache($data);
  1592. $query = $this->mysql->prepare('SELECT COUNT(*) FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
  1593. $query->bindValue(':feed', $this->id);
  1594. if ($query->execute()) {
  1595. if ($query->fetchColumn() > 0) {
  1596. $items = count($prepared[1]);
  1597. if ($items) {
  1598. $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = :items, `data` = :data, `mtime` = :time WHERE `id` = :feed';
  1599. $query = $this->mysql->prepare($sql);
  1600. $query->bindValue(':items', $items);
  1601. }
  1602. else {
  1603. $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `data` = :data, `mtime` = :time WHERE `id` = :feed';
  1604. $query = $this->mysql->prepare($sql);
  1605. }
  1606. $query->bindValue(':data', $prepared[0]);
  1607. $query->bindValue(':time', time());
  1608. $query->bindValue(':feed', $this->id);
  1609. if (!$query->execute()) {
  1610. return false;
  1611. }
  1612. }
  1613. else {
  1614. $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:feed, :count, :data, :time)');
  1615. $query->bindValue(':feed', $this->id);
  1616. $query->bindValue(':count', count($prepared[1]));
  1617. $query->bindValue(':data', $prepared[0]);
  1618. $query->bindValue(':time', time());
  1619. if (!$query->execute()) {
  1620. return false;
  1621. }
  1622. }
  1623. $ids = array_keys($prepared[1]);
  1624. if (!empty($ids)) {
  1625. foreach ($ids as $id) {
  1626. $database_ids[] = $this->mysql->quote($id);
  1627. }
  1628. $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `id` = ' . implode(' OR `id` = ', $database_ids) . ' AND `feed_id` = :feed');
  1629. $query->bindValue(':feed', $this->id);
  1630. if ($query->execute()) {
  1631. $existing_ids = array();
  1632. while ($row = $query->fetchColumn()) {
  1633. $existing_ids[] = $row;
  1634. }
  1635. $new_ids = array_diff($ids, $existing_ids);
  1636. foreach ($new_ids as $new_id) {
  1637. if (!($date = $prepared[1][$new_id]->get_date('U'))) {
  1638. $date = time();
  1639. }
  1640. $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'items` (`feed_id`, `id`, `data`, `posted`) VALUES(:feed, :id, :data, :date)');
  1641. $query->bindValue(':feed', $this->id);
  1642. $query->bindValue(':id', $new_id);
  1643. $query->bindValue(':data', serialize($prepared[1][$new_id]->data));
  1644. $query->bindValue(':date', $date);
  1645. if (!$query->execute()) {
  1646. return false;
  1647. }
  1648. }
  1649. return true;
  1650. }
  1651. }
  1652. else {
  1653. return true;
  1654. }
  1655. }
  1656. }
  1657. else {
  1658. $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
  1659. $query->bindValue(':feed', $this->id);
  1660. if ($query->execute()) {
  1661. if ($query->rowCount() > 0) {
  1662. $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = 0, `data` = :data, `mtime` = :time WHERE `id` = :feed');
  1663. $query->bindValue(':data', serialize($data));
  1664. $query->bindValue(':time', time());
  1665. $query->bindValue(':feed', $this->id);
  1666. if ($this->execute()) {
  1667. return true;
  1668. }
  1669. }
  1670. else {
  1671. $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:id, 0, :data, :time)');
  1672. $query->bindValue(':id', $this->id);
  1673. $query->bindValue(':data', serialize($data));
  1674. $query->bindValue(':time', time());
  1675. if ($query->execute()) {
  1676. return true;
  1677. }
  1678. }
  1679. }
  1680. }
  1681. return false;
  1682. }
  1683. public function load() {
  1684. if ($this->mysql === null) {
  1685. return false;
  1686. }
  1687. $query = $this->mysql->prepare('SELECT `items`, `data` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
  1688. $query->bindValue(':id', $this->id);
  1689. if ($query->execute() && ($row = $query->fetch())) {
  1690. $data = unserialize($row[1]);
  1691. if (isset($this->options['items'][0])) {
  1692. $items = (int) $this->options['items'][0];
  1693. }
  1694. else {
  1695. $items = (int) $row[0];
  1696. }
  1697. if ($items !== 0) {
  1698. if (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0])) {
  1699. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
  1700. }
  1701. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0])) {
  1702. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
  1703. }
  1704. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0])) {
  1705. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
  1706. }
  1707. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0])) {
  1708. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0];
  1709. }
  1710. else {
  1711. $feed = null;
  1712. }
  1713. if ($feed !== null) {
  1714. $sql = 'SELECT `data` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :feed ORDER BY `posted` DESC';
  1715. if ($items > 0) {
  1716. $sql .= ' LIMIT ' . $items;
  1717. }
  1718. $query = $this->mysql->prepare($sql);
  1719. $query->bindValue(':feed', $this->id);
  1720. if ($query->execute()) {
  1721. while ($row = $query->fetchColumn()) {
  1722. $feed['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry'][] = unserialize($row);
  1723. }
  1724. }
  1725. else {
  1726. return false;
  1727. }
  1728. }
  1729. }
  1730. return $data;
  1731. }
  1732. return false;
  1733. }
  1734. public function mtime() {
  1735. if ($this->mysql === null) {
  1736. return false;
  1737. }
  1738. $query = $this->mysql->prepare('SELECT `mtime` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
  1739. $query->bindValue(':id', $this->id);
  1740. if ($query->execute() && ($time = $query->fetchColumn())) {
  1741. return $time;
  1742. }
  1743. else {
  1744. return false;
  1745. }
  1746. }
  1747. public function touch() {
  1748. if ($this->mysql === null) {
  1749. return false;
  1750. }
  1751. $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `mtime` = :time WHERE `id` = :id');
  1752. $query->bindValue(':time', time());
  1753. $query->bindValue(':id', $this->id);
  1754. if ($query->execute() && $query->rowCount() > 0) {
  1755. return true;
  1756. }
  1757. else {
  1758. return false;
  1759. }
  1760. }
  1761. public function unlink() {
  1762. if ($this->mysql === null) {
  1763. return false;
  1764. }
  1765. $query = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
  1766. $query->bindValue(':id', $this->id);
  1767. $query2 = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :id');
  1768. $query2->bindValue(':id', $this->id);
  1769. if ($query->execute() && $query2->execute()) {
  1770. return true;
  1771. }
  1772. else {
  1773. return false;
  1774. }
  1775. }
  1776. }
  1777. class SimplePie_Cache {
  1778. protected static $handlers = array(
  1779. 'mysql' => 'SimplePie_Cache_MySQL',
  1780. 'memcache' => 'SimplePie_Cache_Memcache',
  1781. );
  1782. private function __construct() { }
  1783. public static function create($location, $filename, $extension) {
  1784. $type = explode(':', $location, 2);
  1785. $type = $type[0];
  1786. if (!empty(self::$handlers[$type])) {
  1787. $class = self::$handlers[$type];
  1788. return new $class($location, $filename, $extension);
  1789. }
  1790. return new SimplePie_Cache_File($location, $filename, $extension);
  1791. }
  1792. public static function register($type, $class) {
  1793. self::$handlers[$type] = $class;
  1794. }
  1795. public static function parse_URL($url) {
  1796. $params = parse_url($url);
  1797. $params['extras'] = array();
  1798. if (isset($params['query'])) {
  1799. parse_str($params['query'], $params['extras']);
  1800. }
  1801. return $params;
  1802. }
  1803. }
  1804. class SimplePie_Caption {
  1805. var $type;
  1806. var $lang;
  1807. var $startTime;
  1808. var $endTime;
  1809. var $text;
  1810. public function __construct($type = null, $lang = null, $startTime = null, $endTime = null, $text = null) {
  1811. $this->type = $type;
  1812. $this->lang = $lang;
  1813. $this->startTime = $startTime;
  1814. $this->endTime = $endTime;
  1815. $this->text = $text;
  1816. }
  1817. public function __toString() {
  1818. // There is no $this->data here
  1819. return md5(serialize($this));
  1820. }
  1821. public function get_endtime() {
  1822. if ($this->endTime !== null) {
  1823. return $this->endTime;
  1824. }
  1825. else {
  1826. return null;
  1827. }
  1828. }
  1829. public function get_language() {
  1830. if ($this->lang !== null) {
  1831. return $this->lang;
  1832. }
  1833. else {
  1834. return null;
  1835. }
  1836. }
  1837. public function get_starttime() {
  1838. if ($this->startTime !== null) {
  1839. return $this->startTime;
  1840. }
  1841. else {
  1842. return null;
  1843. }
  1844. }
  1845. public function get_text() {
  1846. if ($this->text !== null) {
  1847. return $this->text;
  1848. }
  1849. else {
  1850. return null;
  1851. }
  1852. }
  1853. public function get_type() {
  1854. if ($this->type !== null) {
  1855. return $this->type;
  1856. }
  1857. else {
  1858. return null;
  1859. }
  1860. }
  1861. }
  1862. class SimplePie_Category {
  1863. var $term;
  1864. var $scheme;
  1865. var $label;
  1866. public function __construct($term = null, $scheme = null, $label = null) {
  1867. $this->term = $term;
  1868. $this->scheme = $scheme;
  1869. $this->label = $label;
  1870. }
  1871. public function __toString() {
  1872. // There is no $this->data here
  1873. return md5(serialize($this));
  1874. }
  1875. public function get_term() {
  1876. if ($this->term !== null) {
  1877. return $this->term;
  1878. }
  1879. else {
  1880. return null;
  1881. }
  1882. }
  1883. public function get_scheme() {
  1884. if ($this->scheme !== null) {
  1885. return $this->scheme;
  1886. }
  1887. else {
  1888. return null;
  1889. }
  1890. }
  1891. public function get_label() {
  1892. if ($this->label !== null) {
  1893. return $this->label;
  1894. }
  1895. else {
  1896. return $this->get_term();
  1897. }
  1898. }
  1899. }
  1900. class SimplePie_Content_Type_Sniffer {
  1901. var $file;
  1902. public function __construct($file) {
  1903. $this->file = $file;
  1904. }
  1905. public function get_type() {
  1906. if (isset($this->file->headers['content-type'])) {
  1907. if (!isset($this->file->headers['content-encoding'])
  1908. && ($this->file->headers['content-type'] === 'text/plain'
  1909. || $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1'
  1910. || $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1'
  1911. || $this->file->headers['content-type'] === 'text/plain; charset=UTF-8')) {
  1912. return $this->text_or_binary();
  1913. }
  1914. if (($pos = strpos($this->file->headers['content-type'], ';')) !== false) {
  1915. $official = substr($this->file->headers['content-type'], 0, $pos);
  1916. }
  1917. else {
  1918. $official = $this->file->headers['content-type'];
  1919. }
  1920. $official = trim(strtolower($official));
  1921. if ($official === 'unknown/unknown'
  1922. || $official === 'application/unknown') {
  1923. return $this->unknown();
  1924. }
  1925. elseif (substr($official, -4) === '+xml'
  1926. || $official === 'text/xml'
  1927. || $official === 'application/xml') {
  1928. return $official;
  1929. }
  1930. elseif (substr($official, 0, 6) === 'image/') {
  1931. if ($return = $this->image()) {
  1932. return $return;
  1933. }
  1934. else {
  1935. return $official;
  1936. }
  1937. }
  1938. elseif ($official === 'text/html') {
  1939. return $this->feed_or_html();
  1940. }
  1941. else {
  1942. return $official;
  1943. }
  1944. }
  1945. else {
  1946. return $this->unknown();
  1947. }
  1948. }
  1949. public function text_or_binary() {
  1950. if (substr($this->file->body, 0, 2) === "\xFE\xFF"
  1951. || substr($this->file->body, 0, 2) === "\xFF\xFE"
  1952. || substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF"
  1953. || substr($this->file->body, 0, 3) === "\xEF\xBB\xBF") {
  1954. return 'text/plain';
  1955. }
  1956. elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body)) {
  1957. return 'application/octect-stream';
  1958. }
  1959. else {
  1960. return 'text/plain';
  1961. }
  1962. }
  1963. public function unknown() {
  1964. $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20");
  1965. if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html'
  1966. || strtolower(substr($this->file->body, $ws, 5)) === '<html'
  1967. || strtolower(substr($this->file->body, $ws, 7)) === '<script') {
  1968. return 'text/html';
  1969. }
  1970. elseif (substr($this->file->body, 0, 5) === '%PDF-') {
  1971. return 'application/pdf';
  1972. }
  1973. elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-') {
  1974. return 'application/postscript';
  1975. }
  1976. elseif (substr($this->file->body, 0, 6) === 'GIF87a'
  1977. || substr($this->file->body, 0, 6) === 'GIF89a') {
  1978. return 'image/gif';
  1979. }
  1980. elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") {
  1981. return 'image/png';
  1982. }
  1983. elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF") {
  1984. return 'image/jpeg';
  1985. }
  1986. elseif (substr($this->file->body, 0, 2) === "\x42\x4D") {
  1987. return 'image/bmp';
  1988. }
  1989. elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00") {
  1990. return 'image/vnd.microsoft.icon';
  1991. }
  1992. else {
  1993. return $this->text_or_binary();
  1994. }
  1995. }
  1996. public function image() {
  1997. if (substr($this->file->body, 0, 6) === 'GIF87a'
  1998. || substr($this->file->body, 0, 6) === 'GIF89a') {
  1999. return 'image/gif';
  2000. }
  2001. elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") {
  2002. return 'image/png';
  2003. }
  2004. elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF") {
  2005. return 'image/jpeg';
  2006. }
  2007. elseif (substr($this->file->body, 0, 2) === "\x42\x4D") {
  2008. return 'image/bmp';
  2009. }
  2010. elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00") {
  2011. return 'image/vnd.microsoft.icon';
  2012. }
  2013. else {
  2014. return false;
  2015. }
  2016. }
  2017. public function feed_or_html() {
  2018. $len = strlen($this->file->body);
  2019. $pos = strspn($this->file->body, "\x09\x0A\x0D\x20");
  2020. while ($pos < $len) {
  2021. switch ($this->file->body[$pos]) {
  2022. case "\x09":
  2023. case "\x0A":
  2024. case "\x0D":
  2025. case "\x20":
  2026. $pos += strspn($this->file->body, "\x09\x0A\x0D\x20", $pos);
  2027. continue 2;
  2028. case '<':
  2029. $pos++;
  2030. break;
  2031. default:
  2032. return 'text/html';
  2033. }
  2034. if (substr($this->file->body, $pos, 3) === '!--') {
  2035. $pos += 3;
  2036. if ($pos < $len && ($pos = strpos($this->file->body, '-->', $pos)) !== false) {
  2037. $pos += 3;
  2038. }
  2039. else {
  2040. return 'text/html';
  2041. }
  2042. }
  2043. elseif (substr($this->file->body, $pos, 1) === '!') {
  2044. if ($pos < $len && ($pos = strpos($this->file->body, '>', $pos)) !== false) {
  2045. $pos++;
  2046. }
  2047. else {
  2048. return 'text/html';
  2049. }
  2050. }
  2051. elseif (substr($this->file->body, $pos, 1) === '?') {
  2052. if ($pos < $len && ($pos = strpos($this->file->body, '?>', $pos)) !== false) {
  2053. $pos += 2;
  2054. }
  2055. else {
  2056. return 'text/html';
  2057. }
  2058. }
  2059. elseif (substr($this->file->body, $pos, 3) === 'rss'
  2060. || substr($this->file->body, $pos, 7) === 'rdf:RDF') {
  2061. return 'application/rss+xml';
  2062. }
  2063. elseif (substr($this->file->body, $pos, 4) === 'feed') {
  2064. return 'application/atom+xml';
  2065. }
  2066. else {
  2067. return 'text/html';
  2068. }
  2069. }
  2070. return 'text/html';
  2071. }
  2072. }
  2073. class SimplePie_Copyright {
  2074. var $url;
  2075. var $label;
  2076. public function __construct($url = null, $label = null) {
  2077. $this->url = $url;
  2078. $this->label = $label;
  2079. }
  2080. public function __toString() {
  2081. // There is no $this->data here
  2082. return md5(serialize($this));
  2083. }
  2084. public function get_url() {
  2085. if ($this->url !== null) {
  2086. return $this->url;
  2087. }
  2088. else {
  2089. return null;
  2090. }
  2091. }
  2092. public function get_attribution() {
  2093. if ($this->label !== null) {
  2094. return $this->label;
  2095. }
  2096. else {
  2097. return null;
  2098. }
  2099. }
  2100. }
  2101. class SimplePie_Core extends SimplePie {
  2102. }
  2103. class SimplePie_Credit {
  2104. var $role;
  2105. var $scheme;
  2106. var $name;
  2107. public function __construct($role = null, $scheme = null, $name = null) {
  2108. $this->role = $role;
  2109. $this->scheme = $scheme;
  2110. $this->name = $name;
  2111. }
  2112. public function __toString() {
  2113. // There is no $this->data here
  2114. return md5(serialize($this));
  2115. }
  2116. public function get_role() {
  2117. if ($this->role !== null) {
  2118. return $this->role;
  2119. }
  2120. else {
  2121. return null;
  2122. }
  2123. }
  2124. public function get_scheme() {
  2125. if ($this->scheme !== null) {
  2126. return $this->scheme;
  2127. }
  2128. else {
  2129. return null;
  2130. }
  2131. }
  2132. public function get_name() {
  2133. if ($this->name !== null) {
  2134. return $this->name;
  2135. }
  2136. else {
  2137. return null;
  2138. }
  2139. }
  2140. }
  2141. class SimplePie_Decode_HTML_Entities {
  2142. var $data = '';
  2143. var $consumed = '';
  2144. var $position = 0;
  2145. public function __construct($data) {
  2146. $this->data = $data;
  2147. }
  2148. public function parse() {
  2149. while (($this->position = strpos($this->data, '&', $this->position)) !== false) {
  2150. $this->consume();
  2151. $this->entity();
  2152. $this->consumed = '';
  2153. }
  2154. return $this->data;
  2155. }
  2156. public function consume() {
  2157. if (isset($this->data[$this->position])) {
  2158. $this->consumed .= $this->data[$this->position];
  2159. return $this->data[$this->position++];
  2160. }
  2161. else {
  2162. return false;
  2163. }
  2164. }
  2165. public function consume_range($chars) {
  2166. if ($len = strspn($this->data, $chars, $this->position)) {
  2167. $data = substr($this->data, $this->position, $len);
  2168. $this->consumed .= $data;
  2169. $this->position += $len;
  2170. return $data;
  2171. }
  2172. else {
  2173. return false;
  2174. }
  2175. }
  2176. public function unconsume() {
  2177. $this->consumed = substr($this->consumed, 0, -1);
  2178. $this->position--;
  2179. }
  2180. public function entity() {
  2181. switch ($this->consume()) {
  2182. case "\x09":
  2183. case "\x0A":
  2184. case "\x0B":
  2185. case "\x0B":
  2186. case "\x0C":
  2187. case "\x20":
  2188. case "\x3C":
  2189. case "\x26":
  2190. case false:
  2191. break;
  2192. case "\x23":
  2193. switch ($this->consume()) {
  2194. case "\x78":
  2195. case "\x58":
  2196. $range = '0123456789ABCDEFabcdef';
  2197. $hex = true;
  2198. break;
  2199. default:
  2200. $range = '0123456789';
  2201. $hex = false;
  2202. $this->unconsume();
  2203. break;
  2204. }
  2205. if ($codepoint = $this->consume_range($range)) {
  2206. 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");
  2207. if ($hex) {
  2208. $codepoint = hexdec($codepoint);
  2209. }
  2210. else {
  2211. $codepoint = intval($codepoint);
  2212. }
  2213. if (isset($windows_1252_specials[$codepoint])) {
  2214. $replacement = $windows_1252_specials[$codepoint];
  2215. }
  2216. else {
  2217. $replacement = SimplePie_Misc::codepoint_to_utf8($codepoint);
  2218. }
  2219. if (!in_array($this->consume(), array(';', false), true)) {
  2220. $this->unconsume();
  2221. }
  2222. $consumed_length = strlen($this->consumed);
  2223. $this->data = substr_replace($this->data, $replacement, $this->position - $consumed_length, $consumed_length);
  2224. $this->position += strlen($replacement) - $consumed_length;
  2225. }
  2226. break;
  2227. default:
  2228. static $entities = array(
  2229. 'Aacute' => "\xC3\x81",
  2230. 'aacute' => "\xC3\xA1",
  2231. 'Aacute;' => "\xC3\x81",
  2232. 'aacute;' => "\xC3\xA1",
  2233. 'Acirc' => "\xC3\x82",
  2234. 'acirc' => "\xC3\xA2",
  2235. 'Acirc;' => "\xC3\x82",
  2236. 'acirc;' => "\xC3\xA2",
  2237. 'acute' => "\xC2\xB4",
  2238. 'acute;' => "\xC2\xB4",
  2239. 'AElig' => "\xC3\x86",
  2240. 'aelig' => "\xC3\xA6",
  2241. 'AElig;' => "\xC3\x86",
  2242. 'aelig;' => "\xC3\xA6",
  2243. 'Agrave' => "\xC3\x80",
  2244. 'agrave' => "\xC3\xA0",
  2245. 'Agrave;' => "\xC3\x80",
  2246. 'agrave;' => "\xC3\xA0",
  2247. 'alefsym;' => "\xE2\x84\xB5",
  2248. 'Alpha;' => "\xCE\x91",
  2249. 'alpha;' => "\xCE\xB1",
  2250. 'AMP' => "\x26",
  2251. 'amp' => "\x26",
  2252. 'AMP;' => "\x26",
  2253. 'amp;' => "\x26",
  2254. 'and;' => "\xE2\x88\xA7",
  2255. 'ang;' => "\xE2\x88\xA0",
  2256. 'apos;' => "\x27",
  2257. 'Aring' => "\xC3\x85",
  2258. 'aring' => "\xC3\xA5",
  2259. 'Aring;' => "\xC3\x85",
  2260. 'aring;' => "\xC3\xA5",
  2261. 'asymp;' => "\xE2\x89\x88",
  2262. 'Atilde' => "\xC3\x83",
  2263. 'atilde' => "\xC3\xA3",
  2264. 'Atilde;' => "\xC3\x83",
  2265. 'atilde;' => "\xC3\xA3",
  2266. 'Auml' => "\xC3\x84",
  2267. 'auml' => "\xC3\xA4",
  2268. 'Auml;' => "\xC3\x84",
  2269. 'auml;' => "\xC3\xA4",
  2270. 'bdquo;' => "\xE2\x80\x9E",
  2271. 'Beta;' => "\xCE\x92",
  2272. 'beta;' => "\xCE\xB2",
  2273. 'brvbar' => "\xC2\xA6",
  2274. 'brvbar;' => "\xC2\xA6",
  2275. 'bull;' => "\xE2\x80\xA2",
  2276. 'cap;' => "\xE2\x88\xA9",
  2277. 'Ccedil' => "\xC3\x87",
  2278. 'ccedil' => "\xC3\xA7",
  2279. 'Ccedil;' => "\xC3\x87",
  2280. 'ccedil;' => "\xC3\xA7",
  2281. 'cedil' => "\xC2\xB8",
  2282. 'cedil;' => "\xC2\xB8",
  2283. 'cent' => "\xC2\xA2",
  2284. 'cent;' => "\xC2\xA2",
  2285. 'Chi;' => "\xCE\xA7",
  2286. 'chi;' => "\xCF\x87",
  2287. 'circ;' => "\xCB\x86",
  2288. 'clubs;' => "\xE2\x99\xA3",
  2289. 'cong;' => "\xE2\x89\x85",
  2290. 'COPY' => "\xC2\xA9",
  2291. 'copy' => "\xC2\xA9",
  2292. 'COPY;' => "\xC2\xA9",
  2293. 'copy;' => "\xC2\xA9",
  2294. 'crarr;' => "\xE2\x86\xB5",
  2295. 'cup;' => "\xE2\x88\xAA",
  2296. 'curren' => "\xC2\xA4",
  2297. 'curren;' => "\xC2\xA4",
  2298. 'Dagger;' => "\xE2\x80\xA1",
  2299. 'dagger;' => "\xE2\x80\xA0",
  2300. 'dArr;' => "\xE2\x87\x93",
  2301. 'darr;' => "\xE2\x86\x93",
  2302. 'deg' => "\xC2\xB0",
  2303. 'deg;' => "\xC2\xB0",
  2304. 'Delta;' => "\xCE\x94",
  2305. 'delta;' => "\xCE\xB4",
  2306. 'diams;' => "\xE2\x99\xA6",
  2307. 'divide' => "\xC3\xB7",
  2308. 'divide;' => "\xC3\xB7",
  2309. 'Eacute' => "\xC3\x89",
  2310. 'eacute' => "\xC3\xA9",
  2311. 'Eacute;' => "\xC3\x89",
  2312. 'eacute;' => "\xC3\xA9",
  2313. 'Ecirc' => "\xC3\x8A",
  2314. 'ecirc' => "\xC3\xAA",
  2315. 'Ecirc;' => "\xC3\x8A",
  2316. 'ecirc;' => "\xC3\xAA",
  2317. 'Egrave' => "\xC3\x88",
  2318. 'egrave' => "\xC3\xA8",
  2319. 'Egrave;' => "\xC3\x88",
  2320. 'egrave;' => "\xC3\xA8",
  2321. 'empty;' => "\xE2\x88\x85",
  2322. 'emsp;' => "\xE2\x80\x83",
  2323. 'ensp;' => "\xE2\x80\x82",
  2324. 'Epsilon;' => "\xCE\x95",
  2325. 'epsilon;' => "\xCE\xB5",
  2326. 'equiv;' => "\xE2\x89\xA1",
  2327. 'Eta;' => "\xCE\x97",
  2328. 'eta;' => "\xCE\xB7",
  2329. 'ETH' => "\xC3\x90",
  2330. 'eth' => "\xC3\xB0",
  2331. 'ETH;' => "\xC3\x90",
  2332. 'eth;' => "\xC3\xB0",
  2333. 'Euml' => "\xC3\x8B",
  2334. 'euml' => "\xC3\xAB",
  2335. 'Euml;' => "\xC3\x8B",
  2336. 'euml;' => "\xC3\xAB",
  2337. 'euro;' => "\xE2\x82\xAC",
  2338. 'exist;' => "\xE2\x88\x83",
  2339. 'fnof;' => "\xC6\x92",
  2340. 'forall;' => "\xE2\x88\x80",
  2341. 'frac12' => "\xC2\xBD",
  2342. 'frac12;' => "\xC2\xBD",
  2343. 'frac14' => "\xC2\xBC",
  2344. 'frac14;' => "\xC2\xBC",
  2345. 'frac34' => "\xC2\xBE",
  2346. 'frac34;' => "\xC2\xBE",
  2347. 'frasl;' => "\xE2\x81\x84",
  2348. 'Gamma;' => "\xCE\x93",
  2349. 'gamma;' => "\xCE\xB3",
  2350. 'ge;' => "\xE2\x89\xA5",
  2351. 'GT' => "\x3E",
  2352. 'gt' => "\x3E",
  2353. 'GT;' => "\x3E",
  2354. 'gt;' => "\x3E",
  2355. 'hArr;' => "\xE2\x87\x94",
  2356. 'harr;' => "\xE2\x86\x94",
  2357. 'hearts;' => "\xE2\x99\xA5",
  2358. 'hellip;' => "\xE2\x80\xA6",
  2359. 'Iacute' => "\xC3\x8D",
  2360. 'iacute' => "\xC3\xAD",
  2361. 'Iacute;' => "\xC3\x8D",
  2362. 'iacute;' => "\xC3\xAD",
  2363. 'Icirc' => "\xC3\x8E",
  2364. 'icirc' => "\xC3\xAE",
  2365. 'Icirc;' => "\xC3\x8E",
  2366. 'icirc;' => "\xC3\xAE",
  2367. 'iexcl' => "\xC2\xA1",
  2368. 'iexcl;' => "\xC2\xA1",
  2369. 'Igrave' => "\xC3\x8C",
  2370. 'igrave' => "\xC3\xAC",
  2371. 'Igrave;' => "\xC3\x8C",
  2372. 'igrave;' => "\xC3\xAC",
  2373. 'image;' => "\xE2\x84\x91",
  2374. 'infin;' => "\xE2\x88\x9E",
  2375. 'int;' => "\xE2\x88\xAB",
  2376. 'Iota;' => "\xCE\x99",
  2377. 'iota;' => "\xCE\xB9",
  2378. 'iquest' => "\xC2\xBF",
  2379. 'iquest;' => "\xC2\xBF",
  2380. 'isin;' => "\xE2\x88\x88",
  2381. 'Iuml' => "\xC3\x8F",
  2382. 'iuml' => "\xC3\xAF",
  2383. 'Iuml;' => "\xC3\x8F",
  2384. 'iuml;' => "\xC3\xAF",
  2385. 'Kappa;' => "\xCE\x9A",
  2386. 'kappa;' => "\xCE\xBA",
  2387. 'Lambda;' => "\xCE\x9B",
  2388. 'lambda;' => "\xCE\xBB",
  2389. 'lang;' => "\xE3\x80\x88",
  2390. 'laquo' => "\xC2\xAB",
  2391. 'laquo;' => "\xC2\xAB",
  2392. 'lArr;' => "\xE2\x87\x90",
  2393. 'larr;' => "\xE2\x86\x90",
  2394. 'lceil;' => "\xE2\x8C\x88",
  2395. 'ldquo;' => "\xE2\x80\x9C",
  2396. 'le;' => "\xE2\x89\xA4",
  2397. 'lfloor;' => "\xE2\x8C\x8A",
  2398. 'lowast;' => "\xE2\x88\x97",
  2399. 'loz;' => "\xE2\x97\x8A",
  2400. 'lrm;' => "\xE2\x80\x8E",
  2401. 'lsaquo;' => "\xE2\x80\xB9",
  2402. 'lsquo;' => "\xE2\x80\x98",
  2403. 'LT' => "\x3C",
  2404. 'lt' => "\x3C",
  2405. 'LT;' => "\x3C",
  2406. 'lt;' => "\x3C",
  2407. 'macr' => "\xC2\xAF",
  2408. 'macr;' => "\xC2\xAF",
  2409. 'mdash;' => "\xE2\x80\x94",
  2410. 'micro' => "\xC2\xB5",
  2411. 'micro;' => "\xC2\xB5",
  2412. 'middot' => "\xC2\xB7",
  2413. 'middot;' => "\xC2\xB7",
  2414. 'minus;' => "\xE2\x88\x92",
  2415. 'Mu;' => "\xCE\x9C",
  2416. 'mu;' => "\xCE\xBC",
  2417. 'nabla;' => "\xE2\x88\x87",
  2418. 'nbsp' => "\xC2\xA0",
  2419. 'nbsp;' => "\xC2\xA0",
  2420. 'ndash;' => "\xE2\x80\x93",
  2421. 'ne;' => "\xE2\x89\xA0",
  2422. 'ni;' => "\xE2\x88\x8B",
  2423. 'not' => "\xC2\xAC",
  2424. 'not;' => "\xC2\xAC",
  2425. 'notin;' => "\xE2\x88\x89",
  2426. 'nsub;' => "\xE2\x8A\x84",
  2427. 'Ntilde' => "\xC3\x91",
  2428. 'ntilde' => "\xC3\xB1",
  2429. 'Ntilde;' => "\xC3\x91",
  2430. 'ntilde;' => "\xC3\xB1",
  2431. 'Nu;' => "\xCE\x9D",
  2432. 'nu;' => "\xCE\xBD",
  2433. 'Oacute' => "\xC3\x93",
  2434. 'oacute' => "\xC3\xB3",
  2435. 'Oacute;' => "\xC3\x93",
  2436. 'oacute;' => "\xC3\xB3",
  2437. 'Ocirc' => "\xC3\x94",
  2438. 'ocirc' => "\xC3\xB4",
  2439. 'Ocirc;' => "\xC3\x94",
  2440. 'ocirc;' => "\xC3\xB4",
  2441. 'OElig;' => "\xC5\x92",
  2442. 'oelig;' => "\xC5\x93",
  2443. 'Ograve' => "\xC3\x92",
  2444. 'ograve' => "\xC3\xB2",
  2445. 'Ograve;' => "\xC3\x92",
  2446. 'ograve;' => "\xC3\xB2",
  2447. 'oline;' => "\xE2\x80\xBE",
  2448. 'Omega;' => "\xCE\xA9",
  2449. 'omega;' => "\xCF\x89",
  2450. 'Omicron;' => "\xCE\x9F",
  2451. 'omicron;' => "\xCE\xBF",
  2452. 'oplus;' => "\xE2\x8A\x95",
  2453. 'or;' => "\xE2\x88\xA8",
  2454. 'ordf' => "\xC2\xAA",
  2455. 'ordf;' => "\xC2\xAA",
  2456. 'ordm' => "\xC2\xBA",
  2457. 'ordm;' => "\xC2\xBA",
  2458. 'Oslash' => "\xC3\x98",
  2459. 'oslash' => "\xC3\xB8",
  2460. 'Oslash;' => "\xC3\x98",
  2461. 'oslash;' => "\xC3\xB8",
  2462. 'Otilde' => "\xC3\x95",
  2463. 'otilde' => "\xC3\xB5",
  2464. 'Otilde;' => "\xC3\x95",
  2465. 'otilde;' => "\xC3\xB5",
  2466. 'otimes;' => "\xE2\x8A\x97",
  2467. 'Ouml' => "\xC3\x96",
  2468. 'ouml' => "\xC3\xB6",
  2469. 'Ouml;' => "\xC3\x96",
  2470. 'ouml;' => "\xC3\xB6",
  2471. 'para' => "\xC2\xB6",
  2472. 'para;' => "\xC2\xB6",
  2473. 'part;' => "\xE2\x88\x82",
  2474. 'permil;' => "\xE2\x80\xB0",
  2475. 'perp;' => "\xE2\x8A\xA5",
  2476. 'Phi;' => "\xCE\xA6",
  2477. 'phi;' => "\xCF\x86",
  2478. 'Pi;' => "\xCE\xA0",
  2479. 'pi;' => "\xCF\x80",
  2480. 'piv;' => "\xCF\x96",
  2481. 'plusmn' => "\xC2\xB1",
  2482. 'plusmn;' => "\xC2\xB1",
  2483. 'pound' => "\xC2\xA3",
  2484. 'pound;' => "\xC2\xA3",
  2485. 'Prime;' => "\xE2\x80\xB3",
  2486. 'prime;' => "\xE2\x80\xB2",
  2487. 'prod;' => "\xE2\x88\x8F",
  2488. 'prop;' => "\xE2\x88\x9D",
  2489. 'Psi;' => "\xCE\xA8",
  2490. 'psi;' => "\xCF\x88",
  2491. 'QUOT' => "\x22",
  2492. 'quot' => "\x22",
  2493. 'QUOT;' => "\x22",
  2494. 'quot;' => "\x22",
  2495. 'radic;' => "\xE2\x88\x9A",
  2496. 'rang;' => "\xE3\x80\x89",
  2497. 'raquo' => "\xC2\xBB",
  2498. 'raquo;' => "\xC2\xBB",
  2499. 'rArr;' => "\xE2\x87\x92",
  2500. 'rarr;' => "\xE2\x86\x92",
  2501. 'rceil;' => "\xE2\x8C\x89",
  2502. 'rdquo;' => "\xE2\x80\x9D",
  2503. 'real;' => "\xE2\x84\x9C",
  2504. 'REG' => "\xC2\xAE",
  2505. 'reg' => "\xC2\xAE",
  2506. 'REG;' => "\xC2\xAE",
  2507. 'reg;' => "\xC2\xAE",
  2508. 'rfloor;' => "\xE2\x8C\x8B",
  2509. 'Rho;' => "\xCE\xA1",
  2510. 'rho;' => "\xCF\x81",
  2511. 'rlm;' => "\xE2\x80\x8F",
  2512. 'rsaquo;' => "\xE2\x80\xBA",
  2513. 'rsquo;' => "\xE2\x80\x99",
  2514. 'sbquo;' => "\xE2\x80\x9A",
  2515. 'Scaron;' => "\xC5\xA0",
  2516. 'scaron;' => "\xC5\xA1",
  2517. 'sdot;' => "\xE2\x8B\x85",
  2518. 'sect' => "\xC2\xA7",
  2519. 'sect;' => "\xC2\xA7",
  2520. 'shy' => "\xC2\xAD",
  2521. 'shy;' => "\xC2\xAD",
  2522. 'Sigma;' => "\xCE\xA3",
  2523. 'sigma;' => "\xCF\x83",
  2524. 'sigmaf;' => "\xCF\x82",
  2525. 'sim;' => "\xE2\x88\xBC",
  2526. 'spades;' => "\xE2\x99\xA0",
  2527. 'sub;' => "\xE2\x8A\x82",
  2528. 'sube;' => "\xE2\x8A\x86",
  2529. 'sum;' => "\xE2\x88\x91",
  2530. 'sup;' => "\xE2\x8A\x83",
  2531. 'sup1' => "\xC2\xB9",
  2532. 'sup1;' => "\xC2\xB9",
  2533. 'sup2' => "\xC2\xB2",
  2534. 'sup2;' => "\xC2\xB2",
  2535. 'sup3' => "\xC2\xB3",
  2536. 'sup3;' => "\xC2\xB3",
  2537. 'supe;' => "\xE2\x8A\x87",
  2538. 'szlig' => "\xC3\x9F",
  2539. 'szlig;' => "\xC3\x9F",
  2540. 'Tau;' => "\xCE\xA4",
  2541. 'tau;' => "\xCF\x84",
  2542. 'there4;' => "\xE2\x88\xB4",
  2543. 'Theta;' => "\xCE\x98",
  2544. 'theta;' => "\xCE\xB8",
  2545. 'thetasym;' => "\xCF\x91",
  2546. 'thinsp;' => "\xE2\x80\x89",
  2547. 'THORN' => "\xC3\x9E",
  2548. 'thorn' => "\xC3\xBE",
  2549. 'THORN;' => "\xC3\x9E",
  2550. 'thorn;' => "\xC3\xBE",
  2551. 'tilde;' => "\xCB\x9C",
  2552. 'times' => "\xC3\x97",
  2553. 'times;' => "\xC3\x97",
  2554. 'TRADE;' => "\xE2\x84\xA2",
  2555. 'trade;' => "\xE2\x84\xA2",
  2556. 'Uacute' => "\xC3\x9A",
  2557. 'uacute' => "\xC3\xBA",
  2558. 'Uacute;' => "\xC3\x9A",
  2559. 'uacute;' => "\xC3\xBA",
  2560. 'uArr;' => "\xE2\x87\x91",
  2561. 'uarr;' => "\xE2\x86\x91",
  2562. 'Ucirc' => "\xC3\x9B",
  2563. 'ucirc' => "\xC3\xBB",
  2564. 'Ucirc;' => "\xC3\x9B",
  2565. 'ucirc;' => "\xC3\xBB",
  2566. 'Ugrave' => "\xC3\x99",
  2567. 'ugrave' => "\xC3\xB9",
  2568. 'Ugrave;' => "\xC3\x99",
  2569. 'ugrave;' => "\xC3\xB9",
  2570. 'uml' => "\xC2\xA8",
  2571. 'uml;' => "\xC2\xA8",
  2572. 'upsih;' => "\xCF\x92",
  2573. 'Upsilon;' => "\xCE\xA5",
  2574. 'upsilon;' => "\xCF\x85",
  2575. 'Uuml' => "\xC3\x9C",
  2576. 'uuml' => "\xC3\xBC",
  2577. 'Uuml;' => "\xC3\x9C",
  2578. 'uuml;' => "\xC3\xBC",
  2579. 'weierp;' => "\xE2\x84\x98",
  2580. 'Xi;' => "\xCE\x9E",
  2581. 'xi;' => "\xCE\xBE",
  2582. 'Yacute' => "\xC3\x9D",
  2583. 'yacute' => "\xC3\xBD",
  2584. 'Yacute;' => "\xC3\x9D",
  2585. 'yacute;' => "\xC3\xBD",
  2586. 'yen' => "\xC2\xA5",
  2587. 'yen;' => "\xC2\xA5",
  2588. 'yuml' => "\xC3\xBF",
  2589. 'Yuml;' => "\xC5\xB8",
  2590. 'yuml;' => "\xC3\xBF",
  2591. 'Zeta;' => "\xCE\x96",
  2592. 'zeta;' => "\xCE\xB6",
  2593. 'zwj;' => "\xE2\x80\x8D",
  2594. 'zwnj;' => "\xE2\x80\x8C"
  2595. );
  2596. for ($i = 0, $match = null; $i < 9 && $this->consume() !== false; $i++) {
  2597. $consumed = substr($this->consumed, 1);
  2598. if (isset($entities[$consumed])) {
  2599. $match = $consumed;
  2600. }
  2601. }
  2602. if ($match !== null) {
  2603. $this->data = substr_replace($this->data, $entities[$match], $this->position - strlen($consumed) - 1, strlen($match) + 1);
  2604. $this->position += strlen($entities[$match]) - strlen($consumed) - 1;
  2605. }
  2606. break;
  2607. }
  2608. }
  2609. }
  2610. class SimplePie_Enclosure {
  2611. var $bitrate;
  2612. var $captions;
  2613. var $categories;
  2614. var $channels;
  2615. var $copyright;
  2616. var $credits;
  2617. var $description;
  2618. var $duration;
  2619. var $expression;
  2620. var $framerate;
  2621. var $handler;
  2622. var $hashes;
  2623. var $height;
  2624. var $javascript;
  2625. var $keywords;
  2626. var $lang;
  2627. var $length;
  2628. var $link;
  2629. var $medium;
  2630. var $player;
  2631. var $ratings;
  2632. var $restrictions;
  2633. var $samplingrate;
  2634. var $thumbnails;
  2635. var $title;
  2636. var $type;
  2637. var $width;
  2638. 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) {
  2639. $this->bitrate = $bitrate;
  2640. $this->captions = $captions;
  2641. $this->categories = $categories;
  2642. $this->channels = $channels;
  2643. $this->copyright = $copyright;
  2644. $this->credits = $credits;
  2645. $this->description = $description;
  2646. $this->duration = $duration;
  2647. $this->expression = $expression;
  2648. $this->framerate = $framerate;
  2649. $this->hashes = $hashes;
  2650. $this->height = $height;
  2651. $this->keywords = $keywords;
  2652. $this->lang = $lang;
  2653. $this->length = $length;
  2654. $this->link = $link;
  2655. $this->medium = $medium;
  2656. $this->player = $player;
  2657. $this->ratings = $ratings;
  2658. $this->restrictions = $restrictions;
  2659. $this->samplingrate = $samplingrate;
  2660. $this->thumbnails = $thumbnails;
  2661. $this->title = $title;
  2662. $this->type = $type;
  2663. $this->width = $width;
  2664. if (class_exists('idna_convert')) {
  2665. $idn = new idna_convert();
  2666. $parsed = SimplePie_Misc::parse_url($link);
  2667. $this->link = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
  2668. }
  2669. $this->handler = $this->get_handler(); // Needs to load last
  2670. }
  2671. public function __toString() {
  2672. // There is no $this->data here
  2673. return md5(serialize($this));
  2674. }
  2675. public function get_bitrate() {
  2676. if ($this->bitrate !== null) {
  2677. return $this->bitrate;
  2678. }
  2679. else {
  2680. return null;
  2681. }
  2682. }
  2683. public function get_caption($key = 0) {
  2684. $captions = $this->get_captions();
  2685. if (isset($captions[$key])) {
  2686. return $captions[$key];
  2687. }
  2688. else {
  2689. return null;
  2690. }
  2691. }
  2692. public function get_captions() {
  2693. if ($this->captions !== null) {
  2694. return $this->captions;
  2695. }
  2696. else {
  2697. return null;
  2698. }
  2699. }
  2700. public function get_category($key = 0) {
  2701. $categories = $this->get_categories();
  2702. if (isset($categories[$key])) {
  2703. return $categories[$key];
  2704. }
  2705. else {
  2706. return null;
  2707. }
  2708. }
  2709. public function get_categories() {
  2710. if ($this->categories !== null) {
  2711. return $this->categories;
  2712. }
  2713. else {
  2714. return null;
  2715. }
  2716. }
  2717. public function get_channels() {
  2718. if ($this->channels !== null) {
  2719. return $this->channels;
  2720. }
  2721. else {
  2722. return null;
  2723. }
  2724. }
  2725. public function get_copyright() {
  2726. if ($this->copyright !== null) {
  2727. return $this->copyright;
  2728. }
  2729. else {
  2730. return null;
  2731. }
  2732. }
  2733. public function get_credit($key = 0) {
  2734. $credits = $this->get_credits();
  2735. if (isset($credits[$key])) {
  2736. return $credits[$key];
  2737. }
  2738. else {
  2739. return null;
  2740. }
  2741. }
  2742. public function get_credits() {
  2743. if ($this->credits !== null) {
  2744. return $this->credits;
  2745. }
  2746. else {
  2747. return null;
  2748. }
  2749. }
  2750. public function get_description() {
  2751. if ($this->description !== null) {
  2752. return $this->description;
  2753. }
  2754. else {
  2755. return null;
  2756. }
  2757. }
  2758. public function get_duration($convert = false) {
  2759. if ($this->duration !== null) {
  2760. if ($convert) {
  2761. $time = SimplePie_Misc::time_hms($this->duration);
  2762. return $time;
  2763. }
  2764. else {
  2765. return $this->duration;
  2766. }
  2767. }
  2768. else {
  2769. return null;
  2770. }
  2771. }
  2772. public function get_expression() {
  2773. if ($this->expression !== null) {
  2774. return $this->expression;
  2775. }
  2776. else {
  2777. return 'full';
  2778. }
  2779. }
  2780. public function get_extension() {
  2781. if ($this->link !== null) {
  2782. $url = SimplePie_Misc::parse_url($this->link);
  2783. if ($url['path'] !== '') {
  2784. return pathinfo($url['path'], PATHINFO_EXTENSION);
  2785. }
  2786. }
  2787. return null;
  2788. }
  2789. public function get_framerate() {
  2790. if ($this->framerate !== null) {
  2791. return $this->framerate;
  2792. }
  2793. else {
  2794. return null;
  2795. }
  2796. }
  2797. public function get_handler() {
  2798. return $this->get_real_type(true);
  2799. }
  2800. public function get_hash($key = 0) {
  2801. $hashes = $this->get_hashes();
  2802. if (isset($hashes[$key])) {
  2803. return $hashes[$key];
  2804. }
  2805. else {
  2806. return null;
  2807. }
  2808. }
  2809. public function get_hashes() {
  2810. if ($this->hashes !== null) {
  2811. return $this->hashes;
  2812. }
  2813. else {
  2814. return null;
  2815. }
  2816. }
  2817. public function get_height() {
  2818. if ($this->height !== null) {
  2819. return $this->height;
  2820. }
  2821. else {
  2822. return null;
  2823. }
  2824. }
  2825. public function get_language() {
  2826. if ($this->lang !== null) {
  2827. return $this->lang;
  2828. }
  2829. else {
  2830. return null;
  2831. }
  2832. }
  2833. public function get_keyword($key = 0) {
  2834. $keywords = $this->get_keywords();
  2835. if (isset($keywords[$key])) {
  2836. return $keywords[$key];
  2837. }
  2838. else {
  2839. return null;
  2840. }
  2841. }
  2842. public function get_keywords() {
  2843. if ($this->keywords !== null) {
  2844. return $this->keywords;
  2845. }
  2846. else {
  2847. return null;
  2848. }
  2849. }
  2850. public function get_length() {
  2851. if ($this->length !== null) {
  2852. return $this->length;
  2853. }
  2854. else {
  2855. return null;
  2856. }
  2857. }
  2858. public function get_link() {
  2859. if ($this->link !== null) {
  2860. return urldecode($this->link);
  2861. }
  2862. else {
  2863. return null;
  2864. }
  2865. }
  2866. public function get_medium() {
  2867. if ($this->medium !== null) {
  2868. return $this->medium;
  2869. }
  2870. else {
  2871. return null;
  2872. }
  2873. }
  2874. public function get_player() {
  2875. if ($this->player !== null) {
  2876. return $this->player;
  2877. }
  2878. else {
  2879. return null;
  2880. }
  2881. }
  2882. public function get_rating($key = 0) {
  2883. $ratings = $this->get_ratings();
  2884. if (isset($ratings[$key])) {
  2885. return $ratings[$key];
  2886. }
  2887. else {
  2888. return null;
  2889. }
  2890. }
  2891. public function get_ratings() {
  2892. if ($this->ratings !== null) {
  2893. return $this->ratings;
  2894. }
  2895. else {
  2896. return null;
  2897. }
  2898. }
  2899. public function get_restriction($key = 0) {
  2900. $restrictions = $this->get_restrictions();
  2901. if (isset($restrictions[$key])) {
  2902. return $restrictions[$key];
  2903. }
  2904. else {
  2905. return null;
  2906. }
  2907. }
  2908. public function get_restrictions() {
  2909. if ($this->restrictions !== null) {
  2910. return $this->restrictions;
  2911. }
  2912. else {
  2913. return null;
  2914. }
  2915. }
  2916. public function get_sampling_rate() {
  2917. if ($this->samplingrate !== null) {
  2918. return $this->samplingrate;
  2919. }
  2920. else {
  2921. return null;
  2922. }
  2923. }
  2924. public function get_size() {
  2925. $length = $this->get_length();
  2926. if ($length !== null) {
  2927. return round($length/1048576, 2);
  2928. }
  2929. else {
  2930. return null;
  2931. }
  2932. }
  2933. public function get_thumbnail($key = 0) {
  2934. $thumbnails = $this->get_thumbnails();
  2935. if (isset($thumbnails[$key])) {
  2936. return $thumbnails[$key];
  2937. }
  2938. else {
  2939. return null;
  2940. }
  2941. }
  2942. public function get_thumbnails() {
  2943. if ($this->thumbnails !== null) {
  2944. return $this->thumbnails;
  2945. }
  2946. else {
  2947. return null;
  2948. }
  2949. }
  2950. public function get_title() {
  2951. if ($this->title !== null) {
  2952. return $this->title;
  2953. }
  2954. else {
  2955. return null;
  2956. }
  2957. }
  2958. public function get_type() {
  2959. if ($this->type !== null) {
  2960. return $this->type;
  2961. }
  2962. else {
  2963. return null;
  2964. }
  2965. }
  2966. public function get_width() {
  2967. if ($this->width !== null) {
  2968. return $this->width;
  2969. }
  2970. else {
  2971. return null;
  2972. }
  2973. }
  2974. public function native_embed($options='') {
  2975. return $this->embed($options, true);
  2976. }
  2977. public function embed($options = '', $native = false) {
  2978. // Set up defaults
  2979. $audio = '';
  2980. $video = '';
  2981. $alt = '';
  2982. $altclass = '';
  2983. $loop = 'false';
  2984. $width = 'auto';
  2985. $height = 'auto';
  2986. $bgcolor = '#ffffff';
  2987. $mediaplayer = '';
  2988. $widescreen = false;
  2989. $handler = $this->get_handler();
  2990. $type = $this->get_real_type();
  2991. // Process options and reassign values as necessary
  2992. if (is_array($options)) {
  2993. extract($options);
  2994. }
  2995. else {
  2996. $options = explode(',', $options);
  2997. foreach($options as $option) {
  2998. $opt = explode(':', $option, 2);
  2999. if (isset($opt[0], $opt[1])) {
  3000. $opt[0] = trim($opt[0]);
  3001. $opt[1] = trim($opt[1]);
  3002. switch ($opt[0]) {
  3003. case 'audio':
  3004. $audio = $opt[1];
  3005. break;
  3006. case 'video':
  3007. $video = $opt[1];
  3008. break;
  3009. case 'alt':
  3010. $alt = $opt[1];
  3011. break;
  3012. case 'altclass':
  3013. $altclass = $opt[1];
  3014. break;
  3015. case 'loop':
  3016. $loop = $opt[1];
  3017. break;
  3018. case 'width':
  3019. $width = $opt[1];
  3020. break;
  3021. case 'height':
  3022. $height = $opt[1];
  3023. break;
  3024. case 'bgcolor':
  3025. $bgcolor = $opt[1];
  3026. break;
  3027. case 'mediaplayer':
  3028. $mediaplayer = $opt[1];
  3029. break;
  3030. case 'widescreen':
  3031. $widescreen = $opt[1];
  3032. break;
  3033. }
  3034. }
  3035. }
  3036. }
  3037. $mime = explode('/', $type, 2);
  3038. $mime = $mime[0];
  3039. // Process values for 'auto'
  3040. if ($width === 'auto') {
  3041. if ($mime === 'video') {
  3042. if ($height === 'auto') {
  3043. $width = 480;
  3044. }
  3045. elseif ($widescreen) {
  3046. $width = round((intval($height)/9)*16);
  3047. }
  3048. else {
  3049. $width = round((intval($height)/3)*4);
  3050. }
  3051. }
  3052. else {
  3053. $width = '100%';
  3054. }
  3055. }
  3056. if ($height === 'auto') {
  3057. if ($mime === 'audio') {
  3058. $height = 0;
  3059. }
  3060. elseif ($mime === 'video') {
  3061. if ($width === 'auto') {
  3062. if ($widescreen) {
  3063. $height = 270;
  3064. }
  3065. else {
  3066. $height = 360;
  3067. }
  3068. }
  3069. elseif ($widescreen) {
  3070. $height = round((intval($width)/16)*9);
  3071. }
  3072. else {
  3073. $height = round((intval($width)/4)*3);
  3074. }
  3075. }
  3076. else {
  3077. $height = 376;
  3078. }
  3079. }
  3080. elseif ($mime === 'audio') {
  3081. $height = 0;
  3082. }
  3083. // Set proper placeholder value
  3084. if ($mime === 'audio') {
  3085. $placeholder = $audio;
  3086. }
  3087. elseif ($mime === 'video') {
  3088. $placeholder = $video;
  3089. }
  3090. $embed = '';
  3091. // Flash
  3092. if ($handler === 'flash') {
  3093. if ($native) {
  3094. $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>";
  3095. }
  3096. else {
  3097. $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>";
  3098. }
  3099. }
  3100. // Flash Media Player file types.
  3101. // Preferred handler for MP3 file types.
  3102. elseif ($handler === 'fmedia' || ($handler === 'mp3' && $mediaplayer !== '')) {
  3103. $height += 20;
  3104. if ($native) {
  3105. $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>";
  3106. }
  3107. else {
  3108. $embed .= "<script type='text/javascript'>embed_flv('$width', '$height', '" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "', '$placeholder', '$loop', '$mediaplayer');</script>";
  3109. }
  3110. }
  3111. // QuickTime 7 file types. Need to test with QuickTime 6.
  3112. // Only handle MP3's if the Flash Media Player is not present.
  3113. elseif ($handler === 'quicktime' || ($handler === 'mp3' && $mediaplayer === '')) {
  3114. $height += 16;
  3115. if ($native) {
  3116. if ($placeholder !== '') {
  3117. $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>";
  3118. }
  3119. else {
  3120. $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>";
  3121. }
  3122. }
  3123. else {
  3124. $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>";
  3125. }
  3126. }
  3127. // Windows Media
  3128. elseif ($handler === 'wmedia') {
  3129. $height += 45;
  3130. if ($native) {
  3131. $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>";
  3132. }
  3133. else {
  3134. $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>";
  3135. }
  3136. }
  3137. // Everything else
  3138. else $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>';
  3139. return $embed;
  3140. }
  3141. public function get_real_type($find_handler = false) {
  3142. // Mime-types by handler.
  3143. $types_flash = array('application/x-shockwave-flash', 'application/futuresplash'); // Flash
  3144. $types_fmedia = array('video/flv', 'video/x-flv','flv-application/octet-stream'); // Flash Media Player
  3145. $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
  3146. $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
  3147. $types_mp3 = array('audio/mp3', 'audio/x-mp3', 'audio/mpeg', 'audio/x-mpeg'); // MP3
  3148. if ($this->get_type() !== null) {
  3149. $type = strtolower($this->type);
  3150. }
  3151. else {
  3152. $type = null;
  3153. }
  3154. // If we encounter an unsupported mime-type, check the file extension and guess intelligently.
  3155. if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3))) {
  3156. switch (strtolower($this->get_extension())) {
  3157. // Audio mime-types
  3158. case 'aac':
  3159. case 'adts':
  3160. $type = 'audio/acc';
  3161. break;
  3162. case 'aif':
  3163. case 'aifc':
  3164. case 'aiff':
  3165. case 'cdda':
  3166. $type = 'audio/aiff';
  3167. break;
  3168. case 'bwf':
  3169. $type = 'audio/wav';
  3170. break;
  3171. case 'kar':
  3172. case 'mid':
  3173. case 'midi':
  3174. case 'smf':
  3175. $type = 'audio/midi';
  3176. break;
  3177. case 'm4a':
  3178. $type = 'audio/x-m4a';
  3179. break;
  3180. case 'mp3':
  3181. case 'swa':
  3182. $type = 'audio/mp3';
  3183. break;
  3184. case 'wav':
  3185. $type = 'audio/wav';
  3186. break;
  3187. case 'wax':
  3188. $type = 'audio/x-ms-wax';
  3189. break;
  3190. case 'wma':
  3191. $type = 'audio/x-ms-wma';
  3192. break;
  3193. // Video mime-types
  3194. case '3gp':
  3195. case '3gpp':
  3196. $type = 'video/3gpp';
  3197. break;
  3198. case '3g2':
  3199. case '3gp2':
  3200. $type = 'video/3gpp2';
  3201. break;
  3202. case 'asf':
  3203. $type = 'video/x-ms-asf';
  3204. break;
  3205. case 'flv':
  3206. $type = 'video/x-flv';
  3207. break;
  3208. case 'm1a':
  3209. case 'm1s':
  3210. case 'm1v':
  3211. case 'm15':
  3212. case 'm75':
  3213. case 'mp2':
  3214. case 'mpa':
  3215. case 'mpeg':
  3216. case 'mpg':
  3217. case 'mpm':
  3218. case 'mpv':
  3219. $type = 'video/mpeg';
  3220. break;
  3221. case 'm4v':
  3222. $type = 'video/x-m4v';
  3223. break;
  3224. case 'mov':
  3225. case 'qt':
  3226. $type = 'video/quicktime';
  3227. break;
  3228. case 'mp4':
  3229. case 'mpg4':
  3230. $type = 'video/mp4';
  3231. break;
  3232. case 'sdv':
  3233. $type = 'video/sd-video';
  3234. break;
  3235. case 'wm':
  3236. $type = 'video/x-ms-wm';
  3237. break;
  3238. case 'wmv':
  3239. $type = 'video/x-ms-wmv';
  3240. break;
  3241. case 'wvx':
  3242. $type = 'video/x-ms-wvx';
  3243. break;
  3244. // Flash mime-types
  3245. case 'spl':
  3246. $type = 'application/futuresplash';
  3247. break;
  3248. case 'swf':
  3249. $type = 'application/x-shockwave-flash';
  3250. break;
  3251. }
  3252. }
  3253. if ($find_handler) {
  3254. if (in_array($type, $types_flash)) {
  3255. return 'flash';
  3256. }
  3257. elseif (in_array($type, $types_fmedia)) {
  3258. return 'fmedia';
  3259. }
  3260. elseif (in_array($type, $types_quicktime)) {
  3261. return 'quicktime';
  3262. }
  3263. elseif (in_array($type, $types_wmedia)) {
  3264. return 'wmedia';
  3265. }
  3266. elseif (in_array($type, $types_mp3)) {
  3267. return 'mp3';
  3268. }
  3269. else {
  3270. return null;
  3271. }
  3272. }
  3273. else {
  3274. return $type;
  3275. }
  3276. }
  3277. }
  3278. class SimplePie_File {
  3279. var $url;
  3280. var $useragent;
  3281. var $success = true;
  3282. var $headers = array();
  3283. var $body;
  3284. var $status_code;
  3285. var $redirects = 0;
  3286. var $error;
  3287. var $method = SIMPLEPIE_FILE_SOURCE_NONE;
  3288. public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) {
  3289. if (class_exists('idna_convert')) {
  3290. $idn = new idna_convert();
  3291. $parsed = SimplePie_Misc::parse_url($url);
  3292. $url = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
  3293. }
  3294. $this->url = $url;
  3295. $this->useragent = $useragent;
  3296. if (preg_match('/^http(s)?:\/\//i', $url)) {
  3297. if ($useragent === null) {
  3298. $useragent = ini_get('user_agent');
  3299. $this->useragent = $useragent;
  3300. }
  3301. if (!is_array($headers)) {
  3302. $headers = array();
  3303. }
  3304. if (!$force_fsockopen && function_exists('curl_exec')) {
  3305. $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_CURL;
  3306. $fp = curl_init();
  3307. $headers2 = array();
  3308. foreach ($headers as $key => $value) {
  3309. $headers2[] = "$key: $value";
  3310. }
  3311. if (version_compare(SimplePie_Misc::get_curl_version(), '7.10.5', '>=')) {
  3312. curl_setopt($fp, CURLOPT_ENCODING, '');
  3313. }
  3314. curl_setopt($fp, CURLOPT_URL, $url);
  3315. curl_setopt($fp, CURLOPT_HEADER, 1);
  3316. curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
  3317. curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
  3318. curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout);
  3319. curl_setopt($fp, CURLOPT_REFERER, $url);
  3320. curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
  3321. curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
  3322. curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, 0);
  3323. if (!ini_get('open_basedir') && !ini_get('safe_mode') && version_compare(SimplePie_Misc::get_curl_version(), '7.15.2', '>=')) {
  3324. curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
  3325. curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
  3326. }
  3327. $this->headers = curl_exec($fp);
  3328. if (curl_errno($fp) === 23 || curl_errno($fp) === 61) {
  3329. curl_setopt($fp, CURLOPT_ENCODING, 'none');
  3330. $this->headers = curl_exec($fp);
  3331. }
  3332. if (curl_errno($fp)) {
  3333. $this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
  3334. $this->success = false;
  3335. }
  3336. else {
  3337. $info = curl_getinfo($fp);
  3338. curl_close($fp);
  3339. $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 1);
  3340. $this->headers = array_pop($this->headers);
  3341. $parser = new SimplePie_HTTP_Parser($this->headers);
  3342. if ($parser->parse()) {
  3343. $this->headers = $parser->headers;
  3344. $this->body = $parser->body;
  3345. $this->status_code = $parser->status_code;
  3346. 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) {
  3347. $this->redirects++;
  3348. $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
  3349. return $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
  3350. }
  3351. }
  3352. }
  3353. }
  3354. else {
  3355. $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_FSOCKOPEN;
  3356. $url_parts = parse_url($url);
  3357. $socket_host = $url_parts['host'];
  3358. if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https') {
  3359. $socket_host = "ssl://$url_parts[host]";
  3360. $url_parts['port'] = 443;
  3361. }
  3362. if (!isset($url_parts['port'])) {
  3363. $url_parts['port'] = 80;
  3364. }
  3365. $fp = @fsockopen($socket_host, $url_parts['port'], $errno, $errstr, $timeout);
  3366. if (!$fp) {
  3367. $this->error = 'fsockopen error: ' . $errstr;
  3368. $this->success = false;
  3369. }
  3370. else {
  3371. stream_set_timeout($fp, $timeout);
  3372. if (isset($url_parts['path'])) {
  3373. if (isset($url_parts['query'])) {
  3374. $get = "$url_parts[path]?$url_parts[query]";
  3375. }
  3376. else {
  3377. $get = $url_parts['path'];
  3378. }
  3379. }
  3380. else {
  3381. $get = '/';
  3382. }
  3383. $out = "GET $get HTTP/1.1\r\n";
  3384. $out .= "Host: $url_parts[host]\r\n";
  3385. $out .= "User-Agent: $useragent\r\n";
  3386. if (extension_loaded('zlib')) {
  3387. $out .= "Accept-Encoding: x-gzip,gzip,deflate\r\n";
  3388. }
  3389. if (isset($url_parts['user']) && isset($url_parts['pass'])) {
  3390. $out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
  3391. }
  3392. foreach ($headers as $key => $value) {
  3393. $out .= "$key: $value\r\n";
  3394. }
  3395. $out .= "Connection: Close\r\n\r\n";
  3396. fwrite($fp, $out);
  3397. $info = stream_get_meta_data($fp);
  3398. $this->headers = '';
  3399. while (!$info['eof'] && !$info['timed_out']) {
  3400. $this->headers .= fread($fp, 1160);
  3401. $info = stream_get_meta_data($fp);
  3402. }
  3403. if (!$info['timed_out']) {
  3404. $parser = new SimplePie_HTTP_Parser($this->headers);
  3405. if ($parser->parse()) {
  3406. $this->headers = $parser->headers;
  3407. $this->body = $parser->body;
  3408. $this->status_code = $parser->status_code;
  3409. 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) {
  3410. $this->redirects++;
  3411. $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
  3412. return $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
  3413. }
  3414. if (isset($this->headers['content-encoding'])) {
  3415. // Hey, we act dumb elsewhere, so let's do that here too
  3416. switch (strtolower(trim($this->headers['content-encoding'], "\x09\x0A\x0D\x20"))) {
  3417. case 'gzip':
  3418. case 'x-gzip':
  3419. $decoder = new SimplePie_gzdecode($this->body);
  3420. if (!$decoder->parse()) {
  3421. $this->error = 'Unable to decode HTTP "gzip" stream';
  3422. $this->success = false;
  3423. }
  3424. else {
  3425. $this->body = $decoder->data;
  3426. }
  3427. break;
  3428. case 'deflate':
  3429. if (($decompressed = gzinflate($this->body)) !== false) {
  3430. $this->body = $decompressed;
  3431. }
  3432. else if (($decompressed = gzuncompress($this->body)) !== false) {
  3433. $this->body = $decompressed;
  3434. }
  3435. else if (function_exists('gzdecode') && ($decompressed = gzdecode($this->body)) !== false) {
  3436. $this->body = $decompressed;
  3437. }
  3438. else {
  3439. $this->error = 'Unable to decode HTTP "deflate" stream';
  3440. $this->success = false;
  3441. }
  3442. break;
  3443. default:
  3444. $this->error = 'Unknown content coding';
  3445. $this->success = false;
  3446. }
  3447. }
  3448. }
  3449. }
  3450. else {
  3451. $this->error = 'fsocket timed out';
  3452. $this->success = false;
  3453. }
  3454. fclose($fp);
  3455. }
  3456. }
  3457. }
  3458. else {
  3459. $this->method = SIMPLEPIE_FILE_SOURCE_LOCAL | SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS;
  3460. if (!$this->body = file_get_contents($url)) {
  3461. $this->error = 'file_get_contents could not read the file';
  3462. $this->success = false;
  3463. }
  3464. }
  3465. }
  3466. }
  3467. class SimplePie_gzdecode {
  3468. var $compressed_data;
  3469. var $compressed_size;
  3470. var $min_compressed_size = 18;
  3471. var $position = 0;
  3472. var $flags;
  3473. var $data;
  3474. var $MTIME;
  3475. var $XFL;
  3476. var $OS;
  3477. var $SI1;
  3478. var $SI2;
  3479. var $extra_field;
  3480. var $filename;
  3481. var $comment;
  3482. public function __set($name, $value) {
  3483. trigger_error("Cannot write property $name", E_USER_ERROR);
  3484. }
  3485. public function __construct($data) {
  3486. $this->compressed_data = $data;
  3487. $this->compressed_size = strlen($data);
  3488. }
  3489. public function parse() {
  3490. if ($this->compressed_size >= $this->min_compressed_size) {
  3491. // Check ID1, ID2, and CM
  3492. if (substr($this->compressed_data, 0, 3) !== "\x1F\x8B\x08") {
  3493. return false;
  3494. }
  3495. // Get the FLG (FLaGs)
  3496. $this->flags = ord($this->compressed_data[3]);
  3497. // FLG bits above (1 << 4) are reserved
  3498. if ($this->flags > 0x1F) {
  3499. return false;
  3500. }
  3501. // Advance the pointer after the above
  3502. $this->position += 4;
  3503. // MTIME
  3504. $mtime = substr($this->compressed_data, $this->position, 4);
  3505. // Reverse the string if we're on a big-endian arch because l is the only signed long and is machine endianness
  3506. if (current(unpack('S', "\x00\x01")) === 1) {
  3507. $mtime = strrev($mtime);
  3508. }
  3509. $this->MTIME = current(unpack('l', $mtime));
  3510. $this->position += 4;
  3511. // Get the XFL (eXtra FLags)
  3512. $this->XFL = ord($this->compressed_data[$this->position++]);
  3513. // Get the OS (Operating System)
  3514. $this->OS = ord($this->compressed_data[$this->position++]);
  3515. // Parse the FEXTRA
  3516. if ($this->flags & 4) {
  3517. // Read subfield IDs
  3518. $this->SI1 = $this->compressed_data[$this->position++];
  3519. $this->SI2 = $this->compressed_data[$this->position++];
  3520. // SI2 set to zero is reserved for future use
  3521. if ($this->SI2 === "\x00") {
  3522. return false;
  3523. }
  3524. // Get the length of the extra field
  3525. $len = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
  3526. $this->position += 2;
  3527. // Check the length of the string is still valid
  3528. $this->min_compressed_size += $len + 4;
  3529. if ($this->compressed_size >= $this->min_compressed_size) {
  3530. // Set the extra field to the given data
  3531. $this->extra_field = substr($this->compressed_data, $this->position, $len);
  3532. $this->position += $len;
  3533. }
  3534. else {
  3535. return false;
  3536. }
  3537. }
  3538. // Parse the FNAME
  3539. if ($this->flags & 8) {
  3540. // Get the length of the filename
  3541. $len = strcspn($this->compressed_data, "\x00", $this->position);
  3542. // Check the length of the string is still valid
  3543. $this->min_compressed_size += $len + 1;
  3544. if ($this->compressed_size >= $this->min_compressed_size) {
  3545. // Set the original filename to the given string
  3546. $this->filename = substr($this->compressed_data, $this->position, $len);
  3547. $this->position += $len + 1;
  3548. }
  3549. else {
  3550. return false;
  3551. }
  3552. }
  3553. // Parse the FCOMMENT
  3554. if ($this->flags & 16) {
  3555. // Get the length of the comment
  3556. $len = strcspn($this->compressed_data, "\x00", $this->position);
  3557. // Check the length of the string is still valid
  3558. $this->min_compressed_size += $len + 1;
  3559. if ($this->compressed_size >= $this->min_compressed_size) {
  3560. // Set the original comment to the given string
  3561. $this->comment = substr($this->compressed_data, $this->position, $len);
  3562. $this->position += $len + 1;
  3563. }
  3564. else {
  3565. return false;
  3566. }
  3567. }
  3568. // Parse the FHCRC
  3569. if ($this->flags & 2) {
  3570. // Check the length of the string is still valid
  3571. $this->min_compressed_size += $len + 2;
  3572. if ($this->compressed_size >= $this->min_compressed_size) {
  3573. // Read the CRC
  3574. $crc = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
  3575. // Check the CRC matches
  3576. if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc) {
  3577. $this->position += 2;
  3578. }
  3579. else {
  3580. return false;
  3581. }
  3582. }
  3583. else {
  3584. return false;
  3585. }
  3586. }
  3587. // Decompress the actual data
  3588. if (($this->data = gzinflate(substr($this->compressed_data, $this->position, -8))) === false) {
  3589. return false;
  3590. }
  3591. else {
  3592. $this->position = $this->compressed_size - 8;
  3593. }
  3594. // Check CRC of data
  3595. $crc = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
  3596. $this->position += 4;
  3597. /*if (extension_loaded('hash') && sprintf('%u', current(unpack('V', hash('crc32b', $this->data)))) !== sprintf('%u', $crc)) {
  3598. return false;
  3599. }*/
  3600. // Check ISIZE of data
  3601. $isize = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
  3602. $this->position += 4;
  3603. if (sprintf('%u', strlen($this->data) & 0xFFFFFFFF) !== sprintf('%u', $isize)) {
  3604. return false;
  3605. }
  3606. // Wow, against all odds, we've actually got a valid gzip string
  3607. return true;
  3608. }
  3609. else {
  3610. return false;
  3611. }
  3612. }
  3613. }
  3614. class SimplePie_HTTP_Parser {
  3615. public $http_version = 0.0;
  3616. public $status_code = 0;
  3617. public $reason = '';
  3618. public $headers = array();
  3619. public $body = '';
  3620. protected $state = 'http_version';
  3621. protected $data = '';
  3622. protected $data_length = 0;
  3623. protected $position = 0;
  3624. protected $name = '';
  3625. protected $value = '';
  3626. public function __construct($data) {
  3627. $this->data = $data;
  3628. $this->data_length = strlen($this->data);
  3629. }
  3630. public function parse() {
  3631. while ($this->state && $this->state !== 'emit' && $this->has_data()) {
  3632. $state = $this->state;
  3633. $this->$state();
  3634. }
  3635. $this->data = '';
  3636. if ($this->state === 'emit' || $this->state === 'body') {
  3637. return true;
  3638. }
  3639. else {
  3640. $this->http_version = '';
  3641. $this->status_code = '';
  3642. $this->reason = '';
  3643. $this->headers = array();
  3644. $this->body = '';
  3645. return false;
  3646. }
  3647. }
  3648. protected function has_data() {
  3649. return (bool) ($this->position < $this->data_length);
  3650. }
  3651. protected function is_linear_whitespace() {
  3652. return (bool) ($this->data[$this->position] === "\x09"
  3653. || $this->data[$this->position] === "\x20"
  3654. || ($this->data[$this->position] === "\x0A"
  3655. && isset($this->data[$this->position + 1])
  3656. && ($this->data[$this->position + 1] === "\x09" || $this->data[$this->position + 1] === "\x20")));
  3657. }
  3658. protected function http_version() {
  3659. if (strpos($this->data, "\x0A") !== false && strtoupper(substr($this->data, 0, 5)) === 'HTTP/') {
  3660. $len = strspn($this->data, '0123456789.', 5);
  3661. $this->http_version = substr($this->data, 5, $len);
  3662. $this->position += 5 + $len;
  3663. if (substr_count($this->http_version, '.') <= 1) {
  3664. $this->http_version = (float) $this->http_version;
  3665. $this->position += strspn($this->data, "\x09\x20", $this->position);
  3666. $this->state = 'status';
  3667. }
  3668. else {
  3669. $this->state = false;
  3670. }
  3671. }
  3672. else {
  3673. $this->state = false;
  3674. }
  3675. }
  3676. protected function status() {
  3677. if ($len = strspn($this->data, '0123456789', $this->position)) {
  3678. $this->status_code = (int) substr($this->data, $this->position, $len);
  3679. $this->position += $len;
  3680. $this->state = 'reason';
  3681. }
  3682. else {
  3683. $this->state = false;
  3684. }
  3685. }
  3686. protected function reason() {
  3687. $len = strcspn($this->data, "\x0A", $this->position);
  3688. $this->reason = trim(substr($this->data, $this->position, $len), "\x09\x0D\x20");
  3689. $this->position += $len + 1;
  3690. $this->state = 'new_line';
  3691. }
  3692. protected function new_line() {
  3693. $this->value = trim($this->value, "\x0D\x20");
  3694. if ($this->name !== '' && $this->value !== '') {
  3695. $this->name = strtolower($this->name);
  3696. // We should only use the last Content-Type header. c.f. issue #1
  3697. if (isset($this->headers[$this->name]) && $this->name !== 'content-type') {
  3698. $this->headers[$this->name] .= ', ' . $this->value;
  3699. }
  3700. else {
  3701. $this->headers[$this->name] = $this->value;
  3702. }
  3703. }
  3704. $this->name = '';
  3705. $this->value = '';
  3706. if (substr($this->data[$this->position], 0, 2) === "\x0D\x0A") {
  3707. $this->position += 2;
  3708. $this->state = 'body';
  3709. }
  3710. elseif ($this->data[$this->position] === "\x0A") {
  3711. $this->position++;
  3712. $this->state = 'body';
  3713. }
  3714. else {
  3715. $this->state = 'name';
  3716. }
  3717. }
  3718. protected function name() {
  3719. $len = strcspn($this->data, "\x0A:", $this->position);
  3720. if (isset($this->data[$this->position + $len])) {
  3721. if ($this->data[$this->position + $len] === "\x0A") {
  3722. $this->position += $len;
  3723. $this->state = 'new_line';
  3724. }
  3725. else {
  3726. $this->name = substr($this->data, $this->position, $len);
  3727. $this->position += $len + 1;
  3728. $this->state = 'value';
  3729. }
  3730. }
  3731. else {
  3732. $this->state = false;
  3733. }
  3734. }
  3735. protected function linear_whitespace() {
  3736. do {
  3737. if (substr($this->data, $this->position, 2) === "\x0D\x0A") {
  3738. $this->position += 2;
  3739. }
  3740. elseif ($this->data[$this->position] === "\x0A") {
  3741. $this->position++;
  3742. }
  3743. $this->position += strspn($this->data, "\x09\x20", $this->position);
  3744. } while ($this->has_data() && $this->is_linear_whitespace());
  3745. $this->value .= "\x20";
  3746. }
  3747. protected function value() {
  3748. if ($this->is_linear_whitespace()) {
  3749. $this->linear_whitespace();
  3750. }
  3751. else {
  3752. switch ($this->data[$this->position]) {
  3753. case '"':
  3754. // Workaround for ETags: we have to include the quotes as
  3755. // part of the tag.
  3756. if (strtolower($this->name) === 'etag') {
  3757. $this->value .= '"';
  3758. $this->position++;
  3759. $this->state = 'value_char';
  3760. break;
  3761. }
  3762. $this->position++;
  3763. $this->state = 'quote';
  3764. break;
  3765. case "\x0A":
  3766. $this->position++;
  3767. $this->state = 'new_line';
  3768. break;
  3769. default:
  3770. $this->state = 'value_char';
  3771. break;
  3772. }
  3773. }
  3774. }
  3775. protected function value_char() {
  3776. $len = strcspn($this->data, "\x09\x20\x0A\"", $this->position);
  3777. $this->value .= substr($this->data, $this->position, $len);
  3778. $this->position += $len;
  3779. $this->state = 'value';
  3780. }
  3781. protected function quote() {
  3782. if ($this->is_linear_whitespace()) {
  3783. $this->linear_whitespace();
  3784. }
  3785. else {
  3786. switch ($this->data[$this->position]) {
  3787. case '"':
  3788. $this->position++;
  3789. $this->state = 'value';
  3790. break;
  3791. case "\x0A":
  3792. $this->position++;
  3793. $this->state = 'new_line';
  3794. break;
  3795. case '\\':
  3796. $this->position++;
  3797. $this->state = 'quote_escaped';
  3798. break;
  3799. default:
  3800. $this->state = 'quote_char';
  3801. break;
  3802. }
  3803. }
  3804. }
  3805. protected function quote_char() {
  3806. $len = strcspn($this->data, "\x09\x20\x0A\"\\", $this->position);
  3807. $this->value .= substr($this->data, $this->position, $len);
  3808. $this->position += $len;
  3809. $this->state = 'value';
  3810. }
  3811. protected function quote_escaped() {
  3812. $this->value .= $this->data[$this->position];
  3813. $this->position++;
  3814. $this->state = 'quote';
  3815. }
  3816. protected function body() {
  3817. $this->body = substr($this->data, $this->position);
  3818. if (!empty($this->headers['transfer-encoding'])) {
  3819. unset($this->headers['transfer-encoding']);
  3820. $this->state = 'chunked';
  3821. }
  3822. else {
  3823. $this->state = 'emit';
  3824. }
  3825. }
  3826. protected function chunked() {
  3827. if (!preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', trim($this->body))) {
  3828. $this->state = 'emit';
  3829. return;
  3830. }
  3831. $decoded = '';
  3832. $encoded = $this->body;
  3833. while (true) {
  3834. $is_chunked = (bool) preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', $encoded, $matches );
  3835. if (!$is_chunked) {
  3836. // Looks like it's not chunked after all
  3837. $this->state = 'emit';
  3838. return;
  3839. }
  3840. $length = hexdec(trim($matches[1]));
  3841. if ($length === 0) {
  3842. // Ignore trailer headers
  3843. $this->state = 'emit';
  3844. $this->body = $decoded;
  3845. return;
  3846. }
  3847. $chunk_length = strlen($matches[0]);
  3848. $decoded .= $part = substr($encoded, $chunk_length, $length);
  3849. $encoded = substr($encoded, $chunk_length + $length + 2);
  3850. if (trim($encoded) === '0' || empty($encoded)) {
  3851. $this->state = 'emit';
  3852. $this->body = $decoded;
  3853. return;
  3854. }
  3855. }
  3856. }
  3857. }
  3858. class SimplePie_IRI {
  3859. protected $scheme = null;
  3860. protected $iuserinfo = null;
  3861. protected $ihost = null;
  3862. protected $port = null;
  3863. protected $ipath = '';
  3864. protected $iquery = null;
  3865. protected $ifragment = null;
  3866. protected $normalization = array(
  3867. 'acap' => array(
  3868. 'port' => 674
  3869. ),
  3870. 'dict' => array(
  3871. 'port' => 2628
  3872. ),
  3873. 'file' => array(
  3874. 'ihost' => 'localhost'
  3875. ),
  3876. 'http' => array(
  3877. 'port' => 80,
  3878. 'ipath' => '/'
  3879. ),
  3880. 'https' => array(
  3881. 'port' => 443,
  3882. 'ipath' => '/'
  3883. ),
  3884. );
  3885. public function __toString() {
  3886. return $this->get_iri();
  3887. }
  3888. public function __set($name, $value) {
  3889. if (method_exists($this, 'set_' . $name)) {
  3890. call_user_func(array($this, 'set_' . $name), $value);
  3891. }
  3892. elseif (
  3893. $name === 'iauthority'
  3894. || $name === 'iuserinfo'
  3895. || $name === 'ihost'
  3896. || $name === 'ipath'
  3897. || $name === 'iquery'
  3898. || $name === 'ifragment'
  3899. ) {
  3900. call_user_func(array($this, 'set_' . substr($name, 1)), $value);
  3901. }
  3902. }
  3903. public function __get($name) {
  3904. // isset() returns false for null, we don't want to do that
  3905. // Also why we use array_key_exists below instead of isset()
  3906. $props = get_object_vars($this);
  3907. if (
  3908. $name === 'iri' ||
  3909. $name === 'uri' ||
  3910. $name === 'iauthority' ||
  3911. $name === 'authority'
  3912. ) {
  3913. $return = $this->{"get_$name"}();
  3914. }
  3915. elseif (array_key_exists($name, $props)) {
  3916. $return = $this->$name;
  3917. }
  3918. // host -> ihost
  3919. elseif (($prop = 'i' . $name) && array_key_exists($prop, $props)) {
  3920. $name = $prop;
  3921. $return = $this->$prop;
  3922. }
  3923. // ischeme -> scheme
  3924. elseif (($prop = substr($name, 1)) && array_key_exists($prop, $props)) {
  3925. $name = $prop;
  3926. $return = $this->$prop;
  3927. }
  3928. else {
  3929. trigger_error('Undefined property: ' . get_class($this) . '::' . $name, E_USER_NOTICE);
  3930. $return = null;
  3931. }
  3932. if ($return === null && isset($this->normalization[$this->scheme][$name])) {
  3933. return $this->normalization[$this->scheme][$name];
  3934. }
  3935. else {
  3936. return $return;
  3937. }
  3938. }
  3939. public function __isset($name) {
  3940. if (method_exists($this, 'get_' . $name) || isset($this->$name)) {
  3941. return true;
  3942. }
  3943. else {
  3944. return false;
  3945. }
  3946. }
  3947. public function __unset($name) {
  3948. if (method_exists($this, 'set_' . $name)) {
  3949. call_user_func(array($this, 'set_' . $name), '');
  3950. }
  3951. }
  3952. public function __construct($iri = null) {
  3953. $this->set_iri($iri);
  3954. }
  3955. public static function absolutize($base, $relative) {
  3956. if (!($relative instanceof SimplePie_IRI)) {
  3957. $relative = new SimplePie_IRI($relative);
  3958. }
  3959. if (!$relative->is_valid()) {
  3960. return false;
  3961. }
  3962. elseif ($relative->scheme !== null) {
  3963. return clone $relative;
  3964. }
  3965. else {
  3966. if (!($base instanceof SimplePie_IRI)) {
  3967. $base = new SimplePie_IRI($base);
  3968. }
  3969. if ($base->scheme !== null && $base->is_valid()) {
  3970. if ($relative->get_iri() !== '') {
  3971. if ($relative->iuserinfo !== null || $relative->ihost !== null || $relative->port !== null) {
  3972. $target = clone $relative;
  3973. $target->scheme = $base->scheme;
  3974. }
  3975. else {
  3976. $target = new SimplePie_IRI;
  3977. $target->scheme = $base->scheme;
  3978. $target->iuserinfo = $base->iuserinfo;
  3979. $target->ihost = $base->ihost;
  3980. $target->port = $base->port;
  3981. if ($relative->ipath !== '') {
  3982. if ($relative->ipath[0] === '/') {
  3983. $target->ipath = $relative->ipath;
  3984. }
  3985. elseif (($base->iuserinfo !== null || $base->ihost !== null || $base->port !== null) && $base->ipath === '') {
  3986. $target->ipath = '/' . $relative->ipath;
  3987. }
  3988. elseif (($last_segment = strrpos($base->ipath, '/')) !== false) {
  3989. $target->ipath = substr($base->ipath, 0, $last_segment + 1) . $relative->ipath;
  3990. }
  3991. else {
  3992. $target->ipath = $relative->ipath;
  3993. }
  3994. $target->ipath = $target->remove_dot_segments($target->ipath);
  3995. $target->iquery = $relative->iquery;
  3996. }
  3997. else {
  3998. $target->ipath = $base->ipath;
  3999. if ($relative->iquery !== null) {
  4000. $target->iquery = $relative->iquery;
  4001. }
  4002. elseif ($base->iquery !== null) {
  4003. $target->iquery = $base->iquery;
  4004. }
  4005. }
  4006. $target->ifragment = $relative->ifragment;
  4007. }
  4008. }
  4009. else {
  4010. $target = clone $base;
  4011. $target->ifragment = null;
  4012. }
  4013. $target->scheme_normalization();
  4014. return $target;
  4015. }
  4016. else {
  4017. return false;
  4018. }
  4019. }
  4020. }
  4021. protected function parse_iri($iri) {
  4022. $iri = trim($iri, "\x20\x09\x0A\x0C\x0D");
  4023. if (preg_match('/^((?P<scheme>[^:\/?#]+):)?(\/\/(?P<authority>[^\/?#]*))?(?P<path>[^?#]*)(\?(?P<query>[^#]*))?(#(?P<fragment>.*))?$/', $iri, $match)) {
  4024. if ($match[1] === '') {
  4025. $match['scheme'] = null;
  4026. }
  4027. if (!isset($match[3]) || $match[3] === '') {
  4028. $match['authority'] = null;
  4029. }
  4030. if (!isset($match[5])) {
  4031. $match['path'] = '';
  4032. }
  4033. if (!isset($match[6]) || $match[6] === '') {
  4034. $match['query'] = null;
  4035. }
  4036. if (!isset($match[8]) || $match[8] === '') {
  4037. $match['fragment'] = null;
  4038. }
  4039. $match['path'] = preg_replace ('#//#', '/', $match['path']); // fix un bug lorsque 2 slashs se suivent
  4040. return $match;
  4041. }
  4042. else {
  4043. trigger_error('This should never happen', E_USER_ERROR);
  4044. die;
  4045. }
  4046. }
  4047. protected function remove_dot_segments($input) {
  4048. $output = '';
  4049. while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..') {
  4050. // A: If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise,
  4051. if (strpos($input, '../') === 0) {
  4052. $input = substr($input, 3);
  4053. }
  4054. elseif (strpos($input, './') === 0) {
  4055. $input = substr($input, 2);
  4056. }
  4057. // 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,
  4058. elseif (strpos($input, '/./') === 0) {
  4059. $input = substr($input, 2);
  4060. }
  4061. elseif ($input === '/.') {
  4062. $input = '/';
  4063. }
  4064. // 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,
  4065. elseif (strpos($input, '/../') === 0) {
  4066. $input = substr($input, 3);
  4067. $output = substr_replace($output, '', strrpos($output, '/'));
  4068. }
  4069. elseif ($input === '/..') {
  4070. $input = '/';
  4071. $output = substr_replace($output, '', strrpos($output, '/'));
  4072. }
  4073. // D: if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise,
  4074. elseif ($input === '.' || $input === '..') {
  4075. $input = '';
  4076. }
  4077. // 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
  4078. elseif (($pos = strpos($input, '/', 1)) !== false) {
  4079. $output .= substr($input, 0, $pos);
  4080. $input = substr_replace($input, '', 0, $pos);
  4081. }
  4082. else {
  4083. $output .= $input;
  4084. $input = '';
  4085. }
  4086. }
  4087. return $output . $input;
  4088. }
  4089. protected function replace_invalid_with_pct_encoding($string, $extra_chars, $iprivate = false) {
  4090. // Normalize as many pct-encoded sections as possible
  4091. $string = preg_replace_callback('/(?:%[A-Fa-f0-9]{2})+/', array($this, 'remove_iunreserved_percent_encoded'), $string);
  4092. // Replace invalid percent characters
  4093. $string = preg_replace('/%(?![A-Fa-f0-9]{2})/', '%25', $string);
  4094. // Add unreserved and % to $extra_chars (the latter is safe because all
  4095. // pct-encoded sections are now valid).
  4096. $extra_chars .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~%';
  4097. // Now replace any bytes that aren't allowed with their pct-encoded versions
  4098. $position = 0;
  4099. $strlen = strlen($string);
  4100. while (($position += strspn($string, $extra_chars, $position)) < $strlen) {
  4101. $value = ord($string[$position]);
  4102. // Start position
  4103. $start = $position;
  4104. // By default we are valid
  4105. $valid = true;
  4106. // No one byte sequences are valid due to the while.
  4107. // Two byte sequence:
  4108. if (($value & 0xE0) === 0xC0) {
  4109. $character = ($value & 0x1F) << 6;
  4110. $length = 2;
  4111. $remaining = 1;
  4112. }
  4113. // Three byte sequence:
  4114. elseif (($value & 0xF0) === 0xE0) {
  4115. $character = ($value & 0x0F) << 12;
  4116. $length = 3;
  4117. $remaining = 2;
  4118. }
  4119. // Four byte sequence:
  4120. elseif (($value & 0xF8) === 0xF0) {
  4121. $character = ($value & 0x07) << 18;
  4122. $length = 4;
  4123. $remaining = 3;
  4124. }
  4125. // Invalid byte:
  4126. else {
  4127. $valid = false;
  4128. $length = 1;
  4129. $remaining = 0;
  4130. }
  4131. if ($remaining) {
  4132. if ($position + $length <= $strlen) {
  4133. for ($position++; $remaining; $position++) {
  4134. $value = ord($string[$position]);
  4135. // Check that the byte is valid, then add it to the character:
  4136. if (($value & 0xC0) === 0x80) {
  4137. $character |= ($value & 0x3F) << (--$remaining * 6);
  4138. }
  4139. // If it is invalid, count the sequence as invalid and reprocess the current byte:
  4140. else {
  4141. $valid = false;
  4142. $position--;
  4143. break;
  4144. }
  4145. }
  4146. }
  4147. else {
  4148. $position = $strlen - 1;
  4149. $valid = false;
  4150. }
  4151. }
  4152. // Percent encode anything invalid or not in ucschar
  4153. if (
  4154. // Invalid sequences
  4155. !$valid
  4156. // Non-shortest form sequences are invalid
  4157. || $length > 1 && $character <= 0x7F
  4158. || $length > 2 && $character <= 0x7FF
  4159. || $length > 3 && $character <= 0xFFFF
  4160. // Outside of range of ucschar codepoints
  4161. // Noncharacters
  4162. || ($character & 0xFFFE) === 0xFFFE
  4163. || $character >= 0xFDD0 && $character <= 0xFDEF
  4164. || (
  4165. // Everything else not in ucschar
  4166. $character > 0xD7FF && $character < 0xF900
  4167. || $character < 0xA0
  4168. || $character > 0xEFFFD
  4169. )
  4170. && (
  4171. // Everything not in iprivate, if it applies
  4172. !$iprivate
  4173. || $character < 0xE000
  4174. || $character > 0x10FFFD
  4175. )
  4176. ) {
  4177. // If we were a character, pretend we weren't, but rather an error.
  4178. if ($valid)
  4179. $position--;
  4180. for ($j = $start; $j <= $position; $j++) {
  4181. $string = substr_replace($string, sprintf('%%%02X', ord($string[$j])), $j, 1);
  4182. $j += 2;
  4183. $position += 2;
  4184. $strlen += 2;
  4185. }
  4186. }
  4187. }
  4188. return $string;
  4189. }
  4190. protected function remove_iunreserved_percent_encoded($match) {
  4191. // As we just have valid percent encoded sequences we can just explode
  4192. // and ignore the first member of the returned array (an empty string).
  4193. $bytes = explode('%', $match[0]);
  4194. // Initialize the new string (this is what will be returned) and that
  4195. // there are no bytes remaining in the current sequence (unsurprising
  4196. // at the first byte!).
  4197. $string = '';
  4198. $remaining = 0;
  4199. // Loop over each and every byte, and set $value to its value
  4200. for ($i = 1, $len = count($bytes); $i < $len; $i++) {
  4201. $value = hexdec($bytes[$i]);
  4202. // If we're the first byte of sequence:
  4203. if (!$remaining) {
  4204. // Start position
  4205. $start = $i;
  4206. // By default we are valid
  4207. $valid = true;
  4208. // One byte sequence:
  4209. if ($value <= 0x7F) {
  4210. $character = $value;
  4211. $length = 1;
  4212. }
  4213. // Two byte sequence:
  4214. elseif (($value & 0xE0) === 0xC0) {
  4215. $character = ($value & 0x1F) << 6;
  4216. $length = 2;
  4217. $remaining = 1;
  4218. }
  4219. // Three byte sequence:
  4220. elseif (($value & 0xF0) === 0xE0) {
  4221. $character = ($value & 0x0F) << 12;
  4222. $length = 3;
  4223. $remaining = 2;
  4224. }
  4225. // Four byte sequence:
  4226. elseif (($value & 0xF8) === 0xF0) {
  4227. $character = ($value & 0x07) << 18;
  4228. $length = 4;
  4229. $remaining = 3;
  4230. }
  4231. // Invalid byte:
  4232. else {
  4233. $valid = false;
  4234. $remaining = 0;
  4235. }
  4236. }
  4237. // Continuation byte:
  4238. else {
  4239. // Check that the byte is valid, then add it to the character:
  4240. if (($value & 0xC0) === 0x80) {
  4241. $remaining--;
  4242. $character |= ($value & 0x3F) << ($remaining * 6);
  4243. }
  4244. // If it is invalid, count the sequence as invalid and reprocess the current byte as the start of a sequence:
  4245. else {
  4246. $valid = false;
  4247. $remaining = 0;
  4248. $i--;
  4249. }
  4250. }
  4251. // If we've reached the end of the current byte sequence, append it to Unicode::$data
  4252. if (!$remaining) {
  4253. // Percent encode anything invalid or not in iunreserved
  4254. if (
  4255. // Invalid sequences
  4256. !$valid
  4257. // Non-shortest form sequences are invalid
  4258. || $length > 1 && $character <= 0x7F
  4259. || $length > 2 && $character <= 0x7FF
  4260. || $length > 3 && $character <= 0xFFFF
  4261. // Outside of range of iunreserved codepoints
  4262. || $character < 0x2D
  4263. || $character > 0xEFFFD
  4264. // Noncharacters
  4265. || ($character & 0xFFFE) === 0xFFFE
  4266. || $character >= 0xFDD0 && $character <= 0xFDEF
  4267. // Everything else not in iunreserved (this is all BMP)
  4268. || $character === 0x2F
  4269. || $character > 0x39 && $character < 0x41
  4270. || $character > 0x5A && $character < 0x61
  4271. || $character > 0x7A && $character < 0x7E
  4272. || $character > 0x7E && $character < 0xA0
  4273. || $character > 0xD7FF && $character < 0xF900
  4274. ) {
  4275. for ($j = $start; $j <= $i; $j++) {
  4276. $string .= '%' . strtoupper($bytes[$j]);
  4277. }
  4278. }
  4279. else {
  4280. for ($j = $start; $j <= $i; $j++) {
  4281. $string .= chr(hexdec($bytes[$j]));
  4282. }
  4283. }
  4284. }
  4285. }
  4286. // If we have any bytes left over they are invalid (i.e., we are
  4287. // mid-way through a multi-byte sequence)
  4288. if ($remaining) {
  4289. for ($j = $start; $j < $len; $j++) {
  4290. $string .= '%' . strtoupper($bytes[$j]);
  4291. }
  4292. }
  4293. return $string;
  4294. }
  4295. protected function scheme_normalization() {
  4296. if (isset($this->normalization[$this->scheme]['iuserinfo']) && $this->iuserinfo === $this->normalization[$this->scheme]['iuserinfo']) {
  4297. $this->iuserinfo = null;
  4298. }
  4299. if (isset($this->normalization[$this->scheme]['ihost']) && $this->ihost === $this->normalization[$this->scheme]['ihost']) {
  4300. $this->ihost = null;
  4301. }
  4302. if (isset($this->normalization[$this->scheme]['port']) && $this->port === $this->normalization[$this->scheme]['port']) {
  4303. $this->port = null;
  4304. }
  4305. if (isset($this->normalization[$this->scheme]['ipath']) && $this->ipath === $this->normalization[$this->scheme]['ipath']) {
  4306. $this->ipath = '';
  4307. }
  4308. if (isset($this->normalization[$this->scheme]['iquery']) && $this->iquery === $this->normalization[$this->scheme]['iquery']) {
  4309. $this->iquery = null;
  4310. }
  4311. if (isset($this->normalization[$this->scheme]['ifragment']) && $this->ifragment === $this->normalization[$this->scheme]['ifragment']) {
  4312. $this->ifragment = null;
  4313. }
  4314. }
  4315. public function is_valid() {
  4316. $isauthority = $this->iuserinfo !== null || $this->ihost !== null || $this->port !== null;
  4317. if ($this->ipath !== '' &&
  4318. (
  4319. $isauthority && (
  4320. $this->ipath[0] !== '/' ||
  4321. substr($this->ipath, 0, 2) === '//'
  4322. ) ||
  4323. (
  4324. $this->scheme === null &&
  4325. !$isauthority &&
  4326. strpos($this->ipath, ':') !== false &&
  4327. (strpos($this->ipath, '/') === false ? true : strpos($this->ipath, ':') < strpos($this->ipath, '/'))
  4328. )
  4329. )
  4330. ) {
  4331. return false;
  4332. }
  4333. return true;
  4334. }
  4335. public function set_iri($iri) {
  4336. static $cache;
  4337. if (!$cache) {
  4338. $cache = array();
  4339. }
  4340. if ($iri === null) {
  4341. return true;
  4342. }
  4343. elseif (isset($cache[$iri])) {
  4344. list($this->scheme,
  4345. $this->iuserinfo,
  4346. $this->ihost,
  4347. $this->port,
  4348. $this->ipath,
  4349. $this->iquery,
  4350. $this->ifragment,
  4351. $return) = $cache[$iri];
  4352. return $return;
  4353. }
  4354. else {
  4355. $parsed = $this->parse_iri((string) $iri);
  4356. $return = $this->set_scheme($parsed['scheme'])
  4357. && $this->set_authority($parsed['authority'])
  4358. && $this->set_path($parsed['path'])
  4359. && $this->set_query($parsed['query'])
  4360. && $this->set_fragment($parsed['fragment']);
  4361. $cache[$iri] = array($this->scheme,
  4362. $this->iuserinfo,
  4363. $this->ihost,
  4364. $this->port,
  4365. $this->ipath,
  4366. $this->iquery,
  4367. $this->ifragment,
  4368. $return);
  4369. return $return;
  4370. }
  4371. }
  4372. public function set_scheme($scheme) {
  4373. if ($scheme === null) {
  4374. $this->scheme = null;
  4375. }
  4376. elseif (!preg_match('/^[A-Za-z][0-9A-Za-z+\-.]*$/', $scheme)) {
  4377. $this->scheme = null;
  4378. return false;
  4379. }
  4380. else {
  4381. $this->scheme = strtolower($scheme);
  4382. }
  4383. return true;
  4384. }
  4385. public function set_authority($authority) {
  4386. static $cache;
  4387. if (!$cache)
  4388. $cache = array();
  4389. if ($authority === null) {
  4390. $this->iuserinfo = null;
  4391. $this->ihost = null;
  4392. $this->port = null;
  4393. return true;
  4394. }
  4395. elseif (isset($cache[$authority])) {
  4396. list($this->iuserinfo,
  4397. $this->ihost,
  4398. $this->port,
  4399. $return) = $cache[$authority];
  4400. return $return;
  4401. }
  4402. else {
  4403. $remaining = $authority;
  4404. if (($iuserinfo_end = strrpos($remaining, '@')) !== false) {
  4405. $iuserinfo = substr($remaining, 0, $iuserinfo_end);
  4406. $remaining = substr($remaining, $iuserinfo_end + 1);
  4407. }
  4408. else {
  4409. $iuserinfo = null;
  4410. }
  4411. if (($port_start = strpos($remaining, ':', strpos($remaining, ']'))) !== false) {
  4412. if (($port = substr($remaining, $port_start + 1)) === false) {
  4413. $port = null;
  4414. }
  4415. $remaining = substr($remaining, 0, $port_start);
  4416. }
  4417. else {
  4418. $port = null;
  4419. }
  4420. $return = $this->set_userinfo($iuserinfo) &&
  4421. $this->set_host($remaining) &&
  4422. $this->set_port($port);
  4423. $cache[$authority] = array($this->iuserinfo,
  4424. $this->ihost,
  4425. $this->port,
  4426. $return);
  4427. return $return;
  4428. }
  4429. }
  4430. public function set_userinfo($iuserinfo) {
  4431. if ($iuserinfo === null) {
  4432. $this->iuserinfo = null;
  4433. }
  4434. else {
  4435. $this->iuserinfo = $this->replace_invalid_with_pct_encoding($iuserinfo, '!$&\'()*+,;=:');
  4436. $this->scheme_normalization();
  4437. }
  4438. return true;
  4439. }
  4440. public function set_host($ihost) {
  4441. if ($ihost === null) {
  4442. $this->ihost = null;
  4443. return true;
  4444. }
  4445. elseif (substr($ihost, 0, 1) === '[' && substr($ihost, -1) === ']') {
  4446. if (SimplePie_Net_IPv6::check_ipv6(substr($ihost, 1, -1))) {
  4447. $this->ihost = '[' . SimplePie_Net_IPv6::compress(substr($ihost, 1, -1)) . ']';
  4448. }
  4449. else {
  4450. $this->ihost = null;
  4451. return false;
  4452. }
  4453. }
  4454. else {
  4455. $ihost = $this->replace_invalid_with_pct_encoding($ihost, '!$&\'()*+,;=');
  4456. // Lowercase, but ignore pct-encoded sections (as they should
  4457. // remain uppercase). This must be done after the previous step
  4458. // as that can add unescaped characters.
  4459. $position = 0;
  4460. $strlen = strlen($ihost);
  4461. while (($position += strcspn($ihost, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ%', $position)) < $strlen) {
  4462. if ($ihost[$position] === '%') {
  4463. $position += 3;
  4464. }
  4465. else {
  4466. $ihost[$position] = strtolower($ihost[$position]);
  4467. $position++;
  4468. }
  4469. }
  4470. $this->ihost = $ihost;
  4471. }
  4472. $this->scheme_normalization();
  4473. return true;
  4474. }
  4475. public function set_port($port) {
  4476. if ($port === null) {
  4477. $this->port = null;
  4478. return true;
  4479. }
  4480. elseif (strspn($port, '0123456789') === strlen($port)) {
  4481. $this->port = (int) $port;
  4482. $this->scheme_normalization();
  4483. return true;
  4484. }
  4485. else {
  4486. $this->port = null;
  4487. return false;
  4488. }
  4489. }
  4490. public function set_path($ipath) {
  4491. static $cache;
  4492. if (!$cache) {
  4493. $cache = array();
  4494. }
  4495. $ipath = (string) $ipath;
  4496. if (isset($cache[$ipath])) {
  4497. $this->ipath = $cache[$ipath][(int) ($this->scheme !== null)];
  4498. }
  4499. else {
  4500. $valid = $this->replace_invalid_with_pct_encoding($ipath, '!$&\'()*+,;=@:/');
  4501. $removed = $this->remove_dot_segments($valid);
  4502. $cache[$ipath] = array($valid, $removed);
  4503. $this->ipath = ($this->scheme !== null) ? $removed : $valid;
  4504. }
  4505. $this->scheme_normalization();
  4506. return true;
  4507. }
  4508. public function set_query($iquery) {
  4509. if ($iquery === null) {
  4510. $this->iquery = null;
  4511. }
  4512. else {
  4513. $this->iquery = $this->replace_invalid_with_pct_encoding($iquery, '!$&\'()*+,;=:@/?', true);
  4514. $this->scheme_normalization();
  4515. }
  4516. return true;
  4517. }
  4518. public function set_fragment($ifragment) {
  4519. if ($ifragment === null) {
  4520. $this->ifragment = null;
  4521. }
  4522. else {
  4523. $this->ifragment = $this->replace_invalid_with_pct_encoding($ifragment, '!$&\'()*+,;=:@/?');
  4524. $this->scheme_normalization();
  4525. }
  4526. return true;
  4527. }
  4528. public function to_uri($string) {
  4529. static $non_ascii;
  4530. if (!$non_ascii) {
  4531. $non_ascii = implode('', range("\x80", "\xFF"));
  4532. }
  4533. $position = 0;
  4534. $strlen = strlen($string);
  4535. while (($position += strcspn($string, $non_ascii, $position)) < $strlen) {
  4536. $string = substr_replace($string, sprintf('%%%02X', ord($string[$position])), $position, 1);
  4537. $position += 3;
  4538. $strlen += 2;
  4539. }
  4540. return $string;
  4541. }
  4542. public function get_iri() {
  4543. if (!$this->is_valid()) {
  4544. return false;
  4545. }
  4546. $iri = '';
  4547. if ($this->scheme !== null) {
  4548. $iri .= $this->scheme . ':';
  4549. }
  4550. if (($iauthority = $this->get_iauthority()) !== null) {
  4551. $iri .= '//' . $iauthority;
  4552. }
  4553. if ($this->ipath !== '') {
  4554. $iri .= $this->ipath;
  4555. }
  4556. elseif (!empty($this->normalization[$this->scheme]['ipath']) && $iauthority !== null && $iauthority !== '') {
  4557. $iri .= $this->normalization[$this->scheme]['ipath'];
  4558. }
  4559. if ($this->iquery !== null) {
  4560. $iri .= '?' . $this->iquery;
  4561. }
  4562. if ($this->ifragment !== null) {
  4563. $iri .= '#' . $this->ifragment;
  4564. }
  4565. return $iri;
  4566. }
  4567. public function get_uri() {
  4568. return $this->to_uri($this->get_iri());
  4569. }
  4570. protected function get_iauthority() {
  4571. if ($this->iuserinfo !== null || $this->ihost !== null || $this->port !== null) {
  4572. $iauthority = '';
  4573. if ($this->iuserinfo !== null) {
  4574. $iauthority .= $this->iuserinfo . '@';
  4575. }
  4576. if ($this->ihost !== null) {
  4577. $iauthority .= $this->ihost;
  4578. }
  4579. if ($this->port !== null) {
  4580. $iauthority .= ':' . $this->port;
  4581. }
  4582. return $iauthority;
  4583. }
  4584. else {
  4585. return null;
  4586. }
  4587. }
  4588. protected function get_authority() {
  4589. $iauthority = $this->get_iauthority();
  4590. if (is_string($iauthority))
  4591. return $this->to_uri($iauthority);
  4592. else
  4593. return $iauthority;
  4594. }
  4595. }
  4596. class SimplePie_Item {
  4597. var $feed;
  4598. var $data = array();
  4599. protected $registry;
  4600. public function __construct($feed, $data) {
  4601. $this->feed = $feed;
  4602. $this->data = $data;
  4603. }
  4604. public function set_registry(SimplePie_Registry $registry) {
  4605. $this->registry = $registry;
  4606. }
  4607. public function __toString() {
  4608. return md5(serialize($this->data));
  4609. }
  4610. public function __destruct() {
  4611. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode')) {
  4612. unset($this->feed);
  4613. }
  4614. }
  4615. public function get_item_tags($namespace, $tag) {
  4616. if (isset($this->data['child'][$namespace][$tag])) {
  4617. return $this->data['child'][$namespace][$tag];
  4618. }
  4619. else {
  4620. return null;
  4621. }
  4622. }
  4623. public function get_base($element = array()) {
  4624. return $this->feed->get_base($element);
  4625. }
  4626. public function sanitize($data, $type, $base = '') {
  4627. return $this->feed->sanitize($data, $type, $base);
  4628. }
  4629. public function get_feed() {
  4630. return $this->feed;
  4631. }
  4632. public function get_id($hash = false) {
  4633. if (!$hash) {
  4634. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id')) {
  4635. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4636. }
  4637. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'id')) {
  4638. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4639. }
  4640. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid')) {
  4641. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4642. }
  4643. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'identifier')) {
  4644. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4645. }
  4646. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'identifier')) {
  4647. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4648. }
  4649. elseif (isset($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about'])) {
  4650. return $this->sanitize($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about'], SIMPLEPIE_CONSTRUCT_TEXT);
  4651. }
  4652. elseif (($return = $this->get_permalink()) !== null) {
  4653. return $return;
  4654. }
  4655. elseif (($return = $this->get_title()) !== null) {
  4656. return $return;
  4657. }
  4658. }
  4659. if ($this->get_permalink() !== null || $this->get_title() !== null) {
  4660. return md5($this->get_permalink() . $this->get_title());
  4661. }
  4662. else {
  4663. return md5(serialize($this->data));
  4664. }
  4665. }
  4666. public function get_title() {
  4667. if (!isset($this->data['title'])) {
  4668. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title')) {
  4669. $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]));
  4670. }
  4671. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title')) {
  4672. $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]));
  4673. }
  4674. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) {
  4675. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  4676. }
  4677. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) {
  4678. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  4679. }
  4680. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) {
  4681. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  4682. }
  4683. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) {
  4684. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4685. }
  4686. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) {
  4687. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4688. }
  4689. else {
  4690. $this->data['title'] = null;
  4691. }
  4692. }
  4693. return $this->data['title'];
  4694. }
  4695. public function get_description($description_only = false) {
  4696. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary')) {
  4697. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  4698. }
  4699. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary')) {
  4700. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  4701. }
  4702. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) {
  4703. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  4704. }
  4705. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) {
  4706. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  4707. }
  4708. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) {
  4709. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4710. }
  4711. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) {
  4712. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4713. }
  4714. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) {
  4715. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  4716. }
  4717. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) {
  4718. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4719. }
  4720. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) {
  4721. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
  4722. }
  4723. elseif (!$description_only) {
  4724. return $this->get_content(true);
  4725. }
  4726. else {
  4727. return null;
  4728. }
  4729. }
  4730. public function get_content($content_only = false) {
  4731. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content')) {
  4732. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_content_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  4733. }
  4734. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content')) {
  4735. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  4736. }
  4737. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded')) {
  4738. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  4739. }
  4740. elseif (!$content_only) {
  4741. return $this->get_description(true);
  4742. }
  4743. else {
  4744. return null;
  4745. }
  4746. }
  4747. public function get_category($key = 0) {
  4748. $categories = $this->get_categories();
  4749. if (isset($categories[$key])) {
  4750. return $categories[$key];
  4751. }
  4752. else {
  4753. return null;
  4754. }
  4755. }
  4756. public function get_categories() {
  4757. $categories = array();
  4758. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category) {
  4759. $term = null;
  4760. $scheme = null;
  4761. $label = null;
  4762. if (isset($category['attribs']['']['term'])) {
  4763. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  4764. }
  4765. if (isset($category['attribs']['']['scheme'])) {
  4766. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  4767. }
  4768. if (isset($category['attribs']['']['label'])) {
  4769. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  4770. }
  4771. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  4772. }
  4773. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category) {
  4774. // This is really the label, but keep this as the term also for BC.
  4775. // Label will also work on retrieving because that falls back to term.
  4776. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4777. if (isset($category['attribs']['']['domain'])) {
  4778. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  4779. }
  4780. else {
  4781. $scheme = null;
  4782. }
  4783. $categories[] = $this->registry->create('Category', array($term, $scheme, null));
  4784. }
  4785. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category) {
  4786. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  4787. }
  4788. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category) {
  4789. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  4790. }
  4791. if (!empty($categories)) {
  4792. return array_unique($categories);
  4793. }
  4794. else {
  4795. return null;
  4796. }
  4797. }
  4798. public function get_author($key = 0) {
  4799. $authors = $this->get_authors();
  4800. if (isset($authors[$key])) {
  4801. return $authors[$key];
  4802. }
  4803. else {
  4804. return null;
  4805. }
  4806. }
  4807. public function get_contributor($key = 0) {
  4808. $contributors = $this->get_contributors();
  4809. if (isset($contributors[$key])) {
  4810. return $contributors[$key];
  4811. }
  4812. else {
  4813. return null;
  4814. }
  4815. }
  4816. public function get_contributors() {
  4817. $contributors = array();
  4818. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor) {
  4819. $name = null;
  4820. $uri = null;
  4821. $email = null;
  4822. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) {
  4823. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4824. }
  4825. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) {
  4826. $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]));
  4827. }
  4828. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) {
  4829. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4830. }
  4831. if ($name !== null || $email !== null || $uri !== null) {
  4832. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  4833. }
  4834. }
  4835. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor) {
  4836. $name = null;
  4837. $url = null;
  4838. $email = null;
  4839. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) {
  4840. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4841. }
  4842. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) {
  4843. $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]));
  4844. }
  4845. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) {
  4846. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4847. }
  4848. if ($name !== null || $email !== null || $url !== null) {
  4849. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  4850. }
  4851. }
  4852. if (!empty($contributors)) {
  4853. return array_unique($contributors);
  4854. }
  4855. else {
  4856. return null;
  4857. }
  4858. }
  4859. public function get_authors() {
  4860. $authors = array();
  4861. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author) {
  4862. $name = null;
  4863. $uri = null;
  4864. $email = null;
  4865. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) {
  4866. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4867. }
  4868. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) {
  4869. $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]));
  4870. }
  4871. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) {
  4872. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4873. }
  4874. if ($name !== null || $email !== null || $uri !== null) {
  4875. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  4876. }
  4877. }
  4878. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author')) {
  4879. $name = null;
  4880. $url = null;
  4881. $email = null;
  4882. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) {
  4883. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4884. }
  4885. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) {
  4886. $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]));
  4887. }
  4888. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) {
  4889. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4890. }
  4891. if ($name !== null || $email !== null || $url !== null) {
  4892. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  4893. }
  4894. }
  4895. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'author')) {
  4896. $authors[] = $this->registry->create('Author', array(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)));
  4897. }
  4898. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author) {
  4899. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  4900. }
  4901. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author) {
  4902. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  4903. }
  4904. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author) {
  4905. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  4906. }
  4907. if (!empty($authors)) {
  4908. return array_unique($authors);
  4909. }
  4910. elseif (($source = $this->get_source()) && ($authors = $source->get_authors())) {
  4911. return $authors;
  4912. }
  4913. elseif ($authors = $this->feed->get_authors()) {
  4914. return $authors;
  4915. }
  4916. else {
  4917. return null;
  4918. }
  4919. }
  4920. public function get_copyright() {
  4921. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights')) {
  4922. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  4923. }
  4924. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights')) {
  4925. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4926. }
  4927. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights')) {
  4928. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4929. }
  4930. else {
  4931. return null;
  4932. }
  4933. }
  4934. public function get_date($date_format = 'j F Y, g:i a') {
  4935. if (!isset($this->data['date'])) {
  4936. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published')) {
  4937. $this->data['date']['raw'] = $return[0]['data'];
  4938. }
  4939. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated')) {
  4940. $this->data['date']['raw'] = $return[0]['data'];
  4941. }
  4942. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'issued')) {
  4943. $this->data['date']['raw'] = $return[0]['data'];
  4944. }
  4945. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'created')) {
  4946. $this->data['date']['raw'] = $return[0]['data'];
  4947. }
  4948. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'modified')) {
  4949. $this->data['date']['raw'] = $return[0]['data'];
  4950. }
  4951. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'pubDate')) {
  4952. $this->data['date']['raw'] = $return[0]['data'];
  4953. }
  4954. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date')) {
  4955. $this->data['date']['raw'] = $return[0]['data'];
  4956. }
  4957. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date')) {
  4958. $this->data['date']['raw'] = $return[0]['data'];
  4959. }
  4960. if (!empty($this->data['date']['raw'])) {
  4961. $parser = $this->registry->call('Parse_Date', 'get');
  4962. $this->data['date']['parsed'] = $parser->parse($this->data['date']['raw']);
  4963. }
  4964. else {
  4965. $this->data['date'] = null;
  4966. }
  4967. }
  4968. if ($this->data['date']) {
  4969. $date_format = (string) $date_format;
  4970. switch ($date_format) {
  4971. case '':
  4972. return $this->sanitize($this->data['date']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  4973. case 'U':
  4974. return $this->data['date']['parsed'];
  4975. default:
  4976. return date($date_format, $this->data['date']['parsed']);
  4977. }
  4978. }
  4979. else {
  4980. return null;
  4981. }
  4982. }
  4983. public function get_updated_date($date_format = 'j F Y, g:i a') {
  4984. if (!isset($this->data['updated'])) {
  4985. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated')) {
  4986. $this->data['updated']['raw'] = $return[0]['data'];
  4987. }
  4988. if (!empty($this->data['updated']['raw'])) {
  4989. $parser = $this->registry->call('Parse_Date', 'get');
  4990. $this->data['updated']['parsed'] = $parser->parse($this->data['date']['raw']);
  4991. }
  4992. else {
  4993. $this->data['updated'] = null;
  4994. }
  4995. }
  4996. if ($this->data['updated']) {
  4997. $date_format = (string) $date_format;
  4998. switch ($date_format) {
  4999. case '':
  5000. return $this->sanitize($this->data['updated']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  5001. case 'U':
  5002. return $this->data['updated']['parsed'];
  5003. default:
  5004. return date($date_format, $this->data['updated']['parsed']);
  5005. }
  5006. }
  5007. else {
  5008. return null;
  5009. }
  5010. }
  5011. public function get_local_date($date_format = '%c') {
  5012. if (!$date_format) {
  5013. return $this->sanitize($this->get_date(''), SIMPLEPIE_CONSTRUCT_TEXT);
  5014. }
  5015. elseif (($date = $this->get_date('U')) !== null && $date !== false) {
  5016. return strftime($date_format, $date);
  5017. }
  5018. else {
  5019. return null;
  5020. }
  5021. }
  5022. public function get_gmdate($date_format = 'j F Y, g:i a') {
  5023. $date = $this->get_date('U');
  5024. if ($date === null) {
  5025. return null;
  5026. }
  5027. return gmdate($date_format, $date);
  5028. }
  5029. public function get_updated_gmdate($date_format = 'j F Y, g:i a') {
  5030. $date = $this->get_updated_date('U');
  5031. if ($date === null) {
  5032. return null;
  5033. }
  5034. return gmdate($date_format, $date);
  5035. }
  5036. public function get_permalink() {
  5037. $link = $this->get_link();
  5038. $enclosure = $this->get_enclosure(0);
  5039. if ($link !== null) {
  5040. return $link;
  5041. }
  5042. elseif ($enclosure !== null) {
  5043. return $enclosure->get_link();
  5044. }
  5045. else {
  5046. return null;
  5047. }
  5048. }
  5049. public function get_link($key = 0, $rel = 'alternate') {
  5050. $links = $this->get_links($rel);
  5051. if ($links[$key] !== null) {
  5052. return $links[$key];
  5053. }
  5054. else {
  5055. return null;
  5056. }
  5057. }
  5058. public function get_links($rel = 'alternate') {
  5059. if (!isset($this->data['links'])) {
  5060. $this->data['links'] = array();
  5061. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link) {
  5062. if (isset($link['attribs']['']['href'])) {
  5063. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  5064. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  5065. }
  5066. }
  5067. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link) {
  5068. if (isset($link['attribs']['']['href'])) {
  5069. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  5070. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  5071. }
  5072. }
  5073. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) {
  5074. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  5075. }
  5076. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) {
  5077. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  5078. }
  5079. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) {
  5080. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  5081. }
  5082. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid')) {
  5083. if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) === 'true') {
  5084. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  5085. }
  5086. }
  5087. $keys = array_keys($this->data['links']);
  5088. foreach ($keys as $key) {
  5089. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key))) {
  5090. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key])) {
  5091. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  5092. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  5093. }
  5094. else {
  5095. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  5096. }
  5097. }
  5098. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) {
  5099. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  5100. }
  5101. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  5102. }
  5103. }
  5104. if (isset($this->data['links'][$rel])) {
  5105. return $this->data['links'][$rel];
  5106. }
  5107. else {
  5108. return null;
  5109. }
  5110. }
  5111. public function get_enclosure($key = 0, $prefer = null) {
  5112. $enclosures = $this->get_enclosures();
  5113. if (isset($enclosures[$key])) {
  5114. return $enclosures[$key];
  5115. }
  5116. else {
  5117. return null;
  5118. }
  5119. }
  5120. public function get_enclosures() {
  5121. if (!isset($this->data['enclosures'])) {
  5122. $this->data['enclosures'] = array();
  5123. // Elements
  5124. $captions_parent = null;
  5125. $categories_parent = null;
  5126. $copyrights_parent = null;
  5127. $credits_parent = null;
  5128. $description_parent = null;
  5129. $duration_parent = null;
  5130. $hashes_parent = null;
  5131. $keywords_parent = null;
  5132. $player_parent = null;
  5133. $ratings_parent = null;
  5134. $restrictions_parent = null;
  5135. $thumbnails_parent = null;
  5136. $title_parent = null;
  5137. // Let's do the channel and item-level ones first, and just re-use them if we need to.
  5138. $parent = $this->get_feed();
  5139. // CAPTIONS
  5140. if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text')) {
  5141. foreach ($captions as $caption) {
  5142. $caption_type = null;
  5143. $caption_lang = null;
  5144. $caption_startTime = null;
  5145. $caption_endTime = null;
  5146. $caption_text = null;
  5147. if (isset($caption['attribs']['']['type'])) {
  5148. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  5149. }
  5150. if (isset($caption['attribs']['']['lang'])) {
  5151. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  5152. }
  5153. if (isset($caption['attribs']['']['start'])) {
  5154. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  5155. }
  5156. if (isset($caption['attribs']['']['end'])) {
  5157. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  5158. }
  5159. if (isset($caption['data'])) {
  5160. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5161. }
  5162. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  5163. }
  5164. }
  5165. elseif ($captions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text')) {
  5166. foreach ($captions as $caption) {
  5167. $caption_type = null;
  5168. $caption_lang = null;
  5169. $caption_startTime = null;
  5170. $caption_endTime = null;
  5171. $caption_text = null;
  5172. if (isset($caption['attribs']['']['type'])) {
  5173. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  5174. }
  5175. if (isset($caption['attribs']['']['lang'])) {
  5176. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  5177. }
  5178. if (isset($caption['attribs']['']['start'])) {
  5179. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  5180. }
  5181. if (isset($caption['attribs']['']['end'])) {
  5182. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  5183. }
  5184. if (isset($caption['data'])) {
  5185. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5186. }
  5187. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  5188. }
  5189. }
  5190. if (is_array($captions_parent)) {
  5191. $captions_parent = array_values(array_unique($captions_parent));
  5192. }
  5193. // CATEGORIES
  5194. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category) {
  5195. $term = null;
  5196. $scheme = null;
  5197. $label = null;
  5198. if (isset($category['data'])) {
  5199. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5200. }
  5201. if (isset($category['attribs']['']['scheme'])) {
  5202. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5203. }
  5204. else {
  5205. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  5206. }
  5207. if (isset($category['attribs']['']['label'])) {
  5208. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  5209. }
  5210. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  5211. }
  5212. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category) {
  5213. $term = null;
  5214. $scheme = null;
  5215. $label = null;
  5216. if (isset($category['data'])) {
  5217. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5218. }
  5219. if (isset($category['attribs']['']['scheme'])) {
  5220. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5221. }
  5222. else {
  5223. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  5224. }
  5225. if (isset($category['attribs']['']['label'])) {
  5226. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  5227. }
  5228. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  5229. }
  5230. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'category') as $category) {
  5231. $term = null;
  5232. $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
  5233. $label = null;
  5234. if (isset($category['attribs']['']['text'])) {
  5235. $label = $this->sanitize($category['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  5236. }
  5237. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  5238. if (isset($category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'])) {
  5239. foreach ((array) $category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'] as $subcategory) {
  5240. if (isset($subcategory['attribs']['']['text'])) {
  5241. $label = $this->sanitize($subcategory['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  5242. }
  5243. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  5244. }
  5245. }
  5246. }
  5247. if (is_array($categories_parent)) {
  5248. $categories_parent = array_values(array_unique($categories_parent));
  5249. }
  5250. // COPYRIGHT
  5251. if ($copyright = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright')) {
  5252. $copyright_url = null;
  5253. $copyright_label = null;
  5254. if (isset($copyright[0]['attribs']['']['url'])) {
  5255. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  5256. }
  5257. if (isset($copyright[0]['data'])) {
  5258. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5259. }
  5260. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  5261. }
  5262. elseif ($copyright = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright')) {
  5263. $copyright_url = null;
  5264. $copyright_label = null;
  5265. if (isset($copyright[0]['attribs']['']['url'])) {
  5266. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  5267. }
  5268. if (isset($copyright[0]['data'])) {
  5269. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5270. }
  5271. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  5272. }
  5273. // CREDITS
  5274. if ($credits = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit')) {
  5275. foreach ($credits as $credit) {
  5276. $credit_role = null;
  5277. $credit_scheme = null;
  5278. $credit_name = null;
  5279. if (isset($credit['attribs']['']['role'])) {
  5280. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  5281. }
  5282. if (isset($credit['attribs']['']['scheme'])) {
  5283. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5284. }
  5285. else {
  5286. $credit_scheme = 'urn:ebu';
  5287. }
  5288. if (isset($credit['data'])) {
  5289. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5290. }
  5291. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  5292. }
  5293. }
  5294. elseif ($credits = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit')) {
  5295. foreach ($credits as $credit) {
  5296. $credit_role = null;
  5297. $credit_scheme = null;
  5298. $credit_name = null;
  5299. if (isset($credit['attribs']['']['role'])) {
  5300. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  5301. }
  5302. if (isset($credit['attribs']['']['scheme'])) {
  5303. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5304. }
  5305. else {
  5306. $credit_scheme = 'urn:ebu';
  5307. }
  5308. if (isset($credit['data'])) {
  5309. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5310. }
  5311. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  5312. }
  5313. }
  5314. if (is_array($credits_parent)) {
  5315. $credits_parent = array_values(array_unique($credits_parent));
  5316. }
  5317. // DESCRIPTION
  5318. if ($description_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description')) {
  5319. if (isset($description_parent[0]['data'])) {
  5320. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5321. }
  5322. }
  5323. elseif ($description_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description')) {
  5324. if (isset($description_parent[0]['data'])) {
  5325. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5326. }
  5327. }
  5328. // DURATION
  5329. if ($duration_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'duration')) {
  5330. $seconds = null;
  5331. $minutes = null;
  5332. $hours = null;
  5333. if (isset($duration_parent[0]['data'])) {
  5334. $temp = explode(':', $this->sanitize($duration_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  5335. if (sizeof($temp) > 0) {
  5336. $seconds = (int) array_pop($temp);
  5337. }
  5338. if (sizeof($temp) > 0) {
  5339. $minutes = (int) array_pop($temp);
  5340. $seconds += $minutes * 60;
  5341. }
  5342. if (sizeof($temp) > 0) {
  5343. $hours = (int) array_pop($temp);
  5344. $seconds += $hours * 3600;
  5345. }
  5346. unset($temp);
  5347. $duration_parent = $seconds;
  5348. }
  5349. }
  5350. // HASHES
  5351. if ($hashes_iterator = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash')) {
  5352. foreach ($hashes_iterator as $hash) {
  5353. $value = null;
  5354. $algo = null;
  5355. if (isset($hash['data'])) {
  5356. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5357. }
  5358. if (isset($hash['attribs']['']['algo'])) {
  5359. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  5360. }
  5361. else {
  5362. $algo = 'md5';
  5363. }
  5364. $hashes_parent[] = $algo.':'.$value;
  5365. }
  5366. }
  5367. elseif ($hashes_iterator = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash')) {
  5368. foreach ($hashes_iterator as $hash) {
  5369. $value = null;
  5370. $algo = null;
  5371. if (isset($hash['data'])) {
  5372. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5373. }
  5374. if (isset($hash['attribs']['']['algo'])) {
  5375. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  5376. }
  5377. else {
  5378. $algo = 'md5';
  5379. }
  5380. $hashes_parent[] = $algo.':'.$value;
  5381. }
  5382. }
  5383. if (is_array($hashes_parent)) {
  5384. $hashes_parent = array_values(array_unique($hashes_parent));
  5385. }
  5386. // KEYWORDS
  5387. if ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords')) {
  5388. if (isset($keywords[0]['data'])) {
  5389. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  5390. foreach ($temp as $word) {
  5391. $keywords_parent[] = trim($word);
  5392. }
  5393. }
  5394. unset($temp);
  5395. }
  5396. elseif ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords')) {
  5397. if (isset($keywords[0]['data'])) {
  5398. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  5399. foreach ($temp as $word) {
  5400. $keywords_parent[] = trim($word);
  5401. }
  5402. }
  5403. unset($temp);
  5404. }
  5405. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords')) {
  5406. if (isset($keywords[0]['data'])) {
  5407. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  5408. foreach ($temp as $word) {
  5409. $keywords_parent[] = trim($word);
  5410. }
  5411. }
  5412. unset($temp);
  5413. }
  5414. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords')) {
  5415. if (isset($keywords[0]['data'])) {
  5416. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  5417. foreach ($temp as $word) {
  5418. $keywords_parent[] = trim($word);
  5419. }
  5420. }
  5421. unset($temp);
  5422. }
  5423. if (is_array($keywords_parent)) {
  5424. $keywords_parent = array_values(array_unique($keywords_parent));
  5425. }
  5426. // PLAYER
  5427. if ($player_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player')) {
  5428. if (isset($player_parent[0]['attribs']['']['url'])) {
  5429. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  5430. }
  5431. }
  5432. elseif ($player_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player')) {
  5433. if (isset($player_parent[0]['attribs']['']['url'])) {
  5434. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  5435. }
  5436. }
  5437. // RATINGS
  5438. if ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating')) {
  5439. foreach ($ratings as $rating) {
  5440. $rating_scheme = null;
  5441. $rating_value = null;
  5442. if (isset($rating['attribs']['']['scheme'])) {
  5443. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5444. }
  5445. else {
  5446. $rating_scheme = 'urn:simple';
  5447. }
  5448. if (isset($rating['data'])) {
  5449. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5450. }
  5451. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  5452. }
  5453. }
  5454. elseif ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit')) {
  5455. foreach ($ratings as $rating) {
  5456. $rating_scheme = 'urn:itunes';
  5457. $rating_value = null;
  5458. if (isset($rating['data'])) {
  5459. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5460. }
  5461. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  5462. }
  5463. }
  5464. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating')) {
  5465. foreach ($ratings as $rating) {
  5466. $rating_scheme = null;
  5467. $rating_value = null;
  5468. if (isset($rating['attribs']['']['scheme'])) {
  5469. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5470. }
  5471. else {
  5472. $rating_scheme = 'urn:simple';
  5473. }
  5474. if (isset($rating['data'])) {
  5475. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5476. }
  5477. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  5478. }
  5479. }
  5480. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit')) {
  5481. foreach ($ratings as $rating) {
  5482. $rating_scheme = 'urn:itunes';
  5483. $rating_value = null;
  5484. if (isset($rating['data'])) {
  5485. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5486. }
  5487. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  5488. }
  5489. }
  5490. if (is_array($ratings_parent)) {
  5491. $ratings_parent = array_values(array_unique($ratings_parent));
  5492. }
  5493. // RESTRICTIONS
  5494. if ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction')) {
  5495. foreach ($restrictions as $restriction) {
  5496. $restriction_relationship = null;
  5497. $restriction_type = null;
  5498. $restriction_value = null;
  5499. if (isset($restriction['attribs']['']['relationship'])) {
  5500. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  5501. }
  5502. if (isset($restriction['attribs']['']['type'])) {
  5503. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  5504. }
  5505. if (isset($restriction['data'])) {
  5506. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5507. }
  5508. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  5509. }
  5510. }
  5511. elseif ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block')) {
  5512. foreach ($restrictions as $restriction) {
  5513. $restriction_relationship = 'allow';
  5514. $restriction_type = null;
  5515. $restriction_value = 'itunes';
  5516. if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes') {
  5517. $restriction_relationship = 'deny';
  5518. }
  5519. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  5520. }
  5521. }
  5522. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction')) {
  5523. foreach ($restrictions as $restriction) {
  5524. $restriction_relationship = null;
  5525. $restriction_type = null;
  5526. $restriction_value = null;
  5527. if (isset($restriction['attribs']['']['relationship'])) {
  5528. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  5529. }
  5530. if (isset($restriction['attribs']['']['type'])) {
  5531. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  5532. }
  5533. if (isset($restriction['data'])) {
  5534. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5535. }
  5536. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  5537. }
  5538. }
  5539. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block')) {
  5540. foreach ($restrictions as $restriction) {
  5541. $restriction_relationship = 'allow';
  5542. $restriction_type = null;
  5543. $restriction_value = 'itunes';
  5544. if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes') {
  5545. $restriction_relationship = 'deny';
  5546. }
  5547. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  5548. }
  5549. }
  5550. if (is_array($restrictions_parent)) {
  5551. $restrictions_parent = array_values(array_unique($restrictions_parent));
  5552. }
  5553. else {
  5554. $restrictions_parent = array(new SimplePie_Restriction('allow', null, 'default'));
  5555. }
  5556. // THUMBNAILS
  5557. if ($thumbnails = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail')) {
  5558. foreach ($thumbnails as $thumbnail) {
  5559. if (isset($thumbnail['attribs']['']['url'])) {
  5560. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  5561. }
  5562. }
  5563. }
  5564. elseif ($thumbnails = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail')) {
  5565. foreach ($thumbnails as $thumbnail) {
  5566. if (isset($thumbnail['attribs']['']['url'])) {
  5567. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  5568. }
  5569. }
  5570. }
  5571. // TITLES
  5572. if ($title_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title')) {
  5573. if (isset($title_parent[0]['data'])) {
  5574. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5575. }
  5576. }
  5577. elseif ($title_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title')) {
  5578. if (isset($title_parent[0]['data'])) {
  5579. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5580. }
  5581. }
  5582. // Clear the memory
  5583. unset($parent);
  5584. // Attributes
  5585. $bitrate = null;
  5586. $channels = null;
  5587. $duration = null;
  5588. $expression = null;
  5589. $framerate = null;
  5590. $height = null;
  5591. $javascript = null;
  5592. $lang = null;
  5593. $length = null;
  5594. $medium = null;
  5595. $samplingrate = null;
  5596. $type = null;
  5597. $url = null;
  5598. $width = null;
  5599. // Elements
  5600. $captions = null;
  5601. $categories = null;
  5602. $copyrights = null;
  5603. $credits = null;
  5604. $description = null;
  5605. $hashes = null;
  5606. $keywords = null;
  5607. $player = null;
  5608. $ratings = null;
  5609. $restrictions = null;
  5610. $thumbnails = null;
  5611. $title = null;
  5612. // If we have media:group tags, loop through them.
  5613. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group') as $group) {
  5614. if(isset($group['child']) && isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'])) {
  5615. // If we have media:content tags, loop through them.
  5616. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content) {
  5617. if (isset($content['attribs']['']['url'])) {
  5618. // Attributes
  5619. $bitrate = null;
  5620. $channels = null;
  5621. $duration = null;
  5622. $expression = null;
  5623. $framerate = null;
  5624. $height = null;
  5625. $javascript = null;
  5626. $lang = null;
  5627. $length = null;
  5628. $medium = null;
  5629. $samplingrate = null;
  5630. $type = null;
  5631. $url = null;
  5632. $width = null;
  5633. // Elements
  5634. $captions = null;
  5635. $categories = null;
  5636. $copyrights = null;
  5637. $credits = null;
  5638. $description = null;
  5639. $hashes = null;
  5640. $keywords = null;
  5641. $player = null;
  5642. $ratings = null;
  5643. $restrictions = null;
  5644. $thumbnails = null;
  5645. $title = null;
  5646. // Start checking the attributes of media:content
  5647. if (isset($content['attribs']['']['bitrate'])) {
  5648. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  5649. }
  5650. if (isset($content['attribs']['']['channels'])) {
  5651. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  5652. }
  5653. if (isset($content['attribs']['']['duration'])) {
  5654. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  5655. }
  5656. else {
  5657. $duration = $duration_parent;
  5658. }
  5659. if (isset($content['attribs']['']['expression'])) {
  5660. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  5661. }
  5662. if (isset($content['attribs']['']['framerate'])) {
  5663. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  5664. }
  5665. if (isset($content['attribs']['']['height'])) {
  5666. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  5667. }
  5668. if (isset($content['attribs']['']['lang'])) {
  5669. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  5670. }
  5671. if (isset($content['attribs']['']['fileSize'])) {
  5672. $length = ceil($content['attribs']['']['fileSize']);
  5673. }
  5674. if (isset($content['attribs']['']['medium'])) {
  5675. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  5676. }
  5677. if (isset($content['attribs']['']['samplingrate'])) {
  5678. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  5679. }
  5680. if (isset($content['attribs']['']['type'])) {
  5681. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  5682. }
  5683. if (isset($content['attribs']['']['width'])) {
  5684. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  5685. }
  5686. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  5687. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  5688. // CAPTIONS
  5689. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'])) {
  5690. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption) {
  5691. $caption_type = null;
  5692. $caption_lang = null;
  5693. $caption_startTime = null;
  5694. $caption_endTime = null;
  5695. $caption_text = null;
  5696. if (isset($caption['attribs']['']['type'])) {
  5697. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  5698. }
  5699. if (isset($caption['attribs']['']['lang'])) {
  5700. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  5701. }
  5702. if (isset($caption['attribs']['']['start'])) {
  5703. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  5704. }
  5705. if (isset($caption['attribs']['']['end'])) {
  5706. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  5707. }
  5708. if (isset($caption['data'])) {
  5709. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5710. }
  5711. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  5712. }
  5713. if (is_array($captions)) {
  5714. $captions = array_values(array_unique($captions));
  5715. }
  5716. }
  5717. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'])) {
  5718. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption) {
  5719. $caption_type = null;
  5720. $caption_lang = null;
  5721. $caption_startTime = null;
  5722. $caption_endTime = null;
  5723. $caption_text = null;
  5724. if (isset($caption['attribs']['']['type'])) {
  5725. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  5726. }
  5727. if (isset($caption['attribs']['']['lang'])) {
  5728. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  5729. }
  5730. if (isset($caption['attribs']['']['start'])) {
  5731. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  5732. }
  5733. if (isset($caption['attribs']['']['end'])) {
  5734. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  5735. }
  5736. if (isset($caption['data'])) {
  5737. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5738. }
  5739. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  5740. }
  5741. if (is_array($captions)) {
  5742. $captions = array_values(array_unique($captions));
  5743. }
  5744. }
  5745. else {
  5746. $captions = $captions_parent;
  5747. }
  5748. // CATEGORIES
  5749. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'])) {
  5750. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category) {
  5751. $term = null;
  5752. $scheme = null;
  5753. $label = null;
  5754. if (isset($category['data'])) {
  5755. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5756. }
  5757. if (isset($category['attribs']['']['scheme'])) {
  5758. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5759. }
  5760. else {
  5761. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  5762. }
  5763. if (isset($category['attribs']['']['label'])) {
  5764. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  5765. }
  5766. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  5767. }
  5768. }
  5769. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'])) {
  5770. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category) {
  5771. $term = null;
  5772. $scheme = null;
  5773. $label = null;
  5774. if (isset($category['data'])) {
  5775. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5776. }
  5777. if (isset($category['attribs']['']['scheme'])) {
  5778. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5779. }
  5780. else {
  5781. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  5782. }
  5783. if (isset($category['attribs']['']['label'])) {
  5784. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  5785. }
  5786. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  5787. }
  5788. }
  5789. if (is_array($categories) && is_array($categories_parent)) {
  5790. $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
  5791. }
  5792. elseif (is_array($categories)) {
  5793. $categories = array_values(array_unique($categories));
  5794. }
  5795. elseif (is_array($categories_parent)) {
  5796. $categories = array_values(array_unique($categories_parent));
  5797. }
  5798. // COPYRIGHTS
  5799. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'])) {
  5800. $copyright_url = null;
  5801. $copyright_label = null;
  5802. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'])) {
  5803. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  5804. }
  5805. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'])) {
  5806. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5807. }
  5808. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  5809. }
  5810. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'])) {
  5811. $copyright_url = null;
  5812. $copyright_label = null;
  5813. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'])) {
  5814. $copyright_url = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  5815. }
  5816. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'])) {
  5817. $copyright_label = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5818. }
  5819. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  5820. }
  5821. else {
  5822. $copyrights = $copyrights_parent;
  5823. }
  5824. // CREDITS
  5825. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'])) {
  5826. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit) {
  5827. $credit_role = null;
  5828. $credit_scheme = null;
  5829. $credit_name = null;
  5830. if (isset($credit['attribs']['']['role'])) {
  5831. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  5832. }
  5833. if (isset($credit['attribs']['']['scheme'])) {
  5834. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5835. }
  5836. else {
  5837. $credit_scheme = 'urn:ebu';
  5838. }
  5839. if (isset($credit['data'])) {
  5840. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5841. }
  5842. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  5843. }
  5844. if (is_array($credits)) {
  5845. $credits = array_values(array_unique($credits));
  5846. }
  5847. }
  5848. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'])) {
  5849. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit) {
  5850. $credit_role = null;
  5851. $credit_scheme = null;
  5852. $credit_name = null;
  5853. if (isset($credit['attribs']['']['role'])) {
  5854. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  5855. }
  5856. if (isset($credit['attribs']['']['scheme'])) {
  5857. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5858. }
  5859. else {
  5860. $credit_scheme = 'urn:ebu';
  5861. }
  5862. if (isset($credit['data'])) {
  5863. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5864. }
  5865. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  5866. }
  5867. if (is_array($credits)) {
  5868. $credits = array_values(array_unique($credits));
  5869. }
  5870. }
  5871. else {
  5872. $credits = $credits_parent;
  5873. }
  5874. // DESCRIPTION
  5875. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'])) {
  5876. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5877. }
  5878. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'])) {
  5879. $description = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5880. }
  5881. else {
  5882. $description = $description_parent;
  5883. }
  5884. // HASHES
  5885. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'])) {
  5886. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash) {
  5887. $value = null;
  5888. $algo = null;
  5889. if (isset($hash['data'])) {
  5890. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5891. }
  5892. if (isset($hash['attribs']['']['algo'])) {
  5893. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  5894. }
  5895. else {
  5896. $algo = 'md5';
  5897. }
  5898. $hashes[] = $algo.':'.$value;
  5899. }
  5900. if (is_array($hashes)) {
  5901. $hashes = array_values(array_unique($hashes));
  5902. }
  5903. }
  5904. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'])) {
  5905. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash) {
  5906. $value = null;
  5907. $algo = null;
  5908. if (isset($hash['data'])) {
  5909. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5910. }
  5911. if (isset($hash['attribs']['']['algo'])) {
  5912. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  5913. }
  5914. else {
  5915. $algo = 'md5';
  5916. }
  5917. $hashes[] = $algo.':'.$value;
  5918. }
  5919. if (is_array($hashes)) {
  5920. $hashes = array_values(array_unique($hashes));
  5921. }
  5922. }
  5923. else {
  5924. $hashes = $hashes_parent;
  5925. }
  5926. // KEYWORDS
  5927. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'])) {
  5928. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'])) {
  5929. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  5930. foreach ($temp as $word) {
  5931. $keywords[] = trim($word);
  5932. }
  5933. unset($temp);
  5934. }
  5935. if (is_array($keywords)) {
  5936. $keywords = array_values(array_unique($keywords));
  5937. }
  5938. }
  5939. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'])) {
  5940. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'])) {
  5941. $temp = explode(',', $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  5942. foreach ($temp as $word) {
  5943. $keywords[] = trim($word);
  5944. }
  5945. unset($temp);
  5946. }
  5947. if (is_array($keywords)) {
  5948. $keywords = array_values(array_unique($keywords));
  5949. }
  5950. }
  5951. else {
  5952. $keywords = $keywords_parent;
  5953. }
  5954. // PLAYER
  5955. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'])) {
  5956. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  5957. }
  5958. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'])) {
  5959. $player = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  5960. }
  5961. else {
  5962. $player = $player_parent;
  5963. }
  5964. // RATINGS
  5965. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'])) {
  5966. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating) {
  5967. $rating_scheme = null;
  5968. $rating_value = null;
  5969. if (isset($rating['attribs']['']['scheme'])) {
  5970. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5971. }
  5972. else {
  5973. $rating_scheme = 'urn:simple';
  5974. }
  5975. if (isset($rating['data'])) {
  5976. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5977. }
  5978. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  5979. }
  5980. if (is_array($ratings)) {
  5981. $ratings = array_values(array_unique($ratings));
  5982. }
  5983. }
  5984. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'])) {
  5985. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating) {
  5986. $rating_scheme = null;
  5987. $rating_value = null;
  5988. if (isset($rating['attribs']['']['scheme'])) {
  5989. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5990. }
  5991. else {
  5992. $rating_scheme = 'urn:simple';
  5993. }
  5994. if (isset($rating['data'])) {
  5995. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5996. }
  5997. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  5998. }
  5999. if (is_array($ratings)) {
  6000. $ratings = array_values(array_unique($ratings));
  6001. }
  6002. }
  6003. else {
  6004. $ratings = $ratings_parent;
  6005. }
  6006. // RESTRICTIONS
  6007. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'])) {
  6008. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction) {
  6009. $restriction_relationship = null;
  6010. $restriction_type = null;
  6011. $restriction_value = null;
  6012. if (isset($restriction['attribs']['']['relationship'])) {
  6013. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  6014. }
  6015. if (isset($restriction['attribs']['']['type'])) {
  6016. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6017. }
  6018. if (isset($restriction['data'])) {
  6019. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6020. }
  6021. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  6022. }
  6023. if (is_array($restrictions)) {
  6024. $restrictions = array_values(array_unique($restrictions));
  6025. }
  6026. }
  6027. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'])) {
  6028. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction) {
  6029. $restriction_relationship = null;
  6030. $restriction_type = null;
  6031. $restriction_value = null;
  6032. if (isset($restriction['attribs']['']['relationship'])) {
  6033. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  6034. }
  6035. if (isset($restriction['attribs']['']['type'])) {
  6036. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6037. }
  6038. if (isset($restriction['data'])) {
  6039. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6040. }
  6041. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  6042. }
  6043. if (is_array($restrictions)) {
  6044. $restrictions = array_values(array_unique($restrictions));
  6045. }
  6046. }
  6047. else {
  6048. $restrictions = $restrictions_parent;
  6049. }
  6050. // THUMBNAILS
  6051. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'])) {
  6052. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) {
  6053. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6054. }
  6055. if (is_array($thumbnails)) {
  6056. $thumbnails = array_values(array_unique($thumbnails));
  6057. }
  6058. }
  6059. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'])) {
  6060. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) {
  6061. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6062. }
  6063. if (is_array($thumbnails)) {
  6064. $thumbnails = array_values(array_unique($thumbnails));
  6065. }
  6066. }
  6067. else {
  6068. $thumbnails = $thumbnails_parent;
  6069. }
  6070. // TITLES
  6071. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'])) {
  6072. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6073. }
  6074. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'])) {
  6075. $title = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6076. }
  6077. else {
  6078. $title = $title_parent;
  6079. }
  6080. $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));
  6081. }
  6082. }
  6083. }
  6084. }
  6085. // If we have standalone media:content tags, loop through them.
  6086. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'])) {
  6087. foreach ((array) $this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content) {
  6088. if (isset($content['attribs']['']['url']) || isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'])) {
  6089. // Attributes
  6090. $bitrate = null;
  6091. $channels = null;
  6092. $duration = null;
  6093. $expression = null;
  6094. $framerate = null;
  6095. $height = null;
  6096. $javascript = null;
  6097. $lang = null;
  6098. $length = null;
  6099. $medium = null;
  6100. $samplingrate = null;
  6101. $type = null;
  6102. $url = null;
  6103. $width = null;
  6104. // Elements
  6105. $captions = null;
  6106. $categories = null;
  6107. $copyrights = null;
  6108. $credits = null;
  6109. $description = null;
  6110. $hashes = null;
  6111. $keywords = null;
  6112. $player = null;
  6113. $ratings = null;
  6114. $restrictions = null;
  6115. $thumbnails = null;
  6116. $title = null;
  6117. // Start checking the attributes of media:content
  6118. if (isset($content['attribs']['']['bitrate'])) {
  6119. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  6120. }
  6121. if (isset($content['attribs']['']['channels'])) {
  6122. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  6123. }
  6124. if (isset($content['attribs']['']['duration'])) {
  6125. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  6126. }
  6127. else {
  6128. $duration = $duration_parent;
  6129. }
  6130. if (isset($content['attribs']['']['expression'])) {
  6131. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  6132. }
  6133. if (isset($content['attribs']['']['framerate'])) {
  6134. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  6135. }
  6136. if (isset($content['attribs']['']['height'])) {
  6137. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  6138. }
  6139. if (isset($content['attribs']['']['lang'])) {
  6140. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  6141. }
  6142. if (isset($content['attribs']['']['fileSize'])) {
  6143. $length = ceil($content['attribs']['']['fileSize']);
  6144. }
  6145. if (isset($content['attribs']['']['medium'])) {
  6146. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  6147. }
  6148. if (isset($content['attribs']['']['samplingrate'])) {
  6149. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  6150. }
  6151. if (isset($content['attribs']['']['type'])) {
  6152. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6153. }
  6154. if (isset($content['attribs']['']['width'])) {
  6155. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  6156. }
  6157. if (isset($content['attribs']['']['url'])) {
  6158. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6159. }
  6160. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  6161. // CAPTIONS
  6162. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'])) {
  6163. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption) {
  6164. $caption_type = null;
  6165. $caption_lang = null;
  6166. $caption_startTime = null;
  6167. $caption_endTime = null;
  6168. $caption_text = null;
  6169. if (isset($caption['attribs']['']['type'])) {
  6170. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6171. }
  6172. if (isset($caption['attribs']['']['lang'])) {
  6173. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  6174. }
  6175. if (isset($caption['attribs']['']['start'])) {
  6176. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  6177. }
  6178. if (isset($caption['attribs']['']['end'])) {
  6179. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  6180. }
  6181. if (isset($caption['data'])) {
  6182. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6183. }
  6184. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  6185. }
  6186. if (is_array($captions)) {
  6187. $captions = array_values(array_unique($captions));
  6188. }
  6189. }
  6190. else {
  6191. $captions = $captions_parent;
  6192. }
  6193. // CATEGORIES
  6194. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'])) {
  6195. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category) {
  6196. $term = null;
  6197. $scheme = null;
  6198. $label = null;
  6199. if (isset($category['data'])) {
  6200. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6201. }
  6202. if (isset($category['attribs']['']['scheme'])) {
  6203. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6204. }
  6205. else {
  6206. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  6207. }
  6208. if (isset($category['attribs']['']['label'])) {
  6209. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  6210. }
  6211. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  6212. }
  6213. }
  6214. if (is_array($categories) && is_array($categories_parent)) {
  6215. $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
  6216. }
  6217. elseif (is_array($categories)) {
  6218. $categories = array_values(array_unique($categories));
  6219. }
  6220. elseif (is_array($categories_parent)) {
  6221. $categories = array_values(array_unique($categories_parent));
  6222. }
  6223. else {
  6224. $categories = null;
  6225. }
  6226. // COPYRIGHTS
  6227. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'])) {
  6228. $copyright_url = null;
  6229. $copyright_label = null;
  6230. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'])) {
  6231. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  6232. }
  6233. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'])) {
  6234. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6235. }
  6236. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  6237. }
  6238. else {
  6239. $copyrights = $copyrights_parent;
  6240. }
  6241. // CREDITS
  6242. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'])) {
  6243. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit) {
  6244. $credit_role = null;
  6245. $credit_scheme = null;
  6246. $credit_name = null;
  6247. if (isset($credit['attribs']['']['role'])) {
  6248. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  6249. }
  6250. if (isset($credit['attribs']['']['scheme'])) {
  6251. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6252. }
  6253. else {
  6254. $credit_scheme = 'urn:ebu';
  6255. }
  6256. if (isset($credit['data'])) {
  6257. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6258. }
  6259. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  6260. }
  6261. if (is_array($credits)) {
  6262. $credits = array_values(array_unique($credits));
  6263. }
  6264. }
  6265. else {
  6266. $credits = $credits_parent;
  6267. }
  6268. // DESCRIPTION
  6269. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'])) {
  6270. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6271. }
  6272. else {
  6273. $description = $description_parent;
  6274. }
  6275. // HASHES
  6276. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'])) {
  6277. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash) {
  6278. $value = null;
  6279. $algo = null;
  6280. if (isset($hash['data'])) {
  6281. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6282. }
  6283. if (isset($hash['attribs']['']['algo'])) {
  6284. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  6285. }
  6286. else {
  6287. $algo = 'md5';
  6288. }
  6289. $hashes[] = $algo.':'.$value;
  6290. }
  6291. if (is_array($hashes)) {
  6292. $hashes = array_values(array_unique($hashes));
  6293. }
  6294. }
  6295. else {
  6296. $hashes = $hashes_parent;
  6297. }
  6298. // KEYWORDS
  6299. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'])) {
  6300. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'])) {
  6301. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  6302. foreach ($temp as $word) {
  6303. $keywords[] = trim($word);
  6304. }
  6305. unset($temp);
  6306. }
  6307. if (is_array($keywords)) {
  6308. $keywords = array_values(array_unique($keywords));
  6309. }
  6310. }
  6311. else {
  6312. $keywords = $keywords_parent;
  6313. }
  6314. // PLAYER
  6315. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'])) {
  6316. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6317. }
  6318. else {
  6319. $player = $player_parent;
  6320. }
  6321. // RATINGS
  6322. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'])) {
  6323. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating) {
  6324. $rating_scheme = null;
  6325. $rating_value = null;
  6326. if (isset($rating['attribs']['']['scheme'])) {
  6327. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6328. }
  6329. else {
  6330. $rating_scheme = 'urn:simple';
  6331. }
  6332. if (isset($rating['data'])) {
  6333. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6334. }
  6335. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  6336. }
  6337. if (is_array($ratings)) {
  6338. $ratings = array_values(array_unique($ratings));
  6339. }
  6340. }
  6341. else {
  6342. $ratings = $ratings_parent;
  6343. }
  6344. // RESTRICTIONS
  6345. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'])) {
  6346. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction) {
  6347. $restriction_relationship = null;
  6348. $restriction_type = null;
  6349. $restriction_value = null;
  6350. if (isset($restriction['attribs']['']['relationship'])) {
  6351. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  6352. }
  6353. if (isset($restriction['attribs']['']['type'])) {
  6354. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6355. }
  6356. if (isset($restriction['data'])) {
  6357. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6358. }
  6359. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  6360. }
  6361. if (is_array($restrictions)) {
  6362. $restrictions = array_values(array_unique($restrictions));
  6363. }
  6364. }
  6365. else {
  6366. $restrictions = $restrictions_parent;
  6367. }
  6368. // THUMBNAILS
  6369. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'])) {
  6370. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) {
  6371. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6372. }
  6373. if (is_array($thumbnails)) {
  6374. $thumbnails = array_values(array_unique($thumbnails));
  6375. }
  6376. }
  6377. else {
  6378. $thumbnails = $thumbnails_parent;
  6379. }
  6380. // TITLES
  6381. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'])) {
  6382. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6383. }
  6384. else {
  6385. $title = $title_parent;
  6386. }
  6387. $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));
  6388. }
  6389. }
  6390. }
  6391. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link) {
  6392. if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure') {
  6393. // Attributes
  6394. $bitrate = null;
  6395. $channels = null;
  6396. $duration = null;
  6397. $expression = null;
  6398. $framerate = null;
  6399. $height = null;
  6400. $javascript = null;
  6401. $lang = null;
  6402. $length = null;
  6403. $medium = null;
  6404. $samplingrate = null;
  6405. $type = null;
  6406. $url = null;
  6407. $width = null;
  6408. $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  6409. if (isset($link['attribs']['']['type'])) {
  6410. $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6411. }
  6412. if (isset($link['attribs']['']['length'])) {
  6413. $length = ceil($link['attribs']['']['length']);
  6414. }
  6415. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  6416. $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));
  6417. }
  6418. }
  6419. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link) {
  6420. if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure') {
  6421. // Attributes
  6422. $bitrate = null;
  6423. $channels = null;
  6424. $duration = null;
  6425. $expression = null;
  6426. $framerate = null;
  6427. $height = null;
  6428. $javascript = null;
  6429. $lang = null;
  6430. $length = null;
  6431. $medium = null;
  6432. $samplingrate = null;
  6433. $type = null;
  6434. $url = null;
  6435. $width = null;
  6436. $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  6437. if (isset($link['attribs']['']['type'])) {
  6438. $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6439. }
  6440. if (isset($link['attribs']['']['length'])) {
  6441. $length = ceil($link['attribs']['']['length']);
  6442. }
  6443. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  6444. $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));
  6445. }
  6446. }
  6447. if ($enclosure = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'enclosure')) {
  6448. if (isset($enclosure[0]['attribs']['']['url'])) {
  6449. // Attributes
  6450. $bitrate = null;
  6451. $channels = null;
  6452. $duration = null;
  6453. $expression = null;
  6454. $framerate = null;
  6455. $height = null;
  6456. $javascript = null;
  6457. $lang = null;
  6458. $length = null;
  6459. $medium = null;
  6460. $samplingrate = null;
  6461. $type = null;
  6462. $url = null;
  6463. $width = null;
  6464. $url = $this->sanitize($enclosure[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($enclosure[0]));
  6465. if (isset($enclosure[0]['attribs']['']['type'])) {
  6466. $type = $this->sanitize($enclosure[0]['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6467. }
  6468. if (isset($enclosure[0]['attribs']['']['length'])) {
  6469. $length = ceil($enclosure[0]['attribs']['']['length']);
  6470. }
  6471. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  6472. $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));
  6473. }
  6474. }
  6475. 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)) {
  6476. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  6477. $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));
  6478. }
  6479. $this->data['enclosures'] = array_values(array_unique($this->data['enclosures']));
  6480. }
  6481. if (!empty($this->data['enclosures'])) {
  6482. return $this->data['enclosures'];
  6483. }
  6484. else {
  6485. return null;
  6486. }
  6487. }
  6488. public function get_latitude() {
  6489. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat')) {
  6490. return (float) $return[0]['data'];
  6491. }
  6492. 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)) {
  6493. return (float) $match[1];
  6494. }
  6495. else {
  6496. return null;
  6497. }
  6498. }
  6499. public function get_longitude() {
  6500. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long')) {
  6501. return (float) $return[0]['data'];
  6502. }
  6503. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon')) {
  6504. return (float) $return[0]['data'];
  6505. }
  6506. 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)) {
  6507. return (float) $match[2];
  6508. }
  6509. else {
  6510. return null;
  6511. }
  6512. }
  6513. public function get_source() {
  6514. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'source')) {
  6515. return $this->registry->create('Source', array($this, $return[0]));
  6516. }
  6517. else {
  6518. return null;
  6519. }
  6520. }
  6521. }
  6522. class SimplePie_Locator {
  6523. var $useragent;
  6524. var $timeout;
  6525. var $file;
  6526. var $local = array();
  6527. var $elsewhere = array();
  6528. var $cached_entities = array();
  6529. var $http_base;
  6530. var $base;
  6531. var $base_location = 0;
  6532. var $checked_feeds = 0;
  6533. var $max_checked_feeds = 10;
  6534. protected $registry;
  6535. public function __construct(SimplePie_File $file, $timeout = 10, $useragent = null, $max_checked_feeds = 10) {
  6536. $this->file = $file;
  6537. $this->useragent = $useragent;
  6538. $this->timeout = $timeout;
  6539. $this->max_checked_feeds = $max_checked_feeds;
  6540. $this->dom = new DOMDocument();
  6541. set_error_handler(array('SimplePie_Misc', 'silence_errors'));
  6542. $this->dom->loadHTML($this->file->body);
  6543. restore_error_handler();
  6544. }
  6545. public function set_registry(SimplePie_Registry $registry) {
  6546. $this->registry = $registry;
  6547. }
  6548. public function find($type = SIMPLEPIE_LOCATOR_ALL, &$working) {
  6549. if ($this->is_feed($this->file)) {
  6550. return $this->file;
  6551. }
  6552. if ($this->file->method & SIMPLEPIE_FILE_SOURCE_REMOTE) {
  6553. $sniffer = $this->registry->create('Content_Type_Sniffer', array($this->file));
  6554. if ($sniffer->get_type() !== 'text/html') {
  6555. return null;
  6556. }
  6557. }
  6558. if ($type & ~SIMPLEPIE_LOCATOR_NONE) {
  6559. $this->get_base();
  6560. }
  6561. if ($type & SIMPLEPIE_LOCATOR_AUTODISCOVERY && $working = $this->autodiscovery()) {
  6562. return $working[0];
  6563. }
  6564. if ($type & (SIMPLEPIE_LOCATOR_LOCAL_EXTENSION | SIMPLEPIE_LOCATOR_LOCAL_BODY | SIMPLEPIE_LOCATOR_REMOTE_EXTENSION | SIMPLEPIE_LOCATOR_REMOTE_BODY) && $this->get_links()) {
  6565. if ($type & SIMPLEPIE_LOCATOR_LOCAL_EXTENSION && $working = $this->extension($this->local)) {
  6566. return $working;
  6567. }
  6568. if ($type & SIMPLEPIE_LOCATOR_LOCAL_BODY && $working = $this->body($this->local)) {
  6569. return $working;
  6570. }
  6571. if ($type & SIMPLEPIE_LOCATOR_REMOTE_EXTENSION && $working = $this->extension($this->elsewhere)) {
  6572. return $working;
  6573. }
  6574. if ($type & SIMPLEPIE_LOCATOR_REMOTE_BODY && $working = $this->body($this->elsewhere)) {
  6575. return $working;
  6576. }
  6577. }
  6578. return null;
  6579. }
  6580. public function is_feed($file) {
  6581. if ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE) {
  6582. $sniffer = $this->registry->create('Content_Type_Sniffer', array($file));
  6583. $sniffed = $sniffer->get_type();
  6584. if (in_array($sniffed, array('application/rss+xml', 'application/rdf+xml', 'text/rdf', 'application/atom+xml', 'text/xml', 'application/xml'))) {
  6585. return true;
  6586. }
  6587. else {
  6588. return false;
  6589. }
  6590. }
  6591. elseif ($file->method & SIMPLEPIE_FILE_SOURCE_LOCAL) {
  6592. return true;
  6593. }
  6594. else {
  6595. return false;
  6596. }
  6597. }
  6598. public function get_base() {
  6599. $this->http_base = $this->file->url;
  6600. $this->base = $this->http_base;
  6601. $elements = $this->dom->getElementsByTagName('base');
  6602. foreach ($elements as $element) {
  6603. if ($element->hasAttribute('href')) {
  6604. $this->base = $this->registry->call('Misc', 'absolutize_url', array(trim($element->getAttribute('href')), $this->http_base));
  6605. $this->base_location = method_exists($element, 'getLineNo') ? $element->getLineNo() : 0;
  6606. break;
  6607. }
  6608. }
  6609. }
  6610. public function autodiscovery() {
  6611. $done = array();
  6612. $feeds = array();
  6613. $feeds = array_merge($feeds, $this->search_elements_by_tag('link', $done, $feeds));
  6614. $feeds = array_merge($feeds, $this->search_elements_by_tag('a', $done, $feeds));
  6615. $feeds = array_merge($feeds, $this->search_elements_by_tag('area', $done, $feeds));
  6616. if (!empty($feeds)) {
  6617. return array_values($feeds);
  6618. }
  6619. else {
  6620. return null;
  6621. }
  6622. }
  6623. protected function search_elements_by_tag($name, &$done, $feeds) {
  6624. $links = $this->dom->getElementsByTagName($name);
  6625. foreach ($links as $link) {
  6626. if ($this->checked_feeds === $this->max_checked_feeds) {
  6627. break;
  6628. }
  6629. if ($link->hasAttribute('href') && $link->hasAttribute('rel')) {
  6630. $rel = array_unique($this->registry->call('Misc', 'space_seperated_tokens', array(strtolower($link->getAttribute('rel')))));
  6631. $line = method_exists($link, 'getLineNo') ? $link->getLineNo() : 1;
  6632. if ($this->base_location < $line) {
  6633. $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->base));
  6634. }
  6635. else {
  6636. $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->http_base));
  6637. }
  6638. 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])) {
  6639. $this->checked_feeds++;
  6640. $headers = array(
  6641. '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',
  6642. );
  6643. $feed = $this->registry->create('File', array($href, $this->timeout, 5, $headers, $this->useragent));
  6644. 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)) {
  6645. $feeds[$href] = $feed;
  6646. }
  6647. }
  6648. $done[] = $href;
  6649. }
  6650. }
  6651. return $feeds;
  6652. }
  6653. public function get_links() {
  6654. $links = $this->dom->getElementsByTagName('a');
  6655. foreach ($links as $link) {
  6656. if ($link->hasAttribute('href')) {
  6657. $href = trim($link->getAttribute('href'));
  6658. $parsed = $this->registry->call('Misc', 'parse_url', array($href));
  6659. if ($parsed['scheme'] === '' || preg_match('/^(http(s)|feed)?$/i', $parsed['scheme'])) {
  6660. if ($this->base_location < $link->getLineNo()) {
  6661. $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->base));
  6662. }
  6663. else {
  6664. $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->http_base));
  6665. }
  6666. $current = $this->registry->call('Misc', 'parse_url', array($this->file->url));
  6667. if ($parsed['authority'] === '' || $parsed['authority'] === $current['authority']) {
  6668. $this->local[] = $href;
  6669. }
  6670. else {
  6671. $this->elsewhere[] = $href;
  6672. }
  6673. }
  6674. }
  6675. }
  6676. $this->local = array_unique($this->local);
  6677. $this->elsewhere = array_unique($this->elsewhere);
  6678. if (!empty($this->local) || !empty($this->elsewhere)) {
  6679. return true;
  6680. }
  6681. return null;
  6682. }
  6683. public function extension(&$array) {
  6684. foreach ($array as $key => $value) {
  6685. if ($this->checked_feeds === $this->max_checked_feeds) {
  6686. break;
  6687. }
  6688. if (in_array(strtolower(strrchr($value, '.')), array('.rss', '.rdf', '.atom', '.xml'))) {
  6689. $this->checked_feeds++;
  6690. $headers = array(
  6691. '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',
  6692. );
  6693. $feed = $this->registry->create('File', array($value, $this->timeout, 5, $headers, $this->useragent));
  6694. 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)) {
  6695. return $feed;
  6696. }
  6697. else {
  6698. unset($array[$key]);
  6699. }
  6700. }
  6701. }
  6702. return null;
  6703. }
  6704. public function body(&$array) {
  6705. foreach ($array as $key => $value) {
  6706. if ($this->checked_feeds === $this->max_checked_feeds) {
  6707. break;
  6708. }
  6709. if (preg_match('/(rss|rdf|atom|xml)/i', $value)) {
  6710. $this->checked_feeds++;
  6711. $headers = array(
  6712. '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',
  6713. );
  6714. $feed = $this->registry->create('File', array($value, $this->timeout, 5, null, $this->useragent));
  6715. 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)) {
  6716. return $feed;
  6717. }
  6718. else {
  6719. unset($array[$key]);
  6720. }
  6721. }
  6722. }
  6723. return null;
  6724. }
  6725. }
  6726. class SimplePie_Misc {
  6727. public static function time_hms($seconds) {
  6728. $time = '';
  6729. $hours = floor($seconds / 3600);
  6730. $remainder = $seconds % 3600;
  6731. if ($hours > 0) {
  6732. $time .= $hours.':';
  6733. }
  6734. $minutes = floor($remainder / 60);
  6735. $seconds = $remainder % 60;
  6736. if ($minutes < 10 && $hours > 0) {
  6737. $minutes = '0' . $minutes;
  6738. }
  6739. if ($seconds < 10) {
  6740. $seconds = '0' . $seconds;
  6741. }
  6742. $time .= $minutes.':';
  6743. $time .= $seconds;
  6744. return $time;
  6745. }
  6746. public static function absolutize_url($relative, $base) {
  6747. $iri = SimplePie_IRI::absolutize(new SimplePie_IRI($base), $relative);
  6748. return $iri->get_uri();
  6749. }
  6750. public static function get_element($realname, $string) {
  6751. $return = array();
  6752. $name = preg_quote($realname, '/');
  6753. if (preg_match_all("/<($name)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$name>|(\/)?>)/siU", $string, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
  6754. for ($i = 0, $total_matches = count($matches); $i < $total_matches; $i++) {
  6755. $return[$i]['tag'] = $realname;
  6756. $return[$i]['full'] = $matches[$i][0][0];
  6757. $return[$i]['offset'] = $matches[$i][0][1];
  6758. if (strlen($matches[$i][3][0]) <= 2) {
  6759. $return[$i]['self_closing'] = true;
  6760. }
  6761. else {
  6762. $return[$i]['self_closing'] = false;
  6763. $return[$i]['content'] = $matches[$i][4][0];
  6764. }
  6765. $return[$i]['attribs'] = array();
  6766. 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)) {
  6767. for ($j = 0, $total_attribs = count($attribs); $j < $total_attribs; $j++) {
  6768. if (count($attribs[$j]) === 2) {
  6769. $attribs[$j][2] = $attribs[$j][1];
  6770. }
  6771. $return[$i]['attribs'][strtolower($attribs[$j][1])]['data'] = SimplePie_Misc::entities_decode(end($attribs[$j]), 'UTF-8');
  6772. }
  6773. }
  6774. }
  6775. }
  6776. return $return;
  6777. }
  6778. public static function element_implode($element) {
  6779. $full = "<$element[tag]";
  6780. foreach ($element['attribs'] as $key => $value) {
  6781. $key = strtolower($key);
  6782. $full .= " $key=\"" . htmlspecialchars($value['data']) . '"';
  6783. }
  6784. if ($element['self_closing']) {
  6785. $full .= ' />';
  6786. }
  6787. else {
  6788. $full .= ">$element[content]</$element[tag]>";
  6789. }
  6790. return $full;
  6791. }
  6792. public static function error($message, $level, $file, $line) {
  6793. if ((ini_get('error_reporting') & $level) > 0) {
  6794. switch ($level) {
  6795. case E_USER_ERROR:
  6796. $note = 'PHP Error';
  6797. break;
  6798. case E_USER_WARNING:
  6799. $note = 'PHP Warning';
  6800. break;
  6801. case E_USER_NOTICE:
  6802. $note = 'PHP Notice';
  6803. break;
  6804. default:
  6805. $note = 'Unknown Error';
  6806. break;
  6807. }
  6808. $log_error = true;
  6809. if (!function_exists('error_log')) {
  6810. $log_error = false;
  6811. }
  6812. $log_file = @ini_get('error_log');
  6813. if (!empty($log_file) && ('syslog' !== $log_file) && !@is_writable($log_file)) {
  6814. $log_error = false;
  6815. }
  6816. if ($log_error) {
  6817. @error_log("$note: $message in $file on line $line", 0);
  6818. }
  6819. }
  6820. return $message;
  6821. }
  6822. public static function fix_protocol($url, $http = 1) {
  6823. $url = SimplePie_Misc::normalize_url($url);
  6824. $parsed = SimplePie_Misc::parse_url($url);
  6825. if ($parsed['scheme'] !== '' && $parsed['scheme'] !== 'http' && $parsed['scheme'] !== 'https') {
  6826. return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['authority'], $parsed['path'], $parsed['query'], $parsed['fragment']), $http);
  6827. }
  6828. if ($parsed['scheme'] === '' && $parsed['authority'] === '' && !file_exists($url)) {
  6829. return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['path'], '', $parsed['query'], $parsed['fragment']), $http);
  6830. }
  6831. if ($http === 2 && $parsed['scheme'] !== '') {
  6832. return "feed:$url";
  6833. }
  6834. elseif ($http === 3 && strtolower($parsed['scheme']) === 'http') {
  6835. return substr_replace($url, 'podcast', 0, 4);
  6836. }
  6837. elseif ($http === 4 && strtolower($parsed['scheme']) === 'http') {
  6838. return substr_replace($url, 'itpc', 0, 4);
  6839. }
  6840. else {
  6841. return $url;
  6842. }
  6843. }
  6844. public static function parse_url($url) {
  6845. $iri = new SimplePie_IRI($url);
  6846. return array(
  6847. 'scheme' => (string) $iri->scheme,
  6848. 'authority' => (string) $iri->authority,
  6849. 'path' => (string) $iri->path,
  6850. 'query' => (string) $iri->query,
  6851. 'fragment' => (string) $iri->fragment
  6852. );
  6853. }
  6854. public static function compress_parse_url($scheme = '', $authority = '', $path = '', $query = '', $fragment = '') {
  6855. $iri = new SimplePie_IRI('');
  6856. $iri->scheme = $scheme;
  6857. $iri->authority = $authority;
  6858. $iri->path = $path;
  6859. $iri->query = $query;
  6860. $iri->fragment = $fragment;
  6861. return $iri->get_uri();
  6862. }
  6863. public static function normalize_url($url) {
  6864. $iri = new SimplePie_IRI($url);
  6865. return $iri->get_uri();
  6866. }
  6867. public static function percent_encoding_normalization($match) {
  6868. $integer = hexdec($match[1]);
  6869. if ($integer >= 0x41 && $integer <= 0x5A || $integer >= 0x61 && $integer <= 0x7A || $integer >= 0x30 && $integer <= 0x39 || $integer === 0x2D || $integer === 0x2E || $integer === 0x5F || $integer === 0x7E) {
  6870. return chr($integer);
  6871. }
  6872. else {
  6873. return strtoupper($match[0]);
  6874. }
  6875. }
  6876. public static function windows_1252_to_utf8($string) {
  6877. 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");
  6878. return strtr($string, $convert_table);
  6879. }
  6880. public static function change_encoding($data, $input, $output) {
  6881. $input = SimplePie_Misc::encoding($input);
  6882. $output = SimplePie_Misc::encoding($output);
  6883. // We fail to fail on non US-ASCII bytes
  6884. if ($input === 'US-ASCII') {
  6885. static $non_ascii_octects = '';
  6886. if (!$non_ascii_octects) {
  6887. for ($i = 0x80; $i <= 0xFF; $i++) {
  6888. $non_ascii_octects .= chr($i);
  6889. }
  6890. }
  6891. $data = substr($data, 0, strcspn($data, $non_ascii_octects));
  6892. }
  6893. // This is first, as behaviour of this is completely predictable
  6894. if ($input === 'windows-1252' && $output === 'UTF-8') {
  6895. return SimplePie_Misc::windows_1252_to_utf8($data);
  6896. }
  6897. // This is second, as behaviour of this varies only with PHP version (the middle part of this expression checks the encoding is supported).
  6898. elseif (function_exists('mb_convert_encoding') && ($return = SimplePie_Misc::change_encoding_mbstring($data, $input, $output))) {
  6899. return $return;
  6900. }
  6901. // This is last, as behaviour of this varies with OS userland and PHP version
  6902. elseif (function_exists('iconv') && ($return = SimplePie_Misc::change_encoding_iconv($data, $input, $output))) {
  6903. return $return;
  6904. }
  6905. // If we can't do anything, just fail
  6906. else {
  6907. return false;
  6908. }
  6909. }
  6910. protected static function change_encoding_mbstring($data, $input, $output) {
  6911. if ($input === 'windows-949') {
  6912. $input = 'EUC-KR';
  6913. }
  6914. if ($output === 'windows-949') {
  6915. $output = 'EUC-KR';
  6916. }
  6917. if ($input === 'Windows-31J') {
  6918. $input = 'SJIS';
  6919. }
  6920. if ($output === 'Windows-31J') {
  6921. $output = 'SJIS';
  6922. }
  6923. // Check that the encoding is supported
  6924. if (@mb_convert_encoding("\x80", 'UTF-16BE', $input) === "\x00\x80") {
  6925. return false;
  6926. }
  6927. if (!in_array($input, mb_list_encodings())) {
  6928. return false;
  6929. }
  6930. // Let's do some conversion
  6931. if ($return = @mb_convert_encoding($data, $output, $input)) {
  6932. return $return;
  6933. }
  6934. return false;
  6935. }
  6936. protected static function change_encoding_iconv($data, $input, $output) {
  6937. return @iconv($input, $output, $data);
  6938. }
  6939. public static function encoding($charset) {
  6940. // Normalization from UTS #22
  6941. switch (strtolower(preg_replace('/(?:[^a-zA-Z0-9]+|([^0-9])0+)/', '\1', $charset))) {
  6942. case 'adobestandardencoding':
  6943. case 'csadobestandardencoding':
  6944. return 'Adobe-Standard-Encoding';
  6945. case 'adobesymbolencoding':
  6946. case 'cshppsmath':
  6947. return 'Adobe-Symbol-Encoding';
  6948. case 'ami1251':
  6949. case 'amiga1251':
  6950. return 'Amiga-1251';
  6951. case 'ansix31101983':
  6952. case 'csat5001983':
  6953. case 'csiso99naplps':
  6954. case 'isoir99':
  6955. case 'naplps':
  6956. return 'ANSI_X3.110-1983';
  6957. case 'arabic7':
  6958. case 'asmo449':
  6959. case 'csiso89asmo449':
  6960. case 'iso9036':
  6961. case 'isoir89':
  6962. return 'ASMO_449';
  6963. case 'big5':
  6964. case 'csbig5':
  6965. return 'Big5';
  6966. case 'big5hkscs':
  6967. return 'Big5-HKSCS';
  6968. case 'bocu1':
  6969. case 'csbocu1':
  6970. return 'BOCU-1';
  6971. case 'brf':
  6972. case 'csbrf':
  6973. return 'BRF';
  6974. case 'bs4730':
  6975. case 'csiso4unitedkingdom':
  6976. case 'gb':
  6977. case 'iso646gb':
  6978. case 'isoir4':
  6979. case 'uk':
  6980. return 'BS_4730';
  6981. case 'bsviewdata':
  6982. case 'csiso47bsviewdata':
  6983. case 'isoir47':
  6984. return 'BS_viewdata';
  6985. case 'cesu8':
  6986. case 'cscesu8':
  6987. return 'CESU-8';
  6988. case 'ca':
  6989. case 'csa71':
  6990. case 'csaz243419851':
  6991. case 'csiso121canadian1':
  6992. case 'iso646ca':
  6993. case 'isoir121':
  6994. return 'CSA_Z243.4-1985-1';
  6995. case 'csa72':
  6996. case 'csaz243419852':
  6997. case 'csiso122canadian2':
  6998. case 'iso646ca2':
  6999. case 'isoir122':
  7000. return 'CSA_Z243.4-1985-2';
  7001. case 'csaz24341985gr':
  7002. case 'csiso123csaz24341985gr':
  7003. case 'isoir123':
  7004. return 'CSA_Z243.4-1985-gr';
  7005. case 'csiso139csn369103':
  7006. case 'csn369103':
  7007. case 'isoir139':
  7008. return 'CSN_369103';
  7009. case 'csdecmcs':
  7010. case 'dec':
  7011. case 'decmcs':
  7012. return 'DEC-MCS';
  7013. case 'csiso21german':
  7014. case 'de':
  7015. case 'din66003':
  7016. case 'iso646de':
  7017. case 'isoir21':
  7018. return 'DIN_66003';
  7019. case 'csdkus':
  7020. case 'dkus':
  7021. return 'dk-us';
  7022. case 'csiso646danish':
  7023. case 'dk':
  7024. case 'ds2089':
  7025. case 'iso646dk':
  7026. return 'DS_2089';
  7027. case 'csibmebcdicatde':
  7028. case 'ebcdicatde':
  7029. return 'EBCDIC-AT-DE';
  7030. case 'csebcdicatdea':
  7031. case 'ebcdicatdea':
  7032. return 'EBCDIC-AT-DE-A';
  7033. case 'csebcdiccafr':
  7034. case 'ebcdiccafr':
  7035. return 'EBCDIC-CA-FR';
  7036. case 'csebcdicdkno':
  7037. case 'ebcdicdkno':
  7038. return 'EBCDIC-DK-NO';
  7039. case 'csebcdicdknoa':
  7040. case 'ebcdicdknoa':
  7041. return 'EBCDIC-DK-NO-A';
  7042. case 'csebcdices':
  7043. case 'ebcdices':
  7044. return 'EBCDIC-ES';
  7045. case 'csebcdicesa':
  7046. case 'ebcdicesa':
  7047. return 'EBCDIC-ES-A';
  7048. case 'csebcdicess':
  7049. case 'ebcdicess':
  7050. return 'EBCDIC-ES-S';
  7051. case 'csebcdicfise':
  7052. case 'ebcdicfise':
  7053. return 'EBCDIC-FI-SE';
  7054. case 'csebcdicfisea':
  7055. case 'ebcdicfisea':
  7056. return 'EBCDIC-FI-SE-A';
  7057. case 'csebcdicfr':
  7058. case 'ebcdicfr':
  7059. return 'EBCDIC-FR';
  7060. case 'csebcdicit':
  7061. case 'ebcdicit':
  7062. return 'EBCDIC-IT';
  7063. case 'csebcdicpt':
  7064. case 'ebcdicpt':
  7065. return 'EBCDIC-PT';
  7066. case 'csebcdicuk':
  7067. case 'ebcdicuk':
  7068. return 'EBCDIC-UK';
  7069. case 'csebcdicus':
  7070. case 'ebcdicus':
  7071. return 'EBCDIC-US';
  7072. case 'csiso111ecmacyrillic':
  7073. case 'ecmacyrillic':
  7074. case 'isoir111':
  7075. case 'koi8e':
  7076. return 'ECMA-cyrillic';
  7077. case 'csiso17spanish':
  7078. case 'es':
  7079. case 'iso646es':
  7080. case 'isoir17':
  7081. return 'ES';
  7082. case 'csiso85spanish2':
  7083. case 'es2':
  7084. case 'iso646es2':
  7085. case 'isoir85':
  7086. return 'ES2';
  7087. case 'cseucpkdfmtjapanese':
  7088. case 'eucjp':
  7089. case 'extendedunixcodepackedformatforjapanese':
  7090. return 'EUC-JP';
  7091. case 'cseucfixwidjapanese':
  7092. case 'extendedunixcodefixedwidthforjapanese':
  7093. return 'Extended_UNIX_Code_Fixed_Width_for_Japanese';
  7094. case 'gb18030':
  7095. return 'GB18030';
  7096. case 'chinese':
  7097. case 'cp936':
  7098. case 'csgb2312':
  7099. case 'csiso58gb231280':
  7100. case 'gb2312':
  7101. case 'gb231280':
  7102. case 'gbk':
  7103. case 'isoir58':
  7104. case 'ms936':
  7105. case 'windows936':
  7106. return 'GBK';
  7107. case 'cn':
  7108. case 'csiso57gb1988':
  7109. case 'gb198880':
  7110. case 'iso646cn':
  7111. case 'isoir57':
  7112. return 'GB_1988-80';
  7113. case 'csiso153gost1976874':
  7114. case 'gost1976874':
  7115. case 'isoir153':
  7116. case 'stsev35888':
  7117. return 'GOST_19768-74';
  7118. case 'csiso150':
  7119. case 'csiso150greekccitt':
  7120. case 'greekccitt':
  7121. case 'isoir150':
  7122. return 'greek-ccitt';
  7123. case 'csiso88greek7':
  7124. case 'greek7':
  7125. case 'isoir88':
  7126. return 'greek7';
  7127. case 'csiso18greek7old':
  7128. case 'greek7old':
  7129. case 'isoir18':
  7130. return 'greek7-old';
  7131. case 'cshpdesktop':
  7132. case 'hpdesktop':
  7133. return 'HP-DeskTop';
  7134. case 'cshplegal':
  7135. case 'hplegal':
  7136. return 'HP-Legal';
  7137. case 'cshpmath8':
  7138. case 'hpmath8':
  7139. return 'HP-Math8';
  7140. case 'cshppifont':
  7141. case 'hppifont':
  7142. return 'HP-Pi-font';
  7143. case 'cshproman8':
  7144. case 'hproman8':
  7145. case 'r8':
  7146. case 'roman8':
  7147. return 'hp-roman8';
  7148. case 'hzgb2312':
  7149. return 'HZ-GB-2312';
  7150. case 'csibmsymbols':
  7151. case 'ibmsymbols':
  7152. return 'IBM-Symbols';
  7153. case 'csibmthai':
  7154. case 'ibmthai':
  7155. return 'IBM-Thai';
  7156. case 'cp37':
  7157. case 'csibm37':
  7158. case 'ebcdiccpca':
  7159. case 'ebcdiccpnl':
  7160. case 'ebcdiccpus':
  7161. case 'ebcdiccpwt':
  7162. case 'ibm37':
  7163. return 'IBM037';
  7164. case 'cp38':
  7165. case 'csibm38':
  7166. case 'ebcdicint':
  7167. case 'ibm38':
  7168. return 'IBM038';
  7169. case 'cp273':
  7170. case 'csibm273':
  7171. case 'ibm273':
  7172. return 'IBM273';
  7173. case 'cp274':
  7174. case 'csibm274':
  7175. case 'ebcdicbe':
  7176. case 'ibm274':
  7177. return 'IBM274';
  7178. case 'cp275':
  7179. case 'csibm275':
  7180. case 'ebcdicbr':
  7181. case 'ibm275':
  7182. return 'IBM275';
  7183. case 'csibm277':
  7184. case 'ebcdiccpdk':
  7185. case 'ebcdiccpno':
  7186. case 'ibm277':
  7187. return 'IBM277';
  7188. case 'cp278':
  7189. case 'csibm278':
  7190. case 'ebcdiccpfi':
  7191. case 'ebcdiccpse':
  7192. case 'ibm278':
  7193. return 'IBM278';
  7194. case 'cp280':
  7195. case 'csibm280':
  7196. case 'ebcdiccpit':
  7197. case 'ibm280':
  7198. return 'IBM280';
  7199. case 'cp281':
  7200. case 'csibm281':
  7201. case 'ebcdicjpe':
  7202. case 'ibm281':
  7203. return 'IBM281';
  7204. case 'cp284':
  7205. case 'csibm284':
  7206. case 'ebcdiccpes':
  7207. case 'ibm284':
  7208. return 'IBM284';
  7209. case 'cp285':
  7210. case 'csibm285':
  7211. case 'ebcdiccpgb':
  7212. case 'ibm285':
  7213. return 'IBM285';
  7214. case 'cp290':
  7215. case 'csibm290':
  7216. case 'ebcdicjpkana':
  7217. case 'ibm290':
  7218. return 'IBM290';
  7219. case 'cp297':
  7220. case 'csibm297':
  7221. case 'ebcdiccpfr':
  7222. case 'ibm297':
  7223. return 'IBM297';
  7224. case 'cp420':
  7225. case 'csibm420':
  7226. case 'ebcdiccpar1':
  7227. case 'ibm420':
  7228. return 'IBM420';
  7229. case 'cp423':
  7230. case 'csibm423':
  7231. case 'ebcdiccpgr':
  7232. case 'ibm423':
  7233. return 'IBM423';
  7234. case 'cp424':
  7235. case 'csibm424':
  7236. case 'ebcdiccphe':
  7237. case 'ibm424':
  7238. return 'IBM424';
  7239. case '437':
  7240. case 'cp437':
  7241. case 'cspc8codepage437':
  7242. case 'ibm437':
  7243. return 'IBM437';
  7244. case 'cp500':
  7245. case 'csibm500':
  7246. case 'ebcdiccpbe':
  7247. case 'ebcdiccpch':
  7248. case 'ibm500':
  7249. return 'IBM500';
  7250. case 'cp775':
  7251. case 'cspc775baltic':
  7252. case 'ibm775':
  7253. return 'IBM775';
  7254. case '850':
  7255. case 'cp850':
  7256. case 'cspc850multilingual':
  7257. case 'ibm850':
  7258. return 'IBM850';
  7259. case '851':
  7260. case 'cp851':
  7261. case 'csibm851':
  7262. case 'ibm851':
  7263. return 'IBM851';
  7264. case '852':
  7265. case 'cp852':
  7266. case 'cspcp852':
  7267. case 'ibm852':
  7268. return 'IBM852';
  7269. case '855':
  7270. case 'cp855':
  7271. case 'csibm855':
  7272. case 'ibm855':
  7273. return 'IBM855';
  7274. case '857':
  7275. case 'cp857':
  7276. case 'csibm857':
  7277. case 'ibm857':
  7278. return 'IBM857';
  7279. case 'ccsid858':
  7280. case 'cp858':
  7281. case 'ibm858':
  7282. case 'pcmultilingual850euro':
  7283. return 'IBM00858';
  7284. case '860':
  7285. case 'cp860':
  7286. case 'csibm860':
  7287. case 'ibm860':
  7288. return 'IBM860';
  7289. case '861':
  7290. case 'cp861':
  7291. case 'cpis':
  7292. case 'csibm861':
  7293. case 'ibm861':
  7294. return 'IBM861';
  7295. case '862':
  7296. case 'cp862':
  7297. case 'cspc862latinhebrew':
  7298. case 'ibm862':
  7299. return 'IBM862';
  7300. case '863':
  7301. case 'cp863':
  7302. case 'csibm863':
  7303. case 'ibm863':
  7304. return 'IBM863';
  7305. case 'cp864':
  7306. case 'csibm864':
  7307. case 'ibm864':
  7308. return 'IBM864';
  7309. case '865':
  7310. case 'cp865':
  7311. case 'csibm865':
  7312. case 'ibm865':
  7313. return 'IBM865';
  7314. case '866':
  7315. case 'cp866':
  7316. case 'csibm866':
  7317. case 'ibm866':
  7318. return 'IBM866';
  7319. case 'cp868':
  7320. case 'cpar':
  7321. case 'csibm868':
  7322. case 'ibm868':
  7323. return 'IBM868';
  7324. case '869':
  7325. case 'cp869':
  7326. case 'cpgr':
  7327. case 'csibm869':
  7328. case 'ibm869':
  7329. return 'IBM869';
  7330. case 'cp870':
  7331. case 'csibm870':
  7332. case 'ebcdiccproece':
  7333. case 'ebcdiccpyu':
  7334. case 'ibm870':
  7335. return 'IBM870';
  7336. case 'cp871':
  7337. case 'csibm871':
  7338. case 'ebcdiccpis':
  7339. case 'ibm871':
  7340. return 'IBM871';
  7341. case 'cp880':
  7342. case 'csibm880':
  7343. case 'ebcdiccyrillic':
  7344. case 'ibm880':
  7345. return 'IBM880';
  7346. case 'cp891':
  7347. case 'csibm891':
  7348. case 'ibm891':
  7349. return 'IBM891';
  7350. case 'cp903':
  7351. case 'csibm903':
  7352. case 'ibm903':
  7353. return 'IBM903';
  7354. case '904':
  7355. case 'cp904':
  7356. case 'csibbm904':
  7357. case 'ibm904':
  7358. return 'IBM904';
  7359. case 'cp905':
  7360. case 'csibm905':
  7361. case 'ebcdiccptr':
  7362. case 'ibm905':
  7363. return 'IBM905';
  7364. case 'cp918':
  7365. case 'csibm918':
  7366. case 'ebcdiccpar2':
  7367. case 'ibm918':
  7368. return 'IBM918';
  7369. case 'ccsid924':
  7370. case 'cp924':
  7371. case 'ebcdiclatin9euro':
  7372. case 'ibm924':
  7373. return 'IBM00924';
  7374. case 'cp1026':
  7375. case 'csibm1026':
  7376. case 'ibm1026':
  7377. return 'IBM1026';
  7378. case 'ibm1047':
  7379. return 'IBM1047';
  7380. case 'ccsid1140':
  7381. case 'cp1140':
  7382. case 'ebcdicus37euro':
  7383. case 'ibm1140':
  7384. return 'IBM01140';
  7385. case 'ccsid1141':
  7386. case 'cp1141':
  7387. case 'ebcdicde273euro':
  7388. case 'ibm1141':
  7389. return 'IBM01141';
  7390. case 'ccsid1142':
  7391. case 'cp1142':
  7392. case 'ebcdicdk277euro':
  7393. case 'ebcdicno277euro':
  7394. case 'ibm1142':
  7395. return 'IBM01142';
  7396. case 'ccsid1143':
  7397. case 'cp1143':
  7398. case 'ebcdicfi278euro':
  7399. case 'ebcdicse278euro':
  7400. case 'ibm1143':
  7401. return 'IBM01143';
  7402. case 'ccsid1144':
  7403. case 'cp1144':
  7404. case 'ebcdicit280euro':
  7405. case 'ibm1144':
  7406. return 'IBM01144';
  7407. case 'ccsid1145':
  7408. case 'cp1145':
  7409. case 'ebcdices284euro':
  7410. case 'ibm1145':
  7411. return 'IBM01145';
  7412. case 'ccsid1146':
  7413. case 'cp1146':
  7414. case 'ebcdicgb285euro':
  7415. case 'ibm1146':
  7416. return 'IBM01146';
  7417. case 'ccsid1147':
  7418. case 'cp1147':
  7419. case 'ebcdicfr297euro':
  7420. case 'ibm1147':
  7421. return 'IBM01147';
  7422. case 'ccsid1148':
  7423. case 'cp1148':
  7424. case 'ebcdicinternational500euro':
  7425. case 'ibm1148':
  7426. return 'IBM01148';
  7427. case 'ccsid1149':
  7428. case 'cp1149':
  7429. case 'ebcdicis871euro':
  7430. case 'ibm1149':
  7431. return 'IBM01149';
  7432. case 'csiso143iecp271':
  7433. case 'iecp271':
  7434. case 'isoir143':
  7435. return 'IEC_P27-1';
  7436. case 'csiso49inis':
  7437. case 'inis':
  7438. case 'isoir49':
  7439. return 'INIS';
  7440. case 'csiso50inis8':
  7441. case 'inis8':
  7442. case 'isoir50':
  7443. return 'INIS-8';
  7444. case 'csiso51iniscyrillic':
  7445. case 'iniscyrillic':
  7446. case 'isoir51':
  7447. return 'INIS-cyrillic';
  7448. case 'csinvariant':
  7449. case 'invariant':
  7450. return 'INVARIANT';
  7451. case 'iso2022cn':
  7452. return 'ISO-2022-CN';
  7453. case 'iso2022cnext':
  7454. return 'ISO-2022-CN-EXT';
  7455. case 'csiso2022jp':
  7456. case 'iso2022jp':
  7457. return 'ISO-2022-JP';
  7458. case 'csiso2022jp2':
  7459. case 'iso2022jp2':
  7460. return 'ISO-2022-JP-2';
  7461. case 'csiso2022kr':
  7462. case 'iso2022kr':
  7463. return 'ISO-2022-KR';
  7464. case 'cswindows30latin1':
  7465. case 'iso88591windows30latin1':
  7466. return 'ISO-8859-1-Windows-3.0-Latin-1';
  7467. case 'cswindows31latin1':
  7468. case 'iso88591windows31latin1':
  7469. return 'ISO-8859-1-Windows-3.1-Latin-1';
  7470. case 'csisolatin2':
  7471. case 'iso88592':
  7472. case 'iso885921987':
  7473. case 'isoir101':
  7474. case 'l2':
  7475. case 'latin2':
  7476. return 'ISO-8859-2';
  7477. case 'cswindows31latin2':
  7478. case 'iso88592windowslatin2':
  7479. return 'ISO-8859-2-Windows-Latin-2';
  7480. case 'csisolatin3':
  7481. case 'iso88593':
  7482. case 'iso885931988':
  7483. case 'isoir109':
  7484. case 'l3':
  7485. case 'latin3':
  7486. return 'ISO-8859-3';
  7487. case 'csisolatin4':
  7488. case 'iso88594':
  7489. case 'iso885941988':
  7490. case 'isoir110':
  7491. case 'l4':
  7492. case 'latin4':
  7493. return 'ISO-8859-4';
  7494. case 'csisolatincyrillic':
  7495. case 'cyrillic':
  7496. case 'iso88595':
  7497. case 'iso885951988':
  7498. case 'isoir144':
  7499. return 'ISO-8859-5';
  7500. case 'arabic':
  7501. case 'asmo708':
  7502. case 'csisolatinarabic':
  7503. case 'ecma114':
  7504. case 'iso88596':
  7505. case 'iso885961987':
  7506. case 'isoir127':
  7507. return 'ISO-8859-6';
  7508. case 'csiso88596e':
  7509. case 'iso88596e':
  7510. return 'ISO-8859-6-E';
  7511. case 'csiso88596i':
  7512. case 'iso88596i':
  7513. return 'ISO-8859-6-I';
  7514. case 'csisolatingreek':
  7515. case 'ecma118':
  7516. case 'elot928':
  7517. case 'greek':
  7518. case 'greek8':
  7519. case 'iso88597':
  7520. case 'iso885971987':
  7521. case 'isoir126':
  7522. return 'ISO-8859-7';
  7523. case 'csisolatinhebrew':
  7524. case 'hebrew':
  7525. case 'iso88598':
  7526. case 'iso885981988':
  7527. case 'isoir138':
  7528. return 'ISO-8859-8';
  7529. case 'csiso88598e':
  7530. case 'iso88598e':
  7531. return 'ISO-8859-8-E';
  7532. case 'csiso88598i':
  7533. case 'iso88598i':
  7534. return 'ISO-8859-8-I';
  7535. case 'cswindows31latin5':
  7536. case 'iso88599windowslatin5':
  7537. return 'ISO-8859-9-Windows-Latin-5';
  7538. case 'csisolatin6':
  7539. case 'iso885910':
  7540. case 'iso8859101992':
  7541. case 'isoir157':
  7542. case 'l6':
  7543. case 'latin6':
  7544. return 'ISO-8859-10';
  7545. case 'iso885913':
  7546. return 'ISO-8859-13';
  7547. case 'iso885914':
  7548. case 'iso8859141998':
  7549. case 'isoceltic':
  7550. case 'isoir199':
  7551. case 'l8':
  7552. case 'latin8':
  7553. return 'ISO-8859-14';
  7554. case 'iso885915':
  7555. case 'latin9':
  7556. return 'ISO-8859-15';
  7557. case 'iso885916':
  7558. case 'iso8859162001':
  7559. case 'isoir226':
  7560. case 'l10':
  7561. case 'latin10':
  7562. return 'ISO-8859-16';
  7563. case 'iso10646j1':
  7564. return 'ISO-10646-J-1';
  7565. case 'csunicode':
  7566. case 'iso10646ucs2':
  7567. return 'ISO-10646-UCS-2';
  7568. case 'csucs4':
  7569. case 'iso10646ucs4':
  7570. return 'ISO-10646-UCS-4';
  7571. case 'csunicodeascii':
  7572. case 'iso10646ucsbasic':
  7573. return 'ISO-10646-UCS-Basic';
  7574. case 'csunicodelatin1':
  7575. case 'iso10646':
  7576. case 'iso10646unicodelatin1':
  7577. return 'ISO-10646-Unicode-Latin1';
  7578. case 'csiso10646utf1':
  7579. case 'iso10646utf1':
  7580. return 'ISO-10646-UTF-1';
  7581. case 'csiso115481':
  7582. case 'iso115481':
  7583. case 'isotr115481':
  7584. return 'ISO-11548-1';
  7585. case 'csiso90':
  7586. case 'isoir90':
  7587. return 'iso-ir-90';
  7588. case 'csunicodeibm1261':
  7589. case 'isounicodeibm1261':
  7590. return 'ISO-Unicode-IBM-1261';
  7591. case 'csunicodeibm1264':
  7592. case 'isounicodeibm1264':
  7593. return 'ISO-Unicode-IBM-1264';
  7594. case 'csunicodeibm1265':
  7595. case 'isounicodeibm1265':
  7596. return 'ISO-Unicode-IBM-1265';
  7597. case 'csunicodeibm1268':
  7598. case 'isounicodeibm1268':
  7599. return 'ISO-Unicode-IBM-1268';
  7600. case 'csunicodeibm1276':
  7601. case 'isounicodeibm1276':
  7602. return 'ISO-Unicode-IBM-1276';
  7603. case 'csiso646basic1983':
  7604. case 'iso646basic1983':
  7605. case 'ref':
  7606. return 'ISO_646.basic:1983';
  7607. case 'csiso2intlrefversion':
  7608. case 'irv':
  7609. case 'iso646irv1983':
  7610. case 'isoir2':
  7611. return 'ISO_646.irv:1983';
  7612. case 'csiso2033':
  7613. case 'e13b':
  7614. case 'iso20331983':
  7615. case 'isoir98':
  7616. return 'ISO_2033-1983';
  7617. case 'csiso5427cyrillic':
  7618. case 'iso5427':
  7619. case 'isoir37':
  7620. return 'ISO_5427';
  7621. case 'iso5427cyrillic1981':
  7622. case 'iso54271981':
  7623. case 'isoir54':
  7624. return 'ISO_5427:1981';
  7625. case 'csiso5428greek':
  7626. case 'iso54281980':
  7627. case 'isoir55':
  7628. return 'ISO_5428:1980';
  7629. case 'csiso6937add':
  7630. case 'iso6937225':
  7631. case 'isoir152':
  7632. return 'ISO_6937-2-25';
  7633. case 'csisotextcomm':
  7634. case 'iso69372add':
  7635. case 'isoir142':
  7636. return 'ISO_6937-2-add';
  7637. case 'csiso8859supp':
  7638. case 'iso8859supp':
  7639. case 'isoir154':
  7640. case 'latin125':
  7641. return 'ISO_8859-supp';
  7642. case 'csiso10367box':
  7643. case 'iso10367box':
  7644. case 'isoir155':
  7645. return 'ISO_10367-box';
  7646. case 'csiso15italian':
  7647. case 'iso646it':
  7648. case 'isoir15':
  7649. case 'it':
  7650. return 'IT';
  7651. case 'csiso13jisc6220jp':
  7652. case 'isoir13':
  7653. case 'jisc62201969':
  7654. case 'jisc62201969jp':
  7655. case 'katakana':
  7656. case 'x2017':
  7657. return 'JIS_C6220-1969-jp';
  7658. case 'csiso14jisc6220ro':
  7659. case 'iso646jp':
  7660. case 'isoir14':
  7661. case 'jisc62201969ro':
  7662. case 'jp':
  7663. return 'JIS_C6220-1969-ro';
  7664. case 'csiso42jisc62261978':
  7665. case 'isoir42':
  7666. case 'jisc62261978':
  7667. return 'JIS_C6226-1978';
  7668. case 'csiso87jisx208':
  7669. case 'isoir87':
  7670. case 'jisc62261983':
  7671. case 'jisx2081983':
  7672. case 'x208':
  7673. return 'JIS_C6226-1983';
  7674. case 'csiso91jisc62291984a':
  7675. case 'isoir91':
  7676. case 'jisc62291984a':
  7677. case 'jpocra':
  7678. return 'JIS_C6229-1984-a';
  7679. case 'csiso92jisc62991984b':
  7680. case 'iso646jpocrb':
  7681. case 'isoir92':
  7682. case 'jisc62291984b':
  7683. case 'jpocrb':
  7684. return 'JIS_C6229-1984-b';
  7685. case 'csiso93jis62291984badd':
  7686. case 'isoir93':
  7687. case 'jisc62291984badd':
  7688. case 'jpocrbadd':
  7689. return 'JIS_C6229-1984-b-add';
  7690. case 'csiso94jis62291984hand':
  7691. case 'isoir94':
  7692. case 'jisc62291984hand':
  7693. case 'jpocrhand':
  7694. return 'JIS_C6229-1984-hand';
  7695. case 'csiso95jis62291984handadd':
  7696. case 'isoir95':
  7697. case 'jisc62291984handadd':
  7698. case 'jpocrhandadd':
  7699. return 'JIS_C6229-1984-hand-add';
  7700. case 'csiso96jisc62291984kana':
  7701. case 'isoir96':
  7702. case 'jisc62291984kana':
  7703. return 'JIS_C6229-1984-kana';
  7704. case 'csjisencoding':
  7705. case 'jisencoding':
  7706. return 'JIS_Encoding';
  7707. case 'cshalfwidthkatakana':
  7708. case 'jisx201':
  7709. case 'x201':
  7710. return 'JIS_X0201';
  7711. case 'csiso159jisx2121990':
  7712. case 'isoir159':
  7713. case 'jisx2121990':
  7714. case 'x212':
  7715. return 'JIS_X0212-1990';
  7716. case 'csiso141jusib1002':
  7717. case 'iso646yu':
  7718. case 'isoir141':
  7719. case 'js':
  7720. case 'jusib1002':
  7721. case 'yu':
  7722. return 'JUS_I.B1.002';
  7723. case 'csiso147macedonian':
  7724. case 'isoir147':
  7725. case 'jusib1003mac':
  7726. case 'macedonian':
  7727. return 'JUS_I.B1.003-mac';
  7728. case 'csiso146serbian':
  7729. case 'isoir146':
  7730. case 'jusib1003serb':
  7731. case 'serbian':
  7732. return 'JUS_I.B1.003-serb';
  7733. case 'koi7switched':
  7734. return 'KOI7-switched';
  7735. case 'cskoi8r':
  7736. case 'koi8r':
  7737. return 'KOI8-R';
  7738. case 'koi8u':
  7739. return 'KOI8-U';
  7740. case 'csksc5636':
  7741. case 'iso646kr':
  7742. case 'ksc5636':
  7743. return 'KSC5636';
  7744. case 'cskz1048':
  7745. case 'kz1048':
  7746. case 'rk1048':
  7747. case 'strk10482002':
  7748. return 'KZ-1048';
  7749. case 'csiso19latingreek':
  7750. case 'isoir19':
  7751. case 'latingreek':
  7752. return 'latin-greek';
  7753. case 'csiso27latingreek1':
  7754. case 'isoir27':
  7755. case 'latingreek1':
  7756. return 'Latin-greek-1';
  7757. case 'csiso158lap':
  7758. case 'isoir158':
  7759. case 'lap':
  7760. case 'latinlap':
  7761. return 'latin-lap';
  7762. case 'csmacintosh':
  7763. case 'mac':
  7764. case 'macintosh':
  7765. return 'macintosh';
  7766. case 'csmicrosoftpublishing':
  7767. case 'microsoftpublishing':
  7768. return 'Microsoft-Publishing';
  7769. case 'csmnem':
  7770. case 'mnem':
  7771. return 'MNEM';
  7772. case 'csmnemonic':
  7773. case 'mnemonic':
  7774. return 'MNEMONIC';
  7775. case 'csiso86hungarian':
  7776. case 'hu':
  7777. case 'iso646hu':
  7778. case 'isoir86':
  7779. case 'msz77953':
  7780. return 'MSZ_7795.3';
  7781. case 'csnatsdano':
  7782. case 'isoir91':
  7783. case 'natsdano':
  7784. return 'NATS-DANO';
  7785. case 'csnatsdanoadd':
  7786. case 'isoir92':
  7787. case 'natsdanoadd':
  7788. return 'NATS-DANO-ADD';
  7789. case 'csnatssefi':
  7790. case 'isoir81':
  7791. case 'natssefi':
  7792. return 'NATS-SEFI';
  7793. case 'csnatssefiadd':
  7794. case 'isoir82':
  7795. case 'natssefiadd':
  7796. return 'NATS-SEFI-ADD';
  7797. case 'csiso151cuba':
  7798. case 'cuba':
  7799. case 'iso646cu':
  7800. case 'isoir151':
  7801. case 'ncnc1081':
  7802. return 'NC_NC00-10:81';
  7803. case 'csiso69french':
  7804. case 'fr':
  7805. case 'iso646fr':
  7806. case 'isoir69':
  7807. case 'nfz62010':
  7808. return 'NF_Z_62-010';
  7809. case 'csiso25french':
  7810. case 'iso646fr1':
  7811. case 'isoir25':
  7812. case 'nfz620101973':
  7813. return 'NF_Z_62-010_(1973)';
  7814. case 'csiso60danishnorwegian':
  7815. case 'csiso60norwegian1':
  7816. case 'iso646no':
  7817. case 'isoir60':
  7818. case 'no':
  7819. case 'ns45511':
  7820. return 'NS_4551-1';
  7821. case 'csiso61norwegian2':
  7822. case 'iso646no2':
  7823. case 'isoir61':
  7824. case 'no2':
  7825. case 'ns45512':
  7826. return 'NS_4551-2';
  7827. case 'osdebcdicdf3irv':
  7828. return 'OSD_EBCDIC_DF03_IRV';
  7829. case 'osdebcdicdf41':
  7830. return 'OSD_EBCDIC_DF04_1';
  7831. case 'osdebcdicdf415':
  7832. return 'OSD_EBCDIC_DF04_15';
  7833. case 'cspc8danishnorwegian':
  7834. case 'pc8danishnorwegian':
  7835. return 'PC8-Danish-Norwegian';
  7836. case 'cspc8turkish':
  7837. case 'pc8turkish':
  7838. return 'PC8-Turkish';
  7839. case 'csiso16portuguese':
  7840. case 'iso646pt':
  7841. case 'isoir16':
  7842. case 'pt':
  7843. return 'PT';
  7844. case 'csiso84portuguese2':
  7845. case 'iso646pt2':
  7846. case 'isoir84':
  7847. case 'pt2':
  7848. return 'PT2';
  7849. case 'cp154':
  7850. case 'csptcp154':
  7851. case 'cyrillicasian':
  7852. case 'pt154':
  7853. case 'ptcp154':
  7854. return 'PTCP154';
  7855. case 'scsu':
  7856. return 'SCSU';
  7857. case 'csiso10swedish':
  7858. case 'fi':
  7859. case 'iso646fi':
  7860. case 'iso646se':
  7861. case 'isoir10':
  7862. case 'se':
  7863. case 'sen850200b':
  7864. return 'SEN_850200_B';
  7865. case 'csiso11swedishfornames':
  7866. case 'iso646se2':
  7867. case 'isoir11':
  7868. case 'se2':
  7869. case 'sen850200c':
  7870. return 'SEN_850200_C';
  7871. case 'csiso102t617bit':
  7872. case 'isoir102':
  7873. case 't617bit':
  7874. return 'T.61-7bit';
  7875. case 'csiso103t618bit':
  7876. case 'isoir103':
  7877. case 't61':
  7878. case 't618bit':
  7879. return 'T.61-8bit';
  7880. case 'csiso128t101g2':
  7881. case 'isoir128':
  7882. case 't101g2':
  7883. return 'T.101-G2';
  7884. case 'cstscii':
  7885. case 'tscii':
  7886. return 'TSCII';
  7887. case 'csunicode11':
  7888. case 'unicode11':
  7889. return 'UNICODE-1-1';
  7890. case 'csunicode11utf7':
  7891. case 'unicode11utf7':
  7892. return 'UNICODE-1-1-UTF-7';
  7893. case 'csunknown8bit':
  7894. case 'unknown8bit':
  7895. return 'UNKNOWN-8BIT';
  7896. case 'ansix341968':
  7897. case 'ansix341986':
  7898. case 'ascii':
  7899. case 'cp367':
  7900. case 'csascii':
  7901. case 'ibm367':
  7902. case 'iso646irv1991':
  7903. case 'iso646us':
  7904. case 'isoir6':
  7905. case 'us':
  7906. case 'usascii':
  7907. return 'US-ASCII';
  7908. case 'csusdk':
  7909. case 'usdk':
  7910. return 'us-dk';
  7911. case 'utf7':
  7912. return 'UTF-7';
  7913. case 'utf8':
  7914. return 'UTF-8';
  7915. case 'utf16':
  7916. return 'UTF-16';
  7917. case 'utf16be':
  7918. return 'UTF-16BE';
  7919. case 'utf16le':
  7920. return 'UTF-16LE';
  7921. case 'utf32':
  7922. return 'UTF-32';
  7923. case 'utf32be':
  7924. return 'UTF-32BE';
  7925. case 'utf32le':
  7926. return 'UTF-32LE';
  7927. case 'csventurainternational':
  7928. case 'venturainternational':
  7929. return 'Ventura-International';
  7930. case 'csventuramath':
  7931. case 'venturamath':
  7932. return 'Ventura-Math';
  7933. case 'csventuraus':
  7934. case 'venturaus':
  7935. return 'Ventura-US';
  7936. case 'csiso70videotexsupp1':
  7937. case 'isoir70':
  7938. case 'videotexsuppl':
  7939. return 'videotex-suppl';
  7940. case 'csviqr':
  7941. case 'viqr':
  7942. return 'VIQR';
  7943. case 'csviscii':
  7944. case 'viscii':
  7945. return 'VISCII';
  7946. case 'csshiftjis':
  7947. case 'cswindows31j':
  7948. case 'mskanji':
  7949. case 'shiftjis':
  7950. case 'windows31j':
  7951. return 'Windows-31J';
  7952. case 'iso885911':
  7953. case 'tis620':
  7954. return 'windows-874';
  7955. case 'cseuckr':
  7956. case 'csksc56011987':
  7957. case 'euckr':
  7958. case 'isoir149':
  7959. case 'korean':
  7960. case 'ksc5601':
  7961. case 'ksc56011987':
  7962. case 'ksc56011989':
  7963. case 'windows949':
  7964. return 'windows-949';
  7965. case 'windows1250':
  7966. return 'windows-1250';
  7967. case 'windows1251':
  7968. return 'windows-1251';
  7969. case 'cp819':
  7970. case 'csisolatin1':
  7971. case 'ibm819':
  7972. case 'iso88591':
  7973. case 'iso885911987':
  7974. case 'isoir100':
  7975. case 'l1':
  7976. case 'latin1':
  7977. case 'windows1252':
  7978. return 'windows-1252';
  7979. case 'windows1253':
  7980. return 'windows-1253';
  7981. case 'csisolatin5':
  7982. case 'iso88599':
  7983. case 'iso885991989':
  7984. case 'isoir148':
  7985. case 'l5':
  7986. case 'latin5':
  7987. case 'windows1254':
  7988. return 'windows-1254';
  7989. case 'windows1255':
  7990. return 'windows-1255';
  7991. case 'windows1256':
  7992. return 'windows-1256';
  7993. case 'windows1257':
  7994. return 'windows-1257';
  7995. case 'windows1258':
  7996. return 'windows-1258';
  7997. default:
  7998. return $charset;
  7999. }
  8000. }
  8001. public static function get_curl_version() {
  8002. if (is_array($curl = curl_version())) {
  8003. $curl = $curl['version'];
  8004. }
  8005. elseif (substr($curl, 0, 5) === 'curl/') {
  8006. $curl = substr($curl, 5, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 5));
  8007. }
  8008. elseif (substr($curl, 0, 8) === 'libcurl/') {
  8009. $curl = substr($curl, 8, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 8));
  8010. }
  8011. else {
  8012. $curl = 0;
  8013. }
  8014. return $curl;
  8015. }
  8016. public static function strip_comments($data) {
  8017. $output = '';
  8018. while (($start = strpos($data, '<!--')) !== false) {
  8019. $output .= substr($data, 0, $start);
  8020. if (($end = strpos($data, '-->', $start)) !== false) {
  8021. $data = substr_replace($data, '', 0, $end + 3);
  8022. }
  8023. else {
  8024. $data = '';
  8025. }
  8026. }
  8027. return $output . $data;
  8028. }
  8029. public static function parse_date($dt) {
  8030. $parser = SimplePie_Parse_Date::get();
  8031. return $parser->parse($dt);
  8032. }
  8033. public static function entities_decode($data) {
  8034. $decoder = new SimplePie_Decode_HTML_Entities($data);
  8035. return $decoder->parse();
  8036. }
  8037. public static function uncomment_rfc822($string) {
  8038. $string = (string) $string;
  8039. $position = 0;
  8040. $length = strlen($string);
  8041. $depth = 0;
  8042. $output = '';
  8043. while ($position < $length && ($pos = strpos($string, '(', $position)) !== false) {
  8044. $output .= substr($string, $position, $pos - $position);
  8045. $position = $pos + 1;
  8046. if ($string[$pos - 1] !== '\\') {
  8047. $depth++;
  8048. while ($depth && $position < $length) {
  8049. $position += strcspn($string, '()', $position);
  8050. if ($string[$position - 1] === '\\') {
  8051. $position++;
  8052. continue;
  8053. }
  8054. elseif (isset($string[$position])) {
  8055. switch ($string[$position]) {
  8056. case '(':
  8057. $depth++;
  8058. break;
  8059. case ')':
  8060. $depth--;
  8061. break;
  8062. }
  8063. $position++;
  8064. }
  8065. else {
  8066. break;
  8067. }
  8068. }
  8069. }
  8070. else {
  8071. $output .= '(';
  8072. }
  8073. }
  8074. $output .= substr($string, $position);
  8075. return $output;
  8076. }
  8077. public static function parse_mime($mime) {
  8078. if (($pos = strpos($mime, ';')) === false) {
  8079. return trim($mime);
  8080. }
  8081. else {
  8082. return trim(substr($mime, 0, $pos));
  8083. }
  8084. }
  8085. public static function atom_03_construct_type($attribs) {
  8086. if (isset($attribs['']['mode']) && strtolower(trim($attribs['']['mode']) === 'base64')) {
  8087. $mode = SIMPLEPIE_CONSTRUCT_BASE64;
  8088. }
  8089. else {
  8090. $mode = SIMPLEPIE_CONSTRUCT_NONE;
  8091. }
  8092. if (isset($attribs['']['type'])) {
  8093. switch (strtolower(trim($attribs['']['type']))) {
  8094. case 'text':
  8095. case 'text/plain':
  8096. return SIMPLEPIE_CONSTRUCT_TEXT | $mode;
  8097. case 'html':
  8098. case 'text/html':
  8099. return SIMPLEPIE_CONSTRUCT_HTML | $mode;
  8100. case 'xhtml':
  8101. case 'application/xhtml+xml':
  8102. return SIMPLEPIE_CONSTRUCT_XHTML | $mode;
  8103. default:
  8104. return SIMPLEPIE_CONSTRUCT_NONE | $mode;
  8105. }
  8106. }
  8107. else {
  8108. return SIMPLEPIE_CONSTRUCT_TEXT | $mode;
  8109. }
  8110. }
  8111. public static function atom_10_construct_type($attribs) {
  8112. if (isset($attribs['']['type'])) {
  8113. switch (strtolower(trim($attribs['']['type']))) {
  8114. case 'text':
  8115. return SIMPLEPIE_CONSTRUCT_TEXT;
  8116. case 'html':
  8117. return SIMPLEPIE_CONSTRUCT_HTML;
  8118. case 'xhtml':
  8119. return SIMPLEPIE_CONSTRUCT_XHTML;
  8120. default:
  8121. return SIMPLEPIE_CONSTRUCT_NONE;
  8122. }
  8123. }
  8124. return SIMPLEPIE_CONSTRUCT_TEXT;
  8125. }
  8126. public static function atom_10_content_construct_type($attribs) {
  8127. if (isset($attribs['']['type'])) {
  8128. $type = strtolower(trim($attribs['']['type']));
  8129. switch ($type) {
  8130. case 'text':
  8131. return SIMPLEPIE_CONSTRUCT_TEXT;
  8132. case 'html':
  8133. return SIMPLEPIE_CONSTRUCT_HTML;
  8134. case 'xhtml':
  8135. return SIMPLEPIE_CONSTRUCT_XHTML;
  8136. }
  8137. if (in_array(substr($type, -4), array('+xml', '/xml')) || substr($type, 0, 5) === 'text/') {
  8138. return SIMPLEPIE_CONSTRUCT_NONE;
  8139. }
  8140. else {
  8141. return SIMPLEPIE_CONSTRUCT_BASE64;
  8142. }
  8143. }
  8144. else {
  8145. return SIMPLEPIE_CONSTRUCT_TEXT;
  8146. }
  8147. }
  8148. public static function is_isegment_nz_nc($string) {
  8149. 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);
  8150. }
  8151. public static function space_seperated_tokens($string) {
  8152. $space_characters = "\x20\x09\x0A\x0B\x0C\x0D";
  8153. $string_length = strlen($string);
  8154. $position = strspn($string, $space_characters);
  8155. $tokens = array();
  8156. while ($position < $string_length) {
  8157. $len = strcspn($string, $space_characters, $position);
  8158. $tokens[] = substr($string, $position, $len);
  8159. $position += $len;
  8160. $position += strspn($string, $space_characters, $position);
  8161. }
  8162. return $tokens;
  8163. }
  8164. public static function codepoint_to_utf8($codepoint) {
  8165. $codepoint = (int) $codepoint;
  8166. if ($codepoint < 0) {
  8167. return false;
  8168. }
  8169. else if ($codepoint <= 0x7f) {
  8170. return chr($codepoint);
  8171. }
  8172. else if ($codepoint <= 0x7ff) {
  8173. return chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3f));
  8174. }
  8175. else if ($codepoint <= 0xffff) {
  8176. return chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
  8177. }
  8178. else if ($codepoint <= 0x10ffff) {
  8179. return chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
  8180. }
  8181. else {
  8182. // U+FFFD REPLACEMENT CHARACTER
  8183. return "\xEF\xBF\xBD";
  8184. }
  8185. }
  8186. public static function parse_str($str) {
  8187. $return = array();
  8188. $str = explode('&', $str);
  8189. foreach ($str as $section) {
  8190. if (strpos($section, '=') !== false) {
  8191. list($name, $value) = explode('=', $section, 2);
  8192. $return[urldecode($name)][] = urldecode($value);
  8193. }
  8194. else {
  8195. $return[urldecode($section)][] = null;
  8196. }
  8197. }
  8198. return $return;
  8199. }
  8200. public static function xml_encoding($data, $registry) {
  8201. // UTF-32 Big Endian BOM
  8202. if (substr($data, 0, 4) === "\x00\x00\xFE\xFF") {
  8203. $encoding[] = 'UTF-32BE';
  8204. }
  8205. // UTF-32 Little Endian BOM
  8206. elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00") {
  8207. $encoding[] = 'UTF-32LE';
  8208. }
  8209. // UTF-16 Big Endian BOM
  8210. elseif (substr($data, 0, 2) === "\xFE\xFF") {
  8211. $encoding[] = 'UTF-16BE';
  8212. }
  8213. // UTF-16 Little Endian BOM
  8214. elseif (substr($data, 0, 2) === "\xFF\xFE") {
  8215. $encoding[] = 'UTF-16LE';
  8216. }
  8217. // UTF-8 BOM
  8218. elseif (substr($data, 0, 3) === "\xEF\xBB\xBF") {
  8219. $encoding[] = 'UTF-8';
  8220. }
  8221. // UTF-32 Big Endian Without BOM
  8222. 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") {
  8223. if ($pos = strpos($data, "\x00\x00\x00\x3F\x00\x00\x00\x3E")) {
  8224. $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32BE', 'UTF-8')));
  8225. if ($parser->parse()) {
  8226. $encoding[] = $parser->encoding;
  8227. }
  8228. }
  8229. $encoding[] = 'UTF-32BE';
  8230. }
  8231. // UTF-32 Little Endian Without BOM
  8232. 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") {
  8233. if ($pos = strpos($data, "\x3F\x00\x00\x00\x3E\x00\x00\x00")) {
  8234. $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32LE', 'UTF-8')));
  8235. if ($parser->parse()) {
  8236. $encoding[] = $parser->encoding;
  8237. }
  8238. }
  8239. $encoding[] = 'UTF-32LE';
  8240. }
  8241. // UTF-16 Big Endian Without BOM
  8242. elseif (substr($data, 0, 10) === "\x00\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C") {
  8243. if ($pos = strpos($data, "\x00\x3F\x00\x3E")) {
  8244. $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16BE', 'UTF-8')));
  8245. if ($parser->parse()) {
  8246. $encoding[] = $parser->encoding;
  8247. }
  8248. }
  8249. $encoding[] = 'UTF-16BE';
  8250. }
  8251. // UTF-16 Little Endian Without BOM
  8252. elseif (substr($data, 0, 10) === "\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C\x00") {
  8253. if ($pos = strpos($data, "\x3F\x00\x3E\x00")) {
  8254. $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16LE', 'UTF-8')));
  8255. if ($parser->parse()) {
  8256. $encoding[] = $parser->encoding;
  8257. }
  8258. }
  8259. $encoding[] = 'UTF-16LE';
  8260. }
  8261. // US-ASCII (or superset)
  8262. elseif (substr($data, 0, 5) === "\x3C\x3F\x78\x6D\x6C") {
  8263. if ($pos = strpos($data, "\x3F\x3E")) {
  8264. $parser = $registry->create('XML_Declaration_Parser', array(substr($data, 5, $pos - 5)));
  8265. if ($parser->parse()) {
  8266. $encoding[] = $parser->encoding;
  8267. }
  8268. }
  8269. $encoding[] = 'UTF-8';
  8270. }
  8271. // Fallback to UTF-8
  8272. else {
  8273. $encoding[] = 'UTF-8';
  8274. }
  8275. return $encoding;
  8276. }
  8277. public static function output_javascript() {
  8278. if (function_exists('ob_gzhandler')) {
  8279. ob_start('ob_gzhandler');
  8280. }
  8281. header('Content-type: text/javascript; charset: UTF-8');
  8282. header('Cache-Control: must-revalidate');
  8283. header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'); // 7 days
  8284. ?>
  8285. function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {
  8286. if (placeholder != '') {
  8287. 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>');
  8288. }
  8289. else {
  8290. 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>');
  8291. }
  8292. }
  8293. function embed_flash(bgcolor, width, height, link, loop, type) {
  8294. 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>');
  8295. }
  8296. function embed_flv(width, height, link, placeholder, loop, player) {
  8297. 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>');
  8298. }
  8299. function embed_wmedia(width, height, link) {
  8300. document.writeln('<embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>');
  8301. }
  8302. <?php
  8303. }
  8304. public static function get_build() {
  8305. $root = dirname(dirname(__FILE__));
  8306. if (file_exists($root . '/.git/index')) {
  8307. return filemtime($root . '/.git/index');
  8308. }
  8309. elseif (file_exists($root . '/SimplePie')) {
  8310. $time = 0;
  8311. foreach (glob($root . '/SimplePie/*.php') as $file) {
  8312. if (($mtime = filemtime($file)) > $time) {
  8313. $time = $mtime;
  8314. }
  8315. }
  8316. return $time;
  8317. }
  8318. elseif (file_exists(dirname(__FILE__) . '/Core.php')) {
  8319. return filemtime(dirname(__FILE__) . '/Core.php');
  8320. }
  8321. else {
  8322. return filemtime(__FILE__);
  8323. }
  8324. }
  8325. public static function debug(&$sp) {
  8326. $info = 'SimplePie ' . SIMPLEPIE_VERSION . ' Build ' . SIMPLEPIE_BUILD . "\n";
  8327. $info .= 'PHP ' . PHP_VERSION . "\n";
  8328. if ($sp->error() !== null) {
  8329. $info .= 'Error occurred: ' . $sp->error() . "\n";
  8330. }
  8331. else {
  8332. $info .= "No error found.\n";
  8333. }
  8334. $info .= "Extensions:\n";
  8335. $extensions = array('pcre', 'curl', 'zlib', 'mbstring', 'iconv', 'xmlreader', 'xml');
  8336. foreach ($extensions as $ext) {
  8337. if (extension_loaded($ext)) {
  8338. $info .= " $ext loaded\n";
  8339. switch ($ext) {
  8340. case 'pcre':
  8341. $info .= ' Version ' . PCRE_VERSION . "\n";
  8342. break;
  8343. case 'curl':
  8344. $version = curl_version();
  8345. $info .= ' Version ' . $version['version'] . "\n";
  8346. break;
  8347. case 'mbstring':
  8348. $info .= ' Overloading: ' . mb_get_info('func_overload') . "\n";
  8349. break;
  8350. case 'iconv':
  8351. $info .= ' Version ' . ICONV_VERSION . "\n";
  8352. break;
  8353. case 'xml':
  8354. $info .= ' Version ' . LIBXML_DOTTED_VERSION . "\n";
  8355. break;
  8356. }
  8357. }
  8358. else {
  8359. $info .= " $ext not loaded\n";
  8360. }
  8361. }
  8362. return $info;
  8363. }
  8364. public static function silence_errors($num, $str) {
  8365. // No-op
  8366. }
  8367. }
  8368. class SimplePie_Net_IPv6 {
  8369. public static function uncompress($ip) {
  8370. $c1 = -1;
  8371. $c2 = -1;
  8372. if (substr_count($ip, '::') === 1) {
  8373. list($ip1, $ip2) = explode('::', $ip);
  8374. if ($ip1 === '') {
  8375. $c1 = -1;
  8376. }
  8377. else {
  8378. $c1 = substr_count($ip1, ':');
  8379. }
  8380. if ($ip2 === '') {
  8381. $c2 = -1;
  8382. }
  8383. else {
  8384. $c2 = substr_count($ip2, ':');
  8385. }
  8386. if (strpos($ip2, '.') !== false) {
  8387. $c2++;
  8388. }
  8389. // ::
  8390. if ($c1 === -1 && $c2 === -1) {
  8391. $ip = '0:0:0:0:0:0:0:0';
  8392. }
  8393. // ::xxx
  8394. else if ($c1 === -1) {
  8395. $fill = str_repeat('0:', 7 - $c2);
  8396. $ip = str_replace('::', $fill, $ip);
  8397. }
  8398. // xxx::
  8399. else if ($c2 === -1) {
  8400. $fill = str_repeat(':0', 7 - $c1);
  8401. $ip = str_replace('::', $fill, $ip);
  8402. }
  8403. // xxx::xxx
  8404. else {
  8405. $fill = ':' . str_repeat('0:', 6 - $c2 - $c1);
  8406. $ip = str_replace('::', $fill, $ip);
  8407. }
  8408. }
  8409. return $ip;
  8410. }
  8411. public static function compress($ip) {
  8412. // Prepare the IP to be compressed
  8413. $ip = self::uncompress($ip);
  8414. $ip_parts = self::split_v6_v4($ip);
  8415. // Replace all leading zeros
  8416. $ip_parts[0] = preg_replace('/(^|:)0+([0-9])/', '\1\2', $ip_parts[0]);
  8417. // Find bunches of zeros
  8418. if (preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE)) {
  8419. $max = 0;
  8420. $pos = null;
  8421. foreach ($matches[0] as $match) {
  8422. if (strlen($match[0]) > $max) {
  8423. $max = strlen($match[0]);
  8424. $pos = $match[1];
  8425. }
  8426. }
  8427. $ip_parts[0] = substr_replace($ip_parts[0], '::', $pos, $max);
  8428. }
  8429. if ($ip_parts[1] !== '') {
  8430. return implode(':', $ip_parts);
  8431. }
  8432. else {
  8433. return $ip_parts[0];
  8434. }
  8435. }
  8436. private static function split_v6_v4($ip) {
  8437. if (strpos($ip, '.') !== false) {
  8438. $pos = strrpos($ip, ':');
  8439. $ipv6_part = substr($ip, 0, $pos);
  8440. $ipv4_part = substr($ip, $pos + 1);
  8441. return array($ipv6_part, $ipv4_part);
  8442. }
  8443. else {
  8444. return array($ip, '');
  8445. }
  8446. }
  8447. public static function check_ipv6($ip) {
  8448. $ip = self::uncompress($ip);
  8449. list($ipv6, $ipv4) = self::split_v6_v4($ip);
  8450. $ipv6 = explode(':', $ipv6);
  8451. $ipv4 = explode('.', $ipv4);
  8452. if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4) {
  8453. foreach ($ipv6 as $ipv6_part) {
  8454. // The section can't be empty
  8455. if ($ipv6_part === '')
  8456. return false;
  8457. // Nor can it be over four characters
  8458. if (strlen($ipv6_part) > 4)
  8459. return false;
  8460. // Remove leading zeros (this is safe because of the above)
  8461. $ipv6_part = ltrim($ipv6_part, '0');
  8462. if ($ipv6_part === '')
  8463. $ipv6_part = '0';
  8464. // Check the value is valid
  8465. $value = hexdec($ipv6_part);
  8466. if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF)
  8467. return false;
  8468. }
  8469. if (count($ipv4) === 4) {
  8470. foreach ($ipv4 as $ipv4_part) {
  8471. $value = (int) $ipv4_part;
  8472. if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF)
  8473. return false;
  8474. }
  8475. }
  8476. return true;
  8477. }
  8478. else {
  8479. return false;
  8480. }
  8481. }
  8482. public static function checkIPv6($ip) {
  8483. return self::check_ipv6($ip);
  8484. }
  8485. }
  8486. class SimplePie_Parse_Date {
  8487. var $date;
  8488. var $day = array(
  8489. // English
  8490. 'mon' => 1,
  8491. 'monday' => 1,
  8492. 'tue' => 2,
  8493. 'tuesday' => 2,
  8494. 'wed' => 3,
  8495. 'wednesday' => 3,
  8496. 'thu' => 4,
  8497. 'thursday' => 4,
  8498. 'fri' => 5,
  8499. 'friday' => 5,
  8500. 'sat' => 6,
  8501. 'saturday' => 6,
  8502. 'sun' => 7,
  8503. 'sunday' => 7,
  8504. // Dutch
  8505. 'maandag' => 1,
  8506. 'dinsdag' => 2,
  8507. 'woensdag' => 3,
  8508. 'donderdag' => 4,
  8509. 'vrijdag' => 5,
  8510. 'zaterdag' => 6,
  8511. 'zondag' => 7,
  8512. // French
  8513. 'lundi' => 1,
  8514. 'mardi' => 2,
  8515. 'mercredi' => 3,
  8516. 'jeudi' => 4,
  8517. 'vendredi' => 5,
  8518. 'samedi' => 6,
  8519. 'dimanche' => 7,
  8520. // German
  8521. 'montag' => 1,
  8522. 'dienstag' => 2,
  8523. 'mittwoch' => 3,
  8524. 'donnerstag' => 4,
  8525. 'freitag' => 5,
  8526. 'samstag' => 6,
  8527. 'sonnabend' => 6,
  8528. 'sonntag' => 7,
  8529. // Italian
  8530. 'lunedì' => 1,
  8531. 'martedì' => 2,
  8532. 'mercoledì' => 3,
  8533. 'giovedì' => 4,
  8534. 'venerdì' => 5,
  8535. 'sabato' => 6,
  8536. 'domenica' => 7,
  8537. // Spanish
  8538. 'lunes' => 1,
  8539. 'martes' => 2,
  8540. 'miércoles' => 3,
  8541. 'jueves' => 4,
  8542. 'viernes' => 5,
  8543. 'sábado' => 6,
  8544. 'domingo' => 7,
  8545. // Finnish
  8546. 'maanantai' => 1,
  8547. 'tiistai' => 2,
  8548. 'keskiviikko' => 3,
  8549. 'torstai' => 4,
  8550. 'perjantai' => 5,
  8551. 'lauantai' => 6,
  8552. 'sunnuntai' => 7,
  8553. // Hungarian
  8554. 'hétfő' => 1,
  8555. 'kedd' => 2,
  8556. 'szerda' => 3,
  8557. 'csütörtok' => 4,
  8558. 'péntek' => 5,
  8559. 'szombat' => 6,
  8560. 'vasárnap' => 7,
  8561. // Greek
  8562. 'Δευ' => 1,
  8563. 'Τρι' => 2,
  8564. 'Τετ' => 3,
  8565. 'Πεμ' => 4,
  8566. 'Παρ' => 5,
  8567. 'Σαβ' => 6,
  8568. 'Κυρ' => 7,
  8569. );
  8570. var $month = array(
  8571. // English
  8572. 'jan' => 1,
  8573. 'january' => 1,
  8574. 'feb' => 2,
  8575. 'february' => 2,
  8576. 'mar' => 3,
  8577. 'march' => 3,
  8578. 'apr' => 4,
  8579. 'april' => 4,
  8580. 'may' => 5,
  8581. // No long form of May
  8582. 'jun' => 6,
  8583. 'june' => 6,
  8584. 'jul' => 7,
  8585. 'july' => 7,
  8586. 'aug' => 8,
  8587. 'august' => 8,
  8588. 'sep' => 9,
  8589. 'september' => 8,
  8590. 'oct' => 10,
  8591. 'october' => 10,
  8592. 'nov' => 11,
  8593. 'november' => 11,
  8594. 'dec' => 12,
  8595. 'december' => 12,
  8596. // Dutch
  8597. 'januari' => 1,
  8598. 'februari' => 2,
  8599. 'maart' => 3,
  8600. 'april' => 4,
  8601. 'mei' => 5,
  8602. 'juni' => 6,
  8603. 'juli' => 7,
  8604. 'augustus' => 8,
  8605. 'september' => 9,
  8606. 'oktober' => 10,
  8607. 'november' => 11,
  8608. 'december' => 12,
  8609. // French
  8610. 'janvier' => 1,
  8611. 'février' => 2,
  8612. 'mars' => 3,
  8613. 'avril' => 4,
  8614. 'mai' => 5,
  8615. 'juin' => 6,
  8616. 'juillet' => 7,
  8617. 'août' => 8,
  8618. 'septembre' => 9,
  8619. 'octobre' => 10,
  8620. 'novembre' => 11,
  8621. 'décembre' => 12,
  8622. // German
  8623. 'januar' => 1,
  8624. 'februar' => 2,
  8625. 'märz' => 3,
  8626. 'april' => 4,
  8627. 'mai' => 5,
  8628. 'juni' => 6,
  8629. 'juli' => 7,
  8630. 'august' => 8,
  8631. 'september' => 9,
  8632. 'oktober' => 10,
  8633. 'november' => 11,
  8634. 'dezember' => 12,
  8635. // Italian
  8636. 'gennaio' => 1,
  8637. 'febbraio' => 2,
  8638. 'marzo' => 3,
  8639. 'aprile' => 4,
  8640. 'maggio' => 5,
  8641. 'giugno' => 6,
  8642. 'luglio' => 7,
  8643. 'agosto' => 8,
  8644. 'settembre' => 9,
  8645. 'ottobre' => 10,
  8646. 'novembre' => 11,
  8647. 'dicembre' => 12,
  8648. // Spanish
  8649. 'enero' => 1,
  8650. 'febrero' => 2,
  8651. 'marzo' => 3,
  8652. 'abril' => 4,
  8653. 'mayo' => 5,
  8654. 'junio' => 6,
  8655. 'julio' => 7,
  8656. 'agosto' => 8,
  8657. 'septiembre' => 9,
  8658. 'setiembre' => 9,
  8659. 'octubre' => 10,
  8660. 'noviembre' => 11,
  8661. 'diciembre' => 12,
  8662. // Finnish
  8663. 'tammikuu' => 1,
  8664. 'helmikuu' => 2,
  8665. 'maaliskuu' => 3,
  8666. 'huhtikuu' => 4,
  8667. 'toukokuu' => 5,
  8668. 'kesäkuu' => 6,
  8669. 'heinäkuu' => 7,
  8670. 'elokuu' => 8,
  8671. 'suuskuu' => 9,
  8672. 'lokakuu' => 10,
  8673. 'marras' => 11,
  8674. 'joulukuu' => 12,
  8675. // Hungarian
  8676. 'január' => 1,
  8677. 'február' => 2,
  8678. 'március' => 3,
  8679. 'április' => 4,
  8680. 'május' => 5,
  8681. 'június' => 6,
  8682. 'július' => 7,
  8683. 'augusztus' => 8,
  8684. 'szeptember' => 9,
  8685. 'október' => 10,
  8686. 'november' => 11,
  8687. 'december' => 12,
  8688. // Greek
  8689. 'Ιαν' => 1,
  8690. 'Φεβ' => 2,
  8691. 'Μάώ' => 3,
  8692. 'Μαώ' => 3,
  8693. 'Απρ' => 4,
  8694. 'Μάι' => 5,
  8695. 'Μαϊ' => 5,
  8696. 'Μαι' => 5,
  8697. 'Ιούν' => 6,
  8698. 'Ιον' => 6,
  8699. 'Ιούλ' => 7,
  8700. 'Ιολ' => 7,
  8701. 'Αύγ' => 8,
  8702. 'Αυγ' => 8,
  8703. 'Σεπ' => 9,
  8704. 'Οκτ' => 10,
  8705. 'Νοέ' => 11,
  8706. 'Δεκ' => 12,
  8707. );
  8708. var $timezone = array(
  8709. 'ACDT' => 37800,
  8710. 'ACIT' => 28800,
  8711. 'ACST' => 34200,
  8712. 'ACT' => -18000,
  8713. 'ACWDT' => 35100,
  8714. 'ACWST' => 31500,
  8715. 'AEDT' => 39600,
  8716. 'AEST' => 36000,
  8717. 'AFT' => 16200,
  8718. 'AKDT' => -28800,
  8719. 'AKST' => -32400,
  8720. 'AMDT' => 18000,
  8721. 'AMT' => -14400,
  8722. 'ANAST' => 46800,
  8723. 'ANAT' => 43200,
  8724. 'ART' => -10800,
  8725. 'AZOST' => -3600,
  8726. 'AZST' => 18000,
  8727. 'AZT' => 14400,
  8728. 'BIOT' => 21600,
  8729. 'BIT' => -43200,
  8730. 'BOT' => -14400,
  8731. 'BRST' => -7200,
  8732. 'BRT' => -10800,
  8733. 'BST' => 3600,
  8734. 'BTT' => 21600,
  8735. 'CAST' => 18000,
  8736. 'CAT' => 7200,
  8737. 'CCT' => 23400,
  8738. 'CDT' => -18000,
  8739. 'CEDT' => 7200,
  8740. 'CET' => 3600,
  8741. 'CGST' => -7200,
  8742. 'CGT' => -10800,
  8743. 'CHADT' => 49500,
  8744. 'CHAST' => 45900,
  8745. 'CIST' => -28800,
  8746. 'CKT' => -36000,
  8747. 'CLDT' => -10800,
  8748. 'CLST' => -14400,
  8749. 'COT' => -18000,
  8750. 'CST' => -21600,
  8751. 'CVT' => -3600,
  8752. 'CXT' => 25200,
  8753. 'DAVT' => 25200,
  8754. 'DTAT' => 36000,
  8755. 'EADT' => -18000,
  8756. 'EAST' => -21600,
  8757. 'EAT' => 10800,
  8758. 'ECT' => -18000,
  8759. 'EDT' => -14400,
  8760. 'EEST' => 10800,
  8761. 'EET' => 7200,
  8762. 'EGT' => -3600,
  8763. 'EKST' => 21600,
  8764. 'EST' => -18000,
  8765. 'FJT' => 43200,
  8766. 'FKDT' => -10800,
  8767. 'FKST' => -14400,
  8768. 'FNT' => -7200,
  8769. 'GALT' => -21600,
  8770. 'GEDT' => 14400,
  8771. 'GEST' => 10800,
  8772. 'GFT' => -10800,
  8773. 'GILT' => 43200,
  8774. 'GIT' => -32400,
  8775. 'GST' => 14400,
  8776. 'GST' => -7200,
  8777. 'GYT' => -14400,
  8778. 'HAA' => -10800,
  8779. 'HAC' => -18000,
  8780. 'HADT' => -32400,
  8781. 'HAE' => -14400,
  8782. 'HAP' => -25200,
  8783. 'HAR' => -21600,
  8784. 'HAST' => -36000,
  8785. 'HAT' => -9000,
  8786. 'HAY' => -28800,
  8787. 'HKST' => 28800,
  8788. 'HMT' => 18000,
  8789. 'HNA' => -14400,
  8790. 'HNC' => -21600,
  8791. 'HNE' => -18000,
  8792. 'HNP' => -28800,
  8793. 'HNR' => -25200,
  8794. 'HNT' => -12600,
  8795. 'HNY' => -32400,
  8796. 'IRDT' => 16200,
  8797. 'IRKST' => 32400,
  8798. 'IRKT' => 28800,
  8799. 'IRST' => 12600,
  8800. 'JFDT' => -10800,
  8801. 'JFST' => -14400,
  8802. 'JST' => 32400,
  8803. 'KGST' => 21600,
  8804. 'KGT' => 18000,
  8805. 'KOST' => 39600,
  8806. 'KOVST' => 28800,
  8807. 'KOVT' => 25200,
  8808. 'KRAST' => 28800,
  8809. 'KRAT' => 25200,
  8810. 'KST' => 32400,
  8811. 'LHDT' => 39600,
  8812. 'LHST' => 37800,
  8813. 'LINT' => 50400,
  8814. 'LKT' => 21600,
  8815. 'MAGST' => 43200,
  8816. 'MAGT' => 39600,
  8817. 'MAWT' => 21600,
  8818. 'MDT' => -21600,
  8819. 'MESZ' => 7200,
  8820. 'MEZ' => 3600,
  8821. 'MHT' => 43200,
  8822. 'MIT' => -34200,
  8823. 'MNST' => 32400,
  8824. 'MSDT' => 14400,
  8825. 'MSST' => 10800,
  8826. 'MST' => -25200,
  8827. 'MUT' => 14400,
  8828. 'MVT' => 18000,
  8829. 'MYT' => 28800,
  8830. 'NCT' => 39600,
  8831. 'NDT' => -9000,
  8832. 'NFT' => 41400,
  8833. 'NMIT' => 36000,
  8834. 'NOVST' => 25200,
  8835. 'NOVT' => 21600,
  8836. 'NPT' => 20700,
  8837. 'NRT' => 43200,
  8838. 'NST' => -12600,
  8839. 'NUT' => -39600,
  8840. 'NZDT' => 46800,
  8841. 'NZST' => 43200,
  8842. 'OMSST' => 25200,
  8843. 'OMST' => 21600,
  8844. 'PDT' => -25200,
  8845. 'PET' => -18000,
  8846. 'PETST' => 46800,
  8847. 'PETT' => 43200,
  8848. 'PGT' => 36000,
  8849. 'PHOT' => 46800,
  8850. 'PHT' => 28800,
  8851. 'PKT' => 18000,
  8852. 'PMDT' => -7200,
  8853. 'PMST' => -10800,
  8854. 'PONT' => 39600,
  8855. 'PST' => -28800,
  8856. 'PWT' => 32400,
  8857. 'PYST' => -10800,
  8858. 'PYT' => -14400,
  8859. 'RET' => 14400,
  8860. 'ROTT' => -10800,
  8861. 'SAMST' => 18000,
  8862. 'SAMT' => 14400,
  8863. 'SAST' => 7200,
  8864. 'SBT' => 39600,
  8865. 'SCDT' => 46800,
  8866. 'SCST' => 43200,
  8867. 'SCT' => 14400,
  8868. 'SEST' => 3600,
  8869. 'SGT' => 28800,
  8870. 'SIT' => 28800,
  8871. 'SRT' => -10800,
  8872. 'SST' => -39600,
  8873. 'SYST' => 10800,
  8874. 'SYT' => 7200,
  8875. 'TFT' => 18000,
  8876. 'THAT' => -36000,
  8877. 'TJT' => 18000,
  8878. 'TKT' => -36000,
  8879. 'TMT' => 18000,
  8880. 'TOT' => 46800,
  8881. 'TPT' => 32400,
  8882. 'TRUT' => 36000,
  8883. 'TVT' => 43200,
  8884. 'TWT' => 28800,
  8885. 'UYST' => -7200,
  8886. 'UYT' => -10800,
  8887. 'UZT' => 18000,
  8888. 'VET' => -14400,
  8889. 'VLAST' => 39600,
  8890. 'VLAT' => 36000,
  8891. 'VOST' => 21600,
  8892. 'VUT' => 39600,
  8893. 'WAST' => 7200,
  8894. 'WAT' => 3600,
  8895. 'WDT' => 32400,
  8896. 'WEST' => 3600,
  8897. 'WFT' => 43200,
  8898. 'WIB' => 25200,
  8899. 'WIT' => 32400,
  8900. 'WITA' => 28800,
  8901. 'WKST' => 18000,
  8902. 'WST' => 28800,
  8903. 'YAKST' => 36000,
  8904. 'YAKT' => 32400,
  8905. 'YAPT' => 36000,
  8906. 'YEKST' => 21600,
  8907. 'YEKT' => 18000,
  8908. );
  8909. var $day_pcre;
  8910. var $month_pcre;
  8911. var $built_in = array();
  8912. var $user = array();
  8913. public function __construct() {
  8914. $this->day_pcre = '(' . implode(array_keys($this->day), '|') . ')';
  8915. $this->month_pcre = '(' . implode(array_keys($this->month), '|') . ')';
  8916. static $cache;
  8917. if (!isset($cache[get_class($this)])) {
  8918. $all_methods = get_class_methods($this);
  8919. foreach ($all_methods as $method) {
  8920. if (strtolower(substr($method, 0, 5)) === 'date_') {
  8921. $cache[get_class($this)][] = $method;
  8922. }
  8923. }
  8924. }
  8925. foreach ($cache[get_class($this)] as $method) {
  8926. $this->built_in[] = $method;
  8927. }
  8928. }
  8929. public static function get() {
  8930. static $object;
  8931. if (!$object) {
  8932. $object = new SimplePie_Parse_Date;
  8933. }
  8934. return $object;
  8935. }
  8936. public function parse($date) {
  8937. foreach ($this->user as $method) {
  8938. if (($returned = call_user_func($method, $date)) !== false) {
  8939. return $returned;
  8940. }
  8941. }
  8942. foreach ($this->built_in as $method) {
  8943. if (($returned = call_user_func(array($this, $method), $date)) !== false) {
  8944. return $returned;
  8945. }
  8946. }
  8947. return false;
  8948. }
  8949. public function add_callback($callback) {
  8950. if (is_callable($callback)) {
  8951. $this->user[] = $callback;
  8952. }
  8953. else {
  8954. trigger_error('User-supplied function must be a valid callback', E_USER_WARNING);
  8955. }
  8956. }
  8957. public function date_w3cdtf($date) {
  8958. static $pcre;
  8959. if (!$pcre) {
  8960. $year = '([0-9]{4})';
  8961. $month = $day = $hour = $minute = $second = '([0-9]{2})';
  8962. $decimal = '([0-9]*)';
  8963. $zone = '(?:(Z)|([+\-])([0-9]{1,2}):?([0-9]{1,2}))';
  8964. $pcre = '/^' . $year . '(?:-?' . $month . '(?:-?' . $day . '(?:[Tt\x09\x20]+' . $hour . '(?::?' . $minute . '(?::?' . $second . '(?:.' . $decimal . ')?)?)?' . $zone . ')?)?)?$/';
  8965. }
  8966. if (preg_match($pcre, $date, $match)) {
  8967. /*
  8968. Capturing subpatterns:
  8969. 1: Year
  8970. 2: Month
  8971. 3: Day
  8972. 4: Hour
  8973. 5: Minute
  8974. 6: Second
  8975. 7: Decimal fraction of a second
  8976. 8: Zulu
  8977. 9: Timezone ±
  8978. 10: Timezone hours
  8979. 11: Timezone minutes
  8980. */
  8981. // Fill in empty matches
  8982. for ($i = count($match); $i <= 3; $i++) {
  8983. $match[$i] = '1';
  8984. }
  8985. for ($i = count($match); $i <= 7; $i++) {
  8986. $match[$i] = '0';
  8987. }
  8988. // Numeric timezone
  8989. if (isset($match[9]) && $match[9] !== '') {
  8990. $timezone = $match[10] * 3600;
  8991. $timezone += $match[11] * 60;
  8992. if ($match[9] === '-') {
  8993. $timezone = 0 - $timezone;
  8994. }
  8995. }
  8996. else {
  8997. $timezone = 0;
  8998. }
  8999. // Convert the number of seconds to an integer, taking decimals into account
  9000. $second = round($match[6] + $match[7] / pow(10, strlen($match[7])));
  9001. return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone;
  9002. }
  9003. else {
  9004. return false;
  9005. }
  9006. }
  9007. public function remove_rfc2822_comments($string) {
  9008. $string = (string) $string;
  9009. $position = 0;
  9010. $length = strlen($string);
  9011. $depth = 0;
  9012. $output = '';
  9013. while ($position < $length && ($pos = strpos($string, '(', $position)) !== false) {
  9014. $output .= substr($string, $position, $pos - $position);
  9015. $position = $pos + 1;
  9016. if ($string[$pos - 1] !== '\\') {
  9017. $depth++;
  9018. while ($depth && $position < $length) {
  9019. $position += strcspn($string, '()', $position);
  9020. if ($string[$position - 1] === '\\') {
  9021. $position++;
  9022. continue;
  9023. }
  9024. elseif (isset($string[$position])) {
  9025. switch ($string[$position]) {
  9026. case '(':
  9027. $depth++;
  9028. break;
  9029. case ')':
  9030. $depth--;
  9031. break;
  9032. }
  9033. $position++;
  9034. }
  9035. else {
  9036. break;
  9037. }
  9038. }
  9039. }
  9040. else {
  9041. $output .= '(';
  9042. }
  9043. }
  9044. $output .= substr($string, $position);
  9045. return $output;
  9046. }
  9047. public function date_rfc2822($date) {
  9048. static $pcre;
  9049. if (!$pcre) {
  9050. $wsp = '[\x09\x20]';
  9051. $fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)';
  9052. $optional_fws = $fws . '?';
  9053. $day_name = $this->day_pcre;
  9054. $month = $this->month_pcre;
  9055. $day = '([0-9]{1,2})';
  9056. $hour = $minute = $second = '([0-9]{2})';
  9057. $year = '([0-9]{2,4})';
  9058. $num_zone = '([+\-])([0-9]{2})([0-9]{2})';
  9059. $character_zone = '([A-Z]{1,5})';
  9060. $zone = '(?:' . $num_zone . '|' . $character_zone . ')';
  9061. $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';
  9062. }
  9063. if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match)) {
  9064. /*
  9065. Capturing subpatterns:
  9066. 1: Day name
  9067. 2: Day
  9068. 3: Month
  9069. 4: Year
  9070. 5: Hour
  9071. 6: Minute
  9072. 7: Second
  9073. 8: Timezone ±
  9074. 9: Timezone hours
  9075. 10: Timezone minutes
  9076. 11: Alphabetic timezone
  9077. */
  9078. // Find the month number
  9079. $month = $this->month[strtolower($match[3])];
  9080. // Numeric timezone
  9081. if ($match[8] !== '') {
  9082. $timezone = $match[9] * 3600;
  9083. $timezone += $match[10] * 60;
  9084. if ($match[8] === '-') {
  9085. $timezone = 0 - $timezone;
  9086. }
  9087. }
  9088. // Character timezone
  9089. elseif (isset($this->timezone[strtoupper($match[11])])) {
  9090. $timezone = $this->timezone[strtoupper($match[11])];
  9091. }
  9092. // Assume everything else to be -0000
  9093. else {
  9094. $timezone = 0;
  9095. }
  9096. // Deal with 2/3 digit years
  9097. if ($match[4] < 50) {
  9098. $match[4] += 2000;
  9099. }
  9100. elseif ($match[4] < 1000) {
  9101. $match[4] += 1900;
  9102. }
  9103. // Second is optional, if it is empty set it to zero
  9104. if ($match[7] !== '') {
  9105. $second = $match[7];
  9106. }
  9107. else {
  9108. $second = 0;
  9109. }
  9110. return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone;
  9111. }
  9112. else {
  9113. return false;
  9114. }
  9115. }
  9116. public function date_rfc850($date) {
  9117. static $pcre;
  9118. if (!$pcre) {
  9119. $space = '[\x09\x20]+';
  9120. $day_name = $this->day_pcre;
  9121. $month = $this->month_pcre;
  9122. $day = '([0-9]{1,2})';
  9123. $year = $hour = $minute = $second = '([0-9]{2})';
  9124. $zone = '([A-Z]{1,5})';
  9125. $pcre = '/^' . $day_name . ',' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i';
  9126. }
  9127. if (preg_match($pcre, $date, $match)) {
  9128. /*
  9129. Capturing subpatterns:
  9130. 1: Day name
  9131. 2: Day
  9132. 3: Month
  9133. 4: Year
  9134. 5: Hour
  9135. 6: Minute
  9136. 7: Second
  9137. 8: Timezone
  9138. */
  9139. // Month
  9140. $month = $this->month[strtolower($match[3])];
  9141. // Character timezone
  9142. if (isset($this->timezone[strtoupper($match[8])])) {
  9143. $timezone = $this->timezone[strtoupper($match[8])];
  9144. }
  9145. // Assume everything else to be -0000
  9146. else {
  9147. $timezone = 0;
  9148. }
  9149. // Deal with 2 digit year
  9150. if ($match[4] < 50) {
  9151. $match[4] += 2000;
  9152. }
  9153. else {
  9154. $match[4] += 1900;
  9155. }
  9156. return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone;
  9157. }
  9158. else {
  9159. return false;
  9160. }
  9161. }
  9162. public function date_asctime($date) {
  9163. static $pcre;
  9164. if (!$pcre) {
  9165. $space = '[\x09\x20]+';
  9166. $wday_name = $this->day_pcre;
  9167. $mon_name = $this->month_pcre;
  9168. $day = '([0-9]{1,2})';
  9169. $hour = $sec = $min = '([0-9]{2})';
  9170. $year = '([0-9]{4})';
  9171. $terminator = '\x0A?\x00?';
  9172. $pcre = '/^' . $wday_name . $space . $mon_name . $space . $day . $space . $hour . ':' . $min . ':' . $sec . $space . $year . $terminator . '$/i';
  9173. }
  9174. if (preg_match($pcre, $date, $match)) {
  9175. /*
  9176. Capturing subpatterns:
  9177. 1: Day name
  9178. 2: Month
  9179. 3: Day
  9180. 4: Hour
  9181. 5: Minute
  9182. 6: Second
  9183. 7: Year
  9184. */
  9185. $month = $this->month[strtolower($match[2])];
  9186. return gmmktime($match[4], $match[5], $match[6], $month, $match[3], $match[7]);
  9187. }
  9188. else {
  9189. return false;
  9190. }
  9191. }
  9192. public function date_strtotime($date) {
  9193. $strtotime = strtotime($date);
  9194. if ($strtotime === -1 || $strtotime === false) {
  9195. return false;
  9196. }
  9197. else {
  9198. return $strtotime;
  9199. }
  9200. }
  9201. }
  9202. class SimplePie_Parser {
  9203. var $error_code;
  9204. var $error_string;
  9205. var $current_line;
  9206. var $current_column;
  9207. var $current_byte;
  9208. var $separator = ' ';
  9209. var $namespace = array('');
  9210. var $element = array('');
  9211. var $xml_base = array('');
  9212. var $xml_base_explicit = array(false);
  9213. var $xml_lang = array('');
  9214. var $data = array();
  9215. var $datas = array(array());
  9216. var $current_xhtml_construct = -1;
  9217. var $encoding;
  9218. protected $registry;
  9219. public function set_registry(SimplePie_Registry $registry) {
  9220. $this->registry = $registry;
  9221. }
  9222. public function parse(&$data, $encoding) {
  9223. // Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
  9224. if (strtoupper($encoding) === 'US-ASCII') {
  9225. $this->encoding = 'UTF-8';
  9226. }
  9227. else {
  9228. $this->encoding = $encoding;
  9229. }
  9230. // Strip BOM:
  9231. // UTF-32 Big Endian BOM
  9232. if (substr($data, 0, 4) === "\x00\x00\xFE\xFF") {
  9233. $data = substr($data, 4);
  9234. }
  9235. // UTF-32 Little Endian BOM
  9236. elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00") {
  9237. $data = substr($data, 4);
  9238. }
  9239. // UTF-16 Big Endian BOM
  9240. elseif (substr($data, 0, 2) === "\xFE\xFF") {
  9241. $data = substr($data, 2);
  9242. }
  9243. // UTF-16 Little Endian BOM
  9244. elseif (substr($data, 0, 2) === "\xFF\xFE") {
  9245. $data = substr($data, 2);
  9246. }
  9247. // UTF-8 BOM
  9248. elseif (substr($data, 0, 3) === "\xEF\xBB\xBF") {
  9249. $data = substr($data, 3);
  9250. }
  9251. if (substr($data, 0, 5) === '<?xml' && strspn(substr($data, 5, 1), "\x09\x0A\x0D\x20") && ($pos = strpos($data, '?>')) !== false) {
  9252. $declaration = $this->registry->create('XML_Declaration_Parser', array(substr($data, 5, $pos - 5)));
  9253. if ($declaration->parse()) {
  9254. $data = substr($data, $pos + 2);
  9255. $data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' . $data;
  9256. }
  9257. else {
  9258. $this->error_string = 'SimplePie bug! Please report this!';
  9259. return false;
  9260. }
  9261. }
  9262. $return = true;
  9263. static $xml_is_sane = null;
  9264. if ($xml_is_sane === null) {
  9265. $parser_check = xml_parser_create();
  9266. xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
  9267. xml_parser_free($parser_check);
  9268. $xml_is_sane = isset($values[0]['value']);
  9269. }
  9270. // Create the parser
  9271. if ($xml_is_sane) {
  9272. $xml = xml_parser_create_ns($this->encoding, $this->separator);
  9273. xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
  9274. xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0);
  9275. xml_set_object($xml, $this);
  9276. xml_set_character_data_handler($xml, 'cdata');
  9277. xml_set_element_handler($xml, 'tag_open', 'tag_close');
  9278. // Parse!
  9279. if (!xml_parse($xml, $data, true)) {
  9280. $this->error_code = xml_get_error_code($xml);
  9281. $this->error_string = xml_error_string($this->error_code);
  9282. $return = false;
  9283. }
  9284. $this->current_line = xml_get_current_line_number($xml);
  9285. $this->current_column = xml_get_current_column_number($xml);
  9286. $this->current_byte = xml_get_current_byte_index($xml);
  9287. xml_parser_free($xml);
  9288. return $return;
  9289. }
  9290. else {
  9291. libxml_clear_errors();
  9292. $xml = new XMLReader();
  9293. $xml->xml($data);
  9294. while (@$xml->read()) {
  9295. switch ($xml->nodeType) {
  9296. case constant('XMLReader::END_ELEMENT'):
  9297. if ($xml->namespaceURI !== '') {
  9298. $tagName = $xml->namespaceURI . $this->separator . $xml->localName;
  9299. }
  9300. else {
  9301. $tagName = $xml->localName;
  9302. }
  9303. $this->tag_close(null, $tagName);
  9304. break;
  9305. case constant('XMLReader::ELEMENT'):
  9306. $empty = $xml->isEmptyElement;
  9307. if ($xml->namespaceURI !== '') {
  9308. $tagName = $xml->namespaceURI . $this->separator . $xml->localName;
  9309. }
  9310. else {
  9311. $tagName = $xml->localName;
  9312. }
  9313. $attributes = array();
  9314. while ($xml->moveToNextAttribute()) {
  9315. if ($xml->namespaceURI !== '') {
  9316. $attrName = $xml->namespaceURI . $this->separator . $xml->localName;
  9317. }
  9318. else {
  9319. $attrName = $xml->localName;
  9320. }
  9321. $attributes[$attrName] = $xml->value;
  9322. }
  9323. $this->tag_open(null, $tagName, $attributes);
  9324. if ($empty) {
  9325. $this->tag_close(null, $tagName);
  9326. }
  9327. break;
  9328. case constant('XMLReader::TEXT'):
  9329. case constant('XMLReader::CDATA'):
  9330. $this->cdata(null, $xml->value);
  9331. break;
  9332. }
  9333. }
  9334. if ($error = libxml_get_last_error()) {
  9335. $this->error_code = $error->code;
  9336. $this->error_string = $error->message;
  9337. $this->current_line = $error->line;
  9338. $this->current_column = $error->column;
  9339. return false;
  9340. }
  9341. else {
  9342. return true;
  9343. }
  9344. }
  9345. }
  9346. public function get_error_code() {
  9347. return $this->error_code;
  9348. }
  9349. public function get_error_string() {
  9350. return $this->error_string;
  9351. }
  9352. public function get_current_line() {
  9353. return $this->current_line;
  9354. }
  9355. public function get_current_column() {
  9356. return $this->current_column;
  9357. }
  9358. public function get_current_byte() {
  9359. return $this->current_byte;
  9360. }
  9361. public function get_data() {
  9362. return $this->data;
  9363. }
  9364. public function tag_open($parser, $tag, $attributes) {
  9365. list($this->namespace[], $this->element[]) = $this->split_ns($tag);
  9366. $attribs = array();
  9367. foreach ($attributes as $name => $value) {
  9368. list($attrib_namespace, $attribute) = $this->split_ns($name);
  9369. $attribs[$attrib_namespace][$attribute] = $value;
  9370. }
  9371. if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['base'])) {
  9372. $this->xml_base[] = $this->registry->call('Misc', 'absolutize_url', array($attribs[SIMPLEPIE_NAMESPACE_XML]['base'], end($this->xml_base)));
  9373. $this->xml_base_explicit[] = true;
  9374. }
  9375. else {
  9376. $this->xml_base[] = end($this->xml_base);
  9377. $this->xml_base_explicit[] = end($this->xml_base_explicit);
  9378. }
  9379. if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['lang'])) {
  9380. $this->xml_lang[] = $attribs[SIMPLEPIE_NAMESPACE_XML]['lang'];
  9381. }
  9382. else {
  9383. $this->xml_lang[] = end($this->xml_lang);
  9384. }
  9385. if ($this->current_xhtml_construct >= 0) {
  9386. $this->current_xhtml_construct++;
  9387. if (end($this->namespace) === SIMPLEPIE_NAMESPACE_XHTML) {
  9388. $this->data['data'] .= '<' . end($this->element);
  9389. if (isset($attribs[''])) {
  9390. foreach ($attribs[''] as $name => $value) {
  9391. $this->data['data'] .= ' ' . $name . '="' . htmlspecialchars($value, ENT_COMPAT, $this->encoding) . '"';
  9392. }
  9393. }
  9394. $this->data['data'] .= '>';
  9395. }
  9396. }
  9397. else {
  9398. $this->datas[] =& $this->data;
  9399. $this->data =& $this->data['child'][end($this->namespace)][end($this->element)][];
  9400. $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));
  9401. 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')
  9402. || (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')
  9403. || (end($this->namespace) === SIMPLEPIE_NAMESPACE_RSS_20 && in_array(end($this->element), array('title')))
  9404. || (end($this->namespace) === SIMPLEPIE_NAMESPACE_RSS_090 && in_array(end($this->element), array('title')))
  9405. || (end($this->namespace) === SIMPLEPIE_NAMESPACE_RSS_10 && in_array(end($this->element), array('title')))) {
  9406. $this->current_xhtml_construct = 0;
  9407. }
  9408. }
  9409. }
  9410. public function cdata($parser, $cdata) {
  9411. if ($this->current_xhtml_construct >= 0) {
  9412. $this->data['data'] .= htmlspecialchars($cdata, ENT_QUOTES, $this->encoding);
  9413. }
  9414. else {
  9415. $this->data['data'] .= $cdata;
  9416. }
  9417. }
  9418. public function tag_close($parser, $tag) {
  9419. if ($this->current_xhtml_construct >= 0) {
  9420. $this->current_xhtml_construct--;
  9421. 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'))) {
  9422. $this->data['data'] .= '</' . end($this->element) . '>';
  9423. }
  9424. }
  9425. if ($this->current_xhtml_construct === -1) {
  9426. $this->data =& $this->datas[count($this->datas) - 1];
  9427. array_pop($this->datas);
  9428. }
  9429. array_pop($this->element);
  9430. array_pop($this->namespace);
  9431. array_pop($this->xml_base);
  9432. array_pop($this->xml_base_explicit);
  9433. array_pop($this->xml_lang);
  9434. }
  9435. public function split_ns($string) {
  9436. static $cache = array();
  9437. if (!isset($cache[$string])) {
  9438. if ($pos = strpos($string, $this->separator)) {
  9439. static $separator_length;
  9440. if (!$separator_length) {
  9441. $separator_length = strlen($this->separator);
  9442. }
  9443. $namespace = substr($string, 0, $pos);
  9444. $local_name = substr($string, $pos + $separator_length);
  9445. if (strtolower($namespace) === SIMPLEPIE_NAMESPACE_ITUNES) {
  9446. $namespace = SIMPLEPIE_NAMESPACE_ITUNES;
  9447. }
  9448. // Normalize the Media RSS namespaces
  9449. if ($namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG ||
  9450. $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2 ||
  9451. $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3 ||
  9452. $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4 ||
  9453. $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5 ) {
  9454. $namespace = SIMPLEPIE_NAMESPACE_MEDIARSS;
  9455. }
  9456. $cache[$string] = array($namespace, $local_name);
  9457. }
  9458. else {
  9459. $cache[$string] = array('', $string);
  9460. }
  9461. }
  9462. return $cache[$string];
  9463. }
  9464. }
  9465. class SimplePie_Rating {
  9466. var $scheme;
  9467. var $value;
  9468. public function __construct($scheme = null, $value = null) {
  9469. $this->scheme = $scheme;
  9470. $this->value = $value;
  9471. }
  9472. public function __toString() {
  9473. // There is no $this->data here
  9474. return md5(serialize($this));
  9475. }
  9476. public function get_scheme() {
  9477. if ($this->scheme !== null) {
  9478. return $this->scheme;
  9479. }
  9480. else {
  9481. return null;
  9482. }
  9483. }
  9484. public function get_value() {
  9485. if ($this->value !== null) {
  9486. return $this->value;
  9487. }
  9488. else {
  9489. return null;
  9490. }
  9491. }
  9492. }
  9493. class SimplePie_Registry {
  9494. protected $default = array(
  9495. 'Cache' => 'SimplePie_Cache',
  9496. 'Locator' => 'SimplePie_Locator',
  9497. 'Parser' => 'SimplePie_Parser',
  9498. 'File' => 'SimplePie_File',
  9499. 'Sanitize' => 'SimplePie_Sanitize',
  9500. 'Item' => 'SimplePie_Item',
  9501. 'Author' => 'SimplePie_Author',
  9502. 'Category' => 'SimplePie_Category',
  9503. 'Enclosure' => 'SimplePie_Enclosure',
  9504. 'Caption' => 'SimplePie_Caption',
  9505. 'Copyright' => 'SimplePie_Copyright',
  9506. 'Credit' => 'SimplePie_Credit',
  9507. 'Rating' => 'SimplePie_Rating',
  9508. 'Restriction' => 'SimplePie_Restriction',
  9509. 'Content_Type_Sniffer' => 'SimplePie_Content_Type_Sniffer',
  9510. 'Source' => 'SimplePie_Source',
  9511. 'Misc' => 'SimplePie_Misc',
  9512. 'XML_Declaration_Parser' => 'SimplePie_XML_Declaration_Parser',
  9513. 'Parse_Date' => 'SimplePie_Parse_Date',
  9514. );
  9515. protected $classes = array();
  9516. protected $legacy = array();
  9517. public function __construct() { }
  9518. public function register($type, $class, $legacy = false) {
  9519. if (!is_subclass_of($class, $this->default[$type])) {
  9520. return false;
  9521. }
  9522. $this->classes[$type] = $class;
  9523. if ($legacy) {
  9524. $this->legacy[] = $class;
  9525. }
  9526. return true;
  9527. }
  9528. public function get_class($type) {
  9529. if (!empty($this->classes[$type])) {
  9530. return $this->classes[$type];
  9531. }
  9532. if (!empty($this->default[$type])) {
  9533. return $this->default[$type];
  9534. }
  9535. return null;
  9536. }
  9537. public function &create($type, $parameters = array()) {
  9538. $class = $this->get_class($type);
  9539. if (in_array($class, $this->legacy)) {
  9540. switch ($type) {
  9541. case 'locator':
  9542. // Legacy: file, timeout, useragent, file_class, max_checked_feeds, content_type_sniffer_class
  9543. // Specified: file, timeout, useragent, max_checked_feeds
  9544. $replacement = array($this->get_class('file'), $parameters[3], $this->get_class('content_type_sniffer'));
  9545. array_splice($parameters, 3, 1, $replacement);
  9546. break;
  9547. }
  9548. }
  9549. if (!method_exists($class, '__construct')) {
  9550. $instance = new $class;
  9551. }
  9552. else {
  9553. $reflector = new ReflectionClass($class);
  9554. $instance = $reflector->newInstanceArgs($parameters);
  9555. }
  9556. if (method_exists($instance, 'set_registry')) {
  9557. $instance->set_registry($this);
  9558. }
  9559. return $instance;
  9560. }
  9561. public function &call($type, $method, $parameters = array()) {
  9562. $class = $this->get_class($type);
  9563. $result = call_user_func_array(array($class, $method), $parameters);
  9564. return $result;
  9565. }
  9566. }
  9567. class SimplePie_Restriction {
  9568. var $relationship;
  9569. var $type;
  9570. var $value;
  9571. public function __construct($relationship = null, $type = null, $value = null) {
  9572. $this->relationship = $relationship;
  9573. $this->type = $type;
  9574. $this->value = $value;
  9575. }
  9576. public function __toString() {
  9577. // There is no $this->data here
  9578. return md5(serialize($this));
  9579. }
  9580. public function get_relationship() {
  9581. if ($this->relationship !== null) {
  9582. return $this->relationship;
  9583. }
  9584. else {
  9585. return null;
  9586. }
  9587. }
  9588. public function get_type() {
  9589. if ($this->type !== null) {
  9590. return $this->type;
  9591. }
  9592. else {
  9593. return null;
  9594. }
  9595. }
  9596. public function get_value() {
  9597. if ($this->value !== null) {
  9598. return $this->value;
  9599. }
  9600. else {
  9601. return null;
  9602. }
  9603. }
  9604. }
  9605. class SimplePie_Sanitize {
  9606. // Private vars
  9607. var $base;
  9608. // Options
  9609. var $remove_div = true;
  9610. var $image_handler = '';
  9611. var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  9612. var $encode_instead_of_strip = false;
  9613. var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
  9614. var $strip_comments = false;
  9615. var $output_encoding = 'UTF-8';
  9616. var $enable_cache = true;
  9617. var $cache_location = './cache';
  9618. var $cache_name_function = 'md5';
  9619. var $timeout = 10;
  9620. var $useragent = '';
  9621. var $force_fsockopen = false;
  9622. var $replace_url_attributes = null;
  9623. public function __construct() {
  9624. // Set defaults
  9625. $this->set_url_replacements(null);
  9626. }
  9627. public function remove_div($enable = true) {
  9628. $this->remove_div = (bool) $enable;
  9629. }
  9630. public function set_image_handler($page = false) {
  9631. if ($page) {
  9632. $this->image_handler = (string) $page;
  9633. }
  9634. else {
  9635. $this->image_handler = false;
  9636. }
  9637. }
  9638. public function set_registry(SimplePie_Registry $registry) {
  9639. $this->registry = $registry;
  9640. }
  9641. public function pass_cache_data($enable_cache = true, $cache_location = './cache', $cache_name_function = 'md5', $cache_class = 'SimplePie_Cache') {
  9642. if (isset($enable_cache)) {
  9643. $this->enable_cache = (bool) $enable_cache;
  9644. }
  9645. if ($cache_location) {
  9646. $this->cache_location = (string) $cache_location;
  9647. }
  9648. if ($cache_name_function) {
  9649. $this->cache_name_function = (string) $cache_name_function;
  9650. }
  9651. }
  9652. public function pass_file_data($file_class = 'SimplePie_File', $timeout = 10, $useragent = '', $force_fsockopen = false) {
  9653. if ($timeout) {
  9654. $this->timeout = (string) $timeout;
  9655. }
  9656. if ($useragent) {
  9657. $this->useragent = (string) $useragent;
  9658. }
  9659. if ($force_fsockopen) {
  9660. $this->force_fsockopen = (string) $force_fsockopen;
  9661. }
  9662. }
  9663. 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')) {
  9664. if ($tags) {
  9665. if (is_array($tags)) {
  9666. $this->strip_htmltags = $tags;
  9667. }
  9668. else {
  9669. $this->strip_htmltags = explode(',', $tags);
  9670. }
  9671. }
  9672. else {
  9673. $this->strip_htmltags = false;
  9674. }
  9675. }
  9676. public function encode_instead_of_strip($encode = false) {
  9677. $this->encode_instead_of_strip = (bool) $encode;
  9678. }
  9679. public function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc')) {
  9680. if ($attribs) {
  9681. if (is_array($attribs)) {
  9682. $this->strip_attributes = $attribs;
  9683. }
  9684. else {
  9685. $this->strip_attributes = explode(',', $attribs);
  9686. }
  9687. }
  9688. else {
  9689. $this->strip_attributes = false;
  9690. }
  9691. }
  9692. public function strip_comments($strip = false) {
  9693. $this->strip_comments = (bool) $strip;
  9694. }
  9695. public function set_output_encoding($encoding = 'UTF-8') {
  9696. $this->output_encoding = (string) $encoding;
  9697. }
  9698. public function set_url_replacements($element_attribute = null) {
  9699. if ($element_attribute === null) {
  9700. $element_attribute = array(
  9701. 'a' => 'href',
  9702. 'area' => 'href',
  9703. 'blockquote' => 'cite',
  9704. 'del' => 'cite',
  9705. 'form' => 'action',
  9706. 'img' => array(
  9707. 'longdesc',
  9708. 'src'
  9709. ),
  9710. 'input' => 'src',
  9711. 'ins' => 'cite',
  9712. 'q' => 'cite'
  9713. );
  9714. }
  9715. $this->replace_url_attributes = (array) $element_attribute;
  9716. }
  9717. public function sanitize($data, $type, $base = '') {
  9718. $data = trim($data);
  9719. if ($data !== '' || $type & SIMPLEPIE_CONSTRUCT_IRI) {
  9720. if ($type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML) {
  9721. 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)) {
  9722. $type |= SIMPLEPIE_CONSTRUCT_HTML;
  9723. }
  9724. else {
  9725. $type |= SIMPLEPIE_CONSTRUCT_TEXT;
  9726. }
  9727. }
  9728. if ($type & SIMPLEPIE_CONSTRUCT_BASE64) {
  9729. $data = base64_decode($data);
  9730. }
  9731. if ($type & (SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML)) {
  9732. $document = new DOMDocument();
  9733. $document->encoding = 'UTF-8';
  9734. $data = $this->preprocess($data, $type);
  9735. set_error_handler(array('SimplePie_Misc', 'silence_errors'));
  9736. $document->loadHTML($data);
  9737. restore_error_handler();
  9738. // Strip comments
  9739. if ($this->strip_comments) {
  9740. $xpath = new DOMXPath($document);
  9741. $comments = $xpath->query('//comment()');
  9742. foreach ($comments as $comment) {
  9743. $comment->parentNode->removeChild($comment);
  9744. }
  9745. }
  9746. // Strip out HTML tags and attributes that might cause various security problems.
  9747. // Based on recommendations by Mark Pilgrim at:
  9748. // http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely
  9749. if ($this->strip_htmltags) {
  9750. foreach ($this->strip_htmltags as $tag) {
  9751. $this->strip_tag($tag, $document, $type);
  9752. }
  9753. }
  9754. if ($this->strip_attributes) {
  9755. foreach ($this->strip_attributes as $attrib) {
  9756. $this->strip_attr($attrib, $document);
  9757. }
  9758. }
  9759. // Replace relative URLs
  9760. $this->base = $base;
  9761. foreach ($this->replace_url_attributes as $element => $attributes) {
  9762. $this->replace_urls($document, $element, $attributes);
  9763. }
  9764. // If image handling (caching, etc.) is enabled, cache and rewrite all the image tags.
  9765. if (isset($this->image_handler) && ((string) $this->image_handler) !== '' && $this->enable_cache) {
  9766. $images = $document->getElementsByTagName('img');
  9767. foreach ($images as $img) {
  9768. if ($img->hasAttribute('src')) {
  9769. $image_url = call_user_func($this->cache_name_function, $img->getAttribute('src'));
  9770. $cache = $this->registry->call('Cache', 'create', array($this->cache_location, $image_url, 'spi'));
  9771. if ($cache->load()) {
  9772. $img->setAttribute('src', $this->image_handler . $image_url);
  9773. }
  9774. else {
  9775. $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));
  9776. $headers = $file->headers;
  9777. if ($file->success && ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300))) {
  9778. if ($cache->save(array('headers' => $file->headers, 'body' => $file->body))) {
  9779. $img->setAttribute('src', $this->image_handler . $image_url);
  9780. }
  9781. else {
  9782. 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);
  9783. }
  9784. }
  9785. }
  9786. }
  9787. }
  9788. }
  9789. // Remove the DOCTYPE
  9790. // Seems to cause segfaulting if we don't do this
  9791. if ($document->firstChild instanceof DOMDocumentType) {
  9792. $document->removeChild($document->firstChild);
  9793. }
  9794. // Move everything from the body to the root
  9795. $real_body = $document->getElementsByTagName('body')->item(0)->childNodes->item(0);
  9796. $document->replaceChild($real_body, $document->firstChild);
  9797. // Finally, convert to a HTML string
  9798. $data = trim($document->saveHTML());
  9799. if ($this->remove_div) {
  9800. $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '', $data);
  9801. $data = preg_replace('/<\/div>$/', '', $data);
  9802. }
  9803. else {
  9804. $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '<div>', $data);
  9805. }
  9806. }
  9807. if ($type & SIMPLEPIE_CONSTRUCT_IRI) {
  9808. $data = $this->registry->call('Misc', 'absolutize_url', array($data, $base));
  9809. }
  9810. if ($type & (SIMPLEPIE_CONSTRUCT_TEXT | SIMPLEPIE_CONSTRUCT_IRI)) {
  9811. $data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
  9812. }
  9813. if ($this->output_encoding !== 'UTF-8') {
  9814. $data = $this->registry->call('Misc', 'change_encoding', array($data, 'UTF-8', $this->output_encoding));
  9815. }
  9816. }
  9817. return $data;
  9818. }
  9819. protected function preprocess($html, $type) {
  9820. $ret = '';
  9821. if ($type & ~SIMPLEPIE_CONSTRUCT_XHTML) {
  9822. // Atom XHTML constructs are wrapped with a div by default
  9823. // Note: No protection if $html contains a stray </div>!
  9824. $html = '<div>' . $html . '</div>';
  9825. $ret .= '<!DOCTYPE html>';
  9826. $content_type = 'text/html';
  9827. }
  9828. else {
  9829. $ret .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
  9830. $content_type = 'application/xhtml+xml';
  9831. }
  9832. $ret .= '<html><head>';
  9833. $ret .= '<meta http-equiv="Content-Type" content="' . $content_type . '; charset=utf-8" />';
  9834. $ret .= '</head><body>' . $html . '</body></html>';
  9835. return $ret;
  9836. }
  9837. public function replace_urls($document, $tag, $attributes) {
  9838. if (!is_array($attributes)) {
  9839. $attributes = array($attributes);
  9840. }
  9841. if (!is_array($this->strip_htmltags) || !in_array($tag, $this->strip_htmltags)) {
  9842. $elements = $document->getElementsByTagName($tag);
  9843. foreach ($elements as $element) {
  9844. foreach ($attributes as $attribute) {
  9845. if ($element->hasAttribute($attribute)) {
  9846. $value = $this->registry->call('Misc', 'absolutize_url', array($element->getAttribute($attribute), $this->base));
  9847. $element->setAttribute($attribute, $value);
  9848. }
  9849. }
  9850. }
  9851. }
  9852. }
  9853. public function do_strip_htmltags($match) {
  9854. if ($this->encode_instead_of_strip) {
  9855. if (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style'))) {
  9856. $match[1] = htmlspecialchars($match[1], ENT_COMPAT, 'UTF-8');
  9857. $match[2] = htmlspecialchars($match[2], ENT_COMPAT, 'UTF-8');
  9858. return "&lt;$match[1]$match[2]&gt;$match[3]&lt;/$match[1]&gt;";
  9859. }
  9860. else {
  9861. return htmlspecialchars($match[0], ENT_COMPAT, 'UTF-8');
  9862. }
  9863. }
  9864. elseif (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style'))) {
  9865. return $match[4];
  9866. }
  9867. else {
  9868. return '';
  9869. }
  9870. }
  9871. protected function strip_tag($tag, $document, $type) {
  9872. $xpath = new DOMXPath($document);
  9873. $elements = $xpath->query('body//' . $tag);
  9874. if ($this->encode_instead_of_strip) {
  9875. foreach ($elements as $element) {
  9876. $fragment = $document->createDocumentFragment();
  9877. // For elements which aren't script or style, include the tag itself
  9878. if (!in_array($tag, array('script', 'style'))) {
  9879. $text = '<' . $tag;
  9880. if ($element->hasAttributes()) {
  9881. $attrs = array();
  9882. foreach ($element->attributes as $name => $attr) {
  9883. $value = $attr->value;
  9884. // In XHTML, empty values should never exist, so we repeat the value
  9885. if (empty($value) && ($type & SIMPLEPIE_CONSTRUCT_XHTML)) {
  9886. $value = $name;
  9887. }
  9888. // For HTML, empty is fine
  9889. elseif (empty($value) && ($type & SIMPLEPIE_CONSTRUCT_HTML)) {
  9890. $attrs[] = $name;
  9891. continue;
  9892. }
  9893. // Standard attribute text
  9894. $attrs[] = $name . '="' . $attr->value . '"';
  9895. }
  9896. $text .= ' ' . implode(' ', $attrs);
  9897. }
  9898. $text .= '>';
  9899. $fragment->appendChild(new DOMText($text));
  9900. }
  9901. $number = $element->childNodes->length;
  9902. for ($i = $number; $i > 0; $i--) {
  9903. $child = $element->childNodes->item(0);
  9904. $fragment->appendChild($child);
  9905. }
  9906. if (!in_array($tag, array('script', 'style'))) {
  9907. $fragment->appendChild(new DOMText('</' . $tag . '>'));
  9908. }
  9909. $element->parentNode->replaceChild($fragment, $element);
  9910. }
  9911. return;
  9912. }
  9913. elseif (in_array($tag, array('script', 'style'))) {
  9914. foreach ($elements as $element) {
  9915. $element->parentNode->removeChild($element);
  9916. }
  9917. return;
  9918. }
  9919. else {
  9920. foreach ($elements as $element) {
  9921. $fragment = $document->createDocumentFragment();
  9922. $number = $element->childNodes->length;
  9923. for ($i = $number; $i > 0; $i--) {
  9924. $child = $element->childNodes->item(0);
  9925. $fragment->appendChild($child);
  9926. }
  9927. $element->parentNode->replaceChild($fragment, $element);
  9928. }
  9929. }
  9930. }
  9931. protected function strip_attr($attrib, $document) {
  9932. $xpath = new DOMXPath($document);
  9933. $elements = $xpath->query('//*[@' . $attrib . ']');
  9934. foreach ($elements as $element) {
  9935. $element->removeAttribute($attrib);
  9936. }
  9937. }
  9938. }
  9939. class SimplePie_Source {
  9940. var $item;
  9941. var $data = array();
  9942. protected $registry;
  9943. public function __construct($item, $data) {
  9944. $this->item = $item;
  9945. $this->data = $data;
  9946. }
  9947. public function set_registry(SimplePie_Registry $registry) {
  9948. $this->registry = $registry;
  9949. }
  9950. public function __toString() {
  9951. return md5(serialize($this->data));
  9952. }
  9953. public function get_source_tags($namespace, $tag) {
  9954. if (isset($this->data['child'][$namespace][$tag])) {
  9955. return $this->data['child'][$namespace][$tag];
  9956. }
  9957. else {
  9958. return null;
  9959. }
  9960. }
  9961. public function get_base($element = array()) {
  9962. return $this->item->get_base($element);
  9963. }
  9964. public function sanitize($data, $type, $base = '') {
  9965. return $this->item->sanitize($data, $type, $base);
  9966. }
  9967. public function get_item() {
  9968. return $this->item;
  9969. }
  9970. public function get_title() {
  9971. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title')) {
  9972. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  9973. }
  9974. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title')) {
  9975. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  9976. }
  9977. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) {
  9978. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  9979. }
  9980. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) {
  9981. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  9982. }
  9983. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) {
  9984. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  9985. }
  9986. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) {
  9987. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  9988. }
  9989. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) {
  9990. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  9991. }
  9992. else {
  9993. return null;
  9994. }
  9995. }
  9996. public function get_category($key = 0) {
  9997. $categories = $this->get_categories();
  9998. if (isset($categories[$key])) {
  9999. return $categories[$key];
  10000. }
  10001. else {
  10002. return null;
  10003. }
  10004. }
  10005. public function get_categories() {
  10006. $categories = array();
  10007. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category) {
  10008. $term = null;
  10009. $scheme = null;
  10010. $label = null;
  10011. if (isset($category['attribs']['']['term'])) {
  10012. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  10013. }
  10014. if (isset($category['attribs']['']['scheme'])) {
  10015. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  10016. }
  10017. if (isset($category['attribs']['']['label'])) {
  10018. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  10019. }
  10020. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  10021. }
  10022. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category) {
  10023. // This is really the label, but keep this as the term also for BC.
  10024. // Label will also work on retrieving because that falls back to term.
  10025. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  10026. if (isset($category['attribs']['']['domain'])) {
  10027. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  10028. }
  10029. else {
  10030. $scheme = null;
  10031. }
  10032. $categories[] = $this->registry->create('Category', array($term, $scheme, null));
  10033. }
  10034. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category) {
  10035. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  10036. }
  10037. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category) {
  10038. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  10039. }
  10040. if (!empty($categories)) {
  10041. return array_unique($categories);
  10042. }
  10043. else {
  10044. return null;
  10045. }
  10046. }
  10047. public function get_author($key = 0) {
  10048. $authors = $this->get_authors();
  10049. if (isset($authors[$key])) {
  10050. return $authors[$key];
  10051. }
  10052. else {
  10053. return null;
  10054. }
  10055. }
  10056. public function get_authors() {
  10057. $authors = array();
  10058. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author) {
  10059. $name = null;
  10060. $uri = null;
  10061. $email = null;
  10062. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) {
  10063. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  10064. }
  10065. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) {
  10066. $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]));
  10067. }
  10068. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) {
  10069. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  10070. }
  10071. if ($name !== null || $email !== null || $uri !== null) {
  10072. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  10073. }
  10074. }
  10075. if ($author = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author')) {
  10076. $name = null;
  10077. $url = null;
  10078. $email = null;
  10079. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) {
  10080. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  10081. }
  10082. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) {
  10083. $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]));
  10084. }
  10085. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) {
  10086. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  10087. }
  10088. if ($name !== null || $email !== null || $url !== null) {
  10089. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  10090. }
  10091. }
  10092. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author) {
  10093. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  10094. }
  10095. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author) {
  10096. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  10097. }
  10098. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author) {
  10099. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  10100. }
  10101. if (!empty($authors)) {
  10102. return array_unique($authors);
  10103. }
  10104. else {
  10105. return null;
  10106. }
  10107. }
  10108. public function get_contributor($key = 0) {
  10109. $contributors = $this->get_contributors();
  10110. if (isset($contributors[$key])) {
  10111. return $contributors[$key];
  10112. }
  10113. else {
  10114. return null;
  10115. }
  10116. }
  10117. public function get_contributors() {
  10118. $contributors = array();
  10119. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor) {
  10120. $name = null;
  10121. $uri = null;
  10122. $email = null;
  10123. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) {
  10124. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  10125. }
  10126. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) {
  10127. $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]));
  10128. }
  10129. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) {
  10130. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  10131. }
  10132. if ($name !== null || $email !== null || $uri !== null) {
  10133. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  10134. }
  10135. }
  10136. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor) {
  10137. $name = null;
  10138. $url = null;
  10139. $email = null;
  10140. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) {
  10141. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  10142. }
  10143. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) {
  10144. $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]));
  10145. }
  10146. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) {
  10147. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  10148. }
  10149. if ($name !== null || $email !== null || $url !== null) {
  10150. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  10151. }
  10152. }
  10153. if (!empty($contributors)) {
  10154. return array_unique($contributors);
  10155. }
  10156. else {
  10157. return null;
  10158. }
  10159. }
  10160. public function get_link($key = 0, $rel = 'alternate') {
  10161. $links = $this->get_links($rel);
  10162. if (isset($links[$key])) {
  10163. return $links[$key];
  10164. }
  10165. else {
  10166. return null;
  10167. }
  10168. }
  10169. public function get_permalink() {
  10170. return $this->get_link(0);
  10171. }
  10172. public function get_links($rel = 'alternate') {
  10173. if (!isset($this->data['links'])) {
  10174. $this->data['links'] = array();
  10175. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link')) {
  10176. foreach ($links as $link) {
  10177. if (isset($link['attribs']['']['href'])) {
  10178. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  10179. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  10180. }
  10181. }
  10182. }
  10183. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link')) {
  10184. foreach ($links as $link) {
  10185. if (isset($link['attribs']['']['href'])) {
  10186. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  10187. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  10188. }
  10189. }
  10190. }
  10191. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) {
  10192. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  10193. }
  10194. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) {
  10195. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  10196. }
  10197. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) {
  10198. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  10199. }
  10200. $keys = array_keys($this->data['links']);
  10201. foreach ($keys as $key) {
  10202. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key))) {
  10203. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key])) {
  10204. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  10205. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  10206. }
  10207. else {
  10208. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  10209. }
  10210. }
  10211. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) {
  10212. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  10213. }
  10214. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  10215. }
  10216. }
  10217. if (isset($this->data['links'][$rel])) {
  10218. return $this->data['links'][$rel];
  10219. }
  10220. else {
  10221. return null;
  10222. }
  10223. }
  10224. public function get_description() {
  10225. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle')) {
  10226. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  10227. }
  10228. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline')) {
  10229. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  10230. }
  10231. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) {
  10232. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  10233. }
  10234. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) {
  10235. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  10236. }
  10237. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) {
  10238. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  10239. }
  10240. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) {
  10241. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  10242. }
  10243. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) {
  10244. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  10245. }
  10246. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) {
  10247. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  10248. }
  10249. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) {
  10250. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  10251. }
  10252. else {
  10253. return null;
  10254. }
  10255. }
  10256. public function get_copyright() {
  10257. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights')) {
  10258. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  10259. }
  10260. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright')) {
  10261. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  10262. }
  10263. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright')) {
  10264. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  10265. }
  10266. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights')) {
  10267. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  10268. }
  10269. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights')) {
  10270. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  10271. }
  10272. else {
  10273. return null;
  10274. }
  10275. }
  10276. public function get_language() {
  10277. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language')) {
  10278. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  10279. }
  10280. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language')) {
  10281. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  10282. }
  10283. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language')) {
  10284. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  10285. }
  10286. elseif (isset($this->data['xml_lang'])) {
  10287. return $this->sanitize($this->data['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  10288. }
  10289. else {
  10290. return null;
  10291. }
  10292. }
  10293. public function get_latitude() {
  10294. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat')) {
  10295. return (float) $return[0]['data'];
  10296. }
  10297. 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)) {
  10298. return (float) $match[1];
  10299. }
  10300. else {
  10301. return null;
  10302. }
  10303. }
  10304. public function get_longitude() {
  10305. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long')) {
  10306. return (float) $return[0]['data'];
  10307. }
  10308. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon')) {
  10309. return (float) $return[0]['data'];
  10310. }
  10311. 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)) {
  10312. return (float) $match[2];
  10313. }
  10314. else {
  10315. return null;
  10316. }
  10317. }
  10318. public function get_image_url() {
  10319. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image')) {
  10320. return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
  10321. }
  10322. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo')) {
  10323. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  10324. }
  10325. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon')) {
  10326. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  10327. }
  10328. else {
  10329. return null;
  10330. }
  10331. }
  10332. }
  10333. class SimplePie_XML_Declaration_Parser {
  10334. var $version = '1.0';
  10335. var $encoding = 'UTF-8';
  10336. var $standalone = false;
  10337. var $state = 'before_version_name';
  10338. var $data = '';
  10339. var $data_length = 0;
  10340. var $position = 0;
  10341. public function __construct($data) {
  10342. $this->data = $data;
  10343. $this->data_length = strlen($this->data);
  10344. }
  10345. public function parse() {
  10346. while ($this->state && $this->state !== 'emit' && $this->has_data()) {
  10347. $state = $this->state;
  10348. $this->$state();
  10349. }
  10350. $this->data = '';
  10351. if ($this->state === 'emit') {
  10352. return true;
  10353. }
  10354. else {
  10355. $this->version = '';
  10356. $this->encoding = '';
  10357. $this->standalone = '';
  10358. return false;
  10359. }
  10360. }
  10361. public function has_data() {
  10362. return (bool) ($this->position < $this->data_length);
  10363. }
  10364. public function skip_whitespace() {
  10365. $whitespace = strspn($this->data, "\x09\x0A\x0D\x20", $this->position);
  10366. $this->position += $whitespace;
  10367. return $whitespace;
  10368. }
  10369. public function get_value() {
  10370. $quote = substr($this->data, $this->position, 1);
  10371. if ($quote === '"' || $quote === "'") {
  10372. $this->position++;
  10373. $len = strcspn($this->data, $quote, $this->position);
  10374. if ($this->has_data()) {
  10375. $value = substr($this->data, $this->position, $len);
  10376. $this->position += $len + 1;
  10377. return $value;
  10378. }
  10379. }
  10380. return false;
  10381. }
  10382. public function before_version_name() {
  10383. if ($this->skip_whitespace()) {
  10384. $this->state = 'version_name';
  10385. }
  10386. else {
  10387. $this->state = false;
  10388. }
  10389. }
  10390. public function version_name() {
  10391. if (substr($this->data, $this->position, 7) === 'version') {
  10392. $this->position += 7;
  10393. $this->skip_whitespace();
  10394. $this->state = 'version_equals';
  10395. }
  10396. else {
  10397. $this->state = false;
  10398. }
  10399. }
  10400. public function version_equals() {
  10401. if (substr($this->data, $this->position, 1) === '=') {
  10402. $this->position++;
  10403. $this->skip_whitespace();
  10404. $this->state = 'version_value';
  10405. }
  10406. else {
  10407. $this->state = false;
  10408. }
  10409. }
  10410. public function version_value() {
  10411. if ($this->version = $this->get_value()) {
  10412. $this->skip_whitespace();
  10413. if ($this->has_data()) {
  10414. $this->state = 'encoding_name';
  10415. }
  10416. else {
  10417. $this->state = 'emit';
  10418. }
  10419. }
  10420. else {
  10421. $this->state = false;
  10422. }
  10423. }
  10424. public function encoding_name() {
  10425. if (substr($this->data, $this->position, 8) === 'encoding') {
  10426. $this->position += 8;
  10427. $this->skip_whitespace();
  10428. $this->state = 'encoding_equals';
  10429. }
  10430. else {
  10431. $this->state = 'standalone_name';
  10432. }
  10433. }
  10434. public function encoding_equals() {
  10435. if (substr($this->data, $this->position, 1) === '=') {
  10436. $this->position++;
  10437. $this->skip_whitespace();
  10438. $this->state = 'encoding_value';
  10439. }
  10440. else {
  10441. $this->state = false;
  10442. }
  10443. }
  10444. public function encoding_value() {
  10445. if ($this->encoding = $this->get_value()) {
  10446. $this->skip_whitespace();
  10447. if ($this->has_data()) {
  10448. $this->state = 'standalone_name';
  10449. }
  10450. else {
  10451. $this->state = 'emit';
  10452. }
  10453. }
  10454. else {
  10455. $this->state = false;
  10456. }
  10457. }
  10458. public function standalone_name() {
  10459. if (substr($this->data, $this->position, 10) === 'standalone') {
  10460. $this->position += 10;
  10461. $this->skip_whitespace();
  10462. $this->state = 'standalone_equals';
  10463. }
  10464. else {
  10465. $this->state = false;
  10466. }
  10467. }
  10468. public function standalone_equals() {
  10469. if (substr($this->data, $this->position, 1) === '=') {
  10470. $this->position++;
  10471. $this->skip_whitespace();
  10472. $this->state = 'standalone_value';
  10473. }
  10474. else {
  10475. $this->state = false;
  10476. }
  10477. }
  10478. public function standalone_value() {
  10479. if ($standalone = $this->get_value()) {
  10480. switch ($standalone) {
  10481. case 'yes':
  10482. $this->standalone = true;
  10483. break;
  10484. case 'no':
  10485. $this->standalone = false;
  10486. break;
  10487. default:
  10488. $this->state = false;
  10489. return;
  10490. }
  10491. $this->skip_whitespace();
  10492. if ($this->has_data()) {
  10493. $this->state = false;
  10494. }
  10495. else {
  10496. $this->state = 'emit';
  10497. }
  10498. }
  10499. else {
  10500. $this->state = false;
  10501. }
  10502. }
  10503. }