use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
-use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\Database;
* Relationship types
* @{
*/
- const NOTHING = 0;
- const FOLLOWER = 1;
- const SHARING = 2;
- const FRIEND = 3;
- const SELF = 4;
+ const NOTHING = 0; // There is no relationship between the contact and the user
+ const FOLLOWER = 1; // The contact is following this user (the contact is the subscriber)
+ const SHARING = 2; // The contact shares their content with this user (the user is the subscriber)
+ const FRIEND = 3; // There is a mutual relationship between the contact and the user
+ const SELF = 4; // This is the user theirself
/**
* @}
*/
return DBA::selectFirst('contact', $fields, ['uri-id' => $uri_id], ['order' => ['uid']]);
}
+ /**
+ * Fetch all remote contacts for a given contact url
+ *
+ * @param string $url The URL of the contact
+ * @param array $fields The wanted fields
+ *
+ * @return array all remote contacts
+ *
+ * @throws \Exception
+ */
+ public static function getVisitorByUrl(string $url, array $fields = ['id', 'uid']): array
+ {
+ $remote = [];
+
+ $remote_contacts = DBA::select('contact', ['id', 'uid'], ['nurl' => Strings::normaliseLink($url), 'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'self' => false]);
+ while ($contact = DBA::fetch($remote_contacts)) {
+ if (($contact['uid'] == 0) || Contact\User::isBlocked($contact['id'], $contact['uid'])) {
+ continue;
+ }
+ $remote[$contact['uid']] = $contact['id'];
+ }
+ DBA::close($remote_contacts);
+
+ return $remote;
+ }
+
/**
* Fetches a contact by a given url
*
'notify' => DI::baseUrl() . '/dfrn_notify/' . $user['nickname'],
'poll' => DI::baseUrl() . '/dfrn_poll/' . $user['nickname'],
'confirm' => DI::baseUrl() . '/dfrn_confirm/' . $user['nickname'],
- 'poco' => DI::baseUrl() . '/poco/' . $user['nickname'],
'name-date' => DateTimeFormat::utcNow(),
'uri-date' => DateTimeFormat::utcNow(),
'avatar-date' => DateTimeFormat::utcNow(),
'notify' => DI::baseUrl() . '/dfrn_notify/' . $user['nickname'],
'poll' => DI::baseUrl() . '/dfrn_poll/'. $user['nickname'],
'confirm' => DI::baseUrl() . '/dfrn_confirm/' . $user['nickname'],
- 'poco' => DI::baseUrl() . '/poco/' . $user['nickname'],
];
self::clearFollowerFollowingEndpointCache($contact['uid']);
// Archive the contact
- self::update(['archive' => true, 'network' => Protocol::PHANTOM, 'deleted' => true], ['id' => $id]);
+ self::update(['archive' => true, 'network' => Protocol::PHANTOM, 'rel' => self::NOTHING, 'deleted' => true], ['id' => $id]);
if (!DBA::exists('contact', ['uri-id' => $contact['uri-id'], 'deleted' => false])) {
Avatar::deleteCache($contact);
$photos_link = '';
if ($uid == 0) {
- $uid = local_user();
+ $uid = DI::userSession()->getLocalUserId();
}
if (empty($contact['uid']) || ($contact['uid'] != $uid)) {
$sparkle = false;
if (($contact['network'] === Protocol::DFRN) && !$contact['self'] && empty($contact['pending'])) {
$sparkle = true;
- $profile_link = DI::baseUrl() . '/redir/' . $contact['id'];
+ $profile_link = 'contact/redir/' . $contact['id'];
} else {
$profile_link = $contact['url'];
}
if ($sparkle) {
$status_link = $profile_link . '/status';
- $photos_link = str_replace('/profile/', '/photos/', $profile_link);
+ $photos_link = $profile_link . '/photos';
$profile_link = $profile_link . '/profile';
}
if (self::canReceivePrivateMessages($contact) && empty($contact['pending'])) {
- $pm_url = DI::baseUrl() . '/message/new/' . $contact['id'];
+ $pm_url = 'message/new/' . $contact['id'];
}
- $contact_url = DI::baseUrl() . '/contact/' . $contact['id'];
+ $contact_url = 'contact/' . $contact['id'];
- $posts_link = DI::baseUrl() . '/contact/' . $contact['id'] . '/conversations';
+ $posts_link = 'contact/' . $contact['id'] . '/conversations';
$follow_link = '';
$unfollow_link = '';
if (!$contact['self'] && Protocol::supportsFollow($contact['network'])) {
if ($contact['uid'] && in_array($contact['rel'], [self::SHARING, self::FRIEND])) {
- $unfollow_link = 'unfollow?url=' . urlencode($contact['url']) . '&auto=1';
+ $unfollow_link = 'contact/unfollow?url=' . urlencode($contact['url']) . '&auto=1';
} elseif(!$contact['pending']) {
- $follow_link = 'follow?url=' . urlencode($contact['url']) . '&auto=1';
+ $follow_link = 'contact/follow?url=' . urlencode($contact['url']) . '&auto=1';
}
}
'network' => [DI::l10n()->t('Network Posts') , $posts_link , false],
'edit' => [DI::l10n()->t('View Contact') , $contact_url , false],
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true],
- 'unfollow'=> [DI::l10n()->t('UnFollow') , $unfollow_link, true],
+ 'unfollow'=> [DI::l10n()->t('Unfollow') , $unfollow_link, true],
];
} else {
$menu = [
'edit' => [DI::l10n()->t('View Contact') , $contact_url , false],
'pm' => [DI::l10n()->t('Send PM') , $pm_url , false],
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true],
- 'unfollow'=> [DI::l10n()->t('UnFollow') , $unfollow_link , true],
+ 'unfollow'=> [DI::l10n()->t('Unfollow') , $unfollow_link , true],
];
if (!empty($contact['pending'])) {
'writable' => 1,
'blocked' => 0,
'readonly' => 0,
- 'pending' => 0];
+ 'pending' => 0,
+ ];
- $condition = ['nurl' => Strings::normaliseLink($data["url"]), 'uid' => $uid, 'deleted' => false];
+ $condition = ['nurl' => Strings::normaliseLink($data['url']), 'uid' => $uid, 'deleted' => false];
// Before inserting we do check if the entry does exist now.
$contact = DBA::selectFirst('contact', ['id'], $condition, ['order' => ['id']]);
if ($thread_mode) {
$condition = ["((`$contact_field` = ? AND `gravity` = ?) OR (`author-id` = ? AND `gravity` = ? AND `vid` = ? AND `thr-parent-id` = `parent-uri-id`)) AND " . $sql,
- $cid, Item::GRAVITY_PARENT, $cid, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), local_user()];
+ $cid, Item::GRAVITY_PARENT, $cid, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), DI::userSession()->getLocalUserId()];
} else {
$condition = ["`$contact_field` = ? AND `gravity` IN (?, ?) AND " . $sql,
- $cid, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, local_user()];
+ $cid, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, DI::userSession()->getLocalUserId()];
}
if (!empty($parent)) {
}
if (DI::mode()->isMobile()) {
- $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
+ $itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network',
DI::config()->get('system', 'itemspage_network_mobile'));
} else {
- $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
+ $itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network',
DI::config()->get('system', 'itemspage_network'));
}
$params = ['order' => ['received' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
- if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
+ if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
$tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
$o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
} else {
if ($thread_mode) {
$fields = ['uri-id', 'thr-parent-id', 'gravity', 'author-id', 'commented'];
- $items = Post::toArray(Post::selectForUser(local_user(), $fields, $condition, $params));
+ $items = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), $fields, $condition, $params));
if ($pager->getStart() == 0) {
- $cdata = self::getPublicAndUserContactID($cid, local_user());
+ $cdata = self::getPublicAndUserContactID($cid, DI::userSession()->getLocalUserId());
if (!empty($cdata['public'])) {
$pinned = Post\Collection::selectToArrayForContact($cdata['public'], Post\Collection::FEATURED, $fields);
$items = array_merge($items, $pinned);
}
}
- $o .= DI::conversation()->create($items, 'contacts', $update, false, 'pinned_commented', local_user());
+ $o .= DI::conversation()->create($items, 'contacts', $update, false, 'pinned_commented', DI::userSession()->getLocalUserId());
} else {
$fields = array_merge(Item::DISPLAY_FIELDLIST, ['featured']);
- $items = Post::toArray(Post::selectForUser(local_user(), $fields, $condition, $params));
+ $items = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), $fields, $condition, $params));
if ($pager->getStart() == 0) {
- $cdata = self::getPublicAndUserContactID($cid, local_user());
+ $cdata = self::getPublicAndUserContactID($cid, DI::userSession()->getLocalUserId());
if (!empty($cdata['public'])) {
$condition = ["`uri-id` IN (SELECT `uri-id` FROM `collection-view` WHERE `cid` = ? AND `type` = ?)",
$cdata['public'], Post\Collection::FEATURED];
- $pinned = Post::toArray(Post::selectForUser(local_user(), $fields, $condition, $params));
+ $pinned = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), $fields, $condition, $params));
$items = array_merge($pinned, $items);
}
}
}
if (!$update) {
- if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
+ if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
$o .= HTML::scrollLoader();
} else {
$o .= $pager->renderMinimal(count($items));
*/
public static function magicLink(string $contact_url, string $url = ''): string
{
- if (!Session::isAuthenticated()) {
+ if (!DI::userSession()->isAuthenticated()) {
return $url ?: $contact_url; // Equivalent to: ($url != '') ? $url : $contact_url;
}
{
$destination = $url ?: $contact['url']; // Equivalent to ($url != '') ? $url : $contact['url'];
- if (!Session::isAuthenticated()) {
+ if (!DI::userSession()->isAuthenticated()) {
return $destination;
}
return $url;
}
- if (DI::pConfig()->get(local_user(), 'system', 'stay_local') && ($url == '')) {
+ if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'stay_local') && ($url == '')) {
return 'contact/' . $contact['id'] . '/conversations';
}
return $destination;
}
- $redirect = 'redir/' . $contact['id'];
+ $redirect = 'contact/redir/' . $contact['id'];
if (($url != '') && !Strings::compareLink($contact['url'], $url)) {
$redirect .= '?url=' . $url;
* @param string $search Name or nick
* @param string $mode Search mode (e.g. "community")
* @param int $uid User ID
+ * @param int $limit Maximum amount of returned values
+ * @param int $offset Limit offset
*
* @return array with search results
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function searchByName(string $search, string $mode = '', int $uid = 0): array
+ public static function searchByName(string $search, string $mode = '', int $uid = 0, int $limit = 0, int $offset = 0): array
{
if (empty($search)) {
return [];
if ($uid == 0) {
$condition['blocked'] = false;
+ } else {
+ $condition['rel'] = [Contact::SHARING, Contact::FRIEND];
}
// check if we search only communities or every contact
$search .= '%';
+ $params = [];
+
+ if (!empty($limit) && !empty($offset)) {
+ $params['limit'] = [$offset, $limit];
+ } elseif (!empty($limit)) {
+ $params['limit'] = $limit;
+ }
+
$condition = DBA::mergeConditions($condition,
["(NOT `unsearchable` OR `nurl` IN (SELECT `nurl` FROM `owner-view` WHERE `publish` OR `net-publish`))
AND (`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?)", $search, $search, $search]);
- $contacts = self::selectToArray([], $condition);
+ $contacts = self::selectToArray([], $condition, $params);
return $contacts;
}
return [];
}
+
+ /**
+ * Checks, if contacts with the given condition exists
+ *
+ * @param array $condition
+ *
+ * @return bool
+ * @throws \Exception
+ */
+ public static function exists(array $condition): bool
+ {
+ return DBA::exists('contact', $condition);
+ }
}