From a3c47ab61422eee9bf901ed9d6891ac6bb9a8b4d Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Mon, 7 Nov 2005 15:30:01 +0000 Subject: [PATCH] Make RSS feeds be Smart(y). --- docs/NEWS | 8 + include/functions_rss.inc.php | 264 +++++++-------------------- include/functions_smarty.inc.php | 16 ++ rss.php | 283 +++++++---------------------- templates/default/feed_0.91.tpl | 26 +++ templates/default/feed_1.0.tpl | 59 ++++++ templates/default/feed_2.0.tpl | 53 ++++++ templates/default/feed_atom0.3.tpl | 56 ++++++ templates/default/feed_atom1.0.tpl | 59 ++++++ templates/default/feed_opml1.0.tpl | 16 ++ 10 files changed, 424 insertions(+), 416 deletions(-) create mode 100644 templates/default/feed_0.91.tpl create mode 100644 templates/default/feed_1.0.tpl create mode 100644 templates/default/feed_2.0.tpl create mode 100644 templates/default/feed_atom0.3.tpl create mode 100644 templates/default/feed_atom1.0.tpl create mode 100644 templates/default/feed_opml1.0.tpl diff --git a/docs/NEWS b/docs/NEWS index 58e417c..e93a609 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,10 @@ Version 1.0 () ------------------------------------------------------------------------ + * Make RSS feeds templatable with Smarty .tpl files (feed_*.tpl), so + that you can easily customize your feeds layouts, inject nagging + ads and so on (garvinhicking) + * Fix certain plugins to correctly behave when using entry- properties caching, by re-executing plugins that were not executed because they "scramble" the true content. (garvinhicking) @@ -10,6 +14,10 @@ Version 1.0 () Version 0.9.1 () ------------------------------------------------------------------------ + * Fix thumbnail generation for imageMagick when target image is + smaller than the target size, it should not be blown up + (garvinhicking) + * Fix spartacus plugin to not properly indicate updatable versions of plugins (garvinhicking) diff --git a/include/functions_rss.inc.php b/include/functions_rss.inc.php index d400da5..45a4e3f 100644 --- a/include/functions_rss.inc.php +++ b/include/functions_rss.inc.php @@ -1,8 +1,8 @@ - $entry['timestamp'])); + foreach ($entries as $key => $_entry) { + $entry = &$entries[$key]; + $entry['feed_id'] = (isset($entry['entryid']) && !empty($entry['entryid']) ? $entry['entryid'] : $entry['id']); + $entry['feed_guid'] = serendipity_rss_getguid($entry, $options['comments']); + $entry['feed_entryLink'] = serendipity_archiveURL($entry['feed_id'], $entry['title'], 'baseURL', true, array('timestamp' => $entry['timestamp'])); if ($options['comments'] == true) { // Display username as part of the title for easier feed-readability $entry['title'] = $entry['author'] . ': ' . $entry['title']; @@ -28,7 +29,7 @@ function serendipity_printEntries_rss($entries, $version, $comments = false, $fu $entry['body'] .= ' ' . $entry['extended']; $ext = ''; } elseif ($entry['exflag']) { - $ext = '
' . sprintf(VIEW_EXTENDED_ENTRY, htmlspecialchars($entry['title'])) . ''; + $ext = '
' . sprintf(VIEW_EXTENDED_ENTRY, htmlspecialchars($entry['title'])) . ''; } else { $ext = ''; } @@ -50,200 +51,65 @@ function serendipity_printEntries_rss($entries, $version, $comments = false, $fu } if (!is_array($entry['categories'])) { - $entry['categories'] = array(0 => array('category_name' => $entry['category_name'])); - } - - if ($options['version'] == 'atom0.3') { - /*********** ATOM 0.3 FEED *************/ -?> - - - - - - - - - - - wfwcomment.php?cid= - - - - rss.php?version=&type=comments&cid= - - - - <?php echo serendipity_utf8_encode(htmlspecialchars($entry['title'])); ?> - - -
- -
-
- -
- - - - - - - - - - - wfwcomment.php?cid= - - - - rss.php?version=&type=comments&cid= - $cat) { - $name = serendipity_utf8_encode(htmlspecialchars($cat['category_name'])); ?> - - - - <?php echo serendipity_utf8_encode(htmlspecialchars($entry['title'])); ?> - - -
- -
-
- -
- - - <?php echo serendipity_utf8_encode(htmlspecialchars($entry['title'])); ?> - - $cat) { - ?> - #comments - wfwcomment.php?cid= - - - rss.php?version=&type=comments&cid= - - - - - - - - - - - - -?> - - - - - - $cat) { - $categories[] = $cat['category_name']; - } - -?> - - <?php echo serendipity_utf8_encode(htmlspecialchars($entry['title'])); ?> - - - - - - array( + 'category_name' => $entry['category_name'], + 'feed_category_name' => serendipity_utf8_encode(htmlspecialchars($entry['category_name'])), + 'categoryURL' => serendipity_categoryURL($cat, 'baseURL') + )); + } else { + foreach($entry['categories'] AS $cid => $_cat) { + $cat = &$entry['categories'][$cid]; + $cat['categoryURL'] = serendipity_categoryURL($cat, 'baseURL'); + $cat['feed_category_name'] = serendipity_utf8_encode(htmlspecialchars($cat['category_name'])); } - - $entry['display_dat'] = ''; - serendipity_plugin_api::hook_event('frontend_display:rss-1.0:per_entry', $entry); - echo $entry['display_dat']; -?> - - - - - wfwcomment.php?cid= - - - rss.php?version=&type=comments&cid= - - - - -trigger_error(__FUNCTION__ .": missing 'entry' parameter"); + return; + } + if ( !isset($params['is_comments']) ) { + $smarty->trigger_error(__FUNCTION__ .": missing 'is_comments' parameter"); + return; + } + + return serendipity_rss_getguid($params['entry'], $params['is_comments']); +} function serendipity_smarty_formatTime($timestamp, $format, $useOffset = true) { if (defined($format)) { @@ -191,12 +203,16 @@ function serendipity_smarty_init() { $serendipity['smarty']->register_modifier('xhtml_target', 'serendipity_xhtml_target'); $serendipity['smarty']->register_modifier('emptyPrefix', 'serendipity_emptyPrefix'); $serendipity['smarty']->register_modifier('formatTime', 'serendipity_smarty_formatTime'); + $serendipity['smarty']->register_modifier('serendipity_utf8_encode', 'serendipity_utf8_encode'); + $serendipity['smarty']->register_function('serendipity_printSidebar', 'serendipity_smarty_printSidebar'); $serendipity['smarty']->register_function('serendipity_hookPlugin', 'serendipity_smarty_hookPlugin'); $serendipity['smarty']->register_function('serendipity_showPlugin', 'serendipity_smarty_showPlugin'); $serendipity['smarty']->register_function('serendipity_getFile', 'serendipity_smarty_getFile'); $serendipity['smarty']->register_function('serendipity_printComments', 'serendipity_smarty_printComments'); $serendipity['smarty']->register_function('serendipity_printTrackbacks', 'serendipity_smarty_printTrackbacks'); + $serendipity['smarty']->register_function('serendipity_rss_getguid', 'serendipity_smarty_rss_getguid'); + $serendipity['smarty']->register_prefilter('serendipity_replaceSmartyVars'); } diff --git a/rss.php b/rss.php index 165f78b..22ce931 100644 --- a/rss.php +++ b/rss.php @@ -30,12 +30,12 @@ if (!isset($_GET['type'])) { if (!isset($_GET['nocache'])) { switch ($_GET['type']) { - case 'comments': + case 'comments': $latest_entry = serendipity_fetchComments(isset($_GET['cid']) ? $_GET['cid'] : null, 1, 'desc'); - break; - case 'content': - default: - $latest_entry = serendipity_fetchEntries(null, false, 1, false, false, 'last_modified DESC', '', false, true); + break; + case 'content': + default: + $latest_entry = serendipity_fetchEntries(null, false, 1, false, false, 'last_modified DESC', '', false, true); break; } @@ -121,6 +121,13 @@ if (is_array($plugins)) { $plugin =& serendipity_plugin_api::load_plugin($plugin_data['name'], $plugin_data['authorid']); $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; + } + } $metadata['fullFeed'] = $plugin->get_config('fullfeed', false); $metadata['showMail'] = serendipity_db_bool($plugin->get_config('show_mail', $metadata['showMail'])); break; @@ -131,229 +138,71 @@ if (is_array($plugins)) { serendipity_plugin_api::hook_event('frontend_rss', $metadata); $self_url = 'http://' . $_SERVER['HTTP_HOST'] . htmlspecialchars($_SERVER['REQUEST_URI']); -echo ''; - -if (strstr($version, 'atom')) { - echo "\n" . ''; +if (!is_array($entries)) { + $entries = array(); } -echo "\n"; -switch ($version) { -case '0.91': - print << - -{$metadata['title']} -{$metadata['link']} -{$metadata['description']} -{$metadata['language']} -{$metadata['additional_fields']['image']} - -HEAD; -break; - -case '1.0': - $rdf_seq_li = "\n"; - if (is_array($entries)) { - foreach($entries AS $entry) { - $rdf_seq_li .= ' ' . "\n"; - } - - $entries['display_dat'] = ''; - serendipity_plugin_api::hook_event('frontend_display:rss-1.0:namespace', $entries); - } else { - $entries = array(); - } - - if ($metadata['showMail']) { - $head_mail = ""; - } else { - $head_mail = ''; - } +if ($entries[0]['last_modified']) { + $gm_modified = gmdate('Y-m-d\TH:i:s\Z', serendipity_serverOffsetHour($entries[0]['last_modified'])); +} else { + $gm_modified = gmdate('Y-m-d\TH:i:s\Z', serendipity_serverOffsetHour()); +} - print << - - {$metadata['title']} - {$metadata['link']} - {$metadata['description']} - {$metadata['language']} - $head_mail - - {$metadata['additional_fields']['image_rss1.0_channel']} - - - {$rdf_seq_li} - - - -{$metadata['additional_fields']['image_rss1.0_rdf']} - -HEAD; -break; - -case '2.0': - if (is_array($entries)) { - $entries['display_dat'] = ''; - serendipity_plugin_api::hook_event('frontend_display:rss-2.0:namespace', $entries); - } else { - $entries = array(); - } +$file_version = preg_replace('@[^0-9a-z\.-_]@i', '', $version); +$template_file = serendipity_getTemplateFile('feed_' . $file_version . '.tpl', 'serendipityPath'); +if (!$template_file) { + die("Invalid RSS version specified\n"); +} - if ($metadata['showMail']) { - $head_mail = ""; - } else { - $head_mail = ''; - } +serendipity_printEntries_rss($entries, $version, $comments, $metadata['fullFeed'], $metadata['showMail']); - print << - - {$metadata['title']} - {$metadata['link']} - {$metadata['description']} - {$metadata['language']} - $head_mail - Serendipity {$serendipity['version']} - http://www.s9y.org/ - {$metadata['additional_fields']['channel']} - {$metadata['additional_fields']['image']} - -HEAD; -break; - -case 'atom0.3': - if (is_array($entries)) { - $modified = gmdate('Y-m-d\TH:i:s\Z', serendipity_serverOffsetHour($entries[0]['last_modified'])); - } else { - $modified = gmdate('Y-m-d\TH:i:s\Z', serendipity_serverOffsetHour()); - } +$namespace_hook = 'frontend_display:unknown:namespace'; +$once_display_dat = ''; +switch($version) { + case 'opml1.0': + $namespace_hook = 'frontend_display:opml-1.0:namespace'; + break; - if ($metadata['showMail']) { - $head_mail = ""; - } else { - $head_mail = ''; - } + case '0.91': + $namespace_hook = 'frontend_display:rss-0.91:namespace'; + break; - print << - - - - {$metadata['title']} - {$metadata['description']} - {$metadata['link']} - $modified - Serendipity {$serendipity['version']} - http://www.s9y.org/ - {$metadata['language']} - $head_mail - -
You are viewing an ATOM formatted XML site feed. Usually this file is inteded to be viewed in an aggregator or syndication software. If you want to know more about ATOM, please visist Atomenabled.org
-
- -HEAD; -break; - -case 'atom1.0': - if (is_array($entries)) { - $modified = gmdate('Y-m-d\TH:i:s\Z', serendipity_serverOffsetHour($entries[0]['last_modified'])); - } else { - $modified = gmdate('Y-m-d\TH:i:s\Z', serendipity_serverOffsetHour()); - } + case '1.0': + $namespace_hook = 'frontend_display:rss-1.0:namespace'; + serendipity_plugin_api::hook_event('frontend_display:rss-1.0:once', $entries); + $once_display_dat = $entries['display_dat']; + unset($entries['display_dat']); + break; - if ($metadata['showMail']) { - $head_mail = ""; - } else { - $head_mail = ''; - } + case '2.0': + $namespace_hook = 'frontend_display:rss-2.0:namespace'; + break; - print << - - - - {$metadata['title']} - {$metadata['description']} - {$metadata['additional_fields']['image_atom1.0']} - {$metadata['link']} - $modified - Serendipity {$serendipity['version']} - http://www.s9y.org/ - {$metadata['language']} - $head_mail - -HEAD; -break; - -case 'opml1.0': - if (is_array($entries)) { - $modified = gmdate('Y-m-d\TH:i:s\Z', serendipity_serverOffsetHour($entries[0]['last_modified'])); - } else { - $modified = gmdate('Y-m-d\TH:i:s\Z', serendipity_serverOffsetHour()); - } - print << - - {$metadata['title']} - $modified - Serendipity {$serendipity['version']} - http://www.s9y.org/ - - -HEAD; -break; + case 'atom0.3': + $namespace_hook = 'frontend_display:atom-0.3:namespace'; + break; -default: - die("Invalid RSS version specified\n"); + case 'atom1.0': + $namespace_hook = 'frontend_display:atom-1.0:namespace'; + break; } -unset($entries['display_dat']); // Only needed for headers. -serendipity_printEntries_rss($entries, $version, $comments, $metadata['fullFeed'], $metadata['showMail']); - -switch ($version) { -case '0.91': -case '2.0': - print "
\n"; - print "\n"; - break; -case '1.0': - if (is_array($entries)) { - $entries['display_dat'] = ''; - serendipity_plugin_api::hook_event('frontend_display:rss-1.0:once', $entries); - echo $entries['display_dat']; - } - print ''; - break; -case 'atom1.0': -case 'atom0.3': - print ''; - break; -case 'opml1.0': - print "\n"; -} +serendipity_plugin_api::hook_event($namespace_hook, $entries); +$namespace_display_dat = $entries['display_dat']; +unset($entries['display_dat']); + +serendipity_smarty_init(); +$serendipity['smarty']->assign( + array( + 'metadata' => $metadata, + 'entries' => $entries, + 'is_comments' => $comments, + 'last_modified' => $gm_modified, + 'self_url' => $self_url, + 'namespace_display_dat' => $namespace_display_dat, + 'once_display_dat' => $once_display_dat + ) +); +$serendipity['smarty']->display($template_file); /* vim: set sts=4 ts=4 expandtab : */ -?> diff --git a/templates/default/feed_0.91.tpl b/templates/default/feed_0.91.tpl new file mode 100644 index 0000000..2fb0d6e --- /dev/null +++ b/templates/default/feed_0.91.tpl @@ -0,0 +1,26 @@ + + + + +{$metadata.title} +{$metadata.link} +{$metadata.description} +{$metadata.language} +{$metadata.additional_fields.image} + +{foreach from=$entries item="entry"} + + {$entry.feed_title} + {$entry.feed_entryLink} + +{if !empty($entry.body)} + + {$entry.feed_body|@escape} {$entry.feed_ext|@escape} + +{/if} + +{/foreach} + + + + diff --git a/templates/default/feed_1.0.tpl b/templates/default/feed_1.0.tpl new file mode 100644 index 0000000..dc5e70b --- /dev/null +++ b/templates/default/feed_1.0.tpl @@ -0,0 +1,59 @@ + + + + + {$metadata.title} + {$metadata.link} + {$metadata.description} + {$metadata.language} +{if $metadata.showMail} + +{/if} + + {$metadata.additional_fields.image_rss10_channel} + + + +{foreach from=$entries item="entry"} + +{/foreach} + + + + +{$metadata.additional_fields.image_rss10_rdf} +{$once_display_dat} + +{foreach from=$entries item="entry"} + + {$entry.feed_title} + {$entry.feed_entryLink} +{if !empty($entry.body)} + + {$entry.feed_body|@escape} {$entry.feed_ext|@escape} + +{/if} + + {$entry.feed_blogTitle} + {$entry.feed_email} ({$entry.feed_author}) + + {foreach from=$entry.categories item="cat"}{$cat.feed_category_name}, {/foreach} + {$entry.feed_timestamp} + {$serendipityBaseURL}wfwcomment.php?cid={$entry.feed_id} +{if !$is_comments} + {$entry.comments} + {$serendipityBaseURL}rss.php?version={$metadata.version}&type=comments&cid={$entry.feed_id} +{/if} + {$entry.per_entry_display_dat} + +{/foreach} + + + diff --git a/templates/default/feed_2.0.tpl b/templates/default/feed_2.0.tpl new file mode 100644 index 0000000..6631b87 --- /dev/null +++ b/templates/default/feed_2.0.tpl @@ -0,0 +1,53 @@ + + + + + {$metadata.title} + {$metadata.link} + {$metadata.description} + {$metadata.language} +{if $metadata.showMail} + +{/if} + Serendipity {$serendipityVersion} - http://www.s9y.org/ + {$metadata.additional_fields.channel} + {$metadata.additional_fields.image} + +{foreach from=$entries item="entry"} + + {$entry.feed_title} + {$entry.feed_entryLink} + {foreach from=$entry.categories item="cat"} + {$cat.feed_category_name} + {/foreach} + + {$entry.feed_entryLink}#comments + {$serendipityBaseURL}wfwcomment.php?cid={$entry.feed_id} + +{if !$is_comments} + {$entry.comments} + {$serendipityBaseURL}rss.php?version={$metadata.version}&type=comments&cid={$entry.feed_id} +{/if} + + {$entry.feed_email} ({$entry.feed_author}) +{if !empty($entry.body)} + + {$entry.feed_body|@escape} {$entry.feed_ext|@escape} + +{/if} + + {$entry.feed_timestamp_r} + {$entry.feed_guid} + {$entry.per_entry_display_dat} + +{/foreach} + + + diff --git a/templates/default/feed_atom0.3.tpl b/templates/default/feed_atom0.3.tpl new file mode 100644 index 0000000..9c873b5 --- /dev/null +++ b/templates/default/feed_atom0.3.tpl @@ -0,0 +1,56 @@ + + + + + + + + {$metadata.title} + {$metadata.description} + {$metadata.link} + {$last_modified} + Serendipity {$serendipityVersion} - http://www.s9y.org/ + {$metadata.language} +{if $metadata.showMail} + +{/if} + +
You are viewing an ATOM formatted XML site feed. Usually this file is inteded to be viewed in an aggregator or syndication software. If you want to know more about ATOM, please visist Atomenabled.org
+
+ +{foreach from=$entries item="entry"} + + + + {$entry.feed_author} + {$entry.feed_email} + + + {$entry.feed_timestamp} + {$entry.feed_timestamp} + {$entry.feed_last_modified} + {$serendipityBaseURL}wfwcomment.php?cid={$entry.feed_id} +{if !$is_comments} + {$entry.comments} + {$serendipityBaseURL}rss.php?version={$metadata.version}&type=comments&cid={$entry.feed_id} +{/if} + {$entry.feed_guid} + {$entry.feed_title} +{if !empty($entry.body)} + +
+ {$entry.feed_body} {$entry.feed_ext} +
+
+{/if} + + {$entry.per_entry_display_dat} +
+{/foreach} +
\ No newline at end of file diff --git a/templates/default/feed_atom1.0.tpl b/templates/default/feed_atom1.0.tpl new file mode 100644 index 0000000..a05e634 --- /dev/null +++ b/templates/default/feed_atom1.0.tpl @@ -0,0 +1,59 @@ + + + + + + + + {$metadata.title} + {$metadata.description} + {$metadata.additional_fields.image_atom10} + {$metadata.link} + {$last_modified} + Serendipity {$serendipityVersion} - http://www.s9y.org/ + {$metadata.language} +{if $metadata.showMail} + +{/if} + +{foreach from=$entries item="entry"} + + + + {$entry.feed_author} + {$entry.feed_email} + + + {$entry.feed_timestamp} + {$entry.feed_last_modified} + {$serendipityBaseURL}wfwcomment.php?cid={$entry.feed_id} + +{if !$is_comments} + {$entry.comments} + {$serendipityBaseURL}rss.php?version={$metadata.version}&type=comments&cid={$entry.feed_id} +{/if} + + {foreach from=$entry.categories item="cat"} + + {/foreach} + + {$entry.feed_guid} + {$entry.feed_title} +{if !empty($entry.body)} + +
+ {$entry.feed_body} {$entry.feed_ext} +
+
+{/if} + {$entry.per_entry_display_dat} +
+{/foreach} + +
\ No newline at end of file diff --git a/templates/default/feed_opml1.0.tpl b/templates/default/feed_opml1.0.tpl new file mode 100644 index 0000000..3d3b2d4 --- /dev/null +++ b/templates/default/feed_opml1.0.tpl @@ -0,0 +1,16 @@ + + + + + {$metadata.title} + {$last_modified} + Serendipity {$serendipityVersion} - http://www.s9y.org/ + + + +{foreach from=$entries item="entry"} + +{/foreach} + + + \ No newline at end of file -- 2.39.5