Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#73 2019-10-28 10:41:24

etc
Developer
Registered: 2010-11-11
Posts: 5,235
Website GitHub

Re: [plugin] [ORPHAN] ajw_comments_feed

jakob wrote #319852:

<txp:header value="text_xml" /><txp:article escape="trim">...

Shouldn’t it be text/xml?

<txp:evaluate query='<txp:page_url type="comment-feed" escape="quote" /> = "rss"'>...

And then in the article form:

<a href="<txp:permlink />?comment-feed=rss">Comment feed for this article</a>...

Why wouldn’t you create a text/xml media type and assign this type to article_comment_feed form? Then you wouldn’t need to include <txp:header /> (since is set by form type), neither evaluate test if your links were

<a href="<txp:permlink />?f=article_comment_feed">Comment feed for this article</a>

Offline

#74 2019-10-28 22:15:01

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,742
Website

Re: [plugin] [ORPHAN] ajw_comments_feed

etc wrote #319853:

Shouldn’t it be text/xml?

Yes, sorry I mistyped that here.

Why wouldn’t you create a text/xml media type and assign this type to article_comment_feed form? Then you wouldn’t need to include <txp:header /> (since is set by form type), neither evaluate test if your links were

<a href="<txp:permlink />?f=article_comment_feed">Comment feed for this article</a>...

Brilliant! I love how you casually drop these small wonders into a thread! That works perfectly. Is this something I overlooked or is that an undocumented feature?

I know about being able to create custom form types after enabling advanced settings and being able to give them a content-type, but I didn’t know about the ?f=form-name url parameter. Perhaps I just missed that when it was announced? Presumably that’s protected from misuse? People can’t start outputting my pages using another form they suspect or know I might have in my setup?

Anyhow, long story short – this works:

1. Set “Advanced options” to “on” in Admin › Preferences › Admin if not already set.
2. Go to Admin › Preferences › Advanced options (as enabled in step 1) and under Custom form template types add the form type:

[feed]
mediatype="text/xml"

3. Go to Presentation › Forms and create a new form with the name comment-feed (or whatever you want to use) and type feed (which after step 2 will now show in the form type dropdown) and paste the following into it:

<txp:article escape="trim">
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
 <generator>http://textpattern.com/</generator>
 <title><txp:site_name /> – <txp:title no_widow="0" /></title>
 <description><txp:title no_widow="0" /> - comments</description>
 <link><txp:permlink /></link>
 <atom:link href="<txp:permlink />?f=comment-feed" rel="self" type="application/rss+xml" />
 <pubDate><txp:comments break="" sort="posted desc" limit="1" escape="trim"><txp:comment_time format="rfc822" /></txp:comments></pubDate>

 <txp:comments break="item">
     <title>Comment on <txp:title no_widow="0" /> by <txp:comment_name link="0" /></title>
     <link><txp:comment_permlink /></link>
     <guid><txp:comment_permlink /></guid>
     <pubDate><txp:comment_time format="rfc822" /></pubDate>
     <description><![CDATA[<txp:comment_message />]]></description>
     <content:encoded><![CDATA[<txp:comment_message />]]></content:encoded>
     <dc:creator><txp:comment_name /></dc:creator>
 </txp:comments>

</channel>
</rss>
</txp:article>

(If you use a form with another name, be sure to change the href of atom:link to match)

4. In your comments_display form add the line:

<a href="<txp:permlink />?f=comment-feed">Comment feed for this article</a>

That’s it!

Altogether much cleaner than my version in the previous thread and doesn’t require any page template adjustments or detection mechanisms.


TXP Builders – finely-crafted code, design and txp

Offline

#75 2019-10-29 10:52:24

etc
Developer
Registered: 2010-11-11
Posts: 5,235
Website GitHub

Re: [plugin] [ORPHAN] ajw_comments_feed

jakob wrote #319857:

I know about being able to create custom form types after enabling advanced settings and being able to give them a content-type, but I didn’t know about the ?f=form-name url parameter. Perhaps I just missed that when it was announced? Presumably that’s protected from misuse? People can’t start outputting my pages using another form they suspect or know I might have in my setup?

These ?f links are not meant to be constructed directly, but via <txp:output_form /> tag. The construction is not yet documented nor established, sorry. But for a teaser, in individual article context you can get it with

<txp:output_form format form="my-form" context="id" />

And yes, people can output your pages using any media-typed form, but that’s what they are designed for. “Usual” forms stay private.

Offline

Board footer

Powered by FluxBB