-- ------------------------------------------
-- Friendica 2021.12-dev (Siberian Iris)
--- DB_UPDATE_VERSION 1436
+-- DB_UPDATE_VERSION 1437
-- ------------------------------------------
`contact`.`url` AS `url`,
`contact`.`nurl` AS `nurl`,
`contact`.`uri-id` AS `uri-id`,
+ `item-uri`.`guid` AS `guid`,
`contact`.`addr` AS `addr`,
`contact`.`alias` AS `alias`,
`contact`.`name` AS `name`,
`apcontact`.`followers_count` AS `ap-followers_count`,
`apcontact`.`statuses_count` AS `ap-statuses_count`
FROM `contact`
+ LEFT JOIN `item-uri` ON `item-uri`.`id` = `contact`.`uri-id`
LEFT JOIN `apcontact` ON `apcontact`.`uri-id` = `contact`.`uri-id`
LEFT JOIN `fcontact` ON `fcontact`.`uri-id` = contact.`uri-id`
WHERE `contact`.`uid` = 0;
`contact`.`url` AS `url`,
`contact`.`nurl` AS `nurl`,
`contact`.`uri-id` AS `uri-id`,
+ `item-uri`.`guid` AS `guid`,
`contact`.`addr` AS `addr`,
`contact`.`alias` AS `alias`,
`contact`.`name` AS `name`,
`apcontact`.`statuses_count` AS `ap-statuses_count`
FROM `contact` AS `ucontact`
INNER JOIN `contact` ON `contact`.`uri-id` = `ucontact`.`uri-id` AND `contact`.`uid` = 0
+ LEFT JOIN `item-uri` ON `item-uri`.`id` = `ucontact`.`uri-id`
LEFT JOIN `apcontact` ON `apcontact`.`uri-id` = `ucontact`.`uri-id`
LEFT JOIN `fcontact` ON `fcontact`.`uri-id` = `ucontact`.`uri-id` AND `fcontact`.`network` = 'dspr';
* @param string $updated Contact update date
* @return string avatar link
*/
- public static function getAvatarUrlForId(int $cid, string $size = '', string $updated = ''):string
+ public static function getAvatarUrlForId(int $cid, string $size = '', string $updated = '', string $guid = ''):string
{
// We have to fetch the "updated" variable when it wasn't provided
// The parameter can be provided to improve performance
- if (empty($updated)) {
- $contact = self::getById($cid, ['updated']);
- $updated = $contact['updated'] ?? '';
+ if (empty($updated) || empty($guid)) {
+ $account = DBA::selectFirst('account-user-view', ['updated', 'guid'], ['id' => $cid]);
+ $updated = $account['updated'] ?? '';
+ $guid = $account['guid'] ?? '';
}
+ $guid = urlencode($guid);
+
$url = DI::baseUrl() . '/photo/contact/';
switch ($size) {
case Proxy::SIZE_MICRO:
$url .= Proxy::PIXEL_LARGE . '/';
break;
}
- return $url . $cid . ($updated ? '?ts=' . strtotime($updated) : '');
+ return $url . ($guid ?: $cid) . ($updated ? '?ts=' . strtotime($updated) : '');
}
/**
* @param string $updated Contact update date
* @return string header link
*/
- public static function getHeaderUrlForId(int $cid, string $size = '', string $updated = ''):string
+ public static function getHeaderUrlForId(int $cid, string $size = '', string $updated = '', string $guid = ''):string
{
// We have to fetch the "updated" variable when it wasn't provided
// The parameter can be provided to improve performance
- if (empty($updated)) {
- $contact = self::getById($cid, ['updated']);
- $updated = $contact['updated'] ?? '';
+ if (empty($updated) || empty($guid)) {
+ $account = DBA::selectFirst('account-user-view', ['updated', 'guid'], ['id' => $cid]);
+ $updated = $account['updated'] ?? '';
+ $guid = $account['guid'] ?? '';
}
+ $guid = urlencode($guid);
+
$url = DI::baseUrl() . '/photo/header/';
switch ($size) {
case Proxy::SIZE_MICRO:
break;
}
- return $url . $cid . ($updated ? '?ts=' . strtotime($updated) : '');
+ return $url . ($guid ?: $cid) . ($updated ? '?ts=' . strtotime($updated) : '');
}
/**
}
$update = false;
- $guid = $ret['guid'] ?? '';
+ $guid = $ret['guid'] ?: Item::guidFromUri($ret['url'], parse_url($ret['url'], PHP_URL_HOST));
// make sure to not overwrite existing values with blank entries except some technical fields
$keep = ['batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'baseurl'];
self::updateAvatar($id, $ret['photo'], $update);
}
+ if (empty($guid)) {
+ $uriid = ItemURI::getIdByURI($ret['url']);
+ } else {
+ $uriid = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]);
+ }
+
if (!$update) {
self::updateContact($id, $uid, $contact['url'], $ret['url'], ['failed' => false, 'last-update' => $updated, 'success_update' => $updated]);
return true;
}
- if (empty($guid)) {
- $ret['uri-id'] = ItemURI::getIdByURI($ret['url']);
- } else {
- $ret['uri-id'] = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]);
- }
-
+ $ret['uri-id'] = $uriid;
$ret['nurl'] = Strings::normaliseLink($ret['url']);
$ret['updated'] = $updated;
$ret['failed'] = false;
}
if (!empty($parameters['nickname_ext'])) {
- $nickname = pathinfo($parameters['nickname_ext'], PATHINFO_FILENAME);
- $user = User::getByNickname($nickname, ['uid']);
- if (empty($user)) {
- throw new HTTPException\NotFoundException();
- }
+ if (in_array($parameters['type'], ['contact', 'header'])) {
+ $guid = pathinfo($parameters['nickname_ext'], PATHINFO_FILENAME);
+ $account = DBA::selectFirst('account-user-view', ['id'], ['guid' => $guid], ['order' => ['uid' => true]]);
+ if (empty($account)) {
+ throw new HTTPException\NotFoundException();
+ }
+
+ $id = $account['id'];
+ } else {
+ $nickname = pathinfo($parameters['nickname_ext'], PATHINFO_FILENAME);
+ $user = User::getByNickname($nickname, ['uid']);
+ if (empty($user)) {
+ throw new HTTPException\NotFoundException();
+ }
- $uid = $user['uid'];
+ $id = $user['uid'];
+ }
}
// User Id Fallback, to remove after version 2021.12
if (!empty($parameters['uid_ext'])) {
- $uid = intval(pathinfo($parameters['uid_ext'], PATHINFO_FILENAME));
+ $id = intval(pathinfo($parameters['uid_ext'], PATHINFO_FILENAME));
}
// Please refactor this for the love of everything that's good
if (!empty($parameters['id'])) {
- $uid = $parameters['id'];
+ $id = $parameters['id'];
+ }
+
+ if (empty($id)) {
+ Logger::notice('No picture id was detected', ['parameters' => $parameters]);
+ throw new HTTPException\NotFoundException(DI::l10n()->t('The Photo is not available.'));
}
- $photo = self::getAvatar($uid, $parameters['type'], $customsize ?: Proxy::PIXEL_SMALL);
+ $photo = self::getPhotoByid($id, $parameters['type'], $customsize ?: Proxy::PIXEL_SMALL);
} else {
$photoid = pathinfo($parameters['name'], PATHINFO_FILENAME);
$scale = 0;
exit();
}
- private static function getAvatar(int $uid, $type, $customsize)
+ private static function getPhotoByid(int $id, $type, $customsize)
{
switch($type) {
case "preview":
- $media = DBA::selectFirst('post-media', ['preview', 'url', 'mimetype', 'type', 'uri-id'], ['id' => $uid]);
+ $media = DBA::selectFirst('post-media', ['preview', 'url', 'mimetype', 'type', 'uri-id'], ['id' => $id]);
if (empty($media)) {
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(), $media['mimetype']);
case "media":
- $media = DBA::selectFirst('post-media', ['url', 'mimetype', 'uri-id'], ['id' => $uid, 'type' => Post\Media::IMAGE]);
+ $media = DBA::selectFirst('post-media', ['url', 'mimetype', 'uri-id'], ['id' => $id, 'type' => Post\Media::IMAGE]);
if (empty($media)) {
return false;
}
return MPhoto::createPhotoForExternalResource($media['url'], (int)local_user(), $media['mimetype']);
case "link":
- $link = DBA::selectFirst('post-link', ['url', 'mimetype'], ['id' => $uid]);
+ $link = DBA::selectFirst('post-link', ['url', 'mimetype'], ['id' => $id]);
if (empty($link)) {
return false;
}
return MPhoto::createPhotoForExternalResource($link['url'], (int)local_user(), $link['mimetype']);
case "contact":
- $contact = Contact::getById($uid, ['uid', 'url', 'avatar', 'photo', 'xmpp', 'addr']);
+ $contact = Contact::getById($id, ['uid', 'url', 'avatar', 'photo', 'xmpp', 'addr']);
if (empty($contact)) {
return false;
}
}
return MPhoto::createPhotoForExternalResource($url);
case "header":
- $contact = Contact::getById($uid, ['uid', 'url', 'header']);
+ $contact = Contact::getById($id, ['uid', 'url', 'header']);
if (empty($contact)) {
return false;
}
$scale = 5;
}
- $photo = MPhoto::selectFirst([], ["scale" => $scale, "uid" => $uid, "profile" => 1]);
+ $photo = MPhoto::selectFirst([], ["scale" => $scale, "uid" => $id, "profile" => 1]);
if (empty($photo)) {
- $contact = DBA::selectFirst('contact', [], ['uid' => $uid, 'self' => true]) ?: [];
+ $contact = DBA::selectFirst('contact', [], ['uid' => $id, 'self' => true]) ?: [];
switch($type) {
case "profile":
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1436);
+ define('DB_UPDATE_VERSION', 1437);
}
return [
"comment" => "The local users",
"fields" => [
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
- "parent-uid" => ["type" => "mediumint unsigned", "foreign" => ["user" => "uid"],
- "comment" => "The parent user that has full control about this user"],
+ "parent-uid" => ["type" => "mediumint unsigned", "foreign" => ["user" => "uid"], "comment" => "The parent user that has full control about this user"],
"guid" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this user"],
"username" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name that this user is known by"],
"password" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "encrypted password"],
"url" => ["contact", "url"],
"nurl" => ["contact", "nurl"],
"uri-id" => ["contact", "uri-id"],
+ "guid" => ["item-uri", "guid"],
"addr" => ["contact", "addr"],
"alias" => ["contact", "alias"],
"name" => ["contact", "name"],
"ap-statuses_count" => ["apcontact", "statuses_count"],
],
"query" => "FROM `contact`
+ LEFT JOIN `item-uri` ON `item-uri`.`id` = `contact`.`uri-id`
LEFT JOIN `apcontact` ON `apcontact`.`uri-id` = `contact`.`uri-id`
LEFT JOIN `fcontact` ON `fcontact`.`uri-id` = contact.`uri-id`
WHERE `contact`.`uid` = 0"
"url" => ["contact", "url"],
"nurl" => ["contact", "nurl"],
"uri-id" => ["contact", "uri-id"],
+ "guid" => ["item-uri", "guid"],
"addr" => ["contact", "addr"],
"alias" => ["contact", "alias"],
"name" => ["contact", "name"],
],
"query" => "FROM `contact` AS `ucontact`
INNER JOIN `contact` ON `contact`.`uri-id` = `ucontact`.`uri-id` AND `contact`.`uid` = 0
+ LEFT JOIN `item-uri` ON `item-uri`.`id` = `ucontact`.`uri-id`
LEFT JOIN `apcontact` ON `apcontact`.`uri-id` = `ucontact`.`uri-id`
LEFT JOIN `fcontact` ON `fcontact`.`uri-id` = `ucontact`.`uri-id` AND `fcontact`.`network` = 'dspr'"
],