]> git.mxchange.org Git - friendica.git/blob - mod/poke.php
Merge pull request #4288 from zeroadam/Addon
[friendica.git] / mod / poke.php
1 <?php
2
3 /**
4  * Poke, prod, finger, or otherwise do unspeakable things to somebody - who must be a connection in your address book
5  * This function can be invoked with the required arguments (verb and cid and private and possibly parent) silently via ajax or
6  * other web request. You must be logged in and connected to a profile.
7  * If the required arguments aren't present, we'll display a simple form to choose a recipient and a verb.
8  * parent is a special argument which let's you attach this activity as a comment to an existing conversation, which
9  * may have started with somebody else poking (etc.) somebody, but this isn't necessary. This can be used in the more pokes
10  * addon version to have entire conversations where Alice poked Bob, Bob fingered Alice, Alice hugged Bob, etc.
11  *
12  * private creates a private conversation with the recipient. Otherwise your profile's default post privacy is used.
13  *
14  * @file mod/poke.php
15  */
16
17 use Friendica\App;
18 use Friendica\Core\Addon;
19 use Friendica\Core\System;
20 use Friendica\Core\Worker;
21 use Friendica\Database\DBM;
22
23 require_once('include/security.php');
24 require_once('include/bbcode.php');
25 require_once('include/items.php');
26
27 function poke_init(App $a) {
28
29         if (! local_user()) {
30                 return;
31         }
32
33         $uid = local_user();
34         $verb = notags(trim($_GET['verb']));
35
36         if (! $verb) {
37                 return;
38         }
39
40         $verbs = get_poke_verbs();
41
42         if (! array_key_exists($verb,$verbs)) {
43                 return;
44         }
45
46         $activity = ACTIVITY_POKE . '#' . urlencode($verbs[$verb][0]);
47
48         $contact_id = intval($_GET['cid']);
49         if (! $contact_id) {
50                 return;
51         }
52
53         $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : 0);
54
55
56         logger('poke: verb ' . $verb . ' contact ' . $contact_id, LOGGER_DEBUG);
57
58
59         $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
60                 intval($contact_id),
61                 intval($uid)
62         );
63
64         if (! DBM::is_result($r)) {
65                 logger('poke: no contact ' . $contact_id);
66                 return;
67         }
68
69         $target = $r[0];
70
71         if($parent) {
72                 $r = q("SELECT `uri`, `private`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`
73                         FROM `item` WHERE `id` = %d AND `parent` = %d AND `uid` = %d LIMIT 1",
74                         intval($parent),
75                         intval($parent),
76                         intval($uid)
77                 );
78                 if (DBM::is_result($r)) {
79                         $parent_uri = $r[0]['uri'];
80                         $private    = $r[0]['private'];
81                         $allow_cid  = $r[0]['allow_cid'];
82                         $allow_gid  = $r[0]['allow_gid'];
83                         $deny_cid   = $r[0]['deny_cid'];
84                         $deny_gid   = $r[0]['deny_gid'];
85                 }
86         }
87         else {
88
89                 $private = ((x($_GET,'private')) ? intval($_GET['private']) : 0);
90
91                 $allow_cid     = (($private) ? '<' . $target['id']. '>' : $a->user['allow_cid']);
92                 $allow_gid     = (($private) ? '' : $a->user['allow_gid']);
93                 $deny_cid      = (($private) ? '' : $a->user['deny_cid']);
94                 $deny_gid      = (($private) ? '' : $a->user['deny_gid']);
95         }
96
97         $poster = $a->contact;
98
99         $uri = item_new_uri($a->get_hostname(),$uid);
100
101         $arr = [];
102
103         $arr['guid']          = get_guid(32);
104         $arr['uid']           = $uid;
105         $arr['uri']           = $uri;
106         $arr['parent-uri']    = (($parent_uri) ? $parent_uri : $uri);
107         $arr['type']          = 'activity';
108         $arr['wall']          = 1;
109         $arr['contact-id']    = $poster['id'];
110         $arr['owner-name']    = $poster['name'];
111         $arr['owner-link']    = $poster['url'];
112         $arr['owner-avatar']  = $poster['thumb'];
113         $arr['author-name']   = $poster['name'];
114         $arr['author-link']   = $poster['url'];
115         $arr['author-avatar'] = $poster['thumb'];
116         $arr['title']         = '';
117         $arr['allow_cid']     = $allow_cid;
118         $arr['allow_gid']     = $allow_gid;
119         $arr['deny_cid']      = $deny_cid;
120         $arr['deny_gid']      = $deny_gid;
121         $arr['visible']       = 1;
122         $arr['verb']          = $activity;
123         $arr['private']       = $private;
124         $arr['object-type']   = ACTIVITY_OBJ_PERSON;
125
126         $arr['origin']        = 1;
127         $arr['body']          = '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' . ' ' . t($verbs[$verb][0]) . ' ' . '[url=' . $target['url'] . ']' . $target['name'] . '[/url]';
128
129         $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $target['name'] . '</title><id>' . System::baseUrl() . '/contact/' . $target['id'] . '</id>';
130         $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $target['url'] . '" />' . "\n");
131
132         $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $target['photo'] . '" />' . "\n");
133         $arr['object'] .= '</link></object>' . "\n";
134
135         $item_id = item_store($arr);
136         if($item_id) {
137                 //q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
138                 //      dbesc(System::baseUrl() . '/display/' . $poster['nickname'] . '/' . $item_id),
139                 //      intval($uid),
140                 //      intval($item_id)
141                 //);
142                 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
143         }
144
145
146         Addon::callHooks('post_local_end', $arr);
147
148         Worker::add(PRIORITY_HIGH, "Notifier", "like", $post_id);
149
150         return;
151 }
152
153
154
155 function poke_content(App $a) {
156
157         if (! local_user()) {
158                 notice( t('Permission denied.') . EOL);
159                 return;
160         }
161
162         $name = '';
163         $id = '';
164
165         if(intval($_GET['c'])) {
166                 $r = q("SELECT `id`,`name` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
167                         intval($_GET['c']),
168                         intval(local_user())
169                 );
170                 if (DBM::is_result($r)) {
171                         $name = $r[0]['name'];
172                         $id = $r[0]['id'];
173                 }
174         }
175
176
177         $base = System::baseUrl();
178
179         $head_tpl = get_markup_template('poke_head.tpl');
180         $a->page['htmlhead'] .= replace_macros($head_tpl,[
181                 '$baseurl' => System::baseUrl(true),
182                 '$base' => $base
183         ]);
184
185
186         $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : '0');
187
188
189         $verbs = get_poke_verbs();
190
191         $shortlist = [];
192         foreach($verbs as $k => $v)
193                 if($v[1] !== 'NOTRANSLATION')
194                         $shortlist[] = [$k,$v[1]];
195
196
197         $tpl = get_markup_template('poke_content.tpl');
198
199         $o = replace_macros($tpl,[
200                 '$title' => t('Poke/Prod'),
201                 '$desc' => t('poke, prod or do other things to somebody'),
202                 '$clabel' => t('Recipient'),
203                 '$choice' => t('Choose what you wish to do to recipient'),
204                 '$verbs' => $shortlist,
205                 '$parent' => $parent,
206                 '$prv_desc' => t('Make this post private'),
207                 '$submit' => t('Submit'),
208                 '$name' => $name,
209                 '$id' => $id
210         ]);
211
212         return $o;
213
214 }