Trim whitespace and spaces to tabs

This commit is contained in:
Tobias Reich 2014-02-17 17:01:46 +01:00
parent 9b8f626836
commit 05543793b0
11 changed files with 496 additions and 496 deletions

View File

@ -1,9 +1,9 @@
<?php <?php
/** /**
* @name Admin Access * @name Admin Access
* @author Tobias Reich * @author Tobias Reich
* @copyright 2014 by Tobias Reich * @copyright 2014 by Tobias Reich
*/ */
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!'); if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
@ -74,7 +74,7 @@ switch ($_POST['function']) {
case 'setPhotoDescription': if (isset($_POST['photoID'])&&isset($_POST['description'])) case 'setPhotoDescription': if (isset($_POST['photoID'])&&isset($_POST['description']))
echo setPhotoDescription($_POST['photoID'], $_POST['description']); echo setPhotoDescription($_POST['photoID'], $_POST['description']);
break; break;
case 'setPhotoTags': if (isset($_POST['photoIDs'])&&isset($_POST['tags'])) case 'setPhotoTags': if (isset($_POST['photoIDs'])&&isset($_POST['tags']))
echo setPhotoTags($_POST['photoIDs'], $_POST['tags']); echo setPhotoTags($_POST['photoIDs'], $_POST['tags']);
break; break;
@ -127,25 +127,25 @@ switch ($_POST['function']) {
case 'update': echo update(); case 'update': echo update();
default: switch ($_GET['function']) { default: switch ($_GET['function']) {
case 'getFeed': if (isset($_GET['albumID'])) case 'getFeed': if (isset($_GET['albumID']))
echo getFeed($_GET['albumID']); echo getFeed($_GET['albumID']);
break; break;
case 'getAlbumArchive': if (isset($_GET['albumID'])) case 'getAlbumArchive': if (isset($_GET['albumID']))
getAlbumArchive($_GET['albumID']); getAlbumArchive($_GET['albumID']);
break; break;
case 'getPhotoArchive': if (isset($_GET['photoID'])) case 'getPhotoArchive': if (isset($_GET['photoID']))
getPhotoArchive($_GET['photoID']); getPhotoArchive($_GET['photoID']);
break; break;
case 'update': echo update(); case 'update': echo update();
break; break;
default: exit('Error: Function not found! Please check the spelling of the called function.'); default: exit('Error: Function not found! Please check the spelling of the called function.');
break; break;
} }
break; break;

View File

@ -1,9 +1,9 @@
<?php <?php
/** /**
* @name Guest Access (Public Mode) * @name Guest Access (Public Mode)
* @author Tobias Reich * @author Tobias Reich
* @copyright 2014 by Tobias Reich * @copyright 2014 by Tobias Reich
*/ */
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!'); if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
@ -66,9 +66,9 @@ switch ($_POST['function']) {
// Miscellaneous // Miscellaneous
default: switch ($_GET['function']) { default: switch ($_GET['function']) {
case 'getFeed': if (isset($_GET['albumID'])&&isset($_GET['password'])) { case 'getFeed': if (isset($_GET['albumID'])&&isset($_GET['password'])) {
// Album Feed // Album Feed
if (isAlbumPublic($_GET['albumID'])) { if (isAlbumPublic($_GET['albumID'])) {
// Album Public // Album Public
@ -80,12 +80,12 @@ switch ($_POST['function']) {
// Album Private // Album Private
exit('Warning: Album private!'); exit('Warning: Album private!');
} }
} }
break; break;
case 'getAlbumArchive': if (isset($_GET['albumID'])&&isset($_GET['password'])) { case 'getAlbumArchive': if (isset($_GET['albumID'])&&isset($_GET['password'])) {
// Album Download // Album Download
if (isAlbumPublic($_GET['albumID'])) { if (isAlbumPublic($_GET['albumID'])) {
// Album Public // Album Public
@ -97,12 +97,12 @@ switch ($_POST['function']) {
// Album Private // Album Private
exit('Warning: Album private or not downloadable!'); exit('Warning: Album private or not downloadable!');
} }
} }
break; break;
case 'getPhotoArchive': if (isset($_GET['photoID'])&&isset($_GET['password'])) { case 'getPhotoArchive': if (isset($_GET['photoID'])&&isset($_GET['password'])) {
// Photo Download // Photo Download
if (isPhotoPublic($_GET['photoID'], $_GET['password'])) if (isPhotoPublic($_GET['photoID'], $_GET['password']))
// Photo Public // Photo Public
@ -110,15 +110,15 @@ switch ($_POST['function']) {
else else
// Photo Private // Photo Private
exit('Warning: Photo private or not downloadable!'); exit('Warning: Photo private or not downloadable!');
} }
break; break;
default: exit('Error: Function not found! Please check the spelling of the called function.'); default: exit('Error: Function not found! Please check the spelling of the called function.');
break; break;
} }
break; break;
} }

View File

@ -1,9 +1,9 @@
<?php <?php
/** /**
* @name Installation Access * @name Installation Access
* @author Tobias Reich * @author Tobias Reich
* @copyright 2014 by Tobias Reich * @copyright 2014 by Tobias Reich
*/ */
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!'); if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');

View File

@ -1,9 +1,9 @@
<?php <?php
/** /**
* @name API * @name API
* @author Tobias Reich * @author Tobias Reich
* @copyright 2014 by Tobias Reich * @copyright 2014 by Tobias Reich
*/ */
@ini_set('max_execution_time', '200'); @ini_set('max_execution_time', '200');
@ -26,7 +26,7 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) {
require('modules/session.php'); require('modules/session.php');
require('modules/settings.php'); require('modules/settings.php');
require('modules/upload.php'); require('modules/upload.php');
if (file_exists('../data/config.php')) require('../data/config.php'); if (file_exists('../data/config.php')) require('../data/config.php');
else { else {
@ -54,7 +54,7 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) {
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 // Fallback for switch statement
if (!isset($_POST['function'])) $_POST['function'] = ''; if (!isset($_POST['function'])) $_POST['function'] = '';
if (!isset($_GET['function'])) $_GET['function'] = ''; if (!isset($_GET['function'])) $_GET['function'] = '';
@ -65,7 +65,7 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) {
* Admin Access * Admin Access
* Full access to Lychee. Only with correct password/session. * Full access to Lychee. Only with correct password/session.
*/ */
define('LYCHEE_ACCESS_ADMIN', true); define('LYCHEE_ACCESS_ADMIN', true);
require('access/admin.php'); require('access/admin.php');

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* @name Album Module * @name Album Module
* @author Philipp Maurer * @author Philipp Maurer
* @author Tobias Reich * @author Tobias Reich
* @copyright 2014 by Philipp Maurer, Tobias Reich * @copyright 2014 by Philipp Maurer, Tobias Reich
*/ */
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!'); if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
@ -13,13 +13,13 @@ 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');");
if (!$result) return false; if (!$result) return false;
return $database->insert_id; return $database->insert_id;
} }
@ -27,52 +27,52 @@ function getAlbums($public) {
global $database, $settings; global $database, $settings;
// Smart Albums // Smart Albums
if (!$public) $return = getSmartInfo(); if (!$public) $return = getSmartInfo();
// Albums // Albums
if ($public) $query = "SELECT id, title, public, sysdate, password FROM lychee_albums WHERE public = 1"; if ($public) $query = "SELECT id, title, public, sysdate, password FROM lychee_albums WHERE public = 1";
else $query = "SELECT id, title, public, sysdate, password FROM lychee_albums"; else $query = "SELECT id, title, public, sysdate, password FROM lychee_albums";
$result = $database->query($query) OR exit("Error: $result <br>".$database->error);
$i = 0;
while($row = $result->fetch_object()) {
// Info $result = $database->query($query) OR exit("Error: $result <br>".$database->error);
$return["content"][$row->id]['id'] = $row->id; $i = 0;
$return["content"][$row->id]['title'] = $row->title;
$return["content"][$row->id]['public'] = $row->public;
$return["content"][$row->id]['sysdate'] = date('F Y', strtotime($row->sysdate));
// Password
if ($row->password=="") $return["content"][$row->id]['password'] = false;
else $return["content"][$row->id]['password'] = true;
// Thumbs while($row = $result->fetch_object()) {
if (($public&&$row->password=="")||(!$public)) {
$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");
$k = 0;
while($row2 = $result2->fetch_object()){
$return["content"][$row->id]["thumb$k"] = $row2->thumbUrl;
$k++;
}
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]["thumb2"])) $return["content"][$row->id]["thumb2"] = "";
}
// Album count // Info
$i++; $return["content"][$row->id]['id'] = $row->id;
$return["content"][$row->id]['title'] = $row->title;
$return["content"][$row->id]['public'] = $row->public;
$return["content"][$row->id]['sysdate'] = date('F Y', strtotime($row->sysdate));
} // Password
if ($row->password=="") $return["content"][$row->id]['password'] = false;
else $return["content"][$row->id]['password'] = true;
$return["num"] = $i; // Thumbs
if (($public&&$row->password=="")||(!$public)) {
return $return; $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");
$k = 0;
while($row2 = $result2->fetch_object()){
$return["content"][$row->id]["thumb$k"] = $row2->thumbUrl;
$k++;
}
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]["thumb2"])) $return["content"][$row->id]["thumb2"] = "";
}
// Album count
$i++;
}
$return["num"] = $i;
return $return;
} }
@ -81,33 +81,33 @@ 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++;
} }
$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++;
} }
$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++;
} }
$return['starredNum'] = $i; $return['starredNum'] = $i;
return $return; return $return;
} }
@ -118,27 +118,27 @@ function getAlbum($albumID) {
// Get album information // Get album information
switch($albumID) { switch($albumID) {
case "f": $return['public'] = false; case "f": $return['public'] = false;
$query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE star = 1 " . $settings['sorting']; $query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE star = 1 " . $settings['sorting'];
break;
case "s": $return['public'] = false;
$query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE public = 1 " . $settings['sorting'];
break;
case "0": $return['public'] = false;
$query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE album = 0 " . $settings['sorting'];
break; break;
default: $result = $database->query("SELECT * FROM lychee_albums WHERE id = '$albumID';"); case "s": $return['public'] = false;
$row = $result->fetch_object(); $query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE public = 1 " . $settings['sorting'];
$return['title'] = $row->title; break;
$return['description'] = $row->description;
$return['sysdate'] = date('d M. Y', strtotime($row->sysdate)); case "0": $return['public'] = false;
$return['public'] = $row->public; $query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE album = 0 " . $settings['sorting'];
$return['password'] = ($row->password=="" ? false : true); break;
$query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE album = '$albumID' " . $settings['sorting'];
break; default: $result = $database->query("SELECT * FROM lychee_albums WHERE id = '$albumID';");
$row = $result->fetch_object();
$return['title'] = $row->title;
$return['description'] = $row->description;
$return['sysdate'] = date('d M. Y', strtotime($row->sysdate));
$return['public'] = $row->public;
$return['password'] = ($row->password=="" ? false : true);
$query = "SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE album = '$albumID' " . $settings['sorting'];
break;
} }
@ -148,21 +148,21 @@ function getAlbum($albumID) {
$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'];
$i++; $i++;
} }
@ -197,22 +197,22 @@ function setAlbumTitle($albumIDs, $title) {
global $database; global $database;
if (strlen($title)<1||strlen($title)>50) return false; if (strlen($title)<1||strlen($title)>50) return false;
$result = $database->query("UPDATE lychee_albums SET title = '$title' WHERE id IN ($albumIDs);"); $result = $database->query("UPDATE lychee_albums SET title = '$title' WHERE id IN ($albumIDs);");
if (!$result) return false; if (!$result) return false;
return true; return true;
} }
function setAlbumDescription($albumID, $description) { function setAlbumDescription($albumID, $description) {
global $database; global $database;
$description = htmlentities($description); $description = htmlentities($description);
if (strlen($description)>1000) return false; if (strlen($description)>1000) return false;
$result = $database->query("UPDATE lychee_albums SET description = '$description' WHERE id = '$albumID';"); $result = $database->query("UPDATE lychee_albums SET description = '$description' WHERE id = '$albumID';");
if (!$result) return false; if (!$result) return false;
return true; return true;
@ -221,17 +221,17 @@ function setAlbumDescription($albumID, $description) {
function deleteAlbum($albumIDs) { 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())
if (!deletePhoto($row->id)) $error = true; if (!deletePhoto($row->id)) $error = true;
// Delete album // Delete album
$result = $database->query("DELETE FROM lychee_albums WHERE id IN ($albumIDs);"); $result = $database->query("DELETE FROM lychee_albums WHERE id IN ($albumIDs);");
if ($error||!$result) return false; if ($error||!$result) return false;
return true; return true;
@ -240,54 +240,54 @@ function deleteAlbum($albumIDs) {
function getAlbumArchive($albumID) { function getAlbumArchive($albumID) {
global $database; global $database;
switch($albumID) { switch($albumID) {
case 's': case 's':
$query = "SELECT url FROM lychee_photos WHERE public = '1';"; $query = "SELECT url FROM lychee_photos WHERE public = '1';";
$zipTitle = "Public"; $zipTitle = "Public";
break; break;
case 'f': case 'f':
$query = "SELECT url FROM lychee_photos WHERE star = '1';"; $query = "SELECT url FROM lychee_photos WHERE star = '1';";
$zipTitle = "Starred"; $zipTitle = "Starred";
break; break;
default: default:
$query = "SELECT url FROM lychee_photos WHERE album = '$albumID';"; $query = "SELECT url FROM lychee_photos WHERE album = '$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;
$i++; $i++;
} }
$result = $database->query("SELECT title FROM lychee_albums WHERE id = '$albumID' LIMIT 1;"); $result = $database->query("SELECT title FROM lychee_albums WHERE id = '$albumID' LIMIT 1;");
$row = $result->fetch_object(); $row = $result->fetch_object();
if ($albumID!=0&&is_numeric($albumID)) $zipTitle = $row->title; if ($albumID!=0&&is_numeric($albumID)) $zipTitle = $row->title;
$filename = "../data/$zipTitle.zip"; $filename = "../data/$zipTitle.zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
return false; return false;
} }
foreach($files AS $zipFile) { foreach($files AS $zipFile) {
$newFile = explode("/",$zipFile); $newFile = explode("/",$zipFile);
$newFile = array_reverse($newFile); $newFile = array_reverse($newFile);
$zip->addFile($zipFile, $zipTitle."/".$newFile[0]); $zip->addFile($zipFile, $zipTitle."/".$newFile[0]);
} }
$zip->close(); $zip->close();
header("Content-Type: application/zip"); header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=\"$zipTitle.zip\""); header("Content-Disposition: attachment; filename=\"$zipTitle.zip\"");
header("Content-Length: ".filesize($filename)); header("Content-Length: ".filesize($filename));
readfile($filename); readfile($filename);
unlink($filename); unlink($filename);
return true; return true;
} }
@ -299,10 +299,10 @@ 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();
$public = ($row->public=='0' ? 1 : 0); $public = ($row->public=='0' ? 1 : 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;
@ -330,7 +330,7 @@ function checkAlbumPassword($albumID, $password) {
$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;
return false; return false;
@ -340,7 +340,7 @@ function checkAlbumPassword($albumID, $password) {
function isAlbumPublic($albumID) { 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();

View File

@ -1,32 +1,32 @@
<?php <?php
/** /**
* @name DB Module * @name DB Module
* @author Philipp Maurer * @author Philipp Maurer
* @author Tobias Reich * @author Tobias Reich
* @copyright 2014 by Philipp Maurer, Tobias Reich * @copyright 2014 by Philipp Maurer, Tobias Reich
*/ */
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!'); if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
function dbConnect() { function dbConnect() {
global $dbUser, $dbPassword, $dbHost, $dbName; global $dbUser, $dbPassword, $dbHost, $dbName;
$database = new mysqli($dbHost, $dbUser, $dbPassword); $database = new mysqli($dbHost, $dbUser, $dbPassword);
if ($database->connect_errno) exit('Error: ' . $database->connect_error);
if ($database->connect_errno) exit('Error: ' . $database->connect_error);
// Avoid sql injection on older MySQL versions // Avoid sql injection on older MySQL versions
if ($database->server_version<50500) $database->set_charset('GBK'); if ($database->server_version<50500) $database->set_charset('GBK');
if (!$database->select_db($dbName)) if (!$database->select_db($dbName))
if (!dbCreate($dbName, $database)) exit('Error: Could not create database!'); if (!dbCreate($dbName, $database)) exit('Error: Could not create database!');
if (!$database->query('SELECT * FROM lychee_photos, lychee_albums, lychee_settings LIMIT 0;')) if (!$database->query('SELECT * FROM lychee_photos, lychee_albums, lychee_settings LIMIT 0;'))
if (!dbCreateTables($database)) exit('Error: Could not create tables!'); if (!dbCreateTables($database)) exit('Error: Could not create tables!');
return $database; return $database;
} }
@ -41,9 +41,9 @@ function dbCreateConfig($dbHost = 'localhost', $dbUser, $dbPassword, $dbName = '
$config = "<?php $config = "<?php
/** /**
* @name Config * @name Config
* @author Tobias Reich * @author Tobias Reich
* @copyright 2014 by Philipp Maurer, Tobias Reich * @copyright 2014 by Philipp Maurer, Tobias Reich
*/ */
if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!'); if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
@ -60,7 +60,7 @@ 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!';
$_SESSION['login'] = true; $_SESSION['login'] = true;
return true; return true;
@ -125,11 +125,11 @@ function dbCreateTables($database) {
"; ";
if (!$database->query($query)) return false; if (!$database->query($query)) return false;
} }
if (!$database->query('SELECT * FROM lychee_photos LIMIT 0;')) { if (!$database->query('SELECT * FROM lychee_photos LIMIT 0;')) {
$query = " $query = "
@ -163,11 +163,11 @@ function dbCreateTables($database) {
"; ";
if (!$database->query($query)) return false; if (!$database->query($query)) return false;
} }
return true; return true;
} }
@ -175,9 +175,9 @@ function dbClose() {
global $database; global $database;
if (!$database->close()) exit('Error: Closing the connection failed!'); if (!$database->close()) exit('Error: Closing the connection failed!');
return true; return true;
} }

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* @name Misc Module * @name Misc Module
* @author Philipp Maurer * @author Philipp Maurer
* @author Tobias Reich * @author Tobias Reich
* @copyright 2014 by Philipp Maurer, Tobias Reich * @copyright 2014 by Philipp Maurer, Tobias Reich
*/ */
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!'); if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
@ -12,30 +12,30 @@ if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
function openGraphHeader($photoID) { function openGraphHeader($photoID) {
global $database; global $database;
$photoID = mysqli_real_escape_string($database, $photoID); $photoID = mysqli_real_escape_string($database, $photoID);
if (!is_numeric($photoID)) return false; if (!is_numeric($photoID)) return false;
$result = $database->query("SELECT title, description, url FROM lychee_photos WHERE id = '$photoID';"); $result = $database->query("SELECT title, description, url FROM lychee_photos WHERE id = '$photoID';");
$row = $result->fetch_object(); $row = $result->fetch_object();
$parseUrl = parse_url("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); $parseUrl = parse_url("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$picture = $parseUrl['scheme']."://".$parseUrl['host'].$parseUrl['path']."/../uploads/big/".$row->url; $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;
} }
@ -47,37 +47,37 @@ function search($term) {
$return['albums'] = ''; $return['albums'] = '';
// Photos // 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%';"); $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 // Albums
$result = $database->query("SELECT id, title, public, sysdate, password FROM lychee_albums WHERE title like '%$term%' OR description like '%$term%';"); $result = $database->query("SELECT id, title, public, sysdate, password 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()) {
// Info // Info
$return['albums'][$row->id]['id'] = $row->id; $return['albums'][$row->id]['id'] = $row->id;
$return['albums'][$row->id]['title'] = $row->title; $return['albums'][$row->id]['title'] = $row->title;
$return['albums'][$row->id]['public'] = $row->public; $return['albums'][$row->id]['public'] = $row->public;
$return['albums'][$row->id]['sysdate'] = date('F Y', strtotime($row->sysdate)); $return['albums'][$row->id]['sysdate'] = date('F Y', strtotime($row->sysdate));
$return['albums'][$row->id]['password'] = ($row->password=='' ? false : true); $return['albums'][$row->id]['password'] = ($row->password=='' ? false : true);
// Thumbs // 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++;
return $return; }
return $return;
} }
@ -85,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/', '')");
return true; return true;

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* @name Photo Module * @name Photo Module
* @author Philipp Maurer * @author Philipp Maurer
* @author Tobias Reich * @author Tobias Reich
* @copyright 2014 by Philipp Maurer, Tobias Reich * @copyright 2014 by Philipp Maurer, Tobias Reich
*/ */
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!'); if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
@ -14,29 +14,29 @@ function getPhoto($photoID, $albumID) {
global $database; global $database;
$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();
if ($albumID!='false') { if ($albumID!='false') {
if ($return['album']!=0) { if ($return['album']!=0) {
$result = $database->query("SELECT public FROM lychee_albums WHERE id = '" . $return['album'] . "';"); $result = $database->query("SELECT public FROM lychee_albums WHERE id = '" . $return['album'] . "';");
$return_album = $result->fetch_array(); $return_album = $result->fetch_array();
if ($return_album['public']=="1") $return['public'] = "2"; if ($return_album['public']=="1") $return['public'] = "2";
} }
$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']));
} }
unset($return['album_public']); unset($return['album_public']);
return $return; return $return;
} }
@ -44,33 +44,33 @@ 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();
$public = ($row->public==0 ? 1 : 0); $public = ($row->public==0 ? 1 : 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;
return true; return true;
} }
function setPhotoStar($photoIDs) { 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()) {
$star = ($row->star==0 ? 1 : 0); $star = ($row->star==0 ? 1 : 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;
} }
if ($error) return false; if ($error) return false;
return true; return true;
} }
@ -78,10 +78,10 @@ function setPhotoAlbum($photoIDs, $albumID) {
global $database; global $database;
$result = $database->query("UPDATE lychee_photos SET album = '$albumID' WHERE id IN ($photoIDs);"); $result = $database->query("UPDATE lychee_photos SET album = '$albumID' WHERE id IN ($photoIDs);");
if (!$result) return false; if (!$result) return false;
return true; return true;
} }
@ -89,11 +89,11 @@ function setPhotoTitle($photoIDs, $title) {
global $database; global $database;
if (strlen($title)>50) return false; if (strlen($title)>50) return false;
$result = $database->query("UPDATE lychee_photos SET title = '$title' WHERE id IN ($photoIDs);"); $result = $database->query("UPDATE lychee_photos SET title = '$title' WHERE id IN ($photoIDs);");
if (!$result) return false; if (!$result) return false;
return true; return true;
} }
@ -101,24 +101,24 @@ function setPhotoDescription($photoID, $description) {
global $database; global $database;
$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';");
if (!$result) return false; $result = $database->query("UPDATE lychee_photos SET description = '$description' WHERE id = '$photoID';");
return true;
if (!$result) return false;
return true;
} }
function setPhotoTags($photoIDs, $tags) { function setPhotoTags($photoIDs, $tags) {
global $database; global $database;
// Parse tags // Parse tags
$tags = preg_replace('/(\ ,\ )|(\ ,)|(,\ )|(,{1,}\ {0,})|(,$|^,)/', ',', $tags); $tags = preg_replace('/(\ ,\ )|(\ ,)|(,\ )|(,{1,}\ {0,})|(,$|^,)/', ',', $tags);
$tags = preg_replace('/,$|^,/', ',', $tags); $tags = preg_replace('/,$|^,/', ',', $tags);
if (strlen($tags)>1000) return false; if (strlen($tags)>1000) return false;
$result = $database->query("UPDATE lychee_photos SET tags = '$tags' WHERE id IN ($photoIDs);"); $result = $database->query("UPDATE lychee_photos SET tags = '$tags' WHERE id IN ($photoIDs);");
@ -131,26 +131,26 @@ function setPhotoTags($photoIDs, $tags) {
function deletePhoto($photoIDs) { function deletePhoto($photoIDs) {
global $database; global $database;
$result = $database->query("SELECT id, url, thumbUrl FROM lychee_photos WHERE id IN ($photoIDs);"); $result = $database->query("SELECT id, url, thumbUrl FROM lychee_photos WHERE id IN ($photoIDs);");
while ($row = $result->fetch_object()) { while ($row = $result->fetch_object()) {
// Get retina thumb url // Get retina thumb url
$thumbUrl2x = explode(".", $row->thumbUrl); $thumbUrl2x = explode(".", $row->thumbUrl);
$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;");
if (!$delete) return false; if (!$delete) return false;
} }
if (!$result) return false; if (!$result) return false;
return true; return true;
@ -162,16 +162,16 @@ function isPhotoPublic($photoID, $password) {
$query = "SELECT public, album FROM lychee_photos WHERE id = '$photoID';"; $query = "SELECT public, album FROM lychee_photos WHERE id = '$photoID';";
$result = $database->query($query); $result = $database->query($query);
$row = $result->fetch_object(); $row = $result->fetch_object();
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;
return false; return false;
} }
} }

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* @name Session Module * @name Session Module
* @author Philipp Maurer * @author Philipp Maurer
* @author Tobias Reich * @author Tobias Reich
* @copyright 2014 by Philipp Maurer, Tobias Reich * @copyright 2014 by Philipp Maurer, Tobias Reich
*/ */
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!'); if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
@ -39,16 +39,16 @@ function login($username, $password) {
global $database, $settings; global $database, $settings;
// Check login // Check login
if ($username===$settings['username']&&$password===$settings['password']) { if ($username===$settings['username']&&$password===$settings['password']) {
$_SESSION['login'] = true; $_SESSION['login'] = true;
return true; return true;
} }
// No login // No login
if ($settings['username']===''&&$settings['password']==='') { if ($settings['username']===''&&$settings['password']==='') {
$_SESSION['login'] = true; $_SESSION['login'] = true;
return true; return true;
} }
return false; return false;
@ -56,8 +56,8 @@ function login($username, $password) {
function logout() { function logout() {
session_destroy(); session_destroy();
return true; return true;
} }

View File

@ -1,9 +1,9 @@
<?php <?php
/** /**
* @name Settings Module * @name Settings Module
* @author Tobias Reich * @author Tobias Reich
* @copyright 2014 by Tobias Reich * @copyright 2014 by Tobias Reich
*/ */
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!'); if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
@ -15,7 +15,7 @@ function getSettings() {
$result = $database->query('SELECT * FROM lychee_settings;'); $result = $database->query('SELECT * FROM lychee_settings;');
while($row = $result->fetch_object()) { while($row = $result->fetch_object()) {
$return[$row->key] = $row->value; $return[$row->key] = $row->value;
} }
return $return; return $return;

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* @name Upload Module * @name Upload Module
* @author Philipp Maurer * @author Philipp Maurer
* @author Tobias Reich * @author Tobias Reich
* @copyright 2014 by Philipp Maurer, Tobias Reich * @copyright 2014 by Philipp Maurer, Tobias Reich
*/ */
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!'); if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
@ -15,66 +15,66 @@ 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) {
if ($file['type']!=='image/jpeg'&&
$file['type']!=='image/png'&&
$file['type']!=='image/gif')
return false;
$id = str_replace('.', '', microtime(true));
while(strlen($id)<14) $id .= 0;
$tmp_name = $file['tmp_name'];
$extension = array_reverse(explode('.', $file['name']));
$extension = $extension[0];
$photo_name = md5($id) . ".$extension";
// Import if not uploaded via web if ($file['type']!=='image/jpeg'&&
if (!is_uploaded_file($tmp_name)) { $file['type']!=='image/png'&&
if (copy($tmp_name, '../uploads/big/' . $photo_name)) { $file['type']!=='image/gif')
return false;
$id = str_replace('.', '', microtime(true));
while(strlen($id)<14) $id .= 0;
$tmp_name = $file['tmp_name'];
$extension = array_reverse(explode('.', $file['name']));
$extension = $extension[0];
$photo_name = md5($id) . ".$extension";
// Import if not uploaded via web
if (!is_uploaded_file($tmp_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 {
move_uploaded_file($tmp_name, '../uploads/big/' . $photo_name); move_uploaded_file($tmp_name, '../uploads/big/' . $photo_name);
$import_name = ''; $import_name = '';
} }
// Read infos // Read infos
$info = getInfo($photo_name); $info = getInfo($photo_name);
// Use title of file if IPTC title missing // Use title of file if IPTC title missing
if ($info['title']==='') if ($info['title']==='')
$info['title'] = mysqli_real_escape_string($database, substr(basename($file['name'], ".$extension"), 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'])) {
if ($info['orientation']==3||$info['orientation']==6||$info['orientation']==8) { if ($info['orientation']==3||$info['orientation']==6||$info['orientation']==8) {
$newWidth = $info['width']; $newWidth = $info['width'];
$newHeight = $info['height']; $newHeight = $info['height'];
$sourceImg = imagecreatefromjpeg("../uploads/big/$photo_name"); $sourceImg = imagecreatefromjpeg("../uploads/big/$photo_name");
switch($info['orientation']){ switch($info['orientation']){
case 2: case 2:
// mirror // mirror
@ -88,77 +88,77 @@ function upload($files, $albumID) {
case 4: case 4:
// rotate 180 and mirror // rotate 180 and mirror
// not yet implemented // not yet implemented
break; break;
case 5: case 5:
// rotate 90 and mirror // rotate 90 and mirror
// not yet implemented // not yet implemented
break; break;
case 6: case 6:
$sourceImg = imagerotate($sourceImg, -90, 0); $sourceImg = imagerotate($sourceImg, -90, 0);
$newWidth = $info['height']; $newWidth = $info['height'];
$newHeight = $info['width']; $newHeight = $info['width'];
break; break;
case 7: case 7:
// rotate -90 and mirror // rotate -90 and mirror
// not yet implemented // not yet implemented
break; break;
case 8: case 8:
$sourceImg = imagerotate($sourceImg, 90, 0); $sourceImg = imagerotate($sourceImg, 90, 0);
$newWidth = $info['height']; $newWidth = $info['height'];
$newHeight = $info['width']; $newHeight = $info['width'];
break; break;
} }
$newSourceImg = imagecreatetruecolor($newWidth, $newHeight); $newSourceImg = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($newSourceImg, $sourceImg, 0, 0, 0, 0, $newWidth, $newHeight, $newWidth, $newHeight); imagecopyresampled($newSourceImg, $sourceImg, 0, 0, 0, 0, $newWidth, $newHeight, $newWidth, $newHeight);
imagejpeg($newSourceImg, "../uploads/big/$photo_name", 100); imagejpeg($newSourceImg, "../uploads/big/$photo_name", 100);
} }
} }
// Create Thumb // Create Thumb
if (!createThumb($photo_name)) return false; if (!createThumb($photo_name)) return false;
// Save to DB // Save to DB
$query = "INSERT INTO lychee_photos (id, title, url, description, type, width, height, size, sysdate, systime, iso, aperture, make, model, shutter, focal, takedate, taketime, thumbUrl, album, public, star, import_name) $query = "INSERT INTO lychee_photos (id, title, url, description, type, width, height, size, sysdate, systime, iso, aperture, make, model, shutter, focal, takedate, taketime, thumbUrl, album, public, star, import_name)
VALUES ( VALUES (
'" . $id . "', '" . $id . "',
'" . $info['title'] . "', '" . $info['title'] . "',
'" . $photo_name . "', '" . $photo_name . "',
'" . $info['description'] . "', '" . $info['description'] . "',
'" . $info['type'] . "', '" . $info['type'] . "',
'" . $info['width'] . "', '" . $info['width'] . "',
'" . $info['height'] . "', '" . $info['height'] . "',
'" . $info['size'] . "', '" . $info['size'] . "',
'" . $info['date'] . "', '" . $info['date'] . "',
'" . $info['time'] . "', '" . $info['time'] . "',
'" . $info['iso'] . "', '" . $info['iso'] . "',
'" . $info['aperture'] . "', '" . $info['aperture'] . "',
'" . $info['make'] . "', '" . $info['make'] . "',
'" . $info['model'] . "', '" . $info['model'] . "',
'" . $info['shutter'] . "', '" . $info['shutter'] . "',
'" . $info['focal'] . "', '" . $info['focal'] . "',
'" . $info['takeDate'] . "', '" . $info['takeDate'] . "',
'" . $info['takeTime'] . "', '" . $info['takeTime'] . "',
'" . md5($id) . ".jpeg', '" . md5($id) . ".jpeg',
'" . $albumID . "', '" . $albumID . "',
'" . $public . "', '" . $public . "',
'" . $star . "', '" . $star . "',
'" . $import_name . "');"; '" . $import_name . "');";
$result = $database->query($query); $result = $database->query($query);
if (!$result) return false; if (!$result) return false;
} }
return true; return true;
} }
@ -188,18 +188,18 @@ function getInfo($filename) {
// IPTC Metadata // IPTC Metadata
if(isset($iptcArray['APP13'])) { if(isset($iptcArray['APP13'])) {
$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;
} }
} }
// EXIF Metadata Fallback // EXIF Metadata Fallback
@ -212,49 +212,49 @@ function getInfo($filename) {
$return['focal'] = ''; $return['focal'] = '';
$return['takeDate'] = ''; $return['takeDate'] = '';
$return['takeTime'] = ''; $return['takeTime'] = '';
// Read EXIF // Read EXIF
if ($info['mime']=='image/jpeg') $exif = exif_read_data($url, 'EXIF', 0); if ($info['mime']=='image/jpeg') $exif = exif_read_data($url, 'EXIF', 0);
else $exif = false; else $exif = false;
// EXIF Metadata // EXIF Metadata
if ($exif!==false) { if ($exif!==false) {
$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];
} }
} }
// Security // Security
foreach(array_keys($return) as $key) $return[$key] = mysqli_real_escape_string($database, $return[$key]); foreach(array_keys($return) as $key) $return[$key] = mysqli_real_escape_string($database, $return[$key]);
return $return; return $return;
} }
@ -262,45 +262,45 @@ 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
if ($info['mime']==='image/webp'&&floatval(phpversion())<5.5) return false;
// Create new image // Fallback for older version
switch($info['mime']) { if ($info['mime']==='image/webp'&&floatval(phpversion())<5.5) return false;
case 'image/jpeg': $sourceImg = imagecreatefromjpeg($url); break;
case 'image/png': $sourceImg = imagecreatefrompng($url); break;
case 'image/gif': $sourceImg = imagecreatefromgif($url); break;
case 'image/webp': $sourceImg = imagecreatefromwebp($url); break;
default: return false;
}
imagecopyresampled($thumb,$sourceImg,0,0,$startWidth,$startHeight,$width,$height,$newSize,$newSize); // Create new image
imagecopyresampled($thumb2x,$sourceImg,0,0,$startWidth,$startHeight,$width*2,$height*2,$newSize,$newSize); switch($info['mime']) {
case 'image/jpeg': $sourceImg = imagecreatefromjpeg($url); break;
case 'image/png': $sourceImg = imagecreatefrompng($url); break;
case 'image/gif': $sourceImg = imagecreatefromgif($url); break;
case 'image/webp': $sourceImg = imagecreatefromwebp($url); break;
default: return false;
}
imagejpeg($thumb,$newUrl,$settings['thumbQuality']); imagecopyresampled($thumb,$sourceImg,0,0,$startWidth,$startHeight,$width,$height,$newSize,$newSize);
imagejpeg($thumb2x,$newUrl2x,$settings['thumbQuality']); imagecopyresampled($thumb2x,$sourceImg,0,0,$startWidth,$startHeight,$width*2,$height*2,$newSize,$newSize);
return true; imagejpeg($thumb,$newUrl,$settings['thumbQuality']);
imagejpeg($thumb2x,$newUrl2x,$settings['thumbQuality']);
return true;
} }
@ -308,7 +308,7 @@ function importPhoto($path, $albumID = 0) {
$info = getimagesize($path); $info = getimagesize($path);
$size = filesize($path); $size = filesize($path);
$nameFile = array(array()); $nameFile = array(array());
$nameFile[0]['name'] = $path; $nameFile[0]['name'] = $path;
$nameFile[0]['type'] = $info['mime']; $nameFile[0]['type'] = $info['mime'];
@ -337,7 +337,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,9 +357,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);
} }
@ -381,19 +381,19 @@ function importServer($albumID = 0, $path = '../uploads/import/') {
foreach ($files as $file) { foreach ($files as $file) {
if (@getimagesize($file)) { if (@getimagesize($file)) {
// Photo // Photo
if (!importPhoto($file, $albumID)) return false; if (!importPhoto($file, $albumID)) return false;
$contains['photos'] = true; $contains['photos'] = true;
} else if (is_dir($file)) { } else if (is_dir($file)) {
$name = mysqli_real_escape_string($database, basename($file)); $name = mysqli_real_escape_string($database, basename($file));
$newAlbumID = addAlbum('[Import] ' . $name); $newAlbumID = addAlbum('[Import] ' . $name);
if ($newAlbumID!==false) importServer($newAlbumID, $file . '/'); if ($newAlbumID!==false) importServer($newAlbumID, $file . '/');
$contains['albums'] = true; $contains['albums'] = true;
} }
} }