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

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
if ( !class_exists( 'FooGallery_Justified_Gallery_Template' ) ) {
4
5
	define('FOOGALLERY_JUSTIFIED_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ ));
6
7
	class FooGallery_Justified_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
			add_filter( 'foogallery_template_thumbnail_dimensions-justified', array( $this, 'get_thumbnail_dimensions' ), 10, 2 );
15
16
			//add extra fields to the templates
17
			add_filter( 'foogallery_override_gallery_template_fields-justified', array( $this, 'add_common_thumbnail_fields' ), 10, 2 );
18
19
			add_action( 'foogallery_located_template-justified', array( $this, 'enqueue_dependencies' ) );
20
21
			//add the data options needed for justified
22
			add_filter( 'foogallery_build_container_data_options-justified', array( $this, 'add_justified_options' ), 10, 3 );
23
24
			//build up any preview arguments
25
			add_filter( 'foogallery_preview_arguments-justified', array( $this, 'preview_arguments' ), 10, 2 );
26
27
			//build up the thumb dimensions from some arguments
28
			add_filter( 'foogallery_calculate_thumbnail_dimensions-justified', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 );
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'        => 'justified',
51
                'name'        => __( 'Justified Gallery', 'foogallery' ),
52
                'lazyload_support' => true,
53
                'fields'	  => array(
54
                    array(
55
                        'id'      => 'thumb_height',
56
                        'title'   => __( 'Thumb Height', 'foogallery' ),
57
                        'desc'    => __( 'Choose the height of your thumbnails. Thumbnails will be generated on the fly and cached once generated', 'foogallery' ),
58
                        'section' => __( 'General', 'foogallery' ),
59
                        'type'    => 'number',
60
                        'class'   => 'small-text',
61
                        'default' => 250,
62
                        'step'    => '10',
63
                        'min'     => '0',
64
						'row_data'=> array(
65
							'data-foogallery-preview' => 'shortcode'
66
						)
67
                    ),
68
                    array(
69
                        'id'      => 'row_height',
70
                        'title'   => __( 'Row Height', 'foogallery' ),
71
                        'desc'    => __( 'The preferred height of your gallery rows. This can be different from the thumbnail height', 'foogallery' ),
72
                        'section' => __( 'General', 'foogallery' ),
73
                        'type'    => 'number',
74
                        'class'   => 'small-text',
75
                        'default' => 150,
76
                        'step'    => '10',
77
                        'min'     => '0',
78
						'row_data'=> array(
79
							'data-foogallery-change-selector' => 'input',
80
							'data-foogallery-value-selector' => 'input',
81
							'data-foogallery-preview' => 'data',
82
						)
83
                    ),
84
                    array(
85
                        'id'      => 'max_row_height',
86
                        'title'   => __( 'Max Row Height', 'foogallery' ),
87
                        'desc'    => __( 'A number (e.g 200) which specifies the maximum row height in pixels. A negative value for no limits. Alternatively, use a percentage (e.g. 200% which means that the row height cannot exceed 2 * rowHeight)', 'foogallery' ),
88
                        'section' => __( 'General', 'foogallery' ),
89
                        'type'    => 'text',
90
                        'class'   => 'small-text',
91
                        'default' => '200%',
92
						'row_data'=> array(
93
							'data-foogallery-change-selector' => 'input',
94
							'data-foogallery-value-selector' => 'input',
95
							'data-foogallery-preview' => 'data',
96
						)
97
                    ),
98
                    array(
99
                        'id'      => 'margins',
100
                        'title'   => __( 'Margins', 'foogallery' ),
101
                        'desc'    => __( 'The spacing between your thumbnails.', 'foogallery' ),
102
						'section' => __( 'General', 'foogallery' ),
103
                        'type'    => 'number',
104
                        'class'   => 'small-text',
105
                        'default' => 1,
106
                        'step'    => '1',
107
                        'min'     => '0',
108
						'row_data'=> array(
109
							'data-foogallery-change-selector' => 'input',
110
							'data-foogallery-value-selector' => 'input',
111
							'data-foogallery-preview' => 'data',
112
						)
113
                    ),
114
                    array(
115
                        'id'      => 'thumbnail_link',
116
                        'title'   => __( 'Thumbnail Link', 'foogallery' ),
117
                        'section' => __( 'General', 'foogallery' ),
118
                        'default' => 'image' ,
119
                        'type'    => 'thumb_link',
120
                        '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' ),
121
                    ),
122
                    array(
123
                        'id'      => 'lightbox',
124
                        'title'   => __( 'Lightbox', 'foogallery' ),
125
                        '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' ),
126
                        'section' => __( 'General', 'foogallery' ),
127
                        'type'    => 'lightbox',
128
                    ),
129
                ),
130
			);
131
132
			return $gallery_templates;
133
		}
134
135
		/**
136
		 * Get the thumb dimensions arguments saved for the gallery for this gallery template
137
		 *
138
		 * @param array $dimensions
139
		 * @param FooGallery $foogallery
140
		 *
141
		 * @return mixed
142
		 */
143
		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...
144
			$height = $foogallery->get_meta( 'justified_thumb_height', false );
145
			return array(
146
				'height' => intval( $height ),
147
				'width'  => 0,
148
				'crop'   => false
149
			);
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
			return apply_filters( 'foogallery_gallery_template_common_thumbnail_fields', $fields );
163
		}
164
165
		/**
166
		 * Enqueue scripts that the default gallery template relies on
167
		 */
168
		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...
169
			//enqueue core files
170
			foogallery_enqueue_core_gallery_template_style();
171
			foogallery_enqueue_core_gallery_template_script();
172
		}
173
174
		/**
175
		 * Add the required justified options if needed
176
		 *
177
		 * @param $options
178
		 * @param $gallery    FooGallery
179
		 *
180
		 * @param $attributes array
181
		 *
182
		 * @return array
183
		 */
184
		function add_justified_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...
185
186
			$row_height = foogallery_gallery_template_setting( 'row_height', '150' );
187
			$max_row_height = foogallery_gallery_template_setting( 'max_row_height', '200%' );
188
			if ( strpos( $max_row_height, '%' ) === false ) {
189
				$max_row_height = intval( $max_row_height );
190
			}
191
			$margins = foogallery_gallery_template_setting( 'margins', '1' );
192
193
			$options['template']['rowHeight'] = intval($row_height);
194
			$options['template']['maxRowHeight'] = $max_row_height;
195
			$options['template']['margins'] = intval($margins);
196
197
			return $options;
198
		}
199
200
		/**
201
		 * Build up a arguments used in the preview of the gallery
202
		 * @param $args
203
		 * @param $post_data
204
		 *
205
		 * @return mixed
206
		 */
207
		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...
208
			$args['thumbnail_height'] = $post_data['foogallery_settings']['justified_thumb_height'];
209
210
			return $args;
211
		}
212
213
		/**
214
		 * Builds thumb dimensions from arguments
215
		 *
216
		 * @param array $dimensions
217
		 * @param array $arguments
218
		 *
219
		 * @return mixed
220
		 */
221
		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...
222
			return array(
223
				'height' => intval( $arguments['thumbnail_height'] ),
224
				'width'  => 0,
225
				'crop'   => false
226
			);
227
		}
228
	}
229
}