? 2
? forms.patch
? forms.patch.txt
? forms.tar.bz2
? scratch
? includes/form.inc
? includes/legacy.inc
? sites/forms.drupal.dev
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.476
diff -u -r1.476 common.inc
--- includes/common.inc 31 Aug 2005 18:37:30 -0000 1.476
+++ includes/common.inc 14 Sep 2005 19:55:40 -0000
@@ -489,38 +489,6 @@
}
/**
- * An unchecked checkbox is not present in $_POST so we fix it here by
- * proving a default value of 0. Also, with form_checkboxes() we expect
- * an array, but HTML does not send the empty array. This is also taken
- * care off.
- */
-function fix_checkboxes() {
- if (isset($_POST['form_array'])) {
- $_POST['edit'] = _fix_checkboxes($_POST['edit'], $_POST['form_array'], array());
- }
- if (isset($_POST['form_zero'])) {
- $_POST['edit'] = _fix_checkboxes($_POST['edit'], $_POST['form_zero'], 0);
- }
-}
-
-function _fix_checkboxes($array1, $array2, $value) {
- if (is_array($array2) && count($array2)) {
- foreach ($array2 as $k => $v) {
- if (is_array($v) && count($v)) {
- $array1[$k] = _fix_checkboxes($array1[$k], $v, $value);
- }
- else if (!isset($array1[$k])) {
- $array1[$k] = $value;
- }
- }
- }
- else {
- $array1 = $value;
- }
- return $array1;
-}
-
-/**
* @name Conversion
* @{
* Converts data structures to different types.
@@ -559,6 +527,41 @@
return $array;
}
+
+/**
+ * Apply a user function recursively to every member of an array
+ *
+ * Taken from PHP Compat package in PEAR.
+ */
+if (!function_exists('array_walk_recursive')) {
+ function array_walk_recursive(&$input, $funcname) {
+ if (!is_callable($funcname)) {
+ if (is_array($funcname)) {
+ $funcname = $funcname[0] . '::' . $funcname[1];
+ }
+ user_error('array_walk_recursive() Not a valid callback ' . $user_func, E_USER_WARNING);
+ return;
+ }
+ if (!is_array($input)) {
+ user_error('array_walk_recursive() The argument should be an array', E_USER_WARNING);
+ return;
+ }
+ $args = func_get_args();
+ foreach ($input as $key => $item) {
+ if (is_array($item)) {
+ array_walk_recursive($item, $funcname, $args);
+ $input[$key] = $item;
+ } else {
+ $args[0] = &$item;
+ $args[1] = &$key;
+ call_user_func_array($funcname, $args);
+ $input[$key] = $item;
+ }
+ }
+ }
+}
+
+
/**
* @} End of "Conversion".
*/
@@ -1009,552 +1012,6 @@
* @} End of "defgroup format".
*/
-/**
- * @defgroup form Form generation
- * @{
- * Functions to enable output of HTML forms and form elements.
- *
- * Drupal uses these functions to achieve consistency in its form presentation,
- * while at the same time simplifying code and reducing the amount of HTML that
- * must be explicitly generated by modules.
- */
-
-/**
- * Generate a form from a set of form elements.
- *
- * @param $form
- * An HTML string containing one or more form elements.
- * @param $method
- * The query method to use ("post" or "get").
- * @param $action
- * The URL to send the form contents to, if not the current page.
- * @param $attributes
- * An associative array of attributes to add to the form tag.
- * @result
- * An HTML string with the contents of $form wrapped in a form tag.
- */
-function form($form, $method = 'post', $action = NULL, $attributes = NULL) {
- if (!$action) {
- $action = request_uri();
- }
- // Anonymous div to satisfy XHTML compliancy.
- return '
\n";
-}
-
-/**
- * File an error against the form element with the specified name.
- */
-function form_set_error($name, $message) {
- $GLOBALS['form'][$name] = $message;
- drupal_set_message($message, 'error');
-}
-
-/**
- * Return an associative array of all errors.
- */
-function form_get_errors() {
- if (array_key_exists('form', $GLOBALS)) {
- return $GLOBALS['form'];
- }
-}
-
-/**
- * Return the error message filed against the form with the specified name.
- */
-function _form_get_error($name) {
- if (array_key_exists('form', $GLOBALS)) {
- return $GLOBALS['form'][$name];
- }
-}
-
-function _form_get_class($name, $required, $error) {
- return $name. ($required ? ' required' : '') . ($error ? ' error' : '');
-}
-
-/**
- * Format a general form item.
- *
- * @param $title
- * The label for the form item.
- * @param $value
- * The contents of the form item.
- * @param $description
- * Explanatory text to display after the form item.
- * @param $id
- * A unique identifier for the form item.
- * @param $required
- * Whether the user must fill in this form element before submitting the form.
- * @param $error
- * An error message to display alongside the form element.
- * @return
- * A themed HTML string representing the form item.
- */
-function form_item($title, $value, $description = NULL, $id = NULL, $required = FALSE, $error = FALSE) {
- return theme('form_element', $title, $value, $description, $id, $required, $error);
-}
-
-/**
- * Format a group of form items.
- *
- * @param $legend
- * The label for the form item group.
- * @param $group
- * The form items within the group, as an HTML string.
- * @param $description
- * Explanatory text to display after the form item group.
- * @param $attributes
- * An associative array of HTML attributes to add to the fieldset tag.
- * @return
- * A themed HTML string representing the form item group.
- */
-function form_group($legend, $group, $description = NULL, $attributes = NULL) {
- return '\n";
-}
-
-/**
- * Format a group of form items.
- *
- * @param $legend
- * The label for the form item group.
- * @param $group
- * The form items within the group, as an HTML string.
- * @param $collapsed
- * A boolean value decided whether the group starts collapsed.
- * @param $description
- * Explanatory text to display after the form item group.
- * @param $attributes
- * An associative array of HTML attributes to add to the fieldset tag.
- * @return
- * A themed HTML string representing the form item group.
- */
-function form_group_collapsible($legend, $group, $collapsed = FALSE, $description = NULL, $attributes = NULL) {
- drupal_add_js('misc/collapse.js');
-
- $attributes['class'] .= ' collapsible';
- if ($collapsed) {
- $attributes['class'] .= ' collapsed';
- }
-
- return '\n";
-}
-
-/**
- * Format a radio button.
- *
- * @param $title
- * The label for the radio button.
- * @param $name
- * The internal name used to refer to the button.
- * @param $value
- * The value that the form element takes on when selected.
- * @param $checked
- * Whether the button will be initially selected when the page is rendered.
- * @param $description
- * Explanatory text to display after the form item.
- * @param $attributes
- * An associative array of HTML attributes to add to the button.
- * @param $required
- * Whether the user must select this radio button before submitting the form.
- * @return
- * A themed HTML string representing the radio button.
- */
-function form_radio($title, $name, $value = 1, $checked = FALSE, $description = NULL, $attributes = NULL, $required = FALSE) {
- $element = '';
- if (!is_null($title)) {
- $element = '';
- }
- return theme('form_element', NULL, $element, $description, $name, $required, _form_get_error($name));
-}
-
-/**
- * Format a set of radio buttons.
- *
- * @param $title
- * The label for the radio buttons as a group.
- * @param $name
- * The internal name used to refer to the buttons.
- * @param $value
- * The currently selected radio button's key.
- * @param $options
- * An associative array of buttons to display. The keys in this array are
- * button values, while the values are the labels to display for each button.
- * @param $description
- * Explanatory text to display after the form item.
- * @param $required
- * Whether the user must select a radio button before submitting the form.
- * @param $attributes
- * An associative array of HTML attributes to add to each button.
- * @return
- * A themed HTML string representing the radio button set.
- */
-function form_radios($title, $name, $value, $options, $description = NULL, $required = FALSE, $attributes = NULL) {
- if (count($options) > 0) {
- $choices = '';
- foreach ($options as $key => $choice) {
- $choices .= ' ';
- }
- return theme('form_element', $title, $choices, $description, NULL, $required, _form_get_error($name));
- }
-}
-
-/**
- * Format a checkbox.
- *
- * @param $title
- * The label for the checkbox.
- * @param $name
- * The internal name used to refer to the button.
- * @param $value
- * The value that the form element takes on when selected.
- * @param $checked
- * Whether the button will be initially selected when the page is rendered.
- * @param $description
- * Explanatory text to display after the form item.
- * @param $attributes
- * An associative array of HTML attributes to add to the button.
- * @param $required
- * Whether the user must check this box before submitting the form.
- * @return
- * A themed HTML string representing the checkbox.
- */
-function form_checkbox($title, $name, $value = 1, $checked = FALSE, $description = NULL, $attributes = NULL, $required = FALSE) {
- $element = '';
- if (!is_null($title)) {
- $element = '';
- }
- return form_hidden($name, 1, 'form_zero') . theme('form_element', NULL, $element, $description, $name, $required, _form_get_error($name));
-}
-
-/**
- * Format a set of checkboxes.
- *
- * @param $title
- * The label for the checkboxes as a group.
- * @param $name
- * The internal name used to refer to the buttons.
- * @param $values
- * A linear array of keys of the initially checked boxes.
- * @param $options
- * An associative array of buttons to display. The keys in this array are
- * button values, while the values are the labels to display for each button.
- * @param $description
- * Explanatory text to display after the form item.
- * @param $attributes
- * An associative array of HTML attributes to add to each button.
- * @param $required
- * Whether the user must check a box before submitting the form.
- * @return
- * A themed HTML string representing the checkbox set.
- */
-function form_checkboxes($title, $name, $values, $options, $description = NULL, $attributes = NULL, $required = FALSE) {
- if (count($options) > 0) {
- if (!isset($values) || $values == 0) {
- $values = array();
- }
- $choices = '';
- foreach ($options as $key => $choice) {
- $choices .= ' ';
- }
- return form_hidden($name, 1, 'form_array') . theme('form_element', $title, $choices, $description, NULL, $required, _form_get_error($name));
- }
-}
-
-/**
- * Format a single-line text field.
- *
- * @param $title
- * The label for the text field.
- * @param $name
- * The internal name used to refer to the field.
- * @param $value
- * The initial value for the field at page load time.
- * @param $size
- * A measure of the visible size of the field (passed directly to HTML).
- * @param $maxlength
- * The maximum number of characters that may be entered in the field.
- * @param $description
- * Explanatory text to display after the form item.
- * @param $attributes
- * An associative array of HTML attributes to add to the form item.
- * @param $required
- * Whether the user must enter some text in the field.
- * @return
- * A themed HTML string representing the field.
- */
-function form_textfield($title, $name, $value, $size, $maxlength, $description = NULL, $attributes = NULL, $required = FALSE) {
- $size = $size ? ' size="'. $size .'"' : '';
- return theme('form_element', $title, '', $description, 'edit-'. $name, $required, _form_get_error($name));
-}
-
-/**
- * Format a single-line text field that uses Ajax for autocomplete.
- *
- * @param $title
- * The label for the text field.
- * @param $name
- * The internal name used to refer to the field.
- * @param $value
- * The initial value for the field at page load time.
- * @param $size
- * A measure of the visible size of the field (passed directly to HTML).
- * @param $maxlength
- * The maximum number of characters that may be entered in the field.
- * @param $callback_path
- * A drupal path for the Ajax autocomplete callback.
- * @param $description
- * Explanatory text to display after the form item.
- * @param $attributes
- * An associative array of HTML attributes to add to the form item.
- * @param $required
- * Whether the user must enter some text in the field.
- * @return
- * A themed HTML string representing the field.
- */
-function form_autocomplete($title, $name, $value, $size, $maxlength, $callback_path, $description = NULL, $attributes = NULL, $required = FALSE) {
- drupal_add_js('misc/autocomplete.js');
-
- $size = $size ? ' size="'. $size .'"' : '';
-
- $output = theme('form_element', $title, '', $description, 'edit-'. $name, $required, _form_get_error($name));
- $output .= '';
-
- return $output;
-}
-
-/**
- * Format a single-line text field that does not display its contents visibly.
- *
- * @param $title
- * The label for the text field.
- * @param $name
- * The internal name used to refer to the field.
- * @param $value
- * The initial value for the field at page load time.
- * @param $size
- * A measure of the visible size of the field (passed directly to HTML).
- * @param $maxlength
- * The maximum number of characters that may be entered in the field.
- * @param $description
- * Explanatory text to display after the form item.
- * @param $attributes
- * An associative array of HTML attributes to add to the form item.
- * @param $required
- * Whether the user must enter some text in the field.
- * @return
- * A themed HTML string representing the field.
- */
-function form_password($title, $name, $value, $size, $maxlength, $description = NULL, $attributes = NULL, $required = FALSE) {
- $size = $size ? ' size="'. $size .'"' : '';
- return theme('form_element', $title, '', $description, 'edit-'. $name, $required, _form_get_error($name));
-}
-
-/**
- * Format a multiple-line text field.
- *
- * @param $title
- * The label for the text field.
- * @param $name
- * The internal name used to refer to the field.
- * @param $value
- * The initial value for the field at page load time.
- * @param $cols
- * The width of the field, in columns of text.
- * @param $rows
- * The height of the field, in rows of text.
- * @param $description
- * Explanatory text to display after the form item.
- * @param $attributes
- * An associative array of HTML attributes to add to the form item.
- * @param $required
- * Whether the user must enter some text in the field.
- * @return
- * A themed HTML string representing the field.
- */
-function form_textarea($title, $name, $value, $cols, $rows, $description = NULL, $attributes = NULL, $required = FALSE) {
- $cols = $cols ? ' cols="'. $cols .'"' : '';
- $pre = '';
- $post = '';
-
- // optionally plug in a WYSIWYG editor
- foreach (module_list() as $module_name) {
- if (module_hook($module_name, 'textarea')) {
- $pre .= module_invoke($module_name, 'textarea', 'pre', $name);
- $post .= module_invoke($module_name, 'textarea', 'post', $name);
- }
- }
-
- return theme('form_element', $title, $pre .''. $post, $description, 'edit-'. $name, $required, _form_get_error($name));
-}
-
-/**
- * Format a dropdown menu or scrolling selection box.
- *
- * @param $title
- * The label for the form element.
- * @param $name
- * The internal name used to refer to the form element.
- * @param $value
- * The key of the currently selected item, or a linear array of keys of all the
- * currently selected items if multiple selections are allowed.
- * @param $options
- * An associative array of buttons to display. The keys in this array are
- * button values, while the values are the labels to display for each button.
- * @param $description
- * Explanatory text to display after the form item.
- * @param $extra
- * Additional HTML to inject into the select element tag.
- * @param $multiple
- * Whether the user may select more than one item.
- * @param $required
- * Whether the user must select a value before submitting the form.
- * @return
- * A themed HTML string representing the form element.
- *
- * It is possible to group options together; to do this, change the format of
- * $options to an associative array in which the keys are group labels, and the
- * values are associative arrays in the normal $options format.
- */
-function form_select($title, $name, $value, $options, $description = NULL, $extra = 0, $multiple = FALSE, $required = FALSE) {
- $select = '';
- foreach ($options as $key => $choice) {
- if (is_array($choice)) {
- $select .= '';
- }
- else {
- $select .= '';
- }
- }
- return theme('form_element', $title, '', $description, 'edit-'. $name, $required, _form_get_error($name));
-}
-
-/**
- * Format a file upload field.
- *
- * @param $title
- * The label for the file upload field.
- * @param $name
- * The internal name used to refer to the field.
- * @param $size
- * A measure of the visible size of the field (passed directly to HTML).
- * @param $description
- * Explanatory text to display after the form item.
- * @param $required
- * Whether the user must upload a file to the field.
- * @return
- * A themed HTML string representing the field.
- *
- * For assistance with handling the uploaded file correctly, see the API
- * provided by file.inc.
- */
-function form_file($title, $name, $size, $description = NULL, $required = FALSE) {
- return theme('form_element', $title, '\n", $description, 'edit-'. $name, $required, _form_get_error($name));
-}
-
-/**
- * Store data in a hidden form field.
- *
- * @param $name
- * The internal name used to refer to the field.
- * @param $value
- * The stored data.
- * @param $edit
- * The array name to prefix to the $name.
- * @param $attributes
- * An array of HTML attributes for the input tag.
- * @return
- * A themed HTML string representing the hidden field.
- *
- * This function can be useful in retaining information between page requests,
- * but be sure to validate the data on the receiving page as it is possible for
- * an attacker to change the value before it is submitted.
- */
-function form_hidden($name, $value, $edit = 'edit', $attributes = NULL) {
- return '\n";
-}
-
-/**
- * Format an action button.
- *
- * @param $value
- * Both the label for the button, and the value passed to the target page
- * when this button is clicked.
- * @param $name
- * The internal name used to refer to the button.
- * @param $type
- * What type to pass to the HTML input tag.
- * @param $attributes
- * An associative array of HTML attributes to add to the form item.
- * @return
- * A themed HTML string representing the button.
- */
-function form_button($value, $name = 'op', $type = 'submit', $attributes = NULL) {
- return '\n";
-}
-
-/**
- * Format a form submit button.
- *
- * @param $value
- * Both the label for the button, and the value passed to the target page
- * when this button is clicked.
- * @param $name
- * The internal name used to refer to the button.
- * @param $attributes
- * An associative array of HTML attributes to add to the form item.
- * @return
- * A themed HTML string representing the button.
- */
-function form_submit($value, $name = 'op', $attributes = NULL) {
- return form_button($value, $name, 'submit', $attributes);
-}
-
-/**
- * Format a weight selection menu.
- *
- * @param $title
- * The label for the form element.
- * @param $name
- * The internal name used to refer to the form element.
- * @param $value
- * The selected weight value at page load time.
- * @param $delta
- * The largest in absolute value the weight can be. For example, if set to 10,
- * weights could range from -10 to 10 inclusive.
- * @param $description
- * Explanatory text to display after the form item.
- * @param $extra
- * Additional HTML to inject into the select element tag.
- * @return
- * A themed HTML string representing the form element.
- */
-function form_weight($title = NULL, $name = 'weight', $value = 0, $delta = 10, $description = NULL, $extra = 0) {
- for ($n = (-1 * $delta); $n <= $delta; $n++) {
- $weights[$n] = $n;
- }
-
- return form_select($title, $name, $value, $weights, $description, $extra);
-}
-
-/**
- * Remove invalid characters from an HTML ID attribute string
- *
- * @param $id
- * The ID to clean
- * @return
- * The cleaned ID
- */
-function form_clean_id($id = NULL) {
- $id = str_replace('][', '-', $id);
- return $id;
-}
-
-/**
- * @} End of "defgroup form".
- */
/**
* Generate an internal Drupal URL.
@@ -1915,6 +1372,8 @@
require_once './includes/file.inc';
require_once './includes/unicode.inc';
require_once './includes/image.inc';
+ require_once './includes/form.inc';
+ require_once './includes/legacy.inc';
// Set the Drupal custom error handler.
set_error_handler('error_handler');
// Emit the correct charset HTTP header.
Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.258
diff -u -r1.258 theme.inc
--- includes/theme.inc 8 Sep 2005 19:17:34 -0000 1.258
+++ includes/theme.inc 14 Sep 2005 19:55:41 -0000
@@ -959,55 +959,6 @@
}
/**
- * Output a confirmation form
- *
- * This function outputs a complete form for confirming an action. A link is
- * offered to go back to the item that is being changed in case the user changes
- * his/her mind.
- *
- * You should use $_POST['edit'][$name] (where $name is usually 'confirm') to
- * check if the confirmation was successful.
- *
- * @param $question
- * The question to ask the user (e.g. "Are you sure you want to delete the
- * block foo?").
- * @param $path
- * The page to go to if the user denies the action.
- * @param $description
- * Additional text to display (defaults to "This action cannot be undone.").
- * @param $yes
- * A caption for the button which confirms the action (e.g. "Delete",
- * "Replace", ...).
- * @param $no
- * A caption for the link which denies the action (e.g. "Cancel").
- * @param $extra
- * Additional HTML to inject into the form, for example form_hidden()s.
- * @param $name
- * The internal name used to refer to the confirmation item.
- * @return
- * A themed HTML string representing the form.
- */
-function theme_confirm($question, $path, $description = NULL, $yes = NULL, $no = NULL, $extra = NULL, $name = 'confirm') {
- drupal_set_title($question);
-
- if (is_null($description)) {
- $description = t('This action cannot be undone.');
- }
-
- $output .= '
',
+ form_weight(NULL, $node->nid .'][weight', $node->weight, 15),
+ l(t('view'), 'node/'. $node->nid),
+ l(t('edit'), 'node/'. $node->nid .'/edit'),
+ l(t('delete'), 'node/'.$node->nid.'/delete'));
}
function book_admin_edit_book($nid, $depth = 1) {
@@ -989,15 +1017,15 @@
function book_admin_edit($nid, $depth = 0) {
$node = node_load($nid);
if ($node->nid) {
+ drupal_set_title(check_plain($node->title));
+
$header = array(t('Title'), t('Weight'), array('data' => t('Operations'), 'colspan' => '3'));
$rows[] = book_admin_edit_line($node);
$rows = array_merge($rows, book_admin_edit_book($nid));
- $output .= theme('table', $header, $rows);
- $output .= form_submit(t('Save book pages'));
+ $form['save'] = array(type => 'submit', value => t('Save book pages'));
- drupal_set_title(check_plain($node->title));
- return form($output);
+ return theme('table', $header, $rows) . $form;
}
else {
drupal_not_found();
/**
Index: modules/contact.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/contact.module,v
retrieving revision 1.22
diff -u -r1.22 contact.module
--- modules/contact.module 25 Aug 2005 21:14:16 -0000 1.22
+++ modules/contact.module 14 Sep 2005 19:55:49 -0000
@@ -58,7 +58,12 @@
* Implementation of hook_settings().
*/
function contact_settings() {
- return form_textarea(t('Additional information'), 'contact_form_information', variable_get('contact_form_information', t('You can leave us a message using the contact form below.')), 60, 5, t('Information to show on the contact page. Can be anything from submission guidelines to your postal address or telephone number.', array('%form' => url('contact'))));
+ $form['contact_form_information'] = array(
+ type => 'textarea', title => t('Additional information'), cols => 60, rows => 5,
+ default_value => ariable_get('contact_form_information', t('You can leave us a message using the contact form below.')),
+ description => t('Information to show on the contact page. Can be anything from submission guidelines to your postal address or telephone number.', array('%form' => url('contact')))
+ );
+ return $form;
}
/**
Index: modules/drupal.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/drupal.module,v
retrieving revision 1.106
diff -u -r1.106 drupal.module
--- modules/drupal.module 25 Aug 2005 21:14:16 -0000 1.106
+++ modules/drupal.module 14 Sep 2005 19:55:49 -0000
@@ -33,19 +33,28 @@
*/
function drupal_settings() {
// Check if all required fields are present for the Drupal directory
- if ((variable_get('site_name', 'drupal') == 'drupal') || (variable_get('site_name', 'drupal') == ''))
+ if ((variable_get('site_name', 'drupal') == 'drupal') || (variable_get('site_name', 'drupal') == '')) {
form_set_error('drupal_directory', t('You must set the name of your site on the administer » settings page.', array('%url' => url('admin/settings'))));
- else if (variable_get('site_mail', ini_get('sendmail_from')) == '')
+ }
+ else if (variable_get('site_mail', ini_get('sendmail_from')) == '') {
form_set_error('drupal_directory', t('You must set an e-mail address for your site on the administer » settings page.', array('%url' => url('admin/settings'))));
- else if (variable_get('site_slogan', '') == '')
+ }
+ else if (variable_get('site_slogan', '') == '') {
form_set_error('drupal_directory', t('You must set your site slogan on the administer » settings page.', array('%url' => url('admin/settings'))));
- else if (variable_get('site_mission', '') == '')
+ }
+ else if (variable_get('site_mission', '') == '') {
form_set_error('drupal_directory', t('You must set your site mission on the administer » settings page.' , array('%url' => url('admin/settings'))));
+ }
+
+ $form['drupal_server'] = array(type => 'textfield', title => t('Drupal XML-RPC server'), default_value => variable_get('drupal_server', 'http://www.drupal.org/xmlrpc.php'), size => 60, maxlength => 128, description => t('The URL of your root Drupal XML-RPC server.'));
- $output = form_textfield(t('Drupal XML-RPC server'), 'drupal_server', variable_get('drupal_server', 'http://www.drupal.org/xmlrpc.php'), 60, 128, t('The URL of your root Drupal XML-RPC server.'));
- $output .= form_radios(t('Drupal directory'), 'drupal_directory', variable_get('drupal_directory', 0), array(t('Disabled'), t('Enabled')), t("If enabled, your Drupal site will make itself known to the Drupal directory at the specified Drupal XML-RPC server. For this to work properly, you must set your site's name, e-mail address, slogan and mission statement. When the \"Drupal XML-RPC server\" field is set to \"%drupal-xml-rpc\", your web site will get listed on the Drupal sites page. Requires the cron feature to be enabled.", array("%drupal-xml-rpc" => "http://www.drupal.org/xmlrpc.php", "%drupal-sites" => "http://www.drupal.org/drupal-sites/")));
+ $form['drupal_directory'] = array(
+ type => 'radios', title => t('Drupal directory'), default_value => variable_get('drupal_directory', 0),
+ options => array(t('Disabled'), t('Enabled')),
+ description => t("If enabled, your Drupal site will make itself known to the Drupal directory at the specified Drupal XML-RPC server. For this to work properly, you must set your site's name, e-mail address, slogan and mission statement. When the \"Drupal XML-RPC server\" field is set to \"%drupal-xml-rpc\", your web site will get listed on the Drupal sites page. Requires the cron feature to be enabled.", array("%drupal-xml-rpc" => "http://www.drupal.org/xmlrpc.php", "%drupal-sites" => "http://www.drupal.org/drupal-sites/"))
+ );
- return $output;
+ return $form;
}
/**
Index: modules/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter.module,v
retrieving revision 1.71
diff -u -r1.71 filter.module
--- modules/filter.module 25 Aug 2005 21:14:16 -0000 1.71
+++ modules/filter.module 14 Sep 2005 19:55:50 -0000
@@ -726,32 +726,26 @@
* @return
* HTML for the form element.
*/
-function filter_form($name = 'format', $value = FILTER_FORMAT_DEFAULT) {
+function filter_form($value = FILTER_FORMAT_DEFAULT) {
if ($value == FILTER_FORMAT_DEFAULT) {
$value = variable_get('filter_default_format', 1);
}
$formats = filter_formats();
$extra = l(t('More information about formatting options'), 'filter/tips');
-
+
+ $form['format'] = array(type => 'fieldset', title => t('Input format'), collapsible => TRUE, collapsed => TRUE);
if (count($formats) > 1) {
// Multiple formats available: display radio buttons with tips.
- $output = '';
foreach ($formats as $format) {
- $tips = _filter_tips($format->format, false);
-
- // TODO: get support for block-level radios so the is not output?
- $output .= '
';
+ return $output;
+}
+
+
/**
* Returns true if the user is allowed to access this format.
*/
Index: modules/forum.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum.module,v
retrieving revision 1.269
diff -u -r1.269 forum.module
--- modules/forum.module 8 Sep 2005 19:22:28 -0000 1.269
+++ modules/forum.module 14 Sep 2005 14:06:52 -0000
@@ -158,15 +158,10 @@
function _forum_confirm_delete($tid) {
$term = taxonomy_get_term($tid);
- $extra = form_hidden('tid', $tid);
- $output = theme('confirm',
- t('Are you sure you want to delete the forum %name?', array('%name' => theme('placeholder', $term->name))),
- 'admin/forums',
- t('Deleting a forum or container will delete all sub-forums as well. This action cannot be undone.'),
- t('Delete'),
- t('Cancel'),
- $extra);
- return $output;
+ $form['tid'] = array(type => 'hidden', value => $tid);
+
+ return confirm_form('forum_confirm_delete', $form, t('Are you sure you want to delete the forum %name?', array('%name' => theme('placeholder', $term->name))),
+ 'admin/forums', t('Deleting a forum or container will delete all sub-forums as well. This action cannot be undone.'), t('Delete'), t('Cancel'));
}
/**
@@ -175,20 +170,19 @@
* @param $edit Associative array containing a container term to be added or edited.
*/
function forum_form_container($edit = array()) {
- $form = form_textfield(t('Container name'), 'name', $edit['name'], 60, 64, t('The container name is used to identify related forums.'), NULL, TRUE);
- $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('The container description can give users more information about the forums it contains.'));
+ $form['name'] = array(title => t('Container name'), type => 'textfield', default_value => $edit['name'], size => 60, maxlength => 64, description => t('The container name is used to identify related forums.'), required => TRUE);
+ $form['description'] = array(type => 'textarea', title => t('Description'), default_value => $edit['description'], cols => 60, rows => 5, description => ('The container description can give users more information about the forums it contains.'));
+ $form['parent'][0] = _forum_parent_select($edit['tid'], t('Parent'), 'container');
+ $form['weight'] = array(type => 'weight', title => t('Weight'), delta => 10, description => t('When listing containers, those with with light (small) weights get listed before containers with heavier (larger) weights. Containers with equal weights are sorted alphabetically.'));
- $form .= _forum_parent_select($edit['tid'], t('Parent'), 'parent][', 'container');
- $form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('When listing containers, those with with light (small) weights get listed before containers with heavier (larger) weights. Containers with equal weights are sorted alphabetically.'));
-
- $form .= form_hidden('vid', _forum_get_vid());
- $form .= form_submit(t('Submit'));
+ $form['vid'] = array(type => 'hidden', value => _forum_get_vid());
+ $form['submit'] = array(type => 'submit', value => t('Submit'));
if ($edit['tid']) {
- $form .= form_submit(t('Delete'));
- $form .= form_hidden('tid', $edit['tid']);
+ $form['delete'] = array(type => 'submit', value => t('Delete'));
+ $form['tid'] = array(type => 'hidden', value => $edit['tid']);
}
- return form($form);
+ return drupal_get_form('forum_form_container', $form);
}
/**
@@ -197,20 +191,19 @@
* @param $edit Associative array containing a forum term to be added or edited.
*/
function forum_form_forum($edit = array()) {
- $form = form_textfield(t('Forum name'), 'name', $edit['name'], 60, 64, t('The forum name is used to identify related topic discussions.'), NULL, TRUE);
- $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('The forum description can give users more information about the discussion topics it contains.'));
-
- $form .= _forum_parent_select($edit['tid'], t('Parent'), 'parent][', 'forum');
- $form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('When listing forums, those with light (small) weights get listed before forums with heavier (larger) weights. Forums with equal weights are sorted alphabetically.'));
+ $form['name'] = array(type => 'textfield', title => t('Forum name'), default_value => $edit['name'], size => 60, maxlength => 64, description => t('The forum name is used to identify related discussions.'), required => TRUE);
+ $form['description'] = array(type => 'textarea', title => t('Description'), default_value => $edit['description'], cols => 60, rows => 5, description => ('The forum description can give users more information about the discussion topics it contains.'));
+ $form['parent'][0] = _forum_parent_select($edit['tid'], t('Parent'), 'forum');
+ $form['weight'] = array(type => 'weight', title => t('Weight'), delta => 10, description => t('When listing forums, those with with light (small) weights get listed before containers with heavier (larger) weights. Forums with equal weights are sorted alphabetically.'));
- $form .= form_hidden('vid', _forum_get_vid());
- $form .= form_submit(t('Submit'));
+ $form['vid'] = array(type => 'hidden', value => _forum_get_vid());
+ $form['submit' ] = array(type => 'submit', value => t('Submit'));
if ($edit['tid']) {
- $form .= form_submit(t('Delete'));
- $form .= form_hidden('tid', $edit['tid']);
+ $form['delete'] = array(type => 'submit', value => t('Delete'));
+ $form['tid'] = array(type => 'hidden', value => $edit['tid']);
}
- return form($form);
+ return drupal_get_form('forum_form_forum', $form);
}
/**
@@ -218,9 +211,9 @@
*
* @param $tid ID of the term which is being added or edited
* @param $title Title to display the select box with
- * @param $name Name to use in the forum
+ * @param $child_type Whether the child is forum or container
*/
-function _forum_parent_select($tid, $title, $name, $child_type) {
+function _forum_parent_select($tid, $title, $child_type) {
$parents = taxonomy_get_parents($tid);
if ($parents) {
@@ -255,7 +248,7 @@
$description = t('You may place your forum inside a parent container or forum, or at the top (root) level of your forum.');
}
- return form_select($title, $name, $parent, $options, $description, 0, FALSE, TRUE);
+ return array(type => 'select', title => $title, default_value => $parent, options => $options, description => $description, required => TRUE);
}
/**
@@ -320,15 +313,16 @@
function forum_admin_configure() {
system_settings_save();
- $output .= form_textfield(t('Forum icon path'), 'forum_icon_path', variable_get('forum_icon_path', ''), 30, 255, t('The path to the forum icons. Leave blank to disable icons. Don\'t add a trailing slash. Default icons are available in the "misc" directory. You may use images of whatever size you wish, but it is recommended to use 15x15 or 16x16. '));
+ $form = array();
+ $form['forum_icon_path'] = array(type => 'textarea', title => t('Forum icon path'), default_value => variable_get('forum_icon_path', ''), size => 30, maxlength => 255, description => t('The path to the forum icons. Leave blank to disable icons. Don\'t add a trailing slash. Default icons are available in the "misc" directory. You may use images of whatever size you wish, but it is recommended to use 15x15 or 16x16. '));
$number = drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 10000));
- $output .= form_select(t('Hot topic threshold'), 'forum_hot_topic', variable_get('forum_hot_topic', 15), $number, t('The number of posts a topic must have to be considered hot.'));
+ $form['forum_hot_topic'] = array(type => 'select', 'title' => t('Hot topic threshold'), default_value => variable_get('forum_hot_topic', 15), options => $number, description => t('The number of posts a topic must have to be considered hot.'));
$number = drupal_map_assoc(array(10, 25, 50, 75, 100));
- $output .= form_select(t('Topics per page'), 'forum_per_page', variable_get('forum_per_page', 25), $number, t('The default number of topics displayed per page; links to browse older messages are automatically being displayed.'));
+ $form['forum_per_page'] = array(type => select, title => t('Topics per page'), default_value => variable_get('forum_per_page', 25), options => $number, description => t('The default number of topics displayed per page; links to browse older messages are automatically being displayed.'));
$forder = array(1 => t('Date - newest first'), 2 => t('Date - oldest first'), 3 => t('Posts - most active first'), 4=> t('Posts - least active first'));
- $output .= form_radios(t('Default order'), 'forum_order', variable_get('forum_order', '1'), $forder, t('The default display order for topics.'));
+ $form['forum_order'] = array(type => 'radios', title => t('Default order'), default_value => variable_get('forum_order', '1'), value => $forder, description => t('The default display order for topics.'));
- return system_settings_form($output);
+ return drupal_get_form('forum_admin_configure', $form);
}
/**
@@ -354,8 +348,8 @@
return $blocks;
case 'configure':
- $output = form_select(t('Number of topics'), 'forum_block_num_'. $delta, variable_get('forum_block_num_'. $delta, '5'), drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)));
- return $output;
+ $form['forum_block_num_'. $delta] = array(type => 'select', title => t('Number of topics'), default_value => variable_get('forum_block_num_'. $delta, '5'), options => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)));
+ return $form;
case 'save':
variable_set('forum_block_num_'. $delta, $edit['forum_block_num_'. $delta]);
@@ -566,18 +560,19 @@
$node->taxonomy = array($node->tid);
}
- $output = implode('', taxonomy_node_form('forum', $node));
-
+ $form['taxonomy'] = taxonomy_node_form('forum', $node);
if ($node->nid) {
// if editing, give option to leave shadows
$shadow = (count(taxonomy_node_get_terms($node->nid)) > 1);
- $output .= form_checkbox(t('Leave shadow copy'), 'shadow', 1, $shadow, t('If you move this topic, you can leave a link in the old forum to the new forum.'));
+ $form['shadow'] = array(type => 'checkbox', 'title' => t('Leave shadow copy'), default_value => $shadow, description => t('If you move this topic, you can leave a link in the old forum to the new forum.'));
}
- $output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, '');
- $output .= filter_form('format', $node->format);
+ $form['body'] = array(
+ type => 'textarea', title => t('Body'), default_value => $node->body, required => TRUE
+ );
+ $form = array_merge($form, filter_form($node->format));
- return $output;
+ return $form;
}
/**
Index: modules/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node.module,v
retrieving revision 1.527
diff -u -r1.527 node.module
--- modules/node.module 2 Sep 2005 02:11:41 -0000 1.527
+++ modules/node.module 14 Sep 2005 19:55:54 -0000
@@ -6,6 +6,8 @@
* The core that allows content to be submitted to the site.
*/
+include_once 'includes/form.inc';
+
define('NODE_NEW_LIMIT', time() - 30 * 24 * 60 * 60);
/**
@@ -1295,121 +1297,92 @@
return $node;
}
+
/**
* Generate the node editing form.
*/
-function node_form($edit) {
- // Validate the node if we don't already know the errors.
+function node_form($node) {
if (!$edit->validated) {
$edit = node_validate($edit);
}
+ // Set the id of the top-level form tag
+ $form[attributes]['id'] = 'node-form';
+
// Prepend extra node form elements.
- $form = implode('', node_invoke_nodeapi($edit, 'form pre'));
+ $form = array_merge($form, node_invoke_nodeapi($node, 'form pre'));
+
+ /**
+ * Basic node information.
+ * These elements set the value property, making them immutable.
+ */
+ $form['uid'] = array(type => 'hidden', value => $node->uid);
+ $form['created'] = array(type => 'hidden', value => $node->created);
+ $form['changed'] = array(type => 'hidden', value => $node->changed);
+ $form['type'] = array(type => 'hidden', value => $node->type);
// Get the node-specific bits.
// We can't use node_invoke() because $param must be passed by reference.
- $function = node_get_base($edit) .'_form';
+ $function = _node_names('base', $node) .'_form';
$param = array();
if (function_exists($function)) {
- $form .= $function($edit, $param);
+ $node_form = $function($node, $param);
+ $form = array_merge($form, $function($node, $param));
}
// Append extra node form elements.
- $form .= implode('', node_invoke_nodeapi($edit, 'form post'));
-
- $output .= '
';
-
- // Add hidden 'op' variable, which specifies the default operation (Preview).
- $output .= '\n";
-
- // Add the admin-specific parts.
- if (user_access('administer nodes')) {
- $output .= '
';
+ return $output;
}
/**
@@ -1432,7 +1405,7 @@
$node[$field] = $_GET['edit'][$field];
}
}
- $output = node_form($node);
+ $output = node_form(array2object($node));
drupal_set_title(t('Submit %name', array('%name' => node_get_name($node))));
}
else {
Index: modules/page.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/page.module,v
retrieving revision 1.136
diff -u -r1.136 page.module
--- modules/page.module 30 Aug 2005 15:22:29 -0000 1.136
+++ modules/page.module 14 Sep 2005 14:07:06 -0000
@@ -68,15 +68,21 @@
*/
function page_form(&$node) {
if (function_exists('taxonomy_node_form')) {
- $output .= implode('', taxonomy_node_form('page', $node));
+ $form['taxonomy'] = taxonomy_node_form('blog', $node);
}
- $output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, '', NULL, TRUE);
- $output .= filter_form('format', $node->format);
+ $form['body'] = array(
+ type => 'textarea', title => t('Body'), default_value => $node->body, required => TRUE
+ );
+ $form = array_merge($form, filter_form($node->format));
- $output .= form_textarea(t('Log message'), 'log', $node->log, 60, 5, t('An explanation of the additions or updates being made to help other authors understand your motivations.'));
- return $output;
+ $form['log'] = array(
+ type => 'textarea', title => t('Log message'), default_value => $node->log, required => TRUE, rows => 5,
+ description => t('An explanation of the additions or updates being made to help other authors understand your motivations.')
+ );
+
+ return $form;
}
ndex: modules/story.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/story.module,v
retrieving revision 1.170
diff -u -r1.170 story.module
--- modules/story.module 29 Aug 2005 19:58:49 -0000 1.170
+++ modules/story.module 14 Sep 2005 19:55:54 -0000
@@ -67,16 +67,22 @@
* Implementation of hook_form().
*/
function story_form(&$node) {
- $output = '';
-
if (function_exists('taxonomy_node_form')) {
- $output .= implode('', taxonomy_node_form('story', $node));
+ $form['taxonomy'] = taxonomy_node_form('blog', $node);
}
- $output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, '', NULL, TRUE);
- $output .= filter_form('format', $node->format);
+ $form['body'] = array(
+ type => 'textarea', title => t('Body'), default_value => $node->body, required => TRUE
+ );
+ $form = array_merge($form, filter_form($node->format));
+
+
+ $form['log'] = array(
+ type => 'textarea', title => t('Log message'), default_value => $node->log, required => TRUE, rows => 5,
+ description => t('An explanation of the additions or updates being made to help other authors understand your motivations.')
+ );
- return $output;
+ return $form;
}
Index: modules/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system.module,v
retrieving revision 1.234
diff -u -r1.234 system.module
--- modules/system.module 13 Sep 2005 19:12:19 -0000 1.234
+++ modules/system.module 14 Sep 2005 19:55:56 -0000
@@ -50,6 +50,35 @@
}
/**
+ * Implementation of hook_elements().
+ */
+function system_elements() {
+ // Top level form
+ $type['form'] = array(method => 'POST', action => request_uri());
+
+ // Inputs
+ $type['checkbox'] = array(input => TRUE, return_value => 1);
+ $type['submit'] = array(input => TRUE, name => 'op', button_type => 'submit');
+ $type['button'] = array(input => TRUE, name => 'op', button_type => 'submit');
+ $type['textfield'] = array(input => TRUE, size => 60, maxlength => 70, autocomplete_path => FALSE);
+ $type['password'] = array(input => TRUE, size => 60, maxlength => 70);
+ $type['textarea'] = array(input => TRUE, cols => 60, rows => 20);
+ $type['radios'] = array(input => TRUE, process => 'expand_radios');
+ $type['radio'] = array(input => TRUE);
+ $type['checkboxes'] = array(input => TRUE, process => 'expand_checkboxes');
+ $type['checkbox'] = array(input => TRUE);
+ $type['select'] = array(input => TRUE);
+ $type['weight'] = array(input => TRUE);
+
+ // Form structure
+ $type['item'] = array();
+ $type['hidden'] = array(input => TRUE);
+ $type['markup'] = array(prefix => '', suffix => '');
+ $type['fieldset'] = array(collapsible => FALSE, collapsed => FALSE);
+ return $type;
+}
+
+/**
* Implementation of hook_menu().
*/
function system_menu($may_cache) {
@@ -180,63 +209,136 @@
function system_view_general() {
// General settings:
- $group = form_textfield(t('Name'), 'site_name', variable_get('site_name', 'drupal'), 60, 70, t('The name of this web site.'));
- $group .= form_textfield(t('E-mail address'), 'site_mail', variable_get('site_mail', ini_get('sendmail_from')), 60, 128, t('A valid e-mail address for this website, used by the auto-mailer during registration, new password requests, notifications, etc.'));
- $group .= form_textfield(t('Slogan'), 'site_slogan', variable_get('site_slogan', ''), 60, 128, t('The slogan of this website. Some themes display a slogan when available.'));
- $group .= form_textarea(t('Mission'), 'site_mission', variable_get('site_mission', ''), 60, 5, t('Your site\'s mission statement or focus.'));
- $group .= form_textarea(t('Footer message'), 'site_footer', variable_get('site_footer', ''), 60, 5, t('This text will be displayed at the bottom of each page. Useful for adding a copyright notice to your pages.'));
- $group .= form_textfield(t('Anonymous user'), 'anonymous', variable_get('anonymous', 'Anonymous'), 60, 70, t('The name used to indicate anonymous users.'));
- $group .= form_textfield(t('Default front page'), 'site_frontpage', variable_get('site_frontpage', 'node'), 60, 70, t('The home page displays content from this relative URL. If you are not using clean URLs, specify the part after "?q=". If unsure, specify "node".'));
+ $form['general'] = array(
+ type => 'fieldset', title => t('General settings'),
+ collapsible => TRUE, collapsed => TRUE
+ );
+ $form['general']['site_name'] = array(
+ type => 'textfield', title => t('Name'), default_value => variable_get('site_name', 'drupal'),
+ description => t('The name of this web site.')
+ );
+ $form['general']['site_mail'] = array(
+ type => 'textfield', title => t('E-mail address'), default_value => variable_get('site_mail', ini_get('sendmail_from')), maxlength => 128,
+ description => t('A valid e-mail address for this website, used by the auto-mailer during registration, new password requests, notifications, etc.')
+ );
+ $form['general']['site_slogan'] = array(
+ type => 'textfield', title => t('Slogan'), default_value => variable_get('site_slogan', ''),
+ maxlength => 128, description => t('The slogan of this website. Some themes display a slogan when available.')
+ );
+
+ $form['general']['site_mission'] = array(
+ type => 'textarea', title => t('Mission'), default_value => variable_get('site_mission', ''),
+ rows => 5, description => t('Your site\'s mission statement or focus.')
+ );
+ $form['general']['site_footer'] = array(
+ type => 'textarea', title => t('Footer message'), default_value => variable_get('site_footer', ''), rows => 5,
+ description => t('This text will be displayed at the bottom of each page. Useful for adding a copyright notice to your pages.')
+ );
+ $form['general']['anonymous'] = array(
+ type => 'textfield', title => t('Anonymous user'), default_value => variable_get('anonymous', 'Anonymous'),
+ description => t('The name used to indicate anonymous users.')
+ );
+ $form['general']['site_frontpage'] = array(
+ type => 'textfield', title => t('Default front page'), default_value => variable_get('site_frontpage', 'node'),
+ description => t('The home page displays content from this relative URL. If you are not using clean URLs, specify the part after "?q=". If unsure, specify "node".')
+ );
// We check for clean URL support using an image on the client side.
- $group .= form_radios(t('Clean URLs'), 'clean_url', variable_get('clean_url', 0), array(t('Disabled'), t('Enabled')), t('This option makes Drupal emit clean URLs (i.e. without ?q= in the URL). You\'ll need ModRewrite support for this to work. See the .htaccess file in Drupal\'s top-level directory for more information.'));
+ $form['general']['clean_url'] = array(
+ type => 'radios', title => t('Clean URLs'), default_value => variable_get('clean_url', 0), options => array(t('Disabled'), t('Enabled')),
+ description => t('This option makes Drupal emit clean URLs (i.e. without ?q= in the URL). You\'ll need ModRewrite support for this to work. See the .htaccess file in Drupal\'s top-level directory for more information.')
+ );
+
variable_set('clean_url_ok', 0);
global $base_url;
// We will use a random URL so there is no way a proxy or a browser could cache the "no such image" answer.
- $group .= '';
-
- $output = form_group_collapsible(t('General settings'), $group, TRUE);
+ $form['general']['clean_url_test'] = array(type => 'markup', value => '');
// Error handling:
+
+ $form['errors'] = array( type => 'fieldset', title =>t('Error handling'), collapsible => TRUE, collapsed => TRUE );
+ $form['errors']['site_403'] = array(
+ type => 'textfield', title => t('Default 403 (access denied) page'), default_value => variable_get('site_403', ''),
+ description => t('This page is displayed when the requested document is denied to the current user. If you are not using clean URLs, specify the part after "?q=". If unsure, specify nothing.')
+ );
+
+ $form['errors']['site_404'] = array(
+ type => 'textfield', title => t('Default 404 (not found) page'), default_value => variable_get('site_404', ''),
+ description => t('This page is displayed when no other content matches the requested document. If you are not using clean URLs, specify the part after "?q=". If unsure, specify nothing.')
+ );
+
+ $form['errors']['error_level'] = array(
+ type => 'select', title => t('Error reporting'), default_value => variable_get('error_level', 1),
+ options => array(t('Write errors to the log'), t('Write errors to the log and to the screen')),
+ description => t('Where Drupal, PHP and SQL errors are logged. On a production server it is recommended that errors are only written to the error log. On a test server it can be helpful to write logs to the screen.')
+ );
+
$period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval');
$period['1000000000'] = t('Never');
- $group = form_textfield(t('Default 403 (access denied) page'), 'site_403', variable_get('site_403', ''), 60, 70, t('This page is displayed when the requested document is denied to the current user. If you are not using clean URLs, specify the part after "?q=". If unsure, specify nothing.'));
- $group .= form_textfield(t('Default 404 (not found) page'), 'site_404', variable_get('site_404', ''), 60, 70, t('This page is displayed when no other content matches the requested document. If you are not using clean URLs, specify the part after "?q=". If unsure, specify nothing.'));
- $group .= form_select(t('Error reporting'), 'error_level', variable_get('error_level', 1), array(t('Write errors to the log'), t('Write errors to the log and to the screen')), t('Where Drupal, PHP and SQL errors are logged. On a production server it is recommended that errors are only written to the error log. On a test server it can be helpful to write logs to the screen.'));
- $group .= form_select(t('Discard log entries older than'), 'watchdog_clear', variable_get('watchdog_clear', 604800), $period, t('The time log entries should be kept. Older entries will be automatically discarded. Requires crontab.'));
+ $form['errors']['watchdog_clear'] = array(
+ type => 'select', title => t('Discard log entries older than'), default_value => variable_get('watchdog_clear', 604800), options => $period,
+ description => t('The time log entries should be kept. Older entries will be automatically discarded. Requires crontab.')
+ );
- $output .= form_group_collapsible(t('Error handling'), $group, TRUE);
// Caching:
- $group = form_radios(t('Page cache'), 'cache', variable_get('cache', CACHE_DISABLED), array(CACHE_DISABLED => t('Disabled'), CACHE_ENABLED => t('Enabled')), t("Drupal has a caching mechanism which stores dynamically generated web pages in a database. By caching a web page, Drupal does not have to create the page each time someone wants to view it, instead it takes only one SQL query to display it, reducing response time and the server's load. Only pages requested by \"anonymous\" users are cached. In order to reduce server load and save bandwidth, Drupal stores and sends compressed cached pages."));
+ $form['cache'] = array(type => 'fieldset', title => t('Cache settings'), collapsible => TRUE, collapsed => TRUE);
+
+ $form['cache']['cache'] = array(
+ type => 'radios', title => t('Page cache'), default_value => variable_get('cache', CACHE_DISABLED),
+ options => array(CACHE_DISABLED => t('Disabled'), CACHE_ENABLED => t('Enabled')),
+ description => t("Drupal has a caching mechanism which stores dynamically generated web pages in a database. By caching a web page, Drupal does not have to create the page each time someone wants to view it, instead it takes only one SQL query to display it, reducing response time and the server's load. Only pages requested by \"anonymous\" users are cached. In order to reduce server load and save bandwidth, Drupal stores and sends compressed cached pages.")
+ );
+
$period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval');
$period[0] = t('none');
- $group .= form_select(t('Minimum cache lifetime'), 'cache_lifetime', variable_get('cache_lifetime', 0), $period, t('Enabling the cache will offer a sufficient performance boost for most low-traffic and medium-traffic sites. On high-traffic sites it can become necessary to enforce a minimum cache lifetime. The minimum cache lifetime is the minimum amount of time that will go by before the cache is emptied and recreated. A larger minimum cache lifetime offers better performance, but users will not see new content for a longer period of time.'));
+ $form['cache']['cache_lifetime'] = array(
+ type => 'select', title => t('Minimum cache lifetime'), default_value => variable_get('cache_lifetime', 0), options => $period,
+ description => t('Enabling the cache will offer a sufficient performance boost for most low-traffic and medium-traffic sites. On high-traffic sites it can become necessary to enforce a minimum cache lifetime. The minimum cache lifetime is the minimum amount of time that will go by before the cache is emptied and recreated. A larger minimum cache lifetime offers better performance, but users will not see new content for a longer period of time.')
+ );
- $output .= form_group_collapsible(t('Cache settings'), $group, TRUE);
// File system:
+ $form['files'] = array(type => 'fieldset', title => t('File system settings'), collapsible => TRUE, collapsed => TRUE);
+
$directory_path = variable_get('file_directory_path', 'files');
file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
+ $form['files']['file_directory_path'] = array(
+ type => 'textfield', title => t('File system path'), default_value => $directory_path, maxlength => 255, valid => 'directory',
+ description => t('A file system path where the files will be stored. This directory has to exist and be writable by Drupal. If the download method is set to public this directory has to be relative to Drupal installation directory, and be accessible over the web. When download method is set to private this directory should not be accessible over the web. Changing this location after the site has been in use will cause problems so only change this setting on an existing site if you know what you are doing.')
+ );
+
$directory_temp = variable_get('file_directory_temp', FILE_DIRECTORY_TEMP);
file_check_directory($directory_temp, FILE_CREATE_DIRECTORY, 'file_directory_temp');
+
+ $form['files']['file_directory_tmp'] = array(
+ type => 'textfield', title => t('Temporary directory'), default_value => $directory_temp, maxlength => 255, valid => 'directory',
+ description => t('Location where uploaded files will be kept during previews. Relative paths will be resolved relative to the file system path.')
+ );
+
+ $form['files']['file_downloads'] = array(
+ type => 'radios', title => t('Download method'), default_value => variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC),
+ options => array(FILE_DOWNLOADS_PUBLIC => t('Public - files are available using http directly.'), FILE_DOWNLOADS_PRIVATE => t('Private - files are transferred by Drupal.')),
+ description => t('If you want any sort of access control on the downloading of files, this needs to be set to private. You can change this at any time, however all download URLs will change and there may be unexpected problems so it is not recommended.')
+ );
- $group = form_textfield(t('File system path'), 'file_directory_path', $directory_path, 60, 255, t('A file system path where the files will be stored. This directory has to exist and be writable by Drupal. If the download method is set to public this directory has to be relative to Drupal installation directory, and be accessible over the web. When download method is set to private this directory should not be accessible over the web. Changing this location after the site has been in use will cause problems so only change this setting on an existing site if you know what you are doing.'));
- $group .= form_textfield(t('Temporary directory'), 'file_directory_temp', $directory_temp, 60, 255, t('Location where uploaded files will be kept during previews. Relative paths will be resolved relative to the Drupal installation directory.'));
- $group .= form_radios(t('Download method'), 'file_downloads', variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC), array(FILE_DOWNLOADS_PUBLIC => t('Public - files are available using http directly.'), FILE_DOWNLOADS_PRIVATE => t('Private - files are transferred by Drupal.')), t('If you want any sort of access control on the downloading of files, this needs to be set to private. You can change this at any time, however all download URLs will change and there may be unexpected problems so it is not recommended.'));
- $output .= form_group_collapsible(t('File system settings'), $group, TRUE);
-
+ /*
// Image handling:
- $group = '';
+ $group = array();
$toolkits_available = image_get_available_toolkits();
if (count($toolkits_available) > 1) {
- $group .= form_radios(t('Select an image processing toolkit'), 'image_toolkit', variable_get('image_toolkit', image_get_toolkit()), $toolkits_available);
- }
- $group .= image_toolkit_invoke('settings');
- if ($group) {
- $output .= form_group_collapsible(t('Image handling'), '
'. $group .'
', TRUE);
+ $group['image_toolkit'] = array(
+ type => 'radios', title => t('Select an image processing toolkit'),
+ default_value => variable_get('image_toolkit', image_get_toolkit()), options => $toolkits_available
+ );
+ }
+ $group['toolkit'] = image_toolkit_invoke('settings');
+ if (is_array($group)) {
+ $form['image'] = array(type => 'fieldset', title => t('Image handling'), collapsible => TRUE, collapsed => true);
+ $form['image'] = array_merge($form['image'], $group);
}
+ */
// Date settings:
$zones = _system_zonelist();
@@ -264,19 +366,44 @@
$datelongchoices[$f] = format_date(time(), 'custom', $f);
}
- $group = form_select(t('Default time zone'), 'date_default_timezone', variable_get('date_default_timezone', 0), $zones, t('Select the default site time zone.'));
- $group .= form_radios(t('Configurable time zones'), 'configurable_timezones', variable_get('configurable_timezones', 1), array(t('Disabled'), t('Enabled')), t('Enable or disable user-configurable time zones. When enabled, users can set their own time zone and dates will be updated accordingly.'));
- $group .= form_select(t('Short date format'), 'date_format_short', variable_get('date_format_short', $dateshort[0]), $dateshortchoices, t('The short format of date display.'));
- $group .= form_select(t('Medium date format'), 'date_format_medium', variable_get('date_format_medium', $datemedium[0]), $datemediumchoices, t('The medium sized date display.'));
- $group .= form_select(t('Long date format'), 'date_format_long', variable_get('date_format_long', $datelong[0]), $datelongchoices, t('Longer date format used for detailed display.'));
- $group .= form_select(t('First day of week'), 'date_first_day', variable_get('date_first_day', 0), array(0 => t('Sunday'), 1 => t('Monday'), 2 => t('Tuesday'), 3 => t('Wednesday'), 4 => t('Thursday'), 5 => t('Friday'), 6 => t('Saturday')), t('The first day of the week for calendar views.'));
+ $form['dates'] = array(type => 'fieldset', title => t('Date settings'), collapsible => TRUE, collapsed => TRUE);
+ $form['dates']['date_default_timezone'] = array(
+ type => 'select', title => t('Default time zone'), default_value => variable_get('date_default_timezone', 0),
+ options => $zones, description => t('Select the default site time zone.')
+ );
+
+ $form['dates']['configurable_timezones'] = array(
+ type => 'radios', title => t('Configurable time zones'), default_value => variable_get('configurable_timezones', 1), options => array(t('Disabled'), t('Enabled')),
+ description => t('Enable or disable user-configurable time zones. When enabled, users can set their own time zone and dates will be updated accordingly.')
+ );
+
+ $form['dates']['date_format_short'] = array(
+ type => 'select', title => t('Short date format'), default_value => variable_get('date_format_short', $dateshort[0]),
+ options => $dateshortchoices, description => t('The short format of date display.')
+ );
+
+ $form['dates']['date_format_medium'] = array(
+ type => 'select', title => t('Medium date format'), default_value => variable_get('date_format_medium', $datemedium[0]),
+ options => $datemediumchoices, description => t('The medium sized date display.')
+ );
+
+ $form['dates']['date_format_long'] = array(
+ type => 'select', title => t('Long date format'), default_value => variable_get('date_format_long', $datelong[0]),
+ options => $datelongchoices, description => t('Longer date format used for detailed display.')
+ );
+
+ $form['dates']['date_first_day'] = array(
+ type => 'select', title => t('First day of week'), default_value => variable_get('date_first_day', 0),
+ options => array(0 => t('Sunday'), 1 => t('Monday'), 2 => t('Tuesday'), 3 => t('Wednesday'), 4 => t('Thursday'), 5 => t('Friday'), 6 => t('Saturday')),
+ description => t('The first day of the week for calendar views.')
+ );
- $output .= form_group_collapsible(t('Date settings'), $group, TRUE);
// String handling: report status and errors.
- $output .= form_group_collapsible(t('String handling'), unicode_settings(), TRUE);
+ $form['strings'] = array(type => 'fieldset', title => t('String handling'), collapsible => TRUE, collapsed => TRUE);
+ $form['strings']['settings'] = array_merge($from['strings'], unicode_settings());
- return $output;
+ return $form;
}
/**
@@ -465,6 +592,8 @@
}
/**
+<<<<<<< system.module
+=======
* Generate a list of all the available theme/style combinations.
*/
function system_theme_listing() {
@@ -500,6 +629,7 @@
}
/**
+>>>>>>> 1.234
* Generate a list of all the available modules, as well as update the system list.
*/
function system_module_listing() {
@@ -608,52 +738,134 @@
}
}
-function system_settings_form($form) {
- $form .= form_submit(t('Save configuration'));
- $form .= form_submit(t('Reset to defaults'));
+// Add the submit / reset buttons and run drupal_get_form()
+function system_settings_form($form_id, $form) {
+ $form['buttons']['submit'] = array(type => 'submit', value => t('Save configuration') );
+ $form['buttons']['reset'] = array(type => 'submit', value => t('Reset to defaults') );
- return form($form);
+ return drupal_get_form($form_id, $form, 'system_settings_form');
}
-function system_settings_save() {
+/**
+ * Execute the system_settings_form.
+ */
+function system_settings_form_execute($form_id, $form) {
$op = $_POST['op'];
- $edit = $_POST['edit'];
+ global $form_values;
if ($op == t('Reset to defaults')) {
- if (is_array($edit)) {
- foreach ($edit as $name => $value) {
- variable_del($name);
- }
- }
+ array_walk_recursive($form_values, 'system_settings_reset');
drupal_set_message(t('The configuration options have been reset to their default values.'));
}
else if ($op == t('Save configuration')) {
- if (is_array($edit)) {
- if ($edit['clean_url'] && !variable_get('clean_url_ok', 0)) {
- drupal_set_message(t('It appears your host is not configured correctly for Clean URLs. Please check for ModRewrite support with your administrator.'), 'error');
- $edit['clean_url'] = 0;
- }
- foreach ($edit as $name => $value) {
- variable_set($name, $value);
- }
- }
+ array_walk_recursive($form_values, 'system_settings_save');
drupal_set_message(t('The configuration options have been saved.'));
+
}
- else {
- return;
- }
+
menu_rebuild();
- drupal_goto($_GET['q']);
}
/**
+ * Save all the variables submitted to the system table.
+ */
+function system_settings_save($key, $value) {
+ variable_set($key, $value);
+}
+
+function system_settings_reset($key, $value) {
+ variable_del($key);
+}
+
+/**
+ * Do the clean url validation, changing the form property if it doesn't work.
+ */
+function system_settings_validate($form_id, &$form) {
+ #TODO .. fix here.
+ if ($edit['clean_url'] && !variable_get('clean_url_ok', 0)) {
+ drupal_set_message(t('It appears your host is not configured correctly for Clean URLs. Please check for ModRewrite support with your administrator.'), 'error');
+ $edit['clean_url'] = 0;
+ }
+
+}
+
+
+
+
+/**
* Menu callback; displays a listing of all themes.
*/
function system_themes() {
- system_listing_save();
- $form = system_theme_listing();
- $form .= form_submit(t('Save configuration'));
- return form($form);
+ $themes = system_theme_data();
+ ksort($themes);
+
+ foreach ($themes as $info) {
+ $info->screenshot = dirname($info->filename) . '/screenshot.png';
+ $screenshot = file_exists($info->screenshot) ? theme('image', $info->screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot'), false) : t('no screenshot');
+
+ $form[$info->name]['screenshot'] = array(type => 'markup', value => $screenshot);
+ $form[$info->name]['description'] = array(type => 'item', title => $info->name, value => dirname($info->filename));
+ $options[$info->name] = '';
+ if ($info->status) {
+ $status[] = $info->name;
+ }
+ if ($info->status && (function_exists($info->prefix . '_settings') || function_exists($info->prefix . '_features'))) {
+ $form[$info->name]['operations'] = array(type => 'markup', value => l(t('configure'), 'admin/themes/settings/' . $info->name) );
+ }
+ else {
+ // Dummy element for form_render. Cleaner than adding a check in the theme function.
+ $form[$info->name]['operations'] = array();
+ }
+ }
+
+ $form['status'] = array(type => 'checkboxes', options => $options, default_value => $status);
+ $form['theme_default'] = array(type => 'radios', options => $options, default_value => variable_get('theme_default', 'bluemarine'));
+ $form['buttons']['submit'] = array(type => 'submit', value => t('Save configuration') );
+ $form['buttons']['reset'] = array(type => 'submit', value => t('Reset to defaults') );
+
+ return drupal_get_form('system_themes', $form);
+}
+
+function theme_system_themes($form) {
+ foreach ($form as $key => $element) {
+ $row = array();
+ if (is_array($element['description'])) {
+
+ $row[] = form_render($form[$key]['screenshot']);
+ $row[] = form_render($form[$key]['description']);
+ $row[] = array('data' => form_render($form['status'][$key]), 'align' => 'center');
+ $row[] = array('data' => form_render($form['theme_default'][$key]), 'align' => 'center');
+ $row[] = array('data' => form_render($form[$key]['operations']), 'align' => 'center');
+ }
+ $rows[] = $row;
+ }
+
+ $header = array(t('Screenshot'), t('Name'), t('Enabled'), t('Default'), t('Operations'));
+ $output = theme('table', $header, $rows);
+ $output .= form_render($form);
+ return $output;
+}
+
+
+function system_themes_execute($form_id, $form) {
+ global $form_values;
+
+ db_query("UPDATE {system} SET status = 0 WHERE type = 'theme'");
+
+ if ($_POST['op'] == t('Save configuration')) {
+ variable_set('theme_default', $form_values['theme_default']);
+ if (is_array($form_values['status'])) {
+ foreach ($form_values['status'] as $key => $choice) {
+ if ($key == $choice) {
+ db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' and name = '%s'", $choice);
+ }
+ }
+ }
+ }
+ else {
+ variable_del('theme_default');
+ }
+ drupal_set_message(t('The configuration options have been saved.'));
}
/**
@@ -670,16 +882,16 @@
* Menu callback; displays a module's settings page.
*/
function system_site_settings($module = NULL) {
- system_settings_save();
if ($module) {
$form = module_invoke($module, 'settings');
}
else {
$form = system_view_general();
+ $module = 'system';
}
- return system_settings_form($form);
+ return system_settings_form($module . '_settings_form', $form);
}
/**
@@ -725,7 +937,6 @@
}
}
- system_settings_save();
$form = '';
@@ -864,4 +1075,62 @@
}
+function search_box() {
+ $form[action] = url('search');
+ $form['keys'] = array(type => 'textfield', size=> 15, value => '', attributes => array('alt' => t('Enter the terms you wish to search for.'), 'class' => 'form-text'));
+ $form['submit'] = array(type => 'submit', value => t('search'));
+ return drupal_get_form('search_box', $form);
+}
+
+function theme_search_box($form) {
+ $output = '
';
+ return $output;
+}
+
+/**
+ * Output a confirmation form
+ *
+ * This function outputs a complete form for confirming an action. A link is
+ * offered to go back to the item that is being changed in case the user changes
+ * his/her mind.
+ *
+ * You should use $GLOBALS['form_values']['edit'][$name] (where $name is usually 'confirm') to
+ * check if the confirmation was successful.
+ *
+ * @param $form_id
+ * The unique form identifier. Used by the form API to construct the theme.
+ * @param $form
+ * Additional elements to inject into the form, for example hidden elements.
+ * @param $question
+ * The question to ask the user (e.g. "Are you sure you want to delete the
+ * block foo?").
+ * @param $path
+ * The page to go to if the user denies the action.
+ * @param $description
+ * Additional text to display (defaults to "This action cannot be undone.").
+ * @param $yes
+ * A caption for the button which confirms the action (e.g. "Delete",
+ * "Replace", ...).
+ * @param $no
+ * A caption for the link which denies the action (e.g. "Cancel").
+ * @param $name
+ * The internal name used to refer to the confirmation item.
+ * @return
+ * A themed HTML string representing the form.
+ */
+
+function confirm_form($form_id, $form, $question, $path, $description = NULL, $yes = NULL, $no = NULL, $name = 'confirm') {
+ $descripton = ($description) ? $description : t('This action cannot be undone.');
+ drupal_set_title($quesion);
+ $form[attributes] = array('class' => 'confirmation');
+ $form['description'] = array(value => $description);
+ $form[$name] = array(type => 'hidden', value => 1);
+
+ $form['actions'] = array(prefix => '
'. form_textfield(t('Mask'), 'mask', $edit['mask'], 30, 64, '%: '. t('Matches any number of characters, even zero characters') .'. _: '. t('Matches exactly one character.'), NULL, TRUE) .'
Index: modules/menu.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/menu.module,v
retrieving revision 1.35
diff -u -F^f -r1.35 menu.module
--- modules/menu.module 13 Sep 2005 19:10:06 -0000 1.35
+++ modules/menu.module 15 Sep 2005 02:01:03 -0000
@@ -303,16 +303,16 @@ function menu_edit_item($mid = 0) {
function menu_edit_item_form($edit) {
$menu = menu_get_menu();
- $form .= form_textfield(t('Title'), 'title', $edit['title'], 60, 128, t('The name of the menu.'), NULL, TRUE);
+ $form['title'] = array(type => 'textfield', title => t('Title'), default_value => $edit['title'], size => 60, maxlength => 128, description => t('The name of the menu.'), required => TRUE);
if ($edit['pid'] == 0) {
// Display a limited set of fields for menus (not items).
- $form .= form_hidden('path', '');
- $form .= form_hidden('pid', 0);
- $form .= form_hidden('weight', 0);
+ $form['path'] = array(type => 'hidden', value => '');
+ $form['pid'] = array(type => 'hidden', value => 0);
+ $form['weight'] = array(type => 'hidden', value => 0);
}
else {
- $form .= form_textfield(t('Description'), 'description', $edit['description'], 60, 128, t('The description displayed when hovering over a menu item.'));
+ $form['description'] = array(type => textfield, title => t('Description'), default_value => $edit['description'], size => 60, maxlength => 128, description => t('The description displayed when hovering over a menu item.'));
$path_description = t('The Drupal path this menu item links to.');
if (isset($edit['path']) && array_key_exists($edit['path'], $menu['path index']) && $menu['path index'][$edit['path']] != $edit['mid']) {
@@ -322,34 +322,34 @@ function menu_edit_item_form($edit) {
}
if ($edit['type'] & MENU_CREATED_BY_ADMIN) {
- $form .= form_textfield(t('Path'), 'path', $edit['path'], 60, 128, $path_description, NULL, TRUE);
+ $form['path'] = array(type => 'textfield', title => t('Path'), default_value => $edit['path'], size => 60, maxlength => 128, description => $path_description, required => TRUE);
}
else {
- $form .= form_item(t('Path'), l($edit['path'], $edit['path']));
- $form .= form_hidden('path', $edit['path']);
+ $form['_path'] = array(type => 'item', title => t('Path'), title => l($edit['path'], $edit['path']));
+ $form['path'] = array(type => 'hidden', value => $edit['path']);
}
- $form .= form_checkbox(t('Expanded'), 'expanded', 1, ($edit['type'] & MENU_EXPANDED), t('If selected and this menu item has children, the menu will always appear expanded.'));
+ $form['expanded'] = array(type => 'checkbox', title => t('Expanded'), default_value => ($edit['type'] & MENU_EXPANDED), description => t('If selected and this menu item has children, the menu will always appear expanded.'));
// Generate a list of possible parents (not including this item or descendants).
$options = menu_parent_options($edit['mid']);
- $form .= form_select(t('Parent item'), 'pid', $edit['pid'], $options);
+ $form['pid'] = array(type => 'select', title => t('Parent item'), default_value => $edit['pid'], options => $options);
- $form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('Optional. In the menu, the heavier items will sink and the lighter items will be positioned nearer the top.'));
+ $form['weight'] = array(type => 'weight', type => t('Weight'), default_value => $edit['weight'], delta => 10, description => t('Optional. In the menu, the heavier items will sink and the lighter items will be positioned nearer the top.'));
}
- $form .= form_submit(t('Submit'));
+ $form['submit'] = array(type => 'submit', value => t('Submit'));
- $form .= form_hidden('mid', $edit['mid']);
+ $form['mid'] = array(type => 'hidden', value => $edit['mid']);
// Always enable menu items (but not menus) when editing them.
if (!($edit['type'] & MENU_IS_ROOT)) {
$edit['type'] |= MENU_VISIBLE_IN_TREE | MENU_VISIBLE_IN_BREADCRUMB;
}
- $form .= form_hidden('type', $edit['type']);
+ $form['type'] = array(type => 'hidden', value => $edit['type']);
- return form($form);
+ return drupal_get_form('menu_edit_item_form', $form);
}
/**
@@ -548,20 +548,23 @@ function menu_node_form($edit = array())
}
}
- $group = form_textfield(t('Title'), 'menu][title', $item['title'], 60, 128, t('The name to display for this link.'));
+ $form['menu'] = array(type => 'fieldset', title => t('Menu item settings'), collapsible => TRUE, collapsed => TRUE);
+
+ $form['menu']['title'] = array(type => 'textfield', title => t('Title'), default_value => $item['title'], size => 60, maxlength => 128, description => t('The name to display for this link.'));
+
// Generate a list of possible parents (not including this item or descendants).
$options = menu_parent_options($edit['mid']);
- $group .= form_select(t('Parent item'), 'menu][pid', $item['pid'], $options);
- $group .= form_hidden('menu][description', $item['description']);
- $group .= form_hidden('menu][path', $item['path']);
- $group .= form_hidden('menu][weight', ($item['weight']) ? $item['weight'] : 0);
- $group .= form_hidden('menu][mid', ($item['mid']) ? $item['mid'] : 0);
- $group .= form_hidden('menu][type', ($item['type']) ? $item['type'] : MENU_CUSTOM_ITEM);
+ $form['menu']['pid'] = array(type => select, title => t('Parent item'), default_value => $item['pid'], options => $options);
+ $form['menu']['description'] = array(type => 'hidden', value => $item['description']);
+ $form['menu']['path'] = array(type => 'hidden', value => $item['path']);
+ $form['menu']['weight'] = array(type => 'hidden', value => $item['weight'] ? $item['weight'] : 0);
+
+ $form['menu']['mid'] = array(type => 'hidden', value => $item['mid'] ? $item['mid'] : 0);
+ $form['menu']['type'] = array(type => 'hidden', value => $item['type'] ? $item['type'] : MENU_CUSTOM_ITEM);
if ($item['mid'] > 0) {
- $group .= form_checkbox(t('Check to delete this menu item.'), 'menu][delete', 1, $item['delete'], null);
+ $form['menu']['delete'] = array(type => 'checkbox', title => t('Check to delete this menu item.'), default_value => $item['delete']);
}
- $form = form_group_collapsible(t('Menu item settings'), $group, TRUE);
return $form;
}
Index: modules/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment.module,v
retrieving revision 1.369
diff -u -r1.369 comment.module
--- modules/comment.module 7 Sep 2005 20:45:53 -0000 1.369
+++ modules/comment.module 10 Sep 2005 00:06:17 -0000
@@ -31,39 +31,19 @@
Flat — Displays the posts in chronological order, with no threading whatsoever.
Expanded — Displays the title and text for each post.
Collapsed — Displays only the title for each post.
-
When a user chooses save settings, the comments are then redisplayed using the user's new choices. Administrators can set the default settings for the comment control panel, along with other comment defaults, in administer » comments » configure. NOTE: When comment moderation is enabled, users will have another control panel option to control thresholds (see below).
+
When a user chooses save settings, the comments are then redisplayed using the user's new choices. Administrators can set the default settings for the comment control panel, along with other comment defaults, in administer » comments » configure.
Additional comment configurations
Comments behave like other user submissions in Drupal. Filters, smileys and HTML that work in nodes will also work with comments. Administrators can control access to various comment module functions through administer » access control » permissions. Know that in a new Drupal installation, all comment permissions are disabled by default. The choice of which permissions to grant to which roles (groups of users) is left up to the site administrator. The following permissions:
Access comments — Allows users to view comments.
Administrate comments — Allows users complete control over configuring, editing and deleting all comments.
-
Moderate comments — Allows users to rate comment postings (see more on moderation below).
Post comments — Allows users to post comments into an administrator moderation queue.
Post comments without approval — Allows users to directly post comments, bypassing the moderation queue.
Notification of new comments
Drupal provides specific features to inform site members when new comments have been posted.
Drupal displays the total number of comments attached to each node, and tracks comments read by individual site members. Members which have logged in will see a notice accompanying nodes which contain comments they have not read. Some administrators may want to download, install and configure the notify module. Users can then request that Drupal send them an e-mail when new comments are posted (the notify module requires that cron.php be configured properly).
-
The tracker module, disabled by default, displays all the site's recent posts. There is a link to the recent posts page in the navigation block. This page is a useful way to browse new or updated nodes and comments. Content which the user has not yet read is tagged with a red star (this graphic depends on the current theme). Visit the comment board for any node, and Drupal will display a red \"new\" label beside the text of unread comments.
-
-
Comment moderation
-
On sites with active commenting from users, the administrator can turn over comment moderation to the community.
-
With comment moderation, each comment is automatically assigned an initial rating. As users read comments, they can apply a vote which affects the comment rating. At the same time, users have an additional option in the control panel which allows them to set a threshold for the comments they wish to view. Those comments with ratings lower than the set threshold will not be shown. To enable moderation, the administrator must grant moderate comments permissions. Then, a number of options in administer » comments » configure must be configured.
-
-
Moderation votes
-
The first step is to create moderation labels which allow users to rate a comment. Go to administer » comments » configure » moderation votes. In the vote field, enter the textual labels which users will see when casting their votes. Some examples are
-
Excellent +3
Insightful +2
Useful +1
Redundant -1
Flame -3
-
So that users know how their votes affect the comment, these examples include the vote value as part of the label, although that is optional. Using the weight option, you can control the order in which the votes appear to users. Setting the weight heavier (positive numbers) will make the vote label appear at the bottom of the list. Lighter (a negative number) will push it to the top. To encourage positive voting, a useful order might be higher values, positive votes, at the top, with negative votes at the bottom.
-
-
Moderator vote/values matrix
-
Next go to administer » comments » configure » moderation matrix. Enter the values for the vote labels for each permission role in the vote matrix. The values entered here will be used to create the rating for each comment. NOTE: Comment ratings are calculated by averaging user votes with the initial rating.
-
-
Creating comment thresholds
-
In administer » comments » configure » moderation thresholds, you'll have to create some comment thresholds to make the comment rating system useful. When comment moderation is enabled and the thresholds are created, users will find another comment control panel option for selecting their thresholds. They'll use the thresholds you enter here to filter out comments with low ratings. Consequently, you'll probably want to create more than one threshold to give users some flexibility in filtering comments.
-
When creating the thresholds, note that the Minimum score is asking you for the lowest rating that a comment can have in order to be displayed. To see a common example of how thresholds work, you might visit Slashdot and view one of their comment boards associated with a story. You can reset the thresholds in their comment control panel.
-
-
Initial comment scores
-
Finally, you may want to enter some initial comment scores. In administer » comments » configure » moderation roles you can assign a beginning rating for all comments posted by a particular permission role. If you do not assign any initial scores, Drupal will assign a rating of 0 as the default.
The tracker module, disabled by default, displays all the site's recent posts. There is a link to the recent posts page in the navigation block. This page is a useful way to browse new or updated nodes and comments. Content which the user has not yet read is tagged with a red star (this graphic depends on the current theme). Visit the comment board for any node, and Drupal will display a red \"new\" label beside the text of unread comments.
Below is a list of the latest comments posted to your site. Click on a subject to see the comment, the author's name to edit the author's user information , \"edit\" to modify the text, and \"delete\" to remove their submission.
");
@@ -72,14 +52,6 @@
case 'admin/comment/configure':
case 'admin/comment/configure/settings':
return t("
Comments can be attached to any node, and their settings are below. The display comes in two types: a \"flat list\" where everything is flush to the left side, and comments come in chronological order, and a \"threaded list\" where replies to other comments are placed immediately below and slightly indented, forming an outline. They also come in two styles: \"expanded\", where you see both the title and the contents, and \"collapsed\" where you only see the title. Preview comment forces a user to look at their comment by clicking on a \"Preview\" button before they can actually add the comment.
");
- case 'admin/comment/configure/matrix':
- return t("
Here you assign a value to each item in the comment moderation dropdown menu. This value is added to the vote total, which is then divided by the number of users who have voted and rounded off to the nearest integer.
In order to use comment moderation, every text box on this page should be populated.
You must assign the \"moderate comments\" permission to at least one role in order to use this page.
Every box not filled in will have a value of zero, which will have the effect of lowering a comments overall score.
");
- case 'admin/comment/configure/roles':
- return t("
You can setup the initial vote value of a comment posted by each user role using these forms. This value is used before any other users vote on the comment. Blank entries are valued at zero.
");
- case 'admin/comment/configure/thresholds':
- return t("
Use these forms to setup the name and minimum \"cut off\" score to help your users hide comments they don't want to see. These thresholds appear in the user's comment control panel. Click \"edit threshold\" to modify the values of an already existing configuration. To delete a setting, \"edit\" it first, and then choose \"delete threshold\".
");
- case 'admin/comment/configure/votes':
- return t('
Create and control the possible comment moderation votes here. "Weight" lets you set the order of the drop down menu. Click "edit" to edit a current vote weight. To delete a name/weight combination go to the "edit" area. To delete a setting, "edit" it first, and then choose "delete vote".
');
case 'admin/modules#description':
return t('Allows users to comment on and discuss published content.');
}
@@ -113,16 +85,6 @@
$items[] = array('path' => 'admin/comment/configure/settings', 'title' => t('settings'),
'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
- $access = user_access('administer comments') && user_access('administer moderation');
- $items[] = array('path' => 'admin/comment/configure/matrix', 'title' => t('moderation matrix'),
- 'callback' => 'comment_matrix_settings', 'access' => $access, 'type' => MENU_LOCAL_TASK);
- $items[] = array('path' => 'admin/comment/configure/thresholds', 'title' => t('moderation thresholds'),
- 'callback' => 'comment_threshold_settings', 'access' => $access, 'type' => MENU_LOCAL_TASK);
- $items[] = array('path' => 'admin/comment/configure/roles', 'title' => t('moderation roles'),
- 'callback' => 'comment_role_settings', 'access' => $access, 'type' => MENU_LOCAL_TASK);
- $items[] = array('path' => 'admin/comment/configure/votes', 'title' => t('moderation votes'),
- 'callback' => 'comment_vote_settings', 'access' => $access,'type' => MENU_LOCAL_TASK);
-
$access = user_access('post comments');
$items[] = array('path' => 'comment/reply', 'title' => t('reply to comment'),
'callback' => 'comment_save_settings', 'access' => 1, 'type' => MENU_CALLBACK);
@@ -153,7 +115,7 @@
* Implementation of hook_perm().
*/
function comment_perm() {
- return array('access comments', 'post comments', 'administer comments', 'moderate comments', 'post comments without approval', 'administer moderation');
+ return array('access comments', 'post comments', 'administer comments', 'post comments without approval');
}
/**
@@ -242,16 +204,31 @@
function comment_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
case 'settings':
- return form_radios(t('Default comment setting'), 'comment_'. $node->type, variable_get('comment_'. $node->type, 2), array(t('Disabled'), t('Read only'), t('Read/Write')), t('Users with the administer comments permission will be able to override this setting.'));
-
+ $form['comment_'. $node->type] = array(
+ type => 'radios', title => t('Default comment setting'), default_value => variable_get('comment_'. $node->type, 2),
+ options => array(t('Disabled'), t('Read only'), t('Read/Write')),
+ description => t('Users with the administer comments permission will be able to override this setting.')
+ );
+ return $form;
case 'fields':
return array('comment');
- case 'form admin':
+ case 'form pre':
if (user_access('administer comments')) {
$selected = isset($node->comment) ? $node->comment : variable_get("comment_$node->type", 2);
- $output = form_radios('', 'comment', $selected, array(t('Disabled'), t('Read only'), t('Read/write')));
- return form_group_collapsible(t('Comment options'), $output, TRUE);
+ $form['user_comments'] = array(
+ type => 'fieldset',
+ title => t('User Comments'),
+ collapsible => TRUE,
+ collapsed => TRUE,
+ weight => -2
+ );
+ $form['user_comments']['comment'] = array(
+ type => 'radios',
+ default_value => $selected,
+ options => array(t('Disabled'), t('Read only'), t('Read/Write'))
+ );
+ return $form;
}
break;
@@ -295,11 +272,26 @@
function comment_user($type, $edit, &$user, $category = NULL) {
if ($type == 'form' && $category == 'account') {
// when user tries to edit his own data
- return array(array('title' => t('Comment settings'), 'data' => form_textarea(t('Signature'), 'signature', $edit['signature'], 60, 5, t('Your signature will be publicly displayed at the end of your comments.')), 'weight' => 2));
+ $form['comment_settings'] = array(
+ type => 'fieldset',
+ title => t('Comment settings'),
+ collapsible => true,
+ collapsed => false,
+ weight => 0
+ );
+ $form['comment_settings']['signature'] = array(
+ type => 'textarea',
+ title => t('Signature'),
+ default_value => $edit['comment_settings']['signature'],
+ cols => 60,
+ rows => 5,
+ description => ('Your signature will be publicly displayed at the end of your comments.')
+ );
+
+ return $form;
}
if ($type == 'validate') {
- // validate user data editing
- return array('signature' => $edit['signature']);
+ // no changes necessary with the new form API.
}
}
@@ -307,32 +299,57 @@
* Menu callback; presents the comment settings page.
*/
function comment_configure() {
- if ($_POST) {
- system_settings_save();
- }
+ $form['viewing_options'] = array(type => 'fieldset', title => t('Comment viewing options'), collapsible => true, collapsed => true, weight => 0);
- $group = form_radios(t('Default display mode'), 'comment_default_mode', variable_get('comment_default_mode', 4), _comment_get_modes(), t('The default view for comments. Expanded views display the body of the comment. Threaded views keep replies together.'));
- $group .= form_radios(t('Default display order'), 'comment_default_order', variable_get('comment_default_order', 1), _comment_get_orders(), t('The default sorting for new users and anonymous users while viewing comments. These users may change their view using the comment control panel. For registered users, this change is remembered as a persistent user preference.'));
- $group .= form_select(t('Default comments per page'), 'comment_default_per_page', variable_get('comment_default_per_page', '50'), _comment_per_page(), t('Default number of comments for each page: more comments are distributed in several pages.'));
- $group .= form_radios(t('Comment controls'), 'comment_controls', variable_get('comment_controls', 3), array(t('Display above the comments'), t('Display below the comments'), t('Display above and below the comments'), t('Do not display')), t('Position of the comment controls box. The comment controls let the user change the default display mode and display order of comments.'));
- $output = form_group(t('Comment viewing options'), $group);
+ $form['viewing_options']['comment_default_mode'] = array(
+ type => 'radios', title => t('Default display mode'), default_value => variable_get('comment_default_mode', 4),
+ options => _comment_get_modes(),
+ description => t('The default view for comments. Expanded views display the body of the comment. Threaded views keep replies together.')
+ );
- $group = form_radios(t('Anonymous poster settings'), 'comment_anonymous', variable_get('comment_anonymous', 0), array(t('Anonymous posters may not enter their contact information'), t('Anonymous posters may leave their contact information'), t('Anonymous posters must leave their contact information')), t('This feature is only useful if you allow anonymous users to post comments. See the permissions page.', array('%url' => url('admin/access/permissions'))));
- $group .= form_radios(t('Comment subject field'), 'comment_subject_field', variable_get('comment_subject_field', 1), array(t('Disabled'), t('Enabled')), t('Can users provide a unique subject for their comments?'));
- $group .= form_radios(t('Preview comment'), 'comment_preview', variable_get('comment_preview', 1), array(t('Optional'), t('Required')));
- $group .= form_radios(t('Location of comment submission form'), 'comment_form_location', variable_get('comment_form_location', 0), array(t('Display on separate page'), t('Display below post or comments')));
- $output .= form_group(t('Comment posting settings'), $group);
+ $form['viewing_options']['comment_default_order'] = array(
+ type => 'radios', title => t('Default display order'), default_value => variable_get('Default display order', 1),
+ options => _comment_get_orders(),
+ description => t('The default sorting for new users and anonymous users while viewing comments. These users may change their view using the comment control panel. For registered users, this change is remembered as a persistent user preference.')
+ );
- $result = db_query('SELECT fid, filter FROM {moderation_filters} ');
- while ($filter = db_fetch_object($result)) {
- $thresholds[$filter->fid] = ($filter->filter);
- }
- if ($thresholds) {
- $group = form_select(t('Default threshold'), 'comment_default_threshold', variable_get('comment_default_threshold', 0), $thresholds, t('Thresholds are values below which comments are hidden. These thresholds are useful for busy sites which want to hide poor comments from most users.'));
- $output .= form_group(t('Comment moderation settings'), $group);
- }
+ $form['viewing_options']['comment_default_per_page'] = array(
+ type => 'select', title => t('Default comments per page'), default_value => variable_get('comment_default_per_page', 50),
+ options => _comment_per_page(),
+ description => t('Default number of comments for each page: more comments are distributed in several pages.')
+ );
+
+ $form['viewing_options']['comment_controls'] = array(
+ type => 'radios', title => t('Comment controls'), default_value => variable_get('comment_controls', 3),
+ options => array(t('Display above the comments'), t('Display below the comments'), t('Display above and below the comments'), t('Do not display')),
+ description => t('Position of the comment controls box. The comment controls let the user change the default display mode and display order of comments.')
+ );
+
+ $form['posting_settings'] = array(type => 'fieldset', title => t('Comment posting settings'), collapsible => true, collapsed => true, weight => 0);
+
+ $form['posting_settings']['comment_anonymous'] = array(
+ type => 'radios', title => t('Comment controls'), default_value => variable_get('comment_anonymous', 3),
+ options => array(t('Anonymous posters may not enter their contact information'), t('Anonymous posters may leave their contact information'), t('Anonymous posters must leave their contact information')),
+ description => t('This feature is only useful if you allow anonymous users to post comments. See the permissions page.', array('%url' => url('admin/access/permissions')))
+ );
+
+ $form['posting_settings']['comment_subject_field'] = array(
+ type => 'radios', title => t('Comment subject field'), default_value => variable_get('comment_subject_field', 1),
+ options => array(t('Disabled'), t('Enabled')),
+ description => t('Can users provide a unique subject for their comments?')
+ );
+
+ $form['posting_settings']['comment_preview'] = array(
+ type => 'radios', title => t('Preview comment'), default_value => variable_get('comment_preview', 1),
+ options => array(t('Optional'), t('Required'))
+ );
+
+ $form['posting_settings']['comment_form_location'] = array(
+ type => 'radios', title => t('Location of comment submission form'), default_value => variable_get('comment_form_location', 0),
+ options => array(t('Display on separate page'), t('Display below post or comments'))
+ );
- return system_settings_form($output);
+ return system_settings_form('comment_settings_form', $form);
}
/**
@@ -364,7 +381,7 @@
$comment = drupal_unpack($comment);
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
if (comment_access('edit', $comment)) {
- return theme('comment_form', object2array($comment));
+ return comment_form(object2array($comment));
}
else {
drupal_access_denied();
@@ -419,7 +436,7 @@
drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error');
}
else if (user_access('post comments')) {
- $output .= theme('comment_form', array('pid' => $pid, 'nid' => $nid), t('Reply'));
+ $output .= comment_form(array('pid' => $pid, 'nid' => $nid), t('Reply'));
}
else {
drupal_set_message(t('You are not authorized to post comments.'), 'error');
@@ -432,9 +449,12 @@
return $output;
}
-function comment_validate($edit) {
+function comment_validate(&$edit) {
global $user;
+ // Invoke other validation handlers
+ comment_invoke_comment($edit, 'validate');
+
// only admins can change these fields
if (!user_access('administer comments')) {
$edit['uid'] = $user->uid;
@@ -443,16 +463,21 @@
}
else {
if (strtotime($edit['date']) != -1) {
- $edit['timestamp'] = strtotime($edit['date']);
+ $edit['timestamp'] = strtotime($edit['admin']['date']);
}
else {
form_set_error('date', t('You have to specify a valid date.'));
}
+
+ if ($edit['admin']['status']) {
+ $edit['status'] = $edit['admin']['status'];
+ }
+
if ($edit['uid']) {
// if a registered user posted the comment, we assume you only want to transfer authorship
// to another registered user. Name changes are freely allowed on anon comments.
- if ($account = user_load(array('name' => $edit['author']))) {
+ if ($account = user_load(array('name' => $edit['admin']['author']))) {
$edit['uid'] = $account->uid;
}
else {
@@ -461,7 +486,7 @@
}
else {
$edit['uid'] = 0;
- $edit['name'] = $edit['author'];
+ $edit['name'] = $edit['admin']['author'];
}
}
@@ -528,8 +553,8 @@
$comment = array2object($edit);
// Attach the user and time information.
- if ($edit['author']) {
- $account = user_load(array('name' => $edit['author']));
+ if ($edit['admin']['author']) {
+ $account = user_load(array('name' => $edit['admin']['author']));
}
elseif ($user->uid) {
$account = $user;
@@ -542,7 +567,7 @@
// Preview the comment.
$output .= theme('comment_view', $comment);
- $output .= theme('comment_form', $edit, t('Reply'));
+ $output .= comment_form( $edit, t('Reply'));
if ($edit['pid']) {
$comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.picture, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = %d', $edit['pid'], COMMENT_PUBLISHED));
@@ -586,7 +611,8 @@
_comment_update_node_statistics($edit['nid']);
// Allow modules to respond to the updating of a comment.
- module_invoke_all('comment', 'update', $edit);
+ comment_invoke_comment($edit, 'update');
+
// Add an entry to the watchdog log.
watchdog('content', t('Comment: updated %subject.', array('%subject' => theme('placeholder', $edit['subject']))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid']));
@@ -675,7 +701,6 @@
}
}
-
$edit['cid'] = db_next_id('{comments}_cid');
$edit['timestamp'] = time();
@@ -683,13 +708,12 @@
$edit['name'] = $user->name;
}
-
db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, format, hostname, timestamp, status, score, users, thread, name, mail, homepage) VALUES (%d, %d, %d, %d, '%s', '%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s')", $edit['cid'], $edit['nid'], $edit['pid'], $edit['uid'], $edit['subject'], $edit['comment'], $edit['format'], $_SERVER['REMOTE_ADDR'], $edit['timestamp'], $edit['status'], $score, $users, $thread, $edit['name'], $edit['mail'], $edit['homepage']);
_comment_update_node_statistics($edit['nid']);
// Tell the other modules a new comment has been submitted.
- module_invoke_all('comment', 'insert', $edit);
+ comment_invoke_comment($edit, 'insert');
// Add an entry to the watchdog log.
watchdog('content', t('Comment: added %subject.', array('%subject' => theme('placeholder', $edit['subject']))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid']));
@@ -744,10 +768,6 @@
}
}
- if ($moderation = comment_moderation_form($comment)) {
- $links[] = $moderation;
- }
-
return $links;
}
@@ -756,7 +776,6 @@
$mode = $_GET['mode'];
$order = $_GET['order'];
- $threshold = $_GET['threshold'];
$comments_per_page = $_GET['comments_per_page'];
$comment_page = $_GET['comment_page'];
@@ -776,10 +795,6 @@
if (empty($order)) {
$order = $user->sort ? $user->sort : ($_SESSION['comment_sort'] ? $_SESSION['comment_sort'] : variable_get('comment_default_order', 1));
}
- if (empty($threshold)) {
- $threshold = $user->threshold ? $user->threshold : ($_SESSION['comment_threshold'] ? $_SESSION['comment_threshold'] : variable_get('comment_default_threshold', 0));
- }
- $threshold_min = db_result(db_query('SELECT minimum FROM {moderation_filters} WHERE fid = %d', $threshold));
if (empty($comments_per_page)) {
$comments_per_page = $user->comments_per_page ? $user->comments_per_page : ($_SESSION['comment_comments_per_page'] ? $_SESSION['comment_comments_per_page'] : variable_get('comment_default_per_page', '50'));
@@ -789,21 +804,12 @@
if ($cid) {
// Single comment view.
-
- $output .= '';
}
else {
// Multiple comment view
@@ -899,34 +905,28 @@
}
}
- // Start a form, for use with comment control and moderation.
+ // Start a form, for use with comment control.
$result = pager_query($query, $comments_per_page, 0, "SELECT COUNT(*) FROM {comments} WHERE status = %d AND nid = %d", $nid, COMMENT_PUBLISHED);
if (db_num_rows($result) && (variable_get('comment_controls', 3) == 0 || variable_get('comment_controls', 3) == 2)) {
- $output .= '';
+ $output .= comment_controls($mode, $order, $comments_per_page, $nid);;
}
- $output .= '';
-
if (db_num_rows($result) && (variable_get('comment_controls', 3) == 1 || variable_get('comment_controls', 3) == 2)) {
- $output .= '';
+ $output .= comment_controls($mode, $order, $comments_per_page, $nid);;
}
}
// If enabled, show new comment form.
if (user_access('post comments') && node_comment_mode($nid) == 2 && variable_get('comment_form_location', 0)) {
- $output .= theme('comment_form', array('nid' => $nid), t('Post new comment'));
+ $output .= comment_form(array('nid' => $nid), t('Post new comment'));
}
}
return $output;
@@ -984,11 +975,13 @@
drupal_goto("node/$comment->nid");
}
else if ($comment->cid) {
- $output = theme('confirm',
+ $output = confirm_form('coment_confirm_delete',
+ array(),
t('Are you sure you want to delete the comment %title?', array('%title' => theme('placeholder', $comment->subject))),
'node/'. $comment->nid,
t('Any replies to this comment will be lost. This action cannot be undone.'),
- t('Delete'));
+ t('Delete'),
+ t('Cancel'));
}
else {
drupal_set_message(t('The comment no longer exists.'));
@@ -1040,265 +1033,24 @@
}
/**
- * Menu callback; presents the moderation vote matrix.
- */
-function comment_matrix_settings() {
-
- if ($edit = $_POST['edit']) {
- db_query('DELETE FROM {moderation_roles} ');
- foreach ($edit as $role_id => $votes) {
- foreach ($votes as $mid => $value) {
- $sql = "('$mid', '$role_id', '". ($value ? $value : 0) ."')";
- db_query('INSERT INTO {moderation_roles} (mid, rid, value) VALUES '. $sql);
- }
- }
- drupal_set_message(t('The vote values have been saved.'));
- }
-
- $output .= '
'. t('Moderation vote/value matrix') .'
';
-
- $result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%moderate comments%'");
- $role_names = array();
- while ($role = db_fetch_object($result)) {
- $role_names[$role->rid] = $role->name;
- }
-
- $result = db_query('SELECT rid, mid, value FROM {moderation_roles} ');
- while ($role = db_fetch_object($result)) {
- $mod_roles[$role->rid][$role->mid] = $role->value;
- }
-
- $header = array_merge(array(t('Votes')), array_values($role_names));
-
- $result = db_query('SELECT mid, vote FROM {moderation_votes} ORDER BY weight');
- while ($vote = db_fetch_object($result)) {
- $row = array($vote->vote);
- foreach (array_keys($role_names) as $rid) {
- $row[] = array('data' => form_textfield(NULL, "$rid][$vote->mid", $mod_roles[$rid][$vote->mid], 15, 3));
- }
- $rows[] = $row;
- }
- if (!$rows) {
- $rows[] = array(array('data' => t('No votes have been defined.'), 'colspan' => '5'));
- }
-
- $output .= theme('table', $header, $rows);
- if ($rows) { $output .= ' '. form_submit(t('Submit votes')); }
-
- return form($output);
-}
-
-/**
- * Menu callback; allows admin to set default scores for different roles.
- */
-function comment_role_settings() {
-
- $edit = $_POST['edit'];
-
- $output .= '
'. t('Initial comment scores') .'
';
-
- if ($edit) {
- variable_set('comment_roles', $edit);
- drupal_set_message(t('The comment scores have been saved.'));
- }
-
- $start_values = variable_get('comment_roles', array());
-
- $result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%post comments%'");
-
- $header = array(t('User role'), t('Initial score'));
-
- while ($role = db_fetch_object($result)) {
- $rows[] = array($role->name, array('data' => form_textfield(NULL, $role->rid, $start_values[$role->rid], 15, 3), 'align' => 'center'));
- }
-
- $output .= theme('table', $header, $rows);
- $output .= ' '. form_submit(t('Save scores'));
-
- return form($output);
-}
-
-/**
- * Menu callback; displays page for assigning names to vote values.
- */
-function comment_vote_settings($mid = 0) {
- $op = $_POST['op'];
- $edit = $_POST['edit'];
-
- if ($op == t('Save vote')) {
- db_query("UPDATE {moderation_votes} SET vote = '%s', weight = %d WHERE mid = %d", $edit['vote'], $edit['weight'], $mid);
- $mid = 0; // zero it out so we return to the overview.
- drupal_set_message(t('The vote has been saved.'));
- }
- else if ($op == t('Delete vote')) {
- db_query('DELETE FROM {moderation_votes} WHERE mid = %d', $mid);
- db_query('DELETE FROM {moderation_roles} WHERE mid = %d', $mid);
- $mid = 0; // zero it out so we return to the overview.
- drupal_set_message(t('The vote has been deleted.'));
- }
- else if ($op == t('Add new vote')) {
- db_query("INSERT INTO {moderation_votes} (vote, weight) VALUES ('%s', %d)", $edit['vote'], $edit['weight']);
- $mid = 0; // zero it out so we return to the overview.
- drupal_set_message(t('The vote has been added.'));
- }
-
- $output .= '
'. t('Moderation votes overview') .'
';
-
- // load up and show any vote types previously defined.
- $header = array(t('Votes'), t('Weight'), t('Operations'));
- $result = db_query('SELECT mid, vote, weight FROM {moderation_votes} ORDER BY weight');
- while ($vote = db_fetch_object($result)) {
- $rows[] = array($vote->vote, array('data' => $vote->weight), array('data' => l(t('edit'), "admin/comment/configure/votes/$vote->mid")));
- }
- if (!$rows) {
- $rows[] = array(array('data' => t('No vote types have been defined.'), 'colspan' => '3'));
- }
- $output .= theme('table', $header, $rows);
-
- if ($mid) { // if we're not saving, deleting, or adding, we must be editing, so prefill the form fields.
- $vote = db_fetch_object(db_query('SELECT vote, weight FROM {moderation_votes} WHERE mid = %d', $mid));
- }
-
- $output .= '
';
- $form .= form_textfield(t('Vote'), 'vote', $vote->vote, 30, 64, t('The name of this vote. Example: "off topic", "excellent", "sucky".'));
- $form .= form_textfield(t('Weight'), 'weight', $vote->weight, 30, 64, t('Used to order votes in the comment control box; heavier sink.'));
- if ($mid) {
- $form .= form_submit(t('Save vote'));
- $form .= form_submit(t('Delete vote'));
- }
- else {
- $form .= form_submit(t('Add new vote'));
- }
-
- return $output . form($form);
-}
-
-/**
- * Menu callback; displays settings for thresholds at which comments are displayed.
- */
-function comment_threshold_settings($fid = 0) {
- $op = $_POST['op'];
- $edit = $_POST['edit'];
-
- if ($op == t('Save threshold')) {
- db_query("UPDATE {moderation_filters} SET filter = '%s', minimum = %d WHERE fid = %d", $edit['filter'], $edit['minimum'], $fid);
- $fid = 0; // zero it out so we return to the overview.
- drupal_set_message(t('The threshold has been saved.'));
- }
- else if ($op == t('Delete threshold')) {
- db_query('DELETE FROM {moderation_filters} WHERE fid = %d', $fid);
- $fid = 0; // zero it out so we return to the overview.
- drupal_set_message(t('The threshold has been deleted.'));
- }
- else if ($op == t('Add new threshold')) {
- db_query("INSERT INTO {moderation_filters} (filter, minimum) VALUES ('%s', %d)", $edit['filter'], $edit['minimum']);
- $fid = 0; // zero it out so we return to the overview.
- drupal_set_message(t('The threshold has been added.'));
- }
-
- $output .= '
'. t('Comment threshold overview') .'
';
-
- // load up and show any thresholds previously defined.
- $header = array(t('Name'), t('Minimum score'), t('Operations'));
- $result = db_query('SELECT fid, filter, minimum FROM {moderation_filters} ORDER BY minimum');
- while ($filter = db_fetch_object($result)) {
- $rows[] = array($filter->filter, array('data' => $filter->minimum), array('data' => l(t('edit'), "admin/comment/configure/thresholds/$filter->fid")));
- }
- if (!$rows) {
- $rows[] = array(array('data' => t('No thresholds have been defined.'), 'colspan' => '3'));
- }
- $output .= theme('table', $header, $rows);
-
- if ($fid) { // if we're not saving, deleting, or adding, we must be editing, so prefill the form fields.
- $filter = db_fetch_object(db_query('SELECT filter, fid, minimum FROM {moderation_filters} WHERE fid = %d', $fid));
- }
-
- $output .= '
'. (isset($fid) ? t('Edit threshold') : t('Add new threshold')) .'
';
- $form .= form_textfield(t('Threshold name'), 'filter', $filter->filter, 30, 64, t('The name of this threshold. Example: "good comments", "+1 comments", "everything".'));
- $form .= form_textfield(t('Minimum score'), 'minimum', $filter->minimum, 30, 64, t('Show all comments whose score is larger or equal to the provided minimal score. Range: -127 +128'));
- if ($fid) {
- $form .= form_submit(t('Save threshold'));
- $form .= form_submit(t('Delete threshold'));
- }
- else {
- $form .= form_submit(t('Add new threshold'));
- }
-
- return $output . form($form);
-}
-
-/**
*** misc functions: helpers, privates, history
**/
-
-function comment_visible($comment, $threshold = 0) {
- if ($comment->score >= $threshold) {
- return 1;
- }
- else {
- return 0;
- }
-}
-
-function comment_moderate() {
- global $user;
-
- if ($moderation = $_POST['edit']['moderation']) {
- $result = db_query('SELECT DISTINCT mid, value, ABS(value) FROM {moderation_roles} WHERE rid IN (%s) ORDER BY mid, ABS(value), value', implode(', ', array_keys($user->roles)));
- while ($mod = db_fetch_object($result)) {
- $votes[$mod->mid] = $mod->value;
- }
-
- $node = node_load(db_result(db_query('SELECT nid FROM {comments} WHERE cid = %d', key($moderation))));
-
- if (user_access('administer comments') || comment_user_can_moderate($node)) {
- foreach ($moderation as $cid => $vote) {
- if ($vote) {
- $comment = db_fetch_object(db_query('SELECT * FROM {comments} WHERE cid = %d', $cid));
- $users = unserialize($comment->users);
- if ($user->uid != $comment->uid && !(comment_already_moderated($user->uid, $comment->users))) {
- $users[$user->uid] = $vote;
- $tot_score = 0;
- foreach ($users as $uid => $vote) {
- if ($uid) {
- $tot_score = $tot_score + $votes[$vote];
- }
- else {
- // vote 0 is the start value
- $tot_score = $tot_score + $vote;
- }
- }
- $new_score = round($tot_score / count($users));
- db_query("UPDATE {comments} SET score = '$new_score', users = '%s' WHERE cid = %d", serialize($users), $cid);
-
- module_invoke_all('comment', 'moderate', $cid, $vote);
- }
- }
- }
- }
- }
-}
-
function comment_save_settings() {
global $user;
$edit = $_POST['edit'];
+
$mode = $edit['mode'];
$order = $edit['order'];
- $threshold = $edit['threshold'];
$comments_per_page = $edit['comments_per_page'];
- if ($edit['moderation']) {
- comment_moderate();
- }
- else if ($user->uid) {
- $user = user_save($user, array('mode' => $mode, 'sort' => $order, 'threshold' => $threshold, 'comments_per_page' => $comments_per_page));
+ if ($user->uid) {
+ $user = user_save($user, array('mode' => $mode, 'sort' => $order, 'comments_per_page' => $comments_per_page));
}
else {
$_SESSION['comment_mode'] = $mode;
$_SESSION['comment_sort'] = $order;
- $_SESSION['comment_threshold'] = $threshold;
$_SESSION['comment_comments_per_page'] = $comments_per_page;
}
@@ -1353,36 +1105,18 @@
}
-function comment_user_can_moderate($node) {
- global $user;
- return (user_access('moderate comments'));
- // TODO: || (($user->uid == $node->uid) && user_access("moderate comments in owned node")));
-}
-
-function comment_already_moderated($uid, $users) {
- $comment_users = unserialize($users);
- if (!$comment_users) {
- $comment_users = array();
- }
- return in_array($uid, array_keys($comment_users));
-}
-
/*
-** Renderer or visualization functions this can be optionally
-** overridden by themes.
+** Generate the basic commenting form, for appending to a node or display on a separate page.
+** This is rendered by theme_comment_form.
*/
-function theme_comment_form($edit, $title = NULL) {
+function comment_form($edit, $title = NULL) {
global $user;
- $form .= "\n";
- // contact information:
if ($user->uid) {
if ($edit['cid'] && user_access('administer comments')) {
- $form .= '