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')) ); break; case 'admin/help#fckeditor': $output = t("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('Go to the !fckeditorlink and download the latest version. Then uncompress the contents of the "fckeditor" directory of the download file to %fckeditordir.
', array( '!fckeditorlink' => l(t('FCKeditor homepage'), 'http://www.fckeditor.net'), '%fckeditordir' => base_path() . drupal_get_path('module', 'fckeditor') .'/fckeditor/') ); $output .= t('If your FCKeditor does not show you must check if all files are extracted correctly. The directory %fckeditordir should have the following files fckeditor.js, fckconfig.js, fckstyles.xml, fcktemplates.xml
and a directory named editor
.
!filter
. Users that need access to tables might be better of using Full HTML. -
-
-
'),
'!filterlink'=> l(t('filters'), 'admin/settings/filters'))
);
$output .= t('Uploading images and files
There are three ways of uploading files: By using the built-in file browser, by using a module like !imce or using the core upload module.
',
array(
'!imce' => l(t('IMCE'), 'http://drupal.org/project/imce')
)
);
$output .= t('Security
Note that enabling file uploads is a security risk. That\'s why there is a
separate permission in Administer > User Management > Access Control for enabling the file
browser to certain groups.
');
// 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:
". base_path() . drupal_get_path('module', 'fckeditor') ."/fckeditor/editor/filemanager/browser/default/connectors/php/config.php
and ". base_path() . drupal_get_path('module', 'fckeditor') ."/fckeditor/editor/filemanager/upload/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 remove or comment out the following line in the connector configuration:
$Config['UserFilesPath'] = '/UserFiles/';
You may also edit this line to reflect a custom upload path.
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() {
// do a quick check for existence of needed fckeditor files
$module_drupal_path = drupal_get_path('module', 'fckeditor');
$fckconfig_file = $module_drupal_path . '/fckeditor/fckconfig.js';
if (!file_exists($fckconfig_file)) {
drupal_set_message(t('checking for %filename', array('%filename' => $fckconfig_file)));
drupal_set_message(
t('The FCKeditor component is not installed correctly. Please go to the !fckeditorlink to download the latest version. After that you must extract the files to %modulepath and make sure that the directory %modulesubdir and the file %modulefile exist. Refer to the !readme for more information.',
array(
'!fckeditorlink'=>l(t('FCKeditor homepage'), 'http://www.fckeditor.net'),
'!readme' => l('readme.txt', 'admin/help/fckeditor'),
'%modulepath' => base_path() . $module_drupal_path .'/fckeditor/',
'%modulesubdir' => base_path() . $module_drupal_path .'/fckeditor/editor',
'%modulefile' => base_path() . $module_drupal_path .'/fckeditor/fckeditor.js')),
'error');
return false;
}
// 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 for users with "use default fckeditor" permission..'),
);
$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 users with "use advanced fckeditor" permission.'),
);
$form['fckeditor_exclude_settings'] = array(
'#type' => 'fieldset',
'#weight' => -15,
'#title' => t('Visibility settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['fckeditor_exclude_settings']['fckeditor_minimum_rows'] = array(
'#type' => 'textfield',
'#title' => t('Minimum rows'),
'#default_value' => variable_get('fckeditor_minimum_rows', 5),
'#description' => t("FCKeditor will be triggered if the textarea has more rows than entered here. Enter '1' if you do not want to use this feature."),
);
$form['fckeditor_exclude_settings']['fckeditor_exclude_toggle'] = array(
'#type' => 'radios',
'#title' => t('Use inclusion or exclusion mode'),
'#default_value' => variable_get('fckeditor_exclude_toggle', '0'),
'#options' => array(
'0' => t('Exclude fields, will disable the editor on all selected fields'),
'1' => t('Include fields, will only load the editor for the selected fields'),
'2' => t('Exclude paths, will disable the editor for all textareas at the configured paths'),
'3' => t('Include paths, will load the editor for all large enough textareas at the configured paths.')),
'#description' => t('Choose what to do with the following values.'),
);
/**
* 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('Selected fields or paths'),
'#cols' => 60,
'#rows' => 5,
'#default_value' => variable_get("fckeditor_exclude", ''),
'#description' => t("Enter fieldnames or drupal paths here, depending on the chosen option for the inclusion mode.
Names (HTML ID's) of fields that may or may not have an FCKeditor.
Paths may be used the same way as in the drupal blocks configuration.
You may separate the different entries by commas, spaces or newlines. You may also use * as a wildcard character.
You can not mix paths and ID's."),
);
$form['fckeditor_special_settings'] = array(
'#type' => 'fieldset',
'#weight' => -10,
'#title' => t('Advanced settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$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%"),
);
$form['fckeditor_special_settings']['fckeditor_stylesheet'] = array(
'#type' => 'textfield',
'#title' => t('Custom stylesheet'),
'#default_value' => variable_get("fckeditor_stylesheet", ""),
'#description' => t("If you enter a path to a stylesheet here it will be used in the FCKeditor area while editing. Be advised that using the default theme stylesheet will not give the correct results."),
);
// don't show useless options if IMCE is preferred
if (function_exists('imce_integrate') && variable_get('imce_settings_fck', 0)) {
$form['fckeditor_upload_settings'] = array(
'#type' => 'fieldset',
'#weight' => -5,
'#title' => t('File browser settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#description' => t('The file browser settings are not diplayed because you have configured IMCE to handle file browsing.')
);
}
else {
$form['fckeditor_upload_settings'] = array(
'#type' => 'fieldset',
'#weight' => -5,
'#title' => t('File browser settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#description' => t('Set file browser settings. If you choose none of these you will need to manage your images and other files with the core upload module or a contrib module like !imce. Please note that these options require manual configuration, check !readme for more information.
Also remember to change the !permissions.',
array(
'!imce' => l(t('IMCE'), 'http://drupal.org/project/imce'),
'!readme' => l('readme.txt', 'admin/help/fckeditor'),
'!permissions' => l('FCKeditor permissions', 'admin/user/access',
array(), null, 'module-fckeditor'),
)
)
);
$form['fckeditor_upload_settings']['fckeditor_upload_basic'] = array(
'#type' => 'checkbox',
'#title' => t('Allow basic file management'),
'#default_value' => variable_get("fckeditor_upload_basic", '0'),
'#description' => t("Allow quick uploads. All files will be placed in the directory designated in the configuration file."),
);
$form['fckeditor_upload_settings']['fckeditor_upload_advanced'] = array(
'#type' => 'checkbox',
'#title' => t('Allow advanced file management'),
'#default_value' => variable_get('fckeditor_upload_advanced', '0'),
'#description' => t('Allow file management in the advanced file manager. All files will be placed in subdirectories of the default drupal upload directory.'),
);
}
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", '')));
$toggle = variable_get('fckeditor_exclude_toggle', '0');
switch ($toggle) {
case (1):
// normal inclusion based on the id
$enabled = fckeditor_idsearch($element['#id'], $exclude);
break;
case (2):
// Path exclusion
$enabled = true; // defaults to enabled
// This bizarre bit of magic courtesy of block.module
$path = drupal_get_path_alias($_GET['q']);
$regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote(variable_get("fckeditor_exclude", ''), '/')) .')$/';
if(preg_match($regexp, $path)) {
$enabled = false; // but if in excluded paths disable it again
}
break;
case (3):
// Path inclusion
// This bizarre bit of magic courtesy of block.module
$path = drupal_get_path_alias($_GET['q']);
$regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote(variable_get("fckeditor_exclude", ''), '/')) .')$/';
if(preg_match($regexp, $path)) {
$enabled = true;
}
break;
case (0):
default:
// normal exclusion based on the id
$enabled = !fckeditor_idsearch($element['#id'], $exclude);
break;
}
if (($element['#rows'] > variable_get('fckeditor_minimum_rows', 5)) && $enabled) {
// only replace textarea when it has enough rows and it is enabled
// 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 = base_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
}
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['#suffix'] .= " (" . t('Open rich editor') . ")";
}
else {
// if no popup mode, add the editor initialization to the footer
// this obviously needs print($closure) in page.tpl.php
drupal_add_js('if (Drupal.jsEnabled) {$(document).ready(function() {'.$js_id.'.ReplaceTextarea();});}', 'inline', 'footer');
}
}
// display the field id for administrators
if (user_access('administer site configuration')) {
$element['#suffix'] .= 'The ID for for excluding or including this element is: '.$element['#id'].' - the path is: '.$_GET['q'].'';
}
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('*','.*',addslashes($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
*
* Opera and Safari are disabled because FCKeditor does not work
* reliably on those browsers yet
*
* @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 = (float)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;
}