function theme_yandex_turbo_page_rss in Yandex.Turbo 7.3
Same name and namespace in other branches
- 7.4 yandex_turbo.pages.inc \theme_yandex_turbo_page_rss()
- 7 yandex_turbo.pages.inc \theme_yandex_turbo_page_rss()
- 7.2 yandex_turbo.pages.inc \theme_yandex_turbo_page_rss()
Prints the RSS page for a feed.
Parameters
$variables: An associative array containing:
- feeds: An array of the feeds to theme.
Return value
string
1 theme call to theme_yandex_turbo_page_rss()
- yandex_turbo_page_rss in ./
yandex_turbo.pages.inc - Page callback: Generates an Yandex Turbo RSS
File
- ./
yandex_turbo.pages.inc, line 70
Code
function theme_yandex_turbo_page_rss($variables) {
/**
* Feed absolute link
*/
$rss_link = url('yandex.turbo.rss', array(
'absolute' => TRUE,
));
/**
* Feeds data
*
* @var array
*/
$feeds = $variables['feeds'];
/**
* Allowed HTMl tags
* @see https://yandex.ru/support/webmaster/turbo/feed.html#rss-elements__item
*/
$allowed_tags = array(
'figure',
'h1',
'h2',
'p',
'br',
'ul',
'ol',
'li',
'b',
'strong',
'i',
'em',
'sup',
'sub',
'ins',
'del',
'small',
'big',
'pre',
'abbr',
'u',
'a',
'img',
'figcaption',
'video',
'header',
);
/**
* Removes CDATA tag from content
*
* @var string
*/
$CDATA = '/^\\s*\\/\\/<!\\[CDATA\\[([\\s\\S]*)\\/\\/\\]\\]>\\s*\\z/';
/**
* Items XML-string
*
* @var string
*/
$items = '';
/**
* @vat string
*/
$output = '';
/**
* Channel settings
*/
$site_name = variable_get('site_name', '');
$site_slogan = variable_get('site_slogan', 'Site description');
$channel_title = variable_get('yandex_turbo_rss_title', $site_name);
$channel_description = variable_get('yandex_turbo_rss_description', $site_slogan);
$channel_analytics = variable_get('yandex_turbo_rss_analytics_type', 'Yandex');
$max_item_images = intval(variable_get('yandex_turbo_rss_max_item_images', '0'));
if (!empty($feeds)) {
foreach ($feeds as $nid => $node) {
$body = strip_tags(trim($node['body']), '<' . implode('><', $allowed_tags) . '>');
$body = preg_replace($CDATA, '$1', $body);
// Skip empty nodes
if (!$body) {
continue;
}
// Images limit
if ($max_item_images > 0) {
$find_images = 0;
$body = preg_replace_callback("/<img([^>]*)>/Us", function ($matches) use (&$find_images, $max_item_images) {
$find_images++;
return $find_images <= $max_item_images ? '<img' . $matches[1] . '>' : '';
}, $body);
}
// If the text is more than 400 characters, then Yandex requires you to arrange paragraphs, but we do from 350
$content_text = strip_tags($body);
if (strlen($body) > 350) {
$body = preg_replace('~(?:\\r?\\n){2,}~', "\n", $body);
$body = explode("\n", $body);
foreach ($body as $line_key => $line_val) {
if (!preg_match("/(\\<p|\\<br|\\<ol|\\<ul|\\<li)/is", $line_val)) {
$body[$line_key] .= '<br>';
}
}
$body = implode("\n", $body);
}
// Make a headline
$body = "<header><h1>" . check_plain($node['title']) . "</h1></header>" . $body;
// Link to node
$node_uri = $node['alias'] ? $node['alias'] : 'node/' . $nid;
$data = array(
array(
'key' => 'title',
'value' => check_plain($node['title']),
),
array(
'key' => 'link',
'value' => url($node_uri, array(
'absolute' => TRUE,
)),
),
array(
'key' => 'pubDate',
'value' => date(DateTime::RFC822, $node['created']),
),
array(
'key' => 'turbo:content',
'value' => '<![CDATA[' . PHP_EOL . $body . PHP_EOL . ']]>',
'encoded' => TRUE,
),
);
$items .= format_xml_elements(array(
array(
'key' => 'item',
'value' => PHP_EOL . format_xml_elements($data),
'encoded' => TRUE,
'attributes' => array(
'turbo' => 'true',
),
),
));
}
$body = $node = $node_uri = $header = $h1 = null;
}
drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');
$cms_plugin = format_xml_elements(array(
array(
'key' => 'turbo:cms_plugin',
'value' => 'C2364A7B7F4160D5B2DC1718E3AE4970',
),
));
$items = $cms_plugin . $items;
$rss = array(
'key' => 'rss',
'value' => PHP_EOL . format_rss_channel($channel_title, $rss_link, $channel_description, $items),
'encoded' => TRUE,
'attributes' => array(
'xmlns:yandex' => 'http://news.yandex.ru',
'xmlns:media' => 'http://search.yahoo.com/mrss/',
'xmlns:turbo' => 'http://search.yahoo.com/mrss/',
'version' => '2.0',
),
);
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>" . PHP_EOL . format_xml_elements(array(
$rss,
));
}