2012-06-02 17:25:50 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OC\Pictures;
|
|
|
|
|
|
|
|
require_once('lib/base.php');
|
|
|
|
require_once('managers.php');
|
|
|
|
|
|
|
|
const TAG = 'Pictures';
|
2012-06-03 02:29:10 +04:00
|
|
|
const IMAGE_WIDTH = 150;
|
2012-06-02 17:25:50 +04:00
|
|
|
|
|
|
|
class TileBase {
|
2012-06-07 01:23:23 +04:00
|
|
|
public function getWidth() { return false; }
|
2012-06-02 17:25:50 +04:00
|
|
|
|
2012-06-07 01:23:23 +04:00
|
|
|
public function getHeight() { return IMAGE_WIDTH; }
|
2012-06-02 17:25:50 +04:00
|
|
|
|
2012-06-07 01:23:23 +04:00
|
|
|
public function getOnHoverAction() { return false; }
|
|
|
|
|
|
|
|
public function getOnOutAction() { return false; }
|
|
|
|
|
|
|
|
public function getOnClickAction() { return false; }
|
2012-06-02 17:25:50 +04:00
|
|
|
|
2012-06-07 01:23:23 +04:00
|
|
|
public function getDisplayedLayer() { return false; }
|
2012-06-02 17:25:50 +04:00
|
|
|
|
2012-06-07 01:23:23 +04:00
|
|
|
public function getTileProportion() { return false; }
|
|
|
|
|
|
|
|
public function get() { return false; }
|
2012-06-02 17:25:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
class TilesLine {
|
|
|
|
|
2012-06-07 01:23:23 +04:00
|
|
|
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 != IMAGE_WIDTH) $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>';
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
|
|
|
private $tiles_array;
|
|
|
|
private $available_space;
|
2012-06-02 17:25:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
class TileSingle extends TileBase {
|
|
|
|
|
2012-06-07 01:23:23 +04:00
|
|
|
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 get($extra = '') {
|
|
|
|
// !HACK! file path needs to be encoded twice because files app decode twice url, so any special chars like + or & in filename
|
|
|
|
// !HACK! will result in failing of opening them
|
2012-06-09 17:12:28 +04:00
|
|
|
return '<a rel="images" title="'.htmlentities(basename($this->getPath())).'" href="'.\OCP\Util::linkTo('files', 'download.php').'?file='.urlencode(urlencode($this->getPath())).'"><img rel="images" src="'.\OCP\Util::linkTo('gallery', 'ajax/thumbnail.php').'&filepath='.urlencode($this->getPath()).'" '.$extra.'></a>';
|
2012-06-07 01:23:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getMiniatureSrc() {
|
|
|
|
return \OCP\Util::linkTo('gallery', 'ajax/thumbnail.php').'&filepath='.urlencode($this->getPath());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPath() {
|
|
|
|
return $this->file_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOnClickAction() {
|
|
|
|
return '';//'javascript:openFile(\''.$this->file_path.'\');';
|
|
|
|
}
|
|
|
|
|
|
|
|
private $file_path;
|
|
|
|
private $image;
|
2012-06-02 17:25:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
class TileStack extends TileBase {
|
|
|
|
|
2012-06-07 01:23:23 +04:00
|
|
|
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(IMAGE_WIDTH, $max);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get() {
|
2012-06-11 21:07:51 +04:00
|
|
|
$r = '<div class="title gallery_div">'.$this->stack_name.'</div>';
|
2012-06-07 01:23:23 +04:00
|
|
|
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 < 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>';
|
|
|
|
}
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOnHoverAction() {
|
2012-06-08 22:26:17 +04:00
|
|
|
return 'javascript:explode(this);return false;';
|
2012-06-07 01:23:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getOnOutAction() {
|
2012-06-08 22:26:17 +04:00
|
|
|
return 'javascript:deplode(this);return false;';
|
2012-06-07 01:23:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getCount() {
|
|
|
|
return count($this->tiles_array);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOnClickAction() {
|
2012-06-11 21:07:51 +04:00
|
|
|
return 'javascript:openNewGal(\''.$this->stack_name.'\');';
|
2012-06-07 01:23:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private $tiles_array;
|
|
|
|
private $stack_name;
|
2012-06-02 17:25:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|