]> git.mxchange.org Git - friendica.git/blob - mod/network.php
provide disclosure warning on private network page
[friendica.git] / mod / network.php
1 <?php
2
3
4 function network_init(&$a) {
5         if(! local_user()) {
6                 notice( t('Permission denied.') . EOL);
7                 return;
8         }
9   
10   
11         require_once('include/group.php');
12         if(! x($a->page,'aside'))
13                 $a->page['aside'] = '';
14
15         $a->page['aside'] .= '<div id="network-new-link">';
16
17         if(($a->argc > 1 && $a->argv[1] === 'new') || ($a->argc > 2 && $a->argv[2] === 'new'))
18                 $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '">' . t('Normal View') . '</a>';
19         else 
20                 $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . $a->cmd . '/new' . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '">' . t('New Item View') . '</a>';
21
22         $a->page['aside'] .= '</div>';
23
24         $a->page['aside'] .= group_side('network','network',true);
25 }
26
27
28 function network_content(&$a, $update = 0) {
29
30         require_once('include/conversation.php');
31
32         if(! local_user())
33         return login(false);
34
35         $o = '';
36
37         $contact_id = $a->cid;
38
39         $group = 0;
40
41         $nouveau = false;
42         require_once('include/acl_selectors.php');
43
44         $cid = ((x($_GET['cid'])) ? intval($_GET['cid']) : 0);
45
46         if(($a->argc > 2) && $a->argv[2] === 'new')
47                 $nouveau = true;
48
49         if($a->argc > 1) {
50                 if($a->argv[1] === 'new')
51                         $nouveau = true;
52                 else {
53                         $group = intval($a->argv[1]);
54                         $def_acl = array('allow_gid' => '<' . $group . '>');
55                 }
56         }
57
58         if($cid)
59                 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
60
61         if(! $update) {
62                 if(group) {
63                         if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
64                                 $plural_form = sprintf( tt('%d member', '%d members', $t), $t);
65                                 notice( sprintf( t('Warning: This group contains %s from an insecure network.'), $plural_form ) . EOL);
66                                 notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
67                         }
68                 }
69
70                 $o .= '<script> $(document).ready(function() { $(\'#nav-network-link\').addClass(\'nav-selected\'); });</script>';
71
72                 $_SESSION['return_url'] = $a->cmd;
73
74                 $geotag = (($a->user['allow_location']) ? load_view_file('view/jot_geotag.tpl') : '');
75
76                 $tpl = load_view_file('view/jot-header.tpl');
77         
78                 $a->page['htmlhead'] .= replace_macros($tpl, array(
79                         '$baseurl' => $a->get_baseurl(),
80                         '$geotag' => $geotag,
81                         '$nickname' => $a->user['nickname'],
82                         '$linkurl' => t('Please enter a link URL:'),
83                         '$utubeurl' => t('Please enter a YouTube link:'),
84                         '$vidurl' => t("Please enter a video\x28.ogg\x29 link/URL:"),
85                         '$audurl' => t("Please enter an audio\x28.ogg\x29 link/URL:"),
86                         '$whereareu' => t('Where are you right now?'),
87                         '$title' => t('Enter a title for this item') 
88                 ));
89
90
91                 $tpl = load_view_file("view/jot.tpl");
92                 
93                 if(($group) || (is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid'])))))
94                                 $lockstate = 'lock';
95                         else
96                                 $lockstate = 'unlock';
97
98                 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
99
100                 $jotplugins = '';
101                 $jotnets = '';
102
103                 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
104
105                 $mail_enabled = false;
106                 $pubmail_enabled = false;
107
108                 if(! $mail_disabled) {
109                         $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
110                                 intval(local_user())
111                         );
112                         if(count($r)) {
113                                 $mail_enabled = true;
114                                 if(intval($r[0]['pubmail']))
115                                         $pubmail_enabled = true;
116                         }
117                 }
118
119                 if($mail_enabled) {
120                $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
121                         $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . 'value="1" /> '
122                 . t("Post to Email") . '</div>';
123                 }
124
125
126                 call_hooks('jot_tool', $jotplugins);
127                 call_hooks('jot_networks', $jotnets);
128
129                 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));        
130
131                 $o .= replace_macros($tpl,array(
132                         '$return_path' => $a->cmd,
133                         '$action' => 'item',
134                         '$share' => t('Share'),
135                         '$upload' => t('Upload photo'),
136                         '$weblink' => t('Insert web link'),
137                         '$youtube' => t('Insert YouTube video'),
138                         '$video' => t('Insert Vorbis [.ogg] video'),
139                         '$audio' => t('Insert Vorbis [.ogg] audio'),
140                         '$setloc' => t('Set your location'),
141                         '$noloc' => t('Clear browser location'),
142                         '$title' => t('Set title'),
143                         '$wait' => t('Please wait'),
144                         '$permset' => t('Permission settings'),
145                         '$content' => '',
146                         '$post_id' => '',
147                         '$baseurl' => $a->get_baseurl(),
148                         '$defloc' => $a->user['default-location'],
149                         '$visitor' => 'block',
150                         '$emailcc' => t('CC: email addresses'),
151                         '$jotnets' => $jotnets,
152                         '$emtitle' => t('Example: bob@example.com, mary@example.com'),
153                         '$lockstate' => $lockstate,
154                         '$acl' => populate_acl((($group || $cid) ? $def_acl : $a->user), $celeb),
155                         '$bang' => (($group || $cid) ? '!' : ''),
156                         '$profile_uid' => local_user()
157                 ));
158
159
160                 // The special div is needed for liveUpdate to kick in for this page.
161                 // We only launch liveUpdate if you are on the front page, you aren't
162                 // filtering by group and also you aren't writing a comment (the last
163                 // criteria is discovered in javascript).
164
165                         $o .= '<div id="live-network"></div>' . "\r\n";
166                         $o .= "<script> var profile_uid = " . $_SESSION['uid'] 
167                                 . "; var netargs = '" . substr($a->cmd,8) 
168                                 . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '')
169                                 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
170
171         }
172
173         // We aren't going to try and figure out at the item, group, and page level 
174         // which items you've seen and which you haven't. You're looking at some
175         // subset of items, so just mark everything seen. 
176         
177         $r = q("UPDATE `item` SET `unseen` = 0 
178                 WHERE `unseen` = 1 AND `uid` = %d",
179                 intval($_SESSION['uid'])
180         );
181
182         // We don't have to deal with ACL's on this page. You're looking at everything
183         // that belongs to you, hence you can see all of it. We will filter by group if
184         // desired. 
185
186         $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
187
188         if($group) {
189                 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
190                         intval($group),
191                         intval($_SESSION['uid'])
192                 );
193                 if(! count($r)) {
194                         if($update)
195                                 killme();
196                         notice( t('No such group') . EOL );
197                         goaway($a->get_baseurl() . '/network');
198                         // NOTREACHED
199                 }
200
201                 $contacts = expand_groups(array($group));
202                 if((is_array($contacts)) && count($contacts)) {
203                         $contact_str = implode(',',$contacts);
204                 }
205                 else {
206                                 $contact_str = ' 0 ';
207                                 notice( t('Group is empty'));
208                 }
209
210                 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `contact-id` IN ( $contact_str )) ";
211                 $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
212         }
213         elseif($cid) {
214
215                 $r = q("SELECT `id`,`name`,`network`,`writable` FROM `contact` WHERE `id` = %d 
216                                 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
217                         intval($cid)
218                 );
219                 if(count($r)) {
220                         $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `contact-id` IN ( " . intval($cid) . " )) ";
221                         $o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o;
222                         if($r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_DFRN && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
223                                 notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
224                         }
225
226                 }
227                 else {
228                         notice( t('Invalid contact.') . EOL);
229                         goaway($a->get_baseurl() . '/network');
230                         // NOTREACHED
231                 }
232         }
233
234         if((! $group) && (! $cid) && (! $update))
235                 $o .= get_birthdays();
236
237
238         $r = q("SELECT COUNT(*) AS `total`
239                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
240                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
241                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
242                 $sql_extra ",
243                 intval($_SESSION['uid'])
244         );
245
246         if(count($r)) {
247                 $a->set_pager_total($r[0]['total']);
248                 $a->set_pager_itemspage(40);
249         }
250
251
252         if($nouveau) {
253
254                 // "New Item View" - show all items unthreaded in reverse created date order
255
256                 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
257                         `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
258                         `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
259                         `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
260                         FROM `item`, `contact`
261                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
262                         AND `contact`.`id` = `item`.`contact-id`
263                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
264                         $sql_extra
265                         ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
266                         intval($_SESSION['uid']),
267                         intval($a->pager['start']),
268                         intval($a->pager['itemspage'])
269                 );
270                 
271         }
272         else {
273
274                 // Normal conversation view
275                 // First fetch a known number of parent items
276
277                 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
278                         FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
279                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
280                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
281                         AND `item`.`parent` = `item`.`id`
282                         $sql_extra
283                         ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
284                         intval(local_user()),
285                         intval($a->pager['start']),
286                         intval($a->pager['itemspage'])
287                 );
288
289
290                 // Then fetch all the children of the parents that are on this page
291
292                 $parents_arr = array();
293                 $parents_str = '';
294
295                 if(count($r)) {
296                         foreach($r as $rr)
297                                 $parents_arr[] = $rr['item_id'];
298                         $parents_str = implode(', ', $parents_arr);
299
300                         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
301                                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
302                                 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
303                                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
304                                 FROM `item`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact`
305                                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
306                                 AND `contact`.`id` = `item`.`contact-id`
307                                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
308                                 AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
309                                 $sql_extra
310                                 ORDER BY `parentitem`.`created`  DESC, `item`.`gravity` ASC, `item`.`created` ASC ",
311                                 intval(local_user()),
312                                 dbesc($parents_str)
313                         );
314                 }
315         }
316
317         // Set this so that the conversation function can find out contact info for our wall-wall items
318         $a->page_contact = $a->contact;
319
320         $mode = (($nouveau) ? 'network-new' : 'network');
321
322         $o .= conversation($a,$r,$mode,$update);
323
324         if(! $update) {
325
326                 $o .= paginate($a);
327                 $o .= '<div class="cc-license">' . t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.') . '</div>';
328         }
329
330         return $o;
331 }