]> git.mxchange.org Git - friendica.git/blob - mod/network.php
typo
[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         $group_id = (($a->argc > 1 && intval($a->argv[1])) ? intval($a->argv[1]) : 0);
11                   
12         require_once('include/group.php');
13         if(! x($a->page,'aside'))
14                 $a->page['aside'] = '';
15
16         $search = ((x($_GET,'search')) ? escape_tags($_GET['search']) : '');
17         $srchurl = '/network' . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : '') . ((x($_GET,'star')) ? '?star=' . $_GET['star'] : '');
18
19
20         $a->page['aside'] .= search($search,'netsearch-box',$srchurl);
21
22         $a->page['aside'] .= '<div id="network-new-link">';
23
24
25         $a->page['aside'] .= '<div id="network-view-link">';
26         if(($a->argc > 1 && $a->argv[1] === 'new') || ($a->argc > 2 && $a->argv[2] === 'new') || x($_GET,'search'))
27                 $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : '') . '">' . t('View Conversations') . '</a></div>';
28         else { 
29                 $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . $a->cmd . '/new' . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '">' . t('View New Items') . '</a></div>';
30
31                 if(x($_GET,'star'))
32                         $a->page['aside'] .= '<div id="network-star-link">'
33                                 . '<a class="network-star" href="' . $a->get_baseurl() . '/' . $a->cmd 
34                                 . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '">' 
35                                 . t('View Any Items') . '</a>' 
36                                 . '<span class="network-star icon starred"></span>' 
37                                 . '<span class="network-star icon unstarred"></span>' 
38                                 . '<div class="clear"></div></div>';
39                 else
40                         $a->page['aside'] .= '<div id="network-star-link">'
41                                 . '<a class="network-star" href="' . $a->get_baseurl() . '/' . $a->cmd 
42                                 . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '&star=1" >' 
43                                 . t('View Starred Items') . '</a>'
44                                 . '<span class="network-star icon starred"></span>' 
45                                 . '<div class="clear"></div></div>';
46
47         }
48
49         $a->page['aside'] .= '</div>';
50
51         $a->page['aside'] .= group_side('network','network',true,$group_id);
52 }
53
54
55 function network_content(&$a, $update = 0) {
56
57         require_once('include/conversation.php');
58
59         if(! local_user())
60         return login(false);
61
62         $o = '';
63
64         $contact_id = $a->cid;
65
66         $group = 0;
67
68         $nouveau = false;
69         require_once('include/acl_selectors.php');
70
71         $cid = ((x($_GET['cid'])) ? intval($_GET['cid']) : 0);
72         $star = ((x($_GET['star'])) ? intval($_GET['star']) : 0);
73
74         if(($a->argc > 2) && $a->argv[2] === 'new')
75                 $nouveau = true;
76
77         if($a->argc > 1) {
78                 if($a->argv[1] === 'new')
79                         $nouveau = true;
80                 else {
81                         $group = intval($a->argv[1]);
82                         $def_acl = array('allow_gid' => '<' . $group . '>');
83                 }
84         }
85
86         if(x($_GET,'search'))
87                 $nouveau = true;
88         if($cid)
89                 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
90
91         if(! $update) {
92                 if(group) {
93                         if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
94                                 notice( sprintf( tt('Warning: This group contains %s member from an insecure network.',
95                                                                         'Warning: This group contains %s members from an insecure network.',
96                                                                         $t), $t ) . EOL);
97                                 notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
98                         }
99                 }
100
101                 $o .= '<script> $(document).ready(function() { $(\'#nav-network-link\').addClass(\'nav-selected\'); });</script>';
102
103                 $_SESSION['return_url'] = $a->cmd;
104
105                 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
106
107                 $x = array(
108                         'is_owner' => true,
109                         'allow_location' => $a->user['allow_location'],
110                         'default_location' => $a->user['default_location'],
111                         'nickname' => $a->user['nickname'],
112                         'lockstate' => ((($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']))))) ? 'lock' : 'unlock'),
113                         'acl' => populate_acl((($group || $cid) ? $def_acl : $a->user), $celeb),
114                         'bang' => (($group || $cid) ? '!' : ''),
115                         'visitor' => 'block',
116                         'profile_uid' => local_user()
117                 );
118
119                 $o .= status_editor($a,$x);
120
121                 // The special div is needed for liveUpdate to kick in for this page.
122                 // We only launch liveUpdate if you are on the front page, you aren't
123                 // filtering by group and also you aren't writing a comment (the last
124                 // criteria is discovered in javascript).
125
126                         $o .= '<div id="live-network"></div>' . "\r\n";
127                         $o .= "<script> var profile_uid = " . $_SESSION['uid'] 
128                                 . "; var netargs = '" . substr($a->cmd,8)
129                                 . '?f='
130                                 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
131                                 . ((x($_GET,'search')) ? '&search=' . $_GET['search'] : '') 
132                                 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '') 
133                                 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
134
135         }
136
137         // We aren't going to try and figure out at the item, group, and page
138         // level which items you've seen and which you haven't. If you're looking
139         // at the top level network page just mark everything seen. 
140         
141         if((! $group) && (! $cid) && (! $star)) {
142                 $r = q("UPDATE `item` SET `unseen` = 0 
143                         WHERE `unseen` = 1 AND `uid` = %d",
144                         intval($_SESSION['uid'])
145                 );
146         }
147
148         // We don't have to deal with ACL's on this page. You're looking at everything
149         // that belongs to you, hence you can see all of it. We will filter by group if
150         // desired. 
151
152         $star_sql = (($star) ?  " AND `starred` = 1 " : '');
153
154         $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $star_sql ) ";
155
156         if($group) {
157                 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
158                         intval($group),
159                         intval($_SESSION['uid'])
160                 );
161                 if(! count($r)) {
162                         if($update)
163                                 killme();
164                         notice( t('No such group') . EOL );
165                         goaway($a->get_baseurl() . '/network');
166                         // NOTREACHED
167                 }
168
169                 $contacts = expand_groups(array($group));
170                 if((is_array($contacts)) && count($contacts)) {
171                         $contact_str = implode(',',$contacts);
172                 }
173                 else {
174                                 $contact_str = ' 0 ';
175                                 info( t('Group is empty'));
176                 }
177
178
179                 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $star_sql AND ( `contact-id` IN ( $contact_str ) OR `allow_gid` REGEXP '<" . intval($group) . ">' )) ";
180                 $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
181         }
182         elseif($cid) {
183
184                 $r = q("SELECT `id`,`name`,`network`,`writable` FROM `contact` WHERE `id` = %d 
185                                 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
186                         intval($cid)
187                 );
188                 if(count($r)) {
189                         $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $star_sql AND `contact-id` IN ( " . intval($cid) . " )) ";
190                         $o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o;
191                         if($r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_FACEBOOK && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
192                                 notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
193                         }
194
195                 }
196                 else {
197                         notice( t('Invalid contact.') . EOL);
198                         goaway($a->get_baseurl() . '/network');
199                         // NOTREACHED
200                 }
201         }
202
203         if((! $group) && (! $cid) && (! $update))
204                 $o .= get_birthdays();
205
206         $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
207
208         if(x($_GET,'search'))
209                 $sql_extra .= " AND `item`.`body` REGEXP '" . dbesc(escape_tags($_GET['search'])) . "' ";
210
211         
212         $r = q("SELECT COUNT(*) AS `total`
213                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
214                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
215                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
216                 $sql_extra2
217                 $sql_extra ",
218                 intval($_SESSION['uid'])
219         );
220
221         if(count($r)) {
222                 $a->set_pager_total($r[0]['total']);
223                 $a->set_pager_itemspage(40);
224         }
225
226
227         if($nouveau) {
228
229                 // "New Item View" - show all items unthreaded in reverse created date order
230
231                 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
232                         `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
233                         `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
234                         `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
235                         FROM `item`, `contact`
236                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
237                         AND `contact`.`id` = `item`.`contact-id`
238                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
239                         $sql_extra
240                         ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
241                         intval($_SESSION['uid']),
242                         intval($a->pager['start']),
243                         intval($a->pager['itemspage'])
244                 );
245                 
246         }
247         else {
248
249                 // Normal conversation view
250                 // First fetch a known number of parent items
251
252                 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
253                         FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
254                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
255                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
256                         AND `item`.`parent` = `item`.`id`
257                         $sql_extra
258                         ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
259                         intval(local_user()),
260                         intval($a->pager['start']),
261                         intval($a->pager['itemspage'])
262                 );
263
264
265                 // Then fetch all the children of the parents that are on this page
266
267                 $parents_arr = array();
268                 $parents_str = '';
269
270                 if(count($r)) {
271                         foreach($r as $rr)
272                                 $parents_arr[] = $rr['item_id'];
273                         $parents_str = implode(', ', $parents_arr);
274
275                         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
276                                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
277                                 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
278                                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
279                                 FROM `item`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact`
280                                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
281                                 AND `contact`.`id` = `item`.`contact-id`
282                                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
283                                 AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
284                                 $sql_extra
285                                 ORDER BY `parentitem`.`created`  DESC, `item`.`gravity` ASC, `item`.`created` ASC ",
286                                 intval(local_user()),
287                                 dbesc($parents_str)
288                         );
289                 }
290         }
291
292         // Set this so that the conversation function can find out contact info for our wall-wall items
293         $a->page_contact = $a->contact;
294
295         $mode = (($nouveau) ? 'network-new' : 'network');
296
297         $o .= conversation($a,$r,$mode,$update);
298
299         if(! $update) {
300
301                 $o .= paginate($a);
302                 $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>';
303         }
304
305         return $o;
306 }