Recent Topics

1 Sep 23, 2011 21:42    

Hello,

in my posts I use some jquerry java scripts. Since I did that the RSS2 feed does not work anymore.

I already found out that in the xml feed the problem is that there are javascript tags. I added noscript tags to be shown when javascript is not allowed.

A analysis of the feed: http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.photo-vinc.com%2FPHP%2Fblog%2Findex.php%3Ftempskin%3D_rss2#l53

the feed itself: http://www.photo-vinc.com/PHP/blog/index.php?tempskin=_rss2

how do I manage to let b2evolution only show the noscript content in the feed?

Best Regards,
Vincent

http://www.photo-vinc.com/

2 Sep 23, 2011 21:51

Welcome to the forums!

b2evolution must escape "<![CDATA[" and "]]>" tags in your post. It looks like a bug, let me check...

3 Sep 23, 2011 21:58

sam2kb,

Thanks for your quick reply. I'm using b2evolution 4.0.5 and my typical posts look like this:

<p>some text.</p>

<script type="text/javascript">// <![CDATA[

var cb20110916 = new blogContentGen("20110916");
cb20110916.setThumb("_mg_4779_500x500.jpg", "Durrësi - Albania - September 2011");
cb20110916.addImage("_mg_4745.jpg", "Durrësi - Albania - September 2011");
cb20110916.showContent();

// ]]></script>
<noscript>
<img src="http://www.photo-vinc.com/PHP/blog/media/blogs/all/20110916/_mg_4779_500x500.jpg" />
</noscript>

<p>Some text </p>

4 Sep 24, 2011 00:02

Fixed in CVS

You can fix it yourself, just edit /skins/_rss2/index.main.php line 150
replace

echo make_rel_links_abs( $content );


with

echo make_rel_links_abs( str_replace(']]>', ']]&gt;', $content) );

5 Sep 24, 2011 17:24

[u]Please Note:[/u]

The fix only partly solves the problem but it inspired my to find a solution by myself. Let me clean-up my code, then I post my own solution.

6 Sep 24, 2011 19:20

First of all the description of the problem:

In the blog post script and noscript are contained. Besides that there is CDATA content in the post. The RSS of b2evolution is not correct anymore.

My solution (which also fixes embed and object tags):

in /skins/_rss2/index.main.php and /skins/_atom/index.main.php replace this line

echo make_rel_links_abs( $content ); 

with

echo prepare_rss_content($content);

in the same files add this function

/**
 * Returns RSS content with absolute URLs and removed tags that are not valid in RSS
 *
 * @param RSS content to be filterd
 * @return RSS content
 */
function prepare_rss_content( $content)
{
	// convert the content into plain html
	if (!function_exists("htmlspecialchars_decode")) 
	{
		// fake the missing htmlspecialchars_decode function in PHP4
	    function htmlspecialchars_decode($string,$style=ENT_COMPAT)
    	{
        	$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS,$style));
        	if($style === ENT_QUOTES){ $translation['''] = '\''; }
        	return strtr($string,$translation);
    	}
	}
	$content = htmlspecialchars_decode($content);

	// remove script and enable noscript
	$content = preg_replace("/(\<script)(.*?)(script>)/si", "", "$content"); 
	$content = str_replace('<noscript>', '', $content);
	$content = str_replace('</noscript>', '', $content);

	// remove other invalid tags e.g. to prevent flash content
	$content = preg_replace("/(\<object)(.*?)(object>)/si", "", "$content"); 
	$content = preg_replace("/(\<embed)(.*?)(embed>)/si", "", "$content"); 

	// echo final result with absolute links
	echo make_rel_links_abs($content);
}

The function also can be added to /inc/_core/_template.funcs.php (the non changed index_main.php files still will work.

Final thoughts:

In the in index_main.php files there is a hint from fp concerning a clean solution in format_to_output where some other things should be fixed. I did not find that approach, it might be worth to try to find out what are the issues to be solved there.

I do hope my solution is OK and it will be taken into the CVS and some day in a next b2evolution release :) .

Best Regards,
Vincent

http://www.photo-vinc.com/PHP/blog/


Form is loading...