Newer
Older
maciej.zgadzaj
committed
<?php
/**
maciej.zgadzaj
committed
* @file
* Provides core <channel> and <item> elements for Views RSS module.
maciej.zgadzaj
committed
*/
maciej.zgadzaj
committed
maciej.zgadzaj
committed
define('VIEWS_RSS_CORE_PATH', drupal_get_path('module', 'views_rss_core'));
/**
* Include file with field formatters.
*/
include_once VIEWS_RSS_CORE_PATH .'/views_rss_core.field.inc';
/**
* Include file with all preprocess functions.
*/
include_once VIEWS_RSS_CORE_PATH . '/views_rss_core.inc';
maciej.zgadzaj
committed
/**
* Implementation of hook_views_rss_namespaces().
*/
function views_rss_core_views_rss_namespaces() {
$namespaces['atom'] = array(
'prefix' => 'xmlns',
'uri' => 'http://www.w3.org/2005/Atom',
);
return $namespaces;
}
maciej.zgadzaj
committed
/**
* Implementation of hook_views_rss_channel_elements().
*/
function views_rss_core_views_rss_channel_elements() {
maciej.zgadzaj
committed
$elements['title'] = array(
'configurable' => FALSE,
'preprocess functions' => array(
'views_rss_core_preprocess_channel_title',
'views_rss_htmlspecialchars',
),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-title',
maciej.zgadzaj
committed
);
$elements['description'] = array(
'description' => t('Description for this feed. If left blank, the default site mission will be used.'),
'settings form' => array('#type' => 'textarea', '#rows' => 3),
'preprocess functions' => array(
'views_rss_core_preprocess_channel_description',
'views_rss_rewrite_relative_paths',
'views_rss_htmlspecialchars',
'help' => 'http://www.rssboard.org/rss-profile#element-channel-description',
maciej.zgadzaj
committed
);
$elements['link'] = array(
'configurable' => FALSE,
'preprocess functions' => array('views_rss_core_preprocess_channel_link'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-link',
maciej.zgadzaj
committed
);
$elements['atom:link'] = array(
'configurable' => FALSE,
'preprocess functions' => array('views_rss_core_preprocess_channel_atom_link'),
'help' => 'http://www.rssboard.org/rss-profile#namespace-elements-atom-link',
);
maciej.zgadzaj
committed
$elements['language'] = array(
'description' => t('The language the channel is written in. This allows aggregators to group all Italian language sites, for example, on a single page. See list of <a href="@w3c_url">allowable values</a> for this element defined by the W3C.', array(
maciej.zgadzaj
committed
'@w3c_url' => url('http://www.w3.org/TR/REC-html40/struct/dirlang.html', array('fragment' => 'langcodes')),
)),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-language',
maciej.zgadzaj
committed
);
$elements['category'] = array(
'description' => t('Specify one or more categories that the channel belongs to. Separate multiple items with comma.'),
'preprocess functions' => array(
'views_rss_htmlspecialchars',
'views_rss_core_preprocess_channel_category',
'help' => 'http://www.rssboard.org/rss-profile#element-channel-category',
);
$elements['image'] = 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. Maximum image width is 144 pixels, maximum height 400 pixels.'),
'preprocess functions' => array('views_rss_core_preprocess_channel_image'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-image',
);
maciej.zgadzaj
committed
$elements['copyright'] = array(
'description' => t('Copyright notice for content in the channel.'),
'preprocess functions' => array('views_rss_htmlspecialchars'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-copyright',
maciej.zgadzaj
committed
);
$elements['managingEditor'] = array(
'description' => t('Email address for person responsible for editorial content.'),
'preprocess functions' => array('views_rss_htmlspecialchars'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-managingeditor',
maciej.zgadzaj
committed
);
$elements['webMaster'] = array(
'description' => t('Email address for person responsible for technical issues relating to channel.'),
'preprocess functions' => array('views_rss_htmlspecialchars'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-webmaster',
maciej.zgadzaj
committed
);
$elements['generator'] = array(
'description' => t('A string indicating the program used to generate the channel.'),
'preprocess functions' => array('views_rss_htmlspecialchars'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-generator',
maciej.zgadzaj
committed
);
$elements['docs'] = array(
'description' => t("A URL that points to the documentation for the format used in the RSS file. It's for people who might stumble across an RSS file on a Web server 25 years from now and wonder what it is."),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-docs',
maciej.zgadzaj
committed
);
$elements['cloud'] = array(
'description' => t("Allows processes to register with a cloud to be notified of updates to the channel, implementing a lightweight publish-subscribe protocol for RSS feeds. Example: <em>soap://rpc.sys.com:80/RPC2#pingMe</em>"),
'preprocess functions' => array('views_rss_core_preprocess_channel_cloud'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-cloud',
maciej.zgadzaj
committed
);
$elements['ttl'] = array(
'description' => t("ttl stands for time to live. It's a number of minutes that indicates how long a channel can be cached before refreshing from the source."),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-ttl',
maciej.zgadzaj
committed
);
$elements['skipHours'] = array(
'description' => t('A hint for aggregators telling them which hours they can skip. The hours must be expressed as an integer representing the number of hours since 00:00:00 GMT. Values from 0 to 23 are permitted, with 0 representing midnight. An hour must not be duplicated.'),
'preprocess functions' => array('views_rss_core_preprocess_channel_skip'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-skiphours',
maciej.zgadzaj
committed
);
$elements['skipDays'] = array(
'description' => t('A hint for aggregators telling them which days of the week they can skip (up to seven days).'),
'preprocess functions' => array('views_rss_core_preprocess_channel_skip'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-skipdays',
maciej.zgadzaj
committed
);
$elements['pubDate'] = array(
'configurable' => FALSE,
'preprocess functions' => array('views_rss_core_preprocess_channel_date'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-pubdate',
);
$elements['lastBuildDate'] = array(
'configurable' => FALSE,
'preprocess functions' => array('views_rss_core_preprocess_channel_date'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-lastbuilddate',
);
maciej.zgadzaj
committed
return $elements;
maciej.zgadzaj
committed
}
/**
maciej.zgadzaj
committed
* Implementation of hook_views_rss_item_elements().
maciej.zgadzaj
committed
*/
maciej.zgadzaj
committed
function views_rss_core_views_rss_item_elements() {
maciej.zgadzaj
committed
$elements['title'] = array(
maciej.zgadzaj
committed
'description' => t('The title of the item. Required by RSS specification.'),
'preprocess functions' => array('views_rss_htmlspecialchars'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-title',
maciej.zgadzaj
committed
);
$elements['link'] = array(
maciej.zgadzaj
committed
'description' => t('The URL of the item. Required by RSS specification.'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-link',
maciej.zgadzaj
committed
);
$elements['description'] = array(
maciej.zgadzaj
committed
'description' => t('The item synopsis. Required by RSS specification.'),
maciej.zgadzaj
committed
'preprocess functions' => array(
'views_rss_rewrite_relative_paths',
'views_rss_htmlspecialchars',
maciej.zgadzaj
committed
),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-description',
maciej.zgadzaj
committed
);
$elements['author'] = array(
maciej.zgadzaj
committed
'description' => t('Email address of the author of the item.'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-author',
maciej.zgadzaj
committed
);
$elements['category'] = array(
maciej.zgadzaj
committed
'description' => t('Includes the item in one or more categories.'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-category',
maciej.zgadzaj
committed
);
$elements['comments'] = array(
maciej.zgadzaj
committed
'description' => t('URL of a page for comments relating to the item.'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-comments',
maciej.zgadzaj
committed
);
$elements['enclosure'] = array(
maciej.zgadzaj
committed
'description' => t('Describes a media object that is attached to the item.'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-enclosure',
maciej.zgadzaj
committed
);
$elements['guid'] = array(
maciej.zgadzaj
committed
'description' => t('A string that uniquely identifies the item.'),
maciej.zgadzaj
committed
'preprocess functions' => array('views_rss_core_preprocess_item_guid'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-guid',
maciej.zgadzaj
committed
);
$elements['pubDate'] = array(
maciej.zgadzaj
committed
'description' => t('Indicates when the item was published.'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-pubdate',
maciej.zgadzaj
committed
);
$elements['source'] = array(
'configurable' => FALSE,
maciej.zgadzaj
committed
'description' => t('The RSS channel that the item came from.'),
maciej.zgadzaj
committed
'preprocess functions' => array('views_rss_core_preprocess_item_source'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-source',
maciej.zgadzaj
committed
);
maciej.zgadzaj
committed
return $elements;
maciej.zgadzaj
committed
}
maciej.zgadzaj
committed
* Implementation of hook_views_rss_date_sources().
maciej.zgadzaj
committed
function views_rss_core_views_rss_date_sources() {
$sources['node'] = array(
'pubDate' => array(
'table' => 'node',
maciej.zgadzaj
committed
'field' => 'created',
maciej.zgadzaj
committed
),
'lastBuildDate' => array(
'table' => 'node',
maciej.zgadzaj
committed
'field' => 'changed',
maciej.zgadzaj
committed
),
);
maciej.zgadzaj
committed
$sources['node_revisions'] = array(
'pubDate' => array(
'table' => 'node_revisions',
maciej.zgadzaj
committed
'field' => 'timestamp',
maciej.zgadzaj
committed
),
);
$sources['comments'] = array(
maciej.zgadzaj
committed
'lastBuildDate' => array(
maciej.zgadzaj
committed
'table' => 'comments',
maciej.zgadzaj
committed
'field' => 'timestamp',
maciej.zgadzaj
committed
),
);
$sources['files'] = array(
'pubDate' => array(
'table' => 'files',
maciej.zgadzaj
committed
'field' => 'timestamp',
maciej.zgadzaj
committed
),
);
$sources['users'] = array(
'pubDate' => array(
'table' => 'users',
maciej.zgadzaj
committed
'field' => 'created',
maciej.zgadzaj
committed
),
);
return $sources;
maciej.zgadzaj
committed
}
/**
maciej.zgadzaj
committed
* Implementation of hook_views_query_alter().
maciej.zgadzaj
committed
*/
maciej.zgadzaj
committed
function views_rss_core_views_query_alter(&$view, &$query) {
if ($view->style_plugin->definition['handler'] == 'views_rss_plugin_style_fields') {
maciej.zgadzaj
committed
$date_sources = views_rss_get('date_sources');
maciej.zgadzaj
committed
foreach (array_keys($date_sources) as $module) {
if (isset($date_sources[$module][$view->base_table])) {
// Select the most recent node creation date for <pubDate> element.
if (isset($date_sources[$module][$view->base_table]['pubDate'])) {
$query->fields['pubDate'] = $date_sources[$module][$view->base_table]['pubDate'];
}
// Select the most recent node update date for <lastBuildDate> element.
if (isset($date_sources[$module][$view->base_table]['lastBuildDate'])) {
$query->fields['lastBuildDate'] = $date_sources[$module][$view->base_table]['lastBuildDate'];
}
}
maciej.zgadzaj
committed
}
}
}
/**
* Implementation of hook_theme().
*/
function views_rss_core_theme() {
$theme = array(
// CCK field formatters.
'views_rss_core_formatter_enclosure_image' => array(
'arguments' => array('element' => NULL),
'function' => 'views_rss_core_field_formatter_view',
'file' => 'views_rss_core.field.inc',
maciej.zgadzaj
committed
),
'views_rss_core_formatter_enclosure_file' => array(
'arguments' => array('element' => NULL),
'function' => 'views_rss_core_field_formatter_view',
'file' => 'views_rss_core.field.inc',
maciej.zgadzaj
committed
),
);
if (module_exists('imagecache')) {
foreach (imagecache_presets() as $preset) {
$theme['views_rss_core_formatter_enclosure_image' . $preset['presetname']] = array(
maciej.zgadzaj
committed
'arguments' => array('element' => NULL),
'function' => 'views_rss_core_field_formatter_view',
'file' => 'views_rss_core.field.inc',
maciej.zgadzaj
committed
);
}
}
return $theme;
}
/**
* Implements hook_views_rss_options_form_validate().
*/
function views_rss_core_views_rss_options_form_validate($form, &$form_state) {
// Validate channel <image> element.
if (!empty($form_state['values']['style_options']['channel']['core']['views_rss_core']['image'])) {
// Do not validate absolute URLs, as this could mean external image.
if (!valid_url($form_state['values']['style_options']['channel']['core']['views_rss_core']['image'], TRUE)) {
// Check that image exists and is in acceptable format.
$real_path = realpath($form_state['values']['style_options']['channel']['core']['views_rss_core']['image']);
if (!file_exists($real_path)) {
form_set_error('style_options][channel][core][views_rss_core][image', t('Unable to find %image or incorrect image format.', array(
'%image' => $form_state['values']['style_options']['channel']['core']['views_rss_core']['image'],
)));
}
else {
list($width, $height) = getimagesize($real_path);
// Check image width.
if ($width > 144) {
form_set_error('style_options][channel][core][views_rss_core][image', t("Maximum allowed width of an image for feed channel's <image> element is 144 pixels. Specified %image is !width pixels wide.", array(
'%image' => $form_state['values']['style_options']['channel']['core']['views_rss_core']['image'],
'!width' => $width,
)));
}
// Check image height.
if ($height > 400) {
form_set_error('style_options][channel][core][views_rss_core][image', t("Maximum allowed height of an image for feed channel's <image> element is 400 pixels. Specified %image is !height pixels high.", array(
'%image' => $form_state['values']['style_options']['channel']['core']['views_rss_core']['image'],
'!height' => $height,
)));
}
// Validate channel <docs> element.
if (!empty($form_state['values']['style_options']['channel']['core']['views_rss_core']['docs'])) {
if (!valid_url($form_state['values']['style_options']['channel']['core']['views_rss_core']['docs'], TRUE)) {
form_set_error('style_options][channel][core][views_rss_core][docs', t("Not a valid URL."));
}
}
}