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 ( f00e4a...d725c4 )
by Brad
03:10
created

display_foogrid_notice()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 0
dl 0
loc 15
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
61
		/**
62
		 * Register myself so that all associated JS and CSS files can be found and automatically included
63
		 * @param $extensions
64
		 *
65
		 * @return array
66
		 */
67
		function register_myself( $extensions ) {
68
			$extensions[] = __FILE__;
69
			return $extensions;
70
		}
71
72
		/**
73
		 * Enqueue any script or stylesheet file dependencies that your gallery template relies on
74
		 *
75
		 * @param  $gallery
76
		 */
77
		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...
78
            foogallery_enqueue_core_gallery_template_style();
79
            foogallery_enqueue_core_gallery_template_script();
80
		}
81
82
		/**
83
		 * Add our gallery template to the list of templates available for every gallery
84
		 * @param $gallery_templates
85
		 *
86
		 * @return array
87
		 */
88
		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...
89
90
			$gallery_templates[] = array(
91
				'slug'        => 'foogridpro',
92
				'name'        => __( 'Grid PRO', 'foogallery'),
93
                'preview_support' => true,
94
                'common_fields_support' => true,
95
                'lazyload_support' => true,
96
                'paging_support' => true,
97
                'thumbnail_dimensions' => true,
98
				'mandatory_classes' => 'foogrid',
99
				'fields'	  => array(
100
					array(
101
						'id'      => 'thumbnail_size',
102
						'title'   => __('Thumbnail Size', 'foogallery'),
103
						'desc'    => __('Choose the size of your thumbs.', 'foogallery'),
104
						'type'    => 'thumb_size',
105
						'default' => array(
106
							'width' => 320,
107
							'height' => 180,
108
							'crop' => true
109
						),
110
						'row_data'=> array(
111
							'data-foogallery-change-selector' => 'input',
112
							'data-foogallery-preview' => 'shortcode'
113
						)
114
					),
115
					array(
116
						'id'      => 'thumbnail_link',
117
						'title'   => __('Thumbnail Link', 'foogallery'),
118
						'default' => 'image' ,
119
						'type'    => 'thumb_link',
120
						'desc'	  => __('You can choose to either link each thumbnail to the full size image or to the image\'s attachment page.', 'foogallery')
121
					),
122
//					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...
123
//						'id'      => 'theme',
124
//						'section' => __( 'General', 'foogallery' ),
125
//						'title' => __('Theme', 'foogallery'),
126
//						'desc' => __('The theme for the content viewer.', 'foogallery'),
127
//						'default' => '',
128
//						'type'    => 'radio',
129
//						'spacer'  => '<span class="spacer"></span>',
130
//						'choices' => array(
131
//							'' => __( 'Dark (Default)', 'foogallery' ),
132
//							'foogrid-light' => __( 'Light', 'foogallery' )
133
//						)
134
//					),
135
					array(
136
						'id'      => 'transition',
137
						'section' => __( 'General', 'foogallery' ),
138
						'title'   => __('Transition', 'foogallery'),
139
						'desc' => __('Transition type to use switching between items, or no transitions at all.', 'foogallery'),
140
						'default' => 'foogrid-transition-fade',
141
						'type'    => 'radio',
142
						'spacer'  => '<span class="spacer"></span>',
143
						'choices' => array(
144
							'foogrid-transition-fade' => __( 'Fade', 'foogallery' ),
145
							'foogrid-transition-horizontal' => __( 'Horizontal', 'foogallery' ),
146
							'foogrid-transition-vertical' => __( 'Vertical', 'foogallery' ),
147
							'' => __( 'None', 'foogallery' )
148
						),
149
						'row_data'=> array(
150
							'data-foogallery-change-selector' => 'input',
151
							'data-foogallery-value-selector' => 'input:checked',
152
							'data-foogallery-preview' => 'class'
153
						)
154
					),
155
					array(
156
						'id' => 'loop',
157
						'section' => __( 'General', 'foogallery' ),
158
						'title' => __('Loop', 'foogallery'),
159
						'desc' => __('Whether the slider should loop (i.e. the first slide goes to the last, the last slide goes to the first).', 'foogallery'),
160
						'default' => 'yes',
161
						'type'    => 'radio',
162
						'spacer'  => '<span class="spacer"></span>',
163
						'choices' => array(
164
							'yes' => __( 'Yes', 'foogallery' ),
165
							'no' => __( 'No', 'foogallery' )
166
						),
167
						'row_data'=> array(
168
							'data-foogallery-change-selector' => 'input',
169
							'data-foogallery-value-selector' => 'input:checked',
170
							'data-foogallery-preview' => 'shortcode'
171
						)
172
					),
173
					array(
174
						'id'      => 'columns',
175
						'section' => __( 'General', 'foogallery' ),
176
						'title'   => __('Max Columns', 'foogallery'),
177
						'desc' => __('The maximum number of thumbnail columns to display. * This amount is automatically reduced on small screen sizes.', 'foogallery'),
178
						'default' => 'foogrid-cols-4',
179
						'type'    => 'select',
180
						'choices' => array(
181
							'foogrid-cols-2' => __( '2 Columns', 'foogallery' ),
182
							'foogrid-cols-3' => __( '3 Columns', 'foogallery' ),
183
							'foogrid-cols-4' => __( '4 Columns', 'foogallery' ),
184
							'foogrid-cols-5' => __( '5 Columns', 'foogallery' ),
185
							'foogrid-cols-6' => __( '6 Columns', 'foogallery' ),
186
							'foogrid-cols-7' => __( '7 Columns', 'foogallery' ),
187
							'foogrid-cols-8' => __( '8 Columns', 'foogallery' )
188
						),
189
						'row_data'=> array(
190
							'data-foogallery-change-selector' => 'select',
191
							'data-foogallery-value-selector' => 'option:selected',
192
							'data-foogallery-preview' => 'class'
193
						)
194
					),
195
					array(
196
						'id'      => 'captions',
197
						'section' => __( 'General', 'foogallery' ),
198
						'title'   => __('Stage Caption', 'foogallery'),
199
						'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'),
200
						'default' => 'foogrid-caption-below',
201
						'type'    => 'radio',
202
						'spacer'  => '<span class="spacer"></span>',
203
						'choices' => array(
204
							'foogrid-caption-below' => __( 'Below', 'foogallery' ),
205
							'foogrid-caption-right' => __( 'Right', 'foogallery' ),
206
							'' => __( 'None', 'foogallery' )
207
						),
208
						'row_data'=> array(
209
							'data-foogallery-change-selector' => 'input',
210
							'data-foogallery-value-selector' => 'input:checked',
211
							'data-foogallery-preview' => 'class'
212
						)
213
					),
214
					array(
215
						'id' => 'scroll',
216
						'section' => __( 'General', 'foogallery' ),
217
						'title' => __('Scroll', 'foogallery'),
218
						'desc' => __('Whether the page is scrolled to the selected item.', 'foogallery'),
219
						'default' => 'yes',
220
						'type'    => 'radio',
221
						'spacer'  => '<span class="spacer"></span>',
222
						'choices' => array(
223
							'yes' => __( 'Yes', 'foogallery' ),
224
							'no' => __( 'No', 'foogallery' )
225
						),
226
						'row_data'=> array(
227
							'data-foogallery-change-selector' => 'input',
228
							'data-foogallery-value-selector' => 'input:checked',
229
							'data-foogallery-preview' => 'shortcode'
230
						)
231
					),
232
					array(
233
						'id' => 'scroll_smooth',
234
						'section' => __( 'General', 'foogallery' ),
235
						'title' => __('Smooth Scroll', 'foogallery'),
236
						'desc' => __('Whether or not to perform a smooth scrolling animation to the selected item.', 'foogallery'),
237
						'default' => 'yes',
238
						'type'    => 'radio',
239
						'spacer'  => '<span class="spacer"></span>',
240
						'choices' => array(
241
							'yes' => __( 'Yes', 'foogallery' ),
242
							'no' => __( 'No', 'foogallery' )
243
						),
244
						'row_data'=> array(
245
							'data-foogallery-change-selector' => 'input',
246
							'data-foogallery-value-selector' => 'input:checked',
247
							'data-foogallery-preview' => 'shortcode'
248
						)
249
					),
250
					array(
251
						'id' => 'scroll_offset',
252
						'section' => __( 'General', 'foogallery' ),
253
						'title' => __('Scroll Offset', 'foogallery'),
254
						'desc' => __('The amount to offset scrolling by. * This can be used to counter fixed headers.', 'foogallery'),
255
						'class'   => 'small-text',
256
						'type' => 'number',
257
						'default' => 0,
258
						'row_data'=> array(
259
							'data-foogallery-change-selector' => 'input',
260
							'data-foogallery-value-selector' => 'input',
261
							'data-foogallery-preview' => 'shortcode'
262
						)
263
					),
264
				)
265
			);
266
267
			return $gallery_templates;
268
		}
269
270
		/**
271
		 * Add the required data options if needed
272
		 *
273
		 * @param $options
274
		 * @param $gallery    FooGallery
275
		 *
276
		 * @param $attributes array
277
		 *
278
		 * @return array
279
		 */
280
		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...
281
			$loop = foogallery_gallery_template_setting( 'loop', 'yes' ) === 'yes';
282
			$scroll = foogallery_gallery_template_setting( 'transition', 'yes' ) === 'yes';
283
			$scroll_smooth = foogallery_gallery_template_setting( 'transition', 'yes' ) === 'yes';
284
			$scroll_offset = foogallery_gallery_template_setting( 'scroll_offset', 0 );
285
286
			$options['template']['loop'] = $loop;
287
			$options['template']['scroll'] = $scroll;
288
			$options['template']['scroll_smooth'] = $scroll_smooth;
289
			$options['template']['scroll_offset'] = intval( $scroll_offset );
290
291
			return $options;
292
		}
293
294
		/**
295
		 * Override specific settings so that the gallery template will always work
296
		 *
297
		 * @param $settings
298
		 * @param $post_id
299
		 * @param $form_data
300
		 *
301
		 * @return mixed
302
		 */
303
		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...
304
			return $settings;
305
		}
306
307
		/**
308
		 * Build up a arguments used in the preview of the gallery
309
		 * @param $args
310
		 * @param $post_data
311
		 *
312
		 * @return mixed
313
		 */
314
		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...
315
			$args['thumbnail_width'] = $post_data[FOOGALLERY_META_SETTINGS]['foogridpro_thumbnail_size']['width'];
316
			$args['thumbnail_height'] = $post_data[FOOGALLERY_META_SETTINGS]['foogridpro_thumbnail_size']['height'];
317
			$args['thumbnail_crop'] = isset( $post_data[FOOGALLERY_META_SETTINGS]['foogridpro_thumbnail_size']['crop'] ) ? '1' : '0';
318
			return $args;
319
		}
320
321
		/**
322
		 * Builds thumb dimensions from arguments
323
		 *
324
		 * @param array $dimensions
325
		 * @param array $arguments
326
		 *
327
		 * @return mixed
328
		 */
329
		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...
330
            if ( array_key_exists( 'thumbnail_height', $arguments) ) {
331
                return array(
332
                    'height' => intval($arguments['thumbnail_height']),
333
                    'width' => intval($arguments['thumbnail_width']),
334
                    'crop' => $arguments['thumbnail_crop'] === '1'
335
                );
336
            }
337
            return null;
338
		}
339
340
		/**
341
		 * Get the thumb dimensions arguments saved for the gallery for this gallery template
342
		 *
343
		 * @param array $dimensions
344
		 * @param FooGallery $foogallery
345
		 *
346
		 * @return mixed
347
		 */
348
		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...
349
			$dimensions = $foogallery->get_meta( 'foogridpro_thumbnail_size', false );
350
			return $dimensions;
351
		}
352
353
        /**
354
         * Display a message if the FooGrid extension is also installed
355
         */
356
		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...
357
		    if ( class_exists('FooGrid_Template_FooGallery_Extension') ) {
358
                ?>
359
                <div class="notice error">
360
                    <p>
361
                        <strong><?php _e('FooGrid Extension Redundant!', 'foogallery'); ?></strong><br/>
362
                        <?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'); ?>
363
                        <br/>
364
                        <?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'); ?>
365
                        <br/>
366
                    </p>
367
                </div>
368
                <?php
369
            }
370
        }
371
	}
372
}