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 !fckconfig and then customize !fckeditor_config to your needs. This is also the only way to define new toolbar sets. It is advised to not edit fckconfig.js because you may overwrite it accidentally when you update the editor.

", 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': $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("

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.

"); break; case 'admin/settings/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 about the editor 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://docs.fckeditor.net/FCKeditor/Users_Guide')) ); $output .= t('

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.

Lastly, only users with the !access1 !permission will be able to use FCKeditor.

', array('!permission' => l(t('permission'), 'admin/user/access'), '!access1' => t('access fckeditor'))); 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://docs.fckeditor.net/FCKeditor/Users_Guide')) ); $output .= t('

Installation

Go to the !fckeditorlink and download the latest version. Then uncompress the contents of the "fckeditor" directory of the downloaded file to %fckeditordir.

', array( '!fckeditorlink' => l(t('FCKeditor homepage'), 'http://www.fckeditor.net/download'), '%fckeditordir' => base_path() . drupal_get_path('module', 'fckeditor') .'/fckeditor/') ); $output .= t('

Configuration

  1. Enable the module as usual from Drupal\'s admin pages.
  2. Grant permissions for use of FCKeditor in !path2
  3. Under !path1, 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
  4. 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.
  5. To have a better control over line breaks, you may disable Line break converter in the chosen filter (recommended).
  6. Modify the fckeditor.config.js file to custom your needs (optional).
    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.
', array( '!path1' => l(t('Administer > Settings > FCKeditor'), 'admin/settings/fckeditor'), '!path2' => l(t('Administer > User Management > Access Control'), 'admin/user/access'), '!filter' => htmlentities('




    1.  
      '), '!filterlink' => l(t('filters'), 'admin/settings/filters')) ); $output .= t('

      Installation troubleshooting

      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, fckeditor.php, fckeditor_php4.php, fckeditor_php5.php and a directory named editor.

      ', array( '%fckeditordir' => base_path() . drupal_get_path('module', 'fckeditor') .'/fckeditor/') ); $output .= t('The correct directory structure is as follows:
      !structure
      ', array( '!structure' => "modules\n fckeditor\n fckeditor.module\n fckeditor\n _samples\n editor\n COPY_HERE.txt\n fckconfig.js\n ..." )); $output .= t("

      Plugins: Teaser break and Pagebreak

      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.

      1. Open !fckeditor.config.js and uncomment these three lines:
        !code
      2. The second step is to add buttons to the toolbar (in the same file). The button names are: DrupalBreak, DrupalPageBreak. For example if you have a toolbar with an array of buttons defined as follows:
        !buttons1
        simply add those two buttons at the end of array:
        !buttons2
        (remember about single quotes).

      ", array( '!fckeditor.config.js' => base_path() . drupal_get_path('module', 'fckeditor') .'/fckeditor.config.js', '!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('

      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') ) ); // the rest is untranslated for the moment $output .= t("

      How to enable the file browser

      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).

      1. To enable file browsing you need to edit the connector configuration file in your fckeditor module directory, the file should be in:
        !config3
        (FCKeditor 2.5+)

        or

        !config1
        and
        !config2
        (FCKeditor 2.3.x - 2.4.x)

        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 (filemanager.config.php). Add this code:

        !code1
        (FCKeditor 2.5+)
        or
        !code2
        (FCKeditor 2.3.x - 2.4.x)
        straight below this line:
        !code3
        The config.php file also holds some other important settings, please take a look at it and adjust it to your needs (optional).

      2. ", 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'] = '' ;", ) ); $output .= t("
      3. As of Drupal 5.2, additional step is required: locate file named settings.php inside your drupal directory (usually sites/default/settings.php) and set $cookie_domain variable to the appropriate domain (remember to uncomment that line). If you not do this, FCKeditor will claim that file browser is disabled
      4. "); $output .= t('
      5. Enabling file uploads is a security risk. That\'s why you have to grant a !link to enable the file browser to certain groups.
      6. ', array('!link' => l(t('separate permission'), 'admin/user/access'))); $output .= t('
      7. Lastly, adjust the !fb for each !profile.
      ', array('!fb' => t('File browser settings'), '!profile' => l(t('profile'), 'admin/settings/fckeditor'))); $output .= t("

      Modules: Image Assist

      Image Assist can be integrated with FCKeditor. To do this, simply copy the !iaf1 file to !iaf2.

      ", array("!iaf1" => drupal_get_path('module', 'fckeditor') ."/img_assist_fckeditor.js", "!iaf2" => drupal_get_path('module', 'img_assist') ."/img_assist_fckeditor.js")); break; } return $output; } /** * Implementation of hook_perm() * Administer -> User management -> Access Control */ function fckeditor_perm() { return array('administer fckeditor', 'access fckeditor', 'allow fckeditor file uploads'); } /** * Implementation of textarea * Replace textarea with FCKeditor using callback function (fckeditor_process_textarea) */ function fckeditor_elements() { $type = array(); $type['textfield'] = array( '#process' => array( 'fckeditor_process_input' => array() ), ); if (user_access('access 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; } /** * 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']; $js_id = $_fckeditor_js_ids[$textarea_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) { $element = &$found_textareas[$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) && !empty($_fckeditor_configuration[$id]['filters'])) { //assign default Filtered HTML to be safe on fields that do not have input format assigned, but only if at least one security filter is enabled in Security settings $js_id = $_fckeditor_js_ids[$element['#id']]; $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) { $items = array(); if ($may_cache) { $items[] = array( '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'); } return $items; } /** * 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__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("|]*)>|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__' => '')); 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.'); } 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]+(\-{1,2}[[: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]+(\-{1,2}[[: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; } } 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); } return count($errors) == 0; } /** * 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]+(\-{1,2}[[: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]+(\-{1,2}[[: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) { $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/download'), '!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; } $edit = $_POST; $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 !fckeditor-directory. 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 !access permission. Visit !acl administration section.', array("!access" => t("access fckeditor"), "!acl" => l(t("Access control"), "admin/user/access"))), "warning"); } else { $result = db_query_range("SELECT name FROM {fckeditor_settings} WHERE name<>'FCKeditor Global Profile'", 0, 1); $has_profiles = FALSE; //find profile other than Global if ($obj = db_fetch_object($result)) { $has_profiles = TRUE; } //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 = "
        "; foreach ($diff as $rid) { $list .= "
      • ". $access_fckeditor_roles[$rid] ."
      • "; } $list .= "
      "; drupal_set_message(t("Not all roles with !access 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 Basic setup section, check "Roles allowed to use this profile".", array("!access" => l(t("access fckeditor"), "admin/user/access"), "!list" => $list)), "warning"); } } } $output = fckeditor_profile_overview(); } 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) { $rids = $p->rids; 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("
      \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 .= "

      ". t("Profiles") ."

      "; $output .= theme('table', $header, $rows); $output .= '

      '. l(t('Create new profile'), 'admin/settings/fckeditor/add') .'

      '; } else { 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 .= "

      ". t("Global Settings") ."

      "; $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); } return $output; } /** * Load all profiles. Just load one profile if $name is passed in. */ function fckeditor_profile_load($name = '', $clear = FALSE) { static $profiles = array(); if (empty($profiles) || $clear === TRUE) { $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)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), 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, $theme, $_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; } if (isset($element['#access']) && !$element['#access']) { 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-log': case 'edit-excl-fields': case 'edit-excl-paths': case 'edit-js-conf': return $element; break; } $profile = fckeditor_user_get_profile($user); if (!$profile) { return $element; } $conf = array(); $conf = $profile->settings; if ($conf['allow_user_conf']=='t') { 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(); } $themepath = path_to_theme() .'/'; $host = base_path(); $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) { // 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++; $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; } $wysiwyg_link = '
      '."\n"; $wysiwyg_link .= ""; $wysiwyg_link .= $fckeditor_on ? t("Switch to plain text editor") : t("Switch to rich text editor"); $wysiwyg_link .= ""; if (!isset($element['#suffix'])) { $element['#suffix'] = ""; } //settings are saved as strings, not booleans 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 $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(); // module_drupal_path: // 'modules/fckeditor' (length=17) // module_full_path: // '/drupal5/modules/fckeditor' (length=26) // files_path: // '/drupal5/files' (length=14) // configured in settings $width = $conf['width']; // sensible default for small toolbars $height = $element['#rows'] * 14 + 140; if (!$is_running) { 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'); $is_running = TRUE; } $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']); } if ($force_simple_toolbar) { $toolbar = FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME; } $textarea_id = $conf['show_toggle'] == 't' ? $js_id : $element['#id']; $_fckeditor_js_ids[$element['#id']] = $textarea_id; if (!empty($conf['theme_config_js']) && $conf['theme_config_js'] == 't' && file_exists($themepath .'fckeditor.config.js')) { $fckeditor_config_path = $host . $themepath .'fckeditor.config.js?'. @filemtime($themepath .'fckeditor.config.js'); } else { $fckeditor_config_path = $module_full_path ."/fckeditor.config.js?". @filemtime($module_drupal_path ."/fckeditor.config.js"); } $js = $js_id ." = new FCKeditor( '". $textarea_id ."' ); ". $js_id .".BasePath = '". $module_full_path ."/fckeditor/'; ". $js_id .".Config['CustomConfigurationsPath'] = \"". $fckeditor_config_path ."\"; ". $js_id .".Config['TextareaID'] = \"". $element['#id'] ."\";"; //if ($conf['appearance_conf'] == 'f') { $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') { $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"; //} if (function_exists('img_assist_perm')) { drupal_add_js("var fckImgAssistPath = '". base_path() . drupal_get_path('module', 'img_assist') ."';", 'inline'); } if (function_exists('linktocontent_node_menu')) { if (!empty($conf['linktoc']) && $conf['linktoc']!='p') { $js .= $js_id .".Config['DrupalPathFilter'] = true;\n"; if ($conf['linktoc'] == 'pn') { $js .= $js_id .".Config['DrupalLinkToContentSelect'] = true;\n"; } } $js .= $js_id .".Config['DrupalPath'] = '". base_path() ."';\n"; } // 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 { $advanced_uploads = ($conf['upload_advanced']=="t"); $basic_uploads = ($conf['upload_basic']=="t"); } // add code for filebrowser for users that have access if (user_access('allow fckeditor file uploads')==1) { $connector_path = $module_drupal_path ."/fckeditor/editor/filemanager/connectors/php/connector.php"; if (file_exists($connector_path)) { //FCKeditor 2.5 and above $connector_path = $module_full_path ."/fckeditor/editor/filemanager/connectors/php/connector.php"; } else { //FCKeditor 2.4.3- $connector_path = "connectors/php/connector.php"; } $upload_path = $module_drupal_path ."/fckeditor/editor/filemanager/connectors/php/upload.php"; if (file_exists($upload_path)) { //FCKeditor 2.5 and above $upload_path = $module_full_path ."/fckeditor/editor/filemanager/connectors/php/upload.php"; } else { //FCKeditor 2.4.3- $upload_path = "/fckeditor/editor/filemanager/upload/php/upload.php"; } if ($advanced_uploads) { $js .= $js_id .".Config['LinkBrowserURL'] = \"". $module_full_path ."/fckeditor/editor/filemanager/browser/default/browser.html?Connector=". $connector_path ."&ServerPath=". $files_path ."\"; ". $js_id .".Config['ImageBrowserURL'] = \"". $module_full_path ."/fckeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=". $connector_path ."&ServerPath=". $files_path ."\"; ". $js_id .".Config['FlashBrowserURL'] = \"". $module_full_path ."/fckeditor/editor/filemanager/browser/default/browser.html?Type=Flash&Connector=". $connector_path ."&ServerPath=". $files_path ."\";\n"; } else { $js .= $js_id .".Config['LinkBrowser'] = false; ". $js_id .".Config['ImageBrowser'] = false; ". $js_id .".Config['FlashBrowser'] = false;\n"; } if ($basic_uploads) { $js .= $js_id .".Config['LinkUploadURL'] = \"". $upload_path ."\"; ". $js_id .".Config['ImageUploadURL'] = \"". $upload_path ."?Type=Image\"; ". $js_id .".Config['FlashUploadURL'] = \"". $upload_path ."?Type=Flash\";\n"; } else { $js .= $js_id .".Config['LinkUpload'] = false; ". $js_id .".Config['ImageUpload'] = false; ". $js_id .".Config['FlashUpload'] = false;\n"; } $_SESSION['FCKeditor']['UserFilesPath'] = strtr($profile->settings['UserFilesPath'], array("%f" => file_directory_path(), "%u" => $user->uid, "%b" => base_path())); $_SESSION['FCKeditor']['UserFilesAbsolutePath'] = strtr($profile->settings['UserFilesAbsolutePath'], array("%f" => file_directory_path(), "%u" => $user->uid, "%b" => base_path(), "%d" => $_SERVER['DOCUMENT_ROOT'])); if (variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE) { $private_dir = isset($global_profile->settings['private_dir']) ? trim($global_profile->settings['private_dir'], '\/') : ''; if (!empty($private_dir)) { $private_dir = strtr($private_dir, array('%u' => $user->uid)); $_SESSION['FCKeditor']['UserFilesPath'] = url('system/files') .'/'. $private_dir .'/'; $_SESSION['FCKeditor']['UserFilesAbsolutePath'] = realpath(file_directory_path()) . DIRECTORY_SEPARATOR . $private_dir . DIRECTORY_SEPARATOR; } else { $_SESSION['FCKeditor']['UserFilesPath'] = url('system/files') .'/'; $_SESSION['FCKeditor']['UserFilesAbsolutePath'] = realpath(file_directory_path()) . DIRECTORY_SEPARATOR; } } } else { $js .= $js_id .".Config['LinkBrowser'] = false; ". $js_id .".Config['ImageBrowser'] = false; ". $js_id .".Config['FlashBrowser'] = false; ". $js_id .".Config['LinkUpload'] = false; ". $js_id .".Config['ImageUpload'] = false; ". $js_id .".Config['FlashUpload'] = false;\n"; } if ($conf['js_conf']) { $lines = preg_split("/[\n\r]+/", $conf['js_conf']); foreach ($lines as $l) if ($l && strlen($l) > 5) { $eqpos = strpos($l, "="); if (false !== $eqpos) { $option = str_replace("FCKConfig.", "", substr($l, 0, $eqpos)); $js .= "\n". $js_id .".Config['". trim($option) ."'] =". substr($l, $eqpos + 1); } } } // add custom xml stylesheet if it exists if ($conf['css_style'] == 'theme') { if (file_exists($themepath .'fckstyles.xml')) { $styles_xml_path = $host . $themepath .'fckstyles.xml'; $js .= $js_id .".Config['StylesXmlPath'] = \"". $styles_xml_path ."\";\n"; } } else if ($conf['css_style'] == 'self') { $conf['styles_path'] = str_replace("%h%t", "%t", $conf['styles_path']); $js .= $js_id .".Config['StylesXmlPath'] = \"". str_replace(array('%h', '%t', '%m'), array($host, $host . $themepath, $module_drupal_path), $conf['styles_path']) ."\";\n"; } // add custom stylesheet if configured // lets hope it exists but we'll leave that to the site admin if ($conf['css_mode'] == 'theme') { $css = $themepath .'style.css'; $editorcss = "\""; if (file_exists($css)) { $editorcss .= $host . $css .","; } $color_path = variable_get('color_'. $theme .'_stylesheet', NULL); if (!empty($color_path)) { $editorcss .= $host . $color_path .","; } $editorcss .= $module_full_path ."/fckeditor.css\";\n"; $js .= $js_id .".Config['EditorAreaCSS'] = ". $editorcss; } else if ($conf['css_mode'] == 'self') { $conf['css_path'] = str_replace("%h%t", "%t", $conf['css_path']); $js .= $js_id .".Config['EditorAreaCSS'] = \"". str_replace(array('%h', '%t'), array($host, $host . $themepath), $conf['css_path']) .",". $module_full_path ."/fckeditor.css\";"; } drupal_add_js('var '. $js_id .';if (Drupal.jsEnabled) {$(document).ready(function() {'. $js .'});}', 'inline'); if ($conf['popup']=="t") { // 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 if ($fckeditor_on) { drupal_add_js('if (Drupal.jsEnabled) {$(document).ready(function() {window.setTimeout("FCKeditorReplaceTextarea(\''. $textarea_id .'\','. $js_id .','. $xss_check .');",100);});}', 'inline', 'footer'); } } } // display the field id for administrators if (user_access('administer fckeditor')) { $element['#suffix'] .= '
      '. t('The ID for !excluding this element is: @id - the path is: @path', array( '!excluding' => l(t("excluding or including"), 'admin/settings/fckeditor'), '@id' => $element['#id'], '@path' => $_GET['q'], )) .'
      '; } $processed_elements[] = $element['#id']; return $element; } /** * Implementation of hook_user(). */ function fckeditor_user($type, &$edit, &$user, $category = NULL) { if ($type == 'form' && $category == 'account' && user_access('access fckeditor')) { $profile = fckeditor_user_get_profile($user); $toolbar_options = fckeditor_load_toolbar_options(); $skin_options = fckeditor_load_skin_options(); $lang_options = fckeditor_load_lang_options(); // because the settings are saved as strings we need to test for the string 'true' if ($profile->settings['allow_user_conf'] == 't') { $form['fckeditor'] = array( '#type' => 'fieldset', '#title' => t('Rich Text Editor settings'), '#weight' => 10, '#collapsible' => TRUE, '#collapsed' => TRUE ); $form['fckeditor']['fckeditor_default'] = array( '#type' => 'select', '#title' => t('Default state'), '#default_value' => isset($user->fckeditor_default) ? $user->fckeditor_default : (isset($profile->settings['default']) ? $profile->settings['default'] : 'f'), '#options' => array('t' => t('enabled'), 'f' => t('disabled')), '#description' => t('Should rich-text editing be enabled or disabled by default in textarea fields? If disabled, rich text editor may still be enabled using toggle or popup window.'), ); $form['fckeditor']['fckeditor_show_toggle'] = array( '#type' => 'select', '#title' => t('Show disable/enable rich text editor toggle'), '#default_value' => isset($user->fckeditor_show_toggle) ? $user->fckeditor_show_toggle : (isset($profile->settings['show_toggle']) ? $profile->settings['show_toggle'] : 't'), '#options' => array('t' => t('true'), 'f' => t('false')), '#description' => t('Whether or not to show the disable/enable rich text editor toggle below the textarea. Works only if FCKeditor is not running a popup window (see below).'), ); $form['fckeditor']['fckeditor_popup'] = array( '#type' => 'select', '#title' => t('Use FCKeditor in a popup window'), '#default_value' => isset($user->fckeditor_popup) ? $user->fckeditor_popup : (isset($profile->settings['popup']) ? $profile->settings['popup'] : 'f'), '#options' => array('f' => t('false'), 't' => t('true')), '#description' => t('If this option is enabled a link to a popup window will be used instead of a textarea replace.'), ); $form['fckeditor']['fckeditor_skin'] = array( '#type' => 'select', '#title' => t('Skin'), '#default_value' => isset($user->fckeditor_skin) ? $user->fckeditor_skin : (isset($profile->settings['skin']) ? $profile->settings['skin'] : 'default'), '#options' => $skin_options, '#description' => t('Choose a FCKeditor skin.'), ); $form['fckeditor']['fckeditor_toolbar'] = array( '#type' => 'select', '#title' => t('Toolbar'), '#default_value' => isset($user->fckeditor_toolbar) ? $user->fckeditor_toolbar : (isset($profile->settings['toolbar']) ? $profile->settings['toolbar'] : 'default'), '#options' => $toolbar_options, '#description' => t('Choose a FCKeditor toolbar set.'), ); $form['fckeditor']['fckeditor_expand'] = array( '#type' => 'select', '#title' => t('Start the toolbar expanded'), '#default_value' => isset($user->fckeditor_expand) ? $user->fckeditor_expand : (isset($profile->settings['expand']) ? $profile->settings['expand'] : 't'), '#options' => array('t' => t('enabled'), 'f' => t('disabled')), '#description' => t('The toolbar start expanded or collapsed.'), ); $form['fckeditor']['fckeditor_width'] = array( '#type' => 'textfield', '#title' => t('Width'), '#default_value' => isset($user->fckeditor_width) ? $user->fckeditor_width : (isset($profile->settings['width']) ? $profile->settings['width'] : '100%'), '#description' => t("Width in pixels or percent. Ex: 400 or 100%"), '#size' => 40, '#maxlength' => 128, ); $form['fckeditor']['fckeditor_lang'] = array( '#type' => 'select', '#title' => t('Language'), '#default_value' => isset($user->fckeditor_lang) ? $user->fckeditor_lang : (isset($profile->settings['lang']) ? $profile->settings['lang'] : 'en'), '#options' => $lang_options, '#description' => t('The language for the FCKeditor interface.') ); $form['fckeditor']['fckeditor_auto_lang'] = array( '#type' => 'select', '#title' => t('Auto-detect language'), '#default_value' => isset($user->fckeditor_auto_lang) ? $user->fckeditor_auto_lang : (isset($profile->settings['auto_lang']) ? $profile->settings['auto_lang'] : 't'), '#options' => array('t' => t('true'), 'f' => t('false')), '#description' => t('Use auto detect user language feature.') ); return array('fckeditor' => $form); } } if ($type == 'validate') { if (isset($edit['fckeditor_default'], $edit['fckeditor_popup']) && $edit['fckeditor_default'] == 't' && $edit['fckeditor_popup'] == 't') { form_set_error('fckeditor_popup', t('If FCKeditor is enabled by default, popup window must be disabled.')); } if (isset($edit['fckeditor_show_toggle'], $edit['fckeditor_popup']) && $edit['fckeditor_show_toggle'] == 't' && $edit['fckeditor_popup'] == 't') { form_set_error('fckeditor_popup', t('If toggle is enabled, popup window must be disabled.')); } if (isset($edit['fckeditor_width']) && !preg_match('/^\d+%?$/', $edit['fckeditor_width'])) { form_set_error('fckeditor_width', t('Enter valid width. Example: 400 or 100%.')); } } } /** * Return an HTML form for profile configuration. */ function fckeditor_profile_form($edit) { $output .= drupal_get_form('fckeditor_profile_form_build', $edit); return $output; } /** * Return an HTML form for global profile configuration. */ function fckeditor_global_profile_form($edit) { $output .= drupal_get_form('fckeditor_global_profile_form_build', $edit); return $output; } function fckeditor_load_toolbar_options() { $arr = array(); $module_drupal_path = drupal_get_path('module', 'fckeditor'); $fckconfig_js = $module_drupal_path .'/fckeditor/fckconfig.js'; $fckeditor_config_js = $module_drupal_path .'/fckeditor.config.js'; if (file_exists($fckconfig_js) && is_readable($fckconfig_js)) { $fp = @fopen($fckconfig_js, "r"); if ($fp) { while (!feof($fp)) { $line = fgets($fp, 1024); if (preg_match("/FCKConfig\.ToolbarSets\[(\"|')(.*?)\\1\]/i", $line, $matches)) { $arr[$matches[2]] = ucfirst($matches[2]); } } fclose($fp); } } if (file_exists($fckeditor_config_js) && is_readable($fckeditor_config_js)) { $fp = @fopen($fckeditor_config_js, "r"); if ($fp) { while (!feof($fp)) { $line = fgets($fp, 1024); if (preg_match("/FCKConfig\.ToolbarSets\[(\"|')(.*?)\\1\]/i", $line, $matches)) { $arr[$matches[2]] = ucfirst($matches[2]); } } fclose($fp); } } //oops, we have no information about toolbars, let's use hardcoded array if (empty($arr)) { $arr = array( 'Basic' => 'Basic', 'Default' => 'Default', ); } asort($arr); return $arr; } /** * Get an array of input formats that include HTML filter * * @return array */ function fckeditor_html_filter_formats() { static $return; if (isset($return)) { return $return; } $return = array(); $r = db_query("SELECT format FROM {filters} WHERE module = 'filter' AND delta = 0"); while ($row = db_fetch_object($r)) { $return[] = $row->format; } return $return; } function fckeditor_load_skin_options() { $arr = array(); $module_drupal_path = drupal_get_path('module', 'fckeditor'); $skin_dir = $module_drupal_path .'/fckeditor/editor/skins'; if (is_dir($skin_dir)) { $dh = @opendir($skin_dir); if (FALSE !== $dh) { while (($file = readdir($dh)) !== FALSE ) { if (in_array($file, array(".", "..", "CVS", ".svn"))) { continue; } if (is_dir($skin_dir . DIRECTORY_SEPARATOR . $file)) { $arr[$file] = ucfirst($file); } } closedir( $dh ); } } //oops, we have no information about skins, let's use only default if (empty($arr)) { $arr = array( 'default' => 'Default', ); } asort($arr); return $arr; } function fckeditor_load_lang_options() { $arr = array(); $module_drupal_path = drupal_get_path('module', 'fckeditor'); $lang_dir = $module_drupal_path .'/fckeditor/editor/lang'; if (is_dir($lang_dir)) { $dh = @opendir($lang_dir); if (FALSE !== $dh ) { while (($file = readdir($dh)) !== FALSE) { if (in_array($file, array(".", "..", "CVS", ".svn"))) { continue; } if (is_file($lang_dir . DIRECTORY_SEPARATOR . $file) && preg_match("/^(.*?)\.js$/", $file, $matches)) { $lang = $matches[1]; $arr[$lang] = strtoupper($lang); } } closedir( $dh ); } } //oops, we have no information about languages, let's use those available in FCKeditor 2.4.3 if (empty($arr)) { $arr = array( 'af' => 'Afrikaans', 'ar' => 'Arabic', 'bg' => 'Bulgarian', 'bn' => 'Bengali/Bangla', 'bs' => 'Bosnian', 'ca' => 'Catalan', 'cs' => 'Czech', 'da' => 'Danish', 'de' => 'German', 'el' => 'Greek', 'en' => 'English', 'en-au' => 'English (Australia)', 'en-ca' => 'English (Canadian)', 'en-uk' => 'English (United Kingdom)', 'eo' => 'Esperanto', 'es' => 'Spanish', 'et' => 'Estonian', 'eu' => 'Basque', 'fa' => 'Persian', 'fi' => 'Finnish', 'fo' => 'Faroese', 'fr' => 'French', 'gl' => 'Galician', 'he' => 'Hebrew', 'hi' => 'Hindi', 'hr' => 'Croatian', 'hu' => 'Hungarian', 'it' => 'Italian', 'ja' => 'Japanese', 'km' => 'Khmer', 'ko' => 'Korean', 'lt' => 'Lithuanian', 'lv' => 'Latvian', 'mn' => 'Mongolian', 'ms' => 'Malay', 'nb' => 'Norwegian Bokmal', 'nl' => 'Dutch', 'no' => 'Norwegian', 'pl' => 'Polish', 'pt' => 'Portuguese (Portugal)', 'pt-br' => 'Portuguese (Brazil)', 'ro' => 'Romanian', 'ru' => 'Russian', 'sk' => 'Slovak', 'sl' => 'Slovenian', 'sr' => 'Serbian (Cyrillic)', 'sr-latn' => 'Serbian (Latin)', 'sv' => 'Swedish', 'th' => 'Thai', 'tr' => 'Turkish', 'uk' => 'Ukrainian', 'vi' => 'Vietnamese', 'zh' => 'Chinese Traditional', 'zh-cn' => 'Chinese Simplified', ); } asort($arr); return $arr; } /** * sort roles according to precedence settings. previously sorted roles are followed by latest added roles. */ function fckeditor_sorted_roles($clear = FALSE) { static $order; if (isset($order) && $clear !== TRUE) { return $order; } $order = array(); $roles = user_roles(0, 'access fckeditor'); $result = db_query("SELECT settings FROM {fckeditor_settings} WHERE name='FCKeditor Global Profile'"); $data = db_fetch_object($result); if ($data->settings) { $settings = unserialize($data->settings); if (isset($settings['rank']) && !empty($settings['rank'])) foreach ($settings['rank'] as $rid) { if (isset($roles[$rid])) { $order[$rid] = $roles[$rid]; unset($roles[$rid]); } } } krsort($roles);//sort the remaining unsorted roles by id, descending. $order += $roles; return $order; } function fckeditor_global_profile_form_build($edit) { $edit = (object) $edit; if (arg(3) == 'addg') { $breadcrumb[] = array('path' => 'admin', 'title' => t('administer')); $breadcrumb[] = array('path' => 'admin/settings/fckeditor', 'title' => t('fckeditor')); $breadcrumb[] = array('path' => 'admin/settings/fckeditor/addg', 'title' => t('Add new FCKeditor global profile')); menu_set_location($breadcrumb); $result = db_query("SELECT DISTINCT(rid) FROM {fckeditor_role} WHERE name='FCKeditor Global Profile'"); $data = db_fetch_object($result); if ($data->rid) { drupal_set_message(t("Global profile already exist. Only one global profile is allowed."), "error"); return array(); } $btn = t('Create global profile'); } else { $form['old_name'] = array('#type' => 'hidden', '#value' => $edit->name); $btn = t('Update global profile'); } $form['common'] = array( '#type' => 'fieldset', '#title' => t('Main setup'), '#collapsible' => TRUE, '#collapsed' => TRUE ); $roles = fckeditor_sorted_roles(); $rids = $rtext = array(); foreach ($roles as $rid => $name) { $rids[] = $rid; $rtext[] = ''. $rid .' - '. $name; } $form['common']['rank'] = array('#type' => 'textfield', '#title' => t('Role precedence'), '#default_value' => implode('>', $rids), '#description' => t('A user having multiple roles gets the permissions of the highest one. Sort role IDs according to their precedence from higher to lower by putting > in between.
      '), ); if ($rids) { $form['common']['rank']['#description'] .= t('Here is the id-name pairs of roles having access to FCKeditor:') .'
      '. implode('
      ', $rtext) .'
      '; } else { $form['common']['rank']['#description'] .= t('You haven\'t assigned the !access1 !permissions yet.', array('!access1' => t('access fckeditor'), '!permissions' => l(t('permissions'), 'admin/user/access'))); } $form['fckeditor_exclude_settings'] = array( '#type' => 'fieldset', '#title' => t('Visibility settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#description' => t('The following settings are combined with the visibility settings of the specific profile.'), ); $form['fckeditor_exclude_settings']['excl_mode'] = array( '#type' => 'select', '#title' => t('Use inclusion or exclusion mode'), '#default_value' => (in_array($edit->settings['excl_mode'], array(0, 2))) ? 0 : 1, '#options' => array('0' => t('exclude'), '1' => t('include')), '#description' => t('Choose the way of disabling/enabling FCKeditor on selected fields/paths (see below). Use exclude to disable FCKeditor on selected fields/paths. Use include if you want to load FCKeditor only on selected paths/fields.'), ); /** * 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']['excl_fields'] = array( '#type' => 'textarea', '#title' => t('Fields to exclude/include'), '#cols' => 60, '#rows' => 5, '#prefix' => '
      ', '#suffix' => '
      ', '#default_value' => $edit->settings['excl_fields'] ? $edit->settings['excl_fields'] : '', '#description' => t("Enter names (HTML ID's) of fields that may or may not have an FCKeditor, depending on the chosen option for the inclusion/exclusion mode.
      You may separate the different entries by commas, spaces or newlines.
      You may also use * as a wildcard character."), ); /** * get excluded paths - 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']['excl_paths'] = array( '#type' => 'textarea', '#title' => t('Paths to exclude/include'), '#prefix' => '
      ', '#suffix' => '
      ', '#cols' => 60, '#rows' => 5, '#default_value' => $edit->settings['excl_paths'] ? $edit->settings['excl_paths'] : '', '#description' => t("Enter drupal paths here, depending on the chosen option for the inclusion/exclusion mode.
      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 (for example comment/*)."), ); $form['fckeditor_exclude_settings']['simple_incl_fields'] = array( '#type' => 'textarea', '#title' => t('Force simplified toolbar on the following fields'), '#cols' => 60, '#rows' => 5, '#default_value' => $edit->settings['simple_incl_fields'] ? $edit->settings['simple_incl_fields'] : '', '#description' => t("Enter names (HTML ID's) of fields that should have the simplified toolbar (!name).
      If you don't want to use this feature, simply leave this field empty.
      You may separate the different entries by commas, spaces or newlines.", array("!name" => FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME)), ); $form['fckeditor_exclude_settings']['simple_incl_paths'] = array( '#type' => 'textarea', '#title' => t('Force simplified toolbar on the following paths'), '#cols' => 60, '#rows' => 5, '#default_value' => $edit->settings['simple_incl_paths'] ? $edit->settings['simple_incl_paths'] : '', '#description' => t("Enter drupal paths that should have the simplified toolbar (!name).
      If you don't want to use this feature, simply leave this field empty.
      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 (for example comment/*).", array("!name" => FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME)), ); if (variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE) { $form['fckeditor_advanced_settings'] = array( '#type' => 'fieldset', '#title' => t('Advanced settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $current_private_dir = !isset($edit->settings['private_dir']) ? "" : $edit->settings['private_dir']; $form['fckeditor_advanced_settings']['private_dir'] = array( '#type' => 'textfield', '#title' => t('Location of files uploaded with FCKeditor in the private folder'), '#default_value' => $current_private_dir, '#size' => 40, '#maxlength' => 255, '#description' => t('The path relative to the location of the private directory where FCKeditor should store uploaded files.') .'
      '. t('Warning: FCKeditor does not implement any kind of access protection on files available in this location. All files stored in the directory defined above might be accessible by unauthenticated users if there is no information about the file in the Drupal\'s database.') .'
      '. t('System path to the private folder is: !system_path.', array('!system_path' => realpath(file_directory_path()) . DIRECTORY_SEPARATOR)) .'
      '. t('Available wildcard characters:
      %u - User ID.') .'
      '. t('Current path: !path', array('!path' => $current_private_dir .' ('. file_create_path($current_private_dir) .')')), ); } $form['submit'] = array( '#type' => 'submit', '#value' => $btn ); return $form; } /** * Return an HTML form for profile configuration. */ function fckeditor_profile_form_build($edit) { $edit = (object) $edit; $toolbar_options = fckeditor_load_toolbar_options(); $skin_options = fckeditor_load_skin_options(); $lang_options = fckeditor_load_lang_options(); // Only display the roles that currently don't have a fckeditor profile. One // profile per role. $orig_roles = user_roles(FALSE, 'access fckeditor'); $roles = $orig_roles; if ($edit->rids && !user_roles(false, 'access fckeditor')) { drupal_set_message(t('You haven\'t assigned !access1 !permissions yet.
      It is recommended to assign the !access1 !permissions before updating FCKeditor profiles.', array( '!access1' => t('access fckeditor'), '!permissions' => l(t('permissions'), 'admin/user/access'))), 'warning'); } if (arg(3) == 'add') { $breadcrumb[] = array('path' => 'admin', 'title' => t('administer')); $breadcrumb[] = array('path' => 'admin/settings/fckeditor', 'title' => t('fckeditor')); $breadcrumb[] = array('path' => 'admin/settings/fckeditor/add', 'title' => t('Add new FCKeditor profile')); menu_set_location($breadcrumb); $result = db_query('SELECT DISTINCT(rid) FROM {fckeditor_role}'); while ($data = db_fetch_object($result)) { if (!in_array($data->rid, array_keys((array) $edit->rids)) && !form_get_errors()) { unset($roles[$data->rid]); } } if (count($orig_roles) != count($roles)) { drupal_set_message(t('Not all user roles are shown since they already have fckeditor profiles. You must first unassign profiles in order to add them to a new one.')); } $btn = t('Create profile'); } else { $form['old_name'] = array('#type' => 'hidden', '#value' => $edit->name); $btn = t('Update profile'); } $form['basic'] = array( '#type' => 'fieldset', '#title' => t('Basic setup'), '#collapsible' => TRUE, '#collapsed' => TRUE ); $form['basic']['name'] = array( '#type' => 'textfield', '#title' => t('Profile name'), '#default_value' => $edit->name, '#size' => 40, '#maxlength' => 128, '#description' => t('Enter a name for this profile. This name is only visible within the fckeditor administration page.'), '#required' => TRUE ); $form['basic']['rids'] = array( '#type' => 'checkboxes', '#title' => t('Roles allowed to use this profile'), '#default_value' => array_keys((array) $edit->rids), '#options' => $roles, '#description' => t('Only roles with \'!access1\' permission will be shown here. If no role is available, make sure that you have assigned the \'!access1\' !permission.', array('!access1' => t('access fckeditor'), '!permission' => l(t("permission"), "admin/user/access"))), '#required' => TRUE ); $form['basic']['allow_user_conf'] = array( '#type' => 'select', '#title' => t('Allow users to customize FCKeditor appearance'), '#default_value' => $edit->settings['allow_user_conf'] ? $edit->settings['allow_user_conf'] : 'f', '#options' => array('f' => t('false'), 't' => t('true')), '#description' => t('If allowed, users will be able to override Editor appearance by visiting their profile page.'), ); $form['security'] = array( '#type' => 'fieldset', '#title' => t('Security'), '#description' => '

      '. t("When Drupal saves user data input through a textarea, it's saved in the database in unmodified form. That's why all untrusted textarea input should be run through an input format filter before outputting it to the screen.") .'

      '.'

      '. t("Drupal will not, however, filter data for content editors editing a textarea. Normally, there is no security risk because the unmodified code is displayed as text and will not be rendered as HTML. But with FCKeditor installed, this is not the case, and content editors are subject to having raw, untrusted code running inside their browsers.") .'

      '.'

      '. t("To address this issue, you should select a security filters below to prevent FCKeditor from rendering malicious code. Note that if a textarea's input format is set to \"Full HTML\" (or if the input format of the node doesn't include the filter), FCKeditor will properly ignore the setting below and will not run the code through the security filter.") .'

      '.'

      '. t("If any textareas on your site are accessible to unwanted users, we recommend checking the \"HTML Filter\". You may have other modules installed that provide other kinds of security filters and you may use those as long as you trust them to properly filter out malicious code. Note that not all the filters below are security filters and will provide no protection.") .'

      ', '#collapsible' => TRUE, '#collapsed' => TRUE ); $all = filter_list_all(); $form['security']['filters'] = array( '#type' => 'fieldset', '#title' => t('Security filters'), '#description' => t('Please choose carefully all filters that protect your content (probably not all filters listed below are security filters).'), '#tree' => TRUE, ); //don't bother administrator with filters that definitely are not security filters $modules_with_filters_to_skip = array('amazon_filter', 'asy', 'bbcode', 'biblio', 'blockquote', 'bookpost', 'chessboard', 'citation_filter', 'codefilter', 'collapse_text', 'contextlinks', 'coolfilter', 'dialectic', 'dript', 'dme', 'drutex', 'embedfilter', 'ext_link_page', 'extlink', 'elf', 'flickr', 'flickrstickr', 'footnotes', 'formdefaults', 'freelinking', 'gallery', 'geogebra', 'geshifilter', 'gotwo', 'googtube', 'gotcha', 'gtspam', 'hidden_content', 'img_assist', 'image_filter', 'inlinetags', 'insert_view', 'insertframe', 'insertnode', 'interwiki', 'jlightbox', 'jsmath', 'language_sections', 'link_node', 'lootz', 'markdown', 'marksmarty', 'mobile_codes', 'mykml', 'nofollowlist', 'oagwt', 'paging', 'pathfilter', 'pearwiki_filter', 'php', 'pirate', 'reptag', 'scrippet', 'scripturefilter', 'signwriter', 'slideshowpro', 'smartlinebreakconverter', 'smartypants', 'smileys', 'spamspan', 'spam_tokens', 'spoiler', 'table_altrow', 'tablemanager', 'tableofcontents', 'textile', 'tooltips', 'twikifilter', 'typogrify', 'unwrap', 'urlclass', 'urlicon', 'url_replace_filter', 'username_highlighter', 'video_filter', 'quote'); if (!isset($edit->settings['ss'])) { $edit->settings['filters']['filter/0'] = 1; } foreach ($all as $id => $filter) { if (in_array(strtolower($filter->module), $modules_with_filters_to_skip)) { continue; } //skip line break converter and email -> link if ($filter->module == 'filter' && in_array($filter->delta, array(1, 2, 3))) { continue; } $form['security']['filters'][$id] = array( '#type' => 'checkbox', '#title' => $filter->name, '#default_value' => isset($edit->settings['filters'][$id]), '#description' => module_invoke($filter->module, 'filter', 'description', $filter->delta), ); } $form['security']['ss'] = array( '#type' => 'radios', '#title' => t('Security settings'), '#default_value' => isset($edit->settings['ss']) ? $edit->settings['ss'] : '2', '#options' => array( '2' => t('Always run security filters for FCKeditor.'), '1' => t('Run security filters only when FCKeditor is set to start automatically.'), ), '#description' => t('There are two ways of starting FCKeditor: automatically and manually (via toggle or in a popup). If you decide to apply security filters only when FCKeditor starts automatically, you\'ll not be protected when toggling manually from plain textarea to FCKeditor or when using FCKeditor in a popup mode. So choose this option only, if you can detect various attacks (mainly XSS) by yourself just by looking at the HTML code.'), ); $form['fckeditor_exclude_settings'] = array( '#type' => 'fieldset', '#title' => t('Visibility settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#description' => t('The following settings are combined with the visibility settings of the global profile.'), ); $form['fckeditor_exclude_settings']['min_rows'] = array( '#type' => 'textfield', '#title' => t('Minimum rows'), '#default_value' => $edit->settings['min_rows'] ? $edit->settings['min_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']['excl_mode'] = array( '#type' => 'select', '#title' => t('Use inclusion or exclusion mode'), '#default_value' => (in_array($edit->settings['excl_mode'], array(0, 2))) ? 0 : 1, '#options' => array('0' => t('exclude'), '1' => t('include')), '#description' => t('Choose the way of disabling/enabling FCKeditor on selected fields/paths (see below). Use exclude to disable FCKeditor on selected fields/paths. Use include if you want to load FCKeditor only on selected paths/fields.'), ); /** * 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']['excl_fields'] = array( '#type' => 'textarea', '#title' => t('Fields to exclude/include'), '#cols' => 60, '#rows' => 5, '#prefix' => '
      ', '#suffix' => '
      ', '#default_value' => $edit->settings['excl_fields'] ? $edit->settings['excl_fields'] : '', '#description' => t("Enter names (HTML ID's) of fields that may or may not have an FCKeditor, depending on the chosen option for the inclusion/exclusion mode.
      You may separate the different entries by commas, spaces or newlines.
      You may also use * as a wildcard character."), ); /** * get excluded paths - 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']['excl_paths'] = array( '#type' => 'textarea', '#title' => t('Paths to exclude/include'), '#prefix' => '
      ', '#suffix' => '
      ', '#cols' => 60, '#rows' => 5, '#default_value' => $edit->settings['excl_paths'] ? $edit->settings['excl_paths'] : '', '#description' => t("Enter drupal paths here, depending on the chosen option for the inclusion/exclusion mode.
      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 (for example comment/*)."), ); $form['fckeditor_exclude_settings']['simple_incl_fields'] = array( '#type' => 'textarea', '#title' => t('Force simplified toolbar on the following fields'), '#cols' => 60, '#rows' => 5, //'#prefix' => t('Here you can define where FCKeditor should force the !simple toolbar.
      Useful for smaller textareas where we usually don\'t use very complicated HTML code, like in signatures.', array('!simple' => FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME)), '#default_value' => $edit->settings['simple_incl_fields'] ? $edit->settings['simple_incl_fields'] : '', '#description' => t("Enter names (HTML ID's) of fields that should have the simplified toolbar (!name).
      If you don't want to use this feature, simply leave this field empty.
      You may separate the different entries by commas, spaces or newlines.", array("!name" => FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME)), ); $form['fckeditor_exclude_settings']['simple_incl_paths'] = array( '#type' => 'textarea', '#title' => t('Force simplified toolbar on the following paths'), '#cols' => 60, '#rows' => 5, //'#prefix' => t('Here you can define where FCKeditor should force the !simple toolbar.
      Useful for smaller textareas where we usually don\'t use very complicated HTML code, like in signatures.', array('!simple' => FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME)), '#default_value' => $edit->settings['simple_incl_paths'] ? $edit->settings['simple_incl_paths'] : '', '#description' => t("Enter drupal paths that should have the simplified toolbar (!name).
      If you don't want to use this feature, simply leave this field empty.
      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 (for example comment/*).", array("!name" => FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME)), ); $form['appearance'] = array( '#type' => 'fieldset', '#title' => t('Editor appearance'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['appearance']['default'] = array( '#type' => 'select', '#title' => t('Default state'), '#default_value' => $edit->settings['default'] ? $edit->settings['default'] : 't', '#options' => array('t' => t('enabled'), 'f' => t('disabled')), '#description' => t('Default editor state. If disabled, rich text editor may still be enabled using toggle or popup window.'), ); $form['appearance']['show_toggle'] = array( '#type' => 'select', '#title' => t('Show disable/enable rich text editor toggle'), '#default_value' => $edit->settings['show_toggle'] ? $edit->settings['show_toggle'] : 't', '#options' => array('t' => t('true'), 'f' => t('false')), '#description' => t('Whether or not to show the disable/enable rich text editor toggle below the textarea. Works only if FCKeditor is not running in a popup window (see below).'), ); $form['appearance']['popup'] = array( '#type' => 'select', '#title' => t('Use FCKeditor in a popup window'), '#default_value' => $edit->settings['popup'] ? $edit->settings['popup'] : 'f', '#options' => array('f' => t('false'), 't' => t('true')), '#description' => t('If this option is enabled a link to a popup window will be used instead of a textarea replace.'), ); $form['appearance']['skin'] = array( '#type' => 'select', '#title' => t('Skin'), '#default_value' => $edit->settings['skin'] ? $edit->settings['skin'] : 'default', '#options' => $skin_options, '#description' => t('Choose a default skin.'), ); $form['appearance']['toolbar'] = array( '#type' => 'select', '#title' => t('Toolbar'), '#default_value' => $edit->settings['toolbar'] ? $edit->settings['toolbar'] : 'default', '#options' => $toolbar_options, '#description' => t('Choose a default toolbar set. To define new toolbar, edit fckeditor.config.js located in !module_path.', array('!module_path' => drupal_get_path('module', 'fckeditor'))), ); $form['appearance']['expand'] = array( '#type' => 'select', '#title' => t('Start the toolbar expanded'), '#default_value' => $edit->settings['expand'] ? $edit->settings['expand'] : 't', '#options' => array('t' => t('enabled'), 'f' => t('disabled')), '#description' => t('The toolbar start expanded or collapsed.'), ); $form['appearance']['width'] = array( '#type' => 'textfield', '#title' => t('Width'), '#default_value' => $edit->settings['width'] ? $edit->settings['width'] : '100%', '#description' => t("Width in pixels or percent. Ex: 400 or 100%"), '#size' => 40, '#maxlength' => 128, ); $form['appearance']['lang'] = array( '#type' => 'select', '#title' => t('Language'), '#default_value' => $edit->settings['lang'] ? $edit->settings['lang'] : 'en', '#options' => $lang_options, '#description' => t('The language for the FCKeditor interface.') ); $form['appearance']['auto_lang'] = array( '#type' => 'select', '#title' => t('Auto-detect language'), '#default_value' => $edit->settings['auto_lang'] ? $edit->settings['auto_lang'] : 't', '#options' => array('t' => t('true'), 'f' => t('false')), '#description' => t('Use auto detect user language feature.') ); /* $form['appearance']['appearance_conf'] = array( '#type' => 'select', '#title' => t('Ignore this section, use default settings defined in config files'), '#default_value' => $edit->settings['appearance_conf'] ? $edit->settings['appearance_conf'] : 'f', '#options' => array('f' => t('false'), 't' => t('true')), '#description' => t('Although it is less handy, defining settings only in config files (fckconfig.js and fckeditor.config.js) will slightly leverage your traffic and improve load time of your site.
      Warning: if set to true, all changes made in Editor appearance will have no affect on FCKeditor\'s behaviour.'), ); */ $form['output'] = array( '#type' => 'fieldset', '#title' => t('Cleanup and output'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['output']['enter_mode'] = array( '#type' => 'select', '#title' => t('Enter mode'), '#default_value' => $edit->settings['enter_mode'] ? $edit->settings['enter_mode'] : 'p', '#options' => array('p' => '

      ', 'br' => '
      ', 'div' => '

      '), '#description' => t('Set which tag FCKeditor should use when [Enter] key is pressed.') ); $form['output']['shift_enter_mode'] = array( '#type' => 'select', '#title' => t('Shift + Enter mode'), '#default_value' => $edit->settings['shift_enter_mode'] ? $edit->settings['shift_enter_mode'] : 'br', '#options' => array('p' => '

      ', 'br' => '
      ', 'div' => '

      '), '#description' => t('Set which tag FCKeditor should use when [Shift] + [Enter] is pressed.') ); $form['output']['font_format'] = array( '#type' => 'textfield', '#title' => t('Font formats'), '#default_value' => $edit->settings['font_format'] ? $edit->settings['font_format'] : 'p;div;pre;address;h1;h2;h3;h4;h5;h6', '#size' => 40, '#maxlength' => 250, '#description' => t('Semicolon separated list of HTML font formats. Allowed values are: p;div;pre;address;h1;h2;h3;h4;h5;h6'), ); $form['output']['format_source'] = array( '#type' => 'select', '#title' => t('Apply source formatting'), '#default_value' => $edit->settings['format_source'] ? $edit->settings['format_source'] : 't', '#options' => array('t' => t('true'), 'f' => t('false')), '#description' => t('When set to "true" the editor will format the XHTML when switching from WYSIWYG view to Source view, by inserting line breaks on some tags endings and indenting paragraphs, tables and lists.'), ); $form['output']['format_output'] = array( '#type' => 'select', '#title' => t('Format output'), '#default_value' => $edit->settings['format_output'] ? $edit->settings['format_output'] : 't', '#options' => array('t' => t('true'), 'f' => t('false')), '#description' => t('When set to "true" the editor will format the XHTML output by inserting line breaks on some tags endings and indenting paragraphs, tables and lists.'), ); /* $form['output']['output_conf'] = array( '#type' => 'select', '#title' => t('Ignore this section, use default settings defined in config files'), '#default_value' => $edit->settings['output_conf'] ? $edit->settings['output_conf'] : 'f', '#options' => array('f' => t('false'), 't' => t('true')), '#description' => t('Although it is less handy, defining settings only in config files (fckconfig.js and fckeditor.config.js) will slightly leverage your traffic and improve load time of your site.
      Warning: if set to true, all changes made in Cleanup and output will have no affect on FCKeditor\'s behaviour.'), ); */ $form['css'] = array( '#type' => 'fieldset', '#title' => t('CSS'), '#collapsible' => TRUE, '#collapsed' => TRUE ); $form['css']['css_mode'] = array( '#type' => 'select', '#title' => t('Editor CSS'), '#default_value' => $edit->settings['css_mode'] ? $edit->settings['css_mode'] : 'theme', '#options' => array('theme' => t('use theme css'), 'self' => t('define css'), 'none' => t('FCKeditor default')), '#description' => t('Defines the CSS to be used in the editor area.
      use theme css - load style.css from current site theme.
      define css - enter path for css file below.
      FCKeditor default - uses default CSS from editor.') ); $form['css']['css_path'] = array( '#type' => 'textfield', '#title' => t('CSS path'), '#default_value' => $edit->settings['css_path'], '#size' => 40, '#maxlength' => 255, '#description' => t('Enter path to CSS file (example: css/editor.css) or a list of css files separated by a comma (example: /themes/garland/style.css,http://example.com/style.css).
      Macros: %h (host name: !host), %t (path to theme: !theme)
      Be sure to select "define css" above.', array('!host' => base_path(), '!theme' => base_path() . path_to_theme() .'/')) ); $form['css']['css_style'] = array( '#type' => 'select', '#title' => t('Predefined styles'), '#default_value' => $edit->settings['css_style'] ? $edit->settings['css_style'] : 'theme', '#options' => array('theme' => t('use theme fckstyles.xml'), 'self' => t('define path to fckstyles.xml'), 'default' => t('FCKeditor default')), '#description' => t('Define the location of fckstyles.xml file. It is used by the "Style" dropdown list available in the Default toolbar.
      Copy !fckstyles.xml inside your theme directory (!theme) and adjust it to your needs.', array('!fckstyles.xml' => drupal_get_path('module', 'fckeditor') .'/fckeditor/fckstyles.xml', '!theme' => path_to_theme() .'/fckstyles.xml')) ); $form['css']['styles_path'] = array( '#type' => 'textfield', '#title' => t('Predefined styles path'), '#default_value' => $edit->settings['styles_path'], '#size' => 40, '#maxlength' => 255, '#description' => t('Enter path to XML file with predefined styles (example: /fckstyles.xml).
      Macros: %h (host name: !host), %t (path to theme: !theme), %m (path to FCKeditor module: !module)
      Be sure to select "define path to fckstyles.xml" above.', array('!host' => base_path(), '!theme' => base_path() . path_to_theme() .'/', '!module' => drupal_get_path('module', 'fckeditor'))) ); // 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', '#title' => t('File browser settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#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', '#title' => t('File browser settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#description' => t('Set file browser settings. If you enable file uploads and disable basic and advanced file management, 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.
      ', array( '!imce' => l(t('IMCE'), 'http://drupal.org/project/imce'), '!readme' => l('readme.txt', 'admin/help/fckeditor'), ) ) ); $form['fckeditor_upload_settings']['upload_basic'] = array( '#type' => 'select', '#options' => array('f' => t('false'), 't' => t('true')), '#title' => t('Allow basic file management'), '#default_value' => $edit->settings['upload_basic'] ? $edit->settings['upload_basic'] : 'f', '#description' => t("Allow quick uploads."), ); $form['fckeditor_upload_settings']['upload_advanced'] = array( '#type' => 'select', '#options' => array('f' => t('false'), 't' => t('true')), '#title' => t('Allow advanced file management'), '#default_value' => $edit->settings['upload_advanced'] ? $edit->settings['upload_advanced'] : 'f', '#description' => t('Allow file management in the advanced file manager.'), ); $current_user_files_path = strtr($edit->settings['UserFilesPath'], array("%f" => file_directory_path(), "%u" => "UID", "%b" => base_path())); $current_user_files_absolute_path = strtr($edit->settings['UserFilesAbsolutePath'], array("%f" => file_directory_path(), "%u" => "UID", "%b" => base_path(), "%d" => $_SERVER['DOCUMENT_ROOT'])); $form['fckeditor_upload_settings']['UserFilesPath'] = array( '#type' => 'textfield', '#title' => t('Path to uploaded files'), '#default_value' => $edit->settings['UserFilesPath'] ? $edit->settings['UserFilesPath'] : "%b%f/", '#size' => 40, '#maxlength' => 255, '#description' => t('Path to uploaded files relative to the document root.
      Available wildcard characters:
      %b - base URL path of the Drupal installation (!base).
      %f - Drupal file system path where the files are stored (!files).
      %u - User ID.
      Current path: !path', array('!path' => $current_user_files_path, '!files' => file_directory_path(), '!base' => base_path())), ); $form['fckeditor_upload_settings']['UserFilesAbsolutePath'] = array( '#type' => 'textfield', '#title' => t('Absolute path to uploaded files'), '#default_value' => $edit->settings['UserFilesAbsolutePath'] ? $edit->settings['UserFilesAbsolutePath'] : "%d%b%f/", '#size' => 40, '#maxlength' => 255, '#description' => t('The path to the local directory (in the server) which points to the path defined above. If empty, FCKeditor will try to discover the right path.
      Available wildcard characters:
      %d - server path to document root (!root).
      %b - base URL path of the Drupal installation (!base).
      %f - Drupal file system path where the files are stored (!files).
      %u - User ID.
      Current path: !path', array('!path' => $current_user_files_absolute_path, '!files' => file_directory_path(), '!base' => base_path(), '!root' => $_SERVER['DOCUMENT_ROOT'])), ); if (variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE) { $form['fckeditor_upload_settings']['UserFilesPath']['#description'] = t('Setting relative path to uploaded files has been disabled because private downloads are enabled and this path is calculated automatically. To change the location of uploaded files in the private file system, edit the FCKeditor Global Profile.', array('!url' => url('admin/settings/fckeditor/editg'))); $form['fckeditor_upload_settings']['UserFilesPath']['#disabled'] = TRUE; $form['fckeditor_upload_settings']['UserFilesAbsolutePath']['#description'] = t('Setting path to uploaded files has been disabled because private downloads are enabled and this path is calculated automatically.To change the location of uploaded files in the private file system, edit the FCKeditor Global Profile.', array('!global' => url('admin/settings/fckeditor/editg'))); $form['fckeditor_upload_settings']['UserFilesAbsolutePath']['#disabled'] = TRUE; } } $form['advanced'] = array( '#type' => 'fieldset', '#title' => t('Advanced options'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['advanced']['theme_config_js'] = array( '#title' => t('Load fckeditor.config.js from theme path'), '#default_value' => !empty($edit->settings['theme_config_js']) ? $edit->settings['theme_config_js'] : 'f', '#type' => 'select', '#options' => array('f' => t('false'), 't' => t('true')), '#description' => t('When set to "true" the editor will try to load the fckeditor.config.js file from theme directory.'), ); if (function_exists('linktocontent_node_menu') && function_exists('pathfilter_filter')) { $form['advanced']['linktoc'] = array( '#type' => 'select', '#options' => array('p' => t('Link to paths only'), 'n' => t('Link using internal: links'), 'pn' => t('Allow user to select between paths and internal links')), '#title' => t('Path Filter & Link To Content integration'), '#default_value' => empty($edit->settings['linktoc']) ? 'p' : $edit->settings['linktoc'], '#description' => t('With !plink extension it is possible to use :internal links. By default !link extension is linking to nodes using paths.', array('!plink' => l(t('Path Filter'), 'http://drupal.org/project/pathfilter'), '!link' => l(t('Link To Content'), 'http://drupal.org/project/linktocontent'))), ); } $form['advanced']['js_conf'] = array( '#type' => 'textarea', '#title' => t('Custom javascript configuration'), '#default_value' => $edit->settings['js_conf'], '#cols' => 60, '#rows' => 5, '#description' => t('Warning: to change FCKeditor configuration globally, you should modify the config file: !fckeditor_config.
      Sometimes it is required to change the FCKeditor configuration for selected profile. Use this box to define settings that are unique for this profile.
      Available options are listed in the !docs.
      Warning: if you make something wrong here, FCKeditor may fail to load.
      For example to disable some advanced tabs in dialog windows in FCKeditor, add the following: !example', array( '!fckeditor_config' => drupal_get_path('module', 'fckeditor') ."/fckeditor.config.js", '!docs' => l(t("FCKeditor documentation"), "http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Configuration/Configuration_Options"), "!example" => "
      LinkDlgHideTarget = true ;
      LinkDlgHideAdvanced = true ;
      ImageDlgHideLink = true ;
      ImageDlgHideAdvanced = true ;
      FlashDlgHideAdvanced = true ;
      ") )); $form['submit'] = array( '#type' => 'submit', '#value' => $btn ); return $form; } /** * 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 * Use built-in test method in fckeditor.php * If fckeditor.php is not found, return false (probably in such case fckeditor is not installed correctly) * * @return * TRUE if the browser is reasonably capable */ function fckeditor_is_compatible_client() { $fckeditor_main_file = drupal_get_path('module', 'fckeditor') .'/fckeditor/fckeditor.php'; if (!function_exists('version_compare') || version_compare(phpversion(), '5', '<')) { $fckeditor_target_file = drupal_get_path('module', 'fckeditor') .'/fckeditor/fckeditor_php4.php'; } else { $fckeditor_target_file = drupal_get_path('module', 'fckeditor') .'/fckeditor/fckeditor_php5.php'; } if (file_exists($fckeditor_target_file)) { include_once $fckeditor_target_file; //FCKeditor 2.6.1+ if (function_exists('FCKeditor_IsCompatibleBrowser')) { return FCKeditor_IsCompatibleBrowser(); } else if (class_exists('FCKeditor')) { //FCKeditor 2.5.1 - 2.6 with definition of FCKeditor_IsCompatibleBrowser() in fckeditor.php if (filesize($fckeditor_main_file) > 1500) { include_once $fckeditor_main_file; } //FCKeditor 2.5 and earlier $fck = new FCKeditor('fake'); return $fck->IsCompatible(); } } return FALSE; } function fckeditor_user_get_setting($user, $profile, $setting) { $default = array( 'default' => 't', 'show_toggle' => 't', 'popup' => 'f', 'skin' => 'default', 'toolbar' => 'default', 'expand' => 't', 'width' => '100%', 'lang' => 'en', 'auto_lang' => 't', ); $settings = $profile->settings; if ($settings['allow_user_conf']) { $status = isset($user->{"fckeditor_". $setting}) ? $user->{"fckeditor_". $setting} : (isset($settings[$setting]) ? $settings[$setting] : $default[$setting]); } else { $status = isset($settings[$setting]) ? $settings[$setting] : $default[$setting]; } return $status; } function fckeditor_user_get_profile($user, $clear = FALSE) { static $profile_name = NULL; if ($clear === TRUE || $profile_name == NULL) { $profile_name = array(); } // Since fckeditor_profile_load() makes a db hit, only call it when we're pretty sure // we're gonna render fckeditor. if (!isset($profile_name[$user->uid])) { $sorted_roles = fckeditor_sorted_roles(); foreach ($sorted_roles as $rid => $name) { if (isset($user->roles[$rid])) { break; } } if (isset($user->roles[$rid])) { $profile_name[$user->uid] = db_result(db_query("SELECT s.name FROM {fckeditor_settings} s INNER JOIN {fckeditor_role} r ON r.name = s.name WHERE r.rid='%s'", $rid)); } else if ($user->uid == "1") { $profile_name[$user->uid] = db_result(db_query_range("SELECT s.name FROM {fckeditor_settings} s INNER JOIN {fckeditor_role} r ON r.name = s.name ORDER BY r.rid DESC", 1)); } } if (isset($profile_name[$user->uid]) && $profile_name[$user->uid]) { $profile = fckeditor_profile_load($profile_name[$user->uid]); return $profile; } return FALSE; } /** * Implementation of hook_file_download(). * Support for private downloads. * FCKeditor does not implement any kind of potection on private files. */ function fckeditor_file_download($file) { if ($path = file_create_path($file)) { $result = db_query("SELECT f.* FROM {files} f WHERE filepath = '%s'", $path); if (db_fetch_object($result)) { return NULL; } //No info in DB? Probably a file uploaded with FCKeditor $global_profile = fckeditor_profile_load("FCKeditor Global Profile"); //Assume that files inside of fckeditor directory belong to the FCKeditor. If private directory is set, let the decision about protection to the user. $private_dir = isset($global_profile->settings['private_dir']) ? trim($global_profile->settings['private_dir'], '\/') : ''; $private_dir = preg_quote($private_dir, '#'); $private_dir = strtr($private_dir, array('%u' => '(\d+)')); $private_dir = trim($private_dir, '\/'); $regex = '#^'. preg_quote(file_directory_path() .'/', '#') . $private_dir .'#'; //If path to the file points to the FCKeditor private directory, allow downloading if (preg_match($regex, $path)) { $ctype = ($info = @getimagesize($path)) ? $info['mime'] : (function_exists('mime_content_type') ? mime_content_type($path) : 'application/x-download'); return array('Content-type: '. $ctype); } } } function fckeditor_ask_delete_confirmation($is_global, $profile = "") { if (!$is_global) { $delete_link = l(t('Yes, delete!'), 'admin/settings/fckeditor/deleteconfirmed/'. urlencode($profile)); $profile_name = t('!profile profile', array('!profile' => $profile)); } else { $delete_link = l(t('Yes, delete!'), 'admin/settings/fckeditor/deletegconfirmed'); $profile_name = t('Global Profile'); } drupal_set_title(t('Confirm profile deletion')); drupal_set_message(t("You're about to delete the FCKeditor profile, read the question below carefully."), "warning"); return t("

      Are you sure that you want to delete the !profile?

      !yes !no

      ", array('!profile' => $profile_name, '!yes' => $delete_link, '!no' => l(t('Cancel'), 'admin/settings/fckeditor', array('style' => 'margin-left:40px')), )); }