PluginProbe
Meow Gallery / 4.3.0
Meow Gallery v4.3.0
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 4.3.0, at classes/run.php

86 lines 2.6 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
7 public function __construct( $core ) {
8 $this->core = $core;
9 add_shortcode( 'gallery', array( $core, 'gallery' ) );
10 add_shortcode( 'meow-gallery', array( $core, 'gallery' ) );
11
12 if ( is_admin() ) {
13 add_action( 'init', array( $this, 'enqueue_scripts' ) );
14 }
15 else {
16 add_action( 'mgl_gallery_created', array( $this, 'enqueue_scripts' ), 10, 0 );
17 }
18
19 // Yoast: Some people really want this, but it needs to be reviewed as Yoast changed its API
20 //add_filter( 'wpseo_sitemap_urlimages', array( $this, 'wpseo_siteimap' ), 10, 2 );
21 }
22
23 function enqueue_scripts() {
24 // Only need to load the scripts once.
25 if ( $this->isEnqueued ) {
26 return;
27 }
28 $this->isEnqueued = true;
29
30 // Load the JS for Meow Gallery
31 $physical_file = MGL_PATH . '/app/galleries.js';
32 $cache_buster = file_exists( $physical_file ) ? filemtime( $physical_file ) : MGL_VERSION;
33 wp_enqueue_script( 'mgl-js', plugins_url( '/app/galleries.js', __DIR__ ), array(), $cache_buster, true );
34
35 // TODO: This should be moved in a getter (since it is also used by tiles.php)
36 $density = [];
37 if ( isset( $this->atts['density'] ) ) {
38 $density['desktop'] = $this->atts['density'];
39 $density['tablet'] = $this->atts['density'];
40 $density['mobile'] = $this->atts['density'];
41 }
42 else {
43 $density['desktop'] = $this->core->get_option( 'tiles_density', 'high' );
44 $density['tablet'] = $this->core->get_option( 'tiles_density_tablet', 'medium' );
45 $density['mobile'] = $this->core->get_option( 'tiles_density_mobile', 'low' );
46 }
47
48 wp_localize_script('mgl-js', 'mgl_settings',
49 array(
50 'infinite_buffer' => $this->core->get_option( 'infinite_buffer', 0 ),
51 'disable_right_click' => !$this->core->get_option( 'right_click', false ),
52 'tiles' => array( 'density' => $density )
53 )
54 );
55 wp_enqueue_style( 'mgl-css', plugins_url( '/app/style.min.css', __DIR__ ), null, $cache_buster );
56 }
57
58 /*
59 For Yoast SEO
60 */
61
62 function wpseo_siteimap( $images, $post_id ) {
63 $galleries = get_post_galleries( $post_id );
64 $images_ids = array();
65 foreach ( $galleries as $gallery ) {
66 preg_match_all( '/wp\-image\-([0-9]{1,16})/', $gallery, $matches );
67 if ( !empty( $matches ) ) {
68 foreach ( $matches[1] as $id )
69 array_push( $images_ids, $id );
70 }
71 }
72 $images_ids = array_unique( $images_ids );
73 foreach ( $images_ids as $id ) {
74 array_push( $images, array(
75 'src' => wp_get_attachment_url( $id ),
76 'title' => get_the_title( $id ),
77 'alt' => get_post_meta( $id, '_wp_attachment_image_alt', true )
78 ) );
79 }
80 return $images;
81 }
82
83 }
84
85 ?>
86