From 17b6475b6ce22faed28ddc3da8fd30f6a6f5576f Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Sat, 12 Apr 2014 18:00:11 +0200 Subject: [PATCH] Small code improvements to getArchive --- php/modules/Album.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/php/modules/Album.php b/php/modules/Album.php index ce40eb4..4792c9a 100644 --- a/php/modules/Album.php +++ b/php/modules/Album.php @@ -232,27 +232,29 @@ class Album extends Module { # Photos query switch($this->albumIDs) { case 's': - $photos = "SELECT url FROM lychee_photos WHERE public = '1';"; + $photos = "SELECT title, type, url FROM lychee_photos WHERE public = '1';"; $zipTitle = 'Public'; break; case 'f': - $photos = "SELECT url FROM lychee_photos WHERE star = '1';"; + $photos = "SELECT title, type, url FROM lychee_photos WHERE star = '1';"; $zipTitle = 'Starred'; break; default: - $photos = "SELECT url FROM lychee_photos WHERE album = '$this->albumIDs';"; + $photos = "SELECT title, type, url FROM lychee_photos WHERE album = '$this->albumIDs';"; $zipTitle = 'Unsorted'; } # Execute query $photos = $this->database->query($photos); + # Check if album empty + if ($photos->num_rows==0) return false; + # Init vars - $zip = new ZipArchive(); $files = array(); $i = 0; - # Parse each url + # Parse each path while ($photo = $photos->fetch_object()) { $files[$i] = __DIR__ . '/../../uploads/big/' . $photo->url; $i++; @@ -261,16 +263,23 @@ class Album extends Module { # Set title $album = $this->database->query("SELECT title FROM lychee_albums WHERE id = '$this->albumIDs' LIMIT 1;"); if ($this->albumIDs!=0&&is_numeric($this->albumIDs)) $zipTitle = $album->fetch_object()->title; + $filename = __DIR__ . "/../../data/$zipTitle.zip"; # Create zip - $filename = __DIR__ . "/../../data/$zipTitle.zip"; + + $zip = new ZipArchive(); if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) return false; # Add each photo foreach ($files AS $file) { - $newFile = explode('/', $file); - $newFile = array_reverse($newFile); - $zip->addFile($file, $zipTitle . '/' . $newFile[0]); + + if (!@is_readable($file)) continue; + + $photoName = explode('/', $file); + $photoName = array_reverse($photoName); + $photoName = $photoName[0]; + $zip->addFile($file, $zipTitle . '/' . $photoName); + } # Finish zip