Simplepi Blogger Comment/Reply Processing
Just in case there're any simplepi users out there desperately searching (as I was) for how to deal with comments from Blogger/Blogspot, here's the code that works for me. I've broken the code into what should be legitimate PHP lines so wrapping doesn't look so dang bad on my website, but some sanity checking after cut-and-paste is probably in order. The actual PHP code is available in the downloads section of my website in functions.php. (Scroll all the way down.)
//I'm not sure why I had to put the namespace link in this tag when all the other get_item_tags calls don't need it. I know it does not work without that namespace link, however. Took quite a while to find where Blogger actually got that xml from.
$temp= $item->get_item_tags( 'http://purl.org/syndication/thread/1.0' ,'total' ); $num_of_replies=$temp[0]['data'];//Blogger puts all kinds of useless crap in their post_id field, so while get_id is a standard method, we have to do a bunch of explode processing to sieve it out. There are probably better ways in PHP, but I learned LISP at a young and impressionable age, and this is the LISP way. Don't throw away the temp array, as we need other elements from it shortly.
$temp=explode('-',$item->get_id()); $postid=$temp[2]; //this one is the post id. $temp=explode('.',$temp[1]); //this one is the blog ID. $blogid=$temp[0]; //Now set the blogid to the value we need.//with those values gathered, we can generate the url to link back to the specific article reply page. We could probably also generate the reply feed url and feed that to simplepie, but why make work for ourselves making our own reply page?
$reply_link=implode(array( 'http://www.blogger.com/comment.g?blogID=' ,(string)$blogid ,'&postID=' ,(string)$postid ));//Now we have all the pieces we need to dynamically generate the html for a Comments: /somenumber/ link that points to the Blogger replies page. It's straightforward PHP from here.
I don't normally post code snippets in my blog - it's not that kind of blog - but I stood on the shoulders of giants to get simplepie working in as little time as it took, and this was the one bit I had to figure out for myself. -JRS
No comments:
Post a Comment