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.

155 lines
4.1KB

  1. <?php
  2. /**
  3. * @file include/common.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\Database\DBA;
  11. use Friendica\Model;
  12. use Friendica\Module;
  13. use Friendica\Util\Proxy as ProxyUtils;
  14. use Friendica\Util\Strings;
  15. function common_content(App $a)
  16. {
  17. $o = '';
  18. $cmd = $a->argv[1];
  19. $uid = intval($a->argv[2]);
  20. $cid = intval($a->argv[3]);
  21. $zcid = 0;
  22. if (!local_user()) {
  23. notice(L10n::t('Permission denied.') . EOL);
  24. return;
  25. }
  26. if ($cmd !== 'loc' && $cmd != 'rem') {
  27. return;
  28. }
  29. if (!$uid) {
  30. return;
  31. }
  32. if ($cmd === 'loc' && $cid) {
  33. $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['id' => $cid, 'uid' => $uid]);
  34. if (DBA::isResult($contact)) {
  35. $a->page['aside'] = "";
  36. Model\Profile::load($a, "", 0, Model\Contact::getDetailsByURL($contact["url"]));
  37. }
  38. } else {
  39. $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['self' => true, 'uid' => $uid]);
  40. if (DBA::isResult($contact)) {
  41. $vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate("vcard-widget.tpl"), [
  42. '$name' => htmlentities($contact['name']),
  43. '$photo' => $contact['photo'],
  44. 'url' => 'contact/' . $cid
  45. ]);
  46. if (empty($a->page['aside'])) {
  47. $a->page['aside'] = '';
  48. }
  49. $a->page['aside'] .= $vcard_widget;
  50. }
  51. }
  52. if (!DBA::isResult($contact)) {
  53. return;
  54. }
  55. if (!$cid && Model\Profile::getMyURL()) {
  56. $contact = DBA::selectFirst('contact', ['id'], ['nurl' => Strings::normaliseLink(Model\Profile::getMyURL()), 'uid' => $uid]);
  57. if (DBA::isResult($contact)) {
  58. $cid = $contact['id'];
  59. } else {
  60. $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => Strings::normaliseLink(Model\Profile::getMyURL())]);
  61. if (DBA::isResult($gcontact)) {
  62. $zcid = $gcontact['id'];
  63. }
  64. }
  65. }
  66. if ($cid == 0 && $zcid == 0) {
  67. return;
  68. }
  69. if ($cid) {
  70. $total = Model\GContact::countCommonFriends($uid, $cid);
  71. } else {
  72. $total = Model\GContact::countCommonFriendsZcid($uid, $zcid);
  73. }
  74. if ($total < 1) {
  75. notice(L10n::t('No contacts in common.') . EOL);
  76. return $o;
  77. }
  78. $pager = new Pager($a->query_string);
  79. if ($cid) {
  80. $common_friends = Model\GContact::commonFriends($uid, $cid, $pager->getStart(), $pager->getItemsPerPage());
  81. } else {
  82. $common_friends = Model\GContact::commonFriendsZcid($uid, $zcid, $pager->getStart(), $pager->getItemsPerPage());
  83. }
  84. if (!DBA::isResult($common_friends)) {
  85. return $o;
  86. }
  87. $id = 0;
  88. $entries = [];
  89. foreach ($common_friends as $common_friend) {
  90. //get further details of the contact
  91. $contact_details = Model\Contact::getDetailsByURL($common_friend['url'], $uid);
  92. // $rr['id'] is needed to use contact_photo_menu()
  93. /// @TODO Adding '/" here avoids E_NOTICE on missing constants
  94. $common_friend['id'] = $common_friend['cid'];
  95. $photo_menu = Model\Contact::photoMenu($common_friend);
  96. $entry = [
  97. 'url' => $common_friend['url'],
  98. 'itemurl' => defaults($contact_details, 'addr', $common_friend['url']),
  99. 'name' => $contact_details['name'],
  100. 'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
  101. 'img_hover' => htmlentities($contact_details['name']),
  102. 'details' => $contact_details['location'],
  103. 'tags' => $contact_details['keywords'],
  104. 'about' => $contact_details['about'],
  105. 'account_type' => Model\Contact::getAccountType($contact_details),
  106. 'network' => ContactSelector::networkToName($contact_details['network'], $contact_details['url']),
  107. 'photo_menu' => $photo_menu,
  108. 'id' => ++$id,
  109. ];
  110. $entries[] = $entry;
  111. }
  112. $title = '';
  113. $tab_str = '';
  114. if ($cmd === 'loc' && $cid && local_user() == $uid) {
  115. $tab_str = Module\Contact::getTabsHTML($a, $contact, 4);
  116. } else {
  117. $title = L10n::t('Common Friends');
  118. }
  119. $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
  120. $o .= Renderer::replaceMacros($tpl, [
  121. '$title' => $title,
  122. '$tab_str' => $tab_str,
  123. '$contacts' => $entries,
  124. '$paginate' => $pager->renderFull($total),
  125. ]);
  126. return $o;
  127. }