Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
431 ddelon 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
 * File Name: fckeditor.php
13
 * 	This is the integration file for PHP.
14
 *
15
 * 	It defines the FCKeditor class that can be used to create editor
16
 * 	instances in PHP pages on server side.
17
 *
18
 * File Authors:
19
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
20
 */
21
 
22
class FCKeditor
23
{
24
	var $InstanceName ;
25
	var $BasePath ;
26
	var $Width ;
27
	var $Height ;
28
	var $ToolbarSet ;
29
	var $Value ;
30
	var $Config ;
31
 
32
	// PHP 5 Constructor (by Marcus Bointon <coolbru@users.sourceforge.net>)
33
	function __construct( $instanceName )
34
 	{
35
		$this->InstanceName	= $instanceName ;
36
		$this->BasePath		= '/FCKeditor/' ;
37
		$this->Width		= '100%' ;
38
		$this->Height		= '200' ;
39
		$this->ToolbarSet	= 'Default' ;
40
		$this->Value		= '' ;
41
 
42
		$this->Config		= array() ;
43
	}
44
 
45
	// PHP 4 Contructor
46
	function FCKeditor( $instanceName )
47
	{
48
		$this->__construct( $instanceName ) ;
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 ( $this->IsCompatible() )
63
		{
64
			$Link = "{$this->BasePath}editor/fckeditor.html?InstanceName={$this->InstanceName}" ;
65
 
66
			if ( $this->ToolbarSet != '' )
67
				$Link .= "&amp;Toolbar={$this->ToolbarSet}" ;
68
 
69
			// Render the linked hidden field.
70
			$Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" />" ;
71
 
72
			// Render the configurations hidden field.
73
			$Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" />" ;
74
 
75
			// Render the editor IFRAME.
76
			$Html .= "<iframe id=\"{$this->InstanceName}___Frame\" src=\"{$Link}\" width=\"{$this->Width}\" height=\"{$this->Height}\" frameborder=\"no\" scrolling=\"no\"></iframe>" ;
77
		}
78
		else
79
		{
80
			if ( strpos( $this->Width, '%' ) === false )
81
				$WidthCSS = $this->Width . 'px' ;
82
			else
83
				$WidthCSS = $this->Width ;
84
 
85
			if ( strpos( $this->Height, '%' ) === false )
86
				$HeightCSS = $this->Height . 'px' ;
87
			else
88
				$HeightCSS = $this->Height ;
89
 
90
			$Html .= "<textarea name=\"{$this->InstanceName}\" rows=\"4\" cols=\"40\" style=\"width: {$WidthCSS}; height: {$HeightCSS}\" wrap=\"virtual\">{$HtmlValue}</textarea>" ;
91
		}
92
 
93
		$Html .= '</div>' ;
94
 
95
		return $Html ;
96
	}
97
 
98
	function IsCompatible()
99
	{
100
		global $HTTP_USER_AGENT ;
101
 
102
		if ( isset( $HTTP_USER_AGENT ) )
103
			$sAgent = $HTTP_USER_AGENT ;
104
		else
105
			$sAgent = $_SERVER['HTTP_USER_AGENT'] ;
106
 
107
		if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false )
108
		{
109
			$iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ;
110
			return ($iVersion >= 5.5) ;
111
		}
112
		else if ( strpos($sAgent, 'Gecko/') !== false )
113
		{
114
			$iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;
115
			return ($iVersion >= 20030210) ;
116
		}
117
		else
118
			return false ;
119
	}
120
 
121
	function GetConfigFieldString()
122
	{
123
		$sParams = '' ;
124
		$bFirst = true ;
125
 
126
		foreach ( $this->Config as $sKey => $sValue )
127
		{
128
			if ( $bFirst == false )
129
				$sParams .= '&amp;' ;
130
			else
131
				$bFirst = false ;
132
 
133
			if ( $sValue === true )
134
				$sParams .= $this->EncodeConfig( $sKey ) . '=true' ;
135
			else if ( $sValue === false )
136
				$sParams .= $this->EncodeConfig( $sKey ) . '=false' ;
137
			else
138
				$sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ;
139
		}
140
 
141
		return $sParams ;
142
	}
143
 
144
	function EncodeConfig( $valueToEncode )
145
	{
146
		$chars = array(
147
			'&' => '%26',
148
			'=' => '%3D',
149
			'"' => '%22' ) ;
150
 
151
		return strtr( $valueToEncode,  $chars ) ;
152
	}
153
}
154
 
155
?>