From 11cfb939b56cd50ee7c9e1e54e973b4b99e14f1f Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Sun, 23 Feb 2014 22:42:15 +0100 Subject: [PATCH] Edit the Dropbox key (#84) --- assets/js/contextMenu.js | 9 ++++++--- assets/js/lychee.js | 20 ++++++++++++++------ assets/js/settings.js | 32 ++++++++++++++++++++++++++++++++ docs/md/Settings.md | 8 +++++++- php/access/admin.php | 4 ++++ php/api.php | 2 +- php/modules/settings.php | 12 ++++-------- readme.md | 4 ++++ 8 files changed, 72 insertions(+), 19 deletions(-) diff --git a/assets/js/contextMenu.js b/assets/js/contextMenu.js index 83114a0..b98f333 100644 --- a/assets/js/contextMenu.js +++ b/assets/js/contextMenu.js @@ -85,6 +85,7 @@ contextMenu = { contextMenu.fns = [ function() { settings.setLogin() }, function() { settings.setSorting() }, + function() { settings.setDropboxKey() }, function() { window.open(lychee.website, "_newtab"); }, function() { window.open("plugins/check.php", "_newtab"); }, function() { lychee.logout() } @@ -93,10 +94,12 @@ contextMenu = { items = [ [" Change Login", 0], [" Change Sorting", 1], - [" About Lychee", 2], - [" Diagnostics", 3], + [" Set Dropbox", 2], ["separator", -1], - [" Sign Out", 4] + [" About Lychee", 3], + [" Diagnostics", 4], + ["separator", -1], + [" Sign Out", 5] ]; contextMenu.show(items, mouse_x, mouse_y, "right"); diff --git a/assets/js/lychee.js b/assets/js/lychee.js index 0ca6d5d..5fc25b3 100644 --- a/assets/js/lychee.js +++ b/assets/js/lychee.js @@ -7,7 +7,7 @@ var lychee = { - version: "2.1 b4", + version: "2.1 b3", api_path: "php/api.php", update_path: "http://lychee.electerious.com/version/index.php", @@ -44,9 +44,9 @@ var lychee = { if (data.loggedIn!==true) { lychee.setMode("public"); } else { - lychee.username = data.config.username; - lychee.sorting = data.config.sorting; - lychee.dropboxKey = data.config.dropboxKey; + lychee.username = data.config.username || ''; + lychee.sorting = data.config.sorting || ''; + lychee.dropboxKey = data.config.dropboxKey || ''; } // No configuration @@ -294,7 +294,7 @@ var lychee = { loadDropbox: function(callback) { - if (!lychee.dropbox) { + if (!lychee.dropbox&&lychee.dropboxKey) { loadingBar.show(); @@ -315,7 +315,15 @@ var lychee = { }; s.parentNode.insertBefore(g, s); - } else callback(); + } else if (lychee.dropbox&&lychee.dropboxKey) { + + callback(); + + } else { + + settings.setDropboxKey(callback); + + }; }, diff --git a/assets/js/settings.js b/assets/js/settings.js index 34d0f01..7e97a5e 100644 --- a/assets/js/settings.js +++ b/assets/js/settings.js @@ -80,6 +80,7 @@ var settings = { }], ["", function() {}] ]; + modal.show("Configuration", "Enter your database connection details below:
Lychee will create its own database. If required, you can enter the name of an existing database instead:", buttons, -215, false); }, @@ -137,6 +138,7 @@ var settings = { }], ["", function() {}] ]; + modal.show("Create Login", "Enter a username and password for your installation: ", buttons, -122, false); }, @@ -181,6 +183,7 @@ var settings = { }], ["Cancel", function() {}] ]; + modal.show("Change Login", "Enter your current password:
Your username and password will be changed to the following: ", buttons, -171); }, @@ -233,6 +236,35 @@ var settings = { $("select#settings_order").val(sorting[1]); } + }, + + setDropboxKey: function(callback) { + + var buttons, + params, + key; + + buttons = [ + ["Set Key", function() { + + key = $(".message input.text#key").val(); + + params = "setDropboxKey&key=" + key; + lychee.api(params, function(data) { + + if (data===true) { + lychee.dropboxKey = key; + if (callback) lychee.loadDropbox(callback); + } else lychee.error(null, params, data); + + }); + + }], + ["Cancel", function() {}] + ]; + + modal.show("Set Dropbox Key", "In order to import photos from your Dropbox, you need a valid drop-ins app key from their website. Generate yourself a personal key and enter it below: ", buttons); + } } \ No newline at end of file diff --git a/docs/md/Settings.md b/docs/md/Settings.md index adc4c58..5c49c43 100644 --- a/docs/md/Settings.md +++ b/docs/md/Settings.md @@ -38,4 +38,10 @@ If `1`, Lychee will check if you are using the latest version. The notice will b sorting = ORDER BY [row] [ASC|DESC] -A typical part of a MySQL statement. This string will be appended to mostly every MySQL query. \ No newline at end of file +A typical part of a MySQL statement. This string will be appended to mostly every MySQL query. + +#### Dropbox Key + +This key is required to use the Dropbox import feature from your server. Lychee will ask you for this key, the first time you try to use the import. You can get your personal drop-ins app key from [their website](https://www.dropbox.com/developers/apps/create). + + dropboxKey = Your personal App Key \ No newline at end of file diff --git a/php/access/admin.php b/php/access/admin.php index b1e418f..b58536c 100644 --- a/php/access/admin.php +++ b/php/access/admin.php @@ -122,6 +122,10 @@ switch ($_POST['function']) { echo setSorting($_POST['type'], $_POST['order']); break; + case 'setDropboxKey': if (isset($_POST['key'])) + echo setDropboxKey($_POST['key']); + break; + // Miscellaneous default: switch ($_GET['function']) { diff --git a/php/api.php b/php/api.php index 9fefa3a..cfdfa08 100755 --- a/php/api.php +++ b/php/api.php @@ -58,7 +58,7 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) { // Fallback for switch statement if (!isset($_POST['function'])) $_POST['function'] = ''; if (!isset($_GET['function'])) $_GET['function'] = ''; - + if (isset($_SESSION['login'])&&$_SESSION['login']==true) { /** diff --git a/php/modules/settings.php b/php/modules/settings.php index e969ac6..dd8f8cf 100755 --- a/php/modules/settings.php +++ b/php/modules/settings.php @@ -66,22 +66,18 @@ function setPassword($password) { } -/*function setCheckForUpdates() { +function setDropboxKey($key) { global $database; - $result = $database->query("SELECT value FROM lychee_settings WHERE `key` = 'checkForUpdates';"); - $row = $result->fetch_object(); + if (strlen($key)<1||strlen($key)>50) return false; - if ($row->value==0) $checkForUpdates = 1; - else $checkForUpdates = 0; - - $result = $database->query("UPDATE lychee_settings SET value = '$checkForUpdates' WHERE `key` = 'checkForUpdates';"); + $result = $database->query("UPDATE lychee_settings SET value = '$key' WHERE `key` = 'dropboxKey';"); if (!$result) return false; return true; -}*/ +} function setSorting($type, $order) { diff --git a/readme.md b/readme.md index 98b9702..b27cb01 100644 --- a/readme.md +++ b/readme.md @@ -31,6 +31,10 @@ Lychee is ready to use, right out of the box. If you want to contribute and edit These shortcuts will help you to use Lychee even faster. [Keyboard Shortcuts »](docs/md/Keyboard Shortcuts.md) +### Dropbox import + +In order to use the Dropbox import from your server, you need a valid drop-ins app key from [their website](https://www.dropbox.com/developers/apps/create). Lychee will ask you for this key, the first time you try to use the import. Want to change your code? Take a loot at [the settings](docs/md/Settings.md) of Lychee. + ### Twitter Cards Lychee supports [Twitter Cards](https://dev.twitter.com/docs/cards) and [Open Graph](http://opengraphprotocol.org) for shared images (not albums). In order to use Twitter Cards you need to request an approval for your domain. Simply share an image with Lychee, copy its link and paste it in [Twitters Card Validator](https://dev.twitter.com/docs/cards/validation/validator).