Merge pull request #8175 from MrPetovan/task/revert-profile-default-tab

Revert profile base URL behavior
This commit is contained in:
Philipp 2020-01-26 20:33:27 +01:00 committed by GitHub
commit 9269221825
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 467 additions and 413 deletions

View File

@ -791,7 +791,7 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ
/**
* Fetch all comments from a query. Additionally set the newest resharer as thread owner.
*
* @param array $thread_items Database statement with thread posts
* @param mixed $thread_items Database statement with thread posts
* @param boolean $pinned Is the item pinned?
*
* @return array items with parents and comments

View File

@ -19,6 +19,7 @@ use Friendica\Model\Contact;
use Friendica\Model\Event;
use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Module\BaseProfile;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Temporal;
@ -121,7 +122,7 @@ function cal_content(App $a)
$sql_extra = " AND `event`.`cid` = 0 " . $sql_perms;
// get the tab navigation bar
$tabs = Profile::getTabs($a, 'cal', false, $a->data['user']['nickname']);
$tabs = BaseProfile::getTabsHTML($a, 'cal', false, $a->data['user']['nickname']);
// The view mode part is similiar to /mod/events.php
if ($mode == 'view') {

View File

@ -16,8 +16,8 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Event;
use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Module\BaseProfile;
use Friendica\Module\Security\Login;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
@ -251,7 +251,7 @@ function events_content(App $a)
$tabs = '';
// tabs
if ($a->theme_events_in_profile) {
$tabs = Profile::getTabs($a, 'events', true);
$tabs = BaseProfile::getTabsHTML($a, 'events', true);
}
$mode = 'view';

View File

@ -9,7 +9,7 @@ use Friendica\Content\Pager;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Module\BaseProfile;
function notes_init(App $a)
{
@ -28,7 +28,7 @@ function notes_content(App $a, $update = false)
return;
}
$o = Profile::getTabs($a, 'notes', true);
$o = BaseProfile::getTabsHTML($a, 'notes', true);
if (!$update) {
$o .= '<h3>' . DI::l10n()->t('Personal Notes') . '</h3>';

View File

@ -21,6 +21,7 @@ use Friendica\Model\Item;
use Friendica\Model\Photo;
use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Module\BaseProfile;
use Friendica\Network\Probe;
use Friendica\Object\Image;
use Friendica\Protocol\Activity;
@ -914,7 +915,7 @@ function photos_content(App $a)
// tabs
$is_owner = (local_user() && (local_user() == $owner_uid));
$o .= Profile::getTabs($a, 'photos', $is_owner, $a->data['user']['nickname']);
$o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $a->data['user']['nickname']);
// Display upload form
if ($datatype === 'upload') {

View File

@ -15,6 +15,7 @@ use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Module\BaseProfile;
use Friendica\Util\Security;
function videos_init(App $a)
@ -171,7 +172,7 @@ function videos_content(App $a)
// tabs
$_is_owner = (local_user() && (local_user() == $owner_uid));
$o .= Profile::getTabs($a, 'videos', $_is_owner, $a->data['user']['nickname']);
$o .= BaseProfile::getTabsHTML($a, 'videos', $_is_owner, $a->data['user']['nickname']);
//
// dispatch request

View File

@ -675,121 +675,6 @@ class Profile
]);
}
/**
* @param App $a
* @param string $current
* @param bool $is_owner
* @param string $nickname
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function getTabs(App $a, string $current, bool $is_owner, string $nickname = null)
{
if (is_null($nickname)) {
$nickname = $a->user['nickname'];
}
$baseProfileUrl = DI::baseUrl() . '/profile/' . $nickname;
$tabs = [
[
'label' => DI::l10n()->t('Profile'),
'url' => $baseProfileUrl,
'sel' => $current == 'profile' ? 'active' : '',
'title' => DI::l10n()->t('Profile Details'),
'id' => 'profile-tab',
'accesskey' => 'r',
],
[
'label' => DI::l10n()->t('Status'),
'url' => $baseProfileUrl . '/status',
'sel' => $current == 'status' ? 'active' : '',
'title' => DI::l10n()->t('Status Messages and Posts'),
'id' => 'status-tab',
'accesskey' => 'm',
],
[
'label' => DI::l10n()->t('Photos'),
'url' => DI::baseUrl() . '/photos/' . $nickname,
'sel' => $current == 'photos' ? 'active' : '',
'title' => DI::l10n()->t('Photo Albums'),
'id' => 'photo-tab',
'accesskey' => 'h',
],
[
'label' => DI::l10n()->t('Videos'),
'url' => DI::baseUrl() . '/videos/' . $nickname,
'sel' => $current == 'videos' ? 'active' : '',
'title' => DI::l10n()->t('Videos'),
'id' => 'video-tab',
'accesskey' => 'v',
],
];
// the calendar link for the full featured events calendar
if ($is_owner && $a->theme_events_in_profile) {
$tabs[] = [
'label' => DI::l10n()->t('Events'),
'url' => DI::baseUrl() . '/events',
'sel' => $current == 'events' ? 'active' : '',
'title' => DI::l10n()->t('Events and Calendar'),
'id' => 'events-tab',
'accesskey' => 'e',
];
// if the user is not the owner of the calendar we only show a calendar
// with the public events of the calendar owner
} elseif (!$is_owner) {
$tabs[] = [
'label' => DI::l10n()->t('Events'),
'url' => DI::baseUrl() . '/cal/' . $nickname,
'sel' => $current == 'cal' ? 'active' : '',
'title' => DI::l10n()->t('Events and Calendar'),
'id' => 'events-tab',
'accesskey' => 'e',
];
}
if ($is_owner) {
$tabs[] = [
'label' => DI::l10n()->t('Personal Notes'),
'url' => DI::baseUrl() . '/notes',
'sel' => $current == 'notes' ? 'active' : '',
'title' => DI::l10n()->t('Only You Can See This'),
'id' => 'notes-tab',
'accesskey' => 't',
];
}
if (empty($a->profile['hide-friends'])) {
$tabs[] = [
'label' => DI::l10n()->t('Contacts'),
'url' => $baseProfileUrl . '/contacts',
'sel' => $current == 'contacts' ? 'active' : '',
'title' => DI::l10n()->t('Contacts'),
'id' => 'viewcontacts-tab',
'accesskey' => 'k',
];
}
if (!empty($_SESSION['new_member']) && $is_owner) {
$tabs[] = [
'label' => DI::l10n()->t('Tips for New Members'),
'url' => DI::baseUrl() . '/newmember',
'sel' => false,
'title' => DI::l10n()->t('Tips for New Members'),
'id' => 'newmember-tab',
];
}
$arr = ['is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => $current, 'tabs' => $tabs];
Hook::callAll('profile_tabs', $arr);
$tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
return Renderer::replaceMacros($tpl, ['$tabs' => $arr['tabs']]);
}
/**
* Retrieves the my_url session variable
*

129
src/Module/BaseProfile.php Normal file
View File

@ -0,0 +1,129 @@
<?php
namespace Friendica\Module;
use Friendica\App;
use Friendica\BaseModule;
use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\DI;
class BaseProfile extends BaseModule
{
/**
* Returns the HTML for the profile pages tabs
*
* @param App $a
* @param string $current
* @param bool $is_owner
* @param string $nickname
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function getTabsHTML(App $a, string $current, bool $is_owner, string $nickname = null)
{
if (is_null($nickname)) {
$nickname = $a->user['nickname'];
}
$baseProfileUrl = DI::baseUrl() . '/profile/' . $nickname;
$tabs = [
[
'label' => DI::l10n()->t('Profile'),
'url' => $baseProfileUrl . '/profile',
'sel' => $current == 'profile' ? 'active' : '',
'title' => DI::l10n()->t('Profile Details'),
'id' => 'profile-tab',
'accesskey' => 'r',
],
[
'label' => DI::l10n()->t('Status'),
'url' => $baseProfileUrl . '/status',
'sel' => $current == 'status' ? 'active' : '',
'title' => DI::l10n()->t('Status Messages and Posts'),
'id' => 'status-tab',
'accesskey' => 'm',
],
[
'label' => DI::l10n()->t('Photos'),
'url' => DI::baseUrl() . '/photos/' . $nickname,
'sel' => $current == 'photos' ? 'active' : '',
'title' => DI::l10n()->t('Photo Albums'),
'id' => 'photo-tab',
'accesskey' => 'h',
],
[
'label' => DI::l10n()->t('Videos'),
'url' => DI::baseUrl() . '/videos/' . $nickname,
'sel' => $current == 'videos' ? 'active' : '',
'title' => DI::l10n()->t('Videos'),
'id' => 'video-tab',
'accesskey' => 'v',
],
];
// the calendar link for the full featured events calendar
if ($is_owner && $a->theme_events_in_profile) {
$tabs[] = [
'label' => DI::l10n()->t('Events'),
'url' => DI::baseUrl() . '/events',
'sel' => $current == 'events' ? 'active' : '',
'title' => DI::l10n()->t('Events and Calendar'),
'id' => 'events-tab',
'accesskey' => 'e',
];
// if the user is not the owner of the calendar we only show a calendar
// with the public events of the calendar owner
} elseif (!$is_owner) {
$tabs[] = [
'label' => DI::l10n()->t('Events'),
'url' => DI::baseUrl() . '/cal/' . $nickname,
'sel' => $current == 'cal' ? 'active' : '',
'title' => DI::l10n()->t('Events and Calendar'),
'id' => 'events-tab',
'accesskey' => 'e',
];
}
if ($is_owner) {
$tabs[] = [
'label' => DI::l10n()->t('Personal Notes'),
'url' => DI::baseUrl() . '/notes',
'sel' => $current == 'notes' ? 'active' : '',
'title' => DI::l10n()->t('Only You Can See This'),
'id' => 'notes-tab',
'accesskey' => 't',
];
}
if (empty($a->profile['hide-friends'])) {
$tabs[] = [
'label' => DI::l10n()->t('Contacts'),
'url' => $baseProfileUrl . '/contacts',
'sel' => $current == 'contacts' ? 'active' : '',
'title' => DI::l10n()->t('Contacts'),
'id' => 'viewcontacts-tab',
'accesskey' => 'k',
];
}
if (DI::session()->get('new_member') && $is_owner) {
$tabs[] = [
'label' => DI::l10n()->t('Tips for New Members'),
'url' => DI::baseUrl() . '/newmember',
'sel' => false,
'title' => DI::l10n()->t('Tips for New Members'),
'id' => 'newmember-tab',
];
}
$arr = ['is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => $current, 'tabs' => $tabs];
Hook::callAll('profile_tabs', $arr);
$tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
return Renderer::replaceMacros($tpl, ['$tabs' => $arr['tabs']]);
}
}

View File

@ -2,7 +2,6 @@
namespace Friendica\Module\Profile;
use Friendica\BaseModule;
use Friendica\Content\ContactSelector;
use Friendica\Content\Nav;
use Friendica\Content\Pager;
@ -13,9 +12,10 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Module\BaseProfile;
use Friendica\Util\Proxy as ProxyUtils;
class Contacts extends BaseModule
class Contacts extends BaseProfile
{
public static function content(array $parameters = [])
{
@ -42,8 +42,7 @@ class Contacts extends BaseModule
$is_owner = $a->profile['uid'] == local_user();
// tabs
$o = Profile::getTabs($a, 'contacts', $is_owner, $nickname);
$o = self::getTabsHTML($a, 'contacts', $is_owner, $nickname);
if (!count($a->profile) || $a->profile['hide-friends']) {
notice(DI::l10n()->t('Permission denied.') . EOL);

View File

@ -3,295 +3,25 @@
namespace Friendica\Module\Profile;
use Friendica\BaseModule;
use Friendica\Content\Feature;
use Friendica\Content\ForumManager;
use Friendica\Content\Nav;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Core\Hook;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Model\Term;
use Friendica\Model\User;
use Friendica\Module\Security\Login;
use Friendica\Network\HTTPException;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Temporal;
/**
* Profile index router
*
* The default profile path (https://domain.tld/profile/nickname) has to serve the profile data when queried as an
* ActivityPub endpoint, but it should show statuses to web users.
*
* Both these view have dedicated sub-paths,
* respectively https://domain.tld/profile/nickname/profile and https://domain.tld/profile/nickname/status
*/
class Index extends BaseModule
{
public static function rawContent(array $parameters = [])
{
if (ActivityPub::isRequest()) {
$user = DBA::selectFirst('user', ['uid'], ['nickname' => $parameters['nickname']]);
if (DBA::isResult($user)) {
// The function returns an empty array when the account is removed, expired or blocked
$data = ActivityPub\Transmitter::getProfile($user['uid']);
if (!empty($data)) {
System::jsonExit($data, 'application/activity+json');
}
}
if (DBA::exists('userd', ['username' => $parameters['nickname']])) {
// Known deleted user
$data = ActivityPub\Transmitter::getDeletedUser($parameters['nickname']);
System::jsonError(410, $data);
} else {
// Any other case (unknown, blocked, nverified, expired, no profile, no self contact)
System::jsonError(404, []);
}
}
Profile::rawContent($parameters);
}
public static function content(array $parameters = [])
{
$a = DI::app();
Profile::load($a, $parameters['nickname']);
if (!$a->profile) {
throw new HTTPException\NotFoundException(DI::l10n()->t('Profile not found.'));
}
$remote_contact_id = Session::getRemoteContactID($a->profile_uid);
if (DI::config()->get('system', 'block_public') && !local_user() && !$remote_contact_id) {
return Login::form();
}
$is_owner = local_user() == $a->profile_uid;
if (!empty($a->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) {
DI::page()['htmlhead'] .= '<meta name="friendica.community" content="true" />' . "\n";
}
DI::page()['htmlhead'] .= self::buildHtmlHead($a->profile, $parameters['nickname'], $remote_contact_id);
Nav::setSelected('home');
$is_owner = local_user() == $a->profile['uid'];
$o = Profile::getTabs($a, 'profile', $is_owner, $a->profile['nickname']);
if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact_id) {
notice(DI::l10n()->t('Access to this profile has been restricted.'));
return '';
}
$view_as_contacts = [];
$view_as_contact_id = 0;
if ($is_owner) {
$view_as_contact_id = intval($_GET['viewas'] ?? 0);
$view_as_contacts = Contact::selectToArray(['id', 'name'], [
'uid' => local_user(),
'rel' => [Contact::FOLLOWER, Contact::SHARING, Contact::FRIEND],
'network' => Protocol::DFRN,
'blocked' => false,
]);
// User manually provided a contact ID they aren't privy to, silently defaulting to their own view
if (!in_array($view_as_contact_id, array_column($view_as_contacts, 'id'))) {
$view_as_contact_id = 0;
}
}
$basic_fields = [];
$basic_fields += self::buildField('fullname', DI::l10n()->t('Full Name:'), $a->profile['name']);
if (Feature::isEnabled($a->profile_uid, 'profile_membersince')) {
$basic_fields += self::buildField(
'membersince',
DI::l10n()->t('Member since:'),
DateTimeFormat::local($a->profile['register_date'])
);
}
if (!empty($a->profile['dob']) && $a->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)
);
$basic_fields += self::buildField('dob', DI::l10n()->t('Birthday:'), $dob);
if ($age = Temporal::getAgeByTimezone($a->profile['dob'], $a->profile['timezone'])) {
$basic_fields += self::buildField('age', DI::l10n()->t('Age: '), DI::l10n()->tt('%d year old', '%d years old', $age));
}
}
if ($a->profile['pdesc']) {
$basic_fields += self::buildField('pdesc', DI::l10n()->t('Description:'), HTML::toLink($a->profile['pdesc']));
}
if ($a->profile['xmpp']) {
$basic_fields += self::buildField('xmpp', DI::l10n()->t('XMPP:'), $a->profile['xmpp']);
}
if ($a->profile['homepage']) {
$basic_fields += self::buildField('homepage', DI::l10n()->t('Homepage:'), HTML::toLink($a->profile['homepage']));
}
if (
$a->profile['address']
|| $a->profile['locality']
|| $a->profile['postal-code']
|| $a->profile['region']
|| $a->profile['country-name']
) {
$basic_fields += self::buildField('location', DI::l10n()->t('Location:'), Profile::formatLocation($a->profile));
}
if ($a->profile['pub_keywords']) {
$tags = [];
foreach (explode(',', $a->profile['pub_keywords']) as $tag_label) {
$tags[] = [
'url' => '/search?tag=' . $tag_label,
'label' => Term::TAG_CHARACTER[Term::HASHTAG] . $tag_label,
];
}
$basic_fields += self::buildField('pub_keywords', DI::l10n()->t('Tags:'), $tags);
}
$custom_fields = [];
// Defaults to the current logged in user self contact id to show self-only fields
$contact_id = $view_as_contact_id ?: $remote_contact_id ?: 0;
if ($is_owner && $contact_id === 0) {
$profile_fields = DI::profileField()->selectByUserId($a->profile_uid);
} else {
$profile_fields = DI::profileField()->selectByContactId($contact_id, $a->profile_uid);
}
foreach ($profile_fields as $profile_field) {
$custom_fields += self::buildField(
'custom_' . $profile_field->order,
$profile_field->label,
BBCode::convert($profile_field->value),
'aprofile custom'
);
};
//show subcribed forum if it is enabled in the usersettings
if (Feature::isEnabled($a->profile_uid, 'forumlist_profile')) {
$custom_fields += self::buildField(
'forumlist',
DI::l10n()->t('Forums:'),
ForumManager::profileAdvanced($a->profile_uid)
);
}
$tpl = Renderer::getMarkupTemplate('profile/index.tpl');
$o .= Renderer::replaceMacros($tpl, [
'$title' => DI::l10n()->t('Profile'),
'$view_as_contacts' => $view_as_contacts,
'$view_as_contact_id' => $view_as_contact_id,
'$view_as' => DI::l10n()->t('View profile as:'),
'$basic' => DI::l10n()->t('Basic'),
'$advanced' => DI::l10n()->t('Advanced'),
'$is_owner' => $a->profile_uid == local_user(),
'$query_string' => DI::args()->getQueryString(),
'$basic_fields' => $basic_fields,
'$custom_fields' => $custom_fields,
'$profile' => $a->profile,
'$edit_link' => [
'url' => DI::baseUrl() . '/settings/profile', DI::l10n()->t('Edit profile'),
'title' => '',
'label' => DI::l10n()->t('Edit profile')
],
]);
Hook::callAll('profile_advanced', $o);
return $o;
}
/**
* Creates a profile field structure to be used in the profile template
*
* @param string $name Arbitrary name of the field
* @param string $label Display label of the field
* @param mixed $value Display value of the field
* @param string $class Optional CSS class to apply to the field
* @return array
*/
private static function buildField(string $name, string $label, $value, string $class = 'aprofile')
{
return [$name => [
'id' => 'aprofile-' . $name,
'class' => $class,
'label' => $label,
'value' => $value,
]];
}
private static function buildHtmlHead(array $profile, string $nickname, int $remote_contact_id)
{
$baseUrl = DI::baseUrl();
$htmlhead = "\n";
if (!empty($profile['page-flags']) && $profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY) {
$htmlhead .= '<meta name="friendica.community" content="true" />' . "\n";
}
if (!empty($profile['openidserver'])) {
$htmlhead .= '<link rel="openid.server" href="' . $profile['openidserver'] . '" />' . "\n";
}
if (!empty($profile['openid'])) {
$delegate = strstr($profile['openid'], '://') ? $profile['openid'] : 'https://' . $profile['openid'];
$htmlhead .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\n";
}
// site block
$blocked = !local_user() && !$remote_contact_id && DI::config()->get('system', 'block_public');
$userblock = !local_user() && !$remote_contact_id && $profile['hidewall'];
if (!$blocked && !$userblock) {
$keywords = str_replace(['#', ',', ' ', ',,'], ['', ' ', ',', ','], $profile['pub_keywords'] ?? '');
if (strlen($keywords)) {
$htmlhead .= '<meta name="keywords" content="' . $keywords . '" />' . "\n";
}
}
$htmlhead .= '<meta name="dfrn-global-visibility" content="' . ($profile['net-publish'] ? 'true' : 'false') . '" />' . "\n";
if (!$profile['net-publish'] || $profile['hidewall']) {
$htmlhead .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
}
$htmlhead .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl . '/dfrn_poll/' . $nickname . '" title="DFRN: ' . DI::l10n()->t('%s\'s timeline', $profile['username']) . '"/>' . "\n";
$htmlhead .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl . '/feed/' . $nickname . '/" title="' . DI::l10n()->t('%s\'s posts', $profile['username']) . '"/>' . "\n";
$htmlhead .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl . '/feed/' . $nickname . '/comments" title="' . DI::l10n()->t('%s\'s comments', $profile['username']) . '"/>' . "\n";
$htmlhead .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl . '/feed/' . $nickname . '/activity" title="' . DI::l10n()->t('%s\'s timeline', $profile['username']) . '"/>' . "\n";
$uri = urlencode('acct:' . $profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : ''));
$htmlhead .= '<link rel="lrdd" type="application/xrd+xml" href="' . $baseUrl . '/xrd/?uri=' . $uri . '" />' . "\n";
header('Link: <' . $baseUrl . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
$dfrn_pages = ['request', 'confirm', 'notify', 'poll'];
foreach ($dfrn_pages as $dfrn) {
$htmlhead .= '<link rel="dfrn-' . $dfrn . '" href="' . $baseUrl . '/dfrn_' . $dfrn . '/' . $nickname . '" />' . "\n";
}
$htmlhead .= '<link rel="dfrn-poco" href="' . $baseUrl . '/poco/' . $nickname . '" />' . "\n";
return $htmlhead;
return Status::content($parameters);
}
}

View File

@ -0,0 +1,297 @@
<?php
namespace Friendica\Module\Profile;
use Friendica\Content\Feature;
use Friendica\Content\ForumManager;
use Friendica\Content\Nav;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Core\Hook;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Profile as ProfileModel;
use Friendica\Model\Term;
use Friendica\Model\User;
use Friendica\Module\BaseProfile;
use Friendica\Module\Security\Login;
use Friendica\Network\HTTPException;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Temporal;
class Profile extends BaseProfile
{
public static function rawContent(array $parameters = [])
{
if (ActivityPub::isRequest()) {
$user = DBA::selectFirst('user', ['uid'], ['nickname' => $parameters['nickname']]);
if (DBA::isResult($user)) {
// The function returns an empty array when the account is removed, expired or blocked
$data = ActivityPub\Transmitter::getProfile($user['uid']);
if (!empty($data)) {
System::jsonExit($data, 'application/activity+json');
}
}
if (DBA::exists('userd', ['username' => $parameters['nickname']])) {
// Known deleted user
$data = ActivityPub\Transmitter::getDeletedUser($parameters['nickname']);
System::jsonError(410, $data);
} else {
// Any other case (unknown, blocked, nverified, expired, no profile, no self contact)
System::jsonError(404, []);
}
}
}
public static function content(array $parameters = [])
{
$a = DI::app();
ProfileModel::load($a, $parameters['nickname']);
if (!$a->profile) {
throw new HTTPException\NotFoundException(DI::l10n()->t('Profile not found.'));
}
$remote_contact_id = Session::getRemoteContactID($a->profile_uid);
if (DI::config()->get('system', 'block_public') && !local_user() && !$remote_contact_id) {
return Login::form();
}
$is_owner = local_user() == $a->profile_uid;
if (!empty($a->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) {
DI::page()['htmlhead'] .= '<meta name="friendica.community" content="true" />' . "\n";
}
DI::page()['htmlhead'] .= self::buildHtmlHead($a->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']);
if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact_id) {
notice(DI::l10n()->t('Access to this profile has been restricted.'));
return '';
}
$view_as_contacts = [];
$view_as_contact_id = 0;
if ($is_owner) {
$view_as_contact_id = intval($_GET['viewas'] ?? 0);
$view_as_contacts = Contact::selectToArray(['id', 'name'], [
'uid' => local_user(),
'rel' => [Contact::FOLLOWER, Contact::SHARING, Contact::FRIEND],
'network' => Protocol::DFRN,
'blocked' => false,
]);
// User manually provided a contact ID they aren't privy to, silently defaulting to their own view
if (!in_array($view_as_contact_id, array_column($view_as_contacts, 'id'))) {
$view_as_contact_id = 0;
}
}
$basic_fields = [];
$basic_fields += self::buildField('fullname', DI::l10n()->t('Full Name:'), $a->profile['name']);
if (Feature::isEnabled($a->profile_uid, 'profile_membersince')) {
$basic_fields += self::buildField(
'membersince',
DI::l10n()->t('Member since:'),
DateTimeFormat::local($a->profile['register_date'])
);
}
if (!empty($a->profile['dob']) && $a->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)
);
$basic_fields += self::buildField('dob', DI::l10n()->t('Birthday:'), $dob);
if ($age = Temporal::getAgeByTimezone($a->profile['dob'], $a->profile['timezone'])) {
$basic_fields += self::buildField('age', DI::l10n()->t('Age: '), DI::l10n()->tt('%d year old', '%d years old', $age));
}
}
if ($a->profile['pdesc']) {
$basic_fields += self::buildField('pdesc', DI::l10n()->t('Description:'), HTML::toLink($a->profile['pdesc']));
}
if ($a->profile['xmpp']) {
$basic_fields += self::buildField('xmpp', DI::l10n()->t('XMPP:'), $a->profile['xmpp']);
}
if ($a->profile['homepage']) {
$basic_fields += self::buildField('homepage', DI::l10n()->t('Homepage:'), HTML::toLink($a->profile['homepage']));
}
if (
$a->profile['address']
|| $a->profile['locality']
|| $a->profile['postal-code']
|| $a->profile['region']
|| $a->profile['country-name']
) {
$basic_fields += self::buildField('location', DI::l10n()->t('Location:'), ProfileModel::formatLocation($a->profile));
}
if ($a->profile['pub_keywords']) {
$tags = [];
foreach (explode(',', $a->profile['pub_keywords']) as $tag_label) {
$tags[] = [
'url' => '/search?tag=' . $tag_label,
'label' => Term::TAG_CHARACTER[Term::HASHTAG] . $tag_label,
];
}
$basic_fields += self::buildField('pub_keywords', DI::l10n()->t('Tags:'), $tags);
}
$custom_fields = [];
// Defaults to the current logged in user self contact id to show self-only fields
$contact_id = $view_as_contact_id ?: $remote_contact_id ?: 0;
if ($is_owner && $contact_id === 0) {
$profile_fields = DI::profileField()->selectByUserId($a->profile_uid);
} else {
$profile_fields = DI::profileField()->selectByContactId($contact_id, $a->profile_uid);
}
foreach ($profile_fields as $profile_field) {
$custom_fields += self::buildField(
'custom_' . $profile_field->order,
$profile_field->label,
BBCode::convert($profile_field->value),
'aprofile custom'
);
};
//show subcribed forum if it is enabled in the usersettings
if (Feature::isEnabled($a->profile_uid, 'forumlist_profile')) {
$custom_fields += self::buildField(
'forumlist',
DI::l10n()->t('Forums:'),
ForumManager::profileAdvanced($a->profile_uid)
);
}
$tpl = Renderer::getMarkupTemplate('profile/index.tpl');
$o .= Renderer::replaceMacros($tpl, [
'$title' => DI::l10n()->t('Profile'),
'$view_as_contacts' => $view_as_contacts,
'$view_as_contact_id' => $view_as_contact_id,
'$view_as' => DI::l10n()->t('View profile as:'),
'$basic' => DI::l10n()->t('Basic'),
'$advanced' => DI::l10n()->t('Advanced'),
'$is_owner' => $a->profile_uid == local_user(),
'$query_string' => DI::args()->getQueryString(),
'$basic_fields' => $basic_fields,
'$custom_fields' => $custom_fields,
'$profile' => $a->profile,
'$edit_link' => [
'url' => DI::baseUrl() . '/settings/profile', DI::l10n()->t('Edit profile'),
'title' => '',
'label' => DI::l10n()->t('Edit profile')
],
]);
Hook::callAll('profile_advanced', $o);
return $o;
}
/**
* Creates a profile field structure to be used in the profile template
*
* @param string $name Arbitrary name of the field
* @param string $label Display label of the field
* @param mixed $value Display value of the field
* @param string $class Optional CSS class to apply to the field
* @return array
*/
private static function buildField(string $name, string $label, $value, string $class = 'aprofile')
{
return [$name => [
'id' => 'aprofile-' . $name,
'class' => $class,
'label' => $label,
'value' => $value,
]];
}
private static function buildHtmlHead(array $profile, string $nickname, int $remote_contact_id)
{
$baseUrl = DI::baseUrl();
$htmlhead = "\n";
if (!empty($profile['page-flags']) && $profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY) {
$htmlhead .= '<meta name="friendica.community" content="true" />' . "\n";
}
if (!empty($profile['openidserver'])) {
$htmlhead .= '<link rel="openid.server" href="' . $profile['openidserver'] . '" />' . "\n";
}
if (!empty($profile['openid'])) {
$delegate = strstr($profile['openid'], '://') ? $profile['openid'] : 'https://' . $profile['openid'];
$htmlhead .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\n";
}
// site block
$blocked = !local_user() && !$remote_contact_id && DI::config()->get('system', 'block_public');
$userblock = !local_user() && !$remote_contact_id && $profile['hidewall'];
if (!$blocked && !$userblock) {
$keywords = str_replace(['#', ',', ' ', ',,'], ['', ' ', ',', ','], $profile['pub_keywords'] ?? '');
if (strlen($keywords)) {
$htmlhead .= '<meta name="keywords" content="' . $keywords . '" />' . "\n";
}
}
$htmlhead .= '<meta name="dfrn-global-visibility" content="' . ($profile['net-publish'] ? 'true' : 'false') . '" />' . "\n";
if (!$profile['net-publish'] || $profile['hidewall']) {
$htmlhead .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
}
$htmlhead .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl . '/dfrn_poll/' . $nickname . '" title="DFRN: ' . DI::l10n()->t('%s\'s timeline', $profile['username']) . '"/>' . "\n";
$htmlhead .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl . '/feed/' . $nickname . '/" title="' . DI::l10n()->t('%s\'s posts', $profile['username']) . '"/>' . "\n";
$htmlhead .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl . '/feed/' . $nickname . '/comments" title="' . DI::l10n()->t('%s\'s comments', $profile['username']) . '"/>' . "\n";
$htmlhead .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl . '/feed/' . $nickname . '/activity" title="' . DI::l10n()->t('%s\'s timeline', $profile['username']) . '"/>' . "\n";
$uri = urlencode('acct:' . $profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : ''));
$htmlhead .= '<link rel="lrdd" type="application/xrd+xml" href="' . $baseUrl . '/xrd/?uri=' . $uri . '" />' . "\n";
header('Link: <' . $baseUrl . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
$dfrn_pages = ['request', 'confirm', 'notify', 'poll'];
foreach ($dfrn_pages as $dfrn) {
$htmlhead .= '<link rel="dfrn-' . $dfrn . '" href="' . $baseUrl . '/dfrn_' . $dfrn . '/' . $nickname . '" />' . "\n";
}
$htmlhead .= '<link rel="dfrn-poco" href="' . $baseUrl . '/poco/' . $nickname . '" />' . "\n";
return $htmlhead;
}
}

View File

@ -2,7 +2,6 @@
namespace Friendica\Module\Profile;
use Friendica\BaseModule;
use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Content\Widget;
@ -13,13 +12,14 @@ use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Profile as ProfileModel;
use Friendica\Model\User;
use Friendica\Module\BaseProfile;
use Friendica\Module\Security\Login;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Security;
use Friendica\Util\Strings;
use Friendica\Util\XML;
class Status extends BaseModule
class Status extends BaseProfile
{
public static function content(array $parameters = [])
{
@ -81,7 +81,7 @@ class Status extends BaseModule
return '';
}
$o .= ProfileModel::getTabs($a, 'status', $is_owner, $a->profile['nickname']);
$o .= self::getTabsHTML($a, 'status', $is_owner, $a->profile['nickname']);
$o .= Widget::commonFriendsVisitor($a->profile['uid']);
@ -206,7 +206,13 @@ class Status extends BaseModule
$items = DBA::toArray($items_stmt);
$o .= conversation($a, $items, $pager, 'profile', false, false, 'received', $a->profile['uid']);
if ($pager->getStart() == 0 && !empty($a->profile['uid'])) {
$pinned_items = Item::selectPinned($a->profile['uid'], ['uri', 'pinned']);
$pinned = Item::inArray($pinned_items);
$items = array_merge($items, $pinned);
}
$o .= conversation($a, $items, $pager, 'profile', false, false, 'pinned_received', $a->profile['uid']);
$o .= $pager->renderMinimal(count($items));

View File

@ -206,6 +206,7 @@ return [
'/profile' => [
'/{nickname}' => [Module\Profile\Index::class, [R::GET]],
'/{nickname}/profile' => [Module\Profile\Profile::class, [R::GET]],
'/{nickname}/contacts[/{type}]' => [Module\Profile\Contacts::class, [R::GET]],
'/{nickname}/status[/{category}[/{date1}[/{date2}]]]' => [Module\Profile\Status::class, [R::GET]],
],

View File

@ -236,7 +236,11 @@ as the value of $top_child_total (this is done at the end of this file)
{{if $item.owner_self}}
{{include file="sub/delivery_count.tpl" delivery=$item.delivery}}
{{/if}}
<span class="pinned">{{$item.pinned}}</span>
{{if $item.pinned}}
&bull; <i class="fa fa-thumb-tack" aria-hidden="true" title="{{$item.pinned}}"></i>
<span class="sr-only">{{$item.pinned}}</span>
{{/if}}
</small>
</div>