Sorting an RSS feed of comments

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

Sorting an RSS feed of comments

Post by schimanke » Tue Oct 02, 2012 11:53 am

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

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by garvinhicking » Tue Oct 02, 2012 1:27 pm

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 5:38 pm
Location: Hameln, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by schimanke » Tue Oct 02, 2012 1:33 pm

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?

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by garvinhicking » Tue Oct 02, 2012 3:17 pm

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 5:38 pm
Location: Hameln, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by schimanke » Thu Oct 04, 2012 3:00 pm

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 5:38 pm
Location: Hameln, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by schimanke » Thu Oct 04, 2012 3:31 pm

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.

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by garvinhicking » Fri Oct 05, 2012 8:38 am

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 5:38 pm
Location: Hameln, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by schimanke » Fri Oct 05, 2012 9:55 am

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?

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by garvinhicking » Fri Oct 05, 2012 10:05 am

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 5:38 pm
Location: Hameln, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by schimanke » Fri Oct 05, 2012 10:36 am

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?

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by garvinhicking » Fri Oct 05, 2012 11:17 am

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 5:38 pm
Location: Hameln, Germany
Contact:

Re: Sorting an RSS feed of comments

Post by schimanke » Fri Oct 05, 2012 11:20 am

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

Post Reply