diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index c36b56710e..a3ccbe7e4e 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -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) ? "$i" : "$i";
+ 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 .= "" . ( ($i == 0) ? ($i+1) : $i) . " - " . ($i+9) . ", ";
+ }
+
+ $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 .= "" . ( ($i == 0) ? ($i+1) : $i) . " - " . ((($i+9) < $total_pages) ? ($i+9) : $total_pages) ."";
+ if($i < $total_pages - 10)
+ {
+ $page_string_append .= ", ";
+ }
+ }
+
+ $page_string .= $page_string_append;
+ }
+
+ if($add_prevnext_text)
+ {
+ if($on_page > 0)
+ {
+ $page_string = "$l_prevpage : " . $page_string;
+ }
+ if($on_page < $total_pages-1)
+ {
+ $page_string .= " : $l_nextpage";
+ }
+ }
+
+ return $page_string;
+
+}
+
?>
\ No newline at end of file
diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php
index 98c55cf796..7f0d727668 100644
--- a/phpBB/viewforum.php
+++ b/phpBB/viewforum.php
@@ -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 = "$l_nextpage | ";
- }
- for($x = 0; $x < $topics_count; $x++)
- {
- if(!($x % $board_config['topics_per_page']))
- {
- if($x == $start)
- {
- $pagination .= "$count";
- }
- else
- {
- $pagination .= " $count ";
- }
- $count++;
- if(!($count % 20))
- {
- $pagination .= "
";
- }
- }
- }
+ "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
diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php
index 2bc2de4e39..8be3e6b7c8 100644
--- a/phpBB/viewtopic.php
+++ b/phpBB/viewtopic.php
@@ -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 .= "$l_prevpage ";
- }
-
- 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 .= "$times";
- }
- $times++;
- }
-
- if(($start + $board_config['posts_per_page']) < $total_replies)
- {
- $next_page = $start + $board_config['posts_per_page'];
- $pagination .= " $l_nextpage";
- }
- $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");