use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\Item as ItemModel;
+use Friendica\Model\Photo;
use Friendica\Model\Post;
use Friendica\Model\Tag;
use Friendica\Model\User;
$author_thumb = $item['author-avatar'];
}
- if (!Contact::isAvatarFile($owner_thumb)) {
+ if (empty($owner_thumb) || Photo::isPhotoURI($owner_thumb)) {
$owner_thumb = Contact::getAvatarUrlForId($owner_avatar, Proxy::SIZE_THUMB, $owner_updated);
}
-
- if (!Contact::isAvatarFile($author_thumb)) {
+
+ if (empty($author_thumb) || Photo::isPhotoURI($author_thumb)) {
$author_thumb = Contact::getAvatarUrlForId($author_avatar, Proxy::SIZE_THUMB, $author_updated);
}
if (DI::config()->get('system', 'avatar_cache')) {
switch ($size) {
case Proxy::SIZE_MICRO:
- if (self::isAvatarFile($contact['micro'])) {
+ if (!empty($contact['micro']) && !Photo::isPhotoURI($contact['micro'])) {
return $contact['micro'];
}
break;
case Proxy::SIZE_THUMB:
- if (self::isAvatarFile($contact['thumb'])) {
+ if (!empty($contact['thumb']) && !Photo::isPhotoURI($contact['thumb'])) {
return $contact['thumb'];
}
break;
case Proxy::SIZE_SMALL:
- if (self::isAvatarFile($contact['photo'])) {
+ if (!empty($contact['photo']) && !Photo::isPhotoURI($contact['photo'])) {
return $contact['photo'];
}
break;
* @param string $avatar
* @return boolean
*/
- public static function isAvatarFile(string $avatar): bool
+ private static function isAvatarFile(string $avatar): bool
{
return !empty(self::getAvatarFile($avatar));
}
return $image_uri;
}
+ /**
+ * Checks if the given URL is a local photo.
+ * Since it is meant for time critical occasions, the check is done without any database requests.
+ *
+ * @param string $url
+ * @return boolean
+ */
+ public static function isPhotoURI(string $url): bool
+ {
+ return !empty(self::ridFromURI($url));
+ }
+
/**
* Changes photo permissions that had been embedded in a post
*
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
+use Friendica\Model\Photo;
use Friendica\Model\Post as PostModel;
use Friendica\Model\Tag;
use Friendica\Model\User;
$author_thumb = $item['author-avatar'];
}
- if (!Contact::isAvatarFile($owner_thumb)) {
+ if (empty($owner_thumb) || Photo::isPhotoURI($owner_thumb)) {
$owner_thumb = Contact::getAvatarUrlForId($owner_avatar, Proxy::SIZE_THUMB, $owner_updated);
}
- if (!Contact::isAvatarFile($author_thumb)) {
+ if (empty($author_thumb) || Photo::isPhotoURI($author_thumb)) {
$author_thumb = Contact::getAvatarUrlForId($author_avatar, Proxy::SIZE_THUMB, $author_updated);
}