Use Model\Photo as much as possible

Most important is to use `Photo::delete()` to have backend
to remove data.
This commit is contained in:
fabrixxm 2018-12-11 20:03:29 +01:00 committed by Hypolite Petovan
parent d549787bc1
commit 8c75c26361
8 changed files with 39 additions and 56 deletions

View file

@ -483,7 +483,7 @@ class Contact extends BaseObject
'gender' => $profile['gender'], 'avatar' => $profile['photo'],
'contact-type' => $user['account-type'], 'xmpp' => $profile['xmpp']];
$avatar = DBA::selectFirst('photo', ['resource-id', 'type'], ['uid' => $uid, 'profile' => true]);
$avatar = Photo::selectFirst(['resource-id', 'type'], ['uid' => $uid, 'profile' => true]);
if (DBA::isResult($avatar)) {
if ($update_avatar) {
$fields['avatar-date'] = DateTimeFormat::utcNow();

View file

@ -1030,7 +1030,7 @@ class Item extends BaseObject
* generate a resource-id and therefore aren't intimately linked to the item.
*/
if (strlen($item['resource-id'])) {
DBA::delete('photo', ['resource-id' => $item['resource-id'], 'uid' => $item['uid']]);
Photo::delete(['resource-id' => $item['resource-id'], 'uid' => $item['uid']]);
}
// If item is a link to an event, delete the event.
@ -2737,8 +2737,7 @@ class Item extends BaseObject
if ($x) {
$res = substr($i, $x + 1);
$i = substr($i, 0, $x);
$fields = ['data', 'type', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
$photo = DBA::selectFirst('photo', $fields, ['resource-id' => $i, 'scale' => $res, 'uid' => $uid]);
$photo = Photo::getPhotoForUser($uid, $i, $res);
if (DBA::isResult($photo)) {
/*
* Check to see if we should replace this photo link with an embedded image
@ -2762,9 +2761,7 @@ class Item extends BaseObject
}
}
if ($replace) {
$data = $photo['data'];
$type = $photo['type'];
$photo_img = Photo::getImageForPhoto($photo);
// If a custom width and height were specified, apply before embedding
if (preg_match("/\[img\=([0-9]*)x([0-9]*)\]/is", substr($orig_body, $img_start, $img_st_close), $match)) {
Logger::log('scaling photo', Logger::DEBUG);
@ -2772,14 +2769,12 @@ class Item extends BaseObject
$width = intval($match[1]);
$height = intval($match[2]);
$Image = new Image($data, $type);
if ($Image->isValid()) {
$Image->scaleDown(max($width, $height));
$data = $Image->asString();
$type = $Image->getType();
}
$photo_img->scaleDown(max($width, $height));
}
$data = $photo_img->asString();
$type = $photo_img->getType();
Logger::log('replacing photo', Logger::DEBUG);
$image = 'data:' . $type . ';base64,' . base64_encode($data);
Logger::log('replaced: ' . $image, Logger::DATA);

View file

@ -10,6 +10,7 @@ use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Model\Photo;
use Friendica\Network\Probe;
use Friendica\Util\DateTimeFormat;
@ -141,7 +142,7 @@ class Mail
}
$image_uri = substr($image, strrpos($image, '/') + 1);
$image_uri = substr($image_uri, 0, strpos($image_uri, '-'));
DBA::update('photo', ['allow-cid' => '<' . $recipient . '>'], ['resource-id' => $image_uri, 'album' => 'Wall Photos', 'uid' => local_user()]);
Photo::update(['allow-cid' => '<' . $recipient . '>'], ['resource-id' => $image_uri, 'album' => 'Wall Photos', 'uid' => local_user()]);
}
}
}

View file

@ -17,6 +17,7 @@ use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Model\Photo;
use Friendica\Object\Image;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
@ -701,7 +702,7 @@ class User
}
if (!$photo_failure) {
DBA::update('photo', ['profile' => 1], ['resource-id' => $hash]);
Photo::update(['profile' => 1], ['resource-id' => $hash]);
}
}
}