]> git.mxchange.org Git - friendica.git/blob - mod/poke.php
Merge pull request #4440 from rabuzarus/20180211_-_fix_variables_part_two
[friendica.git] / mod / poke.php
1 <?php
2 /**
3  * Poke, prod, finger, or otherwise do unspeakable things to somebody - who must be a connection in your address book
4  * This function can be invoked with the required arguments (verb and cid and private and possibly parent) silently via ajax or
5  * other web request. You must be logged in and connected to a profile.
6  * If the required arguments aren't present, we'll display a simple form to choose a recipient and a verb.
7  * parent is a special argument which let's you attach this activity as a comment to an existing conversation, which
8  * may have started with somebody else poking (etc.) somebody, but this isn't necessary. This can be used in the more pokes
9  * addon version to have entire conversations where Alice poked Bob, Bob fingered Alice, Alice hugged Bob, etc.
10  *
11  * private creates a private conversation with the recipient. Otherwise your profile's default post privacy is used.
12  *
13  * @file mod/poke.php
14  */
15
16 use Friendica\App;
17 use Friendica\Core\Addon;
18 use Friendica\Core\L10n;
19 use Friendica\Core\System;
20 use Friendica\Core\Worker;
21 use Friendica\Database\DBM;
22 use Friendica\Model\Item;
23
24 require_once 'include/security.php';
25 require_once 'include/bbcode.php';
26 require_once 'include/items.php';
27
28 function poke_init(App $a) {
29
30         if (! local_user()) {
31                 return;
32         }
33
34         $uid = local_user();
35         $verb = notags(trim($_GET['verb']));
36
37         if (! $verb) {
38                 return;
39         }
40
41         $verbs = get_poke_verbs();
42
43         if (! array_key_exists($verb,$verbs)) {
44                 return;
45         }
46
47         $activity = ACTIVITY_POKE . '#' . urlencode($verbs[$verb][0]);
48
49         $contact_id = intval($_GET['cid']);
50         if (! $contact_id) {
51                 return;
52         }
53
54         $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : 0);
55
56
57         logger('poke: verb ' . $verb . ' contact ' . $contact_id, LOGGER_DEBUG);
58
59
60         $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
61                 intval($contact_id),
62                 intval($uid)
63         );
64
65         if (! DBM::is_result($r)) {
66                 logger('poke: no contact ' . $contact_id);
67                 return;
68         }
69
70         $target = $r[0];
71
72         if($parent) {
73                 $r = q("SELECT `uri`, `private`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`
74                         FROM `item` WHERE `id` = %d AND `parent` = %d AND `uid` = %d LIMIT 1",
75                         intval($parent),
76                         intval($parent),
77                         intval($uid)
78                 );
79                 if (DBM::is_result($r)) {
80                         $parent_uri = $r[0]['uri'];
81                         $private    = $r[0]['private'];
82                         $allow_cid  = $r[0]['allow_cid'];
83                         $allow_gid  = $r[0]['allow_gid'];
84                         $deny_cid   = $r[0]['deny_cid'];
85                         $deny_gid   = $r[0]['deny_gid'];
86                 }
87         }
88         else {
89
90                 $private = ((x($_GET,'private')) ? intval($_GET['private']) : 0);
91
92                 $allow_cid     = (($private) ? '<' . $target['id']. '>' : $a->user['allow_cid']);
93                 $allow_gid     = (($private) ? '' : $a->user['allow_gid']);
94                 $deny_cid      = (($private) ? '' : $a->user['deny_cid']);
95                 $deny_gid      = (($private) ? '' : $a->user['deny_gid']);
96         }
97
98         $poster = $a->contact;
99
100         $uri = item_new_uri($a->get_hostname(),$uid);
101
102         $arr = [];
103
104         $arr['guid']          = get_guid(32);
105         $arr['uid']           = $uid;
106         $arr['uri']           = $uri;
107         $arr['parent-uri']    = (($parent_uri) ? $parent_uri : $uri);
108         $arr['type']          = 'activity';
109         $arr['wall']          = 1;
110         $arr['contact-id']    = $poster['id'];
111         $arr['owner-name']    = $poster['name'];
112         $arr['owner-link']    = $poster['url'];
113         $arr['owner-avatar']  = $poster['thumb'];
114         $arr['author-name']   = $poster['name'];
115         $arr['author-link']   = $poster['url'];
116         $arr['author-avatar'] = $poster['thumb'];
117         $arr['title']         = '';
118         $arr['allow_cid']     = $allow_cid;
119         $arr['allow_gid']     = $allow_gid;
120         $arr['deny_cid']      = $deny_cid;
121         $arr['deny_gid']      = $deny_gid;
122         $arr['visible']       = 1;
123         $arr['verb']          = $activity;
124         $arr['private']       = $private;
125         $arr['object-type']   = ACTIVITY_OBJ_PERSON;
126
127         $arr['origin']        = 1;
128         $arr['body']          = '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' . ' ' . L10n::t($verbs[$verb][0]) . ' ' . '[url=' . $target['url'] . ']' . $target['name'] . '[/url]';
129
130         $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $target['name'] . '</title><id>' . System::baseUrl() . '/contact/' . $target['id'] . '</id>';
131         $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $target['url'] . '" />' . "\n");
132
133         $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $target['photo'] . '" />' . "\n");
134         $arr['object'] .= '</link></object>' . "\n";
135
136         $item_id = Item::insert($arr);
137         if($item_id) {
138                 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
139         }
140
141         Addon::callHooks('post_local_end', $arr);
142
143         return;
144 }
145
146
147
148 function poke_content(App $a) {
149
150         if (! local_user()) {
151                 notice(L10n::t('Permission denied.') . EOL);
152                 return;
153         }
154
155         $name = '';
156         $id = '';
157
158         if(intval($_GET['c'])) {
159                 $r = q("SELECT `id`,`name` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
160                         intval($_GET['c']),
161                         intval(local_user())
162                 );
163                 if (DBM::is_result($r)) {
164                         $name = $r[0]['name'];
165                         $id = $r[0]['id'];
166                 }
167         }
168
169
170         $base = System::baseUrl();
171
172         $head_tpl = get_markup_template('poke_head.tpl');
173         $a->page['htmlhead'] .= replace_macros($head_tpl,[
174                 '$baseurl' => System::baseUrl(true),
175                 '$base' => $base
176         ]);
177
178
179         $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : '0');
180
181
182         $verbs = get_poke_verbs();
183
184         $shortlist = [];
185         foreach($verbs as $k => $v)
186                 if($v[1] !== 'NOTRANSLATION')
187                         $shortlist[] = [$k,$v[1]];
188
189
190         $tpl = get_markup_template('poke_content.tpl');
191
192         $o = replace_macros($tpl,[
193                 '$title' => L10n::t('Poke/Prod'),
194                 '$desc' => L10n::t('poke, prod or do other things to somebody'),
195                 '$clabel' => L10n::t('Recipient'),
196                 '$choice' => L10n::t('Choose what you wish to do to recipient'),
197                 '$verbs' => $shortlist,
198                 '$parent' => $parent,
199                 '$prv_desc' => L10n::t('Make this post private'),
200                 '$submit' => L10n::t('Submit'),
201                 '$name' => $name,
202                 '$id' => $id
203         ]);
204
205         return $o;
206
207 }