May 31

javascript – A simple javascript countdown timer

This is a simple but light weight javascript countdown timer,which can be integrated to your zen cart store by uploading the file to the jscript sub folder of your current zen cart template folder.

I name it as jscript_timer.php, so i can  put some php configure variable to the zen cart admin backend. if you dont’ want,you can rename it to jscript_timer.js.  This countdown timer countdown 4 days and it will start over again.so no bother to admin setting once and once again.(:

Source code    
<?php
$path = '/' . DIR_WS_TEMPLATE . 'jscript/';
$img = $path . 'timer.png';
?>
<script language="javascript" type="text/javascript"><!--
var present;
var future;
var tseconds;
var seconds;
var minutes;
var hours;
var days;
var limit;
limit =4;
// ID=setInterval("countdown();", 1000);
 
function countdown() {
	present = new Date();
	present = present.getTime();
	future = new Date("MAY 27, 2015 11:59:59");
 
	tseconds = (future - present)  / 1000;
 
	days = tseconds /24/60/60;
	days = Math.floor(days);
	odays = days;
	days = days%limit;
	tseconds = tseconds - (odays - days) * 24 * 60 * 60 - (days * 24 * 60 * 60);
 
	hours = tseconds /60/60;
	hours = Math.floor(hours);
	tseconds = tseconds - (hours * 60 * 60);
 
	minutes = tseconds /60;
	minutes = Math.floor(minutes);
	tseconds = tseconds - (minutes * 60);
 
	seconds = tseconds;
	seconds = Math.floor(seconds);
	htmlstr = '<span style="font-weight:bold;font-size:16px">' + days + '</span> days <span style="font-weight:bold;font-size:12px">' +  hours + ':' + minutes + ':' + seconds + '</span>  Left';
	document.getElementById('timerdiv').innerHTML = htmlstr;
	//console.info(days + ' days ' + hours + ' hours ' + minutes + ' minutes ' + seconds + ' seconds');
}
window.onload = function () {
    ID=setInterval("countdown();", 1000);
};
//--></script>

Feel free to adapt it to fit your need!!

 

Apr 29

zen cart — one way to override function in the folder of includes/functions

zen cart don’t have a build in way to override all functions defined in the folder of includes/functions. PHP will throw out an error of “duplicate declare is not allowed”. well, we know that zen cart have built in mechanism to  override all the files in the includes/init_includes folder. And all the files in the includes/functions folder are loaded via includes/init_includes/init_general_funcs.php. let’s take a look at the php source:

Source code    
<?php
/**
 * load the system wide functions
 * see {@link  http://www.zen-cart.com/wiki/index.php/Developers_API_Tutorials#InitSystem wikitutorials} for more details.
 *
 * @package initSystem
 * @copyright Copyright 2003-2005 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: init_general_funcs.php 2845 2006-01-13 06:49:15Z drbyte $
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}
/**
 * General Functions
 */
require(DIR_WS_FUNCTIONS . 'functions_general.php');
/**
 * html_output functions (href_links, input types etc)
 */
require(DIR_WS_FUNCTIONS . 'html_output.php');
/**
 * basic email functions
 */
require(DIR_WS_FUNCTIONS . 'functions_email.php');
/**
 * EZ-Pages functions
 */
require(DIR_WS_FUNCTIONS . 'functions_ezpages.php');
/**
 * User Defined Functions
 */
include(DIR_WS_MODULES . 'extra_functions.php');
?>

 

To override the includes/functions/functions_general.php, we need make a change of this file.so

First,make a copy of includes/init_includes/init_general_funcs.php to includes/init_includes/overrides/init_general_funcs.php

Second, alter the includes/init_includes/overrides/init_general_funcs.php as below

/**
 * General Functions
 */
require(DIR_WS_FUNCTIONS . 'functions_general.php');

To

/**
 * General Functions
 */
require(DIR_WS_FUNCTIONS . '/overrides/functions_general.php');

Then you can do whatever changes as you want to any functions defined in that file.

if you want to overrides all files in includes/functions folder,just like zen cart build in override mechannism,the you can replace the content of includes/init_includes/overrides/init_general_funcs.php
as below:

Source code    
if ($za_dir = @dir(DIR_WS_INCLUDES . 'includes/functions/overrides')) {
  while ($zv_file = $za_dir->read()) {
    if (preg_match('/\.php$/', $zv_file) > 0) {
      include(DIR_WS_INCLUDES . 'includes/functions/overrides' . $zv_file);
    }
  }
  $za_dir->close();
}

 

 

 

 

 

 

Apr 23

zen cart — adapt zen cart to switch template based upon parameter

well,as a zen cart developer,you may have lots of zen cart template. Don’t you bother with  zen cart installation. Though you can make a batch script to generate mass zen cart websites, it will take you a lot of disk space and make you headache while searching for a special zen cart template.

so why not keep all the zen cart template in a single zen cart website.when you need to test some special zen cart template,specify a parameter with the value of template name and zen cart will take the parameter as the current template,no bother to do zen cart admin setting once and once again.

so how? the adoption of the zen cart core code is simple,as below:

Copy includes/init_includes/init_templates.php to includes/init_includes/overrides/init_templates.php,change the code like below:

$sql = “select template_dir
from ” . TABLE_TEMPLATE_SELECT . ”
where template_language = ‘” . $_SESSION['languages_id'] . “‘”;
$template_query = $db->Execute($sql);
if ($template_query->RecordCount() > 0) {
$template_dir = $template_query->fields['template_dir'];
}

// customized by georgezheng
if (isset($_GET['t'])  && $_GET['t'] != ” ) {
$temp = trim($_GET['t']);
$_SESSION['t'] = $temp;
} elseif ( isset($_SESSION['t']) &&  $_SESSION['t'] != ” ) {
$temp = $_SESSION['t'];
} else {
$temp = ”;
}
//end

if ( $temp != ” && is_dir(DIR_WS_TEMPLATES . $temp) ) {
$template_dir = $temp;
}

save,then browse your zen cart website with url like this http://www.abcdomain.com/?t=temp1.zen cart will looking for the template temp1,if exists temp1 will be set as current template for this session.

Mar 27

zen cart — How to determine if current page is HomePage?

sometims,you need to know if the current page is homepage. for example,you don’t want to show some special content in the homepage,then you need to know whether the current page is homepage.

From zen cart source code,i got some idea,see it below

./includes/init_includes/init_category_path.php:47:

Source code    
$this_is_home_page = ($current_page=='index' && (!isset($_GET['cPath'])) && (!isset($_GET['manufacturers_id'])) && (!isset($_GET['typefilter'])) );

so we can get the result from $this_is_home_page.  this is a global varaible,so you can access it if it’s initiated.

 

Mar 25

zen cart — How to Add a Sidebox to Zen Cart

One of the best way to customize Zen Cart is to create a new Sidebox.A Zen Cart sidebox is what displays various contents in the left or right columns of your Zen Cart store. By default numerous sideboxes will show in either the left or right column of a Zen Cart online store. The followings are some of the most popular zen cart sidebox — The categories sidebox, the search sidebox, and the information sidebox. Zen cart comes with some builtin sidebox which could be a good tutor to start to learn how to add a new sidebox to Zen Cart.

A sidebox consists of three files which are located in the includes directory:

  1. modules/sideboxes/YOUR_TEMPLATE/new_sidebox.php
  2. languages/english/extra_definitions/YOUR_TEMPLATE/new_sidebox_defines.php
  3. templates/YOUR_TEMPLATE/sideboxes/tpl_new_sidebox.php

The ‘new’ up there should be replaced with your own sidebox name.

includes/modules/sideboxes/YOUR_TEMPLATE/new_sidebox.php

Source code    
<?php
 $show_new_sidebox = true;
 if ($show_new_sidebox == true){
   require($template->get_template_dir('tpl_new_sidebox.php',DIR_WS_TEMPLATE,
   $current_page_base,'sideboxes'). '/tpl_new_sidebox.php');
   $title =  BOX_HEADING_NEW_SIDEBOX;
   //do some db query and other processing here
 
   $left_corner = false;
   $right_corner = false;
   $right_arrow = false;
   require($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE,
   $current_page_base,'common') . '/' . $column_box_default);
 }
?>

includes/languages/english/extra_definitions/YOUR_TEMPLATE/new_sidebox_defines.php

Source code    
<?php
  define('BOX_HEADING_NEW_SIDEBOX', 'Gallery');
?>

includes/templates/YOUR_TEMPLATE/sideboxes/tpl_new_sidebox.php

Source code    
<?php
 $content = <<< End_Of_Quote
  Enter your sidebox content here
 End_Of_Quote;
?>
Mar 23

zen cart — how to get the url of the current page

i want to set a anchor in all page.so when the user click on the anchor,it will bring user back to the head of the current page.i just don’t want to call too much javascript code.

Source code    
<a href="#backhome">Back to top</a>

The code up there not work.As the browser will fix the anchor url  which cut the current url from last slash.for example

http://www.abcdomain.com/product-one_p_29.html   => http://www.abcdomain.com/#backhome

http://www.abcdomain.com/category1/product-one_p_29.html => http://www.abcdomain.com/category1/#backhome

$_SERVER['REQUEST_URI'] stores the url from the root, see example below

http://www.abcdomain.com/product-one_p_29.html => product-one_p_29.html
http://www.abcdomain.com/category1/product-one_p_29.html  =>
category1/product-one_p_29.html

so the anchor snippet code can be adapter to the following code

Source code    
<a href="<?php echo $_SERVER['REQUEST_URI']?>#backhome">Back to top</a>

 

 

Sep 07

zen cart — all zen cart url with currency parameter will be redirected to home page

i just found that if any url in a zen cart store containing currency=value,then it will be redirected to zen cart website home page.For example,

http://www.abcdomain.com/xxxxxxxxxxx/xxxxxxxxx/?currency=EUR

This url will be redirected to http://www.abcdomain.com/,it’s a 302 redirect.

is this a zen cart bug?

From the code in this file:/includes/init_includes/init_currencies.php

Source code    
<?php
/**
 * initialise currencies
 * see {@link  http://www.zen-cart.com/wiki/index.php/Developers_API_Tutorials#InitSystem wikitutorials} for more details.
 *
 * @package initSystem
 * @copyright Copyright 2003-2007 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: init_currencies.php 6300 2007-05-11 15:49:41Z drbyte $
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}
 
// If no currency is set, use appropriate default
if (!isset($_SESSION['currency']) && !isset($_GET['currency']) ) $_SESSION['currency'] = DEFAULT_CURRENCY;
 
// Validate selected new currency, if any. Is false if valid not found.
$new_currency = (isset($_GET['currency'])) ? zen_currency_exists($_GET['currency']) : zen_currency_exists($_SESSION['currency']);
 
// Validate language-currency and default-currency if relevant. Is false if valid not found.
if ($new_currency == false || isset($_GET['language'])) $new_currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? zen_currency_exists(LANGUAGE_CURRENCY) : $new_currency;
 
// Final check -- if selected currency is bad and the "default" is bad, default to the first-found currency in order of exch rate.
if ($new_currency == false) $new_currency = zen_currency_exists(DEFAULT_CURRENCY, true);
//echo '<br />NEW = ' . $new_currency . '<br />';
 
// Now apply currency update
if (
   // Has new currency been selected?
  (isset($_GET['currency'])) ||
 
  // Does language change require currency update?
  (isset($_GET['language']) && USE_DEFAULT_LANGUAGE_CURRENCY == 'true' && LANGUAGE_CURRENCY != $_SESSION['currency']  )
 
) {
  $_SESSION['currency'] = $new_currency;
  // redraw the page without the currency/language info in the URL
  if (isset($_GET['currency']) || isset($_GET['language'])) zen_redirect(zen_href_link($current_page_base, zen_get_all_get_params(array('currency','language'))));
}
?>

the zen_redirect make this happen.

Aug 18

zen cart — recover zen cart database from mysql data folder

One of my server crashed last week. They do a hard disk rescue and i only get a copy of the mysql data folder(the physical data file of all databases).The new server is ready for use,with the mysql and cpanel updated.so i got no lucky to recover with copy the mysql folder back to the new mysql data folder.it only show the database without any table.

i found i do have a mysqldump backup on 2012 -05 -24.but the lates data(2012-08-09) was stored as mysql physical data file,not sql.how to recover all the zen cart databases with the latest data?is it possible.

There is two way to try:

The first one is to install anthoer copy of mysql.it must be same version as the one before system crashed.and same /etc/my.cnf. The you can turn off the currently running mysql ,copy the the mysql data folder to the data folder of the the old copy mysql.Start the mysql and mysqldump to backup all the zen cart database. The switch mysql to the latest mysql,import all databases;

Sometimes it’s impossible to achive the last version of mysql with same configuration.The what can we do?You can mysqldump the database schema(only structure) from a zen cart database with following command:

mysqldump –no-data zencartdb > onlyschema.sql -u root -p’password’

Then create all the databases you want to recover and import the zen cart database schema to every zen cart database.

mysqladmin create database1 -u root -p’password’

mysql database1 < onlyschema.sql -u root -p’password’

Now turn of mysql dameon process to unlock all databases and tables(if exist).copy the data folder bakup to the mysql data folder.

/etc/init.d/mysqld stop
cp -Rf  /home/bak/mysql/*  /var/lib/mysql/

And all is done. However,keep in mind if you use INNODB storage engine in your old mysql database,then the recovery may be more complicated.

Aug 10

zen cart — how to turn of ezPages header links bar

if you don’t want to ezPages links to show on the header bar or footer bar?how to remove or disable them?

In the admin control panel go to Configuration –> EZ-Pages Settings to turn them off.Click on EZ-Pages Display Status -HeaderBar and change the setting to 0.This will turn off the link bar in the header.
The same applies for the Footer Bar and Side box links!

Aug 04

zen cart – .htaccess file to protect images,cache,bmz_cache folder from attact

To compatible with most 3rd application,most server has a common configuration.This lead to some potential security problem.Zen car allow globally read and write to its images,bmz_cache,cache directory.

The following .htaccess config will help to disable the index list of image directory, block any attemp to running script from this directory.you can put this .htaccess in the zen cart images directory for better security.

Source code    
###############################

# deny *everything*
<FilesMatch ".*">
  Order Allow,Deny
  Deny from all
</FilesMatch>
 
# but now allow just *certain* necessary files:
<FilesMatch ".*\.(jpe?g|JPE?G|gif|GIF|png|PNG|swf|SWF)$" >
  Order Allow,Deny
  Allow from all
</FilesMatch>
 
OPTIONS -Indexes -ExecCGI

The .htaccess above blocks direct HTTP requests to all filetypes in this directory recursively, except certain approved exceptions(image and other approved static file). It also prevents the ability of any scripts to run. No type of script, be it PHP, PERL or whatever, can normally be executed if ExecCGI is disabled.This Will also prevent people from seeing what is in the dir. and any sub-directories. We’d better put this file to both images and bmz_image directory.

For the cache directory,we need to block running script and disalbe auto index.so the .htaccess can be:

Source code    
# deny *everything*
<FilesMatch ".*">
  Order Allow,Deny
  Deny from all
</FilesMatch>
OPTIONS -Indexes -ExecCGI