@@ -74,6 +74,45 @@ '#default_value' => variable_get($code .'_b', ''), '#description' => t('Maximum number of characters allowed for the body field of this content type. Leave blank for an unlimited size.'), ); + $form['nodetypes'][$type]['comment'] = array( + '#type' => 'fieldset', + '#title' => t('comment settings for ').$name->name, + '#collapsible' => TRUE, + '#collapsed' => strlen(variable_get($code . '_comment_' .'_b', '')) == 0, + ); + $form['nodetypes'][$type]['comment'][$code . '_comment_' .'_b'] = array( + '#type' => 'textfield', + '#title' => t('Comment Maxlength'), + '#field_suffix' => t('characters'), + '#return_value' => 1, + '#default_value' => variable_get($code . '_comment_' .'_b', ''), + '#description' => t('Maximum number of characters allowed for the body field of comment for this content type. Leave blank for an unlimited size.'), + ); + $form['nodetypes'][$type]['comment'][$code . '_comment_' .'_resizable'] = array( + '#type' => 'checkbox', + '#title' => t('Comment Resizable ?'), + '#return_value' => 1, + '#default_value' => variable_get($code . '_comment_' .'_resizable', 1), + '#description' => t('Do you want to use drupal default resizable function on textarea ? default : yes.'), + ); + $form['nodetypes'][$type]['comment'][$code . '_comment_' .'_rows'] = array( + '#type' => 'textfield', + '#title' => t('Comment rows'), + '#field_suffix' => t('characters'), + '#return_value' => 1, + '#default_value' => variable_get($code . '_comment_' .'_rows', ''), + '#description' => t('Use only if textarea is not resizable. Number of rows'), + ); + $form['nodetypes'][$type]['comment'][$code . '_comment_' .'_cols'] = array( + '#type' => 'textfield', + '#title' => t('Comment cols'), + '#field_suffix' => t('characters'), + '#return_value' => 1, + '#default_value' => variable_get($code . '_comment_' .'_cols', ''), + '#description' => t('Use only if textarea is not resizable. Number of cols'), + ); + } return system_settings_form($form); @@ -108,9 +147,18 @@ return strlen(variable_get(MAXLENGTH_NODE_TYPE . _maxlength_node_type_from_id($nid) .'_b', '')) > 0; } } + if (arg(0) == 'comment') { + if (arg(1) == 'reply') { + $type = $type = _maxlength_node_type_from_id(arg(2)); + + return strlen(variable_get(MAXLENGTH_NODE_TYPE . $type . '_comment_' .'_b', '')) > 0; + } + } return FALSE; } @@ -160,7 +207,36 @@ $prefix = t('
Content limited to !limit characters, remaining: !remaining
', array('!limit' => $limit, '!remaining' => $remaining)); } + if ($element['#name'] == 'comment') { + $path = drupal_get_path('module', 'maxlength'); + drupal_add_js($path .'/maxlength.js'); + + $type = _maxlength_node_type_from_id(intval(arg(2))); + + $limit = intval(variable_get(MAXLENGTH_NODE_TYPE . $type . '_comment_' .'_b', '')); + + $remaining = $limit - drupal_strlen($element['#value']); + + if ($remaining < 0) { + drupal_set_message( + t('%body_field_label truncated to %limit characters!', + array( + '%body_field_label' => $element['#title'], + '%limit' => $limit) + ), + 'error' + ); + + $element['#value'] = drupal_substr($element['#value'], 0, $limit); + $remaining = 0; + } + + $element['#attributes']['onchange'] = 'maxlength_limit(this, '. $limit .');'; + $element['#attributes']['onkeyup'] = 'maxlength_limit(this, '. $limit .');'; + + $prefix = t('
Comment is limited to !limit characters, remaining: !remaining
', array('!limit' => $limit, '!remaining' => $remaining)); + } return theme_textarea($element) . $prefix; } @@ -195,7 +271,38 @@ } } } + if ($form_id == 'comment_form') { + $type = _maxlength_node_type_from_id($form['nid']['#value']); + $rows = variable_get(MAXLENGTH_NODE_TYPE . $type . '_comment_' .'_rows', ''); + $cols = variable_get(MAXLENGTH_NODE_TYPE . $type . '_comment_' .'_cols', ''); + $resizable = variable_get(MAXLENGTH_NODE_TYPE . $type . '_comment_' .'_resizable', 1); + if($resizable != 1) { + $form['comment_filter']['comment']['#resizable'] = false ; + if ($rows > 0) { + $form['comment_filter']['comment']['#rows'] = $rows; + } + if ($cols > 0) { + $form['comment_filter']['comment']['#cols'] = $cols; + } + } + } +} /** * Implemenation of hook_nodeapi().