Edit File by line
/home/barbar84/www/wp-conte.../plugins/file-man.../applicat.../library/js/commands
File: extract.js
/**
[0] Fix | Delete
* @class elFinder command "extract"
[1] Fix | Delete
* Extract files from archive
[2] Fix | Delete
*
[3] Fix | Delete
* @author Dmitry (dio) Levashov
[4] Fix | Delete
**/
[5] Fix | Delete
elFinder.prototype.commands.extract = function() {
[6] Fix | Delete
"use strict";
[7] Fix | Delete
var self = this,
[8] Fix | Delete
fm = self.fm,
[9] Fix | Delete
mimes = [],
[10] Fix | Delete
filter = function(files) {
[11] Fix | Delete
var fres = true;
[12] Fix | Delete
return $.grep(files, function(file) {
[13] Fix | Delete
fres = fres && file.read && $.inArray(file.mime, mimes) !== -1 ? true : false;
[14] Fix | Delete
return fres;
[15] Fix | Delete
});
[16] Fix | Delete
};
[17] Fix | Delete
[18] Fix | Delete
this.variants = [];
[19] Fix | Delete
this.disableOnSearch = true;
[20] Fix | Delete
[21] Fix | Delete
// Update mimes list on open/reload
[22] Fix | Delete
fm.bind('open reload', function() {
[23] Fix | Delete
mimes = fm.option('archivers')['extract'] || [];
[24] Fix | Delete
if (fm.api > 2) {
[25] Fix | Delete
self.variants = [[{makedir: true}, fm.i18n('cmdmkdir')], [{}, fm.i18n('btnCwd')]];
[26] Fix | Delete
} else {
[27] Fix | Delete
self.variants = [[{}, fm.i18n('btnCwd')]];
[28] Fix | Delete
}
[29] Fix | Delete
self.change();
[30] Fix | Delete
});
[31] Fix | Delete
[32] Fix | Delete
this.getstate = function(select) {
[33] Fix | Delete
var sel = this.files(select),
[34] Fix | Delete
cnt = sel.length,
[35] Fix | Delete
cwdHash, cwdChk;
[36] Fix | Delete
if (!cnt || filter(sel).length != cnt) {
[37] Fix | Delete
return -1;
[38] Fix | Delete
} else if (fm.searchStatus.state > 0) {
[39] Fix | Delete
cwdHash = this.fm.cwd().hash;
[40] Fix | Delete
$.each(sel, function(i, file) {
[41] Fix | Delete
cwdChk = (file.phash === cwdHash);
[42] Fix | Delete
return cwdChk;
[43] Fix | Delete
});
[44] Fix | Delete
return cwdChk? 0 : -1;
[45] Fix | Delete
} else {
[46] Fix | Delete
return this.fm.cwd().write? 0 : -1;
[47] Fix | Delete
}
[48] Fix | Delete
};
[49] Fix | Delete
[50] Fix | Delete
this.exec = function(hashes, opts) {
[51] Fix | Delete
var files = this.files(hashes),
[52] Fix | Delete
dfrd = $.Deferred(),
[53] Fix | Delete
cnt = files.length,
[54] Fix | Delete
makedir = opts && opts.makedir ? 1 : 0,
[55] Fix | Delete
i, error,
[56] Fix | Delete
decision,
[57] Fix | Delete
[58] Fix | Delete
overwriteAll = false,
[59] Fix | Delete
omitAll = false,
[60] Fix | Delete
mkdirAll = 0,
[61] Fix | Delete
siblings = fm.files(files[0].phash),
[62] Fix | Delete
[63] Fix | Delete
names = [],
[64] Fix | Delete
map = {};
[65] Fix | Delete
[66] Fix | Delete
$.each(siblings, function(id, file) {
[67] Fix | Delete
map[file.name] = file;
[68] Fix | Delete
names.push(file.name);
[69] Fix | Delete
});
[70] Fix | Delete
[71] Fix | Delete
var decide = function(decision) {
[72] Fix | Delete
switch (decision) {
[73] Fix | Delete
case 'overwrite_all' :
[74] Fix | Delete
overwriteAll = true;
[75] Fix | Delete
break;
[76] Fix | Delete
case 'omit_all':
[77] Fix | Delete
omitAll = true;
[78] Fix | Delete
break;
[79] Fix | Delete
}
[80] Fix | Delete
};
[81] Fix | Delete
[82] Fix | Delete
var unpack = function(file) {
[83] Fix | Delete
if (!(file.read && fm.file(file.phash).write)) {
[84] Fix | Delete
error = ['errExtract', file.name, 'errPerm'];
[85] Fix | Delete
fm.error(error);
[86] Fix | Delete
dfrd.reject(error);
[87] Fix | Delete
} else if ($.inArray(file.mime, mimes) === -1) {
[88] Fix | Delete
error = ['errExtract', file.name, 'errNoArchive'];
[89] Fix | Delete
fm.error(error);
[90] Fix | Delete
dfrd.reject(error);
[91] Fix | Delete
} else {
[92] Fix | Delete
fm.request({
[93] Fix | Delete
data:{cmd:'extract', target:file.hash, makedir:makedir},
[94] Fix | Delete
notify:{type:'extract', cnt:1},
[95] Fix | Delete
syncOnFail:true,
[96] Fix | Delete
navigate:{
[97] Fix | Delete
toast : makedir? {
[98] Fix | Delete
incwd : {msg: fm.i18n(['complete', fm.i18n('cmdextract')]), action: {cmd: 'open', msg: 'cmdopen'}},
[99] Fix | Delete
inbuffer : {msg: fm.i18n(['complete', fm.i18n('cmdextract')]), action: {cmd: 'open', msg: 'cmdopen'}}
[100] Fix | Delete
} : {
[101] Fix | Delete
inbuffer : {msg: fm.i18n(['complete', fm.i18n('cmdextract')])}
[102] Fix | Delete
}
[103] Fix | Delete
}
[104] Fix | Delete
})
[105] Fix | Delete
.fail(function (error) {
[106] Fix | Delete
if (dfrd.state() != 'rejected') {
[107] Fix | Delete
dfrd.reject(error);
[108] Fix | Delete
}
[109] Fix | Delete
})
[110] Fix | Delete
.done(function () {
[111] Fix | Delete
});
[112] Fix | Delete
}
[113] Fix | Delete
};
[114] Fix | Delete
[115] Fix | Delete
var confirm = function(files, index) {
[116] Fix | Delete
var file = files[index],
[117] Fix | Delete
name = fm.splitFileExtention(file.name)[0],
[118] Fix | Delete
existed = ($.inArray(name, names) >= 0),
[119] Fix | Delete
next = function(){
[120] Fix | Delete
if((index+1) < cnt) {
[121] Fix | Delete
confirm(files, index+1);
[122] Fix | Delete
} else {
[123] Fix | Delete
dfrd.resolve();
[124] Fix | Delete
}
[125] Fix | Delete
};
[126] Fix | Delete
if (!makedir && existed && map[name].mime != 'directory') {
[127] Fix | Delete
fm.confirm(
[128] Fix | Delete
{
[129] Fix | Delete
title : fm.i18n('ntfextract'),
[130] Fix | Delete
text : ['errExists', name, 'confirmRepl'],
[131] Fix | Delete
accept:{
[132] Fix | Delete
label : 'btnYes',
[133] Fix | Delete
callback:function (all) {
[134] Fix | Delete
decision = all ? 'overwrite_all' : 'overwrite';
[135] Fix | Delete
decide(decision);
[136] Fix | Delete
if(!overwriteAll && !omitAll) {
[137] Fix | Delete
if('overwrite' == decision) {
[138] Fix | Delete
unpack(file);
[139] Fix | Delete
}
[140] Fix | Delete
if((index+1) < cnt) {
[141] Fix | Delete
confirm(files, index+1);
[142] Fix | Delete
} else {
[143] Fix | Delete
dfrd.resolve();
[144] Fix | Delete
}
[145] Fix | Delete
} else if(overwriteAll) {
[146] Fix | Delete
for (i = index; i < cnt; i++) {
[147] Fix | Delete
unpack(files[i]);
[148] Fix | Delete
}
[149] Fix | Delete
dfrd.resolve();
[150] Fix | Delete
}
[151] Fix | Delete
}
[152] Fix | Delete
},
[153] Fix | Delete
reject : {
[154] Fix | Delete
label : 'btnNo',
[155] Fix | Delete
callback:function (all) {
[156] Fix | Delete
decision = all ? 'omit_all' : 'omit';
[157] Fix | Delete
decide(decision);
[158] Fix | Delete
if(!overwriteAll && !omitAll && (index+1) < cnt) {
[159] Fix | Delete
confirm(files, index+1);
[160] Fix | Delete
} else if (omitAll) {
[161] Fix | Delete
dfrd.resolve();
[162] Fix | Delete
}
[163] Fix | Delete
}
[164] Fix | Delete
},
[165] Fix | Delete
cancel : {
[166] Fix | Delete
label : 'btnCancel',
[167] Fix | Delete
callback:function () {
[168] Fix | Delete
dfrd.resolve();
[169] Fix | Delete
}
[170] Fix | Delete
},
[171] Fix | Delete
all : ((index+1) < cnt)
[172] Fix | Delete
}
[173] Fix | Delete
);
[174] Fix | Delete
} else if (!makedir) {
[175] Fix | Delete
if (mkdirAll == 0) {
[176] Fix | Delete
fm.confirm({
[177] Fix | Delete
title : fm.i18n('cmdextract'),
[178] Fix | Delete
text : [fm.i18n('cmdextract')+' "'+file.name+'"', 'confirmRepl'],
[179] Fix | Delete
accept:{
[180] Fix | Delete
label : 'btnYes',
[181] Fix | Delete
callback:function (all) {
[182] Fix | Delete
all && (mkdirAll = 1);
[183] Fix | Delete
unpack(file);
[184] Fix | Delete
next();
[185] Fix | Delete
}
[186] Fix | Delete
},
[187] Fix | Delete
reject : {
[188] Fix | Delete
label : 'btnNo',
[189] Fix | Delete
callback:function (all) {
[190] Fix | Delete
all && (mkdirAll = -1);
[191] Fix | Delete
next();
[192] Fix | Delete
}
[193] Fix | Delete
},
[194] Fix | Delete
cancel : {
[195] Fix | Delete
label : 'btnCancel',
[196] Fix | Delete
callback:function () {
[197] Fix | Delete
dfrd.resolve();
[198] Fix | Delete
}
[199] Fix | Delete
},
[200] Fix | Delete
all : ((index+1) < cnt)
[201] Fix | Delete
});
[202] Fix | Delete
} else {
[203] Fix | Delete
(mkdirAll > 0) && unpack(file);
[204] Fix | Delete
next();
[205] Fix | Delete
}
[206] Fix | Delete
} else {
[207] Fix | Delete
unpack(file);
[208] Fix | Delete
next();
[209] Fix | Delete
}
[210] Fix | Delete
};
[211] Fix | Delete
[212] Fix | Delete
if (!(this.enabled() && cnt && mimes.length)) {
[213] Fix | Delete
return dfrd.reject();
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
if(cnt > 0) {
[217] Fix | Delete
confirm(files, 0);
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
return dfrd;
[221] Fix | Delete
};
[222] Fix | Delete
[223] Fix | Delete
};
[224] Fix | Delete
[225] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function