function template_preprocess_amazon_item in Amazon Product Advertisement API 7
Same name and namespace in other branches
- 7.2 amazon.module \template_preprocess_amazon_item()
template_preprocess: amazon_item.
1 string reference to 'template_preprocess_amazon_item'
- amazon_theme in ./
amazon.module - Implementation of hook_theme().
File
- ./
amazon.module, line 136
Code
function template_preprocess_amazon_item(&$variables, $theme_type) {
$item = $variables['item'];
// Do a quick cycle through the simple keys on the item, filter_xss() 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']) ? filter_xss_admin($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['customerreviews'])) {
foreach ($variables['customerreviews'] as $key => $review) {
$variables['customerreviews'][$key] = filter_xss($variables['customerreviews'][$key]);
}
}
$variables['invalid_asin'] = !empty($variables['invalid_asin']) ? 1 : 0;
if (!empty($variables['publicationdate'])) {
$date = explode('-', $variables['publicationdate']);
$variables['publicationyear'] = check_plain($date[0]);
}
else {
$variables['publicationyear'] = '';
}
// Handle participants and types.
if (isset($item['participants'])) {
$variables['participants'] = filter_xss(filter_xss(implode(', ', $item['participants'])));
$participant_types = preg_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', array(
'path' => $image['url'],
'alt' => t('Image of') . ' ' . strip_tags($item['title']),
'title' => strip_tags($item['title']),
'attributes' => array(
'height' => $image['height'],
'width' => $image['width'],
),
'getsize' => 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'] : '';
$variables['classes_array'] = array();
$variables['attributes_array'] = array();
$variables['title_attributes_array'] = array();
$variables['content_attributes_array'] = array();
if (!empty($variables['detail']) && $theme_type == 'amazon_detail') {
$variables['classes_array'] = array(
"amazon-item",
"amazon-item-detail-{$variables['detail']}",
);
}
if (!empty($variables['style']) && $variables['style'] == 'inline' && !empty($variables['producttypename'])) {
$variables['theme_hook_suggestions'][] = 'amazon_inline_item__' . _amazon_clean_type($item['producttypename']);
}
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['theme_hook_suggestions'][] = 'amazon_item__' . $variables['style'];
$variables['theme_hook_suggestions'][] = 'amazon_item__' . strtolower($variables['type']);
$variables['theme_hook_suggestions'][] = 'amazon_item__' . strtolower($variables['type']) . '__' . $variables['style'];
if (!empty($item['view']) && !empty($item['view']->name)) {
$variables['theme_hook_suggestions'][] = 'amazon_item_view__' . $item['view']->name;
$variables['theme_hook_suggestions'][] = 'amazon_item__' . strtolower($variables['type']) . '__view__' . $item['view']->name;
}
}
}