You are here

function template_preprocess_views_slideshow_galleria in Views Slideshow: Galleria 6

We'll grab only the first image from each row.

File

themes/views_slideshow_galleria.theme.inc, line 11
Theme & preprocess functions for the Views Slideshow: Galleria module.

Code

function template_preprocess_views_slideshow_galleria(&$vars) {

  // Initialize our $images array.
  $vars['images'] = array();
  $vars['original_rows'] = $vars['rows'];

  // Strip all images from the $rows created by the original view query.
  foreach ($vars['rows'] as $id => $item) {
    preg_match('@(<\\s*img\\s+[^>]*>)@i', $item, $matches);
    if ($image = $matches[1]) {

      // If our image is in an anchor tag, use its URL.
      preg_match('@<\\s*a\\s+href\\s*=\\s*"\\s*([^"]+)\\s*"[^>]*>[^<]*' . preg_quote($image) . '[^<]*<\\s*/a\\s*>@i', $item, $urls);
      if (isset($urls[1])) {
        $url = $urls[1];
      }
      else {

        // Otherwise link to the original image or the front page instead.
        preg_match('@src\\s*=\\s*"([^"]+)"@i', $image, $urls);
        $url = isset($urls[1]) ? $urls[1] : url('<front>');
      }

      // Ensure the link for the original image is preserved.
      // $url has already been url'ized.
      $vars['rows'][$id] = '<a href="' . $url . '">' . $image . '</a>';

      // Add the image to our image array to display.
      $vars['images'][$id] = $image;
    }
  }
  $options = $vars['options']['views_slideshow_galleria'];
  _views_slideshow_galleria_add_js($options, 'views-slideshow-galleria-images-' . $vars['id']);
  $vars['class'] = array(
    'views-slideshow-galleria-images',
    'galleria',
  );

  // Avoid flash of content.
  if ($options['advanced']['avoid_flash_of_content']) {
    $vars['class'][] = 'hidden';
  }
  $vars['classes'] = implode(' ', $vars['class']);
  drupal_add_css(drupal_get_path('module', 'views_slideshow_galleria') . '/themes/css/views_slideshow_galleria.css');
}