var xcomSites; var xcomHeaders; var xcom_action_url; var xcom_srch_str; function xcom_localSave(a_id) { var fn_sel = document.getElementById('xcom_sel'); /* if function selected, apply function to remote file */ if(fn_sel.selectedIndex > 0) { xcom_setValue('xcom_pageid',a_id); xmlrpc('xcom_action'); return; } /* save remote file to local * first ask if this is what is wanted */ if(a_id) { xcom_setValue('xcom_pageid',a_id); if(!window.confirm(JSINFO['savelocalfile'] + ' ' + a_id)) return; } var params = ""; var id =a_id ? a_id : xcom_getInputValue('xcom_pageid'); var params = 'id='+id; var jobj = xcom_json_ini('xcom_localpwd','xcom_locuser'); jobj['url'] = JSINFO['url']; var str =JSON.stringify(jobj); params +='&local=' + str; var jobj = xcom_json_ini('xcom_pwd','xcom_url','xcom_user'); str =JSON.stringify(jobj); params +='&remote=' + str; //if(!confirm("params: " + params)) return; var status =new Array("Save remote: ("+ id + ") to Local wiki"); xcom_query_status(status); jQuery.ajax({ url: DOKU_BASE + 'lib/plugins/xcom/scripts/xcom_save.php', data: params, type: 'POST', dataType: 'html', success: function(data) { data = decodeURIComponent(data); xcom_show('xcom_results'); xcom_print_data('dokuwiki.copy', data, false,""); } }); } function xmlrpc() { var xcom_action = arguments.length ? 'xcom_action' : ""; xcom_hide_all_views(xcom_action); /* xcom_hide('xcom_action'); xcom_hide('xcom_view'); xcom_hide('xcom_pre_title'); xcom_hide('xcom_htm_title'); xcom_hide('xcom_editable_title'); xcom_hide('xcom_action_title');*/ xcom_action_url = xcom_getInputValue('xcom_url'); xcom_action_url = xcom_action_url.replace(/[\/\\]$/,""); xcom_action_url += '/doku.php?'; xcom_clear('xcom_qstatus',false); var options = xcom_params(); var func = options[0]; xcom_query_status(options); var other=false; var params = 'params=' + JSON.stringify(options); params = params.replace(/\s*__comma__\s*/g,','); if(typeof options[2] == 'object' && options[2] !== null ) { try { if(options[2].hasOwnProperty('hash')) { other = 'hash'; } } catch(e) { } } var array_types = {'dokuwiki.getPagelist':1,'plugin.xcom.pageVersions':1,'plugin.xcom.getPageInfo':1,'wiki.getAllPages':1, 'wiki.getAttachmentInfo':1,'wiki.getAttachments':1, 'wiki.getRecentChanges':1,'wiki.listLinks':1,'dokuwiki.search':1,'plugin.xcom.getMedia':1, 'plugin.xcom.listNamespaces':1,'wiki.getBackLinks':1,}; var jobj = xcom_json_ini('xcom_pwd','xcom_url','xcom_user'); str =JSON.stringify(jobj); params += '&credentials=' + str; params += '&debug=' + document.getElementById('xcom_debug').checked; // if(!confirm(params)) return; jQuery.ajax({ url: DOKU_BASE + 'lib/plugins/xcom/scripts/xml.php', data: params, type: 'POST', dataType: 'html', success: function(data) { if(data.match(/XCOM_LAG/)) return; if(!array_types.hasOwnProperty(func)) { try { data = decodeURIComponent(data); } catch(err){ console.log("By-passed decoding string returned by " + func + ': ' + err.message ); } } xcom_show('xcom_results'); xcom_print_data(func, data,other,xcom_action); } }); var fn_sel = document.getElementById('xcom_sel'); fn_sel.selectedIndex = 0; return false; } function xcom_print_data(fn, data,other,xcom_action) { var id = 'xcom_pre'; var table_calls = { 'dokuwiki_getPagelist': (other=='hash') ? ['id','rev', 'mtime' ,'size','hash'] : ['id','rev', 'mtime' ,'size'] , 'plugin_xcom_pageVersions': ['user','ip','type','sum','modified','version' ], 'plugin_xcom_getPageInfo': ['name','lastModified','author','version'], 'wiki_getAllPages': ['id', 'perms', 'size', 'lastModified'], 'dokuwiki_search': ['id', 'score', 'rev', 'mtime','size','snippet'], 'plugin_xcom_getMedia': ['Media files'], 'wiki_getAttachments': ['id','size','lastModified'], 'wiki_listLinks': ['type', 'page','href'], 'wiki_getAttachmentInfo': ['id','lastModified','size'], 'plugin_xcom_listNamespaces': ['Namespace Directories'], 'wiki_getBackLinks': ['Backlinks'], 'wiki_getRecentChanges': ['name', 'lastModified', 'author','version','size'], 'wiki_getBackLinks' : ['Backlinks'], }; xcomHeaders = table_calls; switch(fn) { case 'wiki.getPage': // (string) raw Wiki text case 'wiki.getPageVersion': // (string) raw Wiki text id = 'xcom_editable' ; break; case 'plugin.xcom.GetMetaData': case 'wiki.getPageHTML': // (string) rendered HTML id = 'xcom_htm'; break; case 'dokuwiki.getPagelist': case 'plugin.xcom.pageVersions': case 'plugin.xcom.getPageInfo': case 'wiki.getAllPages': case 'dokuwiki.search': case 'plugin.xcom.getMedia': case 'wiki.getAttachments': case 'wiki.listLinks': case 'wiki.getAttachmentInfo': case 'plugin.xcom.listNamespaces': case 'wiki.getRecentChanges': case 'wiki.getBackLinks': id = xcom_action ? 'xcom_action':'xcom_htm'; try { var obj = jQuery.parseJSON(data); } catch(e) { id = 'xcom_pre'; // not a table, use code view, probably error msg obj = decodeURIComponent(data); break; } // handle tables if(obj || fn == 'wiki.getBackLinks') { var fncall = fn.replace(/\./g,'_'); data = xcom_thead(table_calls[fncall]); if(fn == 'plugin.xcom.getPageInfo' || fn == 'wiki.getAttachmentInfo') { data += xcom_hash(obj); //straight single hash } else if (fn == 'plugin.xcom.getMedia' || fn =='plugin.xcom.listNamespaces' || fn == 'wiki.getBackLinks') { data += xcom_onedim(obj); } else { data+=xcom_multidim(obj,fn); // array of arrays } } data += xcom_tclose(); //end tables break; case 'wiki.putPage': case 'dokuwiki.appendPage': id = 'xcom_editable'; break; default: break; } // end switch var d = document.getElementById(id); if(id == 'xcom_editable') { xcom_setValue(id,data); } else { d.innerHTML= data; } xcom_show(id); var title = id + '_title'; xcom_show(title); } function xcom_multidim(obj,func) { var data = ""; for(var i in obj) { data +="\n"; for(var j in obj[i]) { var r = obj[i][j]; if(j == 'lastModified' && func == 'wiki.getRecentChanges' || j == 'modified' && func == 'plugin.xcom.pageVersions') { r = obj[i]['version']; var date_time = new Date(r * 1000); var month = (date_time.getMonth() + 1) > 9 ? (date_time.getMonth() + 1) : '0' + (date_time.getMonth() + 1); var day = date_time.getDate() > 9 ? date_time.getDate() : '0'+ date_time.getDate(); r = date_time.getFullYear() + "-" + month + "-" + day + " " + date_time.getHours() + ":" + date_time.getMinutes() + ":" + date_time.getSeconds() } row = xcom_td(j,r,func); //type, value, function if(row) data += row; } } return data; } function xcom_hash(obj) { var data ="\n"; for(var i in obj) { data += xcom_td(i,obj[i]); } return data; } function xcom_onedim(obj) { var data ="\n"; for(var i in obj) { data += xcom_td(i,obj[i]) + "\n"; } return data; } function xcom_thead(args) { var row = "\n"; for (i=0; i'; } return row + "\n"; } function xcom_td(type,val,fn) { if(fn) { var is_header = false; var fncall = fn.replace(/\./g,'_'); var headers = xcomHeaders[fncall]; for(var i = 0; i< headers.length; i++) { if(type == headers[i]) { is_header=true; break; } } if(!is_header) return; } //alert(type + '=' + val); if(type == 'modified' || type == 'lastModified' && typeof val == 'object') { // var min =val['minute'] ? val['minute'] : val['minute']; if (typeof val !== 'undefined' && val['year']) { var d = new Date( val['year'],val['month']-1,val['day'],val['hour'],val['minute'], val['second']); val = d.toUTCString(); } } else if(type == 'rev' || type == 'mtime') { var d = new Date(val*1000); val = d.toUTCString(); } else if(type == 'size') { val += ' bytes'; } else if(type == 'id' && fn=='dokuwiki.search') { return ''; } else if(type == 'id' || type == 'href' || (type =='page' && fn == 'wiki.listLinks')) { var display = val; if(val.length > 40) { var a = val.substring(0,40) + ". . . .
"; var b = val.substring(40); if(b.length > 7) { display = a + '    ' + b; } } if(type == 'id') { return ''; } val =display; } else if(type == 'snippet') { return ''; } else if(type == 'title' && fn=='dokuwiki.search') return ""; //skip title, screws up the table design if(typeof val == 'object') val = "none"; return '' } function xcom_tclose() { return "
'+ xcom_search_url(val) +'' +display +'
 ' + val + '' + val + '
\n"; } function xcom_search_url(pageid) { if ( typeof xcom_srch_str == 'undefined' ) { xcom_srch_str =xcom_getInputValue('xcom_opts'); } var qs = '&'+ xcom_srch_opts(); return '' + pageid + ''; } function xcom_srch_opts() { // for search function var srch_str =xcom_getInputValue('xcom_opts'); srch_str = srch_str.replace(/^\s+/,""); srch_str = srch_str.replace(/\s+$/,""); srch_str = srch_str.replace(/\s+\"/,'\"'); srch_str = srch_str.replace(/\"\s+/,'\"'); var tmp = srch_str.split('\"'); if(tmp.length == 1) { tmp = srch_str.split(/\s+/g); } var result = ""; for(i=0; i:pagename]] , (int) offset break; case 'wiki.getAttachments': (String) namespace, (array) options (#pattern#) break; case 'plugin.acl.addAcl': (String) scope, (String) user|@group break; case 'plugin.acl.delAcl':String) scope, (String) user|@group, (int) permission break; case 'plugin.xcom.listNamespaces':(String) namespace id, (Array) (id1;id2. . .) break; */ default: } return true; } function xcom_params() { var params = new Array(),i=0; var optstring = xcom_getInputValue('xcom_opts'); //Params from User-created Query/Options box var opts = ""; var matches; optstring = optstring.replace(/\s+$/,""); optstring = optstring.replace(/^\s+/,""); optstring = optstring.replace(/;\s+/,";"); optstring = optstring.replace(/\((.*?)\)/g,function(a) { return a.replace(/,/g,' __comma__ '); }); optstring = optstring.replace(/\#(.*?)\#/g,function(a) { return a.replace(/,/g,'__comma__'); }); if(optstring) opts = optstring.split(/,/); for(var p=0; p 0) { params[i] = fn_sel.options[fn_sel.selectedIndex].value; } else { var regex = RegExp('(wiki|plugin|dokuwiki|xcom)\.'); if(!optstring.match(regex)) { xcom_err_msg('nofunc'); return false; } else { // alert(optstring); } return params[i] = opts; } var tmpar = new Array(); var page = document.getElementById('xcom_pageid').value; var opstatus = xcom_check_opts(params[i],page,optstring,tmpar); if(tmpar.length > 0) { opts = new Array(); opts.push(tmpar[0]); } if(!opstatus) return false; if(page) { if(params[0] == 'dokuwiki.search') { // add page to search query opts[0] = opts[0] + " " + page; } else params[++i] = page; } else { if(params[0]=='plugin.xcom.listNamespaces') { params[++i] = '0'; } } if(params[0]=='wiki.putPage' || params[0]=='dokuwiki.appendPage') { params[++i] = xcom_escape(xcom_getInputValue('xcom_editable')); } //assign options to parameter array if(opts.length) { for(j=0;j 70) { q = q.substring(0,70) + '. . .'; } document.getElementById('xcom_qstatus').innerHTML = q; } function xcom_select(sel) { var which =sel.options[sel.selectedIndex].value; if(!which) return; xcom_setValue('xcom_url',xcomSites[which]['url']); xcom_setValue('xcom_pwd',xcomSites[which]['pwd']); xcom_setValue('xcom_user',xcomSites[which]['user']); } function xcom_toggle(which) { jQuery(which).toggle(); var state = jQuery(which).css('display'); if(state != 'none') { xcom_show('xcom_results'); } var title = which + '_title'; jQuery(title).toggle(); } function xcom_show(which) { var d = document.getElementById(which); if(d) d.style.display = 'block'; } function xcom_hide(which) { var d = document.getElementById(which); if(d) d.style.display = 'none'; } function xcom_hide_all_views(xcom_action) { xcom_hide('xcom_editable'); xcom_hide('xcom_pre'); if(!xcom_action) { xcom_hide('xcom_htm'); } xcom_hide('xcom_editable_title'); xcom_hide('xcom_pre_title'); xcom_hide('xcom_htm_title'); xcom_hide('xcom_results'); xcom_hide('xcom_action_title'); } function xcom_clear(which) { if(which == 'xcom_editable') { xcom_setValue(which,""); return; } document.getElementById(which).innerHTML= ''; if(arguments.length > 1) return; xcom_hide(which); } /** creates credentials array for Json encoding */ function xcom_json_ini() { jobj = {}; for (i=0; i "; } else msg+=LANG.plugins.xcom[arguments[i]] + " "; } xcom_msg(msg); }