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 ( eea301...fe82dd )
by Brad
06:04 queued 02:50
created

functions.php ➔ foogallery_album_build_gallery_link_target()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 15
rs 9.4285
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',
108
				'title'   => __( 'Gallery Link', 'foogallery' ),
109
				'section' => __( 'URL Settings', 'foogallery' ),
110
				'default' => '',
111
				'type'    => 'radio',
112
				'spacer'  => '<span class="spacer"></span>',
113
				'choices' =>  array(
114
						'' =>  __('Default', 'foogallery'),
115
						'custom_url' => __('Custom URL', 'foogallery')
116
				),
117
				'desc'	  => __( 'You can choose to link each gallery to the default embedded gallery, or you can choose to link to the gallery custom URL (if set).', 'foogallery' ),
118
			),
119
			array(
120
				'id'      => 'gallery_link_format',
121
				'title'   => __( 'Gallery Link Format', 'foogallery' ),
122
				'desc'    => __( 'The format of the URL for each individual gallery in the album.', 'foogallery' ),
123
				'section' => __( 'URL Settings', 'foogallery' ),
124
				'type'    => 'radio',
125
				'choices' =>  array(
126
					'default' =>  __('Pretty, e.g. ', 'foogallery') . '<code>/page-with-album/' . foogallery_album_gallery_url_slug() . '/some-gallery</code>',
127
					'querystring' => __('Querystring e.g. ', 'foogallery') . '<code>/page-with-album?' . foogallery_album_gallery_url_slug() . '=some-gallery</code>'
128
				),
129
				'default' => foogallery_determine_best_link_format_default()
130
			),
131
			array(
132
				'id'	  => 'url_help',
133
				'title'	  => __( 'Please Note', 'foogallery' ),
134
				'section' => __( 'URL Settings', 'foogallery' ),
135
				'type'	  => 'help',
136
				'help'	  => true,
137
				'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' ),
138
			),
139
			array(
140
				'id'      => 'album_hash',
141
				'title'   => __( 'Remember Scroll Position', 'foogallery' ),
142
				'desc'    => __( 'When a gallery is loaded in your album, the page is refreshed which means the scroll position will be lost .', 'foogallery' ),
143
				'section' => __( 'URL Settings', 'foogallery' ),
144
				'type'    => 'radio',
145
				'choices' =>  array(
146
					'none' =>  __('Don\'t Remember', 'foogallery'),
147
					'remember' => __('Remember Scroll Position', 'foogallery')
148
				),
149
				'default' => 'none'
150
			)
151
		)
152
	);
153
154
	$album_templates[] = array(
155
		'slug'        => 'stack',
156
		'name'        => __( 'All-In-One Stack Album', 'foogallery' ),
157
		'fields'	  => array(
158
			array(
159
				'id'      => 'lightbox',
160
				'title'   => __( 'Lightbox', 'foogallery' ),
161
				'desc'    => __( 'Choose which lightbox you want to use to display images.', 'foogallery' ),
162
				'type'    => 'lightbox',
163
			),
164
165
			array(
166
				'id'      => 'thumbnail_dimensions',
167
				'title'   => __( 'Thumbnail Size', 'foogallery' ),
168
				'desc'    => __( 'Choose the size of your image stack thumbnails.', 'foogallery' ),
169
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
170
				'type'    => 'thumb_size',
171
				'default' => array(
172
					'width' => get_option( 'thumbnail_size_w' ),
173
					'height' => get_option( 'thumbnail_size_h' ),
174
					'crop' => true,
175
				),
176
			),
177
178
			array(
179
				'id'      => 'random_angle',
180
				'title'   => __( 'Thumbnail Rotation', 'foogallery' ),
181
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
182
				'desc'    => __( 'Choose how thumbnails in each gallery are shown when clicking an image stack.', 'foogallery' ),
183
				'type'    => 'radio',
184
				'default' => 'false',
185
				'choices' =>  array(
186
					'false' => __( 'Normal', 'foogallery' ),
187
					'true' => __( 'Random Angles', 'foogallery' )
188
				)
189
			),
190
191
			array(
192
				'id'      => 'gutter',
193
				'title'   => __( 'Thumbnail Gutter', 'foogallery' ),
194
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
195
				'desc'    => __( 'The spacing between each image stack.', 'foogallery' ),
196
				'type'    => 'number',
197
				'default' => 50
198
			),
199
200
			array(
201
				'id'      => 'delay',
202
				'title'   => __( 'Expand Delay', 'foogallery' ),
203
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
204
				'desc'    => __( 'The delay between expanding each image on a image stack.', 'foogallery' ),
205
				'type'    => 'number',
206
				'default' => 0
207
			),
208
209
			array(
210
				'id'      => 'pile_angles',
211
				'title'   => __( 'Image Stack Angles', 'foogallery' ),
212
				'section' => __( 'Thumbnail Settings', 'foogallery' ),
213
				'desc'    => __( 'The angle of the images behind the thumbnail in each image stack.', 'foogallery' ),
214
				'type'    => 'radio',
215
				'default' => '1',
216
				'choices' =>  array(
217
					'1' => __( 'Low', 'foogallery' ),
218
					'2' => __( 'Normal', 'foogallery' ),
219
					'3' => __( 'More Than Normal', 'foogallery' ),
220
					'5' => __( 'High', 'foogallery' ),
221
				)
222
			)
223
		)
224
	);
225
226
	return apply_filters( 'foogallery_album_templates', $album_templates );
227
}
228
229
function foogallery_determine_best_link_format_default() {
230
	global $wp_rewrite;
231
	if ( '' === $wp_rewrite->permalink_structure ) {
232
		//we are using ?page_id
233
		return 'querystring';
234
	}
235
236
	//we are using permalinks
237
	return 'default';
238
}
239
240
/**
241
 * Returns the default album template
242
 *
243
 * @return string
244
 */
245
function foogallery_default_album_template() {
246
	return foogallery_get_setting( 'album_template' );
247
}
248
249
/**
250
 * Returns the gallery link url for an album
251
 *
252
 * @param $album FooGalleryAlbum
253
 * @param $gallery FooGallery
254
 *
255
 * @return string
256
 */
257
function foogallery_album_build_gallery_link( $album, $gallery ) {
258
	//first check if we want to use custom URL's
259
	$gallery_link = $album->get_meta( 'default_gallery_link', '' );
260
261
	if ( 'custom_url' === $gallery_link ) {
262
		//check if the gallery has a custom url, and if so, then use it
263
		$url = get_post_meta( $gallery->ID, 'custom_url', true );
264
	}
265
266
	if ( empty( $url ) ) {
267
		$slug   = foogallery_album_gallery_url_slug();
268
		$format = $album->get_meta( 'default_gallery_link_format', 'default' );
269
270
		if ( 'default' === $format && 'default' === foogallery_determine_best_link_format_default() ) {
271
			$url = untrailingslashit( trailingslashit( get_permalink() ) . $slug . '/' . $gallery->slug );
272
		} else {
273
			$url = add_query_arg( $slug, $gallery->slug );
274
		}
275
276
		$use_hash = $album->get_meta( 'default_album_hash', 'remember' );
277
278
		if ( 'remember' === $use_hash ) {
279
			//add the album hash if required
280
			$url .= '#' . $album->slug;
281
		}
282
	}
283
284
	return apply_filters( 'foogallery_album_build_gallery_link', $url );
285
}
286
287
/**
288
 * Returns the gallery slug used when generating gallery URL's
289
 *
290
 * @return string
291
 */
292
function foogallery_album_gallery_url_slug() {
293
	$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...
294
	return apply_filters( 'foogallery_album_gallery_url_slug', $slug );
295
}
296
297
/**
298
 * Returns the gallery link target for an album
299
 *
300
 * @param $album FooGalleryAlbum
301
 * @param $gallery FooGallery
302
 *
303
 * @return string
304
 */
305
function foogallery_album_build_gallery_link_target( $album, $gallery ) {
306
	//first check if we want to use custom URL's
307
	$gallery_link = $album->get_meta( 'default_gallery_link', '' );
308
309
	if ( 'custom_url' === $gallery_link ) {
310
		//check if the gallery has a custom target, and if so, then use it
311
		$target = get_post_meta( $gallery->ID, 'custom_target', true );
312
	}
313
314
	if ( empty( $target ) ) {
315
		$target = '_self';
316
	}
317
318
	return apply_filters( 'foogallery_album_build_gallery_link_target', $target );
319
}
320
321
function foogallery_album_get_current_gallery() {
322
	$slug = foogallery_album_gallery_url_slug();
323
324
	$gallery = get_query_var( $slug );
325
326
	if ( empty( $gallery ) ) {
327
		$gallery = safe_get_from_request( $slug );
328
	}
329
330
	return apply_filters( 'foogallery_album_get_current_gallery', $gallery );
331
}
332
333
function foogallery_album_remove_gallery_from_link() {
334
	$gallery = foogallery_album_get_current_gallery();
335
	$slug = foogallery_album_gallery_url_slug();
336
337
	$url = untrailingslashit( remove_query_arg( $slug ) );
338
339
	return str_replace( $slug . '/' . $gallery, '', $url);
340
}
341
342
/**
343
 * Get a foogallery album template setting for the current foogallery that is being output to the frontend
344
 * @param string	$key
345
 * @param string	$default
346
 *
347
 * @return bool
348
 */
349
function foogallery_album_template_setting( $key, $default = '' ) {
350
	global $current_foogallery_album;
351
	global $current_foogallery_album_arguments;
352
	global $current_foogallery_album_template;
353
354
	$settings_key = "{$current_foogallery_album_template}_{$key}";
355
356
	if ( $current_foogallery_album_arguments && array_key_exists( $key, $current_foogallery_album_arguments ) ) {
357
		//try to get the value from the arguments
358
		$value = $current_foogallery_album_arguments[ $key ];
359
360
	} else if ( $current_foogallery_album->settings && array_key_exists( $settings_key, $current_foogallery_album->settings ) ) {
361
		//then get the value out of the saved gallery settings
362
		$value = $current_foogallery_album->settings[ $settings_key ];
363
	} else {
364
		//otherwise set it to the default
365
		$value = $default;
366
	}
367
368
	$value = apply_filters( 'foogallery_album_template_setting-' . $key, $value );
369
370
	return $value;
371
}
372