1 | <?php |
---|
2 | /* |
---|
3 | * FCKeditor - The text editor for internet |
---|
4 | * Copyright (C) 2003-2005 Frederico Caldeira Knabben |
---|
5 | * |
---|
6 | * Licensed under the terms of the GNU Lesser General Public License: |
---|
7 | * http://www.opensource.org/licenses/lgpl-license.php |
---|
8 | * |
---|
9 | * For further information visit: |
---|
10 | * http://www.fckeditor.net/ |
---|
11 | * |
---|
12 | * "Support Open Source software. What about a donation today?" |
---|
13 | * |
---|
14 | * File Name: fckeditor.php |
---|
15 | * This is the integration file for PHP. |
---|
16 | * |
---|
17 | * It defines the FCKeditor class that can be used to create editor |
---|
18 | * instances in PHP pages on server side. |
---|
19 | * |
---|
20 | * File Authors: |
---|
21 | * Frederico Caldeira Knabben (fredck@fckeditor.net) |
---|
22 | */ |
---|
23 | |
---|
24 | class FCKeditor |
---|
25 | { |
---|
26 | var $InstanceName ; |
---|
27 | var $BasePath ; |
---|
28 | var $Width ; |
---|
29 | var $Height ; |
---|
30 | var $ToolbarSet ; |
---|
31 | var $Value ; |
---|
32 | var $Config ; |
---|
33 | var $TabIndex ; |
---|
34 | |
---|
35 | // PHP 5 Constructor (by Marcus Bointon <coolbru@users.sourceforge.net>) |
---|
36 | function __construct( $instanceName ) |
---|
37 | { |
---|
38 | $this->InstanceName = $instanceName ; |
---|
39 | $this->BasePath = '/FCKeditor/' ; |
---|
40 | $this->Width = '100%' ; |
---|
41 | $this->Height = '200' ; |
---|
42 | $this->ToolbarSet = 'Default' ; |
---|
43 | $this->Value = '' ; |
---|
44 | $this->TabIndex = NULL; |
---|
45 | |
---|
46 | $this->Config = array() ; |
---|
47 | } |
---|
48 | |
---|
49 | // PHP 4 Contructor |
---|
50 | function FCKeditor( $instanceName ) |
---|
51 | { |
---|
52 | $this->__construct( $instanceName ) ; |
---|
53 | } |
---|
54 | |
---|
55 | function Create() |
---|
56 | { |
---|
57 | echo $this->CreateHtml() ; |
---|
58 | } |
---|
59 | |
---|
60 | function CreateHtml() |
---|
61 | { |
---|
62 | $HtmlValue = htmlspecialchars( $this->Value ) ; |
---|
63 | |
---|
64 | $Html = '<div>' ; |
---|
65 | |
---|
66 | if ( $this->IsCompatible() ) |
---|
67 | { |
---|
68 | if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" ) |
---|
69 | $File = 'fckeditor.original.html' ; |
---|
70 | else |
---|
71 | $File = 'fckeditor.html' ; |
---|
72 | |
---|
73 | $Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ; |
---|
74 | |
---|
75 | if ( $this->ToolbarSet != '' ) |
---|
76 | $Link .= "&Toolbar={$this->ToolbarSet}" ; |
---|
77 | |
---|
78 | // Render the linked hidden field. |
---|
79 | $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ; |
---|
80 | |
---|
81 | // Render the configurations hidden field. |
---|
82 | $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ; |
---|
83 | |
---|
84 | // Render the editor IFRAME. |
---|
85 | $Html .= "<iframe id=\"{$this->InstanceName}___Frame\" src=\"{$Link}\" width=\"{$this->Width}\" height=\"{$this->Height}\" frameborder=\"no\" scrolling=\"no\""; |
---|
86 | if (isset($this->TabIndex)) { |
---|
87 | $Html .= " tabindex=\"".$this->TabIndex."\""; |
---|
88 | } |
---|
89 | $Html .= "></iframe>" ; |
---|
90 | } |
---|
91 | else |
---|
92 | { |
---|
93 | if ( strpos( $this->Width, '%' ) === false ) |
---|
94 | $WidthCSS = $this->Width . 'px' ; |
---|
95 | else |
---|
96 | $WidthCSS = $this->Width ; |
---|
97 | |
---|
98 | if ( strpos( $this->Height, '%' ) === false ) |
---|
99 | $HeightCSS = $this->Height . 'px' ; |
---|
100 | else |
---|
101 | $HeightCSS = $this->Height ; |
---|
102 | |
---|
103 | $Html .= "<textarea name=\"{$this->InstanceName}\" rows=\"4\" cols=\"40\""; |
---|
104 | if (isset($this->TabIndex)) { |
---|
105 | $Html .= " tabindex=\"".$this->TabIndex."\""; |
---|
106 | } |
---|
107 | $Html .= " style=\"width: {$WidthCSS}; height: {$HeightCSS}\">{$HtmlValue}</textarea>" ; |
---|
108 | } |
---|
109 | |
---|
110 | $Html .= '</div>' ; |
---|
111 | |
---|
112 | return $Html ; |
---|
113 | } |
---|
114 | |
---|
115 | function IsCompatible() |
---|
116 | { |
---|
117 | global $HTTP_USER_AGENT ; |
---|
118 | |
---|
119 | if ( isset( $HTTP_USER_AGENT ) ) |
---|
120 | $sAgent = $HTTP_USER_AGENT ; |
---|
121 | else |
---|
122 | $sAgent = $_SERVER['HTTP_USER_AGENT'] ; |
---|
123 | |
---|
124 | if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false ) |
---|
125 | { |
---|
126 | $iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ; |
---|
127 | return ($iVersion >= 5.5) ; |
---|
128 | } |
---|
129 | else if ( strpos($sAgent, 'Gecko/') !== false ) |
---|
130 | { |
---|
131 | $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ; |
---|
132 | return ($iVersion >= 20030210) ; |
---|
133 | } |
---|
134 | else |
---|
135 | return false ; |
---|
136 | } |
---|
137 | |
---|
138 | function GetConfigFieldString() |
---|
139 | { |
---|
140 | $sParams = '' ; |
---|
141 | $bFirst = true ; |
---|
142 | |
---|
143 | foreach ( $this->Config as $sKey => $sValue ) |
---|
144 | { |
---|
145 | if ( $bFirst == false ) |
---|
146 | $sParams .= '&' ; |
---|
147 | else |
---|
148 | $bFirst = false ; |
---|
149 | |
---|
150 | if ( $sValue === true ) |
---|
151 | $sParams .= $this->EncodeConfig( $sKey ) . '=true' ; |
---|
152 | else if ( $sValue === false ) |
---|
153 | $sParams .= $this->EncodeConfig( $sKey ) . '=false' ; |
---|
154 | else |
---|
155 | $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ; |
---|
156 | } |
---|
157 | |
---|
158 | return $sParams ; |
---|
159 | } |
---|
160 | |
---|
161 | function EncodeConfig( $valueToEncode ) |
---|
162 | { |
---|
163 | $chars = array( |
---|
164 | '&' => '%26', |
---|
165 | '=' => '%3D', |
---|
166 | '"' => '%22' ) ; |
---|
167 | |
---|
168 | return strtr( $valueToEncode, $chars ) ; |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | ?> |
---|