]> git.mxchange.org Git - friendica.git/blob - mod/poke.php
Update function calls
[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\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\XML;
26
27 require_once 'include/items.php';
28
29 function poke_init(App $a)
30 {
31         if (!local_user()) {
32                 return;
33         }
34
35         $uid = local_user();
36
37         if (empty($_GET['verb'])) {
38                 return;
39         }
40
41         $verb = notags(trim($_GET['verb']));
42
43         $verbs = L10n::getPokeVerbs();
44
45         if (!array_key_exists($verb, $verbs)) {
46                 return;
47         }
48
49         $activity = ACTIVITY_POKE . '#' . urlencode($verbs[$verb][0]);
50
51         $contact_id = intval($_GET['cid']);
52         if (!$contact_id) {
53                 return;
54         }
55
56         $parent = (x($_GET,'parent') ? intval($_GET['parent']) : 0);
57
58
59         Logger::log('poke: verb ' . $verb . ' contact ' . $contact_id, Logger::DEBUG);
60
61
62         $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
63                 intval($contact_id),
64                 intval($uid)
65         );
66
67         if (!DBA::isResult($r)) {
68                 Logger::log('poke: no contact ' . $contact_id);
69                 return;
70         }
71
72         $target = $r[0];
73
74         if ($parent) {
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);
78
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'];
86                 }
87         } else {
88                 $private = (x($_GET,'private') ? intval($_GET['private']) : 0);
89
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']);
94         }
95
96         $poster = $a->contact;
97
98         $uri = Item::newURI($uid);
99
100         $arr = [];
101
102         $arr['guid']          = System::createUUID();
103         $arr['uid']           = $uid;
104         $arr['uri']           = $uri;
105         $arr['parent-uri']    = (!empty($parent_uri) ? $parent_uri : $uri);
106         $arr['wall']          = 1;
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'];
114         $arr['title']         = '';
115         $arr['allow_cid']     = $allow_cid;
116         $arr['allow_gid']     = $allow_gid;
117         $arr['deny_cid']      = $deny_cid;
118         $arr['deny_gid']      = $deny_gid;
119         $arr['visible']       = 1;
120         $arr['verb']          = $activity;
121         $arr['private']       = $private;
122         $arr['object-type']   = ACTIVITY_OBJ_PERSON;
123
124         $arr['origin']        = 1;
125         $arr['body']          = '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' . ' ' . L10n::t($verbs[$verb][0]) . ' ' . '[url=' . $target['url'] . ']' . $target['name'] . '[/url]';
126
127         $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $target['name'] . '</title><id>' . $target['url'] . '</id>';
128         $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $target['url'] . '" />' . "\n");
129
130         $arr['object'] .= XML::escape('<link rel="photo" type="image/jpeg" href="' . $target['photo'] . '" />' . "\n");
131         $arr['object'] .= '</link></object>' . "\n";
132
133         $item_id = Item::insert($arr);
134
135         Addon::callHooks('post_local_end', $arr);
136
137         return;
138 }
139
140 function poke_content(App $a)
141 {
142         if (!local_user()) {
143                 notice(L10n::t('Permission denied.') . EOL);
144                 return;
145         }
146
147         $name = '';
148         $id = '';
149
150         if (empty($_GET['c'])) {
151                 return;
152         }
153
154         $contact = DBA::selectFirst('contact', ['id', 'name'], ['id' => $_GET['c'], 'uid' => local_user()]);
155         if (!DBA::isResult($contact)) {
156                 return;
157         }
158
159         $name = $contact['name'];
160         $id = $contact['id'];
161
162         $base = System::baseUrl();
163
164         $head_tpl = Renderer::getMarkupTemplate('poke_head.tpl');
165         $a->page['htmlhead'] .= Renderer::replaceMacros($head_tpl,[
166                 '$baseurl' => System::baseUrl(true),
167                 '$base' => $base
168         ]);
169
170
171         $parent = (x($_GET,'parent') ? intval($_GET['parent']) : '0');
172
173
174         $verbs = L10n::getPokeVerbs();
175
176         $shortlist = [];
177         foreach ($verbs as $k => $v) {
178                 if ($v[1] !== 'NOTRANSLATION') {
179                         $shortlist[] = [$k, $v[1]];
180                 }
181         }
182
183         $tpl = Renderer::getMarkupTemplate('poke_content.tpl');
184
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'),
194                 '$name' => $name,
195                 '$id' => $id
196         ]);
197
198         return $o;
199 }