function _amazon_filter_process_text in Amazon Product Advertisement API 7.2
Same name and namespace in other branches
- 6 amazon_filter/amazon_filter.module \_amazon_filter_process_text()
- 7 amazon_filter/amazon_filter.module \_amazon_filter_process_text()
Actual filter processing function - changes [amazon <whatever>] in text.
Parameters
$text: Text to be transformed.
Return value
The transformed text.
1 string reference to '_amazon_filter_process_text'
- amazon_filter_info in amazon_filter/
amazon_filter.module - Implements hook_filter_info().
File
- amazon_filter/
amazon_filter.module, line 55
Code
function _amazon_filter_process_text($text) {
$pattern = "@\\[amazon(?: |:|%20)+(.*?)(?:(?: |:|%20)(.*?))?\\]@";
$matches = array();
if (preg_match_all($pattern, $text, $matches)) {
$search = $matches[0];
$replace = array();
foreach ($matches[0] as $key => $value) {
$asin = $matches[1][$key];
$asin = amazon_convert_to_asin($asin);
$action = $matches[2][$key];
$items = amazon_item_lookup($asin);
$item = "";
if (!empty($items)) {
$item = $items[$asin];
}
if (!empty($item)) {
switch ($action) {
case "":
case 'inline':
$replace[] = theme('amazon_inline_item', array(
'item' => $item,
));
break;
// Full is a synonym of 'details'.
case 'full':
case 'details':
$replace[] = theme('amazon_item', array(
'item' => $item,
'style' => 'details',
));
break;
// Handle themeable cases, like thumbnail.
case 'thumbnail':
$replace[] = theme('amazon_item__thumbnail', array(
'item' => $item,
));
break;
default:
// Allow to use anything found in the item.
$replace[] = theme('amazon_detail', array(
'item' => $item,
'detail' => $action,
));
break;
}
}
else {
// error case
$replace[] = "<!-- The Amazon product '{$asin}' could not be found.-->";
}
}
$text = str_replace($search, $replace, $text);
}
return $text;
}