You are here

function views_slideshow_ddblock_add_image in Views Slideshow: Dynamic Display Block 6

Add slide image variable helper function

Parameters

$vars - An array of variables to pass to the theme template.: $image_type - Slider image or pager image $cck_imagefield - CCK generated image field name $alt - Alternative text for the image $cck_content_type - Content type for getting default image $cck_field_name - CCK field name for getting default image $link - URL to link the image to

File

./views_slideshow_ddblock.module, line 99
Views Slideshow: ddblock adds ddblock functionality to Views Slideshows.

Code

function views_slideshow_ddblock_add_image($vars, $image_type, $cck_image_field, $alt = NULL, $cck_content_type = NULL, $cck_field_name = NULL, $link = NULL) {
  $link_prefix = '';
  $link_suffix = '';
  if ($vars['views_slideshow_ddblock_slider_settings']['imgcache_toggle'] == 1 && $image_type == 'slider_item_image' && module_exists('imagecache') && is_array(imagecache_presets())) {
    $used_image_type = $vars['views_slideshow_ddblock_slider_settings']['imgcache_slide'];
  }
  if ($vars['views_slideshow_ddblock_pager_settings']['imgcache_toggle'] == 1 && $image_type == 'pager_item_image' && module_exists('imagecache') && is_array(imagecache_presets())) {
    $used_image_type = $vars['views_slideshow_ddblock_pager_settings']['imgcache_pager_item'];
  }

  // add slide_image variable
  if (isset($cck_image_field)) {

    // get image id
    $fid = $cck_image_field;

    // get path to image
    $filepath = db_result(db_query("SELECT filepath FROM {files} WHERE fid = %d", $fid));
  }
  else {
    if (module_exists('imagefield')) {

      // cck fieldname, cck content type in use
      $field = content_fields($cck_field_name, $cck_content_type);
      if (!empty($field)) {
        $filepath = $field['widget']['default_image']['filepath'];
      }
    }
  }

  // if image or default imga e exists
  if (!empty($filepath)) {

    // add link to image if link exsist
    if (!empty($link)) {
      $link_prefix = '<a href="' . $link . '">';
      $link_suffix = '</a>';
    }

    //  use imagecache (imagecache, preset_name, file_path, alt, title, array of attributes)
    if ($used_image_type != '<none>') {
      $image = $link_prefix . theme('imagecache', $used_image_type, $filepath, check_plain($alt)) . $link_suffix;
    }
    else {
      $image = $link_prefix . '<img src="' . base_path() . $filepath . '" alt="' . check_plain($alt) . '"/>' . $link_suffix;
    }
  }
  return $image;
}