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;
27 require_once 'include/items.php';
29 function poke_init(App $a)
37 if (empty($_GET['verb'])) {
41 $verb = notags(trim($_GET['verb']));
43 $verbs = get_poke_verbs();
45 if (!array_key_exists($verb, $verbs)) {
49 $activity = ACTIVITY_POKE . '#' . urlencode($verbs[$verb][0]);
51 $contact_id = intval($_GET['cid']);
56 $parent = (x($_GET,'parent') ? intval($_GET['parent']) : 0);
59 Logger::log('poke: verb ' . $verb . ' contact ' . $contact_id, Logger::DEBUG);
62 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
67 if (!DBA::isResult($r)) {
68 Logger::log('poke: no contact ' . $contact_id);
75 $fields = ['uri', 'private', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
76 $condition = ['id' => $parent, 'parent' => $parent, 'uid' => $uid];
77 $item = Item::selectFirst($fields, $condition);
79 if (DBA::isResult($item)) {
80 $parent_uri = $item['uri'];
81 $private = $item['private'];
82 $allow_cid = $item['allow_cid'];
83 $allow_gid = $item['allow_gid'];
84 $deny_cid = $item['deny_cid'];
85 $deny_gid = $item['deny_gid'];
88 $private = (x($_GET,'private') ? intval($_GET['private']) : 0);
90 $allow_cid = ($private ? '<' . $target['id']. '>' : $a->user['allow_cid']);
91 $allow_gid = ($private ? '' : $a->user['allow_gid']);
92 $deny_cid = ($private ? '' : $a->user['deny_cid']);
93 $deny_gid = ($private ? '' : $a->user['deny_gid']);
96 $poster = $a->contact;
98 $uri = Item::newURI($uid);
102 $arr['guid'] = System::createUUID();
105 $arr['parent-uri'] = (!empty($parent_uri) ? $parent_uri : $uri);
107 $arr['contact-id'] = $poster['id'];
108 $arr['owner-name'] = $poster['name'];
109 $arr['owner-link'] = $poster['url'];
110 $arr['owner-avatar'] = $poster['thumb'];
111 $arr['author-name'] = $poster['name'];
112 $arr['author-link'] = $poster['url'];
113 $arr['author-avatar'] = $poster['thumb'];
115 $arr['allow_cid'] = $allow_cid;
116 $arr['allow_gid'] = $allow_gid;
117 $arr['deny_cid'] = $deny_cid;
118 $arr['deny_gid'] = $deny_gid;
120 $arr['verb'] = $activity;
121 $arr['private'] = $private;
122 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
125 $arr['body'] = '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' . ' ' . L10n::t($verbs[$verb][0]) . ' ' . '[url=' . $target['url'] . ']' . $target['name'] . '[/url]';
127 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $target['name'] . '</title><id>' . $target['url'] . '</id>';
128 $arr['object'] .= '<link>' . Strings::escape('<link rel="alternate" type="text/html" href="' . $target['url'] . '" />' . "\n");
130 $arr['object'] .= Strings::escape('<link rel="photo" type="image/jpeg" href="' . $target['photo'] . '" />' . "\n");
131 $arr['object'] .= '</link></object>' . "\n";
133 $item_id = Item::insert($arr);
135 Addon::callHooks('post_local_end', $arr);
140 function poke_content(App $a)
143 notice(L10n::t('Permission denied.') . EOL);
150 if (empty($_GET['c'])) {
154 $contact = DBA::selectFirst('contact', ['id', 'name'], ['id' => $_GET['c'], 'uid' => local_user()]);
155 if (!DBA::isResult($contact)) {
159 $name = $contact['name'];
160 $id = $contact['id'];
162 $base = System::baseUrl();
164 $head_tpl = Renderer::getMarkupTemplate('poke_head.tpl');
165 $a->page['htmlhead'] .= Renderer::replaceMacros($head_tpl,[
166 '$baseurl' => System::baseUrl(true),
171 $parent = (x($_GET,'parent') ? intval($_GET['parent']) : '0');
174 $verbs = get_poke_verbs();
177 foreach ($verbs as $k => $v) {
178 if ($v[1] !== 'NOTRANSLATION') {
179 $shortlist[] = [$k, $v[1]];
183 $tpl = Renderer::getMarkupTemplate('poke_content.tpl');
185 $o = Renderer::replaceMacros($tpl,[
186 '$title' => L10n::t('Poke/Prod'),
187 '$desc' => L10n::t('poke, prod or do other things to somebody'),
188 '$clabel' => L10n::t('Recipient'),
189 '$choice' => L10n::t('Choose what you wish to do to recipient'),
190 '$verbs' => $shortlist,
191 '$parent' => $parent,
192 '$prv_desc' => L10n::t('Make this post private'),
193 '$submit' => L10n::t('Submit'),