From 0c7d95fb15e78d19830c8e4d7f8f8c9cf78d50e6 Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Sun, 31 Jul 2016 15:53:34 +0200 Subject: [PATCH] Syntax adjustments --- php/Modules/Album.php | 2 +- php/database/update_030103.php | 21 ++++++++----- src/scripts/album.js | 56 +++++++++++++++++++--------------- src/scripts/albums.js | 2 +- src/scripts/contextMenu.js | 12 ++++---- src/scripts/multiselect.js | 2 +- src/scripts/settings.js | 2 +- src/scripts/sidebar.js | 20 +++++++----- src/scripts/view.js | 17 ++++++++--- 9 files changed, 78 insertions(+), 56 deletions(-) diff --git a/php/Modules/Album.php b/php/Modules/Album.php index b6cc211..06b40ab 100644 --- a/php/Modules/Album.php +++ b/php/Modules/Album.php @@ -282,7 +282,7 @@ final class Album { private function cleanZipName($name) { // Illicit chars - $badChars = array_merge( + $badChars = array_merge( array_map('chr', range(0,31)), array("<", ">", ":", '"', "/", "\\", "|", "?", "*") ); diff --git a/php/database/update_030103.php b/php/database/update_030103.php index ebacc15..b4cb5a0 100644 --- a/php/database/update_030103.php +++ b/php/database/update_030103.php @@ -8,14 +8,19 @@ use Lychee\Modules\Database; use Lychee\Modules\Response; // Add parent field to albums -$query = Database::prepare($connection, "SELECT `parent` FROM `?` LIMIT 1", array(LYCHEE_TABLE_ALBUMS)); -if (!Database::execute($connection, $query, "update_030103", __LINE__)) { - $query = Database::prepare($connection, "ALTER TABLE `?` ADD `parent` BIGINT(14) NOT NULL DEFAULT 0", array(LYCHEE_TABLE_ALBUMS)); - $result = Database::execute($connection, $query, "update_030103", __LINE__); - if (!$result) { - Log::error($database, 'update_030103', __LINE__, 'Could not update database (' . $database->error . ')'); - return false; - } +$query = Database::prepare($connection, "SELECT `parent` FROM `?` LIMIT 1", array(LYCHEE_TABLE_ALBUMS)); +$result = Database::execute($connection, $query, "update_030103", __LINE__); + +if ($result===false) { + + $query = Database::prepare($connection, "ALTER TABLE `?` ADD `parent` BIGINT(14) NOT NULL DEFAULT 0", array(LYCHEE_TABLE_ALBUMS)); + $result = Database::execute($connection, $query, "update_030103", __LINE__); + + if ($result===false) { + Log::error($database, 'update_030103', __LINE__, 'Could not update database (' . $database->error . ')'); + return false; + } + } // Set version diff --git a/src/scripts/album.js b/src/scripts/album.js index 66fe9b2..e8e43ad 100644 --- a/src/scripts/album.js +++ b/src/scripts/album.js @@ -12,7 +12,7 @@ album = { album.isSmartID = function(id) { - return id==='0' || id==='f' || id==='s' || id==='r' + return (id==='0' || id==='f' || id==='s' || id==='r') } @@ -21,7 +21,7 @@ album.getID = function() { let id = null let isID = (id) => { - if (album.isSmartID(id)) return true + if (album.isSmartID(id)===true) return true return $.isNumeric(id) } @@ -35,19 +35,18 @@ album.getID = function() { } if (isID(id)===true) return id - else return false + + return false } -album.getParent = function () { +album.getParent = function() { - let id = album.json.id; + let id = album.json.id - if (album.isSmartID(id) || album.json.parent==0) { - return '' - } else { - return album.json.parent - } + if (album.isSmartID(id)===true || album.json.parent==0) return '' + + return album.json.parent } @@ -109,7 +108,8 @@ album.load = function(albumID, refresh = false) { } } - if (!album.isSmartID(albumID)) { + if (album.isSmartID(albumID)===false) { + params = { parent: albumID } @@ -125,14 +125,14 @@ album.load = function(albumID, refresh = false) { if (durationTime>300) waitTime = 0 else waitTime = 300 - durationTime - setTimeout(() => { - finish() - }, waitTime) + setTimeout(finish, waitTime) }) - } - else { + + } else { + finish() + } }, waitTime) @@ -192,17 +192,22 @@ album.add = function(albumID = 0) { } - api.post('Albums::get', { - parent: -1 - }, function (data) { - var cmbxOptions = `' + api.post('Albums::get', { parent: -1 }, function(data) { + + let cmbxOptions = ` + + ` + + let msg = ` +

Enter a title for the new album:

+

Select the parent album:
${ cmbxOptions }

+ ` basicModal.show({ - body: `

Enter a title for the new album:

` - + `

Select the parent album:
` + cmbxOptions + `

`, + body: msg, buttons: { action: { title: 'Create Album', @@ -214,6 +219,7 @@ album.add = function(albumID = 0) { } } }) + }) } diff --git a/src/scripts/albums.js b/src/scripts/albums.js index 6bb7667..ff04974 100644 --- a/src/scripts/albums.js +++ b/src/scripts/albums.js @@ -17,7 +17,7 @@ albums.load = function() { if (albums.json===null) { - params = { + let params = { parent: 0 } diff --git a/src/scripts/contextMenu.js b/src/scripts/contextMenu.js index ba46ce0..66e09e1 100644 --- a/src/scripts/contextMenu.js +++ b/src/scripts/contextMenu.js @@ -134,7 +134,7 @@ contextMenu.albumTitle = function(albumID, e) { if (data.albums && data.num>1) { - items = buildAlbumList(data.albums, [albumID], (a) => lychee.goto(a.id)) + items = buildAlbumList(data.albums, [ albumID ], (a) => lychee.goto(a.id)) items.unshift({ }) @@ -168,14 +168,14 @@ contextMenu.mergeAlbum = function(albumID, e) { let title = selalbum.title // disable all parents; we cannot move them into us - let exclude = [albumID] + let exclude = [ albumID ] let a = getAlbumFrom(data.albums, selalbum.parent) while (a != null) { exclude.push(a.id) a = getAlbumFrom(data.albums, a.parent) } - items = buildAlbumList(data.albums, exclude, (a) => album.merge([ albumID, a.id ], [title, a.title])) + items = buildAlbumList(data.albums, exclude, (a) => album.merge([ albumID, a.id ], [ title, a.title ])) } @@ -232,7 +232,7 @@ contextMenu.photoMulti = function(photoIDs, e) { if (subcount && photocount) { $('.photo.active, .album.active').removeClass('active') multiselect.close() - lychee.error("Please select either albums or photos!") + lychee.error('Please select either albums or photos!') return } if (subcount) { @@ -272,7 +272,7 @@ contextMenu.photoTitle = function(albumID, photoID, e) { items.push({ }) - items = items.concat(buildAlbumList(data.content, [photoID], (a) => lychee.goto(albumID + '/' + a.id))) + items = items.concat(buildAlbumList(data.content, [ photoID ], (a) => lychee.goto(albumID + '/' + a.id))) } @@ -311,7 +311,7 @@ contextMenu.move = function(photoIDs, e) { } else { - items = buildAlbumList(data.albums, [album.getID()], (a) => photo.setAlbum(photoIDs, a.id)) + items = buildAlbumList(data.albums, [ album.getID() ], (a) => photo.setAlbum(photoIDs, a.id)) // Show Unsorted when unsorted is not the current album if (album.getID()!=='0') { diff --git a/src/scripts/multiselect.js b/src/scripts/multiselect.js index 5420f1d..d4855c5 100644 --- a/src/scripts/multiselect.js +++ b/src/scripts/multiselect.js @@ -199,7 +199,7 @@ multiselect.getSelection = function(e) { let id = $(this).data('id') - if (id!=null && id!==0 && !album.isSmartID(id)) { + if (id!=null && id!==0 && album.isSmartID(id)===false) { ids.push(id) $(this).addClass('active') diff --git a/src/scripts/settings.js b/src/scripts/settings.js index a28f84a..819b9d6 100644 --- a/src/scripts/settings.js +++ b/src/scripts/settings.js @@ -73,7 +73,7 @@ settings.createConfig = function() { if (data==='Warning: Could not create file!') { basicModal.show({ - body: "

Unable to save this configuration. Permission denied in 'data/'. Please set the read, write and execute rights for others in 'data/' and 'uploads/'. Take a look at the readme for more information.

", + body: `

Unable to save this configuration. Permission denied in 'data/'. Please set the read, write and execute rights for others in 'data/' and 'uploads/'. Take a look at the readme for more information.

`, buttons: { action: { title: 'Retry', diff --git a/src/scripts/sidebar.js b/src/scripts/sidebar.js index 48fb2a9..64daa99 100644 --- a/src/scripts/sidebar.js +++ b/src/scripts/sidebar.js @@ -125,14 +125,18 @@ sidebar.createStructure.photo = function(data) { // Set value for public switch (data.public) { - case '0' : _public = 'No' - break - case '1' : _public = 'Yes' - break - case '2' : _public = 'Yes (Album)' - break - default : _public = '-' - break + case '0': + _public = 'No' + break + case '1': + _public = 'Yes' + break + case '2': + _public = 'Yes (Album)' + break + default: + _public = '-' + break } diff --git a/src/scripts/view.js b/src/scripts/view.js index 447cfcc..ad1c3b6 100644 --- a/src/scripts/view.js +++ b/src/scripts/view.js @@ -178,18 +178,25 @@ view.album = { title: function(photoID) { + let ntitle = '' + let prefix = '' + if (album.json.content[photoID]) { - ntitle = album.json.content[photoID].title + prefix = '.photo' - } - else { + ntitle = album.json.content[photoID].title + + } else { + + prefix = '.album' + for (i in album.subjson.albums) { - if (album.subjson.albums[i].id == photoID) { + if (album.subjson.albums[i].id==photoID) { ntitle = album.subjson.albums[i].title break } } - prefix = '.album' + } ntitle = lychee.escapeHTML(ntitle)