Outils pour utilisateurs

Outils du site


php:cache_gravatar

Ceci est une ancienne révision du document !


<?php /* How to use it: call it from your website like this: http://www.yoursite.com/some_folder_for_gravatar_caching/get.php?g={md5_from_email} */ $expire = time() -604800 ; default: 604800 (7 days) $size = 65; if(isset($_GET['s'])) { switch ($_GET['s']) { case 0: $size = 32; break; default: $size = 65; } } if (isset($_GET['g'])) { g given ? if yes…

if (strlen($_GET['g']) !== 32) { header("HTTP/1.0 404 Not Found");die; }
$hash = preg_replace("/[^a-f0-9]/", "", $_GET['g'] ); 

if (strlen($hash) != 32) { header(“HTTP/1.0 404 Not Found”);die; }

$newfile = $hash.'_'.$size.'.png';
$file = 'http://gravatar.com/avatar/'.$hash.'?s='.$size.'&d=mm&r=x';  
if(file_exists($newfile) && filemtime($newfile) < $expire) {
	unlink($newfile);
}
if (file_exists($newfile)) {
}
else {
	copy($file, $newfile);
	$imagecheck = getimagesize($newfile);
	if ($imagecheck['mime']!=='image/png')  {
		imagepng(imagecreatefromjpeg($newfile),$newfile.'2');
		unlink($newfile);
		rename($newfile.'2', $newfile);
	}
}
$im = imagecreatefrompng($newfile);
header('Content-Type: image/png');
header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($newfile)).' GMT');
imagepng($im);
imagedestroy($im);
die;

}

else {

$seconds_old = 2592000; 
$dirhandle = opendir('.');
while($fileclean = readdir($dirhandle)) {
	if( $fileclean != "." && $fileclean != ".." && $fileclean != "index.php" ) {
		if(filemtime($fileclean) < (time()-$seconds_old) ) {
			unlink($fileclean);
		}
	}
}
header('Location: /');
die;

}

?>

php/cache_gravatar.1425733299.txt.gz · Dernière modification: 2015-03-07 15:01 (modification externe)