Keeping an offset for page switching: This helps so that you don't see old messages

This commit is contained in:
Michael Vogel 2013-12-10 00:13:19 +01:00
parent d20d2f74ae
commit 7e5c8ab91c
3 changed files with 41 additions and 16 deletions

View file

@ -279,6 +279,9 @@ function paginate_data(&$a, $count=null) {
$stripped = trim($stripped,'/');
$pagenum = $a->pager['page'];
if (($a->page_offset != "") AND !strstr($stripped, "&offset="))
$stripped .= "&offset=".urlencode($a->page_offset);
if (!strstr($stripped, "?")) {
$pos = strpos($stripped, "&");
$stripped = substr($stripped, 0, $pos)."?".substr($stripped, $pos + 1);
@ -286,7 +289,6 @@ function paginate_data(&$a, $count=null) {
$url = $a->get_baseurl() . '/' . $stripped;
$data = array();
function _l(&$d, $name, $url, $text, $class="") {
@ -307,7 +309,7 @@ function paginate_data(&$a, $count=null) {
_l($data, "first", $url."&page=1", t('first'));
$numpages = $a->pager['total'] / $a->pager['itemspage'];
$numstart = 1;
@ -338,11 +340,11 @@ function paginate_data(&$a, $count=null) {
$lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);
_l($data, "last", $url."&page=$lastpage", t('last'));
if(($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0)
_l($data, "next", $url."&page=".($a->pager['page'] + 1), t('next'));
}
}
}
return $data;
@ -384,14 +386,14 @@ function alt_pager(&$a, $i) {
$data = paginate_data($a, $i);
$tpl = get_markup_template("paginate.tpl");
return replace_macros($tpl, array('pager' => $data));
}}
if(! function_exists('expand_acl')) {
/**
* Turn user/group ACLs stored as angle bracketed text into arrays
*
*
* @param string $s
* @return array
*/

View file

@ -473,6 +473,10 @@ if ($_GET["mode"] == "raw") {
if (($param != "page") AND ($param != "q"))
$reload_uri .= "&".$param."=".urlencode($value);
if (($a->page_offset != "") AND !strstr($reload_uri, "&offset="))
$reload_uri .= "&offset=".urlencode($a->page_offset);
$a->page['htmlhead'] .= <<< EOT
<script type="text/javascript">

View file

@ -194,8 +194,8 @@ function saved_searches($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'] : '')
@ -204,7 +204,7 @@ function saved_searches($search) {
. ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
. ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '');
;
$o = '';
$r = q("select `id`,`term` from `search` WHERE `uid` = %d",
@ -264,7 +264,7 @@ function network_query_get_sel_tab($a) {
$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';
}
@ -291,8 +291,8 @@ function network_query_get_sel_tab($a) {
if (($new_active == '')
&& ($starred_active == '')
if (($new_active == '')
&& ($starred_active == '')
&& ($bookmarked_active == '')
&& ($conv_active == '')
&& ($search_active == '')
@ -645,6 +645,7 @@ function network_content(&$a, $update = 0) {
$sql_extra3 = (($nouveau) ? '' : $sql_extra3);
//$sql_order = "`item`.`received`";
$sql_order = "";
$order_mode = "received";
if ($sql_table == "")
$sql_table = "`item`";
@ -673,6 +674,7 @@ function network_content(&$a, $update = 0) {
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)));
@ -680,6 +682,7 @@ function network_content(&$a, $update = 0) {
$sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
$sql_order = "`item`.`received`";
$order_mode = "received";
}
}
if(strlen($file)) {
@ -764,14 +767,22 @@ function network_content(&$a, $update = 0) {
// 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) {
@ -801,6 +812,7 @@ function network_content(&$a, $update = 0) {
$parents_arr = array();
$parents_str = '';
$date_offset = "";
if(count($r)) {
foreach($r as $rr)
@ -842,6 +854,13 @@ function network_content(&$a, $update = 0) {
$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) . ' )';
}