Project

General

Profile

1
<?php
2
/*
3
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
4
 * Copyright (C) 2003-2007 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
class FCKeditor
29
{
30
	var $InstanceName ;
31
	var $BasePath ;
32
	var $Width ;
33
	var $Height ;
34
	var $ToolbarSet ;
35
	var $Value ;
36
	var $Config ;
37

    
38
	// PHP 4 Constructor
39
	function FCKeditor( $instanceName )
40
	{
41
		$this->InstanceName	= $instanceName ;
42
		$this->BasePath		= '/fckeditor/' ;
43
		$this->Width		= '100%' ;
44
		$this->Height		= '200' ;
45
		$this->ToolbarSet	= 'Default' ;
46
		$this->Value		= '' ;
47

    
48
		$this->Config		= array() ;
49
	}
50

    
51
	function Create()
52
	{
53
		echo $this->CreateHtml() ;
54
	}
55

    
56
	function CreateHtml()
57
	{
58
		$HtmlValue = htmlspecialchars( $this->Value ) ;
59

    
60
		$Html = '<div>' ;
61
		
62
		if ( !isset( $_GET ) ) {
63
			global $HTTP_GET_VARS ;
64
		    $_GET = $HTTP_GET_VARS ;
65
		}
66

    
67
		if ( $this->IsCompatible() )
68
		{
69
			if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" )
70
				$File = 'fckeditor.original.html' ;
71
			else
72
				$File = 'fckeditor.html' ;
73

    
74
			$Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ;
75

    
76
			if ( $this->ToolbarSet != '' )
77
				$Link .= "&amp;Toolbar={$this->ToolbarSet}" ;
78

    
79
			// Render the linked hidden field.
80
			$Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ;
81

    
82
			// Render the configurations hidden field.
83
			$Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ;
84

    
85
			// Render the editor IFRAME.
86
			$Html .= "<iframe id=\"{$this->InstanceName}___Frame\" src=\"{$Link}\" width=\"{$this->Width}\" height=\"{$this->Height}\" frameborder=\"0\" scrolling=\"no\"></iframe>" ;
87
		}
88
		else
89
		{
90
			if ( strpos( $this->Width, '%' ) === false )
91
				$WidthCSS = $this->Width . 'px' ;
92
			else
93
				$WidthCSS = $this->Width ;
94

    
95
			if ( strpos( $this->Height, '%' ) === false )
96
				$HeightCSS = $this->Height . 'px' ;
97
			else
98
				$HeightCSS = $this->Height ;
99

    
100
			$Html .= "<textarea name=\"{$this->InstanceName}\" rows=\"4\" cols=\"40\" style=\"width: {$WidthCSS}; height: {$HeightCSS}\">{$HtmlValue}</textarea>" ;
101
		}
102

    
103
		$Html .= '</div>' ;
104

    
105
		return $Html ;
106
	}
107

    
108
	function IsCompatible()
109
	{
110
		return FCKeditor_IsCompatibleBrowser() ;
111
	}
112

    
113
	function GetConfigFieldString()
114
	{
115
		$sParams = '' ;
116
		$bFirst = true ;
117

    
118
		foreach ( $this->Config as $sKey => $sValue )
119
		{
120
			if ( $bFirst == false )
121
				$sParams .= '&amp;' ;
122
			else
123
				$bFirst = false ;
124

    
125
			if ( $sValue === true )
126
				$sParams .= $this->EncodeConfig( $sKey ) . '=true' ;
127
			else if ( $sValue === false )
128
				$sParams .= $this->EncodeConfig( $sKey ) . '=false' ;
129
			else
130
				$sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ;
131
		}
132

    
133
		return $sParams ;
134
	}
135

    
136
	function EncodeConfig( $valueToEncode )
137
	{
138
		$chars = array(
139
			'&' => '%26',
140
			'=' => '%3D',
141
			'"' => '%22' ) ;
142

    
143
		return strtr( $valueToEncode,  $chars ) ;
144
	}
145
}
146

    
147
?>
(4-4/9)