Plugin Directory

Changeset 2197670


Ignore:
Timestamp:
11/20/2019 10:07:12 PM (6 years ago)
Author:
macguru2000
Message:

CataBlog Release 1.7.0: Modern html5 multi-image uploader, fix fatal errors in WordPress 5.3, fix PHP warnings

Location:
catablog/trunk
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • catablog/trunk/css/catablog-admin.css

    r1033448 r2197670  
    479479
    480480
    481 #upload-form-left-col.left-col {
     481#upload-form-left-col {
    482482    float: left;
    483     width: 17em;
    484 }
    485 #upload-form-right-col.right-col {
    486     margin: 0 0 0 19em;
     483    width: 32em;
     484}
     485#upload-form-right-col {
     486    margin: 0 0 0 33em;
    487487    border: 1px #ccc solid;
    488488    border-radius: 5px;
  • catablog/trunk/lib/CataBlog.class.php

    r1805522 r2197670  
    122122        add_action('wp_before_admin_bar_render', array(&$this, 'admin_bar_edit_button'), 99);
    123123        add_action('wp_before_admin_bar_render', array(&$this, 'admin_bar_menu'), 100);
    124        
     124
    125125        // register custom sidebar widgets
    126         add_action( 'widgets_init', create_function('', 'return register_widget("CataBlogWidget");') );
    127         add_action( 'widgets_init', create_function('', 'return register_widget("CataBlogCategoryWidget");') );
    128        
    129        
     126        $catablog_widget_callback = function () {
     127            return register_widget("CataBlogWidget");
     128        };
     129        $catablog_category_widget_callback = function () {
     130            return register_widget("CataBlogCategoryWidget");
     131        };
     132        add_action( 'widgets_init', $catablog_widget_callback );
     133        add_action( 'widgets_init', $catablog_category_widget_callback );
     134
     135
    130136        // register admin hooks
    131137        if (is_admin()) {
     
    461467       
    462468        $catablog_upload_page = strpos($_SERVER['QUERY_STRING'], 'page=catablog-upload') !== false;
    463         if ($catablog_page) {
    464             wp_enqueue_script('swfupload');
    465             wp_enqueue_script('swfobject');
    466             wp_enqueue_script('catablog-handlers', $this->urls['javascript'] . '/catablog.handlers.js', array('jquery'), '1.0');
     469        if ($catablog_upload_page) {
     470            // @TODO: refactor upload javascript into its own js file, like catablog-handlers used to be
     471            // wp_enqueue_script('catablog-handlers', $this->urls['javascript'] . '/catablog.handlers.js', array('jquery'), '1.0');
    467472        }
    468473    }
     
    23502355                // separate categories and trim names
    23512356                $categories = explode(',', $category);
    2352                 array_walk($categories, create_function('&$val', '$val = trim($val);'));
     2357                $walk_func = function (&$val) {
     2358                    $val = trim($val);
     2359                };
     2360                array_walk($categories, $walk_func);
    23532361               
    23542362                // load all category names and ids in the catalog
     
    36003608        $slug = strtolower($string);
    36013609        $slug = sanitize_title($slug);
    3602         $slug = @wp_unique_term_slug($slug);
     3610        try {
     3611            $tax = get_taxonomy($this->custom_tax_name);
     3612            $slug = @wp_unique_term_slug($slug, $tax);
     3613        } catch (Exception $e) {
     3614            $slug = @wp_unique_term_slug($slug);
     3615        }
    36033616        return $slug;
    36043617    }
  • catablog/trunk/lib/catablog.upload.php

    r911491 r2197670  
    1515 * example: '/var/www/wordpress/';
    1616 */
    17 $WP_ABS_PATH = '/var/www/wordpress/';
     17$WP_ABS_PATH = '/Applications/MAMP/htdocs/';
    1818
    1919
     
    6969
    7070// make sure the attempting uploader had passed the correct nonce value
    71 check_admin_referer('catablog_swfupload');
     71check_admin_referer('catablog_file_upload');
    7272
    7373
     
    7575global $wp_plugin_catablog_class;
    7676
    77 $tmp_name = $_FILES['Filedata']['tmp_name'];
    78 $_FILES['new_image'] = $_FILES['Filedata'];
     77$tmp_name = $_FILES['new_image']['tmp_name'];
    7978if (strlen($tmp_name) < 1) {
    8079    die("<li class='error'>".__('Image could not be uploaded to the server, please try again.', 'catablog')."</li>");
     
    8483$valid_image = $new_item->validateImage($tmp_name);
    8584if ($valid_image === true) {
    86     $new_item_title = $_FILES['Filedata']['name'];
     85    $new_item_title = $_FILES['new_image']['name'];
    8786    $new_item_title = preg_replace('/\.[^.]+$/','',$new_item_title);
    8887    $new_item_title = str_replace(array('_','-','.'), ' ', $new_item_title);
  • catablog/trunk/readme.txt

    r1805522 r2197670  
    44Tags: plugin, admin, image, images, posts, Post, widget, links, catalog, gallery, portfolio, product catalog, discography, library, collection, store, organize, media, photo, thumbnail, product, listing, list, BuddyPress, ecommerce
    55Requires at least: 3.3
    6 Tested up to: 4.9.2
     6Tested up to: 5.3
    77Stable tag: 1.6.7
    88
     
    105105
    106106= 1.7.0 =
    107 * Fix: Fixed some non-fatal errors and deprecation warnings.
     107* New: Replace Multiple Image Flash Uploader with a new HTML5 Uploader.
     108* Fix: Fatal error with newer versions of wp_unique_term_slug().
     109* Fix: Non-fatal errors and deprecation warnings.
    108110
    109111= 1.6.7 =
  • catablog/trunk/templates/admin-new.php

    r1805522 r2197670  
    1616            <div id="select_images_form">
    1717                <?php /*
    18                
    1918                <p><?php _e("Insert Newly Uploaded Images Into:", "catablog"); ?></p>
    2019               
     
    4342                </p>
    4443                */ ?>
    45                
    46                 <div id="upload_buttons">
    47                     <input type="file" id="new_image" name="new_image"  />
    48                     <?php wp_nonce_field( 'catablog_create', '_catablog_create_nonce', false, true ) ?>
    49                     <input type="submit" name="save" value="<?php _e("Upload", "catablog") ?>" class="button-primary" />
    50                     <p class="error"><?php _e("Flash upload was not enabled.", "catablog"); ?><br /><?php _e("Either you elected to disable it, JavaScript is disabled, or your version of Flash is too old.", "catablog")?></p>
    51                 </div>
     44
     45                <input type="file" id="new_image" name="new_image" accept="image/*" multiple />
     46                <input type="submit" name="save" value="<?php _e("Upload", "catablog") ?>" class="button-primary" />
     47                <?php wp_nonce_field( 'catablog_create', '_catablog_create_nonce', false, true ) ?>
    5248
    5349                <p><?php printf(__("Maximum upload file size: %sB", "catablog"), ini_get('upload_max_filesize')); ?></p>
     
    5854                    <strong><?php _e("No animated GIFs please.", "catablog"); ?></strong>
    5955                </small></p>
    60                
    61                 <p id="catablog-disable-flash-form" class="hide"><small>
    62                     <?php _e("Flash uploader not working for you?", "catablog"); ?><br />
    63                     <a id="catablog-disable-flash-upload" href='#disable-flash'><?php _e("Disable Flash Upload", "catablog") ?></a>
    64                 </small></p>
    65                
    66                 <p id="catablog-enable-flash-form" class=""><small>
    67                     <?php _e("Why not try the flash uploader?", "catablog"); ?><br />
    68                     <a id="catablog-enable-flash-upload" href='#enable-flash'><?php _e("Enable Flash Upload", "catablog") ?></a>
    69                 </small></p>
    70                
     56
     57                <p id="catablog-multifile-upload-disabled" class="error hide">
     58                    <?php _e("Multiple file upload has been disabled. <br>You can fix this by upgrading to a supported browser.", "catablog"); ?><br />
     59                    <a href="" target="_blank"><?php _e("Show me which browsers are supported") ?></a>
     60                </p>
    7161            </div>
    7262<?php /*
     
    120110
    121111<script type="text/javascript">
     112    var file_input;
     113    var current_upload;
     114    var total_uploads;
     115
     116    var post_url = "<?php echo $this->urls['plugin'] . '/lib/catablog.upload.php' ?>";
     117    var wp_nonce = "<?php echo wp_create_nonce('catablog_file_upload'); ?>";
     118    var auth_cookie = "<?php echo (is_ssl() ? $_COOKIE[SECURE_AUTH_COOKIE] : $_COOKIE[AUTH_COOKIE]); ?>";
     119    var logged_in_cookie = "<?php echo $_COOKIE[LOGGED_IN_COOKIE]; ?>";
     120
    122121    jQuery(document).ready(function($) {
    123        
    124         $('#catablog-disable-flash-upload').click(function(event) {
    125             setCookie('catablog-flash-upload','disabled',365);
    126             window.location.reload();
     122
     123        if (!('FormData' in window)) {
     124            $('#catablog-multifile-upload-disabled').removeClass('hide');
     125        }
     126
     127        file_input = document.getElementById("new_image");
     128       
     129        $('#new-items-editor').bind('click', delegateClickForNewItems);
     130        $('#new-items-editor').bind('keyup', delegateKeyUpForNewItems);
     131        $('#new-items-editor').bind('keypress', delegateKeyPressForNewItems);
     132
     133        $("#catablog-create").submit(function(event){
     134            event.preventDefault();
     135           
     136            current_upload = 0;
     137            total_uploads = file_input.files.length;
     138
     139            $('#current_number').html(current_upload + 1);
     140            $('#total_number').html(total_uploads);
     141
     142            $('#catablog-progress-all-uploads .catablog-progress-bar').width('0%');
     143            $('#catablog-progress-all-uploads .catablog-progress-text').html('0%');
     144           
     145            $('#catablog-progress-current-upload .catablog-progress-bar').width('0%');
     146            $('#catablog-progress-current-upload .catablog-progress-text').html('0%');
     147
     148            $('#upload-form-right-col').removeClass('hide');
     149
     150            uploadFile()
    127151        });
    128        
    129         $('#catablog-enable-flash-upload').click(function(event) {
    130             setCookie('catablog-flash-upload','enabled',-1);
    131             window.location.reload();
    132         });
    133        
    134         if (getCookie('catablog-flash-upload') == 'disabled') {
     152    });
     153   
     154
     155    function uploadFile() {
     156        var file = file_input.files[current_upload];
     157
     158        var form_data = new FormData();
     159        form_data.append("new_image", file);
     160        form_data.append("auth_cookie", auth_cookie);
     161        form_data.append("logged_in_cookie", logged_in_cookie);
     162        form_data.append("_wpnonce", wp_nonce);
     163        form_data.append("categories", []);
     164
     165        var xhr = new XMLHttpRequest();
     166
     167        xhr.addEventListener('load', uploadComplete);
     168        xhr.addEventListener('error', uploadError);
     169        xhr.upload.addEventListener('progress', uploadProgress);
     170
     171        xhr.open("POST", post_url);
     172        xhr.send(form_data);
     173    }
     174
     175    function uploadComplete(event) {
     176        current_upload += 1;
     177
     178        var percent = Math.ceil((current_upload/total_uploads) * 100) + '%';
     179       
     180        jQuery('#catablog-progress-all-uploads .catablog-progress-bar').width(percent);
     181        jQuery('#catablog-progress-all-uploads .catablog-progress-text').html(percent);
     182
     183        if (current_upload < total_uploads) {
     184            jQuery('#current_number').html(current_upload + 1);
     185            uploadFile()
     186        }
     187
     188        jQuery('#new-items-editor').append(event.target.response);
     189        jQuery('#new-items-editor li:last').show(800);
     190    }
     191
     192    function uploadProgress(event) {
     193        var percent = Math.ceil((event.loaded / event.total) * 100) + '%';
     194        jQuery('#catablog-progress-current-upload .catablog-progress-bar').width(percent);
     195        jQuery('#catablog-progress-current-upload .catablog-progress-text').html(percent);
     196    }
     197
     198    function uploadError(event) {
     199        console.error('!! Upload Error', event);
     200    }
     201
     202    function delegateClickForNewItems(event) {
     203        var target_tag = event.target.tagName;
     204        var target_class = event.target.className;
     205        if (target_tag == 'INPUT' && target_class == 'button-primary') {
     206            catablog_micro_save.call(event.target);
     207        }
     208    }
     209
     210    function delegateKeyUpForNewItems(event) {
     211        var target = event.target;
     212        if (target.tagName == 'INPUT') {
     213            switch (target.className) {
     214            case 'title catablog-micro-editor-field':
     215                catablog_verify_title.call(target);
     216                break;
     217            case 'price catablog-micro-editor-field':
     218                catablog_verify_price.call(target);
     219                break;
     220            case 'order catablog-micro-editor-field':
     221                catablog_verify_order.call(target);
     222                break;
     223            }
     224        }
     225    }
     226
     227    function delegateKeyPressForNewItems(event) {
     228        var key_pressed = event.type == "keypress";
     229        var key_code = (event.keyCode ? event.keyCode : event.which);
     230        if (key_pressed && key_code == 13) {
     231            catablog_micro_save.call(event.target);
     232            event.preventDefault();
    135233            return false;
    136234        }
    137        
    138         $('#catablog-enable-flash-form').hide();
    139         $('#catablog-disable-flash-form').show();
    140        
    141         flash_version = swfobject.getFlashPlayerVersion();
    142         if (flash_version.major < 10) {
    143             return false;
    144         }
    145        
    146         swfu = new SWFUpload({
    147             upload_url : "<?php echo $this->urls['plugin'] . '/lib/catablog.upload.php' ?>",
    148             flash_url : "<?php echo includes_url('js/swfupload/swfupload.swf'); ?>",
    149        
    150             file_types : "*.jpg;*.jpeg;*.gif;*.png",
    151             file_type_description: "Web Image Files",
    152             file_size_limit : "<?php printf('%sB', ini_get('upload_max_filesize')) ?>",
    153        
    154             button_placeholder_id : 'upload_buttons',
    155             button_image_url : "<?php echo $this->urls['images'] . '/upload.png'; ?>",
    156             button_width : 190,
    157             button_height: 23,
    158             button_text : '<?php _e("Select Images", "catablog") ?>',
    159             button_text_top_padding: 3,
    160             button_cursor: SWFUpload.CURSOR.HAND,
    161        
    162             post_params : {
    163                 "auth_cookie" : "<?php echo (is_ssl() ? $_COOKIE[SECURE_AUTH_COOKIE] : $_COOKIE[AUTH_COOKIE]); ?>",
    164                    "logged_in_cookie": "<?php echo $_COOKIE[LOGGED_IN_COOKIE]; ?>",
    165                    "_wpnonce" : "<?php echo wp_create_nonce('catablog_swfupload'); ?>",
    166                 "categories" : [],
    167             },
    168        
    169             swfupload_loaded_handler : catablog_swfupload_loaded,
    170            
    171             file_dialog_complete_handler : catablog_swfupload_file_dialog_complete,
    172            
    173             file_queued_handler : catablog_swfupload_file_queued,
    174             file_queued_error_handler : catablog_swfupload_file_queued_error,
    175             upload_start_handler : catablog_swfupload_upload_start,
    176             upload_progress_handler : catablog_swfupload_upload_progress,
    177             upload_error_handler : catablog_swfupload_upload_error,
    178             upload_success_handler : catablog_swfupload_upload_success,
    179             upload_complete_handler : catablog_swfupload_upload_complete,
    180         });
    181        
    182        
    183        
    184         var to_show = jQuery('#dynamic_title h3:hidden');
    185         var to_hide = jQuery('#dynamic_title h3:visible');
    186 
    187         to_show.show();
    188         to_hide.hide();
    189 
    190         jQuery('#upload-form-left-col').addClass('left-col');
    191         jQuery('#upload-form-right-col').addClass('right-col');
    192     });
    193    
    194    
    195     function catablog_verify_title(event) {
    196         // return true;
     235    }
     236
     237    function catablog_verify_title() {
    197238        var title = jQuery.trim(this.value);
    198239       
     
    211252    }
    212253   
    213     function catablog_verify_price(event) {
     254    function catablog_verify_price() {
    214255        var price = this.value;
    215256        if (!is_float(price)) {
     
    227268    }
    228269   
    229     function catablog_verify_order(event) {
     270    function catablog_verify_order() {
    230271        var order = this.value;
    231272        if (!is_integer(order)) {
     
    243284    }
    244285   
    245    
    246     function catablog_micro_save(event) {
    247         if (event.type == "keypress") {
    248             var key_code = (event.keyCode ? event.keyCode : event.which);
    249             if (key_code != 13) {
    250                 return true;
    251             }
    252         }
    253        
     286    function catablog_micro_save() {       
    254287        var container = jQuery(this).closest('li');
    255288        var button    = container.find('input.button-primary');
Note: See TracChangeset for help on using the changeset viewer.