PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.4
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.4
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / inc / admin / enqueue.php

enqueue.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.4, at inc/admin/enqueue.php

257 lines 9.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
3
4 /**
5 * Add some CSS on the whole administration
6 *
7 * @since 1.0
8 */
9 add_action( 'admin_print_styles', '_imagify_admin_print_styles' );
10 function _imagify_admin_print_styles() {
11 global $pagenow;
12 $current_screen = get_current_screen();
13 $css_ext = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.css' : '.min.css';
14 $js_ext = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.js' : '.min.js';
15
16 wp_register_style(
17 'imagify-css-admin',
18 IMAGIFY_ASSETS_CSS_URL . 'admin' . $css_ext,
19 array(),
20 IMAGIFY_VERSION
21 );
22
23 wp_register_style(
24 'imagify-css-sweetalert',
25 IMAGIFY_ASSETS_CSS_URL . 'sweetalert' . $css_ext,
26 array(),
27 IMAGIFY_VERSION
28 );
29
30 wp_register_style(
31 'imagify-css-twentytwenty',
32 IMAGIFY_ASSETS_CSS_URL . 'twentytwenty' . $css_ext,
33 array(),
34 IMAGIFY_VERSION
35 );
36
37 wp_register_script(
38 'imagify-js-async',
39 IMAGIFY_ASSETS_JS_URL . 'imagify.min.js',
40 array(),
41 IMAGIFY_VERSION,
42 true
43 );
44
45 wp_register_script(
46 'imagify-js-admin',
47 IMAGIFY_ASSETS_JS_URL . 'admin' . $js_ext,
48 array(),
49 IMAGIFY_VERSION,
50 true
51 );
52
53 wp_register_script(
54 'imagify-js-options',
55 IMAGIFY_ASSETS_JS_URL . 'options' . $js_ext,
56 array(),
57 IMAGIFY_VERSION,
58 true
59 );
60
61 wp_register_script(
62 'imagify-js-upload',
63 IMAGIFY_ASSETS_JS_URL . 'upload' . $js_ext,
64 array( 'jquery' ),
65 IMAGIFY_VERSION,
66 true
67 );
68
69 wp_register_script(
70 'imagify-js-sweetalert',
71 IMAGIFY_ASSETS_JS_URL . 'sweetalert.min.js',
72 array( 'jquery' ),
73 IMAGIFY_VERSION,
74 true
75 );
76
77 wp_register_script(
78 'imagify-js-chart',
79 IMAGIFY_ASSETS_JS_URL . 'chart.min.js',
80 array(),
81 IMAGIFY_VERSION,
82 true
83 );
84
85 wp_register_script(
86 'imagify-js-bulk',
87 IMAGIFY_ASSETS_JS_URL . 'bulk' . $js_ext,
88 array( 'jquery', 'imagify-js-chart' ),
89 IMAGIFY_VERSION,
90 true
91 );
92
93 wp_register_script(
94 'imagify-js-twentytwenty',
95 IMAGIFY_ASSETS_JS_URL . 'jquery.twentytwenty' . $js_ext,
96 array( 'jquery', 'imagify-js-event-move', 'imagify-js-chart' ),
97 IMAGIFY_VERSION,
98 true
99 );
100 wp_register_script(
101 'imagify-js-event-move',
102 IMAGIFY_ASSETS_JS_URL . 'jquery.event.move' . $js_ext,
103 array( 'jquery' ),
104 IMAGIFY_VERSION,
105 true
106 );
107
108 /*
109 * Styles loaded in the whole admnistration
110 */
111 wp_enqueue_style( 'imagify-css-admin' );
112 wp_enqueue_style( 'imagify-css-sweetalert' );
113
114 /*
115 * Scripts loaded in the whole admnistration
116 */
117 wp_enqueue_script( 'imagify-js-sweetalert' );
118 wp_enqueue_script( 'imagify-js-admin' );
119
120 $admin_data = array(
121 'signupTitle' => __( 'Let\'s get you started!', 'imagify' ),
122 'signupText' => __( 'Enter your email to get an API key:', 'imagify' ),
123 'signupConfirmButtonText' => __( 'Sign Up', 'imagify' ),
124 'signupErrorEmptyEmail' => __( 'You need to specify an email!', 'imagify' ),
125 'signupSuccessTitle' => __( 'Congratulations!', 'imagify' ),
126 'signupSuccessText' => __( 'Your account has been succesfully created. Please check your mailbox, you are going to receive an email with API key.', 'imagify' ),
127 'saveApiKeyTitle' => __( 'Connect to Imagify!', 'imagify' ),
128 'saveApiKeyText' => __( 'Paste your API key below:', 'imagify' ),
129 'saveApiKeyConfirmButtonText' => __( 'Connect me', 'imagify' ),
130 'waitApiKeyCheckText' => __( 'Check in progress...', 'imagify' ),
131 'ApiKeyCheckSuccessTitle' => __( 'Congratulations!', 'imagify' ),
132 'ApiKeyCheckSuccessText' => __( 'Your API key is valid. You can now configure the Imagify settings to optimize your images.', 'imagify' ),
133 'ValidApiKeyText' => __( 'Your API key is valid.', 'imagify' )
134
135 );
136 wp_localize_script( 'imagify-js-admin', 'imagify', $admin_data );
137 wp_enqueue_script( 'imagify-js-admin' );
138
139 /*
140 * Scripts loaded in /wp-admin/options-general.php?page=imagify
141 */
142 if ( isset( $current_screen ) && ( 'settings_page_imagify' === $current_screen->base || 'settings_page_imagify-network' === $current_screen->base ) ) {
143 wp_enqueue_script( 'imagify-js-chart' );
144 wp_enqueue_script( 'imagify-js-event-move' );
145 wp_enqueue_script( 'imagify-js-twentytwenty' );
146 wp_enqueue_script( 'imagify-js-options' );
147 wp_enqueue_style( 'imagify-css-twentytwenty' );
148
149 $options_data = array(
150 'noBackupTitle' => __( 'Don\'t Need a Parachute?', 'imagify' ),
151 'noBackupText' => __( 'If you keep this option deactivated, you won\'t be able to re-optimize your images to another compression level and restore your original images in case of need.', 'imagify' )
152 );
153
154 wp_localize_script( 'imagify-js-options', 'imagifyOptions', $options_data );
155 }
156
157 /**
158 * Scripts loaded in /wp-admin/upload.php and post.php
159 */
160 if ( isset( $current_screen ) && ( 'upload' === $current_screen->base || 'post' === $current_screen->base ) ) {
161 $upload_data = array(
162 'bulkActionsLabels' => array(
163 'optimize' => __( 'Optimize', 'imagify' ),
164 'restore' => __( 'Restore Original', 'imagify' ),
165 ),
166 );
167 wp_localize_script( 'imagify-js-upload', 'imagifyUpload', $upload_data );
168 wp_enqueue_script( 'imagify-js-chart' );
169 wp_enqueue_script( 'imagify-js-upload' );
170 }
171
172 /**
173 * Scripts loaded in /wp-admin/post.php (for attachment post type)
174 */
175 if ( isset( $current_screen ) && 'post' === $current_screen->base && 'attachment' === $current_screen->post_type ) {
176 wp_localize_script( 'imagify-js-twentytwenty', 'imagifyTTT', array(
177 'labels' => array(
178 'original_l' => __( 'Original Image', 'imagify' ),
179 'optimized_l' => __( 'Optimized Image', 'imagify' ),
180 'compare' => __( 'Compare Original VS Optimized', 'imagify' ),
181 'close' => __( 'Close', 'imagify' ),
182 'filesize' => __( 'File Size:', 'imagify' ),
183 'saving' => __( 'Original Saving:', 'imagify' ),
184 )
185 ));
186 wp_enqueue_script( 'imagify-js-chart' );
187 wp_enqueue_script( 'imagify-js-event-move' );
188 wp_enqueue_script( 'imagify-js-twentytwenty' );
189 wp_enqueue_style( 'imagify-css-twentytwenty' );
190 }
191
192 /**
193 * Scripts loaded in /wp-admin/upload.php?page=imagify-bulk-optimization
194 */
195 if ( isset( $current_screen ) && 'media_page_imagify-bulk-optimization' === $current_screen->base ) {
196 $user = get_imagify_user();
197 $bulk_data = array(
198 'waitTitle' => __( 'Please wait...', 'imagify' ),
199 'waitText' => __( 'We are trying to get your unoptimized images, it may take time depending on the number of images.', 'imagify' ),
200 'waitImageUrl' => IMAGIFY_ASSETS_IMG_URL . 'popin-loader.svg',
201 'getUnoptimizedImagesErrorTitle' => __( 'Oops, There is something wrong!', 'imagify' ),
202 'getUnoptimizedImagesErrorText' => __( 'An unknow error occurred when we tried to get all your unoptimized images. Try again and if the issue still persist, please contact us!', 'imagify' ),
203 'overviewChartLabels' => array(
204 'optimized' => __( 'Optimized', 'imagify' ),
205 'unoptimized' => __( 'Unoptimized', 'imagify' ),
206 'error' => __( 'Error', 'imagify' ),
207 ),
208 'overQuotaTitle' => __( 'Oops, It\'s Over!', 'imagify' ),
209 'noAttachmentToOptimizeTitle' => __( 'Hold on!', 'imagify' ),
210 'noAttachmentToOptimizeText' => __( 'All your images have been optimized by Imagify. Congratulations!', 'imagify' ),
211 'pluginURL' => 'https://wordpress.org/plugins/imagify',
212 'textToShare' => __( 'Discover @imagify, the new compression tool to optimize your images for free. I saved %1$s out of %2$s!', 'imagify' ),
213 'totalOptimizedAttachments' => imagify_count_optimized_attachments(),
214 'totalUnoptimizedAttachments' => imagify_count_unoptimized_attachments(),
215 'totalErrorsAttachments' => imagify_count_error_attachments(),
216 'processing' => __( 'Imagify is still processing. Are you sure you want to leave this page?', 'imagify' ),
217 );
218
219 if ( imagify_valid_key() ) {
220 if ( is_wp_error( $user ) ) {
221 $bulk_data['overQuotaText'] = sprintf( __( 'To continue to optimize your images, log in to your Imagify account to %sbuy a pack or subscribe to a plan%s.', 'imagify' ), '<a href="' . IMAGIFY_APP_MAIN . '/#/subscription' . '">', '</a>' );
222 }
223 else {
224 $bulk_data['overQuotaText'] = sprintf( __( 'You have consumed all your credit for this month. You will have <strong>%s back on %s</strong>.', 'imagify' ), size_format( $user->quota * 1048576 ), date_i18n( __( 'F j, Y' ), strtotime( $user->next_date_update ) ) ) . '<br/><br/>' . sprintf( __( 'To continue to optimize your images, log in to your Imagify account to %sbuy a pack or subscribe to a plan%s.', 'imagify' ), '<a href="' . IMAGIFY_APP_MAIN . '/#/subscription' . '">', '</a>' );
225 }
226 }
227
228 wp_localize_script( 'imagify-js-bulk', 'imagifyBulk', $bulk_data );
229 wp_enqueue_script( 'imagify-js-chart' );
230 wp_enqueue_script( 'imagify-js-async' );
231 wp_enqueue_script( 'imagify-js-bulk' );
232 }
233 }
234
235 /**
236 * Add Intercom on Options page an Bulk Optimization
237 *
238 * @since 1.0
239 */
240 add_action( 'admin_footer-media_page_imagify-bulk-optimization', '_imagify_admin_print_intercom' );
241 add_action( 'admin_footer-settings_page_imagify', '_imagify_admin_print_intercom' );
242 function _imagify_admin_print_intercom() {
243 $user = get_imagify_user();
244
245 if ( ! imagify_valid_key() || empty( $user->is_intercom ) ) {
246 return;
247 }
248 ?>
249 <script>
250 window.intercomSettings = {
251 app_id: "cd6nxj3z",
252 user_id: <?php echo (int) $user->id; ?>,
253 };
254 </script>
255 <script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/cd6nxj3z';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()</script>
256 <?php
257 }