2 function network_init(&$a) {
4 notice( t('Permission denied.') . EOL);
8 $is_a_date_query = false;
9 if(x($_GET['cid']) && intval($_GET['cid']) != 0)
13 for($x = 1; $x < $a->argc; $x ++) {
14 if(is_a_date_arg($a->argv[$x])) {
15 $is_a_date_query = true;
21 // convert query string to array. remove friendica args
22 $query_array = array();
23 $query_string = str_replace($a->cmd."?", "", $a->query_string);
24 parse_str($query_string, $query_array);
25 array_shift($query_array);
28 // fetch last used network view and redirect if needed
29 if(! $is_a_date_query) {
30 $sel_tabs = network_query_get_sel_tab($a);
31 $sel_nets = network_query_get_sel_net();
32 $sel_groups = network_query_get_sel_group($a);
33 $last_sel_tabs = get_pconfig(local_user(), 'network.view','tab.selected');
34 $last_sel_nets = get_pconfig(local_user(), 'network.view', 'net.selected');
35 $last_sel_groups = get_pconfig(local_user(), 'network.view', 'group.selected');
37 $remember_tab = ($sel_tabs[0] === 'active' && is_array($last_sel_tabs) && $last_sel_tabs[0] !== 'active');
38 $remember_net = ($sel_nets === false && $last_sel_nets && $last_sel_nets !== 'all');
39 $remember_group = ($sel_groups === false && $last_sel_groups && $last_sel_groups != 0);
41 $net_baseurl = '/network';
45 $net_baseurl .= '/' . $last_sel_groups; // Note that the group number must come before the "/new" tab selection
47 else if($sel_groups !== false) {
48 $net_baseurl .= '/' . $sel_groups;
52 // redirect if current selected tab is '/network' and
53 // last selected tab is _not_ '/network?f=&order=comment'.
54 // and this isn't a date query
56 $tab_baseurls = array(
66 'f=&order=comment', //all
67 'f=&order=post', //postord
70 'f=&star=1', //starred
71 'f=&bmark=1', //bookmarked
75 $k = array_search('active', $last_sel_tabs);
77 $net_baseurl .= $tab_baseurls[$k];
79 // parse out tab queries
81 $dest_qs = $tab_args[$k];
82 parse_str( $dest_qs, $dest_qa);
83 $net_args = array_merge($net_args, $dest_qa);
85 else if($sel_tabs[4] === 'active') {
86 // The '/new' tab is selected
87 $net_baseurl .= '/new';
91 $net_args['nets'] = $last_sel_nets;
93 else if($sel_nets!==false) {
94 $net_args['nets'] = $sel_nets;
97 if($remember_tab || $remember_net || $remember_group) {
98 $net_args = array_merge($query_array, $net_args);
99 $net_queries = build_querystring($net_args);
101 $redir_url = ($net_queries ? $net_baseurl."?".$net_queries : $net_baseurl);
103 goaway($a->get_baseurl() . $redir_url);
107 if(x($_GET['nets']) && $_GET['nets'] === 'all')
108 unset($_GET['nets']);
110 $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
112 set_pconfig(local_user(), 'network.view', 'group.selected', $group_id);
114 require_once('include/group.php');
115 require_once('include/contact_widgets.php');
116 require_once('include/items.php');
117 require_once('include/forums.php');
119 if(! x($a->page,'aside'))
120 $a->page['aside'] = '';
122 $search = ((x($_GET,'search')) ? escape_tags($_GET['search']) : '');
124 if(x($_GET,'save')) {
125 $r = q("SELECT * FROM `search` WHERE `uid` = %d AND `term` = '%s' LIMIT 1",
126 intval(local_user()),
130 q("INSERT INTO `search` ( `uid`,`term` ) VALUES ( %d, '%s') ",
131 intval(local_user()),
136 if(x($_GET,'remove')) {
137 q("DELETE FROM `search` WHERE `uid` = %d AND `term` = '%s'",
138 intval(local_user()),
143 // search terms header
144 if(x($_GET,'search')) {
145 $a->page['content'] .= replace_macros(get_markup_template("section_title.tpl"),array(
146 '$title' => sprintf( t('Search Results For: %s'), $search)
150 $a->page['aside'] .= (feature_enabled(local_user(),'groups') ? group_side('network/0','network','standard',$group_id) : '');
151 $a->page['aside'] .= (feature_enabled(local_user(),'forumlist_widget') ? widget_forumlist(local_user(),$cid) : '');
152 $a->page['aside'] .= posted_date_widget($a->get_baseurl() . '/network',local_user(),false);
153 $a->page['aside'] .= networks_widget($a->get_baseurl(true) . '/network',(x($_GET, 'nets') ? $_GET['nets'] : ''));
154 $a->page['aside'] .= saved_searches($search);
155 $a->page['aside'] .= fileas_widget($a->get_baseurl(true) . '/network',(x($_GET, 'file') ? $_GET['file'] : ''));
159 function saved_searches($search) {
161 if(! feature_enabled(local_user(),'savedsearch'))
166 $srchurl = '/network?f='
167 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
168 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
169 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
170 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
171 . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
172 . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
173 . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
174 . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '');
179 $r = q("SELECT `id`,`term` FROM `search` WHERE `uid` = %d",
189 'term' => $rr['term'],
190 'encodedterm' => urlencode($rr['term']),
191 'delete' => t('Remove term'),
192 'selected' => ($search==$rr['term']),
198 $tpl = get_markup_template("saved_searches_aside.tpl");
199 $o = replace_macros($tpl, array(
200 '$title' => t('Saved Searches'),
202 '$searchbox' => search($search,'netsearch-box',$srchurl,true),
211 * Return selected tab from query
214 * '/network' => $no_active = 'active'
215 * '/network?f=&order=comment' => $comment_active = 'active'
216 * '/network?f=&order=post' => $postord_active = 'active'
217 * '/network?f=&conv=1', => $conv_active = 'active'
218 * '/network/new', => $new_active = 'active'
219 * '/network?f=&star=1', => $starred_active = 'active'
220 * '/network?f=&bmark=1', => $bookmarked_active = 'active'
221 * '/network?f=&spam=1', => $spam_active = 'active'
223 * @return Array ( $no_active, $comment_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active );
225 function network_query_get_sel_tab($a) {
227 $starred_active = '';
229 $bookmarked_active = '';
234 $postord_active = '';
236 if(($a->argc > 1 && $a->argv[1] === 'new')
237 || ($a->argc > 2 && $a->argv[2] === 'new')) {
238 $new_active = 'active';
241 if(x($_GET,'search')) {
242 $search_active = 'active';
245 if(x($_GET,'star')) {
246 $starred_active = 'active';
249 if(x($_GET,'bmark')) {
250 $bookmarked_active = 'active';
253 if(x($_GET,'conv')) {
254 $conv_active = 'active';
257 if(x($_GET,'spam')) {
258 $spam_active = 'active';
263 if (($new_active == '')
264 && ($starred_active == '')
265 && ($bookmarked_active == '')
266 && ($conv_active == '')
267 && ($search_active == '')
268 && ($spam_active == '')) {
269 $no_active = 'active';
272 if ($no_active=='active' && x($_GET,'order')) {
273 switch($_GET['order']){
274 case 'post': $postord_active = 'active'; $no_active=''; break;
275 case 'comment' : $all_active = 'active'; $no_active=''; break;
279 return array($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active);
283 * Return selected network from query
285 function network_query_get_sel_net() {
288 if(x($_GET,'nets')) {
289 $network = $_GET['nets'];
295 function network_query_get_sel_group($a) {
298 if($a->argc >= 2 && is_numeric($a->argv[1])) {
299 $group = $a->argv[1];
306 function network_content(&$a, $update = 0) {
308 require_once('include/conversation.php');
311 $_SESSION['return_url'] = $a->query_string;
315 /// @TODO Is this really necessary? $a is already available to hooks
316 $arr = array('query' => $a->query_string);
317 call_hooks('network_content_init', $arr);
320 $datequery = $datequery2 = '';
327 for($x = 1; $x < $a->argc; $x ++) {
328 if(is_a_date_arg($a->argv[$x])) {
330 $datequery2 = escape_tags($a->argv[$x]);
332 $datequery = escape_tags($a->argv[$x]);
333 $_GET['order'] = 'post';
336 elseif($a->argv[$x] === 'new') {
339 elseif(intval($a->argv[$x])) {
340 $group = intval($a->argv[$x]);
341 $def_acl = array('allow_gid' => '<' . $group . '>');
349 /// @TODO fix this logic, reduce duplication
350 /// $a->page['content'] .= '<div class="tabs-wrapper">';
352 list($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) = network_query_get_sel_tab($a);
353 // if no tabs are selected, defaults to comments
354 if ($no_active=='active') $all_active='active';
356 $cmd = (($datequery) ? '' : $a->cmd);
357 $len_naked_cmd = strlen(str_replace('/new','',$cmd));
362 'label' => t('Commented Order'),
363 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=comment' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
364 'sel' => $all_active,
365 'title' => t('Sort by Comment Date'),
366 'id' => 'commented-order-tab',
370 'label' => t('Posted Order'),
371 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
372 'sel' => $postord_active,
373 'title' => t('Sort by Post Date'),
374 'id' => 'posted-order-tab',
379 if(feature_enabled(local_user(),'personal_tab')) {
381 'label' => t('Personal'),
382 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&conv=1',
383 'sel' => $conv_active,
384 'title' => t('Posts that mention or involve you'),
385 'id' => 'personal-tab',
390 if(feature_enabled(local_user(),'new_tab')) {
393 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ($len_naked_cmd ? '/' : '') . 'new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
394 'sel' => $new_active,
395 'title' => t('Activity Stream - by date'),
396 'id' => 'activitiy-by-date-tab',
401 if(feature_enabled(local_user(),'link_tab')) {
403 'label' => t('Shared Links'),
404 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&bmark=1',
405 'sel' => $bookmarked_active,
406 'title' => t('Interesting Links'),
407 'id' => 'shared-links-tab',
412 if(feature_enabled(local_user(),'star_posts')) {
414 'label' => t('Starred'),
415 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&star=1',
416 'sel' => $starred_active,
417 'title' => t('Favourite Posts'),
418 'id' => 'starred-posts-tab',
423 // save selected tab, but only if not in search or file mode
424 if(!x($_GET,'search') && !x($_GET,'file')) {
425 set_pconfig( local_user(), 'network.view','tab.selected',array($all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) );
428 $arr = array('tabs' => $tabs);
429 call_hooks('network_tabs', $arr);
431 $o .= replace_macros(get_markup_template('common_tabs.tpl'), array('$tabs'=> $arr['tabs']));
433 // --- end item filter tabs
435 $contact_id = $a->cid;
437 require_once('include/acl_selectors.php');
439 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
440 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
441 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
442 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
443 $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0);
444 $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
445 $spam = ((x($_GET,'spam')) ? intval($_GET['spam']) : 0);
446 $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
447 $cmin = ((x($_GET,'cmin')) ? intval($_GET['cmin']) : 0);
448 $cmax = ((x($_GET,'cmax')) ? intval($_GET['cmax']) : 99);
449 $file = ((x($_GET,'file')) ? $_GET['file'] : '');
453 if(x($_GET,'search') || x($_GET,'file'))
456 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
459 $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND network = '%s' AND `self` = 0",
460 intval(local_user()),
467 $str .= '<' . $rr['id'] . '>';
469 $def_acl = array('allow_cid' => $str);
471 set_pconfig(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all'));
475 if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
476 notice( sprintf( tt('Warning: This group contains %s member from an insecure network.',
477 'Warning: This group contains %s members from an insecure network.',
479 notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
483 nav_set_selected('network');
488 // If $cid belongs to a communitity forum or a privat goup,.add a mention to the status editor
489 $contact = q("SELECT `nick` FROM `contact` WHERE `id` = %d AND `uid` = %d AND (`forum` OR `prv`) ",
494 $content = "@".$contact[0]["nick"]."+".$cid;
499 'allow_location' => $a->user['allow_location'],
500 'default_location' => $a->user['default-location'],
501 'nickname' => $a->user['nickname'],
502 'lockstate'=> ((($group) || ($cid) || ($nets) || (is_array($a->user) &&
503 ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) ||
504 (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
505 'default_perms' => get_acl_permissions($a->user),
506 'acl' => populate_acl((($group || $cid || $nets) ? $def_acl : $a->user), true),
507 'bang' => (($group || $cid || $nets) ? '!' : ''),
508 'visitor' => 'block',
509 'profile_uid' => local_user(),
510 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
511 'content' => $content,
514 $o .= status_editor($a,$x);
518 // We don't have to deal with ACLs on this page. You're looking at everything
519 // that belongs to you, hence you can see all of it. We will filter by group if
522 $sql_post_table = "";
523 $sql_options = (($star) ? " and starred = 1 " : '');
524 $sql_options .= (($bmark) ? " and bookmark = 1 " : '');
525 $sql_extra = $sql_options;
528 $sql_table = "`thread`";
529 $sql_parent = "`iid`";
531 if ($nouveau OR strlen($file) OR $update) {
532 $sql_table = "`item`";
533 $sql_parent = "`parent`";
536 $sql_nets = (($nets) ? sprintf(" and $sql_table.`network` = '%s' ", dbesc($nets)) : '');
539 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
541 intval($_SESSION['uid'])
546 notice( t('No such group') . EOL );
547 goaway($a->get_baseurl(true) . '/network/0');
551 $contacts = expand_groups(array($group));
553 $contact_str_self = "";
555 if((is_array($contacts)) && count($contacts)) {
556 $contact_str = implode(',',$contacts);
557 $self = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($_SESSION['uid']));
559 $contact_str_self = ",".$self[0]["id"];
562 $contact_str = ' 0 ';
563 info( t('Group is empty'));
566 //$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` ";
568 $sql_extra3 .= " AND `contact-id` IN ($contact_str$contact_str_self) ";
569 $sql_extra3 .= " AND EXISTS (SELECT `id` FROM `item` WHERE (`contact-id` IN ($contact_str)
570 OR `allow_gid` LIKE '".protect_sprintf('%<'.intval($group).'>%')."') AND `deleted` = 0
571 AND `parent` = $sql_table.$sql_parent) ";
573 $o = replace_macros(get_markup_template("section_title.tpl"),array(
574 '$title' => sprintf( t('Group: %s'), $r[0]['name'])
580 $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl`, `forum`, `prv`, `addr`, `thumb`, `location` FROM `contact` WHERE `id` = %d
581 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
585 $sql_post_table = " INNER JOIN (SELECT DISTINCT(`parent`) FROM `item`
586 WHERE 1 $sql_options AND `contact-id` = ".intval($cid)." AND `deleted` = 0
587 ORDER BY `item`.`received` DESC) AS `temp1`
588 ON $sql_table.$sql_parent = `temp1`.`parent` ";
593 'name' => htmlentities($r[0]['name']),
594 'itemurl' => (($r[0]['addr']) ? ($r[0]['addr']) : ($r[0]['nurl'])),
595 'thumb' => proxy_url($r[0]['thumb'], false, PROXY_SIZE_THUMB),
596 'account_type' => (($r[0]['forum']) || ($r[0]['prv']) ? t('Forum') : ''),
597 'details' => $r[0]['location'],
600 $o = replace_macros(get_markup_template("viewcontact_template.tpl"),array(
601 'contacts' => $entries,
605 if($r[0]['network'] === NETWORK_OSTATUS && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
606 notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
611 notice( t('Invalid contact.') . EOL);
612 goaway($a->get_baseurl(true) . '/network');
617 if((! $group) && (! $cid) && (! $update) && (! get_config('theme','hide_eventlist'))) {
618 $o .= get_birthdays();
623 $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
626 $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
629 //$sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
630 $sql_extra2 = (($nouveau) ? '' : $sql_extra2);
631 $sql_extra3 = (($nouveau) ? '' : $sql_extra3);
633 $order_mode = "received";
636 if(x($_GET,'search')) {
637 $search = escape_tags($_GET['search']);
639 if(strpos($search,'#') === 0) {
641 $search = substr($search,1);
644 if (get_config('system','only_tag_search'))
650 $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` ",
651 dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval(local_user()));
652 $sql_order = "`item`.`id`";
655 if (get_config('system','use_fulltext_engine'))
656 $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
658 $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
659 $sql_order = "`item`.`received`";
660 $order_mode = "received";
664 $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` ",
665 dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
666 $sql_order = "`item`.`id`";
671 $sql_extra3 .= " AND `mention`";
675 // only setup pagination on initial page view
680 if(get_config('system', 'old_pager')) {
681 $r = q("SELECT COUNT(*) AS `total`
682 FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = $sql_table.`contact-id`
683 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
684 WHERE $sql_table.`uid` = %d AND $sql_table.`visible` = 1 AND $sql_table.`deleted` = 0
685 $sql_extra2 $sql_extra3
686 $sql_extra $sql_nets ",
687 intval($_SESSION['uid'])
691 $a->set_pager_total($r[0]['total']);
695 // check if we serve a mobile device and get the user settings
698 $itemspage_network = get_pconfig(local_user(),'system','itemspage_mobile_network');
699 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 20);
701 $itemspage_network = get_pconfig(local_user(),'system','itemspage_network');
702 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 40);
705 // now that we have the user settings, see if the theme forces
706 // a maximum item number which is lower then the user choice
707 if(($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network))
708 $itemspage_network = $a->force_max_items;
710 $a->set_pager_itemspage($itemspage_network);
711 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
715 $simple_update = (($update) ? " AND `item`.`unseen` = 1 " : '');
717 if ($sql_order == "")
718 $sql_order = "`item`.`received`";
720 // "New Item View" - show all items unthreaded in reverse created date order
721 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
722 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
723 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
724 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
725 FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
726 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
727 WHERE `item`.`uid` = %d AND `item`.`visible` = 1
728 AND `item`.`deleted` = 0 AND `item`.`moderated` = 0
731 ORDER BY $sql_order DESC $pager_sql ",
732 intval($_SESSION['uid'])
735 $update_unseen = ' WHERE uid = ' . intval($_SESSION['uid']) . " AND unseen = 1 $sql_extra $sql_nets";
738 // Normal conversation view
741 if($order === 'post') {
742 $ordering = "`created`";
743 if ($sql_order == "")
744 $order_mode = "created";
746 $ordering = "`commented`";
747 if ($sql_order == "")
748 $order_mode = "commented";
751 if ($sql_order == "")
752 $sql_order = "$sql_table.$ordering";
754 if (($_GET["offset"] != ""))
755 $sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"]));
757 // Fetch a page full of parent items for this page
759 if (!get_config("system", "like_no_comment"))
760 $sql_extra4 = "(`item`.`deleted` = 0
761 OR `item`.`verb` = '".ACTIVITY_LIKE."' OR `item`.`verb` = '".ACTIVITY_DISLIKE."'
762 OR `item`.`verb` = '".ACTIVITY_ATTEND."' OR `item`.`verb` = '".ACTIVITY_ATTENDNO."'
763 OR `item`.`verb` = '".ACTIVITY_ATTENDMAYBE."')";
765 $sql_extra4 = "`item`.`deleted` = 0 AND `item`.`verb` = '".ACTIVITY_POST."'";
767 $r = q("SELECT `item`.`parent` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
768 FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
769 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
770 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND $sql_extra4
771 AND `item`.`moderated` = 0 AND `item`.`unseen` = 1
772 $sql_extra3 $sql_extra $sql_nets ORDER BY `item_id` DESC LIMIT 100",
776 $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
777 FROM $sql_table $sql_post_table STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
778 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
779 WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0
780 AND `thread`.`moderated` = 0
781 $sql_extra2 $sql_extra3 $sql_extra $sql_nets
782 ORDER BY $sql_order DESC $pager_sql ",
787 // Then fetch all the children of the parents that are on this page
789 $parents_arr = array();
795 if(! in_array($rr['item_id'],$parents_arr))
796 $parents_arr[] = $rr['item_id'];
798 $parents_str = implode(", ", $parents_arr);
800 // splitted into separate queries to avoid the problem with very long threads
801 // so always the last X comments are loaded
802 // This problem can occur expecially with imported facebook posts
803 $max_comments = get_config("system", "max_comments");
804 if ($max_comments == 0)
809 foreach ($parents_arr AS $parents) {
810 // $sql_extra ORDER BY `item`.`commented` DESC LIMIT %d",
811 $thread_items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
812 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,
813 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
814 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
815 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
816 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
817 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
818 AND `item`.`moderated` = 0
819 AND `item`.`parent` = %d
820 ORDER BY `item`.`commented` DESC LIMIT %d",
821 intval(local_user()),
823 intval($max_comments + 1)
825 $items = array_merge($items, $thread_items);
827 $items = conv_sort($items,$ordering);
832 if ($_GET["offset"] == "")
833 $date_offset = $items[0][$order_mode];
835 $date_offset = $_GET["offset"];
837 $a->page_offset = $date_offset;
840 $update_unseen = ' WHERE uid = ' . intval(local_user()) . ' AND unseen = 1 AND parent IN ( ' . dbesc($parents_str) . ' )';
843 // We aren't going to try and figure out at the item, group, and page
844 // level which items you've seen and which you haven't. If you're looking
845 // at the top level network page just mark everything seen.
848 // The $update_unseen is a bit unreliable if you have stuff coming into your stream from a new contact -
849 // and other feeds that bring in stuff from the past. One can't find it all.
850 // I'm reviving this block to mark everything seen on page 1 of the network as a temporary measure.
851 // The correct solution is to implement a network notifications box just like the system notifications popup
852 // with the ability in the popup to "mark all seen".
853 // Several people are complaining because there are unseen messages they can't find and as time goes
854 // on they just get buried deeper. It has happened to me a couple of times also.
857 if((! $group) && (! $cid) && (! $star)) {
858 $r = q("UPDATE `item` SET `unseen` = 0
859 WHERE `unseen` = 1 AND `uid` = %d",
865 $r = q("UPDATE `item` SET `unseen` = 0 $update_unseen");
868 // Set this so that the conversation function can find out contact info for our wall-wall items
869 $a->page_contact = $a->contact;
871 $mode = (($nouveau) ? 'network-new' : 'network');
873 $o .= conversation($a,$items,$mode,$update);
876 if(get_pconfig(local_user(),'system','infinite_scroll')) {
877 $o .= scroll_loader();
878 } elseif(!get_config('system', 'old_pager')) {
879 $o .= alt_pager($a,count($items));