RSS and 1.31.5

All notes and input on 2.0 Development are herein. <ul><li>Feature requests</li>
<li>Bug Reports</li>
<li>Beta Testing Feedback</li>
<li>Open Dev Discussion</li></ul>

Moderator: Coranto Moderator Team

RSS and 1.31.5

Postby Musicvid » Sun Jan 21, 2007 5:32 pm

I wanted to repost my code and instructions for RSS 2.0 with 1.31.5 since it has been mentioned in newer threads, but is now buried inside a four-page thread in the archive forums.
Features
    Creates valid RSS 2.0 (http://feedvalidator.org)
    Uses strftime for dates, which is very fast and fully RFC822 compliant
    (There is an alternative included if for some reason Posix isn't on your server)
    Puts all the variables in the style rather than hardcoding the template. This way, one template will serve many feeds.
    Puts text between <![CDATA[]]> blocks to escape illegal characters like ' " & < > \
Here is the Style (last tweak 8-17-07):
Code: Select all
<PerlCode>

   # Just run the channel stuff once
   my $i  = ++$countitems{$ProfileName};
   for ($i)
   {
   next unless $i == 1;

   ## Populate Channel Fields ##
   ######################################
   #  CHANGE TO MATCH YOUR INFORMATION  #
   ######################################

   # Your Organization or Feed Name
   my $orgname    = 'Your Organization Name';

   # Optional Acronym or Abbreviation (can leave blank)
   my $orgabbr    = '';

   # Channel Image Must Be No More Than 144px In Width
   my $imageurl   = 'http://yoursite.com/yourlogo.gif';

   ######################################
   #   ANY CHANGES BELOW ARE OPTIONAL   #
   ######################################

   if (!$orgabbr) {$orgabbr = $orgname;}
   my $SiteTitle  = $CConfig{'SiteTitle'};
   my $SiteLink   = $CConfig{'SiteLink'};

  # Subs to fix undeclared characters (windows-1252)
  # Substitutes windows characters with generic ISO-8859-1
    sub replace1252  {
    my $string = shift;
    $string =~ tr/\x82\x83\x84\x86\x88\x8A\x8B\x8E/'f"\*^S'Z/;
    $string =~ tr/\x91\x92\x93\x94\x95\x96\x98\x9A\x9B\x9E\x9F/''""\*\-~s'zY/;
    $string =~ s/\x80/EUR/sg;
    $string =~ s/\x85/.../sg;
    $string =~ s/\x87/\*\*/sg;
    $string =~ s/\x89/0\/00/sg;
    $string =~ s/\x8C/OE/sg;
    $string =~ s/\x97/--/sg;
    $string =~ s/\x99/\(TM\)/sg;
    $string =~ s/\x9C/oe/sg;
    $string =~ tr/\x80-\x9F//d;
    return($string);
    }
  # Replaces windows characters with their Unicode equivalents
  # Use in <description> fields only
  # Use replace1252 instead if feed is not served UTF-8
    sub preserve1252 {
    my $string = shift;
    $string =~ s/\x80/&#8364;/sg;
    $string =~ s/\x82/&#8218;/sg;
    $string =~ s/\x83/&#402;/sg;
    $string =~ s/\x84/&#8222;/sg;
    $string =~ s/\x85/&#8230;/sg;
    $string =~ s/\x86/&#8224;/sg;
    $string =~ s/\x87/&#8225;/sg;
    $string =~ s/\x88/&#710;/sg;
    $string =~ s/\x89/&#8240;/sg;
    $string =~ s/\x8A/&#352;/sg;
    $string =~ s/\x8B/&#8249;/sg;
    $string =~ s/\x8C/&#338;/sg;
    $string =~ s/\x8E/&#381;/sg;
    $string =~ s/\x91/&#8216;/sg;
    $string =~ s/\x92/&#8217;/sg;
    $string =~ s/\x93/&#8220;/sg;
    $string =~ s/\x94/&#8221;/sg;
    $string =~ s/\x95/&#8226;/sg;
    $string =~ s/\x96/&#8211;/sg;
    $string =~ s/\x97/&#8212;/sg;
    $string =~ s/\x98/&#732;/sg;
    $string =~ s/\x99/&#8482;/sg;
    $string =~ s/\x9A/&#353;/sg;
    $string =~ s/\x9B/&#8250;/sg;
    $string =~ s/\x9C/&#339;/sg;
    $string =~ s/\x9E/&#382;/sg;
    $string =~ s/\x9F/&#376;/sg;
    $string =~ tr/\x80-\x9F//d;
    return($string);
    }

   # Gets the current time in RFC822 format
     use POSIX qw(strftime);
   # If Posix isn't on your server, comment it out and uncomment the line below.
   # use Date::Format;
     my @BuildDate = localtime(time);
     my $now_year  = strftime("%Y", @BuildDate);
     my $BuildDate = strftime("%a, %d %b %Y %H:%M:%S %z", @BuildDate);
   # If a US timezone, could use %Z above instead

   # Added to confirm feed build in 'News Built' dialog
     print "<small>\"$ProfileName\" Feed Built: $BuildDate<br></small>";

$newshtml .= "<title><![CDATA[<Field: orgabbr> News]]></title>\n";
$newshtml .= "<link><Field: SiteLink></link>\n";
$newshtml .= "<description><![CDATA[The Latest News from <Field: orgname>]]></description>\n";
# Could use <Field: SiteTitle> in description instead
$newshtml .= "<copyright><![CDATA[Copyright (c) <Field: now_year> <Field: orgname>. All rights reserved.]]></copyright>\n";
$newshtml .= "<language>en-us</language>\n";
$newshtml .= "<lastBuildDate><Field: BuildDate></lastBuildDate>\n";
$newshtml .= "<image>\n";
$newshtml .= "<title><![CDATA[<Field: orgabbr> Home Page]]></title>\n";
$newshtml .= "<link><Field: SiteLink></link>\n";
$newshtml .= "<url><Field: imageurl></url>\n";
$newshtml .= "</image>\n";
   }

   ## Populate Item Fields ##
     my @time_added = gmtime($newstime);
     my $pubDate    = strftime("%a, %d %b %Y %H:%M:%S GMT", @time_added);
     my $adminurl   = $scripturl;
     $adminurl      =~ s/\/coranto.cgi?/\//;
   # Template for item links (can leave blank)
     my $tmpl       = 'viewnews';

   # Resolves windows-1252 character issues
     my $Subject = replace1252($Subject);
     my $Text    = preserve1252($Text);
   # If feed is not served UTF-8, use replace1252 above instead
   # Cleans up HTML in titles and text
     $Subject    = unHTMLescape($Subject);
     $Subject    = HTMLstrip($Subject);
     $Text       = HTMLstrip($Text);

## RSS NOTES
#  Channel Image Must Be <= 144px In Width
#  No HTML in <title> Fields
#  Keep Fields Containing ' " & < > \ between <![CDATA[]]> tags
#  Avoid using HTML entities such as &quot;
##
</PerlCode>

<item>
<title><![CDATA[<Field: Subject>]]></title>
<link><![CDATA[<Field: adminurl>viewnews.cgi?id=<Field: newsid>&style=&tmpl=<Field: tmpl>]]></link>
<description><![CDATA[<Snip 265: Field: Text>]]></description>
<pubDate><Field: pubDate></pubDate>
<guid isPermaLink="false"><Field: adminurl>viewnews.cgi?id=<Field: newsid></guid>
</item>

Here is the Template (rss.tmpl):
Code: Select all
<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<channel>
<Field: Content>
</channel>
</rss>

*NOTE: Changed encoding declaration back to ISO-8859-1 to support European characters (11-23-2007).

Example feed is up at http://ovationplayers.com/news/rss.xml
The formatted feed can be seen at http://feeds.feedburner.com/TheOvationPlayersNews
(The images in some of the example feed descriptions are by way of a custom field "Image." A really easy addition to make.)

Here are the full install instructions:
1) In Coranto 1.31.5 Beta, go to Administration->Edit News Styles->Create New Style.

2) Name the new Style "RSS Feed" without the quotes and create a STANDARD Style.

3) Click "Edit" RSS Feed and paste the Style Code I provided. Type in the name of your Organization or Feed, and the URL of your Channel Image, which can be no more than 144 pixels in width. Click "Save Changes."

4) Open the Notepad application on your computer, paste the Template code I provided, Save the file, then Rename the file to "rss.tmpl" without the quotes. Upload the rss.tmpl file to the "Templates" folder in your Coranto 1.31.5 installation on your server.

5) In Administration->Manage Profiles->Create New Profile, create a Profile named "RSS_Feed" without the quotes. Enable the RSS_Feed Profile.

6) Click "Edit General Settings" for the RSS_Feed Profile. Scroll down to "Categories" and select any Categories of news items you wish to include in your feed. Immediately below that, select "RSS Feed" as your News Style. Scroll down to "HTML Template" and select "rss.tmpl". Immediately below that, type in "rss.xml" without the quotes as your "HTML User File Name." Scroll down to "Anchor Tags?" and set them to "OFF." Do not make any other changes to the Profile settings. Click "Save Changes."

7) Go to Administration and click the "Build News" link. You should now have a valid RSS 2.0 file named "rss.xml" in your news files folder.
Hope this will be of use to someone. Feel free to play with it and make suggestions. I haven't tested it with Maginot.
Last edited by Musicvid on Fri Nov 23, 2007 9:58 pm, edited 27 times in total.
Musicvid
 
Posts: 138
Joined: Wed Jan 17, 2007 1:05 am
Location: Western America

Postby Feathers » Sun Jan 21, 2007 6:17 pm

This should go in the Wiki too!
Mike
(Maintaining the vB3Comments addon)
Feathers
 
Posts: 110
Joined: Wed Jan 10, 2007 6:06 pm
Location: London

Postby Musicvid » Mon Feb 19, 2007 10:39 pm

8-17-07 -- See three posts down for a better solution.

[quote] # Added to fix undeclared curly quotes (MS Word)
$Subject =~ s/[‘’]/'/g;
$Subject =~ s/[“â€
Last edited by Musicvid on Sun Jun 01, 2008 2:44 pm, edited 6 times in total.
Musicvid
 
Posts: 138
Joined: Wed Jan 17, 2007 1:05 am
Location: Western America

Postby Dale Ray » Sun Feb 25, 2007 8:36 pm

Feathers wrote:This should go in the Wiki too!

Done -

RSS Files - How to Create
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby Musicvid » Thu Mar 29, 2007 3:57 pm

3-29-07:
I found two subs in crlib that do a nice job of cleaning out html from <title> and <description> text fields. Now html in your Subject and News Text fields will be excluded from the RSS feed, keeping it valid and readable whether or not you Snip. Linked articles still display your original formatting.

The following code was added:
Code: Select all
   # Cleans up HTML in titles and text
    $Subject  = unHTMLescape($Subject);
    $Subject  = HTMLstrip($Subject);
    $Text     = HTMLstrip($Text);
Musicvid
 
Posts: 138
Joined: Wed Jan 17, 2007 1:05 am
Location: Western America

Postby Musicvid » Fri Aug 17, 2007 4:07 pm

8-17-07
Added two subs (replace1252, preserve1252) to completely resolve the windows-1252 character issue.

If you are having problems with MS Word content containing smart quotes, ellipses, dashes, etc. not showing up and or represented as \x93, \x96, etc., then you will want to update your style and template with the code at the top of this thread. Now the undeclared characters will be replaced with generic substitutions in the <title> fields, and preserved in <description> fields. Sorry they can't be preserved in the <title> fields because character entities are not permitted there.

For a more detailed explanation see windows-1252 ISO-8859-1 UTF-8 Encoding Issues & Solution
Musicvid
 
Posts: 138
Joined: Wed Jan 17, 2007 1:05 am
Location: Western America


Return to Coranto 2.0 Development

Who is online

Users browsing this forum: No registered users and 3 guests

cron