4 * @file include/DirSearch.php
5 * @brief This file includes the DirSearch class with directory related functions
8 use Friendica\Core\Config;
11 * @brief This class handels directory related functions
16 * @brief Search global contact table by nick or name
18 * @param string $search Name or nick
19 * @param string $mode Search mode (e.g. "community")
20 * @return array with search results
22 public static function global_search_by_name($search, $mode = '') {
25 // check supported networks
26 if (Config::get('system','diaspora_enabled'))
27 $diaspora = NETWORK_DIASPORA;
29 $diaspora = NETWORK_DFRN;
31 if (!Config::get('system','ostatus_disabled'))
32 $ostatus = NETWORK_OSTATUS;
34 $ostatus = NETWORK_DFRN;
36 // check if we search only communities or every contact
37 if($mode === "community")
38 $extra_sql = " AND `community`";
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`
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
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)));