]> git.mxchange.org Git - friendica.git/blob - mod/poke.php
id mismatch
[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         logger('poke: verb ' . $verb . ' contact ' . $contact_id, LOGGER_DEBUG);
32
33
34         $r = q("SELECT * FROM `contact` WHERE `id` = %d and  `uid` = %d LIMIT 1",
35                 intval($contact_id),
36                 intval($uid)
37         );
38
39         if(! count($r)) {
40                 logger('poke: no contact ' . $contact_id);
41                 return;
42         }
43
44         $target = $r[0];
45
46         $poster = $a->contact;
47
48         $uri = item_new_uri($a->get_hostname(),$owner_uid);
49
50         $arr = array();
51
52         $arr['uid']           = $uid;
53         $arr['uri']           = $uri;
54         $arr['parent-uri']    = $uri;
55         $arr['type']          = 'activity';
56         $arr['wall']          = 1;
57         $arr['contact-id']    = $poster['id'];
58         $arr['owner-name']    = $poster['name'];
59         $arr['owner-link']    = $poster['url'];
60         $arr['owner-avatar']  = $poster['thumb'];
61         $arr['author-name']   = $poster['name'];
62         $arr['author-link']   = $poster['url'];
63         $arr['author-avatar'] = $poster['thumb'];
64         $arr['title']         = '';
65         $arr['allow_cid']     = $a->user['allow_cid'];
66         $arr['allow_gid']     = $a->user['allow_gid'];
67         $arr['deny_cid']      = $a->user['deny_cid'];
68         $arr['deny_gid']      = $a->user['deny_gid'];
69         $arr['last-child']    = 1;
70         $arr['visible']       = 1;
71         $arr['verb']          = $activity;
72         $arr['object-type']   = ACTIVITY_OBJ_PERSON;
73
74         $arr['origin']        = 1;
75         $arr['body']          = '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' . ' ' . t($verbs[$verb][0]) . ' ' . '[url=' . $target['url'] . ']' . $target['name'] . '[/url]';
76
77         $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $target['name'] . '</title><id>' . $a->get_baseurl() . '/contact/' . $target['id'] . '</id>';
78         $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $target['url'] . '" />' . "\n");
79
80         $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $target['photo'] . '" />' . "\n");
81         $arr['object'] .= '</link></object>' . "\n";
82
83         $item_id = item_store($arr);
84         if($item_id) {
85                 q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
86                         dbesc($a->get_baseurl() . '/display/' . $poster['nickname'] . '/' . $item_id),
87                         intval($uid),
88                         intval($item_id)
89                 );
90                 proc_run('php',"include/notifier.php","tag","$item_id");
91         }
92
93
94         call_hooks('post_local_end', $arr);
95
96         proc_run('php',"include/notifier.php","like","$post_id");
97
98         return;
99 }
100
101
102
103 function poke_content(&$a) {
104
105         $base = $a->get_baseurl();
106
107         $a->page['htmlhead'] .= '<script src="' . $a->get_baseurl(true) . '/library/jquery_ac/friendica.complete.js" ></script>';
108         $a->page['htmlhead'] .= <<< EOT
109
110 <script>$(document).ready(function() { 
111         var a; 
112         a = $("#recip").autocomplete({ 
113                 serviceUrl: '$base/acl',
114                 minChars: 2,
115                 width: 350,
116                 onSelect: function(value,data) {
117                         $("#recip-complete").val(data);
118                 }                       
119         });
120         a.setOptions({ params: { type: 'a' }});
121
122
123 }); 
124
125 </script>
126 EOT;
127
128
129         $verbs = get_poke_verbs();
130
131         $shortlist = array();
132         foreach($verbs as $k => $v)
133                 $shortlist[] = array($k,$v[1]);
134
135
136         $tpl = get_markup_template('poke_content.tpl');
137
138         $o = replace_macros($tpl,array(
139                 '$title' => t('Poke/Prod'),
140                 '$desc' => t('poke, prod or do other things to somebody'),
141                 '$clabel' => t('Recipient'),
142                 '$choice' => t('Choose what you wish to do to recipient'),
143                 '$verbs' => $shortlist,
144                 '$submit' => t('Submit')
145         ));
146
147         return $o;
148
149 }