UserSession class - Refactor addon
[friendica-addons.git/.git] / dwpost / dwpost.php
index ed7ac49..a8e8285 100644 (file)
@@ -13,7 +13,6 @@ use Friendica\Content\Text\BBCode;
 use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
-use Friendica\Core\Session;
 use Friendica\DI;
 use Friendica\Model\Post;
 use Friendica\Model\Tag;
@@ -32,17 +31,17 @@ function dwpost_install()
 
 function dwpost_jot_nets(App $a, array &$jotnets_fields)
 {
-       if (!Session::getLocalUser()) {
+       if (!DI::userSession()->getLocalUserId()) {
                return;
        }
 
-       if (DI::pConfig()->get(Session::getLocalUser(), 'dwpost', 'post')) {
+       if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'dwpost', 'post')) {
                $jotnets_fields[] = [
                        'type' => 'checkbox',
                        'field' => [
                                'dwpost_enable',
                                DI::l10n()->t('Post to Dreamwidth'),
-                               DI::pConfig()->get(Session::getLocalUser(), 'dwpost', 'post_by_default')
+                               DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'dwpost', 'post_by_default')
                        ]
                ];
        }
@@ -51,13 +50,13 @@ function dwpost_jot_nets(App $a, array &$jotnets_fields)
 
 function dwpost_settings(App $a, array &$data)
 {
-       if (!Session::getLocalUser()) {
+       if (!DI::userSession()->getLocalUserId()) {
                return;
        }
 
-       $enabled     = DI::pConfig()->get(Session::getLocalUser(), 'dwpost', 'post', false);
-       $dw_username = DI::pConfig()->get(Session::getLocalUser(), 'dwpost', 'dw_username');
-       $def_enabled = DI::pConfig()->get(Session::getLocalUser(), 'dwpost', 'post_by_default');
+       $enabled     = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'dwpost', 'post', false);
+       $dw_username = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'dwpost', 'dw_username');
+       $def_enabled = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'dwpost', 'post_by_default');
 
        $t    = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/dwpost/');
        $html = Renderer::replaceMacros($t, [
@@ -80,10 +79,10 @@ function dwpost_settings(App $a, array &$data)
 function dwpost_settings_post(App $a, array &$b)
 {
        if (!empty($_POST['dwpost-submit'])) {
-               DI::pConfig()->set(Session::getLocalUser(), 'dwpost', 'post',            intval($_POST['dwpost']));
-               DI::pConfig()->set(Session::getLocalUser(), 'dwpost', 'post_by_default', intval($_POST['dw_bydefault']));
-               DI::pConfig()->set(Session::getLocalUser(), 'dwpost', 'dw_username',     trim($_POST['dw_username']));
-               DI::pConfig()->set(Session::getLocalUser(), 'dwpost', 'dw_password',     trim($_POST['dw_password']));
+               DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'dwpost', 'post',            intval($_POST['dwpost']));
+               DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'dwpost', 'post_by_default', intval($_POST['dw_bydefault']));
+               DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'dwpost', 'dw_username',     trim($_POST['dw_username']));
+               DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'dwpost', 'dw_password',     trim($_POST['dw_password']));
        }
 }
 
@@ -94,7 +93,7 @@ function dwpost_post_local(App $a, array &$b)
                return;
        }
 
-       if ((!Session::getLocalUser()) || (Session::getLocalUser() != $b['uid'])) {
+       if ((!DI::userSession()->getLocalUserId()) || (DI::userSession()->getLocalUserId() != $b['uid'])) {
                return;
        }
 
@@ -102,11 +101,11 @@ function dwpost_post_local(App $a, array &$b)
                return;
        }
 
-       $dw_post = intval(DI::pConfig()->get(Session::getLocalUser(),'dwpost','post'));
+       $dw_post = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(),'dwpost','post'));
 
        $dw_enable = (($dw_post && !empty($_REQUEST['dwpost_enable'])) ? intval($_REQUEST['dwpost_enable']) : 0);
 
-       if ($b['api_source'] && intval(DI::pConfig()->get(Session::getLocalUser(),'dwpost','post_by_default'))) {
+       if ($b['api_source'] && intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(),'dwpost','post_by_default'))) {
                $dw_enable = 1;
        }