]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Group.php
Move mod/ping to module class
[friendica.git] / src / Module / Group.php
index 30ca0805a08acaf09c64c12f1f6ab10de82a201f..3cd8166f1fadc2a37275b27b39787c29fc7ef917 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -32,7 +32,7 @@ require_once 'boot.php';
 
 class Group extends BaseModule
 {
-       public function post()
+       protected function post(array $request = [])
        {
                if (DI::mode()->isAjax()) {
                        $this->ajaxPost();
@@ -47,7 +47,7 @@ class Group extends BaseModule
                if ((DI::args()->getArgc() == 2) && (DI::args()->getArgv()[1] === 'new')) {
                        BaseModule::checkFormSecurityTokenRedirectOnError('/group/new', 'group_edit');
 
-                       $name = trim($_POST['groupname']);
+                       $name = trim($request['groupname']);
                        $r = Model\Group::create(local_user(), $name);
                        if ($r) {
                                $r = Model\Group::getIdByName(local_user(), $name);
@@ -93,7 +93,17 @@ class Group extends BaseModule
                                        throw new \Exception(DI::l10n()->t('Unknown group.'), 404);
                                }
 
-                               $contact = DBA::selectFirst('contact', ['deleted'], ['id' => $contact_id, 'uid' => local_user()]);
+                               // @TODO Backward compatibility with user contacts, remove by version 2022.03
+                               $cdata = Model\Contact::getPublicAndUserContactID($contact_id, local_user());
+                               if (empty($cdata['public'])) {
+                                       throw new \Exception(DI::l10n()->t('Contact not found.'), 404);
+                               }
+
+                               if (empty($cdata['user'])) {
+                                       throw new \Exception(DI::l10n()->t('Invalid contact.'), 404);
+                               }
+
+                               $contact = Model\Contact::getById($cdata['user'], ['deleted']);
                                if (!DBA::isResult($contact)) {
                                        throw new \Exception(DI::l10n()->t('Contact not found.'), 404);
                                }
@@ -104,14 +114,14 @@ class Group extends BaseModule
 
                                switch($this->parameters['command']) {
                                        case 'add':
-                                               if (!Model\Group::addMember($group_id, $contact_id)) {
+                                               if (!Model\Group::addMember($group_id, $cdata['user'])) {
                                                        throw new \Exception(DI::l10n()->t('Unable to add the contact to the group.'), 500);
                                                }
 
                                                $message = DI::l10n()->t('Contact successfully added to group.');
                                                break;
                                        case 'remove':
-                                               if (!Model\Group::removeMember($group_id, $contact_id)) {
+                                               if (!Model\Group::removeMember($group_id, $cdata['user'])) {
                                                        throw new \Exception(DI::l10n()->t('Unable to remove the contact from the group.'), 500);
                                                }
 
@@ -130,7 +140,7 @@ class Group extends BaseModule
                }
        }
 
-       public function content(): string
+       protected function content(array $request = []): string
        {
                $change = false;