Catavatar: The profile picture is now stored in a better way

pull/583/head
Michael 2018-04-13 06:34:16 +00:00
parent 0a8a1fadd5
commit 2f5fea4f8c
1 changed files with 20 additions and 24 deletions

View File

@ -13,6 +13,9 @@ use Friendica\Core\Worker;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Network\HTTPException\NotFoundException; use Friendica\Network\HTTPException\NotFoundException;
use Friendica\Model\Contact;
use Friendica\Model\Photo;
use Friendica\Database\DBM;
define("CATAVATAR_SIZE", 256); define("CATAVATAR_SIZE", 256);
@ -92,36 +95,29 @@ function catavatar_addon_settings_post(App $a, &$s)
if (!empty($_POST['catavatar-usecat'])) { if (!empty($_POST['catavatar-usecat'])) {
$url = $a->get_baseurl() . '/catavatar/' . local_user(); $url = $a->get_baseurl() . '/catavatar/' . local_user();
// set the catavatar url as avatar url in contact and default profile $self = dba::selectFirst('contact', ['id'], ['uid' => local_user(), 'self' => true]);
// and set profile to 0 to current photo if (!DBM::is_result($self)) {
// I'm not sure it's the correct way to do this... notice(L10n::t("The cat hadn't found itself."));
$r = dba::update('contact', return;
['photo' => $url . '/4', 'thumb' => $url . '/5', 'micro' => $url . '/6', 'avatar-date' => DateTimeFormat::utcNow()], }
['uid' => local_user(), 'self' => 1]
); Photo::importProfilePhoto($url, local_user(), $self['id']);
if ($r===false) {
$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.')); notice(L10n::t('There was an error, the cat ran away.'));
return; return;
} }
$r = dba::update('profile', dba::update('photo', ['profile' => false], ['profile' => true, 'uid' => local_user()]);
['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;
}
$r = dba::update('photo', $fields = ['profile' => true, 'album' => L10n::t('Profile Photos'), 'contact-id' => 0];
['profile' => 0], dba::update('photo', $fields, ['uid' => local_user(), 'resource-id' => $photo['resource-id']]);
['uid' => local_user(), 'profile' => 1]
);
if ($r === false) {
notice(L10n::t('There was an error, the cat ran away.'));
return;
}
Photo::importProfilePhoto($url, local_user(), $self['id']);
Contact::updateSelfFromUserID(local_user(), true);
// 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'];