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
++++++++++++++
require($body_code);
----------------------

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
stuff.

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:

this
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: http://lifefeed.net/zencart/program_process.php

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^=http://store.shopex.cn/rating]');

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



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

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

    });



    </script>



    ================

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.

xdebug.so: can be extract from the dmg file of Komodo .
zenddebugger: from zend or pdt (issued from zend), or http://downloads.zend.com/pdt/server-debugger/

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

;========================================
[Zend]
zend_optimizer.optimization_level=15
zend_extension_manager.optimizer=/Applications/MAMP/bin/php5/zend/lib/Optimizer-3.3.3
zend_optimizer.version=3.3.3

;----------------------- to be removed; it never runs well with this line
;zend_extension=/Applications/MAMP/bin/php5/zend/lib/ZendExtensionManager.so
;-----------------------

[ZendDebugger]
zend_extension=/Applications/MAMP/bin/php5/zend/lib/ZendDebugger.so

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



[xdebug]
zend_extension=/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20050922/xdebug.so
;xdebug.file_link_format="txmt://open?url=file://%f&line=%1"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.idekey=

Monday, 4 May 2009

曾国藩的修身艺术-男儿自立,必须有倔强之气

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

少年当有狂者进取之趣

从砥砺自己的品性开始



性格决定命运,抱负决定成就,良好的品性是成功的前提。在优秀的领导者身上,我们总是能发现许多优秀的特质。但是这个世界上并没有天生的领导。这些特质无一不是从修养中来的。自我修养,是领导者走向成功的起点。早年的曾国藩同平常人一样,也有很多缺点,然而他凭借着自己的修身工夫,确立了良好的品格。他的成功,在很大程度上取决于他的修身艺术。那么,曾国藩在修身上有哪些值得我们借鉴的地方呢?曾国藩修身艺术,其实无非三条:第一,倔强;第二,进取;第三,有恒。




男儿自立 必须有倔强之气



曾国藩的性格,受他的祖父曾玉屏和他的母亲江氏的影响很大。曾玉屏常对家人说的一句话,就是“以懦弱无刚四字为大耻”。这句话对曾国藩影响很大,做了两江总督之后,他还以祖父的这句话教自己的弟弟,并认为“男儿自立,必须有倔强之气”。他说:

“倔强”二字,却不可少。功业文章,教需要有这两个字贯注于其中,否则柔靡不能成一事。孟子所说的“至刚”,孔子所说的“贞固”,都是从“倔强”两个字中做出。我们兄弟受母亲的性格影响,好处也正在于倔强。



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



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

李申夫曾经说我与人怄气从来不说出,而是特别能忍耐,一步步寻求自强之道,因而引用俗话说:好汉打掉了牙,和血吞下去。这正是我咬牙立志的诀窍。我曾经被京城中的权贵所唾骂,被长沙官场所唾骂,被江西官场所唾骂,也经历过岳州之败,靖港之败,湖口之败,被打掉牙的时候多了,没有一次不是连血一块吞下去的。

又说:

我办理湘军水师,一败于靖港,再败于湖口,将士们都愿意离开水师而做陆军。但我咬紧牙关将局面维持了下来,而后终于有了重振的机会。安庆没有合围的时候,祁门大营十分危急,黄德的局势也很危险,大家都建议我撤安庆之围,以支援祁门、黄德,但我咬紧牙关不撤,终于打下了安庆。至于南京是一个方圆百里的大城,易守难攻,我却以孤军将南京围了起来,大家都说恐怕要蹈前面清军的覆辙了,然而咬着牙坚持下来,最后竟然立了大功。

他甚至还说自己要写一部“挺经”,将自己的体会教给后人。对于自己的倔强,曾国藩十分自负。有一次当他的心腹幕僚赵烈文说起李鸿章“遇到事机不顺的时候,不能一定像曾国藩一样坚韧的时候,曾国藩立即非常得意地说:我死了以后,应当谥为文韧公,这是邵位西说的,足下知道吗?



  • 倔强并不是刚愎自用



所以曾国藩强调,“强”字必须以“明”字为基础。他在给弟弟的信中说:

“强”字原是美德,我以前寄信也说“明强”二字断不可少。只是“强”字须从“明”字做出,然后才会有始有终。如果全不明白,一味蛮横,等到别人折之以道理,证之以后效,又重新俯首认输,这就是前强而后弱。这就是京城所说的瞎闹。

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



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



什么是“明”?就是要明于事,明于理,明于人,明于己。曾国藩曾经有过一段十分精辟的论述:

办事要以明字为第一要义。明有两种,一种叫高明,一种叫精明。同一个地方,只有登上高山的人才看得遥远,只有登上城墙的人才觉得空旷,这就是高明。同一件东西,凭空估计不如用秤称的准确,用眼打量不如用尺量的准确,这就是精明。

以明为基础的倔强,其实就是一种定见,是一种看清问题后坚持到底的决心。李瀚章曾经说曾国藩“过人之处,在于坚持定见,不为浮议所摇。”曾国藩自己也常说,办事“不要固执己见,也不要轻易听从别人的言论。必须确实看清了利害所在,尔后再放弃自己的意见。”所以倔强的表现之一就是要有定见。



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



同时,倔强与谦退也不是矛盾的。曾国藩说:

天地之道,刚柔互用,不可偏废。太柔了则成不事,太刚了则就会折断。刚并不是指的蛮横,敢于进取而已;柔并不是指的卑弱,虚心谦让而已。



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



他还说:

知道自己的过失,就立即自己承认,自己改正,而没有丝毫的掩饰之心,这是最难的事情。豪杰之所以成为豪杰,圣贤之所以成为圣贤,就是在这些地方光明磊落,超出常人。

的确,勇于承认错误并改正错误,同样也需要倔强之气,同样是豪杰的作为。




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

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

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

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

My photo
London, United Kingdom
twitter.com/zhengxin

Facebook & Twitter