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",
47 // search terms header
48 if(x($_GET,'search')) {
49 $a->page['content'] .= '<h2>Search Results For: ' . $search . '</h2>';
52 $a->page['aside'] .= group_side('network','network',true,$group_id);
54 // moved to saved searches to have it in the same div
55 //$a->page['aside'] .= search($search,'netsearch-box',$srchurl,true);
57 $a->page['aside'] .= saved_searches($search);
61 function saved_searches($search) {
64 . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : '')
65 . ((x($_GET,'star')) ? '?star=' . $_GET['star'] : '')
66 . ((x($_GET,'bmark')) ? '?bmark=' . $_GET['bmark'] : '');
70 $r = q("select `term` from `search` WHERE `uid` = %d",
74 $o .= '<div id="saved-search-list" class="widget">';
75 $o .= '<h3 id="search">' . t('Saved Searches') . '</h3>' . "\r\n";
76 $o .= search($search,'netsearch-box',$srchurl,true);
79 $o .= '<ul id="saved-search-ul">' . "\r\n";
81 $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";
86 $o .= '<div class="clear"></div>';
88 $o .= '</div>' . "\r\n";
94 function network_content(&$a, $update = 0) {
96 require_once('include/conversation.php');
104 // TODO: fix this logic, reduce duplication
105 $a->page['content'] .= '<div class="tabs-wrapper">';
107 $starred_active = '';
109 $bookmarked_active = '';
113 if(($a->argc > 1 && $a->argv[1] === 'new')
114 || ($a->argc > 2 && $a->argv[2] === 'new')) {
115 $new_active = 'active';
118 if(x($_GET,'search')) {
119 $search_active = 'active';
122 if(x($_GET,'star')) {
123 $starred_active = 'active';
127 $bookmarked_active = 'active';
130 if (($new_active == '')
131 && ($starred_active == '')
132 && ($bookmarked_active == '')
133 && ($search_active == '')) {
134 $all_active = 'active';
141 'url'=>$a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : ''),
146 'url' => $a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . '/new' . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : ''),
147 'sel' => $new_active,
150 'label' => t('Starred'),
151 'url'=>$a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '&star=1',
152 'sel'=>$starred_active,
155 'label' => t('Bookmarks'),
156 'url'=>$a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '&bmark=1',
157 'sel'=>$bookmarked_active,
160 $tpl = get_markup_template('common_tabs.tpl');
161 $o .= replace_macros($tpl, array('$tabs'=>$tabs));
162 // --- end item filter tabs
168 $contact_id = $a->cid;
173 require_once('include/acl_selectors.php');
175 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
176 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
177 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
178 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
179 $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0);
182 if(($a->argc > 2) && $a->argv[2] === 'new')
186 if($a->argv[1] === 'new')
189 $group = intval($a->argv[1]);
190 $def_acl = array('allow_gid' => '<' . $group . '>');
194 if(x($_GET,'search'))
197 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
201 if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
202 notice( sprintf( tt('Warning: This group contains %s member from an insecure network.',
203 'Warning: This group contains %s members from an insecure network.',
205 notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
209 nav_set_selected('network');
211 $_SESSION['return_url'] = $a->cmd;
213 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
217 'allow_location' => $a->user['allow_location'],
218 'default_location' => $a->user['default_location'],
219 'nickname' => $a->user['nickname'],
220 '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'),
221 'acl' => populate_acl((($group || $cid) ? $def_acl : $a->user), $celeb),
222 'bang' => (($group || $cid) ? '!' : ''),
223 'visitor' => 'block',
224 'profile_uid' => local_user()
227 $o .= status_editor($a,$x);
229 // The special div is needed for liveUpdate to kick in for this page.
230 // We only launch liveUpdate if you are on the front page, you aren't
231 // filtering by group and also you aren't writing a comment (the last
232 // criteria is discovered in javascript).
234 $o .= '<div id="live-network"></div>' . "\r\n";
235 $o .= "<script> var profile_uid = " . $_SESSION['uid']
236 . "; var netargs = '" . substr($a->cmd,8)
238 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
239 . ((x($_GET,'search')) ? '&search=' . $_GET['search'] : '')
240 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
241 . ((x($_GET,'order')) ? '&order=' . $_GET['order'] : '')
242 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
243 . ((x($_GET,'liked')) ? '&liked=' . $_GET['liked'] : '')
244 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
248 // We aren't going to try and figure out at the item, group, and page
249 // level which items you've seen and which you haven't. If you're looking
250 // at the top level network page just mark everything seen.
252 if((! $group) && (! $cid) && (! $star)) {
253 $r = q("UPDATE `item` SET `unseen` = 0
254 WHERE `unseen` = 1 AND `uid` = %d",
255 intval($_SESSION['uid'])
259 // We don't have to deal with ACL's on this page. You're looking at everything
260 // that belongs to you, hence you can see all of it. We will filter by group if
263 $star_sql = (($star) ? " AND `starred` = 1 " : '');
266 $star_sql .= " AND `bookmark` = 1 ";
268 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $star_sql ) ";
271 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
273 intval($_SESSION['uid'])
278 notice( t('No such group') . EOL );
279 goaway($a->get_baseurl() . '/network');
283 $contacts = expand_groups(array($group));
284 if((is_array($contacts)) && count($contacts)) {
285 $contact_str = implode(',',$contacts);
288 $contact_str = ' 0 ';
289 info( t('Group is empty'));
293 $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) . ">' )) ";
294 $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
298 $r = q("SELECT `id`,`name`,`network`,`writable` FROM `contact` WHERE `id` = %d
299 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
303 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $star_sql AND `contact-id` IN ( " . intval($cid) . " )) ";
304 $o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o;
305 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'))) {
306 notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
311 notice( t('Invalid contact.') . EOL);
312 goaway($a->get_baseurl() . '/network');
317 if((! $group) && (! $cid) && (! $update))
318 $o .= get_birthdays();
320 $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
322 if(x($_GET,'search'))
323 $sql_extra .= " AND `item`.`body` REGEXP '" . dbesc(escape_tags($_GET['search'])) . "' ";
326 $r = q("SELECT COUNT(*) AS `total`
327 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
328 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
329 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
332 intval($_SESSION['uid'])
336 $a->set_pager_total($r[0]['total']);
337 $a->set_pager_itemspage(40);
343 // "New Item View" - show all items unthreaded in reverse created date order
345 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
346 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
347 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
348 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
349 FROM `item`, `contact`
350 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
351 AND `contact`.`id` = `item`.`contact-id`
352 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
354 ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
355 intval($_SESSION['uid']),
356 intval($a->pager['start']),
357 intval($a->pager['itemspage'])
363 // Normal conversation view
366 if($order === 'post')
367 $ordering = "`created`";
369 $ordering = "`commented`";
371 // Fetch a page full of parent items for this page
373 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
374 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
375 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
376 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
377 AND `item`.`parent` = `item`.`id`
379 ORDER BY `item`.$ordering DESC LIMIT %d ,%d ",
380 intval(local_user()),
381 intval($a->pager['start']),
382 intval($a->pager['itemspage'])
385 // Then fetch all the children of the parents that are on this page
387 $parents_arr = array();
392 $parents_arr[] = $rr['item_id'];
393 $parents_str = implode(', ', $parents_arr);
395 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
396 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
397 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
398 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
399 FROM `item`, (SELECT `p`.`id`,`p`.`created`,`p`.`commented` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact`
400 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
401 AND `contact`.`id` = `item`.`contact-id`
402 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
403 AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
405 ORDER BY `parentitem`.$ordering DESC, `parentitem`.`id` ASC, `item`.`gravity` ASC, `item`.`created` ASC ",
406 intval(local_user()),
412 // Set this so that the conversation function can find out contact info for our wall-wall items
413 $a->page_contact = $a->contact;
415 $mode = (($nouveau) ? 'network-new' : 'network');
417 $o .= conversation($a,$r,$mode,$update);