Welcome!  
 Welcome! 
::  Home  ::  Photo Albums  ::  Family Login  ::  Forums  ::
 
Claire
Financial Planning
My One Third Acre Blog
Genealogy
Arts and Crafts
Tetris
 
Andy
iPhone blog - *new*
Homepage & blog
phpWebSite
    AlbumView
    BannerBox
    PhotoBox
    Photoalbum hacks
    Google Services
    Themes
Wearable Computers
 
Patrick
Homepage
 
Katie
Homepage
Art
 
Photo Albums
Arts and Crafts
Genealogy
Travel Photos
    California Travels
    Other Places
    Rome - 2005
    John Paul II Memorium
    Montreal - 2003
    Hawaii - 2002
    Boston & Maine - 2001
    San Antonio - 2000
    New Mexico - 2000
    Ana Nuevo - 2000
    Dublin - 1999
    Paris - 1999
Other Photo Albums...
 
Photoalbum hack

Photoalbum hack

Hack - no longer needed - January 2007

These hacks to PhotoAlbum are no longer needed as they are now integrated into the photoalbum module included in phpWebSiye 0.10.x. Check out: http://phpwebsite.appstate.edu/index.php?module=webpage&id=6

New controls added to the Edit Photo form

Photoalbum hacks: select album thumbnail and move photos

Ever wanted to move a photo to a different album or *really* control which thumbnail image is displayed for an album? I have hacked photoalbum to enable these functions.

The current version of photoalbum, version 1.1.5 as found in phpwebsite 0.9.3-3 and 0.9.3-4, has no ability to move a photo from one album to another. Also, the album thumbnail reflects the latest image uploaded or edited. I frequently upload many images but must select an album before uploading. My wife frequently prefers the image placed in a different album than the one I selected ;-) She also wants to select the thumbnail image displayed in the "List Albums" view.

After making these edits, the "Add Photo" and "Edit Photo" forms have 2 new controls: a checkbox to select the image as the album thumbnail image and a drop-down selection to enable moving the photo to a selected album.



Edit files: Photo.php and editPhoto.tpl

My hack to photoalbum 1.1.5 relates to two files - "photoalbum/class/Photo.php" and "photoalbum/templates/editPhoto.tpl"

If you do not want to edit these files yourself, You can download a zip file of the two modified files from here.

I also do NOT recommend copying and pasting from this HTML page. You can view or download a text file of these instructions from here.

Backup the files before modifying!

Edit Photo.php:

Add form controls in "function _edit()":

Around line 188, immediately after:

    $form->add("Photo_hidden", "select", $options);
    $form->setMatch("Photo_hidden", $hidden);
    $form->setTab("Photo_hidden", 3);

Add the following:

    // AF hack - move photo to different album
    // get album ids and labels for select list
    $sql = "SELECT id, label FROM " . PHPWS_TBL_PREFIX . "mod_photoalbum_albums WHERE 1 ORDER BY id";
    $af_result = $GLOBALS['core']->query($sql);
 
    $af_array = array();
     while ($row = $af_result->fetchrow()) {
         $af_id = $row["id"];
         $af_label = $row["label"];
         $af_array[(string)$af_id] = $af_label;
     }
     $af_result->free();

    $form->add("Af_names", "select", $af_array);
    $form->setMatch("Af_names", $this->_album);
    
    // Af hack - add checkbox for album thumbnail
    $form->add("Af_thumb", "checkbox");

This will get the album names from the DB and set up Edit form elements for a checkbox for setting the album thumbnail and the drop-down of album names for selecting an album to move the image to.

Around line 222 in the newly edited file (around line 200 in the original file), you will see:

    $tags = array();
    $tags = $form->getTemplate();

Immediately after these lines, add:

    // AF hack to display "album thumbnail" and "move" text
    $tags["AF_THUMB_TEXT"] = $_SESSION['translate']->it("Set as album thumbnail image");
    $tags["AF_MOVE_TEXT"] = $_SESSION['translate']->it("Move image to album:");

This will set up template variables for the text portion of the new form controls. I used $SESSION['translate']->it() so that translations are possible. I chose not to add these strings in "lang" files to keep the hack simple.

Around line 357 in the edited file (around line 332 in the original file), you will see:

     $_SESSION['PHPWS_AlbumManager']->album->image = "<img src=\"./images/photoalbum/$this->_album/$this->_tnname\" width=\"$this->_tnwidth\" height=\"$this->_tnheight\" border=\"0\" alt=\"" . $this->getLabel() . "\" />";
     $_SESSION['PHPWS_AlbumManager']->album->commit();

Replace these two lines with the following five lines:

         //AF hack - must explicitly select album thumbnail to update album record
         if(isset($_REQUEST['Af_thumb']) && ($_REQUEST['Af_thumb'] == "1")) {
        $_SESSION['PHPWS_AlbumManager']->album->image = "<img src=\"./images/photoalbum/$this->_album/$this->_tnname\" width=\"$this->_tnwidth\" height=\"$this->_tnheight\" border=\"0\" alt=\"" . $this->getLabel() . "\" />";
        $_SESSION['PHPWS_AlbumManager']->album->commit();
     }

This code determines if the "Set as album thumbnail.." checkbox is selected on the Edit form. If the box is checked, the image will be set as the album thumbnail.

Around line 418 in the edited file (around line 390 of the original file), you will see:

     $_REQUEST['PHPWS_Photo_op'] = "edit";
     $this->action();
     return;
    }

Immediately after these lines, add:

    //AF hack to move photo to different album

    if(isset($_REQUEST['Af_names']) && ($_REQUEST['Af_names'] != $this->_album)) {
     $af_album = $_REQUEST['Af_names'];
     $af_from_name = PHOTOALBUM_DIR . $this->_album . "/" . $this->_name;
     $af_to_name = PHOTOALBUM_DIR . $af_album . "/" . $this->_name;
     $af_from_tnname = PHOTOALBUM_DIR . $this->_album . "/" . $this->_tnname;
     $af_to_tnname = PHOTOALBUM_DIR . $af_album . "/" . $this->_tnname;
     // Check for existing photo or thumb with same name
     if ((!file_exists($af_to_name)) && (!file_exists($af_to_tnname))) {
        // rename photo & thumb, if OK - change album in DB
        if ((rename($af_from_name , $af_to_name)) && (rename($af_from_tnname, $af_to_tnname))) {
            $this->_album = $_REQUEST['Af_names'];
        }
      }
    }

This code determines if a different album than the original is selected from the "Move image to album" drop-down. If so the original image and thumbnail files are renamed (moved) to the selected album's image directory. If files with the same names exist, the files are not moved and the album is unchanged.

Around line 447 in the edited file (around line 401 in the original file), you will see:

    $sql = "UPDATE " . PHPWS_TBL_PREFIX . "mod_photoalbum_albums SET image='" . $this->getThumbnail() . "' WHERE id='" . $this->_album . "'";
    $GLOBALS['core']->query($sql);

Replace these two lines with the following five lines:

    //AF hack - only udate album thumbnail fi selected in form - NOT with every edit
    if(isset($_REQUEST['Af_thumb']) && ($_REQUEST['Af_thumb'] == "1")) {
     $sql = "UPDATE " . PHPWS_TBL_PREFIX . "mod_photoalbum_albums SET image='" . $this->getThumbnail() . "' WHERE id='" . $this->_album . "'";
     $GLOBALS['core']->query($sql);
    }

This code determines if the "Set as album thumbnail.." checkbox is selected on the "Add Photo" form. Only if the box is checked will the image will be set as the album thumbnail.

That's it for Photo.php. Save alll changes. The file, "editPhoto.tpl" in the templates directory needs to be updated to reflect the changes.

In "editPhoto.tpl", around line 24, you will see:

{EXT_TEXT}<br />
{PHOTO_EXT}<br /><br />

Immediately after these lines, add:

{AF_THUMB} {AF_THUMB_TEXT}<br /><br />

{AF_MOVE_TEXT}<br />
{AF_NAMES}<br /><br />

Save the file. Upload the new, edited, files to your site only after renaming the originals. This way, if required, you can easily revert to the originals.

Created on 08/14/2004 05:04 PM by andy
Updated on 02/25/2007 02:10 PM by andy
 Printable Version
 
Google Services

WWW   Site

 
Travel Photo
DSCN0343_tn.jpg
Montreal - 2003

View Photo
 
 
Copyright © 2002-2007 by Andy and Claire Felong
Some graphic elements © Jakob Persson
Site powered by phpWebSite