Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

163 lignes
3.9KB

  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. $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
  68. $link = xmlify('<link rel="alternate" type="text/html" href="' . App::get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
  69. $body = $item['body'];
  70. $obj = <<< EOT
  71. <object>
  72. <type>$objtype</type>
  73. <local>1</local>
  74. <id>{$item['uri']}</id>
  75. <link>$link</link>
  76. <title></title>
  77. <content>$body</content>
  78. </object>
  79. EOT;
  80. $bodyverb = t('%1$s is following %2$s\'s %3$s');
  81. if (! isset($bodyverb)) {
  82. return;
  83. }
  84. $arr = array();
  85. $arr['guid'] = get_guid(32);
  86. $arr['uri'] = $uri;
  87. $arr['uid'] = $owner_uid;
  88. $arr['contact-id'] = $contact['id'];
  89. $arr['type'] = 'activity';
  90. $arr['wall'] = $item['wall'];
  91. $arr['origin'] = 1;
  92. $arr['gravity'] = GRAVITY_LIKE;
  93. $arr['parent'] = $item['id'];
  94. $arr['parent-uri'] = $item['uri'];
  95. $arr['thr-parent'] = $item['uri'];
  96. $arr['owner-name'] = $remote_owner['name'];
  97. $arr['owner-link'] = $remote_owner['url'];
  98. $arr['owner-avatar'] = $remote_owner['thumb'];
  99. $arr['author-name'] = $contact['name'];
  100. $arr['author-link'] = $contact['url'];
  101. $arr['author-avatar'] = $contact['thumb'];
  102. $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
  103. $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
  104. $plink = '[url=' . App::get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
  105. $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
  106. $arr['verb'] = $activity;
  107. $arr['object-type'] = $objtype;
  108. $arr['object'] = $obj;
  109. $arr['allow_cid'] = $item['allow_cid'];
  110. $arr['allow_gid'] = $item['allow_gid'];
  111. $arr['deny_cid'] = $item['deny_cid'];
  112. $arr['deny_gid'] = $item['deny_gid'];
  113. $arr['visible'] = 1;
  114. $arr['unseen'] = 1;
  115. $arr['last-child'] = 0;
  116. $post_id = item_store($arr);
  117. if (! $item['visible']) {
  118. $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d",
  119. intval($item['id']),
  120. intval($owner_uid)
  121. );
  122. }
  123. $arr['id'] = $post_id;
  124. call_hooks('post_local_end', $arr);
  125. killme();
  126. }