Plugin Directory

Changeset 708709


Ignore:
Timestamp:
05/06/2013 03:35:50 PM (13 years ago)
Author:
ChrisHurst
Message:

2.3.8

  • fixed text watermark system.
  • added image backup system option.
  • added remove watermarks button to the edit media screen, will only show up when backups are available.
Location:
transparent-image-watermark-plugin/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • transparent-image-watermark-plugin/trunk/readme.txt

    r703550 r708709  
    22Name: Transparent Image Watermark
    33Contributors: MyWebsiteAdvisor, ChrisHurst
    4 Tags: Watermark, Images, Image, Picture, Pictures, Photo, Photos, Upload, Post, Plugin, Page, Admin, Security, administration, automatic, media
     4Tags: Watermark, Images, Image, Picture, Pictures, Photo, Photos, Upload, Post, posts, Plugin, Page, Admin, Security, administration, automatic, media
    55Requires at least: 3.3
    66Tested up to: 3.5.1
    7 Stable tag: 2.3.7
     7Stable tag: 2.3.8
    88Donate link: http://MyWebsiteAdvisor.com/donations/
    99
     
    204204
    205205
     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
    206212= 2.3.7 =
    207213* fixed text watermark size adjustment system.
  • transparent-image-watermark-plugin/trunk/transparent-watermark-loader.php

    r703550 r708709  
    44Plugin URI: http://MyWebsiteAdvisor.com/tools/wordpress-plugins/transparent-image-watermark/
    55Description: Add transparent PNG image watermark to your uploaded images.
    6 Version: 2.3.7
     6Version: 2.3.8
    77Author: MyWebsiteAdvisor
    88Author URI: http://MyWebsiteAdvisor.com
  • transparent-image-watermark-plugin/trunk/transparent-watermark-plugin.php

    r703550 r708709  
    66
    77    //plugin version number
    8     private $version = "2.3.7";
     8    private $version = "2.3.8";
    99   
    1010    private $debug = false;
     
    6868       
    6969            // 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);
    7171           
    7272        }
     
    7676        if($show_on_upload_screen === "true"){ 
    7777       
     78            add_action( 'admin_enqueue_scripts', array($this, 'add_watermark_js') );
     79           
    7880            add_filter('attachment_fields_to_edit', array(&$this, 'attachment_field_add_watermark'), 10, 2);
    7981           
    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       
    8291   
    8392        //check pluign settings and display alert to configure and save plugin settings
     
    107116   
    108117   
    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   
    110166   
    111167   
     
    354410                    )
    355411                ),
     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                ),
    356423                array(
    357424                    '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>(Feature 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 ),
     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 ),
    360427                    'type' => 'radio',
    361428                    'options' => array(
     
    10731140                                                 
    10741141                         
    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);     
    10761145                       
    10771146                       $sizes = array();                           
     
    11241193                        'html'       => '<input type="hidden">');
    11251194                       
     1195                   
     1196                    $checked = "";
    11261197                       
    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_html
    1137                     );
    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_html
    1149                     );
    11501198                       
    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";
    11651206                $form_html .= " <a class='watermark_preview' href='".$post->guid."?".filemtime($filepath)."' title='$base_filename Preview' target='_blank'>" . $base_filename . "</a></p>";
    11661207                  $form_html .= $form_js;
     
    11801221                       
    11811222                   
    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'];
    11831232                        $form_html .= " <a class='watermark_preview' title='".$size['file']." Preview'  href='".$image_link."?".filemtime($current_filepath)."' target='_blank'>" . $size['file'] . "</a></p>";
    11841233                   
     
    11941243
    11951244                 
    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                   
    11981257                  $form_html .= "<script type='text/javascript'>
    11991258                 
     
    12031262                                      });       
    12041263                       
    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                                         };
    12061286                                                 
    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);
    12151302                                                                                       
    12161303                                      </script>";       
  • transparent-image-watermark-plugin/trunk/transparent-watermark-tools.php

    r703550 r708709  
    3434     * @return array
    3535     */
    36     public function apply_watermark($data) {
     36    public function apply_watermark( $metadata, $attachment_id) {
    3737        // get settings for watermarking
    3838        $upload_dir   = wp_upload_dir();
     
    4141        $watermark_types = $options['watermark_settings']['image_types'];
    4242           
    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']);
    4545           
    4646            //$allowed_types = array('jpg', 'png', 'gif');
     
    5454                        switch($image_size) {
    5555                            case 'fullsize':
    56                                 $filepath = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $data['file'];
     56                                $filepath = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $metadata['file'];
    5757                                break;
    5858                            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'];
    6161                                } else {
    6262                                    // early getaway
     
    6666                       
    6767                        // ... and apply watermark
    68                         $this->do_watermark($filepath);
     68                        $this->do_watermark($filepath, $attachment_id);
    6969                    }
    7070                }
     
    7373       
    7474        // pass forward attachment metadata
    75         return $data;
     75        return $metadata;
    7676    }
    7777   
     
    124124     * @return boolean
    125125     */
    126     public function do_watermark($filepath) {
     126    public function do_watermark($filepath, $attachment_id) {
    127127       
    128128        //get plugin options
     
    140140            // get image resource
    141141            $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            }   
    146162       
    147163           
     
    377393            default:
    378394                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           
    379439        }
    380440    }
Note: See TracChangeset for help on using the changeset viewer.