4 use Friendica\Core\System;
6 function network_init(App $a) {
8 notice( t('Permission denied.') . EOL);
12 $is_a_date_query = false;
13 if (x($_GET, 'cid') && intval($_GET['cid']) != 0) {
18 for ($x = 1; $x < $a->argc; $x ++) {
19 if (is_a_date_arg($a->argv[$x])) {
20 $is_a_date_query = true;
26 // convert query string to array. remove friendica args
27 $query_array = array();
28 $query_string = str_replace($a->cmd."?", "", $a->query_string);
29 parse_str($query_string, $query_array);
30 array_shift($query_array);
32 // fetch last used network view and redirect if needed
33 if (! $is_a_date_query) {
34 $sel_tabs = network_query_get_sel_tab($a);
35 $sel_nets = network_query_get_sel_net();
36 $sel_groups = network_query_get_sel_group($a);
37 $last_sel_tabs = get_pconfig(local_user(), 'network.view','tab.selected');
38 $last_sel_nets = get_pconfig(local_user(), 'network.view', 'net.selected');
39 $last_sel_groups = get_pconfig(local_user(), 'network.view', 'group.selected');
41 $remember_tab = ($sel_tabs[0] === 'active' && is_array($last_sel_tabs) && $last_sel_tabs[0] !== 'active');
42 $remember_net = ($sel_nets === false && $last_sel_nets && $last_sel_nets !== 'all');
43 $remember_group = ($sel_groups === false && $last_sel_groups && $last_sel_groups != 0);
45 $net_baseurl = '/network';
48 if ($remember_group) {
49 $net_baseurl .= '/' . $last_sel_groups; // Note that the group number must come before the "/new" tab selection
50 } elseif($sel_groups !== false) {
51 $net_baseurl .= '/' . $sel_groups;
55 // redirect if current selected tab is '/network' and
56 // last selected tab is _not_ '/network?f=&order=comment'.
57 // and this isn't a date query
59 $tab_baseurls = array(
69 'f=&order=comment', //all
70 'f=&order=post', //postord
73 'f=&star=1', //starred
74 'f=&bmark=1', //bookmarked
78 $k = array_search('active', $last_sel_tabs);
81 $net_baseurl .= $tab_baseurls[$k];
83 // parse out tab queries
85 $dest_qs = $tab_args[$k];
86 parse_str($dest_qs, $dest_qa);
87 $net_args = array_merge($net_args, $dest_qa);
89 $remember_tab = false;
91 } elseif ($sel_tabs[4] === 'active') {
92 // The '/new' tab is selected
93 $remember_group = false;
97 $net_args['nets'] = $last_sel_nets;
99 else if($sel_nets!==false) {
100 $net_args['nets'] = $sel_nets;
103 if($remember_tab || $remember_net || $remember_group) {
104 $net_args = array_merge($query_array, $net_args);
105 $net_queries = build_querystring($net_args);
107 $redir_url = ($net_queries ? $net_baseurl."?".$net_queries : $net_baseurl);
109 goaway(System::baseUrl() . $redir_url);
113 // If nets is set to all, unset it
114 if (x($_GET, 'nets') && $_GET['nets'] === 'all') {
115 unset($_GET['nets']);
118 $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
120 set_pconfig(local_user(), 'network.view', 'group.selected', $group_id);
122 require_once 'include/group.php';
123 require_once 'include/contact_widgets.php';
124 require_once 'include/items.php';
125 require_once 'include/ForumManager.php';
127 if (! x($a->page, 'aside')) {
128 $a->page['aside'] = '';
131 $search = ((x($_GET, 'search')) ? escape_tags($_GET['search']) : '');
133 if (x($_GET, 'save')) {
134 $r = q("SELECT * FROM `search` WHERE `uid` = %d AND `term` = '%s' LIMIT 1",
135 intval(local_user()),
138 if (! dbm::is_result($r)) {
139 q("INSERT INTO `search` ( `uid`,`term` ) VALUES ( %d, '%s') ",
140 intval(local_user()),
145 if (x($_GET, 'remove')) {
146 q("DELETE FROM `search` WHERE `uid` = %d AND `term` = '%s'",
147 intval(local_user()),
152 // search terms header
153 if (x($_GET, 'search')) {
154 $a->page['content'] .= replace_macros(get_markup_template("section_title.tpl"),array(
155 '$title' => sprintf( t('Results for: %s'), $search)
159 $a->page['aside'] .= (feature_enabled(local_user(),'groups') ? group_side('network/0','network','standard',$group_id) : '');
160 $a->page['aside'] .= (feature_enabled(local_user(),'forumlist_widget') ? ForumManager::widget(local_user(),$cid) : '');
161 $a->page['aside'] .= posted_date_widget('network',local_user(),false);
162 $a->page['aside'] .= networks_widget('network',(x($_GET, 'nets') ? $_GET['nets'] : ''));
163 $a->page['aside'] .= saved_searches($search);
164 $a->page['aside'] .= fileas_widget('network',(x($_GET, 'file') ? $_GET['file'] : ''));
168 function saved_searches($search) {
170 if (! feature_enabled(local_user(),'savedsearch')) {
176 $srchurl = '/network?f='
177 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
178 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
179 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
180 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
181 . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
182 . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
183 . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
184 . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '');
189 $r = q("SELECT `id`,`term` FROM `search` WHERE `uid` = %d",
195 if (dbm::is_result($r)) {
196 foreach ($r as $rr) {
199 'term' => $rr['term'],
200 'encodedterm' => urlencode($rr['term']),
201 'delete' => t('Remove term'),
202 'selected' => ($search==$rr['term']),
208 $tpl = get_markup_template("saved_searches_aside.tpl");
209 $o = replace_macros($tpl, array(
210 '$title' => t('Saved Searches'),
212 '$searchbox' => search($search,'netsearch-box',$srchurl,true),
221 * Return selected tab from query
224 * '/network' => $no_active = 'active'
225 * '/network?f=&order=comment' => $comment_active = 'active'
226 * '/network?f=&order=post' => $postord_active = 'active'
227 * '/network?f=&conv=1', => $conv_active = 'active'
228 * '/network/new', => $new_active = 'active'
229 * '/network?f=&star=1', => $starred_active = 'active'
230 * '/network?f=&bmark=1', => $bookmarked_active = 'active'
231 * '/network?f=&spam=1', => $spam_active = 'active'
233 * @return Array ( $no_active, $comment_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active );
235 function network_query_get_sel_tab(App $a) {
237 $starred_active = '';
239 $bookmarked_active = '';
244 $postord_active = '';
246 if(($a->argc > 1 && $a->argv[1] === 'new')
247 || ($a->argc > 2 && $a->argv[2] === 'new')) {
248 $new_active = 'active';
251 if(x($_GET,'search')) {
252 $search_active = 'active';
255 if(x($_GET,'star')) {
256 $starred_active = 'active';
259 if(x($_GET,'bmark')) {
260 $bookmarked_active = 'active';
263 if(x($_GET,'conv')) {
264 $conv_active = 'active';
267 if(x($_GET,'spam')) {
268 $spam_active = 'active';
273 if (($new_active == '')
274 && ($starred_active == '')
275 && ($bookmarked_active == '')
276 && ($conv_active == '')
277 && ($search_active == '')
278 && ($spam_active == '')) {
279 $no_active = 'active';
282 if ($no_active=='active' && x($_GET,'order')) {
283 switch($_GET['order']){
284 case 'post': $postord_active = 'active'; $no_active=''; break;
285 case 'comment' : $all_active = 'active'; $no_active=''; break;
289 return array($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active);
293 * @brief Return selected network from query
294 * @return string Name of the selected network
296 function network_query_get_sel_net() {
299 if(x($_GET,'nets')) {
300 $network = $_GET['nets'];
306 function network_query_get_sel_group(App $a) {
309 if($a->argc >= 2 && is_numeric($a->argv[1])) {
310 $group = $a->argv[1];
317 function network_content(App $a, $update = 0) {
319 require_once('include/conversation.php');
321 if (! local_user()) {
322 $_SESSION['return_url'] = $a->query_string;
326 // Rawmode is used for fetching new content at the end of the page
327 $rawmode = (isset($_GET["mode"]) AND ($_GET["mode"] == "raw"));
329 if (isset($_GET["last_received"]) && isset($_GET["last_commented"]) && isset($_GET["last_created"]) && isset($_GET["last_id"])) {
330 $last_received = dbm::date($_GET["last_received"]);
331 $last_commented = dbm::date($_GET["last_commented"]);
332 $last_created = dbm::date($_GET["last_created"]);
333 $last_id = intval($_GET["last_id"]);
336 $last_commented = '';
341 /// @TODO Is this really necessary? $a is already available to hooks
342 $arr = array('query' => $a->query_string);
343 call_hooks('network_content_init', $arr);
346 $datequery = $datequery2 = '';
353 for($x = 1; $x < $a->argc; $x ++) {
354 if(is_a_date_arg($a->argv[$x])) {
356 $datequery2 = escape_tags($a->argv[$x]);
358 $datequery = escape_tags($a->argv[$x]);
359 $_GET['order'] = 'post';
362 elseif($a->argv[$x] === 'new') {
365 elseif(intval($a->argv[$x])) {
366 $group = intval($a->argv[$x]);
367 $def_acl = array('allow_gid' => '<' . $group . '>');
376 $contact_id = $a->cid;
378 require_once('include/acl_selectors.php');
380 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
381 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
382 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
383 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
384 $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0);
385 $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
386 $spam = ((x($_GET,'spam')) ? intval($_GET['spam']) : 0);
387 $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
388 $cmin = ((x($_GET,'cmin')) ? intval($_GET['cmin']) : 0);
389 $cmax = ((x($_GET,'cmax')) ? intval($_GET['cmax']) : 99);
390 $file = ((x($_GET,'file')) ? $_GET['file'] : '');
394 if(x($_GET,'search') || x($_GET,'file'))
397 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
400 $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND network = '%s' AND `self` = 0",
401 intval(local_user()),
406 if (dbm::is_result($r))
408 $str .= '<' . $rr['id'] . '>';
410 $def_acl = array('allow_cid' => $str);
412 set_pconfig(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all'));
414 if(!$update && !$rawmode) {
415 $tabs = network_tabs($a);
419 if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
420 notice(sprintf(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.",
421 "Warning: This group contains %s members from a network that doesn't allow non public messages.",
423 notice(t("Messages in this group won't be send to these receivers.").EOL);
427 nav_set_selected('network');
432 // If $cid belongs to a communitity forum or a privat goup,.add a mention to the status editor
433 $contact = q("SELECT `nick` FROM `contact` WHERE `id` = %d AND `uid` = %d AND (`forum` OR `prv`) ",
438 $content = "@".$contact[0]["nick"]."+".$cid;
443 'allow_location' => $a->user['allow_location'],
444 'default_location' => $a->user['default-location'],
445 'nickname' => $a->user['nickname'],
446 'lockstate'=> ((($group) || ($cid) || ($nets) || (is_array($a->user) &&
447 ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) ||
448 (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
449 'default_perms' => get_acl_permissions($a->user),
450 'acl' => populate_acl((($group || $cid || $nets) ? $def_acl : $a->user), true),
451 'bang' => (($group || $cid || $nets) ? '!' : ''),
452 'visitor' => 'block',
453 'profile_uid' => local_user(),
454 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
455 'content' => $content,
458 $o .= status_editor($a,$x);
462 // We don't have to deal with ACLs on this page. You're looking at everything
463 // that belongs to you, hence you can see all of it. We will filter by group if
466 $sql_post_table = "";
467 $sql_options = (($star) ? " AND `thread`.`starred` " : '');
468 $sql_options .= (($bmark) ? " AND `thread`.`bookmark` " : '');
469 $sql_extra = $sql_options;
472 $sql_table = "`thread`";
473 $sql_parent = "`iid`";
475 if ($nouveau || strlen($file) || $update) {
476 $sql_table = "`item`";
477 $sql_parent = "`parent`";
478 $sql_post_table = " INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`";
481 $sql_nets = (($nets) ? sprintf(" and $sql_table.`network` = '%s' ", dbesc($nets)) : '');
484 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
486 intval($_SESSION['uid'])
488 if (! dbm::is_result($r)) {
491 notice( t('No such group') . EOL );
496 $contacts = expand_groups(array($group));
497 $gcontacts = expand_groups(array($group), false, true);
499 if((is_array($contacts)) && count($contacts)) {
500 $contact_str_self = "";
501 $gcontact_str_self = "";
503 $contact_str = implode(',',$contacts);
504 $gcontact_str = implode(',',$gcontacts);
505 $self = q("SELECT `contact`.`id`, `gcontact`.`id` AS `gid` FROM `contact`
506 INNER JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
507 WHERE `uid` = %d AND `self`", intval($_SESSION['uid']));
509 $contact_str_self = $self[0]["id"];
510 $gcontact_str_self = $self[0]["gid"];
513 $sql_post_table .= " INNER JOIN `item` AS `temp1` ON `temp1`.`id` = ".$sql_table.".".$sql_parent;
514 $sql_extra3 .= " AND (`thread`.`contact-id` IN ($contact_str) ";
515 $sql_extra3 .= " OR (`thread`.`contact-id` = '$contact_str_self' AND `temp1`.`allow_gid` LIKE '".protect_sprintf('%<'.intval($group).'>%')."' AND `temp1`.`private`))";
517 $sql_extra3 .= " AND false ";
518 info( t('Group is empty'));
521 $o = replace_macros(get_markup_template("section_title.tpl"),array(
522 '$title' => sprintf( t('Group: %s'), $r[0]['name'])
528 $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl`, `forum`, `prv`, `contact-type`, `addr`, `thumb`, `location` FROM `contact` WHERE `id` = %d
529 AND (NOT `blocked` OR `pending`) LIMIT 1",
532 if (dbm::is_result($r)) {
533 $sql_extra = " AND ".$sql_table.".`contact-id` = ".intval($cid);
537 'name' => htmlentities($r[0]['name']),
538 'itemurl' => (($r[0]['addr']) ? ($r[0]['addr']) : ($r[0]['nurl'])),
539 'thumb' => proxy_url($r[0]['thumb'], false, PROXY_SIZE_THUMB),
540 'details' => $r[0]['location'],
543 $entries[0]["account_type"] = account_type($r[0]);
545 $o = replace_macros(get_markup_template("viewcontact_template.tpl"),array(
546 'contacts' => $entries,
550 if($r[0]['network'] === NETWORK_OSTATUS && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
551 notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
556 notice( t('Invalid contact.') . EOL);
562 if((! $group) && (! $cid) && (! $update) && (! get_config('theme','hide_eventlist'))) {
563 $o .= get_birthdays();
568 $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
571 $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
574 //$sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
575 $sql_extra2 = (($nouveau) ? '' : $sql_extra2);
576 $sql_extra3 = (($nouveau) ? '' : $sql_extra3);
578 $order_mode = "received";
581 if(x($_GET,'search')) {
582 $search = escape_tags($_GET['search']);
584 if(strpos($search,'#') === 0) {
586 $search = substr($search,1);
589 if (get_config('system','only_tag_search'))
595 $sql_post_table .= sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
596 dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval(local_user()));
597 $sql_order = "`item`.`id`";
600 $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
601 $sql_order = "`item`.`id`";
606 $sql_post_table .= sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
607 dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
608 $sql_order = "`item`.`id`";
613 $sql_extra3 .= " AND $sql_table.`mention`";
616 // only setup pagination on initial page view
619 // check if we serve a mobile device and get the user settings
622 $itemspage_network = get_pconfig(local_user(),'system','itemspage_mobile_network');
623 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 20);
625 $itemspage_network = get_pconfig(local_user(),'system','itemspage_network');
626 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 40);
629 // now that we have the user settings, see if the theme forces
630 // a maximum item number which is lower then the user choice
631 if(($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network))
632 $itemspage_network = $a->force_max_items;
634 $a->set_pager_itemspage($itemspage_network);
635 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
639 $simple_update = (($update) ? " AND `item`.`unseen` " : '');
641 if ($sql_order == "")
642 $sql_order = "`item`.`id`";
644 // "New Item View" - show all items unthreaded in reverse created date order
645 $items = q("SELECT %s FROM $sql_table $sql_post_table %s
646 WHERE %s AND `item`.`uid` = %d
649 ORDER BY $sql_order DESC $pager_sql ",
650 item_fieldlists(), item_joins(), item_condition(),
651 intval($_SESSION['uid'])
654 $update_unseen = ' WHERE uid = ' . intval($_SESSION['uid']) . " AND unseen = 1 $sql_extra $sql_nets";
657 // Normal conversation view
658 if($order === 'post') {
659 $ordering = "`created`";
660 if ($sql_order == "")
661 $order_mode = "created";
663 $ordering = "`commented`";
664 if ($sql_order == "")
665 $order_mode = "commented";
668 if ($sql_order == "")
669 $sql_order = "$sql_table.$ordering";
671 if (($_GET["offset"] != ""))
672 $sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"]));
674 switch ($order_mode) {
676 if ($last_received != '') {
677 $sql_extra3 .= sprintf(" AND $sql_table.`received` < '%s'", dbesc($last_received));
678 $a->set_pager_page(1);
679 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
683 if ($last_commented != '') {
684 $sql_extra3 .= sprintf(" AND $sql_table.`commented` < '%s'", dbesc($last_commented));
685 $a->set_pager_page(1);
686 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
690 if ($last_created != '') {
691 $sql_extra3 .= sprintf(" AND $sql_table.`created` < '%s'", dbesc($last_created));
692 $a->set_pager_page(1);
693 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
697 if (($last_id > 0) && ($sql_table == "`thread`")) {
698 $sql_extra3 .= sprintf(" AND $sql_table.`iid` < '%s'", dbesc($last_id));
699 $a->set_pager_page(1);
700 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
705 // Fetch a page full of parent items for this page
707 if (get_config("system", "like_no_comment"))
708 $sql_extra4 = " AND `item`.`verb` = '".ACTIVITY_POST."'";
712 $r = q("SELECT `item`.`parent` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
713 FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
714 AND (NOT `contact`.`blocked` OR `contact`.`pending`)
715 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` $sql_extra4
716 AND NOT `item`.`moderated` AND `item`.`unseen`
717 $sql_extra3 $sql_extra $sql_nets
718 ORDER BY `item_id` DESC LIMIT 100",
722 $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
723 FROM $sql_table $sql_post_table STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
724 AND (NOT `contact`.`blocked` OR `contact`.`pending`)
725 WHERE `thread`.`uid` = %d AND `thread`.`visible` AND NOT `thread`.`deleted`
726 AND NOT `thread`.`moderated`
727 $sql_extra2 $sql_extra3 $sql_extra $sql_nets
728 ORDER BY $sql_order DESC $pager_sql ",
733 // Then fetch all the children of the parents that are on this page
735 $parents_arr = array();
739 if (dbm::is_result($r)) {
741 if(! in_array($rr['item_id'],$parents_arr))
742 $parents_arr[] = $rr['item_id'];
744 $parents_str = implode(", ", $parents_arr);
746 // splitted into separate queries to avoid the problem with very long threads
747 // so always the last X comments are loaded
748 // This problem can occur expecially with imported facebook posts
749 $max_comments = get_config("system", "max_comments");
750 if ($max_comments == 0)
755 foreach ($parents_arr AS $parents) {
756 $thread_items = dba::p(item_query()." AND `item`.`uid` = ?
757 AND `item`.`parent` = ?
758 ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1),
763 if (dbm::is_result($thread_items))
764 $items = array_merge($items, dba::inArray($thread_items));
766 $items = conv_sort($items,$ordering);
771 if ($_GET["offset"] == "")
772 $date_offset = $items[0][$order_mode];
774 $date_offset = $_GET["offset"];
776 $a->page_offset = $date_offset;
779 $update_unseen = ' WHERE uid = ' . intval(local_user()) . ' AND unseen = 1 AND parent IN ( ' . dbesc($parents_str) . ' )';
782 // We aren't going to try and figure out at the item, group, and page
783 // level which items you've seen and which you haven't. If you're looking
784 // at the top level network page just mark everything seen.
787 // The $update_unseen is a bit unreliable if you have stuff coming into your stream from a new contact -
788 // and other feeds that bring in stuff from the past. One can't find it all.
789 // I'm reviving this block to mark everything seen on page 1 of the network as a temporary measure.
790 // The correct solution is to implement a network notifications box just like the system notifications popup
791 // with the ability in the popup to "mark all seen".
792 // Several people are complaining because there are unseen messages they can't find and as time goes
793 // on they just get buried deeper. It has happened to me a couple of times also.
796 if (!$group && !$cid && !$star) {
797 $unseen = dba::exists('item', array('unseen' => true, 'uid' => local_user()));
800 $r = dba::update('item', array('unseen' => false), array('uid' => local_user(), 'unseen' => true));
802 } elseif ($update_unseen) {
803 $unseen = q("SELECT `id` FROM `item` ".$update_unseen. " LIMIT 1");
805 if (dbm::is_result($unseen)) {
806 $r = q("UPDATE `item` SET `unseen` = 0 $update_unseen");
810 // Set this so that the conversation function can find out contact info for our wall-wall items
811 $a->page_contact = $a->contact;
813 $mode = (($nouveau) ? 'network-new' : 'network');
815 $o .= conversation($a, $items, $mode, $update);
818 if (get_pconfig(local_user(), 'system', 'infinite_scroll')) {
819 $o .= scroll_loader();
821 $o .= alt_pager($a, count($items));
829 * @brief Get the network tabs menu
831 * @param App $a The global App
832 * @return string Html of the networktab
834 function network_tabs(App $a) {
836 /// @TODO fix this logic, reduce duplication
837 /// $a->page['content'] .= '<div class="tabs-wrapper">';
839 list($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) = network_query_get_sel_tab($a);
840 // if no tabs are selected, defaults to comments
841 if ($no_active=='active') $all_active='active';
843 $cmd = (($datequery) ? '' : $a->cmd);
844 $len_naked_cmd = strlen(str_replace('/new','',$cmd));
849 'label' => t('Commented Order'),
850 'url' => str_replace('/new', '', $cmd) . '?f=&order=comment' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
851 'sel' => $all_active,
852 'title' => t('Sort by Comment Date'),
853 'id' => 'commented-order-tab',
857 'label' => t('Posted Order'),
858 'url' => str_replace('/new', '', $cmd) . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
859 'sel' => $postord_active,
860 'title' => t('Sort by Post Date'),
861 'id' => 'posted-order-tab',
866 if(feature_enabled(local_user(),'personal_tab')) {
868 'label' => t('Personal'),
869 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&conv=1',
870 'sel' => $conv_active,
871 'title' => t('Posts that mention or involve you'),
872 'id' => 'personal-tab',
877 if (feature_enabled(local_user(),'new_tab')) {
880 'url' => 'network/new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
881 'sel' => $new_active,
882 'title' => t('Activity Stream - by date'),
883 'id' => 'activitiy-by-date-tab',
888 if(feature_enabled(local_user(),'link_tab')) {
890 'label' => t('Shared Links'),
891 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&bmark=1',
892 'sel' => $bookmarked_active,
893 'title' => t('Interesting Links'),
894 'id' => 'shared-links-tab',
899 if(feature_enabled(local_user(),'star_posts')) {
901 'label' => t('Starred'),
902 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&star=1',
903 'sel' => $starred_active,
904 'title' => t('Favourite Posts'),
905 'id' => 'starred-posts-tab',
910 // save selected tab, but only if not in search or file mode
911 if(!x($_GET,'search') && !x($_GET,'file')) {
912 set_pconfig( local_user(), 'network.view','tab.selected',array($all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) );
915 $arr = array('tabs' => $tabs);
916 call_hooks('network_tabs', $arr);
918 $tpl = get_markup_template('common_tabs.tpl');
920 return replace_macros($tpl, array('$tabs' => $arr['tabs']));
922 // --- end item filter tabs