Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1925 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 5.
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
	public $InstanceName ;
83
	/**
84
	 * Path to FCKeditor relative to the document root.
85
	 *
86
	 * @var string
87
	 */
88
	public $BasePath ;
89
	/**
90
	 * Width of the FCKeditor.
91
	 * Examples: 100%, 600
92
	 *
93
	 * @var mixed
94
	 */
95
	public $Width ;
96
	/**
97
	 * Height of the FCKeditor.
98
	 * Examples: 400, 50%
99
	 *
100
	 * @var mixed
101
	 */
102
	public $Height ;
103
	/**
104
	 * Name of the toolbar to load.
105
	 *
106
	 * @var string
107
	 */
108
	public $ToolbarSet ;
109
	/**
110
	 * Initial value.
111
	 *
112
	 * @var string
113
	 */
114
	public $Value ;
115
	/**
116
	 * This is where additional configuration can be passed.
117
	 * Example:
118
	 * $oFCKeditor->Config['EnterMode'] = 'br';
119
	 *
120
	 * @var array
121
	 */
122
	public $Config ;
123
 
124
	/**
125
	 * Main Constructor.
126
	 * Refer to the _samples/php directory for examples.
127
	 *
128
	 * @param string $instanceName
129
	 */
130
	public function __construct( $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
	public 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
	public function CreateHtml()
157
	{
158
		$HtmlValue = htmlspecialchars( $this->Value ) ;
159
 
160
		$Html = '' ;
161
 
162
		if ( $this->IsCompatible() )
163
		{
164
			if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" )
165
				$File = 'fckeditor.original.html' ;
166
			else
167
				$File = 'fckeditor.html' ;
168
 
169
			$Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ;
170
 
171
			if ( $this->ToolbarSet != '' )
172
				$Link .= "&amp;Toolbar={$this->ToolbarSet}" ;
173
 
174
			// Render the linked hidden field.
175
			$Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ;
176
 
177
			// Render the configurations hidden field.
178
			$Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ;
179
 
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>" ;
182
		}
183
		else
184
		{
185
			if ( strpos( $this->Width, '%' ) === false )
186
				$WidthCSS = $this->Width . 'px' ;
187
			else
188
				$WidthCSS = $this->Width ;
189
 
190
			if ( strpos( $this->Height, '%' ) === false )
191
				$HeightCSS = $this->Height . 'px' ;
192
			else
193
				$HeightCSS = $this->Height ;
194
 
195
			$Html .= "<textarea name=\"{$this->InstanceName}\" rows=\"4\" cols=\"40\" style=\"width: {$WidthCSS}; height: {$HeightCSS}\">{$HtmlValue}</textarea>" ;
196
		}
197
 
198
		return $Html ;
199
	}
200
 
201
	/**
202
	 * Returns true if browser is compatible with FCKeditor.
203
	 *
204
	 * @return boolean
205
	 */
206
	public function IsCompatible()
207
	{
208
		return FCKeditor_IsCompatibleBrowser() ;
209
	}
210
 
211
	/**
212
	 * Get settings from Config array as a single string.
213
	 *
214
	 * @access protected
215
	 * @return string
216
	 */
217
	public function GetConfigFieldString()
218
	{
219
		$sParams = '' ;
220
		$bFirst = true ;
221
 
222
		foreach ( $this->Config as $sKey => $sValue )
223
		{
224
			if ( $bFirst == false )
225
				$sParams .= '&amp;' ;
226
			else
227
				$bFirst = false ;
228
 
229
			if ( $sValue === true )
230
				$sParams .= $this->EncodeConfig( $sKey ) . '=true' ;
231
			else if ( $sValue === false )
232
				$sParams .= $this->EncodeConfig( $sKey ) . '=false' ;
233
			else
234
				$sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ;
235
		}
236
 
237
		return $sParams ;
238
	}
239
 
240
	/**
241
	 * Encode characters that may break the configuration string
242
	 * generated by GetConfigFieldString().
243
	 *
244
	 * @access protected
245
	 * @param string $valueToEncode
246
	 * @return string
247
	 */
248
	public function EncodeConfig( $valueToEncode )
249
	{
250
		$chars = array(
251
			'&' => '%26',
252
			'=' => '%3D',
253
			'"' => '%22' ) ;
254
 
255
		return strtr( $valueToEncode,  $chars ) ;
256
	}
257
}