4 use Friendica\Core\System;
5 use Friendica\Core\Worker;
7 require_once('include/security.php');
8 require_once('include/bbcode.php');
9 require_once('include/items.php');
11 function mood_init(App $a) {
18 $verb = notags(trim($_GET['verb']));
23 $verbs = get_mood_verbs();
25 if(! in_array($verb,$verbs))
28 $activity = ACTIVITY_MOOD . '#' . urlencode($verb);
30 $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : 0);
33 logger('mood: verb ' . $verb, LOGGER_DEBUG);
37 $r = q("select uri, private, allow_cid, allow_gid, deny_cid, deny_gid
38 from item where id = %d and parent = %d and uid = %d limit 1",
43 if (dbm::is_result($r)) {
44 $parent_uri = $r[0]['uri'];
45 $private = $r[0]['private'];
46 $allow_cid = $r[0]['allow_cid'];
47 $allow_gid = $r[0]['allow_gid'];
48 $deny_cid = $r[0]['deny_cid'];
49 $deny_gid = $r[0]['deny_gid'];
56 $allow_cid = $a->user['allow_cid'];
57 $allow_gid = $a->user['allow_gid'];
58 $deny_cid = $a->user['deny_cid'];
59 $deny_gid = $a->user['deny_gid'];
62 $poster = $a->contact;
64 $uri = item_new_uri($a->get_hostname(),$uid);
66 $action = sprintf( t('%1$s is currently %2$s'), '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' , $verbs[$verb]);
69 $arr['guid'] = get_guid(32);
72 $arr['parent-uri'] = (($parent_uri) ? $parent_uri : $uri);
73 $arr['type'] = 'activity';
75 $arr['contact-id'] = $poster['id'];
76 $arr['owner-name'] = $poster['name'];
77 $arr['owner-link'] = $poster['url'];
78 $arr['owner-avatar'] = $poster['thumb'];
79 $arr['author-name'] = $poster['name'];
80 $arr['author-link'] = $poster['url'];
81 $arr['author-avatar'] = $poster['thumb'];
83 $arr['allow_cid'] = $allow_cid;
84 $arr['allow_gid'] = $allow_gid;
85 $arr['deny_cid'] = $deny_cid;
86 $arr['deny_gid'] = $deny_gid;
87 $arr['last-child'] = 1;
89 $arr['verb'] = $activity;
90 $arr['private'] = $private;
93 $arr['body'] = $action;
95 $item_id = item_store($arr);
97 q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
98 dbesc(System::baseUrl() . '/display/' . $poster['nickname'] . '/' . $item_id),
102 Worker::add(PRIORITY_HIGH, "notifier", "tag", $item_id);
106 call_hooks('post_local_end', $arr);
108 Worker::add(PRIORITY_HIGH, "notifier", "like", $post_id);
115 function mood_content(App $a) {
117 if (! local_user()) {
118 notice( t('Permission denied.') . EOL);
122 $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : '0');
126 $verbs = get_mood_verbs();
128 $shortlist = array();
129 foreach($verbs as $k => $v)
130 if($v !== 'NOTRANSLATION')
131 $shortlist[] = array($k,$v);
134 $tpl = get_markup_template('mood_content.tpl');
136 $o = replace_macros($tpl,array(
137 '$title' => t('Mood'),
138 '$desc' => t('Set your current mood and tell your friends'),
139 '$verbs' => $shortlist,
140 '$parent' => $parent,
141 '$submit' => t('Submit'),