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 — hotfix/unyson-support ( a83d09 )
by Brad
02:40
created

functions.php ➔ foogallery_album_template_setting()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 5
eloc 13
nc 3
nop 2
dl 0
loc 23
rs 8.5906
1
<?php
2
3
/**
4
 * Builds up a FooGallery album shortcode
5
 *
6
 * @param $album_id
7
 *
8
 * @return string
9
 */
10
function foogallery_build_album_shortcode( $album_id ) {
11
	return '[' . foogallery_album_shortcode_tag() . ' id="' . $album_id . '"]';
12
}
13
14
/**
15
 * Returns the album shortcode tag
16
 *
17
 * @return string
18
 */
19
function foogallery_album_shortcode_tag() {
20
	return apply_filters( 'foogallery_album_shortcode_tag', FOOGALLERY_CPT_ALBUM );
21
}
22
23
/**
24
 * Return all the album templates used within FooGallery
25
 *
26
 * @return array
27
 */
28
function foogallery_album_templates() {
29
	$album_templates[] = array(
30
		'slug'        => 'default',
31
		'name'        => __( 'Responsive Album Layout', 'foogallery' ),
32
		'fields'	  => array(
33
			array(
34
				'id'      => 'thumbnail_dimensions',
35
				'title'   => __( 'Thumbnail Size', 'foogallery' ),
36
				'desc'    => __( 'Choose the size of your gallery thumbnails.', 'foogallery' ),
37
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
38
				'type'    => 'thumb_size',
39
				'default' => array(
40
					'width' => get_option( 'thumbnail_size_w' ),
41
					'height' => get_option( 'thumbnail_size_h' ),
42
					'crop' => true,
43
				),
44
			),
45
			array(
46
				'id'      => 'title_bg',
47
				'title'   => __( 'Title Background Color', 'foogallery' ),
48
				'desc'    => __( 'The color of the title that overlays the album thumbnails', 'foogallery' ),
49
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
50
				'type'    => 'colorpicker',
51
				'default' => '#fff'
52
			),
53
			array(
54
				'id'      => 'title_font_color',
55
				'title'   => __( 'Title Text Color', 'foogallery' ),
56
				'desc'    => __( 'The color of the title text that overlays the album thumbnails', 'foogallery' ),
57
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
58
				'type'    => 'colorpicker',
59
				'default' => '#000000'
60
			),
61
			array(
62
				'id'      => 'alignment',
63
				'title'   => __( 'Alignment', 'foogallery' ),
64
				'desc'    => __( 'The horizontal alignment of the gallery thumbnails inside the album.', 'foogallery' ),
65
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
66
				'default' => 'alignment-left',
67
				'type'    => 'select',
68
				'choices' => array(
69
					'alignment-left' => __( 'Left', 'foogallery' ),
70
					'alignment-center' => __( 'Center', 'foogallery' ),
71
					'alignment-right' => __( 'Right', 'foogallery' ),
72
				)
73
			),
74
			array(
75
				'id'      => 'back_to_album_text',
76
				'title'   => __( '"Back To Album" Text', 'foogallery' ),
77
				'desc'    => __( 'The text that is shown at the top of the album when a gallery is shown', 'foogallery' ),
78
				'section' => __( 'Language Settings', 'foogallery' ),
79
				'type'    => 'text',
80
				'default' => '&laquo; back to album'
81
			),
82
			array(
83
				'id'      => 'no_images_text',
84
				'title'   => __( '"No Images" Text', 'foogallery' ),
85
				'desc'    => __( 'The text that is shown on the gallery caption when there are no images in the gallery.', 'foogallery' ),
86
				'section' => __( 'Language Settings', 'foogallery' ),
87
				'type'    => 'text',
88
				'default' => 'No images'
89
			),
90
			array(
91
				'id'      => 'single_image_text',
92
				'title'   => __( '"1 Image" Text', 'foogallery' ),
93
				'desc'    => __( 'The text that is shown on the gallery caption when there is a single image in the gallery.', 'foogallery' ),
94
				'section' => __( 'Language Settings', 'foogallery' ),
95
				'type'    => 'text',
96
				'default' => '1 image'
97
			),
98
			array(
99
				'id'      => 'images_text',
100
				'title'   => __( '"X images" Text', 'foogallery' ),
101
				'desc'    => __( 'The text that is shown on the gallery caption when there are many images in the gallery. "s%" will be replaced with the actual count.', 'foogallery' ),
102
				'section' => __( 'Language Settings', 'foogallery' ),
103
				'type'    => 'text',
104
				'default' => '%s images'
105
			),
106
			array(
107
				'id'      => 'gallery_link_format',
108
				'title'   => __( 'Gallery Link Format', 'foogallery' ),
109
				'desc'    => __( 'The format of the URL for each individual gallery in the album.', 'foogallery' ),
110
				'section' => __( 'URL Settings', 'foogallery' ),
111
				'type'    => 'radio',
112
				'choices' =>  array(
113
					'default' =>  __('Pretty, e.g. ', 'foogallery') . '<code>/page-with-album/' . foogallery_album_gallery_url_slug() . '/some-gallery</code>',
114
					'querystring' => __('Querystring e.g. ', 'foogallery') . '<code>/page-with-album?' . foogallery_album_gallery_url_slug() . '=some-gallery</code>'
115
				),
116
				'default' => foogallery_determine_best_link_format_default()
117
			),
118
			array(
119
				'id'	  => 'url_help',
120
				'title'	  => __( 'Please Note', 'foogallery' ),
121
				'section' => __( 'URL Settings', 'foogallery' ),
122
				'type'	  => 'help',
123
				'help'	  => true,
124
				'desc'	  => __( 'If you are getting 404\'s when clicking on the album galleries, then change to the querystring format. To force your rewrite rules to flush, simply deactivate and activate the albums extension again.', 'foogallery' ),
125
			),
126
			array(
127
				'id'      => 'album_hash',
128
				'title'   => __( 'Remember Scroll Position', 'foogallery' ),
129
				'desc'    => __( 'When a gallery is loaded in your album, the page is refreshed which means the scroll position will be lost .', 'foogallery' ),
130
				'section' => __( 'URL Settings', 'foogallery' ),
131
				'type'    => 'radio',
132
				'choices' =>  array(
133
					'none' =>  __('Don\'t Remember', 'foogallery'),
134
					'remember' => __('Remember Scroll Position', 'foogallery')
135
				),
136
				'default' => 'none'
137
			)
138
		)
139
	);
140
141
	$album_templates[] = array(
142
		'slug'        => 'stack',
143
		'name'        => __( 'All-In-One Stack Album', 'foogallery' ),
144
		'fields'	  => array(
145
			array(
146
				'id'      => 'lightbox',
147
				'title'   => __( 'Lightbox', 'foogallery' ),
148
				'desc'    => __( 'Choose which lightbox you want to use to display images.', 'foogallery' ),
149
				'type'    => 'lightbox',
150
			),
151
152
			array(
153
				'id'      => 'thumbnail_dimensions',
154
				'title'   => __( 'Thumbnail Size', 'foogallery' ),
155
				'desc'    => __( 'Choose the size of your image stack thumbnails.', 'foogallery' ),
156
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
157
				'type'    => 'thumb_size',
158
				'default' => array(
159
					'width' => get_option( 'thumbnail_size_w' ),
160
					'height' => get_option( 'thumbnail_size_h' ),
161
					'crop' => true,
162
				),
163
			),
164
165
			array(
166
				'id'      => 'random_angle',
167
				'title'   => __( 'Thumbnail Rotation', 'foogallery' ),
168
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
169
				'desc'    => __( 'Choose how thumbnails in each gallery are shown when clicking an image stack.', 'foogallery' ),
170
				'type'    => 'radio',
171
				'default' => 'false',
172
				'choices' =>  array(
173
					'false' => __( 'Normal', 'foogallery' ),
174
					'true' => __( 'Random Angles', 'foogallery' )
175
				)
176
			),
177
178
			array(
179
				'id'      => 'gutter',
180
				'title'   => __( 'Thumbnail Gutter', 'foogallery' ),
181
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
182
				'desc'    => __( 'The spacing between each image stack.', 'foogallery' ),
183
				'type'    => 'number',
184
				'default' => 50
185
			),
186
187
			array(
188
				'id'      => 'delay',
189
				'title'   => __( 'Expand Delay', 'foogallery' ),
190
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
191
				'desc'    => __( 'The delay between expanding each image on a image stack.', 'foogallery' ),
192
				'type'    => 'number',
193
				'default' => 0
194
			),
195
196
			array(
197
				'id'      => 'pile_angles',
198
				'title'   => __( 'Image Stack Angles', 'foogallery' ),
199
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
200
				'desc'    => __( 'The angle of the images behind the thumbnail in each image stack.', 'foogallery' ),
201
				'type'    => 'radio',
202
				'default' => '1',
203
				'choices' =>  array(
204
					'1' => __( 'Low', 'foogallery' ),
205
					'2' => __( 'Normal', 'foogallery' ),
206
					'3' => __( 'More Than Normal', 'foogallery' ),
207
					'5' => __( 'High', 'foogallery' ),
208
				)
209
			)
210
		)
211
	);
212
213
	return apply_filters( 'foogallery_album_templates', $album_templates );
214
}
215
216
function foogallery_determine_best_link_format_default() {
217
	global $wp_rewrite;
218
	if ( '' === $wp_rewrite->permalink_structure ) {
219
		//we are using ?page_id
220
		return 'querystring';
221
	}
222
223
	//we are using permalinks
224
	return 'default';
225
}
226
227
/**
228
 * Returns the default album template
229
 *
230
 * @return string
231
 */
232
function foogallery_default_album_template() {
233
	return foogallery_get_setting( 'album_template' );
234
}
235
236
function foogallery_album_build_gallery_link( $album, $gallery ) {
237
	$slug = foogallery_album_gallery_url_slug();
238
	$key = 'default_gallery_link_format';
239
	$format = $album->get_meta( $key, 'default' );
240
241
	if ( 'default' === $format && 'default' === foogallery_determine_best_link_format_default() ) {
242
		$url = untrailingslashit( get_permalink() . $slug . '/' . $gallery->slug );
243
	} else {
244
		$url = add_query_arg( $slug, $gallery->slug );
245
	}
246
247
	$use_hash = $album->get_meta( 'default_album_hash', 'remember' );
248
249
	if ( 'remember' === $use_hash ) {
250
		//add the album hash if required
251
		$url .= '#' . $album->slug;
252
	}
253
254
	return apply_filters( 'foogallery_album_build_gallery_link', $url );
255
}
256
257
/**
258
 * Returns the gallery slug used when generating gallery URL's
259
 *
260
 * @return string
261
 */
262
function foogallery_album_gallery_url_slug() {
263
	$slug = foogallery_get_setting( 'album_gallery_slug', 'gallery' );
0 ignored issues
show
Documentation introduced by
'gallery' is of type string, but the function expects a boolean.

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...
264
	return apply_filters( 'foogallery_album_gallery_url_slug', $slug );
265
}
266
267
function foogallery_album_get_current_gallery() {
268
	$slug = foogallery_album_gallery_url_slug();
269
270
	$gallery = get_query_var( $slug );
271
272
	if ( empty( $gallery ) ) {
273
		$gallery = safe_get_from_request( $slug );
274
	}
275
276
	return apply_filters( 'foogallery_album_get_current_gallery', $gallery );
277
}
278
279
function foogallery_album_remove_gallery_from_link() {
280
	$gallery = foogallery_album_get_current_gallery();
281
	$slug = foogallery_album_gallery_url_slug();
282
283
	$url = untrailingslashit( remove_query_arg( $slug ) );
284
285
	return str_replace( $slug . '/' . $gallery, '', $url);
286
}
287
288
/**
289
 * Get a foogallery album template setting for the current foogallery that is being output to the frontend
290
 * @param string	$key
291
 * @param string	$default
292
 *
293
 * @return bool
294
 */
295
function foogallery_album_template_setting( $key, $default = '' ) {
296
	global $current_foogallery_album;
297
	global $current_foogallery_album_arguments;
298
	global $current_foogallery_album_template;
299
300
	$settings_key = "{$current_foogallery_album_template}_{$key}";
301
302
	if ( $current_foogallery_album_arguments && array_key_exists( $key, $current_foogallery_album_arguments ) ) {
303
		//try to get the value from the arguments
304
		$value = $current_foogallery_album_arguments[ $key ];
305
306
	} else if ( $current_foogallery_album->settings && array_key_exists( $settings_key, $current_foogallery_album->settings ) ) {
307
		//then get the value out of the saved gallery settings
308
		$value = $current_foogallery_album->settings[ $settings_key ];
309
	} else {
310
		//otherwise set it to the default
311
		$value = $default;
312
	}
313
314
	$value = apply_filters( 'foogallery_album_template_setting-' . $key, $value );
315
316
	return $value;
317
}
318