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... ( 39a5ef...85d10e )
by Brad
02:34
created

__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
1
<?php
2
3
if ( !class_exists( 'FooGallery_Simple_Portfolio_Gallery_Template' ) ) {
4
5
	define('FOOGALLERY_SIMPLE_PORTFOLIO_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ ));
6
7
	class FooGallery_Simple_Portfolio_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_located_template-simple_portfolio', array( $this, 'enqueue_dependencies' ) );
16
17
			//add extra fields to the templates
18
			add_filter( 'foogallery_override_gallery_template_fields-simple_portfolio', array( $this, 'add_common_thumbnail_fields' ), 10, 2 );
19
20
			//add the data options needed for simple portfolio
21
			add_filter( 'foogallery_build_container_data_options-simple_portfolio', array( $this, 'add_data_options' ), 10, 3 );
22
23
			//override specific settings when saving the gallery
24
			add_filter( 'foogallery_save_gallery_settings-simple_portfolio', array( $this, 'override_settings'), 10, 3 );
25
26
			//build up any preview arguments
27
			add_filter( 'foogallery_preview_arguments-simple_portfolio', array( $this, 'preview_arguments' ), 10, 2 );
28
29
			//build up the thumb dimensions from some arguments
30
			add_filter( 'foogallery_calculate_thumbnail_dimensions-simple_portfolio', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 );
31
32
			//build up the thumb dimensions on save
33
			add_filter( 'foogallery_template_thumbnail_dimensions-simple_portfolio', array( $this, 'get_thumbnail_dimensions' ), 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'        => 'simple_portfolio',
56
                'name'        => __( 'Simple Portfolio', 'foogallery' ),
57
				'preview_support' => true,
58
				'common_fields_support' => true,
59
                'lazyload_support' => true,
60
				'paging_support' => true,
61
				'mandatory_classes' => 'fg-simple_portfolio',
62
				'thumbnail_dimensions' => true,
63
                'fields'	  => array(
64
                    array(
65
                        'id'	  => 'help',
66
                        'title'	  => __( 'Tip', 'foogallery' ),
67
                        'section' => __( 'General', 'foogallery' ),
68
                        'type'	  => 'html',
69
                        'help'	  => true,
70
                        'desc'	  => __( 'The Simple Portfolio template works best when you have <strong>captions and descriptions</strong> set for every attachment in the gallery. To change captions and descriptions, simply hover over the thumbnail above and click the "i" icon.', 'foogallery' ),
71
                    ),
72
                    array(
73
                        'id'      => 'thumbnail_dimensions',
74
                        'title'   => __( 'Thumbnail Size', 'foogallery' ),
75
                        'desc'    => __( 'Choose the size of your thumbnails.', 'foogallery' ),
76
                        'section' => __( 'General', 'foogallery' ),
77
                        'type'    => 'thumb_size_no_crop',
78
                        'default' => array(
79
                            'width' => 250,
80
                            'height' => 200
81
                        ),
82
						'row_data'=> array(
83
							'data-foogallery-change-selector' => 'input',
84
							'data-foogallery-preview' => 'shortcode'
85
						)
86
                    ),
87
                    array(
88
                        'id'      => 'thumbnail_link',
89
                        'title'   => __( 'Thumbnail Link', 'foogallery' ),
90
                        'section' => __( 'General', 'foogallery' ),
91
                        'default' => 'image',
92
                        'type'    => 'thumb_link',
93
                        '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' )
94
                    ),
95
                    array(
96
                        'id'      => 'lightbox',
97
                        'title'   => __( 'Lightbox', 'foogallery' ),
98
                        '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' ),
99
                        'section' => __( 'General', 'foogallery' ),
100
                        'type'    => 'lightbox',
101
                        'default' => 'none',
102
                    ),
103
                    array(
104
                        'id'      => 'gutter',
105
                        'title'   => __( 'Gutter', 'foogallery' ),
106
                        'desc'    => __( 'The spacing between each thumbnail in the gallery.', 'foogallery' ),
107
						'section' => __( 'General', 'foogallery' ),
108
                        'type'    => 'number',
109
                        'class'   => 'small-text',
110
                        'default' => 40,
111
                        'step'    => '1',
112
                        'min'     => '0',
113
						'row_data'=> array(
114
							'data-foogallery-change-selector' => 'input',
115
							'data-foogallery-value-selector' => 'input',
116
							'data-foogallery-preview' => 'shortcode',
117
						)
118
                    ),
119
                    array(
120
                        'id'      => 'caption_position',
121
                        'title' => __('Caption Position', 'foogallery'),
122
                        'desc' => __('Where the captions are displayed in relation to the thumbnail.', 'foogallery'),
123
						'section' => __( 'Captions', 'foogallery' ),
124
                        'default' => '',
125
                        'type'    => 'radio',
126
                        'spacer'  => '<span class="spacer"></span>',
127
                        'choices' => array(
128
                            '' => __( 'Below', 'foogallery' ),
129
                            'fg-captions-top' => __( 'Above', 'foogallery' )
130
                        ),
131
						'row_data'=> array(
132
							'data-foogallery-change-selector' => 'input:radio',
133
							'data-foogallery-value-selector' => 'input:checked',
134
							'data-foogallery-preview' => 'class'
135
						)
136
                    ),
137
                ),
138
			);
139
140
			return $gallery_templates;
141
		}
142
143
		/**
144
		 * Enqueue scripts that the simple portfolio template relies on
145
		 */
146
		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...
147
			//enqueue core files
148
			foogallery_enqueue_core_gallery_template_style();
149
			foogallery_enqueue_core_gallery_template_script();
150
		}
151
152
		/**
153
		 * Add thumbnail fields to the gallery template
154
		 *
155
		 * @uses "foogallery_override_gallery_template_fields"
156
		 * @param $fields
157
		 * @param $template
158
		 *
159
		 * @return array
160
		 */
161
		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...
162
			//update specific fields
163
			foreach ($fields as &$field) {
164
				if ( 'hover_effect_caption_visibility' === $field['id'] ) {
165
					$field['default'] = 'fg-caption-always';
166
					$field['choices'] = array(
167
						'fg-caption-always' => __( 'Always Visible', 'foogallery' ),
168
					);
169
					$field['row_data'] = array(
170
						'data-foogallery-change-selector' => 'input:radio',
171
						'data-foogallery-hidden' => true,
172
						'data-foogallery-preview' => 'class'
173
					);
174
				} else if ( 'hover_effect_help' == $field['id'] ||
175
                            'captions_help' == $field['id']) {
176
					$field['row_data'] = array(
177
						'data-foogallery-hidden' => true
178
					);
179
				}
180
			}
181
182
			return $fields;
183
		}
184
185
		/**
186
		 * Add the required data options if needed
187
		 *
188
		 * @param $options
189
		 * @param $gallery    FooGallery
190
		 *
191
		 * @param $attributes array
192
		 *
193
		 * @return array
194
		 */
195
		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...
196
			$gutter = foogallery_gallery_template_setting( 'gutter', 40 );
197
			$options['template']['gutter'] = intval($gutter);
198
			return $options;
199
		}
200
201
		/**
202
		 * Override specific settings so that the gallery template will always work
203
		 *
204
		 * @param $settings
205
		 * @param $post_id
206
		 * @param $form_data
207
		 *
208
		 * @return mixed
209
		 */
210
		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...
211
			$settings['simple_portfolio_hover_effect_preset'] = 'fg-custom';
212
			$settings['simple_portfolio_hover_effect_caption_visibility'] = 'fg-caption-always';
213
214
			return $settings;
215
		}
216
217
		/**
218
		 * Build up a arguments used in the preview of the gallery
219
		 * @param $args
220
		 * @param $post_data
221
		 *
222
		 * @return mixed
223
		 */
224
		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...
225
			$args['thumbnail_dimensions'] = $post_data[FOOGALLERY_META_SETTINGS]['simple_portfolio_thumbnail_dimensions'];
226
			$args['gutter'] = $post_data[FOOGALLERY_META_SETTINGS]['simple_portfolio_gutter'];
227
			return $args;
228
		}
229
230
		/**
231
		 * Builds thumb dimensions from arguments
232
		 *
233
		 * @param array $dimensions
234
		 * @param array $arguments
235
		 *
236
		 * @return mixed
237
		 */
238
		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...
239
			return array(
240
				'height' => intval( $arguments['thumbnail_dimensions']['height'] ),
241
				'width'  => intval( $arguments['thumbnail_dimensions']['width'] ),
242
				'crop'   => '1'
243
			);
244
		}
245
246
		/**
247
		 * Get the thumb dimensions arguments saved for the gallery for this gallery template
248
		 *
249
		 * @param array $dimensions
250
		 * @param FooGallery $foogallery
251
		 *
252
		 * @return mixed
253
		 */
254
		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...
255
			$dimensions = $foogallery->get_meta( 'simple_portfolio_thumbnail_dimensions', array(
256
				'width' => 250,
257
				'height' => 200
258
			) );
259
			$dimensions['crop'] = true;
260
			return $dimensions;
261
		}
262
	}
263
}