GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 0f0dc5...fc8ae4 )
by Brad
02:33
created

FooGallery_Common_Fields   A

Complexity

Total Complexity 33

Size/Duplication

Total Lines 656
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 656
rs 9.3999
c 0
b 0
f 0
wmc 33
lcom 0
cbo 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 22 1
C alter_gallery_template_field() 0 23 7
B add_common_fields() 0 460 4
B add_common_fields_class_attributes() 0 37 6
B add_caption_data_options() 0 23 5
A preview_arguments() 0 8 1
A add_common_fields_data_attribute() 0 10 4
B check_downgrade_values() 0 12 5
1
<?php
2
/**
3
 * Adds all functionality related to the common gallery fields that are used in the default gallery templates
4
 * Date: 12/09/2017
5
 */
6
if ( ! class_exists( 'FooGallery_Common_Fields' ) ) {
7
8
	class FooGallery_Common_Fields {
9
10
		function __construct() {
11
            //handle some default field types that all templates can reuse
12
            add_filter( 'foogallery_alter_gallery_template_field', array( $this, 'alter_gallery_template_field' ), 10, 2 );
13
14
            //build up class attributes
15
			add_filter( 'foogallery_build_class_attribute', array( $this, 'add_common_fields_class_attributes' ), 10, 2 );
16
17
			//add our common field data attribute
18
			add_filter( 'foogallery_build_container_attributes', array( $this, 'add_common_fields_data_attribute' ), 10, 2 );
19
20
			//add common data options
21
			add_filter( 'foogallery_build_container_data_options', array( $this, 'add_caption_data_options' ), 10, 3 );
22
23
			//build up any preview arguments
24
			add_filter( 'foogallery_preview_arguments', array( $this, 'preview_arguments' ), 10, 3 );
25
26
            //add common fields to the templates that support it
27
            add_filter( 'foogallery_override_gallery_template_fields', array( $this, 'add_common_fields' ), 10, 2 );
28
29
            //check that we are no longer on pro and have previously used a preset or a loaded effect
30
            add_filter( 'foogallery_render_gallery_template_field_value', array( $this, 'check_downgrade_values' ), 10, 4 );
31
		}
32
33
        function alter_gallery_template_field( $field, $gallery ) {
34
            if ( $field ) {
35
36
            	if ( isset( $field['type'] ) ) {
37
					switch ( $field['type'] ) {
38
						case 'thumb_link':
39
							$field['type']    = 'radio';
40
							$field['choices'] = foogallery_gallery_template_field_thumb_link_choices();
41
							break;
42
						case 'lightbox':
43
							$field['lightbox'] = true;
44
							$field['type']     = 'select';
45
							$field['choices']  = foogallery_gallery_template_field_lightbox_choices();
46
							break;
47
					}
48
				}
49
50
                if ( isset($field['help']) && $field['help'] ) {
51
                    $field['type'] = 'help';
52
                }
53
            }
54
            return $field;
55
        }
56
57
		/**
58
		 * Add common fields to the gallery template if supported
59
		 *
60
		 * @param $fields
61
		 * @param $template
62
		 *
63
		 * @return array
64
		 */
65
		function add_common_fields( $fields, $template ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
66
			//check if the template supports the common fields
67
			if ( $template && array_key_exists( 'common_fields_support', $template ) && true === $template['common_fields_support'] ) {
68
69
				//region Appearance Fields
70
				$fields[] = array(
71
					'id'      => 'theme_custom_help',
72
					'title'   => __( 'Theme Help', 'foogallery' ),
73
					'desc'    => __( 'If you choose to use the Custom theme, then you will need to provide your own Custom CSS in order to style the gallery to suit your needs.', 'foogallery' ),
74
					'section' => __( 'Appearance', 'foogallery' ),
75
					'type'    => 'help',
76
					'row_data' => array(
77
						'data-foogallery-hidden' 				   => true,
78
						'data-foogallery-show-when-field'          => 'theme',
79
						'data-foogallery-show-when-field-value'    => 'fg-custom',
80
					)
81
				);
82
83
				$fields[] = array(
84
					'id'       => 'theme',
85
					'title'    => __( 'Theme', 'foogallery' ),
86
					'desc'     => __( 'The overall appearance of the items in the gallery, affecting the border, background, font and shadow colors.', 'foogallery' ),
87
					'section'  => __( 'Appearance', 'foogallery' ),
88
					'type'     => 'radio',
89
					'default'  => 'fg-light',
90
					'spacer'   => '<span class="spacer"></span>',
91
					'choices'  => array(
92
						'fg-light'  => __( 'Light', 'foogallery' ),
93
						'fg-dark'   => __( 'Dark', 'foogallery' ),
94
						'fg-custom' => __( 'Custom', 'foogallery' )
95
					),
96
					'row_data' => array(
97
						'data-foogallery-change-selector' => 'input:radio',
98
						'data-foogallery-value-selector'  => 'input:checked',
99
						'data-foogallery-preview'         => 'class'
100
					)
101
				);
102
103
				$fields[] = array(
104
					'id'       => 'border_size',
105
					'title'    => __( 'Border Size', 'foogallery' ),
106
					'desc'     => __( 'The border size applied to each thumbnail', 'foogallery' ),
107
					'section'  => __( 'Appearance', 'foogallery' ),
108
					'type'     => 'radio',
109
					'spacer'   => '<span class="spacer"></span>',
110
					'default'  => 'fg-border-thin',
111
					'choices'  => array(
112
						''                 => __( 'None', 'foogallery' ),
113
						'fg-border-thin'   => __( 'Thin', 'foogallery' ),
114
						'fg-border-medium' => __( 'Medium', 'foogallery' ),
115
						'fg-border-thick'  => __( 'Thick', 'foogallery' ),
116
					),
117
					'row_data' => array(
118
						'data-foogallery-change-selector' => 'input:radio',
119
						'data-foogallery-preview'         => 'class'
120
					)
121
				);
122
123
				$fields[] = array(
124
					'id'       => 'rounded_corners',
125
					'title'    => __( 'Rounded Corners', 'foogallery' ),
126
					'desc'     => __( 'The border radius, or rounded corners applied to each thumbnail', 'foogallery' ),
127
					'section'  => __( 'Appearance', 'foogallery' ),
128
					'type'     => 'radio',
129
					'spacer'   => '<span class="spacer"></span>',
130
					'default'  => '',
131
					'choices'  => array(
132
						''                => __( 'None', 'foogallery' ),
133
						'fg-round-small'  => __( 'Small', 'foogallery' ),
134
						'fg-round-medium' => __( 'Medium', 'foogallery' ),
135
						'fg-round-large'  => __( 'Large', 'foogallery' ),
136
						'fg-round-full'   => __( 'Full', 'foogallery' ),
137
					),
138
					'row_data' => array(
139
						'data-foogallery-change-selector' => 'input:radio',
140
						'data-foogallery-preview'         => 'class'
141
					)
142
				);
143
144
				$fields[] = array(
145
					'id'       => 'drop_shadow',
146
					'title'    => __( 'Drop Shadow', 'foogallery' ),
147
					'desc'     => __( 'The outer or drop shadow applied to each thumbnail', 'foogallery' ),
148
					'section'  => __( 'Appearance', 'foogallery' ),
149
					'type'     => 'radio',
150
					'spacer'   => '<span class="spacer"></span>',
151
					'default'  => 'fg-shadow-outline',
152
					'choices'  => array(
153
						''                  => __( 'None', 'foogallery' ),
154
						'fg-shadow-outline' => __( 'Outline', 'foogallery' ),
155
						'fg-shadow-small'   => __( 'Small', 'foogallery' ),
156
						'fg-shadow-medium'  => __( 'Medium', 'foogallery' ),
157
						'fg-shadow-large'   => __( 'Large', 'foogallery' ),
158
					),
159
					'row_data' => array(
160
						'data-foogallery-change-selector' => 'input:radio',
161
						'data-foogallery-preview'         => 'class'
162
					)
163
				);
164
165
				$fields[] = array(
166
					'id'       => 'inner_shadow',
167
					'title'    => __( 'Inner Shadow', 'foogallery' ),
168
					'desc'     => __( 'The inner shadow applied to each thumbnail', 'foogallery' ),
169
					'section'  => __( 'Appearance', 'foogallery' ),
170
					'type'     => 'radio',
171
					'spacer'   => '<span class="spacer"></span>',
172
					'default'  => '',
173
					'choices'  => array(
174
						''                       => __( 'None', 'foogallery' ),
175
						'fg-shadow-inset-small'  => __( 'Small', 'foogallery' ),
176
						'fg-shadow-inset-medium' => __( 'Medium', 'foogallery' ),
177
						'fg-shadow-inset-large'  => __( 'Large', 'foogallery' ),
178
					),
179
					'row_data' => array(
180
						'data-foogallery-change-selector' => 'input:radio',
181
						'data-foogallery-preview'         => 'class'
182
					)
183
				);
184
185
				$fields[] = array(
186
					'id'       => 'loading_icon',
187
					'title'    => __( 'Loading Icon', 'foogallery' ),
188
					'desc'     => __( 'An animated loading icon can be shown while the thumbnails are busy loading.', 'foogallery' ),
189
					'section'  => __( 'Appearance', 'foogallery' ),
190
					'default'  => 'fg-loading-default',
191
					'type'     => 'htmlicon',
192
					'choices'  => apply_filters(
193
						'foogallery_gallery_template_common_thumbnail_fields_loading_icon_choices', array(
194
						''                   => array( 'label' => __( 'None', 'foogallery' ), 'html' => '<div class="foogallery-setting-loading_icon"></div>' ),
195
						'fg-loading-default' => array( 'label' => __( 'Default', 'foogallery' ), 'html' => '<div class="foogallery-setting-loading_icon fg-loading-default"><div class="fg-loader"></div></div>' ),
196
						'fg-loading-bars'    => array( 'label' => __( 'Bars', 'foogallery' ), 'html' => '<div class="foogallery-setting-loading_icon fg-loading-bars"><div class="fg-loader"></div></div>' ),
197
						'fg-loading-dots'    => array( 'label' => __( 'Dots', 'foogallery' ), 'html' => '<div class="foogallery-setting-loading_icon fg-loading-dots"><div class="fg-loader"></div></div>' ),
198
						'fg-loading-partial' => array( 'label' => __( 'Partial', 'foogallery' ), 'html' => '<div class="foogallery-setting-loading_icon fg-loading-partial"><div class="fg-loader"></div></div>' ),
199
						'fg-loading-pulse'   => array( 'label' => __( 'Pulse', 'foogallery' ), 'html' => '<div class="foogallery-setting-loading_icon fg-loading-pulse"><div class="fg-loader"></div></div>' ),
200
						'fg-loading-trail'   => array( 'label' => __( 'Trail', 'foogallery' ), 'html' => '<div class="foogallery-setting-loading_icon fg-loading-trail"><div class="fg-loader"></div></div>' ),
201
					)
202
					),
203
					'row_data' => array(
204
						'data-foogallery-change-selector' => 'input:radio',
205
						'data-foogallery-preview'         => 'class'
206
					)
207
				);
208
209
				$fields[] = array(
210
					'id'       => 'loaded_effect',
211
					'title'    => __( 'Loaded Effect', 'foogallery' ),
212
					'desc'     => __( 'The animation effect used to display the thumbnail, once it has loaded.', 'foogallery' ),
213
					'section'  => __( 'Appearance', 'foogallery' ),
214
					'default'  => 'fg-loaded-fade-in',
215
					'type'     => 'select',
216
					'choices'  => apply_filters(
217
						'foogallery_gallery_template_common_thumbnail_fields_loaded_effect_choices', array(
218
						''                      => __( 'None', 'foogallery' ),
219
						'fg-loaded-fade-in'     => __( 'Fade In', 'foogallery' ),
220
					)
221
					),
222
					'row_data' => array(
223
						'data-foogallery-change-selector' => 'input:radio',
224
						'data-foogallery-preview'         => 'class'
225
					)
226
				);
227
				//endregion
228
229
				//region Hover Effects Fields
230
				$fields[] = array(
231
					'id'      => 'hover_effect_help',
232
					'title'   => __( 'Hover Effect Help', 'foogallery' ),
233
					'desc'    => __( 'A preset provides a stylish and pre-defined look &amp; feel for when you hover over the thumbnails.', 'foogallery' ),
234
					'section' => __( 'Hover Effects', 'foogallery' ),
235
					'type'    => 'help',
236
					'row_data' => array(
237
						'data-foogallery-hidden' => true,
238
					)
239
				);
240
241
				$fields[] = array(
242
					'id'       => 'hover_effect_preset',
243
					'title'    => __( 'Preset', 'foogallery' ),
244
					'section'  => __( 'Hover Effects', 'foogallery' ),
245
					'default'  => 'fg-custom',
246
					'type'     => 'radio',
247
					'choices'  => apply_filters(
248
						'foogallery_gallery_template_common_thumbnail_fields_hover_effect_preset_choices', array(
249
						''          => __( 'None', 'foogallery' ),
250
						'fg-custom' => __( 'Custom', 'foogallery' ),
251
					)
252
					),
253
					'spacer'   => '<span class="spacer"></span>',
254
					'desc'     => __( 'A preset styling that is used for the captions. If you want to define your own custom captions, then choose Custom.', 'foogallery' ),
255
					'row_data' => array(
256
						'data-foogallery-hidden'          => true,
257
						'data-foogallery-change-selector' => 'input:radio',
258
						'data-foogallery-value-selector'  => 'input:checked',
259
						'data-foogallery-preview'         => 'class'
260
					)
261
				);
262
263
				$fields[] = array(
264
					'id'       => 'hover_effect_preset_size',
265
					'title'    => __( 'Preset Size', 'foogallery' ),
266
					'section'  => __( 'Hover Effects', 'foogallery' ),
267
					'default'  => 'fg-preset-small',
268
					'spacer'   => '<span class="spacer"></span>',
269
					'type'     => 'radio',
270
					'choices'  => apply_filters(
271
						'foogallery_gallery_template_common_thumbnail_fields_hover_effect_preset_size_choices', array(
272
						'fg-preset-small'  => __( 'Small', 'foogallery' ),
273
						'fg-preset-medium' => __( 'Medium', 'foogallery' ),
274
						'fg-preset-large'  => __( 'Large', 'foogallery' ),
275
					)
276
					),
277
					'desc'     => __( 'Choose an appropriate size for the preset caption effects, based on the size of your thumbs. Choose small for thumbs 150-200 wide, medium for thumbs 200-400 wide, and large for thumbs over 400 wide.', 'foogallery' ),
278
					'row_data' => array(
279
						'data-foogallery-change-selector'          => 'input:radio',
280
						'data-foogallery-hidden'                   => true,
281
						'data-foogallery-show-when-field'          => 'hover_effect_preset',
282
						'data-foogallery-show-when-field-operator' => 'indexOf',
283
						'data-foogallery-show-when-field-value'    => 'fg-preset',
284
						'data-foogallery-preview'                  => 'class'
285
					)
286
				);
287
288
				$fields[] = array(
289
					'id'       => 'hover_effect_color',
290
					'title'    => __( 'Color Effect', 'foogallery' ),
291
					'section'  => __( 'Hover Effects', 'foogallery' ),
292
					'default'  => '',
293
					'spacer'   => '<span class="spacer"></span>',
294
					'type'     => 'radio',
295
					'choices'  => apply_filters(
296
						'foogallery_gallery_template_common_thumbnail_fields_hover_effect_color_choices', array(
297
						''                   => __( 'None', 'foogallery' ),
298
						'fg-hover-colorize'  => __( 'Colorize', 'foogallery' ),
299
						'fg-hover-grayscale' => __( 'Greyscale', 'foogallery' ),
300
					)
301
					),
302
					'desc'     => __( 'Choose an color effect that is applied when you hover over a thumbnail.', 'foogallery' ),
303
					'row_data' => array(
304
						'data-foogallery-change-selector'       => 'input:radio',
305
						'data-foogallery-hidden'                => true,
306
						'data-foogallery-show-when-field'       => 'hover_effect_preset',
307
						'data-foogallery-show-when-field-value' => 'fg-custom',
308
						'data-foogallery-preview'               => 'class'
309
					)
310
				);
311
312
				$fields[] = array(
313
					'id'       => 'hover_effect_scale',
314
					'title'    => __( 'Scaling Effect', 'foogallery' ),
315
					'section'  => __( 'Hover Effects', 'foogallery' ),
316
					'default'  => '',
317
					'spacer'   => '<span class="spacer"></span>',
318
					'type'     => 'radio',
319
					'choices'  => apply_filters(
320
						'foogallery_gallery_template_common_thumbnail_fields_hover_effect_scale_choices', array(
321
						''               => __( 'None', 'foogallery' ),
322
						'fg-hover-scale' => __( 'Scaled', 'foogallery' ),
323
					)
324
					),
325
					'desc'     => __( 'Apply a slight scaling effect when hovering over a thumbnail.', 'foogallery' ),
326
					'row_data' => array(
327
						'data-foogallery-change-selector'       => 'input:radio',
328
						'data-foogallery-hidden'                => true,
329
						'data-foogallery-show-when-field'       => 'hover_effect_preset',
330
						'data-foogallery-show-when-field-value' => 'fg-custom',
331
						'data-foogallery-preview'               => 'class'
332
					)
333
				);
334
335
				$fields[] = array(
336
					'id'       => 'hover_effect_caption_visibility',
337
					'title'    => __( 'Caption Visibility', 'foogallery' ),
338
					'section'  => __( 'Hover Effects', 'foogallery' ),
339
					'default'  => 'fg-caption-hover',
340
					'spacer'   => '<span class="spacer"></span>',
341
					'type'     => 'radio',
342
					'choices'  => apply_filters(
343
						'foogallery_gallery_template_common_thumbnail_fields_hover_effect_caption_visibility_choices', array(
344
						''                  => __( 'None', 'foogallery' ),
345
						'fg-caption-hover'  => __( 'On Hover', 'foogallery' ),
346
						'fg-caption-always' => __( 'Always Visible', 'foogallery' ),
347
					)
348
					),
349
					'desc'     => __( 'Choose how the captions will be displayed.', 'foogallery' ),
350
					'row_data' => array(
351
						'data-foogallery-change-selector'       => 'input:radio',
352
						'data-foogallery-hidden'                => true,
353
						'data-foogallery-show-when-field'       => 'hover_effect_preset',
354
						'data-foogallery-show-when-field-value' => 'fg-custom',
355
						'data-foogallery-preview'               => 'class'
356
					)
357
				);
358
359
				$fields[] = array(
360
					'id'       => 'hover_effect_transition',
361
					'title'    => __( 'Transition', 'foogallery' ),
362
					'section'  => __( 'Hover Effects', 'foogallery' ),
363
					'default'  => 'fg-hover-fade',
364
					'type'     => 'select',
365
					'choices'  => apply_filters( 'foogallery_gallery_template_common_thumbnail_fields_hover_effect_transition_choices', array(
366
						'fg-hover-instant'     => __( 'Instant', 'foogallery' ),
367
						'fg-hover-fade'        => __( 'Fade', 'foogallery' ),
368
						'fg-hover-slide-up'    => __( 'Slide Up', 'foogallery' ),
369
						'fg-hover-slide-down'  => __( 'Slide Down', 'foogallery' ),
370
						'fg-hover-slide-left'  => __( 'Slide Left', 'foogallery' ),
371
						'fg-hover-slide-right' => __( 'Slide Right', 'foogallery' ),
372
						'fg-hover-push'        => __( 'Push', 'foogallery' ) )
373
					),
374
					'desc'     => __( 'Choose what effect is used to show the caption when you hover over a thumbnail', 'foogallery' ),
375
					'row_data' => array(
376
						'data-foogallery-change-selector'       => 'select',
377
						'data-foogallery-hidden'                => true,
378
						'data-foogallery-show-when-field'       => 'hover_effect_preset',
379
						'data-foogallery-show-when-field-value' => 'fg-custom',
380
						'data-foogallery-preview'               => 'class'
381
					)
382
				);
383
384
				$fields[] = array(
385
					'id'       => 'hover_effect_icon',
386
					'title'    => __( 'Icon', 'foogallery' ),
387
					'desc'     => __( 'Choose which icon is shown with the caption when you hover over a thumbnail', 'foogallery' ),
388
					'section'  => __( 'Hover Effects', 'foogallery' ),
389
					'type'     => 'htmlicon',
390
					'default'  => 'fg-hover-zoom',
391
					'choices'  => apply_filters( 'foogallery_gallery_template_common_thumbnail_fields_hover_effect_icon_choices', array(
392
						''                     => array( 'label' => __( 'None', 'foogallery' ), 'html' => '<div class="foogallery-setting-caption_icon"></div>' ),
393
						'fg-hover-zoom'        => array( 'label' => __( 'Zoom', 'foogallery' ), 'html' => '<div class="foogallery-setting-caption_icon fg-hover-zoom"></div>' ),
394
						'fg-hover-zoom2'       => array( 'label' => __( 'Zoom 2', 'foogallery' ), 'html' => '<div class="foogallery-setting-caption_icon fg-hover-zoom2"></div>' ),
395
						'fg-hover-zoom3'       => array( 'label' => __( 'Zoom 3', 'foogallery' ), 'html' => '<div class="foogallery-setting-caption_icon fg-hover-zoom3"></div>' ),
396
						'fg-hover-plus'        => array( 'label' => __( 'Plus', 'foogallery' ), 'html' => '<div class="foogallery-setting-caption_icon fg-hover-plus"></div>' ),
397
						'fg-hover-circle-plus' => array( 'label' => __( 'Circle Plus', 'foogallery' ), 'html' => '<div class="foogallery-setting-caption_icon fg-hover-circle-plus"></div>' ),
398
						'fg-hover-eye'         => array( 'label' => __( 'Eye', 'foogallery' ), 'html' => '<div class="foogallery-setting-caption_icon fg-hover-eye"></div>' ),
399
						'fg-hover-external'    => array( 'label' => __( 'External', 'foogallery' ), 'html' => '<div class="foogallery-setting-caption_icon fg-hover-external"></div>' ), )
400
					),
401
					'row_data' => array(
402
						'data-foogallery-change-selector'       => 'input:radio',
403
						'data-foogallery-hidden'                => true,
404
						'data-foogallery-show-when-field'       => 'hover_effect_preset',
405
						'data-foogallery-show-when-field-value' => 'fg-custom',
406
						'data-foogallery-preview'               => 'class'
407
					)
408
				);
409
				//endregion Hover Effects Fields
410
411
				//region Caption Fields
412
				$fields[] = array(
413
					'id'      => 'captions_help',
414
					'title'   => __( 'Captions Help', 'foogallery' ),
415
					'desc'    => __( 'You can change when captions are shown using the "Hover Effects -> Caption Visibility" setting .', 'foogallery' ),
416
					'section' => __( 'Captions', 'foogallery' ),
417
					'type'    => 'help'
418
				);
419
420
				$settings_link = sprintf( '<a target="blank" href="%s">%s</a>', foogallery_admin_settings_url(), __( 'settings', 'foogallery' ) );
421
422
				$fields[] = array(
423
					'id'       => 'caption_title_source',
424
					'title'    => __( 'Title', 'foogallery' ),
425
					'desc'     => __( 'Decide where caption titles are pulled from. By default, what is saved under general settings will be used, but it can be overridden per gallery', 'foogallery' ),
426
					'section'  => __( 'Captions', 'foogallery' ),
427
					'type'     => 'radio',
428
					'default'  => '',
429
					'choices'  => array(
430
						'none'    => __( 'None', 'foogallery' ),
431
						''        => sprintf( __( 'Default (as per %s)', 'foogallery' ), $settings_link ),
432
						'title'   => foogallery_get_attachment_field_friendly_name( 'title' ),
433
						'caption' => foogallery_get_attachment_field_friendly_name( 'caption' ),
434
						'alt'     => foogallery_get_attachment_field_friendly_name( 'alt' ),
435
						'desc'    => foogallery_get_attachment_field_friendly_name( 'desc' ),
436
					),
437
					'row_data' => array(
438
						'data-foogallery-change-selector'       => 'input:radio',
439
						'data-foogallery-preview'               => 'shortcode'
440
					)
441
				);
442
443
				$fields[] = array(
444
					'id'       => 'caption_desc',
445
					'title'    => __( 'Description', 'foogallery' ),
446
					'desc'     => __( 'Decide where captions descriptions are pulled from. By default, the general settings are used, but it can be overridden per gallery', 'foogallery' ),
447
					'section'  => __( 'Captions', 'foogallery' ),
448
					'type'     => 'radio',
449
					'default'  => '',
450
					'choices'  => array(
451
						'none'    => __( 'None', 'foogallery' ),
452
						''        => sprintf( __( 'Default (as per %s)', 'foogallery' ), $settings_link ),
453
						'title'   => foogallery_get_attachment_field_friendly_name( 'title' ),
454
						'caption' => foogallery_get_attachment_field_friendly_name( 'caption' ),
455
						'alt'     => foogallery_get_attachment_field_friendly_name( 'alt' ),
456
						'desc'    => foogallery_get_attachment_field_friendly_name( 'desc' ),
457
					),
458
					'row_data' => array(
459
						'data-foogallery-change-selector'       => 'input:radio',
460
						'data-foogallery-preview'               => 'shortcode'
461
					)
462
				);
463
464
				$fields[] = array(
465
					'id'      => 'captions_limit_length',
466
					'title'   => __( 'Limit Caption Length', 'foogallery' ),
467
					'desc'    => __( 'You can limit the length of caption title and descriptions in the thumbnails. This will NOT limit the length of captions from within the lightbox.', 'foogallery' ),
468
					'section' => __( 'Captions', 'foogallery' ),
469
					'default' => '',
470
					'type'    => 'radio',
471
					'spacer'  => '<span class="spacer"></span>',
472
					'choices' => array(
473
						'' => __( 'No', 'foogallery' ),
474
						'yes' => __( 'Yes', 'foogallery' ),
475
					),
476
					'row_data'=> array(
477
						'data-foogallery-change-selector' => 'input:radio',
478
						'data-foogallery-preview' => 'shortcode',
479
						'data-foogallery-value-selector'  => 'input:checked',
480
					)
481
				);
482
483
				$fields[] = array(
484
					'id'      => 'caption_title_length',
485
					'title'   => __( 'Max Title Length', 'foogallery' ),
486
					'desc'	  => __( 'A max length of zero will not apply a limit.', 'foogallery '),
487
					'section' => __( 'Captions', 'foogallery' ),
488
					'type'    => 'number',
489
					'class'   => 'small-text',
490
					'default' => 0,
491
					'step'    => '1',
492
					'min'     => '0',
493
					'row_data' => array(
494
						'data-foogallery-change-selector'       => 'input',
495
						'data-foogallery-hidden'                => true,
496
						'data-foogallery-show-when-field'       => 'captions_limit_length',
497
						'data-foogallery-show-when-field-value' => 'yes',
498
						'data-foogallery-preview'               => 'shortcode'
499
					)
500
				);
501
502
				$fields[] = array(
503
					'id'      => 'caption_desc_length',
504
					'title'   => __( 'Max Desc Length', 'foogallery' ),
505
					'desc'	  => __( 'A max length of zero will not apply a limit.', 'foogallery '),
506
					'section' => __( 'Captions', 'foogallery' ),
507
					'type'    => 'number',
508
					'class'   => 'small-text',
509
					'default' => 0,
510
					'step'    => '1',
511
					'min'     => '0',
512
					'row_data' => array(
513
						'data-foogallery-change-selector'       => 'input',
514
						'data-foogallery-hidden'                => true,
515
						'data-foogallery-show-when-field'       => 'captions_limit_length',
516
						'data-foogallery-show-when-field-value' => 'yes',
517
						'data-foogallery-preview'               => 'shortcode'
518
					)
519
				);
520
				//endregion
521
522
			}
523
			return $fields;
524
		}
525
526
		/**
527
		 * Build up the gallery class attribute for the common fields
528
		 *
529
		 * @param $classes array
530
		 * @param $gallery FooGallery
531
		 *
532
		 * @return array
533
		 */
534
		function add_common_fields_class_attributes( $classes, $gallery ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
535
			$template_data = foogallery_get_gallery_template( $gallery->gallery_template );
536
537
			//check the template supports common fields
538
			if ( $template_data && array_key_exists( 'common_fields_support', $template_data ) && true === $template_data['common_fields_support'] ) {
539
540
				//add the gallery template core class
541
				$classes[] = 'fg-' . $gallery->gallery_template;
542
543
				//get some default classes from common gallery settings
544
				$classes[] = $gallery->get_setting( 'theme', 'fg-light' );
545
				$classes[] = $gallery->get_setting( 'border_size', 'fg-border-thin' );
546
				$classes[] = $gallery->get_setting( 'rounded_corners', '' );
547
				$classes[] = $gallery->get_setting( 'drop_shadow', 'fg-shadow-outline' );
548
				$classes[] = $gallery->get_setting( 'inner_shadow', '' );
549
				$classes[] = $gallery->get_setting( 'loading_icon', 'fg-loading-default' );
550
				$classes[] = $gallery->get_setting( 'loaded_effect', 'fg-loaded-fade-in' );
551
552
				$caption_preset = $gallery->get_setting( 'hover_effect_preset', 'fg-custom' );
553
554
				$classes[] = $caption_preset;
555
556
				if ( 'fg-custom' === $caption_preset ) {
557
					//only set these caption classes if custom preset is selected
558
					$classes[] = $gallery->get_setting( 'hover_effect_color', '' );
559
					$classes[] = $gallery->get_setting( 'hover_effect_scale', '' );
560
					$classes[] = $gallery->get_setting( 'hover_effect_caption_visibility', 'fg-caption-hover' );
561
					$classes[] = $gallery->get_setting( 'hover_effect_transition', 'fg-hover-fade' );
562
					$classes[] = $gallery->get_setting( 'hover_effect_icon', 'fg-hover-zoom' );
563
				} else if ( strpos( $caption_preset, 'fg-preset' ) !== false ) {
564
					//set a preset size
565
					$classes[] = $gallery->get_setting( 'hover_effect_preset_size', 'fg-preset-small' );
566
				}
567
			}
568
569
			return $classes;
570
		}
571
572
		/**
573
		 * Add the required data options for captions
574
		 *
575
		 * @param $options
576
		 * @param $gallery    FooGallery
577
		 *
578
		 * @param $attributes array
579
		 *
580
		 * @return array
581
		 */
582
		function add_caption_data_options($options, $gallery, $attributes) {
0 ignored issues
show
Unused Code introduced by
The parameter $attributes is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
583
			$template_data = foogallery_get_gallery_template( $gallery->gallery_template );
584
585
			//check the template supports common fields
586
			if ( $template_data && array_key_exists( 'common_fields_support', $template_data ) && true === $template_data['common_fields_support'] ) {
587
588
				$caption_title = foogallery_gallery_template_setting( 'caption_title_source', '' );
589
				$caption_desc  = foogallery_gallery_template_setting( 'caption_desc_source', '' );
590
591
				$options['item']['showCaptionTitle']       = $caption_title != 'none';
592
				$options['item']['showCaptionDescription'] = $caption_desc != 'none';
593
594
				$captions_limit_length = foogallery_gallery_template_setting( 'captions_limit_length', '' );
595
596
				if ( 'yes' === $captions_limit_length ) {
597
					$caption_title_length                    = foogallery_gallery_template_setting( 'caption_title_length', '0' );
598
					$caption_desc_length                     = foogallery_gallery_template_setting( 'caption_desc_length', '0' );
599
					$options['item']['maxCaptionLength']     = intval( $caption_title_length );
600
					$options['item']['maxDescriptionLength'] = intval( $caption_desc_length );
601
				}
602
			}
603
			return $options;
604
		}
605
606
		/**
607
		 * Build up a arguments used in the preview of the gallery
608
		 * @param $args
609
		 * @param $post_data
610
		 * @param $template
611
		 *
612
		 * @return mixed
613
		 */
614
		function preview_arguments( $args, $post_data, $template ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
615
			$args['caption_title_source'] = $post_data[FOOGALLERY_META_SETTINGS][$template . '_caption_title_source'];
616
			$args['caption_desc_source'] = $post_data[FOOGALLERY_META_SETTINGS][$template . '_caption_desc_source'];
617
			$args['captions_limit_length'] = $post_data[FOOGALLERY_META_SETTINGS][$template . '_captions_limit_length'];
618
			$args['caption_title_length'] = $post_data[FOOGALLERY_META_SETTINGS][$template . '_caption_title_length'];
619
			$args['caption_desc_length'] = $post_data[FOOGALLERY_META_SETTINGS][$template . '_caption_desc_length'];
620
			return $args;
621
		}
622
623
		/**
624
		 * Build up the gallery data attributes for the common fields
625
		 *
626
		 * @param $attributes array
627
		 * @param $gallery FooGallery
628
		 *
629
		 * @return array
630
		 */
631
		function add_common_fields_data_attribute( $attributes, $gallery ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
632
			$template_data = foogallery_get_gallery_template( $gallery->gallery_template );
633
634
			//check the template supports common fields
635
			if ( $template_data && array_key_exists( 'common_fields_support', $template_data ) && true === $template_data['common_fields_support'] ) {
636
				$attributes['data-fg-common-fields'] = true;
637
			}
638
639
			return $attributes;
640
		}
641
642
        /***
643
         * Check if we have a value from FooBox free and change it if foobox free is no longer active
644
         * @param $value
645
         * @param $field
646
         * @param $gallery
647
         * @param $template
648
         *
649
         * @return string
650
         */
651
        function check_downgrade_values($value, $field, $gallery, $template) {
0 ignored issues
show
Unused Code introduced by
The parameter $gallery is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $template is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
652
653
            if ( isset( $field['type'] ) ) {
654
                if ( 'hover_effect_preset' === $field['id'] || 'loaded_effect' === $field['type'] ) {
655
                    if ( !array_key_exists( $value, $field['choices'] ) ) {
656
                        $value = $field['default'];
657
                    }
658
                }
659
            }
660
661
            return $value;
662
        }
663
	}
664
}