function asset_lightbox in Asset 5
Same name and namespace in other branches
- 6 asset.module \asset_lightbox()
Integrate asset with lightbox
2 calls to asset_lightbox()
- asset_field_formatter in modules/
asset_content.inc - Prepare an individual item for viewing in a browser.
- asset_panels_content_gallery in asset_panels/
asset_panels.module - Output function for the 'node' content type. Outputs a node based on the module and delta supplied in the configuration.
File
- ./
asset.module, line 338
Code
function asset_lightbox($assets, $preview = FALSE, $teaser = FALSE) {
if (!$preview && file_exists(path_to_theme() . "/lightbox/lightbox.js")) {
// Do not include Lightbox integration in preview mode: it breaks the jQuery fieldsets
drupal_add_js(path_to_theme() . "/lightbox/prototype.js");
drupal_add_js(path_to_theme() . "/lightbox/scriptaculous.js?load=effects");
drupal_add_js(path_to_theme() . "/lightbox/lightbox.js");
drupal_add_css(path_to_theme() . "/lightbox/lightbox.css");
}
$output = "";
$is_image = array(
'jpg',
'jpeg',
'png',
'gif',
'tif',
'tiff',
'bmp',
);
$is_audio = array(
'mp3',
'wma',
'wav',
'ogg',
'm4a',
'aac',
);
$count = 1;
$total = 3;
$imgpresent = 1;
$imgcount = 0;
$imgdisplay = 0;
$firstimg = "";
foreach ($assets as $asset) {
$a = asset_load(array(
'aid' => $asset['aid'],
));
if (in_array($a->extension, $is_image)) {
// If it's an image and imagecache configuration has been done, display the imagecached version
$imagecache = asset_get_default_formatter('local', $a->extension, $teaser);
if (function_exists('theme_imagecache') && substr($imagecache, 0, 11) == "imagecache:") {
list($imagecache, $preset) = split(":", $imagecache);
$img = theme('imagecache', $preset, $a->filepath, $asset['caption'], $asset['caption']);
}
else {
$img = theme('image', $a->filepath, $asset['caption'], $asset['caption']);
}
$link = '<a href="' . file_create_url($a->filepath) . '" rel="lightbox[gallery]" title="' . str_replace("\"", "'", $asset['caption']);
$link .= $asset['copyright'] ? '<br/>© ' . str_replace("\"", "'", $asset['copyright']) . '"' : '"';
// We only want to display $total thumbnails, but we need the html for the lightbox gallery
if ($count > $total) {
$link .= " style='display:none'";
}
else {
$imgdisplay++;
}
if (empty($firstimg)) {
$firstimg = $link . ">";
}
$link .= ">" . $img . "</a>";
$output .= $link;
if ($count <= $total) {
$output .= $asset['caption'] ? "<p>" . $asset['caption'] . "</p>" : "";
$output .= $asset['copyright'] ? "<p class='attribution'>© " . $asset['copyright'] . "</p>" : "";
$output .= "<br/>";
}
$imgcount++;
}
else {
// Not an image so automatically asset_preview() it
$output .= asset_preview($asset['aid']);
$output .= $asset['caption'] ? "<p>" . $asset['caption'] . "</p>" : "";
$output .= $asset['copyright'] ? "<p class='attribution'>© " . $asset['copyright'] . "</p>" : "";
if (in_array($a->extension, $is_audio)) {
$output .= '<p><a href="' . file_create_url($a->filepath) . '">' . t("Download this audio file") . '</a></p>';
}
}
$count++;
}
if (!empty($imgcount) && $imgcount > $imgdisplay) {
$firstimg = str_replace("style='display:none'", "", $firstimg);
$output .= t('<br/><div class="view-all-images">' . $firstimg . '%mycount </a></div>', array(
'%mycount' => format_plural($imgcount, 'View the image', 'View all @count images'),
));
}
return $output;
}