Drupal 7 – Select node by language using EntityFieldQuery

Here is an example to select entities by the current language in EntityFieldQuery.

// Get the current language
global $language;

// Setup the EntityFieldQuery
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', '<CONTENT TYPE>') // ex. article
  ->propertyCondition('status', 1) // published nodes
  ->propertyCondition('language', $language->language, '='); // filter by current language

// Execute the query
$result = $query->execute();

 

Done =)

Drupal 7 – Trim text programmatically

Drupal 7 provides the truncate_utf8() function for you to trim any string in PHP manually. Assume you have a lorem ipsum paragraph.

  • truncate_utf8($string, $max_length, $wordsafe = FALSE, $add_ellipsis = FALSE, $min_wordsafe_length = 1)

Continue reading Drupal 7 – Trim text programmatically

陶傑 – 馮大導的大悟

中國導演馮小剛說:拍「一九四二」的時候,他明白了,中國人的問題,不一定是哪個政黨、哪套制度,而是民族性的問題。

馮大導講得沒錯。一個國家,即使出現獨裁的政黨,就像一個人得了癌症。癌症一個重要成因,是家族遺傳。

有的民族,癌症比率低,像日本。日本人飲食健康,鍾秀自然,喜愛茶道,又不會向下一代提供有毒污染食品,加上承傳了老莊的道家思想,並學得歐洲人的品味,大和民族心境平和,看破生死,即使地震災劫,毫不喧嘩慌亂,贏得美國和歐洲的尊敬。

日本的民族性,早年因固有蒙古利亞裔成吉思汗的殘暴,以及中國戰國時代武士的愚忠至勇,加上明治維新成功,驕奢不可一世,像白血球過多一樣,對外侵略,為鄰國造成危害。

可幸得到西方文明挽救,杜魯門和麥克阿瑟,保留日本天皇,日本人去除了蒙古利亞的基因,成為東西方文化優秀價值的典範。
Continue reading 陶傑 – 馮大導的大悟

陶傑 – 中國的民族性

中國導演馮小剛先生公開要求,可否拍「文革」題材的電影。馮大導接受採訪,題為「人生能有幾個十八年」,講到拍「一九四二」的經驗,馮大導說:拍這齣戲,令他對中國人「民族性」的認識,得到了昇華:
「過去,我們會把一些苦難歸咎於制度或政黨,但實際上,很多時候是民族性本身的問題。」

許多中國文人很天真,他們認為,「中華民族」是偉大的,或者是所謂勤勞、勇敢的,之所以多災難,不是「列強」的侵略,就是皇權暴政。他們認為,中國人的「民族性」沒有問題,認為「民族性」出問題的,是將中國問題「簡單化」,而且「偏激」。

但是,馮小剛不是一個偏激的人,他是中國導演中少有會賺錢的同時,還能啟動大腦思考的人。以馮大導的大陸經歷,其實更早就可以悟到中國人的民族性天生有極大的黑暗面,但是一直忙着發財。中國人如果能讓你發財,民族性當然不錯,但大導人到了中年,終於也明白了,也是一個喜訊。
Continue reading 陶傑 – 中國的民族性

Drupal 7 – Pathauto and Transliteration

Pathauto is the most common module which i think almost all Drupal websites use it to format the path alias. Sometime we want to use the node title as part of the path alias but if we are working on multilingual Drupal website, this may lead to non english URL.

So we have the Transliteration module to solve the problem. It takes Unicode text and tries to represent it in US-ASCII characters by attempting to transliterate the pronunciation expressed by the text in some other writing system to Roman letters. In addition, it also helps creating clean file name on file upload.

1. Download and install the Transliteration module.
Continue reading Drupal 7 – Pathauto and Transliteration

Drupal 7 – In-place editing using Edit module

The Edit module allows you to edit the node content directly on the node view page. It works with CKEditor and also it will be included in the Drupal 8 core. So see how it works in Drupal 7 first.

1. Drupal 7 >= 7.22 is required.

2. Download and install the CKEditor and Edit modules.

3. Grant the Access in-place editing to the relevant roles.
Continue reading Drupal 7 – In-place editing using Edit module

jQuery NiceScroll Plugin doesn’t work for dynamic content

jQuery NiceScroll Plugin is a very convenient tool for customizing your website scrollbar.
Create a better scrollbar using jQuery NiceScroll Plugin

By default, the scrollbar is hidden if the content doesn’t exceed the content wrapper height. So if you have dynamic content, you have to tell the NiceScroll plugin to resize otherwise the scrollbar doesn’t show.

Let’s start with the following index.html.
Continue reading jQuery NiceScroll Plugin doesn’t work for dynamic content

陶傑 – 家法制裁

香港保釣份子因探望劉霞女士,在北京被抓捕,TVB記者亦遭數名中國男子圍毆,香港人很氣憤。

這個姓楊的先生,身份是「保釣人士」。日中關係緊張,幾乎開戰,就是因為香港的「保釣」人士違反《基本法》,干預中國的外交國防事務,擅自闖入尖閣列島(亦即中國宣稱的釣魚島、台灣說的釣魚台)而起。

香港是一個國際金融經濟城市,不要搞太多政治,日中領土爭議,更是關你屁事。香港人理應對全世界都友善。「保釣份子」啟釁戰端,危害世界和平,這次回到大陸,受到中國公安制裁,令人想到,世上終有報應這回事。

至於電視台記者被毆,可不可以這樣看(Why not put it this way):香港的免費電視新聞台,愛國親中,早已調整了凡事不可以「西方觀點報道」的偏頗立場。他們認為,許多新聞,應該多從中國人的觀點來報道評論,這樣才會免於被英美的CNN和路透社洗腦。
Continue reading 陶傑 – 家法制裁

Dream BIG and go for it =)