diff --git a/src/App.php b/src/App.php index 95b0716e28..081767cfdb 100644 --- a/src/App.php +++ b/src/App.php @@ -33,6 +33,7 @@ use Friendica\Core\Config\ValueObject\Cache; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\L10n; +use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Core\Theme; use Friendica\Database\Database; @@ -157,7 +158,7 @@ class App public function isLoggedIn(): bool { - return local_user() && $this->user_id && ($this->user_id == local_user()); + return Session::getLocalUser() && $this->user_id && ($this->user_id == Session::getLocalUser()); } /** @@ -171,7 +172,7 @@ class App $adminlist = explode(',', str_replace(' ', '', $admin_email)); - return local_user() && $admin_email && $this->database->exists('user', ['uid' => $this->getLoggedInUserId(), 'email' => $adminlist]); + return Session::getLocalUser() && $admin_email && $this->database->exists('user', ['uid' => $this->getLoggedInUserId(), 'email' => $adminlist]); } /** @@ -495,11 +496,11 @@ class App $page_theme = null; // Find the theme that belongs to the user whose stuff we are looking at - if (!empty($this->profile_owner) && ($this->profile_owner != local_user())) { + if (!empty($this->profile_owner) && ($this->profile_owner != Session::getLocalUser())) { // 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 $user = $this->database->selectFirst('user', ['theme'], ['uid' => $this->profile_owner]); - if ($this->database->isResult($user) && !local_user()) { + if ($this->database->isResult($user) && !Session::getLocalUser()) { $page_theme = $user['theme']; } } @@ -528,10 +529,10 @@ class App $page_mobile_theme = null; // Find the theme that belongs to the user whose stuff we are looking at - if (!empty($this->profile_owner) && ($this->profile_owner != local_user())) { + if (!empty($this->profile_owner) && ($this->profile_owner != Session::getLocalUser())) { // 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 - if (!local_user()) { + if (!Session::getLocalUser()) { $page_mobile_theme = $this->pConfig->get($this->profile_owner, 'system', 'mobile-theme'); } } @@ -628,7 +629,7 @@ class App } // ZRL - if (!empty($_GET['zrl']) && $this->mode->isNormal() && !$this->mode->isBackend() && !local_user()) { + if (!empty($_GET['zrl']) && $this->mode->isNormal() && !$this->mode->isBackend() && !Session::getLocalUser()) { // Only continue when the given profile link seems valid // Valid profile links contain a path with "/profile/" and no query parameters if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == '') && diff --git a/src/App/Page.php b/src/App/Page.php index dcd2e8832e..d1aa17ad07 100644 --- a/src/App/Page.php +++ b/src/App/Page.php @@ -32,6 +32,7 @@ use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\Renderer; +use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Core\Theme; use Friendica\Module\Response; @@ -231,7 +232,7 @@ class Page implements ArrayAccess */ private function initHead(App $app, Arguments $args, L10n $l10n, IManageConfigValues $config, IManagePersonalConfigValues $pConfig) { - $interval = ((local_user()) ? $pConfig->get(local_user(), 'system', 'update_interval') : 40000); + $interval = ((Session::getLocalUser()) ? $pConfig->get(Session::getLocalUser(), 'system', 'update_interval') : 40000); // If the update is 'deactivated' set it to the highest integer number (~24 days) if ($interval < 0) { @@ -276,7 +277,7 @@ class Page implements ArrayAccess * being first */ $this->page['htmlhead'] = Renderer::replaceMacros($tpl, [ - '$local_user' => local_user(), + '$local_user' => Session::getLocalUser(), '$generator' => 'Friendica' . ' ' . App::VERSION, '$delitem' => $l10n->t('Delete this item?'), '$blockAuthor' => $l10n->t('Block this author? They won\'t be able to follow you nor see your public posts, and you won\'t be able to see their posts and their notifications.'), diff --git a/src/App/Router.php b/src/App/Router.php index a4fe4f9411..356279e493 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -34,6 +34,7 @@ use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Lock\Capability\ICanLock; +use Friendica\Core\Session; use Friendica\LegacyModule; use Friendica\Module\HTTPException\MethodNotAllowed; use Friendica\Module\HTTPException\PageNotFound; @@ -308,7 +309,7 @@ class Router if (Addon::isEnabled($moduleName) && file_exists("addon/{$moduleName}/{$moduleName}.php")) { //Check if module is an app and if public access to apps is allowed or not $privateapps = $this->config->get('config', 'private_addons', false); - if ((!local_user()) && Hook::isAddonApp($moduleName) && $privateapps) { + if (!Session::getLocalUser() && Hook::isAddonApp($moduleName) && $privateapps) { throw new MethodNotAllowedException($this->l10n->t("You must be logged in to use addons. ")); } else { include_once "addon/{$moduleName}/{$moduleName}.php"; diff --git a/src/Content/Conversation.php b/src/Content/Conversation.php index caab022473..c727ea2fab 100644 --- a/src/Content/Conversation.php +++ b/src/Content/Conversation.php @@ -171,7 +171,7 @@ class Conversation continue; } - if (public_contact() == $activity['author-id']) { + if (Session::getPublicContact() == $activity['author-id']) { $conv_responses[$mode][$activity['thr-parent-id']]['self'] = 1; } @@ -296,7 +296,7 @@ class Conversation $x['bang'] = $x['bang'] ?? ''; $x['visitor'] = $x['visitor'] ?? 'block'; $x['is_owner'] = $x['is_owner'] ?? true; - $x['profile_uid'] = $x['profile_uid'] ?? local_user(); + $x['profile_uid'] = $x['profile_uid'] ?? Session::getLocalUser(); $geotag = !empty($x['allow_location']) ? Renderer::replaceMacros(Renderer::getMarkupTemplate('jot_geotag.tpl'), []) : ''; @@ -359,7 +359,7 @@ class Conversation '$title' => $x['title'] ?? '', '$placeholdertitle' => $this->l10n->t('Set title'), '$category' => $x['category'] ?? '', - '$placeholdercategory' => Feature::isEnabled(local_user(), 'categories') ? $this->l10n->t("Categories \x28comma-separated list\x29") : '', + '$placeholdercategory' => Feature::isEnabled(Session::getLocalUser(), 'categories') ? $this->l10n->t("Categories \x28comma-separated list\x29") : '', '$scheduled_at' => Temporal::getDateTimeField( new \DateTime(), new \DateTime('now + 6 months'), @@ -397,7 +397,7 @@ class Conversation '$browser' => $this->l10n->t('Browser'), '$compose_link_title' => $this->l10n->t('Open Compose page'), - '$always_open_compose' => $this->pConfig->get(local_user(), 'frio', 'always_open_compose', false), + '$always_open_compose' => $this->pConfig->get(Session::getLocalUser(), 'frio', 'always_open_compose', false), ]); @@ -436,7 +436,7 @@ class Conversation $this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.css')); $this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput-typeahead.css')); - $ssl_state = (local_user() ? true : false); + $ssl_state = (Session::getLocalUser() ? true : false); $live_update_div = ''; @@ -488,11 +488,11 @@ class Conversation } } } elseif ($mode === 'notes') { - $items = $this->addChildren($items, false, $order, local_user(), $mode); + $items = $this->addChildren($items, false, $order, Session::getLocalUser(), $mode); if (!$update) { $live_update_div = '
' . "\r\n" - . "\r\n"; } } elseif ($mode === 'display') { @@ -526,7 +526,7 @@ class Conversation $live_update_div = '' . "\r\n"; } - $page_dropping = ((local_user() && local_user() == $uid) ? true : false); + $page_dropping = ((Session::getLocalUser() && Session::getLocalUser() == $uid) ? true : false); if (!$update) { $_SESSION['return_path'] = $this->args->getQueryString(); @@ -546,7 +546,7 @@ class Conversation 'announce' => [], ]; - if ($this->pConfig->get(local_user(), 'system', 'hide_dislike')) { + if ($this->pConfig->get(Session::getLocalUser(), 'system', 'hide_dislike')) { unset($conv_responses['dislike']); } @@ -564,7 +564,7 @@ class Conversation $writable = $items[0]['writable'] || ($items[0]['uid'] == 0) && in_array($items[0]['network'], Protocol::FEDERATED); } - if (!local_user()) { + if (!Session::getLocalUser()) { $writable = false; } @@ -597,7 +597,7 @@ class Conversation $threadsid++; // prevent private email from leaking. - if ($item['network'] === Protocol::MAIL && local_user() != $item['uid']) { + if ($item['network'] === Protocol::MAIL && Session::getLocalUser() != $item['uid']) { continue; } @@ -641,17 +641,17 @@ class Conversation 'announce' => null, ]; - if ($this->pConfig->get(local_user(), 'system', 'hide_dislike')) { + if ($this->pConfig->get(Session::getLocalUser(), 'system', 'hide_dislike')) { unset($likebuttons['dislike']); } $body_html = ItemModel::prepareBody($item, true, $preview); - [$categories, $folders] = $this->item->determineCategoriesTerms($item, local_user()); + [$categories, $folders] = $this->item->determineCategoriesTerms($item, Session::getLocalUser()); if (!empty($item['title'])) { $title = $item['title']; - } elseif (!empty($item['content-warning']) && $this->pConfig->get(local_user(), 'system', 'disable_cw', false)) { + } elseif (!empty($item['content-warning']) && $this->pConfig->get(Session::getLocalUser(), 'system', 'disable_cw', false)) { $title = ucfirst($item['content-warning']); } else { $title = ''; @@ -745,7 +745,7 @@ class Conversation $this->builtinActivityPuller($item, $conv_responses); // Only add what is visible - if ($item['network'] === Protocol::MAIL && local_user() != $item['uid']) { + if ($item['network'] === Protocol::MAIL && Session::getLocalUser() != $item['uid']) { continue; } @@ -790,11 +790,11 @@ class Conversation private function getBlocklist(): array { - if (!local_user()) { + if (!Session::getLocalUser()) { return []; } - $str_blocked = str_replace(["\n", "\r"], ",", $this->pConfig->get(local_user(), 'system', 'blocked')); + $str_blocked = str_replace(["\n", "\r"], ",", $this->pConfig->get(Session::getLocalUser(), 'system', 'blocked')); if (empty($str_blocked)) { return []; } @@ -864,7 +864,7 @@ class Conversation $row['direction'] = ['direction' => 4, 'title' => $this->l10n->t('You subscribed to one or more tags in this post.')]; break; case ItemModel::PR_ANNOUNCEMENT: - if (!empty($row['causer-id']) && $this->pConfig->get(local_user(), 'system', 'display_resharer')) { + if (!empty($row['causer-id']) && $this->pConfig->get(Session::getLocalUser(), 'system', 'display_resharer')) { $row['owner-id'] = $row['causer-id']; $row['owner-link'] = $row['causer-link']; $row['owner-avatar'] = $row['causer-avatar']; @@ -1216,7 +1216,7 @@ class Conversation $parents[$i]['children'] = $this->sortItemChildren($parents[$i]['children']); } - if (!$this->pConfig->get(local_user(), 'system', 'no_smart_threading', 0)) { + if (!$this->pConfig->get(Session::getLocalUser(), 'system', 'no_smart_threading', 0)) { foreach ($parents as $i => $parent) { $parents[$i] = $this->smartFlattenConversation($parent); } diff --git a/src/Content/ForumManager.php b/src/Content/ForumManager.php index 51abaa49dd..f5e7761472 100644 --- a/src/Content/ForumManager.php +++ b/src/Content/ForumManager.php @@ -24,6 +24,7 @@ namespace Friendica\Content; use Friendica\Content\Text\HTML; use Friendica\Core\Protocol; use Friendica\Core\Renderer; +use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; @@ -223,7 +224,7 @@ class ForumManager AND NOT `contact`.`pending` AND NOT `contact`.`archive` AND `contact`.`uid` = ? GROUP BY `contact`.`id`", - local_user(), Protocol::DFRN, Protocol::ACTIVITYPUB, Contact::TYPE_COMMUNITY, local_user() + Session::getLocalUser(), Protocol::DFRN, Protocol::ACTIVITYPUB, Contact::TYPE_COMMUNITY, Session::getLocalUser() ); return DBA::toArray($stmtContacts); diff --git a/src/Content/Item.php b/src/Content/Item.php index b363ad982b..521c015468 100644 --- a/src/Content/Item.php +++ b/src/Content/Item.php @@ -27,6 +27,7 @@ use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\Protocol; +use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Model\Contact; @@ -109,7 +110,7 @@ class Item $categories[] = [ 'name' => $savedFolderName, 'url' => $url, - 'removeurl' => local_user() == $uid ? 'filerm/' . $item['id'] . '?cat=' . rawurlencode($savedFolderName) : '', + 'removeurl' => Session::getLocalUser() == $uid ? 'filerm/' . $item['id'] . '?cat=' . rawurlencode($savedFolderName) : '', 'first' => $first, 'last' => false ]; @@ -120,12 +121,12 @@ class Item $categories[count($categories) - 1]['last'] = true; } - if (local_user() == $uid) { + if (Session::getLocalUser() == $uid) { foreach (Post\Category::getArrayByURIId($item['uri-id'], $uid, Post\Category::FILE) as $savedFolderName) { $folders[] = [ 'name' => $savedFolderName, 'url' => "#", - 'removeurl' => local_user() == $uid ? 'filerm/' . $item['id'] . '?term=' . rawurlencode($savedFolderName) : '', + 'removeurl' => Session::getLocalUser() == $uid ? 'filerm/' . $item['id'] . '?term=' . rawurlencode($savedFolderName) : '', 'first' => $first, 'last' => false ]; @@ -331,7 +332,7 @@ class Item $sub_link = $contact_url = $pm_url = $status_link = ''; $photos_link = $posts_link = $block_link = $ignore_link = ''; - if (local_user() && local_user() == $item['uid'] && $item['gravity'] == ItemModel::GRAVITY_PARENT && !$item['self'] && !$item['mention']) { + if (Session::getLocalUser() && Session::getLocalUser() == $item['uid'] && $item['gravity'] == ItemModel::GRAVITY_PARENT && !$item['self'] && !$item['mention']) { $sub_link = 'javascript:doFollowThread(' . $item['id'] . '); return false;'; } @@ -348,7 +349,7 @@ class Item $pcid = $item['author-id']; $network = ''; $rel = 0; - $condition = ['uid' => local_user(), 'uri-id' => $item['author-uri-id']]; + $condition = ['uid' => Session::getLocalUser(), 'uri-id' => $item['author-uri-id']]; $contact = DBA::selectFirst('contact', ['id', 'network', 'rel'], $condition); if (DBA::isResult($contact)) { $cid = $contact['id']; @@ -378,7 +379,7 @@ class Item } } - if (local_user()) { + if (Session::getLocalUser()) { $menu = [ $this->l10n->t('Follow Thread') => $sub_link, $this->l10n->t('View Status') => $status_link, @@ -439,7 +440,7 @@ class Item return (!($this->activity->match($item['verb'], Activity::FOLLOW) && $item['object-type'] === Activity\ObjectType::NOTE && empty($item['self']) && - $item['uid'] == local_user()) + $item['uid'] == Session::getLocalUser()) ); } diff --git a/src/Content/Nav.php b/src/Content/Nav.php index b43e926e8c..c66758a6df 100644 --- a/src/Content/Nav.php +++ b/src/Content/Nav.php @@ -127,7 +127,7 @@ class Nav //Don't populate apps_menu if apps are private $privateapps = DI::config()->get('config', 'private_addons', false); - if (local_user() || !$privateapps) { + if (Session::getLocalUser() || !$privateapps) { $arr = ['app_menu' => self::$app_menu]; Hook::callAll('app_menu', $arr); @@ -149,7 +149,7 @@ class Nav */ private static function getInfo(App $a): array { - $ssl_state = (bool) local_user(); + $ssl_state = (bool) Session::getLocalUser(); /* * Our network is distributed, and as you visit friends some of the @@ -211,7 +211,7 @@ class Nav $homelink = DI::session()->get('visitor_home', ''); } - if ((DI::args()->getModuleName() != 'home') && (! (local_user()))) { + if ((DI::args()->getModuleName() != 'home') && (! (Session::getLocalUser()))) { $nav['home'] = [$homelink, DI::l10n()->t('Home'), '', DI::l10n()->t('Home Page')]; } @@ -229,7 +229,7 @@ class Nav $nav['apps'] = ['apps', DI::l10n()->t('Apps'), '', DI::l10n()->t('Addon applications, utilities, games')]; } - if (local_user() || !DI::config()->get('system', 'local_search')) { + if (Session::getLocalUser() || !DI::config()->get('system', 'local_search')) { $nav['search'] = ['search', DI::l10n()->t('Search'), '', DI::l10n()->t('Search site content')]; $nav['searchoption'] = [ @@ -252,12 +252,12 @@ class Nav } } - if ((local_user() || DI::config()->get('system', 'community_page_style') != Community::DISABLED_VISITOR) && + if ((Session::getLocalUser() || DI::config()->get('system', 'community_page_style') != Community::DISABLED_VISITOR) && !(DI::config()->get('system', 'community_page_style') == Community::DISABLED)) { $nav['community'] = ['community', DI::l10n()->t('Community'), '', DI::l10n()->t('Conversations on this and other servers')]; } - if (local_user()) { + if (Session::getLocalUser()) { $nav['events'] = ['events', DI::l10n()->t('Events'), '', DI::l10n()->t('Events and Calendar')]; } @@ -270,7 +270,7 @@ class Nav } // The following nav links are only show to logged in users - if (local_user() && !empty($a->getLoggedInUserNickname())) { + if (Session::getLocalUser() && !empty($a->getLoggedInUserNickname())) { $nav['network'] = ['network', DI::l10n()->t('Network'), '', DI::l10n()->t('Conversations from your friends')]; $nav['home'] = ['profile/' . $a->getLoggedInUserNickname(), DI::l10n()->t('Home'), '', DI::l10n()->t('Your posts and conversations')]; @@ -288,7 +288,7 @@ class Nav $nav['messages']['outbox'] = ['message/sent', DI::l10n()->t('Outbox'), '', DI::l10n()->t('Outbox')]; $nav['messages']['new'] = ['message/new', DI::l10n()->t('New Message'), '', DI::l10n()->t('New Message')]; - if (User::hasIdentities(DI::session()->get('submanage') ?: local_user())) { + if (User::hasIdentities(DI::session()->get('submanage') ?: Session::getLocalUser())) { $nav['delegation'] = ['delegation', DI::l10n()->t('Accounts'), '', DI::l10n()->t('Manage other pages')]; } diff --git a/src/Content/Smilies.php b/src/Content/Smilies.php index 04dcf99070..68093e843d 100644 --- a/src/Content/Smilies.php +++ b/src/Content/Smilies.php @@ -22,6 +22,7 @@ namespace Friendica\Content; use Friendica\Core\Hook; +use Friendica\Core\Session; use Friendica\DI; use Friendica\Util\Strings; @@ -213,7 +214,7 @@ class Smilies public static function replaceFromArray(string $text, array $smilies, bool $no_images = false): string { if (intval(DI::config()->get('system', 'no_smilies')) - || (local_user() && intval(DI::pConfig()->get(local_user(), 'system', 'no_smilies'))) + || (Session::getLocalUser() && intval(DI::pConfig()->get(Session::getLocalUser(), 'system', 'no_smilies'))) ) { return $text; } diff --git a/src/Content/Widget.php b/src/Content/Widget.php index f1f62c33fc..06841ed924 100644 --- a/src/Content/Widget.php +++ b/src/Content/Widget.php @@ -26,6 +26,7 @@ use Friendica\Core\Cache\Enum\Duration; use Friendica\Core\Protocol; use Friendica\Core\Renderer; use Friendica\Core\Search; +use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; @@ -66,7 +67,7 @@ class Widget $global_dir = Search::getGlobalDirectory(); if (DI::config()->get('system', 'invitation_only')) { - $x = intval(DI::pConfig()->get(local_user(), 'system', 'invites_remaining')); + $x = intval(DI::pConfig()->get(Session::getLocalUser(), 'system', 'invites_remaining')); if ($x || DI::app()->isSiteAdmin()) { DI::page()['aside'] .= '