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.

210 lines
5.8KB

  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. * plugin 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. */
  14. * @file mod/poke.php
  15. require_once('include/security.php');
  16. require_once('include/bbcode.php');
  17. require_once('include/items.php');
  18. function poke_init(App $a) {
  19. if (! local_user()) {
  20. return;
  21. }
  22. $uid = local_user();
  23. $verb = notags(trim($_GET['verb']));
  24. if (! $verb) {
  25. return;
  26. }
  27. $verbs = get_poke_verbs();
  28. if (! array_key_exists($verb,$verbs)) {
  29. return;
  30. }
  31. $activity = ACTIVITY_POKE . '#' . urlencode($verbs[$verb][0]);
  32. $contact_id = intval($_GET['cid']);
  33. if (! $contact_id) {
  34. return;
  35. }
  36. $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : 0);
  37. logger('poke: verb ' . $verb . ' contact ' . $contact_id, LOGGER_DEBUG);
  38. $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  39. intval($contact_id),
  40. intval($uid)
  41. );
  42. if (! dbm::is_result($r)) {
  43. logger('poke: no contact ' . $contact_id);
  44. return;
  45. }
  46. $target = $r[0];
  47. if($parent) {
  48. $r = q("SELECT `uri`, `private`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`
  49. FROM `item` WHERE `id` = %d AND `parent` = %d AND `uid` = %d LIMIT 1",
  50. intval($parent),
  51. intval($parent),
  52. intval($uid)
  53. );
  54. if (dbm::is_result($r)) {
  55. $parent_uri = $r[0]['uri'];
  56. $private = $r[0]['private'];
  57. $allow_cid = $r[0]['allow_cid'];
  58. $allow_gid = $r[0]['allow_gid'];
  59. $deny_cid = $r[0]['deny_cid'];
  60. $deny_gid = $r[0]['deny_gid'];
  61. }
  62. }
  63. else {
  64. $private = ((x($_GET,'private')) ? intval($_GET['private']) : 0);
  65. $allow_cid = (($private) ? '<' . $target['id']. '>' : $a->user['allow_cid']);
  66. $allow_gid = (($private) ? '' : $a->user['allow_gid']);
  67. $deny_cid = (($private) ? '' : $a->user['deny_cid']);
  68. $deny_gid = (($private) ? '' : $a->user['deny_gid']);
  69. }
  70. $poster = $a->contact;
  71. $uri = item_new_uri($a->get_hostname(),$uid);
  72. $arr = array();
  73. $arr['guid'] = get_guid(32);
  74. $arr['uid'] = $uid;
  75. $arr['uri'] = $uri;
  76. $arr['parent-uri'] = (($parent_uri) ? $parent_uri : $uri);
  77. $arr['type'] = 'activity';
  78. $arr['wall'] = 1;
  79. $arr['contact-id'] = $poster['id'];
  80. $arr['owner-name'] = $poster['name'];
  81. $arr['owner-link'] = $poster['url'];
  82. $arr['owner-avatar'] = $poster['thumb'];
  83. $arr['author-name'] = $poster['name'];
  84. $arr['author-link'] = $poster['url'];
  85. $arr['author-avatar'] = $poster['thumb'];
  86. $arr['title'] = '';
  87. $arr['allow_cid'] = $allow_cid;
  88. $arr['allow_gid'] = $allow_gid;
  89. $arr['deny_cid'] = $deny_cid;
  90. $arr['deny_gid'] = $deny_gid;
  91. $arr['last-child'] = 1;
  92. $arr['visible'] = 1;
  93. $arr['verb'] = $activity;
  94. $arr['private'] = $private;
  95. $arr['object-type'] = ACTIVITY_OBJ_PERSON;
  96. $arr['origin'] = 1;
  97. $arr['body'] = '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' . ' ' . t($verbs[$verb][0]) . ' ' . '[url=' . $target['url'] . ']' . $target['name'] . '[/url]';
  98. $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $target['name'] . '</title><id>' . App::get_baseurl() . '/contact/' . $target['id'] . '</id>';
  99. $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $target['url'] . '" />' . "\n");
  100. $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $target['photo'] . '" />' . "\n");
  101. $arr['object'] .= '</link></object>' . "\n";
  102. $item_id = item_store($arr);
  103. if($item_id) {
  104. //q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
  105. // dbesc(App::get_baseurl() . '/display/' . $poster['nickname'] . '/' . $item_id),
  106. // intval($uid),
  107. // intval($item_id)
  108. //);
  109. proc_run(PRIORITY_HIGH, "include/notifier.php", "tag", $item_id);
  110. }
  111. call_hooks('post_local_end', $arr);
  112. proc_run(PRIORITY_HIGH, "include/notifier.php", "like", $post_id);
  113. return;
  114. }
  115. function poke_content(App $a) {
  116. if (! local_user()) {
  117. notice( t('Permission denied.') . EOL);
  118. return;
  119. }
  120. $name = '';
  121. $id = '';
  122. if(intval($_GET['c'])) {
  123. $r = q("SELECT `id`,`name` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  124. intval($_GET['c']),
  125. intval(local_user())
  126. );
  127. if (dbm::is_result($r)) {
  128. $name = $r[0]['name'];
  129. $id = $r[0]['id'];
  130. }
  131. }
  132. $base = App::get_baseurl();
  133. $head_tpl = get_markup_template('poke_head.tpl');
  134. $a->page['htmlhead'] .= replace_macros($head_tpl,array(
  135. '$baseurl' => App::get_baseurl(true),
  136. '$base' => $base
  137. ));
  138. $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : '0');
  139. $verbs = get_poke_verbs();
  140. $shortlist = array();
  141. foreach($verbs as $k => $v)
  142. if($v[1] !== 'NOTRANSLATION')
  143. $shortlist[] = array($k,$v[1]);
  144. $tpl = get_markup_template('poke_content.tpl');
  145. $o = replace_macros($tpl,array(
  146. '$title' => t('Poke/Prod'),
  147. '$desc' => t('poke, prod or do other things to somebody'),
  148. '$clabel' => t('Recipient'),
  149. '$choice' => t('Choose what you wish to do to recipient'),
  150. '$verbs' => $shortlist,
  151. '$parent' => $parent,
  152. '$prv_desc' => t('Make this post private'),
  153. '$submit' => t('Submit'),
  154. '$name' => $name,
  155. '$id' => $id
  156. ));
  157. return $o;
  158. }