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