Need help exporting comments with SimplePie

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
MarkMushakian
Regular
Posts: 16
Joined: Sun Apr 06, 2008 6:19 am
Location: San Clemente, CA, USA
Contact:

Need help exporting comments with SimplePie

Post by MarkMushakian »

As you just read, I'm in need of some help with SimplePie. I know this is an issue I should bring up that forum and I have, though the response times are a little slower than they seem here.

I really love Serendipity...it's really something I've been looking for since I started my website. Part of this is the ability to regularly use a blog system to update my blogs (which I was doing manually for each individual page, before)....and I have discovered that I can use SimplePie to export the RSS feed to the main index page of my site - exactly like I want. The problem I am having is in importing the comments to my index. This may not be a situation you here can help me with, and I understand that, but I am not sure how I can dynamically access the comments for the current post. Any help or suggestions will indeed be very appreciated :D

Thank you!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Need help exporting comments with SimplePie

Post by garvinhicking »

Hi!

The s9y comment feeds can be found like this:

rss.php?type=comments&cid=[ENTRYID]

If you omit the Entryid, then the most recent entries will be fetched.

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/
MarkMushakian
Regular
Posts: 16
Joined: Sun Apr 06, 2008 6:19 am
Location: San Clemente, CA, USA
Contact:

Re: Need help exporting comments with SimplePie

Post by MarkMushakian »

Hi Garvin...

Thanks for the response! It threw me off seeing what time you posted, but then I realized you're in Germany - and I'm in America. :lol:

I tried the feed access you suggested, but it's not quite what I was looking for. Again, this may be an issue I'll have to handle with SimplePie alone, but what I'd like to do is give the viewer the ability to leave comments for whichever blog is currently showing on my index page, by using a popup window like I have on my blog. Here is a sample of the Comment html code I'd like to use....it's the same as what is on my blog:

Code: Select all

<a href="--------------" onclick="window.open(this.href, 'comments', 'width=480,height=480,scrollbars=yes'); return false;">Comments (#)</a>

Where, the href would be a php code that leads only to the current feed's comments, and the "Comments (#)" could be dynamically updated with another code.

Again, regardless of the outcome, thank you for your help! :D


PS. I like your photography, Garvin :)
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Need help exporting comments with SimplePie

Post by garvinhicking »

Hi!

Do you maybe mean a URL like this:

http://blog.s9y.org/comment.php?serendi ... ]=comments

?
PS. I like your photography, Garvin :)
Thanks a lot! This really means something to me :)

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/
MarkMushakian
Regular
Posts: 16
Joined: Sun Apr 06, 2008 6:19 am
Location: San Clemente, CA, USA
Contact:

Re: Need help exporting comments with SimplePie

Post by MarkMushakian »

garvinhicking wrote:
Do you maybe mean a URL like this:

http://blog.s9y.org/comment.php?serendi ... ]=comments
Yeah, that's just what I'm looking for - I just don't know how to set the link to be dynamic, so that it will point to the comments of the latest post feed every time I post a new blog entry. Haha, I'm so close I can taste it. I suppose I could just manually change the post number each time, but that sort of defeats my purpose. :)
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Need help exporting comments with SimplePie

Post by garvinhicking »

Hi!

For each item of the RSS 2.0 feed you should see a wfw:commentRss link, there you should be able to use PHP and preg_match() code to extract the entry-ID?

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/
MarkMushakian
Regular
Posts: 16
Joined: Sun Apr 06, 2008 6:19 am
Location: San Clemente, CA, USA
Contact:

Re: Need help exporting comments with SimplePie

Post by MarkMushakian »

garvinhicking wrote: For each item of the RSS 2.0 feed you should see a wfw:commentRss link, there you should be able to use PHP and preg_match() code to extract the entry-ID?
I have done research and studied how preg_match() works, but for the past couple of hours I have been thinking of how to implement it all, and I can't find the solution. haha, I tend to do this - get in over my head with code I don't understand, so I apologize.

I have found the wfw:comment link and understand it, and see how it all is necessary, I just can't piece it together. Sorry, again...I know this isn't PHP 101 :oops:
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Need help exporting comments with SimplePie

Post by garvinhicking »

Hi!

Like if you have a variable that holds the wfw:comment thing:

Code: Select all

$link = '<wfw:comment>http://blog.s9y.org/wfwcomment.php?cid=192</wfw:comment>';
you could use a preg-code like this:

Code: Select all

$link = '<wfw:comment>http://blog.s9y.org/wfwcomment.php?cid=192</wfw:comment>';

if (preg_match('@cid=([0-9]+)@i', $link, $matches)) {
  echo "The ID is: {$matches[1]}";
}
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/
MarkMushakian
Regular
Posts: 16
Joined: Sun Apr 06, 2008 6:19 am
Location: San Clemente, CA, USA
Contact:

Post by MarkMushakian »

Hello once again :)
Ok... I understand how that goes together now, thank you. However, I can not get it to find the cid on it's own. If I include the cid number, that is all it will export - however I haven't been able to output anything by any other means. I have included the entire code that I am using, root directory for the simplepie.inc omitted:

Code: Select all

<?php
require_once('********/simplepie.inc');
 
$feed = new SimplePie('http://www.markmushakian.com/Blog/index.php?/feeds/categories/1-Blog.rss');
$feed->init();
$feed->handle_content_type();
 
?>
<?php foreach ($feed->get_items() as $item): ?>
 
	<div class="bloghead"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></div>
	<div class="bloginfo"><?php echo $item->get_date('j F Y'); ?></div>
<br />
	<?php echo $item->get_description(); ?>
<br />
	- Mark.
<br />



<?php

$link = '<wfw:comment>http://www.markmushakian.com/Blog/wfwcomment.php?cid=192</wfw:comment>';

if (preg_match('@cid=([0-9]+)@i', $link, $matches)) {
  echo "{$matches[1]}";
} 
else
{ 
print "This STILL isn't working, Mark.";
}
?>


<?php endforeach; ?>		
Again, I appreciate the help. I can't wait to have this working - but I also really look forward to understanding how it does, as well.

Also, if it helps, here is the test page I am using while working on this feed issue. http://www.markmushakian.com/testBlog.php
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

No PRoblem, try this:

Code: Select all

<?php
require_once('simplepie.inc');
 
$feed = new SimplePie('http://www.markmushakian.com/Blog/index.php?/feeds/categories/1-Blog.rss');
$feed->init();
$feed->handle_content_type();
 
?>
<?php foreach ($feed->get_items() as $item): ?>
 
   <div class="bloghead"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></div>
   <div class="bloginfo"><?php echo $item->get_date('j F Y'); ?></div>
<br />
   <?php echo $item->get_description(); ?>
<br />
   - Mark.
<br />

<?php
$link = $item->data['child']['http://wellformedweb.org/CommentAPI/']['comment'][0]['data'];

if (preg_match('@cid=([0-9]+)@i', $link, $matches)) {
  echo '<a href="http://www.markmushakian.com/Blog/comment.php?serendipity[entry_id]=' . $matches[1] . '&serendipity[type]=comments">Comment!</a>';
}
?>


<?php endforeach; ?>  
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/
MarkMushakian
Regular
Posts: 16
Joined: Sun Apr 06, 2008 6:19 am
Location: San Clemente, CA, USA
Contact:

It worked!

Post by MarkMushakian »

Thank you, very much for your help, it's working perfectly! I really appreciate it when someone patiently finds the time to help someone else - it's a nice, rare treat to find in the world. :D

Serendipity has been a really nice setup so far, so thanks for that too, while I'm at it.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: It worked!

Post by garvinhicking »

Hi!

You're welcome! Hope you have fun with s9y :)

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/
Post Reply