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 14:07:13.000000000 +0200 @@ -30,44 +30,45 @@ function preferred_format_help($path, $a } /** - * Implementation of hook_perm(). - */ -function preferred_format_perm() { - return array('can 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( + 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. + 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. $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( @@ -78,18 +79,19 @@ function preferred_format_user($op, &$ed ); } } - + 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,39 +108,35 @@ 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 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']; - $form_field = 'body_field'; - } - elseif ($form['#id'] == 'comment-form' && $form['cid']['#value'] == '' && is_array($form['comment_filter']['format'])) { - $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)) { - unset($form[$form_field]['format'][$key]['#default_value']); - - if ($key == $preferred_format) { - $form[$form_field]['format'][$key]['#default_value'] = $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']; + $form_field = 'body_field'; + } + elseif ($form['#id'] == 'comment-form' && $form['cid']['#value'] == '' && is_array($form['comment_filter']['format'])) { + $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)) { + unset($form[$form_field]['format'][$key]['#default_value']); + + if ($key == $preferred_format) { + $form[$form_field]['format'][$key]['#default_value'] = $preferred_format; } } - - $form['has_preferred_input_format'] = array( - '#type' => 'value', - '#value' => 1, - ); - } + + $form['has_preferred_input_format'] = array( + '#type' => 'value', + '#value' => 1, + ); } } @@ -164,13 +162,8 @@ 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); - } - else { - return $format; - } + + return ($format) ? $format : variable_get('filter_default_format', 1); } /** @@ -184,7 +177,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,31 +210,31 @@ 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 - // identified by account. - if ($account != NULL) { + // This because filter_formats() only returns the formats for the currently + // logged in user. + if (!is_null($account)) { $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) { + // This because filter_formats() only returns the formats for the currently + // logged in user. + if (!is_null($account)) { $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