PluginProbe
Easy Image Gallery / trunk
Easy Image Gallery vtrunk
1.0.4 1.0.5 1.0.6 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 trunk 1.0.1 1.0.2 All 26 releases
easy-image-gallery / includes / scripts.php

scripts.php in Easy Image Gallery trunk, at includes/scripts.php

242 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 /**
8 * Scripts
9 *
10 * @since 1.0
11 */
12 function easy_image_gallery_scripts() {
13
14 global $post;
15
16 // return if post object is not set
17 if ( ! isset( $post->ID ) ) {
18 return;
19 }
20
21 // JS
22 wp_register_script( 'pretty-photo', EASY_IMAGE_GALLERY_URL . 'includes/lib/prettyphoto/jquery.prettyPhoto.js', array( 'jquery' ), EASY_IMAGE_GALLERY_VERSION, true );
23 wp_register_script( 'fancybox', EASY_IMAGE_GALLERY_URL . 'includes/lib/fancybox/jquery.fancybox.min.js', array( 'jquery' ), EASY_IMAGE_GALLERY_VERSION, true );
24 wp_register_script( 'luminous', EASY_IMAGE_GALLERY_URL . 'includes/lib/luminous/dist/Luminous.min.js', array( 'jquery' ), EASY_IMAGE_GALLERY_VERSION, false );
25
26 // CSS
27 wp_register_style( 'pretty-photo', EASY_IMAGE_GALLERY_URL . 'includes/lib/prettyphoto/prettyPhoto.css', '', EASY_IMAGE_GALLERY_VERSION, 'screen' );
28 wp_register_style( 'fancybox', EASY_IMAGE_GALLERY_URL . 'includes/lib/fancybox/jquery.fancybox.min.css', '', EASY_IMAGE_GALLERY_VERSION, 'screen' );
29
30 // create a new 'css/easy-image-gallery.css' in your child theme to override CSS file completely
31 if ( file_exists( get_stylesheet_directory() . '/css/easy-image-gallery.css' ) ) {
32 wp_register_style( 'easy-image-gallery', get_stylesheet_directory_uri() . '/css/easy-image-gallery.css', '', EASY_IMAGE_GALLERY_VERSION, 'screen' );
33 } else {
34 wp_register_style( 'easy-image-gallery', EASY_IMAGE_GALLERY_URL . 'includes/css/easy-image-gallery.css', '', EASY_IMAGE_GALLERY_VERSION, 'screen' );
35 }
36
37 // post type is not allowed, return
38 if ( ! easy_image_gallery_allowed_post_type() ) {
39 return;
40 }
41
42 // needs to load only when there is a gallery
43 if ( easy_image_gallery_is_gallery() ) {
44 wp_enqueue_style( 'easy-image-gallery' );
45 }
46
47 $linked_images = true;
48 $gutenberg_galleries = easy_image_gallery_if_gutenberg_block();
49 $known_lightboxes = array( 'pretty-photo', 'fancybox', 'luminous' );
50
51 if ( ! empty( $gutenberg_galleries ) ) {
52 foreach ( $gutenberg_galleries as $value ) {
53 if ( ! in_array( $value, $known_lightboxes, true ) ) {
54 continue;
55 }
56
57 if ( 'luminous' !== $value ) {
58 wp_enqueue_style( $value );
59 }
60
61 wp_enqueue_script( $value );
62 }
63 }
64
65 // only load the JS if gallery images are linked or the featured image is linked
66 if ( $linked_images ) {
67
68 $lightbox = easy_image_gallery_get_lightbox();
69
70 // Scripts that we need to remove for proper plugin functionality
71 wp_dequeue_script( 'magnific-popup' ); // OceanWP theme
72 wp_dequeue_script( 'oceanwp-lightbox' ); // OceanWP theme
73
74 switch ( $lightbox ) {
75
76 case 'prettyphoto':
77 // CSS
78 wp_enqueue_style( 'pretty-photo' );
79
80 // JS
81 wp_enqueue_script( 'pretty-photo' );
82
83 break;
84
85 case 'fancybox':
86 // CSS
87 wp_enqueue_style( 'fancybox' );
88
89 // JS
90 wp_enqueue_script( 'fancybox' );
91
92 break;
93
94 case 'luminous':
95 // JS
96 wp_enqueue_script( 'luminous' );
97
98 break;
99
100 default:
101 break;
102 }
103
104 // allow developers to load their own scripts here
105 do_action( 'easy_image_gallery_scripts' );
106
107 }
108
109 }
110 add_action( 'wp_enqueue_scripts', 'easy_image_gallery_scripts', 20 );
111
112 /**
113 * Checking if we have the Easy Image Gallery Gutenberg block in the post content
114 *
115 * @since 1.4.0
116 */
117 function easy_image_gallery_if_gutenberg_block() {
118 global $post;
119
120 if ( ! function_exists( 'has_blocks' ) ) {
121 return false;
122 }
123
124 $arr_lightboxes = array();
125
126 if ( has_blocks( $post->post_content ) ) {
127 $blocks = parse_blocks( $post->post_content );
128 $arr_attrs = array_column( $blocks, 'attrs' );
129
130 if ( in_array( 'devrix/easy-image-gallery-block', array_column( $blocks, 'blockName' ) ) ) {
131 $arr_lightboxes = array_column( $arr_attrs, 'lightbox_option' );
132 }
133 }
134
135 return array_unique( $arr_lightboxes );
136 }
137
138
139 /**
140 * JS
141 *
142 * @since 1.0
143 */
144 function easy_image_gallery_js() {
145
146 if ( ! easy_image_gallery_allowed_post_type() ) {
147 return;
148 }
149
150 //if ( is_singular() ) : ?>
151
152 <?php
153
154 $lightbox = easy_image_gallery_get_lightbox();
155
156 switch ( $lightbox ) {
157
158 case 'prettyphoto':
159 ob_start();
160 ?>
161 <script>
162 jQuery(document).ready(function() {
163 jQuery("a[rel^='prettyPhoto']").prettyPhoto({
164 social_tools : false,
165 show_title : false
166 });
167 });
168 </script>
169 <?php
170 $js = ob_get_clean();
171 $js = apply_filters( 'easy_image_gallery_prettyphoto_js', $js );
172 if ( preg_match( '/<script\b[^>]*>(.*)<\/script>/is', $js, $matches ) ) {
173 $js = $matches[1];
174 }
175 wp_print_inline_script_tag( trim( $js ) );
176 ?>
177
178 <?php
179 break;
180
181 case 'fancybox':
182 ob_start();
183 ?>
184 <script>
185 jQuery(document).ready(function() {
186
187 jQuery("a.eig-popup:not([rel])").attr('rel', 'fancybox').fancybox({
188 'transitionIn' : 'elastic',
189 'transitionOut' : 'elastic',
190 'speedIn' : 200,
191 'speedOut' : 200,
192 'overlayShow' : false
193 });
194
195 });
196 </script>
197 <?php
198 $js = ob_get_clean();
199 $js = apply_filters( 'easy_image_gallery_fancybox_js', $js );
200 if ( preg_match( '/<script\b[^>]*>(.*)<\/script>/is', $js, $matches ) ) {
201 $js = $matches[1];
202 }
203 wp_print_inline_script_tag( trim( $js ) );
204 ?>
205
206 <?php
207 break;
208
209 default:
210 break;
211 }
212
213 // allow developers to add/modify JS
214 do_action( 'easy_image_gallery_js', $lightbox );
215 ?>
216
217 <?php //endif; ?>
218
219 <?php
220 }
221 add_action( 'wp_footer', 'easy_image_gallery_js', 20 );
222
223
224 function easy_image_gallery_admin_scripts() {
225 wp_enqueue_script(
226 'repeatable-fields',
227 EASY_IMAGE_GALLERY_URL . 'includes/lib/repeatable-fields.js',
228 array( 'jquery', 'jquery-ui-core' ),
229 EASY_IMAGE_GALLERY_VERSION,
230 false
231 );
232
233 wp_enqueue_style(
234 'easy_image_gallery_admin_css',
235 EASY_IMAGE_GALLERY_URL . 'includes/css/easy-image-gallery-admin.css',
236 array(),
237 EASY_IMAGE_GALLERY_VERSION
238 );
239 }
240
241 add_action( 'admin_enqueue_scripts', 'easy_image_gallery_admin_scripts' );
242