Imsanity - Version 2.3.7

Version Description

  • fixed: uploads to Media Library not detected properly
  • changed: default JPG quality is now 82, to match the WordPress default
  • changed: fr_FR and ru_RU moved to WP.org language packs
  • changed: new maintainer
Download this release

Release Info

Developer nosilver4u
Plugin Icon 128x128 Imsanity
Version 2.3.7
Comparing to
See all releases

Version 2.3.7

ajax.php ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ################################################################################
4
+ * IMSANITY AJAX FUNCTIONS
5
+ * ################################################################################
6
+ */
7
+
8
+ add_action('wp_ajax_imsanity_get_images', 'imsanity_get_images');
9
+ add_action('wp_ajax_imsanity_resize_image', 'imsanity_resize_image');
10
+ add_action('admin_head', 'imsanity_admin_javascript');
11
+
12
+ /**
13
+ * Verifies that the current user has administrator permission and, if not,
14
+ * renders a json warning and dies
15
+ */
16
+ function imsanity_verify_permission()
17
+ {
18
+ if (!current_user_can('administrator'))
19
+ {
20
+ $results = array('success'=>false,'message' => 'Administrator permission is required');
21
+ echo json_encode($results);
22
+ die();
23
+ }
24
+ }
25
+
26
+
27
+ /**
28
+ * Searches for up to 250 images that are candidates for resize and renders them
29
+ * to the browser as a json array, then dies
30
+ */
31
+ function imsanity_get_images()
32
+ {
33
+ imsanity_verify_permission();
34
+
35
+ global $wpdb;
36
+
37
+ $query = $wpdb->prepare(
38
+ "select
39
+ $wpdb->posts.ID as ID,
40
+ $wpdb->posts.guid as guid,
41
+ $wpdb->postmeta.meta_value as file_meta
42
+ from $wpdb->posts
43
+ inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s
44
+ where $wpdb->posts.post_type = %s
45
+ and $wpdb->posts.post_mime_type like %s
46
+ and $wpdb->posts.post_mime_type != %s",
47
+ array('_wp_attachment_metadata', 'attachment', 'image%','image/bmp')
48
+ );
49
+
50
+ $images = $wpdb->get_results($query);
51
+ $results = array();
52
+
53
+ if ($images)
54
+ {
55
+ $maxW = imsanity_get_option('imsanity_max_width',IMSANITY_DEFAULT_MAX_WIDTH);
56
+ $maxH = imsanity_get_option('imsanity_max_height',IMSANITY_DEFAULT_MAX_HEIGHT);
57
+ $count = 0;
58
+
59
+ foreach ($images as $image)
60
+ {
61
+ $meta = unserialize($image->file_meta);
62
+
63
+ if ($meta['width'] > $maxW || $meta['height'] > $maxH)
64
+ {
65
+ $count++;
66
+
67
+ $results[] = array(
68
+ 'id'=>$image->ID,
69
+ 'width'=>$meta['width'],
70
+ 'height'=>$meta['height'],
71
+ 'file'=>$meta['file']
72
+ );
73
+ }
74
+
75
+ // make sure we only return a limited number of records so we don't overload the ajax features
76
+ if ($count >= IMSANITY_AJAX_MAX_RECORDS) break;
77
+ }
78
+ }
79
+
80
+ echo json_encode($results);
81
+ die(); // required by wordpress
82
+ }
83
+
84
+ /**
85
+ * Resizes the image with the given id according to the configured max width and height settings
86
+ * renders a json response indicating success/failure and dies
87
+ */
88
+ function imsanity_resize_image()
89
+ {
90
+ imsanity_verify_permission();
91
+
92
+ global $wpdb;
93
+
94
+ $id = intval( $_POST['id'] );
95
+
96
+ if (!$id)
97
+ {
98
+ $results = array('success'=>false,'message' => __('Missing ID Parameter','imsanity'));
99
+ echo json_encode($results);
100
+ die();
101
+ }
102
+
103
+ // @TODO: probably doesn't need the join...?
104
+ $query = $wpdb->prepare(
105
+ "select
106
+ $wpdb->posts.ID as ID,
107
+ $wpdb->posts.guid as guid,
108
+ $wpdb->postmeta.meta_value as file_meta
109
+ from $wpdb->posts
110
+ inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s
111
+ where $wpdb->posts.ID = %d
112
+ and $wpdb->posts.post_type = %s
113
+ and $wpdb->posts.post_mime_type like %s",
114
+ array('_wp_attachment_metadata', $id, 'attachment', 'image%')
115
+ );
116
+
117
+ $images = $wpdb->get_results($query);
118
+
119
+ if ($images)
120
+ {
121
+ $image = $images[0];
122
+ $meta = unserialize($image->file_meta);
123
+ $uploads = wp_upload_dir();
124
+ $oldPath = $uploads['basedir'] . "/" . $meta['file'];
125
+
126
+ $maxW = imsanity_get_option('imsanity_max_width',IMSANITY_DEFAULT_MAX_WIDTH);
127
+ $maxH = imsanity_get_option('imsanity_max_height',IMSANITY_DEFAULT_MAX_HEIGHT);
128
+
129
+ // method one - slow but accurate, get file size from file itself
130
+ // list($oldW, $oldH) = getimagesize( $oldPath );
131
+ // method two - get file size from meta, fast but resize will fail if meta is out of sync
132
+ $oldW = $meta['width'];
133
+ $oldH = $meta['height'];
134
+
135
+
136
+ if (($oldW > $maxW && $maxW > 0) || ($oldH > $maxH && $maxH > 0))
137
+ {
138
+ $quality = imsanity_get_option('imsanity_quality',IMSANITY_DEFAULT_QUALITY);
139
+
140
+ list($newW, $newH) = wp_constrain_dimensions($oldW, $oldH, $maxW, $maxH);
141
+
142
+ $resizeResult = imsanity_image_resize( $oldPath, $newW, $newH, false, null, null, $quality);
143
+ // $resizeResult = new WP_Error('invalid_image', __('Could not read image size'), $oldPath); // uncommend to debug fail condition
144
+
145
+ if (!is_wp_error($resizeResult))
146
+ {
147
+ $newPath = $resizeResult;
148
+
149
+ if ($newPath != $oldPath)
150
+ {
151
+ // remove original and replace with re-sized image
152
+ unlink($oldPath);
153
+ rename($newPath, $oldPath);
154
+ }
155
+
156
+ $meta['width'] = $newW;
157
+ $meta['height'] = $newH;
158
+
159
+ // @TODO replace custom query with update_post_meta
160
+ $update_query = $wpdb->prepare(
161
+ "update $wpdb->postmeta
162
+ set $wpdb->postmeta.meta_value = %s
163
+ where $wpdb->postmeta.post_id = %d
164
+ and $wpdb->postmeta.meta_key = %s",
165
+ array(maybe_serialize($meta), $image->ID, '_wp_attachment_metadata')
166
+ );
167
+
168
+ $wpdb->query($update_query);
169
+
170
+ $results = array('success'=>true,'id'=> $id, 'message' => sprintf(__('OK: %s','imsanity') , $oldPath) );
171
+ }
172
+ else
173
+ {
174
+ $results = array('success'=>false,'id'=> $id, 'message' => sprintf(__('ERROR: %s (%s)','imsanity'),$oldPath,htmlentities($resizeResult->get_error_message()) ) );
175
+ }
176
+ }
177
+ else
178
+ {
179
+ $results = array('success'=>true,'id'=> $id, 'message' => sprintf(__('SKIPPED: %s (Resize not required)','imsanity') , $oldPath ) );
180
+ }
181
+
182
+ }
183
+ else
184
+ {
185
+ $results = array('success'=>false,'id'=> $id, 'message' => sprintf(__('ERROR: (Attachment with ID of %s not found) ','imsanity') , htmlentities($id) ) );
186
+ }
187
+
188
+ // if there is a quota we need to reset the directory size cache so it will re-calculate
189
+ delete_transient('dirsize_cache');
190
+
191
+ echo json_encode($results);
192
+ die(); // required by wordpress
193
+ }
194
+
195
+ /**
196
+ * Output the javascript needed for making ajax calls into the header
197
+ */
198
+ function imsanity_admin_javascript()
199
+ {
200
+ // javascript is queued in settings.php imsanity_settings_banner()
201
+ }
202
+
203
+ ?>
images/ajax-loader.gif ADDED
Binary file
images/imsanity.png ADDED
Binary file
imsanity.php ADDED
@@ -0,0 +1,281 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Imsanity
4
+ Plugin URI: https://wordpress.org/plugins/imsanity/
5
+ Description: Imsanity stops insanely huge image uploads
6
+ Author: Shane Bishop
7
+ Version: 2.3.7
8
+ Author URI: https://ewww.io/
9
+ Text Domain: imsanity
10
+ License: GPLv3
11
+ */
12
+
13
+ define('IMSANITY_VERSION','2.3.7');
14
+ define('IMSANITY_SCHEMA_VERSION','1.1');
15
+
16
+ define('IMSANITY_DEFAULT_MAX_WIDTH',2048);
17
+ define('IMSANITY_DEFAULT_MAX_HEIGHT',2048);
18
+ define('IMSANITY_DEFAULT_BMP_TO_JPG',1);
19
+ define('IMSANITY_DEFAULT_PNG_TO_JPG',0);
20
+ define('IMSANITY_DEFAULT_QUALITY',82);
21
+
22
+ define( 'IMSANITY_SOURCE_POST', 1 );
23
+ define( 'IMSANITY_SOURCE_LIBRARY', 2 );
24
+ define( 'IMSANITY_SOURCE_OTHER', 4 );
25
+
26
+ if ( ! defined( 'IMSANITY_AJAX_MAX_RECORDS' ) ) {
27
+ define( 'IMSANITY_AJAX_MAX_RECORDS', 250 );
28
+ }
29
+
30
+ /**
31
+ * Load Translations
32
+ */
33
+ load_plugin_textdomain('imsanity', false, 'imsanity/languages/');
34
+
35
+ /**
36
+ * import supporting libraries
37
+ */
38
+ include_once(plugin_dir_path(__FILE__).'libs/utils.php');
39
+ include_once(plugin_dir_path(__FILE__).'settings.php');
40
+ include_once(plugin_dir_path(__FILE__).'ajax.php');
41
+
42
+ /**
43
+ * Fired with the WordPress upload dialog is displayed
44
+ */
45
+ function imsanity_upload_ui()
46
+ {
47
+ // TODO: output a message on the upload form showing that imanity is enabled
48
+ // echo '<p class="imsanity-upload-message">' . __("Imsanity plugin is enabled. Add the text 'noresize' to the filename to bypass.") . '</p>';
49
+ }
50
+
51
+
52
+ /**
53
+ * Inspects the request and determines where the upload came from
54
+ * @return IMSANITY_SOURCE_POST | IMSANITY_SOURCE_LIBRARY | IMSANITY_SOURCE_OTHER
55
+ */
56
+ function imsanity_get_source() {
57
+ $id = array_key_exists('post_id', $_REQUEST) ? $_REQUEST['post_id'] : '';
58
+ $action = array_key_exists('action', $_REQUEST) ? $_REQUEST['action'] : '';
59
+
60
+ // a post_id indicates image is attached to a post
61
+ if ($id > 0) return IMSANITY_SOURCE_POST;
62
+
63
+ // post_id of 0 is 3.x otherwise use the action parameter
64
+ if ( $id === 0 || $id === '0' || $action == 'upload-attachment' ) return IMSANITY_SOURCE_LIBRARY;
65
+
66
+ // we don't know where this one came from but $_REQUEST['_wp_http_referer'] may contain info
67
+ return IMSANITY_SOURCE_OTHER;
68
+ }
69
+
70
+ /**
71
+ * Given the source, returns the max width/height
72
+ *
73
+ * @example: list($w,$h) = imsanity_get_max_width_height(IMSANITY_SOURCE_LIBRARY);
74
+ * @param int IMSANITY_SOURCE_POST | IMSANITY_SOURCE_LIBRARY | IMSANITY_SOURCE_OTHER
75
+ */
76
+ function imsanity_get_max_width_height( $source ) {
77
+ $w = imsanity_get_option( 'imsanity_max_width',IMSANITY_DEFAULT_MAX_WIDTH );
78
+ $h = imsanity_get_option( 'imsanity_max_height',IMSANITY_DEFAULT_MAX_HEIGHT );
79
+
80
+ switch ( $source ) {
81
+ case IMSANITY_SOURCE_POST:
82
+ break;
83
+ case IMSANITY_SOURCE_LIBRARY:
84
+ $w = imsanity_get_option( 'imsanity_max_width_library',$w );
85
+ $h = imsanity_get_option( 'imsanity_max_height_library',$h );
86
+ break;
87
+ default:
88
+ $w = imsanity_get_option( 'imsanity_max_width_other',$w );
89
+ $h = imsanity_get_option( 'imsanity_max_height_other',$h );
90
+ break;
91
+ }
92
+
93
+ return array( $w, $h );
94
+ }
95
+
96
+ /**
97
+ * Handler after a file has been uploaded. If the file is an image, check the size
98
+ * to see if it is too big and, if so, resize and overwrite the original
99
+ * @param Array $params
100
+ */
101
+ function imsanity_handle_upload($params)
102
+ {
103
+ /* debug logging... */
104
+ // file_put_contents ( "debug.txt" , print_r($params,1) . "\n" );
105
+
106
+ // if "noresize" is included in the filename then we will bypass imsanity scaling
107
+ if (strpos($params['file'],'noresize') !== false) return $params;
108
+
109
+ // if preferences specify so then we can convert an original bmp or png file into jpg
110
+ if ($params['type'] == 'image/bmp' && imsanity_get_option('imsanity_bmp_to_jpg',IMSANITY_DEFAULT_BMP_TO_JPG)) {
111
+ $params = imsanity_convert_to_jpg('bmp',$params);
112
+ }
113
+
114
+ if ($params['type'] == 'image/png' && imsanity_get_option('imsanity_png_to_jpg',IMSANITY_DEFAULT_PNG_TO_JPG)) {
115
+ $params = imsanity_convert_to_jpg('png',$params);
116
+ }
117
+
118
+ // make sure this is a type of image that we want to convert and that it exists
119
+ // @TODO when uploads occur via RPC the image may not exist at this location
120
+ $oldPath = $params['file'];
121
+
122
+ // @HACK not currently working
123
+ // @see https://wordpress.org/support/topic/images-dont-resize-when-uploaded-via-mobile-device
124
+ // if (!file_exists($oldPath)) {
125
+ // $ud = wp_upload_dir();
126
+ // $oldPath = $ud['path'] . DIRECTORY_SEPARATOR . $oldPath;
127
+ // }
128
+
129
+ if ( (!is_wp_error($params)) && file_exists($oldPath) && in_array($params['type'], array('image/png','image/gif','image/jpeg')))
130
+ {
131
+
132
+ // figure out where the upload is coming from
133
+ $source = imsanity_get_source();
134
+
135
+ list($maxW,$maxH) = imsanity_get_max_width_height($source);
136
+
137
+ list($oldW, $oldH) = getimagesize( $oldPath );
138
+
139
+ /* HACK: if getimagesize returns an incorrect value (sometimes due to bad EXIF data..?)
140
+ $img = imagecreatefromjpeg ($oldPath);
141
+ $oldW = imagesx ($img);
142
+ $oldH = imagesy ($img);
143
+ imagedestroy ($img);
144
+ //*/
145
+
146
+ /* HACK: an animated gif may have different frame sizes. to get the "screen" size
147
+ $data = ''; // TODO: convert file to binary
148
+ $header = unpack('@6/vwidth/vheight', $data );
149
+ $oldW = $header['width'];
150
+ $oldH = $header['width'];
151
+ //*/
152
+
153
+ if (($oldW > $maxW && $maxW > 0) || ($oldH > $maxH && $maxH > 0))
154
+ {
155
+ $quality = imsanity_get_option('imsanity_quality',IMSANITY_DEFAULT_QUALITY);
156
+
157
+ list($newW, $newH) = wp_constrain_dimensions($oldW, $oldH, $maxW, $maxH);
158
+
159
+ $resizeResult = imsanity_image_resize( $oldPath, $newW, $newH, false, null, null, $quality);
160
+
161
+ /* uncomment to debug error handling code: */
162
+ // $resizeResult = new WP_Error('invalid_image', __(print_r($_REQUEST)), $oldPath);
163
+
164
+ if (!is_wp_error($resizeResult))
165
+ {
166
+ $newPath = $resizeResult;
167
+
168
+ if (filesize($newPath) < filesize($oldPath)) {
169
+ // we saved some file space. remove original and replace with resized image
170
+ unlink($oldPath);
171
+ rename($newPath, $oldPath);
172
+ }
173
+ else {
174
+ // theresized image is actually bigger in filesize (most likely due to jpg quality).
175
+ // keep the old one and just get rid of the resized image
176
+ unlink($newPath);
177
+ }
178
+ }
179
+ else
180
+ {
181
+ // resize didn't work, likely because the image processing libraries are missing
182
+
183
+ // remove the old image so we don't leave orphan files hanging around
184
+ unlink($oldPath);
185
+
186
+ $params = wp_handle_upload_error( $oldPath ,
187
+ sprintf( __("Oh Snap! Imsanity was unable to resize this image "
188
+ . "for the following reason: '%s'
189
+ . If you continue to see this error message, you may need to either install missing server"
190
+ . " components or disable the Imsanity plugin."
191
+ . " If you think you have discovered a bug, please report it on the Imsanity support forum.", 'imsanity' ) ,$resizeResult->get_error_message() ) );
192
+
193
+ }
194
+ }
195
+
196
+ }
197
+
198
+ return $params;
199
+ }
200
+
201
+
202
+ /**
203
+ * read in the image file from the params and then save as a new jpg file.
204
+ * if successful, remove the original image and alter the return
205
+ * parameters to return the new jpg instead of the original
206
+ *
207
+ * @param string 'bmp' or 'png'
208
+ * @param array $params
209
+ * @return array altered params
210
+ */
211
+ function imsanity_convert_to_jpg($type,$params)
212
+ {
213
+
214
+ $img = null;
215
+
216
+ if ($type == 'bmp') {
217
+ include_once('libs/imagecreatefrombmp.php');
218
+ $img = imagecreatefrombmp($params['file']);
219
+ }
220
+ elseif ($type == 'png') {
221
+
222
+ if(!function_exists('imagecreatefrompng')) {
223
+ return wp_handle_upload_error( $params['file'],'imsanity_convert_to_jpg requires gd library enabled');
224
+ }
225
+
226
+ $img = imagecreatefrompng($params['file']);
227
+ // convert png transparency to white
228
+ $bg = imagecreatetruecolor(imagesx($img), imagesy($img));
229
+ imagefill($bg, 0, 0, imagecolorallocate($bg, 255, 255, 255));
230
+ imagealphablending($bg, TRUE);
231
+ imagecopy($bg, $img, 0, 0, 0, 0, imagesx($img), imagesy($img));
232
+
233
+ }
234
+ else {
235
+ return wp_handle_upload_error( $params['file'],'Unknown image type specified in imsanity_convert_to_jpg');
236
+ }
237
+
238
+ // we need to change the extension from the original to .jpg so we have to ensure it will be a unique filename
239
+ $uploads = wp_upload_dir();
240
+ $oldFileName = basename($params['file']);
241
+ $newFileName = basename(str_ireplace(".".$type, ".jpg", $oldFileName));
242
+ $newFileName = wp_unique_filename( $uploads['path'], $newFileName );
243
+
244
+ $quality = imsanity_get_option('imsanity_quality',IMSANITY_DEFAULT_QUALITY);
245
+
246
+ if (imagejpeg($img,$uploads['path'] . '/' . $newFileName, $quality))
247
+ {
248
+ // conversion succeeded. remove the original bmp & remap the params
249
+ unlink($params['file']);
250
+
251
+ $params['file'] = $uploads['path'] . '/' . $newFileName;
252
+ $params['url'] = $uploads['url'] . '/' . $newFileName;
253
+ $params['type'] = 'image/jpeg';
254
+ }
255
+ else
256
+ {
257
+ unlink($params['file']);
258
+
259
+ return wp_handle_upload_error( $oldPath,
260
+ __("Oh Snap! Imsanity was Unable to process the $type file. "
261
+ ."If you continue to see this error you may need to disable the $type-To-JPG "
262
+ ."feature in Imsanity settings.", 'imsanity' ) );
263
+ }
264
+
265
+ return $params;
266
+ }
267
+
268
+
269
+ /* add filters to hook into uploads */
270
+ add_filter( 'wp_handle_upload', 'imsanity_handle_upload' );
271
+
272
+ /* add filters/actions to customize upload page */
273
+ //add_action('post-upload-ui', 'imsanity_upload_ui');
274
+
275
+
276
+
277
+
278
+ // TODO: if necessary to update the post data in the future...
279
+ // add_filter( 'wp_update_attachment_metadata', 'imsanity_handle_update_attachment_metadata' );
280
+
281
+ ?>
languages/imsanity-es_MX.mo ADDED
Binary file
languages/imsanity-es_MX.po ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Translation of Plugins - Imsanity - Development (trunk) in Spanish (Mexico)
2
+ # This file is distributed under the same license as the Plugins - Imsanity - Development (trunk) package.
3
+ msgid ""
4
+ msgstr ""
5
+ "PO-Revision-Date: 2015-12-08 16:01:42+0000\n"
6
+ "MIME-Version: 1.0\n"
7
+ "Content-Type: text/plain; charset=UTF-8\n"
8
+ "Content-Transfer-Encoding: 8bit\n"
9
+ "Plural-Forms: nplurals=2; plural=n != 1;\n"
10
+ "X-Generator: GlotPress/2.3.0-alpha\n"
11
+ "Language: es_MX\n"
12
+ "Project-Id-Version: Plugins - Imsanity - Development (trunk)\n"
13
+
14
+ #. Author URI of the plugin/theme
15
+ msgid "http://verysimple.com/"
16
+ msgstr ""
17
+
18
+ #. Author of the plugin/theme
19
+ msgid "Jason Hinkle"
20
+ msgstr ""
21
+
22
+ #. Description of the plugin/theme
23
+ msgid "Imsanity stops insanely huge image uploads"
24
+ msgstr ""
25
+
26
+ #. Plugin URI of the plugin/theme
27
+ msgid "http://verysimple.com/products/imsanity/"
28
+ msgstr ""
29
+
30
+ #. Plugin Name of the plugin/theme
31
+ msgid "Imsanity"
32
+ msgstr ""
33
+
34
+ #: settings.php:628
35
+ msgid "Save Changes"
36
+ msgstr "Guardar Cambios"
37
+
38
+ #: settings.php:619
39
+ msgid "Convert PNG To JPG"
40
+ msgstr ""
41
+
42
+ #: settings.php:611
43
+ msgid "Convert BMP To JPG"
44
+ msgstr "Convertir BMP a JPG"
45
+
46
+ #: settings.php:597
47
+ msgid "JPG image quality"
48
+ msgstr "Calidad de imagen JPG"
49
+
50
+ #: settings.php:556
51
+ msgid "Imsanity settings have been configured by the server administrator. There are no site-specific settings available."
52
+ msgstr "Configuración de Imsanity se han configurado por el administrador del servidor. No se dispone de ninguna configuración específica."
53
+
54
+ #: settings.php:539
55
+ msgid "Search Images..."
56
+ msgstr "Búsqueda de imágenes..."
57
+
58
+ #: settings.php:532
59
+ msgid ""
60
+ "It is <strong>HIGHLY</strong> recommended that you backup \n"
61
+ "\t\tyour wp-content/uploads folder before proceeding. You will have a chance to preview and select the images to convert.\n"
62
+ "\t\tIt is also recommended that you initially select only 1 or 2 images and verify that everything is ok before\n"
63
+ "\t\tprocessing your entire library. You have been warned!"
64
+ msgstr ""
65
+ "<strong>Importante!</strong> Es recomendable que realizar el backup de carpeta wp-content/uploads \\\t\\\tyour antes de proceder. Usted tendrá la oportunidad de escuchar y seleccionar las imágenes a convertir.\n"
66
+ "\\\t\\\tIt también se recomienda que inicialmente seleccionar sólo 1 ó 2 imágenes y comprobar que todo está bien antes de \\\t\\\tprocessing la biblioteca entera. Estáis avisados."
67
+
68
+ #: settings.php:530
69
+ msgid "WARNING: BULK RESIZE WILL ALTER YOUR ORIGINAL IMAGES AND CANNOT BE UNDONE!"
70
+ msgstr "ADVERTENCIA: A GRANEL RESIZE ALTERARÁ SUS IMÁGENES ORIGINALES Y NO SE PUEDE DESHACER!"
71
+
72
+ #: settings.php:519
73
+ msgid "Bulk Resize Images"
74
+ msgstr "A granel redimensionar imágenes"
75
+
76
+ #: settings.php:501
77
+ msgid "Imsanity Settings"
78
+ msgstr "Configuración de Imsanity"
79
+
80
+ #: settings.php:484
81
+ msgid "<p>Imsanity Version %s by %s </p>"
82
+ msgstr "<p>Imsanity versión %s de %s</p>"
83
+
84
+ #: settings.php:469
85
+ msgid ""
86
+ "<p>Imsanity automaticaly reduces the size of images that are larger than the specified maximum and replaces the original\n"
87
+ "\t\twith one of a more \"sane\" size. Site contributors don\\'t need to concern themselves with manually scaling images\n"
88
+ "\t\tand can upload them directly from their camera or phone.</p>\n"
89
+ "\n"
90
+ "\t\t<p>The resolution of modern cameras is larger than necessary for typical web display.\n"
91
+ "\t\tThe average computer screen is not big enough to display a 3 megapixel camera-phone image at full resolution.\n"
92
+ "\t\tWordPress does a good job of creating scaled-down copies which can be used, however the original images\n"
93
+ "\t\tare permanently stored, taking up disk quota and, if used on a page, create a poor viewer experience.</p>\n"
94
+ "\n"
95
+ "\t\t<p>This plugin is designed for sites where high-resolution images are not necessary and/or site contributors\n"
96
+ "\t\tdo not want (or understand how) to deal with scaling images. This plugin should not be used on\n"
97
+ "\t\tsites for which original, high-resolution images must be stored.</p>\n"
98
+ "\n"
99
+ "\t\t<p>Be sure to save back-ups of your full-sized images if you wish to keep them.</p>"
100
+ msgstr ""
101
+ "<p>Imsanity reduce de forma automática el tamaño de las imágenes que son más grandes que el máximo especificado y sustituye al original\n"
102
+ "\\\t\\\twith uno de un tamaño más\"sano\" . Colaboradores del sitio don\\'t tiene que preocuparse por la ampliación de imágenes manualmente\n"
103
+ "\\\t\\\tand puede cargar directamente desde su cámara o teléfono . < / P>\n"
104
+ "\n"
105
+ "\\\t\\\t <p> La resolución de las cámaras modernas es más grande de lo necesario para la visualización web típica .\n"
106
+ "\\\t\\pantalla media lLa no es lo suficientemente grande como para mostrar una imagen de la cámara - teléfono 3 megapíxeles con la máxima resolución .\n"
107
+ "\\\t\\\tWordPress hace un buen trabajo de crear a escala reducida copias que se pueden utilizar , sin embargo, las imágenes originales\n"
108
+ "\\\t\\\tara almacenado de forma permanente , tomando cuota de disco y , si se utiliza en una página, crear una experiencia pobre espectador. < / p>\n"
109
+ "\n"
110
+ "\\\t\\\t < p> Este plugin está diseñado para los sitios donde las imágenes de alta resolución no son necesarios y / o sitio contribuyentes\n"
111
+ "\\\t\\\tno quieren ( o entender cómo) para hacer frente a las imágenes de escala. Este complemento no se debe utilizar en\n"
112
+ "\\\t\\\tsites para que las imágenes originales de alta resolución deben ser almacenados . </p>\n"
113
+ "\n"
114
+ "\\\t\\\t <p> Asegúrese de guardar copias de seguridad de toda su imágenes de tamaño si lo desea para mantenerlos . </p>"
115
+
116
+ #: settings.php:467
117
+ msgid "Imsanity automatically resizes insanely huge image uploads"
118
+ msgstr "Automáticamente cambia el tamaño de imagen enorme subidas"
119
+
120
+ #: settings.php:286
121
+ msgid "Update Settings"
122
+ msgstr "Configuración de actualización"
123
+
124
+ #: settings.php:281 settings.php:607
125
+ msgid " (WordPress default is 90)"
126
+ msgstr " (Por defecto de WordPress es 90)"
127
+
128
+ #: settings.php:271
129
+ msgid "JPG Quality"
130
+ msgstr "Calidad JPG"
131
+
132
+ #: settings.php:263
133
+ msgid "Convert PNG to JPG"
134
+ msgstr ""
135
+
136
+ #: settings.php:258 settings.php:266 settings.php:614 settings.php:622
137
+ msgid "No"
138
+ msgstr "No"
139
+
140
+ #: settings.php:257 settings.php:265 settings.php:613 settings.php:621
141
+ msgid "Yes"
142
+ msgstr "Si"
143
+
144
+ #: settings.php:255
145
+ msgid "Convert BMP to JPG"
146
+ msgstr "Convertir BMP a JPG"
147
+
148
+ #: settings.php:247 settings.php:589
149
+ msgid "Images uploaded elsewhere (Theme headers, backgrounds, logos, etc)"
150
+ msgstr "Imágenes subidas en otros lugares (tema cabeceras, fondos, logotipos, etc.)"
151
+
152
+ #: settings.php:239 settings.php:582
153
+ msgid "Images uploaded directly to the Media Library"
154
+ msgstr "Imágenes subidas directamente a la biblioteca multimedia"
155
+
156
+ #: settings.php:234 settings.php:242 settings.php:250 settings.php:577
157
+ #: settings.php:584 settings.php:591
158
+ msgid " (or enter 0 to disable)"
159
+ msgstr " (o escriba 0 para desactivar)"
160
+
161
+ #: settings.php:231 settings.php:575
162
+ msgid "Images uploaded within a Page/Post"
163
+ msgstr "Imágenes subidas dentro de un página y Post"
164
+
165
+ #: settings.php:225
166
+ msgid "Use global Imsanity settings (below) for all sites"
167
+ msgstr "Utilice la configuración global Imsanity (abajo) para todos los sitios"
168
+
169
+ #: settings.php:224
170
+ msgid "Allow each site to configure Imsanity settings"
171
+ msgstr "Permitir que cada sitio configurar las opciones de Imsanity"
172
+
173
+ #: settings.php:221
174
+ msgid "Global Settings Override"
175
+ msgstr "Anulación de la configuración global"
176
+
177
+ #: settings.php:207
178
+ msgid "Imsanity network settings saved."
179
+ msgstr "Configuración de red Imsanity guardado."
180
+
181
+ #: settings.php:187 settings.php:200
182
+ msgid "Imsanity Network Settings"
183
+ msgstr "Configuración de red Imsanity"
184
+
185
+ #: settings.php:40
186
+ msgid "Imsanity Plugin Settings"
187
+ msgstr "Configuración de Imsanity"
188
+
189
+ #: libs/imagecreatefrombmp.php:129
190
+ msgid "imagecreatefrombmp: %s has %d bits and this is not supported!"
191
+ msgstr "imagecreatefrombmp: %s tiene %d bits y esto no es compatible."
192
+
193
+ #: libs/imagecreatefrombmp.php:43
194
+ msgid "imagecreatefrombmp: Can not obtain filesize of %s !"
195
+ msgstr "imagecreatefrombmp: no puede obtener tamaño de %s!"
196
+
197
+ #: libs/imagecreatefrombmp.php:21
198
+ msgid "imagecreatefrombmp: %s is not a bitmap!"
199
+ msgstr "imagecreatefrombmp: %s no es un mapa de bits."
200
+
201
+ #: libs/imagecreatefrombmp.php:14
202
+ msgid "imagecreatefrombmp: Can not open %s!"
203
+ msgstr "imagecreatefrombmp: no se puede abrir %s!"
204
+
205
+ #: ajax.php:185
206
+ msgid "ERROR: (Attachment with ID of %s not found) "
207
+ msgstr "ERROR: (Adjunto con el ID de %s no encontrado) "
208
+
209
+ #: ajax.php:179
210
+ msgid "SKIPPED: %s (Resize not required)"
211
+ msgstr "OMITIDOS: %s (no es necesario redimensionar)"
212
+
213
+ #: ajax.php:174
214
+ msgid "ERROR: %s (%s)"
215
+ msgstr "ERROR: %s (%s)"
216
+
217
+ #: ajax.php:170
218
+ msgid "OK: %s"
219
+ msgstr "Bueno %s"
220
+
221
+ #: ajax.php:98
222
+ msgid "Missing ID Parameter"
223
+ msgstr "Falta el parámetro ID"
languages/imsanity-sv_SE.mo ADDED
Binary file
languages/imsanity-sv_SE.po ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Translation of Plugins - Imsanity - Development (trunk) in Swedish
2
+ # This file is distributed under the same license as the Plugins - Imsanity - Development (trunk) package.
3
+ msgid ""
4
+ msgstr ""
5
+ "PO-Revision-Date: 2015-09-23 14:53:56+0000\n"
6
+ "MIME-Version: 1.0\n"
7
+ "Content-Type: text/plain; charset=UTF-8\n"
8
+ "Content-Transfer-Encoding: 8bit\n"
9
+ "Plural-Forms: nplurals=2; plural=n != 1;\n"
10
+ "X-Generator: GlotPress/2.3.0-alpha\n"
11
+ "Language: sv_SE\n"
12
+ "Project-Id-Version: Plugins - Imsanity - Development (trunk)\n"
13
+
14
+ #. Author URI of the plugin/theme
15
+ msgid "http://verysimple.com/"
16
+ msgstr ""
17
+
18
+ #. Author of the plugin/theme
19
+ msgid "Jason Hinkle"
20
+ msgstr ""
21
+
22
+ #. Description of the plugin/theme
23
+ msgid "Imsanity stops insanely huge image uploads"
24
+ msgstr ""
25
+
26
+ #. Plugin URI of the plugin/theme
27
+ msgid "http://verysimple.com/products/imsanity/"
28
+ msgstr ""
29
+
30
+ #. Plugin Name of the plugin/theme
31
+ msgid "Imsanity"
32
+ msgstr ""
33
+
34
+ #: settings.php:628
35
+ msgid "Save Changes"
36
+ msgstr "Spara Ändringar"
37
+
38
+ #: settings.php:619
39
+ msgid "Convert PNG To JPG"
40
+ msgstr ""
41
+
42
+ #: settings.php:611
43
+ msgid "Convert BMP To JPG"
44
+ msgstr "Konvertera BMP till JPG"
45
+
46
+ #: settings.php:597
47
+ msgid "JPG image quality"
48
+ msgstr "Bildkvalitet för JPG"
49
+
50
+ #: settings.php:556
51
+ msgid "Imsanity settings have been configured by the server administrator. There are no site-specific settings available."
52
+ msgstr "Imsanitys inställningar har konfigurerats av serveradministratören. Det finns inga webbplatsspecifika inställningar tillgängliga."
53
+
54
+ #: settings.php:539
55
+ msgid "Search Images..."
56
+ msgstr "Sök Bilder..."
57
+
58
+ #: settings.php:532
59
+ msgid ""
60
+ "It is <strong>HIGHLY</strong> recommended that you backup \n"
61
+ "\t\tyour wp-content/uploads folder before proceeding. You will have a chance to preview and select the images to convert.\n"
62
+ "\t\tIt is also recommended that you initially select only 1 or 2 images and verify that everything is ok before\n"
63
+ "\t\tprocessing your entire library. You have been warned!"
64
+ msgstr ""
65
+ "Du rekommenderas <strong>STARKT</strong> att ta backup på \n"
66
+ "\t\tdin wp-content/uploads mapp innan du fortsätter. Du kommer att få möjlighet att förhandsvisa och välja bilder att konvertera.\n"
67
+ "\t\tDu rekommenderas också att först prova med 1 eller 2 bilder och kontrollera att all är ok innan\n"
68
+ "\t\tdu processar hela mediabiblioteket. Du har blivit varnad!"
69
+
70
+ #: settings.php:530
71
+ msgid "WARNING: BULK RESIZE WILL ALTER YOUR ORIGINAL IMAGES AND CANNOT BE UNDONE!"
72
+ msgstr "VARNING: BULKSKALNING KOMMER ATT ÄNDRA ORIGINALBILDERNA OCH KAN INTE ÅNGRAS!"
73
+
74
+ #: settings.php:519
75
+ msgid "Bulk Resize Images"
76
+ msgstr "Bulkskala Bilder"
77
+
78
+ #: settings.php:501
79
+ msgid "Imsanity Settings"
80
+ msgstr "Imsanity Inställningar"
81
+
82
+ #: settings.php:484
83
+ msgid "<p>Imsanity Version %s by %s </p>"
84
+ msgstr "<p>Imsanity Version %s av %s </p>"
85
+
86
+ #: settings.php:469
87
+ msgid ""
88
+ "<p>Imsanity automaticaly reduces the size of images that are larger than the specified maximum and replaces the original\n"
89
+ "\t\twith one of a more \"sane\" size. Site contributors don\\'t need to concern themselves with manually scaling images\n"
90
+ "\t\tand can upload them directly from their camera or phone.</p>\n"
91
+ "\n"
92
+ "\t\t<p>The resolution of modern cameras is larger than necessary for typical web display.\n"
93
+ "\t\tThe average computer screen is not big enough to display a 3 megapixel camera-phone image at full resolution.\n"
94
+ "\t\tWordPress does a good job of creating scaled-down copies which can be used, however the original images\n"
95
+ "\t\tare permanently stored, taking up disk quota and, if used on a page, create a poor viewer experience.</p>\n"
96
+ "\n"
97
+ "\t\t<p>This plugin is designed for sites where high-resolution images are not necessary and/or site contributors\n"
98
+ "\t\tdo not want (or understand how) to deal with scaling images. This plugin should not be used on\n"
99
+ "\t\tsites for which original, high-resolution images must be stored.</p>\n"
100
+ "\n"
101
+ "\t\t<p>Be sure to save back-ups of your full-sized images if you wish to keep them.</p>"
102
+ msgstr ""
103
+ "<p>Imsanity reducerar automatiskt storleken på bilder som är större än den specificerade maxstorleken och ersätter originalet\n"
104
+ "\t\tmed en version som har en mer \"sund\" storlek. Webbplatsmedarbetare behöver inte bekymra sig om att manuellt skala bilder\n"
105
+ "\t\toch kan ladda upp dem direkt från sin kamera eller mobil.</p>\n"
106
+ "\n"
107
+ "\t\t<p>Upplösningen på moderna kameror är högre än nödvändigt för vanlig webbvisning.\n"
108
+ "\t\tDen genomsnittliga datorskärmen är inte stor nog att visa en 3 megapixels bild från kamera/telefon i full upplösning.\n"
109
+ "\t\tWordPress gör ett bra jobb med att skapa nedskalade kopior som kan användas, men originalbilderna\n"
110
+ "\t\tlagras permanent och upptar diskutrymme och skapar en dålig visuell upplevelse för besökaren om de används på en sida.</p>\n"
111
+ "\n"
112
+ "\t\t<p>Detta insticksprogram är designat för webbplatser där högupplösta bilder inte är nödvändiga och/eller webbplatsmedarbetare\n"
113
+ "\t\tinte vill (eller kan) skala bilder. Detta insticksprogram bör inte användas på\n"
114
+ "\t\twebbplatser där högupplösta bildoriginal måste lagras.</p>\n"
115
+ "\n"
116
+ "\t\t<p>Se till att spara kopior av dina bildoriginal i full storlek om du vill behålla dem.</p>"
117
+
118
+ #: settings.php:467
119
+ msgid "Imsanity automatically resizes insanely huge image uploads"
120
+ msgstr "Imsanity förminskar automatiskt uppladdade bilder som är galet stora"
121
+
122
+ #: settings.php:286
123
+ msgid "Update Settings"
124
+ msgstr "Uppdatera Inställningar"
125
+
126
+ #: settings.php:281 settings.php:607
127
+ msgid " (WordPress default is 90)"
128
+ msgstr " (Wordpress standardinställning är 90)"
129
+
130
+ #: settings.php:271
131
+ msgid "JPG Quality"
132
+ msgstr "JPG-kvalitet"
133
+
134
+ #: settings.php:263
135
+ msgid "Convert PNG to JPG"
136
+ msgstr ""
137
+
138
+ #: settings.php:258 settings.php:266 settings.php:614 settings.php:622
139
+ msgid "No"
140
+ msgstr "Nej"
141
+
142
+ #: settings.php:257 settings.php:265 settings.php:613 settings.php:621
143
+ msgid "Yes"
144
+ msgstr "Ja"
145
+
146
+ #: settings.php:255
147
+ msgid "Convert BMP to JPG"
148
+ msgstr "Konvertera BMP till JPG"
149
+
150
+ #: settings.php:247 settings.php:589
151
+ msgid "Images uploaded elsewhere (Theme headers, backgrounds, logos, etc)"
152
+ msgstr "Bilder uppladdade på andra ställen (Sidhuvud för teman, bakgrunder, logotyper, etc.)"
153
+
154
+ #: settings.php:239 settings.php:582
155
+ msgid "Images uploaded directly to the Media Library"
156
+ msgstr "Bilder uppladdade direkt till Mediabiblioteket"
157
+
158
+ #: settings.php:234 settings.php:242 settings.php:250 settings.php:577
159
+ #: settings.php:584 settings.php:591
160
+ msgid " (or enter 0 to disable)"
161
+ msgstr "(eller ange 0 för att deaktivera)"
162
+
163
+ #: settings.php:231 settings.php:575
164
+ msgid "Images uploaded within a Page/Post"
165
+ msgstr "Bilder uppladdade till en Sida/Inlägg"
166
+
167
+ #: settings.php:225
168
+ msgid "Use global Imsanity settings (below) for all sites"
169
+ msgstr "Använd Imsanitys globala inställningar (nedan) för alla webbplatser"
170
+
171
+ #: settings.php:224
172
+ msgid "Allow each site to configure Imsanity settings"
173
+ msgstr "Tillåt varje webbplats att konfigurera Imsanitys inställningar"
174
+
175
+ #: settings.php:221
176
+ msgid "Global Settings Override"
177
+ msgstr "Åsidosätt Globala Inställningar"
178
+
179
+ #: settings.php:207
180
+ msgid "Imsanity network settings saved."
181
+ msgstr "Imsanity nätverksinställningar sparades."
182
+
183
+ #: settings.php:187 settings.php:200
184
+ msgid "Imsanity Network Settings"
185
+ msgstr "Imsanity Nätverksinställningar"
186
+
187
+ #: settings.php:40
188
+ msgid "Imsanity Plugin Settings"
189
+ msgstr "Imsanity Programinställningar"
190
+
191
+ #: libs/imagecreatefrombmp.php:129
192
+ msgid "imagecreatefrombmp: %s has %d bits and this is not supported!"
193
+ msgstr "imagecreatefrombmp: %s har %d bits vilket inte stöds!"
194
+
195
+ #: libs/imagecreatefrombmp.php:43
196
+ msgid "imagecreatefrombmp: Can not obtain filesize of %s !"
197
+ msgstr "imagecreatefrombmp: Kan inte hämta filstorlek %s!"
198
+
199
+ #: libs/imagecreatefrombmp.php:21
200
+ msgid "imagecreatefrombmp: %s is not a bitmap!"
201
+ msgstr "imagecreatefrombmp: %s är ingen bitmap!"
202
+
203
+ #: libs/imagecreatefrombmp.php:14
204
+ msgid "imagecreatefrombmp: Can not open %s!"
205
+ msgstr "imagecreatefrombmp: Kan inte öppna %s !"
206
+
207
+ #: ajax.php:185
208
+ msgid "ERROR: (Attachment with ID of %s not found) "
209
+ msgstr "FEL: (Bilaga med ID %s hittades ej) "
210
+
211
+ #: ajax.php:179
212
+ msgid "SKIPPED: %s (Resize not required)"
213
+ msgstr "HOPPADE ÖVER: %s (Storleksändring behövs ej)"
214
+
215
+ #: ajax.php:174
216
+ msgid "ERROR: %s (%s)"
217
+ msgstr "FEL: %s (%s)"
218
+
219
+ #: ajax.php:170
220
+ msgid "OK: %s"
221
+ msgstr "OK: %s"
222
+
223
+ #: ajax.php:98
224
+ msgid "Missing ID Parameter"
225
+ msgstr "Saknad ID-parameter"
languages/readme.txt ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ LANGUAGE TRANSLATION FILES FOR IMSANITY
2
+ ---------------------------------------
3
+
4
+ If you are interested in creating a language translation for Imsanity then
5
+ you've found the right place! Your help is greatly appreciated and allows
6
+ Imsanity to be more easily used by people all over the world.
7
+ Imsanity uses the language that is configured for WordPress in wp-config.php
8
+ and so it can support any language for which a translation has been provided.
9
+
10
+ The language files used by WordPress and Imsanity are extremely simple
11
+ to create and edit, however a plugin or software application is required to work
12
+ with the file formats. The only difficult part is actually translating the
13
+ text into the new language!
14
+
15
+ A ".po" file is a plain text file that you edit using a plugin or application.
16
+ You simply enter a tranlations for each phrase. Once all of the phrases have
17
+ been translated, you use the software to generate an ".mo" file. Save both
18
+ of these files in the imsanity/languages folder and it will be used on
19
+ all imsanity configuration pages.
20
+
21
+ HOW TO CREATE OR UPDATE TRANSLATION FILES:
22
+
23
+ The easiest way to create WordPress translations is with the Codestyling Localization
24
+ plugin at http://wordpress.org/plugins/codestyling-localization/ . After
25
+ installing the plugin, simply login as admin and go to Tools -> Localization.
26
+ Refer to the plugin documentation for instructions.
27
+
28
+ If you prefer desktop software, POEdit is a free application to view and
29
+ edit translation files: http://sourceforge.net/projects/poedit/ You can copy
30
+ and use one of the existing .po files as a starting point.
31
+
32
+ There's plenty of video tutorials that you can find by searching YouTube
33
+ for "po files"
34
+
35
+ WHAT DO I DO ONCE I'VE CREATED A TRANSLATION FILE FOR IMSANITY?
36
+
37
+ Once you have created the .po and .mo files, zip them up and upload them
38
+ to either a file sharing service, your own blog, or any public server
39
+ where I can download them.
40
+
41
+ Once the files are available, post a message on the Imsanity Support Forum at
42
+ http://wordpress.org/support/plugin/imsanity and let me know where to get
43
+ them.
44
+
45
+ Thank you for supporting Imsanity and all free software!
libs/imagecreatefrombmp.php ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * imagecreatefrombmp converts a bmp to an image resource
5
+ *
6
+ * @author http://www.programmierer-forum.de/function-imagecreatefrombmp-laeuft-mit-allen-bitraten-t143137.htm
7
+ */
8
+
9
+ if (!function_exists('imagecreatefrombmp')) {
10
+
11
+ function imagecreatefrombmp($filename) {
12
+ // version 1.00
13
+ if (!($fh = fopen($filename, 'rb'))) {
14
+ trigger_error(sprintf(__('imagecreatefrombmp: Can not open %s!','imsanity'),$filename), E_USER_WARNING);
15
+ return false;
16
+ }
17
+ // read file header
18
+ $meta = unpack('vtype/Vfilesize/Vreserved/Voffset', fread($fh, 14));
19
+ // check for bitmap
20
+ if ($meta['type'] != 19778) {
21
+ trigger_error(sprintf(__('imagecreatefrombmp: %s is not a bitmap!','imsanity'), $filename), E_USER_WARNING);
22
+ return false;
23
+ }
24
+ // read image header
25
+ $meta += unpack('Vheadersize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vcolors/Vimportant', fread($fh, 40));
26
+ // read additional 16bit header
27
+ if ($meta['bits'] == 16) {
28
+ $meta += unpack('VrMask/VgMask/VbMask', fread($fh, 12));
29
+ }
30
+ // set bytes and padding
31
+ $meta['bytes'] = $meta['bits'] / 8;
32
+ $meta['decal'] = 4 - (4 * (($meta['width'] * $meta['bytes'] / 4)- floor($meta['width'] * $meta['bytes'] / 4)));
33
+ if ($meta['decal'] == 4) {
34
+ $meta['decal'] = 0;
35
+ }
36
+ // obtain imagesize
37
+ if ($meta['imagesize'] < 1) {
38
+ $meta['imagesize'] = $meta['filesize'] - $meta['offset'];
39
+ // in rare cases filesize is equal to offset so we need to read physical size
40
+ if ($meta['imagesize'] < 1) {
41
+ $meta['imagesize'] = @filesize($filename) - $meta['offset'];
42
+ if ($meta['imagesize'] < 1) {
43
+ trigger_error(sprintf(__('imagecreatefrombmp: Can not obtain filesize of %s !','imsanity'),$filename ), E_USER_WARNING);
44
+ return false;
45
+ }
46
+ }
47
+ }
48
+ // calculate colors
49
+ $meta['colors'] = !$meta['colors'] ? pow(2, $meta['bits']) : $meta['colors'];
50
+ // read color palette
51
+ $palette = array();
52
+ if ($meta['bits'] < 16) {
53
+ $palette = unpack('l' . $meta['colors'], fread($fh, $meta['colors'] * 4));
54
+ // in rare cases the color value is signed
55
+ if ($palette[1] < 0) {
56
+ foreach ($palette as $i => $color) {
57
+ $palette[$i] = $color + 16777216;
58
+ }
59
+ }
60
+ }
61
+ // create gd image
62
+ $im = imagecreatetruecolor($meta['width'], $meta['height']);
63
+ $data = fread($fh, $meta['imagesize']);
64
+ $p = 0;
65
+ $vide = chr(0);
66
+ $y = $meta['height'] - 1;
67
+ $error = 'imagecreatefrombmp: ' . $filename . ' has not enough data!';
68
+ // loop through the image data beginning with the lower left corner
69
+ while ($y >= 0) {
70
+ $x = 0;
71
+ while ($x < $meta['width']) {
72
+ switch ($meta['bits']) {
73
+ case 32:
74
+ case 24:
75
+ if (!($part = substr($data, $p, 3))) {
76
+ trigger_error($error, E_USER_WARNING);
77
+ return $im;
78
+ }
79
+ $color = unpack('V', $part . $vide);
80
+ break;
81
+ case 16:
82
+ if (!($part = substr($data, $p, 2))) {
83
+ trigger_error($error, E_USER_WARNING);
84
+ return $im;
85
+ }
86
+ $color = unpack('v', $part);
87
+ $color[1] = (($color[1] & 0xf800) >> 8) * 65536 + (($color[1] & 0x07e0) >> 3) * 256 + (($color[1] & 0x001f) << 3);
88
+ break;
89
+ case 8:
90
+ $color = unpack('n', $vide . substr($data, $p, 1));
91
+ $color[1] = $palette[ $color[1] + 1 ];
92
+ break;
93
+ case 4:
94
+ $color = unpack('n', $vide . substr($data, floor($p), 1));
95
+ $color[1] = ($p * 2) % 2 == 0 ? $color[1] >> 4 : $color[1] & 0x0F;
96
+ $color[1] = $palette[ $color[1] + 1 ];
97
+ break;
98
+ case 1:
99
+ $color = unpack('n', $vide . substr($data, floor($p), 1));
100
+ switch (($p * 8) % 8) {
101
+ case 0:
102
+ $color[1] = $color[1] >> 7;
103
+ break;
104
+ case 1:
105
+ $color[1] = ($color[1] & 0x40) >> 6;
106
+ break;
107
+ case 2:
108
+ $color[1] = ($color[1] & 0x20) >> 5;
109
+ break;
110
+ case 3:
111
+ $color[1] = ($color[1] & 0x10) >> 4;
112
+ break;
113
+ case 4:
114
+ $color[1] = ($color[1] & 0x8) >> 3;
115
+ break;
116
+ case 5:
117
+ $color[1] = ($color[1] & 0x4) >> 2;
118
+ break;
119
+ case 6:
120
+ $color[1] = ($color[1] & 0x2) >> 1;
121
+ break;
122
+ case 7:
123
+ $color[1] = ($color[1] & 0x1);
124
+ break;
125
+ }
126
+ $color[1] = $palette[ $color[1] + 1 ];
127
+ break;
128
+ default:
129
+ trigger_error( sprintf(__('imagecreatefrombmp: %s has %d bits and this is not supported!','imsanity'),$filename,$meta['bits']), E_USER_WARNING);
130
+ return false;
131
+ }
132
+ imagesetpixel($im, $x, $y, $color[1]);
133
+ $x++;
134
+ $p += $meta['bytes'];
135
+ }
136
+ $y--;
137
+ $p += $meta['decal'];
138
+ }
139
+ fclose($fh);
140
+ return $im;
141
+ }
142
+ }
143
+
144
+ ?>
libs/utils.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ################################################################################
4
+ * UTILITIES
5
+ * ################################################################################
6
+ */
7
+
8
+ /**
9
+ * Util function returns an array value, if not defined then returns default instead.
10
+ * @param Array $array
11
+ * @param string $key
12
+ * @param variant $default
13
+ */
14
+ function imsanity_val( $arr, $key, $default='' ) {
15
+ return isset( $arr[$key] ) ? $arr[ $key ] : $default;
16
+ }
17
+
18
+ /**
19
+ * output a fatal error and optionally die
20
+ *
21
+ * @param string $message
22
+ * @param string $title
23
+ * @param bool $die
24
+ */
25
+ function imsanity_fatal( $message, $title = "", $die = false ) {
26
+ echo ( "<div style='margin:5px 0px 5px 0px;padding:10px;border: solid 1px red; background-color: #ff6666; color: black;'>"
27
+ . ( $title ? "<h4 style='font-weight: bold; margin: 3px 0px 8px 0px;'>" . $title . "</h4>" : "" )
28
+ . $message
29
+ . "</div>" );
30
+
31
+ if ( $die ) die();
32
+ }
33
+
34
+ /**
35
+ * Replacement for deprecated image_resize function
36
+ * @param string $file Image file path.
37
+ * @param int $max_w Maximum width to resize to.
38
+ * @param int $max_h Maximum height to resize to.
39
+ * @param bool $crop Optional. Whether to crop image or resize.
40
+ * @param string $suffix Optional. File suffix.
41
+ * @param string $dest_path Optional. New image file path.
42
+ * @param int $jpeg_quality Optional, default is 90. Image quality percentage.
43
+ * @return mixed WP_Error on failure. String with new destination path.
44
+ */
45
+ function imsanity_image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 82 ) {
46
+
47
+ if ( function_exists( 'wp_get_image_editor' ) ) {
48
+ // TODO: check to make sure file is writable
49
+ // WP 3.5 and up use the image editor
50
+
51
+ $editor = wp_get_image_editor( $file );
52
+ if ( is_wp_error( $editor ) )
53
+ return $editor;
54
+ $editor->set_quality( $jpeg_quality );
55
+
56
+ $ftype = pathinfo( $file, PATHINFO_EXTENSION );
57
+
58
+ // try to correct for auto-rotation if the info is available
59
+ if (function_exists('exif_read_data') && ($ftype == 'jpg' || $ftype == 'jpeg') ) {
60
+ $exif = @exif_read_data($file);
61
+ $orientation = is_array($exif) && array_key_exists('Orientation', $exif) ? $exif['Orientation'] : 0;
62
+ switch($orientation) {
63
+ case 3:
64
+ $editor->rotate(180);
65
+ break;
66
+ case 6:
67
+ $editor->rotate(-90);
68
+ break;
69
+ case 8:
70
+ $editor->rotate(90);
71
+ break;
72
+ }
73
+ }
74
+
75
+ $resized = $editor->resize( $max_w, $max_h, $crop );
76
+ if ( is_wp_error( $resized ) )
77
+ return $resized;
78
+
79
+ $dest_file = $editor->generate_filename( $suffix, $dest_path );
80
+
81
+ // FIX: make sure that the destination file does not exist. this fixes
82
+ // an issue during bulk resize where one of the optimized media filenames may get
83
+ // used as the temporary file, which causes it to be deleted.
84
+ while (file_exists($dest_file)) {
85
+ $dest_file = $editor->generate_filename('TMP', $dest_path );
86
+ }
87
+
88
+ $saved = $editor->save( $dest_file );
89
+
90
+ if ( is_wp_error( $saved ) )
91
+ return $saved;
92
+
93
+ return $dest_file;
94
+ }
95
+ else
96
+ {
97
+ // TODO: remove this, but handle failure properly upstream
98
+ // wordpress prior to 3.5 uses the old image_resize function
99
+ return image_resize( $file, $max_w, $max_h, $crop, $suffix, $dest_path, $jpeg_quality);
100
+ }
101
+ }
102
+
103
+ ?>
readme.txt ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+ Contributors: nosilver4u,verysimple
3
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MKMQKCBFFG3WW
4
+ Tags: image, scale, resize, space saver, quality
5
+ Requires at least: 3.9
6
+ Tested up to: 4.7
7
+ Stable tag: 2.3.7
8
+
9
+ Imsanity automatically resizes huge image uploads. Are contributors uploading huge photos? Tired of manually scaling? Imsanity to the rescue!
10
+
11
+ == Description ==
12
+
13
+ Imsanity automatically resizes huge image uploads down to a size that is
14
+ more reasonable for display in browser, yet still more than large enough for typical website use.
15
+ The plugin is configurable with a max width, height and quality. When a contributor uploads an
16
+ image that is larger than the configured size, Imsanity will automatically scale it down to the
17
+ configured size and replace the original image.
18
+
19
+ Imsanity also provides a bulk-resize feature to selectively resize previously uploaded images
20
+ to free up disk space.
21
+
22
+ This plugin is ideal for blogs that do not require hi-resolution original images
23
+ to be stored and/or the contributors don't want (or understand how) to scale images
24
+ before uploading.
25
+
26
+ = Features =
27
+
28
+ * Automatically scales large image uploads to a more "sane" size
29
+ * Bulk-resize feature to selectively resize existing images
30
+ * Allows configuration of max width/height and jpg quality
31
+ * Optionally converts BMP files to JPG so image can be scaled
32
+ * Once enabled, Imsanity requires no actions on the part of the user
33
+ * Uses WordPress built-in image scaling functions
34
+
35
+ = Translations =
36
+
37
+ Imsanity is available in several languages, each of which will be downloaded automatically when you install the plugin. To help translate it into your language, visit https://translate.wordpress.org/projects/wp-plugins/imsanity
38
+
39
+ == Installation ==
40
+
41
+ Automatic Installation:
42
+
43
+ 1. Go to Admin - Plugins - Add New and search for "imsanity"
44
+ 2. Click the Install Button
45
+ 3. Click 'Activate'
46
+
47
+ Manual Installation:
48
+
49
+ 1. Download imsanity.zip
50
+ 2. Unzip and upload the 'imsanity' folder to your '/wp-content/plugins/' directory
51
+ 3. Activate the plugin through the 'Plugins' menu in WordPress
52
+
53
+ == Screenshots ==
54
+
55
+ 1. Imsanity settings page to configure max height/width
56
+ 2. Imsanity bulk image resize feature
57
+
58
+ == Frequently Asked Questions ==
59
+
60
+ = What is Imsanity? =
61
+
62
+ Imsanity is a plugin that automatically resizes uploaded images that are larger than the configured max width/height
63
+
64
+ = 1. Will installing the Imsanity plugin alter existing images in my blog? =
65
+
66
+ Activating Imsanity will not alter any existing images. Imsanity resizes images as they are uploaded so
67
+ it does not affect existing images unless you specifically use the "Bulk Image Resize" feature on
68
+ the Imsanity settings page. The "Bulk Image Resize" feature allows you to selectively resize existing images.
69
+
70
+ = 2. Why aren't all of my images detected when I try to use the bulk resize feature? =
71
+
72
+ Imsanity doesn't search your file system to find large files, instead it looks at the "metadata"
73
+ in the WordPress media library database. When you upload files, WordPress stores all of the information
74
+ about the image.
75
+
76
+ = 3. Why am I getting an error saying that my "File is not an image" ? =
77
+
78
+ WordPress uses the GD library to handle the image manipulation. GD can be installed and configured to support
79
+ various types of images. If GD is not configured to handle a particular image type then you will get
80
+ this message when you try to upload it. For more info see http://php.net/manual/en/image.installation.php
81
+
82
+ = 4. How can I tell Imsanity to ignore a certain image so I can upload it without being resized? =
83
+
84
+ You can re-name your file and add "-noresize" to the filename. For example if your file is named
85
+ "photo.jpg" you can rename it "photo-noresize.jpg" and Imsanity will ignore it, allowing you
86
+ to upload the full-sized image.
87
+
88
+ Optionally you can temporarily adjust the max image size settings and set them to a number that is
89
+ higher than the resolution of the image you wish to upload
90
+
91
+ = 5. Why would I need this plugin? =
92
+
93
+ Photos taken on any modern camera and even most cellphones are too large for display full-size in a browser.
94
+ In the case of modern DSLR cameras, the image sizes are intended for high-quality printing and are ridiculously
95
+ over-sized for display on a web page.
96
+
97
+ Imsanity allows you to set a sanity limit so that all uploaded images will be constrained
98
+ to a reasonable size which is still more than large enough for the needs of a typical website.
99
+ Imsanity hooks into WordPress immediately after the image upload, but before WordPress processing
100
+ occurs. So WordPress behaves exactly the same in all ways, except it will be as if the contributor
101
+ had scaled their image to a reasonable size before uploading.
102
+
103
+ The size limit that imsanity uses is configurable. The default value is large enough to fill
104
+ the average vistors entire screen without scaling so it is still more than large enough for
105
+ typical usage.
106
+
107
+ = 6. Why would I NOT want to use this plugin? =
108
+
109
+ You might not want to use Imsanity if you use WordPress as a stock art download
110
+ site, provide high-res images for print or use WordPress as a high-res photo
111
+ storage archive. If you are doing any of these things then most likely
112
+ you already have a good understanding of image resolution.
113
+
114
+ = 7. Doesn't WordPress already automatically scale images? =
115
+
116
+ When an image is uploaded WordPress keeps the original and, depending on the size of the original,
117
+ will create up to 4 smaller sized copies of the file (Large, Medium-Large, Medium, Thumbnail) which are intended
118
+ for embedding on your pages. Unless you have special photographic needs, the original usually sits
119
+ there unused, but taking up disk quota.
120
+
121
+ = 8. Why did you spell Insanity wrong? =
122
+
123
+ Imsanity is short for "Image Sanity Limit". A sanity limit is a term for limiting something down to
124
+ a size or value that is reasonable.
125
+
126
+ = 9. Where do I go for support? =
127
+
128
+ Questions may be posted on the support forum at https://wordpress.org/support/plugin/imsanity although I may move support to the helpscout platform we use for EWWW I.O.
129
+
130
+ = TODO =
131
+
132
+ * Add a network settings to override the individual plugin settings text
133
+
134
+ == Upgrade Notice ==
135
+
136
+ = 2.3.6 =
137
+ * tested up to WP 4.4
138
+ * if resized image is not smaller than original, then keep original
139
+ * allow IMSANITY_AJAX_MAX_RECORDS to be overridden in wp-config.php
140
+ * if png-to-jpg is enabled, replace png transparency with white
141
+
142
+ == Changelog ==
143
+
144
+ As some already know, Jason Hinkle passed away earlier this year. He will be sorely missed, but I hope to continue his legacy, to improve and support Imsanity. Who am I? https://ewww.io
145
+
146
+ = 2.3.7 =
147
+ * fixed: uploads to Media Library not detected properly
148
+ * changed: default JPG quality is now 82, to match the WordPress default
149
+ * changed: fr_FR and ru_RU moved to WP.org language packs
150
+ * changed: new maintainer
151
+
152
+ = 2.3.6 =
153
+ * tested up to WP 4.4
154
+ * if resized image is not smaller than original, then keep original
155
+ * allow IMSANITY_AJAX_MAX_RECORDS to be overridden in wp-config.php
156
+ * if png-to-jpg is enabled, replace png transparency with white
157
+
158
+ = 2.3.5 =
159
+ * Add option to hide Imsanity girl logo image on settings screen
160
+
161
+ = 2.3.4 =
162
+ * Security update to network settings page
163
+
164
+ = 2.3.3 =
165
+ * Update default size from 1024 to 2048
166
+ * Tested up to WordPress 4.1.1
167
+ * Move screenshots to /assets folder
168
+ * Added 256x256 icon
169
+
170
+ = 2.3.2 =
171
+ * Add PNG-To-JPG Option thanks to Jody Nesbitt
172
+
173
+ = 2.3.1 =
174
+ * ignore errors if EXIF data is not readable
175
+ * show counter when bulk resizing images
176
+
177
+ = 2.3.0 =
178
+ * fix for incorrectly identifying media uploads as coming from 'other' on WP 4+
scripts/imsanity.js ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * imsanity admin javascript functions
3
+ */
4
+
5
+ // this must run inline so that the script is detected correctly
6
+ var imsanity_scripts = document.getElementsByTagName("script");
7
+ var imsanity_script_url = imsanity_scripts[imsanity_scripts.length-1].src;
8
+
9
+ /**
10
+ * Begin the process of re-sizing all of the checked images
11
+ */
12
+ function imsanity_resize_images()
13
+ {
14
+ var images = [];
15
+ jQuery('.imsanity_image_cb:checked').each(function(i) {
16
+ images.push(this.value);
17
+ });
18
+
19
+ var target = jQuery('#resize_results');
20
+ target.html('');
21
+ target.show();
22
+ jQuery(document).scrollTop(target.offset().top);
23
+
24
+ // start the recursion
25
+ imsanity_resize_next(images,0);
26
+ }
27
+
28
+ /**
29
+ * Detect the base url for the imsanity plugin folder
30
+ * @returns
31
+ */
32
+ function imsanity_get_base_url()
33
+ {
34
+ return imsanity_script_url.substring(0,imsanity_script_url.indexOf('scripts/imsanity.js'));
35
+ }
36
+
37
+
38
+ /**
39
+ * recursive function for resizing images
40
+ */
41
+ function imsanity_resize_next(images,next_index)
42
+ {
43
+ if (next_index >= images.length) return imsanity_resize_complete();
44
+
45
+ jQuery.post(
46
+ ajaxurl, // (defined by wordpress - points to admin-ajax.php)
47
+ {action: 'imsanity_resize_image', id: images[next_index]},
48
+ function(response)
49
+ {
50
+ var result;
51
+ var target = jQuery('#resize_results');
52
+
53
+ try {
54
+ result = JSON.parse(response);
55
+ target.append('<div>' + (next_index+1) + ' of ' + images.length + ' &gt;&gt; ' + result['message'] +'</div>');
56
+ }
57
+ catch(e) {
58
+ target.append('<div>Error parsing server response for POST ' + images[next_index] + ': '+ e.message +'. Check the console for details.</div>');
59
+ if (console) console.warn('Invalid JSON Response: ' + response);
60
+ }
61
+
62
+ target.animate({scrollTop: target.height()}, 500);
63
+
64
+ // recurse
65
+ imsanity_resize_next(images,next_index+1);
66
+ }
67
+ );
68
+ }
69
+
70
+ /**
71
+ * fired when all images have been resized
72
+ */
73
+ function imsanity_resize_complete()
74
+ {
75
+ var target = jQuery('#resize_results');
76
+ target.append('<div>RESIZE COMPLETE</div>');
77
+ target.animate({scrollTop: target.height()}, 500);
78
+ }
79
+
80
+ /**
81
+ * ajax post to return all images that are candidates for resizing
82
+ * @param string the id of the html element into which results will be appended
83
+ */
84
+ function imsanity_load_images(container_id)
85
+ {
86
+ var container = jQuery('#'+container_id);
87
+ container.html('<div id="imsanity_target" style="border: solid 2px #666666; padding: 10px; height: 0px; overflow: auto;" />');
88
+
89
+ var target = jQuery('#imsanity_target');
90
+
91
+ target.html('<div><image src="'+ imsanity_get_base_url() +'images/ajax-loader.gif" style="margin-bottom: .25em; vertical-align:middle;" /> Examining existing attachments. This may take a few moments...</div>');
92
+
93
+ target.animate({height: [250,'swing']},500, function()
94
+ {
95
+ jQuery(document).scrollTop(container.offset().top);
96
+
97
+ jQuery.post(
98
+ ajaxurl, // (global defined by wordpress - points to admin-ajax.php)
99
+ {action: 'imsanity_get_images'},
100
+ function(response)
101
+ {
102
+ var images = JSON.parse(response);
103
+
104
+ if (images.length > 0)
105
+ {
106
+ target.html('<div><input id="imsanity_check_all" type="checkbox" checked="checked" onclick="jQuery(\'.imsanity_image_cb\').attr(\'checked\', this.checked);" /> Select All</div>');
107
+
108
+ for (var i = 0; i < images.length; i++)
109
+ {
110
+ target.append('<div><input class="imsanity_image_cb" name="imsanity_images" value="' + images[i].id + '" type="checkbox" checked="checked" /> POST ' + images[i].id + ': ' + images[i].file +' ('+images[i].width+' x '+images[i].height+')</div>');
111
+ }
112
+
113
+ container.append('<p class="submit"><button class="button-primary" onclick="imsanity_resize_images();">Resize Checked Images...</button></p>');
114
+ container.append('<div id="resize_results" style="display: none; border: solid 2px #666666; padding: 10px; height: 250px; overflow: auto;" />');
115
+ }
116
+ else
117
+ {
118
+ target.html('<div>There are no existing attachments that require resizing. Blam!</div>');
119
+
120
+ }
121
+ }
122
+ );
123
+ });
124
+ }
settings.php ADDED
@@ -0,0 +1,635 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ################################################################################
4
+ * IMSANITY ADMIN/SETTINGS UI
5
+ * ################################################################################
6
+ */
7
+
8
+ // register the plugin settings menu
9
+ add_action('admin_menu', 'imsanity_create_menu');
10
+ add_action( 'network_admin_menu', 'imsanity_register_network' );
11
+ add_filter("plugin_action_links_imsanity/imsanity.php", 'imsanity_settings_link' );
12
+
13
+ // activation hooks
14
+ // TODO: custom table is not removed because de-activating one site shouldn't affect the entire server
15
+ register_activation_hook('imsanity/imsanity.php', 'imsanity_maybe_created_custom_table' );
16
+ // add_action('plugins_loaded', 'imsanity_maybe_created_custom_table');
17
+ // register_deactivation_hook('imsanity/imsanity.php', ...);
18
+ // register_uninstall_hook('imsanity/imsanity.php', 'imsanity_maybe_remove_custom_table');
19
+
20
+ // settings cache
21
+ $_imsanity_multisite_settings = null;
22
+
23
+ /**
24
+ * Settings link that appears on the plugins overview page
25
+ * @param array $links
26
+ * @return array
27
+ */
28
+ function imsanity_settings_link( $links ) {
29
+ $links[] = '<a href="'. get_admin_url(null, 'options-general.php?page='.__FILE__) .'">Settings</a>';
30
+ return $links;
31
+ }
32
+
33
+ /**
34
+ * Create the settings menu item in the WordPress admin navigation and
35
+ * link it to the plugin settings page
36
+ */
37
+ function imsanity_create_menu()
38
+ {
39
+ // create new menu for site configuration
40
+ add_options_page(__('Imsanity Plugin Settings','imsanity'), 'Imsanity', 'administrator', __FILE__, 'imsanity_settings_page');
41
+
42
+ // call register settings function
43
+ add_action( 'admin_init', 'imsanity_register_settings' );
44
+ }
45
+
46
+ // TODO: legacy code to support previous MU version... ???
47
+ // if ( dm_site_admin() && version_compare( $wp_version, '3.0.9', '<=' ) ) {
48
+ // if ( version_compare( $wp_version, '3.0.1', '<=' ) ) {
49
+ // add_submenu_page('wpmu-admin.php', __( 'Domain Mapping', 'wordpress-mu-domain-mapping' ), __( 'Domain Mapping', 'wordpress-mu-domain-mapping'), 'manage_options', 'dm_admin_page', 'dm_admin_page');
50
+ // add_submenu_page('wpmu-admin.php', __( 'Domains', 'wordpress-mu-domain-mapping' ), __( 'Domains', 'wordpress-mu-domain-mapping'), 'manage_options', 'dm_domains_admin', 'dm_domains_admin');
51
+ // } else {
52
+ // add_submenu_page('ms-admin.php', __( 'Domain Mapping', 'wordpress-mu-domain-mapping' ), 'Domain Mapping', 'manage_options', 'dm_admin_page', 'dm_admin_page');
53
+ // add_submenu_page('ms-admin.php', __( 'Domains', 'wordpress-mu-domain-mapping' ), 'Domains', 'manage_options', 'dm_domains_admin', 'dm_domains_admin');
54
+ // }
55
+ // }
56
+ // add_action( 'admin_menu', 'dm_add_pages' );
57
+
58
+ // TODO: put network options where they belong, not in a custom table
59
+ /**
60
+ * Returns the name of the custom multi-site settings table.
61
+ * this will be the same table regardless of the blog
62
+ */
63
+ function imsanity_get_custom_table_name()
64
+ {
65
+ global $wpdb;
66
+
67
+ // passing in zero seems to return $wpdb->base_prefix, which is not public
68
+ return $wpdb->get_blog_prefix(0) . "imsanity";
69
+ }
70
+
71
+ /**
72
+ * Return true if the multi-site settings table exists
73
+ * @return bool
74
+ */
75
+ function imsanity_multisite_table_exists()
76
+ {
77
+ global $wpdb;
78
+ $table_name = imsanity_get_custom_table_name();
79
+ return $wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") == $table_name;
80
+ }
81
+
82
+ /**
83
+ * Return true if the multi-site settings table exists
84
+ * @return bool
85
+ */
86
+ function imsanity_multisite_table_schema_version()
87
+ {
88
+ // if the table doesn't exist then there is no schema to report
89
+ if (!imsanity_multisite_table_exists()) return '0';
90
+
91
+ global $wpdb;
92
+ $version = $wpdb->get_var('select data from ' . imsanity_get_custom_table_name() . " where setting = 'schema'");
93
+
94
+ if (!$version) $version = '1.0'; // this is a legacy version 1.0 installation
95
+
96
+ return $version;
97
+
98
+ }
99
+
100
+ /**
101
+ * Returns the default network settings in the case where they are not
102
+ * defined in the database, or multi-site is not enabled
103
+ * @return stdClass
104
+ */
105
+ function imsanity_get_default_multisite_settings()
106
+ {
107
+ $data = new stdClass();
108
+ $data->imsanity_override_site = false;
109
+ $data->imsanity_max_height = IMSANITY_DEFAULT_MAX_HEIGHT;
110
+ $data->imsanity_max_width = IMSANITY_DEFAULT_MAX_WIDTH;
111
+ $data->imsanity_max_height_library = IMSANITY_DEFAULT_MAX_HEIGHT;
112
+ $data->imsanity_max_width_library = IMSANITY_DEFAULT_MAX_WIDTH;
113
+ $data->imsanity_max_height_other = IMSANITY_DEFAULT_MAX_HEIGHT;
114
+ $data->imsanity_max_width_other = IMSANITY_DEFAULT_MAX_WIDTH;
115
+ $data->imsanity_bmp_to_jpg = IMSANITY_DEFAULT_BMP_TO_JPG;
116
+ $data->imsanity_png_to_jpg = IMSANITY_DEFAULT_PNG_TO_JPG;
117
+ $data->imsanity_quality = IMSANITY_DEFAULT_QUALITY;
118
+ return $data;
119
+ }
120
+
121
+
122
+ /**
123
+ * On activation create the multisite database table if necessary. this is
124
+ * called when the plugin is activated as well as when it is automatically
125
+ * updated.
126
+ *
127
+ * @param bool set to true to force the query to run in the case of an upgrade
128
+ */
129
+ function imsanity_maybe_created_custom_table()
130
+ {
131
+ // if not a multi-site no need to do any custom table lookups
132
+ if ( (!function_exists("is_multisite")) || (!is_multisite()) ) return;
133
+
134
+ global $wpdb;
135
+
136
+ $schema = imsanity_multisite_table_schema_version();
137
+ $table_name = imsanity_get_custom_table_name();
138
+
139
+ if ($schema == '0')
140
+ {
141
+ // this is an initial database setup
142
+ $sql = "CREATE TABLE IF NOT EXISTS " . $table_name . " (
143
+ setting varchar(55),
144
+ data text NOT NULL,
145
+ PRIMARY KEY (setting)
146
+ );";
147
+
148
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
149
+ dbDelta($sql);
150
+ $data = imsanity_get_default_multisite_settings();
151
+
152
+ // add the rows to the database
153
+ $data = imsanity_get_default_multisite_settings();
154
+ $wpdb->insert( $table_name, array( 'setting' => 'multisite', 'data' => maybe_serialize($data) ) );
155
+ $wpdb->insert( $table_name, array( 'setting' => 'schema', 'data' => IMSANITY_SCHEMA_VERSION ) );
156
+ }
157
+
158
+ if ($schema != IMSANITY_SCHEMA_VERSION)
159
+ {
160
+ // this is a schema update. for the moment there is only one schema update available, from 1.0 to 1.1
161
+ if ($schema == '1.0')
162
+ {
163
+ // update from version 1.0 to 1.1
164
+ $wpdb->insert( $table_name, array( 'setting' => 'schema', 'data' => IMSANITY_SCHEMA_VERSION ) );
165
+ $update1 = "ALTER TABLE " . $table_name . " CHANGE COLUMN data data TEXT NOT NULL;";
166
+ $wpdb->query($update1);
167
+ }
168
+ else
169
+ {
170
+ // @todo we don't have this yet
171
+ $wpdb->update(
172
+ $table_name,
173
+ array('data' => IMSANITY_SCHEMA_VERSION),
174
+ array('setting' => 'schema')
175
+ );
176
+ }
177
+
178
+ }
179
+
180
+
181
+ }
182
+
183
+ /**
184
+ * Register the network settings page
185
+ */
186
+ function imsanity_register_network()
187
+ {
188
+ add_submenu_page('settings.php', __('Imsanity Network Settings','imsanity'), 'Imsanity', 'manage_options', 'imsanity_network', 'imsanity_network_settings');
189
+ }
190
+
191
+ /**
192
+ * display the form for the multi-site settings page
193
+ */
194
+ function imsanity_network_settings()
195
+ {
196
+ imsanity_settings_css();
197
+
198
+ echo '
199
+ <div class="wrap">
200
+ <div id="icon-options-general" class="icon32"><br></div>
201
+ <h2>'.__('Imsanity Network Settings','imsanity').'</h2>
202
+ ';
203
+
204
+ // we only want to update if the form has been submitted
205
+ if (isset($_POST['update_settings']))
206
+ {
207
+ imsanity_network_settings_update();
208
+ echo "<div class='updated settings-error'><p><strong>".__("Imsanity network settings saved.",'imsanity')."</strong></p></div>";
209
+ }
210
+
211
+ imsanity_settings_banner();
212
+
213
+ $settings = imsanity_get_multisite_settings();
214
+
215
+ ?>
216
+
217
+ <form method="post" action="settings.php?page=imsanity_network">
218
+ <input type="hidden" name="update_settings" value="1" />
219
+
220
+ <table class="form-table">
221
+ <tr valign="top">
222
+ <th scope="row"><?php _e("Global Settings Override",'imsanity'); ?></th>
223
+ <td>
224
+ <select name="imsanity_override_site">
225
+ <option value="0" <?php if ($settings->imsanity_override_site == '0') echo "selected='selected'" ?> ><?php _e("Allow each site to configure Imsanity settings",'imsanity'); ?></option>
226
+ <option value="1" <?php if ($settings->imsanity_override_site == '1') echo "selected='selected'" ?> ><?php _e("Use global Imsanity settings (below) for all sites",'imsanity'); ?></option>
227
+ </select>
228
+ </td>
229
+ </tr>
230
+
231
+ <tr valign="top">
232
+ <th scope="row"><?php _e("Images uploaded within a Page/Post",'imsanity');?></th>
233
+ <td>
234
+ Fit within <input name="imsanity_max_width" value="<?php echo $settings->imsanity_max_width ?>" style="width: 50px;" />
235
+ x <input name="imsanity_max_height" value="<?php echo $settings->imsanity_max_height ?>" style="width: 50px;" /> pixels width/height <?php _e(" (or enter 0 to disable)",'imsanity'); ?>
236
+ </td>
237
+ </tr>
238
+
239
+ <tr valign="top">
240
+ <th scope="row"><?php _e("Images uploaded directly to the Media Library",'imsanity'); ?></th>
241
+ <td>
242
+ Fit within <input name="imsanity_max_width_library" value="<?php echo $settings->imsanity_max_width_library ?>" style="width: 50px;" />
243
+ x <input name="imsanity_max_height_library" value="<?php echo $settings->imsanity_max_height_library ?>" style="width: 50px;" /> pixels width/height <?php _e(" (or enter 0 to disable)",'imsanity'); ?>
244
+ </td>
245
+ </tr>
246
+
247
+ <tr valign="top">
248
+ <th scope="row"><?php _e("Images uploaded elsewhere (Theme headers, backgrounds, logos, etc)",'imsanity'); ?></th>
249
+ <td>
250
+ Fit within <input name="imsanity_max_width_other" value="<?php echo $settings->imsanity_max_width_other ?>" style="width: 50px;" />
251
+ x <input name="imsanity_max_height_other" value="<?php echo $settings->imsanity_max_height_other ?>" style="width: 50px;" /> pixels width/height <?php _e(" (or enter 0 to disable)",'imsanity'); ?>
252
+ </td>
253
+ </tr>
254
+
255
+ <tr valign="top">
256
+ <th scope="row"><?php _e("Convert BMP to JPG",'imsanity'); ?></th>
257
+ <td><select name="imsanity_bmp_to_jpg">
258
+ <option value="1" <?php if ($settings->imsanity_bmp_to_jpg == '1') echo "selected='selected'" ?> ><?php _e("Yes",'imsanity'); ?></option>
259
+ <option value="0" <?php if ($settings->imsanity_bmp_to_jpg == '0') echo "selected='selected'" ?> ><?php _e("No",'imsanity'); ?></option>
260
+ </select></td>
261
+ </tr>
262
+
263
+ <tr valign="top">
264
+ <th scope="row"><?php _e("Convert PNG to JPG",'imsanity'); ?></th>
265
+ <td><select name="imsanity_png_to_jpg">
266
+ <option value="1" <?php if ($settings->imsanity_png_to_jpg == '1') echo "selected='selected'" ?> ><?php _e("Yes",'imsanity'); ?></option>
267
+ <option value="0" <?php if ($settings->imsanity_png_to_jpg == '0') echo "selected='selected'" ?> ><?php _e("No",'imsanity'); ?></option>
268
+ </select></td>
269
+ </tr>
270
+
271
+ <tr>
272
+ <th><label for='imsanity_quality' ><?php esc_html_e( "JPG image quality", 'imsanity' ); ?></th>
273
+ <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' ); ?>
274
+ <p class='description'><?php esc_html_e( 'WordPress default is 82','imsanity' ); ?></p></td>
275
+ </tr>
276
+
277
+ </table>
278
+
279
+ <p class="submit"><input type="submit" class="button-primary" value="<?php esc_attr_e( 'Update Settings', 'imsanity' ); ?>" /></p>
280
+
281
+ </form>
282
+ <?php
283
+
284
+ echo '</div>';
285
+ }
286
+
287
+ /**
288
+ * Process the form, update the network settings
289
+ * and clear the cached settings
290
+ */
291
+ function imsanity_network_settings_update()
292
+ {
293
+ global $wpdb;
294
+ global $_imsanity_multisite_settings;
295
+
296
+ // ensure that the custom table is created when the user updates network settings
297
+ // this is not ideal but it's better than checking for this table existance
298
+ // on every page load
299
+ imsanity_maybe_created_custom_table();
300
+
301
+ $table_name = imsanity_get_custom_table_name();
302
+
303
+ $data = new stdClass();
304
+ $data->imsanity_override_site = $_POST['imsanity_override_site'] == 1;
305
+ $data->imsanity_max_height = sanitize_text_field($_POST['imsanity_max_height']);
306
+ $data->imsanity_max_width = sanitize_text_field($_POST['imsanity_max_width']);
307
+ $data->imsanity_max_height_library = sanitize_text_field($_POST['imsanity_max_height_library']);
308
+ $data->imsanity_max_width_library = sanitize_text_field($_POST['imsanity_max_width_library']);
309
+ $data->imsanity_max_height_other = sanitize_text_field($_POST['imsanity_max_height_other']);
310
+ $data->imsanity_max_width_other = sanitize_text_field($_POST['imsanity_max_width_other']);
311
+ $data->imsanity_bmp_to_jpg = $_POST['imsanity_bmp_to_jpg'] == 1;
312
+ $data->imsanity_png_to_jpg = $_POST['imsanity_png_to_jpg'] == 1;
313
+ $data->imsanity_quality = imsanity_jpg_quality($_POST['imsanity_quality']);
314
+
315
+ $wpdb->update(
316
+ $table_name,
317
+ array('data' => maybe_serialize($data)),
318
+ array('setting' => 'multisite')
319
+ );
320
+
321
+ // clear the cache
322
+ $_imsanity_multisite_settings = null;
323
+ }
324
+
325
+ /**
326
+ * Return the multi-site settings as a standard class. If the settings are not
327
+ * defined in the database or multi-site is not enabled then the default settings
328
+ * are returned. This is cached so it only loads once per page load, unless
329
+ * imsanity_network_settings_update is called.
330
+ * @return stdClass
331
+ */
332
+ function imsanity_get_multisite_settings()
333
+ {
334
+ global $_imsanity_multisite_settings;
335
+ $result = null;
336
+
337
+ if (!$_imsanity_multisite_settings)
338
+ {
339
+ if (function_exists("is_multisite") && is_multisite())
340
+ {
341
+ global $wpdb;
342
+
343
+ $result = $wpdb->get_var('select data from ' . imsanity_get_custom_table_name() . " where setting = 'multisite'");
344
+ }
345
+
346
+ // if there's no results, return the defaults instead
347
+ $_imsanity_multisite_settings = $result
348
+ ? unserialize($result)
349
+ : imsanity_get_default_multisite_settings();
350
+
351
+ // this is for backwards compatibility
352
+ if ($_imsanity_multisite_settings->imsanity_max_height_library == '')
353
+ {
354
+ $_imsanity_multisite_settings->imsanity_max_height_library = $_imsanity_multisite_settings->imsanity_max_height;
355
+ $_imsanity_multisite_settings->imsanity_max_width_library = $_imsanity_multisite_settings->imsanity_max_width;
356
+ $_imsanity_multisite_settings->imsanity_max_height_other = $_imsanity_multisite_settings->imsanity_max_height;
357
+ $_imsanity_multisite_settings->imsanity_max_width_other = $_imsanity_multisite_settings->imsanity_max_width;
358
+ }
359
+
360
+ }
361
+
362
+ return $_imsanity_multisite_settings;
363
+ }
364
+
365
+ /**
366
+ * Gets the option setting for the given key, first checking to see if it has been
367
+ * set globally for multi-site. Otherwise checking the site options.
368
+ * @param string $key
369
+ * @param string $ifnull value to use if the requested option returns null
370
+ */
371
+ function imsanity_get_option($key,$ifnull)
372
+ {
373
+ $result = null;
374
+
375
+ $settings = imsanity_get_multisite_settings();
376
+
377
+ if ($settings->imsanity_override_site)
378
+ {
379
+ $result = $settings->$key;
380
+ if ($result == null) $result = $ifnull;
381
+ }
382
+ else
383
+ {
384
+ $result = get_option($key,$ifnull);
385
+ }
386
+
387
+ return $result;
388
+
389
+ }
390
+
391
+ /**
392
+ * Register the configuration settings that the plugin will use
393
+ */
394
+ function imsanity_register_settings()
395
+ {
396
+ //register our settings
397
+ register_setting( 'imsanity-settings-group', 'imsanity_max_height' );
398
+ register_setting( 'imsanity-settings-group', 'imsanity_max_width' );
399
+ register_setting( 'imsanity-settings-group', 'imsanity_max_height_library' );
400
+ register_setting( 'imsanity-settings-group', 'imsanity_max_width_library' );
401
+ register_setting( 'imsanity-settings-group', 'imsanity_max_height_other' );
402
+ register_setting( 'imsanity-settings-group', 'imsanity_max_width_other' );
403
+ register_setting( 'imsanity-settings-group', 'imsanity_bmp_to_jpg' );
404
+ register_setting( 'imsanity-settings-group', 'imsanity_png_to_jpg' );
405
+ register_setting( 'imsanity-settings-group', 'imsanity_quality', 'imsanity_jpg_quality' );
406
+ }
407
+
408
+ /**
409
+ * Validate and return the JPG quality setting
410
+ */
411
+ function imsanity_jpg_quality( $quality = null ) {
412
+ if ( $quality === null ) {
413
+ $quality = get_option( 'imsanity_quality' );
414
+ }
415
+ if ( preg_match( '/^(100|[1-9][0-9]?)$/', $quality ) ) {
416
+ return (int) $quality;
417
+ } else {
418
+ return IMSANITY_DEFAULT_QUALITY;
419
+ }
420
+ }
421
+
422
+ /**
423
+ * Helper function to render css styles for the settings forms
424
+ * for both site and network settings page
425
+ */
426
+ function imsanity_settings_css()
427
+ {
428
+ echo "
429
+ <style>
430
+ #imsanity_header
431
+ {
432
+ border: solid 1px #c6c6c6;
433
+ margin: 12px 2px 8px 2px;
434
+ padding: 20px;
435
+ background-color: #e1e1e1;
436
+ }
437
+ #imsanity_header h4
438
+ {
439
+ margin: 0px 0px 0px 0px;
440
+ }
441
+ #imsanity_header tr
442
+ {
443
+ vertical-align: top;
444
+ }
445
+
446
+ .imsanity_section_header
447
+ {
448
+ border: solid 1px #c6c6c6;
449
+ margin: 12px 2px 8px 2px;
450
+ padding: 20px;
451
+ background-color: #e1e1e1;
452
+ }
453
+
454
+ </style>";
455
+ }
456
+
457
+ /**
458
+ * Helper function to render the settings banner
459
+ * for both site and network settings page
460
+ */
461
+ function imsanity_settings_banner()
462
+ {
463
+ // TODO: put this where it belongs, and merge the calls
464
+ // register the scripts that are used by the bulk resizer
465
+ wp_register_script( 'my_plugin_script', plugins_url('/imsanity/scripts/imsanity.js?v='.IMSANITY_VERSION), array('jquery'));
466
+ wp_enqueue_script( 'my_plugin_script' );
467
+
468
+ // echo '
469
+ // <div id="imsanity_header" style="float: left;">';
470
+
471
+ // if (!defined('IMSANITY_HIDE_LOGO'))
472
+ // echo '<a href="http://verysimple.com/products/imsanity/"><img alt="Imsanity" src="' . plugins_url() . '/imsanity/images/imsanity.png" style="float: right; margin-left: 15px;"/></a>';
473
+
474
+ /* echo '
475
+ <h4>'.__("Imsanity automatically resizes insanely huge image uploads",'imsanity').'</h4>'.
476
+
477
+ __("<p>Imsanity automaticaly reduces the size of images that are larger than the specified maximum and replaces the original
478
+ with one of a more \"sane\" size. Site contributors don\'t need to concern themselves with manually scaling images
479
+ and can upload them directly from their camera or phone.</p>
480
+
481
+ <p>The resolution of modern cameras is larger than necessary for typical web display.
482
+ The average computer screen is not big enough to display a 3 megapixel camera-phone image at full resolution.
483
+ WordPress does a good job of creating scaled-down copies which can be used, however the original images
484
+ are permanently stored, taking up disk quota and, if used on a page, create a poor viewer experience.</p>
485
+
486
+ <p>This plugin is designed for sites where high-resolution images are not necessary and/or site contributors
487
+ do not want (or understand how) to deal with scaling images. This plugin should not be used on
488
+ sites for which original, high-resolution images must be stored.</p>
489
+
490
+ <p>Be sure to save back-ups of your full-sized images if you wish to keep them.</p>",'imsanity') .
491
+
492
+ sprintf( __("<p>Imsanity Version %s by %s </p>",'imsanity'),IMSANITY_VERSION ,'<a href="https://ewww.io/">Shane Bishop</a>') .
493
+ '</div>
494
+ <br style="clear:both" />';*/
495
+ }
496
+
497
+ /**
498
+ * Render the settings page by writing directly to stdout. if multi-site is enabled
499
+ * and imsanity_override_site is true, then display a notice message that settings
500
+ * are not editable instead of the settings form
501
+ */
502
+ function imsanity_settings_page()
503
+ {
504
+ imsanity_settings_css();
505
+
506
+ ?>
507
+ <div class="wrap">
508
+ <div id="icon-options-general" class="icon32"><br></div>
509
+ <h2><?php _e("Imsanity Settings",'imsanity'); ?></h2>
510
+ <?php
511
+
512
+ imsanity_settings_banner();
513
+
514
+ $settings = imsanity_get_multisite_settings();
515
+
516
+ if ($settings->imsanity_override_site)
517
+ {
518
+ imsanity_settings_page_notice();
519
+ }
520
+ else
521
+ {
522
+ imsanity_settings_page_form();
523
+ }
524
+
525
+ ?>
526
+
527
+ <h2 style="margin-top: 0px;"><?php _e("Bulk Resize Images",'imsanity'); ?></h2>
528
+
529
+ <div id="imsanity_header">
530
+ <?php _e('<p>If you have existing images that were uploaded prior to installing Imsanity, you may resize them
531
+ all in bulk to recover disk space. To begin, click the "Search Images" button to search all existing
532
+ attachments for images that are larger than the configured limit.</p>
533
+ <p>Limitations: For performance reasons a maximum of ' . IMSANITY_AJAX_MAX_RECORDS . ' images will be returned at one time. Bitmap
534
+ image types are not supported and will not appear in the search results.</p>','imsanity'); ?>
535
+ </div>
536
+
537
+ <div style="border: solid 1px #ff6666; background-color: #ffbbbb; padding: 8px;">
538
+ <h4><?php _e('WARNING: BULK RESIZE WILL ALTER YOUR ORIGINAL IMAGES AND CANNOT BE UNDONE!','imsanity'); ?></h4>
539
+
540
+ <p><?php _e('It is <strong>HIGHLY</strong> recommended that you backup
541
+ your wp-content/uploads folder before proceeding. You will have a chance to preview and select the images to convert.
542
+ It is also recommended that you initially select only 1 or 2 images and verify that everything is ok before
543
+ processing your entire library. You have been warned!','imsanity'); ?></p>
544
+ </div>
545
+
546
+ <p class="submit" id="imsanity-examine-button">
547
+ <button class="button-primary" onclick="imsanity_load_images('imsanity_image_list');"><?php _e('Search Images...','imsanity'); ?></button>
548
+ </p>
549
+ <div id='imsanity_image_list'></div>
550
+
551
+ <?php
552
+
553
+ echo '</div>';
554
+
555
+ }
556
+
557
+ /**
558
+ * Multi-user config file exists so display a notice
559
+ */
560
+ function imsanity_settings_page_notice()
561
+ {
562
+ ?>
563
+ <div class="updated settings-error">
564
+ <p><strong><?php _e("Imsanity settings have been configured by the server administrator. There are no site-specific settings available.",'imsanity'); ?></strong></p>
565
+ </div>
566
+
567
+ <?php
568
+ }
569
+
570
+ /**
571
+ * Render the site settings form. This is processed by
572
+ * WordPress built-in options persistance mechanism
573
+ */
574
+ function imsanity_settings_page_form()
575
+ {
576
+ ?>
577
+ <form method="post" action="options.php">
578
+
579
+ <?php settings_fields( 'imsanity-settings-group' ); ?>
580
+ <table class="form-table">
581
+
582
+ <tr valign="middle">
583
+ <th scope="row"><?php _e("Images uploaded within a Page/Post",'imsanity'); ?></th>
584
+ <td>Fit within <input type="text" style="width: 50px;" name="imsanity_max_width" value="<?php echo get_option('imsanity_max_width',IMSANITY_DEFAULT_MAX_WIDTH); ?>" />
585
+ x <input type="text" style="width: 50px;" name="imsanity_max_height" value="<?php echo get_option('imsanity_max_height',IMSANITY_DEFAULT_MAX_HEIGHT); ?>" /> pixels width/height <?php _e(" (or enter 0 to disable)",'imsanity'); ?>
586
+ </td>
587
+ </tr>
588
+
589
+ <tr valign="middle">
590
+ <th scope="row"><?php _e("Images uploaded directly to the Media Library",'imsanity'); ?></th>
591
+ <td>Fit within <input type="text" style="width: 50px;" name="imsanity_max_width_library" value="<?php echo get_option('imsanity_max_width_library',IMSANITY_DEFAULT_MAX_WIDTH); ?>" />
592
+ x <input type="text" style="width: 50px;" name="imsanity_max_height_library" value="<?php echo get_option('imsanity_max_height_library',IMSANITY_DEFAULT_MAX_HEIGHT); ?>" /> pixels width/height <?php _e(" (or enter 0 to disable)",'imsanity'); ?>
593
+ </td>
594
+ </tr>
595
+
596
+ <tr valign="middle">
597
+ <th scope="row"><?php _e("Images uploaded elsewhere (Theme headers, backgrounds, logos, etc)",'imsanity'); ?></th>
598
+ <td>Fit within <input type="text" style="width: 50px;" name="imsanity_max_width_other" value="<?php echo get_option('imsanity_max_width_other',IMSANITY_DEFAULT_MAX_WIDTH); ?>" />
599
+ x <input type="text" style="width: 50px;" name="imsanity_max_height_other" value="<?php echo get_option('imsanity_max_height_other',IMSANITY_DEFAULT_MAX_HEIGHT); ?>" /> pixels width/height <?php _e(" (or enter 0 to disable)",'imsanity'); ?>
600
+ </td>
601
+ </tr>
602
+
603
+
604
+ <tr>
605
+ <th><label for='imsanity_quality' ><?php esc_html_e( "JPG image quality", 'imsanity' ); ?></th>
606
+ <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' ); ?>
607
+ <p class='description'><?php esc_html_e( 'WordPress default is 82','imsanity' ); ?></p></td>
608
+ </tr>
609
+
610
+ <tr valign="middle">
611
+ <th scope="row"><?php _e("Convert BMP To JPG",'imsanity'); ?></th>
612
+ <td><select name="imsanity_bmp_to_jpg">
613
+ <option <?php if (get_option('imsanity_bmp_to_jpg',IMSANITY_DEFAULT_BMP_TO_JPG) == "1") {echo "selected='selected'";} ?> value="1"><?php _e("Yes",'imsanity'); ?></option>
614
+ <option <?php if (get_option('imsanity_bmp_to_jpg',IMSANITY_DEFAULT_BMP_TO_JPG) == "0") {echo "selected='selected'";} ?> value="0"><?php _e("No",'imsanity'); ?></option>
615
+ </select></td>
616
+ </tr>
617
+
618
+ <tr valign="middle">
619
+ <th scope="row"><?php _e("Convert PNG To JPG",'imsanity'); ?></th>
620
+ <td><select name="imsanity_png_to_jpg">
621
+ <option <?php if (get_option('imsanity_png_to_jpg',IMSANITY_DEFAULT_PNG_TO_JPG) == "1") {echo "selected='selected'";} ?> value="1"><?php _e("Yes",'imsanity'); ?></option>
622
+ <option <?php if (get_option('imsanity_png_to_jpg',IMSANITY_DEFAULT_PNG_TO_JPG) == "0") {echo "selected='selected'";} ?> value="0"><?php _e("No",'imsanity'); ?></option>
623
+ </select></td>
624
+ </tr>
625
+
626
+ </table>
627
+
628
+ <p class="submit"><input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /></p>
629
+
630
+ </form>
631
+ <?php
632
+
633
+ }
634
+
635
+ ?>