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.

199 lines
5.6KB

  1. <?php
  2. /**
  3. * Poke, prod, finger, or otherwise do unspeakable things to somebody - who must be a connection in your address book
  4. * This function can be invoked with the required arguments (verb and cid and private and possibly parent) silently via ajax or
  5. * other web request. You must be logged in and connected to a profile.
  6. * If the required arguments aren't present, we'll display a simple form to choose a recipient and a verb.
  7. * parent is a special argument which let's you attach this activity as a comment to an existing conversation, which
  8. * may have started with somebody else poking (etc.) somebody, but this isn't necessary. This can be used in the more pokes
  9. * addon version to have entire conversations where Alice poked Bob, Bob fingered Alice, Alice hugged Bob, etc.
  10. *
  11. * private creates a private conversation with the recipient. Otherwise your profile's default post privacy is used.
  12. *
  13. * @file mod/poke.php
  14. */
  15. use Friendica\App;
  16. use Friendica\Core\Addon;
  17. use Friendica\Core\L10n;
  18. use Friendica\Core\Logger;
  19. use Friendica\Core\Renderer;
  20. use Friendica\Core\System;
  21. use Friendica\Core\Worker;
  22. use Friendica\Database\DBA;
  23. use Friendica\Model\Item;
  24. use Friendica\Util\Strings;
  25. use Friendica\Util\XML;
  26. function poke_init(App $a)
  27. {
  28. if (!local_user()) {
  29. return;
  30. }
  31. $uid = local_user();
  32. if (empty($_GET['verb'])) {
  33. return;
  34. }
  35. $verb = Strings::escapeTags(trim($_GET['verb']));
  36. $verbs = L10n::getPokeVerbs();
  37. if (!array_key_exists($verb, $verbs)) {
  38. return;
  39. }
  40. $activity = ACTIVITY_POKE . '#' . urlencode($verbs[$verb][0]);
  41. $contact_id = intval($_GET['cid']);
  42. if (!$contact_id) {
  43. return;
  44. }
  45. $parent = (!empty($_GET['parent']) ? intval($_GET['parent']) : 0);
  46. Logger::log('poke: verb ' . $verb . ' contact ' . $contact_id, Logger::DEBUG);
  47. $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  48. intval($contact_id),
  49. intval($uid)
  50. );
  51. if (!DBA::isResult($r)) {
  52. Logger::log('poke: no contact ' . $contact_id);
  53. return;
  54. }
  55. $target = $r[0];
  56. if ($parent) {
  57. $fields = ['uri', 'private', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
  58. $condition = ['id' => $parent, 'parent' => $parent, 'uid' => $uid];
  59. $item = Item::selectFirst($fields, $condition);
  60. if (DBA::isResult($item)) {
  61. $parent_uri = $item['uri'];
  62. $private = $item['private'];
  63. $allow_cid = $item['allow_cid'];
  64. $allow_gid = $item['allow_gid'];
  65. $deny_cid = $item['deny_cid'];
  66. $deny_gid = $item['deny_gid'];
  67. }
  68. } else {
  69. $private = (!empty($_GET['private']) ? intval($_GET['private']) : 0);
  70. $allow_cid = ($private ? '<' . $target['id']. '>' : $a->user['allow_cid']);
  71. $allow_gid = ($private ? '' : $a->user['allow_gid']);
  72. $deny_cid = ($private ? '' : $a->user['deny_cid']);
  73. $deny_gid = ($private ? '' : $a->user['deny_gid']);
  74. }
  75. $poster = $a->contact;
  76. $uri = Item::newURI($uid);
  77. $arr = [];
  78. $arr['guid'] = System::createUUID();
  79. $arr['uid'] = $uid;
  80. $arr['uri'] = $uri;
  81. $arr['parent-uri'] = (!empty($parent_uri) ? $parent_uri : $uri);
  82. $arr['wall'] = 1;
  83. $arr['contact-id'] = $poster['id'];
  84. $arr['owner-name'] = $poster['name'];
  85. $arr['owner-link'] = $poster['url'];
  86. $arr['owner-avatar'] = $poster['thumb'];
  87. $arr['author-name'] = $poster['name'];
  88. $arr['author-link'] = $poster['url'];
  89. $arr['author-avatar'] = $poster['thumb'];
  90. $arr['title'] = '';
  91. $arr['allow_cid'] = $allow_cid;
  92. $arr['allow_gid'] = $allow_gid;
  93. $arr['deny_cid'] = $deny_cid;
  94. $arr['deny_gid'] = $deny_gid;
  95. $arr['visible'] = 1;
  96. $arr['verb'] = $activity;
  97. $arr['private'] = $private;
  98. $arr['object-type'] = ACTIVITY_OBJ_PERSON;
  99. $arr['origin'] = 1;
  100. $arr['body'] = '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' . ' ' . L10n::t($verbs[$verb][0]) . ' ' . '[url=' . $target['url'] . ']' . $target['name'] . '[/url]';
  101. $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $target['name'] . '</title><id>' . $target['url'] . '</id>';
  102. $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $target['url'] . '" />' . "\n");
  103. $arr['object'] .= XML::escape('<link rel="photo" type="image/jpeg" href="' . $target['photo'] . '" />' . "\n");
  104. $arr['object'] .= '</link></object>' . "\n";
  105. $item_id = Item::insert($arr);
  106. Addon::callHooks('post_local_end', $arr);
  107. return;
  108. }
  109. function poke_content(App $a)
  110. {
  111. if (!local_user()) {
  112. notice(L10n::t('Permission denied.') . EOL);
  113. return;
  114. }
  115. $name = '';
  116. $id = '';
  117. if (empty($_GET['c'])) {
  118. return;
  119. }
  120. $contact = DBA::selectFirst('contact', ['id', 'name'], ['id' => $_GET['c'], 'uid' => local_user()]);
  121. if (!DBA::isResult($contact)) {
  122. return;
  123. }
  124. $name = $contact['name'];
  125. $id = $contact['id'];
  126. $base = System::baseUrl();
  127. $head_tpl = Renderer::getMarkupTemplate('poke_head.tpl');
  128. $a->page['htmlhead'] .= Renderer::replaceMacros($head_tpl,[
  129. '$baseurl' => System::baseUrl(true),
  130. '$base' => $base
  131. ]);
  132. $parent = (!empty($_GET['parent']) ? intval($_GET['parent']) : '0');
  133. $verbs = L10n::getPokeVerbs();
  134. $shortlist = [];
  135. foreach ($verbs as $k => $v) {
  136. if ($v[1] !== 'NOTRANSLATION') {
  137. $shortlist[] = [$k, $v[1]];
  138. }
  139. }
  140. $tpl = Renderer::getMarkupTemplate('poke_content.tpl');
  141. $o = Renderer::replaceMacros($tpl,[
  142. '$title' => L10n::t('Poke/Prod'),
  143. '$desc' => L10n::t('poke, prod or do other things to somebody'),
  144. '$clabel' => L10n::t('Recipient'),
  145. '$choice' => L10n::t('Choose what you wish to do to recipient'),
  146. '$verbs' => $shortlist,
  147. '$parent' => $parent,
  148. '$prv_desc' => L10n::t('Make this post private'),
  149. '$submit' => L10n::t('Submit'),
  150. '$name' => $name,
  151. '$id' => $id
  152. ]);
  153. return $o;
  154. }