aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorpatdenice <patdenice@piwigo.org>2009-03-05 21:08:04 +0000
committerpatdenice <patdenice@piwigo.org>2009-03-05 21:08:04 +0000
commit254aee26953b4e862b73467968f92138a6283da1 (patch)
treef2a78dbce4e54be16dd1698b67bb4a5df2d9c0d1 /include
parentd3e6eabb053f311d5d8fd4ec80cfb0c1b32cf141 (diff)
Create navigation_bar.tpl file.
Move create_navigation_bar function from functions_html.inc.php to functions.inc.php. git-svn-id: http://piwigo.org/svn/trunk@3172 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r--include/functions.inc.php69
-rw-r--r--include/functions_html.inc.php147
-rw-r--r--include/picture_comment.inc.php2
3 files changed, 70 insertions, 148 deletions
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 83c9980de..3f43b943a 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -1493,4 +1493,73 @@ function get_comment_post_key($image_id)
)
);
}
+
+/**
+ * return an array which will be sent to template to display navigation bar
+ */
+function create_navigation_bar($url, $nb_element, $start, $nb_element_page, $clean_url = false)
+{
+ global $conf;
+
+ $pages_around = $conf['paginate_pages_around'];
+ $start_str = $clean_url ? '/start-' : (strpos($url, '?')===false ? '?':'&amp;').'start=';
+
+ if (!isset($start) or !is_numeric($start) or (is_numeric($start) and $start < 0))
+ {
+ $start = 0;
+ }
+
+ $navbar = array();
+
+ // navigation bar useful only if more than one page to display !
+ if ($nb_element > $nb_element_page)
+ {
+ // current page and last page
+ $cur_page = ceil($start / $nb_element_page) + 1;
+ $maximum = ceil($nb_element / $nb_element_page);
+
+ $navbar['CURRENT_PAGE'] = $cur_page;
+
+ // link to first page ?
+ if ($cur_page != 1)
+ {
+ $navbar['URL_FIRST'] = $url;
+ }
+ // link on previous page ?
+ if ($start != 0)
+ {
+ $previous = $start - $nb_element_page;
+ $navbar['URL_PREV'] = $url.($previous > 0 ? $start_str.$previous : '');
+ }
+ // link on next page ?
+ if ($nb_element > $nb_element_page and $start + $nb_element_page < $nb_element)
+ {
+ $next = $start + $nb_element_page;
+ $navbar['URL_NEXT'] = $url.$start_str.$next;
+ }
+ // link to last page ?
+ if ($cur_page != $maximum)
+ {
+ $temp_start = ($maximum - 1) * $nb_element_page;
+ $navbar['URL_LAST'] = $url.$start_str.$temp_start;
+ }
+
+ // pages to display
+ $navbar['pages'] = array();
+
+ $navbar['pages'][1] = $url;
+ $navbar['pages'][$maximum] = $url.$start_str. ($maximum - 1) * $nb_element_page;
+
+ for ($i = $cur_page - $pages_around, $stop = $cur_page + $pages_around + 1; $i < $stop; $i++)
+ {
+ if ($i < 2 or $i > $maximum - 1)
+ {
+ continue;
+ }
+ $navbar['pages'][$i] = $url.$start_str. ($i - 1) * $nb_element_page;
+ }
+ ksort($navbar['pages']);
+ }
+ return $navbar;
+}
?> \ No newline at end of file
diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php
index 9b045bfcb..45e5e04eb 100644
--- a/include/functions_html.inc.php
+++ b/include/functions_html.inc.php
@@ -73,153 +73,6 @@ function get_icon($date, $is_child_date = false)
return $cache['get_icon']['_icons_'][$is_child_date];
}
-function create_navigation_bar(
- $url, $nb_element, $start, $nb_element_page, $clean_url = false
- )
-{
- global $conf;
-
- $pages_around = $conf['paginate_pages_around'];
- $start_str = $clean_url ? '/start-' :
- ( ( strpos($url, '?')===false ? '?':'&amp;') . 'start=' );
-
- $navbar = '';
-
- // current page detection
- if (!isset($start)
- or !is_numeric($start)
- or (is_numeric($start) and $start < 0))
- {
- $start = 0;
- }
-
- // navigation bar useful only if more than one page to display !
- if ($nb_element > $nb_element_page)
- {
- // current page and last page
- $cur_page = ceil($start / $nb_element_page) + 1;
- $maximum = ceil($nb_element / $nb_element_page);
-
- // link to first page ?
- if ($cur_page != 1)
- {
- $navbar.=
- '<a href="'.$url.'" rel="first">'
- .l10n('first_page')
- .'</a>';
- }
- else
- {
- $navbar.= l10n('first_page');
- }
- $navbar.= ' | ';
- // link on previous page ?
- if ($start != 0)
- {
- $previous = $start - $nb_element_page;
-
- $navbar.=
- '<a href="'
- .$url.($previous > 0 ? $start_str.$previous : '')
- .'" rel="prev">'
- .l10n('previous_page')
- .'</a>';
- }
- else
- {
- $navbar.= l10n('previous_page');
- }
- $navbar.= ' |';
-
- if ($cur_page > $pages_around + 1)
- {
- $navbar.= '&nbsp;<a href="'.$url.'">1</a>';
-
- if ($cur_page > $pages_around + 2)
- {
- $navbar.= ' ...';
- }
- }
-
- // inspired from punbb source code
- for ($i = $cur_page - $pages_around, $stop = $cur_page + $pages_around + 1;
- $i < $stop;
- $i++)
- {
- if ($i < 1 or $i > $maximum)
- {
- continue;
- }
- else if ($i != $cur_page)
- {
- $temp_start = ($i - 1) * $nb_element_page;
-
- $navbar.=
- '&nbsp;'
- .'<a href="'.$url
- .($temp_start > 0 ? $start_str.$temp_start : '')
- .'">'
- .$i
- .'</a>';
- }
- else
- {
- $navbar.=
- '&nbsp;'
- .'<span class="pageNumberSelected">'
- .$i
- .'</span>';
- }
- }
-
- if ($cur_page < ($maximum - $pages_around))
- {
- $temp_start = ($maximum - 1) * $nb_element_page;
-
- if ($cur_page < ($maximum - $pages_around - 1))
- {
- $navbar.= ' ...';
- }
-
- $navbar.= ' <a href="'.$url.$start_str.$temp_start.'">'.$maximum.'</a>';
- }
-
- $navbar.= ' | ';
- // link on next page ?
- if ($nb_element > $nb_element_page
- and $start + $nb_element_page < $nb_element)
- {
- $next = $start + $nb_element_page;
-
- $navbar.=
- '<a href="'.$url.$start_str.$next.'" rel="next">'
- .l10n('next_page')
- .'</a>';
- }
- else
- {
- $navbar.= l10n('next_page');
- }
-
- $navbar.= ' | ';
- // link to last page ?
- if ($cur_page != $maximum)
- {
- $temp_start = ($maximum - 1) * $nb_element_page;
-
- $navbar.=
- '<a href="'.$url.$start_str.$temp_start.'" rel="last">'
- .l10n('last_page')
- .'</a>';
- }
- else
- {
- $navbar.= l10n('last_page');
- }
- }
- return $navbar;
-}
-
/**
* returns the list of categories as a HTML string
*
diff --git a/include/picture_comment.inc.php b/include/picture_comment.inc.php
index 73b245b6b..2682d9dab 100644
--- a/include/picture_comment.inc.php
+++ b/include/picture_comment.inc.php
@@ -112,7 +112,7 @@ SELECT COUNT(*) AS nb_comments
$template->assign(
array(
'COMMENT_COUNT' => $row['nb_comments'],
- 'COMMENT_NAV_BAR' => $navigation_bar,
+ 'navbar' => $navigation_bar,
)
);