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.

192 lines
5.6 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. <?php
  2. require_once('include/contact_widgets.php');
  3. require_once('include/socgraph.php');
  4. require_once('include/Contact.php');
  5. require_once('include/contact_selectors.php');
  6. require_once('mod/contacts.php');
  7. function dirfind_init(&$a) {
  8. if(! local_user()) {
  9. notice( t('Permission denied.') . EOL );
  10. return;
  11. }
  12. if(! x($a->page,'aside'))
  13. $a->page['aside'] = '';
  14. $a->page['aside'] .= findpeople_widget();
  15. $a->page['aside'] .= follow_widget();
  16. }
  17. function dirfind_content(&$a, $prefix = "") {
  18. $community = false;
  19. $local = get_config('system','poco_local_search');
  20. $search = $prefix.notags(trim($_REQUEST['search']));
  21. if(strpos($search,'@') === 0)
  22. $search = substr($search,1);
  23. if(strpos($search,'!') === 0) {
  24. $search = substr($search,1);
  25. $community = true;
  26. }
  27. $o = '';
  28. if($search) {
  29. if ($local) {
  30. if ($community)
  31. $extra_sql = " AND `community`";
  32. else
  33. $extra_sql = "";
  34. $perpage = 80;
  35. $startrec = (($a->pager['page']) * $perpage) - $perpage;
  36. if (get_config('system','diaspora_enabled'))
  37. $diaspora = NETWORK_DIASPORA;
  38. else
  39. $diaspora = NETWORK_DFRN;
  40. if (!get_config('system','ostatus_disabled'))
  41. $ostatus = NETWORK_OSTATUS;
  42. else
  43. $ostatus = NETWORK_DFRN;
  44. $count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND
  45. (`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR
  46. `about` REGEXP '%s' OR `keywords` REGEXP '%s')".$extra_sql,
  47. dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
  48. dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
  49. dbesc(escape_tags($search)), dbesc(escape_tags($search)));
  50. $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network` , `gcontact`.`keywords`
  51. FROM `gcontact`
  52. LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
  53. AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
  54. AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
  55. WHERE `gcontact`.`network` IN ('%s', '%s', '%s') AND
  56. ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)) AND
  57. (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR
  58. `gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql
  59. GROUP BY `gcontact`.`nurl`
  60. ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
  61. intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
  62. dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
  63. dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
  64. dbesc(escape_tags($search)), dbesc(escape_tags($search)),
  65. intval($startrec), intval($perpage));
  66. $j = new stdClass();
  67. $j->total = $count[0]["total"];
  68. $j->items_page = $perpage;
  69. $j->page = $a->pager['page'];
  70. foreach ($results AS $result) {
  71. if (poco_alternate_ostatus_url($result["url"]))
  72. continue;
  73. if ($result["name"] == "") {
  74. $urlparts = parse_url($result["url"]);
  75. $result["name"] = end(explode("/", $urlparts["path"]));
  76. }
  77. $objresult = new stdClass();
  78. $objresult->cid = $result["cid"];
  79. $objresult->name = $result["name"];
  80. $objresult->url = $result["url"];
  81. $objresult->photo = $result["photo"];
  82. $objresult->tags = $result["keywords"];
  83. $objresult->network = $result["network"];
  84. $j->results[] = $objresult;
  85. }
  86. // Add found profiles from the global directory to the local directory
  87. proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
  88. } else {
  89. $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
  90. if(strlen(get_config('system','directory')))
  91. $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
  92. $j = json_decode($x);
  93. }
  94. if($j->total) {
  95. $a->set_pager_total($j->total);
  96. $a->set_pager_itemspage($j->items_page);
  97. }
  98. if(count($j->results)) {
  99. $id = 0;
  100. foreach($j->results as $jj) {
  101. $alt_text = "";
  102. $itemurl = $jj->url;
  103. // If We already know this contact then don't show the "connect" button
  104. if ($jj->cid > 0) {
  105. $connlnk = "";
  106. $conntxt = "";
  107. $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
  108. intval($jj->cid));
  109. if ($contact) {
  110. $photo_menu = contact_photo_menu($contact[0]);
  111. $details = _contact_detail_for_template($contact[0]);
  112. $alt_text = $details['alt_text'];
  113. } else
  114. $photo_menu = array();
  115. } else {
  116. $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
  117. $conntxt = t('Connect');
  118. $photo_menu = array(array(t("View Profile"), zrl($jj->url)));
  119. $photo_menu[] = array(t("Connect/Follow"), $connlnk);
  120. }
  121. $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
  122. $entry = array(
  123. 'alt_text' => $alt_text,
  124. 'url' => zrl($jj->url),
  125. 'itemurl' => $itemurl,
  126. 'name' => htmlentities($jj->name),
  127. 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
  128. 'img_hover' => $jj->tags,
  129. 'conntxt' => $conntxt,
  130. 'connlnk' => $connlnk,
  131. 'photo_menu' => $photo_menu,
  132. 'network' => network_to_name($jj->network, $jj->url),
  133. 'id' => ++$id,
  134. );
  135. $entries[] = $entry;
  136. }
  137. $tpl = get_markup_template('viewcontact_template.tpl');
  138. $o .= replace_macros($tpl,array(
  139. 'title' => sprintf( t('People Search - %s'), $search),
  140. '$contacts' => $entries,
  141. '$paginate' => paginate($a),
  142. ));
  143. }
  144. else {
  145. info( t('No matches') . EOL);
  146. }
  147. }
  148. return $o;
  149. }