Lychee 1.2

- Share whole albums
- Public Mode
- Import images via URL
- New Share-Button
- Improved Toolbar
- Check for updates (see config.php)
- ASC or DESC sorting (see config.php)
- Download album fixed
- Code optimizations (thanks @tibounise)
- Changes and enhancements

Update from version 1.0 or 1.1:
1. Replace all files, excluding `uploads/`
2. Open php/config.php and reconfigure your installation (We added new settings)
3. Open php/update.php in your browser
This commit is contained in:
Tobias Reich 2013-06-17 20:40:04 +02:00
parent b0dccfb3e0
commit 4e5c836b8d
26 changed files with 890 additions and 561 deletions

View File

@ -25,10 +25,10 @@ html, body {
body { background-color: #222; background-image: url(../img/background.jpg); font-family:'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; -webkit-font-smoothing: antialiased; }
.center { left: 50%; top:50%; position: absolute; }
* {
-webkit-transition: opacity .3s ease-out, -webkit-transform .3s ease-out, box-shadow .3s;
-webkit-transition: color .3s, opacity .3s ease-out, -webkit-transform .3s ease-out, box-shadow .3s;
-moz-transition: opacity .3s ease-out, -moz-transform .3s ease-out, box-shadow .3s;
-o-transition: opacity .3s ease-out, -o-transform .3s ease-out, box-shadow .3s;
transition: opacity .3s ease-out, transform .3s ease-out, box-shadow .3s;
transition: color .3s, opacity .3s ease-out, transform .3s ease-out, box-shadow .3s;
}
/* Tooltip ------------------------------------------------*/
@ -193,6 +193,7 @@ body { background-color: #222; background-image: url(../img/background.jpg); fon
background-color: #2f0d0e;
background-repeat: repeat-x;
z-index: 1;
display: none;
/* Animation */
-webkit-animation-name: moveBackground;
@ -235,7 +236,7 @@ body { background-color: #222; background-image: url(../img/background.jpg); fon
/* Header ------------------------------------------------*/
header {
position: fixed;
height: 40px;
height: 41px;
width: 100%;
background-color: #333;
@ -279,7 +280,7 @@ header {
position: absolute;
margin: 0px 30%;
width: 40%;
margin-top: 11px;
padding: 11px 0px;
color: #fff;
font-size: 16px;
font-weight: bold;
@ -345,23 +346,17 @@ header {
font-family: 'FontAwesome';
font-size: 16px;
}
#tools_albums, #tools_album, #tools_photo {
#tools_albums, #tools_album, #tools_photo, #button_signin {
display: none;
}
/* Button Custom ------------------------------------------------*/
header .button.icon-refresh {
padding: 7px 10px 4px 10px;
}
/* Button Divider ------------------------------------------------*/
header .button_divider {
float: right;
position: relative;
margin-right: 11px;
margin-top: 1px;
margin: 1px 12px 0px 0px;
width: 1px;
height: 39px;
height: 40px;
background-color: transparent;
background-image: -webkit-gradient(linear, left top, left bottom, from(rgb(68, 68, 68)), to(rgb(37, 37, 37)));
background-image: -webkit-linear-gradient(top, rgba(68, 68, 68, 0), rgb(25, 25, 25));
@ -372,7 +367,7 @@ header {
border-right: 1px solid #555;
}
header .button_divider.less {
margin-right: 8px;
margin: 1px 6px 0px 6px;
}
@ -380,7 +375,7 @@ header {
#search {
float: right;
width: 80px;
margin: 7px 8px 0px 0px;
margin: 7px 12px 0px 0px;
padding: 5px 10px 7px 10px;
background-color: #444;
color: #fff;
@ -398,31 +393,28 @@ header {
#search:focus {
box-shadow: 0px 1px 0px #555, inset 0px 0px 2px #333;
opacity: 1;
width: 150px;
width: 140px;
}
/* Tools ------------------------------------------------*/
.tools:first-of-type {
margin-right: 6px;
}
.tools {
float: right;
padding: 5px 5px 5px 5px;
margin: 5px 8px 0px 0px;
font-family: 'IconicStroke';
padding: 10px 8px;
color: #aaa;
font-size: 21px;
text-shadow: 0px -1px 0px #222;
border-radius: 3px;
cursor: pointer;
}
.tools a.list {
line-height: 21px;
}
.tools:hover a {
color: #fff;
}
.tools .icon-star {
color: #f0ef77;
}
.tools .icon-rss.active {
.tools .icon-share.active {
color: #ff9737;
}
@ -556,8 +548,13 @@ header {
color: #fff;
font-size: 24px;
text-shadow: 0px 1px 0px #000;
font-family: 'IconicStroke';
opacity: 0.9;
opacity: .9;
}
.album .badge.icon-star, .photo .badge.icon-star {
padding: 12px 8px 3px 8px;
}
.album .badge.icon-share, .photo .badge.icon-share {
padding: 12px 6px 3px 8px;
}
.album .badge::after, .photo .badge::after {
content: "";
@ -566,7 +563,6 @@ header {
margin-left: -26px;
width: 34px;
height: 5px;
/* inset 0px 1px 1px rgba(0,0,0,.3); */
background: -moz-linear-gradient(top, rgba(0,0,0,1) 0%, rgba(0,0,0,0) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,1)), color-stop(100%,rgba(0,0,0,0))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(0,0,0,1) 0%,rgba(0,0,0,0) 100%); /* Chrome10+,Safari5.1+ */
@ -580,12 +576,16 @@ header {
margin-left: -28px;
width: 36px;
}
.album .badge.icon-share::after, .photo .badge.icon-share::after {
margin-left: -30px;
width: 38px;
}
.album .badge.icon-reorder::after {
margin-left: -30px;
width: 38px;
}
.album .badge:nth-child(2n), .photo .badge:nth-child(2n) {
margin-left: 55px;
margin-left: 57px;
}
.album .badge.red, .photo .badge.red {
background: #d64b4b;
@ -608,7 +608,7 @@ header {
.divider {
float: left;
width: 100%;
height: 31px;
height: 32px;
margin-top: 50px;
opacity: 0;
@ -623,9 +623,10 @@ header {
box-shadow: 0px 1px 0px #111, inset 0px 1px 0px rgba(255, 255, 255, .1);
}
.divider:first-child {
margin-top: 1px;
margin-top: 2px;
}
.divider h1 {
float: left;
margin: 8px 0px 0px 30px;
color: #fff;
font-size: 14px;
@ -633,6 +634,29 @@ header {
text-shadow: 0px -1px 0px #000;
}
/* No Content ------------------------------------------------*/
.no_content {
position: absolute;
top: 50%;
left: 50%;
height: 160px;
width: 180px;
margin-top: -80px;
margin-left: -90px;
padding-top: 20px;
color: rgba(20, 20, 20, 1);
text-shadow: 0px 1px 0px rgba(255, 255, 255, .05);
text-align: center;
}
.no_content .icon {
font-size: 120px;
}
.no_content p {
font-size: 18px;
}
/* Overlay ------------------------------------------------*/
.message_overlay {
position: fixed;
@ -683,9 +707,6 @@ header {
animation-timing-function: ease-out;
animation-fill-mode: forwards;
}
.message.add {
margin-top: -155px;
}
.message h1 {
float: left;
width: 100%;
@ -698,13 +719,17 @@ header {
}
.message .close {
position: absolute;
top: 10px;
right: 12px;
top: 0px;
right: 0px;
padding: 12px 14px 6px 7px;
color: #aaa;
font-size: 20px;
text-shadow: 0px -1px 0px #111;
cursor: pointer;
}
.message .close:hover {
color: #fff;
}
.message p {
float: left;
width: 90%;
@ -764,15 +789,21 @@ header {
}
/* Add Album ------------------------------------------------*/
.message.add {
width: 588px;
margin-top: -152px;
margin-left: -294px;
}
.add_album {
float: left;
display: inline-block;
width: 200px;
width: 150px;
height: 200px;
margin: 30px 0px 30px 30px;
border-radius: 3px;
border: 3px dashed #777;
cursor: pointer;
text-align: center;
-webkit-transition: border .3s;
-moz-transition: border .3s;
-o-transition: border .3s;
@ -782,15 +813,11 @@ header {
border: 3px dashed #fff;
}
.add_album .icon {
margin: 55px 65px 0px 65px;
margin-top: 55px;
color: #777;
font-family: 'FontAwesome';
font-size: 80px;
text-shadow: 0px 1px 2px #000;
-webkit-transition: color .3s;
-moz-transition: color .3s;
-o-transition: color .3s;
transition: color .3s;
}
.add_album:hover .icon {
color: #fff;
@ -802,11 +829,6 @@ header {
font-size: 14px;
font-weight: bold;
text-shadow: 0px 1px 0px #000;
text-align: center;
-webkit-transition: color .3s;
-moz-transition: color .3s;
-o-transition: color .3s;
transition: color .3s;
}
.add_album:hover a {
color: #fff;
@ -853,8 +875,14 @@ header {
color: #888;
text-shadow: 0px -1px 0px #111;
}
.message #version span {
display: none;
}
.message #version span a {
color: #888;
}
/* Sign in ------------------------------------------------*/
/* Copy Link ------------------------------------------------*/
.copylink {
float: left;
width: 95%;
@ -1018,9 +1046,8 @@ header {
text-shadow: 0px -1px 0px #000;
}
#infobox .header a {
position: absolute;
right: 15px;
margin: 10px 0px;
float: right;
padding: 10px 15px;
color: #fff;
font-size: 21px;
font-weight: bold;
@ -1126,6 +1153,19 @@ header {
background-image: -ms-linear-gradient(top, #6a84f2, #3959ef);
background-image: linear-gradient(top, #6a84f2, #3959ef);
}
.contextmenu tr.separator {
float: left;
height: 1px;
width: 100%;
background-color: #222;
box-shadow: 0px 1px 0px #555;
margin: 4px 0px 5px 0px;
cursor: inherit;
}
.contextmenu tr.separator:hover {
background-color: #222;
background-image: none;
}
.contextmenu tr td {
padding: 5px 20px 5px 10px;
-webkit-transition: none;
@ -1287,10 +1327,7 @@ header {
/* Screen behavior -------------------------------------------------*/
@media only screen and (max-width: 900px) {
#title {
margin: 11px 30% 0px 20%;
width: 50%;
}
#title { margin: 0px 30%; width: 50%; }
#title.view { margin: 11px 20% 0px 20%; width: 60%; }
#title span { display: none; }
@ -1302,10 +1339,10 @@ header {
#button_move { display: none; }
#button_archive { display: none; }
.center {
top: 0px;
left: 0px;
}
.center { top: 0px; left: 0px; }
.album { margin: 40px 0px 0px 50px; }
.photo { margin: 40px 0px 0px 50px; }
.message {
position: fixed;
@ -1325,20 +1362,20 @@ header {
animation-duration: .3s;
}
.album {
margin: 40px 0px 0px 50px;
}
.photo {
margin: 40px 0px 0px 50px;
}
.message.add {
width: 100%;
margin-top: 0px;
}
.add_album {
margin: 30px 0px -10px 55px;
width: 88%;
height: 100px;
margin: 30px 5% -10px 5%;
}
.add_album .icon {
margin-top: 18px;
font-size: 50px;
}
}

0
img/no_images.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

0
img/no_images@2x.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
img/password.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
img/password@2x.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -31,6 +31,7 @@
<!-- Buttons -->
<div id="tools_albums">
<a class="button" id="button_signout">Sign Out</a>
<a class="button" id="button_signin">Sign In</a>
<a class="button icon icon-plus-sign button_add"></a>
<a class="button_divider"></a>
<input id="search" type="text" name="search" placeholder="Search …">
@ -38,21 +39,22 @@
<div id="tools_album">
<a class="button" id="button_back_home">Back</a>
<a class="button icon icon-plus-sign button_add"></a>
<a class="button icon icon-circle-arrow-down" id="button_archive"></a>
<a class="button_divider"></a>
<div class="tools" id="button_trash_album" title="Delete Album"><a class="icon-trash"></a></div>
<div class="tools" id="button_archive" title="Download Album"><a class="icon-circle-arrow-down"></a></div>
<div class="tools" id="button_edit_album" title="Edit Title"><a class="icon-edit"></a></div>
<div class="tools" id="button_share_album" title="Share Album"><a class="icon-share"></a></div>
</div>
<div id="tools_photo">
<a class="button" id="button_back">Back</a>
<div class="tools" id="button_trash" title="Delete"><a class="icon-trash"></a></div>
<div class="tools" id="button_move" title="Move to Album"><a class="icon-folder-open"></a></div>
<div class="tools" id="button_download" title="Full Photo"><a class="icon-resize-full"></a></div>
<a class="button_divider less"></a>
<div class="tools" id="button_info" title="Show Info"><a class="icon-info-sign"></a></div>
<div class="tools" id="button_edit" title="Edit Title"><a class="icon-edit"></a></div>
<a class="button_divider less"></a>
<div class="tools" id="button_share" title="Share Photo"><a class="icon-rss"></a></div>
<div class="tools" id="button_download" title="Full Photo"><a class="icon-resize-full"></a></div>
<div class="tools" id="button_info" title="Show Info"><a class="icon-info-sign"></a></div>
<a class="button_divider less"></a>
<div class="tools" id="button_share" title="Share Photo"><a class="icon-share"></a></div>
<div class="tools" id="button_star" title="Star Photo"><a class="icon-star-empty"></a></div>
</div>

File diff suppressed because one or more lines are too long

View File

@ -15,10 +15,7 @@ $(document).ready(function(){
else event_name = "click";
/* Toolbar */
$("#button_signout").on(event_name, function() {
modal = build.modal("Sign Out", "Are you sure you want to leave and log out?", ["Sign out", "Stay here"], ["lychee.logout();", ""]);
$("body").append(modal);
});
$("#button_signout").on(event_name, lychee.logout);
$("#button_download").on(event_name, function() {
link = $("#image_view #image").css("background-image").replace(/"/g,"").replace(/url\(|\)$/ig, "");
window.open(link,"_newtab");
@ -27,11 +24,15 @@ $(document).ready(function(){
if ($("#button_share a.active").length) contextMenu.share(lychee.image_view.attr("data-id"), e.pageX, e.pageY);
else photos.setPublic(e);
});
$("#button_share_album").on(event_name, function(e) {
if ($("#button_share_album a.active").length) contextMenu.share_album(lychee.content.attr("data-id"), e.pageX, e.pageY);
else albums.setPublic(e);
});
$("#button_trash_album").on(event_name, function() { albums.deleteDialog(lychee.content.attr("data-id")) });
$("#button_move").on(event_name, function(e) { contextMenu.move(lychee.image_view.attr("data-id"), e.pageX, e.pageY) });
$("#button_trash").on(event_name, function() { photos.deleteDialog() });
$("#button_edit_album").on(event_name, function() { albums.rename() });
$("#button_edit").on(event_name, function() { photos.rename() });
$("#button_edit_album").on(event_name, function() { albums.setTitle() });
$("#button_edit").on(event_name, function() { photos.setTitle() });
$("#button_info").on(event_name, function() { photos.showInfobox() });
$("#button_archive").on(event_name, function() { albums.getArchive() });
$("#button_star").on(event_name, function() { photos.setStar() });
@ -52,7 +53,7 @@ $(document).ready(function(){
/* Infobox */
$("#infobox")
.on(event_name, ".header a", function() { photos.hideInfobox() })
.on(event_name, "#edit_title", function() { photos.rename() })
.on(event_name, "#edit_title", function() { photos.setTitle() })
.on(event_name, "#edit_description", function() { photos.setDescription() });
/* Keyboard */
@ -72,7 +73,7 @@ $(document).ready(function(){
Mousetrap.bindGlobal('esc', function(e) {
e.preventDefault();
if ($(".message").length&&$(".sign_in").length==0) lychee.closeModal();
if ($(".message").length) lychee.closeModal();
else if (visible.infobox()) photos.hideInfobox();
else if (visible.imageview()) lychee.goto("a" + lychee.content.attr("data-id"));
else if (visible.albums()&&$("#search").val().length!=0) search.reset();
@ -82,10 +83,11 @@ $(document).ready(function(){
$(document)
/* Login */
.on(event_name, "#button_signin", function() { lychee.showLogin() })
.on("keyup", "#password", function() { if ($(this).val().length>0) $(this).removeClass("error") })
/* Toolbar */
.on(event_name, "#title.editable", function() { if (visible.imageview()) photos.rename(); else albums.rename(); })
.on(event_name, "#title.editable", function() { if (visible.imageview()) photos.setTitle(); else albums.setTitle(); })
/* Navigation */
.on("click", ".album", function() { lychee.goto("a" + $(this).attr("data-id")) })
@ -100,6 +102,7 @@ $(document).ready(function(){
/* Add Dialog */
.on(event_name, ".button_add", function() { $("body").append(build.addModal) })
.on(event_name, "#add_album", albums.add)
.on(event_name, "#add_link", lychee.importUrl)
.on(event_name, "#add_photo", function() { $("#auswahl").html(""); $("#upload_files").click() })
/* Upload */
@ -115,12 +118,16 @@ $(document).ready(function(){
/* Controls */
.bind("mouseenter", lychee.showControls)
.bind("mouseleave", lychee.hideControls);
.bind("mouseleave", lychee.hideControls)
/* Upload */
$(document.documentElement)
.on("dragover", function(e) { e.preventDefault(); }, false)
.on("drop", function (e) { e.stopPropagation(); e.preventDefault(); lychee.upload(e.originalEvent.dataTransfer.files); return true; });
.on("drop", function(e) {
e.stopPropagation();
e.preventDefault();
lychee.upload(e.originalEvent.dataTransfer.files);
return true;
});
/* Init */
lychee.ready();

148
js/modules/albums.js Normal file → Executable file
View File

@ -12,7 +12,6 @@ albums = {
load: function() {
loadingBar.show();
lychee.animate(".album, .photo", "contentZoomOut");
/* Search */
@ -59,7 +58,8 @@ albums = {
if (data.publicThumb1) publicAlbum.thumb1 = lychee.upload_path + data.publicThumb1; else publicAlbum.thumb1 = "";
if (data.publicThumb2) publicAlbum.thumb2 = lychee.upload_path + data.publicThumb2; else publicAlbum.thumb2 = "";
smartData = build.divider("Smart Albums") + build.album(unsortedAlbum) + build.album(starredAlbum) + build.album(publicAlbum);
if (lychee.publicMode) smartData = "";
else smartData = build.divider("Smart Albums") + build.album(unsortedAlbum) + build.album(starredAlbum) + build.album(publicAlbum);
/* Albums */
if (data.albums) {
@ -69,66 +69,80 @@ albums = {
} else albumsData = "";
if (smartData==""&&albumsData=="") $("body").append(build.no_content("picture"));
else {
lychee.content.html(smartData + albumsData);
lychee.animate(".album, .photo", "contentZoomIn");
}
document.title = "Lychee";
lychee.headerTitle.html("Albums").removeClass("editable");
$("img").retina();
loadingBar.hide();
});
})
},
loadInfo: function(albumID) {
loadInfo: function(albumID, password) {
if (albumID=="f"||albumID=="s"||albumID==0) {
lychee.headerTitle.removeClass("editable");
$("#button_edit_album, #button_trash_album, #button_share_album").hide();
lychee.api("getSmartInfo", "json", function(data) {
switch (albumID) {
case "f":
document.title = "Lychee - Starred";
lychee.headerTitle.html("Starred<span> - " + data.starredNum + " photos</span>");
$("#button_edit_album, #button_trash_album, .button_divider").hide();
break;
case "s":
document.title = "Lychee - Public";
lychee.headerTitle.html("Public<span> - " + data.publicNum + " photos</span>");
$("#button_edit_album, #button_trash_album, .button_divider").hide();
break;
case "0":
document.title = "Lychee - Unsorted";
lychee.headerTitle.html("Unsorted<span> - " + data.unsortNum + " photos</span>");
$("#button_edit_album").hide();
$("#button_trash_album, .button_divider").show();
$("#button_trash_album").show();
break;
}
loadingBar.hide();
});
} else {
params = "getAlbumInfo&albumID=" + albumID;
lychee.api(params, "json", function(data) {
/*if (lychee.publicMode&&password==undefined) {
password = localStorage.getItem("album" + albumID);
if (password==null) {
if (lychee.publicMode) password = prompt("Please enter a password for this album:", ""); else password = "";
if (password!="") password = hex_md5(password);
localStorage.setItem("album" + albumID, password);
}
}*/
$("#button_edit_album, #button_trash_album, .button_divider").show();
password = "";
$("#button_edit_album, #button_trash_album, #button_share_album, .button_divider").show();
params = "getAlbumInfo&albumID=" + albumID + "&password=" + password;
lychee.api(params, "json", function(data) {
if (!data.title) data.title = "Untitled";
document.title = "Lychee - " + data.title;
lychee.headerTitle.html(data.title + "<span> - " + data.num + " photos</span>").addClass("editable");
loadingBar.hide();
if (data.public=="1") {
$("#button_share_album a").addClass("active");
$("#button_share_album").attr("title", "Share Album");
} else {
$("#button_share_album a").removeClass("active");
$("#button_share_album").attr("title", "Make Public");
}
});
@ -141,9 +155,7 @@ albums = {
title = prompt("Please enter a title for this album:", "Untitled");
lychee.closeModal();
if (title.length>2&&title.length<31) {
loadingBar.show();
if (title.length>0&&title.length<31) {
params = "addAlbum&title=" + escape(title);
lychee.api(params, "text", function(data) {
@ -170,19 +182,13 @@ albums = {
delete: function(albumID, delAll) {
loadingBar.show();
params = "deleteAlbum&albumID=" + albumID + "&delAll=" + delAll;
lychee.api(params, "text", function(data) {
if (data) {
if (visible.albums()) {
albums.hide(albumID);
loadingBar.hide();
} else lychee.goto("");
if (visible.albums()) albums.hide(albumID);
else lychee.goto("");
} else loadingBar.show("error");
@ -213,16 +219,14 @@ albums = {
},
rename: function(albumID) {
setTitle: function(albumID) {
if (!albumID) oldTitle = lychee.title(); else oldTitle = "";
if (!albumID) albumID = lychee.content.attr("data-id");
newTitle = prompt("Please enter a new title for this album:", oldTitle);
if (albumID!=""&&albumID!=null&&albumID&&newTitle.length>2&&newTitle.length<31) {
loadingBar.show();
if (albumID!=""&&albumID!=null&&albumID&&newTitle.length>0&&newTitle.length<31) {
params = "setAlbumTitle&albumID=" + albumID + "&title=" + encodeURI(newTitle);
lychee.api(params, "text", function(data) {
@ -233,7 +237,6 @@ albums = {
lychee.headerTitle.html(newTitle + "<span>" + $("#title span").html() + "</span>");
document.title = "Lychee - " + newTitle;
}
loadingBar.hide();
} else loadingBar.show("error");
});
@ -242,6 +245,87 @@ albums = {
},
setPublic: function(e) {
albumID = lychee.content.attr("data-id");
params = "setAlbumPublic&albumID=" + albumID;
lychee.api(params, "text", function(data) {
if (data) {
if ($("#button_share_album a.active").length) {
$("#button_share_album a").removeClass("active");
$("#button_share_album").attr("title", "Make Public");
} else {
$("#button_share_album a").addClass("active");
$("#button_share_album").attr("title", "Share Album");
contextMenu.share_album(albumID, e.pageX, e.pageY);
}
} else loadingBar.show("error");
});
},
setPassword: function(albumID, password) {
if (!albumID) albumID = lychee.content.attr("data-id");
if (!password) password = prompt("Please enter a password for this album:", "");
if (password!="") password = hex_md5(password);
params = "setAlbumPassword&albumID=" + albumID + "&password=" + password;
lychee.api(params, "text", function(data) {
if (!data) loadingBar.show("error");
});
},
/*checkAlbumPassword: function(albumID, password) {
params = "checkAlbumPassword&albumID=" + albumID + "&password=" + hex_md5(password);
lychee.api(params, "text", function(data) {
if (data) {
if (password!="") password = hex_md5(password);
localStorage.setItem("album" + albumID, password);
return true;
} else return false;
});
},*/
share: function(service, albumID) {
link = "";
url = location.href;
switch (service) {
case 0:
link = "https://twitter.com/share?url=" + encodeURI(url);
break;
case 1:
link = "http://www.facebook.com/sharer.php?u=" + encodeURI(url) + "&t=" + encodeURI(lychee.title());
break;
case 2:
link = "mailto:?subject=" + encodeURI(lychee.title()) + "&body=" + encodeURI("Hi! Check this out: " + url);
break;
case 3:
modal = build.modal("Copy Link", "Everyone can view your public albums, but only you can edit them. Use this link to share your album with others: <input class='copylink' value='" + url + "'>", ["Close"], [""]);
$("body").append(modal);
$(".copylink").focus();
break;
default:
link = "";
break;
}
if (link.length>5) location.href = link;
},
getArchive: function() {
albumID = lychee.content.attr("data-id");

View File

@ -18,26 +18,38 @@ build = {
album: function(albumJSON) {
var album = "";
if(!albumJSON) return "";
if (albumJSON.password&&lychee.publicMode) {
albumJSON.thumb0 = "img/password.png";
albumJSON.thumb1 = "img/password.png";
albumJSON.thumb2 = "img/password.png";
} else {
if(!albumJSON.thumb0) albumJSON.thumb0 = "img/no_images.png";
if(!albumJSON.thumb1) albumJSON.thumb1 = "img/no_images.png";
if(!albumJSON.thumb2) albumJSON.thumb2 = "img/no_images.png";
}
if(!albumJSON.title) albumJSON.title = "Untitled";
if(albumJSON.title.length>18) albumJSON.title = albumJSON.title.substr(0, 18) + "...";
var album = "";
album += "<div class='album' data-id='" + albumJSON.id + "'>";
album += "<div class='album' data-id='" + albumJSON.id + "' data-password='" + albumJSON.password + "'>";
album += "<img src='" + lychee.upload_path + albumJSON.thumb2 + "' width='200' height='200' alt='thumb'>";
album += "<img src='" + lychee.upload_path + albumJSON.thumb1 + "' width='200' height='200' alt='thumb'>";
album += "<img src='" + lychee.upload_path + albumJSON.thumb0 + "' width='200' height='200' alt='thumb'>";
album += "<div class='overlay'>";
album += "<h1>" + albumJSON.title + "</h1>";
if (albumJSON.password&&!lychee.publicMode) album += "<h1><span class='icon-lock' title='Public album with password'></span> " + albumJSON.title + "</h1>";
else album += "<h1>" + albumJSON.title + "</h1>";
album += "<a>" + albumJSON.sysdate + "</a>";
album += "</div>";
if(albumJSON.star=="1") album += "<a class='badge red icon-star'></a>";
if(albumJSON.public=="1") album += "<a class='badge red icon-rss'></a>";
if(albumJSON.unsorted=="1") album += "<a class='badge red icon-reorder'></a>";
if(!lychee.publicMode&&albumJSON.star=="1") album += "<a class='badge red icon-star'></a>";
if(!lychee.publicMode&&albumJSON.public=="1") album += "<a class='badge red icon-share'></a>";
if(!lychee.publicMode&&albumJSON.unsorted=="1") album += "<a class='badge red icon-reorder'></a>";
album += "</div>";
@ -47,12 +59,13 @@ build = {
photo: function(photoJSON) {
var photo = "";
if(photoJSON=="") return "";
if(!photoJSON.title) photoJSON.title = "";
if(!photoJSON.thumbUrl) photoJSON.thumbUrl = "img/no_image.png";
if(photoJSON.title.length>18) photoJSON.title = photoJSON.title.substr(0, 18) + "...";
var photo = "";
photo += "<div class='photo' data-album-id='" + photoJSON.album + "' data-id='" + photoJSON.id + "'>";
photo += "<img src='" + lychee.upload_path + photoJSON.thumbUrl + "' width='200' height='200' alt='thumb'>";
photo += "<div class='overlay'>";
@ -61,7 +74,7 @@ build = {
photo += "</div>";
if(photoJSON.star=="1") photo += "<a class='badge red icon-star'></a>";
if(photoJSON.public=="1") photo += "<a class='badge red icon-rss'></a>";
if(!lychee.publicMode&&photoJSON.public=="1") photo += "<a class='badge red icon-share'></a>";
photo += "</div>";
@ -69,9 +82,26 @@ build = {
},
no_content: function(typ) {
var no_content = "";
no_content += "<div class='no_content fadeIn'>";
no_content += "<a class='icon icon-" + typ + "'></a>";
if (typ=="search") no_content += "<p>No results</p>";
else if (typ=="picture") no_content += "<p>No public albums</p>";
no_content += "</div>";
return no_content;
},
modal: function(title, text, button, func) {
var modal = "";
modal += "<div class='message_overlay fadeIn'>";
modal += "<div class='message center'>";
modal += "<h1>" + title + "</h1>";
@ -117,11 +147,15 @@ build = {
modal += "<a class='close icon-remove-sign'></a>";
modal += "<div id='add_album' class='add_album'>";
modal += "<div class='icon icon-folder-close'></div>";
modal += "<a>Add new Album</a>";
modal += "<a>New Album</a>";
modal += "</div>";
modal += "<div id='add_link' class='add_album'>";
modal += "<div class='icon icon-link'></div>";
modal += "<a>Import Link</a>";
modal += "</div>";
modal += "<div id='add_photo' class='add_album'>";
modal += "<div class='icon icon-picture'></div>";
modal += "<a>Upload new Photo</a>";
modal += "<a>Upload Photo</a>";
modal += "</div>";
modal += "</div>";
modal += "</div>";
@ -135,12 +169,12 @@ build = {
var modal = "";
modal += "<div class='message_overlay'>";
modal += "<div class='message center'>";
modal += "<h1><a class='icon-lock'></a> Sign in</h1>";
modal += "<h1><a class='icon-lock'></a> Sign In</h1>";
modal += "<div class='sign_in'>";
modal += "<input id='username' type='text' name='' value='' placeholder='username'>";
modal += "<input id='password' type='password' name='' value='' placeholder='password'>";
modal += "</div>";
modal += "<div id='version'>Version " + lychee.version + "</div>";
modal += "<div id='version'>Version " + lychee.version + "<span> &#8211; <a target='_blank' href='" + lychee.updateURL + "'>Update available!</a><span></div>";
modal += "<a onclick='lychee.login()' class='button active'>Sign in</a>";
modal += "</div>";
modal += "</div>";
@ -173,9 +207,8 @@ build = {
$.each(items, function(index) {
if (items[index][1].length!=0) {
menu += "<tr><td onclick='" + items[index][1] + "; contextMenu.close();'>" + items[index][0] + "</td></tr>";
}
if (items[index][0]=="separator"&&items[index][1].length==0) menu += "<tr class='separator'></tr>";
else if (items[index][1].length!=0) menu += "<tr><td onclick='" + items[index][1] + "; contextMenu.close();'>" + items[index][0] + "</td></tr>";
});
@ -194,8 +227,8 @@ build = {
infobox += "<div class='wrapper'>";
if (photo.public==1) photo.public = "Public"; else photo.public = "Private";
if (forView==true) editTitleHTML = ""; else editTitleHTML = " <div id='edit_title'><a class='icon-pencil'></a></div>";
if (forView==true) editDescriptionHTML = ""; else editDescriptionHTML = " <div id='edit_description'><a class='icon-pencil'></a></div>";
if (forView==true||lychee.publicMode) editTitleHTML = ""; else editTitleHTML = " <div id='edit_title'><a class='icon-pencil'></a></div>";
if (forView==true||lychee.publicMode) editDescriptionHTML = ""; else editDescriptionHTML = " <div id='edit_description'><a class='icon-pencil'></a></div>";
infos = [
["", "Basics"],
@ -215,7 +248,7 @@ build = {
["Focal Length", photo.focal],
["ISO", photo.iso],
["", "Share"],
["Privacy", photo.public],
["Visibility", photo.public],
["Short Link", photo.shortlink]
];

65
js/modules/contextMenu.js Normal file → Executable file
View File

@ -22,7 +22,7 @@ contextMenu = {
mouse_y -= $(document).scrollTop();
items = [
["Rename", "albums.rename(" + albumID + ")"],
["Rename", "albums.setTitle(" + albumID + ")"],
["Delete", "albums.deleteDialog(" + albumID + ")"]
];
@ -47,7 +47,7 @@ contextMenu = {
mouse_y -= $(document).scrollTop();
items = [
["Rename", "photos.rename(" + photoID + ")"],
["Rename", "photos.setTitle(" + photoID + ")"],
["Move to Album", "contextMenu.move(" + photoID + ", " + (mouse_x+150) + ", " + (mouse_y+$(document).scrollTop()) + ")"],
["Delete", "photos.deleteDialog(" + photoID + ")"]
];
@ -67,25 +67,30 @@ contextMenu = {
mouse_y -= $(document).scrollTop();
if (!mouse_x||!mouse_y) {
mouse_x = "10px";
mouse_y = "10px";
}
lychee.api("getAlbums", "json", function(data) {
if (lychee.content.attr("data-id")==0) {
items = [];
} else {
items = [
["Unsorted", "photos.move(" + photoID + ", 0)"]
["Unsorted", "photos.setAlbum(" + photoID + ", 0)"]
];
}
if (!data.albums) {
items = [
["Create new Album", "albums.add()"]
["New Album", "albums.add()"]
];
} else {
$.each(data.album, function(index) {
if (this.id!=lychee.content.attr("data-id")) {
if(!this.title) this.title = "Untitled";
items[items.length] = new Array(this.title, "photos.move(" + photoID + ", " + this.id + ")");
items[items.length] = new Array(this.title, "photos.setAlbum(" + photoID + ", " + this.id + ")");
} else {
items[items.length] = new Array("", "");
}
@ -98,7 +103,7 @@ contextMenu = {
$("body").append(build.contextMenu(items));
$(".contextmenu").css({
"top": mouse_y,
"left": mouse_x-150
"left": mouse_x-$(".contextmenu").width()
});
});
@ -109,19 +114,57 @@ contextMenu = {
mouse_y -= $(document).scrollTop();
if (!mouse_x||!mouse_y) {
mouse_x = "10px";
mouse_y = "10px";
}
items = [
["<a class='icon-eye-close'></a> Make Private", "photos.setPublic()"],
["separator", ""],
["<a class='icon-twitter'></a> Twitter", "photos.share(0, " + photoID + ")"],
["<a class='icon-facebook'></a> Facebook", "photos.share(1, " + photoID + ")"],
["<a class='icon-envelope'></a> Mail", "photos.share(2, " + photoID + ")"],
["<a class='icon-link'></a> Copy Link", "photos.share(3, " + photoID + ")"],
["<a class='icon-link'></a> Copy Shortlink", "photos.share(4, " + photoID + ")"]
["<a class='icon-link'></a> Copy Link", "photos.share(3, " + photoID + ")"]
];
if (lychee.bitlyUsername!="") items.push(["<a class='icon-link'></a> Copy Shortlink", "photos.share(4, " + photoID + ")"]);
contextMenu.close();
$("body")
.css("overflow", "hidden")
.append(build.contextMenu(items));
$(".photo[data-id='" + photoID + "']").addClass("active");
$(".contextmenu").css({
"top": mouse_y,
"left": mouse_x
});
},
share_album: function(albumID, mouse_x, mouse_y) {
mouse_y -= $(document).scrollTop();
if (!mouse_x||!mouse_y) {
mouse_x = "10px";
mouse_y = "10px";
}
items = [
["<a class='icon-eye-close'></a> Make Private", "albums.setPublic()"],
//["<a class='icon-key'></a> Set Password", "albums.setPassword()"],
["separator", ""],
["<a class='icon-twitter'></a> Twitter", "albums.share(0, " + albumID + ")"],
["<a class='icon-facebook'></a> Facebook", "albums.share(1, " + albumID + ")"],
["<a class='icon-envelope'></a> Mail", "albums.share(2, " + albumID + ")"],
["<a class='icon-link'></a> Copy Link", "albums.share(3, " + albumID + ")"]
];
contextMenu.close();
$("body").css("overflow", "hidden");
$(".photo[data-id='" + photoID + "']").addClass("active");
$("body").append(build.contextMenu(items));
$("body")
.css("overflow", "hidden")
.append(build.contextMenu(items));
$(".contextmenu").css({
"top": mouse_y,
"left": mouse_x

38
js/modules/loadingBar.js Normal file → Executable file
View File

@ -10,44 +10,50 @@
loadingBar = {
status: null,
show: function(status, errorTitle, errorText) {
if (!status) status = "loading";
clearTimeout(lychee.loadingBar.data("timeout"));
switch (status) {
if (status=="error"&&loadingBar.status!="error") {
loadingBar.status = "error";
if (!errorTitle) errorTitle = "Error";
if (!errorText) errorText = "Whoops, it looks like something went wrong. Please reload the site and try again!"
case "error":
if (!errorTitle||!errorText) {
errorTitle = "Error";
errorText = "Whoops, it looks like something went wrong. Please reload the site and try again!"
}
lychee.loadingBar
.removeClass("loading uploading error")
.addClass(status)
.html("<h1>" + errorTitle + ": <span>" + errorText + "</span></h1>")
.show()
.css("height", "40px");
lychee.header.css("margin-Top", "40px");
$.timer(3000,function(){ loadingBar.hide() });
break;
if (visible.controls()) lychee.header.css("margin-Top", "40px");
lychee.loadingBar.data("timeout", setTimeout(function () { loadingBar.hide(true) }, 3000));
} else if (loadingBar.status==null) {
loadingBar.status = "loading";
case "loading":
clearTimeout(lychee.loadingBar.data("timeout"));
lychee.loadingBar.data("timeout", setTimeout(function () {
lychee.loadingBar
.show()
.removeClass("loading uploading error")
.addClass(status);
.addClass("loading");
if (visible.controls()) lychee.header.css("margin-Top", "3px");
}, 1000));
break;
}
},
hide: function() {
hide: function(force_hide) {
if ((loadingBar.status!="error"&&loadingBar.status!=null)||force_hide) {
loadingBar.status = null;
clearTimeout(lychee.loadingBar.data("timeout"));
lychee.loadingBar.html("").css("height", "3px");
if (visible.controls()) lychee.header.css("marginTop", "0px");
@ -56,3 +62,5 @@ loadingBar = {
}
}
}

114
js/modules/lychee.js Normal file → Executable file
View File

@ -12,9 +12,15 @@ lychee = {
init: function(api_path, upload_path) {
this.version = "1.1";
this.version = "1.2";
this.api_path = api_path;
this.upload_path = upload_path;
this.update_path = "http://lychee.electerious.com/version/index.php";
this.updateURL = "https://github.com/electerious/Lychee";
this.publicMode = false;
this.checkForUpdates = false;
this.bitlyUsername = "";
this.loadingBar = $("#loading");
this.header = $("header");
@ -27,41 +33,70 @@ lychee = {
ready: function() {
$("#tools_albums").show();
if (!mobileBrowser()) $(".tools").tipsy({gravity: 'n'});
if (window.webkitNotifications) { window.webkitNotifications.requestPermission() };
if (window.webkitNotifications) window.webkitNotifications.requestPermission();
lychee.api("loggedIn", "text", function(data) {
if (data!=1) {
$("body").append(build.signInModal());
$("#username").focus();
if (localStorage) {
local_username = localStorage.getItem("username");
if (local_username==null) return false;
if (local_username.length>1) $("#username").val(local_username);
$("#password").focus();
}
} else if (data) {
lychee.api("init", "json", function(data) {
lychee.checkForUpdates = data.config.checkForUpdates;
lychee.bitlyUsername = data.config.bitlyUsername;
if (!data.loggedIn) lychee.setPublicMode();
$(window).bind("popstate", lychee.load);
lychee.load();
}
});
},
api: function(params, type, callback) {
setPublicMode: function() {
this.publicMode = true;
$("#button_signout, #search, #button_trash_album, #button_share_album, #button_edit_album, .button_add, #button_archive, .button_divider").remove();
$("#button_trash, #button_move, #button_edit, #button_share, #button_star").remove();
$(document)
.on("mouseenter", "#title.editable", function() { $(this).removeClass("editable") })
.off(event_name, "#title.editable")
.off("contextmenu", ".photo")
.off("contextmenu", ".album")
.off("drop");
$("#button_signin").show();
},
api: function(params, type, callback, loading) {
if (loading==undefined) loadingBar.show();
$.ajax({
type: "POST",
url: lychee.api_path,
data: "function=" + params,
dataType: type,
success: callback,
success:
function(data) {
$.timer(100, function(){ loadingBar.hide() });
callback(data);
},
error: lychee.error
});
},
showLogin: function() {
$("body").append(build.signInModal());
$("#username").focus();
if (localStorage) {
local_username = localStorage.getItem("username");
if (local_username==null) return false;
if (local_username.length>0) $("#username").val(local_username);
$("#password").focus();
}
if (lychee.checkForUpdates) lychee.update();
},
login: function() {
user = $("input#username").val();
@ -70,10 +105,8 @@ lychee = {
params = "login&user=" + user + "&password=" + password;
lychee.api(params, "text", function(data) {
if (data) {
if (localStorage) { localStorage.setItem("username", user); }
$(window).bind("popstate", lychee.load);
lychee.load();
lychee.closeModal();
localStorage.setItem("username", user);
window.location.reload();
} else {
$("#password").val("").addClass("error");
$(".message .button.active").removeClass("pressed");
@ -90,6 +123,15 @@ lychee = {
},
update: function() {
$.ajax({
url: lychee.update_path,
success: function(data) { if (data!=lychee.version) $("#version span").show(); }
});
},
upload: function(files) {
pre_progress = 0;
@ -151,6 +193,30 @@ lychee = {
},
importUrl: function() {
link = prompt("Please enter the direct link to a photo to import it:", "");
if (lychee.content.attr("data-id")=="") albumID = 0;
else albumID = lychee.content.attr("data-id");
lychee.closeModal();
if (link.length>3) {
params = "importUrl&url=" + escape(link) + "&albumID=" + albumID;
lychee.api(params, "text", function(data) {
if (data) {
if (lychee.content.attr("data-id")=="") lychee.goto("a0");
else photos.load(lychee.content.attr("data-id"));
} else loadingBar.show("error");
});
} else if (link.length>0) loadingBar.show("error", "Error", "Link to short or too long. Please try another one!");
},
load: function() {
contextMenu.close();
@ -168,11 +234,11 @@ lychee = {
if (albumID&&photoID) {
// Show ImageView
if (lychee.content.html()==""||$("#search").val().length!=0) {
if (lychee.content.html()==""||($("#search").length&&$("#search").val().length!=0)) {
lychee.content.hide();
photos.load(albumID, true);
}
photos.loadInfo(photoID);
photos.loadInfo(photoID, albumID);
} else if (albumID) {
@ -232,7 +298,7 @@ lychee = {
hideControls: function() {
if (visible.imageview()) {
if (visible.imageview()&&!visible.infobox()) {
clearTimeout($(window).data("timeout"));
$(window).data("timeout", setTimeout(function() {
lychee.image_view.addClass("full");

110
js/modules/photos.js Normal file → Executable file
View File

@ -14,6 +14,15 @@ photos = {
// If refresh is true the function will only refresh the content and not change the toolbar buttons either the title
/*password = localStorage.getItem("album" + albumID);
if (password==null) {
if (lychee.publicMode) password = prompt("Please enter a password for this album:", ""); else password = "";
if (password!="") password = hex_md5(password);
localStorage.setItem("album" + albumID, password);
}*/
password = "";
if (!refresh) {
loadingBar.show();
if (visible.imageview()) photos.hideView();
@ -23,9 +32,15 @@ photos = {
startTime = new Date().getTime();
params = "getPhotos&albumID=" + albumID;
params = "getPhotos&albumID=" + albumID + "&password=" + password;
lychee.api(params, "json", function(data) {
if (data=="HTTP/1.1 403 Wrong password!") {
localStorage.removeItem("album" + albumID);
photos.load(albumID, refresh);
return false;
}
durationTime = (new Date().getTime() - startTime);
if (durationTime>300) waitTime = 0; else if (refresh) waitTime = 0; else waitTime = 300 - durationTime;
@ -42,25 +57,38 @@ photos = {
$("#tools_album").show();
$("img").retina();
albums.loadInfo(albumID);
albums.loadInfo(albumID, password);
}
});
}, false);
});
},
loadInfo: function(photoID) {
loadInfo: function(photoID, albumID) {
/*password = localStorage.getItem("album" + albumID);
if (password==null) {
if (lychee.publicMode) password = prompt("Please enter a password for this album:", ""); else password = "";
if (password!="") password = hex_md5(password);
localStorage.setItem("album" + albumID, password);
}*/
password = "";
photos.showView();
loadingBar.show();
params = "getPhotoInfo&photoID=" + photoID;
params = "getPhotoInfo&photoID=" + photoID + "&password=" + password;
lychee.api(params, "json", function(data) {
if (data=="HTTP/1.1 403 Wrong password!") {
localStorage.removeItem("album" + albumID);
photos.loadInfo(photoID, albumID);
return false;
}
if (!data.title) data.title = "Untitled";
document.title = "Lychee - " + data.title;
@ -77,10 +105,10 @@ photos = {
if (data.public=="1") {
$("#button_share a").addClass("active");
$("#button_share").attr("title", "Make Photo Private");
$("#button_share").attr("title", "Share Photo");
} else {
$("#button_share a").removeClass("active");
$("#button_share").attr("title", "Share Photo");
$("#button_share").attr("title", "Make Public");
}
data.url = lychee.upload_path + data.url;
@ -99,8 +127,6 @@ photos = {
$.timer(300,function(){ lychee.content.show(); });
loadingBar.hide();
});
},
@ -180,8 +206,6 @@ photos = {
delete: function(photoID) {
loadingBar.show();
params = "deletePhoto&photoID=" + photoID;
lychee.api(params, "text", function(data) {
@ -189,7 +213,6 @@ photos = {
photos.hide(photoID);
lychee.goto("a" + lychee.content.attr("data-id"));
loadingBar.hide();
} else loadingBar.show("error");
@ -212,7 +235,7 @@ photos = {
},
rename: function(photoID) {
setTitle: function(photoID) {
if (!photoID) oldTitle = lychee.title(); else oldTitle = "";
if (!photoID) photoID = lychee.image_view.attr("data-id");
@ -221,8 +244,6 @@ photos = {
if (photoID!=null&&photoID&&newTitle.length<31) {
loadingBar.show();
if (newTitle=="") newTitle = "Untitled";
params = "setPhotoTitle&photoID=" + photoID + "&title=" + encodeURI(newTitle);
@ -235,7 +256,6 @@ photos = {
document.title = "Lychee - " + newTitle;
}
$(".photo[data-id='" + photoID + "'] .overlay h1").html(newTitle);
loadingBar.hide();
} else loadingBar.show("error");
});
@ -244,19 +264,16 @@ photos = {
},
move: function(photoID, albumID) {
setAlbum: function(photoID, albumID) {
if (albumID>=0) {
loadingBar.show();
params = "movePhoto&photoID=" + photoID + "&albumID=" + albumID;
params = "setAlbum&photoID=" + photoID + "&albumID=" + albumID;
lychee.api(params, "text", function(data) {
if (data) {
photos.hide(photoID);
lychee.goto("a" + lychee.content.attr("data-id"));
loadingBar.hide();
} else loadingBar.show("error");
});
@ -267,8 +284,6 @@ photos = {
setStar: function() {
loadingBar.show();
photoID = lychee.image_view.attr("data-id");
params = "setPhotoStar&photoID=" + photoID;
@ -285,7 +300,6 @@ photos = {
}
photos.load(lychee.content.attr("data-id"), true);
loadingBar.hide();
} else loadingBar.show("error");
@ -295,8 +309,6 @@ photos = {
setPublic: function(e) {
loadingBar.show();
photoID = lychee.image_view.attr("data-id");
params = "setPhotoPublic&photoID=" + photoID + "&url=" + photos.getViewLink(photoID);
@ -306,15 +318,16 @@ photos = {
if ($("#button_share a.active").length) {
$("#button_share a").removeClass("active");
$("#button_share").attr("title", "Make Private");
$("#button_share").attr("title", "Make Public");
$("#infobox .attr_visibility").html("Private");
} else {
$("#button_share a").addClass("active");
$("#button_share").attr("title", "Share Photo");
$("#infobox .attr_visibility").html("Public");
contextMenu.share(photoID, e.pageX, e.pageY);
}
photos.load(lychee.content.attr("data-id"), true);
loadingBar.hide();
} else loadingBar.show("error");
@ -329,13 +342,12 @@ photos = {
if (description.length>0&&description.length<160) {
loadingBar.show();
params = "setPhotoDescription&photoID=" + photoID + "&description=" + escape(description);
lychee.api(params, "text", function(data) {
if (data) photos.loadInfo(photoID);
else loadingBar.show("error");
if (data) {
$("#infobox .attr_description").html(description + " <div id='edit_description'><a class='icon-pencil'></a></div>");
} else loadingBar.show("error");
});
@ -345,45 +357,39 @@ photos = {
share: function(service, photoID) {
loadingBar.show();
params = "sharePhoto&photoID=" + photoID + "&url=" + photos.getViewLink(photoID);
lychee.api(params, "json", function(data) {
link = "";
url = photos.getViewLink(photoID);
switch (service) {
case 0:
link = data.twitter;
link = "https://twitter.com/share?url=" + encodeURI(url);
break;
case 1:
link = data.facebook;
link = "http://www.facebook.com/sharer.php?u=" + encodeURI(url) + "&t=" + encodeURI(lychee.title());
break;
case 2:
link = data.mail;
link = "mailto:?subject=" + encodeURI(lychee.title()) + "&body=" + encodeURI("Hi! Check this out: " + url);
break;
case 3:
link = "copy";
modal = build.modal("Copy Link", "You can use this link to share your image with other people: <input class='copylink' value='" + photos.getViewLink(photoID) + "'>", ["Close"], [""]);
modal = build.modal("Copy Link", "Everyone can view your public photos, but only you can edit them. Use this link to share your photo with others: <input class='copylink' value='" + url + "'>", ["Close"], [""]);
$("body").append(modal);
$(".copylink").focus();
break;
case 4:
link = "copy";
modal = build.modal("Copy Shortlink", "You can use this link to share your image with other people: <input class='copylink' value='" + data.shortlink + "'>", ["Close"], [""]);
params = "getShortlink&photoID=" + photoID;
lychee.api(params, "text", function(data) {
if (data=="") data = "Something went wrong!";
modal = build.modal("Copy Shortlink", "Everyone can view your public photos, but only you can edit them. Use this link to share your photo with others: <input class='copylink' value='" + data + "'>", ["Close"], [""]);
$("body").append(modal);
$(".copylink").focus();
});
break;
default:
link = "";
break;
}
if (link=="copy") loadingBar.hide();
else if (link.length>5) {
location.href = link;
loadingBar.hide();
} else loadingBar.show("error");
});
if (link.length>5) location.href = link;
},

9
js/modules/search.js Normal file → Executable file
View File

@ -26,21 +26,27 @@ search = {
photosData = "";
if (data&&data.photos) $.each(data.photos, function() { photosData += build.photo(this); });
if (albumsData==""&&photosData=="") code = "";
if (albumsData==""&&photosData=="") code = "error";
else if (albumsData=="") code = build.divider("Photos")+photosData;
else if (photosData=="") code = build.divider("Albums")+albumsData;
else code = build.divider("Photos")+photosData+build.divider("Albums")+albumsData;
if (lychee.content.attr("data-search")!=code) {
$(".no_content").remove();
lychee.animate(".album, .photo", "contentZoomOut");
lychee.animate(".divider", "fadeOut");
$.timer(300,function(){
lychee.content.attr("data-search", code);
if (code=="error") $("body").append(build.no_content("search"));
else {
lychee.content.html(code);
lychee.animate(".album, .photo", "contentZoomIn");
}
});
@ -57,6 +63,7 @@ search = {
reset: function() {
$("#search").val("");
$(".no_content").remove();
if (lychee.content.attr("data-search")!="") {

0
js/modules/visible.js Normal file → Executable file
View File

View File

@ -80,7 +80,7 @@ function hideInfobox() {
function loadPhotoInfo(photoID) {
params = "function=getPhotoInfo&photoID=" + photoID;
params = "function=getPhotoInfo&photoID=" + photoID + "&password=''";
$.ajax({type: "POST", url: api_path, data: params, dataType: "json", success: function(data) {
if (!data.title) data.title = "Untitled";

2
lychee.sql Normal file → Executable file
View File

@ -10,6 +10,8 @@ CREATE TABLE IF NOT EXISTS `lychee_albums` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(50) NOT NULL,
`sysdate` varchar(10) NOT NULL,
`public` TINYINT(1) DEFAULT '0',
`password` VARCHAR(100),
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

106
php/api.php Normal file → Executable file
View File

@ -7,79 +7,101 @@
* @copyright 2013 by Philipp Maurer, Tobias Reich
*/
if(floatval(phpversion())<5.2) die("Please upgrade to PHP 5.2 or higher!");
if (floatval(phpversion())<5.2) die('Please upgrade to PHP 5.2 or higher!');
if((isset($_POST["function"])&&$_POST["function"]!="")||(isset($_GET["function"])&&$_GET["function"]!="")) {
if (!empty($_POST['function'])||!empty($_GET['function'])) {
session_start();
define("LYCHEE", true);
define('LYCHEE', true);
include("array2json.php");
include("config.php");
include("functions.php");
require('config.php');
require('functions.php');
// Security
if(isset($_POST["albumID"])&&($_POST["albumID"]==""||$_POST["albumID"]<0)) exit("Wrong parameter type for 'albumID'!");
if(isset($_POST["photoID"])&&$_POST["photoID"]=="") exit("Wrong parameter type for 'photoID'!");
if($_SESSION["login"]==true) {
if (isset($_POST['albumID'])&&($_POST['albumID']==''||$_POST['albumID']<0)) exit('Wrong parameter type for albumID!');
if (isset($_POST['photoID'])&&$_POST['photoID']=='') exit('Wrong parameter type for photoID!');
//Connect to DB
$database = dbConnect();
if (isset($_SESSION['login'])&&$_SESSION['login']==true) {
/**
* Admin Mode
* Full access to Lychee. Only with correct password.
*/
// Album Functions
if($_POST["function"]=="getAlbums") echo array2json(getAlbums());
if($_POST["function"]=="getSmartInfo") echo array2json(getSmartInfo());
if($_POST["function"]=="addAlbum"&&isset($_POST["title"])) echo addAlbum($_POST["title"]);
if($_POST["function"]=="getAlbumInfo"&&isset($_POST["albumID"])) echo array2json(getAlbumInfo($_POST["albumID"]));
if($_POST["function"]=="setAlbumTitle"&&isset($_POST["albumID"])&&isset($_POST["title"])) echo setAlbumTitle($_POST["albumID"], $_POST["title"]);
if($_POST["function"]=="deleteAlbum"&&isset($_POST["albumID"])&&isset($_POST["delAll"])) echo deleteAlbum($_POST["albumID"], $_POST["delAll"]);
if($_GET["function"]=="getAlbumArchive"&&isset($_GET["albumID"])) getAlbumArchive($_GET["albumID"]);
if ($_POST['function']=='getAlbums') echo json_encode(getAlbums(false));
if ($_POST['function']=='getSmartInfo') echo json_encode(getSmartInfo());
if ($_POST['function']=='addAlbum'&&isset($_POST['title'])) echo addAlbum($_POST['title']);
if ($_POST['function']=='getAlbumInfo'&&isset($_POST['albumID'])) echo json_encode(getAlbumInfo($_POST['albumID']));
if ($_POST['function']=='setAlbumTitle'&&isset($_POST['albumID'])&&isset($_POST['title'])) echo setAlbumTitle($_POST['albumID'], $_POST['title']);
if ($_POST['function']=='setAlbumPublic'&&isset($_POST['albumID'])) echo setAlbumPublic($_POST['albumID']);
if ($_POST['function']=='setAlbumPassword'&&isset($_POST['albumID'])&&isset($_POST['password'])) echo setAlbumPassword($_POST['albumID'], $_POST['password']);
if ($_POST['function']=='deleteAlbum'&&isset($_POST['albumID'])&&isset($_POST['delAll'])) echo deleteAlbum($_POST['albumID'], $_POST['delAll']);
if (isset($_GET['function'])&&$_GET['function']=='getAlbumArchive'&&isset($_GET['albumID'])) getAlbumArchive($_GET['albumID']);
// Photo Functions
if($_POST["function"]=="getPhotos"&&isset($_POST["albumID"])) echo array2json(getPhotos($_POST["albumID"]));
if($_POST["function"]=="getPhotoInfo"&&isset($_POST["photoID"])) echo array2json(getPhotoInfo($_POST["photoID"]));
if($_POST["function"]=="movePhoto"&&isset($_POST["photoID"])&&isset($_POST["albumID"])) echo movePhoto($_POST["photoID"], $_POST["albumID"]);
if($_POST["function"]=="deletePhoto"&&isset($_POST["photoID"])) echo deletePhoto($_POST["photoID"]);
if($_POST["function"]=="setPhotoTitle"&&isset($_POST["photoID"])&&isset($_POST["title"])) echo setPhotoTitle($_POST["photoID"], $_POST["title"]);
if($_POST["function"]=="setPhotoStar"&&isset($_POST["photoID"])) echo setPhotoStar($_POST["photoID"]);
if($_POST["function"]=="setPhotoPublic"&&isset($_POST["photoID"])&&isset($_POST["url"])) echo setPhotoPublic($_POST["photoID"], $_POST["url"]);
if($_POST["function"]=="setPhotoDescription"&&isset($_POST["photoID"])&&isset($_POST["description"])) echo setPhotoDescription($_POST["photoID"], $_POST["description"]);
if($_POST["function"]=="sharePhoto"&&isset($_POST["photoID"])&&isset($_POST["url"])) echo array2json(sharePhoto($_POST["photoID"], $_POST["url"]));
if($_POST["function"]=="previousPhoto"&&isset($_POST["photoID"])&&isset($_POST["albumID"])) echo array2json(previousPhoto($_POST["photoID"], $_POST["albumID"]));
if($_POST["function"]=="nextPhoto"&&isset($_POST["photoID"])&&isset($_POST["albumID"])) echo array2json(nextPhoto($_POST["photoID"], $_POST["albumID"]));
if ($_POST['function']=='getPhotos'&&isset($_POST['albumID'])) echo json_encode(getPhotos($_POST['albumID']));
if ($_POST['function']=='getPhotoInfo'&&isset($_POST['photoID'])) echo json_encode(getPhotoInfo($_POST['photoID']));
if ($_POST['function']=='getShortlink'&&isset($_POST['photoID'])) echo getShortlink($_POST['photoID']);
if ($_POST['function']=='setAlbum'&&isset($_POST['photoID'])&&isset($_POST['albumID'])) echo setAlbum($_POST['photoID'], $_POST['albumID']);
if ($_POST['function']=='deletePhoto'&&isset($_POST['photoID'])) echo deletePhoto($_POST['photoID']);
if ($_POST['function']=='setPhotoTitle'&&isset($_POST['photoID'])&&isset($_POST['title'])) echo setPhotoTitle($_POST['photoID'], $_POST['title']);
if ($_POST['function']=='setPhotoStar'&&isset($_POST['photoID'])) echo setPhotoStar($_POST['photoID']);
if ($_POST['function']=='setPhotoPublic'&&isset($_POST['photoID'])&&isset($_POST['url'])) echo setPhotoPublic($_POST['photoID'], $_POST['url']);
if ($_POST['function']=='setPhotoDescription'&&isset($_POST['photoID'])&&isset($_POST['description'])) echo setPhotoDescription($_POST['photoID'], $_POST['description']);
if ($_POST['function']=='previousPhoto'&&isset($_POST['photoID'])&&isset($_POST['albumID'])) echo json_encode(previousPhoto($_POST['photoID'], $_POST['albumID'], false));
if ($_POST['function']=='nextPhoto'&&isset($_POST['photoID'])&&isset($_POST['albumID'])) echo json_encode(nextPhoto($_POST['photoID'], $_POST['albumID'], false));
// Upload Function
if($_POST["function"]=="upload"&&isset($_FILES)&&isset($_POST["albumID"])) echo upload($_FILES, $_POST["albumID"]);
// Add Function
if ($_POST['function']=='upload'&&isset($_FILES)&&isset($_POST['albumID'])) echo upload($_FILES, $_POST['albumID']);
if ($_POST['function']=='importUrl'&&isset($_POST['url'])&&isset($_POST['albumID'])) echo importUrl($_POST['url'], $_POST['albumID']);
// Search Function
if($_POST["function"]=="search"&&isset($_POST["term"])) echo array2json(search($_POST["term"]));
// Sync Function
if($_POST["function"]=="syncFolder") echo syncFolder();
if ($_POST['function']=='search'&&isset($_POST['term'])) echo json_encode(search($_POST['term']));
// Session Functions
if($_POST["function"]=="login") echo login($_POST['user'], $_POST['password']);
if($_POST["function"]=="logout") logout();
if($_POST["function"]=="loggedIn") echo true;
if ($_POST['function']=='init') echo json_encode(init('admin'));
if ($_POST['function']=='login') echo login($_POST['user'], $_POST['password']);
if ($_POST['function']=='logout') logout();
} else {
$database = dbConnect();
/**
* Public Mode
* Access to view all public folders and photos in Lychee.
*/
// Album Functions
if ($_POST['function']=='getAlbums') echo json_encode(getAlbums(true));
if ($_POST['function']=='getAlbumInfo'&&isset($_POST['albumID'])&&isset($_POST['password'])&&isAlbumPublic($_POST['albumID'], $_POST['password'])) echo json_encode(getAlbumInfo($_POST['albumID']));
// Photo Functions
if($_POST["function"]=="getPhotoInfo"&&isset($_POST["photoID"])&&isPhotoPublic($_POST["photoID"])) echo array2json(getPhotoInfo($_POST["photoID"]));
if ($_POST['function']=='getPhotos') {
if (isset($_POST['albumID'])&&isset($_POST['password'])&&isAlbumPublic($_POST['albumID'], $_POST['password'])) echo json_encode(getPhotos($_POST['albumID']));
else echo json_encode('HTTP/1.1 403 Wrong password!');
}
if ($_POST['function']=='getPhotoInfo') {
if (isset($_POST['photoID'])&&isset($_POST['password'])&&isPhotoPublic($_POST['photoID'], $_POST['password'])) echo json_encode(getPhotoInfo($_POST['photoID']));
else echo json_encode('HTTP/1.1 403 Wrong password!');
}
if ($_POST['function']=='previousPhoto'&&isset($_POST['photoID'])&&isset($_POST['albumID'])) echo json_encode(previousPhoto($_POST['photoID'], $_POST['albumID'], false));
if ($_POST['function']=='nextPhoto'&&isset($_POST['photoID'])&&isset($_POST['albumID'])) echo json_encode(nextPhoto($_POST['photoID'], $_POST['albumID'], false));
// Session Functions
if($_POST["function"]=="login") echo login($_POST['user'], $_POST['password']);
if($_POST["function"]=="loggedIn") echo false;
if ($_POST['function']=='init') echo json_encode(init('public'));
if ($_POST['function']=='login') echo login($_POST['user'], $_POST['password']);
}
} else {
header('HTTP/1.1 401 Unauthorized');
die("Error: No permission!");
die('Error: No permission!');
}

View File

@ -1,43 +0,0 @@
<?php
function array2json($arr) {
if(function_exists('json_encode')) return json_encode($arr); //Lastest versions of PHP already has this functionality.
$parts = array();
$is_list = false;
//Find out if the given array is a numerical array
$keys = array_keys($arr);
$max_length = count($arr)-1;
if(($keys[0] == 0) and ($keys[$max_length] == $max_length)) {//See if the first key is 0 and last key is length - 1
$is_list = true;
for($i=0; $i<count($keys); $i++) { //See if each key correspondes to its position
if($i != $keys[$i]) { //A key fails at position check.
$is_list = false; //It is an associative array.
break;
}
}
}
foreach($arr as $key=>$value) {
if(is_array($value)) { //Custom handling for arrays
if($is_list) $parts[] = array2json($value); /* :RECURSION: */
else $parts[] = '"' . $key . '":' . array2json($value); /* :RECURSION: */
} else {
$str = '';
if(!$is_list) $str = '"' . $key . '":';
//Custom handling for multiple data types
if(is_numeric($value)) $str .= $value; //Numbers
elseif($value === false) $str .= 'false'; //The booleans
elseif($value === true) $str .= 'true';
else $str .= '"' . addslashes($value) . '"'; //All other things
// :TODO: Is there any more datatype we should be in the lookout for? (Object?)
$parts[] = $str;
}
}
$json = implode(',',$parts);
if($is_list) return '[' . $json . ']';//Return numerical JSON
return '{' . $json . '}';//Return associative JSON
}
?>

View File

@ -1,39 +1,45 @@
<?php
define("LYCHEE", true);
define('LYCHEE', true);
// Declare
$error = "";
$error = '';
// Include
include("config.php");
require('config.php');
// PHP Version
if (floatval(phpversion())<5.2) $error .= ("Error 100: Please upgrade to PHP 5.2 or higher!<br>\n");
if (floatval(phpversion())<5.2) $error .= ('Error 100: Please upgrade to PHP 5.2 or higher!<br>\n');
// Extensions
if (!extension_loaded("exif")) $error .= ("Error 200: PHP exif extension not activated.<br>\n");
if (!extension_loaded("mbstring")) $error .= ("Error 201: PHP mbstring extension not activated.<br>\n");
if (!extension_loaded("gd")) $error .= ("Error 202: PHP gd extension not activated.<br>\n");
if (!extension_loaded("mysqli")) $error .= ("Error 203: PHP mysqli extension not activated.<br>\n");
if (!extension_loaded('exif')) $error .= ('Error 200: PHP exif extension not activated.<br>\n');
if (!extension_loaded('mbstring')) $error .= ('Error 201: PHP mbstring extension not activated.<br>\n');
if (!extension_loaded('gd')) $error .= ('Error 202: PHP gd extension not activated.<br>\n');
if (!extension_loaded('mysqli')) $error .= ('Error 203: PHP mysqli extension not activated.<br>\n');
// Config
if (!$db||$db=="") $error .= ("Error 300: No property for \$db in config.php.<br>\n");
if (!$dbUser||$dbUser=="") $error .= ("Error 301: No property for \$dbUser in config.php.<br>\n");
if (!$dbPassword||$dbPassword=="") $error .= ("Error 302: No property for \$dbPassword in config.php.<br>\n");
if (!$dbHost||$dbHost=="") $error .= ("Error 303: No property for \$dbHost in config.php.<br>\n");
if (!$user||$user=="") $error .= ("Error 304: No property for \$user in config.php.<br>\n");
if (!$password||$password=="") $error .= ("Error 305: No property for \$password in config.php.<br>\n");
if (!$db||$db=='') $error .= ('Error 300: No property for \$db in config.php.<br>\n');
if (!$dbUser||$dbUser=='') $error .= ('Error 301: No property for \$dbUser in config.php.<br>\n');
if (!$dbPassword||$dbPassword=='') $error .= ('Error 302: No property for \$dbPassword in config.php.<br>\n');
if (!$dbHost||$dbHost=='') $error .= ('Error 303: No property for \$dbHost in config.php.<br>\n');
if (!$user||$user=='') $error .= ('Error 304: No property for \$user in config.php.<br>\n');
if (!$password||$password=='') $error .= ('Error 305: No property for \$password in config.php.<br>\n');
// Additional Config
//if ($checkForUpdates!=true&&heckForUpdates!=false) $error .= ('Error 306: No property for \$checkForUpdates in config.php.<br>\n');
if (!is_numeric($thumbQuality)||$thumbQuality<=0||$thumbQuality>=100) $error .= ('Error 307: Wrong property for \$thumbQuality in config.php.<br>\n');
if ($sorting!='ASC'&&$sorting!='DESC') $error .= ('Error 308: Wrong property for \$sorting in config.php.<br>\n');
// Database
$database = new mysqli($dbHost, $dbUser, $dbPassword, $db);
if (mysqli_connect_errno()!=0) $error .= ("Error 400: " . mysqli_connect_errno() . ": " . mysqli_connect_error() . "<br>\n");
if (mysqli_connect_errno()!=0) $error .= ('Error 400: ' . mysqli_connect_errno() . ': ' . mysqli_connect_error() . '<br>\n');
// Permissions
if (substr(sprintf('%o', fileperms("../uploads/big/")), -4) != "0777") $error .= ("Error 500: Wrong permissions for \"/uploads/big\" (777 required).<br>\n");
if (substr(sprintf('%o', fileperms("../uploads/thumb/")), -4) != "0777") $error .= ("Error 501: Wrong permissions for \"/uploads/thumb\" (777 required).<br>\n");
if (substr(sprintf('%o', fileperms("../uploads/import/")), -4) != "0777") $error .= ("Error 502: Wrong permissions for \"/uploads/import\" (777 required).<br>\n");
if (substr(sprintf('%o', fileperms('../uploads/big/')), -4)!='0777') $error .= ('Error 500: Wrong permissions for \'/uploads/big\' (777 required).<br>\n');
if (substr(sprintf('%o', fileperms('../uploads/thumb/')), -4)!='0777') $error .= ('Error 501: Wrong permissions for \'/uploads/thumb\' (777 required).<br>\n');
if (substr(sprintf('%o', fileperms('../uploads/import/')), -4)!='0777') $error .= ('Error 502: Wrong permissions for \'/uploads/import\' (777 required).<br>\n');
if (substr(sprintf('%o', fileperms('../uploads/')), -4)!='0777') $error .= ('Error 503: Wrong permissions for \'/uploads\' (777 required).<br>\n');
if ($error == "") echo("Lychee is ready!"); else echo $error;
if ($error=='') echo('Lychee is ready!'); else echo $error;
?>

View File

@ -7,21 +7,23 @@
* @copyright 2013 by Philipp Maurer, Tobias Reich
*/
if(!defined('LYCHEE')) die("Direct access is not allowed!");
if(!defined('LYCHEE')) die('Direct access is not allowed!');
// Database configurations
$db = "lychee"; //Database name
$dbUser = "lychee"; //Username of the database
$dbPassword = "lychee_passwd"; //Password of the Database
$dbHost = "localhost"; //Host of the Database
$db = 'lychee'; //Database name
$dbUser = 'lychee'; //Username of the database
$dbPassword = 'lychee_passwd'; //Password of the Database
$dbHost = 'localhost'; //Host of the Database
//Lychee user configuration
$user = "lychee"; //lychee username
$password = "1234"; //lychee password
// Admin Login
$user = 'lychee'; //Admin Username
$password = '1234'; //Admin Password
// Additional settings
$checkForUpdates = true;
$thumbQuality = 95; //Quality of the Thumbs (0-100). Default: 95
$bitlyUsername = ""; //Your Bit.ly Username
$bitlyApi = ""; //Your Bit.ly API Key
$sorting = 'DESC'; //ASC or DESC sorting of albums and photos
$bitlyUsername = ''; //Your Bit.ly Username
$bitlyApi = ''; //Your Bit.ly API Key
?>

View File

@ -7,7 +7,7 @@
* @copyright 2013 by Philipp Maurer, Tobias Reich
*/
if(!defined('LYCHEE')) die("Direct access is not allowed!");
if(!defined('LYCHEE')) die('Direct access is not allowed!');
// Database Functions
function dbConnect() {
@ -26,16 +26,14 @@ function dbConnect() {
}
function dbClose() {
global $database;
$close = $database->close();
if(!$close) {
if(!$database->close()) {
echo "Closing the connection failed!";
return false;
}
return true;
}
function createDatabase($db, $database) {
$query = "CREATE DATABASE IF NOT EXISTS $db;";
$result = $database->query($query);
$result = $database->query("CREATE DATABASE IF NOT EXISTS $db;");
$database->select_db($db);
if(!$result) return false;
return true;
@ -45,6 +43,8 @@ function createTables($database) {
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(50) NOT NULL,
`sysdate` varchar(10) NOT NULL,
`public` TINYINT(1) DEFAULT '0',
`password` VARCHAR(100),
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
$result = $database->query($query);
@ -147,7 +147,6 @@ function upload($files, $albumID) {
}
function getCamera($photoID) {
global $database;
$return = array();
$url = "../uploads/big/$photoID";
$type = getimagesize($url);
$type = $type['mime'];
@ -236,14 +235,19 @@ function createThumb($photoName, $width = 200, $width2x = 400, $height = 200, $h
}
// Session Functions
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;
}
function login($loginUser, $loginPassword) {
global $database, $user, $password;
if(($loginUser == $user) && ($loginPassword == md5($password))){
if ($loginUser==$user&&$loginPassword==md5($password)) {
// Admin Login
$_SESSION['login'] = true;
ini_set("session.cookie_lifetime","86400");
ini_set("session.gc_maxlifetime", 86400);
ini_set("session.gc_probability",1);
ini_set("session.gc_divisor",1);
return true;
} else {
return false;
@ -258,38 +262,46 @@ function logout() {
function addAlbum($title) {
global $database;
$title = mysqli_real_escape_string($database, $title);
if(strlen($title)<1||strlen($title)>30) return false;
$sysdate = date("d.m.Y");
$query = "INSERT INTO lychee_albums (title, sysdate) VALUES ('$title', '$sysdate');";
$result = $database->query($query);
if(!$result) return false;
return $database->insert_id;
}
function getAlbums() {
global $database;
$return = array(array(array()));
function getAlbums($public) {
global $database, $sorting;
// Smart Albums
$return = getSmartInfo();
if (!$public) $return = getSmartInfo();
// Albums
$query = "SELECT id, title, sysdate FROM lychee_albums ORDER BY id DESC;";
if ($public) $query = "SELECT * FROM lychee_albums WHERE public = 1 ORDER BY id $sorting;";
else $query = "SELECT * FROM lychee_albums ORDER BY id $sorting;";
$result = $database->query($query) OR die("Error: $result <br>".$database->error);
$i=0;
while($row = $result->fetch_object()) {
$return["album"][$i]['id'] = $row->id;
$return["album"][$i]['title'] = $row->title;
$return["album"][$i]['public'] = $row->public;
$return["album"][$i]['sysdate'] = $row->sysdate;
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 DESC LIMIT 0, 3;";
$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[$i]["thumb0"]="";
if(!isset($return["album"][$i]["thumb1"]))$return[$i]["thumb1"]="";
if(!isset($return["album"][$i]["thumb2"]))$return[$i]["thumb2"]="";
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"]="";
}
$i++;
}
if($i==0) $return["albums"] = false;
@ -297,9 +309,8 @@ function getAlbums() {
return $return;
}
function getSmartInfo() {
global $database;
$return = array(array());
$query = "SELECT * FROM lychee_photos WHERE album = 0 ORDER BY id DESC;";
global $database, $sorting;
$query = "SELECT * FROM lychee_photos WHERE album = 0 ORDER BY id $sorting;";
$result = $database->query($query);
$i = 0;
while($row = $result->fetch_object()) {
@ -308,7 +319,7 @@ function getSmartInfo() {
}
$return['unsortNum'] = $i;
$query2 = "SELECT * FROM lychee_photos WHERE public = 1 ORDER BY id DESC;";
$query2 = "SELECT * FROM lychee_photos WHERE public = 1 ORDER BY id $sorting;";
$result2 = $database->query($query2);
$i = 0;
while($row2 = $result2->fetch_object()) {
@ -317,7 +328,7 @@ function getSmartInfo() {
}
$return['publicNum'] = $i;
$query3 = "SELECT * FROM lychee_photos WHERE star = 1 ORDER BY id DESC;";
$query3 = "SELECT * FROM lychee_photos WHERE star = 1 ORDER BY id $sorting;";
$result3 = $database->query($query3);
$i = 0;
while($row3 = $result3->fetch_object()) {
@ -329,13 +340,11 @@ function getSmartInfo() {
}
function getAlbumInfo($albumID) {
global $database;
$return = array();
$query = "SELECT * FROM lychee_albums WHERE id = '$albumID';";
$result = $database->query($query);
$row = $result->fetch_object();
$return['title'] = $row->title;
$return['date'] = $row->sysdate;
$return['star'] = $row->star;
$return['public'] = $row->public;
$query = "SELECT COUNT(*) AS num FROM lychee_photos WHERE album = '$albumID';";
$result = $database->query($query);
@ -346,7 +355,7 @@ function getAlbumInfo($albumID) {
function setAlbumTitle($albumID, $title) {
global $database;
$title = mysqli_real_escape_string($database, urldecode($title));
if(strlen($title)<3||strlen($title)>30) return false;
if(strlen($title)<1||strlen($title)>30) return false;
$query = "UPDATE lychee_albums SET title = '$title' WHERE id = '$albumID';";
$result = $database->query($query);
if(!$result) return false;
@ -400,7 +409,7 @@ function getAlbumArchive($albumID) {
$result = $database->query($query);
$row = $result->fetch_object();
if($albumID!=0&&is_numeric($albumID))$zipTitle = $row->title;
$filename = "./".$zipTitle.".zip";
$filename = "../uploads/".$zipTitle.".zip";
$zip = new ZipArchive();
@ -418,24 +427,57 @@ function getAlbumArchive($albumID) {
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=\"$zipTitle.zip\"");
header("Content-Length: ".filesize($filename));
readfile($filename);
unlink($filename);
return true;
}
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;
}
}
// Photo Functions
function getPhotos($albumID) {
global $database;
global $database, $sorting;
switch($albumID) {
case "f": $query = "SELECT * FROM lychee_photos WHERE star = 1 ORDER BY id DESC;";
case "f": $query = "SELECT id, title, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE star = 1 ORDER BY id $sorting;";
break;
case "s": $query = "SELECT * FROM lychee_photos WHERE public = 1 ORDER BY id DESC;";
case "s": $query = "SELECT id, title, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE public = 1 ORDER BY id $sorting;";
break;
default: $query = "SELECT * FROM lychee_photos WHERE album = '$albumID' ORDER BY id DESC;";
default: $query = "SELECT id, title, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE album = '$albumID' ORDER BY id $sorting;";
}
$result = $database->query($query);
$return = array(array());
$i = 0;
while($row = $result->fetch_array()) {
$return[$i] = $row;
@ -451,10 +493,10 @@ function getPhotoInfo($photoID) {
$result = $database->query($query);
$row = $result->fetch_object();
if($row->quantity == 0) {
importPhoto($photoID);
importPhoto($photoID, 's');
}
if(is_file("../uploads/import/$photoID")) {
importPhoto($photoID);
importPhoto($photoID, 's');
}
$query = "SELECT * FROM lychee_photos WHERE import_name = '../uploads/import/$photoID' ORDER BY ID DESC;";
} else {
@ -488,13 +530,6 @@ function downloadPhoto($photoID) {
unlink($filename);
return true;
}
function countPhotos() {
global $database;
$query = "SELECT COUNT(*) AS num FROM lychee_photos;";
$result = $database->query($query);
$row = $result->fetch_object();
return $row->num;
}
function setPhotoPublic($photoID, $url) {
global $database;
$query = "SELECT public, shortlink FROM lychee_photos WHERE id = '$photoID';";
@ -533,8 +568,9 @@ function setPhotoStar($photoID) {
$result = $database->query($query);
return true;
}
function nextPhoto($photoID, $albumID) {
global $database;
function nextPhoto($photoID, $albumID, $innerCall) {
global $database, $sorting;
if (!$innerCall&&$sorting=="ASC") return previousPhoto($photoID, $albumID, true);
switch($albumID) {
case 'f': $query = "SELECT * FROM lychee_photos WHERE id < '$photoID' AND star = '1' ORDER BY id DESC LIMIT 0, 1;";
break;
@ -557,14 +593,15 @@ function nextPhoto($photoID, $albumID) {
}
return $return;
}
function previousPhoto($photoID, $albumID) {
global $database;
function previousPhoto($photoID, $albumID, $innerCall) {
global $database, $sorting;
if (!$innerCall&&$sorting=="ASC") return nextPhoto($photoID, $albumID, true);
switch($albumID) {
case 'f': $query = "SELECT * FROM lychee_photos WHERE id > '$photoID' AND star = '1' LIMIT 0, 1;";
case 'f': $query = "SELECT * FROM lychee_photos WHERE id > '$photoID' AND star = '1' ORDER BY id LIMIT 0, 1;";
break;
case 's': $query = "SELECT * FROM lychee_photos WHERE id > '$photoID' AND public = '1' LIMIT 0, 1;";
case 's': $query = "SELECT * FROM lychee_photos WHERE id > '$photoID' AND public = '1' ORDER BY id LIMIT 0, 1;";
break;
default: $query = "SELECT * FROM lychee_photos WHERE id > '$photoID' AND album = '$albumID' LIMIT 0, 1;";
default: $query = "SELECT * FROM lychee_photos WHERE id > '$photoID' AND album = '$albumID' ORDER BY id LIMIT 0, 1;";
}
$result = $database->query($query);
$return = $result->fetch_array();
@ -581,7 +618,7 @@ function previousPhoto($photoID, $albumID) {
}
return $return;
}
function movePhoto($photoID, $newAlbum) {
function setAlbum($photoID, $newAlbum) {
global $database;
$query = "UPDATE lychee_photos SET album = '$newAlbum' WHERE id = '$photoID';";
$result = $database->query($query);
@ -622,8 +659,7 @@ function deletePhoto($photoID) {
if(!$result) return false;
return true;
}
function importPhoto($name) {
global $database;
function importPhoto($name, $albumID) {
$tmp_name = "../uploads/import/$name";
$details = getimagesize($tmp_name);
$size = filesize($tmp_name);
@ -633,9 +669,20 @@ function importPhoto($name) {
$nameFile[0]['tmp_name'] = $tmp_name;
$nameFile[0]['error'] = 0;
$nameFile[0]['size'] = $size;
if(!upload($nameFile, 's')) return false;
if(!upload($nameFile, $albumID)) return false;
else return true;
}
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;
}
}
// Share Functions
function urlShortner($url) {
@ -650,30 +697,12 @@ function urlShortner($url) {
$shortlink = $xml->results->nodeKeyVal->shortUrl;
return $shortlink;
}
function sharePhoto($photoID, $url) {
function getShortlink($photoID) {
global $database;
$query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
$result = $database->query($query);
$row = $result->fetch_object();
$thumb = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."/../../".$row->thumbUrl;
$title = $row->title;
$description = $row->description;
$shortlink = $row->shortlink;
$twitterUrl = "https://twitter.com/share?url=".urlencode("$url");
$facebookUrl = "http://www.facebook.com/sharer.php?u=".urlencode("$url")."&t=".urlencode($title);
$mailUrl = "mailto:?subject=".rawurlencode($title)."&body=".rawurlencode("Hey guy! Check this out: $url");
$share = array();
$share['twitter'] = $twitterUrl;
$share['facebook'] = $facebookUrl;
$share['tumblr'] = $tumblrUrl;
$share['pinterest'] = $pinterestUrl;
$share['mail'] = $mailUrl;
$share['shortlink'] = $shortlink;
return $share;
return $row->shortlink;
}
function facebookHeader($photoID) {
$database = dbConnect();
@ -691,7 +720,7 @@ function facebookHeader($photoID) {
return $return;
}
function isPhotoPublic($photoID) {
function isPhotoPublic($photoID, $password) {
global $database;
$photoID = mysqli_real_escape_string($database, $photoID);
if(is_numeric($photoID)) {
@ -702,16 +731,13 @@ function isPhotoPublic($photoID) {
$result = $database->query($query);
$row = $result->fetch_object();
if (!is_numeric($photoID)&&!$row) return true;
if($row->public == 1) {
return true;
} else {
return false;
}
if($row->public == 1) return true;
else return isAlbumPublic($row->album, $password);
}
// Search Function
function search($term) {
global $database;
global $database, $sorting;
$term = mysqli_real_escape_string($database, $term);
$query = "SELECT * FROM lychee_photos WHERE title like '%$term%' OR description like '%$term%';";
@ -725,7 +751,7 @@ function search($term) {
$i=0;
while($row = $result->fetch_array()) {
$return['albums'][$i] = $row;
$query2 = "SELECT thumbUrl FROM lychee_photos WHERE album = '".$row['id']."' ORDER BY id DESC LIMIT 0, 3;";
$query2 = "SELECT thumbUrl FROM lychee_photos WHERE album = '".$row['id']."' ORDER BY id $sorting LIMIT 0, 3;";
$result2 = $database->query($query2);
$k = 0;
while($row2 = $result2->fetch_object()){

16
php/update.php Normal file
View File

@ -0,0 +1,16 @@
<?php
define('LYCHEE', true);
// Include
require('check.php');
if($error=='') {
if(!$database->query("SELECT `public` FROM `lychee_albums`;")) $database->query("ALTER TABLE `lychee_albums` ADD `public` TINYINT( 1 ) NOT NULL DEFAULT '0'");
if(!$database->query("SELECT `password` FROM `lychee_albums`;")) $database->query("ALTER TABLE `lychee_albums` ADD `password` VARCHAR( 100 ) NULL DEFAULT NULL");
echo "\nUpdate complete!";
} else {
echo "\nCould not Update!";
}
?>

9
readme.md Normal file → Executable file
View File

@ -33,8 +33,13 @@ Lychee supports the latest versions of Google Chrome, Apple Safari and Mozilla F
## Update
To update Lychee, simply replace all files, excluding the following ones:
`uploads/`, `php/config.php`
####From version 1.0/1.1 to 1.2:
1. Replace all files, excluding `uploads/`
2. Open `php/config.php` and reconfigure your installation
3. Open `php/update.php` in your browser
####From version 1.2 to 1.2.x:
Replace all files, excluding `uploads/` and `php/config.php`.
## Troubleshooting

View File

@ -24,8 +24,8 @@
define("LYCHEE", true);
include("php/config.php");
include("php/functions.php");
require("php/config.php");
require("php/functions.php");
echo facebookHeader($_GET['p']);