Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Syndicate X-Cart news as RSS 2.0 Channel
 
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features
 
Thread Tools Search this Thread
  #1  
Old 02-01-2006, 11:32 AM
 
zaa zaa is offline
 

X-Cart team
  
Join Date: Apr 2004
Location: Ulyanovsk, Russia
Posts: 125
 

Default Syndicate X-Cart news as RSS 2.0 Channel

If you'd like to offer a RSS feed with the latest news from your x-cart 4.1.x, feel free to use the following code.

1. Create news_feed.php in the root of your x-cart with the following content:

PHP Code:
<?php
/*
 * news_feed.php.
 * 2008-07-17. Zhuravlev Alexander (zaa@qualiteam.biz).
 * License: MIT (http://www.opensource.org/licenses/mit-license.php)
 * 
 * Syndicate X-Cart news as RSS 2.0 Channel
 * Script supports HTTP conditional GET
 * http://fishbowl.pastiche.org/2002/10/21/http_conditional_get_for_rss_hackers
 * 
 * Note: News should be added at News Management page of x-cart
 * administration area. Corresponding news list and messages in it should have option "Show as news" being enabled.
 * 
 */

@include_once "./top.inc.php";
if (!
defined('DIR_CUSTOMER')) die("ERROR: Can not initiate application! Please check configuration.");

define('XCART_SESSION_START'1); # We do not need any sessions
if (@file_exists($xcart_dir."/init.php")) {
    require 
$xcart_dir."/init.php";
} else {
    require 
$xcart_dir."/config.php";
}

# *Required* RSS channel properties. [[[
$rss_channel = array();

# The name of the channel. It's how people refer to your service.
$rss_channel['title'] = $config['Company']['company_name'] . " News Headlines";

# The URL to the HTML website corresponding to the channel.
$rss_channel['link'] = $http_location;

# Phrase or sentence describing the channel
$rss_channel['description'] = "The latest news from " $config['Company']['company_name'];
    
# The language the channel is written in. 
# http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
$rss_channel['language'] = "en";
    
# By default we assume that text is provided in UTF-8 enconding.
# You may change this according to your needs. 
$rss_channel['encoding'] = 'UTF-8';
# ]]]

define('RSS20_DATE_FORMAT',  "D, d M Y H:i:s O");
   
# Fetch messages info 
if ($active_modules['News_Management']) {
    
$messages_info func_query_first("SELECT COUNT(*) as msg_count, MAX(date) AS last_date FROM $sql_tbl[newslists] AS nl LEFT JOIN $sql_tbl[newsletter] AS n ON n.listid = nl.listid WHERE nl.avail='Y' AND nl.show_as_news='Y' AND n.show_as_news = 'Y' ORDER BY n.date DESC");
}

if (!empty(
$messages_info) && $messages_info['last_date']) {
    
$last_mod_time date(RSS20_DATE_FORMAT$messages_info['last_date']);
    
$news_page_url $http_location.DIR_CUSTOMER."/news.php";
    
$messages func_query("SELECT n.newsid, n.subject, n.body, n.date FROM $sql_tbl[newslists] AS nl LEFT JOIN $sql_tbl[newsletter] AS n ON n.listid = nl.listid WHERE nl.avail='Y' AND nl.show_as_news='Y' and n.show_as_news = 'Y' ORDER BY n.date DESC");
    
$items_code "";
    foreach (
$messages as $m) {
            
$pubDate date(RSS20_DATE_FORMAT$m['date']);
            
$m['title'] = htmlspecialchars($m['subject']);
            
$items_code .= <<<EX
        <item> 
            <title>
{$m['subject']}</title>
            <description><![CDATA[
{$m['body']}]]></description>
            <link>
$news_page_url</link>
            <guid isPermaLink="false">
{$m['newsid']}@$news_page_url</guid>
            <pubDate>
$pubDate</pubDate>
        </item>

EX;
    }
} else {
    
$last_mod_time date(RSS20_DATE_FORMATtime());
}

# Channel header
$rss_channel['title'] = htmlspecialchars($rss_channel['title']);
$rss_channel['description'] = htmlspecialchars($rss_channel['description']);
$channel = <<<EX
<?xml version="1.0" encoding="{$rss_channel['encoding']}"?>
<rss version="2.0">
    <channel>
        <title>
{$rss_channel['title']}</title>
        <link>
{$rss_channel['link']}</link>
        <description>
{$rss_channel['description']}</description>
        <language>
{$rss_channel['language']}</language>
        <generator>X-Cart</generator>
        <pubDate>
$last_mod_time</pubDate>
        <lastBuildDate>
$last_mod_time</lastBuildDate>

EX;

if (!empty(
$items_code)) {
        
$channel .= $items_code;
        unset(
$items_code);
}

$channel .= <<<EX
    </channel>
</rss>

EX;

$channel_etag '"'.md5($channel).'"';

# Conditional GET logic [[[
# Check if the channel contents should be passed to client.
# We analyze HTTP response headers: If-Modified-Since, If-None-Match

$IMS_FLAG 0;
if (!empty(
$HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE'])) {
        if (
strtotime($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE'])  == strtotime($last_mod_time)) {
              
$IMS_FLAG 1;
        }
}

$INM_FLAG 0;
if (!empty(
$HTTP_SERVER_VARS['HTTP_IF_NONE_MATCH'])) {
        if (
$HTTP_SERVER_VARS['HTTP_IF_NONE_MATCH']  == $channel_etag) {
              
$INM_FLAG 1;
        }
}

$pass_channel_to_client = !($IMS_FLAG || $INM_FLAG);
# ]]]

if (!$pass_channel_to_client) {
    
header("HTTP/1.0 304 Not Modified");
    
header('ETag: ' $channel_etag);
} else {
    
# Output headers [[[
    
header("Content-Type: application/xml; charset=".$rss_channel['encoding']);
    
header("Content-length: " strlen($channel));
    
header("Last-Modified: " $last_mod_time);
    
header('ETag: ' $channel_etag);
    
# ]]]

    
echo $channel;
}

# vim600: set et sw=4 sts=4 ts=4 fdm=marker fmr=[[[,]]]:
?>

2. open skin1/customer/home.tpl and replace in the file:

{ include file="meta.tpl" }

with
Code:
{ include file="meta.tpl" } <link rel="alternate" type="application/rss+xml" title="RSS" href="{$current_location}/news_feed.php" />

After that users of Mozilla and Opera will automatically see RSS icon in location bar and will be able to subscribe to the RSS feed.
Reply With Quote
  #2  
Old 02-17-2006, 10:25 AM
 
markwhoo markwhoo is offline
 

X-Adept
  
Join Date: Nov 2003
Posts: 799
 

Default

Has anyone tried anything like this with earlier versions such as 3.4 or 3.5 branches?

I would like to use aspects of this in another mod, but it would be for 3.4 or 3.5 versions.
__________________
vs 4.1.12
Reply With Quote
  #3  
Old 04-18-2006, 07:14 PM
 
Abdul Abdul is offline
 

Member
  
Join Date: Jul 2004
Location: Miami
Posts: 17
 

Default didn't work for me

I tried this mod yet it's not working for me tell me what i'm doing worong.
www.certifiedcomp.com/store/home.php
__________________
X-Cart 4.1.7 Gold
Reply With Quote
  #4  
Old 04-19-2006, 06:30 AM
  TelaFirma's Avatar 
TelaFirma TelaFirma is offline
 

X-Adept
  
Join Date: Nov 2002
Location: North Carolina USA
Posts: 930
 

Default Re: didn't work for me

Quote:
Originally Posted by Abdul
I tried this mod yet it's not working for me tell me what i'm doing worong.
www.certifiedcomp.com/store/home.php

Your PHP file is being processed as a text file.

http://www.certifiedcomp.com/store/news_feed.php

Check to make sure that the vey first thing in that file is <?php
Reply With Quote
  #5  
Old 04-23-2006, 06:44 AM
 
MallRomania MallRomania is offline
 

Senior Member
  
Join Date: Apr 2006
Posts: 109
 

Default

Hello

Please help. I receive following error when acces news_feed.php:

Parse error: parse error, unexpected T_SL in /home/mallroma/public_html/news_feed.php on line 60

Thanks
__________________
Mircea Teleleu
Shopedia.ro-la cumparaturi
www.shopedia.ro
______________________
x-cart gold 4.1.6
Linux
Reply With Quote
  #6  
Old 08-06-2007, 04:14 PM
 
Pilnik Pilnik is offline
 

Member
  
Join Date: Jul 2007
Posts: 18
 

Default Re: Syndicate X-Cart news as RSS 2.0 Channel

I did everything according to the instructions, but it seems it doesn't work. I have no error messages, added two messages to news list and all programs recognize RSS feed. When they open it there are no messages displayed.
Can somebody help?
__________________
X-Cart 4.1.8

africanartstall.com - an online store for african art
Reply With Quote
  #7  
Old 08-26-2007, 11:08 AM
 
alinush alinush is offline
 

Advanced Member
  
Join Date: Jul 2007
Posts: 88
 

Default Re: Syndicate X-Cart news as RSS 2.0 Channel

zaa thank you for posting this. Anybody tried this on 4.1.8 ? I created the news_feed.php file but it doesn't list any news, although I have one posted.
__________________
X-Cart 4.1.x to 4.7.x
Reply With Quote
  #8  
Old 09-10-2007, 06:24 AM
 
zaa zaa is offline
 

X-Cart team
  
Join Date: Apr 2004
Location: Ulyanovsk, Russia
Posts: 125
 

Default Re: Syndicate X-Cart news as RSS 2.0 Channel

New version of the file works with x-cart 4.0.x and x-cart 4.1.x:

PHP Code:
<?php
/*
 * news_feed.php.
 * 2007-09-10. Zhuravlev Alexander (zaa@qualiteam.biz).
 * License: MIT (http://www.opensource.org/licenses/mit-license.php)
 * 
 * Syndicate X-Cart news as RSS 2.0 Channel
 * Script supports HTTP confitional GET
 * http://fishbowl.pastiche.org/2002/10/21/http_conditional_get_for_rss_hackers
 * 
 * Note: News should be added at News Management page of x-cart
 * administraton area.
 * 
 */

@include_once "./top.inc.php";
if (!
defined('DIR_CUSTOMER')) die("ERROR: Can not initiate application! Please check configuration.");

define('XCART_SESSION_START'1); # We do not need any sessions
if (@file_exists($xcart_dir."/init.php")) {
    require 
$xcart_dir."/init.php";
} else {
    require 
$xcart_dir."/config.php";
}

# *Required* RSS channel properties. [[[
$rss_channel = array();

# The name of the channel. It's how people refer to your service.
$rss_channel['title'] = $config['Company']['company_name'] . " News Headlines";

# The URL to the HTML website corresponding to the channel.
$rss_channel['link'] = $http_location;

# Phrase or sentence describing the channel
$rss_channel['description'] = "The latest news from " $config['Company']['company_name'];
    
# The language the channel is written in. 
# http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
$rss_channel['language'] = "en";
    
# By default we assume that text is provided in UTF-8 enconding.
# You may change this according to your needs. 
$rss_channel['encoding'] = 'UTF-8';
# ]]]

define('RSS20_DATE_FORMAT',  "D, d M Y H:i:s O");
            
# Fetch messages info 
if ($active_modules['News_Management']) {
    
$messages_info func_query_first("SELECT COUNT(*) as msg_count, MAX(send_date) AS last_send_time FROM $sql_tbl[newslists] AS nl, $sql_tbl[newsletter] AS n WHERE nl.listid = n.listid AND nl.avail='Y' AND nl.show_as_news='Y' ANd n.show_as_news = 'Y' ORDER BY n.send_date DESC");
}

if (!empty(
$messages_info) && $messages_info['last_send_time']) {
    
$last_mod_time date(RSS20_DATE_FORMAT$messages_info['last_send_time']);
    
$news_page_url $http_location.DIR_CUSTOMER."/news.php";
    
$messages func_query("SELECT n.newsid, n.subject, n.body, n.send_date FROM $sql_tbl[newslists] AS nl, $sql_tbl[newsletter] AS n WHERE nl.listid = n.listid AND nl.avail='Y' AND nl.show_as_news='Y' and n.show_as_news = 'Y' ORDER BY n.send_date DESC");
    
$items_code "";
    foreach (
$messages as $m) {
            
$pubDate date(RSS20_DATE_FORMAT$m['send_date']);
            
$m['title'] = htmlspecialchars($m['subject']);
            
$items_code .= <<<EX
        <item>
            <title>
{$m['subject']}</title>
            <description><![CDATA[
{$m['body']}]]></description>
            <link>
$news_page_url</link>
            <guid isPermaLink="false">
{$m['newsid']}@$news_page_url</guid>
            <pubDate>
$pubDate</pubDate>
        </item>

EX;
    }
} else {
    
$last_mod_time date(RSS20_DATE_FORMATtime());
}

# Channel header
$rss_channel['title'] = htmlspecialchars($rss_channel['title']);
$rss_channel['description'] = htmlspecialchars($rss_channel['description']);
$channel = <<<EX
<?xml version="1.0" encoding="{$rss_channel['encoding']}"?>
<rss version="2.0">
    <channel>
        <title>
{$rss_channel['title']}</title>
        <link>
{$rss_channel['link']}</link>
        <description>
{$rss_channel['description']}</description>
        <language>
{$rss_channel['language']}</language>
        <generator>X-Cart</generator>
        <pubDate>
$last_mod_time</pubDate>
        <lastBuildDate>
$last_mod_time</lastBuildDate>

EX;

if (!empty(
$items_code)) {
        
$channel .= $items_code;
        unset(
$items_code);
}

$channel .= <<<EX
    </channel>
</rss>

EX;

$channel_etag '"'.md5($channel).'"';

# Conditional GET logic [[[
# Check if the channel contents should be passed to client.
# We analyze HTTP response headers: If-Modified-Since, If-None-Match

$IMS_FLAG 0;
if (!empty(
$HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE'])) {
        if (
strtotime($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE'])  == strtotime($last_mod_time)) {
              
$IMS_FLAG 1;
        }
}

$INM_FLAG 0;
if (!empty(
$HTTP_SERVER_VARS['HTTP_IF_NONE_MATCH'])) {
        if (
$HTTP_SERVER_VARS['HTTP_IF_NONE_MATCH']  == $channel_etag) {
              
$INM_FLAG 1;
        }
}

$pass_channel_to_client = !($IMS_FLAG || $INM_FLAG);
# ]]]

if (!$pass_channel_to_client) {
    
header("HTTP/1.0 304 Not Modified");
    
header('ETag: ' $channel_etag);
} else {
    
# Output headers [[[
    
header("Content-Type: application/xml; charset=".$rss_channel['encoding']);
    
header("Content-length: " strlen($channel));
    
header("Last-Modified: " $last_mod_time);
    
header('ETag: ' $channel_etag);
    
# ]]]

    
echo $channel;
}

# vim600: set et sw=4 sts=4 ts=4 fdm=marker fmr=[[[,]]]:
?>
Reply With Quote
  #9  
Old 11-16-2007, 05:20 AM
 
Acquamarina Acquamarina is offline
 

X-Adept
  
Join Date: Aug 2006
Location: USA
Posts: 811
 

Default Re: Syndicate X-Cart news as RSS 2.0 Channel

Hi,

I added this to my site and generates the feed well but does not validate because I used a word in French. I changed the word but I am not sure how to update the feed as it still showing in the feed. Also, some validators aren't accepting the php format. Is there any way to change that to RSS extension? Any suggestions?

Thank you very much!
__________________
Vera B
4.4.5
CFLSystems.com mods, Kosmos eBay Integration, Feed Manager Pro, custom mods, BCSEngineering Mods, CDSEO PRO
Hosting by EWDHosting - The best home for your x-cart.
Reply With Quote
  #10  
Old 11-23-2007, 06:15 AM
 
zaa zaa is offline
 

X-Cart team
  
Join Date: Apr 2004
Location: Ulyanovsk, Russia
Posts: 125
 

Default Re: Syndicate X-Cart news as RSS 2.0 Channel

Quote:
Originally Posted by Acquamarina
Hi,

I added this to my site and generates the feed well but does not validate because I used a word in French. I changed the word but I am not sure how to update the feed as it still showing in the feed. Also, some validators aren't accepting the php format. Is there any way to change that to RSS extension? Any suggestions?

Thank you very much!

The feed is constructed dynamically, so actually you should see the changes right away. As for the French word, you should replace UTF-8 with actual encoding value. For example, you might need to replace

Code:
$rss_channel['encoding'] = 'UTF-8'; with $rss_channel['encoding'] = 'ISO-8859-1';

As for the RSS extension, if you are hosted on a server with Apache web server you may add a rewrite rule that will transparently rewrite feed.xml with feed.php
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 04:55 PM.

   

 
X-Cart forums © 2001-2018