1 of 2
1
RSS comment include problem
Posted: 06 February 2006 03:17 PM   [ Ignore ]  
Grad Student
Rank
Total Posts:  56
Joined  05-15-2004

I’m trying to add a php include to my RSS 2.0 feed such that the feed includes comments along with the entries.  Following the suggestions on the wiki (as well as in various forum threads), I’ve added code into my rss template such that it now looks like this:

{assign_variable:master_weblog_name="weblog1"}
{exp
:rss:feed weblog="{master_weblog_name}"}
<?xml version
="1.0" encoding="{encoding}"?>
<rss version="2.0"
    
xmlns:dc="http://purl.org/dc/elements/1.1/"
    
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    
xmlns:admin="http://webns.net/mvcb/"
    
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    
xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <
channel>
    <
title>{exp:xml_encode}{weblog_name}{/exp:xml_encode}</title>
    <
link>{weblog_url}</link>
    <
description>{weblog_description}</description>
    <
dc:language>{weblog_language}</dc:language>
    <
dc:creator>{email}</dc:creator>
    <
dc:rights>Copyright {gmt_date format="%Y"}</dc:rights>
    <
dc:date>{gmt_date format="%Y-%m-%dT%H:%i:%s%Q"}</dc:date>
    <
admin:generatorAgent rdf:resource="http://www.pmachine.com/" />
{exp:weblog:entries weblog="{master_weblog_name}" limit="10" rdf="off" dynamic_start="on" disable="member_data|trackbacks"}
    
<item>
      <
title>{exp:xml_encode}{title}{/exp:xml_encode}</title>
      <
link>{exp:xml_encode}{title_permalink=weblog/index}{/exp:xml_encode}</link>
      <
description>{exp:xml_encode}{summary}{/exp:xml_encode}</description>
      <
dc:subject>{exp:xml_encode}{categories backspace="1"}{category_name}, {/categories}{/exp:xml_encode}</dc:subject>
      <
content:encoded><![CDATA[{body}{extended} <?php include("{comment_path=weblog/incl_comments}"); ?>]]></content:encoded>
      <
dc:date>{gmt_entry_date format="%Y-%m-%dT%H:%i:%s%Q"}</dc:date>
    </
item>
{/exp:weblog:entries}
        
</channel>
</
rss>
{/exp:rss:feed}

In template preferences, I’ve turned “allow php” on, and set it to parse at output.  And the included template, incl_comments, looks like this:

<div><strong>{exp:weblog:entries limit="1"}
{if comment_total
== 0}0 Comments{/if}
{if comment_total
== 1}1 Comment{/if}
{if comment_total
> 1}{comment_total} Comments{/if}
{if trackback_total
== 0} and 0 Trackbacks{/if}
{if trackback_total
== 1} and 1 Trackback{/if}
{if trackback_total
> 1} and {trackback_total} Trackbacks{/if}
{
/exp:weblog:entries}</strong></div>
<
hr />{exp:comment:entries}
{if comments}
<em>{comment}</em>
<
div>Comment by {name} on on {comment_date format='%m.%d.%y'} at {comment_date format='%h.%i %A'}</div>
{/if}
{if trackbacks}
<em><strong>{title}</strong>{content}</em>
<
div>Trackback from: <a href="{trackback_url}">{weblog_name}</a> ({trackback_ip})
on {trackback_date format='%m.%d.%y, %h.%i %A'}</div>
{/if}{/exp:comment:entries}

Rendering the template gives me repeated iterations of the following error, where the comments ought to be:

<b>Warning</b>:  Unknown(): URL file-access is disabled in the server configuration in <b>(file path snipped)/core/core.functions.php(570) : eval()'d code</b> on line <b>35</b>

I’ve attempted to work my way through the configuration settings in the admin panel, looking for something that would affect this, but I’m coming up dry.  Any suggestions that you might have would be greatly appreciated!

[Updated to add:  that’s supposed to be “eval()‘d” in the last code snippet above; I can’t make the open paren appear properly!]

Profile
 
 
Posted: 06 February 2006 06:37 PM   [ Ignore ]   [ # 1 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7534
Joined  08-05-2002

The {comment_path} variable is going to return a URL (with http:// on the front).  Many servers will not allow you to include a file through a URL because it leaves open the way for the including of naughty files onto the server.  This is a setting your host has setup.  Why do you not use an embed?

 Signature 
Profile
 
 
Posted: 06 February 2006 07:25 PM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  56
Joined  05-15-2004

This is a VERY good question.  I can use an embed?  Just like in a regular web page template?  That’s mildly embarrassing.  I knew I was overlooking SOMETHING obvious.  red face

Profile
 
 
Posted: 06 February 2006 07:28 PM   [ Ignore ]   [ # 3 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7534
Joined  08-05-2002

Well, I take it you are simply using that page to display the comments for an entry or something like that?  The only problem is that the {embed} tag cannot send variables (like the entry_id) to the template.  However, the Snippets plugin can do stuff like this, I believe.

 Signature 
Profile
 
 
Posted: 06 February 2006 08:22 PM   [ Ignore ]   [ # 4 ]  
Grad Student
Rank
Total Posts:  56
Joined  05-15-2004

I think I follow this.  It’s going to take some tinkering, though, and my post-Bikram brain is not cooperating.  I’ll try it in the morning—thanks for the help!

Profile
 
 
Posted: 07 February 2006 06:25 AM   [ Ignore ]   [ # 5 ]  
Grad Student
Rank
Total Posts:  56
Joined  05-15-2004

Okay, here’s where I’ve gotten.  I’ve edited the RSS template so that it now contains this line:

<content:encoded><![CDATA[{body}{extended}{exp:snippets template="weblog/incl_comments"}{entry_id_var}{entry_id}{/entry_id_var}{/exp:snippets}]]></content:encoded>

And the incl_comments template looks like this:

<div><strong>{exp:weblog:entries entry_id="%entry_id_var%"}
{if comment_total
== 0}0 Comments{/if}
{if comment_total
== 1}1 Comment{/if}
{if comment_total
> 1}{comment_total} Comments{/if}
{if trackback_total
== 0} and 0 Trackbacks{/if}
{if trackback_total
== 1} and 1 Trackback{/if}
{if trackback_total
> 1} and {trackback_total} Trackbacks{/if}
{
/exp:weblog:entries}</strong></div>
<
hr />{exp:comment:entries}
{if comments}
<em>{comment}</em>
<
div>Posted by {name} on {comment_date format='%m.%d.%y'} at {comment_date format='%h.%i %A'}</div>
{/if}
{if trackbacks}
<em><strong>{title}</strong>{content}</em>
<
div>Tracked on: <a href="{trackback_url}">{weblog_name}</a> ({trackback_ip})
on {trackback_date format='%m.%d.%y, %h.%i %A'}</div>
{/if}{/exp:comment:entries}

By passing the %entry_id_var% to the snippet, I’m now able to get each entry to appear with an accurate count of the number of comments and/or trackbacks associated with it.  But I can’t yet figure out how to pass a similar variable to the {exp:comment:entries} tag.  Since it doesn’t take entry_id as a parameter, but rather takes its cues about what entry’s comments it should be displaying from the entry_id_path contained in its URL, I’m a little at a loss.  Undoubtedly there’s something totally obvious here as well, a way to invoke the entry_id_path that will cause {exp:comments:entries} to localize, but I’m not seeing it yet…

Profile
 
 
Posted: 07 February 2006 10:43 AM   [ Ignore ]   [ # 6 ]  
Grad Student
Rank
Total Posts:  56
Joined  05-15-2004

Okay, I’ve been bashing my head up against this, and it’s simply not going to work.  Because the call to incl_comments is being issued from inside a {exp:weblog:entries} tag, I don’t have access to the comment variables needed to send to the snippet in order to get it to render comments.

So, new approach, backtracking to the original approach, drawing from the wiki:  I’ve checked with my hosting provider, and while allow_url_fopen is disabled due to security concerns, I can theoretically use a server-side include to call the included template.  Their support materials say that if I want to make this (disabled) php call:

<?php include(“http://example.com/includes/example_include.php”); ?>

I can instead issue this:

<?php include($_SERVER[‘DOCUMENT_ROOT’].”/includes/example_include.php”); ?>

Fine & dandy.  Except that I’m trying to use an EE variable to make the call, and I can’t come up with a way to make an EE-type URL (like http://www.example.com/index.php?/weblog/incl_comments) resolve using the local file structure.

This is getting a teeny bit frustrating.  Is there no other way to build an RSS feed that includes comments with entries?

Profile
 
 
Posted: 07 February 2006 10:54 AM   [ Ignore ]   [ # 7 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32921
Joined  05-14-2004

I’m so bad at server stuff - what does that document_root resolve to?  From there I can help you make it work, I think.  I mean, what is the exact output of that by itself?

And no, showing comments with entries on multi-entry pages isn’t supported by default, that’s why the wiki article exists.

 Signature 
Profile
MSG
 
 
Posted: 07 February 2006 10:59 AM   [ Ignore ]   [ # 8 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7534
Joined  08-05-2002

What your host is suggesting will not work as it will be including a file while you need a processed URL.  Give me a few moments and I will just figure it out and post what I find.

 Signature 
Profile
 
 
Posted: 07 February 2006 11:29 AM   [ Ignore ]   [ # 9 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7534
Joined  08-05-2002

Unfortunately, the Snippets plugin has PHP parsed on input before it exchanges the variables it sets, so that idea is a bust.  So, we’re going to have to use an all PHP solution since your host does not let you load remote files.  You will have to modify the template names and the master weblog name in these two examples, but they seem to work for me:

First Template (PHP On Input)

{assign_variable:master_weblog_name="default_site"}
{exp
:rss:feed weblog="{master_weblog_name}"}
<?xml version
="1.0" encoding="{encoding}"?>
<rss version="2.0"
    
xmlns:dc="http://purl.org/dc/elements/1.1/"
    
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    
xmlns:admin="http://webns.net/mvcb/"
    
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    
xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <
channel>
    <
title>{exp:xml_encode}{weblog_name}{/exp:xml_encode}</title>
    <
link>{weblog_url}</link>
    <
description>{weblog_description}</description>
    <
dc:language>{weblog_language}</dc:language>
    <
dc:creator>{email}</dc:creator>
    <
dc:rights>Copyright {gmt_date format="%Y"}</dc:rights>
    <
dc:date>{gmt_date format="%Y-%m-%dT%H:%i:%s%Q"}</dc:date>
    <
admin:generatorAgent rdf:resource="http://www.pmachine.com/" />
{exp:weblog:entries weblog="{master_weblog_name}" limit="10" rdf="off" dynamic_start="on" disable="member_data|trackbacks"}
    
<item>
      <
title>{exp:xml_encode}{title}{/exp:xml_encode}</title>
      <
link>{exp:xml_encode}{title_permalink=weblog/index}{/exp:xml_encode}</link>
      <
description>{exp:xml_encode}{summary}{/exp:xml_encode}</description>
      <
dc:subject>{exp:xml_encode}{categories backspace="1"}{category_name}, {/categories}{/exp:xml_encode}</dc:subject>
      <
content:encoded><![CDATA[{body}{extended}
<?php

$url
= "{comment_path=site/anything2}";

// -------------------------------------
//  Fetch Page Data
// -------------------------------------
$data = '';
$target = parse_url($url);
$path  = ( ! isset($target['query'])) ? $target['path'] : $target['path'].'?'.$target['query'];

$fp = @fsockopen($target['host'], 80, $errno, $errstr, 15);

if (
is_resource($fp))
{
fputs
($fp,"GET " . $path . " HTTP/1.0\r\n" );
fputs ($fp,"Host: " . $target['host'] . "\r\n" );
fputs ($fp, "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1)\r\n");
fputs ($fp, "Connection: close\r\n\r\n");

$getting_headers = true;

while ( !
feof($fp))
{
$line
= fgets($fp, 4096);

if (
$getting_headers == false)
{
$data
.= $line;
}
elseif (trim($line) == '')
{
$getting_headers
= false;
}
}

@fclose($fp);   

echo
$data;

}

?>

]]
></content:encoded>
      <
dc:date>{gmt_entry_date format="%Y-%m-%dT%H:%i:%s%Q"}</dc:date>
    </
item>
{/exp:weblog:entries}
        
</channel>
</
rss>
{/exp:rss:feed}

Second Template (no PHP processing, no snippets code)

<div><strong>

{exp:weblog:entries}
{if comment_total
== 0}0 Comments{/if}
{if comment_total
== 1}1 Comment{/if}
{if comment_total
> 1}{comment_total} Comments{/if}
{if trackback_total
== 0} and 0 Trackbacks{/if}
{if trackback_total
== 1} and 1 Trackback{/if}
{if trackback_total
> 1} and {trackback_total} Trackbacks{/if}
{
/exp:weblog:entries}</strong></div>
<
hr />

{exp:comment:entries}
{if comments}
<em>{comment}</em>
<
div>Posted by {name} on {comment_date format='%m.%d.%y'} at {comment_date format='%h.%i %A'}</div>
{/if}

{if trackbacks}
<em><strong>{title}</strong>{content}</em>
<
div>Tracked on: <a href="{trackback_url}">{weblog_name}</a> ({trackback_ip})
on {trackback_date format='%m.%d.%y, %h.%i %A'}</div>
{/if}
{
/exp:comment:entries}

 Signature 
Profile
 
 
Posted: 07 February 2006 05:45 PM   [ Ignore ]   [ # 10 ]  
Grad Student
Rank
Total Posts:  56
Joined  05-15-2004

Paul, *thank you* for all the effort you’ve put into this.  Alas, I don’t have great news to report.  I copied the templates you provided, changed the variables that needed changing, made sure preferences were properly set, and on load, I got this error:

XML Parsing Error: junk after document element
Location
: http://www.plannedobsolescence.net/index.php?/weblog/newrss/
Line Number 2, Column 1:<b>Parse error</b>:  parse error, unexpected T_IF in <b>[directory path snipped]/eesys/core/core.functions.php(570) : eval()'d code</b> on line <b>39</b><br />
^

Any ideas?  I’ll absolutely understand if you’re out of them at this point.  And thanks again for all the help.

Profile
 
 
Posted: 07 February 2006 05:52 PM   [ Ignore ]   [ # 11 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7534
Joined  08-05-2002

Hm, seems that one of the conditionals is causing a problem.  You made sure to turn off PHP parsing for the second template?  And you are using the current build of EE?

 Signature 
Profile
 
 
Posted: 07 February 2006 05:56 PM   [ Ignore ]   [ # 12 ]  
Grad Student
Rank
Total Posts:  56
Joined  05-15-2004

Yeah, PHP is off for the included template—but whoops.  I’m apparently running 1.4.0, not 1.4.1.  I’ll upgrade and see if that does it.

Profile
 
 
Posted: 07 February 2006 06:09 PM   [ Ignore ]   [ # 13 ]  
Grad Student
Rank
Total Posts:  56
Joined  05-15-2004

Alas, that didn’t work either…

Profile
 
 
Posted: 07 February 2006 06:11 PM   [ Ignore ]   [ # 14 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7534
Joined  08-05-2002

Hm, it seems to work for me, so I would have to take a look at your site to see what might be causing the problem.

 Signature 
Profile
 
 
Posted: 07 February 2006 06:15 PM   [ Ignore ]   [ # 15 ]  
Grad Student
Rank
Total Posts:  56
Joined  05-15-2004

It’s here.  My fear is that this is going to turn out again to be a peculiarity of my hosting provider, but if you discover differently, I’ll be thrilled!

Profile
 
 
Posted: 07 February 2006 06:16 PM   [ Ignore ]   [ # 16 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7534
Joined  08-05-2002

Actually, I would need to see the templates, which would mean I would require CP access.

 Signature 
Profile
 
 
Posted: 07 February 2006 06:19 PM   [ Ignore ]   [ # 17 ]  
Grad Student
Rank
Total Posts:  56
Joined  05-15-2004

D’oh!  Sent via PM.

Profile
 
 
Posted: 07 February 2006 08:48 PM   [ Ignore ]   [ # 18 ]  
Grad Student
Rank
Total Posts:  56
Joined  05-15-2004

Final update, to close the thread:  Paul’s templates were perfect; something went wrong when I copied them over.  All’s totally functional now.

Profile
 
 
   
1 of 2
1
 
‹‹ Dynamic Variables      Change templates ››
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65075 Total Logged-in Users: 25
Total Topics: 82208 Total Anonymous Users: 14
Total Replies: 441827 Total Guests: 163
Total Posts: 524035    
Members ( View Memberlist )
Newest Members:  TomsBmackskithbtggAdminempoleongwishPasha MahardikarmarkdurandomcatClutch Bearings