<?php
echo theme('imagecache', $preset, $imagepath, $alt, $image_title)
?>在 node.tpl.php 內可用
其中 $preset 是imagecache profile 的 machine name
<?php
echo theme('imagecache', $preset, $imagepath, $alt, $image_title)
?>在 node.tpl.php 內可用
其中 $preset 是imagecache profile 的 machine name
一直看到國內的進階 Drupal 教程都會提到使用 db_query() 用以代替 views, 例如: http://drupalchina.org/node/9021
觀點大概是 views 使用太多資源了, 使用 db_query() 能直接存取數據資料, 性能上會比較好,
也更自由等等
以下是我的個人意見:
雖然是進階的教程, 但開發者在有其他可使用的方法之下直接存取是不可取的, 原因:
1.安全問題
這是最重要的一點, 避開 sql-injection, xss
在自定義的代碼之中, 有太多入門的開發者忽視或不重視數據安全的問題
在不清楚如何編寫安全的 Drupal 代碼之前已經開始開發
而 views 的設計上已經極大量的考量安全問題
至少, views 之類的大型模組, 單單是測試者的數量可能已經比美你的訪客人數
所以, "自定義的代碼 會/可以 和 views 一樣安全" 是不成立的
views 一定比自定義的代碼安全
ref: http://drupal.org/writing-secure-code
2. 可變性
使用 views 的好處還有可變性強
這很明顯, 使用views 的 web admin 修改代碼一定會比修改自定義的快
在這個永遠活在 beta 版的網頁開發世界, 這一定是一個重要的優勢
多出的時間應該要用於編寫幫助文件或者用於測試等等的地方
3. 性能
這是一個沒有正確答案的問題:
使用views 是否一定會比較慢?
views 本身並不只是一個sql 產生器, 它還內建緩存機制
就好像 variables_get() 函數, Drupal 會將會個 variables table 放到一個 cache
一個 select 便可以存取全個 variables table 之內的數值
而類似的機制也出現在views
當然, 一個精心設計的 sql 會比 views 快,
但這個精心設計所帶來的性能是否可以補回以上的問題便值得仔細研究了
4. 培養良好的開發習慣
"良好的開發習慣" 很抽象
但基本的例如 *.tpl.php 之內不應該有顯示視圖以外的功能/代碼
又或者 CSS 應集中於一個css 檔之內而不應使用inline: <a style="color:red;">joe</a>
不應修改 Drupal 的核心代碼等等
這些習慣其實是可以由使用 contributed modules 來培養的
因為它們會定好習慣, 而你順著使用便會是最快的開發方式
然後藉此 "培養更多的良好的開發習慣"
最後, 這些都是我的觀點, 也是我見過的其他 Drupal 國外高手的潛規則
希望大家深入討論, 思考
As soon as a break through app, Opera mini lands, I find it exciting in both:
I am not going to write a user level review, but from developer/technical point of view. Starting from least mentioned in media:

You may not discovered that, opera just have 2 zoom level, a overview and closed view. You may not discover because it calculates the zoom level so actuate, and you barely need a third zoom level. Try it yourself!
I am neutral about this implementation, as far as it calculates correctly over 99% of webpage. But I have a wild guess from this observation, that it is the critical point that made opera so fast, by only saving 2 static image.
This wild guess can be further prove by looking at some "auto changing" sites, like http://berlintwitterwall.com. In normal browser(even in iPhone's safari, although very slow), this site scroll horizontally and popping new tweets, while in opera, the site is static.
In iPhone's safari, by flipping the phone vertically and horizontally, the page render again to fit the monitor width. This also do not apply to opera. you will see a large white space if you flip from horizontal to vertical position. But if you reload the page, the page will render again and fit your phone's orientation.

If my guess is correct, I even have a wilder guess that the 2 static image may actually render on opera's server, not on the iPhone. and Changing orientation do not trigger another request/do not render the page again!

This is another side evidence that opera mini is actually showing a static image, but not just "ignoring continuous javascript". Many sites define a finite height of a div. By applying a css property "overflow:auto", if the content within the div is actually having a height larger than the defined value, a scroll bar take place. http://inmediahk.net on the right sidebar had an example. In opera, the scroll bar do not appear again. (similar behavior with overflow:hidden)(This actually also apply to safari)

The images best explain what I want to say. The rendering logic align image and text to the same width so in closer level zooming, the image and text will fit the screen beautifully. (sorry no guess here ^^)

Also no special observation here, but above 2 points worth mention again. The switching between tabs in super fast, like desktop speed! (maybe because just switching 2 image?). And bandwidth saving by opera turbo is a famous function of opera, even in desktop version.
lastly, an improvement needed. Setting up the 9 speed dials is very difficult through UI. You cannot save the current page as speed dial, but you have to open a new speed dial tab, and press the thumbnail and type the URL to edit it.....
UPDATE: 2010-04-13 images added
ORG: 2009-06-13
svn 是一個管理源碼的工具
它提供一個容許多人協作的平台, 幫助一個多人開發的團隊管理代碼
同時提供一個保存多版本的功能 (version-ing)
而我因為多數都自己一個開發, 主要為了 versioning 而使用 svn
但因為有多個開發機器
為了保持代碼在多個機器中同步, 都會使用 svn
我在 windows 機是使用 TortoiseSVN GUI client
ubuntu 上使用 nautilussvn
使用上, 介面上都很類似, 都很好用
先談一下 svn 的概念
svn server 是指在 remote 上的server
大家都將大家的code 上傳 (commit) 到這個中央的server
而開發機則是 client端 (當然, 他們其實可以在同一部機器上)
而 head 是指最新的一組檔案的集合, 統稱 head version
trunk 一般指 server 上的 head.
從日常使用次數最多的功能開始介紹
checkout

從server 上下載源碼(即 server 上己經建立好, 設定好)
在本機(即開發機上)建立一個拷貝
是在開發機上開始建立一個新的 project 的方法
完成便可以開始改動源碼, 開發的工作了
可以從 code.google.com 隨便選一個 project 使可以checkout了 (source tab 便可以找到 svn url, 例)
commit / add

commit 是指將本機的源碼上載到 svn server 上(要已經checkout 過的檔案)
例如已經checkout 過的 project,
在改動源碼之後, 資料夾上使會有一個紅色的X, 代表需要 commit
而如果你有權力 commit, 便可以上載到 svn server 上了
而每一個commit 都儲存到 server 上, 之後的任何時候都可以調用, 還原等等 (就算commit 再覆寫過都可以)
而 add 則是新增一個沒有 svn 的檔案到 svn server.
commit 的策略是, 每午飯之前, 下班之前都commit, 原因在討論 update 之後再研究
update

如果我 checkout 了一個 project, 但 project code 在svn server 上有其他人 commit 了中
我應該如何更新我的 code 令自己和svn server 同步?
答案是 update.
svn 會幫我們從 server 上下載, 而且萬一需要覆寫一個我們正在修改的檔案(即一個衝突 conflict 發生了),
svn 會嘗試幫我們合併, 確保同事做的修改和我們的修改都正確的保存
如果開發團隊同意了午飯前, 下班前commit 當日的源碼,
update 的策略便是 上班的第一件事, 和午飯後的第一件事了.
change log, diff
每一次的commit 都會留下記錄在 server 上 (change log)
並有一個唯一的 版本(version) id
我們任何時候都可以將任何兩個 commit 比較
並還原, 合併任何兩個檔案
svn 在處理 conflict 的時候, 不一定能自動合併
這時 svn 會要求我們做手動合併, diff 工具都會協助我們分析兩個衝突檔案的內容的
tag / branch
這是一個進階使用者的題目, 請先確保你試過, 用過上面的功能再繼續
head 便是一個等殊tag, 這個tag 是會隨著commit 而移動
而我可以因應需求tag 一個 2009-06-08 tag
標記這些便是 09年 6月 8日 的源碼, 主要是為了方便日後的調用 (稱為日期tag)
而branch 其實和 tag 類似, 但 checkout 了 branch 的話, 你的 commit 會指定為 commit 到這個 branch,
而不是一般的主線
這樣, 你就可以將你的重大更新, refactoring 開一個 branch, 完成再 merge
令自己的重大更新的開發代碼不會干擾其他同事的開發
指令上在 GUI 都好簡單, checkout/update 了以後, 直接在資料夾上右鍵->tag/branch 便可以了
安裝 svn server @ubuntu
首先安裝 SVN
sudo apt-get install subversion
安裝 svn 在 Apache 使用的套件
sudo apt-get install libapache2-svn
進階的權限便自己 google 一下了
Project setup
安裝完便要建立一個 trunk,
而一般的資料夾習慣是:
SVN-ROOT
-PROJECT-NAME1
--trunk
--tags
--branches
-PROJECT-NAME2
--trunk
--tags
--branches
建立 SVN-ROOT 到 /home/svn:
sudo svnadmin create /home/svn
建立 PROJECT-NAME1:
GUI:
在開發資料夾 (例 /var/www) checkout file:///home/svn
checkout 後建立 trunk, branches, tags 三個資料夾
commit 三個資料夾
再 del 三個資料夾, 然後 checkout trunk
便可以開始 add了
conclusion
會使用 svn 工具絕對是其中一個進階程序員的指標 (包括 tag/branch)
工具看似複雜, 但其實真正做起來只是很簡單的概念, 但用文字真的比較難以表達
找一個人教一教, 十分鐘便什麼都懂了.
version control 的工具其實還有 cvs, git 等, 概念有一點不同
但一般的操作反而很類似, 舉一反三就是了
但svn 都不是萬能
sql server 中設定很多的 cms (drupal 便是一個明顯例子) 如何做 version control?
mysqldump + commit?
有高手能解答嗎?
hook_block() 是一個給 Drupal 提供block 的方法
假如你發覺自己在 add block 的時候用了 input method 使用了php
那你其實應該建立一個 module, 使用 hook_block()
原因: "module" vs "add block"
所以, 不要懶了, 而且建立hook_block() 也很簡單
假設 module 名為 joe >Read more
來自社區的一個問題: http://drupalchina.org/node/8514#comment-26113
比如我是 "writer" role, 我想要一個頁面都是 writer role 的用戶的nodes:
views 的 argument 應:
加, User:roles -> Provide default argument
Default argument type: PHP code:
<?php
global $user;
$roles = implode("+",array_keys($user->roles));
return $roles;
?>解說: 先拿到用戶object
再拿出用戶的所在的 role id
因為可以多個role, 需要implode 成 2+5
Allow multiple terms per argument 便會 OR role id 了
htmlentities() 和 html_entity_decode()
htmlentities()
http://www.php.net/manual/en/function.htmlentities.php
功能上很簡單, 就是將 < 變作 <
當然, 還有其他的entities, 可以參考: http://www.w3schools.com/tags/ref_entities.asp
主要是給使用者輸入的 entities 會 escape, 輸出的時候便可以直接使用
另一方面, >Read more
svn 是一種使用之前會討厭,
但使用過以後你已經不能缺少的開發環節 (情況和測試驅動開發(TDD)一樣)
在"使用過" 並愛上的青況之下,
你很容易便會提起興趣學習進階的 branch 和 tag 的功能了
但如果沒有, 直接跳過就好了 >Read more
一個module 需要輸出html 的話, 會使用 hook_theme()
但如果一個theme 都需要輸出特定的html, 或者需要使用 *.tpl.php的話
因為Drupal 6 新增了 theme registry,
以前 Drupal 5 的theme 內的theme() 函數都不會自動加到theme registry
要在 template.php 內: >Read more
Recent comments
2 weeks 6 days ago
2 weeks 6 days ago
2 weeks 6 days ago
2 weeks 6 days ago
2 weeks 6 days ago
2 weeks 6 days ago
2 weeks 6 days ago
3 weeks 3 days ago
4 weeks 10 hours ago
4 weeks 14 hours ago