Textpattern CMS support forum

You are not logged in. Register | Login | Help

#71 2019-10-27 13:26:12

etc
Developer
Registered: 2010-11-11
Posts: 3,356
Website

Re: [plugin] [ORPHAN] ajw_comments_feed

jakob wrote #319847:

<txp:evaluate query='<txp:page_url type="feed" /> = "rss"'>...

(BTW: Have I got the syntax of txp:evaluate correct or does page_url also have to be in quotes? Or is that done better with variable / if_variable?)

You have to enclose it in quotes, either directly or via escape="quote" attribute.

And then in the form article_comment_feed, put the entire code block above with the modifications, starting with:

<txp:header value="text_xml" />...

Will that use txp:header work at all? i.e. can processing of the urlvar begin before the page header is set?

It would work if the parser had a chance to get there. But, afair, feed requests are handled by atom.php / rss.php scripts. Not sure they parse any page by default, you have to use a callback.

Offline

#72 2019-10-27 21:19:44

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,553
Website

Re: [plugin] [ORPHAN] ajw_comments_feed

etc wrote #319851:

You have to enclose it in quotes, either directly or via escape="quote" attribute.

It would work if the parser had a chance to get there. But, afair, feed requests are handled by atom.php / rss.php scripts. Not sure they parse any page by default, you have to use a callback.

Had to read that a few times but I think I have it: I made an unfortunate choice by proposing feed as the url parameter when that’s already used by txp itself.

I think I have it working now with a different url parameter as follows:

A misc form called article_comment_feed:

<txp:header value="text_xml" /><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 />?comment-feed=rss" 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>

and then this in my page template:

<txp:evaluate query='<txp:page_url type="comment-feed" escape="quote" /> = "rss"'>
    <txp:output_form form="article_comment_feed" />
<txp:else />
    ... the regular page template ...
</txp:evaluate>

(It seems that both escape="quote" like above or <txp:evaluate query='"<txp:page_url type="comment-feed" />" = "rss"'> both work. I was expecting the latter to cause it to stumble over the double quotes in the double quotes in the single quotes.)

And then in the article form:

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

to link to the feed.

Can that be improved on, especially the evaluate around the page template?


TXP Builders – finely-crafted code, design and txp

Offline

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

etc
Developer
Registered: 2010-11-11
Posts: 3,356
Website

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: 3,553
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: 3,356
Website

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