| 1 |
<?php |
| 2 |
|
| 3 |
use Imagify\Stats\OptimizedMediaWithoutNextGen; |
| 4 |
use Imagify\Webp\Display; |
| 5 |
|
| 6 |
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); |
| 7 |
|
| 8 |
$settings = Imagify_Settings::get_instance(); |
| 9 |
?> |
| 10 |
<div> |
| 11 |
<h3 class="imagify-options-subtitle"><?php _e( 'Next-Gen image format', 'imagify' ); ?></h3> |
| 12 |
|
| 13 |
<div class="imagify-setting-line"> |
| 14 |
<?php |
| 15 |
$message = __( 'Select WebP for high compatibility, AVIF for superior compression. Please note that the generation process will start automatically after saving the settings.', 'imagify' ); |
| 16 |
$message_class = 'info'; |
| 17 |
$disabled = false; |
| 18 |
|
| 19 |
if ( has_filter( 'imagify_nextgen_images_formats' ) ) { |
| 20 |
$message = sprintf( |
| 21 |
// translators: %1$s and %2$s are <code> tag opening and closing, %3$s and %4$s are <a> tag opening and closing. |
| 22 |
__( 'Next-Gen Images format is currently defined by the %1$simagify_nextgen_images_format%2$s filter. %3$sRead more%4$s', 'imagify' ), |
| 23 |
'<code>', |
| 24 |
'</code>', |
| 25 |
'<a href="https://imagify.io/documentation/how-to-use-the-next-gen-image-format-filter/" target="_blank">', |
| 26 |
'</a>' |
| 27 |
); |
| 28 |
|
| 29 |
$message_class = 'error'; |
| 30 |
$disabled = true; |
| 31 |
} |
| 32 |
|
| 33 |
$attributes = [ |
| 34 |
'aria-describedby' => 'describe-optimization_format', |
| 35 |
]; |
| 36 |
|
| 37 |
if ( $disabled ) { |
| 38 |
$attributes['disabled'] = true; |
| 39 |
} |
| 40 |
|
| 41 |
$settings->field_inline_radio_list( |
| 42 |
[ |
| 43 |
'option_name' => 'optimization_format', |
| 44 |
'legend' => __( 'Next-gen image format', 'imagify' ), |
| 45 |
'info' => $message, |
| 46 |
'info_class' => $message_class, |
| 47 |
'values' => [ |
| 48 |
'off' => __( 'Off', 'imagify' ), |
| 49 |
'avif' => __( 'AVIF', 'imagify' ), |
| 50 |
'webp' => __( 'WebP', 'imagify' ), |
| 51 |
], |
| 52 |
'attributes' => $attributes, |
| 53 |
] |
| 54 |
); |
| 55 |
?> |
| 56 |
</div> |
| 57 |
|
| 58 |
<div class="imagify-setting-line"> |
| 59 |
|
| 60 |
<div class="imagify-options-line"> |
| 61 |
<?php |
| 62 |
$settings->field_checkbox( [ |
| 63 |
'option_name' => 'display_nextgen', |
| 64 |
'label' => __( 'Display images in Next-Gen format on the site', 'imagify' ), |
| 65 |
] ); |
| 66 |
?> |
| 67 |
|
| 68 |
<div class="imagify-options-line"> |
| 69 |
<?php |
| 70 |
$settings->field_radio_list( [ |
| 71 |
'option_name' => 'display_nextgen_method', |
| 72 |
'values' => [ |
| 73 |
'rewrite' => __( 'Use rewrite rules', 'imagify' ), |
| 74 |
/* translators: 1 and 2 are <em> tag opening and closing. */ |
| 75 |
'picture' => sprintf( __( 'Use <picture> tags %1$s(preferred)%2$s', 'imagify' ), '<em>', '</em>' ), |
| 76 |
], |
| 77 |
'attributes' => [ |
| 78 |
'aria-describedby' => 'describe-convert_to_webp', |
| 79 |
], |
| 80 |
] ); |
| 81 |
?> |
| 82 |
|
| 83 |
<div class="imagify-options-line"> |
| 84 |
<?php |
| 85 |
$cdn_source = apply_filters( 'imagify_cdn_source_url', '' ); |
| 86 |
|
| 87 |
if ( 'option' !== $cdn_source['source'] ) { |
| 88 |
if ( 'constant' === $cdn_source['source'] ) { |
| 89 |
printf( |
| 90 |
/* translators: 1 is an URL, 2 is a php constant name. */ |
| 91 |
esc_html__( 'Your CDN URL is set to %1$s by the constant %2$s.', 'imagify' ), |
| 92 |
'<code>' . esc_url( $cdn_source['url'] ) . '</code>', |
| 93 |
'<code>' . esc_html( $cdn_source['name'] ) . '</code>' |
| 94 |
); |
| 95 |
} elseif ( ! empty( $cdn_source['name'] ) ) { |
| 96 |
printf( |
| 97 |
/* translators: 1 is an URL, 2 is a plugin name. */ |
| 98 |
esc_html__( 'Your CDN URL is set to %1$s by %2$s.', 'imagify' ), |
| 99 |
'<code>' . esc_url( $cdn_source['url'] ) . '</code>', |
| 100 |
'<code>' . esc_html( $cdn_source['name'] ) . '</code>' |
| 101 |
); |
| 102 |
} else { |
| 103 |
printf( |
| 104 |
/* translators: %s is an URL. */ |
| 105 |
esc_html__( 'Your CDN URL is set to %1$s by filter.', 'imagify' ), |
| 106 |
'<code>' . esc_url( $cdn_source['url'] ) . '</code>' |
| 107 |
); |
| 108 |
} |
| 109 |
|
| 110 |
$settings->field_hidden( [ |
| 111 |
'option_name' => 'cdn_url', |
| 112 |
'current_value' => $cdn_source['url'], |
| 113 |
] ); |
| 114 |
} else { |
| 115 |
$settings->field_text_box( [ |
| 116 |
'option_name' => 'cdn_url', |
| 117 |
'label' => __( 'If you use a CDN, specify the URL:', 'imagify' ), |
| 118 |
'attributes' => [ |
| 119 |
'size' => 30, |
| 120 |
'placeholder' => __( 'https://cdn.example.com', 'imagify' ), |
| 121 |
], |
| 122 |
] ); |
| 123 |
} |
| 124 |
?> |
| 125 |
</div> |
| 126 |
</div> |
| 127 |
|
| 128 |
<div id="describe-display_nextgen_method" class="imagify-info"> |
| 129 |
<span class="dashicons dashicons-info"></span> |
| 130 |
<?php |
| 131 |
$conf_file_path = Display::get_instance()->get_file_path( true ); |
| 132 |
|
| 133 |
if ( $conf_file_path ) { |
| 134 |
printf( |
| 135 |
/* translators: 1 is a file name, 2 is a <strong> tag opening, 3 is the <strong> tag closing. */ |
| 136 |
esc_html__( 'The first option adds rewrite rules to your site’s configuration file (%1$s) and does not alter your pages code. %2$sThis does not work with CDN though.%3$s', 'imagify' ), |
| 137 |
'<code>' . esc_html( $conf_file_path ) . '</code>', |
| 138 |
'<strong>', |
| 139 |
'</strong>' |
| 140 |
); |
| 141 |
|
| 142 |
echo '<br/>'; |
| 143 |
} |
| 144 |
|
| 145 |
printf( |
| 146 |
/* translators: 1 and 2 are HTML tag names, 3 is a <strong> tag opening, 4 is the <strong> tag closing. */ |
| 147 |
esc_html__( 'The second option replaces the %1$s tags with %2$s tags. %3$sThis is the preferred solution but some themes may break%4$s, so make sure to verify that everything seems fine.', 'imagify' ), |
| 148 |
'<code><img></code>', |
| 149 |
'<code><picture></code>', |
| 150 |
'<strong>', |
| 151 |
'</strong>' |
| 152 |
); |
| 153 |
|
| 154 |
echo '<br/>'; |
| 155 |
|
| 156 |
/** |
| 157 |
* Add more information about WebP. |
| 158 |
* |
| 159 |
* @since 1.9 |
| 160 |
* @author Grégory Viguier |
| 161 |
*/ |
| 162 |
do_action( 'imagify_settings_webp_info' ); |
| 163 |
?> |
| 164 |
</div> |
| 165 |
</div> |
| 166 |
|
| 167 |
<?php |
| 168 |
$count = OptimizedMediaWithoutNextGen::get_instance()->get_cached_stat(); |
| 169 |
|
| 170 |
if ( $count ) { |
| 171 |
?> |
| 172 |
<div class="imagify-options-line hide-if-no-js generate-missing-webp"> |
| 173 |
<?php $this->print_template( 'part-settings-webp-missing-message', [ 'count' => $count ] ); ?> |
| 174 |
|
| 175 |
<button id="imagify-generate-webp-versions" class="button imagify-button-primary imagify-button-mini" type="button"> |
| 176 |
<span class="dashicons dashicons-admin-generic"></span> |
| 177 |
<span class="button-text"><?php esc_html_e( 'Generate missing Next-Gen images versions', 'imagify' ); ?></span> |
| 178 |
</button> |
| 179 |
|
| 180 |
<?php |
| 181 |
$remaining = OptimizedMediaWithoutNextGen::get_instance()->get_stat(); |
| 182 |
$total = get_transient( 'imagify_missing_next_gen_total' ); |
| 183 |
$progress = 0; |
| 184 |
$aria = ' aria-hidden="true"'; |
| 185 |
$class = 'hidden'; |
| 186 |
$style = ''; |
| 187 |
|
| 188 |
if ( |
| 189 |
false !== $total |
| 190 |
&& |
| 191 |
$total > 0 |
| 192 |
) { |
| 193 |
$aria = ''; |
| 194 |
$class = ''; |
| 195 |
$processed = $total - $remaining; |
| 196 |
$progress = $processed . '/' . $total; |
| 197 |
$percent = $processed / $total * 100; |
| 198 |
$style = 'style="width:' . $percent . '%;"'; |
| 199 |
} |
| 200 |
?> |
| 201 |
|
| 202 |
<div <?php echo $aria; ?> class="imagify-progress <?php echo $class; ?>"> |
| 203 |
<div class="progress"> |
| 204 |
<div class="bar" <?php echo $style; ?>><div class="percent"><?php echo $progress; ?></div></div> |
| 205 |
</div> |
| 206 |
</div> |
| 207 |
</div> |
| 208 |
<?php |
| 209 |
if ( Imagify_Requirements::is_api_key_valid() ) { |
| 210 |
?> |
| 211 |
<script type="text/html" id="tmpl-imagify-overquota-alert"> |
| 212 |
<?php $this->print_template( 'part-bulk-optimization-overquota-alert' ); ?> |
| 213 |
</script> |
| 214 |
<?php |
| 215 |
} |
| 216 |
} |
| 217 |
?> |
| 218 |
</div> |
| 219 |
</div> |
| 220 |
<?php |
| 221 |
|