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