]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Group.php
Group selection: Respect "pubmail" and ignore atchived or blocked contacts
[friendica.git] / src / Module / Group.php
index 747ec1e56d8224f8ae71e7930e38242fefba9773..4c7672c01a7285d855547028cfb8072f7fd9c0be 100644 (file)
-<?php\r
-/**\r
- * @file src/Module/Group.php\r
- */\r
-\r
-namespace Friendica\Module;\r
-\r
-use Friendica\BaseModule;\r
-use Friendica\Core\Config;\r
-use Friendica\Core\L10n;\r
-use Friendica\Core\PConfig;\r
-use Friendica\Core\Renderer;\r
-use Friendica\Core\System;\r
-use Friendica\Database\DBA;\r
-use Friendica\Model;\r
-use Friendica\Util\Strings;\r
-\r
-require_once 'boot.php';\r
-\r
-class Group extends BaseModule\r
-{\r
-       public static function post()\r
-       {\r
-               $a = self::getApp();\r
-\r
-               if ($a->isAjax()) {\r
-                       self::ajaxPost();\r
-               }\r
-\r
-               if (!local_user()) {\r
-                       notice(L10n::t('Permission denied.'));\r
-                       $a->internalRedirect();\r
-               }\r
-\r
-               if (($a->argc == 2) && ($a->argv[1] === 'new')) {\r
-                       BaseModule::checkFormSecurityTokenRedirectOnError('/group/new', 'group_edit');\r
-\r
-                       $name = Strings::escapeTags(trim($_POST['groupname']));\r
-                       $r = Model\Group::create(local_user(), $name);\r
-                       if ($r) {\r
-                               info(L10n::t('Group created.'));\r
-                               $r = Model\Group::getIdByName(local_user(), $name);\r
-                               if ($r) {\r
-                                       $a->internalRedirect('group/' . $r);\r
-                               }\r
-                       } else {\r
-                               notice(L10n::t('Could not create group.'));\r
-                       }\r
-                       $a->internalRedirect('group');\r
-               }\r
-\r
-               if (($a->argc == 2) && intval($a->argv[1])) {\r
-                       BaseModule::checkFormSecurityTokenRedirectOnError('/group', 'group_edit');\r
-\r
-                       $group = DBA::selectFirst('group', ['id', 'name'], ['id' => $a->argv[1], 'uid' => local_user()]);\r
-                       if (!DBA::isResult($group)) {\r
-                               notice(L10n::t('Group not found.'));\r
-                               $a->internalRedirect('contact');\r
-                       }\r
-                       $groupname = Strings::escapeTags(trim($_POST['groupname']));\r
-                       if (strlen($groupname) && ($groupname != $group['name'])) {\r
-                               if (Model\Group::update($group['id'], $groupname)) {\r
-                                       info(L10n::t('Group name changed.'));\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-       public static function ajaxPost()\r
-       {\r
-               try {\r
-                       $a = self::getApp();\r
-\r
-                       if (!local_user()) {\r
-                               throw new \Exception(L10n::t('Permission denied.'), 403);\r
-                       }\r
-\r
-                       // POST /group/123/add/123\r
-                       // POST /group/123/remove/123\r
-                       if ($a->argc == 4) {\r
-                               list($group_id, $command, $contact_id) = array_slice($a->argv, 1);\r
-\r
-                               if (!Model\Group::exists($group_id, local_user())) {\r
-                                       throw new \Exception(L10n::t('Unknown group.'), 404);\r
-                               }\r
-\r
-                               $contact = DBA::selectFirst('contact', ['pending', 'blocked', 'deleted'], ['id' => $contact_id, 'uid' => local_user()]);\r
-                               if (!DBA::isResult($contact)) {\r
-                                       throw new \Exception(L10n::t('Contact not found.'), 404);\r
-                               }\r
-\r
-                               if ($contact['pending']) {\r
-                                       throw new \Exception(L10n::t('Contact is unavailable.'), 400);\r
-                               }\r
-\r
-                               if ($contact['deleted']) {\r
-                                       throw new \Exception(L10n::t('Contact is deleted.'), 410);\r
-                               }\r
-\r
-                               switch($command) {\r
-                                       case 'add':\r
-                                               if ($contact['blocked']) {\r
-                                                       throw new \Exception(L10n::t('Contact is blocked, unable to add it to a group.'), 400);\r
-                                               }\r
-\r
-                                               if (!Model\Group::addMember($group_id, $contact_id)) {\r
-                                                       throw new \Exception(L10n::t('Unable to add the contact to the group.'), 500);\r
-                                               }\r
-                                               $message = L10n::t('Contact successfully added to group.');\r
-                                               break;\r
-                                       case 'remove':\r
-                                               if (!Model\Group::removeMember($group_id, $contact_id)) {\r
-                                                       throw new \Exception(L10n::t('Unable to remove the contact from the group.'), 500);\r
-                                               }\r
-                                               $message = L10n::t('Contact successfully removed from group.');\r
-                                               break;\r
-                                       default:\r
-                                               throw new \Exception(L10n::t('Unknown group command.'), 400);\r
-                               }\r
-                       } else {\r
-                               throw new \Exception(L10n::t('Bad request.'), 400);\r
-                       }\r
-\r
-                       notice($message);\r
-                       System::jsonExit(['status' => 'OK', 'message' => $message]);\r
-               } catch (\Exception $e) {\r
-                       notice($e->getMessage());\r
-                       System::jsonError($e->getCode(), ['status' => 'error', 'message' => $e->getMessage()]);\r
-               }\r
-       }\r
-\r
-       public static function content()\r
-       {\r
-               $change = false;\r
-\r
-               if (!local_user()) {\r
-                       System::httpExit(403);\r
-               }\r
-\r
-               $a = self::getApp();\r
-\r
-               $a->page['aside'] = Model\Group::sidebarWidget('contact', 'group', 'extended', (($a->argc > 1) ? $a->argv[1] : 'everyone'));\r
-\r
-               // With no group number provided we jump to the unassigned contacts as a starting point\r
-               if ($a->argc == 1) {\r
-                       $a->internalRedirect('group/none');\r
-               }\r
-\r
-               // Switch to text mode interface if we have more than 'n' contacts or group members\r
-               $switchtotext = PConfig::get(local_user(), 'system', 'groupedit_image_limit');\r
-               if (is_null($switchtotext)) {\r
-                       $switchtotext = Config::get('system', 'groupedit_image_limit', 200);\r
-               }\r
-\r
-               $tpl = Renderer::getMarkupTemplate('group_edit.tpl');\r
-\r
-\r
-               $context = [\r
-                       '$submit' => L10n::t('Save Group'),\r
-                       '$submit_filter' => L10n::t('Filter'),\r
-               ];\r
-\r
-               if (($a->argc == 2) && ($a->argv[1] === 'new')) {\r
-                       return Renderer::replaceMacros($tpl, $context + [\r
-                               '$title' => L10n::t('Create a group of contacts/friends.'),\r
-                               '$gname' => ['groupname', L10n::t('Group Name: '), '', ''],\r
-                               '$gid' => 'new',\r
-                               '$form_security_token' => BaseModule::getFormSecurityToken("group_edit"),\r
-                       ]);\r
-               }\r
-\r
-               $nogroup = false;\r
-\r
-               if (($a->argc == 2) && ($a->argv[1] === 'none')) {\r
-                       $id = -1;\r
-                       $nogroup = true;\r
-                       $group = [\r
-                               'id' => $id,\r
-                               'name' => L10n::t('Contacts not in any group'),\r
-                       ];\r
-\r
-                       $members = [];\r
-                       $preselected = [];\r
-\r
-                       $context = $context + [\r
-                               '$title' => $group['name'],\r
-                               '$gname' => ['groupname', L10n::t('Group Name: '), $group['name'], ''],\r
-                               '$gid' => $id,\r
-                               '$editable' => 0,\r
-                       ];\r
-               }\r
-\r
-               if (($a->argc == 3) && ($a->argv[1] === 'drop')) {\r
-                       BaseModule::checkFormSecurityTokenRedirectOnError('/group', 'group_drop', 't');\r
-\r
-                       if (intval($a->argv[2])) {\r
-                               if (!Model\Group::exists($a->argv[2], local_user())) {\r
-                                       notice(L10n::t('Group not found.'));\r
-                                       $a->internalRedirect('contact');\r
-                               }\r
-\r
-                               if (Model\Group::remove($a->argv[2])) {\r
-                                       info(L10n::t('Group removed.'));\r
-                               } else {\r
-                                       notice(L10n::t('Unable to remove group.'));\r
-                               }\r
-                       }\r
-                       $a->internalRedirect('group');\r
-               }\r
-\r
-               if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {\r
-                       BaseModule::checkFormSecurityTokenForbiddenOnError('group_member_change', 't');\r
-\r
-                       if (DBA::exists('contact', ['id' => $a->argv[2], 'uid' => local_user(), 'self' => false, 'pending' => false, 'blocked' => false])) {\r
-                               $change = intval($a->argv[2]);\r
-                       }\r
-               }\r
-\r
-               if (($a->argc > 1) && intval($a->argv[1])) {\r
-                       $group = DBA::selectFirst('group', ['id', 'name'], ['id' => $a->argv[1], 'uid' => local_user(), 'deleted' => false]);\r
-                       if (!DBA::isResult($group)) {\r
-                               notice(L10n::t('Group not found.'));\r
-                               $a->internalRedirect('contact');\r
-                       }\r
-\r
-                       $members = Model\Contact::getByGroupId($group['id']);\r
-                       $preselected = [];\r
-\r
-                       if (count($members)) {\r
-                               foreach ($members as $member) {\r
-                                       $preselected[] = $member['id'];\r
-                               }\r
-                       }\r
-\r
-                       if ($change) {\r
-                               if (in_array($change, $preselected)) {\r
-                                       Model\Group::removeMember($group['id'], $change);\r
-                               } else {\r
-                                       Model\Group::addMember($group['id'], $change);\r
-                               }\r
-\r
-                               $members = Model\Contact::getByGroupId($group['id']);\r
-                               $preselected = [];\r
-                               if (count($members)) {\r
-                                       foreach ($members as $member) {\r
-                                               $preselected[] = $member['id'];\r
-                                       }\r
-                               }\r
-                       }\r
-\r
-                       $drop_tpl = Renderer::getMarkupTemplate('group_drop.tpl');\r
-                       $drop_txt = Renderer::replaceMacros($drop_tpl, [\r
-                               '$id' => $group['id'],\r
-                               '$delete' => L10n::t('Delete Group'),\r
-                               '$form_security_token' => BaseModule::getFormSecurityToken("group_drop"),\r
-                       ]);\r
-\r
-                       $context = $context + [\r
-                               '$title' => $group['name'],\r
-                               '$gname' => ['groupname', L10n::t('Group Name: '), $group['name'], ''],\r
-                               '$gid' => $group['id'],\r
-                               '$drop' => $drop_txt,\r
-                               '$form_security_token' => BaseModule::getFormSecurityToken('group_edit'),\r
-                               '$edit_name' => L10n::t('Edit Group Name'),\r
-                               '$editable' => 1,\r
-                       ];\r
-               }\r
-\r
-               if (!isset($group)) {\r
-                       System::httpExit(400);\r
-               }\r
-\r
-               $groupeditor = [\r
-                       'label_members' => L10n::t('Members'),\r
-                       'members' => [],\r
-                       'label_contacts' => L10n::t('All Contacts'),\r
-                       'group_is_empty' => L10n::t('Group is empty'),\r
-                       'contacts' => [],\r
-               ];\r
-\r
-               $sec_token = addslashes(BaseModule::getFormSecurityToken('group_member_change'));\r
-\r
-               // Format the data of the group members\r
-               foreach ($members as $member) {\r
-                       if ($member['url']) {\r
-                               $entry = Contact::getContactTemplateVars($member);\r
-                               $entry['label'] = 'members';\r
-                               $entry['photo_menu'] = '';\r
-                               $entry['change_member'] = [\r
-                                       'title'     => L10n::t("Remove contact from group"),\r
-                                       'gid'       => $group['id'],\r
-                                       'cid'       => $member['id'],\r
-                                       'sec_token' => $sec_token\r
-                               ];\r
-\r
-                               $groupeditor['members'][] = $entry;\r
-                       } else {\r
-                               Model\Group::removeMember($group['id'], $member['id']);\r
-                       }\r
-               }\r
-\r
-               if ($nogroup) {\r
-                       $contacts = Model\Contact::getUngroupedList(local_user());\r
-               } else {\r
-                       $contacts_stmt = DBA::select('contact', [],\r
-                               ['uid' => local_user(), 'pending' => false, 'blocked' => false, 'self' => false],\r
-                               ['order' => ['name']]\r
-                       );\r
-                       $contacts = DBA::toArray($contacts_stmt);\r
-                       $context['$desc'] = L10n::t('Click on a contact to add or remove.');\r
-               }\r
-\r
-               if (DBA::isResult($contacts)) {\r
-                       // Format the data of the contacts who aren't in the contact group\r
-                       foreach ($contacts as $member) {\r
-                               if (!in_array($member['id'], $preselected)) {\r
-                                       $entry = Contact::getContactTemplateVars($member);\r
-                                       $entry['label'] = 'contacts';\r
-                                       if (!$nogroup)\r
-                                               $entry['photo_menu'] = [];\r
-\r
-                                       if (!$nogroup) {\r
-                                               $entry['change_member'] = [\r
-                                                       'title'     => L10n::t("Add contact to group"),\r
-                                                       'gid'       => $group['id'],\r
-                                                       'cid'       => $member['id'],\r
-                                                       'sec_token' => $sec_token\r
-                                               ];\r
-                                       }\r
-\r
-                                       $groupeditor['contacts'][] = $entry;\r
-                               }\r
-                       }\r
-               }\r
-\r
-               $context['$groupeditor'] = $groupeditor;\r
-\r
-               // If there are to many contacts we could provide an alternative view mode\r
-               $total = count($groupeditor['members']) + count($groupeditor['contacts']);\r
-               $context['$shortmode'] = (($switchtotext && ($total > $switchtotext)) ? true : false);\r
-\r
-               if ($change) {\r
-                       $tpl = Renderer::getMarkupTemplate('groupeditor.tpl');\r
-                       echo Renderer::replaceMacros($tpl, $context);\r
-                       exit();\r
-               }\r
-\r
-               return Renderer::replaceMacros($tpl, $context);\r
-       }\r
+<?php
+/**
+ * @file src/Module/Group.php
+ */
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Core\Config;
+use Friendica\Core\L10n;
+use Friendica\Core\PConfig;
+use Friendica\Core\Renderer;
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\Model;
+use Friendica\Util\Strings;
+
+require_once 'boot.php';
+
+class Group extends BaseModule
+{
+       public static function post(array $parameters = [])
+       {
+               $a = self::getApp();
+
+               if ($a->isAjax()) {
+                       self::ajaxPost();
+               }
+
+               if (!local_user()) {
+                       notice(L10n::t('Permission denied.'));
+                       $a->internalRedirect();
+               }
+
+               // @TODO: Replace with parameter from router
+               if (($a->argc == 2) && ($a->argv[1] === 'new')) {
+                       BaseModule::checkFormSecurityTokenRedirectOnError('/group/new', 'group_edit');
+
+                       $name = Strings::escapeTags(trim($_POST['groupname']));
+                       $r = Model\Group::create(local_user(), $name);
+                       if ($r) {
+                               info(L10n::t('Group created.'));
+                               $r = Model\Group::getIdByName(local_user(), $name);
+                               if ($r) {
+                                       $a->internalRedirect('group/' . $r);
+                               }
+                       } else {
+                               notice(L10n::t('Could not create group.'));
+                       }
+                       $a->internalRedirect('group');
+               }
+
+               // @TODO: Replace with parameter from router
+               if (($a->argc == 2) && intval($a->argv[1])) {
+                       BaseModule::checkFormSecurityTokenRedirectOnError('/group', 'group_edit');
+
+                       $group = DBA::selectFirst('group', ['id', 'name'], ['id' => $a->argv[1], 'uid' => local_user()]);
+                       if (!DBA::isResult($group)) {
+                               notice(L10n::t('Group not found.'));
+                               $a->internalRedirect('contact');
+                       }
+                       $groupname = Strings::escapeTags(trim($_POST['groupname']));
+                       if (strlen($groupname) && ($groupname != $group['name'])) {
+                               if (Model\Group::update($group['id'], $groupname)) {
+                                       info(L10n::t('Group name changed.'));
+                               }
+                       }
+               }
+       }
+
+       public static function ajaxPost()
+       {
+               try {
+                       $a = self::getApp();
+
+                       if (!local_user()) {
+                               throw new \Exception(L10n::t('Permission denied.'), 403);
+                       }
+
+                       // POST /group/123/add/123
+                       // POST /group/123/remove/123
+                       // @TODO: Replace with parameter from router
+                       if ($a->argc == 4) {
+                               list($group_id, $command, $contact_id) = array_slice($a->argv, 1);
+
+                               if (!Model\Group::exists($group_id, local_user())) {
+                                       throw new \Exception(L10n::t('Unknown group.'), 404);
+                               }
+
+                               $contact = DBA::selectFirst('contact', ['pending', 'blocked', 'deleted'], ['id' => $contact_id, 'uid' => local_user()]);
+                               if (!DBA::isResult($contact)) {
+                                       throw new \Exception(L10n::t('Contact not found.'), 404);
+                               }
+
+                               if ($contact['pending']) {
+                                       throw new \Exception(L10n::t('Contact is unavailable.'), 400);
+                               }
+
+                               if ($contact['deleted']) {
+                                       throw new \Exception(L10n::t('Contact is deleted.'), 410);
+                               }
+
+                               switch($command) {
+                                       case 'add':
+                                               if ($contact['blocked']) {
+                                                       throw new \Exception(L10n::t('Contact is blocked, unable to add it to a group.'), 400);
+                                               }
+
+                                               if (!Model\Group::addMember($group_id, $contact_id)) {
+                                                       throw new \Exception(L10n::t('Unable to add the contact to the group.'), 500);
+                                               }
+                                               $message = L10n::t('Contact successfully added to group.');
+                                               break;
+                                       case 'remove':
+                                               if (!Model\Group::removeMember($group_id, $contact_id)) {
+                                                       throw new \Exception(L10n::t('Unable to remove the contact from the group.'), 500);
+                                               }
+                                               $message = L10n::t('Contact successfully removed from group.');
+                                               break;
+                                       default:
+                                               throw new \Exception(L10n::t('Unknown group command.'), 400);
+                               }
+                       } else {
+                               throw new \Exception(L10n::t('Bad request.'), 400);
+                       }
+
+                       notice($message);
+                       System::jsonExit(['status' => 'OK', 'message' => $message]);
+               } catch (\Exception $e) {
+                       notice($e->getMessage());
+                       System::jsonError($e->getCode(), ['status' => 'error', 'message' => $e->getMessage()]);
+               }
+       }
+
+       public static function content(array $parameters = [])
+       {
+               $change = false;
+
+               if (!local_user()) {
+                       throw new \Friendica\Network\HTTPException\ForbiddenException();
+               }
+
+               $a = self::getApp();
+
+               $a->page['aside'] = Model\Group::sidebarWidget('contact', 'group', 'extended', (($a->argc > 1) ? $a->argv[1] : 'everyone'));
+
+               // With no group number provided we jump to the unassigned contacts as a starting point
+               // @TODO: Replace with parameter from router
+               if ($a->argc == 1) {
+                       $a->internalRedirect('group/none');
+               }
+
+               // Switch to text mode interface if we have more than 'n' contacts or group members
+               $switchtotext = PConfig::get(local_user(), 'system', 'groupedit_image_limit');
+               if (is_null($switchtotext)) {
+                       $switchtotext = Config::get('system', 'groupedit_image_limit', 200);
+               }
+
+               $tpl = Renderer::getMarkupTemplate('group_edit.tpl');
+
+
+               $context = [
+                       '$submit' => L10n::t('Save Group'),
+                       '$submit_filter' => L10n::t('Filter'),
+               ];
+
+               // @TODO: Replace with parameter from router
+               if (($a->argc == 2) && ($a->argv[1] === 'new')) {
+                       return Renderer::replaceMacros($tpl, $context + [
+                               '$title' => L10n::t('Create a group of contacts/friends.'),
+                               '$gname' => ['groupname', L10n::t('Group Name: '), '', ''],
+                               '$gid' => 'new',
+                               '$form_security_token' => BaseModule::getFormSecurityToken("group_edit"),
+                       ]);
+               }
+
+               $nogroup = false;
+
+               // @TODO: Replace with parameter from router
+               if (($a->argc == 2) && ($a->argv[1] === 'none') ||
+                       ($a->argc == 1) && ($a->argv[0] === 'nogroup')) {
+                       $id = -1;
+                       $nogroup = true;
+                       $group = [
+                               'id' => $id,
+                               'name' => L10n::t('Contacts not in any group'),
+                       ];
+
+                       $members = [];
+                       $preselected = [];
+
+                       $context = $context + [
+                               '$title' => $group['name'],
+                               '$gname' => ['groupname', L10n::t('Group Name: '), $group['name'], ''],
+                               '$gid' => $id,
+                               '$editable' => 0,
+                       ];
+               }
+
+               // @TODO: Replace with parameter from router
+               if (($a->argc == 3) && ($a->argv[1] === 'drop')) {
+                       BaseModule::checkFormSecurityTokenRedirectOnError('/group', 'group_drop', 't');
+
+                       // @TODO: Replace with parameter from router
+                       if (intval($a->argv[2])) {
+                               if (!Model\Group::exists($a->argv[2], local_user())) {
+                                       notice(L10n::t('Group not found.'));
+                                       $a->internalRedirect('contact');
+                               }
+
+                               if (Model\Group::remove($a->argv[2])) {
+                                       info(L10n::t('Group removed.'));
+                               } else {
+                                       notice(L10n::t('Unable to remove group.'));
+                               }
+                       }
+                       $a->internalRedirect('group');
+               }
+
+               // @TODO: Replace with parameter from router
+               if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
+                       BaseModule::checkFormSecurityTokenForbiddenOnError('group_member_change', 't');
+
+                       if (DBA::exists('contact', ['id' => $a->argv[2], 'uid' => local_user(), 'self' => false, 'pending' => false, 'blocked' => false])) {
+                               $change = intval($a->argv[2]);
+                       }
+               }
+
+               // @TODO: Replace with parameter from router
+               if (($a->argc > 1) && intval($a->argv[1])) {
+                       $group = DBA::selectFirst('group', ['id', 'name'], ['id' => $a->argv[1], 'uid' => local_user(), 'deleted' => false]);
+                       if (!DBA::isResult($group)) {
+                               notice(L10n::t('Group not found.'));
+                               $a->internalRedirect('contact');
+                       }
+
+                       $members = Model\Contact::getByGroupId($group['id']);
+                       $preselected = [];
+
+                       if (count($members)) {
+                               foreach ($members as $member) {
+                                       $preselected[] = $member['id'];
+                               }
+                       }
+
+                       if ($change) {
+                               if (in_array($change, $preselected)) {
+                                       Model\Group::removeMember($group['id'], $change);
+                               } else {
+                                       Model\Group::addMember($group['id'], $change);
+                               }
+
+                               $members = Model\Contact::getByGroupId($group['id']);
+                               $preselected = [];
+                               if (count($members)) {
+                                       foreach ($members as $member) {
+                                               $preselected[] = $member['id'];
+                                       }
+                               }
+                       }
+
+                       $drop_tpl = Renderer::getMarkupTemplate('group_drop.tpl');
+                       $drop_txt = Renderer::replaceMacros($drop_tpl, [
+                               '$id' => $group['id'],
+                               '$delete' => L10n::t('Delete Group'),
+                               '$form_security_token' => BaseModule::getFormSecurityToken("group_drop"),
+                       ]);
+
+                       $context = $context + [
+                               '$title' => $group['name'],
+                               '$gname' => ['groupname', L10n::t('Group Name: '), $group['name'], ''],
+                               '$gid' => $group['id'],
+                               '$drop' => $drop_txt,
+                               '$form_security_token' => BaseModule::getFormSecurityToken('group_edit'),
+                               '$edit_name' => L10n::t('Edit Group Name'),
+                               '$editable' => 1,
+                       ];
+               }
+
+               if (!isset($group)) {
+                       throw new \Friendica\Network\HTTPException\BadRequestException();
+               }
+
+               $groupeditor = [
+                       'label_members' => L10n::t('Members'),
+                       'members' => [],
+                       'label_contacts' => L10n::t('All Contacts'),
+                       'group_is_empty' => L10n::t('Group is empty'),
+                       'contacts' => [],
+               ];
+
+               $sec_token = addslashes(BaseModule::getFormSecurityToken('group_member_change'));
+
+               // Format the data of the group members
+               foreach ($members as $member) {
+                       if ($member['url']) {
+                               $entry = Contact::getContactTemplateVars($member);
+                               $entry['label'] = 'members';
+                               $entry['photo_menu'] = '';
+                               $entry['change_member'] = [
+                                       'title'     => L10n::t("Remove contact from group"),
+                                       'gid'       => $group['id'],
+                                       'cid'       => $member['id'],
+                                       'sec_token' => $sec_token
+                               ];
+
+                               $groupeditor['members'][] = $entry;
+                       } else {
+                               Model\Group::removeMember($group['id'], $member['id']);
+                       }
+               }
+
+               if ($nogroup) {
+                       $contacts = Model\Contact::getUngroupedList(local_user());
+               } else {
+                       $contacts_stmt = DBA::select('contact', [],
+                               ['uid' => local_user(), 'pending' => false, 'blocked' => false, 'self' => false],
+                               ['order' => ['name']]
+                       );
+                       $contacts = DBA::toArray($contacts_stmt);
+                       $context['$desc'] = L10n::t('Click on a contact to add or remove.');
+               }
+
+               if (DBA::isResult($contacts)) {
+                       // Format the data of the contacts who aren't in the contact group
+                       foreach ($contacts as $member) {
+                               if (!in_array($member['id'], $preselected)) {
+                                       $entry = Contact::getContactTemplateVars($member);
+                                       $entry['label'] = 'contacts';
+                                       if (!$nogroup)
+                                               $entry['photo_menu'] = [];
+
+                                       if (!$nogroup) {
+                                               $entry['change_member'] = [
+                                                       'title'     => L10n::t("Add contact to group"),
+                                                       'gid'       => $group['id'],
+                                                       'cid'       => $member['id'],
+                                                       'sec_token' => $sec_token
+                                               ];
+                                       }
+
+                                       $groupeditor['contacts'][] = $entry;
+                               }
+                       }
+               }
+
+               $context['$groupeditor'] = $groupeditor;
+
+               // If there are to many contacts we could provide an alternative view mode
+               $total = count($groupeditor['members']) + count($groupeditor['contacts']);
+               $context['$shortmode'] = (($switchtotext && ($total > $switchtotext)) ? true : false);
+
+               if ($change) {
+                       $tpl = Renderer::getMarkupTemplate('groupeditor.tpl');
+                       echo Renderer::replaceMacros($tpl, $context);
+                       exit();
+               }
+
+               return Renderer::replaceMacros($tpl, $context);
+       }
 }
\ No newline at end of file