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 ' " & < > \
- 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/€/sg;
$string =~ s/\x82/‚/sg;
$string =~ s/\x83/ƒ/sg;
$string =~ s/\x84/„/sg;
$string =~ s/\x85/…/sg;
$string =~ s/\x86/†/sg;
$string =~ s/\x87/‡/sg;
$string =~ s/\x88/ˆ/sg;
$string =~ s/\x89/‰/sg;
$string =~ s/\x8A/Š/sg;
$string =~ s/\x8B/‹/sg;
$string =~ s/\x8C/Œ/sg;
$string =~ s/\x8E/Ž/sg;
$string =~ s/\x91/‘/sg;
$string =~ s/\x92/’/sg;
$string =~ s/\x93/“/sg;
$string =~ s/\x94/”/sg;
$string =~ s/\x95/•/sg;
$string =~ s/\x96/–/sg;
$string =~ s/\x97/—/sg;
$string =~ s/\x98/˜/sg;
$string =~ s/\x99/™/sg;
$string =~ s/\x9A/š/sg;
$string =~ s/\x9B/›/sg;
$string =~ s/\x9C/œ/sg;
$string =~ s/\x9E/ž/sg;
$string =~ s/\x9F/Ÿ/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 "
##
</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:
Hope this will be of use to someone. Feel free to play with it and make suggestions. I haven't tested it with Maginot.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.