PluginProbe
Imsanity / 2.4.3
Imsanity v2.4.3
2.9.4 2.9.3 2.9.2 trunk 2.4.3 2.5.0 2.6.0 2.7.0 2.7.2 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.9.0 2.9.1
imsanity / settings.php

settings.php in Imsanity 2.4.3, at settings.php

602 lines 25.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Imsanity settings and admin UI.
4 *
5 * @package Imsanity
6 */
7
8 // Setup custom $wpdb attribute for our image-tracking table.
9 global $wpdb;
10 if ( ! isset( $wpdb->imsanity_ms ) ) {
11 $wpdb->imsanity_ms = $wpdb->get_blog_prefix( 0 ) . 'imsanity';
12 }
13
14 // Register the plugin settings menu.
15 add_action( 'admin_menu', 'imsanity_create_menu' );
16 add_action( 'network_admin_menu', 'imsanity_register_network' );
17 add_filter( 'plugin_action_links_imsanity/imsanity.php', 'imsanity_settings_link' );
18 add_action( 'admin_enqueue_scripts', 'imsanity_queue_script' );
19 add_action( 'admin_init', 'imsanity_register_settings' );
20
21 register_activation_hook( 'imsanity/imsanity.php', 'imsanity_maybe_created_custom_table' );
22
23 // settings cache.
24 $_imsanity_multisite_settings = null;
25
26 /**
27 * Create the settings menu item in the WordPress admin navigation and
28 * link it to the plugin settings page
29 */
30 function imsanity_create_menu() {
31 // Create new menu for site configuration.
32 add_options_page( esc_html__( 'Imsanity Plugin Settings', 'imsanity' ), 'Imsanity', 'administrator', __FILE__, 'imsanity_settings_page' );
33 }
34
35 /**
36 * Register the network settings page
37 */
38 function imsanity_register_network() {
39 if ( ! function_exists( 'is_plugin_active_for_network' ) && is_multisite() ) {
40 // Need to include the plugin library for the is_plugin_active function.
41 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
42 }
43 if ( is_multisite() && is_plugin_active_for_network( 'imsanity/imsanity.php' ) ) {
44 add_submenu_page( 'settings.php', esc_html__( 'Imsanity Network Settings', 'imsanity' ), 'Imsanity', 'manage_options', 'imsanity_network', 'imsanity_network_settings' );
45 }
46 }
47
48 /**
49 * Settings link that appears on the plugins overview page
50 *
51 * @param array $links The plugin action links.
52 * @return array The action links, with a settings link pre-pended.
53 */
54 function imsanity_settings_link( $links ) {
55 if ( ! is_array( $links ) ) {
56 $links = array();
57 }
58 $settings_link = '<a href="' . get_admin_url( null, 'options-general.php?page=' . __FILE__ ) . '">' . esc_html__( 'Settings', 'imsanity' ) . '</a>';
59 array_unshift( $links, $settings_link );
60 return $links;
61 }
62
63 /**
64 * Queues up the AJAX script and any localized JS vars we need.
65 *
66 * @param string $hook The hook name for the current page.
67 */
68 function imsanity_queue_script( $hook ) {
69 // Make sure we are being called from the settings page.
70 if ( strpos( $hook, 'settings_page_imsanity' ) !== 0 ) {
71 return;
72 }
73 // Register the scripts that are used by the bulk resizer.
74 wp_enqueue_script( 'imsanity_script', plugins_url( '/scripts/imsanity.js', __FILE__ ), array( 'jquery' ), IMSANITY_VERSION );
75 wp_localize_script(
76 'imsanity_script',
77 'imsanity_vars',
78 array(
79 '_wpnonce' => wp_create_nonce( 'imsanity-bulk' ),
80 'resizing_complete' => esc_html__( 'Resizing Complete', 'imsanity' ),
81 'resize_selected' => esc_html__( 'Resize Selected Images', 'imsanity' ),
82 'image' => esc_html__( 'Image', 'imsanity' ),
83 'invalid_response' => esc_html__( 'Received an invalid response, please check for errors in the Developer Tools console of your browser.', 'imsanity' ),
84 'none_found' => esc_html__( 'There are no images that need to be resized.', 'imsanity' ),
85 )
86 );
87 add_action( 'admin_print_styles', 'imsanity_settings_css' );
88 }
89
90 /**
91 * Return true if the multi-site settings table exists
92 *
93 * @return bool True if the Imsanity table exists.
94 */
95 function imsanity_multisite_table_exists() {
96 global $wpdb;
97 return $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->imsanity_ms'" ) === $wpdb->imsanity_ms;
98 }
99
100 /**
101 * Checks the schema version for the Imsanity table.
102 *
103 * @return string The version identifier for the schema.
104 */
105 function imsanity_multisite_table_schema_version() {
106 // If the table doesn't exist then there is no schema to report.
107 if ( ! imsanity_multisite_table_exists() ) {
108 return '0';
109 }
110
111 global $wpdb;
112 $version = $wpdb->get_var( "SELECT data FROM $wpdb->imsanity_ms WHERE setting = 'schema'" );
113
114 if ( ! $version ) {
115 $version = '1.0'; // This is a legacy version 1.0 installation.
116 }
117
118 return $version;
119 }
120
121 /**
122 * Returns the default network settings in the case where they are not
123 * defined in the database, or multi-site is not enabled.
124 *
125 * @return stdClass
126 */
127 function imsanity_get_default_multisite_settings() {
128 $data = new stdClass();
129
130 $data->imsanity_override_site = false;
131 $data->imsanity_max_height = IMSANITY_DEFAULT_MAX_HEIGHT;
132 $data->imsanity_max_width = IMSANITY_DEFAULT_MAX_WIDTH;
133 $data->imsanity_max_height_library = IMSANITY_DEFAULT_MAX_HEIGHT;
134 $data->imsanity_max_width_library = IMSANITY_DEFAULT_MAX_WIDTH;
135 $data->imsanity_max_height_other = IMSANITY_DEFAULT_MAX_HEIGHT;
136 $data->imsanity_max_width_other = IMSANITY_DEFAULT_MAX_WIDTH;
137 $data->imsanity_bmp_to_jpg = IMSANITY_DEFAULT_BMP_TO_JPG;
138 $data->imsanity_png_to_jpg = IMSANITY_DEFAULT_PNG_TO_JPG;
139 $data->imsanity_deep_scan = false;
140 $data->imsanity_quality = IMSANITY_DEFAULT_QUALITY;
141 return $data;
142 }
143
144
145 /**
146 * On activation create the multisite database table if necessary. this is
147 * called when the plugin is activated as well as when it is automatically
148 * updated.
149 */
150 function imsanity_maybe_created_custom_table() {
151 // If not a multi-site no need to do any custom table lookups.
152 if ( ! function_exists( 'is_multisite' ) || ( ! is_multisite() ) ) {
153 return;
154 }
155
156 global $wpdb;
157
158 $schema = imsanity_multisite_table_schema_version();
159
160 if ( '0' === $schema ) {
161 // This is an initial database setup.
162 $sql = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->imsanity_ms . ' (
163 setting varchar(55),
164 data text NOT NULL,
165 PRIMARY KEY (setting)
166 );';
167
168 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
169 dbDelta( $sql );
170
171 // Add the rows to the database.
172 $data = imsanity_get_default_multisite_settings();
173 $wpdb->insert(
174 $wpdb->imsanity_ms,
175 array(
176 'setting' => 'multisite',
177 'data' => maybe_serialize( $data ),
178 )
179 );
180 $wpdb->insert(
181 $wpdb->imsanity_ms,
182 array(
183 'setting' => 'schema',
184 'data' => IMSANITY_SCHEMA_VERSION,
185 )
186 );
187 }
188
189 if ( IMSANITY_SCHEMA_VERSION !== $schema ) {
190 // This is a schema update. for the moment there is only one schema update available, from 1.0 to 1.1.
191 if ( '1.0' === $schema ) {
192 // Update from version 1.0 to 1.1.
193 $wpdb->insert(
194 $wpdb->imsanity_ms,
195 array(
196 'setting' => 'schema',
197 'data' => IMSANITY_SCHEMA_VERSION,
198 )
199 );
200 $wpdb->query( "ALTER TABLE $wpdb->imsanity_ms CHANGE COLUMN data data TEXT NOT NULL;" );
201 } else {
202 // @todo we don't have this yet
203 $wpdb->update(
204 $wpdb->imsanity_ms,
205 array( 'data' => IMSANITY_SCHEMA_VERSION ),
206 array( 'setting' => 'schema' )
207 );
208 }
209 }
210 }
211
212 /**
213 * Display the form for the multi-site settings page.
214 */
215 function imsanity_network_settings() {
216 $settings = imsanity_get_multisite_settings(); ?>
217 <div class="wrap">
218 <h1><?php esc_html_e( 'Imsanity Network Settings', 'imsanity' ); ?></h1>
219
220 <form method="post" action="settings.php?page=imsanity_network">
221 <input type="hidden" name="update_imsanity_settings" value="1" />
222 <?php wp_nonce_field( 'imsanity_network_options' ); ?>
223 <table class="form-table">
224 <tr>
225 <th scope="row"><label for="imsanity_override_site"><?php esc_html_e( 'Global Settings Override', 'imsanity' ); ?></label></th>
226 <td>
227 <select name="imsanity_override_site">
228 <option value="0" <?php selected( $settings->imsanity_override_site, '0' ); ?> ><?php esc_html_e( 'Allow each site to configure Imsanity settings', 'imsanity' ); ?></option>
229 <option value="1" <?php selected( $settings->imsanity_override_site, '1' ); ?> ><?php esc_html_e( 'Use global Imsanity settings (below) for all sites', 'imsanity' ); ?></option>
230 </select>
231 </td>
232 </tr>
233
234 <tr>
235 <th scope="row"><?php esc_html_e( 'Images uploaded within a Page/Post', 'imsanity' ); ?></th>
236 <td>
237 <label for="imsanity_max_width"><?php esc_html_e( 'Max Width', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class='small-text' name="imsanity_max_width" value="<?php echo (int) $settings->imsanity_max_width; ?>" />
238 <label for="imsanity_max_height"><?php esc_html_e( 'Max Height', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_height" value="<?php echo (int) $settings->imsanity_max_height; ?>" /> <?php esc_html_e( 'in pixels, enter 0 to disable', 'imsanity' ); ?>
239 </td>
240 </tr>
241
242 <tr>
243 <th scope="row"><?php esc_html_e( 'Images uploaded directly to the Media Library', 'imsanity' ); ?></th>
244 <td>
245 <label for="imsanity_max_width_library"><?php esc_html_e( 'Max Width', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class='small-text' name="imsanity_max_width_library" value="<?php echo (int) $settings->imsanity_max_width_library; ?>" />
246 <label for="imsanity_max_height_library"><?php esc_html_e( 'Max Height', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_height_library" value="<?php echo (int) $settings->imsanity_max_height_library; ?>" /> <?php esc_html_e( 'in pixels, enter 0 to disable', 'imsanity' ); ?>
247 </td>
248 </tr>
249
250 <tr>
251 <th scope="row"><?php esc_html_e( 'Images uploaded elsewhere (Theme headers, backgrounds, logos, etc)', 'imsanity' ); ?></th>
252 <td>
253 <label for="imsanity_max_width_other"><?php esc_html_e( 'Max Width', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class='small-text' name="imsanity_max_width_other" value="<?php echo (int) $settings->imsanity_max_width_other; ?>" />
254 <label for="imsanity_max_height_other"><?php esc_html_e( 'Max Height', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_height_other" value="<?php echo (int) $settings->imsanity_max_height_other; ?>" /> <?php esc_html_e( 'in pixels, enter 0 to disable', 'imsanity' ); ?>
255 </td>
256 </tr>
257
258 <tr>
259 <th scope="row"><label for"imsanity_bmp_to_jpg"><?php esc_html_e( 'Convert BMP to JPG', 'imsanity' ); ?></label></th>
260 <td><select name="imsanity_bmp_to_jpg">
261 <option value="1" <?php selected( $settings->imsanity_bmp_to_jpg, '1' ); ?> ><?php esc_html_e( 'Yes', 'imsanity' ); ?></option>
262 <option value="0" <?php selected( $settings->imsanity_bmp_to_jpg, '0' ); ?> ><?php esc_html_e( 'No', 'imsanity' ); ?></option>
263 </select></td>
264 </tr>
265
266 <tr>
267 <th scope="row"><label for="imsanity_png_to_jpg"><?php esc_html_e( 'Convert PNG to JPG', 'imsanity' ); ?></label></th>
268 <td><select name="imsanity_png_to_jpg">
269 <option value="1" <?php selected( $settings->imsanity_png_to_jpg, '1' ); ?> ><?php esc_html_e( 'Yes', 'imsanity' ); ?></option>
270 <option value="0" <?php selected( $settings->imsanity_png_to_jpg, '0' ); ?> ><?php esc_html_e( 'No', 'imsanity' ); ?></option>
271 </select></td>
272 </tr>
273
274 <tr>
275 <th scope="row"><label for='imsanity_quality' ><?php esc_html_e( 'JPG image quality', 'imsanity' ); ?></th>
276 <td><input type='text' id='imsanity_quality' name='imsanity_quality' class='small-text' value='<?php echo (int) $settings->imsanity_quality; ?>' /> <?php esc_html_e( 'Valid values are 1-100.', 'imsanity' ); ?>
277 <p class='description'><?php esc_html_e( 'WordPress default is 82', 'imsanity' ); ?></p></td>
278 </tr>
279
280 <tr>
281 <th scope="row"><label for="imsanity_deep_scan"><?php esc_html_e( 'Deep Scan', 'imsanity' ); ?></label></th>
282 <td><input type="checkbox" id="imsanity_deep_scan" name="imsanity_deep_scan" value="true"<?php echo ( $settings->imsanity_deep_scan ) ? " checked='true'" : ''; ?> /><?php esc_html_e( 'If searching repeatedly returns the same images, deep scanning will check the actual image dimensions instead of relying on metadata from the database.', 'imsanity' ); ?></td>
283 </tr>
284
285 </table>
286
287 <p class="submit"><input type="submit" class="button-primary" value="<?php esc_attr_e( 'Update Settings', 'imsanity' ); ?>" /></p>
288
289 </form>
290 <?php
291
292 echo '</div>';
293 }
294
295 /**
296 * Process the form, update the network settings
297 * and clear the cached settings
298 */
299 function imsanity_network_settings_update() {
300 if ( ! current_user_can( 'manage_options' ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'imsanity_network_options' ) ) {
301 return;
302 }
303 global $wpdb;
304 global $_imsanity_multisite_settings;
305
306 // ensure that the custom table is created when the user updates network settings
307 // this is not ideal but it's better than checking for this table existance
308 // on every page load.
309 imsanity_maybe_created_custom_table();
310
311 $data = new stdClass();
312
313 $data->imsanity_override_site = (bool) $_POST['imsanity_override_site'];
314 $data->imsanity_max_height = sanitize_text_field( $_POST['imsanity_max_height'] );
315 $data->imsanity_max_width = sanitize_text_field( $_POST['imsanity_max_width'] );
316 $data->imsanity_max_height_library = sanitize_text_field( $_POST['imsanity_max_height_library'] );
317 $data->imsanity_max_width_library = sanitize_text_field( $_POST['imsanity_max_width_library'] );
318 $data->imsanity_max_height_other = sanitize_text_field( $_POST['imsanity_max_height_other'] );
319 $data->imsanity_max_width_other = sanitize_text_field( $_POST['imsanity_max_width_other'] );
320 $data->imsanity_bmp_to_jpg = (bool) $_POST['imsanity_bmp_to_jpg'];
321 $data->imsanity_png_to_jpg = (bool) $_POST['imsanity_png_to_jpg'];
322 $data->imsanity_quality = imsanity_jpg_quality( $_POST['imsanity_quality'] );
323 $data->imsanity_deep_scan = empty( $_POST['imsanity_deep_scan'] ) ? 0 : 1;
324
325 $success = $wpdb->update(
326 $wpdb->imsanity_ms,
327 array( 'data' => maybe_serialize( $data ) ),
328 array( 'setting' => 'multisite' )
329 );
330
331 // Clear the cache.
332 $_imsanity_multisite_settings = null;
333 add_action( 'network_admin_notices', 'imsanity_network_settings_saved' );
334 }
335
336 /**
337 * Display a message to inform the user the multi-site setting have been saved.
338 */
339 function imsanity_network_settings_saved() {
340 echo "<div id='imsanity-network-settings-saved' class='updated fade'><p><strong>" . esc_html__( 'Imsanity network settings saved.', 'imsanity' ) . '</strong></p></div>';
341 }
342
343 /**
344 * Return the multi-site settings as a standard class. If the settings are not
345 * defined in the database or multi-site is not enabled then the default settings
346 * are returned. This is cached so it only loads once per page load, unless
347 * imsanity_network_settings_update is called.
348 *
349 * @return stdClass
350 */
351 function imsanity_get_multisite_settings() {
352 global $_imsanity_multisite_settings;
353 $result = null;
354
355 if ( ! $_imsanity_multisite_settings ) {
356 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
357 global $wpdb;
358 $result = $wpdb->get_var( "SELECT data FROM $wpdb->imsanity_ms WHERE setting = 'multisite'" );
359 }
360
361 // if there's no results, return the defaults instead.
362 $_imsanity_multisite_settings = $result
363 ? unserialize( $result )
364 : imsanity_get_default_multisite_settings();
365
366 // this is for backwards compatibility.
367 if ( ! isset( $_imsanity_multisite_settings->imsanity_max_height_library ) ) {
368 $_imsanity_multisite_settings->imsanity_max_height_library = $_imsanity_multisite_settings->imsanity_max_height;
369 $_imsanity_multisite_settings->imsanity_max_width_library = $_imsanity_multisite_settings->imsanity_max_width;
370 $_imsanity_multisite_settings->imsanity_max_height_other = $_imsanity_multisite_settings->imsanity_max_height;
371 $_imsanity_multisite_settings->imsanity_max_width_other = $_imsanity_multisite_settings->imsanity_max_width;
372 }
373 $_imsanity_multisite_settings->imsanity_override_site = ! empty( $_imsanity_multisite_settings->imsanity_override_site ) ? '1' : '0';
374 $_imsanity_multisite_settings->imsanity_bmp_to_jpg = ! empty( $_imsanity_multisite_settings->imsanity_bmp_to_jpg ) ? '1' : '0';
375 $_imsanity_multisite_settings->imsanity_png_to_jpg = ! empty( $_imsanity_multisite_settings->imsanity_png_to_jpg ) ? '1' : '0';
376 if ( ! property_exists( $_imsanity_multisite_settings, 'imsanity_deep_scan' ) ) {
377 $_imsanity_multisite_settings->imsanity_deep_scan = false;
378 }
379 }
380 return $_imsanity_multisite_settings;
381 }
382
383 /**
384 * Gets the option setting for the given key, first checking to see if it has been
385 * set globally for multi-site. Otherwise checking the site options.
386 *
387 * @param string $key The name of the option to retrieve.
388 * @param string $ifnull Value to use if the requested option returns null.
389 */
390 function imsanity_get_option( $key, $ifnull ) {
391 $result = null;
392
393 $settings = imsanity_get_multisite_settings();
394
395 if ( $settings->imsanity_override_site ) {
396 $result = $settings->$key;
397 if ( is_null( $result ) ) {
398 $result = $ifnull;
399 }
400 } else {
401 $result = get_option( $key, $ifnull );
402 }
403
404 return $result;
405 }
406
407 /**
408 * Register the configuration settings that the plugin will use
409 */
410 function imsanity_register_settings() {
411 if ( ! function_exists( 'is_plugin_active_for_network' ) && is_multisite() ) {
412 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
413 }
414 // We only want to update if the form has been submitted.
415 if ( isset( $_POST['update_imsanity_settings'] ) && is_multisite() && is_plugin_active_for_network( 'imsanity/imsanity.php' ) ) {
416 imsanity_network_settings_update();
417 }
418 // Register our settings.
419 register_setting( 'imsanity-settings-group', 'imsanity_max_height' );
420 register_setting( 'imsanity-settings-group', 'imsanity_max_width' );
421 register_setting( 'imsanity-settings-group', 'imsanity_max_height_library' );
422 register_setting( 'imsanity-settings-group', 'imsanity_max_width_library' );
423 register_setting( 'imsanity-settings-group', 'imsanity_max_height_other' );
424 register_setting( 'imsanity-settings-group', 'imsanity_max_width_other' );
425 register_setting( 'imsanity-settings-group', 'imsanity_bmp_to_jpg' );
426 register_setting( 'imsanity-settings-group', 'imsanity_png_to_jpg' );
427 register_setting( 'imsanity-settings-group', 'imsanity_quality', 'imsanity_jpg_quality' );
428 register_setting( 'imsanity-settings-group', 'imsanity_deep_scan' );
429 }
430
431 /**
432 * Validate and return the JPG quality setting.
433 *
434 * @param int $quality The JPG quality currently set.
435 * @return int The (potentially) adjusted quality level.
436 */
437 function imsanity_jpg_quality( $quality = null ) {
438 if ( is_null( $quality ) ) {
439 $quality = get_option( 'imsanity_quality' );
440 }
441 if ( preg_match( '/^(100|[1-9][0-9]?)$/', $quality ) ) {
442 return (int) $quality;
443 } else {
444 return IMSANITY_DEFAULT_QUALITY;
445 }
446 }
447
448 /**
449 * Helper function to render css styles for the settings forms
450 * for both site and network settings page
451 */
452 function imsanity_settings_css() {
453 echo '
454 <style>
455 #imsanity_header {
456 border: solid 1px #c6c6c6;
457 margin: 10px 0px;
458 padding: 0px 10px;
459 background-color: #e1e1e1;
460 }
461 #imsanity_header p {
462 margin: .5em 0;
463 }
464 </style>';
465 }
466
467 /**
468 * Render the settings page by writing directly to stdout. if multi-site is enabled
469 * and imsanity_override_site is true, then display a notice message that settings
470 * are not editable instead of the settings form
471 */
472 function imsanity_settings_page() {
473 ?>
474 <div class="wrap">
475 <h1><?php esc_html_e( 'Imsanity Settings', 'imsanity' ); ?></h1>
476 <?php
477
478 $settings = imsanity_get_multisite_settings();
479
480 if ( $settings->imsanity_override_site ) {
481 imsanity_settings_page_notice();
482 } else {
483 imsanity_settings_page_form();
484 }
485
486 ?>
487
488 <h2 style="margin-top: 0px;"><?php esc_html_e( 'Bulk Resize Images', 'imsanity' ); ?></h2>
489
490 <div id="imsanity_header">
491 <p><?php esc_html_e( 'If you have existing images that were uploaded prior to installing Imsanity, you may resize them all in bulk to recover disk space. To begin, click the "Search Images" button to search all existing attachments for images that are larger than the configured limit.', 'imsanity' ); ?></p>
492 <?php /* translators: %d: the number of images */ ?>
493 <p><?php printf( esc_html__( 'NOTE: To give you greater control over the resizing process, a maximum of %d images will be returned at one time. Bitmap images cannot be bulk resized and will not appear in the search results.', 'imsanity' ), IMSANITY_AJAX_MAX_RECORDS ); ?></p>
494 </div>
495
496 <div style="border: solid 1px #ff6666; background-color: #ffbbbb; padding: 0 10px;">
497 <h4><?php esc_html_e( 'WARNING: Bulk Resize will alter your original images and cannot be undone!', 'imsanity' ); ?></h4>
498
499 <p><?php esc_html_e( 'It is HIGHLY recommended that you backup your wp-content/uploads folder before proceeding. You will have a chance to preview and select the images to convert.', 'imsanity' ); ?><br>
500 <?php esc_html_e( 'It is also recommended that you initially select only 1 or 2 images and verify that everything is working properly before processing your entire library.', 'imsanity' ); ?></p>
501 </div>
502
503 <p class="submit" id="imsanity-examine-button">
504 <button class="button-primary" onclick="imsanity_load_images('imsanity_image_list');"><?php esc_html_e( 'Search Images...', 'imsanity' ); ?></button>
505 </p>
506 <div id='imsanity_image_list'>
507 <div id="imsanity_target" style="display: none; border: solid 2px #666666; padding: 10px; height: 0px; overflow: auto;">
508 <div id="imsanity_loading" style="display: none;"><img src="<?php echo plugins_url( 'images/ajax-loader.gif', __FILE__ ); ?>" style="margin-bottom: .25em; vertical-align:middle;" />
509 <?php esc_html_e( 'Scanning existing images. This may take a moment.', 'imsanity' ); ?>
510 </div>
511 </div>
512 </div>
513
514 <?php
515
516 echo '</div>';
517
518 }
519
520 /**
521 * Multi-user config file exists so display a notice
522 */
523 function imsanity_settings_page_notice() {
524 ?>
525 <div class="updated settings-error">
526 <p><strong><?php esc_html_e( 'Imsanity settings have been configured by the server administrator. There are no site-specific settings available.', 'imsanity' ); ?></strong></p>
527 </div>
528 <?php
529 }
530
531 /**
532 * Render the site settings form. This is processed by
533 * WordPress built-in options persistance mechanism
534 */
535 function imsanity_settings_page_form() {
536 ?>
537 <form method="post" action="options.php">
538 <?php settings_fields( 'imsanity-settings-group' ); ?>
539 <table class="form-table">
540
541 <tr>
542 <th scope="row"><?php esc_html_e( 'Images uploaded within a Page/Post', 'imsanity' ); ?></th>
543 <td>
544 <label for="imsanity_max_width"><?php esc_html_e( 'Max Width', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_width" value="<?php echo (int) get_option( 'imsanity_max_width', IMSANITY_DEFAULT_MAX_WIDTH ); ?>" />
545 <label for="imsanity_max_height"><?php esc_html_e( 'Max Height', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_height" value="<?php echo (int) get_option( 'imsanity_max_height', IMSANITY_DEFAULT_MAX_HEIGHT ); ?>" /> <?php esc_html_e( 'in pixels, enter 0 to disable', 'imsanity' ); ?>
546 </td>
547 </tr>
548
549 <tr>
550 <th scope="row"><?php esc_html_e( 'Images uploaded directly to the Media Library', 'imsanity' ); ?></th>
551 <td>
552 <label for="imsanity_max_width_library"><?php esc_html_e( 'Max Width', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_width_library" value="<?php echo (int) get_option( 'imsanity_max_width_library', IMSANITY_DEFAULT_MAX_WIDTH ); ?>" />
553 <label for="imsanity_max_height_library"><?php esc_html_e( 'Max Height', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_height_library" value="<?php echo (int) get_option( 'imsanity_max_height_library', IMSANITY_DEFAULT_MAX_HEIGHT ); ?>" /> <?php esc_html_e( 'in pixels, enter 0 to disable', 'imsanity' ); ?>
554 </td>
555 </tr>
556
557 <tr>
558 <th scope="row"><?php esc_html_e( 'Images uploaded elsewhere (Theme headers, backgrounds, logos, etc)', 'imsanity' ); ?></th>
559 <td>
560 <label for="imsanity_max_width_other"><?php esc_html_e( 'Max Width', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_width_other" value="<?php echo (int) get_option( 'imsanity_max_width_other', IMSANITY_DEFAULT_MAX_WIDTH ); ?>" />
561 <label for="imsanity_max_height_other"><?php esc_html_e( 'Max Height', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_height_other" value="<?php echo (int) get_option( 'imsanity_max_height_other', IMSANITY_DEFAULT_MAX_HEIGHT ); ?>" /> <?php esc_html_e( 'in pixels, enter 0 to disable', 'imsanity' ); ?>
562 </td>
563 </tr>
564
565
566 <tr>
567 <th scope="row"><label for='imsanity_quality' ><?php esc_html_e( 'JPG image quality', 'imsanity' ); ?></th>
568 <td><input type='text' id='imsanity_quality' name='imsanity_quality' class='small-text' value='<?php echo imsanity_jpg_quality(); ?>' /> <?php esc_html_e( 'Valid values are 1-100.', 'imsanity' ); ?>
569 <p class='description'><?php esc_html_e( 'WordPress default is 82', 'imsanity' ); ?></p></td>
570 </tr>
571
572 <tr>
573 <th scope="row"><label for="imsanity_bmp_to_jpg"><?php esc_html_e( 'Convert BMP To JPG', 'imsanity' ); ?></label></th>
574 <td><select name="imsanity_bmp_to_jpg">
575 <option <?php selected( get_option( 'imsanity_bmp_to_jpg', IMSANITY_DEFAULT_BMP_TO_JPG ), '1' ); ?> value="1"><?php esc_html_e( 'Yes', 'imsanity' ); ?></option>
576 <option <?php selected( get_option( 'imsanity_bmp_to_jpg', IMSANITY_DEFAULT_BMP_TO_JPG ), '0' ); ?> value="0"><?php esc_html_e( 'No', 'imsanity' ); ?></option>
577 </select></td>
578 </tr>
579
580 <tr>
581 <th scope="row"><label for="imsanity_png_to_jpg"><?php esc_html_e( 'Convert PNG To JPG', 'imsanity' ); ?></label></th>
582 <td><select name="imsanity_png_to_jpg">
583 <option <?php selected( get_option( 'imsanity_png_to_jpg', IMSANITY_DEFAULT_PNG_TO_JPG ), '1' ); ?> value="1"><?php esc_html_e( 'Yes', 'imsanity' ); ?></option>
584 <option <?php selected( get_option( 'imsanity_png_to_jpg', IMSANITY_DEFAULT_PNG_TO_JPG ), '0' ); ?> value="0"><?php esc_html_e( 'No', 'imsanity' ); ?></option>
585 </select></td>
586 </tr>
587
588 <tr>
589 <th scope="row"><label for="imsanity_deep_scan"><?php esc_html_e( 'Deep Scan', 'imsanity' ); ?></label></th>
590 <td><input type="checkbox" id="imsanity_deep_scan" name="imsanity_deep_scan" value="true"<?php echo ( get_option( 'imsanity_deep_scan' ) ) ? " checked='true'" : ''; ?> /><?php esc_html_e( 'If searching repeatedly returns the same images, deep scanning will check the actual image dimensions instead of relying on metadata from the database.', 'imsanity' ); ?></td>
591 </tr>
592 </table>
593
594 <p class="submit"><input type="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'imsanity' ); ?>" /></p>
595
596 </form>
597 <?php
598
599 }
600
601 ?>
602