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.
 
 
 
 
 
 

232 lines
7.1 KiB

  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. $discover_user = false;
  20. $local = get_config('system','poco_local_search');
  21. $search = $prefix.notags(trim($_REQUEST['search']));
  22. if(strpos($search,'@') === 0) {
  23. $search = substr($search,1);
  24. if ((valid_email($search) AND validate_email($search)) OR
  25. (substr(normalise_link($search), 0, 7) == "http://")) {
  26. $user_data = probe_url($search);
  27. $discover_user = (in_array($user_data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)));
  28. }
  29. }
  30. if(strpos($search,'!') === 0) {
  31. $search = substr($search,1);
  32. $community = true;
  33. }
  34. $o = '';
  35. if($search) {
  36. if ($discover_user) {
  37. $j = new stdClass();
  38. $j->total = 1;
  39. $j->items_page = 1;
  40. $j->page = $a->pager['page'];
  41. $objresult = new stdClass();
  42. $objresult->cid = 0;
  43. $objresult->name = $user_data["name"];
  44. $objresult->addr = $user_data["addr"];
  45. $objresult->url = $user_data["url"];
  46. $objresult->photo = $user_data["photo"];
  47. $objresult->tags = "";
  48. $objresult->network = $user_data["network"];
  49. $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
  50. dbesc(normalise_link($user_data["url"])), intval(local_user()));
  51. if ($contact)
  52. $objresult->cid = $contact[0]["id"];
  53. $j->results[] = $objresult;
  54. poco_check($user_data["url"], $user_data["name"], $user_data["network"], $user_data["photo"],
  55. "", "", "", "", "", datetime_convert(), 0);
  56. } elseif ($local) {
  57. if ($community)
  58. $extra_sql = " AND `community`";
  59. else
  60. $extra_sql = "";
  61. $perpage = 80;
  62. $startrec = (($a->pager['page']) * $perpage) - $perpage;
  63. if (get_config('system','diaspora_enabled'))
  64. $diaspora = NETWORK_DIASPORA;
  65. else
  66. $diaspora = NETWORK_DFRN;
  67. if (!get_config('system','ostatus_disabled'))
  68. $ostatus = NETWORK_OSTATUS;
  69. else
  70. $ostatus = NETWORK_DFRN;
  71. $count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND
  72. (`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR
  73. `about` REGEXP '%s' OR `keywords` REGEXP '%s')".$extra_sql,
  74. dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
  75. dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
  76. dbesc(escape_tags($search)), dbesc(escape_tags($search)));
  77. $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
  78. FROM `gcontact`
  79. LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
  80. AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
  81. AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
  82. WHERE `gcontact`.`network` IN ('%s', '%s', '%s') AND
  83. ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)) AND
  84. (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR
  85. `gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql
  86. GROUP BY `gcontact`.`nurl`
  87. ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
  88. intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
  89. dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
  90. dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
  91. dbesc(escape_tags($search)), dbesc(escape_tags($search)),
  92. intval($startrec), intval($perpage));
  93. $j = new stdClass();
  94. $j->total = $count[0]["total"];
  95. $j->items_page = $perpage;
  96. $j->page = $a->pager['page'];
  97. foreach ($results AS $result) {
  98. if (poco_alternate_ostatus_url($result["url"]))
  99. continue;
  100. if ($result["name"] == "") {
  101. $urlparts = parse_url($result["url"]);
  102. $result["name"] = end(explode("/", $urlparts["path"]));
  103. }
  104. $objresult = new stdClass();
  105. $objresult->cid = $result["cid"];
  106. $objresult->name = $result["name"];
  107. $objresult->addr = $result["addr"];
  108. $objresult->url = $result["url"];
  109. $objresult->photo = $result["photo"];
  110. $objresult->tags = $result["keywords"];
  111. $objresult->network = $result["network"];
  112. $j->results[] = $objresult;
  113. }
  114. // Add found profiles from the global directory to the local directory
  115. proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
  116. } else {
  117. $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
  118. if(strlen(get_config('system','directory')))
  119. $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
  120. $j = json_decode($x);
  121. }
  122. if($j->total) {
  123. $a->set_pager_total($j->total);
  124. $a->set_pager_itemspage($j->items_page);
  125. }
  126. if(count($j->results)) {
  127. $id = 0;
  128. foreach($j->results as $jj) {
  129. $alt_text = "";
  130. $contact_details = get_contact_details_by_url($jj->url, local_user());
  131. $itemurl = (($contact_details["addr"] != "") ? $contact_details["addr"] : $jj->url);
  132. // If We already know this contact then don't show the "connect" button
  133. if ($jj->cid > 0) {
  134. $connlnk = "";
  135. $conntxt = "";
  136. $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
  137. intval($jj->cid));
  138. if ($contact) {
  139. $photo_menu = contact_photo_menu($contact[0]);
  140. $details = _contact_detail_for_template($contact[0]);
  141. $alt_text = $details['alt_text'];
  142. } else
  143. $photo_menu = array();
  144. } else {
  145. $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
  146. $conntxt = t('Connect');
  147. $photo_menu = array(array(t("View Profile"), zrl($jj->url)));
  148. $photo_menu[] = array(t("Connect/Follow"), $connlnk);
  149. }
  150. $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
  151. $entry = array(
  152. 'alt_text' => $alt_text,
  153. 'url' => zrl($jj->url),
  154. 'itemurl' => $itemurl,
  155. 'name' => htmlentities($jj->name),
  156. 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
  157. 'img_hover' => $jj->tags,
  158. 'conntxt' => $conntxt,
  159. 'connlnk' => $connlnk,
  160. 'photo_menu' => $photo_menu,
  161. 'details' => $contact_details['location'],
  162. 'tags' => $contact_details['keywords'],
  163. 'about' => $contact_details['about'],
  164. 'account_type' => (($contact_details['community']) ? t('Forum') : ''),
  165. 'network' => network_to_name($jj->network, $jj->url),
  166. 'id' => ++$id,
  167. );
  168. $entries[] = $entry;
  169. }
  170. $tpl = get_markup_template('viewcontact_template.tpl');
  171. $o .= replace_macros($tpl,array(
  172. 'title' => sprintf( t('People Search - %s'), $search),
  173. '$contacts' => $entries,
  174. '$paginate' => paginate($a),
  175. ));
  176. }
  177. else {
  178. info( t('No matches') . EOL);
  179. }
  180. }
  181. return $o;
  182. }