]> git.mxchange.org Git - friendica.git/blob - mod/mood.php
Merge pull request #3769 from annando/show-forum-posts
[friendica.git] / mod / mood.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\System;
5
6 require_once('include/security.php');
7 require_once('include/bbcode.php');
8 require_once('include/items.php');
9
10 function mood_init(App $a) {
11
12         if (! local_user()) {
13                 return;
14         }
15
16         $uid = local_user();
17         $verb = notags(trim($_GET['verb']));
18
19         if(! $verb)
20                 return;
21
22         $verbs = get_mood_verbs();
23
24         if(! in_array($verb,$verbs))
25                 return;
26
27         $activity = ACTIVITY_MOOD . '#' . urlencode($verb);
28
29         $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : 0);
30
31
32         logger('mood: verb ' . $verb, LOGGER_DEBUG);
33
34
35         if($parent) {
36                 $r = q("select uri, private, allow_cid, allow_gid, deny_cid, deny_gid
37                         from item where id = %d and parent = %d and uid = %d limit 1",
38                         intval($parent),
39                         intval($parent),
40                         intval($uid)
41                 );
42                 if (dbm::is_result($r)) {
43                         $parent_uri = $r[0]['uri'];
44                         $private    = $r[0]['private'];
45                         $allow_cid  = $r[0]['allow_cid'];
46                         $allow_gid  = $r[0]['allow_gid'];
47                         $deny_cid   = $r[0]['deny_cid'];
48                         $deny_gid   = $r[0]['deny_gid'];
49                 }
50         }
51         else {
52
53                 $private = 0;
54
55                 $allow_cid     =  $a->user['allow_cid'];
56                 $allow_gid     =  $a->user['allow_gid'];
57                 $deny_cid      =  $a->user['deny_cid'];
58                 $deny_gid      =  $a->user['deny_gid'];
59         }
60
61         $poster = $a->contact;
62
63         $uri = item_new_uri($a->get_hostname(),$uid);
64
65         $action = sprintf( t('%1$s is currently %2$s'), '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' , $verbs[$verb]);
66
67         $arr = array();
68         $arr['guid']          = get_guid(32);
69         $arr['uid']           = $uid;
70         $arr['uri']           = $uri;
71         $arr['parent-uri']    = (($parent_uri) ? $parent_uri : $uri);
72         $arr['type']          = 'activity';
73         $arr['wall']          = 1;
74         $arr['contact-id']    = $poster['id'];
75         $arr['owner-name']    = $poster['name'];
76         $arr['owner-link']    = $poster['url'];
77         $arr['owner-avatar']  = $poster['thumb'];
78         $arr['author-name']   = $poster['name'];
79         $arr['author-link']   = $poster['url'];
80         $arr['author-avatar'] = $poster['thumb'];
81         $arr['title']         = '';
82         $arr['allow_cid']     = $allow_cid;
83         $arr['allow_gid']     = $allow_gid;
84         $arr['deny_cid']      = $deny_cid;
85         $arr['deny_gid']      = $deny_gid;
86         $arr['last-child']    = 1;
87         $arr['visible']       = 1;
88         $arr['verb']          = $activity;
89         $arr['private']       = $private;
90
91         $arr['origin']        = 1;
92         $arr['body']          = $action;
93
94         $item_id = item_store($arr);
95         if($item_id) {
96                 q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
97                         dbesc(System::baseUrl() . '/display/' . $poster['nickname'] . '/' . $item_id),
98                         intval($uid),
99                         intval($item_id)
100                 );
101                 proc_run(PRIORITY_HIGH, "include/notifier.php", "tag", $item_id);
102         }
103
104
105         call_hooks('post_local_end', $arr);
106
107         proc_run(PRIORITY_HIGH, "include/notifier.php", "like", $post_id);
108
109         return;
110 }
111
112
113
114 function mood_content(App $a) {
115
116         if (! local_user()) {
117                 notice( t('Permission denied.') . EOL);
118                 return;
119         }
120
121         $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : '0');
122
123
124
125         $verbs = get_mood_verbs();
126
127         $shortlist = array();
128         foreach($verbs as $k => $v)
129                 if($v !== 'NOTRANSLATION')
130                         $shortlist[] = array($k,$v);
131
132
133         $tpl = get_markup_template('mood_content.tpl');
134
135         $o = replace_macros($tpl,array(
136                 '$title' => t('Mood'),
137                 '$desc' => t('Set your current mood and tell your friends'),
138                 '$verbs' => $shortlist,
139                 '$parent' => $parent,
140                 '$submit' => t('Submit'),
141         ));
142
143         return $o;
144
145 }