Browse Source

Merge branch 'develop' of https://github.com/electerious/Lychee into develop

Tobias Reich 8 years ago
parent
commit
31e41eb2b1

+ 1 - 1
php/Modules/Album.php

@@ -278,7 +278,7 @@ final class Album {
 			if (!@is_readable($photo->url)) continue;
 
 			// Get extension of image
-			$extension = getExtension($photo->url);
+			$extension = getExtension($photo->url, true);
 
 			// Set title for photo
 			$zipFileName = $zipTitle . '/' . $photo->title . $extension;

+ 1 - 1
php/Modules/Import.php

@@ -50,7 +50,7 @@ final class Import {
 			// This prevents us from downloading invalid photos.
 
 			// Verify extension
-			$extension = getExtension($url);
+			$extension = getExtension($url, true);
 			if (!in_array(strtolower($extension), Photo::$validExtensions, true)) {
 				$error = true;
 				Log::error(Database::get(), __METHOD__, __LINE__, 'Photo format not supported (' . $url . ')');

+ 4 - 3
php/Modules/Photo.php

@@ -4,6 +4,7 @@ namespace Lychee\Modules;
 
 use ZipArchive;
 use Imagick;
+use ImagickPixel;
 
 final class Photo {
 
@@ -123,7 +124,7 @@ final class Photo {
 		}
 
 		// Verify extension
-		$extension = getExtension($file['name']);
+		$extension = getExtension($file['name'], false);
 		if (!in_array(strtolower($extension), self::$validExtensions, true)) {
 			Log::error(Database::get(), __METHOD__, __LINE__, 'Photo format not supported');
 			if ($returnOnError===true) return false;
@@ -844,8 +845,8 @@ final class Photo {
 		}
 
 		// Get extension
-		$extension = getExtension($photo->url);
-		if ($extension===false) {
+		$extension = getExtension($photo->url, true);
+		if (empty($extension)) {
 			Log::error(Database::get(), __METHOD__, __LINE__, 'Invalid photo extension');
 			return false;
 		}

+ 10 - 5
php/helpers/getExtension.php

@@ -1,13 +1,18 @@
 <?php
 
-function getExtension($filename) {
+# Returns the extension of the filename (path or URI) or an empty string
+function getExtension($filename, $isURI = false) {
 
-	$extension = strpos($filename, '.') !== false
-		? strrchr($filename, '.')
-		: '';
+    # If $filename is an URI, get only the path component
+    if ($isURI)
+        $filename = parse_url($filename, PHP_URL_PATH);
 
-	return $extension;
+	$extension = pathinfo($filename, PATHINFO_EXTENSION);
+
+    if (!empty($extension))
+        $extension = '.' . $extension;
 
+	return $extension;
 }
 
 ?>

+ 1 - 1
plugins/Diagnostics/index.php

@@ -91,7 +91,7 @@ if (!$settings['dropboxKey']) echo('Warning: Dropbox import not working. No prop
 
 // Check php.ini Settings
 if (ini_get('max_execution_time')<200&&ini_set('upload_max_filesize', '20M')===false) echo('Warning: You may experience problems when uploading a large amount of photos. Take a look in the FAQ for details.' . PHP_EOL);
-if (!ini_get('allow_url_fopen')) echo('Warning: You may experience problems with the Dropbox- and URL-Import. Edit your php.ini and set allow_url_fopen to 1.' . PHP_EOL);
+if (empty(ini_get('allow_url_fopen'))) echo('Warning: You may experience problems with the Dropbox- and URL-Import. Edit your php.ini and set allow_url_fopen to 1.' . PHP_EOL);
 
 // Check mysql version
 if ($database->server_version<50500) echo('Warning: Lychee uses the GBK charset to avoid sql injections on your MySQL version. Please update to MySQL 5.5 or higher to enable UTF-8 support.' . PHP_EOL);