Merge branch 'feed' into 2.1

This commit is contained in:
Tobias Reich 2014-02-09 22:30:56 +01:00
commit 91618c24e1
18 changed files with 604 additions and 556 deletions

View File

@ -345,9 +345,11 @@ build = {
break; break;
case "Tags": // Tags case "Tags": // Tags
infobox += "</table>"; if (forView!==true&&!lychee.publicMode) {
infobox += "<div class='separator'><h1>" + infos[index][0] + "</h1></div>"; infobox += "</table>";
infobox += "<div id='tags'>" + infos[index][1] + "</div>"; infobox += "<div class='separator'><h1>" + infos[index][0] + "</h1></div>";
infobox += "<div id='tags'>" + infos[index][1] + "</div>";
}
break; break;
default: // Item default: // Item

View File

@ -224,7 +224,7 @@ contextMenu = {
lychee.api("getAlbums", function(data) { lychee.api("getAlbums", function(data) {
if (!data.albums) { if (data.num===0) {
items = [["New Album", 0, "album.add()"]]; items = [["New Album", 0, "album.add()"]];
} else { } else {
$.each(data.content, function(index) { $.each(data.content, function(index) {

View File

@ -20,6 +20,7 @@ multiselect = {
if (mobileBrowser()) return false; if (mobileBrowser()) return false;
if (lychee.publicMode) return false; if (lychee.publicMode) return false;
if (visible.search()) return false;
if ($('.album:hover, .photo:hover').length!=0) return false; if ($('.album:hover, .photo:hover').length!=0) return false;
if (visible.multiselect()) $('#multiselect').remove(); if (visible.multiselect()) $('#multiselect').remove();

View File

@ -200,7 +200,7 @@ photo = {
}); });
params = "setAlbum&photoIDs=" + photoIDs + "&albumID=" + albumID; params = "setPhotoAlbum&photoIDs=" + photoIDs + "&albumID=" + albumID;
lychee.api(params, function(data) { lychee.api(params, function(data) {
if (data!==true) lychee.error(null, params, data); if (data!==true) lychee.error(null, params, data);
@ -355,7 +355,7 @@ photo = {
album.json.content[id].tags = tags; album.json.content[id].tags = tags;
}); });
params = "setTags&photoIDs=" + photoIDs + "&tags=" + tags; params = "setPhotoTags&photoIDs=" + photoIDs + "&tags=" + tags;
lychee.api(params, function(data) { lychee.api(params, function(data) {
if (data!==true) lychee.error(null, params, data); if (data!==true) lychee.error(null, params, data);

View File

@ -170,6 +170,7 @@ upload = {
}], }],
["Cancel", function() {}] ["Cancel", function() {}]
]; ];
modal.show("Import from Link", "Please enter the direct link to a photo to import it: <input class='text' type='text' placeholder='http://' value='http://'>", buttons); modal.show("Import from Link", "Please enter the direct link to a photo to import it: <input class='text' type='text' placeholder='http://' value='http://'>", buttons);
}, },
@ -194,10 +195,15 @@ upload = {
upload.close(); upload.close();
upload.notify("Import complete"); upload.notify("Import complete");
if (album.getID()===false) lychee.goto("0"); if (data==="Notice: Import only contains albums!") {
if (visible.albums()) lychee.load();
else lychee.goto("");
}
else if (album.getID()===false) lychee.goto("0");
else album.load(albumID); else album.load(albumID);
if (data==="Warning: Folder empty!") lychee.error("Folder empty. No photos imported!", params, data); if (data==="Notice: Import only contains albums!") return true;
else if (data==="Warning: Folder empty!") lychee.error("Folder empty. No photos imported!", params, data);
else if (data!==true) lychee.error(null, params, data); else if (data!==true) lychee.error(null, params, data);
}); });
@ -205,7 +211,8 @@ upload = {
}], }],
["Cancel", function() {}] ["Cancel", function() {}]
]; ];
modal.show("Import from Server", "This action will import all photos which are located in <b>'uploads/import/'</b> of your Lychee installation.", buttons);
modal.show("Import from Server", "This action will import all photos and albums which are located in <b>'uploads/import/'</b> of your Lychee installation.", buttons);
}, },

View File

@ -8,47 +8,52 @@
visible = { visible = {
albums: function() { albums: function() {
if ($("#tools_albums").css("display")==="block") return true; if ($('#tools_albums').css('display')==='block') return true;
else return false; else return false;
}, },
album: function() { album: function() {
if ($("#tools_album").css("display")==="block") return true; if ($('#tools_album').css('display')==='block') return true;
else return false; else return false;
}, },
photo: function() { photo: function() {
if ($("#imageview.fadeIn").length>0) return true; if ($('#imageview.fadeIn').length>0) return true;
else return false;
},
search: function() {
if (search.code!==null&&search.code!=='') return true;
else return false; else return false;
}, },
infobox: function() { infobox: function() {
if ($("#infobox.active").length>0) return true; if ($('#infobox.active').length>0) return true;
else return false; else return false;
}, },
controls: function() { controls: function() {
if (lychee.loadingBar.css("opacity")<1) return false; if (lychee.loadingBar.css('opacity')<1) return false;
else return true; else return true;
}, },
message: function() { message: function() {
if ($(".message").length>0) return true; if ($('.message').length>0) return true;
else return false; else return false;
}, },
signin: function() { signin: function() {
if ($(".message .sign_in").length>0) return true; if ($('.message .sign_in').length>0) return true;
else return false; else return false;
}, },
contextMenu: function() { contextMenu: function() {
if ($(".contextmenu").length>0) return true; if ($('.contextmenu').length>0) return true;
else return false; else return false;
}, },
multiselect: function() { multiselect: function() {
if ($("#multiselect").length>0) return true; if ($('#multiselect').length>0) return true;
else return false; else return false;
} }

View File

@ -1,13 +0,0 @@
### Import from server
To import photos from your server (photos you have uploaded via FTP to your server), sign in and click the add-icon on the top right. Then choose 'Import from Server'.
### Upload and share single photos
You can upload photos directly with every FTP client into Lychee. This feature helps you to share single images quickly with others.
1. Upload an image to `uploads/import/`
2. Navigate your browser to the place where Lychee is located (e.g. `http://example.com/view.php?p=filename.png`). `filename.png` must be replaced with the filename of your uploaded file.
3. Share the link.
Lychee will import the file as a public image, delete the original (unused) file and display it in the browser. [Sample FTP configuration &#187;](http://l.electerious.com/view.php?p=13657692738813)

155
php/access/admin.php Normal file
View File

@ -0,0 +1,155 @@
<?php
/**
* @name Admin Access
* @author Tobias Reich
* @copyright 2014 by Tobias Reich
*/
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
if (!defined('LYCHEE_ACCESS_ADMIN')) exit('Error: You are not allowed to access this area!');
switch ($_POST['function']) {
// Album Functions
case 'getAlbums': echo json_encode(getAlbums(false));
break;
case 'getAlbum': if (isset($_POST['albumID']))
echo json_encode(getAlbum($_POST['albumID']));
break;
case 'addAlbum': if (isset($_POST['title']))
echo addAlbum($_POST['title']);
break;
case 'setAlbumTitle': if (isset($_POST['albumIDs'])&&isset($_POST['title']))
echo setAlbumTitle($_POST['albumIDs'], $_POST['title']);
break;
case 'setAlbumDescription': if (isset($_POST['albumID'])&&isset($_POST['description']))
echo setAlbumDescription($_POST['albumID'], $_POST['description']);
break;
case 'setAlbumPublic': if (isset($_POST['albumID']))
if (!isset($_POST['password'])) $_POST['password'] = '';
echo setAlbumPublic($_POST['albumID'], $_POST['password']);
break;
case 'setAlbumPassword': if (isset($_POST['albumID'])&&isset($_POST['password']))
echo setAlbumPassword($_POST['albumID'], $_POST['password']);
break;
case 'deleteAlbum': if (isset($_POST['albumIDs']))
echo deleteAlbum($_POST['albumIDs']);
break;
// Photo Functions
case 'getPhoto': if (isset($_POST['photoID'])&&isset($_POST['albumID']))
echo json_encode(getPhoto($_POST['photoID'], $_POST['albumID']));
break;
case 'deletePhoto': if (isset($_POST['photoIDs']))
echo deletePhoto($_POST['photoIDs']);
break;
case 'setPhotoAlbum': if (isset($_POST['photoIDs'])&&isset($_POST['albumID']))
echo setPhotoAlbum($_POST['photoIDs'], $_POST['albumID']);
break;
case 'setPhotoTitle': if (isset($_POST['photoIDs'])&&isset($_POST['title']))
echo setPhotoTitle($_POST['photoIDs'], $_POST['title']);
break;
case 'setPhotoStar': if (isset($_POST['photoIDs']))
echo setPhotoStar($_POST['photoIDs']);
break;
case 'setPhotoPublic': if (isset($_POST['photoID'])&&isset($_POST['url']))
echo setPhotoPublic($_POST['photoID'], $_POST['url']);
break;
case 'setPhotoDescription': if (isset($_POST['photoID'])&&isset($_POST['description']))
echo setPhotoDescription($_POST['photoID'], $_POST['description']);
break;
case 'setPhotoTags': if (isset($_POST['photoIDs'])&&isset($_POST['tags']))
echo setPhotoTags($_POST['photoIDs'], $_POST['tags']);
break;
// Add Functions
case 'upload': if (isset($_FILES)&&isset($_POST['albumID']))
echo upload($_FILES, $_POST['albumID']);
break;
case 'importUrl': if (isset($_POST['url'])&&isset($_POST['albumID']))
echo importUrl($_POST['url'], $_POST['albumID']);
break;
case 'importServer': if (isset($_POST['albumID']))
echo importServer($_POST['albumID']);
break;
// Search Function
case 'search': if (isset($_POST['term']))
echo json_encode(search($_POST['term']));
break;
// Session Function
case 'init': echo json_encode(init('admin'));
break;
case 'login': if (isset($_POST['user'])&&isset($_POST['password']))
echo login($_POST['user'], $_POST['password']);
break;
case 'logout': logout();
break;
// Settings
case 'setLogin': if (isset($_POST['username'])&&isset($_POST['password']))
if (!isset($_POST['oldPassword'])) $_POST['oldPassword'] = '';
echo setLogin($_POST['oldPassword'], $_POST['username'], $_POST['password']);
break;
case 'setSorting': if (isset($_POST['type'])&&isset($_POST['order']))
echo setSorting($_POST['type'], $_POST['order']);
break;
// Miscellaneous
case 'update': echo update();
default: switch ($_GET['function']) {
case 'getFeed': if (isset($_GET['albumID']))
echo getFeed($_GET['albumID']);
break;
case 'getAlbumArchive': if (isset($_GET['albumID']))
getAlbumArchive($_GET['albumID']);
break;
case 'getPhotoArchive': if (isset($_GET['photoID']))
getPhotoArchive($_GET['photoID']);
break;
case 'update': echo update();
break;
default: exit('Error: Function not found! Please check the spelling of the called function.');
break;
}
break;
}
?>

126
php/access/guest.php Normal file
View File

@ -0,0 +1,126 @@
<?php
/**
* @name Guest Access (Public Mode)
* @author Tobias Reich
* @copyright 2014 by Tobias Reich
*/
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
if (!defined('LYCHEE_ACCESS_GUEST')) exit('Error: You are not allowed to access this area!');
switch ($_POST['function']) {
// Album Functions
case 'getAlbums': echo json_encode(getAlbums(true));
break;
case 'getAlbum': if (isset($_POST['albumID'])&&isset($_POST['password'])) {
if (isAlbumPublic($_POST['albumID'])) {
// Album Public
if (checkAlbumPassword($_POST['albumID'], $_POST['password']))
echo json_encode(getAlbum($_POST['albumID']));
else
echo 'Warning: Wrong password!';
} else {
// Album Private
echo 'Warning: Album private!';
}
}
break;
case 'checkAlbumAccess':if (isset($_POST['albumID'])&&isset($_POST['password'])) {
if (isAlbumPublic($_POST['albumID'])) {
// Album Public
if (checkAlbumPassword($_POST['albumID'], $_POST['password']))
echo true;
else
echo false;
} else {
// Album Private
echo false;
}
}
break;
// Photo Functions
case 'getPhoto': if (isset($_POST['photoID'])&&isset($_POST['albumID'])&&isset($_POST['password'])) {
if (isPhotoPublic($_POST['photoID'], $_POST['password']))
echo json_encode(getPhoto($_POST['photoID'], $_POST['albumID']));
else
echo 'Warning: Wrong password!';
}
break;
// Session Functions
case 'init': echo json_encode(init('public'));
break;
case 'login': if (isset($_POST['user'])&&isset($_POST['password']))
echo login($_POST['user'], $_POST['password']);
break;
// Miscellaneous
default: switch ($_GET['function']) {
case 'getFeed': if (isset($_GET['albumID'])&&isset($_GET['password'])) {
// Album Feed
if (isAlbumPublic($_GET['albumID'])) {
// Album Public
if (checkAlbumPassword($_GET['albumID'], $_GET['password']))
echo getFeed($_GET['albumID']);
else
exit('Warning: Wrong password!');
} else {
// Album Private
exit('Warning: Album private!');
}
}
break;
case 'getAlbumArchive': if (isset($_GET['albumID'])&&isset($_GET['password'])) {
// Album Download
if (isAlbumPublic($_GET['albumID'])) {
// Album Public
if (checkAlbumPassword($_GET['albumID'], $_GET['password']))
getAlbumArchive($_GET['albumID']);
else
exit('Warning: Wrong password!');
} else {
// Album Private
exit('Warning: Album private or not downloadable!');
}
}
break;
case 'getPhotoArchive': if (isset($_GET['photoID'])&&isset($_GET['password'])) {
// Photo Download
if (isPhotoPublic($_GET['photoID'], $_GET['password']))
// Photo Public
getPhotoArchive($_GET['photoID']);
else
// Photo Private
exit('Warning: Photo private or not downloadable!');
}
break;
default: exit('Error: Function not found! Please check the spelling of the called function.');
break;
}
break;
}
?>

View File

@ -0,0 +1,23 @@
<?php
/**
* @name Installation Access
* @author Tobias Reich
* @copyright 2014 by Tobias Reich
*/
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
if (!defined('LYCHEE_ACCESS_INSTALLATION')) exit('Error: You are not allowed to access this area!');
switch ($_POST['function']) {
case 'dbCreateConfig': if (isset($_POST['dbHost'])&&isset($_POST['dbUser'])&&isset($_POST['dbPassword'])&&isset($_POST['dbName']))
echo dbCreateConfig($_POST['dbHost'], $_POST['dbUser'], $_POST['dbPassword'], $_POST['dbName']);
break;
default: echo 'Warning: No configuration!';
break;
}
?>

View File

@ -3,7 +3,7 @@
/** /**
* @name API * @name API
* @author Tobias Reich * @author Tobias Reich
* @copyright 2014 by Philipp Maurer, Tobias Reich * @copyright 2014 by Tobias Reich
*/ */
@ini_set('max_execution_time', '200'); @ini_set('max_execution_time', '200');
@ -16,305 +16,68 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) {
session_start(); session_start();
define('LYCHEE', true); define('LYCHEE', true);
date_default_timezone_set('UTC');
// Load modules
require('modules/album.php');
require('modules/db.php'); require('modules/db.php');
require('modules/misc.php');
require('modules/photo.php');
require('modules/session.php'); require('modules/session.php');
require('modules/settings.php'); require('modules/settings.php');
require('modules/upload.php'); require('modules/upload.php');
require('modules/album.php');
require('modules/photo.php');
require('modules/tags.php');
require('modules/misc.php');
if (file_exists('../data/config.php')) require('../data/config.php'); if (file_exists('../data/config.php')) require('../data/config.php');
else { else {
/** /**
* Installation Mode * Installation Access
* Limited access to configure Lychee. Only available when the config.php file is missing. * Limited access to configure Lychee. Only available when the config.php file is missing.
*/ */
switch ($_POST['function']) { define('LYCHEE_ACCESS_INSTALLATION', true);
require('access/installation.php');
case 'dbCreateConfig': if (isset($_POST['dbHost'])&&isset($_POST['dbUser'])&&isset($_POST['dbPassword'])&&isset($_POST['dbName']))
echo dbCreateConfig($_POST['dbHost'], $_POST['dbUser'], $_POST['dbPassword'], $_POST['dbName']);
break;
default: echo 'Warning: No configuration!';
break;
}
exit(); exit();
} }
// Connect to DB // Connect and get settings
$database = dbConnect(); $database = dbConnect();
// Get Settings
$settings = getSettings(); $settings = getSettings();
// Escape // Escape
foreach(array_keys($_POST) as $key) $_POST[$key] = mysqli_real_escape_string($database, urldecode($_POST[$key])); foreach(array_keys($_POST) as $key) $_POST[$key] = mysqli_real_escape_string($database, urldecode($_POST[$key]));
foreach(array_keys($_GET) as $key) $_GET[$key] = mysqli_real_escape_string($database, urldecode($_GET[$key])); foreach(array_keys($_GET) as $key) $_GET[$key] = mysqli_real_escape_string($database, urldecode($_GET[$key]));
// Validate parameters // Validate parameters
if (isset($_POST['albumIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['albumIDs'])!==1) exit('Error: Wrong parameter type for albumIDs!'); if (isset($_POST['albumIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['albumIDs'])!==1) exit('Error: Wrong parameter type for albumIDs!');
if (isset($_POST['photoIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['photoIDs'])!==1) exit('Error: Wrong parameter type for photoIDs!'); if (isset($_POST['photoIDs'])&&preg_match('/^[0-9\,]{1,}$/', $_POST['photoIDs'])!==1) exit('Error: Wrong parameter type for photoIDs!');
if (isset($_POST['albumID'])&&preg_match('/^[0-9sf]{1,}$/', $_POST['albumID'])!==1) exit('Error: Wrong parameter type for albumID!'); if (isset($_POST['albumID'])&&preg_match('/^[0-9sf]{1,}$/', $_POST['albumID'])!==1) exit('Error: Wrong parameter type for albumID!');
if (isset($_POST['photoID'])&&preg_match('/^[0-9]{14}$/', $_POST['photoID'])!==1) exit('Error: Wrong parameter type for photoID!'); if (isset($_POST['photoID'])&&preg_match('/^[0-9]{14}$/', $_POST['photoID'])!==1) exit('Error: Wrong parameter type for photoID!');
// Fallback for switch statement
if (!isset($_POST['function'])) $_POST['function'] = '';
if (!isset($_GET['function'])) $_GET['function'] = '';
if (isset($_SESSION['login'])&&$_SESSION['login']==true) { if (isset($_SESSION['login'])&&$_SESSION['login']==true) {
/** /**
* Admin Mode * Admin Access
* Full access to Lychee. Only with correct password/session. * Full access to Lychee. Only with correct password/session.
*/ */
switch ($_POST['function']) { define('LYCHEE_ACCESS_ADMIN', true);
require('access/admin.php');
// Album Functions
case 'getAlbums': echo json_encode(getAlbums(false));
break;
case 'getAlbum': if (isset($_POST['albumID']))
echo json_encode(getAlbum($_POST['albumID']));
break;
case 'addAlbum': if (isset($_POST['title']))
echo addAlbum($_POST['title']);
break;
case 'setAlbumTitle': if (isset($_POST['albumIDs'])&&isset($_POST['title']))
echo setAlbumTitle($_POST['albumIDs'], $_POST['title']);
break;
case 'setAlbumDescription': if (isset($_POST['albumID'])&&isset($_POST['description']))
echo setAlbumDescription($_POST['albumID'], $_POST['description']);
break;
case 'setAlbumPublic': if (isset($_POST['albumID']))
if (!isset($_POST['password'])) $_POST['password'] = '';
echo setAlbumPublic($_POST['albumID'], $_POST['password']);
break;
case 'setAlbumPassword':if (isset($_POST['albumID'])&&isset($_POST['password']))
echo setAlbumPassword($_POST['albumID'], $_POST['password']);
break;
case 'deleteAlbum': if (isset($_POST['albumIDs']))
echo deleteAlbum($_POST['albumIDs']);
break;
// Photo Functions
case 'getPhoto': if (isset($_POST['photoID'])&&isset($_POST['albumID']))
echo json_encode(getPhoto($_POST['photoID'], $_POST['albumID']));
break;
case 'deletePhoto': if (isset($_POST['photoIDs']))
echo deletePhoto($_POST['photoIDs']);
break;
case 'setAlbum': if (isset($_POST['photoIDs'])&&isset($_POST['albumID']))
echo setAlbum($_POST['photoIDs'], $_POST['albumID']);
break;
case 'setPhotoTitle': if (isset($_POST['photoIDs'])&&isset($_POST['title']))
echo setPhotoTitle($_POST['photoIDs'], $_POST['title']);
break;
case 'setPhotoStar': if (isset($_POST['photoIDs']))
echo setPhotoStar($_POST['photoIDs']);
break;
case 'setPhotoPublic': if (isset($_POST['photoID'])&&isset($_POST['url']))
echo setPhotoPublic($_POST['photoID'], $_POST['url']);
break;
case 'setPhotoDescription': if (isset($_POST['photoID'])&&isset($_POST['description']))
echo setPhotoDescription($_POST['photoID'], $_POST['description']);
break;
// Add Functions
case 'upload': if (isset($_FILES)&&isset($_POST['albumID']))
echo upload($_FILES, $_POST['albumID']);
break;
case 'importUrl': if (isset($_POST['url'])&&isset($_POST['albumID']))
echo importUrl($_POST['url'], $_POST['albumID']);
break;
case 'importServer': if (isset($_POST['albumID']))
echo importServer($_POST['albumID']);
break;
// Search Function
case 'search': if (isset($_POST['term']))
echo json_encode(search($_POST['term']));
break;
// Tag Functions
case 'getTags': if (isset($_POST['photoID']))
echo json_encode(getTags($_POST['photoID']));
break;
case 'setTags': if (isset($_POST['photoIDs'])&&isset($_POST['tags']))
echo setTags($_POST['photoIDs'], $_POST['tags']);
break;
// Session Function
case 'init': echo json_encode(init('admin'));
break;
case 'login': if (isset($_POST['user'])&&isset($_POST['password']))
echo login($_POST['user'], $_POST['password']);
break;
case 'logout': logout();
break;
// Settings
case 'setLogin': if (isset($_POST['username'])&&isset($_POST['password']))
if (!isset($_POST['oldPassword'])) $_POST['oldPassword'] = '';
echo setLogin($_POST['oldPassword'], $_POST['username'], $_POST['password']);
break;
case 'setSorting': if (isset($_POST['type'])&&isset($_POST['order']))
echo setSorting($_POST['type'], $_POST['order']);
break;
// Miscellaneous
case 'update': echo update();
default: if (isset($_GET['function'])&&$_GET['function']=='getAlbumArchive'&&isset($_GET['albumID']))
// Album Download
getAlbumArchive($_GET['albumID']);
else if (isset($_GET['function'])&&$_GET['function']=='getPhotoArchive'&&isset($_GET['photoID']))
// Photo Download
getPhotoArchive($_GET['photoID']);
else if (isset($_GET['function'])&&$_GET['function']=='update')
// Update Lychee
echo update();
else
// Function unknown
exit('Error: Function not found! Please check the spelling of the called function.');
break;
}
} else { } else {
/** /**
* Public Mode * Guest Access
* Access to view all public folders and photos in Lychee. * Access to view all public folders and photos in Lychee.
*/ */
switch ($_POST['function']) { define('LYCHEE_ACCESS_GUEST', true);
require('access/guest.php');
// Album Functions
case 'getAlbums': echo json_encode(getAlbums(true));
break;
case 'getAlbum': if (isset($_POST['albumID'])&&isset($_POST['password'])) {
if (isAlbumPublic($_POST['albumID'])) {
// Album Public
if (checkAlbumPassword($_POST['albumID'], $_POST['password']))
echo json_encode(getAlbum($_POST['albumID']));
else
echo 'Warning: Wrong password!';
} else {
// Album Private
echo 'Warning: Album private!';
}
}
break;
case 'checkAlbumAccess':if (isset($_POST['albumID'])&&isset($_POST['password'])) {
if (isAlbumPublic($_POST['albumID'])) {
// Album Public
if (checkAlbumPassword($_POST['albumID'], $_POST['password']))
echo true;
else
echo false;
} else {
// Album Private
echo false;
}
}
break;
// Photo Functions
case 'getPhoto': if (isset($_POST['photoID'])&&isset($_POST['albumID'])&&isset($_POST['password'])) {
if (isPhotoPublic($_POST['photoID'], $_POST['password']))
echo json_encode(getPhoto($_POST['photoID'], $_POST['albumID']));
else
echo 'Warning: Wrong password!';
}
break;
// Session Functions
case 'init': echo json_encode(init('public'));
break;
case 'login': if (isset($_POST['user'])&&isset($_POST['password']))
echo login($_POST['user'], $_POST['password']);
break;
// Miscellaneous
default: if (isset($_GET['function'])&&$_GET['function']=='getAlbumArchive'&&isset($_GET['albumID'])&&isset($_GET['password'])) {
// Album Download
if (isAlbumPublic($_GET['albumID'])) {
// Album Public
if (checkAlbumPassword($_GET['albumID'], $_GET['password']))
getAlbumArchive($_GET['albumID']);
else
exit('Warning: Wrong password!');
} else {
// Album Private
exit('Warning: Album private or not downloadable!');
}
} else if (isset($_GET['function'])&&$_GET['function']=='getPhotoArchive'&&isset($_GET['photoID'])&&isset($_GET['password'])) {
// Photo Download
if (isPhotoPublic($_GET['photoID'], $_GET['password']))
// Photo Public
getPhotoArchive($_GET['photoID']);
else
// Photo Private
exit('Warning: Photo private or not downloadable!');
} else {
// Function unknown
exit('Error: Function not found! Please check the spelling of the called function.');
}
break;
}
} }

View File

@ -14,8 +14,9 @@ function addAlbum($title) {
global $database; global $database;
if (strlen($title)<1||strlen($title)>50) return false; if (strlen($title)<1||strlen($title)>50) return false;
$sysdate = date("d.m.Y");
$result = $database->query("INSERT INTO lychee_albums (title, sysdate) VALUES ('$title', '$sysdate');"); $sysdate = date("d.m.Y");
$result = $database->query("INSERT INTO lychee_albums (title, sysdate) VALUES ('$title', '$sysdate');");
if (!$result) return false; if (!$result) return false;
return $database->insert_id; return $database->insert_id;
@ -32,8 +33,10 @@ function getAlbums($public) {
// Albums // Albums
if ($public) $query = "SELECT * FROM lychee_albums WHERE public = 1"; if ($public) $query = "SELECT * FROM lychee_albums WHERE public = 1";
else $query = "SELECT * FROM lychee_albums"; else $query = "SELECT * FROM lychee_albums";
$result = $database->query($query) OR exit("Error: $result <br>".$database->error);
$i = 0; $result = $database->query($query) OR exit("Error: $result <br>".$database->error);
$i = 0;
while($row = $result->fetch_object()) { while($row = $result->fetch_object()) {
// Info // Info
@ -41,11 +44,14 @@ function getAlbums($public) {
$return["content"][$row->id]['title'] = $row->title; $return["content"][$row->id]['title'] = $row->title;
$return["content"][$row->id]['public'] = $row->public; $return["content"][$row->id]['public'] = $row->public;
$return["content"][$row->id]['sysdate'] = date('F Y', strtotime($row->sysdate)); $return["content"][$row->id]['sysdate'] = date('F Y', strtotime($row->sysdate));
// Password
if ($row->password=="") $return["content"][$row->id]['password'] = false; if ($row->password=="") $return["content"][$row->id]['password'] = false;
else $return["content"][$row->id]['password'] = true; else $return["content"][$row->id]['password'] = true;
// Thumbs // Thumbs
if (($public&&$row->password=="")||(!$public)) { if (($public&&$row->password=="")||(!$public)) {
$albumID = $row->id; $albumID = $row->id;
$result2 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = '$albumID' ORDER BY star DESC, " . substr($settings['sorting'], 9) . " LIMIT 0, 3"); $result2 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = '$albumID' ORDER BY star DESC, " . substr($settings['sorting'], 9) . " LIMIT 0, 3");
$k = 0; $k = 0;
@ -56,6 +62,7 @@ function getAlbums($public) {
if (!isset($return["content"][$row->id]["thumb0"])) $return["content"][$row->id]["thumb0"] = ""; if (!isset($return["content"][$row->id]["thumb0"])) $return["content"][$row->id]["thumb0"] = "";
if (!isset($return["content"][$row->id]["thumb1"])) $return["content"][$row->id]["thumb1"] = ""; if (!isset($return["content"][$row->id]["thumb1"])) $return["content"][$row->id]["thumb1"] = "";
if (!isset($return["content"][$row->id]["thumb2"])) $return["content"][$row->id]["thumb2"] = ""; if (!isset($return["content"][$row->id]["thumb2"])) $return["content"][$row->id]["thumb2"] = "";
} }
// Album count // Album count
@ -65,9 +72,6 @@ function getAlbums($public) {
$return["num"] = $i; $return["num"] = $i;
if ($i==0) $return["albums"] = false;
else $return["albums"] = true;
return $return; return $return;
} }
@ -77,8 +81,8 @@ function getSmartInfo() {
global $database, $settings; global $database, $settings;
// Unsorted // Unsorted
$result = $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = 0 " . $settings['sorting']); $result = $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = 0 " . $settings['sorting']);
$i = 0; $i = 0;
while($row = $result->fetch_object()) { while($row = $result->fetch_object()) {
if ($i<3) $return["unsortedThumb$i"] = $row->thumbUrl; if ($i<3) $return["unsortedThumb$i"] = $row->thumbUrl;
$i++; $i++;
@ -86,8 +90,8 @@ function getSmartInfo() {
$return['unsortedNum'] = $i; $return['unsortedNum'] = $i;
// Public // Public
$result2 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE public = 1 " . $settings['sorting']); $result2 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE public = 1 " . $settings['sorting']);
$i = 0; $i = 0;
while($row2 = $result2->fetch_object()) { while($row2 = $result2->fetch_object()) {
if ($i<3) $return["publicThumb$i"] = $row2->thumbUrl; if ($i<3) $return["publicThumb$i"] = $row2->thumbUrl;
$i++; $i++;
@ -95,8 +99,8 @@ function getSmartInfo() {
$return['publicNum'] = $i; $return['publicNum'] = $i;
// Starred // Starred
$result3 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE star = 1 " . $settings['sorting']); $result3 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE star = 1 " . $settings['sorting']);
$i = 0; $i = 0;
while($row3 = $result3->fetch_object()) { while($row3 = $result3->fetch_object()) {
if ($i<3) $return["starredThumb$i"] = $row3->thumbUrl; if ($i<3) $return["starredThumb$i"] = $row3->thumbUrl;
$i++; $i++;
@ -128,34 +132,33 @@ function getAlbum($albumID) {
default: $result = $database->query("SELECT * FROM lychee_albums WHERE id = '$albumID';"); default: $result = $database->query("SELECT * FROM lychee_albums WHERE id = '$albumID';");
$row = $result->fetch_object(); $row = $result->fetch_object();
$return['title'] = $row->title; $return['title'] = $row->title;
$return['description'] = $row->description; $return['description'] = $row->description;
$return['sysdate'] = date('d M. Y', strtotime($row->sysdate)); $return['sysdate'] = date('d M. Y', strtotime($row->sysdate));
$return['public'] = $row->public; $return['public'] = $row->public;
if ($row->password=="") $return['password'] = false; $return['password'] = ($row->password=="" ? false : true);
else $return['password'] = true;
$query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE album = '$albumID' " . $settings['sorting']; $query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE album = '$albumID' " . $settings['sorting'];
break; break;
} }
// Get photos // Get photos
$result = $database->query($query); $result = $database->query($query);
$previousPhotoID = ""; $previousPhotoID = "";
$i = 0; $i = 0;
while($row = $result->fetch_array()) { while($row = $result->fetch_array()) {
$return['content'][$row['id']]['id'] = $row['id']; $return['content'][$row['id']]['id'] = $row['id'];
$return['content'][$row['id']]['title'] = $row['title']; $return['content'][$row['id']]['title'] = $row['title'];
$return['content'][$row['id']]['sysdate'] = date('d F Y', strtotime($row['sysdate'])); $return['content'][$row['id']]['sysdate'] = date('d F Y', strtotime($row['sysdate']));
$return['content'][$row['id']]['public'] = $row['public']; $return['content'][$row['id']]['public'] = $row['public'];
$return['content'][$row['id']]['star'] = $row['star']; $return['content'][$row['id']]['star'] = $row['star'];
$return['content'][$row['id']]['tags'] = $row['tags']; $return['content'][$row['id']]['tags'] = $row['tags'];
$return['content'][$row['id']]['album'] = $row['album']; $return['content'][$row['id']]['album'] = $row['album'];
$return['content'][$row['id']]['thumbUrl'] = $row['thumbUrl']; $return['content'][$row['id']]['thumbUrl'] = $row['thumbUrl'];
$return['content'][$row['id']]['previousPhoto'] = $previousPhotoID; $return['content'][$row['id']]['previousPhoto'] = $previousPhotoID;
$return['content'][$row['id']]['nextPhoto'] = ""; $return['content'][$row['id']]['nextPhoto'] = "";
if ($previousPhotoID!="") $return['content'][$previousPhotoID]['nextPhoto'] = $row['id']; if ($previousPhotoID!="") $return['content'][$previousPhotoID]['nextPhoto'] = $row['id'];
$previousPhotoID = $row['id']; $previousPhotoID = $row['id'];
@ -171,20 +174,20 @@ function getAlbum($albumID) {
} else { } else {
// Enable next and previous for the first and last photo // Enable next and previous for the first and last photo
$lastElement = end($return['content']); $lastElement = end($return['content']);
$lastElementId = $lastElement['id']; $lastElementId = $lastElement['id'];
$firstElement = reset($return['content']); $firstElement = reset($return['content']);
$firstElementId = $firstElement['id']; $firstElementId = $firstElement['id'];
if ($lastElementId!==$firstElementId) { if ($lastElementId!==$firstElementId) {
$return['content'][$lastElementId]['nextPhoto'] = $firstElementId; $return['content'][$lastElementId]['nextPhoto'] = $firstElementId;
$return['content'][$firstElementId]['previousPhoto'] = $lastElementId; $return['content'][$firstElementId]['previousPhoto'] = $lastElementId;
} }
} }
$return['id'] = $albumID; $return['id'] = $albumID;
$return['num'] = $i; $return['num'] = $i;
return $return; return $return;
@ -219,8 +222,8 @@ function deleteAlbum($albumIDs) {
global $database; global $database;
$error = false; $error = false;
$result = $database->query("SELECT id FROM lychee_photos WHERE album IN ($albumIDs);"); $result = $database->query("SELECT id FROM lychee_photos WHERE album IN ($albumIDs);");
// Delete photos // Delete photos
while ($row = $result->fetch_object()) while ($row = $result->fetch_object())
@ -252,10 +255,10 @@ function getAlbumArchive($albumID) {
$zipTitle = "Unsorted"; $zipTitle = "Unsorted";
} }
$zip = new ZipArchive(); $zip = new ZipArchive();
$result = $database->query($query); $result = $database->query($query);
$files = array(); $files = array();
$i=0; $i = 0;
while($row = $result->fetch_object()) { while($row = $result->fetch_object()) {
$files[$i] = "../uploads/big/".$row->url; $files[$i] = "../uploads/big/".$row->url;
@ -293,15 +296,13 @@ function setAlbumPublic($albumID, $password) {
global $database; global $database;
$result = $database->query("SELECT public FROM lychee_albums WHERE id = '$albumID';"); $result = $database->query("SELECT public FROM lychee_albums WHERE id = '$albumID';");
$row = $result->fetch_object(); $row = $result->fetch_object();
if ($row->public == 0){ $public = ($row->public===0 ? 1 : 0);
$public = 1;
} else {
$public = 0;
}
$result = $database->query("UPDATE lychee_albums SET public = '$public', password = NULL WHERE id = '$albumID';"); $result = $database->query("UPDATE lychee_albums SET public = '$public', password = NULL WHERE id = '$albumID';");
if (!$result) return false; if (!$result) return false;
if ($public==1) { if ($public==1) {
$result = $database->query("UPDATE lychee_photos SET public = 0 WHERE album = '$albumID';"); $result = $database->query("UPDATE lychee_photos SET public = 0 WHERE album = '$albumID';");
if (!$result) return false; if (!$result) return false;
@ -327,8 +328,8 @@ function checkAlbumPassword($albumID, $password) {
global $database; global $database;
$result = $database->query("SELECT password FROM lychee_albums WHERE id = '$albumID';"); $result = $database->query("SELECT password FROM lychee_albums WHERE id = '$albumID';");
$row = $result->fetch_object(); $row = $result->fetch_object();
if ($row->password=="") return true; if ($row->password=="") return true;
else if ($row->password==$password) return true; else if ($row->password==$password) return true;
@ -340,8 +341,8 @@ function isAlbumPublic($albumID) {
global $database; global $database;
$result = $database->query("SELECT public FROM lychee_albums WHERE id = '$albumID';"); $result = $database->query("SELECT public FROM lychee_albums WHERE id = '$albumID';");
$row = $result->fetch_object(); $row = $result->fetch_object();
if ($row->public==1) return true; if ($row->public==1) return true;
return false; return false;

View File

@ -32,8 +32,8 @@ function dbConnect() {
function dbCreateConfig($dbHost = 'localhost', $dbUser, $dbPassword, $dbName = 'lychee') { function dbCreateConfig($dbHost = 'localhost', $dbUser, $dbPassword, $dbName = 'lychee') {
$dbPassword = urldecode($dbPassword); $dbPassword = urldecode($dbPassword);
$database = new mysqli($dbHost, $dbUser, $dbPassword); $database = new mysqli($dbHost, $dbUser, $dbPassword);
if ($database->connect_errno) return 'Warning: Connection failed!'; if ($database->connect_errno) return 'Warning: Connection failed!';
else { else {
@ -60,12 +60,9 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
?>"; ?>";
if (file_put_contents('../data/config.php', $config)===false) return 'Warning: Could not create file!'; if (file_put_contents('../data/config.php', $config)===false) return 'Warning: Could not create file!';
else {
$_SESSION['login'] = true;
$_SESSION['login'] = true; return true;
return true;
}
} }

View File

@ -12,29 +12,31 @@ if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
function openGraphHeader($photoID) { function openGraphHeader($photoID) {
global $database; global $database;
if (!is_numeric($photoID)) return false; $photoID = mysqli_real_escape_string($database, $photoID);
$result = $database->query("SELECT * FROM lychee_photos WHERE id = '$photoID';"); if (!is_numeric($photoID)) return false;
$row = $result->fetch_object();
$result = $database->query("SELECT * FROM lychee_photos WHERE id = '$photoID';");
$parseUrl = parse_url("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); $row = $result->fetch_object();
$picture = $parseUrl['scheme']."://".$parseUrl['host'].$parseUrl['path']."/../uploads/big/".$row->url;
$parseUrl = parse_url("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$picture = $parseUrl['scheme']."://".$parseUrl['host'].$parseUrl['path']."/../uploads/big/".$row->url;
$return = '<!-- General Meta Data -->'; $return = '<!-- General Meta Data -->';
$return .= '<meta name="title" content="'.$row->title.'" />'; $return .= '<meta name="title" content="'.$row->title.'" />';
$return .= '<meta name="description" content="'.$row->description.' - via Lychee" />'; $return .= '<meta name="description" content="'.$row->description.' - via Lychee" />';
$return .= '<link rel="image_src" type="image/jpeg" href="'.$picture.'" />'; $return .= '<link rel="image_src" type="image/jpeg" href="'.$picture.'" />';
$return .= '<!-- Twitter Meta Data -->'; $return .= '<!-- Twitter Meta Data -->';
$return .= '<meta name="twitter:card" content="photo">'; $return .= '<meta name="twitter:card" content="photo">';
$return .= '<meta name="twitter:title" content="'.$row->title.'">'; $return .= '<meta name="twitter:title" content="'.$row->title.'">';
$return .= '<meta name="twitter:image:src" content="'.$picture.'">'; $return .= '<meta name="twitter:image:src" content="'.$picture.'">';
$return .= '<!-- Facebook Meta Data -->'; $return .= '<!-- Facebook Meta Data -->';
$return .= '<meta property="og:title" content="'.$row->title.'">'; $return .= '<meta property="og:title" content="'.$row->title.'">';
$return .= '<meta property="og:image" content="'.$picture.'">'; $return .= '<meta property="og:image" content="'.$picture.'">';
return $return; return $return;
} }
@ -42,31 +44,35 @@ function search($term) {
global $database, $settings; global $database, $settings;
$return["albums"] = ""; $return['albums'] = '';
$result = $database->query("SELECT * FROM lychee_photos WHERE title like '%$term%' OR description like '%$term%' OR tags like '%$term%';"); // Photos
$result = $database->query("SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE title like '%$term%' OR description like '%$term%' OR tags like '%$term%';");
while($row = $result->fetch_array()) { while($row = $result->fetch_array()) {
$return['photos'][$row['id']] = $row; $return['photos'][$row['id']] = $row;
$return['photos'][$row['id']]['sysdate'] = date('d F Y', strtotime($row['sysdate'])); $return['photos'][$row['id']]['sysdate'] = date('d F Y', strtotime($row['sysdate']));
} }
// Albums
$result = $database->query("SELECT * FROM lychee_albums WHERE title like '%$term%' OR description like '%$term%';"); $result = $database->query("SELECT * FROM lychee_albums WHERE title like '%$term%' OR description like '%$term%';");
$i=0; $i = 0;
while($row = $result->fetch_object()) { while($row = $result->fetch_object()) {
$return["albums"][$row->id]['id'] = $row->id; // Info
$return["albums"][$row->id]['title'] = $row->title; $return['albums'][$row->id]['id'] = $row->id;
$return["albums"][$row->id]['public'] = $row->public; $return['albums'][$row->id]['title'] = $row->title;
$return["albums"][$row->id]['sysdate'] = date('F Y', strtotime($row->sysdate)); $return['albums'][$row->id]['public'] = $row->public;
if ($row->password=="") $return["albums"][$row->id]['password'] = false; $return['albums'][$row->id]['sysdate'] = date('F Y', strtotime($row->sysdate));
else $return["albums"][$row->id]['password'] = true; $return['albums'][$row->id]['password'] = ($row->password=='' ? false : true);
$result2 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = '" . $row->id . "' " . $settings['sorting'] . " LIMIT 0, 3;"); // Thumbs
$k = 0; $result2 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = '" . $row->id . "' " . $settings['sorting'] . " LIMIT 0, 3;");
$k = 0;
while($row2 = $result2->fetch_object()){ while($row2 = $result2->fetch_object()){
$return['albums'][$row->id]["thumb$k"] = $row2->thumbUrl; $return['albums'][$row->id]["thumb$k"] = $row2->thumbUrl;
$k++; $k++;
} }
$i++; $i++;
} }
@ -79,13 +85,13 @@ function update() {
global $database; global $database;
if(!$database->query("SELECT `public` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` ADD `public` TINYINT( 1 ) NOT NULL DEFAULT '0'"); if(!$database->query("SELECT `public` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` ADD `public` TINYINT( 1 ) NOT NULL DEFAULT '0'");
if(!$database->query("SELECT `password` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` ADD `password` VARCHAR( 100 ) NULL DEFAULT ''"); if(!$database->query("SELECT `password` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` ADD `password` VARCHAR( 100 ) NULL DEFAULT ''");
if(!$database->query("SELECT `description` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` ADD `description` VARCHAR( 1000 ) NULL DEFAULT ''"); if(!$database->query("SELECT `description` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` ADD `description` VARCHAR( 1000 ) NULL DEFAULT ''");
if($database->query("SELECT `password` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` CHANGE `password` `password` VARCHAR( 100 ) NULL DEFAULT ''"); if($database->query("SELECT `password` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` CHANGE `password` `password` VARCHAR( 100 ) NULL DEFAULT ''");
if($database->query("SELECT `description` FROM `lychee_photos` LIMIT 1;")) $database->query("ALTER TABLE `lychee_photos` CHANGE `description` `description` VARCHAR( 1000 ) NULL DEFAULT ''"); if($database->query("SELECT `description` FROM `lychee_photos` LIMIT 1;")) $database->query("ALTER TABLE `lychee_photos` CHANGE `description` `description` VARCHAR( 1000 ) NULL DEFAULT ''");
if(!$database->query("SELECT `tags` FROM `lychee_photos` LIMIT 1;")) $database->query("ALTER TABLE `lychee_photos` ADD `tags` VARCHAR( 1000 ) NULL DEFAULT ''"); if(!$database->query("SELECT `tags` FROM `lychee_photos` LIMIT 1;")) $database->query("ALTER TABLE `lychee_photos` ADD `tags` VARCHAR( 1000 ) NULL DEFAULT ''");
$database->query("UPDATE `lychee_photos` SET url = replace(url, 'uploads/big/', ''), thumbUrl = replace(thumbUrl, 'uploads/thumb/', '')"); $database->query("UPDATE `lychee_photos` SET url = replace(url, 'uploads/big/', ''), thumbUrl = replace(thumbUrl, 'uploads/thumb/', '')");
$result = $database->query("SELECT `value` FROM `lychee_settings` WHERE `key` = 'importFilename' LIMIT 1;"); $result = $database->query("SELECT `value` FROM `lychee_settings` WHERE `key` = 'importFilename' LIMIT 1;");

View File

@ -13,20 +13,7 @@ function getPhoto($photoID, $albumID) {
global $database; global $database;
if (!is_numeric($photoID)) { $query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
$result = $database->query("SELECT COUNT(*) AS quantity FROM lychee_photos WHERE import_name = '../uploads/import/$photoID';");
$row = $result->fetch_object();
if ($row->quantity == 0) {
importPhoto($photoID, 's');
}
if (is_file("../uploads/import/$photoID")) {
importPhoto($photoID, 's');
}
$query = "SELECT * FROM lychee_photos WHERE import_name = '../uploads/import/$photoID' ORDER BY ID DESC;";
} else {
$query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
}
$result = $database->query($query); $result = $database->query($query);
$return = $result->fetch_array(); $return = $result->fetch_array();
@ -40,9 +27,9 @@ function getPhoto($photoID, $albumID) {
} }
$return['original_album'] = $return['album']; $return['original_album'] = $return['album'];
$return['album'] = $albumID; $return['album'] = $albumID;
$return['sysdate'] = date('d M. Y', strtotime($return['sysdate'])); $return['sysdate'] = date('d M. Y', strtotime($return['sysdate']));
if (strlen($return['takedate'])>0) $return['takedate'] = date('d M. Y', strtotime($return['takedate'])); if (strlen($return['takedate'])>0) $return['takedate'] = date('d M. Y', strtotime($return['takedate']));
} }
@ -57,13 +44,9 @@ function setPhotoPublic($photoID, $url) {
global $database; global $database;
$result = $database->query("SELECT public FROM lychee_photos WHERE id = '$photoID';"); $result = $database->query("SELECT public FROM lychee_photos WHERE id = '$photoID';");
$row = $result->fetch_object(); $row = $result->fetch_object();
if ($row->public == 0){ $public = ($row->public==0 ? 1 : 0);
$public = 1;
} else {
$public = 0;
}
$result = $database->query("UPDATE lychee_photos SET public = '$public' WHERE id = '$photoID';"); $result = $database->query("UPDATE lychee_photos SET public = '$public' WHERE id = '$photoID';");
if (!$result) return false; if (!$result) return false;
@ -75,14 +58,12 @@ function setPhotoStar($photoIDs) {
global $database; global $database;
$error = false; $error = false;
$result = $database->query("SELECT id, star FROM lychee_photos WHERE id IN ($photoIDs);"); $result = $database->query("SELECT id, star FROM lychee_photos WHERE id IN ($photoIDs);");
while ($row = $result->fetch_object()) { while ($row = $result->fetch_object()) {
if ($row->star==0) $star = 1; $star = ($row->star==0 ? 1 : 0);
else $star = 0;
$star = $database->query("UPDATE lychee_photos SET star = '$star' WHERE id = '$row->id';"); $star = $database->query("UPDATE lychee_photos SET star = '$star' WHERE id = '$row->id';");
if (!$star) $error = true; if (!$star) $error = true;
@ -93,7 +74,7 @@ function setPhotoStar($photoIDs) {
} }
function setAlbum($photoIDs, $albumID) { function setPhotoAlbum($photoIDs, $albumID) {
global $database; global $database;
@ -122,6 +103,7 @@ function setPhotoDescription($photoID, $description) {
$description = htmlentities($description); $description = htmlentities($description);
if (strlen($description)>1000) return false; if (strlen($description)>1000) return false;
$result = $database->query("UPDATE lychee_photos SET description = '$description' WHERE id = '$photoID';"); $result = $database->query("UPDATE lychee_photos SET description = '$description' WHERE id = '$photoID';");
if (!$result) return false; if (!$result) return false;
@ -129,6 +111,23 @@ function setPhotoDescription($photoID, $description) {
} }
function setPhotoTags($photoIDs, $tags) {
global $database;
// Parse tags
$tags = preg_replace('/(\ ,\ )|(\ ,)|(,\ )|(,{1,}\ {0,})|(,$|^,)/', ',', $tags);
$tags = preg_replace('/,$|^,/', ',', $tags);
if (strlen($tags)>1000) return false;
$result = $database->query("UPDATE lychee_photos SET tags = '$tags' WHERE id IN ($photoIDs);");
if (!$result) return false;
return true;
}
function deletePhoto($photoIDs) { function deletePhoto($photoIDs) {
global $database; global $database;
@ -142,9 +141,9 @@ function deletePhoto($photoIDs) {
$thumbUrl2x = $thumbUrl2x[0] . '@2x.' . $thumbUrl2x[1]; $thumbUrl2x = $thumbUrl2x[0] . '@2x.' . $thumbUrl2x[1];
// Delete files // Delete files
if (!unlink('../uploads/big/' . $row->url)) return false; if (!unlink('../uploads/big/' . $row->url)) return false;
if (!unlink('../uploads/thumb/' . $row->thumbUrl)) return false; if (!unlink('../uploads/thumb/' . $row->thumbUrl)) return false;
if (!unlink('../uploads/thumb/' . $thumbUrl2x)) return false; if (!unlink('../uploads/thumb/' . $thumbUrl2x)) return false;
// Delete db entry // Delete db entry
$delete = $database->query("DELETE FROM lychee_photos WHERE id = $row->id;"); $delete = $database->query("DELETE FROM lychee_photos WHERE id = $row->id;");
@ -161,20 +160,18 @@ function isPhotoPublic($photoID, $password) {
global $database; global $database;
if (is_numeric($photoID)) { $query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
$query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
} else { $result = $database->query($query);
$query = "SELECT * FROM lychee_photos WHERE import_name = '../uploads/import/$photoID';"; $row = $result->fetch_object();
}
$result = $database->query($query);
$row = $result->fetch_object();
if (!is_numeric($photoID)&&!$row) return true; if (!is_numeric($photoID)&&!$row) return true;
if ($row->public==1) return true; if ($row->public==1) return true;
else { else {
$cAP = checkAlbumPassword($row->album, $password); $cAP = checkAlbumPassword($row->album, $password);
$iAP = isAlbumPublic($row->album); $iAP = isAlbumPublic($row->album);
if ($iAP&&$cAP) return true; if ($iAP&&$cAP) return true;
else return false; return false;
} }
} }
@ -183,8 +180,8 @@ function getPhotoArchive($photoID) {
global $database; global $database;
$result = $database->query("SELECT * FROM lychee_photos WHERE id = '$photoID';"); $result = $database->query("SELECT * FROM lychee_photos WHERE id = '$photoID';");
$row = $result->fetch_object(); $row = $result->fetch_object();
$extension = array_reverse(explode('.', $row->url)); $extension = array_reverse(explode('.', $row->url));

View File

@ -1,38 +0,0 @@
<?php
/**
* @name Album Module
* @author Tobias Reich
* @copyright 2014 by Philipp Maurer, Tobias Reich
*/
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
function getTags($photoID) {
global $database;
$result = $database->query("SELECT tags FROM lychee_photos WHERE id = '$photoID';");
$return = $result->fetch_array();
if (!$result) return false;
return $return;
}
function setTags($photoIDs, $tags) {
global $database;
// Parse tags
$tags = preg_replace('/(\ ,\ )|(\ ,)|(,\ )|(,{1,}\ {0,})|(,$|^,)/', ',', $tags);
$tags = preg_replace('/,$|^,/', ',', $tags);
if (strlen($tags)>1000) return false;
$result = $database->query("UPDATE lychee_photos SET tags = '$tags' WHERE id IN ($photoIDs);");
if (!$result) return false;
return true;
}

View File

@ -16,19 +16,19 @@ function upload($files, $albumID) {
switch($albumID) { switch($albumID) {
// s for public (share) // s for public (share)
case 's': case 's':
$public = 1; $public = 1;
$star = 0; $star = 0;
$albumID = 0; $albumID = 0;
break; break;
// f for starred (fav) // f for starred (fav)
case 'f': case 'f':
$star = 1; $star = 1;
$public = 0; $public = 0;
$albumID = 0; $albumID = 0;
break; break;
default: default:
$star = 0; $star = 0;
$public = 0; $public = 0;
} }
foreach ($files as $file) { foreach ($files as $file) {
@ -41,15 +41,15 @@ function upload($files, $albumID) {
$id = str_replace('.', '', microtime(true)); $id = str_replace('.', '', microtime(true));
while(strlen($id)<14) $id .= 0; while(strlen($id)<14) $id .= 0;
$tmp_name = $file['tmp_name']; $tmp_name = $file['tmp_name'];
$extension = array_reverse(explode('.', $file['name'])); $extension = array_reverse(explode('.', $file['name']));
$extension = $extension[0]; $extension = $extension[0];
$photo_name = md5($id) . ".$extension"; $photo_name = md5($id) . ".$extension";
// Import if not uploaded via web // Import if not uploaded via web
if (!is_uploaded_file($tmp_name)) { if (!is_uploaded_file($tmp_name)) {
if (copy($tmp_name, '../uploads/big/' . $photo_name)) { if (copy($tmp_name, '../uploads/big/' . $photo_name)) {
unlink($tmp_name); @unlink($tmp_name);
$import_name = $tmp_name; $import_name = $tmp_name;
} }
} else { } else {
@ -63,7 +63,7 @@ function upload($files, $albumID) {
// Use title of file if IPTC title missing // Use title of file if IPTC title missing
if ($info['title']===''&& if ($info['title']===''&&
$settings['importFilename']==='1') $settings['importFilename']==='1')
$info['title'] = mysqli_real_escape_string($database, substr(str_replace(".$extension", '', $file['name']), 0, 30)); $info['title'] = mysqli_real_escape_string($database, substr(basename($file['name'], ".$extension"), 0, 30));
// Set orientation based on EXIF data // Set orientation based on EXIF data
if ($file['type']==='image/jpeg'&&isset($info['orientation'])&&isset($info['width'])&&isset($info['height'])) { if ($file['type']==='image/jpeg'&&isset($info['orientation'])&&isset($info['width'])&&isset($info['height'])) {
@ -167,16 +167,16 @@ function getInfo($filename) {
global $database; global $database;
$url = '../uploads/big/' . $filename; $url = '../uploads/big/' . $filename;
$iptcArray = array(); $iptcArray = array();
$info = getimagesize($url, $iptcArray); $info = getimagesize($url, $iptcArray);
// General information // General information
$return['type'] = $info['mime']; $return['type'] = $info['mime'];
$return['width'] = $info[0]; $return['width'] = $info[0];
$return['height'] = $info[1]; $return['height'] = $info[1];
$return['date'] = date('d.m.Y', filectime($url)); $return['date'] = date('d.m.Y', filectime($url));
$return['time'] = date('H:i:s', filectime($url)); $return['time'] = date('H:i:s', filectime($url));
// Size // Size
$size = filesize($url)/1024; $size = filesize($url)/1024;
@ -184,8 +184,8 @@ function getInfo($filename) {
else $return['size'] = round($size, 1) . ' KB'; else $return['size'] = round($size, 1) . ' KB';
// IPTC Metadata Fallback // IPTC Metadata Fallback
$return['title'] = ''; $return['title'] = '';
$return['description'] = ''; $return['description'] = '';
// IPTC Metadata // IPTC Metadata
if(isset($iptcArray['APP13'])) { if(isset($iptcArray['APP13'])) {
@ -193,10 +193,10 @@ function getInfo($filename) {
$iptcInfo = iptcparse($iptcArray['APP13']); $iptcInfo = iptcparse($iptcArray['APP13']);
if (is_array($iptcInfo)) { if (is_array($iptcInfo)) {
$temp = $iptcInfo['2#105'][0]; $temp = @$iptcInfo['2#105'][0];
if (isset($temp)&&strlen($temp)>0) $return['title'] = $temp; if (isset($temp)&&strlen($temp)>0) $return['title'] = $temp;
$temp = $iptcInfo['2#120'][0]; $temp = @$iptcInfo['2#120'][0];
if (isset($temp)&&strlen($temp)>0) $return['description'] = $temp; if (isset($temp)&&strlen($temp)>0) $return['description'] = $temp;
} }
@ -204,46 +204,48 @@ function getInfo($filename) {
} }
// EXIF Metadata Fallback // EXIF Metadata Fallback
$return['orientation'] = ''; $return['orientation'] = '';
$return['iso'] = ''; $return['iso'] = '';
$return['aperture'] = ''; $return['aperture'] = '';
$return['make'] = ''; $return['make'] = '';
$return['model'] = ''; $return['model'] = '';
$return['shutter'] = ''; $return['shutter'] = '';
$return['focal'] = ''; $return['focal'] = '';
$return['takeDate'] = ''; $return['takeDate'] = '';
$return['takeTime'] = ''; $return['takeTime'] = '';
// Read EXIF
if ($info['mime']=='image/jpeg') $exif = exif_read_data($url, 'EXIF', 0);
else $exif = false;
// EXIF Metadata // EXIF Metadata
if ($info['mime']=='image/jpeg'&&function_exists('exif_read_data')&&@exif_read_data($url, 'EXIF', 0)) { if ($exif!==false) {
$exif = exif_read_data($url, 'EXIF', 0); $temp = @$exif['Orientation'];
$temp = $exif['Orientation'];
if (isset($temp)) $return['orientation'] = $temp; if (isset($temp)) $return['orientation'] = $temp;
$temp = $exif['ISOSpeedRatings']; $temp = @$exif['ISOSpeedRatings'];
if (isset($temp)) $return['iso'] = $temp; if (isset($temp)) $return['iso'] = $temp;
$temp = $exif['COMPUTED']['ApertureFNumber']; $temp = @$exif['COMPUTED']['ApertureFNumber'];
if (isset($temp)) $return['aperture'] = $temp; if (isset($temp)) $return['aperture'] = $temp;
$temp = $exif['Make']; $temp = @$exif['Make'];
if (isset($temp)) $return['make'] = $exif['Make']; if (isset($temp)) $return['make'] = $exif['Make'];
$temp = $exif['Model']; $temp = @$exif['Model'];
if (isset($temp)) $return['model'] = $temp; if (isset($temp)) $return['model'] = $temp;
$temp = $exif['ExposureTime']; $temp = @$exif['ExposureTime'];
if (isset($temp)) $return['shutter'] = $exif['ExposureTime'] . ' Sec.'; if (isset($temp)) $return['shutter'] = $exif['ExposureTime'] . ' Sec.';
$temp = $exif['FocalLength']; $temp = @$exif['FocalLength'];
if (isset($temp)) $return['focal'] = ($temp/1) . ' mm'; if (isset($temp)) $return['focal'] = ($temp/1) . ' mm';
$temp = $exif['DateTimeOriginal']; $temp = @$exif['DateTimeOriginal'];
if (isset($temp)) { if (isset($temp)) {
$exifDate = explode(' ', $temp); $exifDate = explode(' ', $temp);
$date = explode(':', $exifDate[0]); $date = explode(':', $exifDate[0]);
$return['takeDate'] = $date[2].'.'.$date[1].'.'.$date[0]; $return['takeDate'] = $date[2].'.'.$date[1].'.'.$date[0];
$return['takeTime'] = $exifDate[1]; $return['takeTime'] = $exifDate[1];
} }
@ -261,24 +263,24 @@ function createThumb($filename, $width = 200, $height = 200) {
global $settings; global $settings;
$url = "../uploads/big/$filename"; $url = "../uploads/big/$filename";
$info = getimagesize($url); $info = getimagesize($url);
$photoName = explode(".", $filename); $photoName = explode(".", $filename);
$newUrl = "../uploads/thumb/$photoName[0].jpeg"; $newUrl = "../uploads/thumb/$photoName[0].jpeg";
$newUrl2x = "../uploads/thumb/$photoName[0]@2x.jpeg"; $newUrl2x = "../uploads/thumb/$photoName[0]@2x.jpeg";
// Set position and size // Set position and size
$thumb = imagecreatetruecolor($width, $height); $thumb = imagecreatetruecolor($width, $height);
$thumb2x = imagecreatetruecolor($width*2, $height*2); $thumb2x = imagecreatetruecolor($width*2, $height*2);
if ($info[0]<$info[1]) { if ($info[0]<$info[1]) {
$newSize = $info[0]; $newSize = $info[0];
$startWidth = 0; $startWidth = 0;
$startHeight = $info[1]/2 - $info[0]/2; $startHeight = $info[1]/2 - $info[0]/2;
} else { } else {
$newSize = $info[1]; $newSize = $info[1];
$startWidth = $info[0]/2 - $info[1]/2; $startWidth = $info[0]/2 - $info[1]/2;
$startHeight = 0; $startHeight = 0;
} }
// Fallback for older version // Fallback for older version
@ -286,10 +288,10 @@ function createThumb($filename, $width = 200, $height = 200) {
// Create new image // Create new image
switch($info['mime']) { switch($info['mime']) {
case 'image/jpeg': $sourceImg = imagecreatefromjpeg($url); break; case 'image/jpeg': $sourceImg = imagecreatefromjpeg($url); break;
case 'image/png': $sourceImg = imagecreatefrompng($url); break; case 'image/png': $sourceImg = imagecreatefrompng($url); break;
case 'image/gif': $sourceImg = imagecreatefromgif($url); break; case 'image/gif': $sourceImg = imagecreatefromgif($url); break;
case 'image/webp': $sourceImg = imagecreatefromwebp($url); break; case 'image/webp': $sourceImg = imagecreatefromwebp($url); break;
default: return false; default: return false;
} }
@ -303,21 +305,19 @@ function createThumb($filename, $width = 200, $height = 200) {
} }
function importPhoto($name, $albumID = 0) { function importPhoto($path, $albumID = 0) {
$tmp_name = "../uploads/import/$name"; $info = getimagesize($path);
$info = getimagesize($tmp_name); $size = filesize($path);
$size = filesize($tmp_name);
$nameFile = array(array()); $nameFile = array(array());
$nameFile[0]['name'] = $name; $nameFile[0]['name'] = $path;
$nameFile[0]['type'] = $info['mime']; $nameFile[0]['type'] = $info['mime'];
$nameFile[0]['tmp_name'] = $tmp_name; $nameFile[0]['tmp_name'] = $path;
$nameFile[0]['error'] = 0; $nameFile[0]['error'] = 0;
$nameFile[0]['size'] = $size; $nameFile[0]['size'] = $size;
if (upload($nameFile, $albumID)) return true; return upload($nameFile, $albumID);
return false;
} }
@ -338,6 +338,7 @@ function importUrl($url, $albumID = 0) {
$pathinfo = pathinfo($key); $pathinfo = pathinfo($key);
$filename = $pathinfo['filename'].".".$pathinfo['extension']; $filename = $pathinfo['filename'].".".$pathinfo['extension'];
$tmp_name = "../uploads/import/$filename"; $tmp_name = "../uploads/import/$filename";
copy($key, $tmp_name); copy($key, $tmp_name);
} }
@ -357,7 +358,9 @@ function importUrl($url, $albumID = 0) {
$pathinfo = pathinfo($url); $pathinfo = pathinfo($url);
$filename = $pathinfo['filename'].".".$pathinfo['extension']; $filename = $pathinfo['filename'].".".$pathinfo['extension'];
$tmp_name = "../uploads/import/$filename"; $tmp_name = "../uploads/import/$filename";
copy($url, $tmp_name); copy($url, $tmp_name);
return importPhoto($filename, $albumID); return importPhoto($filename, $albumID);
} }
@ -368,23 +371,36 @@ function importUrl($url, $albumID = 0) {
} }
function importServer($albumID = 0) { function importServer($albumID = 0, $path = '../uploads/import/') {
global $database; global $database;
$i = 0; $files = glob($path . '*');
$files = glob('../uploads/import/*'); $contains['photos'] = false;
$contains['albums'] = false;
foreach ($files as $file) { foreach ($files as $file) {
if (@getimagesize($file)) { if (@getimagesize($file)) {
if (!importPhoto(basename($file), $albumID)) return false;
$i++; // Photo
if (!importPhoto($file, $albumID)) return false;
$contains['photos'] = true;
} else if (is_dir($file)) {
$name = mysqli_real_escape_string($database, basename($file));
$newAlbumID = addAlbum('[Import] ' . $name);
if ($newAlbumID!==false) importServer($newAlbumID, $file . '/');
$contains['albums'] = true;
} }
} }
if ($i===0) return "Warning: Folder empty!"; 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; return true;
} }

View File

@ -26,7 +26,7 @@ Sign in and click the gear on the top left corner to change your settings. If yo
### FTP Upload ### FTP Upload
You can import photos from your server or upload photos directly with every FTP client into Lychee. [FTP Upload &#187;](docs/md/FTP Upload.md) To import photos and albums located in `uploads/import/` (photos you have uploaded via FTP or else), sign in and click the add-icon on the top right. Then choose 'Import from Server'.
### Keyboard Shortcuts ### Keyboard Shortcuts