4 use Friendica\Core\System;
5 use Friendica\Core\Worker;
6 use Friendica\Database\DBM;
8 require_once('include/security.php');
9 require_once('include/bbcode.php');
10 require_once('include/items.php');
12 function mood_init(App $a) {
19 $verb = notags(trim($_GET['verb']));
24 $verbs = get_mood_verbs();
26 if(! in_array($verb,$verbs))
29 $activity = ACTIVITY_MOOD . '#' . urlencode($verb);
31 $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : 0);
34 logger('mood: verb ' . $verb, LOGGER_DEBUG);
38 $r = q("select uri, private, allow_cid, allow_gid, deny_cid, deny_gid
39 from item where id = %d and parent = %d and uid = %d limit 1",
44 if (DBM::is_result($r)) {
45 $parent_uri = $r[0]['uri'];
46 $private = $r[0]['private'];
47 $allow_cid = $r[0]['allow_cid'];
48 $allow_gid = $r[0]['allow_gid'];
49 $deny_cid = $r[0]['deny_cid'];
50 $deny_gid = $r[0]['deny_gid'];
57 $allow_cid = $a->user['allow_cid'];
58 $allow_gid = $a->user['allow_gid'];
59 $deny_cid = $a->user['deny_cid'];
60 $deny_gid = $a->user['deny_gid'];
63 $poster = $a->contact;
65 $uri = item_new_uri($a->get_hostname(),$uid);
67 $action = sprintf( t('%1$s is currently %2$s'), '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' , $verbs[$verb]);
70 $arr['guid'] = get_guid(32);
73 $arr['parent-uri'] = (($parent_uri) ? $parent_uri : $uri);
74 $arr['type'] = 'activity';
76 $arr['contact-id'] = $poster['id'];
77 $arr['owner-name'] = $poster['name'];
78 $arr['owner-link'] = $poster['url'];
79 $arr['owner-avatar'] = $poster['thumb'];
80 $arr['author-name'] = $poster['name'];
81 $arr['author-link'] = $poster['url'];
82 $arr['author-avatar'] = $poster['thumb'];
84 $arr['allow_cid'] = $allow_cid;
85 $arr['allow_gid'] = $allow_gid;
86 $arr['deny_cid'] = $deny_cid;
87 $arr['deny_gid'] = $deny_gid;
88 $arr['last-child'] = 1;
90 $arr['verb'] = $activity;
91 $arr['private'] = $private;
94 $arr['body'] = $action;
96 $item_id = item_store($arr);
98 q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
99 dbesc(System::baseUrl() . '/display/' . $poster['nickname'] . '/' . $item_id),
103 Worker::add(PRIORITY_HIGH, "notifier", "tag", $item_id);
107 call_hooks('post_local_end', $arr);
109 Worker::add(PRIORITY_HIGH, "notifier", "like", $post_id);
116 function mood_content(App $a) {
118 if (! local_user()) {
119 notice( t('Permission denied.') . EOL);
123 $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : '0');
127 $verbs = get_mood_verbs();
129 $shortlist = array();
130 foreach($verbs as $k => $v)
131 if($v !== 'NOTRANSLATION')
132 $shortlist[] = array($k,$v);
135 $tpl = get_markup_template('mood_content.tpl');
137 $o = replace_macros($tpl,array(
138 '$title' => t('Mood'),
139 '$desc' => t('Set your current mood and tell your friends'),
140 '$verbs' => $shortlist,
141 '$parent' => $parent,
142 '$submit' => t('Submit'),