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\Addon;
18 use Friendica\Core\L10n;
19 use Friendica\Core\Logger;
20 use Friendica\Core\Renderer;
21 use Friendica\Core\System;
22 use Friendica\Core\Worker;
23 use Friendica\Database\DBA;
24 use Friendica\Model\Item;
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 = 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']) : 0);
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_OBJ_PERSON;
124 $arr['body'] = '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' . ' ' . L10n::t($verbs[$verb][0]) . ' ' . '[url=' . $target['url'] . ']' . $target['name'] . '[/url]';
126 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_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";
132 $item_id = Item::insert($arr);
134 Addon::callHooks('post_local_end', $arr);
139 function poke_content(App $a)
142 notice(L10n::t('Permission denied.') . EOL);
149 if (empty($_GET['c'])) {
153 $contact = DBA::selectFirst('contact', ['id', 'name'], ['id' => $_GET['c'], 'uid' => local_user()]);
154 if (!DBA::isResult($contact)) {
158 $name = $contact['name'];
159 $id = $contact['id'];
161 $base = System::baseUrl();
163 $head_tpl = Renderer::getMarkupTemplate('poke_head.tpl');
164 $a->page['htmlhead'] .= Renderer::replaceMacros($head_tpl,[
165 '$baseurl' => System::baseUrl(true),
170 $parent = (!empty($_GET['parent']) ? intval($_GET['parent']) : '0');
173 $verbs = L10n::getPokeVerbs();
176 foreach ($verbs as $k => $v) {
177 if ($v[1] !== 'NOTRANSLATION') {
178 $shortlist[] = [$k, $v[1]];
182 $tpl = Renderer::getMarkupTemplate('poke_content.tpl');
184 $o = Renderer::replaceMacros($tpl,[
185 '$title' => L10n::t('Poke/Prod'),
186 '$desc' => L10n::t('poke, prod or do other things to somebody'),
187 '$clabel' => L10n::t('Recipient'),
188 '$choice' => L10n::t('Choose what you wish to do to recipient'),
189 '$verbs' => $shortlist,
190 '$parent' => $parent,
191 '$prv_desc' => L10n::t('Make this post private'),
192 '$submit' => L10n::t('Submit'),