4 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
5 * Copyright (C) 2003-2007 Frederico Caldeira Knabben
9 * Licensed under the terms of any of the following licenses at your
12 * - GNU General Public License Version 2 or later (the "GPL")
13 * http://www.gnu.org/licenses/gpl.html
15 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
16 * http://www.gnu.org/licenses/lgpl.html
18 * - Mozilla Public License Version 1.1 or later (the "MPL")
19 * http://www.mozilla.org/MPL/MPL-1.1.html
24 * FCKeditor Module for Drupal 5.x
26 * This module allows Drupal to replace textarea fields with FCKeditor.
28 * This HTML text editor brings to the web many of the powerful functionalities
29 * of known desktop editors like Word. It's really lightweight and doesn't
30 * require any kind of installation on the client computer.
34 * The name of simplified toolbar which should be forced
35 * Be sure that this toolbar is defined in fckeditor.config.js or fckconfig.js
37 define('FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME', 'DrupalBasic') ;
40 * Implementation of hook_help
42 function fckeditor_help($section = '') {
43 if (strpos($section, 'admin/settings/fckeditor/edit/') === 0 || $section == 'admin/settings/fckeditor/add') {
44 $output = t("<p>Note: FCKeditor is highly configurable. The most commonly used features are listed below. If you want to take a look at all available settings, open <code>!fckconfig</code> and then customize <code>!fckeditor_config</code> to your needs. This is also the only way to define new toolbar sets. It is advised to not edit <code>fckconfig.js</code> because you may overwrite it accidentally when you update the editor.</p>", array('!fckconfig' => drupal_get_path('module', 'fckeditor') .
"/fckeditor/fckconfig.js", '!fckeditor_config' => drupal_get_path('module', 'fckeditor') .
"/fckeditor.config.js"));
48 case
'admin/settings/help#description':
49 $output = t("Enables the usage of FCKeditor (WYSIWYG editor) instead of plain text fields.");
51 case
'admin/settings/fckeditor/addg':
52 case
'admin/settings/fckeditor/editg':
53 $output = t("<p>The Global Profile allows you to define settings that are common for all profiles. Values defined in other profiles will be appended to the global configuration. This way you can avoid repeating some of the settings that are usually the same in each profile.</p>");
55 case
'admin/settings/fckeditor':
56 $output = t("<p>The FCKeditor module allows Drupal to replace textarea fields with a rich text or <acronym title=\"What You See Is What You Get\">WYSIWYG</acronym> editor. This editor brings many of the powerful functionalities of known desktop editors like Word to the web. It's relatively lightweight and doesn't require any kind of installation on the client computer.</p><p>More information about the editor is located at the !fckeditorlink. A small user guide is located at !userguidelink.</p>",
58 '!fckeditorlink' => l(t('FCKeditor homepage'), 'http://www.fckeditor.net'),
59 '!userguidelink' => l(t('FCKeditor userguide'), 'http://docs.fckeditor.net/FCKeditor/Users_Guide'))
61 $output .
= t('<p>Profiles can be defined based on user roles. A FCKeditor profile can define which pages receive this FCKeditor capability, what buttons or themes are enabled for the editor, how the editor is displayed, and a few other editor functions. It is possible also to define the Global Profile that will hold values that will be appended to all other profiles.</p><p>Lastly, only users with the <code>!access1</code> !permission will be able to use FCKeditor. </p>', array('!permission' => l(t('permission'), 'admin/user/access'), '!access1' => t('access fckeditor')));
63 case
'admin/help#fckeditor':
64 $output = t("<p>The FCKeditor module allows Drupal to replace textarea fields with a rich text or <acronym title=\"What You See Is What You Get\">WYSIWYG</acronym> editor. This editor brings many of the powerful functionalities of known desktop editors like Word to the web. It's relatively lightweight and doesn't require any kind of installation on the client computer.</p><p>More information is located at the !fckeditorlink. A small user guide is located at !userguidelink.</p>",
66 '!fckeditorlink' => l(t('FCKeditor homepage'), 'http://www.fckeditor.net'),
67 '!userguidelink' => l(t('FCKeditor userguide'), 'http://docs.fckeditor.net/FCKeditor/Users_Guide'))
69 $output .
= t('<h3>Installation</h3><p>Go to the !fckeditorlink and download the latest version. Then uncompress the contents of the "fckeditor" directory of the downloaded file to %fckeditordir.</p>',
71 '!fckeditorlink' => l(t('FCKeditor homepage'), 'http://www.fckeditor.net/download'),
72 '%fckeditordir' => base_path() .
drupal_get_path('module', 'fckeditor') .
'/fckeditor/')
74 $output .
= t('<h3>Configuration</h3><ol><li>Enable the module as usual from Drupal\'s admin pages.</li><li>Grant permissions for use of FCKeditor in <code>!path2</code></li><li>Under <code>!path1</code>, create the fckeditor profiles. In each profile you can choose which textareas will be replaced by FCKeditor, select default toolbar and configure some more advanced settings </li><li>For the Rich Text Editing to work you also need to configure your !filterlink for the users that may access Rich Text Editing. Either grant those users Full HTML access or use the following: <br/><code>!filter</code>. </li><li>To have a better control over line breaks, you may disable <code>Line break converter</code> in the chosen filter (recommended).</li><li>Modify the fckeditor.config.js file to custom your needs (optional).<br />You may copy the needed configuration lines from the default FCKeditor configuration settings (modules/fckeditor/fckeditor/fckconfig.js), the lines in fckeditor.config.js will override most settings.</li></ol>',
76 '!path1' => l(t('Administer > Settings > FCKeditor'), 'admin/settings/fckeditor'),
77 '!path2' => l(t('Administer > User Management > Access Control'), 'admin/user/access'),
78 '!filter' => htmlentities('<a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area>
79 <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em>
80 <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote>
81 <pre> <address> <code> <cite> <embed> <object> <strike> <caption>'),
82 '!filterlink' => l(t('filters'), 'admin/settings/filters'))
84 $output .
= t('<h3>Installation troubleshooting</h3><p>If your FCKeditor does not show you must check if all files are extracted correctly. The directory %fckeditordir should have the following files <code>fckeditor.js, fckconfig.js, fckstyles.xml, fcktemplates.xml</code> and a directory named <code>editor</code>.</p>',
86 '%fckeditordir' => base_path() .
drupal_get_path('module', 'fckeditor') .
'/fckeditor/')
88 $output .
= t('The correct directory structure is as follows: <blockquote><pre>!structure</pre></blockquote>', array(
89 '!structure' => "modules\n fckeditor\n <em>fckeditor.module</em>\n fckeditor\n _samples\n editor\n <em>COPY_HERE.txt</em>\n <em>fckconfig.js</em>\n ..."
91 $output .
= t("<h3>Plugins: Teaser break and Pagebreak</h3><p>By default, FCKeditor module comes with two plugins that can handle teaser break (<!--break-->) and pagebreak (<!--pagebreak-->). You can enable any (or even both) of them.<ol><li>Open <code>!fckeditor.config.js</code> and uncomment these three lines: <pre>!code</pre></li><li>The second step is to add buttons to the toolbar (in the same file). The button names are: <code>DrupalBreak, DrupalPageBreak</code>. For example if you have a toolbar with an array of buttons defined as follows: <pre>!buttons1</pre> simply add those two buttons at the end of array: <pre>!buttons2</pre> (remember about single quotes).</li></ol></p>",
93 '!fckeditor.config.js' => base_path() .
drupal_get_path('module', 'fckeditor') .
'/fckeditor.config.js',
95 FCKConfig.PluginsPath = '../../plugins/' ;
96 FCKConfig.Plugins.Add( 'drupalbreak' ) ;
97 FCKConfig.Plugins.Add( 'drupalpagebreak' ) ;
99 '!buttons1' => "['Image','Flash','Table','Rule','SpecialChar']",
100 '!buttons2' => "['Image','Flash','Table','Rule','SpecialChar', 'DrupalBreak', 'DrupalPageBreak']",
102 $output .
= t('<h3>Uploading images and files</h3><p>There are three ways of uploading files: By using the built-in file browser, by using a module like !imce or using the core upload module.</p>',
104 '!imce' => l(t('IMCE'), 'http://drupal.org/project/imce')
107 // the rest is untranslated for the moment
108 $output .
= t("<h3>How to enable the file browser</h3><p>The editor gives the end user the flexibility to create a custom file browser that can be integrated on it. The included file browser allows users to view the content of a specific directory on the server and add new content to that directory (create folders and upload files).</p><p><ol><li>To enable file browsing you need to edit the connector configuration file in your fckeditor module directory, the file should be in:<blockquote><code>!config3</code> <br/> (FCKeditor 2.5+)<br/><br/> or <br/><br/><code>!config1</code><br/> and <br/><code>!config2</code> <br/> (FCKeditor 2.3.x - 2.4.x)</blockquote></p><p>In this file(s) you will need to enable the file browser by adding one line that includes file with the special authentication function for Drupal (<code>filemanager.config.php</code>). Add this code: <blockquote><code>!code1</code><br/> (FCKeditor 2.5+)</blockquote> or <blockquote><code>!code2</code> <br/> (FCKeditor 2.3.x - 2.4.x)</blockquote> straight below this line: <blockquote><code>!code3</code></blockquote> The config.php file also holds some other important settings, please take a look at it and adjust it to your needs (optional).</p></li>",
109 array('!config1' => base_path() .
drupal_get_path('module', 'fckeditor') .
"/fckeditor/editor/filemanager/browser/default/connectors/php/config.php",
110 '!config2' => base_path() .
drupal_get_path('module', 'fckeditor') .
"/fckeditor/editor/filemanager/upload/php/config.php",
111 '!config3' => base_path() .
drupal_get_path('module', 'fckeditor') .
"/fckeditor/editor/filemanager/connectors/php/config.php",
112 '!filesdir' => file_directory_path(),
113 '!code1' => 'require_once "../../../../../filemanager.config.php";', //2.5
114 '!code2' => 'require_once "'.
str_replace("\\", "\\\\", dirname(__FILE__
) . DIRECTORY_SEPARATOR .
'filemanager.config.php"'), //2.4
115 '!code3' => "\$Config['UserFilesAbsolutePath'] = '' ;",
118 $output .
= t("<li>As of Drupal 5.2, additional step is required: locate file named <code>settings.php</code> inside your drupal directory (usually <code>sites/default/settings.php</code>) and set <strong><code>$cookie_domain</code></strong> variable to the appropiate domain (remember to uncomment that line). If you not do this, FCKeditor will claim that file browser is disabled</li>");
119 $output .
= t('<li>Enabling file uploads is <strong>a security risk</strong>. That\'s why you have to grant a !link to enable the file browser to certain groups.</li>', array('!link' => l(t('separate permission'), 'admin/user/access')));
120 $output .
= t('<li>Lastly, adjust the !fb for each !profile.</li></ol>', array('!fb' => t('File browser settings'), '!profile' => l(t('profile'), 'admin/settings/fckeditor')));
121 $output .
= t("<h3>Modules: Image Assist</h3><p>Image Assist can be integrated with FCKeditor. To do this, simply copy the <code>!iaf1</code> file to <code>!iaf2</code>.</p>", array("!iaf1" => drupal_get_path('module', 'fckeditor') .
"/img_assist_fckeditor.js", "!iaf2" => drupal_get_path('module', 'img_assist') .
"/img_assist_fckeditor.js"));
129 * Implementation of hook_perm
130 * Administer -> User management -> Access Control
132 function fckeditor_perm() {
133 return array('administer fckeditor', 'access fckeditor', 'allow fckeditor file uploads');
138 * Implementation of textarea
139 * Replace textarea with FCKeditor using callback function (fckeditor_process_textarea)
141 function fckeditor_elements() {
143 $type['textfield'] = array(
145 'fckeditor_process_input' => array()
148 if (user_access('access fckeditor')) {
149 // only roles with permission get the fckeditor
150 if (fckeditor_is_compatible_client()) {
151 // it would be useless to dig deeper if we're not able or allowed to
152 $type['textarea'] = array(
154 'fckeditor_process_textarea' => array()
163 * Allow more than 255 chars in Allowed HTML tags textfield
166 function fckeditor_process_input($element) {
167 if ($element['#id']=='edit-allowed-html-1') {
168 $element['#maxlength'] = max($element['#maxlength'], 1024);
174 * Add link to FCKeditor configuration in "Administer -> Site configuration" section
177 function fckeditor_menu($may_cache) {
181 'path' => 'admin/settings/fckeditor',
182 'title' => t('FCKeditor'),
183 'callback' => 'fckeditor_admin',
184 'description' => t('Configure the rich editor.'),
185 'access' => user_access('administer fckeditor'));
188 drupal_add_css(drupal_get_path('module', 'fckeditor') .
'/fckeditor.css');
193 //Remove a profile from the database.
194 function fckeditor_profile_delete($name) {
195 db_query("DELETE FROM {fckeditor_settings} WHERE name = '%s'", $name);
196 db_query("DELETE FROM {fckeditor_role} WHERE name = '%s'", $name);
200 * Profile validation.
202 function fckeditor_profile_validate($edit) {
205 if ($edit['excl_mode'] == 1 && !$edit['excl_fields'] && !$edit['excl_paths']) {
206 $errors['excl_mode'] = t('Include mode selected, but no fields/paths given. Enter at least one path or field where FCKeditor should appear.');
209 if (!preg_match("/^\d+$/", trim($edit['min_rows']))) {
210 $errors['min_rows'] = t('Minimum rows must be a valid number');
213 if ($edit['default'] == 't' && $edit['popup'] == 't') {
214 $errors['popup'] = t('If FCKeditor is enabled by default, popup window must be disabled.');
217 if ($edit['show_toggle'] == 't' && $edit['popup'] == 't') {
218 $errors['popup'] = t('If toggle is enabled, popup window must be disabled.');
221 if (!$edit['name']) {
222 $errors['name'] = t('You must give a profile name.');
225 if (!preg_match("/^\d+%?$/", $edit['width'])) {
226 $errors['width'] = t('Enter valid width. Ex: 400 or 100%');
229 if (!empty($edit['css_path'])) {
230 if ($edit['css_mode'] != 'self') {
231 $errors['css_path'] = t('CSS path is not empty. Please set the "Editor CSS" option to "define css" mode.');
233 else if (false
!== strpos($edit['css_path'], '"')) {
234 $errors['css_path'] = t('Double quotes are not allowed in CSS path.');
236 else if (substr($edit['css_path'], 0, 1) == "'" && substr($edit['css_path'], -1) == "'") {
237 $errors['css_path'] = t('Enter valid path, do not surround it with quotes.');
241 if (!empty($edit['styles_path'])) {
242 if ($edit['css_style'] != 'self') {
243 $errors['styles_path'] = t('Path to predefined styles is not empty. Please set the "Predefined styles" option to "define path to fckstyles.xml" mode.');
245 else if (false
!== strpos($edit['styles_path'], '"')) {
246 $errors['styles_path'] = t('Double quotes are not allowed in path.');
248 else if (substr($edit['styles_path'], 0, 1) == "'" && substr($edit['styles_path'], -1) == "'") {
249 $errors['styles_path'] = t('Enter valid path, do not surround it with quotes.');
253 if (!empty($edit['font_format'])) {
254 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'])) {
255 $errors['font_format'] = t('Enter valid, semicolon separated, list of HTML font formats (no semicolon at the end of list expected).');
260 $fields = preg_split("/[\s,]+/", strip_tags($edit['excl_fields']));
261 foreach ($fields as
$field) {
262 if ($field && !preg_match("/^[a-z]+(\-[[:alnum:]]+)+$/i", $field)) {
263 $errors['excl_fields'] = t("Invalid field specified: %1", array("%1" => $field));
268 $fields = preg_split("/[\s,]+/", strip_tags($edit['simple_incl_fields']));
269 foreach ($fields as
$field) {
270 if ($field && !preg_match("/^[a-z]+(\-[[:alnum:]]+)+$/i", $field)) {
271 $errors['excl_fields'] = t("Invalid field specified: %1", array("%1" => $field));
277 $paths = preg_split("/[\s,]+/", strip_tags($edit['excl_paths']));
278 foreach ($paths as
$path) {
279 if ($path && !preg_match("|^[_a-z0-9-\*/]*$|i", $path)) {
280 $errors['excl_paths'] = t("Invalid path specified: %1", array("%1" => $path));
285 $paths = preg_split("/[\s,]+/", strip_tags($edit['simple_incl_paths']));
286 foreach ($paths as
$path) {
287 if ($path && !preg_match("|^[_a-z0-9-\*/]*$|i", $path)) {
288 $errors['excl_paths'] = t("Invalid path specified: %1", array("%1" => $path));
293 if (variable_get('file_downloads', '') !== FILE_DOWNLOADS_PRIVATE
) {
294 if ($edit['UserFilesAbsolutePath'] && !$edit['UserFilesPath']) {
295 $errors['UserFilesPath'] = t("Path to uploaded files is required.");
297 if ($edit['UserFilesPath'] && !$edit['UserFilesAbsolutePath']) {
298 $errors['UserFilesPath'] = t("Absolute path to uploaded files is required.");
302 foreach ($errors as
$name => $message) {
303 form_set_error($name, $message);
306 return count($errors) == 0;
310 * Global profile validation.
312 function fckeditor_global_profile_validate($edit) {
315 if ($edit['excl_mode'] == 1 && !$edit['excl_fields'] && !$edit['excl_paths']) {
316 $errors['excl_mode'] = t('Include mode selected, but no fields/paths given. Enter at least one path or field where FCKeditor should appear.');
320 $fields = preg_split("/[\s,]+/", strip_tags($edit['excl_fields']));
321 foreach ($fields as
$field) {
322 if ($field && !preg_match("/^[a-z]+(\-[[:alnum:]]+)+$/i", $field)) {
323 $errors['excl_fields'] = t("Invalid field specified: %1", array("%1" => $field));
328 $fields = preg_split("/[\s,]+/", strip_tags($edit['simple_incl_fields']));
329 foreach ($fields as
$field) {
330 if ($field && !preg_match("/^[a-z]+(\-[[:alnum:]]+)+$/i", $field)) {
331 $errors['excl_fields'] = t("Invalid field specified: %1", array("%1" => $field));
337 $paths = preg_split("/[\s,]+/", strip_tags($edit['excl_paths']));
338 foreach ($paths as
$path) {
339 if ($path && !preg_match("|^[_a-z0-9-\*/]*$|i", $path)) {
340 $errors['excl_paths'] = t("Invalid path specified: %1", array("%1" => $path));
345 $paths = preg_split("/[\s,]+/", strip_tags($edit['simple_incl_paths']));
346 foreach ($paths as
$path) {
347 if ($path && !preg_match("|^[_a-z0-9-\*/]*$|i", $path)) {
348 $errors['excl_paths'] = t("Invalid path specified: %1", array("%1" => $path));
353 foreach ($errors as
$name => $message) {
354 form_set_error($name, $message);
357 return count($errors) == 0;
361 * Controller for FCKeditor administrative settings.
363 function fckeditor_admin($arg = NULL
) {
365 $module_drupal_path = drupal_get_path('module', 'fckeditor');
366 $fckconfig_file = $module_drupal_path .
'/fckeditor/fckconfig.js';
367 if (!file_exists($fckconfig_file)) {
368 drupal_set_message(t('checking for %filename', array('%filename' => $fckconfig_file)));
370 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.',
372 '!fckeditorlink' => l(t('FCKeditor homepage'), 'http://www.fckeditor.net/download'),
373 '!readme' => l('readme.txt', 'admin/help/fckeditor'),
374 '%modulepath' => base_path() .
$module_drupal_path .
'/fckeditor/',
375 '%modulesubdir' => base_path() .
$module_drupal_path .
'/fckeditor/editor',
376 '%modulefile' => base_path() .
$module_drupal_path .
'/fckeditor/fckeditor.js')),
382 $op = isset($_POST['op']) ?
$_POST['op'] : "";
383 $op = $arg && !$op ?
$arg : $op;
387 $output = fckeditor_profile_form($edit);
391 $output = fckeditor_global_profile_form($edit);
395 $output = fckeditor_ask_delete_confirmation(true
);
399 $output = fckeditor_ask_delete_confirmation(false
, urldecode(arg(4)));
403 drupal_set_title(t('Edit FCKeditor profile'));
404 $output = fckeditor_profile_form(fckeditor_profile_load(urldecode(arg(4))));
408 drupal_set_title(t('Edit FCKeditor profile'));
409 $output = fckeditor_global_profile_form(fckeditor_profile_load("FCKeditor Global Profile"));
412 case
'deleteconfirmed':
413 fckeditor_profile_delete(urldecode(arg(4)));
414 drupal_set_message(t('Deleted profile'));
415 drupal_goto('admin/settings/fckeditor');
418 case
'deletegconfirmed':
419 fckeditor_profile_delete("FCKeditor Global Profile");
420 drupal_set_message(t('Deleted Global profile'));
421 drupal_goto('admin/settings/fckeditor');
424 case
t('Create profile');
425 case
t('Update profile');
426 if (fckeditor_profile_validate($edit)) {
427 fckeditor_profile_save($edit);
428 $edit['old_name'] ?
drupal_set_message(t('Your FCKeditor profile has been updated.')) : drupal_set_message(t('Your FCKeditor profile has been created.'));
429 drupal_goto('admin/settings/fckeditor');
432 $output = fckeditor_profile_form($edit);
436 case
t('Create global profile');
437 case
t('Update global profile');
438 if (fckeditor_global_profile_validate($edit)) {
439 $edit['name'] = 'FCKeditor Global Profile';
440 fckeditor_global_profile_save($edit);
441 drupal_set_message(t('FCKeditor global profile has been saved.'));
442 drupal_goto('admin/settings/fckeditor');
445 $output = fckeditor_global_profile_form($edit);
450 drupal_set_title(t('FCKeditor settings'));
451 //Check if FCKeditor is installed.
452 $fckeditor_loc = drupal_get_path('module', 'fckeditor') .
'/fckeditor/';
453 if (!is_dir($fckeditor_loc)) {
454 drupal_set_message(t('Could not find the FCKeditor engine installed at <strong>!fckeditor-directory</strong>. Please !download, uncompress it and copy the folder into !fckeditor-path.', array('!fckeditor-path' => drupal_get_path('module', 'fckeditor'), '!fckeditor-directory' => $fckeditor_loc, '!download' => l(t("download FCKeditor"), "http://www.fckeditor.net/download"))), 'error');
456 $access_fckeditor_roles = user_roles(FALSE
, 'access fckeditor');
457 if (!$access_fckeditor_roles) {
458 drupal_set_message(t('There is currently no role with the <strong>!access</strong> permission. Visit !acl administration section.',
459 array("!access" => t("access fckeditor"), "!acl" => l(t("Access control"), "admin/user/access"))), "warning");
462 $result = db_query_range("SELECT name FROM {fckeditor_settings} WHERE name<>'FCKeditor Global Profile'", 0, 1);
463 $has_profiles = false
;
464 //find profile other than Global
465 if ($obj = db_fetch_object($result)) {
466 $has_profiles = true
;
469 //find roles with profiles
470 $result = db_query("SELECT rid FROM {fckeditor_role}");
472 while ($obj = db_fetch_object($result)) {
475 $rids = array_unique($rids);
476 if (!$has_profiles) {
477 drupal_set_message(t("No FCKeditor profiles found. At this moment, nobody is able to use FCKeditor. Create new profile below."), "error");
480 //not all roles with access fckeditor has their FCKeditor profile assigned
481 $diff = array_diff(array_keys($access_fckeditor_roles), $rids);
484 foreach ($diff as
$rid) {
485 $list .
= "<li>".
$access_fckeditor_roles[$rid] .
"</li>";
488 drupal_set_message(t("Not all roles with <strong>!access</strong> permission are associated with FCKeditor profiles. As a result, users having the following roles may be unable to use FCKeditor: !list Create new or edit FCKeditor profiles below and in the <strong>Basic setup</strong> section, check "Roles allowed to use this profile".", array("!access" => l(t("access fckeditor"), "admin/user/access"), "!list" => $list)), "warning");
493 $output = fckeditor_profile_overview();
500 * Save a profile to the database.
501 * @todo add more entries to array in the user_save line
503 function fckeditor_profile_save($edit) {
504 db_query("DELETE FROM {fckeditor_settings} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']);
505 db_query("DELETE FROM {fckeditor_role} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']);
506 db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", $edit['name'], serialize($edit));
508 foreach ($edit['rids'] as
$rid => $value) {
509 db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)", $edit['name'], $rid);
512 // if users can't set their own defaults, make sure to remove $user->fckeditor_status so their default doesn't override the main default
513 if ($edit['user_choose'] == 'false') {
515 user_save($user, array('fckeditor_status' => NULL
));
519 function fckeditor_global_profile_save($edit) {
520 if (isset($edit['rank'])) {
521 $edit['rank'] = explode('>', str_replace(' ', '', $edit['rank']));
523 db_query("DELETE FROM {fckeditor_settings} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']);
524 db_query("DELETE FROM {fckeditor_role} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']);
525 db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", $edit['name'], serialize($edit));
529 * Controller for fckeditor profiles.
531 function fckeditor_profile_overview() {
534 $profiles = fckeditor_profile_load();
536 $roles = user_roles();
537 $access_fckeditor_roles = user_roles(FALSE
, 'access fckeditor');
538 $header = array(t('Profile'), t('Roles'), t('Operations'));
539 foreach ($profiles as
$p) {
541 if ($p->name
!== "FCKeditor Global Profile") {
542 foreach ($p->rids as
$rid => $name) {
543 if (!isset($access_fckeditor_roles[$rid])) {
547 $rows[] = array(array('data' => $p->name
, 'valign' => 'top'), array('data' => implode("<br />\n", $rids)), array('data' => l(t('edit'), 'admin/settings/fckeditor/edit/'.
urlencode($p->name
)) .
' '.
l(t('delete'), 'admin/settings/fckeditor/delete/'.
urlencode($p->name
)), 'valign' => 'top'));
550 $output .
= "<h3>".
t("Profiles") .
"</h3>";
551 $output .
= theme('table', $header, $rows);
552 $output .
= '<p>'.
l(t('Create new profile'), 'admin/settings/fckeditor/add') .
'</p>';
555 drupal_set_message(t('No profiles found. Click here to !create.', array('!create' => l(t("create a new profile"), 'admin/settings/fckeditor/add'))));
559 if (!isset($profiles['FCKeditor Global Profile'])) {
560 drupal_set_message(t('Global Profile not found. Click here to !create.', array('!create' => l(t("create the global profile"), 'admin/settings/fckeditor/addg'))));
563 $output .
= "<h3>".
t("Global Settings") .
"</h3>";
564 $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'));
565 $output .
= theme('table', array(t('Profile'), t('Operations')), $rows);
572 * Load all profiles. Just load one profile if $name is passed in.
574 function fckeditor_profile_load($name = '') {
575 static
$profiles = array();
578 $roles = user_roles();
579 $result = db_query('SELECT * FROM {fckeditor_settings}');
580 while ($data = db_fetch_object($result)) {
581 $data->settings
= unserialize($data->settings
);
582 $result2 = db_query("SELECT rid FROM {fckeditor_role} WHERE name = '%s'", $data->name
);
584 while ($r = db_fetch_object($result2)) {
585 $role[$r->rid
] = $roles[$r->rid
];
589 $profiles[$data->name
] = $data;
593 return ($name ?
$profiles[$name] : $profiles);
597 * @param int $excl_mode 1/include, exclude otherwise
598 * @param string $excl_fields fields (HTML IDs)
599 * @param string $excl_paths paths (drupal paths)
600 * @param string $element_id current ID
601 * @param string $get_q current path
604 * returns true if FCKeditor is enabled
606 function fckeditor_is_enabled($excl_mode, $excl_fields, $excl_paths, $element_id, $get_q) {
607 $arr_excl_fields = preg_split("/[\s,]+/", strip_tags($excl_fields));
608 $field_found = fckeditor_idsearch($element_id, $arr_excl_fields);
610 $path = drupal_get_path_alias($get_q);
611 $regexp = '/^('.
preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'.
preg_quote(variable_get('site_frontpage', 'node'), '/') .
'\2'), preg_quote($excl_paths, '/')) .
')$/';
612 $path_found = preg_match($regexp, $path);
614 $found = $field_found || $path_found;
616 $result = ($excl_mode == 1) ?
$found : !$found;
621 * This function create the HTML objects required for the FCKeditor
624 * A fully populated form elment to add the editor to
626 * The same $element with extra FCKeditor markup and initialization
628 function fckeditor_process_textarea($element) {
629 static
$is_running = FALSE
;
631 global $user, $fckeditor_simple_toolbar_ids;
633 //skip this one, surely nobody wants WYSIWYG here
635 switch ($element['#id']) {
636 case
'edit-excl-list':
637 case
'edit-simple-incl-list':
638 case
'edit-simple-incl-paths':
639 case
'edit-simple-incl-fields':
641 case
'edit-excl-fields':
642 case
'edit-excl-paths':
648 $profile = fckeditor_user_get_profile($user);
654 $conf = $profile->settings
;
656 if ($conf['allow_user_conf']=='t') {
657 foreach (array('default', 'show_toggle', 'popup', 'skin', 'toolbar', 'expand', 'width', 'lang', 'auto_lang') as
$setting) {
658 $conf[$setting] = fckeditor_user_get_setting($user, $profile, $setting);
661 if ($conf["popup"]=="t" && $conf["show_toggle"]=="t") {
662 $conf["show_toggle"]="f";
665 $themepath = path_to_theme() .
'/';
668 $enabled = fckeditor_is_enabled($conf['excl_mode'], $conf['excl_fields'], $conf['excl_paths'], $element['#id'], $_GET['q']);
670 $global_profile = fckeditor_profile_load("FCKeditor Global Profile");
671 $global_conf = $global_profile->settings
;
673 $enabled = fckeditor_is_enabled($global_conf['excl_mode'], $global_conf['excl_fields'], $global_conf['excl_paths'], $element['#id'], $_GET['q']);
677 if ((($element['#rows'] > $conf['min_rows']) || ($conf['min_rows'] <= 1 && empty($element['#rows']))) && $enabled) {
678 // Set resizable to false to avoid drupal.js resizable function from taking control of the textarea
679 if ($conf["popup"]=="f") {
680 $element['#resizable'] = FALSE
;
683 // only replace textarea when it has enough rows and it is enabled
685 $js_id = 'oFCK_'.
$num++;
686 $fckeditor_on = ($conf['default']=='t') ?
1 : 0 ;
688 $wysiwyg_link = "<div id=\"fck_{$js_id}\"><textarea id=\"{$js_id}\">".
htmlspecialchars($element['#value']) .
"</textarea></div>\n";
689 $wysiwyg_link .
= "<a href=\"javascript:Toggle('{$js_id}','{$element['#id']}','".
str_replace("'", "\\'", t("Switch to plain text editor")) .
"','".
str_replace("'", "\\'", t("Switch to rich text editor")) .
"');\" id=\"switch_{$js_id}\" ".
($fckeditor_on?
"style=\"display:none\"":"") .
">";
690 $wysiwyg_link .
= $fckeditor_on ?
t("Switch to plain text editor") : t("Switch to rich text editor");
691 $wysiwyg_link .
= "</a>";
692 if (!isset($element['#suffix'])) {
693 $element['#suffix'] = "";
695 //settings are saved as strings, not booleans
696 if ($conf['show_toggle'] == 't') {
697 // Make sure to append to #suffix so it isn't completely overwritten
698 drupal_add_js('if (Drupal.jsEnabled) {$(document).ready(function() {CreateToggle("'.
$element['#id'].
'","'.
$js_id.
'", '.
$fckeditor_on.
');});}', 'inline');
699 $element['#suffix'] .
= $wysiwyg_link;
701 // setting some variables
702 $module_drupal_path = drupal_get_path('module', 'fckeditor');
703 $module_full_path = base_path() .
$module_drupal_path;
704 // get the default drupal files path
705 $files_path = base_path() .
file_directory_path();
706 // module_drupal_path:
707 // 'modules/fckeditor' (length=17)
709 // '/drupal5/modules/fckeditor' (length=26)
711 // '/drupal5/files' (length=14)
712 // configured in settings
713 $width = $conf['width'];
715 // sensible default for small toolbars
716 $height = $element['#rows'] * 14 + 140;
719 drupal_add_js($module_drupal_path .
'/fckeditor/fckeditor.js');
720 drupal_add_js($module_drupal_path .
'/fckeditor.utils.js');
724 $toolbar = $conf['toolbar'];
725 //$height += 100; // for larger toolbars
727 $force_simple_toolbar = fckeditor_is_enabled(1, $conf['simple_incl_fields'], $conf['simple_incl_paths'], $element['#id'], $_GET['q']);
728 if (!$force_simple_toolbar) {
729 $force_simple_toolbar = fckeditor_is_enabled(1, $global_conf['simple_incl_fields'], $global_conf['simple_incl_paths'], $element['#id'], $_GET['q']);
731 if ($force_simple_toolbar) {
732 $toolbar = FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME
;
735 $textarea_id = $conf['show_toggle'] == 't' ?
$js_id : $element['#id'];
737 $js = $js_id .
" = new FCKeditor( '".
$textarea_id .
"' );
738 ".
$js_id .
".BasePath = '".
$module_full_path .
"/fckeditor/';
739 ".
$js_id .
".Config['CustomConfigurationsPath'] = \"".
$module_full_path .
"/fckeditor.config.js?".@
filemtime($module_drupal_path.
"/fckeditor.config.js").
"\";
740 ".
$js_id .
".Config['TextareaID'] = \"".
$element['#id'] .
"\";";
742 //if ($conf['appearance_conf'] == 'f') {
743 $js .
= "\n".
$js_id .
".ToolbarSet = \"".
$toolbar .
"\";
744 ".
$js_id .
".Config['SkinPath'] = ".
$js_id .
".BasePath + \"editor/skins/".
$conf['skin'] .
"/\";
745 ".
$js_id .
".Config['DefaultLanguage'] = \"".
$conf['lang'] .
"\";
746 ".
$js_id .
".Config['AutoDetectLanguage'] = ".
($conf['auto_lang']=="t"?
"true":"false") .
";
747 ".
$js_id .
".Height = \"".
$height .
"\";
748 ".
$js_id .
".Config['ToolbarStartExpanded'] = ".
($conf['expand']=="t"?
"true":"false") .
";
749 ".
$js_id .
".Width = \"".
$width .
"\";\n";
751 //if ($conf['output_conf'] == 'f') {
752 $js .
= "\n".
$js_id .
".Config['EnterMode'] = '".
$conf['enter_mode'] .
"';
753 ".
$js_id .
".Config['ShiftEnterMode'] = \"".
$conf['shift_enter_mode'] .
"\";
754 ".
$js_id .
".Config['FontFormats'] = \"".
str_replace(",", ";", $conf['font_format']) .
"\";
755 ".
$js_id .
".Config['FormatSource'] = ".
($conf['format_source']=="t"?
"true":"false") .
";
756 ".
$js_id .
".Config['FormatOutput'] = ".
($conf['format_output']=="t"?
"true":"false") .
";\n";
759 if (function_exists('img_assist_perm')) {
760 drupal_add_js("var fckImgAssistPath = '".
base_path() .
drupal_get_path('module', 'img_assist') .
"';", 'inline');
763 if (function_exists('linktocontent_node_menu')) {
764 if (!empty($conf['linktoc']) && $conf['linktoc']!='p') {
765 $js .
= $js_id .
".Config['DrupalPathFilter'] = true;\n";
766 if ($conf['linktoc'] == 'pn') {
767 $js .
= $js_id .
".Config['DrupalLinkToContentSelect'] = true;\n";
770 $js .
= $js_id .
".Config['DrupalPath'] = '".
base_path() .
"';\n";
773 // integrate IMCE if it exists and is prefered
774 if (function_exists('imce_integrate') && variable_get('imce_settings_fck', 0)) {
775 imce_integrate('fck');
776 $advanced_uploads = 0;
780 $advanced_uploads = ($conf['upload_advanced']=="t");
781 $basic_uploads = ($conf['upload_basic']=="t");
783 // add code for filebrowser for users that have access
784 if (user_access('allow fckeditor file uploads')==1) {
785 $connector_path = $module_drupal_path .
"/fckeditor/editor/filemanager/connectors/php/connector.php" ;
786 $connector_path = file_exists($connector_path) ?
"../../connectors/php/connector.php" : "connectors/php/connector.php" ;
787 $upload_path = $module_drupal_path .
"/fckeditor/editor/filemanager/connectors/php/upload.php" ;
788 $upload_path = file_exists($upload_path) ?
"/fckeditor/editor/filemanager/connectors/php/upload.php" : "/fckeditor/editor/filemanager/upload/php/upload.php" ;
789 if ($advanced_uploads) {
790 $js .
= $js_id .
".Config['LinkBrowserURL'] = \"".
$module_full_path .
"/fckeditor/editor/filemanager/browser/default/browser.html?Connector=".
$connector_path .
"&ServerPath=".
$files_path .
"\";
791 ".
$js_id .
".Config['ImageBrowserURL'] = \"".
$module_full_path .
"/fckeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=".
$connector_path .
"&ServerPath=".
$files_path .
"\";
792 ".
$js_id .
".Config['FlashBrowserURL'] = \"".
$module_full_path .
"/fckeditor/editor/filemanager/browser/default/browser.html?Type=Flash&Connector=".
$connector_path .
"&ServerPath=".
$files_path .
"\";\n";
795 $js .
= $js_id .
".Config['LinkBrowser'] = false;
796 ".
$js_id .
".Config['ImageBrowser'] = false;
797 ".
$js_id .
".Config['FlashBrowser'] = false;\n";
799 if ($basic_uploads) {
800 $js .
= $js_id .
".Config['LinkUploadURL'] = \"".
$module_full_path .
$upload_path .
"\";
801 ".
$js_id .
".Config['ImageUploadURL'] = \"".
$module_full_path .
$upload_path .
"?Type=Image\";
802 ".
$js_id .
".Config['FlashUploadURL'] = \"".
$module_full_path .
$upload_path .
"?Type=Flash\";\n";
805 $js .
= $js_id .
".Config['LinkUpload'] = false;
806 ".
$js_id .
".Config['ImageUpload'] = false;
807 ".
$js_id .
".Config['FlashUpload'] = false;\n";
809 $_SESSION['FCKeditor']['UserFilesPath'] = strtr($profile->settings
['UserFilesPath'], array("%f" => file_directory_path(), "%u" => $user->uid
, "%b" => base_path()));
810 $_SESSION['FCKeditor']['UserFilesAbsolutePath'] = strtr($profile->settings
['UserFilesAbsolutePath'], array("%f" => file_directory_path(), "%u" => $user->uid
, "%b" => base_path(), "%d" => $_SERVER['DOCUMENT_ROOT']));
811 if (variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE
) {
812 $_SESSION['FCKeditor']['UserFilesPath'] = url('system/files') .
'/';
813 $_SESSION['FCKeditor']['UserFilesAbsolutePath'] = realpath(file_directory_path()) . DIRECTORY_SEPARATOR
;
817 $js .
= $js_id .
".Config['LinkBrowser'] = false;
818 ".
$js_id .
".Config['ImageBrowser'] = false;
819 ".
$js_id .
".Config['FlashBrowser'] = false;
820 ".
$js_id .
".Config['LinkUpload'] = false;
821 ".
$js_id .
".Config['ImageUpload'] = false;
822 ".
$js_id .
".Config['FlashUpload'] = false;\n";
825 if ($conf['js_conf']) {
826 $lines = preg_split("/[\n\r]+/", $conf['js_conf']);
827 foreach ($lines as
$l)
828 if ($l && strlen($l) > 5) {
829 $eqpos = strpos($l, "=");
830 if (false
!== $eqpos) {
831 $option = str_replace("FCKConfig.", "", substr($l, 0, $eqpos));
832 $js .
= "\n".
$js_id .
".Config['".
trim($option) .
"'] =".
substr($l, $eqpos + 1);
837 // add custom xml stylesheet if it exists
838 if ($conf['css_style'] == 'theme') {
839 if (file_exists($themepath .
'/fckstyles.xml')) {
840 $styles_xml_path = $host .
$themepath .
'/fckstyles.xml';
841 $js .
= $js_id .
".Config['StylesXmlPath'] = \"".
$styles_xml_path .
"\";\n";
844 else if ($conf['css_style'] == 'self') {
845 $conf['styles_path'] = str_replace("%h%t", "%t", $conf['styles_path']);
846 $js .
= $js_id .
".Config['StylesXmlPath'] = \"".
str_replace(array('%h', '%t', '%m'), array($host, $host .
$themepath, $module_drupal_path), $conf['styles_path']) .
"\";\n";
848 // add custom stylesheet if configured
849 // lets hope it exists but we'll leave that to the site admin
850 if ($conf['css_mode'] == 'theme') {
851 $css = $themepath .
'style.css';
852 if (file_exists($css)) {
853 $js .
= $js_id .
".Config['EditorAreaCSS'] = \"".
$host .
$css .
",".
$module_full_path .
"/fckeditor.css\";";
856 else if ($conf['css_mode'] == 'self') {
857 $conf['css_path'] = str_replace("%h%t", "%t", $conf['css_path']);
858 $js .
= $js_id .
".Config['EditorAreaCSS'] = \"".
str_replace(array('%h', '%t'), array($host, $host .
$themepath), $conf['css_path']) .
",".
$module_full_path .
"/fckeditor.css\";";
861 drupal_add_js('var '.
$js_id .
';if (Drupal.jsEnabled) {$(document).ready(function() {'.
$js .
'});}', 'inline');
863 if ($conf['popup']=="t") {
864 // Add the script file with the popup open function.
865 drupal_add_js($module_drupal_path .
'/fckeditor.popup.js');
866 $element['#suffix'] .
= " <span class=\"fckeditor_popuplink\">(<a href=\"#\" onclick=\"FCKeditor_OpenPopup('".
$module_full_path .
"/fckeditor.popup.html?var=".
$js_id .
"&el=".
$element['#id'] .
"');return false;\">".
t('Open rich editor') .
"</a>)</span>";
869 // if no popup mode, add the editor initialization to the footer
870 // this obviously needs print($closure) in page.tpl.php
872 drupal_add_js('if (Drupal.jsEnabled) {$(document).ready(function() {window.setTimeout("'.
$js_id .
'.ReplaceTextarea()",100);});}', 'inline', 'footer');
877 // display the field id for administrators
878 if (user_access('administer fckeditor')) {
879 $element['#suffix'] .
= '<div class="textarea-identifier description">'.
t('The ID for !excluding this element is: !id - the path is: !path', array(
880 '!excluding' => l(t("excluding or including"), 'admin/settings/fckeditor'),
881 '!id' => $element['#id'],
882 '!path' => $_GET['q'],
890 * Implementation of hook_user().
892 function fckeditor_user($type, &$edit, &$user, $category = NULL
) {
893 if ($type == 'form' && $category == 'account' && user_access('access fckeditor')) {
894 $profile = fckeditor_user_get_profile($user);
895 $toolbar_options = fckeditor_load_toolbar_options();
896 $skin_options = fckeditor_load_skin_options();
897 $lang_options = fckeditor_load_lang_options();
899 // because the settings are saved as strings we need to test for the string 'true'
900 if ($profile->settings
['allow_user_conf'] == 't') {
901 $form['fckeditor'] = array(
902 '#type' => 'fieldset',
903 '#title' => t('Rich Text Editor settings'),
905 '#collapsible' => TRUE
,
909 $form['fckeditor']['fckeditor_default'] = array(
911 '#title' => t('Default state'),
912 '#default_value' => isset($user->fckeditor_default
) ?
$user->fckeditor_default
: (isset($profile->settings
['default']) ?
$profile->settings
['default'] : 'f'),
913 '#options' => array('t' => t('enabled'), 'f' => t('disabled')),
914 '#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.'),
917 $form['fckeditor']['fckeditor_show_toggle'] = array(
919 '#title' => t('Show disable/enable rich text editor toggle'),
920 '#default_value' => isset($user->fckeditor_show_toggle
) ?
$user->fckeditor_show_toggle
: (isset($profile->settings
['show_toggle']) ?
$profile->settings
['show_toggle'] : 't'),
921 '#options' => array('t' => t('true'), 'f' => t('false')),
922 '#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).'),
925 $form['fckeditor']['fckeditor_popup'] = array(
927 '#title' => t('Use FCKeditor in a popup window'),
928 '#default_value' => isset($user->fckeditor_popup
) ?
$user->fckeditor_popup
: (isset($profile->settings
['popup']) ?
$profile->settings
['popup'] : 'f'),
929 '#options' => array('f' => t('false'), 't' => t('true')),
930 '#description' => t('If this option is enabled a link to a popup window will be used instead of a textarea replace.'),
933 $form['fckeditor']['fckeditor_skin'] = array(
935 '#title' => t('Skin'),
936 '#default_value' => isset($user->fckeditor_skin
) ?
$user->fckeditor_skin
: (isset($profile->settings
['skin']) ?
$profile->settings
['skin'] : 'default'),
937 '#options' => $skin_options,
938 '#description' => t('Choose a FCKeditor skin.'),
941 $form['fckeditor']['fckeditor_toolbar'] = array(
943 '#title' => t('Toolbar'),
944 '#default_value' => isset($user->fckeditor_toolbar
) ?
$user->fckeditor_toolbar
: (isset($profile->settings
['toolbar']) ?
$profile->settings
['toolbar'] : 'default'),
945 '#options' => $toolbar_options,
946 '#description' => t('Choose a FCKeditor toolbar set.'),
949 $form['fckeditor']['fckeditor_expand'] = array(
951 '#title' => t('Start the toolbar expanded'),
952 '#default_value' => isset($user->fckeditor_expand
) ?
$user->fckeditor_expand
: (isset($profile->settings
['expand']) ?
$profile->settings
['expand'] : 't'),
953 '#options' => array('t' => t('enabled'), 'f' => t('disabled')),
954 '#description' => t('The toolbar start expanded or collapsed.'),
957 $form['fckeditor']['fckeditor_width'] = array(
958 '#type' => 'textfield',
959 '#title' => t('Width'),
960 '#default_value' => isset($user->fckeditor_width
) ?
$user->fckeditor_width
: (isset($profile->settings
['width']) ?
$profile->settings
['width'] : '100%'),
961 '#description' => t("Width in pixels or percent. Ex: 400 or 100%"),
966 $form['fckeditor']['fckeditor_lang'] = array(
968 '#title' => t('Language'),
969 '#default_value' => isset($user->fckeditor_lang
) ?
$user->fckeditor_lang
: (isset($profile->settings
['lang']) ?
$profile->settings
['lang'] : 'en'),
970 '#options' => $lang_options,
971 '#description' => t('The language for the FCKeditor interface.')
974 $form['fckeditor']['fckeditor_auto_lang'] = array(
976 '#title' => t('Auto-detect language'),
977 '#default_value' => isset($user->fckeditor_auto_lang
) ?
$user->fckeditor_auto_lang
: (isset($profile->settings
['auto_lang']) ?
$profile->settings
['auto_lang'] : 't'),
978 '#options' => array('t' => t('true'), 'f' => t('false')),
979 '#description' => t('Use auto detect user language feature.')
982 return array('fckeditor' => $form);
986 if ($type == 'validate') {
988 'fckeditor_default' => $edit['fckeditor_default'],
989 'fckeditor_show_toggle' => $edit['fckeditor_show_toggle'],
990 'fckeditor_popup' => $edit['fckeditor_popup'],
991 'fckeditor_skin' => $edit['fckeditor_skin'],
992 'fckeditor_toolbar' => $edit['fckeditor_toolbar'],
993 'fckeditor_expand' => $edit['fckeditor_expand'],
994 'fckeditor_width' => $edit['fckeditor_width'],
995 'fckeditor_lang' => $edit['fckeditor_lang'],
996 'fckeditor_auto_lang' => $edit['fckeditor_auto_lang'],
1002 * Return an HTML form for profile configuration.
1004 function fckeditor_profile_form($edit) {
1006 $output .
= drupal_get_form('fckeditor_profile_form_build', $edit);
1012 * Return an HTML form for global profile configuration.
1014 function fckeditor_global_profile_form($edit) {
1016 $output .
= drupal_get_form('fckeditor_global_profile_form_build', $edit);
1021 function fckeditor_load_toolbar_options() {
1023 $module_drupal_path = drupal_get_path('module', 'fckeditor');
1024 $fckconfig_js = $module_drupal_path .
'/fckeditor/fckconfig.js';
1025 $fckeditor_config_js = $module_drupal_path .
'/fckeditor.config.js';
1026 if (file_exists($fckconfig_js) && is_readable($fckconfig_js)) {
1027 $fp = @
fopen($fckconfig_js, "r");
1029 while (!feof($fp)) {
1030 $line = fgets($fp, 1024);
1031 if (preg_match("/FCKConfig\.ToolbarSets\[(\"|')(.*?)\\1\]/i", $line, $matches)) {
1032 $arr[$matches[2]] = ucfirst($matches[2]);
1038 if (file_exists($fckeditor_config_js) && is_readable($fckeditor_config_js)) {
1039 $fp = @
fopen($fckeditor_config_js, "r");
1041 while (!feof($fp)) {
1042 $line = fgets($fp, 1024);
1043 if (preg_match("/FCKConfig\.ToolbarSets\[(\"|')(.*?)\\1\]/i", $line, $matches)) {
1044 $arr[$matches[2]] = ucfirst($matches[2]);
1051 //oops, we have no information about toolbars, let's use hardcoded array
1055 'Default' => 'Default',
1063 function fckeditor_load_skin_options() {
1065 $module_drupal_path = drupal_get_path('module', 'fckeditor');
1066 $skin_dir = $module_drupal_path .
'/fckeditor/editor/skins';
1067 if (is_dir($skin_dir)) {
1068 $dh = @
opendir($skin_dir);
1069 if (false
!== $dh) {
1070 while (($file = readdir($dh)) !== false
) {
1071 if (in_array($file, array(".", "..", "CVS", ".svn"))) {
1074 if (is_dir($skin_dir . DIRECTORY_SEPARATOR .
$file)) {
1075 $arr[$file] = ucfirst($file);
1082 //oops, we have no information about skins, let's use only default
1085 'default' => 'Default',
1093 function fckeditor_load_lang_options() {
1095 $module_drupal_path = drupal_get_path('module', 'fckeditor');
1096 $lang_dir = $module_drupal_path .
'/fckeditor/editor/lang';
1097 if (is_dir($lang_dir)) {
1098 $dh = @
opendir($lang_dir);
1099 if (false
!== $dh ) {
1100 while (($file = readdir($dh)) !== false
) {
1101 if (in_array($file, array(".", "..", "CVS", ".svn"))) {
1104 if (is_file($lang_dir . DIRECTORY_SEPARATOR .
$file) && preg_match("/^(.*?)\.js$/", $file, $matches)) {
1105 $lang = $matches[1];
1106 $arr[$lang] = strtoupper($lang);
1113 //oops, we have no information about languages, let's use those available in FCKeditor 2.4.3
1116 'af' => 'Afrikaans',
1118 'bg' => 'Bulgarian',
1119 'bn' => 'Bengali/Bangla',
1127 'en-au' => 'English (Australia)',
1128 'en-ca' => 'English (Canadian)',
1129 'en-uk' => 'English (United Kingdom)',
1130 'eo' => 'Esperanto',
1142 'hu' => 'Hungarian',
1147 'lt' => 'Lithuanian',
1149 'mn' => 'Mongolian',
1151 'nb' => 'Norwegian Bokmal',
1153 'no' => 'Norwegian',
1155 'pt' => 'Portuguese (Portugal)',
1156 'pt-br' => 'Portuguese (Brazil)',
1160 'sl' => 'Slovenian',
1161 'sr' => 'Serbian (Cyrillic)',
1162 'sr-latn' => 'Serbian (Latin)',
1166 'uk' => 'Ukrainian',
1167 'vi' => 'Vietnamese',
1168 'zh' => 'Chinese Traditional',
1169 'zh-cn' => 'Chinese Simplified',
1179 * sort roles according to precedence settings. previously sorted roles are followed by latest added roles.
1181 function fckeditor_sorted_roles() {
1183 if (isset($order)) {
1187 $roles = user_roles(0, 'access fckeditor');
1189 $result = db_query("SELECT settings FROM {fckeditor_settings} WHERE name='FCKeditor Global Profile'");
1190 $data = db_fetch_object($result);
1191 if ($data->settings
) {
1192 $settings = unserialize($data->settings
);
1193 if (isset($settings['rank']) && !empty($settings['rank']))
1194 foreach ($settings['rank'] as
$rid) {
1195 if (isset($roles[$rid])) {
1196 $order[$rid] = $roles[$rid];
1197 unset($roles[$rid]);
1201 krsort($roles);//sort the remaining unsorted roles by id, descending.
1206 function fckeditor_global_profile_form_build($edit) {
1207 $edit = (object) $edit;
1209 if (arg(3) == 'addg') {
1210 $breadcrumb[] = array('path' => 'admin', 'title' => t('administer'));
1211 $breadcrumb[] = array('path' => 'admin/settings/fckeditor', 'title' => t('fckeditor'));
1212 $breadcrumb[] = array('path' => 'admin/settings/fckeditor/addg', 'title' => t('Add new FCKeditor global profile'));
1213 menu_set_location($breadcrumb);
1215 $result = db_query("SELECT DISTINCT(rid) FROM {fckeditor_role} WHERE name='FCKeditor Global Profile'");
1216 $data = db_fetch_object($result);
1219 drupal_set_message(t("Global profile already exist. Only one global profile is allowed."), "error");
1223 $btn = t('Create global profile');
1226 $form['old_name'] = array('#type' => 'hidden', '#value' => $edit->name
);
1227 $btn = t('Update global profile');
1230 $form['common'] = array(
1231 '#type' => 'fieldset',
1232 '#title' => t('Main setup'),
1233 '#collapsible' => TRUE
,
1234 '#collapsed' => TRUE
1237 $roles = fckeditor_sorted_roles();
1238 $rids = $rtext = array();
1239 foreach ($roles as
$rid => $name) {
1241 $rtext[] = '<strong>'.
$rid .
' - </strong>'.
$name;
1243 $form['common']['rank'] = array('#type' => 'textfield',
1244 '#title' => t('Role precedence'),
1245 '#default_value' => implode('>', $rids),
1246 '#description' => t('A user having <strong>multiple roles</strong> gets the permissions of the highest one. Sort role IDs according to their <strong>precedence from higher to lower</strong> by putting > in between.<br />'),
1249 $form['common']['rank']['#description'] .
= t('Here is the id-name pairs of roles having access to FCKeditor:') .
'<div>'.
implode('<br />', $rtext) .
'</div>';
1252 $form['common']['rank']['#description'] .
= t('You haven\'t assigned the <code>!access1</code> !permissions yet.', array('!access1' => t('access fckeditor'), '!permissions' => l(t('permissions'), 'admin/user/access')));
1255 $form['fckeditor_exclude_settings'] = array(
1256 '#type' => 'fieldset',
1257 '#title' => t('Visibility settings'),
1258 '#collapsible' => TRUE
,
1259 '#collapsed' => TRUE
,
1262 $form['fckeditor_exclude_settings']['excl_mode'] = array(
1263 '#type' => 'select',
1264 '#title' => t('Use inclusion or exclusion mode'),
1265 '#default_value' => (in_array($edit->settings
['excl_mode'], array(0, 2))) ?
0 : 1,
1266 '#options' => array('0' => t('exclude'), '1' => t('include')),
1267 '#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.'),
1271 * get excluded fields - so we can have normal textareas too
1272 * split the phrase by any number of commas or space characters,
1273 * which include " ", \r, \t, \n and \f
1275 $form['fckeditor_exclude_settings']['excl_fields'] = array(
1276 '#type' => 'textarea',
1277 '#title' => t('Fields to exclude/include'),
1280 '#prefix' => '<div style="margin-left:20px">',
1281 '#suffix' => '</div>',
1282 '#default_value' => $edit->settings
['excl_fields'] ?
$edit->settings
['excl_fields'] : '',
1283 '#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.<br />You may separate the different entries by commas, spaces or newlines."),
1287 * get excluded paths - so we can have normal textareas too
1288 * split the phrase by any number of commas or space characters,
1289 * which include " ", \r, \t, \n and \f
1291 $form['fckeditor_exclude_settings']['excl_paths'] = array(
1292 '#type' => 'textarea',
1293 '#title' => t('Paths to exclude/include'),
1294 '#prefix' => '<div style="margin-left:20px">',
1295 '#suffix' => '</div>',
1298 '#default_value' => $edit->settings
['excl_paths'] ?
$edit->settings
['excl_paths'] : '',
1299 '#description' => t("Enter drupal paths here, depending on the chosen option for the inclusion/exclusion mode.<br />Paths may be used the same way as in the drupal blocks configuration.<br />You may separate the different entries by commas, spaces or newlines. <br />You may also use * as a wildcard character (for example <code>comment/*</code>)."),
1302 $form['fckeditor_exclude_settings']['simple_incl_fields'] = array(
1303 '#type' => 'textarea',
1304 '#title' => t('Force simplified toolbar on the following fields'),
1307 '#default_value' => $edit->settings
['simple_incl_fields'] ?
$edit->settings
['simple_incl_fields'] : '',
1308 '#description' => t("Enter names (HTML ID's) of fields that should have the simplified toolbar.<br />If you don't want to use this feature, simply leave this field empty.<br />You may separate the different entries by commas, spaces or newlines."),
1311 $form['fckeditor_exclude_settings']['simple_incl_paths'] = array(
1312 '#type' => 'textarea',
1313 '#title' => t('Force simplified toolbar on the following paths'),
1316 '#default_value' => $edit->settings
['simple_incl_paths'] ?
$edit->settings
['simple_incl_paths'] : '',
1317 '#description' => t("Enter drupal paths that should have the simplified toolbar.<br />If you don't want to use this feature, simply leave this field empty.<br />Paths may be used the same way as in the drupal blocks configuration.<br />You may separate the different entries by commas, spaces or newlines.<br />You may also use * as a wildcard character (for example <code>comment/*</code>)."),
1320 $form['submit'] = array(
1321 '#type' => 'submit',
1329 * Return an HTML form for profile configuration.
1331 function fckeditor_profile_form_build($edit) {
1332 $edit = (object) $edit;
1334 $toolbar_options = fckeditor_load_toolbar_options();
1335 $skin_options = fckeditor_load_skin_options();
1336 $lang_options = fckeditor_load_lang_options();
1338 // Only display the roles that currently don't have a fckeditor profile. One
1339 // profile per role.
1340 $orig_roles = user_roles(FALSE
, 'access fckeditor');
1341 $roles = $orig_roles;
1343 if ($edit->rids
&& !user_roles(false
, 'access fckeditor')) {
1344 drupal_set_message(t('You haven\'t assigned <code>!access1</code> !permissions yet.<br/>It is recommended to assign the <code>!access1</code> !permissions before updating FCKeditor profiles.',
1346 '!access1' => t('access fckeditor'),
1347 '!permissions' => l(t('permissions'), 'admin/user/access'))), 'warning');
1350 if (arg(3) == 'add') {
1351 $breadcrumb[] = array('path' => 'admin', 'title' => t('administer'));
1352 $breadcrumb[] = array('path' => 'admin/settings/fckeditor', 'title' => t('fckeditor'));
1353 $breadcrumb[] = array('path' => 'admin/settings/fckeditor/add', 'title' => t('Add new FCKeditor profile'));
1354 menu_set_location($breadcrumb);
1356 $result = db_query('SELECT DISTINCT(rid) FROM {fckeditor_role}');
1357 while ($data = db_fetch_object($result)) {
1358 if (!in_array($data->rid
, array_keys((array) $edit->rids
)) && !form_get_errors()) {
1359 unset($roles[$data->rid
]);
1362 if (count($orig_roles) != count($roles)) {
1363 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.'));
1365 $btn = t('Create profile');
1368 $form['old_name'] = array('#type' => 'hidden', '#value' => $edit->name
);
1369 $btn = t('Update profile');
1372 $form['basic'] = array(
1373 '#type' => 'fieldset',
1374 '#title' => t('Basic setup'),
1375 '#collapsible' => TRUE
,
1376 '#collapsed' => TRUE
1379 $form['basic']['name'] = array(
1380 '#type' => 'textfield',
1381 '#title' => t('Profile name'),
1382 '#default_value' => $edit->name
,
1384 '#maxlength' => 128,
1385 '#description' => t('Enter a name for this profile. This name is only visible within the fckeditor administration page.'),
1389 $form['basic']['rids'] = array(
1390 '#type' => 'checkboxes',
1391 '#title' => t('Roles allowed to use this profile'),
1392 '#default_value' => array_keys((array) $edit->rids
),
1393 '#options' => $roles,
1394 '#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"))),
1398 $form['basic']['allow_user_conf'] = array(
1399 '#type' => 'select',
1400 '#title' => t('Allow users to customize FCKeditor appearance'),
1401 '#default_value' => $edit->settings
['allow_user_conf'] ?
$edit->settings
['allow_user_conf'] : 'f',
1402 '#options' => array('f' => t('false'), 't' => t('true')),
1403 '#description' => t('If allowed, users will be able to override <code>Editor appearance</code> by visiting their profile page.'),
1406 $form['fckeditor_exclude_settings'] = array(
1407 '#type' => 'fieldset',
1408 '#title' => t('Visibility settings'),
1409 '#collapsible' => TRUE
,
1410 '#collapsed' => TRUE
,
1413 $form['fckeditor_exclude_settings']['min_rows'] = array(
1414 '#type' => 'textfield',
1415 '#title' => t('Minimum rows'),
1416 '#default_value' => $edit->settings
['min_rows'] ?
$edit->settings
['min_rows'] : '5',
1417 '#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."),
1420 $form['fckeditor_exclude_settings']['excl_mode'] = array(
1421 '#type' => 'select',
1422 '#title' => t('Use inclusion or exclusion mode'),
1423 '#default_value' => (in_array($edit->settings
['excl_mode'], array(0, 2))) ?
0 : 1,
1424 '#options' => array('0' => t('exclude'), '1' => t('include')),
1425 '#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.'),
1429 * get excluded fields - so we can have normal textareas too
1430 * split the phrase by any number of commas or space characters,
1431 * which include " ", \r, \t, \n and \f
1433 $form['fckeditor_exclude_settings']['excl_fields'] = array(
1434 '#type' => 'textarea',
1435 '#title' => t('Fields to exclude/include'),
1438 '#prefix' => '<div style="margin-left:20px">',
1439 '#suffix' => '</div>',
1440 '#default_value' => $edit->settings
['excl_fields'] ?
$edit->settings
['excl_fields'] : '',
1441 '#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.<br />You may separate the different entries by commas, spaces or newlines."),
1445 * get excluded paths - so we can have normal textareas too
1446 * split the phrase by any number of commas or space characters,
1447 * which include " ", \r, \t, \n and \f
1449 $form['fckeditor_exclude_settings']['excl_paths'] = array(
1450 '#type' => 'textarea',
1451 '#title' => t('Paths to exclude/include'),
1452 '#prefix' => '<div style="margin-left:20px">',
1453 '#suffix' => '</div>',
1456 '#default_value' => $edit->settings
['excl_paths'] ?
$edit->settings
['excl_paths'] : '',
1457 '#description' => t("Enter drupal paths here, depending on the chosen option for the inclusion/exclusion mode.<br />Paths may be used the same way as in the drupal blocks configuration.<br />You may separate the different entries by commas, spaces or newlines. <br />You may also use * as a wildcard character (for example <code>comment/*</code>)."),
1460 $form['fckeditor_exclude_settings']['simple_incl_fields'] = array(
1461 '#type' => 'textarea',
1462 '#title' => t('Force simplified toolbar on the following fields'),
1465 //'#prefix' => t('Here you can define where FCKeditor should force the <code>!simple</code> toolbar.<br/>Useful for smaller textareas where we usually don\'t use very complicated HTML code, like in signatures.', array('!simple' => FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME)),
1466 '#default_value' => $edit->settings
['simple_incl_fields'] ?
$edit->settings
['simple_incl_fields'] : '',
1467 '#description' => t("Enter names (HTML ID's) of fields that should have the simplified toolbar.<br />If you don't want to use this feature, simply leave this field empty.<br />You may separate the different entries by commas, spaces or newlines."),
1470 $form['fckeditor_exclude_settings']['simple_incl_paths'] = array(
1471 '#type' => 'textarea',
1472 '#title' => t('Force simplified toolbar on the following paths'),
1475 //'#prefix' => t('Here you can define where FCKeditor should force the <code>!simple</code> toolbar.<br/>Useful for smaller textareas where we usually don\'t use very complicated HTML code, like in signatures.', array('!simple' => FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME)),
1476 '#default_value' => $edit->settings
['simple_incl_paths'] ?
$edit->settings
['simple_incl_paths'] : '',
1477 '#description' => t("Enter drupal paths that should have the simplified toolbar.<br />If you don't want to use this feature, simply leave this field empty.<br />Paths may be used the same way as in the drupal blocks configuration.<br />You may separate the different entries by commas, spaces or newlines.<br />You may also use * as a wildcard character (for example <code>comment/*</code>)."),
1480 $form['appearance'] = array(
1481 '#type' => 'fieldset',
1482 '#title' => t('Editor appearance'),
1483 '#collapsible' => TRUE
,
1484 '#collapsed' => TRUE
,
1487 $form['appearance']['default'] = array(
1488 '#type' => 'select',
1489 '#title' => t('Default state'),
1490 '#default_value' => $edit->settings
['default'] ?
$edit->settings
['default'] : 't',
1491 '#options' => array('t' => t('enabled'), 'f' => t('disabled')),
1492 '#description' => t('Default editor state. If disabled, rich text editor may still be enabled using toggle or popup window.'),
1495 $form['appearance']['show_toggle'] = array(
1496 '#type' => 'select',
1497 '#title' => t('Show disable/enable rich text editor toggle'),
1498 '#default_value' => $edit->settings
['show_toggle'] ?
$edit->settings
['show_toggle'] : 't',
1499 '#options' => array('t' => t('true'), 'f' => t('false')),
1500 '#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).'),
1503 $form['appearance']['popup'] = array(
1504 '#type' => 'select',
1505 '#title' => t('Use FCKeditor in a popup window'),
1506 '#default_value' => $edit->settings
['popup'] ?
$edit->settings
['popup'] : 'f',
1507 '#options' => array('f' => t('false'), 't' => t('true')),
1508 '#description' => t('If this option is enabled a link to a popup window will be used instead of a textarea replace.'),
1511 $form['appearance']['skin'] = array(
1512 '#type' => 'select',
1513 '#title' => t('Skin'),
1514 '#default_value' => $edit->settings
['skin'] ?
$edit->settings
['skin'] : 'default',
1515 '#options' => $skin_options,
1516 '#description' => t('Choose a default skin.'),
1519 $form['appearance']['toolbar'] = array(
1520 '#type' => 'select',
1521 '#title' => t('Toolbar'),
1522 '#default_value' => $edit->settings
['toolbar'] ?
$edit->settings
['toolbar'] : 'default',
1523 '#options' => $toolbar_options,
1524 '#description' => t('Choose a default toolbar set. To define new toolbar, edit <code>fckeditor.config.js</code> located in !module_path.', array('!module_path' => drupal_get_path('module', 'fckeditor'))),
1527 $form['appearance']['expand'] = array(
1528 '#type' => 'select',
1529 '#title' => t('Start the toolbar expanded'),
1530 '#default_value' => $edit->settings
['expand'] ?
$edit->settings
['expand'] : 't',
1531 '#options' => array('t' => t('enabled'), 'f' => t('disabled')),
1532 '#description' => t('The toolbar start expanded or collapsed.'),
1535 $form['appearance']['width'] = array(
1536 '#type' => 'textfield',
1537 '#title' => t('Width'),
1538 '#default_value' => $edit->settings
['width'] ?
$edit->settings
['width'] : '100%',
1539 '#description' => t("Width in pixels or percent. Ex: 400 or 100%"),
1541 '#maxlength' => 128,
1544 $form['appearance']['lang'] = array(
1545 '#type' => 'select',
1546 '#title' => t('Language'),
1547 '#default_value' => $edit->settings
['lang'] ?
$edit->settings
['lang'] : 'en',
1548 '#options' => $lang_options,
1549 '#description' => t('The language for the FCKeditor interface.')
1552 $form['appearance']['auto_lang'] = array(
1553 '#type' => 'select',
1554 '#title' => t('Auto-detect language'),
1555 '#default_value' => $edit->settings
['auto_lang'] ?
$edit->settings
['auto_lang'] : 't',
1556 '#options' => array('t' => t('true'), 'f' => t('false')),
1557 '#description' => t('Use auto detect user language feature.')
1561 $form['appearance']['appearance_conf'] = array(
1562 '#type' => 'select',
1563 '#title' => t('Ignore this section, use default settings defined in config files'),
1564 '#default_value' => $edit->settings['appearance_conf'] ? $edit->settings['appearance_conf'] : 'f',
1565 '#options' => array('f' => t('false'), 't' => t('true')),
1566 '#description' => t('Although it is less handy, defining settings only in config files (<code>fckconfig.js</code> and <code>fckeditor.config.js</code>) will slightly leverage your traffic and improve load time of your site. <br/>Warning: if set to true, all changes made in <code>Editor appearance</code> will have no affect on FCKeditor\'s behaviour.'),
1570 $form['output'] = array(
1571 '#type' => 'fieldset',
1572 '#title' => t('Cleanup and output'),
1573 '#collapsible' => TRUE
,
1574 '#collapsed' => TRUE
,
1577 $form['output']['enter_mode'] = array(
1578 '#type' => 'select',
1579 '#title' => t('Enter mode'),
1580 '#default_value' => $edit->settings
['enter_mode'] ?
$edit->settings
['enter_mode'] : 'p',
1581 '#options' => array('p' => '<p>', 'br' => '<br>', 'div' => '<div>'),
1582 '#description' => t('Set which tag FCKeditor should use when [Enter] key is pressed.')
1585 $form['output']['shift_enter_mode'] = array(
1586 '#type' => 'select',
1587 '#title' => t('Shift + Enter mode'),
1588 '#default_value' => $edit->settings
['shift_enter_mode'] ?
$edit->settings
['shift_enter_mode'] : 'br',
1589 '#options' => array('p' => '<p>', 'br' => '<br>', 'div' => '<div>'),
1590 '#description' => t('Set which tag FCKeditor should use when [Shift] + [Enter] is pressed.')
1593 $form['output']['font_format'] = array(
1594 '#type' => 'textfield',
1595 '#title' => t('Font formats'),
1596 '#default_value' => $edit->settings
['font_format'] ?
$edit->settings
['font_format'] : 'p;div;pre;address;h1;h2;h3;h4;h5;h6',
1598 '#maxlength' => 250,
1599 '#description' => t('Semicolon separated list of HTML font formats. Allowed values are: p;div;pre;address;h1;h2;h3;h4;h5;h6'),
1602 $form['output']['format_source'] = array(
1603 '#type' => 'select',
1604 '#title' => t('Apply source formatting'),
1605 '#default_value' => $edit->settings
['format_source'] ?
$edit->settings
['format_source'] : 't',
1606 '#options' => array('t' => t('true'), 'f' => t('false')),
1607 '#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.'),
1610 $form['output']['format_output'] = array(
1611 '#type' => 'select',
1612 '#title' => t('Format output'),
1613 '#default_value' => $edit->settings
['format_output'] ?
$edit->settings
['format_output'] : 't',
1614 '#options' => array('t' => t('true'), 'f' => t('false')),
1615 '#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.'),
1619 $form['output']['output_conf'] = array(
1620 '#type' => 'select',
1621 '#title' => t('Ignore this section, use default settings defined in config files'),
1622 '#default_value' => $edit->settings['output_conf'] ? $edit->settings['output_conf'] : 'f',
1623 '#options' => array('f' => t('false'), 't' => t('true')),
1624 '#description' => t('Although it is less handy, defining settings only in config files (<code>fckconfig.js</code> and <code>fckeditor.config.js</code>) will slightly leverage your traffic and improve load time of your site. <br/>Warning: if set to true, all changes made in <code>Cleanup and output</code> will have no affect on FCKeditor\'s behaviour.'),
1628 $form['css'] = array(
1629 '#type' => 'fieldset',
1630 '#title' => t('CSS'),
1631 '#collapsible' => TRUE
,
1632 '#collapsed' => TRUE
1635 $form['css']['css_mode'] = array(
1636 '#type' => 'select',
1637 '#title' => t('Editor CSS'),
1638 '#default_value' => $edit->settings
['css_mode'] ?
$edit->settings
['css_mode'] : 'theme',
1639 '#options' => array('theme' => t('use theme css'), 'self' => t('define css'), 'none' => t('FCKeditor default')),
1640 '#description' => t('Defines the CSS to be used in the editor area.<br />use theme css - load style.css from current site theme.<br/>define css - enter path for css file below.<br />FCKeditor default - uses default CSS from editor.')
1643 $form['css']['css_path'] = array(
1644 '#type' => 'textfield',
1645 '#title' => t('CSS path'),
1646 '#default_value' => $edit->settings
['css_path'],
1648 '#maxlength' => 255,
1649 '#description' => t('Enter path to CSS file (<em>example: css/editor.css</em>) or a list of css files seperated by a comma (<em>example: /themes/garland/style.css,http://example.com/style.css</em>).<br />Macros: %h (host name: !host), %t (path to theme: !theme)<br />Be sure to select "define css" above.', array('!host' => base_path(), '!theme' => base_path() .
path_to_theme() .
'/'))
1652 $form['css']['css_style'] = array(
1653 '#type' => 'select',
1654 '#title' => t('Predefined styles'),
1655 '#default_value' => $edit->settings
['css_style'] ?
$edit->settings
['css_style'] : 'theme',
1656 '#options' => array('theme' => t('use theme fckstyles.xml'), 'self' => t('define path to fckstyles.xml'), 'default' => t('FCKeditor default')),
1657 '#description' => t('Define the location of <code>fckstyles.xml</code> file. It is used by the "Style" dropdown list available in the Default toolbar.<br />Copy !fckstyles.xml inside your theme directory (<code>!theme</code>) and adjust it to your needs.', array('!fckstyles.xml' => drupal_get_path('module', 'fckeditor') .
'/fckeditor/fckstyles.xml', '!theme' => path_to_theme() .
'/fckstyles.xml'))
1660 $form['css']['styles_path'] = array(
1661 '#type' => 'textfield',
1662 '#title' => t('Predefined styles path'),
1663 '#default_value' => $edit->settings
['styles_path'],
1665 '#maxlength' => 255,
1666 '#description' => t('Enter path to XML file with predefined styles (<em>example: /fckstyles.xml</em>).<br />Macros: %h (host name: !host), %t (path to theme: !theme), %m (path to FCKeditor module: !module)<br />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')))
1669 // don't show useless options if IMCE is preferred
1670 if (function_exists('imce_integrate') && variable_get('imce_settings_fck', 0)) {
1671 $form['fckeditor_upload_settings'] = array(
1672 '#type' => 'fieldset',
1673 '#title' => t('File browser settings'),
1674 '#collapsible' => TRUE
,
1675 '#collapsed' => TRUE
,
1676 '#description' => t('The file browser settings are not diplayed because you have configured IMCE to handle file browsing.')
1680 $form['fckeditor_upload_settings'] = array(
1681 '#type' => 'fieldset',
1682 '#title' => t('File browser settings'),
1683 '#collapsible' => TRUE
,
1684 '#collapsed' => TRUE
,
1685 '#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.<br />',
1687 '!imce' => l(t('IMCE'), 'http://drupal.org/project/imce'),
1688 '!readme' => l('readme.txt', 'admin/help/fckeditor'),
1692 $form['fckeditor_upload_settings']['upload_basic'] = array(
1693 '#type' => 'select',
1694 '#options' => array('f' => t('false'), 't' => t('true')),
1695 '#title' => t('Allow basic file management'),
1696 '#default_value' => $edit->settings
['upload_basic'] ?
$edit->settings
['upload_basic'] : 'f',
1697 '#description' => t("Allow quick uploads."),
1699 $form['fckeditor_upload_settings']['upload_advanced'] = array(
1700 '#type' => 'select',
1701 '#options' => array('f' => t('false'), 't' => t('true')),
1702 '#title' => t('Allow advanced file management'),
1703 '#default_value' => $edit->settings
['upload_advanced'] ?
$edit->settings
['upload_advanced'] : 'f',
1704 '#description' => t('Allow file management in the advanced file manager.'),
1707 $current_user_files_path = strtr($edit->settings
['UserFilesPath'], array("%f" => file_directory_path(), "%u" => "UID", "%b" => base_path()));
1708 $current_user_files_absolute_path = strtr($edit->settings
['UserFilesAbsolutePath'], array("%f" => file_directory_path(), "%u" => "UID", "%b" => base_path(), "%d" => $_SERVER['DOCUMENT_ROOT']));
1710 $form['fckeditor_upload_settings']['UserFilesPath'] = array(
1711 '#type' => 'textfield',
1712 '#title' => t('Path to uploaded files'),
1713 '#default_value' => $edit->settings
['UserFilesPath'] ?
$edit->settings
['UserFilesPath'] : "%b%f/",
1715 '#maxlength' => 255,
1716 '#description' => t('Path to uploaded files relative to the document root.<br />Available wildcard characters:<br/><strong>%b</strong> - base URL path of the Drupal installation (!base).<br/><strong>%f</strong> - Drupal file system path where the files are stored (!files).<br /><strong>%u</strong> - User ID.<br />Current path: !path', array('!path' => $current_user_files_path, '!files' => file_directory_path(), '!base' => base_path())),
1718 $form['fckeditor_upload_settings']['UserFilesAbsolutePath'] = array(
1719 '#type' => 'textfield',
1720 '#title' => t('Absolute path to uploaded files'),
1721 '#default_value' => $edit->settings
['UserFilesAbsolutePath'] ?
$edit->settings
['UserFilesAbsolutePath'] : "%d%b%f/",
1723 '#maxlength' => 255,
1724 '#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.<br />Available wildcard characters:<br/><strong>%d</strong> - server path to document root (!root).<br /><strong>%b</strong> - base URL path of the Drupal installation (!base).<br/><strong>%f</strong> - Drupal file system path where the files are stored (!files).<br /><strong>%u</strong> - User ID.<br />Current path: !path', array('!path' => $current_user_files_absolute_path, '!files' => file_directory_path(), '!base' => base_path(), '!root' => $_SERVER['DOCUMENT_ROOT'])),
1726 if (variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE
) {
1727 $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.');
1728 $form['fckeditor_upload_settings']['UserFilesPath']['#disabled'] = true
;
1729 $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.');
1730 $form['fckeditor_upload_settings']['UserFilesAbsolutePath']['#disabled'] = true
;
1734 $form['advanced'] = array(
1735 '#type' => 'fieldset',
1736 '#title' => t('Advanced options'),
1737 '#collapsible' => TRUE
,
1738 '#collapsed' => TRUE
,
1740 if (function_exists('linktocontent_node_menu') && function_exists('pathfilter_filter')) {
1741 $form['advanced']['linktoc'] = array(
1742 '#type' => 'select',
1743 '#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')),
1744 '#title' => t('Path Filter & Link To Content integration'),
1745 '#default_value' => empty($edit->settings
['linktoc']) ?
'p' : $edit->settings
['linktoc'],
1746 '#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'))),
1749 $form['advanced']['js_conf'] = array(
1750 '#type' => 'textarea',
1751 '#title' => t('Custom javascript configuration'),
1752 '#default_value' => $edit->settings
['js_conf'],
1755 '#description' => t('Warning: to change FCKeditor configuration globally, you should modify the config file: <code>!fckeditor_config</code>.<br/>Sometimes it is required to change the FCKeditor configuration for selected profile. Use this box to define settings that are uniqe for this profile.<br/>Available options are listed in the !docs.<br/>Warning: if you make something wrong here, FCKeditor may fail to load.<br/>For example to disable some advanced tabs in dialog windows in FCKeditor, add the following: !example',
1757 '!fckeditor_config' => drupal_get_path('module', 'fckeditor') .
"/fckeditor.config.js",
1758 '!docs' => l(t("FCKeditor documentation"), "http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Configuration/Configuration_Options"),
1759 "!example" => "<pre>LinkDlgHideTarget = true ;
1760 LinkDlgHideAdvanced = true ;
1761 ImageDlgHideLink = true ;
1762 ImageDlgHideAdvanced = true ;
1763 FlashDlgHideAdvanced = true ;</pre>")
1766 $form['submit'] = array(
1767 '#type' => 'submit',
1775 * Search the field id for matches in array of matches
1778 * A string representing a form field id
1780 * An $array with strings to match the $search parameter against
1783 * TRUE on match, FALSE on no match
1785 function fckeditor_idsearch($search, $array) {
1786 foreach ($array as
$key => $value) {
1787 if (!empty($value) && preg_match('/^'.
str_replace('*', '.*', addslashes($value)) .
'$/i', $search)) {
1788 // on any first match we know we're done here so return positive
1796 * Test if client can render the FCKeditor
1797 * Use built-in test method in fckeditor.php
1798 * If fckeditor.php is not found, return false (probably in such case fckeditor is not installed correctly)
1801 * TRUE if the browser is reasonably capable
1803 function fckeditor_is_compatible_client() {
1805 $fckeditor_main_file = drupal_get_path('module', 'fckeditor') .
'/fckeditor/fckeditor.php';
1806 if (file_exists($fckeditor_main_file)) {
1807 include_once
$fckeditor_main_file;
1808 if (function_exists('FCKeditor_IsCompatibleBrowser')) {
1809 return FCKeditor_IsCompatibleBrowser();
1812 $fck = new
FCKeditor("fake");
1813 return $fck->IsCompatible();
1820 function fckeditor_user_get_setting($user, $profile, $setting) {
1823 'show_toggle' => 't',
1825 'skin' => 'default',
1826 'toolbar' => 'default',
1832 $settings = $profile->settings
;
1834 if ($settings['allow_user_conf']) {
1835 $status = isset($user->{"fckeditor_".
$setting}) ?
$user->{"fckeditor_".
$setting} : (isset($settings[$setting]) ?
$settings[$setting] : $default[$setting]);
1838 $status = isset($settings[$setting]) ?
$settings[$setting] : $default[$setting];
1844 function fckeditor_user_get_profile($user) {
1845 static
$profile_name;
1847 // Since fckeditor_profile_load() makes a db hit, only call it when we're pretty sure
1848 // we're gonna render fckeditor.
1849 if (!isset($profile_name[$user->uid
])) {
1850 $sorted_roles = fckeditor_sorted_roles();
1851 foreach ($sorted_roles as
$rid => $name) {
1852 if (isset($user->roles
[$rid])) {
1857 if (isset($user->roles
[$rid])) {
1858 $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));
1860 else if ($user->uid
== "1") {
1861 $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));
1865 if (isset($profile_name[$user->uid
]) && $profile_name[$user->uid
]) {
1866 $profile = fckeditor_profile_load($profile_name[$user->uid
]);
1874 * Implementation of hook_file_download().
1875 * Support for private downloads.
1877 function fckeditor_file_download($file) {
1878 if (module_exists('imce') && variable_get('imce_settings_fck', 0)) {
1881 if (module_exists('upload')) {
1882 $result = db_query("SELECT f.* FROM {files} f WHERE filepath = '%s'", $file);
1883 if ($file = db_fetch_object($result)) {
1887 //it is probably file uploaded with FCKeditor
1888 if ($path = file_create_path($file)) {
1889 $ctype = ($info = @
getimagesize($path)) ?
$info['mime'] : (function_exists('mime_content_type') ?
mime_content_type($path) : 'application/x-download');
1890 return array('Content-type: '.
$ctype);
1896 function fckeditor_ask_delete_confirmation($is_global, $profile = "") {
1898 $delete_link = l(t('Yes, delete!'), 'admin/settings/fckeditor/deleteconfirmed/'.
urlencode($profile));
1899 $profile_name = t('!profile profile', array('!profile' => $profile));
1902 $delete_link = l(t('Yes, delete!'), 'admin/settings/fckeditor/deletegconfirmed');
1903 $profile_name = t('Global Profile');
1906 drupal_set_title(t('Confirm profile deletion'));
1907 drupal_set_message(t("You're about to delete the FCKeditor profile, read the question below carefully."), "warning");
1909 return t("<p>Are you sure that you want to delete the !profile?</p><p>!yes !no</p>",
1910 array('!profile' => $profile_name,
1911 '!yes' => $delete_link,
1912 '!no' => l(t('Cancel'), 'admin/settings/fckeditor', array('style' => 'margin-left:40px')),