Ticket #1488: fckeditor_php5.php

File fckeditor_php5.php, 4.8 KB (added by Robert Hafner, 16 years ago)
Line 
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 5.
23 *
24 * It defines the FCKeditor class that can be used to create editor
25 * instances in PHP pages on server side.
26 *
27 * Contributors:
28 *   Robert Hafner <tedivm@tedivm.com>
29 *
30 */
31
32class FCKeditor
33{
34
35    protected $InstanceName ;
36    public $BasePath ;
37    public $Width ;
38    public $Height ;
39    public $ToolbarSet ;
40    public $Value ;
41    public $Config = array();
42    public $id;
43   
44    // PHP 5 Constructor (by Marcus Bointon <coolbru@users.sourceforge.net>)
45    public function __construct( $instanceName )
46     {
47        $this->InstanceName    = $instanceName ;
48        $this->BasePath        = '/fckeditor/' ;
49        $this->Width        = '100%' ;
50        $this->Height        = '200' ;
51        $this->ToolbarSet    = 'Default' ;
52        $this->Value        = '' ;
53        $this->id        = '' ;
54    }
55
56    public function Create()
57    {
58        echo $this->CreateHtml() ;
59    }
60
61    public function CreateHtml()
62    {
63        $HtmlValue = htmlspecialchars( $this->Value ) ;
64
65        $Html = '<div>' ;
66
67        if ( $this->IsCompatible() )
68        {
69           
70            $File = ($_GET['fcksource'] == true) ? 'fckeditor.original.html' : 'fckeditor.html';
71
72            $Link = $this->BasePath . 'editor/' .$File . '?InstanceName=' . $this->InstanceName ;
73
74            if ( $this->ToolbarSet != '' )
75                $Link .= "&amp;Toolbar={$this->ToolbarSet}" ;
76               
77            if ( $this->id == '' )
78                $this->id = $this->InstanceName;
79
80            // Render the linked hidden field.
81            $Html .= '<input type="hidden" id="' . $this->id . '" name="' . $this->InstanceName . '" value="' . $HtmlValue . '" style="display:none" />' ;
82
83            // Render the configurations hidden field.
84            $Html .= '<input type="hidden" id="'. $this->id .'___Config" value="' . $this->GetConfigFieldString() . '" style="display:none" />' ;
85
86            // Render the editor IFRAME.
87            $Html .= '<iframe id="'. $this->id .'___Frame" src="' . $Link . '" width="' . $this->Width .'" height="'. $this->Height .'" frameborder="0" scrolling="no"></iframe>' ;
88        }
89        else
90        {
91           
92            $WidthCSS = ( strpos( $this->Width, '%' ) === false ) ? $this->Width . 'px' : $this->Width ;
93            $HeightCSS = ( strpos( $this->Height, '%' ) === false ) ?  $this->Height . 'px' : $this->Height ;
94
95            $Html .= '<textarea name="' . $this->InstanceName . '" rows="4" cols="40" style="width:' . $WidthCSS . '; height: ' . $HeightCSS . '\">' . $HtmlValue . '</textarea>' ;
96        }
97
98        $Html .= '</div>' ;
99
100        return $Html ;
101    }
102
103    protected function IsCompatible()
104    {
105        $sAgent = $_SERVER['HTTP_USER_AGENT'] ;
106
107
108        if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false )
109        {
110            $iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ;
111            return ($iVersion >= 5.5) ;
112        }
113        else if ( strpos($sAgent, 'Gecko/') !== false )
114        {
115            $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;
116            return ($iVersion >= 20030210) ;
117        }
118        else if ( strpos($sAgent, 'Opera/') !== false )
119        {
120            $fVersion = (float)substr($sAgent, strpos($sAgent, 'Opera/') + 6, 4) ;
121            return ($fVersion >= 9.5) ;
122        }
123        else if ( preg_match( "|AppleWebKit/(\d+)|i", $sAgent, $matches ) )
124        {
125            $iVersion = $matches[1] ;
126            return ( $matches[1] >= 522 ) ;
127        }
128        else
129        {
130            return false ;
131        }
132    }
133
134    protected function GetConfigFieldString()
135    {
136        $sParams = '' ;
137
138        foreach ( $this->Config as $sKey => $sValue )
139        {
140            if ( $sParams != '' )
141                $sParams .= '&amp;' ;
142
143               
144            $sParams .= urlencode($sKey );
145           
146            if ( $sValue === true )
147            {
148                $sParams .= '=true' ;
149            }elseif ( $sValue === false ){
150                $sParams .= '=false' ;
151            }else{
152                $sParams .= '=' . urlencode( $sValue ) ;
153            }
154        }
155
156        return $sParams ;
157    }
158
159
160}
161
162?>
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy