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