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