#824710 by TwoD: CKEditor not disabled upon enabling.
[project/wysiwyg.git] / wysiwyg.admin.inc
CommitLineData
a2f0b052 1<?php
2// $Id$
3
4/**
5 * @file
6 * Integrate Wysiwyg editors into Drupal.
7 */
8
9/**
117ad234 10 * Form builder for Wysiwyg profile form.
a2f0b052 11 */
eb714832 12function wysiwyg_profile_form($form_state, $profile) {
9eca41dc 13 // Merge in defaults.
d76237c4 14 $profile = (array) $profile;
c792e281 15 $profile += array(
81a2754f 16 'format' => 0,
17 'editor' => '',
9eca41dc 18 );
81a2754f 19 if (empty($profile['settings'])) {
20 $profile['settings'] = array();
21 }
c792e281 22 $profile['settings'] += array(
c792e281 23 'default' => TRUE,
24 'user_choose' => FALSE,
25 'show_toggle' => TRUE,
26 'theme' => 'advanced',
27 'language' => 'en',
28 'access' => 1,
29 'access_pages' => "node/*\nuser/*\ncomment/*",
30 'buttons' => array(),
31 'toolbar_loc' => 'top',
32 'toolbar_align' => 'left',
33 'path_loc' => 'bottom',
34 'resizing' => TRUE,
35 // Also available, but buggy in TinyMCE 2.x: blockquote,code,dt,dd,samp.
36 'block_formats' => 'p,address,pre,h2,h3,h4,h5,h6,div',
37 'verify_html' => TRUE,
38 'preformatted' => FALSE,
39 'convert_fonts_to_spans' => TRUE,
40 'remove_linebreaks' => TRUE,
41 'apply_source_formatting' => FALSE,
42 'paste_auto_cleanup_on_paste' => FALSE,
43 'css_setting' => 'theme',
44 'css_path' => NULL,
45 'css_classes' => NULL,
46 );
d76237c4 47 $profile = (object) $profile;
c792e281 48
81a2754f 49 $formats = filter_formats();
117ad234 50 $editor = wysiwyg_get_editor($profile->editor);
51 drupal_set_title(t('%editor profile for %format', array('%editor' => $editor['title'], '%format' => $formats[$profile->format]->name)));
a2f0b052 52
81a2754f 53 $form['format'] = array('#type' => 'value', '#value' => $profile->format);
54 $form['input_format'] = array('#type' => 'value', '#value' => $formats[$profile->format]->name);
55 $form['editor'] = array('#type' => 'value', '#value' => $profile->editor);
a2f0b052 56
57 $form['basic'] = array(
58 '#type' => 'fieldset',
59 '#title' => t('Basic setup'),
60 '#collapsible' => TRUE,
9e3e05cd 61 '#collapsed' => TRUE,
a2f0b052 62 );
63
a2f0b052 64 $form['basic']['default'] = array(
4248dc52 65 '#type' => 'checkbox',
66 '#title' => t('Enabled by default'),
c792e281 67 '#default_value' => $profile->settings['default'],
4248dc52 68 '#return_value' => 1,
69 '#description' => t('The default editor state for users having access to this profile. Users are able to override this state if the next option is enabled.'),
a2f0b052 70 );
71
72 $form['basic']['user_choose'] = array(
4248dc52 73 '#type' => 'checkbox',
a2f0b052 74 '#title' => t('Allow users to choose default'),
c792e281 75 '#default_value' => $profile->settings['user_choose'],
4248dc52 76 '#return_value' => 1,
81a2754f 77 '#description' => t('If allowed, users will be able to choose their own editor default state in their user account settings.'),
a2f0b052 78 );
79
80 $form['basic']['show_toggle'] = array(
4248dc52 81 '#type' => 'checkbox',
81a2754f 82 '#title' => t('Show <em>enable/disable rich text</em> toggle link'),
c792e281 83 '#default_value' => $profile->settings['show_toggle'],
4248dc52 84 '#return_value' => 1,
81a2754f 85 '#description' => t('Whether or not to show the <em>enable/disable rich text</em> toggle link below a textarea. If disabled, the user setting or global default is used (see above).'),
a2f0b052 86 );
87
a2f0b052 88 $form['basic']['theme'] = array(
89 '#type' => 'hidden',
c792e281 90 '#value' => $profile->settings['theme'],
a2f0b052 91 );
92
93 $form['basic']['language'] = array(
94 '#type' => 'select',
95 '#title' => t('Language'),
c792e281 96 '#default_value' => $profile->settings['language'],
6ce9b0a3 97 '#options' => drupal_map_assoc(array('ar', 'ca', 'cs', 'cy', 'da', 'de', 'el', 'en', 'es', 'fa', 'fi', 'fr', 'fr_ca', 'he', 'hu', 'is', 'it', 'ja', 'ko', 'nb', 'nl', 'nn', 'pl', 'pt', 'pt_br', 'ru', 'ru_KOI8-R', 'ru_UTF-8', 'si', 'sk', 'sv', 'th', 'tr', 'uk', 'zh_cn', 'zh_tw', 'zh_tw_utf8')),
81a2754f 98 '#description' => t('The language to use for the editor interface. Language codes are based on the <a href="http://www.loc.gov/standards/iso639-2/englangn.html">ISO-639-2</a> format.'),
a2f0b052 99 );
100
a2f0b052 101 $form['buttons'] = array(
102 '#type' => 'fieldset',
103 '#title' => t('Buttons and plugins'),
104 '#collapsible' => TRUE,
105 '#collapsed' => TRUE,
106 '#tree' => TRUE,
eb714832 107 '#theme' => 'wysiwyg_admin_button_table',
a2f0b052 108 );
109
81a2754f 110 $plugins = wysiwyg_get_plugins($profile->editor);
a2f0b052 111 // Generate the button list.
a090395c 112 foreach ($plugins as $name => $meta) {
a2f0b052 113 if (isset($meta['buttons']) && is_array($meta['buttons'])) {
a090395c 114 foreach ($meta['buttons'] as $button => $title) {
9eb0a9ec 115 $icon = '';
116 if (!empty($meta['path'])) {
117 // @todo Button icon locations are different in editors, editor versions,
118 // and contrib/custom plugins (like Image Assist, f.e.).
54a65ca8 119 $img_src = $meta['path'] . "/images/$name.gif";
9eb0a9ec 120 // Handle plugins that have more than one button.
121 if (!file_exists($img_src)) {
54a65ca8 122 $img_src = $meta['path'] . "/images/$button.gif";
9eb0a9ec 123 }
54a65ca8 124 $icon = file_exists($img_src) ? '<img src="' . base_path() . $img_src . '" title="' . $button . '" style="border: 1px solid grey; vertical-align: middle;" />' : '';
a2f0b052 125 }
6bf6d580 126 $title = (isset($meta['url']) ? l($title, $meta['url'], array('target' => '_blank')) : $title);
54a65ca8 127 $title = (!empty($icon) ? $icon . ' ' . $title : $title);
a090395c 128 $form['buttons'][$name][$button] = array(
129 '#type' => 'checkbox',
130 '#title' => $title,
c792e281 131 '#default_value' => !empty($profile->settings['buttons'][$name][$button]) ? $profile->settings['buttons'][$name][$button] : FALSE,
a090395c 132 );
a2f0b052 133 }
134 }
a090395c 135 else if (isset($meta['extensions']) && is_array($meta['extensions'])) {
136 foreach ($meta['extensions'] as $extension => $title) {
a090395c 137 $form['buttons'][$name][$extension] = array(
138 '#type' => 'checkbox',
6bf6d580 139 '#title' => isset($meta['url']) ? l($title, $meta['url'], array('target' => '_blank')) : $title,
c792e281 140 '#default_value' => !empty($profile->settings['buttons'][$name][$extension]) ? $profile->settings['buttons'][$name][$extension] : FALSE,
a090395c 141 );
a2f0b052 142 }
a2f0b052 143 }
144 }
145
146 $form['appearance'] = array(
147 '#type' => 'fieldset',
148 '#title' => t('Editor appearance'),
149 '#collapsible' => TRUE,
9e3e05cd 150 '#collapsed' => TRUE,
a2f0b052 151 );
152
153 $form['appearance']['toolbar_loc'] = array(
154 '#type' => 'select',
155 '#title' => t('Toolbar location'),
c792e281 156 '#default_value' => $profile->settings['toolbar_loc'],
c2219286 157 '#options' => array('bottom' => t('Bottom'), 'top' => t('Top')),
4248dc52 158 '#description' => t('This option controls whether the editor toolbar is displayed above or below the editing area.'),
a2f0b052 159 );
160
161 $form['appearance']['toolbar_align'] = array(
162 '#type' => 'select',
4248dc52 163 '#title' => t('Button alignment'),
c792e281 164 '#default_value' => $profile->settings['toolbar_align'],
c2219286 165 '#options' => array('center' => t('Center'), 'left' => t('Left'), 'right' => t('Right')),
4248dc52 166 '#description' => t('This option controls the alignment of icons in the editor toolbar.'),
a2f0b052 167 );
168
169 $form['appearance']['path_loc'] = array(
170 '#type' => 'select',
171 '#title' => t('Path location'),
c792e281 172 '#default_value' => $profile->settings['path_loc'],
4248dc52 173 '#options' => array('none' => t('Hide'), 'top' => t('Top'), 'bottom' => t('Bottom')),
174 '#description' => t('Where to display the path to HTML elements (i.e. <code>body > table > tr > td</code>).'),
a2f0b052 175 );
176
177 $form['appearance']['resizing'] = array(
4248dc52 178 '#type' => 'checkbox',
a2f0b052 179 '#title' => t('Enable resizing button'),
c792e281 180 '#default_value' => $profile->settings['resizing'],
4248dc52 181 '#return_value' => 1,
182 '#description' => t('This option gives you the ability to enable/disable the resizing button. If enabled, the Path location toolbar must be set to "Top" or "Bottom" in order to display the resize icon.'),
a2f0b052 183 );
184
a2f0b052 185 $form['output'] = array(
186 '#type' => 'fieldset',
187 '#title' => t('Cleanup and output'),
188 '#collapsible' => TRUE,
9e3e05cd 189 '#collapsed' => TRUE,
a2f0b052 190 );
191
192 $form['output']['verify_html'] = array(
4248dc52 193 '#type' => 'checkbox',
a2f0b052 194 '#title' => t('Verify HTML'),
c792e281 195 '#default_value' => $profile->settings['verify_html'],
4248dc52 196 '#return_value' => 1,
197 '#description' => t('If enabled, potentially malicious code like <code>&lt;HEAD&gt;</code> tags will be removed from HTML contents.'),
a2f0b052 198 );
199
200 $form['output']['preformatted'] = array(
4248dc52 201 '#type' => 'checkbox',
a2f0b052 202 '#title' => t('Preformatted'),
c792e281 203 '#default_value' => $profile->settings['preformatted'],
4248dc52 204 '#return_value' => 1,
205 '#description' => t('If enabled, the editor will insert TAB characters on tab and preserve other whitespace characters just like a PRE element in HTML does.'),
a2f0b052 206 );
207
208 $form['output']['convert_fonts_to_spans'] = array(
4248dc52 209 '#type' => 'checkbox',
a2f0b052 210 '#title' => t('Convert &lt;font&gt; tags to styles'),
c792e281 211 '#default_value' => $profile->settings['convert_fonts_to_spans'],
4248dc52 212 '#return_value' => 1,
213 '#description' => t('If enabled, HTML tags declaring the font size, font family, font color and font background color will be replaced by inline CSS styles.'),
a2f0b052 214 );
215
216 $form['output']['remove_linebreaks'] = array(
4248dc52 217 '#type' => 'checkbox',
9e3e05cd 218 '#title' => t('Remove linebreaks'),
c792e281 219 '#default_value' => $profile->settings['remove_linebreaks'],
4248dc52 220 '#return_value' => 1,
221 '#description' => t('If enabled, the editor will remove most linebreaks from contents. Disabling this option could avoid conflicts with other input filters.'),
a2f0b052 222 );
223
224 $form['output']['apply_source_formatting'] = array(
4248dc52 225 '#type' => 'checkbox',
9e3e05cd 226 '#title' => t('Apply source formatting'),
c792e281 227 '#default_value' => $profile->settings['apply_source_formatting'],
4248dc52 228 '#return_value' => 1,
229 '#description' => t('If enabled, the editor will re-format the HTML source code. Disabling this option could avoid conflicts with other input filters.'),
a2f0b052 230 );
231
11c19e9a 232 $form['output']['paste_auto_cleanup_on_paste'] = array(
4248dc52 233 '#type' => 'checkbox',
234 '#title' => t('Force cleanup on standard paste'),
c792e281 235 '#default_value' => $profile->settings['paste_auto_cleanup_on_paste'],
4248dc52 236 '#return_value' => 1,
237 '#description' => t('If enabled, the default paste function (CTRL-V or SHIFT-INS) behaves like the "paste from word" plugin function.'),
11c19e9a 238 );
239
a2f0b052 240 $form['css'] = array(
241 '#type' => 'fieldset',
242 '#title' => t('CSS'),
243 '#collapsible' => TRUE,
9e3e05cd 244 '#collapsed' => TRUE,
a2f0b052 245 );
246
60486af7 247 $form['css']['block_formats'] = array(
248 '#type' => 'textfield',
249 '#title' => t('Block formats'),
c792e281 250 '#default_value' => $profile->settings['block_formats'],
60486af7 251 '#size' => 40,
252 '#maxlength' => 250,
b913a764 253 '#description' => t('Comma separated list of HTML block formats. Possible values: <code>@format-list</code>.', array('@format-list' => 'p,h1,h2,h3,h4,h5,h6,div,blockquote,address,pre,code,dt,dd')),
60486af7 254 );
255
a2f0b052 256 $form['css']['css_setting'] = array(
257 '#type' => 'select',
258 '#title' => t('Editor CSS'),
c792e281 259 '#default_value' => $profile->settings['css_setting'],
5708da35 260 '#options' => array('theme' => t('Use theme CSS'), 'self' => t('Define CSS'), 'none' => t('Editor default CSS')),
261 '#description' => t('Defines the CSS to be used in the editor area.<br />Use theme CSS - loads stylesheets from current site theme.<br/>Define CSS - enter path for stylesheet files below.<br />Editor default CSS - uses default stylesheets from editor.'),
a2f0b052 262 );
263
264 $form['css']['css_path'] = array(
265 '#type' => 'textfield',
266 '#title' => t('CSS path'),
c792e281 267 '#default_value' => $profile->settings['css_path'],
a2f0b052 268 '#size' => 40,
269 '#maxlength' => 255,
8ccdb7f3 270 '#description' => t('If "Define CSS" was selected above, enter path to a CSS file or a list of CSS files separated by a comma.') . '<br />' . t('Available tokens: <code>%b</code> (base path, eg: <code>/</code>), <code>%t</code> (path to theme, eg: <code>themes/garland</code>)') . '<br />' . t('Example:') . ' css/editor.css,/themes/garland/style.css,%b%t/style.css,http://example.com/external.css',
a2f0b052 271 );
272
273 $form['css']['css_classes'] = array(
60486af7 274 '#type' => 'textarea',
a2f0b052 275 '#title' => t('CSS classes'),
c792e281 276 '#default_value' => $profile->settings['css_classes'],
60486af7 277 '#description' => t('Optionally define CSS classes for the "Font style" dropdown list.<br />Enter one class on each line in the format: !format. Example: !example<br />If left blank, CSS classes are automatically imported from all loaded stylesheet(s).', array('!format' => '<code>[title]=[class]</code>', '!example' => 'My heading=header1')),
a2f0b052 278 );
279
280 $form['submit'] = array(
281 '#type' => 'submit',
81a2754f 282 '#value' => t('Save'),
b78c11cc 283 '#weight' => 100,
284 );
285 $form['cancel'] = array(
286 '#value' => l(t('Cancel'), 'admin/settings/wysiwyg'),
287 '#weight' => 110,
a2f0b052 288 );
289
290 return $form;
291}
292
293/**
eb714832 294 * Submit callback for Wysiwyg profile form.
b8a2b356 295 *
eb714832 296 * @see wysiwyg_profile_form()
b8a2b356 297 */
eb714832 298function wysiwyg_profile_form_submit($form, &$form_state) {
117ad234 299 $values = $form_state['values'];
300 if (isset($values['buttons'])) {
81a2754f 301 // Store only enabled buttons for each plugin.
117ad234 302 foreach ($values['buttons'] as $plugin => $buttons) {
303 $values['buttons'][$plugin] = array_filter($values['buttons'][$plugin]);
81a2754f 304 }
305 // Store only enabled plugins.
117ad234 306 $values['buttons'] = array_filter($values['buttons']);
addb35d1 307 }
81a2754f 308 // Remove input format name.
117ad234 309 $format = $values['format'];
310 $input_format = $values['input_format'];
311 $editor = $values['editor'];
312 unset($values['format'], $values['input_format'], $values['editor']);
b8a2b356 313
075f2dce 314 // Remove FAPI values.
315 // @see system_settings_form_submit()
266ff4f0 316 unset($values['submit'], $values['form_id'], $values['op'], $values['form_token'], $values['form_build_id']);
075f2dce 317
b8a2b356 318 // Insert new profile data.
117ad234 319 db_query("UPDATE {wysiwyg} SET settings = '%s' WHERE format = %d", serialize($values), $format);
81a2754f 320
321 drupal_set_message(t('Wysiwyg profile for %format has been saved.', array('%format' => $input_format)));
b8a2b356 322
117ad234 323 $form_state['redirect'] = 'admin/settings/wysiwyg';
b8a2b356 324}
325
326/**
9eca41dc 327 * Layout for the buttons in the Wysiwyg Editor profile form.
a2f0b052 328 */
8e4cdab3 329function theme_wysiwyg_admin_button_table($form) {
a2f0b052 330 $buttons = array();
331
075f2dce 332 // Flatten forms array.
a090395c 333 foreach (element_children($form) as $name) {
334 foreach (element_children($form[$name]) as $button) {
335 $buttons[] = drupal_render($form[$name][$button]);
336 }
a2f0b052 337 }
338
075f2dce 339 // Split checkboxes into rows with 3 columns.
a2f0b052 340 $total = count($buttons);
341 $rows = array();
342 for ($i = 0; $i < $total; $i++) {
7623c9ce 343 $row = array();
344 $row[] = array('data' => $buttons[$i]);
c792e281 345 if (isset($buttons[++$i])) {
7623c9ce 346 $row[] = array('data' => $buttons[$i]);
c792e281 347 }
348 if (isset($buttons[++$i])) {
7623c9ce 349 $row[] = array('data' => $buttons[$i]);
c792e281 350 }
a2f0b052 351 $rows[] = $row;
352 }
353
354 $output = theme('table', array(), $rows, array('width' => '100%'));
355
356 return $output;
357}
358
359/**
c792e281 360 * Display overview of setup Wysiwyg Editor profiles; menu callback.
a2f0b052 361 */
eb714832 362function wysiwyg_profile_overview() {
c0c42d78 363 include_once './includes/install.inc';
c792e281 364
365 // Check which wysiwyg editors are installed.
366 $editors = wysiwyg_get_all_editors();
367 $count = count($editors);
c0c42d78 368 $status = array();
369 $options = array('' => t('No editor'));
0044993f 370
371 foreach ($editors as $name => $editor) {
372 $status[$name] = array(
373 'severity' => (isset($editor['error']) ? REQUIREMENT_ERROR : ($editor['installed'] ? REQUIREMENT_OK : REQUIREMENT_INFO)),
374 'title' => t('<a href="!vendor-url">@editor</a> (<a href="!download-url">Download</a>)', array('!vendor-url' => $editor['vendor url'], '@editor' => $editor['title'], '!download-url' => $editor['download url'])),
375 'value' => (isset($editor['installed version']) ? $editor['installed version'] : t('Not installed.')),
376 'description' => (isset($editor['error']) ? $editor['error'] : ''),
c0c42d78 377 );
0044993f 378 if ($editor['installed']) {
379 $options[$name] = $editor['title'] . (isset($editor['installed version']) ? ' ' . $editor['installed version'] : '');
c792e281 380 }
c0c42d78 381 else {
0044993f 382 // Build on-site installation instructions.
383 // @todo Setup $library in wysiwyg_load_editor() already.
384 $library = (isset($editor['library']) ? $editor['library'] : key($editor['libraries']));
385 $targs = array(
386 '@editor-path' => $editor['editor path'],
cdb08c25 387 '@library-filepath' => $editor['library path'] . '/' . (isset($editor['libraries'][$library]['files'][0]) ? $editor['libraries'][$library]['files'][0] : key($editor['libraries'][$library]['files'])),
0044993f 388 );
389 $instructions = '<p>' . t('Extract the archive and copy its contents into a new folder in the following location:<br /><code>@editor-path</code>', $targs) . '</p>';
390 $instructions .= '<p>' . t('So the actual library can be found at:<br /><code>@library-filepath</code>', $targs) . '</p>';
391
392 $status[$name]['description'] .= $instructions;
c0c42d78 393 $count--;
c792e281 394 }
0044993f 395 // In case there is an error, always show installation instructions.
396 if (isset($editor['error'])) {
397 $show_instructions = TRUE;
398 }
399 }
400 if (!$count) {
401 $show_instructions = TRUE;
c792e281 402 }
c0c42d78 403 $form['status'] = array(
404 '#type' => 'fieldset',
405 '#title' => t('Installation instructions'),
406 '#collapsible' => TRUE,
0044993f 407 '#collapsed' => !isset($show_instructions),
c0c42d78 408 '#description' => (!$count ? t('There are no editor libraries installed currently. The following list contains a list of currently supported editors:') : ''),
409 '#weight' => 10,
410 );
0a007998 411 $form['status']['report'] = array('#value' => theme('status_report', $status));
c792e281 412
c0c42d78 413 if (!$count) {
81a2754f 414 return $form;
9eca41dc 415 }
416
81a2754f 417 $formats = filter_formats();
117ad234 418 $profiles = wysiwyg_profile_load_all();
c94c9d22 419 $form['formats'] = array(
0a007998 420 '#type' => 'item',
421 '#description' => t('To assign a different editor to a text format, click "delete" to remove the existing first.'),
c94c9d22 422 '#tree' => TRUE,
423 );
9fd8955d 424
425 $enable_save = FALSE;
81a2754f 426 foreach ($formats as $id => $format) {
427 $form['formats'][$id]['name'] = array(
428 '#value' => check_plain($format->name),
429 );
c94c9d22 430 // Only display editor selection for associated input formats to avoid
431 // confusion about disabled selection.
432 if (isset($profiles[$id]) && !empty($profiles[$id]->editor)) {
433 $form['formats'][$id]['editor'] = array(
c94c9d22 434 '#value' => $options[$profiles[$id]->editor],
c94c9d22 435 );
436 }
437 else {
438 $form['formats'][$id]['editor'] = array(
439 '#type' => 'select',
440 '#default_value' => '',
441 '#options' => $options,
c94c9d22 442 );
9fd8955d 443 $enable_save = TRUE;
c94c9d22 444 }
81a2754f 445 if (isset($profiles[$id]) && !empty($profiles[$id]->editor)) {
446 $form['formats'][$id]['edit'] = array(
117ad234 447 '#value' => l(t('Edit'), "admin/settings/wysiwyg/profile/$id/edit"),
81a2754f 448 );
c94c9d22 449 $form['formats'][$id]['delete'] = array(
450 '#value' => l(t('Delete'), "admin/settings/wysiwyg/profile/$id/delete"),
c06ba055 451 );
a2f0b052 452 }
a2f0b052 453 }
454
9fd8955d 455 // Submitting the form when no editors can be selected causes errors.
456 if ($enable_save) {
457 $form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
458 }
81a2754f 459 return $form;
460}
461
462/**
463 * Return HTML for the Wysiwyg profile overview form.
464 */
8e4cdab3 465function theme_wysiwyg_profile_overview($form) {
c0c42d78 466 if (!isset($form['formats'])) {
467 return;
468 }
81a2754f 469 $output = '';
470 $header = array(t('Input format'), t('Editor'), array('data' => t('Operations'), 'colspan' => 2));
471 $rows = array();
472 foreach (element_children($form['formats']) as $item) {
473 $format = &$form['formats'][$item];
474 $rows[] = array(
475 drupal_render($format['name']),
476 drupal_render($format['editor']),
477 isset($format['edit']) ? drupal_render($format['edit']) : '',
c94c9d22 478 isset($format['delete']) ? drupal_render($format['delete']) : '',
81a2754f 479 );
480 }
0a007998 481 $form['formats']['table']['#value'] = theme('table', $header, $rows);
81a2754f 482 $output .= drupal_render($form);
a2f0b052 483 return $output;
484}
485
486/**
81a2754f 487 * Submit callback for Wysiwyg profile overview form.
488 */
489function wysiwyg_profile_overview_submit($form, &$form_state) {
490 foreach ($form_state['values']['formats'] as $format => $values) {
491 db_query("UPDATE {wysiwyg} SET editor = '%s' WHERE format = %d", $values['editor'], $format);
492 if (!db_affected_rows()) {
493 db_query("INSERT INTO {wysiwyg} (format, editor) VALUES (%d, '%s')", $format, $values['editor']);
494 }
495 }
496}
497
498/**
c06ba055 499 * Delete editor profile confirmation form.
500 */
117ad234 501function wysiwyg_profile_delete_confirm(&$form_state, $profile) {
81a2754f 502 $formats = filter_formats();
117ad234 503 $format = $formats[$profile->format];
504 $form['format'] = array('#type' => 'value', '#value' => $format);
c06ba055 505 return confirm_form(
506 $form,
117ad234 507 t('Are you sure you want to remove the profile for %name?', array('%name' => $format->name)),
508 'admin/settings/wysiwyg',
81a2754f 509 t('This action cannot be undone.'), t('Remove'), t('Cancel')
c06ba055 510 );
511}
512
513/**
514 * Submit callback for Wysiwyg profile delete form.
515 *
516 * @see wysiwyg_profile_delete_confirm()
517 */
518function wysiwyg_profile_delete_confirm_submit($form, &$form_state) {
117ad234 519 $format = $form_state['values']['format'];
520 wysiwyg_profile_delete($format->format);
521 drupal_set_message(t('Wysiwyg profile for %name has been deleted.', array('%name' => $format->name)));
522 $form_state['redirect'] = 'admin/settings/wysiwyg';
c06ba055 523}
524
525/**
a2f0b052 526 * Remove a profile from the database.
527 */
81a2754f 528function wysiwyg_profile_delete($format) {
529 db_query("DELETE FROM {wysiwyg} WHERE format = %d", $format);
a2f0b052 530}
531