Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.0 KiB

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