Merge branch 'gallery'
This commit is contained in:
commit
524aaf0e5e
12 changed files with 204 additions and 15 deletions
|
@ -2,6 +2,7 @@ ErrorDocument 404 /core/templates/404.php
|
|||
<IfModule mod_php5.c>
|
||||
php_value upload_max_filesize 512M
|
||||
php_value post_max_size 512M
|
||||
php_value memory_limit 512M
|
||||
SetEnv htaccessWorking true
|
||||
</IfModule>
|
||||
RewriteEngine on
|
||||
|
|
29
apps/gallery/ajax/galleryOp.php
Normal file
29
apps/gallery/ajax/galleryOp.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?
|
||||
require_once('../../../lib/base.php');
|
||||
require_once('../lib/album.php');
|
||||
OC_JSON::checkLoggedIn();
|
||||
OC_JSON::checkAppEnabled('gallery');
|
||||
|
||||
function handleRename($oldname, $newname) {
|
||||
OC_Gallery_Album::rename($oldname, $newname, OC_User::getUser());
|
||||
}
|
||||
|
||||
function handleRemove($name) {
|
||||
OC_Gallery_Album::remove(OC_User::getUser(), $name);
|
||||
}
|
||||
|
||||
if ($_GET['operation']) {
|
||||
switch($_GET['operation']) {
|
||||
case "rename":
|
||||
handleRename($_GET['oldname'], $_GET['newname']);
|
||||
OC_JSON::success(array('newname' => $_GET['newname']));
|
||||
break;
|
||||
case "remove":
|
||||
handleRemove($_GET['name']);
|
||||
OC_JSON::success();
|
||||
break;
|
||||
default:
|
||||
OC_JSON::error(array('cause' => "Unknown operation"));
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -4,12 +4,14 @@ OC_JSON::checkLoggedIn();
|
|||
OC_JSON::checkAppEnabled('gallery');
|
||||
|
||||
$a = array();
|
||||
|
||||
$result = OC_Gallery_Album::find(OC_User::getUser());
|
||||
|
||||
while ($r = $result->fetchRow()) {
|
||||
$album_name = $r['album_name'];
|
||||
$tmp_res = OC_Gallery_Photo::find($r['album_id']);
|
||||
$a[] = array('name' => $album_name, 'numOfItems' => min($tmp_res->numRows(), 10));
|
||||
|
||||
$a[] = array('name' => $album_name, 'numOfItems' => min($tmp_res->numRows(), 10), 'bgPath' => OC::$WEBROOT.'/data/'.OC_User::getUser().'/gallery/'.$album_name.'.png');
|
||||
}
|
||||
|
||||
OC_JSON::success(array('albums'=>$a));
|
||||
|
|
|
@ -4,7 +4,7 @@ require_once('../../../lib/base.php');
|
|||
OC_JSON::checkLoggedIn();
|
||||
OC_JSON::checkAppEnabled('gallery');
|
||||
|
||||
OC_Gallery_Scanner::cleanUp();
|
||||
OC_JSON::success(array('albums' => OC_Gallery_Scanner::scan('')));
|
||||
//OC_JSON::success(array('albums' => array(array('name' => 'test', 'imagesCount' => 1, 'images' => array('dupa')))));
|
||||
|
||||
?>
|
||||
|
|
|
@ -14,6 +14,9 @@ div#gallery_album_box {
|
|||
display: inline-block;
|
||||
margin: 5pt;
|
||||
vertical-align: top;
|
||||
padding: 10px;
|
||||
border: solid 1px black;
|
||||
position: relative;
|
||||
}
|
||||
.leftcontent div#gallery_album_box {
|
||||
margin: 5px;
|
||||
|
@ -21,13 +24,28 @@ div#gallery_album_box {
|
|||
|
||||
div#gallery_album_box h1 {
|
||||
font-size: 12pt;
|
||||
font-family: Arial;
|
||||
font-family: Verdana;
|
||||
}
|
||||
|
||||
div#gallery_album_cover {
|
||||
width: 199px;
|
||||
height: 199px;
|
||||
border: solid 1px black;
|
||||
border: solid 1pt #999;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
div#gallery_control_overlay {
|
||||
border: 0;
|
||||
position:absolute;
|
||||
right: 10pt;
|
||||
background-color: #333;
|
||||
opacity: 0.5;
|
||||
visibility:hidden;
|
||||
padding: 0 5pt;
|
||||
}
|
||||
|
||||
div#gallery_control_overlay a {
|
||||
color:white;
|
||||
}
|
||||
|
||||
#gallery_images {
|
||||
|
|
|
@ -5,6 +5,12 @@ OC_Util::checkLoggedIn();
|
|||
OC_Util::checkAppEnabled('gallery');
|
||||
OC_App::setActiveNavigationEntry( 'gallery_index' );
|
||||
|
||||
if (!file_exists(OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery')) {
|
||||
mkdir(OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery');
|
||||
$f = fopen(OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/.htaccess', 'w');
|
||||
fwrite($f, "allow from all");
|
||||
fclose($f);
|
||||
}
|
||||
|
||||
if (!isset($_GET['view'])) {
|
||||
$result = OC_Gallery_Album::find(OC_User::getUser());
|
||||
|
|
|
@ -4,7 +4,7 @@ $(document).ready(function() {
|
|||
if (r.status == 'success') {
|
||||
for (var i in r.albums) {
|
||||
var a = r.albums[i];
|
||||
Albums.add(a.name, a.numOfItems);
|
||||
Albums.add(a.name, a.numOfItems, a.bgPath);
|
||||
}
|
||||
var targetDiv = document.getElementById('gallery_list');
|
||||
if (targetDiv) {
|
||||
|
@ -39,3 +39,37 @@ function scanForAlbums() {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
function galleryRemove(albumName) {
|
||||
if (confirm("Do you wan't to remove album " + albumName + "?")) {
|
||||
$.getJSON("ajax/galleryOp.php", {operation: "remove", name: albumName}, function(r) {
|
||||
if (r.status == "success") {
|
||||
$("#gallery_album_box[title='"+albumName+"']").remove();
|
||||
Albums.remove(albumName);
|
||||
} else {
|
||||
alert("Error: " + r.cause);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function galleryRename(name) {
|
||||
var result = window.prompt("Input new gallery name", "");
|
||||
if (result) {
|
||||
if (Albums.find(result)) {
|
||||
alert("Album named '" + result + "' already exists");
|
||||
return;
|
||||
}
|
||||
$.getJSON("ajax/galleryOp.php", {operation: "rename", oldname: name, newname: result}, function(r) {
|
||||
if (r.status == "success") {
|
||||
Albums.rename($("#gallery_album_box[title='"+name+"']"), result);
|
||||
} else {
|
||||
alert("Error: " + r.cause);
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
alert("Album name can't be empty")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,13 +12,13 @@ Albums={
|
|||
// album with the same name wont be insered,
|
||||
// and false will be returned
|
||||
// true on success
|
||||
add: function(album_name, num) {
|
||||
add: function(album_name, num, bgPath) {
|
||||
for (var a in Albums.albums) {
|
||||
if (a.name == album_name) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Albums.albums.push({name: album_name, numOfCovers: num});
|
||||
Albums.albums.push({name: album_name, numOfCovers: num, backgroundPath: bgPath});
|
||||
return true;
|
||||
},
|
||||
// remove element with given name
|
||||
|
@ -57,24 +57,38 @@ Albums={
|
|||
// displays gallery in linear representation
|
||||
// on given element, and apply default styles for gallery
|
||||
display: function(element) {
|
||||
var displayTemplate = '<div id="gallery_album_box" title="*NAME*"><a href="?view=*NAME*"><div id="gallery_album_cover"></div></a><h1>*NAME*</h1></div></div>';
|
||||
var displayTemplate = '<div id="gallery_album_box" title="*NAME*"><div id="gallery_control_overlay"><a href="#" onclick="galleryRename(\'*NAME*\');return false;">rename</a> | <a href="#" onclick="galleryRemove(\'*NAME*\');">remove</a></div><a href="?view=*NAME*"><div id="gallery_album_cover" title="*NAME*"></div></a><h1>*NAME*</h1></div></div>';
|
||||
for (var i in Albums.albums) {
|
||||
var a = Albums.albums[i];
|
||||
var local = $(displayTemplate.replace(/\*NAME\*/g, a.name));
|
||||
local.css('background-repeat', 'no-repeat');
|
||||
local.css('background-position', '0 0');
|
||||
local.css('background-image','url("ajax/getCovers.php?album_name='+a.name+'")');
|
||||
local.mousemove(function(e) {
|
||||
$("#gallery_album_cover", local).css('background-repeat', 'no-repeat');
|
||||
$("#gallery_album_cover", local).css('background-position', '0');
|
||||
$("#gallery_album_cover", local).css('background-image','url("ajax/getCovers.php?album_name='+a.name+'")');
|
||||
local.mouseover(function(e) {
|
||||
$("#gallery_control_overlay", this).css('visibility','visible');
|
||||
});
|
||||
local.mouseout(function(e) {
|
||||
$("#gallery_control_overlay", this).css('visibility','hidden');
|
||||
});
|
||||
$("#gallery_album_cover", local).mousemove(function(e) {
|
||||
|
||||
var albumMetadata = Albums.find(this.title);
|
||||
if (albumMetadata == undefined) {
|
||||
return;
|
||||
}
|
||||
var x = Math.min(Math.floor((e.layerX - this.offsetLeft)/(this.offsetWidth/albumMetadata.numOfCovers)), albumMetadata.numOfCovers-1);
|
||||
x *= this.offsetWidth;
|
||||
x *= this.offsetWidth-1;
|
||||
$(this).css('background-position', -x+'px 0');
|
||||
});
|
||||
$(element).append(local);
|
||||
}
|
||||
},
|
||||
rename: function(element, new_name) {
|
||||
if (new_name) {
|
||||
$(element).attr("title", new_name);
|
||||
$("a", element).attr("href", "?view="+new_name);
|
||||
$("h1", element).text(new_name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,23 @@ class OC_Gallery_Album{
|
|||
$stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_albums (uid_owner, album_name) VALUES (?, ?)');
|
||||
$stmt->execute(array($owner, $name));
|
||||
}
|
||||
|
||||
public static function rename($oldname, $newname, $owner) {
|
||||
$stmt = OC_DB::prepare('UPDATE OR IGNORE *PREFIX*gallery_albums SET album_name=? WHERE uid_owner=? AND album_name=?');
|
||||
$stmt->execute(array($newname, $owner, $oldname));
|
||||
}
|
||||
|
||||
public static function remove($owner, $name=null) {
|
||||
$sql = 'DELETE FROM *PREFIX*gallery_albums WHERE uid_owner = ?';
|
||||
$args = array($owner);
|
||||
if (!is_null($name)){
|
||||
$sql .= ' AND album_name = ?';
|
||||
$args[] = $name;
|
||||
}
|
||||
$stmt = OC_DB::prepare($sql);
|
||||
return $stmt->execute($args);
|
||||
}
|
||||
|
||||
public static function find($owner, $name=null){
|
||||
$sql = 'SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ?';
|
||||
$args = array($owner);
|
||||
|
|
43
apps/gallery/lib/images_utils.php
Normal file
43
apps/gallery/lib/images_utils.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
require_once('../../../lib/base.php');
|
||||
OC_JSON::checkLoggedIn();
|
||||
OC_JSON::checkAppEnabled('gallery');
|
||||
|
||||
function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height, $tgtImg, $shift) {
|
||||
//getting the image dimensions
|
||||
list($width_orig, $height_orig) = getimagesize($imgSrc);
|
||||
switch (strtolower(substr($imgSrc, strrpos($imgSrc, '.')+1))) {
|
||||
case "jpeg":
|
||||
case "jpg":
|
||||
case "tiff":
|
||||
$myImage = imagecreatefromjpeg($imgSrc);
|
||||
break;
|
||||
case "png":
|
||||
$myImage = imagecreatefrompng($imgSrc);
|
||||
break;
|
||||
default:
|
||||
exit();
|
||||
}
|
||||
$ratio_orig = $width_orig/$height_orig;
|
||||
|
||||
if ($thumbnail_width/$thumbnail_height > $ratio_orig) {
|
||||
$new_height = $thumbnail_width/$ratio_orig;
|
||||
$new_width = $thumbnail_width;
|
||||
} else {
|
||||
$new_width = $thumbnail_height*$ratio_orig;
|
||||
$new_height = $thumbnail_height;
|
||||
}
|
||||
|
||||
$x_mid = $new_width/2; //horizontal middle
|
||||
$y_mid = $new_height/2; //vertical middle
|
||||
|
||||
$process = imagecreatetruecolor(round($new_width), round($new_height));
|
||||
|
||||
imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
|
||||
imagecopyresampled($tgtImg, $process, $shift, 0, ($x_mid-($thumbnail_width/2)), ($y_mid-($thumbnail_height/2)), $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height);
|
||||
|
||||
imagedestroy($process);
|
||||
imagedestroy($myImage);
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,12 +1,23 @@
|
|||
<?php
|
||||
|
||||
require_once('base.php'); // base lib
|
||||
require_once('images_utils.php');
|
||||
|
||||
class OC_Gallery_Scanner {
|
||||
|
||||
public static function scan($root) {
|
||||
$albums = array();
|
||||
self::scanDir($root, $albums);
|
||||
return $albums;
|
||||
}
|
||||
|
||||
public static function cleanUp() {
|
||||
$stmt = OC_DB::prepare('DELETE FROM *PREFIX*gallery_albums');
|
||||
$stmt->execute(array());
|
||||
$stmt = OC_DB::prepare('DELETE FROM *PREFIX*gallery_photos');
|
||||
$stmt->execute(array());
|
||||
}
|
||||
|
||||
public static function scanDir($path, &$albums) {
|
||||
$current_album = array('name'=> $path, 'imagesCount' => 0, 'images' => array());
|
||||
$current_album['name'] = str_replace('/', '.', str_replace(OC::$CONFIG_DATADIRECTORY, '', $current_album['name']));
|
||||
|
@ -25,6 +36,7 @@ class OC_Gallery_Scanner {
|
|||
}
|
||||
$current_album['imagesCount'] = count($current_album['images']);
|
||||
$albums[] = $current_album;
|
||||
|
||||
$result = OC_Gallery_Album::find(OC_User::getUser(), $current_album['name']);
|
||||
if ($result->numRows() == 0 && count($current_album['images'])) {
|
||||
OC_Gallery_Album::create(OC_User::getUser(), $current_album['name']);
|
||||
|
@ -38,6 +50,18 @@ class OC_Gallery_Scanner {
|
|||
OC_Gallery_Photo::create($albumId, $img);
|
||||
}
|
||||
}
|
||||
if (count($current_album['images'])) {
|
||||
self::createThumbnail($current_album['name'],$current_album['images']);
|
||||
}
|
||||
}
|
||||
|
||||
public static function createThumbnail($albumName, $files) {
|
||||
$file_count = min(count($files), 10);
|
||||
$thumbnail = imagecreatetruecolor($file_count*200, 200);
|
||||
for ($i = 0; $i < $file_count; $i++) {
|
||||
CroppedThumbnail(OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/files/'.$files[$i], 200, 200, $thumbnail, $i*200);
|
||||
}
|
||||
imagepng($thumbnail, OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/' . $albumName.'.png');
|
||||
}
|
||||
|
||||
public static function isPhoto($filename) {
|
||||
|
|
|
@ -15,7 +15,8 @@ OC_Util::addStyle( 'files_imageviewer', 'jquery.fancybox-1.3.4' );
|
|||
</script>
|
||||
|
||||
<div id="controls">
|
||||
<a href="?"><input type="button" value="Back" /></a><br/>
|
||||
<a href="?"><input type="button" value="Back" /></a>
|
||||
<br/>
|
||||
</div>
|
||||
|
||||
<div id="gallery_list" class="leftcontent">
|
||||
|
|
Loading…
Reference in a new issue