X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Facl_selectors.php;h=a20775379707d68b1416618bbaa1760bc19ed8df;hb=66902c7956eedba02ea54aea6ea7aa417344ffbb;hp=19197981e023681f1f0793cb0d4eeb38007a4af6;hpb=c42922f25f34f7d34fa50bc743680169542ac4a5;p=friendica.git diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 19197981e0..a207753797 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -1,13 +1,15 @@ module . '_pre_' . $selname, $arr); - if(count($r)) { - foreach($r as $rr) { + if (dbm::is_result($r)) { + foreach ($r as $rr) { if((is_array($preselected)) && in_array($rr['id'], $preselected)) $selected = " selected=\"selected\" "; else @@ -63,20 +65,24 @@ function contact_selector($selname, $selclass, $preselected = false, $options) { $exclude = false; $size = 4; - if(is_array($options)) { - if(x($options,'size')) + if (is_array($options)) { + if (x($options,'size')) $size = $options['size']; - if(x($options,'mutual_friends')) + if (x($options,'mutual_friends')) { $mutual = true; - if(x($options,'single')) + } + if (x($options,'single')) { $single = true; - if(x($options,'multiple')) + } + if (x($options,'multiple')) { $single = false; - if(x($options,'exclude')) + } + if (x($options,'exclude')) { $exclude = $options['exclude']; + } - if(x($options,'networks')) { + if (x($options,'networks')) { switch($options['networks']) { case 'DFRN_ONLY': $networks = array(NETWORK_DFRN); @@ -142,12 +148,13 @@ function contact_selector($selname, $selclass, $preselected = false, $options) { call_hooks($a->module . '_pre_' . $selname, $arr); - if(count($r)) { - foreach($r as $rr) { - if((is_array($preselected)) && in_array($rr['id'], $preselected)) + if (dbm::is_result($r)) { + foreach ($r as $rr) { + if ((is_array($preselected)) && in_array($rr['id'], $preselected)) { $selected = " selected=\"selected\" "; - else + } else { $selected = ''; + } $trimmed = mb_substr($rr['name'],0,20); @@ -218,17 +225,20 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p $receiverlist = array(); - if(count($r)) { - foreach($r as $rr) { - if((is_array($preselected)) && in_array($rr['id'], $preselected)) + if (dbm::is_result($r)) { + foreach ($r as $rr) { + if ((is_array($preselected)) && in_array($rr['id'], $preselected)) { $selected = " selected=\"selected\" "; - else + } + else { $selected = ''; + } - if($privmail) + if ($privmail) { $trimmed = GetProfileUsername($rr['url'], $rr['name'], false); - else + } else { $trimmed = mb_substr($rr['name'],0,20); + } $receiverlist[] = $trimmed; @@ -254,16 +264,22 @@ function fixacl(&$item) { function prune_deadguys($arr) { - if(! $arr) + if (! $arr) { return $arr; + } + $str = dbesc(implode(',',$arr)); - $r = q("select id from contact where id in ( " . $str . ") and blocked = 0 and pending = 0 and archive = 0 "); - if($r) { + + $r = q("SELECT `id` FROM `contact` WHERE `id` IN ( " . $str . ") AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 "); + + if ($r) { $ret = array(); - foreach($r as $rr) + foreach ($r as $rr) { $ret[] = intval($rr['id']); + } return $ret; } + return array(); } @@ -312,7 +328,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(count($r)) { + if (dbm::is_result($r)) { $mail_enabled = true; if(intval($r[0]['pubmail'])) $pubmail_enabled = true; @@ -390,16 +406,18 @@ function construct_acl_data(&$a, $user) { function acl_lookup(&$a, $out_type = 'json') { - if(!local_user()) - return ""; + if (!local_user()) { + return ''; + } - $start = (x($_REQUEST,'start')?$_REQUEST['start']:0); - $count = (x($_REQUEST,'count')?$_REQUEST['count']:100); - $search = (x($_REQUEST,'search')?$_REQUEST['search']:""); - $type = (x($_REQUEST,'type')?$_REQUEST['type']:""); - $conv_id = (x($_REQUEST,'conversation')?$_REQUEST['conversation']:null); + $start = (x($_REQUEST,'start') ? $_REQUEST['start'] : 0); + $count = (x($_REQUEST,'count') ? $_REQUEST['count'] : 100); + $search = (x($_REQUEST,'search') ? $_REQUEST['search'] : ""); + $type = (x($_REQUEST,'type') ? $_REQUEST['type'] : ""); + $mode = (x($_REQUEST,'smode') ? $_REQUEST['smode'] : ""); + $conv_id = (x($_REQUEST,'conversation') ? $_REQUEST['conversation'] : null); - // For use with jquery.autocomplete for private mail completion + // For use with jquery.textcomplete for private mail completion if(x($_REQUEST,'query') && strlen($_REQUEST['query'])) { if(! $type) @@ -428,6 +446,7 @@ function acl_lookup(&$a, $out_type = 'json') { $sql_extra2 .= " ".unavailable_networks(); + // autocomplete for editor mentions if ($type=='' || $type=='c'){ $r = q("SELECT COUNT(*) AS c FROM `contact` WHERE `uid` = %d AND `self` = 0 @@ -476,12 +495,12 @@ function acl_lookup(&$a, $out_type = 'json') { if ($type=='' || $type=='g'){ - $r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') as uids - FROM `group`,`group_member` - WHERE `group`.`deleted` = 0 AND `group`.`uid` = %d - AND `group_member`.`gid`=`group`.`id` + $r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') AS uids + FROM `group` + INNER JOIN `group_member` ON `group_member`.`gid`=`group`.`id` AND `group_member`.`uid` = `group`.`uid` + WHERE NOT `group`.`deleted` AND `group`.`uid` = %d $sql_extra - GROUP BY `group`.`id` + GROUP BY `group`.`name` ORDER BY `group`.`name` LIMIT %d,%d", intval(local_user()), @@ -505,7 +524,7 @@ function acl_lookup(&$a, $out_type = 'json') { if ($type==''){ - $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, forum FROM `contact` + $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != '' AND NOT (`network` IN ('%s', '%s')) $sql_extra2 @@ -516,7 +535,7 @@ function acl_lookup(&$a, $out_type = 'json') { } elseif ($type=='c'){ - $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, forum FROM `contact` + $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != '' AND NOT (`network` IN ('%s')) $sql_extra2 @@ -536,31 +555,33 @@ function acl_lookup(&$a, $out_type = 'json') { dbesc(NETWORK_ZOT), dbesc(NETWORK_DIASPORA) ); - } - elseif($type == 'a') { - $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact` + } elseif ($type == 'a') { + $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra2 ORDER BY `name` ASC ", intval(local_user()) ); - } - elseif($type == 'x') { + } elseif ($type == 'x') { + // autocomplete for global contact search (e.g. navbar search) $r = navbar_complete($a); $contacts = array(); - if($r) { - foreach($r as $g) { + if ($r) { + foreach ($r as $g) { $contacts[] = array( - "photo" => $g['photo'], - "name" => $g['name'], - "nick" => (x($g['addr']) ? $g['addr'] : $g['url']), + 'photo' => proxy_url($g['photo'], false, PROXY_SIZE_MICRO), + 'name' => $g['name'], + 'nick' => (x($g['addr']) ? $g['addr'] : $g['url']), + 'network' => $g['network'], + 'link' => $g['url'], + 'forum' => (x($g['community']) ? 1 : 0), ); } } $o = array( 'start' => $start, - 'count' => $count, - 'items' => $contacts, + 'count' => $count, + 'items' => $contacts, ); echo json_encode($o); killme(); @@ -569,36 +590,17 @@ function acl_lookup(&$a, $out_type = 'json') { $r = array(); - if($type == 'm' || $type == 'a') { - $x = array(); - $x['query'] = $search; - $x['photos'] = array(); - $x['links'] = array(); - $x['suggestions'] = array(); - $x['data'] = array(); - if(count($r)) { - foreach($r as $g) { - $x['photos'][] = proxy_url($g['micro'], false, PROXY_SIZE_MICRO); - $x['links'][] = $g['url']; - $x['suggestions'][] = htmlentities($g['name']); - $x['data'][] = intval($g['id']); - } - } - echo json_encode($x); - killme(); - } - - if(count($r)) { - foreach($r as $g){ + if (dbm::is_result($r)) { + foreach ($r as $g){ $contacts[] = array( - "type" => "c", - "photo" => proxy_url($g['micro'], false, PROXY_SIZE_MICRO), - "name" => htmlentities($g['name']), - "id" => intval($g['id']), - "network" => $g['network'], - "link" => $g['url'], - "nick" => htmlentities(($g['attag']) ? $g['attag'] : $g['nick']), - "forum" => $g['forum'] + 'type' => 'c', + 'photo' => proxy_url($g['micro'], false, PROXY_SIZE_MICRO), + 'name' => htmlentities($g['name']), + 'id' => intval($g['id']), + 'network' => $g['network'], + 'link' => $g['url'], + 'nick' => htmlentities(($g['attag']) ? $g['attag'] : $g['nick']), + 'forum' => ((x($g['forum']) || x($g['prv'])) ? 1 : 0), ); } } @@ -611,14 +613,10 @@ function acl_lookup(&$a, $out_type = 'json') { function _contact_link($i){ return dbesc($i['link']); } $known_contacts = array_map(_contact_link, $contacts); $unknow_contacts=array(); - $r = q("select - `author-avatar`,`author-name`,`author-link` - from item where parent=%d - and ( - `author-name` LIKE '%%%s%%' OR - `author-link` LIKE '%%%s%%' - ) and - `author-link` NOT IN ('%s') + $r = q("SELECT `author-avatar`,`author-name`,`author-link` + FROM `item` WHERE `parent` = %d + AND (`author-name` LIKE '%%%s%%' OR `author-link` LIKE '%%%s%%') + AND `author-link` NOT IN ('%s') GROUP BY `author-link` ORDER BY `author-name` ASC ", @@ -627,8 +625,8 @@ function acl_lookup(&$a, $out_type = 'json') { dbesc($search), implode("','", $known_contacts) ); - if (is_array($r) && count($r)){ - foreach($r as $row) { + if (dbm::is_result($r)){ + foreach ($r as $row) { // nickname.. $up = parse_url($row['author-link']); $nick = explode("/",$up['path']); @@ -636,14 +634,14 @@ function acl_lookup(&$a, $out_type = 'json') { $nick .= "@".$up['host']; // /nickname $unknow_contacts[] = array( - "type" => "c", - "photo" => proxy_url($row['author-avatar'], false, PROXY_SIZE_MICRO), - "name" => htmlentities($row['author-name']), - "id" => '', - "network" => "unknown", - "link" => $row['author-link'], - "nick" => htmlentities($nick), - "forum" => false + 'type' => 'c', + 'photo' => proxy_url($row['author-avatar'], false, PROXY_SIZE_MICRO), + 'name' => htmlentities($row['author-name']), + 'id' => '', + 'network' => 'unknown', + 'link' => $row['author-link'], + 'nick' => htmlentities($nick), + 'forum' => false ); } } @@ -652,81 +650,88 @@ function acl_lookup(&$a, $out_type = 'json') { $tot += count($unknow_contacts); } + $results = array( + 'tot' => $tot, + 'start' => $start, + 'count' => $count, + 'groups' => $groups, + 'contacts' => $contacts, + 'items' => $items, + 'type' => $type, + 'search' => $search, + ); + + call_hooks('acl_lookup_end', $results); + if($out_type === 'html') { $o = array( - 'tot' => $tot, - 'start' => $start, - 'count' => $count, - 'groups' => $groups, - 'contacts' => $contacts, + 'tot' => $results['tot'], + 'start' => $results['start'], + 'count' => $results['count'], + 'groups' => $results['groups'], + 'contacts' => $results['contacts'], ); return $o; } $o = array( - 'tot' => $tot, - 'start' => $start, - 'count' => $count, - 'items' => $items, + 'tot' => $results['tot'], + 'start' => $results['start'], + 'count' => $results['count'], + 'items' => $results['items'], ); echo json_encode($o); killme(); } - +/** + * @brief Searching for global contacts for autocompletion + * + * @param App $a + * @return array with the search results + */ function navbar_complete(&$a) { // logger('navbar_complete'); - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { return; } - $local = get_config('system','poco_local_search'); - $local = true; + // check if searching in the local global contact table is enabled + $localsearch = get_config('system','poco_local_search'); $search = $prefix.notags(trim($_REQUEST['search'])); - if(! $search || mb_strlen($search) < 2) - return array(); - - $star = false; - $address = false; - - if(substr($search,0,1) === '@') - $search = substr($search,1); + $mode = $_REQUEST['smode']; - if(substr($search,0,1) === '*') { - $star = true; - $search = substr($search,1); + // don't search if search term has less than 2 characters + if (! $search || mb_strlen($search) < 2) { + return array(); } - if(strpos($search,'@') !== false) { - $address = true; + if (substr($search,0,1) === '@') { + $search = substr($search,1); } - if($local) { - require_once("include/dir_fns.php"); - $x = dirsearch_autocomplete($search); + if ($localsearch) { + $x = DirSearch::global_search_by_name($search, $mode); return $x; } - if(! $local) { - require_once("include/dir_fns.php"); - $url = $directory['url'] . '/dirsearch'; - - + if (! $localsearch) { $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : ''); - $x = z_fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search)); - if($x['success']) { + if ($x['success']) { $t = 0; $j = json_decode($x['body'],true); - if($j && $j['results']) { + if ($j && $j['results']) { return $j['results']; } } } + + /// @TODO Not needed here? return; -} \ No newline at end of file +}