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.
 
 
 
 
 
 

142 lines
3.2 KiB

  1. <?php
  2. require_once('include/security.php');
  3. require_once('include/bbcode.php');
  4. require_once('include/items.php');
  5. function mood_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_mood_verbs();
  13. if(! in_array($verb,$verbs))
  14. return;
  15. $activity = ACTIVITY_MOOD . '#' . urlencode($verb);
  16. $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : 0);
  17. logger('mood: verb ' . $verb, LOGGER_DEBUG);
  18. if($parent) {
  19. $r = q("select uri, private, allow_cid, allow_gid, deny_cid, deny_gid
  20. from item where id = %d and parent = %d and uid = %d limit 1",
  21. intval($parent),
  22. intval($parent),
  23. intval($uid)
  24. );
  25. if(count($r)) {
  26. $parent_uri = $r[0]['uri'];
  27. $private = $r[0]['private'];
  28. $allow_cid = $r[0]['allow_cid'];
  29. $allow_gid = $r[0]['allow_gid'];
  30. $deny_cid = $r[0]['deny_cid'];
  31. $deny_gid = $r[0]['deny_gid'];
  32. }
  33. }
  34. else {
  35. $private = 0;
  36. $allow_cid = $a->user['allow_cid'];
  37. $allow_gid = $a->user['allow_gid'];
  38. $deny_cid = $a->user['deny_cid'];
  39. $deny_gid = $a->user['deny_gid'];
  40. }
  41. $poster = $a->contact;
  42. $uri = item_new_uri($a->get_hostname(),$uid);
  43. $action = sprintf( t('%1$s is currently %2$s'), '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' , $verbs[$verb]);
  44. $arr = array();
  45. $arr['uid'] = $uid;
  46. $arr['uri'] = $uri;
  47. $arr['parent-uri'] = (($parent_uri) ? $parent_uri : $uri);
  48. $arr['type'] = 'activity';
  49. $arr['wall'] = 1;
  50. $arr['contact-id'] = $poster['id'];
  51. $arr['owner-name'] = $poster['name'];
  52. $arr['owner-link'] = $poster['url'];
  53. $arr['owner-avatar'] = $poster['thumb'];
  54. $arr['author-name'] = $poster['name'];
  55. $arr['author-link'] = $poster['url'];
  56. $arr['author-avatar'] = $poster['thumb'];
  57. $arr['title'] = '';
  58. $arr['allow_cid'] = $allow_cid;
  59. $arr['allow_gid'] = $allow_gid;
  60. $arr['deny_cid'] = $deny_cid;
  61. $arr['deny_gid'] = $deny_gid;
  62. $arr['last-child'] = 1;
  63. $arr['visible'] = 1;
  64. $arr['verb'] = $activity;
  65. $arr['private'] = $private;
  66. $arr['origin'] = 1;
  67. $arr['body'] = $action;
  68. $item_id = item_store($arr);
  69. if($item_id) {
  70. q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
  71. dbesc($a->get_baseurl() . '/display/' . $poster['nickname'] . '/' . $item_id),
  72. intval($uid),
  73. intval($item_id)
  74. );
  75. proc_run('php',"include/notifier.php","tag","$item_id");
  76. }
  77. call_hooks('post_local_end', $arr);
  78. proc_run('php',"include/notifier.php","like","$post_id");
  79. return;
  80. }
  81. function mood_content(&$a) {
  82. if(! local_user()) {
  83. notice( t('Permission denied.') . EOL);
  84. return;
  85. }
  86. $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : '0');
  87. $verbs = get_mood_verbs();
  88. $shortlist = array();
  89. foreach($verbs as $k => $v)
  90. if($v !== 'NOTRANSLATION')
  91. $shortlist[] = array($k,$v);
  92. $tpl = get_markup_template('mood_content.tpl');
  93. $o = replace_macros($tpl,array(
  94. '$title' => t('Mood'),
  95. '$desc' => t('Set your current mood and tell your friends'),
  96. '$verbs' => $shortlist,
  97. '$parent' => $parent,
  98. '$submit' => t('Submit'),
  99. ));
  100. return $o;
  101. }