source: trunk/admin/inc/FCKeditor/fckeditor.php@ 2

Last change on this file since 2 was 2, checked in by root, 15 years ago

importo il progetto

File size: 4.4 KB
RevLine 
[2]1<?php
2/*
3 * FCKeditor - The text editor for internet
4 * Copyright (C) 2003-2006 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
24class FCKeditor
25{
26 var $InstanceName ;
27 var $BasePath ;
28 var $Width ;
29 var $Height ;
30 var $ToolbarSet ;
31 var $Value ;
32 var $Config ;
33
34 // PHP 5 Constructor (by Marcus Bointon <coolbru@users.sourceforge.net>)
35 function __construct( $instanceName )
36 {
37 $this->InstanceName = $instanceName ;
38 $strBP = str_replace('\\', '/', dirname($_SERVER['PHP_SELF'])); //Fixes issue on some Windows setups - montego
39 if ($strBP{strlen($strBP)-1} != "/") $strBP .= "/";
40 $strBP .= 'inc/FCKeditor/';
41 $this->BasePath = $strBP;
42 $this->Width = '98%' ;
43 $this->Height = '200' ;
44 $this->ToolbarSet = 'PHPNuke' ;
45 $this->Value = '' ;
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 .= "&amp;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=\"0\" scrolling=\"no\"></iframe>" ;
86 }
87 else
88 {
89 if ( strpos( $this->Width, '%' ) === false )
90 $WidthCSS = $this->Width . 'px' ;
91 else
92 $WidthCSS = $this->Width ;
93
94 if ( strpos( $this->Height, '%' ) === false )
95 $HeightCSS = $this->Height . 'px' ;
96 else
97 $HeightCSS = $this->Height ;
98
99 $Html .= "<textarea name=\"{$this->InstanceName}\" rows=\"4\" cols=\"40\" style=\"width: {$WidthCSS}; height: {$HeightCSS}\">{$HtmlValue}</textarea>" ;
100 }
101
102 $Html .= '</div>' ;
103
104 return $Html ;
105 }
106
107 function IsCompatible()
108 {
109 global $HTTP_USER_AGENT ;
110
111 if ( isset( $HTTP_USER_AGENT ) )
112 $sAgent = $HTTP_USER_AGENT ;
113 else
114 $sAgent = $_SERVER['HTTP_USER_AGENT'] ;
115
116 if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false )
117 {
118 $iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ;
119 return ($iVersion >= 5.5) ;
120 }
121 else if ( strpos($sAgent, 'Gecko/') !== false )
122 {
123 $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;
124 return ($iVersion >= 20030210) ;
125 }
126 else
127 return false ;
128 }
129
130 function GetConfigFieldString()
131 {
132 $sParams = '' ;
133 $bFirst = true ;
134
135 foreach ( $this->Config as $sKey => $sValue )
136 {
137 if ( $bFirst == false )
138 $sParams .= '&amp;' ;
139 else
140 $bFirst = false ;
141
142 if ( $sValue === true )
143 $sParams .= $this->EncodeConfig( $sKey ) . '=true' ;
144 else if ( $sValue === false )
145 $sParams .= $this->EncodeConfig( $sKey ) . '=false' ;
146 else
147 $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ;
148 }
149
150 return $sParams ;
151 }
152
153 function EncodeConfig( $valueToEncode )
154 {
155 $chars = array(
156 '&' => '%26',
157 '=' => '%3D',
158 '"' => '%22' ) ;
159
160 return strtr( $valueToEncode, $chars ) ;
161 }
162}
163
164?>
Note: See TracBrowser for help on using the repository browser.