class-admin-bar.php
7 months ago
class-aioseo-sitemaps.php
7 months ago
class-css-load-optimizer.php
7 months ago
class-foogallery-template-loader.php
7 months ago
class-public.php
7 months ago
class-rank-math-seo-sitemaps.php
7 months ago
class-shortcodes.php
7 months ago
class-yoast-seo-sitemaps.php
7 months ago
index.php
11 years ago
class-shortcodes.php
72 lines
| 1 | <?php |
| 2 | /* |
| 3 | * FooGallery Shortcodes |
| 4 | */ |
| 5 | |
| 6 | if ( ! class_exists( 'FooGallery_Shortcodes' ) ) { |
| 7 | |
| 8 | class FooGallery_Shortcodes { |
| 9 | |
| 10 | function __construct() { |
| 11 | add_action( 'foogallery_load_template', array( $this, 'handle_lightbox_field' ) ); |
| 12 | add_action( 'foogallery_loaded_template', array( $this, 'render_custom_css' ) ); |
| 13 | add_action( 'plugins_loaded', array( $this, 'init_shortcodes' ) ); |
| 14 | } |
| 15 | |
| 16 | function init_shortcodes() { |
| 17 | add_shortcode( foogallery_gallery_shortcode_tag(), array( $this, 'render_foogallery_shortcode' ) ); |
| 18 | add_shortcode( 'foogallery-enqueue', array( $this, 'render_foogallery_enqueue' ) ); |
| 19 | } |
| 20 | |
| 21 | function render_foogallery_shortcode( $atts ) { |
| 22 | |
| 23 | $args = wp_parse_args( $atts, array( |
| 24 | 'id' => 0, |
| 25 | 'gallery' => '', |
| 26 | ) ); |
| 27 | |
| 28 | $args = apply_filters( 'foogallery_shortcode_atts', $args ); |
| 29 | |
| 30 | //create new instance of template engine |
| 31 | $engine = new FooGallery_Template_Loader(); |
| 32 | |
| 33 | ob_start(); |
| 34 | |
| 35 | $engine->render_template( $args ); |
| 36 | |
| 37 | $output_string = ob_get_contents(); |
| 38 | ob_end_clean(); |
| 39 | return $output_string; |
| 40 | } |
| 41 | |
| 42 | function render_foogallery_enqueue() { |
| 43 | foogallery_enqueue_core_gallery_template_script(); |
| 44 | foogallery_enqueue_core_gallery_template_style(); |
| 45 | wp_enqueue_script( 'masonry' ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Handle a gallery that has a lightbox. This allows us to include any scripts or CSS that is needed for the lightbox |
| 50 | * |
| 51 | * @param $gallery FooGallery |
| 52 | */ |
| 53 | function handle_lightbox_field( $gallery ) { |
| 54 | if ( $gallery->gallery_template_has_field_of_type( 'lightbox' ) ) { |
| 55 | $lightbox = foogallery_gallery_template_setting_lightbox(); |
| 56 | |
| 57 | if ( !empty( $lightbox ) ) { |
| 58 | do_action( "foogallery_template_lightbox-{$lightbox}", $gallery ); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | function render_custom_css( $foogallery ) { |
| 64 | if ( !empty( $foogallery->custom_css ) ) { |
| 65 | echo '<style type="text/css">'; |
| 66 | echo $foogallery->custom_css; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Custom CSS from gallery settings. The custom CSS is already sanitized |
| 67 | echo '</style>'; |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 |