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.

111 lines
3.0KB

  1. <?php
  2. /**
  3. * @file mod/allfriends.php
  4. */
  5. use Friendica\App;
  6. use Friendica\Content\ContactSelector;
  7. use Friendica\Content\Pager;
  8. use Friendica\Core\L10n;
  9. use Friendica\Core\Renderer;
  10. use Friendica\Core\System;
  11. use Friendica\Database\DBA;
  12. use Friendica\Model;
  13. use Friendica\Module;
  14. use Friendica\Util\Proxy as ProxyUtils;
  15. function allfriends_content(App $a)
  16. {
  17. $o = '';
  18. if (!local_user()) {
  19. notice(L10n::t('Permission denied.') . EOL);
  20. return;
  21. }
  22. $cid = 0;
  23. if ($a->argc > 1) {
  24. $cid = intval($a->argv[1]);
  25. }
  26. if (!$cid) {
  27. return;
  28. }
  29. $uid = $a->user['uid'];
  30. $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['id' => $cid, 'uid' => local_user()]);
  31. if (!DBA::isResult($contact)) {
  32. return;
  33. }
  34. $a->page['aside'] = "";
  35. Model\Profile::load($a, "", 0, Model\Contact::getDetailsByURL($contact["url"]));
  36. $total = Model\GContact::countAllFriends(local_user(), $cid);
  37. $pager = new Pager($a->query_string);
  38. $r = Model\GContact::allFriends(local_user(), $cid, $pager->getStart(), $pager->getItemsPerPage());
  39. if (!DBA::isResult($r)) {
  40. $o .= L10n::t('No friends to display.');
  41. return $o;
  42. }
  43. $id = 0;
  44. $entries = [];
  45. foreach ($r as $rr) {
  46. //get further details of the contact
  47. $contact_details = Model\Contact::getDetailsByURL($rr['url'], $uid, $rr);
  48. $photo_menu = '';
  49. $connlnk = '';
  50. // $rr[cid] is only available for common contacts. So if the contact is a common one, use contact_photo_menu to generate the photo_menu
  51. // If the contact is not common to the user, Connect/Follow' will be added to the photo menu
  52. if ($rr['cid']) {
  53. $rr['id'] = $rr['cid'];
  54. $photo_menu = Model\Contact::photoMenu($rr);
  55. } else {
  56. $connlnk = System::baseUrl() . '/follow/?url=' . $rr['url'];
  57. $photo_menu = [
  58. 'profile' => [L10n::t("View Profile"), Model\Contact::magicLink($rr['url'])],
  59. 'follow' => [L10n::t("Connect/Follow"), $connlnk]
  60. ];
  61. }
  62. $entry = [
  63. 'url' => $rr['url'],
  64. 'itemurl' => defaults($contact_details, 'addr', $rr['url']),
  65. 'name' => htmlentities($contact_details['name']),
  66. 'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
  67. 'img_hover' => htmlentities($contact_details['name']),
  68. 'details' => $contact_details['location'],
  69. 'tags' => $contact_details['keywords'],
  70. 'about' => $contact_details['about'],
  71. 'account_type' => Model\Contact::getAccountType($contact_details),
  72. 'network' => ContactSelector::networkToName($contact_details['network'], $contact_details['url']),
  73. 'photo_menu' => $photo_menu,
  74. 'conntxt' => L10n::t('Connect'),
  75. 'connlnk' => $connlnk,
  76. 'id' => ++$id,
  77. ];
  78. $entries[] = $entry;
  79. }
  80. $tab_str = Module\Contact::getTabsHTML($a, $contact, 4);
  81. $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
  82. $o .= Renderer::replaceMacros($tpl, [
  83. //'$title' => L10n::t('Friends of %s', htmlentities($c[0]['name'])),
  84. '$tab_str' => $tab_str,
  85. '$contacts' => $entries,
  86. '$paginate' => $pager->renderFull($total),
  87. ]);
  88. return $o;
  89. }