/**
 * Returns the title from the feed's url for latest albums or a specific album rss
 *
 * @return string
 */
function getRSSAlbumTitle()
{
    global $_zp_gallery;
    $rssmode = getRSSAlbumsmode();
    if (isset($_GET['albumtitle'])) {
        $albumname = ' - ' . html_encode(sanitize(urldecode($_GET['albumtitle']))) . ' (' . gettext('latest images') . ')';
    } elseif ($rssmode == "albums" && !isset($_GET['folder'])) {
        $albumname = ' (' . gettext('latest albums') . ')';
    } elseif ($rssmode == 'albums' && isset($_GET['folder'])) {
        $folder = sanitize(urldecode($_GET['folder']));
        $albobj = new Album($_zp_gallery, $folder);
        $albumname = ' - ' . html_encode(strip_tags($albobj->getTitle())) . ' (' . gettext('latest albums') . ')';
    } else {
        $albumname = ' (' . gettext('latest images') . ')';
    }
    return $albumname;
}
/**
 * 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;
}
Example #3
0
    static function printSlideShow($heading = true, $speedctl = false, $albumobj = "", $imageobj = "", $width = "", $height = "")
    {
        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;
        //getting the image to start with
        if (!empty($_POST['imagenumber']) and !is_object($imageobj)) {
            $imagenumber = $_POST['imagenumber'] - 1;
            // slideshows starts with 0, but zp with 1.
        } elseif (is_object($imageobj)) {
            makeImageCurrent($imageobj);
            $imagenumber = imageNumber() - 1;
        } else {
            $imagenumber = 0;
        }
        // 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();
        }
        //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");
        }
        $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 = $_POST['preserve_search_params'];
            $search->setSearchParams($params);
            $images = $search->getImages(0);
            $searchwords = $search->words;
            $searchdate = $search->dates;
            $searchfields = $search->fields;
            $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 (!checkAlbumPassword($albumq['folder'], $hint)) {
                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($_POST['imagefile']) . getOption('mod_rewrite_image_suffix'), '/index.php?album=' . urlencode($album->name) . '&image=' . urlencode($_POST['imagefile']));
            }
        }
        // slideshow display section
        switch ($option) {
            case "jQuery":
                $validtypes = array('jpg', 'jpeg', 'gif', 'png', 'mov', '3gp');
                ?>
					<script type="text/javascript">
						$(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);
                        $img = getCustomSizedImageMaxSpace($width, $height);
                        //$img = WEBPATH . '/' . ZENFOLDER . '/i.php?a=' . pathurlencode($image->album->name) . '&i=' . urlencode($filename) . '&s=' . $imagesize;
                        echo 'ImageList[' . $cntr . '] = "' . $img . '";' . "\n";
                        echo 'TitleList[' . $cntr . '] = "' . js_encode($image->getTitle()) . '";' . "\n";
                        if (getOption("slideshow_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) {
									//$(next).parent().animate({opacity: 0});

									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 (!isMyALbum($album->name, ALL_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 
                }
                ?>

									//THE MISSING LINE
									$(next).parent().height(
										$(next).find('img').height() + $(next).find('p').height() + $(next).find('h4').height() + 40
									); //.animate({opacity: 1}, 'normal', 'linear');
									//getOption('slideshow_onafter'); //make it generic
									//END MISSING LINE
								}
			
								$('#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 $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 . getAlbumFolder('') . pathurlencode($folder) . "/" . urlencode($filename);
                    } else {
                        $folder = $album->name;
                        $filename = $images[$idx];
                        //$filename = $animage;
                        $image = newImage($album, $filename);
                        $imagepath = FULLWEBPATH . getAlbumFolder('') . 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);
                            printCustomSizedImageMaxSpace($alt = '', $width, $height, NULL, NULL, false);
                            //echo "<img src='".WEBPATH."/".ZENFOLDER."/i.php?a=".urlencode($folder)."&i=".urlencode($filename)."&s=".$imagesize."' alt='".html_encode($image->getTitle())."' title='".html_encode($image->getTitle())."' />\n";
                        }
                        if (getOption("slideshow_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='" . $returnpath . "' title='" . gettext("back") . "'>" . gettext("back") . "</a></h4>";
                }
                echo "<span id='slideshow'></span>";
                ?>
 
					<script type="text/javascript">
					$("#slideshow").flashembed({
						  src:'<?php 
                echo FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER;
                ?>
/flowplayer/FlowPlayerLight.swf',
						  width:<?php 
                echo getOption("slideshow_flow_player_width");
                ?>
,
						  height:<?php 
                echo getOption("slideshow_flow_player_height");
                ?>
						},
						{config: {
						  autoPlay: true,
						  useNativeFullScreen: true,
						  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 . getAlbumFolder('') . pathurlencode($salbum->name) . "/" . urlencode($filename);
                    } else {
                        $folder = $album->name;
                        $filename = $animage;
                        $image = newImage($album, $filename);
                        $imagepath = FULLWEBPATH . getAlbumFolder('') . 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_speed") / 10;
                        }
                        if ($count > 0) {
                            echo ",\n";
                        }
                        echo "{ url: '" . FULLWEBPATH . getAlbumFolder('') . pathurlencode($folder) . "/" . urlencode($filename) . "'" . $duration . " }";
                        $count++;
                    }
                }
                echo "\n";
                ?>
												],
						  showPlayListButtons: true,
						  showStopButton: true,
						  controlBarBackgroundColor: 0,
						 	showPlayListButtons: true,
						 	controlsOverVideo: 'ease',
						 	controlBarBackgroundColor: '<?php 
                echo getOption('flow_player_controlbarbackgroundcolor');
                ?>
',
						  controlsAreaBorderColor: '<?php 
                echo getOption('flow_player_controlsareabordercolor');
                ?>
'
						}}
				  );
					</script> 
					<?php 
                echo "</span>";
                echo "<p>";
                printf(gettext("Click on %s on the right in the player control bar to view full size."), "<img style='position: relative; top: 4px; border: 1px solid gray' src='" . WEBPATH . "/" . ZENFOLDER . '/' . PLUGIN_FOLDER . "/slideshow/flowplayerfullsizeicon.png' />");
                echo "</p>";
                break;
        }
        ?>
			</div>
		</div>
			<?php 
    }
/**
 * Prints a table with a bar graph of the values.
 *
 * @param string $sortorder "popular", "mostrated","toprated","mostcommented" or - only if $type = "albums"! - "mostimages"
 * @param string_type $type "albums", "images", "pages", "news", "tags"
 * @param int $limit Number of entries to show
 */
function printBarGraph($sortorder = "mostimages", $type = "albums", $from_number = 0, $to_number = 10)
{
    global $gallery, $webpath;
    $limit = $from_number . "," . $to_number;
    $bargraphmaxsize = 400;
    switch ($type) {
        case "albums":
            $typename = gettext("Albums");
            $dbquery = "SELECT * FROM " . prefix('albums');
            break;
        case "images":
            $typename = gettext("Images");
            $dbquery = "SELECT * FROM " . prefix('images');
            break;
        case "pages":
            $typename = gettext("Pages");
            $dbquery = "SELECT * FROM " . prefix('pages');
            break;
        case "news":
            $typename = gettext("News Articles");
            $dbquery = "SELECT * FROM " . prefix('news');
            break;
        case "newscategories":
            $typename = gettext("News Categories");
            $dbquery = "SELECT * FROM " . prefix('news_categories');
            break;
        case "tags":
            $typename = gettext("Tags");
            break;
        case "rss":
            $typename = gettext("rss");
            break;
    }
    switch ($sortorder) {
        case "mostused":
            switch ($type) {
                case "tags":
                    $itemssorted = query_full_array("SELECT tagobj.tagid, count(*) as tagcount, tags.* FROM " . prefix('obj_to_tag') . " AS tagobj, " . prefix('tags') . " AS tags WHERE tags.id=tagobj.tagid GROUP BY tags.id ORDER BY tagcount DESC LIMIT " . $limit);
                    if (empty($itemssorted)) {
                        $maxvalue = 0;
                    } else {
                        $maxvalue = $itemssorted[0]['tagcount'];
                    }
                    break;
                case "newscategories":
                    $itemssorted = query_full_array("SELECT news2cat.cat_id, count(*) as catcount, cats.* FROM " . prefix('news2cat') . " AS news2cat, " . prefix('news_categories') . " AS cats WHERE cats.id=news2cat.cat_id GROUP BY news2cat.cat_id ORDER BY catcount DESC LIMIT " . $limit);
                    if (empty($itemssorted)) {
                        $maxvalue = 0;
                    } else {
                        $maxvalue = $itemssorted[0]['catcount'];
                    }
                    break;
            }
            $headline = $typename . " - " . gettext("most used");
            break;
        case "popular":
            switch ($type) {
                case 'rss':
                    $itemssorted = query_full_array("SELECT `type`,`aux`, `data` FROM " . prefix('plugin_storage') . " WHERE `type` = 'rsshitcounter' ORDER BY CONVERT(data,UNSIGNED) DESC LIMIT " . $limit);
                    if (empty($itemssorted)) {
                        $maxvalue = 0;
                    } else {
                        $maxvalue = $itemssorted[0]['data'];
                    }
                    break;
                default:
                    $itemssorted = query_full_array($dbquery . " ORDER BY hitcounter DESC LIMIT " . $limit);
                    if (empty($itemssorted)) {
                        $maxvalue = 0;
                    } else {
                        $maxvalue = $itemssorted[0]['hitcounter'];
                    }
                    break;
            }
            $headline = $typename . " - " . gettext("most viewed");
            break;
        case "mostrated":
            $itemssorted = query_full_array($dbquery . " ORDER BY total_votes DESC LIMIT " . $limit);
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                $maxvalue = $itemssorted[0]['total_votes'];
            }
            $headline = $typename . " - " . gettext("most rated");
            break;
        case "toprated":
            $itemssorted = query_full_array($dbquery . " ORDER BY (total_value/total_votes) DESC LIMIT {$limit}");
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                if ($itemssorted[0]['total_votes'] != 0) {
                    $maxvalue = $itemssorted[0]['total_value'] / $itemssorted[0]['total_votes'];
                } else {
                    $maxvalue = 0;
                }
            }
            $headline = $typename . " - " . gettext("top rated");
            break;
        case "mostcommented":
            switch ($type) {
                case "albums":
                    $itemssorted = query_full_array("SELECT comments.ownerid, count(*) as commentcount, albums.* FROM " . prefix('comments') . " AS comments, " . prefix('albums') . " AS albums WHERE albums.id=comments.ownerid AND type = 'albums' GROUP BY comments.ownerid ORDER BY commentcount DESC LIMIT " . $limit);
                    break;
                case "images":
                    $itemssorted = query_full_array("SELECT comments.ownerid, count(*) as commentcount, images.* FROM " . prefix('comments') . " AS comments, " . prefix('images') . " AS images WHERE images.id=comments.ownerid AND type = 'images' GROUP BY comments.ownerid ORDER BY commentcount DESC LIMIT " . $limit);
                    break;
                case "pages":
                    $itemssorted = query_full_array("SELECT comments.ownerid, count(*) as commentcount, pages.* FROM " . prefix('comments') . " AS comments, " . prefix('pages') . " AS pages WHERE pages.id=comments.ownerid AND type = 'page' GROUP BY comments.ownerid ORDER BY commentcount DESC LIMIT " . $limit);
                    break;
                case "news":
                    $itemssorted = query_full_array("SELECT comments.ownerid, count(*) as commentcount, news.* FROM " . prefix('comments') . " AS comments, " . prefix('news') . " AS news WHERE news.id=comments.ownerid AND type = 'news' GROUP BY comments.ownerid ORDER BY commentcount DESC LIMIT " . $limit);
                    break;
            }
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                $maxvalue = $itemssorted[0]['commentcount'];
            }
            $headline = $typename . " - " . gettext("most commented");
            break;
        case "mostimages":
            $itemssorted = query_full_array("SELECT images.albumid, count(*) as imagenumber, albums.* FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums WHERE albums.id=images.albumid GROUP BY images.albumid ORDER BY imagenumber DESC LIMIT " . $limit);
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                $maxvalue = $itemssorted[0]['imagenumber'];
            }
            $headline = $typename . " - " . gettext("most images");
            break;
        case "latest":
            switch ($type) {
                case "albums":
                    $allalbums = query_full_array($dbquery . " ORDER BY id DESC LIMIT " . $limit);
                    $albums = array();
                    foreach ($allalbums as $album) {
                        $albumobj = new Album($gallery, $album['folder']);
                        $albumentry = array("id" => $albumobj->get('id'), "title" => $albumobj->getTitle(), "folder" => $albumobj->name, "imagenumber" => $albumobj->getNumImages(), "show" => $albumobj->get("show"));
                        array_unshift($albums, $albumentry);
                    }
                    $maxvalue = 1;
                    $itemssorted = sortMultiArray($albums, 'id', true, true);
                    // The items are originally sorted by id;
                    $headline = $typename . " - " . gettext("latest");
                    break;
                case "images":
                    $itemssorted = query_full_array($dbquery . " ORDER BY id DESC LIMIT " . $limit);
                    $barsize = 0;
                    $maxvalue = 1;
                    $headline = $typename . " - " . gettext("latest");
                    break;
            }
            break;
        case "latestupdated":
            $albums = getAlbumStatistic($to_number, 'latestupdated', '');
            $maxvalue = 1;
            if (!empty($albums)) {
                foreach ($albums as $key => $album) {
                    $albumobj = new Album($gallery, $album['folder']);
                    $albums[$key]['imagenumber'] = $albumobj->getNumImages();
                }
            }
            $itemssorted = $albums;
            $headline = $typename . " - " . gettext("latest updated");
            break;
    }
    if ($maxvalue == 0 || empty($itemssorted)) {
        $maxvalue = 1;
        $no_hitcount_enabled_msg = '';
        if ($sortorder == 'popular' && $type != 'rss' && !getOption('zp_plugin_hitcounter')) {
            $no_hitcount_enabled_msg = gettext("(The hitcounter plugin is not enabled.)");
        }
        $no_statistic_message = "<tr><td><em>" . gettext("No statistic available.") . $no_hitcount_enabled_msg . "</em></td><td></td><td></td><td></td></tr>";
    } else {
        $no_statistic_message = "";
        if ($sortorder == 'popular' && $type != 'rss' && !getOption('zp_plugin_hitcounter')) {
            $no_statistic_message = "<tr><td colspan='4'><em>" . gettext("Note: The hitcounter plugin is not enabled, therefore any existing values will not get updated.") . "</em></td><td></td><td></td><td></td></tr>";
        }
    }
    if ($from_number <= 1) {
        $count = 1;
    } else {
        $count = $from_number;
    }
    $countlines = 0;
    echo "<table class='bordered'>";
    echo "<tr><th colspan='4'><strong>" . $headline . "</strong>";
    if (isset($_GET['stats'])) {
        echo "<a href='gallery_statistics.php'> | " . gettext("Back to the top 10 lists") . "</a>";
    } else {
        if (empty($no_statistic_message)) {
            echo "<a href='gallery_statistics.php?stats=" . $sortorder . "&amp;type=" . $type . "'> | " . gettext("View more") . "</a>";
        }
        echo "<a href='#top'> | " . gettext("top") . "</a>";
    }
    echo "</th></tr>";
    echo $no_statistic_message;
    foreach ($itemssorted as $item) {
        if (array_key_exists("filename", $item)) {
            $name = $item['filename'];
        } else {
            if (array_key_exists("folder", $item)) {
                $name = $item['folder'];
            } else {
                if ($type === "pages" or $type === "news") {
                    $name = $item['titlelink'];
                } else {
                    if ($type === "newscategories") {
                        $name = $item['title'];
                    } else {
                        if ($type === "tags") {
                            $name = "";
                        }
                    }
                }
            }
        }
        switch ($sortorder) {
            case "popular":
                switch ($type) {
                    case 'rss':
                        $barsize = round($item['data'] / $maxvalue * $bargraphmaxsize);
                        $value = $item['data'];
                        break;
                    default:
                        $barsize = round($item['hitcounter'] / $maxvalue * $bargraphmaxsize);
                        $value = $item['hitcounter'];
                        break;
                }
                break;
            case "mostrated":
                if ($item['total_votes'] != 0) {
                    $barsize = round($item['total_votes'] / $maxvalue * $bargraphmaxsize);
                } else {
                    $barsize = 0;
                }
                $value = $item['total_votes'];
                break;
            case "toprated":
                if ($item['total_votes'] != 0) {
                    $barsize = round($item['total_value'] / $item['total_votes'] / $maxvalue * $bargraphmaxsize);
                    $value = round($item['total_value'] / $item['total_votes']);
                } else {
                    $barsize = 0;
                    $value = 0;
                }
                break;
            case "mostcommented":
                if ($maxvalue != 0) {
                    $barsize = round($item['commentcount'] / $maxvalue * $bargraphmaxsize);
                } else {
                    $barsize = 0;
                }
                $value = $item['commentcount'];
                break;
            case "mostimages":
                $barsize = round($item['imagenumber'] / $maxvalue * $bargraphmaxsize);
                $value = $item['imagenumber'];
                break;
            case "latest":
                switch ($type) {
                    case "albums":
                        $barsize = 0;
                        //round($item['imagenumber'] / $maxvalue * $bargraphmaxsize);
                        $value = sprintf(gettext("%s images"), $item['imagenumber']);
                        break;
                    case "images":
                        $barsize = 0;
                        $value = "";
                        break;
                }
                break;
            case "latestupdated":
                $barsize = 0;
                //round($item['imagenumber'] / $maxvalue * $bargraphmaxsize);
                $value = sprintf(gettext("%s images"), $item['imagenumber']);
                break;
            case "mostused":
                switch ($type) {
                    case "tags":
                        if ($maxvalue != 0) {
                            $barsize = round($item['tagcount'] / $maxvalue * $bargraphmaxsize);
                        } else {
                            $barsize = 0;
                        }
                        $value = $item['tagcount'];
                        break;
                    case "newscategories":
                        if ($maxvalue != 0) {
                            $barsize = round($item['catcount'] / $maxvalue * $bargraphmaxsize);
                        } else {
                            $barsize = 0;
                        }
                        $value = $item['catcount'];
                        break;
                }
                break;
        }
        // counter to have a gray background of every second line
        if ($countlines === 1) {
            $style = " style='background-color: #f4f4f4'";
            // a little ugly but the already attached class for the table is so easiest overriden...
            $countlines = 0;
        } else {
            $style = "";
            $countlines++;
        }
        switch ($type) {
            case "albums":
                $editurl = $webpath . "/admin-edit.php?page=edit&amp;album=" . $name;
                $viewurl = WEBPATH . "/index.php?album=" . $name;
                $title = get_language_string($item['title']);
                break;
            case "images":
                $getalbumfolder = query_single_row("SELECT title, folder, `show` from " . prefix("albums") . " WHERE id = " . $item['albumid']);
                if ($sortorder === "latest") {
                    $value = "<span";
                    if ($getalbumfolder['show'] != "1") {
                        $value = $value . " class='unpublished_item'";
                    }
                    $value = $value . ">" . get_language_string($getalbumfolder['title']) . "</span> (" . $getalbumfolder['folder'] . ")";
                }
                $editurl = $webpath . "/admin-edit.php?page=edit&amp;album=" . $getalbumfolder['folder'] . "&amp;image=" . $item['filename'] . "&amp;tab=imageinfo#IT";
                $viewurl = WEBPATH . "/index.php?album=" . $getalbumfolder['folder'] . "&amp;image=" . $name;
                $title = get_language_string($item['title']);
                break;
            case "pages":
                $editurl = $webpath . '/' . PLUGIN_FOLDER . "/zenpage/admin-edit.php?page&amp;titlelink=" . $name;
                $viewurl = WEBPATH . "/index.php?p=pages&amp;title=" . $name;
                $title = get_language_string($item['title']);
                break;
            case "news":
                $editurl = $webpath . '/' . PLUGIN_FOLDER . "/zenpage/admin-edit.php?news&amp;titlelink=" . $name;
                $viewurl = WEBPATH . "/index.php?p=news&amp;title=" . $name;
                $title = get_language_string($item['title']);
                break;
            case "newscategories":
                $editurl = $webpath . '/' . PLUGIN_FOLDER . "/zenpage/admin-categories.php?edit&amp;id=" . $item['id'];
                $viewurl = WEBPATH . "/index.php?p=news&amp;category=" . $name;
                $title = get_language_string($item['titlelink']);
                break;
            case "tags":
                $editurl = $webpath . "/admin-tags.php";
                $viewurl = WEBPATH . "/index.php?p=search&amp;searchfields=tags&amp;words=" . $item['name'];
                $title = get_language_string($item['name']);
                break;
            case "rss":
                $editurl = '';
                $viewurl = WEBPATH . "/index.php?" . html_encode(strrchr($item['aux'], 'rss'));
                $title = html_encode(strrchr($item['aux'], 'rss'));
                break;
        }
        if (isset($item['show'])) {
            if ($item['show'] != "1") {
                $show = " class='unpublished_item'";
            } else {
                $show = "";
            }
        } else {
            $show = "";
        }
        if ($value != 0 or $sortorder === "latest") {
            if (empty($name)) {
                $name = "";
            } else {
                $name = "(" . $name . ")";
            }
            ?>
		<tr class="statistic_wrapper">
		<td class="statistic_counter" <?php 
            echo $style;
            ?>
>
		<?php 
            echo $count;
            ?>
		</td>
		<td class="statistic_title" <?php 
            echo $style;
            ?>
>
		<strong<?php 
            echo $show;
            ?>
><?php 
            echo $title;
            ?>
</strong> <?php 
            echo $name;
            ?>
		</td>
		<td class="statistic_graphwrap" <?php 
            echo $style;
            ?>
>
		<div class="statistic_bargraph" style="width: <?php 
            echo $barsize;
            ?>
px"></div>
		<div class="statistic_value"><?php 
            echo $value;
            ?>
</div>
		</td>
		<td class="statistic_link" <?php 
            echo $style;
            ?>
>
		<?php 
            switch ($type) {
                case 'rss':
                    echo "<a href='" . $viewurl . "' title='" . $name . "'>" . gettext("View") . "</a></td>";
                    break;
                default:
                    echo "<a href='" . $editurl . "' title='" . $name . "'>" . gettext("Edit") . "</a> | <a href='" . $viewurl . "' title='" . $name . "'>" . gettext("View") . "</a></td>";
                    break;
            }
            echo "</tr>";
            $count++;
            if ($count === $limit) {
                break;
            }
        }
    }
    // foreach end
    echo "</table>";
}
        $album->setSortDirection('image', 0);
        $album->save();
    }
    // Layout the page
    printLogoAndLinks();
    ?>

<div id="main"><?php 
    printTabs('edit');
    ?>


<div id="content">

<h1>Sort Album: <?php 
    echo $album->getTitle();
    ?>
</h1>
<p><?php 
    printAlbumEditLinks('', "&laquo; " . gettext("back to the album list"), gettext("Back to the list of albums"));
    ?>
 
| <?php 
    printAlbumEditLinks("&album=" . urlencode($album->getFolder()), gettext("edit album"), gettext("Edit Album"));
    ?>
 
| <?php 
    printViewLink($album, gettext("view album"), gettext("View Album"));
    ?>
</p>
	<?php 
/**
 * Prints the latest news either only news articles or with the latest images or albums as a unordered html list
 *
 * NOTE: Latest images and albums require the image_album_statistic plugin
 *
 * @param int $number The number of news items to get
 * @param string $option "none" for only news articles
 * 											 "with_latest_images" for news articles with the latest images by id
 * 											 "with_latest_images_date" for news articles with the latest images by date
 * 											 "with_latest_images_mtime" for news articles with the latest images by mtime (upload date)
 * 											 "with_latest_albums" for news articles with the latest albums by id
 * 											 "with_latestupdated_albums" for news articles with the latest updated albums
 * @param string $category Optional news articles by category (only "none" option"
 * @param bool $showdate If the date should be shown
 * @param bool $showcontent If the content should be shown
 * @param int $contentlength The lengths of the content
 * @param bool $showcat If the categories should be shown
 * @param string $readmore Text for the read more link, if empty the option value for "zenpage_readmore" is used
 * @return string
 */
function printLatestNews($number = 5, $option = 'with_latest_images', $category = '', $showdate = true, $showcontent = true, $contentlength = 70, $showcat = true, $readmore = NULL)
{
    global $_zp_gallery, $_zp_current_zenpage_news;
    //trigger_error(gettext('printLatestNews is deprecated. Use printLatestCombiNews().'), E_USER_NOTICE);
    $latest = getLatestNews($number, $option, $category);
    echo "\n<ul id=\"latestnews\">\n";
    $count = "";
    foreach ($latest as $item) {
        $count++;
        $category = "";
        $categories = "";
        switch ($item['type']) {
            case 'news':
                $obj = new ZenpageNews($item['titlelink']);
                $title = html_encode($obj->getTitle());
                $link = html_encode(getNewsURL($item['titlelink']));
                $count2 = 0;
                $category = $obj->getCategories();
                foreach ($category as $cat) {
                    $catobj = new ZenpageCategory($cat['titlelink']);
                    $count2++;
                    if ($count2 != 1) {
                        $categories = $categories . ", ";
                    }
                    $categories = $categories . $catobj->getTitle();
                }
                $thumb = "";
                $content = $obj->getContent();
                $date = zpFormattedDate(DATE_FORMAT, strtotime($item['date']));
                $type = 'news';
                break;
            case 'images':
                $obj = newImage(new Album($_zp_gallery, $item['albumname']), $item['titlelink']);
                $categories = $item['albumname'];
                $title = $obj->getTitle();
                $link = html_encode($obj->getImageLink());
                $content = $obj->getDesc();
                if ($option == "with_latest_image_date") {
                    $date = zpFormattedDate(DATE_FORMAT, $item['date']);
                } else {
                    $date = zpFormattedDate(DATE_FORMAT, strtotime($item['date']));
                }
                $thumb = "<a href=\"" . $link . "\" title=\"" . html_encode(strip_tags($title)) . "\"><img src=\"" . html_encode($obj->getThumb()) . "\" alt=\"" . html_encode(strip_tags($title)) . "\" /></a>\n";
                $type = "image";
                break;
            case 'albums':
                $obj = new Album($_zp_gallery, $item['albumname']);
                $title = $obj->getTitle();
                $categories = "";
                $link = html_encode($obj->getAlbumLink());
                $thumb = "<a href=\"" . $link . "\" title=\"" . $title . "\"><img src=\"" . html_encode($obj->getAlbumThumb()) . "\" alt=\"" . strip_tags($title) . "\" /></a>\n";
                $content = $obj->getDesc();
                $date = zpFormattedDate(DATE_FORMAT, strtotime($item['date']));
                $type = "album";
                break;
        }
        echo "<li>";
        if (!empty($thumb)) {
            echo $thumb;
        }
        echo "<h3><a href=\"" . $link . "\" title=\"" . strip_tags(html_encode($title)) . "\">" . $title . "</a></h3>\n";
        if ($showdate) {
            echo "<span class=\"latestnews-date\">" . $date . "</span>\n";
        }
        if ($showcontent) {
            echo "<span class=\"latestnews-desc\">" . getContentShorten($content, $contentlength, '', $readmore, $link) . "</span>\n";
        }
        if ($showcat and $type != "album" && !empty($categories)) {
            echo "<span class=\"latestnews-cats\">(" . html_encode($categories) . ")</span>\n";
        }
        echo "</li>\n";
        if ($count == $number) {
            break;
        }
    }
    echo "</ul>\n";
}
/**
 * Prints all albums of the Zenphoto gallery as a partial drop down menu (<option></option> parts).
 *
 * @return string
 */
function printAlbumsSelector()
{
    global $_zp_gallery;
    $albumlist;
    genAlbumUploadList($albumlist);
    ?>
	<select id="albumselector" name="albumselect">
	<?php 
    foreach ($albumlist as $key => $value) {
        $albumobj = new Album($_zp_gallery, $key);
        $albumname = $albumobj->name;
        $level = substr_count($albumname, "/");
        $arrow = "";
        for ($count = 1; $count <= $level; $count++) {
            $arrow .= "&raquo; ";
        }
        echo "<option value='" . html_encode($albumobj->name) . "'>";
        echo $arrow . $albumobj->getTitle() . unpublishedZenphotoItemCheck($albumobj) . "</option>";
    }
    ?>
	</select>
	<?php 
}
/**
 * Handles an album for printAlbumMenuList
 *
 * @param array $albums albums array
 * @param string $path for createAlbumMenuLink
 * @param string $folder
 * @param string $option see printAlbumMenuList
 * @param string $showcount see printAlbumMenuList
 * @param int $showsubs see printAlbumMenuList
 * @param string $css_class see printAlbumMenuList
 * @param string $css_class_topactive see printAlbumMenuList
 * @param string $css_class_active see printAlbumMenuList
 * @param bool $firstimagelink If set to TRUE and if the album has images the link will point to page of the first image instead the album thumbnail page
 * @param bool $keeptopactive If set to TRUE the toplevel album entry will stay marked as active if within its subalbums ("list" only)
 * @param int $limit truncation of display text
 */
function printAlbumMenuListAlbum($albums, $path, $folder, $option, $showcount, $showsubs, $css_class, $css_class_topactive, $css_class_active, $firstimagelink, $keeptopactive, $limit = NULL)
{
    global $_zp_gallery, $_zp_current_album;
    if (is_null($limit)) {
        $limit = MENU_TRUNCATE_STRING;
    }
    if (is_null($showcount)) {
        $showcount = ALBUM_MENU_COUNT;
    }
    if (is_null($showsubs)) {
        $showsubs = ALBUM_MENU_SHOWSUBS;
    }
    if ($showsubs && !is_numeric($showsubs)) {
        $showsubs = 9999999999.0;
    }
    if (empty($keeptopactive)) {
        $keeptopactive = false;
    }
    $pagelevel = count(explode('/', $folder));
    $currenturalbumname = "";
    foreach ($albums as $album) {
        $level = count(explode('/', $album));
        $process = $level < $showsubs && $option == "list" || $option != 'list-top' && strpos($folder, $album) === 0 && $level <= $pagelevel;
        $topalbum = new Album($_zp_gallery, $album, true);
        if ($level > 1 || $option != 'omit-top') {
            // listing current level album
            if ($level == 1) {
                $css_class_t = $css_class_topactive;
            } else {
                $css_class_t = $css_class_active;
            }
            if ($keeptopactive) {
                if (isset($_zp_current_album) && is_object($_zp_current_album)) {
                    $currenturalbum = getUrAlbum($_zp_current_album);
                    $currenturalbumname = $currenturalbum->name;
                }
            }
            $count = "";
            if ($showcount) {
                $toplevelsubalbums = $topalbum->getAlbums();
                $toplevelsubalbums = count($toplevelsubalbums);
                $topalbumnumimages = $topalbum->getNumImages();
                $count = ' <span style="white-space:nowrap;"><small>(';
                if ($toplevelsubalbums > 0) {
                    $count .= sprintf(ngettext('%u album', '%u albums', $toplevelsubalbums), $toplevelsubalbums);
                }
                if ($topalbumnumimages > 0) {
                    if ($toplevelsubalbums) {
                        $count .= ' ';
                    }
                    $count .= sprintf(ngettext('%u image', '%u images', $topalbumnumimages), $topalbumnumimages);
                }
                $count .= ')</small></span>';
            }
            if (in_context(ZP_ALBUM) && !in_context(ZP_SEARCH_LINKED) && (getAlbumID() == $topalbum->getAlbumID() || $topalbum->name == $currenturalbumname)) {
                $current = $css_class_t . ' ';
            } else {
                $current = "";
            }
            $title = $topalbum->getTitle();
            if ($limit) {
                $display = shortenContent($title, $limit, MENU_TRUNCATE_INDICATOR);
            } else {
                $display = $title;
            }
            if ($firstimagelink && $topalbum->getNumImages() != 0) {
                $imgurl = getFirstImageOfAlbum($topalbum);
                $link = "<li><a " . $current . "href='" . $imgurl . "' title='" . html_encode($title) . "'>" . html_encode($display) . "</a>" . $count;
            } else {
                $link = "<li><a " . $current . "href='" . html_encode($path . pathurlencode($topalbum->name)) . "' title='" . html_encode($title) . "'>" . html_encode($display) . "</a>" . $count;
            }
            echo $link;
        }
        if ($process) {
            // listing subalbums
            $subalbums = $topalbum->getAlbums();
            if (!empty($subalbums)) {
                echo "\n<ul" . $css_class . ">\n";
                printAlbumMenuListAlbum($subalbums, $path, $folder, $option, $showcount, $showsubs, $css_class, $css_class_topactive, $css_class_active, $firstimagelink, false, $limit);
                echo "\n</ul>\n";
            }
        }
        if ($option == 'list' || $option == 'list-top' || $level > 1) {
            // close the LI
            echo "\n</li>\n";
        }
    }
}
            if (!empty($_REQUEST['themealbum'])) {
                $alb = urldecode(sanitize_path($_REQUEST['themealbum']));
                $album = new Album($gallery, $alb);
                $albumtitle = $album->getTitle();
                $themename = $album->getAlbumTheme();
            } else {
                foreach ($themelist as $albumtitle => $alb) {
                    break;
                }
                if (empty($alb)) {
                    $themename = $gallery->getCurrentTheme();
                    $album = NULL;
                } else {
                    $alb = sanitize_path($alb);
                    $album = new Album($gallery, $alb);
                    $albumtitle = $album->getTitle();
                    $themename = $album->getAlbumTheme();
                }
            }
            ?>
	<form action="?action=saveoptions" method="post" AUTOCOMPLETE=OFF>
		<input type="hidden" name="savethemeoptions" value="yes" />
		<table class='bordered'>
		<?php 
            if (count($themelist) == 0) {
                ?>
			<th>
			<br />
			<div class="errorbox" id="no_themes">
			<h2><?php 
                echo gettext("There are no themes for which you have rights to administer.");
/**
 * 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>";
}
/**
 * Prints a table with a bar graph of the values.
 *
 * @param string $sortorder "popular", "mostrated","toprated","mostcommented" or - only if $type = "albums"! - "mostimages" 
 * @param string_type $type "albums" or "images"
 * @param int $limit Number of entries to show
 */
function printBarGraph($sortorder = "mostimages", $type = "albums", $from_number = 0, $to_number = 10)
{
    global $gallery, $webpath;
    $limit = $from_number . "," . $to_number;
    $bargraphmaxsize = 400;
    switch ($type) {
        case "albums":
            $typename = gettext("Albums");
            $dbquery = "SELECT id, title, folder, hitcounter, total_votes, total_value, `show` FROM " . prefix('albums');
            break;
        case "images":
            $typename = gettext("Images");
            $dbquery = "SELECT id, title, filename, albumid, hitcounter, total_votes, total_value, `show` FROM " . prefix('images');
            break;
    }
    switch ($sortorder) {
        case "popular":
            $itemssorted = query_full_array($dbquery . " ORDER BY hitcounter DESC LIMIT " . $limit);
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                $maxvalue = $itemssorted[0]['hitcounter'];
            }
            $headline = $typename . " - " . gettext("most viewed");
            break;
        case "mostrated":
            $itemssorted = query_full_array($dbquery . " ORDER BY total_votes DESC LIMIT " . $limit);
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                $maxvalue = $itemssorted[0]['total_votes'];
            }
            $headline = $typename . " - " . gettext("most rated");
            break;
        case "toprated":
            switch ($type) {
                case "albums":
                    $itemssorted = query_full_array("SELECT * FROM " . prefix('albums') . " ORDER BY (total_value/total_votes) DESC LIMIT {$limit}");
                    break;
                case "images":
                    $itemssorted = query_full_array("SELECT * FROM " . prefix('images') . " ORDER BY (total_value/total_votes) DESC LIMIT {$limit}");
                    break;
            }
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                if ($itemssorted[0]['total_votes'] != 0) {
                    $maxvalue = $itemssorted[0]['total_value'] / $itemssorted[0]['total_votes'];
                } else {
                    $maxvalue = 0;
                }
            }
            $headline = $typename . " - " . gettext("top rated");
            break;
        case "mostcommented":
            switch ($type) {
                case "albums":
                    $itemssorted = query_full_array("SELECT comments.ownerid, count(*) as commentcount, albums.* FROM " . prefix('comments') . " AS comments, " . prefix('albums') . " AS albums WHERE albums.id=comments.ownerid AND type = 'albums' GROUP BY comments.ownerid ORDER BY commentcount DESC LIMIT " . $limit);
                    break;
                case "images":
                    $itemssorted = query_full_array("SELECT comments.ownerid, count(*) as commentcount, images.* FROM " . prefix('comments') . " AS comments, " . prefix('images') . " AS images WHERE images.id=comments.ownerid AND type = 'images' GROUP BY comments.ownerid ORDER BY commentcount DESC LIMIT " . $limit);
                    break;
            }
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                $maxvalue = $itemssorted[0]['commentcount'];
            }
            $headline = $typename . " - " . gettext("most commented");
            break;
        case "mostimages":
            $itemssorted = query_full_array("SELECT images.albumid, count(*) as imagenumber, albums.* FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums WHERE albums.id=images.albumid GROUP BY images.albumid ORDER BY imagenumber DESC LIMIT " . $limit);
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                $maxvalue = $itemssorted[0]['imagenumber'];
            }
            $headline = $typename . " - " . gettext("most images");
            break;
        case "latest":
            switch ($type) {
                case "albums":
                    $allalbums = query_full_array($dbquery . " ORDER BY id DESC LIMIT " . $limit);
                    $albums = array();
                    foreach ($allalbums as $album) {
                        $albumobj = new Album($gallery, $album['folder']);
                        $albumentry = array("id" => $albumobj->get('id'), "title" => $albumobj->getTitle(), "folder" => $albumobj->name, "imagenumber" => $albumobj->getNumImages(), "show" => $albumobj->get("show"));
                        array_unshift($albums, $albumentry);
                    }
                    $maxvalue = 0;
                    if (empty($albums)) {
                        $itemssorted = array();
                    } else {
                        foreach ($albums as $entry) {
                            if (array_key_exists('imagenumber', $entry)) {
                                $v = $entry['imagenumber'];
                                if ($v > $maxvalue) {
                                    $maxvalue = $v;
                                }
                            }
                        }
                        $itemssorted = $albums;
                        // The items are originally sorted by id;
                    }
                    $headline = $typename . " - " . gettext("latest");
                    break;
                case "images":
                    $itemssorted = query_full_array($dbquery . " ORDER BY id DESC LIMIT " . $limit);
                    $barsize = 0;
                    $maxvalue = 1;
                    $headline = $typename . " - " . gettext("latest");
                    break;
            }
            break;
        case "latestupdated":
            // part taken from the image_albums_statistics - could probably be optimized regarding queries...
            // get all albums
            $allalbums = query_full_array("SELECT id, title, folder, `show` FROM " . prefix('albums'));
            $albums = array();
            $latestimages = array();
            foreach ($allalbums as $album) {
                $albumobj = new Album($gallery, $album['folder']);
                $albumentry = array("id" => $albumobj->get('id'), "title" => $albumobj->getTitle(), "folder" => $albumobj->name, "imagenumber" => $albumobj->getNumImages(), "show" => $albumobj->get("show"));
                array_unshift($albums, $albumentry);
            }
            // get latest images of each album
            $count = 0;
            foreach ($albums as $album) {
                $count++;
                $image = query_single_row("SELECT id, albumid, mtime FROM " . prefix('images') . " WHERE albumid = " . $album['id'] . " ORDER BY id DESC LIMIT 1");
                if (is_array($image)) {
                    array_push($latestimages, $image);
                }
                if ($count === $to_number) {
                    break;
                }
            }
            // sort latest image by mtime
            $latestimages = sortMultiArray($latestimages, "mtime", "desc", false, false);
            //echo "<pre>"; print_r($albums); echo "</pre>";
            $itemssorted = array();
            $count = 0;
            foreach ($latestimages as $latestimage) {
                $count++;
                foreach ($allalbums as $album) {
                    if ($album['id'] === $latestimage['albumid']) {
                        array_push($albums, $album);
                    }
                }
                if ($count === $to_number) {
                    break;
                }
            }
            if ($to_number < 1) {
                $stopelement = 1;
            } else {
                $stopelement = $to_number;
            }
            $albums = array_slice($albums, 0, $stopelement);
            // clear unnessesary items fron array
            $maxvalue = 0;
            if (empty($albums)) {
                $itemssorted = array();
            } else {
                foreach ($albums as $key => $entry) {
                    if (array_key_exists('imagenumber', $entry)) {
                        $v = $entry['imagenumber'];
                        if ($v > $maxvalue) {
                            $maxvalue = $v;
                        }
                    } else {
                        unset($albums[$key]);
                        // if it has no imagenumber it must not be a valid entry!
                    }
                }
                $itemssorted = $albums;
                // The items are originally sorted by id;
            }
            $headline = $typename . " - " . gettext("latest updated");
            //echo "<pre>"; print_r($albums); echo "</pre>";
            break;
    }
    if ($maxvalue == 0 or empty($itemssorted)) {
        $maxvalue = 1;
        $no_statistic_message = "<tr><td><em>" . gettext("No statistic available") . "</em></td><td></td><td></td><td></td></tr>";
    } else {
        $no_statistic_message = "";
    }
    if ($from_number <= 1) {
        $count = 1;
    } else {
        $count = $from_number;
    }
    $countlines = 0;
    echo "<table class='bordered'>";
    echo "<tr><th colspan='4'><strong>" . $headline . "</strong>";
    if (isset($_GET['stats'])) {
        echo "<a href='gallery_statistics.php'> | " . gettext("Back to the top 10 lists") . "</a>";
    } else {
        if (empty($no_statistic_message)) {
            echo "<a href='gallery_statistics.php?stats=" . $sortorder . "&amp;type=" . $type . "'> | " . gettext("View more") . "</a>";
        }
        echo "<a href='#top'> | " . gettext("top") . "</a>";
    }
    echo "</th></tr>";
    echo $no_statistic_message;
    foreach ($itemssorted as $item) {
        if (array_key_exists("filename", $item)) {
            $name = $item['filename'];
        } else {
            if (array_key_exists("folder", $item)) {
                $name = $item['folder'];
            }
        }
        switch ($sortorder) {
            case "popular":
                $barsize = round($item['hitcounter'] / $maxvalue * $bargraphmaxsize);
                $value = $item['hitcounter'];
                break;
            case "mostrated":
                if ($item['total_votes'] != 0) {
                    $barsize = round($item['total_votes'] / $maxvalue * $bargraphmaxsize);
                } else {
                    $barsize = 0;
                }
                $value = $item['total_votes'];
                break;
            case "toprated":
                if ($item['total_votes'] != 0) {
                    $barsize = round($item['total_value'] / $item['total_votes'] / $maxvalue * $bargraphmaxsize);
                    $value = round($item['total_value'] / $item['total_votes']);
                } else {
                    $barsize = 0;
                    $value = 0;
                }
                break;
            case "mostcommented":
                if ($maxvalue != 0) {
                    $barsize = round($item['commentcount'] / $maxvalue * $bargraphmaxsize);
                } else {
                    $barsize = 0;
                }
                $value = $item['commentcount'];
                break;
            case "mostimages":
                $barsize = round($item['imagenumber'] / $maxvalue * $bargraphmaxsize);
                $value = $item['imagenumber'];
                break;
            case "latest":
                switch ($type) {
                    case "albums":
                        $barsize = 0;
                        //round($item['imagenumber'] / $maxvalue * $bargraphmaxsize);
                        $value = sprintf(gettext("%s images"), $item['imagenumber']);
                        break;
                    case "images":
                        $barsize = 0;
                        $value = "";
                        break;
                }
                break;
            case "latestupdated":
                $barsize = 0;
                //round($item['imagenumber'] / $maxvalue * $bargraphmaxsize);
                $value = sprintf(gettext("%s images"), $item['imagenumber']);
                break;
        }
        // counter to have a gray background of every second line
        if ($countlines === 1) {
            $style = "style='background-color: #f4f4f4'";
            // a little ugly but the already attached class for the table is so easiest overriden...
            $countlines = 0;
        } else {
            $style = "";
            $countlines++;
        }
        switch ($type) {
            case "albums":
                $editurl = $webpath . "/admin.php?page=edit&amp;album=" . $name;
                $viewurl = WEBPATH . "/index.php?album=" . $name;
                break;
            case "images":
                $getalbumfolder = query_single_row("SELECT title, folder, `show` from " . prefix("albums") . " WHERE id = " . $item['albumid']);
                if ($sortorder === "latest") {
                    $value = "<span";
                    if ($getalbumfolder['show'] != "1") {
                        $value = $value . " class='unpublished_item'";
                    }
                    $value = $value . ">" . get_language_string($getalbumfolder['title']) . "</span> (" . $getalbumfolder['folder'] . ")";
                }
                $editurl = $webpath . "/admin.php?page=edit&amp;album=" . $getalbumfolder['folder'] . "&amp;image=" . $item['filename'] . "&amp;tab=imageinfo#IT";
                $viewurl = WEBPATH . "/index.php?album=" . $getalbumfolder['folder'] . "&amp;image=" . $name;
                break;
        }
        if ($item['show'] != "1") {
            $show = " class='unpublished_item'";
        } else {
            $show = "";
        }
        if ($value != 0 or $sortorder === "latest") {
            ?>
		<tr class="statistic_wrapper">
		<td class="statistic_counter" <?php 
            echo $style;
            ?>
><?php 
            echo $count;
            ?>
</td>
		<td class="statistic_title" <?php 
            echo $style;
            ?>
><strong<?php 
            echo $show;
            ?>
><?php 
            echo get_language_string($item['title']);
            ?>
</strong> (<?php 
            echo $name;
            ?>
)</td>
		<td class="statistic_graphwrap" <?php 
            echo $style;
            ?>
><div class="statistic_bargraph" style="width: <?php 
            echo $barsize;
            ?>
px"></div><div class="statistic_value"><?php 
            echo $value;
            ?>
</div></td>
		<td class="statistic_link" <?php 
            echo $style;
            ?>
>
		<?php 
            echo "<a href='" . $editurl . "' title='" . $name . "'>" . gettext("Edit") . "</a> | <a href='" . $viewurl . "' title='" . $name . "'>" . gettext("View") . "</a></td";
            echo "</tr>";
            $count++;
            if ($count === $limit) {
                break;
            }
        }
    }
    // foreach end
    echo "</table>";
}
 static function printAlbumMenuJumpAlbum($albums, $option, $albumpath, $level = 1)
 {
     global $_zp_gallery;
     foreach ($albums as $album) {
         $subalbum = new Album($_zp_gallery, $album, true);
         if ($option === "count" and $subalbum->getNumImages() > 0) {
             $count = " (" . $subalbum->getNumImages() . ")";
         } else {
             $count = "";
         }
         $arrow = str_replace(':', '&raquo; ', str_pad("", $level - 1, ":"));
         $selected = self::checkSelectedAlbum($subalbum->name, "album");
         $link = "<option {$selected} value='" . htmlspecialchars($albumpath . pathurlencode($subalbum->name)) . "'>" . $arrow . strip_tags($subalbum->getTitle()) . $count . "</option>";
         echo $link;
     }
 }
/**
 * Prints the images and/or albums as thumbnails of the selected album
 *
 * @param $number int The number of images per page
 *
 * @return string
 */
function printImageslist($number)
{
    global $_zp_gallery, $host;
    if (isset($_GET['album']) and !empty($_GET['album'])) {
        $album = urldecode(sanitize($_GET['album']));
        $albumobj = new Album($_zp_gallery, $album);
        echo "<h3 style='margin-bottom:10px'>" . gettext("Album:") . " <em>" . html_encode($albumobj->getTitle()) . unpublishedZenphotoItemCheck($albumobj, false) . "</em> / " . gettext("Album folder:") . " <em>" . html_encode($albumobj->name) . "</em><br /><small>" . gettext("(Click on image to include)") . "</small></h3>";
        // album thumb display;
        $albumthumb = $albumobj->getAlbumThumbImage();
        $albumthumbalbum = $albumthumb->getAlbum();
        $albumdesc = '';
        $albumdesc = $albumobj->getDesc();
        $imagedesc = $albumthumb->getDesc();
        $imgurl = $host . WEBPATH . '/' . ZENFOLDER . "/i.php?a=" . urlencode(pathurlencode($albumthumbalbum->name)) . "&amp;i=" . urlencode(urlencode($albumthumb->filename));
        $fullimage = pathurlencode($albumthumb->getFullImage());
        $videocheck = checkIfImageVideo($albumthumb);
        if (get_class($albumthumb) == '_Image') {
            $video = '';
            $backgroundcss = 'border: 1px solid gray; padding: 1px;';
            $imgurl = $host . WEBPATH . '/' . ZENFOLDER . "/i.php?a=" . urlencode(pathurlencode($albumthumbalbum->name)) . "&amp;i=" . urlencode(urlencode($albumthumb->filename));
        } else {
            $backgroundcss = 'border: 1px solid orange; padding: 1px;background-color: orange';
            $video = $videocheck;
            $imgurl = $albumthumb->getThumb();
        }
        $imgsizeurl = $albumthumb->getCustomImage(85, NULL, NULL, 85, 85, NULL, NULL, TRUE);
        echo "<div class='albumthumb' style='width: 85px; height: 100px; float: left; margin: 10px 10px 10px 13px'>";
        echo "<a href=\"javascript:ZenpageDialog.insert('" . $imgurl . "','" . urlencode($albumthumb->filename) . "','" . html_encode($albumthumb->getTitle()) . "','" . html_encode($albumobj->getTitle()) . "','" . $fullimage . "','zenphoto','" . html_encode(getWatermarkParam($albumthumb, WATERMARK_THUMB)) . "','" . html_encode(getWatermarkParam($albumthumb, WATERMARK_IMAGE)) . "','" . $video . "','" . html_encode($imagedesc) . "','" . html_encode($albumdesc) . "');\"" . " title='" . html_encode($albumthumb->getTitle()) . " (" . html_encode($albumthumb->filename) . ")'><img src='" . $imgsizeurl . "' style='" . $backgroundcss . "' /></a>\n";
        echo "<a href='zoom.php?image=" . urlencode($albumthumb->filename) . "&amp;album=" . pathurlencode($albumthumbalbum->name) . "' title='Zoom' rel='colorbox' style='outline: none;'><img src='img/magnify.png' alt='' style='border: 0' /></a> " . gettext('<em>Albumthumb</em>') . unpublishedZenphotoItemCheck($albumthumb, false);
        echo "</div>";
        $images = $albumobj->getImages();
        if ($albumobj->getNumImages() != 0) {
            $images_per_page = $number;
            if (isset($_GET['page'])) {
                $currentpage = sanitize_numeric($_GET['page']);
            } else {
                $currentpage = 1;
            }
            $imagecount = $albumobj->getNumImages();
            $pagestotal = ceil($imagecount / $images_per_page);
            for ($nr = 1; $nr <= $pagestotal; $nr++) {
                $startimage[$nr] = $nr * $images_per_page - $images_per_page;
                // get start image number
                $endimage[$nr] = $nr * $images_per_page - 1;
                // get end image number
            }
            $number = $startimage[$currentpage];
            printTinyPageNav($pagestotal, $currentpage, 'images');
            for ($nr = $number; $nr <= $images_per_page * $currentpage; $nr++) {
                if ($nr === $imagecount) {
                    break;
                }
                if ($albumobj->isDynamic()) {
                    $linkalbumobj = new Album($_zp_gallery, $images[$nr]['folder']);
                    $imageobj = newImage($linkalbumobj, $images[$nr]['filename']);
                } else {
                    $linkalbumobj = $albumobj;
                    $imageobj = newImage($albumobj, $images[$nr]);
                }
                $imagedesc = '';
                $imagedesc = $imageobj->getDesc();
                $albumdesc = '';
                $albumdesc = $linkalbumobj->getDesc();
                $fullimage = pathurlencode($imageobj->getFullImage());
                $videocheck = checkIfImageVideo($imageobj);
                if (get_class($imageobj) == '_Image') {
                    $video = '';
                    $backgroundcss = 'border: 1px solid gray; padding: 1px;';
                    $imgurl = $host . WEBPATH . '/' . ZENFOLDER . "/i.php?a=" . urlencode(pathurlencode($linkalbumobj->name)) . "&amp;i=" . urlencode(urlencode($imageobj->filename));
                } else {
                    if (get_class($imageobj) == 'TextObject' || get_parent_class($imageobj) == 'TextObject') {
                        $video = 'textobject';
                        $imgurl = $imageobj->getThumb();
                        $fullimage = html_encode($imageobj->getBody());
                    } else {
                        $backgroundcss = 'border: 1px solid orange; padding: 1px;background-color: orange';
                        $video = $videocheck;
                        $imgurl = $imageobj->getThumb();
                    }
                }
                $imgsizeurl = $imageobj->getCustomImage(85, NULL, NULL, 85, 85, NULL, NULL, TRUE);
                echo "<div style='width: 85px; height: 100px; float: left; margin: 10px 10px 10px 13px'>\n";
                echo "<a href=\"javascript:ZenpageDialog.insert('" . $imgurl . "','" . urlencode($imageobj->filename) . "','" . html_encode($imageobj->getTitle()) . "','" . html_encode($linkalbumobj->getTitle()) . "','" . $fullimage . "','zenphoto','" . html_encode(getWatermarkParam($imageobj, WATERMARK_THUMB)) . "','" . html_encode(getWatermarkParam($imageobj, WATERMARK_IMAGE)) . "','" . $video . "','" . html_encode($imagedesc) . "','" . html_encode($albumdesc) . "');\"" . " title='" . html_encode($imageobj->getTitle()) . " (" . html_encode($imageobj->filename) . ")'><img src='" . $imgsizeurl . "' style='" . $backgroundcss . "' /></a>\n";
                echo "<a href='zoom.php?image=" . urlencode($imageobj->filename) . "&amp;album=" . pathurlencode($linkalbumobj->name) . "' title='Zoom' rel='colorbox' style='outline: none;'><img src='img/magnify.png' alt='' style='border: 0' /></a> " . html_encode(shortentitle($imageobj->getTitle(), 8)) . unpublishedZenphotoItemCheck($imageobj, false);
                echo "</div>\n";
                if ($nr === $endimage[$currentpage]) {
                    break;
                }
            }
            // for end
        } else {
            echo "<p style='margin-left: 8px'>" . gettext("<strong>Note:</strong> This album does not contain any images.") . "</p>";
        }
        // if/else  no image end
    }
    // if GET album end
}
function genAlbumUploadList(&$list, $curAlbum = NULL)
{
    $gallery = new Gallery();
    $albums = array();
    if (is_null($curAlbum)) {
        $albumsprime = $gallery->getAlbums(0);
        foreach ($albumsprime as $album) {
            // check for rights
            $albumobj = new Album($gallery, $album);
            if ($albumobj->isMyItem(UPLOAD_RIGHTS)) {
                $albums[] = $album;
            }
        }
    } else {
        $albums = $curAlbum->getAlbums(0);
    }
    if (is_array($albums)) {
        foreach ($albums as $folder) {
            $album = new Album($gallery, $folder);
            if (!$album->isDynamic()) {
                $list[$album->getFolder()] = $album->getTitle();
                genAlbumUploadList($list, $album);
                /* generate for subalbums */
            }
        }
    }
}
/**
 * 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>";
}
 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;
 }