You are here

function royalsliderfield_preprocess_royalsliderfield_slide in RoyalSlider Integration 7

Implements hook_preprocess_HOOK().

Preprocess theme variables for each RoyalSlider slide.

File

contrib/royalsliderfield/royalsliderfield.module, line 365
RoyalSlider Field module.

Code

function royalsliderfield_preprocess_royalsliderfield_slide(&$variables) {

  // Only set slider dimensions once.
  static $slider_size_added = FALSE;
  $optionset = $variables['optionset'];
  $slide = $variables['slide'];

  // Extract necessary details from the optionset.
  $skin = $optionset->skin;
  $imagestyle_fullscreen = $optionset->imagestyle_fullscreen;
  $imagestyle_normal = $optionset->imagestyle_normal;
  $imagestyle_thumbnail = $optionset->imagestyle_thumbnail;
  $attributes = array();
  $variables['rs_image'] = $slide['rs_image'];
  $variables['rs_caption'] = $slide['rs_caption'];
  $variables['rs_video'] = $slide['rs_video'];
  $variables['rs_content'] = $slide['rs_content'];
  $variables['format'] = $slide['format'];
  $variables['rs_link'] = $slide['rs_link'];
  $variables['content'] = '';

  // Image.
  $img_uri = $img_uri_normal = $img_uri_fullscreen = $img_uri_thumbnail = '';
  $img_url = $img_url_normal = $img_url_fullscreen = $img_url_thumbnail = '';
  $dimensions = array();
  if (isset($slide) && ($fid = $slide['rs_image'])) {
    $file = file_load($fid);
    $img_uri = $img_uri_normal = $img_uri_fullscreen = $img_uri_thumbnail = $file->uri;
    $img_url = $img_url_normal = $img_url_fullscreen = $img_url_thumbnail = file_create_url($file->uri);

    // Update image URLs for the defined image styles.
    //
    // Full Screen image style URL.
    if (!empty($imagestyle_fullscreen)) {
      $img_uri_fullscreen = image_style_path($imagestyle_fullscreen, $img_uri);
      $img_url_fullscreen = image_style_url($imagestyle_fullscreen, $img_uri);
    }

    // Normal image style URL.
    if (!empty($imagestyle_normal)) {
      $img_uri_normal = image_style_path($imagestyle_normal, $img_uri);
      $img_url_normal = image_style_url($imagestyle_normal, $img_uri);
    }

    // Thumbnail image style URL.
    if (!empty($imagestyle_thumbnail)) {
      $img_uri_thumbnail = image_style_path($imagestyle_thumbnail, $img_uri);
      $img_url_thumbnail = image_style_url($imagestyle_thumbnail, $img_uri);
    }

    // Full Screen support.
    if ($optionset->options['fullscreen']['enabled']) {
      $attributes['data-rsBigImg'] = $img_url_fullscreen;
    }

    // Thumbnail navigation.
    if ($optionset->options['controlNavigation'] === 'thumbnails') {
      $attributes['data-rsTmb'] = $img_url_thumbnail;
    }

    // Image dimensions.
    $dimensions = array();
    $image = image_get_info($img_uri_normal);
    if ($optionset->options['drupalAutoSetImageDimensions']) {
      $dimensions = array(
        'width' => $image['width'],
        'height' => $image['height'],
      );
      $attributes['data-rsw'] = $dimensions['width'];
      $attributes['data-rsh'] = $dimensions['height'];
    }
    else {
      if (isset($optionset->options['imgWidth'])) {
        $dimensions['width'] = $optionset->options['imgWidth'];
        $attributes['data-rsw'] = $optionset->options['imgWidth'];
      }
      if (isset($optionset->options['imgHeight'])) {
        $dimensions['height'] = $optionset->options['imgHeight'];
        $attributes['data-rsh'] = $optionset->options['imgHeight'];
      }
    }
    $attributes['alt'] = $slide['rs_caption'];
    $attributes['title'] = $slide['rs_caption'];
    $attributes['class'] = 'rsImg';

    // Set slider dimensions.
    if ($optionset->options['autoScaleSlider']) {

      // Only add them once.
      if (!$slider_size_added) {
        drupal_add_js(array(
          'royalslider' => array(
            'instances' => array(
              $variables['royalslider_id'] => array(
                'slider_height' => $dimensions['height'],
                'slider_width' => $dimensions['width'],
              ),
            ),
          ),
        ), 'setting');
      }
      $slider_size_added = TRUE;
    }
    $rs_image = '';
    if ($rs_video = royalsliderfield_get_video_id($slide['rs_video'])) {
      $attributes['data-rsVideo'] = $slide['rs_video'];
    }
    if ($optionset->options['usePreloader']) {
      $rs_image = l($variables['rs_caption'], $img_url_normal, array(
        'attributes' => $attributes,
      ));
    }
    else {
      $rs_image = theme('image', array(
        'attributes' => $attributes,
        'path' => $img_uri_normal,
      ));
    }
    $variables['content'] = $rs_image;
  }
  if (!empty($slide['rs_content'])) {
    $variables['content'] .= '<div class="rsContent-content">' . check_markup($slide['rs_content'], $slide['format']) . '</div>';
  }
  $onclick = '';
  if (!empty($slide['rs_link'])) {
    $onclick = ' data-rslink="' . url($slide['rs_link']) . '"';
  }
  $variables['content'] = '<div class="rsContent"' . $onclick . '>' . $variables['content'] . '</div>';
}