diff --git a/mod/contacts.php b/mod/contacts.php index 59b96d87a9..a4caafe8f9 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -87,7 +87,7 @@ function contacts_init(App $a) $findpeople_widget = Widget::findPeople(); } - $groups_widget = Group::sidebarWidget('contacts', 'group', 'full', 0, $contact_id); + $groups_widget = Group::sidebarWidget('contacts', 'group', 'full', 'everyone', $contact_id); $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"), [ '$vcard_widget' => $vcard_widget, diff --git a/mod/group.php b/mod/group.php index 331b694874..05a358ba70 100644 --- a/mod/group.php +++ b/mod/group.php @@ -16,7 +16,7 @@ use Friendica\Model\Group; function group_init(App $a) { if (local_user()) { - $a->page['aside'] = Group::sidebarWidget('contacts', 'group', 'extended', (($a->argc > 1) ? intval($a->argv[1]) : 0)); + $a->page['aside'] = Group::sidebarWidget('contacts', 'group', 'extended', (($a->argc > 1) ? $a->argv[1] : 'everyone')); } } @@ -98,7 +98,8 @@ function group_content(App $a) { $tpl = get_markup_template('group_edit.tpl'); $context = [ - '$submit' => L10n::t('Save Group'), + '$submit' => L10n::t('Save Group'), + '$submit_filter' => L10n::t('Filter'), ]; if (($a->argc == 2) && ($a->argv[1] === 'new')) { @@ -112,6 +113,29 @@ function group_content(App $a) { } + if (($a->argc == 2) && ($a->argv[1] === 'none')) { + require_once 'mod/contacts.php'; + + $id = -1; + $nogroup = True; + $group = [ + 'id' => $id, + 'name' => L10n::t('Contacts not in any group'), + ]; + + $members = []; + $preselected = []; + $entry = []; + + $context = $context + [ + '$title' => $group['name'], + '$gname' => ['groupname', L10n::t('Group Name: '), $group['name'], ''], + '$gid' => $id, + '$editable' => 0, + ]; + } + + if (($a->argc == 3) && ($a->argv[1] === 'drop')) { check_form_security_token_redirectOnErr('/group', 'group_drop', 't'); @@ -199,12 +223,13 @@ function group_content(App $a) { $context = $context + [ - '$title' => L10n::t('Group Editor'), + '$title' => $group['name'], '$gname' => ['groupname', L10n::t('Group Name: '), $group['name'], ''], '$gid' => $group['id'], '$drop' => $drop_txt, '$form_security_token' => get_form_security_token('group_edit'), - '$edit_name' => L10n::t('Edit Group Name') + '$edit_name' => L10n::t('Edit Group Name'), + '$editable' => 1, ]; } @@ -242,9 +267,14 @@ function group_content(App $a) { } } - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `self` ORDER BY `name` ASC", - intval(local_user()) - ); + if ($nogroup) { + $r = Contact::getUngroupedList(local_user()); + } else { + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `self` ORDER BY `name` ASC", + intval(local_user()) + ); + $context['$desc'] = L10n::t('Click on a contact to add or remove.'); + } if (DBM::is_result($r)) { // Format the data of the contacts who aren't in the contact group @@ -252,13 +282,17 @@ function group_content(App $a) { if (! in_array($member['id'], $preselected)) { $entry = _contact_detail_for_template($member); $entry['label'] = 'contacts'; - $entry['photo_menu'] = ''; - $entry['change_member'] = [ - 'title' => L10n::t("Add contact to group"), - 'gid' => $group['id'], - 'cid' => $member['id'], - 'sec_token' => $sec_token - ]; + 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; } @@ -266,7 +300,6 @@ function group_content(App $a) { } $context['$groupeditor'] = $groupeditor; - $context['$desc'] = L10n::t('Click on a contact to add or remove.'); // If there are to many contacts we could provide an alternative view mode $total = count($groupeditor['members']) + count($groupeditor['contacts']); diff --git a/mod/nogroup.php b/mod/nogroup.php index 75781765e0..570164dce7 100644 --- a/mod/nogroup.php +++ b/mod/nogroup.php @@ -8,18 +8,13 @@ use Friendica\Core\L10n; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\Group; +use Friendica\Core\System; function nogroup_init(App $a) { if (! local_user()) { return; } - - if (! x($a->page, 'aside')) { - $a->page['aside'] = ''; - } - - $a->page['aside'] .= Group::sidebarWidget('contacts', 'group', 'extended'); } function nogroup_content(App $a) @@ -29,41 +24,5 @@ function nogroup_content(App $a) return ''; } - $r = Contact::getUngroupedList(local_user()); - if (DBM::is_result($r)) { - $a->set_pager_total($r[0]['total']); - } - $r = Contact::getUngroupedList(local_user(), $a->pager['start'], $a->pager['itemspage']); - if (DBM::is_result($r)) { - foreach ($r as $rr) { - $contact_details = Contact::getDetailsByURL($rr['url'], local_user(), $rr); - - $contacts[] = [ - 'img_hover' => L10n::t('Visit %s\'s profile [%s]', $contact_details['name'], $rr['url']), - 'edit_hover' => L10n::t('Edit contact'), - 'photo_menu' => Contact::photoMenu($rr), - 'id' => $rr['id'], - 'thumb' => proxy_url($contact_details['thumb'], false, PROXY_SIZE_THUMB), - 'name' => $contact_details['name'], - 'username' => $contact_details['name'], - 'details' => $contact_details['location'], - 'tags' => $contact_details['keywords'], - 'about' => $contact_details['about'], - 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']), - 'url' => $rr['url'], - 'network' => ContactSelector::networkToName($rr['network'], $rr['url']), - ]; - } - } - - $tpl = get_markup_template("nogroup-template.tpl"); - $o = replace_macros( - $tpl, - [ - '$header' => L10n::t('Contacts who are not members of a group'), - '$contacts' => $contacts, - '$paginate' => paginate($a)] - ); - - return $o; + goaway(System::baseUrl() . '/group/none'); } diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 2fd451d6ae..1c6225a30a 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -696,49 +696,20 @@ class Contact extends BaseObject * * @return array */ - public static function getUngroupedList($uid, $start = 0, $count = 0) + public static function getUngroupedList($uid) { - if (!$count) { - $r = q( - "SELECT COUNT(*) AS `total` - FROM `contact` - WHERE `uid` = %d - AND NOT `self` - AND NOT `blocked` - AND NOT `pending` - AND `id` NOT IN ( - SELECT DISTINCT(`contact-id`) - FROM `group_member` - WHERE `uid` = %d - )", - intval($uid), - intval($uid) - ); - - return $r; - } - - $r = q( - "SELECT * - FROM `contact` - WHERE `uid` = %d - AND NOT `self` - AND NOT `blocked` - AND NOT `pending` - AND `id` NOT IN ( - SELECT DISTINCT(`contact-id`) - FROM `group_member` - INNER JOIN `group` ON `group`.`id` = `group_member`.`gid` - WHERE `group`.`uid` = %d - ) - LIMIT %d, %d", - intval($uid), - intval($uid), - intval($start), - intval($count) - ); - - return $r; + return q("SELECT * + FROM `contact` + WHERE `uid` = %d + AND NOT `self` + AND NOT `blocked` + AND NOT `pending` + AND `id` NOT IN ( + SELECT DISTINCT(`contact-id`) + FROM `group_member` + INNER JOIN `group` ON `group`.`id` = `group_member`.`gid` + WHERE `group`.`uid` = %d + )", intval($uid), intval($uid)); } /** diff --git a/src/Model/Group.php b/src/Model/Group.php index 50a3affa19..79604e2ca0 100644 --- a/src/Model/Group.php +++ b/src/Model/Group.php @@ -361,7 +361,7 @@ class Group extends BaseObject * @param int $cid * @return string */ - public static function sidebarWidget($every = 'contacts', $each = 'group', $editmode = 'standard', $group_id = 0, $cid = 0) + public static function sidebarWidget($every = 'contacts', $each = 'group', $editmode = 'standard', $group_id = '', $cid = 0) { $o = ''; @@ -373,7 +373,7 @@ class Group extends BaseObject [ 'text' => L10n::t('Everybody'), 'id' => 0, - 'selected' => (($group_id == 0) ? 'group-selected' : ''), + 'selected' => (($group_id === 'everyone') ? 'group-selected' : ''), 'href' => $every, ] ]; @@ -417,6 +417,7 @@ class Group extends BaseObject 'grouppage' => 'group/', '$edittext' => L10n::t('Edit group'), '$ungrouped' => $every === 'contacts' ? L10n::t('Contacts not in any group') : '', + '$ungrouped_selected' => (($group_id === 'none') ? 'group-selected' : ''), '$createtext' => L10n::t('Create a new group'), '$creategroup' => L10n::t('Group Name: '), '$editgroupstext' => L10n::t('Edit groups'), diff --git a/view/templates/group_edit.tpl b/view/templates/group_edit.tpl index 6b72e776e0..cb9f4198b4 100644 --- a/view/templates/group_edit.tpl +++ b/view/templates/group_edit.tpl @@ -2,6 +2,7 @@