2012-10-02 15:48:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name functions.php
|
|
|
|
* @author Philipp Maurer
|
|
|
|
* @author Tobias Reich
|
2013-05-03 11:57:08 +00:00
|
|
|
* @copyright 2013 by Philipp Maurer, Tobias Reich
|
2012-10-02 15:48:08 +00:00
|
|
|
*/
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-06-17 18:40:04 +00:00
|
|
|
if(!defined('LYCHEE')) die('Direct access is not allowed!');
|
2012-10-02 15:48:08 +00:00
|
|
|
|
|
|
|
// Database Functions
|
|
|
|
function dbConnect() {
|
2012-10-25 10:22:04 +00:00
|
|
|
global $db, $dbUser, $dbPassword, $dbHost;
|
2013-05-03 11:57:08 +00:00
|
|
|
$database = new mysqli($dbHost, $dbUser, $dbPassword);
|
|
|
|
if (mysqli_connect_errno() != 0) {
|
|
|
|
echo mysqli_connect_errno().': '.mysqli_connect_error();
|
2012-10-02 15:48:08 +00:00
|
|
|
return false;
|
2013-05-03 11:57:08 +00:00
|
|
|
}
|
|
|
|
if (!$database->select_db($db)) {
|
|
|
|
createDatabase($db, $database);
|
|
|
|
}
|
|
|
|
$query = "SELECT * FROM lychee_photos, lychee_albums;";
|
|
|
|
if(!$database->query($query)) createTables($database);
|
|
|
|
return $database;
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
|
|
|
function dbClose() {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database;
|
2013-06-17 18:40:04 +00:00
|
|
|
if(!$database->close()) {
|
2012-10-02 15:48:08 +00:00
|
|
|
echo "Closing the connection failed!";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
function createDatabase($db, $database) {
|
2013-06-17 18:40:04 +00:00
|
|
|
$result = $database->query("CREATE DATABASE IF NOT EXISTS $db;");
|
2013-05-03 11:57:08 +00:00
|
|
|
$database->select_db($db);
|
2012-10-25 10:22:04 +00:00
|
|
|
if(!$result) return false;
|
|
|
|
return true;
|
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
function createTables($database) {
|
|
|
|
$query = "CREATE TABLE IF NOT EXISTS `lychee_albums` (
|
2012-10-02 15:48:08 +00:00
|
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
|
|
`title` varchar(50) NOT NULL,
|
|
|
|
`sysdate` varchar(10) NOT NULL,
|
2013-06-17 18:40:04 +00:00
|
|
|
`public` TINYINT(1) DEFAULT '0',
|
|
|
|
`password` VARCHAR(100),
|
2012-10-02 15:48:08 +00:00
|
|
|
PRIMARY KEY (`id`)
|
|
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
|
2013-05-03 11:57:08 +00:00
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
if(!$result) return false;
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "CREATE TABLE `lychee_photos` (
|
2012-10-02 15:48:08 +00:00
|
|
|
`id` bigint(14) NOT NULL,
|
|
|
|
`title` varchar(50) NOT NULL,
|
|
|
|
`description` varchar(160) NOT NULL,
|
|
|
|
`url` varchar(100) NOT NULL,
|
|
|
|
`public` tinyint(1) NOT NULL,
|
|
|
|
`shortlink` varchar(20) NOT NULL,
|
|
|
|
`type` varchar(10) NOT NULL,
|
|
|
|
`width` int(11) NOT NULL,
|
|
|
|
`height` int(11) NOT NULL,
|
|
|
|
`size` varchar(10) NOT NULL,
|
|
|
|
`sysdate` varchar(10) NOT NULL,
|
|
|
|
`systime` varchar(8) NOT NULL,
|
|
|
|
`iso` varchar(15) NOT NULL,
|
|
|
|
`aperture` varchar(10) NOT NULL,
|
|
|
|
`make` varchar(20) NOT NULL,
|
|
|
|
`model` varchar(50) NOT NULL,
|
|
|
|
`shutter` varchar(10) NOT NULL,
|
|
|
|
`focal` varchar(10) NOT NULL,
|
|
|
|
`takedate` varchar(10) NOT NULL,
|
|
|
|
`taketime` varchar(8) NOT NULL,
|
|
|
|
`star` tinyint(1) NOT NULL,
|
|
|
|
`thumbUrl` varchar(50) NOT NULL,
|
2013-05-03 11:57:08 +00:00
|
|
|
`album` varchar(30) NOT NULL DEFAULT '0',
|
|
|
|
`import_name` varchar(100) DEFAULT '',
|
2012-10-02 15:48:08 +00:00
|
|
|
PRIMARY KEY (`id`)
|
2013-05-03 11:57:08 +00:00
|
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
|
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
if(!$result) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Upload Functions
|
2013-05-03 11:57:08 +00:00
|
|
|
function upload($files, $albumID) {
|
|
|
|
global $database;
|
|
|
|
foreach ($files as $file) {
|
|
|
|
switch($albumID) {
|
|
|
|
// s for public (share)
|
|
|
|
case 's':
|
|
|
|
$public = 1;
|
|
|
|
$star = 0;
|
|
|
|
$albumID = 0;
|
|
|
|
break;
|
|
|
|
// f for starred (fav)
|
|
|
|
case 'f':
|
|
|
|
$star = 1;
|
|
|
|
$public = 0;
|
|
|
|
$albumID = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$star = 0;
|
|
|
|
$public = 0;
|
|
|
|
}
|
|
|
|
$id = str_replace('.', '', microtime(true));
|
|
|
|
while(strlen($id)<14) $id .= 0;
|
|
|
|
$tmp_name = $file["tmp_name"];
|
|
|
|
$type = getimagesize($tmp_name);
|
|
|
|
if(($type[2]!=1)&&($type[2]!=2)&&($type[2]!=3)) return false;
|
|
|
|
$data = $file["name"];
|
|
|
|
$data = explode('.',$data);
|
|
|
|
$data = array_reverse ($data);
|
|
|
|
$data = $data[0];
|
|
|
|
if(!is_uploaded_file($file)) {
|
|
|
|
if (copy($tmp_name, "../uploads/big/$id.$data")) {
|
|
|
|
unlink($tmp_name);
|
|
|
|
$import_name = $tmp_name;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
move_uploaded_file($tmp_name, "../uploads/big/$id.$data");
|
|
|
|
$import_name = "";
|
|
|
|
}
|
|
|
|
createThumb($id.".".$data);
|
|
|
|
// Read infos
|
|
|
|
$info = getCamera($id.".".$data);
|
|
|
|
$title="";
|
|
|
|
if(isset($info['type'])){$type=$info['type'];}else{$type="";}
|
|
|
|
if(isset($info['width'])){$width=$info['width'];}else{$width="";}
|
|
|
|
if(isset($info['height'])){$height=$info['height'] OR "";}else{$height="";}
|
|
|
|
if(isset($info['size'])){$size=$info['size'] OR "";}else{$size="";}
|
|
|
|
if(isset($info['date'])){$sysdate=$info['date'];}else{$sysdate="";}
|
|
|
|
if(isset($info['time'])){$systime=$info['time'];}else{$systime="";}
|
|
|
|
if(isset($info['iso'])){$iso=$info['iso'];}else{$iso="";}
|
|
|
|
if(isset($info['aperture'])){$aperture=$info['aperture'];}else{$aperture="";}
|
|
|
|
if(isset($info['make'])){$make=$info['make'];}else{$make="";}
|
|
|
|
if(isset($info['model'])){$model=$info['model'] OR "";}else{$model="";}
|
|
|
|
if(isset($info['shutter'])){$shutter=$info['shutter'];}else{$shutter="";}
|
|
|
|
if(isset($info['focal'])){$focal=$info['focal'];}else{$focal="";}
|
|
|
|
if(isset($info['takeDate'])){$takeDate=$info['takeDate'];}else{$takeDate="";}
|
|
|
|
if(isset($info['takeTime'])){$takeTime=$info['takeTime'];}else{$takeTime="";}
|
|
|
|
$query = "INSERT INTO lychee_photos (id, title, url, type, width, height, size, sysdate, systime, iso, aperture, make, model, shutter, focal, takedate, taketime, thumbUrl, album, public, star, import_name)
|
|
|
|
VALUES ('$id', '$title', 'uploads/big/$id.$data', '$type', '$width', '$height', '$size', '$sysdate', '$systime', '$iso', '$aperture', '$make', '$model', '$shutter', '$focal', '$takeDate', '$takeTime', 'uploads/thumb/$id.$data', '$albumID', '$public', '$star', '$import_name');";
|
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
return true;
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
|
|
|
function getCamera($photoID) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database;
|
2012-10-02 15:48:08 +00:00
|
|
|
$url = "../uploads/big/$photoID";
|
|
|
|
$type = getimagesize($url);
|
|
|
|
$type = $type['mime'];
|
|
|
|
|
|
|
|
if(($type == "image/jpeg") && function_exists('exif_read_data') ){
|
|
|
|
|
|
|
|
$exif = exif_read_data($url, "EXIF", 0);
|
|
|
|
|
|
|
|
// General information
|
|
|
|
$return['name'] = $exif['FileName'];
|
|
|
|
$generalInfos = getimagesize($url);
|
|
|
|
$return['type'] = $generalInfos['mime'];
|
|
|
|
$return['width'] = $generalInfos[0];
|
|
|
|
$return['height'] = $generalInfos[1];
|
|
|
|
$size = (filesize($url) / 1024);
|
|
|
|
if($size >= 1024){$size=round($size/1024,1)." MB";}else{$size=round($size,1)." KB";}
|
|
|
|
$return['size'] = $size;
|
|
|
|
$return['date'] = date("d.m.Y",filectime($url));
|
|
|
|
$return['time'] = date("H:i:s",filectime($url));
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
//echo $exif['FileDateTime']."<br/>".$exif['DateTimeOriginal'];
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
// Camera Information
|
|
|
|
if(isset($exif['ISOSpeedRatings'])){$return['iso']="ISO-".$exif['ISOSpeedRatings'];}
|
|
|
|
if(isset($exif['COMPUTED']['ApertureFNumber'])){$return['aperture']=$exif['COMPUTED']['ApertureFNumber'];}
|
|
|
|
if(isset($exif['Make'])){$return['make']=$exif['Make'];}
|
|
|
|
if(isset($exif['Model'])){$return['model']=$exif['Model'];}
|
|
|
|
if(isset($exif['ExposureTime'])){$return['shutter']=$exif['ExposureTime']." Sek.";}
|
|
|
|
if(isset($exif['FocalLength'])){$return['focal']=($exif['FocalLength']/1)." mm";}
|
|
|
|
if(isset($exif['Software'])){$return['software']=$exif['Software'];}
|
|
|
|
if(isset($exif['DateTimeOriginal'])) {
|
|
|
|
$exifDate = explode(" ",$exif['DateTimeOriginal']);
|
|
|
|
$date = explode(":", $exifDate[0]); $return['takeDate'] = $date[2].".".$date[1].".".$date[0];
|
|
|
|
$return['takeTime'] = $exifDate[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
$exif = getimagesize($url);
|
|
|
|
$return['type'] = $exif['mime'];
|
|
|
|
$return['width'] = $exif[0];
|
|
|
|
$return['height'] = $exif[1];
|
|
|
|
$size = (filesize($url) / 1024);
|
|
|
|
if($size >= 1024){$size=round($size/1024,1)." MB";}else{$size=round($size,1)." KB";}
|
|
|
|
$return['size'] = $size;
|
|
|
|
$return['date'] = date("d.m.Y",filectime($url));
|
|
|
|
$return['time'] = date("H:i:s",filectime($url));
|
|
|
|
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
function createThumb($photoName, $width = 200, $width2x = 400, $height = 200, $height2x = 400) {
|
|
|
|
global $database, $thumbQuality;
|
2012-10-02 15:48:08 +00:00
|
|
|
$photoUrl = "../uploads/big/$photoName";
|
|
|
|
$newUrl = "../uploads/thumb/$photoName";
|
2013-05-03 11:57:08 +00:00
|
|
|
$thumbPhotoName = explode(".", $photoName);
|
|
|
|
$newUrl2x = "../uploads/thumb/".$thumbPhotoName[0]."@2x.".$thumbPhotoName[1];
|
2012-10-02 15:48:08 +00:00
|
|
|
$oldImg = getimagesize($photoUrl);
|
|
|
|
$type = $oldImg['mime'];
|
|
|
|
switch($type) {
|
|
|
|
case "image/jpeg": $sourceImg = imagecreatefromjpeg($photoUrl); break;
|
|
|
|
case "image/png": $sourceImg = imagecreatefrompng($photoUrl); break;
|
|
|
|
case "image/gif": $sourceImg = imagecreatefromgif($photoUrl); break;
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
$thumb = imagecreatetruecolor($width, $height);
|
2013-05-03 11:57:08 +00:00
|
|
|
$thumb2x = imagecreatetruecolor($width2x, $height2x);
|
2012-10-02 15:48:08 +00:00
|
|
|
if($oldImg[0]<$oldImg[1]) {
|
|
|
|
$newSize = $oldImg[0];
|
|
|
|
$startWidth = 0;
|
|
|
|
$startHeight = $oldImg[1]/2 - $oldImg[0]/2;
|
|
|
|
} else {
|
|
|
|
$newSize = $oldImg[1];
|
|
|
|
$startWidth = $oldImg[0]/2 - $oldImg[1]/2;
|
|
|
|
$startHeight = 0;
|
|
|
|
}
|
|
|
|
imagecopyresampled($thumb,$sourceImg,0,0,$startWidth,$startHeight,$width,$height,$newSize,$newSize);
|
2013-05-03 11:57:08 +00:00
|
|
|
imagecopyresampled($thumb2x,$sourceImg,0,0,$startWidth,$startHeight,$width2x,$height2x,$newSize,$newSize);
|
2012-10-02 15:48:08 +00:00
|
|
|
switch($type) {
|
2013-05-03 11:57:08 +00:00
|
|
|
case "image/jpeg": imagejpeg($thumb,$newUrl,$thumbQuality); imagejpeg($thumb2x,$newUrl2x,$thumbQuality); break;
|
|
|
|
case "image/png": imagepng($thumb,$newUrl); imagepng($thumb2x,$newUrl2x); break;
|
|
|
|
case "image/gif": imagegif($thumb,$newUrl); imagegif($thumb2x,$newUrl2x); break;
|
2012-10-02 15:48:08 +00:00
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Session Functions
|
2013-06-17 18:40:04 +00:00
|
|
|
function init($mode) {
|
|
|
|
global $checkForUpdates, $bitlyUsername;
|
|
|
|
$return["config"]["checkForUpdates"] = $checkForUpdates;
|
|
|
|
$return["config"]["bitlyUsername"] = $bitlyUsername;
|
|
|
|
if ($mode=="admin") $return["loggedIn"] = true;
|
|
|
|
else $return["loggedIn"] = false;
|
|
|
|
return $return;
|
|
|
|
}
|
2012-10-02 15:48:08 +00:00
|
|
|
function login($loginUser, $loginPassword) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database, $user, $password;
|
2013-06-17 18:40:04 +00:00
|
|
|
if ($loginUser==$user&&$loginPassword==md5($password)) {
|
|
|
|
// Admin Login
|
2012-10-02 15:48:08 +00:00
|
|
|
$_SESSION['login'] = true;
|
|
|
|
return true;
|
|
|
|
} else {
|
2013-06-17 18:40:04 +00:00
|
|
|
return false;
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function logout() {
|
|
|
|
session_destroy();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Album Functions
|
|
|
|
function addAlbum($title) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database;
|
|
|
|
$title = mysqli_real_escape_string($database, $title);
|
2013-06-17 18:40:04 +00:00
|
|
|
if(strlen($title)<1||strlen($title)>30) return false;
|
2012-10-02 15:48:08 +00:00
|
|
|
$sysdate = date("d.m.Y");
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "INSERT INTO lychee_albums (title, sysdate) VALUES ('$title', '$sysdate');";
|
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
if(!$result) return false;
|
2013-05-03 11:57:08 +00:00
|
|
|
return $database->insert_id;
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
2013-06-17 18:40:04 +00:00
|
|
|
function getAlbums($public) {
|
|
|
|
global $database, $sorting;
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
// Smart Albums
|
2013-06-17 18:40:04 +00:00
|
|
|
if (!$public) $return = getSmartInfo();
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
// Albums
|
2013-06-17 18:40:04 +00:00
|
|
|
if ($public) $query = "SELECT * FROM lychee_albums WHERE public = 1 ORDER BY id $sorting;";
|
|
|
|
else $query = "SELECT * FROM lychee_albums ORDER BY id $sorting;";
|
2013-05-03 11:57:08 +00:00
|
|
|
$result = $database->query($query) OR die("Error: $result <br>".$database->error);
|
2012-10-02 15:48:08 +00:00
|
|
|
$i=0;
|
2013-05-03 11:57:08 +00:00
|
|
|
while($row = $result->fetch_object()) {
|
|
|
|
$return["album"][$i]['id'] = $row->id;
|
|
|
|
$return["album"][$i]['title'] = $row->title;
|
2013-06-17 18:40:04 +00:00
|
|
|
$return["album"][$i]['public'] = $row->public;
|
2013-05-03 11:57:08 +00:00
|
|
|
$return["album"][$i]['sysdate'] = $row->sysdate;
|
2013-06-17 18:40:04 +00:00
|
|
|
if ($row->password=="") $return["album"][$i]['password'] = false;
|
|
|
|
else $return["album"][$i]['password'] = true;
|
|
|
|
|
|
|
|
// Thumbs
|
|
|
|
if (($public&&$row->password=="")||(!$public)) {
|
|
|
|
$albumID = $row->id;
|
|
|
|
$query = "SELECT thumbUrl FROM lychee_photos WHERE album = '$albumID' ORDER BY id $sorting LIMIT 0, 3;";
|
|
|
|
$result2 = $database->query($query);
|
|
|
|
$k = 0;
|
|
|
|
while($row2 = $result2->fetch_object()){
|
|
|
|
$return["album"][$i]["thumb$k"] = $row2->thumbUrl;
|
|
|
|
$k++;
|
|
|
|
}
|
|
|
|
if(!isset($return["album"][$i]["thumb0"]))$return["album"][$i]["thumb0"]="";
|
|
|
|
if(!isset($return["album"][$i]["thumb1"]))$return["album"][$i]["thumb1"]="";
|
|
|
|
if(!isset($return["album"][$i]["thumb2"]))$return["album"][$i]["thumb2"]="";
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
|
|
|
$i++;
|
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
if($i==0) $return["albums"] = false;
|
|
|
|
else $return["albums"] = true;
|
2012-10-02 15:48:08 +00:00
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
function getSmartInfo() {
|
2013-06-17 18:40:04 +00:00
|
|
|
global $database, $sorting;
|
|
|
|
$query = "SELECT * FROM lychee_photos WHERE album = 0 ORDER BY id $sorting;";
|
2013-05-03 11:57:08 +00:00
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
$i = 0;
|
2013-05-03 11:57:08 +00:00
|
|
|
while($row = $result->fetch_object()) {
|
2012-10-02 15:48:08 +00:00
|
|
|
if($i<3) $return["unsortThumb$i"] = $row->thumbUrl;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
$return['unsortNum'] = $i;
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-06-17 18:40:04 +00:00
|
|
|
$query2 = "SELECT * FROM lychee_photos WHERE public = 1 ORDER BY id $sorting;";
|
2013-05-03 11:57:08 +00:00
|
|
|
$result2 = $database->query($query2);
|
2012-10-02 15:48:08 +00:00
|
|
|
$i = 0;
|
2013-05-03 11:57:08 +00:00
|
|
|
while($row2 = $result2->fetch_object()) {
|
2012-10-02 15:48:08 +00:00
|
|
|
if($i<3) $return["publicThumb$i"] = $row2->thumbUrl;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
$return['publicNum'] = $i;
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-06-17 18:40:04 +00:00
|
|
|
$query3 = "SELECT * FROM lychee_photos WHERE star = 1 ORDER BY id $sorting;";
|
2013-05-03 11:57:08 +00:00
|
|
|
$result3 = $database->query($query3);
|
2012-10-02 15:48:08 +00:00
|
|
|
$i = 0;
|
2013-05-03 11:57:08 +00:00
|
|
|
while($row3 = $result3->fetch_object()) {
|
2012-10-02 15:48:08 +00:00
|
|
|
if($i<3) $return["starredThumb$i"] = $row3->thumbUrl;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
$return['starredNum'] = $i;
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
function getAlbumInfo($albumID) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database;
|
|
|
|
$query = "SELECT * FROM lychee_albums WHERE id = '$albumID';";
|
|
|
|
$result = $database->query($query);
|
|
|
|
$row = $result->fetch_object();
|
2012-10-02 15:48:08 +00:00
|
|
|
$return['title'] = $row->title;
|
|
|
|
$return['date'] = $row->sysdate;
|
|
|
|
$return['public'] = $row->public;
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "SELECT COUNT(*) AS num FROM lychee_photos WHERE album = '$albumID';";
|
|
|
|
$result = $database->query($query);
|
|
|
|
$row = $result->fetch_object();
|
2012-10-02 15:48:08 +00:00
|
|
|
$return['num'] = $row->num;
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
function setAlbumTitle($albumID, $title) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database;
|
|
|
|
$title = mysqli_real_escape_string($database, urldecode($title));
|
2013-06-17 18:40:04 +00:00
|
|
|
if(strlen($title)<1||strlen($title)>30) return false;
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "UPDATE lychee_albums SET title = '$title' WHERE id = '$albumID';";
|
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
if(!$result) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
function deleteAlbum($albumID, $delAll) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database;
|
2012-10-02 15:48:08 +00:00
|
|
|
if($delAll=="true") {
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "SELECT id FROM lychee_photos WHERE album = '$albumID';";
|
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
$error = false;
|
2013-05-03 11:57:08 +00:00
|
|
|
while($row = $result->fetch_object()) {
|
2012-10-02 15:48:08 +00:00
|
|
|
if(!deletePhoto($row->id)) $error = true;
|
|
|
|
}
|
|
|
|
} else {
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "UPDATE lychee_photos SET album = '0' WHERE album = '$albumID';";
|
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
if(!$result) return false;
|
|
|
|
}
|
|
|
|
if($albumID!=0) {
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "DELETE FROM lychee_albums WHERE id = '$albumID';";
|
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
if(!$result) return false;
|
|
|
|
}
|
|
|
|
if($error) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
function getAlbumArchive($albumID) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database;
|
2012-10-02 15:48:08 +00:00
|
|
|
switch($albumID) {
|
|
|
|
case 's':
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "SELECT * FROM lychee_photos WHERE public = '1';";
|
2012-10-02 15:48:08 +00:00
|
|
|
$zipTitle = "Public";
|
|
|
|
break;
|
|
|
|
case 'f':
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "SELECT * FROM lychee_photos WHERE star = '1';";
|
2012-10-02 15:48:08 +00:00
|
|
|
$zipTitle = "Starred";
|
|
|
|
break;
|
|
|
|
default:
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "SELECT * FROM lychee_photos WHERE album = '$albumID';";
|
2012-10-02 15:48:08 +00:00
|
|
|
$zipTitle = "Unsorted";
|
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
$files = array();
|
|
|
|
$i=0;
|
2013-05-03 11:57:08 +00:00
|
|
|
while($row = $result->fetch_object()) {
|
2012-10-02 15:48:08 +00:00
|
|
|
$files[$i] = "../".$row->url;
|
|
|
|
$i++;
|
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "SELECT * FROM lychee_albums WHERE id = '$albumID';";
|
|
|
|
$result = $database->query($query);
|
|
|
|
$row = $result->fetch_object();
|
2012-10-02 15:48:08 +00:00
|
|
|
if($albumID!=0&&is_numeric($albumID))$zipTitle = $row->title;
|
2013-06-17 18:40:04 +00:00
|
|
|
$filename = "../uploads/".$zipTitle.".zip";
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
$zip = new ZipArchive();
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
foreach($files AS $zipFile) {
|
|
|
|
$newFile = explode("/",$zipFile);
|
|
|
|
$newFile = array_reverse($newFile);
|
|
|
|
$zip->addFile($zipFile, $zipTitle."/".$newFile[0]);
|
|
|
|
}
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
$zip->close();
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
header("Content-Type: application/zip");
|
|
|
|
header("Content-Disposition: attachment; filename=\"$zipTitle.zip\"");
|
2013-06-17 18:40:04 +00:00
|
|
|
header("Content-Length: ".filesize($filename));
|
2012-10-02 15:48:08 +00:00
|
|
|
readfile($filename);
|
|
|
|
unlink($filename);
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-06-17 18:40:04 +00:00
|
|
|
function setAlbumPublic($albumID) {
|
|
|
|
global $database;
|
|
|
|
$query = "SELECT public FROM lychee_albums WHERE id = '$albumID';";
|
|
|
|
$result = $database->query($query);
|
|
|
|
$row = $result->fetch_object();
|
|
|
|
if($row->public == 0){
|
|
|
|
$public = 1;
|
|
|
|
}else{
|
|
|
|
$public = 0;
|
|
|
|
}
|
|
|
|
$query = "UPDATE lychee_albums SET public = '$public', password = NULL WHERE id = '$albumID';";
|
|
|
|
$result = $database->query($query);
|
|
|
|
if(!$result) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
function setAlbumPassword($albumID, $password) {
|
|
|
|
global $database;
|
|
|
|
$query = "UPDATE lychee_albums SET password = '$password' WHERE id = '$albumID';";
|
|
|
|
$result = $database->query($query);
|
|
|
|
if(!$result) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
function isAlbumPublic($albumID, $password) {
|
|
|
|
global $database;
|
|
|
|
$query = "SELECT public, password FROM lychee_albums WHERE id = '$albumID';";
|
|
|
|
$result = $database->query($query);
|
|
|
|
$row = $result->fetch_object();
|
|
|
|
if(($row->public == 1) && ($row->password == $password)){
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-10-02 15:48:08 +00:00
|
|
|
|
|
|
|
// Photo Functions
|
|
|
|
function getPhotos($albumID) {
|
2013-06-17 18:40:04 +00:00
|
|
|
global $database, $sorting;
|
2012-10-02 15:48:08 +00:00
|
|
|
switch($albumID) {
|
2013-06-17 18:40:04 +00:00
|
|
|
case "f": $query = "SELECT id, title, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE star = 1 ORDER BY id $sorting;";
|
2012-10-02 15:48:08 +00:00
|
|
|
break;
|
2013-06-17 18:40:04 +00:00
|
|
|
case "s": $query = "SELECT id, title, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE public = 1 ORDER BY id $sorting;";
|
2012-10-02 15:48:08 +00:00
|
|
|
break;
|
2013-06-17 18:40:04 +00:00
|
|
|
default: $query = "SELECT id, title, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE album = '$albumID' ORDER BY id $sorting;";
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
$i = 0;
|
2013-05-03 11:57:08 +00:00
|
|
|
while($row = $result->fetch_array()) {
|
2012-10-02 15:48:08 +00:00
|
|
|
$return[$i] = $row;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
if($i==0) return false;
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
function getPhotoInfo($photoID) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database;
|
|
|
|
if(!is_numeric($photoID)) {
|
|
|
|
$query = "SELECT COUNT(*) AS quantity FROM lychee_photos WHERE import_name = '../uploads/import/$photoID';";
|
|
|
|
$result = $database->query($query);
|
|
|
|
$row = $result->fetch_object();
|
|
|
|
if($row->quantity == 0) {
|
2013-06-17 18:40:04 +00:00
|
|
|
importPhoto($photoID, 's');
|
2013-05-03 11:57:08 +00:00
|
|
|
}
|
|
|
|
if(is_file("../uploads/import/$photoID")) {
|
2013-06-17 18:40:04 +00:00
|
|
|
importPhoto($photoID, 's');
|
2013-05-03 11:57:08 +00:00
|
|
|
}
|
|
|
|
$query = "SELECT * FROM lychee_photos WHERE import_name = '../uploads/import/$photoID' ORDER BY ID DESC;";
|
|
|
|
} else {
|
|
|
|
$query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
|
|
|
|
}
|
|
|
|
$result = $database->query($query);
|
|
|
|
$return = $result->fetch_array();
|
2012-10-02 15:48:08 +00:00
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
function downloadPhoto($photoID) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database;
|
|
|
|
$query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
|
|
|
|
$result = $database->query($query);
|
|
|
|
$row = $result->fetch_object();
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
$photo = "../".$row->url;
|
|
|
|
$title = $row->title;
|
|
|
|
$type = "appcication/zip";
|
|
|
|
$filename = "./imageDownload.zip";
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
$zip = new ZipArchive();
|
|
|
|
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) return false;
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
$newFile = explode("/",$photo);
|
|
|
|
$newFile = array_reverse($newFile);
|
|
|
|
$zip->addFile($photo, $title.$newFile[0]);
|
|
|
|
$zip->close();
|
|
|
|
header("Content-Type: $type");
|
|
|
|
header("Content-Disposition: attachment; filename=\"$title.zip\"");
|
|
|
|
readfile($filename);
|
|
|
|
unlink($filename);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
function setPhotoPublic($photoID, $url) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database;
|
|
|
|
$query = "SELECT public, shortlink FROM lychee_photos WHERE id = '$photoID';";
|
|
|
|
$result = $database->query($query);
|
|
|
|
$row = $result->fetch_object();
|
2012-10-02 15:48:08 +00:00
|
|
|
if($row->public == 0){
|
|
|
|
$public = 1;
|
|
|
|
}else{
|
|
|
|
$public = 0;
|
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
if($public==0 || preg_match('/localhost/', $_SERVER['HTTP_REFERER']) || preg_match('\file:\/\/\/', $_SERVER['HTTP_REFERER'])) {
|
2012-10-02 15:48:08 +00:00
|
|
|
$shortlink = "";
|
|
|
|
}else{
|
|
|
|
if($row->shortlink==""){
|
2013-01-15 20:21:36 +00:00
|
|
|
$shortlink = urlShortner($url);
|
2012-10-02 15:48:08 +00:00
|
|
|
}else{
|
|
|
|
$shortlink = $row->shortlink;
|
|
|
|
}
|
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "UPDATE lychee_photos SET public = '$public', shortlink = '$shortlink' WHERE id = '$photoID';";
|
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
if(!$result) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
function setPhotoStar($photoID) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database;
|
|
|
|
$query = "SELECT star FROM lychee_photos WHERE id = '$photoID';";
|
|
|
|
$result = $database->query($query);
|
|
|
|
$row = $result->fetch_object();
|
2012-10-02 15:48:08 +00:00
|
|
|
if($row->star == 0) {
|
|
|
|
$star = 1;
|
|
|
|
} else {
|
|
|
|
$star = 0;
|
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "UPDATE lychee_photos SET star = '$star' WHERE id = '$photoID';";
|
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-06-17 18:40:04 +00:00
|
|
|
function nextPhoto($photoID, $albumID, $innerCall) {
|
|
|
|
global $database, $sorting;
|
|
|
|
if (!$innerCall&&$sorting=="ASC") return previousPhoto($photoID, $albumID, true);
|
2012-10-02 15:48:08 +00:00
|
|
|
switch($albumID) {
|
2013-05-03 11:57:08 +00:00
|
|
|
case 'f': $query = "SELECT * FROM lychee_photos WHERE id < '$photoID' AND star = '1' ORDER BY id DESC LIMIT 0, 1;";
|
2012-10-02 15:48:08 +00:00
|
|
|
break;
|
2013-05-03 11:57:08 +00:00
|
|
|
case 's': $query = "SELECT * FROM lychee_photos WHERE id < '$photoID' AND public = '1' ORDER BY id DESC LIMIT 0, 1;";
|
2012-10-02 15:48:08 +00:00
|
|
|
break;
|
2013-05-03 11:57:08 +00:00
|
|
|
default: $query = "SELECT * FROM lychee_photos WHERE id < '$photoID' AND album = '$albumID' ORDER BY id DESC LIMIT 0, 1;";
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
$result = $database->query($query);
|
|
|
|
$return = $result->fetch_array();
|
2012-10-02 15:48:08 +00:00
|
|
|
if(!$return || ($return==0)) {
|
|
|
|
switch($albumID) {
|
2013-05-03 11:57:08 +00:00
|
|
|
case 'f': $query = "SELECT * FROM lychee_photos WHERE star = '1' ORDER BY id DESC LIMIT 0, 1;";
|
2012-10-02 15:48:08 +00:00
|
|
|
break;
|
2013-05-03 11:57:08 +00:00
|
|
|
case 's': $query = "SELECT * FROM lychee_photos WHERE public = '1' ORDER BY id DESC LIMIT 0, 1;";
|
2012-10-02 15:48:08 +00:00
|
|
|
break;
|
2013-05-03 11:57:08 +00:00
|
|
|
default: $query = "SELECT * FROM lychee_photos WHERE album = '$albumID' ORDER BY id DESC LIMIT 0, 1;";
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
$result = $database->query($query);
|
|
|
|
$return = $result->fetch_array();
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
2013-01-15 20:21:36 +00:00
|
|
|
return $return;
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
2013-06-17 18:40:04 +00:00
|
|
|
function previousPhoto($photoID, $albumID, $innerCall) {
|
|
|
|
global $database, $sorting;
|
|
|
|
if (!$innerCall&&$sorting=="ASC") return nextPhoto($photoID, $albumID, true);
|
2012-10-02 15:48:08 +00:00
|
|
|
switch($albumID) {
|
2013-06-17 18:40:04 +00:00
|
|
|
case 'f': $query = "SELECT * FROM lychee_photos WHERE id > '$photoID' AND star = '1' ORDER BY id LIMIT 0, 1;";
|
2012-10-02 15:48:08 +00:00
|
|
|
break;
|
2013-06-17 18:40:04 +00:00
|
|
|
case 's': $query = "SELECT * FROM lychee_photos WHERE id > '$photoID' AND public = '1' ORDER BY id LIMIT 0, 1;";
|
2012-10-02 15:48:08 +00:00
|
|
|
break;
|
2013-06-17 18:40:04 +00:00
|
|
|
default: $query = "SELECT * FROM lychee_photos WHERE id > '$photoID' AND album = '$albumID' ORDER BY id LIMIT 0, 1;";
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
$result = $database->query($query);
|
|
|
|
$return = $result->fetch_array();
|
2012-10-02 15:48:08 +00:00
|
|
|
if(!$return || ($return==0)) {
|
|
|
|
switch($albumID) {
|
2013-05-03 11:57:08 +00:00
|
|
|
case 'f': $query = "SELECT * FROM lychee_photos WHERE star = '1' ORDER BY id LIMIT 0, 1;";
|
2012-10-02 15:48:08 +00:00
|
|
|
break;
|
2013-05-03 11:57:08 +00:00
|
|
|
case 's': $query = "SELECT * FROM lychee_photos WHERE public = '1' ORDER BY id LIMIT 0, 1;";
|
2012-10-02 15:48:08 +00:00
|
|
|
break;
|
2013-05-03 11:57:08 +00:00
|
|
|
default: $query = "SELECT * FROM lychee_photos WHERE album = '$albumID' ORDER BY id LIMIT 0, 1;";
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
$result = $database->query($query);
|
|
|
|
$return = $result->fetch_array();
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
2013-06-17 18:40:04 +00:00
|
|
|
function setAlbum($photoID, $newAlbum) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database;
|
|
|
|
$query = "UPDATE lychee_photos SET album = '$newAlbum' WHERE id = '$photoID';";
|
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
if(!$result) return false;
|
|
|
|
else return true;
|
|
|
|
}
|
|
|
|
function setPhotoTitle($photoID, $title) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database;
|
|
|
|
$title = mysqli_real_escape_string($database, urldecode($title));
|
2012-10-25 10:22:04 +00:00
|
|
|
if(strlen($title)>30) return false;
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "UPDATE lychee_photos SET title = '$title' WHERE id = '$photoID';";
|
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
if(!$result) return false;
|
|
|
|
else return true;
|
|
|
|
}
|
|
|
|
function setPhotoDescription($photoID, $description) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database;
|
|
|
|
$description = mysqli_real_escape_string($database, htmlentities($description));
|
2012-10-02 15:48:08 +00:00
|
|
|
if(strlen($description)>160) return false;
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "UPDATE lychee_photos SET description = '$description' WHERE id = '$photoID';";
|
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
if(!$result) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
function deletePhoto($photoID) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database;
|
|
|
|
$query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
|
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
if(!$result) return false;
|
2013-05-03 11:57:08 +00:00
|
|
|
$row = $result->fetch_object();
|
|
|
|
$retinaUrl = explode(".", $row->thumbUrl);
|
2012-10-02 15:48:08 +00:00
|
|
|
$unlink1 = unlink("../".$row->url);
|
|
|
|
$unlink2 = unlink("../".$row->thumbUrl);
|
2013-05-03 11:57:08 +00:00
|
|
|
$unlink3 = unlink("../".$retinaUrl[0].'@2x.'.$retinaUrl[1]);
|
|
|
|
$query = "DELETE FROM lychee_photos WHERE id = '$photoID';";
|
|
|
|
$result = $database->query($query);
|
|
|
|
if(!$unlink1 || !$unlink2 || !$unlink3) return false;
|
2012-10-02 15:48:08 +00:00
|
|
|
if(!$result) return false;
|
|
|
|
return true;
|
|
|
|
}
|
2013-06-17 18:40:04 +00:00
|
|
|
function importPhoto($name, $albumID) {
|
2013-05-03 11:57:08 +00:00
|
|
|
$tmp_name = "../uploads/import/$name";
|
|
|
|
$details = getimagesize($tmp_name);
|
|
|
|
$size = filesize($tmp_name);
|
|
|
|
$nameFile = array(array());
|
|
|
|
$nameFile[0]['name'] = $name;
|
|
|
|
$nameFile[0]['type'] = $details['mime'];
|
|
|
|
$nameFile[0]['tmp_name'] = $tmp_name;
|
|
|
|
$nameFile[0]['error'] = 0;
|
|
|
|
$nameFile[0]['size'] = $size;
|
2013-06-17 18:40:04 +00:00
|
|
|
if(!upload($nameFile, $albumID)) return false;
|
2013-05-03 11:57:08 +00:00
|
|
|
else return true;
|
|
|
|
}
|
2013-06-17 18:40:04 +00:00
|
|
|
function importUrl($url, $albumID) {
|
|
|
|
if (@getimagesize($url)) {
|
|
|
|
$pathinfo = pathinfo($url);
|
|
|
|
$filename = $pathinfo['filename'].".".$pathinfo['extension'];
|
|
|
|
$tmp_name = "../uploads/import/$filename";
|
|
|
|
copy($url, $tmp_name);
|
|
|
|
return importPhoto($filename, $albumID);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-10-02 15:48:08 +00:00
|
|
|
|
|
|
|
// Share Functions
|
|
|
|
function urlShortner($url) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database, $bitlyUsername, $bitlyApi;
|
2012-10-02 15:48:08 +00:00
|
|
|
if($bitlyUsername==""||$bitlyApi=="") return false;
|
|
|
|
$url = urlencode($url);
|
|
|
|
$bitlyAPI = "http://api.bit.ly/shorten?version=2.0.1&format=xml&longUrl=$url&login=$bitlyUsername&apiKey=$bitlyApi";
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
$data = file_get_contents($bitlyAPI);
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
$xml = simplexml_load_string($data);
|
|
|
|
$shortlink = $xml->results->nodeKeyVal->shortUrl;
|
|
|
|
return $shortlink;
|
|
|
|
}
|
2013-06-17 18:40:04 +00:00
|
|
|
function getShortlink($photoID) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database;
|
|
|
|
$query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
|
|
|
|
$result = $database->query($query);
|
|
|
|
$row = $result->fetch_object();
|
2013-06-17 18:40:04 +00:00
|
|
|
return $row->shortlink;
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
|
|
|
function facebookHeader($photoID) {
|
2013-05-03 11:57:08 +00:00
|
|
|
$database = dbConnect();
|
2012-10-02 15:48:08 +00:00
|
|
|
if(!is_numeric($photoID)) return false;
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
|
|
|
|
$result = $database->query($query);
|
|
|
|
$row = $result->fetch_object();
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
$parseUrl = parse_url("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
|
|
|
|
$thumb = $parseUrl['scheme']."://".$parseUrl['host'].$parseUrl['path']."/../".$row->thumbUrl;
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
$return = '<meta name="title" content="'.$row->title.'" />';
|
|
|
|
$return .= '<meta name="description" content="'.$row->description.' - via Lychee" />';
|
|
|
|
$return .= '<link rel="image_src" type="image/jpeg" href="'. $thumb .'" />';
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
return $return;
|
|
|
|
}
|
2013-06-17 18:40:04 +00:00
|
|
|
function isPhotoPublic($photoID, $password) {
|
2013-05-03 11:57:08 +00:00
|
|
|
global $database;
|
|
|
|
$photoID = mysqli_real_escape_string($database, $photoID);
|
|
|
|
if(is_numeric($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);
|
|
|
|
$row = $result->fetch_object();
|
|
|
|
if (!is_numeric($photoID)&&!$row) return true;
|
2013-06-17 18:40:04 +00:00
|
|
|
if($row->public == 1) return true;
|
|
|
|
else return isAlbumPublic($row->album, $password);
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Search Function
|
|
|
|
function search($term) {
|
2013-06-17 18:40:04 +00:00
|
|
|
global $database, $sorting;
|
2013-05-03 11:57:08 +00:00
|
|
|
$term = mysqli_real_escape_string($database, $term);
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "SELECT * FROM lychee_photos WHERE title like '%$term%' OR description like '%$term%';";
|
|
|
|
$result = $database->query($query);
|
|
|
|
while($row = $result->fetch_array()) {
|
2012-10-02 15:48:08 +00:00
|
|
|
$return['photos'][] = $row;
|
|
|
|
}
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
$query = "SELECT * FROM lychee_albums WHERE title like '%$term%';";
|
|
|
|
$result = $database->query($query);
|
2012-10-02 15:48:08 +00:00
|
|
|
$i=0;
|
2013-05-03 11:57:08 +00:00
|
|
|
while($row = $result->fetch_array()) {
|
2012-10-02 15:48:08 +00:00
|
|
|
$return['albums'][$i] = $row;
|
2013-06-17 18:40:04 +00:00
|
|
|
$query2 = "SELECT thumbUrl FROM lychee_photos WHERE album = '".$row['id']."' ORDER BY id $sorting LIMIT 0, 3;";
|
2013-05-03 11:57:08 +00:00
|
|
|
$result2 = $database->query($query2);
|
2012-10-02 15:48:08 +00:00
|
|
|
$k = 0;
|
2013-05-03 11:57:08 +00:00
|
|
|
while($row2 = $result2->fetch_object()){
|
2012-10-02 15:48:08 +00:00
|
|
|
$return['albums'][$i]["thumb$k"] = $row2->thumbUrl;
|
|
|
|
$k++;
|
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
$i++;
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|