X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fnetwork.php;h=28893dda7bf0c85d6854ffbfb8ed49bb0547a493;hb=3303d9db7564cb73984755be5c54365d61653b8b;hp=fbfe2de4fd1775008adc2bc6506eef0db4b32b52;hpb=7b3c02057db47a627b56bdd79f1055ea7f876617;p=friendica.git diff --git a/mod/network.php b/mod/network.php index fbfe2de4fd..28893dda7b 100644 --- a/mod/network.php +++ b/mod/network.php @@ -6,11 +6,149 @@ function network_init(&$a) { notice( t('Permission denied.') . EOL); return; } - - $group_id = (($a->argc > 1 && intval($a->argv[1])) ? intval($a->argv[1]) : 0); + + $is_a_date_query = false; + + if($a->argc > 1) { + for($x = 1; $x < $a->argc; $x ++) { + if(is_a_date_arg($a->argv[$x])) { + $is_a_date_query = true; + break; + } + } + } + + // convert query string to array and remove first element (which is friendica args) + $query_array = array(); + parse_str($a->query_string, $query_array); + array_shift($query_array); + + // fetch last used network view and redirect if needed + if(! $is_a_date_query) { + $sel_tabs = network_query_get_sel_tab($a); + $sel_nets = network_query_get_sel_net(); + $sel_groups = network_query_get_sel_group($a); + $last_sel_tabs = get_pconfig(local_user(), 'network.view','tab.selected'); + $last_sel_nets = get_pconfig(local_user(), 'network.view', 'net.selected'); + $last_sel_groups = get_pconfig(local_user(), 'network.view', 'group.selected'); + + $remember_tab = ($sel_tabs[0] === 'active' && is_array($last_sel_tabs) && $last_sel_tabs[0] !== 'active'); + $remember_net = ($sel_nets === false && $last_sel_nets && $last_sel_nets !== 'all'); + $remember_group = ($sel_groups === false && $last_sel_groups && $last_sel_groups != 0); + + $net_baseurl = '/network'; + $net_args = array(); + + if($remember_group) { + $net_baseurl .= '/' . $last_sel_groups; // Note that the group number must come before the "/new" tab selection + } + else if($sel_groups !== false) { + $net_baseurl .= '/' . $sel_groups; + } + + if($remember_tab) { + // redirect if current selected tab is '/network' and + // last selected tab is _not_ '/network?f=&order=comment'. + // and this isn't a date query + + $tab_baseurls = array( + '', //all + '', //postord + '', //conv + '/new', //new + '', //starred + '', //bookmarked + '', //spam + ); + $tab_args = array( + 'f=&order=comment', //all + 'f=&order=post', //postord + 'f=&conv=1', //conv + '', //new + 'f=&star=1', //starred + 'f=&bmark=1', //bookmarked + 'f=&spam=1', //spam + ); + + $k = array_search('active', $last_sel_tabs); + + $net_baseurl .= $tab_baseurls[$k]; + + // parse out tab queries + $dest_qa = array(); + $dest_qs = $tab_args[$k]; + parse_str( $dest_qs, $dest_qa); + $net_args = array_merge($net_args, $dest_qa); + } + else if($sel_tabs[4] === 'active') { + // The '/new' tab is selected + $net_baseurl .= '/new'; + } + + if($remember_net) { + $net_args['nets'] = $last_sel_nets; + } + + if($remember_tab || $remember_net || $remember_group) { + $net_args = array_merge($query_array, $net_args); + $net_queries = build_querystring($net_args); + + // groups filter is in form of "network/nnn". Add it to $dest_url, if it's possible + //if ($a->argc==2 && is_numeric($a->argv[1]) && strpos($net_baseurl, "/",1)===false){ + // $net_baseurl .= "/".$a->argv[1]; + //} + + $redir_url = ($net_queries ? $net_baseurl."?".$net_queries : $net_baseurl); + goaway($a->get_baseurl() . $redir_url); + } + } + +/* $sel_tabs = network_query_get_sel_tab($a); + $last_sel_tabs = get_pconfig(local_user(), 'network.view','tab.selected'); + if (is_array($last_sel_tabs)){ + $tab_urls = array( + '/network?f=&order=comment',//all + '/network?f=&order=post', //postord + '/network?f=&conv=1', //conv + '/network/new', //new + '/network?f=&star=1', //starred + '/network?f=&bmark=1', //bookmarked + '/network?f=&spam=1', //spam + ); + + // redirect if current selected tab is 'no_active' and + // last selected tab is _not_ 'all_active'. + // and this isn't a date query + + if ($sel_tabs[0] == 'active' && $last_sel_tabs[0]!='active' && (! $is_a_date_query)) { + $k = array_search('active', $last_sel_tabs); + + // merge tab querystring with request querystring + $dest_qa = array(); + list($dest_url,$dest_qs) = explode("?", $tab_urls[$k]); + parse_str( $dest_qs, $dest_qa); + $dest_qa = array_merge($query_array, $dest_qa); + $dest_qs = build_querystring($dest_qa); + + // groups filter is in form of "network/nnn". Add it to $dest_url, if it's possible + if ($a->argc==2 && is_numeric($a->argv[1]) && strpos($dest_url, "/",1)===false){ + $dest_url .= "/".$a->argv[1]; + } + + goaway($a->get_baseurl() . $dest_url."?".$dest_qs); + } + }*/ + + if(x($_GET['nets']) && $_GET['nets'] === 'all') + unset($_GET['nets']); + + $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0); + + set_pconfig(local_user(), 'network.view', 'group.selected', $group_id); require_once('include/group.php'); require_once('include/contact_widgets.php'); + require_once('include/items.php'); if(! x($a->page,'aside')) $a->page['aside'] = ''; @@ -42,8 +180,9 @@ function network_init(&$a) { if(x($_GET,'search')) { $a->page['content'] .= '
"; var_dump($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active); killme(); + + $cmd = (($datequery) ? '' : $a->cmd); + $len_naked_cmd = strlen(str_replace('/new','',$cmd)); + // tabs $tabs = array( array( 'label' => t('Commented Order'), - 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '?f=&cid=' . $_GET['cid'] : ''), + 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=comment' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''), 'sel'=>$all_active, 'title'=> t('Sort by Comment Date'), ), array( 'label' => t('Posted Order'), - 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''), + 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''), 'sel'=>$postord_active, 'title' => t('Sort by Post Date'), ), array( 'label' => t('Personal'), - 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&conv=1', + 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&conv=1', 'sel' => $conv_active, 'title' => t('Posts that mention or involve you'), ), array( 'label' => t('New'), - 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . '/new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''), + 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ($len_naked_cmd ? '/' : '') . 'new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''), 'sel' => $new_active, 'title' => t('Activity Stream - by date'), ), array( 'label' => t('Starred'), - 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&star=1', + 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&star=1', 'sel'=>$starred_active, 'title' => t('Favourite Posts'), ), array( 'label' => t('Shared Links'), - 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&bmark=1', + 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&bmark=1', 'sel'=>$bookmarked_active, 'title'=> t('Interesting Links'), ), @@ -215,8 +434,12 @@ function network_content(&$a, $update = 0) { // 'title' => t('Posts flagged as SPAM'), // ), - ); + + // save selected tab, but only if not in search or file mode + if(!x($_GET,'search') && !x($_GET,'file')) { + set_pconfig( local_user(), 'network.view','tab.selected',array($all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) ); + } $arr = array('tabs' => $tabs); call_hooks('network_tabs', $arr); @@ -231,9 +454,6 @@ function network_content(&$a, $update = 0) { $contact_id = $a->cid; - $group = 0; - - $nouveau = false; require_once('include/acl_selectors.php'); $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0); @@ -248,17 +468,7 @@ function network_content(&$a, $update = 0) { $cmax = ((x($_GET,'cmax')) ? intval($_GET['cmax']) : 99); $file = ((x($_GET,'file')) ? $_GET['file'] : ''); - if(($a->argc > 2) && $a->argv[2] === 'new') - $nouveau = true; - if($a->argc > 1) { - if($a->argv[1] === 'new') - $nouveau = true; - else { - $group = intval($a->argv[1]); - $def_acl = array('allow_gid' => '<' . $group . '>'); - } - } if(x($_GET,'search') || x($_GET,'file')) $nouveau = true; @@ -278,6 +488,7 @@ function network_content(&$a, $update = 0) { if(strlen($str)) $def_acl = array('allow_cid' => $str); } + set_pconfig(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all')); if(! $update) { if($group) { @@ -368,44 +579,41 @@ function network_content(&$a, $update = 0) { } } - if((! $group) && (! $cid) && (! $update)) { + if((! $group) && (! $cid) && (! $update) && (! get_config('theme','hide_eventlist'))) { $o .= get_birthdays(); $o .= get_events(); } - if(! $update) { - // The special div is needed for liveUpdate to kick in for this page. - // We only launch liveUpdate if you aren't filtering in some incompatible - // way and also you aren't writing a comment (discovered in javascript). - - $o .= '' . "\r\n"; - $o .= "\r\n"; + $sql_extra3 = ''; + + if($datequery) { + $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery)))); + } + if($datequery2) { + $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2)))); } $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` "); + $sql_extra3 = (($nouveau) ? '' : $sql_extra3); if(x($_GET,'search')) { $search = escape_tags($_GET['search']); - $sql_extra .= sprintf(" AND ( `item`.`body` like '%s' OR `item`.`tag` like '%s' ) ", - dbesc(protect_sprintf('%' . $search . '%')), - dbesc(protect_sprintf('%]' . $search . '[%')) - ); + if (get_config('system','use_fulltext_engine')) { + if(strpos($search,'#') === 0) + $sql_extra .= sprintf(" AND (MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode)) ", + dbesc(protect_sprintf($search)) + ); + else + $sql_extra .= sprintf(" AND (MATCH(`item`.`body`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode)) ", + dbesc(protect_sprintf($search)), + dbesc(protect_sprintf($search)) + ); + } else { + $sql_extra .= sprintf(" AND ( `item`.`body` like '%s' OR `item`.`tag` like '%s' ) ", + dbesc(protect_sprintf('%' . $search . '%')), + dbesc(protect_sprintf('%]' . $search . '[%')) + ); + } } if(strlen($file)) { $sql_extra .= file_tag_file_query('item',unxmlify($file)); @@ -416,11 +624,19 @@ function network_content(&$a, $update = 0) { $myurl = substr($myurl,strpos($myurl,'://')+3); $myurl = str_replace('www.','',$myurl); $diasp_url = str_replace('/profile/','/u/',$myurl); - $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where ( `author-link` like '%s' or `tag` like '%s' or tag like '%s' )) ", - dbesc(protect_sprintf('%' . $myurl)), - dbesc(protect_sprintf('%' . $myurl . ']%')), - dbesc(protect_sprintf('%' . $diasp_url . ']%')) - ); + if (get_config('system','use_fulltext_engine')) + $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where (MATCH(`author-link`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(`tag`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode))) ", + dbesc(protect_sprintf($myurl)), + dbesc(protect_sprintf($myurl)), + dbesc(protect_sprintf($diasp_url)) + ); + else + $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where ( `author-link` like '%s' or `tag` like '%s' or tag like '%s' )) ", + dbesc(protect_sprintf('%' . $myurl)), + dbesc(protect_sprintf('%' . $myurl . ']%')), + dbesc(protect_sprintf('%' . $diasp_url . ']%')) + ); + } if($update) { @@ -430,20 +646,27 @@ function network_content(&$a, $update = 0) { } else { - $r = q("SELECT COUNT(*) AS `total` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - $sql_extra2 - $sql_extra $sql_nets ", - intval($_SESSION['uid']) - ); - - if(count($r)) { - $a->set_pager_total($r[0]['total']); - $itemspage_network = get_pconfig(local_user(),'system','itemspage_network'); - $a->set_pager_itemspage(((intval($itemspage_network)) ? $itemspage_network : 40)); + if(! get_pconfig(local_user(),'system','alt_pager')) { + $r = q("SELECT COUNT(*) AS `total` + FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 + AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 + $sql_extra2 $sql_extra3 + $sql_extra $sql_nets ", + intval($_SESSION['uid']) + ); + + if(count($r)) { + $a->set_pager_total($r[0]['total']); + } } + + $itemspage_network = get_pconfig(local_user(),'system','itemspage_network'); + $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 40); + if(($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) + $itemspage_network = $a->force_max_items; + + $a->set_pager_itemspage($itemspage_network); $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); } @@ -467,6 +690,7 @@ function network_content(&$a, $update = 0) { intval($_SESSION['uid']) ); + $update_unseen = ' WHERE uid = ' . intval($_SESSION['uid']) . " AND unseen = 1 $sql_extra $sql_nets"; } else { @@ -483,10 +707,11 @@ function network_content(&$a, $update = 0) { if($update) { $r = q("SELECT `parent` AS `item_id`, `contact`.`uid` AS `contact_uid` FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 + WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND + (`item`.`deleted` = 0 OR item.verb = '" . ACTIVITY_LIKE ."' OR item.verb = '" . ACTIVITY_DISLIKE . "') and `item`.`moderated` = 0 and `item`.`unseen` = 1 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - $sql_extra $sql_nets ", + $sql_extra3 $sql_extra $sql_nets ", intval(local_user()) ); } @@ -496,7 +721,7 @@ function network_content(&$a, $update = 0) { WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `item`.`parent` = `item`.`id` - $sql_extra $sql_nets + $sql_extra3 $sql_extra $sql_nets ORDER BY `item`.$ordering DESC $pager_sql ", intval(local_user()) ); @@ -514,7 +739,7 @@ function network_content(&$a, $update = 0) { $parents_str = implode(', ', $parents_arr); $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, - `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`, + `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`, `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` FROM `item`, `contact` @@ -532,6 +757,9 @@ function network_content(&$a, $update = 0) { } else { $items = array(); } + + if($parents_str) + $update_unseen = ' WHERE uid = ' . intval(local_user()) . ' AND unseen = 1 AND parent IN ( ' . dbesc($parents_str) . ' )'; } @@ -539,6 +767,15 @@ function network_content(&$a, $update = 0) { // level which items you've seen and which you haven't. If you're looking // at the top level network page just mark everything seen. + +// The $update_unseen is a bit unreliable if you have stuff coming into your stream from a new contact - +// and other feeds that bring in stuff from the past. One can't find it all. +// I'm reviving this block to mark everything seen on page 1 of the network as a temporary measure. +// The correct solution is to implement a network notifications box just like the system notifications popup +// with the ability in the popup to "mark all seen". +// Several people are complaining because there are unseen messages they can't find and as time goes +// on they just get buried deeper. It has happened to me a couple of times also. + if((! $group) && (! $cid) && (! $star)) { $r = q("UPDATE `item` SET `unseen` = 0 WHERE `unseen` = 1 AND `uid` = %d", @@ -546,6 +783,9 @@ function network_content(&$a, $update = 0) { ); } +// if($update_unseen) +// $r = q("UPDATE `item` SET `unseen` = 0 $update_unseen"); + // Set this so that the conversation function can find out contact info for our wall-wall items $a->page_contact = $a->contact; @@ -554,7 +794,12 @@ function network_content(&$a, $update = 0) { $o .= conversation($a,$items,$mode,$update); if(! $update) { - $o .= paginate($a); + if(! get_pconfig(local_user(),'system','alt_pager')) { + $o .= paginate($a); + } + else { + $o .= alt_pager($a,count($items)); + } } return $o;