DCSun Administrator
Posts: 330 |
|
|
| Creating an RSS Feed from your FlexCMS News/Articles | April 29, 2008 @ 2:46pm | Hey sports fans, we've had some interest from users to create an RSS feed from their FlexCMS site's news/articles module, so here it is 
To make it work, simply create a new page, paste the code below into it, and enable PHP. The address of that page becomes the URL of your feed (ie: http://www.flexcms.com/index.php/pages/rss.html, if you called the page "rss").
Code
if ($IM['na'] == 'y') { $query_na = "select * from `".$Settings['DBPrefix']."na-Settings`"; $result_na = mysql_query($query_na) or die (mysql_error()); while ($row_na = mysql_fetch_array($result_na)) { $naSettings[$row_na['Name']] = $row_na['Value']; }
$CategoriesList = ""; // optional -- comma separated list of category IDs to use articles from
$ArticlesCount = 5; // optional -- number of articles to include in feed
$DescriptionLength = ""; // optional -- number of characters to use for description, otherwise // defaults to FlexCMS news/articles teaser length setting
header('Content-type: text/xml');
print '<?xml version="1.0" encoding="UTF-8"?> <rss version="0.91"> <channel> <title>SECWB.com</title> <link>http://www.secwb.com</link> <description>SEC Womens College Basketball</description> <language>en-us</language>';
if ($DescriptionLength > 0) { $naSettings['TeaserLength'] = $DescriptionLength; }
if ($ArticlesCount != '') { if (strpos($ArticlesCount,',') !== false) { list($ACOffset,$ACCount) = explode(',',$ArticlesCount); $LimitString = intval($ACOffset).','.intval($ACCount); } else { $LimitString = intval($ArticlesCount); } } else { $LimitString = 5; }
if ($CategoriesList != '') {
$CategoriesArray = explode(',',$CategoriesList); for ($i = 0; $i < count($CategoriesArray); $i++) { $CategoriesArray[$i] = intval($CategoriesArray[$i]); } $CategoriesList2 = '"'.implode('","',$CategoriesArray).'"'; $query_na = "SELECT * FROM `".$Settings['DBPrefix']."na-Articles` WHERE ApprovedBy!='' AND (Category IN (".$CategoriesList2.") OR Category2 IN (".$CategoriesList2.") OR Category3 IN (".$CategoriesList2.") OR Category4 IN (".$CategoriesList2.") OR Category5 IN (".$CategoriesList2.") OR Category6 IN (".$CategoriesList2.") OR Category7 IN (".$CategoriesList2.") OR Category8 IN (".$CategoriesList2.") OR Category9 IN (".$CategoriesList2.") OR Category10 IN (".$CategoriesList2.")) ORDER BY DateCode DESC LIMIT ".$LimitString; } else { $query_na = "SELECT * FROM `".$Settings['DBPrefix']."na-Articles` WHERE ApprovedBy!='' ORDER BY DateCode DESC LIMIT ".$LimitString; }
$result_na = mysql_query($query_na) or die (mysql_error());
$BadWordChars = array( "\xe2\x80\x98", // left single quote "\xe2\x80\x99", // right single quote "\xe2\x80\x9c", // left double quote "\xe2\x80\x9d", // right double quote "\xe2\x80\x94", // em dash "\xe2\x80\xa6", // elipses "\xe2\x80\x93", // long dash "\xe2\x80\x94", // long dash "\xe2\x80\x98", // single quote opening "\xe2\x80\x99", // single quote closing "\xe2\x80\x9c", // double quote opening "\xe2\x80\x9d", // double quote closing "\xe2\x80\xa2", // dot used for bullet points chr(146), );
$FixedWordChars = array( "‘", "’", '“', '”', '—', '…', '-', '-', '\'', '\'', '"', '"', '*', '\'' );
while ($row_na = mysql_fetch_array($result_na)) {
if ($row_na['Teaser'] == '') { $StrippedArticle = strip_tags($row_na['Article']); if (strlen($StrippedArticle) > $naSettings['TeaserLength']) { $TeaserSection = substr($StrippedArticle,0,$naSettings['TeaserLength']); while (substr($TeaserSection,strlen($TeaserSection)-1,1) != ' ') { $TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1); } while (substr($TeaserSection,strlen($TeaserSection)-1,1) == ' ') { $TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1); } $TeaserSection .= '...'; } else { $TeaserSection = $row_na['Article']; } } else { $TeaserSection = substr($row_na['Teaser'],0,$naSettings['TeaserLength']); if (strlen($row_na['Teaser']) > strlen($TeaserSection)) { while (substr($TeaserSection,strlen($TeaserSection)-1,1) != ' ') { $TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1); } while (substr($TeaserSection,strlen($TeaserSection)-1,1) == ' ') { $TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1); } $TeaserSection .= '...'; } }
$TeaserSection = str_replace($BadWordChars, $FixedWordChars, $TeaserSection); $TeaserPrint = ''; for ($x = 0; $x < $naSettings['TeaserLength']; $x++) { $CharCode = ord(substr($TeaserSection,$x,1)); if (($CharCode > 31 && $CharCode < 127) || $CharCode == 10 || $CharCode == 13 || $CharCode == 9) { $TeaserPrint .= chr($CharCode); } //else { // $TeaserPrint .= ''.$CharCode.';'; //} }
$TeaserPrint = str_replace(' ',' ',$TeaserPrint); $TeaserPrint = str_replace('&','&',$TeaserPrint); $TeaserPrint = str_replace('&','&',$TeaserPrint); $TitleSection = str_replace($BadWordChars, $FixedWordChars, $row_na['Title']); $TitlePrint = ''; for ($x = 0; $x < strlen($TitleSection); $x++) { $CharCode = ord(substr($TitleSection,$x,1)); if (($CharCode > 31 && $CharCode < 127) || $CharCode == 10 || $CharCode == 13 || $CharCode == 9) { $TitlePrint .= chr($CharCode); } //else { // $TitlePrint .= ''.$CharCode.';'; //} }
$TitlePrint = str_replace(' ',' ',$TitlePrint); $TitlePrint = str_replace('&','&',$TitlePrint); $TitlePrint = str_replace('&','&',$TitlePrint);
print '<item> <title>'.$TitlePrint.'</title> <link>'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'.html</link> <description>'.$TeaserPrint.'</description> </item>';
}
print '</channel> </rss>';
}
exit(); |
|
You can also make it appear as a feed for your site in newer browsers by adding this tag to your template or a block on your site: 
Code
<link rel="alternate" type="application/rss+xml" title="YourSiteName News Feed [RSS]" href="http://www.yoursitedomain.com/index.php/pages/rss.html"> |
|
|
|