function upload_scripts_enhanced() { global $woocommerce; $options = get_option('wccs_settings'); $length = empty($options['checkness']['file_upload_number']) ? 'this.files.length' : $options['checkness']['file_upload_number']; if (!empty($options['buttons'])) { foreach ($options['buttons'] as $btn) { if ($btn['type'] == 'wooccmupload') { $file_types = explode(",", $btn['option_array']); $number_of_types = count($file_types); ?> <p> <script type="text/javascript"> jQuery(document).ready(function($){ $("#<?php echo $btn['cow']; ?> _field").magnificPopup({ delegate: "a.wooccm-zoom-special", // child items selector, by clicking on it popup will open type: "image", zoom: { enabled: true, duration: 400, easing: "ease-out" } }); (function post_image_content() { var input = document.getElementById("<?php echo $btn['cow']; ?> _file"), formdata = false, loadfiles, formnames = [], loadfiles = []; $("#<?php echo $btn['cow']; ?> _files_button_wccm").click( function(){ $("#<?php echo $btn['cow']; ?> _field input[type=file]").click(); return false; }); if (window.FormData) { formdata = new FormData(); } function showUploadedItem ( source, getname, filetype ) { var list = document.getElementById("<?php echo $btn['cow']; ?> _field"), li = document.createElement("span"), name = document.createElement("name"), span = document.createElement("span"), zoom = document.createElement("a"), edit = document.createElement("a"), dele = document.createElement("a"), a = document.createElement("a"), spana = document.createElement("spana"), img = document.createElement("img"); name.innerHTML = getname; edit.innerHTML = "Edit"; dele.innerHTML = "Delete"; if (filetype.match("image.*")) { img.src = source; a.href = source; a.title = getname; edit.href = source; zoom.href = source; zoom.title = getname; zoom.innerHTML = "Zoom <img style=display:none />"; li.appendChild(a); a.appendChild(img); a.className = "wooccm-zoom-special wooccm-image-holder mfp-zoom"; zoom.className = "wooccm-zoom-special wooccm_zoom wooccm-btn wooccm-btn-zoom"; edit.className = "wooccm_edit wooccm-btn wooccm-btn-edit enable"; }else{ zoom.innerHTML = "Zoom"; li.appendChild(spana); spana.appendChild(img); spana.className = "wooccm-image-holder"; zoom.className = "wooccm_zoom wooccm-btn disable"; edit.className = "wooccm_edit wooccm-btn disable"; } if ( ( false === filetype.match("application/ms.*") && false === filetype.match("application/x.*") && false === filetype.match("audio.*") && false === filetype.match("text.*") && false === filetype.match("video.*") ) || ( 0 === filetype.length || !filetype) ) { img.src = "<?php echo site_url('wp-includes/images/media/interactive.png'); ?> "; } if (filetype.match("application/ms.*")) { img.src = "<?php echo site_url('wp-includes/images/media/spreadsheet.png'); ?> "; } if (filetype.match("application/x.*")) { img.src = "<?php echo site_url('wp-includes/images/media/archive.png'); ?> "; } if (filetype.match("audio.*")) { img.src = "<?php echo site_url('wp-includes/images/media/audio.png'); ?> "; } if (filetype.match("text.*")) { img.src = "<?php echo site_url('wp-includes/images/media/text.png'); ?> "; } if (filetype.match("video.*")) { img.src = "<?php echo site_url('wp-includes/images/media/video.png'); ?> "; } li.title = getname; dele.title = getname; edit.title = getname; li.appendChild(name); li.appendChild(span); span.appendChild(zoom); span.appendChild(edit); span.appendChild(dele); list.appendChild(li); li.className = "wooccm_each_file"; name.className = "wooccm_name"; dele.id = "wooccm_dele"; dele.className = "wooccm_dele wooccm-btn wooccm-btn-danger"; span.className = "container"; } input.addEventListener("change", function (evt) { $("#<?php echo $btn['cow']; ?> _field").block({ message: null, overlayCSS: { background: '#fff no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } }); var count = $("#<?php echo $btn['cow']; ?> _files_button_wccm").data("count") || 0; $("#<?php echo $btn['cow']; ?> _files_button_wccm").data("count", ++count); var img, reader, file, iname, len = <?php echo $length; ?> ; var file_array = <?php echo wooccm_js_array($file_types); ?> ; var wooempt = <?php echo $file_types; ?> ; for ( i = 0; i < len; i++ ) { file = this.files[i]; for(x=0; x < <?php echo $number_of_types; ?> ; x++){ if( !wooempt || file.type.match(file_array[x]) ) { if ( window.FileReader ) { reader = new FileReader(); reader.onload = (function(theFile){ var fileName = theFile.name, filetype = theFile.type; return function(e){ showUploadedItem( e.target.result, fileName, filetype ); }; })(file); reader.readAsDataURL(file); } formdata.append("<?php echo $btn['cow']; ?> ", file); formnames.push(file.name); loadfiles.push(file); $.ajax({ url: "<?php echo admin_url('/admin-ajax.php?action=wooccm_front_endupload&name=' . $btn['cow'] . ''); ?> ", type: "POST", data: formdata, cache: false, processData: false, contentType: false, success: function (res) { console.dir(res); var result = $.parseJSON(res), new_val; new_val = document.getElementById("<?php echo $btn['cow']; ?> ").value.split("||"); new_val[0] = result[0]; new_val[1] += result[1] + ","; document.getElementById("<?php echo $btn['cow']; ?> ").value = new_val[0] + "||" + new_val[1]; $("#<?php echo $btn['cow']; ?> _field").unblock(); } }); }else{ $("#<?php echo $btn['cow']; ?> _field").unblock(); } } } if( formdata ) { $("#<?php echo $btn['cow']; ?> _field").unblock(); } }, false); $("#caman_content #wooccmtoolbar #save").click( function(){ $("#caman_content #wooccmtoolbar").block({ message: null, overlayCSS: { background: '#fff no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } }); var title = this.title, the_file, wooxtro = document.getElementById("wooccmactualimage").getAttribute("data-caman-hidpi"), listing, store = [], count = $(".wooccm_each_file").each(function(){}); formdata = new FormData(); for(var t = 0; t < count.length; t++) { if( count[t].getAttribute("wooccm-attach-id") ){ break; } store.push(count[t]); } if( store.length !== 0 ){ listing = document.getElementById("<?php echo $btn['cow']; ?> ").value.split("||"); listing = listing[1].split(","); listing = listing.filter(Number); $.each(listing, function(index, value){ $(store[index]).attr("wooccm-attach-id", value); }); } $(".wooccm_each_file").each(function(){ if( this.title === title) { var currentgutz = this; this.firstElementChild.href = wooxtro; this.firstElementChild.firstElementChild.src = wooxtro; this.lastElementChild.firstElementChild.href = wooxtro; this.lastElementChild.lastElementChild.previousElementSibling.href = wooxtro; var byteString; var dataURI = wooxtro; //data:image/gif;base64,R0lGODlhyAAiALM...DfD0QAADs if (dataURI.split(',')[0].indexOf('base64') >= 0) byteString = atob(dataURI.split(',')[1]); else byteString = unescape(dataURI.split(',')[1]); // separate out the mime component var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]; // write the bytes of the string to a typed array var ia = new Uint8Array(byteString.length); for (var i = 0; i < byteString.length; i++) { ia[i] = byteString.charCodeAt(i); } var extension = mimeString.split('/')[1]; var fileName = "image_" + new Date().getTime() + "." + extension; var blob = new Blob([ia], {type:mimeString}); the_file = new File([blob], title, { type: "image/png" }); formdata.append("<?php echo $btn['cow']; ?> ", the_file); var remove = this.getAttribute("wooccm-attach-id"); $.ajax({ url: "<?php echo admin_url('/admin-ajax.php?action=wooccm_front_enduploadsave&name=' . $btn['cow'] . '&remove='); ?> " + remove, type: "POST", data: formdata, cache: false, processData: false, contentType: false, success: function (res) { var result = $.parseJSON(res); $(currentgutz).attr("wooccm-attach-id", result); $("#<?php echo $btn['cow']; ?> ").val(function(index, value) { return value.replace(remove, result); }); $("#caman_content #wooccmtoolbar").unblock(); alert("<?php echo wpml_string_wccm_pro($options['checkness']['picture_success']); ?> "); } }); } }); }); $(document).on('click','.wooccm_dele',function(){ var c = confirm("<?php echo wpml_string_wccm_pro($options['checkness']['file_delete']); ?> " + this.title + " ?"), listing, store = [], count = $(".wooccm_each_file").each(function(){}); if (c==true) { $("#<?php echo $btn['cow']; ?> _field").block({ message: null, overlayCSS: { background: '#fff no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } }); for(var t = 0; t < count.length; t++) { if( count[t].getAttribute("wooccm-attach-id") ){ break; } store.push(count[t]); } if( store.length !== 0 ){ listing = document.getElementById("<?php echo $btn['cow']; ?> ").value.split("||"); listing = listing[1].split(","); listing = listing.filter(Number); $.each(listing, function(index, value){ $(store[index]).attr("wooccm-attach-id", value); }); } var currentname = this.title, wooccmeachfile = document.getElementsByClassName("wooccm_each_file"), remove, shell; formdata = new FormData(); for( i = 0; i < wooccmeachfile.length; i++ ){ if(wooccmeachfile[i].title === currentname){ remove = wooccmeachfile[i].getAttribute("wooccm-attach-id"); shell = wooccmeachfile[i]; } } $.ajax({ url: "<?php echo admin_url('/admin-ajax.php?action=wooccm_front_enduploadsave&remove='); ?> " + remove, type: "POST", data: formdata, cache: false, processData: false, contentType: false, success: function (res) { remove = remove + ","; $("#<?php echo $btn['cow']; ?> ").val(function(index, value) { return value.replace(remove, ""); }); shell.outerHTML = ""; $("#<?php echo $btn['cow']; ?> _field").unblock(); } }); } else { } }); $("#caman_content #wooccmtoolbar #close").click( function(){ var li = document.getElementById( "wooccmactualimage" ); li.outerHTML = ""; $("#caman_content .FilterValue").each(function(){ $(this).text("0"); }); $("#caman_content .FilterSetting input").each(function(){ $(this).val("0"); }); $("#PresetFilters a").each(function(){ $(this).removeClass("Active"); }); $("#caman_content").hide(); $("html").css("overflow", "visible"); }); $(document).on('click','.wooccm_edit',function(){ return false; }); $(document).on('click','.wooccm_edit.enable',function(){ var imageinbase = this.href, li = document.getElementById( "wooccmimageeditorpro" ), data = document.createAttribute("data-caman-hidpi"), img = document.createElement("img"); data.value = imageinbase; $("#caman_content #wooccmtoolbar #save").attr("title", this.title); if( $(".wooccmimageeditor img").length == 0 ){ img.id = "wooccmactualimage"; img.src = imageinbase; img.setAttributeNode(data); li.appendChild(img); $.getScript( "<?php echo plugins_url('includes/pickers/caman/dist/caman_controls.js', WOOCCM_RELPATH); ?> "); } $("#caman_content").show(); $("html").css("overflow", "hidden"); }); }()); }); </script> </p> <?php } } } }
function wccs_file_uploader_front_end($order_id) { global $wpdb, $thepostid, $theorder, $woocommerce, $post; $order = new WC_Order($order_id); $options = get_option('wccs_settings'); $length = empty($options['checkness']['file_upload_number']) ? 'this.files.length' : $options['checkness']['file_upload_number']; $file_types = explode(",", $options['checkness']['file_types']); $number_of_types = count($file_types); $prefix = 'wc-'; if (empty($options['checkness']['upload_os']) || $order->post_status == $prefix . $options['checkness']['upload_os']) { $upload_dir = wp_upload_dir(); $args = array('post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $order_id); ?> <script type="text/javascript"> jQuery(document).ready(function($) { $('#wccm_save_order_submit').click(function() { $(".wccm_results").html("Deleting files, please wait...."); var ajaxurl = '<?php echo admin_url('/admin-ajax.php'); ?> '; data = { action: 'update_attachment_wccm', product_image_gallery : $('#product_image_gallery').val(), wccm_default_keys_load : $('#wccm_default_keys_load').val() }; // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php $.post(ajaxurl, data, function(response) { $(".wccm_results").html(response); }); }); }); </script> <?php wp_enqueue_style('wccm_upload_file_style', plugins_url('includes/classes/file_upload/file_editing_table.css', WOOCCM_RELPATH)); ?> <h2><?php echo empty($options['checkness']['upload_title']) ? 'Order Uploaded Files' : esc_attr($options['checkness']['upload_title']); ?> </h2> <div class="woocommerce_order_items_wrapper front_end"> <table class="woocommerce_order_items front_end"> <thead> <tr> <th style="width:12%"><?php _e('File Image', 'woocommerce-checkout-manager'); ?> </th> <th style="width:10%"><?php _e('Action', 'woocommerce-checkout-manager'); ?> </th> <th style="width:12%"><?php _e('Width x Height', 'woocommerce-checkout-manager'); ?> </th> <th style="width:8%"><?php _e('Extension', 'woocommerce-checkout-manager'); ?> </th> <th style="width:15%;text-align: center;"><?php _e('ID #', 'woocommerce-checkout-manager'); ?> </th> <th style="width:4%"><?php _e('Link', 'woocommerce-checkout-manager'); ?> </th> <th style="width:30%;text-align: center;"><?php _e('Name', 'woocommerce-checkout-manager'); ?> </th> </tr> </thead> <tbody class="product_images front_end"> <?php $attachment_args = get_posts($args); if ($attachment_args) { foreach ($attachment_args as $attachment) { $array[] = $attachment->ID; } $default_wccm_values = implode(',', $array); $product_image_gallery = implode(',', $array); } $attachments = array_filter(explode(',', $product_image_gallery)); if ($attachments) { foreach ($attachments as $attachment_id) { $image_attributes = wp_get_attachment_url($attachment_id); $image_attributes2 = wp_get_attachment_image_src($attachment_id); $filename = basename($image_attributes); $wp_filetype = wp_check_filetype($filename); $value_declear = array_diff(explode(',', $default_wccm_values), explode(',', $attachment_id)); echo ' <tr class="image wccm_filesli wccmv_' . esc_attr($attachment_id) . '"> <td style="display:none;"> <script type="text/javascript"> jQuery(document).ready(function(){ jQuery(".wccmx_' . esc_attr($attachment_id) . '").click(function(){ jQuery(".wccmv_' . esc_attr($attachment_id) . '").hide(); jQuery("#product_image_gallery").val(jQuery("#product_image_gallery").val().replace("' . esc_attr($attachment_id) . '", "")); }); }); </script> </td> <td>' . wp_get_attachment_link($attachment_id, '', false, false, wp_get_attachment_image($attachment_id, array(75, 75), true)) . '</td> <td> <a class="delete tips wccm_delete wccmx_' . esc_attr($attachment_id) . '" data-tip="' . __('Delete image', 'woocommerce') . '">' . __('Delete', 'woocommerce') . '</a> </td> <td>'; if ($image_attributes2[1] == '') { echo '-'; } else { echo $image_attributes2[1] . ' x ' . $image_attributes2[2]; } echo ' </td> <td>' . $wp_filetype['ext'] . '</td> <td>' . $attachment_id . '</td> <td>' . wp_get_attachment_link($attachment_id, '', false, false, 'Link') . '</td> <td>' . preg_replace('/\\.[^.]+$/', '', $filename) . '</td> </tr>'; } } else { echo ' <tr> <td colspan="7">No uploaded files have been assigned to this Order.</td> </tr> '; } ?> </tbody> <input type="hidden" class="wccm_add_to_list" id="product_image_gallery" name="product_image_gallery" value="<?php echo esc_attr($product_image_gallery); ?> " /> <input type="hidden" id="wccm_default_keys_load" name="wccm_default_keys_load" value="<?php echo esc_attr($default_wccm_values); ?> " /> </table> <!-- .woocommerce_order_items --> </div> <!-- .woocommerce_order_items_wrapper --> <button type="button" id="wccm_save_order_submit" class="file_upload_delete wooccm-btn wooccm-btn-danger delete">Confirm Delete</button> <span id="wccm_uploader_select"> <input type="file" style="display:none;" name="files_wccm" id="files_wccm" multiple /> <button type="button" class="file_upload_account wooccm-btn wooccm-btn-primary start" id="files_button_wccm">Upload Files</button> </span> <!-- #wccm_uploader_select --> <div class="wccm_results front_end"></div> <div class="clear"></div> <?php // script for uploading the files echo ' <script type="text/javascript"> jQuery(document).ready(function($){ (function post_image_content() { var input = document.getElementById("files_wccm"), formdata = false; $("#files_button_wccm").click( function(){ $("#wccm_uploader_select input[type=file]").click(); return false; }); if (window.FormData) { formdata = new FormData(); } input.addEventListener("change", function (evt) { $("#wccm_uploader_select").block({message: null, overlayCSS: {background: "#fff url(" + woocommerce_params.plugin_url + "/assets/images/ajax-loader.gif) no-repeat center", opacity: 0.6}}); $("#wccm_uploader_select").block({message: null, overlayCSS: {background: "#fff url(" + woocommerce_params.ajax_loader_url + ") no-repeat center", opacity: 0.6}}); var length = ' . $length . '; var file_array = ' . wooccm_js_array($file_types) . '; var wooempt = ' . $file_types . '; for ( i = 0; i < length; i++ ) { file = this.files[i]; for(x=0; x < ' . $number_of_types . '; x++){ if( !wooempt || file.type.match(file_array[x]) ) { if (formdata) { formdata.append("files_wccm[]",file); } } } } if (formdata) { $.ajax({ url: "' . admin_url('/admin-ajax.php?action=wccs_upload_file_func&order_id=' . $order_id . '&name=files_wccm') . '", type: "POST", data: formdata, processData: false, contentType: false, success: function (res) { $("#files_wccm").show(); $.ajax({ url: "' . $order->get_view_order_url() . '", data: {}, success: function (data) { $("div.woocommerce_order_items_wrapper.front_end").html($(data).find("div.woocommerce_order_items_wrapper.front_end")); jQuery("#wccm_uploader_select").unblock(); }, dataType: "html" }); } }); } }, false); } ()); }); </script>'; // end script // ------------ } }