Example #1
0
function toolbox_crop_image($albumname, $imagename)
{
    $album = new Album(new Gallery(), $albumname);
    if ($album->isMyItem(ALBUM_RIGHTS)) {
        $image = newimage($album, $imagename);
        if (isImagePhoto($image)) {
            ?>
			<li>
			<a href="<?php 
            echo WEBPATH . "/" . ZENFOLDER . '/' . PLUGIN_FOLDER;
            ?>
/crop_image.php?a=<?php 
            echo pathurlencode($albumname);
            ?>
					&amp;i=<?php 
            echo urlencode($imagename);
            ?>
&amp;performcrop=frontend "><?php 
            echo gettext("Crop image");
            ?>
</a>
			</li>
			<?php 
        }
    }
}
/**
 * Prints all albums of the Zenphoto gallery as a partial drop down menu (<option></option> parts).
 *
 * @return string
 */
function printFullAlbumsList()
{
    global $_zp_gallery;
    if (is_null($_zp_gallery)) {
        $_zp_gallery = new Gallery();
    }
    $albumlist = $_zp_gallery->getAlbums();
    foreach ($albumlist as $album) {
        $albumobj = new Album($_zp_gallery, $album);
        if ($albumobj->isMyItem(LIST_RIGHTS)) {
            echo "<option value='" . pathurlencode($albumobj->name) . "'>" . html_encode($albumobj->getTitle()) . unpublishedZenphotoItemCheck($albumobj) . " (" . $albumobj->getNumImages() . ")</option>";
            if (!$albumobj->isDynamic()) {
                printSubLevelAlbums($albumobj);
            }
        }
    }
}
Example #3
0
/**
 * Creates a zip file of the album
 *
 * @param string $albumname album folder
 */
function createAlbumZip($albumname)
{
    global $_zp_zip_list, $zip_gallery;
    $zip_gallery = new Gallery();
    $album = new Album($zip_gallery, $albumname);
    if (!$album->isMyItem(LIST_RIGHTS) && !checkAlbumPassword($albumname)) {
        pageError(403, gettext("Forbidden"));
        exit;
    }
    if (!$album->exists) {
        pageError(404, gettext('Album not found'));
        exit;
    }
    $persist = $zip_gallery->getPersistentArchive();
    $dest = $album->localpath . '.zip';
    if (!$persist || !file_exists($dest)) {
        include_once 'archive.php';
        $curdir = getcwd();
        chdir($album->localpath);
        $_zp_zip_list = array();
        $z = new zip_file($dest);
        $z->set_options(array('basedir' => realpath($album->localpath . '/'), 'inmemory' => 0, 'recurse' => 0, 'storepaths' => 1));
        zipAddAlbum($album, strlen($albumname), $z);
        $z->add_files($_zp_zip_list);
        $z->create_archive();
        unset($_zp_zip_list);
        chdir($curdir);
    }
    header('Content-Type: application/zip');
    header('Content-Disposition: attachment; filename="' . pathurlencode($albumname) . '.zip"');
    header("Content-Length: " . filesize($dest));
    printLargeFileContents($dest);
    if (!$persist) {
        unlink($dest);
    }
    unset($zip_gallery);
    unset($album);
    unset($persist);
    unset($dest);
}
Example #4
0
 if (substr($folder, 0, 1) == '/') {
     $folder = substr($folder, 1);
 }
 if (substr($folder, -1) == '/') {
     $folder = substr($folder, 0, -1);
 }
 $folder = zp_apply_filter('admin_upload_process', $folder);
 $targetPath = ALBUM_FOLDER_SERVERPATH . internalToFilesystem($folder);
 $new = !is_dir($targetPath);
 if (!empty($folder)) {
     if ($new) {
         $rightsalbum = new Album($gallery, dirname($folder));
     } else {
         $rightsalbum = new Album($gallery, $folder);
     }
     if (!$rightsalbum->isMyItem(UPLOAD_RIGHTS)) {
         if (!zp_apply_filter('admin_managed_albums_access', false, $return)) {
             header('Location: ' . FULLWEBPATH . '/' . ZENFOLDER . '/admin.php');
             exit;
         }
     }
     if ($new) {
         mkdir_recursive($targetPath, CHMOD_VALUE);
         $album = new Album($gallery, $folder);
         $album->setShow($_POST['http_publishalbum']);
         $album->setTitle(sanitize($_POST['http_albumtitle']));
         $album->setOwner($_zp_current_admin_obj->getUser());
         $album->save();
     }
     @chmod($targetPath, CHMOD_VALUE);
     $error = zp_apply_filter('check_upload_quota', UPLOAD_ERR_OK, $tempFile);
Example #5
0
 /**
  * Returns an array of image names found in the search
  *
  * @param string $sorttype what to sort on
  * @param string $sortdirection what direction
  * @param bool $mine set true/false to overried ownership
  * @return array
  */
 function getSearchImages($sorttype, $sortdirection, $mine = NULL)
 {
     if (getOption('search_no_images') || $this->search_no_images) {
         return array();
     }
     $hint = '';
     $images = array();
     $searchstring = $this->getSearchString();
     $searchdate = $this->dates;
     if (empty($searchstring) && empty($searchdate)) {
         return $images;
     }
     // nothing to find
     if (empty($searchdate)) {
         $search_results = $this->searchFieldsAndTags($searchstring, 'images', $sorttype, $sortdirection);
     } else {
         $search_results = $this->SearchDate($searchstring, $searchdate, 'images', $sorttype, $sortdirection);
     }
     if (isset($search_results) && is_array($search_results)) {
         foreach ($search_results as $row) {
             $albumid = $row['albumid'];
             $query = "SELECT id, title, folder,`show` FROM " . prefix('albums') . " WHERE id = {$albumid}";
             $row2 = query_single_row($query);
             // id is unique
             $albumname = $row2['folder'];
             if (file_exists(ALBUM_FOLDER_SERVERPATH . internalToFilesystem($albumname) . '/' . internalToFilesystem($row['filename']))) {
                 $album = new Album(new gallery(), $albumname);
                 if ($mine || is_null($mine) && ($album->isMyItem(LIST_RIGHTS) || checkAlbumPassword($albumname) && $row2['show'])) {
                     if (empty($this->album_list) || in_array($albumname, $this->album_list)) {
                         $images[] = array('filename' => $row['filename'], 'folder' => $albumname);
                     }
                 }
             }
         }
     }
     if (empty($searchdate)) {
         zp_apply_filter('search_statistics', $searchstring, 'images', !empty($images), $this->dynalbumname, $this->iteration++);
     }
     return $images;
 }
/**
 * @deprecated
 */
function isMyAlbum($albumname, $action)
{
    deprecated_function_notify(gettext('Use instead the Album class method isMyItem().'), E_USER_NOTICE);
    $album = new Album(new Gallery(), $albumname);
    return $album->isMyItem($action);
}
Example #7
0
$gallery = new Gallery();
if (isset($_GET['album'])) {
    $alb = sanitize($_GET['album']);
} else {
    if (isset($_POST['album'])) {
        $alb = sanitize(urldecode($_POST['album']));
    } else {
        $alb = '';
    }
}
if ($alb) {
    $folder = sanitize_path($alb);
    $object = $folder;
    $tab = 'edit';
    $album = new Album($gallery, $folder);
    if (!$album->isMyItem(ALBUM_RIGHTS)) {
        if (!zp_apply_filter('admin_managed_albums_access', false, $return)) {
            header('Location: ' . FULLWEBPATH . '/' . ZENFOLDER . '/admin.php');
            exit;
        }
    }
} else {
    $object = '<em>' . gettext('Gallery') . '</em>';
    $tab = gettext('utilities');
}
printAdminHeader($tab, gettext('pre-cache'));
echo "\n</head>";
echo "\n<body>";
printLogoAndLinks();
echo "\n" . '<div id="main">';
printTabs();
Example #8
0
 /**
  * Gets the album's set thumbnail image from the database if one exists,
  * otherwise, finds the first image in the album or sub-album and returns it
  * as an Image object.
  *
  * @return Image
  */
 function getAlbumThumbImage()
 {
     if (!is_null($this->albumthumbnail)) {
         return $this->albumthumbnail;
     }
     $albumdir = $this->localpath;
     $thumb = $this->get('thumb');
     $i = strpos($thumb, '/');
     if ($root = $i === 0) {
         $thumb = substr($thumb, 1);
         // strip off the slash
         $albumdir = ALBUM_FOLDER_SERVERPATH;
     }
     $shuffle = empty($thumb);
     $field = getOption('AlbumThumbSelectField');
     $direction = getOption('AlbumThumbSelectDirection');
     if (!empty($thumb) && !is_numeric($thumb) && file_exists($albumdir . internalToFilesystem($thumb))) {
         if ($i === false) {
             return newImage($this, $thumb);
         } else {
             $pieces = explode('/', $thumb);
             $i = count($pieces);
             $thumb = $pieces[$i - 1];
             unset($pieces[$i - 1]);
             $albumdir = implode('/', $pieces);
             if (!$root) {
                 $albumdir = $this->name . "/" . $albumdir;
             } else {
                 $albumdir = $albumdir . "/";
             }
             $this->albumthumbnail = newImage(new Album($this->gallery, $albumdir), $thumb);
             return $this->albumthumbnail;
         }
     } else {
         $this->getImages(0, 0, $field, $direction);
         $thumbs = $this->images;
         if (!is_null($thumbs)) {
             if ($shuffle) {
                 shuffle($thumbs);
             }
             $mine = $this->isMyItem(LIST_RIGHTS);
             $other = NULL;
             while (count($thumbs) > 0) {
                 // first check for images
                 $thumb = array_shift($thumbs);
                 $thumb = newImage($this, $thumb);
                 if ($mine || $thumb->getShow()) {
                     if (isImagePhoto($thumb)) {
                         // legitimate image
                         $this->albumthumbnail = $thumb;
                         return $this->albumthumbnail;
                     } else {
                         if (!is_null($thumb->objectsThumb)) {
                             //	"other" image with a thumb sidecar
                             $this->albumthumbnail = $thumb;
                             return $this->albumthumbnail;
                         } else {
                             if (is_null($other)) {
                                 $other = $thumb;
                             }
                         }
                     }
                 }
             }
             if (!is_null($other)) {
                 //	"other" image, default thumb
                 $this->albumthumbnail = $other;
                 return $this->albumthumbnail;
             }
         }
     }
     // Otherwise, look in sub-albums.
     $subalbums = $this->getAlbums();
     if (!is_null($subalbums)) {
         if ($shuffle) {
             shuffle($subalbums);
         }
         while (count($subalbums) > 0) {
             $folder = array_pop($subalbums);
             $subalbum = new Album($this->gallery, $folder);
             $pwd = $subalbum->getPassword();
             if ($subalbum->getShow() && empty($pwd) || $subalbum->isMyItem(LIST_RIGHTS)) {
                 $thumb = $subalbum->getAlbumThumbImage();
                 if (strtolower(get_class($thumb)) !== 'transientimage' && $thumb->exists) {
                     $this->albumthumbnail = $thumb;
                     return $thumb;
                 }
             }
         }
     }
     $nullimage = SERVERPATH . '/' . ZENFOLDER . '/images/imageDefault.png';
     if (OFFSET_PATH == 0) {
         // check for theme imageDefault.png if we are in the gallery
         $theme = '';
         $uralbum = getUralbum($this);
         $albumtheme = $uralbum->getAlbumTheme();
         if (!empty($albumtheme)) {
             $theme = $albumtheme;
         } else {
             $theme = $this->gallery->getCurrentTheme();
         }
         if (!empty($theme)) {
             $themeimage = SERVERPATH . '/' . THEMEFOLDER . '/' . $theme . '/images/imageDefault.png';
             if (file_exists(internalToFilesystem($themeimage))) {
                 $nullimage = $themeimage;
             }
         }
     }
     $this->albumthumbnail = new transientimage($this, $nullimage);
     return $this->albumthumbnail;
 }
/**
 * generates a nested list of albums for the album tab sorting
 * Returns an array of "albums" each element contains:
 * 								'name' which is the folder name
 * 								'album' which is an album object for the album
 * 								'sort_order' which is an array of the sort order set
 *
 * @param $subalbum root level album (NULL is the gallery)
 * @param $levels how far to nest
 * @param $level internal for keeping the sort order elements
 * @return array
 */
function getNestedAlbumList($subalbum, $levels, $level = array())
{
    global $gallery;
    $cur = count($level);
    $levels--;
    // make it 0 relative to sync with $cur
    if (is_null($subalbum)) {
        $albums = $gallery->getAlbums();
    } else {
        $albums = $subalbum->getAlbums();
    }
    $list = array();
    foreach ($albums as $analbum) {
        $albumobj = new Album($gallery, $analbum);
        if (!is_null($subalbum) || $albumobj->isMyItem(ALBUM_RIGHTS)) {
            $level[$cur] = sprintf('%03u', $albumobj->getSortOrder());
            $list[] = array('name' => $analbum, 'sort_order' => $level);
            if ($cur < $levels && $albumobj->getNumAlbums() > 0 && !$albumobj->isDynamic()) {
                $list = array_merge($list, getNestedAlbumList($albumobj, $levels + 1, $level));
            }
        }
    }
    return $list;
}
Example #10
0
echo "\n" . '<div id="main">';
printTabs();
echo "\n" . '<div id="content">';
$galleryTheme = $gallery->getCurrentTheme();
$themelist = array();
if (zp_loggedin(ADMIN_RIGHTS)) {
    $gallery_title = $gallery->getTitle();
    if ($gallery_title != gettext("Gallery")) {
        $gallery_title .= ' (' . gettext("Gallery") . ')';
    }
    $themelist[$gallery_title] = '';
}
$albums = $gallery->getAlbums(0);
foreach ($albums as $alb) {
    $album = new Album($gallery, $alb);
    if ($album->isMyItem(THEMES_RIGHTS)) {
        $key = $album->getTitle();
        if ($key != $alb) {
            $key .= " ({$alb})";
        }
        $themelist[$key] = $alb;
    }
}
if (!empty($_REQUEST['themealbum'])) {
    $alb = sanitize_path($_REQUEST['themealbum']);
    $album = new Album($gallery, $alb);
    $albumtitle = $album->getTitle();
    $themename = $album->getAlbumTheme();
    $current_theme = $themename;
} else {
    $current_theme = $galleryTheme;
/**
 * Returns  a randomly selected image from the album or its subalbums. (May be NULL if none exists)
 *
 * @param mixed $rootAlbum optional album object/folder from which to get the image.
 * @param bool $daily set to true to change picture only once a day.
 * @param bool $showunpublished set true to consider all images
 *
 * @return object
 */
function getRandomImagesAlbum($rootAlbum = NULL, $daily = false, $showunpublished = false)
{
    global $_zp_current_album, $_zp_gallery, $_zp_current_search;
    if (empty($rootAlbum)) {
        $album = $_zp_current_album;
    } else {
        if (is_object($rootAlbum)) {
            $album = $rootAlbum;
        } else {
            $album = new Album($_zp_gallery, $rootAlbum);
        }
    }
    if ($daily && ($potd = getOption('picture_of_the_day:' . $album->name))) {
        $potd = unserialize($potd);
        if (date('Y-m-d', $potd['day']) == date('Y-m-d')) {
            $rndalbum = new Album($_zp_gallery, $potd['folder']);
            $image = newImage($rndalbum, $potd['filename']);
            if ($image->exists) {
                return $image;
            }
        }
    }
    $image = NULL;
    if ($album->isDynamic()) {
        $images = $album->getImages(0);
        shuffle($images);
        while (count($images) > 0) {
            $result = array_pop($images);
            if (is_valid_image($result['filename'])) {
                $image = newImage(new Album(new Gallery(), $result['folder']), $result['filename']);
            }
        }
    } else {
        $albumfolder = $album->getFolder();
        if ($album->isMyItem(LIST_RIGHTS) || $showunpublished) {
            $imageWhere = '';
            $albumNotWhere = '';
            $albumInWhere = '';
        } else {
            $imageWhere = " AND " . prefix('images') . ".show=1";
            $albumNotWhere = getProtectedAlbumsWhere();
            $albumInWhere = prefix('albums') . ".show=1";
        }
        $query = "SELECT id FROM " . prefix('albums') . " WHERE ";
        if ($albumInWhere) {
            $query .= $albumInWhere . ' AND ';
        }
        $query .= "folder LIKE " . db_quote($albumfolder . '%');
        $result = query_full_array($query);
        if (is_array($result) && count($result) > 0) {
            $albumInWhere = prefix('albums') . ".id in (";
            foreach ($result as $row) {
                $albumInWhere = $albumInWhere . $row['id'] . ", ";
            }
            $albumInWhere = ' AND ' . substr($albumInWhere, 0, -2) . ')';
            $c = 0;
            while (is_null($image) && $c < 10) {
                $result = query_single_row('SELECT COUNT(*) AS row_count ' . ' FROM ' . prefix('images') . ', ' . prefix('albums') . ' WHERE ' . prefix('albums') . '.folder!="" AND ' . prefix('images') . '.albumid = ' . prefix('albums') . '.id ' . $albumInWhere . $albumNotWhere . $imageWhere);
                $rand_row = rand(0, $result['row_count'] - 1);
                $result = query_single_row('SELECT ' . prefix('images') . '.filename, ' . prefix('albums') . '.folder ' . ' FROM ' . prefix('images') . ', ' . prefix('albums') . ' WHERE ' . prefix('images') . '.albumid = ' . prefix('albums') . '.id  ' . $albumInWhere . $albumNotWhere . $imageWhere . ' LIMIT ' . $rand_row . ', 1');
                $imageName = $result['filename'];
                if (is_valid_image($imageName)) {
                    $image = newImage(new Album(new Gallery(), $result['folder']), $imageName);
                }
                $c++;
            }
        }
    }
    if ($daily && is_object($image)) {
        $potd = array('day' => time(), 'folder' => $result['folder'], 'filename' => $result['filename']);
        setThemeOption('picture_of_the_day:' . $album->name, serialize($potd));
    }
    return $image;
}
Example #12
0
 /**
  * Sort the album array based on either according to the sort key.
  * Default is to sort on the `sort_order` field.
  *
  * Returns an array with the albums in the desired sort order
  *
  * @param  array $albums array of album names
  * @param  string $sortkey the sorting scheme
  * @param string $sortdirection
  * @param bool $mine set true/false to override ownership
  * @return array
  *
  * @author Todd Papaioannou (lucky@luckyspin.org)
  * @since  1.0.0
  */
 function sortAlbumArray($parentalbum, $albums, $sortkey = '`sort_order`', $sortdirection = NULL, $mine = NULL)
 {
     if (is_null($parentalbum)) {
         $albumid = ' IS NULL';
         $obj = $this;
     } else {
         $albumid = '=' . $parentalbum->id;
         $obj = $parentalbum;
     }
     if ($sortkey == '`sort_order`' || $sortkey == 'RAND()') {
         // manual sort is always ascending
         $order = false;
     } else {
         if (!is_null($sortdirection)) {
             $order = strtoupper($sortdirection) == 'DESC';
         } else {
             $order = $obj->getSortDirection('album');
         }
     }
     if (count($albums) == 0) {
         return array();
     }
     $sql = 'SELECT * FROM ' . prefix("albums") . ' WHERE `parentid`' . $albumid;
     $result = query($sql);
     $results = array();
     while ($row = db_fetch_assoc($result)) {
         $results[$row['folder']] = $row;
     }
     //	check database aganist file system
     foreach ($results as $dbrow => $row) {
         $folder = $row['folder'];
         if (($key = array_search($folder, $albums)) !== false) {
             // album exists in filesystem
             unset($albums[$key]);
         } else {
             // album no longer exists
             $id = $row['id'];
             query("DELETE FROM " . prefix('albums') . " WHERE `id`={$id}");
             // delete the record
             query("DELETE FROM " . prefix('comments') . " WHERE `type` ='images' AND `ownerid`= '{$id}'");
             // remove image comments
             query("DELETE FROM " . prefix('obj_to_tag') . "WHERE `type`='albums' AND `objectid`=" . $id);
             query("DELETE FROM " . prefix('albums') . " WHERE `id` = " . $id);
             unset($results[$dbrow]);
         }
     }
     foreach ($albums as $folder) {
         // these albums are not in the database
         $albumobj = new Album($this, $folder);
         if ($albumobj->exists) {
             // fail to instantiate?
             $results[$folder] = $albumobj->data;
         }
     }
     //	now put the results in the right order
     $results = sortByKey($results, $sortkey, $order);
     //	albums are now in the correct order
     $albums_ordered = array();
     foreach ($results as $row) {
         // check for visible
         $folder = $row['folder'];
         $album = new Album($this, $folder);
         if ($row['show'] || $mine || is_null($mine) && $album->isMyItem(LIST_RIGHTS)) {
             $albums_ordered[] = $folder;
         }
     }
     return $albums_ordered;
 }
Example #13
0
/**
 * Returns a list of album IDs that the current viewer is allowed to see
 *
 * @return array
 */
function getNotViewableAlbums()
{
    global $_zp_not_viewable_album_list;
    if (zp_loggedin(ADMIN_RIGHTS | MANAGE_ALL_ALBUM_RIGHTS)) {
        return array();
    }
    //admins can see all
    $hint = '';
    $gallery = new Gallery();
    if (is_null($_zp_not_viewable_album_list)) {
        $sql = 'SELECT `folder`, `id`, `password`, `show` FROM ' . prefix('albums') . ' WHERE `show`=0 OR `password`!=""';
        $result = query_full_array($sql);
        if (is_array($result)) {
            $_zp_not_viewable_album_list = array();
            foreach ($result as $row) {
                if (checkAlbumPassword($row['folder'])) {
                    $album = new Album($gallery, $row['folder']);
                    if (!($row['show'] || $album->isMyItem(LIST_RIGHTS))) {
                        $_zp_not_viewable_album_list[] = $row['id'];
                    }
                } else {
                    $_zp_not_viewable_album_list[] = $row['id'];
                }
            }
        }
    }
    return $_zp_not_viewable_album_list;
}
Example #14
0
/**
 * Prints the slideshow using the jQuery plugin Cycle (http://http://www.malsup.com/jquery/cycle/)
 * or Flash based using Flowplayer3 http://flowplayer.org if installed
 *
 * Two ways to use:
 * a) Use on your theme's slideshow.php page and called via printSlideShowLink():
 * If called from image.php it starts with that image, called from album.php it starts with the first image (jQuery only)
 * To be used on slideshow.php only and called from album.php or image.php.
 *
 * b) Calling directly via printSlideShow() function (jQuery mode recommended)
 * Call printSlideShowJS() function in the head section of the theme page you want to use the slideshow on.
 * Then place the printSlideShow() function where you want the slideshow to appear and set $albumobj and if needed $imageobj.
 * The controls are disabled automatically.
 *
 * NOTE: The jQuery mode does not support movie and audio files anymore. If you need to show them please use the Flash mode.
 * Also note that this function is not used for the Colorbox mode!
 *
 * @param bool $heading set to true (default) to emit the slideshow breadcrumbs in flash mode
 * @param bool $speedctl controls whether an option box for controlling transition speed is displayed
 * @param obj $albumobj The object of the album to show the slideshow of. If set this overrides the POST data of the printSlideShowLink()
 * @param obj $imageobj The object of the image to start the slideshow with. If set this overrides the POST data of the printSlideShowLink(). If not set the slideshow starts with the first image of the album.
 * @param int $width The width of the images (jQuery mode). If set this overrides the size the slideshow_width plugin option that otherwise is used.
 * @param int $height The heigth of the images (jQuery mode). If set this overrides the size the slideshow_height plugin option that otherwise is used.
 * @param bool $crop Set to true if you want images cropped width x height (jQuery mode only)
 * @param bool $shuffle Set to true if you want random (shuffled) order
 * */
function printSlideShow($heading = true, $speedctl = false, $albumobj = "", $imageobj = "", $width = "", $height = "", $crop = false, $shuffle = false)
{
    if (!isset($_POST['albumid']) and !is_object($albumobj)) {
        echo "<div class=\"errorbox\" id=\"message\"><h2>" . gettext("Invalid linking to the slideshow page.") . "</h2></div>";
        echo "</div></body></html>";
        exit;
    }
    global $_zp_flash_player, $_zp_current_image, $_zp_current_album, $_zp_gallery;
    $imagenumber = 0;
    //getting the image to start with
    if (!empty($_POST['imagenumber']) and !is_object($imageobj)) {
        $imagenumber = sanitize_numeric($_POST['imagenumber']) - 1;
        // slideshows starts with 0, but zp with 1.
    } elseif (is_object($imageobj)) {
        makeImageCurrent($imageobj);
        $imagenumber = imageNumber() - 1;
    }
    // set pagenumber to 0 if not called via POST link
    if (isset($_POST['pagenr'])) {
        $pagenumber = sanitize_numeric($_POST['pagenr']);
    } else {
        $pagenumber = 0;
    }
    // getting the number of images
    if (!empty($_POST['numberofimages'])) {
        $numberofimages = sanitize_numeric($_POST['numberofimages']);
    } elseif (is_object($albumobj)) {
        $numberofimages = $albumobj->getNumImages();
    } else {
        $numberofimages = 0;
    }
    if ($imagenumber < 2 || $imagenumber > $numberofimages) {
        $imagenumber = 0;
    }
    //getting the album to show
    if (!empty($_POST['albumid']) and !is_object($albumobj)) {
        $albumid = sanitize_numeric($_POST['albumid']);
    } elseif (is_object($albumobj)) {
        $albumid = $albumobj->id;
    } else {
        $albumid = -1;
    }
    // setting the image size
    if (!empty($width) and !empty($height)) {
        $width = sanitize_numeric($width);
        $height = sanitize_numeric($height);
    } else {
        $width = getOption("slideshow_width");
        $height = getOption("slideshow_height");
    }
    if ($numberofimages == 0) {
        return NULL;
    }
    $option = getOption("slideshow_mode");
    // jQuery Cycle slideshow config
    // get slideshow data
    $gallery = new Gallery();
    if ($albumid <= 0) {
        // search page
        $dynamic = 2;
        $search = new SearchEngine();
        $params = sanitize($_POST['preserve_search_params']);
        $search->setSearchParams($params);
        $images = $search->getImages(0);
        $searchwords = $search->words;
        $searchdate = $search->dates;
        $searchfields = $search->getSearchFields(true);
        $page = $search->page;
        if (empty($_POST['imagenumber'])) {
            $albumq = query_single_row("SELECT title, folder FROM " . prefix('albums') . " WHERE id = " . abs($albumid));
            $album = new Album($gallery, $albumq['folder']);
            $returnpath = getSearchURL($searchwords, $searchdate, $searchfields, $page);
            //$returnpath = rewrite_path('/'.pathurlencode($album->name).'/page/'.$pagenumber,'/index.php?album='.urlencode($album->name).'&page='.$pagenumber);
        } else {
            $returnpath = getSearchURL($searchwords, $searchdate, $searchfields, $page);
        }
        $albumtitle = gettext('Search');
    } else {
        $albumq = query_single_row("SELECT title, folder FROM " . prefix('albums') . " WHERE id = " . $albumid);
        $album = new Album($gallery, $albumq['folder']);
        $albumtitle = $album->getTitle();
        if (!$album->isMyItem(LIST_RIGHTS) && !checkAlbumPassword($albumq['folder'])) {
            echo gettext("This album is password protected!");
            exit;
        }
        $dynamic = $album->isDynamic();
        $images = $album->getImages(0);
        // return path to get back to the page we called the slideshow from
        if (empty($_POST['imagenumber'])) {
            $returnpath = rewrite_path('/' . pathurlencode($album->name) . '/page/' . $pagenumber, '/index.php?album=' . urlencode($album->name) . '&page=' . $pagenumber);
        } else {
            $returnpath = rewrite_path('/' . pathurlencode($album->name) . '/' . rawurlencode(sanitize($_POST['imagefile'])) . getOption('mod_rewrite_image_suffix'), '/index.php?album=' . urlencode($album->name) . '&image=' . urlencode($_POST['imagefile']));
        }
    }
    if ($shuffle) {
        shuffle($images);
    }
    $showdesc = getOption("slideshow_showdesc");
    // slideshow display section
    switch ($option) {
        case "jQuery":
            $validtypes = array('jpg', 'jpeg', 'gif', 'png', 'mov', '3gp');
            ?>
			<script type="text/javascript">
				// <!-- <![CDATA[
				$(document).ready(function(){
					$(function() {
						var ThisGallery = '<?php 
            echo html_encode($albumtitle);
            ?>
';
						var ImageList = new Array();
						var TitleList = new Array();
						var DescList = new Array();
						var ImageNameList = new Array();
						var DynTime=(<?php 
            echo getOption("slideshow_timeout");
            ?>
) * 1.0;	// force numeric
						<?php 
            for ($imgnr = 0, $cntr = 0, $idx = $imagenumber; $imgnr < $numberofimages; $imgnr++, $idx++) {
                if ($dynamic) {
                    $filename = $images[$idx]['filename'];
                    $album = new Album($gallery, $images[$idx]['folder']);
                    $image = newImage($album, $filename);
                } else {
                    $filename = $images[$idx];
                    $image = newImage($album, $filename);
                }
                $ext = is_valid($filename, $validtypes);
                if ($ext) {
                    makeImageCurrent($image);
                    if ($crop) {
                        $img = getCustomImageURL(NULL, $width, $height, $width, $height);
                    } else {
                        $img = getCustomSizedImageMaxSpace($width, $height);
                    }
                    //$img = WEBPATH . '/' . ZENFOLDER . '/i.php?a=' . pathurlencode($image->album->name) . '&i=' . pathurlencode($filename) . '&s=' . $imagesize;
                    echo 'ImageList[' . $cntr . '] = "' . $img . '";' . "\n";
                    echo 'TitleList[' . $cntr . '] = "' . js_encode($image->getTitle()) . '";' . "\n";
                    if ($showdesc) {
                        $desc = $image->getDesc();
                        $desc = str_replace("\r\n", '<br />', $desc);
                        $desc = str_replace("\r", '<br />', $desc);
                        echo 'DescList[' . $cntr . '] = "' . js_encode($desc) . '";' . "\n";
                    } else {
                        echo 'DescList[' . $cntr . '] = "";' . "\n";
                    }
                    if ($idx == $numberofimages - 1) {
                        $idx = -1;
                    }
                    echo 'ImageNameList[' . $cntr . '] = "' . urlencode($filename) . '";' . "\n";
                    $cntr++;
                }
            }
            echo "\n";
            $numberofimages = $cntr;
            ?>
						var countOffset = <?php 
            echo $imagenumber;
            ?>
;
						var totalSlideCount = <?php 
            echo $numberofimages;
            ?>
;
						var currentslide = 2;

						function onBefore(curr, next, opts) {
							if (opts.timeout != DynTime) {
								opts.timeout = DynTime;
							}
							if (!opts.addSlide)
								return;

							var currentImageNum = currentslide;
							currentslide++;
							if (currentImageNum == totalSlideCount) {
								opts.addSlide = null;
								return;
							}
							var relativeSlot = (currentslide + countOffset) % totalSlideCount;
							if (relativeSlot == 0) {relativeSlot = totalSlideCount;}
							var htmlblock = "<span class='slideimage'><h4><strong>" + ThisGallery + ":</strong> ";
							htmlblock += TitleList[currentImageNum]  + " (" + relativeSlot + "/" + totalSlideCount + ")</h4>";
							htmlblock += "<img src='" + ImageList[currentImageNum] + "'/>";
							htmlblock += "<p class='imgdesc'>" + DescList[currentImageNum] + "</p></span>";
							opts.addSlide(htmlblock);
						}

						function onAfter(curr, next, opts){
							<?php 
            if (!$album->isMyItem(LIST_RIGHTS)) {
                ?>
							//Only register at hit count the first time the image is viewed.
							if ($(next).attr( 'viewed') != 1) {
								$.get("<?php 
                echo FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER;
                ?>
/slideshow/slideshow-counter.php?album=<?php 
                echo pathurlencode($album->name);
                ?>
&img="+ImageNameList[opts.currSlide]);
								$(next).attr( 'viewed', 1 );
							}
							<?php 
            }
            ?>
						}

						$('#slides').cycle({
								fx:     '<?php 
            echo getOption("slideshow_effect");
            ?>
',
								speed:   <?php 
            echo getOption("slideshow_speed");
            ?>
,
								timeout: DynTime,
								next:   '#next',
								prev:   '#prev',
								cleartype: 1,
								before: onBefore,
								after: onAfter
						});

						$('#speed').change(function () {
							DynTime = this.value;
							return false;
						});

						$('#pause').click(function() { $('#slides').cycle('pause'); return false; });
						$('#play').click(function() { $('#slides').cycle('resume'); return false; });
					});

				});	// Documentready()
				// ]]> -->
			</script>
				<div id="slideshow" align="center">
				<?php 
            // 7/21/08dp
            if ($speedctl) {
                echo '<div id="speedcontrol">';
                // just to keep it away from controls for sake of this demo
                $minto = getOption("slideshow_speed");
                while ($minto % 500 != 0) {
                    $minto += 100;
                    if ($minto > 10000) {
                        break;
                    }
                    // emergency bailout!
                }
                $dflttimeout = getOption("slideshow_timeout");
                /* don't let min timeout = speed */
                $thistimeout = $minto == getOption("slideshow_speed") ? $minto + 250 : $minto;
                echo 'Select Speed: <select id="speed" name="speed">';
                while ($thistimeout <= 60000) {
                    // "around" 1 minute :)
                    echo "<option value={$thistimeout} " . ($thistimeout == $dflttimeout ? " selected='selected'>" : ">") . round($thistimeout / 1000, 1) . " sec</option>";
                    /* put back timeout to even increments of .5 */
                    if ($thistimeout % 500 != 0) {
                        $thistimeout -= 250;
                    }
                    $thistimeout += $thistimeout < 1000 ? 500 : ($thistimeout < 10000 ? 1000 : 5000);
                }
                echo "</select> </div>";
            }
            if (!is_object($albumobj)) {
                // disable controls if calling the slideshow directly on homepage for example
                ?>
				<div id="controls">
				<div><span><a href="#" id="prev"
					title="<?php 
                echo gettext("Previous");
                ?>
"></a></span> <a
					href="<?php 
                echo html_encode($returnpath);
                ?>
" id="stop"
					title="<?php 
                echo gettext("Stop and return to album or image page");
                ?>
"></a>
				<a href="#" id="pause"
					title="<?php 
                echo gettext("Pause (to stop the slideshow without returning)");
                ?>
"></a>
				<a href="#" id="play" title="<?php 
                echo gettext("Play");
                ?>
"></a> <a
					href="#" id="next" title="<?php 
                echo gettext("Next");
                ?>
"></a>
				</div>
				</div>
				<?php 
            }
            ?>
				<div id="slides" class="pics">
				<?php 
            if ($cntr > 1) {
                $cntr = 1;
            }
            for ($imgnr = 0, $idx = $imagenumber; $imgnr <= $cntr; $idx++) {
                if ($idx >= $numberofimages) {
                    $idx = 0;
                }
                if ($dynamic) {
                    $folder = $images[$idx]['folder'];
                    $dalbum = new Album($gallery, $folder);
                    $filename = $images[$idx]['filename'];
                    $image = newImage($dalbum, $filename);
                    $imagepath = FULLWEBPATH . ALBUM_FOLDER_EMPTY . pathurlencode($folder) . "/" . urlencode($filename);
                } else {
                    $folder = $album->name;
                    $filename = $images[$idx];
                    //$filename = $animage;
                    $image = newImage($album, $filename);
                    $imagepath = FULLWEBPATH . ALBUM_FOLDER_EMPTY . pathurlencode($folder) . "/" . urlencode($filename);
                }
                $ext = is_valid($filename, $validtypes);
                if ($ext) {
                    $imgnr++;
                    echo "<span class='slideimage'><h4><strong>" . $albumtitle . gettext(":") . "</strong> " . $image->getTitle() . " (" . ($idx + 1) . "/" . $numberofimages . ")</h4>";
                    if ($ext == "3gp") {
                        echo '</a>
										<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="352" height="304" codebase="http://www.apple.com/qtactivex/qtplugin.cab">
										<param name="src" value="' . $imagepath . '"/>
										<param name="autoplay" value="false" />
										<param name="type" value="video/quicktime" />
										<param name="controller" value="true" />
										<embed src="' . $imagepath . '" width="352" height="304" autoplay="false" controller"true" type="video/quicktime"
										pluginspage="http://www.apple.com/quicktime/download/" cache="true"></embed>
										</object>
										<a>';
                    } elseif ($ext == "mov") {
                        echo '</a>
										<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="640" height="496" codebase="http://www.apple.com/qtactivex/qtplugin.cab">
										<param name="src" value="' . $imagepath . '"/>
										<param name="autoplay" value="false" />
										<param name="type" value="video/quicktime" />
										<param name="controller" value="true" />
										<embed src="' . $imagepath . '" width="640" height="496" autoplay="false" controller"true" type="video/quicktime"
										pluginspage="http://www.apple.com/quicktime/download/" cache="true"></embed>
										</object>
										<a>';
                    } else {
                        makeImageCurrent($image);
                        if ($crop) {
                            printCustomSizedImage('', NULL, $width, $height, $width, $height, NULL, NULL, NULL, NULL, false);
                        } else {
                            printCustomSizedImageMaxSpace($alt = '', $width, $height, NULL, NULL, false);
                        }
                        //echo "<img src='".WEBPATH."/".ZENFOLDER."/i.php?a=".pathurlencode($folder)."&i=".urlencode($filename)."&s=".$imagesize."' alt='".html_encode($image->getTitle())."' title='".html_encode($image->getTitle())."' />\n";
                    }
                    if ($showdesc) {
                        $desc = $image->getDesc();
                        $desc = str_replace("\r\n", '<br />', $desc);
                        $desc = str_replace("\r", '<br />', $desc);
                        echo "<p class='imgdesc'>" . $desc . "</p>";
                    }
                    echo "</span>";
                }
            }
            break;
        case "flash":
            if ($heading) {
                echo "<span class='slideimage'><h4><strong>" . $albumtitle . "</strong> (" . $numberofimages . " images) | <a style='color: white' href='" . html_encode($returnpath) . "' title='" . gettext("back") . "'>" . gettext("back") . "</a></h4>";
            }
            echo "<span id='slideshow' style='display: block; margin: 0 auto; width:" . getOption('slideshow_flow_player_width') . "px; height: " . getOption('slideshow_flow_player_height') . "px'></span>";
            $curdir = getcwd();
            chdir(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/flowplayer3');
            $filelist = safe_glob('flowplayer-*.swf');
            $swf = array_shift($filelist);
            $filelist = safe_glob('flowplayer.controls-*.swf');
            $controls = array_shift($filelist);
            chdir($curdir);
            ?>
			<script type="text/javascript">
			// <!-- <![CDATA[
			flowplayer('slideshow','<?php 
            echo FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER;
            ?>
/flowplayer3/<?php 
            echo $swf;
            ?>
', {

			clip: {
					onLastSecond: function() {
					this.getScreen().animate({opacity: 0}, <?php 
            echo getOption('slideshow_speed') / 2;
            ?>
);
					},
					onFinish: function(){
					this.getScreen().animate({opacity: 1}, 1000);
					},
					onStart: function() {
					this.getScreen().animate({opacity: 1}, <?php 
            echo getOption('slideshow_speed') / 2;
            ?>
);
					}
						},

			playlist: [
			<?php 
            echo "\n";
            $count = 0;
            foreach ($images as $animage) {
                if ($dynamic) {
                    $folder = $animage['folder'];
                    $filename = $animage['filename'];
                    $salbum = new Album($_zp_gallery, $folder);
                    $image = newImage($salbum, $filename);
                    $imagepath = FULLWEBPATH . ALBUM_FOLDER_EMPTY . pathurlencode($salbum->name) . "/" . urlencode($filename);
                } else {
                    $folder = $album->name;
                    $filename = $animage;
                    $image = newImage($album, $filename);
                    $imagepath = FULLWEBPATH . ALBUM_FOLDER_EMPTY . pathurlencode($folder) . "/" . pathurlencode($filename);
                }
                $ext = is_valid($filename, array('jpg', 'jpeg', 'gif', 'png', 'flv', 'mp3', 'mp4'));
                if ($ext) {
                    if ($ext == "flv" || $ext == "mp3" || $ext == "mp4") {
                        $duration = "";
                    } else {
                        $duration = ", duration: " . getOption("slideshow_timeout") / 1000;
                    }
                    if ($count > 0) {
                        echo ",\n";
                    }
                    echo "{ url: '" . FULLWEBPATH . ALBUM_FOLDER_EMPTY . pathurlencode($folder) . "/" . urlencode($filename) . "'" . $duration . ", scaling: 'fit', autoBuffering: true }";
                    $count++;
                }
            }
            echo "\n";
            ?>
		],
		plugins:  {
				controls: {
					url: '<?php 
            echo FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER;
            ?>
/flowplayer3/<?php 
            echo $controls;
            ?>
',
						playlist: true,
						autoHide: 'always'
				}
		}
										});
			// ]]> -->
		</script>
			<?php 
            echo "</span>";
            echo "<p>";
            echo gettext("Click on the right in the player control bar to view full size.");
            echo "</p>";
            break;
    }
    ?>
	</div>
</div>
	<?php 
    restore_context();
    // needed if the slideshow is for example called directly via album object before the next_album loop on index.php
}