You are here

function views_handler_field_amazon_image::render in Amazon Product Advertisement API 6

Same name and namespace in other branches
  1. 7.2 includes/views_handler_field_amazon_image.inc \views_handler_field_amazon_image::render()
  2. 7 includes/views_handler_field_amazon_image.inc \views_handler_field_amazon_image::render()

File

includes/views_handler_field_amazon_image.inc, line 92
Provide views handler so that Amazon Image can be displayed in the various ways that are available.

Class

views_handler_field_amazon_image
@file Provide views handler so that Amazon Image can be displayed in the various ways that are available.

Code

function render($values) {

  // We may not have a URL. It's not guaranteed that Amazon will give us one.
  if (empty($values->{$this->aliases['url']})) {
    return;
  }
  $attributes = array(
    'height' => $values->{$this->aliases['height']},
    'width' => $values->{$this->aliases['width']},
  );

  // Choose presentation style
  if ($this->options['presentation_format'] == 'markup') {
    $image = theme('image', $values->{$this->aliases['url']}, NULL, NULL, $attributes, FALSE);
  }
  else {
    $image = $values->{$this->aliases['url']};
  }
  switch ($this->options['link_format']) {
    case 'plain':
      return $image;
      break;
    case 'amazon':
      if (!empty($values->{$this->aliases['detailpageurl']})) {
        $urlfield = $values->{$this->aliases['detailpageurl']};
        return l($image, $urlfield, array(
          'html' => TRUE,
        ));
      }
      else {
        return $image;
      }
      break;
    case 'amazon_store':
      $path = function_exists('amazon_store_get_amazon_store_path') ? amazon_store_get_amazon_store_path() : 'amazon_store';
      $asin = $values->{$this->aliases['asin']};
      return l($image, "{$path}/item/{$asin}", array(
        'html' => TRUE,
      ));
      break;
  }
}