From: garvinhicking <garvinhicking> Date: Tue, 25 Jul 2006 09:42:28 +0000 (+0000) Subject: Patch by stm: Support trackback and trackback+comment Feeds X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=6f29294c367550506767766a6726a67657121485;p=s9y.git Patch by stm: Support trackback and trackback+comment Feeds --- diff --git a/docs/NEWS b/docs/NEWS index 8a056ec..795a6a6 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,8 @@ Version 1.1-alpha7() ------------------------------------------------------------------------ + * Add "Comments and Trackbacks" feed feature (stm99..) + * Add LiveJournal XML importer (garvinhicking) * Fix not fetching allow_comments/moderate_comments value when diff --git a/include/functions.inc.php b/include/functions.inc.php index 4e23b51..cc57e23 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -927,8 +927,12 @@ function serendipity_discover_rss($name, $ext) { static $default = '2.0'; /* Detect type */ - if ( $name == 'comments' ) { + if ($name == 'comments') { $type = 'comments'; + } elseif ($name == 'comments_and_trackbacks') { + $type = 'comments_and_trackbacks'; + } elseif ($name == 'trackbacks') { + $type = 'trackbacks'; } else { $type = 'content'; } diff --git a/include/functions_comments.inc.php b/include/functions_comments.inc.php index 86ee43a..fd4bcc0 100644 --- a/include/functions_comments.inc.php +++ b/include/functions_comments.inc.php @@ -114,9 +114,10 @@ function serendipity_displayCommentForm($id, $url = '', $comments = NULL, $data * @param int How many comments to fetch (empty: all) * @param string How shall comments be ordered (ASC|DESC) * @param boolean Shall non-approved comments be displayed? + * @param string Comment type to fetch * @return array The SQL result of comments */ -function serendipity_fetchComments($id, $limit = null, $order = '', $showAll = false) { +function serendipity_fetchComments($id, $limit = null, $order = '', $showAll = false, $type = 'NORMAL') { global $serendipity; $and = ''; @@ -125,6 +126,14 @@ function serendipity_fetchComments($id, $limit = null, $order = '', $showAll = f } else { $limit = ''; } + + if ($type == 'comments') { + $type = 'NORMAL'; + } elseif ($type == 'trackbacks') { + $type = 'TRACKBACK'; + } elseif ($type == 'comments_and_trackbacks') { + $type = '%'; + } if (!empty($id)) { $and .= " AND co.entry_id = '" . (int)$id ."'"; @@ -154,7 +163,7 @@ function serendipity_fetchComments($id, $limit = null, $order = '', $showAll = f FROM {$serendipity['dbPrefix']}comments co LEFT JOIN {$serendipity['dbPrefix']}entries e ON (co.entry_id = e.id) - WHERE co.type LIKE 'NORMAL' AND co.entry_id > 0 $and + WHERE co.type LIKE '" . $type . "' AND co.entry_id > 0 $and $group ORDER BY co.id " . ($order != '' ? $order : '') . " diff --git a/include/functions_rss.inc.php b/include/functions_rss.inc.php index e9a8f3c..b397b52 100644 --- a/include/functions_rss.inc.php +++ b/include/functions_rss.inc.php @@ -41,6 +41,9 @@ function serendipity_printEntries_rss(&$entries, $version, $comments = false, $f $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 + if ($entry['type'] == 'TRACKBACK' && !empty($entry['ctitle'])) { + $entry['author'] .= ' - ' . $entry['ctitle']; + } $entry['title'] = (!empty($entry['author']) ? $entry['author'] : ANONYMOUS) . ': ' . $entry['title']; } diff --git a/index.php b/index.php index 85ea8af..0c0835c 100644 --- a/index.php +++ b/index.php @@ -278,7 +278,7 @@ if (preg_match(PAT_ARCHIVES, $uri, $matches) || isset($serendipity['GET']['range $serendipity['view'] = 'feed'; header('Content-Type: text/html; charset=utf-8'); - if (preg_match('@/(index|atom[0-9]*|rss|comments|opml)\.(rss[0-9]?|rdf|rss|xml|atom)@', $uri, $vmatches)) { + if (preg_match('@/(index|atom[0-9]*|rss|comments|trackbacks|comments_and_trackbacks|opml)\.(rss[0-9]?|rdf|rss|xml|atom)@', $uri, $vmatches)) { list($_GET['version'], $_GET['type']) = serendipity_discover_rss($vmatches[1], $vmatches[2]); } diff --git a/plugins/serendipity_plugin_comments/serendipity_plugin_comments.php b/plugins/serendipity_plugin_comments/serendipity_plugin_comments.php index 3123a6e..aa74cc1 100644 --- a/plugins/serendipity_plugin_comments/serendipity_plugin_comments.php +++ b/plugins/serendipity_plugin_comments/serendipity_plugin_comments.php @@ -22,7 +22,7 @@ class serendipity_plugin_comments extends serendipity_plugin $propbag->add('description', PLUGIN_COMMENTS_BLAHBLAH); $propbag->add('stackable', true); $propbag->add('author', 'Garvin Hicking/Tadashi Jokagi/Judebert'); - $propbag->add('version', '1.8'); + $propbag->add('version', '1.9'); $propbag->add('requirements', array( 'serendipity' => '0.8', 'smarty' => '2.6.7', @@ -191,9 +191,10 @@ class serendipity_plugin_comments extends serendipity_plugin 'email' => $row['comment_email']); // Let's help the BBCOde plugin a bit: - #$entry['comment'] = preg_replace('@((\[.*)[\n\r]+(.*\]))+@imsU', '\2\3', $entry['comment']); - #$entry['comment'] = preg_replace('@((\[.+\].*)[\r\n]+(.*\[/.+\]))+@imsU', '\2\3', $entry['comment']); - + if (class_exists('serendipity_event_bbcode')) { + $entry['comment'] = preg_replace('@((\[.*)[\n\r]+(.*\]))+@imsU', '\2\3', $entry['comment']); + $entry['comment'] = preg_replace('@((\[.+\].*)[\r\n]+(.*\[/.+\]))+@imsU', '\2\3', $entry['comment']); + } serendipity_plugin_api::hook_event('frontend_display', $entry); printf( diff --git a/rss.php b/rss.php index 1bb96a9..842f9a7 100644 --- a/rss.php +++ b/rss.php @@ -29,8 +29,10 @@ if (!isset($_GET['type'])) { } switch ($_GET['type']) { + case 'comments_and_trackbacks': + case 'trackbacks': case 'comments': - $latest_entry = serendipity_fetchComments(isset($_GET['cid']) ? $_GET['cid'] : null, 1, 'desc'); + $latest_entry = serendipity_fetchComments(isset($_GET['cid']) ? $_GET['cid'] : null, 1, 'desc', false, $_GET['type']); break; case 'content': default: @@ -76,8 +78,10 @@ if (isset($modified_since) && } switch ($_GET['type']) { +case 'comments_and_trackbacks': +case 'trackbacks': case 'comments': - $entries = serendipity_fetchComments(isset($_GET['cid']) ? $_GET['cid'] : null, $serendipity['RSSfetchLimit'], 'desc'); + $entries = serendipity_fetchComments(isset($_GET['cid']) ? $_GET['cid'] : null, $serendipity['RSSfetchLimit'], 'desc', $_GET['type']); $description = $title . ' - ' . $description; if (isset($_GET['cid'])) { $title = $title . ' - ' . COMMENTS_FROM . ' "' . $latest_entry[0]['title'] . '"'; diff --git a/templates/default-php/trackbacks.tpl b/templates/default-php/trackbacks.tpl index 4fdbd9e..428dda0 100644 --- a/templates/default-php/trackbacks.tpl +++ b/templates/default-php/trackbacks.tpl @@ -1,5 +1,6 @@ {foreach from=$trackbacks item=trackback} <div class="serendipity_comment"> + <a id="c{$trackback.id}"></a> <div class="serendipity_commentBody"> <a href="{$trackback.url|@strip_tags}" {'blank'|@xhtml_target}><?= $trackback['title'] ?></a><br /> {$trackback.body|@strip_tags|@escape:all} diff --git a/templates/default/feed_0.91.tpl b/templates/default/feed_0.91.tpl index 2fb0d6e..6419204 100644 --- a/templates/default/feed_0.91.tpl +++ b/templates/default/feed_0.91.tpl @@ -11,7 +11,7 @@ {foreach from=$entries item="entry"} <item> <title>{$entry.feed_title}</title> - <link>{$entry.feed_entryLink}</link> + <link>{$entry.feed_entryLink}{if $is_comments}#c{$entry.commentid}{/if}</link> {if !empty($entry.body)} <description> diff --git a/templates/default/feed_1.0.tpl b/templates/default/feed_1.0.tpl index dc5e70b..09267a9 100644 --- a/templates/default/feed_1.0.tpl +++ b/templates/default/feed_1.0.tpl @@ -34,7 +34,7 @@ {foreach from=$entries item="entry"} <item rdf:about="{$entry.feed_guid}"> <title>{$entry.feed_title}</title> - <link>{$entry.feed_entryLink}</link> + <link>{$entry.feed_entryLink}{if $is_comments}#c{$entry.commentid}{/if}</link> {if !empty($entry.body)} <description> {$entry.feed_body|@escape} {$entry.feed_ext|@escape} diff --git a/templates/default/feed_2.0.tpl b/templates/default/feed_2.0.tpl index 6631b87..a0af1bc 100644 --- a/templates/default/feed_2.0.tpl +++ b/templates/default/feed_2.0.tpl @@ -23,7 +23,7 @@ {foreach from=$entries item="entry"} <item> <title>{$entry.feed_title}</title> - <link>{$entry.feed_entryLink}</link> + <link>{$entry.feed_entryLink}{if $is_comments}#c{$entry.commentid}{/if}</link> {foreach from=$entry.categories item="cat"} <category>{$cat.feed_category_name}</category> {/foreach} diff --git a/templates/default/feed_atom0.3.tpl b/templates/default/feed_atom0.3.tpl index 9c873b5..e602d96 100644 --- a/templates/default/feed_atom0.3.tpl +++ b/templates/default/feed_atom0.3.tpl @@ -26,7 +26,7 @@ {foreach from=$entries item="entry"} <entry> - <link href="{$entry.feed_entryLink}" rel="alternate" title="{$entry.feed_title}" type="text/html" /> + <link href="{$entry.feed_entryLink}{if $is_comments}#c{$entry.commentid}{/if}" rel="alternate" title="{$entry.feed_title}" type="text/html" /> <author> <name>{$entry.feed_author}</name> <email>{$entry.feed_email}</email> diff --git a/templates/default/feed_atom1.0.tpl b/templates/default/feed_atom1.0.tpl index 5106bb8..a917ab3 100644 --- a/templates/default/feed_atom1.0.tpl +++ b/templates/default/feed_atom1.0.tpl @@ -24,7 +24,7 @@ {foreach from=$entries item="entry"} <entry> - <link href="{$entry.feed_entryLink}" rel="alternate" title="{$entry.feed_title}" /> + <link href="{$entry.feed_entryLink}{if $is_comments}#c{$entry.commentid}{/if}" rel="alternate" title="{$entry.feed_title}" /> <author> <name>{$entry.feed_author}</name> <email>{$entry.feed_email}</email> diff --git a/templates/default/feed_opml1.0.tpl b/templates/default/feed_opml1.0.tpl index 3d3b2d4..ad877ee 100644 --- a/templates/default/feed_opml1.0.tpl +++ b/templates/default/feed_opml1.0.tpl @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8" ?> - + <opml version="{$metadata.version}" {$namespace_display_dat}> <head> <title>{$metadata.title}</title> @@ -7,10 +7,10 @@ <ownerName>Serendipity {$serendipityVersion} - http://www.s9y.org/</ownerName> </head> <body> - + {foreach from=$entries item="entry"} - <outline text="{$entry.feed_title}" type="url" htmlUrl="{$entry.feed_entryLink}" urlHTTP="{$entry.feed_entryLink}" /> -{/foreach} + <outline text="{$entry.feed_title}" type="url" htmlUrl="{$entry.feed_entryLink}{if $is_comments}#c{$entry.commentid}{/if}" urlHTTP="{$entry.feed_entryLink}{if $is_comments}#c{$entry.commentid}{/if}" /> +{/foreach} -</body> +</body> </opml> \ No newline at end of file diff --git a/templates/default/trackbacks.tpl b/templates/default/trackbacks.tpl index e8a9cae..e8b969d 100644 --- a/templates/default/trackbacks.tpl +++ b/templates/default/trackbacks.tpl @@ -1,5 +1,6 @@ {foreach from=$trackbacks item=trackback} <div class="serendipity_comment"> + <a id="c{$trackback.id}"></a> <div class="serendipity_commentBody"> <a href="{$trackback.url|@strip_tags}" {'blank'|@xhtml_target}>{$trackback.title}</a><br /> {$trackback.body|@strip_tags|@escape:all} diff --git a/templates/kubrick/trackbacks.tpl b/templates/kubrick/trackbacks.tpl index 1585111..85d006c 100644 --- a/templates/kubrick/trackbacks.tpl +++ b/templates/kubrick/trackbacks.tpl @@ -1,5 +1,6 @@ {foreach from=$trackbacks item=trackback name="trackbacks"} <li class="{if $smarty.foreach.comments.iteration is odd}graybox{/if}"> + <a id="c{$trackback.id}"></a> <cite><a href="{$trackback.url|@strip_tags}" {'blank'|@xhtml_target}>{$trackback.title}</a></cite> <p>{$trackback.body|@strip_tags|@escape:all}</p> <div class="commentmetadata">