#667848 by TwoD, kaakuu: Fixed FCKeditor is not properly detached in IE.
[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 = array();
54 $form['format'] = array('#type' => 'value', '#value' => $profile->format);
55 $form['input_format'] = array('#type' => 'value', '#value' => $formats[$profile->format]->name);
56 $form['editor'] = array('#type' => 'value', '#value' => $profile->editor);
a2f0b052 57
58 $form['basic'] = array(
59 '#type' => 'fieldset',
60 '#title' => t('Basic setup'),
61 '#collapsible' => TRUE,
9e3e05cd 62 '#collapsed' => TRUE,
a2f0b052 63 );
64
a2f0b052 65 $form['basic']['default'] = array(
4248dc52 66 '#type' => 'checkbox',
67 '#title' => t('Enabled by default'),
c792e281 68 '#default_value' => $profile->settings['default'],
4248dc52 69 '#return_value' => 1,
70 '#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 71 );
72
73 $form['basic']['user_choose'] = array(
4248dc52 74 '#type' => 'checkbox',
a2f0b052 75 '#title' => t('Allow users to choose default'),
c792e281 76 '#default_value' => $profile->settings['user_choose'],
4248dc52 77 '#return_value' => 1,
81a2754f 78 '#description' => t('If allowed, users will be able to choose their own editor default state in their user account settings.'),
a2f0b052 79 );
80
81 $form['basic']['show_toggle'] = array(
4248dc52 82 '#type' => 'checkbox',
81a2754f 83 '#title' => t('Show <em>enable/disable rich text</em> toggle link'),
c792e281 84 '#default_value' => $profile->settings['show_toggle'],
4248dc52 85 '#return_value' => 1,
81a2754f 86 '#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 87 );
88
a2f0b052 89 $form['basic']['theme'] = array(
90 '#type' => 'hidden',
c792e281 91 '#value' => $profile->settings['theme'],
a2f0b052 92 );
93
94 $form['basic']['language'] = array(
95 '#type' => 'select',
96 '#title' => t('Language'),
c792e281 97 '#default_value' => $profile->settings['language'],
6ce9b0a3 98 '#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 99 '#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 100 );
101
a2f0b052 102 $form['buttons'] = array(
103 '#type' => 'fieldset',
104 '#title' => t('Buttons and plugins'),
105 '#collapsible' => TRUE,
106 '#collapsed' => TRUE,
107 '#tree' => TRUE,
eb714832 108 '#theme' => 'wysiwyg_admin_button_table',
a2f0b052 109 );
110
81a2754f 111 $plugins = wysiwyg_get_plugins($profile->editor);
a2f0b052 112 // Generate the button list.
a090395c 113 foreach ($plugins as $name => $meta) {
a2f0b052 114 if (isset($meta['buttons']) && is_array($meta['buttons'])) {
a090395c 115 foreach ($meta['buttons'] as $button => $title) {
9eb0a9ec 116 $icon = '';
117 if (!empty($meta['path'])) {
118 // @todo Button icon locations are different in editors, editor versions,
119 // and contrib/custom plugins (like Image Assist, f.e.).
54a65ca8 120 $img_src = $meta['path'] . "/images/$name.gif";
9eb0a9ec 121 // Handle plugins that have more than one button.
122 if (!file_exists($img_src)) {
54a65ca8 123 $img_src = $meta['path'] . "/images/$button.gif";
9eb0a9ec 124 }
54a65ca8 125 $icon = file_exists($img_src) ? '<img src="' . base_path() . $img_src . '" title="' . $button . '" style="border: 1px solid grey; vertical-align: middle;" />' : '';
a2f0b052 126 }
6bf6d580 127 $title = (isset($meta['url']) ? l($title, $meta['url'], array('target' => '_blank')) : $title);
54a65ca8 128 $title = (!empty($icon) ? $icon . ' ' . $title : $title);
a090395c 129 $form['buttons'][$name][$button] = array(
130 '#type' => 'checkbox',
131 '#title' => $title,
c792e281 132 '#default_value' => !empty($profile->settings['buttons'][$name][$button]) ? $profile->settings['buttons'][$name][$button] : FALSE,
a090395c 133 );
a2f0b052 134 }
135 }
a090395c 136 else if (isset($meta['extensions']) && is_array($meta['extensions'])) {
137 foreach ($meta['extensions'] as $extension => $title) {
a090395c 138 $form['buttons'][$name][$extension] = array(
139 '#type' => 'checkbox',
6bf6d580 140 '#title' => isset($meta['url']) ? l($title, $meta['url'], array('target' => '_blank')) : $title,
c792e281 141 '#default_value' => !empty($profile->settings['buttons'][$name][$extension]) ? $profile->settings['buttons'][$name][$extension] : FALSE,
a090395c 142 );
a2f0b052 143 }
a2f0b052 144 }
145 }
146
147 $form['appearance'] = array(
148 '#type' => 'fieldset',
149 '#title' => t('Editor appearance'),
150 '#collapsible' => TRUE,
9e3e05cd 151 '#collapsed' => TRUE,
a2f0b052 152 );
153
154 $form['appearance']['toolbar_loc'] = array(
155 '#type' => 'select',
156 '#title' => t('Toolbar location'),
c792e281 157 '#default_value' => $profile->settings['toolbar_loc'],
c2219286 158 '#options' => array('bottom' => t('Bottom'), 'top' => t('Top')),
4248dc52 159 '#description' => t('This option controls whether the editor toolbar is displayed above or below the editing area.'),
a2f0b052 160 );
161
162 $form['appearance']['toolbar_align'] = array(
163 '#type' => 'select',
4248dc52 164 '#title' => t('Button alignment'),
c792e281 165 '#default_value' => $profile->settings['toolbar_align'],
c2219286 166 '#options' => array('center' => t('Center'), 'left' => t('Left'), 'right' => t('Right')),
4248dc52 167 '#description' => t('This option controls the alignment of icons in the editor toolbar.'),
a2f0b052 168 );
169
170 $form['appearance']['path_loc'] = array(
171 '#type' => 'select',
172 '#title' => t('Path location'),
c792e281 173 '#default_value' => $profile->settings['path_loc'],
4248dc52 174 '#options' => array('none' => t('Hide'), 'top' => t('Top'), 'bottom' => t('Bottom')),
175 '#description' => t('Where to display the path to HTML elements (i.e. <code>body > table > tr > td</code>).'),
a2f0b052 176 );
177
178 $form['appearance']['resizing'] = array(
4248dc52 179 '#type' => 'checkbox',
a2f0b052 180 '#title' => t('Enable resizing button'),
c792e281 181 '#default_value' => $profile->settings['resizing'],
4248dc52 182 '#return_value' => 1,
183 '#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 184 );
185
a2f0b052 186 $form['output'] = array(
187 '#type' => 'fieldset',
188 '#title' => t('Cleanup and output'),
189 '#collapsible' => TRUE,
9e3e05cd 190 '#collapsed' => TRUE,
a2f0b052 191 );
192
193 $form['output']['verify_html'] = array(
4248dc52 194 '#type' => 'checkbox',
a2f0b052 195 '#title' => t('Verify HTML'),
c792e281 196 '#default_value' => $profile->settings['verify_html'],
4248dc52 197 '#return_value' => 1,
198 '#description' => t('If enabled, potentially malicious code like <code>&lt;HEAD&gt;</code> tags will be removed from HTML contents.'),
a2f0b052 199 );
200
201 $form['output']['preformatted'] = array(
4248dc52 202 '#type' => 'checkbox',
a2f0b052 203 '#title' => t('Preformatted'),
c792e281 204 '#default_value' => $profile->settings['preformatted'],
4248dc52 205 '#return_value' => 1,
206 '#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 207 );
208
209 $form['output']['convert_fonts_to_spans'] = array(
4248dc52 210 '#type' => 'checkbox',
a2f0b052 211 '#title' => t('Convert &lt;font&gt; tags to styles'),
c792e281 212 '#default_value' => $profile->settings['convert_fonts_to_spans'],
4248dc52 213 '#return_value' => 1,
214 '#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 215 );
216
217 $form['output']['remove_linebreaks'] = array(
4248dc52 218 '#type' => 'checkbox',
9e3e05cd 219 '#title' => t('Remove linebreaks'),
c792e281 220 '#default_value' => $profile->settings['remove_linebreaks'],
4248dc52 221 '#return_value' => 1,
222 '#description' => t('If enabled, the editor will remove most linebreaks from contents. Disabling this option could avoid conflicts with other input filters.'),
a2f0b052 223 );
224
225 $form['output']['apply_source_formatting'] = array(
4248dc52 226 '#type' => 'checkbox',
9e3e05cd 227 '#title' => t('Apply source formatting'),
c792e281 228 '#default_value' => $profile->settings['apply_source_formatting'],
4248dc52 229 '#return_value' => 1,
230 '#description' => t('If enabled, the editor will re-format the HTML source code. Disabling this option could avoid conflicts with other input filters.'),
a2f0b052 231 );
232
11c19e9a 233 $form['output']['paste_auto_cleanup_on_paste'] = array(
4248dc52 234 '#type' => 'checkbox',
235 '#title' => t('Force cleanup on standard paste'),
c792e281 236 '#default_value' => $profile->settings['paste_auto_cleanup_on_paste'],
4248dc52 237 '#return_value' => 1,
238 '#description' => t('If enabled, the default paste function (CTRL-V or SHIFT-INS) behaves like the "paste from word" plugin function.'),
11c19e9a 239 );
240
a2f0b052 241 $form['css'] = array(
242 '#type' => 'fieldset',
243 '#title' => t('CSS'),
244 '#collapsible' => TRUE,
9e3e05cd 245 '#collapsed' => TRUE,
a2f0b052 246 );
247
60486af7 248 $form['css']['block_formats'] = array(
249 '#type' => 'textfield',
250 '#title' => t('Block formats'),
c792e281 251 '#default_value' => $profile->settings['block_formats'],
60486af7 252 '#size' => 40,
253 '#maxlength' => 250,
b913a764 254 '#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 255 );
256
a2f0b052 257 $form['css']['css_setting'] = array(
258 '#type' => 'select',
259 '#title' => t('Editor CSS'),
c792e281 260 '#default_value' => $profile->settings['css_setting'],
5708da35 261 '#options' => array('theme' => t('Use theme CSS'), 'self' => t('Define CSS'), 'none' => t('Editor default CSS')),
262 '#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 263 );
264
265 $form['css']['css_path'] = array(
266 '#type' => 'textfield',
267 '#title' => t('CSS path'),
c792e281 268 '#default_value' => $profile->settings['css_path'],
a2f0b052 269 '#size' => 40,
270 '#maxlength' => 255,
8ccdb7f3 271 '#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 272 );
273
274 $form['css']['css_classes'] = array(
60486af7 275 '#type' => 'textarea',
a2f0b052 276 '#title' => t('CSS classes'),
c792e281 277 '#default_value' => $profile->settings['css_classes'],
60486af7 278 '#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 279 );
280
281 $form['submit'] = array(
282 '#type' => 'submit',
81a2754f 283 '#value' => t('Save'),
a2f0b052 284 );
285
286 return $form;
287}
288
289/**
eb714832 290 * Submit callback for Wysiwyg profile form.
b8a2b356 291 *
eb714832 292 * @see wysiwyg_profile_form()
b8a2b356 293 */
eb714832 294function wysiwyg_profile_form_submit($form, &$form_state) {
117ad234 295 $values = $form_state['values'];
296 if (isset($values['buttons'])) {
81a2754f 297 // Store only enabled buttons for each plugin.
117ad234 298 foreach ($values['buttons'] as $plugin => $buttons) {
299 $values['buttons'][$plugin] = array_filter($values['buttons'][$plugin]);
81a2754f 300 }
301 // Store only enabled plugins.
117ad234 302 $values['buttons'] = array_filter($values['buttons']);
addb35d1 303 }
81a2754f 304 // Remove input format name.
117ad234 305 $format = $values['format'];
306 $input_format = $values['input_format'];
307 $editor = $values['editor'];
308 unset($values['format'], $values['input_format'], $values['editor']);
b8a2b356 309
075f2dce 310 // Remove FAPI values.
311 // @see system_settings_form_submit()
266ff4f0 312 unset($values['submit'], $values['form_id'], $values['op'], $values['form_token'], $values['form_build_id']);
075f2dce 313
b8a2b356 314 // Insert new profile data.
117ad234 315 db_query("UPDATE {wysiwyg} SET settings = '%s' WHERE format = %d", serialize($values), $format);
81a2754f 316
317 drupal_set_message(t('Wysiwyg profile for %format has been saved.', array('%format' => $input_format)));
b8a2b356 318
117ad234 319 $form_state['redirect'] = 'admin/settings/wysiwyg';
b8a2b356 320}
321
322/**
9eca41dc 323 * Layout for the buttons in the Wysiwyg Editor profile form.
a2f0b052 324 */
8e4cdab3 325function theme_wysiwyg_admin_button_table($form) {
a2f0b052 326 $buttons = array();
327
075f2dce 328 // Flatten forms array.
a090395c 329 foreach (element_children($form) as $name) {
330 foreach (element_children($form[$name]) as $button) {
331 $buttons[] = drupal_render($form[$name][$button]);
332 }
a2f0b052 333 }
334
075f2dce 335 // Split checkboxes into rows with 3 columns.
a2f0b052 336 $total = count($buttons);
337 $rows = array();
338 for ($i = 0; $i < $total; $i++) {
7623c9ce 339 $row = array();
340 $row[] = array('data' => $buttons[$i]);
c792e281 341 if (isset($buttons[++$i])) {
7623c9ce 342 $row[] = array('data' => $buttons[$i]);
c792e281 343 }
344 if (isset($buttons[++$i])) {
7623c9ce 345 $row[] = array('data' => $buttons[$i]);
c792e281 346 }
a2f0b052 347 $rows[] = $row;
348 }
349
350 $output = theme('table', array(), $rows, array('width' => '100%'));
351
352 return $output;
353}
354
355/**
c792e281 356 * Display overview of setup Wysiwyg Editor profiles; menu callback.
a2f0b052 357 */
eb714832 358function wysiwyg_profile_overview() {
c0c42d78 359 include_once './includes/install.inc';
81a2754f 360 $form = array();
c792e281 361
362 // Check which wysiwyg editors are installed.
363 $editors = wysiwyg_get_all_editors();
364 $count = count($editors);
c0c42d78 365 $status = array();
366 $options = array('' => t('No editor'));
0044993f 367
368 foreach ($editors as $name => $editor) {
369 $status[$name] = array(
370 'severity' => (isset($editor['error']) ? REQUIREMENT_ERROR : ($editor['installed'] ? REQUIREMENT_OK : REQUIREMENT_INFO)),
371 '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'])),
372 'value' => (isset($editor['installed version']) ? $editor['installed version'] : t('Not installed.')),
373 'description' => (isset($editor['error']) ? $editor['error'] : ''),
c0c42d78 374 );
0044993f 375 if ($editor['installed']) {
376 $options[$name] = $editor['title'] . (isset($editor['installed version']) ? ' ' . $editor['installed version'] : '');
c792e281 377 }
c0c42d78 378 else {
0044993f 379 // Build on-site installation instructions.
380 // @todo Setup $library in wysiwyg_load_editor() already.
381 $library = (isset($editor['library']) ? $editor['library'] : key($editor['libraries']));
382 $targs = array(
383 '@editor-path' => $editor['editor path'],
cdb08c25 384 '@library-filepath' => $editor['library path'] . '/' . (isset($editor['libraries'][$library]['files'][0]) ? $editor['libraries'][$library]['files'][0] : key($editor['libraries'][$library]['files'])),
0044993f 385 );
386 $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>';
387 $instructions .= '<p>' . t('So the actual library can be found at:<br /><code>@library-filepath</code>', $targs) . '</p>';
388
389 $status[$name]['description'] .= $instructions;
c0c42d78 390 $count--;
c792e281 391 }
0044993f 392 // In case there is an error, always show installation instructions.
393 if (isset($editor['error'])) {
394 $show_instructions = TRUE;
395 }
396 }
397 if (!$count) {
398 $show_instructions = TRUE;
c792e281 399 }
c0c42d78 400 $form['status'] = array(
401 '#type' => 'fieldset',
402 '#title' => t('Installation instructions'),
403 '#collapsible' => TRUE,
0044993f 404 '#collapsed' => !isset($show_instructions),
c0c42d78 405 '#description' => (!$count ? t('There are no editor libraries installed currently. The following list contains a list of currently supported editors:') : ''),
406 '#weight' => 10,
407 );
408 $form['status']['report'] = array('#type' => 'markup', '#value' => theme('status_report', $status));
c792e281 409
c0c42d78 410 if (!$count) {
81a2754f 411 return $form;
9eca41dc 412 }
413
81a2754f 414 $formats = filter_formats();
117ad234 415 $profiles = wysiwyg_profile_load_all();
c94c9d22 416 $form['formats'] = array(
417 '#type' => 'fieldset',
418 '#title' => t('Wysiwyg profiles'),
419 '#description' => t('Once an editor has been associated with an input format, the editor association cannot be changed without first deleting the profile and then creating a new one. Delete a profile by clicking on the "delete" link and afterwards, set up a new profile as usual.'),
420 '#tree' => TRUE,
421 );
9fd8955d 422
423 $enable_save = FALSE;
81a2754f 424 foreach ($formats as $id => $format) {
425 $form['formats'][$id]['name'] = array(
426 '#value' => check_plain($format->name),
427 );
c94c9d22 428 // Only display editor selection for associated input formats to avoid
429 // confusion about disabled selection.
430 if (isset($profiles[$id]) && !empty($profiles[$id]->editor)) {
431 $form['formats'][$id]['editor'] = array(
432 '#type' => 'markup',
433 '#value' => $options[$profiles[$id]->editor],
434 '#id' => "edit-editor-$id",
435 );
436 }
437 else {
438 $form['formats'][$id]['editor'] = array(
439 '#type' => 'select',
440 '#default_value' => '',
441 '#options' => $options,
442 '#id' => "edit-editor-$id",
443 );
9fd8955d 444 $enable_save = TRUE;
c94c9d22 445 }
81a2754f 446 if (isset($profiles[$id]) && !empty($profiles[$id]->editor)) {
447 $form['formats'][$id]['edit'] = array(
117ad234 448 '#value' => l(t('Edit'), "admin/settings/wysiwyg/profile/$id/edit"),
81a2754f 449 );
c94c9d22 450 $form['formats'][$id]['delete'] = array(
451 '#value' => l(t('Delete'), "admin/settings/wysiwyg/profile/$id/delete"),
c06ba055 452 );
a2f0b052 453 }
a2f0b052 454 }
455
9fd8955d 456 // Submitting the form when no editors can be selected causes errors.
457 if ($enable_save) {
458 $form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
459 }
81a2754f 460 return $form;
461}
462
463/**
464 * Return HTML for the Wysiwyg profile overview form.
465 */
8e4cdab3 466function theme_wysiwyg_profile_overview($form) {
c0c42d78 467 if (!isset($form['formats'])) {
468 return;
469 }
81a2754f 470 $output = '';
471 $header = array(t('Input format'), t('Editor'), array('data' => t('Operations'), 'colspan' => 2));
472 $rows = array();
473 foreach (element_children($form['formats']) as $item) {
474 $format = &$form['formats'][$item];
475 $rows[] = array(
476 drupal_render($format['name']),
477 drupal_render($format['editor']),
478 isset($format['edit']) ? drupal_render($format['edit']) : '',
c94c9d22 479 isset($format['delete']) ? drupal_render($format['delete']) : '',
81a2754f 480 );
481 }
c94c9d22 482 $form['formats']['#children'] = theme('table', $header, $rows);
81a2754f 483 $output .= drupal_render($form);
a2f0b052 484 return $output;
485}
486
487/**
81a2754f 488 * Submit callback for Wysiwyg profile overview form.
489 */
490function wysiwyg_profile_overview_submit($form, &$form_state) {
491 foreach ($form_state['values']['formats'] as $format => $values) {
492 db_query("UPDATE {wysiwyg} SET editor = '%s' WHERE format = %d", $values['editor'], $format);
493 if (!db_affected_rows()) {
494 db_query("INSERT INTO {wysiwyg} (format, editor) VALUES (%d, '%s')", $format, $values['editor']);
495 }
496 }
497}
498
499/**
c06ba055 500 * Delete editor profile confirmation form.
501 */
117ad234 502function wysiwyg_profile_delete_confirm(&$form_state, $profile) {
81a2754f 503 $formats = filter_formats();
117ad234 504 $format = $formats[$profile->format];
505 $form['format'] = array('#type' => 'value', '#value' => $format);
c06ba055 506 return confirm_form(
507 $form,
117ad234 508 t('Are you sure you want to remove the profile for %name?', array('%name' => $format->name)),
509 'admin/settings/wysiwyg',
81a2754f 510 t('This action cannot be undone.'), t('Remove'), t('Cancel')
c06ba055 511 );
512}
513
514/**
515 * Submit callback for Wysiwyg profile delete form.
516 *
517 * @see wysiwyg_profile_delete_confirm()
518 */
519function wysiwyg_profile_delete_confirm_submit($form, &$form_state) {
117ad234 520 $format = $form_state['values']['format'];
521 wysiwyg_profile_delete($format->format);
522 drupal_set_message(t('Wysiwyg profile for %name has been deleted.', array('%name' => $format->name)));
523 $form_state['redirect'] = 'admin/settings/wysiwyg';
c06ba055 524}
525
526/**
a2f0b052 527 * Remove a profile from the database.
528 */
81a2754f 529function wysiwyg_profile_delete($format) {
530 db_query("DELETE FROM {wysiwyg} WHERE format = %d", $format);
a2f0b052 531}
532