mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2025-06-07 09:54:27 +02:00
UserSession class - Refactor addon
This commit is contained in:
parent
8eca74cfab
commit
b0eb28143a
46 changed files with 534 additions and 580 deletions
|
@ -11,7 +11,6 @@ use Friendica\App;
|
|||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\DI;
|
||||
|
||||
/* Define the hooks we want to use
|
||||
|
@ -34,16 +33,16 @@ function langfilter_install()
|
|||
|
||||
function langfilter_addon_settings(App $a, array &$data)
|
||||
{
|
||||
if (!Session::getLocalUser()) {
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$enabled = DI::pConfig()->get(Session::getLocalUser(), 'langfilter', 'enable',
|
||||
!DI::pConfig()->get(Session::getLocalUser(), 'langfilter', 'disable'));
|
||||
$enabled = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'langfilter', 'enable',
|
||||
!DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'langfilter', 'disable'));
|
||||
|
||||
$languages = DI::pConfig()->get(Session::getLocalUser(), 'langfilter', 'languages');
|
||||
$minconfidence = DI::pConfig()->get(Session::getLocalUser(), 'langfilter', 'minconfidence', 0) * 100;
|
||||
$minlength = DI::pConfig()->get(Session::getLocalUser(), 'langfilter', 'minlength', 32);
|
||||
$languages = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'langfilter', 'languages');
|
||||
$minconfidence = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'langfilter', 'minconfidence', 0) * 100;
|
||||
$minlength = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'langfilter', 'minlength', 32);
|
||||
|
||||
$t = Renderer::getMarkupTemplate('settings.tpl', 'addon/langfilter/');
|
||||
$html = Renderer::replaceMacros($t, [
|
||||
|
@ -70,7 +69,7 @@ function langfilter_addon_settings(App $a, array &$data)
|
|||
|
||||
function langfilter_addon_settings_post(App $a, array &$b)
|
||||
{
|
||||
if (!Session::getLocalUser()) {
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -83,10 +82,10 @@ function langfilter_addon_settings_post(App $a, array &$b)
|
|||
$minlength = 32;
|
||||
}
|
||||
|
||||
DI::pConfig()->set(Session::getLocalUser(), 'langfilter', 'enable' , $enable);
|
||||
DI::pConfig()->set(Session::getLocalUser(), 'langfilter', 'languages' , $languages);
|
||||
DI::pConfig()->set(Session::getLocalUser(), 'langfilter', 'minconfidence', $minconfidence);
|
||||
DI::pConfig()->set(Session::getLocalUser(), 'langfilter', 'minlength' , $minlength);
|
||||
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'langfilter', 'enable' , $enable);
|
||||
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'langfilter', 'languages' , $languages);
|
||||
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'langfilter', 'minconfidence', $minconfidence);
|
||||
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'langfilter', 'minlength' , $minlength);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +100,7 @@ function langfilter_addon_settings_post(App $a, array &$b)
|
|||
|
||||
function langfilter_prepare_body_content_filter(App $a, &$hook_data)
|
||||
{
|
||||
$logged_user = Session::getLocalUser();
|
||||
$logged_user = DI::userSession()->getLocalUserId();
|
||||
if (!$logged_user) {
|
||||
return;
|
||||
}
|
||||
|
@ -129,7 +128,7 @@ function langfilter_prepare_body_content_filter(App $a, &$hook_data)
|
|||
$naked_body = preg_replace('#\s+#', ' ', trim($naked_body));
|
||||
|
||||
// Don't filter if body lenght is below minimum
|
||||
$minlen = DI::pConfig()->get(Session::getLocalUser(), 'langfilter', 'minlength', 32);
|
||||
$minlen = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'langfilter', 'minlength', 32);
|
||||
if (!$minlen) {
|
||||
$minlen = 32;
|
||||
}
|
||||
|
@ -138,8 +137,8 @@ function langfilter_prepare_body_content_filter(App $a, &$hook_data)
|
|||
return;
|
||||
}
|
||||
|
||||
$read_languages_string = DI::pConfig()->get(Session::getLocalUser(), 'langfilter', 'languages');
|
||||
$minconfidence = DI::pConfig()->get(Session::getLocalUser(), 'langfilter', 'minconfidence');
|
||||
$read_languages_string = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'langfilter', 'languages');
|
||||
$minconfidence = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'langfilter', 'minconfidence');
|
||||
|
||||
// Don't filter if no spoken languages are configured
|
||||
if (!$read_languages_string) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue