-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxupload.js
More file actions
358 lines (318 loc) · 9.58 KB
/
xupload.js
File metadata and controls
358 lines (318 loc) · 9.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
var show_fname_chars=72;
//var upload_type='file';
var form_action;
var UID,interval,enccx;
function $$(elem){return document.getElementById(elem);}
function fileSelected(f)
{
if(!checkExt(f.value))return;
var files = $(f).prop("files");
var fnames=Array();
$.map(files, function (val) { fnames.push(val.name); });
if(fnames.length>1){
$(f).parents("table").find('.onefile').remove();
} else {
var fname = fnames[0];
var arr = fname.split(/[\.\_\-]+/);
var regx = /^(avi|mkv|mpg|mpeg|mov|divx|dvdrip|bdrip|mp4|flv|vob)$/i;
arr = jQuery.grep(arr, function (a) { return !regx.test(a) });
$(f).parents("tr").next().find("input[name=file_title]").val(arr.join(' '));
}
$(f).parent().hide().after( fnames.join("<br>") );
}
function openStatusWindow(f1,UID,fnames)
{
$('#utmodes').hide();
$('#progress').show();
$('#progress').offset( $('#div_file').offset() );
$('#progress').width( $('#div_file').outerWidth() );
$('#progress').height( $('#div_file').outerHeight() );
$('#div_file').css('visibility','hidden');
var d=new Date();
time_start = d.getTime();
interval = window.setInterval(function (){progressUpdate(UID);},1000);
$("#pbon").click(function (e){
e.preventDefault();
if($(this).html()=='on'){$(this).html('off');window.clearTimeout(interval);}
else{$(this).html('on');interval=window.setInterval(function (){progressUpdate(UID);},1000);};
});
}
function StartUpload(f1)
{
form_action = getFormAction(f1);
f1.target='xupload';
var NF=0;
var farr=new Array();
// Unchecked checkbox value hack
$('.upload_slot input[type="checkbox"]:not(:checked)').each( function(i)
{
$(this).append("<input type='hidden' value='0' name='"+$(this).prop('name')+"'>");
});
var err_bad_ext=0, err_no_cat=0;
$('input[type="file"][name="file"]').each( function(i)
{
if($(this).val() && $('select[name="cat_id"]:eq('+i+')').val()==0)err_no_cat=1;
if($(this).val()){
if(!checkExt($(this).val()))err_bad_ext=1;
name = $(this).val().match(/[^\\\/]+$/);
if(name && name!='null'){farr.push(name);NF++;}
}
});
if(err_bad_ext){ return false; }
if(err_no_cat && category_required){ alert(lng_uploadform_choose_category);return false; }
if(NF<=0){alert(lng_uploadform_select_file_to_upload);return false;};
if(f1.tos && !f1.tos.checked){alert(lng_uploadform_agree_to_tos);return false;};
//if($$('submit_btn')){$$('submit_btn').disabled=true;$$('submit_btn').value='Uploading...';}
UID='';
for(var i=0;i<12;i++)UID+=''+Math.floor(Math.random() * 10);
openStatusWindow( f1, UID, farr.join(', ') );
//window.scrollTo(0,0); +'&utype='+utype
form_action = form_action.split('?')[0]+'?X-Progress-ID='+UID; //cleaning old query to avoid ReUpload bugs
setFormAction(f1,form_action);
f1.action=form_action;
}
function checkExt(value)
{
//value = obj.value;
if(value=="")return true;
var re1 = new RegExp("^.+\.("+ext_allowed+")$","i");
if( ext_allowed && !re1.test(value) )
{
str='';
if(ext_allowed)str+="\n"+lng_uploadform_only_these_ext_allowed+" "+ext_allowed.replace(/\|/g,',');
alert(lng_uploadform_ext_not_allowed+" \"" + value + '"'+str);
return false;
}
return true;
}
function fixLength(str)
{
var arr = str.split(/\\/);
str = arr[arr.length-1];
if(str.length<show_fname_chars)return str;
return '...'+str.substring(str.length-show_fname_chars-1,str.length);
}
function getFormAction(f)
{
if(!f)return;
for(i=0;i<=f.attributes.length;i++)
{
if(f.attributes[i] && f.attributes[i].name.toLowerCase()=='action')return f.attributes[i].value;
}
return '';
}
function setFormAction(f,val)
{
for(i=0;i<=f.attributes.length;i++)
{
if(f.attributes[i] && f.attributes[i].name.toLowerCase()=='action')f.attributes[i].value=val;
}
}
function InitUploadSelector(id1,id2,max)
{
if($$(id1))
{
var multi_selector = new MultiSelector( id1, max );
multi_selector.addElement( $$( id2 ) );
}
}
function findPos(obj)
{
var curleft = curtop = 0;
if (obj.offsetParent)
{
do {curleft += obj.offsetLeft;curtop += obj.offsetTop;} while (obj = obj.offsetParent);
}
return [curleft,curtop];
}
function changeUploadType(utype)
{
$$('div_file').style.position='absolute';
if($$('div_url'))$$('div_url').style.position='absolute';
if($$('div_rs'))$$('div_rs').style.position='absolute';
if($$('div_tt'))$$('div_tt').style.position='absolute';
if($$('div_ff'))$$('div_ff').style.position='absolute';
$$('div_'+utype).style.position='static';
$('#utmodes > input.active').removeClass('active');
$('#r_'+utype).addClass('active');
}
function jah(url,id,silent)
{
var obj;
if(id)
{
if(id !== null && typeof id === 'object'){obj=id} else {obj=$('#'+id)}
}
if(obj &&!silent)
{
obj.html('...');
}
$.get(url,function (data){
if(obj)
{
obj.html(data);
}
else
{
//alert(data);
eval(data);
};
});
return false;
};
function scaleImg(i)
{
if(i.width>800)
{
w=i.width;
h=i.height;
wn = 800;
hn = parseInt(i.height*800/i.width);
i.width = wn;
i.height = hn;
i.onclick = function(){ if(this.width==wn){this.width=w;this.height=h;}else{this.width=wn;this.height=hn;} }
return;
}
}
function OpenWin(link,w,h)
{
if(!w)w=720;
if(!h)h=700;
var popupWin = window.open(link,null, 'width='+w+',height='+h+',status=no,scrollbars=yes,resizable=yes,left=450,top=250');
popupWin.focus();
return false;
}
function player_start()
{
$('#player_ads').show();
//$('#player_img').hide();
//$('#player_code').show();
//alert(player);
//player.sendEvent('PLAY');
return false;
}
function copy(obj)
{
obj.focus();
obj.select();
}
function download_video(code,mode,hash)
{
window.location='/dl?op=download_orig&id='+code+'&mode='+mode+'&hash='+hash;
}
function convertSeconds(seconds)
{
var secs = seconds % 60;
var mins = ((seconds - secs) % 3600) / 60;
var hours = ((seconds - secs - mins*60) % 86400) / 3600;
if(hours>0)
{
return hours+' hours '+mins+' minutes';
}
else if(mins>0)
{
return mins+' minutes '+secs+' seconds';
}
else
{
return secs+' seconds';
}
}
function convertSize(size)
{
if (size > 1024*1024*1024) {
size = Math.round(size/(1024*1024*1024)*10)/10 + " Gb";
} else if (size > 1024*1024) {
size = Math.round(size/(1024*1024)*10)/10+'';
if(!size.match(/\./))size+='.0';
size+=' Mb';
} else if(size > 1024) {
size = Math.round(size/1024*10)/10 + " Kb";
} else {
size = size + " Bytes";
}
return size;
}
$(document).ready(function() {
//smth
});
// Progress bar functions
function SP(cursize,totalsize,speed,estimate)
{
var percent = parseInt(100*parseFloat(cursize)/parseFloat(totalsize));
$('#upload_status').css('width', percent+'%');
$('#percent').html( percent+'%' );
$('#cursize').html( convertSize(cursize) );
$('#totalsize').html( convertSize(totalsize) );
$('#speed').html(speed);
$('#estimate').html( convertSeconds(estimate) );
}
function progressUpdate(uid)
{
var speed = 0;
var time_left =0;
$.getJSON( srv_htdocs_url+'/progress?X-Progress-ID='+uid+'&callback=?', {
format: "json"
})
.fail(function() {window.clearTimeout(interval);$('#progress_msg').html('Uploading...');})
.done(function( upload ) {
if (upload.state == 'uploading')
{
if(!total || total==''){total=upload.size;$('#progress_info').show();$('#progress_msg').html('');}
if(upload.received>=upload.size)
{
SP(total, total, 0, 0);
$('#progress_info').hide();
$('#progress_msg').html('Generating links...');
window.clearTimeout(interval);
return;
}
speed = 1000*upload.received / ((new Date()).getTime() - time_start);
est = Math.round( (upload.size-upload.received)/speed );
speed = Math.round(speed / 1024);
SP(upload.received, upload.size, speed, est);
}
else if (upload.state == 'done')
{
SP(upload.size, upload.size, 0, 0);
$('#progress_info').hide();
$('#progress_msg').html('Generating links...');
window.clearTimeout(interval);
}
else if (upload.state == 'error')
{
$('#progress_msg').html(upload.msg);
window.clearTimeout(interval);
loc = top.window.location+'';
}
} );
};
function encStatus(fid,init)
{
if(init)
{
enccx=init;
if($('#enc_pp')) setInterval("encStatus("+fid+")",10000);
}
enccx++;
if(enccx>1000)return;
$.get('/dl?op=enc_status&id='+fid, function() {}, 'script');
}
$.fn.shiftSelectable = function() {
var lastChecked,
$boxes = this;
$boxes.click(function(evt) {
if(!lastChecked) {
lastChecked = this;
return;
}
if(evt.shiftKey) {
var start = $boxes.index(this),
end = $boxes.index(lastChecked);
$boxes.slice(Math.min(start, end), Math.max(start, end) + 1)
.prop('checked', lastChecked.checked)
.trigger('change');
}
lastChecked = this;
});
};