Version Description
- Problem with SVN commit of 1.0.1
Download this release
Release Info
Developer | sewpafly |
Plugin | Post Thumbnail Editor |
Version | 1.0.2 |
Comparing to | |
See all releases |
Code changes from version 1.0.1 to 1.0.2
- README.txt +6 -0
- php/functions.php +127 -61
- post-thumbnail-editor.php +2 -2
README.txt
CHANGED
@@ -63,6 +63,9 @@ Using a version with [json_encode](http://www.php.net/manual/en/function.json-en
|
|
63 |
|
64 |
== Changelog ==
|
65 |
|
|
|
|
|
|
|
66 |
= 1.0.1 =
|
67 |
* Fixed compatibility with other thickbox enabled plugins that called the wordpress media scripts.
|
68 |
* Added Options screen (Settings -> Post Thumbnail Editor) to configure thickbox dimensions and enable/disable debugging.
|
@@ -85,6 +88,9 @@ Using a version with [json_encode](http://www.php.net/manual/en/function.json-en
|
|
85 |
|
86 |
== Upgrade Notice ==
|
87 |
|
|
|
|
|
|
|
88 |
= 1.0.1 =
|
89 |
Added translation support, french language, options menu and fixed incompatibility with other thickbox enabled plugins.
|
90 |
|
63 |
|
64 |
== Changelog ==
|
65 |
|
66 |
+
= 1.0.2 =
|
67 |
+
* Problem with SVN commit of 1.0.1
|
68 |
+
|
69 |
= 1.0.1 =
|
70 |
* Fixed compatibility with other thickbox enabled plugins that called the wordpress media scripts.
|
71 |
* Added Options screen (Settings -> Post Thumbnail Editor) to configure thickbox dimensions and enable/disable debugging.
|
88 |
|
89 |
== Upgrade Notice ==
|
90 |
|
91 |
+
= 1.0.2 =
|
92 |
+
Problem with SVN commit of 1.0.1
|
93 |
+
|
94 |
= 1.0.1 =
|
95 |
Added translation support, french language, options menu and fixed incompatibility with other thickbox enabled plugins.
|
96 |
|
php/functions.php
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
function pte_require_json() {
|
4 |
if ( function_exists( 'ob_start' ) ){
|
@@ -8,21 +13,36 @@ function pte_require_json() {
|
|
8 |
|
9 |
/*
|
10 |
* This is used to output JSON
|
|
|
11 |
*/
|
12 |
function pte_json_encode($mixed = null){
|
13 |
-
|
|
|
|
|
14 |
// If a buffer was started this will check for any residual output
|
15 |
// and add to the existing errors.
|
16 |
if ( function_exists( 'ob_get_flush' ) ){
|
17 |
$buffer = ob_get_clean();
|
18 |
if ( isset( $buffer ) && strlen( $buffer ) > 0 ){
|
19 |
-
|
20 |
}
|
21 |
}
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
if ( ! function_exists('json_encode') ){
|
24 |
-
|
25 |
-
$messages = implode( "\r\n", $
|
26 |
die("{\"error\":\"{$messages}\"}");
|
27 |
}
|
28 |
|
@@ -30,11 +50,12 @@ function pte_json_encode($mixed = null){
|
|
30 |
$mixed = array();
|
31 |
}
|
32 |
else if ( ! is_array( $mixed ) ){
|
33 |
-
$mixed = array($mixed);
|
34 |
}
|
35 |
|
36 |
-
|
37 |
-
|
|
|
38 |
}
|
39 |
|
40 |
print( json_encode($mixed) );
|
@@ -42,32 +63,14 @@ function pte_json_encode($mixed = null){
|
|
42 |
}
|
43 |
|
44 |
/*
|
45 |
-
* pte_json_error
|
46 |
*/
|
47 |
-
function pte_json_error($error){
|
48 |
-
|
|
|
49 |
return pte_json_encode();
|
50 |
}
|
51 |
|
52 |
-
/*
|
53 |
-
* pte_add_error
|
54 |
-
*/
|
55 |
-
function pte_add_error($error){
|
56 |
-
global $pte_errors;
|
57 |
-
if ( ! isset( $pte_errors ) || ! is_array( $pte_errors ) ){
|
58 |
-
$pte_errors = array();
|
59 |
-
}
|
60 |
-
|
61 |
-
if ( !in_array( $error, $pte_errors ) ){
|
62 |
-
if ( is_string( $error ) ){
|
63 |
-
$pte_errors[] = $error;
|
64 |
-
}
|
65 |
-
else if ( is_array( $error ) ){
|
66 |
-
$pte_errors = array_merge( $error, $pte_errors );
|
67 |
-
}
|
68 |
-
}
|
69 |
-
}
|
70 |
-
|
71 |
/*
|
72 |
* pte_filter_sizes
|
73 |
*
|
@@ -76,7 +79,10 @@ function pte_add_error($error){
|
|
76 |
*/
|
77 |
function pte_filter_sizes( $element ){
|
78 |
global $pte_sizes;
|
79 |
-
|
|
|
|
|
|
|
80 |
){
|
81 |
return false;
|
82 |
}
|
@@ -93,12 +99,22 @@ function pte_filter_sizes( $element ){
|
|
93 |
*
|
94 |
* Thanks to the ajax_thumbnail_rebuild plugin
|
95 |
*/
|
96 |
-
function pte_get_alternate_sizes(){
|
97 |
//Put in some code to check if it's already been called...
|
98 |
global $_wp_additional_image_sizes, $pte_gas;
|
99 |
if ( !isset($pte_gas) ){
|
100 |
$pte_gas = array();
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
if ( isset( $_wp_additional_image_sizes[$s]['width'] ) ) // For theme-added sizes
|
103 |
$width = intval( $_wp_additional_image_sizes[$s]['width'] );
|
104 |
else // For default sizes set in options
|
@@ -130,6 +146,7 @@ function pte_get_alternate_sizes(){
|
|
130 |
* Optionally can return the JSON value or PHP array
|
131 |
*/
|
132 |
function pte_get_image_data( $id, $size, $size_data ){
|
|
|
133 |
|
134 |
$fullsizepath = get_attached_file( $id );
|
135 |
$path_information = image_get_intermediate_size($id, $size);
|
@@ -137,12 +154,8 @@ function pte_get_image_data( $id, $size, $size_data ){
|
|
137 |
if ( $path_information &&
|
138 |
@file_exists( dirname( $fullsizepath ) . DIRECTORY_SEPARATOR . $path_information['file'] )
|
139 |
){
|
140 |
-
//print_r( $path_information );
|
141 |
return $path_information;
|
142 |
}
|
143 |
-
//print("NOPE, no path information...");
|
144 |
-
//print_r($path_information);
|
145 |
-
//print("END PI");
|
146 |
|
147 |
// We don't really care how it gets generated, just that it is...
|
148 |
// see ajax-thumbnail-rebuild plugin for inspiration
|
@@ -166,7 +179,7 @@ function pte_get_image_data( $id, $size, $size_data ){
|
|
166 |
return $path_information;
|
167 |
}
|
168 |
else {
|
169 |
-
|
170 |
}
|
171 |
return false;
|
172 |
}
|
@@ -184,6 +197,22 @@ function pte_get_all_alternate_size_information( $id ){
|
|
184 |
return $sizes;
|
185 |
}
|
186 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
/*
|
188 |
* pte_launch
|
189 |
*
|
@@ -192,17 +221,19 @@ function pte_get_all_alternate_size_information( $id ){
|
|
192 |
* Requires post id as $_GET['id']
|
193 |
*/
|
194 |
function pte_launch(){
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
// , '1.0.0pre'
|
199 |
-
//);
|
200 |
-
if ( PTE_DEBUG ) {
|
201 |
wp_enqueue_script( 'pte'
|
202 |
, PTE_PLUGINURL . 'js/pte.full.js'
|
203 |
, array('jquery','imgareaselect')
|
204 |
, PTE_VERSION
|
205 |
);
|
|
|
|
|
|
|
|
|
|
|
206 |
wp_enqueue_style( 'pte'
|
207 |
, PTE_PLUGINURL . 'css/pte.css'
|
208 |
, array('imgareaselect')
|
@@ -221,6 +252,13 @@ function pte_launch(){
|
|
221 |
, PTE_VERSION
|
222 |
);
|
223 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
|
225 |
$id = pte_check_id((int) $_GET['id']);
|
226 |
|
@@ -236,24 +274,26 @@ function pte_launch(){
|
|
236 |
|
237 |
$sizer = $big > 400 ? 400 / $big : 1;
|
238 |
|
239 |
-
require( PTE_PLUGINPATH . "html/pte.
|
240 |
}
|
241 |
|
242 |
function pte_check_id( $id ){
|
|
|
243 |
if ( !$post =& get_post( $id ) ){
|
244 |
-
|
245 |
return false;
|
246 |
}
|
247 |
if ( !current_user_can( 'edit_post', $id ) ){
|
248 |
-
|
249 |
return false;
|
250 |
}
|
251 |
return $id;
|
252 |
}
|
253 |
|
254 |
function pte_check_int( $int ){
|
|
|
255 |
if (! is_numeric( $int ) ){
|
256 |
-
|
257 |
return false;
|
258 |
}
|
259 |
return $int;
|
@@ -307,10 +347,11 @@ function pte_create_image($original_image, $type,
|
|
307 |
$dst_x, $dst_y, $dst_w, $dst_h,
|
308 |
$src_x, $src_y, $src_w, $src_h )
|
309 |
{
|
310 |
-
$
|
|
|
|
|
311 |
|
312 |
-
|
313 |
-
// 'src_x','src_y','src_w','src_h' ) );
|
314 |
|
315 |
imagecopyresampled( $new_image, $original_image,
|
316 |
$dst_x, $dst_y, $src_x, $src_y,
|
@@ -329,29 +370,31 @@ function pte_create_image($original_image, $type,
|
|
329 |
}
|
330 |
|
331 |
function pte_write_image( $image, $orig_type, $destfilename ){
|
|
|
|
|
332 |
$dir = dirname( $destfilename );
|
333 |
if ( ! is_dir( $dir ) ){
|
334 |
if ( ! mkdir( $dir, 0777, true ) ){
|
335 |
-
|
336 |
}
|
337 |
}
|
338 |
|
339 |
if ( IMAGETYPE_GIF == $orig_type ) {
|
340 |
if ( !imagegif( $image, $destfilename ) ){
|
341 |
-
|
342 |
return false;
|
343 |
}
|
344 |
}
|
345 |
elseif ( IMAGETYPE_PNG == $orig_type ) {
|
346 |
if ( !imagepng( $image, $destfilename ) ){
|
347 |
-
|
348 |
return false;
|
349 |
}
|
350 |
}
|
351 |
else {
|
352 |
// all other formats are converted to jpg
|
353 |
if ( !imagejpeg( $image, $destfilename, 90) ){
|
354 |
-
|
355 |
return false;
|
356 |
}
|
357 |
}
|
@@ -376,6 +419,7 @@ function pte_write_image( $image, $orig_type, $destfilename ){
|
|
376 |
* OUTPUT: JSON object 'size: url'
|
377 |
*/
|
378 |
function pte_resize_images(){
|
|
|
379 |
global $pte_sizes;
|
380 |
|
381 |
// Require JSON output
|
@@ -415,6 +459,7 @@ function pte_resize_images(){
|
|
415 |
return pte_json_error("Could not read image size");
|
416 |
}
|
417 |
|
|
|
418 |
list( $orig_w, $orig_h, $orig_type ) = $original_size;
|
419 |
// *** End common-info
|
420 |
|
@@ -436,12 +481,12 @@ function pte_resize_images(){
|
|
436 |
$x, $y, $w, $h );
|
437 |
|
438 |
if ( ! isset( $image ) ){
|
439 |
-
|
440 |
continue;
|
441 |
}
|
442 |
|
443 |
if ( ! pte_write_image( $image, $orig_type, $tmpfile ) ){
|
444 |
-
|
445 |
continue;
|
446 |
}
|
447 |
// === END CREATE IMAGE ===============
|
@@ -476,7 +521,8 @@ function pte_resize_images(){
|
|
476 |
* Clean up and return error/success information...
|
477 |
*/
|
478 |
function pte_confirm_images(){
|
479 |
-
global $pte_sizes
|
|
|
480 |
|
481 |
// Require JSON output
|
482 |
pte_require_json();
|
@@ -495,6 +541,8 @@ function pte_confirm_images(){
|
|
495 |
if ( is_array( $_GET['pte-confirm'] ) ){
|
496 |
$pte_sizes = array_keys( $_GET['pte-confirm'] );
|
497 |
$sizes = pte_get_all_alternate_size_information( $id );
|
|
|
|
|
498 |
}
|
499 |
else {
|
500 |
return pte_json_error( "Invalid Parameters: can't find sizes" );
|
@@ -529,6 +577,7 @@ function pte_confirm_images(){
|
|
529 |
}
|
530 |
|
531 |
// Move good image
|
|
|
532 |
rename( $good_file, $new_file );
|
533 |
|
534 |
// Update metadata
|
@@ -542,7 +591,7 @@ function pte_confirm_images(){
|
|
542 |
'width' => $w,
|
543 |
'height' => $h
|
544 |
);
|
545 |
-
|
546 |
wp_update_attachment_metadata( $id, $metadata);
|
547 |
|
548 |
// Delete/unlink old file
|
@@ -550,15 +599,30 @@ function pte_confirm_images(){
|
|
550 |
&& $old_file !== $new_file
|
551 |
&& file_exists( $old_file ) )
|
552 |
{
|
553 |
-
|
554 |
unlink( $old_file );
|
555 |
}
|
556 |
}
|
557 |
// Delete tmpdir
|
558 |
-
|
559 |
return pte_json_encode( array( 'success' => "Yay!" ) );
|
560 |
}
|
561 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
562 |
function pte_delete_images()
|
563 |
{
|
564 |
// Require JSON output
|
@@ -575,6 +639,8 @@ function pte_delete_images()
|
|
575 |
$uploads = wp_upload_dir();
|
576 |
$PTE_TMP_DIR = $uploads['basedir'] . DIRECTORY_SEPARATOR . "ptetmp" . DIRECTORY_SEPARATOR . $id;
|
577 |
// Delete tmpdir
|
578 |
-
|
579 |
return pte_json_encode( array( "success" => "Yay!" ) );
|
580 |
}
|
|
|
|
1 |
<?php
|
2 |
+
/*
|
3 |
+
* TODO: add helper functions to get various links to different functions
|
4 |
+
*/
|
5 |
+
|
6 |
+
require_once( "log.php" );
|
7 |
|
8 |
function pte_require_json() {
|
9 |
if ( function_exists( 'ob_start' ) ){
|
13 |
|
14 |
/*
|
15 |
* This is used to output JSON
|
16 |
+
* - Calling this should return all the way up the chain...
|
17 |
*/
|
18 |
function pte_json_encode($mixed = null){
|
19 |
+
$logger = PteLogger::singleton();
|
20 |
+
$options = pte_get_options();
|
21 |
+
|
22 |
// If a buffer was started this will check for any residual output
|
23 |
// and add to the existing errors.
|
24 |
if ( function_exists( 'ob_get_flush' ) ){
|
25 |
$buffer = ob_get_clean();
|
26 |
if ( isset( $buffer ) && strlen( $buffer ) > 0 ){
|
27 |
+
$logger->warn( "Buffered output: {$buffer}" );
|
28 |
}
|
29 |
}
|
30 |
|
31 |
+
if ( $logger->get_log_count( PteLogMessage::$ERROR ) > 0
|
32 |
+
|| $logger->get_log_count( PteLogMessage::$WARN ) > 0 )
|
33 |
+
{
|
34 |
+
$logs['error'] = $logger->get_logs( PteLogMessage::$ERROR | PteLogMessage::$WARN );
|
35 |
+
}
|
36 |
+
//if ( $logger->get_log_count( PteLogMessage::$WARN ) > 0 ){
|
37 |
+
// $logs['warn'] = $logger->get_logs( PteLogMessage::$WARN );
|
38 |
+
//}
|
39 |
+
if ( $options['pte_debug'] ){
|
40 |
+
$logs['log'] = $logger->get_logs();
|
41 |
+
}
|
42 |
+
|
43 |
if ( ! function_exists('json_encode') ){
|
44 |
+
$logs['error'][] = "json_encode not available, upgrade your php";
|
45 |
+
$messages = implode( "\r\n", $logs['error'] );
|
46 |
die("{\"error\":\"{$messages}\"}");
|
47 |
}
|
48 |
|
50 |
$mixed = array();
|
51 |
}
|
52 |
else if ( ! is_array( $mixed ) ){
|
53 |
+
$mixed = array('noarray' => $mixed);
|
54 |
}
|
55 |
|
56 |
+
|
57 |
+
if ( count( $logs['error'] )+count( $logs['log'] ) > 0 ){
|
58 |
+
$mixed = array_merge_recursive( $mixed, $logs );
|
59 |
}
|
60 |
|
61 |
print( json_encode($mixed) );
|
63 |
}
|
64 |
|
65 |
/*
|
66 |
+
* pte_json_error - Calling this should return all the way up the chain...
|
67 |
*/
|
68 |
+
function pte_json_error( $error ){
|
69 |
+
$logger = PteLogger::singleton();
|
70 |
+
$logger->error( $error );
|
71 |
return pte_json_encode();
|
72 |
}
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
/*
|
75 |
* pte_filter_sizes
|
76 |
*
|
79 |
*/
|
80 |
function pte_filter_sizes( $element ){
|
81 |
global $pte_sizes;
|
82 |
+
$options = pte_get_options();
|
83 |
+
// Check if the element is in the pte_sizes array
|
84 |
+
if ( ( is_array( $pte_sizes ) && !in_array( $element, $pte_sizes ) )
|
85 |
+
or ( in_array( $element, $options['pte_hidden_sizes'] ) )
|
86 |
){
|
87 |
return false;
|
88 |
}
|
99 |
*
|
100 |
* Thanks to the ajax_thumbnail_rebuild plugin
|
101 |
*/
|
102 |
+
function pte_get_alternate_sizes($filter=true){
|
103 |
//Put in some code to check if it's already been called...
|
104 |
global $_wp_additional_image_sizes, $pte_gas;
|
105 |
if ( !isset($pte_gas) ){
|
106 |
$pte_gas = array();
|
107 |
+
$sizes = array();
|
108 |
+
|
109 |
+
// Some times we don't want the filter to run (in admin for example)
|
110 |
+
if ($filter){
|
111 |
+
$sizes = array_filter( get_intermediate_image_sizes(), 'pte_filter_sizes' );
|
112 |
+
}
|
113 |
+
else{
|
114 |
+
$sizes = get_intermediate_image_sizes();
|
115 |
+
}
|
116 |
+
|
117 |
+
foreach ($sizes as $s){
|
118 |
if ( isset( $_wp_additional_image_sizes[$s]['width'] ) ) // For theme-added sizes
|
119 |
$width = intval( $_wp_additional_image_sizes[$s]['width'] );
|
120 |
else // For default sizes set in options
|
146 |
* Optionally can return the JSON value or PHP array
|
147 |
*/
|
148 |
function pte_get_image_data( $id, $size, $size_data ){
|
149 |
+
$logger = PteLogger::singleton();
|
150 |
|
151 |
$fullsizepath = get_attached_file( $id );
|
152 |
$path_information = image_get_intermediate_size($id, $size);
|
154 |
if ( $path_information &&
|
155 |
@file_exists( dirname( $fullsizepath ) . DIRECTORY_SEPARATOR . $path_information['file'] )
|
156 |
){
|
|
|
157 |
return $path_information;
|
158 |
}
|
|
|
|
|
|
|
159 |
|
160 |
// We don't really care how it gets generated, just that it is...
|
161 |
// see ajax-thumbnail-rebuild plugin for inspiration
|
179 |
return $path_information;
|
180 |
}
|
181 |
else {
|
182 |
+
$logger->warn( "Couldn't find or generate metadata for image: {$id}-{$size}" );
|
183 |
}
|
184 |
return false;
|
185 |
}
|
197 |
return $sizes;
|
198 |
}
|
199 |
|
200 |
+
/*
|
201 |
+
* pte_test
|
202 |
+
*
|
203 |
+
* Outputs the test HTML (and loads normal interface in an iframe)
|
204 |
+
*
|
205 |
+
* Requires post id as $_GET['id']
|
206 |
+
*/
|
207 |
+
function pte_test(){
|
208 |
+
$id = pte_check_id((int) $_GET['id']);
|
209 |
+
if ( $id ){
|
210 |
+
$testurl = admin_url('admin-ajax.php') . "?action=pte_ajax&pte-action=launch&id=${id}";
|
211 |
+
require( PTE_PLUGINPATH . "html/test.php" );
|
212 |
+
}
|
213 |
+
return;
|
214 |
+
}
|
215 |
+
|
216 |
/*
|
217 |
* pte_launch
|
218 |
*
|
221 |
* Requires post id as $_GET['id']
|
222 |
*/
|
223 |
function pte_launch(){
|
224 |
+
$logger = PteLogger::singleton();
|
225 |
+
$options = pte_get_options();
|
226 |
+
if ( $options['pte_debug'] ) {
|
|
|
|
|
|
|
227 |
wp_enqueue_script( 'pte'
|
228 |
, PTE_PLUGINURL . 'js/pte.full.js'
|
229 |
, array('jquery','imgareaselect')
|
230 |
, PTE_VERSION
|
231 |
);
|
232 |
+
wp_enqueue_script( 'jquery-json'
|
233 |
+
, PTE_PLUGINURL . 'apps/jquery.json-2.2.min.js'
|
234 |
+
, array('jquery')
|
235 |
+
, '2.2'
|
236 |
+
);
|
237 |
wp_enqueue_style( 'pte'
|
238 |
, PTE_PLUGINURL . 'css/pte.css'
|
239 |
, array('imgareaselect')
|
252 |
, PTE_VERSION
|
253 |
);
|
254 |
}
|
255 |
+
wp_localize_script('pte'
|
256 |
+
, 'objectL10n'
|
257 |
+
, array( 'pastebin_create_error' => __( 'Sorry, there was a problem trying to send to pastebin', PTE_DOMAIN )
|
258 |
+
, 'pastebin_url' => __( 'PASTEBIN URL:', PTE_DOMAIN )
|
259 |
+
, 'aspect_ratio_disabled' => __( 'Disabling aspect ratio', PTE_DOMAIN )
|
260 |
+
)
|
261 |
+
);
|
262 |
|
263 |
$id = pte_check_id((int) $_GET['id']);
|
264 |
|
274 |
|
275 |
$sizer = $big > 400 ? 400 / $big : 1;
|
276 |
|
277 |
+
require( PTE_PLUGINPATH . "html/pte.php" );
|
278 |
}
|
279 |
|
280 |
function pte_check_id( $id ){
|
281 |
+
$logger = PteLogger::singleton();
|
282 |
if ( !$post =& get_post( $id ) ){
|
283 |
+
$logger->warn( "Invalid id: {$id}" );
|
284 |
return false;
|
285 |
}
|
286 |
if ( !current_user_can( 'edit_post', $id ) ){
|
287 |
+
$logger->warn( "User does not have permission to edit this item" );
|
288 |
return false;
|
289 |
}
|
290 |
return $id;
|
291 |
}
|
292 |
|
293 |
function pte_check_int( $int ){
|
294 |
+
$logger = PteLogger::singleton();
|
295 |
if (! is_numeric( $int ) ){
|
296 |
+
$logger->warn( "PARAM not numeric: '{$int}'" );
|
297 |
return false;
|
298 |
}
|
299 |
return $int;
|
347 |
$dst_x, $dst_y, $dst_w, $dst_h,
|
348 |
$src_x, $src_y, $src_w, $src_h )
|
349 |
{
|
350 |
+
$logger = PteLogger::singleton();
|
351 |
+
$logger->debug( print_r( compact( 'type', 'dst_x', 'dst_y', 'dst_w', 'dst_h',
|
352 |
+
'src_x','src_y','src_w','src_h' ), true ) );
|
353 |
|
354 |
+
$new_image = wp_imagecreatetruecolor( $dst_w, $dst_h );
|
|
|
355 |
|
356 |
imagecopyresampled( $new_image, $original_image,
|
357 |
$dst_x, $dst_y, $src_x, $src_y,
|
370 |
}
|
371 |
|
372 |
function pte_write_image( $image, $orig_type, $destfilename ){
|
373 |
+
$logger = PteLogger::singleton();
|
374 |
+
|
375 |
$dir = dirname( $destfilename );
|
376 |
if ( ! is_dir( $dir ) ){
|
377 |
if ( ! mkdir( $dir, 0777, true ) ){
|
378 |
+
$logger->warn("Error creating directory: {$dir}");
|
379 |
}
|
380 |
}
|
381 |
|
382 |
if ( IMAGETYPE_GIF == $orig_type ) {
|
383 |
if ( !imagegif( $image, $destfilename ) ){
|
384 |
+
$logger->error("Resize path invalid");
|
385 |
return false;
|
386 |
}
|
387 |
}
|
388 |
elseif ( IMAGETYPE_PNG == $orig_type ) {
|
389 |
if ( !imagepng( $image, $destfilename ) ){
|
390 |
+
$logger->error("Resize path invalid");
|
391 |
return false;
|
392 |
}
|
393 |
}
|
394 |
else {
|
395 |
// all other formats are converted to jpg
|
396 |
if ( !imagejpeg( $image, $destfilename, 90) ){
|
397 |
+
$logger->error("Resize path invalid: " . $destfilename);
|
398 |
return false;
|
399 |
}
|
400 |
}
|
419 |
* OUTPUT: JSON object 'size: url'
|
420 |
*/
|
421 |
function pte_resize_images(){
|
422 |
+
$logger = PteLogger::singleton();
|
423 |
global $pte_sizes;
|
424 |
|
425 |
// Require JSON output
|
459 |
return pte_json_error("Could not read image size");
|
460 |
}
|
461 |
|
462 |
+
$logger->debug( "BASE FILE DIMENSIONS/INFO: " . print_r( $original_size, true ) );
|
463 |
list( $orig_w, $orig_h, $orig_type ) = $original_size;
|
464 |
// *** End common-info
|
465 |
|
481 |
$x, $y, $w, $h );
|
482 |
|
483 |
if ( ! isset( $image ) ){
|
484 |
+
$logger->error( "Error creating image: {$size}" );
|
485 |
continue;
|
486 |
}
|
487 |
|
488 |
if ( ! pte_write_image( $image, $orig_type, $tmpfile ) ){
|
489 |
+
$logger->error( "Error writing image: {$size} to '{$tmpfile}'" );
|
490 |
continue;
|
491 |
}
|
492 |
// === END CREATE IMAGE ===============
|
521 |
* Clean up and return error/success information...
|
522 |
*/
|
523 |
function pte_confirm_images(){
|
524 |
+
global $pte_sizes;
|
525 |
+
$logger = PteLogger::singleton();
|
526 |
|
527 |
// Require JSON output
|
528 |
pte_require_json();
|
541 |
if ( is_array( $_GET['pte-confirm'] ) ){
|
542 |
$pte_sizes = array_keys( $_GET['pte-confirm'] );
|
543 |
$sizes = pte_get_all_alternate_size_information( $id );
|
544 |
+
$logger->debug( "pte_get_all_alternate_size_information returned: "
|
545 |
+
. print_r( $sizes, true ) );
|
546 |
}
|
547 |
else {
|
548 |
return pte_json_error( "Invalid Parameters: can't find sizes" );
|
577 |
}
|
578 |
|
579 |
// Move good image
|
580 |
+
$logger->debug( "Moving '{$good_file}' to '{$new_file}'" );
|
581 |
rename( $good_file, $new_file );
|
582 |
|
583 |
// Update metadata
|
591 |
'width' => $w,
|
592 |
'height' => $h
|
593 |
);
|
594 |
+
$logger->debug( "Updating '{$size}' metadata: " . print_r( $metadata['sizes'][$size], true ) );
|
595 |
wp_update_attachment_metadata( $id, $metadata);
|
596 |
|
597 |
// Delete/unlink old file
|
599 |
&& $old_file !== $new_file
|
600 |
&& file_exists( $old_file ) )
|
601 |
{
|
602 |
+
$logger->debug( "Deleting old thumbnail: {$old_file}" );
|
603 |
unlink( $old_file );
|
604 |
}
|
605 |
}
|
606 |
// Delete tmpdir
|
607 |
+
pte_rmdir( $PTE_TMP_DIR );
|
608 |
return pte_json_encode( array( 'success' => "Yay!" ) );
|
609 |
}
|
610 |
|
611 |
+
function pte_rmdir( $dir ){
|
612 |
+
$logger = PteLogger::singleton();
|
613 |
+
if ( !is_dir( $dir ) || !preg_match( "/ptetmp/", $dir ) ){
|
614 |
+
$logger->warn("Tried to delete invalid directory: {$dir}");
|
615 |
+
return;
|
616 |
+
}
|
617 |
+
foreach ( scandir( $dir ) as $file ){
|
618 |
+
if ( "." == $file || ".." == $file ) continue;
|
619 |
+
$full_path_to_file = $dir . DIRECTORY_SEPARATOR . $file;
|
620 |
+
$logger->debug("DELETING: {$full_path_to_file}");
|
621 |
+
unlink( $full_path_to_file );
|
622 |
+
}
|
623 |
+
rmdir( $dir );
|
624 |
+
}
|
625 |
+
|
626 |
function pte_delete_images()
|
627 |
{
|
628 |
// Require JSON output
|
639 |
$uploads = wp_upload_dir();
|
640 |
$PTE_TMP_DIR = $uploads['basedir'] . DIRECTORY_SEPARATOR . "ptetmp" . DIRECTORY_SEPARATOR . $id;
|
641 |
// Delete tmpdir
|
642 |
+
pte_rmdir( $PTE_TMP_DIR );
|
643 |
return pte_json_encode( array( "success" => "Yay!" ) );
|
644 |
}
|
645 |
+
|
646 |
+
?>
|
post-thumbnail-editor.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin URI: http://wordpress.org/extend/plugins/post-thumbnail-editor/
|
4 |
Author: sewpafly
|
5 |
Author URI: http://sewpafly.github.com/post-thumbnail-editor
|
6 |
-
Version: 1.0.
|
7 |
Description: Individually manage your post thumbnails
|
8 |
|
9 |
LICENSE
|
@@ -35,7 +35,7 @@
|
|
35 |
define( 'PTE_PLUGINURL', plugins_url(basename( dirname(__FILE__))) . "/");
|
36 |
define( 'PTE_PLUGINPATH', dirname(__FILE__) . "/");
|
37 |
define( 'PTE_DOMAIN', "post-thumbnail-editor");
|
38 |
-
define( 'PTE_VERSION', "1.0.
|
39 |
|
40 |
/*
|
41 |
* Option Functionality
|
3 |
Plugin URI: http://wordpress.org/extend/plugins/post-thumbnail-editor/
|
4 |
Author: sewpafly
|
5 |
Author URI: http://sewpafly.github.com/post-thumbnail-editor
|
6 |
+
Version: 1.0.2
|
7 |
Description: Individually manage your post thumbnails
|
8 |
|
9 |
LICENSE
|
35 |
define( 'PTE_PLUGINURL', plugins_url(basename( dirname(__FILE__))) . "/");
|
36 |
define( 'PTE_PLUGINPATH', dirname(__FILE__) . "/");
|
37 |
define( 'PTE_DOMAIN', "post-thumbnail-editor");
|
38 |
+
define( 'PTE_VERSION', "1.0.2");
|
39 |
|
40 |
/*
|
41 |
* Option Functionality
|