Fixed fetching private local images
This commit is contained in:
parent
a0772c91d0
commit
c72abe48a8
|
@ -28,8 +28,10 @@ use Friendica\Database\Database;
|
|||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Util\Images;
|
||||
use Friendica\Util\Network;
|
||||
use Friendica\Util\ParseUrl;
|
||||
use Friendica\Util\Proxy;
|
||||
use Friendica\Util\Strings;
|
||||
|
@ -158,6 +160,10 @@ class Media
|
|||
*/
|
||||
public static function fetchAdditionalData(array $media)
|
||||
{
|
||||
if (Network::isLocalLink($media['url'])) {
|
||||
$media = self::fetchLocalData($media);
|
||||
}
|
||||
|
||||
// Fetch the mimetype or size if missing.
|
||||
if (empty($media['mimetype']) || empty($media['size'])) {
|
||||
$timeout = DI::config()->get('system', 'xrd_timeout');
|
||||
|
@ -216,6 +222,36 @@ class Media
|
|||
return $media;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch media data from local resources
|
||||
* @param array $media
|
||||
* @return array media with added data
|
||||
*/
|
||||
private static function fetchLocalData(array $media)
|
||||
{
|
||||
if (!preg_match('|.*?/photo/(.*[a-fA-F0-9])\-(.*[0-9])\..*[\w]|', $media['url'], $matches)) {
|
||||
return $media;
|
||||
}
|
||||
$photo = Photo::selectFirst([], ['resource-id' => $matches[1], 'scale' => $matches[2]]);
|
||||
if (!empty($photo)) {
|
||||
$media['mimetype'] = $photo['type'];
|
||||
$media['size'] = $photo['datasize'];
|
||||
$media['width'] = $photo['width'];
|
||||
$media['height'] = $photo['height'];
|
||||
}
|
||||
|
||||
if (!preg_match('|.*?/photo/(.*[a-fA-F0-9])\-(.*[0-9])\..*[\w]|', $media['preview'], $matches)) {
|
||||
return $media;
|
||||
}
|
||||
$photo = Photo::selectFirst([], ['resource-id' => $matches[1], 'scale' => $matches[2]]);
|
||||
if (!empty($photo)) {
|
||||
$media['preview-width'] = $photo['width'];
|
||||
$media['preview-height'] = $photo['height'];
|
||||
}
|
||||
|
||||
return $media;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the detected type to the media array
|
||||
*
|
||||
|
|
|
@ -38,6 +38,7 @@ use Friendica\DI;
|
|||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Protocol\Diaspora;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\HTTPSignature;
|
||||
use Friendica\Util\Network;
|
||||
use Friendica\Util\Proxy as ProxyUtils;
|
||||
use Friendica\Util\Strings;
|
||||
|
@ -828,11 +829,11 @@ class Profile
|
|||
// Try to find the public contact entry of the visitor.
|
||||
$cid = Contact::getIdForURL($handle);
|
||||
if (!$cid) {
|
||||
Logger::log('unable to finger ' . $handle, Logger::DEBUG);
|
||||
Logger::info('Handle not found', ['handle' => $handle]);
|
||||
return [];
|
||||
}
|
||||
|
||||
$visitor = DBA::selectFirst('contact', [], ['id' => $cid]);
|
||||
$visitor = Contact::getById($cid);
|
||||
|
||||
// Authenticate the visitor.
|
||||
$_SESSION['authenticated'] = 1;
|
||||
|
@ -851,6 +852,19 @@ class Profile
|
|||
return $visitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the visitor cookies (see remote_user()) for signed HTTP requests
|
||||
* @return array Visitor contact array
|
||||
*/
|
||||
public static function addVisitorCookieForHTTPSigner()
|
||||
{
|
||||
$requester = HTTPSignature::getSigner('', $_SERVER);
|
||||
if (empty($requester)) {
|
||||
return [];
|
||||
}
|
||||
return Profile::addVisitorCookieForHandle($requester);
|
||||
}
|
||||
|
||||
/**
|
||||
* OpenWebAuth authentication.
|
||||
*
|
||||
|
|
|
@ -33,8 +33,8 @@ use Friendica\Model\Storage\ExternalResource;
|
|||
use Friendica\Model\Storage\SystemResource;
|
||||
use Friendica\Util\Proxy;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Util\HTTPSignature;
|
||||
use Friendica\Util\Images;
|
||||
use Friendica\Util\Network;
|
||||
|
||||
/**
|
||||
* Photo Module
|
||||
|
@ -67,10 +67,7 @@ class Photo extends BaseModule
|
|||
exit;
|
||||
}
|
||||
|
||||
$requester = HTTPSignature::getSigner('', $_SERVER);
|
||||
if (!empty($requester)) {
|
||||
Profile::addVisitorCookieForHandle($requester);
|
||||
}
|
||||
Profile::addVisitorCookieForHTTPSigner();
|
||||
|
||||
$customsize = 0;
|
||||
$square_resize = true;
|
||||
|
@ -193,6 +190,10 @@ class Photo extends BaseModule
|
|||
return false;
|
||||
}
|
||||
|
||||
if (Network::isLocalLink($url) && preg_match('|.*?/photo/(.*[a-fA-F0-9])\-(.*[0-9])\..*[\w]|', $url, $matches)) {
|
||||
return MPhoto::getPhoto($matches[1], $matches[2]);
|
||||
}
|
||||
|
||||
return MPhoto::createPhotoForExternalResource($url, (int)local_user());
|
||||
case "media":
|
||||
$media = DBA::selectFirst('post-media', ['url', 'uri-id'], ['id' => $uid, 'type' => Post\Media::IMAGE]);
|
||||
|
@ -200,6 +201,10 @@ class Photo extends BaseModule
|
|||
return false;
|
||||
}
|
||||
|
||||
if (Network::isLocalLink($media['url']) && preg_match('|.*?/photo/(.*[a-fA-F0-9])\-(.*[0-9])\..*[\w]|', $media['url'], $matches)) {
|
||||
return MPhoto::getPhoto($matches[1], $matches[2]);
|
||||
}
|
||||
|
||||
return MPhoto::createPhotoForExternalResource($media['url'], (int)local_user());
|
||||
case "contact":
|
||||
$contact = Contact::getById($uid, ['uid', 'url', 'avatar', 'photo', 'xmpp', 'addr']);
|
||||
|
|
Loading…
Reference in a new issue