]> git.mxchange.org Git - friendica.git/blobdiff - include/acl_selectors.php
Issue 3857: There is the possibility of a bad handling of dislikes
[friendica.git] / include / acl_selectors.php
index f57af575afa3091124e3dff1716d6b288c6c62fe..32348c2330aff6172420b2a20a56288062d42d86 100644 (file)
@@ -4,6 +4,8 @@
  * @file include/acl_selectors.php
  */
 
+use Friendica\App;
+
 require_once "include/contact_selectors.php";
 require_once "include/contact_widgets.php";
 require_once "include/DirSearch.php";
@@ -207,7 +209,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
 
        $tabindex = ($tabindex > 0 ? "tabindex=\"$tabindex\"" : "");
 
-       if ($privmail AND $preselected) {
+       if ($privmail && $preselected) {
                $sql_extra .= " AND `id` IN (".implode(",", $preselected).")";
                $hidepreselected = ' style="display: none;"';
        } else {
@@ -259,7 +261,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
 
        $o .= "</select>\r\n";
 
-       if ($privmail AND $preselected) {
+       if ($privmail && $preselected) {
                $o .= implode(", ", $receiverlist);
        }
 
@@ -386,6 +388,9 @@ function populate_acl($user = null, $show_jotnets = false) {
 }
 
 function construct_acl_data(App $a, $user) {
+       // This function is now deactivated. It seems as if the generated data isn't used anywhere.
+       /// @todo Remove this function and all function calls before releasing Friendica 3.5.3
+       return;
 
        // Get group and contact information for html ACL selector
        $acl_data = acl_lookup($a, 'html');
@@ -468,18 +473,29 @@ function acl_lookup(App $a, $out_type = 'json') {
                $r = q("SELECT COUNT(*) AS c FROM `contact`
                                WHERE `uid` = %d AND NOT `self`
                                AND NOT `blocked` AND NOT `pending` AND NOT `archive`
+                               AND `success_update` >= `failure_update`
                                AND `notify` != '' $sql_extra2" ,
                        intval(local_user())
                );
                $contact_count = (int)$r[0]['c'];
-       }
-       elseif ($type == 'm') {
-
+       } elseif ($type == 'f') {
+               // autocomplete for editor mentions of forums
+               $r = q("SELECT COUNT(*) AS c FROM `contact`
+                               WHERE `uid` = %d AND NOT `self`
+                               AND NOT `blocked` AND NOT `pending` AND NOT `archive`
+                               AND (`forum` OR `prv`)
+                               AND `success_update` >= `failure_update`
+                               AND `notify` != '' $sql_extra2" ,
+                       intval(local_user())
+               );
+               $contact_count = (int)$r[0]['c'];
+       } elseif ($type == 'm') {
                // autocomplete for Private Messages
 
                $r = q("SELECT COUNT(*) AS c FROM `contact`
                                WHERE `uid` = %d AND NOT `self`
                                AND NOT `blocked` AND NOT `pending` AND NOT `archive`
+                               AND `success_update` >= `failure_update`
                                AND `network` IN ('%s','%s','%s') $sql_extra2" ,
                        intval(local_user()),
                        dbesc(NETWORK_DFRN),
@@ -488,8 +504,7 @@ function acl_lookup(App $a, $out_type = 'json') {
                );
                $contact_count = (int)$r[0]['c'];
 
-       }
-       elseif ($type == 'a') {
+       } elseif ($type == 'a') {
 
                // autocomplete for Contacts
 
@@ -539,32 +554,44 @@ function acl_lookup(App $a, $out_type = 'json') {
                                "forum" => '0'
                        );
                }
+               if ((count($groups) > 0) && ($search == "")) {
+                       $groups[] = array("separator" => true);
+               }
        }
 
        if ($type == '') {
 
-               $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact`
+               $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `addr`, `forum`, `prv`, (`prv` OR `forum`) AS `frm` FROM `contact`
                        WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != ''
-                       AND NOT (`network` IN ('%s', '%s'))
+                       AND `success_update` >= `failure_update` AND NOT (`network` IN ('%s', '%s'))
                        $sql_extra2
                        ORDER BY `name` ASC ",
                        intval(local_user()),
                        dbesc(NETWORK_OSTATUS), dbesc(NETWORK_STATUSNET)
                );
        } elseif ($type == 'c') {
-               $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact`
+               $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `addr`, `forum`, `prv` FROM `contact`
                        WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != ''
-                       AND NOT (`network` IN ('%s'))
+                       AND `success_update` >= `failure_update` AND NOT (`network` IN ('%s'))
                        $sql_extra2
                        ORDER BY `name` ASC ",
                        intval(local_user()),
                        dbesc(NETWORK_STATUSNET)
                );
-       }
-       elseif ($type == 'm') {
-               $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact`
+       } elseif ($type == 'f') {
+               $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `addr`, `forum`, `prv` FROM `contact`
+                       WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != ''
+                       AND `success_update` >= `failure_update` AND NOT (`network` IN ('%s'))
+                       AND (`forum` OR `prv`)
+                       $sql_extra2
+                       ORDER BY `name` ASC ",
+                       intval(local_user()),
+                       dbesc(NETWORK_STATUSNET)
+               );
+       } elseif ($type == 'm') {
+               $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `addr` FROM `contact`
                        WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive`
-                       AND `network` IN ('%s','%s','%s')
+                       AND `success_update` >= `failure_update` AND `network` IN ('%s','%s','%s')
                        $sql_extra2
                        ORDER BY `name` ASC ",
                        intval(local_user()),
@@ -573,8 +600,8 @@ function acl_lookup(App $a, $out_type = 'json') {
                        dbesc(NETWORK_DIASPORA)
                );
        } elseif ($type == 'a') {
-               $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact`
-                       WHERE `uid` = %d AND `pending` = 0
+               $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `addr`, `forum`, `prv` FROM `contact`
+                       WHERE `uid` = %d AND `pending` = 0 AND `success_update` >= `failure_update`
                        $sql_extra2
                        ORDER BY `name` ASC ",
                        intval(local_user())
@@ -608,8 +635,9 @@ function acl_lookup(App $a, $out_type = 'json') {
 
 
        if (dbm::is_result($r)) {
+               $forums = array();
                foreach ($r as $g) {
-                       $contacts[] = array(
+                       $entry = array(
                                'type'    => 'c',
                                'photo'   => proxy_url($g['micro'], false, PROXY_SIZE_MICRO),
                                'name'    => htmlentities($g['name']),
@@ -617,8 +645,20 @@ function acl_lookup(App $a, $out_type = 'json') {
                                'network' => $g['network'],
                                'link'    => $g['url'],
                                'nick'    => htmlentities(($g['attag']) ? $g['attag'] : $g['nick']),
+                               'addr'    => htmlentities(($g['addr']) ? $g['addr'] : $g['url']),
                                'forum'   => ((x($g, 'forum') || x($g, 'prv')) ? 1 : 0),
                        );
+                       if ($entry['forum']) {
+                               $forums[] = $entry;
+                       } else {
+                               $contacts[] = $entry;
+                       }
+               }
+               if (count($forums) > 0) {
+                       if ($search == "") {
+                               $forums[] = array("separator" => true);
+                       }
+                       $contacts = array_merge($forums, $contacts);
                }
        }
 
@@ -661,6 +701,7 @@ function acl_lookup(App $a, $out_type = 'json') {
                                                'network' => $contact['network'],
                                                'link'    => $contact['url'],
                                                'nick'    => htmlentities($contact['nick'] ? : $contact['addr']),
+                                               'addr'    => htmlentities(($contact['addr']) ? $contact['addr'] : $contact['url']),
                                                'forum'   => $contact['forum']
                                        );
                                }