|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
if ( !class_exists( 'FooGallery_Image_Viewer_Gallery_Template' ) ) { |
|
4
|
|
|
|
|
5
|
|
|
define('FOOGALLERY_IMAGE_VIEWER_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ )); |
|
6
|
|
|
|
|
7
|
|
|
class FooGallery_Image_Viewer_Gallery_Template { |
|
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Wire up everything we need to run the extension |
|
10
|
|
|
*/ |
|
11
|
|
|
function __construct() { |
|
|
|
|
|
|
12
|
|
|
add_filter( 'foogallery_gallery_templates', array( $this, 'add_template' ) ); |
|
13
|
|
|
|
|
14
|
|
|
//add extra fields to the templates |
|
15
|
|
|
add_filter( 'foogallery_override_gallery_template_fields-image-viewer', array( $this, 'add_common_thumbnail_fields' ), 10, 2 ); |
|
16
|
|
|
|
|
17
|
|
|
add_action( 'foogallery_located_template-image-viewer', array( $this, 'enqueue_dependencies' ) ); |
|
18
|
|
|
|
|
19
|
|
|
add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) ); |
|
20
|
|
|
|
|
21
|
|
|
add_filter( 'foogallery_template_thumbnail_dimensions-image-viewer', array( $this, 'get_thumbnail_dimensions' ), 10, 2 ); |
|
22
|
|
|
|
|
23
|
|
|
//override specific settings when saving the gallery |
|
24
|
|
|
add_filter( 'foogallery_save_gallery_settings-image-viewer', array( $this, 'override_settings'), 10, 3 ); |
|
25
|
|
|
|
|
26
|
|
|
//build up any preview arguments |
|
27
|
|
|
add_filter( 'foogallery_preview_arguments-image-viewer', array( $this, 'preview_arguments' ), 10, 2 ); |
|
28
|
|
|
|
|
29
|
|
|
//build up the thumb dimensions from some arguments |
|
30
|
|
|
add_filter( 'foogallery_calculate_thumbnail_dimensions-image-viewer', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 ); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Register myself so that all associated JS and CSS files can be found and automatically included |
|
35
|
|
|
* @param $extensions |
|
36
|
|
|
* |
|
37
|
|
|
* @return array |
|
38
|
|
|
*/ |
|
39
|
|
|
function register_myself( $extensions ) { |
|
|
|
|
|
|
40
|
|
|
$extensions[] = __FILE__; |
|
41
|
|
|
return $extensions; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Add our gallery template to the list of templates available for every gallery |
|
46
|
|
|
* @param $gallery_templates |
|
47
|
|
|
* |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
|
|
function add_template( $gallery_templates ) { |
|
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
$gallery_templates[] = array( |
|
53
|
|
|
'slug' => 'image-viewer', |
|
54
|
|
|
'name' => __( 'Image Viewer', 'foogallery' ), |
|
55
|
|
|
'lazyload_support' => true, |
|
56
|
|
|
'fields' => array( |
|
57
|
|
|
array( |
|
58
|
|
|
'id' => 'thumbnail_size', |
|
59
|
|
|
'title' => __( 'Thumb Size', 'foogallery' ), |
|
60
|
|
|
'section' => __( 'General', 'foogallery' ), |
|
61
|
|
|
'desc' => __( 'Choose the size of your thumbnails', 'foogallery' ), |
|
62
|
|
|
'type' => 'thumb_size', |
|
63
|
|
|
'default' => array( |
|
64
|
|
|
'width' => 640, |
|
65
|
|
|
'height' => 360, |
|
66
|
|
|
'crop' => true |
|
67
|
|
|
), |
|
68
|
|
|
'row_data'=> array( |
|
69
|
|
|
'data-foogallery-preview' => 'shortcode' |
|
70
|
|
|
) |
|
71
|
|
|
), |
|
72
|
|
|
array( |
|
73
|
|
|
'id' => 'thumbnail_link', |
|
74
|
|
|
'title' => __( 'Thumb Link', 'foogallery' ), |
|
75
|
|
|
'section' => __( 'General', 'foogallery' ), |
|
76
|
|
|
'default' => 'image' , |
|
77
|
|
|
'type' => 'thumb_link', |
|
78
|
|
|
'desc' => __( 'You can choose to either link each thumbnail to the full size image or to the image\'s attachment page', 'foogallery') |
|
79
|
|
|
), |
|
80
|
|
|
array( |
|
81
|
|
|
'id' => 'lightbox', |
|
82
|
|
|
'title' => __( 'Lightbox', 'foogallery' ), |
|
83
|
|
|
'section' => __( 'General', 'foogallery' ), |
|
84
|
|
|
'desc' => __( 'Choose which lightbox you want to use in the gallery', 'foogallery' ), |
|
85
|
|
|
'type' => 'lightbox' |
|
86
|
|
|
), |
|
87
|
|
|
array( |
|
88
|
|
|
'id' => 'alignment', |
|
89
|
|
|
'title' => __( 'Alignment', 'foogallery' ), |
|
90
|
|
|
'section' => __( 'General', 'foogallery' ), |
|
91
|
|
|
'desc' => __( 'The horizontal alignment of the thumbnails inside the gallery', 'foogallery' ), |
|
92
|
|
|
'default' => 'fg-center', |
|
93
|
|
|
'type' => 'radio', |
|
94
|
|
|
'spacer' => '<span class="spacer"></span>', |
|
95
|
|
|
'choices' => array( |
|
96
|
|
|
'fg-left' => __( 'Left', 'foogallery' ), |
|
97
|
|
|
'fg-center' => __( 'Center', 'foogallery' ), |
|
98
|
|
|
'fg-right' => __( 'Right', 'foogallery' ), |
|
99
|
|
|
), |
|
100
|
|
|
'row_data'=> array( |
|
101
|
|
|
'data-foogallery-change-selector' => 'input:radio', |
|
102
|
|
|
'data-foogallery-preview' => 'class' |
|
103
|
|
|
) |
|
104
|
|
|
), |
|
105
|
|
|
array( |
|
106
|
|
|
'id' => 'language-help', |
|
107
|
|
|
'title' => __( 'Language Help', 'foogallery' ), |
|
108
|
|
|
'desc' => __( 'This gallery template shows the below items of text. Change them to suit your preference or language.', 'foogallery' ), |
|
109
|
|
|
'section' => __( 'General', 'foogallery' ), |
|
110
|
|
|
'type' => 'help' |
|
111
|
|
|
), |
|
112
|
|
|
array( |
|
113
|
|
|
'id' => 'text-prev', |
|
114
|
|
|
'title' => __( '"Prev" Text', 'foogallery' ), |
|
115
|
|
|
'section' => __( 'General', 'foogallery' ), |
|
116
|
|
|
'type' => 'text', |
|
117
|
|
|
'default' => __('Prev', 'foogallery'), |
|
118
|
|
|
'row_data'=> array( |
|
119
|
|
|
'data-foogallery-preview' => 'shortcode' |
|
120
|
|
|
) |
|
121
|
|
|
), |
|
122
|
|
|
array( |
|
123
|
|
|
'id' => 'text-of', |
|
124
|
|
|
'title' => __( '"of" Text', 'foogallery' ), |
|
125
|
|
|
'section' => __( 'General', 'foogallery' ), |
|
126
|
|
|
'type' => 'text', |
|
127
|
|
|
'default' => __('of', 'foogallery'), |
|
128
|
|
|
'row_data'=> array( |
|
129
|
|
|
'data-foogallery-preview' => 'shortcode' |
|
130
|
|
|
) |
|
131
|
|
|
), |
|
132
|
|
|
array( |
|
133
|
|
|
'id' => 'text-next', |
|
134
|
|
|
'title' => __( '"Next" Text', 'foogallery' ), |
|
135
|
|
|
'section' => __( 'General', 'foogallery' ), |
|
136
|
|
|
'type' => 'text', |
|
137
|
|
|
'default' => __('Next', 'foogallery'), |
|
138
|
|
|
'row_data'=> array( |
|
139
|
|
|
'data-foogallery-preview' => 'shortcode' |
|
140
|
|
|
) |
|
141
|
|
|
) |
|
142
|
|
|
) |
|
143
|
|
|
); |
|
144
|
|
|
|
|
145
|
|
|
return $gallery_templates; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Add thumbnail fields to the gallery template |
|
150
|
|
|
* |
|
151
|
|
|
* @uses "foogallery_override_gallery_template_fields" |
|
152
|
|
|
* @param $fields |
|
153
|
|
|
* @param $template |
|
154
|
|
|
* |
|
155
|
|
|
* @return array |
|
156
|
|
|
*/ |
|
157
|
|
|
function add_common_thumbnail_fields( $fields, $template ) { |
|
|
|
|
|
|
158
|
|
|
$updated_fields = apply_filters( 'foogallery_gallery_template_common_thumbnail_fields', $fields ); |
|
159
|
|
|
|
|
160
|
|
|
//update specific fields |
|
161
|
|
|
foreach ($updated_fields as &$field) { |
|
162
|
|
|
if ( 'rounded_corners' === $field['id'] ) { |
|
163
|
|
|
$field['choices'] = array( |
|
164
|
|
|
'' => __( 'None', 'foogallery' ), |
|
165
|
|
|
'fg-round-small' => __( 'Small', 'foogallery' ), |
|
166
|
|
|
'fg-round-medium' => __( 'Medium', 'foogallery' ), |
|
167
|
|
|
'fg-round-large' => __( 'Large', 'foogallery' ), |
|
168
|
|
|
); |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
return $updated_fields; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Enqueue scripts that the default gallery template relies on |
|
177
|
|
|
*/ |
|
178
|
|
|
function enqueue_dependencies( $gallery ) { |
|
|
|
|
|
|
179
|
|
|
//enqueue core files |
|
180
|
|
|
foogallery_enqueue_core_gallery_template_style(); |
|
181
|
|
|
foogallery_enqueue_core_gallery_template_script(); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Get the thumb dimensions arguments saved for the gallery for this gallery template |
|
186
|
|
|
* |
|
187
|
|
|
* @param array $dimensions |
|
188
|
|
|
* @param FooGallery $foogallery |
|
189
|
|
|
* |
|
190
|
|
|
* @return mixed |
|
191
|
|
|
*/ |
|
192
|
|
|
function get_thumbnail_dimensions( $dimensions, $foogallery ) { |
|
|
|
|
|
|
193
|
|
|
$dimensions = $foogallery->get_meta( 'image-viewer_thumbnail_size', false ); |
|
194
|
|
|
return $dimensions; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* Override specific settings so that the gallery template will always work |
|
199
|
|
|
* |
|
200
|
|
|
* @param $settings |
|
201
|
|
|
* @param $post_id |
|
202
|
|
|
* @param $form_data |
|
203
|
|
|
* |
|
204
|
|
|
* @return mixed |
|
205
|
|
|
*/ |
|
206
|
|
|
function override_settings($settings, $post_id, $form_data) { |
|
|
|
|
|
|
207
|
|
|
if ( 'fg-round-full' === $settings['image-viewer_rounded_corners'] ) { |
|
208
|
|
|
$settings['image-viewer_rounded_corners'] = 'fg-round-large'; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
return $settings; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* Build up a arguments used in the preview of the gallery |
|
216
|
|
|
* @param $args |
|
217
|
|
|
* @param $post_data |
|
218
|
|
|
* |
|
219
|
|
|
* @return mixed |
|
220
|
|
|
*/ |
|
221
|
|
|
function preview_arguments( $args, $post_data ) { |
|
|
|
|
|
|
222
|
|
|
$args['thumbnail_width'] = $post_data['foogallery_settings']['image-viewer_thumbnail_dimensions']['width']; |
|
223
|
|
|
$args['thumbnail_height'] = $post_data['foogallery_settings']['image-viewer_thumbnail_dimensions']['height']; |
|
224
|
|
|
$args['thumbnail_crop'] = isset( $post_data['foogallery_settings']['image-viewer_thumbnail_dimensions']['crop'] ) ? '1' : '0'; |
|
225
|
|
|
|
|
226
|
|
|
return $args; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* Builds thumb dimensions from arguments |
|
231
|
|
|
* |
|
232
|
|
|
* @param array $dimensions |
|
233
|
|
|
* @param array $arguments |
|
234
|
|
|
* |
|
235
|
|
|
* @return mixed |
|
236
|
|
|
*/ |
|
237
|
|
|
function build_thumbnail_dimensions_from_arguments( $dimensions, $arguments ) { |
|
|
|
|
|
|
238
|
|
|
return array( |
|
239
|
|
|
'height' => intval( $arguments['thumbnail_height'] ), |
|
240
|
|
|
'width' => intval( $arguments['thumbnail_width'] ), |
|
241
|
|
|
'crop' => $arguments['thumbnail_crop'] === '1' |
|
242
|
|
|
); |
|
243
|
|
|
} |
|
244
|
|
|
} |
|
245
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.