[geeklog-hg] geeklog: Slightly optimized the COM_printPageNavigation function
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Mon Sep 17 04:12:29 EDT 2012
changeset 8816:157946fb898f
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/157946fb898f
user: dengen
date: Mon Sep 17 17:11:45 2012 +0900
description:
Slightly optimized the COM_printPageNavigation function
diffstat:
public_html/lib-common.php | 158 ++++++++++++++++++++------------------------
1 files changed, 71 insertions(+), 87 deletions(-)
diffs (200 lines):
diff -r a4042dbb5629 -r 157946fb898f public_html/lib-common.php
--- a/public_html/lib-common.php Mon Sep 17 16:04:50 2012 +0900
+++ b/public_html/lib-common.php Mon Sep 17 17:11:45 2012 +0900
@@ -5462,10 +5462,14 @@
if (function_exists('CUSTOM_printPageNavigation')) {
return CUSTOM_printPageNavigation($base_url, $curpage, $num_pages, $page_str, $do_rewrite, $msg, $open_ended);
}
-
+
+ if ($num_pages < 2) {
+ return '';
+ }
+
$first_url = '';
- $last_url = '';
-
+ $last_url = '';
+
if (is_array($base_url)) {
$first_url = current($base_url);
$last_url = end($base_url);
@@ -5473,114 +5477,94 @@
$first_url = $base_url;
}
- if ($num_pages < 2) {
- return;
- }
-
if (!$do_rewrite) {
- $hasargs = strstr($first_url, '?');
- if ($hasargs) {
- $sep = '&';
- } else {
- $sep = '?';
- }
+ $sep = strstr($first_url, '?') ? '&' : '?';
} else {
$sep = '/';
$page_str = '';
}
-
- $page_navigation = COM_newTemplate($_CONF['path_layout'] . 'page_navigation/');
- $page_navigation->set_file(array('page_navigation' => 'page_navigation.thtml',
- 'page_navigation_start' => 'page_navigation_start.thtml',
- 'page_navigation_end' => 'page_navigation_end.thtml',
- 'page' => 'page.thtml',
- 'page_current' => 'page_current.thtml',
- 'page_open_ended' => 'page_navigation_open_ended.thtml'));
-
+
+ $page_navigation = COM_newTemplate($_CONF['path_layout'] . 'page_navigation');
+ $page_navigation->set_file(array('page_navigation' => 'page_navigation.thtml',
+ 'page_navigation_start' => 'page_navigation_start.thtml',
+ 'page_navigation_end' => 'page_navigation_end.thtml',
+ 'page' => 'page.thtml',
+ 'page_current' => 'page_current.thtml',
+ 'page_open_ended' => 'page_navigation_open_ended.thtml'));
$page_navigation->set_var('lang_first', $LANG05[7]);
$page_navigation->set_var('lang_previous', $LANG05[6]);
$page_navigation->set_var('lang_next', $LANG05[5]);
$page_navigation->set_var('lang_last', $LANG05[8]);
-
+
if ($curpage > 1) {
- $pg = '';
- if (($curpage - 1) > 1) {
- $pg = $sep . $page_str . ( $curpage - 1 );
- }
-
- $page_navigation->set_var('start_first_anchortag', '<a href="' . $first_url . $last_url . '">');
- $page_navigation->set_var('end_first_anchortag', '</a>');
- $page_navigation->set_var('start_previous_anchortag', '<a href="' . $first_url . $pg . $last_url . '">');
- $page_navigation->set_var('end_previous_anchortag', '</a>');
+ $pg = '';
+ if (($curpage - 1) > 1) {
+ $pg = $sep . $page_str . ($curpage - 1);
+ }
+ $page_navigation->set_var('start_first_anchortag', '<a href="' . $first_url . $last_url . '">');
+ $page_navigation->set_var('end_first_anchortag', '</a>');
+ $page_navigation->set_var('start_previous_anchortag', '<a href="' . $first_url . $pg . $last_url . '">');
+ $page_navigation->set_var('end_previous_anchortag', '</a>');
} else {
- $page_navigation->set_var('start_first_anchortag', '');
+ $page_navigation->set_var('start_first_anchortag', '');
$page_navigation->set_var('end_first_anchortag', '');
$page_navigation->set_var('start_previous_anchortag', '');
$page_navigation->set_var('end_previous_anchortag', '');
}
$page_navigation->parse('page_navigation_start', 'page_navigation_start');
-
- $page_nav_split = intval($_CONF['page_navigation_max_pages'] / 2);
- $page_start = $curpage - $page_nav_split;
- if (intval($_CONF['page_navigation_max_pages'] / 2) == ($_CONF['page_navigation_max_pages'] / 2)) { // For even number Max Pages
- if ($page_start <= 0) {
- $page_end = $curpage + $page_nav_split - $page_start;
- $page_start = 1;
- } else {
- $page_end = $curpage + $page_nav_split - 1;
- }
- } else { // For odd number Max Pages
- if ($page_start <= 0) {
- $page_end = $curpage + $page_nav_split - $page_start + 1;
- $page_start = 1;
- } else {
- $page_end = $curpage + $page_nav_split;
- }
- }
+
+ $page_nav_left = intval($_CONF['page_navigation_max_pages'] / 2);
+ $page_nav_right = $_CONF['page_navigation_max_pages'] - $page_nav_left - 1;
+ $page_start = $curpage - $page_nav_left;
+ $odd = 0;
+ if ($page_start < 1) {
+ $odd = 1 - $page_start;
+ $page_start = 1;
+ }
+ $page_end = $curpage + $page_nav_right + $odd;
if ($page_end > $num_pages) {
- $page_start = $curpage - $page_nav_split - ($page_end - $num_pages);
+ $odd = $page_end - $num_pages;
$page_end = $num_pages;
- }
- if ($page_start <= 0) {
- $page_start = 1;
- }
-
- for ($pgcount = $page_start; ($pgcount <= $page_end) AND ($pgcount <= $num_pages); $pgcount++) {
+ if ($page_start - $odd >= 1) {
+ $page_start = $page_start - $odd;
+ }
+ }
+ for ($pgcount = $page_start; $pgcount <= $page_end; $pgcount++) {
if ($pgcount == $curpage) {
- $page_navigation->set_var('page_number', $pgcount);
- $page_navigation->parse('pages', 'page_current', true);
- } else {
- $pg = '';
- if ($pgcount > 1) {
- $pg = $sep . $page_str . $pgcount;
- }
- $page_navigation->set_var('page_number', COM_createLink($pgcount, $first_url . $pg . $last_url));
- $page_navigation->parse( 'pages', 'page', true );
- }
- }
-
- if (!empty($open_ended)) {
+ $page_navigation->set_var('page_number', $pgcount);
+ $page_navigation->parse('pages', 'page_current', true);
+ continue;
+ }
+ $pg = '';
+ if ($pgcount > 1) {
+ $pg = $sep . $page_str . $pgcount;
+ }
+ $page_navigation->set_var('page_number', COM_createLink($pgcount, $first_url . $pg . $last_url));
+ $page_navigation->parse('pages', 'page', true);
+ }
+
+ if (!empty($open_ended)) {
$page_navigation->set_var('open_ended', $open_ended);
$page_navigation->parse('page_navigation_end', 'page_open_ended');
- } else {
- if ( $curpage == $num_pages ) {
+ } else {
+ if ($curpage == $num_pages) {
$page_navigation->set_var('start_next_anchortag', '');
$page_navigation->set_var('end_next_anchortag', '');
- $page_navigation->set_var('start_last_anchortag', '');
- $page_navigation->set_var('end_last_anchortag', '');
- } else {
- $page_navigation->set_var('start_next_anchortag', '<a href="' . $first_url . $sep . $page_str . ($curpage + 1) . $last_url . '">');
- $page_navigation->set_var('end_next_anchortag', '</a>');
- $page_navigation->set_var('start_last_anchortag', '<a href="' . $first_url . $sep . $page_str . $num_pages . $last_url . '">');
- $page_navigation->set_var('end_last_anchortag', '</a>');
- }
- $page_navigation->parse('page_navigation_end', 'page_navigation_end');
- }
-
- if (!empty($msg)) {
- $page_navigation->set_var('message', $msg . ' ');
- }
+ $page_navigation->set_var('start_last_anchortag', '');
+ $page_navigation->set_var('end_last_anchortag', '');
+ } else {
+ $page_navigation->set_var('start_next_anchortag', '<a href="' . $first_url . $sep . $page_str . ($curpage + 1) . $last_url . '">');
+ $page_navigation->set_var('end_next_anchortag', '</a>');
+ $page_navigation->set_var('start_last_anchortag', '<a href="' . $first_url . $sep . $page_str . $num_pages . $last_url . '">');
+ $page_navigation->set_var('end_last_anchortag', '</a>');
+ }
+ $page_navigation->parse('page_navigation_end', 'page_navigation_end');
+ }
+
+ if (!empty($msg)) {
+ $page_navigation->set_var('message', $msg . ' ');
+ }
return $page_navigation->finish($page_navigation->parse('output', 'page_navigation'));
}
More information about the geeklog-cvs
mailing list