function gallery_assist_emulate_pager_pages in Gallery Assist 6
Function from ericpai to simulate a multiple pages pager. It calculate all necessary parameters to add pages links to the GA-Pager.
s
Parameters
object $node:
integer $page:
array $link:
Return value
a string containing the rendered pager.
2 calls to gallery_assist_emulate_pager_pages()
- gallery_assist_display in ./
gallery_assist_display.inc - Display the Gallery Assist Container as grid.
- gallery_assist_display_list in ./
gallery_assist_list_display.inc - Display the Gallery Assist Container as list.
File
- ./
gallery_assist.module, line 5719 - Drupal content type with gallery functionality.
Code
function gallery_assist_emulate_pager_pages(&$node, $page, $pages, $link) {
$nav = array();
for ($i = 1; $i < $pages + 1; $i++) {
if ($page == $i) {
// Bold the page and dont make it a link
$nav[] = '<b>' . $i . '</b>';
}
else {
// Link the page
$nav[] = l($i, "node/{$node->nid}", array(
'attributes' => array(
'title' => "{$page}/{$pages}",
),
'query' => array(
'page' => $i,
),
));
}
}
$my_n = $my_odd == 1 ? 0 : 1;
$my_page = $page;
$my_quantity = 4;
$my_middle = ceil($my_quantity / 2);
$my_short = 1;
$my_total = $pages;
$links = $nav;
if ($my_short == 1 && $my_total > $my_quantity) {
if ($my_page > $my_total - $my_quantity) {
if ($my_page + $my_middle - $my_odd < $my_total) {
$mysmall = array_slice($links, $my_page - $my_middle, $my_quantity, TRUE);
}
else {
$mysmall = array_slice($links, $my_total - $my_quantity, $my_quantity, TRUE);
}
}
elseif ($my_page <= $my_quantity) {
if ($my_page >= $my_middle) {
$mysmall = array_slice($links, $my_page - $my_middle, $my_quantity, TRUE);
}
else {
$mysmall = array_slice($links, 0, $my_quantity, TRUE);
}
}
else {
$mysmall = array_slice($links, $my_page - $my_middle, $my_middle + $my_middle - $my_odd, TRUE);
}
}
else {
$mysmall = $nav;
}
if ($my_total > $my_quantity) {
if (count($link) > 1) {
array_unshift($mysmall, $link[0]);
array_push($mysmall, $link[1]);
}
else {
if (count($link)) {
if (preg_match('/previou/', $link[0])) {
array_unshift($mysmall, $link[0]);
}
if (preg_match('/next/', $link[0])) {
array_push($mysmall, $link[0]);
}
}
}
}
$attributes = array(
'class' => "{$node->type} pager",
'style' => 'text-align: center;',
);
$my_pager = theme('item_list', $mysmall, NULL, 'ul', $attributes);
return $my_pager;
}