upload_billing_scripts_enhanced

The WooCommerce Checkout Manager upload billing scripts enhanced function.

Description

upload_billing_scripts_enhanced(); 

Usage

  1. if ( !function_exists( 'upload_billing_scripts_enhanced' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-checkout-manager/includes/templates/functions/billing_wooccmupload.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = upload_billing_scripts_enhanced(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/templates/functions/billing_wooccmupload.php  
  1. function upload_billing_scripts_enhanced() { 
  2. global $woocommerce; 
  3. $options = get_option( 'wccs_settings3' ); 
  4.  
  5. if( !empty($options['billing_buttons']) ) { 
  6. foreach ( $options['billing_buttons'] as $btn ) : 
  7.  
  8.  
  9. if ( $btn['type'] == 'wooccmupload' ) { 
  10. ?> 
  11. <p> 
  12. <script type="text/javascript"> 
  13. jQuery(document).ready(function($) { 
  14.  
  15. $("#billing_<?php echo $btn['cow']; ?>_field").magnificPopup({ 
  16. delegate: "a.wooccm-zoom-special", // child items selector, by clicking on it popup will open 
  17. type: "image",  
  18. zoom: { 
  19. enabled: true,  
  20. duration: 400,  
  21. easing: "ease-out" 
  22. }); 
  23.  
  24. (function post_image_content() { 
  25. var input = document.getElementById("<?php echo $btn['cow']; ?>_file"),  
  26. formdata = false, loadfiles, formnames = [], loadfiles = []; 
  27.  
  28. $("#billing_<?php echo $btn['cow']; ?>_files_button_wccm").click( function() { 
  29. $("#billing_<?php echo $btn['cow']; ?>_field input[type=file]").click(); 
  30. return false; 
  31. }); 
  32.  
  33. if (window.FormData) { 
  34. formdata = new FormData(); 
  35.  
  36. function showUploadedItem ( source, getname, filetype ) { 
  37. var  
  38. list = document.getElementById("billing_<?php echo $btn['cow']; ?>_field"),  
  39. li = document.createElement("span"),  
  40. name = document.createElement("name"),  
  41. span = document.createElement("span"),  
  42. zoom = document.createElement("a"),  
  43. edit = document.createElement("a"),  
  44. dele = document.createElement("a"),  
  45. a = document.createElement("a"),  
  46. spana = document.createElement("spana"),  
  47. img = document.createElement("img"); 
  48.  
  49. name.innerHTML = getname; 
  50. edit.innerHTML = "Edit"; 
  51. dele.innerHTML = "Delete"; 
  52. if (filetype.match("image.*")) { 
  53. img.src = source; 
  54. a.href = source; 
  55. a.title = getname; 
  56. edit.href = source; 
  57. zoom.href = source; 
  58. zoom.title = getname; 
  59. zoom.innerHTML = "Zoom <img style=display:none />"; 
  60. li.appendChild(a); 
  61. a.appendChild(img); 
  62. a.className = "wooccm-zoom-special wooccm-image-holder mfp-zoom"; 
  63. zoom.className = "wooccm-zoom-special wooccm_zoom wooccm-btn wooccm-btn-zoom"; 
  64. edit.className = "wooccm_edit wooccm-btn wooccm-btn-edit enable"; 
  65. }else{ 
  66. zoom.innerHTML = "Zoom"; 
  67. li.appendChild(spana); 
  68. spana.appendChild(img); 
  69. spana.className = "wooccm-image-holder"; 
  70. zoom.className = "wooccm_zoom wooccm-btn disable"; 
  71. edit.className = "wooccm_edit wooccm-btn disable"; 
  72. 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) ) { 
  73. img.src = "<?php echo site_url('wp-includes/images/media/interactive.png'); ?>"; 
  74. if (filetype.match("application/ms.*")) { 
  75. img.src = "<?php echo site_url('wp-includes/images/media/spreadsheet.png'); ?>"; 
  76. if (filetype.match("application/x.*")) { 
  77. img.src = "<?php echo site_url('wp-includes/images/media/archive.png'); ?>"; 
  78. if (filetype.match("audio.*")) { 
  79. img.src = "<?php echo site_url('wp-includes/images/media/audio.png'); ?>"; 
  80. if (filetype.match("text.*")) { 
  81. img.src = "<?php echo site_url('wp-includes/images/media/text.png'); ?>"; 
  82. if (filetype.match("video.*")) { 
  83. img.src = "<?php echo site_url('wp-includes/images/media/video.png'); ?>"; 
  84.  
  85. li.title = getname; 
  86. dele.title = getname; 
  87. edit.title = getname; 
  88. li.appendChild(name); 
  89. li.appendChild(span); 
  90. span.appendChild(zoom); 
  91. span.appendChild(edit); 
  92. span.appendChild(dele); 
  93. list.appendChild(li); 
  94. li.className = "wooccm_each_file"; 
  95. name.className = "wooccm_name"; 
  96. dele.id = "wooccm_dele"; 
  97. dele.className = "wooccm_dele wooccm-btn wooccm-btn-danger"; 
  98. span.className = "container"; 
  99.  
  100.  
  101.  
  102. input.addEventListener("change", function (evt) { 
  103. $("#billing_<?php echo $btn['cow']; ?>_field").block({ message: null, overlayCSS: { background: '#fff no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } }); 
  104.  
  105. var count = $("#billing_<?php echo $btn['cow']; ?>_files_button_wccm").data("count") || 0; 
  106. $("#billing_<?php echo $btn['cow']; ?>_files_button_wccm").data("count", ++count); 
  107.  
  108. var img, reader, file, iname, len = this.files.length; 
  109.  
  110. for ( i = 0; i < len; i++ ) { 
  111. file = this.files[i]; 
  112.  
  113. if ( window.FileReader ) { 
  114. reader = new FileReader(); 
  115. reader.onload = (function(theFile) { 
  116. var fileName = theFile.name,  
  117. filetype = theFile.type; 
  118. return function(e) { 
  119. showUploadedItem( e.target.result, fileName, filetype ); 
  120. }; 
  121. })(file);  
  122. reader.readAsDataURL(file); 
  123.  
  124. formdata.append("billing_<?php echo $btn['cow']; ?>[]", file); 
  125. formnames.push(file.name); 
  126. loadfiles.push(file); 
  127.  
  128. $.ajax({ 
  129. url: "<?php echo admin_url('/admin-ajax.php?action=wooccm_front_endupload&name='.$btn['cow'].''); ?>",  
  130. type: "POST",  
  131. data: formdata,  
  132. processData: false,  
  133. contentType: false,  
  134. success: function (res) { 
  135. var result = $.parseJSON(res), new_val; 
  136.  
  137. new_val = document.getElementById("billing_<?php echo $btn['cow']; ?>").value.split("||"); 
  138. new_val[0] = result[0]; 
  139. new_val[1] += result[1] + ", "; 
  140. document.getElementById("billing_<?php echo $btn['cow']; ?>").value = new_val[0] + "||" + new_val[1]; 
  141.  
  142. $("#billing_<?php echo $btn['cow']; ?>_field").unblock(); 
  143. }); 
  144.  
  145. if( formdata ) {  
  146. $("#billing_<?php echo $btn['cow']; ?>_field").unblock(); 
  147.  
  148.  
  149. }, false); 
  150.  
  151. $("#caman_content #wooccmtoolbar #save").click( function() { 
  152. $("#caman_content #wooccmtoolbar").block({ message: null, overlayCSS: { background: '#fff no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } }); 
  153.  
  154. var title = this.title, the_file, wooxtro = document.getElementById("wooccmactualimage").getAttribute("data-caman-hidpi"), listing, store = [], count = $(".wooccm_each_file").each(function() {}); 
  155. formdata = new FormData(); 
  156.  
  157. for(var t = 0; t < count.length; t++) { 
  158. if( count[t].getAttribute("wooccm-attach-id") ) { 
  159. break; 
  160. store.push(count[t]); 
  161.  
  162. if( store.length !== 0 ) { 
  163. listing = document.getElementById("billing_<?php echo $btn['cow']; ?>").value.split("||"); 
  164. listing = listing[1].split(", "); 
  165. listing = listing.filter(Number); 
  166.  
  167. $.each(listing, function(index, value) { 
  168. $(store[index]).attr("wooccm-attach-id", value); 
  169. }); 
  170.  
  171.  
  172. $(".wooccm_each_file").each(function() { 
  173. if( this.title === title) { 
  174. var currentgutz = this; 
  175. this.firstElementChild.href = wooxtro; 
  176. this.firstElementChild.firstElementChild.src = wooxtro; 
  177. this.lastElementChild.firstElementChild.href = wooxtro; 
  178. this.lastElementChild.lastElementChild.previousElementSibling.href = wooxtro;  
  179.  
  180. var byteString; 
  181. var dataURI = wooxtro; //data:image/gif;base64, R0lGODlhyAAiALM...DfD0QAADs 
  182.  
  183. if (dataURI.split(', ')[0].indexOf('base64') >= 0) 
  184.  
  185. byteString = atob(dataURI.split(', ')[1]); 
  186.  
  187. else 
  188.  
  189. byteString = unescape(dataURI.split(', ')[1]); 
  190.  
  191. // separate out the mime component 
  192. var mimeString = dataURI.split(', ')[0].split(':')[1].split(';')[0]; 
  193.  
  194. // write the bytes of the string to a typed array 
  195. var ia = new Uint8Array(byteString.length); 
  196. for (var i = 0; i < byteString.length; i++) { 
  197. ia[i] = byteString.charCodeAt(i); 
  198.  
  199. var extension = mimeString.split('/')[1]; 
  200. var fileName = "image_" + new Date().getTime() + "." + extension; 
  201. var blob = new Blob([ia], {type:mimeString}); 
  202.  
  203. the_file = new File([blob], title, { 
  204. type: "image/png"  
  205. }); 
  206.  
  207.  
  208. formdata.append("billing_<?php echo $btn['cow']; ?>[]", the_file); 
  209. var remove = this.getAttribute("wooccm-attach-id"); 
  210.  
  211. $.ajax({ 
  212. url: "<?php echo admin_url('/admin-ajax.php?action=wooccm_front_enduploadsave&name='.$btn['cow'].'&remove='); ?>" + remove,  
  213. type: "POST",  
  214. data: formdata,  
  215. processData: false,  
  216. contentType: false,  
  217. success: function (res) { 
  218. var result = $.parseJSON(res); 
  219. $(currentgutz).attr("wooccm-attach-id", result); 
  220. $("#billing_<?php echo $btn['cow']; ?>").val(function(index, value) { 
  221. return value.replace(remove, result); 
  222. }); 
  223.  
  224. $("#caman_content #wooccmtoolbar").unblock(); 
  225. alert("billing_<?php echo $options['checkness']['picture_success']; ?>"); 
  226.  
  227. }); 
  228. }); 
  229.  
  230.  
  231. }); 
  232.  
  233. $(document).on('click', '.wooccm_dele', function() {  
  234.  
  235. var c = confirm("<?php echo $options['checkness']['file_delete']; ?> " + this.title + " ?"), listing, store = [], count = $(".wooccm_each_file").each(function() {}); 
  236. if (c==true) { 
  237.  
  238. $("#billing_<?php echo $btn['cow']; ?>_field").block({ message: null, overlayCSS: { background: '#fff no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } }); 
  239.  
  240. for(var t = 0; t < count.length; t++) { 
  241. if( count[t].getAttribute("wooccm-attach-id") ) { 
  242. break; 
  243. store.push(count[t]); 
  244.  
  245. if( store.length !== 0 ) { 
  246. listing = document.getElementById("billing_<?php echo $btn['cow']; ?>").value.split("||"); 
  247. listing = listing[1].split(", "); 
  248. listing = listing.filter(Number); 
  249.  
  250. $.each(listing, function(index, value) { 
  251. $(store[index]).attr("wooccm-attach-id", value); 
  252. }); 
  253.  
  254. var currentname = this.title, wooccmeachfile = document.getElementsByClassName("wooccm_each_file"), remove, shell; 
  255. formdata = new FormData(); 
  256.  
  257. for( i = 0; i < wooccmeachfile.length; i++ ) { 
  258. if(wooccmeachfile[i].title === currentname) { 
  259. remove = wooccmeachfile[i].getAttribute("wooccm-attach-id"); 
  260. shell = wooccmeachfile[i]; 
  261.  
  262. $.ajax({ 
  263. url: "<?php echo admin_url('/admin-ajax.php?action=wooccm_front_enduploadsave&remove='); ?>" + remove,  
  264. type: "POST",  
  265. data: formdata,  
  266. processData: false,  
  267. contentType: false,  
  268. success: function (res) { 
  269. remove = remove + ", "; 
  270. $("#billing_<?php echo $btn['cow']; ?>").val(function(index, value) { 
  271. return value.replace(remove, ""); 
  272. }); 
  273.  
  274. shell.outerHTML = ""; 
  275.  
  276. $("#billing_<?php echo $btn['cow']; ?>_field").unblock(); 
  277.  
  278. }); 
  279.  
  280.  
  281. } else { 
  282.  
  283. }); 
  284.  
  285.  
  286.  
  287. $("#caman_content #wooccmtoolbar #close").click( function() { 
  288. var li = document.getElementById( "wooccmactualimage" ); 
  289. li.outerHTML = ""; 
  290. $("#caman_content .FilterValue").each(function() { 
  291. $(this).text("0"); 
  292. }); 
  293. $("#caman_content .FilterSetting input").each(function() { 
  294. $(this).val("0"); 
  295. }); 
  296. $("#PresetFilters a").each(function() { 
  297. $(this).removeClass("Active"); 
  298. }); 
  299. $("#caman_content").hide(); 
  300. $("html").css("overflow", "visible"); 
  301. }); 
  302.  
  303. $(document).on('click', '.wooccm_edit', function() { 
  304. return false; 
  305. }); 
  306.  
  307. $(document).on('click', '.wooccm_edit.enable', function() {  
  308. var imageinbase = this.href,  
  309. li = document.getElementById( "wooccmimageeditorpro" ),  
  310. data = document.createAttribute("data-caman-hidpi"),  
  311. img = document.createElement("img"); 
  312.  
  313. data.value = imageinbase; 
  314.  
  315. $("#caman_content #wooccmtoolbar #save").attr("title", this.title); 
  316.  
  317. if( $(".wooccmimageeditor img").length == 0 ) { 
  318. img.id = "wooccmactualimage"; 
  319. img.src = imageinbase; 
  320. img.setAttributeNode(data); 
  321. li.appendChild(img); 
  322.  
  323.  
  324. $.getScript( "<?php echo plugins_url('woocommerce-checkout-manager-pro/includes/pickers/caman/dist/caman_controls.js'); ?>"); 
  325.  
  326. $("#caman_content").show(); 
  327. $("html").css("overflow", "hidden"); 
  328. }); 
  329.  
  330.  
  331.  
  332.  
  333. }()); 
  334. }); 
  335. </script> 
  336. </p> 
  337.  
  338. <?php 
  339. endforeach;