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 — master ( bb6361...a2a740 )
by Brad
04:28
created

FooGallery_Paging::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Class used to handle paging for gallery templates
4
 */
5
if ( ! class_exists( 'FooGallery_Paging' ) ) {
6
7
	class FooGallery_Paging {
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
		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...
10
			if ( is_admin() ) {
11
				//add extra fields to the templates that support lazy loading
12
				add_filter( 'foogallery_override_gallery_template_fields', array( $this, 'add_paging_fields' ), 10, 2 );
13
14
				//build up any preview arguments
15
				add_filter( 'foogallery_preview_arguments', array( $this, 'preview_arguments' ), 10, 3 );
16
			}
17
18
			//adds the paging property to a FooGallery
19
			add_action( 'foogallery_located_template', array( $this, 'determine_paging' ), 10, 2 );
20
21
			//add the paging attributes to the gallery container
22
			add_filter( 'foogallery_build_container_data_options', array( $this, 'add_paging_options' ), 10, 3 );
23
		}
24
25
		/**
26
		 * Add paging fields to the gallery template
27
		 *
28
		 * @uses "foogallery_override_gallery_template_fields"
29
		 * @param $fields
30
		 * @param $template
31
		 *
32
		 * @return array
33
		 */
34
		function add_paging_fields( $fields, $template ) {
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...
35
			if ( $template && array_key_exists( 'paging_support', $template ) && true === $template['paging_support'] ) {
36
				$fields[] = array(
37
					'id'      => 'paging_type',
38
					'title'   => __( 'Paging Type', 'foogallery' ),
39
					'desc'    => __( 'Add paging to a large gallery.', 'foogallery' ),
40
					'section' => __( 'Paging', 'foogallery' ),
41
					'spacer'  => '<span class="spacer"></span>',
42
					'type'    => 'radio',
43
					'default' => '',
44
					'choices' => apply_filters( 'foogallery_gallery_template_paging_type_choices', array(
45
						''  => __( 'None', 'foogallery' ),
46
						'dots'   => __( 'Dots', 'foogallery' )
47
					) ),
48
					'row_data'=> array(
49
						'data-foogallery-change-selector' => 'input',
50
						'data-foogallery-preview' => 'shortcode',
51
						'data-foogallery-value-selector' => 'input:checked',
52
					)
53
				);
54
55
				$fields[] = array(
56
					'id'      => 'paging_size',
57
					'title'   => __( 'Page Size', 'foogallery' ),
58
					'desc'    => __( 'The size of your pages.', 'foogallery' ),
59
					'section' => __( 'Paging', 'foogallery' ),
60
					'type'    => 'number',
61
					'class'   => 'small-text',
62
					'default' => 20,
63
					'step'    => '1',
64
					'min'     => '0',
65
					'row_data'=> array(
66
						'data-foogallery-change-selector' => 'input',
67
						'data-foogallery-preview' => 'shortcode',
68
						'data-foogallery-hidden'                   => true,
69
						'data-foogallery-show-when-field'          => 'paging_type',
70
						'data-foogallery-show-when-field-operator' => '!==',
71
						'data-foogallery-show-when-field-value'    => '',
72
					)
73
				);
74
75
				$fields[] = array(
76
					'id'      => 'paging_position',
77
					'title'   => __( 'Position', 'foogallery' ),
78
					'desc'    => __( 'The position of the paging for either dots or pagination.', 'foogallery' ),
79
					'section' => __( 'Paging', 'foogallery' ),
80
					'spacer'  => '<span class="spacer"></span>',
81
					'type'    => 'radio',
82
					'default' => 'both',
83
					'choices' => apply_filters( 'foogallery_gallery_template_paging_position_choices', array(
84
						''  => __( 'None', 'foogallery' ),
85
						'top'   => __( 'Top', 'foogallery' ),
86
						'bottom'   => __( 'Bottom', 'foogallery' ),
87
						'both'   => __( 'Both', 'foogallery' )
88
					) ),
89
					'row_data'=> array(
90
						'data-foogallery-hidden' => true,
91
						'data-foogallery-show-when-field-operator' => 'regex',
92
						'data-foogallery-show-when-field' => 'paging_type',
93
						'data-foogallery-show-when-field-value' => 'dots|pagination',
94
						'data-foogallery-change-selector' => 'input',
95
						'data-foogallery-preview' => 'shortcode'
96
					)
97
				);
98
99
				$fields[] = array(
100
					'id'      => 'paging_theme',
101
					'title'   => __( 'Theme', 'foogallery' ),
102
					'desc'    => __( 'The theme used for paging.', 'foogallery' ),
103
					'section' => __( 'Paging', 'foogallery' ),
104
					'spacer'  => '<span class="spacer"></span>',
105
					'type'    => 'radio',
106
					'default' => 'fg-light',
107
					'choices' => apply_filters( 'foogallery_gallery_template_paging_position_choices', array(
108
						'fg-light'  => __( 'Light', 'foogallery' ),
109
						'fg-dark'   => __( 'Dark', 'foogallery' ),
110
					) ),
111
					'row_data'=> array(
112
						'data-foogallery-change-selector' => 'input',
113
						'data-foogallery-preview' => 'shortcode',
114
						'data-foogallery-hidden'                   => true,
115
						'data-foogallery-show-when-field'          => 'paging_type',
116
						'data-foogallery-show-when-field-operator' => '!==',
117
						'data-foogallery-show-when-field-value'    => '',
118
					)
119
				);
120
121
				$fields[] = array(
122
					'id'      => 'paging_scroll',
123
					'title'   => __( 'Scroll To Top', 'foogallery' ),
124
					'desc'    => __( 'Whether or not it should scroll to the top of the gallery when paging is changed.', 'foogallery' ),
125
					'section' => __( 'Paging', 'foogallery' ),
126
					'type'    => 'radio',
127
					'spacer'  => '<span class="spacer"></span>',
128
					'default' => 'true',
129
					'choices' => array(
130
						'true'  => __( 'Yes', 'foogallery' ),
131
						'false'  => __( 'No', 'foogallery' ),
132
					),
133
					'row_data'=> array(
134
						'data-foogallery-hidden' => true,
135
						'data-foogallery-show-when-field-operator' => 'regex',
136
						'data-foogallery-show-when-field' => 'paging_type',
137
						'data-foogallery-show-when-field-value' => 'dots|pagination',
138
						'data-foogallery-change-selector' => 'input',
139
						'data-foogallery-preview' => 'shortcode'
140
					)
141
				);
142
143
				$fields[] = array(
144
					'id'      => 'paging_limit',
145
					'title'   => __( 'Paging Limit', 'foogallery' ),
146
					'desc'    => __( 'The maximum number of page links to display for the gallery.', 'foogallery' ),
147
					'section' => __( 'Paging', 'foogallery' ),
148
					'type'    => 'number',
149
					'class'   => 'small-text',
150
					'default' => 5,
151
					'step'    => '1',
152
					'min'     => '0',
153
					'row_data'=> array(
154
						'data-foogallery-hidden' => true,
155
						'data-foogallery-show-when-field' => 'paging_type',
156
						'data-foogallery-show-when-field-value' => 'pagination',
157
						'data-foogallery-change-selector' => 'input',
158
						'data-foogallery-preview' => 'shortcode'
159
					)
160
				);
161
162
				$fields[] = array(
163
					'id'      => 'paging_showFirstLast',
164
					'title'   => __( 'First &amp; Last Buttons', 'foogallery' ),
165
					'desc'    => __( 'Whether or not to show the first &amp; last buttons for pagination.', 'foogallery' ),
166
					'section' => __( 'Paging', 'foogallery' ),
167
					'type'    => 'radio',
168
					'spacer'  => '<span class="spacer"></span>',
169
					'default' => 'true',
170
					'choices' => array(
171
						'true'  => __( 'Show', 'foogallery' ),
172
						'false'  => __( 'Hide', 'foogallery' ),
173
					),
174
					'row_data'=> array(
175
						'data-foogallery-hidden' => true,
176
						'data-foogallery-show-when-field' => 'paging_type',
177
						'data-foogallery-show-when-field-value' => 'pagination',
178
						'data-foogallery-change-selector' => 'input',
179
						'data-foogallery-preview' => 'shortcode'
180
					)
181
				);
182
183
				$fields[] = array(
184
					'id'      => 'paging_showPrevNext',
185
					'title'   => __( 'Prev &amp; Next Buttons', 'foogallery' ),
186
					'desc'    => __( 'Whether or not to show the previous &amp; next buttons for pagination.', 'foogallery' ),
187
					'section' => __( 'Paging', 'foogallery' ),
188
					'type'    => 'radio',
189
					'spacer'  => '<span class="spacer"></span>',
190
					'default' => 'true',
191
					'choices' => array(
192
						'true'  => __( 'Show', 'foogallery' ),
193
						'false'  => __( 'Hide', 'foogallery' ),
194
					),
195
					'row_data'=> array(
196
						'data-foogallery-hidden' => true,
197
						'data-foogallery-show-when-field' => 'paging_type',
198
						'data-foogallery-show-when-field-value' => 'pagination',
199
						'data-foogallery-change-selector' => 'input',
200
						'data-foogallery-preview' => 'shortcode'
201
					)
202
				);
203
204
				$fields[] = array(
205
					'id'      => 'paging_showPrevNextMore',
206
					'title'   => __( 'More Buttons', 'foogallery' ),
207
					'desc'    => __( 'Whether or not to show the previous &amp; next more buttons for pagination.', 'foogallery' ),
208
					'section' => __( 'Paging', 'foogallery' ),
209
					'type'    => 'radio',
210
					'spacer'  => '<span class="spacer"></span>',
211
					'default' => 'true',
212
					'choices' => array(
213
						'true'  => __( 'Show', 'foogallery' ),
214
						'false'  => __( 'Hide', 'foogallery' ),
215
					),
216
					'row_data'=> array(
217
						'data-foogallery-hidden' => true,
218
						'data-foogallery-show-when-field' => 'paging_type',
219
						'data-foogallery-show-when-field-value' => 'pagination',
220
						'data-foogallery-change-selector' => 'input',
221
						'data-foogallery-preview' => 'shortcode'
222
					)
223
				);
224
			}
225
226
			return $fields;
227
		}
228
229
		/**
230
		 * Determine if the gallery has paging enabled
231
		 *
232
		 * @param $foogallery FooGallery
233
		 */
234
		function determine_paging( $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...
235
			$template_data = foogallery_get_gallery_template( $foogallery->gallery_template );
236
237
			//check the template supports paging
238
			$paging = $template_data && array_key_exists( 'paging_support', $template_data ) && true === $template_data['paging_support'];
239
240
			$foogallery->paging = apply_filters( 'foogallery_paging', $paging, $foogallery );
241
		}
242
243
		/**
244
		 * Add the required paging options if needed
245
		 *
246
		 * @param $attributes array
247
		 * @param $gallery FooGallery
248
		 *
249
		 * @return array
250
		 */
251
		function add_paging_options($options, $gallery, $attributes) {
0 ignored issues
show
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...
252
			if ( isset( $gallery->paging ) && true === $gallery->paging) {
253
254
				//check if we have arguments from the shortcode and override the saved settings
255
				$paging = $this->get_foogallery_argument( $gallery, 'paging_type', 'paging', '' );
256
257
				if ( '' !== $paging ) {
258
					$paging_position = $this->get_foogallery_argument( $gallery, 'paging_position', 'paging_position', 'both' );
259
					$paging_theme    = $this->get_foogallery_argument( $gallery, 'paging_theme', 'paging_theme', 'fg-light' );
260
					$paging_size     = intval( $this->get_foogallery_argument( $gallery, 'paging_size', 'paging_size', '30' ) );
261
					$paging_scroll   = $this->get_foogallery_argument( $gallery, 'paging_scroll', 'paging_scroll', 'true' ) === 'true';
262
263
					//force bottom position for infinite and loadMore paging
264
					if ( 'infinite' === $paging || 'loadMore' === $paging ) {
265
						$paging_position = 'bottom';
266
					}
267
268
					$options['paging'] = array(
269
						'type'        => $paging,
270
						'theme'       => $paging_theme,
271
						'size'        => $paging_size,
272
						'position'    => $paging_position,
273
						'scrollToTop' => $paging_scroll
274
					);
275
276
					if ( 'pagination' === $paging ) {
277
						$options['paging']['limit'] = intval( $this->get_foogallery_argument( $gallery, 'paging_limit', 'paging_limit', '5' ) );;
278
						$options['paging']['showFirstLast'] = $this->get_foogallery_argument( $gallery, 'paging_showFirstLast', 'paging_showFirstLast', 'true' ) === 'true';;
279
						$options['paging']['showPrevNext'] = $this->get_foogallery_argument( $gallery, 'paging_showPrevNext', 'paging_showPrevNext', 'true' ) === 'true';;
280
						$options['paging']['showPrevNextMore'] = $this->get_foogallery_argument( $gallery, 'paging_showPrevNextMore', 'paging_showPrevNextMore', 'true' ) === 'true';;
281
					}
282
				}
283
			}
284
			return $options;
285
		}
286
287
		private function get_foogallery_argument( $gallery, $setting_id, $argument_name, $default_value ) {
288
			global $current_foogallery_arguments;
289
290
			if ( isset( $current_foogallery_arguments ) && isset( $current_foogallery_arguments[$argument_name] ) ) {
291
				return $current_foogallery_arguments[$argument_name];
292
			} else {
293
				return $gallery->get_setting( $setting_id, $default_value );
294
			}
295
		}
296
297
		/**
298
		 * Build up a arguments used in the preview of the gallery
299
		 *
300
		 * @param $args
301
		 * @param $post_data
302
		 * @param $template
303
		 *
304
		 * @return mixed
305
		 */
306
		function preview_arguments( $args, $post_data, $template ) {
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...
307
			$template_data = foogallery_get_gallery_template( $template );
308
309
			//check the template supports paging
310
			if ( $template_data && array_key_exists( 'paging_support', $template_data ) && true === $template_data['paging_support'] ) {
311
				$args['paging'] = $post_data[FOOGALLERY_META_SETTINGS][$template. '_paging_type'];
312
				$args['paging_position'] = $post_data[FOOGALLERY_META_SETTINGS][$template. '_paging_position'];
313
				$args['paging_theme'] = $post_data[FOOGALLERY_META_SETTINGS][$template. '_paging_theme'];
314
				$args['paging_size'] = $post_data[FOOGALLERY_META_SETTINGS][$template. '_paging_size'];
315
				$args['paging_scroll'] = $post_data[FOOGALLERY_META_SETTINGS][$template. '_paging_scroll'];
316
317
				$args['paging_limit'] = $post_data[FOOGALLERY_META_SETTINGS][$template. '_paging_limit'];
318
				$args['paging_showFirstLast'] = $post_data[FOOGALLERY_META_SETTINGS][$template. '_paging_showFirstLast'];
319
				$args['paging_showPrevNext'] = $post_data[FOOGALLERY_META_SETTINGS][$template. '_paging_showPrevNext'];
320
				$args['paging_showPrevNextMore'] = $post_data[FOOGALLERY_META_SETTINGS][$template. '_paging_showPrevNextMore'];
321
			}
322
323
			return $args;
324
		}
325
	}
326
}