]> git.mxchange.org Git - friendica.git/blob - mod/poke.php
82cf4b6d2c21667d9d1e85fe21186d8d212ad714
[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  * plugin 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  */
15  * @file mod/poke.php
16 require_once('include/security.php');
17 require_once('include/bbcode.php');
18 require_once('include/items.php');
19
20
21 function poke_init(App $a) {
22
23         if (! local_user()) {
24                 return;
25         }
26
27         $uid = local_user();
28         $verb = notags(trim($_GET['verb']));
29
30         if (! $verb) {
31                 return;
32         }
33
34         $verbs = get_poke_verbs();
35
36         if (! array_key_exists($verb,$verbs)) {
37                 return;
38         }
39
40         $activity = ACTIVITY_POKE . '#' . urlencode($verbs[$verb][0]);
41
42         $contact_id = intval($_GET['cid']);
43         if (! $contact_id) {
44                 return;
45         }
46
47         $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : 0);
48
49
50         logger('poke: verb ' . $verb . ' contact ' . $contact_id, LOGGER_DEBUG);
51
52
53         $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
54                 intval($contact_id),
55                 intval($uid)
56         );
57
58         if (! dbm::is_result($r)) {
59                 logger('poke: no contact ' . $contact_id);
60                 return;
61         }
62
63         $target = $r[0];
64
65         if($parent) {
66                 $r = q("SELECT `uri`, `private`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`
67                         FROM `item` WHERE `id` = %d AND `parent` = %d AND `uid` = %d LIMIT 1",
68                         intval($parent),
69                         intval($parent),
70                         intval($uid)
71                 );
72                 if (dbm::is_result($r)) {
73                         $parent_uri = $r[0]['uri'];
74                         $private    = $r[0]['private'];
75                         $allow_cid  = $r[0]['allow_cid'];
76                         $allow_gid  = $r[0]['allow_gid'];
77                         $deny_cid   = $r[0]['deny_cid'];
78                         $deny_gid   = $r[0]['deny_gid'];
79                 }
80         }
81         else {
82
83                 $private = ((x($_GET,'private')) ? intval($_GET['private']) : 0);
84
85                 $allow_cid     = (($private) ? '<' . $target['id']. '>' : $a->user['allow_cid']);
86                 $allow_gid     = (($private) ? '' : $a->user['allow_gid']);
87                 $deny_cid      = (($private) ? '' : $a->user['deny_cid']);
88                 $deny_gid      = (($private) ? '' : $a->user['deny_gid']);
89         }
90
91         $poster = $a->contact;
92
93         $uri = item_new_uri($a->get_hostname(),$uid);
94
95         $arr = array();
96
97         $arr['guid']          = get_guid(32);
98         $arr['uid']           = $uid;
99         $arr['uri']           = $uri;
100         $arr['parent-uri']    = (($parent_uri) ? $parent_uri : $uri);
101         $arr['type']          = 'activity';
102         $arr['wall']          = 1;
103         $arr['contact-id']    = $poster['id'];
104         $arr['owner-name']    = $poster['name'];
105         $arr['owner-link']    = $poster['url'];
106         $arr['owner-avatar']  = $poster['thumb'];
107         $arr['author-name']   = $poster['name'];
108         $arr['author-link']   = $poster['url'];
109         $arr['author-avatar'] = $poster['thumb'];
110         $arr['title']         = '';
111         $arr['allow_cid']     = $allow_cid;
112         $arr['allow_gid']     = $allow_gid;
113         $arr['deny_cid']      = $deny_cid;
114         $arr['deny_gid']      = $deny_gid;
115         $arr['last-child']    = 1;
116         $arr['visible']       = 1;
117         $arr['verb']          = $activity;
118         $arr['private']       = $private;
119         $arr['object-type']   = ACTIVITY_OBJ_PERSON;
120
121         $arr['origin']        = 1;
122         $arr['body']          = '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' . ' ' . t($verbs[$verb][0]) . ' ' . '[url=' . $target['url'] . ']' . $target['name'] . '[/url]';
123
124         $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $target['name'] . '</title><id>' . App::get_baseurl() . '/contact/' . $target['id'] . '</id>';
125         $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $target['url'] . '" />' . "\n");
126
127         $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $target['photo'] . '" />' . "\n");
128         $arr['object'] .= '</link></object>' . "\n";
129
130         $item_id = item_store($arr);
131         if($item_id) {
132                 //q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
133                 //      dbesc(App::get_baseurl() . '/display/' . $poster['nickname'] . '/' . $item_id),
134                 //      intval($uid),
135                 //      intval($item_id)
136                 //);
137                 proc_run(PRIORITY_HIGH, "include/notifier.php", "tag", $item_id);
138         }
139
140
141         call_hooks('post_local_end', $arr);
142
143         proc_run(PRIORITY_HIGH, "include/notifier.php", "like", $post_id);
144
145         return;
146 }
147
148
149
150 function poke_content(App $a) {
151
152         if (! local_user()) {
153                 notice( t('Permission denied.') . EOL);
154                 return;
155         }
156
157         $name = '';
158         $id = '';
159
160         if(intval($_GET['c'])) {
161                 $r = q("SELECT `id`,`name` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
162                         intval($_GET['c']),
163                         intval(local_user())
164                 );
165                 if (dbm::is_result($r)) {
166                         $name = $r[0]['name'];
167                         $id = $r[0]['id'];
168                 }
169         }
170
171
172         $base = App::get_baseurl();
173
174         $head_tpl = get_markup_template('poke_head.tpl');
175         $a->page['htmlhead'] .= replace_macros($head_tpl,array(
176                 '$baseurl' => App::get_baseurl(true),
177                 '$base' => $base
178         ));
179
180
181         $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : '0');
182
183
184         $verbs = get_poke_verbs();
185
186         $shortlist = array();
187         foreach($verbs as $k => $v)
188                 if($v[1] !== 'NOTRANSLATION')
189                         $shortlist[] = array($k,$v[1]);
190
191
192         $tpl = get_markup_template('poke_content.tpl');
193
194         $o = replace_macros($tpl,array(
195                 '$title' => t('Poke/Prod'),
196                 '$desc' => t('poke, prod or do other things to somebody'),
197                 '$clabel' => t('Recipient'),
198                 '$choice' => t('Choose what you wish to do to recipient'),
199                 '$verbs' => $shortlist,
200                 '$parent' => $parent,
201                 '$prv_desc' => t('Make this post private'),
202                 '$submit' => t('Submit'),
203                 '$name' => $name,
204                 '$id' => $id
205         ));
206
207         return $o;
208
209 }