X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Facl_selectors.php;h=f4b644d68fb0201a322db05d497f324fe31f74df;hb=ce10a9aa7f97424caa3f2db5d5fd54a2da850ca3;hp=b2e66c98f00ffa28682809285be036e7b0855e5c;hpb=4c04a78d1b6f14ce90e4ca0b23e356d234c4a296;p=friendica.git diff --git a/include/acl_selectors.php b/include/acl_selectors.php index b2e66c98f0..f4b644d68f 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -65,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); @@ -131,7 +135,7 @@ function contact_selector($selname, $selclass, $preselected = false, $options) { $o .= "\r\n"; $r = q("SELECT `id`, `name`, `url`, `network` FROM `contact` - WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != '' + WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != '' $sql_extra ORDER BY `name` ASC ", intval(local_user()) @@ -231,8 +236,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p if ($privmail) { $trimmed = GetProfileUsername($rr['url'], $rr['name'], false); - } - else { + } else { $trimmed = mb_substr($rr['name'],0,20); } @@ -260,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) { + + if (dbm::is_result($r)) { $ret = array(); - foreach($r as $rr) + foreach ($r as $rr) { $ret[] = intval($rr['id']); + } return $ret; } + return array(); } @@ -362,7 +372,7 @@ function populate_acl($user = null, $show_jotnets = false) { } -function construct_acl_data(&$a, $user) { +function construct_acl_data(App $a, $user) { // Get group and contact information for html ACL selector $acl_data = acl_lookup($a, 'html'); @@ -394,7 +404,7 @@ function construct_acl_data(&$a, $user) { } -function acl_lookup(&$a, $out_type = 'json') { +function acl_lookup(App $a, $out_type = 'json') { if (!local_user()) { return ''; @@ -439,8 +449,8 @@ function acl_lookup(&$a, $out_type = 'json') { // autocomplete for editor mentions if ($type=='' || $type=='c'){ $r = q("SELECT COUNT(*) AS c FROM `contact` - WHERE `uid` = %d AND `self` = 0 - AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 + WHERE `uid` = %d AND NOT `self` + AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != '' $sql_extra2" , intval(local_user()) ); @@ -451,8 +461,8 @@ function acl_lookup(&$a, $out_type = 'json') { // autocomplete for Private Messages $r = q("SELECT COUNT(*) AS c FROM `contact` - WHERE `uid` = %d AND `self` = 0 - AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 + WHERE `uid` = %d AND NOT `self` + AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `network` IN ('%s','%s','%s') $sql_extra2" , intval(local_user()), dbesc(NETWORK_DFRN), @@ -467,8 +477,8 @@ function acl_lookup(&$a, $out_type = 'json') { // autocomplete for Contacts $r = q("SELECT COUNT(*) AS c FROM `contact` - WHERE `uid` = %d AND `self` = 0 - AND `pending` = 0 $sql_extra2" , + WHERE `uid` = %d AND NOT `self` + AND NOT `pending` $sql_extra2" , intval(local_user()) ); $contact_count = (int)$r[0]['c']; @@ -485,6 +495,8 @@ function acl_lookup(&$a, $out_type = 'json') { if ($type=='' || $type=='g'){ + /// @todo We should cache this query. + // This can be done when we can delete cache entries via wildcard $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` @@ -515,7 +527,7 @@ function acl_lookup(&$a, $out_type = 'json') { if ($type==''){ $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` != '' + WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != '' AND NOT (`network` IN ('%s', '%s')) $sql_extra2 ORDER BY `name` ASC ", @@ -526,7 +538,7 @@ function acl_lookup(&$a, $out_type = 'json') { elseif ($type=='c'){ $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` != '' + WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != '' AND NOT (`network` IN ('%s')) $sql_extra2 ORDER BY `name` ASC ", @@ -536,7 +548,7 @@ function acl_lookup(&$a, $out_type = 'json') { } elseif($type == 'm') { $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact` - WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 + WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `network` IN ('%s','%s','%s') $sql_extra2 ORDER BY `name` ASC ", @@ -545,54 +557,52 @@ function acl_lookup(&$a, $out_type = 'json') { dbesc(NETWORK_ZOT), dbesc(NETWORK_DIASPORA) ); - } - elseif($type == 'a') { + } 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) { + foreach ($r as $g) { $contacts[] = array( - "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), + '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(); - } - else + } else { $r = array(); + } if (dbm::is_result($r)) { - foreach($r as $g){ + 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" => ((x($g['forum']) || x($g['prv'])) ? 1 : 0), + '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), ); } } @@ -618,7 +628,7 @@ function acl_lookup(&$a, $out_type = 'json') { implode("','", $known_contacts) ); if (dbm::is_result($r)){ - foreach($r as $row) { + foreach ($r as $row) { // nickname.. $up = parse_url($row['author-link']); $nick = explode("/",$up['path']); @@ -626,14 +636,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 ); } } @@ -643,34 +653,34 @@ function acl_lookup(&$a, $out_type = 'json') { } $results = array( - "tot" => $tot, - "start" => $start, - "count" => $count, - "groups" => $groups, - "contacts" => $contacts, - "items" => $items, - "type" => $type, - "search" => $search, + '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' => $results["tot"], - 'start' => $results["start"], - 'count' => $results["count"], - 'groups' => $results["groups"], - 'contacts' => $results["contacts"], + 'tot' => $results['tot'], + 'start' => $results['start'], + 'count' => $results['count'], + 'groups' => $results['groups'], + 'contacts' => $results['contacts'], ); return $o; } $o = array( - 'tot' => $results["tot"], - 'start' => $results["start"], - 'count' => $results["count"], - 'items' => $results["items"], + 'tot' => $results['tot'], + 'start' => $results['start'], + 'count' => $results['count'], + 'items' => $results['items'], ); echo json_encode($o); @@ -679,15 +689,15 @@ function acl_lookup(&$a, $out_type = 'json') { } /** * @brief Searching for global contacts for autocompletion - * + * * @param App $a * @return array with the search results */ -function navbar_complete(App &$a) { +function navbar_complete(App $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; } @@ -698,28 +708,32 @@ function navbar_complete(App &$a) { $mode = $_REQUEST['smode']; // don't search if search term has less than 2 characters - if(! $search || mb_strlen($search) < 2) + if (! $search || mb_strlen($search) < 2) { return array(); + } - if(substr($search,0,1) === '@') + if (substr($search,0,1) === '@') { $search = substr($search,1); + } - if($localsearch) { + if ($localsearch) { $x = DirSearch::global_search_by_name($search, $mode); return $x; } - if(! $localsearch) { + 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; }