photoswipe.theme.inc in PhotoSwipe 7.2
Same filename and directory in other branches
Photoswipe theme functions.
File
photoswipe.theme.incView source
<?php
/**
* @file
* Photoswipe theme functions.
*/
/**
* Returns HTML for an Photoswipe image field formatter.
*
* @param $variables
* An associative array containing:
* - item: An array of image data.
* - image_style: An optional image style.
* - path: An array containing the link 'path' and link 'options'.
*
* @ingroup themeable
*/
function theme_photoswipe_image_formatter($variables) {
$item = $variables['item'];
$node = $variables['node'];
$field = $variables['field'];
$settings = $variables['display_settings'];
$alt = !empty($item['alt']) ? $item['alt'] : '';
$title = !empty($item['title']) ? $item['title'] : '';
if (empty($alt) && !empty($item['field_file_image_alt_text'][LANGUAGE_NONE])) {
$alt = $item['field_file_image_alt_text'][LANGUAGE_NONE][0]['value'];
}
if (empty($title) && !empty($item['field_file_image_title_text'][LANGUAGE_NONE])) {
$title = $item['field_file_image_title_text'][LANGUAGE_NONE][0]['value'];
}
$image = array(
'path' => $item['uri'],
'alt' => $alt,
'title' => $title,
'style_name' => $settings['photoswipe_node_style'],
);
if ($variables['delta'] == 0 && !empty($settings['photoswipe_node_style_first'])) {
$image['style_name'] = $settings['photoswipe_node_style_first'];
}
$dimensions = array();
if (isset($item['width']) && isset($item['height'])) {
$image['width'] = $dimensions['width'] = $item['width'];
$image['height'] = $dimensions['height'] = $item['height'];
}
if ($style_name = $settings['photoswipe_image_style']) {
$path = image_style_url($style_name, $image['path']);
$dimensions = array(
'width' => $item['width'],
'height' => $item['height'],
);
image_style_transform_dimensions($style_name, $dimensions);
}
else {
$path = file_create_url($image['path']);
}
// Set Caption for this image
if (isset($settings['photoswipe_caption'])) {
$caption_setting = $settings['photoswipe_caption'];
switch ($caption_setting) {
case 'alt':
$caption = $image[$caption_setting];
break;
case 'title':
$caption = $image[$caption_setting];
break;
case 'node_title':
$caption = $node->title;
break;
default:
$view_mode = $settings['photoswipe_view_mode'] ? $settings['photoswipe_view_mode'] : 'default';
$field_view = field_view_field('node', $node, $caption_setting, $view_mode);
$caption = drupal_render($field_view);
break;
}
}
else {
$caption = $alt;
}
return theme('photoswipe_imagefield', array(
'image' => $image,
'path' => $path,
'dimensions' => $dimensions['width'] . 'x' . $dimensions['height'],
'caption' => $caption,
));
}
/**
* Returns HTML for an image using a specific Photoswipe image style.
*
* @param $variables
* An associative array containing:
* - image: image item as array.
* - path: The path of the image that should be displayed in the Photoswipe.
*
* @ingroup themeable
*/
function theme_photoswipe_imagefield($variables) {
$class = array(
'photoswipe',
);
if (!empty($variables['image']['style_name'])) {
if ($variables['image']['style_name'] == 'hide') {
$image = '<!-- hidden image -->';
}
else {
$image = theme('image_style', $variables['image']);
}
}
else {
$image = theme('image', $variables['image']);
}
$options = array(
'html' => TRUE,
'attributes' => array(
'class' => implode(' ', $class),
'data-size' => $variables['dimensions'],
'data-overlay-title' => $variables['caption'],
),
);
return l($image, $variables['path'], $options);
}
Functions
Name | Description |
---|---|
theme_photoswipe_imagefield | Returns HTML for an image using a specific Photoswipe image style. |
theme_photoswipe_image_formatter | Returns HTML for an Photoswipe image field formatter. |