You are here

function amazon_preprocess_amazon_item in Amazon Product Advertisement API 6

hook_preprocess: amazon_item.

1 string reference to 'amazon_preprocess_amazon_item'
amazon_theme in ./amazon.module
Implementation of hook_theme().

File

./amazon.module, line 105

Code

function amazon_preprocess_amazon_item(&$variables) {
  $item = $variables['item'];

  // Do a quick cycle through the simple keys on the item, check_plain() them,
  // and stick them in the variables collection.
  foreach ($item as $key => $value) {
    if (is_string($value)) {
      $variables[$key] = filter_xss($value);
    }
  }
  $variables['type'] = _amazon_clean_type($item['producttypename']);
  $variables['detailpageurl'] = check_url($item['detailpageurl']);
  $variables['editorialreview'] = !empty($item['editorialreviews']) ? check_markup($item['editorialreviews'][0]['content']) : '';
  $variables['customerreviews_iframe'] = !empty($item['customerreviews_iframe']) ? check_url($item['customerreviews_iframe']) : '';
  $variables['invalid_asin'] = !empty($item['invalid_asin']) ? 1 : 0;
  if (!empty($variables['theatricalreleasedate'])) {
    $date = explode('-', $variables['theatricalreleasedate']);
    $variables['releaseyear'] = $date[0];
  }
  else {
    $variables['releaseyear'] = '';
  }
  if (!empty($variables['publicationdate'])) {
    $date = explode('-', $variables['publicationdate']);
    $variables['publicationyear'] = $date[0];
  }
  else {
    $variables['publicationyear'] = '';
  }

  // Handle participants and types.
  if (isset($item['participants'])) {
    $variables['participants'] = filter_xss(filter_xss(implode(', ', $item['participants'])));
    $participant_types = split(',', AMAZON_PARTICIPANT_TYPES);
    foreach ($participant_types as $participant_type) {
      $participant_type = strtolower($participant_type);
      if (!empty($item[$participant_type])) {
        if (is_string($item[$participant_type])) {
          $variables[$participant_type] = filter_xss($item[$participant_type]);
        }
        else {
          $variables[$participant_type] = filter_xss(implode(', ', $item[$participant_type]));
        }
      }
    }
  }
  $variables += array(
    'participants' => '',
    'director' => '',
    'actor' => '',
    'artist' => '',
    'author' => '',
  );

  // Handle supported image resolutions.
  if (isset($item['imagesets'])) {
    foreach ($item['imagesets'] as $key => $image) {
      $variables[$key] = theme('image', $image['url'], t('Image of') . ' ' . check_plain($item['title']), check_plain($item['title']), array(
        'height' => $image['height'],
        'width' => $image['width'],
      ), FALSE);
      $variables["{$key}url"] = check_url($image['url']);
      $variables["{$key}height"] = check_plain($image['height']);
      $variables["{$key}width"] = check_plain($image['width']);
    }
  }
  $variables['image'] = !empty($variables['mediumimage']) ? $variables['mediumimage'] : '';
  if (!empty($variables['style'])) {
    $variables['classes'] = _amazon_item_classes($item) . ' amazon-item-' . check_plain($variables['style']);

    // A set of more specific templates to use when displaying items.
    $variables['template_files'][] = 'amazon-item-' . $variables['style'];
    $variables['template_files'][] = 'amazon-item-' . strtolower($variables['type']);
    $variables['template_files'][] = 'amazon-item-' . strtolower($variables['type']) . '-' . $variables['style'];
    if (!empty($item['view']) && !empty($item['view']->name)) {
      $vars['template_files'][] = 'amazon-item-view-' . $item['view']->name;
      $variables['template_files'][] = 'amazon-item-' . strtolower($variables['type']) . '-view-' . $item['view']->name;
    }
  }
}