/*********************************************************************************************************
This code is part of the FileManager software (www.gerd-tentler.de/tools/filemanager), copyright by
Gerd Tentler. Obtain permission before selling this code or hosting it on a commercial website or
redistributing it over the Internet or in any other medium. In all cases copyright must remain intact.
*********************************************************************************************************/
var fmParser = {
mediaCnt: 0,
titleHeight: 25,
parseMain: function(json, contObj) {
if(typeof contObj != 'object') return false;
if(typeof json != 'object') json = eval('(' + json + ')');
if(json.type == 'editor') return this.parseEditor(json, contObj);
var html, id, title, overflow;
var titleWidth = json.width ? (json.width - 120) + 'px' : '100%';
var height = contObj.offsetHeight - this.titleHeight;
if(typeof json.title != 'undefined' && json.title != '') {
title = json.title;
}
else if(typeof json.search != 'undefined' && json.search != '') {
title = fmMsg[json.lang].searchResult + ': ' + json.search;
}
else if(typeof json.sysType != 'undefined' && json.sysType != '') {
title = '[' + json.sysType + '] ' + json.path;
}
else title = json.path;
var now = new Date();
var d = [];
d[0] = now.getFullYear();
d[1] = now.getMonth() + 1;
if(d[1] < 10) d[1] = '0' + d[1];
d[2] = now.getDate();
if(d[2] < 10) d[2] = '0' + d[2];
html = '
';
}
else html += '
';
}
html += '
';
if(explorer.items[i].level > 1) for(j = 1; j < explorer.items[i].level; j++) {
html += '
';
}
if(explorer.items[i+1] && explorer.items[i+1].level > explorer.items[i].level) {
hash = explorer.items[i].hash;
if(fmContSettings[json.cont].expanded[hash]) {
icon = 'treeClose.gif';
icon2 = 'dir_open.gif';
}
else {
icon = 'treeOpen.gif';
icon2 = 'dir.gif';
}
action = 'fmLib.toggleTreeItem(this)';
style = 'cursor:pointer';
}
else {
icon = 'blank.gif';
icon2 = 'dir.gif';
action = style = '';
}
html += '
';
html += '
';
html += '
' + explorer.items[i].name + '';
html += '
';
if(explorer.items[i+1] && explorer.items[i+1].level < explorer.items[i].level) {
for(j = 0; j < explorer.items[i].level - explorer.items[i+1].level; j++) {
html += '
';
}
}
}
return html;
},
parseEditor: function(json, contObj) {
if(typeof json != 'object') return false;
if(typeof contObj != 'object') return false;
var html;
var url = fmWebPath + '/action.php?fmContainer=' + json.cont;
var width = contObj.offsetWidth;
var height = contObj.offsetHeight - this.titleHeight;
var content = fmTools.b64decode(json.text.content);
html = '
\n';
contObj.innerHTML = html;
return true;
},
parseTextViewer: function(json, contObj) {
if(typeof contObj != 'object') return false;
if(typeof json != 'object') json = eval('(' + json + ')');
var html;
var width = fmContSettings[json.cont].docViewerWidth;
var height = fmContSettings[json.cont].docViewerHeight;
var content = fmTools.b64decode(json.text.content);
html = '
' + content + '
\n';
contObj.innerHTML = html;
return true;
},
parseLogin: function(json, height) {
if(typeof json != 'object') return '';
if(!json.login) return '';
var html;
var action = this.parseAction(json.login, json.cont);
html = '
\n';
html += '\n';
html += '\n';
html += ' | \n';
html += '
\n';
return html;
},
parseDebugInfo: function(json, contObj) {
if(typeof contObj != 'object') return false;
if(typeof json != 'object') json = eval('(' + json + ')');
if(!json.debug) return false;
var html;
html = '
DEBUG INFO
\n';
html += '
\n';
html += '
\n';
html += '\n';
html += 'Cookie info: | ' + json.debug.cookie + ' | \n';
html += '
\n';
html += 'PHP version: | ' + json.debug.phpVersion + ' | \n';
html += '
\n';
html += 'Perl version: | ' + json.debug.perlVersion + ' | \n';
html += '
\n';
html += 'Memory limit: | ' + json.debug.memoryLimit + ' | \n';
html += '
\n';
if(json.debug.memoryUsage) {
html += 'Memory usage: | ' + json.debug.memoryUsage + ' | \n';
html += '
\n';
}
html += 'FileManager::$language: | ' + json.debug.lang + ' | \n';
html += '
\n';
html += 'FileManager::$locale: | ' + json.debug.locale + ' | \n';
html += '
\n';
html += 'FileManager::$encoding: | ' + json.debug.encoding + ' | \n';
html += '
\n';
html += 'FileManager::$uploadEngine: | ' + json.debug.uploadEngine + ' | \n';
html += '
\n';
html += 'FileManager::$perlEnabled: | ' + json.debug.perlEnabled + ' | \n';
html += '
\n';
html += 'FileManager::$fmWebPath: | ' + json.debug.webPath + ' | \n';
html += '
\n';
html += 'FileManager::$startDir: | ' + json.debug.startDir + ' | \n';
html += '
\n';
html += 'FileManager::$maxImageWidth: | ' + json.debug.maxImageWidth + ' | \n';
html += '
\n';
html += 'FileManager::$maxImageHeight: | ' + json.debug.maxImageHeight + ' | \n';
html += '
\n';
html += 'Listing::$curDir: | ' + json.debug.curDir + ' | \n';
html += '
\n';
html += 'Listing::$searchString: | ' + json.debug.search + ' | \n';
html += '
\n';
html += 'Cache directory: | ' + json.debug.cache + ' files | \n';
html += '
\n';
html += "
\n";
contObj.innerHTML = html;
return true;
},
parseLogMessages: function(json, contObj) {
if(typeof contObj != 'object') return false;
if(typeof json != 'object') json = eval('(' + json + ')');
if(!json.messages) return false;
var cssLog, i, msg;
var html = '';
for(i = 0; i < json.messages.length; i++) {
msg = json.messages[i];
cssLog = 'fmLog' + msg.type.substr(0, 1).toUpperCase() + msg.type.substr(1, msg.type.length);
html += '
';
html += '' + msg.time + ' | ';
html += '' + msg.text + ' | ';
html += '
\n';
}
contObj.innerHTML += html;
contObj.scrollTop = contObj.scrollHeight;
fmTools.touchScroll(contObj);
return true;
},
parseTitleIcons: function(json) {
if(typeof json != 'object') return '';
if(!json.icons) return '';
var html = action = tooltip = icon = '';
if(json.type == 'list') {
var url = fmWebPath + '/action.php?fmContainer=' + json.cont;
action = "fmLib.call('" + url + "&fmMode=refresh')";
tooltip = fmMsg[json.lang].cmdRefresh;
html += '
';
html += '\n';
html += ' | \n';
if(fmContSettings[json.cont].listType == 'details') {
icon = 'list_icons.gif'
tooltip = fmMsg[json.lang].cmdIcons;
}
else {
icon = 'list_details.gif'
tooltip = fmMsg[json.lang].cmdDetails;
}
action = "fmLib.toggleListView('" + json.cont + "')";
html += '
';
html += '\n';
html += ' | \n';
}
for(i in json.icons) {
action = this.parseAction(json.icons[i], json.cont, json.icons[i].id);
tooltip = (typeof json.icons[i].caption == 'string') ? json.icons[i].caption : '';
html += '
';
html += '\n';
html += ' | \n';
}
html += '
| ';
return html;
},
parseAction: function(json, curCont, id) {
if(typeof json != 'object') return '';
var url = fmWebPath + '/action.php?fmContainer=' + curCont;
var i, params;
var action = name = '';
if(json.call) {
action = "fmLib.call('" + url + '&fmMode=' + json.call;
if(id) action += '&fmObject=' + id;
action += "')";
}
else if(json.submit) {
action = "fmLib.call('" + url + "', '" + json.submit + "')";
}
else if(json.exec) {
for(i = 1, params = []; i < json.exec.length; i++) {
if(typeof json.exec[i] == 'object') {
params.push(json.exec[i]);
}
else params.push("'" + json.exec[i].replace(/\'/g, "\\'") + "'");
}
action = json.exec[0] + '(' + params.join(',') + ')';
}
else if(json.dialog) {
if(json.dialog == 'fmError') {
for(i in json.caption) json.caption[i] = json.caption[i].replace(/\'/g, "\\'");
action = "fmLib.openDialog('', 'fmError', ['" + json.caption[0] + "', '" + json.caption[1] + "'])";
}
else {
if(json.dialog == 'fmMediaPlayer') url += '&fmMode=loadFile&fmObject=' + id;
caption = [json.caption + (id ? ': ' + fmEntries[curCont][id].name : '')];
if(json.confirm) caption.push(json.confirm);
if(json.text) for(i = 0; i < json.text.length; i++) {
caption.push(json.text[i]);
}
if(typeof json.content != 'undefined') name = json.content;
else if(id) name = fmEntries[curCont][id].name.replace(/\'/g, "\\'");
for(i in caption) caption[i] = caption[i].replace(/\'/g, "\\'");
action = "fmLib.openDialog('" + url + "', '" + json.dialog + "', ['" + caption.join("','") + "'], '";
action += id + "', '" + name + "'";
if(json.dialog == 'fmPerm') action += ", '" + fmEntries[curCont][id].permissions + "'";
action += ')';
}
}
return action;
},
parseMenu: function(items, curCont, id) {
var i, css, width, icon, action;
var html = '
';
for(i = 0; i < items.length; i++) {
if(items[i].caption == 'separator') {
if(items[i+1]) {
html += '' +
' | ' +
'
';
}
}
else {
css = (items[i].call || items[i].exec || items[i].dialog) ? 'fmContent' : 'fmContentDisabled';
width = items[i].width ? items[i].width : 10;
icon = cdnpath + '/icn/' + items[i].icon;
action = this.parseAction(items[i], curCont, id);
html += '' +
'' +
' | ' +
'' + items[i].caption + ' | ' +
'
';
}
}
html += '
';
return html;
},
_checkAction: function(item, json) {
var url = fmWebPath + '/action.php?fmContainer=' + json.cont;
var menu = "fmLib.viewMenu('" + item.id + "', '" + json.cont + "')";
if(item.deleted) return menu;
if(item.icon.substr(0, 4) == 'cdup') {
var mode = (json.search != '') ? 'search' : 'parent';
return "fmLib.call('" + url + '&fmMode=' + mode + "')";
}
if(fmLib.useRightClickMenu[json.cont]) {
var lang = fmContSettings[json.cont].language;
var userPerms = fmContSettings[json.cont].userPerms;
var action = menu;
if(item.icon.match(/^dir/i)) {
action = this.parseAction({call:'open'}, json.cont, item.id);
}
else if(userPerms.docViewer && item.docType > 0) {
switch(item.docType) {
case 1:
action = this.parseAction({caption:fmMsg[lang].cmdView,dialog:'fmTextViewer'}, json.cont, item.id);
break;
case 2:
if(fmContSettings[json.cont].publicUrl != '') {
action = this.parseAction({caption:fmMsg[lang].cmdView,dialog:'fmDocViewer'}, json.cont, item.id);
}
break;
}
}
else if(userPerms.imgViewer && item.name.match(/\.(jpe?g|png|gif)$/i)) {
action = this.parseAction({caption:fmMsg[lang].cmdView,dialog:'fmImgViewer'}, json.cont, item.id);
}
else if(userPerms.mediaPlayer && item.name.match(/\.(swf|flv|mp4)$/i)) {
action = this.parseAction({caption:fmMsg[lang].cmdView,dialog:'fmMediaPlayer'}, json.cont, item.id);
}
else if(userPerms.mediaPlayer && item.name.match(/\.(mp3|m4a|aac|wav|og[ga])$/i)) {
var btn = json.cont + '_btn_' + item.id;
action = "fmLib.playSound(document.getElementById('" + btn + "'), '" + json.cont + "', '" + item.id + "')";
}
return 'if(event.button == 2) { ' + menu + '; } else { ' + action + '; }';
}
return "(event.button == 2) ? '' : " + menu;
}
}