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 require_once('include/contact_widgets.php');
15 if(! x($a->page,'aside'))
16 $a->page['aside'] = '';
18 $search = ((x($_GET,'search')) ? escape_tags($_GET['search']) : '');
21 $r = q("select * from `search` where `uid` = %d and `term` = '%s' limit 1",
26 q("insert into `search` ( `uid`,`term` ) values ( %d, '%s') ",
32 if(x($_GET,'remove')) {
33 q("delete from `search` where `uid` = %d and `term` = '%s' limit 1",
41 // search terms header
42 if(x($_GET,'search')) {
43 $a->page['content'] .= '<h2>' . t('Search Results For:') . ' ' . $search . '</h2>';
46 $a->page['aside'] .= group_side('network','network',true,$group_id);
47 $a->page['aside'] .= networks_widget($a->get_baseurl(true) . '/network',(x($_GET, 'nets') ? $_GET['nets'] : ''));
48 $a->page['aside'] .= saved_searches($search);
49 $a->page['aside'] .= fileas_widget($a->get_baseurl(true) . '/network',(x($_GET, 'file') ? $_GET['file'] : ''));
53 function saved_searches($search) {
57 $srchurl = '/network?f='
58 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
59 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
60 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
61 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
62 . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
63 . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
64 . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
65 . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '');
70 $r = q("select `id`,`term` from `search` WHERE `uid` = %d",
80 'term' => $rr['term'],
81 'encodedterm' => urlencode($rr['term']),
82 'delete' => t('Remove term'),
83 'selected' => ($search==$rr['term']),
89 $tpl = get_markup_template("saved_searches_aside.tpl");
90 $o = replace_macros($tpl, array(
91 '$title' => t('Saved Searches'),
93 '$searchbox' => search($search,'netsearch-box',$srchurl,true),
102 function network_content(&$a, $update = 0) {
104 require_once('include/conversation.php');
107 $_SESSION['return_url'] = $a->query_string;
114 // TODO: fix this logic, reduce duplication
115 //$a->page['content'] .= '<div class="tabs-wrapper">';
117 $starred_active = '';
119 $bookmarked_active = '';
125 if(($a->argc > 1 && $a->argv[1] === 'new')
126 || ($a->argc > 2 && $a->argv[2] === 'new')) {
127 $new_active = 'active';
130 if(x($_GET,'search')) {
131 $search_active = 'active';
134 if(x($_GET,'star')) {
135 $starred_active = 'active';
138 if(x($_GET,'bmark')) {
139 $bookmarked_active = 'active';
142 if(x($_GET,'conv')) {
143 $conv_active = 'active';
146 if(x($_GET,'spam')) {
147 $spam_active = 'active';
151 if (($new_active == '')
152 && ($starred_active == '')
153 && ($bookmarked_active == '')
154 && ($conv_active == '')
155 && ($search_active == '')
156 && ($spam_active == '')) {
157 $all_active = 'active';
161 $postord_active = '';
163 if($all_active && x($_GET,'order') && $_GET['order'] !== 'comment') {
165 $postord_active = 'active';
171 'label' => t('Commented Order'),
172 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '?f=&cid=' . $_GET['cid'] : ''),
176 'label' => t('Posted Order'),
177 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
178 'sel'=>$postord_active,
182 'label' => t('Personal'),
183 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&conv=1',
184 'sel' => $conv_active,
188 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . '/new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
189 'sel' => $new_active,
192 'label' => t('Starred'),
193 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&star=1',
194 'sel'=>$starred_active,
197 'label' => t('Shared Links'),
198 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&bmark=1',
199 'sel'=>$bookmarked_active,
202 // 'label' => t('Spam'),
203 // 'url'=>$a->get_baseurl(true) . '/network?f=&spam=1'
204 // 'sel'=> $spam_active,
209 $tpl = get_markup_template('common_tabs.tpl');
210 $o .= replace_macros($tpl, array('$tabs'=>$tabs));
211 // --- end item filter tabs
217 $contact_id = $a->cid;
222 require_once('include/acl_selectors.php');
224 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
225 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
226 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
227 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
228 $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0);
229 $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
230 $spam = ((x($_GET,'spam')) ? intval($_GET['spam']) : 0);
231 $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
232 $cmin = ((x($_GET,'cmin')) ? intval($_GET['cmin']) : 0);
233 $cmax = ((x($_GET,'cmax')) ? intval($_GET['cmax']) : 99);
234 $file = ((x($_GET,'file')) ? $_GET['file'] : '');
236 if(($a->argc > 2) && $a->argv[2] === 'new')
240 if($a->argv[1] === 'new')
243 $group = intval($a->argv[1]);
244 $def_acl = array('allow_gid' => '<' . $group . '>');
248 if(x($_GET,'search') || x($_GET,'file'))
251 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
255 if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
256 notice( sprintf( tt('Warning: This group contains %s member from an insecure network.',
257 'Warning: This group contains %s members from an insecure network.',
259 notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
263 nav_set_selected('network');
265 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
269 'allow_location' => $a->user['allow_location'],
270 'default_location' => $a->user['default-location'],
271 'nickname' => $a->user['nickname'],
272 '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'),
273 'acl' => populate_acl((($group || $cid) ? $def_acl : $a->user), $celeb),
274 'bang' => (($group || $cid) ? '!' : ''),
275 'visitor' => 'block',
276 'profile_uid' => local_user()
279 $o .= status_editor($a,$x);
284 // We don't have to deal with ACL's on this page. You're looking at everything
285 // that belongs to you, hence you can see all of it. We will filter by group if
289 $sql_options = (($star) ? " and starred = 1 " : '');
290 $sql_options .= (($bmark) ? " and bookmark = 1 " : '');
292 $sql_nets = (($nets) ? sprintf(" and `contact`.`network` = '%s' ", dbesc($nets)) : '');
294 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $sql_options ) ";
297 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
299 intval($_SESSION['uid'])
304 notice( t('No such group') . EOL );
305 goaway($a->get_baseurl(true) . '/network');
309 $contacts = expand_groups(array($group));
310 if((is_array($contacts)) && count($contacts)) {
311 $contact_str = implode(',',$contacts);
314 $contact_str = ' 0 ';
315 info( t('Group is empty'));
318 $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND ( `contact-id` IN ( $contact_str ) OR `allow_gid` REGEXP '<" . intval($group) . ">' ) and deleted = 0 ) ";
319 $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
323 $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d
324 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
328 $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND `contact-id` = " . intval($cid) . " and deleted = 0 ) ";
329 $o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o;
330 if($r[0]['network'] === NETWORK_OSTATUS && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
331 notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
336 notice( t('Invalid contact.') . EOL);
337 goaway($a->get_baseurl(true) . '/network');
342 if((! $group) && (! $cid) && (! $update)) {
343 $o .= get_birthdays();
348 // The special div is needed for liveUpdate to kick in for this page.
349 // We only launch liveUpdate if you aren't filtering in some incompatible
350 // way and also you aren't writing a comment (discovered in javascript).
352 $o .= '<div id="live-network"></div>' . "\r\n";
353 $o .= "<script> var profile_uid = " . $_SESSION['uid']
354 . "; var netargs = '" . substr($a->cmd,8)
356 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
357 . ((x($_GET,'search')) ? '&search=' . $_GET['search'] : '')
358 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
359 . ((x($_GET,'order')) ? '&order=' . $_GET['order'] : '')
360 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
361 . ((x($_GET,'liked')) ? '&liked=' . $_GET['liked'] : '')
362 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
363 . ((x($_GET,'spam')) ? '&spam=' . $_GET['spam'] : '')
364 . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
365 . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
366 . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
367 . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '')
369 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
372 $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
374 if(x($_GET,'search')) {
375 $search = escape_tags($_GET['search']);
376 $sql_extra .= sprintf(" AND ( `item`.`body` REGEXP '%s' OR `item`.`tag` REGEXP '%s' ) ",
377 dbesc(preg_quote($search)),
378 dbesc('\\]' . preg_quote($search) . '\\[')
382 $sql_extra .= file_tag_file_query('item',$file);
386 $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
387 $myurl = substr($myurl,strpos($myurl,'://')+3);
388 $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
389 $diasp_url = str_replace('/profile/','/u/',$myurl);
390 $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where ( `author-link` regexp '%s' or `tag` regexp '%s' or tag regexp '%s' )) ",
392 dbesc($myurl . '\\]'),
393 dbesc($diasp_url . '\\]')
400 // only setup pagination on initial page view
405 $r = q("SELECT COUNT(*) AS `total`
406 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
407 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
408 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
410 $sql_extra $sql_nets ",
411 intval($_SESSION['uid'])
415 $a->set_pager_total($r[0]['total']);
416 $itemspage_network = get_pconfig(local_user(),'system','itemspage_network');
417 $a->set_pager_itemspage(((intval($itemspage_network)) ? $itemspage_network : 40));
419 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
422 $simple_update = (($update) ? " and `item`.`unseen` = 1 " : '');
425 // "New Item View" - show all items unthreaded in reverse created date order
427 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
428 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
429 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
430 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
431 FROM `item`, `contact`
432 WHERE `item`.`uid` = %d AND `item`.`visible` = 1
433 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
435 AND `contact`.`id` = `item`.`contact-id`
436 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
438 ORDER BY `item`.`received` DESC $pager_sql ",
439 intval($_SESSION['uid'])
445 // Normal conversation view
448 if($order === 'post')
449 $ordering = "`created`";
451 $ordering = "`commented`";
453 // Fetch a page full of parent items for this page
456 $r = q("SELECT `parent` AS `item_id`, `contact`.`uid` AS `contact_uid`
457 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
458 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
459 and `item`.`moderated` = 0 and `item`.`unseen` = 1
460 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
461 $sql_extra $sql_nets ",
466 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
467 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
468 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
469 AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
470 AND `item`.`parent` = `item`.`id`
472 ORDER BY `item`.$ordering DESC $pager_sql ",
477 // Then fetch all the children of the parents that are on this page
479 $parents_arr = array();
484 if(! in_array($rr['item_id'],$parents_arr))
485 $parents_arr[] = $rr['item_id'];
486 $parents_str = implode(', ', $parents_arr);
488 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
489 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
490 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
491 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
492 FROM `item`, `contact`
493 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
494 AND `item`.`moderated` = 0 AND `contact`.`id` = `item`.`contact-id`
495 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
496 AND `item`.`parent` IN ( %s )
498 intval(local_user()),
502 $items = conv_sort($items,$ordering);
510 // We aren't going to try and figure out at the item, group, and page
511 // level which items you've seen and which you haven't. If you're looking
512 // at the top level network page just mark everything seen.
514 if((! $group) && (! $cid) && (! $star)) {
515 $r = q("UPDATE `item` SET `unseen` = 0
516 WHERE `unseen` = 1 AND `uid` = %d",
521 // Set this so that the conversation function can find out contact info for our wall-wall items
522 $a->page_contact = $a->contact;
524 $mode = (($nouveau) ? 'network-new' : 'network');
526 $o .= conversation($a,$items,$mode,$update);