]> git.mxchange.org Git - friendica.git/blobdiff - include/acl_selectors.php
Merge branch 'develop' into issue/3878-move-Contact-to-src
[friendica.git] / include / acl_selectors.php
index f57af575afa3091124e3dff1716d6b288c6c62fe..ef75d416f6f43a45eef554f4fba06450444d7b14 100644 (file)
@@ -4,9 +4,14 @@
  * @file include/acl_selectors.php
  */
 
+use Friendica\App;
+use Friendica\Core\Config;
+use Friendica\Database\DBM;
+use Friendica\Model\GlobalContact;
+use Friendica\Object\Contact;
+
 require_once "include/contact_selectors.php";
 require_once "include/contact_widgets.php";
-require_once "include/DirSearch.php";
 require_once "include/features.php";
 require_once "mod/proxy.php";
 
@@ -33,7 +38,7 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) {
 
        call_hooks($a->module . '_pre_' . $selname, $arr);
 
-       if (dbm::is_result($r)) {
+       if (DBM::is_result($r)) {
                foreach ($r as $rr) {
                        if ((is_array($preselected)) && in_array($rr['id'], $preselected)) {
                                $selected = " selected=\"selected\" ";
@@ -55,10 +60,9 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) {
        return $o;
 }
 
-/// @TODO after an optional parameter, no mandadory parameter can follow
 /// @TODO find proper type-hints
-function contact_selector($selname, $selclass, $preselected = false, $options) {
-
+function contact_selector($selname, $selclass, $options, $preselected = false)
+{
        $a = get_app();
 
        $mutual = false;
@@ -156,7 +160,7 @@ function contact_selector($selname, $selclass, $preselected = false, $options) {
 
        call_hooks($a->module . '_pre_' . $selname, $arr);
 
-       if (dbm::is_result($r)) {
+       if (DBM::is_result($r)) {
                foreach ($r as $rr) {
                        if ((is_array($preselected)) && in_array($rr['id'], $preselected)) {
                                $selected = " selected=\"selected\" ";
@@ -207,7 +211,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 {
@@ -236,7 +240,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
 
        $receiverlist = array();
 
-       if (dbm::is_result($r)) {
+       if (DBM::is_result($r)) {
                foreach ($r as $rr) {
                        if ((is_array($preselected)) && in_array($rr['id'], $preselected)) {
                                $selected = " selected=\"selected\" ";
@@ -259,7 +263,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);
        }
 
@@ -283,7 +287,7 @@ function prune_deadguys($arr) {
 
        $r = q("SELECT `id` FROM `contact` WHERE `id` IN ( " . $str . ") AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 ");
 
-       if (dbm::is_result($r)) {
+       if (DBM::is_result($r)) {
                $ret = array();
                foreach ($r as $rr) {
                        $ret[] = intval($rr['id']);
@@ -330,7 +334,7 @@ function populate_acl($user = null, $show_jotnets = false) {
 
        $jotnets = '';
        if ($show_jotnets) {
-               $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
+               $mail_disabled = ((function_exists('imap_open') && (! Config::get('system','imap_disabled'))) ? 0 : 1);
 
                $mail_enabled = false;
                $pubmail_enabled = false;
@@ -339,7 +343,7 @@ function populate_acl($user = null, $show_jotnets = false) {
                        $r = q("SELECT `pubmail` FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
                                intval(local_user())
                        );
-                       if (dbm::is_result($r)) {
+                       if (DBM::is_result($r)) {
                                $mail_enabled = true;
                                if (intval($r[0]['pubmail'])) {
                                        $pubmail_enabled = true;
@@ -386,6 +390,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 +475,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 +506,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 +556,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 +602,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())
@@ -607,9 +636,10 @@ function acl_lookup(App $a, $out_type = 'json') {
        }
 
 
-       if (dbm::is_result($r)) {
+       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 +647,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);
                }
        }
 
@@ -648,9 +690,9 @@ function acl_lookup(App $a, $out_type = 'json') {
                                dbesc($search),
                                implode("', '", $known_contacts)
                );
-               if (dbm::is_result($r)) {
+               if (DBM::is_result($r)) {
                        foreach ($r as $row) {
-                               $contact = get_contact_details_by_url($row['author-link']);
+                               $contact = Contact::getDetailsByURL($row['author-link']);
 
                                if (count($contact) > 0) {
                                        $unknown_contacts[] = array(
@@ -661,6 +703,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']
                                        );
                                }
@@ -716,12 +759,12 @@ function navbar_complete(App $a) {
 
 //     logger('navbar_complete');
 
-       if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
+       if ((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
                return;
        }
 
        // check if searching in the local global contact table is enabled
-       $localsearch = get_config('system','poco_local_search');
+       $localsearch = Config::get('system','poco_local_search');
 
        $search = $prefix.notags(trim($_REQUEST['search']));
        $mode = $_REQUEST['smode'];
@@ -736,7 +779,7 @@ function navbar_complete(App $a) {
        }
 
        if ($localsearch) {
-               $x = DirSearch::global_search_by_name($search, $mode);
+               $x = GlobalContact::searchByName($search, $mode);
                return $x;
        }