Changeset 708709
- Timestamp:
- 05/06/2013 03:35:50 PM (13 years ago)
- Location:
- transparent-image-watermark-plugin/trunk
- Files:
-
- 4 edited
-
readme.txt (modified) (2 diffs)
-
transparent-watermark-loader.php (modified) (1 diff)
-
transparent-watermark-plugin.php (modified) (10 diffs)
-
transparent-watermark-tools.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
transparent-image-watermark-plugin/trunk/readme.txt
r703550 r708709 2 2 Name: Transparent Image Watermark 3 3 Contributors: MyWebsiteAdvisor, ChrisHurst 4 Tags: Watermark, Images, Image, Picture, Pictures, Photo, Photos, Upload, Post, Plugin, Page, Admin, Security, administration, automatic, media4 Tags: Watermark, Images, Image, Picture, Pictures, Photo, Photos, Upload, Post, posts, Plugin, Page, Admin, Security, administration, automatic, media 5 5 Requires at least: 3.3 6 6 Tested up to: 3.5.1 7 Stable tag: 2.3. 77 Stable tag: 2.3.8 8 8 Donate link: http://MyWebsiteAdvisor.com/donations/ 9 9 … … 204 204 205 205 206 = 2.3.8 = 207 * fixed text watermark system. 208 * added image backup system option. 209 * added remove watermarks button to the edit media screen, will only show up when backups are available. 210 211 206 212 = 2.3.7 = 207 213 * fixed text watermark size adjustment system. -
transparent-image-watermark-plugin/trunk/transparent-watermark-loader.php
r703550 r708709 4 4 Plugin URI: http://MyWebsiteAdvisor.com/tools/wordpress-plugins/transparent-image-watermark/ 5 5 Description: Add transparent PNG image watermark to your uploaded images. 6 Version: 2.3. 76 Version: 2.3.8 7 7 Author: MyWebsiteAdvisor 8 8 Author URI: http://MyWebsiteAdvisor.com -
transparent-image-watermark-plugin/trunk/transparent-watermark-plugin.php
r703550 r708709 6 6 7 7 //plugin version number 8 private $version = "2.3. 7";8 private $version = "2.3.8"; 9 9 10 10 private $debug = false; … … 68 68 69 69 // add filter for watermarking images 70 add_filter('wp_generate_attachment_metadata', array(&$this->tools, 'apply_watermark') );70 add_filter('wp_generate_attachment_metadata', array(&$this->tools, 'apply_watermark'), 10, 2); 71 71 72 72 } … … 76 76 if($show_on_upload_screen === "true"){ 77 77 78 add_action( 'admin_enqueue_scripts', array($this, 'add_watermark_js') ); 79 78 80 add_filter('attachment_fields_to_edit', array(&$this, 'attachment_field_add_watermark'), 10, 2); 79 81 80 } 81 82 83 } 84 85 add_action('wp_ajax_revert_watermarks', array(&$this, 'revert_watermarks')); 86 87 88 //hook on delete_attachment action to delete all of the backups created before watermarks were applied 89 add_action('delete_attachment', array($this, 'delete_attachment_watermark_backups')); 90 82 91 83 92 //check pluign settings and display alert to configure and save plugin settings … … 107 116 108 117 109 118 119 120 public function add_watermark_js(){ 121 122 wp_enqueue_script('transparent-watermark-script', $this->plugin_url . "watermark.js"); 123 124 } 125 126 127 128 129 130 function delete_attachment_watermark_backups($attachment_id){ 131 132 $bk_meta = get_post_meta($attachment_id, '_watermark_backups', true); 133 134 foreach($bk_meta as $key => $info){ 135 @unlink( $info['bk_path'] ); 136 } 137 138 } 139 140 141 142 143 function revert_watermarks(){ 144 145 check_ajax_referer( 'revert-watermarks', 'security' ); 146 147 $attachment_id = $_POST['post_id']; 148 149 $bk_meta = get_post_meta($attachment_id, '_watermark_backups', true); 150 151 foreach($bk_meta as $key => $info){ 152 153 @unlink( $info['original_path'] ); 154 copy( $info['bk_path'] , $info['original_path'] ); 155 @unlink( $info['bk_path'] ); 156 echo "Removed Watermark: " . $info['original_path'] . "\r\n"; 157 158 } 159 160 delete_post_meta($attachment_id, '_watermark_backups'); 161 162 die(); 163 164 } 165 110 166 111 167 … … 354 410 ) 355 411 ), 412 array( 413 'name' => 'watermark_backup', 414 'label' => __( 'Watermark Backup', $this->plugin_name ), 415 'desc' => __( "Create a Backup of each image before it is watermarked so watermarks can be removed.", $this->plugin_name ), 416 'type' => 'radio', 417 'default' => 'backup-enabled', 418 'options' => array( 419 'backup-enabled' => 'Backup Enabled', 420 'backup-disabled' => 'Backup Disabled' 421 ) 422 ), 356 423 array( 357 424 'name' => 'show_on_upload_screen', 358 'label' => __( 'Show Advanced Preview', $this->plugin_name ),359 'desc' => __( "Show Preview of Advanced Watermark Features on Upload Screen<br>(FeatureAvailable in Ultra Version Only, <a href='http://mywebsiteadvisor.com/tools/wordpress-plugins/transparent-image-watermark/' target='_blank'>Click Here for More Information!</a>)", $this->plugin_name ),425 'label' => __( 'Show Advanced Features', $this->plugin_name ), 426 'desc' => __( "Show Advanced Watermark Features on Upload Screen<br><b>Must Be Enabled to Remove Watermarks</b><br>(Some Features Available in Ultra Version Only, <a href='http://mywebsiteadvisor.com/tools/wordpress-plugins/transparent-image-watermark/' target='_blank'>Click Here for More Information!</a>)", $this->plugin_name ), 360 427 'type' => 'radio', 361 428 'options' => array( … … 1073 1140 1074 1141 1075 $attachment_info = wp_get_attachment_metadata($post->ID); 1142 $attachment_info = wp_get_attachment_metadata($post->ID); 1143 1144 $bk_meta = get_post_meta($post->ID, '_watermark_backups', true); 1076 1145 1077 1146 $sizes = array(); … … 1124 1193 'html' => '<input type="hidden">'); 1125 1194 1195 1196 $checked = ""; 1126 1197 1127 /**1128 1129 $tooltip = "50 means that the watermark will be 50% of the width of the image being watermarked.";1130 $form_html = "<input id='watermark_width' value='$watermark_width' type='text' size='5' style='width:50px !important;' title='$tooltip' />%";1131 1132 1133 $form_fields['image-watermark-width'] = array(1134 'label' => __('Width', 'transparent-watermark'),1135 'input' => 'html',1136 'html' => $form_html1137 );1138 1139 1140 $tooltip = "50 means that the image is centered vertically, 10 means it is 10% from the top.";1141 $form_html = "<input id='watermark_vertical_location' value='$watermark_vertical_location' type='text' size='5' style='width:50px !important;' title='$tooltip' />%";1142 1143 $form_html .= $form_js;1144 1145 $form_fields['image-watermark-vertical-location'] = array(1146 'label' => __('Vertical', 'transparent-watermark'),1147 'input' => 'html',1148 'html' => $form_html1149 );1150 1198 1151 $tooltip = "50 means that the image is centered horizontally, 10 means it is 10% from the left."; 1152 $form_html = "<input id='watermark_horizontal_location' value='$watermark_horizontal_location' type='text' size='5' style='width:50px !important;' title='$tooltip' />%"; 1153 1154 $form_fields['image-watermark-horizontal-location'] = array( 1155 'label' => __('Horizontal', 'transparent-watermark'), 1156 'input' => 'html', 1157 'html' => $form_html 1158 ); 1159 1160 1161 1162 **/ 1163 1164 $form_html = "<p><input type='checkbox' name='attachment_size[]' value='".$post->guid."' style='width:auto;'> Original"; 1199 foreach($bk_meta as $key => $bk){ 1200 if($bk['original_path'] == $filepath){ 1201 $checked = 'checked="checked" '; 1202 } 1203 } 1204 1205 $form_html = "<p><input type='checkbox' name='attachment_size[]' value='".$post->guid."' style='width:auto;' ".$checked." class='attachment_sizes'> Original"; 1165 1206 $form_html .= " <a class='watermark_preview' href='".$post->guid."?".filemtime($filepath)."' title='$base_filename Preview' target='_blank'>" . $base_filename . "</a></p>"; 1166 1207 $form_html .= $form_js; … … 1180 1221 1181 1222 1182 $form_html = "<p><input type='checkbox' name='attachment_size[]' value='".$base_path.$size['file']."' style='width:auto;'> ".$size['width'] . "x" . $size['height']; 1223 $checked = ""; 1224 1225 foreach($bk_meta as $key => $bk){ 1226 if($bk['original_path'] == $current_filepath){ 1227 $checked = 'checked="checked" '; 1228 } 1229 } 1230 1231 $form_html = "<p><input type='checkbox' name='attachment_size[]' value='".$base_path.$size['file']."' style='width:auto;' ".$checked." class='attachment_sizes'> ".$size['width'] . "x" . $size['height']; 1183 1232 $form_html .= " <a class='watermark_preview' title='".$size['file']." Preview' href='".$image_link."?".filemtime($current_filepath)."' target='_blank'>" . $size['file'] . "</a></p>"; 1184 1233 … … 1194 1243 1195 1244 1196 $form_html = "<input type='button' class='button-primary' name='Add Watermark' value='Add Watermark' onclick='image_add_watermark();'>"; 1197 $form_html .= "<script type='text/javascript' src='"."../".PLUGINDIR . "/". dirname(plugin_basename(__FILE__))."/watermark.js'></script>"; 1245 $form_html = "<input type='button' class='button-primary' name='Add Watermark's value='Add Watermarks' onclick='image_add_watermark();'> "; 1246 1247 if($bk_meta != ''){ 1248 $form_html .= "<input type='button' class='button' name='Remove Watermarks' value='Remove All Watermarks' onclick='image_revert_watermarks();'>"; 1249 } 1250 1251 1252 1253 $revert_watermarks_nonce = wp_create_nonce("revert-watermarks"); 1254 1255 $attachment_id = $post->ID; 1256 1198 1257 $form_html .= "<script type='text/javascript'> 1199 1258 … … 1203 1262 }); 1204 1263 1205 function image_add_watermark(){ 1264 function image_add_watermark(){ 1265 var upgrade = confirm('Sorry, This feature is only available in the Ultra Version! Press Ok if you would like to Learn More!'); 1266 1267 if (upgrade == true) window.open('http://mywebsiteadvisor.com/tools/wordpress-plugins/transparent-image-watermark/'); 1268 } 1269 1270 1271 function image_revert_watermarks(){ 1272 1273 var allVals = []; 1274 jQuery('.attachment_sizes:checked').each(function() { 1275 allVals.push(jQuery(this).val()); 1276 }); 1277 1278 1279 var ajax_data = { 1280 'post_id' : $attachment_id, 1281 'images_url_list': allVals, 1282 'revert_watermarks':'revert_watermarks', 1283 'action': 'revert_watermarks', 1284 'security': '$revert_watermarks_nonce' 1285 }; 1206 1286 1207 alert('Sorry, This feature is only available in the Ultra Version! Please Upgrade at http://MyWebsiteAdvisor.com'); 1208 window.open('http://mywebsiteadvisor.com/tools/wordpress-plugins/transparent-image-watermark/'); 1209 1210 1211 1212 } 1213 1214 setTimeout(imagePreview, 100); 1287 jQuery.ajax({ 1288 type: 'POST', 1289 url: ajaxurl, 1290 data: ajax_data, 1291 success: function(data){ 1292 alert(data); 1293 location.reload(); 1294 } 1295 }); 1296 1297 } 1298 1299 1300 1301 setTimeout(imagePreview, 100); 1215 1302 1216 1303 </script>"; -
transparent-image-watermark-plugin/trunk/transparent-watermark-tools.php
r703550 r708709 34 34 * @return array 35 35 */ 36 public function apply_watermark( $data) {36 public function apply_watermark( $metadata, $attachment_id) { 37 37 // get settings for watermarking 38 38 $upload_dir = wp_upload_dir(); … … 41 41 $watermark_types = $options['watermark_settings']['image_types']; 42 42 43 if(isset($ data['file'])){44 $mime_type = wp_check_filetype($upload_dir['basedir'] . DIRECTORY_SEPARATOR . $ data['file']);43 if(isset($metadata['file'])){ 44 $mime_type = wp_check_filetype($upload_dir['basedir'] . DIRECTORY_SEPARATOR . $metadata['file']); 45 45 46 46 //$allowed_types = array('jpg', 'png', 'gif'); … … 54 54 switch($image_size) { 55 55 case 'fullsize': 56 $filepath = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $ data['file'];56 $filepath = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $metadata['file']; 57 57 break; 58 58 default: 59 if(!empty($ data['sizes']) && array_key_exists($image_size, $data['sizes'])) {60 $filepath = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . dirname($ data['file']) . DIRECTORY_SEPARATOR . $data['sizes'][$image_size]['file'];59 if(!empty($metadata['sizes']) && array_key_exists($image_size, $metadata['sizes'])) { 60 $filepath = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . dirname($metadata['file']) . DIRECTORY_SEPARATOR . $metadata['sizes'][$image_size]['file']; 61 61 } else { 62 62 // early getaway … … 66 66 67 67 // ... and apply watermark 68 $this->do_watermark($filepath );68 $this->do_watermark($filepath, $attachment_id); 69 69 } 70 70 } … … 73 73 74 74 // pass forward attachment metadata 75 return $ data;75 return $metadata; 76 76 } 77 77 … … 124 124 * @return boolean 125 125 */ 126 public function do_watermark($filepath ) {126 public function do_watermark($filepath, $attachment_id) { 127 127 128 128 //get plugin options … … 140 140 // get image resource 141 141 $image = $this->get_image_resource($filepath, $mime_type); 142 143 144 // add watermark image to image 145 $this->apply_watermark_image($image, $options); 142 143 144 //create backup image if not disabled 145 if($this->opt['watermark_settings']['watermark_backup'] !== 'backup-disabled'){ 146 147 $this->save_image_backup_file($image, $mime_type, $filepath, $attachment_id); 148 149 } 150 151 152 // add watermarks to image 153 if($options['watermark_settings']['watermark_type'] == "text-only"){ 154 155 $this->apply_watermark_text($image, $options); 156 157 }elseif($options['watermark_settings']['watermark_type'] == "image-only"){ 158 159 $this->apply_watermark_image($image, $options); 160 161 } 146 162 147 163 … … 377 393 default: 378 394 return false; 395 } 396 } 397 398 399 400 401 /** 402 * Save image backup file from image resource 403 * 404 * @param resource $image 405 * @param string $mime_type 406 * @param string $filepath 407 * @return boolean 408 */ 409 private function save_image_backup_file($image, $mime_type, $filepath, $attachment_id) { 410 411 $path_info = pathinfo($filepath); 412 $suffix = time() . rand(100, 999); 413 $backup_file_path = $path_info['dirname'] ."/". $path_info['filename'] . "-" . $suffix . "." . $path_info['extension']; 414 415 $key = $path_info['filename']; 416 417 $bk_meta = get_post_meta($attachment_id, '_watermark_backups', true); 418 419 if(!array_key_exists($key, $bk_meta)){ 420 421 $bk_meta[$key]['bk_path'] = $backup_file_path; 422 $bk_meta[$key]['original_path'] = $filepath; 423 424 error_log("update_post_meta $attachment_id, $backup_file_path"); 425 update_post_meta( $attachment_id, '_watermark_backups', $bk_meta); 426 427 428 switch ( $mime_type ) { 429 case 'image/jpeg': 430 return imagejpeg($image, $backup_file_path, 90); 431 case 'image/png': 432 return imagepng($image, $backup_file_path); 433 case 'image/gif': 434 return imagegif($image, $backup_file_path); 435 default: 436 return false; 437 } 438 379 439 } 380 440 }
Note: See TracChangeset
for help on using the changeset viewer.