/** * * used to get a list of albums to be further processed * @param object $obj from whence to get the albums * @param array $albumlist collects the list */ function getImageAlbumAlbumList($obj, &$albumlist) { global $_zp_gallery; $hint = $show = false; $locallist = $obj->getAlbums(); foreach ($locallist as $folder) { $album = new Album($_zp_gallery, $folder); if (!$album->isDynamic() && $album->checkAccess($hint, $show)) { $albumlist[] = $album->getID(); getImageAlbumAlbumList($album, $albumlist); } } }
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 }
function loadAlbum($album) { global $gallery, $_zp_current_album, $_zp_current_image; $subalbums = $album->getAlbums(); $started = false; $tcount = $count = 0; foreach ($subalbums as $folder) { $subalbum = new Album($gallery, $folder); if (!$subalbum->isDynamic()) { $tcount = $tcount + loadAlbum($subalbum); } } $theme = $gallery->getCurrentTheme(); $id = 0; $parent = getUrAlbum($album); $albumtheme = $parent->getAlbumTheme(); if (!empty($albumtheme)) { $theme = $albumtheme; $id = $parent->id; } loadLocalOptions($id, $theme); $_zp_current_album = $album; if ($album->getNumImages() > 0) { echo "<br />" . $album->name . ' '; while (next_image(true)) { $thumb = getImageThumb(); if (strpos($thumb, 'i.php?') === false) { $thumb = NULL; } if (isImagePhoto($_zp_current_image)) { $image = getDefaultSizedImage(); if (strpos($image, 'i.php?') === false) { $image = NULL; } } else { $image = NULL; if ($_zp_current_image->objectsThumb == NULL) { $thumb = NULL; } } if (!empty($thumb) || !empty($image)) { if (!$count) { $started = true; echo "{ "; } else { echo ' | '; } } if (!empty($thumb)) { echo '<img src="' . $thumb . '" height="8" width="8" /> '; } if (!empty($image)) { echo ' <img src="' . $image . '" height="20" width="20" />'; } if (!empty($thumb) || !empty($image)) { echo "\n"; } $count++; } if ($started) { echo ' } '; } printf(ngettext('[%u image]', '[%u images]', $count), $count); echo "<br />\n"; } return $count + $tcount; }
/** For every album in the gallery, look for its file. Delete from the database * if the file does not exist. Do the same for images. Clean up comments that have * been left orphaned. * * Returns true if the operation was interrupted because it was taking too long * * @param bool $cascade garbage collect every image and album in the gallery. * @param bool $complete garbage collect every image and album in the *database* - completely cleans the database. * @param int $restart Image ID to restart scan from * @return bool */ function garbageCollect($cascade = true, $complete = false, $restart = '') { if (empty($restart)) { // Check for the existence of top-level albums (subalbums handled recursively). $result = query("SELECT * FROM " . prefix('albums')); $dead = array(); $live = array(''); // purge the root album if it exists $deadalbumthemes = array(); // Load the albums from disk $albumfolder = getAlbumFolder(); while ($row = mysql_fetch_assoc($result)) { if (!file_exists($albumfolder . UTF8ToFilesystem($row['folder'])) || in_array($row['folder'], $live)) { $dead[] = $row['id']; if ($row['album_theme'] !== '') { // orphaned album theme options table $deadalbumthemes[$row['id']] = $row['folder']; } } else { $live[] = $row['folder']; } } if (count($dead) > 0) { /* delete the dead albums from the DB */ $first = array_pop($dead); $sql1 = "DELETE FROM " . prefix('albums') . " WHERE `id`='{$first}'"; $sql2 = "DELETE FROM " . prefix('images') . " WHERE `albumid`='{$first}'"; $sql3 = "DELETE FROM " . prefix('comments') . " WHERE `type`='albums' AND `ownerid`='{$first}'"; $sql4 = "DELETE FROM " . prefix('obj_to_tag') . " WHERE `type`='albums' AND `objectid`='{$first}'"; foreach ($dead as $albumid) { $sql1 .= " OR `id` = '{$albumid}'"; $sql2 .= " OR `albumid` = '{$albumid}'"; $sql3 .= " OR `ownerid` = '{$albumid}'"; $sql4 .= " OR `objectid` = '{$albumid}'"; } $n = query($sql1); if (!$complete && $n > 0 && $cascade) { query($sql2); query($sql3); query($sql4); } } if (count($deadalbumthemes) > 0) { // delete the album theme options tables for dead albums foreach ($deadalbumthemes as $id => $deadtable) { $sql = 'DELETE FROM ' . prefix('options') . ' WHERE `ownerid`=' . $id; query($sql, true); } } } if ($complete) { if (empty($restart)) { /* refresh 'metadata' of dynamic albums */ $albumfolder = getAlbumFolder(); $albumids = query_full_array("SELECT `id`, `mtime`, `folder` FROM " . prefix('albums') . " WHERE `dynamic`='1'"); foreach ($albumids as $album) { if (($mtime = filemtime($albumfolder . UTF8ToFilesystem($album['folder']))) > $album['mtime']) { // refresh $data = file_get_contents($albumfolder . UTF8ToFilesystem($album['folder'])); while (!empty($data)) { $data1 = trim(substr($data, 0, $i = strpos($data, "\n"))); if ($i === false) { $data1 = $data; $data = ''; } else { $data = substr($data, $i + 1); } if (strpos($data1, 'WORDS=') !== false) { $words = "words=" . urlencode(substr($data1, 6)); } if (strpos($data1, 'THUMB=') !== false) { $thumb = trim(substr($data1, 6)); } if (strpos($data1, 'FIELDS=') !== false) { $fields = "&searchfields=" . trim(substr($data1, 7)); } } if (!empty($words)) { if (empty($fields)) { $fields = '&searchfields=4'; } } $sql = "UPDATE " . prefix('albums') . "SET `search_params`=\"{$words}.{$fields}\", `thumb`=\"{$thumb}\", `mtime`=\"{$mtime}\" WHERE `id`=\"" . $album['id'] . "\""; query($sql); } } /* Delete all image entries that don't belong to an album at all. */ $albumids = query_full_array("SELECT `id` FROM " . prefix('albums')); /* all the album IDs */ $idsofalbums = array(); foreach ($albumids as $row) { $idsofalbums[] = $row['id']; } $imageAlbums = query_full_array("SELECT DISTINCT `albumid` FROM " . prefix('images')); /* albumids of all the images */ $albumidsofimages = array(); foreach ($imageAlbums as $row) { $albumidsofimages[] = $row['albumid']; } $orphans = array_diff($albumidsofimages, $idsofalbums); /* albumids of images with no album */ if (count($orphans) > 0) { /* delete dead images from the DB */ $firstrow = array_pop($orphans); $sql = "DELETE FROM " . prefix('images') . " WHERE `albumid`='" . $firstrow . "'"; foreach ($orphans as $id) { $sql .= " OR `albumid`='" . $id . "'"; } query($sql); // Then go into existing albums recursively to clean them... very invasive. foreach ($this->getAlbums(0) as $folder) { $album = new Album($this, $folder); if (!$album->isDynamic()) { if (is_null($album->getDateTime())) { // see if we can get one from an image $image = $album->getImage(0); if (is_object($image)) { $album->setDateTime($image->getDateTime()); } } $album->garbageCollect(true); $album->preLoad(); } } } } /* Look for image records where the file no longer exists. While at it, check for images with IPTC data to update the DB */ $start = array_sum(explode(" ", microtime())); // protect against too much processing. if (!empty($restart)) { $restartwhere = ' WHERE `id`>' . $restart; } else { $restartwhere = ''; } $sql = 'SELECT `id`, `albumid`, `filename`, `desc`, `title`, `date`, `mtime` FROM ' . prefix('images') . $restartwhere . ' ORDER BY `id`'; $images = query_full_array($sql); foreach ($images as $image) { $sql = 'SELECT `folder` FROM ' . prefix('albums') . ' WHERE `id`="' . $image['albumid'] . '";'; $row = query_single_row($sql); $imageName = UTF8ToFilesystem(getAlbumFolder() . $row['folder'] . '/' . $image['filename']); if (file_exists($imageName)) { if ($image['mtime'] != filemtime($imageName)) { // file has changed since we last saw it /* check metadata */ $metadata = getImageMetadata($imageName); $set = ''; /* title */ $defaultTitle = substr($image['filename'], 0, strrpos($image['filename'], '.')); if (empty($defaultTitle)) { $defaultTitle = $image['filename']; } if ($defaultTitle == $image['title']) { /* default title */ if (isset($metadata['title'])) { $set = ',`title`="' . mysql_real_escape_string($metadata['title']) . '"'; } } /* description */ if (!isset($row['desc'])) { if (isset($metadata['desc'])) { $set .= ', `desc`="' . mysql_real_escape_string($metadata['desc']) . '"'; } } /* tags */ if (isset($metadata['tags'])) { $tags = $metadata['tags']; storeTags($tags, $image['id'], 'images'); } /* location, city, state, and country */ if (isset($metadata['location'])) { $set .= ', `location`="' . mysql_real_escape_string($metadata['location']) . '"'; } if (isset($metadata['city'])) { $set .= ', `city`="' . mysql_real_escape_string($metadata['city']) . '"'; } if (isset($metadata['state'])) { $set .= ', `state`="' . mysql_real_escape_string($metadata['state']) . '"'; } if (isset($metadata['country'])) { $set .= ', `country`="' . mysql_real_escape_string($metadata['country']) . '"'; } /* credit & copyright */ if (isset($metadata['credit'])) { $set .= ', `credit`="' . escape($metadata['credit']) . '"'; } if (isset($metadata['copyright'])) { $set .= ', `copyright`="' . escape($metadata['copyright']) . '"'; } /* date (for sorting) */ $newDate = strftime('%Y-%m-%d %T', filemtime($imageName)); if (isset($metadata['date'])) { $dt = dateTimeConvert($metadata['date']); if ($dt !== false) { // flaw in exif/iptc data? $newDate = $dt; } } $set .= ', `date`="' . $newDate . '"'; /* update DB is necessary */ $sql = "UPDATE " . prefix('images') . " SET `EXIFValid`=0,`mtime`=" . filemtime($imageName) . $set . " WHERE `id`='" . $image['id'] . "'"; query($sql); } } else { $sql = 'DELETE FROM ' . prefix('images') . ' WHERE `id`="' . $image['id'] . '";'; $result = query($sql); $sql = 'DELETE FROM ' . prefix('comments') . ' WHERE `type` IN (' . zp_image_types('"') . ') AND `ownerid` ="' . $image['id'] . '";'; $result = query($sql); } if (array_sum(explode(" ", microtime())) - $start >= 10) { return $image['id']; // avoide excessive processing } } /* clean the comments table */ /* do the images */ $imageids = query_full_array('SELECT `id` FROM ' . prefix('images')); /* all the image IDs */ $idsofimages = array(); foreach ($imageids as $row) { $idsofimages[] = $row['id']; } $commentImages = query_full_array("SELECT DISTINCT `ownerid` FROM " . prefix('comments') . 'WHERE `type` IN (' . zp_image_types('"') . ')'); /* imageids of all the comments */ $imageidsofcomments = array(); foreach ($commentImages as $row) { $imageidsofcomments[] = $row['ownerid']; } $orphans = array_diff($imageidsofcomments, $idsofimages); /* image ids of comments with no image */ if (count($orphans) > 0) { /* delete dead comments from the DB */ $firstrow = array_pop($orphans); $sql = "DELETE FROM " . prefix('comments') . " WHERE `type` IN (" . zp_image_types("'") . ") AND `ownerid`='" . $firstrow . "'"; foreach ($orphans as $id) { $sql .= " OR `ownerid`='" . $id . "'"; } query($sql); } /* do the same for album comments */ $albumids = query_full_array('SELECT `id` FROM ' . prefix('albums')); /* all the album IDs */ $idsofalbums = array(); foreach ($albumids as $row) { $idsofalbums[] = $row['id']; } $commentAlbums = query_full_array("SELECT DISTINCT `ownerid` FROM " . prefix('comments') . 'WHERE `type`="albums"'); /* album ids of all the comments */ $albumidsofcomments = array(); foreach ($commentAlbums as $row) { $albumidsofcomments[] = $row['ownerid']; } $orphans = array_diff($albumidsofcomments, $idsofalbums); /* album ids of comments with no album */ if (count($orphans) > 0) { /* delete dead comments from the DB */ $firstrow = array_pop($orphans); $sql = "DELETE FROM " . prefix('comments') . "WHERE `type`='albums' AND `ownerid`='" . $firstrow . "'"; foreach ($orphans as $id) { $sql .= " OR `ownerid`='" . $id . "'"; } query($sql); } /* clean the tags table */ /* do the images */ $tagImages = query_full_array("SELECT DISTINCT `objectid` FROM " . prefix('obj_to_tag') . 'WHERE `type` IN (' . zp_image_types('"') . ')'); /* imageids of all the comments */ $imageidsoftags = array(); foreach ($tagImages as $row) { $imageidsoftags[] = $row['objectid']; } $orphans = array_diff($imageidsoftags, $idsofimages); /* image ids of comments with no image */ if (count($orphans) > 0) { /* delete dead tags from the DB */ $firstrow = array_pop($orphans); $sql = "DELETE FROM " . prefix('obj_to_tag') . " WHERE `type` IN (" . zp_image_types('"') . ") AND (`objectid`='" . $firstrow . "'"; foreach ($orphans as $id) { $sql .= " OR `objectid`='" . $id . "'"; } $sql .= ')'; query($sql); } /* do the same for album tags */ $tagAlbums = query_full_array("SELECT DISTINCT `objectid` FROM " . prefix('obj_to_tag') . 'WHERE `type`="albums"'); /* album ids of all the comments */ $albumidsoftags = array(); foreach ($tagAlbums as $row) { $albumidsoftags[] = $row['objectid']; } $orphans = array_diff($albumidsoftags, $idsofalbums); /* album ids of comments with no album */ if (count($orphans) > 0) { /* delete dead tags from the DB */ $firstrow = array_pop($orphans); $sql = "DELETE FROM " . prefix('obj_to_tag') . "WHERE `type`='albums' AND `objectid`='" . $firstrow . "'"; foreach ($orphans as $id) { $sql .= " OR `objectid`='" . $id . "'"; } query($sql); } } return false; }
/** * adds (sub)albums to menu base with their gallery sorting order intact * * @param string $menuset chosen menu set * @param object $gallery a gallery object * @param int $id table id of the parent. * @param string $link folder name of the album * @param string $sort xxx-xxx-xxx style sort order for album */ function addSubalbumMenus($menuset, $gallery, $id, $link, $sort) { $album = new Album($gallery, $link); $show = $album->get('show'); $title = $album->getTitle(); $sql = "INSERT INTO " . prefix('menu') . " (`link`,`type`,`title`,`show`,`menuset`,`sort_order`, `parentid`) " . 'VALUES (' . db_quote($link) . ', "album",' . db_quote($album->name) . ', ' . $show . ',' . db_quote($menuset) . ',' . db_quote($sort) . ',' . $id . ')'; $result = query($sql, false); if ($result) { $id = db_insert_id(); } else { $result = query_single_row('SELECT `id` FROM' . prefix('menu') . ' WHERE `type`="album" AND `link`=' . db_quote($link)); $id = $result['id']; } if (!$album->isDynamic()) { $albums = $album->getAlbums(); foreach ($albums as $key => $link) { addSubalbumMenus($menuset, $gallery, $id, $link, $sort . '-' . sprintf('%03u', $key)); } } }
/** * * Checks for bad parentIDs from old move/copy bug * @param unknown_type $albumname * @param unknown_type $id */ function checkAlbumParentid($albumname, $id) { global $_zp_gallery; $album = new Album($_zp_gallery, $albumname); $oldid = $album->get('parentid'); if ($oldid !== $id) { $album->set('parentid', $id); $album->save(); if (is_null($oldid)) { $oldid = '<em>NULL</em>'; } if (is_null($id)) { $id = '<em>NULL</em>'; } printf('Fixed album <strong>%1$s</strong>: parentid was %2$s should have been %3$s<br />', $albumname, $oldid, $id); } $id = $album->id; if (!$album->isDynamic()) { $albums = $album->getAlbums(); foreach ($albums as $albumname) { checkAlbumParentid($albumname, $id); } } }
?> <div id="content"> <?php /** EDIT ****************************************************************************/ /************************************************************************************/ if (isset($_GET['album']) && !isset($_GET['massedit'])) { /** SINGLE ALBUM ********************************************************************/ define('IMAGES_PER_PAGE', 10); // one time generation of this list. $mcr_albumlist = array(); genAlbumUploadList($mcr_albumlist); $oldalbumimagesort = getOption('albumimagesort'); $direction = getOption('albumimagedirection'); $folder = sanitize_path($_GET['album']); $album = new Album($gallery, $folder); if ($album->isDynamic()) { $subalbums = array(); $allimages = array(); } else { $subalbums = $album->getSubAlbums(); $allimages = $album->getImages(0, 0, $oldalbumimagesort, $direction); } $allimagecount = count($allimages); if (isset($_GET['tab']) && $_GET['tab'] == 'imageinfo' && isset($_GET['image'])) { // directed to an image $target_image = urldecode($_GET['image']); $imageno = array_search($target_image, $allimages); if ($imageno !== false) { $pagenum = ceil(($imageno + 1) / IMAGES_PER_PAGE); } } else {
/** * zp_load_album - loads the album given by the folder name $folder into the * global context, and sets the context appropriately. * @param $folder the folder name of the album to load. Ex: 'testalbum', 'test/subalbum', etc. * @param $force_cache whether to force the use of the global object cache. * @return the loaded album object on success, or (===false) on failure. */ function zp_load_album($folder, $force_nocache = false) { global $_zp_current_album, $_zp_gallery, $_zp_dynamic_album; $_zp_current_album = new Album($_zp_gallery, $folder, !$force_nocache); if (!$_zp_current_album->exists) { return false; } if ($_zp_current_album->isDynamic()) { $_zp_dynamic_album = $_zp_current_album; } else { $_zp_dynamic_album = null; } set_context(ZP_ALBUM | ZP_INDEX); return $_zp_current_album; }
/** * Prints the sortable nested albums list * returns true if nesting levels exceede the database container * * @param array $pages The array containing all pages * @param bool $show_thumb set false to use thumb standin image. * * @return bool */ function printNestedAlbumsList($albums, $show_thumb) { global $gallery; $indent = 1; $open = array(1 => 0); $rslt = false; foreach ($albums as $album) { $order = $album['sort_order']; $level = max(1, count($order)); if ($toodeep = $level > 1 && $order[$level - 1] === '') { $rslt = true; } if ($level > $indent) { echo "\n" . str_pad("\t", $indent, "\t") . "<ul class=\"page-list\">\n"; $indent++; $open[$indent] = 0; } else { if ($level < $indent) { while ($indent > $level) { $open[$indent]--; $indent--; echo "</li>\n" . str_pad("\t", $indent, "\t") . "</ul>\n"; } } else { // indent == level if ($open[$indent]) { echo str_pad("\t", $indent, "\t") . "</li>\n"; $open[$indent]--; } else { echo "\n"; } } } if ($open[$indent]) { echo str_pad("\t", $indent, "\t") . "</li>\n"; $open[$indent]--; } $albumobj = new Album($gallery, $album['name']); if ($albumobj->isDynamic()) { $nonest = ' class="no-nest"'; } else { $nonest = ''; } echo str_pad("\t", $indent - 1, "\t") . "<li id=\"id_" . $albumobj->get('id') . "\"{$nonest} >"; printAlbumEditRow($albumobj, $show_thumb); $open[$indent]++; } while ($indent > 1) { echo "</li>\n"; $open[$indent]--; $indent--; echo str_pad("\t", $indent, "\t") . "</ul>"; } if ($open[$indent]) { echo "</li>\n"; } else { echo "\n"; } return $rslt; }
/** * Returns a randomly selected image from the album or its subalbums. (May be NULL if none exists) * * @param mixed $rootAlbum optional album object/folder from which to get the image. * @param bool $daily set to true to change picture only once a day. * @param bool $showunpublished set true to consider all images * * @return object */ function getRandomImagesAlbum($rootAlbum = NULL, $daily = false, $showunpublished = false) { global $_zp_current_album, $_zp_gallery, $_zp_current_search; if (empty($rootAlbum)) { $album = $_zp_current_album; } else { if (is_object($rootAlbum)) { $album = $rootAlbum; } else { $album = new Album($_zp_gallery, $rootAlbum); } } if ($daily && ($potd = getOption('picture_of_the_day:' . $album->name))) { $potd = unserialize($potd); if (date('Y-m-d', $potd['day']) == date('Y-m-d')) { $rndalbum = new Album($_zp_gallery, $potd['folder']); $image = newImage($rndalbum, $potd['filename']); if ($image->exists) { return $image; } } } $image = NULL; if ($album->isDynamic()) { $images = $album->getImages(0); shuffle($images); while (count($images) > 0) { $result = array_pop($images); if (is_valid_image($result['filename'])) { $image = newImage(new Album(new Gallery(), $result['folder']), $result['filename']); } } } else { $albumfolder = $album->getFolder(); if ($album->isMyItem(LIST_RIGHTS) || $showunpublished) { $imageWhere = ''; $albumNotWhere = ''; $albumInWhere = ''; } else { $imageWhere = " AND " . prefix('images') . ".show=1"; $albumNotWhere = getProtectedAlbumsWhere(); $albumInWhere = prefix('albums') . ".show=1"; } $query = "SELECT id FROM " . prefix('albums') . " WHERE "; if ($albumInWhere) { $query .= $albumInWhere . ' AND '; } $query .= "folder LIKE " . db_quote($albumfolder . '%'); $result = query_full_array($query); if (is_array($result) && count($result) > 0) { $albumInWhere = prefix('albums') . ".id in ("; foreach ($result as $row) { $albumInWhere = $albumInWhere . $row['id'] . ", "; } $albumInWhere = ' AND ' . substr($albumInWhere, 0, -2) . ')'; $c = 0; while (is_null($image) && $c < 10) { $result = query_single_row('SELECT COUNT(*) AS row_count ' . ' FROM ' . prefix('images') . ', ' . prefix('albums') . ' WHERE ' . prefix('albums') . '.folder!="" AND ' . prefix('images') . '.albumid = ' . prefix('albums') . '.id ' . $albumInWhere . $albumNotWhere . $imageWhere); $rand_row = rand(0, $result['row_count'] - 1); $result = query_single_row('SELECT ' . prefix('images') . '.filename, ' . prefix('albums') . '.folder ' . ' FROM ' . prefix('images') . ', ' . prefix('albums') . ' WHERE ' . prefix('images') . '.albumid = ' . prefix('albums') . '.id ' . $albumInWhere . $albumNotWhere . $imageWhere . ' LIMIT ' . $rand_row . ', 1'); $imageName = $result['filename']; if (is_valid_image($imageName)) { $image = newImage(new Album(new Gallery(), $result['folder']), $imageName); } $c++; } } } if ($daily && is_object($image)) { $potd = array('day' => time(), 'folder' => $result['folder'], 'filename' => $result['filename']); setThemeOption('picture_of_the_day:' . $album->name, serialize($potd)); } return $image; }
/** For every album in the gallery, look for its file. Delete from the database * if the file does not exist. Do the same for images. Clean up comments that have * been left orphaned. * * Returns true if the operation was interrupted because it was taking too long * * @param bool $cascade garbage collect every image and album in the gallery. * @param bool $complete garbage collect every image and album in the *database* - completely cleans the database. * @param int $restart Image ID to restart scan from * @return bool */ function garbageCollect($cascade = true, $complete = false, $restart = '') { if (empty($restart)) { setOption('last_garbage_collect', time()); /* clean the comments table */ $this->commentClean('images'); $this->commentClean('albums'); $this->commentClean('news'); $this->commentClean('pages'); // clean up obj_to_tag $dead = array(); $result = query_full_array("SELECT * FROM " . prefix('obj_to_tag')); if (is_array($result)) { foreach ($result as $row) { $dbtag = query_single_row("SELECT * FROM " . prefix('tags') . " WHERE `id`='" . $row['tagid'] . "'"); if (!$dbtag) { $dead['id'] = $row['id']; } switch ($row['type']) { case 'album': $tbl = 'albums'; break; default: $tbl = $row['type']; break; } $dbtag = query_single_row("SELECT * FROM " . prefix($tbl) . " WHERE `id`='" . $row['objectid'] . "'"); if (!$dbtag) { $dead['id'] = $row['id']; } } } if (!empty($dead)) { query('DELETE FROM ' . prefix('obj_to_tag') . ' WHERE `id`=' . implode(' OR `id`=', $dead)); } // clean up admin_to_object $dead = array(); $result = query_full_array("SELECT * FROM " . prefix('admin_to_object')); if (is_array($result)) { foreach ($result as $row) { $dbtag = query_single_row("SELECT * FROM " . prefix('administrators') . " WHERE `id`='" . $row['adminid'] . "'"); if (!$dbtag) { $dead['id'] = $row['id']; } switch ($row['type']) { case 'album': $tbl = 'albums'; break; default: $tbl = $row['type']; break; } $dbtag = query_single_row("SELECT * FROM " . prefix($tbl) . " WHERE `id`='" . $row['objectid'] . "'"); if (!$dbtag) { $dead['id'] = $row['id']; } } } if (!empty($dead)) { query('DELETE FROM ' . prefix('admin_to_object') . ' WHERE `id`=' . implode(' OR `id`=', $dead)); } // clean up news2cat $dead = array(); $result = query_full_array("SELECT * FROM " . prefix('news2cat')); if (is_array($result)) { foreach ($result as $row) { $dbtag = query_single_row("SELECT * FROM " . prefix('news') . " WHERE `id`='" . $row['news_id'] . "'"); if (!$dbtag) { $dead['id'] = $row['id']; } $dbtag = query_single_row("SELECT * FROM " . prefix('news_categories') . " WHERE `id`='" . $row['cat_id'] . "'"); if (!$dbtag) { $dead['id'] = $row['id']; } } } if (!empty($dead)) { query('DELETE FROM ' . prefix('news2cat') . ' WHERE `id`=' . implode(' OR `id`=', $dead)); } // Check for the existence of top-level albums (subalbums handled recursively). $sql = "SELECT * FROM " . prefix('albums'); $result = query($sql); $dead = array(); $live = array(''); // purge the root album if it exists $deadalbumthemes = array(); // Load the albums from disk while ($row = db_fetch_assoc($result)) { $valid = file_exists($albumpath = ALBUM_FOLDER_SERVERPATH . internalToFilesystem($row['folder'])) && (hasDynamicAlbumSuffix($albumpath) || is_dir($albumpath) && strpos($albumpath, '/./') === false && strpos($albumpath, '/../') === false); if (!$valid || in_array($row['folder'], $live)) { $dead[] = $row['id']; if ($row['album_theme'] !== '') { // orphaned album theme options table $deadalbumthemes[$row['id']] = $row['folder']; } } else { $live[] = $row['folder']; } } if (count($dead) > 0) { /* delete the dead albums from the DB */ $first = array_pop($dead); $sql1 = "DELETE FROM " . prefix('albums') . " WHERE `id`='{$first}'"; $sql2 = "DELETE FROM " . prefix('images') . " WHERE `albumid`='{$first}'"; $sql3 = "DELETE FROM " . prefix('comments') . " WHERE `type`='albums' AND `ownerid`='{$first}'"; $sql4 = "DELETE FROM " . prefix('obj_to_tag') . " WHERE `type`='albums' AND `objectid`='{$first}'"; foreach ($dead as $albumid) { $sql1 .= " OR `id` = '{$albumid}'"; $sql2 .= " OR `albumid` = '{$albumid}'"; $sql3 .= " OR `ownerid` = '{$albumid}'"; $sql4 .= " OR `objectid` = '{$albumid}'"; } $n = query($sql1); if (!$complete && $n && $cascade) { query($sql2); query($sql3); query($sql4); } } if (count($deadalbumthemes) > 0) { // delete the album theme options tables for dead albums foreach ($deadalbumthemes as $id => $deadtable) { $sql = 'DELETE FROM ' . prefix('options') . ' WHERE `ownerid`=' . $id; query($sql, false); } } } if ($complete) { if (empty($restart)) { /* refresh 'metadata' albums */ $albumids = query_full_array("SELECT `id`, `mtime`, `folder`, `dynamic` FROM " . prefix('albums')); foreach ($albumids as $analbum) { if (($mtime = filemtime(ALBUM_FOLDER_SERVERPATH . internalToFilesystem($analbum['folder']))) > $analbum['mtime']) { // refresh $album = new Album($this, $analbum['folder']); $album->set('mtime', $mtime); if ($album->isDynamic()) { $data = file_get_contents($album->localpath); while (!empty($data)) { $data1 = trim(substr($data, 0, $i = strpos($data, "\n"))); if ($i === false) { $data1 = $data; $data = ''; } else { $data = substr($data, $i + 1); } if (strpos($data1, 'WORDS=') !== false) { $words = "words=" . urlencode(substr($data1, 6)); } if (strpos($data1, 'THUMB=') !== false) { $thumb = trim(substr($data1, 6)); } if (strpos($data1, 'FIELDS=') !== false) { $fields = "&searchfields=" . trim(substr($data1, 7)); } } if (!empty($words)) { if (empty($fields)) { $fields = '&searchfields=tags'; } } $album->set('search_params', $words . $fields); $album->set('thumb', $thumb); } $album->save(); zp_apply_filter('album_refresh', $album); } } /* Delete all image entries that don't belong to an album at all. */ $albumids = query_full_array("SELECT `id` FROM " . prefix('albums')); /* all the album IDs */ $idsofalbums = array(); foreach ($albumids as $row) { $idsofalbums[] = $row['id']; } $imageAlbums = query_full_array("SELECT DISTINCT `albumid` FROM " . prefix('images')); /* albumids of all the images */ $albumidsofimages = array(); foreach ($imageAlbums as $row) { $albumidsofimages[] = $row['albumid']; } $orphans = array_diff($albumidsofimages, $idsofalbums); /* albumids of images with no album */ if (count($orphans) > 0) { /* delete dead images from the DB */ $firstrow = array_pop($orphans); $sql = "DELETE FROM " . prefix('images') . " WHERE `albumid`='" . $firstrow . "'"; foreach ($orphans as $id) { $sql .= " OR `albumid`='" . $id . "'"; } query($sql); // Then go into existing albums recursively to clean them... very invasive. foreach ($this->getAlbums(0) as $folder) { $album = new Album($this, $folder); if (!$album->isDynamic()) { if (is_null($album->getDateTime())) { // see if we can get one from an image $images = $album->getImages(0, 0, 'date', 'DESC'); if (count($images) > 0) { $image = newImage($album, array_shift($images)); $album->setDateTime($image->getDateTime()); } } $album->garbageCollect(true); $album->preLoad(); } $album->save(); zp_apply_filter('album_refresh', $album); } } } /* Look for image records where the file no longer exists. While at it, check for images with IPTC data to update the DB */ $start = array_sum(explode(" ", microtime())); // protect against too much processing. if (!empty($restart)) { $restartwhere = ' WHERE `id`>' . $restart . ' AND `mtime`=0'; } else { $restartwhere = ' WHERE `mtime`=0'; } define('RECORD_LIMIT', 5); $sql = 'SELECT * FROM ' . prefix('images') . $restartwhere . ' ORDER BY `id` LIMIT ' . (RECORD_LIMIT + 2); $images = query_full_array($sql); if (count($images) > 0) { $c = 0; foreach ($images as $image) { $sql = 'SELECT `folder` FROM ' . prefix('albums') . ' WHERE `id`="' . $image['albumid'] . '";'; $row = query_single_row($sql); $imageName = internalToFilesystem(ALBUM_FOLDER_SERVERPATH . $row['folder'] . '/' . $image['filename']); if (file_exists($imageName)) { $mtime = filemtime($imageName); if ($image['mtime'] != $mtime) { // file has changed since we last saw it $imageobj = newImage(new Album($this, $row['folder']), $image['filename']); $imageobj->set('mtime', $mtime); $imageobj->updateMetaData(); // prime the EXIF/IPTC fields $imageobj->updateDimensions(); // update the width/height & account for rotation $imageobj->save(); zp_apply_filter('image_refresh', $imageobj); } } else { $sql = 'DELETE FROM ' . prefix('images') . ' WHERE `id`="' . $image['id'] . '";'; $result = query($sql); $sql = 'DELETE FROM ' . prefix('comments') . ' WHERE `type` IN (' . zp_image_types('"') . ') AND `ownerid` ="' . $image['id'] . '";'; $result = query($sql); } if (++$c >= RECORD_LIMIT) { return $image['id']; // avoide excessive processing } } } } return false; }
/** * Returns a randomly selected image from the album or its subalbums. (May be NULL if none exists) * * @param string $rootAlbum optional album folder from which to get the image. * * @return object */ function getRandomImagesAlbum($rootAlbum = null) { global $_zp_current_album, $_zp_gallery, $_zp_current_search; if (empty($rootAlbum)) { $album = $_zp_current_album; } else { $album = new Album($_zp_gallery, $rootAlbum); } if ($album->isDynamic()) { $search = $album->getSearchEngine(); $images = $search->getImages(0); $image = NULL; shuffle($images); while (count($images) > 0) { $randomImage = array_pop($images); if (is_valid_image($randomImage['filename'])) { $image = newImage(new Album(new Gallery(), $randomImage['folder']), $randomImage['filename']); return $image; } } } else { if (zp_loggedin()) { $imageWhere = ''; $albumNotWhere = ''; } else { $imageWhere = " AND " . prefix('images') . ".show=1"; $albumNotWhere = getProtectedAlbumsWhere(); } $albumInWhere = ''; $albumfolder = $album->getFolder(); $query = "SELECT id FROM " . prefix('albums') . " WHERE " . prefix('albums') . ".show = 1 AND folder LIKE '" . mysql_real_escape_string($albumfolder) . "%'"; $result = query_full_array($query); $albumInWhere = prefix('albums') . ".id in ("; foreach ($result as $row) { $albumInWhere = $albumInWhere . $row['id'] . ", "; } $albumInWhere = ' AND ' . substr($albumInWhere, 0, -2) . ')'; $c = 0; while ($c < 10) { $result = query_single_row('SELECT COUNT(*) AS row_count ' . ' FROM ' . prefix('images') . ', ' . prefix('albums') . ' WHERE ' . prefix('albums') . '.folder!="" AND ' . prefix('images') . '.albumid = ' . prefix('albums') . '.id ' . $albumInWhere . $albumNotWhere . $imageWhere); $rand_row = rand(1, $result['row_count']); $result = query_single_row('SELECT ' . prefix('images') . '.filename, ' . prefix('albums') . '.folder ' . ' FROM ' . prefix('images') . ', ' . prefix('albums') . ' WHERE ' . prefix('images') . '.albumid = ' . prefix('albums') . '.id ' . $albumInWhere . $albumNotWhere . $imageWhere . ' LIMIT ' . $rand_row . ', 1'); $imageName = $result['filename']; if (is_valid_image($imageName)) { $image = newImage(new Album(new Gallery(), $result['folder']), $imageName); return $image; } $c++; } } return null; }
/** * emits the html for editing album information * called in edit album and mass edit *@param string param1 the index of the entry in mass edit or '0' if single album *@param object param2 the album object *@since 1.1.3 */ function printAlbumEditForm($index, $album) { // Note: This is some pretty confusing spaghetti code with all the echo statements. // Please refactor it so the HTML is readable and easily editable. // FYI: It's perfectly acceptable to drop out of php-parsing mode in a function. // See the move/copy/rename block for an example. global $sortby, $gallery, $_zp_loggedin, $mcr_albumlist, $albumdbfields, $imagedbfields; $tagsort = getTagOrder(); if ($index == 0) { if (isset($saved)) { $album->setSubalbumSortType('manual'); } $suffix = $prefix = ''; } else { $prefix = "{$index}-"; $suffix = "_{$index}"; echo "<p><em><strong>" . $album->name . "</strong></em></p>"; } echo "\n<input type=\"hidden\" name=\"" . $prefix . "folder\" value=\"" . $album->name . "\" />"; echo "\n" . '<input type="hidden" name="tagsort" value=' . $tagsort . ' />'; echo "\n<table>"; echo "\n<td width = \"60%\">\n<table>\n<tr>"; echo "\n<tr>"; echo "<td align=\"right\" valign=\"top\" width=\"150\">" . gettext("Album Title") . ": </td>"; echo '<td>'; print_language_string_list($album->get('title'), $prefix . "albumtitle", false); echo "</td></tr>\n"; echo '<tr><td></td>'; $hc = $album->get('hitcounter'); if (empty($hc)) { $hc = '0'; } echo "<td>"; echo sprintf(gettext("Hit counter: %u"), $hc) . " <input type=\"checkbox\" name=\"reset_hitcounter\"> Reset"; $tv = $album->get('total_value'); $tc = $album->get('total_votes'); echo ' '; if ($tc > 0) { $hc = $tv / $tc; printf(gettext('Rating: <strong>%u</strong>'), $hc); echo "<label for=\"" . $prefix . "reset_rating\"><input type=\"checkbox\" id=\"" . $prefix . "reset_rating\" name=\"" . $prefix . "reset_rating\" value=1> " . gettext("Reset") . "</label> "; } else { echo gettext("Rating: Unrated"); } echo "</td>"; echo '</tr>'; echo "\n<tr><td align=\"right\" valign=\"top\">" . gettext("Album Description:") . " </td> <td>"; print_language_string_list($album->get('desc'), $prefix . "albumdesc", true, NULL, 'texteditor'); echo "</td></tr>"; echo "\n<tr><td align=\"right\" value=\"top\">" . gettext("Album guest user:"******"\n<td><input type='text' size='48' name='" . $prefix . "albumuser' value='" . $album->getUser() . "' /></td></tr>"; echo "\n<tr>"; echo "\n<td align=\"right\">" . gettext("Album password:"******" <br/>" . gettext("repeat:") . " </td>"; echo "\n<td>"; $x = $album->getPassword(); if (!empty($x)) { $x = ' '; } echo "\n<input type=\"password\" size=\"48\" name=\"" . $prefix . "albumpass\""; echo "\nvalue=\"" . $x . '" /><br/>'; echo "\n<input type=\"password\" size=\"48\" name=\"" . $prefix . "albumpass_2\""; echo "\nvalue=\"" . $x . '" />'; echo "\n</td>"; echo "\n</tr>"; echo "\n<tr><td align=\"right\" valign=\"top\">" . gettext("Password hint:") . " </td> <td>"; print_language_string_list($album->get('password_hint'), $prefix . "albumpass_hint", false); echo "</td></tr>"; $d = $album->getDateTime(); if ($d == "0000-00-00 00:00:00") { $d = ""; } echo "\n<tr><td align=\"right\" valign=\"top\">" . gettext("Date:") . " </td> <td width = \"400\"><input type=\"text\" size='48' name=\"" . $prefix . "albumdate\" value=\"" . $d . '" /></td></tr>'; echo "\n<tr><td align=\"right\" valign=\"top\">" . gettext("Location:") . " </td> <td>"; print_language_string_list($album->get('place'), $prefix . "albumplace", false); echo "</td></tr>"; echo "\n<tr><td align=\"right\" valign=\"top\">" . gettext("Custom data:") . "</td><td>"; print_language_string_list($album->get('custom_data'), $prefix . "album_custom_data", true); echo "</td></tr>"; $sort = $sortby; if (!$album->isDynamic()) { $sort[gettext('Manual')] = 'manual'; } $sort[gettext('Custom')] = 'custom'; echo "\n<tr>"; echo "\n<td align=\"right\" valign=\"top\">" . gettext("Sort subalbums by:") . " </td>"; echo "\n<td>"; // script to test for what is selected $javaprefix = 'js_' . preg_replace("/[^a-z0-9_]/", "", strtolower($prefix)); ?> <table> <tr> <td> <select id="sortselect" name="<?php echo $prefix; ?> subalbumsortby" onchange="update_direction(this,'<?php echo $javaprefix; ?> album_direction_div','<?php echo $javaprefix; ?> album_custom_div')"> <?php if (is_null($album->getParent())) { $globalsort = gettext("gallery album sort order"); } else { $globalsort = gettext("parent album subalbum sort order"); } echo "\n<option value =''>{$globalsort}</option>"; $cvt = $type = strtolower($album->get('subalbum_sort_type')); generateListFromArray(array($type), $sort, false, true); ?> </select> </td> <td> <?php if ($type == 'manual' || $type == '') { $dsp = 'none'; } else { $dsp = 'block'; } echo "\n<span id=\"" . $javaprefix . "album_direction_div\" style=\"display:" . $dsp . "\">"; echo " " . gettext("Descending") . " <input type=\"checkbox\" name=\"" . $prefix . "album_sortdirection\" value=\"1\""; if ($album->getSortDirection('album')) { echo "CHECKED"; } echo ">"; echo '</span>'; $flip = array_flip($sort); if (empty($type) || isset($flip[$type])) { $dsp = 'none'; } else { $dsp = 'block'; } ?> </td> </tr> <script type="text/javascript"> $(function () { $('#<?php echo $javaprefix; ?> customalbumsort').tagSuggest({ tags: [<?php echo $albumdbfields; ?> ] }); }); </script> <tr> <td colspan="2"> <span id="<?php echo $javaprefix; ?> album_custom_div" class="customText" style="display:<?php echo $dsp; ?> "> <?php echo gettext('custom fields:'); ?> <input id="<?php echo $javaprefix; ?> customalbumsort" name="<?php echo $prefix; ?> customalbumsort" type="text" value="<?php echo $cvt; ?> "></input> </span> </td> </tr> </table> <?php echo "\n</td>"; echo "\n</tr>"; echo "\n<tr>"; echo "\n<td align=\"right\" valign=\"top\">" . gettext("Sort images by:") . " </td>"; echo "\n<td>"; // script to test for what is selected $javaprefix = 'js_' . preg_replace("/[^a-z0-9_]/", "", strtolower($prefix)); ?> <table> <tr> <td> <select id="sortselect" name="<?php echo $prefix; ?> sortby" onchange="update_direction(this,'<?php echo $javaprefix; ?> image_direction_div','<?php echo $javaprefix; ?> image_custom_div')"> <?php if (is_null($album->getParent())) { $globalsort = gettext("gallery default image sort order"); } else { $globalsort = gettext("parent album image sort order"); } echo "\n<option value =''>{$globalsort}</option>"; $cvt = $type = strtolower($album->get('sort_type')); generateListFromArray(array($type), $sort, false, true); ?> </select> </td> <td> <?php if ($type == 'manual' || $type == '') { $dsp = 'none'; } else { $dsp = 'block'; } echo "\n<span id=\"" . $javaprefix . "image_direction_div\" style=\"display:" . $dsp . "\">"; echo " " . gettext("Descending") . " <input type=\"checkbox\" name=\"" . $prefix . "image_sortdirection\" value=\"1\""; if ($album->getSortDirection('image')) { echo "CHECKED"; } echo ">"; echo '</span>'; $flip = array_flip($sort); if (empty($type) || isset($flip[$type])) { $dsp = 'none'; } else { $dsp = 'block'; } ?> </td> </tr> <script type="text/javascript"> $(function () { $('#<?php echo $javaprefix; ?> customimagesort').tagSuggest({ tags: [<?php echo $imagedbfields; ?> ] }); }); </script> <tr> <td colspan="2"> <span id="<?php echo $javaprefix; ?> image_custom_div" class="customText" style="display:<?php echo $dsp; ?> "> <?php echo gettext('custom fields:'); ?> <input id="<?php echo $javaprefix; ?> customimagesort" name="<?php echo $prefix; ?> customimagesort" type="text" value="<?php echo $cvt; ?> "></input> </span> </td> </tr> </table> <?php echo "\n</td>"; echo "\n</tr>"; echo "\n<tr>"; echo "\n<td align=\"right\" valign=\"top\"></td><td><input type=\"checkbox\" name=\"" . $prefix . "allowcomments\" value=\"1\""; if ($album->getCommentsAllowed()) { echo "CHECKED"; } echo "> " . gettext("Allow Comments") . " "; echo "<input type=\"checkbox\" name=\"" . $prefix . "Published\" value=\"1\""; if ($album->getShow()) { echo "CHECKED"; } echo "> " . gettext("Published") . " "; echo "</td>\n</tr>"; if (is_null($album->getParent())) { echo "\n<tr>"; echo "\n<td align=\"right\" valign=\"top\">" . gettext("Album theme:") . " </td> "; echo "\n<td>"; echo "\n<select id=\"album_theme\" class=\"album_theme\" name=\"" . $prefix . "album_theme\" "; if (!($_zp_loggedin & (ADMIN_RIGHTS | THEMES_RIGHTS))) { echo "DISABLED "; } echo ">"; $themes = $gallery->getThemes(); $oldtheme = $album->getAlbumTheme(); if (empty($oldtheme)) { echo "<option value = \"\" selected=\"SELECTED\" />"; } else { echo "<option value = \"\" />"; } echo "</option>"; foreach ($themes as $theme => $themeinfo) { echo "<option value = \"{$theme}\""; if ($oldtheme == $theme) { echo "selected = \"SELECTED\""; } echo "\t/>"; echo $themeinfo['name']; echo "</option>"; } echo "\n</select>"; echo "\n</td>"; echo "\n</tr>"; } echo "\n</table>\n</td>"; echo "\n<td valign=\"top\">"; $bglevels = array('#fff', '#f8f8f8', '#efefef', '#e8e8e8', '#dfdfdf', '#d8d8d8', '#cfcfcf', '#c8c8c8'); /* **************** Move/Copy/Rename ****************** */ ?> <label for="a-<?php echo $prefix; ?> move" style="padding-right: .5em"> <input type="radio" id="a-<?php echo $prefix; ?> move" name="a-<?php echo $prefix; ?> MoveCopyRename" value="move" onclick="toggleAlbumMoveCopyRename('<?php echo $prefix; ?> ', 'movecopy');"/> <?php echo gettext("Move"); ?> </label> <label for="a-<?php echo $prefix; ?> copy" style="padding-right: .5em"> <input type="radio" id="a-<?php echo $prefix; ?> copy" name="a-<?php echo $prefix; ?> MoveCopyRename" value="copy" onclick="toggleAlbumMoveCopyRename('<?php echo $prefix; ?> ', 'movecopy');"/> <?php echo gettext("Copy"); ?> </label> <label for="a-<?php echo $prefix; ?> rename" style="padding-right: .5em"> <input type="radio" id="a-<?php echo $prefix; ?> rename" name="a-<?php echo $prefix; ?> MoveCopyRename" value="rename" onclick="toggleAlbumMoveCopyRename('<?php echo $prefix; ?> ', 'rename');"/> <?php echo gettext("Rename Folder"); ?> </label> <div id="a-<?php echo $prefix; ?> movecopydiv" style="padding-top: .5em; padding-left: .5em; display: none;"> <?php echo gettext("to"); ?> : <select id="a-<?php echo $prefix; ?> albumselectmenu" name="a-<?php echo $prefix; ?> albumselect" onChange=""> <option value="" selected="selected">/</option> <?php foreach ($mcr_albumlist as $fullfolder => $albumtitle) { $singlefolder = $fullfolder; $saprefix = ""; $salevel = 0; $selected = ""; if ($album->name == $fullfolder) { continue; } // Get rid of the slashes in the subalbum, while also making a subalbum prefix for the menu. while (strstr($singlefolder, '/') !== false) { $singlefolder = substr(strstr($singlefolder, '/'), 1); $saprefix = " " . $saprefix; $salevel++; } echo '<option value="' . $fullfolder . '"' . ($salevel > 0 ? ' style="background-color: ' . $bglevels[$salevel] . ';"' : '') . "{$selected}>" . $saprefix . $singlefolder . "</option>\n"; } ?> </select> <p style="text-align: right;"> <a href="javascript:toggleAlbumMoveCopyRename('<?php echo $prefix; ?> ', '');"><?php echo gettext("Cancel"); ?> </a> </p> </div> <div id="a-<?php echo $prefix; ?> renamediv" style="padding-top: .5em; padding-left: .5em; display: none;"> <?php echo gettext("to"); ?> : <input name="a-<?php echo $prefix; ?> renameto" type="text" size="35" value="<?php echo basename($album->name); ?> "/><br /> <p style="text-align: right; padding: .25em 0px;"> <a href="javascript:toggleAlbumMoveCopyRename('<?php echo $prefix; ?> ', '');"><?php echo gettext("Cancel"); ?> </a> </p> </div> <br/><br /> <?php echo gettext("Tags:"); $tagsort = getTagOrder(); tagSelector($album, 'tags_' . $prefix, false, $tagsort); echo "\n</td>\n</tr>"; echo "\n</table>"; echo "\n<table>"; if ($album->isDynamic()) { echo "\n<tr>"; echo "\n<td> </td>"; echo "\n<td align=\"right\" valign=\"top\" width=\"150\">" . gettext("Dynamic album search:") . "</td>"; echo "\n<td>"; echo "\n<table class=\"noinput\">"; echo "\n<tr><td >" . urldecode($album->getSearchParams()) . "</td></tr>"; echo "\n</table>"; echo "\n</td>"; echo "\n</tr>"; } echo "\n<tr>"; echo "\n<td> </td>"; echo "\n<td align=\"right\" valign=\"top\" width=\"150\">" . gettext("Thumbnail:") . " </td> "; echo "\n<td>"; $showThumb = getOption('thumb_select_images'); if ($showThumb) { echo "\n<script type=\"text/javascript\">updateThumbPreview(document.getElementById('thumbselect'));</script>"; } echo "\n<select id=\"\""; if ($showThumb) { echo " class=\"thumbselect\" onChange=\"updateThumbPreview(this)\""; } echo " name=\"" . $prefix . "thumb\">"; $thumb = $album->get('thumb'); echo "\n<option"; if ($showThumb) { echo " class=\"thumboption\" value=\"\" style=\"background-color:#B1F7B6\""; } if ($thumb === '1') { echo " selected=\"selected\""; } echo ' value="1">' . gettext('most recent'); echo '</option>'; echo "\n<option"; if ($showThumb) { echo " class=\"thumboption\" value=\"\" style=\"background-color:#B1F7B6\""; } if (empty($thumb) && $thumb !== '1') { echo " selected=\"selected\""; } echo ' value="">' . gettext('randomly selected'); echo '</option>'; if ($album->isDynamic()) { $params = $album->getSearchParams(); $search = new SearchEngine(); $search->setSearchParams($params); $images = $search->getImages(0); $thumb = $album->get('thumb'); $imagelist = array(); foreach ($images as $imagerow) { $folder = $imagerow['folder']; $filename = $imagerow['filename']; $imagelist[] = '/' . $folder . '/' . $filename; } if (count($imagelist) == 0) { $subalbums = $search->getAlbums(0); foreach ($subalbums as $folder) { $newalbum = new Album($gallery, $folder); if (!$newalbum->isDynamic()) { $images = $newalbum->getImages(0); foreach ($images as $filename) { $imagelist[] = '/' . $folder . '/' . $filename; } } } } foreach ($imagelist as $imagepath) { $list = explode('/', $imagepath); $filename = $list[count($list) - 1]; unset($list[count($list) - 1]); $folder = implode('/', $list); $albumx = new Album($gallery, $folder); $image = newImage($albumx, $filename); $selected = $imagepath == $thumb; echo "\n<option"; if ($showThumb) { echo " class=\"thumboption\""; echo " style=\"background-image: url(" . $image->getThumb() . "); background-repeat: no-repeat;\""; } echo " value=\"" . $imagepath . "\""; if ($selected) { echo " selected=\"selected\""; } echo ">" . $image->getTitle(); echo " ({$imagepath})"; echo "</option>"; } } else { $images = $album->getImages(); if (count($images) == 0 && count($album->getSubalbums()) > 0) { $imagearray = array(); $albumnames = array(); $strip = strlen($album->name) + 1; $subIDs = getAllSubAlbumIDs($album->name); if (!is_null($subIDs)) { foreach ($subIDs as $ID) { $albumnames[$ID['id']] = $ID['folder']; $query = 'SELECT `id` , `albumid` , `filename` , `title` FROM ' . prefix('images') . ' WHERE `albumid` = "' . $ID['id'] . '"'; $imagearray = array_merge($imagearray, query_full_array($query)); } foreach ($imagearray as $imagerow) { $filename = $imagerow['filename']; $folder = $albumnames[$imagerow['albumid']]; $imagepath = substr($folder, $strip) . '/' . $filename; if (substr($imagepath, 0, 1) == '/') { $imagepath = substr($imagepath, 1); } $albumx = new Album($gallery, $folder); $image = newImage($albumx, $filename); if (is_valid_image($filename)) { $selected = $imagepath == $thumb; echo "\n<option"; if (getOption('thumb_select_images')) { echo " class=\"thumboption\""; echo " style=\"background-image: url(" . $image->getThumb() . "); background-repeat: no-repeat;\""; } echo " value=\"" . $imagepath . "\""; if ($selected) { echo " selected=\"selected\""; } echo ">" . $image->getTitle(); echo " ({$imagepath})"; echo "</option>"; } } } } else { foreach ($images as $filename) { $image = newImage($album, $filename); $selected = $filename == $album->get('thumb'); if (is_valid_image($filename)) { echo "\n<option"; if (getOption('thumb_select_images')) { echo " class=\"thumboption\""; echo " style=\"background-image: url(" . $image->getThumb() . "); background-repeat: no-repeat;\""; } echo " value=\"" . $filename . "\""; if ($selected) { echo " selected=\"selected\""; } echo ">" . $image->getTitle(); if ($filename != $image->getTitle()) { echo " ({$filename})"; } echo "</option>"; } } } } echo "\n</select>"; echo "\n</td>"; echo "\n</tr>"; echo "\n</table>"; echo "\n<input type=\"submit\" value=\"" . gettext("save album") . "\" />"; }