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