Merge remote-tracking branch 'upstream/develop' into share-rework

This commit is contained in:
Michael 2022-10-25 08:31:01 +00:00
commit 1a0b63659b
176 changed files with 6001 additions and 5369 deletions

View file

@ -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

View file

@ -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;

View file

@ -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 .= "<script> var netargs = '?uri_id=" . $item['uri-id'] . "'; </script>";
}

View file

@ -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)),

View file

@ -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']])) {

View file

@ -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)
{

View file

@ -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);

View file

@ -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: [<item id>, 0 (no perm) | <owner id>]
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: [<item id>, 0 (no perm) | <owner id>]
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

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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;

View file

@ -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);

View file

@ -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 = '<h2>' . DI::l10n()->t('Subscribing to contacts') . '</h2>';
$uid = Session::getLocalUser();
$uid = DI::userSession()->getLocalUserId();
$counter = intval($_REQUEST['counter'] ?? 0);

View file

@ -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(),
]);

View file

@ -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;

View file

@ -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();
}

View file

@ -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 = '<h2>' . DI::l10n()->t('Resubscribing to OStatus contacts') . '</h2>';
$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]]);

View file

@ -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;
}

View file

@ -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();
}

View file

@ -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.');
}

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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) {

View file

@ -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'] = '';

View file

@ -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]);
}

View file

@ -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;
}

View file

@ -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,7 +342,7 @@ 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;
@ -349,6 +354,7 @@ class App
$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);
}

View file

@ -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;
@ -227,12 +226,13 @@ class Page implements ArrayAccess
* @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 </body> tag

View file

@ -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";

View file

@ -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,8 +80,10 @@ 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;
@ -96,6 +98,7 @@ class Conversation
$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 = '<div id="live-notes"></div>' . "\r\n"
. "<script> var profile_uid = " . Session::getLocalUser()
. "<script> var profile_uid = " . $this->userSession->getLocalUserId()
. "; var netargs = '/?f='; </script>\r\n";
}
} elseif ($mode === 'display') {
@ -527,7 +530,7 @@ class Conversation
$live_update_div = '<div id="live-search"></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);
}

View file

@ -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);

View file

@ -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->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())
);
}

View file

@ -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')];
}

View file

@ -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));

View file

@ -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;
}

View file

@ -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'] .= '<div class="side-link widget" id="side-invite-remain">'
. DI::l10n()->tt('%d invitation available', '%d invitations available', $x)
@ -196,7 +195,7 @@ class Widget
*/
public static function groups(string $baseurl, string $selected = ''): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return '';
}
@ -205,7 +204,7 @@ class Widget
'ref' => $group['id'],
'name' => $group['name']
];
}, Group::getByUserId(Session::getLocalUser()));
}, Group::getByUserId(DI::userSession()->getLocalUserId()));
return self::filter(
'group',
@ -228,7 +227,7 @@ class Widget
*/
public static function contactRels(string $baseurl, string $selected = ''): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return '';
}
@ -259,13 +258,13 @@ class Widget
*/
public static function networks(string $baseurl, string $selected = ''): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return '';
}
$networks = self::unavailableNetworks();
$query = "`uid` = ? AND NOT `deleted` AND `network` != '' AND NOT `network` IN (" . substr(str_repeat("?, ", count($networks)), 0, -2) . ")";
$condition = array_merge([$query], array_merge([Session::getLocalUser()], $networks));
$condition = array_merge([$query], array_merge([DI::userSession()->getLocalUserId()], $networks));
$r = DBA::select('contact', ['network'], $condition, ['group_by' => ['network'], 'order' => ['network']]);
@ -300,12 +299,12 @@ class Widget
*/
public static function fileAs(string $baseurl, string $selected = ''): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return '';
}
$terms = [];
foreach (Post\Category::getArray(Session::getLocalUser(), Post\Category::FILE) as $savedFolderName) {
foreach (Post\Category::getArray(DI::userSession()->getLocalUserId(), Post\Category::FILE) as $savedFolderName) {
$terms[] = ['ref' => $savedFolderName, 'name' => $savedFolderName];
}
@ -362,11 +361,11 @@ class Widget
*/
public static function commonFriendsVisitor(int $uid, string $nickname): string
{
if (Session::getLocalUser() == $uid) {
if (DI::userSession()->getLocalUserId() == $uid) {
return '';
}
$visitorPCid = Session::getLocalUser() ? Contact::getPublicIdByUserId(Session::getLocalUser()) : Session::getRemoteUser();
$visitorPCid = DI::userSession()->getPublicContactId() ?: DI::userSession()->getRemoteUserId();
if (!$visitorPCid) {
return '';
}

View file

@ -34,12 +34,14 @@ class CalendarExport
{
/**
* Get the events widget.
*
* @param int $uid
*
* @return string Formated HTML of the calendar widget.
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function getHTML(int $uid = 0) {
public static function getHTML(int $uid = 0): string
{
if (empty($uid)) {
return '';
}
@ -49,11 +51,11 @@ class CalendarExport
return '';
}
$tpl = Renderer::getMarkupTemplate("widget/events.tpl");
$tpl = Renderer::getMarkupTemplate('widget/events.tpl');
$return = Renderer::replaceMacros($tpl, [
'$etitle' => DI::l10n()->t("Export"),
'$export_ical' => DI::l10n()->t("Export calendar as ical"),
'$export_csv' => DI::l10n()->t("Export calendar as csv"),
'$etitle' => DI::l10n()->t('Export'),
'$export_ical' => DI::l10n()->t('Export calendar as ical'),
'$export_csv' => DI::l10n()->t('Export calendar as csv'),
'$user' => $user['nickname']
]);

View file

@ -42,9 +42,9 @@ class ContactBlock
*
* @template widget/contacts.tpl
* @hook contact_block_end (contacts=>array, output=>string)
* @return string
* @return string Formatted HTML code or empty string
*/
public static function getHTML(array $profile, int $visitor_uid = null)
public static function getHTML(array $profile, int $visitor_uid = null): string
{
$o = '';
@ -97,7 +97,9 @@ class ContactBlock
'archive' => false,
'rel' => $rel,
'network' => Protocol::FEDERATED,
], ['limit' => $shown]);
], [
'limit' => $shown,
]);
$contact_uriids = array_column($personal_contacts, 'uri-id');

View file

@ -23,7 +23,6 @@ namespace Friendica\Content\Widget;
use Friendica\Core\Renderer;
use Friendica\Core\Search;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
@ -35,10 +34,10 @@ class SavedSearches
* @return string
* @throws \Exception
*/
public static function getHTML($return_url, $search = '')
public static function getHTML(string $return_url, string $search = ''): string
{
$saved = [];
$saved_searches = DBA::select('search', ['id', 'term'], ['uid' => Session::getLocalUser()]);
$saved_searches = DBA::select('search', ['id', 'term'], ['uid' => DI::userSession()->getLocalUserId()]);
while ($saved_search = DBA::fetch($saved_searches)) {
$saved[] = [
'id' => $saved_search['id'],

View file

@ -46,7 +46,7 @@ class TagCloud
* @return string HTML formatted output.
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function getHTML($uid, $count = 0, $owner_id = 0, $flags = '', $type = Tag::HASHTAG)
public static function getHTML(int $uid, int $count = 0, int $owner_id = 0, string $flags = '', int $type = Tag::HASHTAG): string
{
$o = '';
$r = self::tagadelic($uid, $count, $owner_id, $flags, $type);
@ -56,11 +56,11 @@ class TagCloud
$tags = [];
foreach ($r as $rr) {
$tag['level'] = $rr[2];
$tag['url'] = $url . '?tag=' . urlencode($rr[0]);
$tag['name'] = $rr[0];
$tags[] = $tag;
$tags[] = [
'level' => $rr[2],
'url' => $url . '?tag=' . urlencode($rr[0]),
'name' => $rr[0],
];
}
$tpl = Renderer::getMarkupTemplate('widget/tagcloud.tpl');

View file

@ -35,10 +35,11 @@ class TrendingTags
/**
* @param string $content 'global' (all posts) or 'local' (this node's posts only)
* @param int $period Period in hours to consider posts
* @return string
*
* @return string Formatted HTML code
* @throws \Exception
*/
public static function getHTML($content = 'global', int $period = 24)
public static function getHTML(string $content = 'global', int $period = 24): string
{
if ($content == 'local') {
$tags = Tag::getLocalTrendingHashtags($period, 20);

View file

@ -26,7 +26,6 @@ use Friendica\Content\Text\BBCode;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Contact;
@ -45,7 +44,7 @@ class VCard
* @template widget/vcard.tpl
* @return string
*/
public static function getHTML(array $contact)
public static function getHTML(array $contact): string
{
if (!isset($contact['network']) || !isset($contact['id'])) {
Logger::warning('Incomplete contact', ['contact' => $contact ?? [], 'callstack' => System::callstack(20)]);
@ -65,13 +64,13 @@ class VCard
$photo = Contact::getPhoto($contact);
if (Session::getLocalUser()) {
if (DI::userSession()->getLocalUserId()) {
if ($contact['uid']) {
$id = $contact['id'];
$rel = $contact['rel'];
$pending = $contact['pending'];
} else {
$pcontact = Contact::selectFirst([], ['uid' => Session::getLocalUser(), 'uri-id' => $contact['uri-id']]);
$pcontact = Contact::selectFirst([], ['uid' => DI::userSession()->getLocalUserId(), 'uri-id' => $contact['uri-id']]);
$id = $pcontact['id'] ?? 0;
$rel = $pcontact['rel'] ?? Contact::NOTHING;

View file

@ -62,7 +62,7 @@ class ACL
$page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.css'));
$page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput-typeahead.css'));
$contacts = self::getValidMessageRecipientsForUser(Session::getLocalUser());
$contacts = self::getValidMessageRecipientsForUser(DI::userSession()->getLocalUserId());
$tpl = Renderer::getMarkupTemplate('acl/message_recipient.tpl');
$o = Renderer::replaceMacros($tpl, [

View file

@ -70,7 +70,7 @@ class Search
return $emptyResultList;
}
$contactDetails = Contact::getByURLForUser($user_data['url'] ?? '', Session::getLocalUser());
$contactDetails = Contact::getByURLForUser($user_data['url'] ?? '', DI::userSession()->getLocalUserId());
$result = new ContactResult(
$user_data['name'] ?? '',
@ -136,7 +136,7 @@ class Search
foreach ($profiles as $profile) {
$profile_url = $profile['profile_url'] ?? '';
$contactDetails = Contact::getByURLForUser($profile_url, Session::getLocalUser());
$contactDetails = Contact::getByURLForUser($profile_url, DI::userSession()->getLocalUserId());
$result = new ContactResult(
$profile['name'] ?? '',
@ -211,7 +211,7 @@ class Search
{
Logger::info('Searching', ['search' => $search, 'mode' => $mode, 'page' => $page]);
if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) {
return [];
}

View file

@ -1,175 +0,0 @@
<?php
/**
* @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Core;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Util\Strings;
/**
* High-level Session service class
*/
class Session
{
public static $exists = false;
public static $expire = 180000;
/**
* Returns the user id of locally logged in user or false.
*
* @return int|bool user id or false
*/
public static function getLocalUser()
{
$session = DI::session();
if (!empty($session->get('authenticated')) && !empty($session->get('uid'))) {
return intval($session->get('uid'));
}
return false;
}
/**
* Returns the public contact id of logged in user or false.
*
* @return int|bool public contact id or false
*/
public static function getPublicContact()
{
static $public_contact_id = false;
$session = DI::session();
if (!$public_contact_id && !empty($session->get('authenticated'))) {
if (!empty($session->get('my_address'))) {
// Local user
$public_contact_id = intval(Contact::getIdForURL($session->get('my_address'), 0, false));
} elseif (!empty($session->get('visitor_home'))) {
// Remote user
$public_contact_id = intval(Contact::getIdForURL($session->get('visitor_home'), 0, false));
}
} elseif (empty($session->get('authenticated'))) {
$public_contact_id = false;
}
return $public_contact_id;
}
/**
* Returns public contact id of authenticated site visitor or false
*
* @return int|bool visitor_id or false
*/
public static function getRemoteUser()
{
$session = DI::session();
if (empty($session->get('authenticated'))) {
return false;
}
if (!empty($session->get('visitor_id'))) {
return intval($session->get('visitor_id'));
}
return false;
}
/**
* Return the user contact ID of a visitor for the given user ID they are visiting
*
* @param integer $uid User ID
* @return integer
*/
public static function getRemoteContactID($uid)
{
$session = DI::session();
if (!empty($session->get('remote')[$uid])) {
$remote = $session->get('remote')[$uid];
} else {
$remote = 0;
}
$local_user = !empty($session->get('authenticated')) ? $session->get('uid') : 0;
if (empty($remote) && ($local_user != $uid) && !empty($my_address = $session->get('my_address'))) {
$remote = Contact::getIdForURL($my_address, $uid, false);
}
return $remote;
}
/**
* Returns User ID for given contact ID of the visitor
*
* @param integer $cid Contact ID
* @return integer User ID for given contact ID of the visitor
*/
public static function getUserIDForVisitorContactID($cid)
{
$session = DI::session();
if (empty($session->get('remote'))) {
return false;
}
return array_search($cid, $session->get('remote'));
}
/**
* Set the session variable that contains the contact IDs for the visitor's contact URL
*
* @param string $url Contact URL
*/
public static function setVisitorsContacts()
{
$session = DI::session();
$session->set('remote', []);
$remote = [];
$remote_contacts = DBA::select('contact', ['id', 'uid'], ['nurl' => Strings::normaliseLink($session->get('my_url')), 'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'self' => false]);
while ($contact = DBA::fetch($remote_contacts)) {
if (($contact['uid'] == 0) || Contact\User::isBlocked($contact['id'], $contact['uid'])) {
continue;
}
$remote[$contact['uid']] = $contact['id'];
}
DBA::close($remote_contacts);
$session->set('remote', $remote);
}
/**
* Returns if the current visitor is authenticated
*
* @return boolean "true" when visitor is either a local or remote user
*/
public static function isAuthenticated()
{
$session = DI::session();
return $session->get('authenticated', false);
}
}

View file

@ -0,0 +1,95 @@
<?php
/**
* @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Core\Session\Capability;
/**
* Handles user infos based on session infos
*/
interface IHandleUserSessions
{
/**
* Returns the user id of locally logged-in user or false.
*
* @return int|bool user id or false
*/
public function getLocalUserId();
/**
* Returns the public contact id of logged-in user or false.
*
* @return int|bool public contact id or false
*/
public function getPublicContactId();
/**
* Returns public contact id of authenticated site visitor or false
*
* @return int|bool visitor_id or false
*/
public function getRemoteUserId();
/**
* Return the user contact ID of a visitor for the given user ID they are visiting
*
* @param int $uid User ID
*
* @return int
*/
public function getRemoteContactID(int $uid): int;
/**
* Returns User ID for given contact ID of the visitor
*
* @param int $cid Contact ID
*
* @return int User ID for given contact ID of the visitor
*/
public function getUserIDForVisitorContactID(int $cid): int;
/**
* Returns if the current visitor is authenticated
*
* @return bool "true" when visitor is either a local or remote user
*/
public function isAuthenticated(): bool;
/**
* Returns User ID of the managed user in case it's a different identity
*
* @return int|bool uid of the manager or false
*/
public function getSubManagedUserId();
/**
* Sets the User ID of the managed user in case it's a different identity
*
* @param int $managed_uid The user id of the managing user
*/
public function setSubManagedUserId(int $managed_uid): void;
/**
* Set the session variable that contains the contact IDs for the visitor's contact URL
*
* @param string $url Contact URL
*/
public function setVisitorsContacts();
}

View file

@ -0,0 +1,28 @@
<?php
/**
* @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Core\Session\Handler;
abstract class AbstractSessionHandler implements \SessionHandlerInterface
{
/** @var int Duration of the Session */
public const EXPIRE = 180000;
}

View file

@ -23,14 +23,12 @@ namespace Friendica\Core\Session\Handler;
use Friendica\Core\Cache\Capability\ICanCache;
use Friendica\Core\Cache\Exception\CachePersistenceException;
use Friendica\Core\Session;
use Psr\Log\LoggerInterface;
use SessionHandlerInterface;
/**
* SessionHandler using Friendica Cache
*/
class Cache implements SessionHandlerInterface
class Cache extends AbstractSessionHandler
{
/** @var ICanCache */
private $cache;
@ -57,11 +55,10 @@ class Cache implements SessionHandlerInterface
try {
$data = $this->cache->get('session:' . $id);
if (!empty($data)) {
Session::$exists = true;
return $data;
}
} catch (CachePersistenceException $exception) {
$this->logger->warning('Cannot read session.'. ['id' => $id, 'exception' => $exception]);
$this->logger->warning('Cannot read session.', ['id' => $id, 'exception' => $exception]);
return '';
}
@ -91,7 +88,7 @@ class Cache implements SessionHandlerInterface
}
try {
return $this->cache->set('session:' . $id, $data, Session::$expire);
return $this->cache->set('session:' . $id, $data, static::EXPIRE);
} catch (CachePersistenceException $exception) {
$this->logger->warning('Cannot write session', ['id' => $id, 'exception' => $exception]);
return false;

View file

@ -21,15 +21,13 @@
namespace Friendica\Core\Session\Handler;
use Friendica\Core\Session;
use Friendica\Database\Database as DBA;
use Psr\Log\LoggerInterface;
use SessionHandlerInterface;
/**
* SessionHandler using database
*/
class Database implements SessionHandlerInterface
class Database extends AbstractSessionHandler
{
/** @var DBA */
private $dba;
@ -37,6 +35,8 @@ class Database implements SessionHandlerInterface
private $logger;
/** @var array The $_SERVER variable */
private $server;
/** @var bool global check, if the current Session exists */
private $sessionExists = false;
/**
* DatabaseSessionHandler constructor.
@ -66,11 +66,11 @@ class Database implements SessionHandlerInterface
try {
$session = $this->dba->selectFirst('session', ['data'], ['sid' => $id]);
if ($this->dba->isResult($session)) {
Session::$exists = true;
$this->sessionExists = true;
return $session['data'];
}
} catch (\Exception $exception) {
$this->logger->warning('Cannot read session.'. ['id' => $id, 'exception' => $exception]);
$this->logger->warning('Cannot read session.', ['id' => $id, 'exception' => $exception]);
return '';
}
@ -101,11 +101,11 @@ class Database implements SessionHandlerInterface
return $this->destroy($id);
}
$expire = time() + Session::$expire;
$expire = time() + static::EXPIRE;
$default_expire = time() + 300;
try {
if (Session::$exists) {
if ($this->sessionExists) {
$fields = ['data' => $data, 'expire' => $expire];
$condition = ["`sid` = ? AND (`data` != ? OR `expire` != ?)", $id, $data, $expire];
$this->dba->update('session', $fields, $condition);
@ -114,7 +114,7 @@ class Database implements SessionHandlerInterface
$this->dba->insert('session', $fields);
}
} catch (\Exception $exception) {
$this->logger->warning('Cannot write session.'. ['id' => $id, 'exception' => $exception]);
$this->logger->warning('Cannot write session.', ['id' => $id, 'exception' => $exception]);
return false;
}
@ -131,7 +131,7 @@ class Database implements SessionHandlerInterface
try {
return $this->dba->delete('session', ['sid' => $id]);
} catch (\Exception $exception) {
$this->logger->warning('Cannot destroy session.'. ['id' => $id, 'exception' => $exception]);
$this->logger->warning('Cannot destroy session.', ['id' => $id, 'exception' => $exception]);
return false;
}
}
@ -141,7 +141,7 @@ class Database implements SessionHandlerInterface
try {
return $this->dba->delete('session', ["`expire` < ?", time()]);
} catch (\Exception $exception) {
$this->logger->warning('Cannot use garbage collector.'. ['exception' => $exception]);
$this->logger->warning('Cannot use garbage collector.', ['exception' => $exception]);
return false;
}
}

View file

@ -0,0 +1,133 @@
<?php
/**
* @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Core\Session\Model;
use Friendica\Core\Session\Capability\IHandleSessions;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Model\Contact;
class UserSession implements IHandleUserSessions
{
/** @var IHandleSessions */
private $session;
/** @var int|bool saves the public Contact ID for later usage */
protected $publicContactId = false;
public function __construct(IHandleSessions $session)
{
$this->session = $session;
}
/** {@inheritDoc} */
public function getLocalUserId()
{
if (!empty($this->session->get('authenticated')) && !empty($this->session->get('uid'))) {
return intval($this->session->get('uid'));
}
return false;
}
/** {@inheritDoc} */
public function getPublicContactId()
{
if (empty($this->publicContactId) && !empty($this->session->get('authenticated'))) {
if (!empty($this->session->get('my_address'))) {
// Local user
$this->publicContactId = Contact::getIdForURL($this->session->get('my_address'), 0, false);
} elseif (!empty($this->session->get('visitor_home'))) {
// Remote user
$this->publicContactId = Contact::getIdForURL($this->session->get('visitor_home'), 0, false);
}
} elseif (empty($this->session->get('authenticated'))) {
$this->publicContactId = false;
}
return $this->publicContactId;
}
/** {@inheritDoc} */
public function getRemoteUserId()
{
if (empty($this->session->get('authenticated'))) {
return false;
}
if (!empty($this->session->get('visitor_id'))) {
return (int)$this->session->get('visitor_id');
}
return false;
}
/** {@inheritDoc} */
public function getRemoteContactID(int $uid): int
{
if (!empty($this->session->get('remote')[$uid])) {
$remote = $this->session->get('remote')[$uid];
} else {
$remote = 0;
}
$local_user = !empty($this->session->get('authenticated')) ? $this->session->get('uid') : 0;
if (empty($remote) && ($local_user != $uid) && !empty($my_address = $this->session->get('my_address'))) {
$remote = Contact::getIdForURL($my_address, $uid, false);
}
return $remote;
}
/** {@inheritDoc} */
public function getUserIDForVisitorContactID(int $cid): int
{
if (empty($this->session->get('remote'))) {
return false;
}
return array_search($cid, $this->session->get('remote'));
}
/** {@inheritDoc} */
public function isAuthenticated(): bool
{
return $this->session->get('authenticated', false);
}
/** {@inheritDoc} */
public function setVisitorsContacts()
{
$this->session->set('remote', Contact::getVisitorByUrl($this->session->get('my_url')));
}
/** {@inheritDoc} */
public function getSubManagedUserId()
{
return $this->session->get('submanage') ?? false;
}
/** {@inheritDoc} */
public function setSubManagedUserId(int $managed_uid): void
{
$this->session->set('submanage', $managed_uid);
}
}

View file

@ -0,0 +1,81 @@
<?php
/**
* @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Core\Session\Type;
use Friendica\Core\Session\Capability\IHandleSessions;
class ArraySession implements IHandleSessions
{
/** @var array */
protected $data = [];
public function __construct(array $data = [])
{
$this->data = $data;
}
public function start(): IHandleSessions
{
return $this;
}
public function exists(string $name): bool
{
return !empty($this->data[$name]);
}
public function get(string $name, $defaults = null)
{
return $this->data[$name] ?? $defaults;
}
public function pop(string $name, $defaults = null)
{
$value = $defaults;
if ($this->exists($name)) {
$value = $this->get($name);
$this->remove($name);
}
return $value;
}
public function set(string $name, $value)
{
$this->data[$name] = $value;
}
public function setMultiple(array $values)
{
$this->data = array_merge($values, $this->data);
}
public function remove(string $name)
{
unset($this->data[$name]);
}
public function clear()
{
$this->data = [];
}
}

View file

@ -22,6 +22,7 @@
namespace Friendica;
use Dice\Dice;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Navigation\SystemMessages;
use Psr\Log\LoggerInterface;
@ -219,6 +220,11 @@ abstract class DI
return self::$dice->create(Core\Session\Capability\IHandleSessions::class);
}
public static function userSession(): IHandleUserSessions
{
return self::$dice->create(Core\Session\Capability\IHandleUserSessions::class);
}
/**
* @return \Friendica\Core\Storage\Repository\StorageManager
*/

View file

@ -29,7 +29,6 @@ use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\Database;
@ -261,6 +260,32 @@ class Contact
return DBA::selectFirst('contact', $fields, ['uri-id' => $uri_id], ['order' => ['uid']]);
}
/**
* Fetch all remote contacts for a given contact url
*
* @param string $url The URL of the contact
* @param array $fields The wanted fields
*
* @return array all remote contacts
*
* @throws \Exception
*/
public static function getVisitorByUrl(string $url, array $fields = ['id', 'uid']): array
{
$remote = [];
$remote_contacts = DBA::select('contact', ['id', 'uid'], ['nurl' => Strings::normaliseLink($url), 'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'self' => false]);
while ($contact = DBA::fetch($remote_contacts)) {
if (($contact['uid'] == 0) || Contact\User::isBlocked($contact['id'], $contact['uid'])) {
continue;
}
$remote[$contact['uid']] = $contact['id'];
}
DBA::close($remote_contacts);
return $remote;
}
/**
* Fetches a contact by a given url
*
@ -1103,7 +1128,7 @@ class Contact
$photos_link = '';
if ($uid == 0) {
$uid = Session::getLocalUser();
$uid = DI::userSession()->getLocalUserId();
}
if (empty($contact['uid']) || ($contact['uid'] != $uid)) {
@ -1506,10 +1531,10 @@ class Contact
if ($thread_mode) {
$condition = ["((`$contact_field` = ? AND `gravity` = ?) OR (`author-id` = ? AND `gravity` = ? AND `vid` = ? AND `thr-parent-id` = `parent-uri-id`)) AND " . $sql,
$cid, Item::GRAVITY_PARENT, $cid, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), Session::getLocalUser()];
$cid, Item::GRAVITY_PARENT, $cid, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), DI::userSession()->getLocalUserId()];
} else {
$condition = ["`$contact_field` = ? AND `gravity` IN (?, ?) AND " . $sql,
$cid, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, Session::getLocalUser()];
$cid, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, DI::userSession()->getLocalUserId()];
}
if (!empty($parent)) {
@ -1527,10 +1552,10 @@ class Contact
}
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'));
}
@ -1538,7 +1563,7 @@ class Contact
$params = ['order' => ['received' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
if (DI::pConfig()->get(Session::getLocalUser(), 'system', 'infinite_scroll')) {
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
$tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
$o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
} else {
@ -1547,27 +1572,27 @@ class Contact
if ($thread_mode) {
$fields = ['uri-id', 'thr-parent-id', 'gravity', 'author-id', 'commented'];
$items = Post::toArray(Post::selectForUser(Session::getLocalUser(), $fields, $condition, $params));
$items = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), $fields, $condition, $params));
if ($pager->getStart() == 0) {
$cdata = self::getPublicAndUserContactID($cid, Session::getLocalUser());
$cdata = self::getPublicAndUserContactID($cid, DI::userSession()->getLocalUserId());
if (!empty($cdata['public'])) {
$pinned = Post\Collection::selectToArrayForContact($cdata['public'], Post\Collection::FEATURED, $fields);
$items = array_merge($items, $pinned);
}
}
$o .= DI::conversation()->create($items, 'contacts', $update, false, 'pinned_commented', Session::getLocalUser());
$o .= DI::conversation()->create($items, 'contacts', $update, false, 'pinned_commented', DI::userSession()->getLocalUserId());
} else {
$fields = array_merge(Item::DISPLAY_FIELDLIST, ['featured']);
$items = Post::toArray(Post::selectForUser(Session::getLocalUser(), $fields, $condition, $params));
$items = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), $fields, $condition, $params));
if ($pager->getStart() == 0) {
$cdata = self::getPublicAndUserContactID($cid, Session::getLocalUser());
$cdata = self::getPublicAndUserContactID($cid, DI::userSession()->getLocalUserId());
if (!empty($cdata['public'])) {
$condition = ["`uri-id` IN (SELECT `uri-id` FROM `collection-view` WHERE `cid` = ? AND `type` = ?)",
$cdata['public'], Post\Collection::FEATURED];
$pinned = Post::toArray(Post::selectForUser(Session::getLocalUser(), $fields, $condition, $params));
$pinned = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), $fields, $condition, $params));
$items = array_merge($pinned, $items);
}
}
@ -1576,7 +1601,7 @@ class Contact
}
if (!$update) {
if (DI::pConfig()->get(Session::getLocalUser(), 'system', 'infinite_scroll')) {
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
$o .= HTML::scrollLoader();
} else {
$o .= $pager->renderMinimal(count($items));
@ -3231,7 +3256,7 @@ class Contact
*/
public static function magicLink(string $contact_url, string $url = ''): string
{
if (!Session::isAuthenticated()) {
if (!DI::userSession()->isAuthenticated()) {
return $url ?: $contact_url; // Equivalent to: ($url != '') ? $url : $contact_url;
}
@ -3277,7 +3302,7 @@ class Contact
{
$destination = $url ?: $contact['url']; // Equivalent to ($url != '') ? $url : $contact['url'];
if (!Session::isAuthenticated()) {
if (!DI::userSession()->isAuthenticated()) {
return $destination;
}
@ -3286,7 +3311,7 @@ class Contact
return $url;
}
if (DI::pConfig()->get(Session::getLocalUser(), 'system', 'stay_local') && ($url == '')) {
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'stay_local') && ($url == '')) {
return 'contact/' . $contact['id'] . '/conversations';
}

View file

@ -21,8 +21,8 @@
namespace Friendica\Model\Contact;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
/**
@ -54,7 +54,7 @@ class Group
AND NOT `contact`.`pending`
ORDER BY `contact`.`name` ASC',
$gid,
Session::getLocalUser()
DI::userSession()->getLocalUserId()
);
if (DBA::isResult($stmt)) {

View file

@ -26,7 +26,6 @@ use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
@ -411,7 +410,7 @@ class Event
public static function getStrings(): array
{
// First day of the week (0 = Sunday).
$firstDay = DI::pConfig()->get(Session::getLocalUser(), 'system', 'first_day_of_week', 0);
$firstDay = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'first_day_of_week', 0);
$i18n = [
"firstDay" => $firstDay,
@ -609,7 +608,7 @@ class Event
$edit = null;
$copy = null;
$drop = null;
if (Session::getLocalUser() && Session::getLocalUser() == $event['uid'] && $event['type'] == 'event') {
if (DI::userSession()->getLocalUserId() && DI::userSession()->getLocalUserId() == $event['uid'] && $event['type'] == 'event') {
$edit = !$event['cid'] ? [DI::baseUrl() . '/events/event/' . $event['id'], DI::l10n()->t('Edit event') , '', ''] : null;
$copy = !$event['cid'] ? [DI::baseUrl() . '/events/copy/' . $event['id'] , DI::l10n()->t('Duplicate event'), '', ''] : null;
$drop = [DI::baseUrl() . '/events/drop/' . $event['id'] , DI::l10n()->t('Delete event') , '', ''];
@ -776,7 +775,7 @@ class Event
// Does the user who requests happen to be the owner of the events
// requested? then show all of your events, otherwise only those that
// don't have limitations set in allow_cid and allow_gid.
if (Session::getLocalUser() != $uid) {
if (DI::userSession()->getLocalUserId() != $uid) {
$conditions += ['allow_cid' => '', 'allow_gid' => ''];
}

View file

@ -25,7 +25,6 @@ use Friendica\BaseModule;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\DI;
@ -188,8 +187,8 @@ class Group
) AS `count`
FROM `group`
WHERE `group`.`uid` = ?;",
Session::getLocalUser(),
Session::getLocalUser()
DI::userSession()->getLocalUserId(),
DI::userSession()->getLocalUserId()
);
return DBA::toArray($stmt);
@ -527,7 +526,7 @@ class Group
*/
public static function sidebarWidget(string $every = 'contact', string $each = 'group', string $editmode = 'standard', $group_id = '', int $cid = 0)
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return '';
}
@ -545,7 +544,7 @@ class Group
$member_of = self::getIdsByContactId($cid);
}
$stmt = DBA::select('group', [], ['deleted' => false, 'uid' => Session::getLocalUser(), 'cid' => null], ['order' => ['name']]);
$stmt = DBA::select('group', [], ['deleted' => false, 'uid' => DI::userSession()->getLocalUserId(), 'cid' => null], ['order' => ['name']]);
while ($group = DBA::fetch($stmt)) {
$selected = (($group_id == $group['id']) ? ' group-selected' : '');

View file

@ -27,7 +27,6 @@ use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Model\Tag;
use Friendica\Core\Worker;
@ -1066,7 +1065,7 @@ class Item
}
// We have to tell the hooks who we are - this really should be improved
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
$_SESSION['authenticated'] = true;
$_SESSION['uid'] = $uid;
$dummy_session = true;
@ -2775,8 +2774,8 @@ class Item
*/
public static function getPermissionsConditionArrayByUserId(int $owner_id): array
{
$local_user = Session::getLocalUser();
$remote_user = Session::getRemoteContactID($owner_id);
$local_user = DI::userSession()->getLocalUserId();
$remote_user = DI::userSession()->getRemoteContactID($owner_id);
// default permissions - anonymous user
$condition = ["`private` != ?", self::PRIVATE];
@ -2807,8 +2806,8 @@ class Item
*/
public static function getPermissionsSQLByUserId(int $owner_id, string $table = ''): string
{
$local_user = Session::getLocalUser();
$remote_user = Session::getRemoteContactID($owner_id);
$local_user = DI::userSession()->getLocalUserId();
$remote_user = DI::userSession()->getRemoteContactID($owner_id);
if (!empty($table)) {
$table = DBA::quoteIdentifier($table) . '.';
@ -3006,8 +3005,8 @@ class Item
// Compile eventual content filter reasons
$filter_reasons = [];
if (!$is_preview && Session::getPublicContact() != $item['author-id']) {
if (!empty($item['content-warning']) && (!Session::getLocalUser() || !DI::pConfig()->get(Session::getLocalUser(), 'system', 'disable_cw', false))) {
if (!$is_preview && DI::userSession()->getPublicContactId() != $item['author-id']) {
if (!empty($item['content-warning']) && (!DI::userSession()->getLocalUserId() || !DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'disable_cw', false))) {
$filter_reasons[] = DI::l10n()->t('Content warning: %s', $item['content-warning']);
}
@ -3443,7 +3442,7 @@ class Item
$plink = $item['uri'];
}
if (Session::getLocalUser()) {
if (DI::userSession()->getLocalUserId()) {
$ret = [
'href' => "display/" . $item['guid'],
'orig' => "display/" . $item['guid'],

View file

@ -23,7 +23,6 @@ namespace Friendica\Model;
use Friendica\Core\ACL;
use Friendica\Core\Logger;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
@ -138,12 +137,12 @@ class Mail
$subject = DI::l10n()->t('[no subject]');
}
$me = DBA::selectFirst('contact', [], ['uid' => Session::getLocalUser(), 'self' => true]);
$me = DBA::selectFirst('contact', [], ['uid' => DI::userSession()->getLocalUserId(), 'self' => true]);
if (!DBA::isResult($me)) {
return -2;
}
$contacts = ACL::getValidMessageRecipientsForUser(Session::getLocalUser());
$contacts = ACL::getValidMessageRecipientsForUser(DI::userSession()->getLocalUserId());
$contactIndex = array_search($recipient, array_column($contacts, 'id'));
if ($contactIndex === false) {
@ -152,7 +151,7 @@ class Mail
$contact = $contacts[$contactIndex];
Photo::setPermissionFromBody($body, Session::getLocalUser(), $me['id'], '<' . $contact['id'] . '>', '', '', '');
Photo::setPermissionFromBody($body, DI::userSession()->getLocalUserId(), $me['id'], '<' . $contact['id'] . '>', '', '', '');
$guid = System::createUUID();
$uri = Item::newURI($guid);
@ -165,7 +164,7 @@ class Mail
if (strlen($replyto)) {
$reply = true;
$condition = ["`uid` = ? AND (`uri` = ? OR `parent-uri` = ?)",
Session::getLocalUser(), $replyto, $replyto];
DI::userSession()->getLocalUserId(), $replyto, $replyto];
$mail = DBA::selectFirst('mail', ['convid'], $condition);
if (DBA::isResult($mail)) {
$convid = $mail['convid'];
@ -178,7 +177,7 @@ class Mail
$conv_guid = System::createUUID();
$convuri = $contact['addr'] . ':' . $conv_guid;
$fields = ['uid' => Session::getLocalUser(), 'guid' => $conv_guid, 'creator' => $me['addr'],
$fields = ['uid' => DI::userSession()->getLocalUserId(), 'guid' => $conv_guid, 'creator' => $me['addr'],
'created' => DateTimeFormat::utcNow(), 'updated' => DateTimeFormat::utcNow(),
'subject' => $subject, 'recips' => $contact['addr'] . ';' . $me['addr']];
if (DBA::insert('conv', $fields)) {
@ -197,7 +196,7 @@ class Mail
$post_id = self::insert(
[
'uid' => Session::getLocalUser(),
'uid' => DI::userSession()->getLocalUserId(),
'guid' => $guid,
'convid' => $convid,
'from-name' => $me['name'],
@ -233,7 +232,7 @@ class Mail
foreach ($images as $image) {
$image_rid = Photo::ridFromURI($image);
if (!empty($image_rid)) {
Photo::update(['allow-cid' => '<' . $recipient . '>'], ['resource-id' => $image_rid, 'album' => 'Wall Photos', 'uid' => Session::getLocalUser()]);
Photo::update(['allow-cid' => '<' . $recipient . '>'], ['resource-id' => $image_rid, 'album' => 'Wall Photos', 'uid' => DI::userSession()->getLocalUserId()]);
}
}
}

View file

@ -23,7 +23,6 @@ namespace Friendica\Model;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Logger;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
@ -639,10 +638,10 @@ class Photo
{
$sql_extra = Security::getPermissionsSQLByUserId($uid);
$avatar_type = (Session::getLocalUser() && (Session::getLocalUser() == $uid)) ? self::USER_AVATAR : self::DEFAULT;
$banner_type = (Session::getLocalUser() && (Session::getLocalUser() == $uid)) ? self::USER_BANNER : self::DEFAULT;
$avatar_type = (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserId() == $uid)) ? self::USER_AVATAR : self::DEFAULT;
$banner_type = (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserId() == $uid)) ? self::USER_BANNER : self::DEFAULT;
$key = 'photo_albums:' . $uid . ':' . Session::getLocalUser() . ':' . Session::getRemoteUser();
$key = 'photo_albums:' . $uid . ':' . DI::userSession()->getLocalUserId() . ':' . DI::userSession()->getRemoteUserId();
$albums = DI::cache()->get($key);
if (is_null($albums) || $update) {
@ -681,7 +680,7 @@ class Photo
*/
public static function clearAlbumCache(int $uid)
{
$key = 'photo_albums:' . $uid . ':' . Session::getLocalUser() . ':' . Session::getRemoteUser();
$key = 'photo_albums:' . $uid . ':' . DI::userSession()->getLocalUserId() . ':' . DI::userSession()->getRemoteUserId();
DI::cache()->set($key, null, Duration::DAY);
}

View file

@ -23,7 +23,6 @@ namespace Friendica\Model;
use BadMethodCallException;
use Friendica\Core\Logger;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\Database;
use Friendica\Database\DBA;
@ -509,7 +508,7 @@ class Post
{
$affected = 0;
Logger::info('Start Update', ['fields' => $fields, 'condition' => $condition, 'uid' => Session::getLocalUser(),'callstack' => System::callstack(10)]);
Logger::info('Start Update', ['fields' => $fields, 'condition' => $condition, 'uid' => DI::userSession()->getLocalUserId(),'callstack' => System::callstack(10)]);
// Don't allow changes to fields that are responsible for the relation between the records
unset($fields['id']);

View file

@ -30,7 +30,6 @@ use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Search;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
@ -239,7 +238,7 @@ class Profile
DI::page()['title'] = $profile['name'] . ' @ ' . DI::config()->get('config', 'sitename');
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
$a->setCurrentTheme($profile['theme']);
$a->setCurrentMobileTheme(DI::pConfig()->get($a->getProfileOwner(), 'system', 'mobile_theme') ?? '');
}
@ -255,7 +254,7 @@ class Profile
require_once $theme_info_file;
}
$block = (DI::config()->get('system', 'block_public') && !Session::isAuthenticated());
$block = (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated());
/**
* @todo
@ -295,8 +294,8 @@ class Profile
$profile_contact = [];
if (Session::getLocalUser() && ($profile['uid'] ?? 0) != Session::getLocalUser()) {
$profile_contact = Contact::getByURL($profile['nurl'], null, [], Session::getLocalUser());
if (DI::userSession()->getLocalUserId() && ($profile['uid'] ?? 0) != DI::userSession()->getLocalUserId()) {
$profile_contact = Contact::getByURL($profile['nurl'], null, [], DI::userSession()->getLocalUserId());
}
if (!empty($profile['cid']) && self::getMyURL()) {
$profile_contact = Contact::selectFirst([], ['id' => $profile['cid']]);
@ -379,7 +378,7 @@ class Profile
$xmpp = !empty($profile['xmpp']) ? DI::l10n()->t('XMPP:') : false;
$matrix = !empty($profile['matrix']) ? DI::l10n()->t('Matrix:') : false;
if ((!empty($profile['hidewall']) || $block) && !Session::isAuthenticated()) {
if ((!empty($profile['hidewall']) || $block) && !DI::userSession()->isAuthenticated()) {
$location = $homepage = $about = false;
}
@ -413,7 +412,7 @@ class Profile
}
if (!$block && $show_contacts) {
$contact_block = ContactBlock::getHTML($profile, Session::getLocalUser());
$contact_block = ContactBlock::getHTML($profile, DI::userSession()->getLocalUserId());
if (is_array($profile) && !$profile['hide-friends']) {
$contact_count = DBA::count('contact', [
@ -493,7 +492,7 @@ class Profile
*/
public static function getBirthdays(): string
{
if (!Session::getLocalUser() || DI::mode()->isMobile() || DI::mode()->isMobile()) {
if (!DI::userSession()->getLocalUserId() || DI::mode()->isMobile() || DI::mode()->isMobile()) {
return '';
}
@ -506,7 +505,7 @@ class Profile
$bd_short = DI::l10n()->t('F d');
$cacheKey = 'get_birthdays:' . Session::getLocalUser();
$cacheKey = 'get_birthdays:' . DI::userSession()->getLocalUserId();
$events = DI::cache()->get($cacheKey);
if (is_null($events)) {
$result = DBA::p(
@ -523,7 +522,7 @@ class Profile
ORDER BY `start`",
Contact::SHARING,
Contact::FRIEND,
Session::getLocalUser(),
DI::userSession()->getLocalUserId(),
DateTimeFormat::utc('now + 6 days'),
DateTimeFormat::utcNow()
);
@ -595,7 +594,7 @@ class Profile
$a = DI::app();
$o = '';
if (!Session::getLocalUser() || DI::mode()->isMobile() || DI::mode()->isMobile()) {
if (!DI::userSession()->getLocalUserId() || DI::mode()->isMobile() || DI::mode()->isMobile()) {
return $o;
}
@ -610,7 +609,7 @@ class Profile
$classtoday = '';
$condition = ["`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?",
Session::getLocalUser(), DateTimeFormat::utc('now + 7 days'), DateTimeFormat::utc('now - 1 days')];
DI::userSession()->getLocalUserId(), DateTimeFormat::utc('now + 7 days'), DateTimeFormat::utc('now - 1 days')];
$s = DBA::select('event', [], $condition, ['order' => ['start']]);
$r = [];
@ -620,7 +619,7 @@ class Profile
$total = 0;
while ($rr = DBA::fetch($s)) {
$condition = ['parent-uri' => $rr['uri'], 'uid' => $rr['uid'], 'author-id' => Session::getPublicContact(),
$condition = ['parent-uri' => $rr['uri'], 'uid' => $rr['uid'], 'author-id' => DI::userSession()->getPublicContactId(),
'vid' => [Verb::getID(Activity::ATTEND), Verb::getID(Activity::ATTENDMAYBE)],
'visible' => true, 'deleted' => false];
if (!Post::exists($condition)) {
@ -712,7 +711,7 @@ class Profile
$my_url = self::getMyURL();
$my_url = Network::isUrlValid($my_url);
if (empty($my_url) || Session::getLocalUser()) {
if (empty($my_url) || DI::userSession()->getLocalUserId()) {
return;
}
@ -730,7 +729,7 @@ class Profile
$contact = DBA::selectFirst('contact',['id', 'url'], ['id' => $cid]);
if (DBA::isResult($contact) && Session::getRemoteUser() && Session::getRemoteUser() == $contact['id']) {
if (DBA::isResult($contact) && DI::userSession()->getRemoteUserId() && DI::userSession()->getRemoteUserId() == $contact['id']) {
Logger::info('The visitor ' . $my_url . ' is already authenticated');
return;
}
@ -797,7 +796,7 @@ class Profile
$_SESSION['my_url'] = $visitor['url'];
$_SESSION['remote_comment'] = $visitor['subscribe'];
Session::setVisitorsContacts();
DI::userSession()->setVisitorsContacts();
$a->setContactId($visitor['id']);
@ -916,7 +915,7 @@ class Profile
*/
public static function getThemeUid(App $a): int
{
return Session::getLocalUser() ?: $a->getProfileOwner();
return DI::userSession()->getLocalUserId() ?: $a->getProfileOwner();
}
/**

View file

@ -192,7 +192,7 @@ class DomainPatternBlocklist
'reason' => $data[1] ?? '',
];
if (!in_array($item, $blocklist)) {
$blocklist[] = $data;
$blocklist[] = $item;
}
}

View file

@ -22,7 +22,6 @@
namespace Friendica\Module\Admin;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Register;
@ -122,7 +121,7 @@ abstract class BaseUsers extends BaseAdmin
$user['login_date'] = Temporal::getRelativeDate($user['login_date']);
$user['lastitem_date'] = Temporal::getRelativeDate($user['last-item']);
$user['is_admin'] = in_array($user['email'], $adminlist);
$user['is_deletable'] = !$user['account_removed'] && intval($user['uid']) != Session::getLocalUser();
$user['is_deletable'] = !$user['account_removed'] && intval($user['uid']) != DI::userSession()->getLocalUserId();
$user['deleted'] = ($user['account_removed'] ? Temporal::getRelativeDate($user['account_expires_on']) : False);
return $user;

View file

@ -69,8 +69,6 @@ class Index extends BaseAdmin
$this->blocklist->set($blocklist);
$
$this->baseUrl->redirect('admin/blocklist/server');
}

View file

@ -23,7 +23,6 @@ namespace Friendica\Module\Admin\Users;
use Friendica\Content\Pager;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\User;
@ -48,7 +47,7 @@ class Active extends BaseUsers
if (!empty($_POST['page_users_delete'])) {
foreach ($users as $uid) {
if (Session::getLocalUser() != $uid) {
if (DI::userSession()->getLocalUserId() != $uid) {
User::remove($uid);
} else {
DI::sysmsg()->addNotice(DI::l10n()->t('You can\'t remove yourself'));
@ -79,7 +78,7 @@ class Active extends BaseUsers
switch ($action) {
case 'delete':
if (Session::getLocalUser() != $uid) {
if (DI::userSession()->getLocalUserId() != $uid) {
self::checkFormSecurityTokenRedirectOnError('admin/users/active', 'admin_users_active', 't');
// delete user
User::remove($uid);

View file

@ -23,7 +23,6 @@ namespace Friendica\Module\Admin\Users;
use Friendica\Content\Pager;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\User;
@ -49,7 +48,7 @@ class Blocked extends BaseUsers
if (!empty($_POST['page_users_delete'])) {
foreach ($users as $uid) {
if (Session::getLocalUser() != $uid) {
if (DI::userSession()->getLocalUserId() != $uid) {
User::remove($uid);
} else {
DI::sysmsg()->addNotice(DI::l10n()->t('You can\'t remove yourself'));
@ -80,7 +79,7 @@ class Blocked extends BaseUsers
switch ($action) {
case 'delete':
if (Session::getLocalUser() != $uid) {
if (DI::userSession()->getLocalUserId() != $uid) {
self::checkFormSecurityTokenRedirectOnError('/admin/users/blocked', 'admin_users_blocked', 't');
// delete user
User::remove($uid);

View file

@ -23,7 +23,6 @@ namespace Friendica\Module\Admin\Users;
use Friendica\Content\Pager;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\User;
@ -55,7 +54,7 @@ class Index extends BaseUsers
if (!empty($_POST['page_users_delete'])) {
foreach ($users as $uid) {
if (Session::getLocalUser() != $uid) {
if (DI::userSession()->getLocalUserId() != $uid) {
User::remove($uid);
} else {
DI::sysmsg()->addNotice(DI::l10n()->t('You can\'t remove yourself'));
@ -86,7 +85,7 @@ class Index extends BaseUsers
switch ($action) {
case 'delete':
if (Session::getLocalUser() != $uid) {
if (DI::userSession()->getLocalUserId() != $uid) {
self::checkFormSecurityTokenRedirectOnError(DI::baseUrl()->get(true), 'admin_users', 't');
// delete user
User::remove($uid);

View file

@ -28,7 +28,6 @@ use Friendica\Content\Nav;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
@ -43,7 +42,7 @@ class Apps extends BaseModule
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$privateaddons = $config->get('config', 'private_addons');
if ($privateaddons === "1" && !Session::getLocalUser()) {
if ($privateaddons === "1" && !DI::userSession()->getLocalUserId()) {
$baseUrl->redirect();
}
}

View file

@ -24,7 +24,6 @@ namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\Addon;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Network\HTTPException;
@ -50,7 +49,7 @@ abstract class BaseAdmin extends BaseModule
*/
public static function checkAdminAccess(bool $interactive = false)
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
if ($interactive) {
DI::sysmsg()->addNotice(DI::l10n()->t('Please login to continue.'));
DI::session()->set('return_path', DI::args()->getQueryString());
@ -64,7 +63,7 @@ abstract class BaseAdmin extends BaseModule
throw new HTTPException\ForbiddenException(DI::l10n()->t('You don\'t have access to administration pages.'));
}
if (!empty($_SESSION['submanage'])) {
if (DI::userSession()->getSubManagedUserId()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Submanaged account can\'t access the administration pages. Please log back in as the main account.'));
}
}

View file

@ -28,7 +28,7 @@ use Friendica\BaseModule;
use Friendica\Content\Pager;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Core\System;
use Friendica\Navigation\Notifications\ValueObject\FormattedNotify;
use Friendica\Network\HTTPException\ForbiddenException;
@ -90,11 +90,11 @@ abstract class BaseNotifications extends BaseModule
*/
abstract public function getNotifications();
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $userSession, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
if (!Session::getLocalUser()) {
if (!$userSession->getLocalUserId()) {
throw new ForbiddenException($this->t('Permission denied.'));
}

View file

@ -25,7 +25,6 @@ use Friendica\BaseModule;
use Friendica\Content\Pager;
use Friendica\Core\Renderer;
use Friendica\Core\Search;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Model;
use Friendica\Network\HTTPException;
@ -83,10 +82,10 @@ class BaseSearch extends BaseModule
$search = Network::convertToIdn($search);
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'));
}
@ -126,7 +125,7 @@ class BaseSearch extends BaseModule
// in case the result is a contact result, add a contact-specific entry
if ($result instanceof ContactResult) {
$contact = Model\Contact::getByURLForUser($result->getUrl(), Session::getLocalUser());
$contact = Model\Contact::getByURLForUser($result->getUrl(), DI::userSession()->getLocalUserId());
if (!empty($contact)) {
$entries[] = Contact::getContactTemplateVars($contact);
}

View file

@ -23,7 +23,6 @@ namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Content\PageInfo;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Module\Security\Login;
use Friendica\Network\HTTPException;
@ -41,7 +40,7 @@ class Bookmarklet extends BaseModule
$config = DI::config();
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
$output = '<h2>' . DI::l10n()->t('Login') . '</h2>';
$output .= Login::form(DI::args()->getQueryString(), intval($config->get('config', 'register_policy')) === Register::CLOSED ? false : true);
return $output;

View file

@ -28,7 +28,6 @@ use Friendica\Content\Pager;
use Friendica\Content\Widget;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\Theme;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
@ -60,12 +59,12 @@ class Contact extends BaseModule
self::checkFormSecurityTokenRedirectOnError($redirectUrl, 'contact_batch_actions');
$orig_records = Model\Contact::selectToArray(['id', 'uid'], ['id' => $_POST['contact_batch'], 'uid' => [0, Session::getLocalUser()], 'self' => false, 'deleted' => false]);
$orig_records = Model\Contact::selectToArray(['id', 'uid'], ['id' => $_POST['contact_batch'], 'uid' => [0, DI::userSession()->getLocalUserId()], 'self' => false, 'deleted' => false]);
$count_actions = 0;
foreach ($orig_records as $orig_record) {
$cdata = Model\Contact::getPublicAndUserContactID($orig_record['id'], Session::getLocalUser());
if (empty($cdata) || Session::getPublicContact() === $cdata['public']) {
$cdata = Model\Contact::getPublicAndUserContactID($orig_record['id'], DI::userSession()->getLocalUserId());
if (empty($cdata) || DI::userSession()->getPublicContactId() === $cdata['public']) {
// No action available on your own contact
continue;
}
@ -76,7 +75,7 @@ class Contact extends BaseModule
}
if (!empty($_POST['contacts_batch_block'])) {
self::toggleBlockContact($cdata['public'], Session::getLocalUser());
self::toggleBlockContact($cdata['public'], DI::userSession()->getLocalUserId());
$count_actions++;
}
@ -94,7 +93,7 @@ class Contact extends BaseModule
protected function post(array $request = [])
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return;
}
@ -114,7 +113,7 @@ class Contact extends BaseModule
*/
public static function updateContactFromPoll(int $contact_id)
{
$contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => Session::getLocalUser(), 'deleted' => false]);
$contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => DI::userSession()->getLocalUserId(), 'deleted' => false]);
if (!DBA::isResult($contact)) {
return;
}
@ -154,13 +153,13 @@ class Contact extends BaseModule
*/
private static function toggleIgnoreContact(int $contact_id)
{
$ignored = !Model\Contact\User::isIgnored($contact_id, Session::getLocalUser());
Model\Contact\User::setIgnored($contact_id, Session::getLocalUser(), $ignored);
$ignored = !Model\Contact\User::isIgnored($contact_id, DI::userSession()->getLocalUserId());
Model\Contact\User::setIgnored($contact_id, DI::userSession()->getLocalUserId(), $ignored);
}
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return Login::form($_SERVER['REQUEST_URI']);
}
@ -204,7 +203,7 @@ class Contact extends BaseModule
$_SESSION['return_path'] = DI::args()->getQueryString();
$sql_values = [Session::getLocalUser()];
$sql_values = [DI::userSession()->getLocalUserId()];
// @TODO: Replace with parameter from router
$type = DI::args()->getArgv()[1] ?? '';
@ -230,7 +229,7 @@ class Contact extends BaseModule
$sql_extra = " AND `pending` AND NOT `archive` AND NOT `failed` AND ((`rel` = ?)
OR `id` IN (SELECT `contact-id` FROM `intro` WHERE `intro`.`uid` = ? AND NOT `ignore`))";
$sql_values[] = Model\Contact::SHARING;
$sql_values[] = Session::getLocalUser();
$sql_values[] = DI::userSession()->getLocalUserId();
break;
default:
$sql_extra = " AND NOT `archive` AND NOT `blocked` AND NOT `pending`";
@ -299,8 +298,8 @@ class Contact extends BaseModule
$stmt = DBA::select('contact', [], $condition, ['order' => ['name'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);
while ($contact = DBA::fetch($stmt)) {
$contact['blocked'] = Model\Contact\User::isBlocked($contact['id'], Session::getLocalUser());
$contact['readonly'] = Model\Contact\User::isIgnored($contact['id'], Session::getLocalUser());
$contact['blocked'] = Model\Contact\User::isBlocked($contact['id'], DI::userSession()->getLocalUserId());
$contact['readonly'] = Model\Contact\User::isIgnored($contact['id'], DI::userSession()->getLocalUserId());
$contacts[] = self::getContactTemplateVars($contact);
}
DBA::close($stmt);
@ -424,7 +423,7 @@ class Contact extends BaseModule
public static function getTabsHTML(array $contact, int $active_tab)
{
$cid = $pcid = $contact['id'];
$data = Model\Contact::getPublicAndUserContactID($contact['id'], Session::getLocalUser());
$data = Model\Contact::getPublicAndUserContactID($contact['id'], DI::userSession()->getLocalUserId());
if (!empty($data['user']) && ($contact['id'] == $data['public'])) {
$cid = $data['user'];
} elseif (!empty($data['public'])) {
@ -500,8 +499,8 @@ class Contact extends BaseModule
{
$alt_text = '';
if (!empty($contact['url']) && isset($contact['uid']) && ($contact['uid'] == 0) && Session::getLocalUser()) {
$personal = Model\Contact::getByURL($contact['url'], false, ['uid', 'rel', 'self'], Session::getLocalUser());
if (!empty($contact['url']) && isset($contact['uid']) && ($contact['uid'] == 0) && DI::userSession()->getLocalUserId()) {
$personal = Model\Contact::getByURL($contact['url'], false, ['uid', 'rel', 'self'], DI::userSession()->getLocalUserId());
if (!empty($personal)) {
$contact['uid'] = $personal['uid'];
$contact['rel'] = $personal['rel'];
@ -509,7 +508,7 @@ class Contact extends BaseModule
}
}
if (!empty($contact['uid']) && !empty($contact['rel']) && Session::getLocalUser() == $contact['uid']) {
if (!empty($contact['uid']) && !empty($contact['rel']) && DI::userSession()->getLocalUserId() == $contact['uid']) {
switch ($contact['rel']) {
case Model\Contact::FRIEND:
$alt_text = DI::l10n()->t('Mutual Friendship');

View file

@ -28,7 +28,6 @@ use Friendica\Content\Widget;
use Friendica\Core\L10n;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\Database;
use Friendica\DI;
use Friendica\Model;
@ -57,7 +56,7 @@ class Advanced extends BaseModule
$this->dba = $dba;
$this->page = $page;
if (!Session::isAuthenticated()) {
if (!DI::userSession()->isAuthenticated()) {
throw new ForbiddenException($this->t('Permission denied.'));
}
}
@ -66,7 +65,7 @@ class Advanced extends BaseModule
{
$cid = $this->parameters['id'];
$contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => Session::getLocalUser()]);
$contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => DI::userSession()->getLocalUserId()]);
if (empty($contact)) {
throw new BadRequestException($this->t('Contact not found.'));
}
@ -87,7 +86,7 @@ class Advanced extends BaseModule
'nurl' => $nurl,
'poll' => $poll,
],
['id' => $contact['id'], 'uid' => Session::getLocalUser()]
['id' => $contact['id'], 'uid' => DI::userSession()->getLocalUserId()]
);
if ($photo) {
@ -105,7 +104,7 @@ class Advanced extends BaseModule
{
$cid = $this->parameters['id'];
$contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => Session::getLocalUser()]);
$contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => DI::userSession()->getLocalUserId()]);
if (empty($contact)) {
throw new BadRequestException($this->t('Contact not found.'));
}

View file

@ -25,7 +25,6 @@ use Friendica\BaseModule;
use Friendica\Content\Pager;
use Friendica\Content\Widget;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Model;
use Friendica\Model\User;
@ -36,7 +35,7 @@ class Contacts extends BaseModule
{
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
throw new HTTPException\ForbiddenException();
}
@ -54,7 +53,7 @@ class Contacts extends BaseModule
throw new HTTPException\NotFoundException(DI::l10n()->t('Contact not found.'));
}
$localContactId = Model\Contact::getPublicIdByUserId(Session::getLocalUser());
$localContactId = Model\Contact::getPublicIdByUserId(DI::userSession()->getLocalUserId());
DI::page()['aside'] = Widget\VCard::getHTML($contact);

View file

@ -29,7 +29,7 @@ use Friendica\Content\Nav;
use Friendica\Content\Widget;
use Friendica\Core\L10n;
use Friendica\Core\Protocol;
use Friendica\Core\Session;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Core\Theme;
use Friendica\Model;
use Friendica\Module\Contact;
@ -56,25 +56,30 @@ class Conversations extends BaseModule
* @var LocalRelationship
*/
private $localRelationship;
/**
* @var IHandleUserSessions
*/
private $userSession;
public function __construct(L10n $l10n, LocalRelationship $localRelationship, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, App\Page $page, Conversation $conversation, array $server, array $parameters = [])
public function __construct(L10n $l10n, LocalRelationship $localRelationship, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, App\Page $page, Conversation $conversation, IHandleUserSessions $userSession, $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->page = $page;
$this->conversation = $conversation;
$this->localRelationship = $localRelationship;
$this->userSession = $userSession;
}
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!$this->userSession->getLocalUserId()) {
return Login::form($_SERVER['REQUEST_URI']);
}
// Backward compatibility: Ensure to use the public contact when the user contact is provided
// Remove by version 2022.03
$data = Model\Contact::getPublicAndUserContactID(intval($this->parameters['id']), Session::getLocalUser());
$data = Model\Contact::getPublicAndUserContactID(intval($this->parameters['id']), $this->userSession->getLocalUserId());
if (empty($data)) {
throw new NotFoundException($this->t('Contact not found.'));
}
@ -89,7 +94,7 @@ class Conversations extends BaseModule
throw new NotFoundException($this->t('Contact not found.'));
}
$localRelationship = $this->localRelationship->getForUserContact(Session::getLocalUser(), $contact['id']);
$localRelationship = $this->localRelationship->getForUserContact($this->userSession->getLocalUserId(), $contact['id']);
if ($localRelationship->rel === Model\Contact::SELF) {
$this->baseUrl->redirect('profile/' . $contact['nick']);
}

View file

@ -23,7 +23,6 @@ namespace Friendica\Module\Contact;
use Friendica\BaseModule;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
@ -41,7 +40,7 @@ class Hovercard extends BaseModule
$contact_url = $_REQUEST['url'] ?? '';
// Get out if the system doesn't have public access allowed
if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) {
throw new HTTPException\ForbiddenException();
}
@ -70,8 +69,8 @@ class Hovercard extends BaseModule
// Search for contact data
// Look if the local user has got the contact
if (Session::isAuthenticated()) {
$contact = Contact::getByURLForUser($contact_url, Session::getLocalUser());
if (DI::userSession()->isAuthenticated()) {
$contact = Contact::getByURLForUser($contact_url, DI::userSession()->getLocalUserId());
} else {
$contact = Contact::getByURL($contact_url, false);
}
@ -81,7 +80,7 @@ class Hovercard extends BaseModule
}
// Get the photo_menu - the menu if possible contact actions
if (Session::isAuthenticated()) {
if (DI::userSession()->isAuthenticated()) {
$actions = Contact::photoMenu($contact);
} else {
$actions = [];

View file

@ -28,7 +28,7 @@ use Friendica\Content\Nav;
use Friendica\Content\Widget;
use Friendica\Core\L10n;
use Friendica\Core\Protocol;
use Friendica\Core\Session;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Database\DBA;
use Friendica\Model;
use Friendica\Module\Contact;
@ -51,24 +51,29 @@ class Posts extends BaseModule
* @var App\Page
*/
private $page;
/**
* @var IHandleUserSessions
*/
private $userSession;
public function __construct(L10n $l10n, LocalRelationship $localRelationship, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, App\Page $page, array $server, array $parameters = [])
public function __construct(L10n $l10n, LocalRelationship $localRelationship, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, App\Page $page, IHandleUserSessions $userSession, $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->localRelationship = $localRelationship;
$this->page = $page;
$this->userSession = $userSession;
}
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!$this->userSession->getLocalUserId()) {
return Login::form($_SERVER['REQUEST_URI']);
}
// Backward compatibility: Ensure to use the public contact when the user contact is provided
// Remove by version 2022.03
$data = Model\Contact::getPublicAndUserContactID(intval($this->parameters['id']), Session::getLocalUser());
$data = Model\Contact::getPublicAndUserContactID(intval($this->parameters['id']), $this->userSession->getLocalUserId());
if (empty($data)) {
throw new NotFoundException($this->t('Contact not found.'));
}
@ -83,7 +88,7 @@ class Posts extends BaseModule
throw new NotFoundException($this->t('Contact not found.'));
}
$localRelationship = $this->localRelationship->getForUserContact(Session::getLocalUser(), $contact['id']);
$localRelationship = $this->localRelationship->getForUserContact($this->userSession->getLocalUserId(), $contact['id']);
if ($localRelationship->rel === Model\Contact::SELF) {
$this->baseUrl->redirect('profile/' . $contact['nick']);
}

View file

@ -34,7 +34,6 @@ use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
@ -75,7 +74,7 @@ class Profile extends BaseModule
protected function post(array $request = [])
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return;
}
@ -83,7 +82,7 @@ class Profile extends BaseModule
// Backward compatibility: The update still needs a user-specific contact ID
// Change to user-contact table check by version 2022.03
$cdata = Contact::getPublicAndUserContactID($contact_id, Session::getLocalUser());
$cdata = Contact::getPublicAndUserContactID($contact_id, DI::userSession()->getLocalUserId());
if (empty($cdata['user']) || !DBA::exists('contact', ['id' => $cdata['user'], 'deleted' => false])) {
return;
}
@ -125,20 +124,20 @@ class Profile extends BaseModule
$fields['info'] = $_POST['info'];
}
if (!Contact::update($fields, ['id' => $cdata['user'], 'uid' => Session::getLocalUser()])) {
if (!Contact::update($fields, ['id' => $cdata['user'], 'uid' => DI::userSession()->getLocalUserId()])) {
DI::sysmsg()->addNotice($this->t('Failed to update contact record.'));
}
}
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return Module\Security\Login::form($_SERVER['REQUEST_URI']);
}
// Backward compatibility: Ensure to use the public contact when the user contact is provided
// Remove by version 2022.03
$data = Contact::getPublicAndUserContactID(intval($this->parameters['id']), Session::getLocalUser());
$data = Contact::getPublicAndUserContactID(intval($this->parameters['id']), DI::userSession()->getLocalUserId());
if (empty($data)) {
throw new HTTPException\NotFoundException($this->t('Contact not found.'));
}
@ -153,7 +152,7 @@ class Profile extends BaseModule
throw new HTTPException\NotFoundException($this->t('Contact not found.'));
}
$localRelationship = $this->localRelationship->getForUserContact(Session::getLocalUser(), $contact['id']);
$localRelationship = $this->localRelationship->getForUserContact(DI::userSession()->getLocalUserId(), $contact['id']);
if ($localRelationship->rel === Contact::SELF) {
$this->baseUrl->redirect('profile/' . $contact['nick'] . '/profile');
@ -174,12 +173,12 @@ class Profile extends BaseModule
if ($cmd === 'block') {
if ($localRelationship->blocked) {
// @TODO Backward compatibility, replace with $localRelationship->unblock()
Contact\User::setBlocked($contact['id'], Session::getLocalUser(), false);
Contact\User::setBlocked($contact['id'], DI::userSession()->getLocalUserId(), false);
$message = $this->t('Contact has been unblocked');
} else {
// @TODO Backward compatibility, replace with $localRelationship->block()
Contact\User::setBlocked($contact['id'], Session::getLocalUser(), true);
Contact\User::setBlocked($contact['id'], DI::userSession()->getLocalUserId(), true);
$message = $this->t('Contact has been blocked');
}
@ -190,12 +189,12 @@ class Profile extends BaseModule
if ($cmd === 'ignore') {
if ($localRelationship->ignored) {
// @TODO Backward compatibility, replace with $localRelationship->unblock()
Contact\User::setIgnored($contact['id'], Session::getLocalUser(), false);
Contact\User::setIgnored($contact['id'], DI::userSession()->getLocalUserId(), false);
$message = $this->t('Contact has been unignored');
} else {
// @TODO Backward compatibility, replace with $localRelationship->block()
Contact\User::setIgnored($contact['id'], Session::getLocalUser(), true);
Contact\User::setIgnored($contact['id'], DI::userSession()->getLocalUserId(), true);
$message = $this->t('Contact has been ignored');
}
@ -224,8 +223,8 @@ class Profile extends BaseModule
'$baseurl' => $this->baseUrl->get(true),
]);
$contact['blocked'] = Contact\User::isBlocked($contact['id'], Session::getLocalUser());
$contact['readonly'] = Contact\User::isIgnored($contact['id'], Session::getLocalUser());
$contact['blocked'] = Contact\User::isBlocked($contact['id'], DI::userSession()->getLocalUserId());
$contact['readonly'] = Contact\User::isIgnored($contact['id'], DI::userSession()->getLocalUserId());
switch ($localRelationship->rel) {
case Contact::FRIEND: $relation_text = $this->t('You are mutual friends with %s', $contact['name']); break;
@ -486,7 +485,7 @@ class Profile extends BaseModule
*/
private static function updateContactFromProbe(int $contact_id)
{
$contact = DBA::selectFirst('contact', ['url'], ['id' => $contact_id, 'uid' => [0, Session::getLocalUser()], 'deleted' => false]);
$contact = DBA::selectFirst('contact', ['url'], ['id' => $contact_id, 'uid' => [0, DI::userSession()->getLocalUserId()], 'deleted' => false]);
if (!DBA::isResult($contact)) {
return;
}

View file

@ -27,7 +27,6 @@ use Friendica\Content\Nav;
use Friendica\Core\L10n;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\Database;
use Friendica\DI;
use Friendica\Model;
@ -55,11 +54,11 @@ class Revoke extends BaseModule
$this->dba = $dba;
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return;
}
$data = Model\Contact::getPublicAndUserContactID($this->parameters['id'], Session::getLocalUser());
$data = Model\Contact::getPublicAndUserContactID($this->parameters['id'], DI::userSession()->getLocalUserId());
if (!$this->dba->isResult($data)) {
throw new HTTPException\NotFoundException($this->t('Unknown contact.'));
}
@ -81,7 +80,7 @@ class Revoke extends BaseModule
protected function post(array $request = [])
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
throw new HTTPException\UnauthorizedException();
}
@ -96,7 +95,7 @@ class Revoke extends BaseModule
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return Login::form($_SERVER['REQUEST_URI']);
}

View file

@ -30,7 +30,6 @@ use Friendica\Content\Text\HTML;
use Friendica\Content\Widget;
use Friendica\Content\Widget\TrendingTags;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
@ -74,7 +73,7 @@ class Community extends BaseModule
'$global_community_hint' => DI::l10n()->t("This community stream shows all public posts received by this node. They may not reflect the opinions of this nodes users.")
]);
if (DI::pConfig()->get(Session::getLocalUser(), 'system', 'infinite_scroll')) {
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
$tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
$o .= Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
}
@ -82,7 +81,7 @@ class Community extends BaseModule
if (empty($_GET['mode']) || ($_GET['mode'] != 'raw')) {
$tabs = [];
if ((Session::isAuthenticated() || in_array(self::$page_style, [self::LOCAL_AND_GLOBAL, self::LOCAL])) && empty(DI::config()->get('system', 'singleuser'))) {
if ((DI::userSession()->isAuthenticated() || in_array(self::$page_style, [self::LOCAL_AND_GLOBAL, self::LOCAL])) && empty(DI::config()->get('system', 'singleuser'))) {
$tabs[] = [
'label' => DI::l10n()->t('Local Community'),
'url' => 'community/local',
@ -93,7 +92,7 @@ class Community extends BaseModule
];
}
if (Session::isAuthenticated() || in_array(self::$page_style, [self::LOCAL_AND_GLOBAL, self::GLOBAL])) {
if (DI::userSession()->isAuthenticated() || in_array(self::$page_style, [self::LOCAL_AND_GLOBAL, self::GLOBAL])) {
$tabs[] = [
'label' => DI::l10n()->t('Global Community'),
'url' => 'community/global',
@ -111,7 +110,7 @@ class Community extends BaseModule
DI::page()['aside'] .= Widget::accountTypes('community/' . self::$content, self::$accountTypeString);
if (Session::getLocalUser() && DI::config()->get('system', 'community_no_sharer')) {
if (DI::userSession()->getLocalUserId() && DI::config()->get('system', 'community_no_sharer')) {
$path = self::$content;
if (!empty($this->parameters['accounttype'])) {
$path .= '/' . $this->parameters['accounttype'];
@ -140,12 +139,12 @@ class Community extends BaseModule
]);
}
if (Feature::isEnabled(Session::getLocalUser(), 'trending_tags')) {
if (Feature::isEnabled(DI::userSession()->getLocalUserId(), 'trending_tags')) {
DI::page()['aside'] .= TrendingTags::getHTML(self::$content);
}
// We need the editor here to be able to reshare an item.
if (Session::isAuthenticated()) {
if (DI::userSession()->isAuthenticated()) {
$o .= DI::conversation()->statusEditor([], 0, true);
}
}
@ -157,7 +156,7 @@ class Community extends BaseModule
return $o;
}
$o .= DI::conversation()->create($items, 'community', false, false, 'commented', Session::getLocalUser());
$o .= DI::conversation()->create($items, 'community', false, false, 'commented', DI::userSession()->getLocalUserId());
$pager = new BoundariesPager(
DI::l10n(),
@ -167,7 +166,7 @@ class Community extends BaseModule
self::$itemsPerPage
);
if (DI::pConfig()->get(Session::getLocalUser(), 'system', 'infinite_scroll')) {
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
$o .= HTML::scrollLoader();
} else {
$o .= $pager->renderMinimal(count($items));
@ -184,7 +183,7 @@ class Community extends BaseModule
*/
protected function parseRequest()
{
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.'));
}
@ -213,7 +212,7 @@ class Community extends BaseModule
}
// Check if we are allowed to display the content to visitors
if (!Session::isAuthenticated()) {
if (!DI::userSession()->isAuthenticated()) {
$available = self::$page_style == self::LOCAL_AND_GLOBAL;
if (!$available) {
@ -230,10 +229,10 @@ class Community extends BaseModule
}
if (DI::mode()->isMobile()) {
self::$itemsPerPage = DI::pConfig()->get(Session::getLocalUser(), 'system', 'itemspage_mobile_network',
self::$itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network',
DI::config()->get('system', 'itemspage_network_mobile'));
} else {
self::$itemsPerPage = DI::pConfig()->get(Session::getLocalUser(), 'system', 'itemspage_network',
self::$itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network',
DI::config()->get('system', 'itemspage_network'));
}
@ -335,9 +334,9 @@ class Community extends BaseModule
$condition[0] .= " AND `id` = ?";
$condition[] = $item_id;
} else {
if (Session::getLocalUser() && !empty($_REQUEST['no_sharer'])) {
if (DI::userSession()->getLocalUserId() && !empty($_REQUEST['no_sharer'])) {
$condition[0] .= " AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ?)";
$condition[] = Session::getLocalUser();
$condition[] = DI::userSession()->getLocalUserId();
}
if (isset($max_id)) {

View file

@ -30,7 +30,6 @@ use Friendica\Content\Text\HTML;
use Friendica\Core\ACL;
use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
@ -78,7 +77,7 @@ class Network extends BaseModule
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return Login::form();
}
@ -88,8 +87,8 @@ class Network extends BaseModule
DI::page()['aside'] .= Widget::accountTypes($module, self::$accountTypeString);
DI::page()['aside'] .= Group::sidebarWidget($module, $module . '/group', 'standard', self::$groupId);
DI::page()['aside'] .= ForumManager::widget($module . '/forum', Session::getLocalUser(), self::$forumContactId);
DI::page()['aside'] .= Widget::postedByYear($module . '/archive', Session::getLocalUser(), false);
DI::page()['aside'] .= ForumManager::widget($module . '/forum', DI::userSession()->getLocalUserId(), self::$forumContactId);
DI::page()['aside'] .= Widget::postedByYear($module . '/archive', DI::userSession()->getLocalUserId(), false);
DI::page()['aside'] .= Widget::networks($module, !self::$forumContactId ? self::$network : '');
DI::page()['aside'] .= Widget\SavedSearches::getHTML(DI::args()->getQueryString());
DI::page()['aside'] .= Widget::fileAs('filed', '');
@ -105,7 +104,7 @@ class Network extends BaseModule
$items = self::getItems($table, $params);
if (DI::pConfig()->get(Session::getLocalUser(), 'system', 'infinite_scroll') && ($_GET['mode'] ?? '') != 'minimal') {
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll') && ($_GET['mode'] ?? '') != 'minimal') {
$tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
$o .= Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
}
@ -138,7 +137,7 @@ class Network extends BaseModule
$allowedCids[] = (int) self::$forumContactId;
} elseif (self::$network) {
$condition = [
'uid' => Session::getLocalUser(),
'uid' => DI::userSession()->getLocalUserId(),
'network' => self::$network,
'self' => false,
'blocked' => false,
@ -168,7 +167,7 @@ class Network extends BaseModule
}
if (self::$groupId) {
$group = DBA::selectFirst('group', ['name'], ['id' => self::$groupId, 'uid' => Session::getLocalUser()]);
$group = DBA::selectFirst('group', ['name'], ['id' => self::$groupId, 'uid' => DI::userSession()->getLocalUserId()]);
if (!DBA::isResult($group)) {
DI::sysmsg()->addNotice(DI::l10n()->t('No such group'));
}
@ -199,9 +198,9 @@ class Network extends BaseModule
$ordering = '`commented`';
}
$o .= DI::conversation()->create($items, 'network', false, false, $ordering, Session::getLocalUser());
$o .= DI::conversation()->create($items, 'network', false, false, $ordering, DI::userSession()->getLocalUserId());
if (DI::pConfig()->get(Session::getLocalUser(), 'system', 'infinite_scroll')) {
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
$o .= HTML::scrollLoader();
} else {
$pager = new BoundariesPager(
@ -307,7 +306,7 @@ class Network extends BaseModule
self::$forumContactId = $this->parameters['contact_id'] ?? 0;
self::$selectedTab = DI::session()->get('network-tab', DI::pConfig()->get(Session::getLocalUser(), 'network.view', 'selected_tab', ''));
self::$selectedTab = DI::session()->get('network-tab', DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'network.view', 'selected_tab', ''));
if (!empty($get['star'])) {
self::$selectedTab = 'star';
@ -346,7 +345,7 @@ class Network extends BaseModule
}
DI::session()->set('network-tab', self::$selectedTab);
DI::pConfig()->set(Session::getLocalUser(), 'network.view', 'selected_tab', self::$selectedTab);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'network.view', 'selected_tab', self::$selectedTab);
self::$accountTypeString = $get['accounttype'] ?? $this->parameters['accounttype'] ?? '';
self::$accountType = User::getAccountTypeByString(self::$accountTypeString);
@ -357,10 +356,10 @@ class Network extends BaseModule
self::$dateTo = $this->parameters['to'] ?? '';
if (DI::mode()->isMobile()) {
self::$itemsPerPage = DI::pConfig()->get(Session::getLocalUser(), 'system', 'itemspage_mobile_network',
self::$itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network',
DI::config()->get('system', 'itemspage_network_mobile'));
} else {
self::$itemsPerPage = DI::pConfig()->get(Session::getLocalUser(), 'system', 'itemspage_network',
self::$itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network',
DI::config()->get('system', 'itemspage_network'));
}
@ -385,7 +384,7 @@ class Network extends BaseModule
protected static function getItems(string $table, array $params, array $conditionFields = [])
{
$conditionFields['uid'] = Session::getLocalUser();
$conditionFields['uid'] = DI::userSession()->getLocalUserId();
$conditionStrings = [];
if (!is_null(self::$accountType)) {
@ -414,7 +413,7 @@ class Network extends BaseModule
} elseif (self::$forumContactId) {
$conditionStrings = DBA::mergeConditions($conditionStrings,
["((`contact-id` = ?) OR `uri-id` IN (SELECT `parent-uri-id` FROM `post-user-view` WHERE (`contact-id` = ? AND `gravity` = ? AND `vid` = ? AND `uid` = ?)))",
self::$forumContactId, self::$forumContactId, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), Session::getLocalUser()]);
self::$forumContactId, self::$forumContactId, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), DI::userSession()->getLocalUserId()]);
}
// Currently only the order modes "received" and "commented" are in use
@ -478,10 +477,10 @@ class Network extends BaseModule
// level which items you've seen and which you haven't. If you're looking
// at the top level network page just mark everything seen.
if (!self::$groupId && !self::$forumContactId && !self::$star && !self::$mention) {
$condition = ['unseen' => true, 'uid' => Session::getLocalUser()];
$condition = ['unseen' => true, 'uid' => DI::userSession()->getLocalUserId()];
self::setItemsSeenByCondition($condition);
} elseif (!empty($parents)) {
$condition = ['unseen' => true, 'uid' => Session::getLocalUser(), 'parent-uri-id' => $parents];
$condition = ['unseen' => true, 'uid' => DI::userSession()->getLocalUserId(), 'parent-uri-id' => $parents];
self::setItemsSeenByCondition($condition);
}

View file

@ -23,7 +23,6 @@ namespace Friendica\Module\Debug;
use Friendica\BaseModule;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\JsonLD;
@ -42,7 +41,7 @@ class ActivityPubConversion extends BaseModule
try {
$source = json_decode($_REQUEST['source'], true);
$trust_source = true;
$uid = Session::getLocalUser();
$uid = DI::userSession()->getLocalUserId();
$push = false;
if (!$source) {
@ -127,7 +126,7 @@ class ActivityPubConversion extends BaseModule
];
} catch (\Throwable $e) {
$results[] = [
'title' => DI::l10n()->t('Error'),
'title' => DI::l10n()->tt('Error', 'Errors', 1),
'content' => $e->getMessage(),
];
}

View file

@ -290,7 +290,7 @@ class Babel extends BaseModule
];
} else {
$results[] = [
'title' => DI::l10n()->t('Error'),
'title' => DI::l10n()->tt('Error', 'Errors', 1),
'content' => DI::l10n()->t('Twitter addon is absent from the addon/ folder.'),
];
}

View file

@ -25,7 +25,6 @@ use Friendica\App;
use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Model;
use Friendica\Module\Response;
@ -49,7 +48,7 @@ class Feed extends BaseModule
$this->httpClient = $httpClient;
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
DI::sysmsg()->addNotice($this->t('You must be logged in to use this module'));
$baseUrl->redirect();
}
@ -61,7 +60,7 @@ class Feed extends BaseModule
if (!empty($_REQUEST['url'])) {
$url = $_REQUEST['url'];
$contact = Model\Contact::getByURLForUser($url, Session::getLocalUser(), null);
$contact = Model\Contact::getByURLForUser($url, DI::userSession()->getLocalUserId(), null);
$xml = $this->httpClient->fetch($contact['poll'], HttpClientAccept::FEED_XML);

View file

@ -22,7 +22,6 @@
namespace Friendica\Module\Debug;
use Friendica\BaseModule;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Post;
@ -35,7 +34,7 @@ class ItemBody extends BaseModule
{
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
throw new HTTPException\UnauthorizedException(DI::l10n()->t('Access denied.'));
}
@ -45,7 +44,7 @@ class ItemBody extends BaseModule
$itemId = intval($this->parameters['item']);
$item = Post::selectFirst(['body'], ['uid' => [0, Session::getLocalUser()], 'uri-id' => $itemId]);
$item = Post::selectFirst(['body'], ['uid' => [0, DI::userSession()->getLocalUserId()], 'uri-id' => $itemId]);
if (!empty($item)) {
if (DI::mode()->isAjax()) {

View file

@ -23,7 +23,6 @@ namespace Friendica\Module\Debug;
use Friendica\BaseModule;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Network\HTTPException;
use Friendica\Network\Probe as NetworkProbe;
@ -35,7 +34,7 @@ class Probe extends BaseModule
{
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Only logged in users are permitted to perform a probing.'));
}

View file

@ -23,7 +23,6 @@ namespace Friendica\Module\Debug;
use Friendica\BaseModule;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Network\Probe;
@ -34,7 +33,7 @@ class WebFinger extends BaseModule
{
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
throw new \Friendica\Network\HTTPException\ForbiddenException(DI::l10n()->t('Only logged in users are permitted to perform a probing.'));
}

View file

@ -24,7 +24,6 @@ namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Notification;
@ -39,15 +38,15 @@ class Delegation extends BaseModule
{
protected function post(array $request = [])
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return;
}
$uid = Session::getLocalUser();
$uid = DI::userSession()->getLocalUserId();
$orig_record = User::getById(DI::app()->getLoggedInUserId());
if (DI::session()->get('submanage')) {
$user = User::getById(DI::session()->get('submanage'));
if (DI::userSession()->getSubManagedUserId()) {
$user = User::getById(DI::userSession()->getSubManagedUserId());
if (DBA::isResult($user)) {
$uid = intval($user['uid']);
$orig_record = $user;
@ -102,7 +101,7 @@ class Delegation extends BaseModule
DI::auth()->setForUser(DI::app(), $user, true, true);
if ($limited_id) {
DI::session()->set('submanage', $original_id);
DI::userSession()->setSubManagedUserId($original_id);
}
$ret = [];
@ -115,11 +114,11 @@ class Delegation extends BaseModule
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
throw new ForbiddenException(DI::l10n()->t('Permission denied.'));
}
$identities = User::identities(DI::session()->get('submanage', Session::getLocalUser()));
$identities = User::identities(DI::userSession()->getSubManagedUserId() ?: DI::userSession()->getLocalUserId());
//getting additinal information for each identity
foreach ($identities as $key => $identity) {

View file

@ -26,7 +26,6 @@ use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Content\Widget;
use Friendica\Core\Hook;
use Friendica\Core\Session;
use Friendica\Core\Renderer;
use Friendica\Core\Search;
use Friendica\DI;
@ -44,12 +43,12 @@ class Directory extends BaseModule
$app = DI::app();
$config = DI::config();
if (($config->get('system', 'block_public') && !Session::isAuthenticated()) ||
($config->get('system', 'block_local_dir') && !Session::isAuthenticated())) {
if (($config->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) ||
($config->get('system', 'block_local_dir') && !DI::userSession()->isAuthenticated())) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Public access denied.'));
}
if (Session::getLocalUser()) {
if (DI::userSession()->getLocalUserId()) {
DI::page()['aside'] .= Widget::findPeople();
DI::page()['aside'] .= Widget::follow();
}
@ -75,7 +74,7 @@ class Directory extends BaseModule
DI::sysmsg()->addNotice(DI::l10n()->t('No entries (some entries may be hidden).'));
} else {
foreach ($profiles['entries'] as $entry) {
$contact = Model\Contact::getByURLForUser($entry['url'], Session::getLocalUser());
$contact = Model\Contact::getByURLForUser($entry['url'], DI::userSession()->getLocalUserId());
if (!empty($contact)) {
$entries[] = Contact::getContactTemplateVars($contact);
}

View file

@ -21,7 +21,6 @@
namespace Friendica\Module\Events;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
@ -36,7 +35,7 @@ class Json extends \Friendica\BaseModule
{
protected function rawContent(array $request = [])
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
throw new HTTPException\UnauthorizedException();
}
@ -70,9 +69,9 @@ class Json extends \Friendica\BaseModule
// 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 = [];

View file

@ -22,7 +22,6 @@
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Protocol\Feed as ProtocolFeed;
@ -47,7 +46,7 @@ class Feed extends BaseModule
protected function rawContent(array $request = [])
{
$last_update = $this->getRequestValue($request, 'last_update', '');
$nocache = !empty($request['nocache']) && Session::getLocalUser();
$nocache = !empty($request['nocache']) && DI::userSession()->getLocalUserId();
$type = null;
// @TODO: Replace with parameter from router

View file

@ -24,7 +24,7 @@ namespace Friendica\Module\Filer;
use Friendica\App;
use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Core\Session;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\Post;
@ -41,12 +41,15 @@ class RemoveTag extends BaseModule
{
/** @var SystemMessages */
private $systemMessages;
/** @var IHandleUserSessions */
private $userSession;
public function __construct(SystemMessages $systemMessages, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
public function __construct(SystemMessages $systemMessages, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $userSession, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->systemMessages = $systemMessages;
$this->userSession = $userSession;
}
protected function post(array $request = [])
@ -56,7 +59,7 @@ class RemoveTag extends BaseModule
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!$this->userSession->getLocalUserId()) {
throw new HTTPException\ForbiddenException();
}
@ -108,7 +111,7 @@ class RemoveTag extends BaseModule
return 404;
}
if (!Post\Category::deleteFileByURIId($item['uri-id'], Session::getLocalUser(), $type, $term)) {
if (!Post\Category::deleteFileByURIId($item['uri-id'], $this->userSession->getLocalUserId(), $type, $term)) {
$this->systemMessages->addNotice($this->l10n->t('Item was not removed'));
return 500;
}

View file

@ -25,7 +25,6 @@ use Friendica\App;
use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model;
@ -44,7 +43,7 @@ class SaveTag extends BaseModule
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
DI::sysmsg()->addNotice($this->t('You must be logged in to use this module'));
$baseUrl->redirect();
}
@ -63,11 +62,11 @@ class SaveTag extends BaseModule
if (!DBA::isResult($item)) {
throw new HTTPException\NotFoundException();
}
Model\Post\Category::storeFileByURIId($item['uri-id'], Session::getLocalUser(), Model\Post\Category::FILE, $term);
Model\Post\Category::storeFileByURIId($item['uri-id'], DI::userSession()->getLocalUserId(), Model\Post\Category::FILE, $term);
}
// return filer dialog
$filetags = Model\Post\Category::getArray(Session::getLocalUser(), Model\Post\Category::FILE);
$filetags = Model\Post\Category::getArray(DI::userSession()->getLocalUserId(), Model\Post\Category::FILE);
$tpl = Renderer::getMarkupTemplate("filer_dialog.tpl");
echo Renderer::replaceMacros($tpl, [

View file

@ -22,7 +22,6 @@
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Model\Contact;
@ -34,7 +33,7 @@ class FollowConfirm extends BaseModule
protected function post(array $request = [])
{
parent::post($request);
$uid = Session::getLocalUser();
$uid = DI::userSession()->getLocalUserId();
if (!$uid) {
DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
return;
@ -44,7 +43,7 @@ class FollowConfirm extends BaseModule
$duplex = intval($_POST['duplex'] ?? 0);
$hidden = intval($_POST['hidden'] ?? 0);
$intro = DI::intro()->selectOneById($intro_id, Session::getLocalUser());
$intro = DI::intro()->selectOneById($intro_id, DI::userSession()->getLocalUserId());
Contact\Introduction::confirm($intro, $duplex, $hidden);
DI::intro()->delete($intro);

View file

@ -26,7 +26,6 @@ use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\Worker;
use Friendica\Database\Database;
use Friendica\DI;
@ -54,7 +53,7 @@ class FriendSuggest extends BaseModule
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
throw new ForbiddenException($this->t('Permission denied.'));
}
@ -68,7 +67,7 @@ class FriendSuggest extends BaseModule
$cid = intval($this->parameters['contact']);
// We do query the "uid" as well to ensure that it is our contact
if (!$this->dba->exists('contact', ['id' => $cid, 'uid' => Session::getLocalUser()])) {
if (!$this->dba->exists('contact', ['id' => $cid, 'uid' => DI::userSession()->getLocalUserId()])) {
throw new NotFoundException($this->t('Contact not found.'));
}
@ -78,7 +77,7 @@ class FriendSuggest extends BaseModule
}
// We do query the "uid" as well to ensure that it is our contact
$contact = $this->dba->selectFirst('contact', ['name', 'url', 'request', 'avatar'], ['id' => $suggest_contact_id, 'uid' => Session::getLocalUser()]);
$contact = $this->dba->selectFirst('contact', ['name', 'url', 'request', 'avatar'], ['id' => $suggest_contact_id, 'uid' => DI::userSession()->getLocalUserId()]);
if (empty($contact)) {
DI::sysmsg()->addNotice($this->t('Suggested contact not found.'));
return;
@ -87,7 +86,7 @@ class FriendSuggest extends BaseModule
$note = Strings::escapeHtml(trim($_POST['note'] ?? ''));
$suggest = $this->friendSuggestRepo->save($this->friendSuggestFac->createNew(
Session::getLocalUser(),
DI::userSession()->getLocalUserId(),
$cid,
$contact['name'],
$contact['url'],
@ -105,7 +104,7 @@ class FriendSuggest extends BaseModule
{
$cid = intval($this->parameters['contact']);
$contact = $this->dba->selectFirst('contact', [], ['id' => $cid, 'uid' => Session::getLocalUser()]);
$contact = $this->dba->selectFirst('contact', [], ['id' => $cid, 'uid' => DI::userSession()->getLocalUserId()]);
if (empty($contact)) {
DI::sysmsg()->addNotice($this->t('Contact not found.'));
$this->baseUrl->redirect();
@ -121,7 +120,7 @@ class FriendSuggest extends BaseModule
AND NOT `archive`
AND NOT `deleted`
AND `notify` != ""',
Session::getLocalUser(),
DI::userSession()->getLocalUserId(),
$cid,
Protocol::DFRN,
]);

View file

@ -23,7 +23,6 @@ namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
@ -37,7 +36,7 @@ class Group extends BaseModule
$this->ajaxPost();
}
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
DI::baseUrl()->redirect();
}
@ -47,9 +46,9 @@ class Group extends BaseModule
BaseModule::checkFormSecurityTokenRedirectOnError('/group/new', 'group_edit');
$name = trim($request['groupname']);
$r = Model\Group::create(Session::getLocalUser(), $name);
$r = Model\Group::create(DI::userSession()->getLocalUserId(), $name);
if ($r) {
$r = Model\Group::getIdByName(Session::getLocalUser(), $name);
$r = Model\Group::getIdByName(DI::userSession()->getLocalUserId(), $name);
if ($r) {
DI::baseUrl()->redirect('group/' . $r);
}
@ -63,7 +62,7 @@ class Group extends BaseModule
if ((DI::args()->getArgc() == 2) && intval(DI::args()->getArgv()[1])) {
BaseModule::checkFormSecurityTokenRedirectOnError('/group', 'group_edit');
$group = DBA::selectFirst('group', ['id', 'name'], ['id' => DI::args()->getArgv()[1], 'uid' => Session::getLocalUser()]);
$group = DBA::selectFirst('group', ['id', 'name'], ['id' => DI::args()->getArgv()[1], 'uid' => DI::userSession()->getLocalUserId()]);
if (!DBA::isResult($group)) {
DI::sysmsg()->addNotice(DI::l10n()->t('Group not found.'));
DI::baseUrl()->redirect('contact');
@ -80,7 +79,7 @@ class Group extends BaseModule
public function ajaxPost()
{
try {
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
throw new \Exception(DI::l10n()->t('Permission denied.'), 403);
}
@ -88,12 +87,12 @@ class Group extends BaseModule
$group_id = $this->parameters['group'];
$contact_id = $this->parameters['contact'];
if (!Model\Group::exists($group_id, Session::getLocalUser())) {
if (!Model\Group::exists($group_id, DI::userSession()->getLocalUserId())) {
throw new \Exception(DI::l10n()->t('Unknown group.'), 404);
}
// @TODO Backward compatibility with user contacts, remove by version 2022.03
$cdata = Model\Contact::getPublicAndUserContactID($contact_id, Session::getLocalUser());
$cdata = Model\Contact::getPublicAndUserContactID($contact_id, DI::userSession()->getLocalUserId());
if (empty($cdata['public'])) {
throw new \Exception(DI::l10n()->t('Contact not found.'), 404);
}
@ -143,7 +142,7 @@ class Group extends BaseModule
{
$change = false;
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
throw new \Friendica\Network\HTTPException\ForbiddenException();
}
@ -158,7 +157,7 @@ class Group extends BaseModule
}
// Switch to text mode interface if we have more than 'n' contacts or group members
$switchtotext = DI::pConfig()->get(Session::getLocalUser(), 'system', 'groupedit_image_limit');
$switchtotext = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'groupedit_image_limit');
if (is_null($switchtotext)) {
$switchtotext = DI::config()->get('system', 'groupedit_image_limit', 200);
}
@ -210,7 +209,7 @@ class Group extends BaseModule
// @TODO: Replace with parameter from router
if (intval(DI::args()->getArgv()[2])) {
if (!Model\Group::exists(DI::args()->getArgv()[2], Session::getLocalUser())) {
if (!Model\Group::exists(DI::args()->getArgv()[2], DI::userSession()->getLocalUserId())) {
DI::sysmsg()->addNotice(DI::l10n()->t('Group not found.'));
DI::baseUrl()->redirect('contact');
}
@ -226,14 +225,14 @@ class Group extends BaseModule
if ((DI::args()->getArgc() > 2) && intval(DI::args()->getArgv()[1]) && intval(DI::args()->getArgv()[2])) {
BaseModule::checkFormSecurityTokenForbiddenOnError('group_member_change', 't');
if (DBA::exists('contact', ['id' => DI::args()->getArgv()[2], 'uid' => Session::getLocalUser(), 'self' => false, 'pending' => false, 'blocked' => false])) {
if (DBA::exists('contact', ['id' => DI::args()->getArgv()[2], 'uid' => DI::userSession()->getLocalUserId(), 'self' => false, 'pending' => false, 'blocked' => false])) {
$change = intval(DI::args()->getArgv()[2]);
}
}
// @TODO: Replace with parameter from router
if ((DI::args()->getArgc() > 1) && intval(DI::args()->getArgv()[1])) {
$group = DBA::selectFirst('group', ['id', 'name'], ['id' => DI::args()->getArgv()[1], 'uid' => Session::getLocalUser(), 'deleted' => false]);
$group = DBA::selectFirst('group', ['id', 'name'], ['id' => DI::args()->getArgv()[1], 'uid' => DI::userSession()->getLocalUserId(), 'deleted' => false]);
if (!DBA::isResult($group)) {
DI::sysmsg()->addNotice(DI::l10n()->t('Group not found.'));
DI::baseUrl()->redirect('contact');
@ -316,11 +315,11 @@ class Group extends BaseModule
}
if ($nogroup) {
$contacts = Model\Contact\Group::listUngrouped(Session::getLocalUser());
$contacts = Model\Contact\Group::listUngrouped(DI::userSession()->getLocalUserId());
} else {
$contacts_stmt = DBA::select('contact', [],
['rel' => [Model\Contact::FOLLOWER, Model\Contact::FRIEND, Model\Contact::SHARING],
'uid' => Session::getLocalUser(), 'pending' => false, 'blocked' => false, 'failed' => false, 'self' => false],
'uid' => DI::userSession()->getLocalUserId(), 'pending' => false, 'blocked' => false, 'failed' => false, 'self' => false],
['order' => ['name']]
);
$contacts = DBA::toArray($contacts_stmt);

View file

@ -22,7 +22,6 @@
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Model\Profile;
use Friendica\Model\User;
@ -36,7 +35,7 @@ class HCard extends BaseModule
{
protected function content(array $request = []): string
{
if (Session::getLocalUser() && ($this->parameters['action'] ?? '') === 'view') {
if (DI::userSession()->getLocalUserId() && ($this->parameters['action'] ?? '') === 'view') {
// A logged in user views a profile of a user
$nickname = DI::app()->getLoggedInUserNickname();
} elseif (empty($this->parameters['action'])) {
@ -78,7 +77,7 @@ class HCard extends BaseModule
$page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"" . $baseUrl->get() . "/dfrn_{$dfrn}/{$nickname}\" />\r\n";
}
$block = (DI::config()->get('system', 'block_public') && !Session::isAuthenticated());
$block = (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated());
// check if blocked
if ($block) {

View file

@ -24,7 +24,6 @@ namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Module\Security\Login;
@ -43,7 +42,7 @@ class Home extends BaseModule
Hook::callAll('home_init', $ret);
if (Session::getLocalUser() && ($app->getLoggedInUserNickname())) {
if (DI::userSession()->getLocalUserId() && ($app->getLoggedInUserNickname())) {
DI::baseUrl()->redirect('network');
}

View file

@ -24,7 +24,6 @@ namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\Renderer;
use Friendica\Core\Search;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Model;
use Friendica\Model\User;
@ -39,7 +38,7 @@ class Invite extends BaseModule
{
protected function post(array $request = [])
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
@ -53,7 +52,7 @@ class Invite extends BaseModule
$max_invites = 50;
}
$current_invites = intval(DI::pConfig()->get(Session::getLocalUser(), 'system', 'sent_invites'));
$current_invites = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'sent_invites'));
if ($current_invites > $max_invites) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Total invitation limit exceeded.'));
}
@ -68,13 +67,13 @@ class Invite extends BaseModule
if ($config->get('system', 'invitation_only')) {
$invitation_only = true;
$invites_remaining = DI::pConfig()->get(Session::getLocalUser(), 'system', 'invites_remaining');
$invites_remaining = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'invites_remaining');
if ((!$invites_remaining) && (!$app->isSiteAdmin())) {
throw new HTTPException\ForbiddenException();
}
}
$user = User::getById(Session::getLocalUser());
$user = User::getById(DI::userSession()->getLocalUserId());
foreach ($recipients as $recipient) {
$recipient = trim($recipient);
@ -91,7 +90,7 @@ class Invite extends BaseModule
if (!$app->isSiteAdmin()) {
$invites_remaining--;
if ($invites_remaining >= 0) {
DI::pConfig()->set(Session::getLocalUser(), 'system', 'invites_remaining', $invites_remaining);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'invites_remaining', $invites_remaining);
} else {
return;
}
@ -113,7 +112,7 @@ class Invite extends BaseModule
if ($res) {
$total++;
$current_invites++;
DI::pConfig()->set(Session::getLocalUser(), 'system', 'sent_invites', $current_invites);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'sent_invites', $current_invites);
if ($current_invites > $max_invites) {
DI::sysmsg()->addNotice(DI::l10n()->t('Invitation limit exceeded. Please contact your site administrator.'));
return;
@ -128,7 +127,7 @@ class Invite extends BaseModule
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
@ -139,7 +138,7 @@ class Invite extends BaseModule
if ($config->get('system', 'invitation_only')) {
$inviteOnly = true;
$x = DI::pConfig()->get(Session::getLocalUser(), 'system', 'invites_remaining');
$x = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'invites_remaining');
if ((!$x) && (!$app->isSiteAdmin())) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('You have no more invitations available'));
}

Some files were not shown because too many files have changed in this diff Show more