Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

250 rindas
8.2KB

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