2014-01-22 10:12:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2014-02-17 16:01:46 +00:00
|
|
|
* @name Photo Module
|
|
|
|
* @author Philipp Maurer
|
|
|
|
* @author Tobias Reich
|
|
|
|
* @copyright 2014 by Philipp Maurer, Tobias Reich
|
2014-01-22 10:12:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
|
|
|
|
|
|
|
function getPhoto($photoID, $albumID) {
|
|
|
|
|
|
|
|
global $database;
|
|
|
|
|
2014-02-09 21:30:16 +00:00
|
|
|
$query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
|
2014-02-17 16:01:46 +00:00
|
|
|
$result = $database->query($query);
|
|
|
|
$return = $result->fetch_array();
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
if ($albumID!='false') {
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
if ($return['album']!=0) {
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
$result = $database->query("SELECT public FROM lychee_albums WHERE id = '" . $return['album'] . "';");
|
|
|
|
$return_album = $result->fetch_array();
|
|
|
|
if ($return_album['public']=="1") $return['public'] = "2";
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
}
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
$return['original_album'] = $return['album'];
|
|
|
|
$return['album'] = $albumID;
|
|
|
|
$return['sysdate'] = date('d M. Y', strtotime($return['sysdate']));
|
|
|
|
if (strlen($return['takedate'])>0) $return['takedate'] = date('d M. Y', strtotime($return['takedate']));
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
unset($return['album_public']);
|
|
|
|
|
2014-03-18 21:57:49 +00:00
|
|
|
// Remove unused items
|
|
|
|
foreach ($return as $key => $value) {
|
|
|
|
if (is_int($key)) unset($return[$key]);
|
|
|
|
}
|
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
return $return;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function setPhotoPublic($photoID, $url) {
|
|
|
|
|
|
|
|
global $database;
|
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
$result = $database->query("SELECT public FROM lychee_photos WHERE id = '$photoID';");
|
|
|
|
$row = $result->fetch_object();
|
|
|
|
$public = ($row->public==0 ? 1 : 0);
|
|
|
|
$result = $database->query("UPDATE lychee_photos SET public = '$public' WHERE id = '$photoID';");
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
if (!$result) return false;
|
|
|
|
return true;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-01-31 19:11:28 +00:00
|
|
|
function setPhotoStar($photoIDs) {
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
global $database;
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-02-09 21:30:16 +00:00
|
|
|
$error = false;
|
2014-02-17 16:01:46 +00:00
|
|
|
$result = $database->query("SELECT id, star FROM lychee_photos WHERE id IN ($photoIDs);");
|
|
|
|
|
|
|
|
while ($row = $result->fetch_object()) {
|
|
|
|
|
|
|
|
$star = ($row->star==0 ? 1 : 0);
|
|
|
|
$star = $database->query("UPDATE lychee_photos SET star = '$star' WHERE id = '$row->id';");
|
|
|
|
if (!$star) $error = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($error) return false;
|
|
|
|
return true;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-09 18:21:55 +00:00
|
|
|
function setPhotoAlbum($photoIDs, $albumID) {
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
global $database;
|
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
$result = $database->query("UPDATE lychee_photos SET album = '$albumID' WHERE id IN ($photoIDs);");
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
if (!$result) return false;
|
|
|
|
return true;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-01-31 19:11:28 +00:00
|
|
|
function setPhotoTitle($photoIDs, $title) {
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
global $database;
|
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
if (strlen($title)>50) return false;
|
|
|
|
$result = $database->query("UPDATE lychee_photos SET title = '$title' WHERE id IN ($photoIDs);");
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
if (!$result) return false;
|
|
|
|
return true;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function setPhotoDescription($photoID, $description) {
|
|
|
|
|
|
|
|
global $database;
|
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
$description = htmlentities($description);
|
|
|
|
if (strlen($description)>1000) return false;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
$result = $database->query("UPDATE lychee_photos SET description = '$description' WHERE id = '$photoID';");
|
|
|
|
|
|
|
|
if (!$result) return false;
|
|
|
|
return true;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-09 18:21:55 +00:00
|
|
|
function setPhotoTags($photoIDs, $tags) {
|
|
|
|
|
|
|
|
global $database;
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-02-09 18:21:55 +00:00
|
|
|
// Parse tags
|
|
|
|
$tags = preg_replace('/(\ ,\ )|(\ ,)|(,\ )|(,{1,}\ {0,})|(,$|^,)/', ',', $tags);
|
|
|
|
$tags = preg_replace('/,$|^,/', ',', $tags);
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-02-09 18:21:55 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-01-31 19:11:28 +00:00
|
|
|
function deletePhoto($photoIDs) {
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
global $database;
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-02-10 17:04:34 +00:00
|
|
|
$result = $database->query("SELECT id, url, thumbUrl FROM lychee_photos WHERE id IN ($photoIDs);");
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-01-28 23:43:06 +00:00
|
|
|
while ($row = $result->fetch_object()) {
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-01-28 23:43:06 +00:00
|
|
|
// Get retina thumb url
|
|
|
|
$thumbUrl2x = explode(".", $row->thumbUrl);
|
|
|
|
$thumbUrl2x = $thumbUrl2x[0] . '@2x.' . $thumbUrl2x[1];
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-01-28 23:43:06 +00:00
|
|
|
// Delete files
|
2014-02-09 21:30:16 +00:00
|
|
|
if (!unlink('../uploads/big/' . $row->url)) return false;
|
|
|
|
if (!unlink('../uploads/thumb/' . $row->thumbUrl)) return false;
|
|
|
|
if (!unlink('../uploads/thumb/' . $thumbUrl2x)) return false;
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-01-28 23:43:06 +00:00
|
|
|
// Delete db entry
|
|
|
|
$delete = $database->query("DELETE FROM lychee_photos WHERE id = $row->id;");
|
|
|
|
if (!$delete) return false;
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-01-28 23:43:06 +00:00
|
|
|
}
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-01-28 23:43:06 +00:00
|
|
|
if (!$result) return false;
|
|
|
|
return true;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function isPhotoPublic($photoID, $password) {
|
|
|
|
|
|
|
|
global $database;
|
|
|
|
|
2014-02-10 17:04:34 +00:00
|
|
|
$query = "SELECT public, album FROM lychee_photos WHERE id = '$photoID';";
|
2014-02-09 21:30:16 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
$result = $database->query($query);
|
|
|
|
$row = $result->fetch_object();
|
|
|
|
|
|
|
|
if ($row->public==1) return true;
|
|
|
|
else {
|
|
|
|
$cAP = checkAlbumPassword($row->album, $password);
|
|
|
|
$iAP = isAlbumPublic($row->album);
|
|
|
|
if ($iAP&&$cAP) return true;
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-01-24 12:49:01 +00:00
|
|
|
function getPhotoArchive($photoID) {
|
|
|
|
|
|
|
|
global $database;
|
|
|
|
|
2014-02-10 17:04:34 +00:00
|
|
|
$result = $database->query("SELECT title, url FROM lychee_photos WHERE id = '$photoID';");
|
2014-02-09 21:30:16 +00:00
|
|
|
$row = $result->fetch_object();
|
2014-01-24 12:49:01 +00:00
|
|
|
|
|
|
|
$extension = array_reverse(explode('.', $row->url));
|
|
|
|
|
|
|
|
if ($row->title=='') $row->title = 'Untitled';
|
|
|
|
|
|
|
|
header("Content-Type: application/octet-stream");
|
|
|
|
header("Content-Disposition: attachment; filename=\"$row->title.$extension[0]\"");
|
|
|
|
header("Content-Length: " . filesize("../uploads/big/$row->url"));
|
|
|
|
|
|
|
|
readfile("../uploads/big/$row->url");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
?>
|