]> git.mxchange.org Git - friendica.git/commitdiff
rework autocomplete: make remote and local search work
authorrabuzarus <>
Wed, 20 Jan 2016 02:34:22 +0000 (03:34 +0100)
committerrabuzarus <>
Wed, 20 Jan 2016 02:34:22 +0000 (03:34 +0100)
include/acl_selectors.php
include/dir_fns.php [new file with mode: 0644]
include/nav.php

index 69181b7359bcb1ab68af4e84892782156771bf8c..19197981e023681f1f0793cb0d4eeb38007a4af6 100644 (file)
@@ -545,6 +545,26 @@ function acl_lookup(&$a, $out_type = 'json') {
                        intval(local_user())
                );
        }
+       elseif($type == 'x') {
+               $r = navbar_complete($a);
+               $contacts = array();
+               if($r) {
+                       foreach($r as $g) {
+                               $contacts[] = array(
+                                       "photo"    => $g['photo'],
+                                       "name"     => $g['name'],
+                                       "nick"     => (x($g['addr']) ? $g['addr'] : $g['url']),
+                               );
+                       }
+               }
+               $o = array(
+                       'start' => $start,
+                       'count' => $count,
+                       'items' => $contacts,
+               );
+               echo json_encode($o);
+               killme();
+       }
        else
                $r = array();
 
@@ -655,3 +675,58 @@ function acl_lookup(&$a, $out_type = 'json') {
        killme();
 }
 
+function navbar_complete(&$a) {
+
+//     logger('navbar_complete');
+
+       if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
+               return;
+       }
+
+       $local = get_config('system','poco_local_search');
+       $local = true;
+
+       $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);
+
+       if(substr($search,0,1) === '*') {
+               $star = true;
+               $search = substr($search,1);
+       }
+
+       if(strpos($search,'@') !== false) {
+               $address = true;
+       }
+
+       if($local) {
+               require_once("include/dir_fns.php");
+               $x = dirsearch_autocomplete($search);
+               return $x;
+       }
+
+       if(! $local) {
+               require_once("include/dir_fns.php");
+               $url = $directory['url'] . '/dirsearch';
+       
+
+               $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
+       
+
+               $x = z_fetch_url(get_server().'/lsearch?f=' . $p .  '&search=' . urlencode($search));
+               if($x['success']) {
+                       $t = 0;
+                       $j = json_decode($x['body'],true);
+                       if($j && $j['results']) {
+                               return $j['results'];
+                       }
+               }
+       }
+       return;
+}
\ No newline at end of file
diff --git a/include/dir_fns.php b/include/dir_fns.php
new file mode 100644 (file)
index 0000000..a362732
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+
+
+function dirsearch_autocomplete($search) {
+
+       if($search) {
+
+               if (get_config('system','diaspora_enabled'))
+                       $diaspora = NETWORK_DIASPORA;
+               else
+                       $diaspora = NETWORK_DFRN;
+
+               if (!get_config('system','ostatus_disabled'))
+                       $ostatus = NETWORK_OSTATUS;
+               else
+                       $ostatus = NETWORK_DFRN;
+
+               $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`nick`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
+                                       FROM `gcontact`
+                                       LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
+                                               AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
+                                               AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
+                                       WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
+                                       ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
+                                       (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`nick` REGEXP '%s'
+                                               ) 
+                                               GROUP BY `gcontact`.`nurl`
+                                               ORDER BY `gcontact`.`updated` DESC ",
+                                       intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
+                                       dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
+                                       dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)));
+               return $results;
+       }
+               
+}
\ No newline at end of file
index 6512d35609f25e031674a1a673434b748211cb23..0261ab7d6673383f6133532037ea5292796fd088 100644 (file)
@@ -11,10 +11,18 @@ function nav(&$a) {
        if(!(x($a->page,'nav')))
                $a->page['nav'] = '';
 
+       $base = z_root();
        /**
         * Placeholder div for popup panel
         */
 
+       $a->page['htmlhead'] .= <<< EOT
+
+<script>$(document).ready(function() {
+               $("#search-text").search_autocomplete('$base/acl');
+});
+</script>
+EOT;
        $a->page['nav'] .= '<div id="panel" style="display: none;"></div>' ;
 
        $nav_info = nav_info($a);