Subversion Repositories Applications.papyrus

Rev

Rev 1925 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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