Skip to content

Instantly share code, notes, and snippets.

@bachors
Last active October 13, 2017 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bachors/588133c3a8ff894e1ec0cf6dc5b19cda to your computer and use it in GitHub Desktop.
Save bachors/588133c3a8ff894e1ec0cf6dc5b19cda to your computer and use it in GitHub Desktop.
<?php
/*****************************************************************************************************************
* #### Read Webpage Offline ####
* Read Webpage Offline is a free online tools and easy-to-use offline browser utility.
* It allows you to download a World Wide Web site from the Internet to a local directory,
* building recursively all directories, getting HTML, images, and other files from the server to your computer..
* http://ibacor.com/tools/read-webpage-offline
*****************************************************************************************************************/
error_reporting(0);
header('Access-Control-Allow-Origin: *');
if(!empty($_POST['url'])){
$url = str_replace(' ', '', $_POST['url']);
if(!preg_match("/\/\//", $url)){
$url = str_replace(':/', '://', $_POST['url']);
}
$save = ayosave($url);
echo $save;
}
function ayocurl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (http://www.googlebot.com/bot.html)');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_URL, $url);
$html = curl_exec($ch);
curl_close($ch);
return $html;
}
function ayosave($url){
$scheme = parse_url($url, PHP_URL_SCHEME);
$host = parse_url($url, PHP_URL_HOST);
$des = $host;
if (!file_exists($des)) {
mkdir($des);
}
$path = parse_url( $url, PHP_URL_PATH );
$dir = dirname($path) . '/';
if(!empty($dir)){
if ( !file_exists( $des.$dir ) ) {
mkdir( $des.$dir, 0777, true );
}
$tokens = explode('/', $url);
$file = $tokens[sizeof($tokens)-1];
$file = preg_replace("/\?([^>]*)/", '', $file);
if($dir == '/'){
$res = $des.'/index.html';
}else if($dir == '\/'){
if(!empty($file)){
if ( !file_exists( $des.'/'.$file ) ) {
mkdir( $des.'/'.$file, 0777, true );
}
$res = $des.'/'.$file.'/index.html';
}else{
$file = $tokens[sizeof($tokens)-2];
$file = preg_replace("/\?([^>]*)/", '', $file);
if(!preg_match("/$host/", $file)){
if ( !file_exists( $des.'/'.$file ) ) {
mkdir( $des.'/'.$file, 0777, true );
}
$res = $des.'/'.$file.'/index.html';
}else{
$res = $des.'/index.html';
}
}
}else{
if(!empty($file)){
if(preg_match('/\./', $file)){
$file = str_replace(array('.asp', '.aspx'), '.html', $file);
$res = $des.$dir.$file;
}else{
if ( !file_exists( $des.$dir.$file ) ) {
mkdir( $des.$dir.$file, 0777, true );
}
$res = $des.$dir.$file.'/index.html';
}
}else{
$file = $tokens[sizeof($tokens)-2];
$file = preg_replace("/\?([^>]*)/", '', $file);
if ( !file_exists( $des.$dir.$file ) ) {
mkdir( $des.$dir.$file, 0777, true );
}
$res = $des.$dir.$file.'/index.html';
}
}
if(!file_exists($res)){
$myfile = fopen($res, "w") or die("Unable to open file!");
$txt = "iBacor.com\n";
fwrite($myfile, $txt);
fclose($myfile);
$isi = preg_replace("/$scheme:\/\/([^>]*)$host/", '', ayocurl($url));
$isi = str_replace(array('="/', "='/"), array('="/'.$host.'/', "='/$host/"), $isi);
$isi = str_replace(array('="/'.$host.'//', "='/$host//"), array('="//', "='//"), $isi);
$isi = str_replace(array('="/'.$host.'/', "='/$host/"), array('="', "='"), $isi);
$isi = str_replace(array('="../', "='../"), array('="', "='"), $isi);
$fileput = $res;
file_put_contents($fileput, $isi);
}
}
return $res;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment