Index: wysiwyg.admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/wysiwyg.admin.inc,v retrieving revision 1.12 diff -u -p -r1.12 wysiwyg.admin.inc --- wysiwyg.admin.inc 4 Jun 2009 22:31:15 -0000 1.12 +++ wysiwyg.admin.inc 8 Jun 2009 05:00:45 -0000 @@ -7,35 +7,7 @@ */ /** - * Callback handler for admin pages; menu callback. - * - * @todo Move into hook_menu(), resp. FAPI functions. - */ -function wysiwyg_admin($arg = '', $format = '') { - switch ($arg) { - case 'edit': - if ($profile = wysiwyg_load_profile($format)) { - $breadcrumb = array(); - $breadcrumb[] = l(t('Home'), NULL); - $breadcrumb[] = l(t('Administer'), 'admin'); - $breadcrumb[] = l(t('Site configuration'), 'admin/settings'); - $breadcrumb[] = l(t('Wysiwyg profiles'), 'admin/settings/wysiwyg/profile'); - drupal_set_breadcrumb($breadcrumb); - return drupal_get_form('wysiwyg_profile_form', $profile); - } - break; - - case 'delete': - return drupal_get_form('wysiwyg_profile_delete_confirm', $format); - - case '': - return drupal_get_form('wysiwyg_profile_overview'); - } - drupal_goto('admin/settings/wysiwyg/profile'); -} - -/** - * Return an HTML form for profile configuration. + * Form builder for Wysiwyg profile form. */ function wysiwyg_profile_form($form_state, $profile) { // Merge in defaults. @@ -75,7 +47,8 @@ function wysiwyg_profile_form($form_stat $profile = (object) $profile; $formats = filter_formats(); - drupal_set_title(t('%format Wysiwyg profile', array('%format' => $formats[$profile->format]->name))); + $editor = wysiwyg_get_editor($profile->editor); + drupal_set_title(t('%editor profile for %format', array('%editor' => $editor['title'], '%format' => $formats[$profile->format]->name))); $form = array(); $form['format'] = array('#type' => 'value', '#value' => $profile->format); @@ -319,30 +292,31 @@ function wysiwyg_profile_form($form_stat * @see wysiwyg_profile_form() */ function wysiwyg_profile_form_submit($form, &$form_state) { - if (isset($form_state['values']['buttons'])) { + $values = $form_state['values']; + if (isset($values['buttons'])) { // Store only enabled buttons for each plugin. - foreach ($form_state['values']['buttons'] as $plugin => $buttons) { - $form_state['values']['buttons'][$plugin] = array_filter($form_state['values']['buttons'][$plugin]); + foreach ($values['buttons'] as $plugin => $buttons) { + $values['buttons'][$plugin] = array_filter($values['buttons'][$plugin]); } // Store only enabled plugins. - $form_state['values']['buttons'] = array_filter($form_state['values']['buttons']); + $values['buttons'] = array_filter($values['buttons']); } // Remove input format name. - $format = $form_state['values']['format']; - $input_format = $form_state['values']['input_format']; - $editor = $form_state['values']['editor']; - unset($form_state['values']['format'], $form_state['values']['input_format'], $form_state['values']['editor']); + $format = $values['format']; + $input_format = $values['input_format']; + $editor = $values['editor']; + unset($values['format'], $values['input_format'], $values['editor']); // Remove FAPI values. // @see system_settings_form_submit() - unset($form_state['values']['submit'], $form_state['values']['form_id'], $form_state['values']['op'], $form_state['values']['form_token']); + unset($values['submit'], $values['form_id'], $values['op'], $values['form_token']); // Insert new profile data. - db_query("UPDATE {wysiwyg} SET settings = '%s' WHERE format = %d", serialize($form_state['values']), $format); + db_query("UPDATE {wysiwyg} SET settings = '%s' WHERE format = %d", serialize($values), $format); drupal_set_message(t('Wysiwyg profile for %format has been saved.', array('%format' => $input_format))); - drupal_goto('admin/settings/wysiwyg/profile'); + $form_state['redirect'] = 'admin/settings/wysiwyg'; } /** @@ -419,7 +393,7 @@ function wysiwyg_profile_overview() { } $formats = filter_formats(); - $profiles = wysiwyg_load_profile(); + $profiles = wysiwyg_profile_load_all(); $form['formats']['#tree'] = TRUE; foreach ($formats as $id => $format) { $form['formats'][$id]['name'] = array( @@ -434,10 +408,10 @@ function wysiwyg_profile_overview() { ); if (isset($profiles[$id]) && !empty($profiles[$id]->editor)) { $form['formats'][$id]['edit'] = array( - '#value' => l(t('Edit'), 'admin/settings/wysiwyg/profile/edit/'. $profiles[$id]->format), + '#value' => l(t('Edit'), "admin/settings/wysiwyg/profile/$id/edit"), ); $form['formats'][$id]['remove'] = array( - '#value' => l(t('Remove'), 'admin/settings/wysiwyg/profile/delete/'. $profiles[$id]->format), + '#value' => l(t('Remove'), "admin/settings/wysiwyg/profile/$id/delete"), ); } } @@ -485,15 +459,14 @@ function wysiwyg_profile_overview_submit /** * Delete editor profile confirmation form. */ -function wysiwyg_profile_delete_confirm(&$form_state, $format) { - $form = array(); - $form['format'] = array('#type' => 'value', '#value' => $format); +function wysiwyg_profile_delete_confirm(&$form_state, $profile) { $formats = filter_formats(); - $form['name'] = array('#type' => 'value', '#value' => $formats[$format]->name); + $format = $formats[$profile->format]; + $form['format'] = array('#type' => 'value', '#value' => $format); return confirm_form( $form, - t('Are you sure you want to remove the profile for %name?', array('%name' => $formats[$format]->name)), - 'admin/settings/wysiwyg/profile', + t('Are you sure you want to remove the profile for %name?', array('%name' => $format->name)), + 'admin/settings/wysiwyg', t('This action cannot be undone.'), t('Remove'), t('Cancel') ); } @@ -504,9 +477,10 @@ function wysiwyg_profile_delete_confirm( * @see wysiwyg_profile_delete_confirm() */ function wysiwyg_profile_delete_confirm_submit($form, &$form_state) { - wysiwyg_profile_delete($form_state['values']['format']); - drupal_set_message(t('Wysiwyg profile for %name has been deleted.', array('%name' => $form_state['values']['name']))); - $form_state['redirect'] = 'admin/settings/wysiwyg/profile'; + $format = $form_state['values']['format']; + wysiwyg_profile_delete($format->format); + drupal_set_message(t('Wysiwyg profile for %name has been deleted.', array('%name' => $format->name))); + $form_state['redirect'] = 'admin/settings/wysiwyg'; } /** Index: wysiwyg.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/wysiwyg.module,v retrieving revision 1.31 diff -u -p -r1.31 wysiwyg.module --- wysiwyg.module 7 Jun 2009 23:16:02 -0000 1.31 +++ wysiwyg.module 8 Jun 2009 05:01:25 -0000 @@ -10,13 +10,38 @@ * Implementation of hook_menu(). */ function wysiwyg_menu() { - $items = array(); - $items['admin/settings/wysiwyg/profile'] = array( + $items['admin/settings/wysiwyg'] = array( 'title' => 'Wysiwyg', - 'page callback' => 'wysiwyg_admin', - 'description' => 'Configure client-side editor profiles.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('wysiwyg_profile_overview'), + 'description' => 'Configure client-side editors.', + 'access arguments' => array('administer filters'), + 'file' => 'wysiwyg.admin.inc', + ); + $items['admin/settings/wysiwyg/profile'] = array( + 'title' => 'Profiles', + 'type' => MENU_DEFAULT_LOCAL_TASK, + ); + $items['admin/settings/wysiwyg/profile/%wysiwyg_profile/edit'] = array( + 'title' => 'Edit', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('wysiwyg_profile_form', 4), 'access arguments' => array('administer filters'), 'file' => 'wysiwyg.admin.inc', + 'tab_root' => 'admin/settings/wysiwyg/profile', + 'tab_parent' => 'admin/settings/wysiwyg/profile/%wysiwyg_profile', + 'type' => MENU_LOCAL_TASK, + ); + $items['admin/settings/wysiwyg/profile/%wysiwyg_profile/delete'] = array( + 'title' => 'Remove', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('wysiwyg_profile_delete_confirm', 4), + 'access arguments' => array('administer filters'), + 'file' => 'wysiwyg.admin.inc', + 'tab_root' => 'admin/settings/wysiwyg/profile', + 'tab_parent' => 'admin/settings/wysiwyg/profile/%wysiwyg_profile', + 'type' => MENU_LOCAL_TASK, + 'weight' => 10, ); $items['wysiwyg/%'] = array( 'page callback' => 'wysiwyg_dialog', @@ -51,12 +76,9 @@ function wysiwyg_theme() { */ function wysiwyg_help($path, $arg) { switch ($path) { - case 'admin/settings/wysiwyg/profile': - if (empty($arg[4])) { - $output = '

'. t('A Wysiwyg profile can be associated to an input format. A Wysiwyg profile defines which client-side editor is loaded, what buttons or themes are enabled for the editor, how the editor is displayed, and a few other editor-specific functions.') .'

'; - return $output; - } - break; + case 'admin/settings/wysiwyg': + $output = '

'. t('A Wysiwyg profile can be associated to an input format. A Wysiwyg profile defines which client-side editor is loaded, what buttons or themes are enabled for the editor, how the editor is displayed, and a few other editor-specific functions.') .'

'; + return $output; } } @@ -187,7 +209,7 @@ function wysiwyg_process_form(&$form) { * @see wysiwyg_load_editor(), wysiwyg_get_editor() */ function wysiwyg_get_profile($format) { - if ($profile = wysiwyg_load_profile($format)) { + if ($profile = wysiwyg_profile_load($format)) { if (wysiwyg_load_editor($profile)) { return $profile; } @@ -539,21 +561,38 @@ function wysiwyg_get_css() { } /** - * Load all profiles. Just load one profile if $name is passed in. + * Load profile for a given input format. + */ +function wysiwyg_profile_load($format) { + static $profiles; + + if (!isset($profiles) || !array_key_exists($format, $profiles)) { + $result = db_query('SELECT format, editor, settings FROM {wysiwyg} WHERE format = %d', $format); + while ($profile = db_fetch_object($result)) { + $profile->settings = unserialize($profile->settings); + $profiles[$profile->format] = $profile; + } + } + + return (isset($profiles[$format]) ? $profiles[$format] : FALSE); +} + +/** + * Load all profiles. */ -function wysiwyg_load_profile($format = '') { +function wysiwyg_profile_load_all() { static $profiles; if (!isset($profiles)) { $profiles = array(); - $result = db_query('SELECT * FROM {wysiwyg}'); + $result = db_query('SELECT format, editor, settings FROM {wysiwyg}'); while ($profile = db_fetch_object($result)) { $profile->settings = unserialize($profile->settings); $profiles[$profile->format] = $profile; } } - return ($format && isset($profiles[$format]) ? $profiles[$format] : ($format ? FALSE : $profiles)); + return $profiles; } /**