2 function network_init(&$a) {
4 notice( t('Permission denied.') . EOL);
8 $is_a_date_query = false;
11 for($x = 1; $x < $a->argc; $x ++) {
12 if(is_a_date_arg($a->argv[$x])) {
13 $is_a_date_query = true;
19 // convert query string to array. remove friendica args
20 $query_array = array();
21 $query_string = str_replace($a->cmd."?", "", $a->query_string);
22 parse_str($query_string, $query_array);
23 array_shift($query_array);
26 // fetch last used network view and redirect if needed
27 if(! $is_a_date_query) {
28 $sel_tabs = network_query_get_sel_tab($a);
29 $sel_nets = network_query_get_sel_net();
30 $sel_groups = network_query_get_sel_group($a);
31 $last_sel_tabs = get_pconfig(local_user(), 'network.view','tab.selected');
32 $last_sel_nets = get_pconfig(local_user(), 'network.view', 'net.selected');
33 $last_sel_groups = get_pconfig(local_user(), 'network.view', 'group.selected');
35 $remember_tab = ($sel_tabs[0] === 'active' && is_array($last_sel_tabs) && $last_sel_tabs[0] !== 'active');
36 $remember_net = ($sel_nets === false && $last_sel_nets && $last_sel_nets !== 'all');
37 $remember_group = ($sel_groups === false && $last_sel_groups && $last_sel_groups != 0);
39 $net_baseurl = '/network';
43 $net_baseurl .= '/' . $last_sel_groups; // Note that the group number must come before the "/new" tab selection
45 else if($sel_groups !== false) {
46 $net_baseurl .= '/' . $sel_groups;
50 // redirect if current selected tab is '/network' and
51 // last selected tab is _not_ '/network?f=&order=comment'.
52 // and this isn't a date query
54 $tab_baseurls = array(
64 'f=&order=comment', //all
65 'f=&order=post', //postord
68 'f=&star=1', //starred
69 'f=&bmark=1', //bookmarked
73 $k = array_search('active', $last_sel_tabs);
75 $net_baseurl .= $tab_baseurls[$k];
77 // parse out tab queries
79 $dest_qs = $tab_args[$k];
80 parse_str( $dest_qs, $dest_qa);
81 $net_args = array_merge($net_args, $dest_qa);
83 else if($sel_tabs[4] === 'active') {
84 // The '/new' tab is selected
85 $net_baseurl .= '/new';
89 $net_args['nets'] = $last_sel_nets;
91 else if($sel_nets!==false) {
92 $net_args['nets'] = $sel_nets;
95 if($remember_tab || $remember_net || $remember_group) {
96 $net_args = array_merge($query_array, $net_args);
97 $net_queries = build_querystring($net_args);
99 $redir_url = ($net_queries ? $net_baseurl."?".$net_queries : $net_baseurl);
101 goaway($a->get_baseurl() . $redir_url);
105 if(x($_GET['nets']) && $_GET['nets'] === 'all')
106 unset($_GET['nets']);
108 $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
110 set_pconfig(local_user(), 'network.view', 'group.selected', $group_id);
112 require_once('include/group.php');
113 require_once('include/contact_widgets.php');
114 require_once('include/items.php');
116 if(! x($a->page,'aside'))
117 $a->page['aside'] = '';
119 $search = ((x($_GET,'search')) ? escape_tags($_GET['search']) : '');
121 if(x($_GET,'save')) {
122 $r = q("select * from `search` where `uid` = %d and `term` = '%s' limit 1",
123 intval(local_user()),
127 q("insert into `search` ( `uid`,`term` ) values ( %d, '%s') ",
128 intval(local_user()),
133 if(x($_GET,'remove')) {
134 q("delete from `search` where `uid` = %d and `term` = '%s'",
135 intval(local_user()),
140 // search terms header
141 if(x($_GET,'search')) {
142 $a->page['content'] .= replace_macros(get_markup_template("section_title.tpl"),array(
143 '$title' => sprintf( t('Search Results For: %s'), $search)
147 $a->page['aside'] .= (feature_enabled(local_user(),'groups') ? group_side('network/0','network',true,$group_id) : '');
148 $a->page['aside'] .= posted_date_widget($a->get_baseurl() . '/network',local_user(),false);
149 $a->page['aside'] .= networks_widget($a->get_baseurl(true) . '/network',(x($_GET, 'nets') ? $_GET['nets'] : ''));
150 $a->page['aside'] .= saved_searches($search);
151 $a->page['aside'] .= fileas_widget($a->get_baseurl(true) . '/network',(x($_GET, 'file') ? $_GET['file'] : ''));
155 function saved_searches($search) {
157 if(! feature_enabled(local_user(),'savedsearch'))
162 $srchurl = '/network?f='
163 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
164 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
165 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
166 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
167 . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
168 . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
169 . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
170 . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '');
175 $r = q("select `id`,`term` from `search` WHERE `uid` = %d",
185 'term' => $rr['term'],
186 'encodedterm' => urlencode($rr['term']),
187 'delete' => t('Remove term'),
188 'selected' => ($search==$rr['term']),
194 $tpl = get_markup_template("saved_searches_aside.tpl");
195 $o = replace_macros($tpl, array(
196 '$title' => t('Saved Searches'),
198 '$searchbox' => search($search,'netsearch-box',$srchurl,true),
207 * Return selected tab from query
210 * '/network' => $no_active = 'active'
211 * '/network?f=&order=comment' => $comment_active = 'active'
212 * '/network?f=&order=post' => $postord_active = 'active'
213 * '/network?f=&conv=1', => $conv_active = 'active'
214 * '/network/new', => $new_active = 'active'
215 * '/network?f=&star=1', => $starred_active = 'active'
216 * '/network?f=&bmark=1', => $bookmarked_active = 'active'
217 * '/network?f=&spam=1', => $spam_active = 'active'
219 * @return Array ( $no_active, $comment_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active );
221 function network_query_get_sel_tab($a) {
223 $starred_active = '';
225 $bookmarked_active = '';
230 $postord_active = '';
232 if(($a->argc > 1 && $a->argv[1] === 'new')
233 || ($a->argc > 2 && $a->argv[2] === 'new')) {
234 $new_active = 'active';
237 if(x($_GET,'search')) {
238 $search_active = 'active';
241 if(x($_GET,'star')) {
242 $starred_active = 'active';
245 if(x($_GET,'bmark')) {
246 $bookmarked_active = 'active';
249 if(x($_GET,'conv')) {
250 $conv_active = 'active';
253 if(x($_GET,'spam')) {
254 $spam_active = 'active';
259 if (($new_active == '')
260 && ($starred_active == '')
261 && ($bookmarked_active == '')
262 && ($conv_active == '')
263 && ($search_active == '')
264 && ($spam_active == '')) {
265 $no_active = 'active';
268 if ($no_active=='active' && x($_GET,'order')) {
269 switch($_GET['order']){
270 case 'post': $postord_active = 'active'; $no_active=''; break;
271 case 'comment' : $all_active = 'active'; $no_active=''; break;
275 return array($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active);
279 * Return selected network from query
281 function network_query_get_sel_net() {
284 if(x($_GET,'nets')) {
285 $network = $_GET['nets'];
291 function network_query_get_sel_group($a) {
294 if($a->argc >= 2 && is_numeric($a->argv[1])) {
295 $group = $a->argv[1];
302 function network_content(&$a, $update = 0) {
304 require_once('include/conversation.php');
307 $_SESSION['return_url'] = $a->query_string;
311 // TODO:is this really necessary? $a is already available to hooks
312 $arr = array('query' => $a->query_string);
313 call_hooks('network_content_init', $arr);
316 $datequery = $datequery2 = '';
323 for($x = 1; $x < $a->argc; $x ++) {
324 if(is_a_date_arg($a->argv[$x])) {
326 $datequery2 = escape_tags($a->argv[$x]);
328 $datequery = escape_tags($a->argv[$x]);
329 $_GET['order'] = 'post';
332 elseif($a->argv[$x] === 'new') {
335 elseif(intval($a->argv[$x])) {
336 $group = intval($a->argv[$x]);
337 $def_acl = array('allow_gid' => '<' . $group . '>');
345 // TODO: fix this logic, reduce duplication
346 //$a->page['content'] .= '<div class="tabs-wrapper">';
348 list($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) = network_query_get_sel_tab($a);
349 // if no tabs are selected, defaults to comments
350 if ($no_active=='active') $all_active='active';
352 $cmd = (($datequery) ? '' : $a->cmd);
353 $len_naked_cmd = strlen(str_replace('/new','',$cmd));
358 'label' => t('Commented Order'),
359 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=comment' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
361 'title'=> t('Sort by Comment Date'),
365 'label' => t('Posted Order'),
366 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
367 'sel'=>$postord_active,
368 'title' => t('Sort by Post Date'),
373 if(feature_enabled(local_user(),'personal_tab')) {
375 'label' => t('Personal'),
376 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&conv=1',
377 'sel' => $conv_active,
378 'title' => t('Posts that mention or involve you'),
383 if(feature_enabled(local_user(),'new_tab')) {
386 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ($len_naked_cmd ? '/' : '') . 'new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
387 'sel' => $new_active,
388 'title' => t('Activity Stream - by date'),
393 if(feature_enabled(local_user(),'link_tab')) {
395 'label' => t('Shared Links'),
396 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&bmark=1',
397 'sel'=>$bookmarked_active,
398 'title'=> t('Interesting Links'),
403 if(feature_enabled(local_user(),'star_posts')) {
405 'label' => t('Starred'),
406 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&star=1',
407 'sel'=>$starred_active,
408 'title' => t('Favourite Posts'),
413 // save selected tab, but only if not in search or file mode
414 if(!x($_GET,'search') && !x($_GET,'file')) {
415 set_pconfig( local_user(), 'network.view','tab.selected',array($all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) );
418 $arr = array('tabs' => $tabs);
419 call_hooks('network_tabs', $arr);
421 $o .= replace_macros(get_markup_template('common_tabs.tpl'), array('$tabs'=> $arr['tabs']));
423 // --- end item filter tabs
425 $contact_id = $a->cid;
427 require_once('include/acl_selectors.php');
429 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
430 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
431 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
432 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
433 $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0);
434 $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
435 $spam = ((x($_GET,'spam')) ? intval($_GET['spam']) : 0);
436 $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
437 $cmin = ((x($_GET,'cmin')) ? intval($_GET['cmin']) : 0);
438 $cmax = ((x($_GET,'cmax')) ? intval($_GET['cmax']) : 99);
439 $file = ((x($_GET,'file')) ? $_GET['file'] : '');
443 if(x($_GET,'search') || x($_GET,'file'))
446 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
449 $r = q("select id from contact where uid = %d and network = '%s' and self = 0",
450 intval(local_user()),
457 $str .= '<' . $rr['id'] . '>';
459 $def_acl = array('allow_cid' => $str);
461 set_pconfig(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all'));
465 if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
466 notice( sprintf( tt('Warning: This group contains %s member from an insecure network.',
467 'Warning: This group contains %s members from an insecure network.',
469 notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
473 nav_set_selected('network');
478 $contact = q("SELECT `nick` FROM `contact` WHERE `id` = %d AND `uid` = %d AND `forum`", intval($cid), intval(local_user()));
480 $content = "@".$contact[0]["nick"]."+".$cid;
485 'allow_location' => $a->user['allow_location'],
486 'default_location' => $a->user['default-location'],
487 'nickname' => $a->user['nickname'],
488 'lockstate'=> ((($group) || ($cid) || ($nets) || (is_array($a->user) &&
489 ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) ||
490 (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
491 'default_perms' => get_acl_permissions($a->user),
492 'acl' => populate_acl((($group || $cid || $nets) ? $def_acl : $a->user), true),
493 'bang' => (($group || $cid || $nets) ? '!' : ''),
494 'visitor' => 'block',
495 'profile_uid' => local_user(),
496 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
497 'content' => $content,
500 $o .= status_editor($a,$x);
504 // We don't have to deal with ACLs on this page. You're looking at everything
505 // that belongs to you, hence you can see all of it. We will filter by group if
508 $sql_post_table = "";
509 $sql_options = (($star) ? " and starred = 1 " : '');
510 $sql_options .= (($bmark) ? " and bookmark = 1 " : '');
511 $sql_extra = $sql_options;
514 $sql_table = "`thread`";
515 $sql_parent = "`iid`";
517 if ($nouveau OR strlen($file) OR $update) {
518 $sql_table = "`item`";
519 $sql_parent = "`parent`";
522 $sql_nets = (($nets) ? sprintf(" and $sql_table.`network` = '%s' ", dbesc($nets)) : '');
525 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
527 intval($_SESSION['uid'])
532 notice( t('No such group') . EOL );
533 goaway($a->get_baseurl(true) . '/network/0');
537 $contacts = expand_groups(array($group));
539 $contact_str_self = "";
541 if((is_array($contacts)) && count($contacts)) {
542 $contact_str = implode(',',$contacts);
543 $self = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($_SESSION['uid']));
545 $contact_str_self = ",".$self[0]["id"];
548 $contact_str = ' 0 ';
549 info( t('Group is empty'));
552 //$sql_post_table = " INNER JOIN (SELECT DISTINCT(`parent`) FROM `item` WHERE (`contact-id` IN ($contact_str) OR `allow_gid` like '".protect_sprintf('%<'.intval($group).'>%')."') and deleted = 0 ORDER BY `created` DESC) AS `temp1` ON $sql_table.$sql_parent = `temp1`.`parent` ";
554 $sql_extra3 .= " AND `contact-id` IN ($contact_str$contact_str_self) ";
555 $sql_extra3 .= " AND EXISTS (SELECT id FROM `item` WHERE (`contact-id` IN ($contact_str)
556 OR `allow_gid` like '".protect_sprintf('%<'.intval($group).'>%')."') and deleted = 0
557 AND parent = $sql_table.$sql_parent) ";
559 $o = replace_macros(get_markup_template("section_title.tpl"),array(
560 '$title' => sprintf( t('Group: %s'), $r[0]['name'])
566 $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d
567 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
571 $sql_post_table = " INNER JOIN (SELECT DISTINCT(`parent`) FROM `item`
572 WHERE 1 $sql_options AND `contact-id` = ".intval($cid)." and deleted = 0
573 ORDER BY `item`.`received` DESC) AS `temp1`
574 ON $sql_table.$sql_parent = `temp1`.`parent` ";
577 $o = replace_macros(get_markup_template("section_title.tpl"),array(
578 '$title' => sprintf( t('Contact: %s'), $r[0]['name'])
581 if($r[0]['network'] === NETWORK_OSTATUS && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
582 notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
587 notice( t('Invalid contact.') . EOL);
588 goaway($a->get_baseurl(true) . '/network');
593 if((! $group) && (! $cid) && (! $update) && (! get_config('theme','hide_eventlist'))) {
594 $o .= get_birthdays();
599 $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
602 $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
605 //$sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
606 $sql_extra2 = (($nouveau) ? '' : $sql_extra2);
607 $sql_extra3 = (($nouveau) ? '' : $sql_extra3);
609 $order_mode = "received";
612 if(x($_GET,'search')) {
613 $search = escape_tags($_GET['search']);
615 if(strpos($search,'#') === 0) {
617 $search = substr($search,1);
620 if (get_config('system','only_tag_search'))
626 $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` ",
627 dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval(local_user()));
628 $sql_order = "`item`.`id`";
631 if (get_config('system','use_fulltext_engine'))
632 $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
634 $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
635 $sql_order = "`item`.`received`";
636 $order_mode = "received";
640 $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` ",
641 dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
642 $sql_order = "`item`.`id`";
647 $sql_extra3 .= " AND `mention`";
651 // only setup pagination on initial page view
656 if(get_config('system', 'old_pager')) {
657 $r = q("SELECT COUNT(*) AS `total`
658 FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = $sql_table.`contact-id`
659 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
660 WHERE $sql_table.`uid` = %d AND $sql_table.`visible` = 1 AND $sql_table.`deleted` = 0
661 $sql_extra2 $sql_extra3
662 $sql_extra $sql_nets ",
663 intval($_SESSION['uid'])
667 $a->set_pager_total($r[0]['total']);
671 // check if we serve a mobile device and get the user settings
674 $itemspage_network = get_pconfig(local_user(),'system','itemspage_mobile_network');
675 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 20);
677 $itemspage_network = get_pconfig(local_user(),'system','itemspage_network');
678 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 40);
680 // now that we have the user settings, see if the theme forces
681 // a maximum item number which is lower then the user choice
682 if(($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network))
683 $itemspage_network = $a->force_max_items;
685 $a->set_pager_itemspage($itemspage_network);
686 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
690 $simple_update = (($update) ? " and `item`.`unseen` = 1 " : '');
692 if ($sql_order == "")
693 $sql_order = "`item`.`received`";
695 // "New Item View" - show all items unthreaded in reverse created date order
696 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
697 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
698 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
699 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
700 FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
701 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
702 WHERE `item`.`uid` = %d AND `item`.`visible` = 1
703 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
706 ORDER BY $sql_order DESC $pager_sql ",
707 intval($_SESSION['uid'])
710 $update_unseen = ' WHERE uid = ' . intval($_SESSION['uid']) . " AND unseen = 1 $sql_extra $sql_nets";
713 // Normal conversation view
716 if($order === 'post') {
717 $ordering = "`created`";
718 if ($sql_order == "")
719 $order_mode = "created";
721 $ordering = "`commented`";
722 if ($sql_order == "")
723 $order_mode = "commented";
726 if ($sql_order == "")
727 $sql_order = "$sql_table.$ordering";
729 if (($_GET["offset"] != ""))
730 $sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"]));
732 // Fetch a page full of parent items for this page
734 if (!get_config("system", "like_no_comment"))
735 $sql_extra4 = "(`item`.`deleted` = 0 OR `item`.`verb` = '".ACTIVITY_LIKE."' OR `item`.`verb` = '".ACTIVITY_DISLIKE."')";
737 $sql_extra4 = "`item`.`deleted` = 0 AND `item`.`verb` = '".ACTIVITY_POST."'";
739 $r = q("SELECT `item`.`parent` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
740 FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
741 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
742 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND $sql_extra4
743 AND `item`.`moderated` = 0 AND `item`.`unseen` = 1
744 $sql_extra3 $sql_extra $sql_nets ORDER BY `item_id` DESC LIMIT 100",
748 $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
749 FROM $sql_table $sql_post_table STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
750 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
751 WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0
752 AND `thread`.`moderated` = 0
753 $sql_extra2 $sql_extra3 $sql_extra $sql_nets
754 ORDER BY $sql_order DESC $pager_sql ",
759 // Then fetch all the children of the parents that are on this page
761 $parents_arr = array();
767 if(! in_array($rr['item_id'],$parents_arr))
768 $parents_arr[] = $rr['item_id'];
770 $parents_str = implode(", ", $parents_arr);
772 // splitted into separate queries to avoid the problem with very long threads
773 // so always the last X comments are loaded
774 // This problem can occur expecially with imported facebook posts
775 $max_comments = get_config("system", "max_comments");
776 if ($max_comments == 0)
781 foreach ($parents_arr AS $parents) {
782 // $sql_extra ORDER BY `item`.`commented` DESC LIMIT %d",
783 $thread_items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
784 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,
785 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
786 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
787 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
788 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
789 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
790 AND `item`.`moderated` = 0
791 AND `item`.`parent` = %d
792 ORDER BY `item`.`commented` DESC LIMIT %d",
793 intval(local_user()),
795 intval($max_comments + 1)
797 $items = array_merge($items, $thread_items);
799 $items = conv_sort($items,$ordering);
804 if ($_GET["offset"] == "")
805 $date_offset = $items[0][$order_mode];
807 $date_offset = $_GET["offset"];
809 $a->page_offset = $date_offset;
812 $update_unseen = ' WHERE uid = ' . intval(local_user()) . ' AND unseen = 1 AND parent IN ( ' . dbesc($parents_str) . ' )';
815 // We aren't going to try and figure out at the item, group, and page
816 // level which items you've seen and which you haven't. If you're looking
817 // at the top level network page just mark everything seen.
820 // The $update_unseen is a bit unreliable if you have stuff coming into your stream from a new contact -
821 // and other feeds that bring in stuff from the past. One can't find it all.
822 // I'm reviving this block to mark everything seen on page 1 of the network as a temporary measure.
823 // The correct solution is to implement a network notifications box just like the system notifications popup
824 // with the ability in the popup to "mark all seen".
825 // Several people are complaining because there are unseen messages they can't find and as time goes
826 // on they just get buried deeper. It has happened to me a couple of times also.
829 if((! $group) && (! $cid) && (! $star)) {
830 $r = q("UPDATE `item` SET `unseen` = 0
831 WHERE `unseen` = 1 AND `uid` = %d",
837 $r = q("UPDATE `item` SET `unseen` = 0 $update_unseen");
840 // Set this so that the conversation function can find out contact info for our wall-wall items
841 $a->page_contact = $a->contact;
843 $mode = (($nouveau) ? 'network-new' : 'network');
845 $o .= conversation($a,$items,$mode,$update);
848 if(get_pconfig(local_user(),'system','infinite_scroll')) {
849 $o .= scroll_loader();
850 } elseif(!get_config('system', 'old_pager')) {
851 $o .= alt_pager($a,count($items));