diff --git a/php/access/admin.php b/php/access/admin.php index 28b8caa..d1c92ed 100644 --- a/php/access/admin.php +++ b/php/access/admin.php @@ -101,12 +101,12 @@ switch ($_POST['function']) { echo $photo->add($_FILES, $_POST['albumID']); break; - case 'importUrl': if (isset($_POST['url'], $_POST['albumID'])) - echo importUrl($_POST['url'], $_POST['albumID']); + case 'importUrl': if (!isset($_POST['url'], $_POST['albumID'])) exit(); + echo Import::url($_POST['url'], $_POST['albumID']); break; - case 'importServer': if (isset($_POST['albumID'])) - echo importServer($_POST['albumID']); + case 'importServer': if (!isset($_POST['albumID'])) exit(); + echo Import::server($_POST['albumID'], null); break; // Search Function diff --git a/php/api.php b/php/api.php index 8939aec..845a686 100755 --- a/php/api.php +++ b/php/api.php @@ -23,7 +23,6 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) { # Load modules require(__DIR__ . '/modules/misc.php'); - require(__DIR__ . '/modules/upload.php'); if (file_exists(__DIR__ . '/../data/config.php')) require(__DIR__ . '/../data/config.php'); else { diff --git a/php/modules/Import.php b/php/modules/Import.php new file mode 100644 index 0000000..0f92879 --- /dev/null +++ b/php/modules/Import.php @@ -0,0 +1,100 @@ +add($nameFile, $albumID, $description, $tags)) return false; + return true; + + } + + static function url($urls, $albumID = 0) { + + # Parse + $urls = str_replace(' ', '%20', $urls); + $urls = explode(',', $urls); + + # Set path + $path = __DIR__ . '/../../data/'; + + foreach ($urls as &$url) { + + if (@getimagesize($url)) { + + $pathinfo = pathinfo($url); + $filename = $pathinfo['filename'] . '.' . $pathinfo['extension']; + $tmp_name = $path . $filename; + + if (!@copy($url, $tmp_name)) return false; + + } + + } + + return Import::server($albumID, $path); + + } + + static function server($albumID = 0, $path) { + + if (!isset($path)) $path = __DIR__ . '/../../uploads/import/'; + + global $database, $plugins, $settings; + + $files = glob($path . '*'); + $contains['photos'] = false; + $contains['albums'] = false; + + foreach ($files as $file) { + + if (@getimagesize($file)) { + + # Photo + + if (!Import::photo($database, $plugins, $settings, $file, $albumID)) return false; + $contains['photos'] = true; + + } else if (is_dir($file)) { + + # Folder + + $name = mysqli_real_escape_string($database, basename($file)); + $album = new Album($database, null, null, null); + $newAlbumID = $album->add('[Import] ' . $name); + + if ($newAlbumID!==false) Import::server($newAlbumID, $file . '/'); + $contains['albums'] = true; + + } + + } + + 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; + + } + +} + +?> \ No newline at end of file diff --git a/php/modules/Photo.php b/php/modules/Photo.php index 76837bb..f9cb542 100755 --- a/php/modules/Photo.php +++ b/php/modules/Photo.php @@ -68,7 +68,7 @@ class Photo extends Module { if ($file['type']!=='image/jpeg'&& $file['type']!=='image/png'&& $file['type']!=='image/gif') - return false; + continue; $id = str_replace('.', '', microtime(true)); while(strlen($id)<14) $id .= 0; @@ -81,9 +81,10 @@ class Photo extends Module { # Import if not uploaded via web if (!is_uploaded_file($tmp_name)) { - if (copy($tmp_name, $path)) { @unlink($tmp_name); } + if (!@copy($tmp_name, $path)) exit('Error: Could not copy photo to uploads!'); + else @unlink($tmp_name); } else { - move_uploaded_file($tmp_name, $path); + if (!@move_uploaded_file($tmp_name, $path)) exit('Error: Could not move photo to uploads!'); } # Read infos @@ -97,11 +98,11 @@ class Photo extends Module { # Set orientation based on EXIF data if ($file['type']==='image/jpeg'&&isset($info['orientation'])&&$info['orientation']!==''&&isset($info['width'])&&isset($info['height'])) { - if (!$this->adjustFile($path, $info)) return false; + if (!$this->adjustFile($path, $info)) exit('Error: Could not adjust photo!'); } # Create Thumb - if (!$this->createThumb($path, $photo_name)) return false; + if (!$this->createThumb($path, $photo_name)) exit('Error: Could not create thumbnail for photo!'); # Save to DB $query = "INSERT INTO lychee_photos (id, title, url, description, tags, type, width, height, size, iso, aperture, make, model, shutter, focal, takestamp, thumbUrl, album, public, star) @@ -128,7 +129,7 @@ class Photo extends Module { '" . $star . "');"; $result = $this->database->query($query); - if (!$result) return false; + if (!$result) exit('Error: Could not save photo in database!'); } diff --git a/php/modules/upload.php b/php/modules/upload.php deleted file mode 100644 index f1c5468..0000000 --- a/php/modules/upload.php +++ /dev/null @@ -1,114 +0,0 @@ - \ No newline at end of file