Binary files old/.DS_Store and new/.DS_Store differ diff -upN old/preferred_format.module new/preferred_format.module --- old/preferred_format.module 2008-03-26 20:48:44.000000000 +0100 +++ new/preferred_format.module 2008-07-20 11:24:51.000000000 +0200 @@ -33,63 +33,75 @@ function preferred_format_help($path, $a * Implementation of hook_perm(). */ function preferred_format_perm() { - return array('can set preferred format'); + return array('set preferred format'); } /** * Implementation of hook_user(). */ -function preferred_format_user($op, &$edit, &$account) { +function preferred_format_user($op, &$edit, &$account, $category = NULL) { global $user; + switch ($op) { + case 'categories': + return array( + 'preferred_format' => array( + 'name' => 'preferred_format', + 'title' => t('Preferred filter format'), + 'weight' => 5, + ) + ); + break; + case 'form' : - // Add the user can choose it's own preferred input format, - // append the user edit form with the necessary form field. - if (user_access('can set preferred format')) { - // Get a list of all input formats available to the user. - $formats = _preferred_format_get_available_input_formats($account); - - // Get a list of all node types which the user is allowed to create. - $types = _preferred_format_get_available_node_types($account); - - $form['preferred_format'] = array( - '#tree' => TRUE, - '#type' => 'fieldset', - '#title' => t('Preferred input formats'), - '#description' => t('Choose the preferred input format you like to use for each content type.'), - '#collapsible' => TRUE, - '#weight' => 9, - ); - - $form['preferred_format']['comments'] = array( - '#type' => 'select', - '#title' => t('Preferred input format for comments'), - '#options' => $formats, - '#default_value' => _preferred_format_load($account->uid, ''), - ); - - if (count($types)) { - foreach ($types as $key => $name) { - $form['preferred_format']['node_types'][$key] = array( - '#type' => 'select', - '#title' => t('Preferred input format for !nodetype', array('!nodetype' => $name)), - '#options' => $formats, - '#default_value' => _preferred_format_load($account->uid, $key), - ); + if ($category == 'preferred_format') { + // Add the user can choose it's own preferred input format, + // append the user edit form with the necessary form field. + if (user_access('set preferred format')) { + // Get a list of all input formats available to the user. + $formats = _preferred_format_get_available_input_formats($account); + + // Get a list of all node types which the user is allowed to create. + $types = _preferred_format_get_available_node_types($account); + + $form['preferred_format'] = array( + '#tree' => TRUE, + '#type' => 'fieldset', + '#title' => t('Preferred input formats'), + '#description' => t('Choose the preferred input format you like to use for each content type.'), + ); + + $form['preferred_format']['comments'] = array( + '#type' => 'select', + '#title' => t('Preferred input format for comments'), + '#options' => $formats, + '#default_value' => _preferred_format_load($account->uid, ''), + ); + + if (count($types)) { + foreach ($types as $key => $name) { + $form['preferred_format']['node_types'][$key] = array( + '#type' => 'select', + '#title' => t('Preferred input format for !nodetype', array('!nodetype' => $name)), + '#options' => $formats, + '#default_value' => _preferred_format_load($account->uid, $key), + ); + } } + + return $form; } - - return $form; } break; - case 'update' : + + case 'update' : // Store preferred format settings for comments. if (isset($edit['preferred_format']['comments'])) { // Store preferred input format settings of user for comments. db_query("DELETE FROM {preferred_format} WHERE uid = %d AND node_type = ''", $account->uid); db_query("INSERT INTO {preferred_format} (uid, format_id, node_type) VALUES (%d, %d, '')", $account->uid, $edit['preferred_format']['comments']); } - + // If available, store preferred input format settings for each node type. if (count($edit['preferred_format']['node_types'])) { foreach ($edit['preferred_format']['node_types'] as $node_type => $format_id) { @@ -106,9 +118,9 @@ function preferred_format_user($op, &$ed */ function preferred_format_form_alter(&$form, &$form_state, $form_id) { global $user; - + // Check whether the user is allowed to have a preferred input format. - if (user_access('can set preferred format')) { + if (user_access('set preferred format')) { // If on an node add form or a comment add form. if ($form['#id'] == 'node-form' && $form['nid']['#value'] == '' && is_array($form['body_field']['format'])) { $type = $form['type']['#value']; @@ -118,10 +130,10 @@ function preferred_format_form_alter(&$f $type = ''; $form_field = 'comment_filter'; } - + if (isset($form_field)) { $preferred_format = _preferred_format_load($user->uid, $type); - + // Unselect all input formats and set the preferred input format. foreach ($form[$form_field]['format'] as $key => $value) { if (intval($key)) { @@ -137,7 +149,6 @@ function preferred_format_form_alter(&$f '#type' => 'value', '#value' => 1, ); - } } } @@ -164,7 +175,7 @@ function preferred_format_nodeapi(&$node */ function _preferred_format_load($uid, $type = '') { $format = db_result(db_query("SELECT format_id FROM {preferred_format} WHERE uid = %d AND node_type = '%s'", $uid, $type)); - + if ($format == NULL) { return variable_get('filter_default_format', 1); } @@ -184,7 +195,7 @@ function _preferred_format_load($uid, $t */ function _preferred_format_get_available_node_types($account = NULL) { $types = node_get_types('names'); - + if (count($types)) { if (user_access('administer nodes', $account)) { // All node types are available for this user. @@ -217,7 +228,7 @@ function _preferred_format_get_available */ function _preferred_format_get_available_input_formats($account = NULL) { global $user; - + // Ugly hack needed to get the list of filters for a given user. // This because filter_formats() only returns the formats. // Temporary store current user and set user to be the user @@ -226,22 +237,22 @@ function _preferred_format_get_available $user_temp = $user; $user = $account; } - + $formats = filter_formats(); - + // Ugly hack needed to get the list of filters for a given user. // This because filter_formats() only returns the formats. // Switching back to the original current user. if ($account != NULL) { $user = $user_temp; } - + $format_list = array(); if (count($formats)) { foreach ($formats as $key => $format) { $format_list[$key] = $format->name; } } - + return $format_list; } \ No newline at end of file Common subdirectories: old/translations and new/translations