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.
 
 
 
 
 
 

206 lines
5.0 KiB

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