Small code improvements to getArchive

This commit is contained in:
Tobias Reich 2014-04-12 18:00:11 +02:00
parent 1fdc495f91
commit 17b6475b6c

View File

@ -232,27 +232,29 @@ class Album extends Module {
# Photos query # Photos query
switch($this->albumIDs) { switch($this->albumIDs) {
case 's': case 's':
$photos = "SELECT url FROM lychee_photos WHERE public = '1';"; $photos = "SELECT title, type, url FROM lychee_photos WHERE public = '1';";
$zipTitle = 'Public'; $zipTitle = 'Public';
break; break;
case 'f': case 'f':
$photos = "SELECT url FROM lychee_photos WHERE star = '1';"; $photos = "SELECT title, type, url FROM lychee_photos WHERE star = '1';";
$zipTitle = 'Starred'; $zipTitle = 'Starred';
break; break;
default: 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'; $zipTitle = 'Unsorted';
} }
# Execute query # Execute query
$photos = $this->database->query($photos); $photos = $this->database->query($photos);
# Check if album empty
if ($photos->num_rows==0) return false;
# Init vars # Init vars
$zip = new ZipArchive();
$files = array(); $files = array();
$i = 0; $i = 0;
# Parse each url # Parse each path
while ($photo = $photos->fetch_object()) { while ($photo = $photos->fetch_object()) {
$files[$i] = __DIR__ . '/../../uploads/big/' . $photo->url; $files[$i] = __DIR__ . '/../../uploads/big/' . $photo->url;
$i++; $i++;
@ -261,16 +263,23 @@ class Album extends Module {
# Set title # Set title
$album = $this->database->query("SELECT title FROM lychee_albums WHERE id = '$this->albumIDs' LIMIT 1;"); $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; if ($this->albumIDs!=0&&is_numeric($this->albumIDs)) $zipTitle = $album->fetch_object()->title;
$filename = __DIR__ . "/../../data/$zipTitle.zip";
# Create zip # Create zip
$filename = __DIR__ . "/../../data/$zipTitle.zip";
$zip = new ZipArchive();
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) return false; if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) return false;
# Add each photo # Add each photo
foreach ($files AS $file) { foreach ($files AS $file) {
$newFile = explode('/', $file);
$newFile = array_reverse($newFile); if (!@is_readable($file)) continue;
$zip->addFile($file, $zipTitle . '/' . $newFile[0]);
$photoName = explode('/', $file);
$photoName = array_reverse($photoName);
$photoName = $photoName[0];
$zip->addFile($file, $zipTitle . '/' . $photoName);
} }
# Finish zip # Finish zip