]> git.mxchange.org Git - friendica.git/blob - include/dir_fns.php
rework autocomplete: some cleanup and docu
[friendica.git] / include / dir_fns.php
1 <?php
2
3 /**
4  * @file include/dir_fns.php
5  * @brief Functions for directory
6  */
7
8 /**
9  * @brief Search global contact table by nick or name
10  *  * 
11  * @param string $search
12  * @return array
13  */
14 function dirsearch_global_by_name($search) {
15
16         if($search) {
17                 // check supported networks
18                 if (get_config('system','diaspora_enabled'))
19                         $diaspora = NETWORK_DIASPORA;
20                 else
21                         $diaspora = NETWORK_DFRN;
22
23                 if (!get_config('system','ostatus_disabled'))
24                         $ostatus = NETWORK_OSTATUS;
25                 else
26                         $ostatus = NETWORK_DFRN;
27
28                 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`nick`, `gcontact`.`photo`,
29                                                 `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
30                                         FROM `gcontact`
31                                         LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
32                                                 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
33                                                 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
34                                         WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
35                                         ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
36                                         (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`nick` REGEXP '%s'
37                                                 ) 
38                                                 GROUP BY `gcontact`.`nurl`
39                                                 ORDER BY `gcontact`.`updated` DESC ",
40                                         intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
41                                         dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
42                                         dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)));
43                 return $results;
44         }
45                 
46 }