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