PluginProbe
Meow Gallery / 5.5.2
Meow Gallery v5.5.2
5.5.4 5.5.3 5.5.2 5.5.1 5.5.0 5.4.9 5.4.8 5.4.7 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 All 156 releases
meow-gallery / classes / run.php

run.php in Meow Gallery 5.5.2, at classes/run.php

102 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Meow_MGL_Run {
4 private $isEnqueued = false;
5 private $core;
6 private $atts;
7
8 public function __construct( $core ) {
9 $this->core = $core;
10
11 $override_disabled = get_option( 'mgl_options', [] )[ 'gallery_shortcode_override_disabled' ] ?? false;
12 if ( !$override_disabled ) { add_shortcode( 'gallery', array( $core, 'gallery' ) ); }
13 add_shortcode( 'meow-gallery', array( $core, 'gallery' ) );
14
15 if ( is_admin() ) {
16 add_action( 'init', array( $this, 'enqueue_scripts' ) );
17 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
18 } else {
19 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ), 10 );
20
21 add_action( 'mgl_gallery_created', array( $this, 'enqueue_scripts' ), 10, 0 );
22 add_action( 'mgl_collection_created', array( $this, 'enqueue_scripts' ), 10, 0 );
23 }
24
25 // Yoast: Some people really want this, but it needs to be reviewed as Yoast changed its API
26 //add_filter( 'wpseo_sitemap_urlimages', array( $this, 'wpseo_siteimap' ), 10, 2 );
27 }
28
29 function enqueue_styles() {
30 // Cache buster for CSS
31 $css_file = MGL_PATH . '/app/style.min.css';
32 $css_cache_buster = file_exists( $css_file ) ? filemtime( $css_file ) : MGL_VERSION;
33 wp_enqueue_style( 'mgl-css', plugins_url( '/app/style.min.css', __DIR__ ), null, $css_cache_buster );
34 }
35
36 function enqueue_scripts() {
37 // Only need to load the scripts once.
38 if ( $this->isEnqueued ) {
39 return;
40 }
41 $this->isEnqueued = true;
42
43 // Load the JS for Meow Gallery
44 $physical_file = MGL_PATH . '/app/galleries.js';
45 $cache_buster = file_exists( $physical_file ) ? filemtime( $physical_file ) : MGL_VERSION;
46 wp_enqueue_script( 'mgl-js', plugins_url( '/app/galleries.js', __DIR__ ), array(), $cache_buster, true );
47
48
49 // TODO: This should be moved in a getter (since it is also used by tiles.php)
50 $density = [];
51 if ( isset( $this->atts['density'] ) ) {
52 $density['desktop'] = $this->atts['density'];
53 $density['tablet'] = $this->atts['density'];
54 $density['mobile'] = $this->atts['density'];
55 }
56 else {
57 $density['desktop'] = $this->core->get_option( 'tiles_density', 'high' );
58 $density['tablet'] = $this->core->get_option( 'tiles_density_tablet', 'medium' );
59 $density['mobile'] = $this->core->get_option( 'tiles_density_mobile', 'low' );
60 }
61
62 wp_localize_script('mgl-js', 'mgl_settings',
63 array(
64 'infinite_buffer' => $this->core->get_option( 'infinite_buffer', 0 ),
65 'disable_right_click' => !$this->core->get_option( 'right_click', false ),
66 'tiles' => array( 'density' => $density ),
67 'api_url' => get_rest_url( null, '/meow-gallery/v1/' ),
68 'rest_nonce' => wp_create_nonce( 'wp_rest' ),
69 'options' => $this->core->get_all_options(),
70 )
71 );
72 }
73
74 /*
75 For Yoast SEO
76 */
77
78 function wpseo_siteimap( $images, $post_id ) {
79 $galleries = get_post_galleries( $post_id );
80 $images_ids = array();
81 foreach ( $galleries as $gallery ) {
82 preg_match_all( '/wp\-image\-([0-9]{1,16})/', $gallery, $matches );
83 if ( !empty( $matches ) ) {
84 foreach ( $matches[1] as $id )
85 array_push( $images_ids, $id );
86 }
87 }
88 $images_ids = array_unique( $images_ids );
89 foreach ( $images_ids as $id ) {
90 array_push( $images, array(
91 'src' => wp_get_attachment_url( $id ),
92 'title' => get_the_title( $id ),
93 'alt' => get_post_meta( $id, '_wp_attachment_image_alt', true )
94 ) );
95 }
96 return $images;
97 }
98
99 }
100
101 ?>
102