Archive

Archive for the ‘CRE Loaded’ Category

Adding SMTP server support in CRE Loaded 6.2

November 21st, 2009 2 comments

Till version 6.2 cre loaded was only capable of sending emails using sendmail program using php mail() function. Some time it happens that our site is hosted on shared hosting where same server IP is shared between many sites. These sites may include site which send spam emails and in result the server IP get penalized by email servers and messages being sent from this IP are not delivered to recipients, or sent to junk/spam folders directly.

For a site which has to send email notifications and status update emails, this can be a nightmare. Due to this customer don’t feel confident and think the site as fake one. To avoid this situation we can use separate mail hosting services or servers which are not black list to ensure delivery to customer inbox.

Starting from cre loaded 6.3 we can tell which smtp server to be used to send emails. It is also possible to add this feature in old versions.

In this post I will guide you how to add smtp feature, but before start keep these in mind

  • None of the code is written by me so the code belongs to its respective owners
  • Backup your files and database for in case any thing goes wrong
  • The version I am using is 6.2 Pro, I think procedure will be same for simple and B2B version

What you will need

We need SMTP class library (includes/classes/class.smtp.php)available in version 6.3 and 6.4, I got it from 6.4.0 Pro, but i think it will be same for Community addition.
Copy the file includes/classes/class.smtp.php from version 6.3 or 6.4 to includes/classes/ folder. This will be used for sending emails from front end for admin area copy same file in admin/includes/classes/.
So two new files will be includes/classes/class.smtp.php and admin/includes/classes/class.smtp.php

Adding Required Configurations:
Add following configurations in your database, these will allow admins to do settings for SMTP server.

INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES ( 'SMTP Server Host Address', 'EMAIL_SMTP_HOST_SERVER', '', 'The fully qualified host name of the SMTP server.', '12', '10', '0000-00-00 00:00:00', '2009-06-16 20:09:42', '', '');


INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES ('SMTP Server EHLO / HELO Name', 'EMAIL_SMTP_HELO_SERVER', '', 'A name to send as part of the SMTP EHLO / HELO commands. The name is typically the hostname of the machine this web site runs on.', '12', '11', '0000-00-00 00:00:00', '2009-06-16 20:09:42', '', '');


INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES ('SMTP Server Port Number', 'EMAIL_SMTP_PORT_SERVER', '25', 'The SMTP server port number. Port number 25 is typically used by default.', '12', '12', '0000-00-00 00:00:00', '2009-06-16 20:09:42', '', '');


INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES ('SMTP Authentication Required', 'EMAIL_SMTP_ACTIVE_PASSWORD', 'true', 'Set to true when the SMTP Server requires password authentication.', '12', '13', '0000-00-00 00:00:00', '2009-06-16 20:09:42', '', 'tep_cfg_select_option(array(\'true\', \'false\'), ');


INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES ('SMTP Authentication Username', 'EMAIL_SMTP_USERNAME', '', 'The e-mail username sent to the server when SMTP password authentication is required.', '12', '14', '0000-00-00 00:00:00', '2009-06-16 20:09:42', '', '');


INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES ('SMTP Authentication Password', 'EMAIL_SMTP_PASSWORD', '', 'The e-mail password sent to the server when SMTP password authentication is required.', '12', '15', '0000-00-00 00:00:00', '2009-06-16 20:09:42', '', '');

Modifying files:
You will need to modify two files one for front and second for admin. These files will be includes/classes/email.php and admin/includes/classes/email.php

Now open includes/classes/email.php
Find

if (EMAIL_TRANSPORT == 'smtp') {
return mail($to_addr, $subject, $this->output, 'From: ' . $from . $this->lf . 'To: ' . $to . $this->lf . implode($this->lf, $this->headers) . $this->lf . implode($this->lf, $xtra_headers));

Replace line

return mail($to_addr, $subject, $this->output, 'From: ' . $from . $this->lf . 'To: ' . $to . $this->lf . implode($this->lf, $this->headers) . $this->lf . implode($this->lf, $xtra_headers));

With this code

include_once(DIR_WS_CLASSES . ‘class.smtp.php’);

// Build up the SMTP connection parameter list
$params['host'] = EMAIL_SMTP_HOST_SERVER; // The smtp server host/ip
$params['port'] = EMAIL_SMTP_PORT_SERVER; // The smtp server port
$params['helo'] = EMAIL_SMTP_HELO_SERVER; // helo/ehlo command string; typically your domain/hostname
$params['auth'] = EMAIL_SMTP_ACTIVE_PASSWORD; // Whether to use basic authentication or not
$params['user'] = EMAIL_SMTP_USERNAME; // Username for authentication
$params['pass'] = EMAIL_SMTP_PASSWORD; // Password for authentication

// Prepare the recipient names; there can be multiple recipients in the to_addr seperated by a comma.
// Create an array of the recipients and then strip off everything and just leave the internet style
// email address behind. For example: “MyCuteName <me@mydomain.com>” => “me@mydomain.com”
$recipients = explode(‘,’, $to_addr);
for ($i = 0; $i < count($recipients); $i++) {
$recipients[$i] = trim(preg_replace( ‘/(.*)<(.*)>(.*)/’, ‘$2′, $recipients[$i]));
}
$send_params['recipients'] = $recipients;

// Timestamp the message
$date = date(‘r’);

$send_params['headers'] = array_merge($this->headers, array(“From: $from”, “To: $to”, “Subject: $subject”, “Date: $date”));

// This is used as in the MAIL FROM: cmd
// It should end up as the Return-Path: header
$send_params['from'] = $from_addr;

// The body of the email message
$send_params['body'] = $this->output;

//Send the email via SMTP
return (is_object($smtp = smtp::connect($params)) AND $smtp->send($send_params));

For file admin/includes/classes/email.php do the same as above and after that
Find:

case (($text == true) && ($attachments == false) && ($html == false)):

Replace with

case (($text == true) && ($attachments == false)):

and thats it now go to admin area and update smtp settings in Configuration > Email Options. I am using this code in one of my sites so it should work if every thing is done as described.

Categories: CRE Loaded Tags:

Categories Breadcrumb not working, CRE Loaded Pro

November 1st, 2009 3 comments

I was amazed to see that Categories breadcrumb is not working http://demos.creloaded.com/creloaded_pro/index.php?cPath=3_10 on category pages. You can see proper cPath in url still the breadcrumb is missing. This happens on in CRE Loaded 6.4 PRO. Breadcrumb is not only important for visitors, it is also important for SEO aspect.

The issue is due to bug in “runtime override” code. The code is using $cPath_array variable which is not declared global in function. To fix this open file includes/runoverride/applicationtop/CDSlogic_applicationtop_breadcrumb.php and find line global $breadcrumb, $languages_id after the $languages_id variable add, $cPath_array. This will make cPath_array global and the breadcrumb will start working.

Categories: CRE Loaded Tags:

Installing “Output Queries Debug” in CRE Loaded 6.4 PCI

November 1st, 2009 No comments

Output Queries Debug is very useful contribution for osCommerce. This contribution captures each query used to construct a page and can be output if desired. This information can be very useful for developers working on CRE Loaded performance optimization. To see more details about the contribution please refer to this page.

In this post we will be installing on CRE Loaded PCI 6.4 PRO. We will be using Runtime Code Inclusion (RCI) feature for installing the contribution. For details about RCI please refer to CRE loaded forums or any where ever you can find.

It is always a good idea to backup your files before making any changes. Unless you feel comfortable do not make the changes on live site.

Step One: Changing tep_db_query function
Open file includes/functions/database.php and

Find:

if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
$page_name = $_SERVER['SCRIPT_FILENAME'];
$page_name = str_replace('\', '/', $page_name);
$page_name = str_replace('//', '/', $page_name);
$i = strrpos($page_name, '/');
$page_name = substr($page_name, $i+1);
error_log('QUERY - ' . $page_name . ':'. "\n" . $query . "\n", 3, DIR_FS_CATALOG . STORE_PAGE_PARSE_TIME_LOG);
$sql_start = microtime(true);
}

After above code Add following

// queries_debug-v1.7
$query_start = microtime();

After:

$result = mysql_query($query, $$link) or tep_db_error($query, mysql_errno(), mysql_error());

Add:

// start queries_debug-v1.7
global $debug;
if ((DISPLAY_QUERIES == 'true') || (DISPLAY_PAGE_PARSE_TIME == 'true')){
$_start = explode(' ', $query_start);
$_end = explode(' ', microtime());
$_time = number_format(($_end[1] + $_end[0]) - ($_start[1] + $_start[0]), 6);

$debug['QUERIES'][] = $query;
$debug['TIME'][] = $_time;
}
// end queries_debug-v1.7

Step Two:
Create a new php file debug_applicationbottom_bottom.php in /includes/runtime/applicationbottom/ and put following code in the created file

<?php
global $debug;
if (DISPLAY_PAGE_PARSE_TIME == ‘true’) {
$time_start = explode(‘ ‘, PAGE_PARSE_START_TIME);
$time_end = explode(‘ ‘, microtime());
$parse_time = number_format(($time_end[1] + $time_end[0] – ($time_start[1] + $time_start[0])), 3);
echo ‘<div align=”center”><span>’ . $parse_time . ‘ – ‘ . sizeof($debug['QUERIES']) . ‘</span></div>’;
if (DISPLAY_QUERIES == ‘true’) {
echo ‘<b>QUERY DEBUG:</b><pre>’;
print_r($debug);
echo ‘</pre><hr>’;
echo ‘<b>SESSION:</b><pre>’;
print_r($_SESSION);
echo ‘</pre><hr>’;
echo ‘<b>COOKIE:</b><pre>’;
print_r($_COOKIE);
echo ‘</pre><b>POST:</b><pre>’;
print_r($_POST);
echo ‘</pre><hr>’;
echo ‘<b>GET:</b><pre>’;
print_r($_GET);
echo ‘</pre>’;
} # END if request
}
unset($debug);
?>

Step Three: adding configuration
Run following sql statement on your database through phpmyadmin, command line or any MySQL other interface. This statement will allow you to turn on or off the queries through the admin panel:

INSERT INTO configuration ( configuration_id , configuration_title , configuration_key ,
configuration_value , configuration_description , configuration_group_id , sort_order ,
last_modified , date_added , use_function , set_function )
VALUES ( '', 'Display Database Queries', 'DISPLAY_QUERIES', 'true',
'Display COOKIE, SESSION, POST, and GET data in the footer', '10', '6', NOW( ) , NOW( ) ,
NULL , 'tep_cfg_select_option(array(''true'', ''false''),' );

And that’s it we are done with the installation. Browse to home page of your CRE Loaded installation to see if its working. You can turn on/off the queries information displayed at bottom of the page from admin » Logging » Display Database Queries menu.

Categories: CRE Loaded Tags:

SEO URLs addon for CRE Loaded

November 1st, 2009 2 comments

SEO url is a commercial addon for converting links to SEO Friendly format. Almost every cre loaded site requests to have seo friendly urls. In CRE loaded 6.4 pro the addon has become built in feature.

Over the time using this addons I realized a major issue regarding SEO. As you may know issue of duplicate content is major concern for every seo expert. The seo urls addon helps generating duplicate content :) , yes its true.

Consider a product posted in two or more categories, there will two different SEO friendly URLs which will be pointing to same content. For example

http://**/Main-cat-one-subcat-one/c1_21/p1/my-product/product_info.html
http://**/Other-main-cat-other-sub-cat/c2_30/p1/my-product/product_info.html

the two above urls point to same product same content. These links are generated from listing pages.

Even if there are no product listed in multiple categories still different pages like “specials” page can generate duplicate link for same product.

Due to this addon more urls are generated from “Buy Now” links which are like http://**/Main-cat-one-subcat-one/c1_21/p1/my-product/index.html?action=buy_now. These duplicate links are just killing for seo as search engine consider them separate links and expect different content.

How to fix: These issues and some more are fixable and have been fixed for many sites. If you like to get them fixed for your site then contact or post a commit.

Categories: CRE Loaded, SEO Tags:

CRE Loaded Block unwanted countries traffic by IP

October 31st, 2009 Comments off

One of site i worked on, was having a lot of crawler and normal visitor activities, from non targeted countries. For example it was having a lot of visitors and un friendly bots (crawlers) from India. This traffic was useless for the site because site was to serve Europe and US, still it was consuming a lot of processing and bandwidth.

The solution was to block all the traffic from such countries but could not find and extension to block specified countries from our site. Finally we decided to write a simple extension that can detect country of visitor and block the visitor if its country is in our block list.

The site was based on CRE Loaded so i thought it would be useful extension for other people who experiences similar issues. The extension is very simple and created using RCI, so it dose not get disturbed by any CRE Loaded updates.

The extension requires free country to IP database from MaxMind and its PHP API. These can be found on http://www.maxmind.com/app/geoip_country and http://geolite.maxmind.com/download/geoip/api/php/ respectively.

Installation of this extension is easy and include following steps

Step 1: Copy file GeoIP.dat (IP to country database) and geoip.inc (API) in includes/ directory under your installation.
Setp 2: Run following SQL queries on your database. This will add configuration to enable/disable this extension and will let you specify list of countries to block.

INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES ('Enable Block Countries', 'BLOCK_COUNTRIES_ENABLE', 'false', 'Block traffic and spiders from specific countries. by http://blog.wasimasif.com', '1', '999', NOW(), NOW(), '', 'tep_cfg_select_option(array(\'true\', \'false\'),') ;
INSERT INTO configuration (configuration_title, configuration_key, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES ('Blocked Countries List', 'BLOCK_COUNTRIES_LIST', 'Comma separated list of country codes to block traffic from. For example AL,AM will block all traffic from Albania and Armenia. By http://blog.wasimasif.com', '1', '1000', NOW(), NOW(), '', 'tep_cfg_textarea(') ;

Step 3: Create a new file blockcountry_applicationtop_bottom.php in includes/runtime/applicationtop/ folder and paste the following code in this file.

<?php
/**
* Block contries by http://blog.wasimasif.com/
* Blocks unwanted traffic on your site
* @since 2009-10-28
*/
if(BLOCK_COUNTRIES_ENABLE == 'true' && BLOCK_COUNTRIES_LIST != ''){ // check if block countries is enabled
if(!isset($_SESSION['cok']) || intval($_SESSION['cok']) == 0){ // We have not checked country yet
$ip_address = tep_get_ip_address(); // get IP
include(DIR_FS_INCLUDES."geoip.inc"); // include geoIP API
$gi = geoip_open(DIR_FS_INCLUDES."GeoIP.dat",GEOIP_MEMORY_CACHE); // open GeoIP database
$country_code = strtoupper(geoip_country_code_by_addr($gi, $ip_address)); // Get country code
geoip_close($gi); // Close the IP database

$blocked_countries = explode(‘,’,strtoupper(BLOCK_COUNTRIES_LIST));

for($i=0; $i < count($blocked_countries);$i++)
$blocked_countries[$i] = trim($blocked_countries[$i]); // avoid any trailing spaces etc

if($country_code != “” && in_array($country_code,$blocked_countries)){ // country code is in block list
header(‘HTTP/1.1 403 Forbidden’);
die(“<h1>Forbidden</h1>”);
}
else{
$_SESSION['cok'] = 1; // register this in session
}
}
}
// end block countries
?>

Now you are done with the installation. Now enable the extension and provide list of blocked country in Admin > Configuration > My Store. You have to specify a list of comma separated two latter country codes to block.

Use the code on your own risk no warranties what so ever is provided. The code is tested with CRE Loaded 6.4 Pro on linux but should work with 6.3.x and windows.

Categories: CRE Loaded Tags: