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