views_rss_yandex.module in Views RSS: Yandex Elements 7
Same filename and directory in other branches
Provides Yandex namespace and <item> elements for Views RSS module.
File
views_rss_yandex.moduleView source
<?php
/**
* @file
* Provides Yandex namespace and <item> elements for Views RSS module.
*/
/**
* Implements hook_views_rss_namespaces().
*/
function views_rss_yandex_views_rss_namespaces() {
$namespaces['yandex'] = array(
'prefix' => 'xmlns',
'uri' => 'http://news.yandex.ru',
);
if (!module_exists('views_rss_media')) {
$namespaces['media'] = array(
'prefix' => 'xmlns',
'uri' => 'http://search.yahoo.com/mrss/',
);
}
return $namespaces;
}
/**
* Implements hook_views_rss_channel_elements().
*/
function views_rss_yandex_views_rss_channel_elements() {
$elements['yandex:logo'] = array(
'description' => t('Path to the image to be used as the artwork for your feed, for example <em>sites/default/files/AllAboutEverything.jpg</em>. Allowed image formats are GIF, JPEG or PNG.'),
'preprocess functions' => array(
'views_rss_yandex_preprocess_channel_yandex_logo',
),
'help' => 'http://partner.news.yandex.ru/tech.pdf',
);
$elements['yandex:logo type=square'] = array(
'description' => t('Path to the image to be used as the artwork for your feed, for example <em>sites/default/files/AllAboutEverything.jpg</em>. Allowed image formats are GIF, JPEG or PNG. Minimum image width and height is 180 pixels.'),
'preprocess functions' => array(
'views_rss_yandex_preprocess_channel_yandex_logo_square',
),
'help' => 'http://partner.news.yandex.ru/tech.pdf',
);
return $elements;
}
/**
* Preprocess function for channel <yandex:logo> element.
*/
function views_rss_yandex_preprocess_channel_yandex_logo(&$variables) {
// No value = no preprocessing.
if (empty($variables['elements'][0]['value'])) {
return;
}
$path = $variables['elements'][0]['value'];
$variables['elements'][0]['value'] = file_create_url($path);
}
/**
* Preprocess function for channel <yandex:logo type="square"> element.
*/
function views_rss_yandex_preprocess_channel_yandex_logo_square(&$variables) {
// No value = no preprocessing.
if (empty($variables['elements'][0]['value'])) {
return;
}
// Change the element key and add the type="square" attribute.
$variables['elements'][0]['key'] = 'yandex:logo';
$variables['elements'][0]['attributes'] = array(
'type' => 'square',
);
$path = $variables['elements'][0]['value'];
$variables['elements'][0]['value'] = file_create_url($path);
}
/**
* Implements hook_views_rss_item_elements().
*/
function views_rss_yandex_views_rss_item_elements() {
$elements['yandex:full-text'] = array(
'description' => t('Full message text for search index.'),
'help' => 'http://partner.news.yandex.ru/tech.pdf',
);
$elements['yandex:genre'] = array(
'description' => t('Should be either lenta, message, article or interview.'),
'help' => 'http://partner.news.yandex.ru/tech.pdf',
);
$elements['yandex:tags'] = array(
'description' => t('Tags, separate multiple items with comma.'),
'help' => 'http://partner.news.yandex.ru/tech.pdf',
'preprocess functions' => array(
'views_rss_yandex_preprocess_item_yandex_tags',
),
);
$elements['yandex:online'] = array(
'description' => t('Link to online broadcast xml feed.'),
'help' => 'http://partner.news.yandex.ru/tech.pdf',
);
$elements['yandex:enclosure'] = array(
'description' => t('Handles several enclosure elements per item.'),
'help' => 'http://partner.news.yandex.ru/tech.pdf',
);
$elements['yandex:pdalink'] = array(
'description' => t('Link to the mobile version of the content.'),
'preprocess functions' => array(
'views_rss_yandex_preprocess_item_yandex_pdalink',
),
'help' => 'http://partner.news.yandex.ru/tech.pdf',
);
return $elements;
}
/**
* Preprocess function for item <yandex:tags> element.
*/
function views_rss_yandex_preprocess_item_yandex_tags(&$variables) {
// No value = no preprocessing.
if (empty($variables['elements'][0]['value'])) {
return;
}
$elements = array();
$categories = explode(',', $variables['elements'][0]['value']);
foreach ($categories as $category) {
$elements[] = array(
'key' => 'yandex:tags',
'value' => trim($category),
);
}
$variables['elements'] = $elements;
}
/**
* Preprocess function for item <pdalink> element.
*/
function views_rss_yandex_preprocess_item_yandex_pdalink(&$variables) {
// No value = no preprocessing.
if (empty($variables['elements'][0]['value'])) {
return;
}
// Change the element key.
$variables['elements'][0]['key'] = 'pdalink';
}
/**
* Implements hook_views_rss_options_form_validate().
*/
function views_rss_yandex_views_rss_options_form_validate($form, &$form_state) {
// Validate channel <yandex:logo> element.
if (!empty($form_state['values']['style_options']['channel']['yandex']['views_rss_yandex']['logo'])) {
// Do not validate absolute URLs, as this could mean external image.
if (!valid_url($form_state['values']['style_options']['channel']['yandex']['views_rss_yandex']['logo'], TRUE)) {
// Check that image exists and is in acceptable format.
$image = image_load($form_state['values']['style_options']['channel']['yandex']['views_rss_yandex']['logo']);
if (empty($image)) {
form_set_error('style_options][channel][yandex][views_rss_yandex][logo', t('Unable to find %image or incorrect image format.', array(
'%image' => $form_state['values']['style_options']['channel']['yandex']['views_rss_yandex']['logo'],
)));
}
}
}
// Validate channel <yandex:logo type="square"> element.
if (!empty($form_state['values']['style_options']['channel']['yandex']['views_rss_yandex']['logo type=square'])) {
// Do not validate absolute URLs, as this could mean external image.
if (!valid_url($form_state['values']['style_options']['channel']['yandex']['views_rss_yandex']['logo type=square'], TRUE)) {
// Check that image exists and is in acceptable format.
$image = image_load($form_state['values']['style_options']['channel']['yandex']['views_rss_yandex']['logo type=square']);
if (empty($image)) {
form_set_error('style_options][channel][yandex][views_rss_yandex][logo type=square', t('Unable to find %image or incorrect image format.', array(
'%image' => $form_state['values']['style_options']['channel']['yandex']['views_rss_yandex']['logo type=square'],
)));
}
else {
// Check image width and height.
if ($image->info['width'] < 180 || $image->info['height'] < 180) {
form_set_error('style_options][channel][yandex][views_rss_yandex][logo type=square', t("Minimum allowed width/height of an image for feed channel's <yandex:logo type=square> element is 180 pixels. Specified %image is !width x !height pixels.", array(
'%image' => $form_state['values']['style_options']['channel']['yandex']['views_rss_yandex']['logo type=square'],
'!width' => $image->info['width'],
'!height' => $image->info['height'],
)));
}
elseif ($image->info['width'] != $image->info['height']) {
form_set_error('style_options][channel][yandex][views_rss_yandex][logo type=square', t("Width and height of an image for feed channel's <yandex:logo type=square> element should be equal. Specified %image is !width x !height pixels.", array(
'%image' => $form_state['values']['style_options']['channel']['yandex']['views_rss_yandex']['logo type=square'],
'!width' => $image->info['width'],
'!height' => $image->info['height'],
)));
}
}
}
}
}
Functions
Name![]() |
Description |
---|---|
views_rss_yandex_preprocess_channel_yandex_logo | Preprocess function for channel <yandex:logo> element. |
views_rss_yandex_preprocess_channel_yandex_logo_square | Preprocess function for channel <yandex:logo type="square"> element. |
views_rss_yandex_preprocess_item_yandex_pdalink | Preprocess function for item <pdalink> element. |
views_rss_yandex_preprocess_item_yandex_tags | Preprocess function for item <yandex:tags> element. |
views_rss_yandex_views_rss_channel_elements | Implements hook_views_rss_channel_elements(). |
views_rss_yandex_views_rss_item_elements | Implements hook_views_rss_item_elements(). |
views_rss_yandex_views_rss_namespaces | Implements hook_views_rss_namespaces(). |
views_rss_yandex_views_rss_options_form_validate | Implements hook_views_rss_options_form_validate(). |