'/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'.
+ // 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];
}
}
if(x($_GET,'remove')) {
- q("delete from `search` where `uid` = %d and `term` = '%s' limit 1",
+ q("delete from `search` where `uid` = %d and `term` = '%s'",
intval(local_user()),
dbesc($search)
);
$a = get_app();
- $srchurl = '/network?f='
- . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
+ $srchurl = '/network?f='
+ . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
. ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
. ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
. ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
. ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
. ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '');
;
-
+
$o = '';
$r = q("select `id`,`term` from `search` WHERE `uid` = %d",
$spam_active = '';
$postord_active = '';
- if(($a->argc > 1 && $a->argv[1] === 'new')
+ if(($a->argc > 1 && $a->argv[1] === 'new')
|| ($a->argc > 2 && $a->argv[2] === 'new')) {
$new_active = 'active';
}
- if (($new_active == '')
- && ($starred_active == '')
+ if (($new_active == '')
+ && ($starred_active == '')
&& ($bookmarked_active == '')
&& ($conv_active == '')
&& ($search_active == '')
info( t('Group is empty'));
}
- $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 ) ";
+ $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 ";
+ $sql_extra = "";
+ //$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 ) ";
$o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
}
elseif($cid) {
$sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
$sql_extra3 = (($nouveau) ? '' : $sql_extra3);
- $sql_order = "`item`.`received`";
+ //$sql_order = "`item`.`received`";
+ $sql_order = "";
+ $order_mode = "received";
if ($sql_table == "")
$sql_table = "`item`";
if (get_config('system','only_tag_search'))
$tag = true;
- /*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`, `item`.`title`) 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($tag) {
- $sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ",
- dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG));
- $sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` ";
+ //$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ",
+ // dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG));
+ //$sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` ";
+
+ //$sql_order = "`term`.`tid`";
+
+ $sql_extra = "";
- $sql_order = "`term`.`tid`";
+ $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` ",
+ dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval(local_user()));
+
+ $sql_order = "`item`.`received`";
+ $order_mode = "received";
} else {
if (get_config('system','use_fulltext_engine'))
$sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
$sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
$sql_order = "`item`.`received`";
+ $order_mode = "received";
}
}
if(strlen($file)) {
$myurl = substr($myurl,strpos($myurl,'://')+3);
$myurl = str_replace('www.','',$myurl);
$diasp_url = str_replace('/profile/','/u/',$myurl);
- /*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))) ",
- //$sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where (`author-link` IN ('https://%s', 'http://%s') OR MATCH(`tag`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode))) ",
- //$sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)",
- 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 . ']%'))
- );*/
$sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)",
dbesc(protect_sprintf($myurl)),
$simple_update
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
$sql_extra $sql_nets
- ORDER BY $sql_order DESC $pager_sql ",
+ ORDER BY `item`.`received` DESC $pager_sql ",
intval($_SESSION['uid'])
);
// Normal conversation view
- if($order === 'post')
- $ordering = "`created`";
- else
- $ordering = "`commented`";
+ if($order === 'post') {
+ $ordering = "`created`";
+ if ($sql_order == "")
+ $order_mode = "created";
+ } else {
+ $ordering = "`commented`";
+ if ($sql_order == "")
+ $order_mode = "commented";
+ }
if ($sql_order == "")
$sql_order = "`item`.$ordering";
+ if (($_GET["offset"] != ""))
+ $sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"]));
+
// Fetch a page full of parent items for this page
if($update) {
- $r = q("SELECT `parent` AS `item_id`, `contact`.`uid` AS `contact_uid`
+ $r = q("SELECT `item`.`parent` AS `item_id`, `contact`.`uid` AS `contact_uid`
FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND
(`item`.`deleted` = 0 OR item.verb = '" . ACTIVITY_LIKE ."' OR item.verb = '" . ACTIVITY_DISLIKE . "')
$parents_arr = array();
$parents_str = '';
+ $date_offset = "";
if(count($r)) {
foreach($r as $rr)
if(! in_array($rr['item_id'],$parents_arr))
$parents_arr[] = $rr['item_id'];
- $parents_str = implode(', ', $parents_arr);
- $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
- `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 $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
- 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` IN ( %s )
- $sql_extra ",
- intval(local_user()),
- dbesc($parents_str)
- );
+ //$parents_str = implode(', ', $parents_arr);
+ // splitted into separate queries to avoid the problem with very long threads
+ // so always the last X comments are loaded
+ // This problem can occur expecially with imported facebook posts
+ $max_comments = get_config("system", "max_comments");
+ if ($max_comments == 0)
+ $max_comments = 1000;
+
+ $items = array();
+
+ foreach ($parents_arr AS $parents_str) {
+
+ $thread_items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
+ `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 $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
+ 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` IN ( %s )
+ $sql_extra ORDER BY `item`.`commented` DESC LIMIT %d",
+ intval(local_user()),
+ dbesc($parents_str),
+ intval($max_comments + 1)
+ );
+ $items = array_merge($items, $thread_items);
+ }
$items = conv_sort($items,$ordering);
} else {
$items = array();
}
+ if ($_GET["offset"] == "")
+ $date_offset = $items[0][$order_mode];
+ else
+ $date_offset = $_GET["offset"];
+
+ $a->page_offset = $date_offset;
+
if($parents_str)
$update_unseen = ' WHERE uid = ' . intval(local_user()) . ' AND unseen = 1 AND parent IN ( ' . dbesc($parents_str) . ' )';
}