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... ( 275fef...a33793 )
by Brad
02:29
created

add_template()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 80
Code Lines 66

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 66
nc 1
nop 1
dl 0
loc 80
rs 8.8387
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
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
                'fields'	  => array(
63
                    array(
64
                        'id'      => 'thumbnail_dimensions',
65
                        'title'   => __( 'Thumbnail Size', 'foogallery' ),
66
                        'desc'    => __( 'Choose the size of your thumbnails.', 'foogallery' ),
67
                        'section' => __( 'General', 'foogallery' ),
68
                        'type'    => 'thumb_size',
69
                        'default' => array(
70
                            'width' => 250,
71
                            'height' => 200,
72
                            'crop' => true,
73
                        ),
74
						'row_data'=> array(
75
							'data-foogallery-change-selector' => 'input',
76
							'data-foogallery-preview' => 'shortcode'
77
						)
78
                    ),
79
                    array(
80
                        'id'      => 'thumbnail_link',
81
                        'title'   => __( 'Thumbnail Link', 'foogallery' ),
82
                        'section' => __( 'General', 'foogallery' ),
83
                        'default' => 'image',
84
                        'type'    => 'thumb_link',
85
                        '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' )
86
                    ),
87
                    array(
88
                        'id'      => 'lightbox',
89
                        'title'   => __( 'Lightbox', 'foogallery' ),
90
                        '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' ),
91
                        'section' => __( 'General', 'foogallery' ),
92
                        'type'    => 'lightbox',
93
                    ),
94
                    array(
95
                        'id'      => 'gutter',
96
                        'title'   => __( 'Gutter', 'foogallery' ),
97
                        'desc'    => __( 'The spacing between each thumbnail in the gallery.', 'foogallery' ),
98
						'section' => __( 'General', 'foogallery' ),
99
                        'type'    => 'number',
100
                        'class'   => 'small-text',
101
                        'default' => 40,
102
                        'step'    => '1',
103
                        'min'     => '0',
104
						'row_data'=> array(
105
							'data-foogallery-change-selector' => 'input',
106
							'data-foogallery-value-selector' => 'input',
107
							'data-foogallery-preview' => 'data',
108
						)
109
                    ),
110
                    array(
111
                        'id'      => 'caption_position',
112
                        'title' => __('Caption Position', 'foogallery'),
113
                        'desc' => __('Where the captions are displayed in relation to the thumbnail.', 'foogallery'),
114
						'section' => __( 'Captions', 'foogallery' ),
115
                        'default' => '',
116
                        'type'    => 'radio',
117
                        'spacer'  => '<span class="spacer"></span>',
118
                        'choices' => array(
119
                            '' => __( 'Below', 'foogallery' ),
120
                            'fg-captions-top' => __( 'Above', 'foogallery' )
121
                        ),
122
						'row_data'=> array(
123
							'data-foogallery-change-selector' => 'input:radio',
124
							'data-foogallery-value-selector' => 'input:checked',
125
							'data-foogallery-preview' => 'class'
126
						)
127
                    ),
128
                ),
129
			);
130
131
			return $gallery_templates;
132
		}
133
134
		/**
135
		 * Enqueue scripts that the polaroid template relies on
136
		 */
137
		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...
138
			//enqueue core files
139
			foogallery_enqueue_core_gallery_template_style();
140
			foogallery_enqueue_core_gallery_template_script();
141
		}
142
143
		/**
144
		 * Add thumbnail fields to the gallery template
145
		 *
146
		 * @uses "foogallery_override_gallery_template_fields"
147
		 * @param $fields
148
		 * @param $template
149
		 *
150
		 * @return array
151
		 */
152
		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...
153
			//update specific fields
154
			foreach ($fields as &$field) {
155
				if ( 'hover_effect_preset' === $field['id'] ) {
156
					$field['default'] = 'fg-custom';
157
					$field['choices'] = array(
158
						'fg-custom'  => __( 'Polaroid', 'foogallery' )
159
					);
160
					$field['row_data'] = array(
161
						'data-foogallery-hidden' => true,
162
						'data-foogallery-change-selector' => 'input:radio',
163
						'data-foogallery-value-selector' => 'input:checked',
164
						'data-foogallery-preview' => 'class'
165
					);
166
				} else if ( 'hover_effect_caption_visibility' === $field['id'] ) {
167
					$field['default'] = 'fg-caption-always';
168
					$field['choices'] = array(
169
						'fg-caption-always' => __( 'Always Visible', 'foogallery' ),
170
					);
171
					$field['row_data'] = array(
172
						'data-foogallery-change-selector' => 'input:radio',
173
						'data-foogallery-hidden' => true,
174
						'data-foogallery-preview' => 'class'
175
					);
176
				} else if ( 'hover_effect_help' == $field['id'] ) {
177
					$field['row_data'] = array(
178
						'data-foogallery-hidden' => true
179
					);
180
				}
181
			}
182
183
			return $fields;
184
		}
185
186
		/**
187
		 * Add the required data options if needed
188
		 *
189
		 * @param $options
190
		 * @param $gallery    FooGallery
191
		 *
192
		 * @param $attributes array
193
		 *
194
		 * @return array
195
		 */
196
		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...
197
			$gutter = foogallery_gallery_template_setting( 'gutter', 40 );
198
			$options['template']['gutter'] = intval($gutter);
199
			return $options;
200
		}
201
202
		/**
203
		 * Override specific settings so that the gallery template will always work
204
		 *
205
		 * @param $settings
206
		 * @param $post_id
207
		 * @param $form_data
208
		 *
209
		 * @return mixed
210
		 */
211
		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...
212
			$settings['polaroid_new_hover_effect_preset'] = 'fg-custom';
213
			$settings['polaroid_new_hover_effect_caption_visibility'] = 'fg-caption-always';
214
215
			return $settings;
216
		}
217
218
		/**
219
		 * Build up a arguments used in the preview of the gallery
220
		 * @param $args
221
		 * @param $post_data
222
		 *
223
		 * @return mixed
224
		 */
225
		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...
226
			$args['thumbnail_width'] = $post_data[FOOGALLERY_META_SETTINGS]['polaroid_new_thumbnail_dimensions']['width'];
227
			$args['thumbnail_height'] = $post_data[FOOGALLERY_META_SETTINGS]['polaroid_new_thumbnail_dimensions']['height'];
228
			$args['thumbnail_crop'] = isset( $post_data[FOOGALLERY_META_SETTINGS]['polaroid_new_thumbnail_dimensions']['crop'] ) ? '1' : '0';
229
230
			return $args;
231
		}
232
233
		/**
234
		 * Builds thumb dimensions from arguments
235
		 *
236
		 * @param array $dimensions
237
		 * @param array $arguments
238
		 *
239
		 * @return mixed
240
		 */
241
		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...
242
			return array(
243
				'height' => intval( $arguments['thumbnail_height'] ),
244
				'width'  => intval( $arguments['thumbnail_width'] ),
245
				'crop'   => $arguments['thumbnail_crop'] === '1'
246
			);
247
		}
248
	}
249
}