Feed 聚合器

2010-03-15 Boost enabled

JOE Tsui's Drupal site - 星期一, 2010-03-15 20:04

Boost 是一個將匿名(非登入用戶, anonymous visitor)從動態生成的PHP 頁面轉到靜態HTML 頁面的模組

這模組能大量減少匿名用戶的載入頁面時間
但登入的使用者就沒有幫助

它的工作原理是利用了匿名用戶所看到的頁面不含有個人化的 block/內容
在匿名用戶的頁面內容完全一玫的話
頁面便有可能只使用靜態的HTML

它的工作的流程從Drupal 初始化開始
先判定使用者的登入狀態
直到這裡, Boost 都沒有提升頁面效能
但一旦判定為匿名用戶, 用戶便會被.htaccess 轉發到預先製好的靜態HTML
達成效能的提升

一個很好用的模組, 特別是對於匿名用遊客訪問為主的網站

Boost is a module that drive anonymous visitor from dynamic PHP pages to boost generated static HTML through apache .htaccess settings

This module can help anonymous users page load speed very much,
while logged in user have no effect on it.

It used the nature that annoymous user do not have customized theme/blocks/content
so every visitor should see the same content,
can thus can serve the page through static HTML

The mechanism start from Drupal initialize,
first check if the user is logged in or not.
Up to this point, this module do not help in performance,
but once anonymous user got redirected to cached files by redirect and .htaccess file,
the page load time boosted

A very good module for sites with mainly anonymous users like joetsuihk.com

简单水墨主题

kzeng 寱语 - 星期六, 2010-03-13 10:54

晚饭啃“赛百味”的时候,看到了一些矢量水墨国画,在 photoshop 里拼摆了一下,想创建一个新的 Drupal 主题风格,其实除了三只鸟以外,似乎也就是单纯的文本文字,这样也好,很清爽。等有时间,把这个构图转化为主题文件。

hook_submit, hook_form_alter, hook_validate in Drupal 6.x

JOE Tsui's Drupal site - 星期三, 2010-03-10 00:44

hook_submit() 是每一張form 提交的時候會經過的 hook
可以用作發電郵之類的自定義動作

類似的, hook_validate() 是驗證每一張 form 的時候會經過的hook
可以自定義更多驗證的 logic

而從Drupal 5.x 之中, hook_submit() 的 function callback 可以在form API 使用如下 syntax:
<?php
$form['submit']['#submit'] = array('function1','function2');
?>
那 function1 和 function2 都會在 hook_submit() 之中callback 了

而 Drupal 6.x 之中, #submit 在不再在 submit button 之中定義:
<?php
$form['#submit'][] = 'my_module_submit_handler'
?>
雖然 D5 的方法都可以, 但便不可以用 hook_form_alter() 從一個 module 修改另一個module 的 form 了

例如, contact form 需要一個contact number,
submit 時將 contact number 加到 body 之內:
<?php
function my_module_form_alter($form,&$form_statues) {
  $form['#submit'][] = 'my_module_submit_handler';
}
function my_module_submit_handler($form,&$form_statues){
  //processing
}
?>

2010-03-04 更新到 Drupal 6.16

JOE Tsui's Drupal site - 星期四, 2010-03-04 23:54

Drupal 6.16 update

更新發現了一個在icdsoft 實用的功能
就是resotre

因為我的 .htaccess 和 cron.php 不是 Drupal default 的,
我加了些少 logic, 更新以後便變回原本的版本
restore 可以 restore 最多 5 日的data,
而且可以 "單一/多個" "檔案/資料夾", click 一下便 restore 了, 方便!

UPDATE1: .htaccess in 6.16 had been modified as: http://drupal.org/node/638030

SA-CORE-2010-001 - Drupal core - Multiple vulnerabilities

Drupal安全公告 - 星期四, 2010-03-04 03:31
  • Advisory ID: DRUPAL-SA-CORE-2010-001
  • Project: Drupal core
  • Version: 5.x, 6.x
  • Date: 2010-March-03
  • Security risk: Critical
  • Exploitable from: Remote
  • Vulnerability: Multiple vulnerabilities

Drupal .htaccess block file access

JOE Tsui's Drupal site - 星期二, 2010-03-02 00:40

In Drupal, in addition to hosting in icdsoft,
i have a php.ini file and maybe a backup folder(i do not have) that do not want unaurotized access

use .htaccess to do the job as:
<Files ~ "php\.ini|install\.php">
  Order allow,deny
  Deny from all
</Files>

which block php.ini and install.php from access by anyone from web

Mollem not properly configurated since last year?

JOE Tsui's Drupal site - 星期二, 2010-02-23 19:51

Thank you Kay.L for pointing this out...

Sorry readers....

2010-02-22 Poor-ly structured Drupal site ever seen

JOE Tsui's Drupal site - 星期二, 2010-02-23 00:38

Drupal template system is so flexible that you can do anything in node.tpl.php

This let chaos happens in a site i maintain, which made my pull my hair out of my head. (sort of)

That is a classic example that more power bring a larger disaster.
The developer that leaves the project even define a form , its hook_validate() and its hook_submit() inside the node.tpl.php. TOTALLY INSANE.

As a professional developer, not a part time one, YOU SHOULD TAKE RESPONSIBILITY TO YOUR CODE!!
so, you should:

  • avoid any node_load() in *.tpl.php (should be in custom module or preprocess function)
  • avoid any complex PHP code in custom block content, and visibility settings. Build a custom module will only cost you 5 mins
  • multi site settings should be carefully planned
  • DOCUMENTATION on your magic tricks
  • 山寨就是貌似做到一樣, 但細緻就不行了

God bless me, please open new projects instead of fixing old ones.

Module development - introduction [module].info

JOE Tsui's Drupal site - 星期四, 2010-02-18 21:36

要自己建立一個 module, 先要跟從 Drupal 的一些規定
令 Drupal 知道有這麼一個新的 module 存在

假設要寫的是一個名為 my_module 的模組 (真正的模組只可以使用 a 到 z 和 _ )

  1. 先到 sites/all/modules 建立一個資金夾, 名為 my_module
  2. 在資料夾之內建立兩個檔案
    1. my_module.info (模組的基本資料)
    2. my_module.module (模組的 php code)

my_module.info: (只介紹最基本的要求, 以後再補上非必要的設定)
//不需要 <?php
; $Id$
name = "My module"
description = "模組簡介"
core = 6.x
ref: Writing .info files (Drupal 6.x) http://drupal.org/node/231036

而 my_module.module 內基本上沒有必需的內容
但在這個時候便適合介紹 hook 系統了

你會在 Drupal 的教學看到很多 hook_block(), hook_help()
hook 是什麼?
其實, 每一個 module 都可以使用這些 hook 令 Drupal core 可以使用模組提供的功能
在 my_module.module 的例子, 我應該 declare
function my_module_block() {}
作為 "使用 hook_block()", 或者
function my_module_help(){}
作為 hook_help()
"hook" 是要變為你的模組名, 以區分不同模組之下的相同 hook

下一篇會慢慢介紹各個常用的 hook

ref: Creating Modules http://drupal.org/node/206753

2010-02-10 轉hosting 了

JOE Tsui's Drupal site - 星期三, 2010-02-10 21:45

原本使用hostmonster 的, 因為有shell access, 好玩, 可以開svn server, samba
但就是慢了點, 而且我都有自己的svn server 了
現在不太需要另一個shell 了

所以轉了本地存取較快的icdsoft
只提供php, mysql, ftp, 10G space, 夠用就好了, 其他專門服務還是找專門的hosting 吧

大家試試有沒有網頁快了?

最近正在看, 和想看的書 Recent books

JOE Tsui's Drupal site - 星期四, 2010-02-04 11:02

正在看:

一本不是有關algorithm 的書, 而是有關思考解決問題的書
"如何漂亮的解決問題" 是這書的重點, 既是高深的書, 又應該及早看看以增強功力


想看: High perforamance javascript

Theme-ing "login to post comment", theme_comment_post_forbidden()

JOE Tsui's Drupal site - 星期三, 2010-01-27 22:09

Recently, i have find some theme-ing functions that cannot be simply find by theme developer module, as that theme function only calls when you are anonymous user.

comment.module theme_comment_post_forbidden() is an example.
This function render the "Please login to post comments" to anonymous user, request them to login in order to get access to the comment form.

As theme developer do not appears when you are not admin, so when i want to theme this sentence, i spend some time to find out the function is defined in comment module, which is reasonable.

Hope this small tips helps someone.

2010-01-19 iphone mobile app - iui library

JOE Tsui's Drupal site - 星期二, 2010-01-19 21:18

最近之玩物: http://code.google.com/p/iui/

一個css framework, 和iphone native app 做到九成似, 功能也不錯, 有些時候還有些很聰明的點子

缺點, 除了example 之外, docs 很少, 要深入的話, 要自己看 source code..

但都是一個很好的project

2010-01-17 Ubuntu 9.10 安裝 gcin 倉頡中文輪入法 chinese input method

JOE Tsui's Drupal site - 星期日, 2010-01-17 15:53

@ubuntu 9.10, 我netbook 上的ibus 輸入法(原生的) 經常hang (倉3)
特別是在hiberbate, sleep mode 再wake up 之後

日前終於認不了, 比較了 gcin 和scim 之後
從其他人的blog 中得知 scim 在9.10 上不太stable
便決定用gcin

安裝很容易, 到 System -> Administration -> Synaptic Packet Manager 找gcin
check install, 按apply, 之後restart

再到 System -> Administration -> language support, input method 選 gcin
就可以了.

gcin default enable 了很多輸入法, 而我自己只用 WIN 的倉頡
System -> Preference -> gcin setup, 內定輸入法, 只選倉頡

完成!!

MVC in Drupal

JOE Tsui's Drupal site - 星期一, 2010-01-11 20:58

在Drupal 要maintain 一個完整的MVC 結構其實不容易
因為template engine 的功能太強大, 而且我們的習慣又免得修改 module
所以好多在controller 和views 界線之間的修改都會在template 內做

在我從其他的framework 中得到的MVC concept,
覺得其中一部份的修改其實是應該用修改controller 實現的
但因為上面的原因, 便選擇了用Views 處理
我都正在試驗自定一個module 來 customize 部份功能,
又能令其他 contrib module 的升級不受影響

其中一個想法是,
要分開"需要的功能" 和 "garland 不需要的功能"
應該能清楚的分辨什麼應該在Views, 什麼不應該的煩惱

修改首頁的template

JOE Tsui's Drupal site - 星期三, 2010-01-06 00:38

你可以使用一個和其他頁面完全不同的首頁, 只要你能應用 template suggestion.

打開你的theme_developer module, 指一下首頁,
你便會發現frontpage 是有一個特別的suggestion: page-front.tpl.php

你只要在你的theme folder 內建立/複製一個page-front.tpl.php,
然後你便可以開始加特別的class 到body,
或者使用完全不同的region (front-left, front-mid-left, front-mid-right, front-right)
把首頁變作4欄以應付首頁大量資料的需求

p.s. 記得清空你的cache 以使用新增的page-front.tpl.php
p.p.s 你當然也可以使用panels 之類的模組完成相同的效果

原文: http://drupal.org/node/317461

加js, css file 到theme, Add a theme specific js/css to a page

JOE Tsui's Drupal site - 星期三, 2009-12-30 00:23

如題, 你可以在 theme 的 .info file 用以下的方法
scripts[] = js/gallery.js

stylesheets[all][] = css/gallery.css
你可以加第三方的 js/css, 例如 jquery ui, fancybox 之類
如果你看到你的page.tpl.php 有<script type="text/javascript" src=""></script>你可能會考慮用以上的方法include 了

Note1: 路徑是相對到theme 的資料夾
Node2: 它們會被優化的, 如果你開啟了壓縮 js/css 檔案的話

As titled, if you want to add a js or css file only to a theme, you may:

scripts[] = js/gallery.js

stylesheets[all][] = css/gallery.css

This should contain mostly contain some 3rd party js/css libraries/frameworks.
if you find you put some <script type="text/javascript" src=""></script> in page.tpl.php, you better think again to put it like above.

Note1: the path they refered is CURRENT_THEME directory
Node2: They will got aggregated if you turn on compressing js/css files in "Performance" page

Actions, trigger, rules, workflow

JOE Tsui's Drupal site - 星期日, 2009-12-20 15:46

這四個Drupal6 的module 互相有關連,功能又多, 做一個小小的整理

action 和 rules 是做同一件事:定義一些“行為”/“行動”
而rules 是進階版的 action
這些“行為” 例如顯示一個信息, 發一個email 等等,單獨存是沒有意義的, 它需要一個觸發器去觸發一個action/rule
這個觸發器就是 trigger module 了

觸發器的例子有:“在儲存一個node 之後”
那你就可以達成:“在儲存一個node 之後,發一個email到 admin@abc.com”

以上的例子很簡單,不足以說明它們的強大,但這篇只是想給讀者一個概念
讀者們要先內化這概念, 下一個post 便可以講一下進階的用法

而 workflow 是一個處理流程的module, 本身也是一個巨大的觸發器
workflow 自己可以做到定時出版一類的功能,由draft 到review 到publish, 每一步都有一個trigger, 可以trigger send email 等等的rules
有機會的話也可以詳細講講

ref:
trigger 和 action 是 D6 內建的
Rules: http://drupal.org/project/rules
Workflow: http://drupal.org/project/workflow

SA-CORE-2009-009 - Drupal Core - Cross site scripting

Drupal安全公告 - 星期四, 2009-12-17 05:17
  • Advisory ID: DRUPAL-SA-CORE-2009-009
  • Project: Drupal core
  • Version: 5.x, 6.x
  • Date: 2009-December-16
  • Security risk: Not critical
  • Exploitable from: Remote
  • Vulnerability: Cross site scripting

在windows 上使用Drush

JOE Tsui's Drupal site - 星期一, 2009-12-14 20:54

使用了一段時間了, 現在才有時間介紹一下drush
有如 admin_menu, 用過便忘不了
基於 *nix 的 drush 簡單易用, 但windows 上便有些限制, 最常用的 drush dl views 用不了..
hack (不用cygwin):

1.
下載Drush http://drupal.org/project/drush, 解壓到 /path/to/drush

2.
下載並安裝:
http://gnuwin32.sourceforge.net/packages/libarchive.htm
http://gnuwin32.sourceforge.net/packages/gzip.htm
http://gnuwin32.sourceforge.net/packages/wget.htm

再將 控制台 > 進階 > 環境變數
新增 / 修改 PATH: C:\Program Files\GnuWin32\bin;/path/to/drush

3.
cd /path/to/drupal
drush.bat dl views

完成!!

p.s. admin_menu 之外, 我還一定會裝 vertical_tabs, drush, devel