CKEditor Class Reference

CKEditor class that can be used to create editor instances in PHP pages on server side. More...

Public Member Functions

 __construct ($basePath=null)
 editor ($name, $value="", $config=array(), $events=array())
 replace ($id, $config=array(), $events=array())
 replaceAll ($className=null)
 addEventHandler ($event, $javascriptCode)
 clearEventHandlers ($event=null)
 addGlobalEventHandler ($event, $javascriptCode)
 clearGlobalEventHandlers ($event=null)

Data Fields

const version = '%VERSION%'
const timestamp = '%TIMESTAMP%'
 $basePath
 $config = array()
 $initialized = false
 $returnOutput = false
 $textareaAttributes = array( "rows" => 8, "cols" => 60 )
 $timestamp = "%TIMESTAMP%"

Detailed Description

CKEditor class that can be used to create editor instances in PHP pages on server side.

See also:
http://ckeditor.com

Sample usage:

 $CKEditor = new CKEditor();
 $CKEditor->editor("editor1", "<p>Initial value.</p>");

Constructor & Destructor Documentation

__construct ( basePath = null  ) 

Main Constructor.

Parameters:
$basePath (string) URL to the CKEditor installation directory (optional).

Member Function Documentation

addEventHandler ( event,
javascriptCode 
)

Adds event listener. Events are fired by CKEditor in various situations.

Parameters:
$event (string) Event name.
$javascriptCode (string) Javascript anonymous function or function name.

Example usage:

 $CKEditor->addEventHandler('instanceReady', 'function (ev) {
     alert("Loaded: " + ev.editor.name);
 }');
addGlobalEventHandler ( event,
javascriptCode 
)

Adds global event listener.

Parameters:
$event (string) Event name.
$javascriptCode (string) Javascript anonymous function or function name.

Example usage:

 $CKEditor->addGlobalEventHandler('dialogDefinition', 'function (ev) {
     alert("Loading dialog: " + ev.data.name);
 }');
clearEventHandlers ( event = null  ) 

Clear registered event handlers. Note: this function will have no effect on already created editor instances.

Parameters:
$event (string) Event name, if not set all event handlers will be removed (optional).
clearGlobalEventHandlers ( event = null  ) 

Clear registered global event handlers. Note: this function will have no effect if the event handler has been already printed/returned.

Parameters:
$event (string) Event name, if not set all event handlers will be removed (optional).
editor ( name,
value = "",
config = array(),
events = array() 
)

Creates a CKEditor instance. In incompatible browsers CKEditor will downgrade to plain HTML <textarea> element.

Parameters:
$name (string) Name of the CKEditor instance (this will be also the "name" attribute of textarea element).
$value (string) Initial value (optional).
$config (array) The specific configurations to apply to this editor instance (optional).
$events (array) Event listeners for this editor instance (optional).

Example usage:

 $CKEditor = new CKEditor();
 $CKEditor->editor("field1", "<p>Initial value.</p>");

Advanced example:

 $CKEditor = new CKEditor();
 $config = array();
 $config['toolbar'] = array(
     array( 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike' ),
     array( 'Image', 'Link', 'Unlink', 'Anchor' )
 );
 $events['instanceReady'] = 'function (ev) {
     alert("Loaded: " + ev.editor.name);
 }';
 $CKEditor->editor("field1", "<p>Initial value.</p>", $config, $events);
replace ( id,
config = array(),
events = array() 
)

Replaces a <textarea> with a CKEditor instance.

Parameters:
$id (string) The id or name of textarea element.
$config (array) The specific configurations to apply to this editor instance (optional).
$events (array) Event listeners for this editor instance (optional).

Example 1: adding CKEditor to <textarea name="article"></textarea> element:

 $CKEditor = new CKEditor();
 $CKEditor->replace("article");
replaceAll ( className = null  ) 

Replace all <textarea> elements available in the document with editor instances.

Parameters:
$className (string) If set, replace all textareas with class className in the page.

Example 1: replace all <textarea> elements in the page.

 $CKEditor = new CKEditor();
 $CKEditor->replaceAll();

Example 2: replace all <textarea class="myClassName"> elements in the page.

 $CKEditor = new CKEditor();
 $CKEditor->replaceAll( 'myClassName' );

Field Documentation

$basePath

URL to the CKEditor installation directory (absolute or relative to document root). If not set, CKEditor will try to guess it's path.

Example usage:

 $CKEditor->basePath = '/ckeditor/';
$config = array()

An array that holds the global CKEditor configuration. For the list of available options, see http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html

Example usage:

 $CKEditor->config['height'] = 400;
 // Use @@ at the beggining of a string to ouput it without surrounding quotes.
 $CKEditor->config['width'] = '@@screen.width * 0.8';
$initialized = false

A boolean variable indicating whether CKEditor has been initialized. Set it to true only if you have already included <script> tag loading ckeditor.js in your website.

$returnOutput = false

Boolean variable indicating whether created code should be printed out or returned by a function.

Example 1: get the code creating CKEditor instance and print it on a page with the "echo" function.

 $CKEditor = new CKEditor();
 $CKEditor->returnOutput = true;
 $code = $CKEditor->editor("editor1", "<p>Initial value.</p>");
 echo "<p>Editor 1:</p>";
 echo $code;
$textareaAttributes = array( "rows" => 8, "cols" => 60 )

An array with textarea attributes.

When CKEditor is created with the editor() method, a HTML <textarea> element is created, it will be displayed to anyone with JavaScript disabled or with incompatible browser.

$timestamp = "%TIMESTAMP%"

A string indicating the creation date of CKEditor. Do not change it unless you want to force browsers to not use previously cached version of CKEditor.

const timestamp = '%TIMESTAMP%'

A constant string unique for each release of CKEditor.

const version = '%VERSION%'

The version of CKEditor.

Copyright © 2003-2009, CKSource - Frederico Knabben. All rights reserved.