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.
 
 
 
 
 
 

112 lines
2.9 KiB

  1. <?php
  2. include_once('include/text.php');
  3. require_once('include/socgraph.php');
  4. require_once('include/contact_widgets.php');
  5. require_once('mod/proxy.php');
  6. /**
  7. * @brief Controller for /match.
  8. *
  9. * It takes keywords from your profile and queries the directory server for
  10. * matching keywords from other profiles.
  11. *
  12. * @param App &$a
  13. * @return void|string
  14. */
  15. function match_content(&$a) {
  16. $o = '';
  17. if(! local_user())
  18. return;
  19. $a->page['aside'] .= findpeople_widget();
  20. $a->page['aside'] .= follow_widget();
  21. $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
  22. $r = q("SELECT `pub_keywords`, `prv_keywords` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
  23. intval(local_user())
  24. );
  25. if(! count($r))
  26. return;
  27. if(! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) {
  28. notice( t('No keywords to match. Please add keywords to your default profile.') . EOL);
  29. return;
  30. }
  31. $params = array();
  32. $tags = trim($r[0]['pub_keywords'] . ' ' . $r[0]['prv_keywords']);
  33. if($tags) {
  34. $params['s'] = $tags;
  35. if($a->pager['page'] != 1)
  36. $params['p'] = $a->pager['page'];
  37. if(strlen(get_config('system','directory')))
  38. $x = post_url(get_server().'/msearch', $params);
  39. else
  40. $x = post_url($a->get_baseurl() . '/msearch', $params);
  41. $j = json_decode($x);
  42. if($j->total) {
  43. $a->set_pager_total($j->total);
  44. $a->set_pager_itemspage($j->items_page);
  45. }
  46. if(count($j->results)) {
  47. $id = 0;
  48. foreach($j->results as $jj) {
  49. $match_nurl = normalise_link($jj->url);
  50. $match = q("SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1",
  51. intval(local_user()),
  52. dbesc($match_nurl));
  53. if (!count($match)) {
  54. $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
  55. $connlnk = $a->get_baseurl() . '/follow/?url=' . $jj->url;
  56. $photo_menu = array(array(t("View Profile"), zrl($jj->url)));
  57. $photo_menu[] = array(t("Connect/Follow"), $connlnk);
  58. $contact_details = get_contact_details_by_url($jj->url, local_user());
  59. $entry = array(
  60. 'url' => zrl($jj->url),
  61. 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $jj->url),
  62. 'name' => $jj->name,
  63. 'details' => $contact_details['location'],
  64. 'tags' => $contact_details['keywords'],
  65. 'about' => $contact_details['about'],
  66. 'account_type' => (($contact_details['community']) ? t('Forum') : ''),
  67. 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
  68. 'inttxt' => ' ' . t('is interested in:'),
  69. 'conntxt' => t('Connect'),
  70. 'connlnk' => $connlnk,
  71. 'img_hover' => $jj->tags,
  72. 'photo_menu' => $photo_menu,
  73. 'id' => ++$id,
  74. );
  75. $entries[] = $entry;
  76. }
  77. }
  78. $tpl = get_markup_template('viewcontact_template.tpl');
  79. $o .= replace_macros($tpl,array(
  80. '$title' => t('Profile Match'),
  81. '$contacts' => $entries,
  82. '$paginate' => paginate($a),
  83. ));
  84. }
  85. else {
  86. info( t('No matches') . EOL);
  87. }
  88. }
  89. return $o;
  90. }