function _amazon_filter_process_text in Amazon Product Advertisement API 6
Same name and namespace in other branches
- 7.2 amazon_filter/amazon_filter.module \_amazon_filter_process_text()
- 7 amazon_filter/amazon_filter.module \_amazon_filter_process_text()
1 call to _amazon_filter_process_text()
- amazon_filter_filter in amazon_filter/
amazon_filter.module - Implementation of hook_filter().
File
- amazon_filter/
amazon_filter.module, line 54
Code
function _amazon_filter_process_text($text) {
$pattern = "/\\[amazon +(.*?)(?: +(.*?))?\\]/";
$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', $item);
break;
case 'thumbnail':
// Handle themeable cases, like thumbnail, full.
case 'full':
$replace[] = theme('amazon_item', $item, $action);
break;
default:
// Allow to use anything found in the item.
$replace[] = theme('amazon_detail', $item, $action);
break;
}
}
else {
// error case
$replace[] = "<!-- The Amazon product '{$asin}' could not be found.-->";
}
}
$text = str_replace($search, $replace, $text);
}
return $text;
}