-3

Okay so im reworking the products_new.php page in oscommerce to be output as an rss page, problem is the date formatting is wrong, currently it outputs as such

Wednesday, 02. October 2002 Using:

tep_date_long($products_new['products_date_added'])

it needs to be in this format: Wed, 02 Oct 2002 15:00:00 +0200 the php for this is

("D, d M Y H:i:s O", time())

but im not sure how to implement it or change the exisiting code

any ideas?

    echo '<?xml version="1.0" encoding="ISO-8859-1"?>
    <rss version="2.0">
    <channel>
    <link>http://www.primedelux.com</link>
    <language>en-uk</language>
    <copyright>Copyright (C) 2011 http://www.primedelux.com</copyright>
    <pubDate>' . date("D, d M Y H:i:s O", time()) . '</pubDate>';
    ?>
    <?php
      $products_new_array = array();

     $products_new_query_raw = "select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added DESC, pd.products_name";

      $products_new_split = new splitPageResults($products_new_query_raw, MAX_DISPLAY_PRODUCTS_NEW); ?>

    <?php
      if ($products_new_split->number_of_rows > 0) {
        $products_new_query = tep_db_query($products_new_split->sql_query);
        while ($products_new = tep_db_fetch_array($products_new_query)) {
          if ($new_price = tep_get_products_special_price($products_new['products_id'])) {
            $products_price = '<s>' . $currencies->display_price($products_new['products_price'], tep_get_tax_rate($products_new['products_tax_class_id'])) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($products_new['products_tax_class_id'])) . '</span>';
          } else {
            $products_price = $currencies->display_price($products_new['products_price'], tep_get_tax_rate($products_new['products_tax_class_id']));
          }
    ?>
    <?php
    echo '<item>';
    echo '<title>' . $products_new['products_name'] . '</title>';
    echo '<description><![CDATA[' . tep_image('http://www.primedelux.com/images/' . $products_new['products_image']) . ' ]]>' . $products_new['products_name'] . '</description>';


    echo '<link>' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '</link>';
    echo '<guid>' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '</guid>';
    echo '<pubDate>' . tep_date_long($products_new['products_date_added']) . '</pubDate>';
    echo '</item>';
    ?>
    <?php
        }
      } 
    ?>
    <?php echo '</urlset>';?>
    <?php echo '</channel>';?>
    <?php echo '</rss>';?>

tep_date_long below:

// Output a raw date string in the selected locale date format
// $raw_date needs to be in this format: YYYY-MM-DD HH:MM:SS
function tep_date_long($raw_date) {
if ( ($raw_date == '0000-00-00 00:00:00') || ($raw_date == '') ) return false;

$year = (int)substr($raw_date, 0, 4);
$month = (int)substr($raw_date, 5, 2);
$day = (int)substr($raw_date, 8, 2);
$hour = (int)substr($raw_date, 11, 2);
$minute = (int)substr($raw_date, 14, 2);
$second = (int)substr($raw_date, 17, 2);

return strftime(DATE_FORMAT_LONG, mktime($hour,$minute,$second,$month,$day,$year));

}

Brad
  • 5
  • 3

1 Answers1

1

Replaces:

return strftime(DATE_FORMAT_LONG, mktime($hour,$minute,$second,$month,$day,$year));

with:

$time= mktime($hour,$minute,$second,$month,$day,$year);
$x= strftime("%a, %d %b %Y %H:%M:%S",$time);
if($x){
    return $x;
}else{
    return date("D, d M Y H:i:s O", $time);
}

strftime does not accept the same settings in Windows and Linux, the solution presented is a simplification, but in the manual find the right information to your environment.

Alfonso Rubalcava
  • 2,237
  • 17
  • 26