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

@ -27,13 +27,13 @@ use Friendica\App\BaseURL;
use Friendica\Capabilities\ICanCreateResponses;
use Friendica\Core\Config\Factory\Config;
use Friendica\Core\Session\Capability\IHandleSessions;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Module\Maintenance;
use Friendica\Security\Authentication;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\L10n;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Core\Theme;
use Friendica\Database\Database;
@ -134,6 +134,11 @@ class App
*/
private $session;
/**
* @var IHandleUserSessions
*/
private $userSession;
/**
* Set the user ID
*
@ -158,7 +163,7 @@ class App
public function isLoggedIn(): bool
{
return Session::getLocalUser() && $this->user_id && ($this->user_id == Session::getLocalUser());
return $this->userSession->getLocalUserId() && $this->user_id && ($this->user_id == $this->userSession->getLocalUserId());
}
/**
@ -172,7 +177,7 @@ class App
$adminlist = explode(',', str_replace(' ', '', $admin_email));
return Session::getLocalUser() && $admin_email && $this->database->exists('user', ['uid' => $this->getLoggedInUserId(), 'email' => $adminlist]);
return $this->userSession->getLocalUserId() && $admin_email && $this->database->exists('user', ['uid' => $this->getLoggedInUserId(), 'email' => $adminlist]);
}
/**
@ -337,18 +342,19 @@ class App
* @param IManagePersonalConfigValues $pConfig Personal configuration
* @param IHandleSessions $session The Session handler
*/
public function __construct(Database $database, IManageConfigValues $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, IManagePersonalConfigValues $pConfig, IHandleSessions $session)
public function __construct(Database $database, IManageConfigValues $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, IManagePersonalConfigValues $pConfig, IHandleSessions $session, IHandleUserSessions $userSession)
{
$this->database = $database;
$this->config = $config;
$this->mode = $mode;
$this->baseURL = $baseURL;
$this->profiler = $profiler;
$this->logger = $logger;
$this->l10n = $l10n;
$this->args = $args;
$this->pConfig = $pConfig;
$this->session = $session;
$this->database = $database;
$this->config = $config;
$this->mode = $mode;
$this->baseURL = $baseURL;
$this->profiler = $profiler;
$this->logger = $logger;
$this->l10n = $l10n;
$this->args = $args;
$this->pConfig = $pConfig;
$this->session = $session;
$this->userSession = $userSession;
$this->load();
}
@ -496,11 +502,11 @@ class App
$page_theme = null;
// Find the theme that belongs to the user whose stuff we are looking at
if (!empty($this->profile_owner) && ($this->profile_owner != Session::getLocalUser())) {
if (!empty($this->profile_owner) && ($this->profile_owner != $this->userSession->getLocalUserId())) {
// Allow folks to override user themes and always use their own on their own site.
// This works only if the user is on the same server
$user = $this->database->selectFirst('user', ['theme'], ['uid' => $this->profile_owner]);
if ($this->database->isResult($user) && !Session::getLocalUser()) {
if ($this->database->isResult($user) && !$this->userSession->getLocalUserId()) {
$page_theme = $user['theme'];
}
}
@ -529,10 +535,10 @@ class App
$page_mobile_theme = null;
// Find the theme that belongs to the user whose stuff we are looking at
if (!empty($this->profile_owner) && ($this->profile_owner != Session::getLocalUser())) {
if (!empty($this->profile_owner) && ($this->profile_owner != $this->userSession->getLocalUserId())) {
// Allow folks to override user themes and always use their own on their own site.
// This works only if the user is on the same server
if (!Session::getLocalUser()) {
if (!$this->userSession->getLocalUserId()) {
$page_mobile_theme = $this->pConfig->get($this->profile_owner, 'system', 'mobile-theme');
}
}
@ -629,7 +635,7 @@ class App
}
// ZRL
if (!empty($_GET['zrl']) && $this->mode->isNormal() && !$this->mode->isBackend() && !Session::getLocalUser()) {
if (!empty($_GET['zrl']) && $this->mode->isNormal() && !$this->mode->isBackend() && !$this->userSession->getLocalUserId()) {
// Only continue when the given profile link seems valid
// Valid profile links contain a path with "/profile/" and no query parameters
if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == '') &&
@ -737,7 +743,7 @@ class App
$response = $module->run($input);
$this->profiler->set(microtime(true) - $timestamp, 'content');
if ($response->getHeaderLine(ICanCreateResponses::X_HEADER) === ICanCreateResponses::TYPE_HTML) {
$page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig);
$page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig, $this->userSession->getLocalUserId());
} else {
$page->exit($response);
}

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;
@ -222,17 +221,18 @@ class Page implements ArrayAccess
* - Infinite scroll data
* - head.tpl template
*
* @param App $app The Friendica App instance
* @param Arguments $args The Friendica App Arguments
* @param L10n $l10n The l10n language instance
* @param IManageConfigValues $config The Friendica configuration
* @param IManagePersonalConfigValues $pConfig The Friendica personal configuration (for user)
* @param App $app The Friendica App instance
* @param Arguments $args The Friendica App Arguments
* @param L10n $l10n The l10n language instance
* @param IManageConfigValues $config The Friendica configuration
* @param IManagePersonalConfigValues $pConfig The Friendica personal configuration (for user)
* @param int $localUID The local user id
*
* @throws HTTPException\InternalServerErrorException
*/
private function initHead(App $app, Arguments $args, L10n $l10n, IManageConfigValues $config, IManagePersonalConfigValues $pConfig)
private function initHead(App $app, Arguments $args, L10n $l10n, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, int $localUID)
{
$interval = ((Session::getLocalUser()) ? $pConfig->get(Session::getLocalUser(), 'system', 'update_interval') : 40000);
$interval = ($localUID ? $pConfig->get($localUID, 'system', 'update_interval') : 40000);
// If the update is 'deactivated' set it to the highest integer number (~24 days)
if ($interval < 0) {
@ -277,7 +277,7 @@ class Page implements ArrayAccess
* being first
*/
$this->page['htmlhead'] = Renderer::replaceMacros($tpl, [
'$local_user' => Session::getLocalUser(),
'$local_user' => $localUID,
'$generator' => 'Friendica' . ' ' . App::VERSION,
'$delitem' => $l10n->t('Delete this item?'),
'$blockAuthor' => $l10n->t('Block this author? They won\'t be able to follow you nor see your public posts, and you won\'t be able to see their posts and their notifications.'),
@ -444,10 +444,11 @@ class Page implements ArrayAccess
* @param L10n $l10n The l10n language class
* @param IManageConfigValues $config The Configuration of this node
* @param IManagePersonalConfigValues $pconfig The personal/user configuration
* @param int $localUID The UID of the local user
*
* @throws HTTPException\InternalServerErrorException|HTTPException\ServiceUnavailableException
*/
public function run(App $app, BaseURL $baseURL, Arguments $args, Mode $mode, ResponseInterface $response, L10n $l10n, Profiler $profiler, IManageConfigValues $config, IManagePersonalConfigValues $pconfig)
public function run(App $app, BaseURL $baseURL, Arguments $args, Mode $mode, ResponseInterface $response, L10n $l10n, Profiler $profiler, IManageConfigValues $config, IManagePersonalConfigValues $pconfig, int $localUID)
{
$moduleName = $args->getModuleName();
@ -481,7 +482,7 @@ class Page implements ArrayAccess
* all the module functions have executed so that all
* theme choices made by the modules can take effect.
*/
$this->initHead($app, $args, $l10n, $config, $pconfig);
$this->initHead($app, $args, $l10n, $config, $pconfig, $localUID);
/* Build the page ending -- this is stuff that goes right before
* the closing </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,22 +80,25 @@ class Conversation
private $mode;
/** @var IHandleSessions */
private $session;
/** @var IHandleUserSessions */
private $userSession;
public function __construct(LoggerInterface $logger, Profiler $profiler, Activity $activity, L10n $l10n, Item $item, Arguments $args, BaseURL $baseURL, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, App\Page $page, App\Mode $mode, App $app, IHandleSessions $session)
public function __construct(LoggerInterface $logger, Profiler $profiler, Activity $activity, L10n $l10n, Item $item, Arguments $args, BaseURL $baseURL, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, App\Page $page, App\Mode $mode, App $app, IHandleSessions $session, IHandleUserSessions $userSession)
{
$this->activity = $activity;
$this->item = $item;
$this->config = $config;
$this->mode = $mode;
$this->baseURL = $baseURL;
$this->profiler = $profiler;
$this->logger = $logger;
$this->l10n = $l10n;
$this->args = $args;
$this->pConfig = $pConfig;
$this->page = $page;
$this->app = $app;
$this->session = $session;
$this->activity = $activity;
$this->item = $item;
$this->config = $config;
$this->mode = $mode;
$this->baseURL = $baseURL;
$this->profiler = $profiler;
$this->logger = $logger;
$this->l10n = $l10n;
$this->args = $args;
$this->pConfig = $pConfig;
$this->page = $page;
$this->app = $app;
$this->session = $session;
$this->userSession = $userSession;
}
/**
@ -172,7 +175,7 @@ class Conversation
continue;
}
if (Session::getPublicContact() == $activity['author-id']) {
if ($this->userSession->getPublicContactId() == $activity['author-id']) {
$conv_responses[$mode][$activity['thr-parent-id']]['self'] = 1;
}
@ -297,7 +300,7 @@ class Conversation
$x['bang'] = $x['bang'] ?? '';
$x['visitor'] = $x['visitor'] ?? 'block';
$x['is_owner'] = $x['is_owner'] ?? true;
$x['profile_uid'] = $x['profile_uid'] ?? Session::getLocalUser();
$x['profile_uid'] = $x['profile_uid'] ?? $this->userSession->getLocalUserId();
$geotag = !empty($x['allow_location']) ? Renderer::replaceMacros(Renderer::getMarkupTemplate('jot_geotag.tpl'), []) : '';
@ -360,7 +363,7 @@ class Conversation
'$title' => $x['title'] ?? '',
'$placeholdertitle' => $this->l10n->t('Set title'),
'$category' => $x['category'] ?? '',
'$placeholdercategory' => Feature::isEnabled(Session::getLocalUser(), 'categories') ? $this->l10n->t("Categories \x28comma-separated list\x29") : '',
'$placeholdercategory' => Feature::isEnabled($this->userSession->getLocalUserId(), 'categories') ? $this->l10n->t("Categories \x28comma-separated list\x29") : '',
'$scheduled_at' => Temporal::getDateTimeField(
new \DateTime(),
new \DateTime('now + 6 months'),
@ -398,7 +401,7 @@ class Conversation
'$browser' => $this->l10n->t('Browser'),
'$compose_link_title' => $this->l10n->t('Open Compose page'),
'$always_open_compose' => $this->pConfig->get(Session::getLocalUser(), 'frio', 'always_open_compose', false),
'$always_open_compose' => $this->pConfig->get($this->userSession->getLocalUserId(), 'frio', 'always_open_compose', false),
]);
@ -437,7 +440,7 @@ class Conversation
$this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.css'));
$this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput-typeahead.css'));
$ssl_state = (bool)Session::getLocalUser();
$ssl_state = (bool)$this->userSession->getLocalUserId();
$live_update_div = '';
@ -489,11 +492,11 @@ class Conversation
}
}
} elseif ($mode === 'notes') {
$items = $this->addChildren($items, false, $order, Session::getLocalUser(), $mode);
$items = $this->addChildren($items, false, $order, $this->userSession->getLocalUserId(), $mode);
if (!$update) {
$live_update_div = '<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->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 = '';
@ -66,13 +66,13 @@ class ContactBlock
$contacts = [];
$total = DBA::count('contact', [
'uid' => $profile['uid'],
'self' => false,
'uid' => $profile['uid'],
'self' => false,
'blocked' => false,
'pending' => false,
'hidden' => false,
'hidden' => false,
'archive' => false,
'failed' => false,
'failed' => false,
'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::FEED],
]);
@ -89,15 +89,17 @@ class ContactBlock
}
$personal_contacts = DBA::selectToArray('contact', ['uri-id'], [
'uid' => $profile['uid'],
'self' => false,
'uid' => $profile['uid'],
'self' => false,
'blocked' => false,
'pending' => false,
'hidden' => false,
'hidden' => false,
'archive' => false,
'rel' => $rel,
'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,17 +56,17 @@ 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');
$o = Renderer::replaceMacros($tpl, [
'$title' => DI::l10n()->t('Tags'),
'$tags' => $tags
'$tags' => $tags
]);
}
return $o;

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);
@ -49,8 +50,8 @@ class TrendingTags
$tpl = Renderer::getMarkupTemplate('widget/trending_tags.tpl');
$o = Renderer::replaceMacros($tpl, [
'$title' => DI::l10n()->tt('Trending Tags (last %d hour)', 'Trending Tags (last %d hours)', $period),
'$more' => DI::l10n()->t('More Trending Tags'),
'$tags' => $tags,
'$more' => DI::l10n()->t('More Trending Tags'),
'$tags' => $tags,
]);
return $o;

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

View file

@ -26,7 +26,6 @@ use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Core\Session;
use Friendica\Model\Post;
use Friendica\Network\HTTPException;
use Friendica\Protocol\Diaspora;
@ -39,7 +38,7 @@ class Activity extends BaseModule
{
protected function rawContent(array $request = [])
{
if (!Session::isAuthenticated()) {
if (!DI::userSession()->isAuthenticated()) {
throw new HTTPException\ForbiddenException();
}
@ -51,13 +50,13 @@ class Activity extends BaseModule
$itemId = $this->parameters['id'];
if (in_array($verb, ['announce', 'unannounce'])) {
$item = Post::selectFirst(['network', 'uri-id'], ['id' => $itemId, 'uid' => [Session::getLocalUser(), 0]]);
$item = Post::selectFirst(['network', 'uri-id'], ['id' => $itemId, 'uid' => [DI::userSession()->getLocalUserId(), 0]]);
if ($item['network'] == Protocol::DIASPORA) {
Diaspora::performReshare($item['uri-id'], Session::getLocalUser());
Diaspora::performReshare($item['uri-id'], DI::userSession()->getLocalUserId());
}
}
if (!Item::performActivity($itemId, $verb, Session::getLocalUser())) {
if (!Item::performActivity($itemId, $verb, DI::userSession()->getLocalUserId())) {
throw new HTTPException\BadRequestException();
}

View file

@ -31,7 +31,6 @@ use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\Theme;
use Friendica\Database\DBA;
use Friendica\DI;
@ -89,7 +88,7 @@ class Compose extends BaseModule
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return Login::form('compose');
}
@ -111,7 +110,7 @@ class Compose extends BaseModule
}
}
$user = User::getById(Session::getLocalUser(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'default-location']);
$user = User::getById(DI::userSession()->getLocalUserId(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'default-location']);
$contact_allow_list = $this->ACLFormatter->expand($user['allow_cid']);
$group_allow_list = $this->ACLFormatter->expand($user['allow_gid']);
@ -168,7 +167,7 @@ class Compose extends BaseModule
$contact = Contact::getById($a->getContactId());
if ($this->pConfig->get(Session::getLocalUser(), 'system', 'set_creation_date')) {
if ($this->pConfig->get(DI::userSession()->getLocalUserId(), 'system', 'set_creation_date')) {
$created_at = Temporal::getDateTimeField(
new \DateTime(DBA::NULL_DATETIME),
new \DateTime('now'),
@ -204,8 +203,8 @@ class Compose extends BaseModule
'location_disabled' => $this->l10n->t('Location services are disabled. Please check the website\'s permissions on your device'),
'wait' => $this->l10n->t('Please wait'),
'placeholdertitle' => $this->l10n->t('Set title'),
'placeholdercategory' => Feature::isEnabled(Session::getLocalUser(),'categories') ? $this->l10n->t('Categories (comma-separated list)') : '',
'always_open_compose' => $this->pConfig->get(Session::getLocalUser(), 'frio', 'always_open_compose',
'placeholdercategory' => Feature::isEnabled(DI::userSession()->getLocalUserId(),'categories') ? $this->l10n->t('Categories (comma-separated list)') : '',
'always_open_compose' => $this->pConfig->get(DI::userSession()->getLocalUserId(), 'frio', 'always_open_compose',
$this->config->get('frio', 'always_open_compose', false)) ? '' :
$this->l10n->t('You can make this page always open when you use the New Post button in the <a href="/settings/display">Theme Customization settings</a>.'),
],

View file

@ -22,7 +22,6 @@
namespace Friendica\Module\Item;
use Friendica\BaseModule;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Item;
@ -38,7 +37,7 @@ class Follow extends BaseModule
{
$l10n = DI::l10n();
if (!Session::isAuthenticated()) {
if (!DI::userSession()->isAuthenticated()) {
throw new HttpException\ForbiddenException($l10n->t('Access denied.'));
}
@ -48,7 +47,7 @@ class Follow extends BaseModule
$itemId = intval($this->parameters['id']);
if (!Item::performActivity($itemId, 'follow', Session::getLocalUser())) {
if (!Item::performActivity($itemId, 'follow', DI::userSession()->getLocalUserId())) {
throw new HTTPException\BadRequestException($l10n->t('Unable to follow this item.'));
}

View file

@ -22,7 +22,6 @@
namespace Friendica\Module\Item;
use Friendica\BaseModule;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Item;
@ -38,7 +37,7 @@ class Ignore extends BaseModule
{
$l10n = DI::l10n();
if (!Session::isAuthenticated()) {
if (!DI::userSession()->isAuthenticated()) {
throw new HttpException\ForbiddenException($l10n->t('Access denied.'));
}
@ -55,10 +54,10 @@ class Ignore extends BaseModule
throw new HTTPException\NotFoundException();
}
$ignored = !Post\ThreadUser::getIgnored($thread['uri-id'], Session::getLocalUser());
$ignored = !Post\ThreadUser::getIgnored($thread['uri-id'], DI::userSession()->getLocalUserId());
if (in_array($thread['uid'], [0, Session::getLocalUser()])) {
Post\ThreadUser::setIgnored($thread['uri-id'], Session::getLocalUser(), $ignored);
if (in_array($thread['uid'], [0, DI::userSession()->getLocalUserId()])) {
Post\ThreadUser::setIgnored($thread['uri-id'], DI::userSession()->getLocalUserId(), $ignored);
} else {
throw new HTTPException\BadRequestException();
}

View file

@ -22,7 +22,6 @@
namespace Friendica\Module\Item;
use Friendica\BaseModule;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
@ -38,7 +37,7 @@ class Pin extends BaseModule
{
$l10n = DI::l10n();
if (!Session::isAuthenticated()) {
if (!DI::userSession()->isAuthenticated()) {
throw new HttpException\ForbiddenException($l10n->t('Access denied.'));
}
@ -53,16 +52,16 @@ class Pin extends BaseModule
throw new HTTPException\NotFoundException();
}
if (!in_array($item['uid'], [0, Session::getLocalUser()])) {
if (!in_array($item['uid'], [0, DI::userSession()->getLocalUserId()])) {
throw new HttpException\ForbiddenException($l10n->t('Access denied.'));
}
$pinned = !$item['featured'];
if ($pinned) {
Post\Collection::add($item['uri-id'], Post\Collection::FEATURED, $item['author-id'], Session::getLocalUser());
Post\Collection::add($item['uri-id'], Post\Collection::FEATURED, $item['author-id'], DI::userSession()->getLocalUserId());
} else {
Post\Collection::remove($item['uri-id'], Post\Collection::FEATURED, Session::getLocalUser());
Post\Collection::remove($item['uri-id'], Post\Collection::FEATURED, DI::userSession()->getLocalUserId());
}
// See if we've been passed a return path to redirect to

View file

@ -22,7 +22,6 @@
namespace Friendica\Module\Item;
use Friendica\BaseModule;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
@ -39,7 +38,7 @@ class Star extends BaseModule
{
$l10n = DI::l10n();
if (!Session::isAuthenticated()) {
if (!DI::userSession()->isAuthenticated()) {
throw new HttpException\ForbiddenException($l10n->t('Access denied.'));
}
@ -50,13 +49,13 @@ class Star extends BaseModule
$itemId = intval($this->parameters['id']);
$item = Post::selectFirstForUser(Session::getLocalUser(), ['uid', 'uri-id', 'starred'], ['uid' => [0, Session::getLocalUser()], 'id' => $itemId]);
$item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), ['uid', 'uri-id', 'starred'], ['uid' => [0, DI::userSession()->getLocalUserId()], 'id' => $itemId]);
if (empty($item)) {
throw new HTTPException\NotFoundException();
}
if ($item['uid'] == 0) {
$stored = Item::storeForUserByUriId($item['uri-id'], Session::getLocalUser(), ['post-reason' => Item::PR_ACTIVITY]);
$stored = Item::storeForUserByUriId($item['uri-id'], DI::userSession()->getLocalUserId(), ['post-reason' => Item::PR_ACTIVITY]);
if (!empty($stored)) {
$item = Post::selectFirst(['starred'], ['id' => $stored]);
if (!DBA::isResult($item)) {

View file

@ -24,7 +24,7 @@ namespace Friendica\Module;
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\Database;
use Friendica\Model\Contact;
@ -50,14 +50,17 @@ class Magic extends BaseModule
protected $dba;
/** @var ICanSendHttpRequests */
protected $httpClient;
/** @var IHandleUserSessions */
protected $userSession;
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Database $dba, ICanSendHttpRequests $httpClient, array $server, array $parameters = [])
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Database $dba, ICanSendHttpRequests $httpClient, IHandleUserSessions $userSession, $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->app = $app;
$this->dba = $dba;
$this->httpClient = $httpClient;
$this->app = $app;
$this->dba = $dba;
$this->httpClient = $httpClient;
$this->userSession = $userSession;
}
protected function rawContent(array $request = [])
@ -91,8 +94,8 @@ class Magic extends BaseModule
}
// OpenWebAuth
if (Session::getLocalUser() && $owa) {
$user = User::getById(Session::getLocalUser());
if ($this->userSession->getLocalUserId() && $owa) {
$user = User::getById($this->userSession->getLocalUserId());
// Extract the basepath
// NOTE: we need another solution because this does only work

View file

@ -22,7 +22,6 @@
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
@ -43,7 +42,7 @@ class NoScrape extends BaseModule
if (isset($this->parameters['nick'])) {
// Get infos about a specific nick (public)
$which = $this->parameters['nick'];
} elseif (Session::getLocalUser() && isset($this->parameters['profile']) && DI::args()->get(2) == 'view') {
} elseif (DI::userSession()->getLocalUserId() && isset($this->parameters['profile']) && DI::args()->get(2) == 'view') {
// view infos about a known profile (needs a login)
$which = $a->getLoggedInUserNickname();
} else {

View file

@ -30,7 +30,7 @@ use Friendica\Content\Text\BBCode;
use Friendica\Core\L10n;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\DI;
use Friendica\Model\User;
use Friendica\Module\BaseNotifications;
@ -50,9 +50,9 @@ class Introductions extends BaseNotifications
/** @var Mode */
protected $mode;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Mode $mode, IntroductionFactory $notificationIntro, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Mode $mode, IntroductionFactory $notificationIntro, IHandleUserSessions $userSession, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $userSession, $server, $parameters);
$this->notificationIntro = $notificationIntro;
$this->mode = $mode;
@ -99,7 +99,7 @@ class Introductions extends BaseNotifications
'text' => (!$all ? $this->t('Show Ignored Requests') : $this->t('Hide Ignored Requests')),
];
$owner = User::getOwnerDataById(Session::getLocalUser());
$owner = User::getOwnerDataById(DI::userSession()->getLocalUserId());
// Loop through all introduction notifications.This creates an array with the output html for each
// introduction

View file

@ -26,7 +26,6 @@ use Friendica\BaseModule;
use Friendica\Contact\Introduction\Repository\Introduction;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Contact;
@ -73,14 +72,14 @@ class Notification extends BaseModule
*/
protected function post(array $request = [])
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
throw new HTTPException\UnauthorizedException($this->l10n->t('Permission denied.'));
}
$request_id = $this->parameters['id'] ?? false;
if ($request_id) {
$intro = $this->introductionRepo->selectOneById($request_id, Session::getLocalUser());
$intro = $this->introductionRepo->selectOneById($request_id, DI::userSession()->getLocalUserId());
switch ($_POST['submit']) {
case $this->l10n->t('Discard'):
@ -104,14 +103,14 @@ class Notification extends BaseModule
*/
protected function rawContent(array $request = [])
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
throw new HTTPException\UnauthorizedException($this->l10n->t('Permission denied.'));
}
if ($this->args->get(1) === 'mark' && $this->args->get(2) === 'all') {
try {
$this->notificationRepo->setAllSeenForUser(Session::getLocalUser());
$success = $this->notifyRepo->setAllSeenForUser(Session::getLocalUser());
$this->notificationRepo->setAllSeenForUser(DI::userSession()->getLocalUserId());
$success = $this->notifyRepo->setAllSeenForUser(DI::userSession()->getLocalUserId());
} catch (\Exception $e) {
$this->logger->warning('set all seen failed.', ['exception' => $e]);
$success = false;
@ -132,7 +131,7 @@ class Notification extends BaseModule
*/
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
DI::sysmsg()->addNotice($this->l10n->t('You must be logged in to show this page.'));
return Login::form();
}
@ -151,11 +150,11 @@ class Notification extends BaseModule
private function handleNotify(int $notifyId)
{
$Notify = $this->notifyRepo->selectOneById($notifyId);
if ($Notify->uid !== Session::getLocalUser()) {
if ($Notify->uid !== DI::userSession()->getLocalUserId()) {
throw new HTTPException\ForbiddenException();
}
if ($this->pconfig->get(Session::getLocalUser(), 'system', 'detailed_notif')) {
if ($this->pconfig->get(DI::userSession()->getLocalUserId(), 'system', 'detailed_notif')) {
$Notify->setSeen();
$this->notifyRepo->save($Notify);
} else {
@ -176,11 +175,11 @@ class Notification extends BaseModule
private function handleNotification(int $notificationId)
{
$Notification = $this->notificationRepo->selectOneById($notificationId);
if ($Notification->uid !== Session::getLocalUser()) {
if ($Notification->uid !== DI::userSession()->getLocalUserId()) {
throw new HTTPException\ForbiddenException();
}
if ($this->pconfig->get(Session::getLocalUser(), 'system', 'detailed_notif')) {
if ($this->pconfig->get(DI::userSession()->getLocalUserId(), 'system', 'detailed_notif')) {
$Notification->setSeen();
$this->notificationRepo->save($Notification);
} else {

View file

@ -26,6 +26,7 @@ use Friendica\App\Arguments;
use Friendica\Content\Nav;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Module\BaseNotifications;
use Friendica\Module\Response;
use Friendica\Navigation\Notifications\ValueObject\FormattedNotify;
@ -44,9 +45,9 @@ class Notifications extends BaseNotifications
/** @var \Friendica\Navigation\Notifications\Factory\FormattedNotify */
protected $formattedNotifyFactory;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, \Friendica\Navigation\Notifications\Factory\FormattedNotify $formattedNotifyFactory, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, \Friendica\Navigation\Notifications\Factory\FormattedNotify $formattedNotifyFactory, IHandleUserSessions $userSession, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $userSession, $server, $parameters);
$this->formattedNotifyFactory = $formattedNotifyFactory;
}

View file

@ -28,7 +28,6 @@ use Friendica\Content\ForumManager;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
@ -91,18 +90,18 @@ class Ping extends BaseModule
$today_birthday_count = 0;
if (Session::getLocalUser()) {
if (DI::pConfig()->get(Session::getLocalUser(), 'system', 'detailed_notif')) {
$notifications = $this->notificationRepo->selectDetailedForUser(Session::getLocalUser());
if (DI::userSession()->getLocalUserId()) {
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'detailed_notif')) {
$notifications = $this->notificationRepo->selectDetailedForUser(DI::userSession()->getLocalUserId());
} else {
$notifications = $this->notificationRepo->selectDigestForUser(Session::getLocalUser());
$notifications = $this->notificationRepo->selectDigestForUser(DI::userSession()->getLocalUserId());
}
$condition = [
"`unseen` AND `uid` = ? AND NOT `origin` AND (`vid` != ? OR `vid` IS NULL)",
Session::getLocalUser(), Verb::getID(Activity::FOLLOW)
DI::userSession()->getLocalUserId(), Verb::getID(Activity::FOLLOW)
];
$items = Post::selectForUser(Session::getLocalUser(), ['wall', 'uid', 'uri-id'], $condition, ['limit' => 1000]);
$items = Post::selectForUser(DI::userSession()->getLocalUserId(), ['wall', 'uid', 'uri-id'], $condition, ['limit' => 1000]);
if (DBA::isResult($items)) {
$items_unseen = Post::toArray($items, false);
$arr = ['items' => $items_unseen];
@ -140,12 +139,12 @@ class Ping extends BaseModule
}
}
$intros = $this->introductionRepo->selectForUser(Session::getLocalUser());
$intros = $this->introductionRepo->selectForUser(DI::userSession()->getLocalUserId());
$intro_count = $intros->count();
$myurl = DI::baseUrl() . '/profile/' . DI::app()->getLoggedInUserNickname();
$mail_count = DBA::count('mail', ["`uid` = ? AND NOT `seen` AND `from-url` != ?", Session::getLocalUser(), $myurl]);
$mail_count = DBA::count('mail', ["`uid` = ? AND NOT `seen` AND `from-url` != ?", DI::userSession()->getLocalUserId(), $myurl]);
if (intval(DI::config()->get('config', 'register_policy')) === Register::APPROVE && DI::app()->isSiteAdmin()) {
$regs = \Friendica\Model\Register::getPending();
@ -155,12 +154,12 @@ class Ping extends BaseModule
}
}
$cachekey = 'ping:events:' . Session::getLocalUser();
$cachekey = 'ping:events:' . DI::userSession()->getLocalUserId();
$ev = DI::cache()->get($cachekey);
if (is_null($ev)) {
$ev = DBA::selectToArray('event', ['type', 'start'],
["`uid` = ? AND `start` < ? AND `finish` > ? AND NOT `ignore`",
Session::getLocalUser(), DateTimeFormat::utc('now + 7 days'), DateTimeFormat::utcNow()]);
DI::userSession()->getLocalUserId(), DateTimeFormat::utc('now + 7 days'), DateTimeFormat::utcNow()]);
DI::cache()->set($cachekey, $ev, Duration::HOUR);
}
@ -188,7 +187,7 @@ class Ping extends BaseModule
}
}
$owner = User::getOwnerDataById(Session::getLocalUser());
$owner = User::getOwnerDataById(DI::userSession()->getLocalUserId());
$navNotifications = array_map(function (Entity\Notification $notification) use ($owner) {
if (!DI::notify()->NotifyOnDesktop($notification)) {
@ -215,7 +214,7 @@ class Ping extends BaseModule
}
if (DBA::isResult($regs)) {
if (count($regs) <= 1 || DI::pConfig()->get(Session::getLocalUser(), 'system', 'detailed_notif')) {
if (count($regs) <= 1 || DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'detailed_notif')) {
foreach ($regs as $reg) {
$navNotifications[] = $this->formattedNavNotification->createFromParams(
[

View file

@ -22,7 +22,6 @@
namespace Friendica\Module\OAuth;
use Friendica\Core\Logger;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Module\BaseApi;
use Friendica\Security\OAuth;
@ -71,7 +70,7 @@ class Authorize extends BaseApi
unset($redirect_request['pagename']);
$redirect = 'oauth/authorize?' . http_build_query($redirect_request);
$uid = Session::getLocalUser();
$uid = DI::userSession()->getLocalUserId();
if (empty($uid)) {
Logger::info('Redirect to login');
DI::app()->redirect('login?return_path=' . urlencode($redirect));

View file

@ -21,19 +21,33 @@
namespace Friendica\Module;
use Friendica\App;
use Friendica\BaseModule;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Hook;
use Friendica\Core\Session;
use Friendica\Core\L10n;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Core\System;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Util;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
class ParseUrl extends BaseModule
{
/** @var IHandleUserSessions */
protected $userSession;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $userSession, $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->userSession = $userSession;
}
protected function rawContent(array $request = [])
{
if (!Session::isAuthenticated()) {
if (!$this->userSession->isAuthenticated()) {
throw new \Friendica\Network\HTTPException\ForbiddenException();
}

View file

@ -22,7 +22,6 @@
namespace Friendica\Module;
use Friendica\Core\Hook;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
@ -50,7 +49,7 @@ class PermissionTooltip extends \Friendica\BaseModule
throw new HTTPException\BadRequestException(DI::l10n()->t('Wrong type "%s", expected one of: %s', $type, implode(', ', $expectedTypes)));
}
$condition = ['id' => $referenceId, 'uid' => [0, Session::getLocalUser()]];
$condition = ['id' => $referenceId, 'uid' => [0, DI::userSession()->getLocalUserId()]];
if ($type == 'item') {
$fields = ['uid', 'psid', 'private', 'uri-id'];
$model = Post::selectFirst($fields, $condition);
@ -178,7 +177,7 @@ class PermissionTooltip extends \Friendica\BaseModule
private function fetchReceivers(int $uriId): string
{
$own_url = '';
$uid = Session::getLocalUser();
$uid = DI::userSession()->getLocalUserId();
if ($uid) {
$owner = User::getOwnerDataById($uid);
if (!empty($owner['url'])) {

View file

@ -24,7 +24,6 @@ namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
@ -259,7 +258,7 @@ class Photo extends BaseModule
return MPhoto::getPhoto($matches[1], $matches[2]);
}
return MPhoto::createPhotoForExternalResource($url, (int)Session::getLocalUser(), $media['mimetype'] ?? '');
return MPhoto::createPhotoForExternalResource($url, (int)DI::userSession()->getLocalUserId(), $media['mimetype'] ?? '');
case 'media':
$media = DBA::selectFirst('post-media', ['url', 'mimetype', 'uri-id'], ['id' => $id, 'type' => Post\Media::IMAGE]);
if (empty($media)) {
@ -270,14 +269,14 @@ class Photo extends BaseModule
return MPhoto::getPhoto($matches[1], $matches[2]);
}
return MPhoto::createPhotoForExternalResource($media['url'], (int)Session::getLocalUser(), $media['mimetype']);
return MPhoto::createPhotoForExternalResource($media['url'], (int)DI::userSession()->getLocalUserId(), $media['mimetype']);
case 'link':
$link = DBA::selectFirst('post-link', ['url', 'mimetype'], ['id' => $id]);
if (empty($link)) {
return false;
}
return MPhoto::createPhotoForExternalResource($link['url'], (int)Session::getLocalUser(), $link['mimetype'] ?? '');
return MPhoto::createPhotoForExternalResource($link['url'], (int)DI::userSession()->getLocalUserId(), $link['mimetype'] ?? '');
case 'contact':
$fields = ['uid', 'uri-id', 'url', 'nurl', 'avatar', 'photo', 'xmpp', 'addr', 'network', 'failed', 'updated'];
$contact = Contact::getById($id, $fields);

View file

@ -25,7 +25,6 @@ use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Module;
use Friendica\DI;
use Friendica\Model\Contact;
@ -37,7 +36,7 @@ class Common extends BaseProfile
{
protected function content(array $request = []): string
{
if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) {
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
}
@ -56,7 +55,7 @@ class Common extends BaseProfile
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
$displayCommonTab = Session::isAuthenticated() && $profile['uid'] != Session::getLocalUser();
$displayCommonTab = DI::userSession()->isAuthenticated() && $profile['uid'] != DI::userSession()->getLocalUserId();
if (!$displayCommonTab) {
$a->redirect('profile/' . $nickname . '/contacts');

View file

@ -25,7 +25,6 @@ use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model;
@ -36,7 +35,7 @@ class Contacts extends Module\BaseProfile
{
protected function content(array $request = []): string
{
if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) {
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
}
@ -50,7 +49,7 @@ class Contacts extends Module\BaseProfile
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
}
$is_owner = $profile['uid'] == Session::getLocalUser();
$is_owner = $profile['uid'] == DI::userSession()->getLocalUserId();
if ($profile['hide-friends'] && !$is_owner) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
@ -60,7 +59,7 @@ class Contacts extends Module\BaseProfile
$o = self::getTabsHTML($a, 'contacts', $is_owner, $profile['nickname'], $profile['hide-friends']);
$tabs = self::getContactFilterTabs('profile/' . $nickname, $type, Session::isAuthenticated() && $profile['uid'] != Session::getLocalUser());
$tabs = self::getContactFilterTabs('profile/' . $nickname, $type, DI::userSession()->isAuthenticated() && $profile['uid'] != DI::userSession()->getLocalUserId());
$condition = [
'uid' => $profile['uid'],

View file

@ -21,7 +21,6 @@
namespace Friendica\Module\Profile;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Profile as ProfileModel;
@ -43,7 +42,7 @@ class Media extends BaseProfile
DI::page()['htmlhead'] .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
}
$is_owner = Session::getLocalUser() == $profile['uid'];
$is_owner = DI::userSession()->getLocalUserId() == $profile['uid'];
$o = self::getTabsHTML($a, 'media', $is_owner, $profile['nickname'], $profile['hide-friends']);

View file

@ -29,7 +29,6 @@ use Friendica\Content\Text\HTML;
use Friendica\Core\Hook;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
@ -82,13 +81,13 @@ class Profile extends BaseProfile
throw new HTTPException\NotFoundException(DI::l10n()->t('Profile not found.'));
}
$remote_contact_id = Session::getRemoteContactID($profile['uid']);
$remote_contact_id = DI::userSession()->getRemoteContactID($profile['uid']);
if (DI::config()->get('system', 'block_public') && !Session::getLocalUser() && !$remote_contact_id) {
if (DI::config()->get('system', 'block_public') && !DI::userSession()->getLocalUserId() && !$remote_contact_id) {
return Login::form();
}
$is_owner = Session::getLocalUser() == $profile['uid'];
$is_owner = DI::userSession()->getLocalUserId() == $profile['uid'];
if (!empty($profile['hidewall']) && !$is_owner && !$remote_contact_id) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Access to this profile has been restricted.'));
@ -102,7 +101,7 @@ class Profile extends BaseProfile
Nav::setSelected('home');
$is_owner = Session::getLocalUser() == $profile['uid'];
$is_owner = DI::userSession()->getLocalUserId() == $profile['uid'];
$o = self::getTabsHTML($a, 'profile', $is_owner, $profile['nickname'], $profile['hide-friends']);
if (!empty($profile['hidewall']) && !$is_owner && !$remote_contact_id) {
@ -117,7 +116,7 @@ class Profile extends BaseProfile
$view_as_contact_id = intval($_GET['viewas'] ?? 0);
$view_as_contacts = Contact::selectToArray(['id', 'name'], [
'uid' => Session::getLocalUser(),
'uid' => DI::userSession()->getLocalUserId(),
'rel' => [Contact::FOLLOWER, Contact::SHARING, Contact::FRIEND],
'network' => Protocol::DFRN,
'blocked' => false,
@ -247,7 +246,7 @@ class Profile extends BaseProfile
'$submit' => DI::l10n()->t('Submit'),
'$basic' => DI::l10n()->t('Basic'),
'$advanced' => DI::l10n()->t('Advanced'),
'$is_owner' => $profile['uid'] == Session::getLocalUser(),
'$is_owner' => $profile['uid'] == DI::userSession()->getLocalUserId(),
'$query_string' => DI::args()->getQueryString(),
'$basic_fields' => $basic_fields,
'$custom_fields' => $custom_fields,
@ -308,8 +307,8 @@ class Profile extends BaseProfile
}
// site block
$blocked = !Session::getLocalUser() && !$remote_contact_id && DI::config()->get('system', 'block_public');
$userblock = !Session::getLocalUser() && !$remote_contact_id && $profile['hidewall'];
$blocked = !DI::userSession()->getLocalUserId() && !$remote_contact_id && DI::config()->get('system', 'block_public');
$userblock = !DI::userSession()->getLocalUserId() && !$remote_contact_id && $profile['hidewall'];
if (!$blocked && !$userblock) {
$keywords = str_replace(['#', ',', ' ', ',,'], ['', ' ', ',', ','], $profile['pub_keywords'] ?? '');
if (strlen($keywords)) {

View file

@ -24,7 +24,6 @@ namespace Friendica\Module\Profile;
use Friendica\BaseModule;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Post;
@ -36,7 +35,7 @@ class Schedule extends BaseProfile
{
protected function post(array $request = [])
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
@ -44,7 +43,7 @@ class Schedule extends BaseProfile
throw new HTTPException\BadRequestException();
}
if (!DBA::exists('delayed-post', ['id' => $_REQUEST['delete'], 'uid' => Session::getLocalUser()])) {
if (!DBA::exists('delayed-post', ['id' => $_REQUEST['delete'], 'uid' => DI::userSession()->getLocalUserId()])) {
throw new HTTPException\NotFoundException();
}
@ -53,7 +52,7 @@ class Schedule extends BaseProfile
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
@ -62,7 +61,7 @@ class Schedule extends BaseProfile
$o = self::getTabsHTML($a, 'schedule', true, $a->getLoggedInUserNickname(), false);
$schedule = [];
$delayed = DBA::select('delayed-post', [], ['uid' => Session::getLocalUser()]);
$delayed = DBA::select('delayed-post', [], ['uid' => DI::userSession()->getLocalUserId()]);
while ($row = DBA::fetch($delayed)) {
$parameter = Post\Delayed::getParametersForid($row['id']);
if (empty($parameter)) {

View file

@ -26,7 +26,6 @@ use Friendica\Content\Pager;
use Friendica\Content\Widget;
use Friendica\Core\ACL;
use Friendica\Core\Protocol;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
@ -92,19 +91,19 @@ class Status extends BaseProfile
$hashtags = $_GET['tag'] ?? '';
if (DI::config()->get('system', 'block_public') && !Session::getLocalUser() && !Session::getRemoteContactID($profile['uid'])) {
if (DI::config()->get('system', 'block_public') && !DI::userSession()->getLocalUserId() && !DI::userSession()->getRemoteContactID($profile['uid'])) {
return Login::form();
}
$o = '';
if ($profile['uid'] == Session::getLocalUser()) {
if ($profile['uid'] == DI::userSession()->getLocalUserId()) {
Nav::setSelected('home');
}
$remote_contact = Session::getRemoteContactID($profile['uid']);
$is_owner = Session::getLocalUser() == $profile['uid'];
$last_updated_key = "profile:" . $profile['uid'] . ":" . Session::getLocalUser() . ":" . $remote_contact;
$remote_contact = DI::userSession()->getRemoteContactID($profile['uid']);
$is_owner = DI::userSession()->getLocalUserId() == $profile['uid'];
$last_updated_key = "profile:" . $profile['uid'] . ":" . DI::userSession()->getLocalUserId() . ":" . $remote_contact;
if (!empty($profile['hidewall']) && !$is_owner && !$remote_contact) {
DI::sysmsg()->addNotice(DI::l10n()->t('Access to this profile has been restricted.'));
@ -166,10 +165,10 @@ class Status extends BaseProfile
}
if (DI::mode()->isMobile()) {
$itemspage_network = DI::pConfig()->get(Session::getLocalUser(), 'system', 'itemspage_mobile_network',
$itemspage_network = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network',
DI::config()->get('system', 'itemspage_network_mobile'));
} else {
$itemspage_network = DI::pConfig()->get(Session::getLocalUser(), 'system', 'itemspage_network',
$itemspage_network = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network',
DI::config()->get('system', 'itemspage_network'));
}
@ -197,9 +196,9 @@ class Status extends BaseProfile
}
if ($is_owner) {
$unseen = Post::exists(['wall' => true, 'unseen' => true, 'uid' => Session::getLocalUser()]);
$unseen = Post::exists(['wall' => true, 'unseen' => true, 'uid' => DI::userSession()->getLocalUserId()]);
if ($unseen) {
Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => Session::getLocalUser()]);
Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => DI::userSession()->getLocalUserId()]);
}
}

View file

@ -23,7 +23,6 @@ namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\Logger;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
@ -75,7 +74,7 @@ class Proxy extends BaseModule
throw new \Friendica\Network\HTTPException\BadRequestException();
}
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
Logger::debug('Redirecting not logged in user to original address', ['url' => $request['url']]);
System::externalRedirect($request['url']);
}
@ -84,7 +83,7 @@ class Proxy extends BaseModule
$request['url'] = str_replace(' ', '+', $request['url']);
// Fetch the content with the local user
$fetchResult = HTTPSignature::fetchRaw($request['url'], Session::getLocalUser(), [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE], 'timeout' => 10]);
$fetchResult = HTTPSignature::fetchRaw($request['url'], DI::userSession()->getLocalUserId(), [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE], 'timeout' => 10]);
$img_str = $fetchResult->getBody();
if (!$fetchResult->isSuccess() || empty($img_str)) {
@ -93,7 +92,7 @@ class Proxy extends BaseModule
// stop.
}
Logger::debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => Session::getLocalUser(), 'image' => $request['url']]);
Logger::debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => DI::userSession()->getLocalUserId(), 'image' => $request['url']]);
$mime = Images::getMimeTypeByData($img_str);

View file

@ -29,7 +29,6 @@ use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
@ -74,20 +73,20 @@ class Register extends BaseModule
// 'block_extended_register' blocks all registrations, period.
$block = DI::config()->get('system', 'block_extended_register');
if (Session::getLocalUser() && $block) {
if (DI::userSession()->getLocalUserId() && $block) {
DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
return '';
}
if (Session::getLocalUser()) {
$user = DBA::selectFirst('user', ['parent-uid'], ['uid' => Session::getLocalUser()]);
if (DI::userSession()->getLocalUserId()) {
$user = DBA::selectFirst('user', ['parent-uid'], ['uid' => DI::userSession()->getLocalUserId()]);
if (!empty($user['parent-uid'])) {
DI::sysmsg()->addNotice(DI::l10n()->t('Only parent users can create additional accounts.'));
return '';
}
}
if (!Session::getLocalUser() && (intval(DI::config()->get('config', 'register_policy')) === self::CLOSED)) {
if (!DI::userSession()->getLocalUserId() && (intval(DI::config()->get('config', 'register_policy')) === self::CLOSED)) {
DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
return '';
}
@ -109,7 +108,7 @@ class Register extends BaseModule
$photo = $_REQUEST['photo'] ?? '';
$invite_id = $_REQUEST['invite_id'] ?? '';
if (Session::getLocalUser() || DI::config()->get('system', 'no_openid')) {
if (DI::userSession()->getLocalUserId() || DI::config()->get('system', 'no_openid')) {
$fillwith = '';
$fillext = '';
$oidlabel = '';
@ -180,7 +179,7 @@ class Register extends BaseModule
'$form_security_token' => BaseModule::getFormSecurityToken('register'),
'$explicit_content' => DI::config()->get('system', 'explicit_content', false),
'$explicit_content_note' => DI::l10n()->t('Note: This node explicitly contains adult content'),
'$additional' => !empty(Session::getLocalUser()),
'$additional' => !empty(DI::userSession()->getLocalUserId()),
'$parent_password' => ['parent_password', DI::l10n()->t('Parent Password:'), '', DI::l10n()->t('Please enter the password of the parent account to legitimize your request.')]
]);
@ -203,19 +202,19 @@ class Register extends BaseModule
$additional_account = false;
if (!Session::getLocalUser() && !empty($arr['post']['parent_password'])) {
if (!DI::userSession()->getLocalUserId() && !empty($arr['post']['parent_password'])) {
DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
return;
} elseif (Session::getLocalUser() && !empty($arr['post']['parent_password'])) {
} elseif (DI::userSession()->getLocalUserId() && !empty($arr['post']['parent_password'])) {
try {
Model\User::getIdFromPasswordAuthentication(Session::getLocalUser(), $arr['post']['parent_password']);
Model\User::getIdFromPasswordAuthentication(DI::userSession()->getLocalUserId(), $arr['post']['parent_password']);
} catch (\Exception $ex) {
DI::sysmsg()->addNotice(DI::l10n()->t("Password doesn't match."));
$regdata = ['nickname' => $arr['post']['nickname'], 'username' => $arr['post']['username']];
DI::baseUrl()->redirect('register?' . http_build_query($regdata));
}
$additional_account = true;
} elseif (Session::getLocalUser()) {
} elseif (DI::userSession()->getLocalUserId()) {
DI::sysmsg()->addNotice(DI::l10n()->t('Please enter your password.'));
$regdata = ['nickname' => $arr['post']['nickname'], 'username' => $arr['post']['username']];
DI::baseUrl()->redirect('register?' . http_build_query($regdata));
@ -263,7 +262,7 @@ class Register extends BaseModule
}
if ($additional_account) {
$user = DBA::selectFirst('user', ['email'], ['uid' => Session::getLocalUser()]);
$user = DBA::selectFirst('user', ['email'], ['uid' => DI::userSession()->getLocalUserId()]);
if (!DBA::isResult($user)) {
DI::sysmsg()->addNotice(DI::l10n()->t('User not found.'));
DI::baseUrl()->redirect('register');
@ -307,7 +306,7 @@ class Register extends BaseModule
}
if ($additional_account) {
DBA::update('user', ['parent-uid' => Session::getLocalUser()], ['uid' => $user['uid']]);
DBA::update('user', ['parent-uid' => DI::userSession()->getLocalUserId()], ['uid' => $user['uid']]);
DI::sysmsg()->addInfo(DI::l10n()->t('The additional account was created.'));
DI::baseUrl()->redirect('delegation');
}

View file

@ -27,7 +27,6 @@ use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Search;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
@ -52,7 +51,7 @@ class Acl extends BaseModule
protected function rawContent(array $request = [])
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
throw new HTTPException\UnauthorizedException(DI::l10n()->t('You must be logged in to use this module.'));
}
@ -114,8 +113,8 @@ class Acl extends BaseModule
Logger::info('ACL {action} - {subaction} - start', ['module' => 'acl', 'action' => 'content', 'subaction' => 'search', 'search' => $search, 'type' => $type, 'conversation' => $conv_id]);
$sql_extra = '';
$condition = ["`uid` = ? AND NOT `deleted` AND NOT `pending` AND NOT `archive`", Session::getLocalUser()];
$condition_group = ["`uid` = ? AND NOT `deleted`", Session::getLocalUser()];
$condition = ["`uid` = ? AND NOT `deleted` AND NOT `pending` AND NOT `archive`", DI::userSession()->getLocalUserId()];
$condition_group = ["`uid` = ? AND NOT `deleted`", DI::userSession()->getLocalUserId()];
if ($search != '') {
$sql_extra = "AND `name` LIKE '%%" . DBA::escape($search) . "%%'";
@ -177,7 +176,7 @@ class Acl extends BaseModule
GROUP BY `group`.`name`, `group`.`id`
ORDER BY `group`.`name`
LIMIT ?, ?",
Session::getLocalUser(),
DI::userSession()->getLocalUserId(),
$start,
$count
));
@ -252,7 +251,7 @@ class Acl extends BaseModule
$condition = ["`parent` = ?", $conv_id];
$params = ['order' => ['author-name' => true]];
$authors = Post::selectForUser(Session::getLocalUser(), ['author-link'], $condition, $params);
$authors = Post::selectForUser(DI::userSession()->getLocalUserId(), ['author-link'], $condition, $params);
$item_authors = [];
while ($author = Post::fetch($authors)) {
$item_authors[$author['author-link']] = $author['author-link'];

View file

@ -22,7 +22,6 @@
namespace Friendica\Module\Search;
use Friendica\Content\Widget;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Module\BaseSearch;
use Friendica\Module\Security\Login;
@ -34,7 +33,7 @@ class Directory extends BaseSearch
{
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
return Login::form();
}

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