-
Notifications
You must be signed in to change notification settings - Fork 7
/
gallery.php
58 lines (47 loc) · 1.29 KB
/
gallery.php
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
<?php
class GalleryField extends BaseField {
public $type = 'text';
public $displayFilename = true;
public function __construct(){
// Build translation file path
$baseDir = __DIR__ . DS . 'localization' . DS;
$lang = panel()->language();
if (file_exists($baseDir . $lang . '.php')) {
require $baseDir . $lang . '.php';
} else {
require $baseDir . 'en.php';
}
}
static public $assets = array(
'js' => array(
'gallery.js'
),
'css' => array(
'gallery.css'
)
);
public function getImage($image, $width){
if(!empty($this->aspectRatio)){
return $image->crop($width, $width * $this->calcAspectRatio($this->aspectRatio));
}
return $image->width($width);
}
public function getRetinaImage($image){
return $image->width($this->size);
}
public function calcAspectRatio($ratioString){
$ratios = explode(':', $ratioString);
return ((int) $ratios[1]) / ((int) $ratios[0]);
}
public function content() {
return tpl::load(__DIR__ . DS . 'template.php', array('field' => $this, 'page' => $this->page));
}
public function result() {
$result = parent::result();
return yaml::encode($result);
}
public function value() {
$value = parent::value();
return yaml::decode($value);
}
}