Extract App::getProfileOwner() and setProfileOwner() into AppHelper

This commit is contained in:
Art4 2024-11-06 13:36:38 +01:00
parent b5317f8e46
commit f0ce7ea61e
2 changed files with 32 additions and 7 deletions

View file

@ -61,7 +61,6 @@ class App
'videoheight' => 350, 'videoheight' => 350,
]; ];
private $profile_owner = 0;
private $queue = []; private $queue = [];
/** /**
@ -133,22 +132,26 @@ class App
/** /**
* Set the profile owner ID * Set the profile owner ID
* *
* @deprecated 2024.12 Use AppHelper::setProfileOwner() instead
*
* @param int $owner_id * @param int $owner_id
* @return void * @return void
*/ */
public function setProfileOwner(int $owner_id) public function setProfileOwner(int $owner_id)
{ {
$this->profile_owner = $owner_id; $this->appHelper->setProfileOwner($owner_id);
} }
/** /**
* Get the profile owner ID * Get the profile owner ID
* *
* @deprecated 2024.12 Use AppHelper::getProfileOwner() instead
*
* @return int * @return int
*/ */
public function getProfileOwner(): int public function getProfileOwner(): int
{ {
return $this->profile_owner; return $this->appHelper->getProfileOwner();
} }
/** /**
@ -460,11 +463,13 @@ class App
$this->setCurrentTheme($system_theme); $this->setCurrentTheme($system_theme);
$page_theme = null; $page_theme = null;
$profile_owner = $this->appHelper->getProfileOwner();
// Find the theme that belongs to the user whose stuff we are looking at // Find the theme that belongs to the user whose stuff we are looking at
if (!empty($this->profile_owner) && ($this->profile_owner != $this->session->getLocalUserId())) { if (!empty($profile_owner) && ($profile_owner != $this->session->getLocalUserId())) {
// Allow folks to override user themes and always use their own on their own site. // Allow folks to override user themes and always use their own on their own site.
// This works only if the user is on the same server // This works only if the user is on the same server
$user = $this->database->selectFirst('user', ['theme'], ['uid' => $this->profile_owner]); $user = $this->database->selectFirst('user', ['theme'], ['uid' => $profile_owner]);
if ($this->database->isResult($user) && !$this->session->getLocalUserId()) { if ($this->database->isResult($user) && !$this->session->getLocalUserId()) {
$page_theme = $user['theme']; $page_theme = $user['theme'];
} }
@ -493,12 +498,14 @@ class App
$this->setCurrentMobileTheme($system_mobile_theme); $this->setCurrentMobileTheme($system_mobile_theme);
$page_mobile_theme = null; $page_mobile_theme = null;
$profile_owner = $this->appHelper->getProfileOwner();
// Find the theme that belongs to the user whose stuff we are looking at // Find the theme that belongs to the user whose stuff we are looking at
if (!empty($this->profile_owner) && ($this->profile_owner != $this->session->getLocalUserId())) { if (!empty($profile_owner) && ($profile_owner != $this->session->getLocalUserId())) {
// Allow folks to override user themes and always use their own on their own site. // Allow folks to override user themes and always use their own on their own site.
// This works only if the user is on the same server // This works only if the user is on the same server
if (!$this->session->getLocalUserId()) { if (!$this->session->getLocalUserId()) {
$page_mobile_theme = $this->pConfig->get($this->profile_owner, 'system', 'mobile-theme'); $page_mobile_theme = $this->pConfig->get($profile_owner, 'system', 'mobile-theme');
} }
} }

View file

@ -22,10 +22,28 @@ use Friendica\Util\DateTimeFormat;
*/ */
final class AppHelper final class AppHelper
{ {
private $profile_owner = 0;
private $timezone = ''; private $timezone = '';
private $contact_id = 0; private $contact_id = 0;
/**
* Set the profile owner ID
*/
public function setProfileOwner(int $owner_id): void
{
$this->profile_owner = $owner_id;
}
/**
* Get the profile owner ID
*/
public function getProfileOwner(): int
{
return $this->profile_owner;
}
/** /**
* Set the timezone * Set the timezone
* *