aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartek Przybylski <bart.p.pl@gmail.com>2011-12-27 12:34:32 +0100
committerBartek Przybylski <bart.p.pl@gmail.com>2011-12-27 12:34:32 +0100
commit524aaf0e5e890944472f919041146c68a4300184 (patch)
treed9d86e2e23b5752b9945694d192932d841a27d33
parent1fe55b665609ad5af1c6b5af4f0b4fad9bede9f3 (diff)
parent1383cb51e7672b422732a1d20379baaa4f3f7b62 (diff)
downloadnextcloud-server-524aaf0e5e890944472f919041146c68a4300184.tar.gz
nextcloud-server-524aaf0e5e890944472f919041146c68a4300184.zip
Merge branch 'gallery'
-rw-r--r--.htaccess1
-rw-r--r--apps/gallery/ajax/galleryOp.php29
-rw-r--r--apps/gallery/ajax/getAlbums.php4
-rw-r--r--apps/gallery/ajax/scanForAlbums.php2
-rw-r--r--apps/gallery/css/styles.css22
-rw-r--r--apps/gallery/index.php6
-rw-r--r--apps/gallery/js/album_cover.js36
-rw-r--r--apps/gallery/js/albums.js30
-rw-r--r--apps/gallery/lib/album.php19
-rw-r--r--apps/gallery/lib/images_utils.php43
-rw-r--r--apps/gallery/lib/scanner.php24
-rw-r--r--apps/gallery/templates/view_album.php3
12 files changed, 204 insertions, 15 deletions
diff --git a/.htaccess b/.htaccess
index 0d334503d07..b181f8b8452 100644
--- a/.htaccess
+++ b/.htaccess
@@ -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
diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php
new file mode 100644
index 00000000000..cd7cab202b1
--- /dev/null
+++ b/apps/gallery/ajax/galleryOp.php
@@ -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"));
+ }
+}
+?> \ No newline at end of file
diff --git a/apps/gallery/ajax/getAlbums.php b/apps/gallery/ajax/getAlbums.php
index 856f29344d7..e4736076fed 100644
--- a/apps/gallery/ajax/getAlbums.php
+++ b/apps/gallery/ajax/getAlbums.php
@@ -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));
diff --git a/apps/gallery/ajax/scanForAlbums.php b/apps/gallery/ajax/scanForAlbums.php
index ff696804b00..f603cbb4971 100644
--- a/apps/gallery/ajax/scanForAlbums.php
+++ b/apps/gallery/ajax/scanForAlbums.php
@@ -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')))));
?>
diff --git a/apps/gallery/css/styles.css b/apps/gallery/css/styles.css
index e23d822fec7..09f9daeb6b1 100644
--- a/apps/gallery/css/styles.css
+++ b/apps/gallery/css/styles.css
@@ -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 {
diff --git a/apps/gallery/index.php b/apps/gallery/index.php
index 2c409089ebe..0cd795bac01 100644
--- a/apps/gallery/index.php
+++ b/apps/gallery/index.php
@@ -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());
diff --git a/apps/gallery/js/album_cover.js b/apps/gallery/js/album_cover.js
index 776feae32cc..619aa391c56 100644
--- a/apps/gallery/js/album_cover.js
+++ b/apps/gallery/js/album_cover.js
@@ -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")
+ }
+}
+
diff --git a/apps/gallery/js/albums.js b/apps/gallery/js/albums.js
index fb091698a76..ae7d1fac500 100644
--- a/apps/gallery/js/albums.js
+++ b/apps/gallery/js/albums.js
@@ -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);
+ }
}
}
diff --git a/apps/gallery/lib/album.php b/apps/gallery/lib/album.php
index 6ddfe46de3d..0999429c5d5 100644
--- a/apps/gallery/lib/album.php
+++ b/apps/gallery/lib/album.php
@@ -1,10 +1,27 @@
<?php
-class OC_Gallery_Album{
+class OC_Gallery_Album {
public static function create($owner, $name){
$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);
diff --git a/apps/gallery/lib/images_utils.php b/apps/gallery/lib/images_utils.php
new file mode 100644
index 00000000000..cb46bf3f160
--- /dev/null
+++ b/apps/gallery/lib/images_utils.php
@@ -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);
+}
+
+?>
diff --git a/apps/gallery/lib/scanner.php b/apps/gallery/lib/scanner.php
index 1590051c48d..ef210327966 100644
--- a/apps/gallery/lib/scanner.php
+++ b/apps/gallery/lib/scanner.php
@@ -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) {
diff --git a/apps/gallery/templates/view_album.php b/apps/gallery/templates/view_album.php
index ae43e2fc557..4acc965269c 100644
--- a/apps/gallery/templates/view_album.php
+++ b/apps/gallery/templates/view_album.php
@@ -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">