Simplified functionality to load the profile in the sidebar

This commit is contained in:
Michael
2021-07-23 12:39:37 +00:00
parent fe8e71216d
commit afe3c8954c
15 changed files with 195 additions and 138 deletions
+99
View File
@@ -0,0 +1,99 @@
<?php
/**
* @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Content\Widget;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Util\Strings;
/**
* VCard widget
*
* @author Michael Vogel
*/
class VCard
{
/**
* Get HTML for vcard block
*
* @template widget/vcard.tpl
* @return string
*/
public static function getHTML(array $contact)
{
if (($contact['network'] != '') && ($contact['network'] != Protocol::DFRN)) {
$network_link = Strings::formatNetworkName($contact['network'], $contact['url']);
} else {
$network_link = '';
}
$follow_link = '';
$unfollow_link = '';
$wallmessage_link = '';
if (local_user()) {
if ($contact['uid']) {
$id = $contact['id'];
$rel = $contact['rel'];
$pending = $contact['pending'];
} else {
$pcontact = Contact::selectFirst(['id', 'rel', 'pending'], ['uid' => local_user(), 'uri-id' => $contact['uri-id']]);
$id = $pcontact['id'] ?? 0;
$rel = $pcontact['rel'] ?? Contact::NOTHING;
$pending = $pcontact['pending'] ?? false;
}
if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
if (in_array($rel, [Contact::SHARING, Contact::FRIEND])) {
$unfollow_link = 'unfollow?url=' . urlencode($contact['url']) . '&auto=1';
} elseif(!$pending) {
$follow_link = 'follow?url=' . urlencode($contact['url']) . '&auto=1';
}
}
if (in_array($rel, [Contact::FOLLOWER, Contact::FRIEND]) && Contact::canReceivePrivateMessages($contact)) {
$wallmessage_link = 'message/new/' . $id;
}
}
return Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/vcard.tpl'), [
'$contact' => $contact,
'$photo' => Contact::getPhoto($contact),
'$url' => Contact::magicLinkByContact($contact, $contact['url']),
'$about' => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['about'] ?? ''),
'$xmpp' => DI::l10n()->t('XMPP:'),
'$location' => DI::l10n()->t('Location:'),
'$network_link' => $network_link,
'$network' => DI::l10n()->t('Network:'),
'$account_type' => Contact::getAccountType($contact),
'$follow' => DI::l10n()->t('Follow'),
'$follow_link' => $follow_link,
'$unfollow' => DI::l10n()->t('Unfollow'),
'$unfollow_link' => $unfollow_link,
'$wallmessage' => DI::l10n()->t('Message'),
'$wallmessage_link' => $wallmessage_link,
]);
}
}
+3 -7
View File
@@ -468,18 +468,14 @@ class Item
// Checking if there is already an item with the same guid
$condition = ['guid' => $item['guid'], 'network' => $item['network'], 'uid' => $item['uid']];
if (Post::exists($condition)) {
Logger::notice('Found already existing item', [
'guid' => $item['guid'],
'uid' => $item['uid'],
'network' => $item['network']
]);
Logger::notice('Found already existing item', $condition);
return true;
}
$condition = ['uri-id' => $item['uri-id'], 'uid' => $item['uid'],
'network' => [$item['network'], Protocol::DFRN]];
if (Post::exists($condition)) {
Logger::notice('duplicated item with the same uri found.', $item);
Logger::notice('duplicated item with the same uri found.', $condition);
return true;
}
@@ -487,7 +483,7 @@ class Item
if (in_array($item['network'], [Protocol::DFRN, Protocol::DIASPORA])) {
$condition = ['guid' => $item['guid'], 'uid' => $item['uid']];
if (Post::exists($condition)) {
Logger::notice('duplicated item with the same guid found.', $item);
Logger::notice('duplicated item with the same guid found.', $condition);
return true;
}
} elseif ($item['network'] == Protocol::OSTATUS) {
+10 -38
View File
@@ -211,38 +211,12 @@ class Profile
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function load(App $a, $nickname, array $profiledata = [], $show_connect = true)
public static function load(App $a, $nickname)
{
$user = DBA::selectFirst('user', ['uid'], ['nickname' => $nickname, 'account_removed' => false]);
if (!DBA::isResult($user) && empty($profiledata)) {
Logger::log('profile error: ' . DI::args()->getQueryString(), Logger::DEBUG);
return;
}
if (count($profiledata) > 0) {
// Ensure to have a "nickname" field
if (empty($profiledata['nickname']) && !empty($profiledata['nick'])) {
$profiledata['nickname'] = $profiledata['nick'];
}
// Add profile data to sidebar
DI::page()['aside'] .= self::sidebar($a, $profiledata, true, $show_connect);
if (!DBA::isResult($user)) {
return;
}
}
$profile = !empty($user['uid']) ? User::getOwnerDataById($user['uid'], false) : [];
if (empty($profile) && empty($profiledata)) {
Logger::log('profile error: ' . DI::args()->getQueryString(), Logger::DEBUG);
return;
}
$profile = User::getOwnerDataByNick($nickname);
if (empty($profile)) {
$profile = ['uid' => 0, 'name' => $nickname];
Logger::log('profile error: ' . DI::args()->getQueryString(), Logger::DEBUG);
return;
}
$a->profile = $profile;
@@ -253,7 +227,7 @@ class Profile
DI::page()['title'] = $a->profile['name'] . ' @ ' . DI::config()->get('config', 'sitename');
if (!$profiledata && !DI::pConfig()->get(local_user(), 'system', 'always_my_theme')) {
if (!DI::pConfig()->get(local_user(), 'system', 'always_my_theme')) {
$a->setCurrentTheme($a->profile['theme']);
$a->setCurrentMobileTheme($a->profile['mobile-theme']);
}
@@ -269,16 +243,14 @@ class Profile
require_once $theme_info_file;
}
$block = ((DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) ? true : false);
$block = (DI::config()->get('system', 'block_public') && !Session::isAuthenticated());
/**
* @todo
* By now, the contact block isn't shown, when a different profile is given
* But: When this profile was on the same server, then we could display the contacts
*/
if (!$profiledata) {
DI::page()['aside'] .= self::sidebar($a, $a->profile, $block, $show_connect);
}
DI::page()['aside'] .= self::sidebar($a, $a->profile, $block);
return;
}
@@ -304,7 +276,7 @@ class Profile
* @hooks 'profile_sidebar'
* array $arr
*/
private static function sidebar(App $a, array $profile, $block = 0, $show_connect = true)
private static function sidebar(App $a, array $profile, $block = 0)
{
$o = '';
$location = false;
@@ -374,7 +346,7 @@ class Profile
|| in_array($profile_contact['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND]);
$visitor_base_path = self::getMyURL() ? preg_replace('=/profile/(.*)=ism', '', self::getMyURL()) : '';
if (!$local_user_is_self && $show_connect) {
if (!$local_user_is_self) {
if (!$visitor_is_authenticated) {
// Remote follow is only available for local profiles
if (!empty($profile['nickname']) && strpos($profile_url, DI::baseUrl()->get()) === 0) {
@@ -495,7 +467,7 @@ class Profile
$p['photo'] = Contact::getAvatarUrlForId($cid, ProxyUtils::SIZE_SMALL);
$p['url'] = Contact::magicLinkById($cid);
$p['url'] = Contact::magicLinkById($cid, $profile['url']);
$tpl = Renderer::getMarkupTemplate('profile/vcard.tpl');
$o .= Renderer::replaceMacros($tpl, [
+10 -47
View File
@@ -308,42 +308,7 @@ class Contact extends BaseModule
$a->data['contact'] = $contact;
if (($contact['network'] != '') && ($contact['network'] != Protocol::DFRN)) {
$network_link = Strings::formatNetworkName($contact['network'], $contact['url']);
} else {
$network_link = '';
}
$follow_link = '';
$unfollow_link = '';
if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
if ($contact['uid'] && in_array($contact['rel'], [Model\Contact::SHARING, Model\Contact::FRIEND])) {
$unfollow_link = 'unfollow?url=' . urlencode($contact['url']) . '&auto=1';
} elseif(!$contact['pending']) {
$follow_link = 'follow?url=' . urlencode($contact['url']) . '&auto=1';
}
}
$wallmessage_link = '';
if ($contact['uid'] && Model\Contact::canReceivePrivateMessages($contact)) {
$wallmessage_link = 'message/new/' . $contact['id'];
}
$vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/vcard.tpl'), [
'$name' => $contact['name'],
'$photo' => Model\Contact::getPhoto($contact),
'$url' => Model\Contact::magicLinkByContact($contact, $contact['url']),
'$addr' => $contact['addr'] ?? '',
'$network_link' => $network_link,
'$network' => DI::l10n()->t('Network:'),
'$account_type' => Model\Contact::getAccountType($contact),
'$follow' => DI::l10n()->t('Follow'),
'$follow_link' => $follow_link,
'$unfollow' => DI::l10n()->t('Unfollow'),
'$unfollow_link' => $unfollow_link,
'$wallmessage' => DI::l10n()->t('Message'),
'$wallmessage_link' => $wallmessage_link,
]);
$vcard_widget = Widget\VCard::getHTML($contact);
$findpeople_widget = '';
$follow_widget = '';
@@ -578,14 +543,14 @@ class Contact extends BaseModule
Model\Contact::MIRROR_FORWARDED => DI::l10n()->t('Mirror as forwarded posting'),
Model\Contact::MIRROR_OWN_POST => DI::l10n()->t('Mirror as my own posting')];
} elseif (in_array($contact['network'], [Protocol::ACTIVITYPUB])) {
$remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
$remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
Model\Contact::MIRROR_NATIVE_RESHARE => DI::l10n()->t('Native reshare')];
} elseif (in_array($contact['network'], [Protocol::DFRN])) {
$remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
$remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
Model\Contact::MIRROR_OWN_POST => DI::l10n()->t('Mirror as my own posting'),
Model\Contact::MIRROR_NATIVE_RESHARE => DI::l10n()->t('Native reshare')];
} else {
$remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
$remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
Model\Contact::MIRROR_OWN_POST => DI::l10n()->t('Mirror as my own posting')];
}
@@ -669,7 +634,7 @@ class Contact extends BaseModule
$contact['remote_self'],
DI::l10n()->t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'),
$remote_self_options
],
],
]);
$arr = ['contact' => $contact, 'output' => $o];
@@ -1002,11 +967,11 @@ class Contact extends BaseModule
}
if (DBA::isResult($contact)) {
DI::page()['aside'] = '';
if (!$update) {
$profiledata = Model\Contact::getByURLForUser($contact['url'], local_user());
Model\Profile::load($a, '', $profiledata, true);
DI::page()['aside'] = Widget\VCard::getHTML($profiledata);
} else {
DI::page()['aside'] = '';
}
if ($contact['uid'] == 0) {
@@ -1026,15 +991,13 @@ class Contact extends BaseModule
$o = self::getTabsHTML($contact, self::TAB_POSTS);
if (DBA::isResult($contact)) {
DI::page()['aside'] = '';
$profiledata = Model\Contact::getByURLForUser($contact['url'], local_user());
if (local_user() && in_array($profiledata['network'], Protocol::FEDERATED)) {
$profiledata['remoteconnect'] = DI::baseUrl() . '/follow?url=' . urlencode($profiledata['url']);
}
Model\Profile::load($a, '', $profiledata, true);
DI::page()['aside'] = Widget\VCard::getHTML($profiledata);
if ($contact['uid'] == 0) {
$o .= Model\Contact::getPostsFromId($contact['id']);
@@ -1115,7 +1078,7 @@ class Contact extends BaseModule
'alt_text' => $alt_text,
'name' => $contact['name'],
'nick' => $contact['nick'],
'details' => $contact['location'],
'details' => $contact['location'],
'tags' => $contact['keywords'],
'about' => $contact['about'],
'account_type' => Model\Contact::getAccountType($contact),
+2 -1
View File
@@ -22,6 +22,7 @@
namespace Friendica\Module\Contact;
use Friendica\BaseModule;
use Friendica\Content\Widget;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
@@ -104,7 +105,7 @@ class Advanced extends BaseModule
throw new BadRequestException(DI::l10n()->t('Contact not found.'));
}
Model\Profile::load(DI::app(), "", Model\Contact::getByURL($contact["url"], false));
DI::page()['aside'] = Widget\VCard::getHTML($contact);
$warning = DI::l10n()->t('<strong>WARNING: This is highly advanced</strong> and if you enter incorrect information your communications with this contact may stop working.');
$info = DI::l10n()->t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
+1 -1
View File
@@ -38,7 +38,7 @@ class Contacts extends BaseModule
$localContactId = Model\Contact::getPublicIdByUserId(local_user());
Model\Profile::load($app, '', $contact);
DI::page()['aside'] = Widget\VCard::getHTML($contact);
$condition = [
'blocked' => false,
+2 -1
View File
@@ -3,6 +3,7 @@
namespace Friendica\Module\Contact;
use Friendica\BaseModule;
use Friendica\Content\Widget;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
@@ -135,7 +136,7 @@ class Poke extends BaseModule
throw new HTTPException\NotFoundException();
}
Model\Profile::load(DI::app(), '', Model\Contact::getByURL($contact["url"], false));
DI::page()['aside'] = Widget\VCard::getHTML(Model\Contact::getByURL($contact["url"], false));
$verbs = [];
foreach (DI::l10n()->getPokeVerbs() as $verb => $translations) {
+2 -2
View File
@@ -878,8 +878,8 @@ class Feed
Protocol::OSTATUS, Protocol::DFRN, Protocol::DIASPORA];
if ($filter === 'comments') {
$condition[0] .= " AND `object-type` = ? ";
$condition[] = Activity\ObjectType::COMMENT;
$condition[0] .= " AND `gravity` = ? ";
$condition[] = GRAVITY_COMMENT;
}
if ($owner['account-type'] != User::ACCOUNT_TYPE_COMMUNITY) {
+3 -3
View File
@@ -55,9 +55,9 @@ class UpdateContacts
$ids = self::getContactsToUpdate($condition, [], $limit);
Logger::info('Fetched federated user contacts', ['count' => count($ids)]);
$conditions = ["`id` IN (SELECT `author-id` FROM `post-user` WHERE `author-id` = `contact`.`id`)",
"`id` IN (SELECT `owner-id` FROM `post-user` WHERE `owner-id` = `contact`.`id`)",
"`id` IN (SELECT `causer-id` FROM `post-user` WHERE `causer-id` = `contact`.`id`)",
$conditions = ["`id` IN (SELECT `author-id` FROM `post` WHERE `author-id` = `contact`.`id`)",
"`id` IN (SELECT `owner-id` FROM `post` WHERE `owner-id` = `contact`.`id`)",
"`id` IN (SELECT `causer-id` FROM `post` WHERE `causer-id` = `contact`.`id`)",
"`id` IN (SELECT `cid` FROM `post-tag` WHERE `cid` = `contact`.`id`)",
"`id` IN (SELECT `cid` FROM `user-contact` WHERE `cid` = `contact`.`id`)"];