Code and speed improvements
This commit is contained in:
parent
f6177e9d3e
commit
6eb46da1a1
@ -15,7 +15,7 @@ function addAlbum($title = '', $public = 0, $visible = 1) {
|
|||||||
|
|
||||||
if (strlen($title)>50) $title = substr($title, 0, 50);
|
if (strlen($title)>50) $title = substr($title, 0, 50);
|
||||||
|
|
||||||
$sysdate = date("d.m.Y");
|
$sysdate = date('d.m.Y');
|
||||||
$result = $database->query("INSERT INTO lychee_albums (title, sysdate, public, visible) VALUES ('$title', '$sysdate', '$public', '$visible');");
|
$result = $database->query("INSERT INTO lychee_albums (title, sysdate, public, visible) VALUES ('$title', '$sysdate', '$public', '$visible');");
|
||||||
|
|
||||||
if (!$result) return false;
|
if (!$result) return false;
|
||||||
@ -28,49 +28,42 @@ function getAlbums($public) {
|
|||||||
global $database, $settings;
|
global $database, $settings;
|
||||||
|
|
||||||
// Smart Albums
|
// Smart Albums
|
||||||
if (!$public) $return = getSmartInfo();
|
if ($public===false) $return = getSmartInfo();
|
||||||
|
|
||||||
// Albums
|
// Albums
|
||||||
if ($public) $query = "SELECT id, title, public, sysdate, password FROM lychee_albums WHERE public = 1 AND visible <> 0";
|
$query = "SELECT id, title, public, sysdate, password FROM lychee_albums WHERE public = 1 AND visible <> 0";
|
||||||
else $query = "SELECT id, title, public, sysdate, password FROM lychee_albums";
|
if ($public===false) $query = "SELECT id, title, public, sysdate, password FROM lychee_albums";
|
||||||
|
|
||||||
$result = $database->query($query) OR exit("Error: $result <br>".$database->error);
|
$result = $database->query($query) OR exit('Error: ' . $database->error);
|
||||||
$i = 0;
|
|
||||||
|
|
||||||
while($row = $result->fetch_object()) {
|
while ($row = $result->fetch_object()) {
|
||||||
|
|
||||||
// Info
|
// Info
|
||||||
$return["content"][$row->id]['id'] = $row->id;
|
$return['content'][$row->id]['id'] = $row->id;
|
||||||
$return["content"][$row->id]['title'] = $row->title;
|
$return['content'][$row->id]['title'] = $row->title;
|
||||||
$return["content"][$row->id]['public'] = $row->public;
|
$return['content'][$row->id]['public'] = $row->public;
|
||||||
$return["content"][$row->id]['sysdate'] = date('F Y', strtotime($row->sysdate));
|
$return['content'][$row->id]['sysdate'] = date('F Y', strtotime($row->sysdate));
|
||||||
|
|
||||||
// Password
|
// Password
|
||||||
if ($row->password=="") $return["content"][$row->id]['password'] = false;
|
$return['content'][$row->id]['password'] = false;
|
||||||
else $return["content"][$row->id]['password'] = true;
|
if ($row->password!='') $return['content'][$row->id]['password'] = true;
|
||||||
|
|
||||||
// Thumbs
|
// Thumbs
|
||||||
if (($public&&$row->password=="")||(!$public)) {
|
if (($public&&$row->password=='')||(!$public)) {
|
||||||
|
|
||||||
$albumID = $row->id;
|
$albumID = $row->id;
|
||||||
$result2 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = '$albumID' ORDER BY star DESC, " . substr($settings['sorting'], 9) . " LIMIT 0, 3");
|
$result2 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = '$albumID' ORDER BY star DESC, " . substr($settings['sorting'], 9) . " LIMIT 0, 3");
|
||||||
$k = 0;
|
$k = 0;
|
||||||
while($row2 = $result2->fetch_object()){
|
while ($row2 = $result2->fetch_object()) {
|
||||||
$return["content"][$row->id]["thumb$k"] = $row2->thumbUrl;
|
$return['content'][$row->id]["thumb$k"] = $row2->thumbUrl;
|
||||||
$k++;
|
$k++;
|
||||||
}
|
}
|
||||||
if (!isset($return["content"][$row->id]["thumb0"])) $return["content"][$row->id]["thumb0"] = "";
|
|
||||||
if (!isset($return["content"][$row->id]["thumb1"])) $return["content"][$row->id]["thumb1"] = "";
|
|
||||||
if (!isset($return["content"][$row->id]["thumb2"])) $return["content"][$row->id]["thumb2"] = "";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Album count
|
|
||||||
$i++;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$return["num"] = $i;
|
$return["num"] = $result->num_rows;
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
|
||||||
@ -84,28 +77,34 @@ function getSmartInfo() {
|
|||||||
$result = $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = 0 " . $settings['sorting']);
|
$result = $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = 0 " . $settings['sorting']);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while($row = $result->fetch_object()) {
|
while($row = $result->fetch_object()) {
|
||||||
if ($i<3) $return["unsortedThumb$i"] = $row->thumbUrl;
|
if ($i<3) {
|
||||||
$i++;
|
$return["unsortedThumb$i"] = $row->thumbUrl;
|
||||||
|
$i++;
|
||||||
|
} else break;
|
||||||
}
|
}
|
||||||
$return['unsortedNum'] = $i;
|
$return['unsortedNum'] = $result->num_rows;
|
||||||
|
|
||||||
// Public
|
// Public
|
||||||
$result2 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE public = 1 " . $settings['sorting']);
|
$result2 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE public = 1 " . $settings['sorting']);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while($row2 = $result2->fetch_object()) {
|
while($row2 = $result2->fetch_object()) {
|
||||||
if ($i<3) $return["publicThumb$i"] = $row2->thumbUrl;
|
if ($i<3) {
|
||||||
$i++;
|
$return["publicThumb$i"] = $row2->thumbUrl;
|
||||||
|
$i++;
|
||||||
|
} else break;
|
||||||
}
|
}
|
||||||
$return['publicNum'] = $i;
|
$return['publicNum'] = $result2->num_rows;
|
||||||
|
|
||||||
// Starred
|
// Starred
|
||||||
$result3 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE star = 1 " . $settings['sorting']);
|
$result3 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE star = 1 " . $settings['sorting']);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while($row3 = $result3->fetch_object()) {
|
while($row3 = $result3->fetch_object()) {
|
||||||
if ($i<3) $return["starredThumb$i"] = $row3->thumbUrl;
|
if ($i<3) {
|
||||||
$i++;
|
$return["starredThumb$i"] = $row3->thumbUrl;
|
||||||
|
$i++;
|
||||||
|
} else break;
|
||||||
}
|
}
|
||||||
$return['starredNum'] = $i;
|
$return['starredNum'] = $result3->num_rows;
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
|
||||||
@ -118,15 +117,15 @@ function getAlbum($albumID) {
|
|||||||
// Get album information
|
// Get album information
|
||||||
switch($albumID) {
|
switch($albumID) {
|
||||||
|
|
||||||
case "f": $return['public'] = false;
|
case 'f': $return['public'] = false;
|
||||||
$query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE star = 1 " . $settings['sorting'];
|
$query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE star = 1 " . $settings['sorting'];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "s": $return['public'] = false;
|
case 's': $return['public'] = false;
|
||||||
$query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE public = 1 " . $settings['sorting'];
|
$query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE public = 1 " . $settings['sorting'];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "0": $return['public'] = false;
|
case '0': $return['public'] = false;
|
||||||
$query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE album = 0 " . $settings['sorting'];
|
$query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE album = 0 " . $settings['sorting'];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -136,7 +135,7 @@ function getAlbum($albumID) {
|
|||||||
$return['description'] = $row->description;
|
$return['description'] = $row->description;
|
||||||
$return['sysdate'] = date('d M. Y', strtotime($row->sysdate));
|
$return['sysdate'] = date('d M. Y', strtotime($row->sysdate));
|
||||||
$return['public'] = $row->public;
|
$return['public'] = $row->public;
|
||||||
$return['password'] = ($row->password=="" ? false : true);
|
$return['password'] = ($row->password=='' ? false : true);
|
||||||
$query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE album = '$albumID' " . $settings['sorting'];
|
$query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE album = '$albumID' " . $settings['sorting'];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -144,8 +143,7 @@ function getAlbum($albumID) {
|
|||||||
|
|
||||||
// Get photos
|
// Get photos
|
||||||
$result = $database->query($query);
|
$result = $database->query($query);
|
||||||
$previousPhotoID = "";
|
$previousPhotoID = '';
|
||||||
$i = 0;
|
|
||||||
while($row = $result->fetch_assoc()) {
|
while($row = $result->fetch_assoc()) {
|
||||||
|
|
||||||
$return['content'][$row['id']]['id'] = $row['id'];
|
$return['content'][$row['id']]['id'] = $row['id'];
|
||||||
@ -158,15 +156,14 @@ function getAlbum($albumID) {
|
|||||||
$return['content'][$row['id']]['thumbUrl'] = $row['thumbUrl'];
|
$return['content'][$row['id']]['thumbUrl'] = $row['thumbUrl'];
|
||||||
|
|
||||||
$return['content'][$row['id']]['previousPhoto'] = $previousPhotoID;
|
$return['content'][$row['id']]['previousPhoto'] = $previousPhotoID;
|
||||||
$return['content'][$row['id']]['nextPhoto'] = "";
|
$return['content'][$row['id']]['nextPhoto'] = '';
|
||||||
if ($previousPhotoID!="") $return['content'][$previousPhotoID]['nextPhoto'] = $row['id'];
|
if ($previousPhotoID!="") $return['content'][$previousPhotoID]['nextPhoto'] = $row['id'];
|
||||||
|
|
||||||
$previousPhotoID = $row['id'];
|
$previousPhotoID = $row['id'];
|
||||||
$i++;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($i==0) {
|
if ($result->num_rows===0) {
|
||||||
|
|
||||||
// Empty album
|
// Empty album
|
||||||
$return['content'] = false;
|
$return['content'] = false;
|
||||||
@ -187,7 +184,7 @@ function getAlbum($albumID) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$return['id'] = $albumID;
|
$return['id'] = $albumID;
|
||||||
$return['num'] = $i;
|
$return['num'] = $result->num_rows;
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
|
||||||
@ -197,7 +194,8 @@ function setAlbumTitle($albumIDs, $title) {
|
|||||||
|
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
if (strlen($title)<1||strlen($title)>50) return false;
|
if (strlen($title)>50) $title = substr($title, 0, 50);
|
||||||
|
|
||||||
$result = $database->query("UPDATE lychee_albums SET title = '$title' WHERE id IN ($albumIDs);");
|
$result = $database->query("UPDATE lychee_albums SET title = '$title' WHERE id IN ($albumIDs);");
|
||||||
|
|
||||||
if (!$result) return false;
|
if (!$result) return false;
|
||||||
@ -211,6 +209,7 @@ function setAlbumDescription($albumID, $description) {
|
|||||||
|
|
||||||
$description = htmlentities($description);
|
$description = htmlentities($description);
|
||||||
if (strlen($description)>1000) return false;
|
if (strlen($description)>1000) return false;
|
||||||
|
|
||||||
$result = $database->query("UPDATE lychee_albums SET description = '$description' WHERE id = '$albumID';");
|
$result = $database->query("UPDATE lychee_albums SET description = '$description' WHERE id = '$albumID';");
|
||||||
|
|
||||||
if (!$result) return false;
|
if (!$result) return false;
|
||||||
@ -244,15 +243,15 @@ function getAlbumArchive($albumID) {
|
|||||||
switch($albumID) {
|
switch($albumID) {
|
||||||
case 's':
|
case 's':
|
||||||
$query = "SELECT url FROM lychee_photos WHERE public = '1';";
|
$query = "SELECT url FROM lychee_photos WHERE public = '1';";
|
||||||
$zipTitle = "Public";
|
$zipTitle = 'Public';
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
$query = "SELECT url FROM lychee_photos WHERE star = '1';";
|
$query = "SELECT url FROM lychee_photos WHERE star = '1';";
|
||||||
$zipTitle = "Starred";
|
$zipTitle = 'Starred';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$query = "SELECT url FROM lychee_photos WHERE album = '$albumID';";
|
$query = "SELECT url FROM lychee_photos WHERE album = '$albumID';";
|
||||||
$zipTitle = "Unsorted";
|
$zipTitle = 'Unsorted';
|
||||||
}
|
}
|
||||||
|
|
||||||
$zip = new ZipArchive();
|
$zip = new ZipArchive();
|
||||||
@ -261,12 +260,13 @@ function getAlbumArchive($albumID) {
|
|||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
while($row = $result->fetch_object()) {
|
while($row = $result->fetch_object()) {
|
||||||
$files[$i] = "../uploads/big/".$row->url;
|
$files[$i] = '../uploads/big/' . $row->url;
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $database->query("SELECT title FROM lychee_albums WHERE id = '$albumID' LIMIT 1;");
|
$result = $database->query("SELECT title FROM lychee_albums WHERE id = '$albumID' LIMIT 1;");
|
||||||
$row = $result->fetch_object();
|
$row = $result->fetch_object();
|
||||||
|
|
||||||
if ($albumID!=0&&is_numeric($albumID)) $zipTitle = $row->title;
|
if ($albumID!=0&&is_numeric($albumID)) $zipTitle = $row->title;
|
||||||
$filename = "../data/$zipTitle.zip";
|
$filename = "../data/$zipTitle.zip";
|
||||||
|
|
||||||
@ -275,9 +275,9 @@ function getAlbumArchive($albumID) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach($files AS $zipFile) {
|
foreach($files AS $zipFile) {
|
||||||
$newFile = explode("/",$zipFile);
|
$newFile = explode('/',$zipFile);
|
||||||
$newFile = array_reverse($newFile);
|
$newFile = array_reverse($newFile);
|
||||||
$zip->addFile($zipFile, $zipTitle."/".$newFile[0]);
|
$zip->addFile($zipFile, $zipTitle . '/' . $newFile[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$zip->close();
|
$zip->close();
|
||||||
@ -296,7 +296,7 @@ function setAlbumPublic($albumID, $password) {
|
|||||||
|
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
$result = $database->query("SELECT public FROM lychee_albums WHERE id = '$albumID';");
|
$result = $database->query("SELECT public FROM lychee_albums WHERE id = '$albumID' LIMIT 1;");
|
||||||
$row = $result->fetch_object();
|
$row = $result->fetch_object();
|
||||||
$public = ($row->public=='0' ? 1 : 0);
|
$public = ($row->public=='0' ? 1 : 0);
|
||||||
|
|
||||||
@ -331,7 +331,7 @@ function checkAlbumPassword($albumID, $password) {
|
|||||||
$result = $database->query("SELECT password FROM lychee_albums WHERE id = '$albumID';");
|
$result = $database->query("SELECT password FROM lychee_albums WHERE id = '$albumID';");
|
||||||
$row = $result->fetch_object();
|
$row = $result->fetch_object();
|
||||||
|
|
||||||
if ($row->password=="") return true;
|
if ($row->password=='') return true;
|
||||||
else if ($row->password==$password) return true;
|
else if ($row->password==$password) return true;
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -341,10 +341,11 @@ function isAlbumPublic($albumID) {
|
|||||||
|
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
|
if ($albumID==='0'||$albumID==='s'||$albumID==='f') return false;
|
||||||
|
|
||||||
$result = $database->query("SELECT public FROM lychee_albums WHERE id = '$albumID';");
|
$result = $database->query("SELECT public FROM lychee_albums WHERE id = '$albumID';");
|
||||||
$row = $result->fetch_object();
|
$row = $result->fetch_object();
|
||||||
|
|
||||||
if ($albumID==='0'||$albumID==='s'||$albumID==='f') return false;
|
|
||||||
if ($row->public==1) return true;
|
if ($row->public==1) return true;
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user