Skip to content

Instantly share code, notes, and snippets.

@Golgarud
Last active July 18, 2017 15:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Golgarud/65a5dcfa4db9126a1a7cd1afa9ce821e to your computer and use it in GitHub Desktop.
Save Golgarud/65a5dcfa4db9126a1a7cd1afa9ce821e to your computer and use it in GitHub Desktop.
<?php
define("glolbCronDebug", true);
function init_error_param()
{
ob_start();
ignore_user_abort( true );
set_time_limit( 0 );
if ( glolbCronDebug )
{
error_reporting( 1 );
ini_set( 'display_errors', true );
}
ini_set('memory_limit', '-1');
ini_set('max_execution_time', 0);
}
function cdroot()
{
$path = realpath("./functionCron.php");
chdir( explode("functionCron.php", $path) [0] . "..");
if ( glolbCronDebug )
{
debugL( "cd ".getcwd() );
}
}
function tempo($time = 0.2)
{
ob_flush();
flush();
sleep($time);
ob_end_clean();
}
function debugL($mainStr, $type = 'log', $subStr = false)
{
if ( glolbCronDebug )
{
echo "<div class='debug-container'>";
echo "<p class='debug " . $type . "'>" . $mainStr . "</p>";
if ( $subStr && !is_array($subStr) )
{
echo "<img class='btn-sub-debug' src='http://www.bulko.net/templates/img/ref_plus.png' />";
echo "<p class='debug-sub " . $type . "'>" . $subStr . "</p>";
}
elseif ( is_array($subStr) )
{
echo "<img class='btn-sub-debug' src='http://www.bulko.net/templates/img/ref_plus.png' />";
foreach ($subStr as $key => $subStrRow)
{
echo "<p class='debug-sub " . $type . "'>" . $subStrRow . "</p>";
}
}
echo "</div>";
tempo();
tempo();
}
}
function getHeaderDebug()
{
if ( glolbCronDebug )
{
echo '
<!DOCTYPE html>
<html lang="fr">
<head>
<title>Coucou betty ❤</title>
<meta charset="UTF-8" />
<meta name="robots" content="noindex">
<link rel="icon" type="image/vnd.microsoft.icon" href="http://www.cours.golga.eu/wp-content/uploads/2015/03/ico1.png" />
<link rel="shortcut icon" type="image/x-icon" href="http://www.cours.golga.eu/wp-content/uploads/2015/03/ico1.png" />
<style type="text/css" media="screen">
p.debug{
color:green;
margin:0;
}
p.debug-sub{
margin-top:0px;
margin-bottom:0px;
padding-top:10px;
padding-bottom:10px;
margin-left:30px;
border-bottom:1px solid white;
display:none
}
p.debug:after{
content:";";
}
p.debug:before{
content:"¯\_(ツ)_/¯> ";
}
p.debug span{
color: white;
}
.btn-sub-debug{
max-width:15px;
opacity:0.6
}
.btn-sub-debug:hover{
opacity:1;
}
p.error{
color:red;
}
p.empty{
color:orange;
}
</style>
</head>
<body style="background:#1F1F1F; color:white;">
<div id="content" style="position:relative; margin:auto;">
';
}
}
function getFooterDebug()
{
if ( glolbCronDebug )
{
echo '
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
<script>
$(function()
{
$(".btn-sub-debug").on("click", function(e){
e.preventDefault();
$(this).parents(".debug-container").find(".debug-sub").each(function(){
$(this).slideToggle();
});
});
});
</script>
</body>
</html>';
}
}
function getCurlData($url, $fields, $https = false, $login = "boesner:tyqyd1ea" )
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
if( $login )
{
curl_setopt($ch, CURLOPT_USERPWD, $login);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (!$https)
{
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
return curl_exec($ch);
}
function grab_image( $url, $saveto )
{
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$raw=curl_exec($ch);
curl_close ($ch);
if(file_exists($saveto)){
unlink($saveto);
}
$fp = fopen($saveto,'x');
fwrite($fp, $raw);
fclose($fp);
}
function url_exists( $url )
{
$file_headers = @get_headers($url);
if(!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found')
{
$exists = false;
}
else
{
$exists = true;
}
return $exists;
}
getHeaderDebug();
init_error_param();
debugL( "Statment [<span>START</span>]" );
echo "<hr />";
tempo();
$urlBase = "http://www.tonmanga.com/content/fullmetal_alchemist/";
$savetoBase = "fma/";
$ext = ".png";
$ext2 = ".jpg";
if ( !file_exists( $savetoBase ) )
{
debugL( "Création d'un dossier \"<span>fma</span>\"" );
}
$start = ( !empty($_GET["start"]) ) ? $_GET["start"] : 1 ;
$end = ( !empty($_GET["end"]) ) ? $_GET["end"] : 110 ;
for ( $i = $start; $i <= $end; $i++ )
{
//@see http://php.net/manual/en/function.str-pad.php
$chapterName = "chapitre_" . str_pad( $i, 3, "0", STR_PAD_LEFT);
if ( !file_exists( $savetoBase . $chapterName ) )
{
mkdir( $savetoBase . $chapterName, 0777, true );
debugL( "Création d'un dossier \"<span>fma/" . $chapterName ."</span>\"" );
}
for ( $i2 = 1; $i2 <= 900; $i2 ++ )
{
if ( url_exists( $urlBase . $i . "/" .$i2 . $ext ) )
{
$nameSource = $i . "/" .$i2 . $ext ;
$name = $chapterName . "/" .$i2 . $ext ;
}
elseif ( url_exists( $urlBase . $i . "/0" .$i2 . $ext ) )
{
$nameSource = $i . "/0" .$i2 . $ext ;
$name = $chapterName . "/0" .$i2 . $ext ;
}
elseif ( url_exists( $urlBase . $i . "/00" .$i2 . $ext ) )
{
$nameSource = $i . "/00" .$i2 . $ext ;
$name = $chapterName . "/00" .$i2 . $ext ;
}
elseif ( url_exists( $urlBase . $i . "/" .$i2 . $ext2 ) )
{
$nameSource = $i . "/" .$i2 . $ext2 ;
$name = $chapterName . "/" .$i2 . $ext2 ;
}
elseif ( url_exists( $urlBase . $i . "/0" .$i2 . $ext2 ) )
{
$nameSource = $i . "/0" .$i2 . $ext2 ;
$name = $chapterName . "/0" .$i2 . $ext2 ;
}
elseif ( url_exists( $urlBase . $i . "/00" .$i2 . $ext2 ) )
{
$nameSource = $i . "/00" .$i2 . $ext2 ;
$name = $chapterName . "/00" .$i2 . $ext2 ;
}
else
{
$nbPage = $i2 -1;
debugL( "Chapitre <span>" . $i . "</span> à biens était cloné, <span>" . $nbPage. "</span> pages importé(s)" );
break;
}
grab_image( $urlBase . $nameSource ,$savetoBase . $name );
}
}
echo "<hr />";
debugL( "Statment [<span>END</span>]" );
debugL( "Voilaaaa ✌ C'est finiiii! bonne lecture :)", "empty" );
debugL( "٩(⁎❛ᴗ❛⁎)۶", "empty" );
getFooterDebug();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment