Index: wysiwyg.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/wysiwyg.install,v retrieving revision 1.4.2.3 diff -u -p -r1.4.2.3 wysiwyg.install --- wysiwyg.install 10 Sep 2010 00:39:24 -0000 1.4.2.3 +++ wysiwyg.install 4 Jan 2011 00:35:36 -0000 @@ -6,7 +6,7 @@ */ function wysiwyg_schema() { $schema['wysiwyg'] = array( - 'description' => t('Stores Wysiwyg profiles.'), + 'description' => 'Stores Wysiwyg profiles.', 'fields' => array( 'format' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'editor' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), @@ -14,6 +14,46 @@ function wysiwyg_schema() { ), 'primary key' => array('format'), ); + $schema['wysiwyg_user'] = array( + 'description' => 'Stores user preferences for wysiwyg profiles.', + 'fields' => array( + 'uid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => 'The {users}.uid of the user.', + ), + 'format' => array( + 'description' => 'The {filter_formats}.format of the text format.', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), + 'status' => array( + 'description' => 'Boolean indicating whether the format is enabled by default.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'size' => 'tiny', + ), + ), + 'indexes' => array( + 'uid' => array('uid'), + 'format' => array('format'), + ), + 'foreign keys' => array( + 'uid' => array( + 'table' => 'users', + 'columns' => array('uid' => 'uid'), + ), + 'format' => array( + 'table' => 'filter_formats', + 'columns' => array('format' => 'format'), + ), + ), + ); return $schema; } @@ -177,3 +217,52 @@ function wysiwyg_update_6200() { return $ret; } +/** + * Create the {wysiwyg_user} table. + */ +function wysiwyg_update_6201() { + $ret = array(); + if (db_table_exists('wysiwyg_user')) { + db_create_table($ret, 'wysiwyg_user', array( + 'description' => 'Stores user preferences for wysiwyg profiles.', + 'fields' => array( + 'uid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => 'The {users}.uid of the user.', + ), + 'format' => array( + 'description' => 'The {filter_formats}.format of the text format.', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), + 'status' => array( + 'description' => 'Boolean indicating whether the format is enabled by default.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'size' => 'tiny', + ), + ), + 'indexes' => array( + 'uid' => array('uid'), + 'format' => array('format'), + ), + 'foreign keys' => array( + 'uid' => array( + 'table' => 'users', + 'columns' => array('uid' => 'uid'), + ), + 'format' => array( + 'table' => 'filter_formats', + 'columns' => array('format' => 'format'), + ), + ), + )); + } + return $ret; +} Index: wysiwyg.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/wysiwyg.module,v retrieving revision 1.33.2.12 diff -u -p -r1.33.2.12 wysiwyg.module --- wysiwyg.module 6 Nov 2010 17:57:36 -0000 1.33.2.12 +++ wysiwyg.module 4 Jan 2011 00:45:56 -0000 @@ -626,44 +626,65 @@ function wysiwyg_profile_load_all() { /** * Implementation of hook_user(). */ -function wysiwyg_user($type, &$edit, &$user, $category = NULL) { - if ($type == 'form' && $category == 'account') { - // @todo http://drupal.org/node/322433 - $profile = new stdClass; - if (isset($profile->settings['user_choose']) && $profile->settings['user_choose']) { - $form['wysiwyg'] = array( - '#type' => 'fieldset', - '#title' => t('Wysiwyg Editor settings'), - '#weight' => 10, - '#collapsible' => TRUE, - '#collapsed' => TRUE, - ); - $form['wysiwyg']['wysiwyg_status'] = array( - '#type' => 'checkbox', - '#title' => t('Enable editor by default'), - '#default_value' => isset($user->wysiwyg_status) ? $user->wysiwyg_status : (isset($profile->settings['default']) ? $profile->settings['default'] : FALSE), - '#return_value' => 1, - '#description' => t('If enabled, rich-text editing is enabled by default in textarea fields.'), +function wysiwyg_user($op, &$edit, &$user, $category = NULL) { + if ($op == 'form' && $category == 'account') { + $user_formats = filter_formats(); + $options = array(); + $options_default = array(); + foreach ($wysiwyg_profile_load_all() as $format => $profile) { + // Only show formats a user has access to use that allow user_choose. + if (!empty($profile->settings['user_choose']) && isset($user_formats[$format])) { + $options[$format] = $user_formats[$format]->name; + if (wysiwyg_user_get_status($profile)) { + $options_default[] = $format; + } + } + } + if (!empty($options)) { + $form['wysiwyg_status'] = array( + '#type' => 'checkboxes', + '#title' => t('Input formats enabled for rich-text editing'), + '#default_value' => $options_default, + '#options' => $options, ); return array('wysiwyg' => $form); } } - elseif ($type == 'validate' && isset($edit['wysiwyg_status'])) { - return array('wysiwyg_status' => $edit['wysiwyg_status']); + elseif ($op == 'insert' || $op == 'update') { + if (isset($edit['wysiwyg_status'])) { + db_query("DELETE FROM {wysiwyg_user} WHERE uid = %d", $user->uid); + foreach ($edit['wysiwyg_status'] as $format => $status) { + db_query("INSERT INTO {wysiwyg_user} (uid, format, status) VALUES (%d, %d, %d)", array( + $user->uid, + $format, + (int) (bool) $status, + )); + } + } } } function wysiwyg_user_get_status($profile) { global $user; - if (!empty($profile->settings['user_choose']) && isset($user->wysiwyg_status)) { - $status = $user->wysiwyg_status; + // Default wysiwyg editor status information is only required on forms, so we + // do not pre-emptively load and attach this information on every user_load(). + if (!isset($user->wysiwyg_status)) { + $user->wysiwyg_status = array(); + $result = db_query("SELECT format, status FROM {wysiwyg_user} WHERE uid = %d", $user->uid); + while ($row = db_fetch_object($result)) { + $user->wysiwyg_status[$row->format] = $row->status; + } + } + + if (!empty($profile->settings['user_choose']) && isset($user->wysiwyg_status[$profile->format])) { + $status = $user->wysiwyg_status[$profile->format]; } else { $status = isset($profile->settings['default']) ? $profile->settings['default'] : TRUE; } - return $status; + return (bool) $status; } /**