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 — master ( 9c0c8a...f2b063 )
by Brad
05:17 queued 02:45
created

get_thumbnail_dimensions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
if ( !class_exists( 'FooGallery_Slider_Gallery_Template' ) ) {
4
5
	class FooGallery_Slider_Gallery_Template {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
		/**
7
		 * Wire up everything we need to run the extension
8
		 */
9
		function __construct() {
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...
10
			add_filter( 'foogallery_gallery_templates', array( $this, 'add_template' ), 101 );
11
12
			add_filter( 'foogallery_override_gallery_template_fields-slider', array( $this, 'add_additional_setting_fields' ), 10, 2 );
13
14
			add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) );
15
16
			add_filter( 'foogallery_located_template-slider', array( $this, 'enqueue_dependencies' ) );
17
18
			//change fields for the template
19
			add_filter( 'foogallery_override_gallery_template_fields-slider', array( $this, 'change_common_thumbnail_fields' ), 10, 2 );
20
21
			//add the data options needed for polaroid
22
			add_filter( 'foogallery_build_container_data_options-slider', array( $this, 'add_data_options' ), 10, 3 );
23
24
			//override specific settings when saving the gallery
25
			add_filter( 'foogallery_save_gallery_settings-slider', array( $this, 'override_settings'), 10, 3 );
26
27
			//build up any preview arguments
28
			add_filter( 'foogallery_preview_arguments-slider', array( $this, 'preview_arguments' ), 10, 2 );
29
30
			//build up the thumb dimensions from some arguments
31
			add_filter( 'foogallery_calculate_thumbnail_dimensions-slider', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 );
32
33
			//build up the thumb dimensions on save
34
			add_filter( 'foogallery_template_thumbnail_dimensions-slider', array( $this, 'get_thumbnail_dimensions' ), 10, 2 );
35
36
			//build up the arguments needed for rendering this template
37
			add_filter( 'foogallery_gallery_template_arguments-slider', array( $this, 'build_gallery_template_arguments' ) );
38
39
			add_filter( 'foogallery_build_class_attribute', array( $this, 'remove_classes' ), 99, 2 );
40
		}
41
42
		/**
43
		 * Add the video gallery template to the list of templates available
44
		 * @param $gallery_templates
45
		 *
46
		 * @return array
47
		 */
48
		function add_template( $gallery_templates ) {
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...
49
50
			$gallery_templates[] = array(
51
				'slug'        => 'slider',
52
				'name'        => __( 'Slider PRO', 'foogallery'),
53
				'preview_support' => true,
54
				'common_fields_support' => true,
55
				'lazyload_support' => true,
56
				'paging_support' => false,
57
				'thumbnail_dimensions' => false,
58
				'filtering_support' => true,
59
				'mandatory_classes' => 'fg-slider',
60
				'embed_support' => true,
61
				'fields'	  => array(
62
					array(
63
						'id'      => 'layout',
64
						'title'   => __('Layout', 'foogallery'),
65
						'desc'    => __( 'You can choose either a horizontal or vertical layout for your responsive video gallery.', 'foogallery' ),
66
						'section' => __( 'General', 'foogallery' ),
67
						'type'    => 'icon',
68
						'default' => '',
69
						'choices' => array(
70
							'' => array( 'label' => __( 'Vertical' , 'foogallery' ), 'img' => plugin_dir_url( __FILE__ ) . 'assets/video-layout-vertical.png' ),
71
							'fgs-horizontal' => array( 'label' => __( 'Horizontal' , 'foogallery' ), 'img' => plugin_dir_url( __FILE__ ) . 'assets/video-layout-horizontal.png' )
72
						),
73
						'row_data' => array(
74
							'data-foogallery-change-selector' => 'input:radio',
75
							'data-foogallery-value-selector'  => 'input:checked',
76
							'data-foogallery-preview' => 'class',
77
						)
78
					),
79
					array(
80
						'id'      => 'viewport',
81
						'title'   => __('Use Viewport Width', 'foogallery'),
82
						'desc'    => __('Use the viewport width instead of the parent element width.', 'foogallery'),
83
						'section' => __( 'General', 'foogallery' ),
84
						'default' => '',
85
						'type'    => 'radio',
86
						'spacer'  => '<span class="spacer"></span>',
87
						'choices' => array(
88
							'' => __( 'No', 'foogallery' ),
89
							'yes' => __( 'Yes', 'foogallery' )
90
						),
91
						'row_data' => array(
92
							'data-foogallery-change-selector' => 'input:radio',
93
							'data-foogallery-value-selector'  => 'input:checked',
94
							'data-foogallery-preview' => 'shortcode',
95
						)
96
					),
97
				)
98
			);
99
100
			return $gallery_templates;
101
		}
102
103
		/**
104
		 * Add additional fields to the settings
105
		 * @param $fields
106
		 * @param $template
107
		 *
108
		 * @return array
109
		 */
110
		function add_additional_setting_fields( $fields, $template ) {
0 ignored issues
show
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...
111
112
			$fields[] =	array(
113
				'id'      => 'highlight',
114
				'title'   => __('Highlight', 'foogallery'),
115
				'section' => __( 'Appearance', 'foogallery' ),
116
				'desc'    => __('The color that is used to highlight the selected video.', 'foogallery'),
117
				'default' => 'fgs-purple',
118
				'type'    => 'radio',
119
				'spacer'  => '<span class="spacer"></span>',
120
				'choices' => array(
121
					'fgs-purple' => __( 'Purple', 'foogallery' ),
122
					'fgs-blue' => __( 'Blue', 'foogallery' ),
123
					'fgs-green' => __( 'Green', 'foogallery' ),
124
					'fgs-orange' => __( 'Orange', 'foogallery' ),
125
					'fgs-red' => __( 'Red', 'foogallery' ),
126
					'fg-custom' => __( 'Custom', 'foogallery' )
127
				),
128
				'row_data' => array(
129
					'data-foogallery-change-selector' => 'input:radio',
130
					'data-foogallery-value-selector'  => 'input:checked',
131
					'data-foogallery-preview' => 'class',
132
				)
133
			);
134
135
			$fields[] = array(
136
				'id'      => 'thumbnail_captions',
137
				'title'   => __('Thumbnail Captions', 'foogallery'),
138
				'desc'    => __('You can choose to hide the captions for the small thumbnails in the slider.', 'foogallery'),
139
				'section' => __( 'Captions', 'foogallery' ),
140
				'default' => '',
141
				'type'    => 'radio',
142
				'spacer'  => '<span class="spacer"></span>',
143
				'choices' => array(
144
					'' => __( 'Show Captions', 'foogallery' ),
145
					'fgs-no-captions' => __( 'Hide Captions', 'foogallery' )
146
				),
147
				'row_data' => array(
148
					'data-foogallery-change-selector' => 'input:radio',
149
					'data-foogallery-value-selector'  => 'input:checked',
150
					'data-foogallery-preview' => 'class',
151
				)
152
			);
153
154
			return $fields;
155
		}
156
157
		function unused_fields_for_future_version() {
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...
158
			$fields[] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$fields was never initialized. Although not strictly required by PHP, it is generally a good practice to add $fields = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
159
				'id'      => 'theme_custom_bgcolor',
160
				'title'   => __('Background Color', 'foogallery'),
161
				'section' => __( 'Appearance', 'foogallery' ),
162
				'type'    => 'colorpicker',
163
				'default' => '#000000',
164
				'opacity' => true,
165
				'row_data' => array(
166
					'data-foogallery-hidden'          		   => true,
167
					'data-foogallery-show-when-field'          => 'theme',
168
					'data-foogallery-show-when-field-value'    => 'fg-custom',
169
				)
170
			);
171
			$fields[] = array(
172
				'id'      => 'theme_custom_textcolor',
173
				'title'   => __('Text Color', 'foogallery'),
174
				'section' => __( 'Appearance', 'foogallery' ),
175
				'type'    => 'colorpicker',
176
				'default' => '#ffffff',
177
				'opacity' => true,
178
				'row_data' => array(
179
					'data-foogallery-hidden'          		   => true,
180
					'data-foogallery-show-when-field'          => 'theme',
181
					'data-foogallery-show-when-field-value'    => 'fg-custom',
182
				)
183
			);
184
			$fields[] = array(
185
				'id'      => 'theme_custom_hovercolor',
186
				'title'   => __('Hover BG Color', 'foogallery'),
187
				'section' => __( 'Appearance', 'foogallery' ),
188
				'type'    => 'colorpicker',
189
				'default' => '#222222',
190
				'opacity' => true,
191
				'row_data' => array(
192
					'data-foogallery-hidden'          		   => true,
193
					'data-foogallery-show-when-field'          => 'theme',
194
					'data-foogallery-show-when-field-value'    => 'fg-custom',
195
				)
196
			);
197
			$fields[] =	array(
198
				'id'      => 'theme_custom_dividercolor',
199
				'title'   => __('Divider Color', 'foogallery'),
200
				'section' => __( 'Appearance', 'foogallery' ),
201
				'type'    => 'colorpicker',
202
				'default' => '#2e2e2e',
203
				'opacity' => true,
204
				'row_data' => array(
205
					'data-foogallery-hidden'          		   => true,
206
					'data-foogallery-show-when-field'          => 'theme',
207
					'data-foogallery-show-when-field-value'    => 'fg-custom',
208
				)
209
			);
210
211
			$fields[] =	array(
212
				'id'      => 'highlight_custom_bgcolor',
213
				'title'   => __('Highlight BG Color', 'foogallery'),
214
				'section' => __( 'Appearance', 'foogallery' ),
215
				'type'    => 'colorpicker',
216
				'default' => '#7816d6',
217
				'opacity' => true,
218
				'row_data' => array(
219
					'data-foogallery-hidden'          		   => true,
220
					'data-foogallery-show-when-field'          => 'highlight',
221
					'data-foogallery-show-when-field-value'    => 'fg-custom',
222
				)
223
			);
224
			$fields[] =	array(
225
				'id'      => 'highlight_custom_textcolor',
226
				'title'   => __('Highlight Text Color', 'foogallery'),
227
				'section' => __( 'Appearance', 'foogallery' ),
228
				'type'    => 'colorpicker',
229
				'default' => 'rgba(255, 255, 255, 1)',
230
				'opacity' => true,
231
				'row_data' => array(
232
					'data-foogallery-hidden'          		   => true,
233
					'data-foogallery-show-when-field'          => 'highlight',
234
					'data-foogallery-show-when-field-value'    => 'fg-custom',
235
				)
236
			);
237
238
		}
239
240
		/**
241
		 * Register myself so that all associated JS and CSS files can be found and automatically included
242
		 * @param $extensions
243
		 *
244
		 * @return array
245
		 */
246
		function register_myself( $extensions ) {
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...
247
			$extensions[] = __FILE__;
248
			return $extensions;
249
		}
250
251
		/**
252
		 * Enqueue scripts that the template relies on
253
		 */
254
		function enqueue_dependencies() {
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...
255
			//enqueue core files
256
			foogallery_enqueue_core_gallery_template_style();
257
			foogallery_enqueue_core_gallery_template_script();
258
		}
259
260
		/**
261
		 * Remove some common fields
262
		 *
263
		 * @uses "foogallery_override_gallery_template_fields"
264
		 * @param $fields
265
		 * @param $template
266
		 *
267
		 * @return array
268
		 */
269
		function change_common_thumbnail_fields( $fields, $template ) {
0 ignored issues
show
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...
270
271
			$fields_to_remove = array();
272
			$fields_to_remove[] = 'border_size';
273
			$fields_to_remove[] = 'rounded_corners';
274
			$fields_to_remove[] = 'drop_shadow';
275
			$fields_to_remove[] = 'loaded_effect';
276
 			$fields_to_remove[] = 'hover_effect_help';
277
			$fields_to_remove[] = 'theme_custom_help';
278
			$fields_to_remove[] = 'hover_effect_preset_size';
279
			$fields_to_remove[] = 'hover_effect_caption_visibility';
280
			$fields_to_remove[] = 'captions_help';
281
			$fields_to_remove[] = 'video_size_help';
282
			$fields_to_remove[] = 'video_size';
283
284
			$indexes_to_remove = array();
285
286
			foreach ($fields as $key => &$field) {
287
				if ( 'hover_effect_preset' === $field['id'] ) {
288
					$field['default'] = 'fg-custom';
289
					$field['choices'] = array(
290
						'fg-custom'  => __( 'Slider', 'foogallery' )
291
					);
292
					$field['row_data'] = array(
293
						'data-foogallery-hidden' => true,
294
						'data-foogallery-change-selector' => 'input:radio',
295
						'data-foogallery-value-selector' => 'input:checked',
296
						'data-foogallery-preview' => 'class'
297
					);
298
				} else if ( 'video_autoplay' === $field['id'] ) {
299
					$field['title'] = __( 'Autoplay', 'foogallery' );
300
					$field['desc'] = __( 'Try to autoplay the video when selected. This will only work with videos hosted on Youtube or Vimeo.', 'foogallery' );
301
				}
302
303
				if ( in_array( $field['id'], $fields_to_remove ) ) {
304
					$indexes_to_remove[] = $key;
305
				}
306
			}
307
308
			foreach ($indexes_to_remove as $index) {
309
				unset( $fields[$index] );
310
			}
311
312
			return $fields;
313
		}
314
315
		/**
316
		 * Add the required data options if needed
317
		 *
318
		 * @param $options
319
		 * @param $gallery    FooGallery
320
		 *
321
		 * @param $attributes array
322
		 *
323
		 * @return array
324
		 */
325
		function add_data_options($options, $gallery, $attributes) {
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 $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...
326
			$viewport = foogallery_gallery_template_setting( 'viewport', '' );
327
			if ( 'yes' === $viewport ) {
328
				$options['template']['viewport'] = true;
329
			}
330
331
			$video_autoplay = foogallery_gallery_template_setting( 'video_autoplay', 'yes' );
332
			if ( 'yes' === $video_autoplay ) {
333
				$options['template']['autoPlay'] = true;
334
			}
335
336
			return $options;
337
		}
338
339
		/**
340
		 * Override specific settings so that the gallery template will always work
341
		 *
342
		 * @param $settings
343
		 * @param $post_id
344
		 * @param $form_data
345
		 *
346
		 * @return mixed
347
		 */
348
		function override_settings($settings, $post_id, $form_data) {
0 ignored issues
show
Unused Code introduced by
The parameter $post_id 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 $form_data 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...
349
			$settings['slider_hover_effect_preset'] = 'fg-custom';
350
			return $settings;
351
		}
352
353
		/**
354
		 * Build up a arguments used in the preview of the gallery
355
		 * @param $args
356
		 * @param $post_data
357
		 *
358
		 * @return mixed
359
		 */
360
		function preview_arguments( $args, $post_data ) {
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...
361
			$args['thumbnail_dimensions'] = array(
362
				'width' => 150,
363
				'height' => 150,
364
				'crop' => true
365
			);
366
			$args['layout'] = $post_data[FOOGALLERY_META_SETTINGS]['slider_layout'];
367
			$args['viewport'] = $post_data[FOOGALLERY_META_SETTINGS]['slider_viewport'];
368
			return $args;
369
		}
370
371
		/**
372
		 * Builds thumb dimensions from arguments
373
		 *
374
		 * @param array $dimensions
375
		 * @param array $arguments
376
		 *
377
		 * @return mixed
378
		 */
379
		function build_thumbnail_dimensions_from_arguments( $dimensions, $arguments ) {
0 ignored issues
show
Unused Code introduced by
The parameter $dimensions 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 $arguments 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...
380
			return array(
381
				'width' => 150,
382
				'height' => 150,
383
				'crop' => true
384
			);
385
		}
386
387
		/**
388
		 * Get the thumb dimensions arguments saved for the gallery for this gallery template
389
		 *
390
		 * @param array $dimensions
391
		 * @param FooGallery $foogallery
392
		 *
393
		 * @return mixed
394
		 */
395
		function get_thumbnail_dimensions( $dimensions, $foogallery ) {
0 ignored issues
show
Unused Code introduced by
The parameter $dimensions 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 $foogallery 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...
396
			return array(
397
				'width' => 150,
398
				'height' => 150,
399
				'crop' => true
400
			);
401
		}
402
403
		/**
404
		 * Build up the arguments needed for rendering this gallery template
405
		 *
406
		 * @param $args
407
		 * @return array
408
		 */
409
		function build_gallery_template_arguments( $args ) {
0 ignored issues
show
Unused Code introduced by
The parameter $args 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...
410
			$args = array(
411
				'width' => 150,
412
				'height' => 150,
413
				'crop' => true
414
			);
415
416
			return $args;
417
		}
418
419
		/**
420
		 * Remove certain classes from the container only if the slider gallery template is in use
421
		 *
422
		 * @param $classes
423
		 * @param $gallery
424
		 *
425
		 * @return array
426
		 */
427
		function remove_classes( $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...
428
			if ( 'slider' === $gallery->gallery_template ) {
429
430
				if ( ( $key = array_search( 'slider', $classes ) ) !== false ) {
431
					unset( $classes[$key] );
432
				}
433
				if ( ( $key = array_search( 'fg-border-thin', $classes ) ) !== false ) {
434
					unset( $classes[$key] );
435
				}
436
				if ( ( $key = array_search( 'fg-loaded-fade-in', $classes ) ) !== false ) {
437
					unset( $classes[$key] );
438
				}
439
				if ( ( $key = array_search( 'video-icon-default', $classes ) ) !== false ) {
440
					unset( $classes[$key] );
441
				}
442
				if ( ( $key = array_search( 'fgs-no-captions', $classes ) ) !== false ) {
443
					//only remove the caption hover class if no captions is enabled
444
					if ( ( $key = array_search( 'fg-caption-hover', $classes ) ) !== false ) {
445
						unset( $classes[$key] );
446
					}
447
				}
448
			}
449
450
			return $classes;
451
		}
452
	}
453
}