summaryrefslogtreecommitdiffstats
path: root/apps/gallery/lib/tiles.php
diff options
context:
space:
mode:
authorBartek Przybylski <bart.p.pl@gmail.com>2012-06-02 15:25:50 +0200
committerBartek Przybylski <bart.p.pl@gmail.com>2012-06-06 22:13:48 +0200
commit6d211155ab505c99dd7a723a011a755c2c038bc8 (patch)
treed9bd0748cbba75da4869f47fdb049fd2ade3bf77 /apps/gallery/lib/tiles.php
parentc960e42a1723a3ddc1a703724a6863b3a2d5fa8e (diff)
downloadnextcloud-server-6d211155ab505c99dd7a723a011a755c2c038bc8.tar.gz
nextcloud-server-6d211155ab505c99dd7a723a011a755c2c038bc8.zip
git status
Diffstat (limited to 'apps/gallery/lib/tiles.php')
-rw-r--r--apps/gallery/lib/tiles.php183
1 files changed, 183 insertions, 0 deletions
diff --git a/apps/gallery/lib/tiles.php b/apps/gallery/lib/tiles.php
new file mode 100644
index 00000000000..d7f5208ff83
--- /dev/null
+++ b/apps/gallery/lib/tiles.php
@@ -0,0 +1,183 @@
+<?php
+
+namespace OC\Pictures;
+
+require_once('lib/base.php');
+require_once('managers.php');
+
+const TILE_PROPORTION_HORIZONTAL = 0;
+const TILE_PROPORTION_VERTICAL = 0;
+const GET_THUMBNAIL_PATH = '?app=gallery&getfile=ajax/thumbnail.php&filepath=';
+const TAG = 'Pictures';
+
+class TileBase {
+ public function getWidth() { return false; }
+
+ public function getHeight() { return 200; }
+
+ public function getOnHoverAction() { return false; }
+
+ public function getOnOutAction() { return false; }
+
+ public function getOnClickAction() { return false; }
+
+ public function getDisplayedLayer() { return false; }
+
+ public function getTileProportion() { return false; }
+
+ public function get() { return false; }
+}
+
+class TilesLine {
+
+ public function __construct() {
+ $this->tiles_array = array();
+ }
+
+ public function setAvailableSpace($space) {
+ $available_space = $space;
+ }
+
+ public function getTilesCount() {
+ return count($this->tiles_array);
+ }
+
+ public function addTile($tile) {
+ array_push($this->tiles_array, $tile);
+ }
+
+ public function getLeftSpace() {
+ $occupied_space = 0;
+ for ($i = 0; $i < count($this->tiles_array); $i++) {
+ $occupied_space += $this->tiles_array[$i]->getWidth();
+ }
+ return $this->available_space - $occupied_space;
+ }
+
+ public function tileWillFit($tile) {
+ return $this->getLeftSpace() > $tile->getWidth();
+ }
+
+ public function get() {
+ $r = '<div class="line gallery_div">';
+
+ 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>';
+ }
+
+ $r .= '</div>';
+ return $r;
+ }
+
+ private $tiles_array;
+ private $available_space;
+}
+
+class TileSingle extends TileBase {
+
+ public function __construct($path) {
+ \OC_Log::write(TAG, 'Loading file from path '.$path, \OC_Log::DEBUG);
+ $this->file_path = $path;
+/* $this->image = new \OC_Image();
+ if (!$this->image->loadFromFile($this->file_path)) {
+ \OC_Log::write(TAG, 'Loading file filed', \OC_Log::ERROR);
+ return;
+ }
+ $this->image->fixOrientation();*/
+ }
+
+ public function getWidth() {
+ $a = ThumbnailsManager::getInstance()->getThumbnailInfo($this->file_path);
+ 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.'>';
+ }
+
+ public function getMiniatureSrc() {
+ return GET_THUMBNAIL_PATH.urlencode($this->getPath());
+ }
+
+ public function getPath() {
+ return $this->file_path;
+ }
+
+ private $file_path;
+ private $image;
+}
+
+class TileStack extends TileBase {
+
+ const STACK_REPRESENTATIVES = 3;
+
+ public function __construct($path_array, $stack_name) {
+ $this->tiles_array = array();
+ $this->stack_name = $stack_name;
+ for ($i = 0; $i < count($path_array) && $i < self::STACK_REPRESENTATIVES; $i++) {
+ $tile = new TileSingle($path_array[$i]);
+ array_push($this->tiles_array, $tile);
+ }
+ }
+
+ public function forceSize($width_must_fit=false) {
+ for ($i = 0; $i < count($this->tiles_array); $i++)
+ $this->tiles_array[$i]->forceSize(true);
+ }
+
+ public function getWidth() {
+ $max = 0;
+ for ($i = 0; $i < count($this->tiles_array); $i++) {
+ $max = max($max, $this->tiles_array[$i]->getWidth());
+ }
+ return min(200, $max);
+ }
+
+ public function get() {
+ $r = '<div class="title gallery_div">'.$this->stack_name.'</div>';
+ for ($i = 0; $i < count($this->tiles_array); $i++) {
+ $top = rand(-5, 5);
+ $left = rand(-5, 5);
+ $img_w = $this->tiles_array[$i]->getWidth();
+ $extra = '';
+ if ($img_w < 200) {
+ $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;
+ }
+
+ public function getOnHoverAction() {
+ return 'javascript:t(this);return false;';
+ }
+
+ public function getOnOutAction() {
+ return 'javascript:o(this);return false;';
+ }
+
+ public function getCount() {
+ return count($this->tiles_array);
+ }
+
+ private $tiles_array;
+ private $stack_name;
+}
+
+?>