navigate on galleries

This commit is contained in:
Bartek Przybylski 2012-06-03 00:29:10 +02:00
parent 34a21a63ce
commit 76e7e361ae
3 changed files with 45 additions and 25 deletions

View file

@ -29,9 +29,11 @@ class DatabaseManager {
if (!$image->loadFromFile($path)) {
return false;
}
\OCP\DB::beginTransaction();
$stmt = \OCP\DB::prepare('INSERT INTO *PREFIX*pictures_images_cache (uid_owner, path, width, height) VALUES (?, ?, ?, ?)');
$stmt->execute(array(\OCP\USER::getUser(), $path, $image->width(), $image->height()));
unset($image);
\OCP\DB::commit();
return $this->getFileData($path);
}
@ -64,7 +66,7 @@ class ThumbnailsManager {
$image->fixOrientation();
$ret = $image->preciseResize(floor((200*$image->width())/$image->height()), 200);
$ret = $image->preciseResize(floor((150*$image->width())/$image->height()), 150);
if (!$ret) {
\OC_Log::write(self::TAG, 'Couldn\'t resize image', \OC_Log::ERROR);

View file

@ -9,11 +9,12 @@ const TILE_PROPORTION_HORIZONTAL = 0;
const TILE_PROPORTION_VERTICAL = 0;
const GET_THUMBNAIL_PATH = '?app=gallery&getfile=ajax/thumbnail.php&filepath=';
const TAG = 'Pictures';
const IMAGE_WIDTH = 150;
class TileBase {
public function getWidth() { return false; }
public function getHeight() { return 200; }
public function getHeight() { return 150; }
public function getOnHoverAction() { return false; }
@ -64,8 +65,8 @@ class TilesLine {
for ($i = 0; $i < count($this->tiles_array); $i++) {
$img_w = $this->tiles_array[$i]->getWidth();
$extra = '';
if ($img_w != 200) $extra = ' style="width:'.$img_w.'px"';
$r .= '<div class="gallery_div" '.$extra.' onmouseover="'.$this->tiles_array[$i]->getOnHoverAction().'" onmouseout="'.$this->tiles_array[$i]->getOnOutAction().'">'.$this->tiles_array[$i]->get().'</div>';
if ($img_w != 150) $extra = ' style="width:'.$img_w.'px"';
$r .= '<div class="gallery_div" '.$extra.' onmouseover="'.$this->tiles_array[$i]->getOnHoverAction().'" onmouseout="'.$this->tiles_array[$i]->getOnOutAction().'" onclick="'.$this->tiles_array[$i]->getOnClickAction().'">'.$this->tiles_array[$i]->get().'</div>';
}
$r .= '</div>';
@ -94,18 +95,6 @@ class TileSingle extends TileBase {
return $a['width'];
}
public function forceSize($width_must_fit=false) {
$current_height = $this->image->height();
$current_width = $this->image->width();
// we need height of 250px but not for tiles stack
if ($current_width > $current_height && !$width_must_fit) {
$this->image->resize(floor((250*$current_width)/$current_height));
} else {
$this->image->resize(200);
}
}
public function get($extra = '') {
return '<img src="'.GET_THUMBNAIL_PATH.urlencode($this->getPath()).'" '.$extra.'>';
}
@ -118,6 +107,10 @@ class TileSingle extends TileBase {
return $this->file_path;
}
public function getOnClickAction() {
return 'javascript:openFile(\''.$this->file_path.'\');';
}
private $file_path;
private $image;
}
@ -145,7 +138,7 @@ class TileStack extends TileBase {
for ($i = 0; $i < count($this->tiles_array); $i++) {
$max = max($max, $this->tiles_array[$i]->getWidth());
}
return min(200, $max);
return min(IMAGE_WIDTH, $max);
}
public function get() {
@ -155,11 +148,10 @@ class TileStack extends TileBase {
$left = rand(-5, 5);
$img_w = $this->tiles_array[$i]->getWidth();
$extra = '';
if ($img_w < 200) {
if ($img_w < IMAGE_WIDTH) {
$extra = 'width:'.$img_w.'px;';
}
$r .= '<div class="miniature_border gallery_div" style="background-image:url(\''.$this->tiles_array[$i]->getMiniatureSrc().'\');margin-top:'.$top.'px; margin-left:'.$left.'px;'.$extra.'"></div>';
// $r .= $this->tiles_array[$i]->get(' style="margin-top:'.$top.'px; margin-left:'.$left.'px; "');
}
return $r;
}
@ -176,6 +168,10 @@ class TileStack extends TileBase {
return count($this->tiles_array);
}
public function getOnClickAction() {
return 'javascript:openNewGal(\''.$this->stack_name.'\');';
}
private $tiles_array;
private $stack_name;
}

View file

@ -1,17 +1,25 @@
<?php
OCP\Util::addStyle('files', 'files');
OCP\Util::addscript('files_imageviewer', 'jquery.mousewheel-3.0.4.pack');
OCP\Util::addscript('files_imageviewer', 'jquery.fancybox-1.3.4.pack');
OCP\Util::addStyle( 'files_imageviewer', 'jquery.fancybox-1.3.4' );
$l = OC_L10N::get('gallery');
?>
<style>
div.gallery_div {position:relative; display: inline-block; height: 202px; width: 200px; margin: 5px;}
div.miniature_border {position:absolute; height: 200px; -webkit-transition-duration: .2s; background-position: 50%;}
div.line {display:inline-block; border: 0; width: auto; height: 210px}
div.gallery_div img{position:absolute; top: 1; left: 0; -webkit-transition-duration: 0.3s; height:200px; width: auto;}
div.gallery_div {position:relative; display: inline-block; height: 152px; width: 150px; margin: 5px;}
div.miniature_border {position:absolute; height: 150px; -webkit-transition-duration: .2s; background-position: 50%;}
div.line {display:inline-block; border: 0; width: auto; height: 160px}
div.gallery_div img{position:absolute; top: 1; left: 0; -webkit-transition-duration: 0.3s; height:150px; width: auto;}
div.gallery_div img.shrinker {width:80px !important;}
div.title { opacity: 0; text-align: center; vertical-align: middle; font-family: Arial; font-size: 12px; border: 0; position: absolute; text-overflow: ellipsis; bottom: 20px; left:10px; height:auto; padding: 5px; width: 170px; background-color: black; color: white; -webkit-transition: opacity 0.5s; z-index:1000; border-radius: 7px}
div.title { opacity: 0; text-align: center; vertical-align: middle; font-family: Arial; font-size: 12px; border: 0; position: absolute; text-overflow: ellipsis; bottom: 20px; left:5px; height:auto; padding: 5px; width: 140px; background-color: black; color: white; -webkit-transition: opacity 0.5s; z-index:1000; border-radius: 7px}
div.visible { opacity: 0.8;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
var root = "<?php echo !empty($_GET['root']) ? $_GET['root'] : '/'; ?>";
function t(element) {
$('div', element).each(function(index, elem) {
if ($(elem).hasClass('title')) {
@ -36,6 +44,20 @@ function o(element) {
});
}
function openNewGal(album_name) {
root = root + album_name + "/";
var url = window.location.toString().replace(window.location.search, '');
url = url + "?app=gallery&root="+root;
window.location = url;
}
function openFile(file_path) {
var url = window.location.toString().replace(window.location.search, '');
url = url + "?app=files&getfile=download.php?file="+file_path;
window.location = url;
}
</script>
<?php
@ -43,7 +65,7 @@ function o(element) {
include('apps/gallery/lib/tiles.php');
$root = empty($_GET['root'])?'/':$_GET['root'];
$images = \OC_FileCache::searchByMime('image', null, '/'.\OCP\USER\getUser().'/files'.$root);
$images = \OC_FileCache::searchByMime('image', null, '/'.\OCP\USER::getUser().'/files'.$root);
sort($images);
$arr = array();