/**
 * support to show an image from an album
 * The imagename is optional. If absent the album thumb image will be
 * used and the link will be to the album. If present the link will be
 * to the image.
 *
 * @param string $albumname
 * @param string $imagename
 * @param int $size the size to make the image. If omitted image will be 50% of 'image_size' option.
 * @param bool $linkalbum set true to link specific image to album instead of image
 */
function zenpageAlbumImage($albumname, $imagename = NULL, $size = NULL, $linkalbum = false)
{
    global $_zp_gallery;
    echo '<br />';
    $album = new Album($_zp_gallery, $albumname);
    if ($album->loaded) {
        if (is_null($size)) {
            $size = floor(getOption('image_size') * 0.5);
        }
        $image = NULL;
        if (is_null($imagename)) {
            $linkalbum = true;
            $image = $album->getAlbumThumbImage();
        } else {
            $image = newImage($album, $imagename);
        }
        if ($image && $image->loaded) {
            makeImageCurrent($image);
            if ($linkalbum) {
                rem_context(ZP_IMAGE);
                echo '<a href="' . html_encode(getAlbumLinkURL($album)) . '"   title="' . sprintf(gettext('View the %s album'), $albumname) . '">';
                add_context(ZP_IMAGE);
                printCustomSizedImage(sprintf(gettext('View the album %s'), $albumname), $size);
                rem_context(ZP_IMAGE | ZP_ALBUM);
                echo '</a>';
            } else {
                echo '<a href="' . html_encode(getImageLinkURL($image)) . '" title="' . sprintf(gettext('View %s'), $imagename) . '">';
                printCustomSizedImage(sprintf(gettext('View %s'), $imagename), $size);
                rem_context(ZP_IMAGE | ZP_ALBUM);
                echo '</a>';
            }
        } else {
            ?>
			<span style="background:red;color:black;">
			<?php 
            printf(gettext('<code>zenpageAlbumImage()</code> did not find the image %1$s:%2$s'), $albumname, $imagename);
            ?>
			</span>
			<?php 
        }
    } else {
        ?>
		<span style="background:red;color:black;">
		<?php 
        printf(gettext('<code>zenpageAlbumImage()</code> did not find the album %1$s'), $albumname);
        ?>
		</span>
		<?php 
    }
}
/**
 * Gets news articles and images of a gallery to show them together on the news section
 *
 * NOTE: This function does not exclude articles that are password protected via a category
 *
 * @param int $articles_per_page The number of articles to get
 * @param string $mode 	"latestimages-thumbnail"
 *											"latestimages-thumbnail-customcrop"
 *											"latestimages-sizedimage"
 *											"latestalbums-thumbnail"
 *		 									"latestalbums-thumbnail-customcrop"
 *		 									"latestalbums-sizedimage"
 *		 									"latestimagesbyalbum-thumbnail"
 *		 									"latestimagesbyalbum-thumbnail-customcrop"
 *		 									"latestimagesbyalbum-sizedimage"
 *		 									"latestupdatedalbums-thumbnail" (for RSS and getLatestNews() used only)
 *		 									"latestupdatedalbums-thumbnail-customcrop" (for RSS and getLatestNews() used only)
 *		 									"latestupdatedalbums-sizedimage" (for RSS and getLatestNews() used only)
 *	NOTE: The "latestupdatedalbums" variants do NOT support pagination as required on the news loop!
 *
 * @param string $published "published" for published articles,
 * 													"unpublished" for un-published articles,
 * 													"all" for all articles
 * @param string $sortorder 	id, date or mtime, only for latestimages-... modes
 * @param bool $sticky set to true to place "sticky" articles at the front of the list.
 * @return array
 */
function getCombiNews($articles_per_page = '', $mode = '', $published = NULL, $sortorder = '', $sticky = true)
{
    deprecated_function_notify(gettext('Use the Zenpage class method instead.'));
    global $_zp_gallery, $_zp_flash_player;
    processExpired('news');
    if (is_null($published)) {
        if (zp_loggedin(ZENPAGE_NEWS_RIGHTS)) {
            $published = "all";
        } else {
            $published = "published";
        }
    }
    if (empty($mode)) {
        $mode = getOption("zenpage_combinews_mode");
    }
    if ($published == "published") {
        $show = " WHERE `show` = 1 AND date <= '" . date('Y-m-d H:i:s') . "'";
        $imagesshow = " AND images.show = 1 ";
    } else {
        $show = "";
        $imagesshow = "";
    }
    $passwordcheck = "";
    if (zp_loggedin(ZENPAGE_NEWS_RIGHTS)) {
        $albumWhere = "";
        $passwordcheck = "";
    } else {
        $albumscheck = query_full_array("SELECT * FROM " . prefix('albums') . " ORDER BY title");
        foreach ($albumscheck as $albumcheck) {
            if (!checkAlbumPassword($albumcheck['folder'])) {
                $albumpasswordcheck = " AND albums.id != " . $albumcheck['id'];
                $passwordcheck = $passwordcheck . $albumpasswordcheck;
            }
        }
        $albumWhere = "AND albums.show=1" . $passwordcheck;
    }
    $limit = getLimitAndOffset($articles_per_page);
    if (empty($sortorder)) {
        $combinews_sortorder = getOption("zenpage_combinews_sortorder");
    } else {
        $combinews_sortorder = $sortorder;
    }
    $stickyorder = '';
    if ($sticky) {
        $stickyorder = 'sticky DESC,';
    }
    $type3 = query("SET @type3:='0'");
    switch ($mode) {
        case "latestimages-thumbnail":
        case "latestimages-thumbnail-customcrop":
        case "latestimages-sizedimage":
            $sortorder = "images." . $combinews_sortorder;
            $type1 = query("SET @type1:='news'");
            $type2 = query("SET @type2:='images'");
            switch ($combinews_sortorder) {
                case 'id':
                case 'date':
                    $imagequery = "(SELECT albums.folder, images.filename, images.date, @type2, @type3 as sticky FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                    break;
                case 'mtime':
                    $imagequery = "(SELECT albums.folder, images.filename, FROM_UNIXTIME(images.mtime), @type2, @type3 as sticky FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                    break;
            }
            $result = query_full_array("(SELECT title as albumname, titlelink, date, @type1 as type, sticky FROM " . prefix('news') . " " . $show . ")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $imagequery . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY {$stickyorder} date DESC {$limit}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
            break;
        case "latestalbums-thumbnail":
        case "latestalbums-thumbnail-customcrop":
        case "latestalbums-sizedimage":
            $sortorder = $combinews_sortorder;
            $type1 = query("SET @type1:='news'");
            $type2 = query("SET @type2:='albums'");
            switch ($combinews_sortorder) {
                case 'id':
                case 'date':
                    $albumquery = "(SELECT albums.folder, albums.title, albums.date, @type2, @type3 as sticky FROM " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t" . $show . $albumWhere . ")";
                    break;
                case 'mtime':
                    $albumquery = "(SELECT albums.folder, albums.title, FROM_UNIXTIME(albums.mtime), @type2, @type3 as sticky FROM " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t" . $show . $albumWhere . ")";
                    break;
            }
            $result = query_full_array("(SELECT title as albumname, titlelink, date, @type1 as type, sticky FROM " . prefix('news') . " " . $show . ")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $albumquery . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY {$stickyorder} date DESC {$limit}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
            break;
        case "latestimagesbyalbum-thumbnail":
        case "latestimagesbyalbum-thumbnail-customcrop":
        case "latestimagesbyalbum-sizedimage":
            $type1 = query("SET @type1:='news'");
            $type2 = query("SET @type2:='albums'");
            if (empty($combinews_sortorder) || $combinews_sortorder != "date" || $combinews_sortorder != "mtime") {
                $combinews_sortorder = "date";
            }
            $combinews_sortorder = "date";
            $sortorder = "images." . $combinews_sortorder;
            switch ($combinews_sortorder) {
                case "date":
                    $imagequery = "(SELECT DISTINCT DATE_FORMAT(" . $sortorder . ",'%Y-%m-%d'), albums.folder, DATE_FORMAT(images.`date`,'%Y-%m-%d'), @type2 FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                    break;
                case "mtime":
                    $imagequery = "(SELECT DISTINCT FROM_UNIXTIME(" . $sortorder . ",'%Y-%m-%d'), albums.folder, DATE_FORMAT(images.`mtime`,'%Y-%m-%d'), @type2 FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                    break;
            }
            $result = query_full_array("(SELECT title as albumname, titlelink, date, @type1 as type FROM " . prefix('news') . " " . $show . ")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $imagequery . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER By date DESC {$limit}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
            //echo "<pre>"; print_r($result); echo "</pre>";
            //$result = "";
            break;
        case "latestupdatedalbums-thumbnail":
        case "latestupdatedalbums-thumbnail-customcrop":
        case "latestupdatedalbums-sizedimage":
            $latest = getNewsArticles($articles_per_page, '', NULL, true);
            $counter = '';
            foreach ($latest as $news) {
                $article = new ZenpageNews($news['titlelink']);
                if ($article->checkAccess($hint, $show)) {
                    $counter++;
                    $latestnews[$counter] = array("albumname" => $article->getTitle(), "titlelink" => $article->getTitlelink(), "date" => $article->getDateTime(), "type" => "news");
                }
            }
            $albums = getAlbumStatistic($articles_per_page, "latestupdated");
            $latestalbums = array();
            $counter = "";
            foreach ($albums as $album) {
                $counter++;
                $tempalbum = new Album($_zp_gallery, $album['folder']);
                $tempalbumthumb = $tempalbum->getAlbumThumbImage();
                $timestamp = $tempalbum->get('mtime');
                if ($timestamp == 0) {
                    $albumdate = $tempalbum->getDateTime();
                } else {
                    $albumdate = strftime('%Y-%m-%d %H:%M:%S', $timestamp);
                }
                $latestalbums[$counter] = array("albumname" => $tempalbum->getFolder(), "titlelink" => $tempalbum->getTitle(), "date" => $albumdate, "type" => 'albums');
            }
            //$latestalbums = array_merge($latestalbums, $item);
            $latest = array_merge($latestnews, $latestalbums);
            $result = sortMultiArray($latest, "date", true);
            if (count($result) > $articles_per_page) {
                $result = array_slice($result, 0, 10);
            }
            break;
    }
    //$result = "";
    return $result;
}
/**
 * A helper function that only prints a item of the loop within printAlbumStatistic()
 * Not for standalone use.
 *
 * @param array $album the array that getAlbumsStatistic() submitted
 * @param string $option "popular" for the most popular albums,
 *                  "latest" for the latest uploaded,
 *                  "mostrated" for the most voted,
 *                  "toprated" for the best voted
 * 									"latestupdated" for the latest updated
 * @param bool $showtitle if the album title should be shown
 * @param bool $showdate if the album date should be shown
 * @param bool $showdesc if the album description should be shown
 * @param integer $desclength the length of the description to be shown
 * @param string $showstatistic "hitcounter" for showing the hitcounter (views),
 * 															"rating" for rating,
 * 															"rating+hitcounter" for both.
 * @param integer $width the width/cropwidth of the thumb if crop=true else $width is longest size. (Default 85px)
 * @param integer $height the height/cropheight of the thumb if crop=true else not used.  (Default 85px)
 * @param bool $crop 'true' (default) if the thumb should be cropped, 'false' if not
 * @param bool $firstimglink 'false' (default) if the album thumb link should lead to the album page, 'true' if to the first image of theh album if the album itself has images
 */
function printAlbumStatisticItem($album, $option, $showtitle = false, $showdate = false, $showdesc = false, $desclength = 40, $showstatistic = '', $width = 85, $height = 85, $crop = true, $firstimglink = false)
{
    global $_zp_gallery;
    $tempalbum = new Album($_zp_gallery, $album['folder']);
    if ($firstimglink && $tempalbum->getNumImages() != 0) {
        $firstimage = $tempalbum->getImages(1);
        // need only the first so don't get all
        $firstimage = $firstimage[0];
        $modrewritesuffix = getOption('mod_rewrite_image_suffix');
        $imagepath = html_encode(rewrite_path("/" . $firstimage . $modrewritesuffix, "&amp;image=" . $firstimage, false));
    } else {
        $imagepath = "";
    }
    $albumpath = html_encode(rewrite_path("/" . pathurlencode($tempalbum->name) . $imagepath, "index.php?album=" . pathurlencode($tempalbum->name) . $imagepath));
    echo "<li><a href=\"" . $albumpath . "\" title=\"" . html_encode($tempalbum->getTitle()) . "\">\n";
    $albumthumb = $tempalbum->getAlbumThumbImage();
    $thumb = newImage($tempalbum, $albumthumb->filename);
    if ($crop) {
        echo "<img src=\"" . html_encode($albumthumb->getCustomImage(NULL, $width, $height, $width, $height, NULL, NULL, TRUE)) . "\" alt=\"" . html_encode($albumthumb->getTitle()) . "\" /></a>\n<br />";
    } else {
        echo "<img src=\"" . html_encode($albumthumb->getCustomImage($width, NULL, NULL, NULL, NULL, NULL, NULL, TRUE)) . "\" alt=\"" . html_encode($albumthumb->getTitle()) . "\" /></a>\n<br />";
    }
    if ($showtitle) {
        echo "<h3><a href=\"" . $albumpath . "\" title=\"" . html_encode($tempalbum->getTitle()) . "\">\n";
        echo $tempalbum->getTitle() . "</a></h3>\n";
    }
    if ($showdate) {
        if ($option === "latestupdated") {
            $filechangedate = filectime(ALBUM_FOLDER_SERVERPATH . internalToFilesystem($tempalbum->name));
            $latestimage = query_single_row("SELECT mtime FROM " . prefix('images') . " WHERE albumid = " . $tempalbum->getAlbumID() . " AND `show` = 1 ORDER BY id DESC");
            $lastuploaded = query("SELECT COUNT(*) FROM " . prefix('images') . " WHERE albumid = " . $tempalbum->getAlbumID() . " AND mtime = " . $latestimage['mtime']);
            $row = db_fetch_row($lastuploaded);
            $count = $row[0];
            echo "<p>" . sprintf(gettext("Last update: %s"), zpFormattedDate(DATE_FORMAT, $filechangedate)) . "</p>";
            if ($count <= 1) {
                $image = gettext("image");
            } else {
                $image = gettext("images");
            }
            echo "<span>" . sprintf(gettext('%1$u new %2$s'), $count, $image) . "</span>";
        } else {
            echo "<p>" . zpFormattedDate(DATE_FORMAT, strtotime($tempalbum->getDateTime())) . "</p>";
        }
    }
    if ($showstatistic === "rating" or $showstatistic === "rating+hitcounter") {
        $votes = $tempalbum->get("total_votes");
        $value = $tempalbum->get("total_value");
        if ($votes != 0) {
            $rating = round($value / $votes, 1);
        }
        echo "<p>" . sprintf(gettext('Rating: %1$u (Votes: %2$u)'), $rating, $tempalbum->get("total_votes")) . "</p>";
    }
    if ($showstatistic === "hitcounter" or $showstatistic === "rating+hitcounter") {
        $hitcounter = $tempalbum->get("hitcounter");
        if (empty($hitcounter)) {
            $hitcounter = "0";
        }
        echo "<p>" . sprintf(gettext("Views: %u"), $hitcounter) . "</p>";
    }
    if ($showdesc) {
        echo shortenContent($tempalbum->getDesc(), $desclength, ' (...)');
    }
    echo "</li>";
}
Example #4
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;
 }
Example #5
0
 if ($rssmode != "albums") {
     $ext = strtolower(strrchr($item->filename, "."));
     $albumobj = $item->getAlbum();
     $itemlink = $host . WEBPATH . $albumpath . pathurlencode($albumobj->name) . $imagepath . pathurlencode($item->filename) . $modrewritesuffix;
     $fullimagelink = $host . WEBPATH . "/albums/" . pathurlencode($albumobj->name) . "/" . $item->filename;
     $imagefile = "albums/" . $albumobj->name . "/" . $item->filename;
     $thumburl = '<img border="0" src="' . $protocol . '://' . $host . $item->getCustomImage($size, NULL, NULL, NULL, NULL, NULL, NULL, TRUE) . '" alt="' . get_language_string(get_language_string($item->get("title"), $locale)) . '" />';
     $itemcontent = '<![CDATA[<a title="' . html_encode(get_language_string($item->get("title"), $locale)) . ' in ' . html_encode(get_language_string($albumobj->get("title"), $locale)) . '" href="' . $protocol . '://' . $itemlink . '">' . $thumburl . '</a>' . get_language_string(get_language_string($item->get("desc"), $locale)) . ']]>';
     $videocontent = '<![CDATA[<a title="' . html_encode(get_language_string($item->get("title"), $locale)) . ' in ' . html_encode(get_language_string($albumobj->getTitle(), $locale)) . '" href="' . $protocol . '://' . $itemlink . '"><img src="' . $protocol . '://' . $host . $item->getThumb() . '" alt="' . get_language_string(get_language_string($item->get("title"), $locale)) . '" /></a>' . get_language_string(get_language_string($item->get("desc"), $locale)) . ']]>';
     $datecontent = '<![CDATA[Date: ' . zpFormattedDate(DATE_FORMAT, $item->get('mtime')) . ']]>';
 } else {
     $galleryobj = new Gallery();
     $albumitem = new Album($galleryobj, $item['folder']);
     $totalimages = $albumitem->getNumImages();
     $itemlink = $host . WEBPATH . $albumpath . pathurlencode($albumitem->name);
     $thumb = $albumitem->getAlbumThumbImage();
     $thumburl = '<img border="0" src="' . $thumb->getCustomImage($size, NULL, NULL, NULL, NULL, NULL, NULL, TRUE) . '" alt="' . html_encode(get_language_string($albumitem->get("title"), $locale)) . '" />';
     $title = get_language_string($albumitem->get("title"), $locale);
     if (true || getOption("feed_sortorder_albums") == "latestupdated") {
         $filechangedate = filectime(ALBUM_FOLDER_SERVERPATH . internalToFilesystem($albumitem->name));
         $latestimage = query_single_row("SELECT mtime FROM " . prefix('images') . " WHERE albumid = " . $albumitem->getAlbumID() . " AND `show` = 1 ORDER BY id DESC");
         $lastuploaded = query("SELECT COUNT(*) FROM " . prefix('images') . " WHERE albumid = " . $albumitem->getAlbumID() . " AND mtime = " . $latestimage['mtime']);
         $row = db_fetch_row($lastuploaded);
         $count = $row[0];
         if ($count == 1) {
             $imagenumber = sprintf(gettext('%s (1 new image)'), $title);
         } else {
             $imagenumber = sprintf(gettext('%1$s (%2$s new images)'), $title, $count);
         }
         $itemcontent = '<![CDATA[<a title="' . $title . '" href="' . $protocol . '://' . $itemlink . '">' . $thumburl . '</a>' . '<p>' . html_encode($imagenumber) . '</p>' . html_encode(get_language_string($albumitem->get("desc"), $locale)) . ']]>';
         $videocontent = '';
 /**
  * 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 = getAlbumFolder();
     }
     $shuffle = $thumb != '1';
     if (!empty($thumb) && $thumb != '1' && file_exists($albumdir . UTF8ToFilesystem($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 {
         if ($this->isDynamic()) {
             $this->getImages(0, 0, 'ID', 'DESC');
             $thumbs = $this->images;
             if (!is_null($thumbs)) {
                 if ($shuffle) {
                     shuffle($thumbs);
                 }
                 while (count($thumbs) > 0) {
                     $thumb = array_shift($thumbs);
                     if (is_valid_image($thumb['filename'])) {
                         $alb = new Album($this->gallery, $thumb['folder']);
                         $thumb = newImage($alb, $thumb['filename']);
                         if ($thumb->getShow()) {
                             $this->albumthumbnail = $thumb;
                             return $thumb;
                         }
                     }
                 }
             }
         } else {
             $this->getImages(0, 0, 'ID', 'DESC');
             $thumbs = $this->images;
             if (!is_null($thumbs)) {
                 if ($shuffle) {
                     shuffle($thumbs);
                 }
                 while (count($thumbs) > 0) {
                     $thumb = array_shift($thumbs);
                     if (is_valid_image($thumb)) {
                         $thumb = newImage($this, $thumb);
                         if ($thumb->getShow()) {
                             $this->albumthumbnail = $thumb;
                             return $thumb;
                         }
                     }
                 }
             }
             // Otherwise, look in sub-albums.
             $subalbums = $this->getSubAlbums();
             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) || isMyALbum($folder, ALL_RIGHTS)) {
                         $thumb = $subalbum->getAlbumThumbImage();
                         if (strtolower(get_class($thumb)) !== 'transientimage' && $thumb->exists) {
                             $this->albumthumbnail = $thumb;
                             return $thumb;
                         }
                     }
                 }
             }
             //jordi-kun - no images, no subalbums, check for videos
             $dp = opendir($albumdir);
             while ($thumb = readdir($dp)) {
                 if (is_file($albumdir . $thumb) && is_valid_video($thumb)) {
                     $othersThumb = checkObjectsThumb($albumdir, $thumb);
                     if (!empty($othersThumb)) {
                         $thumb = newImage($this, $othersThumb);
                         if ($this->getShow()) {
                             $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(UTF8ToFilesystem($themeimage))) {
                 $nullimage = $themeimage;
             }
         }
     }
     $this->albumthumbnail = new transientimage($this, $nullimage);
     return $this->albumthumbnail;
 }
/**
 * A helper function that only prints a item of the loop within printAlbumStatistic()
 * Not for standalone use.
 *
 * @param array $album the array that getAlbumsStatistic() submitted
 * @param string $option "popular" for the most popular albums,
 *                  "latest" for the latest uploaded,
 *                  "mostrated" for the most voted,
 *                  "toprated" for the best voted
 * 									"latestupdated" for the latest updated
 * @param bool $showtitle if the album title should be shown
 * @param bool $showdate if the album date should be shown
 * @param bool $showdesc if the album description should be shown
 * @param integer $desclength the length of the description to be shown
 * @param string $showstatistic "hitcounter" for showing the hitcounter (views),
 * 															"rating" for rating,
 * 															"rating+hitcounter" for both.
 * @param integer $width the width/cropwidth of the thumb if crop=true else $width is longest size. (Default 85px)
 * @param integer $height the height/cropheight of the thumb if crop=true else not used.  (Default 85px)
 * @param bool $crop 'true' (default) if the thumb should be cropped, 'false' if not
 */
function printAlbumStatisticItem($album, $option, $showtitle = false, $showdate = false, $showdesc = false, $desclength = 40, $showstatistic = '', $width = 85, $height = 85, $crop = true)
{
    global $_zp_gallery;
    $albumpath = rewrite_path("/", "index.php?album=");
    $tempalbum = new Album($_zp_gallery, $album['folder']);
    echo "<li><a href=\"" . $albumpath . pathurlencode($tempalbum->name) . "\" title=\"" . html_encode($tempalbum->getTitle()) . "\">\n";
    $albumthumb = $tempalbum->getAlbumThumbImage();
    $thumb = newImage($tempalbum, $albumthumb->filename);
    if ($crop) {
        echo "<img src=\"" . $thumb->getCustomImage(NULL, $width, $height, $width, $height, NULL, NULL, TRUE) . "\" alt=\"" . html_encode($thumb->getTitle()) . "\" /></a>\n<br />";
    } else {
        echo "<img src=\"" . $thumb->getCustomImage($width, NULL, NULL, NULL, NULL, NULL, NULL, TRUE) . "\" alt=\"" . html_encode($thumb->getTitle()) . "\" /></a>\n<br />";
    }
    if ($showtitle) {
        echo "<h3><a href=\"" . $albumpath . pathurlencode($tempalbum->name) . "\" title=\"" . html_encode($tempalbum->getTitle()) . "\">\n";
        echo $tempalbum->getTitle() . "</a></h3>\n";
    }
    if ($showdate) {
        if ($option === "latestupdated") {
            $filechangedate = filectime(getAlbumFolder() . UTF8ToFilesystem($tempalbum->name));
            $latestimage = query_single_row("SELECT mtime FROM " . prefix('images') . " WHERE albumid = " . $tempalbum->getAlbumID() . " AND `show` = 1 ORDER BY id DESC");
            $lastuploaded = query("SELECT COUNT(*) FROM " . prefix('images') . " WHERE albumid = " . $tempalbum->getAlbumID() . " AND mtime = " . $latestimage['mtime']);
            $row = mysql_fetch_row($lastuploaded);
            $count = $row[0];
            echo "<p>" . sprintf(gettext("Last update: %s"), zpFormattedDate(getOption('date_format'), $filechangedate)) . "</p>";
            if ($count <= 1) {
                $image = gettext("image");
            } else {
                $image = gettext("images");
            }
            echo "<span>" . sprintf(gettext('%1$u new %2$s'), $count, $image) . "</span>";
        } else {
            echo "<p>" . zpFormattedDate(getOption('date_format'), strtotime($tempalbum->getDateTime())) . "</p>";
        }
    }
    if ($showstatistic === "rating" or $showstatistic === "rating+hitcounter") {
        $votes = $tempalbum->get("total_votes");
        $value = $tempalbum->get("total_value");
        if ($votes != 0) {
            $rating = round($value / $votes, 1);
        }
        echo "<p>" . sprintf(gettext('Rating: %1$u (Votes: %2$u )'), $rating, $tempalbum->get("total_votes")) . "</p>";
    }
    if ($showstatistic === "hitcounter" or $showstatistic === "rating+hitcounter") {
        $hitcounter = $tempalbum->get("hitcounter");
        if (empty($hitcounter)) {
            $hitcounter = "0";
        }
        echo "<p>" . sprintf(gettext("Views: %u"), $hitcounter) . "</p>";
    }
    if ($showdesc) {
        echo "<p>" . truncate_string($tempalbum->getDesc(), $desclength) . "</p>";
    }
    echo "</li>";
}
/**
 * Show the content of an media album with .flv/.mp4/.mp3 movie/audio files only as a playlist or as separate players with Flowplayer 3
 * Important: The Flowplayer 3 plugin needs to be activated to use this plugin. This plugin shares all settings with this plugin, too.
 *
 * You can either show a 'one player window' playlist or show all items as separate players paginated. See the examples below.
 * (set in the settings for thumbs per page) on one page (like on a audio or podcast blog).
 *
 * There are two usage modes:
 *
 * a) 'playlist'
 * The playlist is meant to replace the 'next_image()' loop on a theme's album.php.
 * It can be used with a special 'album theme' that can be assigned to media albums with with .flv/.mp4/.mp3s, although Flowplayer 3 also supports images
 * Replace the entire 'next_image()' loop on album.php with this:
 * <?php flowplayerPlaylist("playlist"); ?>
 *
 * This produces the following html:
 * <div class="wrapper">
 * <a class="up" title="Up"></a>
 * <div class="playlist">
 * <div class="clips">
 * <!-- single playlist entry as an "template" -->
 * <a href="${url}">${title}</a>
 * </div>
 * </div>
 * <a class="down" title="Down"></a>
 * </div>
 * </div>
 * This is styled by the css file 'playlist.css" that is located within the 'zp-core/plugins/flowplayer3_playlist/flowplayer3_playlist.css' by default.
 * Alternatively you can style it specifically for your theme. Just place a css file named "flowplayer3_playlist.css" in your theme's folder.
 *
 * b) 'players'
 * This displays each audio/movie file as a separate player on album.php.
 * If there is no videothumb image for an mp3 file existing only the player control bar is shown.
 * Modify the 'next_image()' loop on album.php like this:
 * <?php
 * while (next_image()):
 * flowplayerPlaylist("players");
 * endwhile;
 * ?>
 * Of course you can add further functions to b) like printImageTitle() etc., too.
 *
 * @param string $option The mode to use "players", "playlist" or "playlist-mp3". "playlist-mp3" is the same as "playlist" except that only the controlbar is shown (if you are too lazy for custom video thumbs and don't like the empty screen)
 * @param string $albumfolder For "playlist" mode only: To show a playlist of an specific album directly on another page (for example on index.php). Note: Currently it is not possible to have several playlists on one page
 */
function flowplayerPlaylist($option = "playlist", $albumfolder = "")
{
    global $_zp_current_image, $_zp_current_album, $_zp_flash_player;
    $curdir = getcwd();
    chdir(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/flowplayer3');
    $filelist = safe_glob('flowplayer-*.swf');
    $swf = array_shift($filelist);
    $filelist = safe_glob('flowplayer.audio-*.swf');
    $audio = array_shift($filelist);
    $filelist = safe_glob('flowplayer.controls-*.swf');
    $controls = array_shift($filelist);
    chdir($curdir);
    $playlistwidth = getOption('flow_player3_playlistwidth');
    $playlistheight = getOption('flow_player3_playlistheight');
    switch ($option) {
        case 'playlist':
        case 'playlist-mp3':
            $splashimage = getOption('flow_player3_playlistsplashimage');
            if ($option == 'playlist-mp3') {
                $playlistheight = FLOW_PLAYER_MP3_HEIGHT;
                $splashimage = 'none';
            }
            if (empty($albumfolder)) {
                $albumname = $_zp_current_album->name;
            } else {
                $albumname = $albumfolder;
            }
            $album = new Album(new Gallery(), $albumname);
            if (getOption("flow_player3_playlistautoplay") == 1) {
                $autoplay = 'true';
            } else {
                $autoplay = 'false';
            }
            $playlist = $album->getImages();
            // slash image fetching
            $videoobj = new Video($album, $playlist[0]);
            $albumfolder = $album->name;
            $splashimagerwidth = $playlistwidth;
            $splashimageheight = $playlistheight;
            $videoThumbImg = '';
            if ($splashimage != 'none') {
                switch ($splashimage) {
                    case 'albumthumb':
                        $albumthumbobj = $album->getAlbumThumbImage();
                        getMaxSpaceContainer($splashimagerwidth, $splashimageheight, $albumthumbobj, true);
                        $albumthumb = $albumthumbobj->getCustomImage(null, $splashimagerwidth, $splashimageheight, null, null, null, null, true);
                        $videoThumbImg = '<img src="' . pathurlencode($albumthumb) . '" alt="" />';
                        break;
                    case 'firstentry':
                        getMaxSpaceContainer($splashimagerwidth, $splashimageheight, $videoobj, true);
                        $videoThumb = $videoobj->getCustomImage(null, $splashimagerwidth, $splashimageheight, null, null, null, null, true);
                        $videoThumbImg = '<img src="' . pathurlencode($videoThumb) . '" alt="" />';
                        break;
                }
            }
            if ($album->getNumImages() != 0) {
                if (getOption('flow_player3_playlistnumbered')) {
                    $liststyle = 'ol';
                } else {
                    $liststyle = 'div';
                }
                echo '<div class="flowplayer3_playlistwrapper">
			<a id="player' . $album->get('id') . '" class="flowplayer3_playlist" style="display:block; width: ' . $playlistwidth . 'px; height: ' . $playlistheight . 'px;">
			' . $videoThumbImg . '
			</a>
			<script type="text/javascript">
			// <!-- <![CDATA[
			$(function() {

			$("div.playlist").scrollable({
				items:"' . $liststyle . '.clips' . $album->get('id') . '",
				vertical:true,
				next:"a.down",
				prev:"a.up",
				mousewheel: true
			});
			flowplayer("player' . $album->get('id') . '","' . WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/flowplayer3/' . $swf . '", {
			plugins: {
				audio: {
					url: "' . $audio . '"
				},
				controls: {
					url: "' . $controls . '",
					backgroundColor: "' . getOption('flow_player3_controlsbackgroundcolor') . '",
					autoHide: "' . getOption('flow_player3_playlistautohide') . '",
					timeColor:"' . getOption('flow_player3_controlstimecolor') . '",
					durationColor: "' . getOption('flow_player3_controlsdurationcolor') . '",
					progressColor: "' . getOption('flow_player3_controlsprogresscolor') . '",
					progressGradient: "' . getOption('flow_player3_controlsprogressgradient') . '",
					bufferColor: "' . getOption('flow_player3_controlsbuffercolor') . '",
					bufferGradient:	 "' . getOption('fflow_player3_controlsbuffergradient') . '",
					sliderColor: "' . getOption('flow_player3_controlsslidercolor') . '",
					sliderGradient: "' . getOption('flow_player3_controlsslidergradient') . '",
					buttonColor: "' . getOption('flow_player3_controlsbuttoncolor') . '",
					buttonOverColor: "' . getOption('flow_player3_controlsbuttonovercolor') . '",
					scaling: "' . getOption('flow_player3_scaling') . '",
					playlist: true
				}
			},
			canvas: {
				backgroundColor: "' . getOption('flow_player3_backgroundcolor') . '",
				backgroundGradient: "' . getOption('flow_player3_backgroundcolorgradient') . '"
			},';
                $list = '';
                foreach ($playlist as $item) {
                    $image = newImage($album, $item);
                    $coverimagerwidth = getOption('flow_player3_playlistwidth');
                    $coverimageheight = getOption('flow_player3_playlistheight');
                    getMaxSpaceContainer($coverimagerwidth, $coverimageheight, $image, true);
                    $cover = $image->getCustomImage(null, $coverimagerwidth, $coverimageheight, null, null, null, null, true);
                    $ext = strtolower(strrchr($item, "."));
                    if ($ext == ".flv" || $ext == ".mp3" || $ext == ".mp4") {
                        $list .= '{
					url:"' . ALBUM_FOLDER_WEBPATH . $album->name . '/' . $item . '",
					autoPlay: ' . $autoplay . ',
					title: "' . $image->getTitle() . ' <small>(' . $ext . ')</small>",
					autoBuffering: ' . $autoplay . ',
					coverImage: {
						url: "' . urlencode($cover) . '",
						scaling: "fit"
					}
				},';
                    }
                    // if ext end
                }
                // foreach end
                echo 'playlist: [' . substr($list, 0, -1) . ']
			});
			flowplayer("player' . $album->get('id') . '").playlist("' . $liststyle . '.clips' . $album->get('id') . ':first", {loop:true});
			});
			// ]]> -->
			</script>';
                ?>
		<div class="wrapper">
					<a class="up" title="Up"></a>

			<div class="playlist playlist<?php 
                echo $album->get('id');
                ?>
">
				<<?php 
                echo $liststyle;
                ?>
 class="clips clips<?php 
                echo $album->get('id');
                ?>
">
					<!-- single playlist entry as an "template" -->
					<?php 
                if ($liststyle == 'ol') {
                    ?>
 <li> <?php 
                }
                ?>
					<a href="${url}">${title}</a>
					<?php 
                if ($liststyle == 'ol') {
                    ?>
 </li> <?php 
                }
                ?>
				</<?php 
                echo $liststyle;
                ?>
>
			</div>
		<a class="down" title="Down"></a>
</div>
</div><!-- flowplayer3_playlist wrapper end -->
<?php 
            }
            // check if there are images end
            break;
        case 'players':
            $_zp_flash_player->printPlayerConfig('', '', imageNumber());
            break;
    }
    // switch end
}
 function getSubalbumsHTML()
 {
     $numAlbums = $this->getNumAlbums();
     if ($numAlbums <= 0 || $this->albumPage >= $this->getFirstImagePage()) {
         return '';
     }
     global $_zp_themeroot, $_zp_gallery, $_zp_current_image, $_zp_current_album;
     $w = 318;
     $slideshowLink = $this->getSlideshowLink();
     $subalbums = "<div id='subalbums'>";
     $i = 0;
     $albums = $this->getAlbums();
     $page = $this->getAlbumPage();
     $start = ($page - 1) * getOption('albums_per_page');
     $albums = array_slice($albums, $start, getOption('albums_per_page'));
     for ($u = 0; $u < count($albums); $u++) {
         $a = new Album($_zp_gallery, $albums[$u]);
         $thumb = $a->getAlbumThumbImage();
         $title = $a->getTitle();
         $desc = $a->getDesc();
         $customThumb = $thumb->getCustomImage(NULL, 104, 56, 104, 56, NULL, NULL, false);
         $subalbums .= "<span class='subalbum' id='subalbum-{$u}' width='104' height='56' >" . "<a href='" . getAlbumURL($a) . "' >" . "<img width='104' height='56' src='{$customThumb}'/></a></span>";
         $i++;
     }
     $m = $i;
     $i++;
     while ($i <= getOption('albums_per_page')) {
         $subalbums .= "<span class='subalbum' id='subalbum-{$i}'>" . "<img width='104' height='56' src='{$_zp_themeroot}/resources/images/opa/bg-b-20.png'/>" . "</span>";
         $i++;
     }
     $subalbums .= "</div>";
     $s = ($this->getAlbumPage() - 1) * getOption('albums_per_page');
     $batch = $s + 1 . "-" . ($s + $m);
     $subalbums = "<div id='subalbum-count' class='count'>" . (isset($slideshowLink) && $this->getNumImages() > 0 ? "<span id='album-slideshow-link' class='unselected'><a href='{$slideshowLink}'>Slideshow</a></span>" : "") . "<span class='selected'>{$batch} / " . $numAlbums . " " . gettext($this->getAlbumTabText($numAlbums)) . "</span>" . ($this->getNumImages() > 0 ? "<span class='unselected last'><a href='" . $this->getImageTabLink() . "'>" . $this->getNumImages() . " " . gettext("images") . "</a></span>" : "<span class='unselected last'>" . $this->getNumImages() . " " . gettext("image") . "</span>") . "</div>" . $subalbums;
     if ($this->showRandomImage()) {
         $img = $this->getRandomAlbumImage();
         $subalbums .= "<div id='random-album-image'>";
         $previous = $_zp_current_image;
         $_zp_current_image = $img;
         $size = getSizeCustomImage(NULL, $w + 2);
         $small = getCustomImageURL(NULL, $w + 2);
         $width = $img->getWidth();
         $height = $img->getHeight();
         $ratio = ($w + 2) / $width;
         $height = $height * $ratio;
         $subalbums .= "<img src='{$small}' width='" . ($w + 2) . "' height='{$height}'/>";
         $subalbums .= "<div class='caption'>Random selection</div>";
         $subalbums .= "</div>";
         $_zp_current_image = $previous;
     }
     return $subalbums;
 }