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... ( cd983d...5984e4 )
by Brad
02:39
created

preview_arguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
if ( !class_exists( 'FooGallery_Masonry_Gallery_Template' ) ) {
4
5
	define('FOOGALLERY_MASONRY_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ ));
6
7
	class FooGallery_Masonry_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_action( 'foogallery_enqueue_preview_dependencies', array( $this, 'enqueue_preview_dependencies' ) );
16
17
			add_filter( 'foogallery_located_template-masonry', array( $this, 'enqueue_dependencies' ) );
18
19
			add_filter( 'foogallery_template_thumbnail_dimensions-masonry', array( $this, 'get_thumbnail_dimensions' ), 10, 2 );
20
21
			//add extra fields to the templates
22
			add_filter( 'foogallery_override_gallery_template_fields-masonry', array( $this, 'add_common_thumbnail_fields' ), 10, 2 );
23
24
			//add the data options needed for masonry
25
			add_filter( 'foogallery_build_container_data_options-masonry', array( $this, 'add_masonry_options' ), 10, 3 );
26
27
			//build up any preview arguments
28
			add_filter( 'foogallery_preview_arguments-masonry', array( $this, 'preview_arguments' ), 10, 2 );
29
30
			//build up the thumb dimensions from some arguments
31
			add_filter( 'foogallery_calculate_thumbnail_dimensions-masonry', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 );
32
		}
33
34
		/**
35
		 * Register myself so that all associated JS and CSS files can be found and automatically included
36
		 * @param $extensions
37
		 *
38
		 * @return array
39
		 */
40
		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...
41
			$extensions[] = __FILE__;
42
			return $extensions;
43
		}
44
45
		/**
46
		 * Add our gallery template to the list of templates available for every gallery
47
		 * @param $gallery_templates
48
		 *
49
		 * @return array
50
		 */
51
		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...
52
			$gallery_templates[] = array(
53
                'slug'        => 'masonry',
54
                'name'        => __( 'Masonry Image Gallery', 'foogallery' ),
55
                'lazyload_support' => true,
56
                'fields'	  => array(
57
                    array(
58
                        'id'      => 'thumbnail_width',
59
                        'title'   => __( 'Thumb Width', 'foogallery' ),
60
                        'desc'    => __( 'Choose the width of your thumbnails. Thumbnails will be generated on the fly and cached once generated', 'foogallery' ),
61
                        'section' => __( 'General', 'foogallery' ),
62
                        'type'    => 'number',
63
                        'class'   => 'small-text',
64
                        'default' => 150,
65
                        'step'    => '1',
66
                        'min'     => '0',
67
						'row_data'=> array(
68
							'data-foogallery-preview' => 'shortcode'
69
						)
70
                    ),
71
                    array(
72
                        'id'      => 'layout',
73
                        'title'   => __( 'Masonry Layout', 'foogallery' ),
74
                        'desc'    => __( 'Choose a fixed width thumb layout, or responsive columns.', 'foogallery' ),
75
                        'section' => __( 'General', 'foogallery' ),
76
                        'type'    => 'radio',
77
                        'choices' => array(
78
                            'fixed'  => __( 'Fixed Width', 'foogallery' ),
79
                            'col2'   => __( '2 Columns', 'foogallery' ),
80
                            'col3'   => __( '3 Columns', 'foogallery' ),
81
                            'col4'   => __( '4 Columns', 'foogallery' ),
82
                            'col5'   => __( '5 Columns', 'foogallery' )
83
                        ),
84
                        'default' => 'fixed',
85
                        'row_data'=> array(
86
                            'data-foogallery-change-selector' => 'input:radio',
87
                            'data-foogallery-value-selector' => 'input:checked',
88
							'data-foogallery-preview' => 'data'
89
                        )
90
                    ),
91
                    array(
92
                        'id'      => 'gutter_width',
93
                        'title'   => __( 'Gutter Width', 'foogallery' ),
94
                        'desc'    => __( 'The spacing between your thumbnails. Only applicable when using a fixed layout!', 'foogallery' ),
95
                        'section' => __( 'General', 'foogallery' ),
96
                        'type'    => 'number',
97
                        'class'   => 'small-text',
98
                        'default' => 10,
99
                        'step'    => '1',
100
                        'min'     => '0',
101
                        'row_data'=> array(
102
                            'data-foogallery-hidden' => true,
103
							'data-foogallery-change-selector' => 'input',
104
							'data-foogallery-value-selector' => 'input',
105
                            'data-foogallery-show-when-field' => 'layout',
106
                            'data-foogallery-show-when-field-value' => 'fixed',
107
							'data-foogallery-preview' => 'data',
108
                        )
109
                    ),
110
                    array(
111
                        'id'      => 'gutter_percent',
112
                        'title'   => __( 'Gutter Size', 'foogallery' ),
113
                        'desc'    => __( 'Choose a gutter size when using responsive columns.', 'foogallery' ),
114
                        'section' => __( 'General', 'foogallery' ),
115
                        'type'    => 'radio',
116
                        'choices' => array(
117
                            'fg-gutter-none'   => __( 'No Gutter', 'foogallery' ),
118
                            ''  => __( 'Normal Size Gutter', 'foogallery' ),
119
                            'fg-gutter-large'   => __( 'Larger Gutter', 'foogallery' )
120
                        ),
121
                        'default' => '',
122
                        'row_data'=> array(
123
                            'data-foogallery-hidden' => true,
124
							'data-foogallery-change-selector' => 'input:radio',
125
							'data-foogallery-value-selector' => 'input:checked',
126
                            'data-foogallery-show-when-field' => 'layout',
127
                            'data-foogallery-show-when-field-operator' => '!==',
128
                            'data-foogallery-show-when-field-value' => 'fixed',
129
							'data-foogallery-preview' => 'class'
130
                        )
131
                    ),
132
                    array(
133
                        'id'      => 'alignment',
134
                        'title'   => __( 'Alignment', 'foogallery' ),
135
                        'desc'    => __( 'You can choose to center align your images or leave them at the default (left). Only applicable when using a fixed layout!', 'foogallery' ),
136
						'section' => __( 'General', 'foogallery' ),
137
						'type'    => 'radio',
138
						'spacer'  => '<span class="spacer"></span>',
139
                        'choices' => array(
140
                            ''  => __( 'Left', 'foogallery' ),
141
                            'fg-center'   => __( 'Center', 'foogallery' )
142
                        ),
143
                        'default' => 'default',
144
						'row_data'=> array(
145
							'data-foogallery-hidden' => true,
146
							'data-foogallery-show-when-field' => 'layout',
147
							'data-foogallery-show-when-field-value' => 'fixed',
148
							'data-foogallery-change-selector' => 'input:radio',
149
							'data-foogallery-preview' => 'class'
150
						)
151
                    ),
152
                    array(
153
                        'id'      => 'thumbnail_link',
154
                        'title'   => __( 'Thumb Link', 'foogallery' ),
155
                        'default' => 'image' ,
156
                        'type'    => 'thumb_link',
157
                        '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' ),
158
                    ),
159
                    array(
160
                        'id'      => 'lightbox',
161
                        'title'   => __( 'Lightbox', 'foogallery' ),
162
                        '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' ),
163
                        'type'    => 'lightbox',
164
                    ),
165
                ),
166
			);
167
168
169
			return $gallery_templates;
170
		}
171
172
		/**
173
		 * Enqueue scripts that the masonry gallery template relies on
174
		 */
175
		function enqueue_preview_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...
176
			wp_enqueue_script( 'masonry' );
177
		}
178
179
		/**
180
		 * Enqueue scripts that the masonry gallery template relies on
181
		 */
182
		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...
183
			wp_enqueue_script( 'masonry' );
184
185
			//enqueue core files
186
			foogallery_enqueue_core_gallery_template_style();
187
			foogallery_enqueue_core_gallery_template_script();
188
		}
189
190
		/**
191
		 * Get the thumb dimensions arguments saved for the gallery for this gallery template
192
		 *
193
		 * @param array $dimensions
194
		 * @param FooGallery $foogallery
195
		 *
196
		 * @return mixed
197
		 */
198
		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...
199
			$width = $foogallery->get_meta( 'masonry_thumbnail_width', false );
200
			return array(
201
				'height' => 0,
202
				'width'  => intval( $width ),
203
				'crop'   => false
204
			);
205
		}
206
207
		/**
208
		 * Add thumbnail fields to the gallery template
209
		 *
210
		 * @uses "foogallery_override_gallery_template_fields"
211
		 * @param $fields
212
		 * @param $template
213
		 *
214
		 * @return array
215
		 */
216
		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...
217
			return apply_filters( 'foogallery_gallery_template_common_thumbnail_fields', $fields );
218
		}
219
220
221
		/**
222
		 * Add the required masonry options if needed
223
		 *
224
		 * @param $options
225
		 * @param $gallery    FooGallery
226
		 *
227
		 * @param $attributes array
228
		 *
229
		 * @return array
230
		 */
231
		function add_masonry_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...
232
			$layout = foogallery_gallery_template_setting( 'layout', 'fixed' );
233
			$options['template']['layout'] = $layout;
234
			if ( 'fixed' === $layout ) {
235
				$width = foogallery_gallery_template_setting( 'thumbnail_width', '150' );
236
				$gutter_width = foogallery_gallery_template_setting( 'gutter_width', '10' );
237
				$options['template']['columnWidth'] = intval($width);
238
				$options['template']['gutter'] = intval($gutter_width);
239
			}
240
			return $options;
241
		}
242
243
		/**
244
		 * Build up a arguments used in the preview of the gallery
245
		 * @param $args
246
		 * @param $post_data
247
		 *
248
		 * @return mixed
249
		 */
250
		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...
251
			$args['thumbnail_width'] = $post_data['foogallery_settings']['masonry_thumbnail_width'];
252
253
			return $args;
254
		}
255
256
		/**
257
		 * Builds thumb dimensions from arguments
258
		 *
259
		 * @param array $dimensions
260
		 * @param array $arguments
261
		 *
262
		 * @return mixed
263
		 */
264
		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...
265
			return array(
266
				'height' => 0,
267
				'width'  => intval( $arguments['thumbnail_width'] ),
268
				'crop'   => false
269
			);
270
		}
271
	}
272
}