Rework Profile::sidebar profile link conditions

- Now show Follow, Unfollow, Atom Feed and Message in profile sidebar more consistently with the status of the current visitor
- Remove pseudo-field contact.remoteconnect
This commit is contained in:
Hypolite Petovan 2019-06-10 21:33:25 -04:00
parent 61c79ce9ee
commit 3aebb92cf3
9 changed files with 150 additions and 175 deletions

View File

@ -186,16 +186,7 @@ function display_fetchauthor($a, $item)
$profiledata["photo"] = System::removedBaseUrl($profiledata["photo"]); $profiledata["photo"] = System::removedBaseUrl($profiledata["photo"]);
if (local_user()) { return $profiledata;
if (in_array($profiledata["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
$profiledata["remoteconnect"] = System::baseUrl()."/follow?url=".urlencode($profiledata["url"]);
}
} elseif ($profiledata["network"] == Protocol::DFRN) {
$connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"]);
$profiledata["remoteconnect"] = $connect;
}
return($profiledata);
} }
function display_content(App $a, $update = false, $update_uid = 0) function display_content(App $a, $update = false, $update_uid = 0)

View File

@ -124,6 +124,20 @@ class Contact extends BaseObject
return DBA::toArray($statement); return DBA::toArray($statement);
} }
/**
* @param array $fields Array of selected fields, empty for all
* @param array $condition Array of fields for condition
* @param array $params Array of several parameters
* @return array
* @throws \Exception
*/
public static function selectFirst(array $fields = [], array $condition = [], array $params = [])
{
$contact = DBA::selectFirst('contact', $fields, $condition, $params);
return $contact;
}
/** /**
* @param integer $id Contact ID * @param integer $id Contact ID
* @param array $fields Array of selected fields, empty for all * @param array $fields Array of selected fields, empty for all

View File

@ -18,6 +18,7 @@ use Friendica\Core\Logger;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
@ -302,93 +303,68 @@ class Profile
Hook::callAll('profile_sidebar_enter', $profile); Hook::callAll('profile_sidebar_enter', $profile);
// don't show connect link to yourself
$connect = $profile['uid'] != local_user() ? L10n::t('Connect') : false;
// don't show connect link to authenticated visitors either
if (remote_user() && !empty($_SESSION['remote'])) {
foreach ($_SESSION['remote'] as $visitor) {
if ($visitor['uid'] == $profile['uid']) {
$connect = false;
break;
}
}
}
if (!$show_connect) {
$connect = false;
}
$profile_url = '';
// Is the local user already connected to that user?
if ($connect && local_user()) {
if (isset($profile['url'])) { if (isset($profile['url'])) {
$profile_url = Strings::normaliseLink($profile['url']); $profile_url = $profile['url'];
} else { } else {
$profile_url = Strings::normaliseLink(System::baseUrl() . '/profile/' . $profile['nickname']); $profile_url = System::baseUrl() . '/profile/' . $profile['nickname'];
} }
if (DBA::exists('contact', ['pending' => false, 'uid' => local_user(), 'nurl' => $profile_url])) { $follow_link = null;
$connect = false; $unfollow_link = null;
} $subscribe_feed_link = null;
$wallmessage_link = null;
$visitor_contact = [];
if ($profile['uid'] && self::getMyURL()) {
$visitor_contact = Contact::selectFirst(['rel'], ['uid' => $profile['uid'], 'nurl' => Strings::normaliseLink(self::getMyURL())]);
} }
// Is the remote user already connected to that user? $profile_contact = [];
if ($connect && Contact::isFollower(remote_user(), $profile['uid'])) { if ($profile['cid'] && self::getMyURL()) {
$connect = false; $profile_contact = Contact::selectFirst(['rel'], ['id' => $profile['cid']]);
} }
if ($connect && ($profile['network'] != Protocol::DFRN) && !isset($profile['remoteconnect'])) { $profile_is_dfrn = $profile['network'] == Protocol::DFRN;
$connect = false; $profile_is_native = in_array($profile['network'], Protocol::NATIVE_SUPPORT);
} $local_user_is_self = local_user() && local_user() == ($profile['profile_uid'] ?? 0);
$visitor_is_authenticated = (bool)self::getMyURL();
$visitor_is_following =
in_array($visitor_contact['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND])
|| in_array($profile_contact['rel'] ?? 0, [Contact::SHARING, Contact::FRIEND]);
$visitor_is_followed =
in_array($visitor_contact['rel'] ?? 0, [Contact::SHARING, Contact::FRIEND])
|| in_array($profile_contact['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND]);
$visitor_base_path = self::getMyURL() ? preg_replace('=/profile/(.*)=ism', '', self::getMyURL()) : '';
$remoteconnect = null; if (!$local_user_is_self) {
if (isset($profile['remoteconnect'])) { if (!$visitor_is_authenticated) {
$remoteconnect = $profile['remoteconnect']; $follow_link = 'dfrn_request/' . $profile['nickname'];
} } elseif ($profile_is_native) {
if ($visitor_is_following) {
if ($connect && ($profile['network'] == Protocol::DFRN) && !isset($remoteconnect)) { $unfollow_link = $visitor_base_path . '/unfollow?url=' . urlencode($profile_url);
$subscribe_feed = L10n::t('Atom feed');
} else { } else {
$subscribe_feed = false; $follow_link = $visitor_base_path .'/follow?url=' . urlencode($profile_url);
}
} }
$wallmessage = false; if ($profile_is_dfrn) {
$wallmessage_link = false; $subscribe_feed_link = 'dfrn_poll/' . $profile['nickname'];
// See issue https://github.com/friendica/friendica/issues/3838
// Either we remove the message link for remote users or we enable creating messages from remote users
if (remote_user() || (self::getMyURL() && !empty($profile['unkmail']) && ($profile['uid'] != local_user()))) {
$wallmessage = L10n::t('Message');
if (remote_user()) {
$r = q(
"SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
intval($profile['uid']),
intval(remote_user()),
intval(Contact::FRIEND)
);
} else {
$r = q(
"SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
intval($profile['uid']),
DBA::escape(Strings::normaliseLink(self::getMyURL())),
intval(Contact::FRIEND)
);
} }
if ($r) {
$remote_url = $r[0]['url']; if (Contact::canReceivePrivateMessages($profile)) {
$message_path = preg_replace('=(.*)/profile/(.*)=ism', '$1/message/new/', $remote_url); if ($visitor_is_followed || $visitor_is_following) {
$wallmessage_link = $message_path . base64_encode(defaults($profile, 'addr', '')); $wallmessage_link = $visitor_base_path . '/message/new/' . base64_encode(defaults($profile, 'addr', ''));
} else if (!empty($profile['nickname'])) { } elseif ($visitor_is_authenticated && !empty($profile['unkmail'])) {
$wallmessage_link = 'wallmessage/' . $profile['nickname']; $wallmessage_link = 'wallmessage/' . $profile['nickname'];
} }
} }
}
// show edit profile to yourself // show edit profile to yourself
if (!$is_contact && $profile['uid'] == local_user() && Feature::isEnabled(local_user(), 'multi_profiles')) { if (!$is_contact && $local_user_is_self) {
if (Feature::isEnabled(local_user(), 'multi_profiles')) {
$profile['edit'] = [System::baseUrl() . '/profiles', L10n::t('Profiles'), '', L10n::t('Manage/edit profiles')]; $profile['edit'] = [System::baseUrl() . '/profiles', L10n::t('Profiles'), '', L10n::t('Manage/edit profiles')];
$r = q( $r = q(
"SELECT * FROM `profile` WHERE `uid` = %d", "SELECT * FROM `profile` WHERE `uid` = %d",
@ -414,8 +390,7 @@ class Profile
]; ];
} }
} }
} } else {
if (!$is_contact && $profile['uid'] == local_user() && !Feature::isEnabled(local_user(), 'multi_profiles')) {
$profile['edit'] = [System::baseUrl() . '/profiles/' . $profile['id'], L10n::t('Edit profile'), '', L10n::t('Edit profile')]; $profile['edit'] = [System::baseUrl() . '/profiles/' . $profile['id'], L10n::t('Edit profile'), '', L10n::t('Edit profile')];
$profile['menu'] = [ $profile['menu'] = [
'chg_photo' => L10n::t('Change profile photo'), 'chg_photo' => L10n::t('Change profile photo'),
@ -423,6 +398,7 @@ class Profile
'entries' => [], 'entries' => [],
]; ];
} }
}
// Fetch the account type // Fetch the account type
$account_type = Contact::getAccountType($profile); $account_type = Contact::getAccountType($profile);
@ -523,10 +499,13 @@ class Profile
$o .= Renderer::replaceMacros($tpl, [ $o .= Renderer::replaceMacros($tpl, [
'$profile' => $p, '$profile' => $p,
'$xmpp' => $xmpp, '$xmpp' => $xmpp,
'$connect' => $connect, '$follow' => L10n::t('Follow'),
'$remoteconnect' => $remoteconnect, '$follow_link' => $follow_link,
'$subscribe_feed' => $subscribe_feed, '$unfollow' => L10n::t('Unfollow'),
'$wallmessage' => $wallmessage, '$unfollow_link' => $unfollow_link,
'$subscribe_feed' => L10n::t('Atom feed'),
'$subscribe_feed_link' => $subscribe_feed_link,
'$wallmessage' => L10n::t('Message'),
'$wallmessage_link' => $wallmessage_link, '$wallmessage_link' => $wallmessage_link,
'$account_type' => $account_type, '$account_type' => $account_type,
'$location' => $location, '$location' => $location,
@ -996,10 +975,7 @@ class Profile
*/ */
public static function getMyURL() public static function getMyURL()
{ {
if (!empty($_SESSION['my_url'])) { return Session::get('my_url');
return $_SESSION['my_url'];
}
return null;
} }
/** /**

View File

@ -944,10 +944,6 @@ class Contact extends BaseModule
$profiledata = Model\Contact::getDetailsByURL($contact['url']); $profiledata = Model\Contact::getDetailsByURL($contact['url']);
if (local_user() && in_array($profiledata['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
$profiledata['remoteconnect'] = System::baseUrl() . '/follow?url=' . urlencode($profiledata['url']);
}
Model\Profile::load($a, '', 0, $profiledata, true); Model\Profile::load($a, '', 0, $profiledata, true);
$o .= Model\Contact::getPostsFromUrl($contact['url'], true, $update); $o .= Model\Contact::getPostsFromUrl($contact['url'], true, $update);
} }

View File

@ -53,18 +53,17 @@
<div id="profile-extra-links"> <div id="profile-extra-links">
<ul> <ul>
{{if $connect}} {{if $unfollow_link}}
{{if $remoteconnect}} <li><a id="dfrn-request-link" href="{{$unfollow_link}}">{{$unfollow}}</a></li>
<li><a id="dfrn-request-link" href="{{$remoteconnect}}">{{$connect}}</a></li>
{{else}}
<li><a id="dfrn-request-link" href="dfrn_request/{{$profile.nickname}}">{{$connect}}</a></li>
{{/if}} {{/if}}
{{if $follow_link}}
<li><a id="dfrn-request-link" href="{{$follow_link}}">{{$follow}}</a></li>
{{/if}} {{/if}}
{{if $wallmessage}} {{if $wallmessage_link}}
<li><a id="wallmessage-link" href="{{$wallmessage_link}}">{{$wallmessage}}</a></li> <li><a id="wallmessage-link" href="{{$wallmessage_link}}">{{$wallmessage}}</a></li>
{{/if}} {{/if}}
{{if $subscribe_feed}} {{if $subscribe_feed_link}}
<li><a id="subscribe-feed-link" href="dfrn_poll/{{$profile.nickname}}">{{$subscribe_feed}}</a></li> <li><a id="subscribe-feed-link" href="{{$subscribe_feed_link}}">{{$subscribe_feed}}</a></li>
{{/if}} {{/if}}
</ul> </ul>
</div> </div>

View File

@ -39,18 +39,17 @@
<div id="profile-vcard-break"></div> <div id="profile-vcard-break"></div>
<div id="profile-extra-links"> <div id="profile-extra-links">
<ul> <ul>
{{if $connect}} {{if $unfollow_link}}
{{if $remoteconnect}} <li><a id="dfrn-request-link" href="{{$unfollow_link}}">{{$unfollow}}</a></li>
<li><a id="dfrn-request-link" href="{{$remoteconnect}}">{{$connect}}</a></li>
{{else}}
<li><a id="dfrn-request-link" href="dfrn_request/{{$profile.nickname}}">{{$connect}}</a></li>
{{/if}} {{/if}}
{{if $follow_link}}
<li><a id="dfrn-request-link" href="{{$follow_link}}">{{$follow}}</a></li>
{{/if}} {{/if}}
{{if $wallmessage}} {{if $wallmessage_link}}
<li><a id="wallmessage-link" href="{{$wallmessage_link}}">{{$wallmessage}}</a></li> <li><a id="wallmessage-link" href="{{$wallmessage_link}}">{{$wallmessage}}</a></li>
{{/if}} {{/if}}
{{if $subscribe_feed}} {{if $subscribe_feed_link}}
<li><a id="subscribe-feed-link" href="dfrn_poll/{{$profile.nickname}}">{{$subscribe_feed}}</a></li> <li><a id="subscribe-feed-link" href="{{$subscribe_feed_link}}">{{$subscribe_feed}}</a></li>
{{/if}} {{/if}}
</ul> </ul>
</div> </div>

View File

@ -46,23 +46,24 @@
{{if $account_type}}<div class="account-type">({{$account_type}})</div>{{/if}} {{if $account_type}}<div class="account-type">({{$account_type}})</div>{{/if}}
</div> </div>
{{if $follow_link || $unfollow_link || $wallmessage_link}}
<div id="profile-extra-links"> <div id="profile-extra-links">
{{if $connect}} {{if $follow_link || $unfollow_link}}
<div id="dfrn-request-link-button"> <div id="dfrn-request-link-button">
{{if $remoteconnect}} {{if $unfollow_link}}
<a id="dfrn-request-link" class="btn btn-primary btn-sm" href="{{$remoteconnect}}"> <a id="dfrn-request-link" class="btn btn-labeled btn-primary btn-sm" href="{{$unfollow_link}}">
<span class=""><i class="fa fa-user-plus"></i></span> <span class=""><i class="fa fa-user-times"></i></span>
<span class="">{{$connect}}</span> <span class="">{{$unfollow}}</span>
</a> </a>
{{else}} {{else}}
<a id="dfrn-request-link" class="btn btn-labeled btn-primary btn-sm" href="dfrn_request/{{$profile.nickname}}"> <a id="dfrn-request-link" class="btn btn-labeled btn-primary btn-sm" href="{{$follow_link}}">
<span class=""><i class="fa fa-user-plus"></i></span> <span class=""><i class="fa fa-user-plus"></i></span>
<span class="">{{$connect}}</span> <span class="">{{$follow}}</span>
</a> </a>
{{/if}} {{/if}}
</div> </div>
{{/if}} {{/if}}
{{if $wallmessage}} {{if $wallmessage_link}}
<div id="wallmessage-link-botton"> <div id="wallmessage-link-botton">
<button type="button" id="wallmessage-link" class="btn btn-labeled btn-primary btn-sm" onclick="openWallMessage('{{$wallmessage_link}}')"> <button type="button" id="wallmessage-link" class="btn btn-labeled btn-primary btn-sm" onclick="openWallMessage('{{$wallmessage_link}}')">
<span class=""><i class="fa fa-envelope"></i></span> <span class=""><i class="fa fa-envelope"></i></span>
@ -71,6 +72,7 @@
</div> </div>
{{/if}} {{/if}}
</div> </div>
{{/if}}
<div class="clear"></div> <div class="clear"></div>

View File

@ -72,18 +72,17 @@
<div id="profile-extra-links"> <div id="profile-extra-links">
<ul> <ul>
{{if $connect}} {{if $unfollow_link}}
{{if $remoteconnect}} <li><a id="dfrn-request-link" href="{{$unfollow_link}}">{{$unfollow}}</a></li>
<li><a id="dfrn-request-link" href="{{$remoteconnect}}">{{$connect}}</a></li>
{{else}}
<li><a id="dfrn-request-link" href="dfrn_request/{{$profile.nickname}}">{{$connect}}</a></li>
{{/if}} {{/if}}
{{if $follow_link}}
<li><a id="dfrn-request-link" href="{{$follow_link}}">{{$follow}}</a></li>
{{/if}} {{/if}}
{{if $wallmessage}} {{if $wallmessage_link}}
<li><a id="wallmessage-link" href="{{$wallmessage_link}}">{{$wallmessage}}</a></li> <li><a id="wallmessage-link" href="{{$wallmessage_link}}">{{$wallmessage}}</a></li>
{{/if}} {{/if}}
{{if $subscribe_feed}} {{if $subscribe_feed_link}}
<li><a id="subscribe-feed-link" href="dfrn_poll/{{$profile.nickname}}">{{$subscribe_feed}}</a></li> <li><a id="subscribe-feed-link" href="{{$subscribe_feed_link}}">{{$subscribe_feed}}</a></li>
{{/if}} {{/if}}
</ul> </ul>
</div> </div>

View File

@ -64,18 +64,17 @@
<div id="profile-extra-links"> <div id="profile-extra-links">
<ul> <ul>
{{if $connect}} {{if $unfollow_link}}
{{if $remoteconnect}} <li><a id="dfrn-request-link" href="{{$unfollow_link}}">{{$unfollow}}</a></li>
<li><a id="dfrn-request-link" href="{{$remoteconnect}}">{{$connect}}</a></li>
{{else}}
<li><a id="dfrn-request-link" href="dfrn_request/{{$profile.nickname}}">{{$connect}}</a></li>
{{/if}} {{/if}}
{{if $follow_link}}
<li><a id="dfrn-request-link" href="{{$follow_link}}">{{$follow}}</a></li>
{{/if}} {{/if}}
{{if $wallmessage}} {{if $wallmessage_link}}
<li><a id="wallmessage-link" href="{{$wallmessage_link}}">{{$wallmessage}}</a></li> <li><a id="wallmessage-link" href="{{$wallmessage_link}}">{{$wallmessage}}</a></li>
{{/if}} {{/if}}
{{if $subscribe_feed}} {{if $subscribe_feed_link}}
<li><a id="subscribe-feed-link" href="dfrn_poll/{{$profile.nickname}}">{{$subscribe_feed}}</a></li> <li><a id="subscribe-feed-link" href="{{$subscribe_feed_link}}">{{$subscribe_feed}}</a></li>
{{/if}} {{/if}}
</ul> </ul>
</div> </div>