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 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * FooGallery FooGrid Pro Extension
4
 *
5
 * A gallery with inline preview based on the Google image search results.
6
 *
7
 * @package   FooGrid_Template_FooGallery_Extension
8
 * @author     FooPlugins
9
 * @license   GPL-2.0+
10
 * @link      https://fooplugins.com
11
 * @copyright 2014  FooPlugins
12
 *
13
 * @wordpress-plugin
14
 * Plugin Name: FooGallery - FooGrid
15
 * Description: A gallery with inline preview based on Google\'s image search results.
16
 * Version:     1.0.0
17
 * Author:       FooPlugins
18
 * Author URI:  https://fooplugins.com
19
 * License:     GPL-2.0+
20
 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
21
 */
22
23
if ( !class_exists( 'FooGallery_FooGrid_Gallery_Template' ) ) {
24
25
	define('FOOGALLERY_FOOGRID_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ ));
26
	define('FOOGALLERY_FOOGRID_GALLERY_TEMPLATE_PATH', plugin_dir_path( __FILE__ ));
27
28
	class FooGallery_FooGrid_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...
29
		/**
30
		 * Wire up everything we need to run the extension
31
		 */
32
		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...
33
			add_filter( 'foogallery_gallery_templates', array( $this, 'add_template' ), 100, 1 );
34
			add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) );
35
			add_filter( 'foogallery_located_template-foogridpro', array( $this, 'enqueue_dependencies' ) );
36
37
			//get thumbnail dimensions
38
			add_filter( 'foogallery_template_thumbnail_dimensions-foogridpro', array( $this, 'get_thumbnail_dimensions' ), 10, 2 );
39
40
			add_filter( 'foogallery_template_load_css-foogridpro', '__return_false' );
41
			add_filter( 'foogallery_template_load_js-foogridpro', '__return_false' );
42
43
			//add the data options needed for polaroid
44
			add_filter( 'foogallery_build_container_data_options-foogridpro', array( $this, 'add_data_options' ), 10, 3 );
45
46
			//override specific settings when saving the gallery
47
			add_filter( 'foogallery_save_gallery_settings-foogridpro', array( $this, 'override_settings'), 10, 3 );
48
49
			//build up any preview arguments
50
			add_filter( 'foogallery_preview_arguments-foogridpro', array( $this, 'preview_arguments' ), 10, 2 );
51
52
			//build up the thumb dimensions from some arguments
53
			add_filter( 'foogallery_calculate_thumbnail_dimensions-foogridpro', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 );
54
55
			//check if the old FooGrid is installed
56
			if ( is_admin() ) {
57
                add_action( 'admin_notices', array( $this, 'display_foogrid_notice') );
58
            }
59
60
            //build up the arguments needed for rendering this template
61
            add_filter( 'foogallery_gallery_template_arguments-foogridpro', array( $this, 'build_gallery_template_arguments' ) );
62
        }
63
64
		/**
65
		 * Register myself so that all associated JS and CSS files can be found and automatically included
66
		 * @param $extensions
67
		 *
68
		 * @return array
69
		 */
70
		function register_myself( $extensions ) {
71
			$extensions[] = __FILE__;
72
			return $extensions;
73
		}
74
75
		/**
76
		 * Enqueue any script or stylesheet file dependencies that your gallery template relies on
77
		 *
78
		 * @param  $gallery
79
		 */
80
		function enqueue_dependencies( $gallery ) {
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...
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...
81
            foogallery_enqueue_core_gallery_template_style();
82
            foogallery_enqueue_core_gallery_template_script();
83
		}
84
85
		/**
86
		 * Add our gallery template to the list of templates available for every gallery
87
		 * @param $gallery_templates
88
		 *
89
		 * @return array
90
		 */
91
		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...
92
93
			$gallery_templates[] = array(
94
				'slug'        => 'foogridpro',
95
				'name'        => __( 'Grid PRO', 'foogallery'),
96
                'preview_support' => true,
97
                'common_fields_support' => true,
98
                'lazyload_support' => true,
99
                'paging_support' => true,
100
                'thumbnail_dimensions' => true,
101
				'mandatory_classes' => 'foogrid',
102
				'fields'	  => array(
103
					array(
104
						'id'      => 'thumbnail_size',
105
						'title'   => __('Thumbnail Size', 'foogallery'),
106
						'desc'    => __('Choose the size of your thumbs.', 'foogallery'),
107
						'type'    => 'thumb_size',
108
						'default' => array(
109
							'width' => 320,
110
							'height' => 180,
111
							'crop' => true
112
						),
113
						'row_data'=> array(
114
							'data-foogallery-change-selector' => 'input',
115
							'data-foogallery-preview' => 'shortcode'
116
						)
117
					),
118
					array(
119
						'id'      => 'thumbnail_link',
120
						'title'   => __('Thumbnail Link', 'foogallery'),
121
						'default' => 'image' ,
122
						'type'    => 'thumb_link',
123
						'desc'	  => __('You can choose to either link each thumbnail to the full size image or to the image\'s attachment page.', 'foogallery')
124
					),
125
//					array(
0 ignored issues
show
Unused Code Comprehensibility introduced by
51% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
126
//						'id'      => 'theme',
127
//						'section' => __( 'General', 'foogallery' ),
128
//						'title' => __('Theme', 'foogallery'),
129
//						'desc' => __('The theme for the content viewer.', 'foogallery'),
130
//						'default' => '',
131
//						'type'    => 'radio',
132
//						'spacer'  => '<span class="spacer"></span>',
133
//						'choices' => array(
134
//							'' => __( 'Dark (Default)', 'foogallery' ),
135
//							'foogrid-light' => __( 'Light', 'foogallery' )
136
//						)
137
//					),
138
					array(
139
						'id'      => 'transition',
140
						'section' => __( 'General', 'foogallery' ),
141
						'title'   => __('Transition', 'foogallery'),
142
						'desc' => __('Transition type to use switching between items, or no transitions at all.', 'foogallery'),
143
						'default' => 'foogrid-transition-fade',
144
						'type'    => 'radio',
145
						'spacer'  => '<span class="spacer"></span>',
146
						'choices' => array(
147
							'foogrid-transition-fade' => __( 'Fade', 'foogallery' ),
148
							'foogrid-transition-horizontal' => __( 'Horizontal', 'foogallery' ),
149
							'foogrid-transition-vertical' => __( 'Vertical', 'foogallery' ),
150
							'' => __( 'None', 'foogallery' )
151
						),
152
						'row_data'=> array(
153
							'data-foogallery-change-selector' => 'input',
154
							'data-foogallery-value-selector' => 'input:checked',
155
							'data-foogallery-preview' => 'class'
156
						)
157
					),
158
					array(
159
						'id' => 'loop',
160
						'section' => __( 'General', 'foogallery' ),
161
						'title' => __('Loop', 'foogallery'),
162
						'desc' => __('Whether the slider should loop (i.e. the first slide goes to the last, the last slide goes to the first).', 'foogallery'),
163
						'default' => 'yes',
164
						'type'    => 'radio',
165
						'spacer'  => '<span class="spacer"></span>',
166
						'choices' => array(
167
							'yes' => __( 'Yes', 'foogallery' ),
168
							'no' => __( 'No', 'foogallery' )
169
						),
170
						'row_data'=> array(
171
							'data-foogallery-change-selector' => 'input',
172
							'data-foogallery-value-selector' => 'input:checked',
173
							'data-foogallery-preview' => 'shortcode'
174
						)
175
					),
176
					array(
177
						'id'      => 'columns',
178
						'section' => __( 'General', 'foogallery' ),
179
						'title'   => __('Max Columns', 'foogallery'),
180
						'desc' => __('The maximum number of thumbnail columns to display. * This amount is automatically reduced on small screen sizes.', 'foogallery'),
181
						'default' => 'foogrid-cols-4',
182
						'type'    => 'select',
183
						'choices' => array(
184
							'foogrid-cols-2' => __( '2 Columns', 'foogallery' ),
185
							'foogrid-cols-3' => __( '3 Columns', 'foogallery' ),
186
							'foogrid-cols-4' => __( '4 Columns', 'foogallery' ),
187
							'foogrid-cols-5' => __( '5 Columns', 'foogallery' ),
188
							'foogrid-cols-6' => __( '6 Columns', 'foogallery' ),
189
							'foogrid-cols-7' => __( '7 Columns', 'foogallery' ),
190
							'foogrid-cols-8' => __( '8 Columns', 'foogallery' )
191
						),
192
						'row_data'=> array(
193
							'data-foogallery-change-selector' => 'select',
194
							'data-foogallery-value-selector' => 'option:selected',
195
							'data-foogallery-preview' => 'class'
196
						)
197
					),
198
					array(
199
						'id'      => 'captions',
200
						'section' => __( 'General', 'foogallery' ),
201
						'title'   => __('Stage Caption', 'foogallery'),
202
						'desc' => __('The position of caption in the stage or no captions at all. * The caption will automatically switch to below the item on small screen sizes.', 'foogallery'),
203
						'default' => 'foogrid-caption-below',
204
						'type'    => 'radio',
205
						'spacer'  => '<span class="spacer"></span>',
206
						'choices' => array(
207
							'foogrid-caption-below' => __( 'Below', 'foogallery' ),
208
							'foogrid-caption-right' => __( 'Right', 'foogallery' ),
209
							'' => __( 'None', 'foogallery' )
210
						),
211
						'row_data'=> array(
212
							'data-foogallery-change-selector' => 'input',
213
							'data-foogallery-value-selector' => 'input:checked',
214
							'data-foogallery-preview' => 'class'
215
						)
216
					),
217
					array(
218
						'id' => 'scroll',
219
						'section' => __( 'General', 'foogallery' ),
220
						'title' => __('Scroll', 'foogallery'),
221
						'desc' => __('Whether the page is scrolled to the selected item.', 'foogallery'),
222
						'default' => 'yes',
223
						'type'    => 'radio',
224
						'spacer'  => '<span class="spacer"></span>',
225
						'choices' => array(
226
							'yes' => __( 'Yes', 'foogallery' ),
227
							'no' => __( 'No', 'foogallery' )
228
						),
229
						'row_data'=> array(
230
							'data-foogallery-change-selector' => 'input',
231
							'data-foogallery-value-selector' => 'input:checked',
232
							'data-foogallery-preview' => 'shortcode'
233
						)
234
					),
235
					array(
236
						'id' => 'scroll_smooth',
237
						'section' => __( 'General', 'foogallery' ),
238
						'title' => __('Smooth Scroll', 'foogallery'),
239
						'desc' => __('Whether or not to perform a smooth scrolling animation to the selected item.', 'foogallery'),
240
						'default' => 'yes',
241
						'type'    => 'radio',
242
						'spacer'  => '<span class="spacer"></span>',
243
						'choices' => array(
244
							'yes' => __( 'Yes', 'foogallery' ),
245
							'no' => __( 'No', 'foogallery' )
246
						),
247
						'row_data'=> array(
248
							'data-foogallery-change-selector' => 'input',
249
							'data-foogallery-value-selector' => 'input:checked',
250
							'data-foogallery-preview' => 'shortcode'
251
						)
252
					),
253
					array(
254
						'id' => 'scroll_offset',
255
						'section' => __( 'General', 'foogallery' ),
256
						'title' => __('Scroll Offset', 'foogallery'),
257
						'desc' => __('The amount to offset scrolling by. * This can be used to counter fixed headers.', 'foogallery'),
258
						'class'   => 'small-text',
259
						'type' => 'number',
260
						'default' => 0,
261
						'row_data'=> array(
262
							'data-foogallery-change-selector' => 'input',
263
							'data-foogallery-value-selector' => 'input',
264
							'data-foogallery-preview' => 'shortcode'
265
						)
266
					),
267
				)
268
			);
269
270
			return $gallery_templates;
271
		}
272
273
		/**
274
		 * Add the required data options if needed
275
		 *
276
		 * @param $options
277
		 * @param $gallery    FooGallery
278
		 *
279
		 * @param $attributes array
280
		 *
281
		 * @return array
282
		 */
283
		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...
284
			$loop = foogallery_gallery_template_setting( 'loop', 'yes' ) === 'yes';
285
			$scroll = foogallery_gallery_template_setting( 'transition', 'yes' ) === 'yes';
286
			$scroll_smooth = foogallery_gallery_template_setting( 'transition', 'yes' ) === 'yes';
287
			$scroll_offset = foogallery_gallery_template_setting( 'scroll_offset', 0 );
288
289
			$options['template']['loop'] = $loop;
290
			$options['template']['scroll'] = $scroll;
291
			$options['template']['scroll_smooth'] = $scroll_smooth;
292
			$options['template']['scroll_offset'] = intval( $scroll_offset );
293
294
			return $options;
295
		}
296
297
		/**
298
		 * Override specific settings so that the gallery template will always work
299
		 *
300
		 * @param $settings
301
		 * @param $post_id
302
		 * @param $form_data
303
		 *
304
		 * @return mixed
305
		 */
306
		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...
307
			return $settings;
308
		}
309
310
		/**
311
		 * Build up a arguments used in the preview of the gallery
312
		 * @param $args
313
		 * @param $post_data
314
		 *
315
		 * @return mixed
316
		 */
317
		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...
318
			$args['thumbnail_width'] = $post_data[FOOGALLERY_META_SETTINGS]['foogridpro_thumbnail_size']['width'];
319
			$args['thumbnail_height'] = $post_data[FOOGALLERY_META_SETTINGS]['foogridpro_thumbnail_size']['height'];
320
			$args['thumbnail_crop'] = isset( $post_data[FOOGALLERY_META_SETTINGS]['foogridpro_thumbnail_size']['crop'] ) ? '1' : '0';
321
			return $args;
322
		}
323
324
		/**
325
		 * Builds thumb dimensions from arguments
326
		 *
327
		 * @param array $dimensions
328
		 * @param array $arguments
329
		 *
330
		 * @return mixed
331
		 */
332
		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...
333
            if ( array_key_exists( 'thumbnail_height', $arguments) ) {
334
                return array(
335
                    'height' => intval($arguments['thumbnail_height']),
336
                    'width' => intval($arguments['thumbnail_width']),
337
                    'crop' => $arguments['thumbnail_crop'] === '1'
338
                );
339
            }
340
            return null;
341
		}
342
343
		/**
344
		 * Get the thumb dimensions arguments saved for the gallery for this gallery template
345
		 *
346
		 * @param array $dimensions
347
		 * @param FooGallery $foogallery
348
		 *
349
		 * @return mixed
350
		 */
351
		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...
352
			$dimensions = $foogallery->get_meta( 'foogridpro_thumbnail_size', false );
353
			return $dimensions;
354
		}
355
356
        /**
357
         * Display a message if the FooGrid extension is also installed
358
         */
359
		function display_foogrid_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...
360
		    if ( class_exists('FooGrid_Template_FooGallery_Extension') ) {
361
                ?>
362
                <div class="notice error">
363
                    <p>
364
                        <strong><?php _e('FooGrid Extension Redundant!', 'foogallery'); ?></strong><br/>
365
                        <?php _e('You have both FooGallery PRO and the FooGrid extension activated. FooGallery PRO includes the Grid PRO gallery template, which makes the FooGrid extension redundant.', 'foogallery'); ?>
366
                        <br/>
367
                        <?php _e('Please edit all galleries that use the FooGrid gallery template and change them to use the Grid PRO gallery template. Once this is done, you can delete the FooGrid extension.', 'foogallery'); ?>
368
                        <br/>
369
                    </p>
370
                </div>
371
                <?php
372
            }
373
        }
374
375
        /**
376
         * Build up the arguments needed for rendering this gallery template
377
         *
378
         * @param $args
379
         * @return array
380
         */
381
        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...
382
            $args = foogallery_gallery_template_setting( 'thumbnail_size', array() );
383
            $args['link'] = foogallery_gallery_template_setting( 'thumbnail_link', 'image' );
384
385
            return $args;
386
        }
387
	}
388
}