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/attachment-taxonomies ( 9fe273...54ac97 )
by Brad
06:02 queued 02:51
created

FooGallery_Masonry_Gallery_Template::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 28
rs 8.8571
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 the data options needed for masonry
22
			add_filter( 'foogallery_build_container_data_options-masonry', array( $this, 'add_masonry_options' ), 10, 3 );
23
24
			//build up any preview arguments
25
			add_filter( 'foogallery_preview_arguments-masonry', array( $this, 'preview_arguments' ), 10, 2 );
26
27
			//build up the thumb dimensions from some arguments
28
			add_filter( 'foogallery_calculate_thumbnail_dimensions-masonry', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 );
29
30
            //build up the arguments needed for rendering this template
31
            add_filter( 'foogallery_gallery_template_arguments-masonry', array( $this, 'build_gallery_template_arguments' ) );
32
33
            //add extra fields to the templates
34
            add_filter( 'foogallery_override_gallery_template_fields-masonry', array( $this, 'add_masonry_fields' ), 10, 2 );
35
36
			//remove the captions if the captions are below thumbs
37
			add_filter( 'foogallery_build_attachment_html_caption', array( $this, 'remove_captions' ), 10, 3 );
38
        }
39
40
		/**
41
		 * Register myself so that all associated JS and CSS files can be found and automatically included
42
		 * @param $extensions
43
		 *
44
		 * @return array
45
		 */
46
		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...
47
			$extensions[] = __FILE__;
48
			return $extensions;
49
		}
50
51
		/**
52
		 * Add our gallery template to the list of templates available for every gallery
53
		 * @param $gallery_templates
54
		 *
55
		 * @return array
56
		 */
57
		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...
58
			$gallery_templates[] = array(
59
                'slug'        => 'masonry',
60
                'name'        => __( 'Masonry Image Gallery', 'foogallery' ),
61
				'preview_support' => true,
62
				'common_fields_support' => true,
63
                'lazyload_support' => true,
64
				'paging_support' => true,
65
				'mandatory_classes' => 'fg-masonry',
66
				'thumbnail_dimensions' => true,
67
                'fields'	  => array(
68
                    array(
69
                        'id'      => 'thumbnail_width',
70
                        'title'   => __( 'Thumb Width', 'foogallery' ),
71
                        'desc'    => __( 'Choose the width of your thumbnails. Thumbnails will be generated on the fly and cached once generated', 'foogallery' ),
72
                        'section' => __( 'General', 'foogallery' ),
73
                        'type'    => 'number',
74
                        'class'   => 'small-text',
75
                        'default' => 150,
76
                        'step'    => '1',
77
                        'min'     => '0',
78
						'row_data'=> array(
79
							'data-foogallery-change-selector' => 'input',
80
							'data-foogallery-preview' => 'shortcode'
81
						)
82
                    ),
83
                    array(
84
                        'id'      => 'layout',
85
                        'title'   => __( 'Masonry Layout', 'foogallery' ),
86
                        'desc'    => __( 'Choose a fixed width thumb layout, or responsive columns.', 'foogallery' ),
87
                        'section' => __( 'General', 'foogallery' ),
88
                        'type'    => 'radio',
89
                        'choices' => array(
90
                            'fixed'  => __( 'Fixed Width', 'foogallery' ),
91
                            'col2'   => __( '2 Columns', 'foogallery' ),
92
                            'col3'   => __( '3 Columns', 'foogallery' ),
93
                            'col4'   => __( '4 Columns', 'foogallery' ),
94
                            'col5'   => __( '5 Columns', 'foogallery' )
95
                        ),
96
                        'default' => 'fixed',
97
                        'row_data'=> array(
98
                            'data-foogallery-change-selector' => 'input:radio',
99
                            'data-foogallery-value-selector' => 'input:checked',
100
							'data-foogallery-preview' => 'shortcode'
101
                        )
102
                    ),
103
                    array(
104
                        'id'      => 'gutter_width',
105
                        'title'   => __( 'Gutter Width', 'foogallery' ),
106
                        'desc'    => __( 'The spacing between your thumbnails. Only applicable when using a fixed layout!', 'foogallery' ),
107
                        'section' => __( 'General', 'foogallery' ),
108
                        'type'    => 'number',
109
                        'class'   => 'small-text',
110
                        'default' => 10,
111
                        'step'    => '1',
112
                        'min'     => '0',
113
                        'row_data'=> array(
114
                            'data-foogallery-hidden' => true,
115
							'data-foogallery-change-selector' => 'input',
116
							'data-foogallery-value-selector' => 'input',
117
                            'data-foogallery-show-when-field' => 'layout',
118
                            'data-foogallery-show-when-field-value' => 'fixed',
119
							'data-foogallery-preview' => 'shortcode',
120
                        )
121
                    ),
122
                    array(
123
                        'id'      => 'gutter_percent',
124
                        'title'   => __( 'Gutter Size', 'foogallery' ),
125
                        'desc'    => __( 'Choose a gutter size when using responsive columns.', 'foogallery' ),
126
                        'section' => __( 'General', 'foogallery' ),
127
                        'type'    => 'radio',
128
                        'choices' => array(
129
                            'fg-gutter-none'   => __( 'No Gutter', 'foogallery' ),
130
                            ''  => __( 'Normal Size Gutter', 'foogallery' ),
131
                            'fg-gutter-large'   => __( 'Larger Gutter', 'foogallery' )
132
                        ),
133
                        'default' => '',
134
                        'row_data'=> array(
135
                            'data-foogallery-hidden' => true,
136
							'data-foogallery-change-selector' => 'input:radio',
137
							'data-foogallery-value-selector' => 'input:checked',
138
                            'data-foogallery-show-when-field' => 'layout',
139
                            'data-foogallery-show-when-field-operator' => '!==',
140
                            'data-foogallery-show-when-field-value' => 'fixed',
141
							'data-foogallery-preview' => 'class'
142
                        )
143
                    ),
144
                    array(
145
                        'id'      => 'alignment',
146
                        'title'   => __( 'Alignment', 'foogallery' ),
147
                        'desc'    => __( 'You can choose to center align your images or leave them at the default (left). Only applicable when using a fixed layout!', 'foogallery' ),
148
						'section' => __( 'General', 'foogallery' ),
149
						'type'    => 'radio',
150
						'spacer'  => '<span class="spacer"></span>',
151
                        'choices' => array(
152
                            ''  => __( 'Left', 'foogallery' ),
153
                            'fg-center'   => __( 'Center', 'foogallery' )
154
                        ),
155
                        'default' => 'fg-center',
156
						'row_data'=> array(
157
							'data-foogallery-hidden' => true,
158
							'data-foogallery-show-when-field' => 'layout',
159
							'data-foogallery-show-when-field-value' => 'fixed',
160
							'data-foogallery-change-selector' => 'input:radio',
161
							'data-foogallery-preview' => 'class'
162
						)
163
                    ),
164
                    array(
165
                        'id'      => 'thumbnail_link',
166
                        'title'   => __( 'Thumb Link', 'foogallery' ),
167
                        'default' => 'image' ,
168
                        'type'    => 'thumb_link',
169
                        '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' ),
170
                    ),
171
                    array(
172
                        'id'      => 'lightbox',
173
                        'title'   => __( 'Lightbox', 'foogallery' ),
174
                        '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' ),
175
                        'type'    => 'lightbox',
176
                        'default' => 'none',
177
                    ),
178
                ),
179
			);
180
181
182
			return $gallery_templates;
183
		}
184
185
		/**
186
		 * Enqueue scripts that the masonry gallery template relies on
187
		 */
188
		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...
189
			wp_enqueue_script( 'masonry' );
190
		}
191
192
		/**
193
		 * Enqueue scripts that the masonry gallery template relies on
194
		 */
195
		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...
196
			wp_enqueue_script( 'masonry' );
197
198
			//enqueue core files
199
			foogallery_enqueue_core_gallery_template_style();
200
			foogallery_enqueue_core_gallery_template_script();
201
		}
202
203
		/**
204
		 * Get the thumb dimensions arguments saved for the gallery for this gallery template
205
		 *
206
		 * @param array $dimensions
207
		 * @param FooGallery $foogallery
208
		 *
209
		 * @return mixed
210
		 */
211
		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...
212
			$width = $foogallery->get_meta( 'masonry_thumbnail_width', false );
213
			return array(
214
				'height' => 0,
215
				'width'  => intval( $width ),
216
				'crop'   => false
217
			);
218
		}
219
220
		/**
221
		 * Add the required masonry options if needed
222
		 *
223
		 * @param $options
224
		 * @param $gallery    FooGallery
225
		 *
226
		 * @param $attributes array
227
		 *
228
		 * @return array
229
		 */
230
		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...
231
			$layout = foogallery_gallery_template_setting( 'layout', 'fixed' );
232
			$options['template']['layout'] = $layout;
233
			if ( 'fixed' === $layout ) {
234
				$width = foogallery_gallery_template_setting( 'thumbnail_width', '150' );
235
				$gutter_width = foogallery_gallery_template_setting( 'gutter_width', '10' );
236
				$options['template']['columnWidth'] = intval($width);
237
				$options['template']['gutter'] = intval($gutter_width);
238
			}
239
			return $options;
240
		}
241
242
		/**
243
		 * Build up a arguments used in the preview of the gallery
244
		 * @param $args
245
		 * @param $post_data
246
		 *
247
		 * @return mixed
248
		 */
249
		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...
250
			$args['thumbnail_width'] = $post_data[FOOGALLERY_META_SETTINGS]['masonry_thumbnail_width'];
251
			$args['layout'] = $post_data[FOOGALLERY_META_SETTINGS]['masonry_layout'];
252
			$args['gutter_width'] = $post_data[FOOGALLERY_META_SETTINGS]['masonry_gutter_width'];
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
            if ( array_key_exists( 'thumbnail_width', $arguments) ) {
266
                return array(
267
                    'height' => 0,
268
                    'width' => intval($arguments['thumbnail_width']),
269
                    'crop' => false
270
                );
271
            }
272
            return null;
273
		}
274
275
        /**
276
         * Build up the arguments needed for rendering this gallery template
277
         *
278
         * @param $args
279
         * @return array
280
         */
281
        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...
282
            $args = array(
283
                'width' => foogallery_gallery_template_setting( 'thumbnail_width', '150' ),
284
                'link' => foogallery_gallery_template_setting( 'thumbnail_link', 'image' ),
285
                'crop' => false
286
            );
287
288
            return $args;
289
        }
290
291
        /**
292
         * Add masonry-specific fields to the gallery template
293
         *
294
         * @uses "foogallery_override_gallery_template_fields"
295
         * @param $fields
296
         * @param $template
297
         *
298
         * @return array
299
         */
300
        function add_masonry_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...
301
            //update specific fields
302
            foreach ($fields as &$field) {
303
                if ( 'hover_effect_caption_visibility' === $field['id'] ) {
304
                    $field['choices']['fg-captions-bottom'] = __( 'Below Thumbnail', 'foogallery' );
305
                }
306
            }
307
308
            return $fields;
309
        }
310
311
        function remove_captions( $captions, $foogallery_attachment, $args ) {
0 ignored issues
show
Unused Code introduced by
The parameter $foogallery_attachment 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 $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...
312
			global $current_foogallery_template;
313
314
        	//check if masonry
315
			if ( 'masonry' === $current_foogallery_template ) {
316
317
				$hover_effect_caption_visibility = foogallery_gallery_template_setting( 'hover_effect_caption_visibility', 'fg-caption-hover' );
318
319
				//check if captions are set to show below the thumbs
320
				if ( 'fg-captions-bottom' === $hover_effect_caption_visibility ) {
321
					//if we have no captions then do not output captions at all
322
					if ( !array_key_exists( 'title', $captions ) && !array_key_exists( 'desc', $captions ) ) {
323
						$captions = false;
324
					}
325
				}
326
			}
327
328
        	return $captions;
329
		}
330
	}
331
}