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.

167 lines
4.0 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. <?php
  2. require_once('include/security.php');
  3. require_once('include/bbcode.php');
  4. require_once('include/items.php');
  5. function subthread_content(App &$a) {
  6. if(! local_user() && ! remote_user()) {
  7. return;
  8. }
  9. $activity = ACTIVITY_FOLLOW;
  10. $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
  11. $r = q("SELECT * FROM `item` WHERE `parent` = '%s' OR `parent-uri` = '%s' and parent = id LIMIT 1",
  12. dbesc($item_id),
  13. dbesc($item_id)
  14. );
  15. if(! $item_id || (! dbm::is_result($r))) {
  16. logger('subthread: no item ' . $item_id);
  17. return;
  18. }
  19. $item = $r[0];
  20. $owner_uid = $item['uid'];
  21. if(! can_write_wall($a,$owner_uid)) {
  22. return;
  23. }
  24. $remote_owner = null;
  25. if(! $item['wall']) {
  26. // The top level post may have been written by somebody on another system
  27. $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  28. intval($item['contact-id']),
  29. intval($item['uid'])
  30. );
  31. if (! dbm::is_result($r)) {
  32. return;
  33. }
  34. if (! $r[0]['self']) {
  35. $remote_owner = $r[0];
  36. }
  37. }
  38. // this represents the post owner on this system.
  39. $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
  40. WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
  41. intval($owner_uid)
  42. );
  43. if (dbm::is_result($r))
  44. $owner = $r[0];
  45. if (! $owner) {
  46. logger('like: no owner');
  47. return;
  48. }
  49. if (! $remote_owner)
  50. $remote_owner = $owner;
  51. // This represents the person posting
  52. if ((local_user()) && (local_user() == $owner_uid)) {
  53. $contact = $owner;
  54. } else {
  55. $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  56. intval($_SESSION['visitor_id']),
  57. intval($owner_uid)
  58. );
  59. if (dbm::is_result($r))
  60. $contact = $r[0];
  61. }
  62. if (! $contact) {
  63. return;
  64. }
  65. $uri = item_new_uri($a->get_hostname(),$owner_uid);
  66. $post_type = (($item['resource-id']) ? t('photo') : t('status'));
  67. <<<<<<< upstream/develop
  68. $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
  69. =======
  70. $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );
  71. >>>>>>> HEAD~33
  72. $link = xmlify('<link rel="alternate" type="text/html" href="' . App::get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
  73. $body = $item['body'];
  74. $obj = <<< EOT
  75. <object>
  76. <type>$objtype</type>
  77. <local>1</local>
  78. <id>{$item['uri']}</id>
  79. <link>$link</link>
  80. <title></title>
  81. <content>$body</content>
  82. </object>
  83. EOT;
  84. $bodyverb = t('%1$s is following %2$s\'s %3$s');
  85. if (! isset($bodyverb)) {
  86. return;
  87. }
  88. $arr = array();
  89. $arr['guid'] = get_guid(32);
  90. $arr['uri'] = $uri;
  91. $arr['uid'] = $owner_uid;
  92. $arr['contact-id'] = $contact['id'];
  93. $arr['type'] = 'activity';
  94. $arr['wall'] = $item['wall'];
  95. $arr['origin'] = 1;
  96. $arr['gravity'] = GRAVITY_LIKE;
  97. $arr['parent'] = $item['id'];
  98. $arr['parent-uri'] = $item['uri'];
  99. $arr['thr-parent'] = $item['uri'];
  100. $arr['owner-name'] = $remote_owner['name'];
  101. $arr['owner-link'] = $remote_owner['url'];
  102. $arr['owner-avatar'] = $remote_owner['thumb'];
  103. $arr['author-name'] = $contact['name'];
  104. $arr['author-link'] = $contact['url'];
  105. $arr['author-avatar'] = $contact['thumb'];
  106. $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
  107. $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
  108. $plink = '[url=' . App::get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
  109. $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
  110. $arr['verb'] = $activity;
  111. $arr['object-type'] = $objtype;
  112. $arr['object'] = $obj;
  113. $arr['allow_cid'] = $item['allow_cid'];
  114. $arr['allow_gid'] = $item['allow_gid'];
  115. $arr['deny_cid'] = $item['deny_cid'];
  116. $arr['deny_gid'] = $item['deny_gid'];
  117. $arr['visible'] = 1;
  118. $arr['unseen'] = 1;
  119. $arr['last-child'] = 0;
  120. $post_id = item_store($arr);
  121. if (! $item['visible']) {
  122. $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d",
  123. intval($item['id']),
  124. intval($owner_uid)
  125. );
  126. }
  127. $arr['id'] = $post_id;
  128. call_hooks('post_local_end', $arr);
  129. killme();
  130. }