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