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... ( 3fa32a...1ace21 )
by Brad
02:32
created

add_common_thumbnail_fields()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 41
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 28
nc 12
nop 2
dl 0
loc 41
rs 6.7272
c 0
b 0
f 0
1
<?php
2
3
if ( !class_exists( 'FooGallery_Polaroid_Gallery_Template' ) ) {
4
5
	define('FOOGALLERY_POLAROID_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ ));
6
7
	class FooGallery_Polaroid_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...
8
		/**
9
		 * Wire up everything we need to run the extension
10
		 */
11
		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...
12
			add_filter( 'foogallery_gallery_templates', array( $this, 'add_template' ) );
13
			add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) );
14
15
			add_filter( 'foogallery_template_load_css-polaroid_new', '__return_false' );
16
			add_filter( 'foogallery_template_load_js-polaroid_new', '__return_false' );
17
18
			add_filter( 'foogallery_located_template-polaroid_new', array( $this, 'enqueue_dependencies' ) );
19
20
			//add extra fields to the templates
21
			add_filter( 'foogallery_override_gallery_template_fields-polaroid_new', array( $this, 'add_common_thumbnail_fields' ), 10, 2 );
22
23
			//add the data options needed for polaroid
24
			add_filter( 'foogallery_build_container_data_options-polaroid_new', array( $this, 'add_data_options' ), 10, 3 );
25
26
			//override specific settings when saving the gallery
27
			add_filter( 'foogallery_save_gallery_settings-polaroid_new', array( $this, 'override_settings'), 10, 3 );
28
29
			//build up any preview arguments
30
			add_filter( 'foogallery_preview_arguments-polaroid_new', array( $this, 'preview_arguments' ), 10, 2 );
31
32
			//build up the thumb dimensions from some arguments
33
			add_filter( 'foogallery_calculate_thumbnail_dimensions-polaroid_new', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 );
34
		}
35
36
		/**
37
		 * Register myself so that all associated JS and CSS files can be found and automatically included
38
		 * @param $extensions
39
		 *
40
		 * @return array
41
		 */
42
		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...
43
			$extensions[] = __FILE__;
44
			return $extensions;
45
		}
46
47
		/**
48
		 * Add our gallery template to the list of templates available for every gallery
49
		 * @param $gallery_templates
50
		 *
51
		 * @return array
52
		 */
53
		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...
54
			$gallery_templates[] = array(
55
                'slug'        => 'polaroid_new',
56
                'name'        => __( 'Polaroid', 'foogallery' ),
57
				'preview_support' => true,
58
				'common_fields_support' => true,
59
                'lazyload_support' => true,
60
				'paging_support' => true,
61
				'mandatory_classes' => 'fg-simple_portfolio fg-preset fg-polaroid',
62
				'thumbnail_dimensions' => true,
63
                'fields'	  => array(
64
                    array(
65
                        'id'      => 'thumbnail_dimensions',
66
                        'title'   => __( 'Thumbnail Size', 'foogallery' ),
67
                        'desc'    => __( 'Choose the size of your thumbnails.', 'foogallery' ),
68
                        'section' => __( 'General', 'foogallery' ),
69
                        'type'    => 'thumb_size',
70
                        'default' => array(
71
                            'width' => 250,
72
                            'height' => 200,
73
                            'crop' => true,
74
                        ),
75
						'row_data'=> array(
76
							'data-foogallery-change-selector' => 'input',
77
							'data-foogallery-preview' => 'shortcode'
78
						)
79
                    ),
80
                    array(
81
                        'id'      => 'thumbnail_link',
82
                        'title'   => __( 'Thumbnail Link', 'foogallery' ),
83
                        'section' => __( 'General', 'foogallery' ),
84
                        'default' => 'image',
85
                        'type'    => 'thumb_link',
86
                        'desc'	  => __( 'You can choose to link each thumbnail to the full size image, or to the image\'s attachment page, or you can choose to not link to anything.', 'foogallery' )
87
                    ),
88
                    array(
89
                        'id'      => 'lightbox',
90
                        'title'   => __( 'Lightbox', 'foogallery' ),
91
                        'desc'    => __( 'Choose which lightbox you want to display images with. The lightbox will only work if you set the thumbnail link to "Full Size Image".', 'foogallery' ),
92
                        'section' => __( 'General', 'foogallery' ),
93
                        'type'    => 'lightbox',
94
                    ),
95
                    array(
96
                        'id'      => 'gutter',
97
                        'title'   => __( 'Gutter', 'foogallery' ),
98
                        'desc'    => __( 'The spacing between each thumbnail in the gallery.', 'foogallery' ),
99
						'section' => __( 'General', 'foogallery' ),
100
                        'type'    => 'number',
101
                        'class'   => 'small-text',
102
                        'default' => 40,
103
                        'step'    => '1',
104
                        'min'     => '0',
105
						'row_data'=> array(
106
							'data-foogallery-change-selector' => 'input',
107
							'data-foogallery-value-selector' => 'input',
108
							'data-foogallery-preview' => 'data',
109
						)
110
                    ),
111
                    array(
112
                        'id'      => 'caption_position',
113
                        'title' => __('Caption Position', 'foogallery'),
114
                        'desc' => __('Where the captions are displayed in relation to the thumbnail.', 'foogallery'),
115
						'section' => __( 'Captions', 'foogallery' ),
116
                        'default' => '',
117
                        'type'    => 'radio',
118
                        'spacer'  => '<span class="spacer"></span>',
119
                        'choices' => array(
120
                            '' => __( 'Below', 'foogallery' ),
121
                            'fg-captions-top' => __( 'Above', 'foogallery' )
122
                        ),
123
						'row_data'=> array(
124
							'data-foogallery-change-selector' => 'input:radio',
125
							'data-foogallery-value-selector' => 'input:checked',
126
							'data-foogallery-preview' => 'class'
127
						)
128
                    ),
129
                ),
130
			);
131
132
			return $gallery_templates;
133
		}
134
135
		/**
136
		 * Enqueue scripts that the polaroid template relies on
137
		 */
138
		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...
139
			//enqueue core files
140
			foogallery_enqueue_core_gallery_template_style();
141
			foogallery_enqueue_core_gallery_template_script();
142
		}
143
144
		/**
145
		 * Add thumbnail fields to the gallery template
146
		 *
147
		 * @uses "foogallery_override_gallery_template_fields"
148
		 * @param $fields
149
		 * @param $template
150
		 *
151
		 * @return array
152
		 */
153
		function add_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...
154
			$fields_to_remove = array();
155
156
			//update specific fields
157
			foreach ($fields as $key => &$field) {
158
				if ( 'hover_effect_preset' === $field['id'] ) {
159
					$field['default'] = 'fg-custom';
160
					$field['choices'] = array(
161
						'fg-custom'  => __( 'Polaroid', 'foogallery' )
162
					);
163
					$field['row_data'] = array(
164
						'data-foogallery-hidden' => true,
165
						'data-foogallery-change-selector' => 'input:radio',
166
						'data-foogallery-value-selector' => 'input:checked',
167
						'data-foogallery-preview' => 'class'
168
					);
169
				} else if ( 'hover_effect_caption_visibility' === $field['id'] ) {
170
					$field['default'] = 'fg-caption-always';
171
					$field['choices'] = array(
172
						'fg-caption-always' => __( 'Always Visible', 'foogallery' ),
173
					);
174
					$field['row_data'] = array(
175
						'data-foogallery-change-selector' => 'input:radio',
176
						'data-foogallery-hidden' => true,
177
						'data-foogallery-preview' => 'class'
178
					);
179
				} else if ( 'hover_effect_help' == $field['id'] ) {
180
					$field['row_data'] = array(
181
						'data-foogallery-hidden' => true
182
					);
183
				} else if ( 'hover_effect_scale' == $field['id'] ) {
184
					$fields_to_remove[] = $key;
185
				}
186
			}
187
188
			foreach ($fields_to_remove as $key) {
189
				unset($fields[$key]);
190
			}
191
192
			return $fields;
193
		}
194
195
		/**
196
		 * Add the required data options if needed
197
		 *
198
		 * @param $options
199
		 * @param $gallery    FooGallery
200
		 *
201
		 * @param $attributes array
202
		 *
203
		 * @return array
204
		 */
205
		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...
206
			$gutter = foogallery_gallery_template_setting( 'gutter', 40 );
207
			$options['template']['gutter'] = intval($gutter);
208
			return $options;
209
		}
210
211
		/**
212
		 * Override specific settings so that the gallery template will always work
213
		 *
214
		 * @param $settings
215
		 * @param $post_id
216
		 * @param $form_data
217
		 *
218
		 * @return mixed
219
		 */
220
		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...
221
			$settings['polaroid_new_hover_effect_preset'] = 'fg-custom';
222
			$settings['polaroid_new_hover_effect_caption_visibility'] = 'fg-caption-always';
223
224
			return $settings;
225
		}
226
227
		/**
228
		 * Build up a arguments used in the preview of the gallery
229
		 * @param $args
230
		 * @param $post_data
231
		 *
232
		 * @return mixed
233
		 */
234
		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...
235
			$args['thumbnail_width'] = $post_data[FOOGALLERY_META_SETTINGS]['polaroid_new_thumbnail_dimensions']['width'];
236
			$args['thumbnail_height'] = $post_data[FOOGALLERY_META_SETTINGS]['polaroid_new_thumbnail_dimensions']['height'];
237
			$args['thumbnail_crop'] = isset( $post_data[FOOGALLERY_META_SETTINGS]['polaroid_new_thumbnail_dimensions']['crop'] ) ? '1' : '0';
238
239
			return $args;
240
		}
241
242
		/**
243
		 * Builds thumb dimensions from arguments
244
		 *
245
		 * @param array $dimensions
246
		 * @param array $arguments
247
		 *
248
		 * @return mixed
249
		 */
250
		function build_thumbnail_dimensions_from_arguments( $dimensions, $arguments ) {
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...
251
			return array(
252
				'height' => intval( $arguments['thumbnail_height'] ),
253
				'width'  => intval( $arguments['thumbnail_width'] ),
254
				'crop'   => $arguments['thumbnail_crop'] === '1'
255
			);
256
		}
257
	}
258
}