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 +'">&nbsp;' +
91				sLink +
92				folderName +
93				'<\/a>' +
94		'<\/td><\/tr>' ;
95}
96
97
98var imageDirectoryRegex = new RegExp ('^(.*?ckgedit\\/fckeditor\\/userfiles\\/image\\/)(.*)');
99var imageDirectoryRegexFarms = new RegExp ('^(.*?ckgedit\\/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 +'&nbsp;';
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,iLinkTitle )
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 ="&nbsp;&nbsp;&nbsp;&nbsp;" + fileTime.toDateString().replace(/^\w+\s*/,"")  + "&nbsp;" + fileTime.toLocaleTimeString();
236   var Unlink,sUnlink,trash,sLink,sTitle;
237    if(iLinkTitle) {
238     sTitle = ';;' + iLinkTitle;
239     fileUrl += sTitle;
240    }
241	// Build the link to view the folder.
242	var sLink = '<a href="#" onclick="OpenFile(\'' + ProtectPath( fileUrl ) + '\');return false;">' ;
243
244    var trash = 'images/trash.png';
245    var sUnlink = '<td width="20" class="' + c_type +'"><a href="#" onclick="UnlinkFile(event,\'' + fileName + '\');return false;">' ;
246            sUnlink += '<img src="' + trash  + '" border="0"></a><\/td>';
247    if(c_type == 'txt'){
248        sUnlink = ""; //ilink title here
249    }
250    var imgTD = "";
251    var fileSizeSpan="";
252    if(isImage) {
253         elems = fileSize.split(';;');
254         fileSize = elems[0];
255
256        var oImage = new oListImage(fileUrl, elems[1],elems[2]);
257        oImage.inserted = false;
258        imageArray[imgCount] = oImage;
259        var imgId = 'img_' + imgCount;
260        var imgTD = '<td width="152" align="center" class="' +c_type +'"><div id="' +	imgId +  '">'
261         +  showImage(imgId) + '<\/div>' +
262        '<div class="img_buttons"><a href="#" onclick="big_image(\'' + imgId + '\');return false;">'
263         + translateItem('DlgFileBrowserMagnify', 'magnify') +
264        '<\/a><\/div><\/td>';
265         fileSizeSpan='<span id="size_'+ imgCount + '">' + elems[1] + 'x' + elems[2] + '&nbsp;</span>';
266         imgCount++;
267
268
269    }
270
271    if(currentFolderUploadStatus != 'd') sUnlink = '&nbsp;';
272	// Get the file icon.
273	var sIcon = oIcons.GetIcon( fileName ) ;
274   	return '<tr>' + sUnlink +
275			 '<td width="16" class="' + c_type + '">' +
276				sLink +
277				'<img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"><\/a>' +
278			'<\/td><td class="' + c_type +  '">&nbsp;' +
279				sLink +
280				fileName +
281				'<\/a>' +
282			 '<\/td>' + imgTD +
283			'<\/td>' + '<td align="right" class="' + c_type + '"nowrap>&nbsp;' + fileSizeSpan +
284				fileSize +
285				' KB'  +   fileTime +
286		'<\/td><\/tr>' ;
287}
288
289function OpenFolder( folderPath )
290{
291
292	// Load the resources list for this folder.
293	window.parent.frames['frmFolders'].LoadFolders( dwikiUTF8_encodeFN(folderPath,DwikiFNencode) ) ;
294}
295
296function UnlinkFile(evt,f) {
297var evt = (evt) ? evt : ((window.event) ? event : null);
298
299    if(evt && (evt.ctrlKey||evt.metaKey)) {
300        move_to = window.prompt('Subdirectory of current directory to which you want to move ' + f, "secure");
301        if(move_to) {
302            move_to = move_to.replace(/^[\/\s]+/,"");
303            move_to = move_to.replace(/[\/\s]+$/,"");
304            if(move_to.match(/[\/\\]/)) {
305              alert(translateItem('FolderMoveWarning','You can only move files to a folder one level below the current directory'));
306              return false;
307            }
308            move_to = move_to.toLowerCase(move_to);
309            move_to = move_to.replace(/\s/g, '_');
310            move_to = encodeURI(dwikiUTF8_encodeFN(move_to,DwikiFNencode));
311            f = move_to + '/' +f;
312        }
313        else return false;
314    }
315    else {
316       if(!confirm("Delete " + f + "?")) return false;
317    }
318
319    var id = oConnector.CurrentFolder + ':' + f;
320    id = id.replace(/\//g,':');
321    id = id.replace('::',':');
322    parent.opener.ckged_get_unlink_size(id);
323     setTimeout(oConnector.SendCommand( 'UnlinkFile', 'file=' + f, UnlinkFileCallBack ), 7000) ;
324     setTimeout(LoadResources(oConnector.ResourceType, oConnector.CurrentFolder),9000);
325
326}
327
328
329function OpenFile( fileUrl )
330{
331    if(DwikiFNencode != 'safe') {
332    fileUrl = dwikiUTF8_decodeFN(fileUrl,DwikiFNencode);
333    fileUrl =  decodeURI( fileUrl );
334    }
335	funcNum = GetUrlParam('CKEditorFuncNum') ;
336  try {
337
338    if(isInternalLink) {
339       fileUrl=decodeURI( fileUrl ).replace( '#', '%23' ) ;
340    }
341    if(isDwikiUrlExtern) {
342        fileUrl = window.location.protocol +'//' + window.location.host + '/' + decodeURI( fileUrl ).replace( '#', '%23' ) ;
343    }
344    if(isDwikiImage) {
345      if(DwikiFNencode == 'url')  fileUrl=encodeURI(encodeURI(fileUrl));
346        if(window.top.opener.JSINFO['ckg_canonical'] ) {
347            fileUrl = window.location.protocol +'//' + window.location.host + fileUrl;
348        }
349    }
350    window.top.opener.CKEDITOR.tools.callFunction( funcNum, fileUrl);
351    if(isInternalLink) {
352        fileUrl = fileUrl.replace(/^.*?\/pages\//,"")
353        window.top.opener.update_ckgeditInternalLink(fileUrl);
354    }
355    else if(isDwikiMediaFile) {
356       var url;
357       if(url = fileUrl.match(/userfiles\/(file|image)\/(.*?)$/)) {
358            fileUrl = url[2];
359           if(!fileUrl.match(/^\//)) fileUrl = '/' + fileUrl;
360       }
361       else if(url = fileUrl.match(/data\/media\/(.*?)$/)) {  // needs tobe updated for non-standard and Windows save dirs
362           fileUrl = url[1];
363           if(!fileUrl.match(/^\//)) fileUrl = '/' + fileUrl;
364       }
365      else {
366                   var cookie = ckgEedit_getCookie('FCK_animal') ;
367                   if(cookie) {
368                        var match = fileUrl.match(cookie+'\/file/(.*)');
369                        if(match)  fileUrl = match[1];
370                   }
371      }
372       window.top.opener.update_ckgeditMediaLink(fileUrl);
373    parent.opener.oDokuWiki_FCKEditorInstance.isLocalDwikiBrowser=false;
374    }
375
376  }
377  catch(e) {
378  }
379	window.top.close() ;
380	window.top.opener.focus() ;
381}
382function sortFileList(type) {
383     oListManager.Clear();
384    oConnector.SortType = type;
385    oConnector.SendCommand( 'GetFoldersAndFiles', null, GetFoldersAndFilesCallBack ) ;
386}
387
388function findFiles(search){
389   oConnector.Search = new RegExp(search);
390   sortFileList('search');
391}
392
393function reverseListOrder(bool){
394   oConnector.reverseOrder = bool;
395   if(oConnector.SortType && (oConnector.SortType == 'mtime' || oConnector.SortType=='fsize')) {
396       oConnector.SendCommand( 'GetFoldersAndFiles', null, GetFoldersAndFilesCallBack ) ;
397   }
398}
399
400function LoadResources( resourceType, folderPath )
401{
402
403	oListManager.Clear();
404	document.body.innerHTML = translateItem('DlgFileBrowserWaitingMsg', 'Loading, please wait.'); //Show waiting message
405	oConnector.ResourceType = resourceType ;
406	oConnector.CurrentFolder = folderPath ? folderPath : '/';
407     parent.opener.window.setTimeout( oConnector.SendCommand( 'GetFoldersAndFiles', null, GetFoldersAndFilesCallBack ), 9000) ;
408
409}
410
411function Refresh()
412{
413	LoadResources( oConnector.ResourceType, oConnector.CurrentFolder ) ;
414}
415
416function GetFoldersAndFilesCallBack( fckXml )
417{
418   imgCount = 0;
419   imageArray = new Array();
420   KBArray = new Array();
421   imgProcessingStack = new Array();
422   oListManager.Clear();//Clear waiting message
423
424	if ( oConnector.CheckError( fckXml ) != 0 )
425		return ;
426
427	// Get the current folder path.
428	var oFolderNode = fckXml.SelectSingleNode( 'Connector/CurrentFolder' ) ;
429	if ( oFolderNode == null )
430	{
431
432        alert(translateItem('FileBrowserError_XML', 'The server didn\'t reply with a proper XML data. Please check your configuration.'));
433		return ;
434	}
435	var sCurrentFolderPath	= oFolderNode.attributes.getNamedItem('path').value ;
436
437	var sCurrentFolderUrl	= oFolderNode.attributes.getNamedItem('url').value ;
438
439	var oHtml = new StringBuilder( '<table id="tableFiles" cellspacing="0" cellpadding="1" width="100%" border="0">' ) ;
440
441	// Add the Folders.
442    var isImage = oConnector.ResourceType == 'Image' ? true : false;
443	var oNodes ;
444	oNodes = fckXml.SelectNodes( 'Connector/Folders/Folder' ) ;
445	for ( var i = 0 ; i < oNodes.length ; i++ )
446	{
447
448        var sFolderName = dwikiUTF8_decodeFN(oNodes[i].attributes.getNamedItem('name').value,DwikiFNencode);
449        var folder_class = oNodes[i].attributes.getNamedItem('class').value ;
450        if(sFolderName.match(/__AAAAAAAA__.AAA/)) {
451            currentFolderUploadStatus = folder_class;
452            continue;
453        }
454		oHtml.Append( oListManager.GetFolderRowHtml( sFolderName, sCurrentFolderPath + sFolderName + "/", folder_class, isImage ) ) ;
455	}
456
457	// Add the Files.
458	oNodes = fckXml.SelectNodes( 'Connector/Files/File' ) ;
459    if(oConnector.SortType == 'mtime') {
460        oNodes.sort(function(a, b) {
461            var a_tm = Number(a.attributes.getNamedItem('time').value);
462            var b_tm = Number(b.attributes.getNamedItem('time').value);
463            if(oConnector.reverseOrder) {
464               return b_tm - a_tm;
465            }
466            return a_tm - b_tm;
467         });
468     }
469     else if(oConnector.SortType == 'fsize') {
470        oNodes.sort(function(a, b) {
471            var a_tm = parseInt(a.attributes.getNamedItem('size').value);
472            var b_tm = parseInt(b.attributes.getNamedItem('size').value);
473            if(oConnector.reverseOrder) {
474               return b_tm - a_tm;
475            }
476            return a_tm - b_tm;
477         });
478     }
479	for ( var j = 0 ; j < oNodes.length ; j++ )
480	{
481		var oNode = oNodes[j] ;
482        var sFileName = dwikiUTF8_decodeFN(oNode.attributes.getNamedItem('name').value,DwikiFNencode);
483        if(oConnector.SortType == 'search' && !sFileName.match(oConnector.Search)) continue;
484    	var sFileSize = oNode.attributes.getNamedItem('size').value ;
485        var sFileTime = oNode.attributes.getNamedItem('time').value;
486
487        if(isInternalLink) {
488            var sTitle = "";
489            sTitle = oNode.attributes.getNamedItem('title').value;
490           // if(sTitle) alert(sTitle);
491            if(!sFileName.match(/\.txt$/)) continue;
492            sFileName = sFileName.replace(/\.txt$/,"");
493        }
494        else if(isImage) {
495          if(!sFileName.match(ImagesAllowed)) {
496                continue;
497          }
498        }
499
500
501		// Get the optional "url" attribute. If not available, build the url.
502		var oFileUrlAtt = oNodes[j].attributes.getNamedItem('url') ;
503		var sFileUrl = oFileUrlAtt != null ? oFileUrlAtt.value : sCurrentFolderUrl + sFileName ;
504
505         if(isImage && FCKImageSaveDir) {
506           sFileUrl=sFileUrl.replace(/^.*?\/image\//,"");
507           sFileUrl = FCKImageSaveDir + sFileUrl;
508        }
509
510        if(isImage) {
511               sFileUrl = dwikiUTF8_encodeFN(sFileUrl,DwikiFNencode);
512       }
513		oHtml.Append( oListManager.GetFileRowHtml( sFileName, sFileUrl, sFileSize, isImage, sFileTime, sTitle) ) ;
514	}
515
516	oHtml.Append( '<\/table>' ) ;
517    var big = '<center><div id="big_imagewin"><div id="bigwin_display"></div>' +
518              '<div id="big_iwin_close"><button onclick="close_bigImgwin();"  class="bigwin_close_but">close</button>&nbsp;&nbsp;&nbsp;</div></div></center>';
519	document.body.innerHTML = big + oHtml.ToString() ;
520    oConnector.Search = new RegExp("");
521
522}
523
524
525function insertImages() {
526
527   for(var i = 0; i<imageArray.length; i++) {
528           var imgId = 'img_' + i;
529           showImage(imgId);
530   }
531
532}
533
534function postMessageHandler( event ) {
535/*
536  console.log("We've got a message!");
537  console.log("* Message:", event.data);
538  console.log("* Origin:", event.origin);
539  console.log("* Source:", event.source);
540  */
541  Refresh();
542}
543
544if (window.addEventListener) {
545  window.addEventListener("message", postMessageHandler, false);
546  } else {
547  window.attachEvent("onmessage", postMessageHandler);
548}
549function UnlinkFileCallBack( fckXml, id )
550{
551    if(id) {
552       parent.opener.ckged_setmedia(id,true,this);
553    }
554   GetFoldersAndFilesCallBack( fckXml );
555
556}
557
558function close_bigImgwin() {
559
560  document.getElementById('big_imagewin').style.display='none';
561}
562
563window.onload = function()
564{
565	window.top.IsLoadedResourcesList = true ;
566        setupLanguage();
567       FCKImageSaveDir=getFCKSaveDir() ;
568     //  alert(FCKImageSaveDir);
569
570}
571	</script>
572</head>
573<body class="FileArea">
574</body>
575</html>
576