Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: [FIX] RSS Feed Quick Fix  (Read 8040 times)

Luka

  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 36
  • Posts: 1716
    • http://www.snewscms.com
[FIX] RSS Feed Quick Fix
« on: June 15, 2006, 10:51:32 PM »

Backup your snews.php first!


If your feed doesn't validate, try replacing old rss function with this one:

Code: [Select]
// RSS FEED
function rss() {
$limit = s('rss_limit');
$query = "SELECT * FROM articles WHERE position = 1 ORDER BY date DESC LIMIT 0, $limit";
$result = mysql_query($query);
$filename = "rss.xml";
$header = "";
$header .= "";
$header .= "";
$header .= "" .s('website_title'). "";
$header .= "" .s('website_title'). "";
$header .= "" .s('website'). "";
$header .= "Copyright " .s('website_title'). "";
$footer = "
";
$footer .= "
";
$fh = fopen($filename, "w+");
fwrite($fh, $header);
while ($r = mysql_fetch_assoc($result)){
$date = date('D, d M Y H:i:s +0000', strtotime($r['date']));
    $pattern="'<[\/\!]*?[^<>]*?>'si";
    $replace="";
    $description = preg_replace($pattern, $replace, stripslashes($r['text']));
    $item  ="";
    $item .= "". $r['title'] ."";
    $item .= "". $description ."";
    $item .= "". $date ."";
    $item .= "". s('website') . find_cat_sef($r['category']). "/" .$r['seftitle']. "/";
    $item .= "". s('website') . find_cat_sef($r['category']). "/" .$r['seftitle']. "/";
    $item .= "
";
    fwrite($fh, $item);
  }
fwrite($fh, $footer);
fclose($fh);
echo "";
}
Test here: http://www.feedvalidator.org/
Logged

ketut

  • Full Member
  • ***
  • Karma: 0
  • Posts: 115
    • Book Bali Hotels
[FIX] RSS Feed Quick Fix
« Reply #1 on: July 15, 2006, 06:49:06 AM »

change from:

$query = "SELECT * FROM articles WHERE position = 1 ORDER BY date DESC LIMIT 0, $limit";

into :
$query = "SELECT * FROM " .s('prefix'). "articles  WHERE position = 1 ORDER BY date DESC LIMIT 0, $limit";

brauck

  • Hero Member
  • *****
  • Karma: 18
  • Posts: 556
    • http://www.hbw-webdesign.nl/
[FIX] RSS Feed Quick Fix
« Reply #2 on: July 15, 2006, 04:39:14 PM »

This was a known bug ketut. Very good observed though! :)
Logged
Confidence is reduced complexity.
brauck.nl for free css templates

Edgar

  • Newbie
  • *
  • Karma: 0
  • Posts: 12
    • Http://www.warriorsofthe107th.com
[FIX] RSS Feed Quick Fix
« Reply #3 on: September 19, 2006, 07:26:38 PM »

i still get errors ...

This feed does not validate.
line 1, column 0: Undefined root element: script


In addition, this feed has an issue that may cause problems for some users. We recommend fixing this issue.

Feeds should not be served with the "text/html" media type

Source: http://80.57.240.139/snews/rss/
Logged
I love deadlines.  I especially like the whooshing sound they make as they go by.

mininovax

  • Newbie
  • *
  • Karma: 1
  • Posts: 44
    • http://www.ondapc.net
[FIX] RSS Feed Quick Fix
« Reply #4 on: November 07, 2006, 06:20:07 PM »

You need to place CDATA sections into your RSS feeds for validation...


replace // RSS FEED function with this ... just adds in your feeds so validators note to interpret it correctly


Code: [Select]
// RSS FEED
function rss() {
$limit = s('rss_limit');
$result = mysql_query("SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = 1 ORDER BY date DESC LIMIT 0, $limit");
header('Content-type: text/xml; charset='.s('charset'));
$header = '';
$header .= '';
    $header .= '';
    $header .= '<![CDATA['.s('website_title').']]>';
    $header .= '';
    $header .= ''.db('website').'';
    $header .= 'Copyright '.s('website_title').'';
    $header .= 'OndaPC S.A.';
    $footer = '
';
    $footer .= '
';
echo $header;    
while ($r = mysql_fetch_assoc($result)) {
$link = db('website').find_cat_sef($r['category']).'/'.$r['seftitle'].'/';
$date = date('D, d M Y H:i:s +0000', strtotime($r['date']));
$description = preg_replace("[\[(.*?)\]]", "", stripslashes(strip_tags($r['text'])));
$item  = '';
$item .= '<![CDATA['.$r['title'].']]>';
$item .= '';
$item .= ''.$date.'';
$item .= ''.$link.'';
$item .= ''.$link.'';
$item .= '
';
echo $item;
}
echo $footer;
}
Logged

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
[FIX] RSS Feed Quick Fix
« Reply #5 on: November 08, 2006, 08:12:59 AM »

Just to makesure, is this code (from mininovax) 1.5RC3.

I ask, because I put my site's rss thru' the validator, and it passed... and it is unaduktered 1,5RC3
Logged
Of all the things I have lost, it is my mind that I miss the most.

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[FIX] RSS Feed Quick Fix
« Reply #6 on: November 08, 2006, 10:30:29 AM »

If your site charset is consistent site wide, that is, if you've edited snews package files with the same encoding/charset as stated in
admin -> settings -> time & locale settings -> default charset (your-charset-here),
then you shouldn't have any problems. Notice that RSS (xml files) works best with UTF-8 charset.

If you're using some other encoding, you can use (as previously suggested) CDATA entities.
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

mininovax

  • Newbie
  • *
  • Karma: 1
  • Posts: 44
    • http://www.ondapc.net
[FIX] RSS Feed Quick Fix
« Reply #7 on: November 10, 2006, 08:43:10 PM »

Actually, not to be in an argumentative mode, but in my experience coding for RSS feeds, it is almost 99.9 suggested to use CDATA in all text areas.

Now, why would you ask? Well XML is very finicky. Character sets, that are used in UTF are encoded incorrectly, and this causes the XML parser to fail validation.

Most articles at one time or another will use the & sign, if the "&" signed is used directly in the text area of an article the RSS feed will not validate.

My suggestion to Solucija and all users is to begin using CDATA in their RSS FUNCTIONS ....

UTF-8 / ISO-8859 /

I have tried on multiple occassions to use PHP to help me out, because I did not want to use the CDATA tags in my xml, but you just cannot do it without using a major "character --> entity" function which is about 400 lines long, I liked that even less.

just my 2 cents
Logged

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[FIX] RSS Feed Quick Fix
« Reply #8 on: November 10, 2006, 11:04:47 PM »

LOL you're right... I was going to suggest that same huge thing...
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version