Simple Image Sizes - Version 3.0.4

Version Description

Download this release

Release Info

Developer Rahe
Plugin Icon wp plugin Simple Image Sizes
Version 3.0.4
Comparing to
See all releases

Code changes from version 3.0.3 to 3.0.4

Files changed (7) hide show
  1. README +197 -192
  2. classes/admin/main.php +330 -307
  3. classes/admin/media.php +525 -479
  4. classes/admin/post.php +265 -251
  5. classes/main.php +60 -51
  6. readme.txt +179 -177
  7. simple_image_sizes.php +62 -60
README CHANGED
@@ -1,192 +1,197 @@
1
- # Simple Image Sizes #
2
- **Contributors:** Rahe
3
-
4
- **Donate link:** http://www.beapi.fr/donate/
5
-
6
- **Tags:** images, image, custom sizes, custom images, thumbnail regenerate, thumbnail, regenerate, cropping
7
-
8
- **Requires at least:** 3.5
9
-
10
- **Tested up to:** 3.9
11
-
12
- **Stable tag:** 3.0.1
13
-
14
-
15
- ## Description ##
16
-
17
- This plugin allow create custom image sizes for your site. Override your theme sizes directly on the media option page.
18
- You can regenerate all the sizes you have just created and choose which one you wanted to regenerate.
19
- You can now get all the code to copy and paste to your function theme file.
20
- Now you can use the generated sizes directly into your posts and insert images at the right size !
21
- Now you choose if you want display the size in the post insert image.
22
- Now you can regenerate the images one by one in the 'Medias' general pane.
23
- Now you can regenerate the images by bulk action in the 'Medias' general pane.
24
- Now you can regenerate the image sizes on single attachment edit page.
25
-
26
- I have added a timer so when you regeneration your thumbnails, you can know approximately when the regeneration will be ended.
27
- I have improved the php and javascript, you can know if the image have been regenerated or not or if there is an error and which one.
28
-
29
- Contribute on https://github.com/Rahe/Simple-image-sizes
30
-
31
- ## Installation ##
32
- **PHP5 Required.**
33
-
34
- 1. Download, unzip and upload to your WordPress plugins directory
35
- 2. Activate the plugin within you WordPress Administration Backend
36
- 3. Go to Settings > Medias
37
- 4. Configure your new image sizes and regenerate the thumbnails !
38
-
39
-
40
- ## Frequently Asked Questions ##
41
-
42
- ### Where can I add image sizes ? ####
43
- Go to Settings -> Media then you can add a image size. You have to add a unique custom name without any spaces or special chars.
44
- The best is to use something like my-custom-size.
45
- Then you have several fields for configuring the image size, the widht, the height, cropping.
46
- And then you can choose if the image is displayed on the media insertion or not ( this will be displayed on the dropdown list ).
47
-
48
-
49
- ## Screenshots ##
50
-
51
- ###1. Settings page
52
- ###
53
- ![Settings page
54
- ](http://s.wordpress.org/extend/plugins/simple-image-sizes/screenshot-1.png)
55
-
56
- ###2. Get PHP for the theme
57
- ###
58
- ![Get PHP for the theme
59
- ](http://s.wordpress.org/extend/plugins/simple-image-sizes/screenshot-2.png)
60
-
61
- ###3. Choose the sizes to regenerate and regenerate them
62
- ###
63
- ![Choose the sizes to regenerate
64
- ](http://s.wordpress.org/extend/plugins/simple-image-sizes/screenshot-3.png)
65
-
66
- ## Changelog ##
67
- * 3.0.2
68
- * Fix version check for the image crop positions
69
- * 3.0.1
70
- * Change the template render method for non apache webservers : https://wordpress.org/support/topic/fatal-error-1190?replies=6
71
- * Remove ambigious ids for the css bugging WooCommerce : https://wordpress.org/support/topic/bad-css-style-administration and
72
- * Right code for counting the elements on backoffice : https://github.com/Rahe/Simple-image-sizes/issues/20
73
- * Fix bug on regenation and _e instead of __ : https://plugins.trac.wordpress.org/ticket/2259
74
- * 3.0
75
- * Revamping all the code, change classes and structure
76
- * Use grunt for compiling files
77
- * Handle the 3.9 new cropping position
78
- * Remove aristo css
79
- * Use UI from WordPress
80
- * 2.4.3
81
- * Remove some php notices
82
- * Remove notice when wrong image size
83
- * 2.4.2
84
- * Selective regeneration fix by g100g on http://wordpress.org/support/topic/regenerating-fix
85
- * 2.4.1
86
- * Remove function not working on admin file
87
- * 2.4
88
- * Made for 3.5 and up
89
- * Refactoring PHP/Javascript code
90
- * Javascript improvements
91
- * Remove useless UI
92
- * UI improvements
93
- * Global PHP performance improvements
94
- * 2.3.1
95
- * Add Ajax bulk actions on medias list
96
- * Add ajax thumbnail rebuild on single media
97
- * 2.3
98
- * Add the custom size name in the attachment insertion
99
- * Exclude post_type wich do not support the post-thumbnail feature
100
- * 2.2.5
101
- * Debug the regeneration buggy !
102
- * Complete the french translation
103
- * Security update for single regeneration, include the nonce this time :)
104
- * 2.2.4
105
- * Add security nonces for every actions
106
- * Put the messages at the begining of the log
107
- * Add a select all checkbox Thank to cocola
108
- * Add the german translation thanks to glueckpress
109
- * Remove notice tnahks to christianwach
110
- * Remove useless and buggy for my scripting pointers
111
- * 2.2.3
112
- * Do not force network usage
113
- * 2.2.2
114
- * Debug js for the buttons
115
- * Remove console.log calls
116
- * 2.2.1
117
- * Use buttonset for the checkboxes
118
- * Add Pointer for WordPress 3.3
119
- * Fix translation in French
120
- * Some medias queries for small windows ( change size of buttons and alignment )
121
- * 2.2
122
- * Add new version of css aristo
123
- * Add some icons
124
- * Display button for saving changes only when changes detected
125
- * Display message when a size is modified but not saved and wanted to regenerate
126
- * Debug functionnality when regenerating only some sizes, metas not crushed
127
- * Add solo regenerating
128
- * Remove displaying for theme/not theme sizes
129
- * Use WordPress class for small inputs
130
- * 2.1
131
- * Add javascript timer
132
- * Improve javascript and more IE friendly
133
- * You can now choose if you want to display the image sizes in image insertion or not
134
- * Handle errors and messages
135
- * Remove some css useless rules
136
- * Fix bad translation for french
137
- * Remove accents in image sizes
138
- * Do not update size properties if there is an ajax query for an another size name
139
- * 2.0.3
140
- * Resolve issue with theme sizes witch by default are displayed as not cropped. Thanks to momo360modena for the bug signalment.
141
- * 2.0.2
142
- * Remove debug on php for javascript
143
- * Resolve issue with the different versions on jquery ( like in WP3.2 ) with attr return for checked components
144
- * 2.0.1
145
- * Resolve javascript issue when clicking on delete button
146
- * Resolve issue of never unchecking crop button
147
- * 2.0
148
- * Code refactoring
149
- * Update translations
150
- * Ajaxification of the process
151
- * Deleting by Ajax
152
- * Updating by Ajax
153
- * Adding by Ajax
154
- * Change UI
155
- * Change theme
156
- * Handle ajax errors
157
- * Handle not modified sizes, cropped
158
- * Handle same names
159
- * Sanitize the names
160
- * Customize jQuery ui
161
- * Customize jQuery ui theme
162
- * HTML5 Elements
163
- * CSS3 Animations
164
- * 1.0.6
165
- * Minify javascript names
166
- * Change progressbar style
167
- * Add animations on progressbar
168
- * 1.0.5
169
- * Only add css and js script in the media page to avoid any javascript error in other pages
170
- * Rectify css
171
- * Add function to get the code for the function.php file of the theme
172
- * Don't redefine the Wordpress basic size names
173
- * 1.0.4
174
- * Fix the add_image_size issue ( height and width reversed )
175
- * 1.0.3
176
- * Fix the plugin language
177
- * Add some translations
178
- * Externalise some css
179
- * Add sizes in the image adding to an article
180
- * Add setting link in the plugins list
181
- * Use admin_url instead of home_url
182
- * Add legend for colors
183
- * Some code refactoring
184
- * 1.0.2
185
- * Fix the plugin license
186
- * 1.0.1
187
- * Add POT file
188
- * Add french translation
189
- * 1.0
190
- * First release
191
- * Thumbnail regenerate
192
- * Image size generation
 
 
 
 
 
1
+ # Simple Image Sizes #
2
+ **Contributors:** Rahe
3
+
4
+ **Donate link:** http://www.beapi.fr/donate/
5
+
6
+ **Tags:** images, image, custom sizes, custom images, thumbnail regenerate, thumbnail, regenerate, cropping
7
+
8
+ **Requires at least:** 3.5
9
+
10
+ **Tested up to:** 4.2.1
11
+
12
+ **Stable tag:** 3.0.4
13
+
14
+
15
+ ## Description ##
16
+
17
+ This plugin allow create custom image sizes for your site. Override your theme sizes directly on the media option page.
18
+ You can regenerate all the sizes you have just created and choose which one you wanted to regenerate.
19
+ You can now get all the code to copy and paste to your function theme file.
20
+ Now you can use the generated sizes directly into your posts and insert images at the right size !
21
+ Now you choose if you want display the size in the post insert image.
22
+ Now you can regenerate the images one by one in the 'Medias' general pane.
23
+ Now you can regenerate the images by bulk action in the 'Medias' general pane.
24
+ Now you can regenerate the image sizes on single attachment edit page.
25
+
26
+ I have added a timer so when you regeneration your thumbnails, you can know approximately when the regeneration will be ended.
27
+ I have improved the php and javascript, you can know if the image have been regenerated or not or if there is an error and which one.
28
+
29
+ Contribute on https://github.com/Rahe/Simple-image-sizes
30
+
31
+ ## Installation ##
32
+ **PHP5 Required.**
33
+
34
+ 1. Download, unzip and upload to your WordPress plugins directory
35
+ 2. Activate the plugin within you WordPress Administration Backend
36
+ 3. Go to Settings > Medias
37
+ 4. Configure your new image sizes and regenerate the thumbnails !
38
+
39
+
40
+ ## Frequently Asked Questions ##
41
+
42
+ ### Where can I add image sizes ? ####
43
+ Go to Settings -> Media then you can add a image size. You have to add a unique custom name without any spaces or special chars.
44
+ The best is to use something like my-custom-size.
45
+ Then you have several fields for configuring the image size, the widht, the height, cropping.
46
+ And then you can choose if the image is displayed on the media insertion or not ( this will be displayed on the dropdown list ).
47
+
48
+
49
+ ## Screenshots ##
50
+
51
+ ###1. Settings page
52
+ ###
53
+ ![Settings page
54
+ ](http://s.wordpress.org/extend/plugins/simple-image-sizes/screenshot-1.png)
55
+
56
+ ###2. Get PHP for the theme
57
+ ###
58
+ ![Get PHP for the theme
59
+ ](http://s.wordpress.org/extend/plugins/simple-image-sizes/screenshot-2.png)
60
+
61
+ ###3. Choose the sizes to regenerate and regenerate them
62
+ ###
63
+ ![Choose the sizes to regenerate
64
+ ](http://s.wordpress.org/extend/plugins/simple-image-sizes/screenshot-3.png)
65
+
66
+ ## Changelog ##
67
+ * 3.0.4
68
+ * Fix global add_image_size
69
+ * 3.0.3
70
+ * Add Hebrew translations thanks to Atar4U
71
+ * 3.0.2
72
+ * Fix version check for the image crop positions
73
+ * Add Hebrew translations thanks to Atar4U
74
+ * 3.0.1
75
+ * Change the template render method for non apache webservers : https://wordpress.org/support/topic/fatal-error-1190?replies=6
76
+ * Remove ambigious ids for the css bugging WooCommerce : https://wordpress.org/support/topic/bad-css-style-administration and
77
+ * Right code for counting the elements on backoffice : https://github.com/Rahe/Simple-image-sizes/issues/20
78
+ * Fix bug on regenation and _e instead of __ : https://plugins.trac.wordpress.org/ticket/2259
79
+ * 3.0
80
+ * Revamping all the code, change classes and structure
81
+ * Use grunt for compiling files
82
+ * Handle the 3.9 new cropping position
83
+ * Remove aristo css
84
+ * Use UI from WordPress
85
+ * 2.4.3
86
+ * Remove some php notices
87
+ * Remove notice when wrong image size
88
+ * 2.4.2
89
+ * Selective regeneration fix by g100g on http://wordpress.org/support/topic/regenerating-fix
90
+ * 2.4.1
91
+ * Remove function not working on admin file
92
+ * 2.4
93
+ * Made for 3.5 and up
94
+ * Refactoring PHP/Javascript code
95
+ * Javascript improvements
96
+ * Remove useless UI
97
+ * UI improvements
98
+ * Global PHP performance improvements
99
+ * 2.3.1
100
+ * Add Ajax bulk actions on medias list
101
+ * Add ajax thumbnail rebuild on single media
102
+ * 2.3
103
+ * Add the custom size name in the attachment insertion
104
+ * Exclude post_type wich do not support the post-thumbnail feature
105
+ * 2.2.5
106
+ * Debug the regeneration buggy !
107
+ * Complete the french translation
108
+ * Security update for single regeneration, include the nonce this time :)
109
+ * 2.2.4
110
+ * Add security nonces for every actions
111
+ * Put the messages at the begining of the log
112
+ * Add a select all checkbox Thank to cocola
113
+ * Add the german translation thanks to glueckpress
114
+ * Remove notice tnahks to christianwach
115
+ * Remove useless and buggy for my scripting pointers
116
+ * 2.2.3
117
+ * Do not force network usage
118
+ * 2.2.2
119
+ * Debug js for the buttons
120
+ * Remove console.log calls
121
+ * 2.2.1
122
+ * Use buttonset for the checkboxes
123
+ * Add Pointer for WordPress 3.3
124
+ * Fix translation in French
125
+ * Some medias queries for small windows ( change size of buttons and alignment )
126
+ * 2.2
127
+ * Add new version of css aristo
128
+ * Add some icons
129
+ * Display button for saving changes only when changes detected
130
+ * Display message when a size is modified but not saved and wanted to regenerate
131
+ * Debug functionnality when regenerating only some sizes, metas not crushed
132
+ * Add solo regenerating
133
+ * Remove displaying for theme/not theme sizes
134
+ * Use WordPress class for small inputs
135
+ * 2.1
136
+ * Add javascript timer
137
+ * Improve javascript and more IE friendly
138
+ * You can now choose if you want to display the image sizes in image insertion or not
139
+ * Handle errors and messages
140
+ * Remove some css useless rules
141
+ * Fix bad translation for french
142
+ * Remove accents in image sizes
143
+ * Do not update size properties if there is an ajax query for an another size name
144
+ * 2.0.3
145
+ * Resolve issue with theme sizes witch by default are displayed as not cropped. Thanks to momo360modena for the bug signalment.
146
+ * 2.0.2
147
+ * Remove debug on php for javascript
148
+ * Resolve issue with the different versions on jquery ( like in WP3.2 ) with attr return for checked components
149
+ * 2.0.1
150
+ * Resolve javascript issue when clicking on delete button
151
+ * Resolve issue of never unchecking crop button
152
+ * 2.0
153
+ * Code refactoring
154
+ * Update translations
155
+ * Ajaxification of the process
156
+ * Deleting by Ajax
157
+ * Updating by Ajax
158
+ * Adding by Ajax
159
+ * Change UI
160
+ * Change theme
161
+ * Handle ajax errors
162
+ * Handle not modified sizes, cropped
163
+ * Handle same names
164
+ * Sanitize the names
165
+ * Customize jQuery ui
166
+ * Customize jQuery ui theme
167
+ * HTML5 Elements
168
+ * CSS3 Animations
169
+ * 1.0.6
170
+ * Minify javascript names
171
+ * Change progressbar style
172
+ * Add animations on progressbar
173
+ * 1.0.5
174
+ * Only add css and js script in the media page to avoid any javascript error in other pages
175
+ * Rectify css
176
+ * Add function to get the code for the function.php file of the theme
177
+ * Don't redefine the Wordpress basic size names
178
+ * 1.0.4
179
+ * Fix the add_image_size issue ( height and width reversed )
180
+ * 1.0.3
181
+ * Fix the plugin language
182
+ * Add some translations
183
+ * Externalise some css
184
+ * Add sizes in the image adding to an article
185
+ * Add setting link in the plugins list
186
+ * Use admin_url instead of home_url
187
+ * Add legend for colors
188
+ * Some code refactoring
189
+ * 1.0.2
190
+ * Fix the plugin license
191
+ * 1.0.1
192
+ * Add POT file
193
+ * Add french translation
194
+ * 1.0
195
+ * First release
196
+ * Thumbnail regenerate
197
+ * Image size generation
classes/admin/main.php CHANGED
@@ -1,308 +1,331 @@
1
- <?php
2
- Class SIS_Admin_Main {
3
-
4
- public function __construct() {
5
- add_action( 'admin_init', array( __CLASS__, 'register_assets' ) );
6
- }
7
-
8
- /**
9
- *
10
- */
11
- public static function register_assets() {
12
- $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG === true ? '' : '.min' ;
13
- // Add javascript
14
- wp_register_script( 'underscore', '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js' , array(), '1.6.0' );
15
- wp_register_script( 'sis_js', SIS_URL.'/assets/js/sis'.$suffix.'.js', array( 'jquery', 'jquery-ui-button', 'jquery-ui-progressbar', 'underscore' ), SIS_VERSION );
16
-
17
- // Differencitate the scripts
18
- wp_register_script( 'sis_js_attachments', SIS_URL.'/assets/js/sis-attachments'.$suffix.'.js', array( 'jquery' ), SIS_VERSION );
19
-
20
- // Add javascript translation
21
- wp_localize_script( 'sis_js', 'sis', self::localize_vars() );
22
- wp_localize_script( 'sis_js_attachments', 'sis', self::localize_vars() );
23
-
24
- // Add CSS
25
- wp_enqueue_style( 'sis_css', SIS_URL.'/assets/css/sis-style'.$suffix.'.css', array(), SIS_VERSION );
26
- }
27
-
28
-
29
- /**
30
- * Localize the var for javascript
31
- *
32
- * @access public
33
- * @return array
34
- * @author Nicolas Juen
35
- */
36
- public static function localize_vars() {
37
- return array(
38
- 'ajaxUrl' => admin_url( '/admin-ajax.php' ),
39
- 'reading' => __( 'Reading attachments...', 'simple-image-sizes' ),
40
- 'maximumWidth' => __( 'Maximum width', 'simple-image-sizes' ),
41
- 'maximumHeight' => __( 'Maximum height', 'simple-image-sizes' ),
42
- 'crop' => __( 'Crop', 'simple-image-sizes' ),
43
- 'tr' => __( 'yes', 'simple-image-sizes' ),
44
- 'fl' => __( 'no', 'simple-image-sizes' ),
45
- 'show' => __( 'Show in post insertion ?', 'simple-image-sizes' ),
46
- 'of' => __( ' of ', 'simple-image-sizes' ),
47
- 'or' => __( ' or ', 'simple-image-sizes' ),
48
- 'beforeEnd' => __( ' before the end.', 'simple-image-sizes' ),
49
- 'deleteImage' => __( 'Delete', 'simple-image-sizes' ),
50
- 'noMedia' => __( 'No media in your site to regenerate !', 'simple-image-sizes' ),
51
- 'regenerating' => __( 'Regenerating ', 'simple-image-sizes'),
52
- 'regenerate' => __( 'Regenerate ', 'simple-image-sizes'),
53
- 'validate' => __( 'Validate image size name', 'simple-image-sizes' ),
54
- 'done' => __( 'Done.', 'simple-image-sizes' ),
55
- 'size' => __( 'Size', 'simple-image-sizes' ),
56
- 'notOriginal' => __( 'Don\'t use the basic Wordpress thumbnail size name, use the form above to edit them', 'simple-image-sizes' ),
57
- 'alreadyPresent' => __( 'This size is already registered, edit it instead of recreating it.', 'simple-image-sizes' ),
58
- 'confirmDelete' => __( 'Do you really want to delete these size ?', 'simple-image-sizes' ),
59
- 'update' => __( 'Update', 'simple-image-sizes' ),
60
- 'ajaxErrorHandler' => __( 'Error requesting page', 'simple-image-sizes' ),
61
- 'messageRegenerated' => __( 'images have been regenerated !', 'simple-image-sizes' ),
62
- 'validateButton' => __( 'Validate', 'simple-image-sizes' ),
63
- 'startedAt' => __( ' started at', 'simple-image-sizes' ),
64
- 'customName' => __( 'Public name', 'simple-image-sizes' ),
65
- 'finishedAt' => __( ' finished at :', 'simple-image-sizes' ),
66
- 'phpError' => __( 'Error during the php treatment, be sure to not have php errors in your page', 'simple-image-sizes' ),
67
- 'notSaved' => __( 'All the sizes you have modifed are not saved, continue anyway ?', 'simple-image-sizes' ),
68
- 'soloRegenerated' => __( 'This image has been regenerated in %s seconds', 'simple-image-sizes' ),
69
- 'crop_positions' => self::get_available_crop(),
70
- 'regen_one' => wp_create_nonce( 'regen' )
71
- );
72
- }
73
-
74
- /**
75
- * Rebuild the given attribute with the given thumbnails
76
- *
77
- * @param $att_id
78
- * @param $thumbnails
79
- * @return array
80
- * @author Nicolas Juen
81
- */
82
- public static function thumbnail_rebuild( $att_id, $thumbnails = null ) {
83
- global $wpdb;
84
- // Time a the begining
85
- timer_start();
86
-
87
- // Check Id
88
- if( (int)$att_id <= 0 ) {
89
- return array(
90
- 'time' => timer_stop( false, 4 ),
91
- 'error' => __( 'No id given in POST datas.', 'simple-image-sizes' )
92
- );
93
- }
94
-
95
- // Get the path
96
- $fullsizepath = get_attached_file( $att_id );
97
-
98
- // Regen the attachment
99
- if ( false !== $fullsizepath && file_exists( $fullsizepath ) ) {
100
- if( wp_update_attachment_metadata( $att_id, self::wp_generate_attachment_metadata_custom( $att_id, $fullsizepath, $thumbnails ) ) == false ) {
101
- return array(
102
- 'src' => wp_get_attachment_thumb_url( $att_id ),
103
- 'time' => timer_stop( false, 4 ),
104
- 'message' => sprintf( __( 'This file already exists in this size and have not been regenerated :<br/><a target="_blank" href="%1$s" >%2$s</a>', 'simple-image-sizes'), get_edit_post_link( $att_id ), get_the_title( $att_id ) )
105
- );
106
- }
107
- } else {
108
- return array(
109
- 'src' => wp_get_attachment_thumb_url( $att_id ),
110
- 'time' => timer_stop( false, 4 ),
111
- 'error' => sprintf( __( 'This file does not exists and have not been regenerated :<br/><a target="_blank" href="%1$s" >%2$s</a>', 'simple-image-sizes'), get_edit_post_link( $att_id ), get_the_title( $att_id ) )
112
- );
113
-
114
- }
115
- // Display the attachment url for feedback
116
- return array(
117
- 'time' => timer_stop( false, 4 ),
118
- 'src' => wp_get_attachment_thumb_url( $att_id ),
119
- 'title' => get_the_title( $att_id )
120
- );
121
- }
122
-
123
- /**
124
- * Include the javascript template
125
- *
126
- * @param void
127
- * @return bool
128
- */
129
- public static function add_template() {
130
- global $pagenow;
131
- if( $pagenow != 'options-media.php' ) {
132
- return false;
133
- }
134
-
135
- if( is_file( SIS_DIR.'/templates/admin-js.html' ) ) {
136
- include( SIS_DIR.'/templates/admin-js.html' );
137
- }
138
-
139
- return true;
140
- }
141
-
142
- /**
143
- * Get all the available cropping
144
- *
145
- * @return array
146
- * @param void
147
- * @author Nicolas Juen
148
- */
149
- public static function get_available_crop() {
150
- global $wp_version;
151
-
152
- // Return the only possible
153
- if( version_compare( $wp_version, '3.9', '<' ) ) {
154
- return array( );
155
- }
156
-
157
- $x = array(
158
- 'left' => __( 'Left', 'simple-image-sizes' ),
159
- 'center' => __( 'Center', 'simple-image-sizes' ),
160
- 'right' => __( 'Right', 'simple-image-sizes' ),
161
- );
162
-
163
- $y = array(
164
- 'top' => __( 'top', 'simple-image-sizes' ),
165
- 'center' => __( 'center', 'simple-image-sizes' ),
166
- 'bottom' => __( 'bottom', 'simple-image-sizes' ),
167
- );
168
-
169
- $crops = array();
170
- foreach ( $x as $x_pos => $x_pos_label ) {
171
- foreach ( $y as $y_pos => $y_pos_label ) {
172
- $crops[$x_pos.'_'.$y_pos] = $x_pos_label.' '.$y_pos_label;
173
- }
174
- }
175
-
176
- return $crops;
177
- }
178
-
179
- /**
180
- * Check if the crop is available
181
- *
182
- * @param string $crop_position
183
- * @return bool
184
- * @author Nicolas Juen
185
- */
186
- public static function is_crop_position( $crop_position = '' ) {
187
- $crops = self::get_available_crop();
188
- return isset( $crops[$crop_position] );
189
- }
190
-
191
- /**
192
- * Return the crop position label from the slug
193
- *
194
- *
195
- * @param string $crop_position
196
- * @return string
197
- * @author Nicolas Juen
198
- */
199
- public static function get_crop_position_label( $crop_position = '' ) {
200
- if( !self::is_crop_position( $crop_position ) ) {
201
- return '';
202
- }
203
- $crops = self::get_available_crop();
204
- return $crops[$crop_position];
205
- }
206
-
207
-
208
- /**
209
- * Display a json encoded element with right headers
210
- *
211
- * @param $data(optional) : the element to display ( if needed )
212
- * @return void
213
- * @author Nicolas Juen
214
- */
215
- public static function displayJson( $data = array() ) {
216
- if( function_exists( 'wp_send_json' ) ) {
217
- wp_send_json( $data );
218
- }
219
-
220
- header('Cache-Control: no-cache, must-revalidate');
221
- header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
222
- header('Content-type: application/json');
223
- echo json_encode( $data );
224
- die();
225
- }
226
-
227
- /**
228
- * Generate post thumbnail attachment meta data.
229
- *
230
- * @since 2.1.0
231
- *
232
- * @param int $attachment_id Attachment Id to process.
233
- * @param string $file Filepath of the Attached image.
234
- * @return mixed Metadata for attachment.
235
- */
236
- public static function wp_generate_attachment_metadata_custom( $attachment_id, $file, $thumbnails = NULL ) {
237
- $attachment = get_post( $attachment_id );
238
-
239
- $meta_datas = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
240
-
241
- $metadata = array();
242
- if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) {
243
- $imagesize = getimagesize( $file );
244
- $metadata['width'] = $imagesize[0];
245
- $metadata['height'] = $imagesize[1];
246
- list($uwidth, $uheight) = wp_constrain_dimensions($metadata['width'], $metadata['height'], 128, 96);
247
- $metadata['hwstring_small'] = "height='$uheight' width='$uwidth'";
248
-
249
- // Make the file path relative to the upload dir
250
- $metadata['file'] = _wp_relative_upload_path($file);
251
-
252
- // make thumbnails and other intermediate sizes
253
- global $_wp_additional_image_sizes;
254
-
255
- foreach ( get_intermediate_image_sizes() as $s ) {
256
- $sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => FALSE );
257
- if ( isset( $_wp_additional_image_sizes[$s]['width'] ) )
258
- $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes
259
- else
260
- $sizes[$s]['width'] = get_option( "{$s}_size_w" ); // For default sizes set in options
261
- if ( isset( $_wp_additional_image_sizes[$s]['height'] ) )
262
- $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); // For theme-added sizes
263
- else
264
- $sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options
265
- if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) )
266
- $sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); // For theme-added sizes
267
- else
268
- $sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options
269
- }
270
-
271
- $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
272
-
273
- // Only if not all sizes
274
- if( isset( $thumbnails ) && is_array( $thumbnails ) && isset( $meta_datas['sizes'] ) && !empty( $meta_datas['sizes'] ) ) {
275
- // Fill the array with the other sizes not have to be done
276
- foreach( $meta_datas['sizes'] as $name => $fsize ) {
277
- $metadata['sizes'][$name] = $fsize;
278
- }
279
- }
280
-
281
- foreach ( $sizes as $size => $size_data ) {
282
- if( isset( $thumbnails ) )
283
- if( !in_array( $size, $thumbnails ) ) {
284
- continue;
285
- }
286
-
287
- $resized = image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] );
288
-
289
- if( isset( $meta_datas['size'][$size] ) ) {
290
- // Remove the size from the orignal sizes for after work
291
- unset( $meta_datas['size'][$size] );
292
- }
293
-
294
- if ( $resized ) {
295
- $metadata['sizes'][$size] = $resized;
296
- }
297
- }
298
-
299
- // fetch additional metadata from exif/iptc
300
- $image_meta = wp_read_image_metadata( $file );
301
- if ( $image_meta ) {
302
- $metadata['image_meta'] = $image_meta;
303
- }
304
- }
305
-
306
- return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );
307
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
  }
1
+ <?php
2
+
3
+ Class SIS_Admin_Main {
4
+
5
+ public function __construct() {
6
+ add_action( 'admin_init', array( __CLASS__, 'register_assets' ) );
7
+ }
8
+
9
+ /**
10
+ *
11
+ */
12
+ public static function register_assets() {
13
+ $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG === true ? '' : '.min';
14
+ // Add javascript
15
+ wp_register_script( 'underscore', '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js', array(), '1.6.0' );
16
+ wp_register_script( 'sis_js', SIS_URL . '/assets/js/sis' . $suffix . '.js', array(
17
+ 'jquery',
18
+ 'jquery-ui-button',
19
+ 'jquery-ui-progressbar',
20
+ 'underscore'
21
+ ), SIS_VERSION );
22
+
23
+ // Differencitate the scripts
24
+ wp_register_script( 'sis_js_attachments', SIS_URL . '/assets/js/sis-attachments' . $suffix . '.js', array( 'jquery' ), SIS_VERSION );
25
+
26
+ // Add javascript translation
27
+ wp_localize_script( 'sis_js', 'sis', self::localize_vars() );
28
+ wp_localize_script( 'sis_js_attachments', 'sis', self::localize_vars() );
29
+
30
+ // Add CSS
31
+ wp_enqueue_style( 'sis_css', SIS_URL . '/assets/css/sis-style' . $suffix . '.css', array(), SIS_VERSION );
32
+ }
33
+
34
+
35
+ /**
36
+ * Localize the var for javascript
37
+ *
38
+ * @access public
39
+ * @return array
40
+ * @author Nicolas Juen
41
+ */
42
+ public static function localize_vars() {
43
+ return array(
44
+ 'ajaxUrl' => admin_url( '/admin-ajax.php' ),
45
+ 'reading' => __( 'Reading attachments...', 'simple-image-sizes' ),
46
+ 'maximumWidth' => __( 'Maximum width', 'simple-image-sizes' ),
47
+ 'maximumHeight' => __( 'Maximum height', 'simple-image-sizes' ),
48
+ 'crop' => __( 'Crop', 'simple-image-sizes' ),
49
+ 'tr' => __( 'yes', 'simple-image-sizes' ),
50
+ 'fl' => __( 'no', 'simple-image-sizes' ),
51
+ 'show' => __( 'Show in post insertion ?', 'simple-image-sizes' ),
52
+ 'of' => __( ' of ', 'simple-image-sizes' ),
53
+ 'or' => __( ' or ', 'simple-image-sizes' ),
54
+ 'beforeEnd' => __( ' before the end.', 'simple-image-sizes' ),
55
+ 'deleteImage' => __( 'Delete', 'simple-image-sizes' ),
56
+ 'noMedia' => __( 'No media in your site to regenerate !', 'simple-image-sizes' ),
57
+ 'regenerating' => __( 'Regenerating ', 'simple-image-sizes' ),
58
+ 'regenerate' => __( 'Regenerate ', 'simple-image-sizes' ),
59
+ 'validate' => __( 'Validate image size name', 'simple-image-sizes' ),
60
+ 'done' => __( 'Done.', 'simple-image-sizes' ),
61
+ 'size' => __( 'Size', 'simple-image-sizes' ),
62
+ 'notOriginal' => __( 'Don\'t use the basic Wordpress thumbnail size name, use the form above to edit them', 'simple-image-sizes' ),
63
+ 'alreadyPresent' => __( 'This size is already registered, edit it instead of recreating it.', 'simple-image-sizes' ),
64
+ 'confirmDelete' => __( 'Do you really want to delete these size ?', 'simple-image-sizes' ),
65
+ 'update' => __( 'Update', 'simple-image-sizes' ),
66
+ 'ajaxErrorHandler' => __( 'Error requesting page', 'simple-image-sizes' ),
67
+ 'messageRegenerated' => __( 'images have been regenerated !', 'simple-image-sizes' ),
68
+ 'validateButton' => __( 'Validate', 'simple-image-sizes' ),
69
+ 'startedAt' => __( ' started at', 'simple-image-sizes' ),
70
+ 'customName' => __( 'Public name', 'simple-image-sizes' ),
71
+ 'finishedAt' => __( ' finished at :', 'simple-image-sizes' ),
72
+ 'phpError' => __( 'Error during the php treatment, be sure to not have php errors in your page', 'simple-image-sizes' ),
73
+ 'notSaved' => __( 'All the sizes you have modifed are not saved, continue anyway ?', 'simple-image-sizes' ),
74
+ 'soloRegenerated' => __( 'This image has been regenerated in %s seconds', 'simple-image-sizes' ),
75
+ 'crop_positions' => self::get_available_crop(),
76
+ 'regen_one' => wp_create_nonce( 'regen' )
77
+ );
78
+ }
79
+
80
+ /**
81
+ * Rebuild the given attribute with the given thumbnails
82
+ *
83
+ * @param $att_id
84
+ * @param $thumbnails
85
+ *
86
+ * @return array
87
+ * @author Nicolas Juen
88
+ */
89
+ public static function thumbnail_rebuild( $att_id, $thumbnails = null ) {
90
+ // Time a the begining
91
+ timer_start();
92
+
93
+ // Check Id
94
+ if ( (int) $att_id <= 0 ) {
95
+ return array(
96
+ 'time' => timer_stop( false, 4 ),
97
+ 'error' => __( 'No id given in POST datas.', 'simple-image-sizes' )
98
+ );
99
+ }
100
+
101
+ // Get the path
102
+ $fullsizepath = get_attached_file( $att_id );
103
+
104
+ // Regen the attachment
105
+ if ( false !== $fullsizepath && file_exists( $fullsizepath ) ) {
106
+ if ( false == wp_update_attachment_metadata( $att_id, self::wp_generate_attachment_metadata_custom( $att_id, $fullsizepath, $thumbnails ) ) ) {
107
+ return array(
108
+ 'src' => wp_get_attachment_thumb_url( $att_id ),
109
+ 'time' => timer_stop( false, 4 ),
110
+ 'message' => sprintf( __( 'This file already exists in this size and have not been regenerated :<br/><a target="_blank" href="%1$s" >%2$s</a>', 'simple-image-sizes' ), get_edit_post_link( $att_id ), get_the_title( $att_id ) )
111
+ );
112
+ }
113
+ } else {
114
+ return array(
115
+ 'src' => wp_get_attachment_thumb_url( $att_id ),
116
+ 'time' => timer_stop( false, 4 ),
117
+ 'error' => sprintf( __( 'This file does not exists and have not been regenerated :<br/><a target="_blank" href="%1$s" >%2$s</a>', 'simple-image-sizes' ), get_edit_post_link( $att_id ), get_the_title( $att_id ) )
118
+ );
119
+
120
+ }
121
+
122
+ // Display the attachment url for feedback
123
+ return array(
124
+ 'time' => timer_stop( false, 4 ),
125
+ 'src' => wp_get_attachment_thumb_url( $att_id ),
126
+ 'title' => get_the_title( $att_id )
127
+ );
128
+ }
129
+
130
+ /**
131
+ * Include the javascript template
132
+ *
133
+ * @param void
134
+ *
135
+ * @return bool
136
+ */
137
+ public static function add_template() {
138
+ global $pagenow;
139
+ if ( 'options-media.php' !== $pagenow ) {
140
+ return false;
141
+ }
142
+
143
+ if ( is_file( SIS_DIR . '/templates/admin-js.html' ) ) {
144
+ include( SIS_DIR . '/templates/admin-js.html' );
145
+ }
146
+
147
+ return true;
148
+ }
149
+
150
+ /**
151
+ * Get all the available cropping
152
+ *
153
+ * @return array
154
+ *
155
+ * @param void
156
+ *
157
+ * @author Nicolas Juen
158
+ */
159
+ public static function get_available_crop() {
160
+ global $wp_version;
161
+
162
+ // Return the only possible
163
+ if ( version_compare( $wp_version, '3.9', '<' ) ) {
164
+ return array();
165
+ }
166
+
167
+ $x = array(
168
+ 'left' => __( 'Left', 'simple-image-sizes' ),
169
+ 'center' => __( 'Center', 'simple-image-sizes' ),
170
+ 'right' => __( 'Right', 'simple-image-sizes' ),
171
+ );
172
+
173
+ $y = array(
174
+ 'top' => __( 'top', 'simple-image-sizes' ),
175
+ 'center' => __( 'center', 'simple-image-sizes' ),
176
+ 'bottom' => __( 'bottom', 'simple-image-sizes' ),
177
+ );
178
+
179
+ $crops = array();
180
+ foreach ( $x as $x_pos => $x_pos_label ) {
181
+ foreach ( $y as $y_pos => $y_pos_label ) {
182
+ $crops[ $x_pos . '_' . $y_pos ] = $x_pos_label . ' ' . $y_pos_label;
183
+ }
184
+ }
185
+
186
+ return $crops;
187
+ }
188
+
189
+ /**
190
+ * Check if the crop is available
191
+ *
192
+ * @param string $crop_position
193
+ *
194
+ * @return bool
195
+ * @author Nicolas Juen
196
+ */
197
+ public static function is_crop_position( $crop_position ) {
198
+ $crops = self::get_available_crop();
199
+
200
+ return isset( $crops[ $crop_position ] );
201
+ }
202
+
203
+ /**
204
+ * Return the crop position label from the slug
205
+ *
206
+ *
207
+ * @param string $crop_position
208
+ *
209
+ * @return string
210
+ * @author Nicolas Juen
211
+ */
212
+ public static function get_crop_position_label( $crop_position ) {
213
+ if ( ! self::is_crop_position( $crop_position ) ) {
214
+ return '';
215
+ }
216
+ $crops = self::get_available_crop();
217
+
218
+ return $crops[ $crop_position ];
219
+ }
220
+
221
+
222
+ /**
223
+ * Display a json encoded element with right headers
224
+ *
225
+ * @param $data (optional) : the element to display ( if needed )
226
+ *
227
+ * @return void
228
+ * @author Nicolas Juen
229
+ */
230
+ public static function displayJson( $data = array() ) {
231
+ if ( function_exists( 'wp_send_json' ) ) {
232
+ wp_send_json( $data );
233
+ }
234
+
235
+ header( 'Cache-Control: no-cache, must-revalidate' );
236
+ header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
237
+ header( 'Content-type: application/json' );
238
+ echo json_encode( $data );
239
+ die();
240
+ }
241
+
242
+ /**
243
+ * Generate post thumbnail attachment meta data.
244
+ *
245
+ * @since 2.1.0
246
+ *
247
+ * @param int $attachment_id Attachment Id to process.
248
+ * @param string $file Filepath of the Attached image.
249
+ *
250
+ * @return mixed Metadata for attachment.
251
+ */
252
+ public static function wp_generate_attachment_metadata_custom( $attachment_id, $file, $thumbnails = null ) {
253
+ $attachment = get_post( $attachment_id );
254
+
255
+ $meta_datas = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
256
+
257
+ $metadata = array();
258
+ if ( preg_match( '!^image/!', get_post_mime_type( $attachment ) ) && file_is_displayable_image( $file ) ) {
259
+ $imagesize = getimagesize( $file );
260
+ $metadata['width'] = $imagesize[0];
261
+ $metadata['height'] = $imagesize[1];
262
+ list( $uwidth, $uheight ) = wp_constrain_dimensions( $metadata['width'], $metadata['height'], 128, 96 );
263
+ $metadata['hwstring_small'] = "height='$uheight' width='$uwidth'";
264
+
265
+ // Make the file path relative to the upload dir
266
+ $metadata['file'] = _wp_relative_upload_path( $file );
267
+
268
+ // make thumbnails and other intermediate sizes
269
+ global $_wp_additional_image_sizes;
270
+
271
+ foreach ( get_intermediate_image_sizes() as $s ) {
272
+ $sizes[ $s ] = array( 'width' => '', 'height' => '', 'crop' => false );
273
+ if ( isset( $_wp_additional_image_sizes[ $s ]['width'] ) ) {
274
+ $sizes[ $s ]['width'] = intval( $_wp_additional_image_sizes[ $s ]['width'] );
275
+ } // For theme-added sizes
276
+ else {
277
+ $sizes[ $s ]['width'] = get_option( "{$s}_size_w" );
278
+ } // For default sizes set in options
279
+ if ( isset( $_wp_additional_image_sizes[ $s ]['height'] ) ) {
280
+ $sizes[ $s ]['height'] = intval( $_wp_additional_image_sizes[ $s ]['height'] );
281
+ } // For theme-added sizes
282
+ else {
283
+ $sizes[ $s ]['height'] = get_option( "{$s}_size_h" );
284
+ } // For default sizes set in options
285
+ if ( isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ) {
286
+ $sizes[ $s ]['crop'] = intval( $_wp_additional_image_sizes[ $s ]['crop'] );
287
+ } // For theme-added sizes
288
+ else {
289
+ $sizes[ $s ]['crop'] = get_option( "{$s}_crop" );
290
+ } // For default sizes set in options
291
+ }
292
+
293
+ $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
294
+
295
+ // Only if not all sizes
296
+ if ( isset( $thumbnails ) && is_array( $thumbnails ) && isset( $meta_datas['sizes'] ) && ! empty( $meta_datas['sizes'] ) ) {
297
+ // Fill the array with the other sizes not have to be done
298
+ foreach ( $meta_datas['sizes'] as $name => $fsize ) {
299
+ $metadata['sizes'][ $name ] = $fsize;
300
+ }
301
+ }
302
+
303
+ foreach ( $sizes as $size => $size_data ) {
304
+ if ( isset( $thumbnails ) ) {
305
+ if ( ! in_array( $size, $thumbnails ) ) {
306
+ continue;
307
+ }
308
+ }
309
+
310
+ $resized = image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] );
311
+
312
+ if ( isset( $meta_datas['size'][ $size ] ) ) {
313
+ // Remove the size from the orignal sizes for after work
314
+ unset( $meta_datas['size'][ $size ] );
315
+ }
316
+
317
+ if ( $resized ) {
318
+ $metadata['sizes'][ $size ] = $resized;
319
+ }
320
+ }
321
+
322
+ // fetch additional metadata from exif/iptc
323
+ $image_meta = wp_read_image_metadata( $file );
324
+ if ( $image_meta ) {
325
+ $metadata['image_meta'] = $image_meta;
326
+ }
327
+ }
328
+
329
+ return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );
330
+ }
331
  }
classes/admin/media.php CHANGED
@@ -1,479 +1,525 @@
1
- <?php
2
- Class SIS_Admin_Media {
3
-
4
- // Original sizes
5
- public static $original = array( 'thumbnail', 'medium', 'large' );
6
-
7
- public function __construct() {
8
- // Init
9
-
10
- add_action( 'admin_menu', array( __CLASS__, 'init' ) );
11
- add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ), 11 );
12
-
13
- // Add ajax action
14
- // Option page
15
- add_action( 'wp_ajax_'.'sis_get_list', array( __CLASS__, 'a_get_list' ) );
16
- add_action( 'wp_ajax_'.'sis_rebuild_images', array( __CLASS__, 'a_thumbnails_rebuild' ) );
17
- add_action( 'wp_ajax_'.'sis_get_sizes', array( __CLASS__, 'a_get_sizes' ) );
18
- add_action( 'wp_ajax_'.'sis_add_size', array( __CLASS__, 'a_add_size' ) );
19
- add_action( 'wp_ajax_'.'sis_remove_size', array( __CLASS__, 'a_remove_size' ) );
20
-
21
- // Add link in plugins list
22
- add_filter( 'plugin_action_links', array( __CLASS__,'add_settings_link' ), 10, 2 );
23
- }
24
-
25
- /**
26
- * Register javascripts and css.
27
- *
28
- * @access public
29
- * @return void
30
- * @author Nicolas Juen
31
- */
32
- public static function enqueue_assets( $hook_suffix = '' ) {
33
- if( !isset( $hook_suffix ) || empty( $hook_suffix ) ) {
34
- return false;
35
- }
36
-
37
- if( $hook_suffix == 'options-media.php' ) {
38
- // Add javascript
39
- wp_enqueue_script( 'sis_js' );
40
-
41
- // Add CSS
42
- wp_enqueue_style( 'sis_css' );
43
-
44
- // Add underscore template
45
- add_action( 'admin_footer', array( 'SIS_Admin_Main', 'add_template' ) );
46
- }
47
- }
48
-
49
-
50
-
51
- /**
52
- * Add a link to the setting option page
53
- *
54
- * @access public
55
- * @param array $links
56
- * @param string $file
57
- * @return void
58
- * @author Nicolas Juen
59
- */
60
- public static function add_settings_link( $links, $file ) {
61
-
62
- if( $file != 'simple-image-sizes/simple_image_sizes.php' ) {
63
- return $links;
64
- }
65
-
66
- $settings_link = '<a href="'.admin_url('options-media.php').'"> '.__( 'Settings', 'simple-image-sizes' ).' </a>';
67
- array_unshift( $links, $settings_link );
68
-
69
- return $links;
70
- }
71
-
72
- /**
73
- * Init for the option page
74
- *
75
- * @access public
76
- * @return void
77
- * @author Nicolas Juen
78
- */
79
- public static function init() {
80
- // Check if admin
81
- if( !is_admin() ) {
82
- return false;
83
- }
84
-
85
- // Get the image sizes
86
- global $_wp_additional_image_sizes;
87
- $options = get_option( SIS_OPTION );
88
-
89
- // Get the sizes and add the settings
90
- foreach ( get_intermediate_image_sizes() as $s ) {
91
- // Don't make the original sizes or numeric sizes that appear
92
- if( in_array( $s, self::$original ) || is_integer( $s ) ) {
93
- continue;
94
- }
95
-
96
- // Set width
97
- $width = isset( $_wp_additional_image_sizes[$s]['width'] ) ? intval( $_wp_additional_image_sizes[$s]['width'] ) : get_option( "{$s}_size_w" ) ;
98
-
99
- // Set height
100
- $height = isset( $_wp_additional_image_sizes[$s]['height'] ) ? intval( $_wp_additional_image_sizes[$s]['height'] ) : get_option( "{$s}_size_h" ) ;
101
-
102
- //Set crop
103
- $crop = isset( $_wp_additional_image_sizes[$s]['crop'] ) ? intval( $_wp_additional_image_sizes[$s]['crop'] ) : get_option( "{$s}_crop" ) ;
104
-
105
- // Add the setting field for this size
106
- add_settings_field( 'image_size_'.$s, sprintf( __( '%s size', 'simple-image-sizes' ), $s ), array( __CLASS__, 'image_sizes' ), 'media' , 'default', array( 'name' => $s , 'width' => $width , 'height' => $height, 'c' => $crop ) );
107
- }
108
-
109
- // Register the setting for media option page
110
- register_setting( 'media', SIS_OPTION );
111
-
112
- // Add the button
113
- add_settings_field( 'add_size_button', __( 'Add a new size', 'simple-image-sizes' ), array( __CLASS__, 'addSizeButton' ), 'media' );
114
-
115
- // Add php button
116
- add_settings_field( 'get_php_button', __( 'Get php for theme', 'simple-image-sizes' ), array( __CLASS__, 'getPhpButton' ), 'media' );
117
-
118
- // Add section for the thumbnail regeneration
119
- add_settings_section( 'thumbnail_regenerate', __( 'Thumbnail regeneration', 'simple-image-sizes' ), array( __CLASS__, 'thumbnailRegenerate' ), 'media' );
120
- }
121
-
122
- /**
123
- * Display the row of the image size
124
- *
125
- * @access public
126
- * @param mixed $args
127
- * @return void
128
- * @author Nicolas Juen
129
- */
130
- public static function image_sizes( $args ) {
131
-
132
- if( is_integer( $args['name'] ) ) {
133
- return false;
134
- }
135
-
136
- // Get the options
137
- $sizes = (array)get_option( SIS_OPTION, array() );
138
-
139
- // Get the vars
140
- $height = isset( $sizes[$args['name']]['h'] )? $sizes[$args['name']]['h'] : $args['height'] ;
141
- $width = isset( $sizes[$args['name']]['w'] )? $sizes[$args['name']]['w'] : $args['width'] ;
142
- $crop = isset( $sizes[$args['name']]['c'] ) && !empty( $sizes[$args['name']]['c'] )? $sizes[$args['name']]['c'] : $args['c'] ;
143
- $show = isset( $sizes[$args['name']]['s'] ) && !empty( $sizes[$args['name']]['s'] )? '1' : '0' ;
144
- $custom = isset( $sizes[$args['name']]['custom'] ) && !empty( $sizes[$args['name']]['custom'] )? '1' : '0' ;
145
- $name = isset( $sizes[$args['name']]['n'] ) && !empty( $sizes[$args['name']]['n'] )? esc_html( $sizes[$args['name']]['n'] ) : esc_html( $args['name'] ) ;
146
- ?>
147
- <input type="hidden" value="<?php echo esc_attr( $args['name'] ); ?>" name="image_name" />
148
- <?php if( $custom ): ?>
149
- <input name="<?php echo esc_attr( 'custom_image_sizes['.$args['name'].'][custom]' ); ?>" type="hidden" id="<?php echo esc_attr( 'custom_image_sizes['.$args['name'].'][custom]' ); ?>" value="1" />
150
- <?php else: ?>
151
- <input name="<?php echo esc_attr( 'custom_image_sizes['.$args['name'].'][theme]' ); ?>" type="hidden" id="<?php echo esc_attr( 'custom_image_sizes['.$args['name'].'][theme]' ); ?>" value="1" />
152
- <?php endif; ?>
153
- <label class="sis-label" for="<?php echo esc_attr( 'custom_image_sizes['.$args['name'].'][w]' ); ?>">
154
- <?php _e( 'Maximum width', 'simple-image-sizes'); ?>
155
- <input name="<?php esc_attr_e( 'custom_image_sizes['.$args['name'].'][w]' ); ?>" class='w small-text' type="number" step='1' min='0' id="<?php echo esc_attr( 'custom_image_sizes['.$args['name'].'][w]' ); ?>" base_w='<?php echo esc_attr( $width ); ?>' value="<?php echo esc_attr( $width ); ?>" />
156
- </label>
157
- <label class="sis-label" for="<?php esc_attr_e( 'custom_image_sizes['.$args['name'].'][h]' ); ?>">
158
- <?php _e( 'Maximum height', 'simple-image-sizes'); ?>
159
- <input name="<?php esc_attr_e( 'custom_image_sizes['.$args['name'].'][h]' ); ?>" class='h small-text' type="number" step='1' min='0' id="<?php echo esc_attr( 'custom_image_sizes['.$args['name'].'][h]' ); ?>" base_h='<?php echo esc_attr( $height ); ?>' value="<?php echo esc_attr( $height ); ?>" />
160
- </label>
161
- <label class="sis-label" for="<?php echo esc_attr( 'custom_image_sizes['.$args['name'].'][n]' ); ?>">
162
- <?php _e( 'Public name', 'simple-image-sizes'); ?>
163
- <input name="<?php echo esc_attr( 'custom_image_sizes['.$args['name'].'][n]' ); ?>" class='n' type="text" id="<?php echo esc_attr( 'custom_image_sizes['.$args['name'].'][n]' ); ?>" base_n='<?php echo $name; ?>' value="<?php echo $name ?>" />
164
- </label>
165
- <span class="size_options">
166
- <label class="c" for="<?php echo esc_attr( 'custom_image_sizes['.$args['name'].'][c]' ); ?>"><?php _e( 'Cropping', 'simple-image-sizes'); ?></label>
167
- <select id="<?php echo esc_attr( 'custom_image_sizes['.$args['name'].'][c]' ); ?>" class="c crop" base_c='<?php echo esc_attr( $crop ); ?>' name="<?php echo esc_attr( 'custom_image_sizes['.$args['name'].'][c]' ); ?>" >
168
- <option value="0" <?php selected( 0, $crop ); ?>><?php esc_html_e( 'No', 'simple-image-sizes' ); ?></option>
169
- <option value="1" <?php selected( 1, $crop ); ?>><?php esc_html_e( 'Yes', 'simple-image-sizes' ); ?></option>
170
- <?php foreach( SIS_Admin_Main::get_available_crop() as $crop_position => $label ): ?>
171
- <option <?php selected( $crop_position, $crop ); ?> value="<?php echo esc_attr( $crop_position ) ?>"><?php echo esc_html( $label ); ?></option>
172
- <?php endforeach; ?>
173
- </select>
174
-
175
- <input type='checkbox' id="<?php echo esc_attr( 'custom_image_sizes['.$args['name'].'][s]'); ?>" <?php checked( $show, 1 ) ?> class="s show" base_s='<?php echo esc_attr( $show ); ?>' name="<?php echo esc_attr( 'custom_image_sizes['.$args['name'].'][s]'); ?>" value="1" />
176
- <label class="s" for="<?php echo esc_attr( 'custom_image_sizes['.$args['name'].'][s]'); ?>"><?php _e( 'Show in post insertion ?', 'simple-image-sizes'); ?></label>
177
- </span>
178
- <span class="delete_size button-secondary"><?php _e( 'Delete', 'simple-image-sizes'); ?></span>
179
- <span class="add_size validate_size button-primary"><?php _e( 'Update', 'simple-image-sizes'); ?></span>
180
-
181
- <input type="hidden" class="deleteSize button-primary" value='<?php echo wp_create_nonce( 'delete_'.$args['name'] ); ?>' />
182
- <?php }
183
-
184
- /**
185
- * Add the button to add a size
186
- *
187
- * @access public
188
- * @return void
189
- * @author Nicolas Juen
190
- */
191
- public static function addSizeButton() { ?>
192
- <input type="button" class="button-secondary action" id="add_size" value="<?php esc_attr_e( 'Add a new size of thumbnail', 'simple-image-sizes'); ?>" />
193
- <?php
194
- }
195
-
196
- /**
197
- * Add the button to get the php for th sizes
198
- *
199
- * @access public
200
- * @return void
201
- * @author Nicolas Juen
202
- */
203
- public static function getPhpButton() { ?>
204
- <input type="button" class="button-secondary action" id="get_php" value="<?php esc_attr_e( 'Get the PHP for the theme', 'simple-image-sizes'); ?>" />
205
- <p> <?php _e( 'Copy and paste the code below into your Wordpress theme function file if you wanted to save them and deactivate the plugin.', 'simple-image-sizes'); ?> </p>
206
- <code></code>
207
- <?php
208
- }
209
-
210
- /**
211
- * Display the Table of sizes and post types for regenerating
212
- *
213
- * @access public
214
- * @return void
215
- * @author Nicolas Juen
216
- */
217
- public static function thumbnailRegenerate() {
218
- if( is_file( SIS_DIR.'/templates/options-media.php' ) ) {
219
- include( SIS_DIR.'/templates/options-media.php' );
220
- } else {
221
- esc_html_e( 'Admin option-media template missing', 'simple-image-sizes' );
222
- }
223
- }
224
-
225
- /**
226
- * Add a size by Ajax
227
- *
228
- * @access public
229
- * @return void
230
- * @author Nicolas Juen
231
- */
232
- public static function a_add_size() {
233
-
234
- // Get the nonce
235
- $nonce = isset( $_POST['nonce'] ) ? $_POST['nonce']: '' ;
236
-
237
- // Get old options
238
- $sizes = (array)get_option( SIS_OPTION, array() );
239
- $croppings = SIS_Admin_Main::get_available_crop();
240
- $croppings[true] = '';
241
- $croppings[false] = '';
242
-
243
- // Check entries
244
- $name = isset( $_POST['name'] ) ? sanitize_title( $_POST['name'] ): '' ;
245
- $height = !isset( $_POST['height'] )? 0 : absint( $_POST['height'] );
246
- $width = !isset( $_POST['width'] )? 0 : absint( $_POST['width'] );
247
- $crop = isset( $_POST['crop'] ) && isset( $croppings[$_POST['crop']] ) ? $_POST['crop'] : false;
248
- $show = isset( $_POST['show'] ) && $_POST['show'] == 'false' ? false : true;
249
- $cn = isset( $_POST['customName'] ) && !empty( $_POST['customName'] ) ? sanitize_text_field( $_POST['customName'] ): $name ;
250
-
251
- // Check the nonce
252
- if( !wp_verify_nonce( $nonce , 'add_size' ) ) {
253
- die(0);
254
- }
255
-
256
- // If no name given do not save
257
- if( empty( $name ) ) {
258
- die(0);
259
- }
260
-
261
- // Make values
262
- $values = array( 'custom' => 1, 'w' => $width , 'h' => $height, 'c' => $crop, 's' => $show, 'n' => $cn );
263
-
264
- // If the size have not changed return 2
265
- if( isset( $sizes[$name] ) && $sizes[$name] === $values ) {
266
- die(2);
267
- }
268
-
269
- // Put the new values
270
- $sizes[$name] = $values;
271
-
272
- // display update result
273
- echo (int)update_option( 'custom_image_sizes', $sizes );
274
- die();
275
- }
276
-
277
- /**
278
- * Remove a size by Ajax
279
- *
280
- * @access public
281
- * @return void
282
- * @author Nicolas Juen
283
- */
284
- public static function a_remove_size() {
285
-
286
- // Get old options
287
- $sizes = (array)get_option( SIS_OPTION, array() );
288
-
289
- // Get the nonce and name
290
- $nonce = isset( $_POST['nonce'] ) ? $_POST['nonce']: '' ;
291
- $name = isset( $_POST['name'] ) ? sanitize_title( $_POST['name'] ): '' ;
292
-
293
- // Check the nonce
294
- if( !wp_verify_nonce( $nonce , 'delete_'.$name ) ) {
295
- die(0);
296
- }
297
-
298
- // Remove the size
299
- unset( $sizes[sanitize_title( $name )] );
300
- unset( $sizes[0] );
301
-
302
- // Display the results
303
- echo (int)update_option( SIS_OPTION, $sizes );
304
- die();
305
- }
306
-
307
- /**
308
- * Display the add_image_size for the registered sizes
309
- *
310
- * @access public
311
- * @return void
312
- */
313
- public static function a_get_sizes() {
314
- global $_wp_additional_image_sizes,$wp_version;
315
-
316
- foreach ( get_intermediate_image_sizes() as $s ) {
317
- // Don't make the original sizes
318
- if( in_array( $s, self::$original ) ) {
319
- continue;
320
- }
321
-
322
- // Set width
323
- $width = isset( $_wp_additional_image_sizes[$s]['width'] ) ? intval( $_wp_additional_image_sizes[$s]['width'] ) : get_option( "{$s}_size_w" ) ;
324
-
325
- // Set height
326
- $height = isset( $_wp_additional_image_sizes[$s]['height'] ) ? intval( $_wp_additional_image_sizes[$s]['height'] ) : get_option( "{$s}_size_h" ) ;
327
-
328
- //Set crop
329
- $crop = isset( $_wp_additional_image_sizes[$s]['crop'] ) ? $_wp_additional_image_sizes[$s]['crop'] : get_option( "{$s}_crop" ) ;
330
-
331
- if( is_bool( $crop ) || is_numeric( $crop ) || version_compare( '3.9', $wp_version, '<' ) ) {
332
- $crop = ( absint( $crop ) == 0 )? 'false' : 'true' ;
333
- } else {
334
- if( !Sis_Admin_Main::is_crop_position( $crop ) ){
335
- $crop = "false";
336
- } else {
337
- $crop = explode( '_', $crop );
338
- $crop = 'array( "'.$crop[0].'", "'.$crop[1].'")';
339
- }
340
- }
341
- ?>
342
- add_image_size( '<?php echo $s; ?>', '<?php echo $width; ?>', '<?php echo $height; ?>', <?php echo $crop; ?> );<br />
343
- <?php
344
- }
345
-
346
- die();
347
- }
348
-
349
- /**
350
- *
351
- * Get the media list to regenerate
352
- *
353
- * @param : void
354
- * @return oid
355
- */
356
- public static function a_get_list() {
357
- global $wpdb;
358
- // Basic vars
359
- $res = array();
360
- $nonce = isset( $_POST['nonce'] ) ? $_POST['nonce']: '' ;
361
-
362
- // Check the nonce
363
- if( !wp_verify_nonce( $nonce , 'getList' ) ) {
364
- SIS_Admin_Main::displayJson();
365
- }
366
-
367
- if ( isset( $_POST['post_types'] ) && !empty( $_POST['post_types'] ) ) {
368
-
369
- foreach( $_POST['post_types'] as $key => $type ) {
370
- if( !post_type_exists( $type ) ) {
371
- unset( $_POST['post_types'][$key] );
372
- }
373
- }
374
-
375
- if( empty( $_POST['post_types'][$key]) ) {
376
- SIS_Admin_Main::displayJson();
377
- }
378
-
379
- // Get image medias
380
- $whichmimetype = wp_post_mime_type_where( 'image', $wpdb->posts );
381
-
382
- // Get all parent from post type
383
- $attachments = $wpdb->get_var( "SELECT COUNT( ID )
384
- FROM $wpdb->posts
385
- WHERE 1 = 1
386
- AND post_type = 'attachment'
387
- $whichmimetype
388
- AND post_parent IN (
389
- SELECT DISTINCT ID
390
- FROM $wpdb->posts
391
- WHERE post_type IN ('".implode( "', '", $_POST['post_types'] )."')
392
- )" );
393
- // Return the Id's and Title of medias
394
- SIS_Admin_Main::displayJson( array( 'total' => $attachments ) );
395
-
396
- } else {
397
- $attachments = get_children( array(
398
- 'post_type' => 'attachment',
399
- 'post_mime_type' => 'image',
400
- 'numberposts' => -1,
401
- 'post_status' => null,
402
- 'post_parent' => null, // any parent
403
- 'output' => 'ids',
404
- ) );
405
- // Return the Id's and Title of medias
406
- SIS_Admin_Main::displayJson( array( 'total' => count( $attachments ) ) );
407
- }
408
-
409
- }
410
-
411
- /**
412
- * Regenerate the thumbnails ajax action
413
- *
414
- * @return array
415
- * @param void
416
- * @author Nicolas Juen
417
- */
418
- public static function a_thumbnails_rebuild() {
419
- // Get the nonce
420
- $nonce = isset( $_POST['nonce'] ) ? $_POST['nonce']: '' ;
421
- $offset = isset( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 0 ;
422
- $post_types = isset( $_POST['post_types'] ) ? $_POST['post_types'] : 'any' ;
423
- $thumbnails = isset( $_POST['thumbnails'] )? $_POST['thumbnails'] : NULL;
424
-
425
- // Check the nonce
426
- if( !wp_verify_nonce( $nonce , 'regen' ) ) {
427
- SIS_Admin_Main::displayJson( array( 'error' => __( 'Trying to cheat ?', 'simple-image-sizes' ) ) );
428
- }
429
-
430
- if ( $post_types !== 'any' ) {
431
-
432
- foreach( $_POST['post_types'] as $key => $type ) {
433
- if( !post_type_exists( $type ) ) {
434
- unset( $_POST['post_types'][$key] );
435
- }
436
- }
437
-
438
- if( empty( $_POST['post_types'] ) ) {
439
- SIS_Admin_Main::displayJson();
440
- }
441
-
442
- // Get image medias
443
- $whichmimetype = wp_post_mime_type_where( 'image', $wpdb->posts );
444
-
445
- // Get all parent from post type
446
- $attachment = $wpdb->get_var( $wpdb->prepare( "SELECT ID
447
- FROM $wpdb->posts
448
- WHERE 1 = 1
449
- AND post_type = 'attachment'
450
- $whichmimetype
451
- AND post_parent IN (
452
- SELECT DISTINCT ID
453
- FROM $wpdb->posts
454
- WHERE post_type IN ('".implode( "', '", $_POST['post_types'] )."')
455
- )
456
- LIMIT %d,1
457
- ", $offset ) );
458
-
459
- } else {
460
- $attachment = get_posts( array(
461
- 'post_type' => 'attachment',
462
- 'post_mime_type' => 'image',
463
- 'numberposts' => 1,
464
- 'post_status' => 'any',
465
- 'output' => 'object',
466
- 'offset' => $offset
467
- ) );
468
-
469
- $attachment = !empty( $attachment ) ? $attachment[0]->ID : 0 ;
470
- }
471
-
472
- if( empty( $attachment ) ) {
473
- return array(
474
- 'message' => __( 'Regeneration ended', 'simple-image-sizes')
475
- );
476
- }
477
- SIS_Admin_Main::displayJson( SIS_Admin_Main::thumbnail_rebuild( $attachment, $thumbnails ) );
478
- }
479
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ Class SIS_Admin_Media {
4
+
5
+ // Original sizes
6
+ public static $original = array( 'thumbnail', 'medium', 'large' );
7
+
8
+ public function __construct() {
9
+ // Init
10
+
11
+ add_action( 'admin_menu', array( __CLASS__, 'init' ) );
12
+ add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ), 11 );
13
+
14
+ // Add ajax action
15
+ // Option page
16
+ add_action( 'wp_ajax_' . 'sis_get_list', array( __CLASS__, 'a_get_list' ) );
17
+ add_action( 'wp_ajax_' . 'sis_rebuild_images', array( __CLASS__, 'a_thumbnails_rebuild' ) );
18
+ add_action( 'wp_ajax_' . 'sis_get_sizes', array( __CLASS__, 'a_get_sizes' ) );
19
+ add_action( 'wp_ajax_' . 'sis_add_size', array( __CLASS__, 'a_add_size' ) );
20
+ add_action( 'wp_ajax_' . 'sis_remove_size', array( __CLASS__, 'a_remove_size' ) );
21
+
22
+ // Add link in plugins list
23
+ add_filter( 'plugin_action_links', array( __CLASS__, 'add_settings_link' ), 10, 2 );
24
+ }
25
+
26
+ /**
27
+ * Register javascripts and css.
28
+ *
29
+ * @access public
30
+ * @return void
31
+ * @author Nicolas Juen
32
+ */
33
+ public static function enqueue_assets( $hook_suffix = '' ) {
34
+ if ( ! isset( $hook_suffix ) || empty( $hook_suffix ) ) {
35
+ return false;
36
+ }
37
+
38
+ if ( 'options-media.php'!== $hook_suffix ) {
39
+ // Add javascript
40
+ wp_enqueue_script( 'sis_js' );
41
+
42
+ // Add CSS
43
+ wp_enqueue_style( 'sis_css' );
44
+
45
+ // Add underscore template
46
+ add_action( 'admin_footer', array( 'SIS_Admin_Main', 'add_template' ) );
47
+ }
48
+ }
49
+
50
+
51
+ /**
52
+ * Add a link to the setting option page
53
+ *
54
+ * @access public
55
+ *
56
+ * @param array $links
57
+ * @param string $file
58
+ *
59
+ * @return void
60
+ * @author Nicolas Juen
61
+ */
62
+ public static function add_settings_link( $links, $file ) {
63
+
64
+ if ( 'simple-image-sizes/simple_image_sizes.php' !== $file ) {
65
+ return $links;
66
+ }
67
+
68
+ $settings_link = '<a href="' . admin_url( 'options-media.php' ) . '"> ' . __( 'Settings', 'simple-image-sizes' ) . ' </a>';
69
+ array_unshift( $links, $settings_link );
70
+
71
+ return $links;
72
+ }
73
+
74
+ /**
75
+ * Init for the option page
76
+ *
77
+ * @access public
78
+ * @return void
79
+ * @author Nicolas Juen
80
+ */
81
+ public static function init() {
82
+ // Check if admin
83
+ if ( ! is_admin() ) {
84
+ return false;
85
+ }
86
+
87
+ // Get the image sizes
88
+ global $_wp_additional_image_sizes;
89
+ $options = get_option( SIS_OPTION );
90
+
91
+ // Get the sizes and add the settings
92
+ foreach ( get_intermediate_image_sizes() as $s ) {
93
+ // Don't make the original sizes or numeric sizes that appear
94
+ if ( in_array( $s, self::$original ) || is_integer( $s ) ) {
95
+ continue;
96
+ }
97
+
98
+ // Set width
99
+ $width = isset( $_wp_additional_image_sizes[ $s ]['width'] ) ? intval( $_wp_additional_image_sizes[ $s ]['width'] ) : get_option( "{$s}_size_w" );
100
+
101
+ // Set height
102
+ $height = isset( $_wp_additional_image_sizes[ $s ]['height'] ) ? intval( $_wp_additional_image_sizes[ $s ]['height'] ) : get_option( "{$s}_size_h" );
103
+
104
+ //Set crop
105
+ $crop = isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ? intval( $_wp_additional_image_sizes[ $s ]['crop'] ) : get_option( "{$s}_crop" );
106
+
107
+ // Add the setting field for this size
108
+ add_settings_field( 'image_size_' . $s, sprintf( __( '%s size', 'simple-image-sizes' ), $s ), array(
109
+ __CLASS__,
110
+ 'image_sizes'
111
+ ), 'media', 'default', array( 'name' => $s, 'width' => $width, 'height' => $height, 'c' => $crop ) );
112
+ }
113
+
114
+ // Register the setting for media option page
115
+ register_setting( 'media', SIS_OPTION );
116
+
117
+ // Add the button
118
+ add_settings_field( 'add_size_button', __( 'Add a new size', 'simple-image-sizes' ), array(
119
+ __CLASS__,
120
+ 'addSizeButton'
121
+ ), 'media' );
122
+
123
+ // Add php button
124
+ add_settings_field( 'get_php_button', __( 'Get php for theme', 'simple-image-sizes' ), array(
125
+ __CLASS__,
126
+ 'getPhpButton'
127
+ ), 'media' );
128
+
129
+ // Add section for the thumbnail regeneration
130
+ add_settings_section( 'thumbnail_regenerate', __( 'Thumbnail regeneration', 'simple-image-sizes' ), array(
131
+ __CLASS__,
132
+ 'thumbnailRegenerate'
133
+ ), 'media' );
134
+ }
135
+
136
+ /**
137
+ * Display the row of the image size
138
+ *
139
+ * @access public
140
+ *
141
+ * @param mixed $args
142
+ *
143
+ * @return void
144
+ * @author Nicolas Juen
145
+ */
146
+ public static function image_sizes( $args ) {
147
+
148
+ if ( is_integer( $args['name'] ) ) {
149
+ return;
150
+ }
151
+
152
+ // Get the options
153
+ $sizes = (array) get_option( SIS_OPTION, array() );
154
+
155
+ // Get the vars
156
+ $height = isset( $sizes[ $args['name'] ]['h'] ) ? $sizes[ $args['name'] ]['h'] : $args['height'];
157
+ $width = isset( $sizes[ $args['name'] ]['w'] ) ? $sizes[ $args['name'] ]['w'] : $args['width'];
158
+ $crop = isset( $sizes[ $args['name'] ]['c'] ) && ! empty( $sizes[ $args['name'] ]['c'] ) ? $sizes[ $args['name'] ]['c'] : $args['c'];
159
+ $show = isset( $sizes[ $args['name'] ]['s'] ) && ! empty( $sizes[ $args['name'] ]['s'] ) ? '1' : '0';
160
+ $custom = isset( $sizes[ $args['name'] ]['custom'] ) && ! empty( $sizes[ $args['name'] ]['custom'] ) ? '1' : '0';
161
+ $name = isset( $sizes[ $args['name'] ]['n'] ) && ! empty( $sizes[ $args['name'] ]['n'] ) ? esc_html( $sizes[ $args['name'] ]['n'] ) : esc_html( $args['name'] );
162
+ ?>
163
+ <input type="hidden" value="<?php echo esc_attr( $args['name'] ); ?>" name="image_name"/>
164
+ <?php if ( $custom ): ?>
165
+ <input name="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][custom]' ); ?>" type="hidden"
166
+ id="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][custom]' ); ?>" value="1"/>
167
+ <?php else: ?>
168
+ <input name="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][theme]' ); ?>" type="hidden"
169
+ id="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][theme]' ); ?>" value="1"/>
170
+ <?php endif; ?>
171
+ <label class="sis-label" for="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][w]' ); ?>">
172
+ <?php _e( 'Maximum width', 'simple-image-sizes' ); ?>
173
+ <input name="<?php esc_attr_e( 'custom_image_sizes[' . $args['name'] . '][w]' ); ?>" class='w small-text'
174
+ type="number" step='1' min='0'
175
+ id="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][w]' ); ?>"
176
+ base_w='<?php echo esc_attr( $width ); ?>' value="<?php echo esc_attr( $width ); ?>"/>
177
+ </label>
178
+ <label class="sis-label" for="<?php esc_attr_e( 'custom_image_sizes[' . $args['name'] . '][h]' ); ?>">
179
+ <?php _e( 'Maximum height', 'simple-image-sizes' ); ?>
180
+ <input name="<?php esc_attr_e( 'custom_image_sizes[' . $args['name'] . '][h]' ); ?>" class='h small-text'
181
+ type="number" step='1' min='0'
182
+ id="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][h]' ); ?>"
183
+ base_h='<?php echo esc_attr( $height ); ?>' value="<?php echo esc_attr( $height ); ?>"/>
184
+ </label>
185
+ <label class="sis-label" for="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][n]' ); ?>">
186
+ <?php _e( 'Public name', 'simple-image-sizes' ); ?>
187
+ <input name="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][n]' ); ?>" class='n'
188
+ type="text" id="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][n]' ); ?>"
189
+ base_n='<?php echo $name; ?>' value="<?php echo $name ?>"/>
190
+ </label>
191
+ <span class="size_options">
192
+ <label class="c"
193
+ for="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][c]' ); ?>"><?php _e( 'Cropping', 'simple-image-sizes' ); ?></label>
194
+ <select id="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][c]' ); ?>" class="c crop"
195
+ base_c='<?php echo esc_attr( $crop ); ?>'
196
+ name="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][c]' ); ?>">
197
+ <option
198
+ value="0" <?php selected( 0, $crop ); ?>><?php esc_html_e( 'No', 'simple-image-sizes' ); ?></option>
199
+ <option
200
+ value="1" <?php selected( 1, $crop ); ?>><?php esc_html_e( 'Yes', 'simple-image-sizes' ); ?></option>
201
+ <?php foreach ( SIS_Admin_Main::get_available_crop() as $crop_position => $label ): ?>
202
+ <option <?php selected( $crop_position, $crop ); ?>
203
+ value="<?php echo esc_attr( $crop_position ) ?>"><?php echo esc_html( $label ); ?></option>
204
+ <?php endforeach; ?>
205
+ </select>
206
+
207
+ <input type='checkbox'
208
+ id="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][s]' ); ?>" <?php checked( $show, 1 ) ?>
209
+ class="s show" base_s='<?php echo esc_attr( $show ); ?>'
210
+ name="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][s]' ); ?>" value="1"/>
211
+ <label class="s"
212
+ for="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][s]' ); ?>"><?php _e( 'Show in post insertion ?', 'simple-image-sizes' ); ?></label>
213
+ </span>
214
+ <span class="delete_size button-secondary"><?php _e( 'Delete', 'simple-image-sizes' ); ?></span>
215
+ <span class="add_size validate_size button-primary"><?php _e( 'Update', 'simple-image-sizes' ); ?></span>
216
+
217
+ <input type="hidden" class="deleteSize button-primary"
218
+ value='<?php echo wp_create_nonce( 'delete_' . $args['name'] ); ?>'/>
219
+ <?php }
220
+
221
+ /**
222
+ * Add the button to add a size
223
+ *
224
+ * @access public
225
+ * @return void
226
+ * @author Nicolas Juen
227
+ */
228
+ public static function addSizeButton() { ?>
229
+ <input type="button" class="button-secondary action" id="add_size"
230
+ value="<?php esc_attr_e( 'Add a new size of thumbnail', 'simple-image-sizes' ); ?>"/>
231
+ <?php
232
+ }
233
+
234
+ /**
235
+ * Add the button to get the php for th sizes
236
+ *
237
+ * @access public
238
+ * @return void
239
+ * @author Nicolas Juen
240
+ */
241
+ public static function getPhpButton() { ?>
242
+ <input type="button" class="button-secondary action" id="get_php"
243
+ value="<?php esc_attr_e( 'Get the PHP for the theme', 'simple-image-sizes' ); ?>"/>
244
+ <p> <?php _e( 'Copy and paste the code below into your Wordpress theme function file if you wanted to save them and deactivate the plugin.', 'simple-image-sizes' ); ?> </p>
245
+ <code></code>
246
+ <?php
247
+ }
248
+
249
+ /**
250
+ * Display the Table of sizes and post types for regenerating
251
+ *
252
+ * @access public
253
+ * @return void
254
+ * @author Nicolas Juen
255
+ */
256
+ public static function thumbnailRegenerate() {
257
+ if ( is_file( SIS_DIR . '/templates/options-media.php' ) ) {
258
+ include( SIS_DIR . '/templates/options-media.php' );
259
+ } else {
260
+ esc_html_e( 'Admin option-media template missing', 'simple-image-sizes' );
261
+ }
262
+ }
263
+
264
+ /**
265
+ * Add a size by Ajax
266
+ *
267
+ * @access public
268
+ * @return void
269
+ * @author Nicolas Juen
270
+ */
271
+ public static function a_add_size() {
272
+
273
+ // Get the nonce
274
+ $nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';
275
+
276
+ // Get old options
277
+ $sizes = (array) get_option( SIS_OPTION, array() );
278
+ $croppings = SIS_Admin_Main::get_available_crop();
279
+ $croppings[ true ] = '';
280
+ $croppings[ false ] = '';
281
+
282
+ // Check entries
283
+ $name = isset( $_POST['name'] ) ? sanitize_title( $_POST['name'] ) : '';
284
+ $height = ! isset( $_POST['height'] ) ? 0 : absint( $_POST['height'] );
285
+ $width = ! isset( $_POST['width'] ) ? 0 : absint( $_POST['width'] );
286
+ $crop = isset( $_POST['crop'] ) && isset( $croppings[ $_POST['crop'] ] ) ? $_POST['crop'] : false;
287
+ $show = isset( $_POST['show'] ) && $_POST['show'] == 'false' ? false : true;
288
+ $cn = isset( $_POST['customName'] ) && ! empty( $_POST['customName'] ) ? sanitize_text_field( $_POST['customName'] ) : $name;
289
+
290
+ // Check the nonce
291
+ if ( ! wp_verify_nonce( $nonce, 'add_size' ) ) {
292
+ die( 0 );
293
+ }
294
+
295
+ // If no name given do not save
296
+ if ( empty( $name ) ) {
297
+ die( 0 );
298
+ }
299
+
300
+ // Make values
301
+ $values = array( 'custom' => 1, 'w' => $width, 'h' => $height, 'c' => $crop, 's' => $show, 'n' => $cn );
302
+
303
+ // If the size have not changed return 2
304
+ if ( isset( $sizes[ $name ] ) && $sizes[ $name ] === $values ) {
305
+ die( 2 );
306
+ }
307
+
308
+ // Put the new values
309
+ $sizes[ $name ] = $values;
310
+
311
+ // display update result
312
+ echo (int) update_option( 'custom_image_sizes', $sizes );
313
+ die();
314
+ }
315
+
316
+ /**
317
+ * Remove a size by Ajax
318
+ *
319
+ * @access public
320
+ * @return void
321
+ * @author Nicolas Juen
322
+ */
323
+ public static function a_remove_size() {
324
+
325
+ // Get old options
326
+ $sizes = (array) get_option( SIS_OPTION, array() );
327
+
328
+ // Get the nonce and name
329
+ $nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';
330
+ $name = isset( $_POST['name'] ) ? sanitize_title( $_POST['name'] ) : '';
331
+
332
+ // Check the nonce
333
+ if ( ! wp_verify_nonce( $nonce, 'delete_' . $name ) ) {
334
+ die( 0 );
335
+ }
336
+
337
+ // Remove the size
338
+ unset( $sizes[ sanitize_title( $name ) ] );
339
+ unset( $sizes[0] );
340
+
341
+ // Display the results
342
+ echo (int) update_option( SIS_OPTION, $sizes );
343
+ die();
344
+ }
345
+
346
+ /**
347
+ * Display the add_image_size for the registered sizes
348
+ *
349
+ * @access public
350
+ * @return void
351
+ */
352
+ public static function a_get_sizes() {
353
+ global $_wp_additional_image_sizes, $wp_version;
354
+
355
+ foreach ( get_intermediate_image_sizes() as $s ) {
356
+ // Don't make the original sizes
357
+ if ( in_array( $s, self::$original ) ) {
358
+ continue;
359
+ }
360
+
361
+ // Set width
362
+ $width = isset( $_wp_additional_image_sizes[ $s ]['width'] ) ? intval( $_wp_additional_image_sizes[ $s ]['width'] ) : get_option( "{$s}_size_w" );
363
+
364
+ // Set height
365
+ $height = isset( $_wp_additional_image_sizes[ $s ]['height'] ) ? intval( $_wp_additional_image_sizes[ $s ]['height'] ) : get_option( "{$s}_size_h" );
366
+
367
+ //Set crop
368
+ $crop = isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ? $_wp_additional_image_sizes[ $s ]['crop'] : get_option( "{$s}_crop" );
369
+
370
+ if ( is_bool( $crop ) || is_numeric( $crop ) || version_compare( $wp_version, '3.9', '<' ) ) {
371
+ $crop = ( absint( $crop ) == 0 ) ? 'false' : 'true';
372
+ } else {
373
+ if ( ! Sis_Admin_Main::is_crop_position( implode( '_', $crop ) ) ) {
374
+ $crop = "false";
375
+ } else {
376
+ $crop = 'array( "' . $crop[0] . '", "' . $crop[1] . '")';
377
+ }
378
+ }
379
+ ?>
380
+ add_image_size( '<?php echo $s; ?>', '<?php echo $width; ?>', '<?php echo $height; ?>', <?php echo $crop; ?> );
381
+ <br/>
382
+ <?php
383
+ }
384
+
385
+ die();
386
+ }
387
+
388
+ /**
389
+ *
390
+ * Get the media list to regenerate
391
+ *
392
+ * @param : void
393
+ *
394
+ * @return void
395
+ */
396
+ public static function a_get_list() {
397
+ /**
398
+ * @var $wpdb wpdb
399
+ */
400
+ global $wpdb;
401
+
402
+ // Basic vars
403
+ $res = array();
404
+ $nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';
405
+
406
+ // Check the nonce
407
+ if ( ! wp_verify_nonce( $nonce, 'getList' ) ) {
408
+ SIS_Admin_Main::displayJson();
409
+ }
410
+
411
+ if ( isset( $_POST['post_types'] ) && ! empty( $_POST['post_types'] ) ) {
412
+
413
+ foreach ( $_POST['post_types'] as $key => $type ) {
414
+ if ( ! post_type_exists( $type ) ) {
415
+ unset( $_POST['post_types'][ $key ] );
416
+ }
417
+ }
418
+
419
+ if ( empty( $_POST['post_types'][ $key ] ) ) {
420
+ SIS_Admin_Main::displayJson();
421
+ }
422
+
423
+ // Get image medias
424
+ $whichmimetype = wp_post_mime_type_where( 'image', $wpdb->posts );
425
+
426
+ // Get all parent from post type
427
+ $attachments = $wpdb->get_var( "SELECT COUNT( ID )
428
+ FROM $wpdb->posts
429
+ WHERE 1 = 1
430
+ AND post_type = 'attachment'
431
+ $whichmimetype
432
+ AND post_parent IN (
433
+ SELECT DISTINCT ID
434
+ FROM $wpdb->posts
435
+ WHERE post_type IN ('" . implode( "', '", $_POST['post_types'] ) . "')
436
+ )" );
437
+ // Return the Id's and Title of medias
438
+ SIS_Admin_Main::displayJson( array( 'total' => $attachments ) );
439
+
440
+ } else {
441
+ $attachments = get_children( array(
442
+ 'post_type' => 'attachment',
443
+ 'post_mime_type' => 'image',
444
+ 'numberposts' => - 1,
445
+ 'post_status' => null,
446
+ 'post_parent' => null, // any parent
447
+ 'output' => 'ids',
448
+ ) );
449
+ // Return the Id's and Title of medias
450
+ SIS_Admin_Main::displayJson( array( 'total' => count( $attachments ) ) );
451
+ }
452
+
453
+ }
454
+
455
+ /**
456
+ * Regenerate the thumbnails ajax action
457
+ *
458
+ * @return array
459
+ *
460
+ * @param void
461
+ *
462
+ * @author Nicolas Juen
463
+ */
464
+ public static function a_thumbnails_rebuild() {
465
+ // Get the nonce
466
+ $nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';
467
+ $offset = isset( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 0;
468
+ $post_types = isset( $_POST['post_types'] ) ? $_POST['post_types'] : 'any';
469
+ $thumbnails = isset( $_POST['thumbnails'] ) ? $_POST['thumbnails'] : null;
470
+
471
+ // Check the nonce
472
+ if ( ! wp_verify_nonce( $nonce, 'regen' ) ) {
473
+ SIS_Admin_Main::displayJson( array( 'error' => __( 'Trying to cheat ?', 'simple-image-sizes' ) ) );
474
+ }
475
+
476
+ if ('any' !== $post_types ) {
477
+
478
+ foreach ( $_POST['post_types'] as $key => $type ) {
479
+ if ( ! post_type_exists( $type ) ) {
480
+ unset( $_POST['post_types'][ $key ] );
481
+ }
482
+ }
483
+
484
+ if ( empty( $_POST['post_types'] ) ) {
485
+ SIS_Admin_Main::displayJson();
486
+ }
487
+
488
+ // Get image medias
489
+ $whichmimetype = wp_post_mime_type_where( 'image', $wpdb->posts );
490
+
491
+ // Get all parent from post type
492
+ $attachment = $wpdb->get_var( $wpdb->prepare( "SELECT ID
493
+ FROM $wpdb->posts
494
+ WHERE 1 = 1
495
+ AND post_type = 'attachment'
496
+ $whichmimetype
497
+ AND post_parent IN (
498
+ SELECT DISTINCT ID
499
+ FROM $wpdb->posts
500
+ WHERE post_type IN ('" . implode( "', '", $_POST['post_types'] ) . "')
501
+ )
502
+ LIMIT %d,1
503
+ ", $offset ) );
504
+
505
+ } else {
506
+ $attachment = get_posts( array(
507
+ 'post_type' => 'attachment',
508
+ 'post_mime_type' => 'image',
509
+ 'numberposts' => 1,
510
+ 'post_status' => 'any',
511
+ 'output' => 'object',
512
+ 'offset' => $offset,
513
+ ) );
514
+
515
+ $attachment = ! empty( $attachment ) ? $attachment[0]->ID : 0;
516
+ }
517
+
518
+ if ( empty( $attachment ) ) {
519
+ return array(
520
+ 'message' => __( 'Regeneration ended', 'simple-image-sizes' )
521
+ );
522
+ }
523
+ SIS_Admin_Main::displayJson( SIS_Admin_Main::thumbnail_rebuild( $attachment, $thumbnails ) );
524
+ }
525
+ }
classes/admin/post.php CHANGED
@@ -1,252 +1,266 @@
1
- <?php
2
- Class SIS_Admin_Post {
3
- public function __construct(){
4
- // Add image sizes in the form, check if 3.3 is installed or not
5
- if( !function_exists( 'is_main_query' ) ) {
6
- add_filter( 'attachment_fields_to_edit', array( __CLASS__, 'sizes_in_form' ), 11, 2 ); // Add our sizes to media forms
7
- } else {
8
- add_filter( 'image_size_names_choose', array( __CLASS__, 'add_thumbnail_name' ) );
9
- }
10
-
11
- add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ), 11 );
12
-
13
- // Rebuilt the image
14
- add_action( 'wp_ajax_'.'sis_rebuild_image', array( __CLASS__, 'a_thumbnail_rebuild' ) );
15
-
16
- // Add action in media row quick actions
17
- add_filter( 'media_row_actions', array( __CLASS__, 'add_actions_list' ), 10, 2 );
18
-
19
- // Add filter for the Media single
20
- add_filter( 'attachment_fields_to_edit', array( __CLASS__, 'add_field_regenerate' ), 9, 2 );
21
- }
22
-
23
- /**
24
- * Register javascripts and css.
25
- *
26
- * @access public
27
- * @return void
28
- * @author Nicolas Juen
29
- */
30
- public static function enqueue_assets( $hook_suffix = '' ) {
31
- if( !isset( $hook_suffix ) || empty( $hook_suffix ) ) {
32
- return false;
33
- }
34
-
35
- if( $hook_suffix == 'upload.php' || ( $hook_suffix == 'post.php' && isset( $_GET['post'] ) && isset( $_GET['action'] ) && $_GET['action'] == 'edit' ) ) {
36
- // Add javascript
37
- wp_enqueue_script( 'sis_js_attachments' );
38
-
39
- // Add underscore template
40
- add_action( 'admin_footer', array( 'SIS_Admin_Main', 'add_template' ) );
41
- }
42
- }
43
-
44
- /**
45
- * Rebuild the image
46
- *
47
- * @access public
48
- * @return void
49
- * @author Nicolas Juen
50
- */
51
- public static function a_thumbnail_rebuild() {
52
- global $wpdb;
53
-
54
- // Get the nonce
55
- $nonce = isset( $_POST['nonce'] ) ? $_POST['nonce']: '' ;
56
-
57
- // Time a the begining
58
- timer_start();
59
-
60
- // Get the thumbnails
61
- $thumbnails = isset( $_POST['thumbnails'] )? $_POST['thumbnails'] : NULL;
62
-
63
- // Check the nonce
64
- if( !wp_verify_nonce( $nonce , 'regen' ) ) {
65
- SIS_Admin_Main::displayJson( array( 'error' => _e( 'Trying to cheat ?', 'simple-image-sizes' ) ) );
66
- }
67
-
68
- // Get the id
69
- $id = isset( $_POST["id"] ) ? $_POST["id"] : 0 ;
70
- SIS_Admin_Main::displayJson( SIS_Admin_Main::thumbnail_rebuild( $id, $thumbnails ) );
71
- }
72
-
73
- /**
74
- * Add the custom sizes to the image sizes in article edition
75
- *
76
- * @access public
77
- * @param array $form_fields
78
- * @param object $post
79
- * @return void
80
- * @author Nicolas Juen
81
- * @author Additional Image Sizes (zui)
82
- */
83
- public static function sizes_in_form( $form_fields, $post ) {
84
- // Protect from being view in Media editor where there are no sizes
85
- if ( !isset( $form_fields['image-size'] ) ) {
86
- return $form_fields;
87
- }
88
-
89
- $out = NULL;
90
- $size_names = array();
91
- $sizes_custom = get_option( SIS_OPTION, array() );
92
-
93
- if ( is_array( $sizes_custom ) ) {
94
- foreach( $sizes_custom as $key => $value ) {
95
- if( isset( $value['s'] ) && $value['s'] == 1 ) {
96
- $size_names[$key] = self::_get_thumbnail_name( $key );;
97
- }
98
- }
99
- }
100
- foreach ( $size_names as $size => $label ) {
101
- $downsize = image_downsize( $post->ID, $size );
102
-
103
- // is this size selectable?
104
- $enabled = ( $downsize[3] || 'full' == $size );
105
- $css_id = "image-size-{$size}-{$post->ID}";
106
-
107
- // We must do a clumsy search of the existing html to determine is something has been checked yet
108
- if ( FALSE === strpos( 'checked="checked"', $form_fields['image-size']['html'] ) ) {
109
- if ( empty($check) )
110
- $check = get_user_setting( 'imgsize' ); // See if they checked a custom size last time
111
-
112
- $checked = '';
113
-
114
- // if this size is the default but that's not available, don't select it
115
- if ( $size == $check || str_replace( " ", "", $size ) == $check ) {
116
- if ( $enabled )
117
- $checked = " checked='checked'";
118
- else
119
- $check = '';
120
- } elseif ( !$check && $enabled && 'thumbnail' != $size ) {
121
- // if $check is not enabled, default to the first available size that's bigger than a thumbnail
122
- $check = $size;
123
- $checked = " checked='checked'";
124
- }
125
- }
126
- $html = "<div class='image-size-item' style='min-height: 50px; margin-top: 18px;'><input type='radio' " . disabled( $enabled, false, false ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />";
127
-
128
- $html .= "<label for='{$css_id}'>$label</label>";
129
- // only show the dimensions if that choice is available
130
- if ( $enabled )
131
- $html .= " <label for='{$css_id}' class='help'>" . sprintf( "(%d&nbsp;&times;&nbsp;%d)", $downsize[1], $downsize[2] ). "</label>";
132
-
133
- $html .= '</div>';
134
-
135
- $out .= $html;
136
- }
137
- $form_fields['image-size']['html'] .= $out;
138
-
139
- return $form_fields;
140
- }
141
-
142
- /**
143
- * Add the thumbnail name in the post insertion, based on new WP filter
144
- *
145
- * @access public
146
- * @param array $sizes
147
- * @return array
148
- * @since 2.3
149
- * @author Nicolas Juen
150
- * @author radeno based on this post : http://www.wpmayor.com/wordpress-hacks/how-to-add-custom-image-sizes-to-wordpress-uploader/
151
- */
152
- public static function add_thumbnail_name($sizes) {
153
- // Get options
154
- $sizes_custom = get_option( SIS_OPTION, array() );
155
- // init size array
156
- $addsizes = array();
157
-
158
- // check there is custom sizes
159
- if ( is_array( $sizes_custom ) && !empty( $sizes_custom ) ) {
160
- foreach( $sizes_custom as $key => $value ) {
161
- // If we show this size in the admin
162
- if( isset( $value['s'] ) && $value['s'] == 1 ) {
163
- $addsizes[$key] = self::_get_thumbnail_name( $key );
164
- }
165
- }
166
- }
167
-
168
- // Merge the two array
169
- $newsizes = array_merge($sizes, $addsizes);
170
-
171
- // Add new size
172
- return $newsizes;
173
- }
174
-
175
- /**
176
- * Get a thumbnail name from its slug
177
- *
178
- * @access private
179
- * @param string $thumbnailSlug : the slug of the thumbnail
180
- * @return array
181
- * @since 2.3
182
- * @author Nicolas Juen
183
- */
184
- private static function _get_thumbnail_name( $thumbnailSlug = '' ) {
185
-
186
- // get the options
187
- $sizes_custom = get_option( SIS_OPTION );
188
-
189
- if( !isset( $sizes_custom[$thumbnailSlug] ) ) {
190
- // return slug if not found
191
- return $thumbnailSlug;
192
- }
193
-
194
- // If the name exists return it, slug by default
195
- if( isset( $sizes_custom[$thumbnailSlug]['n'] ) && !empty( $sizes_custom[$thumbnailSlug]['n'] ) ) {
196
- return $sizes_custom[$thumbnailSlug]['n'];
197
- }
198
-
199
- return $thumbnailSlug;
200
- }
201
-
202
-
203
- /**
204
- * Add action in media row
205
- *
206
- * @since 2.2
207
- * @access public
208
- * @return $actions : array of actions and content to display
209
- * @author Nicolas Juen
210
- */
211
- public static function add_actions_list( $actions, $object ) {
212
- if( !wp_attachment_is_image( $object->ID ) ) {
213
- return $actions;
214
- }
215
- // Add action for regeneration
216
- $actions['sis-regenerate'] = "<a href='#' data-id='".$object->ID."' class='sis-regenerate-one'>".__( 'Regenerate thumbnails', 'simple-image-sizes' )."</a>";
217
-
218
- // Return actions
219
- return $actions;
220
- }
221
-
222
-
223
- /**
224
- * Get a thumbnail name from its slug
225
- *
226
- * @access public
227
- * @param array $fields : the fields of the media
228
- * @param object $post : the post object
229
- * @return array
230
- * @since 2.3.1
231
- * @author Nicolas Juen
232
- */
233
- public static function add_field_regenerate( $fields, $post ) {
234
- // Check this is an image
235
- if( strpos( $post->post_mime_type, 'image' ) === false ) {
236
- return $fields;
237
- }
238
-
239
- $fields['sis-regenerate'] = array(
240
- 'label' => __( 'Regenerate Thumbnails', 'simple-image-sizes' ),
241
- 'input' => 'html',
242
- 'html' => '
243
- <input type="button" data-id="'.$post->ID.'" class="button title sis-regenerate-one" value="'.__( 'Regenerate Thumbnails', 'simple-image-sizes' ).'" />
244
- <span class="spinner"></span>
245
- <span class="title"><em></em></span>
246
- <input type="hidden" class="regen" value="'.wp_create_nonce( 'regen' ).'" />',
247
- 'show_in_edit' => true,
248
- 'show_in_modal' => false,
249
- );
250
- return $fields;
251
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  }
1
+ <?php
2
+
3
+ Class SIS_Admin_Post {
4
+ public function __construct() {
5
+ // Add image sizes in the form, check if 3.3 is installed or not
6
+ if ( ! function_exists( 'is_main_query' ) ) {
7
+ add_filter( 'attachment_fields_to_edit', array(
8
+ __CLASS__,
9
+ 'sizes_in_form'
10
+ ), 11, 2 ); // Add our sizes to media forms
11
+ } else {
12
+ add_filter( 'image_size_names_choose', array( __CLASS__, 'add_thumbnail_name' ) );
13
+ }
14
+
15
+ add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ), 11 );
16
+
17
+ // Rebuilt the image
18
+ add_action( 'wp_ajax_' . 'sis_rebuild_image', array( __CLASS__, 'a_thumbnail_rebuild' ) );
19
+
20
+ // Add action in media row quick actions
21
+ add_filter( 'media_row_actions', array( __CLASS__, 'add_actions_list' ), 10, 2 );
22
+
23
+ // Add filter for the Media single
24
+ add_filter( 'attachment_fields_to_edit', array( __CLASS__, 'add_field_regenerate' ), 9, 2 );
25
+ }
26
+
27
+ /**
28
+ * Register javascripts and css.
29
+ *
30
+ * @access public
31
+ * @return void
32
+ * @author Nicolas Juen
33
+ */
34
+ public static function enqueue_assets( $hook_suffix = '' ) {
35
+ if ( ! isset( $hook_suffix ) || empty( $hook_suffix ) ) {
36
+ return false;
37
+ }
38
+
39
+ if ( 'upload.php' !== $hook_suffix || ( 'post.php' !== $hook_suffix && isset( $_GET['post'] ) && isset( $_GET['action'] ) && 'edit' == $_GET['action'] ) ) {
40
+ // Add javascript
41
+ wp_enqueue_script( 'sis_js_attachments' );
42
+
43
+ // Add underscore template
44
+ add_action( 'admin_footer', array( 'SIS_Admin_Main', 'add_template' ) );
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Rebuild the image
50
+ *
51
+ * @access public
52
+ * @return void
53
+ * @author Nicolas Juen
54
+ */
55
+ public static function a_thumbnail_rebuild() {
56
+ // Get the nonce
57
+ $nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';
58
+
59
+ // Time a the begining
60
+ timer_start();
61
+
62
+ // Get the thumbnails
63
+ $thumbnails = isset( $_POST['thumbnails'] ) ? $_POST['thumbnails'] : null;
64
+
65
+ // Check the nonce
66
+ if ( ! wp_verify_nonce( $nonce, 'regen' ) ) {
67
+ SIS_Admin_Main::displayJson( array( 'error' => _e( 'Trying to cheat ?', 'simple-image-sizes' ) ) );
68
+ }
69
+
70
+ // Get the id
71
+ $id = isset( $_POST['id'] ) ? $_POST['id'] : 0;
72
+ SIS_Admin_Main::displayJson( SIS_Admin_Main::thumbnail_rebuild( $id, $thumbnails ) );
73
+ }
74
+
75
+ /**
76
+ * Add the custom sizes to the image sizes in article edition
77
+ *
78
+ * @access public
79
+ *
80
+ * @param array $form_fields
81
+ * @param object $post
82
+ *
83
+ * @return string
84
+ * @author Nicolas Juen
85
+ * @author Additional Image Sizes (zui)
86
+ */
87
+ public static function sizes_in_form( $form_fields, $post ) {
88
+ // Protect from being view in Media editor where there are no sizes
89
+ if ( ! isset( $form_fields['image-size'] ) ) {
90
+ return $form_fields;
91
+ }
92
+
93
+ $out = null;
94
+ $size_names = array();
95
+ $sizes_custom = get_option( SIS_OPTION, array() );
96
+
97
+ if ( is_array( $sizes_custom ) ) {
98
+ foreach ( $sizes_custom as $key => $value ) {
99
+ if ( isset( $value['s'] ) && $value['s'] == 1 ) {
100
+ $size_names[ $key ] = self::_get_thumbnail_name( $key );;
101
+ }
102
+ }
103
+ }
104
+ foreach ( $size_names as $size => $label ) {
105
+ $downsize = image_downsize( $post->ID, $size );
106
+
107
+ // is this size selectable?
108
+ $enabled = ( $downsize[3] || 'full' == $size );
109
+ $css_id = "image-size-{$size}-{$post->ID}";
110
+
111
+ // We must do a clumsy search of the existing html to determine is something has been checked yet
112
+ if ( false === strpos( 'checked="checked"', $form_fields['image-size']['html'] ) ) {
113
+ if ( empty( $check ) ) {
114
+ $check = get_user_setting( 'imgsize' );
115
+ } // See if they checked a custom size last time
116
+
117
+ $checked = '';
118
+
119
+ // if this size is the default but that's not available, don't select it
120
+ if ( $size == $check || str_replace( " ", "", $size ) == $check ) {
121
+ if ( $enabled ) {
122
+ $checked = " checked='checked'";
123
+ } else {
124
+ $check = '';
125
+ }
126
+ } elseif ( ! $check && $enabled && 'thumbnail' != $size ) {
127
+ // if $check is not enabled, default to the first available size that's bigger than a thumbnail
128
+ $check = $size;
129
+ $checked = " checked='checked'";
130
+ }
131
+ }
132
+ $html = "<div class='image-size-item' style='min-height: 50px; margin-top: 18px;'><input type='radio' " . disabled( $enabled, false, false ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />";
133
+
134
+ $html .= "<label for='{$css_id}'>$label</label>";
135
+ // only show the dimensions if that choice is available
136
+ if ( $enabled ) {
137
+ $html .= " <label for='{$css_id}' class='help'>" . sprintf( "(%d&nbsp;&times;&nbsp;%d)", $downsize[1], $downsize[2] ) . "</label>";
138
+ }
139
+
140
+ $html .= '</div>';
141
+
142
+ $out .= $html;
143
+ }
144
+ $form_fields['image-size']['html'] .= $out;
145
+
146
+ return $form_fields;
147
+ }
148
+
149
+ /**
150
+ * Add the thumbnail name in the post insertion, based on new WP filter
151
+ *
152
+ * @access public
153
+ *
154
+ * @param array $sizes
155
+ *
156
+ * @return array
157
+ * @since 2.3
158
+ * @author Nicolas Juen
159
+ * @author radeno based on this post : http://www.wpmayor.com/wordpress-hacks/how-to-add-custom-image-sizes-to-wordpress-uploader/
160
+ */
161
+ public static function add_thumbnail_name( $sizes ) {
162
+ // Get options
163
+ $sizes_custom = get_option( SIS_OPTION, array() );
164
+ // init size array
165
+ $addsizes = array();
166
+
167
+ // check there is custom sizes
168
+ if ( is_array( $sizes_custom ) && ! empty( $sizes_custom ) ) {
169
+ foreach ( $sizes_custom as $key => $value ) {
170
+ // If we show this size in the admin
171
+ if ( isset( $value['s'] ) && 1 == $value['s'] ) {
172
+ $addsizes[ $key ] = self::_get_thumbnail_name( $key );
173
+ }
174
+ }
175
+ }
176
+
177
+ // Merge the two array
178
+ $newsizes = array_merge( $sizes, $addsizes );
179
+
180
+ // Add new size
181
+ return $newsizes;
182
+ }
183
+
184
+ /**
185
+ * Get a thumbnail name from its slug
186
+ *
187
+ * @access private
188
+ *
189
+ * @param string $thumbnailSlug : the slug of the thumbnail
190
+ *
191
+ * @return array
192
+ * @since 2.3
193
+ * @author Nicolas Juen
194
+ */
195
+ private static function _get_thumbnail_name( $thumbnailSlug = '' ) {
196
+
197
+ // get the options
198
+ $sizes_custom = get_option( SIS_OPTION );
199
+
200
+ if ( ! isset( $sizes_custom[ $thumbnailSlug ] ) ) {
201
+ // return slug if not found
202
+ return $thumbnailSlug;
203
+ }
204
+
205
+ // If the name exists return it, slug by default
206
+ if ( isset( $sizes_custom[ $thumbnailSlug ]['n'] ) && ! empty( $sizes_custom[ $thumbnailSlug ]['n'] ) ) {
207
+ return $sizes_custom[ $thumbnailSlug ]['n'];
208
+ }
209
+
210
+ return $thumbnailSlug;
211
+ }
212
+
213
+
214
+ /**
215
+ * Add action in media row
216
+ *
217
+ * @since 2.2
218
+ * @access public
219
+ * @return $actions : array of actions and content to display
220
+ * @author Nicolas Juen
221
+ */
222
+ public static function add_actions_list( $actions, $object ) {
223
+ if ( ! wp_attachment_is_image( $object->ID ) ) {
224
+ return $actions;
225
+ }
226
+ // Add action for regeneration
227
+ $actions['sis-regenerate'] = "<a href='#' data-id='" . $object->ID . "' class='sis-regenerate-one'>" . __( 'Regenerate thumbnails', 'simple-image-sizes' ) . "</a>";
228
+
229
+ // Return actions
230
+ return $actions;
231
+ }
232
+
233
+
234
+ /**
235
+ * Get a thumbnail name from its slug
236
+ *
237
+ * @access public
238
+ *
239
+ * @param array $fields : the fields of the media
240
+ * @param object $post : the post object
241
+ *
242
+ * @return array
243
+ * @since 2.3.1
244
+ * @author Nicolas Juen
245
+ */
246
+ public static function add_field_regenerate( $fields, $post ) {
247
+ // Check this is an image
248
+ if ( false === strpos( $post->post_mime_type, 'image' ) ) {
249
+ return $fields;
250
+ }
251
+
252
+ $fields['sis-regenerate'] = array(
253
+ 'label' => __( 'Regenerate Thumbnails', 'simple-image-sizes' ),
254
+ 'input' => 'html',
255
+ 'html' => '
256
+ <input type="button" data-id="' . $post->ID . '" class="button title sis-regenerate-one" value="' . __( 'Regenerate Thumbnails', 'simple-image-sizes' ) . '" />
257
+ <span class="spinner"></span>
258
+ <span class="title"><em></em></span>
259
+ <input type="hidden" class="regen" value="' . wp_create_nonce( 'regen' ) . '" />',
260
+ 'show_in_edit' => true,
261
+ 'show_in_modal' => false,
262
+ );
263
+
264
+ return $fields;
265
+ }
266
  }
classes/main.php CHANGED
@@ -1,52 +1,61 @@
1
- <?php
2
- Class SIS_Client {
3
-
4
- // Set the original
5
- var $original = array( 'thumbnail', 'medium', 'large' );
6
-
7
- function __construct() {
8
-
9
- // Make new image sizes
10
- add_action ( 'init', array( __CLASS__, 'init' ), 1 );
11
-
12
- // Add translation
13
- add_action ( 'init', array( __CLASS__, 'init_translation' ), 2 );
14
- }
15
-
16
- /**
17
- * Override the images by the plugin images
18
- *
19
- * @access public
20
- * @return void
21
- * @author Nicolas Juen
22
- */
23
- public static function init() {
24
- // Get inital options
25
- $sizes = get_option( SIS_OPTION, array() );
26
-
27
- // Return flase if empty
28
- if( empty( $sizes ) || !is_array( $sizes ) ) {
29
- return false;
30
- }
31
-
32
- // Set the new sizes
33
- foreach( $sizes as $name => $size ) {
34
- if( empty( $size ) || !isset( $size['w'] ) || !isset( $size['h'] ) ) {
35
- continue;
36
- }
37
- // Add the images sizes
38
- add_image_size( $name, $size['w'], $size['h'], ( isset( $size['c'] ) && !empty( $size['c'] ) )? $size['c'] : 0 );
39
- }
40
- }
41
-
42
- /**
43
- * Load the plugin text domain
44
- *
45
- * @param void
46
- * @return void
47
- * @author Nicolas Juen
48
- */
49
- public static function init_translation() {
50
- load_plugin_textdomain ( 'simple-image-sizes', false, basename( rtrim( SIS_DIR, '/' ) ) . '/languages' );
51
- }
 
 
 
 
 
 
 
 
 
52
  }
1
+ <?php
2
+
3
+ Class SIS_Client {
4
+
5
+ // Set the original
6
+ var $original = array( 'thumbnail', 'medium', 'large' );
7
+
8
+ function __construct() {
9
+
10
+ // Make new image sizes
11
+ add_action( 'init', array( __CLASS__, 'init' ), 1 );
12
+
13
+ // Add translation
14
+ add_action( 'init', array( __CLASS__, 'init_translation' ), 2 );
15
+ }
16
+
17
+ /**
18
+ * Override the images by the plugin images
19
+ *
20
+ * @access public
21
+ * @return void
22
+ * @author Nicolas Juen
23
+ */
24
+ public static function init() {
25
+ // Get inital options
26
+ $sizes = get_option( SIS_OPTION, array() );
27
+
28
+ // Return false if empty
29
+ if ( empty( $sizes ) || ! is_array( $sizes ) ) {
30
+ return;
31
+ }
32
+
33
+ // Set the new sizes
34
+ foreach ( $sizes as $name => $size ) {
35
+ if ( empty( $size ) || ! isset( $size['w'] ) || ! isset( $size['h'] ) ) {
36
+ continue;
37
+ }
38
+
39
+ $crop = ( isset( $size['c'] ) && ! empty( $size['c'] ) ) ? $size['c'] : false;
40
+
41
+ if ( is_string( $crop ) ) {
42
+ $crop = explode( '_', $crop );
43
+ }
44
+
45
+ // Add the images sizes
46
+ add_image_size( $name, $size['w'], $size['h'], $crop );
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Load the plugin text domain
52
+ *
53
+ * @param void
54
+ *
55
+ * @return void
56
+ * @author Nicolas Juen
57
+ */
58
+ public static function init_translation() {
59
+ load_plugin_textdomain( 'simple-image-sizes', false, basename( rtrim( SIS_DIR, '/' ) ) . '/languages' );
60
+ }
61
  }
readme.txt CHANGED
@@ -1,178 +1,180 @@
1
- === Simple Image Sizes ===
2
- Contributors: Rahe
3
- Donate link: http://www.beapi.fr/donate/
4
- Tags: images, image, custom sizes, custom images, thumbnail regenerate, thumbnail, regenerate
5
- Requires at least: 3.5
6
- Tested up to: 4.1
7
- Stable tag: 3.0.3
8
- License: GPLv2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
-
11
- == Description ==
12
-
13
- This plugin allow create custom image sizes for your site. Override your theme sizes directly on the media option page.
14
- You can regenerate all the sizes you have just created and choose which one you wanted to regenerate.
15
- You can now get all the code to copy and paste to your function theme file.
16
- Now you can use the generated sizes directly into your posts and insert images at the right size !
17
- Now you choose if you want display the size in the post insert image.
18
- Now you can regenerate the images one by one in the 'Medias' general pane.
19
- Now you can regenerate the images by bulk action in the 'Medias' general pane.
20
- Now you can regenerate the image sizes on single attachment edit page.
21
-
22
- I have added a timer so when you regeneration your thumbnails, you can know approximately when the regeneration will be ended.
23
- I have improved the php and javascript, you can know if the image have been regenerated or not or if there is an error and which one.
24
-
25
- Contribute on https://github.com/Rahe/Simple-image-sizes
26
-
27
- == Installation ==
28
- **PHP5 Required.**
29
-
30
- 1. Download, unzip and upload to your WordPress plugins directory
31
- 2. Activate the plugin within you WordPress Administration Backend
32
- 3. Go to Settings > Medias
33
- 4. Configure your new image sizes and regenerate the thumbnails !
34
-
35
- == Frequently Asked Questions ==
36
-
37
- = Where can I add image sizes ? =
38
- Go to Settings -> Media then you can add a image size. You have to add a unique custom name without any spaces or special chars.
39
- The best is to use something like my-custom-size.
40
- Then you have several fields for configuring the image size, the widht, the height, cropping.
41
- And then you can choose if the image is displayed on the media insertion or not ( this will be displayed on the dropdown list ).
42
-
43
-
44
- == Screenshots ==
45
-
46
- 1. Settings page
47
- 2. Get PHP for the theme
48
- 3. Choose the sizes to regenerate and regenerate them
49
-
50
- == Changelog ==
51
- * 3.0.3
52
- * Add Hebrew translations thanks to Atar4U
53
- * 3.0.2
54
- * Fix version check for the image crop positions
55
- * 3.0.1
56
- * Change the template render method for non apache webservers : https://wordpress.org/support/topic/fatal-error-1190?replies=6
57
- * Remove ambigious ids for the css bugging WooCommerce : https://wordpress.org/support/topic/bad-css-style-administration and
58
- * Right code for counting the elements on backoffice : https://github.com/Rahe/Simple-image-sizes/issues/20
59
- * Fix bug on regenation and _e instead of __ : https://plugins.trac.wordpress.org/ticket/2259
60
- * 3.0
61
- * Revamping all the code, change classes and structure
62
- * Use grunt for compiling files
63
- * Handle the 3.9 new cropping position
64
- * Remove aristo css
65
- * Use UI from WordPress
66
- * 2.4.3
67
- * Remove some php notices
68
- * Remove notice when wrong image size
69
- * 2.4.2
70
- * Selective regeneration fix by g100g on http://wordpress.org/support/topic/regenerating-fix
71
- * 2.4.1
72
- * Remove function not working on admin file
73
- * 2.4
74
- * Made for 3.5 and up
75
- * Refactoring PHP/Javascript code
76
- * Javascript improvements
77
- * Remove useless UI
78
- * UI improvements
79
- * Global PHP performance improvements
80
- * 2.3.1
81
- * Add Ajax bulk actions on medias list
82
- * Add ajax thumbnail rebuild on single media
83
- * 2.3
84
- * Add the custom size name in the attachment insertion
85
- * Exclude post_type wich do not support the post-thumbnail feature
86
- * 2.2.5
87
- * Debug the regeneration buggy !
88
- * Complete the french translation
89
- * Security update for single regeneration, include the nonce this time :)
90
- * 2.2.4
91
- * Add security nonces for every actions
92
- * Put the messages at the begining of the log
93
- * Add a select all checkbox Thank to cocola
94
- * Add the german translation thanks to glueckpress
95
- * Remove notice tnahks to christianwach
96
- * Remove useless and buggy for my scripting pointers
97
- * 2.2.3
98
- * Do not force network usage
99
- * 2.2.2
100
- * Debug js for the buttons
101
- * Remove console.log calls
102
- * 2.2.1
103
- * Use buttonset for the checkboxes
104
- * Add Pointer for WordPress 3.3
105
- * Fix translation in French
106
- * Some medias queries for small windows ( change size of buttons and alignment )
107
- * 2.2
108
- * Add new version of css aristo
109
- * Add some icons
110
- * Display button for saving changes only when changes detected
111
- * Display message when a size is modified but not saved and wanted to regenerate
112
- * Debug functionnality when regenerating only some sizes, metas not crushed
113
- * Add solo regenerating
114
- * Remove displaying for theme/not theme sizes
115
- * Use WordPress class for small inputs
116
- * 2.1
117
- * Add javascript timer
118
- * Improve javascript and more IE friendly
119
- * You can now choose if you want to display the image sizes in image insertion or not
120
- * Handle errors and messages
121
- * Remove some css useless rules
122
- * Fix bad translation for french
123
- * Remove accents in image sizes
124
- * Do not update size properties if there is an ajax query for an another size name
125
- * 2.0.3
126
- * Resolve issue with theme sizes witch by default are displayed as not cropped. Thanks to momo360modena for the bug signalment.
127
- * 2.0.2
128
- * Remove debug on php for javascript
129
- * Resolve issue with the different versions on jquery ( like in WP3.2 ) with attr return for checked components
130
- * 2.0.1
131
- * Resolve javascript issue when clicking on delete button
132
- * Resolve issue of never unchecking crop button
133
- * 2.0
134
- * Code refactoring
135
- * Update translations
136
- * Ajaxification of the process
137
- * Deleting by Ajax
138
- * Updating by Ajax
139
- * Adding by Ajax
140
- * Change UI
141
- * Change theme
142
- * Handle ajax errors
143
- * Handle not modified sizes, cropped
144
- * Handle same names
145
- * Sanitize the names
146
- * Customize jQuery ui
147
- * Customize jQuery ui theme
148
- * HTML5 Elements
149
- * CSS3 Animations
150
- * 1.0.6
151
- * Minify javascript names
152
- * Change progressbar style
153
- * Add animations on progressbar
154
- * 1.0.5
155
- * Only add css and js script in the media page to avoid any javascript error in other pages
156
- * Rectify css
157
- * Add function to get the code for the function.php file of the theme
158
- * Don't redefine the Wordpress basic size names
159
- * 1.0.4
160
- * Fix the add_image_size issue ( height and width reversed )
161
- * 1.0.3
162
- * Fix the plugin language
163
- * Add some translations
164
- * Externalise some css
165
- * Add sizes in the image adding to an article
166
- * Add setting link in the plugins list
167
- * Use admin_url instead of home_url
168
- * Add legend for colors
169
- * Some code refactoring
170
- * 1.0.2
171
- * Fix the plugin license
172
- * 1.0.1
173
- * Add POT file
174
- * Add french translation
175
- * 1.0
176
- * First release
177
- * Thumbnail regenerate
 
 
178
  * Image size generation
1
+ === Simple Image Sizes ===
2
+ Contributors: Rahe
3
+ Donate link: http://www.beapi.fr/donate/
4
+ Tags: images, image, custom sizes, custom images, thumbnail regenerate, thumbnail, regenerate
5
+ Requires at least: 3.5
6
+ Tested up to: 4.2.1
7
+ Stable tag: 3.0.4
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ == Description ==
12
+
13
+ This plugin allow create custom image sizes for your site. Override your theme sizes directly on the media option page.
14
+ You can regenerate all the sizes you have just created and choose which one you wanted to regenerate.
15
+ You can now get all the code to copy and paste to your function theme file.
16
+ Now you can use the generated sizes directly into your posts and insert images at the right size !
17
+ Now you choose if you want display the size in the post insert image.
18
+ Now you can regenerate the images one by one in the 'Medias' general pane.
19
+ Now you can regenerate the images by bulk action in the 'Medias' general pane.
20
+ Now you can regenerate the image sizes on single attachment edit page.
21
+
22
+ I have added a timer so when you regeneration your thumbnails, you can know approximately when the regeneration will be ended.
23
+ I have improved the php and javascript, you can know if the image have been regenerated or not or if there is an error and which one.
24
+
25
+ Contribute on https://github.com/Rahe/Simple-image-sizes
26
+
27
+ == Installation ==
28
+ **PHP5 Required.**
29
+
30
+ 1. Download, unzip and upload to your WordPress plugins directory
31
+ 2. Activate the plugin within you WordPress Administration Backend
32
+ 3. Go to Settings > Medias
33
+ 4. Configure your new image sizes and regenerate the thumbnails !
34
+
35
+ == Frequently Asked Questions ==
36
+
37
+ = Where can I add image sizes ? =
38
+ Go to Settings -> Media then you can add a image size. You have to add a unique custom name without any spaces or special chars.
39
+ The best is to use something like my-custom-size.
40
+ Then you have several fields for configuring the image size, the widht, the height, cropping.
41
+ And then you can choose if the image is displayed on the media insertion or not ( this will be displayed on the dropdown list ).
42
+
43
+
44
+ == Screenshots ==
45
+
46
+ 1. Settings page
47
+ 2. Get PHP for the theme
48
+ 3. Choose the sizes to regenerate and regenerate them
49
+
50
+ == Changelog ==
51
+ * 3.0.4
52
+ * Fix global add_image_size
53
+ * 3.0.3
54
+ * Add Hebrew translations thanks to Atar4U
55
+ * 3.0.2
56
+ * Fix version check for the image crop positions
57
+ * 3.0.1
58
+ * Change the template render method for non apache webservers : https://wordpress.org/support/topic/fatal-error-1190?replies=6
59
+ * Remove ambigious ids for the css bugging WooCommerce : https://wordpress.org/support/topic/bad-css-style-administration and
60
+ * Right code for counting the elements on backoffice : https://github.com/Rahe/Simple-image-sizes/issues/20
61
+ * Fix bug on regenation and _e instead of __ : https://plugins.trac.wordpress.org/ticket/2259
62
+ * 3.0
63
+ * Revamping all the code, change classes and structure
64
+ * Use grunt for compiling files
65
+ * Handle the 3.9 new cropping position
66
+ * Remove aristo css
67
+ * Use UI from WordPress
68
+ * 2.4.3
69
+ * Remove some php notices
70
+ * Remove notice when wrong image size
71
+ * 2.4.2
72
+ * Selective regeneration fix by g100g on http://wordpress.org/support/topic/regenerating-fix
73
+ * 2.4.1
74
+ * Remove function not working on admin file
75
+ * 2.4
76
+ * Made for 3.5 and up
77
+ * Refactoring PHP/Javascript code
78
+ * Javascript improvements
79
+ * Remove useless UI
80
+ * UI improvements
81
+ * Global PHP performance improvements
82
+ * 2.3.1
83
+ * Add Ajax bulk actions on medias list
84
+ * Add ajax thumbnail rebuild on single media
85
+ * 2.3
86
+ * Add the custom size name in the attachment insertion
87
+ * Exclude post_type wich do not support the post-thumbnail feature
88
+ * 2.2.5
89
+ * Debug the regeneration buggy !
90
+ * Complete the french translation
91
+ * Security update for single regeneration, include the nonce this time :)
92
+ * 2.2.4
93
+ * Add security nonces for every actions
94
+ * Put the messages at the begining of the log
95
+ * Add a select all checkbox Thank to cocola
96
+ * Add the german translation thanks to glueckpress
97
+ * Remove notice tnahks to christianwach
98
+ * Remove useless and buggy for my scripting pointers
99
+ * 2.2.3
100
+ * Do not force network usage
101
+ * 2.2.2
102
+ * Debug js for the buttons
103
+ * Remove console.log calls
104
+ * 2.2.1
105
+ * Use buttonset for the checkboxes
106
+ * Add Pointer for WordPress 3.3
107
+ * Fix translation in French
108
+ * Some medias queries for small windows ( change size of buttons and alignment )
109
+ * 2.2
110
+ * Add new version of css aristo
111
+ * Add some icons
112
+ * Display button for saving changes only when changes detected
113
+ * Display message when a size is modified but not saved and wanted to regenerate
114
+ * Debug functionnality when regenerating only some sizes, metas not crushed
115
+ * Add solo regenerating
116
+ * Remove displaying for theme/not theme sizes
117
+ * Use WordPress class for small inputs
118
+ * 2.1
119
+ * Add javascript timer
120
+ * Improve javascript and more IE friendly
121
+ * You can now choose if you want to display the image sizes in image insertion or not
122
+ * Handle errors and messages
123
+ * Remove some css useless rules
124
+ * Fix bad translation for french
125
+ * Remove accents in image sizes
126
+ * Do not update size properties if there is an ajax query for an another size name
127
+ * 2.0.3
128
+ * Resolve issue with theme sizes witch by default are displayed as not cropped. Thanks to momo360modena for the bug signalment.
129
+ * 2.0.2
130
+ * Remove debug on php for javascript
131
+ * Resolve issue with the different versions on jquery ( like in WP3.2 ) with attr return for checked components
132
+ * 2.0.1
133
+ * Resolve javascript issue when clicking on delete button
134
+ * Resolve issue of never unchecking crop button
135
+ * 2.0
136
+ * Code refactoring
137
+ * Update translations
138
+ * Ajaxification of the process
139
+ * Deleting by Ajax
140
+ * Updating by Ajax
141
+ * Adding by Ajax
142
+ * Change UI
143
+ * Change theme
144
+ * Handle ajax errors
145
+ * Handle not modified sizes, cropped
146
+ * Handle same names
147
+ * Sanitize the names
148
+ * Customize jQuery ui
149
+ * Customize jQuery ui theme
150
+ * HTML5 Elements
151
+ * CSS3 Animations
152
+ * 1.0.6
153
+ * Minify javascript names
154
+ * Change progressbar style
155
+ * Add animations on progressbar
156
+ * 1.0.5
157
+ * Only add css and js script in the media page to avoid any javascript error in other pages
158
+ * Rectify css
159
+ * Add function to get the code for the function.php file of the theme
160
+ * Don't redefine the Wordpress basic size names
161
+ * 1.0.4
162
+ * Fix the add_image_size issue ( height and width reversed )
163
+ * 1.0.3
164
+ * Fix the plugin language
165
+ * Add some translations
166
+ * Externalise some css
167
+ * Add sizes in the image adding to an article
168
+ * Add setting link in the plugins list
169
+ * Use admin_url instead of home_url
170
+ * Add legend for colors
171
+ * Some code refactoring
172
+ * 1.0.2
173
+ * Fix the plugin license
174
+ * 1.0.1
175
+ * Add POT file
176
+ * Add french translation
177
+ * 1.0
178
+ * First release
179
+ * Thumbnail regenerate
180
  * Image size generation
simple_image_sizes.php CHANGED
@@ -1,60 +1,62 @@
1
- <?php
2
- /*
3
- Plugin Name: Simple Image Sizes
4
- Plugin URI: https://github.com/Rahe/'simple-image-sizes'
5
- Description: Add options in media setting page for images sizes
6
- Version: 3.0.3
7
- Author: Rahe
8
- Author URI: http://nicolas-juen.fr
9
- Text Domain: 'simple-image-sizes'
10
- Domain Path: /languages
11
- License: GPLv2 or later
12
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
-
14
- Copyright 2011 Nicolas JUEN (njuen@beapi.fr) - Be-API
15
-
16
- This program is free software; you can redistribute it and/or modify
17
- it under the terms of the GNU General Public License as published by
18
- the Free Software Foundation; either version 2 of the License, or
19
- (at your option) any later version.
20
-
21
- This program is distributed in the hope that it will be useful,
22
- but WITHOUT ANY WARRANTY; without even the implied warranty of
23
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
- GNU General Public License for more details.
25
-
26
- You should have received a copy of the GNU General Public License
27
- along with this program; if not, write to the Free Software
28
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
- */
30
-
31
- define( 'SIS_URL', plugin_dir_url ( __FILE__ ) );
32
- define( 'SIS_DIR', plugin_dir_path( __FILE__ ) );
33
- define( 'SIS_VERSION', '3.0.3' );
34
- define( 'SIS_OPTION', 'custom_image_sizes' );
35
-
36
- // Function for easy load files
37
- function _sis_load_files($dir, $files, $prefix = '') {
38
- foreach ( $files as $file ) {
39
- if ( is_file( $dir . $prefix . $file . ".php" ) ) {
40
- require_once( $dir . $prefix . $file . ".php" );
41
- }
42
- }
43
- }
44
-
45
- // Plugin client classes
46
- _sis_load_files( SIS_DIR . 'classes/', array( 'main' ) );
47
-
48
- // Admins classes
49
- _sis_load_files( SIS_DIR . 'classes/admin/', array( 'main', 'post', 'media' ) );
50
-
51
- add_action ( 'plugins_loaded', 'initSIS' );
52
- function initSIS() {
53
- if( is_admin() ) {
54
- new SIS_Admin_Main();
55
- new SIS_Admin_Post();
56
- new SIS_Admin_Media();
57
- }
58
-
59
- new SIS_Client();
60
- }
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Simple Image Sizes
4
+ Plugin URI: https://github.com/Rahe/simple-image-sizes
5
+ Description: Add options in media setting page for images sizes
6
+ Version: 3.0.4
7
+ Author: Rahe
8
+ Author URI: http://nicolas-juen.fr
9
+ Text Domain: 'simple-image-sizes'
10
+ Domain Path: /languages
11
+ License: GPLv2 or later
12
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
+
14
+ Copyright 2011 Nicolas JUEN (njuen@beapi.fr) - Be-API
15
+
16
+ This program is free software; you can redistribute it and/or modify
17
+ it under the terms of the GNU General Public License as published by
18
+ the Free Software Foundation; either version 2 of the License, or
19
+ (at your option) any later version.
20
+
21
+ This program is distributed in the hope that it will be useful,
22
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ GNU General Public License for more details.
25
+
26
+ You should have received a copy of the GNU General Public License
27
+ along with this program; if not, write to the Free Software
28
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
+ */
30
+
31
+ define( 'SIS_URL', plugin_dir_url( __FILE__ ) );
32
+ define( 'SIS_DIR', plugin_dir_path( __FILE__ ) );
33
+ define( 'SIS_VERSION', '3.0.4' );
34
+ define( 'SIS_OPTION', 'custom_image_sizes' );
35
+
36
+ // Function for easy load files
37
+ function _sis_load_files( $dir, $files, $prefix = '' ) {
38
+ foreach ( $files as $file ) {
39
+ if ( is_file( $dir . $prefix . $file . '.php' ) ) {
40
+ require_once( $dir . $prefix . $file . '.php' );
41
+ }
42
+ }
43
+ }
44
+
45
+ // Plugin client classes
46
+ _sis_load_files( SIS_DIR . 'classes/', array( 'main' ) );
47
+
48
+ if ( is_admin() ) {
49
+ // Admins classes
50
+ _sis_load_files( SIS_DIR . 'classes/admin/', array( 'main', 'post', 'media' ) );
51
+ }
52
+
53
+ add_action( 'plugins_loaded', 'init_sis' );
54
+ function init_sis() {
55
+ if ( is_admin() ) {
56
+ new SIS_Admin_Main();
57
+ new SIS_Admin_Post();
58
+ new SIS_Admin_Media();
59
+ }
60
+
61
+ new SIS_Client();
62
+ }