1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549 |
- <?php
- /****************************************************
- SIMPLEPIE
- A PHP-Based RSS and Atom Feed Framework
- Takes the hard work out of managing a complete RSS/Atom solution.
-
- Version: "Lemon Meringue"
- Updated: 24 November 2006
- Copyright: 2004-2006 Ryan Parman, Geoffrey Sneddon
- http://simplepie.org
-
- *****************************************************
- LICENSE:
-
- GNU Lesser General Public License 2.1 (LGPL)
- http://creativecommons.org/licenses/LGPL/2.1/
-
- *****************************************************
- Please submit all bug reports and feature requests to the SimplePie forums.
- http://simplepie.org/support/
-
- ****************************************************/
-
- class SimplePie
- {
- // SimplePie Info
- public $name = 'SimplePie';
- public $version = '1.0 b3.2';
- public $build = '20061124';
- public $url = 'http://simplepie.org/';
- public $useragent;
- public $linkback;
-
- // Other objects, instances created here so we can set options on them
- public $sanitize;
-
- // Options
- public $rss_url;
- public $file;
- public $timeout = 10;
- public $xml_dump = false;
- public $enable_cache = true;
- public $max_minutes = 60;
- public $cache_location = './cache';
- public $order_by_date = true;
- public $input_encoding = false;
- public $cache_class = 'SimplePie_Cache';
- public $locator_class = 'SimplePie_Locator';
- public $parser_class = 'SimplePie_Parser';
- public $file_class = 'SimplePie_File';
- public $force_fsockopen = false;
- public $cache_name_type = 'sha1';
-
- // Misc. variables
- public $data;
- public $error;
-
- public function __construct($feed_url = null, $cache_location = null, $cache_max_minutes = null)
- {
- // Couple of variables built up from other variables
- $this->useragent = $this->name . '/' . $this->version . ' (Feed Parser; ' . $this->url . '; Allow like Gecko) Build/' . $this->build;
- $this->linkback = '<a href="' . $this->url . '" title="' . $this->name . ' ' . $this->version . '">' . $this->name . '</a>';
-
- // Other objects, instances created here so we can set options on them
- $this->sanitize = new SimplePie_Sanitize;
-
- // Set options if they're passed to the constructor
- if (!is_null($feed_url)) {
- $this->feed_url($feed_url);
- }
-
- if (!is_null($cache_location)) {
- $this->cache_location($cache_location);
- }
-
- if (!is_null($cache_max_minutes)) {
- $this->cache_max_minutes($cache_max_minutes);
- }
-
- // If we've passed an xmldump variable in the URL, snap into XMLdump mode
- if (isset($_GET['xmldump'])) {
- $this->enable_xmldump(true);
- }
-
- // Only init the script if we're passed a feed URL
- if (!is_null($feed_url)) {
- return $this->init();
- }
- }
-
- public function feed_url($url)
- {
- $this->rss_url = SimplePie_Misc::fix_protocol($url, 1);
- }
-
- public function set_file(&$file)
- {
- if (is_a($file, 'SimplePie_File')) {
- $this->rss_url = $file->url;
- $this->file =& $file;
- }
- }
-
- public function set_timeout($timeout = 10)
- {
- $this->timeout = (int) $timeout;
- }
-
- public function set_raw_data($data)
- {
- $this->raw_data = trim((string) $data);
- }
-
- public function enable_xmldump($enable = false)
- {
- $this->xml_dump = (bool) $enable;
- }
-
- public function enable_caching($enable = true)
- {
- $this->enable_cache = (bool) $enable;
- }
-
- public function cache_max_minutes($minutes = 60)
- {
- $this->max_minutes = (float) $minutes;
- }
-
- public function cache_location($location = './cache')
- {
- $this->cache_location = (string) $location;
- }
-
- public function order_by_date($enable = true)
- {
- $this->order_by_date = (bool) $enable;
- }
-
- public function input_encoding($encoding = false)
- {
- if ($encoding) {
- $this->input_encoding = (string) $encoding;
- } else {
- $this->input_encoding = false;
- }
- }
-
- public function set_cache_class($class = 'SimplePie_Cache')
- {
- if (SimplePie_Misc::is_a_class($class, 'SimplePie_Cache')) {
- $this->cache_class = $class;
- return true;
- }
- return false;
- }
-
- public function set_locator_class($class = 'SimplePie_Locator')
- {
- if (SimplePie_Misc::is_a_class($class, 'SimplePie_Locator')) {
- $this->locator_class = $class;
- return true;
- }
- return false;
- }
-
- public function set_parser_class($class = 'SimplePie_Parser')
- {
- if (SimplePie_Misc::is_a_class($class, 'SimplePie_Parser')) {
- $this->parser_class = $class;
- return true;
- }
- return false;
- }
-
- public function set_file_class($class = 'SimplePie_File')
- {
- if (SimplePie_Misc::is_a_class($class, 'SimplePie_File')) {
- $this->file_class = $class;
- return true;
- }
- return false;
- }
-
- public function set_sanitize_class($object = 'SimplePie_Sanitize')
- {
- if (class_exists($object)) {
- $this->sanitize = new $object;
- return true;
- }
- return false;
- }
-
- public function set_useragent($ua)
- {
- $this->useragent = (string) $ua;
- }
-
- public function force_fsockopen($enable = false)
- {
- $this->force_fsockopen = (bool) $enable;
- }
-
- public function set_cache_name_type($type = 'sha1')
- {
- $type = strtolower(trim($type));
- switch ($type) {
- case 'crc32':
- $this->cache_name_type = 'crc32';
- break;
-
- case 'md5':
- $this->cache_name_type = 'md5';
- break;
-
- case 'rawurlencode':
- $this->cache_name_type = 'rawurlencode';
- break;
-
- case 'urlencode':
- $this->cache_name_type = 'urlencode';
- break;
-
- default:
- $this->cache_name_type = 'sha1';
- break;
- }
- }
-
- public function bypass_image_hotlink($get = false)
- {
- $this->sanitize->bypass_image_hotlink($get);
- }
-
- public function bypass_image_hotlink_page($page = false)
- {
- $this->sanitize->bypass_image_hotlink_page($page);
- }
-
- public function replace_headers($enable = false)
- {
- $this->sanitize->replace_headers($enable);
- }
-
- public function remove_div($enable = true)
- {
- $this->sanitize->remove_div($enable);
- }
-
- public function strip_ads($enable = false)
- {
- $this->sanitize->strip_ads($enable);
- }
-
- public function strip_htmltags($tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'), $encode = null)
- {
- $this->sanitize->strip_htmltags($tags);
- if (!is_null($encode)) {
- $this->sanitize->encode_instead_of_strip($tags);
- }
- }
-
- public function encode_instead_of_strip($enable = true)
- {
- $this->sanitize->encode_instead_of_strip($enable);
- }
-
- public function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur'))
- {
- $this->sanitize->strip_attributes($attribs);
- }
-
- public function output_encoding($encoding = 'UTF-8')
- {
- $this->sanitize->output_encoding($encoding);
- }
-
- public function set_item_class($class = 'SimplePie_Item')
- {
- return $this->sanitize->set_item_class($class);
- }
-
- public function set_author_class($class = 'SimplePie_Author')
- {
- return $this->sanitize->set_author_class($class);
- }
-
- public function set_enclosure_class($class = 'SimplePie_Enclosure')
- {
- return $this->sanitize->set_enclosure_class($class);
- }
-
- public function init()
- {
- 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')) {
- return false;
- }
- if ($this->sanitize->bypass_image_hotlink && !empty($_GET[$this->sanitize->bypass_image_hotlink])) {
- if (get_magic_quotes_gpc()) {
- $_GET[$this->sanitize->bypass_image_hotlink] = stripslashes($_GET[$this->sanitize->bypass_image_hotlink]);
- }
- SimplePie_Misc::display_file($_GET[$this->sanitize->bypass_image_hotlink], 10, $this->useragent);
- }
-
- if (isset($_GET['js'])) {
- $embed = <<<EOT
- function embed_odeo(link) {
- 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>');
- }
-
- function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {
- if (placeholder != '') {
- 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>');
- }
- else {
- 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>');
- }
- }
-
- function embed_flash(bgcolor, width, height, link, loop, type) {
- 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>');
- }
-
- function embed_wmedia(width, height, link) {
- document.writeln('<embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>');
- }
- EOT;
-
- if (function_exists('ob_gzhandler')) {
- ob_start('ob_gzhandler');
- }
- header('Content-type: text/javascript; charset: UTF-8');
- header('Cache-Control: must-revalidate');
- header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 86400) . ' GMT');
- echo $embed;
- exit;
- }
-
- if (!empty($this->rss_url) || !empty($this->raw_data)) {
- $this->data = array();
- $cache = false;
-
- if (!empty($this->rss_url)) {
- // Decide whether to enable caching
- if ($this->enable_cache && preg_match('/^http(s)?:\/\//i', $this->rss_url)) {
- $cache = new $this->cache_class($this->cache_location, call_user_func($this->cache_name_type, $this->rss_url), 'spc');
- }
- // If it's enabled and we don't want an XML dump, use the cache
- if ($cache && !$this->xml_dump) {
- // Load the Cache
- $this->data = $cache->load();
- if (!empty($this->data)) {
- // If we've hit a collision just rerun it with caching disabled
- if (isset($this->data['url']) && $this->data['url'] != $this->rss_url) {
- $cache = false;
- }
- // If we've got a feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL
- elseif (!empty($this->data['feed_url'])) {
- if ($this->data['feed_url'] == $this->data['url']) {
- $cache->unlink();
- } else {
- $this->feed_url($this->data['feed_url']);
- return $this->init();
- }
- }
- // If the cache is new enough
- elseif ($cache->mtime() + $this->max_minutes * 60 < time()) {
- // If we have last-modified and/or etag set
- if (!empty($this->data['last-modified']) || !empty($this->data['etag'])) {
- $headers = array();
- if (!empty($this->data['last-modified'])) {
- $headers['if-modified-since'] = $this->data['last-modified'];
- }
- if (!empty($this->data['etag'])) {
- $headers['if-none-match'] = $this->data['etag'];
- }
- $file = new $this->file_class($this->rss_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen);
- if ($file->success) {
- $headers = $file->headers();
- if ($headers['status']['code'] == 304) {
- $cache->touch();
- return true;
- }
- } else {
- unset($file);
- }
- }
- // If we don't have last-modified or etag set, just clear the cache
- else {
- $cache->unlink();
- }
- }
- // If the cache is still valid, just return true
- else {
- return true;
- }
- }
- // If the cache is empty, delete it
- else {
- $cache->unlink();
- }
- }
- $this->data = array();
- // 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.
- if (!isset($file)) {
- if (is_a($this->file, 'SimplePie_File') && $this->file->url == $this->rss_url) {
- $file =& $this->file;
- } else {
- $file = new $this->file_class($this->rss_url, $this->timeout, 5, null, $this->useragent, $this->force_fsockopen);
- }
- }
- // If the file connection has an error, set SimplePie::error to that and quit
- if (!$file->success) {
- $this->error = $file->error;
- return false;
- }
-
- // Check if the supplied URL is a feed, if it isn't, look for it.
- $locate = new $this->locator_class($file, $this->timeout, $this->useragent);
- if (!$locate->is_feed($file)) {
- $feed = $locate->find();
- if ($feed) {
- if ($cache && !$cache->save(array('url' => $this->rss_url, 'feed_url' => $feed))) {
- $this->error = "$cache->name is not writeable";
- SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
- }
- $this->rss_url = $feed;
- return $this->init();
- } else {
- $this->error = "A feed could not be found at $this->rss_url";
- SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
- return false;
- }
- }
-
- $headers = $file->headers();
- $data = trim($file->body());
- $file->close();
- unset($file);
- } else {
- $data = $this->raw_data;
- }
-
- // First check to see if input has been overridden.
- if (!empty($this->input_encoding)) {
- $encoding = $this->input_encoding;
- }
- // Second try HTTP headers
- elseif (!empty($headers['content-type']) && preg_match('/charset\s*=\s*([^;]*)/i', $headers['content-type'], $charset)) {
- $encoding = $charset[1];
- }
- // Then prolog, if at the very start of the document
- elseif (preg_match('/^<\?xml(.*)?>/msiU', $data, $prolog) && preg_match('/encoding\s*=\s*("([^"]*)"|\'([^\']*)\')/Ui', $prolog[1], $encoding)) {
- $encoding = substr($encoding[1], 1, -1);
- }
- // UTF-32 Big Endian BOM
- elseif (strpos($data, sprintf('%c%c%c%c', 0x00, 0x00, 0xFE, 0xFF)) === 0) {
- $encoding = 'UTF-32be';
- }
- // UTF-32 Little Endian BOM
- elseif (strpos($data, sprintf('%c%c%c%c', 0xFF, 0xFE, 0x00, 0x00)) === 0) {
- $encoding = 'UTF-32';
- }
- // UTF-16 Big Endian BOM
- elseif (strpos($data, sprintf('%c%c', 0xFE, 0xFF)) === 0) {
- $encoding = 'UTF-16be';
- }
- // UTF-16 Little Endian BOM
- elseif (strpos($data, sprintf('%c%c', 0xFF, 0xFE)) === 0) {
- $encoding = 'UTF-16le';
- }
- // UTF-8 BOM
- elseif (strpos($data, sprintf('%c%c%c', 0xEF, 0xBB, 0xBF)) === 0) {
- $encoding = 'UTF-8';
- }
- // Fallback to the default
- else {
- $encoding = null;
- }
-
- // Change the encoding to UTF-8 (as we always use UTF-8 internally)
- $data = SimplePie_Misc::change_encoding($data, $encoding, 'UTF-8');
-
- // Strip illegal characters (if on less than PHP5, as on PHP5 expat can manage fine)
- if (version_compare(phpversion(), '5', '<')) {
- if (function_exists('iconv')) {
- $data = iconv('UTF-8', 'UTF-8//IGNORE', $data);
- } elseif (function_exists('mb_convert_encoding')) {
- $data = mb_convert_encoding($data, 'UTF-8', 'UTF-8');
- } else {
- $data = SimplePie_Misc::utf8_bad_replace($data);
- }
- }
-
- // Start parsing
- $data = new $this->parser_class($data, 'UTF-8', $this->xml_dump);
- // If we want the XML, just output that and quit
- if ($this->xml_dump) {
- header('Content-type: text/xml; charset=UTF-8');
- echo $data->data;
- exit;
- }
- // If it's parsed fine
- elseif (!$data->error_code) {
- // Parse the data, and make it sane
- $this->sanitize->parse_data_array($data->data, $this->rss_url);
- unset($data);
- // Get the sane data
- $this->data['feedinfo'] = $this->sanitize->feedinfo;
- unset($this->sanitize->feedinfo);
- $this->data['info'] = $this->sanitize->info;
- unset($this->sanitize->info);
- $this->data['items'] = $this->sanitize->items;
- unset($this->sanitize->items);
- $this->data['feedinfo']['encoding'] = $this->sanitize->output_encoding;
- $this->data['url'] = $this->rss_url;
-
- // Store the headers that we need
- if (!empty($headers['last-modified'])) {
- $this->data['last-modified'] = $headers['last-modified'];
- }
- if (!empty($headers['etag'])) {
- $this->data['etag'] = $headers['etag'];
- }
-
- // If we want to order it by date, check if all items have a date, and then sort it
- if ($this->order_by_date && !empty($this->data['items'])) {
- $do_sort = true;
- foreach ($this->data['items'] as $item) {
- if (!$item->get_date('U')) {
- $do_sort = false;
- break;
- }
- }
- if ($do_sort) {
- 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;'));
- }
- }
-
- // Cache the file if caching is enabled
- if ($cache && !$cache->save($this->data)) {
- $this->error = "$cache->name is not writeable";
- SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
- }
- return true;
- }
- // If we have an error, just set SimplePie::error to it and quit
- else {
- $this->error = "XML error: $data->error_string at line $data->current_line, column $data->current_column";
- SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
- return false;
- }
- }
- }
-
- public function get_encoding()
- {
- if (!empty($this->data['feedinfo']['encoding'])) {
- return $this->data['feedinfo']['encoding'];
- } else {
- return false;
- }
- }
-
- public function handle_content_type($mime = 'text/html')
- {
- if (!headers_sent()) {
- $header = "Content-type: $mime;";
- if ($this->get_encoding()) {
- $header .= ' charset=' . $this->get_encoding();
- } else {
- $header .= ' charset=UTF-8';
- }
- header($header);
- }
- }
-
- public function get_type()
- {
- if (!empty($this->data['feedinfo']['type'])) {
- return $this->data['feedinfo']['type'];
- } else {
- return false;
- }
- }
-
- public function get_version()
- {
- if (!empty($this->data['feedinfo']['version'])) {
- return $this->data['feedinfo']['version'];
- } else {
- return false;
- }
- }
-
- public function get_favicon($check = false, $alternate = null)
- {
- if (!empty($this->data['info']['link']['alternate'][0])) {
- $favicon = SimplePie_Misc::absolutize_url('/favicon.ico', $this->get_feed_link());
-
- if ($check) {
- $file = new $this->file_class($favicon, $this->timeout/10, 5, null, $this->useragent, $this->force_fsockopen);
- $headers = $file->headers();
- $file->close();
-
- if ($headers['status']['code'] == 200) {
- return $favicon;
- }
- } else {
- return $favicon;
- }
- }
- if (!is_null($alternate)) {
- return $alternate;
- } else {
- return false;
- }
- }
-
- public function subscribe_url()
- {
- if (!empty($this->rss_url)) {
- return $this->rss_url;
- } else {
- return false;
- }
- }
-
- public function subscribe_feed()
- {
- if (!empty($this->rss_url)) {
- return SimplePie_Misc::fix_protocol($this->rss_url, 2);
- } else {
- return false;
- }
- }
-
- public function subscribe_outlook()
- {
- if (!empty($this->rss_url)) {
- return 'outlook' . SimplePie_Misc::fix_protocol($this->rss_url, 2);
- } else {
- return false;
- }
- }
-
- public function subscribe_podcast()
- {
- if (!empty($this->rss_url)) {
- return SimplePie_Misc::fix_protocol($this->rss_url, 3);
- } else {
- return false;
- }
- }
-
- public function subscribe_aol()
- {
- if ($this->subscribe_url()) {
- return 'http://feeds.my.aol.com/add.jsp?url=' . rawurlencode($this->subscribe_url());
- } else {
- return false;
- }
- }
-
- public function subscribe_bloglines()
- {
- if ($this->subscribe_url()) {
- return 'http://www.bloglines.com/sub/' . rawurlencode($this->subscribe_url());
- } else {
- return false;
- }
- }
-
- public function subscribe_eskobo()
- {
- if ($this->subscribe_url()) {
- return 'http://www.eskobo.com/?AddToMyPage=' . rawurlencode($this->subscribe_url());
- } else {
- return false;
- }
- }
-
- public function subscribe_feedfeeds()
- {
- if ($this->subscribe_url()) {
- return 'http://www.feedfeeds.com/add?feed=' . rawurlencode($this->subscribe_url());
- } else {
- return false;
- }
- }
-
- public function subscribe_feedlounge()
- {
- if ($this->subscribe_url()) {
- return 'http://my.feedlounge.com/external/subscribe?url=' . rawurlencode($this->subscribe_url());
- } else {
- return false;
- }
- }
-
- public function subscribe_feedster()
- {
- if ($this->subscribe_url()) {
- return 'http://www.feedster.com/myfeedster.php?action=addrss&confirm=no&rssurl=' . rawurlencode($this->subscribe_url());
- } else {
- return false;
- }
- }
-
- public function subscribe_google()
- {
- if ($this->subscribe_url()) {
- return 'http://fusion.google.com/add?feedurl=' . rawurlencode($this->subscribe_url());
- } else {
- return false;
- }
- }
-
- public function subscribe_gritwire()
- {
- if ($this->subscribe_url()) {
- return 'http://my.gritwire.com/feeds/addExternalFeed.aspx?FeedUrl=' . rawurlencode($this->subscribe_url());
- } else {
- return false;
- }
- }
-
- public function subscribe_msn()
- {
- if ($this->subscribe_url()) {
- $url = 'http://my.msn.com/addtomymsn.armx?id=rss&ut=' . rawurlencode($this->subscribe_url());
- if ($this->get_feed_link()) {
- $url .= '&ru=' . rawurlencode($this->get_feed_link());
- }
- return $url;
- } else {
- return false;
- }
- }
-
- public function subscribe_netvibes()
- {
- if ($this->subscribe_url()) {
- return 'http://www.netvibes.com/subscribe.php?url=' . rawurlencode($this->subscribe_url());
- } else {
- return false;
- }
- }
-
- public function subscribe_newsburst()
- {
- if ($this->subscribe_url()) {
- return 'http://www.newsburst.com/Source/?add=' . rawurlencode($this->subscribe_url());
- } else {
- return false;
- }
- }
-
- public function subscribe_newsgator()
- {
- if ($this->subscribe_url()) {
- return 'http://www.newsgator.com/ngs/subscriber/subext.aspx?url=' . rawurlencode($this->subscribe_url());
- } else {
- return false;
- }
- }
-
- public function subscribe_odeo()
- {
- if ($this->subscribe_url()) {
- return 'http://www.odeo.com/listen/subscribe?feed=' . rawurlencode($this->subscribe_url());
- } else {
- return false;
- }
- }
-
- public function subscribe_pluck()
- {
- if ($this->subscribe_url()) {
- return 'http://client.pluck.com/pluckit/prompt.aspx?GCID=C12286x053&a=' . rawurlencode($this->subscribe_url());
- } else {
- return false;
- }
- }
-
- public function subscribe_podnova()
- {
- if ($this->subscribe_url()) {
- return 'http://www.podnova.com/index_your_podcasts.srf?action=add&url=' . rawurlencode($this->subscribe_url());
- } else {
- return false;
- }
- }
-
- public function subscribe_rojo()
- {
- if ($this->subscribe_url()) {
- return 'http://www.rojo.com/add-subscription?resource=' . rawurlencode($this->subscribe_url());
- } else {
- return false;
- }
- }
-
- public function subscribe_yahoo()
- {
- if ($this->subscribe_url()) {
- return 'http://add.my.yahoo.com/rss?url=' . rawurlencode($this->subscribe_url());
- } else {
- return false;
- }
- }
-
- public function get_feed_title()
- {
- if (!empty($this->data['info']['title'])) {
- return $this->data['info']['title'];
- } else {
- return false;
- }
- }
-
- public function get_feed_link()
- {
- if (!empty($this->data['info']['link']['alternate'][0])) {
- return $this->data['info']['link']['alternate'][0];
- } else {
- return false;
- }
- }
-
- public function get_feed_links()
- {
- if (!empty($this->data['info']['link'])) {
- return $this->data['info']['link'];
- } else {
- return false;
- }
- }
-
- public function get_feed_description()
- {
- if (!empty($this->data['info']['description'])) {
- return $this->data['info']['description'];
- } elseif (!empty($this->data['info']['dc:description'])) {
- return $this->data['info']['dc:description'];
- } elseif (!empty($this->data['info']['tagline'])) {
- return $this->data['info']['tagline'];
- } elseif (!empty($this->data['info']['subtitle'])) {
- return $this->data['info']['subtitle'];
- } else {
- return false;
- }
- }
-
- public function get_feed_copyright()
- {
- if (!empty($this->data['info']['copyright'])) {
- return $this->data['info']['copyright'];
- } else {
- return false;
- }
- }
-
- public function get_feed_language()
- {
- if (!empty($this->data['info']['language'])) {
- return $this->data['info']['language'];
- } elseif (!empty($this->data['info']['xml:lang'])) {
- return $this->data['info']['xml:lang'];
- } else {
- return false;
- }
- }
-
- public function get_image_exist()
- {
- if (!empty($this->data['info']['image']['url']) || !empty($this->data['info']['image']['logo'])) {
- return true;
- } else {
- return false;
- }
- }
-
- public function get_image_title()
- {
- if (!empty($this->data['info']['image']['title'])) {
- return $this->data['info']['image']['title'];
- } else {
- return false;
- }
- }
-
- public function get_image_url()
- {
- if (!empty($this->data['info']['image']['url'])) {
- return $this->data['info']['image']['url'];
- } elseif (!empty($this->data['info']['image']['logo'])) {
- return $this->data['info']['image']['logo'];
- } else {
- return false;
- }
- }
-
- public function get_image_link()
- {
- if (!empty($this->data['info']['image']['link'])) {
- return $this->data['info']['image']['link'];
- } else {
- return false;
- }
- }
-
- public function get_image_width()
- {
- if (!empty($this->data['info']['image']['width'])) {
- return $this->data['info']['image']['width'];
- } else {
- return false;
- }
- }
-
- public function get_image_height()
- {
- if (!empty($this->data['info']['image']['height'])) {
- return $this->data['info']['image']['height'];
- } else {
- return false;
- }
- }
-
- public function get_item_quantity($max = 0)
- {
- if (!empty($this->data['items'])) {
- $qty = sizeof($this->data['items']);
- } else {
- $qty = 0;
- }
- if ($max == 0) {
- return $qty;
- } else {
- return ($qty > $max) ? $max : $qty;
- }
- }
-
- public function get_item($key = 0)
- {
- if (!empty($this->data['items'][$key])) {
- return $this->data['items'][$key];
- } else {
- return false;
- }
- }
-
- public function get_items($start = 0, $end = 0)
- {
- if ($this->get_item_quantity() > 0) {
- if ($end == 0) {
- return array_slice($this->data['items'], $start);
- } else {
- return array_slice($this->data['items'], $start, $end);
- }
- } else {
- return false;
- }
- }
- }
-
- class SimplePie_Item
- {
- public $data;
-
- public function __construct($data)
- {
- $this->data =& $data;
- }
-
- public function get_id()
- {
- if (!empty($this->data['guid']['data'])) {
- return $this->data['guid']['data'];
- } elseif (!empty($this->data['id'])) {
- return $this->data['id'];
- } else {
- return false;
- }
- }
-
- public function get_title()
- {
- if (!empty($this->data['title'])) {
- return $this->data['title'];
- } elseif (!empty($this->data['dc:title'])) {
- return $this->data['dc:title'];
- } else {
- return false;
- }
- }
-
- public function get_description()
- {
- if (!empty($this->data['content'])) {
- return $this->data['content'];
- } elseif (!empty($this->data['encoded'])) {
- return $this->data['encoded'];
- } elseif (!empty($this->data['summary'])) {
- return $this->data['summary'];
- } elseif (!empty($this->data['description'])) {
- return $this->data['description'];
- } elseif (!empty($this->data['dc:description'])) {
- return $this->data['dc:description'];
- } elseif (!empty($this->data['longdesc'])) {
- return $this->data['longdesc'];
- } else {
- return false;
- }
- }
-
- public function get_category($key = 0)
- {
- $categories = $this->get_categories();
- if (!empty($categories[$key])) {
- return $categories[$key];
- } else {
- return false;
- }
- }
-
- public function get_categories()
- {
- $categories = array();
- if (!empty($this->data['category'])) {
- $categories = array_merge($categories, $this->data['category']);
- }
- if (!empty($this->data['subject'])) {
- $categories = array_merge($categories, $this->data['subject']);
- }
- if (!empty($this->data['term'])) {
- $categories = array_merge($categories, $this->data['term']);
- }
- if (!empty($categories)) {
- return array_unique($categories);
- } else {
- return false;
- }
- }
-
- public function get_author($key = 0)
- {
- $authors = $this->get_authors();
- if (!empty($authors[$key])) {
- return $authors[$key];
- } else {
- return false;
- }
- }
-
- public function get_authors()
- {
- $authors = array();
- if (!empty($this->data['author'])) {
- $authors = array_merge($authors, $this->data['author']);
- }
- if (!empty($this->data['creator'])) {
- $authors = array_merge($authors, $this->data['creator']);
- }
- if (!empty($authors)) {
- return array_unique($authors);
- } else {
- return false;
- }
- }
-
- public function get_date($date_format = 'j F Y, g:i a')
- {
- if (!empty($this->data['pubdate'])) {
- return date($date_format, $this->data['pubdate']);
- } elseif (!empty($this->data['dc:date'])) {
- return date($date_format, $this->data['dc:date']);
- } elseif (!empty($this->data['issued'])) {
- return date($date_format, $this->data['issued']);
- } elseif (!empty($this->data['published'])) {
- return date($date_format, $this->data['published']);
- } elseif (!empty($this->data['modified'])) {
- return date($date_format, $this->data['modified']);
- } elseif (!empty($this->data['updated'])) {
- return date($date_format, $this->data['updated']);
- } else {
- return false;
- }
- }
-
- public function get_permalink()
- {
- $link = $this->get_link(0);
- $enclosure = $this->get_enclosure(0);
- if (!empty($link)) {
- return $link;
- } elseif (!empty($enclosure)) {
- return $enclosure->get_link();
- } else {
- return false;
- }
- }
-
- public function get_link($key = 0, $rel = 'alternate')
- {
- $links = $this->get_links($rel);
- if (!empty($links[$key])) {
- return $links[$key];
- } else {
- return false;
- }
- }
-
- public function get_links($rel = 'alternate')
- {
- if ($rel == 'alternate') {
- $links = array();
- if (!empty($this->data['link'][$rel])) {
- $links = $this->data['link'][$rel];
- }
- if (!empty($this->data['guid']['data']) && $this->data['guid']['permalink'] == true) {
- $links[] = $this->data['guid']['data'];
- }
- return $links;
- } elseif (!empty($this->data['link'][$rel])) {
- return $this->data['link'][$rel];
- } else {
- return false;
- }
- }
-
- public function get_enclosure($key = 0)
- {
- $enclosures = $this->get_enclosures();
- if (!empty($enclosures[$key])) {
- return $enclosures[$key];
- } else {
- return false;
- }
- }
-
- public function get_enclosures()
- {
- $enclosures = array();
- $links = $this->get_links('enclosure');
- if (!empty($this->data['enclosures'])) {
- $enclosures = array_merge($enclosures, $this->data['enclosures']);
- }
- if (!empty($links)) {
- $enclosures = array_merge($enclosures, $links);
- }
- if (!empty($enclosures)) {
- return array_unique($enclosures);
- } else {
- return false;
- }
- }
-
- public function add_to_blinklist()
- {
- if ($this->get_permalink()) {
- $url = 'http://www.blinklist.com/index.php?Action=Blink/addblink.php&Description=&Url=' . rawurlencode($this->get_permalink());
- if ($this->get_title()) {
- $url .= '&Title=' . rawurlencode($this->get_title());
- }
- return $url;
- } else {
- return false;
- }
- }
-
- public function add_to_blogmarks()
- {
- if ($this->get_permalink()) {
- $url = 'http://blogmarks.net/my/new.php?mini=1&simple=1&url=' . rawurlencode($this->get_permalink());
- if ($this->get_title()) {
- $url .= '&title=' . rawurlencode($this->get_title());
- }
- return $url;
- } else {
- return false;
- }
- }
-
- public function add_to_delicious()
- {
- if ($this->get_permalink()) {
- $url = 'http://del.icio.us/post/?v=3&url=' . rawurlencode($this->get_permalink());
- if ($this->get_title()) {
- $url .= '&title=' . rawurlencode($this->get_title());
- }
- return $url;
- } else {
- return false;
- }
- }
-
- public function add_to_digg()
- {
- if ($this->get_permalink()) {
- return 'http://digg.com/submit?phase=2&URL=' . rawurlencode($this->get_permalink());
- } else {
- return false;
- }
- }
-
- public function add_to_furl()
- {
- if ($this->get_permalink()) {
- $url = 'http://www.furl.net/storeIt.jsp?u=' . rawurlencode($this->get_permalink());
- if ($this->get_title()) {
- $url .= '&t=' . rawurlencode($this->get_title());
- }
- return $url;
- } else {
- return false;
- }
- }
-
- public function add_to_magnolia()
- {
- if ($this->get_permalink()) {
- $url = 'http://ma.gnolia.com/bookmarklet/add?url=' . rawurlencode($this->get_permalink());
- if ($this->get_title()) {
- $url .= '&title=' . rawurlencode($this->get_title());
- }
- return $url;
- } else {
- return false;
- }
- }
-
- public function add_to_myweb20()
- {
- if ($this->get_permalink()) {
- $url = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=' . rawurlencode($this->get_permalink());
- if ($this->get_title()) {
- $url .= '&t=' . rawurlencode($this->get_title());
- }
- return $url;
- } else {
- return false;
- }
- }
-
- public function add_to_newsvine()
- {
- if ($this->get_permalink()) {
- $url = 'http://www.newsvine.com/_wine/save?u=' . rawurlencode($this->get_permalink());
- if ($this->get_title()) {
- $url .= '&h=' . rawurlencode($this->get_title());
- }
- return $url;
- } else {
- return false;
- }
- }
-
- public function add_to_reddit()
- {
- if ($this->get_permalink()) {
- $url = 'http://reddit.com/submit?url=' . rawurlencode($this->get_permalink());
- if ($this->get_title()) {
- $url .= '&title=' . rawurlencode($this->get_title());
- }
- return $url;
- } else {
- return false;
- }
- }
-
- public function add_to_segnalo()
- {
- if ($this->get_permalink()) {
- $url = 'http://segnalo.com/post.html.php?url=' . rawurlencode($this->get_permalink());
- if ($this->get_title()) {
- $url .= '&title=' . rawurlencode($this->get_title());
- }
- return $url;
- } else {
- return false;
- }
- }
-
- public function add_to_simpy()
- {
- if ($this->get_permalink()) {
- $url = 'http://www.simpy.com/simpy/LinkAdd.do?href=' . rawurlencode($this->get_permalink());
- if ($this->get_title()) {
- $url .= '&title=' . rawurlencode($this->get_title());
- }
- return $url;
- } else {
- return false;
- }
- }
-
- public function add_to_smarking()
- {
- if ($this->get_permalink()) {
- return 'http://smarking.com/editbookmark/?url=' . rawurlencode($this->get_permalink());
- } else {
- return false;
- }
- }
-
- public function add_to_spurl()
- {
- if ($this->get_permalink()) {
- $url = 'http://www.spurl.net/spurl.php?v=3&url=' . rawurlencode($this->get_permalink());
- if ($this->get_title()) {
- $url .= '&title=' . rawurlencode($this->get_title());
- }
- return $url;
- } else {
- return false;
- }
- }
-
- public function add_to_wists()
- {
- if ($this->get_permalink()) {
- $url = 'http://wists.com/r.php?c=&r=' . rawurlencode($this->get_permalink());
- if ($this->get_title()) {
- $url .= '&title=' . rawurlencode($this->get_title());
- }
- return $url;
- } else {
- return false;
- }
- }
-
- public function search_technorati()
- {
- if ($this->get_permalink()) {
- return 'http://www.technorati.com/search/' . rawurlencode($this->get_permalink());
- } else {
- return false;
- }
- }
- }
-
- class SimplePie_Author
- {
- public $name;
- public $link;
- public $email;
-
- // Constructor, used to input the data
- public function __construct($name, $link, $email)
- {
- $this->name = $name;
- $this->link = $link;
- $this->email = $email;
- }
-
- public function get_name()
- {
- if (!empty($this->name)) {
- return $this->name;
- } else {
- return false;
- }
- }
-
- public function get_link()
- {
- if (!empty($this->link)) {
- return $this->link;
- } else {
- return false;
- }
- }
-
- public function get_email()
- {
- if (!empty($this->email)) {
- return $this->email;
- } else {
- return false;
- }
- }
- }
-
- class SimplePie_Enclosure
- {
- public $link;
- public $type;
- public $length;
-
- // Constructor, used to input the data
- public function __construct($link, $type, $length)
- {
- $this->link = $link;
- $this->type = $type;
- $this->length = $length;
- }
-
- public function get_link()
- {
- if (!empty($this->link)) {
- if (class_exists('idna_convert')) {
- $idn = new idna_convert;
- $this->link = $idn->encode($this->link);
- }
- return $this->link;
- } else {
- return false;
- }
- }
-
- public function get_extension()
- {
- if (!empty($this->link)) {
- return pathinfo($this->link, PATHINFO_EXTENSION);
- } else {
- return false;
- }
- }
-
- public function get_type()
- {
- if (!empty($this->type)) {
- return $this->type;
- } else {
- return false;
- }
- }
-
- public function get_length()
- {
- if (!empty($this->length)) {
- return $this->length;
- } else {
- return false;
- }
- }
-
- public function get_size()
- {
- $length = $this->get_length();
- if (!empty($length)) {
- return round($length/1048576, 2);
- } else {
- return false;
- }
- }
-
- public function native_embed($options='')
- {
- return $this->embed($options, true);
- }
-
- public function embed($options = '', $native = false)
- {
- // Set up defaults
- $audio = '';
- $video = '';
- $alt = '';
- $altclass = '';
- $loop = 'false';
- $width = 'auto';
- $height = 'auto';
- $bgcolor = '#ffffff';
-
- // Process options and reassign values as necessary
- if (is_array($options)) {
- extract($options);
- } else {
- $options = explode(',', $options);
- foreach ($options as $option) {
- $opt = explode(':', $option, 2);
- if (isset($opt[0], $opt[1])) {
- $opt[0] = trim($opt[0]);
- $opt[1] = trim($opt[1]);
- switch ($opt[0]) {
- case 'audio':
- $audio = $opt[1];
- break;
-
- case 'video':
- $video = $opt[1];
- break;
-
- case 'alt':
- $alt = $opt[1];
- break;
-
- case 'altclass':
- $altclass = $opt[1];
- break;
-
- case 'loop':
- $loop = $opt[1];
- break;
-
- case 'width':
- $width = $opt[1];
- break;
-
- case 'height':
- $height = $opt[1];
- break;
-
- case 'bgcolor':
- $bgcolor = $opt[1];
- break;
- }
- }
- }
- }
-
- $type = strtolower($this->get_type());
-
- // If we encounter an unsupported mime-type, check the file extension and guess intelligently.
- 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'))) {
- switch (strtolower($this->get_extension())) {
- // Audio mime-types
- case 'aac':
- case 'adts':
- $type = 'audio/acc';
- break;
-
- case 'aif':
- case 'aifc':
- case 'aiff':
- case 'cdda':
- $type = 'audio/aiff';
- break;
-
- case 'bwf':
- $type = 'audio/wav';
- break;
-
- case 'kar':
- case 'mid':
- case 'midi':
- case 'smf':
- $type = 'audio/midi';
- break;
-
- case 'm4a':
- $type = 'audio/x-m4a';
- break;
-
- case 'mp3':
- case 'swa':
- $type = 'audio/mp3';
- break;
-
- case 'wav':
- $type = 'audio/wav';
- break;
-
- case 'wax':
- $type = 'audio/x-ms-wax';
- break;
-
- case 'wma':
- $type = 'audio/x-ms-wma';
- break;
-
- // Video mime-types
- case '3gp':
- case '3gpp':
- $type = 'video/3gpp';
- break;
-
- case '3g2':
- case '3gp2':
- $type = 'video/3gpp2';
- break;
-
- case 'asf':
- $type = 'video/x-ms-asf';
- break;
-
- case 'm1a':
- case 'm1s':
- case 'm1v':
- case 'm15':
- case 'm75':
- case 'mp2':
- case 'mpa':
- case 'mpeg':
- case 'mpg':
- case 'mpm':
- case 'mpv':
- $type = 'video/mpeg';
- break;
-
- case 'm4v':
- $type = 'video/x-m4v';
- break;
-
- case 'mov':
- case 'qt':
- $type = 'video/quicktime';
- break;
-
- case 'mp4':
- case 'mpg4':
- $type = 'video/mp4';
- break;
-
- case 'sdv':
- $type = 'video/sd-video';
- break;
-
- case 'wm':
- $type = 'video/x-ms-wm';
- break;
-
- case 'wmv':
- $type = 'video/x-ms-wmv';
- break;
-
- case 'wvx':
- $type = 'video/x-ms-wvx';
- break;
-
- // Flash mime-types
- case 'spl':
- $type = 'application/futuresplash';
- break;
-
- case 'swf':
- $type = 'application/x-shockwave-flash';
- break;
- }
- }
-
- $mime = explode('/', $type, 2);
- $mime = $mime[0];
-
- // Process values for 'auto'
- if ($width == 'auto') {
- if ($mime == 'video') {
- $width = '320';
- } else {
- $width = '100%';
- }
- }
- if ($height == 'auto') {
- if ($mime == 'audio') {
- $height = 0;
- } elseif ($mime == 'video') {
- $height = 240;
- } else {
- $height = 256;
- }
- }
-
- // Set proper placeholder value
- if ($mime == 'audio') {
- $placeholder = $audio;
- } elseif ($mime == 'video') {
- $placeholder = $video;
- }
-
- $embed = '';
-
- // Make sure the JS library is included
- // (I know it'll be included multiple times, but I can't think of a better way to do this automatically)
- if (!$native) {
- $embed .= '<script type="text/javascript" src="?js"></script>';
- }
-
- // Odeo Feed MP3's
- if (substr(strtolower($this->get_link()), 0, 15) == 'http://odeo.com') {
- if ($native) {
- $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>';
- } else {
- $embed .= '<script type="text/javascript">embed_odeo("' . $this->get_link() . '");</script>';
- }
- }
-
- // QuickTime 7 file types. Need to test with QuickTime 6.
- elseif (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'))) {
- $height += 16;
- if ($native) {
- if ($placeholder != "") {
- $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>";
- } else {
- $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>";
- }
- } else {
- $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>";
- }
- }
-
- // Flash
- elseif (in_array($type, array('application/x-shockwave-flash', 'application/futuresplash'))) {
- if ($native) {
- $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>";
- } else {
- $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>";
- }
- }
-
- // Windows Media
- elseif (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'))) {
- $height += 45;
- if ($native) {
- $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>";
- } else {
- $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>";
- }
- }
-
- // Everything else
- else {
- $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>';
- }
-
- return $embed;
- }
- }
-
- class SimplePie_File
- {
- public $url;
- public $useragent;
- public $success = true;
- public $headers = array();
- public $body;
- public $fp;
- public $redirects = 0;
- public $error;
- public $method;
-
- public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
- {
- if (class_exists('idna_convert')) {
- $idn = new idna_convert;
- $url = $idn->encode($url);
- }
- $this->url = $url;
- $this->useragent = $useragent;
- if (preg_match('/^http(s)?:\/\//i', $url)) {
- if (empty($useragent)) {
- $useragent = ini_get('user_agent');
- $this->useragent = $useragent;
- }
- if (!is_array($headers)) {
- $headers = array();
- }
- if (extension_loaded('curl') && version_compare(SimplePie_Misc::get_curl_version(), '7.10.5', '>=') && !$force_fsockopen) {
- $this->method = 'curl';
- $fp = curl_init();
- $headers2 = array();
- foreach ($headers as $key => $value) {
- $headers2[] = "$key: $value";
- }
- curl_setopt($fp, CURLOPT_ENCODING, '');
- curl_setopt($fp, CURLOPT_URL, $url);
- curl_setopt($fp, CURLOPT_HEADER, 1);
- curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
- curl_setopt($fp, CURLOPT_REFERER, $url);
- curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
- curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
- if (!ini_get('open_basedir') && !ini_get('safe_mode')) {
- curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
- }
-
- $this->headers = trim(curl_exec($fp));
- if (curl_errno($fp) == 23 || curl_errno($fp) == 61) {
- curl_setopt($fp, CURLOPT_ENCODING, 'none');
- $this->headers = trim(curl_exec($fp));
- }
- if (curl_errno($fp)) {
- $this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
- $this->success = false;
- return false;
- }
- $info = curl_getinfo($fp);
- $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 2);
- if (count($this->headers) == $info['redirect_count'] + 1) {
- $this->headers = array_pop($this->headers);
- $this->body = '';
- } else {
- $this->body = array_pop($this->headers);
- $this->headers = array_pop($this->headers);
- }
- $this->headers = $this->parse_headers($this->headers);
- 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) {
- $this->redirects++;
- return $this->SimplePie_File($this->headers['location'], $timeout, $redirects, $headers, $useragent, $force_fsockopen);
- }
- } else {
- $this->method = 'fsockopen';
- $url_parts = parse_url($url);
- if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) == 'https') {
- $url_parts['host'] = "ssl://$url_parts[host]";
- $url_parts['port'] = 443;
- }
- if (!isset($url_parts['port'])) {
- $url_parts['port'] = 80;
- }
- $this->fp = @fsockopen($url_parts['host'], $url_parts['port'], $errno, $errstr, $timeout);
- if (!$this->fp) {
- $this->error = 'fsockopen error: ' . $errstr;
- $this->success = false;
- return false;
- } else {
- stream_set_timeout($this->fp, $timeout);
- $get = (isset($url_parts['query'])) ? "$url_parts[path]?$url_parts[query]" : $url_parts['path'];
- $out = "GET $get HTTP/1.0\r\n";
- $out .= "Host: $url_parts[host]\r\n";
- $out .= "User-Agent: $useragent\r\n";
- if (function_exists('gzinflate')) {
- $out .= "Accept-Encoding: gzip,deflate\r\n";
- }
-
- if (!empty($url_parts['user']) && !empty($url_parts['pass'])) {
- $out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
- }
- foreach ($headers as $key => $value) {
- $out .= "$key: $value\r\n";
- }
- $out .= "Connection: Close\r\n\r\n";
- fwrite($this->fp, $out);
-
- $info = stream_get_meta_data($this->fp);
- $data = '';
- while (strpos($data, "\r\n\r\n") === false && !$info['timed_out']) {
- $data .= fgets($this->fp, 128);
- $info = @stream_get_meta_data($this->fp);
- }
- if (!$info['timed_out']) {
- $this->headers = $this->parse_headers($data);
- 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) {
- $this->redirects++;
- return $this->SimplePie_File($this->headers['location'], $timeout, $redirects, $headers, $useragent, $force_fsockopen);
- }
- } else {
- $this->close();
- $this->error = 'fsocket timed out';
- $this->success = false;
- return false;
- }
- }
- }
- return $this->headers['status']['code'];
- } else {
- $this->method = 'fopen';
- if ($this->fp = fopen($url, 'r')) {
- return true;
- } else {
- $this->error = 'fopen could not open the file';
- $this->success = false;
- return false;
- }
- }
- }
-
- public function headers()
- {
- return $this->headers;
- }
-
- public function body()
- {
- if (is_null($this->body)) {
- if ($this->fp) {
- $info = stream_get_meta_data($this->fp);
- $this->body = '';
- while (!$info['eof'] && !$info['timed_out']) {
- $this->body .= fread($this->fp, 1024);
- $info = stream_get_meta_data($this->fp);
- }
- if (!$info['timed_out']) {
- $this->body = trim($this->body);
- if ($this->method == 'fsockopen' && !empty($this->headers['content-encoding']) && ($this->headers['content-encoding'] == 'gzip' || $this->headers['content-encoding'] == 'deflate')) {
- if (substr($this->body, 0, 8) == "\x1f\x8b\x08\x00\x00\x00\x00\x00") {
- $this->body = substr($this->body, 10);
- }
- $this->body = gzinflate($this->body);
- }
- $this->close();
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
- return $this->body;
- }
-
- public function close()
- {
- if (!is_null($this->fp)) {
- if (fclose($this->fp)) {
- $this->fp = null;
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
-
- public function parse_headers($headers)
- {
- $headers = explode("\r\n", trim($headers));
- $status = array_shift($headers);
- foreach ($headers as $header) {
- $data = explode(':', $header, 2);
- $head[strtolower(trim($data[0]))] = trim($data[1]);
- }
- if (preg_match('/HTTP\/[0-9\.]+ ([0-9]+)(.*)$/i', $status, $matches)) {
- if (isset($head['status'])) {
- unset($head['status']);
- }
- $head['status']['code'] = $matches[1];
- $head['status']['name'] = trim($matches[2]);
- }
- return $head;
- }
- }
-
- class SimplePie_Cache
- {
- public $location;
- public $filename;
- public $extension;
- public $name;
-
- public function __construct($location, $filename, $extension)
- {
- $this->location = $location;
- $this->filename = rawurlencode($filename);
- $this->extension = rawurlencode($extension);
- $this->name = "$location/$this->filename.$this->extension";
- }
-
- public function save($data)
- {
- if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location)) {
- $fp = fopen($this->name, 'w');
- if ($fp) {
- fwrite($fp, serialize($data));
- fclose($fp);
- return true;
- }
- }
- return false;
- }
-
- public function load()
- {
- if (file_exists($this->name) && is_readable($this->name)) {
- return unserialize(file_get_contents($this->name));
- }
- return false;
- }
-
- public function mtime()
- {
- if (file_exists($this->name)) {
- return filemtime($this->name);
- }
- return false;
- }
-
- public function touch()
- {
- if (file_exists($this->name)) {
- return touch($this->name);
- }
- return false;
- }
-
- public function unlink()
- {
- if (file_exists($this->name)) {
- return unlink($this->name);
- }
- return false;
- }
- }
-
- class SimplePie_Misc
- {
- public function absolutize_url($relative, $base)
- {
- $relative = trim($relative);
- $base = trim($base);
- if (!empty($relative)) {
- $relative = SimplePie_Misc::parse_url($relative, false);
- $relative = array('scheme' => $relative[2], 'authority' => $relative[3], 'path' => $relative[5], 'query' => $relative[7], 'fragment' => $relative[9]);
- if (!empty($relative['scheme'])) {
- $target = $relative;
- } elseif (!empty($base)) {
- $base = SimplePie_Misc::parse_url($base, false);
- $base = array('scheme' => $base[2], 'authority' => $base[3], 'path' => $base[5], 'query' => $base[7], 'fragment' => $base[9]);
- $target['scheme'] = $base['scheme'];
- if (!empty($relative['authority'])) {
- $target = array_merge($relative, $target);
- } else {
- $target['authority'] = $base['authority'];
- if (!empty($relative['path'])) {
- if (strpos($relative['path'], '/') === 0) {
- $target['path'] = $relative['path'];
- } else {
- if (!empty($base['path'])) {
- $target['path'] = dirname("$base[path].") . '/' . $relative['path'];
- } else {
- $target['path'] = '/' . $relative['path'];
- }
- }
- if (!empty($relative['query'])) {
- $target['query'] = $relative['query'];
- }
- $input = $target['path'];
- $target['path'] = '';
- while (!empty($input)) {
- if (strpos($input, '../') === 0) {
- $input = substr($input, 3);
- } elseif (strpos($input, './') === 0) {
- $input = substr($input, 2);
- } elseif (strpos($input, '/./') === 0) {
- $input = substr_replace($input, '/', 0, 3);
- } elseif (strpos($input, '/.') === 0 && SimplePie_Misc::strendpos($input, '/.') === 0) {
- $input = substr_replace($input, '/', -2);
- } elseif (strpos($input, '/../') === 0) {
- $input = substr_replace($input, '/', 0, 4);
- $target['path'] = preg_replace('/(\/)?([^\/]+)$/msiU', '', $target['path']);
- } elseif (strpos($input, '/..') === 0 && SimplePie_Misc::strendpos($input, '/..') === 0) {
- $input = substr_replace($input, '/', 0, 3);
- $target['path'] = preg_replace('/(\/)?([^\/]+)$/msiU', '', $target['path']);
- } elseif ($input == '.' || $input == '..') {
- $input = '';
- } else {
- if (preg_match('/^(.+)(\/|$)/msiU', $input, $match)) {
- $target['path'] .= $match[1];
- $input = substr_replace($input, '', 0, strlen($match[1]));
- }
- }
- }
- } else {
- if (!empty($base['path'])) {
- $target['path'] = $base['path'];
- } else {
- $target['path'] = '/';
- }
- if (!empty($relative['query'])) {
- $target['query'] = $relative['query'];
- } elseif (!empty($base['query'])) {
- $target['query'] = $base['query'];
- }
- }
- }
- if (!empty($relative['fragment'])) {
- $target['fragment'] = $relative['fragment'];
- }
- } else {
- return false;
- }
- $return = '';
- if (!empty($target['scheme'])) {
- $return .= "$target[scheme]:";
- }
- if (!empty($target['authority'])) {
- $return .= $target['authority'];
- }
- if (!empty($target['path'])) {
- $return .= $target['path'];
- }
- if (!empty($target['query'])) {
- $return .= "?$target[query]";
- }
- if (!empty($target['fragment'])) {
- $return .= "#$target[fragment]";
- }
- } else {
- $return = $base;
- }
- return $return;
- }
-
- public function strendpos($haystack, $needle)
- {
- return strlen($haystack) - strpos($haystack, $needle) - strlen($needle);
- }
-
- public function get_element($realname, $string)
- {
- $return = array();
- $name = preg_quote($realname, '/');
- preg_match_all("/<($name)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'|(.*)))*)\s*((\/)?>|>(.*)<\/$name>)/msiU", $string, $matches, PREG_SET_ORDER);
- for ($i = 0; $i < count($matches); $i++) {
- $return[$i]['tag'] = $realname;
- $return[$i]['full'] = $matches[$i][0];
- if (strlen($matches[$i][10]) <= 2) {
- $return[$i]['self_closing'] = true;
- } else {
- $return[$i]['self_closing'] = false;
- $return[$i]['content'] = $matches[$i][12];
- }
- $return[$i]['attribs'] = array();
- if (!empty($matches[$i][2])) {
- preg_match_all('/((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(\S+))\s/msiU', ' ' . $matches[$i][2] . ' ', $attribs, PREG_SET_ORDER);
- for ($j = 0; $j < count($attribs); $j++) {
- $return[$i]['attribs'][strtoupper($attribs[$j][1])]['data'] = $attribs[$j][count($attribs[$j])-1];
- $first = substr($attribs[$j][2], 0, 1);
- $return[$i]['attribs'][strtoupper($attribs[$j][1])]['split'] = ($first == '"' || $first == "'") ? $first : '"';
- }
- }
- }
- return $return;
- }
-
- public function element_implode($element)
- {
- $full = "<$element[tag]";
- foreach ($element['attribs'] as $key => $value) {
- $key = strtolower($key);
- $full .= " $key=$value[split]$value[data]$value[split]";
- }
- if ($element['self_closing']) {
- $full .= ' />';
- } else {
- $full .= ">$element[content]</$element[tag]>";
- }
- return $full;
- }
-
- public function error($message, $level, $file, $line)
- {
- switch ($level) {
- case E_USER_ERROR:
- $note = 'PHP Error';
- break;
- case E_USER_WARNING:
- $note = 'PHP Warning';
- break;
- case E_USER_NOTICE:
- $note = 'PHP Notice';
- break;
- default:
- $note = 'Unknown Error';
- break;
- }
- error_log("$note: $message in $file on line $line", 0);
- return $message;
- }
-
- public function display_file($url, $timeout = 10, $useragent = null)
- {
- $file = new SimplePie_File($url, $timeout, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $useragent);
- $headers = $file->headers();
- if ($file->body() !== false) {
- header('Content-type: ' . $headers['content-type']);
- echo $file->body();
- exit;
- }
- }
-
- public function fix_protocol($url, $http = 1)
- {
- $parsed = SimplePie_Misc::parse_url($url);
- if (!empty($parsed['scheme']) && strtolower($parsed['scheme']) != 'http' && strtolower($parsed['scheme']) != 'https') {
- return SimplePie_Misc::fix_protocol("$parsed[authority]$parsed[path]$parsed[query]$parsed[fragment]", $http);
- }
- if (!file_exists($url) && empty($parsed['scheme'])) {
- return SimplePie_Misc::fix_protocol("http://$url", $http);
- }
-
- if ($http == 2 && !empty($parsed['scheme'])) {
- return "feed:$url";
- } elseif ($http == 3 && strtolower($parsed['scheme']) == 'http') {
- return substr_replace($url, 'podcast', 0, 4);
- } else {
- return $url;
- }
- }
-
- public function parse_url($url, $parse_match = true)
- {
- preg_match('/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/i', $url, $match);
- if (empty($match[0])) {
- return false;
- } else {
- for ($i = 6; $i < 10; $i++) {
- if (!isset($match[$i])) {
- $match[$i] = '';
- }
- }
- if ($parse_match) {
- $match = array('scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5], 'query' => $match[6], 'fragment' => $match[8]);
- }
- return $match;
- }
- }
-
- /**
- * Replace bad bytes
- *
- * PCRE Pattern to locate bad bytes in a UTF-8 string
- * Comes from W3 FAQ: Multilingual Forms
- * Note: modified to include full ASCII range including control chars
- *
- * Modified by Geoffrey Sneddon 2006-11-19 to remove functionality
- * to choose what the replace string is, and to use a variable for
- * the output instead of PHP's output buffer
- */
- public function utf8_bad_replace($str)
- {
- $UTF8_BAD =
- '([\x00-\x7F]' . # ASCII (including control chars)
- '|[\xC2-\xDF][\x80-\xBF]' . # non-overlong 2-byte
- '|\xE0[\xA0-\xBF][\x80-\xBF]' . # excluding overlongs
- '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' . # straight 3-byte
- '|\xED[\x80-\x9F][\x80-\xBF]' . # excluding surrogates
- '|\xF0[\x90-\xBF][\x80-\xBF]{2}' . # planes 1-3
- '|[\xF1-\xF3][\x80-\xBF]{3}' . # planes 4-15
- '|\xF4[\x80-\x8F][\x80-\xBF]{2}' . # plane 16
- '|(.{1}))'; # invalid byte
- $output = '';
- while (preg_match('/' . $UTF8_BAD . '/S', $str, $matches)) {
- if (!isset($matches[2])) {
- $output .= $matches[0];
- }
- $str = substr($str, strlen($matches[0]));
- }
- return $output;
- }
-
- public function change_encoding($data, $input, $output)
- {
- $input = SimplePie_Misc::encoding($input);
- $output = SimplePie_Misc::encoding($output);
-
- if ($input != $output) {
- if (function_exists('iconv') && $input['use_iconv'] && $output['use_iconv'] && iconv($input['encoding'], "$output[encoding]//TRANSLIT", $data)) {
- return iconv($input['encoding'], "$output[encoding]//TRANSLIT", $data);
- } elseif (function_exists('iconv') && $input['use_iconv'] && $output['use_iconv'] && iconv($input['encoding'], $output['encoding'], $data)) {
- return iconv($input['encoding'], $output['encoding'], $data);
- } elseif (function_exists('mb_convert_encoding') && $input['use_mbstring'] && $output['use_mbstring']) {
- return mb_convert_encoding($data, $output['encoding'], $input['encoding']);
- } elseif ($input['encoding'] == 'ISO-8859-1' && $output['encoding'] == 'UTF-8') {
- return utf8_encode($data);
- } elseif ($input['encoding'] == 'UTF-8' && $output['encoding'] == 'ISO-8859-1') {
- return utf8_decode($data);
- }
- }
- return $data;
- }
-
- public function encoding($encoding)
- {
- $return['use_mbstring'] = false;
- $return['use_iconv'] = false;
- switch (strtolower($encoding)) {
-
- // 7bit
- case '7bit':
- case '7-bit':
- $return['encoding'] = '7bit';
- $return['use_mbstring'] = true;
- break;
-
- // 8bit
- case '8bit':
- case '8-bit':
- $return['encoding'] = '8bit';
- $return['use_mbstring'] = true;
- break;
-
- // ARMSCII-8
- case 'armscii-8':
- case 'armscii':
- $return['encoding'] = 'ARMSCII-8';
- $return['use_iconv'] = true;
- break;
-
- // ASCII
- case 'us-ascii':
- case 'ascii':
- $return['encoding'] = 'US-ASCII';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // BASE64
- case 'base64':
- case 'base-64':
- $return['encoding'] = 'BASE64';
- $return['use_mbstring'] = true;
- break;
-
- // Big5 - Traditional Chinese, mainly used in Taiwan
- case 'big5':
- case '950':
- $return['encoding'] = 'BIG5';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // Big5 with Hong Kong extensions, Traditional Chinese
- case 'big5-hkscs':
- $return['encoding'] = 'BIG5-HKSCS';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // byte2be
- case 'byte2be':
- $return['encoding'] = 'byte2be';
- $return['use_mbstring'] = true;
- break;
-
- // byte2le
- case 'byte2le':
- $return['encoding'] = 'byte2le';
- $return['use_mbstring'] = true;
- break;
-
- // byte4be
- case 'byte4be':
- $return['encoding'] = 'byte4be';
- $return['use_mbstring'] = true;
- break;
-
- // byte4le
- case 'byte4le':
- $return['encoding'] = 'byte4le';
- $return['use_mbstring'] = true;
- break;
-
- // EUC-CN
- case 'euc-cn':
- case 'euccn':
- $return['encoding'] = 'EUC-CN';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // EUC-JISX0213
- case 'euc-jisx0213':
- case 'eucjisx0213':
- $return['encoding'] = 'EUC-JISX0213';
- $return['use_iconv'] = true;
- break;
-
- // EUC-JP
- case 'euc-jp':
- case 'eucjp':
- $return['encoding'] = 'EUC-JP';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // EUCJP-win
- case 'euc-jp-win':
- case 'eucjp-win':
- case 'eucjpwin':
- $return['encoding'] = 'EUCJP-win';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // EUC-KR
- case 'euc-kr':
- case 'euckr':
- $return['encoding'] = 'EUC-KR';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // EUC-TW
- case 'euc-tw':
- case 'euctw':
- $return['encoding'] = 'EUC-TW';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // GB18030 - Simplified Chinese, national standard character set
- case 'gb18030-2000':
- case 'gb18030':
- $return['encoding'] = 'GB18030';
- $return['use_iconv'] = true;
- break;
-
- // GB2312 - Simplified Chinese, national standard character set
- case 'gb2312':
- case '936':
- $return['encoding'] = 'GB2312';
- $return['use_mbstring'] = true;
- break;
-
- // GBK
- case 'gbk':
- $return['encoding'] = 'GBK';
- $return['use_iconv'] = true;
- break;
-
- // Georgian-Academy
- case 'georgian-academy':
- $return['encoding'] = 'Georgian-Academy';
- $return['use_iconv'] = true;
- break;
-
- // Georgian-PS
- case 'georgian-ps':
- $return['encoding'] = 'Georgian-PS';
- $return['use_iconv'] = true;
- break;
-
- // HTML-ENTITIES
- case 'html-entities':
- case 'htmlentities':
- $return['encoding'] = 'HTML-ENTITIES';
- $return['use_mbstring'] = true;
- break;
-
- // HZ
- case 'hz':
- $return['encoding'] = 'HZ';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // ISO-2022-CN
- case 'iso-2022-cn':
- case 'iso2022-cn':
- case 'iso2022cn':
- $return['encoding'] = 'ISO-2022-CN';
- $return['use_iconv'] = true;
- break;
-
- // ISO-2022-CN-EXT
- case 'iso-2022-cn-ext':
- case 'iso2022-cn-ext':
- case 'iso2022cn-ext':
- case 'iso2022cnext':
- $return['encoding'] = 'ISO-2022-CN';
- $return['use_iconv'] = true;
- break;
-
- // ISO-2022-JP
- case 'iso-2022-jp':
- case 'iso2022-jp':
- case 'iso2022jp':
- $return['encoding'] = 'ISO-2022-JP';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // ISO-2022-JP-1
- case 'iso-2022-jp-1':
- case 'iso2022-jp-1':
- case 'iso2022jp-1':
- case 'iso2022jp1':
- $return['encoding'] = 'ISO-2022-JP-1';
- $return['use_iconv'] = true;
- break;
-
- // ISO-2022-JP-2
- case 'iso-2022-jp-2':
- case 'iso2022-jp-2':
- case 'iso2022jp-2':
- case 'iso2022jp2':
- $return['encoding'] = 'ISO-2022-JP-2';
- $return['use_iconv'] = true;
- break;
-
- // ISO-2022-JP-3
- case 'iso-2022-jp-3':
- case 'iso2022-jp-3':
- case 'iso2022jp-3':
- case 'iso2022jp3':
- $return['encoding'] = 'ISO-2022-JP-3';
- $return['use_iconv'] = true;
- break;
-
- // ISO-2022-KR
- case 'iso-2022-kr':
- case 'iso2022-kr':
- case 'iso2022kr':
- $return['encoding'] = 'ISO-2022-KR';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // ISO-8859-1
- case 'iso-8859-1':
- case 'iso8859-1':
- $return['encoding'] = 'ISO-8859-1';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // ISO-8859-2
- case 'iso-8859-2':
- case 'iso8859-2':
- $return['encoding'] = 'ISO-8859-2';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // ISO-8859-3
- case 'iso-8859-3':
- case 'iso8859-3':
- $return['encoding'] = 'ISO-8859-3';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // ISO-8859-4
- case 'iso-8859-4':
- case 'iso8859-4':
- $return['encoding'] = 'ISO-8859-4';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // ISO-8859-5
- case 'iso-8859-5':
- case 'iso8859-5':
- $return['encoding'] = 'ISO-8859-5';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // ISO-8859-6
- case 'iso-8859-6':
- case 'iso8859-6':
- $return['encoding'] = 'ISO-8859-6';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // ISO-8859-7
- case 'iso-8859-7':
- case 'iso8859-7':
- $return['encoding'] = 'ISO-8859-7';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // ISO-8859-8
- case 'iso-8859-8':
- case 'iso8859-8':
- $return['encoding'] = 'ISO-8859-8';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // ISO-8859-9
- case 'iso-8859-9':
- case 'iso8859-9':
- $return['encoding'] = 'ISO-8859-9';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // ISO-8859-10
- case 'iso-8859-10':
- case 'iso8859-10':
- $return['encoding'] = 'ISO-8859-10';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // mbstring/iconv functions don't appear to support 11 & 12
-
- // ISO-8859-13
- case 'iso-8859-13':
- case 'iso8859-13':
- $return['encoding'] = 'ISO-8859-13';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // ISO-8859-14
- case 'iso-8859-14':
- case 'iso8859-14':
- $return['encoding'] = 'ISO-8859-14';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // ISO-8859-15
- case 'iso-8859-15':
- case 'iso8859-15':
- $return['encoding'] = 'ISO-8859-15';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // ISO-8859-16
- case 'iso-8859-16':
- case 'iso8859-16':
- $return['encoding'] = 'ISO-8859-16';
- $return['use_iconv'] = true;
- break;
-
- // JIS
- case 'jis':
- $return['encoding'] = 'JIS';
- $return['use_mbstring'] = true;
- break;
-
- // JOHAB - Korean
- case 'johab':
- $return['encoding'] = 'JOHAB';
- $return['use_iconv'] = true;
- break;
-
- // Russian
- case 'koi8-r':
- case 'koi8r':
- $return['encoding'] = 'KOI8-R';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // Turkish
- case 'koi8-t':
- case 'koi8t':
- $return['encoding'] = 'KOI8-T';
- $return['use_iconv'] = true;
- break;
-
- // Ukrainian
- case 'koi8-u':
- case 'koi8u':
- $return['encoding'] = 'KOI8-U';
- $return['use_iconv'] = true;
- break;
-
- // Russian+Ukrainian
- case 'koi8-ru':
- case 'koi8ru':
- $return['encoding'] = 'KOI8-RU';
- $return['use_iconv'] = true;
- break;
-
- // Macintosh (Mac OS Classic)
- case 'macintosh':
- $return['encoding'] = 'Macintosh';
- $return['use_iconv'] = true;
- break;
-
- // MacArabic (Mac OS Classic)
- case 'macarabic':
- $return['encoding'] = 'MacArabic';
- $return['use_iconv'] = true;
- break;
-
- // MacCentralEurope (Mac OS Classic)
- case 'maccentraleurope':
- $return['encoding'] = 'MacCentralEurope';
- $return['use_iconv'] = true;
- break;
-
- // MacCroatian (Mac OS Classic)
- case 'maccroatian':
- $return['encoding'] = 'MacCroatian';
- $return['use_iconv'] = true;
- break;
-
- // MacCyrillic (Mac OS Classic)
- case 'maccyrillic':
- $return['encoding'] = 'MacCyrillic';
- $return['use_iconv'] = true;
- break;
-
- // MacGreek (Mac OS Classic)
- case 'macgreek':
- $return['encoding'] = 'MacGreek';
- $return['use_iconv'] = true;
- break;
-
- // MacHebrew (Mac OS Classic)
- case 'machebrew':
- $return['encoding'] = 'MacHebrew';
- $return['use_iconv'] = true;
- break;
-
- // MacIceland (Mac OS Classic)
- case 'maciceland':
- $return['encoding'] = 'MacIceland';
- $return['use_iconv'] = true;
- break;
-
- // MacRoman (Mac OS Classic)
- case 'macroman':
- $return['encoding'] = 'MacRoman';
- $return['use_iconv'] = true;
- break;
-
- // MacRomania (Mac OS Classic)
- case 'macromania':
- $return['encoding'] = 'MacRomania';
- $return['use_iconv'] = true;
- break;
-
- // MacThai (Mac OS Classic)
- case 'macthai':
- $return['encoding'] = 'MacThai';
- $return['use_iconv'] = true;
- break;
-
- // MacTurkish (Mac OS Classic)
- case 'macturkish':
- $return['encoding'] = 'MacTurkish';
- $return['use_iconv'] = true;
- break;
-
- // MacUkraine (Mac OS Classic)
- case 'macukraine':
- $return['encoding'] = 'MacUkraine';
- $return['use_iconv'] = true;
- break;
-
- // MuleLao-1
- case 'mulelao-1':
- case 'mulelao1':
- $return['encoding'] = 'MuleLao-1';
- $return['use_iconv'] = true;
- break;
-
- // Shift_JIS
- case 'shift_jis':
- case 'sjis':
- case '932':
- $return['encoding'] = 'Shift_JIS';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // Shift_JISX0213
- case 'shift-jisx0213':
- case 'shiftjisx0213':
- $return['encoding'] = 'Shift_JISX0213';
- $return['use_iconv'] = true;
- break;
-
- // SJIS-win
- case 'sjis-win':
- case 'sjiswin':
- case 'shift_jis-win':
- $return['encoding'] = 'SJIS-win';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // TCVN - Vietnamese
- case 'tcvn':
- $return['encoding'] = 'TCVN';
- $return['use_iconv'] = true;
- break;
-
- // TDS565 - Turkish
- case 'tds565':
- $return['encoding'] = 'TDS565';
- $return['use_iconv'] = true;
- break;
-
- // TIS-620 Thai
- case 'tis-620':
- case 'tis620':
- $return['encoding'] = 'TIS-620';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // UCS-2
- case 'ucs-2':
- case 'ucs2':
- case 'utf-16':
- case 'utf16':
- $return['encoding'] = 'UCS-2';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // UCS-2BE
- case 'ucs-2be':
- case 'ucs2be':
- case 'utf-16be':
- case 'utf16be':
- $return['encoding'] = 'UCS-2BE';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // UCS-2LE
- case 'ucs-2le':
- case 'ucs2le':
- case 'utf-16le':
- case 'utf16le':
- $return['encoding'] = 'UCS-2LE';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // UCS-2-INTERNAL
- case 'ucs-2-internal':
- case 'ucs2internal':
- $return['encoding'] = 'UCS-2-INTERNAL';
- $return['use_iconv'] = true;
- break;
-
- // UCS-4
- case 'ucs-4':
- case 'ucs4':
- case 'utf-32':
- case 'utf32':
- $return['encoding'] = 'UCS-4';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // UCS-4BE
- case 'ucs-4be':
- case 'ucs4be':
- case 'utf-32be':
- case 'utf32be':
- $return['encoding'] = 'UCS-4BE';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // UCS-4LE
- case 'ucs-4le':
- case 'ucs4le':
- case 'utf-32le':
- case 'utf32le':
- $return['encoding'] = 'UCS-4LE';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // UCS-4-INTERNAL
- case 'ucs-4-internal':
- case 'ucs4internal':
- $return['encoding'] = 'UCS-4-INTERNAL';
- $return['use_iconv'] = true;
- break;
-
- // UCS-16
- case 'ucs-16':
- case 'ucs16':
- $return['encoding'] = 'UCS-16';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // UCS-16BE
- case 'ucs-16be':
- case 'ucs16be':
- $return['encoding'] = 'UCS-16BE';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // UCS-16LE
- case 'ucs-16le':
- case 'ucs16le':
- $return['encoding'] = 'UCS-16LE';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // UCS-32
- case 'ucs-32':
- case 'ucs32':
- $return['encoding'] = 'UCS-32';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // UCS-32BE
- case 'ucs-32be':
- case 'ucs32be':
- $return['encoding'] = 'UCS-32BE';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // UCS-32LE
- case 'ucs-32le':
- case 'ucs32le':
- $return['encoding'] = 'UCS-32LE';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // UTF-7
- case 'utf-7':
- case 'utf7':
- $return['encoding'] = 'UTF-7';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // UTF7-IMAP
- case 'utf-7-imap':
- case 'utf7-imap':
- case 'utf7imap':
- $return['encoding'] = 'UTF7-IMAP';
- $return['use_mbstring'] = true;
- break;
-
- // VISCII - Vietnamese ASCII
- case 'viscii':
- $return['encoding'] = 'VISCII';
- $return['use_iconv'] = true;
- break;
-
- // Windows-specific Central & Eastern Europe
- case 'cp1250':
- case 'windows-1250':
- case 'win-1250':
- case '1250':
- $return['encoding'] = 'Windows-1250';
- $return['use_iconv'] = true;
- break;
-
- // Windows-specific Cyrillic
- case 'cp1251':
- case 'windows-1251':
- case 'win-1251':
- case '1251':
- $return['encoding'] = 'Windows-1251';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // Windows-specific Western Europe
- case 'cp1252':
- case 'windows-1252':
- case '1252':
- $return['encoding'] = 'Windows-1252';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
-
- // Windows-specific Greek
- case 'cp1253':
- case 'windows-1253':
- case '1253':
- $return['encoding'] = 'Windows-1253';
- $return['use_iconv'] = true;
- break;
-
- // Windows-specific Turkish
- case 'cp1254':
- case 'windows-1254':
- case '1254':
- $return['encoding'] = 'Windows-1254';
- $return['use_iconv'] = true;
- break;
-
- // Windows-specific Hebrew
- case 'cp1255':
- case 'windows-1255':
- case '1255':
- $return['encoding'] = 'Windows-1255';
- $return['use_iconv'] = true;
- break;
-
- // Windows-specific Arabic
- case 'cp1256':
- case 'windows-1256':
- case '1256':
- $return['encoding'] = 'Windows-1256';
- $return['use_iconv'] = true;
- break;
-
- // Windows-specific Baltic
- case 'cp1257':
- case 'windows-1257':
- case '1257':
- $return['encoding'] = 'Windows-1257';
- $return['use_iconv'] = true;
- break;
-
- // Windows-specific Vietnamese
- case 'cp1258':
- case 'windows-1258':
- case '1258':
- $return['encoding'] = 'Windows-1258';
- $return['use_iconv'] = true;
- break;
-
- // Default to UTF-8
- default:
- $return['encoding'] = 'UTF-8';
- $return['use_iconv'] = true;
- $return['use_mbstring'] = true;
- break;
- }
-
- // Then, return it.
- return $return;
- }
-
- public function get_curl_version()
- {
- $curl = 0;
- if (is_array(curl_version())) {
- $curl = curl_version();
- $curl = $curl['version'];
- } else {
- $curl = curl_version();
- $curl = explode(' ', $curl);
- $curl = explode('/', $curl[0]);
- $curl = $curl[1];
- }
- return $curl;
- }
-
- public function is_a_class($class1, $class2)
- {
- if (class_exists($class1)) {
- $classes = array(strtolower($class1));
- while ($class1 = get_parent_class($class1)) {
- $classes[] = strtolower($class1);
- }
- return in_array(strtolower($class2), $classes);
- } else {
- return false;
- }
- }
- }
-
- class SimplePie_Locator
- {
- public $useragent;
- public $timeout;
- public $file;
- public $local;
- public $elsewhere;
- public $file_class = 'SimplePie_File';
-
- public function __construct(&$file, $timeout = 10, $useragent = null, $file_class = 'SimplePie_File')
- {
- if (!is_a($file, 'SimplePie_File')) {
- $this->file = new $this->file_class($file, $timeout, $useragent);
- } else {
- $this->file =& $file;
- }
- $this->file_class = $file_class;
- $this->useragent = $useragent;
- $this->timeout = $timeout;
- }
-
-
- public function find()
- {
- if ($this->is_feed($this->file)) {
- return $this->file->url;
- }
-
- $autodiscovery = $this->autodiscovery($this->file);
- if ($autodiscovery) {
- return $autodiscovery;
- }
-
- if ($this->get_links($this->file)) {
- if (!empty($this->local)) {
- $extension_local = $this->extension($this->local);
- if ($extension_local) {
- return $extension_local;
- }
-
- $body_local = $this->body($this->local);
- if ($body_local) {
- return $body_local;
- }
- }
-
- if (!empty($this->elsewhere)) {
- $extension_elsewhere = $this->extension($this->elsewhere);
- if ($extension_elsewhere) {
- return $extension_elsewhere;
- }
-
- $body_elsewhere = $this->body($this->elsewhere);
- if ($body_elsewhere) {
- return $body_elsewhere;
- }
- }
- }
- return false;
- }
-
- public function is_feed(&$file)
- {
- if (!is_a($file, 'SimplePie_File')) {
- if (isset($this)) {
- $file2 = new $this->file_class($file, $this->timeout, 5, null, $this->useragent);
- } else {
- $file2 = new $this->file_class($file);
- }
- $file2->body();
- $file2->close();
- } else {
- $file2 =& $file;
- }
- $body = preg_replace('/<\!-(.*)-\>/msiU', '', $file2->body());
- if (preg_match('/<(\w+\:)?rss/msiU', $body) || preg_match('/<(\w+\:)?RDF/mi', $body) || preg_match('/<(\w+\:)?feed/mi', $body)) {
- return true;
- }
- return false;
- }
-
- public function autodiscovery(&$file)
- {
- $links = SimplePie_Misc::get_element('link', $file->body());
- $done = array();
- foreach ($links as $link) {
- if (!empty($link['attribs']['TYPE']['data']) && !empty($link['attribs']['HREF']['data']) && !empty($link['attribs']['REL']['data'])) {
- $rel = preg_split('/\s+/', strtolower(trim($link['attribs']['REL']['data'])));
- $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']));
- $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['HREF']['data']), $this->file->url);
- if (!in_array($href, $done) && in_array('alternate', $rel) && $type) {
- $feed = $this->is_feed($href);
- if ($feed) {
- return $href;
- }
- }
- $done[] = $href;
- }
- }
- return false;
- }
-
- public function get_links(&$file)
- {
- $links = SimplePie_Misc::get_element('a', $file->body());
- foreach ($links as $link) {
- if (!empty($link['attribs']['HREF']['data'])) {
- $href = trim($link['attribs']['HREF']['data']);
- $parsed = SimplePie_Misc::parse_url($href);
- if (empty($parsed['scheme']) || $parsed['scheme'] != 'javascript') {
- $current = SimplePie_Misc::parse_url($this->file->url);
- if (empty($parsed['authority']) || $parsed['authority'] == $current['authority']) {
- $this->local[] = SimplePie_Misc::absolutize_url($href, $this->file->url);
- } else {
- $this->elsewhere[] = SimplePie_Misc::absolutize_url($href, $this->file->url);
- }
- }
- }
- }
- if (!empty($this->local)) {
- $this->local = array_unique($this->local);
- }
- if (!empty($this->elsewhere)) {
- $this->elsewhere = array_unique($this->elsewhere);
- }
- if (!empty($this->local) || !empty($this->elsewhere)) {
- return true;
- }
- return false;
- }
-
- public function extension(&$array)
- {
- foreach ($array as $key => $value) {
- $value = SimplePie_Misc::absolutize_url($value, $this->file->url);
- if (in_array(strrchr($value, '.'), array('.rss', '.rdf', '.atom', '.xml'))) {
- if ($this->is_feed($value)) {
- return $value;
- } else {
- unset($array[$key]);
- }
- }
- }
- return false;
- }
-
- public function body(&$array)
- {
- foreach ($array as $key => $value) {
- $value = SimplePie_Misc::absolutize_url($value, $this->file->url);
- if (preg_match('/(rss|rdf|atom|xml)/i', $value)) {
- if ($this->is_feed($value)) {
- return $value;
- } else {
- unset($array[$key]);
- }
- }
- }
- return false;
- }
- }
-
- class SimplePie_Parser
- {
- public $encoding;
- public $data;
- public $namespaces = array('xml' => 'HTTP://WWW.W3.ORG/XML/1998/NAMESPACE', 'atom' => 'ATOM', 'rss2' => 'RSS', 'rdf' => 'RDF', 'rss1' => 'RSS', 'dc' => 'DC', 'xhtml' => 'XHTML', 'content' => 'CONTENT');
- public $xml;
- public $error_code;
- public $error_string;
- public $current_line;
- public $current_column;
- public $current_byte;
- public $tag_name;
- public $inside_item;
- public $item_number = 0;
- public $inside_channel;
- public $author_number= 0;
- public $category_number = 0;
- public $enclosure_number = 0;
- public $link_number = 0;
- public $item_link_number = 0;
- public $inside_image;
- public $attribs;
- public $is_first;
- public $inside_author;
- public $depth_inside_item = 0;
-
- public function __construct($data, $encoding, $return_xml = false)
- {
- $this->encoding = $encoding;
-
- // Strip BOM:
- // UTF-32 Big Endian BOM
- if (strpos($data, sprintf('%c%c%c%c', 0x00, 0x00, 0xFE, 0xFF)) === 0) {
- $data = substr($data, 4);
- }
- // UTF-32 Little Endian BOM
- elseif (strpos($data, sprintf('%c%c%c%c', 0xFF, 0xFE, 0x00, 0x00)) === 0) {
- $data = substr($data, 4);
- }
- // UTF-16 Big Endian BOM
- elseif (strpos($data, sprintf('%c%c', 0xFE, 0xFF)) === 0) {
- $data = substr($data, 2);
- }
- // UTF-16 Little Endian BOM
- elseif (strpos($data, sprintf('%c%c', 0xFF, 0xFE)) === 0) {
- $data = substr($data, 2);
- }
- // UTF-8 BOM
- elseif (strpos($data, sprintf('%c%c%c', 0xEF, 0xBB, 0xBF)) === 0) {
- $data = substr($data, 3);
- }
-
- // Make sure the XML prolog is sane and has the correct encoding
- if (preg_match('/^<\?xml(.*)?>/msiU', $data, $prolog)) {
- $data = substr_replace($data, '', 0, strlen($prolog[0]));
- }
- $data = "<?xml version='1.0' encoding='$encoding'?>\n" . $data;
-
- // Put some data into CDATA blocks
- // If we're RSS
- 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))) {
- $sp_elements = array(
- 'author',
- 'category',
- 'copyright',
- 'description',
- 'docs',
- 'generator',
- 'guid',
- 'language',
- 'lastBuildDate',
- 'link',
- 'managingEditor',
- 'pubDate',
- 'title',
- 'url',
- 'webMaster',
- );
- }
- // Or if we're Atom
- else {
- $sp_elements = array(
- 'content',
- 'copyright',
- 'name',
- 'subtitle',
- 'summary',
- 'tagline',
- 'title',
- );
- }
- foreach ($sp_elements as $full) {
- $data = preg_replace_callback("/<($full)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'))*)\s*(\/>|>(.*)<\/$full>)/msiU", array(&$this, 'add_cdata'), $data);
- }
- foreach ($sp_elements as $full) {
- // Deal with CDATA within CDATA (this can be caused by us inserting CDATA above)
- $data = preg_replace_callback("/<($full)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'))*)\s*(\/>|><!\[CDATA\[(.*)\]\]><\/$full>)/msiU", array(&$this, 'cdata_in_cdata'), $data);
- }
-
- // Return the XML, if so desired
- if ($return_xml) {
- $this->data =& $data;
- return;
- }
-
- // Create the parser
- $this->xml = xml_parser_create_ns($encoding);
- xml_parser_set_option($this->xml, XML_OPTION_SKIP_WHITE, 1);
- xml_set_object($this->xml, $this);
- xml_set_character_data_handler($this->xml, 'data_handler');
- xml_set_element_handler($this->xml, 'start_handler', 'end_handler');
- xml_set_start_namespace_decl_handler($this->xml, 'start_name_space');
- xml_set_end_namespace_decl_handler($this->xml, 'end_name_space');
-
- // Parse!
- if (!xml_parse($this->xml, $data)) {
- $this->data = null;
- $this->error_code = xml_get_error_code($this->xml);
- $this->error_string = xml_error_string($this->error_code);
- }
- $this->current_line = xml_get_current_line_number($this->xml);
- $this->current_column = xml_get_current_column_number($this->xml);
- $this->current_byte = xml_get_current_byte_index($this->xml);
- xml_parser_free($this->xml);
- return;
- }
-
- public function add_cdata($match)
- {
- if (isset($match[10])) {
- return "<$match[1]$match[2]><![CDATA[$match[10]]]></$match[1]>";
- }
- return $match[0];
- }
-
- public function cdata_in_cdata($match)
- {
- if (isset($match[10])) {
- $match[10] = preg_replace_callback('/<!\[CDATA\[(.*)\]\]>/msiU', array(&$this, 'real_cdata_in_cdata'), $match[10]);
- return "<$match[1]$match[2]><![CDATA[$match[10]]]></$match[1]>";
- }
- return $match[0];
- }
-
- public function real_cdata_in_cdata($match)
- {
- return htmlspecialchars($match[1], ENT_NOQUOTES);
- }
-
- public function do_add_content(&$array, $data)
- {
- if ($this->is_first) {
- $array['data'] = $data;
- $array['attribs'] = $this->attribs;
- } else {
- $array['data'] .= $data;
- }
- }
-
- public function start_handler($parser, $name, $attribs)
- {
- $this->tag_name = $name;
- $this->attribs = $attribs;
- $this->is_first = true;
-
- if ($this->inside_item) {
- $this->depth_inside_item++;
- }
-
- switch ($this->tag_name) {
- case 'ITEM':
- case $this->namespaces['rss2'] . ':ITEM':
- case $this->namespaces['rss1'] . ':ITEM':
- case 'ENTRY':
- case $this->namespaces['atom'] . ':ENTRY':
- $this->inside_item = true;
- $this->do_add_content($this->data['items'][$this->item_number], '');
- break;
-
- case 'CHANNEL':
- case $this->namespaces['rss2'] . ':CHANNEL':
- case $this->namespaces['rss1'] . ':CHANNEL':
- $this->inside_channel = true;
- break;
-
- case 'RSS':
- case $this->namespaces['rss2'] . ':RSS':
- $this->data['feedinfo']['type'] = 'RSS';
- $this->do_add_content($this->data['feeddata'], '');
- if (!empty($attribs['VERSION'])) {
- $this->data['feedinfo']['version'] = trim($attribs['VERSION']);
- }
- break;
-
- case $this->namespaces['rdf'] . ':RDF':
- $this->data['feedinfo']['type'] = 'RSS';
- $this->do_add_content($this->data['feeddata'], '');
- $this->data['feedinfo']['version'] = 1;
- break;
-
- case 'FEED':
- case $this->namespaces['atom'] . ':FEED':
- $this->data['feedinfo']['type'] = 'Atom';
- $this->do_add_content($this->data['feeddata'], '');
- if (!empty($attribs['VERSION'])) {
- $this->data['feedinfo']['version'] = trim($attribs['VERSION']);
- }
- break;
-
- case 'IMAGE':
- case $this->namespaces['rss2'] . ':IMAGE':
- case $this->namespaces['rss1'] . ':IMAGE':
- if ($this->inside_channel) {
- $this->inside_image = true;
- }
- break;
- }
-
- if (!empty($this->data['feedinfo']['type']) && $this->data['feedinfo']['type'] == 'Atom' && ($this->tag_name == 'AUTHOR' || $this->tag_name == $this->namespaces['atom'] . ':AUTHOR')) {
- $this->inside_author = true;
- }
- $this->data_handler($this->xml, '');
- }
-
- public function data_handler($parser, $data)
- {
- if ($this->inside_item && $this->depth_inside_item == 1) {
- switch ($this->tag_name) {
- case 'TITLE':
- case $this->namespaces['rss1'] . ':TITLE':
- case $this->namespaces['rss2'] . ':TITLE':
- case $this->namespaces['atom'] . ':TITLE':
- $this->do_add_content($this->data['items'][$this->item_number]['title'], $data);
- break;
-
- case $this->namespaces['dc'] . ':TITLE':
- $this->do_add_content($this->data['items'][$this->item_number]['dc:title'], $data);
- break;
-
- case 'CONTENT':
- case $this->namespaces['atom'] . ':CONTENT':
- $this->do_add_content($this->data['items'][$this->item_number]['content'], $data);
- break;
-
- case $this->namespaces['content'] . ':ENCODED':
- $this->do_add_content($this->data['items'][$this->item_number]['encoded'], $data);
- break;
-
- case 'SUMMARY':
- case $this->namespaces['atom'] . ':SUMMARY':
- $this->do_add_content($this->data['items'][$this->item_number]['summary'], $data);
- break;
-
- case 'LONGDESC':
- $this->do_add_content($this->data['items'][$this->item_number]['longdesc'], $data);
- break;
-
- case 'DESCRIPTION':
- case $this->namespaces['rss1'] . ':DESCRIPTION':
- case $this->namespaces['rss2'] . ':DESCRIPTION':
- $this->do_add_content($this->data['items'][$this->item_number]['description'], $data);
- break;
-
- case $this->namespaces['dc'] . ':DESCRIPTION':
- $this->do_add_content($this->data['items'][$this->item_number]['dc:description'], $data);
- break;
-
- case 'LINK':
- case $this->namespaces['rss1'] . ':LINK':
- case $this->namespaces['rss2'] . ':LINK':
- case $this->namespaces['atom'] . ':LINK':
- $this->do_add_content($this->data['items'][$this->item_number]['link'][$this->item_link_number], $data);
- break;
-
- case 'ENCLOSURE':
- case $this->namespaces['rss1'] . ':ENCLOSURE':
- case $this->namespaces['rss2'] . ':ENCLOSURE':
- case $this->namespaces['atom'] . ':ENCLOSURE':
- $this->do_add_content($this->data['items'][$this->item_number]['enclosure'][$this->enclosure_number], $data);
- break;
-
- case 'GUID':
- case $this->namespaces['rss1'] . ':GUID':
- case $this->namespaces['rss2'] . ':GUID':
- $this->do_add_content($this->data['items'][$this->item_number]['guid'], $data);
- break;
-
- case 'ID':
- case $this->namespaces['atom'] . ':ID':
- $this->do_add_content($this->data['items'][$this->item_number]['id'], $data);
- break;
-
- case 'PUBDATE':
- case $this->namespaces['rss1'] . ':PUBDATE':
- case $this->namespaces['rss2'] . ':PUBDATE':
- $this->do_add_content($this->data['items'][$this->item_number]['pubdate'], $data);
- break;
-
- case $this->namespaces['dc'] . ':DATE':
- $this->do_add_content($this->data['items'][$this->item_number]['dc:date'], $data);
- break;
-
- case 'ISSUED':
- case $this->namespaces['atom'] . ':ISSUED':
- $this->do_add_content($this->data['items'][$this->item_number]['issued'], $data);
- break;
-
- case 'PUBLISHED':
- case $this->namespaces['atom'] . ':PUBLISHED':
- $this->do_add_content($this->data['items'][$this->item_number]['published'], $data);
- break;
-
- case 'MODIFIED':
- case $this->namespaces['atom'] . ':MODIFIED':
- $this->do_add_content($this->data['items'][$this->item_number]['modified'], $data);
- break;
-
- case 'UPDATED':
- case $this->namespaces['atom'] . ':UPDATED':
- $this->do_add_content($this->data['items'][$this->item_number]['updated'], $data);
- break;
-
- case 'CATEGORY':
- case $this->namespaces['rss1'] . ':CATEGORY':
- case $this->namespaces['rss2'] . ':CATEGORY':
- case $this->namespaces['atom'] . ':CATEGORY':
- $this->do_add_content($this->data['items'][$this->item_number]['category'][$this->category_number], $data);
- break;
-
- case $this->namespaces['dc'] . ':SUBJECT':
- $this->do_add_content($this->data['items'][$this->item_number]['subject'][$this->category_number], $data);
- break;
-
- case $this->namespaces['dc'] . ':CREATOR':
- $this->do_add_content($this->data['items'][$this->item_number]['creator'][$this->author_number], $data);
- break;
-
- case 'AUTHOR':
- case $this->namespaces['rss1'] . ':AUTHOR':
- case $this->namespaces['rss2'] . ':AUTHOR':
- $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['rss'], $data);
- break;
- }
-
- if ($this->inside_author) {
- switch ($this->tag_name) {
- case 'NAME':
- case $this->namespaces['atom'] . ':NAME':
- $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['name'], $data);
- break;
-
- case 'URL':
- case $this->namespaces['atom'] . ':URL':
- $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['url'], $data);
- break;
-
- case 'URI':
- case $this->namespaces['atom'] . ':URI':
- $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['uri'], $data);
- break;
-
- case 'HOMEPAGE':
- case $this->namespaces['atom'] . ':HOMEPAGE':
- $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['homepage'], $data);
- break;
-
- case 'EMAIL':
- case $this->namespaces['atom'] . ':EMAIL':
- $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['email'], $data);
- break;
- }
- }
- } elseif (($this->inside_channel && !$this->inside_image) || (isset($this->data['feedinfo']['type']) && $this->data['feedinfo']['type'] == 'Atom')) {
- switch ($this->tag_name) {
- case 'TITLE':
- case $this->namespaces['rss1'] . ':TITLE':
- case $this->namespaces['rss2'] . ':TITLE':
- case $this->namespaces['atom'] . ':TITLE':
- $this->do_add_content($this->data['info']['title'], $data);
- break;
-
- case 'LINK':
- case $this->namespaces['rss1'] . ':LINK':
- case $this->namespaces['rss2'] . ':LINK':
- case $this->namespaces['atom'] . ':LINK':
- $this->do_add_content($this->data['info']['link'][$this->link_number], $data);
- break;
-
- case 'DESCRIPTION':
- case $this->namespaces['rss1'] . ':DESCRIPTION':
- case $this->namespaces['rss2'] . ':DESCRIPTION':
- $this->do_add_content($this->data['info']['description'], $data);
- break;
-
- case $this->namespaces['dc'] . ':DESCRIPTION':
- $this->do_add_content($this->data['info']['dc:description'], $data);
- break;
-
- case 'TAGLINE':
- case $this->namespaces['atom'] . ':TAGLINE':
- $this->do_add_content($this->data['info']['tagline'], $data);
- break;
-
- case 'SUBTITLE':
- case $this->namespaces['atom'] . ':SUBTITLE':
- $this->do_add_content($this->data['info']['subtitle'], $data);
- break;
-
- case 'COPYRIGHT':
- case $this->namespaces['rss1'] . ':COPYRIGHT':
- case $this->namespaces['rss2'] . ':COPYRIGHT':
- case $this->namespaces['atom'] . ':COPYRIGHT':
- $this->do_add_content($this->data['info']['copyright'], $data);
- break;
-
- case 'LANGUAGE':
- case $this->namespaces['rss1'] . ':LANGUAGE':
- case $this->namespaces['rss2'] . ':LANGUAGE':
- $this->do_add_content($this->data['info']['language'], $data);
- break;
-
- case 'LOGO':
- case $this->namespaces['atom'] . ':LOGO':
- $this->do_add_content($this->data['info']['logo'], $data);
- break;
-
- }
- } elseif ($this->inside_channel && $this->inside_image) {
- switch ($this->tag_name) {
- case 'TITLE':
- case $this->namespaces['rss1'] . ':TITLE':
- case $this->namespaces['rss2'] . ':TITLE':
- $this->do_add_content($this->data['info']['image']['title'], $data);
- break;
-
- case 'URL':
- case $this->namespaces['rss1'] . ':URL':
- case $this->namespaces['rss2'] . ':URL':
- $this->do_add_content($this->data['info']['image']['url'], $data);
- break;
-
- case 'LINK':
- case $this->namespaces['rss1'] . ':LINK':
- case $this->namespaces['rss2'] . ':LINK':
- $this->do_add_content($this->data['info']['image']['link'], $data);
- break;
-
- case 'WIDTH':
- case $this->namespaces['rss1'] . ':WIDTH':
- case $this->namespaces['rss2'] . ':WIDTH':
- $this->do_add_content($this->data['info']['image']['width'], $data);
- break;
-
- case 'HEIGHT':
- case $this->namespaces['rss1'] . ':HEIGHT':
- case $this->namespaces['rss2'] . ':HEIGHT':
- $this->do_add_content($this->data['info']['image']['height'], $data);
- break;
- }
- }
- $this->is_first = false;
- }
-
- public function end_handler($parser, $name)
- {
- $this->tag_name = '';
- switch ($name) {
- case 'ITEM':
- case $this->namespaces['rss1'] . ':ITEM':
- case $this->namespaces['rss2'] . ':ITEM':
- case 'ENTRY':
- case $this->namespaces['atom'] . ':ENTRY':
- $this->inside_item = false;
- $this->item_number++;
- $this->author_number = 0;
- $this->category_number = 0;
- $this->enclosure_number = 0;
- $this->item_link_number = 0;
- break;
-
- case 'CHANNEL':
- case $this->namespaces['rss1'] . ':CHANNEL':
- case $this->namespaces['rss2'] . ':CHANNEL':
- $this->inside_channel = false;
- break;
-
- case 'IMAGE':
- case $this->namespaces['rss1'] . ':IMAGE':
- case $this->namespaces['rss2'] . ':IMAGE':
- $this->inside_image = false;
- break;
-
- case 'AUTHOR':
- case $this->namespaces['rss1'] . ':AUTHOR':
- case $this->namespaces['rss2'] . ':AUTHOR':
- case $this->namespaces['atom'] . ':AUTHOR':
- $this->author_number++;
- $this->inside_author = false;
- break;
-
- case 'CATEGORY':
- case $this->namespaces['rss1'] . ':CATEGORY':
- case $this->namespaces['rss2'] . ':CATEGORY':
- case $this->namespaces['atom'] . ':CATEGORY':
- case $this->namespaces['dc'] . ':SUBJECT':
- $this->category_number++;
- break;
-
- case 'ENCLOSURE':
- case $this->namespaces['rss1'] . ':ENCLOSURE':
- case $this->namespaces['rss2'] . ':ENCLOSURE':
- $this->enclosure_number++;
- break;
-
- case 'LINK':
- case $this->namespaces['rss1'] . ':LINK':
- case $this->namespaces['rss2'] . ':LINK':
- case $this->namespaces['atom'] . ':LINK':
- if ($this->inside_item) {
- $this->item_link_number++;
- } else {
- $this->link_number++;
- }
- break;
- }
- if ($this->inside_item) {
- $this->depth_inside_item--;
- }
- }
-
- public function start_name_space($parser, $prefix, $uri = null)
- {
- $prefix = strtoupper($prefix);
- $uri = strtoupper($uri);
- if ($prefix == 'ATOM' || $uri == 'HTTP://WWW.W3.ORG/2005/ATOM' || $uri == 'HTTP://PURL.ORG/ATOM/NS#') {
- $this->namespaces['atom'] = $uri;
- } elseif ($prefix == 'RSS2' || $uri == 'HTTP://BACKEND.USERLAND.COM/RSS2') {
- $this->namespaces['rss2'] = $uri;
- } elseif ($prefix == 'RDF' || $uri == 'HTTP://WWW.W3.ORG/1999/02/22-RDF-SYNTAX-NS#') {
- $this->namespaces['rdf'] = $uri;
- } elseif ($prefix == 'RSS' || $uri == 'HTTP://PURL.ORG/RSS/1.0/' || $uri == 'HTTP://MY.NETSCAPE.COM/RDF/SIMPLE/0.9/') {
- $this->namespaces['rss1'] = $uri;
- } elseif ($prefix == 'DC' || $uri == 'HTTP://PURL.ORG/DC/ELEMENTS/1.1/') {
- $this->namespaces['dc'] = $uri;
- } elseif ($prefix == 'XHTML' || $uri == 'HTTP://WWW.W3.ORG/1999/XHTML') {
- $this->namespaces['xhtml'] = $uri;
- $this->xhtml_prefix = $prefix;
- } elseif ($prefix == 'CONTENT' || $uri == 'HTTP://PURL.ORG/RSS/1.0/MODULES/CONTENT/') {
- $this->namespaces['content'] = $uri;
- }
- }
-
- public function end_name_space($parser, $prefix)
- {
- if ($key = array_search(strtoupper($prefix), $this->namespaces)) {
- if ($key == 'atom') {
- $this->namespaces['atom'] = 'ATOM';
- } elseif ($key == 'rss2') {
- $this->namespaces['rss2'] = 'RSS';
- } elseif ($key == 'rdf') {
- $this->namespaces['rdf'] = 'RDF';
- } elseif ($key == 'rss1') {
- $this->namespaces['rss1'] = 'RSS';
- } elseif ($key == 'dc') {
- $this->namespaces['dc'] = 'DC';
- } elseif ($key == 'xhtml') {
- $this->namespaces['xhtml'] = 'XHTML';
- $this->xhtml_prefix = 'XHTML';
- } elseif ($key == 'content') {
- $this->namespaces['content'] = 'CONTENT';
- }
- }
- }
- }
-
- class SimplePie_Sanitize
- {
- // Private vars
- public $feedinfo;
- public $info;
- public $items;
- public $feed_xmlbase;
- public $item_xmlbase;
- public $attribs;
- public $cached_entities;
- public $cache_convert_entities;
-
- // Options
- public $remove_div = true;
- public $strip_ads = false;
- public $replace_headers = false;
- public $bypass_image_hotlink = false;
- public $bypass_image_hotlink_page = false;
- public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
- public $encode_instead_of_strip = false;
- public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur');
- public $input_encoding = 'UTF-8';
- public $output_encoding = 'UTF-8';
- public $item_class = 'SimplePie_Item';
- public $author_class = 'SimplePie_Author';
- public $enclosure_class = 'SimplePie_Enclosure';
-
- public function remove_div($enable = true)
- {
- $this->remove_div = (bool) $enable;
- }
-
- public function strip_ads($enable = false)
- {
- $this->strip_ads = (bool) $enable;
- }
-
- public function replace_headers($enable = false)
- {
- $this->enable_headers = (bool) $enable;
- }
-
- public function bypass_image_hotlink($get = false)
- {
- if ($get) {
- $this->bypass_image_hotlink = (string) $get;
- } else {
- $this->bypass_image_hotlink = false;
- }
- }
-
- public function bypass_image_hotlink_page($page = false)
- {
- if ($page) {
- $this->bypass_image_hotlink_page = (string) $page;
- } else {
- $this->bypass_image_hotlink_page = false;
- }
- }
-
- public function strip_htmltags($tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'))
- {
- if ($tags) {
- if (is_array($tags)) {
- $this->strip_htmltags = $tags;
- } else {
- $this->strip_htmltags = explode(',', $tags);
- }
- } else {
- $this->strip_htmltags = false;
- }
- }
-
- public function encode_instead_of_strip($enable = false)
- {
- $this->encode_instead_of_strip = (bool) $enable;
- }
-
- public function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur'))
- {
- if ($attribs) {
- if (is_array($attribs)) {
- $this->strip_attributes = $attribs;
- } else {
- $this->strip_attributes = explode(',', $attribs);
- }
- } else {
- $this->strip_attributes = false;
- }
- }
-
- public function input_encoding($encoding = 'UTF-8')
- {
- $this->input_encoding = (string) $encoding;
- }
-
- public function output_encoding($encoding = 'UTF-8')
- {
- $this->output_encoding = (string) $encoding;
- }
-
- public function set_item_class($class = 'SimplePie_Item')
- {
- if (SimplePie_Misc::is_a_class($class, 'SimplePie_Item')) {
- $this->item_class = $class;
- return true;
- }
- return false;
- }
-
- public function set_author_class($class = 'SimplePie_Author')
- {
- if (SimplePie_Misc::is_a_class($class, 'SimplePie_Author')) {
- $this->author_class = $class;
- return true;
- }
- return false;
- }
-
- public function set_enclosure_class($class = 'SimplePie_Enclosure')
- {
- if (SimplePie_Misc::is_a_class($class, 'SimplePie_Enclosure')) {
- $this->enclosure_class = $class;
- return true;
- }
- return false;
- }
-
- public function parse_data_array(&$data, $url)
- {
- // Feed Info (Type and Version)
- if (!empty($data['feedinfo']['type'])) {
- $this->feedinfo = $data['feedinfo'];
- }
-
- // Feed level xml:base
- if (!empty($data['feeddata']['attribs']['XML:BASE'])) {
- $this->feed_xmlbase = $data['feeddata']['attribs']['XML:BASE'];
- } elseif (!empty($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'])) {
- $this->feed_xmlbase = $data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'];
- }
- // FeedBurner feeds use alternate link
- elseif (strpos($url, 'http://feeds.feedburner.com/') !== 0) {
- $this->feed_xmlbase = SimplePie_Misc::parse_url($url);
- if (empty($this->feed_xmlbase['authority'])) {
- $this->feed_xmlbase = preg_replace('/^' . preg_quote(realpath($_SERVER['DOCUMENT_ROOT']), '/') . '/', '', realpath($url));
- } else {
- $this->feed_xmlbase = $url;
- }
- }
-
-
- // Feed link(s)
- if (!empty($data['info']['link'])) {
- foreach ($data['info']['link'] as $link) {
- if (empty($link['attribs']['REL'])) {
- $rel = 'alternate';
- } else {
- $rel = strtolower($link['attribs']['REL']);
- }
- if ($rel == 'enclosure') {
- $href = null;
- $type = null;
- $length = null;
- if (!empty($link['data'])) {
- $href = $this->sanitize($link['data'], $link['attribs'], true);
- } elseif (!empty($link['attribs']['HREF'])) {
- $href = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
- }
- if (!empty($link['attribs']['TYPE'])) {
- $type = $this->sanitize($link['attribs']['TYPE'], $link['attribs']);
- }
- if (!empty($link['attribs']['LENGTH'])) {
- $length = $this->sanitize($link['attribs']['LENGTH'], $link['attribs']);
- }
- $this->info['link']['enclosure'][] = new $this->enclosure_class($href, $type, $length);
- } else {
- if (!empty($link['data'])) {
- $this->info['link'][$rel][] = $this->sanitize($link['data'], $link['attribs'], true);
- } elseif (!empty($link['attribs']['HREF'])) {
- $this->info['link'][$rel][] = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
- }
- }
- }
- }
-
- // Use the first alternate link if we don't have any feed xml:base
- if (empty($this->feed_xmlbase) && !empty($this->info['link']['alternate'][0])) {
- $this->feed_xmlbase = $this->info['link']['alternate'][0];
- }
-
- // Feed Title
- if (!empty($data['info']['title']['data'])) {
- $this->info['title'] = $this->sanitize($data['info']['title']['data'], $data['info']['title']['attribs']);
- }
-
- // Feed Descriptions
- if (!empty($data['info']['description']['data'])) {
- $this->info['description'] = $this->sanitize($data['info']['description']['data'], $data['info']['description']['attribs'], false, true);
- }
- if (!empty($data['info']['dc:description']['data'])) {
- $this->info['dc:description'] = $this->sanitize($data['info']['dc:description']['data'], $data['info']['dc:description']['attribs']);
- }
- if (!empty($data['info']['tagline']['data'])) {
- $this->info['tagline'] = $this->sanitize($data['info']['tagline']['data'], $data['info']['tagline']['attribs']);
- }
- if (!empty($data['info']['subtitle']['data'])) {
- $this->info['subtitle'] = $this->sanitize($data['info']['subtitle']['data'], $data['info']['subtitle']['attribs']);
- }
-
- // Feed Language
- if (!empty($data['info']['language']['data'])) {
- $this->info['language'] = $this->sanitize($data['info']['language']['data'], $data['info']['language']['attribs']);
- }
- if (!empty($data['feeddata']['attribs']['XML:LANG'])) {
- $this->info['xml:lang'] = $this->sanitize($data['feeddata']['attribs']['XML:LANG'], null);
- } elseif (!empty($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:LANG'])) {
- $this->info['xml:lang'] = $this->sanitize($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:LANG'], null);
- }
-
- // Feed Copyright
- if (!empty($data['info']['copyright']['data'])) {
- $this->info['copyright'] = $this->sanitize($data['info']['copyright']['data'], $data['info']['copyright']['attribs']);
- }
-
- // Feed Image
- if (!empty($data['info']['image']['title']['data'])) {
- $this->info['image']['title'] = $this->sanitize($data['info']['image']['title']['data'], $data['info']['image']['title']['attribs']);
- }
- if (!empty($data['info']['image']['url']['data'])) {
- $this->info['image']['url'] = $this->sanitize($data['info']['image']['url']['data'], $data['info']['image']['url']['attribs'], true);
- }
- if (!empty($data['info']['logo']['data'])) {
- $this->info['image']['logo'] = $this->sanitize($data['info']['logo']['data'], $data['info']['logo']['attribs'], true);
- }
- if (!empty($data['info']['image']['link']['data'])) {
- $this->info['image']['link'] = $this->sanitize($data['info']['image']['link']['data'], $data['info']['image']['link']['attribs'], true);
- }
- if (!empty($data['info']['image']['width']['data'])) {
- $this->info['image']['width'] = $this->sanitize($data['info']['image']['width']['data'], $data['info']['image']['width']['attribs']);
- }
- if (!empty($data['info']['image']['height']['data'])) {
- $this->info['image']['height'] = $this->sanitize($data['info']['image']['height']['data'], $data['info']['image']['height']['attribs']);
- }
-
- // Items
- if (!empty($data['items'])) {
- foreach ($data['items'] as $key => $item) {
- $newitem = null;
-
- // Item level xml:base
- if (!empty($item['attribs']['XML:BASE'])) {
- $this->item_xmlbase = SimplePie_Misc::absolutize_url($item['attribs']['XML:BASE'], $this->feed_xmlbase);
- } elseif (!empty($item['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'])) {
- $this->item_xmlbase = SimplePie_Misc::absolutize_url($item['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'], $this->feed_xmlbase);
- } else {
- $this->item_xmlbase = null;
- }
-
- // Title
- if (!empty($item['title']['data'])) {
- $newitem['title'] = $this->sanitize($item['title']['data'], $item['title']['attribs']);
- }
- if (!empty($item['dc:title']['data'])) {
- $newitem['dc:title'] = $this->sanitize($item['dc:title']['data'], $item['dc:title']['attribs']);
- }
-
- // Description
- if (!empty($item['content']['data'])) {
- $newitem['content'] = $this->sanitize($item['content']['data'], $item['content']['attribs']);
- }
- if (!empty($item['encoded']['data'])) {
- $newitem['encoded'] = $this->sanitize($item['encoded']['data'], $item['encoded']['attribs']);
- }
- if (!empty($item['summary']['data'])) {
- $newitem['summary'] = $this->sanitize($item['summary']['data'], $item['summary']['attribs']);
- }
- if (!empty($item['description']['data'])) {
- $newitem['description'] = $this->sanitize($item['description']['data'], $item['description']['attribs'], false, true);
- }
- if (!empty($item['dc:description']['data'])) {
- $newitem['dc:description'] = $this->sanitize($item['dc:description']['data'], $item['dc:description']['attribs']);
- }
- if (!empty($item['longdesc']['data'])) {
- $newitem['longdesc'] = $this->sanitize($item['longdesc']['data'], $item['longdesc']['attribs']);
- }
-
- // Link(s)
- if (!empty($item['link'])) {
- foreach ($item['link'] as $link) {
- if (empty($link['attribs']['REL'])) {
- $rel = 'alternate';
- } else {
- $rel = strtolower($link['attribs']['REL']);
- }
- if ($rel == 'enclosure') {
- $href = null;
- $type = null;
- $length = null;
- if (!empty($link['data'])) {
- $href = $this->sanitize($link['data'], $link['attribs'], true);
- } elseif (!empty($link['attribs']['HREF'])) {
- $href = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
- }
- if (!empty($link['attribs']['TYPE'])) {
- $type = $this->sanitize($link['attribs']['TYPE'], $link['attribs']);
- }
- if (!empty($link['attribs']['LENGTH'])) {
- $length = $this->sanitize($link['attribs']['LENGTH'], $link['attribs']);
- }
- if (!empty($href)) {
- $newitem['link'][$rel][] = new $this->enclosure_class($href, $type, $length);
- }
- } else {
- if (!empty($link['data'])) {
- $newitem['link'][$rel][] = $this->sanitize($link['data'], $link['attribs'], true);
- } elseif (!empty($link['attribs']['HREF'])) {
- $newitem['link'][$rel][] = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
- }
- }
- }
- }
-
- // Enclosure(s)
- if (!empty($item['enclosure'])) {
- foreach ($item['enclosure'] as $enclosure) {
- if (!empty($enclosure['attribs']['URL'])) {
- $type = null;
- $length = null;
- $href = $this->sanitize($enclosure['attribs']['URL'], $enclosure['attribs'], true);
- if (!empty($enclosure['attribs']['TYPE'])) {
- $type = $this->sanitize($enclosure['attribs']['TYPE'], $enclosure['attribs']);
- }
- if (!empty($enclosure['attribs']['LENGTH'])) {
- $length = $this->sanitize($enclosure['attribs']['LENGTH'], $enclosure['attribs']);
- }
- $newitem['enclosures'][] = new $this->enclosure_class($href, $type, $length);
- }
- }
- }
-
- // ID
- if (!empty($item['guid']['data'])) {
- if (!empty($item['guid']['attribs']['ISPERMALINK']) && strtolower($item['guid']['attribs']['ISPERMALINK']) == 'false') {
- $newitem['guid']['permalink'] = false;
- } else {
- $newitem['guid']['permalink'] = true;
- }
- $newitem['guid']['data'] = $this->sanitize($item['guid']['data'], $item['guid']['attribs']);
- }
- if (!empty($item['id']['data'])) {
- $newitem['id'] = $this->sanitize($item['id']['data'], $item['id']['attribs']);
- }
-
- // Date
- if (!empty($item['pubdate']['data'])) {
- $newitem['pubdate'] = $this->parse_date($this->sanitize($item['pubdate']['data'], $item['pubdate']['attribs']));
- }
- if (!empty($item['dc:date']['data'])) {
- $newitem['dc:date'] = $this->parse_date($this->sanitize($item['dc:date']['data'], $item['dc:date']['attribs']));
- }
- if (!empty($item['issued']['data'])) {
- $newitem['issued'] = $this->parse_date($this->sanitize($item['issued']['data'], $item['issued']['attribs']));
- }
- if (!empty($item['published']['data'])) {
- $newitem['published'] = $this->parse_date($this->sanitize($item['published']['data'], $item['published']['attribs']));
- }
- if (!empty($item['modified']['data'])) {
- $newitem['modified'] = $this->parse_date($this->sanitize($item['modified']['data'], $item['modified']['attribs']));
- }
- if (!empty($item['updated']['data'])) {
- $newitem['updated'] = $this->parse_date($this->sanitize($item['updated']['data'], $item['updated']['attribs']));
- }
-
- // Categories
- if (!empty($item['category'])) {
- foreach ($item['category'] as $category) {
- if (!empty($category['data'])) {
- $newitem['category'][] = $this->sanitize($category['data'], $category['attribs']);
- } elseif (!empty($category['attribs']['TERM'])) {
- $newitem['term'][] = $this->sanitize($category['attribs']['TERM'], $category['attribs']);
- }
- }
- }
- if (!empty($item['subject'])) {
- foreach ($item['subject'] as $category) {
- if (!empty($category['data'])) {
- $newitem['subject'][] = $this->sanitize($category['data'], $category['attribs']);
- }
- }
- }
-
- // Author
- if (!empty($item['creator'])) {
- foreach ($item['creator'] as $creator) {
- if (!empty($creator['data'])) {
- $newitem['creator'][] = new $this->author_class($this->sanitize($creator['data'], $creator['attribs']), null, null);
- }
- }
- }
- if (!empty($item['author'])) {
- foreach ($item['author'] as $author) {
- $name = null;
- $link = null;
- $email = null;
- if (!empty($author['rss'])) {
- $sane = $this->sanitize($author['rss']['data'], $author['rss']['attribs']);
- if (preg_match('/(.*)@(.*) \((.*)\)/msiU', $sane, $matches)) {
- $name = trim($matches[3]);
- $email = trim("$matches[1]@$matches[2]");
- } else {
- $email = $sane;
- }
- } else {
- if (!empty($author['name'])) {
- $name = $this->sanitize($author['name']['data'], $author['name']['attribs']);
- }
- if (!empty($author['url'])) {
- $link = $this->sanitize($author['url']['data'], $author['url']['attribs'], true);
- } elseif (!empty($author['uri'])) {
- $link = $this->sanitize($author['uri']['data'], $author['uri']['attribs'], true);
- } elseif (!empty($author['homepage'])) {
- $link = $this->sanitize($author['homepage']['data'], $author['homepage']['attribs'], true);
- }
- if (!empty($author['email'])) {
- $email = $this->sanitize($author['email']['data'], $author['email']['attribs']);
- }
- }
- $newitem['author'][] = new $this->author_class($name, $link, $email);
- }
- }
- unset($data['items'][$key]);
- $this->items[] = new $this->item_class($newitem);
- }
- }
- }
-
- public function sanitize($data, $attribs, $is_url = false, $force_decode = false)
- {
- $this->attribs = $attribs;
- if (isset($this->feedinfo['type']) && $this->feedinfo['type'] == 'Atom') {
- if ((!empty($attribs['MODE']) && $attribs['MODE'] == 'base64') || (!empty($attribs['TYPE']) && $attribs['TYPE'] == 'application/octet-stream')) {
- $data = trim($data);
- $data = base64_decode($data);
- } elseif ((!empty($attribs['MODE']) && $attribs['MODE'] == 'escaped' || !empty($attribs['TYPE']) && ($attribs['TYPE'] == 'html' || $attribs['TYPE'] == 'text/html'))) {
- $data = $this->entities_decode($data);
- }
- if (!empty($attribs['TYPE']) && ($attribs['TYPE'] == 'xhtml' || $attribs['TYPE'] == 'application/xhtml+xml')) {
- if ($this->remove_div) {
- $data = preg_replace('/<div( .*)?>/msiU', '', strrev(preg_replace('/>vid\/</i', '', strrev($data), 1)), 1);
- } else {
- $data = preg_replace('/<div( .*)?>/msiU', '<div>', $data, 1);
- }
- $data = $this->convert_entities($data);
- }
- } else {
- $data = $this->convert_entities($data);
- }
- if ($force_decode) {
- $data = $this->entities_decode($data);
- }
- $data = trim($data);
- $data = preg_replace('/<\!--([^-]|-[^-])*-->/msiU', '', $data);
-
- // If Strip Ads is enabled, strip them.
- if ($this->strip_ads) {
- $data = preg_replace('/<a (.*)href=(.*)click\.phdo\?s=(.*)<\/a>/msiU', '', $data); // Pheedo links (tested with Dooce.com)
- $data = preg_replace('/<p(.*)>(.*)<a href="http:\/\/ad.doubleclick.net\/jump\/(.*)<\/p>/msiU', '', $data); // Doubleclick links (tested with InfoWorld.com)
- $data = preg_replace('/<p><map (.*)name=(.*)google_ad_map(.*)<\/p>/msiU', '', $data); // Google AdSense for Feeds (tested with tuaw.com).
- // Feedflare, from Feedburner
- }
-
- // Replace H1, H2, and H3 tags with the less important H4 tags.
- // This is because on a site, the more important headers might make sense,
- // but it most likely doesn't fit in the context of RSS-in-a-webpage.
- if ($this->replace_headers) {
- $data = preg_replace('/<h[1-3]((\s*((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(.*)))*)\s*>/msiU', '<h4\\1>', $data);
- $data = preg_replace('/<\/h[1-3]>/i', '</h4>', $data);
- }
-
- if ($is_url) {
- $data = $this->replace_urls($data, true);
- } else {
- $data = preg_replace_callback('/<(\S+)((\s*((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(.*)))*)\s*(\/>|>(.*)<\/\S+>)/msiU', array(&$this, 'replace_urls'), $data);
- }
-
- // If Bypass Image Hotlink is enabled, rewrite all the image tags.
- if ($this->bypass_image_hotlink) {
- $images = SimplePie_Misc::get_element('img', $data);
- foreach ($images as $img) {
- if (!empty($img['attribs']['SRC']['data'])) {
- $pre = '';
- if ($this->bypass_image_hotlink_page) {
- $pre = $this->bypass_image_hotlink_page;
- }
- $pre .= "?$this->bypass_image_hotlink=";
- $img['attribs']['SRC']['data'] = $pre . rawurlencode(strtr($img['attribs']['SRC']['data'], array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES))));
- $data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data);
- }
- }
- }
-
- // Strip out HTML tags and attributes that might cause various security problems.
- // Based on recommendations by Mark Pilgrim at:
- // http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely
- if ($this->strip_htmltags) {
- foreach ($this->strip_htmltags as $tag) {
- $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);
- }
- }
-
- if ($this->strip_attributes) {
- foreach ($this->strip_attributes as $attrib) {
- $data = preg_replace('/ '. trim($attrib) .'=("|")(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|\'|'|<|>|\+|{|})*("|")/i', '', $data);
- $data = preg_replace('/ '. trim($attrib) .'=(\'|')(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|"|"|<|>|\+|{|})*(\'|')/i', '', $data);
- $data = preg_replace('/ '. trim($attrib) .'=(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|\+|{|})*/i', '', $data);
- }
- }
-
- // Convert encoding
- $data = SimplePie_Misc::change_encoding($data, $this->input_encoding, $this->output_encoding);
-
- return $data;
- }
-
- public function do_strip_htmltags($match)
- {
- if ($this->encode_instead_of_strip) {
- if (isset($match[12]) && !in_array(strtolower($match[1]), array('script', 'style'))) {
- return "<$match[1]$match[2]>$match[12]</$match[1]>";
- } elseif (isset($match[12])) {
- return "<$match[1]$match[2]></$match[1]>";
- } else {
- return "<$match[1]$match[2]/>";
- }
- } else {
- if (isset($match[12]) && !in_array(strtolower($match[1]), array('script', 'style'))) {
- return $match[12];
- } else {
- return '';
- }
- }
- }
-
- public function replace_urls($data, $raw_url = false)
- {
- if (!empty($this->attribs['XML:BASE'])) {
- $xmlbase = $attribs['XML:BASE'];
- } elseif (!empty($this->attribs['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'])) {
- $xmlbase = $this->attribs['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'];
- }
- if (!empty($xmlbase)) {
- if (!empty($this->item_xmlbase)) {
- $xmlbase = SimplePie_Misc::absolutize_url($xmlbase, $this->item_xmlbase);
- } else {
- $xmlbase = SimplePie_Misc::absolutize_url($xmlbase, $this->feed_xmlbase);
- }
- } elseif (!empty($this->item_xmlbase)) {
- $xmlbase = $this->item_xmlbase;
- } else {
- $xmlbase = $this->feed_xmlbase;
- }
-
- if ($raw_url) {
- return SimplePie_Misc::absolutize_url($data, $xmlbase);
- } else {
- $attributes = array(
- 'background',
- 'href',
- 'src',
- 'longdesc',
- 'usemap',
- 'codebase',
- 'data',
- 'classid',
- 'cite',
- 'action',
- 'profile',
- 'for'
- );
- foreach ($attributes as $attribute) {
- if (preg_match("/$attribute='(.*)'/siU", $data[0], $attrib) || preg_match("/$attribute=\"(.*)\"/siU", $data[0], $attrib) || preg_match("/$attribute=(.*)[ |\/|>]/siU", $data[0], $attrib)) {
- $new_tag = str_replace($attrib[1], SimplePie_Misc::absolutize_url($attrib[1], $xmlbase), $attrib[0]);
- $data[0] = str_replace($attrib[0], $new_tag, $data[0]);
- }
- }
- return $data[0];
- }
- }
-
- public function entities_decode($data)
- {
- return preg_replace_callback('/&(#)?(x)?([0-9a-z]+);/mi', array(&$this, 'do_entites_decode'), $data);
- }
-
- public function do_entites_decode($data)
- {
- if (isset($this->cached_entities[$data[0]])) {
- return $this->cached_entities[$data[0]];
- } else {
- $return = SimplePie_Misc::change_encoding(html_entity_decode($data[0], ENT_QUOTES), 'ISO-8859-1', $this->input_encoding);
- if ($return == $data[0]) {
- $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);
- }
- $this->cached_entities[$data[0]] = $return;
- return $return;
- }
- }
-
- public function convert_entities($data)
- {
- return preg_replace_callback('/&#(x)?([0-9a-z]+);/mi', array(&$this, 'do_convert_entities'), $data);
- }
-
- public function do_convert_entities($data)
- {
- if (isset($this->cache_convert_entities[$data[0]])) {
- return $this->cache_convert_entities[$data[0]];
- } elseif (isset($this->cached_entities[$data[0]])) {
- $return = htmlentities($this->cached_entities[$data[0]], ENT_QUOTES, 'UTF-8');
- } else {
- $return = htmlentities(preg_replace_callback('/&#([x]?[0-9a-f]+);/mi', array(&$this, 'replace_num_entity'), $data[0]), ENT_QUOTES, 'UTF-8');
- }
- $this->cache_convert_entities[$data[0]] = $return;
- return $return;
- }
-
- /*
- * Escape numeric entities
- * From a PHP Manual note (on html_entity_decode())
- * Copyright (c) 2005 by "php dot net at c dash ovidiu dot tk",
- * "emilianomartinezluque at yahoo dot com" and "hurricane at cyberworldz dot org".
- *
- * This material may be distributed only subject to the terms and conditions set forth in
- * the Open Publication License, v1.0 or later (the latest version is presently available at
- * http://www.opencontent.org/openpub/).
- */
- public function replace_num_entity($ord)
- {
- $ord = $ord[1];
- if (preg_match('/^x([0-9a-f]+)$/i', $ord, $match)) {
- $ord = hexdec($match[1]);
- } else {
- $ord = intval($ord);
- }
-
- $no_bytes = 0;
- $byte = array();
- if ($ord < 128) {
- return chr($ord);
- }
- if ($ord < 2048) {
- $no_bytes = 2;
- } elseif ($ord < 65536) {
- $no_bytes = 3;
- } elseif ($ord < 1114112) {
- $no_bytes = 4;
- } else {
- return;
- }
- switch ($no_bytes) {
- case 2:
- $prefix = array(31, 192);
- break;
-
- case 3:
- $prefix = array(15, 224);
- break;
-
- case 4:
- $prefix = array(7, 240);
- break;
- }
-
- for ($i = 0; $i < $no_bytes; $i++) {
- $byte[$no_bytes-$i-1] = (($ord & (63 * pow(2, 6*$i))) / pow(2, 6*$i)) & 63 | 128;
- }
- $byte[0] = ($byte[0] & $prefix[0]) | $prefix[1];
-
- $ret = '';
- for ($i = 0; $i < $no_bytes; $i++) {
- $ret .= chr($byte[$i]);
- }
- return $ret;
- }
-
- public function parse_date($date)
- {
- $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');
- $north_american_timezone = array('GMT' => '-0000', 'EST' => '-0500', 'EDT' => '-0400', 'CST' => '-0600', 'CDT' => '-0500', 'MST' => '-0700', 'MDT' => '-0600', 'PST' => '-0800', 'PDT' => '-0700');
- 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)) {
- if (!isset($matches[7])) {
- $matches[7] = '';
- }
- if (!isset($matches[9])) {
- $matches[9] = '';
- }
- $matches[7] = str_pad(round($matches[7]), 2, '0', STR_PAD_LEFT);
- switch (strlen($matches[9])) {
- case 0:
- $timezone = '';
- break;
-
- case 1:
- $timezone = $military_timezone[strtoupper($matches[9])];
- break;
-
- case 2:
- $timezone = '-0000';
- break;
-
- case 3:
- $timezone = $north_american_timezone[strtoupper($matches[9])];
- break;
-
- case 5:
- $timezone = $matches[9];
- break;
-
- case 6:
- $timezone = substr_replace($matches[9], '', 3, 1);
- break;
- }
- $date = strtotime("$matches[1]-$matches[2]-$matches[3] $matches[4]:$matches[5]:$matches[7] $timezone");
- } elseif (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)) {
- $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);
- $month = $three_month[$matches[2]];
- if (strlen($matches[3]) == 2) {
- $year = ($matches[3] < 70) ? "20$matches[3]" : "19$matches[3]";
- } else {
- $year = $matches[3];
- }
- if (!isset($matches[7])) {
- $matches[7] = '';
- }
- if (!isset($matches[9])) {
- $matches[9] = '';
- }
- $second = str_pad(round($matches[7]), 2, '0', STR_PAD_LEFT);
- switch (strlen($matches[9])) {
- case 0:
- $timezone = '';
- break;
-
- case 1:
- $timezone = $military_timezone[strtoupper($matches[9])];
- break;
-
- case 2:
- $timezone = '-0000';
- break;
-
- case 3:
- $timezone = $north_american_timezone[strtoupper($matches[9])];
- break;
-
- case 5:
- $timezone = $matches[9];
- break;
-
- case 6:
- $timezone = substr_replace($matches[9], '', 3, 1);
- break;
- }
- $date = strtotime("$year-$month-$matches[1] $matches[4]:$matches[5]:$second $timezone");
- } else {
- $date = strtotime($date);
- }
- if ($date !== false && $date !== -1) {
- return $date;
- } else {
- return false;
- }
- }
- }
|