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