The FCKeditor module allows Drupal to replace textarea fields with a rich text or WYSIWYG editor. This editor brings many of the powerful functionalities of known desktop editors like Word to the web. It's relatively lightweight and doesn't require any kind of installation on the client computer.
More information is located at the !fckeditorlink. A small user guide is located at !userguidelink.
", array('!fckeditorlink'=>l(t('FCKeditor homepage'), 'http://www.fckeditor.net'), '!userguidelink'=>l(t('FCKeditor userguide'), 'http://wiki.fckeditor.net/UsersGuide'))); $output .= "The FCKeditor module allows Drupal to replace textarea fields with a rich text or WYSIWYG editor. This editor brings many of the powerful functionalities of known desktop editors like Word to the web. It's relatively lightweight and doesn't require any kind of installation on the client computer.
More information is located at the !fckeditorlink. A small user guide is located at !userguidelink.
", array('!fckeditorlink'=>l(t('FCKeditor homepage'), 'http://www.fckeditor.net'), '!userguidelink'=>l(t('FCKeditor userguide'), 'http://wiki.fckeditor.net/UsersGuide'))); $output .= t('For the Rich Text Editing to work you also need to configure your !filterlink for the users that may access Rich Text Editing. Either grant those users Full HTML access or use the following: !filter
. Users that need access to tables might be better of using Full HTML.
-
-
-
'), '!filterlink'=> l(t('filters'),'admin/filters')));
$output .= t('Security
Note that enabling file uploads is a security risk, please take care about to who and when you will grant access.
');
// the rest is untranslated for the moment
$output .= "How to enable the file browser (in FCKeditor 2.3.x)
The editor gives the end user the flexibility to create a custom file browser that can be integrated on it. The included file browser allows users to view the content of a specific directory on the server and add new content to that directory (create folders and upload files).
To enable file browsing you need to edit the connector configuration file in your fckeditor module directory, the file should be in:
/fckeditor/editor/filemanager/browser/default/connectors/php/config.php
In this file you will need to enable the file browser:
$Config['Enabled'] = true;
To use the drupal files directory you also need to comment out the following line in the connector configuration:
//$Config['UserFilesPath'] = '/UserFiles/';
Furthermore, you will need to create a 'File', 'Image', 'Flash' and 'Media' subdirectory in your drupal files directory ('".file_directory_path()."'). These directories must have the same privileges as the drupal files directory. In some cases these directories must be world writable (chmod 0777).
";
break;
}
return $output;
}
/**
* Implementation of hook_perm
*/
function fckeditor_perm() {
return array('use default fckeditor', 'use advanced fckeditor', 'allow fckeditor file uploads');
}
/**
* Implementation of textarea
*/
function fckeditor_elements() {
$type = array();
if (user_access('use advanced fckeditor') || user_access('use default fckeditor')) {
// only roles with permission get the fckeditor
if (fckeditor_is_compatible_client()) {
// it would be useless to dig deeper if we're not able or allowed to
$type['textarea'] = array(
'#process' => array(
'fckeditor_process_textarea' => array()
),
);
}
}
return $type;
}
function fckeditor_menu($may_cache) {
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/fckeditor',
'title' => t('FCKeditor'),
'callback' => 'drupal_get_form',
'callback arguments' => array('fckeditor_settings_form'),
'access' => user_access('administer site configuration'),
'description' => t("Enables the usage of FCKeditor (WYSIWYG editor) instead of plain text fields."),
);
}
return $items;
}
function fckeditor_settings_form() {
// Settings form
$toolbar_options = array(
'Default' => 'Default',
'DrupalFull' => 'Drupal Full',
'DrupalBasic' => 'Drupal Basic',
'Basic' => 'Basic',
);
// Generate the form - settings applying to all patterns first
$form['fckeditor_settings'] = array(
'#type' => 'fieldset',
'#weight' => -20,
'#title' => t('Basic settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['fckeditor_settings']['fckeditor_popup'] = array(
'#type' => 'checkbox',
'#title' => t('Use FCKeditor in a popup window'),
'#default_value' => variable_get('fckeditor_popup', '0'),
'#description' => t('If this option is selected a link to a popup window will be used instead of a textarea replace.'),
);
$form['fckeditor_settings']['fckeditor_default_toolbar'] = array(
'#type' => 'select',
'#title' => t('Default Toolbar'),
'#default_value' => variable_get('fckeditor_default_toolbar', 'DrupalBasic'),
'#options' => $toolbar_options,
'#description' => t('Choose a default toolbar set.'),
);
$form['fckeditor_settings']['fckeditor_advanced_toolbar'] = array(
'#type' => 'select',
'#title' => t('Advanced Toolbar'),
'#default_value' => variable_get('fckeditor_advanced_toolbar', 'DrupalFull'),
'#options' => $toolbar_options,
'#description' => t('Choose a toolbar set for administrators.'),
);
$form['fckeditor_exclude_settings'] = array(
'#type' => 'fieldset',
'#weight' => -15,
'#title' => t('Exclusion settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['fckeditor_exclude_settings']['fckeditor_minimum_rows'] = array(
'#type' => 'textfield',
'#title' => t('Minimum rows'),
'#default_value' => variable_get('fckeditor_minimum_rows', 5),
'#description' => t("Textareas must have a minimum of rows before FCKeditor will be triggered. Enter '1' if you do not want to use this feature."),
);
/**
* get excluded fields - so we can have normal textareas too
* split the phrase by any number of commas or space characters,
* which include " ", \r, \t, \n and \f
*/
$form['fckeditor_exclude_settings']['fckeditor_exclude'] = array(
'#type' => 'textarea',
'#title' => t('Exclude fields'),
'#cols' => 60,
'#rows' => 5,
'#default_value' => variable_get("fckeditor_exclude", ''),
'#description' => t("Names (HTML ID's) of fields that may not have an FCKeditor (separated by commas, spaces or newlines. You may also use * for a wildcard)"),
);
$form['fckeditor_special_settings'] = array(
'#type' => 'fieldset',
'#weight' => -10,
'#title' => t('Advanced settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['fckeditor_special_settings']['fckeditor_toolbar_start_expanded'] = array(
'#type' => 'checkbox',
'#title' => t('Start the toolbar expanded'),
'#default_value' => variable_get('fckeditor_toolbar_start_expanded', '1'),
'#description' => t('The toolbar start expanded or collapsed.'),
);
$form['fckeditor_special_settings']['fckeditor_width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#default_value' => variable_get("fckeditor_width", "100%"),
'#description' => t("Width in pixels or percent. Ex: 400 or 100%"),
);
return system_settings_form($form);
}
/**
* This function create the HTML objects required for the FCKeditor
*
* @param $element
* A fully populated form elment to add the editor to
* @return
* The same $element with extra FCKeditor markup and initialization
*/
function fckeditor_process_textarea($element) {
$exclude = preg_split("/[\s,]+/", strip_tags(variable_get("fckeditor_exclude", '')));
if (($element['#rows'] > variable_get('fckeditor_minimum_rows', 5))
&& !fckeditor_idsearch($element['#id'], $exclude)) {
// only replace textarea when it has enough rows and it is not in the exclusion list
// setting some variables
$module_drupal_path = drupal_get_path('module', 'fckeditor');
$module_full_path = base_path() . $module_drupal_path;
// get the default drupal files path
$files_path = file_directory_path();
// '-' in a javascript id will not work
$js_id = 'oFCKeditor_' . str_replace('-', '_', $element['#id']);
// configured in settings
$width = variable_get("fckeditor_width", '100%');
// sensible default for small toolbars
$height = $element['#rows'] * 14 + 100;
// nessecary because FCKeditor interferes with resize script
$element['#resizable'] = FALSE;
drupal_add_js($module_drupal_path . '/fckeditor/fckeditor.js');
if (user_access('use advanced fckeditor')) {
$toolbar = variable_get("fckeditor_advanced_toolbar", 'DrupalFull');
$height += 100; // sensible default for admin toolbars toolbars
}
else {
$toolbar = variable_get("fckeditor_default_toolbar", 'DrupalBasic');
}
$element['#suffix'] .= "\n\n";
if (variable_get('fckeditor_popup', '0')) {
// Add the script file with the popup open function.
drupal_add_js($module_drupal_path . '/fckeditor.popup.js');
$element['#title'] .= " (" . t('Open rich editor') . ")";
}
else {
// if no popup mode, add the editor
$element['#suffix'] .="\n";
}
}
return $element;
}
/**
* Search the field id for matches in array of matches
*
* @param $search
* A string representing a form field id
* @ param $array
* An $array with strings to match the $search parameter against
*
* @return
* TRUE on match, FALSE on no match
*/
function fckeditor_idsearch($search, $array) {
foreach ($array as $key => $value) {
if (!empty($value) && preg_match('/^'.str_replace('*','.*',$value).'$/i', $search)) {
// on any first match we know we're done here so return positive
return true;
}
}
return false;
}
/**
* Test if client can render the FCKeditor
*
* Check the user agent for a matching browser,
* using HTTP_USER_AGENT because the browsers that are known to support FCKeditor are limited
*
* @return
* TRUE if the browser is reasonably capable
*/
function fckeditor_is_compatible_client() {
$useragent = $_SERVER['HTTP_USER_AGENT'];
if (strpos($useragent, 'MSIE') !== false && strpos($useragent, 'mac') === false && strpos($useragent, 'Opera') === false) {
$browserversion = (int)substr($useragent, strpos($useragent, 'MSIE') + 5, 3);
return ($browserversion >= 5.5);
}
elseif (strpos($useragent, 'Gecko') !== false) {
$browserversion = (int)substr($useragent, strpos($useragent, 'Gecko/') + 6, 8);
return ($browserversion >= 20030210);
}
else
return false;
}