4 function network_init(&$a) {
6 notice( t('Permission denied.') . EOL);
10 $group_id = (($a->argc > 1 && intval($a->argv[1])) ? intval($a->argv[1]) : 0);
12 require_once('include/group.php');
13 if(! x($a->page,'aside'))
14 $a->page['aside'] = '';
16 $search = ((x($_GET,'search')) ? escape_tags($_GET['search']) : '');
18 // We need a better way of managing a growing argument list
20 // moved into savedsearches()
21 // $srchurl = '/network'
22 // . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : '')
23 // . ((x($_GET,'star')) ? '?star=' . $_GET['star'] : '')
24 // . ((x($_GET,'bmark')) ? '?bmark=' . $_GET['bmark'] : '');
27 $r = q("select * from `search` where `uid` = %d and `term` = '%s' limit 1",
32 q("insert into `search` ( `uid`,`term` ) values ( %d, '%s') ",
38 if(x($_GET,'remove')) {
39 q("delete from `search` where `uid` = %d and `term` = '%s' limit 1",
46 // TODO: fix this logic, reduce duplication
47 $a->page['content'] .= '<div class="tabs-wrapper">';
51 $bookmarked_active = '';
55 if(($a->argc > 1 && $a->argv[1] === 'new')
56 || ($a->argc > 2 && $a->argv[2] === 'new')) {
57 $new_active = 'active';
60 if(x($_GET,'search')) {
61 $search_active = 'active';
65 $starred_active = 'active';
69 $bookmarked_active = 'active';
72 if (($new_active == '')
73 && ($starred_active == '')
74 && ($bookmarked_active == '')
75 && ($search_active == '')) {
76 $all_active = 'active';
79 // network links moved to content to match other pages
81 // added 'button' class for easier styling - not the best place for it, should be moved into the tpl like profile_tabs.tpl
82 // once there is a network_tabs.tpl or something
83 $a->page['content'] .= '<a class="button tabs ' . $all_active . '" href="' . $a->get_baseurl() . '/'
84 . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : '') . '">'
88 $a->page['content'] .= '<a class="button tabs ' . $new_active . '" href="' . $a->get_baseurl() . '/'
89 . str_replace('/new', '', $a->cmd) . '/new'
90 . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '">'
94 $a->page['content'] .= '<a class="button tabs ' . $starred_active . '" href="' . $a->get_baseurl() . '/'
95 . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '&star=1" >'
96 . t('Starred') . '</a>';
99 $a->page['content'] .= '<a class="button tabs ' . $bookmarked_active . '" href="' . $a->get_baseurl() . '/'
100 . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '&bmark=1" >'
101 . t('Bookmarks') . '</a>';
103 $a->page['content'] .= '</div>';
104 // --- end item filter tabs
106 // search terms header
107 if(x($_GET,'search')) {
108 $a->page['content'] .= '<h2>Search Results For: ' . $search . '</h2>';
111 $a->page['aside'] .= group_side('network','network',true,$group_id);
113 // moved to saved searches to have it in the same div
114 //$a->page['aside'] .= search($search,'netsearch-box',$srchurl,true);
116 $a->page['aside'] .= saved_searches($search);
120 function saved_searches($search) {
122 $srchurl = '/network'
123 . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : '')
124 . ((x($_GET,'star')) ? '?star=' . $_GET['star'] : '')
125 . ((x($_GET,'bmark')) ? '?bmark=' . $_GET['bmark'] : '');
129 $r = q("select `term` from `search` WHERE `uid` = %d",
133 $o .= '<div id="saved-search-list" class="widget">';
134 $o .= '<h3 id="search">' . t('Saved Searches') . '</h3>' . "\r\n";
135 $o .= search($search,'netsearch-box',$srchurl,true);
138 $o .= '<ul id="saved-search-ul">' . "\r\n";
140 $o .= '<li class="saved-search-li clear"><a href="network/?f=&remove=1&search=' . $rr['term'] . '" class="icon drophide savedsearchdrop" title="' . t('Remove term') . '" onclick="return confirmDelete();" onmouseover="imgbright(this);" onmouseout="imgdull(this);" ></a> <a href="network/?f&search=' . urlencode($rr['term']) . '" class="savedsearchterm" >' . $rr['term'] . '</a></li>' . "\r\n";
145 $o .= '</div>' . "\r\n";
151 function network_content(&$a, $update = 0) {
153 require_once('include/conversation.php');
160 $contact_id = $a->cid;
165 require_once('include/acl_selectors.php');
167 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
168 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
169 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
170 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
171 $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0);
174 if(($a->argc > 2) && $a->argv[2] === 'new')
178 if($a->argv[1] === 'new')
181 $group = intval($a->argv[1]);
182 $def_acl = array('allow_gid' => '<' . $group . '>');
186 if(x($_GET,'search'))
189 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
193 if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
194 notice( sprintf( tt('Warning: This group contains %s member from an insecure network.',
195 'Warning: This group contains %s members from an insecure network.',
197 notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
201 nav_set_selected('network');
203 $_SESSION['return_url'] = $a->cmd;
205 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
209 'allow_location' => $a->user['allow_location'],
210 'default_location' => $a->user['default_location'],
211 'nickname' => $a->user['nickname'],
212 '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'),
213 'acl' => populate_acl((($group || $cid) ? $def_acl : $a->user), $celeb),
214 'bang' => (($group || $cid) ? '!' : ''),
215 'visitor' => 'block',
216 'profile_uid' => local_user()
219 $o .= status_editor($a,$x);
221 // The special div is needed for liveUpdate to kick in for this page.
222 // We only launch liveUpdate if you are on the front page, you aren't
223 // filtering by group and also you aren't writing a comment (the last
224 // criteria is discovered in javascript).
226 $o .= '<div id="live-network"></div>' . "\r\n";
227 $o .= "<script> var profile_uid = " . $_SESSION['uid']
228 . "; var netargs = '" . substr($a->cmd,8)
230 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
231 . ((x($_GET,'search')) ? '&search=' . $_GET['search'] : '')
232 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
233 . ((x($_GET,'order')) ? '&order=' . $_GET['order'] : '')
234 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
235 . ((x($_GET,'liked')) ? '&liked=' . $_GET['liked'] : '')
236 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
240 // We aren't going to try and figure out at the item, group, and page
241 // level which items you've seen and which you haven't. If you're looking
242 // at the top level network page just mark everything seen.
244 if((! $group) && (! $cid) && (! $star)) {
245 $r = q("UPDATE `item` SET `unseen` = 0
246 WHERE `unseen` = 1 AND `uid` = %d",
247 intval($_SESSION['uid'])
251 // We don't have to deal with ACL's on this page. You're looking at everything
252 // that belongs to you, hence you can see all of it. We will filter by group if
255 $star_sql = (($star) ? " AND `starred` = 1 " : '');
258 $star_sql .= " AND `bookmark` = 1 ";
260 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $star_sql ) ";
263 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
265 intval($_SESSION['uid'])
270 notice( t('No such group') . EOL );
271 goaway($a->get_baseurl() . '/network');
275 $contacts = expand_groups(array($group));
276 if((is_array($contacts)) && count($contacts)) {
277 $contact_str = implode(',',$contacts);
280 $contact_str = ' 0 ';
281 info( t('Group is empty'));
285 $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) . ">' )) ";
286 $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
290 $r = q("SELECT `id`,`name`,`network`,`writable` FROM `contact` WHERE `id` = %d
291 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
295 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $star_sql AND `contact-id` IN ( " . intval($cid) . " )) ";
296 $o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o;
297 if($r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_FACEBOOK && $r[0]['network'] !== NETWORK_DIASPORA && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
298 notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
303 notice( t('Invalid contact.') . EOL);
304 goaway($a->get_baseurl() . '/network');
309 if((! $group) && (! $cid) && (! $update))
310 $o .= get_birthdays();
312 $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
314 if(x($_GET,'search'))
315 $sql_extra .= " AND `item`.`body` REGEXP '" . dbesc(escape_tags($_GET['search'])) . "' ";
318 $r = q("SELECT COUNT(*) AS `total`
319 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
320 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
321 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
324 intval($_SESSION['uid'])
328 $a->set_pager_total($r[0]['total']);
329 $a->set_pager_itemspage(40);
335 // "New Item View" - show all items unthreaded in reverse created date order
337 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
338 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
339 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
340 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
341 FROM `item`, `contact`
342 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
343 AND `contact`.`id` = `item`.`contact-id`
344 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
346 ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
347 intval($_SESSION['uid']),
348 intval($a->pager['start']),
349 intval($a->pager['itemspage'])
355 // Normal conversation view
358 if($order === 'post')
359 $ordering = "`created`";
361 $ordering = "`commented`";
363 // Fetch a page full of parent items for this page
365 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
366 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
367 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
368 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
369 AND `item`.`parent` = `item`.`id`
371 ORDER BY `item`.$ordering DESC LIMIT %d ,%d ",
372 intval(local_user()),
373 intval($a->pager['start']),
374 intval($a->pager['itemspage'])
377 // Then fetch all the children of the parents that are on this page
379 $parents_arr = array();
384 $parents_arr[] = $rr['item_id'];
385 $parents_str = implode(', ', $parents_arr);
387 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
388 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
389 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
390 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
391 FROM `item`, (SELECT `p`.`id`,`p`.`created`,`p`.`commented` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact`
392 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
393 AND `contact`.`id` = `item`.`contact-id`
394 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
395 AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
397 ORDER BY `parentitem`.$ordering DESC, `parentitem`.`id` ASC, `item`.`gravity` ASC, `item`.`created` ASC ",
398 intval(local_user()),
404 // Set this so that the conversation function can find out contact info for our wall-wall items
405 $a->page_contact = $a->contact;
407 $mode = (($nouveau) ? 'network-new' : 'network');
409 $o .= conversation($a,$r,$mode,$update);