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.

157 lines
3.9KB

  1. <?php
  2. /**
  3. * @file mod/subthread.php
  4. */
  5. use Friendica\App;
  6. use Friendica\Core\Addon;
  7. use Friendica\Core\L10n;
  8. use Friendica\Core\Logger;
  9. use Friendica\Core\System;
  10. use Friendica\Database\DBA;
  11. use Friendica\Model\Item;
  12. use Friendica\Util\Security;
  13. use Friendica\Util\Strings;
  14. use Friendica\Util\XML;
  15. function subthread_content(App $a) {
  16. if (!local_user() && !remote_user()) {
  17. return;
  18. }
  19. $activity = ACTIVITY_FOLLOW;
  20. $item_id = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : 0);
  21. $condition = ["`parent` = ? OR `parent-uri` = ? AND `parent` = `id`", $item_id, $item_id];
  22. $item = Item::selectFirst([], $condition);
  23. if (empty($item_id) || !DBA::isResult($item)) {
  24. Logger::log('subthread: no item ' . $item_id);
  25. return;
  26. }
  27. $owner_uid = $item['uid'];
  28. if (!Security::canWriteToUserWall($owner_uid)) {
  29. return;
  30. }
  31. $remote_owner = null;
  32. if (!$item['wall']) {
  33. // The top level post may have been written by somebody on another system
  34. $contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'uid' => $item['uid']]);
  35. if (!DBA::isResult($contact)) {
  36. return;
  37. }
  38. if (!$contact['self']) {
  39. $remote_owner = $contact;
  40. }
  41. }
  42. $owner = null;
  43. // this represents the post owner on this system.
  44. $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
  45. WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
  46. intval($owner_uid)
  47. );
  48. if (DBA::isResult($r)) {
  49. $owner = $r[0];
  50. }
  51. if (!$owner) {
  52. Logger::log('like: no owner');
  53. return;
  54. }
  55. if (!$remote_owner) {
  56. $remote_owner = $owner;
  57. }
  58. $contact = null;
  59. // This represents the person posting
  60. if (local_user() && (local_user() == $owner_uid)) {
  61. $contact = $owner;
  62. } else {
  63. $contact = DBA::selectFirst('contact', [], ['id' => $_SESSION['visitor_id'], 'uid' => $owner_uid]);
  64. if (!DBA::isResult($contact)) {
  65. return;
  66. }
  67. }
  68. $uri = Item::newURI($owner_uid);
  69. $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
  70. $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
  71. $link = XML::escape('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n");
  72. $body = $item['body'];
  73. $obj = <<< EOT
  74. <object>
  75. <type>$objtype</type>
  76. <local>1</local>
  77. <id>{$item['uri']}</id>
  78. <link>$link</link>
  79. <title></title>
  80. <content>$body</content>
  81. </object>
  82. EOT;
  83. $bodyverb = L10n::t('%1$s is following %2$s\'s %3$s');
  84. if (!isset($bodyverb)) {
  85. return;
  86. }
  87. $arr = [];
  88. $arr['guid'] = System::createUUID();
  89. $arr['uri'] = $uri;
  90. $arr['uid'] = $owner_uid;
  91. $arr['contact-id'] = $contact['id'];
  92. $arr['wall'] = $item['wall'];
  93. $arr['origin'] = 1;
  94. $arr['gravity'] = GRAVITY_ACTIVITY;
  95. $arr['parent'] = $item['id'];
  96. $arr['parent-uri'] = $item['uri'];
  97. $arr['thr-parent'] = $item['uri'];
  98. $arr['owner-name'] = $remote_owner['name'];
  99. $arr['owner-link'] = $remote_owner['url'];
  100. $arr['owner-avatar'] = $remote_owner['thumb'];
  101. $arr['author-name'] = $contact['name'];
  102. $arr['author-link'] = $contact['url'];
  103. $arr['author-avatar'] = $contact['thumb'];
  104. $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
  105. $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
  106. $plink = '[url=' . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
  107. $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
  108. $arr['verb'] = $activity;
  109. $arr['object-type'] = $objtype;
  110. $arr['object'] = $obj;
  111. $arr['allow_cid'] = $item['allow_cid'];
  112. $arr['allow_gid'] = $item['allow_gid'];
  113. $arr['deny_cid'] = $item['deny_cid'];
  114. $arr['deny_gid'] = $item['deny_gid'];
  115. $arr['visible'] = 1;
  116. $arr['unseen'] = 1;
  117. $post_id = Item::insert($arr);
  118. if (!$item['visible']) {
  119. Item::update(['visible' => true], ['id' => $item['id']]);
  120. }
  121. $arr['id'] = $post_id;
  122. Addon::callHooks('post_local_end', $arr);
  123. killme();
  124. }