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\Logger;
19 use Friendica\Core\Renderer;
20 use Friendica\Core\System;
21 use Friendica\Database\DBA;
23 use Friendica\Model\Item;
24 use Friendica\Protocol\Activity;
25 use Friendica\Util\Strings;
26 use Friendica\Util\XML;
28 function poke_init(App $a)
36 if (empty($_GET['verb'])) {
40 $verb = Strings::escapeTags(trim($_GET['verb']));
42 $verbs = DI::l10n()->getPokeVerbs();
44 if (!array_key_exists($verb, $verbs)) {
48 $activity = Activity::POKE . '#' . urlencode($verbs[$verb][0]);
50 $contact_id = intval($_GET['cid']);
55 $parent = (!empty($_GET['parent']) ? intval($_GET['parent']) : 0);
58 Logger::log('poke: verb ' . $verb . ' contact ' . $contact_id, Logger::DEBUG);
61 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
66 if (!DBA::isResult($r)) {
67 Logger::log('poke: no contact ' . $contact_id);
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);
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'];
87 $private = (!empty($_GET['private']) ? intval($_GET['private']) : Item::PUBLIC);
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']);
95 $poster = $a->contact;
97 $uri = Item::newURI($uid);
101 $arr['guid'] = System::createUUID();
104 $arr['parent-uri'] = (!empty($parent_uri) ? $parent_uri : $uri);
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'];
114 $arr['allow_cid'] = $allow_cid;
115 $arr['allow_gid'] = $allow_gid;
116 $arr['deny_cid'] = $deny_cid;
117 $arr['deny_gid'] = $deny_gid;
119 $arr['verb'] = $activity;
120 $arr['private'] = $private;
121 $arr['object-type'] = Activity\ObjectType::PERSON;
124 $arr['body'] = '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' . ' ' . DI::l10n()->t($verbs[$verb][0]) . ' ' . '[url=' . $target['url'] . ']' . $target['name'] . '[/url]';
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");
129 $arr['object'] .= XML::escape('<link rel="photo" type="image/jpeg" href="' . $target['photo'] . '" />' . "\n");
130 $arr['object'] .= '</link></object>' . "\n";
134 Hook::callAll('post_local_end', $arr);
139 function poke_content(App $a)
142 notice(DI::l10n()->t('Permission denied.') . EOL);
146 if (empty($_GET['c'])) {
150 $contact = DBA::selectFirst('contact', ['id', 'name'], ['id' => $_GET['c'], 'uid' => local_user()]);
151 if (!DBA::isResult($contact)) {
155 $name = $contact['name'];
156 $id = $contact['id'];
158 $head_tpl = Renderer::getMarkupTemplate('poke_head.tpl');
159 DI::page()['htmlhead'] .= Renderer::replaceMacros($head_tpl,[
160 '$baseurl' => DI::baseUrl()->get(true),
163 $parent = (!empty($_GET['parent']) ? intval($_GET['parent']) : '0');
166 $verbs = DI::l10n()->getPokeVerbs();
169 foreach ($verbs as $k => $v) {
170 if ($v[1] !== 'NOTRANSLATION') {
171 $shortlist[] = [$k, $v[1]];
175 $tpl = Renderer::getMarkupTemplate('poke_content.tpl');
177 $o = Renderer::replaceMacros($tpl,[
178 '$title' => DI::l10n()->t('Poke/Prod'),
179 '$desc' => DI::l10n()->t('poke, prod or do other things to somebody'),
180 '$clabel' => DI::l10n()->t('Recipient'),
181 '$choice' => DI::l10n()->t('Choose what you wish to do to recipient'),
182 '$verbs' => $shortlist,
183 '$parent' => $parent,
184 '$prv_desc' => DI::l10n()->t('Make this post private'),
185 '$submit' => DI::l10n()->t('Submit'),