]> git.mxchange.org Git - friendica.git/blobdiff - mod/group.php
Rename dbesc to DBA::escape
[friendica.git] / mod / group.php
index 726616a90f0e5807f2c3f3998ff595e61e33d2fd..71a84a80ca5f2420b21e2c853374fce684112e13 100644 (file)
@@ -10,13 +10,13 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
-use Friendica\Database\DBM;
+use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 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'));
        }
 }
 
@@ -52,7 +52,7 @@ function group_post(App $a) {
                        intval($a->argv[1]),
                        intval(local_user())
                );
-               if (! DBM::is_result($r)) {
+               if (! DBA::isResult($r)) {
                        notice(L10n::t('Group not found.') . EOL);
                        goaway(System::baseUrl() . '/contacts');
                        return; // NOTREACHED
@@ -61,7 +61,7 @@ function group_post(App $a) {
                $groupname = notags(trim($_POST['groupname']));
                if ((strlen($groupname))  && ($groupname != $group['name'])) {
                        $r = q("UPDATE `group` SET `name` = '%s' WHERE `uid` = %d AND `id` = %d",
-                               dbesc($groupname),
+                               DBA::escape($groupname),
                                intval(local_user()),
                                intval($group['id'])
                        );
@@ -85,6 +85,10 @@ function group_content(App $a) {
        }
 
        // Switch to text mode interface if we have more than 'n' contacts or group members
+       
+       if ($a->argc == 1) {
+               goaway(System::baseUrl() . '/contacts');
+       }
 
        $switchtotext = PConfig::get(local_user(), 'system', 'groupedit_image_limit');
        if (is_null($switchtotext)) {
@@ -94,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')) {
@@ -108,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');
 
@@ -119,7 +147,7 @@ function group_content(App $a) {
 
                        $result = null;
 
-                       if (DBM::is_result($r)) {
+                       if (DBA::isResult($r)) {
                                $result = Group::removeByName(local_user(), $r[0]['name']);
                        }
 
@@ -140,7 +168,7 @@ function group_content(App $a) {
                        intval($a->argv[2]),
                        intval(local_user())
                );
-               if (DBM::is_result($r)) {
+               if (DBA::isResult($r)) {
                        $change = intval($a->argv[2]);
                }
        }
@@ -153,7 +181,7 @@ function group_content(App $a) {
                        intval(local_user())
                );
 
-               if (! DBM::is_result($r)) {
+               if (! DBA::isResult($r)) {
                        notice(L10n::t('Group not found.') . EOL);
                        goaway(System::baseUrl() . '/contacts');
                }
@@ -195,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,
                ];
 
        }
@@ -238,23 +267,32 @@ 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)) {
+       if (DBA::isResult($r)) {
                // Format the data of the contacts who aren't in the contact group
                foreach ($r as $member) {
                        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;
                        }
@@ -262,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']);