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 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
if ( !class_exists( 'FooGallery_Default_Gallery_Template' ) ) {
4
5
	define('FOOGALLERY_DEFAULT_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ ));
6
7
	class FooGallery_Default_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
14
			add_action( 'foogallery_located_template-default', array( $this, 'enqueue_dependencies' ) );
15
16
			add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) );
17
18
			//build up any preview arguments
19
			add_filter( 'foogallery_preview_arguments-default', array( $this, 'preview_arguments' ), 10, 2 );
20
21
			//build up the thumb dimensions from some arguments
22
			add_filter( 'foogallery_calculate_thumbnail_dimensions-default', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 );
23
24
			//build up the thumb dimensions on save
25
			add_filter( 'foogallery_template_thumbnail_dimensions-default', array( $this, 'get_thumbnail_dimensions' ), 10, 2 );
26
27
			//build up the arguments needed for rendering this template
28
			add_filter( 'foogallery_gallery_template_arguments-default', array( $this, 'build_gallery_template_arguments' ) );
29
		}
30
31
		/**
32
		 * Register myself so that all associated JS and CSS files can be found and automatically included
33
		 * @param $extensions
34
		 *
35
		 * @return array
36
		 */
37
		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...
38
			$extensions[] = __FILE__;
39
			return $extensions;
40
		}
41
42
		/**
43
		 * Add our gallery template to the list of templates available for every gallery
44
		 * @param $gallery_templates
45
		 *
46
		 * @return array
47
		 */
48
		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...
49
			$gallery_templates[] = array(
50
				'slug'        => 'default',
51
				'name'        => __( 'Responsive Image Gallery', 'foogallery' ),
52
				'preview_support' => true,
53
				'common_fields_support' => true,
54
				'paging_support' => true,
55
				'lazyload_support' => true,
56
				'mandatory_classes' => 'fg-default',
57
				'thumbnail_dimensions' => true,
58
				'fields'	  => array(
59
                    array(
60
                        'id'      => 'thumbnail_dimensions',
61
                        'title'   => __( 'Thumbnail Size', 'foogallery' ),
62
                        'desc'    => __( 'Choose the size of your thumbnails.', 'foogallery' ),
63
                        'section' => __( 'General', 'foogallery' ),
64
                        'type'    => 'thumb_size_no_crop',
65
                        'default' => array(
66
                            'width' => get_option( 'thumbnail_size_w' ),
67
                            'height' => get_option( 'thumbnail_size_h' ),
68
                        ),
69
						'row_data'=> array(
70
                            'data-foogallery-change-selector' => 'input',
71
							'data-foogallery-preview' => 'shortcode'
72
						)
73
                    ),
74
                    array(
75
                        'id'      => 'thumbnail_link',
76
                        'title'   => __( 'Link To', 'foogallery' ),
77
                        'section' => __( 'General', 'foogallery' ),
78
                        'default' => 'image',
79
                        'type'    => 'thumb_link',
80
                        'desc'	  => __( 'You can choose to link each thumbnail to the full size image, the image\'s attachment page, a custom URL, or you can choose to not link to anything.', 'foogallery' ),
81
                    ),
82
					array(
83
						'id'      => 'lightbox',
84
						'title'   => __( 'Lightbox', 'foogallery' ),
85
						'desc'    => __( 'Choose which lightbox you want to use. The lightbox will generally only work if you set the thumbnail link to "Full Size Image".', 'foogallery' ),
86
                        'section' => __( 'General', 'foogallery' ),
87
						'type'    => 'lightbox',
88
                        'default' => 'none',
89
						'row_data'=> array(
90
							'data-foogallery-change-selector' => 'select'
91
						)
92
					),
93
					array(
94
						'id'      => 'lightbox_foobox_help',
95
						'title'   => __( 'FooBox Help', 'foogallery' ),
96
						'desc'    => __( 'The FooBox lightbox is a separate plugin.', 'foogallery' ),
97
						'section' => __( 'General', 'foogallery' ),
98
						'type'    => 'help',
99
						'row_data'=> array(
100
							'data-foogallery-hidden' => true,
101
							'data-foogallery-show-when-field' => 'lightbox',
102
							'data-foogallery-show-when-field-value' => 'foobox'
103
						)
104
					),
105
					array(
106
						'id'      => 'spacing',
107
						'title'   => __( 'Spacing', 'foogallery' ),
108
						'desc'    => __( 'The spacing or gap between thumbnails in the gallery.', 'foogallery' ),
109
                        'section' => __( 'General', 'foogallery' ),
110
						'type'    => 'select',
111
						'default' => 'fg-gutter-10',
112
						'choices' => array(
113
							'fg-gutter-0' => __( 'none', 'foogallery' ),
114
							'fg-gutter-5' => __( '5 pixels', 'foogallery' ),
115
							'fg-gutter-10' => __( '10 pixels', 'foogallery' ),
116
							'fg-gutter-15' => __( '15 pixels', 'foogallery' ),
117
							'fg-gutter-20' => __( '20 pixels', 'foogallery' ),
118
							'fg-gutter-25' => __( '25 pixels', 'foogallery' ),
119
						),
120
                        'row_data'=> array(
121
                            'data-foogallery-change-selector' => 'select',
122
							'data-foogallery-preview' => 'class'
123
                        )
124
					),
125
					array(
126
						'id'      => 'alignment',
127
						'title'   => __( 'Alignment', 'foogallery' ),
128
						'desc'    => __( 'The horizontal alignment of the thumbnails inside the gallery.', 'foogallery' ),
129
                        'section' => __( 'General', 'foogallery' ),
130
						'default' => 'fg-center',
131
						'type'    => 'radio',
132
						'spacer'  => '<span class="spacer"></span>',
133
						'choices' => array(
134
							'fg-left' => __( 'Left', 'foogallery' ),
135
							'fg-center' => __( 'Center', 'foogallery' ),
136
							'fg-right' => __( 'Right', 'foogallery' ),
137
						),
138
                        'row_data'=> array(
139
                            'data-foogallery-change-selector' => 'input:radio',
140
							'data-foogallery-preview' => 'class'
141
                        )
142
					)
143
				)
144
			);
145
146
			return $gallery_templates;
147
		}
148
149
		/**
150
		 * Enqueue scripts that the default gallery template relies on
151
		 */
152
		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...
153
			//enqueue core files
154
			foogallery_enqueue_core_gallery_template_style();
155
			foogallery_enqueue_core_gallery_template_script();
156
		}
157
158
		/**
159
		 * Build up a arguments used in the preview of the gallery
160
		 * @param $args
161
		 * @param $post_data
162
		 *
163
		 * @return mixed
164
		 */
165
		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...
166
			$args['thumbnail_dimensions'] = $post_data[FOOGALLERY_META_SETTINGS]['default_thumbnail_dimensions'];
167
			return $args;
168
		}
169
170
		/**
171
		 * Builds thumb dimensions from arguments
172
		 *
173
		 * @param array $dimensions
174
		 * @param array $arguments
175
		 *
176
		 * @return mixed
177
		 */
178
		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...
179
            if ( array_key_exists( 'thumbnail_dimensions', $arguments) ) {
180
                return array(
181
                    'height' => intval($arguments['thumbnail_dimensions']['height']),
182
                    'width' => intval($arguments['thumbnail_dimensions']['width']),
183
                    'crop' => '1'
184
                );
185
            }
186
            return null;
187
		}
188
189
		/**
190
		 * Get the thumb dimensions arguments saved for the gallery for this gallery template
191
		 *
192
		 * @param array $dimensions
193
		 * @param FooGallery $foogallery
194
		 *
195
		 * @return mixed
196
		 */
197
		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...
198
			$dimensions = $foogallery->get_meta( 'default_thumbnail_dimensions', array(
199
				'width' => get_option( 'thumbnail_size_w' ),
200
				'height' => get_option( 'thumbnail_size_h' )
201
			) );
202
			$dimensions['crop'] = true;
203
			return $dimensions;
204
		}
205
206
        /**
207
         * Build up the arguments needed for rendering this gallery template
208
         *
209
         * @param $args
210
         * @return array
211
         */
212
		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...
213
            $args = foogallery_gallery_template_setting( 'thumbnail_dimensions', array() );
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
214
            $args['crop'] = '1'; //we now force thumbs to be cropped
215
            $args['link'] = foogallery_gallery_template_setting( 'thumbnail_link', 'image' );
216
217
            return $args;
218
        }
219
	}
220
}