4 function network_init(&$a) {
6 notice( t('Permission denied.') . EOL);
10 $is_a_date_query = false;
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 and remove first element (which is friendica args)
22 $query_array = array();
23 parse_str($a->query_string, $query_array);
24 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;
92 if($remember_tab || $remember_net || $remember_group) {
93 $net_args = array_merge($query_array, $net_args);
94 $net_queries = build_querystring($net_args);
96 // groups filter is in form of "network/nnn". Add it to $dest_url, if it's possible
97 //if ($a->argc==2 && is_numeric($a->argv[1]) && strpos($net_baseurl, "/",1)===false){
98 // $net_baseurl .= "/".$a->argv[1];
101 $redir_url = ($net_queries ? $net_baseurl."?".$net_queries : $net_baseurl);
102 goaway($a->get_baseurl() . $redir_url);
106 /* $sel_tabs = network_query_get_sel_tab($a);
107 $last_sel_tabs = get_pconfig(local_user(), 'network.view','tab.selected');
108 if (is_array($last_sel_tabs)){
110 '/network?f=&order=comment',//all
111 '/network?f=&order=post', //postord
112 '/network?f=&conv=1', //conv
113 '/network/new', //new
114 '/network?f=&star=1', //starred
115 '/network?f=&bmark=1', //bookmarked
116 '/network?f=&spam=1', //spam
119 // redirect if current selected tab is 'no_active' and
120 // last selected tab is _not_ 'all_active'.
121 // and this isn't a date query
123 if ($sel_tabs[0] == 'active' && $last_sel_tabs[0]!='active' && (! $is_a_date_query)) {
124 $k = array_search('active', $last_sel_tabs);
126 // merge tab querystring with request querystring
128 list($dest_url,$dest_qs) = explode("?", $tab_urls[$k]);
129 parse_str( $dest_qs, $dest_qa);
130 $dest_qa = array_merge($query_array, $dest_qa);
131 $dest_qs = build_querystring($dest_qa);
133 // groups filter is in form of "network/nnn". Add it to $dest_url, if it's possible
134 if ($a->argc==2 && is_numeric($a->argv[1]) && strpos($dest_url, "/",1)===false){
135 $dest_url .= "/".$a->argv[1];
138 goaway($a->get_baseurl() . $dest_url."?".$dest_qs);
142 if(x($_GET['nets']) && $_GET['nets'] === 'all')
143 unset($_GET['nets']);
145 $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
147 set_pconfig(local_user(), 'network.view', 'group.selected', $group_id);
149 require_once('include/group.php');
150 require_once('include/contact_widgets.php');
151 require_once('include/items.php');
153 if(! x($a->page,'aside'))
154 $a->page['aside'] = '';
156 $search = ((x($_GET,'search')) ? escape_tags($_GET['search']) : '');
158 if(x($_GET,'save')) {
159 $r = q("select * from `search` where `uid` = %d and `term` = '%s' limit 1",
160 intval(local_user()),
164 q("insert into `search` ( `uid`,`term` ) values ( %d, '%s') ",
165 intval(local_user()),
170 if(x($_GET,'remove')) {
171 q("delete from `search` where `uid` = %d and `term` = '%s'",
172 intval(local_user()),
177 // search terms header
178 if(x($_GET,'search')) {
179 $a->page['content'] .= '<h2>' . t('Search Results For:') . ' ' . $search . '</h2>';
182 $a->page['aside'] .= (feature_enabled(local_user(),'groups') ? group_side('network/0','network',true,$group_id) : '');
183 $a->page['aside'] .= posted_date_widget($a->get_baseurl() . '/network',local_user(),false);
184 $a->page['aside'] .= networks_widget($a->get_baseurl(true) . '/network',(x($_GET, 'nets') ? $_GET['nets'] : ''));
185 $a->page['aside'] .= saved_searches($search);
186 $a->page['aside'] .= fileas_widget($a->get_baseurl(true) . '/network',(x($_GET, 'file') ? $_GET['file'] : ''));
190 function saved_searches($search) {
192 if(! feature_enabled(local_user(),'savedsearch'))
197 $srchurl = '/network?f='
198 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
199 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
200 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
201 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
202 . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
203 . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
204 . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
205 . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '');
210 $r = q("select `id`,`term` from `search` WHERE `uid` = %d",
220 'term' => $rr['term'],
221 'encodedterm' => urlencode($rr['term']),
222 'delete' => t('Remove term'),
223 'selected' => ($search==$rr['term']),
229 $tpl = get_markup_template("saved_searches_aside.tpl");
230 $o = replace_macros($tpl, array(
231 '$title' => t('Saved Searches'),
233 '$searchbox' => search($search,'netsearch-box',$srchurl,true),
242 * Return selected tab from query
245 * '/network' => $no_active = 'active'
246 * '/network?f=&order=comment' => $comment_active = 'active'
247 * '/network?f=&order=post' => $postord_active = 'active'
248 * '/network?f=&conv=1', => $conv_active = 'active'
249 * '/network/new', => $new_active = 'active'
250 * '/network?f=&star=1', => $starred_active = 'active'
251 * '/network?f=&bmark=1', => $bookmarked_active = 'active'
252 * '/network?f=&spam=1', => $spam_active = 'active'
254 * @return Array ( $no_active, $comment_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active );
256 function network_query_get_sel_tab($a) {
258 $starred_active = '';
260 $bookmarked_active = '';
265 $postord_active = '';
267 if(($a->argc > 1 && $a->argv[1] === 'new')
268 || ($a->argc > 2 && $a->argv[2] === 'new')) {
269 $new_active = 'active';
272 if(x($_GET,'search')) {
273 $search_active = 'active';
276 if(x($_GET,'star')) {
277 $starred_active = 'active';
280 if(x($_GET,'bmark')) {
281 $bookmarked_active = 'active';
284 if(x($_GET,'conv')) {
285 $conv_active = 'active';
288 if(x($_GET,'spam')) {
289 $spam_active = 'active';
294 if (($new_active == '')
295 && ($starred_active == '')
296 && ($bookmarked_active == '')
297 && ($conv_active == '')
298 && ($search_active == '')
299 && ($spam_active == '')) {
300 $no_active = 'active';
303 if ($no_active=='active' && x($_GET,'order')) {
304 switch($_GET['order']){
305 case 'post': $postord_active = 'active'; $no_active=''; break;
306 case 'comment' : $all_active = 'active'; $no_active=''; break;
310 return array($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active);
314 * Return selected network from query
316 function network_query_get_sel_net() {
319 if(x($_GET,'nets')) {
320 $network = $_GET['nets'];
326 function network_query_get_sel_group($a) {
329 if($a->argc >= 2 && is_numeric($a->argv[1])) {
330 $group = $a->argv[1];
337 function network_content(&$a, $update = 0) {
339 require_once('include/conversation.php');
342 $_SESSION['return_url'] = $a->query_string;
346 $arr = array('query' => $a->query_string);
348 call_hooks('network_content_init', $arr);
351 $datequery = $datequery2 = '';
358 for($x = 1; $x < $a->argc; $x ++) {
359 if(is_a_date_arg($a->argv[$x])) {
361 $datequery2 = escape_tags($a->argv[$x]);
363 $datequery = escape_tags($a->argv[$x]);
364 $_GET['order'] = 'post';
367 elseif($a->argv[$x] === 'new') {
370 elseif(intval($a->argv[$x])) {
371 $group = intval($a->argv[$x]);
372 $def_acl = array('allow_gid' => '<' . $group . '>');
380 // TODO: fix this logic, reduce duplication
381 //$a->page['content'] .= '<div class="tabs-wrapper">';
383 list($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) = network_query_get_sel_tab($a);
384 // if no tabs are selected, defaults to comments
385 if ($no_active=='active') $all_active='active';
386 //echo "<pre>"; var_dump($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active); killme();
388 $cmd = (($datequery) ? '' : $a->cmd);
389 $len_naked_cmd = strlen(str_replace('/new','',$cmd));
394 'label' => t('Commented Order'),
395 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=comment' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
397 'title'=> t('Sort by Comment Date'),
400 'label' => t('Posted Order'),
401 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
402 'sel'=>$postord_active,
403 'title' => t('Sort by Post Date'),
407 'label' => t('Personal'),
408 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&conv=1',
409 'sel' => $conv_active,
410 'title' => t('Posts that mention or involve you'),
414 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ($len_naked_cmd ? '/' : '') . 'new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
415 'sel' => $new_active,
416 'title' => t('Activity Stream - by date'),
419 'label' => t('Starred'),
420 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&star=1',
421 'sel'=>$starred_active,
422 'title' => t('Favourite Posts'),
425 'label' => t('Shared Links'),
426 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&bmark=1',
427 'sel'=>$bookmarked_active,
428 'title'=> t('Interesting Links'),
431 // 'label' => t('Spam'),
432 // 'url'=>$a->get_baseurl(true) . '/network?f=&spam=1'
433 // 'sel'=> $spam_active,
434 // 'title' => t('Posts flagged as SPAM'),
439 if(feature_enabled(local_user(),'personal_tab')) {
441 'label' => t('Personal'),
442 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&conv=1',
443 'sel' => $conv_active,
444 'title' => t('Posts that mention or involve you'),
448 if(feature_enabled(local_user(),'new_tab')) {
451 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ($len_naked_cmd ? '/' : '') . 'new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
452 'sel' => $new_active,
453 'title' => t('Activity Stream - by date'),
457 if(feature_enabled(local_user(),'link_tab')) {
459 'label' => t('Shared Links'),
460 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&bmark=1',
461 'sel'=>$bookmarked_active,
462 'title'=> t('Interesting Links'),
466 if(feature_enabled(local_user(),'star_posts')) {
468 'label' => t('Starred'),
469 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&star=1',
470 'sel'=>$starred_active,
471 'title' => t('Favourite Posts'),
475 // Not yet implemented
477 /* if(feature_enabled(local_user(),'spam_filter')) {
479 'label' => t('Spam'),
480 'url'=>$a->get_baseurl(true) . '/network?f=&spam=1',
481 'sel'=> $spam_active,
482 'title' => t('Posts flagged as SPAM'),
486 // save selected tab, but only if not in search or file mode
487 if(!x($_GET,'search') && !x($_GET,'file')) {
488 set_pconfig( local_user(), 'network.view','tab.selected',array($all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) );
491 $arr = array('tabs' => $tabs);
492 call_hooks('network_tabs', $arr);
494 $o .= replace_macros(get_markup_template('common_tabs.tpl'), array('$tabs'=> $arr['tabs']));
496 // --- end item filter tabs
498 $contact_id = $a->cid;
500 require_once('include/acl_selectors.php');
502 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
503 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
504 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
505 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
506 $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0);
507 $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
508 $spam = ((x($_GET,'spam')) ? intval($_GET['spam']) : 0);
509 $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
510 $cmin = ((x($_GET,'cmin')) ? intval($_GET['cmin']) : 0);
511 $cmax = ((x($_GET,'cmax')) ? intval($_GET['cmax']) : 99);
512 $file = ((x($_GET,'file')) ? $_GET['file'] : '');
516 if(x($_GET,'search') || x($_GET,'file'))
519 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
522 $r = q("select id from contact where uid = %d and network = '%s' and self = 0",
523 intval(local_user()),
530 $str .= '<' . $rr['id'] . '>';
532 $def_acl = array('allow_cid' => $str);
534 set_pconfig(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all'));
538 if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
539 notice( sprintf( tt('Warning: This group contains %s member from an insecure network.',
540 'Warning: This group contains %s members from an insecure network.',
542 notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
546 nav_set_selected('network');
548 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
552 'allow_location' => $a->user['allow_location'],
553 'default_location' => $a->user['default-location'],
554 'nickname' => $a->user['nickname'],
555 'lockstate' => ((($group) || ($cid) || ($nets) || (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'),
556 'default_perms' => get_acl_permissions($a->user),
557 'acl' => populate_acl((($group || $cid || $nets) ? $def_acl : $a->user), $celeb),
558 'bang' => (($group || $cid || $nets) ? '!' : ''),
559 'visitor' => 'block',
560 'profile_uid' => local_user(),
561 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
564 $o .= status_editor($a,$x);
568 // We don't have to deal with ACLs on this page. You're looking at everything
569 // that belongs to you, hence you can see all of it. We will filter by group if
572 $sql_options = (($star) ? " and starred = 1 " : '');
573 $sql_options .= (($bmark) ? " and bookmark = 1 " : '');
575 //$sql_nets = (($nets) ? sprintf(" and `contact`.`network` = '%s' ", dbesc($nets)) : '');
576 $sql_nets = (($nets) ? sprintf(" and `item`.`network` = '%s' ", dbesc($nets)) : '');
578 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $sql_options ) ";
581 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
583 intval($_SESSION['uid'])
588 notice( t('No such group') . EOL );
589 goaway($a->get_baseurl(true) . '/network/0');
593 $contacts = expand_groups(array($group));
594 if((is_array($contacts)) && count($contacts)) {
595 $contact_str = implode(',',$contacts);
598 $contact_str = ' 0 ';
599 info( t('Group is empty'));
602 $sql_table = "`item` INNER JOIN (SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND (`contact-id` IN ($contact_str) OR `allow_gid` like '".protect_sprintf('%<'.intval($group).'>%')."') and deleted = 0 ORDER BY `created` DESC) AS `temp1` ON item.parent = `temp1`.parent ";
604 //$sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND ( `contact-id` IN ( $contact_str ) OR `allow_gid` like '" . protect_sprintf('%<' . intval($group) . '>%') . "' ) and deleted = 0 ) ";
605 $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
609 $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d
610 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
614 $sql_table = "`item` INNER JOIN (SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND `contact-id` = ".intval($cid)." and deleted = 0 ORDER BY `item`.`received` DESC) AS `temp1` ON item.parent = `temp1`.parent ";
616 //$sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND `contact-id` = " . intval($cid) . " and deleted = 0 ) ";
617 $o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o;
618 if($r[0]['network'] === NETWORK_OSTATUS && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
619 notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
624 notice( t('Invalid contact.') . EOL);
625 goaway($a->get_baseurl(true) . '/network');
630 if((! $group) && (! $cid) && (! $update) && (! get_config('theme','hide_eventlist'))) {
631 $o .= get_birthdays();
638 $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
641 $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
644 $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
645 $sql_extra3 = (($nouveau) ? '' : $sql_extra3);
646 //$sql_order = "`item`.`received`";
648 $order_mode = "received";
650 if ($sql_table == "")
651 $sql_table = "`item`";
653 if(x($_GET,'search')) {
654 $search = escape_tags($_GET['search']);
656 if(strpos($search,'#') === 0) {
658 $search = substr($search,1);
661 if (get_config('system','only_tag_search'))
665 //$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ",
666 // dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG));
667 //$sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` ";
669 //$sql_order = "`term`.`tid`";
673 $sql_table = sprintf("`item` 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` ",
674 dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval(local_user()));
676 $sql_order = "`item`.`received`";
677 $order_mode = "received";
679 if (get_config('system','use_fulltext_engine'))
680 $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
682 $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
684 $sql_order = "`item`.`received`";
685 $order_mode = "received";
689 $sql_extra .= file_tag_file_query('item',unxmlify($file));
693 $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
694 $myurl = substr($myurl,strpos($myurl,'://')+3);
695 $myurl = str_replace('www.','',$myurl);
696 $diasp_url = str_replace('/profile/','/u/',$myurl);
698 $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)",
699 dbesc(protect_sprintf($myurl)),
700 dbesc(protect_sprintf($myurl))
706 // only setup pagination on initial page view
711 if( (! get_config('alt_pager', 'global')) && (! get_pconfig(local_user(),'system','alt_pager')) ) {
712 $r = q("SELECT COUNT(*) AS `total`
713 FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
714 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
715 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
716 $sql_extra2 $sql_extra3
717 $sql_extra $sql_nets ",
718 intval($_SESSION['uid'])
722 $a->set_pager_total($r[0]['total']);
726 // check if we serve a mobile device and get the user settings
729 $itemspage_network = get_pconfig(local_user(),'system','itemspage_mobile_network');
730 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 20);
732 $itemspage_network = get_pconfig(local_user(),'system','itemspage_network');
733 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 40);
735 // now that we have the user settings, see if the theme forces
736 // a maximum item number which is lower then the user choice
737 if(($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network))
738 $itemspage_network = $a->force_max_items;
740 $a->set_pager_itemspage($itemspage_network);
741 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
744 $simple_update = (($update) ? " and `item`.`unseen` = 1 " : '');
747 // "New Item View" - show all items unthreaded in reverse created date order
749 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
750 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
751 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
752 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
753 FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
754 WHERE `item`.`uid` = %d AND `item`.`visible` = 1
755 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
757 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
759 ORDER BY `item`.`received` DESC $pager_sql ",
760 intval($_SESSION['uid'])
763 $update_unseen = ' WHERE uid = ' . intval($_SESSION['uid']) . " AND unseen = 1 $sql_extra $sql_nets";
767 // Normal conversation view
770 if($order === 'post') {
771 $ordering = "`created`";
772 if ($sql_order == "")
773 $order_mode = "created";
775 $ordering = "`commented`";
776 if ($sql_order == "")
777 $order_mode = "commented";
780 if ($sql_order == "")
781 $sql_order = "`item`.$ordering";
783 if (($_GET["offset"] != ""))
784 $sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"]));
786 // Fetch a page full of parent items for this page
789 $r = q("SELECT `item`.`parent` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
790 FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
791 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND
792 (`item`.`deleted` = 0 OR item.verb = '" . ACTIVITY_LIKE ."' OR item.verb = '" . ACTIVITY_DISLIKE . "')
793 and `item`.`moderated` = 0 and `item`.`unseen` = 1
794 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
795 $sql_extra3 $sql_extra $sql_nets ",
800 $r = q("SELECT `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
801 FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
802 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
803 AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
804 AND `item`.`parent` = `item`.`id`
805 $sql_extra3 $sql_extra $sql_nets
806 ORDER BY $sql_order DESC $pager_sql ",
811 // Then fetch all the children of the parents that are on this page
813 $parents_arr = array();
819 if(! in_array($rr['item_id'],$parents_arr))
820 $parents_arr[] = $rr['item_id'];
822 //$parents_str = implode(', ', $parents_arr);
824 // splitted into separate queries to avoid the problem with very long threads
825 // so always the last X comments are loaded
826 // This problem can occur expecially with imported facebook posts
827 $max_comments = get_config("system", "max_comments");
828 if ($max_comments == 0)
829 $max_comments = 1000;
833 foreach ($parents_arr AS $parents_str) {
835 $thread_items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
836 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,
837 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
838 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
839 FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
840 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
841 AND `item`.`moderated` = 0
842 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
843 AND `item`.`parent` IN ( %s )
844 $sql_extra ORDER BY `item`.`commented` DESC LIMIT %d",
845 intval(local_user()),
847 intval($max_comments + 1)
849 $items = array_merge($items, $thread_items);
851 $items = conv_sort($items,$ordering);
857 if ($_GET["offset"] == "")
858 $date_offset = $items[0][$order_mode];
860 $date_offset = $_GET["offset"];
862 $a->page_offset = $date_offset;
865 $update_unseen = ' WHERE uid = ' . intval(local_user()) . ' AND unseen = 1 AND parent IN ( ' . dbesc($parents_str) . ' )';
868 // We aren't going to try and figure out at the item, group, and page
869 // level which items you've seen and which you haven't. If you're looking
870 // at the top level network page just mark everything seen.
873 // The $update_unseen is a bit unreliable if you have stuff coming into your stream from a new contact -
874 // and other feeds that bring in stuff from the past. One can't find it all.
875 // I'm reviving this block to mark everything seen on page 1 of the network as a temporary measure.
876 // The correct solution is to implement a network notifications box just like the system notifications popup
877 // with the ability in the popup to "mark all seen".
878 // Several people are complaining because there are unseen messages they can't find and as time goes
879 // on they just get buried deeper. It has happened to me a couple of times also.
881 if((! $group) && (! $cid) && (! $star)) {
882 $r = q("UPDATE `item` SET `unseen` = 0
883 WHERE `unseen` = 1 AND `uid` = %d",
889 $r = q("UPDATE `item` SET `unseen` = 0 $update_unseen");
892 // Set this so that the conversation function can find out contact info for our wall-wall items
893 $a->page_contact = $a->contact;
895 $mode = (($nouveau) ? 'network-new' : 'network');
897 $o .= conversation($a,$items,$mode,$update);
900 if( get_config('alt_pager', 'global') || get_pconfig(local_user(),'system','alt_pager') ) {
901 $o .= alt_pager($a,count($items));