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