function scald_gallery_scald_prerender in Scald: Gallery 7.2
Same name and namespace in other branches
- 7 scald_gallery.module \scald_gallery_scald_prerender()
Implements hook_scald_prerender().
For use with a player other than scald_galleria.
File
- ./
scald_gallery.module, line 271 - Scald Gallery is a Scald Atom Provider for image galleries.
Code
function scald_gallery_scald_prerender($atom, $context, $options, $mode) {
if ($mode == 'atom') {
$config = scald_context_config_load($context);
$player = $config->player['gallery']['*'];
if ('default' != $player) {
return;
}
// Prerender gallery as an image atom.
// Find out which transcoder is in use, and checks if it's
// one of the transcoder provided by Scald Image.
$style_name = NULL;
$mappings = NULL;
$transcoder = $config->transcoder['gallery']['*'];
// Image style support.
if (preg_match('/^style-(.*)$/', $transcoder, $match)) {
$style_name = $match[1];
}
elseif (module_exists('picture') && preg_match('/^group-(.*)$/', $transcoder, $match)) {
$mappings = picture_mapping_load($match[1]);
}
// Default attributes, which can be overridden by field settings.
$attributes = array(
'alt' => $atom->title,
'title' => $atom->title,
);
$items = field_get_items('scald_atom', $atom, 'scald_thumbnail');
$thumbnail = !empty($items) ? $items[0] : array();
foreach (array(
'alt',
'title',
'width',
'height',
) as $attribute_name) {
if (isset($thumbnail[$attribute_name]) && $thumbnail[$attribute_name]) {
$attributes[$attribute_name] = $thumbnail[$attribute_name];
}
}
if (!empty($style_name)) {
$atom->rendered->player = theme('image_style', array(
'path' => $atom->file_source,
'style_name' => $style_name,
) + $attributes);
}
elseif (isset($mappings)) {
foreach ($mappings->mapping as $breakpoint_name => $multipliers) {
if (!empty($multipliers)) {
foreach ($multipliers as $multiplier => $image_style) {
if (!$image_style) {
continue;
}
// $image_style is machine name in Picture 1.x and an array in
// Picture 2.x.
if (is_array($image_style) && $image_style['mapping_type'] === '_none') {
continue;
}
$fallback_image_style = is_array($image_style) ? $image_style['image_style'] : $image_style;
break 2;
}
}
}
// The fallback_image_style is the first image style we find, and so if it
// is empty then we do not have any image style.
if (!empty($fallback_image_style)) {
$atom->rendered->player = theme('picture', array(
'uri' => $atom->file_source,
'style_name' => $fallback_image_style,
'breakpoints' => $mappings->mapping,
) + $attributes);
}
}
else {
$path = empty($atom->rendered->file_transcoded_url) ? $atom->file_source : $atom->rendered->file_transcoded_url;
$atom->rendered->player = theme('image', array(
'path' => $path,
) + $attributes);
}
}
}