Tommy 碎碎念

Tommy Wu's blog

« 上一篇 | 下一篇 »

LifeType 與 Gallery2 plugin 修改
post by tommy @ 16 二月, 2006 15:37
這幾天把 LifeType 裝了起來, 發現有一個 Gallery 的 plugin 可以使用, 不過我昨天試了一天, 都無法正常運作. 忙了一天後, 終於讓我找到無法運作的原因了.

我不確定為什麼這個 plugin 在別的網站上頭是可以運作的, 因為裡頭在使用 Gallery API 時, 參數似乎不怎麼正確, 且傳回值在沒有錯誤時是個 null 而不是一個 object, 所以接著用來檢查的動作就會有問題 (也許是版本不同的關係, 不過我看過 2.0.2 與 2.1 的 source code, 都不應該這樣子寫. 剛剛又重看了一次 CVS 內的資料, 發現的確在兩個月前有改過一次 (我之前真的眼花了? 看到那去了?)  所以 2.0.2 應該還適用原本的寫法, 不過之後的都不行. 難怪看到一堆 gallery 網站上都的文件也都是這樣子使用.

所以, 簡單改了一下:

diff -Nur galleryhelper.class.php.orig galleryhelper.class.php
--- galleryhelper.class.php.orig 2005-05-17 13:26:12.000000000 +0800
+++ galleryhelper.class.php 2006-02-16 15:50:29.501266842 +0800
@@ -60,11 +60,12 @@
// Set up the gallery call
$ret = GalleryEmbed::init( array( 'embedUri' => $this->_embedUri,
- 'embedPath' => $this->_embedPath,
- 'relativeG2Path' => $this->_relativePath,
+ 'g2Uri' => $this->_relativePath,
+ 'loginRedirect' => '/index.php',
'activeUserId' => '' ) );

// Return error details if there is a problem
- if ($ret->isError()) {
+ if ($ret != null) {
$this->_error = $ret->getAsHtml();
return;
}
@@ -94,7 +95,7 @@
$ret = GalleryEmbed::done();

// Check for errors
- if ($ret->isError()) {
+ if ($ret != null) {
return $ret->getAsHtml();
}

@@ -121,12 +122,13 @@

$ret = GalleryEmbed::init( array( 'embedUri' => $this->_embedUri,
- 'embedPath' => $this->_embedPath,
- 'relativeG2Path' => $this->_relativePath,
+ 'g2Uri' => $this->_relativePath,
+ 'loginRedirect' => '/index.php',
'activeUserId' => '',
'fullInit' => true) );

// Check for errors
- if ($ret->isError()) {
+ if ($ret != null) {
return $ret->getAsHtml();
}

@@ -141,7 +143,7 @@
}

// Check for errors
- if ($ret->isError()) {
+ if ($ret != null) {
return $ret->getAsHtml();
}

@@ -149,7 +151,7 @@
$ret = GalleryEmbed::done();

// Check for errors
- if ($ret->isError()) {
+ if ($ret != null) {
return $ret->getAsHtml();
}

這個 patch 可以到這兒抓: http://www.teatime.com.tw/~tommy/mypatch/lifetype_gallery.patch

經過這個修正後, Gallery 應該可以在 LifeType 中正常使用了.

有關這個 plugin 的說明並不多, 有些要注意的地方如下:

  • Gallery 部份

在網址改寫的部份, 其中 "限制熱鏈接項目" 這個項目不可以使用. 另外 "顯示項目" 這個也最好不要用 (用了之後, 有個壞處是當你要用 specificItem 設定來顯示某張圖片時, 很難由原本的 Gallery 來查出到底 itemId 是什麼), 如果要使用這個功能, 後面對於 LifeType 的部份 rewrite 模組的設定也要加上這項才可以.

  • LifeType 部份

Absolute path: 設定你的系統上頭, 安裝 Gallery2 的 embed.php 的完整路徑. 以我的系統而言, 就是 /usr/share/gallery2/embed.php

Embed uri: 你的 LifeType 使用 Gallery 時, 應該用的 index.php 連結與參數. 以我的系統而言, 就是 blog.teatiem.com.tw/index.php?op=gallery&blogId=1 (如果是同一個 hostname, 則可以省略 hostname)

Embed path: 弄不清楚做什麼用的, 實際上好像也沒用到這個參數了, 就打個 / 上去吧. 程式裡頭也沒用到這個參數了.

Relative path: 就是你的 Gallery 的 main.php 所在的路徑. 以我的系統來說, 就是 gallery.teatime.com.tw/main.php (如果是同一個 hostname, 則可以省略 hostname, 用相對路徑表示)

如果你在 Gallery 有啟用 "顯示項目" 的網址改寫, 在 Gallery 的 .htaccess 會有下列的設定:

RewriteCond %{THE_REQUEST} /v/([^?]+)(?.| .)
RewriteCond %{REQUEST_FILENAME} !/main.php$
RewriteRule . /main.php?g2_view=core.ShowItem&g2_path=%1 [QSA,L] 

這時在 LifeType 的 .htaccess 就要有相對應的設定:

RewriteCond %{THE_REQUEST} /v/([^?]+)(?.| .)
RewriteCond %{REQUEST_FILENAME} !/index.php$
RewriteRule . index.php?op=gallery&blogId=1&g2_view=core.ShowItem&g2_path=%1 [QSA,L] 

經過這樣的修正與設定後, 就可以順利將 LifeType 與 Gallery2 整合在一起了.

Del.icio.us Furl HEMiDEMi Technorati MyShare
commons icon [1] [ 回覆 ]

您好:
感謝你辛苦的寫出這四篇修改的方法,不知道有沒有興趣做個完整的修改版本的plugin來放回Lifetype社群呢?或是我可不可以用您的這些修改,確認沒問題後,放回社群呢?

另外,因為您的網站沒有寫授權方式,不知道可不可以整合程式碼和部份說明後放在我的Blog呢?

commons icon [2] [ 回覆 ]

原本的 plugin 作者似乎無法聯絡上, 也沒有看到原本的授權方式, 所以我不清楚修改後再打包釋出會不會有違原作的授權.

至於我這幾篇文章與修改的部份, 歡迎轉載或自由修改使用.

commons icon [3] [ 回覆 ]

補充一下, 我剛剛有把這些 patch submit bugs.lifetype.net.

commons icon [4] [ 回覆 ]

嗯嗯,你有submit上去了就ok啦,希望能趕快看到修正後的版本出來。

不過怪怪的是,我剛剛照著修正,會產生錯誤@@

commons icon [5] 該如何使用呢!? [ 回覆 ]

你這個 patch 檔案要如何使用呢 @.@ 我有點不太懂!!

我抓下來 lifetype_gallery.patch 之後呢~!?

後續要如何使用呢!?

commons icon [6] [ 回覆 ]

有什麼錯誤訊息呢? 也許是因為 Gallery 版本的關係. 參數有修改, 在 2.1RC1 與 2.0 之間是不同的. 我改的是給 2.1RC1 使用的.

另外 patch.... 如果你用 unix-like 的東西, 就 man patch 看一下說明. 如果是 windows... 我就不知道你要怎麼用了. 自己看看那個檔案自己改也可以, 上頭會有說明那個檔案改了那些東西. + 就是新增, - 就是刪除.

commons icon [7] [ 回覆 ]

如果真的不知道 patch 怎麼弄, 就等官方正式的版本出來吧. 我有 submit 一份 bug patch, 應該後續的版本會有修正吧.

迴響
暱稱:
標題:
個人網頁:
電子郵件:
authimage

迴響

  

Bad Behavior 已經阻擋了 48 個過去 7 天試圖闖關的垃圾迴響與引用。
Power by LifeType. Template design by JamesHuang. Valid XHTML and CSS