function node_gallery_get_images_slice in Node Gallery 6.3
Returns a specific slice of the node_gallery_get_images() array. If both $to_left and $to_right are not set or are 0, this returns only 1 element.
Parameters
$gallery: Node object representing the gallery
$image_nid: Nid of the current image
$to_left: Integer representing the first position to return
$to_right: Integer representing the last position to return
1 call to node_gallery_get_images_slice()
- node_gallery_json_get_images in ./
node_gallery.pages.inc - Page callback for json image object requests.
File
- ./
node_gallery.inc, line 440 - Shared functions for node_gallery
Code
function node_gallery_get_images_slice($gallery, $image_nid, $to_left = 0, $to_right = 0) {
$images = node_gallery_get_images($gallery);
$last_element = count($images) - 1;
$range = array();
$current_element = node_gallery_get_image_position($gallery->nid, $image_nid) - 1;
$offset = $current_element - $to_left < 0 ? 0 : $current_element - $to_left;
$end = $current_element + $to_right > $last_element ? $last_element : $current_element + $to_right;
$length = $end - $offset + 1;
$range = array_slice($images, $offset, $length);
return $range;
}