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: [MOD] A RSS mod (plug-n-play) (sNews 1.4)  (Read 3728 times)

clsc

  • Guest
[MOD] A RSS mod (plug-n-play) (sNews 1.4)
« on: November 30, 2005, 05:52:00 pm »

I've made some changes to the RSS module. Here's the list:


// ----------------------------------------------------------
// RSS feed:
// - - new fields for "":
// - - - ""<br />// - - - "<link><br />// - - - "<description>"<br />// - - - "<language>"<br />// - - - "<ttl>"<br />// - - entries in RSS feed date sorted (descending)<br />// - - custom number of articles in feed (default 10)<br />// - - special date format for RSS possible<br />// - - custom character encoding for feed<br />// - - HTML tags are converted to RSS-equivalents, not deleted<br />// ----------------------------------------------------------<br /><br /><br />I'll just post the changes below, if anyone wants to use them for their own purposes, or if Luka wants to include it in a later version. It's plug-and-play, just copy the parts into the "snews.php" file.<br /><br /><strong>List:</strong><br />·Block (1) goes inside the "Global settings" (top of file). Edit as you please. <br /><br />·Block (2) replaces the existing RSS section ( function rss() ) (around line 870-880 or something). Don't edit this part. Yes, replaces, as in "delete the old block, all of it, and insert the new one in stead". <strong>Please do a backup first</strong>.<br /><br /><br /><br /><br />Now, you don't have to credit me for this, and I'm not going to support it either. Of course it's been tested and it works nicely and all, but don't believe what you read on the internet just like that: <strong>Make a backup of the old file before you test a new file with these changes.</strong> If everything works, well nice, if not then you can just replace the corrupt file with your backup.<br /><br />Here goes, it's free as in "whatever":<br /><br /><strong>Part 1</strong><br /><br />// ----------------------------------------------------------<br />// RSS BLOCK for GLOBAL SETTINGS<br /><br />$s['RSS_description'] = "The YOURSITE news feed"; // RSS: Brief description for RSS feed<br />$s['RSS_language'] = "en-us"; // RSS: Language of RSS Feed<br />$s['RSS_char_encoding'] = "ISO-8859-15"; // RSS Character encoding for feed (default ISO-8859-15)<br />$s['RSS_ttl'] = "480"; // RSS: Time-To-Live (recommended refresh interval for readers, minutes)<br />$s['RSS_date_format'] = "r"; // Date and time format for RSS (PHP syntax, eg. "Y-m-d H:i:s")<br />$s['RSS_no_of_items'] = "10"; // Number of articles in RSS feed<br /><br />// ----------------------------------------------------------<br /><br /><br /><br /><strong>Part 2</strong><br /><br />// ----------------------------------------------------------<br />// RSS BLOCK for MAIN PROGRAM<br /><br />function rss()<br />{<br />   $db = mysql_connect(s('dbhost'),s('dbuname'),s('dbpass'));<br />   mysql_select_db(s('dbname')) or die(s('dberror'));<br />   // get ten articles from center position sorted by date<br />   $query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 1 ORDER BY date DESC LIMIT 0 , " . s(RSS_no_of_items);<br />   $result = mysql_query($query);<br />   $filename = "rss.xml";<br /><br />   $header = "<?xml version="1.0" encoding="" . s(RSS_char_encoding) . "" ?>n";<br />   $header .= "<rss version="2.0">";<br />   $header .= "<channel>";<br />   $header .= "<title>" . s(website_title) . "";
   $header .= "http://" . s(website) . "/";
   $header .= "" . s(RSS_description) . "";
   $header .= "" . s(RSS_language) . "";
   $header .= "" . s(RSS_ttl) . "";

   $footer = "
";
   $footer .= "";

   $items  = "";
   while ($r = mysql_fetch_assoc($result))
   {
      $patterns[0] = "/&/";
      $patterns[1] = "/      $patterns[2] = "/>/";

      $replacements[0] = "&";
      $replacements[1] = "<";
      $replacements[2] = ">";

      $description = preg_replace($patterns, $replacements, stripslashes($r['text']));

      $date = date(s('RSS_date_format'), strtotime($r['date']));

      $items .= "";
      $items .= "". $r['title'] ."";
      $items .= "". $date ."";
      $items .= "". $description ."";
      $items .= "http://". s(website) ."/index.php?id=". $r['id'] ."";
      $items .= "
";
      }

   $theFullFeed = $header . $items . $footer;
   $fh = fopen($filename, "w+");
      fwrite($fh, $theFullFeed);
   fclose($fh);

   echo "";
}

// ----------------------------------------------------------


- enjoy :)

--
/claus - http://clsc.net
Logged

ketut

  • Full Member
  • ***
  • Karma: 0
  • Posts: 115
    • Book Bali Hotels
[MOD] A RSS mod (plug-n-play) (sNews 1.4)
« Reply #1 on: December 02, 2005, 12:48:29 pm »

work well for me...
thanks a lot

Andreas

  • Guest
[MOD] A RSS mod (plug-n-play) (sNews 1.4)
« Reply #2 on: December 06, 2005, 10:01:54 am »

NIce contrib, thanks a lot!
Logged

Presto

  • Newbie
  • *
  • Karma: 0
  • Posts: 26
    • http://www.BirdFluRSS.com
[MOD] A RSS mod (plug-n-play) (sNews 1.4)
« Reply #3 on: January 12, 2006, 12:33:11 pm »

Just what I was looking for but for the life of me can't get it to work with v1.3.

Did anyone else who used this have to make mods or did the script work as given?

Thanks.

Dom

  • Full Member
  • ***
  • Karma: 5
  • Posts: 163
    • domdelimar.com
[MOD] A RSS mod (plug-n-play) (sNews 1.4)
« Reply #4 on: March 11, 2006, 08:34:55 pm »

Thanks claus, it's a nice mod and i successfuly applied it on my sNews1.4.

Presto, I did change claus'  block N°2 that starts with "// RSS BLOCK for MAIN PROGRAM".
Here's what I used and if you want to try it out don't forget to do a backup first.

Code: [Select]
// RSS BLOCK for MAIN PROGRAM

function rss()
{
   $db = mysql_connect(s('dbhost'),s('dbuname'),s('dbpass'));
   mysql_select_db(s('dbname')) or die(s('dberror'));
   // get ten articles from center position sorted by date
   $query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 1 ORDER BY date DESC LIMIT 0 , " . s('RSS_no_of_items');
   $result = mysql_query($query);
   $filename = "rss.xml";

   $header = "n";
   $header .= "";
   $header .= "";
   $header .= "" . s('website_title') . "";
   $header .= "http://" . s('website') . "/";
   $header .= "" . s('RSS_description') . "";
   $header .= "" . s('RSS_language') . "";
   $header .= "" . s('RSS_ttl') . "";

   $footer = "
";
   $footer .= "
";

   $items  = "";
   while ($r = mysql_fetch_assoc($result))
   {
      $patterns[0] = "/&/";
      $patterns[1] = "/      $patterns[2] = "/>/";

      $replacements[0] = "&";
      $replacements[1] = "<";
      $replacements[2] = ">";

      $description = preg_replace($patterns, $replacements, stripslashes($r['text']));

      $date = date(s('RSS_date_format'), strtotime($r['date']));

      $items .= "";
      $items .= "". $r['title'] ."";
      $items .= "". $date ."";
      $items .= "". $description ."";
      $items .= "". s(website) . find_cat_sef($r['category']). "/" .$r['seftitle']. "/";
      $items .= "". s(website) . find_cat_sef($r['category']). "/" .$r['seftitle']. "/";
      $items .= "
";
      }

   $theFullFeed = $header . $items . $footer;
   $fh = fopen($filename, "w+");
      fwrite($fh, $theFullFeed);
   fclose($fh);

   echo "";
}

It works great as you can see on http://how-to-write-a-business-letter.com.
It also validates great as you can see at feedvalidator.org.

Hope it hepls. Make sure to let us know anyway.
Logged