PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.2.6
Gallery : FooGallery v3.2.6
3.3.2 3.3.3 3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / extensions / albums / functions.php
foogallery / extensions / albums Last commit date
admin 1 month ago css 1 month ago js 1 month ago public 1 month ago album-default.php 1 month ago album-stack.php 1 month ago class-albums-extension.php 1 month ago class-foogallery-album.php 1 month ago class-posttypes.php 1 month ago foogallery-albums.png 1 month ago functions.php 1 month ago
functions.php
482 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 if ( ! defined( 'FOOGALLERY_ALBUM_API_VERSION' ) ) {
8 define( 'FOOGALLERY_ALBUM_API_VERSION', '1.0.0' );
9 }
10
11 /**
12 * Checks whether the active Albums extension supports an API capability.
13 *
14 * The nested-items-v1 capability represents the complete first-version
15 * contract for filtering render arguments, declaring renderable items,
16 * handling template output, validating saves, and receiving save context.
17 *
18 * @param string $capability The capability to check.
19 *
20 * @return bool
21 */
22 function foogallery_album_api_supports( $capability ) {
23 return 'nested-items-v1' === $capability;
24 }
25
26 /**
27 * Builds up a FooGallery album shortcode
28 *
29 * @param $album_id
30 *
31 * @return string
32 */
33 function foogallery_build_album_shortcode( $album_id ) {
34 return '[' . foogallery_album_shortcode_tag() . ' id="' . $album_id . '"]';
35 }
36
37 /**
38 * Returns the album shortcode tag
39 *
40 * @return string
41 */
42 function foogallery_album_shortcode_tag() {
43 return apply_filters( 'foogallery_album_shortcode_tag', FOOGALLERY_CPT_ALBUM );
44 }
45
46 /**
47 * Return all the album templates used within FooGallery
48 *
49 * @return array
50 */
51 function foogallery_album_templates() {
52 $album_templates[] = array(
53 'slug' => 'default',
54 'name' => __( 'Responsive Album Layout', 'foogallery' ),
55 'fields' => array(
56 array(
57 'id' => 'thumbnail_dimensions',
58 'title' => __( 'Thumbnail Size', 'foogallery' ),
59 'desc' => __( 'Choose the size of your gallery thumbnails.', 'foogallery' ),
60 'section' => __( 'Thumbnail Settings', 'foogallery' ),
61 'type' => 'thumb_size',
62 'for' => 'thumbnail_dimensions_width',
63 'default' => array(
64 'width' => get_option( 'thumbnail_size_w' ),
65 'height' => get_option( 'thumbnail_size_h' ),
66 'crop' => true,
67 ),
68 ),
69 array(
70 'id' => 'title_bg',
71 'title' => __( 'Title Background Color', 'foogallery' ),
72 'desc' => __( 'The color of the title that overlays the album thumbnails', 'foogallery' ),
73 'section' => __( 'Thumbnail Settings', 'foogallery' ),
74 'type' => 'colorpicker',
75 'default' => '#fff'
76 ),
77 array(
78 'id' => 'title_font_color',
79 'title' => __( 'Title Text Color', 'foogallery' ),
80 'desc' => __( 'The color of the title text that overlays the album thumbnails', 'foogallery' ),
81 'section' => __( 'Thumbnail Settings', 'foogallery' ),
82 'type' => 'colorpicker',
83 'default' => '#000000'
84 ),
85 array(
86 'id' => 'alignment',
87 'title' => __( 'Alignment', 'foogallery' ),
88 'desc' => __( 'The horizontal alignment of the gallery thumbnails inside the album.', 'foogallery' ),
89 'section' => __( 'Thumbnail Settings', 'foogallery' ),
90 'default' => 'alignment-left',
91 'type' => 'select',
92 'choices' => array(
93 'alignment-left' => __( 'Left', 'foogallery' ),
94 'alignment-center' => __( 'Center', 'foogallery' ),
95 'alignment-right' => __( 'Right', 'foogallery' ),
96 )
97 ),
98 array(
99 'id' => 'gallery_link',
100 'title' => __( 'Gallery Link', 'foogallery' ),
101 'section' => __( 'URL Settings', 'foogallery' ),
102 'default' => '',
103 'type' => 'radio',
104 'choices' => array(
105 '' => __('Default', 'foogallery'),
106 'custom_url' => __('Custom URL', 'foogallery')
107 ),
108 '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' ),
109 ),
110 array(
111 'id' => 'gallery_link_format',
112 'title' => __( 'Gallery Link Format', 'foogallery' ),
113 'desc' => __( 'The format of the URL for each individual gallery in the album.', 'foogallery' ),
114 'section' => __( 'URL Settings', 'foogallery' ),
115 'type' => 'radio',
116 'choices' => array(
117 'default' => __('Pretty, e.g. ', 'foogallery') . '<code>/page-with-album/' . foogallery_album_gallery_url_slug() . '/some-gallery</code>',
118 'querystring' => __('Querystring e.g. ', 'foogallery') . '<code>/page-with-album?' . foogallery_album_gallery_url_slug() . '=some-gallery</code>'
119 ),
120 'default' => foogallery_determine_best_link_format_default()
121 ),
122 array(
123 'id' => 'url_help',
124 'title' => __( 'Please Note', 'foogallery' ),
125 'section' => __( 'URL Settings', 'foogallery' ),
126 'type' => 'help',
127 'help' => true,
128 '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' ),
129 ),
130 array(
131 'id' => 'album_hash',
132 'title' => __( 'Remember Scroll Position', 'foogallery' ),
133 'desc' => __( 'When a gallery is loaded in your album, the page is refreshed which means the scroll position will be lost .', 'foogallery' ),
134 'section' => __( 'URL Settings', 'foogallery' ),
135 'type' => 'radio',
136 'choices' => array(
137 'none' => __('Don\'t Remember', 'foogallery'),
138 'remember' => __('Remember Scroll Position', 'foogallery')
139 ),
140 'default' => 'none'
141 ),
142 array(
143 'id' => 'gallery_title_size',
144 'title' => __( 'Gallery Title Size', 'foogallery' ),
145 'desc' => __( 'The size of the title when displaying a gallery page.', 'foogallery' ),
146 'section' => __( 'Gallery Settings', 'foogallery' ),
147 'default' => 'h2',
148 'type' => 'select',
149 'choices' => array(
150 'h2' => __( 'H2', 'foogallery' ),
151 'h3' => __( 'H3', 'foogallery' ),
152 'h4' => __( 'H4', 'foogallery' ),
153 'h5' => __( 'H5', 'foogallery' ),
154 'h6' => __( 'H6', 'foogallery' ),
155 )
156 ),
157 )
158 );
159
160 $album_templates[] = array(
161 'slug' => 'stack',
162 'name' => __( 'All-In-One Stack Album', 'foogallery' ),
163 'fields' => array(
164 array(
165 'id' => 'lightbox',
166 'title' => __( 'Lightbox', 'foogallery' ),
167 'desc' => __( 'Choose which lightbox you want to use to display images.', 'foogallery' ),
168 'type' => 'lightbox',
169 ),
170
171 array(
172 'id' => 'thumbnail_dimensions',
173 'title' => __( 'Thumbnail Size', 'foogallery' ),
174 'desc' => __( 'Choose the size of your image stack thumbnails.', 'foogallery' ),
175 'section' => __( 'Thumbnail Settings', 'foogallery' ),
176 'type' => 'thumb_size_no_crop',
177 'for' => 'thumbnail_dimensions_width',
178 'default' => array(
179 'width' => get_option( 'thumbnail_size_w' ),
180 'height' => get_option( 'thumbnail_size_h' ),
181 'crop' => true,
182 ),
183 ),
184
185 array(
186 'id' => 'random_angle',
187 'title' => __( 'Thumbnail Rotation', 'foogallery' ),
188 'section' => __( 'Thumbnail Settings', 'foogallery' ),
189 'desc' => __( 'Choose how thumbnails in each gallery are shown when clicking an image stack.', 'foogallery' ),
190 'type' => 'radio',
191 'default' => 'false',
192 'choices' => array(
193 'false' => __( 'Normal', 'foogallery' ),
194 'true' => __( 'Random Angles', 'foogallery' )
195 )
196 ),
197
198 array(
199 'id' => 'gutter',
200 'title' => __( 'Thumbnail Gutter', 'foogallery' ),
201 'section' => __( 'Thumbnail Settings', 'foogallery' ),
202 'desc' => __( 'The spacing between each image stack.', 'foogallery' ),
203 'type' => 'number',
204 'default' => 50
205 ),
206
207 array(
208 'id' => 'pile_angles',
209 'title' => __( 'Image Stack Angles', 'foogallery' ),
210 'section' => __( 'Thumbnail Settings', 'foogallery' ),
211 'desc' => __( 'The angle of the images behind the thumbnail in each image stack.', 'foogallery' ),
212 'type' => 'radio',
213 'default' => '1',
214 'choices' => array(
215 '1' => __( 'Low', 'foogallery' ),
216 '2' => __( 'Normal', 'foogallery' ),
217 '3' => __( 'More Than Normal', 'foogallery' ),
218 '5' => __( 'High', 'foogallery' ),
219 )
220 ),
221
222 array(
223 'id' => 'caption_alignment',
224 'title' => __( 'Caption Alignment', 'foogallery' ),
225 'section' => __( 'Gallery Settings', 'foogallery' ),
226 'desc' => __( 'Choose the horizontal alignment for the image stack caption.', 'foogallery' ),
227 'type' => 'select',
228 'default' => 'center',
229 'choices' => array(
230 'left' => __( 'Left', 'foogallery' ),
231 'center' => __( 'Centre', 'foogallery' ),
232 'right' => __( 'Right', 'foogallery' ),
233 )
234 )
235 )
236 );
237
238 if ( foogallery_album_gallery_descriptions_enabled() ) {
239 $gallery_description_caption_field = array(
240 'id' => 'show_gallery_description_in_caption',
241 'title' => __( 'Include Gallery Description In Caption', 'foogallery' ),
242 'desc' => __( 'Display each gallery description in the album caption.', 'foogallery' ),
243 'section' => __( 'Gallery Settings', 'foogallery' ),
244 'type' => 'checkbox',
245 );
246
247 foreach ( $album_templates as &$album_template ) {
248 if ( in_array( $album_template['slug'], array( 'default', 'stack' ), true ) ) {
249 $album_template['fields'][] = $gallery_description_caption_field;
250 }
251 }
252 unset( $album_template );
253 }
254
255 return apply_filters( 'foogallery_album_templates', $album_templates );
256 }
257
258 /**
259 * Check if gallery descriptions are enabled for albums.
260 *
261 * @return bool
262 */
263 function foogallery_album_gallery_descriptions_enabled() {
264 return 'on' === foogallery_get_setting( 'enable_gallery_descriptions' );
265 }
266
267 /**
268 * Returns safely formatted gallery description HTML for album output.
269 *
270 * @param FooGallery $gallery The gallery object.
271 *
272 * @return string
273 */
274 function foogallery_album_gallery_description_html( $gallery ) {
275 if ( ! foogallery_album_gallery_descriptions_enabled() ) {
276 return '';
277 }
278
279 if ( ! $gallery instanceof FooGallery || ! isset( $gallery->_post ) || empty( $gallery->_post->post_content ) ) {
280 return '';
281 }
282
283 $description = apply_filters( 'the_content', $gallery->_post->post_content );
284
285 return wp_kses_post( $description );
286 }
287
288 function foogallery_determine_best_link_format_default() {
289 global $wp_rewrite;
290 if ( '' === $wp_rewrite->permalink_structure ) {
291 //we are using ?page_id
292 return 'querystring';
293 }
294
295 //we are using permalinks
296 return 'default';
297 }
298
299 /**
300 * Returns the default album template
301 *
302 * @return string
303 */
304 function foogallery_default_album_template() {
305 return foogallery_get_setting( 'album_template' );
306 }
307
308 /**
309 * Returns the gallery link url for an album
310 *
311 * @param $album FooGalleryAlbum
312 * @param $gallery FooGallery
313 *
314 * @return string
315 */
316 function foogallery_album_build_gallery_link( $album, $gallery ) {
317 //first check if we want to use custom URL's
318 $gallery_link = $album->get_meta( 'default_gallery_link', '' );
319
320 if ( 'custom_url' === $gallery_link ) {
321 //check if the gallery has a custom url, and if so, then use it
322 $url = get_post_meta( $gallery->ID, 'custom_url', true );
323 }
324
325 if ( empty( $url ) ) {
326 $slug = foogallery_album_gallery_url_slug();
327 $format = $album->get_meta( 'default_gallery_link_format', 'default' );
328
329 if ( 'default' === $format && 'default' === foogallery_determine_best_link_format_default() ) {
330 $url = untrailingslashit( trailingslashit( get_permalink() ) . $slug . '/' . $gallery->slug );
331 } else {
332 $url = add_query_arg( $slug, $gallery->slug );
333 }
334
335 $use_hash = $album->get_meta( 'default_album_hash', 'remember' );
336
337 if ( 'remember' === $use_hash ) {
338 //add the album hash if required
339 $url .= '#' . $album->slug;
340 }
341 }
342
343 return apply_filters( 'foogallery_album_build_gallery_link', $url );
344 }
345
346 /**
347 * Returns the gallery slug used when generating gallery URL's
348 *
349 * @return string
350 */
351 function foogallery_album_gallery_url_slug() {
352 $slug = foogallery_get_setting( 'album_gallery_slug', 'gallery' );
353 return apply_filters( 'foogallery_album_gallery_url_slug', $slug );
354 }
355
356 /**
357 * Returns the gallery link target for an album
358 *
359 * @param $album FooGalleryAlbum
360 * @param $gallery FooGallery
361 *
362 * @return string
363 */
364 function foogallery_album_build_gallery_link_target( $album, $gallery ) {
365 //first check if we want to use custom URL's
366 $gallery_link = $album->get_meta( 'default_gallery_link', '' );
367
368 if ( 'custom_url' === $gallery_link ) {
369 //check if the gallery has a custom target, and if so, then use it
370 $target = get_post_meta( $gallery->ID, 'custom_target', true );
371
372 //check if the $target is 'default' and set to '_self'
373 if ( 'default' === $target ) {
374 $target = '_self';
375 }
376 }
377
378 if ( empty( $target ) ) {
379 $target = '_self';
380 }
381
382 return apply_filters( 'foogallery_album_build_gallery_link_target', $target );
383 }
384
385 function foogallery_album_get_current_gallery() {
386 $slug = foogallery_album_gallery_url_slug();
387
388 $gallery = get_query_var( $slug );
389
390 if ( empty( $gallery ) ) {
391 $gallery = safe_get_from_request( $slug );
392 }
393
394 return apply_filters( 'foogallery_album_get_current_gallery', $gallery );
395 }
396
397 function foogallery_album_remove_gallery_from_link() {
398 $gallery = foogallery_album_get_current_gallery();
399 $slug = foogallery_album_gallery_url_slug();
400
401 $url = untrailingslashit( remove_query_arg( $slug ) );
402
403 return str_replace( $slug . '/' . $gallery, '', $url);
404 }
405
406 /**
407 * Get a foogallery album template setting for the current foogallery that is being output to the frontend
408 * @param string $key
409 * @param string $default
410 *
411 * @return bool
412 */
413 function foogallery_album_template_setting( $key, $default = '' ) {
414 global $current_foogallery_album;
415 global $current_foogallery_album_arguments;
416 global $current_foogallery_album_template;
417
418 $settings_key = "{$current_foogallery_album_template}_{$key}";
419
420 if ( $current_foogallery_album_arguments && array_key_exists( $key, $current_foogallery_album_arguments ) ) {
421 //try to get the value from the arguments
422 $value = $current_foogallery_album_arguments[ $key ];
423
424 } else if ( $current_foogallery_album->settings && array_key_exists( $settings_key, $current_foogallery_album->settings ) ) {
425 //then get the value out of the saved gallery settings
426 $value = $current_foogallery_album->settings[ $settings_key ];
427 } else {
428 //otherwise set it to the default
429 $value = $default;
430 }
431
432 $value = apply_filters( 'foogallery_album_template_setting-' . $key, $value );
433
434 return $value;
435 }
436
437 /**
438 * uninstall all albums and setting for albums
439 */
440 function foogallery_album_uninstall() {
441 if ( !current_user_can( 'install_plugins' ) ) exit;
442
443 //delete all albums posts
444 global $wpdb;
445 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Uninstall intentionally retrieves every matching ID immediately before deleting the posts.
446 $gallery_post_ids = $wpdb->get_col(
447 $wpdb->prepare(
448 "SELECT p.ID FROM {$wpdb->posts} AS p WHERE p.post_type = %s",
449 FOOGALLERY_CPT_ALBUM
450 )
451 );
452
453 if ( !empty( $gallery_post_ids ) ) {
454 $deleted = 0;
455 foreach ( $gallery_post_ids as $post_id ) {
456 $del = wp_delete_post( $post_id );
457 if ( false !== $del ) {
458 ++$deleted;
459 }
460 }
461 }
462 }
463
464 /**
465 * Render a foogallery album
466 *
467 * @param $album_id int The id of the foogallery album you want to render
468 * @param array $args
469 */
470 if (! function_exists( 'foogallery_render_album') ) {
471 function foogallery_render_album( $album_id, $args = array() ) {
472 //create new instance of template engine
473 $engine = new FooGallery_Album_Template_Loader();
474
475 $shortcode_args = wp_parse_args( $args, array(
476 'id' => $album_id
477 ) );
478
479 $engine->render_template( $shortcode_args );
480 }
481 }
482