You are here

function amazon_convert_to_asin in Amazon Product Advertisement API 7

Same name and namespace in other branches
  1. 6 amazon.module \amazon_convert_to_asin()
  2. 7.2 amazon.module \amazon_convert_to_asin()

Try to turn a non-asin into an ASIN where possible.

If the received input appears to be an EAN (ISBN-13) or an Amazon.com/de/uk link, then this tries to convert it into an ASIN.

Parameters

$input:

Return value

An ASIN if possible. Otherwise whatever was passed in, after removing dashes.

3 calls to amazon_convert_to_asin()
amazon_test_form_validate in ./amazon.admin.inc
asin_field_widget_element_validate in asin/asin.module
Widget validation function.
_amazon_filter_process_text in amazon_filter/amazon_filter.module
Actual filter processing function - changes [amazon <whatever>] in text.

File

./amazon.module, line 754

Code

function amazon_convert_to_asin($input) {
  $input = preg_replace('/-/', '', $input);

  // Remove dashes.
  if (preg_match('/^https?:/', $input)) {
    $parts = preg_split('/\\//', $input);
    $asin = $parts[5];

    // 6th section of split, right after /dp/
    return $asin;
  }

  // Attempt conversion of 13-digit ASIN by doing an Amazon lookup.
  if (strlen($input) == 13 && is_numeric($input)) {
    $asin = amazon_ean_to_asin($input);
    return $asin;
  }
  return $input;
}