X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Syndicate X-Cart news as RSS 2.0 Channel (https://forum.x-cart.com/showthread.php?t=19661)

zaa 02-01-2006 11:32 AM

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.

markwhoo 02-17-2006 10:25 AM

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.

Abdul 04-18-2006 07:14 PM

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

TelaFirma 04-19-2006 06:30 AM

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

MallRomania 04-23-2006 06:44 AM

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

Pilnik 08-06-2007 04:14 PM

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?

alinush 08-26-2007 11:08 AM

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.

zaa 09-10-2007 06:24 AM

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=[[[,]]]:
?>


Acquamarina 11-16-2007 05:20 AM

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!

zaa 11-23-2007 06:15 AM

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


All times are GMT -8. The time now is 05:00 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.