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