1/* 2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 3 * Copyright (C) 2003-2009 Frederico Caldeira Knabben 4 * 5 * == BEGIN LICENSE == 6 * 7 * Licensed under the terms of any of the following licenses at your 8 * choice: 9 * 10 * - GNU General Public License Version 2 or later (the "GPL") 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14 * http://www.gnu.org/licenses/lgpl.html 15 * 16 * - Mozilla Public License Version 1.1 or later (the "MPL") 17 * http://www.mozilla.org/MPL/MPL-1.1.html 18 * 19 * == END LICENSE == 20 * 21 * Defines the FCKXml object that is used for XML data calls 22 * and XML processing. 23 * 24 * This script is shared by almost all pages that compose the 25 * File Browser frameset. 26 */ 27 28var FCKXml = function() 29{} 30 31FCKXml.prototype.GetHttpRequest = function() 32{ 33 // Gecko / IE7 34 try { return new XMLHttpRequest(); } 35 catch(e) {} 36 37 // IE6 38 try { return new ActiveXObject( 'Msxml2.XMLHTTP' ) ; } 39 catch(e) {} 40 41 // IE5 42 try { return new ActiveXObject( 'Microsoft.XMLHTTP' ) ; } 43 catch(e) {} 44 45 return null ; 46} 47 48FCKXml.prototype.LoadUrl = function( urlToCall, asyncFunctionPointer ) 49{ 50 var oFCKXml = this ; 51 52 var bAsync = ( typeof(asyncFunctionPointer) == 'function' ) ; 53 54 var oXmlHttp = this.GetHttpRequest() ; 55 56 oXmlHttp.open( "GET", urlToCall, bAsync ) ; 57 // For IE 10 58 //See: https://blogs.msdn.com/b/ie/archive/2012/07/19/xmlhttprequest-responsexml-in-ie10-release-preview.aspx?Redirected=true 59 try { oXmlHttp.responseType = 'msxml-document'; } catch(e){} 60 61 this.RespType = oXmlHttp.responseType; 62 63 if ( bAsync ) 64 { 65 oXmlHttp.onreadystatechange = function() 66 { 67 if ( oXmlHttp.readyState == 4 ) 68 { 69 var oXml ; 70 try 71 { 72 // this is the same test for an FF2 bug as in fckxml_gecko.js 73 // but we've moved the responseXML assignment into the try{} 74 // so we don't even have to check the return status codes. 75 var test = oXmlHttp.responseXML.firstChild ; 76 oXml = oXmlHttp.responseXML ; 77 } 78 catch ( e ) 79 { 80 try 81 { 82 oXml = (new DOMParser()).parseFromString( oXmlHttp.responseText, 'text/xml' ) ; 83 } 84 catch ( e ) {} 85 } 86 87 if ( !oXml || !oXml.firstChild || oXml.firstChild.nodeName == 'parsererror' ) 88 { 89 alert( 'The server didn\'t send back a proper XML response. Please contact your system administrator.\n\n' + 90 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')\n\n' + 91 'Requested URL:\n' + urlToCall + '\n\n' + 92 'Response text:\n' + oXmlHttp.responseText ) ; 93 return ; 94 } 95 96 oFCKXml.DOMDocument = oXml ; 97 var id = getimgid(urlToCall); 98 99 if(id){ 100 id = encodeURIComponent(id); 101 asyncFunctionPointer( oFCKXml,id) ; 102 } 103 else asyncFunctionPointer( oFCKXml ) ; 104 } 105 } 106 } 107 108 oXmlHttp.send( null ) ; 109 110 if ( ! bAsync ) 111 { 112 if ( oXmlHttp.status == 200 || oXmlHttp.status == 304 ) { 113 this.DOMDocument = oXmlHttp.responseXML ; 114 } 115 else 116 { 117 alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ; 118 } 119 } 120 121} 122 123FCKXml.prototype.SelectNodes = function( xpath ) 124{ 125 126 if(this.RespType && this.RespType == 'msxml-document' || navigator.userAgent.indexOf('MSIE') >= 0) 127 return this.DOMDocument.selectNodes( xpath ) ; 128 else // Gecko 129 { 130 var aNodeArray = new Array(); 131 132 var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument, 133 this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) ; 134 if ( xPathResult ) 135 { 136 var oNode = xPathResult.iterateNext() ; 137 while( oNode ) 138 { 139 aNodeArray[aNodeArray.length] = oNode ; 140 oNode = xPathResult.iterateNext(); 141 } 142 } 143 return aNodeArray ; 144 } 145} 146 147FCKXml.prototype.SelectSingleNode = function( xpath ) 148{ 149 150 if(this.RespType && this.RespType == 'msxml-document' || navigator.userAgent.indexOf('MSIE') >= 0) { 151 return this.DOMDocument.selectSingleNode( xpath ) ; 152 } 153 else // Gecko 154 { 155 var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument, 156 this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), 9, null); 157 158 if ( xPathResult && xPathResult.singleNodeValue ) 159 return xPathResult.singleNodeValue ; 160 else 161 return null ; 162 } 163} 164function getimgid(url) 165{ 166 urlspl = url.split('?'); 167 var id = ''; 168 var folder,file; 169 var str = urlspl[1]; 170 if (str.match(/Unlink/)) { 171 //alert('str='+str) ; 172 found = str.split(/&/); 173 console.log(found); 174 // alert('ps='+found); 175 176 for(i=0; i<found.length; i++) { 177 178 if(found[i].match(/Folder/)) { 179 var ar = found[i].split(/=/); 180 folder = ar[1]; 181 } 182 183 if(found[i].match(/file/)) { 184 var ar = found[i].split(/=/); 185 file = ar[1]; 186 } 187 } 188 189 if(file) { 190 id = folder + file; 191 console.log(id); 192 } 193 } 194 195 return id; 196} 197 198