SimpleViewerAdmin Mods
I designed a website for a friend, who wanted to use SimpleViewer for his portfolio. I wanted a dynamic gallery, rather than a static one requiring him to use, for example, Picasa to manage the gallery and then upload it. Thus I searched and came upon SimpleViewerAdmin.
He requested a hidden album feature such that the album can only be accessed directly through its URL.
Note: The following mod is based on SimpleViewer 1.7 and SimpleViewerAdmin 1.3. Also, line numbers refer to those in the original file, and should be used as a guide, and not an exact indicator.
Hidden Album Mod
The first step is to edit
(lines 109-117) to add an ”
” value to the default XML file.
// After parsing the configuration data, init a basic XML template. $simpleViewer['basicXMLTemplate'] = '<?xml version="1.0" encoding="UTF-8"?> <SIMPLEVIEWER_DATA maxImageDimension="' . $simpleViewer['maxImageDimension'] . '" textColor="' . $simpleViewer['textColor'] . '" frameColor="' . $simpleViewer['frameColor'] . '" backgroundColor="' . $simpleViewer['backgroundColor'] . '" frameWidth="' . $simpleViewer['frameWidth'] . '" stagePadding="' . $simpleViewer['stagePadding'] . '" thumbnailColumns="' . $simpleViewer['thumbnailColumns'] . '" thumbnailRows="' . $simpleViewer['thumbnailRows'] . '" navPosition="' . $simpleViewer['navPosition'] . '" navDirection="' . $simpleViewer['navDirection'] . '" isPublished="false" isHidden="false" title="" imagePath="" thumbPath=""> </SIMPLEVIEWER_DATA>';
Note that for existing albums, the XML file must be edited manually to add the
portion.
The next file to edit is
.
At the end of the file, add a function called
.
// {{{ isHidden() /** * Indicates whether or not an album is hidden. * * @param string $albumName name of the album to check * @return boolean * @access public * @author Jonathan Giam */ function isHidden($albumName) { if (empty($albumName)) { die('Give me an album name to check.'); } $config = getConfig($albumName . '/imageData.xml'); return $config["isHidden"] == 'true'; } // }}}
This function checks if an album has been marked as hidden.
The next file is
.
After line 131, add a simple check:
if ($xmlData['isHidden'] == "true") continue;
Simply put, if an album has been marked as hidden, then it will not be displayed.
To handle the left/right album navigation links, lines 35-37 and 44-46 need to be modified as below.
// Get the previous album. $i=$k; while (array_key_exists(--$i, $dirList['List'])) { if (!isHidden($dirList['List'][$i])) { $previous = $dirList['List'][$i]; $previousAlbum = getConfig('./' . $previous . '/imageData.xml'); break; } } // Get the next album. $i=$k; while (array_key_exists(++$i, $dirList['List'])) { if (!isHidden($dirList['List'][$i])) { $next = $dirList['List'][$i]; $nextAlbum = getConfig('./' . $next . '/imageData.xml'); break; } }
The code will iterate through the list of albums until it finds one that is not hidden.
Finally, the
file.
Because a hidden album can only be accessed directly via its URL, the URL to the album needs to be displayed in the Admin page. Add the following code at line 391.
echo '<p>Album URL: <a href="http://'.$_SERVER['SERVER_NAME'].'/?album='.$name.'">http://'.$_SERVER['SERVER_NAME'].'/?album='.$name.'</a></p>';
This displays the URL to the album on the Admin page. Note that you might need to edit the URLs above depending on where you put your SimpleViewer files.
And the following code (line 592) adds a "(hidden)" text in the album list for hidden albums.
echo '<li><a href="?action=edit&file=album&name=' . $v . '">' . ((isPhpOfVersion(5) == -1) ? utf8_encode($xmlData['title']) : $xmlData['title']) . "</a>".(($xmlData['isHidden'] == "true") ? " (hidden)" : "")."</li>\n";
ZIP Archive Mod
This is a more interesting mod. My friend requested the ability to upload many images at once. Because of the dynamic nature of SimpleViewerAdmin, there was no point in giving him FTP access to upload the photos. Instead, I worked on providing ZIP upload.
ZIP handling is not built into PHP by default. Luckily, I found the PclZip library by PhpConcept.
The main code is shown below, and needs to be added after line 482 of
. Of course, you will need to place
in the same directory as this file.
// Mod by Jonathan Giam to handle ZIP files // is this a ZIP file? if (stristr($_FILES['file']['type'], 'zip')) { require_once("pclzip.lib.php"); $archive = new PclZip($_FILES['file']['tmp_name']); // extract only jpg/png/gif $status = $archive->extract(PCLZIP_OPT_PATH, '/tmp/furry-photos', PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_BY_PREG, "/^(.*).((jpg)|(png)|(gif))$/"); if ($status != 0) { $count = count($status); $_SESSION['statusMsg'][] = $count.' images found in '.$_FILES['file']['name']; // Loop through and create the images foreach($status as $imagefile) { $imageName = $imagefile['stored_filename']; $format = substr($imageName, (strpos($imageName, ".")+1)); $destFile = $_SESSION['currentDir'] . 'images/' . substr($imageName, 0, strpos($imageName, ".", 1)) .".jpg"; // Create the image if (createImage($imagefile['filename'], $format, 'images', $destFile)) { $_SESSION['statusMsg'][] = 'The image, '.$imageName.', was saved.'; // Create the thumbnail. if (createImage($imagefile['filename'], $format, 'thumbs', str_replace('images', 'thumbs', $destFile))) { $_SESSION['statusMsg'][] = ' - The preview thumbnail was created.'; $captionText = $_POST['name']; if (!empty($_POST['autoCaption'])) { $captionText = '<a href="' . $destFile . '" target="_blank"><u>Open image in new window</u></a>'; } // Update the XML file. saveImageToXML($_SESSION['currentDir'] . 'images/' . $imageName, $captionText); } else { $_SESSION['statusMsg'][] = ' - The preview thumbnail could not be created.'; } // The image could be created. } else { $_SESSION['statusMsg'][] = 'Could not save the image '.$imagefile['stored_filename'].'.'; } } // end foreach } else { $_SESSION['statusMsg'][] = 'Could not extract files from '.$_FILES['file']['name']; } } // end mod
The code is quite intuitive (I believe). First, it checks if the uploaded file is of type "
". If it is, the PclZip library is loaded, and the files are extracted. The options above are to get it to extract to a specified temporary directory (can be changed to suit your needs), and directories in the ZIP file are ignored. Finally, the regular expression
will only extract files with extensions of JPG, GIF or PNG.
On a successful extraction,
is an array with properties of the extracted files. The
iterates through
and adds the image to the album. The code segment is taken from the original, with the variable names modified accordingly. This results in some redundancy, and I’m sure the code can be optimised. However, my aim was to minimise changes to the original code.
It should also be noted that the code is rather naïve, and does not perform checks to verify the files. However, the original code also did not perform proper checking, instead, assuming image type through the extension only. Thus I decided to keep my code in line with the original style.
After that, an
should be added to the following
statement.
// Check the uploaded image's file type. else if (stristr($_FILES['file']['type'], 'image')) {
To display that
files are allowed to be uploaded, the
function needs to be modified.
After line 920, add:
$gd['formats']['zip'] = 0;
And after line 939, add:
$gd['formats']['zip'] = true;
Credit
If you use the above modifications, you are kindly requested to include the following in
anywhere between lines 539-543.
<li>Hidden Album and ZIP Archive mod by <a href="http://jgiam.com/" target="_blank">Jon G ↑</a></li> <li>PclZip Library by <a href="http://www.phpconcept.net/pclzip/index.en.php" target="_blank">PhpConcept ↑</a></li>
Finally, in line with the SimpleViewerAdmin License, the above modifications are released under the Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Licence.