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.

148 lines
3.6 KiB

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 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. logger('poke: verb ' . $verb . ' contact ' . $contact_id, LOGGER_DEBUG);
  20. $r = q("SELECT * FROM `contact` WHERE `id` = %d and `uid` = %d LIMIT 1",
  21. intval($contact_id),
  22. intval($uid)
  23. );
  24. if(! count($r)) {
  25. logger('poke: no contact ' . $contact_id);
  26. return;
  27. }
  28. $target = $r[0];
  29. $poster = $a->contact;
  30. $uri = item_new_uri($a->get_hostname(),$owner_uid);
  31. $arr = array();
  32. $arr['uid'] = $uid;
  33. $arr['uri'] = $uri;
  34. $arr['parent-uri'] = $uri;
  35. $arr['type'] = 'activity';
  36. $arr['wall'] = 1;
  37. $arr['contact-id'] = $target['id'];
  38. $arr['owner-name'] = $poster['name'];
  39. $arr['owner-link'] = $poster['url'];
  40. $arr['owner-avatar'] = $poster['thumb'];
  41. $arr['author-name'] = $poster['name'];
  42. $arr['author-link'] = $poster['url'];
  43. $arr['author-avatar'] = $poster['thumb'];
  44. $arr['title'] = '';
  45. $arr['allow_cid'] = $a->user['allow_cid'];
  46. $arr['allow_gid'] = $a->user['allow_gid'];
  47. $arr['deny_cid'] = $a->user['deny_cid'];
  48. $arr['deny_gid'] = $a->user['deny_gid'];
  49. $arr['last-child'] = 1;
  50. $arr['visible'] = 1;
  51. $arr['verb'] = $activity;
  52. $arr['object-type'] = ACTIVITY_OBJ_PERSON;
  53. $arr['origin'] = 1;
  54. $arr['body'] = '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' . ' ' . t($verbs[$verb][0]) . ' ' . '[url=' . $target['url'] . ']' . $target['name'] . '[/url]';
  55. $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $target['name'] . '</title><id>' . $a->get_baseurl() . '/contact/' . $target['id'] . '</id>';
  56. $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $target['url'] . '" />' . "\n");
  57. $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $target['photo'] . '" />' . "\n");
  58. $arr['object'] .= '</link></object>' . "\n";
  59. $item_id = item_store($arr);
  60. if($item_id) {
  61. q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
  62. dbesc($a->get_baseurl() . '/display/' . $poster['nickname'] . '/' . $item_id),
  63. intval($uid),
  64. intval($item_id)
  65. );
  66. proc_run('php',"include/notifier.php","tag","$item_id");
  67. }
  68. call_hooks('post_local_end', $arr);
  69. proc_run('php',"include/notifier.php","like","$post_id");
  70. return;
  71. }
  72. function poke_content(&$a) {
  73. $base = $a->get_baseurl();
  74. $a->page['htmlhead'] .= '<script src="' . $a->get_baseurl(true) . '/library/jquery_ac/friendica.complete.js" ></script>';
  75. $a->page['htmlhead'] .= <<< EOT
  76. <script>$(document).ready(function() {
  77. var a;
  78. a = $("#recip").autocomplete({
  79. serviceUrl: '$base/acl',
  80. minChars: 2,
  81. width: 350,
  82. onSelect: function(value,data) {
  83. $("#recip-complete").val(data);
  84. }
  85. });
  86. a.setOptions({ params: { type: 'a' }});
  87. });
  88. </script>
  89. EOT;
  90. $verbs = get_poke_verbs();
  91. $shortlist = array();
  92. foreach($verbs as $k => $v)
  93. $shortlist[] = array($k,$v[1]);
  94. $tpl = get_markup_template('poke_content.tpl');
  95. $o = replace_macros($tpl,array(
  96. '$title' => t('Poke/Prod'),
  97. '$desc' => t('poke, prod or do other things to somebody'),
  98. '$clabel' => t('Recipient'),
  99. '$choice' => t('Choose what you wish to do to recipient'),
  100. '$verbs' => $shortlist,
  101. '$submit' => t('Submit')
  102. ));
  103. return $o;
  104. }