summaryrefslogtreecommitdiff
path: root/httemplate/elements/fckeditor/editor/dialog/fck_paste.html
blob: 3e11da1037a1e8ee16828164f68f0b87f7034f5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2010 Frederico Caldeira Knabben
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
 *
 * This dialog is shown when, for some reason (usually security settings),
 * the user is not able to paste data from the clipboard to the editor using
 * the toolbar buttons or the context menu.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title></title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="robots" content="noindex, nofollow" />
	<script src="common/fck_dialog_common.js" type="text/javascript"></script>
	<script type="text/javascript">
var dialog = window.parent ;
var oEditor = dialog.InnerDialogLoaded() ;
var FCK = oEditor.FCK;
var FCKTools	= oEditor.FCKTools ;
var FCKConfig	= oEditor.FCKConfig ;
var FCKBrowserInfo = oEditor.FCKBrowserInfo ;

window.onload = function ()
{
	// First of all, translate the dialog box texts
	oEditor.FCKLanguageManager.TranslatePage(document) ;

	var sPastingType = dialog.Args().CustomValue ;

	if ( sPastingType == 'Word' || sPastingType == 'Security' )
	{
		if ( sPastingType == 'Security' )
			document.getElementById( 'xSecurityMsg' ).style.display = '' ;

		// For document.domain compatibility (#123) we must do all the magic in
		// the URL for IE.
		var sFrameUrl = !oEditor.FCK_IS_CUSTOM_DOMAIN || !FCKBrowserInfo.IsIE ?
			'javascript:void(0)' :
			'javascript:void( (function(){' +
				'document.open() ;' +
				'document.domain=\'' + document.domain + '\' ;' +
				'document.write(\'<html><head><scr' + 'ipt>window.onerror = function() { return true ; };<\/script><\/head><body><\/body><\/html>\') ;' +
				'document.close() ;' +
				'document.body.contentEditable = true ;' +
				'window.focus() ;' +
				'})() )' ;

		var eFrameSpace = document.getElementById( 'xFrameSpace' ) ;
		eFrameSpace.innerHTML = '<iframe id="frmData" src="' + sFrameUrl + '" ' +
					'height="98%" width="99%" frameborder="0" style="border: #000000 1px; background-color: #ffffff"><\/iframe>' ;

		var oFrame = eFrameSpace.firstChild ;

		if ( !oEditor.FCK_IS_CUSTOM_DOMAIN || !FCKBrowserInfo.IsIE )
		{
			// Avoid errors if the pasted content has any script that fails: #389
			var oDoc = oFrame.contentWindow.document ;
			oDoc.open() ;
			oDoc.write('<html><head><scr' + 'ipt>window.onerror = function() { return true ; };<\/script><\/head><body><\/body><\/html>') ;
			oDoc.close() ;

			if ( FCKBrowserInfo.IsIE )
				oDoc.body.contentEditable = true ;
			else
				oDoc.designMode = 'on' ;

			oFrame.contentWindow.focus();
		}
	}
	else
	{
		document.getElementById('txtData').style.display = '' ;
		SelectField( 'txtData' ) ;
	}

	if ( sPastingType != 'Word' )
		document.getElementById('oWordCommands').style.display = 'none' ;

	dialog.SetOkButton( true ) ;
	dialog.SetAutoSize( true ) ;
}

function Ok()
{
	// Before doing anything, save undo snapshot.
	oEditor.FCKUndo.SaveUndoStep() ;

	var sHtml ;

	var sPastingType = dialog.Args().CustomValue ;

	if ( sPastingType == 'Word' || sPastingType == 'Security' )
	{
		var oFrame = document.getElementById('frmData') ;
		var oBody ;

		if ( oFrame.contentDocument )
			oBody = oFrame.contentDocument.body ;
		else
			oBody = oFrame.contentWindow.document.body ;

		if ( sPastingType == 'Word' )
		{
			// If a plugin creates a FCK.CustomCleanWord function it will be called instead of the default one
			if ( typeof( FCK.CustomCleanWord ) == 'function' )
				sHtml = FCK.CustomCleanWord( oBody, document.getElementById('chkRemoveFont').checked, document.getElementById('chkRemoveStyles').checked ) ;
			else
				sHtml = CleanWord( oBody, document.getElementById('chkRemoveFont').checked, document.getElementById('chkRemoveStyles').checked ) ;
		}
		else
			sHtml = oBody.innerHTML ;

		// Fix relative anchor URLs (IE automatically adds the current page URL).
		var re = new RegExp( window.location + "#", "g" ) ;
		sHtml = sHtml.replace( re, '#') ;
	}
	else
	{
		sHtml = oEditor.FCKTools.HTMLEncode( document.getElementById('txtData').value )  ;
		sHtml = FCKTools.ProcessLineBreaks( oEditor, FCKConfig, sHtml ) ;

		// FCK.InsertHtml() does not work for us, since document fragments cannot contain node fragments. :(
		// Use the marker method instead. It's primitive, but it works.
		var range = new oEditor.FCKDomRange( oEditor.FCK.EditorWindow ) ;
		var oDoc = oEditor.FCK.EditorDocument ;
		dialog.Selection.EnsureSelection() ;
		range.MoveToSelection() ;
		range.DeleteContents() ;
		var marker = [] ;
		for ( var i = 0 ; i < 5 ; i++ )
			marker.push( parseInt(Math.random() * 100000, 10 ) ) ;
		marker = marker.join( "" ) ;
		range.InsertNode ( oDoc.createTextNode( marker ) ) ;
		var bookmark = range.CreateBookmark() ;

		// Now we've got a marker indicating the paste position in the editor document.
		// Find its position in the HTML code.
		var htmlString = oDoc.body.innerHTML ;
		var index = htmlString.indexOf( marker ) ;

		// Split it the HTML code up, add the code we generated, and put them back together.
		var htmlList = [] ;
		htmlList.push( htmlString.substr( 0, index ) ) ;
		htmlList.push( sHtml ) ;
		htmlList.push( htmlString.substr( index + marker.length ) ) ;
		htmlString = htmlList.join( "" ) ;

		if ( oEditor.FCKBrowserInfo.IsIE )
			oEditor.FCK.SetInnerHtml( htmlString ) ;
		else
			oDoc.body.innerHTML = htmlString ;

		range.MoveToBookmark( bookmark ) ;
		range.Collapse( false ) ;
		range.Select() ;
		range.Release() ;
		return true ;
	}

	oEditor.FCK.InsertHtml( sHtml ) ;

	return true ;
}

// This function will be called from the PasteFromWord dialog (fck_paste.html)
// Input: oNode a DOM node that contains the raw paste from the clipboard
// bIgnoreFont, bRemoveStyles booleans according to the values set in the dialog
// Output: the cleaned string
function CleanWord( oNode, bIgnoreFont, bRemoveStyles )
{
	var html = oNode.innerHTML ;

	html = html.replace(/<o:p>\s*<\/o:p>/g, '') ;
	html = html.replace(/<o:p>[\s\S]*?<\/o:p>/g, '&nbsp;') ;

	// Remove mso-xxx styles.
	html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, '' ) ;

	// Remove margin styles.
	html = html.replace( /\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*;/gi, '' ) ;
	html = html.replace( /\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*"/gi, "\"" ) ;

	html = html.replace( /\s*TEXT-INDENT: 0(?:cm|in)\s*;/gi, '' ) ;
	html = html.replace( /\s*TEXT-INDENT: 0(?:cm|in)\s*"/gi, "\"" ) ;

	html = html.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;

	html = html.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;

	html = html.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;

	html = html.replace( /\s*tab-stops:[^;"]*;?/gi, '' ) ;
	html = html.replace( /\s*tab-stops:[^"]*/gi, '' ) ;

	// Remove FONT face attributes.
	if ( bIgnoreFont )
	{
		html = html.replace( /\s*face="[^"]*"/gi, '' ) ;
		html = html.replace( /\s*face=[^ >]*/gi, '' ) ;

		html = html.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, '' ) ;
	}

	// Remove Class attributes
	html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;

	// Remove styles.
	if ( bRemoveStyles )
		html = html.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ;

	// Remove style, meta and link tags
	html = html.replace( /<STYLE[^>]*>[\s\S]*?<\/STYLE[^>]*>/gi, '' ) ;
	html = html.replace( /<(?:META|LINK)[^>]*>\s*/gi, '' ) ;

	// Remove empty styles.
	html =  html.replace( /\s*style="\s*"/gi, '' ) ;

	html = html.replace( /<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>/gi, '&nbsp;' ) ;

	html = html.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ;

	// Remove Lang attributes
	html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;

	html = html.replace( /<SPAN\s*>([\s\S]*?)<\/SPAN>/gi, '$1' ) ;

	html = html.replace( /<FONT\s*>([\s\S]*?)<\/FONT>/gi, '$1' ) ;

	// Remove XML elements and declarations
	html = html.replace(/<\\?\?xml[^>]*>/gi, '' ) ;

	// Remove w: tags with contents.
	html = html.replace( /<w:[^>]*>[\s\S]*?<\/w:[^>]*>/gi, '' ) ;

	// Remove Tags with XML namespace declarations: <o:p><\/o:p>
	html = html.replace(/<\/?\w+:[^>]*>/gi, '' ) ;

	// Remove comments [SF BUG-1481861].
	html = html.replace(/<\!--[\s\S]*?-->/g, '' ) ;

	html = html.replace( /<(U|I|STRIKE)>&nbsp;<\/\1>/g, '&nbsp;' ) ;

	html = html.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;

	// Remove "display:none" tags.
	html = html.replace( /<(\w+)[^>]*\sstyle="[^"]*DISPLAY\s?:\s?none[\s\S]*?<\/\1>/ig, '' ) ;

	// Remove language tags
	html = html.replace( /<(\w[^>]*) language=([^ |>]*)([^>]*)/gi, "<$1$3") ;

	// Remove onmouseover and onmouseout events (from MS Word comments effect)
	html = html.replace( /<(\w[^>]*) onmouseover="([^\"]*)"([^>]*)/gi, "<$1$3") ;
	html = html.replace( /<(\w[^>]*) onmouseout="([^\"]*)"([^>]*)/gi, "<$1$3") ;

	if ( FCKConfig.CleanWordKeepsStructure )
	{
		// The original <Hn> tag send from Word is something like this: <Hn style="margin-top:0px;margin-bottom:0px">
		html = html.replace( /<H(\d)([^>]*)>/gi, '<h$1>' ) ;

		// Word likes to insert extra <font> tags, when using MSIE. (Wierd).
		html = html.replace( /<(H\d)><FONT[^>]*>([\s\S]*?)<\/FONT><\/\1>/gi, '<$1>$2<\/$1>' );
		html = html.replace( /<(H\d)><EM>([\s\S]*?)<\/EM><\/\1>/gi, '<$1>$2<\/$1>' );
	}
	else
	{
		html = html.replace( /<H1([^>]*)>/gi, '<div$1><b><font size="6">' ) ;
		html = html.replace( /<H2([^>]*)>/gi, '<div$1><b><font size="5">' ) ;
		html = html.replace( /<H3([^>]*)>/gi, '<div$1><b><font size="4">' ) ;
		html = html.replace( /<H4([^>]*)>/gi, '<div$1><b><font size="3">' ) ;
		html = html.replace( /<H5([^>]*)>/gi, '<div$1><b><font size="2">' ) ;
		html = html.replace( /<H6([^>]*)>/gi, '<div$1><b><font size="1">' ) ;

		html = html.replace( /<\/H\d>/gi, '<\/font><\/b><\/div>' ) ;

		// Transform <P> to <DIV>
		var re = new RegExp( '(<P)([^>]*>[\\s\\S]*?)(<\/P>)', 'gi' ) ;	// Different because of a IE 5.0 error
		html = html.replace( re, '<div$2<\/div>' ) ;

		// Remove empty tags (three times, just to be sure).
		// This also removes any empty anchor
		html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
		html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
		html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
	}

	return html ;
}

	</script>

</head>
<body style="overflow: hidden">
	<table cellspacing="0" cellpadding="0" width="100%" border="0" style="height: 98%">
		<tr>
			<td>
				<div id="xSecurityMsg" style="display: none">
					<span fcklang="DlgPasteSec">Because of your browser security settings,
						the editor is not able to access your clipboard data directly. You are required
						to paste it again in this window.</span><br />
					&nbsp;
				</div>
				<div>
					<span fcklang="DlgPasteMsg2">Please paste inside the following box using the keyboard
						(<strong>Ctrl+V</strong>) and hit <strong>OK</strong>.</span><br />
					&nbsp;
				</div>
			</td>
		</tr>
		<tr>
			<td id="xFrameSpace" valign="top" height="100%" style="border: #000000 1px solid">
				<textarea id="txtData" cols="80" rows="5" style="border: #000000 1px; display: none;
					width: 99%; height: 98%"></textarea>
			</td>
		</tr>
		<tr id="oWordCommands">
			<td>

					<input id="chkRemoveFont" type="checkbox" checked="checked" />
					<label for="chkRemoveFont" fcklang="DlgPasteIgnoreFont">
						Ignore Font Face definitions</label>
					<br />
					<input id="chkRemoveStyles" type="checkbox" />
					<label for="chkRemoveStyles" fcklang="DlgPasteRemoveStyles">
						Remove Styles definitions</label>

			</td>
		</tr>
	</table>
</body>
</html>