New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Cat Avatar Generator Addon #571
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Friendica Cat Avatar Generator Addon | ||
|
||
Generate a default avatar based on David Revoy's cat-avatar-generator https://framagit.org/Deevad/cat-avatar-generator | ||
|
||
## License: | ||
|
||
**Artworks:** | ||
PNG and ORA files licensed under: [CC-By 4.0](https://creativecommons.org/licenses/by/4.0/) | ||
attribution: David Revoy with the following exception: | ||
Generated cats used as Avatar (for blog,forum,social-network) don't need direct | ||
attribution and so, can be used as regular avatars without pasting David Revoy's | ||
name all over the place. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,306 @@ | ||
<?php | ||
/** | ||
* Name: Cat Avatar Generator | ||
* Description: Generate a default avatar based on David Revoy's cat-avatar-generator https://framagit.org/Deevad/cat-avatar-generator | ||
* Version: 1.1 | ||
* Author: Fabio <https://kirgroup.com/profile/fabrixxm> | ||
*/ | ||
use Friendica\Core\Addon; | ||
use Friendica\Core\Config; | ||
use Friendica\Core\L10n; | ||
use Friendica\Core\Worker; | ||
use Friendica\Core\PConfig; | ||
use Friendica\Util\DateTimeFormat; | ||
use Friendica\Network\HTTPException\NotFoundException; | ||
|
||
define("CATAVATAR_SIZE", 256); | ||
|
||
/** | ||
* Installs the addon hook | ||
*/ | ||
function catavatar_install() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a new line before function opening braces. |
||
Addon::registerHook('avatar_lookup', 'addon/catavatar/catavatar.php', 'catavatar_lookup'); | ||
Addon::registerHook('addon_settings', 'addon/catavatar/catavatar.php', 'catavatar_addon_settings'); | ||
Addon::registerHook('addon_settings_post', 'addon/catavatar/catavatar.php', 'catavatar_addon_settings_post'); | ||
|
||
logger("registered catavatar"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. |
||
} | ||
|
||
/** | ||
* Removes the addon hook | ||
*/ | ||
function catavatar_uninstall() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a new line before function opening braces. |
||
Addon::unregisterHook('avatar_lookup', 'addon/catavatar/catavatar.php', 'catavatar_lookup'); | ||
Addon::unregisterHook('addon_settings', 'addon/catavatar/catavatar.php', 'catavatar_addon_settings'); | ||
Addon::unregisterHook('addon_settings_post', 'addon/catavatar/catavatar.php', 'catavatar_addon_settings_post'); | ||
|
||
logger("unregistered catavatar"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. |
||
} | ||
|
||
|
||
function catavatar_addon_settings(&$a, &$s) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a new line before function opening braces. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
if(! local_user()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space after conditional operators. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add braces to every conditional statement. |
||
return; | ||
|
||
$t = get_markup_template("settings.tpl", "addon/catavatar/" ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please remove the extra space before the closing parenthesis. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. |
||
$s = replace_macros ($t, [ | ||
'$postpost' => x($_POST,"catavatar-morecat") || x($_POST,"catavatar-emailcat"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Obsolete: Please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. |
||
'$uncache' => time(), | ||
'$uid' => local_user(), | ||
'$usecat' => L10n::t('Use Cat as Avatar'), | ||
'$morecat' => L10n::t('More Random Cat!'), | ||
'$emailcat' => L10n::t('Reset to email Cat'), | ||
'$seed' => PConfig::get(local_user(), "catavatar", "seed", false), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. |
||
'$header' => L10n::t('Cat Avatar').' '.L10n::t('Settings'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
]); | ||
return; | ||
} | ||
|
||
function catavatar_addon_settings_post(&$a, &$s) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a new line before function opening braces. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
if(! local_user()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add braces to every conditional statement. |
||
return; | ||
|
||
// delete the current cached cat avatar | ||
$user = dba::selectFirst('user', ['email'], | ||
[ | ||
'uid' => $uid, | ||
'blocked' => 0, | ||
'account_expired' => 0, | ||
'account_removed' => 0, | ||
] | ||
); | ||
$seed = PConfig::get(local_user(), "catavatar", "seed", md5(trim(strtolower($user['email'])))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. |
||
$imageurl = preg_replace('/[^A-Za-z0-9\._-]/', '', $seed); | ||
$imageurl = substr($imageurl,0,35).''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space after commas. |
||
$cachefile = get_cachefile($imageurl); | ||
if ($cachefile != "" && file_exists($cachefile)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. |
||
unlink($cachefile); | ||
} | ||
|
||
|
||
if (x($_POST,"catavatar-usecat")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Obsolete: Please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space after commas. |
||
$url = $a->get_baseurl()."/catavatar/".local_user(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
|
||
// set the catavatar url as avatar url in contact and default profile | ||
// and set profile to 0 to current photo | ||
// I'm not sure it's the correct way to do this... | ||
$r = dba::update('contact', | ||
['photo'=>$url."/4", 'thumb'=>$url."/5", 'micro'=>$url."/6", 'avatar-date'=>DateTimeFormat::utcNow()], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
['uid'=>local_user(), 'self'=>1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
); | ||
if ($r===false) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
notice(L10n::t('There was an error, the cat ran away.')); | ||
return; | ||
} | ||
|
||
$r = dba::update('profile', | ||
['photo'=>$url."/4", 'thumb'=>$url."/5"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
['uid'=>local_user(), 'is-default'=>1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
); | ||
if ($r===false) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
notice(L10n::t('There was an error, the cat ran away.')); | ||
return; | ||
} | ||
|
||
$r = dba::update('photo', | ||
['profile'=>0], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
['uid'=>local_user(), 'profile'=>1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
); | ||
if ($r===false) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
notice(L10n::t('There was an error, the cat ran away.')); | ||
return; | ||
} | ||
|
||
|
||
// Update global directory in background | ||
$url = $a->get_baseurl() . '/profile/' . $a->user['nickname']; | ||
if ($url && strlen(Config::get('system','directory'))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space after commas. |
||
Worker::add(PRIORITY_LOW, "Directory", $url); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. |
||
} | ||
|
||
Worker::add(PRIORITY_LOW, 'ProfileUpdate', local_user()); | ||
|
||
info(L10n::t("Meow!")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. |
||
return; | ||
} | ||
|
||
|
||
|
||
if (x($_POST,"catavatar-morecat")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Obsolete: Please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space after commas. |
||
PConfig::set(local_user(), "catavatar", "seed", time()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. |
||
} | ||
|
||
if (x($_POST,"catavatar-emailcat")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Obsolete: Please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space after commas. |
||
PConfig::delete(local_user(), "catavatar", "seed"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. |
||
} | ||
} | ||
|
||
|
||
/** | ||
* Returns the URL to the cat avatar | ||
* | ||
* @param $a array | ||
* @param &$b array | ||
*/ | ||
function catavatar_lookup($a, &$b) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a new line before function opening braces. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
$user = dba::selectFirst('user', ['uid'],['email'=>$b['email']]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space after commas. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
|
||
$url = $a->get_baseurl().'/catavatar/'.$user['uid']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
|
||
switch($b['size']) { | ||
case 175: $url.="/4"; break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
case 80: $url.="/5"; break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
case 47: $url.="/6"; break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
} | ||
|
||
$b['url'] = $url; | ||
$b['success'] = true; | ||
} | ||
|
||
|
||
function catavatar_module(){} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space before opening braces. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as is a empty function, what's the standard here? function catavatar_module()
{}
// or
function catavatar_module()
{
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would go with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. Ok. class CatAvatar extends Addon implements Module { :-D ) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather see class CatAvatar extends Addon
{
public function __construct(\Friendica\App $a)
{
$a->addRoute('catavatar', '\Friendica\Addon\Module\CatAvatar');
...
}
...
} and have the module in a separate file in the addon. |
||
|
||
|
||
/** | ||
* Returns image for user id | ||
* | ||
* @throws NotFoundException | ||
* | ||
* @TODO: support sizes | ||
*/ | ||
function catavatar_content($a) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a new line before function opening braces. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
if ($a->argc < 2 || $a->argc > 3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add braces to every conditional statement. |
||
throw new NotFoundException(); // this should be catched on index and show default "not found" page. | ||
|
||
$uid = intval($a->argv[1]); | ||
|
||
$size = 0; | ||
if ($a->argc == 3) { | ||
$size = intval($a->argv[2]); | ||
} | ||
|
||
$user = dba::selectFirst('user', ['email'], | ||
[ | ||
'uid' => $uid, | ||
'blocked' => 0, | ||
'account_expired' => 0, | ||
'account_removed' => 0, | ||
] | ||
); | ||
|
||
if ($user === False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap conditionals with braces. |
||
throw new NotFoundException(); | ||
|
||
$seed = PConfig::get(local_user(), "catavatar", "seed", md5(trim(strtolower($user['email'])))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. |
||
//echo "<pre>"; var_dump($hash); killme(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please remove debug code. |
||
|
||
|
||
// from cat-avatar-generator.php | ||
|
||
$imageurl = $seed."-".$size; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
$imageurl = preg_replace('/[^A-Za-z0-9\._-]/', '', $imageurl); | ||
$imageurl = substr($imageurl,0,35).''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space after commas. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
$cachefile = get_cachefile($imageurl); | ||
$cachetime = 604800; # 1 week (1 day = 86400) | ||
|
||
// Serve from the cache if it is younger than $cachetime | ||
if ($cachefile != "" && file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. |
||
header('Pragma: public'); | ||
header('Cache-Control: max-age=86400'); | ||
header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + 86400)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
header('Content-Type: image/jpg'); | ||
readfile($cachefile); | ||
exit; | ||
} | ||
|
||
// ...Or start generation | ||
ob_start(); | ||
|
||
// render the picture: | ||
build_cat($seed, $size); | ||
|
||
// Save/cache the output to a file | ||
if ($cachefile!=""){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space before conditional opening brace. |
||
$savedfile = fopen($cachefile, 'w+'); # w+ to be at start of the file, write mode, and attempt to create if not existing. | ||
fwrite($savedfile, ob_get_contents()); | ||
fclose($savedfile); | ||
chmod($cachefile, 0755); | ||
} | ||
ob_end_flush(); | ||
|
||
killme(); | ||
} | ||
|
||
|
||
|
||
/** | ||
* ==================== | ||
* CAT-AVATAR-GENERATOR | ||
* ==================== | ||
* | ||
* @authors: Andreas Gohr, David Revoy | ||
* | ||
* This PHP is licensed under the short and simple permissive: | ||
* [MIT License](https://en.wikipedia.org/wiki/MIT_License) | ||
* | ||
**/ | ||
|
||
function build_cat($seed='', $size=0){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a new line before function opening braces. |
||
|
||
// init random seed | ||
if($seed) srand( hexdec(substr(md5($seed),0,6)) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space after commas. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap conditionals with braces. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please remove extra spaces in |
||
|
||
// throw the dice for body parts | ||
$parts = array( | ||
'body' => rand(1,15), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space after commas. |
||
'fur' => rand(1,10), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space after commas. |
||
'eyes' => rand(1,15), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space after commas. |
||
'mouth' => rand(1,10), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space after commas. |
||
'accessorie' => rand(1,20) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space after commas. |
||
); | ||
|
||
// create backgound | ||
$cat = @imagecreatetruecolor(CATAVATAR_SIZE, CATAVATAR_SIZE) | ||
or die("GD image create failed"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please use single-quotes or double-quotes but not a mix and match. |
||
$white = imagecolorallocate($cat, 255, 255, 255); | ||
imagefill($cat,0,0,$white); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space after commas. |
||
|
||
// add parts | ||
foreach($parts as $part => $num){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space before opening braces. |
||
$file = dirname(__FILE__).'/avatars/'.$part.'_'.$num.'.png'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
|
||
$im = @imagecreatefrompng($file); | ||
if(!$im) die('Failed to load '.$file); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap conditionals with braces. |
||
imageSaveAlpha($im, true); | ||
imagecopy($cat,$im,0,0,0,0,CATAVATAR_SIZE,CATAVATAR_SIZE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please add a space after commas. |
||
imagedestroy($im); | ||
} | ||
|
||
// scale image | ||
if ($size > 3 && $size < 7) { | ||
switch($size) { | ||
case 4: $size = 175; break; | ||
case 5: $size = 80; break; | ||
case 6: $size = 48; break; | ||
} | ||
|
||
$dest = imagecreatetruecolor($size, $size); | ||
imagealphablending($dest, false); | ||
imagesavealpha($dest, true); | ||
imagecopyresampled($dest, $cat, 0, 0, 0, 0, $size, $size, CATAVATAR_SIZE, CATAVATAR_SIZE); | ||
imagedestroy($cat); | ||
$cat = $dest; | ||
} | ||
|
||
// restore random seed | ||
if($seed) srand(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap conditionals with braces. |
||
|
||
header('Pragma: public'); | ||
header('Cache-Control: max-age=86400'); | ||
header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + 86400)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards: Please wrap operators with spaces. |
||
header('Content-Type: image/jpg'); | ||
imagejpeg($cat, NULL, 90); | ||
imagedestroy($cat); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<span id="settings_catavatar_inflated" class="settings-block fakelink" | ||
style="{{if $postpost}}display: none;{{else}}display: block;{{/if}}" | ||
onclick="openClose('settings_catavatar_expanded'); openClose('settings_catavatar_inflated');"> | ||
<h3>{{$header}}</h3> | ||
</span> | ||
<div id="settings_catavatar_expanded" class="settings-block" | ||
style="{{if $postpost}}display: block;{{else}}display: none;{{/if}}"> | ||
<span class="fakelink" onclick="openClose('settings_catavatar_expanded'); openClose('settings_catavatar_inflated');"> | ||
<h3>{{$header}}</h3> | ||
</span> | ||
<img src="{{$basepath}}/catavatar/{{$uid}}?{{$uncache}}"> | ||
<p>Set default profile avatar or randomize the cat</p> | ||
<div class="settings-submit-wrapper" > | ||
<input type="submit" name="catavatar-usecat" | ||
class="btn btn-primary settings-submit" value="{{$usecat}}" /> | ||
|
||
<div class="btn-group" role="group" aria-label="..."> | ||
<input type="submit" name="catavatar-morecat" | ||
class="btn btn-default settings-submit" value="{{$morecat}}" /> | ||
<input type="submit" name="catavatar-emailcat" {{if !$seed}}disabled{{/if}} | ||
class="btn btn-default settings-submit" value="{{$emailcat}}" /> | ||
</div> | ||
</div> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Standards: Please use single-quotes or double-quotes but not a mix and match.