1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 2<!-- 3 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 4 * Copyright (C) 2003-2009 Frederico Caldeira Knabben 5 * 6 * == BEGIN LICENSE == 7 * 8 * Licensed under the terms of any of the following licenses at your 9 * choice: 10 * 11 * - GNU General Public License Version 2 or later (the "GPL") 12 * http://www.gnu.org/licenses/gpl.html 13 * 14 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 15 * http://www.gnu.org/licenses/lgpl.html 16 * 17 * - Mozilla Public License Version 1.1 or later (the "MPL") 18 * http://www.mozilla.org/MPL/MPL-1.1.html 19 * 20 * == END LICENSE == 21 * 22 * This page shows all resources available in a folder in the File Browser. 23--> 24<html> 25<head> 26 <title>Resources</title> 27 <link href="browser.css" type="text/css" rel="stylesheet"> 28 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 29 <script type="text/javascript" src="js/common.js"></script> 30 <script type="text/javascript" src="js/language.js"></script> 31 <script type="text/javascript" src="js/safeFN_class.js"></script> 32 <script type="text/javascript"> 33 34var oListManager = new Object() ; 35var currentFolderUploadStatus; 36var DwikiFNencode = parent.DwikiFNencode; 37var isInternalLink = parent.isLocalDwikiBrowser; 38var ImagesAllowed = new RegExp(parent.DwikiImageUploadAllowedExtensions); 39var isDwikiUrlExtern = parent.isDwikiUrlExtern; 40var isDwikiMediaFile = parent.isDwikiMediaFile; 41var FCKImageSaveDir = false; 42var isDwikiImage = parent.isDwikiImage; 43var isInternet_Explorer = false; 44 if(navigator.userAgent.indexOf('MSIE') != -1 || navigator.userAgent.indexOf('Trident') != -1) { 45 isInternet_Explorer = true; 46 } 47 48function getFCKSaveDir() { 49 //alert(dwikiUTF8_decodeFN(document.cookie,DwikiFNencode)); 50 var allcookies = document.cookie; 51 var pos = allcookies.indexOf("FCK_media="); 52 if(pos != -1) { 53 var start = pos+10; 54 var end = allcookies.indexOf(";",start); 55 if(end == -1) end = allcookies.length; 56 var value = allcookies.substring(start,end); 57 value = decodeURIComponent(value); 58 return dwikiUTF8_decodeFN(value,DwikiFNencode); 59 } 60 return false; 61} 62 63window.onbeforeunload = function() { }; 64 65oListManager.Clear = function() 66{ 67 document.body.innerHTML = '' ; 68} 69 70function ProtectPath(path) 71{ 72 path = path.replace( /\\/g, '\\\\') ; 73 path = path.replace( /'/g, '\\\'') ; 74 return path ; 75} 76 77oListManager.GetFolderRowHtml = function( folderName, folderPath, folder_class, isImage ) 78{ 79 80 folderPath = dwikiUTF8_decodeFN(folderPath,DwikiFNencode); 81 var sLink = '<a href="#" onclick="OpenFolder(\'' + ProtectPath( folderPath ) + '\');return false;">' ; 82 icon = 'images/Folder.gif'; 83 84 if(folder_class == 'r') icon = 'images/FolderRO.gif'; 85 var ColSpan = isImage ? 4 : 3; 86 return '<tr>' + 87 '<td width="16">' + 88 sLink + 89 '<img alt="" src="' + icon +'" width="16" height="16" border="0"><\/a>' + 90 '<\/td><td nowrap colspan="' + ColSpan +'"> ' + 91 sLink + 92 folderName + 93 '<\/a>' + 94 '<\/td><\/tr>' ; 95} 96 97 98var imageDirectoryRegex = new RegExp ('^(.*?ckgdoku\\/fckeditor\\/userfiles\\/image\\/)(.*)'); 99var imageDirectoryRegexFarms = new RegExp ('^(.*?ckgdoku\\/fckeditor\\/.*?\\/image\\/)(.*)'); 100function reviseImgSrc(url) { 101 102 var imgUrl =decodeURI(dwikiUTF8_decodeFN(url,DwikiFNencode)); 103 104 var matches = imgUrl.match(imageDirectoryRegex); 105 if(!matches) matches = imgUrl.match(imageDirectoryRegexFarms); 106 if(matches && matches.length > 1) { 107 if(!matches[1].match(/^\//)) matches[1] = '/'+matches[1]; 108 return matches[1]+ encodeURI(dwikiUTF8_encodeFN(matches[2],DwikiFNencode)); 109 } 110 else { 111 var matches = imgUrl.match(/^http:\/\/(.*)/); 112 if(matches) { 113 return 'http://' + encodeURI(dwikiUTF8_encodeFN(matches[1],DwikiFNencode)); 114 } 115 } 116 return url; 117} 118 119function oListImage(fileUrl,width,height) { 120 fileUrl = encodeURI(dwikiUTF8_encodeFN(fileUrl,DwikiFNencode)); 121 this.src = ProtectPath( fileUrl ); 122 123 this.src = reviseImgSrc(this.src); 124 125 126 this.fileUrl = fileUrl; 127 this.width = width; 128 this.height = height; 129} 130 131function GetUrlParam( paramName ) 132{ 133 134 var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ; 135 var oMatch = oRegex.exec( window.top.location.search ) ; 136 137 if ( oMatch && oMatch.length > 1 ) 138 return decodeURIComponent( oMatch[1] ) ; 139 else 140 return '' ; 141} 142 143var imgCount = 0; 144var imageArray = new Array(); 145var KBArray = new Array(); 146var imgProcessingStack = new Array(); 147 148function big_image(id) { 149 var elems = id.split('_'); 150 var oImg = imageArray[elems[1]]; 151 152 153 var height = oImg.height; 154 var width = oImg.width; 155 156 if(elems.length > 1) { 157 if(oImg.width > 500) { 158 height = Math.round( oImg.height * ( 500 / oImg.width ) ) ; 159 width = 500; 160 } 161 if(height > 400) { 162 width = Math.round( width * ( 400 / height ) ) ; 163 height = 400; 164 } 165 } 166 167 var element = '<img border = "0" src = "' + oImg.src + '" width = "' + width + '" height="' + height + '">'; 168 element += '<center><br /><button class="bigwin_close_but" onclick="OpenFile(\''+ ProtectPath(oImg.fileUrl) +'\');void 0;">insert into document<\/button><\/center>'; 169 var big_win = document.getElementById('bigwin_display'); 170 big_win.innerHTML = element; 171 big_win = document.getElementById('big_imagewin'); 172 big_win.style.display = 'block'; 173 big_win.scrollIntoView(); 174 175} 176 177function getImageSize(oImgWidth,oImgHeight) { 178 179 var width = oImgWidth; var height = oImgHeight; 180 181 if(oImgWidth > 120) { 182 height = Math.round( oImgHeight * ( 120 / oImgWidth ) ) ; 183 width = 120; 184 } 185 if(height > 120) { 186 width = Math.round( width * ( 120 / height ) ) ; 187 height = 120; 188 } 189 190 return width + 'x' + height +' '; 191} 192 193function showImage(id) { 194 var elems = id.split('_'); 195 var oImg = imageArray[elems[1]]; 196 if(!oImg) return id; 197 198 var height = oImg.height; 199 var width = oImg.width; 200 201 202 if(oImg.width > 120) { 203 height = Math.round( oImg.height * ( 120 / oImg.width ) ) ; 204 width = 120; 205 } 206 if(height > 120) { 207 width = Math.round( width * ( 120 / height ) ) ; 208 height = 120; 209 } 210 211 var sLink = '<a href="#" onclick="OpenFile(\'' + ProtectPath( oImg.src ) + '\');return false;">' ; 212 var element = sLink + '<img border = "0" src = "' + oImg.src + '" width = "' + width + '" height="' + height + '"></a>'; 213 return element; 214 // document.getElementById(id).innerHTML = element; 215 216 217} 218 219var foldersDone = { }; 220oListManager.GetFileRowHtml = function( fileName, fileUrl, fileSize, isImage, fileTime ) 221{ 222 var c_type = "file"; 223 if(isImage) { 224 225 if(imgCount % 2 == 0) { 226 c_type = 'silver'; 227 } 228 else c_type = 'img'; 229 } 230 else if(fileUrl.match(/data\/pages/)) { 231 c_type = 'txt'; 232 } 233 234 fileTime = new Date(Number(fileTime)*1000); 235 fileTime =" " + fileTime.toDateString().replace(/^\w+\s*/,"") + " " + fileTime.toLocaleTimeString(); 236 var Unlink,sUnlink,trash,sLink; 237 238 // Build the link to view the folder. 239 var sLink = '<a href="#" onclick="OpenFile(\'' + ProtectPath( fileUrl ) + '\');return false;">' ; 240 241 var trash = 'images/trash.png'; 242 var sUnlink = '<td width="20" class="' + c_type +'"><a href="#" onclick="UnlinkFile(event,\'' + fileName + '\');return false;">' ; 243 sUnlink += '<img src="' + trash + '" border="0"></a><\/td>'; 244 if(c_type == 'txt') sUnlink = ""; 245 var imgTD = ""; 246 var fileSizeSpan=""; 247 if(isImage) { 248 elems = fileSize.split(';;'); 249 fileSize = elems[0]; 250 251 var oImage = new oListImage(fileUrl, elems[1],elems[2]); 252 oImage.inserted = false; 253 imageArray[imgCount] = oImage; 254 var imgId = 'img_' + imgCount; 255 var imgTD = '<td width="152" align="center" class="' +c_type +'"><div id="' + imgId + '">' 256 + showImage(imgId) + '<\/div>' + 257 '<div class="img_buttons"><a href="#" onclick="big_image(\'' + imgId + '\');return false;">' 258 + translateItem('DlgFileBrowserMagnify', 'magnify') + 259 '<\/a><\/div><\/td>'; 260 fileSizeSpan='<span id="size_'+ imgCount + '">' + elems[1] + 'x' + elems[2] + ' </span>'; 261 imgCount++; 262 263 264 } 265 266 if(currentFolderUploadStatus != 'd') sUnlink = ' '; 267 // Get the file icon. 268 var sIcon = oIcons.GetIcon( fileName ) ; 269 270 271 return '<tr>' + sUnlink + 272 '<td width="16" class="' + c_type + '">' + 273 sLink + 274 '<img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"><\/a>' + 275 '<\/td><td class="' + c_type + '"> ' + 276 sLink + 277 fileName + 278 '<\/a>' + 279 '<\/td>' + imgTD + 280 '<\/td>' + '<td align="right" class="' + c_type + '"nowrap> ' + fileSizeSpan + 281 fileSize + 282 ' KB' + fileTime + 283 '<\/td><\/tr>' ; 284} 285 286function OpenFolder( folderPath ) 287{ 288 289 // Load the resources list for this folder. 290 window.parent.frames['frmFolders'].LoadFolders( dwikiUTF8_encodeFN(folderPath,DwikiFNencode) ) ; 291} 292 293function UnlinkFile(evt,f) { 294var evt = (evt) ? evt : ((window.event) ? event : null); 295 296 if(evt && (evt.ctrlKey||evt.metaKey)) { 297 move_to = window.prompt('Subdirectory of current directory to which you want to move ' + f, "secure"); 298 if(move_to) { 299 move_to = move_to.replace(/^[\/\s]+/,""); 300 move_to = move_to.replace(/[\/\s]+$/,""); 301 if(move_to.match(/[\/\\]/)) { 302 alert(translateItem('FolderMoveWarning','You can only move files to a folder one level below the current directory')); 303 return false; 304 } 305 move_to = move_to.toLowerCase(move_to); 306 move_to = move_to.replace(/\s/g, '_'); 307 move_to = encodeURI(dwikiUTF8_encodeFN(move_to,DwikiFNencode)); 308 f = move_to + '/' +f; 309 } 310 else return false; 311 } 312 else { 313 if(!confirm("Delete " + f + "?")) return false; 314 } 315 316 var id = oConnector.CurrentFolder + ':' + f; 317 id = id.replace(/\//g,':'); 318 id = id.replace('::',':'); 319 parent.opener.ckged_get_unlink_size(id); 320 setTimeout(oConnector.SendCommand( 'UnlinkFile', 'file=' + f, UnlinkFileCallBack ), 7000) ; 321 setTimeout(LoadResources(oConnector.ResourceType, oConnector.CurrentFolder),9000); 322 323} 324 325 326function OpenFile( fileUrl ) 327{ 328 if(DwikiFNencode != 'safe') { 329 fileUrl = dwikiUTF8_decodeFN(fileUrl,DwikiFNencode); 330 fileUrl = decodeURI( fileUrl ); 331 } 332 funcNum = GetUrlParam('CKEditorFuncNum') ; 333 try { 334 335 if(isInternalLink) { 336 fileUrl=decodeURI( fileUrl ).replace( '#', '%23' ) ; 337 } 338 if(isDwikiUrlExtern) { 339 fileUrl = window.location.protocol +'//' + window.location.host + '/' + decodeURI( fileUrl ).replace( '#', '%23' ) ; 340 } 341 if(isDwikiImage) { 342 if(DwikiFNencode == 'url') fileUrl=encodeURI(encodeURI(fileUrl)); 343 if(window.top.opener.JSINFO['ckg_canonical'] ) { 344 fileUrl = window.location.protocol +'//' + window.location.host + fileUrl; 345 } 346 } 347 window.top.opener.CKEDITOR.tools.callFunction( funcNum, fileUrl); 348 if(isInternalLink) { 349 window.top.opener.update_ckgdokuInternalLink(fileUrl.replace(/^.*?\/data\/pages\//,"")); 350 } 351 else if(isDwikiMediaFile) { 352 var url; 353 if(url = fileUrl.match(/userfiles\/(file|image)\/(.*?)$/)) { 354 fileUrl = url[2]; 355 if(!fileUrl.match(/^\//)) fileUrl = '/' + fileUrl; 356 } 357 else if(url = fileUrl.match(/data\/media\/(.*?)$/)) { // needs tobe updated for non-standard and Windows save dirs 358 fileUrl = url[1]; 359 if(!fileUrl.match(/^\//)) fileUrl = '/' + fileUrl; 360 } 361 else { 362 var cookie = ckgEedit_getCookie('FCK_animal') ; 363 if(cookie) { 364 var match = fileUrl.match(cookie+'\/file/(.*)'); 365 if(match) fileUrl = match[1]; 366 } 367 } 368 window.top.opener.update_ckgdokuMediaLink(fileUrl); 369 parent.opener.oDokuWiki_FCKEditorInstance.isLocalDwikiBrowser=false; 370 } 371 372 } 373 catch(e) { 374 } 375 window.top.close() ; 376 window.top.opener.focus() ; 377} 378function sortFileList(type) { 379 oListManager.Clear(); 380 oConnector.SortType = type; 381 oConnector.SendCommand( 'GetFoldersAndFiles', null, GetFoldersAndFilesCallBack ) ; 382} 383 384function findFiles(search){ 385 oConnector.Search = new RegExp(search); 386 sortFileList('search'); 387} 388 389function reverseListOrder(bool){ 390 oConnector.reverseOrder = bool; 391 if(oConnector.SortType && (oConnector.SortType == 'mtime' || oConnector.SortType=='fsize')) { 392 oConnector.SendCommand( 'GetFoldersAndFiles', null, GetFoldersAndFilesCallBack ) ; 393 } 394} 395 396function LoadResources( resourceType, folderPath ) 397{ 398 399 oListManager.Clear(); 400 document.body.innerHTML = translateItem('DlgFileBrowserWaitingMsg', 'Loading, please wait.'); //Show waiting message 401 oConnector.ResourceType = resourceType ; 402 oConnector.CurrentFolder = folderPath ? folderPath : '/'; 403 parent.opener.window.setTimeout( oConnector.SendCommand( 'GetFoldersAndFiles', null, GetFoldersAndFilesCallBack ), 9000) ; 404 405} 406 407function Refresh() 408{ 409 LoadResources( oConnector.ResourceType, oConnector.CurrentFolder ) ; 410} 411 412function GetFoldersAndFilesCallBack( fckXml ) 413{ 414 imgCount = 0; 415 imageArray = new Array(); 416 KBArray = new Array(); 417 imgProcessingStack = new Array(); 418 oListManager.Clear();//Clear waiting message 419 420 if ( oConnector.CheckError( fckXml ) != 0 ) 421 return ; 422 423 // Get the current folder path. 424 var oFolderNode = fckXml.SelectSingleNode( 'Connector/CurrentFolder' ) ; 425 if ( oFolderNode == null ) 426 { 427 428 alert(translateItem('FileBrowserError_XML', 'The server didn\'t reply with a proper XML data. Please check your configuration.')); 429 return ; 430 } 431 var sCurrentFolderPath = oFolderNode.attributes.getNamedItem('path').value ; 432 433 var sCurrentFolderUrl = oFolderNode.attributes.getNamedItem('url').value ; 434 435 var oHtml = new StringBuilder( '<table id="tableFiles" cellspacing="0" cellpadding="1" width="100%" border="0">' ) ; 436 437 // Add the Folders. 438 var isImage = oConnector.ResourceType == 'Image' ? true : false; 439 var oNodes ; 440 oNodes = fckXml.SelectNodes( 'Connector/Folders/Folder' ) ; 441 for ( var i = 0 ; i < oNodes.length ; i++ ) 442 { 443 444 var sFolderName = dwikiUTF8_decodeFN(oNodes[i].attributes.getNamedItem('name').value,DwikiFNencode); 445 var folder_class = oNodes[i].attributes.getNamedItem('class').value ; 446 if(sFolderName.match(/__AAAAAAAA__.AAA/)) { 447 currentFolderUploadStatus = folder_class; 448 continue; 449 } 450 oHtml.Append( oListManager.GetFolderRowHtml( sFolderName, sCurrentFolderPath + sFolderName + "/", folder_class, isImage ) ) ; 451 } 452 453 // Add the Files. 454 oNodes = fckXml.SelectNodes( 'Connector/Files/File' ) ; 455 if(oConnector.SortType == 'mtime') { 456 oNodes.sort(function(a, b) { 457 var a_tm = Number(a.attributes.getNamedItem('time').value); 458 var b_tm = Number(b.attributes.getNamedItem('time').value); 459 if(oConnector.reverseOrder) { 460 return b_tm - a_tm; 461 } 462 return a_tm - b_tm; 463 }); 464 } 465 else if(oConnector.SortType == 'fsize') { 466 oNodes.sort(function(a, b) { 467 var a_tm = parseInt(a.attributes.getNamedItem('size').value); 468 var b_tm = parseInt(b.attributes.getNamedItem('size').value); 469 if(oConnector.reverseOrder) { 470 return b_tm - a_tm; 471 } 472 return a_tm - b_tm; 473 }); 474 } 475 for ( var j = 0 ; j < oNodes.length ; j++ ) 476 { 477 var oNode = oNodes[j] ; 478 var sFileName = dwikiUTF8_decodeFN(oNode.attributes.getNamedItem('name').value,DwikiFNencode); 479 if(oConnector.SortType == 'search' && !sFileName.match(oConnector.Search)) continue; 480 var sFileSize = oNode.attributes.getNamedItem('size').value ; 481 var sFileTime = oNode.attributes.getNamedItem('time').value; 482 483 if(isInternalLink) { 484 if(!sFileName.match(/\.txt$/)) continue; 485 sFileName = sFileName.replace(/\.txt$/,""); 486 } 487 else if(isImage) { 488 if(!sFileName.match(ImagesAllowed)) { 489 continue; 490 } 491 } 492 493 494 // Get the optional "url" attribute. If not available, build the url. 495 var oFileUrlAtt = oNodes[j].attributes.getNamedItem('url') ; 496 var sFileUrl = oFileUrlAtt != null ? oFileUrlAtt.value : sCurrentFolderUrl + sFileName ; 497 498 if(isImage && FCKImageSaveDir) { 499 sFileUrl=sFileUrl.replace(/^.*?\/image\//,""); 500 sFileUrl = FCKImageSaveDir + sFileUrl; 501 } 502 503 if(isImage) { 504 sFileUrl = dwikiUTF8_encodeFN(sFileUrl,DwikiFNencode); 505 } 506 oHtml.Append( oListManager.GetFileRowHtml( sFileName, sFileUrl, sFileSize, isImage, sFileTime) ) ; 507 } 508 509 oHtml.Append( '<\/table>' ) ; 510 var big = '<center><div id="big_imagewin"><div id="bigwin_display"></div>' + 511 '<div id="big_iwin_close"><button onclick="close_bigImgwin();" class="bigwin_close_but">close</button> </div></div></center>'; 512 document.body.innerHTML = big + oHtml.ToString() ; 513 oConnector.Search = new RegExp(""); 514 515} 516 517 518function insertImages() { 519 520 for(var i = 0; i<imageArray.length; i++) { 521 var imgId = 'img_' + i; 522 showImage(imgId); 523 } 524 525} 526 527function postMessageHandler( event ) { 528/* 529 console.log("We've got a message!"); 530 console.log("* Message:", event.data); 531 console.log("* Origin:", event.origin); 532 console.log("* Source:", event.source); 533 */ 534 Refresh(); 535} 536 537if (window.addEventListener) { 538 window.addEventListener("message", postMessageHandler, false); 539 } else { 540 window.attachEvent("onmessage", postMessageHandler); 541} 542function UnlinkFileCallBack( fckXml, id ) 543{ 544 if(id) { 545 parent.opener.ckged_setmedia(id,true,this); 546 } 547 GetFoldersAndFilesCallBack( fckXml ); 548 549} 550 551function close_bigImgwin() { 552 553 document.getElementById('big_imagewin').style.display='none'; 554} 555 556window.onload = function() 557{ 558 window.top.IsLoadedResourcesList = true ; 559 setupLanguage(); 560 FCKImageSaveDir=getFCKSaveDir() ; 561 // alert(FCKImageSaveDir); 562 563} 564 </script> 565</head> 566<body class="FileArea"> 567</body> 568</html> 569