-- ------------------------------------------
-- Friendica 2021.03-dev (Red Hot Poker)
--- DB_UPDATE_VERSION 1401
+-- DB_UPDATE_VERSION 1402
-- ------------------------------------------
INDEX `uid_hidden` (`uid`,`hidden`),
INDEX `event-id` (`event-id`),
INDEX `uid_wall` (`uid`,`wall`),
- INDEX `parent-uri-id` (`parent-uri-id`),
+ INDEX `parent-uri-id_uid` (`parent-uri-id`,`uid`),
INDEX `thr-parent-id` (`thr-parent-id`),
INDEX `external-id` (`external-id`),
INDEX `owner-id` (`owner-id`),
- INDEX `author-id` (`author-id`),
+ INDEX `author-id_uid` (`author-id`,`uid`),
INDEX `causer-id` (`causer-id`),
INDEX `vid` (`vid`),
INDEX `uid_received` (`uid`,`received`),
`post-user`.`unseen` AS `unseen`,
`post-user`.`deleted` AS `deleted`,
`post-user`.`origin` AS `origin`,
+ `post-thread-user`.`origin` AS `parent-origin`,
`post-thread-user`.`forum_mode` AS `forum_mode`,
`post-thread-user`.`mention` AS `mention`,
`post-user`.`global` AS `global`,
return;
}
- $Aname = $item['author-name'];
- $Alink = $item['author-link'];
-
$obj = XML::parseString($xmlhead . $item['object']);
$Bname = $obj->title;
}
}
- $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
- $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
- if ($Bphoto != "") {
+ $author = ['uid' => 0, 'id' => $item['author-id'],
+ 'network' => $item['author-network'], 'url' => $item['author-link']];
+ $A = '[url=' . Contact::magicLinkByContact($author) . ']' . $item['author-name'] . '[/url]';
+
+ if (!empty($Blink)) {
+ $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
+ } else {
+ $B = '';
+ }
+
+ if ($Bphoto != "" && !empty($Blink)) {
$Bphoto = '[url=' . Contact::magicLink($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
}
}
// add sparkle links to appropriate permalinks
- $author = ['uid' => 0, 'id' => $item['author-id'],
- 'network' => $item['author-network'], 'url' => $item['author-link']];
-
// Only create a redirection to a magic link when logged in
if (!empty($item['plink']) && Session::isAuthenticated()) {
+ $author = ['uid' => 0, 'id' => $item['author-id'],
+ 'network' => $item['author-network'], 'url' => $item['author-link']];
$item['plink'] = Contact::magicLinkByContact($author, $item['plink']);
}
}
}
if (($row['gravity'] == GRAVITY_PARENT) && !empty($row['causer-id'])) {
- $row['reshared'] = DI::l10n()->t('%s reshared this.', '<a href="'. htmlentities(Contact::magicLinkById($row['causer-id'])) .'">' . htmlentities($name) . '</a>');
+ $causer = ['uid' => 0, 'id' => $row['causer-id'],
+ 'network' => $row['causer-network'], 'url' => $row['causer-link']];
+ $row['reshared'] = DI::l10n()->t('%s reshared this.', '<a href="'. htmlentities(Contact::magicLinkByContact($causer)) .'">' . htmlentities($name) . '</a>');
}
$row['direction'] = ['direction' => 3, 'title' => (empty($row['causer-id']) ? DI::l10n()->t('Reshared') : DI::l10n()->t('Reshared by %s', $name))];
break;
$sparkle = (strpos($profile_link, 'redir/') === 0);
$cid = 0;
- $pcid = Contact::getIdForURL($item['author-link'], 0, false);
+ $pcid = $item['author-id'];
$network = '';
$rel = 0;
$condition = ['uid' => local_user(), 'nurl' => Strings::normaliseLink($item['author-link'])];
continue;
}
- $profile_url = Contact::magicLinkById($item['author-id']);
+ $author = ['uid' => 0, 'id' => $item['author-id'],
+ 'network' => $item['author-network'], 'url' => $item['author-link']];
+ $profile_url = Contact::magicLinkByContact($author);
if (strpos($profile_url, 'redir/') === 0) {
$sparkle = ' sparkle';
} else {
local_user(), Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url),
Strings::normaliseLink($url), $url];
- $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
+ $contact = DBA::selectFirst('contact', ['url', 'id', 'uid', 'network', 'addr', 'name'], $condition);
if (!DBA::isResult($contact)) {
notice(DI::l10n()->t("You aren't following this contact."));
'$submit' => DI::l10n()->t('Submit Request'),
'$cancel' => DI::l10n()->t('Cancel'),
'$url' => $contact['url'],
- '$zrl' => Contact::magicLink($contact['url']),
+ '$zrl' => Contact::magicLinkByContact($contact),
'$url_label' => DI::l10n()->t('Profile URL'),
'$myaddr' => $self['url'],
'$request' => $request,
*/
class ContactSelector
{
+ static $serverdata = [];
+ static $server_url = [];
+
/**
* @param string $current current
* @param boolean $disabled optional, default false
return $o;
}
+ private static function getServerForProfile(string $profile)
+ {
+ $server_url = self::getServerURLForProfile($profile);
+
+ if (!empty(self::$serverdata[$server_url])) {
+ return self::$serverdata[$server_url];
+ }
+
+ // Now query the GServer for the platform name
+ $gserver = DBA::selectFirst('gserver', ['platform', 'network'], ['nurl' => $server_url]);
+
+ self::$serverdata[$server_url] = $gserver;
+ return $gserver;
+ }
+
/**
* @param string $profile Profile URL
* @return string Server URL
*/
private static function getServerURLForProfile($profile)
{
+ if (!empty(self::$server_url[$profile])) {
+ return self::$server_url[$profile];
+ }
+
$server_url = '';
// Fetch the server url from the contact table
$server_url = Strings::normaliseLink(Network::unparseURL($parts));
}
+ self::$server_url[$profile] = $server_url;
+
return $server_url;
}
$networkname = str_replace($search, $replace, $network);
if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) {
- $server_url = self::getServerURLForProfile($profile);
-
- // Now query the GServer for the platform name
- $gserver = DBA::selectFirst('gserver', ['platform', 'network'], ['nurl' => $server_url]);
+ $gserver = self::getServerForProfile($profile);
- if (DBA::isResult($gserver)) {
- if (!empty($gserver['platform'])) {
- $platform = $gserver['platform'];
- } elseif (!empty($gserver['network']) && ($gserver['network'] != Protocol::ACTIVITYPUB)) {
- $platform = self::networkToName($gserver['network']);
- }
+ if (!empty($gserver['platform'])) {
+ $platform = $gserver['platform'];
+ } elseif (!empty($gserver['network']) && ($gserver['network'] != Protocol::ACTIVITYPUB)) {
+ $platform = self::networkToName($gserver['network']);
+ }
- if (!empty($platform)) {
- $networkname = $platform;
+ if (!empty($platform)) {
+ $networkname = $platform;
- if ($network == Protocol::ACTIVITYPUB) {
- $networkname .= ' (AP)';
- }
+ if ($network == Protocol::ACTIVITYPUB) {
+ $networkname .= ' (AP)';
}
}
}
$network_icon = str_replace($search, $replace, $network);
if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) {
- $server_url = self::getServerURLForProfile($profile);
-
- // Now query the GServer for the platform name
- $gserver = DBA::selectFirst('gserver', ['platform'], ['nurl' => $server_url]);
-
- if (DBA::isResult($gserver) && !empty($gserver['platform'])) {
+ $gserver = self::getServerForProfile($profile);
+ if (!empty($gserver['platform'])) {
$network_icon = $platform_icons[strtolower($gserver['platform'])] ?? $network_icon;
}
}
$forumlist = [];
- $fields = ['id', 'url', 'name', 'micro', 'thumb', 'avatar'];
+ $fields = ['id', 'url', 'name', 'micro', 'thumb', 'avatar', 'network', 'uid'];
$condition = [$condition_str, Protocol::DFRN, Protocol::ACTIVITYPUB, $uid];
$contacts = DBA::select('contact', $fields, $condition, $params);
if (!$contacts) {
$entry = [
'url' => $baseurl . '/' . $contact['id'],
- 'external_url' => Contact::magicLink($contact['url']),
+ 'external_url' => Contact::magicLinkByContact($contact),
'name' => $contact['name'],
'cid' => $contact['id'],
'selected' => $selected,
$redir = false;
if ($redirect) {
- $url = Contact::magicLink($contact['url']);
+ $url = Contact::magicLinkByContact($contact);
if (strpos($url, 'redir/') === 0) {
$sparkle = ' sparkle';
}
namespace Friendica\Content;
use Friendica\Core\Addon;
+use Friendica\Core\Cache\Duration;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
$extra_sql = self::unavailableNetworks();
- $r = DBA::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND NOT `deleted` AND `network` != '' $extra_sql ORDER BY `network`",
+ $r = DBA::p("SELECT `network` FROM `contact` WHERE `uid` = ? AND NOT `deleted` AND `network` != '' $extra_sql GROUP BY `network` ORDER BY `network`",
local_user()
);
$entries = [];
foreach ($commonContacts as $contact) {
$entries[] = [
- 'url' => Contact::magicLink($contact['url']),
+ 'url' => Contact::magicLinkByContact($contact),
'name' => $contact['name'],
'photo' => Contact::getThumb($contact),
];
$ret = [];
- $dthen = Item::firstPostDate($uid, $wall);
+ $cachekey = 'Widget::postedByYear' . $uid . '-' . (int)$wall;
+ $dthen = DI::cache()->get($cachekey);
+ if (!empty($dthen)) {
+ $dthen = Item::firstPostDate($uid, $wall);
+ DI::cache()->set($cachekey, $dthen, Duration::HOUR);
+ }
+
if ($dthen) {
// Set the start and end date to the beginning of the month
$dnow = substr($dnow, 0, 8) . '01';
'archive' => false,
'deleted' => false,
'pending' => false,
+ 'network' => Protocol::FEDERATED,
'rel' => [Contact::FOLLOWER, Contact::FRIEND]
], $condition),
$params
$acl_forums = Contact::selectToArray($fields,
['uid' => $user_id, 'self' => false, 'blocked' => false, 'archive' => false, 'deleted' => false,
- 'pending' => false, 'contact-type' => Contact::TYPE_COMMUNITY], $params
+ 'network' => Protocol::FEDERATED, 'pending' => false, 'contact-type' => Contact::TYPE_COMMUNITY], $params
);
$acl_contacts = array_merge($acl_forums, $acl_contacts);
if (empty($contact['uid']) || ($contact['uid'] != $uid)) {
if ($uid == 0) {
- $profile_link = self::magicLink($contact['url']);
+ $profile_link = self::magicLinkByContact($contact);
$menu = ['profile' => [DI::l10n()->t('View Profile'), $profile_link, true]];
return $menu;
return 'contact/' . $contact['id'] . '/conversations';
}
- if ($contact['network'] != Protocol::DFRN) {
+ if (!empty($contact['network']) && $contact['network'] != Protocol::DFRN) {
return $destination;
}
- if (!empty($contact['uid'])) {
+ if (!empty($contact['uid']) || empty($contact['network'])) {
return self::magicLink($contact['url'], $url);
}
}
/**
- * Returns a random, global contact of the current node
+ * Returns a random, global contact array of the current node
*
- * @return string The profile URL
+ * @return array The profile array
* @throws Exception
*/
- public static function getRandomUrl()
+ public static function getRandomContact()
{
- $r = DBA::selectFirst('contact', ['url'], [
+ $contact = DBA::selectFirst('contact', ['id', 'network', 'url', 'uid'], [
"`uid` = ? AND `network` = ? AND NOT `failed` AND `last-item` > ?",
0, Protocol::DFRN, DateTimeFormat::utc('now - 1 month'),
], ['order' => ['RAND()']]);
- if (DBA::isResult($r)) {
- return $r['url'];
+ if (DBA::isResult($contact)) {
+ return $contact;
}
- return '';
+ return [];
}
}
$location = self::locationToArray($item['event-location']);
// Construct the profile link (magic-auth).
- $profile_link = Contact::magicLinkById($item['author-id']);
+ $author = ['uid' => 0, 'id' => $item['author-id'],
+ 'network' => $item['author-network'], 'url' => $item['author-link']];
+ $profile_link = Contact::magicLinkByContact($author);
$tpl = Renderer::getMarkupTemplate('event_stream_item.tpl');
$return = Renderer::replaceMacros($tpl, [
use Friendica\Model\Tag;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
-use Friendica\Database\DBStructure;
use Friendica\DI;
use Friendica\Model\Post;
use Friendica\Protocol\Activity;
'uid', 'id', 'parent', 'guid', 'network', 'gravity',
'uri-id', 'uri', 'thr-parent-id', 'thr-parent', 'parent-uri-id', 'parent-uri',
'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
- 'wall', 'private', 'starred', 'origin', 'title', 'body', 'language',
+ 'wall', 'private', 'starred', 'origin', 'parent-origin', 'title', 'body', 'language',
'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'owner-network',
- 'causer-id', 'causer-link', 'causer-name', 'causer-avatar', 'causer-contact-type',
+ 'causer-id', 'causer-link', 'causer-name', 'causer-avatar', 'causer-contact-type', 'causer-network',
'contact-id', 'contact-uid', 'contact-link', 'contact-name', 'contact-avatar',
'writable', 'self', 'cid', 'alias',
'event-created', 'event-edited', 'event-start', 'event-finish',
$params = ['order' => ['received' => false]];
$thread = Post::selectFirst(['received'], $condition, $params);
if (DBA::isResult($thread)) {
- return substr(DateTimeFormat::local($thread['received']), 0, 10);
+ $postdate = substr(DateTimeFormat::local($thread['received']), 0, 10);
+ return $postdate;
}
return false;
}
foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]) as $attachment) {
$mime = $attachment['mimetype'];
- $the_url = Contact::magicLinkById($item['author-id'], $attachment['url']);
+ $author = ['uid' => 0, 'id' => $item['author-id'],
+ 'network' => $item['author-network'], 'url' => $item['author-link']];
+ $the_url = Contact::magicLinkByContact($author, $attachment['url']);
if (strpos($mime, 'video') !== false) {
if (!$vhead) {
$today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
- $rr['link'] = Contact::magicLink($rr['url']);
+ $rr['link'] = Contact::magicLinkById($rr['cid']);
$rr['title'] = $rr['name'];
$rr['date'] = DI::l10n()->getDay(DateTimeFormat::convert($rr['start'], $a->timezone, 'UTC', $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . DI::l10n()->t('[today]') : '');
$rr['startime'] = null;
$searchpath = DI::baseUrl() . "/search?tag=";
- $taglist = DBA::select('tag-view', ['type', 'name', 'url'],
+ $taglist = DBA::select('tag-view', ['type', 'name', 'url', 'cid'],
['uri-id' => $item['uri-id'], 'type' => [self::HASHTAG, self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION]]);
while ($tag = DBA::fetch($taglist)) {
if ($tag['url'] == '') {
break;
case self::MENTION:
case self::EXCLUSIVE_MENTION:
+ if (!empty($tag['cid'])) {
+ $tag['url'] = Contact::magicLinkById($tag['cid']);
+ } else {
$tag['url'] = Contact::magicLink($tag['url']);
+ }
$return['mentions'][] = $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a>';
$return['tags'][] = $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a>';
break;
$relation_text = sprintf($relation_text, $contact['name']);
- $url = Model\Contact::magicLink($contact['url']);
+ $url = Model\Contact::magicLinkByContact($contact);
if (strpos($url, 'redir/') === 0) {
$sparkle = ' class="sparkle" ';
} else {
}
}
- $url = Model\Contact::magicLink($contact['url']);
+ $url = Model\Contact::magicLinkByContact($contact);
if (strpos($url, 'redir/') === 0) {
$sparkle = ' class="sparkle" ';
'nick' => $contact['nick'],
'addr' => $contact['addr'] ?: $contact['url'],
'thumb' => Contact::getThumb($contact),
- 'url' => Contact::magicLink($contact['url']),
+ 'url' => Contact::magicLinkByContact($contact),
'nurl' => $contact['nurl'],
'location' => $contact['location'],
'about' => $contact['about'],
throw new HTTPException\NotFoundException(DI::l10n()->t('Item not found.'));
}
- $item = Post::selectFirst(['body'], ['uid' => local_user(), 'id' => $itemId]);
+ $item = Post::selectFirst(['body'], ['uid' => local_user(), 'uri-id' => $itemId]);
if (!empty($item)) {
if (DI::mode()->isAjax()) {
{
$a = DI::app();
- $contactUrl = Contact::getRandomUrl();
+ $contact = Contact::getRandomContact();
- if ($contactUrl) {
- $link = Contact::magicLink($contactUrl);
+ if (!empty($contact)) {
+ $link = Contact::magicLinkByContact($contact);
$a->redirect($link);
}
$dropping = true;
}
- $origin = $item['origin'];
-
- if (!$origin) {
- /// @todo This shouldn't be done as query here, but better during the data creation.
- // it is now done here, since during the RC phase we shouldn't make to intense changes.
- $parent = PostModel::selectFirst(['origin'], ['id' => $item['parent']]);
- if (DBA::isResult($parent)) {
- $origin = $parent['origin'];
- }
- } elseif ($item['pinned']) {
+ $origin = $item['origin'] || $item['parent-origin'];
+
+ if ($item['pinned']) {
$pinned = DI::l10n()->t('pinned item');
}
$profile_name = $item['author-link'];
}
- $author = ['uid' => 0, 'id' => $item['author-id'],
- 'network' => $item['author-network'], 'url' => $item['author-link']];
-
if (Session::isAuthenticated()) {
+ $author = ['uid' => 0, 'id' => $item['author-id'],
+ 'network' => $item['author-network'], 'url' => $item['author-link']];
$profile_link = Contact::magicLinkByContact($author);
} else {
$profile_link = $item['author-link'];
// This will have been stored in $a->page_contact by our calling page.
// Put this person as the wall owner of the wall-to-wall notice.
- $this->owner_url = Contact::magicLink($a->page_contact['url']);
+ $this->owner_url = Contact::magicLinkByContact($a->page_contact);
$this->owner_photo = $a->page_contact['thumb'];
$this->owner_name = $a->page_contact['name'];
$this->wall_to_wall = true;
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1401);
+ define('DB_UPDATE_VERSION', 1402);
}
return [
"uid_hidden" => ["uid", "hidden"],
"event-id" => ["event-id"],
"uid_wall" => ["uid", "wall"],
- "parent-uri-id" => ["parent-uri-id"],
+ "parent-uri-id_uid" => ["parent-uri-id", "uid"],
"thr-parent-id" => ["thr-parent-id"],
"external-id" => ["external-id"],
"owner-id" => ["owner-id"],
- "author-id" => ["author-id"],
+ "author-id_uid" => ["author-id", "uid"],
"causer-id" => ["causer-id"],
"vid" => ["vid"],
"uid_received" => ["uid", "received"],
"unseen" => ["post-user", "unseen"],
"deleted" => ["post-user", "deleted"],
"origin" => ["post-user", "origin"],
+ "parent-origin" => ["post-thread-user", "origin"],
"forum_mode" => ["post-thread-user", "forum_mode"],
"mention" => ["post-thread-user", "mention"],
"global" => ["post-user", "global"],