Skip to content

Commit

Permalink
Merge pull request #376 from electerious/develop
Browse files Browse the repository at this point in the history
Lychee v3.0.4
  • Loading branch information
electerious committed Jul 17, 2015
2 parents c7d426c + b0300b9 commit aee5d9b
Show file tree
Hide file tree
Showing 44 changed files with 2,649 additions and 2,566 deletions.
2 changes: 1 addition & 1 deletion dist/main.css

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/main.js
100755 → 100644

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/view.js
100644 → 100755

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions docs/Build.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@ First you have to install the following dependencies:

- `node` [Node.js](http://nodejs.org) v0.10 or later
- `npm` [Node Packaged Modules](https://www.npmjs.org)
- `bower` [Bower](http://bower.io)
- `gulp` [Gulp.js](http://gulpjs.com)

After [installing Node.js](http://nodejs.org) you can use the included `npm` package manager to install the global requirements and Lychee-dependencies with the following command:

cd src/
npm install -g bower gulp
npm install && bower install
npm install -g gulp
npm install

### Build

The Gruntfile is located in `src/` and can be easily executed using the `gulp` command.
The Gulpfile is located in `src/` and can be easily executed using the `gulp` command.

### Watch for changes

While developing, you might want to use the following command to watch for changes:

gulp watch

`gulp` will automatically build Lychee everytime you save a file.
`gulp watch` will automatically build Lychee everytime you save a file.
14 changes: 13 additions & 1 deletion docs/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
## v3.0.4

Released July 17, 2015

- `Improved` Removed bower and updated basicModal & basicContext
- `Improved` Small interface performance improvements
- `Improved` Updated all JS-files to take advantage of ES2015
- `Improved` Better error-handling for the Dropbox-, URL- and Server-Import
- `Improved` Added skipDuplicates- and identifier-check to the diagnostics
- `Fixed` error when using "Merge All" with one selected album
- `Fixed` error when saving username and password after the initial setup
- `Fixed` Clicks not recognized when using a mouse on a touchscreen-device (#345)

## v3.0.3

Released June 28, 2015

- `New` Skip duplicates on upload (#367, [How to activate](settings.md))
- `Fixed` Clicks not recognized when using a mouse on a touchscreen-device (#345)

## v3.0.2

Expand Down
6 changes: 4 additions & 2 deletions php/access/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,16 @@ private function upload() {
private function importUrl() {

Module::dependencies(isset($_POST['url'], $_POST['albumID']));
echo Import::url($_POST['url'], $_POST['albumID']);
$import = new Import($this->database, $this->plugins, $this->settings);
echo $import->url($_POST['url'], $_POST['albumID']);

}

private function importServer() {

Module::dependencies(isset($_POST['albumID'], $_POST['path']));
echo Import::server($_POST['albumID'], $_POST['path']);
$import = new Import($this->database, $this->plugins, $this->settings);
echo $import->server($_POST['path'], $_POST['albumID']);

}

Expand Down
1 change: 1 addition & 0 deletions php/database/settings_content.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ VALUES
('imagick','1'),
('dropboxKey',''),
('identifier',''),
('skipDuplicates','0'),
('plugins','');
8 changes: 0 additions & 8 deletions php/database/update_030001.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@
Log::error($database, 'update_030001', __LINE__, 'Could not update database (' . $database->error . ')');
return false;
}
} else {
$identifier = md5(microtime(true));
$query = Database::prepare($database, "UPDATE `?` SET `value` = '?' WHERE `key` = 'identifier' LIMIT 1", array(LYCHEE_TABLE_SETTINGS, $identifier));
$result = $database->query($query);
if (!$result) {
Log::error($database, 'update_030001', __LINE__, 'Could not reset public albums (' . $database->error . ')');
return false;
}
}

# Set version
Expand Down
8 changes: 8 additions & 0 deletions php/modules/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ static function createTables($database) {
return false;
}

# Generate identifier
$identifier = md5(microtime(true));
$query = Database::prepare($database, "UPDATE `?` SET `value` = '?' WHERE `key` = 'identifier' LIMIT 1", array(LYCHEE_TABLE_SETTINGS, $identifier));
if (!$database->query($query)) {
Log::error($database, __METHOD__, __LINE__, $database->error);
return false;
}

}

# Create albums
Expand Down
105 changes: 75 additions & 30 deletions php/modules/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,32 @@

class Import extends Module {

static function photo($database, $plugins, $settings, $path, $albumID = 0, $description = '', $tags = '') {
private $database = null;
private $settings = null;
private $albumIDs = null;

public function __construct($database, $plugins, $settings) {

# Init vars
$this->database = $database;
$this->plugins = $plugins;
$this->settings = $settings;

return true;

}

private function photo($path, $albumID = 0, $description = '', $tags = '') {

# Check dependencies
self::dependencies(isset($this->database, $this->plugins, $this->settings, $path));

# No need to validate photo type and extension in this function.
# $photo->add will take care of it.

$info = getimagesize($path);
$size = filesize($path);
$photo = new Photo($database, $plugins, $settings, null);
$photo = new Photo($this->database, $this->plugins, $this->settings, null);

$nameFile = array(array());
$nameFile[0]['name'] = $path;
Expand All @@ -25,79 +43,103 @@ static function photo($database, $plugins, $settings, $path, $albumID = 0, $desc
$nameFile[0]['error'] = 0;
$nameFile[0]['size'] = $size;

if (!$photo->add($nameFile, $albumID, $description, $tags)) return false;
if (!$photo->add($nameFile, $albumID, $description, $tags, true)) return false;
return true;

}

static function url($urls, $albumID = 0) {
public function url($urls, $albumID = 0) {

# Check dependencies
self::dependencies(isset($this->database, $urls));

# Call plugins
$this->plugins(__METHOD__, 0, func_get_args());

$error = false;

# Parse
# Parse URLs
$urls = str_replace(' ', '%20', $urls);
$urls = explode(',', $urls);

foreach ($urls as &$url) {

# Validate photo type and extension even when $this->photo (=> $photo->add) will do the same.
# This prevents us from downloading invalid photos.

# Verify extension
$extension = getExtension($url);
if (!in_array(strtolower($extension), Photo::$validExtensions, true)) {
$error = true;
Log::error($this->database, __METHOD__, __LINE__, 'Photo format not supported (' . $url . ')');
continue;
}

# Verify image
$type = @exif_imagetype($url);
if (!in_array($type, Photo::$validTypes, true)) {
$error = true;
Log::error($this->database, __METHOD__, __LINE__, 'Photo type not supported (' . $url . ')');
continue;
}

$pathinfo = pathinfo($url);
$filename = $pathinfo['filename'] . '.' . $pathinfo['extension'];
$tmp_name = LYCHEE_DATA . $filename;

if (@copy($url, $tmp_name)===false) $error = true;
if (@copy($url, $tmp_name)===false) {
$error = true;
Log::error($this->database, __METHOD__, __LINE__, 'Could not copy file (' . $tmp_name . ') to temp-folder (' . $tmp_name . ')');
continue;
}

# Import photo
if (!$this->photo($tmp_name, $albumID)) {
$error = true;
Log::error($this->database, __METHOD__, __LINE__, 'Could not import file: ' . $tmp_name);
continue;
}

}

$import = Import::server($albumID, LYCHEE_DATA);
# Call plugins
$this->plugins(__METHOD__, 1, func_get_args());

if ($error===false&&$import===true) return true;
else return false;
if ($error===false) return true;
return false;

}

static function server($albumID = 0, $path) {
public function server($path, $albumID = 0) {

global $database, $plugins, $settings;
# Check dependencies
self::dependencies(isset($this->database, $this->plugins, $this->settings));

# Parse path
if (!isset($path)) $path = LYCHEE_UPLOADS_IMPORT;
if (substr($path, -1)==='/') $path = substr($path, 0, -1);
if (!isset($path)) $path = LYCHEE_UPLOADS_IMPORT;
if (substr($path, -1)==='/') $path = substr($path, 0, -1);

if (is_dir($path)===false) {
Log::error($database, __METHOD__, __LINE__, 'Given path is not a directory (' . $path . ')');
Log::error($this->database, __METHOD__, __LINE__, 'Given path is not a directory (' . $path . ')');
return 'Error: Given path is not a directory!';
}

# Skip folders of Lychee
if ($path===LYCHEE_UPLOADS_BIG||($path . '/')===LYCHEE_UPLOADS_BIG||
$path===LYCHEE_UPLOADS_MEDIUM||($path . '/')===LYCHEE_UPLOADS_MEDIUM||
$path===LYCHEE_UPLOADS_THUMB||($path . '/')===LYCHEE_UPLOADS_THUMB) {
Log::error($database, __METHOD__, __LINE__, 'The given path is a reserved path of Lychee (' . $path . ')');
Log::error($this->database, __METHOD__, __LINE__, 'The given path is a reserved path of Lychee (' . $path . ')');
return 'Error: Given path is a reserved path of Lychee!';
}

$error = false;
$contains['photos'] = false;
$contains['albums'] = false;

# Invoke plugins directly, as instance method not valid here
# Call plugins
# Note that updated albumId and path explicitly passed, rather
# than using func_get_args() which will only return original ones
$plugins->activate(__METHOD__ . ":before", array($albumID, $path));
$this->plugins(__METHOD__, 0, array($albumID, $path));

# Get all files
$files = glob($path . '/*');
Expand All @@ -108,55 +150,58 @@ static function server($albumID = 0, $path) {
# the file may still be unreadable by the user
if (!is_readable($file)) {
$error = true;
Log::error($database, __METHOD__, __LINE__, 'Could not read file or directory: ' . $file);
Log::error($this->database, __METHOD__, __LINE__, 'Could not read file or directory: ' . $file);
continue;
}

if (@exif_imagetype($file)!==false) {

# Photo

if (!Import::photo($database, $plugins, $settings, $file, $albumID)) {
$contains['photos'] = true;

if (!$this->photo($file, $albumID)) {
$error = true;
Log::error($database, __METHOD__, __LINE__, 'Could not import file: ' . $file);
Log::error($this->database, __METHOD__, __LINE__, 'Could not import file: ' . $file);
continue;
}
$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);
$album = new Album($this->database, $this->plugins, $this->settings, null);
$newAlbumID = $album->add('[Import] ' . basename($file));
$contains['albums'] = true;

if ($newAlbumID===false) {
$error = true;
Log::error($database, __METHOD__, __LINE__, 'Could not create album in Lychee (' . $newAlbumID . ')');
Log::error($this->database, __METHOD__, __LINE__, 'Could not create album in Lychee (' . $newAlbumID . ')');
continue;
}

$import = Import::server($newAlbumID, $file . '/');
$import = $this->server($file . '/', $newAlbumID);

if ($import!==true&&$import!=='Notice: Import only contains albums!') {
$error = true;
Log::error($database, __METHOD__, __LINE__, 'Could not import folder. Function returned warning');
Log::error($this->database, __METHOD__, __LINE__, 'Could not import folder. Function returned warning.');
continue;
}

}

}

# Invoke plugins directly, as instance method not valid here
# Call plugins
# Note that updated albumId and path explicitly passed, rather
# than using func_get_args() which will only return original ones
$plugins->activate(__METHOD__ . ":after", array($albumID, $path));
$this->plugins(__METHOD__, 1, array($albumID, $path));

# The following returns will be caught in the front-end
if ($contains['photos']===false&&$contains['albums']===false) return 'Warning: Folder empty or no readable files to process!';
if ($contains['photos']===false&&$contains['albums']===true) return 'Notice: Import only contains albums!';
if ($contains['photos']===false&&$contains['albums']===true) return 'Notice: Import only contained albums!';

if ($error===true) return false;
return true;

}
Expand Down
Loading

0 comments on commit aee5d9b

Please sign in to comment.