phpjs
Version:
141 lines (136 loc) • 11.1 kB
JavaScript
/*
* More info at: http://phpjs.org
*
* This is version: 3.06
* php.js is copyright 2010 Kevin van Zonneveld.
*
* Portions copyright Brett Zamir (http://brett-zamir.me), Kevin van Zonneveld
* (http://kevin.vanzonneveld.net), Onno Marsman, Michael White
* (http://getsprink.com), Theriault, Waldo Malqui Silva, Paulo Ricardo F.
* Santos, Jack, Jonas Raoni Soares Silva (http://www.jsfromhell.com), Philip
* Peterson, Legaev Andrey, Ates Goral (http://magnetiq.com), Alex, Ratheous,
* Martijn Wieringa, Nate, Philippe Baumann, lmeyrick
* (https://sourceforge.net/projects/bcmath-js/), Enrique Gonzalez,
* Webtoolkit.info (http://www.webtoolkit.info/), Jani Hartikainen, Ole
* Vrijenhoek, Carlos R. L. Rodrigues (http://www.jsfromhell.com), Ash Searle
* (http://hexmen.com/blog/), travc, stag019, pilus, T.Wild,
* http://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript,
* Johnny Mast (http://www.phpvrouwen.nl), Erkekjetter, WebDevHobo
* (http://webdevhobo.blogspot.com/), GeekFG (http://geekfg.blogspot.com),
* Andrea Giammarchi (http://webreflection.blogspot.com), d3x, marrtins,
* Michael Grier, Mirek Slugen, majak, mdsjack (http://www.mdsjack.bo.it),
* gettimeofday, Mailfaker (http://www.weedem.fr/), David, Michael White,
* Public Domain (http://www.json.org/json2.js), Tim de Koning
* (http://www.kingsquare.nl), Oleg Eremeev, Marc Palau, Steven Levithan
* (http://blog.stevenlevithan.com), Josh Fraser
* (http://onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/),
* KELAN, Arpad Ray (mailto:arpad@php.net), Joris, Breaking Par Consulting Inc
* (http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256CFB006C45F7),
* Martin (http://www.erlenwiese.de/), AJ, Lars Fischer, Felix Geisendoerfer
* (http://www.debuggable.com/felix), Pellentesque Malesuada, Caio Ariede
* (http://caioariede.com), Kankrelune (http://www.webfaktory.info/), Alfonso
* Jimenez (http://www.alfonsojimenez.com), Sakimori, Steve Hilder, gorthaur,
* Aman Gupta, Karol Kowalski, Thunder.m, Tyler Akins (http://rumkin.com),
* john (http://www.jd-tech.net), Douglas Crockford
* (http://javascript.crockford.com), mktime, Gilbert, Marco, paulo kuong,
* Frank Forte, duncan, madipta, ger, Subhasis Deb, felix, Denny Wardhana,
* Mateusz "loonquawl" Zalega, ReverseSyntax, Francois, Scott Cariss, Slawomir
* Kaniecki, Arno, Nathan, Nick Kolosov (http://sammy.ru), 0m3r, noname, marc
* andreu, Fox, sankai, Sanjoy Roy, nobbler, Steve Clay, class_exists, Thiago
* Mata (http://thiagomata.blog.com), Jon Hohle, nord_ua, Ozh, echo is bad,
* Linuxworld, XoraX (http://www.xorax.info), Pyerre, Soren Hansen, Brad
* Touesnard, MeEtc (http://yass.meetcweb.com), Tim Wiel, Bryan Elliott,
* T0bsn, Peter-Paul Koch (http://www.quirksmode.org/js/beat.html), David
* Randall, Der Simon (http://innerdom.sourceforge.net/), lmeyrick
* (https://sourceforge.net/projects/bcmath-js/this.), Hyam Singer
* (http://www.impact-computing.com/), Paul, kenneth, Raphael (Ao RUDLER),
* David James, T. Wild, Ole Vrijenhoek (http://www.nervous.nl/), J A R,
* Bayron Guevara, LH, JB, Eugene Bulkin (http://doubleaw.com/), Stoyan Kyosev
* (http://www.svest.org/), djmix, Marc Jansen, Francesco, Lincoln Ramsay,
* Manish, date, Kristof Coomans (SCK-CEN Belgian Nucleair Research Centre),
* Pierre-Luc Paour, Martin Pool, Rick Waldron, Kirk Strobeck, Saulo Vallory,
* Christoph, Artur Tchernychev, Wagner B. Soares, Valentina De Rosa, Daniel
* Esteban, Jason Wong (http://carrot.org/), Mick@el, rezna, Simon Willison
* (http://simonwillison.net), Gabriel Paderni, Marco van Oort,
* penutbutterjelly, Philipp Lenssen, Anton Ongson, Blues
* (http://tech.bluesmoon.info/), Tomasz Wesolowski, Eric Nagel, Bobby Drake,
* Luke Godfrey, Pul, uestla, Alan C, Yves Sucaet, sowberry, hitwork, Orlando,
* Norman "zEh" Fuchs, Ulrich, johnrembo, Nick Callen, ejsanders, Aidan Lister
* (http://aidanlister.com/), Brian Tafoya (http://www.premasolutions.com/),
* Philippe Jausions (http://pear.php.net/user/jausions), kilops, dptr1988,
* HKM, metjay, strcasecmp, strcmp, Taras Bogach, jpfle, ChaosNo1, Alexander
* Ermolaev (http://snippets.dzone.com/user/AlexanderErmolaev), Le Torbi,
* James, Chris, DxGx, Pedro Tainha (http://www.pedrotainha.com), Christian
* Doebler, setcookie, Greg Frazier, Tod Gentille, Alexander M Beedie,
* FremyCompany, T.J. Leahy, baris ozdil, FGFEmperor, daniel airton wermann
* (http://wermann.com.br), 3D-GRAF, jakes, gabriel paderni, Yannoo, Luis
* Salazar (http://www.freaky-media.com/), Tim de Koning, stensi, Billy, vlado
* houba, Itsacon (http://www.itsacon.net/), Jalal Berrami, Matteo, Victor,
* taith, Robin, Matt Bradley, fearphage
* (http://http/my.opera.com/fearphage/), Cord, Atli Þór, Maximusya, Andrej
* Pavlovic, Dino, rem, Greenseed, meo, Garagoth, Russell Walker
* (http://www.nbill.co.uk/), YUI Library:
* http://developer.yahoo.com/yui/docs/YAHOO.util.DateLocale.html, Blues at
* http://hacks.bluesmoon.info/strftime/strftime.js, Andreas, Jamie Beck
* (http://www.terabit.ca/), DtTvB
* (http://dt.in.th/2008-09-16.string-length-in-bytes.html), mk.keck, Leslie
* Hoare, Diogo Resende, Howard Yeend, Allan Jensen (http://www.winternet.no),
* davook, Benjamin Lupton, Rival, Luke Smith (http://lucassmith.name),
* booeyOH, Ben Bryan, Cagri Ekin, Amir Habibi
* (http://www.residence-mixte.com/), Kheang Hok Chin
* (http://www.distantia.ca/), Jay Klehr
*
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL KEVIN VAN ZONNEVELD BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// Compression: minified
function file_get_contents(url,flags,context,offset,maxLen){var tmp,headers=[],newTmp=[],k=0,i=0,href='',pathPos=-1,flagNames=0,content=null,http_stream=false;var func=function(value){return value.substring(1)!=='';};this.php_js=this.php_js||{};this.php_js.ini=this.php_js.ini||{};var ini=this.php_js.ini;context=context||this.php_js.default_streams_context||null;if(!flags){flags=0;}
var OPTS={FILE_USE_INCLUDE_PATH:1,FILE_TEXT:32,FILE_BINARY:64};if(typeof flags==='number'){flagNames=flags;}
else{flags=[].concat(flags);for(i=0;i<flags.length;i++){if(OPTS[flags[i]]){flagNames=flagNames|OPTS[flags[i]];}}}
if(flagNames&OPTS.FILE_BINARY&&(flagNames&OPTS.FILE_TEXT)){throw'You cannot pass both FILE_BINARY and FILE_TEXT to file_get_contents()';}
if((flagNames&OPTS.FILE_USE_INCLUDE_PATH)&&ini.include_path&&ini.include_path.local_value){var slash=ini.include_path.local_value.indexOf('/')!==-1?'/':'\\';url=ini.include_path.local_value+slash+url;}
else if(!/^(https?|file):/.test(url)){href=this.window.location.href;pathPos=url.indexOf('/')===0?href.indexOf('/',8)-1:href.lastIndexOf('/');url=href.slice(0,pathPos+1)+url;}
if(context){var http_options=context.stream_options&&context.stream_options.http;http_stream=!!http_options;}
if(!context||http_stream){var req=this.window.ActiveXObject?new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();if(!req){throw new Error('XMLHttpRequest not supported');}
var method=http_stream?http_options.method:'GET';var async=!!(context&&context.stream_params&&context.stream_params['phpjs.async']);if(ini['phpjs.ajaxBypassCache']&&ini['phpjs.ajaxBypassCache'].local_value){url+=(url.match(/\?/)==null?"?":"&")+(new Date()).getTime();}
req.open(method,url,async);if(async){var notification=context.stream_params.notification;if(typeof notification==='function'){if(0&&req.addEventListener){}
else{req.onreadystatechange=function(aEvt){var objContext={responseText:req.responseText,responseXML:req.responseXML,status:req.status,statusText:req.statusText,readyState:req.readyState,evt:aEvt};var bytes_transferred;switch(req.readyState){case 0:notification.call(objContext,0,0,'',0,0,0);break;case 1:notification.call(objContext,0,0,'',0,0,0);break;case 2:notification.call(objContext,0,0,'',0,0,0);break;case 3:bytes_transferred=req.responseText.length*2;notification.call(objContext,7,0,'',0,bytes_transferred,0);break;case 4:if(req.status>=200&&req.status<400){bytes_transferred=req.responseText.length*2;notification.call(objContext,8,0,'',req.status,bytes_transferred,0);}
else if(req.status===403){notification.call(objContext,10,2,'',req.status,0,0);}
else{notification.call(objContext,9,2,'',req.status,0,0);}
break;default:throw'Unrecognized ready state for file_get_contents()';}}}}}
if(http_stream){var sendHeaders=http_options.header&&http_options.header.split(/\r?\n/);var userAgentSent=false;for(i=0;i<sendHeaders.length;i++){var sendHeader=sendHeaders[i];var breakPos=sendHeader.search(/:\s*/);var sendHeaderName=sendHeader.substring(0,breakPos);req.setRequestHeader(sendHeaderName,sendHeader.substring(breakPos+1));if(sendHeaderName==='User-Agent'){userAgentSent=true;}}
if(!userAgentSent){var user_agent=http_options.user_agent||(ini.user_agent&&ini.user_agent.local_value);if(user_agent){req.setRequestHeader('User-Agent',user_agent);}}
content=http_options.content||null;}
if(flagNames&OPTS.FILE_TEXT){var content_type='text/html';if(http_options&&http_options['phpjs.override']){content_type=http_options['phpjs.override'];}
else{var encoding=(ini['unicode.stream_encoding']&&ini['unicode.stream_encoding'].local_value)||'UTF-8';if(http_options&&http_options.header&&(/^content-type:/im).test(http_options.header)){content_type=http_options.header.match(/^content-type:\s*(.*)$/im)[1];}
if(!(/;\s*charset=/).test(content_type)){content_type+='; charset='+encoding;}}
req.overrideMimeType(content_type);}
else if(flagNames&OPTS.FILE_BINARY){req.overrideMimeType('text/plain; charset=x-user-defined');}
if(http_options&&http_options['phpjs.sendAsBinary']){req.sendAsBinary(content);}
else{req.send(content);}
tmp=req.getAllResponseHeaders();if(tmp){tmp=tmp.split('\n');for(k=0;k<tmp.length;k++){if(func(tmp[k])){newTmp.push(tmp[k]);}}
tmp=newTmp;for(i=0;i<tmp.length;i++){headers[i]=tmp[i];}
this.$http_response_header=headers;}
if(offset||maxLen){if(maxLen){return req.responseText.substr(offset||0,maxLen);}
return req.responseText.substr(offset);}
return req.responseText;}
return false;}