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... ( 6aa6f0...0fed14 )
by Brad
02:45
created

FooGallery_Paging::add_paging_options()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 35
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

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