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;
*/
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');
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
*
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;
// 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;
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.
*
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
exit;
}
- $requester = HTTPSignature::getSigner('', $_SERVER);
- if (!empty($requester)) {
- Profile::addVisitorCookieForHandle($requester);
- }
+ Profile::addVisitorCookieForHTTPSigner();
$customsize = 0;
$square_resize = true;
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]);
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']);