Standards

pull/583/head
Michael 2018-04-13 10:28:25 +00:00
parent 814edd4541
commit 7f06962bd1
1 changed files with 15 additions and 15 deletions

View File

@ -85,7 +85,7 @@ function catavatar_addon_settings_post(App $a, &$s)
); );
$seed = PConfig::get(local_user(), 'catavatar', 'seed', md5(trim(strtolower($user['email'])))); $seed = PConfig::get(local_user(), 'catavatar', 'seed', md5(trim(strtolower($user['email']))));
$imageurl = preg_replace('/[^A-Za-z0-9\._-]/', '', $seed); $imageurl = preg_replace('/[^A-Za-z0-9\._-]/', '', $seed);
$imageurl = substr($imageurl,0,35).''; $imageurl = substr($imageurl, 0, 35) . '';
$cachefile = get_cachefile($imageurl); $cachefile = get_cachefile($imageurl);
if ($cachefile != "" && file_exists($cachefile)) { if ($cachefile != "" && file_exists($cachefile)) {
unlink($cachefile); unlink($cachefile);
@ -121,7 +121,7 @@ function catavatar_addon_settings_post(App $a, &$s)
// Update global directory in background // Update global directory in background
$url = $a->get_baseurl() . '/profile/' . $a->user['nickname']; $url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
if ($url && strlen(Config::get('system','directory'))) { if ($url && strlen(Config::get('system', 'directory'))) {
Worker::add(PRIORITY_LOW, 'Directory', $url); Worker::add(PRIORITY_LOW, 'Directory', $url);
} }
@ -205,7 +205,7 @@ function catavatar_content(App $a)
// from cat-avatar-generator.php // from cat-avatar-generator.php
$imageurl = $seed . "-" . $size; $imageurl = $seed . "-" . $size;
$imageurl = preg_replace('/[^A-Za-z0-9\._-]/', '', $imageurl); $imageurl = preg_replace('/[^A-Za-z0-9\._-]/', '', $imageurl);
$imageurl = substr($imageurl,0,35) . ''; $imageurl = substr($imageurl, 0, 35) . '';
$cachefile = get_cachefile($imageurl); $cachefile = get_cachefile($imageurl);
$cachetime = 604800; # 1 week (1 day = 86400) $cachetime = 604800; # 1 week (1 day = 86400)
@ -213,7 +213,7 @@ function catavatar_content(App $a)
if ($cachefile != "" && file_exists($cachefile) && (time() - $cachetime) < filemtime($cachefile)) { if ($cachefile != "" && file_exists($cachefile) && (time() - $cachetime) < filemtime($cachefile)) {
header('Pragma: public'); header('Pragma: public');
header('Cache-Control: max-age=86400'); header('Cache-Control: max-age=86400');
header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + 86400)); header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 86400));
header('Content-Type: image/jpg'); header('Content-Type: image/jpg');
readfile($cachefile); readfile($cachefile);
exit(); exit();
@ -256,34 +256,34 @@ function build_cat($seed = '', $size = 0)
{ {
// init random seed // init random seed
if ($seed) { if ($seed) {
srand(hexdec(substr(md5($seed),0,6))); srand(hexdec(substr(md5($seed), 0, 6)));
} }
// throw the dice for body parts // throw the dice for body parts
$parts = array( $parts = array(
'body' => rand(1,15), 'body' => rand(1, 15),
'fur' => rand(1,10), 'fur' => rand(1, 10),
'eyes' => rand(1,15), 'eyes' => rand(1, 15),
'mouth' => rand(1,10), 'mouth' => rand(1, 10),
'accessorie' => rand(1,20) 'accessorie' => rand(1, 20)
); );
// create backgound // create backgound
$cat = @imagecreatetruecolor(CATAVATAR_SIZE, CATAVATAR_SIZE) $cat = @imagecreatetruecolor(CATAVATAR_SIZE, CATAVATAR_SIZE)
or die("GD image create failed"); or die("GD image create failed");
$white = imagecolorallocate($cat, 255, 255, 255); $white = imagecolorallocate($cat, 255, 255, 255);
imagefill($cat,0,0,$white); imagefill($cat, 0, 0, $white);
// add parts // add parts
foreach ($parts as $part => $num){ foreach ($parts as $part => $num){
$file = dirname(__FILE__).'/avatars/'.$part.'_'.$num.'.png'; $file = dirname(__FILE__) . '/avatars/' . $part . '_' . $num . '.png';
$im = @imagecreatefrompng($file); $im = @imagecreatefrompng($file);
if (!$im) { if (!$im) {
die('Failed to load '.$file); die('Failed to load ' . $file);
} }
imageSaveAlpha($im, true); imageSaveAlpha($im, true);
imagecopy($cat,$im,0,0,0,0,CATAVATAR_SIZE,CATAVATAR_SIZE); imagecopy($cat, $im, 0, 0, 0, 0, CATAVATAR_SIZE, CATAVATAR_SIZE);
imagedestroy($im); imagedestroy($im);
} }
@ -316,7 +316,7 @@ function build_cat($seed = '', $size = 0)
header('Pragma: public'); header('Pragma: public');
header('Cache-Control: max-age=86400'); header('Cache-Control: max-age=86400');
header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + 86400)); header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 86400));
header('Content-Type: image/jpg'); header('Content-Type: image/jpg');
imagejpeg($cat, NULL, 90); imagejpeg($cat, NULL, 90);
imagedestroy($cat); imagedestroy($cat);