Opened 12 years ago

Closed 10 years ago

#1611 closed New Feature (fixed)

use JS to "detect" browser-JS-capability

Reported by: blueyed@… Owned by:
Priority: Normal Milestone:
Component: Server : PHP Version:
Keywords: HasPatch Cc:

Description

This is the fckeditor.php file as I've also sent it to Frederico.

It obsoletes the isCompatible() method and uses javascript itself to "detect" if it is compatible. Simply by using document.write().

It also detects/converts the Width and Height members better to html attribute values.

It was based on 2.1.

<?php
/*
* FCKeditor - The text editor for internet
* Copyright (C) 2003-2005 Frederico Caldeira Knabben
*
* Licensed under the terms of the GNU Lesser General
Public License:
* http://www.opensource.org/licenses/lgpl-license.php
*
* For further information visit:
* http://www.fckeditor.net/
*
* "Support Open Source software. What about a donation
today?"
*
* File Name: fckeditor.php
* This is the integration file for PHP.
*
* It defines the FCKeditor class that can be used to
create editor
* instances in PHP pages on server side.
*
* File Authors:
* Frederico Caldeira Knabben (fredck@fckeditor.net)
* Daniel HAHLER (https://www.thequod.de/contact)
*/

class FCKeditor
{
var $InstanceName ;
var $BasePath = '/FCKeditor/' ;
var $Width = '100%' ;
var $Height = '200px' ;
var $ToolbarSet = 'Default' ;
var $Value = '' ;
var $Config = array();
/**
* @var int The number of rows for the textarea
element (used as non-JS-fallback).
*/
var $TextareaRows = 8;
/**
* @var int The number of cols for the textarea
element (used as non-JS-fallback).
*/
var $TextareaCols = 40;


// PHP 5 Constructor (by Marcus Bointon
<coolbru@users.sourceforge.net>)
function __construct( $instanceName )
{
$this->InstanceName = $instanceName ;
$this->BasePath = '/FCKeditor/' ;
$this->Width = '100%' ;
$this->Height = '200' ;
$this->ToolbarSet = 'Default' ;
$this->Value = '' ;

$this->Config = array() ;
}

// PHP 4 Contructor
function FCKeditor( $instanceName )
{
$this->__construct( $instanceName ) ;
}


function Create()
{
echo $this->CreateHtml() ;
}


/**
* Create the HTML that will either display the input-
and iframe-elements or
* a simple textarea for non-Javascript browsers.
*
* Javascript-"detection" is done by using JS to write
the inputs/iframe for
* FCKeditor and putting the textarea tag into the
following noscript tag.
*
* @return string
*/
function CreateHtml()
{
$HtmlValue = htmlspecialchars( $this->Value ) ;

if ( isset( $_GET['fcksource'] ) &&
$_GET['fcksource'] == "true" )
$File = 'fckeditor.original.html' ;
else
$File = 'fckeditor.html' ;
$Link =
"{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}"
;

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

// Set width and height for textarea (fallback)
if ( is_numeric( $this->Width ) )
$WidthCSS = $this->Width . 'px' ;
else
$WidthCSS = $this->Width ;

if ( is_numeric( $this->Height ) )
$HeightCSS = $this->Height . 'px' ;
else
$HeightCSS = $this->Height ;


$Html = '<div>' ;

// The Javascript part
$Html .= '<script type="text/javascript">'
// Render the linked hidden field.
.'document.write( \'<input type="hidden"
id="'.$this->InstanceName.'"
name="'.$this->InstanceName.'" value="'
.preg_replace( array( '#\r?\n#', "#'#" ),
array( '\\n', "\'" ),
$HtmlValue )
.'" />'
// Render the configurations hidden field.
.'<input type="hidden"
id="'.$this->InstanceName.'___Config"
value="'.$this->GetConfigFieldString().'" />'
// Render the editor IFRAME.
.'<iframe id="'.$this->InstanceName.'___Frame"
src="'.$Link.'" width="'.$this->Width.'"
height="'.$this->Height.'" frameborder="no"
scrolling="no">'
.'<\/iframe>'
."' );</script>";

// Render the textarea for non-Javascript
$Html .= "<noscript><textarea
name=\"{$this->InstanceName}\"
rows=\"{$this->TextareaRows}\"
cols=\"{$this->TextareaCols}\" style=\"width:
{$WidthCSS}; height: {$HeightCSS}\"
wrap=\"virtual\">{$HtmlValue}</textarea></noscript>" ;

$Html .= '</div>' ;

return $Html ;
}


function GetConfigFieldString()
{
$sParams = '' ;
$bFirst = true ;

foreach ( $this->Config as $sKey => $sValue )
{
if ( $bFirst == false )
$sParams .= '&amp;' ;
else
$bFirst = false ;

if ( $sValue === true )
$sParams .= $this->EncodeConfig( $sKey ) . '=true' ;
else if ( $sValue === false )
$sParams .= $this->EncodeConfig( $sKey ) . '=false' ;
else
$sParams .= $this->EncodeConfig( $sKey ) . '=' .
$this->EncodeConfig( $sValue ) ;
}

return $sParams ;
}


function EncodeConfig( $valueToEncode )
{
$chars = array(
'&' => '%26',
'=' => '%3D',
'"' => '%22' ) ;

return strtr( $valueToEncode, $chars ) ;
}
}

?>

Moved from http://sourceforge.net/tracker/index.php?func=detail&aid=1333904&group_id=75348&atid=543655

Note, newlines and tabs have been destroyed by SourceForge, I have't tried to recreate them.

Change History (2)

comment:1 Changed 12 years ago by Alfonso Martínez de Lizarrondo

Reporter: changed from Alfonso Martínez de Lizarrondo to blueyed@…

comment:2 Changed 10 years ago by Alfonso Martínez de Lizarrondo

Resolution: fixed
Status: newclosed

This is working in CKEditor

Note: See TracTickets for help on using tickets.
© 2003 – 2019 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy