UserSession class - Refactor addon

This commit is contained in:
Philipp 2022-10-20 23:51:49 +02:00
parent 8eca74cfab
commit b0eb28143a
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
46 changed files with 534 additions and 580 deletions

View file

@ -13,7 +13,6 @@ use Friendica\App;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Util\Proxy as ProxyUtils;
@ -32,7 +31,7 @@ function getWeather($loc, $units = 'metric', $lang = 'en', $appid = '', $cacheti
$now = new DateTime();
if (!is_null($cached)) {
$cdate = DI::pConfig()->get(Session::getLocalUser(), 'curweather', 'last');
$cdate = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'curweather', 'last');
$cached = unserialize($cached);
if ($cdate + $cachetime > $now->getTimestamp()) {
@ -81,7 +80,7 @@ function getWeather($loc, $units = 'metric', $lang = 'en', $appid = '', $cacheti
'icon' => (string) $res->weather['icon'],
];
DI::pConfig()->set(Session::getLocalUser(), 'curweather', 'last', $now->getTimestamp());
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'curweather', 'last', $now->getTimestamp());
DI::cache()->set('curweather'.md5($url), serialize($r), Duration::HOUR);
return $r;
@ -89,7 +88,7 @@ function getWeather($loc, $units = 'metric', $lang = 'en', $appid = '', $cacheti
function curweather_network_mod_init(App $a, string &$body)
{
if (!intval(DI::pConfig()->get(Session::getLocalUser(), 'curweather', 'curweather_enable'))) {
if (!intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'curweather', 'curweather_enable'))) {
return;
}
@ -104,11 +103,11 @@ function curweather_network_mod_init(App $a, string &$body)
// those parameters will be used to get: cloud status, temperature, preassure
// and relative humidity for display, also the relevent area of the map is
// linked from lat/log of the reply of OWMp
$rpt = DI::pConfig()->get(Session::getLocalUser(), 'curweather', 'curweather_loc');
$rpt = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'curweather', 'curweather_loc');
// Set the language to the browsers language or default and use metric units
$lang = DI::session()->get('language', DI::config()->get('system', 'language'));
$units = DI::pConfig()->get(Session::getLocalUser(), 'curweather', 'curweather_units');
$units = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'curweather', 'curweather_units');
$appid = DI::config()->get('curweather', 'appid');
$cachetime = intval(DI::config()->get('curweather', 'cachetime'));
@ -155,23 +154,23 @@ function curweather_network_mod_init(App $a, string &$body)
function curweather_addon_settings_post(App $a, $post)
{
if (!Session::getLocalUser() || empty($_POST['curweather-settings-submit'])) {
if (!DI::userSession()->getLocalUserId() || empty($_POST['curweather-settings-submit'])) {
return;
}
DI::pConfig()->set(Session::getLocalUser(), 'curweather', 'curweather_loc' , trim($_POST['curweather_loc']));
DI::pConfig()->set(Session::getLocalUser(), 'curweather', 'curweather_enable', intval($_POST['curweather_enable']));
DI::pConfig()->set(Session::getLocalUser(), 'curweather', 'curweather_units' , trim($_POST['curweather_units']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'curweather', 'curweather_loc' , trim($_POST['curweather_loc']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'curweather', 'curweather_enable', intval($_POST['curweather_enable']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'curweather', 'curweather_units' , trim($_POST['curweather_units']));
}
function curweather_addon_settings(App $a, array &$data)
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return;
}
$curweather_loc = DI::pConfig()->get(Session::getLocalUser(), 'curweather', 'curweather_loc');
$curweather_units = DI::pConfig()->get(Session::getLocalUser(), 'curweather', 'curweather_units');
$curweather_loc = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'curweather', 'curweather_loc');
$curweather_units = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'curweather', 'curweather_units');
$appid = DI::config()->get('curweather', 'appid');
if ($appid == '') {
@ -180,7 +179,7 @@ function curweather_addon_settings(App $a, array &$data)
$noappidtext = '';
}
$enabled = intval(DI::pConfig()->get(Session::getLocalUser(), 'curweather', 'curweather_enable'));
$enabled = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'curweather', 'curweather_enable'));
$t = Renderer::getMarkupTemplate('settings.tpl', 'addon/curweather/');
$html = Renderer::replaceMacros($t, [