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.

156 lines
4.1 KiB

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