Simple Image Sizes - Version 3.0.7

Version Description

Download this release

Release Info

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

Code changes from version 3.0.5 to 3.0.7

Gruntfile.js DELETED
@@ -1,57 +0,0 @@
1
- // Ici c'est du javascript
2
- module.exports = function(grunt) {
3
- grunt.initConfig({
4
- // On lit le fichier de package
5
- pkg: grunt.file.readJSON('package.json'),
6
- watch: {
7
- scripts : {
8
- files: ['assets/js/*.js'],
9
- tasks: ['jshint:dev']
10
- }
11
- },
12
- jshint : {
13
- dev : {
14
- src: [ 'Gruntfile.js', 'assets/*.js' ],
15
- options: {
16
- // options here to override JSHint defaults
17
- globals: {
18
- jQuery: true,
19
- console: true,
20
- document: true
21
- }
22
- }
23
- }
24
- },
25
- uglify : {
26
- dist : {
27
- files: {
28
- 'assets/js/sis.min.js': [
29
- 'assets/js/sis.js',
30
- ],
31
- 'assets/js/sis-attachments.min.js': [
32
- 'assets/js/sis-attachments.js',
33
-
34
- ]
35
- }
36
- }
37
- },
38
- cssmin : {
39
- minify: {
40
- expand: true,
41
- cwd: 'assets/css/',
42
- src: ['*.css', '!*.min.css'],
43
- dest: 'assets/css/',
44
- ext: '.min.css'
45
- }
46
- }
47
- });
48
-
49
- grunt.loadNpmTasks('grunt-contrib-uglify');
50
- grunt.loadNpmTasks('grunt-contrib-watch');
51
- grunt.loadNpmTasks('grunt-contrib-jshint');
52
- grunt.loadNpmTasks('grunt-contrib-cssmin');
53
-
54
- grunt.registerTask('default', ['watch:scripts'] );
55
-
56
- grunt.registerTask('dist', ['uglify:dist', 'cssmin'] );
57
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README CHANGED
@@ -1,200 +1,204 @@
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.5
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
-
68
- * 3.0.5
69
- * Fix bug on condition
70
- * 3.0.4
71
- * Fix global add_image_size
72
- * 3.0.3
73
- * Add Hebrew translations thanks to Atar4U
74
- * 3.0.2
75
- * Fix version check for the image crop positions
76
- * Add Hebrew translations thanks to Atar4U
77
- * 3.0.1
78
- * Change the template render method for non apache webservers : https://wordpress.org/support/topic/fatal-error-1190?replies=6
79
- * Remove ambigious ids for the css bugging WooCommerce : https://wordpress.org/support/topic/bad-css-style-administration and
80
- * Right code for counting the elements on backoffice : https://github.com/Rahe/Simple-image-sizes/issues/20
81
- * Fix bug on regenation and _e instead of __ : https://plugins.trac.wordpress.org/ticket/2259
82
- * 3.0
83
- * Revamping all the code, change classes and structure
84
- * Use grunt for compiling files
85
- * Handle the 3.9 new cropping position
86
- * Remove aristo css
87
- * Use UI from WordPress
88
- * 2.4.3
89
- * Remove some php notices
90
- * Remove notice when wrong image size
91
- * 2.4.2
92
- * Selective regeneration fix by g100g on http://wordpress.org/support/topic/regenerating-fix
93
- * 2.4.1
94
- * Remove function not working on admin file
95
- * 2.4
96
- * Made for 3.5 and up
97
- * Refactoring PHP/Javascript code
98
- * Javascript improvements
99
- * Remove useless UI
100
- * UI improvements
101
- * Global PHP performance improvements
102
- * 2.3.1
103
- * Add Ajax bulk actions on medias list
104
- * Add ajax thumbnail rebuild on single media
105
- * 2.3
106
- * Add the custom size name in the attachment insertion
107
- * Exclude post_type wich do not support the post-thumbnail feature
108
- * 2.2.5
109
- * Debug the regeneration buggy !
110
- * Complete the french translation
111
- * Security update for single regeneration, include the nonce this time :)
112
- * 2.2.4
113
- * Add security nonces for every actions
114
- * Put the messages at the begining of the log
115
- * Add a select all checkbox Thank to cocola
116
- * Add the german translation thanks to glueckpress
117
- * Remove notice tnahks to christianwach
118
- * Remove useless and buggy for my scripting pointers
119
- * 2.2.3
120
- * Do not force network usage
121
- * 2.2.2
122
- * Debug js for the buttons
123
- * Remove console.log calls
124
- * 2.2.1
125
- * Use buttonset for the checkboxes
126
- * Add Pointer for WordPress 3.3
127
- * Fix translation in French
128
- * Some medias queries for small windows ( change size of buttons and alignment )
129
- * 2.2
130
- * Add new version of css aristo
131
- * Add some icons
132
- * Display button for saving changes only when changes detected
133
- * Display message when a size is modified but not saved and wanted to regenerate
134
- * Debug functionnality when regenerating only some sizes, metas not crushed
135
- * Add solo regenerating
136
- * Remove displaying for theme/not theme sizes
137
- * Use WordPress class for small inputs
138
- * 2.1
139
- * Add javascript timer
140
- * Improve javascript and more IE friendly
141
- * You can now choose if you want to display the image sizes in image insertion or not
142
- * Handle errors and messages
143
- * Remove some css useless rules
144
- * Fix bad translation for french
145
- * Remove accents in image sizes
146
- * Do not update size properties if there is an ajax query for an another size name
147
- * 2.0.3
148
- * Resolve issue with theme sizes witch by default are displayed as not cropped. Thanks to momo360modena for the bug signalment.
149
- * 2.0.2
150
- * Remove debug on php for javascript
151
- * Resolve issue with the different versions on jquery ( like in WP3.2 ) with attr return for checked components
152
- * 2.0.1
153
- * Resolve javascript issue when clicking on delete button
154
- * Resolve issue of never unchecking crop button
155
- * 2.0
156
- * Code refactoring
157
- * Update translations
158
- * Ajaxification of the process
159
- * Deleting by Ajax
160
- * Updating by Ajax
161
- * Adding by Ajax
162
- * Change UI
163
- * Change theme
164
- * Handle ajax errors
165
- * Handle not modified sizes, cropped
166
- * Handle same names
167
- * Sanitize the names
168
- * Customize jQuery ui
169
- * Customize jQuery ui theme
170
- * HTML5 Elements
171
- * CSS3 Animations
172
- * 1.0.6
173
- * Minify javascript names
174
- * Change progressbar style
175
- * Add animations on progressbar
176
- * 1.0.5
177
- * Only add css and js script in the media page to avoid any javascript error in other pages
178
- * Rectify css
179
- * Add function to get the code for the function.php file of the theme
180
- * Don't redefine the Wordpress basic size names
181
- * 1.0.4
182
- * Fix the add_image_size issue ( height and width reversed )
183
- * 1.0.3
184
- * Fix the plugin language
185
- * Add some translations
186
- * Externalise some css
187
- * Add sizes in the image adding to an article
188
- * Add setting link in the plugins list
189
- * Use admin_url instead of home_url
190
- * Add legend for colors
191
- * Some code refactoring
192
- * 1.0.2
193
- * Fix the plugin license
194
- * 1.0.1
195
- * Add POT file
196
- * Add french translation
197
- * 1.0
198
- * First release
199
- * Thumbnail regenerate
200
- * 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.6
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.7
68
+ * Fix bug on single image regeneration upload page
69
+ * Fix bug https://github.com/Rahe/Simple-image-sizes/issues/30
70
+ * 3.0.6
71
+ * Fix bug for the image adding
72
+ * 3.0.5
73
+ * Fix bug on condition
74
+ * 3.0.4
75
+ * Fix global add_image_size
76
+ * 3.0.3
77
+ * Add Hebrew translations thanks to Atar4U
78
+ * 3.0.2
79
+ * Fix version check for the image crop positions
80
+ * Add Hebrew translations thanks to Atar4U
81
+ * 3.0.1
82
+ * Change the template render method for non apache webservers : https://wordpress.org/support/topic/fatal-error-1190?replies=6
83
+ * Remove ambigious ids for the css bugging WooCommerce : https://wordpress.org/support/topic/bad-css-style-administration and
84
+ * Right code for counting the elements on backoffice : https://github.com/Rahe/Simple-image-sizes/issues/20
85
+ * Fix bug on regenation and _e instead of __ : https://plugins.trac.wordpress.org/ticket/2259
86
+ * 3.0
87
+ * Revamping all the code, change classes and structure
88
+ * Use grunt for compiling files
89
+ * Handle the 3.9 new cropping position
90
+ * Remove aristo css
91
+ * Use UI from WordPress
92
+ * 2.4.3
93
+ * Remove some php notices
94
+ * Remove notice when wrong image size
95
+ * 2.4.2
96
+ * Selective regeneration fix by g100g on http://wordpress.org/support/topic/regenerating-fix
97
+ * 2.4.1
98
+ * Remove function not working on admin file
99
+ * 2.4
100
+ * Made for 3.5 and up
101
+ * Refactoring PHP/Javascript code
102
+ * Javascript improvements
103
+ * Remove useless UI
104
+ * UI improvements
105
+ * Global PHP performance improvements
106
+ * 2.3.1
107
+ * Add Ajax bulk actions on medias list
108
+ * Add ajax thumbnail rebuild on single media
109
+ * 2.3
110
+ * Add the custom size name in the attachment insertion
111
+ * Exclude post_type wich do not support the post-thumbnail feature
112
+ * 2.2.5
113
+ * Debug the regeneration buggy !
114
+ * Complete the french translation
115
+ * Security update for single regeneration, include the nonce this time :)
116
+ * 2.2.4
117
+ * Add security nonces for every actions
118
+ * Put the messages at the begining of the log
119
+ * Add a select all checkbox Thank to cocola
120
+ * Add the german translation thanks to glueckpress
121
+ * Remove notice tnahks to christianwach
122
+ * Remove useless and buggy for my scripting pointers
123
+ * 2.2.3
124
+ * Do not force network usage
125
+ * 2.2.2
126
+ * Debug js for the buttons
127
+ * Remove console.log calls
128
+ * 2.2.1
129
+ * Use buttonset for the checkboxes
130
+ * Add Pointer for WordPress 3.3
131
+ * Fix translation in French
132
+ * Some medias queries for small windows ( change size of buttons and alignment )
133
+ * 2.2
134
+ * Add new version of css aristo
135
+ * Add some icons
136
+ * Display button for saving changes only when changes detected
137
+ * Display message when a size is modified but not saved and wanted to regenerate
138
+ * Debug functionnality when regenerating only some sizes, metas not crushed
139
+ * Add solo regenerating
140
+ * Remove displaying for theme/not theme sizes
141
+ * Use WordPress class for small inputs
142
+ * 2.1
143
+ * Add javascript timer
144
+ * Improve javascript and more IE friendly
145
+ * You can now choose if you want to display the image sizes in image insertion or not
146
+ * Handle errors and messages
147
+ * Remove some css useless rules
148
+ * Fix bad translation for french
149
+ * Remove accents in image sizes
150
+ * Do not update size properties if there is an ajax query for an another size name
151
+ * 2.0.3
152
+ * Resolve issue with theme sizes witch by default are displayed as not cropped. Thanks to momo360modena for the bug signalment.
153
+ * 2.0.2
154
+ * Remove debug on php for javascript
155
+ * Resolve issue with the different versions on jquery ( like in WP3.2 ) with attr return for checked components
156
+ * 2.0.1
157
+ * Resolve javascript issue when clicking on delete button
158
+ * Resolve issue of never unchecking crop button
159
+ * 2.0
160
+ * Code refactoring
161
+ * Update translations
162
+ * Ajaxification of the process
163
+ * Deleting by Ajax
164
+ * Updating by Ajax
165
+ * Adding by Ajax
166
+ * Change UI
167
+ * Change theme
168
+ * Handle ajax errors
169
+ * Handle not modified sizes, cropped
170
+ * Handle same names
171
+ * Sanitize the names
172
+ * Customize jQuery ui
173
+ * Customize jQuery ui theme
174
+ * HTML5 Elements
175
+ * CSS3 Animations
176
+ * 1.0.6
177
+ * Minify javascript names
178
+ * Change progressbar style
179
+ * Add animations on progressbar
180
+ * 1.0.5
181
+ * Only add css and js script in the media page to avoid any javascript error in other pages
182
+ * Rectify css
183
+ * Add function to get the code for the function.php file of the theme
184
+ * Don't redefine the Wordpress basic size names
185
+ * 1.0.4
186
+ * Fix the add_image_size issue ( height and width reversed )
187
+ * 1.0.3
188
+ * Fix the plugin language
189
+ * Add some translations
190
+ * Externalise some css
191
+ * Add sizes in the image adding to an article
192
+ * Add setting link in the plugins list
193
+ * Use admin_url instead of home_url
194
+ * Add legend for colors
195
+ * Some code refactoring
196
+ * 1.0.2
197
+ * Fix the plugin license
198
+ * 1.0.1
199
+ * Add POT file
200
+ * Add french translation
201
+ * 1.0
202
+ * First release
203
+ * Thumbnail regenerate
204
+ * Image size generation
assets/css/sis-style.min.css CHANGED
@@ -1 +1 @@
1
- .media-item.sis{display:none}.media-item.sis .progress{width:100%}input.h,input.w{border-color:#DFDFDF;background-color:#fff;border-width:1px;border-style:solid;-moz-border-radius:3px;-khtml-border-radius:3px;-webkit-border-radius:3px;border-radius:3px}table.sis tr{-webkit-transition:all .5s ease-in-out;-moz-transition:all .5s ease-in-out;-o-transition:all .5s ease-in-out;transition:all .5s ease-in-out}table.sis tr:nth-child(even){background-color:#FCFCFC}table.sis tr:nth-child(odd){background-color:transparent}tr.addPending{background-color:#6CA1D7}tr.successAdding{background-color:#89D76A}tr.errorAdding{background-color:#C45858}tr.notChangedAdding{background-color:#F2A13A}.sis .regenerate_message,.sis .thumb,.sis .time{display:none}#ajax_thumbnail_rebuild{margin-top:40px}#sis_progress-percent{width:100%;text-align:center;font-weight:700}.sis .time .ui-state-highlight{margin-top:20px;padding:0 .7em}#post-body .sis-regenerate-one{float:left}
1
+ .media-item.sis,.sis .regenerate_message,.sis .thumb,.sis .time{display:none}.media-item.sis .progress{width:100%}input.h,input.w{border-color:#DFDFDF;background-color:#fff;border-width:1px;border-style:solid;-moz-border-radius:3px;-khtml-border-radius:3px;-webkit-border-radius:3px;border-radius:3px}table.sis tr{-webkit-transition:all .5s ease-in-out;-moz-transition:all .5s ease-in-out;-o-transition:all .5s ease-in-out;transition:all .5s ease-in-out}table.sis tr:nth-child(even){background-color:#FCFCFC}table.sis tr:nth-child(odd){background-color:transparent}tr.addPending{background-color:#6CA1D7}tr.successAdding{background-color:#89D76A}tr.errorAdding{background-color:#C45858}tr.notChangedAdding{background-color:#F2A13A}#ajax_thumbnail_rebuild{margin-top:40px}#sis_progress-percent{width:100%;text-align:center;font-weight:700}.sis .time .ui-state-highlight{margin-top:20px;padding:0 .7em}#post-body .sis-regenerate-one{float:left}
assets/js/sis-attachments.min.js CHANGED
@@ -1 +1,3 @@
1
- var sis;if(sis){if("object"!=typeof sis)throw new Error("sis already exists and not an object")}else sis={};jQuery(function(){"use strict";var a=jQuery(document.body),b=null,c=null;jQuery('select[name="action"], select[name="action2"]').append(jQuery("<option/>").attr("value","sis-regenerate").text(sis.regenerate)),a.on("click",".sis-regenerate-one",function(a){a.preventDefault(),c=new b(this)}),jQuery("#doaction, #doaction2").on("click",function(a){if("sis-regenerate"===jQuery(this).parent().find("select").val()){var d=jQuery('#the-list .check-column input[type="checkbox"]:checked').closest("tr").find(".sis-regenerate-one");d.length>0&&(a.preventDefault(),d.each(function(a,d){c=new b(this)}))}}),b=function(a){var b={list:{},parent:null,el:null,id:null,messageZone:"",init:function(a){this.el=a,this.parent=a.closest("tr"),this.id=this.el.data("id"),this.list={id:this.id,title:""},this.messageZone=this.parent.find(".title em"),0===this.parent.find(".title em").length&&this.parent.find(".title strong").after("<em/>"),this.messageZone=this.parent.find(".title em"),this.parent.hasClass("ajaxing")||this.regenItem()},setMessage:function(a){this.messageZone.html(" - "+a).addClass("updated").addClass("fade").show()},regenItem:function(){var a=this;jQuery.ajax({url:sis.ajaxUrl,type:"POST",dataType:"json",cache:!1,data:{action:"sis_rebuild_image",id:this.list.id,nonce:sis.regen_one},beforeSend:function(){a.parent.addClass("ajaxing").find(".sis-regenerate-one").hide().end().find(".spinner").show(),a.parent.find("a.sis-regenerate-one").closest("tr").fadeTo("fast","0.3")},success:function(b){var c="";c=b.src&&b.time&&!b.error&&"object"==typeof b?sis.soloRegenerated.replace("%s",b.time):"object"!=typeof b?c=sis.phpError:b.error,a.setMessage(c),a.parent.removeClass("ajaxing").find(".sis-regenerate-one").show().end().find(".spinner").hide(),a.parent.find("a.sis-regenerate-one").closest("tr").fadeTo("fast","1")}})}};b.init(jQuery(a))}});
 
 
1
+ var sis;if(sis){if("object"!=typeof sis)throw new Error("sis already exists and not an object")}else sis={};jQuery(function(){"use strict";var e=jQuery(document.body),t=null,s=null;jQuery('select[name="action"], select[name="action2"]').append(jQuery("<option/>").attr("value","sis-regenerate").text(sis.regenerate)),e.on("click",".sis-regenerate-one",function(e){e.preventDefault(),s=new t(this)}),jQuery("#doaction, #doaction2").on("click",function(e){if("sis-regenerate"===jQuery(this).parent().find("select").val()){var n=jQuery('#the-list .check-column input[type="checkbox"]:checked').closest("tr").find(".sis-regenerate-one");n.length>0&&(e.preventDefault(),n.each(function(e,n){s=new t(this)}))}}),t=function(e){var t={list:{},parent:null,el:null,id:null,messageZone:"",init:function(e){this.el=e,this.parent=e.closest("tr"),this.id=this.el.data("id"),this.list={id:this.id,title:""},this.messageZone=this.parent.find(".title em"),0===this.parent.find(".title em").length&&this.parent.find(".title strong").after("<em/>"),this.messageZone=this.parent.find(".title em"),this.parent.hasClass("ajaxing")||this.regenItem()},setMessage:function(e){this.messageZone.html(" - "+e).addClass("updated").addClass("fade").show()},regenItem:function(){var e=this;jQuery.ajax({url:sis.ajaxUrl,type:"POST",dataType:"json",cache:!1,data:{action:"sis_rebuild_image",id:this.list.id,nonce:sis.regen_one},beforeSend:function(){e.parent.addClass("ajaxing").find(".sis-regenerate-one").hide().end().find(".spinner").show(),e.parent.find("a.sis-regenerate-one").closest("tr").fadeTo("fast","0.3")},success:function(t){var s="";s=t.src&&t.time&&!t.error&&"object"==typeof t?sis.soloRegenerated.replace("%s",t.time):"object"!=typeof t?s=sis.phpError:t.error,e.setMessage(s),e.parent.removeClass("ajaxing").find(".sis-regenerate-one").show().end().find(".spinner").hide(),e.parent.find("a.sis-regenerate-one").closest("tr").fadeTo("fast","1")}})}};t.init(jQuery(e))}});
2
+
3
+ //# sourceMappingURL=sis-attachments.min.js.map
assets/js/sis-attachments.min.js.map ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": 3,
3
+ "file": "sis-attachments.min.js",
4
+ "sources": [
5
+ "assets/js/sis-attachments.js"
6
+ ],
7
+ "names": [],
8
+ "mappings": "AAAA",
9
+ "sourceRoot": "../../"
10
+ }
assets/js/sis.min.js CHANGED
@@ -1 +1,3 @@
1
- var rahe;if(rahe){if("object"!=typeof rahe)throw new Error("rahe already exists and not an object")}else rahe={};if(rahe.sis){if("object"!=typeof rahe.sis)throw new Error("rahe.sis already exists and not an object")}else rahe.sis={};rahe.sis.regenerate={post_types:[],thumbnails:[],total:0,cur:0,timeScript:[],dateScript:"",percent:"",percentText:null,progress:null,messageZone:null,sisZone:null,time:null,timeZone:null,buttonRegenerate:null,errorZone:null,errorMessages:null,thumb:null,thumbImg:null,init:function(){this.sisZone=jQuery(".sis"),this.percentText=jQuery("#sis_progress-percent"),this.progress=jQuery(".progress"),this.messageZone=this.sisZone.find(".regenerate_message"),this.time=this.sisZone.find(".time"),this.timeZone=this.time.find("p span.time_message"),this.buttonRegenerate=jQuery("#ajax_thumbnail_rebuild"),this.errorZone=jQuery("#error_messages"),this.errorMessages=this.errorZone.find("ul.messages"),this.thumb=this.sisZone.find(".thumb"),this.thumbImg=this.sisZone.find(".thumb-img")},getThumbnails:function(){var a=this,b=jQuery("input.thumbnails:checked");b.length!=jQuery('input.thumbnails[type="checkbox"]').length&&b.each(function(b){a.thumbnails.push(this.value)})},getPostTypes:function(){var a=this,b=jQuery("input.post_types:checked");b.length!=jQuery('input.post_types[type="checkbox"]').length&&b.each(function(){a.post_types.push(this.value)})},setMessage:function(a){this.messageZone.html("<p>"+a+"</p>").addClass("updated").addClass("fade").show()},setTimeMessage:function(a){this.timeZone.html(a)},checkStartRegenerating:function(){if(jQuery(".notSaved").size()>0){var a=confirm(sis.notSaved);if(1!=a)return!1;this.startRegenerating()}else this.startRegenerating()},startRegenerating:function(){var a=this,b=jQuery("input.getList").val();a.getThumbnails(),a.getPostTypes(),this.dateScript=new Date,jQuery.ajax({url:sis.ajaxUrl,type:"POST",dataType:"json",data:{action:"sis_get_list",post_types:a.post_types,nonce:b},beforeSend:function(){a.buttonRegenerate.attr("disabled",!0),a.setMessage(sis.reading)},success:function(b){return"object"!=typeof b?(a.reInit(),a.setMessage(sis.phpError),!1):(a.time.show(),a.total=b.total,a.curr=0,a.progress.show().parent().show(),void a.regenItem())}})},regenItem:function(){var a=this,b=jQuery("input.regen").val();if(0==this.total||_.isUndefined(this.total))return this.reInit(),this.setMessage(sis.noMedia),!1;if(this.curr>=this.total){var c=new Date;return this.reInit(),void this.setMessage(sis.done+this.curr+" "+sis.messageRegenerated+sis.startedAt+" "+this.dateScript.getHours()+":"+this.dateScript.getMinutes()+":"+this.dateScript.getSeconds()+sis.finishedAt+" "+c.getHours()+":"+c.getMinutes()+":"+c.getSeconds())}this.setMessage(sis.regenerating+(this.curr+1)+sis.of+this.total),this.setMessage(sis.regenerating+(this.curr+1)+sis.of+this.total),jQuery.ajax({url:sis.ajaxUrl,type:"POST",dataType:"json",data:{action:"sis_rebuild_images",offset:this.curr,thumbnails:this.thumbnails,nonce:b},beforeSend:function(){a.percent=a.curr/a.total*100,a.progress.find(".bar").width(a.percent+"%").find(".percent").html(a.percent+"%"),a.percentText.removeClass("hidden").html(Math.round(a.percent)+"%")},success:function(b){if(b.src&&b.time&&!b.error&&"object"==typeof b){b.message&&a.time.find("ul.messages").prepend("<li>"+b.message+"</li>"),a.thumb.show(),a.thumbImg.attr("src",b.src);var c=new Date,d=new Date,e=0,f=0,g=0,h=0,i="";for(a.timeScript.push(parseFloat(b.time.replace(",","."),10)),e=a.timeScript.length,g;e>g;g++)f+=a.timeScript[g];h=f/e,t=Math.round(h*a.total*1e3),c.setTime(a.dateScript.getTime()+t),i=a.s2t(Math.abs(c.getTime()-d.getTime())/1e3),a.setTimeMessage(c.getHours()+":"+c.getMinutes()+":"+c.getSeconds()+sis.or+i+sis.beforeEnd)}else{var j="";j="object"!=typeof b?sis.phpError:b.error,a.errorZone.addClass("error message"),a.errorMessages.prepend("<li>"+j+"</li>")}a.curr++,a.regenItem()}})},s2t:function(a){var a=a%86400,b=new Date(1970,0,1),c=0;return b.setSeconds(a),c=b.toTimeString().substr(0,8),a>86399&&(c=Math.floor((b-Date.parse("1/1/70"))/36e5)+c.substr(2)),c},reInit:function(){this.buttonRegenerate.removeAttr("disabled"),this.thumb.hide(),this.progress.hide(),this.percentText.addClass("hidden")}},rahe.sis.sizes={i:0,add:function(a,b){a.preventDefault();var c=rahe.sis.template("new_size");c=c({size_id:this.i,validate:sis.validate}),jQuery(b).closest("tr").before(c),this.i++},register:function(a,b){a.preventDefault();var c=jQuery(b).closest("tr").children("th").find("input").val(),d=jQuery(b).closest("tr").children("th").find("input").attr("id"),e=jQuery(b).closest("tbody").find('input[value="'+c+'"]').length;if("thumbnail"==c||"medium"==c||"large"==c)return alert(sis.notOriginal),!1;if(0!=e)return alert(sis.alreadyPresent),!1;var f=rahe.sis.template("new_size_row");f=f({size:sis.size,size_name:c,maximumWidth:sis.maximumWidth,maximumHeight:sis.maximumHeight,customName:sis.customName,crop:sis.crop,crop_positions:sis.crop_positions,show:sis.show,deleteImage:sis.deleteImage,validateButton:sis.validateButton}),jQuery("#"+d).closest("tr").html(f)},deleteSize:function(a,b){a.preventDefault();var c=confirm(sis.confirmDelete);1==c&&(jQuery(b).closest("tr").remove(),this.ajaxUnregister(b))},getPhp:function(a,b){a.preventDefault();var c=jQuery(b).closest("tr");jQuery.ajax({url:sis.ajaxUrl,type:"POST",data:{action:"sis_get_sizes"},beforeSend:function(){c.removeClass("addPending"),c.addClass("addPending")},success:function(a){jQuery("#get_php").nextAll("code").html("<br />"+a).show().css({display:"block"}),c.removeClass("addPending")}})},ajaxRegister:function(a,b){a.preventDefault();var c,d=this,e=jQuery(b).closest("table"),f=jQuery(".addSize").val(),g=jQuery(b).closest("tr"),h=g.find('input[name="image_name"]').val(),i=g.find("select.crop").val(),j=g.find("input.show").val(),k=g.find("input.n").val(),l=0,m=0;j=0==j||void 0==j?!1:!0,m=parseInt(g.find("input.w").val()),l=parseInt(g.find("input.h").val()),e.hasClass("ajaxing")||jQuery.ajax({url:sis.ajaxUrl,type:"POST",dataType:"json",data:{action:"sis_add_size",width:m,height:l,crop:i,name:h,show:j,customName:k,nonce:f},beforeSend:function(){g.removeClass(),g.addClass("addPending"),e.addClass("ajaxing")},success:function(a){var b="";g.removeClass(),e.removeClass("ajaxing"),0==a?b="errorAdding":2==a?(b="notChangedAdding",d.addToArray(h,m,l,i,b)):(b="successAdding",d.addToArray(h,m,l,i,b)),g.find("input.h").attr({base_h:l}),g.find("input.w").attr({base_w:m}),g.find("select.c").attr({base_c:i}),g.find("input.s").attr({base_s:j}),g.addClass(b),g.find("td").removeClass("notSaved"),g.find(".add_size").removeClass("validate_size").hide().children(".ui-button-text").text(sis.update),clearTimeout(c),c=setTimeout(function(){g.removeClass("errorAdding notChangedAdding successAdding")},2e3)}})},ajaxUnregister:function(a){var b=this,c=jQuery(a).closest("tr").find('input[name="image_name"]').val(),d=jQuery(a).closest("tr").find("input.deleteSize").val();jQuery.ajax({url:sis.ajaxUrl,type:"POST",data:{action:"sis_remove_size",name:c,nonce:d},success:function(c){b.removeFromArray(a)}})},addToArray:function(a,b,c,d,e){var f,g=jQuery("#sis-"+a),h="";h=0!=g.length?g.closest("tr"):jQuery("#sis-regen .wrapper > table#sis_sizes > tbody > tr:first").clone().attr("id","sis-"+a),d=_.isUndefined(sis.crop_positions[d])?sis.fl:sis.crop_positions[d],h.find("th > label").attr("for",a).end().find("input.thumbnails").val(a).attr("id",a).end().find("th:nth-child(2) > label").text(a).end().find("th:nth-child(3) > label").text(b+"px").end().find("th:nth-child(4) > label").text(c+"px").end().find("th:nth-child(5) > label").text(d),0==g.length&&h.appendTo("#sis-regen .wrapper > table#sis_sizes > tbody"),h.removeClass("errorAdding notChangedAdding successAdding").addClass(e),clearTimeout(f),f=setTimeout(function(){h.removeClass("errorAdding notChangedAdding successAdding")},3e3)},removeFromArray:function(a){var b=jQuery(a).closest("tr").find("input[name=image_name]").val();jQuery("#sis-"+b).remove()},displayChange:function(a){var a=jQuery(a),b=a.closest("tr");if(b.hasClass("new_size"))return!1;var c=b.find("input.h"),d=b.find("input.w"),e=b.find("select.c"),f=b.find("input.s"),g=b.find("input.n"),h=c.val(),i=d.val(),j=e.val(),k=f.val(),l=g.val(),m=c.attr("base_h"),n=d.attr("base_w"),o=e.attr("base_c"),p=f.attr("base_s"),q=g.attr("base_n");o="0"==o?!1:!0,p="0"==p?!1:!0,h!=m||i!=n||j!=o||k!=p||l!=q?a.closest("td").addClass("notSaved").find(".add_size").css("display","inline-block"):a.closest("td").removeClass("notSaved").find(".add_size").css("display","none")}},rahe.sis.template=_.memoize(function(a){var b,c={evaluate:/<#([\s\S]+?)#>/g,interpolate:/\{\{\{([\s\S]+?)\}\}\}/g,escape:/\{\{([^\}]+?)\}\}(?!\})/g,variable:"data"};return function(d){return(b=b||_.template(jQuery("#sis-"+a).html(),null,c))(d)}}),jQuery(function(){rahe.sis.regenerate.init();var a=jQuery("#wpbody-content");jQuery("#ajax_thumbnail_rebuild").click(function(){rahe.sis.regenerate.checkStartRegenerating()}),a.on("click","#add_size",function(a){rahe.sis.sizes.add(a,this)}).on("click",".add_size_name",function(a){rahe.sis.sizes.register(a,this)}).on("click",".delete_size",function(a){rahe.sis.sizes.deleteSize(a,this)}).on("click",".add_size",function(a){rahe.sis.sizes.ajaxRegister(a,this)}).on("click keyup change",".h,.w,.c,.s,.n",function(a){rahe.sis.sizes.displayChange(this)}).on("click","#get_php",function(a){rahe.sis.sizes.getPhp(a,this)}),jQuery("#get_php").nextAll("code").hide(),jQuery(".add_size").hide()});
 
 
1
+ var rahe;if(rahe){if("object"!=typeof rahe)throw new Error("rahe already exists and not an object")}else rahe={};if(rahe.sis){if("object"!=typeof rahe.sis)throw new Error("rahe.sis already exists and not an object")}else rahe.sis={};rahe.sis.regenerate={post_types:[],thumbnails:[],total:0,cur:0,timeScript:[],dateScript:"",percent:"",percentText:null,progress:null,messageZone:null,sisZone:null,time:null,timeZone:null,buttonRegenerate:null,errorZone:null,errorMessages:null,thumb:null,thumbImg:null,init:function(){this.sisZone=jQuery(".sis"),this.percentText=jQuery("#sis_progress-percent"),this.progress=jQuery(".progress"),this.messageZone=this.sisZone.find(".regenerate_message"),this.time=this.sisZone.find(".time"),this.timeZone=this.time.find("p span.time_message"),this.buttonRegenerate=jQuery("#ajax_thumbnail_rebuild"),this.errorZone=jQuery("#error_messages"),this.errorMessages=this.errorZone.find("ul.messages"),this.thumb=this.sisZone.find(".thumb"),this.thumbImg=this.sisZone.find(".thumb-img")},getThumbnails:function(){var e=this,t=jQuery("input.thumbnails:checked");t.length!=jQuery('input.thumbnails[type="checkbox"]').length&&t.each(function(t){e.thumbnails.push(this.value)})},getPostTypes:function(){var e=this,t=jQuery("input.post_types:checked");t.length!=jQuery('input.post_types[type="checkbox"]').length&&t.each(function(){e.post_types.push(this.value)})},setMessage:function(e){this.messageZone.html("<p>"+e+"</p>").addClass("updated").addClass("fade").show()},setTimeMessage:function(e){this.timeZone.html(e)},checkStartRegenerating:function(){if(jQuery(".notSaved").size()>0){var e=confirm(sis.notSaved);if(1!=e)return!1;this.startRegenerating()}else this.startRegenerating()},startRegenerating:function(){var e=this,t=jQuery("input.getList").val();e.getThumbnails(),e.getPostTypes(),this.dateScript=new Date,jQuery.ajax({url:sis.ajaxUrl,type:"POST",dataType:"json",data:{action:"sis_get_list",post_types:e.post_types,nonce:t},beforeSend:function(){e.buttonRegenerate.attr("disabled",!0),e.setMessage(sis.reading)},success:function(t){return"object"!=typeof t?(e.reInit(),e.setMessage(sis.phpError),!1):(e.time.show(),e.total=t.total,e.curr=0,e.progress.show().parent().show(),void e.regenItem())}})},regenItem:function(){var e=this,s=jQuery("input.regen").val();if(0==this.total||_.isUndefined(this.total))return this.reInit(),this.setMessage(sis.noMedia),!1;if(this.curr>=this.total){var i=new Date;return this.reInit(),void this.setMessage(sis.done+this.curr+" "+sis.messageRegenerated+sis.startedAt+" "+this.dateScript.getHours()+":"+this.dateScript.getMinutes()+":"+this.dateScript.getSeconds()+sis.finishedAt+" "+i.getHours()+":"+i.getMinutes()+":"+i.getSeconds())}this.setMessage(sis.regenerating+(this.curr+1)+sis.of+this.total),this.setMessage(sis.regenerating+(this.curr+1)+sis.of+this.total),jQuery.ajax({url:sis.ajaxUrl,type:"POST",dataType:"json",data:{action:"sis_rebuild_images",offset:this.curr,thumbnails:this.thumbnails,nonce:s},beforeSend:function(){e.percent=e.curr/e.total*100,e.progress.find(".bar").width(e.percent+"%").find(".percent").html(e.percent+"%"),e.percentText.removeClass("hidden").html(Math.round(e.percent)+"%")},success:function(s){if(s.src&&s.time&&!s.error&&"object"==typeof s){s.message&&e.time.find("ul.messages").prepend("<li>"+s.message+"</li>"),e.thumb.show(),e.thumbImg.attr("src",s.src);var i=new Date,n=new Date,a=0,r=0,o=0,d=0,l="";for(e.timeScript.push(parseFloat(s.time.replace(",","."),10)),a=e.timeScript.length,o;a>o;o++)r+=e.timeScript[o];d=r/a,t=Math.round(d*e.total*1e3),i.setTime(e.dateScript.getTime()+t),l=e.s2t(Math.abs(i.getTime()-n.getTime())/1e3),e.setTimeMessage(i.getHours()+":"+i.getMinutes()+":"+i.getSeconds()+sis.or+l+sis.beforeEnd)}else{var u="";u="object"!=typeof s?sis.phpError:s.error,e.errorZone.addClass("error message"),e.errorMessages.prepend("<li>"+u+"</li>")}e.curr++,e.regenItem()}})},s2t:function(e){var e=e%86400,t=new Date(1970,0,1),s=0;return t.setSeconds(e),s=t.toTimeString().substr(0,8),e>86399&&(s=Math.floor((t-Date.parse("1/1/70"))/36e5)+s.substr(2)),s},reInit:function(){this.buttonRegenerate.removeAttr("disabled"),this.thumb.hide(),this.progress.hide(),this.percentText.addClass("hidden")}},rahe.sis.sizes={i:0,add:function(e,t){e.preventDefault();var s=rahe.sis.template("new_size");s=s({size_id:this.i,validate:sis.validate}),jQuery(t).closest("tr").before(s),this.i++},register:function(e,t){e.preventDefault();var s=jQuery(t).closest("tr").children("th").find("input").val(),i=jQuery(t).closest("tr").children("th").find("input").attr("id"),n=jQuery(t).closest("tbody").find('input[value="'+s+'"]').length;if("thumbnail"==s||"medium"==s||"large"==s)return alert(sis.notOriginal),!1;if(0!=n)return alert(sis.alreadyPresent),!1;var a=rahe.sis.template("new_size_row");a=a({size:sis.size,size_name:s,maximumWidth:sis.maximumWidth,maximumHeight:sis.maximumHeight,customName:sis.customName,crop:sis.crop,crop_positions:sis.crop_positions,show:sis.show,deleteImage:sis.deleteImage,validateButton:sis.validateButton}),jQuery("#"+i).closest("tr").html(a)},deleteSize:function(e,t){e.preventDefault();var s=confirm(sis.confirmDelete);1==s&&(jQuery(t).closest("tr").remove(),this.ajaxUnregister(t))},getPhp:function(e,t){e.preventDefault();var s=jQuery(t).closest("tr");jQuery.ajax({url:sis.ajaxUrl,type:"POST",data:{action:"sis_get_sizes"},beforeSend:function(){s.removeClass("addPending"),s.addClass("addPending")},success:function(e){jQuery("#get_php").nextAll("code").html("<br />"+e).show().css({display:"block"}),s.removeClass("addPending")}})},ajaxRegister:function(e,t){e.preventDefault();var s,i=this,n=jQuery(t).closest("table"),a=jQuery(".addSize").val(),r=jQuery(t).closest("tr"),o=r.find('input[name="image_name"]').val(),d=r.find("select.crop").val(),l=r.find("input.show").val(),u=r.find("input.n").val(),h=0,c=0;l=0==l||void 0==l?!1:!0,c=parseInt(r.find("input.w").val()),h=parseInt(r.find("input.h").val()),n.hasClass("ajaxing")||jQuery.ajax({url:sis.ajaxUrl,type:"POST",dataType:"json",data:{action:"sis_add_size",width:c,height:h,crop:d,name:o,show:l,customName:u,nonce:a},beforeSend:function(){r.removeClass(),r.addClass("addPending"),n.addClass("ajaxing")},success:function(e){var t="";r.removeClass(),n.removeClass("ajaxing"),0==e?t="errorAdding":2==e?(t="notChangedAdding",i.addToArray(o,c,h,d,t)):(t="successAdding",i.addToArray(o,c,h,d,t)),r.find("input.h").attr({base_h:h}),r.find("input.w").attr({base_w:c}),r.find("select.c").attr({base_c:d}),r.find("input.s").attr({base_s:l}),r.addClass(t),r.find("td").removeClass("notSaved"),r.find(".add_size").removeClass("validate_size").hide().children(".ui-button-text").text(sis.update),clearTimeout(s),s=setTimeout(function(){r.removeClass("errorAdding notChangedAdding successAdding")},2e3)}})},ajaxUnregister:function(e){var t=this,s=jQuery(e).closest("tr").find('input[name="image_name"]').val(),i=jQuery(e).closest("tr").find("input.deleteSize").val();jQuery.ajax({url:sis.ajaxUrl,type:"POST",data:{action:"sis_remove_size",name:s,nonce:i},success:function(s){t.removeFromArray(e)}})},addToArray:function(e,t,s,i,n){var a,r=jQuery("#sis-"+e),o="";o=0!=r.length?r.closest("tr"):jQuery("#sis-regen .wrapper > table#sis_sizes > tbody > tr:first").clone().attr("id","sis-"+e),i=_.isUndefined(sis.crop_positions[i])?sis.fl:sis.crop_positions[i],o.find("th > label").attr("for",e).end().find("input.thumbnails").val(e).attr("id",e).end().find("th:nth-child(2) > label").text(e).end().find("th:nth-child(3) > label").text(t+"px").end().find("th:nth-child(4) > label").text(s+"px").end().find("th:nth-child(5) > label").text(i),0==r.length&&o.appendTo("#sis-regen .wrapper > table#sis_sizes > tbody"),o.removeClass("errorAdding notChangedAdding successAdding").addClass(n),clearTimeout(a),a=setTimeout(function(){o.removeClass("errorAdding notChangedAdding successAdding")},3e3)},removeFromArray:function(e){var t=jQuery(e).closest("tr").find("input[name=image_name]").val();jQuery("#sis-"+t).remove()},displayChange:function(e){var e=jQuery(e),t=e.closest("tr");if(t.hasClass("new_size"))return!1;var s=t.find("input.h"),i=t.find("input.w"),n=t.find("select.c"),a=t.find("input.s"),r=t.find("input.n"),o=s.val(),d=i.val(),l=n.val(),u=a.val(),h=r.val(),c=s.attr("base_h"),p=i.attr("base_w"),g=n.attr("base_c"),m=a.attr("base_s"),f=r.attr("base_n");g="0"==g?!1:!0,m="0"==m?!1:!0,o!=c||d!=p||l!=g||u!=m||h!=f?e.closest("td").addClass("notSaved").find(".add_size").css("display","inline-block"):e.closest("td").removeClass("notSaved").find(".add_size").css("display","none")}},rahe.sis.template=_.memoize(function(e){var t,s={evaluate:/<#([\s\S]+?)#>/g,interpolate:/\{\{\{([\s\S]+?)\}\}\}/g,escape:/\{\{([^\}]+?)\}\}(?!\})/g,variable:"data"};return function(i){return(t=t||_.template(jQuery("#sis-"+e).html(),null,s))(i)}}),jQuery(function(){rahe.sis.regenerate.init();var e=jQuery("#wpbody-content");jQuery("#ajax_thumbnail_rebuild").click(function(){rahe.sis.regenerate.checkStartRegenerating()}),e.on("click","#add_size",function(e){rahe.sis.sizes.add(e,this)}).on("click",".add_size_name",function(e){rahe.sis.sizes.register(e,this)}).on("click",".delete_size",function(e){rahe.sis.sizes.deleteSize(e,this)}).on("click",".add_size",function(e){rahe.sis.sizes.ajaxRegister(e,this)}).on("click keyup change",".h,.w,.c,.s,.n",function(e){rahe.sis.sizes.displayChange(this)}).on("click","#get_php",function(e){rahe.sis.sizes.getPhp(e,this)}),jQuery("#get_php").nextAll("code").hide(),jQuery(".add_size").hide()});
2
+
3
+ //# sourceMappingURL=sis.min.js.map
assets/js/sis.min.js.map ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": 3,
3
+ "file": "sis.min.js",
4
+ "sources": [
5
+ "assets/js/sis.js"
6
+ ],
7
+ "names": [],
8
+ "mappings": "AAAA",
9
+ "sourceRoot": "../../"
10
+ }
classes/admin/main.php CHANGED
@@ -1,331 +1,331 @@
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
  }
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,525 +1,525 @@
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
- }
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,266 +1,266 @@
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
  }
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,61 +1,61 @@
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
  }
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
  }
gulpfile.js ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*Load all plugin define in package.json*/
2
+ var gulp = require('gulp'),
3
+ gulpLoadPlugins = require('gulp-load-plugins'),
4
+ plugins = gulpLoadPlugins(),
5
+ concat = require('gulp-concat-sourcemap');
6
+
7
+ /*JS task*/
8
+ gulp.task('dist', function () {
9
+ gulp.src([
10
+ 'assets/js/sis.js'
11
+ ])
12
+ .pipe(plugins.uglify())
13
+ .pipe(concat('sis.min.js', { sourceRoot : '../../' }))
14
+ .pipe(gulp.dest('assets/js/'));
15
+
16
+ gulp.src([
17
+ 'assets/js/sis-attachments.js'
18
+ ])
19
+ .pipe(plugins.uglify())
20
+ .pipe(concat('sis-attachments.min.js', { sourceRoot : '../../' }))
21
+ .pipe(gulp.dest('assets/js/'));
22
+
23
+ gulp.src([
24
+ 'assets/css/sis-style.css'
25
+ ])
26
+ .pipe(plugins.cssmin())
27
+ .pipe(plugins.rename( { 'suffix' : '.min' } ))
28
+ .pipe(gulp.dest('assets/css/'));
29
+ });
30
+
31
+ gulp.task('dev', function () {
32
+ return gulp.src([
33
+ 'assets/js/sis.js',
34
+ 'assets/js/sis-attachments.js'
35
+ ])
36
+ .pipe(plugins.jshint());
37
+ });
38
+
39
+ // On default task, just compile on demand
40
+ gulp.task('default', function() {
41
+ gulp.watch( [ 'assets/js/*.js', '!assets/js/*.min.js' ], [ 'dev' ] );
42
+ });
package.json CHANGED
@@ -1,13 +1,17 @@
1
- {
2
- "name": "simple-image-sizes",
3
- "version": "3.0.5",
4
- "description": "Simple image sizes for WordPress",
5
- "author": "Nicolas Juen",
6
- "devDependencies": {
7
- "grunt": "~0.4.4",
8
- "grunt-contrib-jshint": "~0.10.0",
9
- "grunt-contrib-uglify": "~0.4.0",
10
- "grunt-contrib-watch":"~0.6.1",
11
- "grunt-contrib-cssmin":"~0.9.0"
12
- }
 
 
 
 
13
  }
1
+ {
2
+ "name": "simple-image-sizes",
3
+ "version": "3.0.7",
4
+ "description": "Simple image sizes for WordPress",
5
+ "author": "Nicolas Juen",
6
+ "devDependencies": {
7
+ "gulp": "*",
8
+ "gulp-concat-sourcemap": "*",
9
+ "gulp-cssmin": "*",
10
+ "gulp-jshint": "*",
11
+ "gulp-load-plugins": "*",
12
+ "gulp-rename": "*",
13
+ "gulp-uglify": "*",
14
+ "gulp-watch": "*",
15
+ "matchdep": "*"
16
+ }
17
  }
readme.txt CHANGED
@@ -1,182 +1,187 @@
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.5
52
- * Fix bug on condition
53
- * 3.0.4
54
- * Fix global add_image_size
55
- * 3.0.3
56
- * Add Hebrew translations thanks to Atar4U
57
- * 3.0.2
58
- * Fix version check for the image crop positions
59
- * 3.0.1
60
- * Change the template render method for non apache webservers : https://wordpress.org/support/topic/fatal-error-1190?replies=6
61
- * Remove ambigious ids for the css bugging WooCommerce : https://wordpress.org/support/topic/bad-css-style-administration and
62
- * Right code for counting the elements on backoffice : https://github.com/Rahe/Simple-image-sizes/issues/20
63
- * Fix bug on regenation and _e instead of __ : https://plugins.trac.wordpress.org/ticket/2259
64
- * 3.0
65
- * Revamping all the code, change classes and structure
66
- * Use grunt for compiling files
67
- * Handle the 3.9 new cropping position
68
- * Remove aristo css
69
- * Use UI from WordPress
70
- * 2.4.3
71
- * Remove some php notices
72
- * Remove notice when wrong image size
73
- * 2.4.2
74
- * Selective regeneration fix by g100g on http://wordpress.org/support/topic/regenerating-fix
75
- * 2.4.1
76
- * Remove function not working on admin file
77
- * 2.4
78
- * Made for 3.5 and up
79
- * Refactoring PHP/Javascript code
80
- * Javascript improvements
81
- * Remove useless UI
82
- * UI improvements
83
- * Global PHP performance improvements
84
- * 2.3.1
85
- * Add Ajax bulk actions on medias list
86
- * Add ajax thumbnail rebuild on single media
87
- * 2.3
88
- * Add the custom size name in the attachment insertion
89
- * Exclude post_type wich do not support the post-thumbnail feature
90
- * 2.2.5
91
- * Debug the regeneration buggy !
92
- * Complete the french translation
93
- * Security update for single regeneration, include the nonce this time :)
94
- * 2.2.4
95
- * Add security nonces for every actions
96
- * Put the messages at the begining of the log
97
- * Add a select all checkbox Thank to cocola
98
- * Add the german translation thanks to glueckpress
99
- * Remove notice tnahks to christianwach
100
- * Remove useless and buggy for my scripting pointers
101
- * 2.2.3
102
- * Do not force network usage
103
- * 2.2.2
104
- * Debug js for the buttons
105
- * Remove console.log calls
106
- * 2.2.1
107
- * Use buttonset for the checkboxes
108
- * Add Pointer for WordPress 3.3
109
- * Fix translation in French
110
- * Some medias queries for small windows ( change size of buttons and alignment )
111
- * 2.2
112
- * Add new version of css aristo
113
- * Add some icons
114
- * Display button for saving changes only when changes detected
115
- * Display message when a size is modified but not saved and wanted to regenerate
116
- * Debug functionnality when regenerating only some sizes, metas not crushed
117
- * Add solo regenerating
118
- * Remove displaying for theme/not theme sizes
119
- * Use WordPress class for small inputs
120
- * 2.1
121
- * Add javascript timer
122
- * Improve javascript and more IE friendly
123
- * You can now choose if you want to display the image sizes in image insertion or not
124
- * Handle errors and messages
125
- * Remove some css useless rules
126
- * Fix bad translation for french
127
- * Remove accents in image sizes
128
- * Do not update size properties if there is an ajax query for an another size name
129
- * 2.0.3
130
- * Resolve issue with theme sizes witch by default are displayed as not cropped. Thanks to momo360modena for the bug signalment.
131
- * 2.0.2
132
- * Remove debug on php for javascript
133
- * Resolve issue with the different versions on jquery ( like in WP3.2 ) with attr return for checked components
134
- * 2.0.1
135
- * Resolve javascript issue when clicking on delete button
136
- * Resolve issue of never unchecking crop button
137
- * 2.0
138
- * Code refactoring
139
- * Update translations
140
- * Ajaxification of the process
141
- * Deleting by Ajax
142
- * Updating by Ajax
143
- * Adding by Ajax
144
- * Change UI
145
- * Change theme
146
- * Handle ajax errors
147
- * Handle not modified sizes, cropped
148
- * Handle same names
149
- * Sanitize the names
150
- * Customize jQuery ui
151
- * Customize jQuery ui theme
152
- * HTML5 Elements
153
- * CSS3 Animations
154
- * 1.0.6
155
- * Minify javascript names
156
- * Change progressbar style
157
- * Add animations on progressbar
158
- * 1.0.5
159
- * Only add css and js script in the media page to avoid any javascript error in other pages
160
- * Rectify css
161
- * Add function to get the code for the function.php file of the theme
162
- * Don't redefine the Wordpress basic size names
163
- * 1.0.4
164
- * Fix the add_image_size issue ( height and width reversed )
165
- * 1.0.3
166
- * Fix the plugin language
167
- * Add some translations
168
- * Externalise some css
169
- * Add sizes in the image adding to an article
170
- * Add setting link in the plugins list
171
- * Use admin_url instead of home_url
172
- * Add legend for colors
173
- * Some code refactoring
174
- * 1.0.2
175
- * Fix the plugin license
176
- * 1.0.1
177
- * Add POT file
178
- * Add french translation
179
- * 1.0
180
- * First release
181
- * Thumbnail regenerate
 
 
 
 
 
182
  * 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.7
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.7
52
+ * Fix bug on single image regeneration upload page
53
+ * Fix bug https://github.com/Rahe/Simple-image-sizes/issues/30
54
+ * 3.0.6
55
+ * Fix bug for the image adding
56
+ * 3.0.5
57
+ * Fix bug on condition
58
+ * 3.0.4
59
+ * Fix global add_image_size
60
+ * 3.0.3
61
+ * Add Hebrew translations thanks to Atar4U
62
+ * 3.0.2
63
+ * Fix version check for the image crop positions
64
+ * 3.0.1
65
+ * Change the template render method for non apache webservers : https://wordpress.org/support/topic/fatal-error-1190?replies=6
66
+ * Remove ambigious ids for the css bugging WooCommerce : https://wordpress.org/support/topic/bad-css-style-administration and
67
+ * Right code for counting the elements on backoffice : https://github.com/Rahe/Simple-image-sizes/issues/20
68
+ * Fix bug on regenation and _e instead of __ : https://plugins.trac.wordpress.org/ticket/2259
69
+ * 3.0
70
+ * Revamping all the code, change classes and structure
71
+ * Use grunt for compiling files
72
+ * Handle the 3.9 new cropping position
73
+ * Remove aristo css
74
+ * Use UI from WordPress
75
+ * 2.4.3
76
+ * Remove some php notices
77
+ * Remove notice when wrong image size
78
+ * 2.4.2
79
+ * Selective regeneration fix by g100g on http://wordpress.org/support/topic/regenerating-fix
80
+ * 2.4.1
81
+ * Remove function not working on admin file
82
+ * 2.4
83
+ * Made for 3.5 and up
84
+ * Refactoring PHP/Javascript code
85
+ * Javascript improvements
86
+ * Remove useless UI
87
+ * UI improvements
88
+ * Global PHP performance improvements
89
+ * 2.3.1
90
+ * Add Ajax bulk actions on medias list
91
+ * Add ajax thumbnail rebuild on single media
92
+ * 2.3
93
+ * Add the custom size name in the attachment insertion
94
+ * Exclude post_type wich do not support the post-thumbnail feature
95
+ * 2.2.5
96
+ * Debug the regeneration buggy !
97
+ * Complete the french translation
98
+ * Security update for single regeneration, include the nonce this time :)
99
+ * 2.2.4
100
+ * Add security nonces for every actions
101
+ * Put the messages at the begining of the log
102
+ * Add a select all checkbox Thank to cocola
103
+ * Add the german translation thanks to glueckpress
104
+ * Remove notice tnahks to christianwach
105
+ * Remove useless and buggy for my scripting pointers
106
+ * 2.2.3
107
+ * Do not force network usage
108
+ * 2.2.2
109
+ * Debug js for the buttons
110
+ * Remove console.log calls
111
+ * 2.2.1
112
+ * Use buttonset for the checkboxes
113
+ * Add Pointer for WordPress 3.3
114
+ * Fix translation in French
115
+ * Some medias queries for small windows ( change size of buttons and alignment )
116
+ * 2.2
117
+ * Add new version of css aristo
118
+ * Add some icons
119
+ * Display button for saving changes only when changes detected
120
+ * Display message when a size is modified but not saved and wanted to regenerate
121
+ * Debug functionnality when regenerating only some sizes, metas not crushed
122
+ * Add solo regenerating
123
+ * Remove displaying for theme/not theme sizes
124
+ * Use WordPress class for small inputs
125
+ * 2.1
126
+ * Add javascript timer
127
+ * Improve javascript and more IE friendly
128
+ * You can now choose if you want to display the image sizes in image insertion or not
129
+ * Handle errors and messages
130
+ * Remove some css useless rules
131
+ * Fix bad translation for french
132
+ * Remove accents in image sizes
133
+ * Do not update size properties if there is an ajax query for an another size name
134
+ * 2.0.3
135
+ * Resolve issue with theme sizes witch by default are displayed as not cropped. Thanks to momo360modena for the bug signalment.
136
+ * 2.0.2
137
+ * Remove debug on php for javascript
138
+ * Resolve issue with the different versions on jquery ( like in WP3.2 ) with attr return for checked components
139
+ * 2.0.1
140
+ * Resolve javascript issue when clicking on delete button
141
+ * Resolve issue of never unchecking crop button
142
+ * 2.0
143
+ * Code refactoring
144
+ * Update translations
145
+ * Ajaxification of the process
146
+ * Deleting by Ajax
147
+ * Updating by Ajax
148
+ * Adding by Ajax
149
+ * Change UI
150
+ * Change theme
151
+ * Handle ajax errors
152
+ * Handle not modified sizes, cropped
153
+ * Handle same names
154
+ * Sanitize the names
155
+ * Customize jQuery ui
156
+ * Customize jQuery ui theme
157
+ * HTML5 Elements
158
+ * CSS3 Animations
159
+ * 1.0.6
160
+ * Minify javascript names
161
+ * Change progressbar style
162
+ * Add animations on progressbar
163
+ * 1.0.5
164
+ * Only add css and js script in the media page to avoid any javascript error in other pages
165
+ * Rectify css
166
+ * Add function to get the code for the function.php file of the theme
167
+ * Don't redefine the Wordpress basic size names
168
+ * 1.0.4
169
+ * Fix the add_image_size issue ( height and width reversed )
170
+ * 1.0.3
171
+ * Fix the plugin language
172
+ * Add some translations
173
+ * Externalise some css
174
+ * Add sizes in the image adding to an article
175
+ * Add setting link in the plugins list
176
+ * Use admin_url instead of home_url
177
+ * Add legend for colors
178
+ * Some code refactoring
179
+ * 1.0.2
180
+ * Fix the plugin license
181
+ * 1.0.1
182
+ * Add POT file
183
+ * Add french translation
184
+ * 1.0
185
+ * First release
186
+ * Thumbnail regenerate
187
  * Image size generation
simple_image_sizes.php CHANGED
@@ -1,62 +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.5
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.5' );
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
  }
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.7
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.7' );
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
  }
templates/options-media.php CHANGED
@@ -1,139 +1,152 @@
1
  <?php
2
  // Get the sizes
3
- global $_wp_additional_image_sizes,$_wp_post_type_features;
4
  ?>
5
- <input type="hidden" class="addSize" value='<?php echo wp_create_nonce( 'add_size' ); ?>' />
6
- <input type="hidden" class="regen" value='<?php echo wp_create_nonce( 'regen' ); ?>' />
7
- <input type="hidden" class="getList" value='<?php echo wp_create_nonce( 'getList' ); ?>' />
8
- <div id="sis-regen">
9
- <div class="wrapper" style="">
10
- <h4> <?php _e( 'Select which thumbnails you want to rebuild:', 'simple-image-sizes'); ?> </h4>
11
- <table cellspacing="0" id="sis_sizes" class="widefat page fixed sis">
12
- <thead>
13
- <tr>
14
- <th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input checked="checked" type="checkbox"></th>
15
- <th class="manage-column" scope="col"><?php _e( 'Size name', 'simple-image-sizes'); ?></th>
16
- <th class="manage-column" scope="col"><?php _e( 'Width', 'simple-image-sizes'); ?></th>
17
- <th class="manage-column" scope="col"><?php _e( 'Height', 'simple-image-sizes'); ?></th>
18
- <th class="manage-column" scope="col"><?php _e( 'Crop ?', 'simple-image-sizes'); ?></th>
19
- </tr>
20
- </thead>
21
- <tbody>
22
- <?php
23
- // Display the sizes in the array
24
- foreach ( get_intermediate_image_sizes() as $s ):
25
- // Don't make or numeric sizes that appear
26
- if( is_integer( $s ) ) {
27
- continue;
28
- }
29
-
30
- // Set width
31
- $width = isset( $_wp_additional_image_sizes[$s]['width'] ) ? intval( $_wp_additional_image_sizes[$s]['width'] ) : get_option( "{$s}_size_w" ) ;
32
-
33
- // Set height
34
- $height = isset( $_wp_additional_image_sizes[$s]['height'] ) ? intval( $_wp_additional_image_sizes[$s]['height'] ) : get_option( "{$s}_size_h" ) ;
35
-
36
- //Set crop
37
- $crop = isset( $_wp_additional_image_sizes[$s]['crop'] ) ? $_wp_additional_image_sizes[$s]['crop'] : get_option( "{$s}_crop" ) ;
38
- if( is_numeric( $crop ) || is_bool( $crop ) ) {
39
- $crop = absint( $crop ) > 0 ? __( 'Yes', 'simple-image-sizes' ) : __( 'No', 'simple-image-sizes' ) ;
40
- } else {
41
- $crop = Sis_Admin_Main::get_crop_position_label( $crop );
42
- }
43
-
44
- ?>
45
- <tr id="sis-<?php echo esc_attr( $s ) ?>">
46
- <th class="check-column">
47
- <input type="checkbox" class="thumbnails" id="<?php echo esc_attr( $s ) ?>" name="thumbnails[]" checked="checked" value="<?php echo esc_attr( $s ); ?>" />
48
- </th>
49
- <th>
50
- <label for="<?php esc_attr_e( $s ); ?>"><?php echo esc_html( $s ); ?></label>
51
- </th>
52
- <th>
53
- <label for="<?php esc_attr_e( $s ); ?>"><?php echo esc_html( $width ); ?> px</label>
54
- </th>
55
- <th>
56
- <label for="<?php esc_attr_e( $s ); ?>"><?php echo esc_html( $height ); ?> px</label>
57
- </th>
58
- <th>
59
- <label for="<?php esc_attr_e( $s ); ?>"><?php echo $crop; ?> </label>
60
- </th>
61
- </tr>
62
- <?php endforeach;?>
63
- </tbody>
64
- <tfoot>
65
- <tr>
66
- <th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input checked="checked" type="checkbox"></th>
67
- <th class="manage-column" scope="col"><?php _e( 'Size name', 'simple-image-sizes'); ?></th>
68
- <th class="manage-column" scope="col"><?php _e( 'Width', 'simple-image-sizes'); ?></th>
69
- <th class="manage-column" scope="col"><?php _e( 'Height', 'simple-image-sizes'); ?></th>
70
- <th class="manage-column" scope="col"><?php _e( 'Crop ?', 'simple-image-sizes'); ?></th>
71
- </tr>
72
- </tfoot>
73
- </table>
74
-
75
- <h4><?php _e( 'Select which post type source thumbnails you want to rebuild:', 'simple-image-sizes'); ?></h4>
76
- <table cellspacing="0" class="widefat page fixed sis">
77
- <thead>
78
- <tr>
79
- <th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input checked="checked" type="checkbox"></th>
80
- <th class="manage-column" scope="col"><?php _e( 'Post type', 'simple-image-sizes'); ?></th>
81
- </tr>
82
- </thead>
83
- <tbody>
84
- <?php
85
- // Diplay the post types table
86
- foreach ( get_post_types( array( 'public' => true ), 'objects' ) as $ptype ):
87
- // Avoid the post_types without post thumbnails feature
88
- if( !array_key_exists( 'thumbnail' , $_wp_post_type_features[$ptype->name] ) || $_wp_post_type_features[$ptype->name] == false ) {
89
- continue;
90
- }
91
- ?>
92
- <tr>
93
- <th class="check-column">
94
- <label for="<?php esc_attr_e( $ptype->name ); ?>">
95
- <input type="checkbox" class="post_types" name="post_types[]" checked="checked" id="<?php echo esc_attr( $ptype->name ); ?>" value="<?php echo esc_attr( $ptype->name ); ?>" />
96
- </label>
97
- </th>
98
- <th>
99
- <label for="<?php esc_attr_e( $ptype->name ); ?>"><em><?php echo esc_html( $ptype->labels->name ); ?></em></label>
100
- </th>
101
- </tr>
102
- <?php endforeach;?>
103
- </tbody>
104
- <tfoot>
105
- <tr>
106
- <th scope="col" id="cb" class="manage-column column-cb check-column"><input checked="checked" type="checkbox"></th>
107
- <th class="manage-column" scope="col"><?php _e( 'Post type', 'simple-image-sizes'); ?></th>
108
- </tr>
109
- </tfoot>
110
- </table>
111
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  </div>
113
- <div class="sis" >
114
- <div class="regenerate_message"></div>
115
- <div class="media-item sis">
116
- <div class="progress">
117
- <div id="sis_progress-percent" class="percent">100%</div>
118
- <div class="bar"></div>
119
- </div>
120
- </div>
121
-
122
- <div class="ui-widget time">
123
- <div class="ui-state-highlight ui-corner-all">
124
- <p>
125
- <span class="ui-icon ui-icon-info"></span>
126
- <span><strong><?php _e( 'End time calculated :', 'simple-image-sizes' ); ?></strong> <span class='time_message'><?php _e( 'Calculating...', 'simple-image-sizes' ) ?></span> </span>
127
- </p>
128
- <ul class="messages"></ul>
129
- </div>
130
- </div>
131
- <div id="error_messages">
132
- <p>
133
- <ol class="messages">
134
- </ol>
135
- </p>
136
- </div>
137
- <div class="thumb"><h4><?php _e( 'Last image:', 'simple-image-sizes'); ?></h4><img class="thumb-img" /></div>
138
- <input type="button" class="button" name="ajax_thumbnail_rebuild" id="ajax_thumbnail_rebuild" value="<?php _e( 'Regenerate Thumbnails', 'simple-image-sizes' ) ?>" />
139
- </div>
1
  <?php
2
  // Get the sizes
3
+ global $_wp_additional_image_sizes, $_wp_post_type_features;
4
  ?>
5
+ <input type="hidden" class="addSize" value='<?php echo wp_create_nonce( 'add_size' ); ?>'/>
6
+ <input type="hidden" class="regen" value='<?php echo wp_create_nonce( 'regen' ); ?>'/>
7
+ <input type="hidden" class="getList" value='<?php echo wp_create_nonce( 'getList' ); ?>'/>
8
+ <div id="sis-regen">
9
+ <div class="wrapper" style="">
10
+ <h4> <?php _e( 'Select which thumbnails you want to rebuild:', 'simple-image-sizes' ); ?> </h4>
11
+ <table cellspacing="0" id="sis_sizes" class="widefat page fixed sis">
12
+ <thead>
13
+ <tr>
14
+ <th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input checked="checked"
15
+ type="checkbox">
16
+ </th>
17
+ <th class="manage-column" scope="col"><?php _e( 'Size name', 'simple-image-sizes' ); ?></th>
18
+ <th class="manage-column" scope="col"><?php _e( 'Width', 'simple-image-sizes' ); ?></th>
19
+ <th class="manage-column" scope="col"><?php _e( 'Height', 'simple-image-sizes' ); ?></th>
20
+ <th class="manage-column" scope="col"><?php _e( 'Crop ?', 'simple-image-sizes' ); ?></th>
21
+ </tr>
22
+ </thead>
23
+ <tbody>
24
+ <?php
25
+ // Display the sizes in the array
26
+ foreach ( get_intermediate_image_sizes() as $s ):
27
+ // Don't make or numeric sizes that appear
28
+ if ( is_integer( $s ) ) {
29
+ continue;
30
+ }
31
+
32
+ // Set width
33
+ $width = isset( $_wp_additional_image_sizes[ $s ]['width'] ) ? intval( $_wp_additional_image_sizes[ $s ]['width'] ) : get_option( "{$s}_size_w" );
34
+
35
+ // Set height
36
+ $height = isset( $_wp_additional_image_sizes[ $s ]['height'] ) ? intval( $_wp_additional_image_sizes[ $s ]['height'] ) : get_option( "{$s}_size_h" );
37
+
38
+ //Set crop
39
+ $crop = isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ? $_wp_additional_image_sizes[ $s ]['crop'] : get_option( "{$s}_crop" );
40
+ if ( is_numeric( $crop ) || is_bool( $crop ) ) {
41
+ $crop = absint( $crop ) > 0 ? __( 'Yes', 'simple-image-sizes' ) : __( 'No', 'simple-image-sizes' );
42
+ } else {
43
+ $crop = Sis_Admin_Main::get_crop_position_label( implode( '_', $crop ) );
44
+ }
45
+
46
+ ?>
47
+ <tr id="sis-<?php echo esc_attr( $s ) ?>">
48
+ <th class="check-column">
49
+ <input type="checkbox" class="thumbnails" id="<?php echo esc_attr( $s ) ?>" name="thumbnails[]"
50
+ checked="checked" value="<?php echo esc_attr( $s ); ?>"/>
51
+ </th>
52
+ <th>
53
+ <label for="<?php esc_attr_e( $s ); ?>"><?php echo esc_html( $s ); ?></label>
54
+ </th>
55
+ <th>
56
+ <label for="<?php esc_attr_e( $s ); ?>"><?php echo esc_html( $width ); ?> px</label>
57
+ </th>
58
+ <th>
59
+ <label for="<?php esc_attr_e( $s ); ?>"><?php echo esc_html( $height ); ?> px</label>
60
+ </th>
61
+ <th>
62
+ <label for="<?php esc_attr_e( $s ); ?>"><?php echo $crop; ?> </label>
63
+ </th>
64
+ </tr>
65
+ <?php endforeach; ?>
66
+ </tbody>
67
+ <tfoot>
68
+ <tr>
69
+ <th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input checked="checked"
70
+ type="checkbox">
71
+ </th>
72
+ <th class="manage-column" scope="col"><?php _e( 'Size name', 'simple-image-sizes' ); ?></th>
73
+ <th class="manage-column" scope="col"><?php _e( 'Width', 'simple-image-sizes' ); ?></th>
74
+ <th class="manage-column" scope="col"><?php _e( 'Height', 'simple-image-sizes' ); ?></th>
75
+ <th class="manage-column" scope="col"><?php _e( 'Crop ?', 'simple-image-sizes' ); ?></th>
76
+ </tr>
77
+ </tfoot>
78
+ </table>
79
+
80
+ <h4><?php _e( 'Select which post type source thumbnails you want to rebuild:', 'simple-image-sizes' ); ?></h4>
81
+ <table cellspacing="0" class="widefat page fixed sis">
82
+ <thead>
83
+ <tr>
84
+ <th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input checked="checked"
85
+ type="checkbox">
86
+ </th>
87
+ <th class="manage-column" scope="col"><?php _e( 'Post type', 'simple-image-sizes' ); ?></th>
88
+ </tr>
89
+ </thead>
90
+ <tbody>
91
+ <?php
92
+ // Diplay the post types table
93
+ foreach ( get_post_types( array( 'public' => true ), 'objects' ) as $ptype ):
94
+ // Avoid the post_types without post thumbnails feature
95
+ if ( ! isset ( $_wp_post_type_features[ $ptype->name ] ) || ! array_key_exists( 'thumbnail', $_wp_post_type_features[ $ptype->name ] ) || false == $_wp_post_type_features[ $ptype->name ] ) {
96
+ continue;
97
+ }
98
+ ?>
99
+ <tr>
100
+ <th class="check-column">
101
+ <label for="<?php esc_attr_e( $ptype->name ); ?>">
102
+ <input type="checkbox" class="post_types" name="post_types[]" checked="checked"
103
+ id="<?php echo esc_attr( $ptype->name ); ?>"
104
+ value="<?php echo esc_attr( $ptype->name ); ?>"/>
105
+ </label>
106
+ </th>
107
+ <th>
108
+ <label
109
+ for="<?php esc_attr_e( $ptype->name ); ?>"><em><?php echo esc_html( $ptype->labels->name ); ?></em></label>
110
+ </th>
111
+ </tr>
112
+ <?php endforeach; ?>
113
+ </tbody>
114
+ <tfoot>
115
+ <tr>
116
+ <th scope="col" id="cb" class="manage-column column-cb check-column"><input checked="checked"
117
+ type="checkbox"></th>
118
+ <th class="manage-column" scope="col"><?php _e( 'Post type', 'simple-image-sizes' ); ?></th>
119
+ </tr>
120
+ </tfoot>
121
+ </table>
122
+ </div>
123
+ </div>
124
+ <div class="sis">
125
+ <div class="regenerate_message"></div>
126
+ <div class="media-item sis">
127
+ <div class="progress">
128
+ <div id="sis_progress-percent" class="percent">100%</div>
129
+ <div class="bar"></div>
130
  </div>
131
+ </div>
132
+
133
+ <div class="ui-widget time">
134
+ <div class="ui-state-highlight ui-corner-all">
135
+ <p>
136
+ <span class="ui-icon ui-icon-info"></span>
137
+ <span><strong><?php _e( 'End time calculated :', 'simple-image-sizes' ); ?></strong> <span
138
+ class='time_message'><?php _e( 'Calculating...', 'simple-image-sizes' ) ?></span> </span>
139
+ </p>
140
+ <ul class="messages"></ul>
141
+ </div>
142
+ </div>
143
+ <div id="error_messages">
144
+ <p>
145
+ <ol class="messages">
146
+ </ol>
147
+ </p>
148
+ </div>
149
+ <div class="thumb"><h4><?php _e( 'Last image:', 'simple-image-sizes' ); ?></h4><img class="thumb-img"/></div>
150
+ <input type="button" class="button" name="ajax_thumbnail_rebuild" id="ajax_thumbnail_rebuild"
151
+ value="<?php _e( 'Regenerate Thumbnails', 'simple-image-sizes' ) ?>"/>
152
+ </div>