Pages

June 24, 2004

pLog plugin mod: galleryimages

Galleryimages is a plug-in for pLog which enables showing a recent uploaded or a random image -- only ONE image. I made a modification to the plugin and have added a new function to allow showing a number of images orderred by date from a specific album. By this function I can show recent books read (see the bottom panel on the right) or recent baby photos. Though it is similar to the plug-in CurrentlyAddictedTo, it doesn't need a wizard to manage images. All you need to do is upload images to a named album.

Galleryimages 這個 plug-in 讓 pLog 可以顯示相簿中最近上傳的圖、或者隨機秀圖,但最大限制是它只能秀一張圖。我增加了一個函數讓它可以秀特定檔案夾(album)裡最新的幾張圖,這樣我就可以秀最近讀過的書的封面(請看右列 panels 最下方)、最新的貝比照片...等,有點像 CurrentlyAddictedTo,只不過沒有設定類別和管理項目的功能,圖片管理很單純,就用 album 名稱。

Open and edit plugins/plugingalleryimages.php, insert following codes after function randomImage():
編輯 plugins/plugingalleryimages.php,在 randomImage() 函數之後加上這段程式碼:
/**
* Returns a number of recent uploaded images from a
* specific album (assigned by album name).
*/
function latestImagesInAlbum($albumName, $limit)
{
$resources = new GalleryResources();
$prefix = $resources->getPrefix();
$blogId = $this->blogInfo->getId();
$resourceArray = array();

// We choose only images from a specific album
// and limit the number by variable $limit.
$query = "SELECT r.*
FROM {$prefix}gallery_resources r
LEFT JOIN {$prefix}gallery_albums a
ON r.album_id = a.id
WHERE r.resource_type = 1 AND a.name = '$albumName'
AND a.owner_id = $blogId
ORDER BY r.date DESC LIMIT $limit";
// just to make things easier, we'll cheat a little here...
$result = $resources->_db->Execute( $query );
if( !$result )
return false;

while ($row = $result->FetchRow()) {
$resourceArray[] = $resources->_fillResourceInformation( $row );
}

return $resourceArray;
}

Then find a proper place in the template where panel group is defined, such as panel.template, and insert following codes:
然後在定義 panels 的 template 中(例如 panel.template)適當位置加入:



Finally create a new album and name it "Books" (no quotes). From now on, 3 recent images (only image) in this album will be shown in the panel "Recently Read" and image description will be shown as small text under the corresponding image. Recent images in album "Musics" will be shown in the panel "Recently Listened".

再到檔案中心(Resource Center)增加一個檔案夾(Album),命名為 "Books"(不要雙引號)。此後上傳到這個資料夾的圖片(僅限圖片)會在 Recently Read 欄中按日期顯示最近的 3 張圖,說明會以小字顯示在圖片下方。命名為 "Musics"(不要雙引號)的資料夾則會顯示在 Recently Listened 欄內。

For quick adoption of this plug-in mod, download it here:
請按這裡下載修改檔:[Download galleryimages_mod.tar.gz]

Well, I just found in Mark's Place a similar mod is made available for download. It uses album ID and mine uses album name to identify albums. Using album ID seems to be good for data uniqueness. However one always needs to modify the code manually, which is not feasible for multi-user pLog (like us) unless every user install his/her own template and know how/where to change. System administrator only need to add panels whenever user requires. And only when the album exists and images can be found in it, the corresponding panel shows up.

另外,剛剛發現在 Mark's Place 也提供了類似的修改方法,基本上做法一樣,但他用 album ID 來指定檔案夾,雖然資料唯一性可以顧及,但都要手動修改程式碼,像我們這個多使用者環境,除非每位使用者都自己裝一個 template 才能這樣做。系統管理員只要按需求新增 panel 定義,只有當該使用者的檔案中心有相對應的檔案夾存在、而且裡面也有影像檔的時候,panel 才會出現。

No comments: