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 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 7
rs 9.4285
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
33
		/**
34
		 * Register myself so that all associated JS and CSS files can be found and automatically included
35
		 * @param $extensions
36
		 *
37
		 * @return array
38
		 */
39
		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...
40
			$extensions[] = __FILE__;
41
			return $extensions;
42
		}
43
44
		/**
45
		 * Add our gallery template to the list of templates available for every gallery
46
		 * @param $gallery_templates
47
		 *
48
		 * @return array
49
		 */
50
		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...
51
			$gallery_templates[] = array(
52
                'slug'        => 'simple_portfolio',
53
                'name'        => __( 'Simple Portfolio', 'foogallery' ),
54
                'lazyload_support' => true,
55
                'fields'	  => array(
56
                    array(
57
                        'id'	  => 'help',
58
                        'title'	  => __( 'Tip', 'foogallery' ),
59
                        'section' => __( 'General', 'foogallery' ),
60
                        'type'	  => 'html',
61
                        'help'	  => true,
62
                        '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' ),
63
                    ),
64
                    array(
65
                        'id'      => 'thumbnail_dimensions',
66
                        'title'   => __( 'Thumbnail Size', 'foogallery' ),
67
                        'desc'    => __( 'Choose the size of your thumbnails.', 'foogallery' ),
68
                        'section' => __( 'General', 'foogallery' ),
69
                        'type'    => 'thumb_size',
70
                        'default' => array(
71
                            'width' => 250,
72
                            'height' => 200,
73
                            'crop' => true,
74
                        ),
75
						'row_data'=> array(
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' => __( 'General', '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 masonry gallery 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
			$updated_fields = apply_filters( 'foogallery_gallery_template_common_thumbnail_fields', $fields );
154
155
			//update specific fields
156
			foreach ($updated_fields as &$field) {
157
				if ( 'hover_effect_preset' === $field['id'] ) {
158
					$field['default'] = 'fg-custom';
159
					$field['choices'] = array(
160
						'fg-custom'  => __( 'Custom', 'foogallery' ),
161
					);
162
					$field['row_data'] = array(
163
						'data-foogallery-hidden' => true,
164
						'data-foogallery-change-selector' => 'input:radio',
165
						'data-foogallery-value-selector' => 'input:checked',
166
						'data-foogallery-preview' => 'class'
167
					);
168
				} else if ( 'hover_effect_caption_visibility' === $field['id'] ) {
169
					$field['default'] = 'fg-caption-always';
170
					$field['choices'] = array(
171
						'fg-caption-always' => __( 'Always Visible', 'foogallery' ),
172
					);
173
					$field['row_data'] = array(
174
						'data-foogallery-change-selector' => 'input:radio',
175
						'data-foogallery-hidden' => true,
176
						'data-foogallery-preview' => 'class'
177
					);
178
				}
179
			}
180
181
			return $updated_fields;
182
		}
183
184
		/**
185
		 * Add the required data options if needed
186
		 *
187
		 * @param $options
188
		 * @param $gallery    FooGallery
189
		 *
190
		 * @param $attributes array
191
		 *
192
		 * @return array
193
		 */
194
		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...
195
			$gutter = foogallery_gallery_template_setting( 'gutter', 40 );
196
			$options['template']['gutter'] = intval($gutter);
197
			return $options;
198
		}
199
200
		/**
201
		 * Override specific settings so that the gallery template will always work
202
		 *
203
		 * @param $settings
204
		 * @param $post_id
205
		 * @param $form_data
206
		 *
207
		 * @return mixed
208
		 */
209
		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...
210
			$settings['simple_portfolio_hover_effect_preset'] = 'fg-custom';
211
			$settings['simple_portfolio_hover_effect_caption_visibility'] = 'fg-caption-always';
212
213
			return $settings;
214
		}
215
216
		/**
217
		 * Build up a arguments used in the preview of the gallery
218
		 * @param $args
219
		 * @param $post_data
220
		 *
221
		 * @return mixed
222
		 */
223
		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...
224
			$args['thumbnail_width'] = $post_data['foogallery_settings']['simple_portfolio_thumbnail_dimensions']['width'];
225
			$args['thumbnail_height'] = $post_data['foogallery_settings']['simple_portfolio_thumbnail_dimensions']['height'];
226
			$args['thumbnail_crop'] = isset( $post_data['foogallery_settings']['simple_portfolio_thumbnail_dimensions']['crop'] ) ? '1' : '0';
227
228
			return $args;
229
		}
230
231
		/**
232
		 * Builds thumb dimensions from arguments
233
		 *
234
		 * @param array $dimensions
235
		 * @param array $arguments
236
		 *
237
		 * @return mixed
238
		 */
239
		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...
240
			return array(
241
				'height' => intval( $arguments['thumbnail_height'] ),
242
				'width'  => intval( $arguments['thumbnail_width'] ),
243
				'crop'   => $arguments['thumbnail_crop'] === '1'
244
			);
245
		}
246
	}
247
}