Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1921 jp_milcent 1
<?php
2
/*
3
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
4
 * Copyright (C) 2003-2008 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 is the integration file for PHP 4.
23
 *
24
 * It defines the FCKeditor class that can be used to create editor
25
 * instances in PHP pages on server side.
26
 */
27
 
28
/**
29
 * Check if browser is compatible with FCKeditor.
30
 * Return true if is compatible.
31
 *
32
 * @return boolean
33
 */
34
function FCKeditor_IsCompatibleBrowser()
35
{
36
	if ( isset( $_SERVER ) ) {
37
		$sAgent = $_SERVER['HTTP_USER_AGENT'] ;
38
	}
39
	else {
40
		global $HTTP_SERVER_VARS ;
41
		if ( isset( $HTTP_SERVER_VARS ) ) {
42
			$sAgent = $HTTP_SERVER_VARS['HTTP_USER_AGENT'] ;
43
		}
44
		else {
45
			global $HTTP_USER_AGENT ;
46
			$sAgent = $HTTP_USER_AGENT ;
47
		}
48
	}
49
 
50
	if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false )
51
	{
52
		$iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ;
53
		return ($iVersion >= 5.5) ;
54
	}
55
	else if ( strpos($sAgent, 'Gecko/') !== false )
56
	{
57
		$iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;
58
		return ($iVersion >= 20030210) ;
59
	}
60
	else if ( strpos($sAgent, 'Opera/') !== false )
61
	{
62
		$fVersion = (float)substr($sAgent, strpos($sAgent, 'Opera/') + 6, 4) ;
63
		return ($fVersion >= 9.5) ;
64
	}
65
	else if ( preg_match( "|AppleWebKit/(\d+)|i", $sAgent, $matches ) )
66
	{
67
		$iVersion = $matches[1] ;
68
		return ( $matches[1] >= 522 ) ;
69
	}
70
	else
71
		return false ;
72
}
73
 
74
class FCKeditor
75
{
76
	/**
77
	 * Name of the FCKeditor instance.
78
	 *
79
	 * @access protected
80
	 * @var string
81
	 */
82
	var $InstanceName ;
83
	/**
84
	 * Path to FCKeditor relative to the document root.
85
	 *
86
	 * @var string
87
	 */
88
	var $BasePath ;
89
	/**
90
	 * Width of the FCKeditor.
91
	 * Examples: 100%, 600
92
	 *
93
	 * @var mixed
94
	 */
95
	var $Width ;
96
	/**
97
	 * Height of the FCKeditor.
98
	 * Examples: 400, 50%
99
	 *
100
	 * @var mixed
101
	 */
102
	var $Height ;
103
	/**
104
	 * Name of the toolbar to load.
105
	 *
106
	 * @var string
107
	 */
108
	var $ToolbarSet ;
109
	/**
110
	 * Initial value.
111
	 *
112
	 * @var string
113
	 */
114
	var $Value ;
115
	/**
116
	 * This is where additional configuration can be passed.
117
	 * Example:
118
	 * $oFCKeditor->Config['EnterMode'] = 'br';
119
	 *
120
	 * @var array
121
	 */
122
	var $Config ;
123
 
124
	/**
125
	 * Main Constructor.
126
	 * Refer to the _samples/php directory for examples.
127
	 *
128
	 * @param string $instanceName
129
	 */
130
	function FCKeditor( $instanceName )
131
	{
132
		$this->InstanceName	= $instanceName ;
133
		$this->BasePath		= '/fckeditor/' ;
134
		$this->Width		= '100%' ;
135
		$this->Height		= '200' ;
136
		$this->ToolbarSet	= 'Default' ;
137
		$this->Value		= '' ;
138
 
139
		$this->Config		= array() ;
140
	}
141
 
142
	/**
143
	 * Display FCKeditor.
144
	 *
145
	 */
146
	function Create()
147
	{
148
		echo $this->CreateHtml() ;
149
	}
150
 
151
	/**
152
	 * Return the HTML code required to run FCKeditor.
153
	 *
154
	 * @return string
155
	 */
156
	function CreateHtml()
157
	{
158
		$HtmlValue = htmlspecialchars( $this->Value ) ;
159
 
160
		$Html = '' ;
161
 
162
		if ( !isset( $_GET ) ) {
163
			global $HTTP_GET_VARS ;
164
			$_GET = $HTTP_GET_VARS ;
165
		}
166
 
167
		if ( $this->IsCompatible() )
168
		{
169
			if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" )
170
				$File = 'fckeditor.original.html' ;
171
			else
172
				$File = 'fckeditor.html' ;
173
 
174
			$Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ;
175
 
176
			if ( $this->ToolbarSet != '' )
177
				$Link .= "&amp;Toolbar={$this->ToolbarSet}" ;
178
 
179
			// Render the linked hidden field.
180
			$Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ;
181
 
182
			// Render the configurations hidden field.
183
			$Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ;
184
 
185
			// Render the editor IFRAME.
186
			$Html .= "<iframe id=\"{$this->InstanceName}___Frame\" src=\"{$Link}\" width=\"{$this->Width}\" height=\"{$this->Height}\" frameborder=\"0\" scrolling=\"no\"></iframe>" ;
187
		}
188
		else
189
		{
190
			if ( strpos( $this->Width, '%' ) === false )
191
				$WidthCSS = $this->Width . 'px' ;
192
			else
193
				$WidthCSS = $this->Width ;
194
 
195
			if ( strpos( $this->Height, '%' ) === false )
196
				$HeightCSS = $this->Height . 'px' ;
197
			else
198
				$HeightCSS = $this->Height ;
199
 
200
			$Html .= "<textarea name=\"{$this->InstanceName}\" rows=\"4\" cols=\"40\" style=\"width: {$WidthCSS}; height: {$HeightCSS}\">{$HtmlValue}</textarea>" ;
201
		}
202
 
203
		return $Html ;
204
	}
205
 
206
	/**
207
	 * Returns true if browser is compatible with FCKeditor.
208
	 *
209
	 * @return boolean
210
	 */
211
	function IsCompatible()
212
	{
213
		return FCKeditor_IsCompatibleBrowser() ;
214
	}
215
 
216
	/**
217
	 * Get settings from Config array as a single string.
218
	 *
219
	 * @access protected
220
	 * @return string
221
	 */
222
	function GetConfigFieldString()
223
	{
224
		$sParams = '' ;
225
		$bFirst = true ;
226
 
227
		foreach ( $this->Config as $sKey => $sValue )
228
		{
229
			if ( $bFirst == false )
230
				$sParams .= '&amp;' ;
231
			else
232
				$bFirst = false ;
233
 
234
			if ( $sValue === true )
235
				$sParams .= $this->EncodeConfig( $sKey ) . '=true' ;
236
			else if ( $sValue === false )
237
				$sParams .= $this->EncodeConfig( $sKey ) . '=false' ;
238
			else
239
				$sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ;
240
		}
241
 
242
		return $sParams ;
243
	}
244
 
245
	/**
246
	 * Encode characters that may break the configuration string
247
	 * generated by GetConfigFieldString().
248
	 *
249
	 * @access protected
250
	 * @param string $valueToEncode
251
	 * @return string
252
	 */
253
	function EncodeConfig( $valueToEncode )
254
	{
255
		$chars = array(
256
			'&' => '%26',
257
			'=' => '%3D',
258
			'"' => '%22' ) ;
259
 
260
		return strtr( $valueToEncode,  $chars ) ;
261
	}
262
}