PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
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
← All changes | inc/functions/admin-ui.php +488 -597 1.5 → trunk View file →
@@ -1,712 +1,603 @@
1 1 <?php
2 -defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
2 +defined( 'ABSPATH' ) || exit;
3 3
4 -/*
5 - * Get the optimization data list for a specific attachment.
4 +/**
5 + * Get the optimization data list for a specific media.
6 6 *
7 - * @since 1.0
7 + * @since 1.0
8 + * @since 1.9 Function signature changed.
8 9 * @author Jonathan Buttigieg
9 10 *
10 - * @param object $attachment The attachment object.
11 - * @return string The output to print.
11 + * @param \Imagify\Optimization\Process\ProcessInterface $process The optimization process object.
12 + * @return string The output to print.
12 13 */
13 -function get_imagify_attachment_optimization_text( $attachment, $context = 'wp' ) {
14 - global $pagenow;
15 -
16 - $attachment_id = $attachment->id;
17 - $data = $attachment->get_data();
18 - $output = ( 'post.php' != $pagenow ) ? '<ul class="imagify-datas-list">' : '';
19 - $output_before = ( 'post.php' != $pagenow ) ? '<li class="imagify-data-item">' : '<div class="misc-pub-section misc-pub-imagify imagify-data-item">';
20 - $output_after = ( 'post.php' != $pagenow ) ? '</li>' : '</div>';
21 - $reoptimize_output = '';
22 -
23 - if ( $error = get_imagify_attachment_error_text( $attachment, $context ) ) {
24 - $error = ( 'post.php' === $pagenow ) ? $output_before . $error . $output_after : $error;
25 - return $error;
14 +function get_imagify_attachment_optimization_text( $process ) {
15 + if ( ! $process->is_valid() ) {
16 + return '';
26 17 }
27 18
28 - $optimization_level = $attachment->get_optimization_level_label();
19 + $is_media_page = Imagify_Views::get_instance()->is_media_page();
20 + $is_library_page = Imagify_Views::get_instance()->is_wp_library_page();
21 + $output = $is_media_page ? '' : '<ul class="imagify-datas-list" id="imagify_data_sum">';
22 + $output_before = $is_media_page ? '' : '<li class="imagify-data-item">';
23 + $output_after = $is_media_page ? '<br/>' : '</li>';
24 + $reoptimize_link = get_imagify_attachment_reoptimize_link( $process );
25 + $reoptimize_link .= get_imagify_attachment_optimize_missing_thumbnails_link( $process );
26 + $reoptimize_link .= get_imagify_attachment_generate_nextgen_versions_link( $process );
27 + $reoptimize_link .= get_imagify_attachment_delete_nextgen_versions_link( $process );
28 + $reoptimize_output = $reoptimize_link ? $reoptimize_link : '';
29 + $reoptimize_output_before = '<div class="imagify-datas-actions-links">';
30 + $reoptimize_output_after = '</div><!-- .imagify-datas-actions-links -->';
31 + $error = get_imagify_attachment_error_text( $process );
32 + $media = $process->get_media();
29 33
30 - if ( imagify_valid_key() && $attachment->has_backup() ) {
31 - $reoptimize_link = get_imagify_attachment_reoptimize_link( $attachment, $context );
32 - $reoptimize_output = ( $reoptimize_link ) ? $reoptimize_link : '';
34 + if ( $error ) {
35 + if ( ! $is_media_page && $reoptimize_link && $media->has_backup() ) {
36 + $reoptimize_output .= '<span class="attachment-has-backup hidden"></span>';
37 + }
38 +
39 + $reoptimize_output = $reoptimize_output_before . $reoptimize_output . $reoptimize_output_after;
40 +
41 + return $is_media_page ? $output_before . $error . $reoptimize_output . $output_after : $error . $reoptimize_output;
33 42 }
34 43
35 - if ( 'post.php' !== $pagenow ) {
36 - $output .= $output_before . '<span class="data">' . __( 'New Filesize:', 'imagify' ) . '</span> <strong class="big">' . size_format( $data['sizes']['full']['optimized_size'], 2 ) . '</strong>' . $output_after;
44 + $data = $process->get_data();
45 + $optimized_data = $data->get_optimization_data();
46 + $attachment_id = $media->get_id();
47 + $optimization_level = imagify_get_optimization_level_label( $data->get_optimization_level() );
48 +
49 + if ( ! $is_media_page ) {
50 + $output .= $output_before . '<span class="data">' . __( 'New Filesize:', 'imagify' ) . '</span> <strong class="big">' . $data->get_optimized_size() . '</strong>' . $output_after;
37 51 }
38 52
39 - $chart = '<span class="imagify-chart">
40 - <span class="imagify-chart-container">
41 - <canvas id="imagify-consumption-chart" width="15" height="15"></canvas>
42 - </span>
43 - </span>';
53 + if ( key_exists( 'message', $optimized_data ) && $optimized_data['message'] ) {
54 + $output .= $output_before . '<span class="data">' . __( 'Convert:', 'imagify' ) . '</span> <strong class="big">' . $optimized_data['message'] . '</strong>' . $output_after;
55 + }
44 56
45 - $output .= $output_before . '<span class="data">' . __( 'Original Saving:', 'imagify' ) . '</span> <strong>
46 - ' . ( ( 'post.php' != $pagenow ) ? $chart : '' ) . '<span class="imagify-chart-value">' . $data['sizes']['full']['percent'] . '</span>%</strong>' . $output_after;
57 + $chart = '';
47 58
48 - // more details section
49 - if ( 'post.php' != $pagenow ) {
50 - // new list
59 + if ( ! $is_media_page ) {
60 + if ( ! $is_library_page ) {
61 + // No need to print this on the library page, the event whould be triggered before the handler is attached (the JS file is loaded in the footer).
62 + $chart = '<script type="text/javascript">jQuery( window ).trigger( "canvasprinted.imagify", [ ".imagify-consumption-chart-' . $attachment_id . '" ] ); </script>';
63 + }
64 +
65 + $chart = '<span class="imagify-chart">
66 + <span class="imagify-chart-container">
67 + <canvas class="imagify-consumption-chart imagify-consumption-chart-' . $attachment_id . '" width="15" height="15"></canvas>
68 + ' . $chart . '
69 + </span>
70 + </span>';
71 + }
72 +
73 + $output .= $output_before;
74 + $output .= '<span class="data">' . __( 'Original Saving:', 'imagify' ) . '</span> ';
75 + $output .= '<strong>' . $chart . '<span class="imagify-chart-value">' . $data->get_saving_percent() . '</span>%</strong>';
76 + $output .= $output_after;
77 +
78 + // More details section.
79 + if ( ! $is_media_page ) {
80 + // New list.
51 81 $output .= '</ul>';
52 - $output .= '<p class="imagify-datas-more-action"><a href="#imagify-view-details-' . $attachment_id . '" data-close="' . __( 'Close details', 'imagify' ) . '" data-open="' . __( 'View details', 'imagify' ) . '"><span class="the-text">' . __( 'View details', 'imagify' ) . '</span><span class="dashicons dashicons-arrow-down-alt2"></span></a></p>';
82 + $output .= '<p class="imagify-datas-more-action">';
83 + $output .= '<a href="#imagify-view-details-' . $attachment_id . '" data-close="' . __( 'Close details', 'imagify' ) . '" data-open="' . __( 'View details', 'imagify' ) . '">';
84 + $output .= '<span class="the-text">' . __( 'View details', 'imagify' ) . '</span>';
85 + $output .= '<span class="dashicons dashicons-arrow-down-alt2"></span>';
86 + $output .= '</a>';
87 + $output .= '</p>';
53 88 $output .= '<ul id="imagify-view-details-' . $attachment_id . '" class="imagify-datas-list imagify-datas-details">';
54 89
55 - // not in metabox
56 - $output .= $output_before . '<span class="data">' . __( 'Original Filesize:', 'imagify' ) . '</span> <strong class="original">' . $attachment->get_original_size() . '</strong>' . $output_after;
90 + // Not in metabox.
91 + $output .= $output_before . '<span class="data">' . __( 'Original Filesize:', 'imagify' ) . '</span> <strong class="original">' . $data->get_original_size() . '</strong>' . $output_after;
57 92 }
58 93
59 94 $output .= $output_before . '<span class="data">' . __( 'Level:', 'imagify' ) . '</span> <strong>' . $optimization_level . '</strong>' . $output_after;
60 95
61 - if ( $total_optimized_thumbnails = $attachment->get_optimized_sizes_count() ) {
62 - $output .= $output_before . '<span class="data">' . __( 'Thumbnails Optimized:', 'imagify' ) . '</span> <strong>' . $total_optimized_thumbnails . '</strong>' . $output_after;
63 - $output .= $output_before . '<span class="data">' . __( 'Overall Saving:', 'imagify' ) . '</span> <strong>' . $data['stats']['percent'] . '%</strong>' . $output_after;
96 + if ( $media->is_image() ) {
97 + $has_nextgen = $process->has_next_gen() ? __( 'Yes', 'imagify' ) : __( 'No', 'imagify' );
98 +
99 + if ( $process->has_next_gen() ) {
100 + $has_nextgen = $process->is_full_next_gen() ? __( 'Yes', 'imagify' ) : __( 'Partially', 'imagify' );
101 + }
102 + $output .= $output_before . '<span class="data">' . __( 'Next-Gen generated:', 'imagify' ) . '</span> <strong class="big">' . esc_html( $has_nextgen ) . '</strong>' . $output_after;
103 +
104 + // When the API permanently refused the conversion, show the reason it gave.
105 + $nextgen_reason = '';
106 +
107 + if ( ! empty( $optimized_data['sizes'] ) && is_array( $optimized_data['sizes'] ) ) {
108 + foreach ( $optimized_data['sizes'] as $size_data ) {
109 + if ( ! empty( $size_data['permanent_error'] ) && ! empty( $size_data['error'] ) ) {
110 + $nextgen_reason = $size_data['error'];
111 + break;
112 + }
113 + }
114 + }
115 +
116 + if ( $nextgen_reason ) {
117 + $output .= $output_before . '<span class="data">' . __( 'Next-Gen status:', 'imagify' ) . '</span> <strong>' . esc_html( $nextgen_reason ) . '</strong>' . $output_after;
118 + }
119 +
120 + $total_optimized_thumbnails = $data->get_optimized_sizes_count();
121 +
122 + if ( $total_optimized_thumbnails ) {
123 + $output .= $output_before . '<span class="data">' . __( 'Thumbnails Optimized:', 'imagify' ) . '</span> <strong>' . $total_optimized_thumbnails . '</strong>' . $output_after;
124 + $output .= $output_before . '<span class="data">' . __( 'Overall Saving:', 'imagify' ) . '</span> <strong>' . $data->get_overall_saving_percent() . '%</strong>' . $output_after;
125 + }
64 126 }
65 127
66 - // end of list
67 - $output .= ( 'post.php' != $pagenow ) ? '</ul>' : '';
128 + // End of list.
129 + $output .= $is_media_page ? '' : '</ul>';
68 130
69 - // actions section
70 - $output .= ( 'post.php' != $pagenow ) ? '' : $output_before;
71 - $output .= '<div class="imagify-datas-actions-links">';
131 + // Actions section.
132 + $output .= $is_media_page ? $output_before : '';
133 + $output .= $reoptimize_output_before;
72 134 $output .= $reoptimize_output;
73 -
74 - if ( $attachment->has_backup() ) {
75 - $args = array(
76 - 'attachment_id' => $attachment_id,
77 - 'context' => $context
135 +
136 + if ( $media->has_backup() ) {
137 + $url = get_imagify_admin_url(
138 + 'restore',
139 + [
140 + 'attachment_id' => $attachment_id,
141 + 'context' => $media->get_context(),
142 + ]
78 143 );
79 - $class = ( 'post.php' !== $pagenow ) ? 'button-imagify-restore' : '';
80 - $output .= '<a id="imagify-restore-' . $attachment_id . '" href="' . get_imagify_admin_url( 'restore-upload', $args ) . '" class="' . $class . '" data-waiting-label="' . esc_attr__( 'Restoring...', 'imagify' ) . '"><span class="dashicons dashicons-image-rotate"></span>' . __( 'Restore Original', 'imagify' ) . '</a>';
81 -
82 - if ( 'upload.php' != $pagenow ) {
83 - $image = wp_get_attachment_image_src( $attachment_id, 'full' );
84 -
85 - $output .= '<input id="imagify-original-src" type="hidden" value="' . $attachment->get_backup_url() . '">';
86 - $output .= '<input id="imagify-original-size" type="hidden" value="' . $attachment->get_original_size() . '">';
87 - $output .= '<input id="imagify-full-src" type="hidden" value="' . $image[0] . '">';
88 - $output .= '<input id="imagify-full-width" type="hidden" value="' . $image[1] . '">';
89 - $output .= '<input id="imagify-full-height" type="hidden" value="' . $image[2] . '">';
144 +
145 + $output .= Imagify_Views::get_instance()->get_template(
146 + 'button/restore',
147 + [
148 + 'url' => $url,
149 + 'atts' => [
150 + 'class' => $is_media_page ? '' : null,
151 + ],
152 + ]
153 + );
154 +
155 + if ( ! $is_library_page ) {
156 + $output .= '<input id="imagify-original-src" type="hidden" value="' . esc_url( $media->get_backup_url() ) . '">';
157 + $output .= '<input id="imagify-original-size" type="hidden" value="' . $data->get_original_size() . '">';
158 + $output .= '<input id="imagify-full-src" type="hidden" value="' . esc_url( $media->get_fullsize_url() ) . '">';
159 +
160 + if ( $media->is_image() ) {
161 + $dimensions = $media->get_dimensions();
162 +
163 + $output .= '<input id="imagify-full-width" type="hidden" value="' . $dimensions['width'] . '">';
164 + $output .= '<input id="imagify-full-height" type="hidden" value="' . $dimensions['height'] . '">';
165 + }
90 166 }
91 167 }
92 -
93 - $output .= '</div><!-- .imagify-datas-actions-links -->';
94 - $output .= ( 'post.php' != $pagenow ) ? '' : $output_after;
95 168
169 + $output .= $reoptimize_output_after;
170 +
96 171 return $output;
97 172 }
98 173
99 -/*
174 +/**
100 175 * Get the error message for a specific attachment.
101 176 *
102 - * @since 1.0
177 + * @since 1.0
178 + * @since 1.9 Function signature changed.
103 179 * @author Jonathan Buttigieg
104 180 *
105 - * @param object $attachment The attachement object.
106 - * @return string The output to print.
181 + * @param ProcessInterface $process The optimization process object.
182 + * @return string The output to print.
107 183 */
108 -function get_imagify_attachment_error_text( $attachment, $context = 'wp' ) {
109 - global $pagenow;
110 -
111 - $attachment_id = $attachment->id;
112 - $data = $attachment->get_data();
113 - $output = '';
114 - $args = array(
115 - 'attachment_id' => $attachment_id,
116 - 'context' => $context
184 +function get_imagify_attachment_error_text( $process ) {
185 + if ( ! $process->is_valid() ) {
186 + return '';
187 + }
188 +
189 + $data = $process->get_data()->get_optimization_data();
190 +
191 + if ( ! isset( $data['sizes']['full']['success'] ) || $data['sizes']['full']['success'] ) {
192 + return '';
193 + }
194 +
195 + $class = 'button';
196 + $media = $process->get_media();
197 + $url = get_imagify_admin_url(
198 + 'optimize',
199 + [
200 + 'attachment_id' => $media->get_id(),
201 + 'context' => $media->get_context(),
202 + ]
117 203 );
118 204
119 - if ( isset( $data['sizes']['full']['success'] ) && ! $data['sizes']['full']['success'] ) {
120 - $class = ( 'post.php' !== $pagenow ) ? 'button-imagify-manual-upload' : '';
121 - $output .= '<strong>' . $data['sizes']['full']['error'] . '</strong><br/><a id="imagify-upload-' . $attachment_id . '" class="button ' . $class . '" href="' . get_imagify_admin_url( 'manual-upload', $args ) . '" data-waiting-label="' . esc_attr__( 'Optimizing...', 'imagify' ) . '">' . __( 'Try again', 'imagify' ) . '</a>';
205 + if ( ! Imagify_Views::get_instance()->is_media_page() ) {
206 + $class .= ' button-imagify-optimize';
122 207 }
123 208
124 - return $output;
209 + return Imagify_Views::get_instance()->get_template(
210 + 'button/retry-optimize',
211 + [
212 + 'url' => $url,
213 + 'error' => $data['sizes']['full']['error'],
214 + 'atts' => [
215 + 'class' => $class,
216 + ],
217 + ]
218 + );
125 219 }
126 220
127 -/*
221 +/**
128 222 * Get the re-optimize link for a specific attachment.
129 223 *
130 - * @since 1.0
224 + * @since 1.0
225 + * @since 1.9 Function signature changed.
131 226 * @author Jonathan Buttigieg
132 227 *
133 - * @param int $attachment_id The attachement ID.
134 - * @return string The output to print.
228 + * @param ProcessInterface $process The optimization process object.
229 + * @return string The output to print.
135 230 */
136 -function get_imagify_attachment_reoptimize_link( $attachment, $context = 'wp' ) {
137 - global $pagenow;
138 -
139 - $attachment_id = $attachment->id;
140 - $level = (int) $attachment->get_optimization_level();
141 - $args = array(
142 - 'attachment_id' => $attachment_id,
143 - 'context' => $context
144 - );
145 - $output = '';
231 +function get_imagify_attachment_reoptimize_link( $process ) {
232 + if ( ! $process->is_valid() ) {
233 + return '';
234 + }
146 235
147 - if ( $attachment->has_backup() ) {
148 - $class = ( 'post.php' !== $pagenow ) ? 'button-imagify-manual-override-upload' : '';
149 -
150 - // Re-optimize to Ultra
151 - if ( 1 === $level || 0 === $level ) {
152 - $args['optimization_level'] = 2;
153 - $output .= '<a href="' . get_imagify_admin_url( 'manual-override-upload', $args ) . '" class="' . $class . '" data-waiting-label="' . esc_attr__( 'Optimizing...', 'imagify' ) . '"><span class="dashicons dashicons-admin-generic"></span>' . sprintf( __( 'Re-Optimize to %s', 'imagify' ), __( 'Ultra', 'imagify' ) ) . '</a>';
154 - }
155 -
156 - // Re-optimize to Aggressive
157 - if ( 2 === $level || 0 === $level ) {
158 - $args['optimization_level'] = 1;
159 - $output .= '<a href="' . get_imagify_admin_url( 'manual-override-upload', $args ) . '" class="' . $class . '" data-waiting-label="' . esc_attr__( 'Optimizing...', 'imagify' ) . '"><span class="dashicons dashicons-admin-generic"></span>' . sprintf( __( 'Re-Optimize to %s', 'imagify' ), __( 'Aggressive', 'imagify' ) ) . '</a>';
160 - }
161 -
162 - // Re-optimize to Normal
163 - if ( 2 === $level || 1 === $level ) {
164 - $args['optimization_level'] = 0;
165 - $output .= '<a href="' . get_imagify_admin_url( 'manual-override-upload', $args ) . '" class="' . $class . '" data-waiting-label="' . esc_attr__( 'Optimizing...', 'imagify' ) . '"><span class="dashicons dashicons-admin-generic"></span>' . sprintf( __( 'Re-Optimize to %s', 'imagify' ), __( 'Normal', 'imagify' ) ) . '</a>';
166 - }
167 -
236 + $data = $process->get_data();
237 +
238 + if ( ! $data->get_optimization_status() ) {
239 + // Not optimized yet.
240 + return '';
168 241 }
169 242
170 - return $output;
171 -}
243 + // Stop the process if the API key isn't valid.
244 + if ( ! Imagify_Requirements::is_api_key_valid() ) {
245 + return '';
246 + }
172 247
173 -/*
174 - * Get all data to diplay for a specific attachment.
175 - *
176 - * @since 1.2
177 - * @author Jonathan Buttigieg
178 - *
179 - * @param object $attachment The attachement object.
180 - * @return string The output to print.
181 - */
182 -function get_imagify_media_column_content( $attachment, $context = 'wp' ) {
183 - $attachment_id = $attachment->id;
184 - $attachment_ext = $attachment->get_extension();
185 - $output = '';
186 -
187 - // Check if the attachment extension is allowed
188 - if ( 'wp' === $context && ! wp_attachment_is_image( $attachment_id ) ) {
189 - $output = sprintf( __( '%s can\'t be optimized', 'imagify' ), strtoupper( $attachment_ext ) );
190 - return $output;
248 + $is_already_optimized = $data->is_already_optimized();
249 + $media = $process->get_media();
250 + $can_reoptimize = $is_already_optimized || $media->has_backup();
251 +
252 + // Don't display anything if there is no backup or the image has been optimized.
253 + if ( ! $can_reoptimize ) {
254 + return '';
191 255 }
192 -
193 - // Check if the API key is valid
194 - if ( ! imagify_valid_key() && ! $attachment->is_optimized() ) {
195 - $output .= __( 'Invalid API key', 'imagify' );
196 - $output .= '<br/>';
197 - $output .= '<a href="' . get_imagify_admin_url( 'options-general' ) . '">' . __( 'Check your Settings', 'imagify' ) . '</a>';
198 - return $output;
256 +
257 + $output = '';
258 + $views = Imagify_Views::get_instance();
259 + $media_level = $data->get_optimization_level();
260 + $data = [];
261 + $url_args = [
262 + 'attachment_id' => $media->get_id(),
263 + 'context' => $media->get_context(),
264 + ];
265 +
266 + if ( Imagify_Views::get_instance()->is_media_page() ) {
267 + $data['atts'] = [
268 + 'class' => '',
269 + ];
199 270 }
200 -
201 - $transient_context = ( 'wp' !== $context ) ? strtolower( $context ) . '-' : '';
202 - $transient_name = 'imagify-' . $transient_context . 'async-in-progress-' . $attachment_id;
203 -
204 - if ( false !== get_transient( $transient_name ) ) {
205 - $output = '<div class="button"><span class="imagify-spinner"></span>' . __( 'Optimizing...', 'imagify' ) . '</div>';
206 - return $output;
207 - }
208 271
209 - // Check if the image was optimized
210 - if ( ! $attachment->is_optimized() && ! $attachment->has_error() ) {
211 - $args = array(
212 - 'attachment_id' => $attachment_id,
213 - 'context' => $context
214 - );
215 - $output .= '<a id="imagify-upload-' . $attachment_id . '" href="' . get_imagify_admin_url( 'manual-upload', $args ) . '" class="button-primary button-imagify-manual-upload" data-waiting-label="' . esc_attr__( 'Optimizing...', 'imagify' ) . '">' . __( 'Optimize', 'imagify' ) . '</a>';
216 - return $output;
272 + if ( $media_level < 1 ) {
273 + $url_args['optimization_level'] = 2;
274 + $data['optimization_level'] = 2;
275 + $data['url'] = get_imagify_admin_url( 'manual-reoptimize', $url_args );
276 +
277 + $output .= $views->get_template( 'button/re-optimize', $data );
278 + } elseif ( $media_level > 0 ) {
279 + $url_args['optimization_level'] = 0;
280 + $data['optimization_level'] = 0;
281 + $data['url'] = get_imagify_admin_url( 'manual-reoptimize', $url_args );
282 +
283 + $output .= $views->get_template( 'button/re-optimize', $data );
217 284 }
218 285
219 - $output .= get_imagify_attachment_optimization_text( $attachment, $context );
220 286 return $output;
221 287 }
222 288
223 289 /**
224 - * Add a small section with button
290 + * Get the link to optimize missing thumbnail sizes for a specific attachment.
225 291 *
226 - * @return string HTML
292 + * @since 1.6.10
293 + * @since 1.9 Function signature changed.
294 + * @author Grégory Viguier
227 295 *
228 - * @since 1.5
229 - * @author Geoffrey
230 - *
231 - * @todo add only for no-payable users?
296 + * @param ProcessInterface $process The optimization process object.
297 + * @return string The output to print.
232 298 */
233 -function get_imagify_new_to_imagify() {
234 - if ( apply_filters( 'imagify_show_new_to_imagify', true ) ) {
235 - return '
236 - <div class="imagify-section imagify-section-positive">
237 - <div class="imagify-start imagify-mr2">
238 - <button id="imagify-get-pricing-modal" data-nonce="' . wp_create_nonce('imagify_get_pricing_' . get_current_user_id() ) . '" data-target="#imagify-pricing-modal" type="button" class="imagify-modal-trigger imagify-button imagify-button-light imagify-button-big">
239 - <i class="dashicons dashicons-dashboard" aria-hidden="true"></i>
240 - <span class="button-text">' . esc_html__( 'What plan do I need?', 'imagify' ) . '</span>
241 - </button>
242 - </div>
243 - <div class="imagify-oh">
244 - <p class="imagify-section-title">' . esc_html__( 'You\'re new to Imagify?', 'imagify' ) . '</p>
245 - <p>' . esc_html__( 'Let us help you by analyzing your existing images and determinate the best plan for you', 'imagify' ) . '</p>
246 - </div>
247 - </div>
248 - ';
299 +function get_imagify_attachment_optimize_missing_thumbnails_link( $process ) {
300 + if ( ! $process->is_valid() ) {
301 + return '';
249 302 }
250 -}
251 303
252 -/**
253 - * Return the formatted price present in pricing tables
254 - *
255 - * @param float $value the price value
256 - * @return string the markuped price
257 - *
258 - * @since 1.5
259 - * @author Geoffrey
260 - */
261 -function get_imagify_price_table_format( $value ) {
262 - $v = explode( '.', (string) $value );
263 -
264 - return '<span class="imagify-price-big">' . $v[0] . '</span> <span class="imagify-price-mini">.' . ( strlen( $v[1] ) === 1 ? $v[1] . '0' : $v[1] ) . '</span>';
265 -}
304 + $media = $process->get_media();
266 305
267 -/**
268 - * Return the payment modal HTML
269 - * @return string HTML code for payement modal
270 - *
271 - * @since 1.5
272 - * @author Geoffrey
273 - */
274 -function imagify_payment_modal() {
275 -?>
276 - <div id="imagify-pricing-modal" class="imagify-modal imagify-payment-modal" aria-hidden="false" role="dialog" aria-labelledby="imagify-pricing-step-1">
277 - <div class="imagify-modal-content">
278 - <div class="imagify-modal-main">
279 - <ol class="imagify-payment-steps">
280 - <li id="imagify-pricing-step-1" class="active"><?php esc_html_e( 'Choose Plan', 'imagify' ); ?></li>
281 - <li id="imagify-pricing-step-2"><?php esc_html_e( 'Payment Info', 'imagify' ); ?></li>
282 - </ol>
283 -
284 - <div class="imagify-modal-views imagify-pre-checkout-view" id="imagify-pre-checkout-view" aria-hidden="false">
285 - <div class="imagify-modal-section section-gray">
286 - <p class="imagify-modal-title"><?php esc_html_e( 'We analysed your images', 'imagify' ); ?></p>
306 + if ( ! $media->is_image() || ! Imagify_Requirements::is_api_key_valid() || ! $media->has_backup() ) {
307 + return '';
308 + }
287 309
288 - <div class="imagify-modal-cols">
289 - <div class="imagify-col">
290 - <p>
291 - <span class="imagify-border-styled"><?php
292 - printf( esc_html__( 'You have %s images', 'imagify' ), '</span><span class="imagify-big-number">58000</span><span class="imagify-border-styled">' ); ?></span>
293 - </p>
294 - </div>
295 - <div class="imagify-col">
296 - <p class="imagify-iconed">
297 - <i class="dashicons dashicons-images-alt2" aria-hidden="true"></i>
298 - <?php printf( esc_html__( 'You actually have %s of images in your library.', 'imagify' ), '<strong class="imagify-dark">3 GB</strong>' ); ?>
299 - </p>
300 - <p class="imagify-iconed">
301 - <i class="dashicons dashicons-cloud" aria-hidden="true"></i>
302 - <?php printf( esc_html__( 'You upload around %s of images per month.', 'imagify' ), '<strong class="imagify-dark">353 MB</strong>' ); ?>
303 - </p>
304 - </div>
305 - </div>
306 - </div>
310 + $context = $media->get_context();
307 311
308 - <div class="imagify-modal-section">
309 - <p class="imagify-modal-title"><?php esc_html_e( 'We recommend you this plan', 'imagify' ); ?></p>
312 + /**
313 + * Allow to not display the "Optimize missing thumbnails" link.
314 + *
315 + * @since 1.6.10
316 + * @since 1.9 The $attachment object is replaced by a $process object.
317 + * @author Grégory Viguier
318 + *
319 + * @param bool $display True to display the link. False to not display it.
320 + * @param ProcessInterface $process The optimization process object.
321 + * @param string $context The context.
322 + */
323 + $display = apply_filters( 'imagify_display_missing_thumbnails_link', true, $process, $context );
310 324
311 - <div class="imagify-offer-line imagify-offer-monthly imagify-offer-selected imagify-month-selected" data-offer='{"lite":{"id":3,"name":"Lite","data":1073741824,"dataf":"1 GB","imgs":5000,"prices":{"monthly":4.99,"yearly":4.16,"add":4}}}'>
312 - <div class="imagify-offer-header">
313 - <p class="imagify-offer-title imagify-switch-my">
314 - <span aria-hidden="false" class="imagify-monthly"><?php esc_html_e( 'Subscribe a monthly plan', 'imagify' ); ?></span>
315 - <span aria-hidden="true" class="imagify-yearly"><?php esc_html_e( 'Subscribe a yearly plan', 'imagify' ); ?></span>
316 - </p>
317 - <div class="imagify-inline-options imagify-radio-line">
318 - <input id="imagify-subscription-monthly" type="radio" value="monthly" name="plan-subscription" checked="checked">
319 - <label for="imagify-subscription-monthly"><?php esc_html_e( 'Monthly' , 'imagify' ); ?></label>
325 + // Stop the process if the filter is false.
326 + if ( ! $display ) {
327 + return '';
328 + }
320 329
321 - <input id="imagify-subscription-yearly" type="radio" value="yearly" name="plan-subscription">
322 - <label for="imagify-subscription-yearly"><?php esc_html_e( 'Yearly' , 'imagify' ); ?><span class="imagify-2-free"><?php esc_html_e( '2 months free', 'imagify' ) ?></span></label>
323 - </div><!-- .imagify-radio-line -->
324 - </div><!-- .imagify-offer-header -->
330 + $missing_sizes = $process->get_missing_sizes();
325 331
326 - <div class="imagify-offer-content imagify-flex-table">
332 + if ( ! $missing_sizes || is_wp_error( $missing_sizes ) ) {
333 + return '';
334 + }
327 335
328 - <div class="imagify-col-checkbox">
329 - <input type="checkbox" name="imagify-offer" id="imagify-offer-1gb" value="1Gb" checked="checked" class="imagify-checkbox medium">
330 - <label for="imagify-offer-1gb">
331 - <span class="imagify-the-offer">
332 - <span class="imagify-offer-size">1 GB</span>
333 - <span class="imagify-offer-by"><?php esc_html_e( '/month', 'imagify' ); ?></span>
334 - </span>
335 - <span class="imagify-approx"><?php printf( esc_html__( 'approx: %s images', 'imagify' ), '<span class="imagify-approx-nb">5&nbsp;000</span>' ); ?></span>
336 - </label>
337 - </div>
338 - <div class="imagify-col-price imagify-flex-table">
339 - <span class="imagify-price-block">
340 - <span class="imagify-dollars">$</span>
341 - <span class="imagify-number-block">
342 - <span class="imagify-switch-my">
343 - <span class="imagify-monthly" aria-hidden="false">
344 - <span class="imagify-price-big">3</span>
345 - <span class="imagify-price-mini">.99</span>
346 - </span>
347 - <span class="imagify-yearly" aria-hidden="true">
348 - <span class="imagify-price-big">3</span>
349 - <span class="imagify-price-mini">.16</span>
350 - </span>
351 - </span>
352 - <span class="imagify-price-by"><?php esc_html_e( '/month', 'imagify' ); ?></span>
353 - </span>
354 - </span>
336 + $url = get_imagify_admin_url(
337 + 'optimize-missing-sizes',
338 + [
339 + 'attachment_id' => $media->get_id(),
340 + 'context' => $context,
341 + ]
342 + );
355 343
356 - <p class="imagify-price-complement"><?php printf( __( '%s per<br>
357 -additionnal Gb', 'imagify' ), '<span class="imagify-price-add-data"></span>' ); ?></p>
344 + return Imagify_Views::get_instance()->get_template(
345 + 'button/optimize-missing-sizes',
346 + [
347 + 'url' => $url,
348 + 'count' => count( $missing_sizes ),
349 + ]
350 + );
351 +}
358 352
359 - </div>
360 - <div class="imagify-col-other-actions">
361 - <a href="#imagify-plans-selection-view" class="imagify-choose-another-plan" data-imagify-choose="plan"><?php esc_html_e( 'Choose another plan', 'imagify' ); ?></a>
362 - </div>
353 +/**
354 + * Get the link to generate next-gen versions if they are missing.
355 + *
356 + * @since 1.9
357 + *
358 + * @param ProcessInterface $process The optimization process object.
359 + *
360 + * @return string The output to print.
361 + */
362 +function get_imagify_attachment_generate_nextgen_versions_link( $process ) {
363 + if ( ! $process->is_valid() ) {
364 + return '';
365 + }
363 366
364 - </div><!-- .imagify-offer-content -->
367 + $formats = imagify_nextgen_images_formats();
365 368
366 - </div><!-- .imagify-offer-line -->
369 + if ( empty( $formats ) ) {
370 + return '';
371 + }
367 372
368 - <div class="imagify-offer-line imagify-offer-onetime" data-offer='{"recommended":{"id":999,"name":"Customized","data":3000001337,"dataf":"3 GB","imgs":54634,"price":28.98}}'>
369 - <div class="imagify-offer-header">
370 - <p class="imagify-offer-title">
371 - <?php esc_html_e( 'Optimize the images you already have, buy a one-time plan', 'imagify' ); ?>
372 - </p>
373 - </div><!-- .imagify-offer-header -->
373 + $media = $process->get_media();
374 374
375 - <div class="imagify-offer-content imagify-flex-table">
375 + if ( ! $media->is_image() || ! Imagify_Requirements::is_api_key_valid() || ! $media->has_backup() ) {
376 + return '';
377 + }
376 378
377 - <div class="imagify-col-checkbox">
378 - <input type="checkbox" name="imagify-offer" id="imagify-offer-custom" value="1Gb" class="imagify-checkbox medium">
379 - <label for="imagify-offer-custom">
380 - <span class="imagify-the-offer">
381 - <span class="imagify-offer-size">3 GB</span>
382 - </span>
383 - <span class="imagify-approx"><?php printf( esc_html__( 'approx: %s images', 'imagify' ), '<span class="imagify-approx-nb">54000</span>' ); ?></span>
384 - </label>
385 - </div>
386 - <div class="imagify-col-price imagify-flex-table">
387 - <span class="imagify-price-block">
388 - <span class="imagify-dollars">$</span>
389 - <span class="imagify-number-block">
390 - <span class="imagify-price-big">60</span>
391 - <span class="imagify-price-mini">.99</span>
392 - </span>
393 - </span>
394 - </div>
395 - <div class="imagify-col-other-actions">
396 - <a href="#imagify-plans-selection-view" class="imagify-choose-another-plan" data-imagify-choose="onetime"><?php esc_html_e( 'Choose another plan', 'imagify' ); ?></a>
397 - </div>
379 + $format = get_imagify_option( 'optimization_format' );
398 380
399 - </div><!-- .imagify-offer-content -->
381 + if (
382 + 'avif' === $format
383 + &&
384 + 'image/avif' === $media->get_mime_type()
385 + ) {
386 + return '';
387 + } elseif ( 'image/webp' === $media->get_mime_type() ) {
388 + return '';
389 + }
400 390
401 - </div><!-- .imagify-offer-line -->
391 + $data = $process->get_data();
402 392
393 + if ( ! $data->is_optimized() && ! $data->is_already_optimized() ) {
394 + return '';
395 + }
403 396
404 - <p class="imagify-submit-line">
405 - <button type="button" class="button button-secondary imagify-button-secondary" id="imagify-modal-checkout-btn">
406 - <i class="dashicons dashicons-cart" aria-hidden="true"></i>
407 - <?php esc_html_e( 'Checkout', 'imagify' ); ?>
408 - </button>
409 - </p>
397 + if ( $process->has_next_gen() ) {
398 + return '';
399 + }
410 400
411 - <p class="imagify-footer-lines"><?php esc_html_e( 'Monthly plans comes with credits which is renewed every months. The billing happens automatically each month or year depending the billing period you choose.', 'imagify' ); ?></p>
412 - </div>
413 - </div><!-- .imagify-pre-checkout-view -->
414 -
415 - <?php
401 + $context = $media->get_context();
416 402
417 -
403 + $display = apply_filters_deprecated( 'imagify_display_generate_webp_versions_link', [ true, $process, $context ], '2.2', 'imagify_display_generate_next_gen_versions_link' );
418 404
419 - /**
420 - *
421 - *
422 - * SECOND MODAL VIEW
423 - *
424 - *
425 - */
405 + /**
406 + * Allow to not display the "Generate next-gen versions" link.
407 + *
408 + * @since 1.9
409 + * @author Grégory Viguier
410 + *
411 + * @param bool $display True to display the link. False to not display it.
412 + * @param ProcessInterface $process The optimization process object.
413 + * @param string $context The context.
414 + */
415 + $display = apply_filters( 'imagify_display_generate_next_gen_versions_link', $display, $process, $context );
426 416
427 -
417 + // Stop the process if the filter is false.
418 + if ( ! $display ) {
419 + return '';
420 + }
428 421
429 - ?>
422 + $url = get_imagify_admin_url(
423 + 'generate-nextgen-versions',
424 + [
425 + 'attachment_id' => $media->get_id(),
426 + 'context' => $context,
427 + ]
428 + );
430 429
431 - <div class="imagify-modal-views imagify-plans-selection-view" id="imagify-plans-selection-view" aria-hidden="true">
432 - <ul class="imagify-tabs" role="tablist">
433 - <li class="imagify-tab imagify-current">
434 - <a href="#imagify-pricing-tab-monthly" role="tab" aria-controls="imagify-pricing-tab-monthly" aria-selected="true">
435 - <?php esc_html_e( 'Monthly Plans', 'imagify' ); ?>
436 - </a>
437 - </li>
438 - <li class="imagify-tab">
439 - <a href="#imagify-pricing-tab-onetime" role="tab" aria-controls="imagify-pricing-tab-onetime" aria-selected="false">
440 - <?php esc_html_e( 'One Time Plans', 'imagify' ); ?>
441 - </a>
442 - </li>
443 - </ul><!-- .imagify-tabs -->
430 + $output = Imagify_Views::get_instance()->get_template(
431 + 'button/generate-webp',
432 + [
433 + 'url' => $url,
434 + ]
435 + );
444 436
445 - <div class="imagify-tabs-contents">
437 + return $output . '<br/>';
438 +}
446 439
447 - <div class="imagify-tab-content imagify-current" id="imagify-pricing-tab-monthly" role="tabpanel">
448 -
449 - <div class="imagify-modal-section section-gray">
450 - <p><?php esc_html_e( 'Monthly plans come with credits which is renewed every months. The billing happens automatically each month or year depending the billing period you choose.', 'imagify' ); ?></p>
451 - </div>
440 +/**
441 + * Get the link to delete next-gen versions when the status is "already_optimized".
442 + *
443 + * @since 1.9.6
444 + * @author Grégory Viguier
445 + *
446 + * @param ProcessInterface $process The optimization process object.
447 + * @return string The output to print.
448 + */
449 +function get_imagify_attachment_delete_nextgen_versions_link( $process ) {
450 + if ( ! $process->is_valid() ) {
451 + return '';
452 + }
452 453
453 - <div class="imagify-inline-options imagify-small-options imagify-radio-line">
454 - <input id="imagify-pricing-montly" type="radio" value="monthly" name="plan-pricing" checked="checked">
455 - <label for="imagify-pricing-montly"><?php esc_html_e( 'Monthly' , 'imagify' ); ?></label>
454 + $media = $process->get_media();
455 + $context = $media->get_context();
456 + $media_id = $media->get_id();
456 457
457 - <input id="imagify-pricing-yearly" type="radio" value="yearly" name="plan-pricing">
458 - <label for="imagify-pricing-yearly"><?php esc_html_e( 'Yearly' , 'imagify' ); ?><span class="imagify-2-free imagify-b-right"><?php esc_html_e( '2 months free', 'imagify' ) ?></span></label>
459 - </div><!-- .imagify-radio-line -->
458 + if ( ! imagify_get_context( $context )->current_user_can( 'manual-restore', $media_id ) ) {
459 + imagify_die();
460 + }
460 461
461 - <div class="imagify-pricing-table imagify-month-selected">
462 -
463 - <script type="text/template" id="imagify-offer-monthly-template"><div class="imagify-offer-line imagify-offer-monthlies imagify-flex-table">
464 - <div class="imagify-col-details">
465 - <p class="imagify-label">
466 - <span class="imagify-the-offer">
467 - <span class="imagify-offer-size"></span>
468 - <span class="imagify-offer-by"><?php esc_html_e( '/month', 'imagify' ); ?></span>
469 - </span>
470 - <span class="imagify-approx"><?php printf( __( 'approx: %s images', 'imagify' ), '<span class="imagify-approx-nb"></span>' ); ?></span>
471 - </p>
472 - </div>
473 - <div class="imagify-col-price imagify-flex-table">
474 - <span class="imagify-price-block">
475 - <span class="imagify-dollars">$</span>
476 - <span class="imagify-number-block">
477 - <span class="imagify-switch-my"></span>
478 - <span class="imagify-price-by"><?php esc_html_e( '/month', 'imagify' ); ?></span>
479 - </span>
480 - </span>
462 + $data = $process->get_data();
481 463
482 - <span class="imagify-recommend" aria-hidden="true"><?php esc_html_e( 'we recommend for you', 'imagify' ); ?></span>
464 + if ( ! $data->is_already_optimized() || ! $process->has_next_gen() ) {
465 + return '';
466 + }
483 467
484 - <p class="imagify-price-complement"><?php printf( __( '%s per<br>
485 -additionnal Gb', 'imagify' ), '<span class="imagify-price-add-data"></span>' ); ?></p>
468 + $class = '';
469 + $url = get_imagify_admin_url(
470 + 'delete-nextgen-versions',
471 + [
472 + 'attachment_id' => $media_id,
473 + 'context' => $context,
474 + ]
475 + );
486 476
487 - </div><!-- .imagify-col-price -->
477 + if ( ! Imagify_Views::get_instance()->is_media_page() ) {
478 + $class .= 'button-imagify-delete-webp';
479 + }
488 480
489 - <div class="imagify-col-other-actions">
490 - <button type="button" class="button imagify-button-secondary mini imagify-payment-btn-select-plan"><?php esc_html_e( 'Choose plan', 'imagify' ); ?></button>
491 - </div>
492 - </div><!-- .imagify-offer-line --></script>
493 - </div><!-- .imagify-pricing-table -->
494 -
495 - <div class="imagify-cols">
496 - <div class="imagify-col imagify-txt-start">
497 - <p class="imagify-special-needs">
498 - <strong><?php esc_html_e( 'Need more?', 'imagify' ); ?></strong>
499 - <span><?php esc_html_e( 'for special needs', 'imagify' ); ?></span>
500 - </p>
501 - </div>
502 - <div class="imagify-col imagify-txt-end">
503 - <p><a class="button imagify-button-ghost imagify-button-medium imagify-mt1 imagify-mb1 imagify-mr1" href="https://imagify.io/<?php echo ( get_locale() === 'fr_FR' ? 'fr/' : '' ) ?>contact" target="_blank"><i class="dashicons dashicons-email" aria-hidden="true"></i>&nbsp;<?php esc_html_e( 'Contact Us', 'imagify' ); ?></a></p>
504 - </div>
505 - </div>
481 + return Imagify_Views::get_instance()->get_template(
482 + 'button/delete-webp',
483 + [
484 + 'url' => $url,
485 + 'atts' => [
486 + 'class' => $class,
487 + ],
488 + ]
489 + );
490 +}
506 491
507 - </div><!-- .imagify-tab-content -->
508 - <div class="imagify-tab-content" id="imagify-pricing-tab-onetime" role="tabpanel">
509 - <div class="imagify-modal-section section-gray">
510 - <p><?php esc_html_e( 'One time plans are useful if you have a lots of existing images which need to be optimized. You can use it for bulk optimizing all your past images. You will pay only once.', 'imagify' ); ?></p>
511 - </div>
512 -
492 +/**
493 + * Get all data to diplay for a specific media.
494 + *
495 + * @since 1.2
496 + * @since 1.9 Function signature changed.
497 + * @author Jonathan Buttigieg
498 + *
499 + * @param \Imagify\Optimization\Process\ProcessInterface $process The optimization process object.
500 + * @param bool $with_container Set to false to not return the HTML container.
501 + *
502 + * @return string The output to print.
503 + */
504 +function get_imagify_media_column_content( $process, $with_container = true ) {
505 + if ( ! $process->is_valid() ) {
506 + return __( 'This media is not valid.', 'imagify' );
507 + }
513 508
514 - <div class="imagify-pricing-table imagify-month-selected">
515 - <script type="text/template" id="imagify-offer-onetime-template"><div class="imagify-offer-line imagify-flex-table imagify-offer-onetimes">
516 - <div class="imagify-col-details">
517 - <p class="imagify-label">
518 - <span class="imagify-the-offer">
519 - <span class="imagify-offer-size"></span>
520 - </span>
521 - <span class="imagify-approx"><?php printf( __( 'approx: %s images', 'imagify' ), '<span class="imagify-approx-nb"></span>' ); ?></span>
522 - </p>
523 - </div>
524 - <div class="imagify-col-price">
525 - <span class="imagify-price-block">
526 - <span class="imagify-dollars">$</span>
527 - <span class="imagify-number-block"></span>
528 - </span>
529 - <span class="imagify-recommend"><?php esc_html__( 'we recommend for you', 'imagify' ); ?></span>
530 - </div><!-- .imagify-col-price -->
509 + if ( ! $process->current_user_can( 'manual-optimize' ) ) {
510 + return __( 'You are not allowed to optimize this file.', 'imagify' );
511 + }
531 512
532 - <div class="imagify-col-other-actions">
533 - <button type="button" class="button imagify-button-secondary mini imagify-payment-btn-select-plan"><?php esc_html_e( 'Choose plan', 'imagify' ); ?></button>
534 - </div>
535 - </div><!-- .imagify-offer-line --></script>
536 - </div><!-- .imagify-pricing-table -->
513 + $media = $process->get_media();
537 514
538 - </div><!-- .imagify-tab-content -->
515 + // Check if the media is supported.
516 + if ( ! $media->is_supported() ) {
517 + return __( 'This media is not supported.', 'imagify' );
518 + }
539 519
540 - </div><!-- .imagify-tabs-contents -->
541 - </div><!-- .imagify-plans-selection-view -->
520 + // Check if the media has the required WP data.
521 + if ( ! $media->has_required_media_data() ) {
522 + return __( 'This media lacks the required metadata and cannot be optimized.', 'imagify' );
523 + }
542 524
525 + $data = $process->get_data();
543 526
544 - <?php
527 + // Check if the API key is valid.
528 + if ( ! Imagify_Requirements::is_api_key_valid() && ! $data->is_optimized() ) {
529 + $output = __( 'Invalid API key', 'imagify' );
530 + $output .= '<br/>';
531 + $output .= '<a href="' . esc_url( get_imagify_admin_url() ) . '">' . __( 'Check your Settings', 'imagify' ) . '</a>';
532 + return $output;
533 + }
545 534
546 -
535 + $media_id = $media->get_id();
536 + $context = $media->get_context();
537 + $views = Imagify_Views::get_instance();
538 + $is_locked = $process->is_locked();
547 539
548 - /**
549 - *
550 - *
551 - * THIRD MODAL VIEW
552 - *
553 - *
554 - */
540 + if ( $is_locked ) {
541 + switch ( $is_locked ) {
542 + case 'optimizing':
543 + $lock_label = __( 'Optimizing...', 'imagify' );
544 + break;
545 + case 'restoring':
546 + $lock_label = __( 'Restoring...', 'imagify' );
547 + break;
548 + default:
549 + $lock_label = __( 'Processing...', 'imagify' );
550 + }
555 551
556 -
552 + if ( ! $with_container ) {
553 + return $views->get_template(
554 + 'button/processing',
555 + [ 'label' => $lock_label ]
556 + );
557 + }
557 558
558 - ?>
559 + return $views->get_template(
560 + 'container/data-actions',
561 + [
562 + 'media_id' => $media_id,
563 + 'context' => $context,
564 + 'content' => $views->get_template( 'button/processing', [ 'label' => $lock_label ] ),
565 + ]
566 + );
567 + }
559 568
560 - <div class="imagify-modal-views imagify-payment-process-view" id="imagify-payment-process-view" aria-hidden="true">
561 - <div class="imagify-modal-section section-gray">
562 - <div class="imagify-cart imagify-month-selected">
563 - <p class="imagify-cart-label"><?php esc_html_e( 'Your order', 'imagify' ); ?></p>
569 + // Check if the image was optimized.
570 + if ( ! $data->get_optimization_status() ) {
571 + $output = Imagify_Views::get_instance()->get_template(
572 + 'button/optimize',
573 + [
574 + 'url' => get_imagify_admin_url(
575 + 'manual-optimize',
576 + [
577 + 'attachment_id' => $media_id,
578 + 'context' => $context,
579 + ]
580 + ),
581 + ]
582 + );
564 583
565 - <div class="imagify-cart-list">
566 - <?php
567 - $emptied_item = '<div class="imagify-cart-emptied-item">
568 - <p>' . sprintf( esc_html__( '%scancel%sYou just removed %s', 'imagify' ), '<a href="#cancel" class="imagify-cancel-removing">', '</a>', '<span class="imagify-removed-name"></span>' ) . '</p>
569 - </div>';
570 - ?>
584 + if ( $media->has_backup() ) {
585 + $output .= '<span class="attachment-has-backup hidden"></span>';
586 + }
587 + } else {
588 + $output = get_imagify_attachment_optimization_text( $process );
589 + }
571 590
572 - <!-- JS stuff will complete the datas of list item -->
591 + if ( ! $with_container ) {
592 + return $output;
593 + }
573 594
574 - <div class="imagify-cart-item imagify-cart-item-monthly imagify-flex-table imagify-align-top" data-offer="">
575 - <div class="imagify-cl-remove">
576 - <button type="button" class="imagify-remove-from-cart" title="<?php esc_html_e( 'Remove this item', 'imagify' ); ?>"><i class="dashicons dashicons-no-alt" aria-hidden="true"></i></button>
577 - </div>
578 - <div class="imagify-cl-name">
579 - <p class="imagify-cart-product-name"><span class="imagify-the-product-name"></span> Monthly plan</p>
580 - <p class="imagify-cart-suggestion"><a href="#step1" class="imagify-back-to-plans"><?php esc_html_e( 'Choose another plan', 'imagify' ); ?></a></p>
581 - </div>
582 - <div class="imagify-cl-description">
583 - <p><?php printf( esc_html__( '%s per month', 'imagify' ), '<span class="imagify-cart-offer-data"></span>') ?></p>
584 - </div>
585 - <div class="imagify-cl-price imagify-price-block">
586 - <span class="imagify-dollars">$</span>
587 - <span class="imagify-number-block">
588 - <span class="imagify-switch-my">
589 - </span>
590 - </span>
591 - </div>
592 - </div><!-- .imagify-cart-item -->
593 - <?php echo $emptied_item; ?>
594 -
595 - <div class="imagify-cart-item imagify-cart-item-onetime imagify-flex-table imagify-align-top" data-offer="">
596 - <div class="imagify-cl-remove">
597 - <button type="button" class="imagify-remove-from-cart" title="<?php esc_html_e( 'Remove this item', 'imagify' ); ?>"><i class="dashicons dashicons-no-alt" aria-hidden="true"></i></button>
598 - </div>
599 - <div class="imagify-cl-name">
600 - <p class="imagify-cart-product-name"><span class="imagify-the-product-name"></span> One Time Plan</p>
601 - <p class="imagify-cart-suggestion"><a href="#step1" class="imagify-back-to-plans"><?php esc_html_e( 'Choose another plan', 'imagify' ); ?></a></p>
602 - </div>
603 - <div class="imagify-cl-description">
604 - <p><?php printf( esc_html__( 'one time %s', 'imagify' ), '<span class="imagify-cart-offer-data"></span>') ?></p>
605 - </div>
606 - <div class="imagify-cl-price imagify-price-block">
607 - <span class="imagify-dollars">$</span>
608 - <span class="imagify-number-block">
609 - </span>
610 - </div>
611 - </div><!-- .imagify-cart-item -->
612 - <?php echo $emptied_item; ?>
613 - </div><!-- .imagify-cart-list -->
614 -
615 - <div class="imagify-cols imagify-cart-list-my-choice">
616 - <div class="imagify-col imagify-switch-my imagify-pr1">
617 - <p class="imagify-monthly"><?php printf( __( 'Switch to yearly subscription and <br><strong class="imagify-dark">save %s per year!</strong>', 'imagify' ), '<span class="imagify-nb-save-per-year"></span>' ); ?></p>
618 - <p class="imagify-yearly"><?php printf( __( 'Perfect!<br>You\'re <strong class="imagify-dark">saving %s per year!</strong>', 'imagify' ), '<span class="imagify-nb-save-per-year"></span>' ); ?></p>
619 - </div>
620 - <div class="imagify-col">
621 - <div class="imagify-inline-options imagify-small-options imagify-radio-line imagify-cart-list-switcher">
622 - <input type="radio" checked="checked" name="plan-checkout" value="monthly" id="imagify-checkout-monthly">
623 - <label for="imagify-checkout-monthly"><?php esc_html_e('Monthly', 'imagify' ); ?></label>
624 -
625 - <input type="radio" name="plan-checkout" value="yearly" id="imagify-checkout-yearly">
626 - <label for="imagify-checkout-yearly"><?php esc_html_e('Yearly', 'imagify' ); ?><span class="imagify-2-free imagify-b-bottom"><?php esc_html_e('2 months free', 'imagify' ); ?></span></label>
627 - </div>
628 - </div>
629 - </div>
630 -
631 - </div><!-- .imagify-cart.imagify-month-selected -->
632 - </div><!-- .imagify-section-gray -->
633 -
634 - <?php $imagify_api_key = get_imagify_option( 'api_key', false ); ?>
635 -
636 - <iframe data-imagify-api="<?php echo $imagify_api_key; ?>" id="imagify-payment-iframe" src="" frameborder="0"></iframe>
637 -
638 - </div><!-- .imagify-modal-views -->
639 -
640 -
641 - <?php
642 -
643 -
644 - /**
645 - *
646 - *
647 - * Succes view
648 - *
649 - *
650 - */
651 -
652 -
653 - ?>
654 -
655 - <div class="imagify-modal-views imagify-success-view" id="imagify-success-view" aria-hidden="true">
656 - <img src="<?php echo IMAGIFY_ASSETS_IMG_URL; ?>big-blue-check.png" width="113" height="109" alt="">
657 - <p><?php esc_html_e( 'Thank you for being awesome!', 'imagify' ); ?></p>
658 - </div><!-- .imagify-modal-views -->
659 -
660 - <button class="close-btn" type="button">
661 - <i aria-hidden="true" class="dashicons dashicons-no-alt"></i>
662 - <span class="screen-reader-text"><?php esc_html_e( 'Close', 'imagify' ); ?></span>
663 - </button>
664 - </div><!-- .imagify-modal-main -->
665 -
666 - <div class="imagify-modal-sidebar">
667 - <div class="imagify-modal-sidebar-content imagify-txt-start">
668 - <p class="imagify-modal-sidebar-title"><?php esc_html_e( 'What do our user think about Imagify', 'imagify' ) ?></p>
669 -
670 - <div class="imagify-modal-testimony">
671 - <div class="imagify-modal-testimony-person">
672 - <span class="imagify-modal-avatar">
673 - <img src="<?php echo IMAGIFY_ASSETS_IMG_URL; ?>pic-srhdesign.jpg" alt="">
674 - </span>
675 - <p class="imagify-modal-identity">
676 - <a href="https://twitter.com/SRHDesign" target="_blank">@SRHDesign</a>
677 - <a href="https://twitter.com/SRHDesign/status/686486119249260544" target="_blank"><time datetime="2016-01-11">11 jan. 2016 @ 17:40</time></a>
678 - </p>
679 - </div>
680 - <div class="imagify-modal-testimony-content">
681 - <p>@imagify is an awesome tool that is powerful &amp; easy to use. It's fast, rivals and surpasses other established plugins/software. Awesome!</p>
682 - </div>
683 - </div>
684 -
685 - <div class="imagify-modal-testimony">
686 - <div class="imagify-modal-testimony-person">
687 - <span class="imagify-modal-avatar">
688 - <img src="<?php echo IMAGIFY_ASSETS_IMG_URL; ?>pic-ericwaltr.jpg" alt="">
689 - </span>
690 - <p class="imagify-modal-identity">
691 - <a href="https://twitter.com/EricWaltr" target="_blank">@EricWaltr</a>
692 - <a href="https://twitter.com/EricWaltR/status/679053496382038016" target="_blank"><time datetime="2016-01-11">21 dec. 2015 @ 22:39</time></a>
693 - </p>
694 - </div>
695 - <div class="imagify-modal-testimony-content">
696 - <p>Clearly @imagify is the most awesome tool to compress images on your website! A must try</p>
697 - </div>
698 - </div>
699 -
700 - <div class="imagify-modal-sidebar-trust imagify-txt-center">
701 - <p class="imagify-secondary">
702 - <img src="<?php echo IMAGIFY_ASSETS_IMG_URL; ?>icon-lock.png" srcset="<?php echo IMAGIFY_ASSETS_IMG_URL; ?>icon-lock.svg 2x" width="16" height="19" alt="">&nbsp;<?php esc_html_e( 'Secure Credit Card Payment', 'imagify' ); ?></p>
703 - <p><?php esc_html_e( 'This is secure 128-bits SSL encrypted payment', 'imagify' ); ?></p>
704 - </div>
705 - </div>
706 - </div>
707 -
708 - <div class="imagify-modal-loader"></div>
709 - </div><!-- .imagify-modal-content-->
710 - </div><!-- .imagify-payment-modal -->
711 -<?php
712 -}
595 + return $views->get_template(
596 + 'container/data-actions',
597 + [
598 + 'media_id' => $media_id,
599 + 'context' => $context,
600 + 'content' => $output,
601 + ]
602 + );
603 +}