1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if ( !class_exists( 'FooGallery_Polaroid_Gallery_Template' ) ) { |
4
|
|
|
|
5
|
|
|
define('FOOGALLERY_POLAROID_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ )); |
6
|
|
|
|
7
|
|
|
class FooGallery_Polaroid_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' ), 99, 1 ); |
13
|
|
|
add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) ); |
14
|
|
|
|
15
|
|
|
add_filter( 'foogallery_template_load_css-polaroid_new', '__return_false' ); |
16
|
|
|
add_filter( 'foogallery_template_load_js-polaroid_new', '__return_false' ); |
17
|
|
|
|
18
|
|
|
add_filter( 'foogallery_located_template-polaroid_new', array( $this, 'enqueue_dependencies' ) ); |
19
|
|
|
|
20
|
|
|
//add extra fields to the templates |
21
|
|
|
add_filter( 'foogallery_override_gallery_template_fields-polaroid_new', array( $this, 'add_common_thumbnail_fields' ), 10, 2 ); |
22
|
|
|
|
23
|
|
|
//add the data options needed for polaroid |
24
|
|
|
add_filter( 'foogallery_build_container_data_options-polaroid_new', array( $this, 'add_data_options' ), 10, 3 ); |
25
|
|
|
|
26
|
|
|
//override specific settings when saving the gallery |
27
|
|
|
add_filter( 'foogallery_save_gallery_settings-polaroid_new', array( $this, 'override_settings'), 10, 3 ); |
28
|
|
|
|
29
|
|
|
//build up any preview arguments |
30
|
|
|
add_filter( 'foogallery_preview_arguments-polaroid_new', array( $this, 'preview_arguments' ), 10, 2 ); |
31
|
|
|
|
32
|
|
|
//build up the thumb dimensions from some arguments |
33
|
|
|
add_filter( 'foogallery_calculate_thumbnail_dimensions-polaroid_new', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 ); |
34
|
|
|
|
35
|
|
|
//build up the thumb dimensions on save |
36
|
|
|
add_filter( 'foogallery_template_thumbnail_dimensions-polaroid_new', array( $this, 'get_thumbnail_dimensions' ), 10, 2 ); |
37
|
|
|
|
38
|
|
|
//check if the old Polaroid is installed |
39
|
|
|
if ( is_admin() ) { |
40
|
|
|
add_action( 'admin_notices', array( $this, 'display_polaroid_notice') ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Register myself so that all associated JS and CSS files can be found and automatically included |
47
|
|
|
* @param $extensions |
48
|
|
|
* |
49
|
|
|
* @return array |
50
|
|
|
*/ |
51
|
|
|
function register_myself( $extensions ) { |
|
|
|
|
52
|
|
|
$extensions[] = __FILE__; |
53
|
|
|
return $extensions; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Add our gallery template to the list of templates available for every gallery |
58
|
|
|
* @param $gallery_templates |
59
|
|
|
* |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
|
|
function add_template( $gallery_templates ) { |
|
|
|
|
63
|
|
|
$gallery_templates[] = array( |
64
|
|
|
'slug' => 'polaroid_new', |
65
|
|
|
'name' => __( 'Polaroid PRO', 'foogallery' ), |
66
|
|
|
'preview_support' => true, |
67
|
|
|
'common_fields_support' => true, |
68
|
|
|
'lazyload_support' => true, |
69
|
|
|
'paging_support' => true, |
70
|
|
|
'mandatory_classes' => 'fg-simple_portfolio fg-preset fg-polaroid', |
71
|
|
|
'thumbnail_dimensions' => true, |
72
|
|
|
'fields' => array( |
73
|
|
|
array( |
74
|
|
|
'id' => 'thumbnail_dimensions', |
75
|
|
|
'title' => __( 'Thumbnail Size', 'foogallery' ), |
76
|
|
|
'desc' => __( 'Choose the size of your thumbnails.', 'foogallery' ), |
77
|
|
|
'section' => __( 'General', 'foogallery' ), |
78
|
|
|
'type' => 'thumb_size', |
79
|
|
|
'default' => array( |
80
|
|
|
'width' => 250, |
81
|
|
|
'height' => 200, |
82
|
|
|
'crop' => true, |
83
|
|
|
), |
84
|
|
|
'row_data'=> array( |
85
|
|
|
'data-foogallery-change-selector' => 'input', |
86
|
|
|
'data-foogallery-preview' => 'shortcode' |
87
|
|
|
) |
88
|
|
|
), |
89
|
|
|
array( |
90
|
|
|
'id' => 'thumbnail_link', |
91
|
|
|
'title' => __( 'Thumbnail Link', 'foogallery' ), |
92
|
|
|
'section' => __( 'General', 'foogallery' ), |
93
|
|
|
'default' => 'image', |
94
|
|
|
'type' => 'thumb_link', |
95
|
|
|
'desc' => __( 'You can choose to link each thumbnail to the full size image, or to the image\'s attachment page, or you can choose to not link to anything.', 'foogallery' ) |
96
|
|
|
), |
97
|
|
|
array( |
98
|
|
|
'id' => 'lightbox', |
99
|
|
|
'title' => __( 'Lightbox', 'foogallery' ), |
100
|
|
|
'desc' => __( 'Choose which lightbox you want to display images with. The lightbox will only work if you set the thumbnail link to "Full Size Image".', 'foogallery' ), |
101
|
|
|
'section' => __( 'General', 'foogallery' ), |
102
|
|
|
'type' => 'lightbox', |
103
|
|
|
), |
104
|
|
|
array( |
105
|
|
|
'id' => 'gutter', |
106
|
|
|
'title' => __( 'Gutter', 'foogallery' ), |
107
|
|
|
'desc' => __( 'The spacing between each thumbnail in the gallery.', 'foogallery' ), |
108
|
|
|
'section' => __( 'General', 'foogallery' ), |
109
|
|
|
'type' => 'number', |
110
|
|
|
'class' => 'small-text', |
111
|
|
|
'default' => 40, |
112
|
|
|
'step' => '1', |
113
|
|
|
'min' => '0', |
114
|
|
|
'row_data'=> array( |
115
|
|
|
'data-foogallery-change-selector' => 'input', |
116
|
|
|
'data-foogallery-value-selector' => 'input', |
117
|
|
|
'data-foogallery-preview' => 'shortcode', |
118
|
|
|
) |
119
|
|
|
), |
120
|
|
|
array( |
121
|
|
|
'id' => 'align', |
122
|
|
|
'title' => __( 'Alignment', 'foogallery' ), |
123
|
|
|
'desc' => __( 'The horizontal alignment of the thumbnails inside the gallery.', 'foogallery' ), |
124
|
|
|
'section' => __( 'General', 'foogallery' ), |
125
|
|
|
'type' => 'radio', |
126
|
|
|
'spacer' => '<span class="spacer"></span>', |
127
|
|
|
'default' => 'center', |
128
|
|
|
'choices' => array( |
129
|
|
|
'left' => __( 'Left', 'foogallery' ), |
130
|
|
|
'center' => __( 'Center', 'foogallery' ), |
131
|
|
|
'right' => __( 'Right', 'foogallery' ), |
132
|
|
|
), |
133
|
|
|
'row_data'=> array( |
134
|
|
|
'data-foogallery-change-selector' => 'input:radio', |
135
|
|
|
'data-foogallery-value-selector' => 'input:checked', |
136
|
|
|
'data-foogallery-preview' => 'shortcode', |
137
|
|
|
) |
138
|
|
|
), |
139
|
|
|
array( |
140
|
|
|
'id' => 'caption_position', |
141
|
|
|
'title' => __('Caption Position', 'foogallery'), |
142
|
|
|
'desc' => __('Where the captions are displayed in relation to the thumbnail.', 'foogallery'), |
143
|
|
|
'section' => __( 'Captions', 'foogallery' ), |
144
|
|
|
'default' => '', |
145
|
|
|
'type' => 'radio', |
146
|
|
|
'spacer' => '<span class="spacer"></span>', |
147
|
|
|
'choices' => array( |
148
|
|
|
'' => __( 'Below', 'foogallery' ), |
149
|
|
|
'fg-captions-top' => __( 'Above', 'foogallery' ) |
150
|
|
|
), |
151
|
|
|
'row_data'=> array( |
152
|
|
|
'data-foogallery-change-selector' => 'input:radio', |
153
|
|
|
'data-foogallery-value-selector' => 'input:checked', |
154
|
|
|
'data-foogallery-preview' => 'class' |
155
|
|
|
) |
156
|
|
|
), |
157
|
|
|
), |
158
|
|
|
); |
159
|
|
|
|
160
|
|
|
return $gallery_templates; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Enqueue scripts that the polaroid template relies on |
165
|
|
|
*/ |
166
|
|
|
function enqueue_dependencies() { |
|
|
|
|
167
|
|
|
//enqueue core files |
168
|
|
|
foogallery_enqueue_core_gallery_template_style(); |
169
|
|
|
foogallery_enqueue_core_gallery_template_script(); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Add thumbnail fields to the gallery template |
174
|
|
|
* |
175
|
|
|
* @uses "foogallery_override_gallery_template_fields" |
176
|
|
|
* @param $fields |
177
|
|
|
* @param $template |
178
|
|
|
* |
179
|
|
|
* @return array |
180
|
|
|
*/ |
181
|
|
|
function add_common_thumbnail_fields( $fields, $template ) { |
|
|
|
|
182
|
|
|
$fields_to_remove = array(); |
183
|
|
|
|
184
|
|
|
//update specific fields |
185
|
|
|
foreach ($fields as $key => &$field) { |
186
|
|
|
if ( 'hover_effect_preset' === $field['id'] ) { |
187
|
|
|
$field['default'] = 'fg-custom'; |
188
|
|
|
$field['choices'] = array( |
189
|
|
|
'fg-custom' => __( 'Polaroid', 'foogallery' ) |
190
|
|
|
); |
191
|
|
|
$field['row_data'] = array( |
192
|
|
|
'data-foogallery-hidden' => true, |
193
|
|
|
'data-foogallery-change-selector' => 'input:radio', |
194
|
|
|
'data-foogallery-value-selector' => 'input:checked', |
195
|
|
|
'data-foogallery-preview' => 'class' |
196
|
|
|
); |
197
|
|
|
} else if ( 'hover_effect_caption_visibility' === $field['id'] ) { |
198
|
|
|
$field['default'] = 'fg-caption-always'; |
199
|
|
|
$field['choices'] = array( |
200
|
|
|
'fg-caption-always' => __( 'Always Visible', 'foogallery' ), |
201
|
|
|
); |
202
|
|
|
$field['row_data'] = array( |
203
|
|
|
'data-foogallery-change-selector' => 'input:radio', |
204
|
|
|
'data-foogallery-hidden' => true, |
205
|
|
|
'data-foogallery-preview' => 'class' |
206
|
|
|
); |
207
|
|
|
} else if ( 'hover_effect_help' == $field['id'] ) { |
208
|
|
|
$field['row_data'] = array( |
209
|
|
|
'data-foogallery-hidden' => true |
210
|
|
|
); |
211
|
|
|
} else if ( 'hover_effect_scale' == $field['id'] ) { |
212
|
|
|
$fields_to_remove[] = $key; |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
foreach ($fields_to_remove as $key) { |
217
|
|
|
unset($fields[$key]); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
return $fields; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Add the required data options if needed |
225
|
|
|
* |
226
|
|
|
* @param $options |
227
|
|
|
* @param $gallery FooGallery |
228
|
|
|
* |
229
|
|
|
* @param $attributes array |
230
|
|
|
* |
231
|
|
|
* @return array |
232
|
|
|
*/ |
233
|
|
|
function add_data_options($options, $gallery, $attributes) { |
|
|
|
|
234
|
|
|
$gutter = foogallery_gallery_template_setting( 'gutter', 40 ); |
235
|
|
|
$options['template']['gutter'] = intval($gutter); |
236
|
|
|
|
237
|
|
|
$align = foogallery_gallery_template_setting( 'align', 'center' ); |
238
|
|
|
$options['template']['align'] = $align; |
239
|
|
|
return $options; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Override specific settings so that the gallery template will always work |
244
|
|
|
* |
245
|
|
|
* @param $settings |
246
|
|
|
* @param $post_id |
247
|
|
|
* @param $form_data |
248
|
|
|
* |
249
|
|
|
* @return mixed |
250
|
|
|
*/ |
251
|
|
|
function override_settings($settings, $post_id, $form_data) { |
|
|
|
|
252
|
|
|
$settings['polaroid_new_hover_effect_preset'] = 'fg-custom'; |
253
|
|
|
$settings['polaroid_new_hover_effect_caption_visibility'] = 'fg-caption-always'; |
254
|
|
|
|
255
|
|
|
return $settings; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Build up a arguments used in the preview of the gallery |
260
|
|
|
* @param $args |
261
|
|
|
* @param $post_data |
262
|
|
|
* |
263
|
|
|
* @return mixed |
264
|
|
|
*/ |
265
|
|
|
function preview_arguments( $args, $post_data ) { |
|
|
|
|
266
|
|
|
$args['thumbnail_dimensions'] = $post_data[FOOGALLERY_META_SETTINGS]['polaroid_new_thumbnail_dimensions']; |
267
|
|
|
$args['gutter'] = $post_data[FOOGALLERY_META_SETTINGS]['polaroid_new_gutter']; |
268
|
|
|
$args['align'] = $post_data[FOOGALLERY_META_SETTINGS]['polaroid_new_align']; |
269
|
|
|
return $args; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Builds thumb dimensions from arguments |
274
|
|
|
* |
275
|
|
|
* @param array $dimensions |
276
|
|
|
* @param array $arguments |
277
|
|
|
* |
278
|
|
|
* @return mixed |
279
|
|
|
*/ |
280
|
|
|
function build_thumbnail_dimensions_from_arguments( $dimensions, $arguments ) { |
|
|
|
|
281
|
|
|
if ( array_key_exists( 'thumbnail_dimensions', $arguments) ) { |
282
|
|
|
return array( |
283
|
|
|
'height' => intval($arguments['thumbnail_dimensions']['height']), |
284
|
|
|
'width' => intval($arguments['thumbnail_dimensions']['width']), |
285
|
|
|
'crop' => '1' |
286
|
|
|
); |
287
|
|
|
} |
288
|
|
|
return null; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* Get the thumb dimensions arguments saved for the gallery for this gallery template |
293
|
|
|
* |
294
|
|
|
* @param array $dimensions |
295
|
|
|
* @param FooGallery $foogallery |
296
|
|
|
* |
297
|
|
|
* @return mixed |
298
|
|
|
*/ |
299
|
|
|
function get_thumbnail_dimensions( $dimensions, $foogallery ) { |
|
|
|
|
300
|
|
|
$dimensions = $foogallery->get_meta( 'polaroid_new_thumbnail_dimensions', array( |
301
|
|
|
'width' => 250, |
302
|
|
|
'height' => 200 |
303
|
|
|
) ); |
304
|
|
|
$dimensions['crop'] = true; |
305
|
|
|
return $dimensions; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Display a message if the Polaroid extension is also installed |
310
|
|
|
*/ |
311
|
|
|
function display_polaroid_notice() { |
|
|
|
|
312
|
|
|
if ( class_exists('FooGallery_Polaroid_Template_Extension') ) { |
313
|
|
|
?> |
314
|
|
|
<div class="notice error"> |
315
|
|
|
<p> |
316
|
|
|
<strong><?php _e('Polaroid Extension Redundant!', 'foogallery'); ?></strong><br/> |
317
|
|
|
<?php _e('You have both FooGallery PRO and the old Polaroid extension activated. FooGallery PRO includes the Polaroid PRO gallery template, which makes the free Polaroid extension redundant.', 'foogallery'); ?> |
318
|
|
|
<br/> |
319
|
|
|
<?php _e('Please edit all galleries that use the old Polaroid gallery template and change them to use the Polaroid PRO gallery template. Once this is done, you can delete the free Polaroid extension.', 'foogallery'); ?> |
320
|
|
|
<br/> |
321
|
|
|
</p> |
322
|
|
|
</div> |
323
|
|
|
<?php |
324
|
|
|
} |
325
|
|
|
} |
326
|
|
|
} |
327
|
|
|
} |
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.