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 ( c721e5...0f0dc5 )
by Brad
03:00
created

FooGallery_Common_Fields::add_common_fields()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 460
Code Lines 360

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 360
nc 2
nop 2
dl 0
loc 460
rs 8.1935
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
30
        function alter_gallery_template_field( $field, $gallery ) {
31
            if ( $field ) {
32
33
            	if ( isset( $field['type'] ) ) {
34
					switch ( $field['type'] ) {
35
						case 'thumb_link':
36
							$field['type']    = 'radio';
37
							$field['choices'] = foogallery_gallery_template_field_thumb_link_choices();
38
							break;
39
						case 'lightbox':
40
							$field['lightbox'] = true;
41
							$field['type']     = 'select';
42
							$field['choices']  = foogallery_gallery_template_field_lightbox_choices();
43
							break;
44
					}
45
				}
46
47
                if ( isset($field['help']) && $field['help'] ) {
48
                    $field['type'] = 'help';
49
                }
50
            }
51
            return $field;
52
        }
53
54
		/**
55
		 * Add common fields to the gallery template if supported
56
		 *
57
		 * @param $fields
58
		 * @param $template
59
		 *
60
		 * @return array
61
		 */
62
		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...
63
			//check if the template supports the common fields
64
			if ( $template && array_key_exists( 'common_fields_support', $template ) && true === $template['common_fields_support'] ) {
65
66
				//region Appearance Fields
67
				$fields[] = array(
68
					'id'      => 'theme_custom_help',
69
					'title'   => __( 'Theme Help', 'foogallery' ),
70
					'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' ),
71
					'section' => __( 'Appearance', 'foogallery' ),
72
					'type'    => 'help',
73
					'row_data' => array(
74
						'data-foogallery-hidden' 				   => true,
75
						'data-foogallery-show-when-field'          => 'theme',
76
						'data-foogallery-show-when-field-value'    => 'fg-custom',
77
					)
78
				);
79
80
				$fields[] = array(
81
					'id'       => 'theme',
82
					'title'    => __( 'Theme', 'foogallery' ),
83
					'desc'     => __( 'The overall appearance of the items in the gallery, affecting the border, background, font and shadow colors.', 'foogallery' ),
84
					'section'  => __( 'Appearance', 'foogallery' ),
85
					'type'     => 'radio',
86
					'default'  => 'fg-light',
87
					'spacer'   => '<span class="spacer"></span>',
88
					'choices'  => array(
89
						'fg-light'  => __( 'Light', 'foogallery' ),
90
						'fg-dark'   => __( 'Dark', 'foogallery' ),
91
						'fg-custom' => __( 'Custom', 'foogallery' )
92
					),
93
					'row_data' => array(
94
						'data-foogallery-change-selector' => 'input:radio',
95
						'data-foogallery-value-selector'  => 'input:checked',
96
						'data-foogallery-preview'         => 'class'
97
					)
98
				);
99
100
				$fields[] = array(
101
					'id'       => 'border_size',
102
					'title'    => __( 'Border Size', 'foogallery' ),
103
					'desc'     => __( 'The border size applied to each thumbnail', 'foogallery' ),
104
					'section'  => __( 'Appearance', 'foogallery' ),
105
					'type'     => 'radio',
106
					'spacer'   => '<span class="spacer"></span>',
107
					'default'  => 'fg-border-thin',
108
					'choices'  => array(
109
						''                 => __( 'None', 'foogallery' ),
110
						'fg-border-thin'   => __( 'Thin', 'foogallery' ),
111
						'fg-border-medium' => __( 'Medium', 'foogallery' ),
112
						'fg-border-thick'  => __( 'Thick', 'foogallery' ),
113
					),
114
					'row_data' => array(
115
						'data-foogallery-change-selector' => 'input:radio',
116
						'data-foogallery-preview'         => 'class'
117
					)
118
				);
119
120
				$fields[] = array(
121
					'id'       => 'rounded_corners',
122
					'title'    => __( 'Rounded Corners', 'foogallery' ),
123
					'desc'     => __( 'The border radius, or rounded corners applied to each thumbnail', 'foogallery' ),
124
					'section'  => __( 'Appearance', 'foogallery' ),
125
					'type'     => 'radio',
126
					'spacer'   => '<span class="spacer"></span>',
127
					'default'  => '',
128
					'choices'  => array(
129
						''                => __( 'None', 'foogallery' ),
130
						'fg-round-small'  => __( 'Small', 'foogallery' ),
131
						'fg-round-medium' => __( 'Medium', 'foogallery' ),
132
						'fg-round-large'  => __( 'Large', 'foogallery' ),
133
						'fg-round-full'   => __( 'Full', 'foogallery' ),
134
					),
135
					'row_data' => array(
136
						'data-foogallery-change-selector' => 'input:radio',
137
						'data-foogallery-preview'         => 'class'
138
					)
139
				);
140
141
				$fields[] = array(
142
					'id'       => 'drop_shadow',
143
					'title'    => __( 'Drop Shadow', 'foogallery' ),
144
					'desc'     => __( 'The outer or drop shadow applied to each thumbnail', 'foogallery' ),
145
					'section'  => __( 'Appearance', 'foogallery' ),
146
					'type'     => 'radio',
147
					'spacer'   => '<span class="spacer"></span>',
148
					'default'  => 'fg-shadow-outline',
149
					'choices'  => array(
150
						''                  => __( 'None', 'foogallery' ),
151
						'fg-shadow-outline' => __( 'Outline', 'foogallery' ),
152
						'fg-shadow-small'   => __( 'Small', 'foogallery' ),
153
						'fg-shadow-medium'  => __( 'Medium', 'foogallery' ),
154
						'fg-shadow-large'   => __( 'Large', 'foogallery' ),
155
					),
156
					'row_data' => array(
157
						'data-foogallery-change-selector' => 'input:radio',
158
						'data-foogallery-preview'         => 'class'
159
					)
160
				);
161
162
				$fields[] = array(
163
					'id'       => 'inner_shadow',
164
					'title'    => __( 'Inner Shadow', 'foogallery' ),
165
					'desc'     => __( 'The inner shadow applied to each thumbnail', 'foogallery' ),
166
					'section'  => __( 'Appearance', 'foogallery' ),
167
					'type'     => 'radio',
168
					'spacer'   => '<span class="spacer"></span>',
169
					'default'  => '',
170
					'choices'  => array(
171
						''                       => __( 'None', 'foogallery' ),
172
						'fg-shadow-inset-small'  => __( 'Small', 'foogallery' ),
173
						'fg-shadow-inset-medium' => __( 'Medium', 'foogallery' ),
174
						'fg-shadow-inset-large'  => __( 'Large', 'foogallery' ),
175
					),
176
					'row_data' => array(
177
						'data-foogallery-change-selector' => 'input:radio',
178
						'data-foogallery-preview'         => 'class'
179
					)
180
				);
181
182
				$fields[] = array(
183
					'id'       => 'loading_icon',
184
					'title'    => __( 'Loading Icon', 'foogallery' ),
185
					'desc'     => __( 'An animated loading icon can be shown while the thumbnails are busy loading.', 'foogallery' ),
186
					'section'  => __( 'Appearance', 'foogallery' ),
187
					'default'  => 'fg-loading-default',
188
					'type'     => 'htmlicon',
189
					'choices'  => apply_filters(
190
						'foogallery_gallery_template_common_thumbnail_fields_loading_icon_choices', array(
191
						''                   => array( 'label' => __( 'None', 'foogallery' ), 'html' => '<div class="foogallery-setting-loading_icon"></div>' ),
192
						'fg-loading-default' => array( 'label' => __( 'Default', 'foogallery' ), 'html' => '<div class="foogallery-setting-loading_icon fg-loading-default"><div class="fg-loader"></div></div>' ),
193
						'fg-loading-bars'    => array( 'label' => __( 'Bars', 'foogallery' ), 'html' => '<div class="foogallery-setting-loading_icon fg-loading-bars"><div class="fg-loader"></div></div>' ),
194
						'fg-loading-dots'    => array( 'label' => __( 'Dots', 'foogallery' ), 'html' => '<div class="foogallery-setting-loading_icon fg-loading-dots"><div class="fg-loader"></div></div>' ),
195
						'fg-loading-partial' => array( 'label' => __( 'Partial', 'foogallery' ), 'html' => '<div class="foogallery-setting-loading_icon fg-loading-partial"><div class="fg-loader"></div></div>' ),
196
						'fg-loading-pulse'   => array( 'label' => __( 'Pulse', 'foogallery' ), 'html' => '<div class="foogallery-setting-loading_icon fg-loading-pulse"><div class="fg-loader"></div></div>' ),
197
						'fg-loading-trail'   => array( 'label' => __( 'Trail', 'foogallery' ), 'html' => '<div class="foogallery-setting-loading_icon fg-loading-trail"><div class="fg-loader"></div></div>' ),
198
					)
199
					),
200
					'row_data' => array(
201
						'data-foogallery-change-selector' => 'input:radio',
202
						'data-foogallery-preview'         => 'class'
203
					)
204
				);
205
206
				$fields[] = array(
207
					'id'       => 'loaded_effect',
208
					'title'    => __( 'Loaded Effect', 'foogallery' ),
209
					'desc'     => __( 'The animation effect used to display the thumbnail, once it has loaded.', 'foogallery' ),
210
					'section'  => __( 'Appearance', 'foogallery' ),
211
					'default'  => 'fg-loaded-fade-in',
212
					'type'     => 'select',
213
					'choices'  => apply_filters(
214
						'foogallery_gallery_template_common_thumbnail_fields_loaded_effect_choices', array(
215
						''                      => __( 'None', 'foogallery' ),
216
						'fg-loaded-fade-in'     => __( 'Fade In', 'foogallery' ),
217
					)
218
					),
219
					'row_data' => array(
220
						'data-foogallery-change-selector' => 'input:radio',
221
						'data-foogallery-preview'         => 'class'
222
					)
223
				);
224
				//endregion
225
226
				//region Hover Effects Fields
227
				$fields[] = array(
228
					'id'      => 'hover_effect_help',
229
					'title'   => __( 'Hover Effect Help', 'foogallery' ),
230
					'desc'    => __( 'A preset provides a stylish and pre-defined look &amp; feel for when you hover over the thumbnails.', 'foogallery' ),
231
					'section' => __( 'Hover Effects', 'foogallery' ),
232
					'type'    => 'help',
233
					'row_data' => array(
234
						'data-foogallery-hidden' => true,
235
					)
236
				);
237
238
				$fields[] = array(
239
					'id'       => 'hover_effect_preset',
240
					'title'    => __( 'Preset', 'foogallery' ),
241
					'section'  => __( 'Hover Effects', 'foogallery' ),
242
					'default'  => 'fg-custom',
243
					'type'     => 'radio',
244
					'choices'  => apply_filters(
245
						'foogallery_gallery_template_common_thumbnail_fields_hover_effect_preset_choices', array(
246
						''          => __( 'None', 'foogallery' ),
247
						'fg-custom' => __( 'Custom', 'foogallery' ),
248
					)
249
					),
250
					'spacer'   => '<span class="spacer"></span>',
251
					'desc'     => __( 'A preset styling that is used for the captions. If you want to define your own custom captions, then choose Custom.', 'foogallery' ),
252
					'row_data' => array(
253
						'data-foogallery-hidden'          => true,
254
						'data-foogallery-change-selector' => 'input:radio',
255
						'data-foogallery-value-selector'  => 'input:checked',
256
						'data-foogallery-preview'         => 'class'
257
					)
258
				);
259
260
				$fields[] = array(
261
					'id'       => 'hover_effect_preset_size',
262
					'title'    => __( 'Preset Size', 'foogallery' ),
263
					'section'  => __( 'Hover Effects', 'foogallery' ),
264
					'default'  => 'fg-preset-small',
265
					'spacer'   => '<span class="spacer"></span>',
266
					'type'     => 'radio',
267
					'choices'  => apply_filters(
268
						'foogallery_gallery_template_common_thumbnail_fields_hover_effect_preset_size_choices', array(
269
						'fg-preset-small'  => __( 'Small', 'foogallery' ),
270
						'fg-preset-medium' => __( 'Medium', 'foogallery' ),
271
						'fg-preset-large'  => __( 'Large', 'foogallery' ),
272
					)
273
					),
274
					'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' ),
275
					'row_data' => array(
276
						'data-foogallery-change-selector'          => 'input:radio',
277
						'data-foogallery-hidden'                   => true,
278
						'data-foogallery-show-when-field'          => 'hover_effect_preset',
279
						'data-foogallery-show-when-field-operator' => 'indexOf',
280
						'data-foogallery-show-when-field-value'    => 'fg-preset',
281
						'data-foogallery-preview'                  => 'class'
282
					)
283
				);
284
285
				$fields[] = array(
286
					'id'       => 'hover_effect_color',
287
					'title'    => __( 'Color Effect', 'foogallery' ),
288
					'section'  => __( 'Hover Effects', 'foogallery' ),
289
					'default'  => '',
290
					'spacer'   => '<span class="spacer"></span>',
291
					'type'     => 'radio',
292
					'choices'  => apply_filters(
293
						'foogallery_gallery_template_common_thumbnail_fields_hover_effect_color_choices', array(
294
						''                   => __( 'None', 'foogallery' ),
295
						'fg-hover-colorize'  => __( 'Colorize', 'foogallery' ),
296
						'fg-hover-grayscale' => __( 'Greyscale', 'foogallery' ),
297
					)
298
					),
299
					'desc'     => __( 'Choose an color effect that is applied when you hover over a thumbnail.', 'foogallery' ),
300
					'row_data' => array(
301
						'data-foogallery-change-selector'       => 'input:radio',
302
						'data-foogallery-hidden'                => true,
303
						'data-foogallery-show-when-field'       => 'hover_effect_preset',
304
						'data-foogallery-show-when-field-value' => 'fg-custom',
305
						'data-foogallery-preview'               => 'class'
306
					)
307
				);
308
309
				$fields[] = array(
310
					'id'       => 'hover_effect_scale',
311
					'title'    => __( 'Scaling Effect', 'foogallery' ),
312
					'section'  => __( 'Hover Effects', 'foogallery' ),
313
					'default'  => '',
314
					'spacer'   => '<span class="spacer"></span>',
315
					'type'     => 'radio',
316
					'choices'  => apply_filters(
317
						'foogallery_gallery_template_common_thumbnail_fields_hover_effect_scale_choices', array(
318
						''               => __( 'None', 'foogallery' ),
319
						'fg-hover-scale' => __( 'Scaled', 'foogallery' ),
320
					)
321
					),
322
					'desc'     => __( 'Apply a slight scaling effect when hovering over a thumbnail.', 'foogallery' ),
323
					'row_data' => array(
324
						'data-foogallery-change-selector'       => 'input:radio',
325
						'data-foogallery-hidden'                => true,
326
						'data-foogallery-show-when-field'       => 'hover_effect_preset',
327
						'data-foogallery-show-when-field-value' => 'fg-custom',
328
						'data-foogallery-preview'               => 'class'
329
					)
330
				);
331
332
				$fields[] = array(
333
					'id'       => 'hover_effect_caption_visibility',
334
					'title'    => __( 'Caption Visibility', 'foogallery' ),
335
					'section'  => __( 'Hover Effects', 'foogallery' ),
336
					'default'  => 'fg-caption-hover',
337
					'spacer'   => '<span class="spacer"></span>',
338
					'type'     => 'radio',
339
					'choices'  => apply_filters(
340
						'foogallery_gallery_template_common_thumbnail_fields_hover_effect_caption_visibility_choices', array(
341
						''                  => __( 'None', 'foogallery' ),
342
						'fg-caption-hover'  => __( 'On Hover', 'foogallery' ),
343
						'fg-caption-always' => __( 'Always Visible', 'foogallery' ),
344
					)
345
					),
346
					'desc'     => __( 'Choose how the captions will be displayed.', 'foogallery' ),
347
					'row_data' => array(
348
						'data-foogallery-change-selector'       => 'input:radio',
349
						'data-foogallery-hidden'                => true,
350
						'data-foogallery-show-when-field'       => 'hover_effect_preset',
351
						'data-foogallery-show-when-field-value' => 'fg-custom',
352
						'data-foogallery-preview'               => 'class'
353
					)
354
				);
355
356
				$fields[] = array(
357
					'id'       => 'hover_effect_transition',
358
					'title'    => __( 'Transition', 'foogallery' ),
359
					'section'  => __( 'Hover Effects', 'foogallery' ),
360
					'default'  => 'fg-hover-fade',
361
					'type'     => 'select',
362
					'choices'  => apply_filters( 'foogallery_gallery_template_common_thumbnail_fields_hover_effect_transition_choices', array(
363
						'fg-hover-instant'     => __( 'Instant', 'foogallery' ),
364
						'fg-hover-fade'        => __( 'Fade', 'foogallery' ),
365
						'fg-hover-slide-up'    => __( 'Slide Up', 'foogallery' ),
366
						'fg-hover-slide-down'  => __( 'Slide Down', 'foogallery' ),
367
						'fg-hover-slide-left'  => __( 'Slide Left', 'foogallery' ),
368
						'fg-hover-slide-right' => __( 'Slide Right', 'foogallery' ),
369
						'fg-hover-push'        => __( 'Push', 'foogallery' ) )
370
					),
371
					'desc'     => __( 'Choose what effect is used to show the caption when you hover over a thumbnail', 'foogallery' ),
372
					'row_data' => array(
373
						'data-foogallery-change-selector'       => 'select',
374
						'data-foogallery-hidden'                => true,
375
						'data-foogallery-show-when-field'       => 'hover_effect_preset',
376
						'data-foogallery-show-when-field-value' => 'fg-custom',
377
						'data-foogallery-preview'               => 'class'
378
					)
379
				);
380
381
				$fields[] = array(
382
					'id'       => 'hover_effect_icon',
383
					'title'    => __( 'Icon', 'foogallery' ),
384
					'desc'     => __( 'Choose which icon is shown with the caption when you hover over a thumbnail', 'foogallery' ),
385
					'section'  => __( 'Hover Effects', 'foogallery' ),
386
					'type'     => 'htmlicon',
387
					'default'  => 'fg-hover-zoom',
388
					'choices'  => apply_filters( 'foogallery_gallery_template_common_thumbnail_fields_hover_effect_icon_choices', array(
389
						''                     => array( 'label' => __( 'None', 'foogallery' ), 'html' => '<div class="foogallery-setting-caption_icon"></div>' ),
390
						'fg-hover-zoom'        => array( 'label' => __( 'Zoom', 'foogallery' ), 'html' => '<div class="foogallery-setting-caption_icon fg-hover-zoom"></div>' ),
391
						'fg-hover-zoom2'       => array( 'label' => __( 'Zoom 2', 'foogallery' ), 'html' => '<div class="foogallery-setting-caption_icon fg-hover-zoom2"></div>' ),
392
						'fg-hover-zoom3'       => array( 'label' => __( 'Zoom 3', 'foogallery' ), 'html' => '<div class="foogallery-setting-caption_icon fg-hover-zoom3"></div>' ),
393
						'fg-hover-plus'        => array( 'label' => __( 'Plus', 'foogallery' ), 'html' => '<div class="foogallery-setting-caption_icon fg-hover-plus"></div>' ),
394
						'fg-hover-circle-plus' => array( 'label' => __( 'Circle Plus', 'foogallery' ), 'html' => '<div class="foogallery-setting-caption_icon fg-hover-circle-plus"></div>' ),
395
						'fg-hover-eye'         => array( 'label' => __( 'Eye', 'foogallery' ), 'html' => '<div class="foogallery-setting-caption_icon fg-hover-eye"></div>' ),
396
						'fg-hover-external'    => array( 'label' => __( 'External', 'foogallery' ), 'html' => '<div class="foogallery-setting-caption_icon fg-hover-external"></div>' ), )
397
					),
398
					'row_data' => array(
399
						'data-foogallery-change-selector'       => 'input:radio',
400
						'data-foogallery-hidden'                => true,
401
						'data-foogallery-show-when-field'       => 'hover_effect_preset',
402
						'data-foogallery-show-when-field-value' => 'fg-custom',
403
						'data-foogallery-preview'               => 'class'
404
					)
405
				);
406
				//endregion Hover Effects Fields
407
408
				//region Caption Fields
409
				$fields[] = array(
410
					'id'      => 'captions_help',
411
					'title'   => __( 'Captions Help', 'foogallery' ),
412
					'desc'    => __( 'You can change when captions are shown using the "Hover Effects -> Caption Visibility" setting .', 'foogallery' ),
413
					'section' => __( 'Captions', 'foogallery' ),
414
					'type'    => 'help'
415
				);
416
417
				$settings_link = sprintf( '<a target="blank" href="%s">%s</a>', foogallery_admin_settings_url(), __( 'settings', 'foogallery' ) );
418
419
				$fields[] = array(
420
					'id'       => 'caption_title_source',
421
					'title'    => __( 'Title', 'foogallery' ),
422
					'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' ),
423
					'section'  => __( 'Captions', 'foogallery' ),
424
					'type'     => 'radio',
425
					'default'  => '',
426
					'choices'  => array(
427
						'none'    => __( 'None', 'foogallery' ),
428
						''        => sprintf( __( 'Default (as per %s)', 'foogallery' ), $settings_link ),
429
						'title'   => foogallery_get_attachment_field_friendly_name( 'title' ),
430
						'caption' => foogallery_get_attachment_field_friendly_name( 'caption' ),
431
						'alt'     => foogallery_get_attachment_field_friendly_name( 'alt' ),
432
						'desc'    => foogallery_get_attachment_field_friendly_name( 'desc' ),
433
					),
434
					'row_data' => array(
435
						'data-foogallery-change-selector'       => 'input:radio',
436
						'data-foogallery-preview'               => 'shortcode'
437
					)
438
				);
439
440
				$fields[] = array(
441
					'id'       => 'caption_desc',
442
					'title'    => __( 'Description', 'foogallery' ),
443
					'desc'     => __( 'Decide where captions descriptions are pulled from. By default, the general settings are used, but it can be overridden per gallery', 'foogallery' ),
444
					'section'  => __( 'Captions', 'foogallery' ),
445
					'type'     => 'radio',
446
					'default'  => '',
447
					'choices'  => array(
448
						'none'    => __( 'None', 'foogallery' ),
449
						''        => sprintf( __( 'Default (as per %s)', 'foogallery' ), $settings_link ),
450
						'title'   => foogallery_get_attachment_field_friendly_name( 'title' ),
451
						'caption' => foogallery_get_attachment_field_friendly_name( 'caption' ),
452
						'alt'     => foogallery_get_attachment_field_friendly_name( 'alt' ),
453
						'desc'    => foogallery_get_attachment_field_friendly_name( 'desc' ),
454
					),
455
					'row_data' => array(
456
						'data-foogallery-change-selector'       => 'input:radio',
457
						'data-foogallery-preview'               => 'shortcode'
458
					)
459
				);
460
461
				$fields[] = array(
462
					'id'      => 'captions_limit_length',
463
					'title'   => __( 'Limit Caption Length', 'foogallery' ),
464
					'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' ),
465
					'section' => __( 'Captions', 'foogallery' ),
466
					'default' => '',
467
					'type'    => 'radio',
468
					'spacer'  => '<span class="spacer"></span>',
469
					'choices' => array(
470
						'' => __( 'No', 'foogallery' ),
471
						'yes' => __( 'Yes', 'foogallery' ),
472
					),
473
					'row_data'=> array(
474
						'data-foogallery-change-selector' => 'input:radio',
475
						'data-foogallery-preview' => 'shortcode',
476
						'data-foogallery-value-selector'  => 'input:checked',
477
					)
478
				);
479
480
				$fields[] = array(
481
					'id'      => 'caption_title_length',
482
					'title'   => __( 'Max Title Length', 'foogallery' ),
483
					'desc'	  => __( 'A max length of zero will not apply a limit.', 'foogallery '),
484
					'section' => __( 'Captions', 'foogallery' ),
485
					'type'    => 'number',
486
					'class'   => 'small-text',
487
					'default' => 0,
488
					'step'    => '1',
489
					'min'     => '0',
490
					'row_data' => array(
491
						'data-foogallery-change-selector'       => 'input',
492
						'data-foogallery-hidden'                => true,
493
						'data-foogallery-show-when-field'       => 'captions_limit_length',
494
						'data-foogallery-show-when-field-value' => 'yes',
495
						'data-foogallery-preview'               => 'shortcode'
496
					)
497
				);
498
499
				$fields[] = array(
500
					'id'      => 'caption_desc_length',
501
					'title'   => __( 'Max Desc Length', 'foogallery' ),
502
					'desc'	  => __( 'A max length of zero will not apply a limit.', 'foogallery '),
503
					'section' => __( 'Captions', 'foogallery' ),
504
					'type'    => 'number',
505
					'class'   => 'small-text',
506
					'default' => 0,
507
					'step'    => '1',
508
					'min'     => '0',
509
					'row_data' => array(
510
						'data-foogallery-change-selector'       => 'input',
511
						'data-foogallery-hidden'                => true,
512
						'data-foogallery-show-when-field'       => 'captions_limit_length',
513
						'data-foogallery-show-when-field-value' => 'yes',
514
						'data-foogallery-preview'               => 'shortcode'
515
					)
516
				);
517
				//endregion
518
519
			}
520
			return $fields;
521
		}
522
523
		/**
524
		 * Build up the gallery class attribute for the common fields
525
		 *
526
		 * @param $classes array
527
		 * @param $gallery FooGallery
528
		 *
529
		 * @return array
530
		 */
531
		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...
532
			$template_data = foogallery_get_gallery_template( $gallery->gallery_template );
533
534
			//check the template supports common fields
535
			if ( $template_data && array_key_exists( 'common_fields_support', $template_data ) && true === $template_data['common_fields_support'] ) {
536
537
				//add the gallery template core class
538
				$classes[] = 'fg-' . $gallery->gallery_template;
539
540
				//get some default classes from common gallery settings
541
				$classes[] = $gallery->get_setting( 'theme', 'fg-light' );
542
				$classes[] = $gallery->get_setting( 'border_size', 'fg-border-thin' );
543
				$classes[] = $gallery->get_setting( 'rounded_corners', '' );
544
				$classes[] = $gallery->get_setting( 'drop_shadow', 'fg-shadow-outline' );
545
				$classes[] = $gallery->get_setting( 'inner_shadow', '' );
546
				$classes[] = $gallery->get_setting( 'loading_icon', 'fg-loading-default' );
547
				$classes[] = $gallery->get_setting( 'loaded_effect', 'fg-loaded-fade-in' );
548
549
				$caption_preset = $gallery->get_setting( 'hover_effect_preset', 'fg-custom' );
550
551
				$classes[] = $caption_preset;
552
553
				if ( 'fg-custom' === $caption_preset ) {
554
					//only set these caption classes if custom preset is selected
555
					$classes[] = $gallery->get_setting( 'hover_effect_color', '' );
556
					$classes[] = $gallery->get_setting( 'hover_effect_scale', '' );
557
					$classes[] = $gallery->get_setting( 'hover_effect_caption_visibility', 'fg-caption-hover' );
558
					$classes[] = $gallery->get_setting( 'hover_effect_transition', 'fg-hover-fade' );
559
					$classes[] = $gallery->get_setting( 'hover_effect_icon', 'fg-hover-zoom' );
560
				} else if ( strpos( $caption_preset, 'fg-preset' ) !== false ) {
561
					//set a preset size
562
					$classes[] = $gallery->get_setting( 'hover_effect_preset_size', 'fg-preset-small' );
563
				}
564
			}
565
566
			return $classes;
567
		}
568
569
		/**
570
		 * Add the required data options for captions
571
		 *
572
		 * @param $options
573
		 * @param $gallery    FooGallery
574
		 *
575
		 * @param $attributes array
576
		 *
577
		 * @return array
578
		 */
579
		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...
580
			$template_data = foogallery_get_gallery_template( $gallery->gallery_template );
581
582
			//check the template supports common fields
583
			if ( $template_data && array_key_exists( 'common_fields_support', $template_data ) && true === $template_data['common_fields_support'] ) {
584
585
				$caption_title = foogallery_gallery_template_setting( 'caption_title_source', '' );
586
				$caption_desc  = foogallery_gallery_template_setting( 'caption_desc_source', '' );
587
588
				$options['item']['showCaptionTitle']       = $caption_title != 'none';
589
				$options['item']['showCaptionDescription'] = $caption_desc != 'none';
590
591
				$captions_limit_length = foogallery_gallery_template_setting( 'captions_limit_length', '' );
592
593
				if ( 'yes' === $captions_limit_length ) {
594
					$caption_title_length                    = foogallery_gallery_template_setting( 'caption_title_length', '0' );
595
					$caption_desc_length                     = foogallery_gallery_template_setting( 'caption_desc_length', '0' );
596
					$options['item']['maxCaptionLength']     = intval( $caption_title_length );
597
					$options['item']['maxDescriptionLength'] = intval( $caption_desc_length );
598
				}
599
			}
600
			return $options;
601
		}
602
603
		/**
604
		 * Build up a arguments used in the preview of the gallery
605
		 * @param $args
606
		 * @param $post_data
607
		 * @param $template
608
		 *
609
		 * @return mixed
610
		 */
611
		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...
612
			$args['caption_title_source'] = $post_data[FOOGALLERY_META_SETTINGS][$template . '_caption_title_source'];
613
			$args['caption_desc_source'] = $post_data[FOOGALLERY_META_SETTINGS][$template . '_caption_desc_source'];
614
			$args['captions_limit_length'] = $post_data[FOOGALLERY_META_SETTINGS][$template . '_captions_limit_length'];
615
			$args['caption_title_length'] = $post_data[FOOGALLERY_META_SETTINGS][$template . '_caption_title_length'];
616
			$args['caption_desc_length'] = $post_data[FOOGALLERY_META_SETTINGS][$template . '_caption_desc_length'];
617
			return $args;
618
		}
619
620
		/**
621
		 * Build up the gallery data attributes for the common fields
622
		 *
623
		 * @param $attributes array
624
		 * @param $gallery FooGallery
625
		 *
626
		 * @return array
627
		 */
628
		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...
629
			$template_data = foogallery_get_gallery_template( $gallery->gallery_template );
630
631
			//check the template supports common fields
632
			if ( $template_data && array_key_exists( 'common_fields_support', $template_data ) && true === $template_data['common_fields_support'] ) {
633
				$attributes['data-fg-common-fields'] = true;
634
			}
635
636
			return $attributes;
637
		}
638
	}
639
}