1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* FooGallery FooGrid Pro Extension
|
4
|
|
|
*
|
5
|
|
|
* A gallery with inline preview based on the Google image search results.
|
6
|
|
|
*
|
7
|
|
|
* @package FooGrid_Template_FooGallery_Extension
|
8
|
|
|
* @author FooPlugins
|
9
|
|
|
* @license GPL-2.0+
|
10
|
|
|
* @link https://fooplugins.com
|
11
|
|
|
* @copyright 2014 FooPlugins
|
12
|
|
|
*
|
13
|
|
|
* @wordpress-plugin
|
14
|
|
|
* Plugin Name: FooGallery - FooGrid
|
15
|
|
|
* Description: A gallery with inline preview based on Google\'s image search results.
|
16
|
|
|
* Version: 1.0.0
|
17
|
|
|
* Author: FooPlugins
|
18
|
|
|
* Author URI: https://fooplugins.com
|
19
|
|
|
* License: GPL-2.0+
|
20
|
|
|
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
21
|
|
|
*/
|
22
|
|
|
|
23
|
|
|
if ( !class_exists( 'FooGallery_FooGrid_Gallery_Template' ) ) {
|
24
|
|
|
|
25
|
|
|
define('FOOGALLERY_FOOGRID_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ ));
|
26
|
|
|
define('FOOGALLERY_FOOGRID_GALLERY_TEMPLATE_PATH', plugin_dir_path( __FILE__ ));
|
27
|
|
|
|
28
|
|
|
class FooGallery_FooGrid_Gallery_Template {
|
|
|
|
|
29
|
|
|
/**
|
30
|
|
|
* Wire up everything we need to run the extension
|
31
|
|
|
*/
|
32
|
|
|
function __construct() {
|
|
|
|
|
33
|
|
|
add_filter( 'foogallery_gallery_templates', array( $this, 'add_template' ), 100, 1 );
|
34
|
|
|
add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) );
|
35
|
|
|
add_filter( 'foogallery_located_template-foogridpro', array( $this, 'enqueue_dependencies' ) );
|
36
|
|
|
|
37
|
|
|
//get thumbnail dimensions
|
38
|
|
|
add_filter( 'foogallery_template_thumbnail_dimensions-foogridpro', array( $this, 'get_thumbnail_dimensions' ), 10, 2 );
|
39
|
|
|
|
40
|
|
|
add_filter( 'foogallery_template_load_css-foogridpro', '__return_false' );
|
41
|
|
|
add_filter( 'foogallery_template_load_js-foogridpro', '__return_false' );
|
42
|
|
|
|
43
|
|
|
//add the data options needed for polaroid
|
44
|
|
|
add_filter( 'foogallery_build_container_data_options-foogridpro', array( $this, 'add_data_options' ), 10, 3 );
|
45
|
|
|
|
46
|
|
|
//override specific settings when saving the gallery
|
47
|
|
|
add_filter( 'foogallery_save_gallery_settings-foogridpro', array( $this, 'override_settings'), 10, 3 );
|
48
|
|
|
|
49
|
|
|
//build up any preview arguments
|
50
|
|
|
add_filter( 'foogallery_preview_arguments-foogridpro', array( $this, 'preview_arguments' ), 10, 2 );
|
51
|
|
|
|
52
|
|
|
//build up the thumb dimensions from some arguments
|
53
|
|
|
add_filter( 'foogallery_calculate_thumbnail_dimensions-foogridpro', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 );
|
54
|
|
|
}
|
55
|
|
|
|
56
|
|
|
/**
|
57
|
|
|
* Register myself so that all associated JS and CSS files can be found and automatically included
|
58
|
|
|
* @param $extensions
|
59
|
|
|
*
|
60
|
|
|
* @return array
|
61
|
|
|
*/
|
62
|
|
|
function register_myself( $extensions ) {
|
63
|
|
|
$extensions[] = __FILE__;
|
64
|
|
|
return $extensions;
|
65
|
|
|
}
|
66
|
|
|
|
67
|
|
|
/**
|
68
|
|
|
* Enqueue any script or stylesheet file dependencies that your gallery template relies on
|
69
|
|
|
*
|
70
|
|
|
* @param $gallery
|
71
|
|
|
*/
|
72
|
|
|
function enqueue_dependencies( $gallery ) {
|
|
|
|
|
73
|
|
|
foogallery_enqueue_core_gallery_template_style();
|
74
|
|
|
foogallery_enqueue_core_gallery_template_script();
|
75
|
|
|
}
|
76
|
|
|
|
77
|
|
|
/**
|
78
|
|
|
* Add our gallery template to the list of templates available for every gallery
|
79
|
|
|
* @param $gallery_templates
|
80
|
|
|
*
|
81
|
|
|
* @return array
|
82
|
|
|
*/
|
83
|
|
|
function add_template( $gallery_templates ) {
|
|
|
|
|
84
|
|
|
|
85
|
|
|
$gallery_templates[] = array(
|
86
|
|
|
'slug' => 'foogridpro',
|
87
|
|
|
'name' => __( 'Grid PRO', 'foogallery'),
|
88
|
|
|
'preview_support' => true,
|
89
|
|
|
'common_fields_support' => true,
|
90
|
|
|
'lazyload_support' => true,
|
91
|
|
|
'paging_support' => true,
|
92
|
|
|
'thumbnail_dimensions' => true,
|
93
|
|
|
'mandatory_classes' => 'foogrid',
|
94
|
|
|
'fields' => array(
|
95
|
|
|
array(
|
96
|
|
|
'id' => 'thumbnail_size',
|
97
|
|
|
'title' => __('Thumbnail Size', 'foogallery'),
|
98
|
|
|
'desc' => __('Choose the size of your thumbs.', 'foogallery'),
|
99
|
|
|
'type' => 'thumb_size',
|
100
|
|
|
'default' => array(
|
101
|
|
|
'width' => 320,
|
102
|
|
|
'height' => 180,
|
103
|
|
|
'crop' => true
|
104
|
|
|
),
|
105
|
|
|
'row_data'=> array(
|
106
|
|
|
'data-foogallery-change-selector' => 'input',
|
107
|
|
|
'data-foogallery-preview' => 'shortcode'
|
108
|
|
|
)
|
109
|
|
|
),
|
110
|
|
|
array(
|
111
|
|
|
'id' => 'thumbnail_link',
|
112
|
|
|
'title' => __('Thumbnail Link', 'foogallery'),
|
113
|
|
|
'default' => 'image' ,
|
114
|
|
|
'type' => 'thumb_link',
|
115
|
|
|
'desc' => __('You can choose to either link each thumbnail to the full size image or to the image\'s attachment page.', 'foogallery')
|
116
|
|
|
),
|
117
|
|
|
// array(
|
|
|
|
|
118
|
|
|
// 'id' => 'theme',
|
119
|
|
|
// 'section' => __( 'General', 'foogallery' ),
|
120
|
|
|
// 'title' => __('Theme', 'foogallery'),
|
121
|
|
|
// 'desc' => __('The theme for the content viewer.', 'foogallery'),
|
122
|
|
|
// 'default' => '',
|
123
|
|
|
// 'type' => 'radio',
|
124
|
|
|
// 'spacer' => '<span class="spacer"></span>',
|
125
|
|
|
// 'choices' => array(
|
126
|
|
|
// '' => __( 'Dark (Default)', 'foogallery' ),
|
127
|
|
|
// 'foogrid-light' => __( 'Light', 'foogallery' )
|
128
|
|
|
// )
|
129
|
|
|
// ),
|
130
|
|
|
array(
|
131
|
|
|
'id' => 'transition',
|
132
|
|
|
'section' => __( 'General', 'foogallery' ),
|
133
|
|
|
'title' => __('Transition', 'foogallery'),
|
134
|
|
|
'desc' => __('Transition type to use switching between items, or no transitions at all.', 'foogallery'),
|
135
|
|
|
'default' => 'foogrid-transition-fade',
|
136
|
|
|
'type' => 'radio',
|
137
|
|
|
'spacer' => '<span class="spacer"></span>',
|
138
|
|
|
'choices' => array(
|
139
|
|
|
'foogrid-transition-fade' => __( 'Fade', 'foogallery' ),
|
140
|
|
|
'foogrid-transition-horizontal' => __( 'Horizontal', 'foogallery' ),
|
141
|
|
|
'foogrid-transition-vertical' => __( 'Vertical', 'foogallery' ),
|
142
|
|
|
'' => __( 'None', 'foogallery' )
|
143
|
|
|
),
|
144
|
|
|
'row_data'=> array(
|
145
|
|
|
'data-foogallery-change-selector' => 'input',
|
146
|
|
|
'data-foogallery-value-selector' => 'input:checked',
|
147
|
|
|
'data-foogallery-preview' => 'class'
|
148
|
|
|
)
|
149
|
|
|
),
|
150
|
|
|
array(
|
151
|
|
|
'id' => 'loop',
|
152
|
|
|
'section' => __( 'General', 'foogallery' ),
|
153
|
|
|
'title' => __('Loop', 'foogallery'),
|
154
|
|
|
'desc' => __('Whether the slider should loop (i.e. the first slide goes to the last, the last slide goes to the first).', 'foogallery'),
|
155
|
|
|
'default' => 'yes',
|
156
|
|
|
'type' => 'radio',
|
157
|
|
|
'spacer' => '<span class="spacer"></span>',
|
158
|
|
|
'choices' => array(
|
159
|
|
|
'yes' => __( 'Yes', 'foogallery' ),
|
160
|
|
|
'no' => __( 'No', 'foogallery' )
|
161
|
|
|
),
|
162
|
|
|
'row_data'=> array(
|
163
|
|
|
'data-foogallery-change-selector' => 'input',
|
164
|
|
|
'data-foogallery-value-selector' => 'input:checked',
|
165
|
|
|
'data-foogallery-preview' => 'shortcode'
|
166
|
|
|
)
|
167
|
|
|
),
|
168
|
|
|
array(
|
169
|
|
|
'id' => 'columns',
|
170
|
|
|
'section' => __( 'General', 'foogallery' ),
|
171
|
|
|
'title' => __('Max Columns', 'foogallery'),
|
172
|
|
|
'desc' => __('The maximum number of thumbnail columns to display. * This amount is automatically reduced on small screen sizes.', 'foogallery'),
|
173
|
|
|
'default' => 'foogrid-cols-4',
|
174
|
|
|
'type' => 'select',
|
175
|
|
|
'choices' => array(
|
176
|
|
|
'foogrid-cols-2' => __( '2 Columns', 'foogallery' ),
|
177
|
|
|
'foogrid-cols-3' => __( '3 Columns', 'foogallery' ),
|
178
|
|
|
'foogrid-cols-4' => __( '4 Columns', 'foogallery' ),
|
179
|
|
|
'foogrid-cols-5' => __( '5 Columns', 'foogallery' ),
|
180
|
|
|
'foogrid-cols-6' => __( '6 Columns', 'foogallery' ),
|
181
|
|
|
'foogrid-cols-7' => __( '7 Columns', 'foogallery' ),
|
182
|
|
|
'foogrid-cols-8' => __( '8 Columns', 'foogallery' )
|
183
|
|
|
),
|
184
|
|
|
'row_data'=> array(
|
185
|
|
|
'data-foogallery-change-selector' => 'select',
|
186
|
|
|
'data-foogallery-value-selector' => 'option:selected',
|
187
|
|
|
'data-foogallery-preview' => 'class'
|
188
|
|
|
)
|
189
|
|
|
),
|
190
|
|
|
array(
|
191
|
|
|
'id' => 'captions',
|
192
|
|
|
'section' => __( 'General', 'foogallery' ),
|
193
|
|
|
'title' => __('Stage Caption', 'foogallery'),
|
194
|
|
|
'desc' => __('The position of caption in the stage or no captions at all. * The caption will automatically switch to below the item on small screen sizes.', 'foogallery'),
|
195
|
|
|
'default' => 'foogrid-caption-below',
|
196
|
|
|
'type' => 'radio',
|
197
|
|
|
'spacer' => '<span class="spacer"></span>',
|
198
|
|
|
'choices' => array(
|
199
|
|
|
'foogrid-caption-below' => __( 'Below', 'foogallery' ),
|
200
|
|
|
'foogrid-caption-right' => __( 'Right', 'foogallery' ),
|
201
|
|
|
'' => __( 'None', 'foogallery' )
|
202
|
|
|
),
|
203
|
|
|
'row_data'=> array(
|
204
|
|
|
'data-foogallery-change-selector' => 'input',
|
205
|
|
|
'data-foogallery-value-selector' => 'input:checked',
|
206
|
|
|
'data-foogallery-preview' => 'class'
|
207
|
|
|
)
|
208
|
|
|
),
|
209
|
|
|
array(
|
210
|
|
|
'id' => 'scroll',
|
211
|
|
|
'section' => __( 'General', 'foogallery' ),
|
212
|
|
|
'title' => __('Scroll', 'foogallery'),
|
213
|
|
|
'desc' => __('Whether the page is scrolled to the selected item.', 'foogallery'),
|
214
|
|
|
'default' => 'yes',
|
215
|
|
|
'type' => 'radio',
|
216
|
|
|
'spacer' => '<span class="spacer"></span>',
|
217
|
|
|
'choices' => array(
|
218
|
|
|
'yes' => __( 'Yes', 'foogallery' ),
|
219
|
|
|
'no' => __( 'No', 'foogallery' )
|
220
|
|
|
),
|
221
|
|
|
'row_data'=> array(
|
222
|
|
|
'data-foogallery-change-selector' => 'input',
|
223
|
|
|
'data-foogallery-value-selector' => 'input:checked',
|
224
|
|
|
'data-foogallery-preview' => 'shortcode'
|
225
|
|
|
)
|
226
|
|
|
),
|
227
|
|
|
array(
|
228
|
|
|
'id' => 'scroll_smooth',
|
229
|
|
|
'section' => __( 'General', 'foogallery' ),
|
230
|
|
|
'title' => __('Smooth Scroll', 'foogallery'),
|
231
|
|
|
'desc' => __('Whether or not to perform a smooth scrolling animation to the selected item.', 'foogallery'),
|
232
|
|
|
'default' => 'yes',
|
233
|
|
|
'type' => 'radio',
|
234
|
|
|
'spacer' => '<span class="spacer"></span>',
|
235
|
|
|
'choices' => array(
|
236
|
|
|
'yes' => __( 'Yes', 'foogallery' ),
|
237
|
|
|
'no' => __( 'No', 'foogallery' )
|
238
|
|
|
),
|
239
|
|
|
'row_data'=> array(
|
240
|
|
|
'data-foogallery-change-selector' => 'input',
|
241
|
|
|
'data-foogallery-value-selector' => 'input:checked',
|
242
|
|
|
'data-foogallery-preview' => 'shortcode'
|
243
|
|
|
)
|
244
|
|
|
),
|
245
|
|
|
array(
|
246
|
|
|
'id' => 'scroll_offset',
|
247
|
|
|
'section' => __( 'General', 'foogallery' ),
|
248
|
|
|
'title' => __('Scroll Offset', 'foogallery'),
|
249
|
|
|
'desc' => __('The amount to offset scrolling by. * This can be used to counter fixed headers.', 'foogallery'),
|
250
|
|
|
'class' => 'small-text',
|
251
|
|
|
'type' => 'number',
|
252
|
|
|
'default' => 0,
|
253
|
|
|
'row_data'=> array(
|
254
|
|
|
'data-foogallery-change-selector' => 'input',
|
255
|
|
|
'data-foogallery-value-selector' => 'input',
|
256
|
|
|
'data-foogallery-preview' => 'shortcode'
|
257
|
|
|
)
|
258
|
|
|
),
|
259
|
|
|
)
|
260
|
|
|
);
|
261
|
|
|
|
262
|
|
|
return $gallery_templates;
|
263
|
|
|
}
|
264
|
|
|
|
265
|
|
|
/**
|
266
|
|
|
* Add the required data options if needed
|
267
|
|
|
*
|
268
|
|
|
* @param $options
|
269
|
|
|
* @param $gallery FooGallery
|
270
|
|
|
*
|
271
|
|
|
* @param $attributes array
|
272
|
|
|
*
|
273
|
|
|
* @return array
|
274
|
|
|
*/
|
275
|
|
|
function add_data_options($options, $gallery, $attributes) {
|
|
|
|
|
276
|
|
|
$loop = foogallery_gallery_template_setting( 'loop', 'yes' ) === 'yes';
|
277
|
|
|
$scroll = foogallery_gallery_template_setting( 'transition', 'yes' ) === 'yes';
|
278
|
|
|
$scroll_smooth = foogallery_gallery_template_setting( 'transition', 'yes' ) === 'yes';
|
279
|
|
|
$scroll_offset = foogallery_gallery_template_setting( 'scroll_offset', 0 );
|
280
|
|
|
|
281
|
|
|
$options['template']['loop'] = $loop;
|
282
|
|
|
$options['template']['scroll'] = $scroll;
|
283
|
|
|
$options['template']['scroll_smooth'] = $scroll_smooth;
|
284
|
|
|
$options['template']['scroll_offset'] = intval( $scroll_offset );
|
285
|
|
|
|
286
|
|
|
return $options;
|
287
|
|
|
}
|
288
|
|
|
|
289
|
|
|
/**
|
290
|
|
|
* Override specific settings so that the gallery template will always work
|
291
|
|
|
*
|
292
|
|
|
* @param $settings
|
293
|
|
|
* @param $post_id
|
294
|
|
|
* @param $form_data
|
295
|
|
|
*
|
296
|
|
|
* @return mixed
|
297
|
|
|
*/
|
298
|
|
|
function override_settings($settings, $post_id, $form_data) {
|
|
|
|
|
299
|
|
|
return $settings;
|
300
|
|
|
}
|
301
|
|
|
|
302
|
|
|
/**
|
303
|
|
|
* Build up a arguments used in the preview of the gallery
|
304
|
|
|
* @param $args
|
305
|
|
|
* @param $post_data
|
306
|
|
|
*
|
307
|
|
|
* @return mixed
|
308
|
|
|
*/
|
309
|
|
|
function preview_arguments( $args, $post_data ) {
|
|
|
|
|
310
|
|
|
$args['thumbnail_width'] = $post_data[FOOGALLERY_META_SETTINGS]['foogridpro_thumbnail_size']['width'];
|
311
|
|
|
$args['thumbnail_height'] = $post_data[FOOGALLERY_META_SETTINGS]['foogridpro_thumbnail_size']['height'];
|
312
|
|
|
$args['thumbnail_crop'] = isset( $post_data[FOOGALLERY_META_SETTINGS]['foogridpro_thumbnail_size']['crop'] ) ? '1' : '0';
|
313
|
|
|
return $args;
|
314
|
|
|
}
|
315
|
|
|
|
316
|
|
|
/**
|
317
|
|
|
* Builds thumb dimensions from arguments
|
318
|
|
|
*
|
319
|
|
|
* @param array $dimensions
|
320
|
|
|
* @param array $arguments
|
321
|
|
|
*
|
322
|
|
|
* @return mixed
|
323
|
|
|
*/
|
324
|
|
|
function build_thumbnail_dimensions_from_arguments( $dimensions, $arguments ) {
|
|
|
|
|
325
|
|
|
return array(
|
326
|
|
|
'height' => intval( $arguments['thumbnail_height'] ),
|
327
|
|
|
'width' => intval( $arguments['thumbnail_width'] ),
|
328
|
|
|
'crop' => $arguments['thumbnail_crop'] === '1'
|
329
|
|
|
);
|
330
|
|
|
}
|
331
|
|
|
|
332
|
|
|
/**
|
333
|
|
|
* Get the thumb dimensions arguments saved for the gallery for this gallery template
|
334
|
|
|
*
|
335
|
|
|
* @param array $dimensions
|
336
|
|
|
* @param FooGallery $foogallery
|
337
|
|
|
*
|
338
|
|
|
* @return mixed
|
339
|
|
|
*/
|
340
|
|
|
function get_thumbnail_dimensions( $dimensions, $foogallery ) {
|
|
|
|
|
341
|
|
|
$dimensions = $foogallery->get_meta( 'foogridpro_thumbnail_size', false );
|
342
|
|
|
return $dimensions;
|
343
|
|
|
}
|
344
|
|
|
}
|
345
|
|
|
} |
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.