Sorting an RSS feed of comments

Creating and modifying plugins.
Post Reply
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Sorting an RSS feed of comments

Post by schimanke »

Hi there,

is there a way to sort the RSS feed of comments not by the pubDate but by the consecutive number like they are shown under a blog post? i.e. #1 on top, then #2, then #2.1, then #2.1.1, then #3 and so on.

I don't see any of those numbers in the RSS feed of the comments but I would like to have answers to comments right under the original comment when I process the feed in my iPhone app. Is there a way to use the mentioned numbers to sort the feed? Any other suggestions?

Regards,
Flo
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by garvinhicking »

Hi!

That goes against the intention of RSS feeds, which is always meant to deliver content earliest-first.

Consuming a comment feed is not meant for you to be able to read up the discussion (that's what the normal blogview is for), but to get notified of new comments.

I would suggest to simply go to the original blog article if you have the need to read up the full discussion?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by schimanke »

Yes, I understand that.

The idea was to make the comments available in the iOS app for my blog. I have already managed to let my readers write new comments and also replies to comments through my app. But I think it is a little confusing when the comments are then ordered chronological and not by discussion.

So no way to accomplish my idea?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by garvinhicking »

Hi!

- You could patch the feed*.tpl files and for example write a custom smarty function in your template's config.inc.php to pass the parent id of a comment, and use that to look up serendipity_comments and fetch a thread-list to put inside the comment feed

- You could create a simple PHP script that uses serendipity_fetchComments (or your own SQL code) to inspect serendipity_comments; the SQL structure of this table is fairly easy. With that you can fetch and display the comments to your liking, independently to your RSS feed. You could even put this script into a simple s9y event plugin, and maybe output the result as JSON or RSS instead of HTML.

?

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by schimanke »

Thanks for the ideas.
I think I'll go for the first suggestion and see if I can sort it by comment_id and parent_id.
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by schimanke »

Okay, one last question. Is it somehow possible to put {$comment.trace} from the comments.tpl into feed_2.0.tpl? That would be the perfect sorting value for me. I have managed to get {$entry.parent_id} but failed when I tried to put {$comment.trace} into feed_2.0.tpl.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by garvinhicking »

Hi!

Try a {$comment|@print_r}, then you'll see which variable keys are available. {$comment} is not a valid variable in the .tpl file I think.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by schimanke »

Thanks for that. I did a {$comment|@print_r} and received the following output:

Array
(
[id] => 24365
[entry_id] => 3872
[timestamp] => 1349397332
[ctitle] =>
[email] =>
[url] =>
[ip] => XXXXX
[body] => Ich hätte gern mal ein System mit mehr als 64Gb RAM oO
[type] => NORMAL
[subscribed] => false
[author] => Eric
[title] => Apple veröffentlicht Ergänzungs-Update zu OS X 10.8.2
[entrytimestamp] => 1349383500
[entryid] => 3872
[authorid] => 1
[commentid] => 24365
[parent_id] => 0
[status] => approved
[no_email] => 1
[comment] => Ich hätte gern mal ein System mit mehr als 64Gb RAM oO
[link_delete] => http://www.schimanke.com/...
[pos] => 2
[trace] => 2
[depth] => 0
)

Since I am able to put some of those values into my rss feed like

<parent>{$entry.parent_id}</parent> or
<status>{$entry.status}</status>

I thought that I could also use <trace>{$entry.trace}</trace> to do that with the trace value. But <trace> is always empty while the examples <parent> and <status> always contain the correct value. Any idea why that happens?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by garvinhicking »

Hi!

Sorry, I told you to use {$comment}, but I think {$entry} is the proper one. Also, did you include this in your RSS feed? That's where I meant you to place it.

If the output is from the RSS feed then you should be able to put {$entry.trace} somewhere. Try to put it into the comment body with something like:

Code: Select all

<content:encoded>
...
TRACE: {$entry.trace}
...
</content:encoded>
and then check the RSS feed if that appears. You might be getting the cached version of your RSS feed, so add a rss.php?type=comments&nocache=true to get the "real" one.

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by schimanke »

Ah, okay. I made the mistake to place it in comments.tpl. After putting it into my RSS feed, I do not get the trace variable any more, which is why I don't get an output.

Is it possible to pass the trace variable from comments.tpl over to the feed_2.0.tpl to use it there? If yes, how can I do that?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by garvinhicking »

Hi!

No, those tpl files are completely different and get completely different execution code.

The entries for the RSS feed are created in the include/functions_rss.inc.php file, probably those functions do not iterate the same way like s9y does when the comments are ALL displayed. Note the RSS feed never queries all comments, only the most recent 15. So there is no way to create the trace level without fetching all comments.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by schimanke »

Okay, thanks for your help! I will then try to build something based on the parent ID of a comment.
Post Reply