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.
11 * private creates a private conversation with the recipient. Otherwise your profile's default post privacy is used.
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\Util\Strings;
25 use Friendica\Util\XML;
27 function poke_init(App $a)
35 if (empty($_GET['verb'])) {
39 $verb = Strings::escapeTags(trim($_GET['verb']));
41 $verbs = L10n::getPokeVerbs();
43 if (!array_key_exists($verb, $verbs)) {
47 $activity = ACTIVITY_POKE . '#' . urlencode($verbs[$verb][0]);
49 $contact_id = intval($_GET['cid']);
54 $parent = (!empty($_GET['parent']) ? intval($_GET['parent']) : 0);
57 Logger::log('poke: verb ' . $verb . ' contact ' . $contact_id, Logger::DEBUG);
60 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
65 if (!DBA::isResult($r)) {
66 Logger::log('poke: no contact ' . $contact_id);
73 $fields = ['uri', 'private', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
74 $condition = ['id' => $parent, 'parent' => $parent, 'uid' => $uid];
75 $item = Item::selectFirst($fields, $condition);
77 if (DBA::isResult($item)) {
78 $parent_uri = $item['uri'];
79 $private = $item['private'];
80 $allow_cid = $item['allow_cid'];
81 $allow_gid = $item['allow_gid'];
82 $deny_cid = $item['deny_cid'];
83 $deny_gid = $item['deny_gid'];
86 $private = (!empty($_GET['private']) ? intval($_GET['private']) : 0);
88 $allow_cid = ($private ? '<' . $target['id']. '>' : $a->user['allow_cid']);
89 $allow_gid = ($private ? '' : $a->user['allow_gid']);
90 $deny_cid = ($private ? '' : $a->user['deny_cid']);
91 $deny_gid = ($private ? '' : $a->user['deny_gid']);
94 $poster = $a->contact;
96 $uri = Item::newURI($uid);
100 $arr['guid'] = System::createUUID();
103 $arr['parent-uri'] = (!empty($parent_uri) ? $parent_uri : $uri);
105 $arr['contact-id'] = $poster['id'];
106 $arr['owner-name'] = $poster['name'];
107 $arr['owner-link'] = $poster['url'];
108 $arr['owner-avatar'] = $poster['thumb'];
109 $arr['author-name'] = $poster['name'];
110 $arr['author-link'] = $poster['url'];
111 $arr['author-avatar'] = $poster['thumb'];
113 $arr['allow_cid'] = $allow_cid;
114 $arr['allow_gid'] = $allow_gid;
115 $arr['deny_cid'] = $deny_cid;
116 $arr['deny_gid'] = $deny_gid;
118 $arr['verb'] = $activity;
119 $arr['private'] = $private;
120 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
123 $arr['body'] = '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' . ' ' . L10n::t($verbs[$verb][0]) . ' ' . '[url=' . $target['url'] . ']' . $target['name'] . '[/url]';
125 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $target['name'] . '</title><id>' . $target['url'] . '</id>';
126 $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $target['url'] . '" />' . "\n");
128 $arr['object'] .= XML::escape('<link rel="photo" type="image/jpeg" href="' . $target['photo'] . '" />' . "\n");
129 $arr['object'] .= '</link></object>' . "\n";
133 Hook::callAll('post_local_end', $arr);
138 function poke_content(App $a)
141 notice(L10n::t('Permission denied.') . EOL);
145 if (empty($_GET['c'])) {
149 $contact = DBA::selectFirst('contact', ['id', 'name'], ['id' => $_GET['c'], 'uid' => local_user()]);
150 if (!DBA::isResult($contact)) {
154 $name = $contact['name'];
155 $id = $contact['id'];
157 $base = System::baseUrl();
159 $head_tpl = Renderer::getMarkupTemplate('poke_head.tpl');
160 $a->page['htmlhead'] .= Renderer::replaceMacros($head_tpl,[
161 '$baseurl' => System::baseUrl(true),
166 $parent = (!empty($_GET['parent']) ? intval($_GET['parent']) : '0');
169 $verbs = L10n::getPokeVerbs();
172 foreach ($verbs as $k => $v) {
173 if ($v[1] !== 'NOTRANSLATION') {
174 $shortlist[] = [$k, $v[1]];
178 $tpl = Renderer::getMarkupTemplate('poke_content.tpl');
180 $o = Renderer::replaceMacros($tpl,[
181 '$title' => L10n::t('Poke/Prod'),
182 '$desc' => L10n::t('poke, prod or do other things to somebody'),
183 '$clabel' => L10n::t('Recipient'),
184 '$choice' => L10n::t('Choose what you wish to do to recipient'),
185 '$verbs' => $shortlist,
186 '$parent' => $parent,
187 '$prv_desc' => L10n::t('Make this post private'),
188 '$submit' => L10n::t('Submit'),