]> git.mxchange.org Git - friendica.git/blob - mod/poke.php
poke privacy
[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
31         $private = ((x($_GET,'private')) ? intval($_GET['private']) : 0);
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         $poster = $a->contact;
49
50         $uri = item_new_uri($a->get_hostname(),$owner_uid);
51
52         $arr = array();
53
54         $arr['uid']           = $uid;
55         $arr['uri']           = $uri;
56         $arr['parent-uri']    = $uri;
57         $arr['type']          = 'activity';
58         $arr['wall']          = 1;
59         $arr['contact-id']    = $poster['id'];
60         $arr['owner-name']    = $poster['name'];
61         $arr['owner-link']    = $poster['url'];
62         $arr['owner-avatar']  = $poster['thumb'];
63         $arr['author-name']   = $poster['name'];
64         $arr['author-link']   = $poster['url'];
65         $arr['author-avatar'] = $poster['thumb'];
66         $arr['title']         = '';
67         $arr['allow_cid']     = (($private) ? '<' . $target['id']. '>' : $a->user['allow_cid']);
68         $arr['allow_gid']     = (($private) ? '' : $a->user['allow_gid']);
69         $arr['deny_cid']      = (($private) ? '' : $a->user['deny_cid']);
70         $arr['deny_gid']      = (($private) ? '' : $a->user['deny_gid']);
71         $arr['last-child']    = 1;
72         $arr['visible']       = 1;
73         $arr['verb']          = $activity;
74         $arr['private']       = $private;
75         $arr['object-type']   = ACTIVITY_OBJ_PERSON;
76
77         $arr['origin']        = 1;
78         $arr['body']          = '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' . ' ' . t($verbs[$verb][0]) . ' ' . '[url=' . $target['url'] . ']' . $target['name'] . '[/url]';
79
80         $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $target['name'] . '</title><id>' . $a->get_baseurl() . '/contact/' . $target['id'] . '</id>';
81         $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $target['url'] . '" />' . "\n");
82
83         $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $target['photo'] . '" />' . "\n");
84         $arr['object'] .= '</link></object>' . "\n";
85
86         $item_id = item_store($arr);
87         if($item_id) {
88                 q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
89                         dbesc($a->get_baseurl() . '/display/' . $poster['nickname'] . '/' . $item_id),
90                         intval($uid),
91                         intval($item_id)
92                 );
93                 proc_run('php',"include/notifier.php","tag","$item_id");
94         }
95
96
97         call_hooks('post_local_end', $arr);
98
99         proc_run('php',"include/notifier.php","like","$post_id");
100
101         return;
102 }
103
104
105
106 function poke_content(&$a) {
107
108         if(! local_user()) {
109                 notice( t('Permission denied.') . EOL);
110                 return;
111         }
112
113         $name = '';
114         $id = '';
115
116         if(intval($_GET['c'])) {
117                 $r = q("select id,name from contact where id = %d and uid = %d limit 1",
118                         intval($_GET['c']),
119                         intval(local_user())
120                 );
121                 if(count($r)) {
122                         $name = $r[0]['name'];
123                         $id = $r[0]['id'];
124                 }
125         }
126
127
128         $base = $a->get_baseurl();
129
130         $a->page['htmlhead'] .= '<script src="' . $a->get_baseurl(true) . '/library/jquery_ac/friendica.complete.js" ></script>';
131         $a->page['htmlhead'] .= <<< EOT
132
133 <script>$(document).ready(function() { 
134         var a; 
135         a = $("#recip").autocomplete({ 
136                 serviceUrl: '$base/acl',
137                 minChars: 2,
138                 width: 350,
139                 onSelect: function(value,data) {
140                         $("#recip-complete").val(data);
141                 }                       
142         });
143         a.setOptions({ params: { type: 'a' }});
144
145
146 }); 
147
148 </script>
149 EOT;
150
151
152         $verbs = get_poke_verbs();
153
154         $shortlist = array();
155         foreach($verbs as $k => $v)
156                 if($v[1] !== 'NOTRANSLATION')
157                         $shortlist[] = array($k,$v[1]);
158
159
160         $tpl = get_markup_template('poke_content.tpl');
161
162         $o = replace_macros($tpl,array(
163                 '$title' => t('Poke/Prod'),
164                 '$desc' => t('poke, prod or do other things to somebody'),
165                 '$clabel' => t('Recipient'),
166                 '$choice' => t('Choose what you wish to do to recipient'),
167                 '$verbs' => $shortlist,
168                 '$prv_desc' => t('Make this post private'),
169                 '$submit' => t('Submit'),
170                 '$name' => $name,
171                 '$id' => $id
172         ));
173
174         return $o;
175
176 }