Remove direct calls to App->user

This commit is contained in:
Michael 2021-08-08 10:14:56 +00:00
commit fc283ab928
51 changed files with 238 additions and 166 deletions

View file

@ -36,6 +36,7 @@ use Friendica\Core\Theme;
use Friendica\Database\Database;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
use Friendica\Network\HTTPException;
use Friendica\Util\ConfigFileLoader;
@ -66,6 +67,8 @@ class App
'events_in_profile' => true
];
private $user_id = 0;
private $nickname = '';
private $timezone = '';
private $profile_owner = 0;
private $contact_id = 0;
@ -126,6 +129,65 @@ class App
*/
private $pConfig;
/**
* Set the user ID
*
* @param int $user_id
* @return void
*/
public function setUserId(int $user_id)
{
$this->user_id = $user_id;
}
/**
* Set the nickname
*
* @param int $user_id
* @return void
*/
public function setNickname(string $nickname)
{
$this->nickname = $nickname;
}
/**
* Fetch the user id
* @return int
*/
public function getUserId()
{
return $this->user_id;
}
/**
* Fetch the user nick name
* @return string
*/
public function getNickname()
{
return $this->nickname;
}
/**
* Fetch a specific user field
*
* @param string $index
* @return mixed
*/
public function getUserValue(string $index)
{
if (empty($this->user_id)) {
return null;
}
if (empty($this->user)) {
$this->user = User::getById($this->user_id);
}
return $this->user[$index] ?? null;
}
/**
* Set the profile owner ID
*

View file

@ -277,8 +277,8 @@ class Page implements ArrayAccess
// If you're just visiting, let javascript take you home
if (!empty($_SESSION['visitor_home'])) {
$homebase = $_SESSION['visitor_home'];
} elseif (!empty($app->user['nickname'])) {
$homebase = 'profile/' . $app->user['nickname'];
} elseif (!empty($app->getNickname())) {
$homebase = 'profile/' . $app->getNickname();
}
if (isset($homebase)) {

View file

@ -22,6 +22,7 @@
namespace Friendica;
use Friendica\Core\Logger;
use Friendica\Model\User;
/**
* All modules in Friendica should extend BaseModule, although not all modules
@ -135,10 +136,9 @@ abstract class BaseModule
*/
public static function getFormSecurityToken($typename = '')
{
$a = DI::app();
$user = User::getById(DI::app()->getUserId(), ['guid', 'prvkey']);
$timestamp = time();
$sec_hash = hash('whirlpool', ($a->user['guid'] ?? '') . ($a->user['prvkey'] ?? '') . session_id() . $timestamp . $typename);
$sec_hash = hash('whirlpool', ($user['guid'] ?? '') . ($user['prvkey'] ?? '') . session_id() . $timestamp . $typename);
return $timestamp . '.' . $sec_hash;
}
@ -163,14 +163,14 @@ abstract class BaseModule
$max_livetime = 10800; // 3 hours
$a = DI::app();
$user = User::getById(DI::app()->getUserId(), ['guid', 'prvkey']);
$x = explode('.', $hash);
if (time() > (intval($x[0]) + $max_livetime)) {
return false;
}
$sec_hash = hash('whirlpool', ($a->user['guid'] ?? '') . ($a->user['prvkey'] ?? '') . session_id() . $x[0] . $typename);
$sec_hash = hash('whirlpool', ($user['guid'] ?? '') . ($user['prvkey'] ?? '') . session_id() . $x[0] . $typename);
return ($sec_hash == $x[1]);
}
@ -183,8 +183,7 @@ abstract class BaseModule
public static function checkFormSecurityTokenRedirectOnError($err_redirect, $typename = '', $formname = 'form_security_token')
{
if (!self::checkFormSecurityToken($typename, $formname)) {
$a = DI::app();
Logger::log('checkFormSecurityToken failed: user ' . $a->user['guid'] . ' - form element ' . $typename);
Logger::log('checkFormSecurityToken failed: user ' . DI::app()->getNickname() . ' - form element ' . $typename);
Logger::log('checkFormSecurityToken failed: _REQUEST data: ' . print_r($_REQUEST, true), Logger::DATA);
notice(self::getFormSecurityStandardErrorMessage());
DI::baseUrl()->redirect($err_redirect);
@ -194,8 +193,7 @@ abstract class BaseModule
public static function checkFormSecurityTokenForbiddenOnError($typename = '', $formname = 'form_security_token')
{
if (!self::checkFormSecurityToken($typename, $formname)) {
$a = DI::app();
Logger::log('checkFormSecurityToken failed: user ' . $a->user['guid'] . ' - form element ' . $typename);
Logger::log('checkFormSecurityToken failed: user ' . DI::app()->getNickname() . ' - form element ' . $typename);
Logger::log('checkFormSecurityToken failed: _REQUEST data: ' . print_r($_REQUEST, true), Logger::DATA);
throw new \Friendica\Network\HTTPException\ForbiddenException();

View file

@ -154,7 +154,7 @@ class Nav
* Display the current site location as a navigation aid.
*/
$myident = ((is_array($a->user) && isset($a->user['nickname'])) ? $a->user['nickname'] . '@' : '');
$myident = !empty($a->getNickname() ? $a->getNickname() . '@' : '');
$sitelocation = $myident . substr(DI::baseUrl()->get($ssl_state), strpos(DI::baseUrl()->get($ssl_state), '//') + 2);
@ -188,18 +188,18 @@ class Nav
if (local_user()) {
if (!empty($a->user)) {
// user menu
$nav['usermenu'][] = ['profile/' . $a->user['nickname'], DI::l10n()->t('Status'), '', DI::l10n()->t('Your posts and conversations')];
$nav['usermenu'][] = ['profile/' . $a->user['nickname'] . '/profile', DI::l10n()->t('Profile'), '', DI::l10n()->t('Your profile page')];
$nav['usermenu'][] = ['photos/' . $a->user['nickname'], DI::l10n()->t('Photos'), '', DI::l10n()->t('Your photos')];
$nav['usermenu'][] = ['videos/' . $a->user['nickname'], DI::l10n()->t('Videos'), '', DI::l10n()->t('Your videos')];
$nav['usermenu'][] = ['profile/' . $a->getNickname(), DI::l10n()->t('Status'), '', DI::l10n()->t('Your posts and conversations')];
$nav['usermenu'][] = ['profile/' . $a->getNickname() . '/profile', DI::l10n()->t('Profile'), '', DI::l10n()->t('Your profile page')];
$nav['usermenu'][] = ['photos/' . $a->getNickname(), DI::l10n()->t('Photos'), '', DI::l10n()->t('Your photos')];
$nav['usermenu'][] = ['videos/' . $a->getNickname(), DI::l10n()->t('Videos'), '', DI::l10n()->t('Your videos')];
$nav['usermenu'][] = ['events/', DI::l10n()->t('Events'), '', DI::l10n()->t('Your events')];
$nav['usermenu'][] = ['notes/', DI::l10n()->t('Personal notes'), '', DI::l10n()->t('Your personal notes')];
// user info
$contact = DBA::selectFirst('contact', ['micro'], ['uid' => $a->user['uid'], 'self' => true]);
$contact = DBA::selectFirst('contact', ['micro'], ['uid' => $a->getUserId(), 'self' => true]);
$userinfo = [
'icon' => (DBA::isResult($contact) ? DI::baseUrl()->remove($contact['micro']) : Contact::DEFAULT_AVATAR_MICRO),
'name' => $a->user['username'],
'name' => $a->getUserValue('username'),
];
} else {
DI::logger()->warning('Empty $a->user for local user', ['local_user' => local_user(), '$a' => $a]);
@ -274,7 +274,7 @@ class Nav
if (local_user() && !empty($a->user)) {
$nav['network'] = ['network', DI::l10n()->t('Network'), '', DI::l10n()->t('Conversations from your friends')];
$nav['home'] = ['profile/' . $a->user['nickname'], DI::l10n()->t('Home'), '', DI::l10n()->t('Your posts and conversations')];
$nav['home'] = ['profile/' . $a->getNickname(), DI::l10n()->t('Home'), '', DI::l10n()->t('Your posts and conversations')];
// Don't show notifications for public communities
if (Session::get('page_flags', '') != User::PAGE_FLAGS_COMMUNITY) {

View file

@ -26,12 +26,24 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Model\User;
/**
* Handle ACL management and display
*/
class ACL
{
/**
* Returns the default lock state for the given user id
* @param int $uid
* @return bool "true" if the default settings are non public
*/
public static function getLockstateForUserId(int $uid)
{
$user = User::getById($uid, ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']);
return !empty($user['allow_cid']) || !empty($user['allow_gid']) || !empty($user['deny_cid']) || !empty($user['deny_gid']);
}
/**
* Returns a select input tag for private message recipient
*

View file

@ -68,7 +68,7 @@ class Introduction extends BaseFactory
$this->l10n = $l10n;
$this->pConfig = $pConfig;
$this->session = $session;
$this->nick = $app->user['nickname'] ?? '';
$this->nick = $app->getNickname() ?? '';
}
/**

View file

@ -173,7 +173,7 @@ class Mail
$recip_host = substr($recip_host, 0, strpos($recip_host, '/'));
$recip_handle = (($contact['addr']) ? $contact['addr'] : $contact['nick'] . '@' . $recip_host);
$sender_handle = $a->user['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3);
$sender_handle = $a->getNickname() . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3);
$conv_guid = System::createUUID();
$convuri = $recip_handle . ':' . $conv_guid;

View file

@ -155,6 +155,8 @@ class User
$system['region'] = '';
$system['country-name'] = '';
$system['net-publish'] = false;
$system['picdate'] = '';
$system['theme'] = '';
// Ensure that the user contains data
$user = DBA::selectFirst('user', ['prvkey', 'guid'], ['uid' => 0]);

View file

@ -77,7 +77,7 @@ class BaseApi extends BaseModule
$a = DI::app();
if (!empty($a->user['uid']) && $a->user['uid'] != self::getCurrentUserID()) {
if (empty($a->getUserId()) || $a->getUserId() != self::getCurrentUserID()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
}
@ -88,7 +88,7 @@ class BaseApi extends BaseModule
$a = DI::app();
if (!empty($a->user['uid']) && $a->user['uid'] != self::getCurrentUserID()) {
if (empty($a->getUserId()) || $a->getUserId() != self::getCurrentUserID()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
}
@ -99,7 +99,7 @@ class BaseApi extends BaseModule
$a = DI::app();
if (!empty($a->user['uid']) && $a->user['uid'] != self::getCurrentUserID()) {
if (empty($a->getUserId()) || $a->getUserId() != self::getCurrentUserID()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
}
@ -110,7 +110,7 @@ class BaseApi extends BaseModule
$a = DI::app();
if (!empty($a->user['uid']) && $a->user['uid'] != self::getCurrentUserID()) {
if (empty($a->getUserId()) || $a->getUserId() != self::getCurrentUserID()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
}

View file

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

View file

@ -60,10 +60,10 @@ class Bookmarklet extends BaseModule
$x = [
'is_owner' => true,
'allow_location' => $app->user['allow_location'],
'default_location' => $app->user['default-location'],
'nickname' => $app->user['nickname'],
'lockstate' => ((is_array($app->user) && ((strlen($app->user['allow_cid'])) || (strlen($app->user['allow_gid'])) || (strlen($app->user['deny_cid'])) || (strlen($app->user['deny_gid'])))) ? 'lock' : 'unlock'),
'allow_location' => $app->getUserValue('allow_location'),
'default_location' => $app->getUserValue('default-location'),
'nickname' => $app->getNickname(),
'lockstate' => ACL::getLockstateForUserId($app->getUserId()) ? 'lock' : 'unlock',
'default_perms' => ACL::getDefaultUserPermissions($app->user),
'acl' => ACL::getFullSelectorHTML(DI::page(), $app->user, true),
'bang' => '',

View file

@ -55,10 +55,11 @@ class Poke extends BaseModule
$private = !empty($_POST['private']) ? Model\Item::PRIVATE : Model\Item::PUBLIC;
$allow_cid = ($private ? '<' . $contact['id']. '>' : $a->user['allow_cid']);
$allow_gid = ($private ? '' : $a->user['allow_gid']);
$deny_cid = ($private ? '' : $a->user['deny_cid']);
$deny_gid = ($private ? '' : $a->user['deny_gid']);
$user = Model\User::getById($a->getUserId());
$allow_cid = ($private ? '<' . $contact['id']. '>' : $user['allow_cid']);
$allow_gid = ($private ? '' : $user['allow_gid']);
$deny_cid = ($private ? '' : $user['deny_cid']);
$deny_gid = ($private ? '' : $user['deny_gid']);
$actor = Contact::getById($a->getContactId());

View file

@ -130,10 +130,10 @@ class Community extends BaseModule
if (Session::isAuthenticated()) {
$x = [
'is_owner' => true,
'allow_location' => DI::app()->user['allow_location'],
'default_location' => DI::app()->user['default-location'],
'nickname' => DI::app()->user['nickname'],
'lockstate' => (is_array(DI::app()->user) && (strlen(DI::app()->user['allow_cid']) || strlen(DI::app()->user['allow_gid']) || strlen(DI::app()->user['deny_cid']) || strlen(DI::app()->user['deny_gid'])) ? 'lock' : 'unlock'),
'allow_location' => DI::app()->getUserValue('allow_location'),
'default_location' => DI::app()->getUserValue('default-location'),
'nickname' => DI::app()->getNickname(),
'lockstate' => ACL::getLockstateForUserId(DI::app()->getUserId()) ? 'lock' : 'unlock',
'acl' => ACL::getFullSelectorHTML(DI::page(), DI::app()->user, true),
'bang' => '',
'visitor' => 'block',

View file

@ -140,12 +140,10 @@ class Network extends BaseModule
$x = [
'is_owner' => true,
'allow_location' => $a->user['allow_location'],
'default_location' => $a->user['default-location'],
'nickname' => $a->user['nickname'],
'lockstate' => (self::$groupId || self::$forumContactId || self::$network || (is_array($a->user) &&
(strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) ||
strlen($a->user['deny_cid']) || strlen($a->user['deny_gid']))) ? 'lock' : 'unlock'),
'allow_location' => $a->getUserValue('allow_location'),
'default_location' => $a->getUserValue('default-location'),
'nickname' => $a->getNickname(),
'lockstate' => self::$groupId || self::$forumContactId || self::$network || ACL::getLockstateForUserId($a->getUserId()) ? 'lock' : 'unlock',
'default_perms' => ACL::getDefaultUserPermissions($a->user),
'acl' => ACL::getFullSelectorHTML(DI::page(), $a->user, true, $default_permissions),
'bang' => ((self::$groupId || self::$forumContactId || self::$network) ? '!' : ''),

View file

@ -109,7 +109,7 @@ class Delegation extends BaseModule
$ret = [];
Hook::callAll('home_init', $ret);
DI::baseUrl()->redirect('profile/' . DI::app()->user['nickname']);
DI::baseUrl()->redirect('profile/' . DI::app()->getNickname());
// NOTREACHED
}
@ -130,7 +130,7 @@ class Delegation extends BaseModule
$identities[$key]['thumb'] = Contact::getAvatarUrlForId($self['id'], Proxy::SIZE_THUMB, $self['updated']);
$identities[$key]['selected'] = ($identity['nickname'] === DI::app()->user['nickname']);
$identities[$key]['selected'] = ($identity['nickname'] === DI::app()->getNickname());
$condition = ["`uid` = ? AND `msg` != '' AND NOT (`type` IN (?, ?)) AND NOT `seen`", $identity['uid'], Notification\Type::INTRO, Notification\Type::MAIL];
$params = ['distinct' => true, 'expression' => 'parent'];

View file

@ -40,7 +40,7 @@ class HCard extends BaseModule
if ((local_user()) && ($parameters['action'] ?? '') === 'view') {
// A logged in user views a profile of a user
$nickname = $a->user['nickname'];
$nickname = $a->getNickname();
} elseif (empty($parameters['action'])) {
// Show the profile hCard
$nickname = $parameters['profile'];

View file

@ -42,7 +42,7 @@ class Home extends BaseModule
Hook::callAll('home_init', $ret);
if (local_user() && ($app->user['nickname'])) {
if (local_user() && ($app->getNickname())) {
DI::baseUrl()->redirect('network');
}

View file

@ -95,7 +95,7 @@ class Invite extends BaseModule
$nmessage = $message;
}
$additional_headers = 'From: "' . $app->user['email'] . '" <' . DI::emailer()->getSiteEmailAddress() . ">\n"
$additional_headers = 'From: "' . $app->getUserValue('email') . '" <' . DI::emailer()->getSiteEmailAddress() . ">\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit';
@ -168,7 +168,7 @@ class Invite extends BaseModule
DI::l10n()->t('You are cordially invited to join me and other close friends on Friendica - and help us to create a better social web.') . "\r\n" . "\r\n"
. $linkTxt
. "\r\n" . "\r\n" . (($inviteOnly) ? DI::l10n()->t('You will need to supply this invitation code: $invite_code') . "\r\n" . "\r\n" : '') . DI::l10n()->t('Once you have registered, please connect with me via my profile page at:')
. "\r\n" . "\r\n" . DI::baseUrl()->get() . '/profile/' . $app->user['nickname']
. "\r\n" . "\r\n" . DI::baseUrl()->get() . '/profile/' . $app->getNickname()
. "\r\n" . "\r\n" . DI::l10n()->t('For more information about the Friendica project and why we feel it is important, please visit http://friendi.ca') . "\r\n" . "\r\n",
],
'$submit' => DI::l10n()->t('Submit')

View file

@ -45,7 +45,7 @@ class NoScrape extends BaseModule
$which = $parameters['nick'];
} elseif (local_user() && isset($parameters['profile']) && DI::args()->get(2) == 'view') {
// view infos about a known profile (needs a login)
$which = $a->user['nickname'];
$which = $a->getNickname();
} else {
System::jsonError(403, 'Authentication required');
}

View file

@ -62,7 +62,7 @@ class Common extends BaseProfile
$a->redirect('profile/' . $nickname . '/contacts');
};
$o = self::getTabsHTML($a, 'contacts', false, $profile);
$o = self::getTabsHTML($a, 'contacts', false, $profile['nickname'], $profile['hide-friends']);
$tabs = self::getContactFilterTabs('profile/' . $nickname, 'common', $displayCommonTab);

View file

@ -59,7 +59,7 @@ class Contacts extends Module\BaseProfile
Nav::setSelected('home');
$o = self::getTabsHTML($a, 'contacts', $is_owner, $profile);
$o = self::getTabsHTML($a, 'contacts', $is_owner, $profile['nickname'], $profile['hide-friends']);
$tabs = self::getContactFilterTabs('profile/' . $nickname, $type, Session::isAuthenticated() && $profile['uid'] != local_user());

View file

@ -104,7 +104,7 @@ class Profile extends BaseProfile
Nav::setSelected('home');
$is_owner = local_user() == $profile['uid'];
$o = self::getTabsHTML($a, 'profile', $is_owner, $profile);
$o = self::getTabsHTML($a, 'profile', $is_owner, $profile['nickname'], $profile['hide-friends']);
if (!empty($profile['hidewall']) && !$is_owner && !$remote_contact_id) {
notice(DI::l10n()->t('Access to this profile has been restricted.'));

View file

@ -58,7 +58,7 @@ class Schedule extends BaseProfile
$a = DI::app();
$o = self::getTabsHTML($a, 'schedule', true, $a->user);
$o = self::getTabsHTML($a, 'schedule', true, $a->getNickname(), false);
$schedule = [];
$delayed = DBA::select('delayed-post', [], ['uid' => local_user()]);

View file

@ -110,7 +110,7 @@ class Status extends BaseProfile
return '';
}
$o .= self::getTabsHTML($a, 'status', $is_owner, $profile);
$o .= self::getTabsHTML($a, 'status', $is_owner, $profile['nickname'], $profile['hide-friends']);
$o .= Widget::commonFriendsVisitor($profile['uid'], $profile['nickname']);
@ -125,14 +125,9 @@ class Status extends BaseProfile
$x = [
'is_owner' => $is_owner,
'allow_location' => ($is_owner || $commvisitor) && $profile['allow_location'],
'default_location' => $is_owner ? $a->user['default-location'] : '',
'default_location' => $is_owner ? $a->getUserValue('default-location') : '',
'nickname' => $profile['nickname'],
'lockstate' => is_array($a->user)
&& (strlen($a->user['allow_cid'])
|| strlen($a->user['allow_gid'])
|| strlen($a->user['deny_cid'])
|| strlen($a->user['deny_gid'])
) ? 'lock' : 'unlock',
'lockstate' => ACL::getLockstateForUserId($a->getUserId()) ? 'lock' : 'unlock',
'acl' => $is_owner ? ACL::getFullSelectorHTML(DI::page(), $a->user, true) : '',
'bang' => '',
'visitor' => $is_owner || $commvisitor ? 'block' : 'none',

View file

@ -38,7 +38,7 @@ class Delegation extends BaseSettings
{
public static function post(array $parameters = [])
{
if (!local_user() || !empty(DI::app()->user['uid']) && DI::app()->user['uid'] != local_user()) {
if (!local_user() || empty(DI::app()->getUserId()) || DI::app()->getUserId() != local_user()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}

View file

@ -38,13 +38,13 @@ class Display extends BaseSettings
{
public static function post(array $parameters = [])
{
if (!local_user() || !empty(DI::app()->user['uid']) && DI::app()->user['uid'] != local_user()) {
if (!local_user() || empty(DI::app()->getUserId()) || DI::app()->getUserId() != local_user()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
self::checkFormSecurityTokenRedirectOnError('/settings/display', 'settings_display');
$theme = !empty($_POST['theme']) ? Strings::escapeTags(trim($_POST['theme'])) : DI::app()->user['theme'];
$theme = !empty($_POST['theme']) ? Strings::escapeTags(trim($_POST['theme'])) : DI::app()->getUserValue('theme');
$mobile_theme = !empty($_POST['mobile_theme']) ? Strings::escapeTags(trim($_POST['mobile_theme'])) : '';
$nosmile = !empty($_POST['nosmile']) ? intval($_POST['nosmile']) : 0;
$first_day_of_week = !empty($_POST['first_day_of_week']) ? intval($_POST['first_day_of_week']) : 0;
@ -92,7 +92,7 @@ class Display extends BaseSettings
DI::pConfig()->set(local_user(), 'system', 'first_day_of_week' , $first_day_of_week);
if (in_array($theme, Theme::getAllowedList())) {
if ($theme == DI::app()->user['theme']) {
if ($theme == DI::app()->getUserValue('theme')) {
// call theme_post only if theme has not been changed
if (($themeconfigfile = Theme::getConfigFile($theme)) !== null) {
require_once $themeconfigfile;
@ -152,7 +152,7 @@ class Display extends BaseSettings
}
}
$theme_selected = DI::app()->user['theme'] ?: $default_theme;
$theme_selected = DI::app()->getUserValue('theme') ?: $default_theme;
$mobile_theme_selected = Session::get('mobile-theme', $default_mobile_theme);
$itemspage_network = intval(DI::pConfig()->get(local_user(), 'system', 'itemspage_network'));

View file

@ -207,7 +207,7 @@ class Index extends BaseSettings
'$baseurl' => DI::baseUrl()->get(true),
]);
$personal_account = !in_array($a->user['page-flags'], [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP]);
$personal_account = !in_array($profile['page-flags'], [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP]);
$tpl = Renderer::getMarkupTemplate('settings/profile/index.tpl');
$o .= Renderer::replaceMacros($tpl, [
@ -220,7 +220,7 @@ class Index extends BaseSettings
'$banner' => DI::l10n()->t('Edit Profile Details'),
'$submit' => DI::l10n()->t('Submit'),
'$profpic' => DI::l10n()->t('Change Profile Photo'),
'$profpiclink' => '/photos/' . $a->user['nickname'],
'$profpiclink' => '/photos/' . $profile['nickname'],
'$viewprof' => DI::l10n()->t('View Profile'),
'$lbl_personal_section' => DI::l10n()->t('Personal'),
@ -232,16 +232,16 @@ class Index extends BaseSettings
'$lbl_profile_photo' => DI::l10n()->t('Upload Profile Photo'),
'$baseurl' => DI::baseUrl()->get(true),
'$nickname' => $a->user['nickname'],
'$nickname' => $profile['nickname'],
'$name' => ['name', DI::l10n()->t('Display name:'), $profile['name']],
'$about' => ['about', DI::l10n()->t('Description:'), $profile['about']],
'$dob' => Temporal::getDateofBirthField($profile['dob'], $a->user['timezone']),
'$dob' => Temporal::getDateofBirthField($profile['dob'], $profile['timezone']),
'$address' => ['address', DI::l10n()->t('Street Address:'), $profile['address']],
'$locality' => ['locality', DI::l10n()->t('Locality/City:'), $profile['locality']],
'$region' => ['region', DI::l10n()->t('Region/State:'), $profile['region']],
'$postal_code' => ['postal_code', DI::l10n()->t('Postal/Zip Code:'), $profile['postal-code']],
'$country_name' => ['country_name', DI::l10n()->t('Country:'), $profile['country-name']],
'$age' => ((intval($profile['dob'])) ? '(' . DI::l10n()->t('Age: ') . DI::l10n()->tt('%d year old', '%d years old', Temporal::getAgeByTimezone($profile['dob'], $a->user['timezone'])) . ')' : ''),
'$age' => ((intval($profile['dob'])) ? '(' . DI::l10n()->t('Age: ') . DI::l10n()->tt('%d year old', '%d years old', Temporal::getAgeByTimezone($profile['dob'], $profile['timezone'])) . ')' : ''),
'$xmpp' => ['xmpp', DI::l10n()->t('XMPP (Jabber) address:'), $profile['xmpp'], DI::l10n()->t('The XMPP address will be propagated to your contacts so that they can follow you.')],
'$homepage' => ['homepage', DI::l10n()->t('Homepage URL:'), $profile['homepage']],
'$pub_keywords' => ['pub_keywords', DI::l10n()->t('Public Keywords:'), $profile['pub_keywords'], DI::l10n()->t('(Used for suggesting potential friends, can be seen by others)')],
@ -251,7 +251,7 @@ class Index extends BaseSettings
<p>Reorder by dragging the field title.</p>
<p>Empty the label field to remove a custom field.</p>
<p>Non-public fields can only be seen by the selected Friendica contacts or the Friendica contacts in the selected groups.</p>",
'profile/' . $a->user['nickname']
'profile/' . $profile['nickname']
),
'$custom_fields' => $custom_fields,
]);

View file

@ -57,7 +57,7 @@ class Crop extends BaseSettings
$selectionW = intval($_POST['width'] ?? 0);
$selectionH = intval($_POST['height'] ?? 0);
$path = 'profile/' . DI::app()->user['nickname'];
$path = 'profile/' . DI::app()->getNickname();
$base_image = Photo::selectFirst([], ['resource-id' => $resource_id, 'uid' => local_user(), 'scale' => $scale]);
if (DBA::isResult($base_image)) {
@ -185,7 +185,7 @@ class Crop extends BaseSettings
info(DI::l10n()->t('Profile picture successfully updated.'));
DI::baseUrl()->redirect('profile/' . DI::app()->user['nickname']);
DI::baseUrl()->redirect('profile/' . DI::app()->getNickname());
}
$Image = Photo::getImageForPhoto($photos[0]);

View file

@ -134,7 +134,7 @@ class Index extends BaseSettings
DI::l10n()->t('or'),
($newuser) ?
'<a href="' . DI::baseUrl() . '">' . DI::l10n()->t('skip this step') . '</a>'
: '<a href="' . DI::baseUrl() . '/photos/' . DI::app()->user['nickname'] . '">'
: '<a href="' . DI::baseUrl() . '/photos/' . DI::app()->getNickname() . '">'
. DI::l10n()->t('select a photo from your photo albums') . '</a>'
),
]);

View file

@ -90,7 +90,7 @@ class UserExport extends BaseSettings
*/
public static function rawContent(array $parameters = [])
{
if (!local_user() || !empty(DI::app()->user['uid']) && DI::app()->user['uid'] != local_user()) {
if (!local_user() || empty(DI::app()->getUserId()) || DI::app()->getUserId() != local_user()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}

View file

@ -36,20 +36,20 @@ class ItemCCEMail extends Email
{
public function __construct(App $a, L10n $l10n, BaseURL $baseUrl, array $item, string $toAddress, string $authorThumb)
{
$disclaimer = '<hr />' . $l10n->t('This message was sent to you by %s, a member of the Friendica social network.', $a->user['username'])
$disclaimer = '<hr />' . $l10n->t('This message was sent to you by %s, a member of the Friendica social network.', $a->getUserValue('username'))
. '<br />';
$disclaimer .= $l10n->t('You may visit them online at %s', $baseUrl . '/profile/' . $a->user['nickname']) . EOL;
$disclaimer .= $l10n->t('You may visit them online at %s', $baseUrl . '/profile/' . $a->getNickname()) . EOL;
$disclaimer .= $l10n->t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL;
if (!$item['title'] == '') {
$subject = EmailProtocol::encodeHeader($item['title'], 'UTF-8');
} else {
$subject = EmailProtocol::encodeHeader('[Friendica]' . ' ' . $l10n->t('%s posted an update.', $a->user['username']), 'UTF-8');
$subject = EmailProtocol::encodeHeader('[Friendica]' . ' ' . $l10n->t('%s posted an update.', $a->getUserValue('username')), 'UTF-8');
}
$link = '<a href="' . $baseUrl . '/profile/' . $a->user['nickname'] . '"><img src="' . $authorThumb . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
$link = '<a href="' . $baseUrl . '/profile/' . $a->getNickname() . '"><img src="' . $authorThumb . '" alt="' . $a->getUserValue('username') . '" /></a><br /><br />';
$html = Item::prepareBody($item);
$message = '<html><body>' . $link . $html . $disclaimer . '</body></html>';;
parent::__construct($a->user['username'], $a->user['email'], $a->user['email'], $toAddress,
parent::__construct($a->getUserValue('username'), $a->getUserValue('email'), $a->getUserValue('email'), $toAddress,
$subject, $message, HTML::toPlaintext($html . $disclaimer));
}
}

View file

@ -870,7 +870,7 @@ class Post
return '';
}
$owner = User::getOwnerDataById($a->user['uid']);
$owner = User::getOwnerDataById($a->getUserId());
if (!Feature::isEnabled(local_user(), 'explicit_mentions')) {
return '';

View file

@ -353,10 +353,12 @@ class Authentication
}
}
$a->setUserId($user_record['uid']);
$a->setNickname($user_record['nickname']);
$a->user = $user_record;
if ($login_initial) {
Hook::callAll('logged_in', $a->user);
Hook::callAll('logged_in', $user_record);
if (DI::module()->getName() !== 'home' && $this->session->exists('return_path')) {
$this->baseUrl->redirect($this->session->get('return_path'));

View file

@ -184,7 +184,7 @@ class BasicAuth
Session::set('allow_api', true);
Hook::callAll('logged_in', $a->user);
Hook::callAll('logged_in', $record);
if (Session::get('allow_api')) {
self::$current_user_id = local_user();