Hey!
For our blog we want to provide RSSs feed for our articles’ comments.
For this purpose I created a resource with content type set to "RSS" which calls QuipRSS. This resource is requested via
http://host/blog/comments-feed.rss?article=xy where ’article’ specifies the blog article of which the latest comments should be listed in the feed:
[[!QuipRss?
&type=`thread`
&thread=`blog-post-[[!getReqParam? &name=`article`]]`
&containerTpl=`rssFeed.article`
&pagetitle=`[[!getResourceField? &id=`[[!getReqParam? &name=`article`]]` &field=`pagetitle`]]`
]]
Note: Because the article’s pagetitle is only set by QuipRSS when there are already comments available, I added the &pagetitle parameter (see
https://github.com/splittingred/Quip/pull/43).
This works fine but the
http://host/blog/comments-feed.rss?article=xy are not really nice and friendly (for SEO, too).
I thought of URLs like this:
http://host/blog/article1.html/comments.rss, http://host/blog/article2.html/comments.rss, ...
http://host/blog/articleXY.html/comments.rss and created a plugin (QuipRSSFurl) which does this job:
The original comments-feed.rss resource (
http://host/blog/comments-feed.rss) is still used to create the RSS files. Additionally the new QuipRSSFurl plugin listens to OnPageNotFound events, checks whether the requested URL ends with the /comments.rss suffix (it offeres multi language support for the suffix), sets the ’article’ GET param and forwards the request to the comments-feed.rss resource:
/**
* QuipRSSFurl
*
* Author Jakob Class <[email protected]>
*
* Plugin which fetches 404 errors to provide RSS Feeds when a blog article is
* requested with a special suffix (/[quip.comments].rss).
*
* @package quip
*/
if ($modx->event->name != 'OnPageNotFound') return;
$rssResourceId = $modx->getOption('quip.comments_rss_resource_id','',null,'');
if (empty($rssResourceId)) return;
/* check if requested resource ends with correct suffix */
$modx->getService('lexicon','modLexicon');
$modx->lexicon->load('quip:default');
$suffix = '/'.strtolower($modx->lexicon('quip.comments').'.rss');
$search = $_SERVER['REQUEST_URI'];
$base_url = $modx->getOption('base_url');
if ($base_url != '/') {
$search = str_replace($base_url,'',$search);
}
$search = strtolower(trim($search, '/'));
if(substr( $search, -strlen($suffix) ) != $suffix) return;
/* check for orginal resource (without suffix) */
$search = str_replace($suffix,'',$search);
$resourceId = $modx->aliasMap[$search];
if (empty($resourceId)) return;
/* set parameters for QuipRSS resource */
$_GET['article'] = $resourceId;
/* forward */
$modx->sendForward($rssResourceId);
return;
To make this plugin work you have to specify the id of the comments-feed.rss resource (
http://host/blog/comments-feed.rss) via the system setting ’quip.comments_rss_resource_id’.
@Shaun: If you like me to pull this code to your GitHub repository, just tell me!
Cheers,
Jakob