Documentation improvements
[project/fckeditor.git] / fckeditor.module
1 <?php
2 // $Id$
3 /**
4 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
5 * Copyright (C) 2003-2007 Frederico Caldeira Knabben
6 *
7 * == BEGIN LICENSE ==
8 *
9 * Licensed under the terms of any of the following licenses at your
10 * choice:
11 *
12 * - GNU General Public License Version 2 or later (the "GPL")
13 * http://www.gnu.org/licenses/gpl.html
14 *
15 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
16 * http://www.gnu.org/licenses/lgpl.html
17 *
18 * - Mozilla Public License Version 1.1 or later (the "MPL")
19 * http://www.mozilla.org/MPL/MPL-1.1.html
20 *
21 * == END LICENSE ==
22 *
23 * @file
24 * FCKeditor Module for Drupal 5.x
25 *
26 * This module allows Drupal to replace textarea fields with FCKeditor.
27 *
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.
31 */
32
33 /**
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
36 */
37 define('FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME', 'DrupalBasic') ;
38
39 /**
40 * Implementation of hook_help
41 */
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"));
45 }
46
47 switch ($section) {
48 case 'admin/settings/help#description':
49 $output = t("Enables the usage of FCKeditor (WYSIWYG editor) instead of plain text fields.");
50 break;
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>");
54 break;
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>",
57 array(
58 '!fckeditorlink' => l(t('FCKeditor homepage'), 'http://www.fckeditor.net'),
59 '!userguidelink' => l(t('FCKeditor userguide'), 'http://docs.fckeditor.net/FCKeditor/Users_Guide'))
60 );
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')));
62 break;
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>",
65 array(
66 '!fckeditorlink' => l(t('FCKeditor homepage'), 'http://www.fckeditor.net'),
67 '!userguidelink' => l(t('FCKeditor userguide'), 'http://docs.fckeditor.net/FCKeditor/Users_Guide'))
68 );
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>',
70 array(
71 '!fckeditorlink' => l(t('FCKeditor homepage'), 'http://www.fckeditor.net/download'),
72 '%fckeditordir' => base_path() . drupal_get_path('module', 'fckeditor') .'/fckeditor/')
73 );
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>',
75 array(
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'))
83 );
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>',
85 array(
86 '%fckeditordir' => base_path() . drupal_get_path('module', 'fckeditor') .'/fckeditor/')
87 );
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 ..."
90 ));
91 $output .= t("<h3>Plugins: Teaser break and Pagebreak</h3><p>By default, FCKeditor module comes with two plugins that can handle teaser break (&lt;!--break--&gt;) and pagebreak (&lt;!--pagebreak--&gt;). 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>",
92 array(
93 '!fckeditor.config.js' => base_path() . drupal_get_path('module', 'fckeditor') .'/fckeditor.config.js',
94 '!code' => "
95 FCKConfig.PluginsPath = '../../plugins/' ;
96 FCKConfig.Plugins.Add( 'drupalbreak' ) ;
97 FCKConfig.Plugins.Add( 'drupalpagebreak' ) ;
98 ",
99 '!buttons1' => "['Image','Flash','Table','Rule','SpecialChar']",
100 '!buttons2' => "['Image','Flash','Table','Rule','SpecialChar', 'DrupalBreak', 'DrupalPageBreak']",
101 ));
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>',
103 array(
104 '!imce' => l(t('IMCE'), 'http://drupal.org/project/imce')
105 )
106 );
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'] = '' ;",
116 )
117 );
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>&#36;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"));
122
123 break;
124 }
125 return $output;
126 }
127
128 /**
129 * Implementation of hook_perm
130 * Administer -> User management -> Access Control
131 */
132 function fckeditor_perm() {
133 return array('administer fckeditor', 'access fckeditor', 'allow fckeditor file uploads');
134 }
135
136
137 /**
138 * Implementation of textarea
139 * Replace textarea with FCKeditor using callback function (fckeditor_process_textarea)
140 */
141 function fckeditor_elements() {
142 $type = array();
143 $type['textfield'] = array(
144 '#process' => array(
145 'fckeditor_process_input' => array()
146 ),
147 );
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(
153 '#process' => array(
154 'fckeditor_process_textarea' => array()
155 ),
156 );
157 }
158 }
159 return $type;
160 }
161
162 /**
163 * Allow more than 255 chars in Allowed HTML tags textfield
164 *
165 */
166 function fckeditor_process_input($element) {
167 if ($element['#id']=='edit-allowed-html-1') {
168 $element['#maxlength'] = max($element['#maxlength'], 1024);
169 }
170 return $element;
171 }
172
173 /**
174 * Add link to FCKeditor configuration in "Administer -> Site configuration" section
175 *
176 */
177 function fckeditor_menu($may_cache) {
178 $items = array();
179 if ($may_cache) {
180 $items[] = array(
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'));
186 }
187 else {
188 drupal_add_css(drupal_get_path('module', 'fckeditor') .'/fckeditor.css');
189 }
190 return $items;
191 }
192
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);
197 }
198
199 /**
200 * Profile validation.
201 */
202 function fckeditor_profile_validate($edit) {
203 $errors = array();
204
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.');
207 }
208
209 if (!preg_match("/^\d+$/", trim($edit['min_rows']))) {
210 $errors['min_rows'] = t('Minimum rows must be a valid number');
211 }
212
213 if ($edit['default'] == 't' && $edit['popup'] == 't') {
214 $errors['popup'] = t('If FCKeditor is enabled by default, popup window must be disabled.');
215 }
216
217 if ($edit['show_toggle'] == 't' && $edit['popup'] == 't') {
218 $errors['popup'] = t('If toggle is enabled, popup window must be disabled.');
219 }
220
221 if (!$edit['name']) {
222 $errors['name'] = t('You must give a profile name.');
223 }
224
225 if (!preg_match("/^\d+%?$/", $edit['width'])) {
226 $errors['width'] = t('Enter valid width. Ex: 400 or 100%');
227 }
228
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.');
232 }
233 else if (false !== strpos($edit['css_path'], '"')) {
234 $errors['css_path'] = t('Double quotes are not allowed in CSS path.');
235 }
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.');
238 }
239 }
240
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.');
244 }
245 else if (false !== strpos($edit['styles_path'], '"')) {
246 $errors['styles_path'] = t('Double quotes are not allowed in path.');
247 }
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.');
250 }
251 }
252
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).');
256 }
257 }
258
259 //validate fields
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));
264 break;
265 }
266 }
267
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));
272 break;
273 }
274 }
275
276 //validate paths
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));
281 break;
282 }
283 }
284
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));
289 break;
290 }
291 }
292
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.");
296 }
297 if ($edit['UserFilesPath'] && !$edit['UserFilesAbsolutePath']) {
298 $errors['UserFilesPath'] = t("Absolute path to uploaded files is required.");
299 }
300 }
301
302 foreach ($errors as $name => $message) {
303 form_set_error($name, $message);
304 }
305
306 return count($errors) == 0;
307 }
308
309 /**
310 * Global profile validation.
311 */
312 function fckeditor_global_profile_validate($edit) {
313 $errors = array();
314
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.');
317 }
318
319 //validate fields
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));
324 break;
325 }
326 }
327
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));
332 break;
333 }
334 }
335
336 //validate paths
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));
341 break;
342 }
343 }
344
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));
349 break;
350 }
351 }
352
353 foreach ($errors as $name => $message) {
354 form_set_error($name, $message);
355 }
356
357 return count($errors) == 0;
358 }
359
360 /**
361 * Controller for FCKeditor administrative settings.
362 */
363 function fckeditor_admin($arg = NULL) {
364
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)));
369 drupal_set_message(
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.',
371 array(
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')),
377 'error');
378 return false;
379 }
380
381 $edit = $_POST;
382 $op = isset($_POST['op']) ? $_POST['op'] : "";
383 $op = $arg && !$op ? $arg : $op;
384
385 switch ($op) {
386 case 'add':
387 $output = fckeditor_profile_form($edit);
388 break;
389
390 case 'addg':
391 $output = fckeditor_global_profile_form($edit);
392 break;
393
394 case 'deleteg':
395 $output = fckeditor_ask_delete_confirmation(true);
396 break;
397
398 case 'delete':
399 $output = fckeditor_ask_delete_confirmation(false, urldecode(arg(4)));
400 break;
401
402 case 'edit':
403 drupal_set_title(t('Edit FCKeditor profile'));
404 $output = fckeditor_profile_form(fckeditor_profile_load(urldecode(arg(4))));
405 break;
406
407 case 'editg':
408 drupal_set_title(t('Edit FCKeditor profile'));
409 $output = fckeditor_global_profile_form(fckeditor_profile_load("FCKeditor Global Profile"));
410 break;
411
412 case 'deleteconfirmed':
413 fckeditor_profile_delete(urldecode(arg(4)));
414 drupal_set_message(t('Deleted profile'));
415 drupal_goto('admin/settings/fckeditor');
416 break;
417
418 case 'deletegconfirmed':
419 fckeditor_profile_delete("FCKeditor Global Profile");
420 drupal_set_message(t('Deleted Global profile'));
421 drupal_goto('admin/settings/fckeditor');
422 break;
423
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');
430 }
431 else {
432 $output = fckeditor_profile_form($edit);
433 }
434 break;
435
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');
443 }
444 else {
445 $output = fckeditor_global_profile_form($edit);
446 }
447 break;
448
449 default:
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');
455 }
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");
460 }
461 else {
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;
467 }
468
469 //find roles with profiles
470 $result = db_query("SELECT rid FROM {fckeditor_role}");
471 $rids = array();
472 while ($obj = db_fetch_object($result)) {
473 $rids[] = $obj->rid;
474 }
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");
478 }
479 else {
480 //not all roles with access fckeditor has their FCKeditor profile assigned
481 $diff = array_diff(array_keys($access_fckeditor_roles), $rids);
482 if ($diff) {
483 $list = "<ul>";
484 foreach ($diff as $rid) {
485 $list .= "<li>". $access_fckeditor_roles[$rid] ."</li>";
486 }
487 $list .= "</ul>";
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 &quot;Roles allowed to use this profile&quot;.", array("!access" => l(t("access fckeditor"), "admin/user/access"), "!list" => $list)), "warning");
489 }
490 }
491 }
492
493 $output = fckeditor_profile_overview();
494 }
495
496 return $output;
497 }
498
499 /**
500 * Save a profile to the database.
501 * @todo add more entries to array in the user_save line
502 */
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));
507 if ($edit['rids']) {
508 foreach ($edit['rids'] as $rid => $value) {
509 db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)", $edit['name'], $rid);
510 }
511 }
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') {
514 global $user;
515 user_save($user, array('fckeditor_status' => NULL));
516 }
517 }
518
519 function fckeditor_global_profile_save($edit) {
520 if (isset($edit['rank'])) {
521 $edit['rank'] = explode('>', str_replace(' ', '', $edit['rank']));
522 }
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));
526 }
527
528 /**
529 * Controller for fckeditor profiles.
530 */
531 function fckeditor_profile_overview() {
532 $output = '';
533
534 $profiles = fckeditor_profile_load();
535 if ($profiles) {
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) {
540 $rids = $p->rids;
541 if ($p->name !== "FCKeditor Global Profile") {
542 foreach ($p->rids as $rid => $name) {
543 if (!isset($access_fckeditor_roles[$rid])) {
544 unset($rids[$rid]);
545 }
546 }
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'));
548 }
549 }
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>';
553 }
554 else {
555 drupal_set_message(t('No profiles found. Click here to !create.', array('!create' => l(t("create a new profile"), 'admin/settings/fckeditor/add'))));
556 }
557
558 $rows = array();
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'))));
561 }
562 else {
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);
566 }
567
568 return $output;
569 }
570
571 /**
572 * Load all profiles. Just load one profile if $name is passed in.
573 */
574 function fckeditor_profile_load($name = '') {
575 static $profiles = array();
576
577 if (!$profiles) {
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);
583 $role = array();
584 while ($r = db_fetch_object($result2)) {
585 $role[$r->rid] = $roles[$r->rid];
586 }
587 $data->rids = $role;
588
589 $profiles[$data->name] = $data;
590 }
591 }
592
593 return ($name ? $profiles[$name] : $profiles);
594 }
595
596 /**
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
602 *
603 * @return boolean
604 * returns true if FCKeditor is enabled
605 */
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);
609
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);
613
614 $found = $field_found || $path_found;
615
616 $result = ($excl_mode == 1) ? $found : !$found;
617 return $result;
618 }
619
620 /**
621 * This function create the HTML objects required for the FCKeditor
622 *
623 * @param $element
624 * A fully populated form elment to add the editor to
625 * @return
626 * The same $element with extra FCKeditor markup and initialization
627 */
628 function fckeditor_process_textarea($element) {
629 static $is_running = FALSE;
630 static $num = 1;
631 global $user, $fckeditor_simple_toolbar_ids;
632
633 //skip this one, surely nobody wants WYSIWYG here
634
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':
640 case 'edit-log':
641 case 'edit-excl-fields':
642 case 'edit-excl-paths':
643 case 'edit-js-conf':
644 return $element;
645 break;
646 }
647
648 $profile = fckeditor_user_get_profile($user);
649 if (!$profile) {
650 return $element;
651 }
652
653 $conf = array();
654 $conf = $profile->settings;
655
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);
659 }
660 }
661 if ($conf["popup"]=="t" && $conf["show_toggle"]=="t") {
662 $conf["show_toggle"]="f";
663 }
664
665 $themepath = path_to_theme() .'/';
666 $host = base_path();
667
668 $enabled = fckeditor_is_enabled($conf['excl_mode'], $conf['excl_fields'], $conf['excl_paths'], $element['#id'], $_GET['q']);
669 if ($enabled) {
670 $global_profile = fckeditor_profile_load("FCKeditor Global Profile");
671 $global_conf = $global_profile->settings;
672 if ($global_conf) {
673 $enabled = fckeditor_is_enabled($global_conf['excl_mode'], $global_conf['excl_fields'], $global_conf['excl_paths'], $element['#id'], $_GET['q']);
674 }
675 }
676
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;
681 }
682
683 // only replace textarea when it has enough rows and it is enabled
684
685 $js_id = 'oFCK_'. $num++;
686 $fckeditor_on = ($conf['default']=='t') ? 1 : 0 ;
687
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'] = "";
694 }
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;
700 }
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)
708 // module_full_path:
709 // '/drupal5/modules/fckeditor' (length=26)
710 // files_path:
711 // '/drupal5/files' (length=14)
712 // configured in settings
713 $width = $conf['width'];
714
715 // sensible default for small toolbars
716 $height = $element['#rows'] * 14 + 140;
717
718 if (!$is_running) {
719 drupal_add_js($module_drupal_path .'/fckeditor/fckeditor.js');
720 drupal_add_js($module_drupal_path .'/fckeditor.utils.js');
721 $is_running = true;
722 }
723
724 $toolbar = $conf['toolbar'];
725 //$height += 100; // for larger toolbars
726
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']);
730 }
731 if ($force_simple_toolbar) {
732 $toolbar = FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME;
733 }
734
735 $textarea_id = $conf['show_toggle'] == 't' ? $js_id : $element['#id'];
736
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'] ."\";";
741
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";
750 //}
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";
757 //}
758
759 if (function_exists('img_assist_perm')) {
760 drupal_add_js("var fckImgAssistPath = '". base_path() . drupal_get_path('module', 'img_assist') ."';", 'inline');
761 }
762
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";
768 }
769 }
770 $js .= $js_id .".Config['DrupalPath'] = '". base_path() ."';\n";
771 }
772
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;
777 $basic_uploads = 0;
778 }
779 else {
780 $advanced_uploads = ($conf['upload_advanced']=="t");
781 $basic_uploads = ($conf['upload_basic']=="t");
782 }
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";
793 }
794 else {
795 $js .= $js_id .".Config['LinkBrowser'] = false;
796 ". $js_id .".Config['ImageBrowser'] = false;
797 ". $js_id .".Config['FlashBrowser'] = false;\n";
798 }
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";
803 }
804 else {
805 $js .= $js_id .".Config['LinkUpload'] = false;
806 ". $js_id .".Config['ImageUpload'] = false;
807 ". $js_id .".Config['FlashUpload'] = false;\n";
808 }
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;
814 }
815 }
816 else {
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";
823 }
824
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);
833 }
834 }
835 }
836
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";
842 }
843 }
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";
847 }
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\";";
854 }
855 }
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\";";
859 }
860
861 drupal_add_js('var '. $js_id .';if (Drupal.jsEnabled) {$(document).ready(function() {'. $js .'});}', 'inline');
862
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>";
867 }
868 else {
869 // if no popup mode, add the editor initialization to the footer
870 // this obviously needs print($closure) in page.tpl.php
871 if ($fckeditor_on) {
872 drupal_add_js('if (Drupal.jsEnabled) {$(document).ready(function() {window.setTimeout("'. $js_id .'.ReplaceTextarea()",100);});}', 'inline', 'footer');
873 }
874 }
875 }
876
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'],
883 )) .'</div>';
884 }
885
886 return $element;
887 }
888
889 /**
890 * Implementation of hook_user().
891 */
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();
898
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'),
904 '#weight' => 10,
905 '#collapsible' => TRUE,
906 '#collapsed' => TRUE
907 );
908
909 $form['fckeditor']['fckeditor_default'] = array(
910 '#type' => 'select',
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.'),
915 );
916
917 $form['fckeditor']['fckeditor_show_toggle'] = array(
918 '#type' => 'select',
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).'),
923 );
924
925 $form['fckeditor']['fckeditor_popup'] = array(
926 '#type' => 'select',
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.'),
931 );
932
933 $form['fckeditor']['fckeditor_skin'] = array(
934 '#type' => 'select',
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.'),
939 );
940
941 $form['fckeditor']['fckeditor_toolbar'] = array(
942 '#type' => 'select',
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.'),
947 );
948
949 $form['fckeditor']['fckeditor_expand'] = array(
950 '#type' => 'select',
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.'),
955 );
956
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%"),
962 '#size' => 40,
963 '#maxlength' => 128,
964 );
965
966 $form['fckeditor']['fckeditor_lang'] = array(
967 '#type' => 'select',
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.')
972 );
973
974 $form['fckeditor']['fckeditor_auto_lang'] = array(
975 '#type' => 'select',
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.')
980 );
981
982 return array('fckeditor' => $form);
983 }
984 }
985
986 if ($type == 'validate') {
987 return array(
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'],
997 );
998 }
999 }
1000
1001 /**
1002 * Return an HTML form for profile configuration.
1003 */
1004 function fckeditor_profile_form($edit) {
1005
1006 $output .= drupal_get_form('fckeditor_profile_form_build', $edit);
1007
1008 return $output;
1009 }
1010
1011 /**
1012 * Return an HTML form for global profile configuration.
1013 */
1014 function fckeditor_global_profile_form($edit) {
1015
1016 $output .= drupal_get_form('fckeditor_global_profile_form_build', $edit);
1017
1018 return $output;
1019 }
1020
1021 function fckeditor_load_toolbar_options() {
1022 $arr = array();
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");
1028 if ($fp) {
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]);
1033 }
1034 }
1035 fclose($fp);
1036 }
1037 }
1038 if (file_exists($fckeditor_config_js) && is_readable($fckeditor_config_js)) {
1039 $fp = @fopen($fckeditor_config_js, "r");
1040 if ($fp) {
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]);
1045 }
1046 }
1047 fclose($fp);
1048 }
1049 }
1050
1051 //oops, we have no information about toolbars, let's use hardcoded array
1052 if (empty($arr)) {
1053 $arr = array(
1054 'Basic' => 'Basic',
1055 'Default' => 'Default',
1056 );
1057 }
1058 asort($arr);
1059
1060 return $arr;
1061 }
1062
1063 function fckeditor_load_skin_options() {
1064 $arr = array();
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"))) {
1072 continue;
1073 }
1074 if (is_dir($skin_dir . DIRECTORY_SEPARATOR . $file)) {
1075 $arr[$file] = ucfirst($file);
1076 }
1077 }
1078 closedir( $dh );
1079 }
1080 }
1081
1082 //oops, we have no information about skins, let's use only default
1083 if (empty($arr)) {
1084 $arr = array(
1085 'default' => 'Default',
1086 );
1087 }
1088 asort($arr);
1089
1090 return $arr;
1091 }
1092
1093 function fckeditor_load_lang_options() {
1094 $arr = array();
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"))) {
1102 continue;
1103 }
1104 if (is_file($lang_dir . DIRECTORY_SEPARATOR . $file) && preg_match("/^(.*?)\.js$/", $file, $matches)) {
1105 $lang = $matches[1];
1106 $arr[$lang] = strtoupper($lang);
1107 }
1108 }
1109 closedir( $dh );
1110 }
1111 }
1112
1113 //oops, we have no information about languages, let's use those available in FCKeditor 2.4.3
1114 if (empty($arr)) {
1115 $arr = array(
1116 'af' => 'Afrikaans',
1117 'ar' => 'Arabic',
1118 'bg' => 'Bulgarian',
1119 'bn' => 'Bengali/Bangla',
1120 'bs' => 'Bosnian',
1121 'ca' => 'Catalan',
1122 'cs' => 'Czech',
1123 'da' => 'Danish',
1124 'de' => 'German',
1125 'el' => 'Greek',
1126 'en' => 'English',
1127 'en-au' => 'English (Australia)',
1128 'en-ca' => 'English (Canadian)',
1129 'en-uk' => 'English (United Kingdom)',
1130 'eo' => 'Esperanto',
1131 'es' => 'Spanish',
1132 'et' => 'Estonian',
1133 'eu' => 'Basque',
1134 'fa' => 'Persian',
1135 'fi' => 'Finnish',
1136 'fo' => 'Faroese',
1137 'fr' => 'French',
1138 'gl' => 'Galician',
1139 'he' => 'Hebrew',
1140 'hi' => 'Hindi',
1141 'hr' => 'Croatian',
1142 'hu' => 'Hungarian',
1143 'it' => 'Italian',
1144 'ja' => 'Japanese',
1145 'km' => 'Khmer',
1146 'ko' => 'Korean',
1147 'lt' => 'Lithuanian',
1148 'lv' => 'Latvian',
1149 'mn' => 'Mongolian',
1150 'ms' => 'Malay',
1151 'nb' => 'Norwegian Bokmal',
1152 'nl' => 'Dutch',
1153 'no' => 'Norwegian',
1154 'pl' => 'Polish',
1155 'pt' => 'Portuguese (Portugal)',
1156 'pt-br' => 'Portuguese (Brazil)',
1157 'ro' => 'Romanian',
1158 'ru' => 'Russian',
1159 'sk' => 'Slovak',
1160 'sl' => 'Slovenian',
1161 'sr' => 'Serbian (Cyrillic)',
1162 'sr-latn' => 'Serbian (Latin)',
1163 'sv' => 'Swedish',
1164 'th' => 'Thai',
1165 'tr' => 'Turkish',
1166 'uk' => 'Ukrainian',
1167 'vi' => 'Vietnamese',
1168 'zh' => 'Chinese Traditional',
1169 'zh-cn' => 'Chinese Simplified',
1170 );
1171 }
1172
1173 asort($arr);
1174
1175 return $arr;
1176 }
1177
1178 /**
1179 * sort roles according to precedence settings. previously sorted roles are followed by latest added roles.
1180 */
1181 function fckeditor_sorted_roles() {
1182 static $order;
1183 if (isset($order)) {
1184 return $order;
1185 }
1186 $order = array();
1187 $roles = user_roles(0, 'access fckeditor');
1188
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]);
1198 }
1199 }
1200 }
1201 krsort($roles);//sort the remaining unsorted roles by id, descending.
1202 $order += $roles;
1203 return $order;
1204 }
1205
1206 function fckeditor_global_profile_form_build($edit) {
1207 $edit = (object) $edit;
1208
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);
1214
1215 $result = db_query("SELECT DISTINCT(rid) FROM {fckeditor_role} WHERE name='FCKeditor Global Profile'");
1216 $data = db_fetch_object($result);
1217
1218 if ($data->rid) {
1219 drupal_set_message(t("Global profile already exist. Only one global profile is allowed."), "error");
1220 return array();
1221 }
1222
1223 $btn = t('Create global profile');
1224 }
1225 else {
1226 $form['old_name'] = array('#type' => 'hidden', '#value' => $edit->name);
1227 $btn = t('Update global profile');
1228 }
1229
1230 $form['common'] = array(
1231 '#type' => 'fieldset',
1232 '#title' => t('Main setup'),
1233 '#collapsible' => TRUE,
1234 '#collapsed' => TRUE
1235 );
1236
1237 $roles = fckeditor_sorted_roles();
1238 $rids = $rtext = array();
1239 foreach ($roles as $rid => $name) {
1240 $rids[] = $rid;
1241 $rtext[] = '<strong>'. $rid .' - </strong>'. $name;
1242 }
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 />'),
1247 );
1248 if ($rids) {
1249 $form['common']['rank']['#description'] .= t('Here is the id-name pairs of roles having access to FCKeditor:') .'<div>'. implode('<br />', $rtext) .'</div>';
1250 }
1251 else {
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')));
1253 }
1254
1255 $form['fckeditor_exclude_settings'] = array(
1256 '#type' => 'fieldset',
1257 '#title' => t('Visibility settings'),
1258 '#collapsible' => TRUE,
1259 '#collapsed' => TRUE,
1260 );
1261
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.'),
1268 );
1269
1270 /**
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
1274 */
1275 $form['fckeditor_exclude_settings']['excl_fields'] = array(
1276 '#type' => 'textarea',
1277 '#title' => t('Fields to exclude/include'),
1278 '#cols' => 60,
1279 '#rows' => 5,
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."),
1284 );
1285
1286 /**
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
1290 */
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>',
1296 '#cols' => 60,
1297 '#rows' => 5,
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>)."),
1300 );
1301
1302 $form['fckeditor_exclude_settings']['simple_incl_fields'] = array(
1303 '#type' => 'textarea',
1304 '#title' => t('Force simplified toolbar on the following fields'),
1305 '#cols' => 60,
1306 '#rows' => 5,
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."),
1309 );
1310
1311 $form['fckeditor_exclude_settings']['simple_incl_paths'] = array(
1312 '#type' => 'textarea',
1313 '#title' => t('Force simplified toolbar on the following paths'),
1314 '#cols' => 60,
1315 '#rows' => 5,
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>)."),
1318 );
1319
1320 $form['submit'] = array(
1321 '#type' => 'submit',
1322 '#value' => $btn
1323 );
1324
1325 return $form;
1326 }
1327
1328 /**
1329 * Return an HTML form for profile configuration.
1330 */
1331 function fckeditor_profile_form_build($edit) {
1332 $edit = (object) $edit;
1333
1334 $toolbar_options = fckeditor_load_toolbar_options();
1335 $skin_options = fckeditor_load_skin_options();
1336 $lang_options = fckeditor_load_lang_options();
1337
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;
1342
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.',
1345 array(
1346 '!access1' => t('access fckeditor'),
1347 '!permissions' => l(t('permissions'), 'admin/user/access'))), 'warning');
1348 }
1349
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);
1355
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]);
1360 }
1361 }
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.'));
1364 }
1365 $btn = t('Create profile');
1366 }
1367 else {
1368 $form['old_name'] = array('#type' => 'hidden', '#value' => $edit->name);
1369 $btn = t('Update profile');
1370 }
1371
1372 $form['basic'] = array(
1373 '#type' => 'fieldset',
1374 '#title' => t('Basic setup'),
1375 '#collapsible' => TRUE,
1376 '#collapsed' => TRUE
1377 );
1378
1379 $form['basic']['name'] = array(
1380 '#type' => 'textfield',
1381 '#title' => t('Profile name'),
1382 '#default_value' => $edit->name,
1383 '#size' => 40,
1384 '#maxlength' => 128,
1385 '#description' => t('Enter a name for this profile. This name is only visible within the fckeditor administration page.'),
1386 '#required' => TRUE
1387 );
1388
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"))),
1395 '#required' => TRUE
1396 );
1397
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.'),
1404 );
1405
1406 $form['fckeditor_exclude_settings'] = array(
1407 '#type' => 'fieldset',
1408 '#title' => t('Visibility settings'),
1409 '#collapsible' => TRUE,
1410 '#collapsed' => TRUE,
1411 );
1412
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."),
1418 );
1419
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.'),
1426 );
1427
1428 /**
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
1432 */
1433 $form['fckeditor_exclude_settings']['excl_fields'] = array(
1434 '#type' => 'textarea',
1435 '#title' => t('Fields to exclude/include'),
1436 '#cols' => 60,
1437 '#rows' => 5,
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."),
1442 );
1443
1444 /**
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
1448 */
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>',
1454 '#cols' => 60,
1455 '#rows' => 5,
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>)."),
1458 );
1459
1460 $form['fckeditor_exclude_settings']['simple_incl_fields'] = array(
1461 '#type' => 'textarea',
1462 '#title' => t('Force simplified toolbar on the following fields'),
1463 '#cols' => 60,
1464 '#rows' => 5,
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."),
1468 );
1469
1470 $form['fckeditor_exclude_settings']['simple_incl_paths'] = array(
1471 '#type' => 'textarea',
1472 '#title' => t('Force simplified toolbar on the following paths'),
1473 '#cols' => 60,
1474 '#rows' => 5,
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>)."),
1478 );
1479
1480 $form['appearance'] = array(
1481 '#type' => 'fieldset',
1482 '#title' => t('Editor appearance'),
1483 '#collapsible' => TRUE,
1484 '#collapsed' => TRUE,
1485 );
1486
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.'),
1493 );
1494
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).'),
1501 );
1502
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.'),
1509 );
1510
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.'),
1517 );
1518
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'))),
1525 );
1526
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.'),
1533 );
1534
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%"),
1540 '#size' => 40,
1541 '#maxlength' => 128,
1542 );
1543
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.')
1550 );
1551
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.')
1558 );
1559
1560 /*
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.'),
1567 );
1568 */
1569
1570 $form['output'] = array(
1571 '#type' => 'fieldset',
1572 '#title' => t('Cleanup and output'),
1573 '#collapsible' => TRUE,
1574 '#collapsed' => TRUE,
1575 );
1576
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.')
1583 );
1584
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.')
1591 );
1592
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',
1597 '#size' => 40,
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'),
1600 );
1601
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.'),
1608 );
1609
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.'),
1616 );
1617
1618 /*
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.'),
1625 );
1626 */
1627
1628 $form['css'] = array(
1629 '#type' => 'fieldset',
1630 '#title' => t('CSS'),
1631 '#collapsible' => TRUE,
1632 '#collapsed' => TRUE
1633 );
1634
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.')
1641 );
1642
1643 $form['css']['css_path'] = array(
1644 '#type' => 'textfield',
1645 '#title' => t('CSS path'),
1646 '#default_value' => $edit->settings['css_path'],
1647 '#size' => 40,
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() .'/'))
1650 );
1651
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 &quot;Style&quot; 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'))
1658 );
1659
1660 $form['css']['styles_path'] = array(
1661 '#type' => 'textfield',
1662 '#title' => t('Predefined styles path'),
1663 '#default_value' => $edit->settings['styles_path'],
1664 '#size' => 40,
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')))
1667 );
1668
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.')
1677 );
1678 }
1679 else {
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 />',
1686 array(
1687 '!imce' => l(t('IMCE'), 'http://drupal.org/project/imce'),
1688 '!readme' => l('readme.txt', 'admin/help/fckeditor'),
1689 )
1690 )
1691 );
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."),
1698 );
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.'),
1705 );
1706
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']));
1709
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/",
1714 '#size' => 40,
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())),
1717 );
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/",
1722 '#size' => 40,
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'])),
1725 );
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;
1731 }
1732 }
1733
1734 $form['advanced'] = array(
1735 '#type' => 'fieldset',
1736 '#title' => t('Advanced options'),
1737 '#collapsible' => TRUE,
1738 '#collapsed' => TRUE,
1739 );
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'))),
1747 );
1748 }
1749 $form['advanced']['js_conf'] = array(
1750 '#type' => 'textarea',
1751 '#title' => t('Custom javascript configuration'),
1752 '#default_value' => $edit->settings['js_conf'],
1753 '#cols' => 60,
1754 '#rows' => 5,
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',
1756 array(
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>")
1764 ));
1765
1766 $form['submit'] = array(
1767 '#type' => 'submit',
1768 '#value' => $btn
1769 );
1770
1771 return $form;
1772 }
1773
1774 /**
1775 * Search the field id for matches in array of matches
1776 *
1777 * @param $search
1778 * A string representing a form field id
1779 * @ param $array
1780 * An $array with strings to match the $search parameter against
1781 *
1782 * @return
1783 * TRUE on match, FALSE on no match
1784 */
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
1789 return true;
1790 }
1791 }
1792 return false;
1793 }
1794
1795 /**
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)
1799 *
1800 * @return
1801 * TRUE if the browser is reasonably capable
1802 */
1803 function fckeditor_is_compatible_client() {
1804
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();
1810 }
1811 else {
1812 $fck = new FCKeditor("fake");
1813 return $fck->IsCompatible();
1814 }
1815 }
1816
1817 return false;
1818 }
1819
1820 function fckeditor_user_get_setting($user, $profile, $setting) {
1821 $default = array(
1822 'default' => 't',
1823 'show_toggle' => 't',
1824 'popup' => 'f',
1825 'skin' => 'default',
1826 'toolbar' => 'default',
1827 'expand' => 't',
1828 'width' => '100%',
1829 'lang' => 'en',
1830 'auto_lang' => 't',
1831 );
1832 $settings = $profile->settings;
1833
1834 if ($settings['allow_user_conf']) {
1835 $status = isset($user->{"fckeditor_". $setting}) ? $user->{"fckeditor_". $setting} : (isset($settings[$setting]) ? $settings[$setting] : $default[$setting]);
1836 }
1837 else {
1838 $status = isset($settings[$setting]) ? $settings[$setting] : $default[$setting];
1839 }
1840
1841 return $status;
1842 }
1843
1844 function fckeditor_user_get_profile($user) {
1845 static $profile_name;
1846
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])) {
1853 break;
1854 }
1855 }
1856
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));
1859 }
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));
1862 }
1863 }
1864
1865 if (isset($profile_name[$user->uid]) && $profile_name[$user->uid]) {
1866 $profile = fckeditor_profile_load($profile_name[$user->uid]);
1867 return $profile;
1868 }
1869
1870 return false;
1871 }
1872
1873 /**
1874 * Implementation of hook_file_download().
1875 * Support for private downloads.
1876 */
1877 function fckeditor_file_download($file) {
1878 if (module_exists('imce') && variable_get('imce_settings_fck', 0)) {
1879 return null;
1880 }
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)) {
1884 return null;
1885 }
1886 }
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);
1891 }
1892
1893 return -1;
1894 }
1895
1896 function fckeditor_ask_delete_confirmation($is_global, $profile = "") {
1897 if (!$is_global) {
1898 $delete_link = l(t('Yes, delete!'), 'admin/settings/fckeditor/deleteconfirmed/'. urlencode($profile));
1899 $profile_name = t('!profile profile', array('!profile' => $profile));
1900 }
1901 else {
1902 $delete_link = l(t('Yes, delete!'), 'admin/settings/fckeditor/deletegconfirmed');
1903 $profile_name = t('Global Profile');
1904 }
1905
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");
1908
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')),
1913 ));
1914 }