|
<?php |
|
|
|
// Choose target directory for downloaded files |
|
$save_directory= './fonts_ge'; |
|
|
|
// You can set the starting page number, i.e. 44 ( https://fonts.ge/ka/fonts/?sort_by=name&pn=44 ) |
|
$start_page_num= !empty($_GET['startpage']) ? $_GET['startpage'] : 1; |
|
|
|
// by 2019, this is url, if changes in future, change this.. |
|
$download_url = 'https://fonts.ge/ka/download/font/'; |
|
|
|
|
|
// =============== you dont need below ================ // |
|
set_time_limit(50000); |
|
if( !is_dir($save_directory)) mkdir($save_directory, 0755, true); |
|
$zip = new ZipArchive(); |
|
for($i=$start_page_num; $i<=200; $i++) |
|
{ |
|
$link='https://fonts.ge/ka/fonts/?sort_by=name&pn='.$i; |
|
$data= get_remote_data($link); |
|
// break if end-of-numeration pages |
|
if ($i != 1 && stripos($data, '<span class=pagination id=current>1</span>') !== false) break; |
|
preg_match_all('/href\=\"\/\/fonts.ge\/ka\/font\/(\d{1,8})\/(.*?)"/', $data, $matches); |
|
$matches= count($matches[1]); |
|
for($j=0; $j<$matches; $j++) |
|
{ |
|
$downlo_url = $download_url.$matches[1][$j]; |
|
$name=preg_replace("/\W/si", '', $matches[2][$j]). '.zip'; |
|
$save_to = $save_directory .'/'.$name; |
|
file_put_contents($save_to, get_remote_data($downlo_url) ) ; |
|
|
|
if ($zip->open($save_to) !== true){ |
|
echo $save_to . ' could not be read for extracting<br/>'; |
|
} |
|
else{ |
|
$zip->extractTo($save_directory); |
|
} |
|
} |
|
} |
|
$zip->close(); |
|
|
|
|
|
|
|
|
|
//=================== ( https://github.com/tazotodua/useful-php-scripts/ ) ========================== |
|
function get_remote_data($url, $post_paramtrs=false, $extra=array('schemeless'=>true, 'replace_src'=>true, 'return_array'=>false) ) { |
|
// start curl |
|
$c = curl_init();curl_setopt($c, CURLOPT_URL, $url); |
|
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); |
|
//if parameters were passed to this function, then transform into POST method.. (if you need GET request, then simply change the passed URL) |
|
if($post_paramtrs){ curl_setopt($c, CURLOPT_POST,TRUE); curl_setopt($c, CURLOPT_POSTFIELDS, (is_array($post_paramtrs)? http_build_query($post_paramtrs) : $post_paramtrs) ); } |
|
curl_setopt($c, CURLOPT_SSL_VERIFYHOST,false); |
|
curl_setopt($c, CURLOPT_SSL_VERIFYPEER,false); |
|
curl_setopt($c, CURLOPT_COOKIE, 'CookieName1=Value;'); |
|
$headers[]= "User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:76.0) Gecko/20100101 Firefox/76.0"; $headers[]= "Pragma: "; $headers[]= "Cache-Control: max-age=0"; |
|
if (!empty($post_paramtrs) && !is_array($post_paramtrs) && is_object(json_decode($post_paramtrs))){ $headers[]= 'Content-Type: application/json'; $headers[]= 'Content-Length: '.strlen($post_paramtrs); } |
|
if(!empty($GLOBALS['cHeader_2'])) $headers[]=$GLOBALS['cHeader_2']; |
|
curl_setopt($c, CURLOPT_HTTPHEADER, $headers); |
|
curl_setopt($c, CURLOPT_MAXREDIRS, 10); |
|
//if SAFE_MODE or OPEN_BASEDIR is set,then FollowLocation cant be used.. so... |
|
$follow_allowed= ( ini_get('open_basedir') || ini_get('safe_mode')) ? false:true; if ($follow_allowed){curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);} |
|
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 9); |
|
curl_setopt($c, CURLOPT_REFERER, $url); |
|
curl_setopt($c, CURLOPT_TIMEOUT, 60); |
|
curl_setopt($c, CURLOPT_AUTOREFERER, true); |
|
curl_setopt($c, CURLOPT_ENCODING, 'gzip,deflate'); |
|
curl_setopt($c, CURLOPT_HEADER, true); |
|
$result=curl_exec($c); preg_match("/(.*?)\r\n\r\n(.*)/si",$result, $x); preg_match_all('/(.*?): (.*?)\r\n/i', trim('head_line: '.$x[1]), $headers_, PREG_SET_ORDER); foreach($headers_ as $each){ $header[$each[1]] = $each[2]; } $data=trim($x[2]); $status=curl_getinfo($c); curl_close($c); |
|
// if redirected, then get that redirected page |
|
if($status['http_code']==301 || $status['http_code']==302) { |
|
//if we FOLLOWLOCATION was not allowed, then re-get REDIRECTED URL |
|
//p.s. WE dont need "else", because if FOLLOWLOCATION was allowed, then we wouldnt have come to this place, because 301 could already auto-followed by curl :) |
|
if (!$follow_allowed){ |
|
//if REDIRECT URL is found in HEADER |
|
if(empty($redirURL)){if(!empty($status['redirect_url'])){$redirURL=$status['redirect_url'];}} |
|
//if REDIRECT URL is found in RESPONSE |
|
if(empty($redirURL)){preg_match('/(Location:|URI:)(.*?)(\r|\n)/si', $data, $m); if (!empty($m[2])){ $redirURL=$m[2]; } } |
|
//if REDIRECT URL is found in OUTPUT |
|
if(empty($redirURL)){preg_match('/moved\s\<a(.*?)href\=\"(.*?)\"(.*?)here\<\/a\>/si',$data,$m); if (!empty($m[1])){ $redirURL=$m[1]; } } |
|
//if URL found, then re-use this function again, for the found url |
|
if(!empty($redirURL)){$t=debug_backtrace(); return call_user_func( $t[0]["function"], trim($redirURL), $post_paramtrs);} |
|
} |
|
} |
|
// if not redirected,and nor "status 200" page, then error.. |
|
elseif ( $status['http_code'] != 200 ) { $data = "ERRORCODE22 with $url<br/><br/>Last status codes:".json_encode($status)."<br/><br/>Last data got:$data";} |
|
//URLS correction |
|
return $data; |
|
} |
|
|
|
?> |