4 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
5 * Copyright (C) 2003-2008 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 6.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 * Main administrative page
36 function fckeditor_admin_main() {
37 $editor_path = fckeditor_path(TRUE
);
38 $fckconfig_file = $editor_path .
'/fckconfig.js';
39 if (!file_exists($fckconfig_file)) {
40 drupal_set_message(t('Checking for %filename.', array('%filename' => $fckconfig_file)));
41 drupal_set_message(t('The FCKeditor component is not installed correctly. Please go to the <a href="!fckeditorlink">FCKeditor homepage</a> to download the latest version. After that you must extract the files to %fckeditorpath and make sure that the directory %fckeditorsubdir and the file %fckeditorfile exist. Refer to the <a href="!readme">readme.txt</a> for more information.', array('!fckeditorlink' => url('http://www.fckeditor.net/download'), '!readme' => url('admin/help/fckeditor'), '%fckeditorpath' => $editor_path, '%fckeditorsubdir' => $editor_path .
'/editor', '%fckeditorfile' => $editor_path .
'/fckeditor.js')), 'error');
42 drupal_set_message(t('If you have FCKeditor already installed please edit <a href="!editg">FCKeditor Global Profile</a> and update FCKeditor path.', array('!editg' => url('admin/settings/fckeditor/editg'))), 'warning');
46 $access_fckeditor_roles = user_roles(FALSE
, 'access fckeditor');
47 if (!$access_fckeditor_roles) {
48 drupal_set_message(t('There is currently no role with the "access fckeditor" permission. Visit <a href="!acl">permissions</a> administration section.', array('!acl' => url('admin/user/permissions'))), 'warning');
51 $result = db_query_range("SELECT name FROM {fckeditor_settings} WHERE name<>'FCKeditor Global Profile'", 0, 1);
52 $has_profiles = FALSE
;
53 //find profile other than Global
54 if (($obj = db_fetch_object($result))) {
58 //find roles with profiles
59 $result = db_query("SELECT rid FROM {fckeditor_role}");
61 while (($obj = db_fetch_object($result))) {
64 $rids = array_unique($rids);
66 drupal_set_message(t('No FCKeditor profiles found. At this moment, nobody is able to use FCKeditor. Create new profile below.'), 'error');
69 //not all roles with access fckeditor has their FCKeditor profile assigned
70 $diff = array_diff(array_keys($access_fckeditor_roles), $rids);
73 foreach ($diff as
$rid) {
74 $list .
= "<li>".
$access_fckeditor_roles[$rid] .
"</li>";
77 drupal_set_message(t('Not all roles with <a href="!access">access fckeditor</a> 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 <em>Basic setup</em> section, check "Roles allowed to use this profile".', array('!access' => url('admin/user/permissions'), '!list' => $list)), 'warning');
82 return fckeditor_profile_overview();
86 * Controller for fckeditor profiles.
88 function fckeditor_profile_overview() {
91 $profiles = fckeditor_profile_load();
93 $access_fckeditor_roles = user_roles(FALSE
, 'access fckeditor');
94 $header = array(t('Profile'), t('Roles'), t('Operations'));
95 foreach ($profiles as
$p) {
97 if ($p->name
!== "FCKeditor Global Profile") {
98 foreach (array_keys($p->rids
) as
$rid) {
99 if (!isset($access_fckeditor_roles[$rid])) {
104 array('data' => $p->name
, 'valign' => 'top'),
105 array('data' => implode("<br />\n", $rids)),
107 l(t('edit'), 'admin/settings/fckeditor/edit/'.
urlencode($p->name
)) .
' '.
108 l(t('clone'), 'admin/settings/fckeditor/clone/'.
urlencode($p->name
)) .
' '.
109 l(t('delete'), 'admin/settings/fckeditor/delete/'.
urlencode($p->name
)), 'valign' => 'top'
114 $output .
= '<h3>'.
t('Profiles') .
'</h3>';
115 $output .
= theme('table', $header, $rows);
116 $output .
= '<p>'.
l(t('Create new profile'), 'admin/settings/fckeditor/add') .
'</p>';
119 drupal_set_message(t('No profiles found. Click here to <a href="!create">create a new profile</a>.', array('!create' => url('admin/settings/fckeditor/add'))));
123 if (!isset($profiles['FCKeditor Global Profile'])) {
124 drupal_set_message(t('Global profile not found. Click here to <a href="!create">create the global profile</a>.', array('!create' => url('admin/settings/fckeditor/addg'))));
127 $output .
= "<h3>".
t("Global settings") .
"</h3>";
129 array('data' => t('FCKeditor Global Profile'), 'valign' => 'top'),
130 array('data' => l(t('edit'), 'admin/settings/fckeditor/editg') .
" ".
l(t('delete'), 'admin/settings/fckeditor/delete/FCKeditor Global Profile'), 'valign' => 'top')
132 $output .
= theme('table', array(t('Profile'), t('Operations')), $rows);
140 function fckeditor_admin_profile_clone_form($form_state, $oldprofile) {
141 return fckeditor_admin_profile_form($form_state, $oldprofile);
144 function fckeditor_admin_profile_clone_form_validate($form_state, $oldprofile) {
145 fckeditor_admin_profile_form_validate($form_state, $oldprofile);
148 function fckeditor_admin_profile_clone_form_submit($form, &$form_state) {
149 $edit =& $form_state['values'];
150 drupal_set_message(t('Your FCKeditor profile has been created.'));
151 $settings = fckeditor_admin_values_to_settings($edit);
152 db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", $edit['name'], $settings);
153 fckeditor_rebuild_selectors($edit['name']);
154 if (!empty($edit['rids'])) {
155 foreach (array_keys($edit['rids']) as
$rid) {
156 if ($edit['rids'][$rid]!=0) {
157 db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)", $edit['name'], $rid);
161 $form_state['redirect'] = 'admin/settings/fckeditor';
165 * Form builder for a normal profile
167 function fckeditor_admin_profile_form($form_state, $profile = NULL
) {
168 if ($profile != NULL
) {
169 $form['_profile'] = array(
171 '#value' => $profile,
175 $profile = new
stdClass();
178 module_load_include('lib.inc', 'fckeditor');
180 $toolbar_options = fckeditor_load_toolbar_options();
181 $skin_options = fckeditor_load_skin_options();
182 $lang_options = fckeditor_load_lang_options();
184 // Only display the roles that currently don't have a fckeditor profile. One
186 $orig_roles = user_roles(FALSE
, 'access fckeditor');
187 $roles = $orig_roles;
189 if (!empty($profile->rids
) && !user_roles(FALSE
, 'access fckeditor')) {
190 drupal_set_message(t('You haven\'t assigned "access fckeditor" <a href="!permissions">permissions</a> yet. It is recommended to assign the "access fckeditor" <a href="!permissions">permissions</a> before updating FCKeditor profiles.', array('!permissions' => url('admin/user/permissions'))), 'warning');
193 if (empty($profile->name
)) {
194 $result = db_query("SELECT DISTINCT(rid) FROM {fckeditor_role}");
195 while (($data = db_fetch_object($result))) {
196 if ((empty($profile->rids
) || !in_array($data->rid
, array_keys((array) $profile->rids
))) && !form_get_errors()) {
197 unset($roles[$data->rid
]);
200 if (count($orig_roles) != count($roles)) {
201 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.'));
205 $form['basic'] = array(
206 '#type' => 'fieldset',
207 '#title' => t('Basic setup'),
208 '#collapsible' => TRUE
,
212 if (arg(3) == 'clone') {
213 //load all profiles to check their names
214 $profiles = fckeditor_profile_load();
215 $oldname = $profile->name
;
216 $maxsize=128; //default max name length
219 $pat = "/^(?<name>.*?)_(?<n>[0-9]*)$/";
220 if (preg_match_all($pat, $oldname, $res)) { // oldname like 'name_nr'
221 $name=$res['name'][0];
229 $newname=substr($name, 0, $maxsize-3) .
'_'.
$num; // +limit
230 while (isset($profiles[$newname])) { //find next free number
232 $newname=substr($name, 0, $maxsize-3) .
'_'.
$num;
236 $profile->settings
['rids']=array();
237 $profile->rids
=array();
240 $newname = $profile->name
;
243 $form['basic']['name'] = array(
244 '#type' => 'textfield',
245 '#title' => t('Profile name'),
246 '#default_value' => !empty($profile->name
) ?
$newname : '',
249 '#description' => t('Enter a name for this profile. This name is only visible within the fckeditor administration page.'),
253 $form['basic']['rids'] = array(
254 '#type' => 'checkboxes',
255 '#title' => t('Roles allowed to use this profile'),
256 '#default_value' => !empty($profile->rids
) ?
array_keys((array) $profile->rids
) : array(),
257 '#options' => $roles,
258 '#description' => t('Only roles with "access fckeditor" permission will be shown here. If no role is available, make sure that you have assigned the "access fckeditor" <a href="!permission">permission</a>.', array('!permission' => url('admin/user/permissions'))),
262 $form['basic']['allow_user_conf'] = array(
264 '#title' => t('Allow users to customize FCKeditor appearance'),
265 '#default_value' => !empty($profile->settings
['allow_user_conf']) ?
$profile->settings
['allow_user_conf'] : 'f',
270 '#description' => t('If allowed, users will be able to override the "Editor appearance" by visiting their profile page.'),
273 $form['security'] = array(
274 '#type' => 'fieldset',
275 '#title' => t('Security'),
276 '#description' => '<p>'.
t("When Drupal saves user data input through a textarea, it's saved in the database in unmodified form. That's why all untrusted textarea input should be run through an input format filter before outputting it to the screen.") .
'</p>'.
'<p>'.
t("Drupal will not, however, filter data for content editors editing a textarea. Normally, there is no security risk because the unmodified code is displayed as text and will not be rendered as HTML. But with FCKeditor installed, this is not the case, and content editors are subject to having raw, untrusted code running inside their browsers.") .
'</p>'.
'<p>'.
t("To address this issue, you should select a security filters below to prevent FCKeditor from rendering malicious code. Note that if a textarea's input format is set to \"Full HTML\" (or if the input format of the node doesn't include the filter), FCKeditor will properly ignore the setting below and will not run the code through the security filter.") .
'</p>'.
'<p>'.
t("If any textareas on your site are accessible to unwanted users, we recommend checking the \"HTML Filter\". You may have other modules installed that provide other kinds of security filters and you may use those as long as you trust them to properly filter out malicious code. Note that not all the filters below are security filters and will provide no protection.") .
'</p>',
277 '#collapsible' => TRUE
,
281 $all = filter_list_all();
283 $form['security']['filters'] = array(
284 '#type' => 'fieldset',
285 '#title' => t('Security filters'),
286 '#description' => t('Please choose carefully all filters that protect your content (probably not all filters listed below are security filters).'),
290 //don't bother administrator with filters that definitely are not security filters
291 $modules_with_filters_to_skip = array('amazon_filter', 'asy', 'bbcode', 'biblio', 'blockquote', 'bookpost', 'chessboard', 'citation_filter', 'codefilter', 'collapse_text', 'contextlinks', 'coolfilter', 'dialectic', 'dript', 'dme', 'drutex', 'embedfilter', 'ext_link_page', 'extlink', 'elf', 'flickr', 'flickrstickr', 'footnotes', 'formdefaults', 'freelinking', 'gallery', 'geogebra', 'geshifilter', 'gotwo', 'googtube', 'gotcha', 'gtspam', 'hidden_content', 'img_assist', 'image_filter', 'inlinetags', 'insert_view', 'insertframe', 'insertnode', 'interwiki', 'jlightbox', 'jsmath', 'language_sections', 'link_node', 'lootz', 'markdown', 'marksmarty', 'mobile_codes', 'mykml', 'nofollowlist', 'oagwt', 'paging', 'pathfilter', 'pearwiki_filter', 'php', 'pirate', 'reptag', 'scrippet', 'scripturefilter', 'signwriter', 'slideshowpro', 'smartlinebreakconverter', 'smartypants', 'smileys', 'spamspan', 'spam_tokens', 'spoiler', 'table_altrow', 'tablemanager', 'tableofcontents', 'textile', 'tooltips', 'twikifilter', 'typogrify', 'unwrap', 'urlclass', 'urlicon', 'url_replace_filter', 'username_highlighter', 'video_filter', 'quote');
293 if (!isset($profile->settings
['ss'])) {
294 $profile->settings
['filters']['filter/0'] = 1;
297 foreach ($all as
$id => $filter) {
298 if (in_array(strtolower($filter->module
), $modules_with_filters_to_skip)) {
301 //skip line break converter and email -> link
302 if ($filter->module
== 'filter' && in_array($filter->delta
, array(1, 2))) {
305 $form['security']['filters'][$id] = array(
306 '#type' => 'checkbox',
307 '#title' => $filter->name
,
308 '#default_value' => !empty($profile->settings
['filters'][$id]),
309 '#description' => module_invoke($filter->module
, 'filter', 'description', $filter->delta
),
313 $form['security']['ss'] = array(
315 '#title' => t('Security settings'),
316 '#default_value' => isset($profile->settings
['ss']) ?
$profile->settings
['ss'] : '2',
318 '2' => t('Always run security filters for FCKeditor.'),
319 '1' => t('Run security filters only when FCKeditor is set to start automatically.'),
321 '#description' => t('There are two ways of starting FCKeditor: automatically and manually (via toggle or in a popup). If you decide to apply security filters only when FCKeditor starts automatically, you\'ll not be protected when toggling manually from plain textarea to FCKeditor or when using FCKeditor in a popup mode. So choose this option only, if you can detect various attacks (mainly XSS) by yourself just by looking at the HTML code.'),
324 $form['fckeditor_exclude_settings'] = array(
325 '#type' => 'fieldset',
326 '#title' => t('Visibility settings'),
327 '#collapsible' => TRUE
,
328 '#collapsed' => TRUE
,
329 '#description' => t('The following settings are combined with the visibility settings of the global profile.'),
332 $form['fckeditor_exclude_settings']['min_rows'] = array(
333 '#type' => 'textfield',
334 '#title' => t('Minimum rows'),
335 '#default_value' => !empty($profile->settings
['min_rows']) ?
$profile->settings
['min_rows'] : '5',
336 '#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."),
339 $form['fckeditor_exclude_settings']['excl_mode'] = array(
341 '#title' => t('Use inclusion or exclusion mode'),
342 '#default_value' => (empty($profile->settings
['excl_mode']) || in_array($profile->settings
['excl_mode'], array(0, 2))) ?
0 : 1,
347 '#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.'),
351 * get excluded fields - so we can have normal textareas too
352 * split the phrase by any number of commas or space characters,
353 * which include " ", \r, \t, \n and \f
355 $form['fckeditor_exclude_settings']['excl'] = array(
356 '#type' => 'textarea',
357 '#title' => t('Fields to exclude/include'),
360 '#prefix' => '<div style="margin-left:20px">',
361 '#suffix' => '</div>',
362 '#default_value' => !empty($profile->settings
['excl']) ?
$profile->settings
['excl'] : '',
363 '#description' => t('Enter the paths to the textarea fields on which you want to enable or disable FCKeditor.') .
' '.
t('Please see the <a href="!helppagelink">help page</a> for more information about defining field names. Short instruction is available below.', array('!helppagelink' => url('admin/help/fckeditor', array('fragment' => 'fieldinclexcl')))) .
' <ul><li>'.
t('Path structure: <strong>content_type@path.element_id</strong>') .
'</li><li>'.
t('The following wildcards are available: "*", "?".') .
'</li><li>'.
t('Content type is optional. You may even specify only path or field id.') .
'</li><li>'.
t('Examples:') .
'<ul><li><em>blog@*.edit-body</em> - '.
t('matches all fields of type "blog" called edit-body, on any page.') .
'<li><em>node/add/*.edit-user-*</em> - '.
t('matches fields starting with "edit-user-" on pages starting with "node/add/') .
'</li></ul></li></ul>',
367 $form['fckeditor_exclude_settings']['simple_incl'] = array(
368 '#type' => 'textarea',
369 '#title' => t('Force simplified toolbar on the following fields'),
372 '#default_value' => !empty($profile->settings
['simple_incl']) ?
$profile->settings
['simple_incl'] : '',
373 '#description' => t('Enter the paths to the textarea fields on which you want to force the simplified toolbar (!name).', array('!name' => FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME
)) .
' '.
t('Please see the <a href="!helppagelink">help page</a> for more information about defining field names. Take a look at the exclusion settings (above) for short instruction.', array('!helppagelink' => url('admin/help/fckeditor', array('fragment' => 'fieldinclexcl')))),
377 $form['appearance'] = array(
378 '#type' => 'fieldset',
379 '#title' => t('Editor appearance'),
380 '#collapsible' => TRUE
,
381 '#collapsed' => TRUE
,
384 $form['appearance']['default'] = array(
386 '#title' => t('Default state'),
387 '#default_value' => !empty($profile->settings
['default']) ?
$profile->settings
['default'] : 't',
392 '#description' => t('Default editor state. If disabled, rich text editor may still be enabled using toggle or popup window.'),
395 $form['appearance']['show_toggle'] = array(
397 '#title' => t('Show disable/enable rich text editor toggle'),
398 '#default_value' => !empty($profile->settings
['show_toggle']) ?
$profile->settings
['show_toggle'] : 't',
403 '#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).'),
406 $form['appearance']['popup'] = array(
408 '#title' => t('Use FCKeditor in a popup window'),
409 '#default_value' => !empty($profile->settings
['popup']) ?
$profile->settings
['popup'] : 'f',
414 '#description' => t('If this option is enabled a link to a popup window will be used instead of a textarea replace.'),
417 $form['appearance']['skin'] = array(
419 '#title' => t('Skin'),
420 '#default_value' => !empty($profile->settings
['skin']) ?
$profile->settings
['skin'] : 'default',
421 '#options' => $skin_options,
422 '#description' => t('Choose a default skin.'),
425 $form['appearance']['toolbar'] = array(
427 '#title' => t('Toolbar'),
428 '#default_value' => !empty($profile->settings
['toolbar']) ?
$profile->settings
['toolbar'] : 'default',
429 '#options' => $toolbar_options,
430 '#description' => t('Choose a default toolbar set. To define new toolbar, edit "fckeditor.config.js" located in "!module_path".', array('!module_path' => drupal_get_path('module', 'fckeditor'))),
433 $form['appearance']['expand'] = array(
435 '#title' => t('Start the toolbar expanded'),
436 '#default_value' => !empty($profile->settings
['expand']) ?
$profile->settings
['expand'] : 't',
438 't' => t('Expanded'),
439 'f' => t('Collapsed')
441 '#description' => t('The toolbar start expanded or collapsed.'),
444 $form['appearance']['width'] = array(
445 '#type' => 'textfield',
446 '#title' => t('Width'),
447 '#default_value' => !empty($profile->settings
['width']) ?
$profile->settings
['width'] : '100%',
448 '#description' => t("Width in pixels or percent. Example: 400 or 100%."),
453 $form['appearance']['lang'] = array(
455 '#title' => t('Language'),
456 '#default_value' => !empty($profile->settings
['lang']) ?
$profile->settings
['lang'] : 'en',
457 '#options' => $lang_options,
458 '#description' => t('The language for the FCKeditor interface.')
461 $form['appearance']['auto_lang'] = array(
463 '#title' => t('Auto-detect language'),
464 '#default_value' => !empty($profile->settings
['auto_lang']) ?
$profile->settings
['auto_lang'] : 't',
469 '#description' => t('Use auto detect user language feature.')
473 $form['appearance']['appearance_conf'] = array(
475 '#title' => t('Ignore this section, use default settings defined in config files'),
476 '#default_value' => $profile->settings['appearance_conf'] ? $profile->settings['appearance_conf'] : 'f',
481 '#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.'),
485 $form['output'] = array(
486 '#type' => 'fieldset',
487 '#title' => t('Cleanup and output'),
488 '#collapsible' => TRUE
,
489 '#collapsed' => TRUE
,
492 $form['output']['enter_mode'] = array(
494 '#title' => t('Enter mode'),
495 '#default_value' => !empty($profile->settings
['enter_mode']) ?
$profile->settings
['enter_mode'] : 'p',
501 '#description' => t('Set which tag FCKeditor should use when [Enter] key is pressed.')
504 $form['output']['shift_enter_mode'] = array(
506 '#title' => t('Shift + Enter mode'),
507 '#default_value' => !empty($profile->settings
['shift_enter_mode']) ?
$profile->settings
['shift_enter_mode'] : 'br',
513 '#description' => t('Set which tag FCKeditor should use when [Shift] + [Enter] is pressed.')
516 $form['output']['font_format'] = array(
517 '#type' => 'textfield',
518 '#title' => t('Font formats'),
519 '#default_value' => !empty($profile->settings
['font_format']) ?
$profile->settings
['font_format'] : 'p;div;pre;address;h1;h2;h3;h4;h5;h6',
522 '#description' => t('Semicolon separated list of HTML font formats. Allowed values are: p;div;pre;address;h1;h2;h3;h4;h5;h6'),
525 $form['output']['format_source'] = array(
527 '#title' => t('Apply source formatting'),
528 '#default_value' => !empty($profile->settings
['format_source']) ?
$profile->settings
['format_source'] : 't',
533 '#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.'),
536 $form['output']['format_output'] = array(
538 '#title' => t('Format output'),
539 '#default_value' => !empty($profile->settings
['format_output']) ?
$profile->settings
['format_output'] : 't',
544 '#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.'),
548 $form['output']['output_conf'] = array(
550 '#title' => t('Ignore this section, use default settings defined in config files'),
551 '#default_value' => $profile->settings['output_conf'] ? $profile->settings['output_conf'] : 'f',
556 '#description' => t('Although it is less handy, defining settings only in config files ("fckconfig.js" and "fckeditor.config.js") will slightly leverage your traffic and improve load time of your site. <br/>Warning: if set to true, all changes made in "Cleanup and output" will have no affect on FCKeditor\'s behaviour.'),
560 $form['css'] = array(
561 '#type' => 'fieldset',
562 '#title' => t('CSS'),
563 '#collapsible' => TRUE
,
567 $form['css']['css_mode'] = array(
569 '#title' => t('Editor CSS'),
570 '#default_value' => !empty($profile->settings
['css_mode']) ?
$profile->settings
['css_mode'] : 'theme',
572 'theme' => t('Use theme css'),
573 'self' => t('Define css'),
574 'none' => t('FCKeditor default')
576 '#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.')
579 $form['css']['css_path'] = array(
580 '#type' => 'textfield',
581 '#title' => t('CSS path'),
582 '#default_value' => !empty($profile->settings
['css_path']) ?
$profile->settings
['css_path'] : "",
585 '#description' => t('Enter path to CSS file (Example: "css/editor.css") or a list of css files seperated by a comma (Example: "/themes/garland/style.css,http://example.com/style.css"). Make sure to select "Define css" above.<br />Available placeholders:<br /><strong>%h</strong> - host name (!host).<br /><strong>%t</strong> - path to theme (!theme).', array('!host' => base_path(), '!theme' => base_path() .
path_to_theme() .
'/'))
588 $form['css']['css_style'] = array(
590 '#title' => t('Predefined styles'),
591 '#default_value' => !empty($profile->settings
['css_style']) ?
$profile->settings
['css_style'] : 'theme',
593 'theme' => t('Use theme fckstyles.xml'),
594 'self' => t('Define path to fckstyles.xml'),
595 'default' => t('FCKeditor default')
597 '#description' => t('Define the location of "fckstyles.xml" file. It is used by the "Style" dropdown list available in the default toolbar. Copy "!fckstyles.xml" inside your theme directory ("!theme") and adjust it to your needs.', array('!fckstyles.xml' => fckeditor_path(TRUE
) .
'/fckstyles.xml', '!theme' => path_to_theme() .
'/fckstyles.xml'))
600 $form['css']['styles_path'] = array(
601 '#type' => 'textfield',
602 '#title' => t('Predefined styles path'),
603 '#default_value' => !empty($profile->settings
['styles_path']) ?
$profile->settings
['styles_path'] : "",
606 '#description' => t('Enter path to XML file with predefined styles (Example: "/fckstyles.xml"). Be sure to select "define path to fckstyles.xml" above.<br />Available placeholders:<br /><strong>%h</strong> - host name (!host).<br /><strong>%t</strong> - path to theme (!theme).<br /><strong>%m</strong> - path to FCKeditor module (!module).', array('!host' => base_path(), '!theme' => base_path() .
path_to_theme() .
'/', '!module' => drupal_get_path('module', 'fckeditor')))
609 $form['fckeditor_upload_settings'] = array(
610 '#type' => 'fieldset',
611 '#title' => t('File browser settings'),
612 '#collapsible' => TRUE
,
613 '#collapsed' => TRUE
,
614 '#description' => t('Set file browser settings. A file browser will allow you to explore the files contained on the server and embed them as links, images or flash movies. Besides the built-in FCKeditor file browser, you can also use a contributed module like <a href="!imce">IMCE</a>, <a href="!ib">Image Browser</a> or <a href="!webfm">Web File Manager</a>. The quick upload setting controls whether images, flash movies and files can be uploaded using the upload tab of the respective dialogs. Please note that these options require manual configuration, check <a href="!readme">readme.txt</a> for more information.', array('!imce' => url('http://drupal.org/project/imce'), '!ib' => url('http://drupal.org/project/imagebrowser'), '!webfm' => url('http://drupal.org/project/webfm'), '!readme' => url('admin/help/fckeditor')))
617 $filebrowsers = array(
619 'builtin' => t('Built-in filebrowser'),
622 if (module_exists('imce')) {
623 $filebrowsers['imce'] = t('IMCE');
626 if (module_exists('imagebrowser')) {
627 $filebrowsers['ib'] = t('Image Browser');
630 if (module_exists('webfm_popup')) {
631 $filebrowsers['webfm'] = t('Web File Manager');
634 $form['fckeditor_upload_settings']['filebrowser'] = array(
636 '#title' => t('File browser type'),
637 '#default_value' => !empty($profile->settings
['filebrowser']) ?
$profile->settings
['filebrowser'] : 'none',
638 '#options' => $filebrowsers,
639 '#description' => t('Select the file browser that you would like to use to upload files, images and flash movies.'),
642 $form['fckeditor_upload_settings']['quickupload'] = array(
644 '#title' => t('Allow quick uploads'),
645 '#default_value' => !empty($profile->settings
['quickupload']) ?
$profile->settings
['quickupload'] : 'f',
650 '#description' => t('The quick upload functionality can be disabled and enabled independently of the file browser. It will always use the settings below. To enable quick uploads you must follow the same configuration procedure as when enabling the built-in file browser.'),
653 $current_user_files_path = empty($profile->settings
['UserFilesPath']) ?
"" : strtr($profile->settings
['UserFilesPath'], array("%f" => file_directory_path(), "%u" => "UID", "%b" => base_path(), "%n" => "UNAME"));
654 $current_user_files_absolute_path = empty($profile->settings
['UserFilesAbsolutePath']) ?
"" : strtr($profile->settings
['UserFilesAbsolutePath'], array("%f" => file_directory_path(), "%u" => "UID", "%b" => base_path(), "%d" => $_SERVER['DOCUMENT_ROOT'], "%n" => "UNAME"));
656 $form['fckeditor_upload_settings']['UserFilesPath'] = array(
657 '#type' => 'textfield',
658 '#title' => t('Path to uploaded files'),
659 '#default_value' => !empty($profile->settings
['UserFilesPath']) ?
$profile->settings
['UserFilesPath'] : "%b%f/",
662 '#description' => t('Path to uploaded files relative to the document root.<br />Available placeholders:<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 /><strong>%n</strong> - Username.<br />Current path: !path', array('!path' => $current_user_files_path, '!files' => file_directory_path(), '!base' => base_path())),
665 $form['fckeditor_upload_settings']['UserFilesAbsolutePath'] = array(
666 '#type' => 'textfield',
667 '#title' => t('Absolute path to uploaded files'),
668 '#default_value' => !empty($profile->settings
['UserFilesAbsolutePath']) ?
$profile->settings
['UserFilesAbsolutePath'] : "%d%b%f/",
671 '#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 placeholders:<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 /><strong>%n</strong> - Username.<br />Current path: !path', array('!path' => $current_user_files_absolute_path, '!files' => file_directory_path(), '!base' => base_path(), '!root' => $_SERVER['DOCUMENT_ROOT'])),
674 if (variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE
) {
675 $form['fckeditor_upload_settings']['UserFilesPath']['#description'] = t('Setting relative path to uploaded files has been disabled because private downloads are enabled and this path is calculated automatically. To change the location of uploaded files in the private file system, edit the <a href="!url">FCKeditor Global Profile</a>.', array('!url' => url('admin/settings/fckeditor/editg')));
676 $form['fckeditor_upload_settings']['UserFilesPath']['#disabled'] = TRUE
;
677 $form['fckeditor_upload_settings']['UserFilesAbsolutePath']['#description'] = t('Setting path to uploaded files has been disabled because private downloads are enabled and this path is calculated automatically.To change the location of uploaded files in the private file system, edit the <a href="!url">FCKeditor Global Profile</a>.', array('!global' => url('admin/settings/fckeditor/editg')));
678 $form['fckeditor_upload_settings']['UserFilesAbsolutePath']['#disabled'] = TRUE
;
681 $form['advanced'] = array(
682 '#type' => 'fieldset',
683 '#title' => t('Advanced options'),
684 '#collapsible' => TRUE
,
685 '#collapsed' => TRUE
,
687 $form['advanced']['theme_config_js'] = array(
689 '#title' => t('Load fckeditor.config.js from theme path'),
690 '#default_value' => !empty($profile->settings
['theme_config_js']) ?
$profile->settings
['theme_config_js'] : 'f',
695 '#description' => t('When set to "true" the editor will try to load the fckeditor.config.js file from theme directory.'),
697 $form['advanced']['js_conf'] = array(
698 '#type' => 'textarea',
699 '#title' => t('Custom javascript configuration'),
700 '#default_value' => !empty($profile->settings
['js_conf']) ?
$profile->settings
['js_conf'] : "",
703 '#description' => t('To change FCKeditor configuration globally, you should modify the config file: "!fckeditor_config". Sometimes it is required to change the FCKeditor configuration for a single profile only. Use this box to define settings that are unique for this profile. Available options are listed in the <a href="!docs">FCKeditor documentation</a>. Add the following code snippet to disable some advanced tabs in dialog windows of FCKeditor: <pre>@code</pre><strong>Warning</strong>: If you make something wrong here, FCKeditor may fail to load.', array('!fckeditor_config' => drupal_get_path('module', 'fckeditor') .
"/fckeditor.config.js", '!docs' => 'http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Configuration/Configuration_Options', '@code' => "LinkDlgHideTarget = true;\nLinkDlgHideAdvanced = true;\nImageDlgHideLink = true;\nImageDlgHideAdvanced = true;\nFlashDlgHideAdvanced = true;")),
707 $form['submit'] = array(
709 '#value' => t('Save')
716 * Profile validation.
718 function fckeditor_admin_profile_form_validate($form, &$form_state) {
719 $edit =& $form_state['values'];
721 //include mode and all other fields are empty, invalid
722 if ($edit['excl_mode'] == 1 && empty($edit['excl'])) {
723 form_set_error('excl_mode', t('Include mode selected, but no paths given. Enter at least one path where FCKeditor should appear.'));
726 fckeditor_admin_profile_validate_fieldpaths('excl', $edit['excl']);
729 fckeditor_admin_profile_validate_fieldpaths('simple_incl', $edit['simple_incl']);
731 if (!preg_match('/^\d+$/', trim($edit['min_rows']))) {
732 form_set_error('min_rows', t('Minimum rows must be a valid number.'));
735 if ($edit['default'] == 't' && $edit['popup'] == 't') {
736 form_set_error('popup', t('If FCKeditor is enabled by default, popup window must be disabled.'));
739 if ($edit['show_toggle'] == 't' && $edit['popup'] == 't') {
740 form_set_error('popup', t('If toggle is enabled, popup window must be disabled.'));
743 if (!$edit['name']) {
744 form_set_error('name', t('You must give a profile name.'));
746 elseif ($edit['name'] == 'FCKeditor Global Profile') {
747 form_set_error('name', t('This profile name is reserved. Please choose a different name.'));
749 elseif (!isset($edit['_profile']) || ($edit['_profile']->name
!= $edit['name'])) {
750 $result = fckeditor_profile_load($edit['name']);
751 if (!empty($result)) {
752 form_set_error('name', t('The profile name must be unique. A profile with this name already exists.'));
756 if (!preg_match('/^\d+%?$/', $edit['width'])) {
757 form_set_error('width', t('Enter valid width. Example: 400 or 100%.'));
760 if (!empty($edit['css_path'])) {
761 if ($edit['css_mode'] != 'self') {
762 form_set_error('css_path', t('CSS path is not empty. Please set the "Editor CSS" option to "define css" mode.'));
764 else if (FALSE
!== strpos($edit['css_path'], '"')) {
765 form_set_error('css_path', t('Double quotes are not allowed in CSS path.'));
768 else if (substr($edit['css_path'], 0, 1) == "'" && substr($edit['css_path'], -1) == "'") {
769 form_set_error('css_path', t('Enter valid path, do not surround it with quotes.'));
773 if (!empty($edit['styles_path'])) {
774 if ($edit['css_style'] != 'self') {
775 form_set_error('styles_path', t('Path to predefined styles is not empty. Please set the "Predefined styles" option to "define path to fckstyles.xml" mode.'));
777 else if (FALSE
!== strpos($edit['styles_path'], '"')) {
778 form_set_error('styles_path', t('Double quotes are not allowed in path.'));
780 else if (substr($edit['styles_path'], 0, 1) == "'" && substr($edit['styles_path'], -1) == "'") {
781 form_set_error('styles_path', t('Enter valid path, do not surround it with quotes.'));
785 if (!empty($edit['font_format'])) {
786 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'])) {
787 form_set_error('font_format', t('Enter valid, semicolon separated, list of HTML font formats (no semicolon at the end of list expected).'));
791 if (variable_get('file_downloads', '') !== FILE_DOWNLOADS_PRIVATE
) {
792 if (!empty($edit['UserFilesAbsolutePath']) && empty($edit['UserFilesPath'])) {
793 form_set_error('UserFilesPath', t('Path to uploaded files is required.'));
795 if (!empty($edit['UserFilesPath']) && empty($edit['UserFilesAbsolutePath'])) {
796 form_set_error('UserFilesPath', t('Absolute path to uploaded files is required.'));
801 function fckeditor_admin_profile_form_submit($form, &$form_state) {
802 $edit =& $form_state['values'];
804 if (isset($edit['_profile'])) {
805 db_query("DELETE FROM {fckeditor_settings} WHERE name = '%s'", $edit['_profile']->name
);
806 db_query("DELETE FROM {fckeditor_role} WHERE name = '%s'", $edit['_profile']->name
);
807 drupal_set_message(t('Your FCKeditor profile has been updated.'));
810 drupal_set_message(t('Your FCKeditor profile has been created.'));
813 $settings = fckeditor_admin_values_to_settings($edit);
814 db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", $edit['name'], $settings);
815 fckeditor_rebuild_selectors($edit['name']);
816 if (!empty($edit['rids'])) {
817 foreach (array_keys($edit['rids']) as
$rid) {
818 if ($edit['rids'][$rid]!=0) {
819 db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)", $edit['name'], $rid);
824 $form_state['redirect'] = 'admin/settings/fckeditor';
827 function fckeditor_admin_global_profile_form($form_state, $mode = 'add') {
828 module_load_include('lib.inc', 'fckeditor');
829 if ($mode == 'edit') {
830 $profile = fckeditor_profile_load('FCKeditor Global Profile');
832 $form['_profile'] = array(
834 '#value' => $profile,
838 $profile = new
stdClass();
841 if ($mode == 'add') {
842 $data = fckeditor_profile_load('FCKeditor Global Profile');
844 drupal_set_message(t('Global profile already exist. Only one global profile is allowed.'), 'error');
848 $btn = t('Create global profile');
851 $btn = t('Update global profile');
854 $form['common'] = array(
855 '#type' => 'fieldset',
856 '#title' => t('Main setup'),
857 '#collapsible' => TRUE
,
861 $roles = fckeditor_sorted_roles();
862 $rids = $rtext = array();
863 foreach ($roles as
$rid => $name) {
865 $rtext[] = '<strong>'.
$rid .
' - </strong>'.
$name;
867 $form['common']['rank'] = array(
868 '#type' => 'textfield',
869 '#title' => t('Role precedence'),
870 '#default_value' => implode('>', $rids),
871 '#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.'),
874 $form['common']['rank']['#description'] .
= '<br />'.
t('Here is the id-name pairs of roles having access to FCKeditor:') .
'<div>'.
implode('<br />', $rtext) .
'</div>';
877 $form['common']['rank']['#description'] .
= '<br />'.
t('You haven\'t assigned the "access fckeditor" <a href="!permissions">permissions</a> yet.', array('!permissions' => url('admin/user/permissions')));
880 $form['fckeditor_exclude_settings'] = array(
881 '#type' => 'fieldset',
882 '#title' => t('Visibility settings'),
883 '#collapsible' => TRUE
,
884 '#collapsed' => TRUE
,
885 '#description' => t('The following settings are combined with the visibility settings of the specific profile.'),
888 $form['fckeditor_exclude_settings']['excl_mode'] = array(
890 '#title' => t('Use inclusion or exclusion mode'),
891 '#default_value' => (empty($profile->settings
['excl_mode']) || in_array($profile->settings
['excl_mode'], array(0, 2))) ?
0 : 1,
896 '#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.'),
899 * get excluded fields - so we can have normal textareas too
900 * split the phrase by any number of commas or space characters,
901 * which include " ", \r, \t, \n and \f
903 $form['fckeditor_exclude_settings']['excl'] = array(
904 '#type' => 'textarea',
905 '#title' => t('Fields to exclude/include'),
908 '#prefix' => '<div style="margin-left:20px">',
909 '#suffix' => '</div>',
910 '#default_value' => !empty($profile->settings
['excl']) ?
$profile->settings
['excl'] : '',
911 '#description' => t('Enter the paths to the textarea fields on which you want to enable or disable FCKeditor.') .
' '.
t('Please see the <a href="!helppagelink">help page</a> for more information about defining field names. Short instruction is available below.', array('!helppagelink' => url('admin/help/fckeditor', array('fragment' => 'fieldinclexcl')))) .
' <ul><li>'.
t('Path structure: <strong>content_type@path.element_id</strong>') .
'</li><li>'.
t('The following wildcards are available: "*", "?".') .
'</li><li>'.
t('Content type is optional. You may even specify only path or field id.') .
'</li><li>'.
t('Examples:') .
'<ul><li><em>blog@*.edit-body</em> - '.
t('matches all fields of type "blog" called edit-body, on any page.') .
'<li><em>node/add/*.edit-user-*</em> - '.
t('matches fields starting with "edit-user-" on pages starting with "node/add/') .
'</li></ul></li></ul>',
915 $form['fckeditor_exclude_settings']['simple_incl'] = array(
916 '#type' => 'textarea',
917 '#title' => t('Force simplified toolbar on the following fields'),
920 '#default_value' => !empty($profile->settings
['simple_incl']) ?
$profile->settings
['simple_incl'] : '',
921 '#description' => t('Enter the paths to the textarea fields on which you want to force the simplified toolbar (!name).', array('!name' => FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME
)) .
' '.
t('Please see the <a href="!helppagelink">help page</a> for more information about defining field names. Take a look at the exclusion settings (above) for short instruction.', array('!helppagelink' => url('admin/help/fckeditor', array('fragment' => 'fieldinclexcl')))),
925 $form['fckeditor_advanced_settings'] = array(
926 '#type' => 'fieldset',
927 '#title' => t('Advanced settings'),
928 '#collapsible' => TRUE
,
929 '#collapsed' => TRUE
,
932 $module_drupal_path = drupal_get_path('module', 'fckeditor');
934 $form['fckeditor_advanced_settings']['fckeditor_path'] = array(
935 '#type' => 'textfield',
936 '#title' => t('Path to FCKeditor'),
937 '#default_value' => !empty($profile->settings
['fckeditor_path']) ?
$profile->settings
['fckeditor_path'] : '%m/fckeditor',
940 '#description' => t('Path to FCKeditor (the HTML editor, downloaded from <a href="!fckeditornet">www.fckeditor.net</a>) relative to the document root.<br />Available placeholders:<br /><strong>%b</strong> - base URL path of the Drupal installation (!base).<br /><strong>%m</strong> - base URL path where FCKeditor module is stored (!files).<br />Current path: !path', array('!path' => fckeditor_path(FALSE
), '!base' => base_path(), '!files' => base_path() .
$module_drupal_path , '!fckeditornet' => 'http://www.fckeditor.net/download')),
944 $form['fckeditor_advanced_settings']['fckeditor_local_path'] = array(
945 '#type' => 'textfield',
946 '#title' => t('Local path to FCKeditor'),
947 '#default_value' => isset($profile->settings
['fckeditor_local_path'])?
$profile->settings
['fckeditor_local_path']:'',
950 '#description' => t('The path to the local directory (on the server) which points to the path defined above. Enter either an absolute server path or path relative to "index.php". If empty, FCKeditor module will try to find the right path.<br />Current path: !path', array('!path' => fckeditor_path(TRUE
))),
953 $form['fckeditor_advanced_settings']['show_fieldnamehint'] = array(
955 '#title' => t('Show field name hint below each rich text editor'),
956 '#default_value' => !empty($profile->settings
['show_fieldnamehint']) ?
$profile->settings
['show_fieldnamehint'] : 't',
961 '#description' => t('This only applies for users with "administer fckeditor" permissions.'),
964 if (variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE
) {
965 $current_private_dir = !isset($edit->settings
['private_dir']) ?
"" : $edit->settings
['private_dir'];
966 $form['fckeditor_advanced_settings']['private_dir'] = array(
967 '#type' => 'textfield',
968 '#title' => t('Location of files uploaded with FCKeditor in the private folder'),
969 '#default_value' => $current_private_dir,
972 '#description' => t('The path relative to the location of the private directory where FCKeditor should store uploaded files.') .
'<br />'.
t('<strong>Warning:</strong> FCKeditor does not implement any kind of access protection on files available in this location. All files stored in the directory defined above might be accessible by unathenticated users if there is no information about the file in the Drupal\'s database.') .
'<br />'.
t('System path to the private folder is: !system_path.', array('!system_path' => realpath(file_directory_path()) . DIRECTORY_SEPARATOR
)) .
'<br />'.
t('Available wildcard characters:<br/><strong>%u</strong> - User ID.') .
'<br />'.
t('Current path: !path', array('!path' => $current_private_dir .
' ('.
file_create_path($current_private_dir) .
')')),
976 $form['submit'] = array(
984 function fckeditor_admin_global_profile_form_validate($form, &$form_state) {
985 $edit =& $form_state['values'];
987 //include mode and all other fields are empty, invalid
988 if ($edit['excl_mode'] == 1 && empty($edit['excl'])) {
989 form_set_error('excl_mode', t('Include mode selected, but no paths given. Enter at least one path where FCKeditor should appear.'));
992 fckeditor_admin_profile_validate_fieldpaths('excl', $edit['excl']);
995 fckeditor_admin_profile_validate_fieldpaths('simple_incl', $edit['simple_incl']);
998 function fckeditor_admin_global_profile_form_submit($form, &$form_state) {
999 module_load_include('lib.inc', 'fckeditor');
1000 $edit =& $form_state['values'];
1001 $edit['name'] = 'FCKeditor Global Profile';
1003 if (isset($edit['rank'])) {
1004 $edit['rank'] = explode('>', str_replace(' ', '', $edit['rank']));
1007 if (isset($edit['_profile'])) {
1008 db_query("DELETE FROM {fckeditor_settings} WHERE name = '%s'", $edit['_profile']->name
);
1009 db_query("DELETE FROM {fckeditor_role} WHERE name = '%s'", $edit['_profile']->name
);
1013 if (empty($edit['fckeditor_local_path'])) {
1014 $edit['fckeditor_local_path'] = '';
1017 $edit['fckeditor_local_path'] = trim($edit['fckeditor_local_path']);
1020 //strip slash from the end
1021 if (empty($edit['fckeditor_path'])) {
1022 $edit['fckeditor_path'] = '';
1024 $edit['fckeditor_path'] = trim(rtrim($edit['fckeditor_path'], "/"));
1025 if ($edit['fckeditor_path'] && 0 !== strpos($edit['fckeditor_path'], "/") && 0 !== strpos($edit['fckeditor_path'], "%")) {
1026 //ensure that slash is at the beginning
1027 $edit['fckeditor_path'] = "/".
$edit['fckeditor_path'];
1029 //no slash at the end
1030 $edit['fckeditor_local_path'] = trim(rtrim($edit['fckeditor_local_path'], "/"));
1032 $settings = fckeditor_admin_values_to_settings($edit);
1033 db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", $edit['name'], $settings);
1034 fckeditor_rebuild_selectors($edit['name']);
1036 drupal_set_message(t('FCKeditor global profile has been saved.'));
1037 $form_state['redirect'] = 'admin/settings/fckeditor';
1041 * Converts an array of form values to a serialized array that does not
1042 * contain Drupal Form API values
1044 function fckeditor_admin_values_to_settings($values) {
1045 unset($values['name'], $values['rids'], $values['_profile'], $values['op'], $values['submit'], $values['form_build_id'], $values['form_token'], $values['form_id']);
1046 return serialize($values);
1049 function fckeditor_admin_profile_validate_fieldpaths($fieldname, $paths) {
1050 $myerrors = array();
1052 $rules = preg_split('/[\s,]+/', $paths);
1054 foreach ($rules as
$rule) {
1055 $rule = trim($rule);
1056 if (!empty($rule) && strpos($rule, '.') === FALSE
&& strpos($rule, '/') === FALSE
&& strpos($rule, '-') === FALSE
) {
1057 $myerrors[] = t('Rule %rule is ambiguous: please append .* if %rule is a path or prepend *. if %rule is a field', array('%rule' => $rule));
1061 if (!empty($myerrors)) {
1062 form_set_error($fieldname, implode('<br/>', $myerrors));
1066 function fckeditor_admin_profile_delete_form($form_state, $profile) {
1069 $form['_profile'] = array(
1071 '#value' => $profile,
1074 $form['question'] = array(
1076 '#value' => t('Are you sure that you want to delete the FCKeditor profile %profile?', array('%profile' => $profile->name
)),
1079 $form['delete'] = array(
1080 '#type' => 'submit',
1082 '#value' => t('Delete'),
1085 $form['back'] = array(
1086 '#type' => 'submit',
1088 '#value' => t('Cancel'),
1094 function fckeditor_admin_profile_delete_form_submit($form, &$form_state) {
1095 $v =& $form_state['values'];
1097 if ($form_state['clicked_button']['#id'] == 'delete') {
1098 fckeditor_profile_delete($v['_profile']->name
);
1099 drupal_set_message(t('Deleted FCKeditor profile.'));
1102 $form_state['redirect'] = 'admin/settings/fckeditor';
1106 * Rebuilds the regular expression that is used to match the inclusion/exclusion rules
1107 * and the simplified toolbar rules
1109 * @param string $name Name of the profile to process. If omitted, all profiles are rebuilt
1111 function fckeditor_rebuild_selectors($name = NULL
) {
1112 if ($name == NULL
) {
1113 $result = db_query("SELECT * FROM {fckeditor_settings}");
1116 $result = db_query("SELECT * FROM {fckeditor_settings} WHERE name = '%s'", $name);
1119 while (($data = db_fetch_object($result))) {
1120 if ($data->settings
) {
1121 $settings = unserialize($data->settings
);
1123 foreach (array('excl', 'simple_incl') as
$var) {
1124 $settings[$var .
'_regex'] = '';
1125 $rules = preg_split('/[\s,]+/', $settings[$var]);
1128 if (!empty($rules)) {
1129 foreach ($rules as
$rule) {
1130 if (!empty($rule)) {
1131 $rule = fckeditor_parse_rule($rule);
1132 $regex[] = '(?:'.
fckeditor_rule_to_regex($rule) .
')';
1136 if (!empty($regex)) {
1137 $settings[$var .
'_regex'] = '#'.
implode('|', $regex) .
'#';
1142 db_query("UPDATE {fckeditor_settings} SET settings='%s' WHERE name='%s'", serialize($settings), $data->name
);
1147 function fckeditor_rule_create($nodetype = '*', $path = '*', $fieldname = '*') {
1148 $rule = new
stdClass();
1149 $rule->nodetype
= $nodetype;
1150 $rule->path
= $path;
1151 $rule->field
= $fieldname;
1156 function fckeditor_parse_rule($rule) {
1157 $ruleobj = new
stdClass();
1159 $atpos = strpos($rule, '@');
1160 if ($atpos !== FALSE
) {
1161 $ruleobj->nodetype
= substr($rule, 0, $atpos);
1162 $rule = substr($rule, $atpos + 1);
1165 $ruleobj->nodetype
= '*';
1168 $dotpos = strpos($rule, '.');
1169 if ($dotpos === FALSE
) {
1170 if (strpos($rule, '/') === FALSE
&& strpos($rule, '-') !== FALSE
) {
1171 // assume it's a field
1172 $ruleobj->path
= '*';
1173 $ruleobj->field
= $rule;
1175 elseif (strpos($rule, '/') !== FALSE
) {
1176 // assume it's a path
1177 $ruleobj->path
= $rule;
1178 $ruleobj->field
= '*';
1185 $ruleobj->path
= substr($rule, 0, $dotpos);
1186 $ruleobj->field
= str_replace('\.', '.', substr($rule, $dotpos + 1));
1192 function fckeditor_rule_to_regex($rule) {
1193 static
$replace = array('\*' => '.*', '\?' => '.');
1195 $field = str_replace('.', '\.', $rule->field
);
1196 $regex = '^'.
preg_quote($rule->nodetype
, '#') .
'@'.
preg_quote($rule->path
, '#') .
'\.'.
preg_quote($field, '#') .
'$';
1197 $regex = strtr($regex, $replace);
1202 function fckeditor_rule_to_string($rule) {
1203 $field = str_replace('.', '\.', $rule->field
);
1205 if ($rule->nodetype
!= '*') {
1206 $rulestr .
= $rule->nodetype .
'@';
1208 return $rulestr .
$rule->path .
'.'.
$field;
1212 * Remove a profile from the database.
1214 function fckeditor_profile_delete($name) {
1215 db_query("DELETE FROM {fckeditor_settings} WHERE name = '%s'", $name);
1216 db_query("DELETE FROM {fckeditor_role} WHERE name = '%s'", $name);