You are here

function asin_token_values in Amazon Product Advertisement API 6

Implementation of hook_token_values()

File

asin/asin.module, line 657
Defines a field type for referencing an Amazon product.

Code

function asin_token_values($type, $object = NULL, $options = array()) {
  if ($type == 'field') {
    $item = $object[0];
    $amazonAsin = amazon_convert_to_asin($item['asin']);
    $amazonArr = amazon_item_lookup($amazonAsin);
    $item = $amazonArr[$amazonAsin];
    if (is_array($item)) {
      foreach ($item as $k => $v) {
        if ($k == 'detailpageurl') {
          $v = check_url($v);
        }
        else {
          if ($k == 'author' || $k == 'participants') {
            $v = array_map('check_plain', $v);
            $v = implode(', ', $v);
          }
          else {
            if (is_string($v)) {
              $v = check_plain($v);
            }
          }
        }
        ${$k} = $v;
      }
    }
    $values['asin'] = $asin;
    $values['title'] = $title;
    $values['title-dec'] = decode_entities($title);
    $values['detailpageurl'] = $detailpageurl;
    $values['salesrank'] = $salesrank;
    $values['brand'] = $brand;
    $values['brand-dec'] = decode_entities($brand);
    $values['publisher'] = $publisher;
    $values['publisher-dec'] = decode_entities($publisher);
    $values['manufacturer'] = $manufacturer;
    $values['manufacturer-dec'] = decode_entities($manufacturer);
    $values['studio'] = $studio;
    $values['studio-dec'] = decode_entities($studio);
    $values['label'] = $label;
    $values['label-dec'] = decode_entities($label);
    $values['binding'] = $binding;
    $values['binding-dec'] = decode_entities($binding);
    $values['release'] = $releasedate;
    $values['release-Y'] = substr($releasedate, 0, 4);
    $values['release-y'] = substr($releasedate, 2, 2);
    $month = substr($releasedate, 5, 2);
    $values['release-m'] = $month;
    $values['release-n'] = ltrim($month, '0');
    $values['release-M'] = $month ? date('M', mktime(0, 0, 0, $month)) : '';
    $day = substr($releasedate, 8, 2);
    $values['release-d'] = $day;
    $values['release-j'] = ltrim($day, '0');
    $values['list'] = $listpriceformattedprice;
    $values['list-amount'] = $listpriceamount;
    $values['list-currency'] = $listpricecurrencycode;
    $values['lowest'] = $lowestpriceformattedprice;
    $values['lowest-amount'] = $lowestpriceamount;
    $values['lowest-currency'] = $lowestpricecurrencycode;
    $values['amazon'] = $amazonpriceformattedprice;
    $values['amazon-amount'] = $amazonpriceamount;
    $values['amazon-currency'] = $amazonpricecurrencycode;
    $values['group'] = $productgroup;
    $values['group-dec'] = decode_entities($productgroup);
    $values['type'] = $producttypename;
    $values['type-dec'] = decode_entities($producttypename);
    $values['author'] = $author;
    $values['author-dec'] = decode_entities($author);
    $values['participants'] = $participants;
    $values['participants-dec'] = decode_entities($participants);
    return $values;
  }
}