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