1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
<?php
/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */
/*
* List Header
*
* PHP version 5
*
* LICENSE: GNU General Public License, version 2 (GPLv2)
* Copyright (c) 2001 - 2011 Ampache.org All Rights Reserved
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License v2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @category Template
* @package Template
* @author Karl Vollmer <vollmer@ampache.org>
* @copyright 2001 - 2011 Ampache.org
* @license http://opensource.org/licenses/gpl-2.0 GPLv2
* @version PHP 5.2
* @link http://www.ampache.org/
* @since File available since Release 1.0
*/
/**
* List Header
* The default pager widget for moving through a list of many items.
* This relies heavily on the View object to get pieces about how
* to layout this page.
*/
// Pull these variables out to allow shorthand (easier for lazy programmers)
$limit = $browse->get_offset();
$start = $browse->get_start();
$total = $browse->get_total();
$uid = Config::get('list_header_uid');
$sides = 5;
// ++ the uid
Config::set('list_header_uid', $uid + 1, 1);
// Next
$next_offset = $start + $limit;
if ($next_offset > $total) { $next_offset = $start; }
// Prev
$prev_offset = $start - $limit;
if ($prev_offset < 0) { $prev_offset = '0'; }
/* Calculate how many pages total exist */
if ($limit > 0 && $total > $limit) {
$pages = ceil($total / $limit);
}
else {
$pages = 0;
}
// are there enough items to even need this view?
if ($pages > 1) {
/* Calculate current page and how many we have on each side */
$page_data = array('up' => array(), 'down' => array());
// Can't divide by 0
if ($start > 0) {
$current_page = floor($start / $limit);
}
else {
$current_page = 0;
}
// Create 10 pages in either direction
// Down first
$page = $current_page;
$i = 0;
while ($page > 0) {
if ($i == $sides) { $page_data['down'][1] = '...'; $page_data['down'][0] = '0'; break; }
$i++;
$page = $page - 1;
$page_data['down'][$page] = $page * $limit;
} // while page > 0
// Then up
$page = $current_page + 1;
$i = 0;
while ($page <= $pages) {
if ($page * $limit > $total) { break; }
if ($i == $sides) {
$key = $pages - 1;
if (!$page_data['up'][$key]) { $page_data['up'][$key] = '...'; }
$page_data['up'][$pages] = ($pages - 1) * $limit;
break;
}
$i++;
$page = $page + 1;
$page_data['up'][$page] = ($page - 1) * $limit;
} // end while
// Sort these arrays of hotness
ksort($page_data['up']);
ksort($page_data['down']);
?>
<div class="list-header">
<?php echo Ajax::text('?page=browse&action=page&browse_id=' . $browse->id . '&start=' . $prev_offset,_('Prev'),'browse_' . $uid . 'prev','','prev'); ?>
<?php echo Ajax::text('?page=browse&action=page&browse_id=' . $browse->id . '&start=' . $next_offset,_('Next'),'browse_' . $uid . 'next','','next'); ?>
<?php
/* Echo everything below us */
foreach ($page_data['down'] as $page => $offset) {
if ($offset === '...') { echo '... '; }
else {
// Hack Alert
$page++;
echo Ajax::text('?page=browse&action=page&browse_id=' . $browse->id . '&start=' . $offset,$page,'browse_' . $uid . 'page_' . $page,'','page-nb');
}
} // end foreach down
/* Echo current page */
$current_page++;
?>
<span class="page-nb selected"><?php echo $current_page; ?></span>
<?php
/* Echo everything above us */
foreach ($page_data['up'] as $page=>$offset) {
if ($offset === '...') { echo '... '; }
else {
echo Ajax::text('?page=browse&action=page&browse_id=' . $browse->id . '&start=' . $offset,$page,'browse_' . $uid . 'page_' . $page,'','page-nb');
} // end else
} // end foreach up
?>
</div>
<?php
} // if stuff
?>
|