Browse Source

- Multi-Folder import from server
- Improved upload
- Tidied up .php files
- Removed import of single files via view.php?p=filename

Tobias Reich 11 years ago
parent
commit
88a5810e0c

+ 1 - 1
assets/js/modules/contextMenu.js

@@ -224,7 +224,7 @@ contextMenu = {
 
 		lychee.api("getAlbums", function(data) {
 
-			if (!data.albums) {
+			if (data.num===0) {
 				items = [["New Album", 0, "album.add()"]];
 			} else {
 				$.each(data.content, function(index) {

+ 10 - 3
assets/js/modules/upload.js

@@ -170,6 +170,7 @@ upload = {
 				}],
 				["Cancel", function() {}]
 			];
+			
 			modal.show("Import from Link", "Please enter the direct link to a photo to import it: <input class='text' type='text' placeholder='http://' value='http://'>", buttons);
 
 		},
@@ -194,10 +195,15 @@ upload = {
 						upload.close();
 						upload.notify("Import complete");
 
-						if (album.getID()===false) lychee.goto("0");
+						if (data==="Notice: Import only contains albums!") {
+							if (visible.albums()) lychee.load();
+							else lychee.goto("");
+						}
+						else if (album.getID()===false) lychee.goto("0");
 						else album.load(albumID);
 
-						if (data==="Warning: Folder empty!") lychee.error("Folder empty. No photos imported!", params, data);
+						if (data==="Notice: Import only contains albums!") return true;
+						else if (data==="Warning: Folder empty!") lychee.error("Folder empty. No photos imported!", params, data);
 						else if (data!==true) lychee.error(null, params, data);
 
 					});
@@ -205,7 +211,8 @@ upload = {
 				}],
 				["Cancel", function() {}]
 			];
-			modal.show("Import from Server", "This action will import all photos which are located in <b>'uploads/import/'</b> of your Lychee installation.", buttons);
+			
+			modal.show("Import from Server", "This action will import all photos and albums which are located in <b>'uploads/import/'</b> of your Lychee installation.", buttons);
 
 		},
 

+ 59 - 58
php/modules/album.php

@@ -14,8 +14,9 @@ function addAlbum($title) {
 	global $database;
 
     if (strlen($title)<1||strlen($title)>50) return false;
-    $sysdate = date("d.m.Y");
-    $result = $database->query("INSERT INTO lychee_albums (title, sysdate) VALUES ('$title', '$sysdate');");
+    
+    $sysdate	= date("d.m.Y");
+    $result		= $database->query("INSERT INTO lychee_albums (title, sysdate) VALUES ('$title', '$sysdate');");
     
     if (!$result) return false;
     return $database->insert_id;
@@ -32,8 +33,10 @@ function getAlbums($public) {
     // Albums
     if ($public) $query = "SELECT * FROM lychee_albums WHERE public = 1";
     else $query = "SELECT * FROM lychee_albums";
-    $result = $database->query($query) OR exit("Error: $result <br>".$database->error);
-    $i = 0;
+    
+    $result	= $database->query($query) OR exit("Error: $result <br>".$database->error);
+    $i		= 0;
+    
     while($row = $result->fetch_object()) {
 
     	// Info
@@ -41,11 +44,14 @@ function getAlbums($public) {
         $return["content"][$row->id]['title'] = $row->title;
         $return["content"][$row->id]['public'] = $row->public;
         $return["content"][$row->id]['sysdate'] = date('F Y', strtotime($row->sysdate));
+        
+        // Password
         if ($row->password=="") $return["content"][$row->id]['password'] = false;
         else $return["content"][$row->id]['password'] = true;
 
         // Thumbs
         if (($public&&$row->password=="")||(!$public)) {
+        
 	        $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");
 	        $k = 0;
@@ -56,6 +62,7 @@ function getAlbums($public) {
 	        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
@@ -65,9 +72,6 @@ function getAlbums($public) {
 
     $return["num"] = $i;
 
-    if ($i==0) $return["albums"] = false;
-    else $return["albums"] = true;
-
     return $return;
 
 }
@@ -77,8 +81,8 @@ function getSmartInfo() {
 	global $database, $settings;
 
 	// Unsorted
-    $result = $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = 0 " . $settings['sorting']);
-    $i = 0;
+    $result	= $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = 0 " . $settings['sorting']);
+    $i		= 0;
     while($row = $result->fetch_object()) {
         if ($i<3) $return["unsortedThumb$i"] = $row->thumbUrl;
         $i++;
@@ -86,8 +90,8 @@ function getSmartInfo() {
     $return['unsortedNum'] = $i;
 
 	// Public
-    $result2 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE public = 1 " . $settings['sorting']);
-    $i = 0;
+    $result2	= $database->query("SELECT thumbUrl FROM lychee_photos WHERE public = 1 " . $settings['sorting']);
+    $i			= 0;
     while($row2 = $result2->fetch_object()) {
         if ($i<3) $return["publicThumb$i"] = $row2->thumbUrl;
         $i++;
@@ -95,8 +99,8 @@ function getSmartInfo() {
     $return['publicNum'] = $i;
 
 	// Starred
-    $result3 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE star = 1 " . $settings['sorting']);
-    $i = 0;
+    $result3	= $database->query("SELECT thumbUrl FROM lychee_photos WHERE star = 1 " . $settings['sorting']);
+    $i			= 0;
     while($row3 = $result3->fetch_object()) {
         if ($i<3) $return["starredThumb$i"] = $row3->thumbUrl;
         $i++;
@@ -128,34 +132,33 @@ function getAlbum($albumID) {
 
 	    default:	$result = $database->query("SELECT * FROM lychee_albums WHERE id = '$albumID';");
 			    	$row = $result->fetch_object();
-			    	$return['title'] = $row->title;
-			    	$return['description'] = $row->description;
-			    	$return['sysdate'] = date('d M. Y', strtotime($row->sysdate));
-			    	$return['public'] = $row->public;
-			    	if ($row->password=="") $return['password'] = false;
-			    	else $return['password'] = true;
+			    	$return['title']		= $row->title;
+			    	$return['description']	= $row->description;
+			    	$return['sysdate']		= date('d M. Y', strtotime($row->sysdate));
+			    	$return['public']		= $row->public;
+			    	$return['password']		= ($row->password=="" ? false : true);
 			    	$query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE album = '$albumID' " . $settings['sorting'];
 			    	break;
 
 	}
 
 	// Get photos
-	$result = $database->query($query);
-	$previousPhotoID = "";
-	$i = 0;
+	$result				= $database->query($query);
+	$previousPhotoID	= "";
+	$i					= 0;
 	while($row = $result->fetch_array()) {
 
-	    $return['content'][$row['id']]['id'] = $row['id'];
-	    $return['content'][$row['id']]['title'] = $row['title'];
-	    $return['content'][$row['id']]['sysdate'] = date('d F Y', strtotime($row['sysdate']));
-	    $return['content'][$row['id']]['public'] = $row['public'];
-	    $return['content'][$row['id']]['star'] = $row['star'];
-	    $return['content'][$row['id']]['tags'] = $row['tags'];
-	    $return['content'][$row['id']]['album'] = $row['album'];
-	    $return['content'][$row['id']]['thumbUrl'] = $row['thumbUrl'];
-
-	    $return['content'][$row['id']]['previousPhoto'] = $previousPhotoID;
-	    $return['content'][$row['id']]['nextPhoto'] = "";
+	    $return['content'][$row['id']]['id']		= $row['id'];
+	    $return['content'][$row['id']]['title']		= $row['title'];
+	    $return['content'][$row['id']]['sysdate']	= date('d F Y', strtotime($row['sysdate']));
+	    $return['content'][$row['id']]['public']	= $row['public'];
+	    $return['content'][$row['id']]['star']		= $row['star'];
+	    $return['content'][$row['id']]['tags']		= $row['tags'];
+	    $return['content'][$row['id']]['album']		= $row['album'];
+	    $return['content'][$row['id']]['thumbUrl']	= $row['thumbUrl'];
+
+	    $return['content'][$row['id']]['previousPhoto']	= $previousPhotoID;
+	    $return['content'][$row['id']]['nextPhoto']		= "";
 	    if ($previousPhotoID!="") $return['content'][$previousPhotoID]['nextPhoto'] = $row['id'];
 
 	    $previousPhotoID = $row['id'];
@@ -171,20 +174,20 @@ function getAlbum($albumID) {
 	} else {
 
 		// Enable next and previous for the first and last photo
-		$lastElement = end($return['content']);
-		$lastElementId = $lastElement['id'];
-		$firstElement = reset($return['content']);
-		$firstElementId = $firstElement['id'];
+		$lastElement	= end($return['content']);
+		$lastElementId	= $lastElement['id'];
+		$firstElement	= reset($return['content']);
+		$firstElementId	= $firstElement['id'];
 
 		if ($lastElementId!==$firstElementId) {
-			$return['content'][$lastElementId]['nextPhoto'] = $firstElementId;
-			$return['content'][$firstElementId]['previousPhoto'] = $lastElementId;
+			$return['content'][$lastElementId]['nextPhoto']			= $firstElementId;
+			$return['content'][$firstElementId]['previousPhoto']	= $lastElementId;
 		}
 
 	}
 
-	$return['id'] = $albumID;
-	$return['num'] = $i;
+	$return['id']	= $albumID;
+	$return['num']	= $i;
 
 	return $return;
 
@@ -219,8 +222,8 @@ function deleteAlbum($albumIDs) {
 
 	global $database;
 	
-	$error = false;
-	$result = $database->query("SELECT id FROM lychee_photos WHERE album IN ($albumIDs);");
+	$error	= false;
+	$result	= $database->query("SELECT id FROM lychee_photos WHERE album IN ($albumIDs);");
 	
 	// Delete photos
 	while ($row = $result->fetch_object())
@@ -252,10 +255,10 @@ function getAlbumArchive($albumID) {
 	        $zipTitle = "Unsorted";
 	}
 	
-	$zip = new ZipArchive();
-	$result = $database->query($query);
-	$files = array();
-	$i=0;
+	$zip	= new ZipArchive();
+	$result	= $database->query($query);
+	$files	= array();
+	$i		= 0;
 	
 	while($row = $result->fetch_object()) {
 	    $files[$i] = "../uploads/big/".$row->url;
@@ -293,15 +296,13 @@ function setAlbumPublic($albumID, $password) {
 
 	global $database;
 
-	$result = $database->query("SELECT public FROM lychee_albums WHERE id = '$albumID';");
-	$row = $result->fetch_object();
-	if ($row->public == 0){
-	    $public = 1;
-	} else {
-	    $public = 0;
-	}
+	$result	= $database->query("SELECT public FROM lychee_albums WHERE id = '$albumID';");
+	$row	= $result->fetch_object();
+	$public	= ($row->public===0 ? 1 : 0);
+	
 	$result = $database->query("UPDATE lychee_albums SET public = '$public', password = NULL WHERE id = '$albumID';");
 	if (!$result) return false;
+	
 	if ($public==1) {
 		$result = $database->query("UPDATE lychee_photos SET public = 0 WHERE album = '$albumID';");
 		if (!$result) return false;
@@ -327,8 +328,8 @@ function checkAlbumPassword($albumID, $password) {
 
 	global $database;
 
-	$result = $database->query("SELECT password FROM lychee_albums WHERE id = '$albumID';");
-	$row = $result->fetch_object();
+	$result	= $database->query("SELECT password FROM lychee_albums WHERE id = '$albumID';");
+	$row	= $result->fetch_object();
 	
 	if ($row->password=="") return true;
 	else if ($row->password==$password) return true;
@@ -340,8 +341,8 @@ function isAlbumPublic($albumID) {
 
 	global $database;
 
-	$result = $database->query("SELECT public FROM lychee_albums WHERE id = '$albumID';");
-	$row = $result->fetch_object();
+	$result	= $database->query("SELECT public FROM lychee_albums WHERE id = '$albumID';");
+	$row	= $result->fetch_object();
 
 	if ($row->public==1) return true;
 	return false;

+ 5 - 8
php/modules/db.php

@@ -32,8 +32,8 @@ function dbConnect() {
 
 function dbCreateConfig($dbHost = 'localhost', $dbUser, $dbPassword, $dbName = 'lychee') {
 
-	$dbPassword = urldecode($dbPassword);
-	$database = new mysqli($dbHost, $dbUser, $dbPassword);
+	$dbPassword	= urldecode($dbPassword);
+	$database	= new mysqli($dbHost, $dbUser, $dbPassword);
 
 	if ($database->connect_errno) return 'Warning: Connection failed!';
 	else {
@@ -60,12 +60,9 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
 ?>";
 
 		if (file_put_contents('../data/config.php', $config)===false) return 'Warning: Could not create file!';
-		else {
-
-			$_SESSION['login'] = true;
-			return true;
-
-		}
+			
+		$_SESSION['login'] = true;
+		return true;
 
 	}
 

+ 37 - 44
php/modules/misc.php

@@ -12,29 +12,31 @@ if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
 function openGraphHeader($photoID) {
 
 	global $database;
-
-    if (!is_numeric($photoID)) return false;
-    $result = $database->query("SELECT * FROM lychee_photos WHERE id = '$photoID';");
-    $row = $result->fetch_object();
-
-    $parseUrl = parse_url("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
-    $picture = $parseUrl['scheme']."://".$parseUrl['host'].$parseUrl['path']."/../uploads/big/".$row->url;
-
+	
+	$photoID = mysqli_real_escape_string($database, $photoID);
+	if (!is_numeric($photoID)) return false;
+	
+	$result	= $database->query("SELECT * FROM lychee_photos WHERE id = '$photoID';");
+	$row	= $result->fetch_object();
+	
+	$parseUrl = parse_url("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
+	$picture = $parseUrl['scheme']."://".$parseUrl['host'].$parseUrl['path']."/../uploads/big/".$row->url;
+	
 	$return  = '<!-- General Meta Data -->';
 	$return .= '<meta name="title" content="'.$row->title.'" />';
 	$return .= '<meta name="description" content="'.$row->description.' - via Lychee" />';
 	$return .= '<link rel="image_src"  type="image/jpeg" href="'.$picture.'" />';
-
+	
 	$return .= '<!-- Twitter Meta Data -->';
 	$return .= '<meta name="twitter:card" content="photo">';
 	$return .= '<meta name="twitter:title" content="'.$row->title.'">';
 	$return .= '<meta name="twitter:image:src" content="'.$picture.'">';
-
+	
 	$return .= '<!-- Facebook Meta Data -->';
 	$return .= '<meta property="og:title" content="'.$row->title.'">';
 	$return .= '<meta property="og:image" content="'.$picture.'">';
-
-    return $return;
+	
+	return $return;
 
 }
 
@@ -42,31 +44,35 @@ function search($term) {
 
 	global $database, $settings;
 
-	$return["albums"] = "";
+	$return['albums'] = '';
 
-    $result = $database->query("SELECT * FROM lychee_photos WHERE title like '%$term%' OR description like '%$term%' OR tags like '%$term%';");
+	// Photos
+    $result = $database->query("SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE title like '%$term%' OR description like '%$term%' OR tags like '%$term%';");
     while($row = $result->fetch_array()) {
-        $return['photos'][$row['id']] = $row;
-        $return['photos'][$row['id']]['sysdate'] = date('d F Y', strtotime($row['sysdate']));
+        $return['photos'][$row['id']]				= $row;
+        $return['photos'][$row['id']]['sysdate']	= date('d F Y', strtotime($row['sysdate']));
     }
 
+	// Albums
     $result = $database->query("SELECT * FROM lychee_albums WHERE title like '%$term%' OR description like '%$term%';");
-    $i=0;
+    $i		= 0;
     while($row = $result->fetch_object()) {
 
-        $return["albums"][$row->id]['id'] = $row->id;
-        $return["albums"][$row->id]['title'] = $row->title;
-        $return["albums"][$row->id]['public'] = $row->public;
-        $return["albums"][$row->id]['sysdate'] = date('F Y', strtotime($row->sysdate));
-        if ($row->password=="") $return["albums"][$row->id]['password'] = false;
-        else $return["albums"][$row->id]['password'] = true;
+		// Info
+        $return['albums'][$row->id]['id']		= $row->id;
+        $return['albums'][$row->id]['title']	= $row->title;
+        $return['albums'][$row->id]['public']	= $row->public;
+        $return['albums'][$row->id]['sysdate']	= date('F Y', strtotime($row->sysdate));
+        $return['albums'][$row->id]['password']	= ($row->password=='' ? false : true);
 
-        $result2 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = '" . $row->id . "' " . $settings['sorting'] . " LIMIT 0, 3;");
-        $k = 0;
+		// Thumbs
+        $result2	= $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = '" . $row->id . "' " . $settings['sorting'] . " LIMIT 0, 3;");
+        $k			= 0;
         while($row2 = $result2->fetch_object()){
             $return['albums'][$row->id]["thumb$k"] = $row2->thumbUrl;
             $k++;
         }
+        
         $i++;
 
     }
@@ -79,13 +85,13 @@ function update() {
 
 	global $database;
 
-	if(!$database->query("SELECT `public` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE  `lychee_albums` ADD  `public` TINYINT( 1 ) NOT NULL DEFAULT  '0'");
-	if(!$database->query("SELECT `password` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE  `lychee_albums` ADD  `password` VARCHAR( 100 ) NULL DEFAULT ''");
-	if(!$database->query("SELECT `description` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE  `lychee_albums` ADD  `description` VARCHAR( 1000 ) NULL DEFAULT ''");
-	if($database->query("SELECT `password` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE  `lychee_albums` CHANGE  `password` `password` VARCHAR( 100 ) NULL DEFAULT ''");
+	if(!$database->query("SELECT `public` FROM `lychee_albums` LIMIT 1;"))		$database->query("ALTER TABLE  `lychee_albums` ADD  `public` TINYINT( 1 ) NOT NULL DEFAULT  '0'");
+	if(!$database->query("SELECT `password` FROM `lychee_albums` LIMIT 1;"))	$database->query("ALTER TABLE  `lychee_albums` ADD  `password` VARCHAR( 100 ) NULL DEFAULT ''");
+	if(!$database->query("SELECT `description` FROM `lychee_albums` LIMIT 1;"))	$database->query("ALTER TABLE  `lychee_albums` ADD  `description` VARCHAR( 1000 ) NULL DEFAULT ''");
+	if($database->query("SELECT `password` FROM `lychee_albums` LIMIT 1;"))		$database->query("ALTER TABLE  `lychee_albums` CHANGE  `password` `password` VARCHAR( 100 ) NULL DEFAULT ''");
 
-	if($database->query("SELECT `description` FROM `lychee_photos` LIMIT 1;")) $database->query("ALTER TABLE  `lychee_photos` CHANGE  `description` `description` VARCHAR( 1000 ) NULL DEFAULT ''");
-	if(!$database->query("SELECT `tags` FROM `lychee_photos` LIMIT 1;")) $database->query("ALTER TABLE  `lychee_photos` ADD  `tags` VARCHAR( 1000 ) NULL DEFAULT ''");
+	if($database->query("SELECT `description` FROM `lychee_photos` LIMIT 1;"))	$database->query("ALTER TABLE  `lychee_photos` CHANGE  `description` `description` VARCHAR( 1000 ) NULL DEFAULT ''");
+	if(!$database->query("SELECT `tags` FROM `lychee_photos` LIMIT 1;"))		$database->query("ALTER TABLE  `lychee_photos` ADD  `tags` VARCHAR( 1000 ) NULL DEFAULT ''");
 	$database->query("UPDATE `lychee_photos` SET url = replace(url, 'uploads/big/', ''), thumbUrl = replace(thumbUrl, 'uploads/thumb/', '')");
 	
 	$result = $database->query("SELECT `value` FROM `lychee_settings` WHERE `key` = 'importFilename' LIMIT 1;");
@@ -95,17 +101,4 @@ function update() {
 
 }
 
-function pageURL() {
-
-	$pageURL = 'http';
-	if (isset($_SERVER["HTTPS"])&&$_SERVER["HTTPS"]==="on") $pageURL .= "s";
-	$pageURL .= "://";
-	
-	if ($_SERVER["SERVER_PORT"]!="80") $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER['SCRIPT_NAME'];
-	else $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER['SCRIPT_NAME'];
-	
-	return $pageURL;
-	
-}
-
 ?>

+ 22 - 42
php/modules/photo.php

@@ -13,20 +13,7 @@ function getPhoto($photoID, $albumID) {
 
 	global $database;
 
-	if (!is_numeric($photoID)) {
-		$result = $database->query("SELECT COUNT(*) AS quantity FROM lychee_photos WHERE import_name = '../uploads/import/$photoID';");
-		$row = $result->fetch_object();
-		if ($row->quantity == 0) {
-			importPhoto($photoID, 's');
-		}
-		if (is_file("../uploads/import/$photoID")) {
-			importPhoto($photoID, 's');
-		}
-		$query = "SELECT * FROM lychee_photos WHERE import_name = '../uploads/import/$photoID' ORDER BY ID DESC;";
-	} else {
-		$query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
-	}
-
+	$query	= "SELECT * FROM lychee_photos WHERE id = '$photoID';";
     $result = $database->query($query);
     $return = $result->fetch_array();
 
@@ -40,9 +27,9 @@ function getPhoto($photoID, $albumID) {
 
     	}
 
-    	$return['original_album'] = $return['album'];
-    	$return['album'] = $albumID;
-    	$return['sysdate'] = date('d M. Y', strtotime($return['sysdate']));
+    	$return['original_album']	= $return['album'];
+    	$return['album']			= $albumID;
+    	$return['sysdate']			= date('d M. Y', strtotime($return['sysdate']));
     	if (strlen($return['takedate'])>0) $return['takedate'] = date('d M. Y', strtotime($return['takedate']));
 
 	}
@@ -57,13 +44,9 @@ function setPhotoPublic($photoID, $url) {
 
 	global $database;
 
-    $result = $database->query("SELECT public FROM lychee_photos WHERE id = '$photoID';");
-    $row = $result->fetch_object();
-    if ($row->public == 0){
-        $public = 1;
-    } else {
-        $public = 0;
-    }
+    $result	= $database->query("SELECT public FROM lychee_photos WHERE id = '$photoID';");
+    $row	= $result->fetch_object();
+    $public = ($row->public==0 ? 1 : 0);
     $result = $database->query("UPDATE lychee_photos SET public = '$public' WHERE id = '$photoID';");
 
     if (!$result) return false;
@@ -75,14 +58,12 @@ function setPhotoStar($photoIDs) {
 
 	global $database;
 	
-	$error = false;
-    $result = $database->query("SELECT id, star FROM lychee_photos WHERE id IN ($photoIDs);");
+	$error	= false;
+    $result	= $database->query("SELECT id, star FROM lychee_photos WHERE id IN ($photoIDs);");
     
     while ($row = $result->fetch_object()) {
         
-    	if ($row->star==0) $star = 1;
-    	else $star = 0;
-    	
+        $star = ($row->star==0 ? 1 : 0);    	
     	$star = $database->query("UPDATE lychee_photos SET star = '$star' WHERE id = '$row->id';");
     	if (!$star) $error = true;
     	
@@ -122,6 +103,7 @@ function setPhotoDescription($photoID, $description) {
 
     $description = htmlentities($description);
     if (strlen($description)>1000) return false;
+    
     $result = $database->query("UPDATE lychee_photos SET description = '$description' WHERE id = '$photoID';");
 
     if (!$result) return false;
@@ -159,9 +141,9 @@ function deletePhoto($photoIDs) {
 		$thumbUrl2x = $thumbUrl2x[0] . '@2x.' . $thumbUrl2x[1];
 		
 		// Delete files
-		if (!unlink('../uploads/big/' . $row->url)) return false;
-		if (!unlink('../uploads/thumb/' . $row->thumbUrl)) return false;
-		if (!unlink('../uploads/thumb/' . $thumbUrl2x)) return false;
+		if (!unlink('../uploads/big/' . $row->url))			return false;
+		if (!unlink('../uploads/thumb/' . $row->thumbUrl))	return false;
+		if (!unlink('../uploads/thumb/' . $thumbUrl2x))		return false;
 		
 		// Delete db entry
 		$delete = $database->query("DELETE FROM lychee_photos WHERE id = $row->id;");
@@ -178,20 +160,18 @@ function isPhotoPublic($photoID, $password) {
 
 	global $database;
 
-	if (is_numeric($photoID)) {
-		$query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
-	} else {
-		$query = "SELECT * FROM lychee_photos WHERE import_name = '../uploads/import/$photoID';";
-	}
-    $result = $database->query($query);
-    $row = $result->fetch_object();
+	$query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
+
+    $result	= $database->query($query);
+    $row	= $result->fetch_object();
+    
     if (!is_numeric($photoID)&&!$row) return true;
     if ($row->public==1) return true;
     else {
     	$cAP = checkAlbumPassword($row->album, $password);
     	$iAP = isAlbumPublic($row->album);
     	if ($iAP&&$cAP) return true;
-    	else return false;
+    	return false;
     }
 
 }
@@ -200,8 +180,8 @@ function getPhotoArchive($photoID) {
 
 	global $database;
 
-	$result = $database->query("SELECT * FROM lychee_photos WHERE id = '$photoID';");
-	$row = $result->fetch_object();
+	$result	= $database->query("SELECT * FROM lychee_photos WHERE id = '$photoID';");
+	$row	= $result->fetch_object();
 
 	$extension = array_reverse(explode('.', $row->url));
 

+ 98 - 82
php/modules/upload.php

@@ -16,19 +16,19 @@ function upload($files, $albumID) {
 	switch($albumID) {
 		// s for public (share)
 	    case 's':
-	        $public = 1;
-	        $star = 0;
-	        $albumID = 0;
+	        $public		= 1;
+	        $star		= 0;
+	        $albumID	= 0;
 	        break;
 	    // f for starred (fav)
 	    case 'f':
-	        $star = 1;
-	        $public = 0;
-	        $albumID = 0;
+	        $star		= 1;
+	        $public		= 0;
+	        $albumID	= 0;
 	        break;
 	    default:
-	        $star = 0;
-	        $public = 0;
+	        $star		= 0;
+	        $public		= 0;
 	}
 
 	foreach ($files as $file) {
@@ -41,15 +41,15 @@ function upload($files, $albumID) {
 	    $id = str_replace('.', '', microtime(true));
 	    while(strlen($id)<14) $id .= 0;
 	    
-	    $tmp_name = $file['tmp_name'];
-	    $extension = array_reverse(explode('.', $file['name']));
-	    $extension = $extension[0];
-	    $photo_name = md5($id) . ".$extension";
+	    $tmp_name	= $file['tmp_name'];
+	    $extension	= array_reverse(explode('.', $file['name']));
+	    $extension	= $extension[0];
+	    $photo_name	= md5($id) . ".$extension";
 
 	    // Import if not uploaded via web
 	    if (!is_uploaded_file($tmp_name)) {
 	    	if (copy($tmp_name, '../uploads/big/' . $photo_name)) {
-				unlink($tmp_name);
+				@unlink($tmp_name);
 				$import_name = $tmp_name;
 			}
 	    } else {
@@ -63,7 +63,7 @@ function upload($files, $albumID) {
 	    // Use title of file if IPTC title missing
 	    if ($info['title']===''&&
 	    	$settings['importFilename']==='1')
-	    		$info['title'] = mysqli_real_escape_string($database, substr(str_replace(".$extension", '', $file['name']), 0, 30));
+	    		$info['title'] = mysqli_real_escape_string($database, substr(basename($file['name'], ".$extension"), 0, 30));
 
 	    // Set orientation based on EXIF data
 	    if ($file['type']==='image/jpeg'&&isset($info['orientation'])&&isset($info['width'])&&isset($info['height'])) {
@@ -167,16 +167,16 @@ function getInfo($filename) {
 
 	global $database;
 
-	$url = '../uploads/big/' . $filename;
-	$iptcArray = array();
-	$info = getimagesize($url, $iptcArray);
+	$url		= '../uploads/big/' . $filename;
+	$iptcArray	= array();
+	$info		= getimagesize($url, $iptcArray);
 
 	// General information
-	$return['type'] = $info['mime'];
-	$return['width'] = $info[0];
-	$return['height'] = $info[1];
-	$return['date'] = date('d.m.Y', filectime($url));
-	$return['time'] = date('H:i:s', filectime($url));
+	$return['type']		= $info['mime'];
+	$return['width']	= $info[0];
+	$return['height']	= $info[1];
+	$return['date']		= date('d.m.Y', filectime($url));
+	$return['time']		= date('H:i:s', filectime($url));
 
 	// Size
 	$size = filesize($url)/1024;
@@ -184,8 +184,8 @@ function getInfo($filename) {
 	else $return['size'] = round($size, 1) . ' KB';
 
 	// IPTC Metadata Fallback
-	$return['title'] = '';
-	$return['description'] = '';
+	$return['title']		= '';
+	$return['description']	= '';
 
 	// IPTC Metadata
 	if(isset($iptcArray['APP13'])) {
@@ -193,10 +193,10 @@ function getInfo($filename) {
 		$iptcInfo = iptcparse($iptcArray['APP13']);
 		if (is_array($iptcInfo)) {
 	
-			$temp = $iptcInfo['2#105'][0];
+			$temp = @$iptcInfo['2#105'][0];
 			if (isset($temp)&&strlen($temp)>0) $return['title'] = $temp;
 	
-			$temp = $iptcInfo['2#120'][0];
+			$temp = @$iptcInfo['2#120'][0];
 			if (isset($temp)&&strlen($temp)>0) $return['description'] = $temp;
 	
 		}
@@ -204,46 +204,48 @@ function getInfo($filename) {
 	}
 
 	// EXIF Metadata Fallback
-	$return['orientation'] = '';
-	$return['iso'] = '';
-	$return['aperture'] = '';
-	$return['make'] = '';
-	$return['model'] = '';
-	$return['shutter'] = '';
-	$return['focal'] = '';
-	$return['takeDate'] = '';
-	$return['takeTime'] = '';
+	$return['orientation']	= '';
+	$return['iso']			= '';
+	$return['aperture']		= '';
+	$return['make']			= '';
+	$return['model']		= '';
+	$return['shutter']		= '';
+	$return['focal']		= '';
+	$return['takeDate']		= '';
+	$return['takeTime']		= '';
+	
+	// Read EXIF
+	if ($info['mime']=='image/jpeg') $exif = exif_read_data($url, 'EXIF', 0);
+	else $exif = false;
 
 	// EXIF Metadata
-    if ($info['mime']=='image/jpeg'&&function_exists('exif_read_data')&&@exif_read_data($url, 'EXIF', 0)) {
-
-        $exif = exif_read_data($url, 'EXIF', 0);
+    if ($exif!==false) {
 
-        $temp = $exif['Orientation'];
+        $temp = @$exif['Orientation'];
         if (isset($temp)) $return['orientation'] = $temp;
 
-        $temp = $exif['ISOSpeedRatings'];
+        $temp = @$exif['ISOSpeedRatings'];
         if (isset($temp)) $return['iso'] = $temp;
 
-        $temp = $exif['COMPUTED']['ApertureFNumber'];
+        $temp = @$exif['COMPUTED']['ApertureFNumber'];
         if (isset($temp)) $return['aperture'] = $temp;
 
-        $temp = $exif['Make'];
+        $temp = @$exif['Make'];
         if (isset($temp)) $return['make'] = $exif['Make'];
 
-        $temp = $exif['Model'];
+        $temp = @$exif['Model'];
         if (isset($temp)) $return['model'] = $temp;
 
-        $temp = $exif['ExposureTime'];
+        $temp = @$exif['ExposureTime'];
         if (isset($temp)) $return['shutter'] = $exif['ExposureTime'] . ' Sec.';
 
-        $temp = $exif['FocalLength'];
+        $temp = @$exif['FocalLength'];
         if (isset($temp)) $return['focal'] = ($temp/1) . ' mm';
 
-        $temp = $exif['DateTimeOriginal'];
+        $temp = @$exif['DateTimeOriginal'];
         if (isset($temp)) {
-            $exifDate = explode(' ', $temp);
-            $date = explode(':', $exifDate[0]);
+            $exifDate	= explode(' ', $temp);
+            $date		= explode(':', $exifDate[0]);
             $return['takeDate'] = $date[2].'.'.$date[1].'.'.$date[0];
             $return['takeTime'] = $exifDate[1];
         }
@@ -261,24 +263,24 @@ function createThumb($filename, $width = 200, $height = 200) {
 
 	global $settings;
 
-    $url = "../uploads/big/$filename";
-    $info = getimagesize($url);
+    $url	= "../uploads/big/$filename";
+    $info	= getimagesize($url);
 
-    $photoName = explode(".", $filename);
-    $newUrl = "../uploads/thumb/$photoName[0].jpeg";
-    $newUrl2x = "../uploads/thumb/$photoName[0]@2x.jpeg";
+    $photoName	= explode(".", $filename);
+    $newUrl		= "../uploads/thumb/$photoName[0].jpeg";
+    $newUrl2x	= "../uploads/thumb/$photoName[0]@2x.jpeg";
 
     // Set position and size
     $thumb = imagecreatetruecolor($width, $height);
     $thumb2x = imagecreatetruecolor($width*2, $height*2);
     if ($info[0]<$info[1]) {
-        $newSize = $info[0];
-        $startWidth = 0;
-        $startHeight = $info[1]/2 - $info[0]/2;
+        $newSize		= $info[0];
+        $startWidth		= 0;
+        $startHeight	= $info[1]/2 - $info[0]/2;
     } else {
-        $newSize = $info[1];
-        $startWidth = $info[0]/2 - $info[1]/2;
-        $startHeight = 0;
+        $newSize		= $info[1];
+        $startWidth		= $info[0]/2 - $info[1]/2;
+        $startHeight	= 0;
     }
     
     // Fallback for older version
@@ -286,10 +288,10 @@ function createThumb($filename, $width = 200, $height = 200) {
 
     // Create new image
     switch($info['mime']) {
-        case 'image/jpeg': $sourceImg = imagecreatefromjpeg($url); break;
-        case 'image/png': $sourceImg = imagecreatefrompng($url); break;
-        case 'image/gif': $sourceImg = imagecreatefromgif($url); break;
-        case 'image/webp': $sourceImg = imagecreatefromwebp($url); break;
+        case 'image/jpeg':	$sourceImg = imagecreatefromjpeg($url); break;
+        case 'image/png':	$sourceImg = imagecreatefrompng($url); break;
+        case 'image/gif':	$sourceImg = imagecreatefromgif($url); break;
+        case 'image/webp':	$sourceImg = imagecreatefromwebp($url); break;
         default: return false;
     }
 
@@ -303,21 +305,19 @@ function createThumb($filename, $width = 200, $height = 200) {
 
 }
 
-function importPhoto($name, $albumID = 0) {
+function importPhoto($path, $albumID = 0) {
 
-	$tmp_name = "../uploads/import/$name";
-	$info = getimagesize($tmp_name);
-	$size = filesize($tmp_name);
-	$nameFile = array(array());
-	$nameFile[0]['name'] = $name;
-	$nameFile[0]['type'] = $info['mime'];
-	$nameFile[0]['tmp_name'] = $tmp_name;
-	$nameFile[0]['error'] = 0;
-	$nameFile[0]['size'] = $size;
-
-	if (upload($nameFile, $albumID)) return true;
+	$info = getimagesize($path);
+	$size = filesize($path);
+	
+	$nameFile					= array(array());
+	$nameFile[0]['name']		= $path;
+	$nameFile[0]['type']		= $info['mime'];
+	$nameFile[0]['tmp_name']	= $path;
+	$nameFile[0]['error']		= 0;
+	$nameFile[0]['size']		= $size;
 
-	return false;
+	return upload($nameFile, $albumID);
 
 }
 
@@ -338,6 +338,7 @@ function importUrl($url, $albumID = 0) {
 				$pathinfo = pathinfo($key);
 				$filename = $pathinfo['filename'].".".$pathinfo['extension'];
 				$tmp_name = "../uploads/import/$filename";
+				
 				copy($key, $tmp_name);
 
 			}
@@ -357,7 +358,9 @@ function importUrl($url, $albumID = 0) {
 			$pathinfo = pathinfo($url);
 			$filename = $pathinfo['filename'].".".$pathinfo['extension'];
 			$tmp_name = "../uploads/import/$filename";
+			
 			copy($url, $tmp_name);
+			
 			return importPhoto($filename, $albumID);
 
 		}
@@ -368,23 +371,36 @@ function importUrl($url, $albumID = 0) {
 
 }
 
-function importServer($albumID = 0) {
+function importServer($albumID = 0, $path = '../uploads/import/') {
 
 	global $database;
 
-	$i = 0;
-	$files = glob('../uploads/import/*');
+	$files				= glob($path . '*');
+	$contains['photos'] = false;
+	$contains['albums'] = false;
 
 	foreach ($files as $file) {
 
 		if (@getimagesize($file)) {
-			if (!importPhoto(basename($file), $albumID)) return false;
-			$i++;
+		
+			// Photo
+			if (!importPhoto($file, $albumID)) return false;
+			$contains['photos'] = true;
+			
+		} else if (is_dir($file)) {
+		
+			$name		= mysqli_real_escape_string($database, basename($file));
+			$newAlbumID	= addAlbum('[Import] ' . $name);
+				
+			if ($newAlbumID!==false) importServer($newAlbumID, $file . '/');
+			$contains['albums'] = true;
+		
 		}
 
 	}
 
-	if ($i===0) return "Warning: Folder empty!";
+	if ($contains['photos']===false&&$contains['albums']===false) return "Warning: Folder empty!";
+	if ($contains['photos']===false&&$contains['albums']===true) return "Notice: Import only contains albums!";
 	return true;
 
 }