您在這裡

拿掉留言(comment)時,your name 後頭的那串 (not verified)

drakeguan's 的頭像
drakeguan 在 2006-05-25 (四) 13:27 發表

當有人留言時,如果他沒有登入或註冊,他在 your name 打上的名字,會在顯示時加上 ( not verified ),這對於拿 drupal 來做個人經營用,所以架起來的網站就兩三個使用者(架站者本身)來說,並不太需要這個提示,所以我把它拿來改了一下 :p

修改的前提是以不動到原來 comment 這個 module,而是透過 drupal 的 themeable node 的功能來達到的。

假設你的 theme 是使用 phptemplate(使用 smarty 的方式也差不多),在你的 theme 目錄下(ex, ~/themes/ooxx/)有個 comment.tpl.php(or comment.tpl for smarty),我在它的最一開始加上了如下的 php:


if( strstr($author, "(not verified)") ) {
$author = ereg_replace( " \(not verified\)", "", $author );
}

嗯...cool!
如果有匯入中文語系的話,這程式碼也能作用嗎?

現在比較了解 theme 一點點了,回來補充一下。

如果在不同語系下,依然希望可以拿掉 t('not verified') 的話

假設你的 theme 叫 ooxx,在那個 theme 的目錄下建一個叫 template.theme 的檔案。因為我們想要更改的是有關留言(comment)的部份,所以要改寫的 function 叫 ooxx_comment()

首先把 includes/theme.inc 裏頭的 theme_comment 整個 function 拷貝到你的 template.theme,然後你可以針對

$output .= ' ('. t('not verified') .')';

做手腳。ex, 整行拿掉(or 註解掉),就不會出現了。

ps. t('') 這個 function 可以先假設它是 translate('') 的縮寫,它會依據你語系回傳不同的字串,不過前提是那個語系有設定一個 mapping。

ex, 在 zh_tw.utf-8 這個語系上(有這個語系嗎? 我不曉得 XD)
在 locale (or internationalization?) 裏頭有個把 not verified 對應到 未註冊這一組對應(好像不叫對應? 或是應該叫它翻譯?)存在

ps II. 很抱歉,因為我還沒有使用任何中文語系,所以不知道對應過來的中文譯名叫啥 XD

ps III. 還有很多 themable function 可以改寫,可以參考 ~/includes/theme.inc 裏頭 theme_ 開頭的檔案,或是去官方網站看一下手冊 :)

ps IV. 如果是使用 smarty engine 的話,檔名要取為 theme_name.theme (ex, ooxx.theme)

如果你只有用一個語系的話
是可以把上頭的 ( not verified ) 改成那個語系的內容的啦 :)

Try this, it works.
$FilterStr=sprintf('(%s)', t('not verified'));
if(strstr($author, $FilterStr))
$author=str_replace($FilterStr, '', $author);