default.php
1 month ago
default_media.php
1 month ago
default_upload.php
1 month ago
index.html
1 month ago
default_upload.php
212 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | $vik = VAPApplication::getInstance(); |
| 15 | |
| 16 | ?> |
| 17 | |
| 18 | <div class="vap-media-droptarget"> |
| 19 | <p class="icon"> |
| 20 | <i class="fas fa-upload" style="font-size: 48px;"></i> |
| 21 | </p> |
| 22 | |
| 23 | <div class="lead"> |
| 24 | <a href="javascript: void(0);" id="upload-file"><?php echo JText::translate('VAPMANUALUPLOAD'); ?></a> <?php echo JText::translate('VAPMEDIADRAGDROP'); ?> |
| 25 | </div> |
| 26 | |
| 27 | <p class="maxsize"> |
| 28 | <?php echo JText::sprintf('JGLOBAL_MAXIMUM_UPLOAD_SIZE_LIMIT', JHtml::fetch('vikappointments.maxuploadsize')); ?> |
| 29 | </p> |
| 30 | |
| 31 | <input type="file" id="legacy-upload" multiple style="display: none;"/> |
| 32 | </div> |
| 33 | |
| 34 | <script> |
| 35 | |
| 36 | // files upload |
| 37 | |
| 38 | jQuery(function($) { |
| 39 | |
| 40 | var dragCounter = 0; |
| 41 | |
| 42 | // drag&drop actions on target div |
| 43 | |
| 44 | $('.vap-media-droptarget').on('drag dragstart dragend dragover dragenter dragleave drop', function(e) { |
| 45 | e.preventDefault(); |
| 46 | e.stopPropagation(); |
| 47 | }); |
| 48 | |
| 49 | $('.vap-media-droptarget').on('dragenter', function(e) { |
| 50 | // increase the drag counter because we may |
| 51 | // enter into a child element |
| 52 | dragCounter++; |
| 53 | |
| 54 | $(this).addClass('drag-enter'); |
| 55 | }); |
| 56 | |
| 57 | $('.vap-media-droptarget').on('dragleave', function(e) { |
| 58 | // decrease the drag counter to check if we |
| 59 | // left the main container |
| 60 | dragCounter--; |
| 61 | |
| 62 | if (dragCounter <= 0) { |
| 63 | $(this).removeClass('drag-enter'); |
| 64 | } |
| 65 | }); |
| 66 | |
| 67 | $('.vap-media-droptarget').on('drop', function(e) { |
| 68 | |
| 69 | $(this).removeClass('drag-enter'); |
| 70 | |
| 71 | var files = e.originalEvent.dataTransfer.files; |
| 72 | |
| 73 | vapDispatchMediaUploads(files); |
| 74 | |
| 75 | }); |
| 76 | |
| 77 | $('.vap-media-droptarget #upload-file').on('click', function() { |
| 78 | // unset selected files before showing the dialog |
| 79 | $('input#legacy-upload').val(null).trigger('click'); |
| 80 | }); |
| 81 | |
| 82 | $('input#legacy-upload').on('change', function() { |
| 83 | // execute AJAX uploads after selecting the files |
| 84 | vapDispatchMediaUploads($(this)[0].files); |
| 85 | }); |
| 86 | |
| 87 | }); |
| 88 | |
| 89 | // upload |
| 90 | |
| 91 | function vapDispatchMediaUploads(files) { |
| 92 | var up_cont = jQuery('#vap-uploads-cont'); |
| 93 | |
| 94 | for (var i = 0; i < files.length; i++) { |
| 95 | if (files[i].name.match(/\.(png|jpe?g|gif|bmp)$/)) { |
| 96 | // show "uploads" section only in case there is |
| 97 | // at least a supported file |
| 98 | jQuery('#vap-uploads').show(); |
| 99 | |
| 100 | var status = new createStatusBar(); |
| 101 | status.setFileNameSize(files[i].name, files[i].size); |
| 102 | status.setProgress(0); |
| 103 | up_cont.append(status.getHtml()); |
| 104 | |
| 105 | vapMediaFileUploadThread(status, files[i]); |
| 106 | } else { |
| 107 | alert('File [' + files[i].name + '] not supported'); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | var fileCount = 0; |
| 113 | function createStatusBar() { |
| 114 | fileCount++; |
| 115 | this.statusbar = jQuery("<div class='vap-progressbar-status'></div>"); |
| 116 | this.filename = jQuery("<div class='vap-progressbar-filename'></div>").appendTo(this.statusbar); |
| 117 | this.size = jQuery("<div class='vap-progressbar-filesize hidden-phone'></div>").appendTo(this.statusbar); |
| 118 | this.progressBar = jQuery("<div class='vap-progressbar'><div></div></div>").appendTo(this.statusbar); |
| 119 | this.abort = jQuery("<div class='vap-progressbar-abort hidden-phone'>Abort</div>").appendTo(this.statusbar); |
| 120 | this.statusinfo = jQuery("<div class='vap-progressbar-info hidden-phone' style='display:none;'><?php echo addslashes(JText::translate('VAPMANAGEMEDIA11')); ?></div>").appendTo(this.statusbar); |
| 121 | this.completed = false; |
| 122 | |
| 123 | this.setFileNameSize = function(name, size) { |
| 124 | var sizeStr = ""; |
| 125 | if(size > 1024*1024) { |
| 126 | var sizeMB = size/(1024*1024); |
| 127 | sizeStr = sizeMB.toFixed(2)+" MB"; |
| 128 | } else if(size > 1024) { |
| 129 | var sizeKB = size/1024; |
| 130 | sizeStr = sizeKB.toFixed(2)+" kB"; |
| 131 | } else { |
| 132 | sizeStr = size.toFixed(2)+" B"; |
| 133 | } |
| 134 | |
| 135 | this.filename.html(name); |
| 136 | this.size.html(sizeStr); |
| 137 | } |
| 138 | |
| 139 | this.setProgress = function(progress) { |
| 140 | var progressBarWidth = progress*this.progressBar.width()/100; |
| 141 | this.progressBar.find('div').css('width', progressBarWidth+'px').html(progress + "% "); |
| 142 | if(parseInt(progress) >= 100) { |
| 143 | if( !this.completed ) { |
| 144 | this.abort.hide(); |
| 145 | this.statusinfo.show(); |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | this.complete = function() { |
| 151 | this.completed = true; |
| 152 | this.abort.hide(); |
| 153 | this.statusinfo.hide(); |
| 154 | this.setProgress(100); |
| 155 | this.progressBar.find('div').addClass('completed'); |
| 156 | } |
| 157 | |
| 158 | this.setAbort = function(jqxhr) { |
| 159 | var bar = this.progressBar; |
| 160 | this.abort.click(function() { |
| 161 | jqxhr.abort(); |
| 162 | this.hide(); |
| 163 | bar.find('div').addClass('aborted'); |
| 164 | }); |
| 165 | } |
| 166 | |
| 167 | this.getHtml = function() { |
| 168 | return this.statusbar; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | function vapMediaFileUploadThread(status, file) { |
| 173 | jQuery.noConflict(); |
| 174 | |
| 175 | var formData = new FormData(); |
| 176 | formData.append('file', file); |
| 177 | formData.append('isresize', jQuery('input[name="isresize"]:checked').val()); |
| 178 | formData.append('oriwres', jQuery('input[name="oriwres"]').val()); |
| 179 | formData.append('orihres', jQuery('input[name="orihres"]').val()); |
| 180 | formData.append('smallwres', jQuery('input[name="smallwres"]').val()); |
| 181 | formData.append('smallhres', jQuery('input[name="smallhres"]').val()); |
| 182 | |
| 183 | var xhr = UIAjax.upload( |
| 184 | // end-point URL |
| 185 | '<?php echo $vik->ajaxUrl('index.php?option=com_vikappointments&task=media.dropupload'); ?>', |
| 186 | // file post data |
| 187 | formData, |
| 188 | // success callback |
| 189 | function(resp) { |
| 190 | if (resp) { |
| 191 | status.complete(); |
| 192 | status.filename.html(resp.name); |
| 193 | } else { |
| 194 | status.progressBar.find('div').addClass('aborted'); |
| 195 | } |
| 196 | }, |
| 197 | // failure callback |
| 198 | function(error) { |
| 199 | status.progressBar.find('div').addClass('aborted'); |
| 200 | }, |
| 201 | // progress callback |
| 202 | function(progress) { |
| 203 | // update progress |
| 204 | status.setProgress(progress); |
| 205 | } |
| 206 | ); |
| 207 | |
| 208 | status.setAbort(xhr); |
| 209 | } |
| 210 | |
| 211 | </script> |
| 212 |