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