Newer
Older
ontwerpwerk
committed
// $Id$
Wiktor Walc
committed
/**
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
* Copyright (C) 2003-2007 Frederico Caldeira Knabben
*
* == BEGIN LICENSE ==
*
* Licensed under the terms of any of the following licenses at your
* choice:
*
* - GNU General Public License Version 2 or later (the "GPL")
* http://www.gnu.org/licenses/gpl.html
*
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
* http://www.gnu.org/licenses/lgpl.html
*
* - Mozilla Public License Version 1.1 or later (the "MPL")
* http://www.mozilla.org/MPL/MPL-1.1.html
*
* == END LICENSE ==
*
ontwerpwerk
committed
* @file
*
* 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.
/**
* The name of simplified toolbar which should be forced
* Be sure that this toolbar is defined in fckeditor.config.js or fckconfig.js
*/
define('FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME', 'DrupalBasic') ;
global $_fckeditor_configuration;
global $_fckeditor_js_ids;
$_fckeditor_configuration = array();
$_fckeditor_js_ids = array();
/**
* Implementation of hook_help
*/
function fckeditor_help($section = '') {
if (strpos($section, 'admin/settings/fckeditor/edit/') === 0 || $section == 'admin/settings/fckeditor/add') {
$output = t("<p>Note: FCKeditor is highly configurable. The most commonly used features are listed below. If you want to take a look at all available settings, open <code>!fckconfig</code> and then customize <code>!fckeditor_config</code> to your needs. This is also the only way to define new toolbar sets. It is advised to not edit <code>fckconfig.js</code> because you may overwrite it accidentally when you update the editor.</p>", array('!fckconfig' => drupal_get_path('module', 'fckeditor') ."/fckeditor/fckconfig.js", '!fckeditor_config' => drupal_get_path('module', 'fckeditor') ."/fckeditor.config.js"));
}
switch ($section) {
case 'admin/settings/help#description':
ontwerpwerk
committed
$output = t("Enables the usage of FCKeditor (WYSIWYG editor) instead of plain text fields.");
break;
case 'admin/settings/fckeditor/addg':
case 'admin/settings/fckeditor/editg':
$output = t("<p>The Global Profile allows you to define settings that are common for all profiles. Values defined in other profiles will be appended to the global configuration. This way you can avoid repeating some of the settings that are usually the same in each profile.</p>");
case 'admin/settings/fckeditor':
$output = t("<p>The FCKeditor module allows Drupal to replace textarea fields with a rich text or <acronym title=\"What You See Is What You Get\">WYSIWYG</acronym> 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.</p><p>More information about the editor is located at the !fckeditorlink. A small user guide is located at !userguidelink.</p>",
array(
'!fckeditorlink' => l(t('FCKeditor homepage'), 'http://www.fckeditor.net'),
'!userguidelink' => l(t('FCKeditor userguide'), 'http://docs.fckeditor.net/FCKeditor/Users_Guide'))
$output .= t('<p>Profiles can be defined based on user roles. A FCKeditor profile can define which pages receive this FCKeditor capability, what buttons or themes are enabled for the editor, how the editor is displayed, and a few other editor functions. It is possible also to define the Global Profile that will hold values that will be appended to all other profiles.</p><p>Lastly, only users with the <code>!access1</code> !permission will be able to use FCKeditor. </p>', array('!permission' => l(t('permission'), 'admin/user/access'), '!access1' => t('access fckeditor')));
ontwerpwerk
committed
case 'admin/help#fckeditor':
$output = t("<p>The FCKeditor module allows Drupal to replace textarea fields with a rich text or <acronym title=\"What You See Is What You Get\">WYSIWYG</acronym> 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.</p><p>More information is located at the !fckeditorlink. A small user guide is located at !userguidelink.</p>",
array(
'!fckeditorlink' => l(t('FCKeditor homepage'), 'http://www.fckeditor.net'),
'!userguidelink' => l(t('FCKeditor userguide'), 'http://docs.fckeditor.net/FCKeditor/Users_Guide'))
$output .= t('<h3>Installation</h3><p>Go to the !fckeditorlink and download the latest version. Then uncompress the contents of the "fckeditor" directory of the downloaded file to %fckeditordir.</p>',
array(
'!fckeditorlink' => l(t('FCKeditor homepage'), 'http://www.fckeditor.net/download'),
'%fckeditordir' => base_path() . drupal_get_path('module', 'fckeditor') .'/fckeditor/')
$output .= t('<h3>Configuration</h3><ol><li>Enable the module as usual from Drupal\'s admin pages.</li><li>Grant permissions for use of FCKeditor in <code>!path2</code></li><li>Under <code>!path1</code>, create the fckeditor profiles. In each profile you can choose which textareas will be replaced by FCKeditor, select default toolbar and configure some more advanced settings </li><li>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: <br/><code>!filter</code>. </li><li>To have a better control over line breaks, you may disable <code>Line break converter</code> in the chosen filter (recommended).</li><li>Modify the fckeditor.config.js file to custom your needs (optional).<br />You may copy the needed configuration lines from the default FCKeditor configuration settings (modules/fckeditor/fckeditor/fckconfig.js), the lines in fckeditor.config.js will override most settings.</li></ol>',
Wiktor Walc
committed
'!path1' => l(t('Administer > Settings > FCKeditor'), 'admin/settings/fckeditor'),
'!path2' => l(t('Administer > User Management > Access Control'), 'admin/user/access'),
'!filter' => htmlentities('<a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area>
<hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em>
<b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote>
<pre> <address> <code> <cite> <embed> <object> <param> <strike> <caption>'),
Wiktor Walc
committed
'!filterlink' => l(t('filters'), 'admin/settings/filters'))
$output .= t('<h3>Installation troubleshooting</h3><p>If your FCKeditor does not show you must check if all files are extracted correctly. The directory %fckeditordir should have the following files <code>fckeditor.js, fckconfig.js, fckstyles.xml, fcktemplates.xml</code> and a directory named <code>editor</code>.</p>',
array(
'%fckeditordir' => base_path() . drupal_get_path('module', 'fckeditor') .'/fckeditor/')
);
$output .= t('The correct directory structure is as follows: <blockquote><pre>!structure</pre></blockquote>', array(
'!structure' => "modules\n fckeditor\n <em>fckeditor.module</em>\n fckeditor\n _samples\n editor\n <em>COPY_HERE.txt</em>\n <em>fckconfig.js</em>\n ..."
));
$output .= t("<h3>Plugins: Teaser break and Pagebreak</h3><p>By default, FCKeditor module comes with two plugins that can handle teaser break (<!--break-->) and pagebreak (<!--pagebreak-->). You can enable any (or even both) of them.<ol><li>Open <code>!fckeditor.config.js</code> and uncomment these three lines: <pre>!code</pre></li><li>The second step is to add buttons to the toolbar (in the same file). The button names are: <code>DrupalBreak, DrupalPageBreak</code>. For example if you have a toolbar with an array of buttons defined as follows: <pre>!buttons1</pre> simply add those two buttons at the end of array: <pre>!buttons2</pre> (remember about single quotes).</li></ol></p>",
'!fckeditor.config.js' => base_path() . drupal_get_path('module', 'fckeditor') .'/fckeditor.config.js',
Wiktor Walc
committed
'!code' => "
FCKConfig.PluginsPath = '../../plugins/' ;
FCKConfig.Plugins.Add( 'drupalbreak' ) ;
FCKConfig.Plugins.Add( 'drupalpagebreak' ) ;
",
'!buttons1' => "['Image','Flash','Table','Rule','SpecialChar']",
'!buttons2' => "['Image','Flash','Table','Rule','SpecialChar', 'DrupalBreak', 'DrupalPageBreak']",
));
$output .= t('<h3>Uploading images and files</h3><p>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.</p>',
array(
'!imce' => l(t('IMCE'), 'http://drupal.org/project/imce')
)
ontwerpwerk
committed
// the rest is untranslated for the moment
$output .= t("<h3>How to enable the file browser</h3><p>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).</p><p><ol><li>To enable file browsing you need to edit the connector configuration file in your fckeditor module directory, the file should be in:<blockquote><code>!config3</code> <br/> (FCKeditor 2.5+)<br/><br/> or <br/><br/><code>!config1</code><br/> and <br/><code>!config2</code> <br/> (FCKeditor 2.3.x - 2.4.x)</blockquote></p><p>In this file(s) you will need to enable the file browser by adding one line that includes file with the special authentication function for Drupal (<code>filemanager.config.php</code>). Add this code: <blockquote><code>!code1</code><br/> (FCKeditor 2.5+)</blockquote> or <blockquote><code>!code2</code> <br/> (FCKeditor 2.3.x - 2.4.x)</blockquote> straight below this line: <blockquote><code>!code3</code></blockquote> The config.php file also holds some other important settings, please take a look at it and adjust it to your needs (optional).</p></li>",
array('!config1' => base_path() . drupal_get_path('module', 'fckeditor') ."/fckeditor/editor/filemanager/browser/default/connectors/php/config.php",
'!config2' => base_path() . drupal_get_path('module', 'fckeditor') ."/fckeditor/editor/filemanager/upload/php/config.php",
'!config3' => base_path() . drupal_get_path('module', 'fckeditor') ."/fckeditor/editor/filemanager/connectors/php/config.php",
'!filesdir' => file_directory_path(),
'!code1' => 'require_once "../../../../../filemanager.config.php";', //2.5
'!code2' => 'require_once "'. str_replace("\\", "\\\\", dirname(__FILE__) . DIRECTORY_SEPARATOR .'filemanager.config.php"'), //2.4
'!code3' => "\$Config['UserFilesAbsolutePath'] = '' ;",
Wiktor Walc
committed
);
$output .= t("<li>As of Drupal 5.2, additional step is required: locate file named <code>settings.php</code> inside your drupal directory (usually <code>sites/default/settings.php</code>) and set <strong><code>$cookie_domain</code></strong> variable to the appropiate domain (remember to uncomment that line). If you not do this, FCKeditor will claim that file browser is disabled</li>");
$output .= t('<li>Enabling file uploads is <strong>a security risk</strong>. That\'s why you have to grant a !link to enable the file browser to certain groups.</li>', array('!link' => l(t('separate permission'), 'admin/user/access')));
$output .= t('<li>Lastly, adjust the !fb for each !profile.</li></ol>', array('!fb' => t('File browser settings'), '!profile' => l(t('profile'), 'admin/settings/fckeditor')));
$output .= t("<h3>Modules: Image Assist</h3><p>Image Assist can be integrated with FCKeditor. To do this, simply copy the <code>!iaf1</code> file to <code>!iaf2</code>.</p>", array("!iaf1" => drupal_get_path('module', 'fckeditor') ."/img_assist_fckeditor.js", "!iaf2" => drupal_get_path('module', 'img_assist') ."/img_assist_fckeditor.js"));
}
return $output;
}
/**
* Implementation of hook_perm
* Administer -> User management -> Access Control
*/
function fckeditor_perm() {
return array('administer fckeditor', 'access fckeditor', 'allow fckeditor file uploads');
* Replace textarea with FCKeditor using callback function (fckeditor_process_textarea)
function fckeditor_elements() {
$type = array();
$type['textfield'] = array(
'#process' => array(
'fckeditor_process_input' => array()
),
);
// 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;
/**
* Drupal 5 does not properly support #after_build in hook_elements().
*
* @see fckeditor_elements()
*/
function fckeditor_form_alter($form_id, &$form) {
if (user_access('access fckeditor') && fckeditor_is_compatible_client()) {
if (!isset($form['#after_build'])) {
$form['#after_build'] = array();
}
if (!in_array('fckeditor_process_form', $form['#after_build'])) {
array_unshift($form['#after_build'], 'fckeditor_process_form');
}
}
}
function fckeditor_process_form(&$form) {
global $_fckeditor_configuration, $_fckeditor_js_ids;
static $processed_textareas = array();
static $found_textareas = array();
//Skip if:
// - we're not editing an element
// - fckeditor is not enabled (configuration is empty)
if (arg(1) == "add" || arg(1) == "reply" || !count($_fckeditor_configuration)) {
return $form;
}
$fckeditor_filters = array();
// Iterate over element children; resetting array keys to access last index.
if ($children = array_values(element_children($form))) {
foreach ($children as $index => $item) {
$element = &$form[$item];
if (isset($element['#id']) && in_array($element['#id'], array_keys($_fckeditor_js_ids))) {
$found_textareas[$element['#id']] = &$element;
}
// filter_form() always uses the key 'format'. We need a type-agnostic
// match to prevent false positives. Also, there must have been at least
// one element on this level.
if ($item === 'format' && $index > 0) {
// Make sure we either match a input format selector or input format
// guidelines (displayed if user has access to one input format only).
if ((isset($element['#type']) && $element['#type'] == 'fieldset') || isset($element['format']['guidelines'])) {
// The element before this element is the target form field.
$field = &$form[$children[$index - 1]];
$textarea_id = $field['#id'];
array_push($processed_textareas, $js_id);
//search for checkxss1/2 class
if (empty($field['#attributes']['class']) || strpos($field['#attributes']['class'], "checkxss") === FALSE) {
continue;
}
// Determine the available input formats. The last child element is a
// link to "More information about formatting options". When only one
// input format is displayed, we also have to remove formatting
// guidelines, stored in the child 'format'.
$formats = element_children($element);
foreach ($formats as $format_id) {
$format = !empty($element[$format_id]['#default_value']) ? $element[$format_id]['#default_value'] : $element[$format_id]['#value'];
break;
}
$enabled = filter_list_format($format);
$fckeditor_filters = array();
//loop through all enabled filters
foreach ($enabled as $id => $filter) {
//but use only that one selected in FCKeditor profile
if (in_array($id, array_keys($_fckeditor_configuration[$textarea_id]['filters']))) {
if (!isset($fckeditor_filters[$js_id])) {
$fckeditor_filters[$js_id] = array();
}
$fckeditor_filters[$js_id][] = $id ."/". $format;
}
}
//No filters assigned, remove xss class
if (empty($fckeditor_filters[$js_id])) {
$field['#attributes']['class'] = preg_replace("/checkxss(1|2)/", "", $field['#attributes']['class']);
}
else {
$field['#attributes']['class'] = strtr($field['#attributes']['class'], array("checkxss1" => "filterxss1", "checkxss2" => "filterxss2"));
}
array_pop($formats);
unset($formats['format']);
}
// If this element is 'format', do not recurse further.
continue;
}
// Recurse into children.
fckeditor_process_form($element);
}
}
//We're in a form
if (isset($form['#action'])) {
//some textareas associated with FCKeditor has not been processed
if (count($processed_textareas) < count($_fckeditor_js_ids)) {
//loop through all found textfields
foreach (array_keys($found_textareas) as $id) {
//if not processed yet (checkxss class is before final processing)
if (strpos($element['#attributes']['class'], "checkxss") !== FALSE && !in_array($_fckeditor_js_ids[$element['#id']], $processed_textareas)) {
//assign default Filtered HTML to be safe on fields that do not have input format assigned
$fckeditor_filters[$js_id][] = "filter/0/1";
$element['#attributes']['class'] = strtr($element['#attributes']['class'], array("checkxss1" => "filterxss1", "checkxss2" => "filterxss2"));
}
}
}
}
if (!empty($fckeditor_filters)) {
drupal_add_js(array('fckeditor_filters' => $fckeditor_filters), 'setting');
}
return $form;
}
/**
* Allow more than 255 chars in Allowed HTML tags textfield
*
*/
function fckeditor_process_input($element) {
if ($element['#id']=='edit-allowed-html-1') {
$element['#maxlength'] = max($element['#maxlength'], 1024);
}
return $element;
}
/**
* Add link to FCKeditor configuration in "Administer -> Site configuration" section
*
*/
function fckeditor_menu($may_cache) {
'path' => 'admin/settings/fckeditor',
'title' => t('FCKeditor'),
'callback' => 'fckeditor_admin',
'description' => t('Configure the rich editor.'),
'access' => user_access('administer fckeditor'));
$items[] = array(
'path' => 'fckeditor/xss',
'title' => t('XSS Filter'),
'description' => t('XSS Filter.'),
'callback' => 'fckeditor_filter_xss',
'access' => user_access('access fckeditor'),
'type' => MENU_CALLBACK,
);
}
else {
drupal_add_css(drupal_get_path('module', 'fckeditor') .'/fckeditor.css');
/**
* AJAX callback - XSS filter
*/
function fckeditor_filter_xss() {
$GLOBALS['devel_shutdown'] = FALSE;
if (!isset($_POST['text']) || !is_string($_POST['text']) || !is_array($_POST['filters'])) {
exit;
}
$text = $_POST['text'];
$text = strtr($text, array('<!--' => '__COMMENT__START__', '-->' => '__COMMENT__END__'));
foreach ($_POST['filters'] as $module_delta) {
$module = strtok($module_delta, "/");
$delta = strtok("/");
$format = strtok("/");
if (!module_hook($module, 'filter')) {
continue;
}
//built-in filter module, a special case where we would like to strip XSS and nothing more
if ($module == 'filter' && $delta == 0) {
preg_match_all("|</?([a-z][a-z0-9]*)(?:\b[^>]*)>|i", $text, $matches);
if ($matches[1]) {
$tags = array_unique($matches[1]);
$text = filter_xss($text, $tags);
}
}
else {
$text = module_invoke($module, 'filter', 'process', $delta, $format, $text);
}
}
$text = strtr($text, array('__COMMENT__START__' => '<!--', '__COMMENT__END__' => '-->'));
echo $text;
exit;
}
//Remove a profile from the database.
function fckeditor_profile_delete($name) {
db_query("DELETE FROM {fckeditor_settings} WHERE name = '%s'", $name);
db_query("DELETE FROM {fckeditor_role} WHERE name = '%s'", $name);
}
/**
* Profile validation.
*/
function fckeditor_profile_validate($edit) {
$errors = array();
if ($edit['excl_mode'] == 1 && !$edit['excl_fields'] && !$edit['excl_paths']) {
$errors['excl_mode'] = t('Include mode selected, but no fields/paths given. Enter at least one path or field where FCKeditor should appear.');
}
if (!preg_match("/^\d+$/", trim($edit['min_rows']))) {
$errors['min_rows'] = t('Minimum rows must be a valid number');
}
if ($edit['default'] == 't' && $edit['popup'] == 't') {
$errors['popup'] = t('If FCKeditor is enabled by default, popup window must be disabled.');
}
if ($edit['show_toggle'] == 't' && $edit['popup'] == 't') {
$errors['popup'] = t('If toggle is enabled, popup window must be disabled.');
}
if (!$edit['name']) {
$errors['name'] = t('You must give a profile name.');
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
if (!preg_match("/^\d+%?$/", $edit['width'])) {
$errors['width'] = t('Enter valid width. Ex: 400 or 100%');
}
if (!empty($edit['css_path'])) {
if ($edit['css_mode'] != 'self') {
$errors['css_path'] = t('CSS path is not empty. Please set the "Editor CSS" option to "define css" mode.');
}
else if (false !== strpos($edit['css_path'], '"')) {
$errors['css_path'] = t('Double quotes are not allowed in CSS path.');
}
else if (substr($edit['css_path'], 0, 1) == "'" && substr($edit['css_path'], -1) == "'") {
$errors['css_path'] = t('Enter valid path, do not surround it with quotes.');
}
}
if (!empty($edit['styles_path'])) {
if ($edit['css_style'] != 'self') {
$errors['styles_path'] = t('Path to predefined styles is not empty. Please set the "Predefined styles" option to "define path to fckstyles.xml" mode.');
}
else if (false !== strpos($edit['styles_path'], '"')) {
$errors['styles_path'] = t('Double quotes are not allowed in path.');
}
else if (substr($edit['styles_path'], 0, 1) == "'" && substr($edit['styles_path'], -1) == "'") {
$errors['styles_path'] = t('Enter valid path, do not surround it with quotes.');
}
}
if (!empty($edit['font_format'])) {
if (!preg_match("/^((p|div|pre|address|h1|h2|h3|h4|h5|h6);)*(p|div|pre|address|h1|h2|h3|h4|h5|h6)$/", $edit['font_format'])) {
$errors['font_format'] = t('Enter valid, semicolon separated, list of HTML font formats (no semicolon at the end of list expected).');
}
}
//validate fields
$fields = preg_split("/[\s,]+/", strip_tags($edit['excl_fields']));
foreach ($fields as $field) {
if ($field && !preg_match("/^[a-z]+(\-[[:alnum:]]+|\\*|\-\\*)+$/i", $field)) {
$errors['excl_fields'] = t("Invalid field specified: %1", array("%1" => $field));
break;
}
}
$fields = preg_split("/[\s,]+/", strip_tags($edit['simple_incl_fields']));
foreach ($fields as $field) {
if ($field && !preg_match("/^[a-z]+(\-[[:alnum:]]+|\\*|\-\\*)+$/i", $field)) {
$errors['simple_incl_fields'] = t("Invalid field specified: %1", array("%1" => $field));
break;
}
}
//validate paths
$paths = preg_split("/[\s,]+/", strip_tags($edit['excl_paths']));
foreach ($paths as $path) {
if ($path && !preg_match("|^[_a-z0-9-\*/]*$|i", $path)) {
$errors['excl_paths'] = t("Invalid path specified: %1", array("%1" => $path));
break;
}
}
$paths = preg_split("/[\s,]+/", strip_tags($edit['simple_incl_paths']));
foreach ($paths as $path) {
if ($path && !preg_match("|^[_a-z0-9-\*/]*$|i", $path)) {
$errors['excl_paths'] = t("Invalid path specified: %1", array("%1" => $path));
break;
}
}
if (variable_get('file_downloads', '') !== FILE_DOWNLOADS_PRIVATE) {
if (!empty($edit['UserFilesAbsolutePath']) && empty($edit['UserFilesPath'])) {
$errors['UserFilesPath'] = t("Path to uploaded files is required.");
}
if (!empty($edit['UserFilesPath']) && empty($edit['UserFilesAbsolutePath'])) {
$errors['UserFilesPath'] = t("Absolute path to uploaded files is required.");
}
foreach ($errors as $name => $message) {
form_set_error($name, $message);
}
/**
* Global profile validation.
*/
function fckeditor_global_profile_validate($edit) {
$errors = array();
if ($edit['excl_mode'] == 1 && !$edit['excl_fields'] && !$edit['excl_paths']) {
$errors['excl_mode'] = t('Include mode selected, but no fields/paths given. Enter at least one path or field where FCKeditor should appear.');
}
//validate fields
$fields = preg_split("/[\s,]+/", strip_tags($edit['excl_fields']));
foreach ($fields as $field) {
if ($field && !preg_match("/^[a-z]+(\-[[:alnum:]]+|\\*|\-\\*)+$/i", $field)) {
$errors['excl_fields'] = t("Invalid field specified: %1", array("%1" => $field));
break;
}
}
$fields = preg_split("/[\s,]+/", strip_tags($edit['simple_incl_fields']));
foreach ($fields as $field) {
if ($field && !preg_match("/^[a-z]+(\-[[:alnum:]]+|\\*|\-\\*)+$/i", $field)) {
$errors['simple_incl_fields'] = t("Invalid field specified: %1", array("%1" => $field));
break;
}
}
//validate paths
$paths = preg_split("/[\s,]+/", strip_tags($edit['excl_paths']));
foreach ($paths as $path) {
if ($path && !preg_match("|^[_a-z0-9-\*/]*$|i", $path)) {
$errors['excl_paths'] = t("Invalid path specified: %1", array("%1" => $path));
break;
}
}
$paths = preg_split("/[\s,]+/", strip_tags($edit['simple_incl_paths']));
foreach ($paths as $path) {
if ($path && !preg_match("|^[_a-z0-9-\*/]*$|i", $path)) {
$errors['simple_incl_paths'] = t("Invalid path specified: %1", array("%1" => $path));
break;
}
}
foreach ($errors as $name => $message) {
form_set_error($name, $message);
}
return count($errors) == 0;
}
/**
* Controller for FCKeditor administrative settings.
*/
function fckeditor_admin($arg = NULL) {
Wiktor Walc
committed
$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(
Wiktor Walc
committed
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/download'),
Wiktor Walc
committed
'!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');
}
$op = isset($_POST['op']) ? $_POST['op'] : "";
$op = $arg && !$op ? $arg : $op;
switch ($op) {
case 'add':
$output = fckeditor_profile_form($edit);
break;
case 'addg':
$output = fckeditor_global_profile_form($edit);
break;
case 'deleteg':
$output = fckeditor_ask_delete_confirmation(true);
break;
case 'delete':
$output = fckeditor_ask_delete_confirmation(false, urldecode(arg(4)));
break;
case 'edit':
drupal_set_title(t('Edit FCKeditor profile'));
$output = fckeditor_profile_form(fckeditor_profile_load(urldecode(arg(4))));
break;
case 'editg':
drupal_set_title(t('Edit FCKeditor profile'));
$output = fckeditor_global_profile_form(fckeditor_profile_load("FCKeditor Global Profile"));
break;
case 'deleteconfirmed':
fckeditor_profile_delete(urldecode(arg(4)));
drupal_set_message(t('Deleted profile'));
drupal_goto('admin/settings/fckeditor');
break;
case 'deletegconfirmed':
fckeditor_profile_delete("FCKeditor Global Profile");
drupal_set_message(t('Deleted Global profile'));
drupal_goto('admin/settings/fckeditor');
break;
case t('Create profile');
case t('Update profile');
if (fckeditor_profile_validate($edit)) {
fckeditor_profile_save($edit);
$edit['old_name'] ? drupal_set_message(t('Your FCKeditor profile has been updated.')) : drupal_set_message(t('Your FCKeditor profile has been created.'));
drupal_goto('admin/settings/fckeditor');
}
else {
$output = fckeditor_profile_form($edit);
}
break;
case t('Create global profile');
case t('Update global profile');
if (fckeditor_global_profile_validate($edit)) {
$edit['name'] = 'FCKeditor Global Profile';
fckeditor_global_profile_save($edit);
drupal_set_message(t('FCKeditor global profile has been saved.'));
drupal_goto('admin/settings/fckeditor');
}
else {
$output = fckeditor_global_profile_form($edit);
}
break;
default:
drupal_set_title(t('FCKeditor settings'));
//Check if FCKeditor is installed.
$fckeditor_loc = drupal_get_path('module', 'fckeditor') .'/fckeditor/';
if (!is_dir($fckeditor_loc)) {
drupal_set_message(t('Could not find the FCKeditor engine installed at <strong>!fckeditor-directory</strong>. Please !download, uncompress it and copy the folder into !fckeditor-path.', array('!fckeditor-path' => drupal_get_path('module', 'fckeditor'), '!fckeditor-directory' => $fckeditor_loc, '!download' => l(t("download FCKeditor"), "http://www.fckeditor.net/download"))), 'error');
$access_fckeditor_roles = user_roles(FALSE, 'access fckeditor');
if (!$access_fckeditor_roles) {
drupal_set_message(t('There is currently no role with the <strong>!access</strong> permission. Visit !acl administration section.',
array("!access" => t("access fckeditor"), "!acl" => l(t("Access control"), "admin/user/access"))), "warning");
$result = db_query_range("SELECT name FROM {fckeditor_settings} WHERE name<>'FCKeditor Global Profile'", 0, 1);
//find profile other than Global
if ($obj = db_fetch_object($result)) {
//find roles with profiles
$result = db_query("SELECT rid FROM {fckeditor_role}");
$rids = array();
while ($obj = db_fetch_object($result)) {
$rids[] = $obj->rid;
}
$rids = array_unique($rids);
if (!$has_profiles) {
drupal_set_message(t("No FCKeditor profiles found. At this moment, nobody is able to use FCKeditor. Create new profile below."), "error");
}
else {
//not all roles with access fckeditor has their FCKeditor profile assigned
$diff = array_diff(array_keys($access_fckeditor_roles), $rids);
if ($diff) {
$list = "<ul>";
foreach ($diff as $rid) {
$list .= "<li>". $access_fckeditor_roles[$rid] ."</li>";
drupal_set_message(t("Not all roles with <strong>!access</strong> permission are associated with FCKeditor profiles. As a result, users having the following roles may be unable to use FCKeditor: !list Create new or edit FCKeditor profiles below and in the <strong>Basic setup</strong> section, check "Roles allowed to use this profile".", array("!access" => l(t("access fckeditor"), "admin/user/access"), "!list" => $list)), "warning");
return $output;
}
/**
* Save a profile to the database.
* @todo add more entries to array in the user_save line
*/
function fckeditor_profile_save($edit) {
db_query("DELETE FROM {fckeditor_settings} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']);
db_query("DELETE FROM {fckeditor_role} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']);
db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", $edit['name'], serialize($edit));
if ($edit['rids']) {
foreach ($edit['rids'] as $rid => $value) {
db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)", $edit['name'], $rid);
}
}
// if users can't set their own defaults, make sure to remove $user->fckeditor_status so their default doesn't override the main default
if ($edit['user_choose'] == 'false') {
global $user;
user_save($user, array('fckeditor_status' => NULL));
}
function fckeditor_global_profile_save($edit) {
if (isset($edit['rank'])) {
$edit['rank'] = explode('>', str_replace(' ', '', $edit['rank']));
}
db_query("DELETE FROM {fckeditor_settings} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']);
db_query("DELETE FROM {fckeditor_role} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']);
db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", $edit['name'], serialize($edit));
}
/**
* Controller for fckeditor profiles.
*/
function fckeditor_profile_overview() {
$output = '';
$profiles = fckeditor_profile_load();
if ($profiles) {
$roles = user_roles();
$access_fckeditor_roles = user_roles(FALSE, 'access fckeditor');
$header = array(t('Profile'), t('Roles'), t('Operations'));
foreach ($profiles as $p) {
if ($p->name !== "FCKeditor Global Profile") {
foreach ($p->rids as $rid => $name) {
if (!isset($access_fckeditor_roles[$rid])) {
unset($rids[$rid]);
}
}
$rows[] = array(array('data' => $p->name, 'valign' => 'top'), array('data' => implode("<br />\n", $rids)), array('data' => l(t('edit'), 'admin/settings/fckeditor/edit/'. urlencode($p->name)) .' '. l(t('delete'), 'admin/settings/fckeditor/delete/'. urlencode($p->name)), 'valign' => 'top'));
$output .= "<h3>". t("Profiles") ."</h3>";
$output .= theme('table', $header, $rows);
$output .= '<p>'. l(t('Create new profile'), 'admin/settings/fckeditor/add') .'</p>';
drupal_set_message(t('No profiles found. Click here to !create.', array('!create' => l(t("create a new profile"), 'admin/settings/fckeditor/add'))));
}
$rows = array();
if (!isset($profiles['FCKeditor Global Profile'])) {
drupal_set_message(t('Global Profile not found. Click here to !create.', array('!create' => l(t("create the global profile"), 'admin/settings/fckeditor/addg'))));
}
else {
$output .= "<h3>". t("Global Settings") ."</h3>";
$rows[] = array(array('data' => t('FCKeditor Global Profile'), 'valign' => 'top'), array('data' => l(t('edit'), 'admin/settings/fckeditor/editg') ." ". l(t('delete'), 'admin/settings/fckeditor/deleteg'), 'valign' => 'top'));
$output .= theme('table', array(t('Profile'), t('Operations')), $rows);
* Load all profiles. Just load one profile if $name is passed in.
function fckeditor_profile_load($name = '') {
static $profiles = array();
if (!$profiles) {
$roles = user_roles();
$result = db_query('SELECT * FROM {fckeditor_settings}');
while ($data = db_fetch_object($result)) {
$data->settings = unserialize($data->settings);
$result2 = db_query("SELECT rid FROM {fckeditor_role} WHERE name = '%s'", $data->name);
$role = array();
while ($r = db_fetch_object($result2)) {
$role[$r->rid] = $roles[$r->rid];
}
$data->rids = $role;
$profiles[$data->name] = $data;
}
}
return ($name ? $profiles[$name] : $profiles);
}
/**
* @param int $excl_mode 1/include, exclude otherwise
* @param string $excl_fields fields (HTML IDs)
* @param string $excl_paths paths (drupal paths)
* @param string $element_id current ID
* @param string $get_q current path
*
* @return boolean
* returns true if FCKeditor is enabled
*/
function fckeditor_is_enabled($excl_mode, $excl_fields, $excl_paths, $element_id, $get_q) {
$arr_excl_fields = preg_split("/[\s,]+/", strip_tags($excl_fields));
$field_found = fckeditor_idsearch($element_id, $arr_excl_fields);
$path = drupal_get_path_alias($get_q);
$regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($excl_paths, '/')) .')$/';
$path_found = preg_match($regexp, $path);
$found = $field_found || $path_found;
$result = ($excl_mode == 1) ? $found : !$found;
return $result;
}
/**
* 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) {
static $is_running = FALSE;
static $num = 1;
static $processed_elements = array();
global $user, $fckeditor_simple_toolbar_ids, $_fckeditor_configuration, $_fckeditor_js_ids;
$processed = in_array($element['#id'], $processed_elements);
if ($processed) {
return $element;
}
//hack for module developers that want to disable FCKeditor on their textareas
if (key_exists('#wysiwyg', $element) && !$element['#wysiwyg']) {
return $element;
}
//skip this one, surely nobody wants WYSIWYG here
switch ($element['#id']) {
case 'edit-excl-list':
case 'edit-simple-incl-list':
case 'edit-simple-incl-paths':
case 'edit-simple-incl-fields':
case 'edit-excl-fields':
case 'edit-excl-paths':
case 'edit-js-conf':
$profile = fckeditor_user_get_profile($user);
if (!$profile) {
return $element;
}
$conf = array();
$conf = $profile->settings;
if ($conf['allow_user_conf']=='t') {
Wiktor Walc
committed
foreach (array('default', 'show_toggle', 'popup', 'skin', 'toolbar', 'expand', 'width', 'lang', 'auto_lang') as $setting) {
$conf[$setting] = fckeditor_user_get_setting($user, $profile, $setting);
}
}
if ($conf["popup"]=="t" && $conf["show_toggle"]=="t") {
$conf["show_toggle"]="f";
}
//old profile info, assume Filtered HTML is enabled
if (!isset($conf['ss'])) {
$conf['ss'] = 2;
$conf['filters']['filter/0'] = 1;
}
if (!isset($conf['filters'])) {
$conf['filters'] = array();
}
Wiktor Walc
committed
$themepath = path_to_theme() .'/';
$enabled = fckeditor_is_enabled($conf['excl_mode'], $conf['excl_fields'], $conf['excl_paths'], $element['#id'], $_GET['q']);
if ($enabled) {
$global_profile = fckeditor_profile_load("FCKeditor Global Profile");
$global_conf = $global_profile->settings;
if ($global_conf) {
$enabled = fckeditor_is_enabled($global_conf['excl_mode'], $global_conf['excl_fields'], $global_conf['excl_paths'], $element['#id'], $_GET['q']);
}
}
if ((($element['#rows'] > $conf['min_rows']) || ($conf['min_rows'] <= 1 && empty($element['#rows']))) && $enabled) {
Wiktor Walc
committed
// Set resizable to false to avoid drupal.js resizable function from taking control of the textarea
if ($conf["popup"]=="f") {
$element['#resizable'] = FALSE;
}
// only replace textarea when it has enough rows and it is enabled
$js_id = 'oFCK_'. $num++;
Wiktor Walc
committed
$fckeditor_on = ($conf['default']=='t') ? 1 : 0 ;
$xss_check = 0;
//it's not a problem when adding new content/comment
if (arg(1) != "add" && arg(1) != "reply") {
$_fckeditor_configuration[$element['#id']] = $conf;
//let FCKeditor know when perform XSS checks auto/manual
if ($conf['ss'] == 1) {
$xss_class = 'checkxss1';
}
else {
$xss_class = 'checkxss2';
}
if (!isset($element['#attributes']['class'])) {
$element['#attributes']['class'] = '';
}
$element['#attributes']['class'] .= ' '. $xss_class;
$xss_check = 1;
}
Wiktor Walc
committed
$wysiwyg_link = "<div id=\"fck_{$js_id}\"><textarea id=\"{$js_id}\">". htmlspecialchars($element['#value']) ."</textarea></div>\n";
$wysiwyg_link .= "<a href=\"javascript:Toggle('{$js_id}','{$element['#id']}','". str_replace("'", "\\'", t("Switch to plain text editor")) ."','". str_replace("'", "\\'", t("Switch to rich text editor")) ."',". $xss_check .");\" id=\"switch_{$js_id}\" ". ($fckeditor_on?"style=\"display:none\"":"") .">";
Wiktor Walc
committed
$wysiwyg_link .= $fckeditor_on ? t("Switch to plain text editor") : t("Switch to rich text editor");
if (!isset($element['#suffix'])) {
Wiktor Walc
committed
$element['#suffix'] = "";
//settings are saved as strings, not booleans
Wiktor Walc
committed
if ($conf['show_toggle'] == 't') {
// Make sure to append to #suffix so it isn't completely overwritten
drupal_add_js('if (Drupal.jsEnabled) {$(document).ready(function() {CreateToggle("'. $element['#id'] .'","'. $js_id .'", '. $fckeditor_on .');});}', 'inline');
$element['#suffix'] .= $wysiwyg_link;
}
// setting some variables
Wiktor Walc
committed
$module_drupal_path = drupal_get_path('module', 'fckeditor');
$module_full_path = base_path() . $module_drupal_path;
$files_path = base_path() . file_directory_path();
// module_drupal_path:
// 'modules/fckeditor' (length=17)
// module_full_path:
// '/drupal5/modules/fckeditor' (length=26)
// files_path:
// '/drupal5/files' (length=14)
// configured in settings
// sensible default for small toolbars
Wiktor Walc
committed
drupal_add_js($module_drupal_path .'/fckeditor/fckeditor.js');
drupal_add_js($module_drupal_path .'/fckeditor.utils.js');
drupal_add_js(array('basePath' => base_path()), 'setting');
ontwerpwerk
committed
}
$toolbar = $conf['toolbar'];
//$height += 100; // for larger toolbars
$force_simple_toolbar = fckeditor_is_enabled(1, $conf['simple_incl_fields'], $conf['simple_incl_paths'], $element['#id'], $_GET['q']);
if (!$force_simple_toolbar) {
$force_simple_toolbar = fckeditor_is_enabled(1, $global_conf['simple_incl_fields'], $global_conf['simple_incl_paths'], $element['#id'], $_GET['q']);
}
Wiktor Walc
committed
if ($force_simple_toolbar) {
$toolbar = FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME;
Wiktor Walc
committed
$textarea_id = $conf['show_toggle'] == 't' ? $js_id : $element['#id'];
$_fckeditor_js_ids[$element['#id']] = $textarea_id;
Wiktor Walc
committed
$js = $js_id ." = new FCKeditor( '". $textarea_id ."' );
Wiktor Walc
committed
". $js_id .".BasePath = '". $module_full_path ."/fckeditor/';
". $js_id .".Config['CustomConfigurationsPath'] = \"". $module_full_path ."/fckeditor.config.js?". @filemtime($module_drupal_path ."/fckeditor.config.js") ."\";
". $js_id .".Config['TextareaID'] = \"". $element['#id'] ."\";";
//if ($conf['appearance_conf'] == 'f') {
Wiktor Walc
committed
$js .= "\n". $js_id .".ToolbarSet = \"". $toolbar ."\";
". $js_id .".Config['SkinPath'] = ". $js_id .".BasePath + \"editor/skins/". $conf['skin'] ."/\";
". $js_id .".Config['DefaultLanguage'] = \"". $conf['lang'] ."\";
". $js_id .".Config['AutoDetectLanguage'] = ". ($conf['auto_lang']=="t"?"true":"false") .";
". $js_id .".Height = \"". $height ."\";
". $js_id .".Config['ToolbarStartExpanded'] = ". ($conf['expand']=="t"?"true":"false") .";
". $js_id .".Width = \"". $width ."\";\n";
//}
//if ($conf['output_conf'] == 'f') {
Wiktor Walc
committed
$js .= "\n". $js_id .".Config['EnterMode'] = '". $conf['enter_mode'] ."';
". $js_id .".Config['ShiftEnterMode'] = \"". $conf['shift_enter_mode'] ."\";
". $js_id .".Config['FontFormats'] = \"". str_replace(",", ";", $conf['font_format']) ."\";
". $js_id .".Config['FormatSource'] = ". ($conf['format_source']=="t"?"true":"false") .";
". $js_id .".Config['FormatOutput'] = ". ($conf['format_output']=="t"?"true":"false") .";\n";
ontwerpwerk
committed
if (function_exists('img_assist_perm')) {
Wiktor Walc
committed
drupal_add_js("var fckImgAssistPath = '". base_path() . drupal_get_path('module', 'img_assist') ."';", 'inline');
Wiktor Walc
committed
if (function_exists('linktocontent_node_menu')) {
if (!empty($conf['linktoc']) && $conf['linktoc']!='p') {
Wiktor Walc
committed
$js .= $js_id .".Config['DrupalPathFilter'] = true;\n";
Wiktor Walc
committed
$js .= $js_id .".Config['DrupalLinkToContentSelect'] = true;\n";
Wiktor Walc
committed
$js .= $js_id .".Config['DrupalPath'] = '". base_path() ."';\n";
Wiktor Walc
committed
// integrate IMCE if it exists and is prefered
if (function_exists('imce_integrate') && variable_get('imce_settings_fck', 0)) {
imce_integrate('fck');
$advanced_uploads = 0;
$basic_uploads = 0;
}
else {