1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-21 16:22:22 +02:00

Added generate_pagination routine

git-svn-id: file:///svn/phpbb/trunk@265 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2001-05-07 23:04:16 +00:00
parent 2d6c917744
commit 2efd2e97b8
3 changed files with 87 additions and 71 deletions

View File

@ -280,11 +280,88 @@ function append_sid($url)
if(!empty($SID) && !eregi("^http:", $url) && !eregi("sid=", $url))
{
$url = ereg_replace("[&?]+$", "", $url);
$url .= ( strpos($url, "?") != false ? "&" : "?" ) . $SID;
$url .= ( (strpos($url, "?") != false) ? "&" : "?" ) . $SID;
}
return($url);
}
//
// Pagination routine, generates
// page number sequence
//
function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = TRUE)
{
global $l_prevpage, $l_nextpage;
$total_pages = ceil($num_items/$per_page);
if($total_pages == 1)
{
return "";
}
$on_page = floor($start_item/$per_page);
$page_string = "";
$this_block_start = ($on_page < 10) ? 1 : floor($on_page/10) * 10;
$this_block_end = ($on_page < 10) ? 9 : $this_block_start + 9;
if($this_block_end > $total_pages)
{
$this_block_end = $total_pages;
}
for($i = $this_block_start; $i <= $this_block_end; $i++)
{
$page_string .= ($i == $on_page + 1) ? "<b>$i</b>" : "<a href=\"".append_sid($base_url."&start=".(($i-1)*$per_page))."\">$i</a>";
if($i < $this_block_end)
{
$page_string .= ", ";
}
}
if($this_block_start > 1)
{
$page_string_prepend = "";
for($i = 0; $i < $this_block_start; $i+=10)
{
$page_string_prepend .= "<a href=\"".append_sid($base_url."&start=".($i*$per_page))."\">" . ( ($i == 0) ? ($i+1) : $i) . " - " . ($i+9) . "</a>, ";
}
$page_string = $page_string_prepend . $page_string;
}
if($this_block_end < $total_pages)
{
$page_string_append = ", ";
for($i = $this_block_end + 1; $i < $total_pages; $i+=10)
{
$page_string_append .= "<a href=\"".append_sid($base_url."&start=".($i*$per_page))."\">" . ( ($i == 0) ? ($i+1) : $i) . " - " . ((($i+9) < $total_pages) ? ($i+9) : $total_pages) ."</a>";
if($i < $total_pages - 10)
{
$page_string_append .= ", ";
}
}
$page_string .= $page_string_append;
}
if($add_prevnext_text)
{
if($on_page > 0)
{
$page_string = "<a href=\"".append_sid($base_url."&start=".(($on_page - 1)*$per_page))."\">$l_prevpage</a> : " . $page_string;
}
if($on_page < $total_pages-1)
{
$page_string .= " : <a href=\"".append_sid($base_url."&start=".(($on_page + 1)*$per_page))."\">$l_nextpage</a>";
}
}
return $page_string;
}
?>

View File

@ -6,7 +6,8 @@
* copyright : (C) 2001 The phpBB Group
* email : support@phpbb.com
*
* $Id$ *
* $Id$
*
*
***************************************************************************/
@ -89,6 +90,7 @@ if(!$forum_row)
$forum_name = stripslashes($forum_row[0]["forum_name"]);
$topics_count = $forum_row[0]["forum_topics"];
for($x = 0; $x < $db->sql_numrows($result); $x++)
{
if($x > 0)
@ -197,39 +199,13 @@ if($total_topics)
"LAST_POST_USER" => $last_post_user,
"U_VIEW_TOPIC" => $view_topic_url,
"U_LAST_POST_USER_PROFILE" => $last_post_profile_url));
}
$count = 1;
$next = $start + $board_config['topics_per_page'];
if($topics_count > $board_config['topics_per_page'])
{
if($next < $topics_count)
{
$pagination = "<a href=\"".append_sid("viewforum.$phpEx?".POST_FORUM_URL."=$forum_id&start=$next")."\">$l_nextpage</a> | ";
}
for($x = 0; $x < $topics_count; $x++)
{
if(!($x % $board_config['topics_per_page']))
{
if($x == $start)
{
$pagination .= "$count";
}
else
{
$pagination .= " <a href=\"".append_sid("viewforum.$phpEx?".POST_FORUM_URL."=$forum_id&start=$x")."\">$count</a> ";
}
$count++;
if(!($count % 20))
{
$pagination .= "<br>";
}
}
}
"U_LAST_POST_USER_PROFILE" => $last_post_profile_url)
);
}
$template->assign_vars(array(
"PAGINATION" => $pagination));
"PAGINATION" => generate_pagination("viewforum.$phpEx?".POST_FORUM_URL."=$forum_id", $topics_count, $board_config['topics_per_page'], $start))
);
$template->pparse("body");
}
else

View File

@ -293,43 +293,6 @@ if($total_replies > $board_config['posts_per_page'])
$times++;
}
$pages = $times . " $l_pages";
$times = 1;
$pagination = "$l_gotopage (";
$last_page = $start - $board_config['posts_per_page'];
if($start > 0)
{
$pagination .= "<a href=\"".append_sid("$PHP_SELF?".POST_TOPIC_URL."=$topic_id&start=$last_page")."\">$l_prevpage</a> ";
}
for($x = 0; $x < $total_replies; $x += $board_config['posts_per_page'])
{
if($times != 1)
{
$pagination .= " | ";
}
if($start && ($start == $x))
{
$pagination .= $times;
}
else if($start == 0 && $x == 0)
{
$pagination .= "1";
}
else
{
$pagination .= "<a href=\"".append_sid("$PHP_SELF?".POST_TOPIC_URL."=$topic_id&start=$x")."\">$times</a>";
}
$times++;
}
if(($start + $board_config['posts_per_page']) < $total_replies)
{
$next_page = $start + $board_config['posts_per_page'];
$pagination .= " <a href=\"".append_sid("$PHP_SELF?".POST_TOPIC_URL."=$topic_id&start=$next_page")."\">$l_nextpage</a>";
}
$pagination .= " )";
}
else
{
@ -338,7 +301,7 @@ else
$template->assign_vars(array(
"PAGES" => $pages,
"PAGINATION" => $pagination));
"PAGINATION" => generate_pagination("viewtopic.$phpEx?".POST_TOPIC_URL."=$topic_id", $total_replies, $board_config['posts_per_page'], $start)));
$template->pparse("body");