A tumblelog CMS built on AJAX, PHP and MySQL.

simplepie.class.php 135KB

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