Merge pull request #10543 from annando/app-variables

App variables reduced and removed
This commit is contained in:
Hypolite Petovan 2021-07-25 08:56:05 -04:00 committed by GitHub
commit 69c75daf4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 532 additions and 552 deletions

View file

@ -39,11 +39,9 @@ class BaseProfile extends BaseModule
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function getTabsHTML(App $a, string $current, bool $is_owner, string $nickname = null)
public static function getTabsHTML(App $a, string $current, bool $is_owner, array $profile)
{
if (is_null($nickname)) {
$nickname = $a->user['nickname'];
}
$nickname = $profile['nickname'];
$baseProfileUrl = DI::baseUrl() . '/profile/' . $nickname;
@ -116,7 +114,7 @@ class BaseProfile extends BaseModule
];
}
if (empty($a->profile['hide-friends'])) {
if (empty($profile['hide-friends'])) {
$tabs[] = [
'label' => DI::l10n()->t('Contacts'),
'url' => $baseProfileUrl . '/contacts',

View file

@ -156,12 +156,6 @@ class Contact extends BaseModule
if (!DBA::isResult($r)) {
notice(DI::l10n()->t('Failed to update contact record.'));
}
$contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
if (DBA::isResult($contact)) {
$a->data['contact'] = $contact;
}
return;
}
@ -306,8 +300,6 @@ class Contact extends BaseModule
}
}
$a->data['contact'] = $contact;
$vcard_widget = Widget\VCard::getHTML($contact);
$findpeople_widget = '';
@ -453,9 +445,7 @@ class Contact extends BaseModule
$_SESSION['return_path'] = DI::args()->getQueryString();
if (!empty($a->data['contact']) && is_array($a->data['contact'])) {
$contact = $a->data['contact'];
if (!empty($contact)) {
DI::page()['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('contact_head.tpl'), [
'$baseurl' => DI::baseUrl()->get(true),
]);

View file

@ -11,6 +11,7 @@ use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model;
use Friendica\Model\Contact;
use Friendica\Network\HTTPException;
use Friendica\Protocol\Activity;
use Friendica\Util\XML;
@ -59,7 +60,7 @@ class Poke extends BaseModule
$deny_cid = ($private ? '' : $a->user['deny_cid']);
$deny_gid = ($private ? '' : $a->user['deny_gid']);
$actor = $a->contact;
$actor = Contact::getById($a->getContactId());
$uri = Model\Item::newURI($uid);

View file

@ -29,6 +29,8 @@ use Friendica\Util\Temporal;
class Localtime extends BaseModule
{
static $mod_localtime = '';
public static function post(array $parameters = [])
{
$time = ($_REQUEST['time'] ?? '') ?: 'now';
@ -36,14 +38,12 @@ class Localtime extends BaseModule
$bd_format = DI::l10n()->t('l F d, Y \@ g:i A');
if (!empty($_POST['timezone'])) {
DI::app()->data['mod-localtime'] = DateTimeFormat::convert($time, $_POST['timezone'], 'UTC', $bd_format);
self::$mod_localtime = DateTimeFormat::convert($time, $_POST['timezone'], 'UTC', $bd_format);
}
}
public static function content(array $parameters = [])
{
$app = DI::app();
$time = ($_REQUEST['time'] ?? '') ?: 'now';
$output = '<h3>' . DI::l10n()->t('Time Conversion') . '</h3>';
@ -54,8 +54,8 @@ class Localtime extends BaseModule
$output .= '<p>' . DI::l10n()->t('Current timezone: %s', $_REQUEST['timezone']) . '</p>';
}
if (!empty($app->data['mod-localtime'])) {
$output .= '<p>' . DI::l10n()->t('Converted localtime: %s', $app->data['mod-localtime']) . '</p>';
if (!empty(self::$mod_localtime)) {
$output .= '<p>' . DI::l10n()->t('Converted localtime: %s', self::$mod_localtime) . '</p>';
}
$output .= '<form action ="' . DI::baseUrl()->get() . '/localtime?time=' . $time . '" method="post" >';

View file

@ -118,7 +118,7 @@ class Delegation extends BaseModule
throw new ForbiddenException(DI::l10n()->t('Permission denied.'));
}
$identities = DI::app()->identities;
$identities = User::identities(DI::session()->get('submanage', local_user()));
//getting additinal information for each identity
foreach ($identities as $key => $identity) {

View file

@ -48,28 +48,28 @@ class HCard extends BaseModule
throw new HTTPException\NotFoundException(DI::l10n()->t('No profile'));
}
Profile::load($a, $nickname);
$profile = Profile::load($a, $nickname, false);
if (empty($a->profile)) {
if (empty($profile)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
}
$page = DI::page();
if (!empty($a->profile['page-flags']) && ($a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY)) {
if (!empty($profile['page-flags']) && ($profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY)) {
$page['htmlhead'] .= '<meta name="friendica.community" content="true" />';
}
if (!empty($a->profile['openidserver'])) {
$page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\r\n";
if (!empty($profile['openidserver'])) {
$page['htmlhead'] .= '<link rel="openid.server" href="' . $profile['openidserver'] . '" />' . "\r\n";
}
if (!empty($a->profile['openid'])) {
$delegate = ((strstr($a->profile['openid'], '://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']);
if (!empty($profile['openid'])) {
$delegate = ((strstr($profile['openid'], '://')) ? $profile['openid'] : 'http://' . $profile['openid']);
$page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
}
// check if blocked
if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
$keywords = $a->profile['pub_keywords'] ?? '';
$keywords = $profile['pub_keywords'] ?? '';
$keywords = str_replace([',', ' ', ',,'], [' ', ',', ','], $keywords);
if (strlen($keywords)) {
$page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n";
@ -78,9 +78,9 @@ class HCard extends BaseModule
$baseUrl = DI::baseUrl();
$uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : ''));
$uri = urlencode('acct:' . $profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : ''));
$page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . ($a->profile['net-publish'] ? 'true' : 'false') . '" />' . "\r\n";
$page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . ($profile['net-publish'] ? 'true' : 'false') . '" />' . "\r\n";
$page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl->get() . '/dfrn_poll/' . $nickname . '" />' . "\r\n";
$page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . $baseUrl->get() . '/xrd/?uri=' . $uri . '" />' . "\r\n";
header('Link: <' . $baseUrl->get() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);

View file

@ -28,6 +28,7 @@ use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\Core\Theme;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\User;
use Friendica\Module\Security\Login;
@ -86,7 +87,7 @@ class Compose extends BaseModule
$compose_title = DI::l10n()->t('Compose new personal note');
$type = 'note';
$doesFederate = false;
$contact_allow_list = [$a->contact['id']];
$contact_allow_list = [$a->getContactId()];
$group_allow_list = [];
$contact_deny_list = [];
$group_deny_list = [];
@ -129,6 +130,8 @@ class Compose extends BaseModule
DI::page()->registerFooterScript(Theme::getPathForFile('js/linkPreview.js'));
DI::page()->registerFooterScript(Theme::getPathForFile('js/compose.js'));
$contact = Contact::getById($a->getContactId());
$tpl = Renderer::getMarkupTemplate('item/compose.tpl');
return Renderer::replaceMacros($tpl, [
'$compose_title'=> $compose_title,
@ -138,9 +141,9 @@ class Compose extends BaseModule
'$type' => $type,
'$wall' => $wall,
'$default' => '',
'$mylink' => DI::baseUrl()->remove($a->contact['url']),
'$mylink' => DI::baseUrl()->remove($contact['url']),
'$mytitle' => DI::l10n()->t('This is you'),
'$myphoto' => DI::baseUrl()->remove($a->contact['thumb']),
'$myphoto' => DI::baseUrl()->remove($contact['thumb']),
'$submit' => DI::l10n()->t('Submit'),
'$edbold' => DI::l10n()->t('Bold'),
'$editalic' => DI::l10n()->t('Italic'),
@ -171,7 +174,6 @@ class Compose extends BaseModule
'$group_deny' => implode(',', $group_deny_list),
'$jotplugins' => $jotplugins,
'$sourceapp' => DI::l10n()->t($a->sourcename),
'$rand_num' => Crypto::randomDigits(12),
'$acl_selector' => ACL::getFullSelectorHTML(DI::page(), $a->user, $doesFederate, [
'allow_cid' => $contact_allow_list,

View file

@ -65,7 +65,7 @@ class Magic extends BaseModule
$contact = DBA::selectFirst('contact', ['id', 'nurl', 'url'], ['id' => $cid]);
// Redirect if the contact is already authenticated on this site.
if (!empty($a->contact) && array_key_exists('id', $a->contact) && strpos($contact['nurl'], Strings::normaliseLink(DI::baseUrl()->get())) !== false) {
if ($a->getContactId() && strpos($contact['nurl'], Strings::normaliseLink(DI::baseUrl()->get())) !== false) {
if ($test) {
$ret['success'] = true;
$ret['message'] .= 'Local site - you are already authenticated.' . EOL;

View file

@ -47,28 +47,27 @@ class Common extends BaseProfile
$nickname = $parameters['nickname'];
Profile::load($a, $nickname);
if (empty($a->profile)) {
$profile = Profile::load($a, $nickname);
if (empty($profile)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
}
if (!empty($a->profile['hide-friends'])) {
if (!empty($profile['hide-friends'])) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
$displayCommonTab = Session::isAuthenticated() && $a->profile['uid'] != local_user();
$displayCommonTab = Session::isAuthenticated() && $profile['uid'] != local_user();
if (!$displayCommonTab) {
$a->redirect('profile/' . $nickname . '/contacts');
};
$o = self::getTabsHTML($a, 'contacts', false, $nickname);
$o = self::getTabsHTML($a, 'contacts', false, $profile);
$tabs = self::getContactFilterTabs('profile/' . $nickname, 'common', $displayCommonTab);
$sourceId = Contact::getIdForURL(Profile::getMyURL());
$targetId = Contact::getPublicIdByUserId($a->profile['uid']);
$targetId = Contact::getPublicIdByUserId($profile['uid']);
$condition = [
'blocked' => false,
@ -87,7 +86,7 @@ class Common extends BaseProfile
$title = DI::l10n()->tt('Common contact (%s)', 'Common contacts (%s)', $total);
$desc = DI::l10n()->t(
'Both <strong>%s</strong> and yourself have publicly interacted with these contacts (follow, comment or likes on public posts).',
htmlentities($a->profile['name'], ENT_COMPAT, 'UTF-8')
htmlentities($profile['name'], ENT_COMPAT, 'UTF-8')
);
$tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');

View file

@ -23,6 +23,7 @@ namespace Friendica\Module\Profile;
use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Content\Widget;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
@ -45,26 +46,25 @@ class Contacts extends Module\BaseProfile
$nickname = $parameters['nickname'];
$type = $parameters['type'] ?? 'all';
Model\Profile::load($a, $nickname);
if (empty($a->profile)) {
$profile = Model\Profile::load($a, $nickname);
if (empty($profile)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
}
$is_owner = $a->profile['uid'] == local_user();
$is_owner = $profile['uid'] == local_user();
if (!empty($a->profile['hide-friends']) && !$is_owner) {
if (!empty($profile['hide-friends']) && !$is_owner) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
Nav::setSelected('home');
$o = self::getTabsHTML($a, 'contacts', $is_owner, $nickname);
$o = self::getTabsHTML($a, 'contacts', $is_owner, $profile);
$tabs = self::getContactFilterTabs('profile/' . $nickname, $type, Session::isAuthenticated() && $a->profile['uid'] != local_user());
$tabs = self::getContactFilterTabs('profile/' . $nickname, $type, Session::isAuthenticated() && $profile['uid'] != local_user());
$condition = [
'uid' => $a->profile['uid'],
'uid' => $profile['uid'],
'blocked' => false,
'pending' => false,
'hidden' => false,
@ -103,7 +103,7 @@ class Contacts extends Module\BaseProfile
$title = DI::l10n()->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total);
$desc = DI::l10n()->t(
'These contacts both follow and are followed by <strong>%s</strong>.',
htmlentities($a->profile['name'], ENT_COMPAT, 'UTF-8')
htmlentities($profile['name'], ENT_COMPAT, 'UTF-8')
);
break;
case 'all':

View file

@ -26,6 +26,7 @@ use Friendica\Content\ForumManager;
use Friendica\Content\Nav;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Content\Widget;
use Friendica\Core\Hook;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
@ -76,36 +77,35 @@ class Profile extends BaseProfile
{
$a = DI::app();
ProfileModel::load($a, $parameters['nickname']);
if (!$a->profile) {
$profile = ProfileModel::load($a, $parameters['nickname']);
if (!$profile) {
throw new HTTPException\NotFoundException(DI::l10n()->t('Profile not found.'));
}
$remote_contact_id = Session::getRemoteContactID($a->profile_uid);
$remote_contact_id = Session::getRemoteContactID($profile['uid']);
if (DI::config()->get('system', 'block_public') && !local_user() && !$remote_contact_id) {
return Login::form();
}
$is_owner = local_user() == $a->profile_uid;
$is_owner = local_user() == $profile['uid'];
if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact_id) {
if (!empty($profile['hidewall']) && !$is_owner && !$remote_contact_id) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Access to this profile has been restricted.'));
}
if (!empty($a->profile['page-flags']) && $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY) {
if (!empty($profile['page-flags']) && $profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY) {
DI::page()['htmlhead'] .= '<meta name="friendica.community" content="true" />' . "\n";
}
DI::page()['htmlhead'] .= self::buildHtmlHead($a->profile, $parameters['nickname'], $remote_contact_id);
DI::page()['htmlhead'] .= self::buildHtmlHead($profile, $parameters['nickname'], $remote_contact_id);
Nav::setSelected('home');
$is_owner = local_user() == $a->profile['uid'];
$o = self::getTabsHTML($a, 'profile', $is_owner, $a->profile['nickname']);
$is_owner = local_user() == $profile['uid'];
$o = self::getTabsHTML($a, 'profile', $is_owner, $profile);
if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact_id) {
if (!empty($profile['hidewall']) && !$is_owner && !$remote_contact_id) {
notice(DI::l10n()->t('Access to this profile has been restricted.'));
return '';
}
@ -141,59 +141,59 @@ class Profile extends BaseProfile
$basic_fields = [];
$basic_fields += self::buildField('fullname', DI::l10n()->t('Full Name:'), $a->profile['name']);
$basic_fields += self::buildField('fullname', DI::l10n()->t('Full Name:'), $profile['name']);
if (Feature::isEnabled($a->profile_uid, 'profile_membersince')) {
if (Feature::isEnabled($profile['uid'], 'profile_membersince')) {
$basic_fields += self::buildField(
'membersince',
DI::l10n()->t('Member since:'),
DateTimeFormat::local($a->profile['register_date'])
DateTimeFormat::local($profile['register_date'])
);
}
if (!empty($a->profile['dob']) && $a->profile['dob'] > DBA::NULL_DATE) {
if (!empty($profile['dob']) && $profile['dob'] > DBA::NULL_DATE) {
$year_bd_format = DI::l10n()->t('j F, Y');
$short_bd_format = DI::l10n()->t('j F');
$dob = DI::l10n()->getDay(
intval($a->profile['dob']) ?
DateTimeFormat::utc($a->profile['dob'] . ' 00:00 +00:00', $year_bd_format)
: DateTimeFormat::utc('2001-' . substr($a->profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format)
intval($profile['dob']) ?
DateTimeFormat::utc($profile['dob'] . ' 00:00 +00:00', $year_bd_format)
: DateTimeFormat::utc('2001-' . substr($profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format)
);
$basic_fields += self::buildField('dob', DI::l10n()->t('Birthday:'), $dob);
if ($age = Temporal::getAgeByTimezone($a->profile['dob'], $a->profile['timezone'])) {
if ($age = Temporal::getAgeByTimezone($profile['dob'], $profile['timezone'])) {
$basic_fields += self::buildField('age', DI::l10n()->t('Age: '), DI::l10n()->tt('%d year old', '%d years old', $age));
}
}
if ($a->profile['about']) {
$basic_fields += self::buildField('about', DI::l10n()->t('Description:'), BBCode::convertForUriId($a->profile['uri-id'], $a->profile['about']));
if ($profile['about']) {
$basic_fields += self::buildField('about', DI::l10n()->t('Description:'), BBCode::convertForUriId($profile['uri-id'], $profile['about']));
}
if ($a->profile['xmpp']) {
$basic_fields += self::buildField('xmpp', DI::l10n()->t('XMPP:'), $a->profile['xmpp']);
if ($profile['xmpp']) {
$basic_fields += self::buildField('xmpp', DI::l10n()->t('XMPP:'), $profile['xmpp']);
}
if ($a->profile['homepage']) {
$basic_fields += self::buildField('homepage', DI::l10n()->t('Homepage:'), HTML::toLink($a->profile['homepage']));
if ($profile['homepage']) {
$basic_fields += self::buildField('homepage', DI::l10n()->t('Homepage:'), HTML::toLink($profile['homepage']));
}
if (
$a->profile['address']
|| $a->profile['locality']
|| $a->profile['postal-code']
|| $a->profile['region']
|| $a->profile['country-name']
$profile['address']
|| $profile['locality']
|| $profile['postal-code']
|| $profile['region']
|| $profile['country-name']
) {
$basic_fields += self::buildField('location', DI::l10n()->t('Location:'), ProfileModel::formatLocation($a->profile));
$basic_fields += self::buildField('location', DI::l10n()->t('Location:'), ProfileModel::formatLocation($profile));
}
if ($a->profile['pub_keywords']) {
if ($profile['pub_keywords']) {
$tags = [];
// Separator is defined in Module\Settings\Profile\Index::cleanKeywords
foreach (explode(', ', $a->profile['pub_keywords']) as $tag_label) {
foreach (explode(', ', $profile['pub_keywords']) as $tag_label) {
$tags[] = [
'url' => '/search?tag=' . $tag_label,
'label' => Tag::TAG_CHARACTER[Tag::HASHTAG] . $tag_label,
@ -209,26 +209,26 @@ class Profile extends BaseProfile
$contact_id = $view_as_contact_id ?: $remote_contact_id ?: 0;
if ($is_owner && $contact_id === 0) {
$profile_fields = DI::profileField()->selectByUserId($a->profile_uid);
$profile_fields = DI::profileField()->selectByUserId($profile['uid']);
} else {
$profile_fields = DI::profileField()->selectByContactId($contact_id, $a->profile_uid);
$profile_fields = DI::profileField()->selectByContactId($contact_id, $profile['uid']);
}
foreach ($profile_fields as $profile_field) {
$custom_fields += self::buildField(
'custom_' . $profile_field->order,
$profile_field->label,
BBCode::convertForUriId($a->profile['uri-id'], $profile_field->value),
BBCode::convertForUriId($profile['uri-id'], $profile_field->value),
'aprofile custom'
);
};
//show subcribed forum if it is enabled in the usersettings
if (Feature::isEnabled($a->profile_uid, 'forumlist_profile')) {
if (Feature::isEnabled($profile['uid'], 'forumlist_profile')) {
$custom_fields += self::buildField(
'forumlist',
DI::l10n()->t('Forums:'),
ForumManager::profileAdvanced($a->profile_uid)
ForumManager::profileAdvanced($profile['uid'])
);
}
@ -243,11 +243,11 @@ class Profile extends BaseProfile
'$submit' => DI::l10n()->t('Submit'),
'$basic' => DI::l10n()->t('Basic'),
'$advanced' => DI::l10n()->t('Advanced'),
'$is_owner' => $a->profile_uid == local_user(),
'$is_owner' => $profile['uid'] == local_user(),
'$query_string' => DI::args()->getQueryString(),
'$basic_fields' => $basic_fields,
'$custom_fields' => $custom_fields,
'$profile' => $a->profile,
'$profile' => $profile,
'$edit_link' => [
'url' => DI::baseUrl() . '/settings/profile', DI::l10n()->t('Edit profile'),
'title' => '',

View file

@ -52,20 +52,20 @@ class Status extends BaseProfile
$a = DI::app();
ProfileModel::load($a, $parameters['nickname']);
$profile = ProfileModel::load($a, $parameters['nickname']);
if (empty($a->profile)) {
if (empty($profile)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
}
if (!$a->profile['net-publish']) {
if (!$profile['net-publish']) {
DI::page()['htmlhead'] .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
}
DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/dfrn_poll/' . $parameters['nickname'] . '" title="DFRN: ' . DI::l10n()->t('%s\'s timeline', $a->profile['name']) . '"/>' . "\n";
DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/" title="' . DI::l10n()->t('%s\'s posts', $a->profile['name']) . '"/>' . "\n";
DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/comments" title="' . DI::l10n()->t('%s\'s comments', $a->profile['name']) . '"/>' . "\n";
DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/activity" title="' . DI::l10n()->t('%s\'s timeline', $a->profile['name']) . '"/>' . "\n";
DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/dfrn_poll/' . $parameters['nickname'] . '" title="DFRN: ' . DI::l10n()->t('%s\'s timeline', $profile['name']) . '"/>' . "\n";
DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/" title="' . DI::l10n()->t('%s\'s posts', $profile['name']) . '"/>' . "\n";
DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/comments" title="' . DI::l10n()->t('%s\'s comments', $profile['name']) . '"/>' . "\n";
DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/activity" title="' . DI::l10n()->t('%s\'s timeline', $profile['name']) . '"/>' . "\n";
$category = $datequery = $datequery2 = '';
@ -91,42 +91,42 @@ class Status extends BaseProfile
$hashtags = $_GET['tag'] ?? '';
if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($a->profile['uid'])) {
if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($profile['uid'])) {
return Login::form();
}
$o = '';
if ($a->profile['uid'] == local_user()) {
if ($profile['uid'] == local_user()) {
Nav::setSelected('home');
}
$remote_contact = Session::getRemoteContactID($a->profile['uid']);
$is_owner = local_user() == $a->profile['uid'];
$last_updated_key = "profile:" . $a->profile['uid'] . ":" . local_user() . ":" . $remote_contact;
$remote_contact = Session::getRemoteContactID($profile['uid']);
$is_owner = local_user() == $profile['uid'];
$last_updated_key = "profile:" . $profile['uid'] . ":" . local_user() . ":" . $remote_contact;
if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact) {
if (!empty($profile['hidewall']) && !$is_owner && !$remote_contact) {
notice(DI::l10n()->t('Access to this profile has been restricted.'));
return '';
}
$o .= self::getTabsHTML($a, 'status', $is_owner, $a->profile['nickname']);
$o .= self::getTabsHTML($a, 'status', $is_owner, $profile);
$o .= Widget::commonFriendsVisitor($a->profile['uid'], $a->profile['nickname']);
$o .= Widget::commonFriendsVisitor($profile['uid'], $profile['nickname']);
$commpage = $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
$commpage = $profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
$commvisitor = $commpage && $remote_contact;
DI::page()['aside'] .= Widget::postedByYear(DI::baseUrl() . '/profile/' . $a->profile['nickname'] . '/status', $a->profile['profile_uid'] ?? 0, true);
DI::page()['aside'] .= Widget::categories(DI::baseUrl() . '/profile/' . $a->profile['nickname'] . '/status', XML::escape($category));
DI::page()['aside'] .= Widget::tagCloud();
DI::page()['aside'] .= Widget::postedByYear(DI::baseUrl() . '/profile/' . $profile['nickname'] . '/status', $profile['profile_uid'] ?? 0, true);
DI::page()['aside'] .= Widget::categories(DI::baseUrl() . '/profile/' . $profile['nickname'] . '/status', XML::escape($category));
DI::page()['aside'] .= Widget::tagCloud($profile['uid']);
if (Security::canWriteToUserWall($a->profile['uid'])) {
if (Security::canWriteToUserWall($profile['uid'])) {
$x = [
'is_owner' => $is_owner,
'allow_location' => ($is_owner || $commvisitor) && $a->profile['allow_location'],
'allow_location' => ($is_owner || $commvisitor) && $profile['allow_location'],
'default_location' => $is_owner ? $a->user['default-location'] : '',
'nickname' => $a->profile['nickname'],
'nickname' => $profile['nickname'],
'lockstate' => is_array($a->user)
&& (strlen($a->user['allow_cid'])
|| strlen($a->user['allow_gid'])
@ -136,25 +136,25 @@ class Status extends BaseProfile
'acl' => $is_owner ? ACL::getFullSelectorHTML(DI::page(), $a->user, true) : '',
'bang' => '',
'visitor' => $is_owner || $commvisitor ? 'block' : 'none',
'profile_uid' => $a->profile['uid'],
'profile_uid' => $profile['uid'],
];
$o .= status_editor($a, $x);
}
// Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
$condition = Item::getPermissionsConditionArrayByUserId($a->profile['uid']);
$condition = Item::getPermissionsConditionArrayByUserId($profile['uid']);
$last_updated_array = Session::get('last_updated', []);
if (!empty($category)) {
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `category-view` WHERE `name` = ? AND `type` = ? AND `uid` = ?)",
$category, Category::CATEGORY, $a->profile['uid']]);
$category, Category::CATEGORY, $profile['uid']]);
}
if (!empty($hashtags)) {
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `tag-search-view` WHERE `name` = ? AND `uid` = ?)",
$hashtags, $a->profile['uid']]);
$hashtags, $profile['uid']]);
}
if (!empty($datequery)) {
@ -166,9 +166,9 @@ class Status extends BaseProfile
// Does the profile page belong to a forum?
// If not then we can improve the performance with an additional condition
$condition2 = ['uid' => $a->profile['uid'], 'page-flags' => [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP]];
$condition2 = ['uid' => $profile['uid'], 'page-flags' => [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP]];
if (!DBA::exists('user', $condition2)) {
$condition = DBA::mergeConditions($condition, ['contact-id' => $a->profile['id']]);
$condition = DBA::mergeConditions($condition, ['contact-id' => $profile['id']]);
}
if (DI::mode()->isMobile()) {
@ -186,7 +186,7 @@ class Status extends BaseProfile
GRAVITY_PARENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), GRAVITY_PARENT,
Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::OSTATUS]);
$condition = DBA::mergeConditions($condition, ['uid' => $a->profile['uid'], 'network' => Protocol::FEDERATED,
$condition = DBA::mergeConditions($condition, ['uid' => $profile['uid'], 'network' => Protocol::FEDERATED,
'visible' => true, 'deleted' => false]);
$pager = new Pager(DI::l10n(), $args->getQueryString(), $itemspage_network);
@ -213,25 +213,25 @@ class Status extends BaseProfile
$items = Post::toArray($items_stmt);
if ($pager->getStart() == 0 && !empty($a->profile['uid'])) {
if ($pager->getStart() == 0 && !empty($profile['uid'])) {
$condition = ['private' => [Item::PUBLIC, Item::UNLISTED]];
$remote_user = Session::getRemoteContactID($a->profile['uid']);
$remote_user = Session::getRemoteContactID($profile['uid']);
if (!empty($remote_user)) {
$permissionSets = DI::permissionSet()->selectByContactId($remote_user, $a->profile['uid']);
$permissionSets = DI::permissionSet()->selectByContactId($remote_user, $profile['uid']);
if (!empty($permissionSets)) {
$condition = ['psid' => array_merge($permissionSets->column('id'),
[DI::permissionSet()->getIdFromACL($a->profile['uid'], '', '', '', '')])];
[DI::permissionSet()->getIdFromACL($profile['uid'], '', '', '', '')])];
}
} elseif ($a->profile['uid'] == local_user()) {
} elseif ($profile['uid'] == local_user()) {
$condition = [];
}
$pinned_items = Post::selectPinned($a->profile['uid'], ['uri-id', 'pinned'], $condition);
$pinned_items = Post::selectPinned($profile['uid'], ['uri-id', 'pinned'], $condition);
$pinned = Post::toArray($pinned_items);
$items = array_merge($items, $pinned);
}
$o .= conversation($a, $items, 'profile', false, false, 'pinned_received', $a->profile['uid']);
$o .= conversation($a, $items, 'profile', false, false, 'pinned_received', $profile['uid']);
$o .= $pager->renderMinimal(count($items));

View file

@ -22,6 +22,7 @@
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Content\Widget;
use Friendica\DI;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
@ -30,6 +31,7 @@ use Friendica\Core\Search;
use Friendica\Core\System;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Network\Probe;
/**
@ -37,20 +39,22 @@ use Friendica\Network\Probe;
*/
class RemoteFollow extends BaseModule
{
static $owner;
public static function init(array $parameters = [])
{
Profile::load(DI::app(), $parameters['profile']);
self::$owner = User::getOwnerDataByNick($parameters['profile']);
DI::page()['aside'] = Widget\VCard::getHTML(self::$owner);
}
public static function post(array $parameters = [])
{
$a = DI::app();
if (!empty($_POST['cancel']) || empty($_POST['dfrn_url'])) {
DI::baseUrl()->redirect();
}
if (empty($a->profile['uid'])) {
if (empty(self::$owner)) {
notice(DI::l10n()->t('Profile unavailable.'));
return;
}
@ -73,15 +77,15 @@ class RemoteFollow extends BaseModule
return;
}
Logger::notice('Remote request', ['url' => $url, 'follow' => $a->profile['url'], 'remote' => $data['subscribe']]);
Logger::notice('Remote request', ['url' => $url, 'follow' => self::$owner['url'], 'remote' => $data['subscribe']]);
// Substitute our user's feed URL into $data['subscribe']
// Send the subscriber home to subscribe
// Diaspora needs the uri in the format user@domain.tld
if ($data['network'] == Protocol::DIASPORA) {
$uri = urlencode($a->profile['addr']);
$uri = urlencode(self::$owner['addr']);
} else {
$uri = urlencode($a->profile['url']);
$uri = urlencode(self::$owner['url']);
}
$follow_link = str_replace('{uri}', $uri, $data['subscribe']);
@ -90,14 +94,12 @@ class RemoteFollow extends BaseModule
public static function content(array $parameters = [])
{
$a = DI::app();
if (empty($a->profile)) {
if (empty(self::$owner)) {
return '';
}
$target_addr = $a->profile['addr'];
$target_url = $a->profile['url'];
$target_addr = self::$owner['addr'];
$target_url = self::$owner['url'];
$tpl = Renderer::getMarkupTemplate('auto_request.tpl');
$o = Renderer::replaceMacros($tpl, [
@ -110,7 +112,7 @@ class RemoteFollow extends BaseModule
'$cancel' => DI::l10n()->t('Cancel'),
'$request' => 'remote_follow/' . $parameters['profile'],
'$name' => $a->profile['name'],
'$name' => self::$owner['name'],
'$myaddr' => Profile::getMyURL(),
]);
return $o;

View file

@ -29,6 +29,7 @@ use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\Profile as ProfileModel;
use Friendica\Model\User;
use Friendica\Network\HTTPException\ForbiddenException;
use Friendica\Util\DateTimeFormat;
@ -38,21 +39,22 @@ class Profile extends BaseModule
{
$a = DI::app();
if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($a->profile['uid'])) {
// Ensure we've got a profile owner if updating.
$a->setProfileOwner($_GET['p'] ?? 0);
if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($a->getProfileOwner())) {
throw new ForbiddenException();
}
$profile_uid = intval($_GET['p'] ?? 0);
$remote_contact = Session::getRemoteContactID($a->getProfileOwner());
$is_owner = local_user() == $a->getProfileOwner();
$last_updated_key = "profile:" . $a->getProfileOwner() . ":" . local_user() . ":" . $remote_contact;
// Ensure we've got a profile owner if updating.
$a->profile['uid'] = $profile_uid;
$remote_contact = Session::getRemoteContactID($a->profile['uid']);
$is_owner = local_user() == $a->profile['uid'];
$last_updated_key = "profile:" . $a->profile['uid'] . ":" . local_user() . ":" . $remote_contact;
if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact) {
throw new ForbiddenException(DI::l10n()->t('Access to this profile has been restricted.'));
if (!$is_owner && !$remote_contact) {
$user = User::getById($a->getProfileOwner(), ['hidewall']);
if ($user['hidewall']) {
throw new ForbiddenException(DI::l10n()->t('Access to this profile has been restricted.'));
}
}
$o = '';
@ -62,7 +64,7 @@ class Profile extends BaseModule
}
// Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
$sql_extra = Item::getPermissionsSQLByUserId($a->profile['uid']);
$sql_extra = Item::getPermissionsSQLByUserId($a->getProfileOwner());
$last_updated_array = Session::get('last_updated', []);
@ -86,7 +88,7 @@ class Profile extends BaseModule
AND `visible` AND (NOT `deleted` OR `gravity` = ?)
AND `wall` $sql_extra4 $sql_extra
GROUP BY `parent-uri-id` ORDER BY `received` DESC",
$a->profile['uid'],
$a->getProfileOwner(),
GRAVITY_ACTIVITY
);
@ -99,7 +101,7 @@ class Profile extends BaseModule
$last_updated_array[$last_updated_key] = time();
Session::set('last_updated', $last_updated_array);
if ($is_owner && !$profile_uid && !DI::config()->get('theme', 'hide_eventlist')) {
if ($is_owner && !$a->getProfileOwner() && !DI::config()->get('theme', 'hide_eventlist')) {
$o .= ProfileModel::getBirthdays();
$o .= ProfileModel::getEventsReminderHTML();
}
@ -113,7 +115,7 @@ class Profile extends BaseModule
$items = DBA::toArray($items_stmt);
$o .= conversation($a, $items, 'profile', $profile_uid, false, 'received', $a->profile['uid']);
$o .= conversation($a, $items, 'profile', $a->getProfileOwner(), false, 'received', $a->getProfileOwner());
System::htmlUpdateExit($o);
}