syndication: feed options into core; option for rss + atom

The force-feed option still needs to be included into the core
This commit is contained in:
onli 2014-06-29 03:10:43 +02:00
parent 150f3e1e64
commit 719ed77457
3 changed files with 191 additions and 241 deletions

View File

@ -538,6 +538,74 @@
'permission' => 'blogConfiguration')
);
$res['feeds'] =
array('title' => INSTALL_CAT_FEEDS,
'description' => INSTALL_CAT_FEEDS_DESC,
'items' => array(
array('var' => 'fullfeed',
'title' => SYNDICATION_PLUGIN_FULLFEED,
'description' => '',
'type' => 'list',
'default' => array('false' => NO, 'true' => YES, 'client' => 'Client'),
'permission' => 'siteConfiguration'),
array('var' => 'feedBannerURL',
'title' => SYNDICATION_PLUGIN_BANNERURL,
'description' => SYNDICATION_PLUGIN_BANNERURL_DESC,
'type' => 'string',
'default' => '',
'permission' => 'blogConfiguration'),
array('var' => 'feedBannerWidth',
'title' => SYNDICATION_PLUGIN_BANNERWIDTH,
'description' => SYNDICATION_PLUGIN_BANNERWIDTH_DESC,
'type' => 'string',
'default' => '',
'permission' => 'blogConfiguration'),
array('var' => 'feedBannerHeight',
'title' => SYNDICATION_PLUGIN_BANNERHEIGHT,
'description' => SYNDICATION_PLUGIN_BANNERHEIGHT_DESC,
'type' => 'string',
'default' => '',
'permission' => 'blogConfiguration'),
array('var' => 'feedShowMail',
'title' => SYNDICATION_PLUGIN_SHOW_MAIL,
'description' => '',
'type' => 'bool',
'default' => false,
'permission' => 'blogConfiguration'),
array ('var' => 'feedManagingEditor',
'title' => SYNDICATION_PLUGIN_MANAGINGEDITOR,
'description' => SYNDICATION_PLUGIN_MANAGINGEDITOR_DESC,
'type' => 'string',
'default' => '',
'permission' => 'blogConfiguration'),
array ('var' => 'feedWebmaster',
'title' => SYNDICATION_PLUGIN_WEBMASTER,
'description' => SYNDICATION_PLUGIN_WEBMASTER_DESC,
'type' => 'string',
'default' => '',
'permission' => 'blogConfiguration'),
array ('var' => 'feedTtl',
'title' => SYNDICATION_PLUGIN_TTL,
'description' => SYNDICATION_PLUGIN_TTL_DESC,
'type' => 'string',
'default' => '',
'permission' => 'blogConfiguration'),
array ('var' => 'feedPubDate',
'title' => SYNDICATION_PLUGIN_PUBDATE,
'description' => SYNDICATION_PLUGIN_PUBDATE_DESC,
'type' => 'bool',
'default' => true,
'permission' => 'blogConfiguration')
));
$res['imagehandling'] =
array('title' => INSTALL_CAT_IMAGECONV,
'description' => INSTALL_CAT_IMAGECONV_DESC,

View File

@ -12,25 +12,15 @@ class serendipity_plugin_syndication extends serendipity_plugin {
$propbag->add('version', '2.0');
$propbag->add('configuration', array(
'title',
'fullfeed',
'big_img',
'feed_format',
'subToMe',
'show_comment_feed',
'seperator',
'show_mail',
'field_managingEditor',
'field_webMaster',
'field_ttl',
'field_pubDate',
'bannerURL',
'bannerWidth',
'bannerHeight',
'seperator2',
'iconURL',
'feed_name',
'comment_name',
'seperator3',
'seperator2',
'fb_id',
'custom_url'
)
@ -48,34 +38,16 @@ class serendipity_plugin_syndication extends serendipity_plugin {
$propbag->add('default', SYNDICATE_THIS_BLOG);
break;
case 'fullfeed':
$radio['value'][] = 'false';
$radio['desc'][] = NO;
$radio['value'][] = 'true';
$radio['desc'][] = YES;
$radio['value'][] = 'client';
$radio['desc'][] = 'Client';
$propbag->add('type', 'radio');
$propbag->add('name', SYNDICATION_PLUGIN_FULLFEED);
$propbag->add('description', '');
$propbag->add('default', false);
$propbag->add('radio_per_row', '3');
$propbag->add('radio', $radio);
break;
case 'feed_format':
$propbag->add('type', 'radio');
$propbag->add('name', 'Feed Format'); // i18n
$propbag->add('description', 'Which format shall be used for all feeds. Both are supported in all common readers'); // i18n
$propbag->add('default', 'rss');
$propbag->add('radio', array(
'value' => array('rss', 'atom'),
'desc' => array(SYNDICATION_PLUGIN_20, sprintf(SYNDICATION_PLUGIN_GENERIC_FEED, 'Atom 1.0'))
'value' => array('rss', 'atom', 'rssatom'),
'desc' => array(SYNDICATION_PLUGIN_20, sprintf(SYNDICATION_PLUGIN_GENERIC_FEED, 'Atom 1.0'), SYNDICATION_PLUGIN_20 .' + '. sprintf(SYNDICATION_PLUGIN_GENERIC_FEED, 'Atom 1.0'))
));
$propbag->add('radio_per_row', '1');
$propbag->add('radio_per_row', '3');
break;
case 'fb_id':
@ -94,45 +66,9 @@ class serendipity_plugin_syndication extends serendipity_plugin {
case 'seperator':
case 'seperator2':
case 'seperator3':
$propbag->add('type', 'seperator');
break;
case 'show_mail':
$propbag->add('type', 'boolean');
$propbag->add('name', SYNDICATION_PLUGIN_SHOW_MAIL);
$propbag->add('description', '');
$propbag->add('default', false);
break;
case 'field_managingEditor':
$propbag->add('type', 'string');
$propbag->add('name', SYNDICATION_PLUGIN_MANAGINGEDITOR);
$propbag->add('description', SYNDICATION_PLUGIN_MANAGINGEDITOR_DESC);
$propbag->add('default', '');
break;
case 'field_webMaster':
$propbag->add('type', 'string');
$propbag->add('name', SYNDICATION_PLUGIN_WEBMASTER);
$propbag->add('description', SYNDICATION_PLUGIN_WEBMASTER_DESC);
$propbag->add('default', '');
break;
case 'field_ttl':
$propbag->add('type', 'string');
$propbag->add('name', SYNDICATION_PLUGIN_TTL);
$propbag->add('description', SYNDICATION_PLUGIN_TTL_DESC);
$propbag->add('default', '');
break;
case 'field_pubDate':
$propbag->add('type', 'boolean');
$propbag->add('name', SYNDICATION_PLUGIN_PUBDATE);
$propbag->add('description', SYNDICATION_PLUGIN_PUBDATE_DESC);
$propbag->add('default', true);
break;
case 'iconURL':
$propbag->add('type', 'string');
$propbag->add('name', XML_IMAGE_TO_DISPLAY);
@ -140,27 +76,6 @@ class serendipity_plugin_syndication extends serendipity_plugin {
$propbag->add('default', 'img/xml.gif');
break;
case 'bannerURL':
$propbag->add('type', 'string');
$propbag->add('name', SYNDICATION_PLUGIN_BANNERURL);
$propbag->add('description', SYNDICATION_PLUGIN_BANNERURL_DESC);
$propbag->add('default', '');
break;
case 'bannerWidth':
$propbag->add('type', 'string');
$propbag->add('name', SYNDICATION_PLUGIN_BANNERWIDTH);
$propbag->add('description', SYNDICATION_PLUGIN_BANNERWIDTH_DESC);
$propbag->add('default', '');
break;
case 'bannerHeight':
$propbag->add('type', 'string');
$propbag->add('name', SYNDICATION_PLUGIN_BANNERHEIGHT);
$propbag->add('description', SYNDICATION_PLUGIN_BANNERHEIGHT_DESC);
$propbag->add('default', '');
break;
case 'big_img':
$propbag->add('type', 'string');
$propbag->add('name', 'Feed Icon'); // i18n
@ -215,11 +130,14 @@ class serendipity_plugin_syndication extends serendipity_plugin {
$subtome = serendipity_db_bool($this->get_config('subToMe', true));
$fbid = $this->get_config('fb_id');
$custom_url = $this->get_config('custom_url', '');
$feed_format = $this->get_config('feed_format', 'rss');
$useRss = true;
if ($this->get_config('feed_format', 'rss') == 'atom') {
if ($feed_format == 'atom') {
$useRss = false;
$useAtom = true;
} else if ($feed_format == 'rssatom') {
$useAtom = true;
}
$img = 'http://feeds.feedburner.com/~fc/'.$this->get_config('fb_id').'?bg=99CCFF&fg=444444&anim=0';
@ -254,7 +172,7 @@ class serendipity_plugin_syndication extends serendipity_plugin {
if ($fbid != "") {
$mainFeed ='http://feeds.feedburner.com/' . $fbid;
} else {
if ($useAtom) {
if ($useAtom && ! $useRss) {
$mainFeed = serendipity_rewriteURL(PATH_FEEDS .'/atom10.xml', 'serendipityHTTPPath');
}
}
@ -266,123 +184,35 @@ class serendipity_plugin_syndication extends serendipity_plugin {
}
echo '<ul id="serendipity_syndication_list" style="list-style: none; margin: 0px; padding: 0px">';
echo "<li>
<a id='serendipity_subtome'
class='serendipity_xml_icon'
href='$mainFeed'
$onclick
>
<img src='$icon' alt='XML' style='border: 0px' />
" . ($icon == $small_icon ? ($useRss ? "RSS $FEED " : "Atom $FEED") : "") . "
</a>
</li>";
echo $this->generateFeedButton($mainFeed, ($icon == $small_icon ? ($useRss ? "RSS $FEED" : "Atom $FEED") : ""), $onclick, $icon);
if ($useRss && $useAtom) {
echo $this->generateFeedButton(serendipity_rewriteURL(PATH_FEEDS .'/atom10.xml', 'serendipityHTTPPath'), "Atom $FEED", $onclick, $small_icon);
}
if (serendipity_db_bool($this->get_config('show_2.0c', false)) || serendipity_db_bool($this->get_config('show_comment_feed', false))) {
if ($subtome) {
$onclick=$this->getOnclick(serendipity_rewriteURL(PATH_FEEDS .'/comments.rss2', 'serendipityHTTPPath'));
}
$href = serendipity_rewriteURL(PATH_FEEDS .'/comments.rss2', 'serendipityHTTPPath');
if ($useAtom) {
$href = serendipity_rewriteURL(PATH_FEEDS .'/comments.atom', 'serendipityHTTPPath');
}
echo "<li>
<a class='serendipity_xml_icon'
href='$href'
$onclick
>
<img src='$small_icon' alt='XML' style='border: 0px' />
$COMMENTS $FEED
</a>
</li>";
echo $this->generateFeedButton(($useAtom && ! $useRss ? serendipity_rewriteURL(PATH_FEEDS .'/comments.atom', 'serendipityHTTPPath') : serendipity_rewriteURL(PATH_FEEDS .'/comments.rss2', 'serendipityHTTPPath')),
$COMMENTS,
($subtome ? $this->getOnclick(serendipity_rewriteURL(PATH_FEEDS .'/comments.rss2', 'serendipityHTTPPath')) : ""),
$small_icon);
}
echo "</ul>";
}
function generateFeedButton($feed, $label, $onlick, $icon) {
$link = "class='serendipity_xml_icon' href='$feed' $onclick";
$output = "<li>
<a id='serendipity_subtome' $link><img src='$icon' alt='XML' style='border: 0px' /></a>";
if (! empty($label)) {
$output .= " <a $link>$label</a>";
}
return $output .= "</li>";
}
function getOnclick($url) {
return "onclick=\"document.subtomeBtn=document.querySelector('#serendipity_subtome');document.subtomeBtn.dataset['subtomeFeeds']='". urlencode($url). "';var s=document.createElement('script');s.src='https://www.subtome.com/load.js';document.body.appendChild(s);return false;\"";
}
function generate_rss_fields(&$title, &$description, &$entries) {
global $serendipity;
// Check for a logo to use for an RSS feed. Can either be set by configuring the
// syndication plugin OR by just placing a rss_banner.png file in the template directory.
// If both is not set, we will display our happy own branding. :-)
$bag = new serendipity_property_bag;
$this->introspect($bag);
$additional_fields = array();
if ($this->get_config('bannerURL') != '') {
$img = $this->get_config('bannerURL');
$w = $this->get_config('bannerWidth');
$h = $this->get_config('bannerHeight');
} elseif (($banner = serendipity_getTemplateFile('img/rss_banner.png', 'serendipityPath'))) {
$img = serendipity_getTemplateFile('img/rss_banner.png', 'baseURL');
$i = getimagesize($banner);
$w = $i[0];
$h = $i[1];
} else {
$img = serendipity_getTemplateFile('img/s9y_banner_small.png', 'baseURL');
$w = 100;
$h = 21;
}
$additional_fields['image'] = <<<IMAGE
<image>
<url>$img</url>
<title>RSS: $title - $description</title>
<link>{$serendipity['baseURL']}</link>
<width>$w</width>
<height>$h</height>
</image>
IMAGE;
$additional_fields['image_atom1.0'] = <<<IMAGE
<icon>$img</icon>
IMAGE;
$additional_fields['image_rss1.0_channel'] = '<image rdf:resource="' . $img . '" />';
$additional_fields['image_rss1.0_rdf'] = <<<IMAGE
<image rdf:about="$img">
<url>$img</url>
<title>RSS: $title - $description</title>
<link>{$serendipity['baseURL']}</link>
<width>$w</width>
<height>$h</height>
</image>
IMAGE;
// Now, if set, stitch together any fields that have been configured in the syndication plugin.
// First, do some sanity checks
$additional_fields['channel'] = '';
foreach($bag->get('configuration') AS $bag_index => $bag_value) {
if (preg_match('|^field_(.*)$|', $bag_value, $match)) {
$bag_content = $this->get_config($bag_value);
switch($match[1]) {
case 'pubDate':
if (serendipity_db_bool($bag_content)) {
$bag_content = gmdate('D, d M Y H:i:s \G\M\T', $entries[0]['last_modified']);
} else {
$bag_content = '';
}
break;
// Each new RSS-field which needs rewrite of its content should get its own case here.
default:
break;
}
if ($bag_content != '') {
$additional_fields['channel'] .= '<' . $match[1] . '>' . $bag_content . '</' . $match[1] . '>' . "\n";
}
}
}
return $additional_fields;
}
}
?>

136
rss.php
View File

@ -138,57 +138,109 @@ $metadata = array(
'version' => $version
);
if (serendipity_get_config_var('feedBannerURL') != '') {
$img = serendipity_get_config_var('feedBannerURL');
$w = serendipity_get_config_var('feedBannerWidth');
$h = serendipity_get_config_var('feedBannerHeight');
} elseif (($banner = serendipity_getTemplateFile('img/rss_banner.png', 'serendipityPath'))) {
$img = serendipity_getTemplateFile('img/rss_banner.png', 'baseURL');
$i = getimagesize($banner);
$w = $i[0];
$h = $i[1];
} else {
$img = serendipity_getTemplateFile('img/s9y_banner_small.png', 'baseURL');
$w = 100;
$h = 21;
}
include_once(S9Y_INCLUDE_PATH . 'include/plugin_api.inc.php');
$metadata['additional_fields']['image'] = <<<IMAGE
<image>
<url>$img</url>
<title>RSS: $title - $description</title>
<link>{$serendipity['baseURL']}</link>
<width>$w</width>
<height>$h</height>
</image>
IMAGE;
$plugins = serendipity_plugin_api::enum_plugins();
$metadata['additional_fields']['image_atom1.0'] = <<<IMAGE
<icon>$img</icon>
IMAGE;
if (is_array($plugins)) {
// load each plugin to make some introspection
foreach ($plugins as $plugin_data) {
if (preg_match('@(serendipity_syndication_plugin|serendipity_plugin_syndication)@', $plugin_data['name'])) {
$plugin =& serendipity_plugin_api::load_plugin($plugin_data['name'], $plugin_data['authorid']);
$metadata['additional_fields']['image_rss1.0_channel'] = '<image rdf:resource="' . $img . '" />';
$metadata['additional_fields']['image_rss1.0_rdf'] = <<<IMAGE
<image rdf:about="$img">
<url>$img</url>
<title>RSS: $title - $description</title>
<link>{$serendipity['baseURL']}</link>
<width>$w</width>
<height>$h</height>
</image>
IMAGE;
$metadata['additional_fields'] = $plugin->generate_rss_fields($metadata['title'], $metadata['description'], $entries);
if (is_array($metadata['additional_fields'])) {
// Fix up array keys, because "." are not allowed when wanting to output using Smarty
foreach($metadata['additional_fields'] AS $_aid => $af) {
$aid = str_replace('.', '', $_aid);
$metadata['additional_fields'][$aid] = $af;
}
// Now, if set, stitch together any fields that have been configured in the syndication plugin.
// First, do some sanity checks
$metadata['additional_fields']['channel'] = '';
$rssFields = array('feedManagingEditor' => 'managingEditor', 'feedWebmaster' => 'webMaster', 'feedTtl' => 'ttl', 'feedPubDate' => 'pubDate');
foreach( $rssFields as $configName => $field) {
$fieldValue = serendipity_get_config_var($configName);
switch($field) {
case 'pubDate':
if (serendipity_db_bool($fieldValue)) {
$fieldValue = gmdate('D, d M Y H:i:s \G\M\T', $entries[0]['last_modified']);
} else {
$fieldValue = '';
}
$metadata['fullFeed'] = $plugin->get_config('fullfeed', false);
if ($metadata['fullFeed'] === 'client') {
if ($_GET['fullFeed'] || $serendipity['GET']['fullFeed']) {
$metadata['fullFeed'] = true;
} else {
$metadata['fullFeed'] = false;
}
}
if ($_GET['type'] == 'content' &&
!isset($_GET['category']) &&
!isset($serendipity['GET']['tag']) &&
$plugin->get_config('show_feedburner') === 'force' &&
!preg_match('@FeedBurn@i', $_SERVER['HTTP_USER_AGENT']) &&
!(serendipity_userLoggedIn() && isset($_GET['forceLocal']))
) {
$fbid = $plugin->get_config('fb_id');
if (stristr($fbid, 'http://')) {
$url = $fbid;
} else {
$url = 'http://feeds.feedburner.com/' . $fbid;
}
header('Status: 302 Found');
header('Location: ' . $url);
exit;
}
$metadata['showMail'] = serendipity_db_bool($plugin->get_config('show_mail', $metadata['showMail']));
break;
}
// Each new RSS-field which needs rewrite of its content should get its own case here.
default:
break;
}
if ($fieldValue != '') {
$metadata['additional_fields']['channel'] .= '<' . $field . '>' . $fieldValue . '</' . $field . '>' . "\n";
}
}
if (is_array($metadata['additional_fields'])) {
// Fix up array keys, because "." are not allowed when wanting to output using Smarty
foreach($metadata['additional_fields'] AS $_aid => $af) {
$aid = str_replace('.', '', $_aid);
$metadata['additional_fields'][$aid] = $af;
}
}
$metadata['fullFeed'] = serendipity_get_config_var('fullfeed', false);
if ($metadata['fullFeed'] === 'client') {
if ($_GET['fullFeed'] || $serendipity['GET']['fullFeed']) {
$metadata['fullFeed'] = true;
} else {
$metadata['fullFeed'] = false;
}
}
// TODO: Recode option to force a specific feed instead of showing the main feed
//if ($_GET['type'] == 'content' &&
//!isset($_GET['category']) &&
//!isset($serendipity['GET']['tag']) &&
//$plugin->get_config('show_feedburner') === 'force' &&
//!preg_match('@FeedBurn@i', $_SERVER['HTTP_USER_AGENT']) &&
//!(serendipity_userLoggedIn() && isset($_GET['forceLocal']))
//) {
//$fbid = $plugin->get_config('fb_id');
//if (stristr($fbid, 'http://')) {
//$url = $fbid;
//} else {
//$url = 'http://feeds.feedburner.com/' . $fbid;
//}
//header('Status: 302 Found');
//header('Location: ' . $url);
//exit;
//}
$metadata['showMail'] = serendipity_db_bool(serendipity_get_config_var('show_mail', $metadata['showMail']));
$file_version = preg_replace('@[^0-9a-z\.-_]@i', '', $version);
$metadata['template_file'] = serendipity_getTemplateFile('feed_' . $file_version . '.tpl', 'serendipityPath');