diff --git a/CHANGELOG b/CHANGELOG index 88d28f313..b2e549610 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,9 @@ Version 2022.12 (unreleased) Friendica Core Friendica Addons + BREAKING: The functions from the boot.php file have been moved into better fitting classes + this may break your custom addons. See the pull requests #1293 and #1294 in the + addon repository about the needed changes to your addons. Closed Issues diff --git a/mod/cal.php b/mod/cal.php index ef2063d0a..4c22232d2 100644 --- a/mod/cal.php +++ b/mod/cal.php @@ -27,7 +27,6 @@ use Friendica\App; use Friendica\Content\Nav; use Friendica\Content\Widget; use Friendica\Core\Renderer; -use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; @@ -42,7 +41,7 @@ use Friendica\Util\Temporal; function cal_init(App $a) { - if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) { + if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) { throw new HTTPException\ForbiddenException(DI::l10n()->t('Access denied.')); } @@ -112,11 +111,11 @@ function cal_content(App $a) $owner_uid = intval($owner['uid']); $nick = $owner['nickname']; - $contact_id = Session::getRemoteContactID($owner['uid']); + $contact_id = DI::userSession()->getRemoteContactID($owner['uid']); $remote_contact = $contact_id && DBA::exists('contact', ['id' => $contact_id, 'uid' => $owner['uid']]); - $is_owner = Session::getLocalUser() == $owner['uid']; + $is_owner = DI::userSession()->getLocalUserId() == $owner['uid']; if ($owner['hidewall'] && !$is_owner && !$remote_contact) { DI::sysmsg()->addNotice(DI::l10n()->t('Access to this profile has been restricted.')); @@ -278,7 +277,7 @@ function cal_content(App $a) // If it the own calendar return to the events page // otherwise to the profile calendar page - if (Session::getLocalUser() === $owner_uid) { + if (DI::userSession()->getLocalUserId() === $owner_uid) { $return_path = "events"; } else { $return_path = "cal/" . $nick; diff --git a/mod/display.php b/mod/display.php index fd508fcfc..41c4cc3b9 100644 --- a/mod/display.php +++ b/mod/display.php @@ -24,7 +24,6 @@ use Friendica\Content\Text\BBCode; use Friendica\Content\Widget; use Friendica\Core\Logger; use Friendica\Core\Renderer; -use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; @@ -46,14 +45,14 @@ function display_init(App $a) (new Objects(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), $_SERVER, ['guid' => DI::args()->getArgv()[1] ?? null]))->run(); } - if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) { + if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) { return; } $nick = ((DI::args()->getArgc() > 1) ? DI::args()->getArgv()[1] : ''); $item = null; - $item_user = Session::getLocalUser(); + $item_user = DI::userSession()->getLocalUserId(); $fields = ['uri-id', 'parent-uri-id', 'author-id', 'author-link', 'body', 'uid', 'guid', 'gravity']; @@ -62,18 +61,18 @@ function display_init(App $a) $nick = ''; // Does the local user have this item? - if (Session::getLocalUser()) { - $item = Post::selectFirstForUser(Session::getLocalUser(), $fields, ['guid' => DI::args()->getArgv()[1], 'uid' => Session::getLocalUser()]); + if (DI::userSession()->getLocalUserId()) { + $item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), $fields, ['guid' => DI::args()->getArgv()[1], 'uid' => DI::userSession()->getLocalUserId()]); if (DBA::isResult($item)) { $nick = $a->getLoggedInUserNickname(); } } // Is this item private but could be visible to the remove visitor? - if (!DBA::isResult($item) && Session::getRemoteUser()) { + if (!DBA::isResult($item) && DI::userSession()->getRemoteUserId()) { $item = Post::selectFirst($fields, ['guid' => DI::args()->getArgv()[1], 'private' => Item::PRIVATE, 'origin' => true]); if (DBA::isResult($item)) { - if (!Contact::isFollower(Session::getRemoteUser(), $item['uid'])) { + if (!Contact::isFollower(DI::userSession()->getRemoteUserId(), $item['uid'])) { $item = null; } else { $item_user = $item['uid']; @@ -83,14 +82,14 @@ function display_init(App $a) // Is it an item with uid=0? if (!DBA::isResult($item)) { - $item = Post::selectFirstForUser(Session::getLocalUser(), $fields, ['guid' => DI::args()->getArgv()[1], 'private' => [Item::PUBLIC, Item::UNLISTED], 'uid' => 0]); + $item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), $fields, ['guid' => DI::args()->getArgv()[1], 'private' => [Item::PUBLIC, Item::UNLISTED], 'uid' => 0]); } } elseif (DI::args()->getArgc() >= 3 && $nick == 'feed-item') { $uri_id = DI::args()->getArgv()[2]; if (substr($uri_id, -5) == '.atom') { $uri_id = substr($uri_id, 0, -5); } - $item = Post::selectFirstForUser(Session::getLocalUser(), $fields, ['uri-id' => $uri_id, 'private' => [Item::PUBLIC, Item::UNLISTED], 'uid' => 0]); + $item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), $fields, ['uri-id' => $uri_id, 'private' => [Item::PUBLIC, Item::UNLISTED], 'uid' => 0]); } if (!DBA::isResult($item)) { @@ -125,7 +124,7 @@ function display_fetchauthor($item) { $shared = Item::getShareArray($item); if (empty($shared['comment']) && !empty($shared['guid']) && !empty($shared['profile'])) { - $contact = Contact::getByURLForUser($shared['profile'], Session::getLocalUser()); + $contact = Contact::getByURLForUser($shared['profile'], DI::userSession()->getLocalUserId()); } if (empty($contact)) { @@ -137,7 +136,7 @@ function display_fetchauthor($item) function display_content(App $a, $update = false, $update_uid = 0) { - if (DI::config()->get('system','block_public') && !Session::isAuthenticated()) { + if (DI::config()->get('system','block_public') && !DI::userSession()->isAuthenticated()) { throw new HTTPException\ForbiddenException(DI::l10n()->t('Public access denied.')); } @@ -179,18 +178,18 @@ function display_content(App $a, $update = false, $update_uid = 0) if (DI::args()->getArgc() == 2) { $fields = ['uri-id', 'parent-uri-id', 'uid']; - if (Session::getLocalUser()) { - $condition = ['guid' => DI::args()->getArgv()[1], 'uid' => [0, Session::getLocalUser()]]; - $item = Post::selectFirstForUser(Session::getLocalUser(), $fields, $condition, ['order' => ['uid' => true]]); + if (DI::userSession()->getLocalUserId()) { + $condition = ['guid' => DI::args()->getArgv()[1], 'uid' => [0, DI::userSession()->getLocalUserId()]]; + $item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), $fields, $condition, ['order' => ['uid' => true]]); if (DBA::isResult($item)) { $uri_id = $item['uri-id']; $parent_uri_id = $item['parent-uri-id']; } } - if (($parent_uri_id == 0) && Session::getRemoteUser()) { + if (($parent_uri_id == 0) && DI::userSession()->getRemoteUserId()) { $item = Post::selectFirst($fields, ['guid' => DI::args()->getArgv()[1], 'private' => Item::PRIVATE, 'origin' => true]); - if (DBA::isResult($item) && Contact::isFollower(Session::getRemoteUser(), $item['uid'])) { + if (DBA::isResult($item) && Contact::isFollower(DI::userSession()->getRemoteUserId(), $item['uid'])) { $uri_id = $item['uri-id']; $parent_uri_id = $item['parent-uri-id']; } @@ -198,7 +197,7 @@ function display_content(App $a, $update = false, $update_uid = 0) if ($parent_uri_id == 0) { $condition = ['private' => [Item::PUBLIC, Item::UNLISTED], 'guid' => DI::args()->getArgv()[1], 'uid' => 0]; - $item = Post::selectFirstForUser(Session::getLocalUser(), $fields, $condition); + $item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), $fields, $condition); if (DBA::isResult($item)) { $uri_id = $item['uri-id']; $parent_uri_id = $item['parent-uri-id']; @@ -211,9 +210,9 @@ function display_content(App $a, $update = false, $update_uid = 0) throw new HTTPException\NotFoundException(DI::l10n()->t('The requested item doesn\'t exist or has been deleted.')); } - if (!DI::pConfig()->get(Session::getLocalUser(), 'system', 'detailed_notif')) { - DI::notification()->setAllSeenForUser(Session::getLocalUser(), ['parent-uri-id' => $item['parent-uri-id']]); - DI::notify()->setAllSeenForUser(Session::getLocalUser(), ['parent-uri-id' => $item['parent-uri-id']]); + if (!DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'detailed_notif')) { + DI::notification()->setAllSeenForUser(DI::userSession()->getLocalUserId(), ['parent-uri-id' => $item['parent-uri-id']]); + DI::notify()->setAllSeenForUser(DI::userSession()->getLocalUserId(), ['parent-uri-id' => $item['parent-uri-id']]); } // We are displaying an "alternate" link if that post was public. See issue 2864 @@ -232,17 +231,17 @@ function display_content(App $a, $update = false, $update_uid = 0) '$conversation' => $conversation]); $is_remote_contact = false; - $item_uid = Session::getLocalUser(); + $item_uid = DI::userSession()->getLocalUserId(); $page_uid = 0; $parent = null; - if (!Session::getLocalUser() && !empty($parent_uri_id)) { + if (!DI::userSession()->getLocalUserId() && !empty($parent_uri_id)) { $parent = Post::selectFirst(['uid'], ['uri-id' => $parent_uri_id, 'wall' => true]); } if (DBA::isResult($parent)) { $page_uid = $page_uid ?? 0 ?: $parent['uid']; - $is_remote_contact = Session::getRemoteContactID($page_uid); + $is_remote_contact = DI::userSession()->getRemoteContactID($page_uid); if ($is_remote_contact) { $item_uid = $parent['uid']; } @@ -250,11 +249,11 @@ function display_content(App $a, $update = false, $update_uid = 0) $page_uid = $item['uid']; } - if (!empty($page_uid) && ($page_uid != Session::getLocalUser())) { + if (!empty($page_uid) && ($page_uid != DI::userSession()->getLocalUserId())) { $page_user = User::getById($page_uid); } - $is_owner = Session::getLocalUser() && (in_array($page_uid, [Session::getLocalUser(), 0])); + $is_owner = DI::userSession()->getLocalUserId() && (in_array($page_uid, [DI::userSession()->getLocalUserId(), 0])); if (!empty($page_user['hidewall']) && !$is_owner && !$is_remote_contact) { throw new HTTPException\ForbiddenException(DI::l10n()->t('Access to this profile has been restricted.')); @@ -266,8 +265,8 @@ function display_content(App $a, $update = false, $update_uid = 0) } $sql_extra = Item::getPermissionsSQLByUserId($page_uid); - if (Session::getLocalUser() && (Session::getLocalUser() == $page_uid)) { - $condition = ['parent-uri-id' => $parent_uri_id, 'uid' => Session::getLocalUser(), 'unseen' => true]; + if (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserId() == $page_uid)) { + $condition = ['parent-uri-id' => $parent_uri_id, 'uid' => DI::userSession()->getLocalUserId(), 'unseen' => true]; $unseen = Post::exists($condition); } else { $unseen = false; @@ -288,11 +287,11 @@ function display_content(App $a, $update = false, $update_uid = 0) $item['uri-id'] = $item['parent-uri-id']; if ($unseen) { - $condition = ['parent-uri-id' => $parent_uri_id, 'uid' => Session::getLocalUser(), 'unseen' => true]; + $condition = ['parent-uri-id' => $parent_uri_id, 'uid' => DI::userSession()->getLocalUserId(), 'unseen' => true]; Item::update(['unseen' => false], $condition); } - if (!$update && Session::getLocalUser()) { + if (!$update && DI::userSession()->getLocalUserId()) { $o .= ""; } diff --git a/mod/editpost.php b/mod/editpost.php index 8b25f66be..bec5d3449 100644 --- a/mod/editpost.php +++ b/mod/editpost.php @@ -23,7 +23,6 @@ use Friendica\App; use Friendica\Content\Feature; use Friendica\Core\Hook; use Friendica\Core\Renderer; -use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; @@ -35,7 +34,7 @@ function editpost_content(App $a) { $o = ''; - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); return; } @@ -50,14 +49,14 @@ function editpost_content(App $a) $fields = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'body', 'title', 'uri-id', 'wall', 'post-type', 'guid']; - $item = Post::selectFirstForUser(Session::getLocalUser(), $fields, ['id' => $post_id, 'uid' => Session::getLocalUser()]); + $item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), $fields, ['id' => $post_id, 'uid' => DI::userSession()->getLocalUserId()]); if (!DBA::isResult($item)) { DI::sysmsg()->addNotice(DI::l10n()->t('Item not found')); return; } - $user = User::getById(Session::getLocalUser()); + $user = User::getById(DI::userSession()->getLocalUserId()); $geotag = ''; @@ -119,8 +118,8 @@ function editpost_content(App $a) '$jotnets' => $jotnets, '$title' => $item['title'], '$placeholdertitle' => DI::l10n()->t('Set title'), - '$category' => Post\Category::getCSVByURIId($item['uri-id'], Session::getLocalUser(), Post\Category::CATEGORY), - '$placeholdercategory' => (Feature::isEnabled(Session::getLocalUser(),'categories') ? DI::l10n()->t("Categories \x28comma-separated list\x29") : ''), + '$category' => Post\Category::getCSVByURIId($item['uri-id'], DI::userSession()->getLocalUserId(), Post\Category::CATEGORY), + '$placeholdercategory' => (Feature::isEnabled(DI::userSession()->getLocalUserId(),'categories') ? DI::l10n()->t("Categories \x28comma-separated list\x29") : ''), '$emtitle' => DI::l10n()->t('Example: bob@example.com, mary@example.com'), '$lockstate' => $lockstate, '$acl' => '', // populate_acl((($group) ? $group_acl : $a->user)), diff --git a/mod/events.php b/mod/events.php index ac2a08afc..b87120672 100644 --- a/mod/events.php +++ b/mod/events.php @@ -27,7 +27,6 @@ use Friendica\Core\ACL; use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\Renderer; -use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Core\Theme; use Friendica\Core\Worker; @@ -47,7 +46,7 @@ use Friendica\Worker\Delivery; function events_init(App $a) { - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { return; } @@ -55,7 +54,7 @@ function events_init(App $a) DI::page()['aside'] = ''; } - $cal_widget = CalendarExport::getHTML(Session::getLocalUser()); + $cal_widget = CalendarExport::getHTML(DI::userSession()->getLocalUserId()); DI::page()['aside'] .= $cal_widget; @@ -65,13 +64,13 @@ function events_init(App $a) function events_post(App $a) { Logger::debug('post', ['request' => $_REQUEST]); - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { return; } $event_id = !empty($_POST['event_id']) ? intval($_POST['event_id']) : 0; $cid = !empty($_POST['cid']) ? intval($_POST['cid']) : 0; - $uid = Session::getLocalUser(); + $uid = DI::userSession()->getLocalUserId(); $start_text = Strings::escapeHtml($_REQUEST['start_text'] ?? ''); $finish_text = Strings::escapeHtml($_REQUEST['finish_text'] ?? ''); @@ -215,7 +214,7 @@ function events_post(App $a) function events_content(App $a) { - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); return Login::form(); } @@ -225,11 +224,11 @@ function events_content(App $a) } if ((DI::args()->getArgc() > 2) && (DI::args()->getArgv()[1] === 'ignore') && intval(DI::args()->getArgv()[2])) { - DBA::update('event', ['ignore' => true], ['id' => DI::args()->getArgv()[2], 'uid' => Session::getLocalUser()]); + DBA::update('event', ['ignore' => true], ['id' => DI::args()->getArgv()[2], 'uid' => DI::userSession()->getLocalUserId()]); } if ((DI::args()->getArgc() > 2) && (DI::args()->getArgv()[1] === 'unignore') && intval(DI::args()->getArgv()[2])) { - DBA::update('event', ['ignore' => false], ['id' => DI::args()->getArgv()[2], 'uid' => Session::getLocalUser()]); + DBA::update('event', ['ignore' => false], ['id' => DI::args()->getArgv()[2], 'uid' => DI::userSession()->getLocalUserId()]); } if ($a->getThemeInfoValue('events_in_profile')) { @@ -324,9 +323,9 @@ function events_content(App $a) // get events by id or by date if ($event_params['event_id']) { - $r = Event::getListById(Session::getLocalUser(), $event_params['event_id']); + $r = Event::getListById(DI::userSession()->getLocalUserId(), $event_params['event_id']); } else { - $r = Event::getListByDate(Session::getLocalUser(), $event_params); + $r = Event::getListByDate(DI::userSession()->getLocalUserId(), $event_params); } $links = []; @@ -397,7 +396,7 @@ function events_content(App $a) } if (($mode === 'edit' || $mode === 'copy') && $event_id) { - $orig_event = DBA::selectFirst('event', [], ['id' => $event_id, 'uid' => Session::getLocalUser()]); + $orig_event = DBA::selectFirst('event', [], ['id' => $event_id, 'uid' => DI::userSession()->getLocalUserId()]); } // Passed parameters overrides anything found in the DB @@ -406,8 +405,8 @@ function events_content(App $a) $share_disabled = ''; if (empty($orig_event)) { - $orig_event = User::getById(Session::getLocalUser(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']);; - } elseif ($orig_event['allow_cid'] !== '<' . Session::getLocalUser() . '>' + $orig_event = User::getById(DI::userSession()->getLocalUserId(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']);; + } elseif ($orig_event['allow_cid'] !== '<' . DI::userSession()->getLocalUserId() . '>' || $orig_event['allow_gid'] || $orig_event['deny_cid'] || $orig_event['deny_gid']) { @@ -525,11 +524,11 @@ function events_content(App $a) // Remove an event from the calendar and its related items if ($mode === 'drop' && $event_id) { - $ev = Event::getListById(Session::getLocalUser(), $event_id); + $ev = Event::getListById(DI::userSession()->getLocalUserId(), $event_id); // Delete only real events (no birthdays) if (DBA::isResult($ev) && $ev[0]['type'] == 'event') { - Item::deleteForUser(['id' => $ev[0]['itemid']], Session::getLocalUser()); + Item::deleteForUser(['id' => $ev[0]['itemid']], DI::userSession()->getLocalUserId()); } if (Post::exists(['id' => $ev[0]['itemid']])) { diff --git a/mod/fbrowser.php b/mod/fbrowser.php index a2457575a..952ab1452 100644 --- a/mod/fbrowser.php +++ b/mod/fbrowser.php @@ -24,7 +24,6 @@ use Friendica\App; use Friendica\Core\Renderer; -use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; @@ -39,7 +38,7 @@ use Friendica\Util\Strings; */ function fbrowser_content(App $a) { - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { System::exit(); } @@ -66,7 +65,7 @@ function fbrowser_content(App $a) if (DI::args()->getArgc() == 2) { $photos = DBA::toArray(DBA::p("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = ? AND NOT `photo-type` IN (?, ?)", - Session::getLocalUser(), + DI::userSession()->getLocalUserId(), Photo::CONTACT_AVATAR, Photo::CONTACT_BANNER )); @@ -85,7 +84,7 @@ function fbrowser_content(App $a) min(`scale`) AS `hiq`, max(`scale`) AS `loq`, ANY_VALUE(`desc`) AS `desc`, ANY_VALUE(`created`) AS `created` FROM `photo` WHERE `uid` = ? $sql_extra AND NOT `photo-type` IN (?, ?) GROUP BY `resource-id` $sql_extra2", - Session::getLocalUser(), + DI::userSession()->getLocalUserId(), Photo::CONTACT_AVATAR, Photo::CONTACT_BANNER )); @@ -125,7 +124,7 @@ function fbrowser_content(App $a) break; case "file": if (DI::args()->getArgc()==2) { - $files = DBA::selectToArray('attach', ['id', 'filename', 'filetype'], ['uid' => Session::getLocalUser()]); + $files = DBA::selectToArray('attach', ['id', 'filename', 'filetype'], ['uid' => DI::userSession()->getLocalUserId()]); function _map_files2($rr) { diff --git a/mod/follow.php b/mod/follow.php index 8e08d7a72..db7a52b2c 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -23,7 +23,6 @@ use Friendica\App; use Friendica\Content\Widget; use Friendica\Core\Protocol; use Friendica\Core\Renderer; -use Friendica\Core\Session; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Profile; @@ -36,7 +35,7 @@ use Friendica\Util\Strings; function follow_post(App $a) { - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { throw new \Friendica\Network\HTTPException\ForbiddenException(DI::l10n()->t('Access denied.')); } @@ -53,13 +52,13 @@ function follow_content(App $a) { $return_path = 'contact'; - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); DI::baseUrl()->redirect($return_path); // NOTREACHED } - $uid = Session::getLocalUser(); + $uid = DI::userSession()->getLocalUserId(); $url = Probe::cleanURI(trim($_REQUEST['url'] ?? '')); @@ -196,7 +195,7 @@ function follow_process(App $a, string $url) function follow_remote_item($url) { - $item_id = Item::fetchByLink($url, Session::getLocalUser()); + $item_id = Item::fetchByLink($url, DI::userSession()->getLocalUserId()); if (!$item_id) { // If the user-specific search failed, we search and probe a public post $item_id = Item::fetchByLink($url); diff --git a/mod/item.php b/mod/item.php index e36853acc..f30798fa3 100644 --- a/mod/item.php +++ b/mod/item.php @@ -34,7 +34,6 @@ use Friendica\Content\Text\BBCode; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\Protocol; -use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; @@ -58,11 +57,11 @@ use Friendica\Util\DateTimeFormat; use Friendica\Util\ParseUrl; function item_post(App $a) { - if (!Session::isAuthenticated()) { + if (!DI::userSession()->isAuthenticated()) { throw new HTTPException\ForbiddenException(); } - $uid = Session::getLocalUser(); + $uid = DI::userSession()->getLocalUserId(); if (!empty($_REQUEST['dropitems'])) { $arr_drop = explode(',', $_REQUEST['dropitems']); @@ -107,7 +106,7 @@ function item_post(App $a) { $toplevel_user_id = null; $objecttype = null; - $profile_uid = ($_REQUEST['profile_uid'] ?? 0) ?: Session::getLocalUser(); + $profile_uid = ($_REQUEST['profile_uid'] ?? 0) ?: DI::userSession()->getLocalUserId(); $posttype = ($_REQUEST['post_type'] ?? '') ?: Item::PT_ARTICLE; if ($parent_item_id || $thr_parent_uri) { @@ -139,7 +138,7 @@ function item_post(App $a) { // When commenting on a public post then store the post for the current user // This enables interaction like starring and saving into folders if ($toplevel_item['uid'] == 0) { - $stored = Item::storeForUserByUriId($toplevel_item['uri-id'], Session::getLocalUser(), ['post-reason' => Item::PR_ACTIVITY]); + $stored = Item::storeForUserByUriId($toplevel_item['uri-id'], DI::userSession()->getLocalUserId(), ['post-reason' => Item::PR_ACTIVITY]); Logger::info('Public item stored for user', ['uri-id' => $toplevel_item['uri-id'], 'uid' => $uid, 'stored' => $stored]); if ($stored) { $toplevel_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $stored]); @@ -169,16 +168,16 @@ function item_post(App $a) { } // Ensure that the user id in a thread always stay the same - if (!is_null($toplevel_user_id) && in_array($toplevel_user_id, [Session::getLocalUser(), 0])) { + if (!is_null($toplevel_user_id) && in_array($toplevel_user_id, [DI::userSession()->getLocalUserId(), 0])) { $profile_uid = $toplevel_user_id; } // Allow commenting if it is an answer to a public post - $allow_comment = Session::getLocalUser() && $toplevel_item_id && in_array($toplevel_item['private'], [Item::PUBLIC, Item::UNLISTED]) && in_array($toplevel_item['network'], Protocol::FEDERATED); + $allow_comment = DI::userSession()->getLocalUserId() && $toplevel_item_id && in_array($toplevel_item['private'], [Item::PUBLIC, Item::UNLISTED]) && in_array($toplevel_item['network'], Protocol::FEDERATED); // Now check that valid personal details have been provided if (!Security::canWriteToUserWall($profile_uid) && !$allow_comment) { - Logger::warning('Permission denied.', ['local' => Session::getLocalUser(), 'profile_uid' => $profile_uid, 'toplevel_item_id' => $toplevel_item_id, 'network' => $toplevel_item['network']]); + Logger::warning('Permission denied.', ['local' => DI::userSession()->getLocalUserId(), 'profile_uid' => $profile_uid, 'toplevel_item_id' => $toplevel_item_id, 'network' => $toplevel_item['network']]); DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); if ($return_path) { DI::baseUrl()->redirect($return_path); @@ -324,9 +323,9 @@ function item_post(App $a) { $pubmail_enabled = ($_REQUEST['pubmail_enable'] ?? false) && !$private; // if using the API, we won't see pubmail_enable - figure out if it should be set - if ($api_source && $profile_uid && $profile_uid == Session::getLocalUser() && !$private) { + if ($api_source && $profile_uid && $profile_uid == DI::userSession()->getLocalUserId() && !$private) { if (function_exists('imap_open') && !DI::config()->get('system', 'imap_disabled')) { - $pubmail_enabled = DBA::exists('mailacct', ["`uid` = ? AND `server` != ? AND `pubmail`", Session::getLocalUser(), '']); + $pubmail_enabled = DBA::exists('mailacct', ["`uid` = ? AND `server` != ? AND `pubmail`", DI::userSession()->getLocalUserId(), '']); } } @@ -363,11 +362,11 @@ function item_post(App $a) { $self = false; $contact_id = 0; - if (Session::getLocalUser() && ((Session::getLocalUser() == $profile_uid) || $allow_comment)) { + if (DI::userSession()->getLocalUserId() && ((DI::userSession()->getLocalUserId() == $profile_uid) || $allow_comment)) { $self = true; - $author = DBA::selectFirst('contact', [], ['uid' => Session::getLocalUser(), 'self' => true]); - } elseif (!empty(Session::getRemoteContactID($profile_uid))) { - $author = DBA::selectFirst('contact', [], ['id' => Session::getRemoteContactID($profile_uid)]); + $author = DBA::selectFirst('contact', [], ['uid' => DI::userSession()->getLocalUserId(), 'self' => true]); + } elseif (!empty(DI::userSession()->getRemoteContactID($profile_uid))) { + $author = DBA::selectFirst('contact', [], ['id' => DI::userSession()->getRemoteContactID($profile_uid)]); } if (DBA::isResult($author)) { @@ -375,7 +374,7 @@ function item_post(App $a) { } // get contact info for owner - if ($profile_uid == Session::getLocalUser() || $allow_comment) { + if ($profile_uid == DI::userSession()->getLocalUserId() || $allow_comment) { $contact_record = $author ?: []; } else { $contact_record = DBA::selectFirst('contact', [], ['uid' => $profile_uid, 'self' => true]) ?: []; @@ -385,7 +384,7 @@ function item_post(App $a) { if ($posttype != Item::PT_PERSONAL_NOTE) { // Look for any tags and linkify them $item = [ - 'uid' => Session::getLocalUser() ? Session::getLocalUser() : $profile_uid, + 'uid' => DI::userSession()->getLocalUserId() ? DI::userSession()->getLocalUserId() : $profile_uid, 'gravity' => $toplevel_item_id ? Item::GRAVITY_COMMENT : Item::GRAVITY_PARENT, 'network' => $network, 'body' => $body, @@ -734,7 +733,7 @@ function item_post(App $a) { Hook::callAll('post_local_end', $datarray); - if (strlen($emailcc) && $profile_uid == Session::getLocalUser()) { + if (strlen($emailcc) && $profile_uid == DI::userSession()->getLocalUserId()) { $recipients = explode(',', $emailcc); if (count($recipients)) { foreach ($recipients as $recipient) { @@ -780,7 +779,7 @@ function item_post_return($baseurl, $api_source, $return_path) function item_content(App $a) { - if (!Session::isAuthenticated()) { + if (!DI::userSession()->isAuthenticated()) { throw new HTTPException\UnauthorizedException(); } @@ -794,9 +793,9 @@ function item_content(App $a) switch ($args->get(1)) { case 'drop': if (DI::mode()->isAjax()) { - Item::deleteForUser(['id' => $args->get(2)], Session::getLocalUser()); + Item::deleteForUser(['id' => $args->get(2)], DI::userSession()->getLocalUserId()); // ajax return: [, 0 (no perm) | ] - System::jsonExit([intval($args->get(2)), Session::getLocalUser()]); + System::jsonExit([intval($args->get(2)), DI::userSession()->getLocalUserId()]); } else { if (!empty($args->get(3))) { $o = drop_item($args->get(2), $args->get(3)); @@ -807,16 +806,16 @@ function item_content(App $a) break; case 'block': - $item = Post::selectFirstForUser(Session::getLocalUser(), ['guid', 'author-id', 'parent', 'gravity'], ['id' => $args->get(2)]); + $item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), ['guid', 'author-id', 'parent', 'gravity'], ['id' => $args->get(2)]); if (empty($item['author-id'])) { throw new HTTPException\NotFoundException('Item not found'); } - Contact\User::setBlocked($item['author-id'], Session::getLocalUser(), true); + Contact\User::setBlocked($item['author-id'], DI::userSession()->getLocalUserId(), true); if (DI::mode()->isAjax()) { // ajax return: [, 0 (no perm) | ] - System::jsonExit([intval($args->get(2)), Session::getLocalUser()]); + System::jsonExit([intval($args->get(2)), DI::userSession()->getLocalUserId()]); } else { item_redirect_after_action($item, $args->get(3)); } @@ -835,7 +834,7 @@ function item_content(App $a) function drop_item(int $id, string $return = ''): string { // Locate item to be deleted - $item = Post::selectFirstForUser(Session::getLocalUser(), ['id', 'uid', 'guid', 'contact-id', 'deleted', 'gravity', 'parent'], ['id' => $id]); + $item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), ['id', 'uid', 'guid', 'contact-id', 'deleted', 'gravity', 'parent'], ['id' => $id]); if (!DBA::isResult($item)) { DI::sysmsg()->addNotice(DI::l10n()->t('Item not found.')); @@ -850,18 +849,18 @@ function drop_item(int $id, string $return = ''): string $contact_id = 0; // check if logged in user is either the author or owner of this item - if (Session::getRemoteContactID($item['uid']) == $item['contact-id']) { + if (DI::userSession()->getRemoteContactID($item['uid']) == $item['contact-id']) { $contact_id = $item['contact-id']; } - if ((Session::getLocalUser() == $item['uid']) || $contact_id) { + if ((DI::userSession()->getLocalUserId() == $item['uid']) || $contact_id) { // delete the item - Item::deleteForUser(['id' => $item['id']], Session::getLocalUser()); + Item::deleteForUser(['id' => $item['id']], DI::userSession()->getLocalUserId()); item_redirect_after_action($item, $return); //NOTREACHED } else { - Logger::warning('Permission denied.', ['local' => Session::getLocalUser(), 'uid' => $item['uid'], 'cid' => $contact_id]); + Logger::warning('Permission denied.', ['local' => DI::userSession()->getLocalUserId(), 'uid' => $item['uid'], 'cid' => $contact_id]); DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); DI::baseUrl()->redirect('display/' . $item['guid']); //NOTREACHED @@ -880,7 +879,7 @@ function item_redirect_after_action(array $item, string $returnUrlHex) // Check if delete a comment if ($item['gravity'] == Item::GRAVITY_COMMENT) { if (!empty($item['parent'])) { - $parentitem = Post::selectFirstForUser(Session::getLocalUser(), ['guid'], ['id' => $item['parent']]); + $parentitem = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), ['guid'], ['id' => $item['parent']]); } // Return to parent guid diff --git a/mod/match.php b/mod/match.php index 860d60f56..e8a0a6605 100644 --- a/mod/match.php +++ b/mod/match.php @@ -23,7 +23,6 @@ use Friendica\App; use Friendica\Content\Widget; use Friendica\Core\Renderer; use Friendica\Core\Search; -use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; @@ -45,7 +44,7 @@ use Friendica\Module\Contact as ModuleContact; */ function match_content(App $a) { - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { return ''; } @@ -54,7 +53,7 @@ function match_content(App $a) $_SESSION['return_path'] = DI::args()->getCommand(); - $profile = Profile::getByUID(Session::getLocalUser()); + $profile = Profile::getByUID(DI::userSession()->getLocalUserId()); if (!DBA::isResult($profile)) { return ''; @@ -68,10 +67,10 @@ function match_content(App $a) $tags = trim($profile['pub_keywords'] . ' ' . $profile['prv_keywords']); if (DI::mode()->isMobile()) { - $limit = DI::pConfig()->get(Session::getLocalUser(), 'system', 'itemspage_mobile_network', + $limit = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network', DI::config()->get('system', 'itemspage_network_mobile')); } else { - $limit = DI::pConfig()->get(Session::getLocalUser(), 'system', 'itemspage_network', + $limit = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network', DI::config()->get('system', 'itemspage_network')); } @@ -115,12 +114,12 @@ function match_get_contacts($msearch, $entries, $limit) } // Already known contact - $contact = Contact::getByURL($profile->url, null, ['rel'], Session::getLocalUser()); + $contact = Contact::getByURL($profile->url, null, ['rel'], DI::userSession()->getLocalUserId()); if (!empty($contact) && in_array($contact['rel'], [Contact::FRIEND, Contact::SHARING])) { continue; } - $contact = Contact::getByURLForUser($profile->url, Session::getLocalUser()); + $contact = Contact::getByURLForUser($profile->url, DI::userSession()->getLocalUserId()); if (!empty($contact)) { $entries[$contact['id']] = ModuleContact::getContactTemplateVars($contact); } diff --git a/mod/message.php b/mod/message.php index 8d379f4e9..794d2ace4 100644 --- a/mod/message.php +++ b/mod/message.php @@ -25,7 +25,6 @@ use Friendica\Content\Pager; use Friendica\Content\Text\BBCode; use Friendica\Core\ACL; use Friendica\Core\Renderer; -use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; @@ -40,7 +39,7 @@ function message_init(App $a) $tabs = ''; if (DI::args()->getArgc() > 1 && is_numeric(DI::args()->getArgv()[1])) { - $tabs = render_messages(get_messages(Session::getLocalUser(), 0, 5), 'mail_list.tpl'); + $tabs = render_messages(get_messages(DI::userSession()->getLocalUserId(), 0, 5), 'mail_list.tpl'); } $new = [ @@ -66,7 +65,7 @@ function message_init(App $a) function message_post(App $a) { - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); return; } @@ -111,7 +110,7 @@ function message_content(App $a) $o = ''; Nav::setSelected('messages'); - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); return Login::form(); } @@ -145,28 +144,28 @@ function message_content(App $a) $cmd = DI::args()->getArgv()[1]; if ($cmd === 'drop') { - $message = DBA::selectFirst('mail', ['convid'], ['id' => DI::args()->getArgv()[2], 'uid' => Session::getLocalUser()]); + $message = DBA::selectFirst('mail', ['convid'], ['id' => DI::args()->getArgv()[2], 'uid' => DI::userSession()->getLocalUserId()]); if(!DBA::isResult($message)){ DI::sysmsg()->addNotice(DI::l10n()->t('Conversation not found.')); DI::baseUrl()->redirect('message'); } - if (!DBA::delete('mail', ['id' => DI::args()->getArgv()[2], 'uid' => Session::getLocalUser()])) { + if (!DBA::delete('mail', ['id' => DI::args()->getArgv()[2], 'uid' => DI::userSession()->getLocalUserId()])) { DI::sysmsg()->addNotice(DI::l10n()->t('Message was not deleted.')); } - $conversation = DBA::selectFirst('mail', ['id'], ['convid' => $message['convid'], 'uid' => Session::getLocalUser()]); + $conversation = DBA::selectFirst('mail', ['id'], ['convid' => $message['convid'], 'uid' => DI::userSession()->getLocalUserId()]); if(!DBA::isResult($conversation)){ DI::baseUrl()->redirect('message'); } DI::baseUrl()->redirect('message/' . $conversation['id'] ); } else { - $parentmail = DBA::selectFirst('mail', ['parent-uri'], ['id' => DI::args()->getArgv()[2], 'uid' => Session::getLocalUser()]); + $parentmail = DBA::selectFirst('mail', ['parent-uri'], ['id' => DI::args()->getArgv()[2], 'uid' => DI::userSession()->getLocalUserId()]); if (DBA::isResult($parentmail)) { $parent = $parentmail['parent-uri']; - if (!DBA::delete('mail', ['parent-uri' => $parent, 'uid' => Session::getLocalUser()])) { + if (!DBA::delete('mail', ['parent-uri' => $parent, 'uid' => DI::userSession()->getLocalUserId()])) { DI::sysmsg()->addNotice(DI::l10n()->t('Conversation was not removed.')); } } @@ -216,11 +215,11 @@ function message_content(App $a) $o .= $header; - $total = DBA::count('mail', ['uid' => Session::getLocalUser()], ['distinct' => true, 'expression' => 'parent-uri']); + $total = DBA::count('mail', ['uid' => DI::userSession()->getLocalUserId()], ['distinct' => true, 'expression' => 'parent-uri']); $pager = new Pager(DI::l10n(), DI::args()->getQueryString()); - $r = get_messages(Session::getLocalUser(), $pager->getStart(), $pager->getItemsPerPage()); + $r = get_messages(DI::userSession()->getLocalUserId(), $pager->getStart(), $pager->getItemsPerPage()); if (!DBA::isResult($r)) { DI::sysmsg()->addNotice(DI::l10n()->t('No messages.')); @@ -244,14 +243,14 @@ function message_content(App $a) LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id` WHERE `mail`.`uid` = ? AND `mail`.`id` = ? LIMIT 1", - Session::getLocalUser(), + DI::userSession()->getLocalUserId(), DI::args()->getArgv()[1] ); if (DBA::isResult($message)) { $contact_id = $message['contact-id']; $params = [ - Session::getLocalUser(), + DI::userSession()->getLocalUserId(), $message['parent-uri'] ]; @@ -273,7 +272,7 @@ function message_content(App $a) $messages = DBA::toArray($messages_stmt); - DBA::update('mail', ['seen' => 1], ['parent-uri' => $message['parent-uri'], 'uid' => Session::getLocalUser()]); + DBA::update('mail', ['seen' => 1], ['parent-uri' => $message['parent-uri'], 'uid' => DI::userSession()->getLocalUserId()]); } else { $messages = false; } diff --git a/mod/notes.php b/mod/notes.php index 9363e51b8..39649d81f 100644 --- a/mod/notes.php +++ b/mod/notes.php @@ -22,7 +22,6 @@ use Friendica\App; use Friendica\Content\Nav; use Friendica\Content\Pager; -use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Item; @@ -31,7 +30,7 @@ use Friendica\Module\BaseProfile; function notes_init(App $a) { - if (! Session::getLocalUser()) { + if (! DI::userSession()->getLocalUserId()) { return; } @@ -41,7 +40,7 @@ function notes_init(App $a) function notes_content(App $a, bool $update = false) { - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); return; } @@ -53,7 +52,7 @@ function notes_content(App $a, bool $update = false) $x = [ 'lockstate' => 'lock', - 'acl' => \Friendica\Core\ACL::getSelfOnlyHTML(Session::getLocalUser(), DI::l10n()->t('Personal notes are visible only by yourself.')), + 'acl' => \Friendica\Core\ACL::getSelfOnlyHTML(DI::userSession()->getLocalUserId(), DI::l10n()->t('Personal notes are visible only by yourself.')), 'button' => DI::l10n()->t('Save'), 'acl_data' => '', ]; @@ -61,14 +60,14 @@ function notes_content(App $a, bool $update = false) $o .= DI::conversation()->statusEditor($x, $a->getContactId()); } - $condition = ['uid' => Session::getLocalUser(), 'post-type' => Item::PT_PERSONAL_NOTE, 'gravity' => Item::GRAVITY_PARENT, + $condition = ['uid' => DI::userSession()->getLocalUserId(), 'post-type' => Item::PT_PERSONAL_NOTE, 'gravity' => Item::GRAVITY_PARENT, 'contact-id'=> $a->getContactId()]; if (DI::mode()->isMobile()) { - $itemsPerPage = DI::pConfig()->get(Session::getLocalUser(), 'system', 'itemspage_mobile_network', + $itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network', DI::config()->get('system', 'itemspage_network_mobile')); } else { - $itemsPerPage = DI::pConfig()->get(Session::getLocalUser(), 'system', 'itemspage_network', + $itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network', DI::config()->get('system', 'itemspage_network')); } @@ -76,7 +75,7 @@ function notes_content(App $a, bool $update = false) $params = ['order' => ['created' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; - $r = Post::selectThreadForUser(Session::getLocalUser(), ['uri-id'], $condition, $params); + $r = Post::selectThreadForUser(DI::userSession()->getLocalUserId(), ['uri-id'], $condition, $params); $count = 0; diff --git a/mod/oexchange.php b/mod/oexchange.php index 0970af2fd..dd3809bc7 100644 --- a/mod/oexchange.php +++ b/mod/oexchange.php @@ -22,7 +22,6 @@ use Friendica\App; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; -use Friendica\Core\Session; use Friendica\Core\System; use Friendica\DI; use Friendica\Module\Response; @@ -98,7 +97,7 @@ function oexchange_init(App $a) function oexchange_content(App $a) { - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { $o = Login::form(); return $o; } @@ -120,7 +119,7 @@ function oexchange_content(App $a) $post = []; - $post['profile_uid'] = Session::getLocalUser(); + $post['profile_uid'] = DI::userSession()->getLocalUserId(); $post['return'] = '/oexchange/done'; $post['body'] = HTML::toBBCode($s); diff --git a/mod/ostatus_subscribe.php b/mod/ostatus_subscribe.php index 50ff44569..5344ed845 100644 --- a/mod/ostatus_subscribe.php +++ b/mod/ostatus_subscribe.php @@ -21,7 +21,6 @@ use Friendica\App; use Friendica\Core\Protocol; -use Friendica\Core\Session; use Friendica\DI; use Friendica\Model\APContact; use Friendica\Model\Contact; @@ -30,7 +29,7 @@ use Friendica\Protocol\ActivityPub; function ostatus_subscribe_content(App $a): string { - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); DI::baseUrl()->redirect('ostatus_subscribe'); // NOTREACHED @@ -38,7 +37,7 @@ function ostatus_subscribe_content(App $a): string $o = '

' . DI::l10n()->t('Subscribing to contacts') . '

'; - $uid = Session::getLocalUser(); + $uid = DI::userSession()->getLocalUserId(); $counter = intval($_REQUEST['counter'] ?? 0); diff --git a/mod/photos.php b/mod/photos.php index f47456a0b..2d7516be9 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -30,7 +30,6 @@ use Friendica\Core\Addon; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\Renderer; -use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; @@ -57,7 +56,7 @@ use Friendica\Network\HTTPException; function photos_init(App $a) { - if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) { + if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) { return; } @@ -69,11 +68,11 @@ function photos_init(App $a) throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.')); } - $is_owner = (Session::getLocalUser() && (Session::getLocalUser() == $owner['uid'])); + $is_owner = (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserId() == $owner['uid'])); $albums = Photo::getAlbums($owner['uid']); - $albums_visible = ((intval($owner['hidewall']) && !Session::isAuthenticated()) ? false : true); + $albums_visible = ((intval($owner['hidewall']) && !DI::userSession()->isAuthenticated()) ? false : true); // add various encodings to the array so we can just loop through and pick them out in a template $ret = ['success' => false]; @@ -96,7 +95,7 @@ function photos_init(App $a) } } - if (Session::getLocalUser() && $owner['uid'] == Session::getLocalUser()) { + if (DI::userSession()->getLocalUserId() && $owner['uid'] == DI::userSession()->getLocalUserId()) { $can_post = true; } else { $can_post = false; @@ -148,10 +147,10 @@ function photos_post(App $a) $page_owner_uid = intval($user['uid']); $community_page = $user['page-flags'] == User::PAGE_FLAGS_COMMUNITY; - if (Session::getLocalUser() && (Session::getLocalUser() == $page_owner_uid)) { + if (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserId() == $page_owner_uid)) { $can_post = true; - } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) { - $contact_id = Session::getRemoteContactID($page_owner_uid); + } elseif ($community_page && !empty(DI::userSession()->getRemoteContactID($page_owner_uid))) { + $contact_id = DI::userSession()->getRemoteContactID($page_owner_uid); $can_post = true; $visitor = $contact_id; } @@ -229,7 +228,7 @@ function photos_post(App $a) )); } else { $r = DBA::toArray(DBA::p("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = ? AND `album` = ?", - Session::getLocalUser(), + DI::userSession()->getLocalUserId(), $album )); } @@ -268,7 +267,7 @@ function photos_post(App $a) $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => DI::args()->getArgv()[3]]; } else { - $condition = ['uid' => Session::getLocalUser(), 'resource-id' => DI::args()->getArgv()[3]]; + $condition = ['uid' => DI::userSession()->getLocalUserId(), 'resource-id' => DI::args()->getArgv()[3]]; } $photo = DBA::selectFirst('photo', ['resource-id'], $condition); @@ -794,7 +793,7 @@ function photos_content(App $a) throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.')); } - if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) { + if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) { DI::sysmsg()->addNotice(DI::l10n()->t('Public access denied.')); return; } @@ -840,10 +839,10 @@ function photos_content(App $a) $community_page = (($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false); - if (Session::getLocalUser() && (Session::getLocalUser() == $owner_uid)) { + if (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserId() == $owner_uid)) { $can_post = true; - } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) { - $contact_id = Session::getRemoteContactID($owner_uid); + } elseif ($community_page && !empty(DI::userSession()->getRemoteContactID($owner_uid))) { + $contact_id = DI::userSession()->getRemoteContactID($owner_uid); $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]); if (DBA::isResult($contact)) { @@ -854,21 +853,21 @@ function photos_content(App $a) } // perhaps they're visiting - but not a community page, so they wouldn't have write access - if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) { - $contact_id = Session::getRemoteContactID($owner_uid); + if (!empty(DI::userSession()->getRemoteContactID($owner_uid)) && !$visitor) { + $contact_id = DI::userSession()->getRemoteContactID($owner_uid); $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]); $remote_contact = DBA::isResult($contact); } - if (!$remote_contact && Session::getLocalUser()) { + if (!$remote_contact && DI::userSession()->getLocalUserId()) { $contact_id = $_SESSION['cid']; $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]); } - if ($user['hidewall'] && (Session::getLocalUser() != $owner_uid) && !$remote_contact) { + if ($user['hidewall'] && (DI::userSession()->getLocalUserId() != $owner_uid) && !$remote_contact) { DI::sysmsg()->addNotice(DI::l10n()->t('Access to this item is restricted.')); return; } @@ -878,7 +877,7 @@ function photos_content(App $a) $o = ""; // tabs - $is_owner = (Session::getLocalUser() && (Session::getLocalUser() == $owner_uid)); + $is_owner = (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserId() == $owner_uid)); $o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $user['nickname'], $profile['hide-friends']); // Display upload form @@ -1197,7 +1196,7 @@ function photos_content(App $a) } if ( - $ph[0]['uid'] == Session::getLocalUser() + $ph[0]['uid'] == DI::userSession()->getLocalUserId() && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) ) { $tools['lock'] = DI::l10n()->t('Private Photo'); @@ -1237,7 +1236,7 @@ function photos_content(App $a) $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; $items = Post::toArray(Post::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params)); - if (Session::getLocalUser() == $link_item['uid']) { + if (DI::userSession()->getLocalUserId() == $link_item['uid']) { Item::update(['unseen' => false], ['parent' => $link_item['parent']]); } } @@ -1315,7 +1314,7 @@ function photos_content(App $a) */ $qcomment = null; if (Addon::isEnabled('qcomment')) { - $words = DI::pConfig()->get(Session::getLocalUser(), 'qcomment', 'words'); + $words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'qcomment', 'words'); $qcomment = $words ? explode("\n", $words) : []; } @@ -1346,7 +1345,7 @@ function photos_content(App $a) 'attendmaybe' => [] ]; - if (DI::pConfig()->get(Session::getLocalUser(), 'system', 'hide_dislike')) { + if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'hide_dislike')) { unset($conv_responses['dislike']); } @@ -1371,7 +1370,7 @@ function photos_content(App $a) */ $qcomment = null; if (Addon::isEnabled('qcomment')) { - $words = DI::pConfig()->get(Session::getLocalUser(), 'qcomment', 'words'); + $words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'qcomment', 'words'); $qcomment = $words ? explode("\n", $words) : []; } @@ -1413,7 +1412,7 @@ function photos_content(App $a) $sparkle = ''; } - $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == Session::getLocalUser())); + $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == DI::userSession()->getLocalUserId())); $drop = [ 'dropping' => $dropping, 'pagedrop' => false, @@ -1445,7 +1444,7 @@ function photos_content(App $a) */ $qcomment = null; if (Addon::isEnabled('qcomment')) { - $words = DI::pConfig()->get(Session::getLocalUser(), 'qcomment', 'words'); + $words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'qcomment', 'words'); $qcomment = $words ? explode("\n", $words) : []; } @@ -1484,7 +1483,7 @@ function photos_content(App $a) '$dislike' => DI::l10n()->t('Dislike'), '$wait' => DI::l10n()->t('Please wait'), '$dislike_title' => DI::l10n()->t('I don\'t like this (toggle)'), - '$hide_dislike' => DI::pConfig()->get(Session::getLocalUser(), 'system', 'hide_dislike'), + '$hide_dislike' => DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'hide_dislike'), '$responses' => $responses, '$return_path' => DI::args()->getQueryString(), ]); diff --git a/mod/redir.php b/mod/redir.php index 6243710b2..903c6b2a3 100644 --- a/mod/redir.php +++ b/mod/redir.php @@ -21,7 +21,6 @@ use Friendica\App; use Friendica\Core\Logger; -use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; @@ -32,7 +31,7 @@ use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Util\Strings; function redir_init(App $a) { - if (!Session::isAuthenticated()) { + if (!DI::userSession()->isAuthenticated()) { throw new \Friendica\Network\HTTPException\ForbiddenException(DI::l10n()->t('Access denied.')); } @@ -52,7 +51,7 @@ function redir_init(App $a) { } $fields = ['id', 'uid', 'nurl', 'url', 'addr', 'name']; - $contact = DBA::selectFirst('contact', $fields, ['id' => $cid, 'uid' => [0, Session::getLocalUser()]]); + $contact = DBA::selectFirst('contact', $fields, ['id' => $cid, 'uid' => [0, DI::userSession()->getLocalUserId()]]); if (!DBA::isResult($contact)) { throw new \Friendica\Network\HTTPException\NotFoundException(DI::l10n()->t('Contact not found.')); } @@ -65,10 +64,10 @@ function redir_init(App $a) { $a->redirect($url ?: $contact_url); } - if ($contact['uid'] == 0 && Session::getLocalUser()) { + if ($contact['uid'] == 0 && DI::userSession()->getLocalUserId()) { // Let's have a look if there is an established connection // between the public contact we have found and the local user. - $contact = DBA::selectFirst('contact', $fields, ['nurl' => $contact['nurl'], 'uid' => Session::getLocalUser()]); + $contact = DBA::selectFirst('contact', $fields, ['nurl' => $contact['nurl'], 'uid' => DI::userSession()->getLocalUserId()]); if (DBA::isResult($contact)) { $cid = $contact['id']; @@ -83,7 +82,7 @@ function redir_init(App $a) { } } - if (Session::getRemoteUser()) { + if (DI::userSession()->getRemoteUserId()) { $host = substr(DI::baseUrl()->getUrlPath() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : ''), strpos(DI::baseUrl()->getUrlPath(), '://') + 3); $remotehost = substr($contact['addr'], strpos($contact['addr'], '@') + 1); @@ -91,7 +90,7 @@ function redir_init(App $a) { // with the local contact. Otherwise the local user would ask the local contact // for authentification everytime he/she is visiting a profile page of the local // contact. - if (($host == $remotehost) && (Session::getRemoteContactID(DI::session()->get('visitor_visiting')) == DI::session()->get('visitor_id'))) { + if (($host == $remotehost) && (DI::userSession()->getRemoteContactID(DI::session()->get('visitor_visiting')) == DI::session()->get('visitor_id'))) { // Remote user is already authenticated. redir_check_url($contact_url, $url); $target_url = $url ?: $contact_url; diff --git a/mod/removeme.php b/mod/removeme.php index 5555fcbb7..9ef372fed 100644 --- a/mod/removeme.php +++ b/mod/removeme.php @@ -21,7 +21,6 @@ use Friendica\App; use Friendica\Core\Renderer; -use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\User; @@ -29,11 +28,11 @@ use Friendica\Util\Strings; function removeme_post(App $a) { - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { return; } - if (!empty($_SESSION['submanage'])) { + if (DI::userSession()->getSubManagedUserId()) { return; } @@ -65,7 +64,7 @@ function removeme_post(App $a) ->withMessage( $l10n->t('[Friendica System Notify]') . ' ' . $l10n->t('User deleted their account'), $l10n->t('On your Friendica node an user deleted their account. Please ensure that their data is removed from the backups.'), - $l10n->t('The user id is %d', Session::getLocalUser())) + $l10n->t('The user id is %d', DI::userSession()->getLocalUserId())) ->forUser($admin) ->withRecipient($admin['email']) ->build(); @@ -84,7 +83,7 @@ function removeme_post(App $a) function removeme_content(App $a) { - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { DI::baseUrl()->redirect(); } diff --git a/mod/repair_ostatus.php b/mod/repair_ostatus.php index 8ae294a0a..b0ee0bf57 100644 --- a/mod/repair_ostatus.php +++ b/mod/repair_ostatus.php @@ -21,14 +21,13 @@ use Friendica\App; use Friendica\Core\Protocol; -use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; function repair_ostatus_content(App $a) { - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); DI::baseUrl()->redirect('ostatus_repair'); // NOTREACHED @@ -36,7 +35,7 @@ function repair_ostatus_content(App $a) { $o = '

' . DI::l10n()->t('Resubscribing to OStatus contacts') . '

'; - $uid = Session::getLocalUser(); + $uid = DI::userSession()->getLocalUserId(); $counter = intval($_REQUEST['counter'] ?? 0); @@ -44,7 +43,7 @@ function repair_ostatus_content(App $a) { $total = DBA::count('contact', $condition); if (!$total) { - return ($o . DI::l10n()->t('Error')); + return ($o . DI::l10n()->tt('Error', 'Errors', 1)); } $contact = Contact::selectToArray(['url'], $condition, ['order' => ['url'], 'limit' => [$counter++, 1]]); diff --git a/mod/settings.php b/mod/settings.php index 5f3be2767..45f5f96c5 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -26,7 +26,6 @@ use Friendica\Content\Nav; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\Renderer; -use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Item; @@ -37,7 +36,7 @@ use Friendica\Protocol\Email; function settings_init(App $a) { - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); return; } @@ -52,7 +51,7 @@ function settings_post(App $a) return; } - if (!empty($_SESSION['submanage'])) { + if (DI::userSession()->getSubManagedUserId()) { return; } @@ -70,12 +69,12 @@ function settings_post(App $a) BaseModule::checkFormSecurityTokenRedirectOnError(DI::args()->getQueryString(), 'settings_connectors'); if (!empty($_POST['general-submit'])) { - DI::pConfig()->set(Session::getLocalUser(), 'system', 'accept_only_sharer', intval($_POST['accept_only_sharer'])); - DI::pConfig()->set(Session::getLocalUser(), 'system', 'disable_cw', !intval($_POST['enable_cw'])); - DI::pConfig()->set(Session::getLocalUser(), 'system', 'no_intelligent_shortening', !intval($_POST['enable_smart_shortening'])); - DI::pConfig()->set(Session::getLocalUser(), 'system', 'simple_shortening', intval($_POST['simple_shortening'])); - DI::pConfig()->set(Session::getLocalUser(), 'system', 'attach_link_title', intval($_POST['attach_link_title'])); - DI::pConfig()->set(Session::getLocalUser(), 'ostatus', 'legacy_contact', $_POST['legacy_contact']); + DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'accept_only_sharer', intval($_POST['accept_only_sharer'])); + DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'disable_cw', !intval($_POST['enable_cw'])); + DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'no_intelligent_shortening', !intval($_POST['enable_smart_shortening'])); + DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'simple_shortening', intval($_POST['simple_shortening'])); + DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'attach_link_title', intval($_POST['attach_link_title'])); + DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'ostatus', 'legacy_contact', $_POST['legacy_contact']); } elseif (!empty($_POST['mail-submit'])) { $mail_server = $_POST['mail_server'] ?? ''; $mail_port = $_POST['mail_port'] ?? ''; @@ -88,13 +87,13 @@ function settings_post(App $a) $mail_pubmail = $_POST['mail_pubmail'] ?? ''; if (function_exists('imap_open') && !DI::config()->get('system', 'imap_disabled')) { - if (!DBA::exists('mailacct', ['uid' => Session::getLocalUser()])) { - DBA::insert('mailacct', ['uid' => Session::getLocalUser()]); + if (!DBA::exists('mailacct', ['uid' => DI::userSession()->getLocalUserId()])) { + DBA::insert('mailacct', ['uid' => DI::userSession()->getLocalUserId()]); } if (strlen($mail_pass)) { $pass = ''; openssl_public_encrypt($mail_pass, $pass, $user['pubkey']); - DBA::update('mailacct', ['pass' => bin2hex($pass)], ['uid' => Session::getLocalUser()]); + DBA::update('mailacct', ['pass' => bin2hex($pass)], ['uid' => DI::userSession()->getLocalUserId()]); } $r = DBA::update('mailacct', [ @@ -107,10 +106,10 @@ function settings_post(App $a) 'mailbox' => 'INBOX', 'reply_to' => $mail_replyto, 'pubmail' => $mail_pubmail - ], ['uid' => Session::getLocalUser()]); + ], ['uid' => DI::userSession()->getLocalUserId()]); Logger::debug('updating mailaccount', ['response' => $r]); - $mailacct = DBA::selectFirst('mailacct', [], ['uid' => Session::getLocalUser()]); + $mailacct = DBA::selectFirst('mailacct', [], ['uid' => DI::userSession()->getLocalUserId()]); if (DBA::isResult($mailacct)) { $mb = Email::constructMailboxName($mailacct); @@ -136,7 +135,7 @@ function settings_post(App $a) BaseModule::checkFormSecurityTokenRedirectOnError('/settings/features', 'settings_features'); foreach ($_POST as $k => $v) { if (strpos($k, 'feature_') === 0) { - DI::pConfig()->set(Session::getLocalUser(), 'feature', substr($k, 8), ((intval($v)) ? 1 : 0)); + DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'feature', substr($k, 8), ((intval($v)) ? 1 : 0)); } } return; @@ -148,12 +147,12 @@ function settings_content(App $a) $o = ''; Nav::setSelected('settings'); - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { //DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); return Login::form(); } - if (!empty($_SESSION['submanage'])) { + if (DI::userSession()->getSubManagedUserId()) { DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); return ''; } @@ -162,12 +161,12 @@ function settings_content(App $a) if ((DI::args()->getArgc() > 3) && (DI::args()->getArgv()[2] === 'delete')) { BaseModule::checkFormSecurityTokenRedirectOnError('/settings/oauth', 'settings_oauth', 't'); - DBA::delete('application-token', ['application-id' => DI::args()->getArgv()[3], 'uid' => Session::getLocalUser()]); + DBA::delete('application-token', ['application-id' => DI::args()->getArgv()[3], 'uid' => DI::userSession()->getLocalUserId()]); DI::baseUrl()->redirect('settings/oauth/', true); return ''; } - $applications = DBA::selectToArray('application-view', ['id', 'uid', 'name', 'website', 'scopes', 'created_at'], ['uid' => Session::getLocalUser()]); + $applications = DBA::selectToArray('application-view', ['id', 'uid', 'name', 'website', 'scopes', 'created_at'], ['uid' => DI::userSession()->getLocalUserId()]); $tpl = Renderer::getMarkupTemplate('settings/oauth.tpl'); $o .= Renderer::replaceMacros($tpl, [ @@ -226,7 +225,7 @@ function settings_content(App $a) $arr[$fname] = []; $arr[$fname][0] = $fdata[0]; foreach (array_slice($fdata,1) as $f) { - $arr[$fname][1][] = ['feature_' . $f[0], $f[1], Feature::isEnabled(Session::getLocalUser(), $f[0]), $f[2]]; + $arr[$fname][1][] = ['feature_' . $f[0], $f[1], Feature::isEnabled(DI::userSession()->getLocalUserId(), $f[0]), $f[2]]; } } @@ -241,12 +240,12 @@ function settings_content(App $a) } if ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'connectors')) { - $accept_only_sharer = intval(DI::pConfig()->get(Session::getLocalUser(), 'system', 'accept_only_sharer')); - $enable_cw = !intval(DI::pConfig()->get(Session::getLocalUser(), 'system', 'disable_cw')); - $enable_smart_shortening = !intval(DI::pConfig()->get(Session::getLocalUser(), 'system', 'no_intelligent_shortening')); - $simple_shortening = intval(DI::pConfig()->get(Session::getLocalUser(), 'system', 'simple_shortening')); - $attach_link_title = intval(DI::pConfig()->get(Session::getLocalUser(), 'system', 'attach_link_title')); - $legacy_contact = DI::pConfig()->get(Session::getLocalUser(), 'ostatus', 'legacy_contact'); + $accept_only_sharer = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'accept_only_sharer')); + $enable_cw = !intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'disable_cw')); + $enable_smart_shortening = !intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'no_intelligent_shortening')); + $simple_shortening = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'simple_shortening')); + $attach_link_title = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'attach_link_title')); + $legacy_contact = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'ostatus', 'legacy_contact'); if (!empty($legacy_contact)) { /// @todo Isn't it supposed to be a $a->internalRedirect() call? @@ -280,7 +279,7 @@ function settings_content(App $a) $mail_disabled = ((function_exists('imap_open') && (!DI::config()->get('system', 'imap_disabled'))) ? 0 : 1); if (!$mail_disabled) { - $mailacct = DBA::selectFirst('mailacct', [], ['uid' => Session::getLocalUser()]); + $mailacct = DBA::selectFirst('mailacct', [], ['uid' => DI::userSession()->getLocalUserId()]); } else { $mailacct = null; } diff --git a/mod/share.php b/mod/share.php index 237da9553..9f94d9ddc 100644 --- a/mod/share.php +++ b/mod/share.php @@ -21,7 +21,6 @@ use Friendica\App; use Friendica\Content\Text\BBCode; -use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; @@ -31,7 +30,7 @@ use Friendica\Model\Post; function share_init(App $a) { $post_id = ((DI::args()->getArgc() > 1) ? intval(DI::args()->getArgv()[1]) : 0); - if (!$post_id || !Session::getLocalUser()) { + if (!$post_id || !DI::userSession()->getLocalUserId()) { System::exit(); } diff --git a/mod/suggest.php b/mod/suggest.php index 207a49e88..9ad11f745 100644 --- a/mod/suggest.php +++ b/mod/suggest.php @@ -22,7 +22,6 @@ use Friendica\App; use Friendica\Content\Widget; use Friendica\Core\Renderer; -use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; @@ -31,7 +30,7 @@ use Friendica\Network\HTTPException; function suggest_content(App $a) { - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.')); } @@ -40,7 +39,7 @@ function suggest_content(App $a) DI::page()['aside'] .= Widget::findPeople(); DI::page()['aside'] .= Widget::follow(); - $contacts = Contact\Relation::getSuggestions(Session::getLocalUser()); + $contacts = Contact\Relation::getSuggestions(DI::userSession()->getLocalUserId()); if (!DBA::isResult($contacts)) { return DI::l10n()->t('No suggestions available. If this is a new site, please try again in 24 hours.'); } diff --git a/mod/tagger.php b/mod/tagger.php index 5e209ec94..dae9cbc2b 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -22,7 +22,6 @@ use Friendica\App; use Friendica\Core\Hook; use Friendica\Core\Logger; -use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; @@ -37,7 +36,7 @@ use Friendica\Worker\Delivery; function tagger_content(App $a) { - if (!Session::isAuthenticated()) { + if (!DI::userSession()->isAuthenticated()) { return; } @@ -63,13 +62,13 @@ function tagger_content(App $a) $owner_uid = $item['uid']; - if (Session::getLocalUser() != $owner_uid) { + if (DI::userSession()->getLocalUserId() != $owner_uid) { return; } - $contact = Contact::selectFirst([], ['self' => true, 'uid' => Session::getLocalUser()]); + $contact = Contact::selectFirst([], ['self' => true, 'uid' => DI::userSession()->getLocalUserId()]); if (!DBA::isResult($contact)) { - Logger::warning('Self contact not found.', ['uid' => Session::getLocalUser()]); + Logger::warning('Self contact not found.', ['uid' => DI::userSession()->getLocalUserId()]); return; } diff --git a/mod/tagrm.php b/mod/tagrm.php index 7ffa7616b..26d2c905f 100644 --- a/mod/tagrm.php +++ b/mod/tagrm.php @@ -21,7 +21,6 @@ use Friendica\App; use Friendica\Content\Text\BBCode; -use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Post; @@ -29,7 +28,7 @@ use Friendica\Model\Tag; function tagrm_post(App $a) { - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { DI::baseUrl()->redirect($_SESSION['photo_return']); } @@ -62,7 +61,7 @@ function update_tags($item_id, $tags) return; } - $item = Post::selectFirst(['uri-id'], ['id' => $item_id, 'uid' => Session::getLocalUser()]); + $item = Post::selectFirst(['uri-id'], ['id' => $item_id, 'uid' => DI::userSession()->getLocalUserId()]); if (!DBA::isResult($item)) { return; } @@ -82,7 +81,7 @@ function tagrm_content(App $a) $photo_return = $_SESSION['photo_return'] ?? ''; - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { DI::baseUrl()->redirect($photo_return); // NOTREACHED } @@ -98,7 +97,7 @@ function tagrm_content(App $a) // NOTREACHED } - $item = Post::selectFirst(['uri-id'], ['id' => $item_id, 'uid' => Session::getLocalUser()]); + $item = Post::selectFirst(['uri-id'], ['id' => $item_id, 'uid' => DI::userSession()->getLocalUserId()]); if (!DBA::isResult($item)) { DI::baseUrl()->redirect($photo_return); } diff --git a/mod/unfollow.php b/mod/unfollow.php index ec8cd4506..8431d04d0 100644 --- a/mod/unfollow.php +++ b/mod/unfollow.php @@ -23,7 +23,6 @@ use Friendica\App; use Friendica\Content\Widget; use Friendica\Core\Protocol; use Friendica\Core\Renderer; -use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; @@ -32,7 +31,7 @@ use Friendica\Util\Strings; function unfollow_post(App $a) { - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); DI::baseUrl()->redirect('login'); // NOTREACHED @@ -47,17 +46,17 @@ function unfollow_content(App $a) { $base_return_path = 'contact'; - if (!Session::getLocalUser()) { + if (!DI::userSession()->getLocalUserId()) { DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); DI::baseUrl()->redirect('login'); // NOTREACHED } - $uid = Session::getLocalUser(); + $uid = DI::userSession()->getLocalUserId(); $url = trim($_REQUEST['url']); $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)", - Session::getLocalUser(), Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url), + DI::userSession()->getLocalUserId(), Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url), Strings::normaliseLink($url), $url]; $contact = DBA::selectFirst('contact', ['url', 'id', 'uid', 'network', 'addr', 'name'], $condition); @@ -119,7 +118,7 @@ function unfollow_process(string $url) { $base_return_path = 'contact'; - $uid = Session::getLocalUser(); + $uid = DI::userSession()->getLocalUserId(); $owner = User::getOwnerDataById($uid); if (!$owner) { diff --git a/mod/update_contact.php b/mod/update_contact.php index 21e46b19d..c6a49a417 100644 --- a/mod/update_contact.php +++ b/mod/update_contact.php @@ -22,7 +22,6 @@ */ use Friendica\App; -use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; @@ -31,7 +30,7 @@ use Friendica\Model\Contact; function update_contact_content(App $a) { - if (!empty(DI::args()->get(1)) && (!empty($_GET['force']) || !DI::pConfig()->get(Session::getLocalUser(), 'system', 'no_auto_update'))) { + if (!empty(DI::args()->get(1)) && (!empty($_GET['force']) || !DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'no_auto_update'))) { $contact = Contact::getById(DI::args()->get(1), ['id', 'deleted']); if (DBA::isResult($contact) && empty($contact['deleted'])) { DI::page()['aside'] = ''; diff --git a/mod/wall_attach.php b/mod/wall_attach.php index 7f12d15e6..83d5338da 100644 --- a/mod/wall_attach.php +++ b/mod/wall_attach.php @@ -20,7 +20,6 @@ */ use Friendica\App; -use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; @@ -55,10 +54,10 @@ function wall_attach_post(App $a) { $page_owner_cid = $owner['id']; $community_page = $owner['page-flags'] == User::PAGE_FLAGS_COMMUNITY; - if (Session::getLocalUser() && (Session::getLocalUser() == $page_owner_uid)) { + if (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserId() == $page_owner_uid)) { $can_post = true; - } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) { - $contact_id = Session::getRemoteContactID($page_owner_uid); + } elseif ($community_page && !empty(DI::userSession()->getRemoteContactID($page_owner_uid))) { + $contact_id = DI::userSession()->getRemoteContactID($page_owner_uid); $can_post = DBA::exists('contact', ['blocked' => false, 'pending' => false, 'id' => $contact_id, 'uid' => $page_owner_uid]); } diff --git a/mod/wall_upload.php b/mod/wall_upload.php index d66e2af8f..c5575da97 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -27,7 +27,6 @@ use Friendica\App; use Friendica\Core\Logger; -use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; @@ -76,10 +75,10 @@ function wall_upload_post(App $a, $desktopmode = true) $page_owner_nick = $user['nickname']; $community_page = (($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false); - if ((Session::getLocalUser()) && (Session::getLocalUser() == $page_owner_uid)) { + if ((DI::userSession()->getLocalUserId()) && (DI::userSession()->getLocalUserId() == $page_owner_uid)) { $can_post = true; - } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) { - $contact_id = Session::getRemoteContactID($page_owner_uid); + } elseif ($community_page && !empty(DI::userSession()->getRemoteContactID($page_owner_uid))) { + $contact_id = DI::userSession()->getRemoteContactID($page_owner_uid); $can_post = DBA::exists('contact', ['blocked' => false, 'pending' => false, 'id' => $contact_id, 'uid' => $page_owner_uid]); $visitor = $contact_id; } diff --git a/src/App.php b/src/App.php index 081767cfd..1933b359e 100644 --- a/src/App.php +++ b/src/App.php @@ -27,13 +27,13 @@ use Friendica\App\BaseURL; use Friendica\Capabilities\ICanCreateResponses; use Friendica\Core\Config\Factory\Config; use Friendica\Core\Session\Capability\IHandleSessions; +use Friendica\Core\Session\Capability\IHandleUserSessions; use Friendica\Module\Maintenance; use Friendica\Security\Authentication; 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; @@ -134,6 +134,11 @@ class App */ private $session; + /** + * @var IHandleUserSessions + */ + private $userSession; + /** * Set the user ID * @@ -158,7 +163,7 @@ class App public function isLoggedIn(): bool { - return Session::getLocalUser() && $this->user_id && ($this->user_id == Session::getLocalUser()); + return $this->userSession->getLocalUserId() && $this->user_id && ($this->user_id == $this->userSession->getLocalUserId()); } /** @@ -172,7 +177,7 @@ class App $adminlist = explode(',', str_replace(' ', '', $admin_email)); - return Session::getLocalUser() && $admin_email && $this->database->exists('user', ['uid' => $this->getLoggedInUserId(), 'email' => $adminlist]); + return $this->userSession->getLocalUserId() && $admin_email && $this->database->exists('user', ['uid' => $this->getLoggedInUserId(), 'email' => $adminlist]); } /** @@ -337,18 +342,19 @@ class App * @param IManagePersonalConfigValues $pConfig Personal configuration * @param IHandleSessions $session The Session handler */ - public function __construct(Database $database, IManageConfigValues $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, IManagePersonalConfigValues $pConfig, IHandleSessions $session) + public function __construct(Database $database, IManageConfigValues $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, IManagePersonalConfigValues $pConfig, IHandleSessions $session, IHandleUserSessions $userSession) { - $this->database = $database; - $this->config = $config; - $this->mode = $mode; - $this->baseURL = $baseURL; - $this->profiler = $profiler; - $this->logger = $logger; - $this->l10n = $l10n; - $this->args = $args; - $this->pConfig = $pConfig; - $this->session = $session; + $this->database = $database; + $this->config = $config; + $this->mode = $mode; + $this->baseURL = $baseURL; + $this->profiler = $profiler; + $this->logger = $logger; + $this->l10n = $l10n; + $this->args = $args; + $this->pConfig = $pConfig; + $this->session = $session; + $this->userSession = $userSession; $this->load(); } @@ -496,11 +502,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 != Session::getLocalUser())) { + if (!empty($this->profile_owner) && ($this->profile_owner != $this->userSession->getLocalUserId())) { // 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) && !Session::getLocalUser()) { + if ($this->database->isResult($user) && !$this->userSession->getLocalUserId()) { $page_theme = $user['theme']; } } @@ -529,10 +535,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 != Session::getLocalUser())) { + if (!empty($this->profile_owner) && ($this->profile_owner != $this->userSession->getLocalUserId())) { // 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 (!Session::getLocalUser()) { + if (!$this->userSession->getLocalUserId()) { $page_mobile_theme = $this->pConfig->get($this->profile_owner, 'system', 'mobile-theme'); } } @@ -629,7 +635,7 @@ class App } // ZRL - if (!empty($_GET['zrl']) && $this->mode->isNormal() && !$this->mode->isBackend() && !Session::getLocalUser()) { + if (!empty($_GET['zrl']) && $this->mode->isNormal() && !$this->mode->isBackend() && !$this->userSession->getLocalUserId()) { // 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) == '') && @@ -737,7 +743,7 @@ class App $response = $module->run($input); $this->profiler->set(microtime(true) - $timestamp, 'content'); if ($response->getHeaderLine(ICanCreateResponses::X_HEADER) === ICanCreateResponses::TYPE_HTML) { - $page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig); + $page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig, $this->userSession->getLocalUserId()); } else { $page->exit($response); } diff --git a/src/App/Page.php b/src/App/Page.php index d1aa17ad0..a6f46bdd8 100644 --- a/src/App/Page.php +++ b/src/App/Page.php @@ -32,7 +32,6 @@ 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; @@ -222,17 +221,18 @@ class Page implements ArrayAccess * - Infinite scroll data * - head.tpl template * - * @param App $app The Friendica App instance - * @param Arguments $args The Friendica App Arguments - * @param L10n $l10n The l10n language instance - * @param IManageConfigValues $config The Friendica configuration - * @param IManagePersonalConfigValues $pConfig The Friendica personal configuration (for user) + * @param App $app The Friendica App instance + * @param Arguments $args The Friendica App Arguments + * @param L10n $l10n The l10n language instance + * @param IManageConfigValues $config The Friendica configuration + * @param IManagePersonalConfigValues $pConfig The Friendica personal configuration (for user) + * @param int $localUID The local user id * * @throws HTTPException\InternalServerErrorException */ - private function initHead(App $app, Arguments $args, L10n $l10n, IManageConfigValues $config, IManagePersonalConfigValues $pConfig) + private function initHead(App $app, Arguments $args, L10n $l10n, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, int $localUID) { - $interval = ((Session::getLocalUser()) ? $pConfig->get(Session::getLocalUser(), 'system', 'update_interval') : 40000); + $interval = ($localUID ? $pConfig->get($localUID, 'system', 'update_interval') : 40000); // If the update is 'deactivated' set it to the highest integer number (~24 days) if ($interval < 0) { @@ -277,7 +277,7 @@ class Page implements ArrayAccess * being first */ $this->page['htmlhead'] = Renderer::replaceMacros($tpl, [ - '$local_user' => Session::getLocalUser(), + '$local_user' => $localUID, '$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.'), @@ -444,10 +444,11 @@ class Page implements ArrayAccess * @param L10n $l10n The l10n language class * @param IManageConfigValues $config The Configuration of this node * @param IManagePersonalConfigValues $pconfig The personal/user configuration + * @param int $localUID The UID of the local user * * @throws HTTPException\InternalServerErrorException|HTTPException\ServiceUnavailableException */ - public function run(App $app, BaseURL $baseURL, Arguments $args, Mode $mode, ResponseInterface $response, L10n $l10n, Profiler $profiler, IManageConfigValues $config, IManagePersonalConfigValues $pconfig) + public function run(App $app, BaseURL $baseURL, Arguments $args, Mode $mode, ResponseInterface $response, L10n $l10n, Profiler $profiler, IManageConfigValues $config, IManagePersonalConfigValues $pconfig, int $localUID) { $moduleName = $args->getModuleName(); @@ -481,7 +482,7 @@ class Page implements ArrayAccess * all the module functions have executed so that all * theme choices made by the modules can take effect. */ - $this->initHead($app, $args, $l10n, $config, $pconfig); + $this->initHead($app, $args, $l10n, $config, $pconfig, $localUID); /* Build the page ending -- this is stuff that goes right before * the closing tag diff --git a/src/App/Router.php b/src/App/Router.php index 356279e49..4e5f29521 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -34,7 +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\Core\Session\Capability\IHandleUserSessions; use Friendica\LegacyModule; use Friendica\Module\HTTPException\MethodNotAllowed; use Friendica\Module\HTTPException\PageNotFound; @@ -99,6 +99,9 @@ class Router /** @var LoggerInterface */ private $logger; + /** @var bool */ + private $isLocalUser; + /** @var float */ private $dice_profiler_threshold; @@ -121,9 +124,10 @@ class Router * @param Arguments $args * @param LoggerInterface $logger * @param Dice $dice + * @param IHandleUserSessions $userSession * @param RouteCollector|null $routeCollector */ - public function __construct(array $server, string $baseRoutesFilepath, L10n $l10n, ICanCache $cache, ICanLock $lock, IManageConfigValues $config, Arguments $args, LoggerInterface $logger, Dice $dice, RouteCollector $routeCollector = null) + public function __construct(array $server, string $baseRoutesFilepath, L10n $l10n, ICanCache $cache, ICanLock $lock, IManageConfigValues $config, Arguments $args, LoggerInterface $logger, Dice $dice, IHandleUserSessions $userSession, RouteCollector $routeCollector = null) { $this->baseRoutesFilepath = $baseRoutesFilepath; $this->l10n = $l10n; @@ -134,6 +138,7 @@ class Router $this->dice = $dice; $this->server = $server; $this->logger = $logger; + $this->isLocalUser = !empty($userSession->getLocalUserId()); $this->dice_profiler_threshold = $config->get('system', 'dice_profiler_threshold', 0); $this->routeCollector = $routeCollector ?? new RouteCollector(new Std(), new GroupCountBased()); @@ -309,7 +314,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 (!Session::getLocalUser() && Hook::isAddonApp($moduleName) && $privateapps) { + if (!$this->isLocalUser && 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 9ff1b63ef..aa8a05f7a 100644 --- a/src/Content/Conversation.php +++ b/src/Content/Conversation.php @@ -32,8 +32,8 @@ use Friendica\Core\L10n; use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\Protocol; use Friendica\Core\Renderer; -use Friendica\Core\Session; use Friendica\Core\Session\Capability\IHandleSessions; +use Friendica\Core\Session\Capability\IHandleUserSessions; use Friendica\Core\Theme; use Friendica\Database\DBA; use Friendica\Model\Contact; @@ -80,22 +80,25 @@ class Conversation private $mode; /** @var IHandleSessions */ private $session; + /** @var IHandleUserSessions */ + private $userSession; - public function __construct(LoggerInterface $logger, Profiler $profiler, Activity $activity, L10n $l10n, Item $item, Arguments $args, BaseURL $baseURL, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, App\Page $page, App\Mode $mode, App $app, IHandleSessions $session) + public function __construct(LoggerInterface $logger, Profiler $profiler, Activity $activity, L10n $l10n, Item $item, Arguments $args, BaseURL $baseURL, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, App\Page $page, App\Mode $mode, App $app, IHandleSessions $session, IHandleUserSessions $userSession) { - $this->activity = $activity; - $this->item = $item; - $this->config = $config; - $this->mode = $mode; - $this->baseURL = $baseURL; - $this->profiler = $profiler; - $this->logger = $logger; - $this->l10n = $l10n; - $this->args = $args; - $this->pConfig = $pConfig; - $this->page = $page; - $this->app = $app; - $this->session = $session; + $this->activity = $activity; + $this->item = $item; + $this->config = $config; + $this->mode = $mode; + $this->baseURL = $baseURL; + $this->profiler = $profiler; + $this->logger = $logger; + $this->l10n = $l10n; + $this->args = $args; + $this->pConfig = $pConfig; + $this->page = $page; + $this->app = $app; + $this->session = $session; + $this->userSession = $userSession; } /** @@ -172,7 +175,7 @@ class Conversation continue; } - if (Session::getPublicContact() == $activity['author-id']) { + if ($this->userSession->getPublicContactId() == $activity['author-id']) { $conv_responses[$mode][$activity['thr-parent-id']]['self'] = 1; } @@ -297,7 +300,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'] ?? Session::getLocalUser(); + $x['profile_uid'] = $x['profile_uid'] ?? $this->userSession->getLocalUserId(); $geotag = !empty($x['allow_location']) ? Renderer::replaceMacros(Renderer::getMarkupTemplate('jot_geotag.tpl'), []) : ''; @@ -360,7 +363,7 @@ class Conversation '$title' => $x['title'] ?? '', '$placeholdertitle' => $this->l10n->t('Set title'), '$category' => $x['category'] ?? '', - '$placeholdercategory' => Feature::isEnabled(Session::getLocalUser(), 'categories') ? $this->l10n->t("Categories \x28comma-separated list\x29") : '', + '$placeholdercategory' => Feature::isEnabled($this->userSession->getLocalUserId(), 'categories') ? $this->l10n->t("Categories \x28comma-separated list\x29") : '', '$scheduled_at' => Temporal::getDateTimeField( new \DateTime(), new \DateTime('now + 6 months'), @@ -398,7 +401,7 @@ class Conversation '$browser' => $this->l10n->t('Browser'), '$compose_link_title' => $this->l10n->t('Open Compose page'), - '$always_open_compose' => $this->pConfig->get(Session::getLocalUser(), 'frio', 'always_open_compose', false), + '$always_open_compose' => $this->pConfig->get($this->userSession->getLocalUserId(), 'frio', 'always_open_compose', false), ]); @@ -437,7 +440,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 = (bool)Session::getLocalUser(); + $ssl_state = (bool)$this->userSession->getLocalUserId(); $live_update_div = ''; @@ -489,11 +492,11 @@ class Conversation } } } elseif ($mode === 'notes') { - $items = $this->addChildren($items, false, $order, Session::getLocalUser(), $mode); + $items = $this->addChildren($items, false, $order, $this->userSession->getLocalUserId(), $mode); if (!$update) { $live_update_div = '
' . "\r\n" - . "\r\n"; } } elseif ($mode === 'display') { @@ -527,7 +530,7 @@ class Conversation $live_update_div = '' . "\r\n"; } - $page_dropping = Session::getLocalUser() && Session::getLocalUser() == $uid; + $page_dropping = $this->userSession->getLocalUserId() && $this->userSession->getLocalUserId() == $uid; if (!$update) { $_SESSION['return_path'] = $this->args->getQueryString(); @@ -547,7 +550,7 @@ class Conversation 'announce' => [], ]; - if ($this->pConfig->get(Session::getLocalUser(), 'system', 'hide_dislike')) { + if ($this->pConfig->get($this->userSession->getLocalUserId(), 'system', 'hide_dislike')) { unset($conv_responses['dislike']); } @@ -565,7 +568,7 @@ class Conversation $writable = $items[0]['writable'] || ($items[0]['uid'] == 0) && in_array($items[0]['network'], Protocol::FEDERATED); } - if (!Session::getLocalUser()) { + if (!$this->userSession->getLocalUserId()) { $writable = false; } @@ -598,7 +601,7 @@ class Conversation $threadsid++; // prevent private email from leaking. - if ($item['network'] === Protocol::MAIL && Session::getLocalUser() != $item['uid']) { + if ($item['network'] === Protocol::MAIL && $this->userSession->getLocalUserId() != $item['uid']) { continue; } @@ -642,17 +645,17 @@ class Conversation 'announce' => null, ]; - if ($this->pConfig->get(Session::getLocalUser(), 'system', 'hide_dislike')) { + if ($this->pConfig->get($this->userSession->getLocalUserId(), 'system', 'hide_dislike')) { unset($likebuttons['dislike']); } $body_html = ItemModel::prepareBody($item, true, $preview); - [$categories, $folders] = $this->item->determineCategoriesTerms($item, Session::getLocalUser()); + [$categories, $folders] = $this->item->determineCategoriesTerms($item, $this->userSession->getLocalUserId()); if (!empty($item['title'])) { $title = $item['title']; - } elseif (!empty($item['content-warning']) && $this->pConfig->get(Session::getLocalUser(), 'system', 'disable_cw', false)) { + } elseif (!empty($item['content-warning']) && $this->pConfig->get($this->userSession->getLocalUserId(), 'system', 'disable_cw', false)) { $title = ucfirst($item['content-warning']); } else { $title = ''; @@ -746,7 +749,7 @@ class Conversation $this->builtinActivityPuller($item, $conv_responses); // Only add what is visible - if ($item['network'] === Protocol::MAIL && Session::getLocalUser() != $item['uid']) { + if ($item['network'] === Protocol::MAIL && $this->userSession->getLocalUserId() != $item['uid']) { continue; } @@ -791,11 +794,11 @@ class Conversation private function getBlocklist(): array { - if (!Session::getLocalUser()) { + if (!$this->userSession->getLocalUserId()) { return []; } - $str_blocked = str_replace(["\n", "\r"], ",", $this->pConfig->get(Session::getLocalUser(), 'system', 'blocked')); + $str_blocked = str_replace(["\n", "\r"], ",", $this->pConfig->get($this->userSession->getLocalUserId(), 'system', 'blocked')); if (empty($str_blocked)) { return []; } @@ -865,7 +868,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(Session::getLocalUser(), 'system', 'display_resharer')) { + if (!empty($row['causer-id']) && $this->pConfig->get($this->userSession->getLocalUserId(), 'system', 'display_resharer')) { $row['owner-id'] = $row['causer-id']; $row['owner-link'] = $row['causer-link']; $row['owner-avatar'] = $row['causer-avatar']; @@ -1217,7 +1220,7 @@ class Conversation $parents[$i]['children'] = $this->sortItemChildren($parents[$i]['children']); } - if (!$this->pConfig->get(Session::getLocalUser(), 'system', 'no_smart_threading', 0)) { + if (!$this->pConfig->get($this->userSession->getLocalUserId(), '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 f5e776147..603151473 100644 --- a/src/Content/ForumManager.php +++ b/src/Content/ForumManager.php @@ -24,7 +24,6 @@ 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; @@ -224,7 +223,7 @@ class ForumManager AND NOT `contact`.`pending` AND NOT `contact`.`archive` AND `contact`.`uid` = ? GROUP BY `contact`.`id`", - Session::getLocalUser(), Protocol::DFRN, Protocol::ACTIVITYPUB, Contact::TYPE_COMMUNITY, Session::getLocalUser() + DI::userSession()->getLocalUserId(), Protocol::DFRN, Protocol::ACTIVITYPUB, Contact::TYPE_COMMUNITY, DI::userSession()->getLocalUserId() ); return DBA::toArray($stmtContacts); diff --git a/src/Content/Item.php b/src/Content/Item.php index 2f780ec4e..f03e42a08 100644 --- a/src/Content/Item.php +++ b/src/Content/Item.php @@ -27,7 +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\Session\Capability\IHandleUserSessions; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Model\Contact; @@ -53,12 +53,15 @@ class Item private $l10n; /** @var Profiler */ private $profiler; + /** @var IHandleUserSessions */ + private $userSession; - public function __construct(Profiler $profiler, Activity $activity, L10n $l10n) + public function __construct(Profiler $profiler, Activity $activity, L10n $l10n, IHandleUserSessions $userSession) { - $this->profiler = $profiler; - $this->activity = $activity; - $this->l10n = $l10n; + $this->profiler = $profiler; + $this->activity = $activity; + $this->l10n = $l10n; + $this->userSession = $userSession; } /** @@ -110,7 +113,7 @@ class Item $categories[] = [ 'name' => $savedFolderName, 'url' => $url, - 'removeurl' => Session::getLocalUser() == $uid ? 'filerm/' . $item['id'] . '?cat=' . rawurlencode($savedFolderName) : '', + 'removeurl' => $this->userSession->getLocalUserId() == $uid ? 'filerm/' . $item['id'] . '?cat=' . rawurlencode($savedFolderName) : '', 'first' => $first, 'last' => false ]; @@ -121,12 +124,12 @@ class Item $categories[count($categories) - 1]['last'] = true; } - if (Session::getLocalUser() == $uid) { + if ($this->userSession->getLocalUserId() == $uid) { foreach (Post\Category::getArrayByURIId($item['uri-id'], $uid, Post\Category::FILE) as $savedFolderName) { $folders[] = [ 'name' => $savedFolderName, 'url' => "#", - 'removeurl' => Session::getLocalUser() == $uid ? 'filerm/' . $item['id'] . '?term=' . rawurlencode($savedFolderName) : '', + 'removeurl' => $this->userSession->getLocalUserId() == $uid ? 'filerm/' . $item['id'] . '?term=' . rawurlencode($savedFolderName) : '', 'first' => $first, 'last' => false ]; @@ -332,7 +335,7 @@ class Item $sub_link = $contact_url = $pm_url = $status_link = ''; $photos_link = $posts_link = $block_link = $ignore_link = ''; - if (Session::getLocalUser() && Session::getLocalUser() == $item['uid'] && $item['gravity'] == ItemModel::GRAVITY_PARENT && !$item['self'] && !$item['mention']) { + if ($this->userSession->getLocalUserId() && $this->userSession->getLocalUserId() == $item['uid'] && $item['gravity'] == ItemModel::GRAVITY_PARENT && !$item['self'] && !$item['mention']) { $sub_link = 'javascript:doFollowThread(' . $item['id'] . '); return false;'; } @@ -349,7 +352,7 @@ class Item $pcid = $item['author-id']; $network = ''; $rel = 0; - $condition = ['uid' => Session::getLocalUser(), 'uri-id' => $item['author-uri-id']]; + $condition = ['uid' => $this->userSession->getLocalUserId(), 'uri-id' => $item['author-uri-id']]; $contact = DBA::selectFirst('contact', ['id', 'network', 'rel'], $condition); if (DBA::isResult($contact)) { $cid = $contact['id']; @@ -379,7 +382,7 @@ class Item } } - if (Session::getLocalUser()) { + if ($this->userSession->getLocalUserId()) { $menu = [ $this->l10n->t('Follow Thread') => $sub_link, $this->l10n->t('View Status') => $status_link, @@ -440,7 +443,7 @@ class Item return (!($this->activity->match($item['verb'], Activity::FOLLOW) && $item['object-type'] === Activity\ObjectType::NOTE && empty($item['self']) && - $item['uid'] == Session::getLocalUser()) + $item['uid'] == $this->userSession->getLocalUserId()) ); } diff --git a/src/Content/Nav.php b/src/Content/Nav.php index c66758a6d..23f5dcf07 100644 --- a/src/Content/Nav.php +++ b/src/Content/Nav.php @@ -24,7 +24,6 @@ namespace Friendica\Content; use Friendica\App; use Friendica\Core\Hook; use Friendica\Core\Renderer; -use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; @@ -127,7 +126,7 @@ class Nav //Don't populate apps_menu if apps are private $privateapps = DI::config()->get('config', 'private_addons', false); - if (Session::getLocalUser() || !$privateapps) { + if (DI::userSession()->getLocalUserId() || !$privateapps) { $arr = ['app_menu' => self::$app_menu]; Hook::callAll('app_menu', $arr); @@ -149,7 +148,7 @@ class Nav */ private static function getInfo(App $a): array { - $ssl_state = (bool) Session::getLocalUser(); + $ssl_state = (bool) DI::userSession()->getLocalUserId(); /* * Our network is distributed, and as you visit friends some of the @@ -182,7 +181,7 @@ class Nav $userinfo = null; // nav links: array of array('href', 'text', 'extra css classes', 'title') - if (Session::isAuthenticated()) { + if (DI::userSession()->isAuthenticated()) { $nav['logout'] = ['logout', DI::l10n()->t('Logout'), '', DI::l10n()->t('End this session')]; } else { $nav['login'] = ['login', DI::l10n()->t('Login'), (DI::args()->getModuleName() == 'login' ? 'selected' : ''), DI::l10n()->t('Sign in')]; @@ -211,11 +210,11 @@ class Nav $homelink = DI::session()->get('visitor_home', ''); } - if ((DI::args()->getModuleName() != 'home') && (! (Session::getLocalUser()))) { + if (DI::args()->getModuleName() != 'home' && ! DI::userSession()->getLocalUserId()) { $nav['home'] = [$homelink, DI::l10n()->t('Home'), '', DI::l10n()->t('Home Page')]; } - if (intval(DI::config()->get('config', 'register_policy')) === \Friendica\Module\Register::OPEN && !Session::isAuthenticated()) { + if (intval(DI::config()->get('config', 'register_policy')) === \Friendica\Module\Register::OPEN && !DI::userSession()->isAuthenticated()) { $nav['register'] = ['register', DI::l10n()->t('Register'), '', DI::l10n()->t('Create an account')]; } @@ -229,7 +228,7 @@ class Nav $nav['apps'] = ['apps', DI::l10n()->t('Apps'), '', DI::l10n()->t('Addon applications, utilities, games')]; } - if (Session::getLocalUser() || !DI::config()->get('system', 'local_search')) { + if (DI::userSession()->getLocalUserId() || !DI::config()->get('system', 'local_search')) { $nav['search'] = ['search', DI::l10n()->t('Search'), '', DI::l10n()->t('Search site content')]; $nav['searchoption'] = [ @@ -252,12 +251,12 @@ class Nav } } - if ((Session::getLocalUser() || DI::config()->get('system', 'community_page_style') != Community::DISABLED_VISITOR) && + if ((DI::userSession()->getLocalUserId() || 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 (Session::getLocalUser()) { + if (DI::userSession()->getLocalUserId()) { $nav['events'] = ['events', DI::l10n()->t('Events'), '', DI::l10n()->t('Events and Calendar')]; } @@ -270,7 +269,7 @@ class Nav } // The following nav links are only show to logged in users - if (Session::getLocalUser() && !empty($a->getLoggedInUserNickname())) { + if (DI::userSession()->getLocalUserId() && !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 +287,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') ?: Session::getLocalUser())) { + if (User::hasIdentities(DI::userSession()->getSubManagedUserId() ?: DI::userSession()->getLocalUserId())) { $nav['delegation'] = ['delegation', DI::l10n()->t('Accounts'), '', DI::l10n()->t('Manage other pages')]; } diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index 498a65e33..008269785 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -391,7 +391,7 @@ class OEmbed * @param string $title Optional title (default: what comes from OEmbed object) * @return string Formatted HTML */ - public static function getHTML(string $url, string $title = '') + public static function getHTML(string $url, string $title = ''): string { $o = self::fetchURL($url, !self::isAllowedURL($url)); diff --git a/src/Content/Smilies.php b/src/Content/Smilies.php index 68093e843..02abee6cf 100644 --- a/src/Content/Smilies.php +++ b/src/Content/Smilies.php @@ -22,7 +22,6 @@ namespace Friendica\Content; use Friendica\Core\Hook; -use Friendica\Core\Session; use Friendica\DI; use Friendica\Util\Strings; @@ -214,7 +213,7 @@ class Smilies public static function replaceFromArray(string $text, array $smilies, bool $no_images = false): string { if (intval(DI::config()->get('system', 'no_smilies')) - || (Session::getLocalUser() && intval(DI::pConfig()->get(Session::getLocalUser(), 'system', 'no_smilies'))) + || (DI::userSession()->getLocalUserId() && intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'no_smilies'))) ) { return $text; } diff --git a/src/Content/Widget.php b/src/Content/Widget.php index 06841ed92..6d00c6132 100644 --- a/src/Content/Widget.php +++ b/src/Content/Widget.php @@ -26,7 +26,6 @@ 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; @@ -67,7 +66,7 @@ class Widget $global_dir = Search::getGlobalDirectory(); if (DI::config()->get('system', 'invitation_only')) { - $x = intval(DI::pConfig()->get(Session::getLocalUser(), 'system', 'invites_remaining')); + $x = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'invites_remaining')); if ($x || DI::app()->isSiteAdmin()) { DI::page()['aside'] .= '