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.
 
 
 
 
 
 

120 lines
2.8 KiB

  1. <?php
  2. /*
  3. * @file src/Content/Widget/ContactBlock.php
  4. */
  5. namespace Friendica\Content\Widget;
  6. use Friendica\Content\Text\HTML;
  7. use Friendica\Core\Hook;
  8. use Friendica\Core\L10n;
  9. use Friendica\Core\Protocol;
  10. use Friendica\Core\Renderer;
  11. use Friendica\Database\DBA;
  12. use Friendica\DI;
  13. use Friendica\Model\Contact;
  14. use Friendica\Model\User;
  15. /**
  16. * ContactBlock widget
  17. *
  18. * @author Hypolite Petovan
  19. */
  20. class ContactBlock
  21. {
  22. /**
  23. * Get HTML for contact block
  24. *
  25. * @template widget/contacts.tpl
  26. * @hook contact_block_end (contacts=>array, output=>string)
  27. * @return string
  28. */
  29. public static function getHTML(array $profile)
  30. {
  31. $o = '';
  32. $shown = DI::pConfig()->get($profile['uid'], 'system', 'display_friend_count', 24);
  33. if ($shown == 0) {
  34. return $o;
  35. }
  36. if (!empty($profile['hide-friends'])) {
  37. return $o;
  38. }
  39. $contacts = [];
  40. $total = DBA::count('contact', [
  41. 'uid' => $profile['uid'],
  42. 'self' => false,
  43. 'blocked' => false,
  44. 'pending' => false,
  45. 'hidden' => false,
  46. 'archive' => false,
  47. 'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::FEED],
  48. ]);
  49. $contacts_title = L10n::t('No contacts');
  50. $micropro = [];
  51. if ($total) {
  52. // Only show followed for personal accounts, followers for pages
  53. if ((($profile['account-type'] ?? '') ?: User::ACCOUNT_TYPE_PERSON) == User::ACCOUNT_TYPE_PERSON) {
  54. $rel = [Contact::SHARING, Contact::FRIEND];
  55. } else {
  56. $rel = [Contact::FOLLOWER, Contact::FRIEND];
  57. }
  58. $contact_ids_stmt = DBA::select('contact', ['id'], [
  59. 'uid' => $profile['uid'],
  60. 'self' => false,
  61. 'blocked' => false,
  62. 'pending' => false,
  63. 'hidden' => false,
  64. 'archive' => false,
  65. 'rel' => $rel,
  66. 'network' => Protocol::FEDERATED,
  67. ], ['limit' => $shown]);
  68. if (DBA::isResult($contact_ids_stmt)) {
  69. $contact_ids = [];
  70. while($contact = DBA::fetch($contact_ids_stmt)) {
  71. $contact_ids[] = $contact["id"];
  72. }
  73. $contacts_stmt = DBA::select('contact', ['id', 'uid', 'addr', 'url', 'name', 'thumb', 'network'], ['id' => $contact_ids]);
  74. if (DBA::isResult($contacts_stmt)) {
  75. $contacts_title = L10n::tt('%d Contact', '%d Contacts', $total);
  76. $micropro = [];
  77. while ($contact = DBA::fetch($contacts_stmt)) {
  78. $contacts[] = $contact;
  79. $micropro[] = HTML::micropro($contact, true, 'mpfriend');
  80. }
  81. }
  82. DBA::close($contacts_stmt);
  83. }
  84. DBA::close($contact_ids_stmt);
  85. }
  86. $tpl = Renderer::getMarkupTemplate('widget/contacts.tpl');
  87. $o = Renderer::replaceMacros($tpl, [
  88. '$contacts' => $contacts_title,
  89. '$nickname' => $profile['nickname'],
  90. '$viewcontacts' => L10n::t('View Contacts'),
  91. '$micropro' => $micropro,
  92. ]);
  93. $arr = ['contacts' => $contacts, 'output' => $o];
  94. Hook::callAll('contact_block_end', $arr);
  95. return $o;
  96. }
  97. }