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