]> git.mxchange.org Git - friendica.git/blob - mod/poke.php
Merge pull request #7988 from friendica/MrPetovan-notice
[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\Hook;
18 use Friendica\Core\L10n;
19 use Friendica\Core\Logger;
20 use Friendica\Core\Renderer;
21 use Friendica\Core\System;
22 use Friendica\Database\DBA;
23 use Friendica\Model\Item;
24 use Friendica\Protocol\Activity;
25 use Friendica\Util\Strings;
26 use Friendica\Util\XML;
27
28 function poke_init(App $a)
29 {
30         if (!local_user()) {
31                 return;
32         }
33
34         $uid = local_user();
35
36         if (empty($_GET['verb'])) {
37                 return;
38         }
39
40         $verb = Strings::escapeTags(trim($_GET['verb']));
41
42         $verbs = L10n::getPokeVerbs();
43
44         if (!array_key_exists($verb, $verbs)) {
45                 return;
46         }
47
48         $activity = Activity::POKE . '#' . urlencode($verbs[$verb][0]);
49
50         $contact_id = intval($_GET['cid']);
51         if (!$contact_id) {
52                 return;
53         }
54
55         $parent = (!empty($_GET['parent']) ? intval($_GET['parent']) : 0);
56
57
58         Logger::log('poke: verb ' . $verb . ' contact ' . $contact_id, Logger::DEBUG);
59
60
61         $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
62                 intval($contact_id),
63                 intval($uid)
64         );
65
66         if (!DBA::isResult($r)) {
67                 Logger::log('poke: no contact ' . $contact_id);
68                 return;
69         }
70
71         $target = $r[0];
72
73         if ($parent) {
74                 $fields = ['uri', 'private', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
75                 $condition = ['id' => $parent, 'parent' => $parent, 'uid' => $uid];
76                 $item = Item::selectFirst($fields, $condition);
77
78                 if (DBA::isResult($item)) {
79                         $parent_uri = $item['uri'];
80                         $private    = $item['private'];
81                         $allow_cid  = $item['allow_cid'];
82                         $allow_gid  = $item['allow_gid'];
83                         $deny_cid   = $item['deny_cid'];
84                         $deny_gid   = $item['deny_gid'];
85                 }
86         } else {
87                 $private = (!empty($_GET['private']) ? intval($_GET['private']) : 0);
88
89                 $allow_cid     = ($private ? '<' . $target['id']. '>' : $a->user['allow_cid']);
90                 $allow_gid     = ($private ? '' : $a->user['allow_gid']);
91                 $deny_cid      = ($private ? '' : $a->user['deny_cid']);
92                 $deny_gid      = ($private ? '' : $a->user['deny_gid']);
93         }
94
95         $poster = $a->contact;
96
97         $uri = Item::newURI($uid);
98
99         $arr = [];
100
101         $arr['guid']          = System::createUUID();
102         $arr['uid']           = $uid;
103         $arr['uri']           = $uri;
104         $arr['parent-uri']    = (!empty($parent_uri) ? $parent_uri : $uri);
105         $arr['wall']          = 1;
106         $arr['contact-id']    = $poster['id'];
107         $arr['owner-name']    = $poster['name'];
108         $arr['owner-link']    = $poster['url'];
109         $arr['owner-avatar']  = $poster['thumb'];
110         $arr['author-name']   = $poster['name'];
111         $arr['author-link']   = $poster['url'];
112         $arr['author-avatar'] = $poster['thumb'];
113         $arr['title']         = '';
114         $arr['allow_cid']     = $allow_cid;
115         $arr['allow_gid']     = $allow_gid;
116         $arr['deny_cid']      = $deny_cid;
117         $arr['deny_gid']      = $deny_gid;
118         $arr['visible']       = 1;
119         $arr['verb']          = $activity;
120         $arr['private']       = $private;
121         $arr['object-type']   = Activity\ObjectType::PERSON;
122
123         $arr['origin']        = 1;
124         $arr['body']          = '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' . ' ' . L10n::t($verbs[$verb][0]) . ' ' . '[url=' . $target['url'] . ']' . $target['name'] . '[/url]';
125
126         $arr['object'] = '<object><type>' . Activity\ObjectType::PERSON . '</type><title>' . $target['name'] . '</title><id>' . $target['url'] . '</id>';
127         $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $target['url'] . '" />' . "\n");
128
129         $arr['object'] .= XML::escape('<link rel="photo" type="image/jpeg" href="' . $target['photo'] . '" />' . "\n");
130         $arr['object'] .= '</link></object>' . "\n";
131
132         Item::insert($arr);
133
134         Hook::callAll('post_local_end', $arr);
135
136         return;
137 }
138
139 function poke_content(App $a)
140 {
141         if (!local_user()) {
142                 notice(L10n::t('Permission denied.') . EOL);
143                 return;
144         }
145
146         if (empty($_GET['c'])) {
147                 return;
148         }
149
150         $contact = DBA::selectFirst('contact', ['id', 'name'], ['id' => $_GET['c'], 'uid' => local_user()]);
151         if (!DBA::isResult($contact)) {
152                 return;
153         }
154
155         $name = $contact['name'];
156         $id = $contact['id'];
157
158         $head_tpl = Renderer::getMarkupTemplate('poke_head.tpl');
159         $a->page['htmlhead'] .= Renderer::replaceMacros($head_tpl,[
160                 '$baseurl' => System::baseUrl(true),
161         ]);
162
163         $parent = (!empty($_GET['parent']) ? intval($_GET['parent']) : '0');
164
165
166         $verbs = L10n::getPokeVerbs();
167
168         $shortlist = [];
169         foreach ($verbs as $k => $v) {
170                 if ($v[1] !== 'NOTRANSLATION') {
171                         $shortlist[] = [$k, $v[1]];
172                 }
173         }
174
175         $tpl = Renderer::getMarkupTemplate('poke_content.tpl');
176
177         $o = Renderer::replaceMacros($tpl,[
178                 '$title' => L10n::t('Poke/Prod'),
179                 '$desc' => L10n::t('poke, prod or do other things to somebody'),
180                 '$clabel' => L10n::t('Recipient'),
181                 '$choice' => L10n::t('Choose what you wish to do to recipient'),
182                 '$verbs' => $shortlist,
183                 '$parent' => $parent,
184                 '$prv_desc' => L10n::t('Make this post private'),
185                 '$submit' => L10n::t('Submit'),
186                 '$name' => $name,
187                 '$id' => $id
188         ]);
189
190         return $o;
191 }