]> git.mxchange.org Git - friendica.git/blob - mod/network.php
Merge branch 'fabrixxm-master'
[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                                 notice( sprintf( tt('Warning: This group contains %s member from an insecure network.',
65                                                                         'Warning: This group contains %s members from an insecure network.',
66                                                                         $t), $t ) . EOL);
67                                 notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
68                         }
69                 }
70
71                 $o .= '<script> $(document).ready(function() { $(\'#nav-network-link\').addClass(\'nav-selected\'); });</script>';
72
73                 $_SESSION['return_url'] = $a->cmd;
74
75                 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
76
77                 $x = array(
78                         'is_owner' => true,
79                         'allow_location' => $a->user['allow_location'],
80                         'default_location' => $a->user['default_location'],
81                         'nickname' => $a->user['nickname'],
82                         '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'),
83                         'acl' => populate_acl((($group || $cid) ? $def_acl : $a->user), $celeb),
84                         'bang' => (($group || $cid) ? '!' : ''),
85                         'visitor' => 'block',
86                         'profile_uid' => local_user()
87                 );
88
89                 $o .= status_editor($a,$x);
90
91                 // The special div is needed for liveUpdate to kick in for this page.
92                 // We only launch liveUpdate if you are on the front page, you aren't
93                 // filtering by group and also you aren't writing a comment (the last
94                 // criteria is discovered in javascript).
95
96                         $o .= '<div id="live-network"></div>' . "\r\n";
97                         $o .= "<script> var profile_uid = " . $_SESSION['uid'] 
98                                 . "; var netargs = '" . substr($a->cmd,8) 
99                                 . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '')
100                                 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
101
102         }
103
104         // We aren't going to try and figure out at the item, group, and page
105         // level which items you've seen and which you haven't. If you're looking
106         // at the top level network page just mark everything seen. 
107         
108         if((! $group) && (! $cid)) {
109                 $r = q("UPDATE `item` SET `unseen` = 0 
110                         WHERE `unseen` = 1 AND `uid` = %d",
111                         intval($_SESSION['uid'])
112                 );
113         }
114
115         // We don't have to deal with ACL's on this page. You're looking at everything
116         // that belongs to you, hence you can see all of it. We will filter by group if
117         // desired. 
118
119         $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
120
121         if($group) {
122                 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
123                         intval($group),
124                         intval($_SESSION['uid'])
125                 );
126                 if(! count($r)) {
127                         if($update)
128                                 killme();
129                         notice( t('No such group') . EOL );
130                         goaway($a->get_baseurl() . '/network');
131                         // NOTREACHED
132                 }
133
134                 $contacts = expand_groups(array($group));
135                 if((is_array($contacts)) && count($contacts)) {
136                         $contact_str = implode(',',$contacts);
137                 }
138                 else {
139                                 $contact_str = ' 0 ';
140                                 info( t('Group is empty'));
141                 }
142
143                 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND ( `contact-id` IN ( $contact_str ) OR `allow_gid` REGEXP '<" . intval($group) . ">' )) ";
144                 $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
145         }
146         elseif($cid) {
147
148                 $r = q("SELECT `id`,`name`,`network`,`writable` FROM `contact` WHERE `id` = %d 
149                                 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
150                         intval($cid)
151                 );
152                 if(count($r)) {
153                         $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `contact-id` IN ( " . intval($cid) . " )) ";
154                         $o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o;
155                         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'))) {
156                                 notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
157                         }
158
159                 }
160                 else {
161                         notice( t('Invalid contact.') . EOL);
162                         goaway($a->get_baseurl() . '/network');
163                         // NOTREACHED
164                 }
165         }
166
167         if((! $group) && (! $cid) && (! $update))
168                 $o .= get_birthdays();
169
170         $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
171
172         $r = q("SELECT COUNT(*) AS `total`
173                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
174                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
175                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
176                 $sql_extra2
177                 $sql_extra ",
178                 intval($_SESSION['uid'])
179         );
180
181         if(count($r)) {
182                 $a->set_pager_total($r[0]['total']);
183                 $a->set_pager_itemspage(40);
184         }
185
186
187         if($nouveau) {
188
189                 // "New Item View" - show all items unthreaded in reverse created date order
190
191                 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
192                         `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
193                         `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
194                         `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
195                         FROM `item`, `contact`
196                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
197                         AND `contact`.`id` = `item`.`contact-id`
198                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
199                         $sql_extra
200                         ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
201                         intval($_SESSION['uid']),
202                         intval($a->pager['start']),
203                         intval($a->pager['itemspage'])
204                 );
205                 
206         }
207         else {
208
209                 // Normal conversation view
210                 // First fetch a known number of parent items
211
212                 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
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                         AND `item`.`parent` = `item`.`id`
217                         $sql_extra
218                         ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
219                         intval(local_user()),
220                         intval($a->pager['start']),
221                         intval($a->pager['itemspage'])
222                 );
223
224
225                 // Then fetch all the children of the parents that are on this page
226
227                 $parents_arr = array();
228                 $parents_str = '';
229
230                 if(count($r)) {
231                         foreach($r as $rr)
232                                 $parents_arr[] = $rr['item_id'];
233                         $parents_str = implode(', ', $parents_arr);
234
235                         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
236                                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
237                                 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
238                                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
239                                 FROM `item`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact`
240                                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
241                                 AND `contact`.`id` = `item`.`contact-id`
242                                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
243                                 AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
244                                 $sql_extra
245                                 ORDER BY `parentitem`.`created`  DESC, `item`.`gravity` ASC, `item`.`created` ASC ",
246                                 intval(local_user()),
247                                 dbesc($parents_str)
248                         );
249                 }
250         }
251
252         // Set this so that the conversation function can find out contact info for our wall-wall items
253         $a->page_contact = $a->contact;
254
255         $mode = (($nouveau) ? 'network-new' : 'network');
256
257         $o .= conversation($a,$r,$mode,$update);
258
259         if(! $update) {
260
261                 $o .= paginate($a);
262                 $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>';
263         }
264
265         return $o;
266 }