media-library-file.php
7 months ago
remote-url.php
2 years ago
server-file.php
3 years ago
upload-file.php
7 months ago
remote-url.php
50 lines
| 1 | <?php |
| 2 | if(!defined("ABSPATH")) die("Shit happens!"); |
| 3 | ?> |
| 4 | <div class="w3eden"> |
| 5 | <div class="input-group" style="margin-bottom: 10px"><input type="url" id="rurl" class="form-control" placeholder="Insert URL" style="margin-right: -1px"><span class="input-group-btn"><button type="button" id="rmta" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button></span></div> |
| 6 | </div> |
| 7 | |
| 8 | <script> |
| 9 | |
| 10 | jQuery(function($){ |
| 11 | |
| 12 | $('#rmta').click(function(){ |
| 13 | var d = new Date(); |
| 14 | var ID = d.getTime(); |
| 15 | var file = $('#rurl').val().replace(/[\<\>]/g, ''); |
| 16 | var filename = file; |
| 17 | $('#rurl').val(''); |
| 18 | |
| 19 | let regex = new RegExp("^(ftp:\/\/|http:\/\/|https:\/\/)[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$"); |
| 20 | if(!regex.test(file)){ |
| 21 | alert("Invalid url"); |
| 22 | return false; |
| 23 | } |
| 24 | |
| 25 | var ext = file.split('.'); |
| 26 | ext = ext[ext.length-1]; |
| 27 | if(ext.indexOf('://')) ext = 'url'; |
| 28 | else |
| 29 | if(ext.length==1 || ext==filename || ext.length>4 || ext=='') ext = '_blank'; |
| 30 | |
| 31 | var icon = "<?php echo WPDM_BASE_URL; ?>file-type-icons/"+ext.toLowerCase()+".png"; |
| 32 | var title = file; |
| 33 | title = title.split('/'); |
| 34 | title = title[title.length - 1]; |
| 35 | |
| 36 | var _file = {}; |
| 37 | _file.filetitle = (title); |
| 38 | _file.filepath = encodeURI(file); |
| 39 | _file.fileindex = ID; |
| 40 | _file.preview = icon; |
| 41 | wpdm_attach_file(_file); |
| 42 | |
| 43 | |
| 44 | |
| 45 | }); |
| 46 | |
| 47 | }); |
| 48 | |
| 49 | </script> |
| 50 |