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.
 
 
 
 
 
 

129 lines
3.8 KiB

  1. <?php
  2. function dirfind_init(&$a) {
  3. require_once('include/contact_widgets.php');
  4. if(! x($a->page,'aside'))
  5. $a->page['aside'] = '';
  6. $a->page['aside'] .= follow_widget();
  7. $a->page['aside'] .= findpeople_widget();
  8. }
  9. function dirfind_content(&$a) {
  10. $local = get_config('system','poco_local_search');
  11. $search = notags(trim($_REQUEST['search']));
  12. if(strpos($search,'@') === 0)
  13. $search = substr($search,1);
  14. $o = '';
  15. $o .= replace_macros(get_markup_template("section_title.tpl"),array(
  16. '$title' => sprintf( t('People Search - %s'), $search)
  17. ));
  18. if($search) {
  19. if ($local) {
  20. $perpage = 80;
  21. $startrec = (($a->pager['page']) * $perpage) - $perpage;
  22. $count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND
  23. (`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR
  24. `about` REGEXP '%s' OR `keywords` REGEXP '%s')",
  25. dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA),
  26. dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
  27. dbesc(escape_tags($search)), dbesc(escape_tags($search)));
  28. $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`keywords`
  29. FROM `gcontact`
  30. LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl` AND `contact`.`uid` = %d
  31. WHERE `gcontact`.`network` IN ('%s', '%s', '%s') AND `gcontact`.`last_contact` >= `gcontact`.`last_failure` AND
  32. (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR
  33. `gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s')
  34. GROUP BY `gcontact`.`nurl`
  35. ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
  36. intval(local_user()), dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA),
  37. dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
  38. dbesc(escape_tags($search)), dbesc(escape_tags($search)),
  39. intval($startrec), intval($perpage));
  40. $j = new stdClass();
  41. $j->total = $count[0]["total"];
  42. $j->items_page = $perpage;
  43. $j->page = $a->pager['page'];
  44. foreach ($results AS $result) {
  45. if ($result["name"] == "") {
  46. $urlparts = parse_url($result["url"]);
  47. $result["name"] = end(explode("/", $urlparts["path"]));
  48. }
  49. $objresult = new stdClass();
  50. $objresult->cid = $result["cid"];
  51. $objresult->name = $result["name"];
  52. $objresult->url = $result["url"];
  53. $objresult->photo = $result["photo"];
  54. $objresult->tags = $result["keywords"];
  55. $j->results[] = $objresult;
  56. }
  57. // Add found profiles from the global directory to the local directory
  58. proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
  59. } else {
  60. $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
  61. if(strlen(get_config('system','directory_submit_url')))
  62. $x = fetch_url('http://dir.friendica.com/lsearch?f=' . $p . '&search=' . urlencode($search));
  63. $j = json_decode($x);
  64. }
  65. if($j->total) {
  66. $a->set_pager_total($j->total);
  67. $a->set_pager_itemspage($j->items_page);
  68. }
  69. if(count($j->results)) {
  70. $tpl = get_markup_template('match.tpl');
  71. foreach($j->results as $jj) {
  72. // If We already know this contact then don't show the "connect" button
  73. if ($jj->cid > 0) {
  74. $connlnk = "";
  75. $conntxt = "";
  76. } else {
  77. $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
  78. $conntxt = t('Connect');
  79. }
  80. $o .= replace_macros($tpl,array(
  81. '$url' => zrl($jj->url),
  82. '$name' => $jj->name,
  83. '$photo' => proxy_url($jj->photo),
  84. '$tags' => $jj->tags,
  85. '$conntxt' => $conntxt,
  86. '$connlnk' => $connlnk,
  87. ));
  88. }
  89. }
  90. else {
  91. info( t('No matches') . EOL);
  92. }
  93. }
  94. $o .= '<div class="clear"></div>';
  95. $o .= paginate($a);
  96. return $o;
  97. }