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 ( f3e37c...e64063 )
by Brad
07:56 queued 03:40
created

build_gallery_template_arguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 11
rs 9.4285
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' ), 99, 1 );
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
            //build up the thumb dimensions on save
36
            add_filter( 'foogallery_template_thumbnail_dimensions-polaroid_new', array( $this, 'get_thumbnail_dimensions' ), 10, 2 );
37
38
            //check if the old Polaroid is installed
39
            if ( is_admin() ) {
40
                add_action( 'admin_notices', array( $this, 'display_polaroid_notice') );
41
            }
42
43
            //build up the arguments needed for rendering this template
44
            add_filter( 'foogallery_gallery_template_arguments-polaroid_new', array( $this, 'build_gallery_template_arguments' ) );
45
        }
46
47
		/**
48
		 * Register myself so that all associated JS and CSS files can be found and automatically included
49
		 * @param $extensions
50
		 *
51
		 * @return array
52
		 */
53
		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...
54
			$extensions[] = __FILE__;
55
			return $extensions;
56
		}
57
58
		/**
59
		 * Add our gallery template to the list of templates available for every gallery
60
		 * @param $gallery_templates
61
		 *
62
		 * @return array
63
		 */
64
		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...
65
			$gallery_templates[] = array(
66
                'slug'        => 'polaroid_new',
67
                'name'        => __( 'Polaroid PRO', 'foogallery' ),
68
				'preview_support' => true,
69
				'common_fields_support' => true,
70
                'lazyload_support' => true,
71
				'paging_support' => true,
72
				'mandatory_classes' => 'fg-simple_portfolio fg-preset fg-polaroid',
73
				'thumbnail_dimensions' => true,
74
                'fields'	  => array(
75
                    array(
76
                        'id'      => 'thumbnail_dimensions',
77
                        'title'   => __( 'Thumbnail Size', 'foogallery' ),
78
                        'desc'    => __( 'Choose the size of your thumbnails.', 'foogallery' ),
79
                        'section' => __( 'General', 'foogallery' ),
80
                        'type'    => 'thumb_size',
81
                        'default' => array(
82
                            'width' => 250,
83
                            'height' => 200,
84
                            'crop' => true,
85
                        ),
86
						'row_data'=> array(
87
							'data-foogallery-change-selector' => 'input',
88
							'data-foogallery-preview' => 'shortcode'
89
						)
90
                    ),
91
                    array(
92
                        'id'      => 'thumbnail_link',
93
                        'title'   => __( 'Thumbnail Link', 'foogallery' ),
94
                        'section' => __( 'General', 'foogallery' ),
95
                        'default' => 'image',
96
                        'type'    => 'thumb_link',
97
                        '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' )
98
                    ),
99
                    array(
100
                        'id'      => 'lightbox',
101
                        'title'   => __( 'Lightbox', 'foogallery' ),
102
                        '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' ),
103
                        'section' => __( 'General', 'foogallery' ),
104
                        'type'    => 'lightbox',
105
                    ),
106
                    array(
107
                        'id'      => 'gutter',
108
                        'title'   => __( 'Gutter', 'foogallery' ),
109
                        'desc'    => __( 'The spacing between each thumbnail in the gallery.', 'foogallery' ),
110
						'section' => __( 'General', 'foogallery' ),
111
                        'type'    => 'number',
112
                        'class'   => 'small-text',
113
                        'default' => 40,
114
                        'step'    => '1',
115
                        'min'     => '0',
116
						'row_data'=> array(
117
							'data-foogallery-change-selector' => 'input',
118
							'data-foogallery-value-selector' => 'input',
119
							'data-foogallery-preview' => 'shortcode',
120
						)
121
                    ),
122
                    array(
123
                        'id'      => 'align',
124
                        'title'   => __( 'Alignment', 'foogallery' ),
125
                        'desc'    => __( 'The horizontal alignment of the thumbnails inside the gallery.', 'foogallery' ),
126
                        'section' => __( 'General', 'foogallery' ),
127
                        'type'    => 'radio',
128
                        'spacer'  => '<span class="spacer"></span>',
129
                        'default' => 'center',
130
                        'choices' => array(
131
                            'left' => __( 'Left', 'foogallery' ),
132
                            'center' => __( 'Center', 'foogallery' ),
133
                            'right' => __( 'Right', 'foogallery' ),
134
                        ),
135
                        'row_data'=> array(
136
                            'data-foogallery-change-selector' => 'input:radio',
137
                            'data-foogallery-value-selector' => 'input:checked',
138
                            'data-foogallery-preview' => 'shortcode',
139
                        )
140
                    ),
141
                    array(
142
                        'id'      => 'caption_position',
143
                        'title' => __('Caption Position', 'foogallery'),
144
                        'desc' => __('Where the captions are displayed in relation to the thumbnail.', 'foogallery'),
145
						'section' => __( 'Captions', 'foogallery' ),
146
                        'default' => '',
147
                        'type'    => 'radio',
148
                        'spacer'  => '<span class="spacer"></span>',
149
                        'choices' => array(
150
                            '' => __( 'Below', 'foogallery' ),
151
                            'fg-captions-top' => __( 'Above', 'foogallery' )
152
                        ),
153
						'row_data'=> array(
154
							'data-foogallery-change-selector' => 'input:radio',
155
							'data-foogallery-value-selector' => 'input:checked',
156
							'data-foogallery-preview' => 'class'
157
						)
158
                    ),
159
                ),
160
			);
161
162
			return $gallery_templates;
163
		}
164
165
		/**
166
		 * Enqueue scripts that the polaroid template relies on
167
		 */
168
		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...
169
			//enqueue core files
170
			foogallery_enqueue_core_gallery_template_style();
171
			foogallery_enqueue_core_gallery_template_script();
172
		}
173
174
		/**
175
		 * Add thumbnail fields to the gallery template
176
		 *
177
		 * @uses "foogallery_override_gallery_template_fields"
178
		 * @param $fields
179
		 * @param $template
180
		 *
181
		 * @return array
182
		 */
183
		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...
184
			$fields_to_remove = array();
185
186
			//update specific fields
187
			foreach ($fields as $key => &$field) {
188
				if ( 'hover_effect_preset' === $field['id'] ) {
189
					$field['default'] = 'fg-custom';
190
					$field['choices'] = array(
191
						'fg-custom'  => __( 'Polaroid', 'foogallery' )
192
					);
193
					$field['row_data'] = array(
194
						'data-foogallery-hidden' => true,
195
						'data-foogallery-change-selector' => 'input:radio',
196
						'data-foogallery-value-selector' => 'input:checked',
197
						'data-foogallery-preview' => 'class'
198
					);
199
				} else if ( 'hover_effect_caption_visibility' === $field['id'] ) {
200
					$field['default'] = 'fg-caption-always';
201
					$field['choices'] = array(
202
						'fg-caption-always' => __( 'Always Visible', 'foogallery' ),
203
					);
204
					$field['row_data'] = array(
205
						'data-foogallery-change-selector' => 'input:radio',
206
						'data-foogallery-hidden' => true,
207
						'data-foogallery-preview' => 'class'
208
					);
209
				} else if ( 'hover_effect_help' == $field['id'] ) {
210
					$field['row_data'] = array(
211
						'data-foogallery-hidden' => true
212
					);
213
				} else if ( 'hover_effect_scale' == $field['id'] ) {
214
					$fields_to_remove[] = $key;
215
				}
216
			}
217
218
			foreach ($fields_to_remove as $key) {
219
				unset($fields[$key]);
220
			}
221
222
			return $fields;
223
		}
224
225
		/**
226
		 * Add the required data options if needed
227
		 *
228
		 * @param $options
229
		 * @param $gallery    FooGallery
230
		 *
231
		 * @param $attributes array
232
		 *
233
		 * @return array
234
		 */
235
		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...
236
			$gutter = foogallery_gallery_template_setting( 'gutter', 40 );
237
			$options['template']['gutter'] = intval($gutter);
238
239
            $align = foogallery_gallery_template_setting( 'align', 'center' );
240
            $options['template']['align'] = $align;
241
			return $options;
242
		}
243
244
		/**
245
		 * Override specific settings so that the gallery template will always work
246
		 *
247
		 * @param $settings
248
		 * @param $post_id
249
		 * @param $form_data
250
		 *
251
		 * @return mixed
252
		 */
253
		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...
254
			$settings['polaroid_new_hover_effect_preset'] = 'fg-custom';
255
			$settings['polaroid_new_hover_effect_caption_visibility'] = 'fg-caption-always';
256
257
			return $settings;
258
		}
259
260
		/**
261
		 * Build up a arguments used in the preview of the gallery
262
		 * @param $args
263
		 * @param $post_data
264
		 *
265
		 * @return mixed
266
		 */
267
		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...
268
            $args['thumbnail_dimensions'] = $post_data[FOOGALLERY_META_SETTINGS]['polaroid_new_thumbnail_dimensions'];
269
            $args['gutter'] = $post_data[FOOGALLERY_META_SETTINGS]['polaroid_new_gutter'];
270
            $args['align'] = $post_data[FOOGALLERY_META_SETTINGS]['polaroid_new_align'];
271
            return $args;
272
		}
273
274
		/**
275
		 * Builds thumb dimensions from arguments
276
		 *
277
		 * @param array $dimensions
278
		 * @param array $arguments
279
		 *
280
		 * @return mixed
281
		 */
282
		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...
283
            if ( array_key_exists( 'thumbnail_dimensions', $arguments) ) {
284
                return array(
285
                    'height' => intval($arguments['thumbnail_dimensions']['height']),
286
                    'width' => intval($arguments['thumbnail_dimensions']['width']),
287
                    'crop' => '1'
288
                );
289
            }
290
            return null;
291
		}
292
293
        /**
294
         * Get the thumb dimensions arguments saved for the gallery for this gallery template
295
         *
296
         * @param array $dimensions
297
         * @param FooGallery $foogallery
298
         *
299
         * @return mixed
300
         */
301
        function get_thumbnail_dimensions( $dimensions, $foogallery ) {
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...
302
            $dimensions = $foogallery->get_meta( 'polaroid_new_thumbnail_dimensions', array(
303
                'width' => 250,
304
                'height' => 200
305
            ) );
306
            $dimensions['crop'] = true;
307
            return $dimensions;
308
        }
309
310
        /**
311
         * Display a message if the Polaroid extension is also installed
312
         */
313
        function display_polaroid_notice() {
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...
314
            if ( class_exists('FooGallery_Polaroid_Template_Extension') ) {
315
                ?>
316
                <div class="notice error">
317
                    <p>
318
                        <strong><?php _e('Polaroid Extension Redundant!', 'foogallery'); ?></strong><br/>
319
                        <?php _e('You have both FooGallery PRO and the old Polaroid extension activated. FooGallery PRO includes the Polaroid PRO gallery template, which makes the free Polaroid extension redundant.', 'foogallery'); ?>
320
                        <br/>
321
                        <?php _e('Please edit all galleries that use the old Polaroid gallery template and change them to use the Polaroid PRO gallery template. Once this is done, you can delete the free Polaroid extension.', 'foogallery'); ?>
322
                        <br/>
323
                    </p>
324
                </div>
325
                <?php
326
            }
327
        }
328
329
        /**
330
         * Build up the arguments needed for rendering this gallery template
331
         *
332
         * @param $args
333
         * @return array
334
         */
335
        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...
336
            $args = foogallery_gallery_template_setting( 'thumbnail_dimensions', array() );
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
337
            $args['link'] = foogallery_gallery_template_setting( 'thumbnail_link', 'image' );
338
            $args['image_attributes'] = array(
339
                'class'  => 'bf-img',
340
                'height' => $args['height']
341
            );
342
            $args['link_attributes'] = array( 'class' => 'foogallery-thumb' );
343
344
            return $args;
345
        }
346
	}
347
}