You are here

function slick_build_captions in Slick Carousel 7.2

Build lightbox captions.

1 call to slick_build_captions()
slick_get_media_switch in includes/slick.global.inc
Returns the media switch: colorbox/photobox, content, excluding iframe.

File

includes/slick.global.inc, line 172
Global functions across Slick field formatters and Views.

Code

function slick_build_captions($item, $file = array(), $settings = array()) {
  $title = empty($item['title']) ? '' : $item['title'];
  $alt = empty($item['alt']) ? '' : $item['alt'];
  $delta = $settings['delta'];
  $caption = '';
  $entity = $entity_type = NULL;

  // @todo FC.
  if (!empty($settings['entity'])) {
    $entity_type = $settings['entity_type'];
    $entity = $settings['entity'];
  }
  switch ($settings['box_caption']) {
    case 'auto':
      $caption = $alt ? $alt : $title;
      break;
    case 'alt':
      $caption = $alt;
      break;
    case 'title':
      $caption = $title;
      break;
    case 'alt_title':
    case 'title_alt':
      $alt = $alt ? '<p>' . $alt . '</p>' : '';
      $title = $title ? '<h2>' . $title . '</h2>' : '';
      $caption = $settings['box_caption'] == 'alt_title' ? $alt . $title : $title . $alt;
      break;
    case 'entity_title':
      $caption = '';
      if ($entity) {
        $caption = entity_label($entity_type, $entity);
      }
      break;
    case 'custom':
      $caption = '';
      if ($entity) {
        $options = array(
          'clear' => TRUE,
        );
        $caption = token_replace($settings['box_caption_custom'], array(
          $entity_type => $entity,
          'file' => (object) $file,
        ), $options);

        // Checks for multi-value text fields, and maps its delta to image.
        if (strpos($caption, ", <p>") !== FALSE) {
          $caption = str_replace(", <p>", '| <p>', $caption);
          $captions = explode("|", $caption);
          $caption = isset($captions[$delta]) ? $captions[$delta] : '';
        }
      }
      break;
    default:
      $caption = '';
  }
  $allowed_tags = array(
    'a',
    'em',
    'strong',
    'h2',
    'p',
    'span',
    'ul',
    'li',
  );
  return empty($caption) ? '' : filter_xss($caption, $allowed_tags);
}