Rich Editor Documentation

Date: 13 april 2005, Version: 2.0


Table of Contents

1. About the Rich Editor
2. Features
General
Text
Tables
Image&Flash
Forms
Languages supported
3. Requirements
4. Installation&Using
Settings
Settings API
Simple mode
Active mode
XHTML mode
Default stylesheets
Snippets
Language
Borders visibility
On Enter Key press behaviour
Font and font size lists
Save button
Javascript API
5. Examples
6. License


1. About the Rich Editor

Rich Editor (RE) is a browser-based online WYSIWYG html editor. The editor is to be used in content management systems or just instead of <TEXTAREA> tags in forms to create/edit html formatted text and whole html pages.

100% script (javascript and php). Easy to install. No additional Java Applets or ActiveX components are required! Works with Internet Explorer 5.x+ (Windows only), Netscape 7.1 / Mozilla 1.4+. MSIE 6.x is recommended. Implemented as a PHP class. Multiple instances of RE on the same page are supported. Generates source code in common HTML and XHTML 1.0 format.

No knowledge of HTML required. Advanced work with images, including file uploading, tables, links, stylesheets, flash and more!

Active and simple modes of the editor. Adjustable toolbar. Works with server-side files and folders. Colored source code. Multilingual support. And more!


2. Features

General

Text

Tables

Image&Flash

Note: if you do not see local flash preview, please, install the latest version of flash player from macromedia.com.

MSIE 6.0 is recommended!

Forms

Languages supported


3. Requirements


4. Installation&Using

You must have possibility to run PHP scripts inside your files and rights to write in your directories at server!

  1. Copy directory 'class' on server. There must be access to this directory through an URL.
  2. Add at the top of file, where you want RE to be used, code of the form:
  3. <?php
    	$class_path = "path to 'class' folder";
    	require_once($class_path."class.rich.php");
    ?>
    
    Here
    "path to 'class' folder" is a string with path to folder 'class', where RE files are, e.g. "class/", if your script and this folder are in the same folder. The path should be relative to current folder of your script using RE

    Alternative method

    <?php
    	$class_path = "path to 'class' folder relative to site root";
    	require_once($path_to_class_folder."class.rich.php");
    ?>
    
    Here
    "path to 'class' folder relative to site root" is a string with path to folder 'class' relative to site root, eg '/re/class/' for folder 'http://www.yourdomain.com/re/class/'
    "path_to_class_folder is a server side path to folder 'class' (could be set eg to $_SERVER['DOCUMENT_ROOT'].$class_path to be independent of where your script using RE is placed:
    <?php
    	$class_path = "/re/class/";
    	require_once($_SERVER['DOCUMENT_ROOT'].$class_path."class.rich.php");
    ?>
    
    In this case you do not need to change these settings even if you move the file using RE to another folder of your site

    No global variables method

    To avoid using of global variable $class_path it is possible to use function

    	$editor->set_class_path($class_path);
    
    where $class_path is path to folder 'class'

    Such approach is necessary when you have to create editor's instances inside your own functions where global variables are not seen. In case when this function is not used to set path to folder 'class' the editor will use global variable $class_path

    Note: variable $editor must be declared yet and function set_class_path must be called before methods get_rich() or draw()

  4. Insert the following two strings inside tag <HEAD>:
  5. <link rel="StyleSheet" type="text/css" href="<?php echo $class_path; ?>rich_files/rich<?php echo $rich_prefix; ?>.css">
    <script language="JavaScript" src="<?php echo $class_path; ?>rich_files/rich<?php echo $rich_prefix; ?>.js"></script>
    <script language="JavaScript" src="<?php echo $class_path; ?>rich_files/rich_xhtml.js"></script>
    

    Note: the last line could be omitted if you do not use XHTML mode.

    Also it is possible to insert the code using the following function:

    	echo rich_get_head_code($class_path);
    
    where $class_path is path to folder 'class'

    or method

    	echo $editor->get_head_code();
    

    Note: In this case variable $editor must be declared yet

  6. Code to create RE instance is of the form:
  7. <?php
    	$editor = new rich($caption, $name, $value, $width, $height, $files_path,
    			$files_url, $page_mode, $absolute_path);
    	$editor->draw(); // or echo $editor->get_rich();
    ?>
    
    Here
    $caption is a string, appearing before RE in page (caption of editor),
    $name is name of the textarea element, which is used to send edited text through forms (must be unique, if you create several editors),
    $value is a string with initial content of the editor (can be empty),
    $width is width of the editor (can be in absolute values or in %s),
    $height is height of the editor (can be in absolute values or in %s),
    $files_path is a string with path to top directory for uploaded files relative to site root, eg '/files/', or to folder 'class', eg '../files/' (useful if you use aliases)
    $files_url is string with url to top directory (directory $files_path) for uploaded files,
    $page_mode - set it to true to edit the whole pages, otherwise can be omitted.
    $absolute_path - set it to true to refer to files at server through absolute paths (default), otherwise -- through relative (to site root) paths.

    Note: if $absolute_path is set to false, $files_url should specify url to folder for uploading relative to site root. I.e. if folder for uploading is 'http://www.yoursite.com/files/upload/', this variable should be set to '/files/upload/'. In this case, all urls in content will not depend on name of site domain. Value of $files_path does not depend on the mode used.

  8. Add 'save_in_textarea_all' function to onsubmit event handler, e.g:
  9. <form action="" method="post" onsubmit="save_in_textarea_all();">
    
Contents of RE editors can be accessed in scripts after submitting forms containing them by names, pointed in corresponding variables $name.

RE appears on page in the place, where method draw() is called. Also you can use get_rich() method to get code of the editor and then output it to a variable or to browser. It could be useful if you are going to use the editor with a template engine.

Settings

File check_auth.inc.php contains variables that could be used to restrict user actions such as uploading, creating new folders, renaming of deleting files and folders. Also it is possible to specify file extensions available for files uploaded, to restrict size of files uploaded or the total size of folder for the files.

VARIABLE DESCRIPTION EXAMPLE
Common settings
$re_set_avail_paths
All actions are available within the paths specified only. Eg. all actions could be produced only in these folders or in their subfolders
All paths are available if this array is empty
$re_set_avail_paths = array('/files/uploaded/', '/files/shared/');
 
Available paths: '/files/uploaded/', '/files/uploaded/images/', '/files/shared/'
Unavailable paths: '/files/', '/files/private/'

$re_set_avail_paths = array('../user_files/john/');
 
Available paths: '../user_files/john/', '../user_files/john/images/'
Unavailable paths: '../admin_files/', '../user_files/steve/'

$re_set_total_size
Defines max size (in bytes) available for all files in folder for uploading. Uploading refused if total size of all files including uploaded will exceed the limit
No restriction if set to 0
$re_set_total_size = 1024*1024;
 
The total size of all files uploaded must be 1Mb or less
Uploading settings
$re_set_can_upload
User is permitted to upload files on server if the variable set to true.
The rest of uploading settings is applied if this one set to true only
$re_set_can_upload = true;
Uploading is permitted
$re_set_max_size
Set max size (in bytes) of uploaded file available (-1 if no restriction necessary)
$re_set_max_size = 1024*1024;
 
Attempts to upload files with size exceeding 1Mb will be refused
$re_set_allow_override
Set permission to upload if file with the same name exists yet
$re_set_allow_override = true;
 
Files uploaded will override existing files
$re_set_avail_files
Specifies file extensions available for uploading and renaming (all extensions if not set)
$re_set_avail_files = array ('zip', 'txt');
 
Only zip and txt files are available for upload
$re_set_not_avail_files
Specifies file extensions not available for uploading and renaming (no restriction if not set)
Has higher priority then $re_set_avail_files!
The settings is applied to all files except images
$re_set_not_avail_files = array ('php', 'pl');
 
Attempts to upload php and pl files will be refused
$re_set_avail_images
Specifies image types available for uploading (all types if not set)
Possible values: 'jpg', 'gif', 'png', 'bmp' (the list could be extended)
NOTE! There are not restrictions for extensions of image files!
$re_set_avail_images = array ('jpg' 'png');
 
Only jpg and png images are available for upload
$re_set_not_avail_images
Specifies image types not available for uploading (no restriction if not set)
Possible values: 'jpg', 'gif', 'png', 'bmp' (the list could be extended)
Has higher priority then $re_set_avail_images!
NOTE! There are not restrictions for extensions of image files!
$re_set_not_avail_images = array ('gif');
 
Attempts to upload gif images will be refused
$re_set_max_image_size
Max size of images available for uploading.
Set as an array(width, height) (0s if no restrictions)
$re_set_max_image_size = array(100, 100);
 
Size of images uploaded must be 100x100 or smaller
$re_set_max_flash_size
Max size of flashes available for uploading.
Set as an array(width, height) (0s if no restrictions)
$re_set_max_flash_size = array(100, 100);
 
Size of flash files uploaded must be 100x100 or smaller
File browser settings
$re_set_can_create_dir
Set permission to create folders
$re_set_can_create_dir = false;
 
User is not available to create folders
$re_set_can_rename_dir
Set permission to rename folders
$re_set_can_rename_dir = false;
 
User is not available to rename folders
$re_set_can_delete_dir
Set permission to delete folders
Only empty folders could be deleted
$re_set_can_delete_dir = true;
 
User is available to delete folders
$re_set_can_rename_file
Set permission to rename files
$re_set_can_rename_file = true;
 
User is available to rename files
$re_set_can_delete_file
Set permission to delete files
$re_set_can_delete_file = true;
 
User is available to delete files

Settings API

It is possible to set values for all settings defined in file check_auth.inc.php through API functions. These functions use session technique, so sessions should be set correctly on your server. Cookies support in cliens' browsers are not required.

To use the functions you should uncomment the following line in check_auth.inc.php:

start_session();

Or you can uncomment it for all cases if you always use sessions

This line initially commented as sessions are not required by RE, but if sessions are not configured correctly on your server a warning will be printed by PHP every time session_start() is called

  Function list

To change settings to its default values defined in check_auth.inc.php call the appropriate functions without arquments, eg. $editor->set_allow_override();

Simple mode

To handle RE Simple mode add a sring of the form

	$editor->simple_mode($mode);
before draw() method call.
If $mode is true or omitted, the simple mode is on, otherwise -- off.

To hide some buttons use the method

	$editor->hide_tb($item, $mode);
before draw() method call.

Here

$item is a string defining a button (or a group of buttons) to be hidden/shown,
$mode -- set it to true to hide buttons, defined by $item, or can be omitted, if set to false the $item buttons are shown at RE toolbar.

Using the hide_tb() function it is possible to hide some buttons of RE toolbar. Besides it, you can set up your own "simple mode" adding or deleting the function calls inside simple_mode() function.

The possible values of $item:

'fullscreen' -- fullscreen mode button;
'preview' -- preview button;
'find' -- find&replace button;
'clipboard' -- cut, copy and paste buttons;
'history' -- undo and redo buttons;
'text' -- bold, italic, underline, strikesrough, superscript and subscript buttons;
'align' -- align left, center, right and justify buttons;
'list' -- ordered and unordered list buttons;
'indent' -- indent and outdent buttons;
'hr' -- horizontal line buttons;
'remove_format' -- remove formatting button;
'table' -- create table, insert/delete row, insert/delete column buttons;
'adv_table' -- insert/delete cell, merge cells, split cell buttons (shown only if 'table' buttons are not hidden);
'paragraph' -- paragraph select;
'font' -- font select;
'style' -- stylesheet class select;
'size', -- font size select;
'color',-- forecolor and backcolor buttons;
'image' -- create image button;
'flash' -- create flash button;
'link' -- create hyperlink button;
'paste_word' -- paste text from MS Word button;
'switch_borders' -- show invisible table borders button;
'special_chars' -- insert special char button;
'form' -- form elements' buttons;
'snippets' -- insert custom html code button;
'absolute_position' -- absolute positioning button;
'page_properties' -- page properties button
'help' -- help button

Active mode

In this mode buttons pressing on which will take no effect become inactive.

To handle RE Active mode add a sring of the form

	$editor->active_mode($mode);
before draw() method call.
If $mode is true or omitted the active mode is on, otherwise -- off.

XHTML mode

In XHTML mode editor generates source code in XHTML 1.0 format instead of common HTML.

To handle RE XHTML mode add a sring of the form

	$editor->xhtml_mode($mode);
before draw() method call.
If $mode is true or omitted the xhtml mode is on, otherwise -- off.

Language and Charset settings

In XHTML mode you can specify language and charset for RE document.

Note: these settings are necessary in page mode only (whole pages editing mode).

To change document language/charset settings use the following funcions:
	//set document language
	function set_doc_lang($lang);

	//set document charset
	function set_doc_charset($cs);

Here

$lang is string specifying language of the document ('en' -- default),
$cs is charset of the document ('iso-8859-1' -- default)

Note: if the language/charset settings are not spesified, the current language of RE toolbar and charset of the corresponding language file is used;

Default stylesheets

To set default stylesheet files use the following function:

	$editor->set_default_stylesheet($style_path);
before draw() method call.

Here

$style_path is a path to stylesheet file (or array of such paths) from the dir where script creating the editor is

Snippets

To define html snippets for the editor use the following function:

	$editor->set_snippets($snippets, $group);
before draw() method call.

Here

$snippets is an array (or array of such arrays) of the form
	array('name' => 'name of the snippet', 'code' => 'code of the snippet')
$group is name of a snippet group that these snippets should to be placed in (could be omitted)

HTML tags are available inside html snippets

Language

To set a desired language use the following function:

	$editor->set_lang($lang);
before draw() method call

Here

$lang is code of the language

Supported languages (language codes):

To add a new language to the editor, create files 'rich_lang_{code}.inc.php' and 'help_{code}.php' with texts in this language and copy them in folder 'lang'. Here, {code} is a code of the new language.

The new language will be available by the code {code} in set_lang() method

Borders visibility

To make borders visible by default call the function

	$editor->set_borders_visibility($set_on);
before draw() method call

Here

$set_on should be set to true or omitted to make borders visible by default

On Enter Key press behaviour

By default <br> tag is inserted on Enter Key press. To insert <p> tag use Shift-Enter instead.
To change this behaviour call function
	$editor->set_br_on_enter($set_on);
before draw() method call

Here

$set_on should be set to true or omitted to make RE handle Enter Key press as described above; otherwise Enter Key press inserts <p> tag and Shift-Enter inserts <br>

Font and font size lists

To specify your own list of fonts and font sizes use the following functions:

	$editor->set_font_list($font_data);
	$editor->set_font_size_list($font_data);
before draw() method call.

Here

$font_data is name of font/font size (or array of such values)

Save button

To use a toolbar button to submit form with Rich Editor instead of clicking on form submit button the following code should be used:

	//make the button visible
	$editor->hide_tb('save', false);
	//define reaction on the button click
	$editor->set_on_save_handler($code);
before draw() method call

Here

$code is code to be performed on the button click
E.g. to submit form with id "form_id" set $code to string 'document.getElementById("form_id").submit()'

Note: If you use the save button to submit form data, it is not necessary to add function save_in_textarea_all() to onsubmit form attribute

Javascript API

To get content of an editor from javascript use the following function:

	var editor_content = get_rich(editor_name);

Here

editor_name is a name of the desired editor. Eg. for all examples from section 'Examples' of the document this variable should be set to string 'rich_name'
Javascript variable editor_content will be set to the content of the editor instance named 'rich_name'

To set new content to an editor from javascript use the following function:

	var result = set_rich(editor_name, content);

Here

editor_name is name of the desired editor. Eg. for all examples from section 'Examples' of the document this variable should be set to string 'rich_name'
content is a variable specifying content to be set
Javascript variable result is set to true if content was changed successfully and to false otherwise


5. Examples

Note: full description of RE installation and using see in INSTALLATION&USING section and in file example.php. This is examples of RE php class using only.

Example1. Default mode

	$editor = new rich('Example #1', 'rich_name', 'initial_content',
		'100%', '100%', '/files/', 'http://www.yourdomain.com/files/');
	$editor->draw(); // or echo $editor->get_rich();

Example2. Active mode

	$editor = new rich('Example #2', 'rich_name', 'initial_content',
		500, 500, '/files/', 'http://www.yourdomain.com/files/');

	$editor->active_mode();

	$editor->draw(); // or echo $editor->get_rich();

Example3. Simple mode

	$editor = new rich('Example #3', 'rich_name', 'initial_content',
		'100%', 300, '/files/', 'http://www.yourdomain.com/files/');

	$editor->simple_mode();

	$editor->draw();

Example4. Adjustable toolbar (turn off image and table buttons)

	$editor = new rich('Example #4', 'rich_name', 'initial_content',
		500, '80%', '/files/', 'http://www.yourdomain.com/files/');

	$editor->hide_tb('image');
	$editor->hide_tb('table');

	$editor->draw(); // or echo $editor->get_rich();

Example5. Default stylesheets

	$editor = new rich('Example #5', 'rich_name', 'initial_content',
		'100%', '100%', '/files/', 'http://www.yourdomain.com/files/');

	//to load style1.css and style2.css you can write

	$editor->set_default_stylesheet('style1.css');
	$editor->set_default_stylesheet('style2.css');

	/*or (the same result)

	$editor->set_default_stylesheet(array('style1.css','style2.css'));

	*/

	$editor->draw(); // or echo $editor->get_rich();

Example6. Snippets

	$editor = new rich('Example #6', 'rich_name', 'initial_content',
		500, 500, '/files/', 'http://www.yourdomain.com/files/');

	$snippets = array();
	$snippets[] = array('name'=>'Snippet 1 name', 'code'=>'Snippet 1 code');
	$snippets[] = array('name'=>'Snippet 2 name', 'code'=>'Snippet 2 code');
	$editor->set_snippets($snippets);

	$editor->draw(); // or echo $editor->get_rich();

Example7. Relative paths

	$editor = new rich('Example #7', 'rich_name', 'initial_content',
		500, 500, '/files/', '/files/', false, false);

	$editor->draw(); // or echo $editor->get_rich();

Example8. Language

	$editor = new rich('Example #8', 'rich_name', 'initial_content',
		'100%', 400, '/files/', '/files/', true, false);

	$editor->set_lang('ru'); //set language of toolbar and dialogs to russian

	$editor->draw(); // or echo $editor->get_rich();

Example9. XHTML mode

	$editor = new rich('Example #9', 'rich_name', 'initial_content',
		'800', 400, '/files/', '/files/', false, true);

	$editor->xhtml_mode(); //generate code in XHTML 1.0 format
	$editor->set_doc_lang('de'); //set language of document to german
	$editor->set_doc_charset('iso-8859-1'); //set charset to iso-8859-1

	$editor->draw(); // or echo $editor->get_rich();

Example10. User-specified lists of fonts and font sizes

	$editor = new rich('Example #10', 'rich_name', 'initial_content',
		'100%', 600, '/files/', '/files/');

	$editor->set_font_list(array('Arial', 'Times New Roman'));
	$editor->set_font_size_list('3');
	$editor->set_font_size_list('4');

	$editor->draw(); // or echo $editor->get_rich();


6. License

Software License Agreement

RICH EDITOR AND ANY DOCUMENTATION PROVIDED TO YOU (COLLECTIVELY THE "SOFTWARE" OR "RE") COVERED BY THIS AGREEMENT IS COPYRIGHTED AND IS LICENSED, NOT SOLD. BY TAKING POSSESSION OF THE SOFTWARE, YOU AND YOUR COMPANY (COLLECTIVELY "YOU") ARE ACCEPTING AND AGREEING TO THE TERMS OF THIS LICENSE AGREEMENT

1. All copyrights to RE are exclusively owned by the author - Vyacheslav Smolin.

2. You agree to take reasonable steps to keep in confidence and protect the software provided to you from unauthorized copying or use. These steps include, without limitation, obtaining the agreement of all persons having access to the Software that they will respect the terms of this License and using the Software in such a way as to prevent unauthorized copying.

3. There are 3 basic types of licenses issued for the Software, these are:
  a.  General license. You may not use the Software to create content for third parties, or that will be linked to or framed by other web sites related to you in any way, including without limitation third parties' web sites created by you unless third parties have a separate license for the Software. You may not use the Software in your commercial products.
  b.  Commercial license. You may use the Software to create content for third parties. You may use the Software in your commercial product. In this case you must provide obtaining the agreement of all third parties and your customers having access to the Software that they will respect the terms of this license and use the Software in such a way as to prevent unauthorized copying. You may include the Software as a part of only one commercial product. Number of copies of the product is not limited.
  c.  Rebrandable license. You may use the Software to create content for third parties. You may use the Software in your commercial products. In this case you must provide obtaining the agreement of all third parties and your customers having access to the Software that they will respect the terms of this license and use the Software in such a way as to prevent unauthorized copying. Number of products is not limited.

Once you paid a license fee, you are granted a non-exclusive right to use the Software only as authorized in this license. Number of servers and domains are not limited. All payments are non refundable. You may assign your right to use the Software to a third party provided that you cease using your licensed copy of the Software and the content produced by it.

4. THE SOFTWARE IS DISTRIBUTED "AS IS". NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED. YOU USE IT AT YOUR OWN RISK. NEITHER THE AUTHOR NOR THE AGENTS OF THE AUTHOR WILL BE LIABLE FOR DATA LOSS, DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS SOFTWARE.

5. You may not sub-license, share, rent, or lease your right to use the Software. You also agree not to create derivative works of the Software for any reason. Any unauthorized use shall result in immediate and automatic termination of this license and may result in criminal and/or civil prosecution.

6. All copyright notices used throughout the Software, within the scripts and within the HTML that the scripts generate, must remain intact.

7. Installing and using the Software signifies acceptance of terms and conditions of the license.


Copyright © 2002-2005 by Vyacheslav Smolin. All rights reserved. Top of the document Table of contents