Fix coding style

pull/573/head
fabrixxm 2018-04-05 22:21:59 +02:00
parent 078267f9f7
commit 98365a8808
1 changed files with 82 additions and 71 deletions

View File

@ -18,47 +18,57 @@ define("CATAVATAR_SIZE", 256);
/**
* Installs the addon hook
*/
function catavatar_install() {
function catavatar_install()
{
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");
logger('registered catavatar');
}
/**
* Removes the addon hook
*/
function catavatar_uninstall() {
function catavatar_uninstall()
{
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");
logger('unregistered catavatar');
}
function catavatar_addon_settings(&$a, &$s) {
if(! local_user())
/**
* Cat avatar user settings page
*/
function catavatar_addon_settings(&$a, &$s)
{
if (!local_user()) {
return;
}
$t = get_markup_template("settings.tpl", "addon/catavatar/" );
$t = get_markup_template('settings.tpl', 'addon/catavatar/');
$s = replace_macros ($t, [
'$postpost' => x($_POST,"catavatar-morecat") || x($_POST,"catavatar-emailcat"),
'$postpost' => !empty($_POST['catavatar-morecat']) || !empty($_POST['catavatar-emailcat']),
'$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),
'$header' => L10n::t('Cat Avatar').' '.L10n::t('Settings'),
'$seed' => PConfig::get(local_user(), 'catavatar', 'seed', false),
'$header' => L10n::t('Cat Avatar Settings'),
]);
return;
}
function catavatar_addon_settings_post(&$a, &$s) {
if(! local_user())
/**
* Cat avatar user settings POST handle
*/
function catavatar_addon_settings_post(&$a, &$s)
{
if (!local_user()) {
return;
}
// delete the current cached cat avatar
$user = dba::selectFirst('user', ['email'],
@ -69,7 +79,7 @@ function catavatar_addon_settings_post(&$a, &$s) {
'account_removed' => 0,
]
);
$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 = substr($imageurl,0,35).'';
$cachefile = get_cachefile($imageurl);
@ -78,14 +88,14 @@ function catavatar_addon_settings_post(&$a, &$s) {
}
if (x($_POST,"catavatar-usecat")) {
$url = $a->get_baseurl()."/catavatar/".local_user();
if (!empty($_POST['catavatar-usecat'})) {
$url = $a->get_baseurl() . '/catavatar/' . local_user();
// 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()],
['photo' => $url . '/4', 'thumb' => $url . '/5', 'micro' => $url . '/6', 'avatar-date' => DateTimeFormat::utcNow()],
['uid' => local_user(), 'self' => 1]
);
if ($r===false) {
@ -94,7 +104,7 @@ function catavatar_addon_settings_post(&$a, &$s) {
}
$r = dba::update('profile',
['photo'=>$url."/4", 'thumb'=>$url."/5"],
['photo' => $url . '/4', 'thumb' => $url . '/5'],
['uid' => local_user(), 'is-default' => 1]
);
if ($r===false) {
@ -115,23 +125,23 @@ function catavatar_addon_settings_post(&$a, &$s) {
// Update global directory in background
$url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
if ($url && strlen(Config::get('system','directory'))) {
Worker::add(PRIORITY_LOW, "Directory", $url);
Worker::add(PRIORITY_LOW, 'Directory', $url);
}
Worker::add(PRIORITY_LOW, 'ProfileUpdate', local_user());
info(L10n::t("Meow!"));
info(L10n::t('Meow!'));
return;
}
if (x($_POST,"catavatar-morecat")) {
PConfig::set(local_user(), "catavatar", "seed", time());
if (!empty($_POST['catavatar-morecat'])) {
PConfig::set(local_user(), 'catavatar', 'seed', time());
}
if (x($_POST,"catavatar-emailcat")) {
PConfig::delete(local_user(), "catavatar", "seed");
if (!empty($_POST['catavatar-emailcat'])) {
PConfig::delete(local_user(), 'catavatar', 'seed');
}
}
@ -142,9 +152,9 @@ function catavatar_addon_settings_post(&$a, &$s) {
* @param $a array
* @param &$b array
*/
function catavatar_lookup($a, &$b) {
function catavatar_lookup($a, &$b)
{
$user = dba::selectFirst('user', ['uid'], ['email' => $b['email']]);
$url = $a->get_baseurl() . '/catavatar/' . $user['uid'];
switch($b['size']) {
@ -168,9 +178,11 @@ function catavatar_module(){}
*
* @TODO: support sizes
*/
function catavatar_content($a) {
if ($a->argc < 2 || $a->argc > 3)
function catavatar_content($a)
{
if ($a->argc < 2 || $a->argc > 3) {
throw new NotFoundException(); // this should be catched on index and show default "not found" page.
}
$uid = intval($a->argv[1]);
@ -188,15 +200,13 @@ function catavatar_content($a) {
]
);
if ($user === False)
if ($user === false) {
throw new NotFoundException();
}
$seed = PConfig::get(local_user(), "catavatar", "seed", md5(trim(strtolower($user['email']))));
//echo "<pre>"; var_dump($hash); killme();
// from cat-avatar-generator.php
$imageurl = $seed . "-" . $size;
$imageurl = preg_replace('/[^A-Za-z0-9\._-]/', '', $imageurl);
$imageurl = substr($imageurl,0,35) . '';
@ -204,13 +214,13 @@ function catavatar_content($a) {
$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)) {
if ($cachefile != "" && file_exists($cachefile) && (time() - $cachetime) < filemtime($cachefile)) {
header('Pragma: public');
header('Cache-Control: max-age=86400');
header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + 86400));
header('Content-Type: image/jpg');
readfile($cachefile);
exit;
killme();
}
// ...Or start generation
@ -226,6 +236,7 @@ function catavatar_content($a) {
fclose($savedfile);
chmod($cachefile, 0755);
}
ob_end_flush();
killme();