Merge pull request #583 from annando/cat-profile
Catavatar: The profile picture is now stored in a better way
This commit is contained in:
commit
ac0d42dcaa
2 changed files with 69 additions and 57 deletions
|
@ -13,6 +13,9 @@ use Friendica\Core\Worker;
|
|||
use Friendica\Core\PConfig;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Database\DBM;
|
||||
|
||||
define("CATAVATAR_SIZE", 256);
|
||||
|
||||
|
@ -90,38 +93,31 @@ function catavatar_addon_settings_post(App $a, &$s)
|
|||
|
||||
|
||||
if (!empty($_POST['catavatar-usecat'])) {
|
||||
$url = $a->get_baseurl() . '/catavatar/' . local_user();
|
||||
$url = $a->get_baseurl() . '/catavatar/' . local_user() . '?ts=' . time();
|
||||
|
||||
// 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()],
|
||||
['uid' => local_user(), 'self' => 1]
|
||||
);
|
||||
if ($r===false) {
|
||||
$self = dba::selectFirst('contact', ['id'], ['uid' => local_user(), 'self' => true]);
|
||||
if (!DBM::is_result($self)) {
|
||||
notice(L10n::t("The cat hadn't found itself."));
|
||||
return;
|
||||
}
|
||||
|
||||
Photo::importProfilePhoto($url, local_user(), $self['id']);
|
||||
|
||||
$condition = ['uid' => local_user(), 'contact-id' => $self['id']];
|
||||
$photo = dba::selectFirst('photo', ['resource-id'], $condition);
|
||||
if (!DBM::is_result($photo)) {
|
||||
notice(L10n::t('There was an error, the cat ran away.'));
|
||||
return;
|
||||
}
|
||||
|
||||
$r = dba::update('profile',
|
||||
['photo' => $url . '/4', 'thumb' => $url . '/5'],
|
||||
['uid' => local_user(), 'is-default' => 1]
|
||||
);
|
||||
if ($r===false) {
|
||||
notice(L10n::t('There was an error, the cat ran away.'));
|
||||
return;
|
||||
}
|
||||
dba::update('photo', ['profile' => false], ['profile' => true, 'uid' => local_user()]);
|
||||
|
||||
$r = dba::update('photo',
|
||||
['profile' => 0],
|
||||
['uid' => local_user(), 'profile' => 1]
|
||||
);
|
||||
if ($r === false) {
|
||||
notice(L10n::t('There was an error, the cat ran away.'));
|
||||
return;
|
||||
}
|
||||
$fields = ['profile' => true, 'album' => L10n::t('Profile Photos'), 'contact-id' => 0];
|
||||
dba::update('photo', $fields, ['uid' => local_user(), 'resource-id' => $photo['resource-id']]);
|
||||
|
||||
Photo::importProfilePhoto($url, local_user(), $self['id']);
|
||||
|
||||
Contact::updateSelfFromUserID(local_user(), true);
|
||||
|
||||
// Update global directory in background
|
||||
$url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
|
||||
|
@ -204,7 +200,7 @@ function catavatar_content(App $a)
|
|||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
$seed = PConfig::get(local_user(), "catavatar", "seed", md5(trim(strtolower($user['email']))));
|
||||
$seed = PConfig::get($uid, "catavatar", "seed", md5(trim(strtolower($user['email']))));
|
||||
|
||||
// from cat-avatar-generator.php
|
||||
$imageurl = $seed . "-" . $size;
|
||||
|
@ -256,10 +252,12 @@ function catavatar_content(App $a)
|
|||
*
|
||||
**/
|
||||
|
||||
function build_cat($seed='', $size=0){
|
||||
|
||||
function build_cat($seed = '', $size = 0)
|
||||
{
|
||||
// init random seed
|
||||
if($seed) srand( hexdec(substr(md5($seed),0,6)) );
|
||||
if ($seed) {
|
||||
srand(hexdec(substr(md5($seed), 0, 6)));
|
||||
}
|
||||
|
||||
// throw the dice for body parts
|
||||
$parts = array(
|
||||
|
@ -281,7 +279,9 @@ function build_cat($seed='', $size=0){
|
|||
$file = dirname(__FILE__) . '/avatars/' . $part . '_' . $num . '.png';
|
||||
|
||||
$im = @imagecreatefrompng($file);
|
||||
if(!$im) die('Failed to load '.$file);
|
||||
if (!$im) {
|
||||
die('Failed to load ' . $file);
|
||||
}
|
||||
imageSaveAlpha($im, true);
|
||||
imagecopy($cat, $im, 0, 0, 0, 0, CATAVATAR_SIZE, CATAVATAR_SIZE);
|
||||
imagedestroy($im);
|
||||
|
@ -290,9 +290,15 @@ function build_cat($seed='', $size=0){
|
|||
// scale image
|
||||
if ($size > 3 && $size < 7) {
|
||||
switch ($size) {
|
||||
case 4: $size = 175; break;
|
||||
case 5: $size = 80; break;
|
||||
case 6: $size = 48; break;
|
||||
case 4:
|
||||
$size = 175;
|
||||
break;
|
||||
case 5:
|
||||
$size = 80;
|
||||
break;
|
||||
case 6:
|
||||
$size = 48;
|
||||
break;
|
||||
}
|
||||
|
||||
$dest = imagecreatetruecolor($size, $size);
|
||||
|
@ -315,5 +321,3 @@ function build_cat($seed='', $size=0){
|
|||
imagejpeg($cat, NULL, 90);
|
||||
imagedestroy($cat);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2018-04-06 18:26+0200\n"
|
||||
"POT-Creation-Date: 2018-04-13 09:35+0000\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -17,26 +17,34 @@ msgstr ""
|
|||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#: catavatar.php:57
|
||||
#: catavatar.php:60
|
||||
msgid "Use Cat as Avatar"
|
||||
msgstr ""
|
||||
|
||||
#: catavatar.php:58
|
||||
#: catavatar.php:61
|
||||
msgid "More Random Cat!"
|
||||
msgstr ""
|
||||
|
||||
#: catavatar.php:59
|
||||
#: catavatar.php:62
|
||||
msgid "Reset to email Cat"
|
||||
msgstr ""
|
||||
|
||||
#: catavatar.php:61
|
||||
#: catavatar.php:64
|
||||
msgid "Cat Avatar Settings"
|
||||
msgstr ""
|
||||
|
||||
#: catavatar.php:103 catavatar.php:112 catavatar.php:121
|
||||
#: catavatar.php:100
|
||||
msgid "The cat hadn't found itself."
|
||||
msgstr ""
|
||||
|
||||
#: catavatar.php:109
|
||||
msgid "There was an error, the cat ran away."
|
||||
msgstr ""
|
||||
|
||||
#: catavatar.php:134
|
||||
#: catavatar.php:115
|
||||
msgid "Profile Photos"
|
||||
msgstr ""
|
||||
|
||||
#: catavatar.php:130
|
||||
msgid "Meow!"
|
||||
msgstr ""
|
||||
|
|
Loading…
Reference in a new issue