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
if (forView!==true&&!lychee.publicMode) {
infobox += "</table>"; infobox += "</table>";
infobox += "<div class='separator'><h1>" + infos[index][0] + "</h1></div>"; infobox += "<div class='separator'><h1>" + infos[index][0] + "</h1></div>";
infobox += "<div id='tags'>" + infos[index][1] + "</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,43 +16,33 @@ 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
@ -65,256 +55,29 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) {
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,6 +14,7 @@ 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"); $sysdate = date("d.m.Y");
$result = $database->query("INSERT INTO lychee_albums (title, sysdate) VALUES ('$title', '$sysdate');"); $result = $database->query("INSERT INTO lychee_albums (title, sysdate) VALUES ('$title', '$sysdate');");
@ -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); $result = $database->query($query) OR exit("Error: $result <br>".$database->error);
$i = 0; $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;
} }
@ -132,8 +136,7 @@ function getAlbum($albumID) {
$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;
@ -295,13 +298,11 @@ function setAlbumPublic($albumID, $password) {
$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;

View File

@ -60,7 +60,6 @@ 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;
@ -69,8 +68,6 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
} }
}
function dbCreate($dbName, $database) { function dbCreate($dbName, $database) {
$result = $database->query("CREATE DATABASE IF NOT EXISTS $dbName;"); $result = $database->query("CREATE DATABASE IF NOT EXISTS $dbName;");

View File

@ -13,7 +13,9 @@ function openGraphHeader($photoID) {
global $database; global $database;
$photoID = mysqli_real_escape_string($database, $photoID);
if (!is_numeric($photoID)) return false; if (!is_numeric($photoID)) return false;
$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();
@ -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);
// Thumbs
$result2 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = '" . $row->id . "' " . $settings['sorting'] . " LIMIT 0, 3;"); $result2 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = '" . $row->id . "' " . $settings['sorting'] . " LIMIT 0, 3;");
$k = 0; $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++;
} }

View File

@ -13,20 +13,7 @@ function getPhoto($photoID, $albumID) {
global $database; global $database;
if (!is_numeric($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';"; $query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
}
$result = $database->query($query); $result = $database->query($query);
$return = $result->fetch_array(); $return = $result->fetch_array();
@ -59,11 +46,7 @@ function setPhotoPublic($photoID, $url) {
$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;
@ -80,9 +63,7 @@ function setPhotoStar($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;
@ -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 {
$query = "SELECT * FROM lychee_photos WHERE import_name = '../uploads/import/$photoID';";
}
$result = $database->query($query); $result = $database->query($query);
$row = $result->fetch_object(); $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;
} }
} }

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

@ -49,7 +49,7 @@ function upload($files, $albumID) {
// 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'])) {
@ -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;
} }
@ -214,33 +214,35 @@ function getInfo($filename) {
$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]);
@ -303,21 +305,19 @@ function createThumb($filename, $width = 200, $height = 200) {
} }
function importPhoto($name, $albumID = 0) { function importPhoto($path, $albumID = 0) {
$info = getimagesize($path);
$size = filesize($path);
$tmp_name = "../uploads/import/$name";
$info = getimagesize($tmp_name);
$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