]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Group.php
Merge pull request #12895 from HankG/mastodon-status-edit-fix-deleting-all-images
[friendica.git] / src / Module / Group.php
index 3cd8166f1fadc2a37275b27b39787c29fc7ef917..78b49d993f167f40e3739d4901fda9794eae7ce9 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -28,8 +28,6 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model;
 
-require_once 'boot.php';
-
 class Group extends BaseModule
 {
        protected function post(array $request = [])
@@ -38,8 +36,8 @@ class Group extends BaseModule
                        $this->ajaxPost();
                }
 
-               if (!local_user()) {
-                       notice(DI::l10n()->t('Permission denied.'));
+               if (!DI::userSession()->getLocalUserId()) {
+                       DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
                        DI::baseUrl()->redirect();
                }
 
@@ -48,14 +46,14 @@ class Group extends BaseModule
                        BaseModule::checkFormSecurityTokenRedirectOnError('/group/new', 'group_edit');
 
                        $name = trim($request['groupname']);
-                       $r = Model\Group::create(local_user(), $name);
+                       $r = Model\Group::create(DI::userSession()->getLocalUserId(), $name);
                        if ($r) {
-                               $r = Model\Group::getIdByName(local_user(), $name);
+                               $r = Model\Group::getIdByName(DI::userSession()->getLocalUserId(), $name);
                                if ($r) {
                                        DI::baseUrl()->redirect('group/' . $r);
                                }
                        } else {
-                               notice(DI::l10n()->t('Could not create group.'));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('Could not create group.'));
                        }
                        DI::baseUrl()->redirect('group');
                }
@@ -64,15 +62,15 @@ 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' => local_user()]);
+                       $group = DBA::selectFirst('group', ['id', 'name'], ['id' => DI::args()->getArgv()[1], 'uid' => DI::userSession()->getLocalUserId()]);
                        if (!DBA::isResult($group)) {
-                               notice(DI::l10n()->t('Group not found.'));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('Group not found.'));
                                DI::baseUrl()->redirect('contact');
                        }
                        $groupname = trim($_POST['groupname']);
                        if (strlen($groupname) && ($groupname != $group['name'])) {
                                if (!Model\Group::update($group['id'], $groupname)) {
-                                       notice(DI::l10n()->t('Group name was not changed.'));
+                                       DI::sysmsg()->addNotice(DI::l10n()->t('Group name was not changed.'));
                                }
                        }
                }
@@ -81,7 +79,7 @@ class Group extends BaseModule
        public function ajaxPost()
        {
                try {
-                       if (!local_user()) {
+                       if (!DI::userSession()->getLocalUserId()) {
                                throw new \Exception(DI::l10n()->t('Permission denied.'), 403);
                        }
 
@@ -89,12 +87,12 @@ class Group extends BaseModule
                                $group_id = $this->parameters['group'];
                                $contact_id = $this->parameters['contact'];
 
-                               if (!Model\Group::exists($group_id, local_user())) {
+                               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, local_user());
+                               $cdata = Model\Contact::getPublicAndUserContactID($contact_id, DI::userSession()->getLocalUserId());
                                if (empty($cdata['public'])) {
                                        throw new \Exception(DI::l10n()->t('Contact not found.'), 404);
                                }
@@ -132,10 +130,10 @@ class Group extends BaseModule
                                throw new \Exception(DI::l10n()->t('Bad request.'), 400);
                        }
 
-                       info($message);
+                       DI::sysmsg()->addInfo($message);
                        System::jsonExit(['status' => 'OK', 'message' => $message]);
                } catch (\Exception $e) {
-                       notice($e->getMessage());
+                       DI::sysmsg()->addNotice($e->getMessage());
                        System::jsonError($e->getCode(), ['status' => 'error', 'message' => $e->getMessage()]);
                }
        }
@@ -144,7 +142,7 @@ class Group extends BaseModule
        {
                $change = false;
 
-               if (!local_user()) {
+               if (!DI::userSession()->getLocalUserId()) {
                        throw new \Friendica\Network\HTTPException\ForbiddenException();
                }
 
@@ -159,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(local_user(), '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);
                }
@@ -211,13 +209,13 @@ class Group extends BaseModule
 
                        // @TODO: Replace with parameter from router
                        if (intval(DI::args()->getArgv()[2])) {
-                               if (!Model\Group::exists(DI::args()->getArgv()[2], local_user())) {
-                                       notice(DI::l10n()->t('Group not found.'));
+                               if (!Model\Group::exists(DI::args()->getArgv()[2], DI::userSession()->getLocalUserId())) {
+                                       DI::sysmsg()->addNotice(DI::l10n()->t('Group not found.'));
                                        DI::baseUrl()->redirect('contact');
                                }
 
                                if (!Model\Group::remove(DI::args()->getArgv()[2])) {
-                                       notice(DI::l10n()->t('Unable to remove group.'));
+                                       DI::sysmsg()->addNotice(DI::l10n()->t('Unable to remove group.'));
                                }
                        }
                        DI::baseUrl()->redirect('group');
@@ -227,16 +225,16 @@ 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' => local_user(), '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' => local_user(), 'deleted' => false]);
+                       $group = DBA::selectFirst('group', ['id', 'name'], ['id' => DI::args()->getArgv()[1], 'uid' => DI::userSession()->getLocalUserId(), 'deleted' => false]);
                        if (!DBA::isResult($group)) {
-                               notice(DI::l10n()->t('Group not found.'));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('Group not found.'));
                                DI::baseUrl()->redirect('contact');
                        }
 
@@ -317,11 +315,11 @@ class Group extends BaseModule
                }
 
                if ($nogroup) {
-                       $contacts = Model\Contact\Group::listUngrouped(local_user());
+                       $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' => local_user(), '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);
@@ -360,7 +358,7 @@ class Group extends BaseModule
                if ($change) {
                        $tpl = Renderer::getMarkupTemplate('groupeditor.tpl');
                        echo Renderer::replaceMacros($tpl, $context);
-                       exit();
+                       System::exit();
                }
 
                return Renderer::replaceMacros($tpl, $context);