Snippety pro Drupal 5:
Doplnění textové navigace do galerie obrázků modulu Image.
Jako základ bylo použito řešení Add a << first < previous next > last >> Pager to Image Nodes Within a Gallery doplněné o lokalizaci.
/**
* Image Gallery Pager
*/
function custom_pager($current_nid, $class = NULL) {
$tid = reset(array_keys(taxonomy_node_get_terms($current_nid)));
$result = db_query(db_rewrite_sql('SELECT n.nid, n.title FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid = %s AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC, n.nid DESC'), $tid);
while ($node = db_fetch_object($result)) {
$nodes[++$i] = $node;
if ($node->nid == $current_nid) $x = $i;
}
if($x > 1) {
$output .= l(t('« first'), 'node/'. $nodes[1]->nid, array('title' => check_plain($nodes[1]->title), 'class' => $class), NULL, NULL, FALSE, TRUE);
$output .= l(t('‹ previous'), 'node/'. $nodes[$x-1]->nid, array('title' => check_plain($nodes[$x-1]->title), 'class' => $class), NULL, NULL, FALSE, TRUE);
}
else {
// not required
// $output .= '<span class="">' . t(t('« first')) . ' </span>' . '<span class="">' . t('‹ previous') . ' </span>';
}
$output .= $x .' ('. $i .')';
if($x < $i) {
$output .= l(t('next ›'), 'node/'. $nodes[$x+1]->nid, array('title' => check_plain($nodes[$x+1]->title), 'class' => $class), NULL, NULL, FALSE, TRUE);
$output .= l(t('last »'), 'node/'. $nodes[$i]->nid, array('title' => check_plain($nodes[$i]->title), 'class' => $class), NULL, NULL, FALSE, TRUE);
}
else {
// not required
// $output .= '<span class="">' . t(t('next ›')) . ' </span>' . '<span class="">' . t(t('last »')) . ' </span>';
}
return $output;
}
<!-- Image Gallery Pager -->
<div class="pager">
<?php if ($page != 0 && $terms) { print custom_pager($node->nid); } ?>
</div>
Doplnění navigace s náhledy do galerie obrázků u modulu Image.
Jako základ bylo použito řešení Pager with thumbnails doplněné o lokalizaci, číslování a velikosti náhledů.
/**
* Image Gallery Pager with thumbnails
*/
function custom_pager_thumbnails($current_nid, $class = NULL) {
$tid = reset(array_keys(taxonomy_node_get_terms($current_nid)));
$result = db_query(db_rewrite_sql('SELECT n.nid, n.title, f.filepath FROM {node} n INNER JOIN {term_node} tn INNER JOIN {files} f ON n.nid = tn.nid AND n.nid = f.nid WHERE tn.tid = %s AND n.status = 1 AND f.filename = \'%s\' ORDER BY n.sticky DESC, n.created DESC, n.nid DESC'), $tid, 'thumbnail');
while ($node = db_fetch_object($result)) {
$nodes[++$i] = $node;
if ($node->nid == $current_nid) $x = $i;
// image size
$image_info = image_get_info($nodes[$i]->filepath);
$image_width[$i] = $image_info['width'];
$image_height[$i] = $image_info['height'];
}
if ($i < 6) {
while (++$j <= $i) {
$output .= l('<img src="' . check_url(url('system/files/' . $nodes[$j]->filepath)) . '" alt="'. check_plain($nodes[$j]->title) . '" width="'. $image_width[$j] .'" height="'. $image_height[$j] .'" />', 'node/'. $nodes[$j]->nid, array('title' => check_plain($nodes[$j]->title), 'class' => $class), NULL, NULL, FALSE, TRUE);
}
}
else {
switch ($x) {
case 1:
// first image
$y = array($i-1, $i, 1, 2, 3);
break;
case 2:
// second image
$y = array($i, 1, 2, 3, 4);
break;
case $i-1:
// penultimate image
$y = array($x-2, $x-1, $x, $i, 1);
break;
case $i:
// last image
$y = array($x-2, $x-1, $x, 1, 2);
break;
default:
$y = array($x-2, $x-1, $x, $x+1, $x+2);
}
foreach($y as $index => $z) {
if ($index != 2) {
$output .= l('<img src="' . check_url(url('system/files/' . $nodes[$z]->filepath)) . '" alt="'. check_plain($nodes[$z]->title) . '" width="'. $image_width[$z] .'" height="'. $image_height[$z] .'" />', 'node/'. $nodes[$z]->nid, array('title' => '('. ($z) .') '. check_plain($nodes[$z]->title), 'class' => $class), NULL, NULL, FALSE, TRUE);
}
else {
$output .= '<span class="active" title="('. ($z) .') '. check_plain($nodes[$z]->title) .'"><img src="' . check_url(url('system/files/' . $nodes[$z]->filepath)) . '" alt="'. check_plain($nodes[$z]->title) . '" width="'. $image_width[$z] .'" height="'. $image_height[$z] .'" /></span>';
}
}
}
return $output;
}
<!-- Image Gallery Pager with thumbnails -->
<div class="pager">
<?php if ($page != 0 && $terms) { print custom_pager_thumbnails($node->nid); } ?>
</div>
/* Theme snippet: Image Gallery Pager with thumbnails */
#content .pager {
margin-top: 3px;
margin-bottom: 3px;
}
#content .pager img {
margin-bottom: 3px;
vertical-align: middle;
}
#content .pager .active img {
border: 5px solid #f93;
margin-bottom: 0;
}