1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
<?php
namespace OC\Pictures;
require_once('lib/base.php');
require_once('managers.php');
const TAG = 'Pictures';
const IMAGE_WIDTH = 150;
class TileBase {
public function getWidth() { return false; }
public function getHeight() { return IMAGE_WIDTH; }
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 != 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().'" style="background-color:#ddd">'.$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 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
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>';
}
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;
}
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;
if(count($this->tiles_array) == 0) {
$max = IMAGE_WIDTH;
} else {
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() {
$r = '<div class="title gallery_div">'.$this->stack_name.'</div>';
if(count($this->tiles_array) == 0) {
// aint no pictures in this folder...
$r.='<div class="miniature_border gallery_div"></div>';
} else {
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() {
if(count($this->tiles_array) == 0) {
return 'javascript:explode_empty(this);return false;';
}
return 'javascript:explode(this);return false;';
}
public function getOnOutAction() {
if(count($this->tiles_array) == 0) {
return 'javascript:deplode_empty(this);return false;';
}
return 'javascript:deplode(this);return false;';
}
public function getCount() {
return count($this->tiles_array);
}
public function getOnClickAction() {
return 'javascript:openNewGal(\''.$this->stack_name.'\');';
}
private $tiles_array;
private $stack_name;
}
?>
|