-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMarkupPwpswpGalleryLegacy.module
169 lines (137 loc) · 4.46 KB
/
MarkupPwpswpGalleryLegacy.module
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
<?php namespace ProcessWire;
/**
* MarkupPwpswpGalleryLegacy
*
* Basic gallery and base module for other MarkupPwpswpGallery extension modules
* legacy plain theme
*
*/
class MarkupPwpswpGalleryLegacy extends MarkupPwpswpGallery implements Module {
private $templateFile;
public static function getModuleInfo() {
return array(
'title' => 'Pwpswp Gallery: Legacy',
'author' => 'Steffen Henschel',
'version' => '0.0.1',
'summary' => __('Adapter to enable compatibility with previous themeing pattern. Not available in Processwire Photoswipe config.'),
'permission' => [],
'autoload' => false,
'singular' => false,
'permanent' => false,
'requires' => [
'ProcessWire>=3.0.0',
'PHP>=5.6',
],
'installs' => []
);
}
/**
* alias
*
* return a short unique name for this module here
* legacy theme name
* it will be used for css classes, module identification, etc.
*
* @return string
*/
static public function alias() {
return 'legacy';
}
/**
* init
*
* @return void
*/
public function init() {}
/**
* getRelatedFileUrl
*
* returns url to a file of same name but with given extension
* residing just next to this .module file
*
* @param string $ext file extension
* @return string|null
*/
public function getRelatedFileUrl($ext) {
$file = preg_replace("/(.php$)/", '.'.$ext, $this->templateFile);
if(is_file($file)) {
return str_replace(wire('config')->paths->root, '/', $file);
} else {
return null;
}
}
/**
* setTemplateFile
*
* set template file relative to site/templates/
*
* @param [type] $path
* @return void
*/
public function setTemplateFile($path) {
$this->templateFile = wire('config')->paths->templates .ltrim($path, '/');
}
/**
* getTemplateFile
*
* @param string $template
* @return mixed
*/
private function getTemplateFile($template = null) {
return $this->templateFile;
}
/**
* getResizeClosure
*
* @param array $resizeOptions
* @param array $mixinOptions
* @return callable
*/
public function getResizeClosure($resizeOptions) {
return function(Pageimage $image, $mixinOptions = []) use($resizeOptions) {
if(strpos($resizeOptions['size'], 'x' === false)) throw new WireException("size option must contain \"x\"", 1);
$resizeOptions['size'] = explode('x', $resizeOptions['size']);
$resizeOptions = array_merge($resizeOptions, $mixinOptions);
$w = isset($resizeOptions['size'][0]) ? $resizeOptions['size'][0] : 0;
$h = isset($resizeOptions['size'][1]) ? $resizeOptions['size'][1] : 0;
return $image->size($w, $h, $resizeOptions);
};
}
/**
* render
*
* build and render the gallery structure for this module
*
* these methods are helpful and provide direct functionality:
* use $this->renderImageElement() to render a single image unit
* use $this->wrapMarkup() to wrap your structure into
*
* @param [type] $images
* @param [type] $options
* @return string
*/
public function ___render($images, $options = []) {
$templateFile = $this->getTemplateFile();
if(is_file($templateFile)) {
$output = wire('files')->render($templateFile, array(
'images' => $images,
'options' => $options,
'imageResize' => $this->getResizeClosure($options['imageResizerOptions']),
'loresResize' => $this->getResizeClosure($options['loresResizerOptions'])
));
return $output;
} else {
user_error('Template file "' .$templateFile .'" not found. Empty string returned.', E_USER_WARNING);
return '';
}
}
/**
* getPswpOptionsAttribute [markup helper]
*
* @param [type] $options
* @return void
*/
public function getPswpOptionsAttribute($options) {
return isset($options['pswpOptions']) ? ' data-pswp-options="' . htmlspecialchars(json_encode($options['pswpOptions']), ENT_QUOTES, 'UTF-8') . '"' : '';
}
}