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