You are here

views_nivo_slider.module in Views Nivo Slider 6

The implementation of Views Nivo Slider module.

File

views_nivo_slider.module
View source
<?php

/**
 * @file
 *  The implementation of Views Nivo Slider module.
 */

/**
 * Implementation of hook_views_api().
 */
function views_nivo_slider_views_api() {
  return array(
    'api' => 2,
  );
}

/**
 * Implementation of template preprocess for the view
 */
function template_preprocess_views_nivo_slider_view(&$vars) {
  $view = $vars['view'];
  $options = $vars['options'];
  $vars['views_nivo_slider_id'] = 'views-nivo-slider-' . $view->name . '-' . $view->current_display;
  $cfg = array();
  $cfg[$vars['views_nivo_slider_id']] = array(
    'effect' => $options['effect'],
    'slices' => $options['slices'],
    'animSpeed' => $options['animSpeed'],
    'pauseTime' => $options['pauseTime'],
    'directionNav' => $options['directionNav'],
    'directionNavHide' => $options['directionNavHide'],
    'controlNav' => $options['controlNav'],
    'controlNavThumbs' => $options['controlNavThumbs'],
    'controlNavThumbsSearch' => "/{$options['imagefield_preset']}/",
    'controlNavThumbsReplace' => "/{$options['controlNavThumbsIC']}/",
    'keyboardNav' => $options['keyboardNav'],
    'pauseOnHover' => $options['pauseOnHover'],
    'manualAdvance' => $options['manualAdvance'],
    'captionOpacity' => $options['captionOpacity'],
  );
  drupal_add_js(array(
    'views_nivo_slider' => $cfg,
  ), 'setting');
  $_path = drupal_get_path('module', 'views_nivo_slider');
  drupal_add_js($_path . '/js/jquery.nivo.slider.pack.js');
  drupal_add_js($_path . '/js/views_nivo_slider.js');
  drupal_add_css($_path . '/js/nivo-slider.css');

  // Style
  if ($options['style'] != 'none') {
    drupal_add_css($_path . '/styles/' . $options['style'] . '/custom-nivo-slider.css');
  }
}

/**
 * Implementation of template preprocess for the view fields
 */
function template_preprocess_views_nivo_slider_view_nivo_sliderfields(&$vars) {
  $view =& $vars['view'];
  $options = $vars['options'];
  $presetname = $view->style_options['imagefield_preset'];
  $thumbnail_url = $title = $link = NULL;

  // Force URL format for thumbnail_field
  if (isset($view->field[$options['thumbnail_field']])) {
    $view->field[$options['thumbnail_field']]->options['format'] = 'path_plain';
    $view->field[$options['thumbnail_field']]->options['alter']['make_link'] = 0;
  }

  // Title field formats
  if (isset($view->field[$options['title_field']])) {
    $view->field[$options['title_field']]->options['format'] = 'plain';
    $view->field[$options['title_field']]->options['alter']['make_link'] = 0;
    $view->field[$options['title_field']]->options['alter']['strip_tags'] = 1;
  }

  // link
  if (isset($view->field[$options['link_field']])) {

    //Node: Link
    if ($view->field[$options['link_field']]->definition['handler'] == 'views_handler_field_node_link') {
      $link = url('node/' . $view->result[$view->row_index]->nid);
    }
    else {
      $view->field[$options['link_field']]->options['format'] = 'plain';
    }
  }
  foreach ($view->field as $id => $field) {
    $field_output = $view->field[$id]
      ->theme($vars['row']);
    switch ($id) {
      case $options['thumbnail_field']:
        $thumbnail_url = $field_output;
        break;
      case $options['title_field']:
        $title = $field_output;
        break;
      case $options['link_field']:
        if ($field->definition['handler'] != 'views_handler_field_node_link') {
          $link = check_url($field_output);
        }
        break;
    }
  }
  $img = theme('imagecache', $presetname, $thumbnail_url, $title, $title, NULL, TRUE);
  if ($link) {
    $img = '<a href="' . $link . '" class="views-processed">' . $img . '</a>';
  }
  $vars['content'] = $img;
}

Functions

Namesort descending Description
template_preprocess_views_nivo_slider_view Implementation of template preprocess for the view
template_preprocess_views_nivo_slider_view_nivo_sliderfields Implementation of template preprocess for the view fields
views_nivo_slider_views_api Implementation of hook_views_api().