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 — feature/gallery-template-clien... ( 87baaf...c48b9b )
by Brad
02:46
created

alter_gallery_template_field()   C

Complexity

Conditions 7
Paths 9

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

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