Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2014-08-31 10:07:37

etc
Developer
Registered: 2010-11-11
Posts: 4,660
Website GitHub

Re: Combine comments and articles in a single stream

jdueck wrote #283375:

I had to install and enable XSL on my server.

I should have mentioned it, sorry.

<txp:recent_comments break="" sort=''FIELD(discussid, <txp:variable name="dscids" />) DESC'' limit=''<txp:variable name="dscount" />'' form="comments_form_with_timestamps" />...

…I get empty output. But if I manually enter the values like this:

<txp:recent_comments break="" sort=''FIELD(discussid, 313,311,310,309) DESC'' limit=''4'' form="comments_form_with_timestamps" />...

I get the expected output. It’s as if recent_comments objects to the use of txp:variable within its attribute values.

I guess it’s a quotes affair, try with one single quote. It’s a bit strange that your second example works, however.

Edit: sorry, I goofed, it must be {dscount?} (and not {dscount}) inside the first etc_query tag.

Last edited by etc (2014-08-31 10:37:57)

Offline

#14 2014-08-31 17:04:59

jdueck
Plugin Author
From: Minneapolis, MN
Registered: 2004-02-27
Posts: 147
Website

Re: Combine comments and articles in a single stream

Thanks, I had already found and fixed the dscount? typo when I noticed the value was being surrounded by tags in the output. I think the issue was ultimately Textpattern’s pickiness about how to do quotes for attribute values when nesting tags.

Anyhow, it’s working now! I’m experimenting with typographic treatment at thelocalyarn.com/blogtest (link will expire at some point). My next step will probably be to do the same thing for my RSS feed. (I’ve been talking about the reasons behind doing all this on Twitter.) Many thanks for showing me so far down the correct path, I would never have found the solution on my own.

Offline

#15 2014-08-31 17:08:49

jdueck
Plugin Author
From: Minneapolis, MN
Registered: 2004-02-27
Posts: 147
Website

Re: Combine comments and articles in a single stream

Interesting sidenote, I am really enjoying the flexibility of etc_query. As part of this, I found I could not use the txp:author_email tag within my comments form in this context (it returned empty output). This was needed to slightly alter a few things if the current comment was one of mine, so I used etc_query to roll my own:

<txp:etc_query data='SELECT email FROM `txp_users` WHERE name=
 (SELECT AuthorID FROM `textpattern` WHERE ID=
    (SELECT parentid FROM `txp_discuss` WHERE discussid=<txp:comment_id />
  ))' name="etc_author_email" />

Offline

#16 2014-08-31 17:34:26

etc
Developer
Registered: 2010-11-11
Posts: 4,660
Website GitHub

Re: Combine comments and articles in a single stream

jdueck wrote #283383:

Interesting sidenote, I am really enjoying the flexibility of etc_query. As part of this, I found I could not use the txp:author_email tag within my comments form in this context (it returned empty output).

Glad you enjoy it. I think you can gain one db query, since article ids are populated by <txp:recent_comments />:

<txp:etc_query data='SELECT email FROM `txp_users` WHERE name=
 (SELECT AuthorID FROM `textpattern` WHERE ID=<txp:article_id />)' name="etc_author_email" />

Offline

#17 2014-09-21 19:03:13

jdueck
Plugin Author
From: Minneapolis, MN
Registered: 2004-02-27
Posts: 147
Website

Re: Combine comments and articles in a single stream

I’m implementing this in my RSS feed, and have overcome several small obstacles but am up against one last one related to etc_query that I can’t seem to figure out.

You can see my efforts so far at http://thelocalyarn.com/feed (temporary). You can see that the entry elements are being sorted by the values contained in their child published elements.

My problem is that etc_query appears to be stripping <![CDATA[ from my items when processing the XSLT. My article form for the RSS feed is as follows:

<entry>
    <author>
      <name><txp:author link="0" /></name>
    </author>
    <published><txp:posted format="iso8601" /></published>
    <updated><txp:posted format="iso8601" /></updated>
    <title type="html"><txp:title no_widow="0" /></title>
    <link rel="alternate" type="text/html" href="<txp:permlink />" />
    <id>tag:thelocalyarn.com,<txp:posted format="%Y-%m-%d" />:<txp:etc_query data='SELECT uid FROM `textpattern` WHERE ID=<txp:article_id />'>{uid?}</txp:etc_query></id>
    <content type="html"><![CDATA[
      <txp:body />
    ]]></content>
    <summary type="html"><![CDATA[
      <txp:excerpt />
    ]]></summary>
  </entry>

But as you can see the feed that gets served has the opening CDATA tag stripped out, and the now-useless closing CDATA tag is escaped. After doing some extra-credit homework I thought perhaps I could get it to work by adding cdata-section-elements (or output-cdata-elements) to the XSLT:

<txp:etc_query
	data='<body>
	<txp:if_variable name="artids" value=""><txp:else />
	<txp:article_custom id=''<txp:variable name="artids" />'' form="rss_article" />
	</txp:if_variable>
	<txp:if_variable name="dscids" value=""><txp:else />
		<txp:recent_comments break="" sort=''FIELD(discussid, <txp:variable name="dscids" />) DESC'' limit=''<txp:variable name="dscount" />'' form="rss_comment" />
	</txp:if_variable>
	</body>'>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" cdata-section-elements="content summary" />
<xsl:template match="body">
	<xsl:for-each select="entry">
		<xsl:sort select="published" order="descending" />
		<xsl:copy-of select="." />
	</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
</txp:etc_query>

…but this has no effect. Is there a way to get etc_query to leave my cdata alone? (I have verified that it’s etc_query by manually generating the same output using txp:article_custom.)

PS. it is also apparently changing <link href="..." /> to <link href="..."> (note lack of trailing slash) but it doesn’t appear that this will affect the feed’s validation.

Offline

#18 2014-09-21 20:34:54

etc
Developer
Registered: 2010-11-11
Posts: 4,660
Website GitHub

Re: Combine comments and articles in a single stream

jdueck wrote #283996:

Is there a way to get etc_query to leave my cdata alone?

Have you tried to call etc_query with markup="xml" attribute?

Offline

#19 2014-09-21 23:50:36

jdueck
Plugin Author
From: Minneapolis, MN
Registered: 2004-02-27
Posts: 147
Website

Re: Combine comments and articles in a single stream

Ah, that must be it, thanks. Although now instead of passing the <![CDATA[ through unmodified, it actually strips out the cdata tags and escapes all the HTML inside the element, which is another way of getting there (‘there’ meaning valid XML).

Inspired by your suggestion I also changed xsl:output to method="xml" which fixed the link tag markup that actually was causing me all kinds of other problems I didn’t realize.

Last edited by jdueck (2014-09-21 23:51:25)

Offline

#20 2014-09-22 07:18:28

etc
Developer
Registered: 2010-11-11
Posts: 4,660
Website GitHub

Re: Combine comments and articles in a single stream

I haven’t played much with xsl, but everything seems to work fine with cdata-section-elements="content summary" (thanks for info): test. Might it be something else that intervenes before the feed is served?

Offline

#21 2014-09-23 17:56:50

jdueck
Plugin Author
From: Minneapolis, MN
Registered: 2004-02-27
Posts: 147
Website

Re: Combine comments and articles in a single stream

etc wrote #284018:

I haven’t played much with xsl, but everything seems to work fine with cdata-section-elements="content summary" (thanks for info): test. Might it be something else that intervenes before the feed is served?

Nope that actually does work. I had removed cdata-section-elements while debugging; putting it back in did the trick, in combination with the other changes.

Offline

Board footer

Powered by FluxBB