source: trunk/expressoMail1_2/inc/fckeditor.php @ 4828

Revision 4828, 4.7 KB checked in by airton, 13 years ago (diff)

Ticket #2146 - Implementacao da funcionalidade de multiplas assinaturas

Line 
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                $this->BasePath         = '/fckeditor/' ;
39                $this->Width            = '100%' ;
40                $this->Height           = '275' ;
41                $this->ToolbarSet       = 'Default' ;
42                $this->Value            = '' ;
43
44                $this->Config           = array() ;
45        }
46       
47        // PHP 4 Contructor
48        function FCKeditor( $instanceName )
49        {
50                $this->__construct( $instanceName ) ;
51        }
52
53        function Create()
54        {
55                return $this->CreateHtml() ;
56        }
57       
58        function CreateHtml()
59        {
60                $HtmlValue = htmlspecialchars( $this->Value ) ;
61
62                $Html = '<div>' ;
63               
64                if ( $this->IsCompatible() )
65                {
66                        if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" )
67                                $File = 'fckeditor.original.html' ;
68                        else
69                                $File = 'fckeditor.html' ;
70
71                        $Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ;
72                       
73                        if ( $this->ToolbarSet != '' )
74                                $Link .= "&Toolbar={$this->ToolbarSet}" ;
75
76                        // Render the linked hidden field.
77                        $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ;
78
79                        // Render the configurations hidden field.
80                        $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ;
81
82                        // Render the editor IFRAME.
83                        $Html .= "<iframe id=\"{$this->InstanceName}___Frame\" src=\"{$Link}\" width=\"{$this->Width}\" height=\"{$this->Height}\" frameborder=\"0\" scrolling=\"no\"></iframe>" ;
84                }
85                else
86                {
87                        if ( strpos( $this->Width, '%' ) === false )
88                                $WidthCSS = $this->Width . 'px' ;
89                        else
90                                $WidthCSS = $this->Width ;
91
92                        if ( strpos( $this->Height, '%' ) === false )
93                                $HeightCSS = $this->Height . 'px' ;
94                        else
95                                $HeightCSS = $this->Height ;
96
97                        $Html .= "<textarea name=\"{$this->InstanceName}\" rows=\"4\" cols=\"40\" style=\"width: {$WidthCSS}; height: {$HeightCSS}\">{$HtmlValue}</textarea>" ;
98                }
99
100                $Html .= '</div>' ;
101               
102                return $Html ;
103        }
104
105        function IsCompatible()
106        {
107                //             global $HTTP_USER_AGENT ;
108                // 
109                //              if ( isset( $HTTP_USER_AGENT ) )
110                //                      $sAgent = $HTTP_USER_AGENT ;
111                //              else
112                //                      $sAgent = $_SERVER['HTTP_USER_AGENT'] ;
113                // 
114                //              if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false )
115                //              {
116                //                      $iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ;
117                //                      return ($iVersion >= 5.5) ;
118                //              }
119                //              else if ( strpos($sAgent, 'Gecko/') !== false )
120                //              {
121                //                      $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;
122                //                      return ($iVersion >= 20030210) ;
123                //              }
124                //              else
125                //                      return false ;
126                            return( true );
127        }
128
129        function GetConfigFieldString()
130        {
131                $sParams = '' ;
132                $bFirst = true ;
133
134                foreach ( $this->Config as $sKey => $sValue )
135                {
136                        if ( $bFirst == false )
137                                $sParams .= '&amp;' ;
138                        else
139                                $bFirst = false ;
140                       
141                        if ( $sValue === true )
142                                $sParams .= $this->EncodeConfig( $sKey ) . '=true' ;
143                        else if ( $sValue === false )
144                                $sParams .= $this->EncodeConfig( $sKey ) . '=false' ;
145                        else
146                                $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ;
147                }
148               
149                return $sParams ;
150        }
151
152                //      function getConfigFieldString()
153                //      {
154                //          $sParams = array();
155                //       
156                //          foreach( $this->Config as $sKey => $sValue )
157                //              $sParams[] = $this->EncodeConfig( $sKey ).'='.$this->EncodeConfig( $sValue );
158                // 
159                //          return implode( '&amp;', $sParams );
160                //      }
161       
162       
163        function EncodeConfig( $valueToEncode )
164        {
165                $chars = array(
166                        '&' => '%26',
167                        '=' => '%3D',
168                        '"' => '%22' ) ;
169
170                return strtr( $valueToEncode,  $chars ) ;
171        }
172}
173
174?>
Note: See TracBrowser for help on using the repository browser.