Newer
Older
/*
* FCKeditor Module for Drupal 4.7
* This module allows Drupal to replace textarea fields with FCKeditor.
*
* This HTML text editor brings to the web many of the powerful functionalities
* of known desktop editors like Word. It's really lightweight and doesn't
* require any kind of installation on the client computer.
*
* ----------------------------------------------------------------------------
*
* FCKeditor - The text editor for internet
* Copyright (C) 2003-2006 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/
* ----------------------------------------------------------------------------
*
* @version 1.0
* @author LatPro Inc (George)
* @version 1.1
* @author Frederico Caldeira Knabben (www.fckeditor.net)
* @version 1.2
* @author Ontwerpwerk (www.ontwerpwerk.nl)
*/
/**
* Implementation of hook_help
*/
function fckeditor_help($section = '') {
if ($section == 'admin/modules#description') {
return $output = t("Enables the usage of FCKeditor (WYSIWYG editor) instead of plain text fields.");
}
return $output;
}
/**
* Implementation of hook_perm
*/
function fckeditor_perm() {
return array('use default fckeditor', 'use advanced fckeditor');
}
/**
* 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;
}
/**
* Implementation of hook_setting().
*/
function fckeditor_settings() {
// 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_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.'),
);
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
$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"),
);
/*
// 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'),
'#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_popup'] = array(
'#type' => 'checkbox',
'#title' => t('Use FCKeditor in a popup window'),
'#default_value' => variable_get('fckeditor_popup', '0'),
'#description' => t('Popup window or Textarea replace.'),
);
$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_skin'] = array('#type' => 'value', '#value' => variable_get('fckeditor_skin', 'default'));
return $form;
}
* This function create the HTML objects required for the FCKeditor
function fckeditor_process_textarea($element) {
$exclude = preg_split("/[\s,]+/", strip_tags(variable_get("fckeditor_exclude", '')));
if ($element['#rows'] > variable_get('fckeditor_minimum_rows', 5)
&& !array_pregsearch($element['#id'], $exclude)) {
// only when a textarea has enough rows and is not in the exclusion list
// setting some variables
ontwerpwerk
committed
$module_drupal_path = drupal_get_path('module', 'fckeditor');
$module_full_path = base_path() . $module_drupal_path;
$js_id = 'oFCKeditor_' . str_replace('-', '_', $element['#id']);
// configured in settings
$width = variable_get("fckeditor_width", '100%');
// sensible default for small toolbars
$height = $element['#rows'] * 18 + 100;
// nessecary because FCKeditor interferes with resize script
$element['#resizable'] = FALSE;
ontwerpwerk
committed
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'] .= "
<script type=\"text/javascript\">
var ".$js_id." = new FCKeditor( '".$element['#id']."' );
ontwerpwerk
committed
".$js_id.".BasePath = '".$module_full_path."/fckeditor/';
".$js_id.".Config['CustomConfigurationsPath'] = '".$module_full_path."/fckeditor.config.js';
".$js_id.".ToolbarSet = '".$toolbar."';
".$js_id.".Height = '".$height."';
</script>\n";
if (variable_get('fckeditor_popup', '0')) {
// Add the script file with the popup open function.
ontwerpwerk
committed
drupal_add_js($module_drupal_path . '/fckeditor.popup.js');
$element['#title'] .= " <span class=\"fckeditor_popuplink\">(<a href=\"#\" onclick=\"FCKeditor_OpenPopup('".$module_full_path."/fckeditor.popup.html?var=".$js_id."&el=".$element['#id']."');return false;\">" . t('Open rich editor') . "</a>)</span>" ;
} else {
// if no popup mode, add the editor
$element['#suffix'] .="
<script type=\"text/javascript\">
".$js_id.".ReplaceTextarea();
</script>\n";
}
}
return $element;
if (!function_exists('array_pregsearch')) {
function array_pregsearch($search, $array) {
foreach ($array as $key => $value) {
if (!empty($value) && preg_match('/'.str_replace('*','.*',$value).'/si', $search)) {
return $key;
}
}
return false;
}
}
* Test if client supports the FCKeditor
*/
function fckeditor_is_compatible_client() {
$sAgent = $_SERVER['HTTP_USER_AGENT'] ;
if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false ) {
$iVersion = (int)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3);
return ($iVersion >= 5.5);
}
else if ( strpos($sAgent, 'Gecko') !== false ) {
$iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;
return ($iVersion >= 20030210) ;
}
else
return false;
}