UserSession class [7] - Refactor view/ files

This commit is contained in:
Philipp Holzer 2022-10-20 23:45:14 +02:00
parent bf39b5a948
commit ee71086133
Signed by: nupplaPhil
GPG key ID: 24A7501396EB5432
8 changed files with 55 additions and 63 deletions

View file

@ -21,16 +21,15 @@
use Friendica\App;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
function theme_content(App $a)
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return;
}
$colorset = DI::pConfig()->get(Session::getLocalUser(), 'duepuntozero', 'colorset');
$colorset = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'duepuntozero', 'colorset');
$user = true;
return clean_form($a, $colorset, $user);
@ -38,12 +37,12 @@ function theme_content(App $a)
function theme_post(App $a)
{
if (! Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return;
}
if (isset($_POST['duepuntozero-settings-submit'])) {
DI::pConfig()->set(Session::getLocalUser(), 'duepuntozero', 'colorset', $_POST['duepuntozero_colorset']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'duepuntozero', 'colorset', $_POST['duepuntozero_colorset']);
}
}
@ -76,7 +75,7 @@ function clean_form(App $a, &$colorset, $user)
];
if ($user) {
$color = DI::pConfig()->get(Session::getLocalUser(), 'duepuntozero', 'colorset');
$color = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'duepuntozero', 'colorset');
} else {
$color = DI::config()->get('duepuntozero', 'colorset');
}

View file

@ -21,7 +21,6 @@
use Friendica\App;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
/*
@ -35,7 +34,7 @@ function duepuntozero_init(App $a) {
$colorset = null;
if (DI::mode()->has(App\Mode::MAINTENANCEDISABLED)) {
$colorset = DI::pConfig()->get(Session::getLocalUser(), 'duepuntozero', 'colorset');
$colorset = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'duepuntozero', 'colorset');
if (!$colorset)
$colorset = DI::config()->get('duepuntozero', 'colorset'); // user setting have priority, then node settings
}

View file

@ -21,14 +21,13 @@
use Friendica\App;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
require_once 'view/theme/frio/php/Image.php';
function theme_post(App $a)
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return;
}
@ -48,12 +47,12 @@ function theme_post(App $a)
'always_open_compose',
] as $field) {
if (isset($_POST['frio_' . $field])) {
DI::pConfig()->set(Session::getLocalUser(), 'frio', $field, $_POST['frio_' . $field]);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'frio', $field, $_POST['frio_' . $field]);
}
}
DI::pConfig()->set(Session::getLocalUser(), 'frio', 'css_modified', time());
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'frio', 'css_modified', time());
}
}
@ -89,13 +88,13 @@ function theme_admin_post(App $a)
function theme_content(): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return '';
}
$arr = [
'scheme' => DI::pConfig()->get(Session::getLocalUser(), 'frio', 'scheme',
DI::pConfig()->get(Session::getLocalUser(), 'frio', 'schema',
'scheme' => DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'scheme',
DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'schema',
DI::config()->get('frio', 'scheme',
DI::config()->get('frio', 'schema')
)
@ -103,15 +102,15 @@ function theme_content(): string
),
'share_string' => '',
'scheme_accent' => DI::pConfig()->get(Session::getLocalUser(), 'frio', 'scheme_accent' , DI::config()->get('frio', 'scheme_accent')),
'nav_bg' => DI::pConfig()->get(Session::getLocalUser(), 'frio', 'nav_bg' , DI::config()->get('frio', 'nav_bg')),
'nav_icon_color' => DI::pConfig()->get(Session::getLocalUser(), 'frio', 'nav_icon_color' , DI::config()->get('frio', 'nav_icon_color')),
'link_color' => DI::pConfig()->get(Session::getLocalUser(), 'frio', 'link_color' , DI::config()->get('frio', 'link_color')),
'background_color' => DI::pConfig()->get(Session::getLocalUser(), 'frio', 'background_color' , DI::config()->get('frio', 'background_color')),
'contentbg_transp' => DI::pConfig()->get(Session::getLocalUser(), 'frio', 'contentbg_transp' , DI::config()->get('frio', 'contentbg_transp')),
'background_image' => DI::pConfig()->get(Session::getLocalUser(), 'frio', 'background_image' , DI::config()->get('frio', 'background_image')),
'bg_image_option' => DI::pConfig()->get(Session::getLocalUser(), 'frio', 'bg_image_option' , DI::config()->get('frio', 'bg_image_option')),
'always_open_compose' => DI::pConfig()->get(Session::getLocalUser(), 'frio', 'always_open_compose', DI::config()->get('frio', 'always_open_compose', false)),
'scheme_accent' => DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'scheme_accent' , DI::config()->get('frio', 'scheme_accent')),
'nav_bg' => DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'nav_bg' , DI::config()->get('frio', 'nav_bg')),
'nav_icon_color' => DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'nav_icon_color' , DI::config()->get('frio', 'nav_icon_color')),
'link_color' => DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'link_color' , DI::config()->get('frio', 'link_color')),
'background_color' => DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'background_color' , DI::config()->get('frio', 'background_color')),
'contentbg_transp' => DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'contentbg_transp' , DI::config()->get('frio', 'contentbg_transp')),
'background_image' => DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'background_image' , DI::config()->get('frio', 'background_image')),
'bg_image_option' => DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'bg_image_option' , DI::config()->get('frio', 'bg_image_option')),
'always_open_compose' => DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'always_open_compose', DI::config()->get('frio', 'always_open_compose', false)),
];
return frio_form($arr);
@ -119,7 +118,7 @@ function theme_content(): string
function theme_admin(): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return '';
}

View file

@ -34,7 +34,6 @@
* 'overwrites' => Variables which overwriting custom settings
*/
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Util\Strings;
@ -43,7 +42,7 @@ function get_scheme_info($scheme)
$theme = DI::app()->getCurrentTheme();
$themepath = 'view/theme/' . $theme . '/';
if (empty($scheme)) {
$scheme = DI::pConfig()->get(Session::getLocalUser(), 'frio', 'scheme', DI::pConfig()->get(Session::getLocalUser(), 'frio', 'schema', '---'));
$scheme = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'scheme', DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'frio', 'schema', '---'));
}
$scheme = Strings::sanitizeFilePathItem($scheme);

View file

@ -29,7 +29,6 @@ use Friendica\Content\Widget;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model;
@ -215,8 +214,8 @@ function frio_remote_nav(App $a, array &$nav_info)
$fields = ['id', 'url', 'avatar', 'micro', 'name', 'nick', 'baseurl', 'updated'];
if ($a->isLoggedIn()) {
$remoteUser = Contact::selectFirst($fields, ['uid' => $a->getLoggedInUserId(), 'self' => true]);
} elseif (!Session::getLocalUser() && Session::getRemoteUser()) {
$remoteUser = Contact::getById(Session::getRemoteUser(), $fields);
} elseif (!DI::userSession()->getLocalUserId() && DI::userSession()->getRemoteUserId()) {
$remoteUser = Contact::getById(DI::userSession()->getRemoteUserId(), $fields);
$nav_info['nav']['remote'] = DI::l10n()->t('Guest');
} elseif (Profile::getMyURL()) {
$remoteUser = Contact::getByURL($homelink, null, $fields);
@ -233,7 +232,7 @@ function frio_remote_nav(App $a, array &$nav_info)
$server_url = $remoteUser['baseurl'];
}
if (!Session::getLocalUser() && !empty($server_url) && !is_null($remoteUser)) {
if (!DI::userSession()->getLocalUserId() && !empty($server_url) && !is_null($remoteUser)) {
// user menu
$nav_info['nav']['usermenu'][] = [$server_url . '/profile/' . $remoteUser['nick'], DI::l10n()->t('Status'), '', DI::l10n()->t('Your posts and conversations')];
$nav_info['nav']['usermenu'][] = [$server_url . '/profile/' . $remoteUser['nick'] . '/profile', DI::l10n()->t('Profile'), '', DI::l10n()->t('Your profile page')];
@ -257,8 +256,8 @@ function frio_display_item(App $a, &$arr)
// Add follow to the item menu
$followThread = [];
if (
Session::getLocalUser()
&& in_array($arr['item']['uid'], [0, Session::getLocalUser()])
DI::userSession()->getLocalUserId()
&& in_array($arr['item']['uid'], [0, DI::userSession()->getLocalUserId()])
&& $arr['item']['gravity'] == Item::GRAVITY_PARENT
&& !$arr['item']['self']
&& !$arr['item']['mention']

View file

@ -21,32 +21,31 @@
use Friendica\App;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
function theme_content(App $a) {
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return;
}
$align = DI::pConfig()->get(Session::getLocalUser(), 'quattro', 'align' );
$color = DI::pConfig()->get(Session::getLocalUser(), 'quattro', 'color' );
$tfs = DI::pConfig()->get(Session::getLocalUser(),"quattro","tfs");
$pfs = DI::pConfig()->get(Session::getLocalUser(),"quattro","pfs");
$align = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'quattro', 'align' );
$color = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'quattro', 'color' );
$tfs = DI::pConfig()->get(DI::userSession()->getLocalUserId(),"quattro","tfs");
$pfs = DI::pConfig()->get(DI::userSession()->getLocalUserId(),"quattro","pfs");
return quattro_form($a,$align, $color, $tfs, $pfs);
}
function theme_post(App $a) {
if (! Session::getLocalUser()) {
if (! DI::userSession()->getLocalUserId()) {
return;
}
if (isset($_POST['quattro-settings-submit'])){
DI::pConfig()->set(Session::getLocalUser(), 'quattro', 'align', $_POST['quattro_align']);
DI::pConfig()->set(Session::getLocalUser(), 'quattro', 'color', $_POST['quattro_color']);
DI::pConfig()->set(Session::getLocalUser(), 'quattro', 'tfs', $_POST['quattro_tfs']);
DI::pConfig()->set(Session::getLocalUser(), 'quattro', 'pfs', $_POST['quattro_pfs']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'quattro', 'align', $_POST['quattro_align']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'quattro', 'color', $_POST['quattro_color']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'quattro', 'tfs', $_POST['quattro_tfs']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'quattro', 'pfs', $_POST['quattro_pfs']);
}
}

View file

@ -21,14 +21,13 @@
use Friendica\App;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
require_once __DIR__ . '/theme.php';
function theme_content(App $a)
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return;
}
@ -36,7 +35,7 @@ function theme_content(App $a)
return;
}
$style = DI::pConfig()->get(Session::getLocalUser(), 'vier', 'style');
$style = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'vier', 'style');
if ($style == "") {
$style = DI::config()->get('vier', 'style');
@ -59,18 +58,18 @@ function theme_content(App $a)
function theme_post(App $a)
{
if (! Session::getLocalUser()) {
if (! DI::userSession()->getLocalUserId()) {
return;
}
if (isset($_POST['vier-settings-submit'])) {
DI::pConfig()->set(Session::getLocalUser(), 'vier', 'style', $_POST['vier_style']);
DI::pConfig()->set(Session::getLocalUser(), 'vier', 'show_pages', $_POST['vier_show_pages']);
DI::pConfig()->set(Session::getLocalUser(), 'vier', 'show_profiles', $_POST['vier_show_profiles']);
DI::pConfig()->set(Session::getLocalUser(), 'vier', 'show_helpers', $_POST['vier_show_helpers']);
DI::pConfig()->set(Session::getLocalUser(), 'vier', 'show_services', $_POST['vier_show_services']);
DI::pConfig()->set(Session::getLocalUser(), 'vier', 'show_friends', $_POST['vier_show_friends']);
DI::pConfig()->set(Session::getLocalUser(), 'vier', 'show_lastusers', $_POST['vier_show_lastusers']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'vier', 'style', $_POST['vier_style']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'vier', 'show_pages', $_POST['vier_show_pages']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'vier', 'show_profiles', $_POST['vier_show_profiles']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'vier', 'show_helpers', $_POST['vier_show_helpers']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'vier', 'show_services', $_POST['vier_show_services']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'vier', 'show_friends', $_POST['vier_show_friends']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'vier', 'show_lastusers', $_POST['vier_show_lastusers']);
}
}

View file

@ -31,7 +31,6 @@ use Friendica\Content\ForumManager;
use Friendica\Core\Addon;
use Friendica\Core\Renderer;
use Friendica\Core\Search;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
@ -53,7 +52,7 @@ function vier_init(App $a)
DI::mode()->has(App\Mode::MAINTENANCEDISABLED)
&& (
$args->get(0) === 'profile' && $args->get(1) === ($a->getLoggedInUserNickname() ?? '')
|| $args->get(0) === 'network' && Session::getLocalUser()
|| $args->get(0) === 'network' && DI::userSession()->getLocalUserId()
)
) {
vier_community_info();
@ -115,8 +114,8 @@ EOT;
function get_vier_config($key, $default = false, $admin = false)
{
if (Session::getLocalUser() && !$admin) {
$result = DI::pConfig()->get(Session::getLocalUser(), "vier", $key);
if (DI::userSession()->getLocalUserId() && !$admin) {
$result = DI::pConfig()->get(DI::userSession()->getLocalUserId(), "vier", $key);
if (!is_null($result)) {
return $result;
}
@ -145,7 +144,7 @@ function vier_community_info()
// comunity_profiles
if ($show_profiles) {
$contacts = Contact\Relation::getSuggestions(Session::getLocalUser(), 0, 9);
$contacts = Contact\Relation::getSuggestions(DI::userSession()->getLocalUserId(), 0, 9);
$tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
if (DBA::isResult($contacts)) {
@ -192,7 +191,7 @@ function vier_community_info()
}
//right_aside FIND FRIENDS
if ($show_friends && Session::getLocalUser()) {
if ($show_friends && DI::userSession()->getLocalUserId()) {
$nv = [];
$nv['findpeople'] = DI::l10n()->t('Find People');
$nv['desc'] = DI::l10n()->t('Enter name or interest');
@ -211,8 +210,8 @@ function vier_community_info()
}
//Community_Pages at right_aside
if ($show_pages && Session::getLocalUser()) {
$aside['$page'] = ForumManager::widget('network/forum', Session::getLocalUser());;
if ($show_pages && DI::userSession()->getLocalUserId()) {
$aside['$page'] = ForumManager::widget('network/forum', DI::userSession()->getLocalUserId());;
}
// END Community Page