Friday, 29 May 2009

HOWTO[zen-cart]: disable random on homepage

At beginning.
Copy featured_products.php / new_products.php from /includes/modules/ to /includes/modules/YOURTEMPLATE, then start to edit it.

1. append "order by featured_sort_id DESC" to the two select statements

2. change ExecuteRandomMulti() to Execute()

3. change MoveNextRandom() to MoveNext()

Tuesday, 26 May 2009

The procedure of Zen-cart display home page

1) tpl_main_page.php

2) $body_code is defined in /includes/templates/template_default/common/main_template_vars.php
Here, firstly check whether it's overridden or not by the current template. If not (/not exist overridden main_template_vars.php, then load the default tpl_SOME_PAGE_default.php)
3) If overridden, in the zen-cart pages system, /includes/modules/pages/index/main_template_vars.php defines which tpl file should be loaded to display the home page.
  • tpl_index_categories.php // $category_depth=='nested' 有子分类
  • tpl_index_product_list.php // $category_depth=='products' || zen_check_url_get_terms() 列出所有
  • tpl_index_default.php // the default tpl_SOME_PAGE_default.php 主页默认内容

HOWTO: Add css for IE within zen-cart

1) Prepare a css file for IE, called ie7.css, located in /includes/templates/template_default/my

2) Add the following codes:
echo '<!--[if lte IE 7]><link rel="stylesheet" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'my') . '/ie7.css" />'."\n".'<![endif]-->';

around the following codes in /includes/templates/template_default/common/html_header.php

 * load all template-specific stylesheets, named like "style*.css", alphabetically


  $directory_array = $template->get_template_part($template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css'), '/^style/', '.css');

  while(list ($key, $value) = each($directory_array)) {

    echo '<link rel="stylesheet" type="text/css" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . $value . '" />'."\n";


HOWTO: The Zen Cart Execution Process

Zen Cart, like most open-source code, is a largly undocumented.
Luckily for us, it also has a habit of mixing in much of it's
program/application logic with it's actual HTML design, so it's not
only undocumented, it's also hard to browse the HTML code. To top it
off, it also has a dynamic template loader, which means that the
program logic and HTML templates could be in any one of four different
directories. Also undocumented, and of dubious usefullness.

The result is that it's not only difficult to browse through the
program logic and HTML code, but you often don't even know which files
are going to get loaded.

This document is an attempt to sort through the overarching structure of how Zen Cart tends to work.

index.php steps:

Here's where all of action begins.
  1. it loads 'includes/application_top.php'
  2. if $main_page isn't set, it gets set to 'index'
  3. if the directory 'includes/modules/pages/$main_page' doesn't exist, $main_page gets set to 'index'
  4. it loads all of the files starting with 'header_php' in 'includes/modules/pages/$main_page'
  5. now it loads 'html_header.php' from the first first place it finds it from the following directories
    1. includes/templates/mytemplate/$main_page/
    2. includes/templates/template_default/$main_page/
    3. includes/templates/mytemplate/common/
    4. includes/templates/template_default/common/

  6. now it does the same thing for finding and loading 'main_template_vars.php'
  7. now it does the same thing for finding and loading 'tpl_main_page.php'
  8. Finally it displays the '</html>' tag. Why display it here when the '<html>' tag is displayed somewhere else? Who knows.

application_top.php steps:

This file will load in all of general definitions used site-wide,
initialize some site-wide classes ($template, $db) and do other general

html_header.php steps:

The default html_header.php file will simply create all of the HTML up to the </head> tag
It loads 'includes/modules/meta_tags.php', which uses a bloated switch statement to figure out what the site's title, meta-keywords, and meta-description should be.
It tries to find the css directory, and loads in it all stylesheets that begin with 'style' and end with '.css'
It does the same thing for the jscript directory, and tries to load all files that begin with 'jscript_' and end with '.js'

main_template_vars.php steps:

it simply sets $body_code to the first of:
  1. includes/modules/pages/$main_page/main_template_vars.php
  2. includes/templates/mytemplate/$main_page/tpl_{$main_page}_default.php
  3. includes/templates/template_default/$main_page/tpl_{$main_page}_default.php
  4. includes/templates/mytemplate/templates/tpl_{$main_page}_default.php
  5. includes/templates/template_default/templates/tpl_{$main_page}_default.php

that's it.

tpl_main_page.php steps:

this file lays out the basic page.
  1. <body>
  2. loads the 'includes/modules/header.php' file
  3. if the left column is enabled, it loads 'includes/modules/column_left.php'
  4. it loads the file set in $body_code
  5. if the right column is enabled, it loads 'includes/modules/column_right.php'
  6. loads 'includes/modules/footer.php'
  7. </body>

includes/modules/pages/$main_page/main_template_vars.php steps:

is where the meat of the actual content if loaded and displayed.
it typically does all of the program logic first, sets all of the
necessary variables, and then loads the template file. As usual, the
template file is loaded from the first of the following:
  1. includes/templates/mytemplate/$main_page/
  2. includes/templates/template_default/$main_page/
  3. includes/templates/mytemplate/templates/
  4. includes/templates/template_default/templates/

The standard is that the template file will be named 'tpl_SOMENAME.php'. Note that it doesn't end with '_default.php'. The undocumented naming convention is that files that end with '_default.php' are files that get loaded with it can't find the 'includes/modules/pages/$main_page/main_template_vars.php' file.

tpl_{$main_page}_default.php steps:

If it doesn't find the
above file and it instead finds a tpl_*_default.php file, then it means
that all of the program logic and variables will be mixed up with the
actual displayed HTML code. In Zen-Cart's defense, this generally means
that there's not a lot of program logic to be had here, hardly any
really, but it's still damn annoying to be mixing the program logic
with design. No sir, I don't like it one bit.

Future Updates

Eventually this document will also cover the process by which the program loads in the language files, such as "english.php" and the content files like "privacy.php" and "conditions.php."
The Zen Cart creators actually created these files with the idea that
they would be a part of your custom template, which is a clear
violation of the content/design seperation.

This document will also cover sideboxes (which requires a whole
nother custom template directory). As an interesting sidenote, when you
switch to a new template, all of the sideboxes get turned off. The
level of user-unfriendliness of Zen Cart is amazing to me sometimes.

This article is from:

Saturday, 16 May 2009

HOWTO: [MAC] Move User to a different partition

Move User to a different partition

As we have hopefully set up a separate partition for our private data, here’s the bash-way of moving a home. (based on this article)

  1. in 'Disk Utility' to setup a new partition with 'Mac OS Extended (Journaled)' format, I call it 'home'.
  2. copy the whole home to your new partition:

    # sudo su -
    # cp -Rp /Users/username /Volumes/username
  3. Now we use Directory Services which can be accessed by dscl (Directory Services Command Line):

    # sudo su -
    # dscl localhost
    > cd /Local/Default/Users
    > change username dsAttrTypeNative:home /Users/username /Volumes/home/username> exit

Reboot, verify if your user data is at the new spot and then delete it from the old spot (/Users/username).

Wednesday, 13 May 2009

HOWTO: hide 隐藏 SHOPEX footer 'powered by shopex'

Shopex use zend encoder to protect their commercial product. To run it, the 'zend-optimiser' is needed for decoding. Some web servers do not provide this module, such as ONE.COM. Therefore, to remove this 'footer' slogan, you must have their license the override the encoded php file.

Here is a hack to remove this 'powered by shopex' from footer, using 'mootools', which is coming with shopex installation automatically.

  1. go to /themes/THEME NAME/block/footer.html.
    Use '<div id="footer_remove">' and '</div>' to surround the '<{foot}>'
  2. go to /themes/THEME NAME/block/header.html.
    Add the following javascript after '<{head}>'

    <script type="text/javascript">

    window.addEvent('domready', function() {

    var fa=$('footer_remove').getElements('a[href^=]');

    fa.setStyle('display', 'none');

    var fb=fa.getNext('span');

    fb.setStyle('display', 'none');});




Tuesday, 12 May 2009

HOWTO[mac]: php.ini for both xdebug and zenddebugger in both Eclipse and M(L)AMP

Note: Either zenddebugger or xdebug is not included by default, (all-in-one PDT saying zenddebugger is included), You'd better check and install from software update in Eclipse. can be extract from the dmg file of Komodo .
zenddebugger: from zend or pdt (issued from zend), or

Note: Sometime, when the debugger is changed, the xdebug will not work any more on that project. Copy all the files into a new php project, it will work fine. This seems that the some of the project properties are changed during debuger is changed. (so far, don't know which modified property cause this issue). Refactor, such as rename, the project name will fix it.

The content in the end of php.ini


;----------------------- to be removed; it never runs well with this line


; Sometime, to enable Zend Debugger, Xdebug need to be disabled in php.ini; vice versa.


Monday, 4 May 2009






男儿自立 必须有倔强之气



  • 男儿自立,必须有倔强之气。

曾 国藩的倔强性格,在他最初出来带兵的时候表现得最为突出。他是以在籍侍郎的身份出来带兵的,没有地盘,无粮饷,事事仰给于人。偏偏曾国藩又是勇于任事之 人,因而与地方官员势同水火,屡屡发生冲突。加上初期与太平军作战屡战屡败,更是使他的处境雪上加霜。然而在与官场政敌和与太平天国的双重博斗中,他却养 成了一种咬牙立志、不肯认输的脾气。他自己将之称之为“打脱牙,和血吞”的“挺”字功夫。他曾经夫子自道说:





  • 倔强并不是刚愎自用



担 当大事,全在于明、强这两个字。所有的事,没有志气和刚强都是无法成功的。即使是修身齐家,也必须以明强为根本。“难禁风浪”这四个字说得很好,我把它再 送给你。自古以来,豪杰之士都以这四个字为大忌。我家祖父教人,也以“懦弱无刚”四个字为大耻。所以男儿自立于世,一定要有倔强之气。

  • “强”字须从“明”字做出




  • 看清问题之后要坚持到底



  • 天地之道,刚柔互用,不可偏废




曾国藩的为官之道,说白了,就是一种智慧。而这种智慧,主要是来自于中国传 统文化。曾国藩确实是一个悟透了中国文化的人,他的为人行事,也无不体现出中国文化的影响。他的以天下为己任,明显体现出儒生的进取精神;他的“花未全开 月未圆”、“晚场善退”,明显体现出道家的影响;他的治乱世用重典,学的是所谓的“申商之术”,他的俭以奉身、勤以治事,则明显体现出的是墨家的影响。 儒、道、法、墨四家的思想,在曾国藩身上都得到了充分的体现。

从文化的角度来说,曾国藩就是传统文化的化身。他非常善于将性理之学与经世致用结合贯通,他讲究人生理想, 讲求精神境界,讲求道德修养与自我完善,他的反省内求,日新又新,磨砺意志,勤俭刻苦,力戒虚骄,以恒为本等修身原则,在很大程度上体现了中华民族的优秀 美德。他以一介儒生,居然将燃烧了大半个中国的太平天国革命的烈火给扑灭了下去,这其中自然也有他成功的经验。曾国藩是一个理学家,他有深厚的传统文化底 蕴,但又绝对不是一个书呆子。毛泽东曾经说:“吾于近人,独服曾国藩。观其收拾洪杨一役,完美无缺,设使易以他人,岂能若是?”陈毅元帅也说过:“曾国藩 用兵很有一套,在军事上很值得研究。”其实何止是军事,曾国藩为官一生,他的“以天下为己任”的追求(当然他的“天下”毕竟是清王朝的“天下”),他的忧 患意识,他的打脱牙和血吞的刚毅精神,他对子弟、子女的教育方法,他在逆境之中所表现出来的政治智慧,都是很值得研究的。尤其是曾国藩是一个很善于概括的 人,他在不经意中留下的许多话,充满了哲理性,可以说既是他为官一生的经验总结,也体现了传统文化的深厚之所在。这些话,完全是可以当作格言来读的。毛泽 东在论述如何继承传统时提出了一条基本的原则,就是“取其精华,弃其糟粕”。对于曾国藩,我们同样可以采取这样的方法。

曾国藩是一个活生 生的人,他有他的局限,他有他的缺点。他的彷徨,他的郁闷,他的内心矛盾,他的焦虑紧张,都与普通人没有什么区别。他三次自杀,他屡战屡败,他是在不他断 地与自我作战的历程中一步步地完成他的“功业”的。他的成功,从根本上来说,还是出于那坚韧不拔的精神。梁启超在评价曾国藩时曾有过一段非常精譬的话。我 们就以这段话,来为我们的这个专题打一个结。梁启超说:

曾国藩并没有超群绝伦的才华。在当时的著名人物中,他可以说是最不聪明的一个。他 的一生,也一直在逆境之中,然而他立德、立功、立言,达到了古人所说的三不朽的境界,他的成就震古烁今,没有一个人能跟他,这是什么原因呢?他一生得力的 地方,在于立志自拔于流俗,而困而知,而勉而行,历尽百千险阻而不屈服;他不求近效,铢积寸累,受之以虚,将之以勤,植之以刚,贞之以恒,帅之以诚,勇猛 精进,坚苦卓绝,如此而已!如此而已!

My photo
London, United Kingdom

Facebook & Twitter