summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-10-07 06:11:12 +0000
committerDries Buytaert <dries@buytaert.net>2005-10-07 06:11:12 +0000
commit7e1527ee61bc10b3765b95b9af8faaa2254da5a8 (patch)
tree2225c7f571b4a3f635564f8281406a12b2a271a7
parent7b5b460534e5c54b07d28467c2aa2fc670c714e4 (diff)
downloadbrdo-7e1527ee61bc10b3765b95b9af8faaa2254da5a8.tar.gz
brdo-7e1527ee61bc10b3765b95b9af8faaa2254da5a8.tar.bz2
- Patch #29465: new form API by Adrian et al.
TODO: + The contact.module was broken; a new patch for contact.module is needed. + Documentation is needed. + The most important modules need to be updated ASAP.
-rw-r--r--CHANGELOG.txt3
-rw-r--r--includes/common.inc631
-rw-r--r--includes/form.inc1078
-rw-r--r--includes/legacy.inc584
-rw-r--r--includes/locale.inc133
-rw-r--r--includes/theme.inc49
-rw-r--r--includes/unicode.inc4
-rw-r--r--misc/drupal.css5
-rw-r--r--misc/upload.js2
-rw-r--r--modules/aggregator.module187
-rw-r--r--modules/aggregator/aggregator.module187
-rw-r--r--modules/block.module224
-rw-r--r--modules/block/block.module224
-rw-r--r--modules/blog.module18
-rw-r--r--modules/blog/blog.module18
-rw-r--r--modules/blogapi.module15
-rw-r--r--modules/blogapi/blogapi.module15
-rw-r--r--modules/book.module78
-rw-r--r--modules/book/book.module78
-rw-r--r--modules/comment.module697
-rw-r--r--modules/comment/comment.module697
-rw-r--r--modules/drupal.module23
-rw-r--r--modules/drupal/drupal.module23
-rw-r--r--modules/filter.module182
-rw-r--r--modules/filter/filter.module182
-rw-r--r--modules/forum.module96
-rw-r--r--modules/forum/forum.module96
-rw-r--r--modules/locale.module40
-rw-r--r--modules/locale/locale.module40
-rw-r--r--modules/menu.module78
-rw-r--r--modules/menu/menu.module78
-rw-r--r--modules/node.module732
-rw-r--r--modules/node/node.module732
-rw-r--r--modules/page.module19
-rw-r--r--modules/page/page.module19
-rw-r--r--modules/path.module28
-rw-r--r--modules/path/path.module28
-rw-r--r--modules/poll.module59
-rw-r--r--modules/poll/poll.module59
-rw-r--r--modules/profile.module117
-rw-r--r--modules/profile/profile.module117
-rw-r--r--modules/search.module72
-rw-r--r--modules/search/search.module72
-rw-r--r--modules/statistics.module26
-rw-r--r--modules/statistics/statistics.module26
-rw-r--r--modules/story.module19
-rw-r--r--modules/story/story.module19
-rw-r--r--modules/system.module837
-rw-r--r--modules/system/system.module837
-rw-r--r--modules/taxonomy.module138
-rw-r--r--modules/taxonomy/taxonomy.module138
-rw-r--r--modules/throttle.module31
-rw-r--r--modules/throttle/throttle.module31
-rw-r--r--modules/upload.module136
-rw-r--r--modules/upload/upload.module136
-rw-r--r--modules/user.module490
-rw-r--r--modules/user/user.module490
-rw-r--r--modules/watchdog.module26
-rw-r--r--modules/watchdog/watchdog.module26
-rw-r--r--themes/bluemarine/page.tpl.php7
-rw-r--r--themes/engines/phptemplate/phptemplate.engine5
-rw-r--r--themes/pushbutton/page.tpl.php9
-rw-r--r--update.php15
63 files changed, 6455 insertions, 4806 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 9de2c7017..756a7070d 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,7 +1,8 @@
Drupal x.x.x, xxxx-xx-xx (development version)
------------------------
-- added free tagging support (folksonomies).
+- added free tagging support.
- added a site-wide contact form.
+- refactored the form API.
- theme system:
* added the PHPTemplate theme engine and removed the Xtemplate engine.
* converted the bluemarine theme from XTemplate to PHPTemplate.
diff --git a/includes/common.inc b/includes/common.inc
index eacb23a14..9ef5e6d7b 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -479,38 +479,6 @@ function fix_gpc_magic() {
}
/**
- * 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.
@@ -549,6 +517,7 @@ function object2array($object) {
return $array;
}
+
/**
* @} End of "Conversion".
*/
@@ -1000,600 +969,6 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL
*/
/**
- * @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 '<form action="'. check_url($action) .'" method="'. $method .'"'. drupal_attributes($attributes) .">\n<div>". $form ."\n</div></form>\n";
-}
-
-/**
- * Set a hidden 'form_token' field to be included in a form, used to validate
- * that the resulting submission was actually generated by a local form.
- *
- * @param $key
- * A unique key to identify the form that is currently being displayed.
- * This identical key is later used to validate that the resulting submission
- * actually originated with this form.
- * @result
- * A themed HTML string representing the hidden token field.
- */
-function form_token($key) {
- // this private key should always be kept secret
- if (!variable_get('drupal_private_key', '')) {
- variable_set('drupal_private_key', mt_rand());
- }
-
- // the verification token is an md5 hash of the form key and our private key
- return form_hidden('form_token', md5($_SERVER['REMOTE_ADDR'] . $key . variable_get('drupal_private_key', '')));
-}
-
-/**
- * Verify that the hidden 'form_token' field was actually generated with our
- * private key.
- *
- * @param $edit
- * An array containing the form that needs to be validated.
- * @param $key
- * The same key that was used to generate the 'form_token'.
- * @param $error_message
- * An optional error message to display if the form does not validate.
- * @result
- * There is nothing returned from this function, but if the 'form_token' does
- * not validate an error is generated, preventing the submission.
- */
-function form_validate($edit, $key, $error_message = NULL) {
- if ($error_message == NULL) {
- // set a generic default error message
- $error = t('Validation error, please try again. If this error persists, please contact the site administrator.');
- }
-
- if ($edit['form_token'] != md5($_SERVER['REMOTE_ADDR'] . $key . variable_get('drupal_private_key', ''))) {
- // setting this error will cause the form to fail validation
- form_set_error('form_token', $error);
- }
-}
-
-/**
- * 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 '<fieldset' . drupal_attributes($attributes) .'>' . ($legend ? '<legend>'. $legend .'</legend>' : '') . $group . ($description ? '<div class="description">'. $description .'</div>' : '') . "</fieldset>\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 '<fieldset' . drupal_attributes($attributes) .'>' . ($legend ? '<legend>'. $legend .'</legend>' : '') . $group . ($description ? '<div class="description">'. $description .'</div>' : '') . "</fieldset>\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 = '<input type="radio" class="'. _form_get_class('form-radio', $required, _form_get_error($name)) .'" name="edit['. $name .']" value="'. $value .'"'. ($checked ? ' checked="checked"' : '') . drupal_attributes($attributes) .' />';
- if (!is_null($title)) {
- $element = '<label class="option">'. $element .' '. $title .'</label>';
- }
- 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 .= '<label class="option"><input type="radio" class="form-radio" name="edit['. $name .']" value="'. $key .'"'. ($key == $value ? ' checked="checked"' : ''). drupal_attributes($attributes) .' /> '. $choice .'</label><br />';
- }
- 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 = '<input type="checkbox" class="'. _form_get_class('form-checkbox', $required, _form_get_error($name)) .'" name="edit['. $name .']" id="edit-'. form_clean_id($name).'" value="'. $value .'"'. ($checked ? ' checked="checked"' : '') . drupal_attributes($attributes) .' />';
- if (!is_null($title)) {
- $element = '<label class="option">'. $element .' '. $title .'</label>';
- }
- 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 .= '<label class="option"><input type="checkbox" class="form-checkbox" name="edit['. $name .'][]" value="'. $key .'"'. (in_array($key, $values) ? ' checked="checked"' : ''). drupal_attributes($attributes) .' /> '. $choice .'</label><br />';
- }
- 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, '<input type="text" maxlength="'. $maxlength .'" class="'. _form_get_class('form-text', $required, _form_get_error($name)) .'" name="edit['. $name .']" id="edit-'. form_clean_id($name) .'"'. $size .' value="'. check_plain($value) .'"'. drupal_attributes($attributes) .' />', $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, '<input type="text" maxlength="'. $maxlength .'" class="'. _form_get_class('form-text form-autocomplete', $required, _form_get_error($name)) .'" name="edit['. $name .']" id="edit-'. form_clean_id($name) .'"'. $size .' value="'. check_plain($value) .'"'. drupal_attributes($attributes) .' />', $description, 'edit-'. $name, $required, _form_get_error($name));
- $output .= '<input class="autocomplete" type="hidden" id="edit-'. form_clean_id($name) .'-autocomplete" value="'. check_url(url($callback_path, NULL, NULL, TRUE)) .'" disabled="disabled" />';
-
- 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, '<input type="password" class="'. _form_get_class('form-password', $required, _form_get_error($name)) .'" maxlength="'. $maxlength .'" name="edit['. $name .']" id="edit-'. form_clean_id($name) .'"'. $size .' value="'. check_plain($value) .'"'. drupal_attributes($attributes) .' />', $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 .'<textarea'. $cols .' rows="'. $rows .'" name="edit['. $name .']" id="edit-'. form_clean_id($name) .'" class="'. _form_get_class('textarea', $required, _form_get_error($name)) .'"'. drupal_attributes($attributes) .'>'. check_plain($value) .'</textarea>'. $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 .= '<optgroup label="'. $key .'">';
- foreach ($choice as $key => $choice) {
- $select .= '<option value="'. $key .'"'. (is_array($value) ? (in_array($key, $value) ? ' selected="selected"' : '') : ($value == $key ? ' selected="selected"' : '')) .'>'. check_plain($choice) .'</option>';
- }
- $select .= '</optgroup>';
- }
- else {
- $select .= '<option value="'. $key .'"'. (is_array($value) ? (in_array($key, $value) ? ' selected="selected"' : '') : ($value == $key ? ' selected="selected"' : '')) .'>'. check_plain($choice) .'</option>';
- }
- }
- return theme('form_element', $title, '<select name="edit['. $name .']'. ($multiple ? '[]' : '') .'"'. ($multiple ? ' multiple="multiple" ' : '') . ($extra ? ' '. $extra : '') .' id="edit-'. form_clean_id($name) .'">'. $select .'</select>', $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, '<input type="file" class="'. _form_get_class('form-file', $required, _form_get_error($name)) .'" name="edit['. $name .']" id="edit-'. form_clean_id($name) .'" size="'. $size ."\" />\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 '<input type="hidden" name="'. $edit .'['. $name .']" id="'. form_clean_id($edit .'-'. $name) .'" value="'. check_plain($value) .'"'. drupal_attributes($attributes) ." />\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 '<input type="'. $type .'" class="form-'. $type .'" name="'. $name .'" id="'. form_clean_id($name) .'" value="'. check_plain($value) .'" '. drupal_attributes($attributes) ." />\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.
*
* @param $path
@@ -1622,7 +997,7 @@ function url($path = NULL, $query = NULL, $fragment = NULL, $absolute = FALSE) {
// Apache.
$script = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') === false) ? 'index.php' : '';
}
-
+
$path = drupal_get_path_alias($path);
if (isset($fragment)) {
@@ -1952,6 +1327,8 @@ function _drupal_bootstrap_full() {
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.
diff --git a/includes/form.inc b/includes/form.inc
new file mode 100644
index 000000000..0408db883
--- /dev/null
+++ b/includes/form.inc
@@ -0,0 +1,1078 @@
+<?php
+/**
+ * @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.
+ */
+
+/**
+ * Form property constants.
+ *
+ * These constants are defined to keep the namespace of the form tree available for elements.
+ * Properties are strings that start with '_' (underscore) and have special meaning for the form api.
+ */
+
+/**
+ * Keyword: type.
+ * Required: true
+ * Description: Used to specify the form element type. Form elements are defined by implementation of hook_elements.
+ */
+define('type', '_type');
+
+define('theme', '_theme');
+
+define('theme_used', '_theme_used');
+/**
+ * Keyword: name.
+ * Internal: For use within the form api. Should not be set by the developer.
+ * Description: The form_builder function populates this property based on the location of the form element in the form tree.
+ */
+define('name', '_name');
+
+/**
+ * Keyword: id.
+ * Internal: For use within the form api. Should not be set by the developer.
+ * Description: The form_builder function populates this property based on the location of the form element in the form tree.
+ * This is used for the form_set_error notification, along with the stylesheets to be used.
+ */
+define('id', '_id');
+
+/**
+ * Keyword: printed
+ * Internal: For use within the form api. Should not be set by the developer.
+ * Description: Used by form_render to ascertain wether or not a form element has been printed yet
+ */
+define('printed', '_printed');
+
+/**
+ * Keyword: built
+ * Internal: For use within the form api. Should not be set by the developer.
+ * Description: Used by _form_builder to ascertain wether or not a form element has been built yet
+ */
+define('built', '_built');
+
+/**
+ * Keyword: processed
+ * Internal: For use within the form api. Should not be set by the developer.
+ * Description: Used by _form_builder to ascertain wether or not a form element has been processed (ie: expanded to multiple elements)
+ */
+define('processed', '_processed');
+
+
+/**
+ * Keyword: variable
+ * Internal: For use within the form api. Should not be set by the developer.
+ * Description: used by form builder to populate a global form_variables array.
+ */
+define('variable', '_variable');
+
+/**
+ * Keyword: id.
+ * Internal: For use within the form api. Should not be set by the developer.
+ * Description: The form_builder function uses this property to keep track of the parent form elements, and uses this to generate the id and name properties.
+ */
+define('parents', '_parents');
+
+/**
+ * Keyword: input.
+ * Description: Wether or not an input is possible for this form element. True / False. Set in the hook_elements implementation.
+ */
+define('input', '_input');
+
+/**
+ * Keyword: validated.
+ * Description: Wether or not an input has been validated.
+ */
+define('validated', '_validated');
+
+/**
+ * Keyword: value.
+ * Used: For all form elements except 'textarea' and the 'default' fallback.
+ * Description: The value the form element should be set as. Setting this yourself is not required, although it might be a good idea for form elements that
+ * don't change. See the default_value property.
+ */
+define('value', '_value');
+
+/**
+ * Keyword: default_value.
+ * Used: For all form elements that have a value property.
+ * Description: The value the form element should be initialized as. If no submission for this element exists, the element will be set to this value.
+ * This means that you do not have to set the value properties for form elements, as they will be automatically handled by the form api.
+ */
+define('default_value', '_default_value');
+
+/**
+ * Keyword: return_value.
+ * Used: For select , radio and checkbox elements.
+ * Description: The value the form element will return.
+ */
+define('return_value', '_return_value');
+
+/**
+ * Keyword: title
+ * Used: For all form elements that have visible output.
+ * Description: The title of the form element. The developer should use the t() function to translate this property.
+ */
+define('title', '_title');
+
+/**
+ * Keyword: description
+ * Used: For all form elements that have visible output.
+ * Description: The description of the form element. The developer should use the t() function to translate this property.
+ */
+define('description', '_description');
+
+/**
+ * Keyword: required
+ * Used: For all form elements that have visible output.
+ * Description: Wether or not the element is required. This automatically validates for empty fields, and flags inputs as required.
+ */
+define('required', '_required');
+
+/**
+ * Keyword: cols
+ * Used: textarea elements.
+ * Description: How many columns wide the textarea should be.
+ */
+define('cols', '_cols');
+
+/**
+ * Keyword: rows
+ * Used: textarea elements.
+ * Description: How many rows high the textarea should be.
+ */
+define('rows', '_rows');
+
+/**
+ * Keyword: size
+ * Used: textfield elements.
+ * Description: How many characters wide should the textfield be.
+ */
+define('size', '_size');
+
+/**
+ * Keyword: maxlength
+ * Used: For textfield element types.
+ * Description: The maximum amount of characters to accept as input.
+ */
+define('maxlength', '_maxlength');
+
+/**
+ * Keyword: valid
+ * Used: For all form elements that have the value property.
+ * Description: A list of validation functions that need to be passed.
+ */
+define('valid', '_valid');
+define('validation_arguments', '_validation_arguments');
+
+/**
+ * Keyword: weight
+ * Used: all elements.
+ * Description: Used by the form_render function to sort the list of elements before being output.
+ */
+define('weight', '_weight');
+
+/**
+ * Keyword: collapsible
+ * Used: fieldset elements.
+ * Description: Wether or not the fieldset can be collapsed with javascript.
+ */
+define('collapsible', '_collapsible');
+
+/**
+ * Keyword: collapsed
+ * Used: fieldset elements.
+ * Description: Wether or not the fieldset is collapsed by default. See collapsible property.
+ */
+define('collapsed', '_collapsed');
+
+/**
+ * Keyword: autocomplete_path
+ * Used: textfield elements.
+ * Description: The path the AJAX autocomplete script uses as the source for autocompletion.
+ */
+define('autocomplete_path', '_autocomplete_path');
+
+/**
+ * Keyword: action
+ * Used: form elements.
+ * Description: The path to which the form will be submitted.
+ */
+define('action', '_action');
+
+/**
+ * Keyword: method
+ * Used: form elements.
+ * Description: The HTTP method the form will be submitted with (GET/POST). Default is 'post'.
+ */
+define('method', '_method');
+
+/**
+ * Keyword: attributes
+ * Used: all visible form elements.
+ * Description: Additional html attributes, such as 'class' can be set using this mechanism.
+ */
+define('attributes', '_attributes');
+
+/**
+ * Keyword: options
+ * Used: select boxes, checkboxes and radios form elements.
+ * Description: An associative array containing the options to be used. In the format 'return_value' => 'Display Value'
+ *
+ * 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.
+ */
+define('options', '_options');
+
+/**
+ * Keyword: extra
+ * Used: select boxes.
+ * Description: Additional HTML to inject into the select element tag.
+ */
+define('extra', '_extra');
+
+/**
+ * Keyword: multiple
+ * Used: select boxes.
+ * Description: Wether the user may select more than one item.
+ */
+define('multiple', '_multiple');
+
+/**
+ * Keyword: button_type
+ * Used: buttons.
+ * Description: The type of button to display (cancel or submit)
+ */
+define('button_type', '_button_type');
+
+
+
+/**
+ * Keyword: error
+ * Used: All visible form elements.
+ * Description: Wether or not a form element has been flagged as having an error.
+ */
+define('error', '_error');
+
+/**
+ * Keyword: prefix
+ * Used: markup element.
+ * Description: Text to include before the value and children properties.
+ */
+define('prefix', '_prefix');
+
+/**
+ * Keyword: suffix
+ * Used: markup element.
+ * Description: Text to include after the value and children properties.
+ */
+define('suffix', '_suffix');
+
+/**
+ * Keyword: error
+ * Used: weight form element.
+ * Description: Number of weights to have selectable.
+ */
+define('delta', '_delta');
+
+/**
+ * Multiple elements. For use in the poll module, and for file uploads.
+ */
+
+/**
+ * Keyword : process
+ * Used : By any element, used to modify a form element.
+ */
+define('process', '_process');
+
+/**
+ * Keyword: multiple
+ */
+define('multiple', '_multiple');
+
+/**
+ * Keyword: min
+ */
+define('minimum', '_minimum');
+
+/**
+ * Keyword: max
+ */
+define('maximum', '_maximum');
+
+/**
+ * Keyword: increment
+ */
+define('increment', '_increment');
+
+define('spawned', '_spawned');
+
+define('tree', '_tree');
+
+define('token', '_token');
+
+define('execute', '_execute');
+
+/**
+ * Check if the key is a property.
+ */
+function element_property($key) {
+ return (substr($key, 0, 1) == '_');
+}
+
+function element_properties($element) {
+ return array_filter(array_keys($element), 'element_property');
+}
+
+/**
+ * Check if the key is a child.
+ */
+function element_child($key) {
+ return (substr($key, 0, 1) != '_');
+}
+
+function element_children($element) {
+ return array_filter(array_keys($element), 'element_child');
+}
+
+/**
+ * Processes a form array, and produces the HTML output of a form.
+ * If there is input in the $_POST['edit'] variable, this function
+ * will attempt to validate it, using <code>drupal_validate_form</code>,
+ * and then execute the form using <code>drupal_execute_form</code>.
+ *
+ * @param $form_id
+ * A unique string identifying the form. Allows each form to be themed.
+ * @param $form
+ * An associative array containing the structure of the form.
+ * @param $callback
+ * An optional callback that will be used in addition to the form_id.
+ *
+ */
+function drupal_get_form($form_id, &$form, $callback = NULL) {
+ global $form_values, $form_execute;
+ $form_values = array();
+ $form_execute = FALSE;
+ $form[type] = 'form';
+ $form[attributes]['class'] .= ' form-api';
+ if (isset($form[token])) {
+ $form['form_token'] = array(type => 'hidden', value => md5($_SERVER['REMOTE_ADDR'] . $form[token] . variable_get('drupal_private_key', '')));
+ }
+ $form = array_merge(_element_info('form'), $form);
+
+ foreach (module_implements('form_alter') as $module) {
+ $function = $module .'_form_alter';
+ $function($form);
+ }
+
+ $function = $form_id . '_alter';
+ if (function_exists($function)) {
+ $function($form);
+ }
+
+ if (!$form[built]) {
+ $form = _form_builder($form);
+ }
+ if ($form_execute) {
+ drupal_execute_form($form_id, $form, $callback);
+ }
+
+ if (function_exists('theme_' . $form_id)) {
+ $form[theme] = $form_id;
+ }
+ elseif (function_exists('theme_' . $callback)) {
+ $form[theme] = $callback;
+ }
+ return form_render($form);
+}
+
+function drupal_validate_form($form_id, &$form, $callback = NULL) {
+ global $form_values;
+
+ if (isset($form[token])) {
+ if ($form_values['form_token'] != md5($_SERVER['REMOTE_ADDR'] . $form[token] . variable_get('drupal_private_key', ''))) {
+ // setting this error will cause the form to fail validation
+ form_set_error('form_token', t('Validation error, please try again. If this error persists, please contact the site administrator.'));
+ }
+ }
+
+ foreach (module_implements('form_validate_alter') as $module) {
+ $function = $module .'_form_validate_alter';
+ $function($form_id, $form_values);
+ }
+
+ _form_validate($form);
+
+ if (function_exists($form_id . '_validate')) {
+ call_user_func($form_id . '_validate', $form_id, $form_values);
+ }
+ if (function_exists($callback . '_validate')) {
+ call_user_func($callback . '_validate', $form_id, $form_values);
+ }
+}
+
+function drupal_execute_form($form_id, $form, $callback = NULL) {
+ global $form_values;
+ if (!empty($_POST['edit'])) {
+ drupal_validate_form($form_id, $form, $callback);
+ if (!form_get_errors()) {
+ foreach (module_implements('form_execute_alter') as $module) {
+ $function = $module .'_form_execute_alter';
+ $function($form_id, $form_values);
+ }
+
+ if (function_exists($form_id . '_execute')) {
+ call_user_func($form_id . '_execute', $form_id, $form_values);
+ }
+ elseif (function_exists($callback . '_execute')) {
+ call_user_func($callback . '_execute', $form_id, $form_values);
+ }
+ }
+ }
+}
+
+function _form_validate(&$elements) {
+
+ // Recurse through all children.
+ foreach (element_children($elements) as $key) {
+ _form_validate($elements[$key]);
+ }
+
+ /* Validate the current input */
+ if (!$elements[validated] && $elements[input]) {
+ if ($elements[required]) {
+ if (!$elements[value]) {
+ form_error($elements, t('%name field is required', array('%name' => $elements[title])));
+ }
+ if ($elements[valid]) {
+ if (is_array($elements[valid])) {
+ foreach ($elements[valid] as $key => $valid) {
+ $args = is_array($elements[validation_arguments][$key]) ? $elements[validation_arguments][$key] : array();
+ if (function_exists('valid_' . $valid)) {
+ call_user_func_array('valid_' . $valid, array_merge(array($elements), $args));
+ }
+ }
+ }
+ else {
+ $args = is_array($elements[validation_arguments]) ? $elements[validation_arguments] : array();
+ if (function_exists('valid_' . $elements[valid])) {
+ call_user_func_array('valid_' . $elements[valid], array_merge(array($elements), $args));
+ }
+ }
+
+ }
+ }
+ $elements[validated] = TRUE;
+ }
+}
+
+/**
+ * Flag an element as having an error.
+ */
+function form_error(&$element, $message) {
+ $element[error] = TRUE;
+ $GLOBALS['form'][$element[name]] = $message;
+ drupal_set_message($message, 'error');
+}
+
+
+/**
+ * Adds some required properties to each form element, which are used internally in the form api.
+ * This function also automatically assigns the value property from the $edit array, provided the
+ * element doesn't already have an assigned value.
+ */
+function _form_builder($form, $parents = array(), $multiple = FALSE) {
+ global $form_values;
+ global $form_execute;
+
+ if ($form[built] == TRUE) {
+ return $form;
+ }
+ $form[built] = TRUE;
+
+ $form[parents] = ($form[parents]) ? $form[parents] : $parents;
+ /* Use element defaults */
+ if ((!empty($form[type])) && ($info = _element_info($form[type]))) {
+ $form += $info;
+ }
+
+ if ($form[input]) {
+ if (!$form[tree]) {
+ $form[parents] = array(array_pop($form[parents]));
+ }
+
+ $form[name] = ($form[name]) ? $form[name] : 'edit[' . implode('][', $form[parents]) . ']';
+ $form[id] = ($form[id]) ? $form[id] : 'edit-' . implode('-', $form[parents]);
+
+ $posted = isset($_POST['edit']);
+ $edit = $posted ? $_POST['edit'] : array();
+ $ref =& $form_values;
+ foreach ($form[parents] as $parent) {
+ $edit = isset($edit[$parent]) ? $edit[$parent] : NULL;
+ $ref =& $ref[$parent];
+ }
+ $default_value = $posted ? $edit : $form[default_value];
+ $form[value] = $form[value] ? $form[value] : $default_value;
+ if (isset($form[execute])) {
+ if ($_POST[$form[name]] == $form[value]) {
+ $form_execute = $form_execute || $form[execute];
+ }
+ }
+
+ $ref = $form[value];
+ }
+
+ // Allow for elements to expand to multiple elements. Radios, checkboxes and files for instance.
+ if (function_exists($form[process]) && !$form[processed]) {
+ $form = call_user_func($form[process], $form);
+ $form[processed] = TRUE;
+ }
+
+ // Recurse through all child elements.
+ $count = 0;
+ foreach (element_children($form) as $key) {
+ $form[$key][tree] = (isset($form[$key][tree])) ? $form[$key][tree] : $form[tree];
+ # Assign a decimal placeholder weight, to preserve original array order
+ $form[$key][weight] = $form[$key][weight] ? $form[$key][weight] : $count/10;
+ $form[$key] = _form_builder($form[$key], array_merge($form[parents], array($key)));
+ $count++;
+ }
+
+
+ return $form;
+}
+
+/**
+ * Renders a HTML form given an form tree. Recursively iterates over each of
+ * each of the form elements generating HTML code. This function is usually
+ * called from within a theme. To render a form from within a module, use
+ * <code>drupal_get_form()</code>.
+ *
+ * @param $elements
+ * The form tree describing the form.
+ * @return
+ * The rendered HTML form.
+ */
+function form_render(&$elements) {
+ $content = '';
+ if (is_array($elements)) {
+ uasort($elements, "_form_sort");
+ }
+
+ if (!$elements[children]) {
+ /* render all the children using a theme function */
+ if ($elements[theme] && !$elements[theme_used]) {
+ $elements[theme_used] = TRUE;
+ $previous_type = $elements[type];
+ $elements[type] = 'markup';
+ $content = theme($elements[theme], $elements);
+ $elements[type] = $previous_type;
+ }
+ /* render each of the children using form_render and concatenate them */
+ if (!$content) {
+ foreach (element_children($elements) as $key) {
+ $content .= form_render($elements[$key]);
+ }
+ }
+ }
+ if ($content) {
+ $elements[children] = $content;
+ }
+
+ /* Call the form element renderer */
+ if (!$elements[printed]) {
+ $content = theme(($elements[type]) ? $elements[type]: 'markup', $elements);
+ $elements[printed] = TRUE;
+ }
+
+ return $elements[prefix] . $content . $elements[suffix];
+}
+
+function _print_rp($var) {
+ echo "<pre>";
+ print_r($var);
+ echo "</pre>";
+}
+
+/**
+ * Function used by uasort in form render to sort form via weight.
+ */
+function _form_sort($a, $b) {
+ if ($a[weight] == $b[weight]) {
+ return 0;
+ }
+ return ($a[weight] < $b[weight]) ? -1 : 1;
+}
+
+/**
+ * Retrieve the default properties for the defined element type.
+ */
+function _element_info($type, $refresh = null) {
+ static $cache;
+ $basic_defaults = array(
+ description => NULL,
+ attributes => array(),
+ required => FALSE,
+ tree => FALSE
+ );
+ if ($refresh || !is_array($cache)) {
+ $cache = array();
+ foreach (module_implements('elements') as $module) {
+ $elements = module_invoke($module, 'elements');
+ if (is_array($elements)) {
+ $cache = array_merge($cache, $elements);
+ }
+ }
+ if (sizeof($cache)) {
+ foreach ($cache as $element_type => $info) {
+ $cache[$element_type] = array_merge($basic_defaults, $info);
+ }
+ }
+ }
+
+ return $cache[$type];
+}
+
+/**
+ * Format a dropdown menu or scrolling selection box.
+ *
+ * @param $element
+ * An associative array containing the properties of the element.
+ * Properties used : title, value, options, description, extra, multiple, required
+ * @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 theme_select($element) {
+ $select = '';
+ foreach ($element[options] as $key => $choice) {
+ if (is_array($choice)) {
+ $select .= '<optgroup label="'. $key .'">';
+ foreach ($choice as $key => $choice) {
+ $select .= '<option value="'. $key .'"'. (is_array($elementp[value]) ? (in_array($key, $element[value]) ? ' selected="selected"' : '') : ($element[value] == $key ? ' selected="selected"' : '')) .'>'. check_plain($choice) .'</option>';
+ }
+ $select .= '</optgroup>';
+ }
+ else {
+ $select .= '<option value="'. $key .'"'. (is_array($element[value]) ? (in_array($key, $element[value]) ? ' selected="selected"' : '') : ($element[value] == $key ? ' selected="selected"' : '')) .'>'. check_plain($choice) .'</option>';
+ }
+ }
+ return theme('form_element', $element[title], '<select name="'. $element[name] .''. ($element[multiple] ? '[]' : '') .'"'. ($element[multiple] ? ' multiple="multiple" ' : '') . ($element[extra] ? ' '. $element[extra] : '') .' id="' . $element[id] .'">'. $select .'</select>', $element[description], $element[name], $element[required], _form_get_error($element[name]));
+}
+
+/**
+ * Format a group of form items.
+ *
+ * @param $element
+ * An associative array containing the properties of the element.
+ * Properties used : attributes, title, description, children, collapsible, collapsed
+ * @return
+ * A themed HTML string representing the form item group.
+ */
+function theme_fieldset($element) {
+ if ($element[collapsible]) {
+ drupal_add_js('misc/collapse.js');
+
+ $element[attributes]['class'] .= ' collapsible';
+ if ($element[collapsed]) {
+ $element[attributes]['class'] .= ' collapsed';
+ }
+ }
+
+ return '<fieldset' . drupal_attributes($element[attributes]) .'>' . ($element[title] ? '<legend>'. $element[title] .'</legend>' : '') . $element[children] . $element[value] . ($element[description] ? '<div class="description">'. $element[description] .'</div>' : '') . "</fieldset>\n";
+
+}
+
+
+/**
+ * Format a radio button.
+ *
+ * @param $element
+ * An associative array containing the properties of the element.
+ * Properties used : required, return_value, value, attributes, title, description
+ * @return
+ * A themed HTML string representing the form item group.
+ */
+function theme_radio($element) {
+ $output = '<input type="radio" ';
+ $output .= 'class="'. _form_get_class('form-radio', $element[required], _form_get_error($element[name])) .'" ';
+ $output .= 'name="' . $element[name] .'" ';
+ $output .= 'value="'. $element[return_value] .'" ';
+ $output .= ($element[value] == $element[return_value]) ? ' checked="checked" ' : ' ';
+ $output .= drupal_attributes($element[attributes]) .' />';
+ if (!is_null($element[title])) {
+ $output = '<label class="option">'. $output .' '. $element[title] .'</label>';
+ }
+ return theme('form_element', NULL, $output, $element[description], $element[name], $element[required], _form_get_error($element[name]));
+}
+
+/**
+ * Format a set of radio buttons.
+ *
+ * @param $element
+ * An associative array containing the properties of the element.
+ * Properties used : title, value, options, description, required and attributes.
+ * @return
+ * A themed HTML string representing the radio button set.
+ */
+function theme_radios($element) {
+ if ($element[title] || $element[description]) {
+ return theme('form_element', $element[title], $element[children], $element[description], $element[id], $element[required], _form_get_error($element[name]));
+ }
+ else {
+ return $element[children];
+ }
+}
+
+/**
+ * Format a set of radio buttons.
+ *
+ * @param $element
+ * An associative array containing the properties of the element.
+ * Properties used : title, value, options, description, required and attributes.
+ * @return
+ * A themed HTML string representing the radio button set.
+ */
+function theme_date($element) {
+ $output = '<div class="container-inline">' . $element[children] . '</div>';
+ return theme('form_element', $element[title], $output, $element[description], $element[id], $element[required], _form_get_error($element[name]));
+}
+
+/**
+ * Roll out a single checkbox element to a list of checkboxes, using the options array as index.
+ */
+function expand_date($element) {
+ // Default to current date
+ if (!isset($element[value])) {
+ $element[value] = array('day' => format_date(time(), 'custom', 'j'),
+ 'month' => format_date(time(), 'custom', 'n'),
+ 'year' => format_date(time(), 'custom', 'Y'));
+ }
+
+ // Determine the order of day, month, year in the site's chosen date format.
+ $format = variable_get('date_format_short', 'm/d/Y');
+ $sort = array();
+ $sort['day'] = max(strpos($format, 'd'), strpos($format, 'j'));
+ $sort['month'] = max(strpos($format, 'm'), strpos($format, 'M'));
+ $sort['year'] = strpos($format, 'Y');
+ asort($sort);
+ $order = array_keys($sort);
+
+ // Output multi-selector for date
+ foreach ($order as $type) {
+ switch ($type) {
+ case 'day':
+ $options = drupal_map_assoc(range(1, 31));
+ break;
+ case 'month':
+ $options = drupal_map_assoc(range(1, 12), '_profile_map_month');
+ break;
+ case 'year':
+ $options = drupal_map_assoc(range(1900, 2050));
+ break;
+ }
+ $element[$type] = array(type => 'radio', value => $element[value][$type], attributes => $element[attributes], parents => $element[parents], options => $options, tree => TRUE);
+ }
+
+ return $element;
+}
+
+
+/**
+ * Roll out a single checkbox element to a list of checkboxes, using the options array as index.
+ */
+function expand_radios($element) {
+ if (count($element[options]) > 0) {
+ foreach ($element[options] as $key => $choice) {
+ if (!$element[$key]) {
+ $element[$key] = array(type => 'radio', title => $choice, return_value => $key, default_value => $element[default_value], attributes => $element[attributes], parents => $element[parents], spawned => TRUE);
+ }
+ }
+ }
+
+ return $element;
+}
+
+
+/**
+ * Format a form item.
+ *
+ * @param $element
+ * An associative array containing the properties of the element.
+ * Properties used : title, value, description, required, error
+ * @return
+ * A themed HTML string representing the form item.
+ */
+function theme_item($element) {
+ return theme('form_element', $element[title], $element[value] . $element[children], $element[description], $element[id], $element[required], $element[error]);
+}
+
+
+/**
+ * Format a checkbox.
+ *
+ * @param $element
+ * An associative array containing the properties of the element.
+ * Properties used : title, value, return_value, description, required
+ * @return
+ * A themed HTML string representing the checkbox.
+ */
+function theme_checkbox($element) {
+ $checkbox = '<input ';
+ $checkbox .= 'type="checkbox" ';
+ $checkbox .= 'class="'. _form_get_class('form-checkbox', $element[required], _form_get_error($element[name])) . '" ';
+ $checkbox .= 'name="'. $element[name] .'" ';
+ $checkbox .= 'id="'. $element[id].'" ' ;
+ $checkbox .= 'value="'. $element[return_value] .'" ';
+ $checkbox .= ($element[value] == $element[return_value]) ? ' checked="checked" ' : ' ';
+ $checkbox .= drupal_attributes($element[attributes]) . ' />';
+
+ if (!is_null($element[title])) {
+ $checkbox = '<label class="option">'. $checkbox .' '. $element[title] .'</label>';
+ }
+
+ return theme('form_element', NULL, $checkbox, $element[description], $element[name], $element[required], _form_get_error($element[name]));
+}
+
+/**
+ * Format a set of checkboxes.
+ *
+ * @param $element
+ * An associative array containing the properties of the element.
+ * @return
+ * A themed HTML string representing the checkbox set.
+ */
+function theme_checkboxes($element) {
+ if ($element[title] || $element[description]) {
+ return theme('form_element', $element[title], $element[children], $element[description], 'edit-'. $element[name], $element[required], _form_get_error($element[name]));
+ }
+ else {
+ return $element[children];
+ }
+}
+
+function expand_checkboxes($element) {
+ $value = is_array($element[value]) ? $element[value] : array();
+ if (count($element[options]) > 0) {
+ if (!isset($element[default_value]) || $element[default_value] == 0) {
+ $element[default_value] = array();
+ }
+ foreach ($element[options] as $key => $choice) {
+ if (!isset($element[$key])) {
+ $element[$key] = array(
+ type => 'checkbox', processed => TRUE, title => $choice, tree => TRUE,
+ value => in_array($key, $value), attributes => $element[attributes]
+ );
+ }
+ }
+ }
+ return $element;
+}
+
+
+function theme_submit($element) {
+ return theme('button', $element);
+}
+
+function theme_button($element) {
+ return '<input type="submit" class="form-'. $element[button_type] .'" name="'. $element[name] .'" value="'. check_plain($element[value]) .'" '. drupal_attributes($element[attributes]) ." />\n";
+}
+
+/**
+ * Format a hidden form field.
+ *
+ * @param $element
+ * An associative array containing the properties of the element.
+ * Properties used : value, edit
+ * @return
+ * A themed HTML string representing the hidden form field.
+ */
+function theme_hidden($element) {
+ return '<input type="hidden" name="'. $element[name] . '" id="' . $element[id] . '" value="'. check_plain($element[value]) ."\" " . drupal_attributes($element[attributes]) ." />\n";
+}
+
+/**
+ * Format a textfield.
+ *
+ * @param $element
+ * An associative array containing the properties of the element.
+ * Properties used : title, value, description, size, maxlength, required, attributes autocomplete_path
+ * @return
+ * A themed HTML string representing the textfield.
+ */
+function theme_textfield($element) {
+ $size = $element[size] ? ' size="' . $element[size] . '"' : '';
+ if ($element[autocomplete_path]) {
+ drupal_add_js('misc/autocomplete.js');
+ $class = ' form-autocomplete';
+ $extra = '<input class="autocomplete" type="hidden" id="'. $element[id] .'-autocomplete" value="'. check_url(url($element[autocomplete_path], NULL, NULL, TRUE)) .'" disabled="disabled" />';
+ }
+
+ $output = '<input type="text" maxlength="'. $element[maxlength] .'" class="'. _form_get_class("form-text$class", $element[required], _form_get_error($element[name])) .'" name="'. $element[name] .'" id="'. $element[id] .'" '. $size .' value="'. check_plain($element[value]) .'"'. drupal_attributes($element[attributes]) .' />';
+ return theme('form_element', $element[title], $output, $element[description], $element[id], $element[required], _form_get_error($element[name])). $extra;
+}
+
+/**
+ * Format a form.
+ *
+ * @param $element
+ * An associative array containing the properties of the element.
+ * Properties used : action, method, attributes, children
+ * @return
+ * A themed HTML string representing the form.
+ */
+function theme_form($element) {
+ // Anonymous div to satisfy XHTML compliancy.
+ $action = $element[action] ? 'action="' . check_url($element[action]) . '" ' : '';
+ return '<form '. $action . ' method="'. $element[method] .'" '. drupal_attributes($element[attributes]) .">\n<div>". $element[children] ."\n</div></form>\n";
+}
+
+
+/**
+ * Format a textarea.
+ *
+ * @param $element
+ * An associative array containing the properties of the element.
+ * Properties used : title, value, description, rows, cols, required, attributes
+ * @return
+ * A themed HTML string representing the textarea.
+ */
+function theme_textarea($element) {
+ $cols = $element[cols] ? ' cols="'. $element[cols] .'"' : '';
+
+ return theme('form_element', $element[title], '<textarea'. $cols .' rows="'. $element[rows] .'" name="'. $element[name] .'" id="' . $element[id] .'" class="'. _form_get_class('textarea', $element[required], _form_get_error($element[name])) .'"'. drupal_attributes($element[attributes]) .'>'. check_plain($element[value]) .'</textarea>', $element[description], $element[id], $element[required], _form_get_error($element[name]));
+}
+
+/**
+ * Format HTML markup for use in forms.
+ *
+ * This is used in more advanced forms, such as theme selection and filter format.
+ *
+ * @param $element
+ * An associative array containing the properties of the element.
+ * Properties used : prefix, value, children and suffix.
+ * @return
+ * A themed HTML string representing the HTML markup.
+ */
+
+function theme_markup($element) {
+ return $element[value] . $element[children];
+}
+
+
+
+/**
+* Format a password field.
+*
+* @param $element
+* An associative array containing the properties of the element.
+* Properties used : title, value, description, size, maxlength, required, attributes
+* @return
+* A themed HTML string representing the form.
+*/
+function theme_password($element) {
+ $size = $element[size] ? ' size="'. $element[size] .'" ' : '';
+
+ $output = '<input type="password" maxlength="'. $element[maxlength] .'" class="'. _form_get_class("form-text $class", $element[required], _form_get_error($element[name])) .'" name="'. $element[name] .'" id="'. $element[id] .'" '. $size . drupal_attributes($element[attributes]) .' />';
+
+ return theme('form_element', $element[title], $output, $element[description], $element[id], $element[required], _form_get_error($element[name]));
+}
+
+/**
+ * Format a weight selection menu.
+ *
+ * @param $element
+ * An associative array containing the properties of the element.
+ * Properties used : title, delta, description
+ * @return
+ * A themed HTML string representing the form.
+ */
+function theme_weight($element) {
+ for ($n = (-1 * $element[delta]); $n <= $element[delta]; $n++) {
+ $weights[$n] = $n;
+ }
+ $element[options] = $weights;
+ $element[type] = 'select';
+
+ return form_render($element);
+}
+
+/**
+ * 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'];
+ }
+}
+
+/**
+ * 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 theme_file($element) {
+ return theme('form_element', $element[title], '<input type="file" class="'. _form_get_class('form-file', $element[required], _form_get_error($element[name])) .'" name="'. $element[name] .'" id="'. form_clean_id($element[id]) .'" size="'. $element[size] ."\" />\n", $element[description], $element[id], $element[required], _form_get_error($element[name]));
+}
+
+/**
+ * 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' : '');
+}
+
+/**
+ * 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".
+ */
+
+?>
diff --git a/includes/legacy.inc b/includes/legacy.inc
new file mode 100644
index 000000000..ad17aeaa5
--- /dev/null
+++ b/includes/legacy.inc
@@ -0,0 +1,584 @@
+<?
+
+/**
+ * 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;
+}
+/**
+ * @defgroup form Form generation (deprecated)
+ * @{
+ * 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 '<form action="'. check_url($action) .'" method="'. $method .'"'. drupal_attributes($attributes) .">\n<div>". $form ."\n</div></form>\n";
+}
+/**
+ * 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 '<fieldset' . drupal_attributes($attributes) .'>' . ($legend ? '<legend>'. $legend .'</legend>' : '') . $group . ($description ? '<div class="description">'. $description .'</div>' : '') . "</fieldset>\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 '<fieldset' . drupal_attributes($attributes) .'>' . ($legend ? '<legend>'. $legend .'</legend>' : '') . $group . ($description ? '<div class="description">'. $description .'</div>' : '') . "</fieldset>\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 = '<input type="radio" class="'. _form_get_class('form-radio', $required, _form_get_error($name)) .'" name="edit['. $name .']" value="'. $value .'"'. ($checked ? ' checked="checked"' : '') . drupal_attributes($attributes) .' />';
+ if (!is_null($title)) {
+ $element = '<label class="option">'. $element .' '. $title .'</label>';
+ }
+ 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 .= '<label class="option"><input type="radio" class="form-radio" name="edit['. $name .']" value="'. $key .'"'. ($key == $value ? ' checked="checked"' : ''). drupal_attributes($attributes) .' /> '. $choice .'</label><br />';
+ }
+ 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 = '<input type="checkbox" class="'. _form_get_class('form-checkbox', $required, _form_get_error($name)) .'" name="edit['. $name .']" id="edit-'. form_clean_id($name).'" value="'. $value .'"'. ($checked ? ' checked="checked"' : '') . drupal_attributes($attributes) .' />';
+ if (!is_null($title)) {
+ $element = '<label class="option">'. $element .' '. $title .'</label>';
+ }
+ 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 .= '<label class="option"><input type="checkbox" class="form-checkbox" name="edit['. $name .'][]" value="'. $key .'"'. (in_array($key, $values) ? ' checked="checked"' : ''). drupal_attributes($attributes) .' /> '. $choice .'</label><br />';
+ }
+ 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, '<input type="text" maxlength="'. $maxlength .'" class="'. _form_get_class('form-text', $required, _form_get_error($name)) .'" name="edit['. $name .']" id="edit-'. form_clean_id($name) .'"'. $size .' value="'. check_plain($value) .'"'. drupal_attributes($attributes) .' />', $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, '<input type="text" maxlength="'. $maxlength .'" class="'. _form_get_class('form-text form-autocomplete', $required, _form_get_error($name)) .'" name="edit['. $name .']" id="edit-'. form_clean_id($name) .'"'. $size .' value="'. check_plain($value) .'"'. drupal_attributes($attributes) .' />', $description, 'edit-'. $name, $required, _form_get_error($name));
+ $output .= '<input class="autocomplete" type="hidden" id="edit-'. form_clean_id($name) .'-autocomplete" value="'. check_url(url($callback_path, NULL, NULL, TRUE)) .'" disabled="disabled" />';
+
+ 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, '<input type="password" class="'. _form_get_class('form-password', $required, _form_get_error($name)) .'" maxlength="'. $maxlength .'" name="edit['. $name .']" id="edit-'. form_clean_id($name) .'"'. $size .' value="'. check_plain($value) .'"'. drupal_attributes($attributes) .' />', $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 .'<textarea'. $cols .' rows="'. $rows .'" name="edit['. $name .']" id="edit-'. form_clean_id($name) .'" class="'. _form_get_class('textarea', $required, _form_get_error($name)) .'"'. drupal_attributes($attributes) .'>'. check_plain($value) .'</textarea>'. $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 .= '<optgroup label="'. $key .'">';
+ foreach ($choice as $key => $choice) {
+ $select .= '<option value="'. $key .'"'. (is_array($value) ? (in_array($key, $value) ? ' selected="selected"' : '') : ($value == $key ? ' selected="selected"' : '')) .'>'. check_plain($choice) .'</option>';
+ }
+ $select .= '</optgroup>';
+ }
+ else {
+ $select .= '<option value="'. $key .'"'. (is_array($value) ? (in_array($key, $value) ? ' selected="selected"' : '') : ($value == $key ? ' selected="selected"' : '')) .'>'. check_plain($choice) .'</option>';
+ }
+ }
+ return theme('form_element', $title, '<select name="edit['. $name .']'. ($multiple ? '[]' : '') .'"'. ($multiple ? ' multiple="multiple" ' : '') . ($extra ? ' '. $extra : '') .' id="edit-'. form_clean_id($name) .'">'. $select .'</select>', $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, '<input type="file" class="'. _form_get_class('form-file', $required, _form_get_error($name)) .'" name="edit['. $name .']" id="edit-'. form_clean_id($name) .'" size="'. $size ."\" />\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 '<input type="hidden" name="'. $edit .'['. $name .']" id="'. form_clean_id($edit .'-'. $name) .'" value="'. check_plain($value) .'"'. drupal_attributes($attributes) ." />\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 '<input type="'. $type .'" class="form-'. $type .'" name="'. $name .'" id="'. form_clean_id($name) .'" value="'. check_plain($value) .'" '. drupal_attributes($attributes) ." />\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);
+}
+
+/**
+ * Set a hidden 'form_token' field to be included in a form, used to validate
+ * that the resulting submission was actually generated by a local form.
+ *
+ * @param $key
+ * A unique key to identify the form that is currently being displayed.
+ * This identical key is later used to validate that the resulting submission
+ * actually originated with this form.
+ * @result
+ * A themed HTML string representing the hidden token field.
+ */
+function form_token($key) {
+ // this private key should always be kept secret
+ if (!variable_get('drupal_private_key', '')) {
+ variable_set('drupal_private_key', mt_rand());
+ }
+
+ // the verification token is an md5 hash of the form key and our private key
+ return form_hidden('form_token', md5($_SERVER['REMOTE_ADDR'] . $key . variable_get('drupal_private_key', '')));
+}
+
+/**
+ * Verify that the hidden 'form_token' field was actually generated with our
+ * private key.
+ *
+ * @param $edit
+ * An array containing the form that needs to be validated.
+ * @param $key
+ * The same key that was used to generate the 'form_token'.
+ * @param $error_message
+ * An optional error message to display if the form does not validate.
+ * @result
+ * There is nothing returned from this function, but if the 'form_token' does
+ * not validate an error is generated, preventing the submission.
+ */
+function form_validate($edit, $key, $error_message = NULL) {
+ if ($error_message == NULL) {
+ // set a generic default error message
+ $error = t('Validation error, please try again. If this error persists, please contact the site administrator.');
+ }
+
+ if ($edit['form_token'] != md5($_SERVER['REMOTE_ADDR'] . $key . variable_get('drupal_private_key', ''))) {
+ // setting this error will cause the form to fail validation
+ form_set_error('form_token', $error);
+ }
+}
+
+/**
+ * @} End of "defgroup form".
+ */
+
+
diff --git a/includes/locale.inc b/includes/locale.inc
index 0bacb47e3..8779a8c67 100644
--- a/includes/locale.inc
+++ b/includes/locale.inc
@@ -36,17 +36,22 @@ function _locale_add_language($code, $name, $onlylanguage = TRUE) {
* User interface for the language management screen
*/
function _locale_admin_manage_screen() {
- $edit = &$_POST['edit'];
$languages = locale_supported_languages(TRUE, TRUE);
- $header = array(array('data' => t('Code')), array('data' => t('English name')), array('data' => t('Enabled')), array('data' => t('Default')), array('data' => t('Translated')), array('data' => t('Operations')));
-
+ $options = array();
+ $form[action] = url('admin/locale');
+ $form['name'] = array(tree => TRUE);
foreach ($languages['name'] as $key => $lang) {
-
+ $options[$key] = '';
$status = db_fetch_object(db_query("SELECT isdefault, enabled FROM {locales_meta} WHERE locale = '%s'", $key));
-
+ if ($status->enabled) {
+ $enabled[] = $key;
+ }
+ if ($status->isdefault) {
+ $isdefault = $key;
+ }
if ($key == 'en') {
- $rows[] = array('en', check_plain($lang), form_checkbox('', 'enabled][en', 1, $status->enabled), form_radio('', 'sitedefault', $key, $status->isdefault), message_na(), '');
+ $form['name']['en'] = array(type => 'markup', value => check_plain($lang));
}
else {
$original = db_fetch_object(db_query("SELECT COUNT(*) AS strings FROM {locales_source}"));
@@ -54,11 +59,28 @@ function _locale_admin_manage_screen() {
$ratio = ($original->strings > 0 && $translation->translation > 0) ? round(($translation->translation/$original->strings)*100., 2) : 0;
- $rows[] = array(check_plain($key), ($key != 'en' ? form_textfield('', 'name]['. $key, $lang, 15, 64) : $lang), form_checkbox('', 'enabled]['. $key, 1, $status->enabled), form_radio('', 'sitedefault', $key, $status->isdefault), "$translation->translation/$original->strings ($ratio%)", ($key != 'en' ? l(t('delete'), 'admin/locale/language/delete/'. urlencode($key)) : ''));
+ $form['name'][$key] = array(type => 'textfield', default_value => $lang, size => 15, maxlength => 64);
+ $form['translation'][$key] = array(type => 'markup', default_value => "$translation->translation/$original->strings ($ratio%)");
}
}
+ $form['enabled'] = array(type => 'checkboxes', options => $options, default_value => $enabled, return_value => 1);
+ $form['sitedefault'] = array(type => 'radios', options => $options, default_value => $isdefault, return_value => 1);
+ $form['submit'] = array(type => 'submit', value => t('Save configuration'));
+
+ return drupal_get_form('_locale_admin_manage_screen', $form);
+}
- return form(theme('table', $header, $rows) . form_submit(t('Save configuration')), 'post', url('admin/locale'));
+function theme__locale_admin_manage_screen($form) {
+ foreach ($form['name'] as $key => $element) {
+ // Don't take form control structures
+ if (is_array($element) && element_child($key)) {
+ $rows[] = array(check_plain($key), form_render($form['name'][$key]), form_render($form['enabled'][$key]), form_render($form['sitedefault'][$key]), ($key != 'en' ? form_render($form['translation'][$key]) : message_na()), ($key != 'en' ? l(t('delete'), 'admin/locale/language/delete/'. urlencode($key)) : ''));
+ }
+ }
+ $header = array(array('data' => t('Code')), array('data' => t('English name')), array('data' => t('Enabled')), array('data' => t('Default')), array('data' => t('Translated')), array('data' => t('Operations')));
+ $output = theme('table', $header, $rows);
+ $output .= form_render($form);
+ return $output;
}
/**
@@ -68,28 +90,30 @@ function _locale_admin_manage_add_screen() {
$isocodes = _locale_prepare_iso_list();
- $output = '<h2>'. t('From language list') .'</h2>';
- $form = form_select(t('Language name'), 'langcode', key($isocodes), $isocodes, t('Select your language here, or add it below, if you are unable to find it.'));
- $form .= form_submit(t('Add language'));
- $output .= form($form);
+ $form = array();
+ $form['header'] = array(prefix => '<h2>', value => t('Language list'), suffix => '</h2>');
+ $form['langcode'] = array(type => 'select', title => t('Language name'), default_value => key($isocodes), options => $isocodes, description => t('Select your language here, or add it below, if you are unable to find it.'));
+ $form['submit'] = array(type => 'submit', value => t('Add language'));
+ $output = drupal_get_form('locale_add_language', $form);
$edit = &$_POST['edit'];
- $output .= '<h2>'. t('Custom language') .'</h2>';
- $form = form_textfield(t('Language code'), 'langcode', $edit['langcode'], 60, 12, t("Commonly this is an <a href=\"%iso-codes\">ISO 639 language code</a> with an optional country code for regional variants. Examples include 'en', 'en-US' and 'zh-cn'.", array('%iso-codes' => 'http://www.w3.org/WAI/ER/IG/ert/iso639.htm')));
- $form .= form_textfield(t('Language name in English'), 'langname', $edit['langname'], 60, 64, t('Name of the language. Will be available for translation in all languages.'));
- $form .= form_submit(t('Add language'));
- $output .= form($form);
+ $form = array();
+ $form['header'] = array(prefix => '<h2>', value => t('Custom language') , suffix => '</h2>');
+ $form['langcode'] = array(type => 'textfield', title => t('Language code'), default_value => $edit['langcode'], size => 12, maxlength => 60, description => t("Commonly this is an <a href=\"%iso-codes\">ISO 639 language code</a> with an optional country code for regional variants. Examples include 'en', 'en-US' and 'zh-cn'.", array('%iso-codes' => 'http://www.w3.org/WAI/ER/IG/ert/iso639.htm')));
+ $form['langname'] = array(type => 'textfield', title => t('Language name in English'), default_value => $edit['langname'], size => 60, maxlength => 64, description => t('Name of the language. Will be available for translation in all languages.'));
+ $form['submit'] = array(type => 'submit', value => t('Add custom language'));
+
+ $output .= drupal_get_form('_locale_custom_language', $form);
return $output;
}
-
/**
* User interface for the translation import screen
*/
function _locale_admin_import_screen() {
$languages = locale_supported_languages(FALSE, TRUE);
- $languages = array_map("t", $languages['name']);
+ $languages = array_map('t', $languages['name']);
unset($languages['en']);
if (!count($languages)) {
@@ -102,12 +126,15 @@ function _locale_admin_import_screen() {
);
}
- $form = form_file(t('Language file'), 'file', 50, t('A gettext Portable Object (.po) file.'));
- $form .= form_select(t('Import into'), 'langcode', '', $languages, t('Choose the language you want to add strings into. If you choose a language which is not yet set up, then it will be added.'));
- $form .= form_radios(t('Mode'), 'mode', 'overwrite', array('overwrite' => t('Strings in the uploaded file replace existing ones, new ones are added'), 'keep' => t('Existing strings are kept, only new strings are added')));
- $form .= form_submit(t('Import'));
- $output = form($form, 'post', url('admin/locale/language/import'), array('enctype' => 'multipart/form-data'));
- return $output;
+ $form = array();
+ $form['file'] = array(type => 'file', title => t('Language file'), size => 50, description => t('A gettext Portable Object (.po) file.'));
+ $form['langcode'] = array(type => 'select', title => t('Import into'), options => $languages, description => t('Choose the language you want to add strings into. If you choose a language which is not yet set up, then it will be added.'));
+ $form['mode'] = array(type => 'radios', title => t('Mode'), default_value => 'overwrite', options => array('overwrite' => t('Strings in the uploaded file replace existing ones, new ones are added'), 'keep' => t('Existing strings are kept, only new strings are added')));
+ $form['submit'] = array(type => 'submit', value => t('Import'));
+ $form[attributes]['enctype'] = 'multipart/form-data';
+ $form[action] = 'admin/locale/language/import';
+
+ return drupal_get_form('_locale_admin_import', $form);
}
/**
@@ -705,16 +732,18 @@ function _locale_admin_export_screen() {
// Offer language specific export if any language is set up
if (count($languages)) {
$output .= '<h2>'. t('Export translation') .'</h2>';
- $form = form_select(t('Language name'), 'langcode', '', $languages, t('Select the language you would like to export in gettext Portable Object (.po) format.'));
- $form .= form_submit(t('Export'));
- $output .= form($form);
+ $form = array();
+ $form['langcode'] = array(type => 'select', title => t('Language name'), options => $languages, description => t('Select the language you would like to export in gettext Portable Object (.po) format.'));
+ $form['submit'] = array(type => 'submit', value => t('Export'));
+ $output .= drupal_get_form('_locale_export_po', $form);
}
// Complete template export of the strings
$output .= '<h2>'. t('Export template') .'</h2>';
- $form = t('<p>Generate a gettext Portable Object Template (.pot) file with all the interface strings from the Drupal locale database.</p>');
- $form .= form_submit(t('Export'));
- $output .= form($form);
+ $output .= t('<p>Generate a gettext Portable Object Template (.pot) file with all the interface strings from the Drupal locale database.</p>');
+ $form = array();
+ $form['submit'] = array(type => 'submit', value => t('Export'));
+ $output .= drupal_get_form('_locale_export_pot', $form);
return $output;
}
@@ -947,20 +976,24 @@ function _locale_string_edit($lid) {
unset($languages['name']['en']);
$result = db_query('SELECT DISTINCT s.source, t.translation, t.locale FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE s.lid = %d', $lid);
- $form = '';
+ $form = array();
while ($translation = db_fetch_object($result)) {
$orig = $translation->source;
- $form .= (strlen($orig) > 40) ? form_textarea($languages['name'][$translation->locale], $translation->locale, $translation->translation, 60, 15) : form_textfield($languages['name'][$translation->locale], $translation->locale, $translation->translation, 60, 128);
+ $form[$translation->locale] = (strlen($orig) > 40) ?
+ array(type => 'textarea', title => $languages['name'][$translation->locale], default_value => $translation->translation, cols => 60, rows => 15)
+ : array(type => 'textfield', title => $languages['name'][$translation->locale], default_value => $translation->translation, size => 60, maxlength => 128);
unset($languages['name'][$translation->locale]);
}
+ $form = array(type => 'item', title => t('Original text'), value => wordwrap(check_plain($orig, 0)));
foreach ($languages['name'] as $key => $lang) {
- $form .= (strlen($orig) > 40) ? form_textarea($lang, $key, '', 60, 15) : form_textfield($lang, $key, '', 60, 128);
+ $form[$key] = (strlen($orig) > 40) ?
+array(type => 'textarea', title => $lang, cols => 60, rows => 15) :
+array(type => 'textfield', title => $lang, size => 60, maxlength => 128);
}
- $form = form_item(t('Original text'), wordwrap(check_plain($orig, 0))) . $form;
- $form .= form_submit(t('Save translations'));
+ $form['submit'] = array(type => 'submit', value => t('Save translations'));
- return form($form);
+ return $form;
}
/**
@@ -1065,9 +1098,12 @@ function _locale_string_seek() {
}
}
- $output .= theme('table', $header, $rows);
-
- $output .= theme('pager', NULL, 50, 0, $request);
+ if (count($rows)) {
+ $output .= theme('table', $header, $rows);
+ }
+ if ($pager = theme('pager', NULL, 50, 0, $request)) {
+ $output .= $pager;
+ }
}
return $output;
@@ -1085,14 +1121,15 @@ function _locale_string_seek_form() {
// Present edit form preserving previous user settings
$query = _locale_string_seek_query();
- $form .= form_textfield(t('Strings to search for'), 'string', $query->string, 30, 30, t('Leave blank to show all strings. The search is case sensitive.'));
- $form .= form_radios(t('Language'), 'language', ($query->language ? $query->language : 'all'), array_merge(array('all' => t('All languages'), 'en' => t('English (provided by Drupal)')), $languages['name']));
- $form .= form_radios(t('Search in'), 'searchin', ($query->searchin ? $query->searchin : 'all'), array('all' => t('All strings in that language'), 'translated' => t('Only translated strings'), 'untranslated' => t('Only untranslated strings')));
-
- $form .= form_submit(t('Search'));
- $output = form(form_group(t('Search strings'), $form), 'post', url('admin/locale/string/search'));
-
- return $output;
+ $form = array();
+ $form['search'] = array(type => 'fieldset', title => t('Search'));
+ $form['search']['string'] = array(type => 'textfield', title => t('Strings to search for'), default_value => $query->string, size => 30, maxlength => 30, description => t('Leave blank to show all strings. The search is case sensitive.'));
+ $form['search']['language'] = array(type => 'radios', title => t('Language'), default_value => ($query->language ? $query->language : 'all'), options => array_merge(array('all' => t('All languages'), 'en' => t('English (provided by Drupal)')), $languages['name']));
+ $form['search']['searchin'] = array(type => 'radios', title => t('Search in'), default_value => ($query->searchin ? $query->searchin : 'all'), options => array('all' => t('All strings in that language'), 'translated' => t('Only translated strings'), 'untranslated' => t('Only untranslated strings')));
+ $form['search']['submit'] = array(type => 'submit', value => t('Search'));
+ $form[action] = 'admin/locale/string/search';
+
+ return drupal_get_form('_locale_string_seek', $form);
}
// ---------------------------------------------------------------------------------
diff --git a/includes/theme.inc b/includes/theme.inc
index 2f3e64b6f..ba2051ff7 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -959,55 +959,6 @@ function theme_blocks($region) {
}
/**
- * 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 <em>foo</em>?").
- * @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 .= '<p>'. $description ."</p>\n";
- if (!is_null($extra)) {
- $output .= $extra;
- }
- $output .= '<div class="container-inline">';
- $output .= form_submit($yes ? $yes : t('Confirm'));
- $output .= l($no ? $no : t('Cancel'), $path);
- $output .= "</div>\n";
-
- $output .= form_hidden($name, 1);
- return form($output, 'post', NULL, array('class' => 'confirmation'));
-}
-
-/**
* Format a username.
*
* @param $object
diff --git a/includes/unicode.inc b/includes/unicode.inc
index 04751ed79..ce6ba32ac 100644
--- a/includes/unicode.inc
+++ b/includes/unicode.inc
@@ -81,7 +81,8 @@ function unicode_settings() {
$options = array(UNICODE_SINGLEBYTE => t('Standard PHP: operations on Unicode strings are emulated on a best-effort basis. Install the <a href="%url">PHP mbstring extension</a> for improved Unicode support.', array('%url' => 'http://www.php.net/mbstring')),
UNICODE_MULTIBYTE => t('Multi-byte: operations on Unicode strings are supported through the <a href="%url">PHP mbstring extension</a>.', array('%url' => 'http://www.php.net/mbstring')),
UNICODE_ERROR => t('Invalid: the current configuration is incompatible with Drupal.'));
- return form_item(t('String handling method'), $options[$status]);
+ $form['settings'] = array(type => 'item', title =>t('String handling method'), value => $options[$status]);
+ return $form;
}
/**
@@ -474,3 +475,4 @@ function drupal_substr($text, $start, $length = NULL) {
}
}
+
diff --git a/misc/drupal.css b/misc/drupal.css
index 840398666..16ee7362d 100644
--- a/misc/drupal.css
+++ b/misc/drupal.css
@@ -629,3 +629,8 @@ html.js fieldset.collapsed legend a {
display: block;
}
+/*
+** Temporary CSS for porting of drupal forms.
+*/
+form { border: 3px solid red; }
+form.form-api { border : 0px; }
diff --git a/misc/upload.js b/misc/upload.js
index 6437b3175..b4d2a9b6d 100644
--- a/misc/upload.js
+++ b/misc/upload.js
@@ -58,4 +58,4 @@ jsUpload.prototype.oncomplete = function (data) {
// Replace form and re-attach behaviour
$(this.wrapper).innerHTML = data;
uploadAutoAttach();
-} \ No newline at end of file
+}
diff --git a/modules/aggregator.module b/modules/aggregator.module
index 0c07a99d0..546634973 100644
--- a/modules/aggregator.module
+++ b/modules/aggregator.module
@@ -72,12 +72,30 @@ function aggregator_settings() {
$items = array(0 => t('none')) + drupal_map_assoc(array(3, 5, 10, 15, 20, 25), '_aggregator_items');
$period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');
- $output = '';
- $output .= form_textfield(t('Allowed HTML tags'), 'aggregator_allowed_html_tags', variable_get('aggregator_allowed_html_tags', '<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>'), 80, 255, t('The list of tags which are allowed in feeds, i.e., which will not be removed by Drupal.'));
- $output .= form_select(t('Items shown in sources and categories pages'), 'aggregator_summary_items', variable_get('aggregator_summary_items', 3), $items, t('The number of items which will be shown with each feed or category in the feed and category summary pages.'));
- $output .= form_select(t('Discard news items older than'), 'aggregator_clear', variable_get('aggregator_clear', 9676800), $period, t('Older news items will be automatically discarded. Requires crontab.'));
- $output .= form_radios(t('Category selection type'), 'aggregator_category_selector', variable_get('aggregator_category_selector', 'check'), array('check' => t('checkboxes'), 'select' => t('multiple selector')), t('The type of category selection widget which is shown on categorization pages. Checkboxes are easier to use; a multiple selector is good for working with large numbers of categories.'));
- return $output;
+ $form['aggregator_allowed_html_tags'] = array(
+ type => 'textfield', title => t('Allowed HTML tags'), size => 80, maxlength => 255,
+ default_value => variable_get('aggregator_allowed_html_tags', '<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>'),
+ description => t('The list of tags which are allowed in feeds, i.e., which will not be removed by Drupal.')
+ );
+
+ $form['aggregator_summary_items'] = array(
+ type => 'select', title => t('Items shown in sources and categories pages') ,
+ default_value => variable_get('aggregator_summary_items', 3), options => $items,
+ description => t('The number of items which will be shown with each feed or category in the feed and category summary pages.')
+ );
+
+ $form['aggregator_clear'] = array(
+ type => 'select', title => t('Discard news items older than'),
+ default_value => variable_get('aggregator_clear', 9676800), options => $period,
+ description => t('Older news items will be automatically discarded. Requires crontab.')
+ );
+
+ $form['aggregator_category_selector'] = array(
+ type => 'radios', title => t('Category selection type'), default_value => variable_get('aggregator_category_selector', 'check'),
+ options => array('check' => t('checkboxes'), 'select' => t('multiple selector')),
+ description => t('The type of category selection widget which is shown on categorization pages. Checkboxes are easier to use; a multiple selector is good for working with large numbers of categories.')
+ );
+ return $form;
}
/**
@@ -219,9 +237,8 @@ function aggregator_block($op, $delta = 0, $edit = array()) {
else {
$value = db_result(db_query('SELECT block FROM {aggregator_feed} WHERE fid = %d', $id));
}
-
- $output = form_select(t('Number of news items in block'), 'block', $value, 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['block'] = array(type => 'select', title => t('Number of news items in block'), default_value => $value, 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;
}
else if ($op == 'save') {
list($type, $id) = explode('-', $delta);
@@ -658,16 +675,16 @@ function aggregator_save_item($edit) {
}
function aggregator_form_category($edit = array()) {
- $form = form_textfield(t('Title'), 'title', $edit['title'], 60, 64);
- $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5);
- $form .= form_submit(t('Submit'));
+ $form['title'] = array(type => 'textfield', title => t('Title'), default_value => $edit['title'], size => 60, maxlength => 64);
+ $form['description'] = array(type => 'textarea', title => t('Description'), default_value => $edit['description'], cols => 60, rows => 5);
+ $form['submit'] = array(type => 'submit', value =>t('Submit'));
if ($edit['cid']) {
- $form .= form_submit(t('Delete'));
- $form .= form_hidden('cid', $edit['cid']);
+ $form['delete'] = array(type => 'submit', value =>t('Delete'));
+ $form['cid'] = array(type => 'hidden', value => $edit['cid']);
}
- return form($form);
+ return drupal_get_form('aggregator_form_category', $form);
}
function aggregator_save_category($edit) {
@@ -691,9 +708,10 @@ function aggregator_form_feed($edit = array()) {
$edit['refresh'] = 3600;
}
- $form .= form_textfield(t('Title'), 'title', $edit['title'], 60, 64, t('The name of the feed; typically the name of the web site you syndicate content from.'));
- $form .= form_textfield(t('URL'), 'url', $edit['url'], 60, 255, t('The fully-qualified URL of the feed.'));
- $form .= form_select(t('Update interval'), 'refresh', $edit['refresh'], $period, t('The refresh interval indicating how often you want to update this feed. Requires crontab.'));
+
+ $form['title'] = array(type => 'textfield', title => t('Title'), default_value => $edit['title'], size => 60, maxlength => 64, description => t('The name of the feed; typically the name of the web site you syndicate content from.'));
+ $form['url'] = array(type => 'textfield', title => t('URL'), default_value => $edit['url'], size => 60, maxlength => 255, description => t('The fully-qualified URL of the feed.'));
+ $form['refresh'] = array(type => 'select', title => t('Update interval'), default_value => $edit['refresh'], options => $period, description => t('The refresh interval indicating how often you want to update this feed. Requires crontab.'));
// Handling of categories:
$options = array();
@@ -704,17 +722,16 @@ function aggregator_form_feed($edit = array()) {
if ($category->fid) $values[] = check_plain($category->cid);
}
if ($options) {
- $form .= form_checkboxes(t('Categorize news items'), 'category', $values, $options, t('New items in this feed will be automatically filed in the checked categories as they are received.'));
+ $form['category'] = array(type => 'checkboxes', title => t('Categorize news items'), default_value => $values, options => $options, description => t('New items in this feed will be automatically filed in the checked categories as they are received.'));
}
+ $form['submit'] = array(type => 'submit', value =>t('Submit'));
- // Form buttons:
- $form .= form_submit(t('Submit'));
if ($edit['fid']) {
- $form .= form_submit(t('Delete'));
- $form .= form_hidden('fid', $edit['fid']);
+ $form['delete'] = array(type => 'submit', value =>t('Delete'));
+ $form['fid'] = array(type => 'hidden', value => $edit['fid']);
}
- return form($form);
+ return drupal_get_form('aggregator_form_feed', $form);
}
function aggregator_save_feed($edit) {
@@ -786,7 +803,6 @@ function aggregator_view() {
}
function aggregator_edit() {
-
if ($_POST['op'] == t('Submit')) {
if (arg(1) == 'categories') {
aggregator_save_category($_POST['edit']);
@@ -941,83 +957,98 @@ function aggregator_page_category() {
* menu callbacks use this function to print their feeds.
*/
function _aggregator_page_list($sql, $op, $header = '') {
- if (user_access('administer news feeds') && $op == 'categorize') {
- if ($edit = $_POST['edit']) {
- foreach ($edit['categories'] as $iid => $selection) {
- db_query('DELETE FROM {aggregator_category_item} WHERE iid = %d', $iid);
- foreach ($selection as $cid) {
- if ($cid) {
- db_query('INSERT INTO {aggregator_category_item} (cid, iid) VALUES (%d, %d)', $cid, $iid);
- }
- }
- }
- drupal_set_message(t('The categories have been saved.'));
- drupal_goto($_GET['q']);
- }
- else {
- $categorize = true;
- }
- }
+ $categorize = (user_access('administer news feeds') && ($op == 'categorize'));
$output = '<div id="aggregator">';
- if ($header) {
- $output .= $header;
- }
- if ($links) {
- $output .= theme('links', $links);
- }
- $result = pager_query($sql, 20);
+ $form['header'] = array(value => $header);
+ $output .= $form['header'][value];
- $rows = array();
+ $result = pager_query($sql, 20);
$categories = array();
while ($item = db_fetch_object($result)) {
+ $form['items'][$item->iid] = array(value => theme('aggregator_page_item', $item));
+ $output .= $form['items'][$item->iid][value];
+ $form['categories'][$item->iid] = array();
+
if ($categorize) {
+
$categories_result = db_query('SELECT c.cid, c.title, ci.iid FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid AND ci.iid = %d', $item->iid);
- if (variable_get('aggregator_category_selector', 'check') == 'select') {
- $selected = array();
- while ($category = db_fetch_object($categories_result)) {
- if (!$done) {
- $categories[$category->cid] = check_plain($category->title);
- }
- if ($category->iid) {
- $selected[] = $category->cid;
- }
+ $selected = array();
+ while ($category = db_fetch_object($categories_result)) {
+ if (!$done) {
+ $categories[$category->cid] = check_plain($category->title);
}
- $done = true;
- $form = form_select(NULL, 'categories]['. $item->iid, $selected, $categories, NULL, 'size="10"', true);
- }
- else {
- $form = '';
- while ($category = db_fetch_object($categories_result)) {
- $form .= form_checkbox(check_plain($category->title), 'categories]['. $item->iid .'][', $category->cid, !is_null($category->iid));
+ if ($category->iid) {
+ $selected[] = $category->cid;
}
}
- $rows[] = array(theme('aggregator_page_item', $item), array('data' => $form, 'class' => 'categorize-item'));
- }
- else {
- $output .= theme('aggregator_page_item', $item);
+ $done = true;
+ $form['categories'][$item->iid] = array(
+ type => variable_get('aggregator_category_selector', 'checkboxes'),
+ default_value => $selected, options => $categories,
+ size => 10, multiple => true
+ );
}
}
- if ($categorize) {
- $output .= form(theme('table', array('', t('Categorize')), $rows) . form_submit(t('Save categories')));
- }
- $output .= '</div>';
-
- $output .= theme('pager', NULL, 20, 0);
+ $output .= '</div>';
+ $form['submit'] = array(type => 'submit', value => t('Save categories'));
+ $form['pager'] = array(value => theme('pager', NULL, 20, 0));
+ $output .= $form['pager'][value];
// arg(1) is undefined if we are at the top aggregator URL
// is there a better way to do this?
if (!arg(1)) {
- $output .= theme('xml_icon', url('aggregator/rss'));
+ $form['xml_icon'] = array(value => theme('xml_icon', url('aggregator/rss')));
}
elseif (arg(1) == 'categories' && arg(2) && !arg(3)) {
- $output .= theme('xml_icon', url('aggregator/rss/' . arg(2)));
+ $form['xml_icon'] = array(value => theme('xml_icon', url('aggregator/rss/' . arg(2))));
}
+ $output .= $form['xml_icon'][value];
+
+ return ($categorize) ? drupal_get_form('aggregator_page_list', $form) : $output;
+}
+function theme_aggregator_page_list($form) {
+ $output = '<div id="aggregator">';
+ $output .= form_render($form['header']);
+ $rows = array();
+ if ($form['items']) {
+ foreach (element_children($form['items']) as $key) {
+ if (is_array($form['items'][$key])) {
+ $rows[] = array(form_render($form['items'][$key]), array('data' => form_render($form['categories'][$key]), 'class' => 'categorize-item'));
+ }
+ }
+ }
+ $output .= theme('table', array('', t('Categorize')), $rows);
+ $output .= form_render($form['submit']);
+ $output .= '</div>';
+ $output .= form_render($form);
return $output;
}
+function aggregator_page_list_validate($form_id, &$form) {
+ if (!user_access('administer news feeds')) {
+ form_error($form, t('You are not allowed to categorize this feed item.'));
+ }
+}
+
+function aggregator_page_list_execute($form_id, $form) {
+ global $form_values;
+ foreach ($form_values['categories'] as $iid => $selection) {
+ db_query('DELETE FROM {aggregator_category_item} WHERE iid = %d', $iid);
+ foreach ($selection as $cid) {
+ if ($cid) {
+ db_query('INSERT INTO {aggregator_category_item} (cid, iid) VALUES (%d, %d)', $cid, $iid);
+ }
+ }
+ }
+ drupal_set_message(t('The categories have been saved.'));
+ drupal_goto($_GET['q']);
+}
+
+
+
/**
* Menu callback; displays all the feeds used by the aggregator.
*/
diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module
index 0c07a99d0..546634973 100644
--- a/modules/aggregator/aggregator.module
+++ b/modules/aggregator/aggregator.module
@@ -72,12 +72,30 @@ function aggregator_settings() {
$items = array(0 => t('none')) + drupal_map_assoc(array(3, 5, 10, 15, 20, 25), '_aggregator_items');
$period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');
- $output = '';
- $output .= form_textfield(t('Allowed HTML tags'), 'aggregator_allowed_html_tags', variable_get('aggregator_allowed_html_tags', '<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>'), 80, 255, t('The list of tags which are allowed in feeds, i.e., which will not be removed by Drupal.'));
- $output .= form_select(t('Items shown in sources and categories pages'), 'aggregator_summary_items', variable_get('aggregator_summary_items', 3), $items, t('The number of items which will be shown with each feed or category in the feed and category summary pages.'));
- $output .= form_select(t('Discard news items older than'), 'aggregator_clear', variable_get('aggregator_clear', 9676800), $period, t('Older news items will be automatically discarded. Requires crontab.'));
- $output .= form_radios(t('Category selection type'), 'aggregator_category_selector', variable_get('aggregator_category_selector', 'check'), array('check' => t('checkboxes'), 'select' => t('multiple selector')), t('The type of category selection widget which is shown on categorization pages. Checkboxes are easier to use; a multiple selector is good for working with large numbers of categories.'));
- return $output;
+ $form['aggregator_allowed_html_tags'] = array(
+ type => 'textfield', title => t('Allowed HTML tags'), size => 80, maxlength => 255,
+ default_value => variable_get('aggregator_allowed_html_tags', '<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>'),
+ description => t('The list of tags which are allowed in feeds, i.e., which will not be removed by Drupal.')
+ );
+
+ $form['aggregator_summary_items'] = array(
+ type => 'select', title => t('Items shown in sources and categories pages') ,
+ default_value => variable_get('aggregator_summary_items', 3), options => $items,
+ description => t('The number of items which will be shown with each feed or category in the feed and category summary pages.')
+ );
+
+ $form['aggregator_clear'] = array(
+ type => 'select', title => t('Discard news items older than'),
+ default_value => variable_get('aggregator_clear', 9676800), options => $period,
+ description => t('Older news items will be automatically discarded. Requires crontab.')
+ );
+
+ $form['aggregator_category_selector'] = array(
+ type => 'radios', title => t('Category selection type'), default_value => variable_get('aggregator_category_selector', 'check'),
+ options => array('check' => t('checkboxes'), 'select' => t('multiple selector')),
+ description => t('The type of category selection widget which is shown on categorization pages. Checkboxes are easier to use; a multiple selector is good for working with large numbers of categories.')
+ );
+ return $form;
}
/**
@@ -219,9 +237,8 @@ function aggregator_block($op, $delta = 0, $edit = array()) {
else {
$value = db_result(db_query('SELECT block FROM {aggregator_feed} WHERE fid = %d', $id));
}
-
- $output = form_select(t('Number of news items in block'), 'block', $value, 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['block'] = array(type => 'select', title => t('Number of news items in block'), default_value => $value, 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;
}
else if ($op == 'save') {
list($type, $id) = explode('-', $delta);
@@ -658,16 +675,16 @@ function aggregator_save_item($edit) {
}
function aggregator_form_category($edit = array()) {
- $form = form_textfield(t('Title'), 'title', $edit['title'], 60, 64);
- $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5);
- $form .= form_submit(t('Submit'));
+ $form['title'] = array(type => 'textfield', title => t('Title'), default_value => $edit['title'], size => 60, maxlength => 64);
+ $form['description'] = array(type => 'textarea', title => t('Description'), default_value => $edit['description'], cols => 60, rows => 5);
+ $form['submit'] = array(type => 'submit', value =>t('Submit'));
if ($edit['cid']) {
- $form .= form_submit(t('Delete'));
- $form .= form_hidden('cid', $edit['cid']);
+ $form['delete'] = array(type => 'submit', value =>t('Delete'));
+ $form['cid'] = array(type => 'hidden', value => $edit['cid']);
}
- return form($form);
+ return drupal_get_form('aggregator_form_category', $form);
}
function aggregator_save_category($edit) {
@@ -691,9 +708,10 @@ function aggregator_form_feed($edit = array()) {
$edit['refresh'] = 3600;
}
- $form .= form_textfield(t('Title'), 'title', $edit['title'], 60, 64, t('The name of the feed; typically the name of the web site you syndicate content from.'));
- $form .= form_textfield(t('URL'), 'url', $edit['url'], 60, 255, t('The fully-qualified URL of the feed.'));
- $form .= form_select(t('Update interval'), 'refresh', $edit['refresh'], $period, t('The refresh interval indicating how often you want to update this feed. Requires crontab.'));
+
+ $form['title'] = array(type => 'textfield', title => t('Title'), default_value => $edit['title'], size => 60, maxlength => 64, description => t('The name of the feed; typically the name of the web site you syndicate content from.'));
+ $form['url'] = array(type => 'textfield', title => t('URL'), default_value => $edit['url'], size => 60, maxlength => 255, description => t('The fully-qualified URL of the feed.'));
+ $form['refresh'] = array(type => 'select', title => t('Update interval'), default_value => $edit['refresh'], options => $period, description => t('The refresh interval indicating how often you want to update this feed. Requires crontab.'));
// Handling of categories:
$options = array();
@@ -704,17 +722,16 @@ function aggregator_form_feed($edit = array()) {
if ($category->fid) $values[] = check_plain($category->cid);
}
if ($options) {
- $form .= form_checkboxes(t('Categorize news items'), 'category', $values, $options, t('New items in this feed will be automatically filed in the checked categories as they are received.'));
+ $form['category'] = array(type => 'checkboxes', title => t('Categorize news items'), default_value => $values, options => $options, description => t('New items in this feed will be automatically filed in the checked categories as they are received.'));
}
+ $form['submit'] = array(type => 'submit', value =>t('Submit'));
- // Form buttons:
- $form .= form_submit(t('Submit'));
if ($edit['fid']) {
- $form .= form_submit(t('Delete'));
- $form .= form_hidden('fid', $edit['fid']);
+ $form['delete'] = array(type => 'submit', value =>t('Delete'));
+ $form['fid'] = array(type => 'hidden', value => $edit['fid']);
}
- return form($form);
+ return drupal_get_form('aggregator_form_feed', $form);
}
function aggregator_save_feed($edit) {
@@ -786,7 +803,6 @@ function aggregator_view() {
}
function aggregator_edit() {
-
if ($_POST['op'] == t('Submit')) {
if (arg(1) == 'categories') {
aggregator_save_category($_POST['edit']);
@@ -941,83 +957,98 @@ function aggregator_page_category() {
* menu callbacks use this function to print their feeds.
*/
function _aggregator_page_list($sql, $op, $header = '') {
- if (user_access('administer news feeds') && $op == 'categorize') {
- if ($edit = $_POST['edit']) {
- foreach ($edit['categories'] as $iid => $selection) {
- db_query('DELETE FROM {aggregator_category_item} WHERE iid = %d', $iid);
- foreach ($selection as $cid) {
- if ($cid) {
- db_query('INSERT INTO {aggregator_category_item} (cid, iid) VALUES (%d, %d)', $cid, $iid);
- }
- }
- }
- drupal_set_message(t('The categories have been saved.'));
- drupal_goto($_GET['q']);
- }
- else {
- $categorize = true;
- }
- }
+ $categorize = (user_access('administer news feeds') && ($op == 'categorize'));
$output = '<div id="aggregator">';
- if ($header) {
- $output .= $header;
- }
- if ($links) {
- $output .= theme('links', $links);
- }
- $result = pager_query($sql, 20);
+ $form['header'] = array(value => $header);
+ $output .= $form['header'][value];
- $rows = array();
+ $result = pager_query($sql, 20);
$categories = array();
while ($item = db_fetch_object($result)) {
+ $form['items'][$item->iid] = array(value => theme('aggregator_page_item', $item));
+ $output .= $form['items'][$item->iid][value];
+ $form['categories'][$item->iid] = array();
+
if ($categorize) {
+
$categories_result = db_query('SELECT c.cid, c.title, ci.iid FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid AND ci.iid = %d', $item->iid);
- if (variable_get('aggregator_category_selector', 'check') == 'select') {
- $selected = array();
- while ($category = db_fetch_object($categories_result)) {
- if (!$done) {
- $categories[$category->cid] = check_plain($category->title);
- }
- if ($category->iid) {
- $selected[] = $category->cid;
- }
+ $selected = array();
+ while ($category = db_fetch_object($categories_result)) {
+ if (!$done) {
+ $categories[$category->cid] = check_plain($category->title);
}
- $done = true;
- $form = form_select(NULL, 'categories]['. $item->iid, $selected, $categories, NULL, 'size="10"', true);
- }
- else {
- $form = '';
- while ($category = db_fetch_object($categories_result)) {
- $form .= form_checkbox(check_plain($category->title), 'categories]['. $item->iid .'][', $category->cid, !is_null($category->iid));
+ if ($category->iid) {
+ $selected[] = $category->cid;
}
}
- $rows[] = array(theme('aggregator_page_item', $item), array('data' => $form, 'class' => 'categorize-item'));
- }
- else {
- $output .= theme('aggregator_page_item', $item);
+ $done = true;
+ $form['categories'][$item->iid] = array(
+ type => variable_get('aggregator_category_selector', 'checkboxes'),
+ default_value => $selected, options => $categories,
+ size => 10, multiple => true
+ );
}
}
- if ($categorize) {
- $output .= form(theme('table', array('', t('Categorize')), $rows) . form_submit(t('Save categories')));
- }
- $output .= '</div>';
-
- $output .= theme('pager', NULL, 20, 0);
+ $output .= '</div>';
+ $form['submit'] = array(type => 'submit', value => t('Save categories'));
+ $form['pager'] = array(value => theme('pager', NULL, 20, 0));
+ $output .= $form['pager'][value];
// arg(1) is undefined if we are at the top aggregator URL
// is there a better way to do this?
if (!arg(1)) {
- $output .= theme('xml_icon', url('aggregator/rss'));
+ $form['xml_icon'] = array(value => theme('xml_icon', url('aggregator/rss')));
}
elseif (arg(1) == 'categories' && arg(2) && !arg(3)) {
- $output .= theme('xml_icon', url('aggregator/rss/' . arg(2)));
+ $form['xml_icon'] = array(value => theme('xml_icon', url('aggregator/rss/' . arg(2))));
}
+ $output .= $form['xml_icon'][value];
+
+ return ($categorize) ? drupal_get_form('aggregator_page_list', $form) : $output;
+}
+function theme_aggregator_page_list($form) {
+ $output = '<div id="aggregator">';
+ $output .= form_render($form['header']);
+ $rows = array();
+ if ($form['items']) {
+ foreach (element_children($form['items']) as $key) {
+ if (is_array($form['items'][$key])) {
+ $rows[] = array(form_render($form['items'][$key]), array('data' => form_render($form['categories'][$key]), 'class' => 'categorize-item'));
+ }
+ }
+ }
+ $output .= theme('table', array('', t('Categorize')), $rows);
+ $output .= form_render($form['submit']);
+ $output .= '</div>';
+ $output .= form_render($form);
return $output;
}
+function aggregator_page_list_validate($form_id, &$form) {
+ if (!user_access('administer news feeds')) {
+ form_error($form, t('You are not allowed to categorize this feed item.'));
+ }
+}
+
+function aggregator_page_list_execute($form_id, $form) {
+ global $form_values;
+ foreach ($form_values['categories'] as $iid => $selection) {
+ db_query('DELETE FROM {aggregator_category_item} WHERE iid = %d', $iid);
+ foreach ($selection as $cid) {
+ if ($cid) {
+ db_query('INSERT INTO {aggregator_category_item} (cid, iid) VALUES (%d, %d)', $cid, $iid);
+ }
+ }
+ }
+ drupal_set_message(t('The categories have been saved.'));
+ drupal_goto($_GET['q']);
+}
+
+
+
/**
* Menu callback; displays all the feeds used by the aggregator.
*/
diff --git a/modules/block.module b/modules/block.module
index 576ca1a10..ded693cef 100644
--- a/modules/block.module
+++ b/modules/block.module
@@ -201,80 +201,96 @@ function _block_rehash($order_by = array('weight')) {
* Prepare the main block administration form.
*/
function block_admin_display() {
+ global $theme_key;
+ $throttle = module_exist('throttle');
+
+ $blocks = _block_rehash();
+ $block_regions = system_region_list($theme_key);
+
+ $form[action] = arg(3) ? url('admin/block/list/' . $theme_key) : url('admin/block');
+ $form[tree] = TRUE;
+ foreach ($blocks as $block) {
+ $form[$block['module']][$block['delta']]['info'] = array(type => 'markup', value => $block['info']);
+ $form[$block['module']][$block['delta']]['status'] = array(type => 'checkbox', default_value => $block['status']);
+ $form[$block['module']][$block['delta']]['theme'] = array(type => 'hidden', value => $theme_key);
+ $form[$block['module']][$block['delta']]['weight'] = array(type => 'weight', default_value => $block['weight']);
+ $form[$block['module']][$block['delta']]['region'] = array(type => 'select', default_value => isset($block['region']) ? $block['region'] : system_default_region(), options => $block_regions);
+
+ if ($throttle) {
+ $form[$block['module']][$block['delta']]['throttle'] = array(type => 'checkbox', default_value => $block['throttle']);
+ }
+ $form[$block['module']][$block['delta']]['configure'] = array(type => 'markup', value => l(t('configure'), 'admin/block/configure/'. $block['module'] .'/'. $block['delta']));
+ if ($block['module'] == 'block') {
+ $form[$block['module']][$block['delta']]['delete'] = array(type => 'markup', value => l(t('delete'), 'admin/block/delete/'. $block['delta']));
+ }
+ }
+ $form['submit'] = array(type => 'submit', value => t('Save blocks'));
+
+ return drupal_get_form('block_admin_display', $form);
+}
+
+function theme_block_admin_display($form) {
+
global $theme_key, $custom_theme;
+ $throttle = module_exist('throttle');
// If non-default theme configuration has been selected, set the custom theme.
if (arg(3)) {
$custom_theme = arg(3);
init_theme();
}
-
- $blocks = _block_rehash();
-
$block_regions = system_region_list($theme_key);
-
+
// Highlight regions on page, to provide visual reference.
foreach ($block_regions as $key => $value) {
drupal_set_content($key, '<div class="block-region">' . $value . '</div>');
}
-
- $header = array(t('Block'), t('Enabled'), t('Weight'), t('Placement'));
- if (module_exist('throttle')) {
- $header[] = t('Throttle');
- }
- $header[] = array('data' => t('Operations'), 'colspan' => 2);
-
$regions = array();
$disabled = array();
-
- foreach ($blocks as $block) {
- if ($block['module'] == 'block') {
- $delete = l(t('delete'), 'admin/block/delete/'. $block['delta']);
- }
- else {
- $delete = '';
- }
-
- $row = array(array('data' => $block['info'], 'class' => 'block'),
- form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][status', 1, $block['status']) . form_hidden($block['module'] .']['. $block['delta'] .'][theme', $theme_key),
- form_weight(NULL, $block['module'] .']['. $block['delta'] .'][weight', $block['weight']),
- form_select(NULL, $block['module'] .']['. $block['delta'] .'][region', isset($block['region']) ? $block['region'] : system_default_region(),
- $block_regions));
-
- if (module_exist('throttle')) {
- $row[] = form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][throttle', 1, $block['throttle']);
- }
- $row[] = l(t('configure'), 'admin/block/configure/'. $block['module'] .'/'. $block['delta']);
- $row[] = $delete;
- if ($block['status']) {
- foreach ($block_regions as $key => $value) {
- if ($block['region'] == $key) {
- $regions[$key][] = $row;
+ foreach (element_children($form) as $module) {
+ // Don't take form control structures
+ if (is_array($form[$module])) {
+ foreach ($form[$module] as $delta => $element) {
+ // Only take form elements that are blocks
+ if (is_array($form[$module][$delta]['info'])) {
+ $block = $form[$module][$delta];
+ $row = array(array('data' => form_render($block['info']), 'class' => 'block'), form_render($block['status']) . form_render($block['theme']), form_render($block['weight']), form_render($block['region']));
+ if ($throttle) {
+ $row[] = form_render($block['throttle']);
+ }
+ $row[] = form_render($block['configure']);
+ $row[] = $block['delete'] ? form_render($block['delete']) : '';
+ if ($block['status'][default_value]) {
+ $regions[$block['region'][default_value]][] = $row;
+ }
+ else if ($block['region'][default_value] <= 1) {
+ $disabled[] = $row;
+ }
}
}
}
- else if ($block['region'] <= 1) {
- $disabled[] = $row;
- }
}
-
+
$rows = array();
-
if (count($regions)) {
foreach ($regions as $region => $row) {
$region_title = t('%region', array ('%region' => ucfirst($block_regions[$region])));
- $rows[] = array(array('data' => $region_title, 'class' => 'region', 'colspan' => (module_exist('throttle') ? 7 : 6)));
+ $rows[] = array(array('data' => $region_title, 'class' => 'region', 'colspan' => ($throttle ? 7 : 6)));
$rows = array_merge($rows, $row);
}
}
if (count($disabled)) {
- $rows[] = array(array('data' => t('Disabled'), 'class' => 'region', 'colspan' => (module_exist('throttle') ? 7 : 6)));
+ $rows[] = array(array('data' => t('Disabled'), 'class' => 'region', 'colspan' => ($throttle ? 7 : 6)));
$rows = array_merge($rows, $disabled);
}
+ $header = array(t('Block'), t('Enabled'), t('Weight'), t('Placement'));
+ if ($throttle) {
+ $header[] = t('Throttle');
+ }
+ $header[] = array('data' => t('Operations'), 'colspan' => 2);
$output = theme('table', $header, $rows, array('id' => 'blocks'));
- $output .= form_submit(t('Save blocks'));
-
- return form($output, 'post', arg(3) ? url('admin/block/list/' . $theme_key) : url('admin/block'));
+ $output .= form_render($form['submit']);
+ return $output;
}
function block_box_get($bid) {
@@ -304,7 +320,15 @@ function block_admin_configure($module = NULL, $delta = 0) {
// Module-specific block configurations.
if ($settings = module_invoke($module, 'block', 'configure', $delta)) {
- $form = form_group(t('Block specific settings'), $settings);
+ $form['block_settings'] = array(type => 'fieldset',
+ title => t('Block specific settings'),
+ collapsible => true,
+ collapsed => false,
+ weight => 0);
+
+ foreach ($settings as $k => $v) {
+ $form['block_settings'][$k] = $v;
+ }
}
// Get the block subject for the page title.
@@ -312,16 +336,46 @@ function block_admin_configure($module = NULL, $delta = 0) {
drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info'])));
// Standard block configurations.
- $group_1 = form_radios(t('Custom visibility settings'), 'custom', $edit['custom'], array(t('Users cannot control whether or not they see this block.'), t('Show this block by default, but let individual users hide it.'), t('Hide this block by default but let individual users show it.')), t('Allow individual users to customize the visibility of this block in their account settings.'));
- $group_2 = form_radios(t('Show block on specific pages'), 'visibility', $edit['visibility'], array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'), t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).')));
- $group_2 .= form_textarea(t('Pages'), 'pages', $edit['pages'], 60, 5, t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog1 for every personal blog. %front is the front page. If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.", array('%blog' => theme('placeholder', 'blog'), '%blog1' => theme('placeholder', 'blog/*'), '%front' => theme('placeholder', '<front>'), '%php' => theme('placeholder', '<?php ?>'))));
-
- $form .= form_group(t('User specific visibility settings'), $group_1);
- $form .= form_group(t('Page specific visibility settings'), $group_2);
-
- $form .= form_submit(t('Save block'));
-
- return form($form);
+
+ $form['user_vis_settings'] = array(type => 'fieldset',
+ title => t('User specific visibility settings'),
+ collapsible => true,
+ collapsed => false,
+ weight => 0);
+
+ $form['user_vis_settings']['custom'] = array(
+ type => 'radios',
+ title => t('Custom visibility settings'),
+ default_value => $edit['custom'],
+ options => array(t('Users cannot control whether or not they see this block.'), t('Show this block by default, but let individual users hide it.'), t('Hide this block by default but let individual users show it.')), t('Allow individual users to customize the visibility of this block in their account settings.'),
+ default_value => $edit['custom']);
+
+
+ $form['page_vis_settings'] = array(type => 'fieldset',
+ title => t('Page specific visibility settings'),
+ collapsible => true,
+ collapsed => false,
+ weight => 0);
+
+
+ $form['page_vis_settings']['visibility'] = array(
+ type => 'radios',
+ title => t('Show block on specific pages'),
+ default_value => $edit['visibility'],
+ options => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'), t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).')),
+ default_value => $edit['visibility']);
+
+ $form['page_vis_settings']['pages'] = array(
+ type => 'textarea',
+ title => t('Pages'),
+ default_value => $edit['pages'],
+ cols => 60,
+ rows => 5,
+ description => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog1 for every personal blog. %front is the front page. If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.", array('%blog' => theme('placeholder', 'blog'), '%blog1' => theme('placeholder', 'blog/*'), '%front' => theme('placeholder', '<front>'), '%php' => theme('placeholder', '<?php ?>'))));
+
+ $form['submit'] = array(type => 'submit', value => t('Save block'));
+
+ return drupal_get_form('block_config', $form);
}
}
@@ -341,45 +395,42 @@ function block_box_add() {
// deliberate no break
default:
$form = block_box_form($edit);
- $form .= form_submit(t('Save block'));
- $output .= form($form);
+ $form['submit'] = array(type => 'submit', value => t('Save block'));
}
- return $output;
+ return drupal_get_form('block_box_add', $form);
}
/**
- * Menu callback; confirm and delete custom blocks.
+ * Menu callback; confirm deletion of custom blocks.
*/
function block_box_delete($bid = 0) {
- $op = $_POST['op'];
$box = block_box_get($bid);
- $info = $box['info'] ? $box['info'] : $box['title'];
-
- if ($_POST['edit']['confirm']) {
- db_query('DELETE FROM {boxes} WHERE bid = %d', $bid);
- drupal_set_message(t('The block %name has been removed.', array('%name' => theme('placeholder', $info))));
- cache_clear_all();
- drupal_goto('admin/block');
- }
- else {
- $output = theme('confirm',
- t('Are you sure you want to delete the block %name?', array('%name' => theme('placeholder', $info))),
- 'admin/block',
- NULL,
- t('Delete'));
- }
+ $form['info'] = array(type => 'hidden', value => $box['info'] ? $box['info'] : $box['title']);
+ $form['bid'] = array(type => 'hidden', value => $bid);
- return $output;
+ return confirm_form('block_box_delete_confirm', $form, t('Are you sure you want to delete the block %name?', array('%name' => theme('placeholder', $info))), 'admin/block', '', t('Delete'), t('Cancel'));
}
+/**
+ * Deletion of custom blocks.
+ */
+function block_box_delete_confirm_execute($form_id, $edit) {
+ $form = $GLOBALS['form_values'];
+ db_query('DELETE FROM {boxes} WHERE bid = %d', $form['bid']);
+ drupal_set_message(t('The block %name has been removed.', array('%name' => theme('placeholder', $form['info']))));
+ cache_clear_all();
+ drupal_goto('admin/block');
+};
+
+
function block_box_form($edit = array()) {
- $output = form_textfield(t('Block title'), 'title', $edit['title'], 60, 64, t('The title of the block as shown to the user.'));
- $output .= filter_form('format', $edit['format']);
- $output .= form_textarea(t('Block body'), 'body', $edit['body'], 60, 15, t('The content of the block as shown to the user.'));
- $output .= form_textfield(t('Block description'), 'info', $edit['info'], 60, 64, t('A brief description of your block. Used on the <a href="%overview">block overview page</a>.', array('%overview' => url('admin/block'))), NULL, TRUE);
+ $form['title'] = array(type => 'textfield', title => t('Block title'), default_value => $edit['title'], size => 60, maxlength => 64, description => t('The title of the block as shown to the user.'));
+ $form['format'] = filter_form($edit['format']);
+ $form['body'] = array(type => 'textarea', title => t('Block body'), default_value => $edit['body'], cols => 60, rows => 15, description => t('The content of the block as shown to the user.'));
+ $form['info'] = array(type => 'textfield', title => t('Block description'), default_value => $edit['info'], size => 60, maxlength => 64, description => t('A brief description of your block. Used on the <a href="%overview">block overview page</a>.', array('%overview' => url('admin/block'))), required => TRUE);
- return $output;
+ return $form;
}
function block_box_save($edit, $delta = NULL) {
@@ -427,16 +478,17 @@ function block_user($type, $edit, &$user, $category = NULL) {
case 'form':
if ($category == 'account') {
$result = db_query('SELECT * FROM {blocks} WHERE status = 1 AND custom != 0 ORDER BY weight, module, delta');
-
+ $form['block'] = array(type => 'fieldset', title => t('Block configuration'), weight => 3, collapsible => TRUE, collapsed => FALSE, tree => TRUE);
while ($block = db_fetch_object($result)) {
$data = module_invoke($block->module, 'block', 'list');
if ($data[$block->delta]['info']) {
- $form .= form_checkbox($data[$block->delta]['info'], 'block]['. $block->module .']['. $block->delta, 1, isset($user->block[$block->module][$block->delta]) ? $user->block[$block->module][$block->delta] : ($block->custom == 1));
+ $return = TRUE;
+ $form['block'][$block->module][$block->delta] = array(type => 'checkbox', title => $data[$block->delta]['info'], default_value => isset($user->block[$block->module][$block->delta]) ? $user->block[$block->module][$block->delta] : ($block->custom == 1));
}
}
- if (isset($form)) {
- return array(array('title' => t('Block configuration'), 'data' => $form, 'weight' => 2));
+ if ($return) {
+ return $form;
}
}
diff --git a/modules/block/block.module b/modules/block/block.module
index 576ca1a10..ded693cef 100644
--- a/modules/block/block.module
+++ b/modules/block/block.module
@@ -201,80 +201,96 @@ function _block_rehash($order_by = array('weight')) {
* Prepare the main block administration form.
*/
function block_admin_display() {
+ global $theme_key;
+ $throttle = module_exist('throttle');
+
+ $blocks = _block_rehash();
+ $block_regions = system_region_list($theme_key);
+
+ $form[action] = arg(3) ? url('admin/block/list/' . $theme_key) : url('admin/block');
+ $form[tree] = TRUE;
+ foreach ($blocks as $block) {
+ $form[$block['module']][$block['delta']]['info'] = array(type => 'markup', value => $block['info']);
+ $form[$block['module']][$block['delta']]['status'] = array(type => 'checkbox', default_value => $block['status']);
+ $form[$block['module']][$block['delta']]['theme'] = array(type => 'hidden', value => $theme_key);
+ $form[$block['module']][$block['delta']]['weight'] = array(type => 'weight', default_value => $block['weight']);
+ $form[$block['module']][$block['delta']]['region'] = array(type => 'select', default_value => isset($block['region']) ? $block['region'] : system_default_region(), options => $block_regions);
+
+ if ($throttle) {
+ $form[$block['module']][$block['delta']]['throttle'] = array(type => 'checkbox', default_value => $block['throttle']);
+ }
+ $form[$block['module']][$block['delta']]['configure'] = array(type => 'markup', value => l(t('configure'), 'admin/block/configure/'. $block['module'] .'/'. $block['delta']));
+ if ($block['module'] == 'block') {
+ $form[$block['module']][$block['delta']]['delete'] = array(type => 'markup', value => l(t('delete'), 'admin/block/delete/'. $block['delta']));
+ }
+ }
+ $form['submit'] = array(type => 'submit', value => t('Save blocks'));
+
+ return drupal_get_form('block_admin_display', $form);
+}
+
+function theme_block_admin_display($form) {
+
global $theme_key, $custom_theme;
+ $throttle = module_exist('throttle');
// If non-default theme configuration has been selected, set the custom theme.
if (arg(3)) {
$custom_theme = arg(3);
init_theme();
}
-
- $blocks = _block_rehash();
-
$block_regions = system_region_list($theme_key);
-
+
// Highlight regions on page, to provide visual reference.
foreach ($block_regions as $key => $value) {
drupal_set_content($key, '<div class="block-region">' . $value . '</div>');
}
-
- $header = array(t('Block'), t('Enabled'), t('Weight'), t('Placement'));
- if (module_exist('throttle')) {
- $header[] = t('Throttle');
- }
- $header[] = array('data' => t('Operations'), 'colspan' => 2);
-
$regions = array();
$disabled = array();
-
- foreach ($blocks as $block) {
- if ($block['module'] == 'block') {
- $delete = l(t('delete'), 'admin/block/delete/'. $block['delta']);
- }
- else {
- $delete = '';
- }
-
- $row = array(array('data' => $block['info'], 'class' => 'block'),
- form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][status', 1, $block['status']) . form_hidden($block['module'] .']['. $block['delta'] .'][theme', $theme_key),
- form_weight(NULL, $block['module'] .']['. $block['delta'] .'][weight', $block['weight']),
- form_select(NULL, $block['module'] .']['. $block['delta'] .'][region', isset($block['region']) ? $block['region'] : system_default_region(),
- $block_regions));
-
- if (module_exist('throttle')) {
- $row[] = form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][throttle', 1, $block['throttle']);
- }
- $row[] = l(t('configure'), 'admin/block/configure/'. $block['module'] .'/'. $block['delta']);
- $row[] = $delete;
- if ($block['status']) {
- foreach ($block_regions as $key => $value) {
- if ($block['region'] == $key) {
- $regions[$key][] = $row;
+ foreach (element_children($form) as $module) {
+ // Don't take form control structures
+ if (is_array($form[$module])) {
+ foreach ($form[$module] as $delta => $element) {
+ // Only take form elements that are blocks
+ if (is_array($form[$module][$delta]['info'])) {
+ $block = $form[$module][$delta];
+ $row = array(array('data' => form_render($block['info']), 'class' => 'block'), form_render($block['status']) . form_render($block['theme']), form_render($block['weight']), form_render($block['region']));
+ if ($throttle) {
+ $row[] = form_render($block['throttle']);
+ }
+ $row[] = form_render($block['configure']);
+ $row[] = $block['delete'] ? form_render($block['delete']) : '';
+ if ($block['status'][default_value]) {
+ $regions[$block['region'][default_value]][] = $row;
+ }
+ else if ($block['region'][default_value] <= 1) {
+ $disabled[] = $row;
+ }
}
}
}
- else if ($block['region'] <= 1) {
- $disabled[] = $row;
- }
}
-
+
$rows = array();
-
if (count($regions)) {
foreach ($regions as $region => $row) {
$region_title = t('%region', array ('%region' => ucfirst($block_regions[$region])));
- $rows[] = array(array('data' => $region_title, 'class' => 'region', 'colspan' => (module_exist('throttle') ? 7 : 6)));
+ $rows[] = array(array('data' => $region_title, 'class' => 'region', 'colspan' => ($throttle ? 7 : 6)));
$rows = array_merge($rows, $row);
}
}
if (count($disabled)) {
- $rows[] = array(array('data' => t('Disabled'), 'class' => 'region', 'colspan' => (module_exist('throttle') ? 7 : 6)));
+ $rows[] = array(array('data' => t('Disabled'), 'class' => 'region', 'colspan' => ($throttle ? 7 : 6)));
$rows = array_merge($rows, $disabled);
}
+ $header = array(t('Block'), t('Enabled'), t('Weight'), t('Placement'));
+ if ($throttle) {
+ $header[] = t('Throttle');
+ }
+ $header[] = array('data' => t('Operations'), 'colspan' => 2);
$output = theme('table', $header, $rows, array('id' => 'blocks'));
- $output .= form_submit(t('Save blocks'));
-
- return form($output, 'post', arg(3) ? url('admin/block/list/' . $theme_key) : url('admin/block'));
+ $output .= form_render($form['submit']);
+ return $output;
}
function block_box_get($bid) {
@@ -304,7 +320,15 @@ function block_admin_configure($module = NULL, $delta = 0) {
// Module-specific block configurations.
if ($settings = module_invoke($module, 'block', 'configure', $delta)) {
- $form = form_group(t('Block specific settings'), $settings);
+ $form['block_settings'] = array(type => 'fieldset',
+ title => t('Block specific settings'),
+ collapsible => true,
+ collapsed => false,
+ weight => 0);
+
+ foreach ($settings as $k => $v) {
+ $form['block_settings'][$k] = $v;
+ }
}
// Get the block subject for the page title.
@@ -312,16 +336,46 @@ function block_admin_configure($module = NULL, $delta = 0) {
drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info'])));
// Standard block configurations.
- $group_1 = form_radios(t('Custom visibility settings'), 'custom', $edit['custom'], array(t('Users cannot control whether or not they see this block.'), t('Show this block by default, but let individual users hide it.'), t('Hide this block by default but let individual users show it.')), t('Allow individual users to customize the visibility of this block in their account settings.'));
- $group_2 = form_radios(t('Show block on specific pages'), 'visibility', $edit['visibility'], array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'), t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).')));
- $group_2 .= form_textarea(t('Pages'), 'pages', $edit['pages'], 60, 5, t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog1 for every personal blog. %front is the front page. If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.", array('%blog' => theme('placeholder', 'blog'), '%blog1' => theme('placeholder', 'blog/*'), '%front' => theme('placeholder', '<front>'), '%php' => theme('placeholder', '<?php ?>'))));
-
- $form .= form_group(t('User specific visibility settings'), $group_1);
- $form .= form_group(t('Page specific visibility settings'), $group_2);
-
- $form .= form_submit(t('Save block'));
-
- return form($form);
+
+ $form['user_vis_settings'] = array(type => 'fieldset',
+ title => t('User specific visibility settings'),
+ collapsible => true,
+ collapsed => false,
+ weight => 0);
+
+ $form['user_vis_settings']['custom'] = array(
+ type => 'radios',
+ title => t('Custom visibility settings'),
+ default_value => $edit['custom'],
+ options => array(t('Users cannot control whether or not they see this block.'), t('Show this block by default, but let individual users hide it.'), t('Hide this block by default but let individual users show it.')), t('Allow individual users to customize the visibility of this block in their account settings.'),
+ default_value => $edit['custom']);
+
+
+ $form['page_vis_settings'] = array(type => 'fieldset',
+ title => t('Page specific visibility settings'),
+ collapsible => true,
+ collapsed => false,
+ weight => 0);
+
+
+ $form['page_vis_settings']['visibility'] = array(
+ type => 'radios',
+ title => t('Show block on specific pages'),
+ default_value => $edit['visibility'],
+ options => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'), t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).')),
+ default_value => $edit['visibility']);
+
+ $form['page_vis_settings']['pages'] = array(
+ type => 'textarea',
+ title => t('Pages'),
+ default_value => $edit['pages'],
+ cols => 60,
+ rows => 5,
+ description => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog1 for every personal blog. %front is the front page. If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.", array('%blog' => theme('placeholder', 'blog'), '%blog1' => theme('placeholder', 'blog/*'), '%front' => theme('placeholder', '<front>'), '%php' => theme('placeholder', '<?php ?>'))));
+
+ $form['submit'] = array(type => 'submit', value => t('Save block'));
+
+ return drupal_get_form('block_config', $form);
}
}
@@ -341,45 +395,42 @@ function block_box_add() {
// deliberate no break
default:
$form = block_box_form($edit);
- $form .= form_submit(t('Save block'));
- $output .= form($form);
+ $form['submit'] = array(type => 'submit', value => t('Save block'));
}
- return $output;
+ return drupal_get_form('block_box_add', $form);
}
/**
- * Menu callback; confirm and delete custom blocks.
+ * Menu callback; confirm deletion of custom blocks.
*/
function block_box_delete($bid = 0) {
- $op = $_POST['op'];
$box = block_box_get($bid);
- $info = $box['info'] ? $box['info'] : $box['title'];
-
- if ($_POST['edit']['confirm']) {
- db_query('DELETE FROM {boxes} WHERE bid = %d', $bid);
- drupal_set_message(t('The block %name has been removed.', array('%name' => theme('placeholder', $info))));
- cache_clear_all();
- drupal_goto('admin/block');
- }
- else {
- $output = theme('confirm',
- t('Are you sure you want to delete the block %name?', array('%name' => theme('placeholder', $info))),
- 'admin/block',
- NULL,
- t('Delete'));
- }
+ $form['info'] = array(type => 'hidden', value => $box['info'] ? $box['info'] : $box['title']);
+ $form['bid'] = array(type => 'hidden', value => $bid);
- return $output;
+ return confirm_form('block_box_delete_confirm', $form, t('Are you sure you want to delete the block %name?', array('%name' => theme('placeholder', $info))), 'admin/block', '', t('Delete'), t('Cancel'));
}
+/**
+ * Deletion of custom blocks.
+ */
+function block_box_delete_confirm_execute($form_id, $edit) {
+ $form = $GLOBALS['form_values'];
+ db_query('DELETE FROM {boxes} WHERE bid = %d', $form['bid']);
+ drupal_set_message(t('The block %name has been removed.', array('%name' => theme('placeholder', $form['info']))));
+ cache_clear_all();
+ drupal_goto('admin/block');
+};
+
+
function block_box_form($edit = array()) {
- $output = form_textfield(t('Block title'), 'title', $edit['title'], 60, 64, t('The title of the block as shown to the user.'));
- $output .= filter_form('format', $edit['format']);
- $output .= form_textarea(t('Block body'), 'body', $edit['body'], 60, 15, t('The content of the block as shown to the user.'));
- $output .= form_textfield(t('Block description'), 'info', $edit['info'], 60, 64, t('A brief description of your block. Used on the <a href="%overview">block overview page</a>.', array('%overview' => url('admin/block'))), NULL, TRUE);
+ $form['title'] = array(type => 'textfield', title => t('Block title'), default_value => $edit['title'], size => 60, maxlength => 64, description => t('The title of the block as shown to the user.'));
+ $form['format'] = filter_form($edit['format']);
+ $form['body'] = array(type => 'textarea', title => t('Block body'), default_value => $edit['body'], cols => 60, rows => 15, description => t('The content of the block as shown to the user.'));
+ $form['info'] = array(type => 'textfield', title => t('Block description'), default_value => $edit['info'], size => 60, maxlength => 64, description => t('A brief description of your block. Used on the <a href="%overview">block overview page</a>.', array('%overview' => url('admin/block'))), required => TRUE);
- return $output;
+ return $form;
}
function block_box_save($edit, $delta = NULL) {
@@ -427,16 +478,17 @@ function block_user($type, $edit, &$user, $category = NULL) {
case 'form':
if ($category == 'account') {
$result = db_query('SELECT * FROM {blocks} WHERE status = 1 AND custom != 0 ORDER BY weight, module, delta');
-
+ $form['block'] = array(type => 'fieldset', title => t('Block configuration'), weight => 3, collapsible => TRUE, collapsed => FALSE, tree => TRUE);
while ($block = db_fetch_object($result)) {
$data = module_invoke($block->module, 'block', 'list');
if ($data[$block->delta]['info']) {
- $form .= form_checkbox($data[$block->delta]['info'], 'block]['. $block->module .']['. $block->delta, 1, isset($user->block[$block->module][$block->delta]) ? $user->block[$block->module][$block->delta] : ($block->custom == 1));
+ $return = TRUE;
+ $form['block'][$block->module][$block->delta] = array(type => 'checkbox', title => $data[$block->delta]['info'], default_value => isset($user->block[$block->module][$block->delta]) ? $user->block[$block->module][$block->delta] : ($block->custom == 1));
}
}
- if (isset($form)) {
- return array(array('title' => t('Block configuration'), 'data' => $form, 'weight' => 2));
+ if ($return) {
+ return $form;
}
}
diff --git a/modules/blog.module b/modules/blog.module
index 43a1760dc..4ac9240f7 100644
--- a/modules/blog.module
+++ b/modules/blog.module
@@ -42,7 +42,11 @@ function blog_access($op, $node) {
*/
function blog_user($type, &$edit, &$user) {
if ($type == 'view' && user_access('edit own blog', $user)) {
- return array(t('History') => array('blog' => form_item(t('Blog'), l(t('view recent blog entries'), "blog/$user->uid", array('title' => t("Read %username's latest blog entries.", array('%username' => $user->name)))))));
+ $form['blog'] = array(
+ type => 'item', title => t('Blog'),
+ value => l(t('view recent blog entries'), "blog/$user->uid", array('title' => t("Read %username's latest blog entries.", array('%username' => $user->name))))
+ );
+ return array(t('History') => $form);
}
}
@@ -196,7 +200,6 @@ function blog_form(&$node) {
global $nid;
$iid = $_GET['iid'];
- $output = form_textfield(t('Title'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
if (empty($node->body)) {
/*
@@ -213,16 +216,17 @@ function blog_form(&$node) {
// Note: $item->description has been validated on aggregation.
$node->body = '<a href="'. check_url($item->link) .'">'. check_plain($item->title) .'</a> - <em>'. $item->description .'</em> [<a href="'. check_url($item->flink) .'">'. check_plain($item->ftitle) ."</a>]\n";
}
+
}
if (function_exists('taxonomy_node_form')) {
- $output .= implode('', taxonomy_node_form('blog', $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);
-
- return $output;
+ $form['title'] = array(type => 'textfield', title => t('Title'), size => 60, maxlength => 128, required => TRUE, default_value => $node->title);
+ $form['body'] = array(type => 'textarea', title => t('Body'), default_value => $node->body, required => TRUE);
+ $form = array_merge($form, filter_form($node->format));
+ return $form;
}
/**
diff --git a/modules/blog/blog.module b/modules/blog/blog.module
index 43a1760dc..4ac9240f7 100644
--- a/modules/blog/blog.module
+++ b/modules/blog/blog.module
@@ -42,7 +42,11 @@ function blog_access($op, $node) {
*/
function blog_user($type, &$edit, &$user) {
if ($type == 'view' && user_access('edit own blog', $user)) {
- return array(t('History') => array('blog' => form_item(t('Blog'), l(t('view recent blog entries'), "blog/$user->uid", array('title' => t("Read %username's latest blog entries.", array('%username' => $user->name)))))));
+ $form['blog'] = array(
+ type => 'item', title => t('Blog'),
+ value => l(t('view recent blog entries'), "blog/$user->uid", array('title' => t("Read %username's latest blog entries.", array('%username' => $user->name))))
+ );
+ return array(t('History') => $form);
}
}
@@ -196,7 +200,6 @@ function blog_form(&$node) {
global $nid;
$iid = $_GET['iid'];
- $output = form_textfield(t('Title'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
if (empty($node->body)) {
/*
@@ -213,16 +216,17 @@ function blog_form(&$node) {
// Note: $item->description has been validated on aggregation.
$node->body = '<a href="'. check_url($item->link) .'">'. check_plain($item->title) .'</a> - <em>'. $item->description .'</em> [<a href="'. check_url($item->flink) .'">'. check_plain($item->ftitle) ."</a>]\n";
}
+
}
if (function_exists('taxonomy_node_form')) {
- $output .= implode('', taxonomy_node_form('blog', $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);
-
- return $output;
+ $form['title'] = array(type => 'textfield', title => t('Title'), size => 60, maxlength => 128, required => TRUE, default_value => $node->title);
+ $form['body'] = array(type => 'textarea', title => t('Body'), default_value => $node->body, required => TRUE);
+ $form = array_merge($form, filter_form($node->format));
+ return $form;
}
/**
diff --git a/modules/blogapi.module b/modules/blogapi.module
index e983177be..a85e1d485 100644
--- a/modules/blogapi.module
+++ b/modules/blogapi.module
@@ -548,10 +548,21 @@ function blogapi_blogger_title(&$contents) {
}
function blogapi_settings() {
+ $form['blogapi_engine'] = array(
+ type => 'select', title => t('XML-RPC Engine'), default_value => variable_get('blogapi_engine', 0),
+ options => array(0 => 'Blogger', 1 => 'MetaWeblog', 2 => 'Movabletype'),
+ description => t('RSD or Really-Simple-Discovery is a mechanism which allows external blogger tools to discover the APIs they can use to interact with Drupal. Here you can set the preferred method for blogger tools to interact with your site. The common XML-RPC engines are Blogger, MetaWeblog and Movabletype. If you are not sure which is the correct setting, choose Blogger.')
+ );
+
$node_types = node_get_types();
$defaults = isset($node_types['blog']) ? array('blog') : array();
- $output .= form_checkboxes(t('Blog types'), "blogapi_node_types", variable_get('blogapi_node_types', $defaults), $node_types, t('Select the content types for which you wish to enable posting via blogapi. Each type will appear as a different "blog" in the client application (if supported).'), 0, 1);
- return $output;
+ $form['blogapi_node_types'] = array(
+ type => 'checkboxes', title => t('Blog types'), required => TRUE,
+ default_value => variable_get('blogapi_node_types', $defaults), options => $node_types,
+ description => t('Select the content types for which you wish to enable posting via blogapi. Each type will appear as a different "blog" in the client application (if supported).')
+ );
+
+ return $form;
}
function blogapi_menu($may_cache) {
diff --git a/modules/blogapi/blogapi.module b/modules/blogapi/blogapi.module
index e983177be..a85e1d485 100644
--- a/modules/blogapi/blogapi.module
+++ b/modules/blogapi/blogapi.module
@@ -548,10 +548,21 @@ function blogapi_blogger_title(&$contents) {
}
function blogapi_settings() {
+ $form['blogapi_engine'] = array(
+ type => 'select', title => t('XML-RPC Engine'), default_value => variable_get('blogapi_engine', 0),
+ options => array(0 => 'Blogger', 1 => 'MetaWeblog', 2 => 'Movabletype'),
+ description => t('RSD or Really-Simple-Discovery is a mechanism which allows external blogger tools to discover the APIs they can use to interact with Drupal. Here you can set the preferred method for blogger tools to interact with your site. The common XML-RPC engines are Blogger, MetaWeblog and Movabletype. If you are not sure which is the correct setting, choose Blogger.')
+ );
+
$node_types = node_get_types();
$defaults = isset($node_types['blog']) ? array('blog') : array();
- $output .= form_checkboxes(t('Blog types'), "blogapi_node_types", variable_get('blogapi_node_types', $defaults), $node_types, t('Select the content types for which you wish to enable posting via blogapi. Each type will appear as a different "blog" in the client application (if supported).'), 0, 1);
- return $output;
+ $form['blogapi_node_types'] = array(
+ type => 'checkboxes', title => t('Blog types'), required => TRUE,
+ default_value => variable_get('blogapi_node_types', $defaults), options => $node_types,
+ description => t('Select the content types for which you wish to enable posting via blogapi. Each type will appear as a different "blog" in the client application (if supported).')
+ );
+
+ return $form;
}
function blogapi_menu($may_cache) {
diff --git a/modules/book.module b/modules/book.module
index 2b7a33eea..0d5c0ded2 100644
--- a/modules/book.module
+++ b/modules/book.module
@@ -233,28 +233,39 @@ function book_validate(&$node) {
* Implementation of hook_form().
*/
function book_form(&$node) {
- $output = form_textfield(t('Title'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
- $output .= form_select(t('Parent'), 'parent', ($node->parent ? $node->parent : arg(4)), book_toc($node->nid), t('The parent that this page belongs in. Note that pages whose parent is &lt;top-level&gt; are regarded as independent, top-level books.'));
+ $form['parent'] = array(
+ type => 'select', title => t('Parent'), default_value => ($node->parent ? $node->parent : arg(4)), options => book_toc($node->nid), weight => -15,
+ description => t('The parent that this page belongs in. Note that pages whose parent is &lt;top-level&gt; are regarded as independent, top-level books.')
+ );
if (function_exists('taxonomy_node_form')) {
- $output .= implode('', taxonomy_node_form('book', $node));
+ $form['taxonomy'] = taxonomy_node_form('book', $node);
}
- $output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, '', NULL, TRUE);
- $output .= filter_form('format', $node->format);
+ $form['title'] = array(type => 'textfield', title => t('Title'), size => 60, maxlength => 128, required => TRUE, default_value => $node->title);
+ $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.'));
+ $form['log'] = array(
+ type => 'textarea', title => t('Log message'), default_value => $node->log, rows => 5, weight => 19,
+ description => t('An explanation of the additions or updates being made to help other authors understand your motivations.')
+ );
if (user_access('administer nodes')) {
- $output .= form_weight(t('Weight'), 'weight', $node->weight, 15, t('Pages at a given level are ordered first by weight and then by title.'));
+ $form['weight'] = array(
+ type => 'weight', title => t('Weight'), default_value => $node->weight, delta => 15, weight => -14,
+ description => t('Pages at a given level are ordered first by weight and then by title.')
+ );
}
else {
// If a regular user updates a book page, we create a new revision
// authored by that user:
- $output .= form_hidden('revision', 1);
+ $form['revision'] = array(type => 'hidden', value => 1);
}
- return $output;
+ return $form;
}
/**
@@ -291,21 +302,32 @@ function book_outline() {
default:
$page = db_fetch_object(db_query('SELECT * FROM {book} WHERE vid = %d', $node->vid));
-
- $output = form_select(t('Parent'), 'parent', $page->parent, book_toc($node->nid), t('The parent page in the book.'));
- $output .= form_weight(t('Weight'), 'weight', $page->weight, 15, t('Pages at a given level are ordered first by weight and then by title.'));
- $output .= form_textarea(t('Log message'), 'log', $node->log, 60, 5, t('An explanation to help other authors understand your motivations to put this post into the book.'));
+
+ $form['parent'] = array(
+ type => 'select', title => t('Parent'), default_value => $page->parent,
+ options => book_toc($node->nid), description => t('The parent page in the book.')
+ );
+
+ $form['weight'] = array(
+ type => 'weight', title => t('Weight'), default_value => $page->weight, delta => 15,
+ description => t('Pages at a given level are ordered first by weight and then by title.')
+ );
+
+ $form['log'] = array(
+ type => 'textarea', title => t('Log message'), cols => 60, rows => 5,
+ default_value => $node->log, description => t('An explanation to help other authors understand your motivations to put this post into the book.')
+ );
if ($page->nid) {
- $output .= form_submit(t('Update book outline'));
- $output .= form_submit(t('Remove from book outline'));
+ $form['update'] = array(type => 'submit', value => t('Update book outline'));
+ $form['remove'] = array(type => 'submit', value => t('Remove from book outline'));
}
else {
- $output .= form_submit(t('Add to book outline'));
+ $form['add'] = array(type => 'submit', value => t('Add to book outline'));
}
drupal_set_title(check_plain($node->title));
- return form($output);
+ return drupal_get_form('book_outline', $form);
}
}
}
@@ -933,7 +955,19 @@ function book_node_visitor_opml_post($node, $depth) {
* Creates a row for the 'admin' view of a book. Each row represents a page in the book, in the tree representing the book
*/
function book_admin_edit_line($node, $depth = 0) {
- return array('<div style="padding-left: '. (25 * $depth) .'px;">'. form_textfield(NULL, $node->nid .'][title', $node->title, 60, 255) .'</div>', 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'));
+ $form[tree] = TRUE;
+ $form[$node->nid]['title'] = array(type => 'textfield', default_value => $node->title, size => 60, maxlength => 255);
+ $form[$node->nid]['weight'] = array(type => 'weight', default_value => $node->weight, delta => 15);
+ $form['depth'] = array(value => $depth);
+ $form['nid'] = array(value => $node->nid);
+ return drupal_get_form('book_admin_edit_line', $form);
+}
+
+function theme_book_admin_edit_line($form) {
+ $nid = $form['nid'][value];
+ return array(
+ '<div style="padding-left: '. (25 * $form['depth'][value]) .'px;">'. form_render($form[$nid]['title']) .'</div>', form_render($form[$nid]['weight']), l(t('view'), 'node/'. $nid), l(t('edit'), 'node/'. $nid .'/edit'), l(t('delete'), 'node/'.$nid.'/delete')
+ );
}
function book_admin_edit_book($nid, $depth = 1) {
@@ -956,15 +990,15 @@ function book_admin_edit_book($nid, $depth = 1) {
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();
diff --git a/modules/book/book.module b/modules/book/book.module
index 2b7a33eea..0d5c0ded2 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -233,28 +233,39 @@ function book_validate(&$node) {
* Implementation of hook_form().
*/
function book_form(&$node) {
- $output = form_textfield(t('Title'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
- $output .= form_select(t('Parent'), 'parent', ($node->parent ? $node->parent : arg(4)), book_toc($node->nid), t('The parent that this page belongs in. Note that pages whose parent is &lt;top-level&gt; are regarded as independent, top-level books.'));
+ $form['parent'] = array(
+ type => 'select', title => t('Parent'), default_value => ($node->parent ? $node->parent : arg(4)), options => book_toc($node->nid), weight => -15,
+ description => t('The parent that this page belongs in. Note that pages whose parent is &lt;top-level&gt; are regarded as independent, top-level books.')
+ );
if (function_exists('taxonomy_node_form')) {
- $output .= implode('', taxonomy_node_form('book', $node));
+ $form['taxonomy'] = taxonomy_node_form('book', $node);
}
- $output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, '', NULL, TRUE);
- $output .= filter_form('format', $node->format);
+ $form['title'] = array(type => 'textfield', title => t('Title'), size => 60, maxlength => 128, required => TRUE, default_value => $node->title);
+ $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.'));
+ $form['log'] = array(
+ type => 'textarea', title => t('Log message'), default_value => $node->log, rows => 5, weight => 19,
+ description => t('An explanation of the additions or updates being made to help other authors understand your motivations.')
+ );
if (user_access('administer nodes')) {
- $output .= form_weight(t('Weight'), 'weight', $node->weight, 15, t('Pages at a given level are ordered first by weight and then by title.'));
+ $form['weight'] = array(
+ type => 'weight', title => t('Weight'), default_value => $node->weight, delta => 15, weight => -14,
+ description => t('Pages at a given level are ordered first by weight and then by title.')
+ );
}
else {
// If a regular user updates a book page, we create a new revision
// authored by that user:
- $output .= form_hidden('revision', 1);
+ $form['revision'] = array(type => 'hidden', value => 1);
}
- return $output;
+ return $form;
}
/**
@@ -291,21 +302,32 @@ function book_outline() {
default:
$page = db_fetch_object(db_query('SELECT * FROM {book} WHERE vid = %d', $node->vid));
-
- $output = form_select(t('Parent'), 'parent', $page->parent, book_toc($node->nid), t('The parent page in the book.'));
- $output .= form_weight(t('Weight'), 'weight', $page->weight, 15, t('Pages at a given level are ordered first by weight and then by title.'));
- $output .= form_textarea(t('Log message'), 'log', $node->log, 60, 5, t('An explanation to help other authors understand your motivations to put this post into the book.'));
+
+ $form['parent'] = array(
+ type => 'select', title => t('Parent'), default_value => $page->parent,
+ options => book_toc($node->nid), description => t('The parent page in the book.')
+ );
+
+ $form['weight'] = array(
+ type => 'weight', title => t('Weight'), default_value => $page->weight, delta => 15,
+ description => t('Pages at a given level are ordered first by weight and then by title.')
+ );
+
+ $form['log'] = array(
+ type => 'textarea', title => t('Log message'), cols => 60, rows => 5,
+ default_value => $node->log, description => t('An explanation to help other authors understand your motivations to put this post into the book.')
+ );
if ($page->nid) {
- $output .= form_submit(t('Update book outline'));
- $output .= form_submit(t('Remove from book outline'));
+ $form['update'] = array(type => 'submit', value => t('Update book outline'));
+ $form['remove'] = array(type => 'submit', value => t('Remove from book outline'));
}
else {
- $output .= form_submit(t('Add to book outline'));
+ $form['add'] = array(type => 'submit', value => t('Add to book outline'));
}
drupal_set_title(check_plain($node->title));
- return form($output);
+ return drupal_get_form('book_outline', $form);
}
}
}
@@ -933,7 +955,19 @@ function book_node_visitor_opml_post($node, $depth) {
* Creates a row for the 'admin' view of a book. Each row represents a page in the book, in the tree representing the book
*/
function book_admin_edit_line($node, $depth = 0) {
- return array('<div style="padding-left: '. (25 * $depth) .'px;">'. form_textfield(NULL, $node->nid .'][title', $node->title, 60, 255) .'</div>', 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'));
+ $form[tree] = TRUE;
+ $form[$node->nid]['title'] = array(type => 'textfield', default_value => $node->title, size => 60, maxlength => 255);
+ $form[$node->nid]['weight'] = array(type => 'weight', default_value => $node->weight, delta => 15);
+ $form['depth'] = array(value => $depth);
+ $form['nid'] = array(value => $node->nid);
+ return drupal_get_form('book_admin_edit_line', $form);
+}
+
+function theme_book_admin_edit_line($form) {
+ $nid = $form['nid'][value];
+ return array(
+ '<div style="padding-left: '. (25 * $form['depth'][value]) .'px;">'. form_render($form[$nid]['title']) .'</div>', form_render($form[$nid]['weight']), l(t('view'), 'node/'. $nid), l(t('edit'), 'node/'. $nid .'/edit'), l(t('delete'), 'node/'.$nid.'/delete')
+ );
}
function book_admin_edit_book($nid, $depth = 1) {
@@ -956,15 +990,15 @@ function book_admin_edit_book($nid, $depth = 1) {
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();
diff --git a/modules/comment.module b/modules/comment.module
index 3ef7b6504..d932b6214 100644
--- a/modules/comment.module
+++ b/modules/comment.module
@@ -31,39 +31,19 @@ function comment_help($section = "admin/help#comment") {
<li><strong>Flat</strong> &mdash; Displays the posts in chronological order, with no threading whatsoever.</li>
<li><strong>Expanded</strong> &mdash; Displays the title and text for each post.</li>
<li><strong>Collapsed</strong> &mdash; Displays only the title for each post.</li></ul>
- <p>When a user chooses <em>save settings</em>, 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 <a href=\"%comment-config\">administer &raquo; comments &raquo; configure</a>. NOTE: When comment moderation is enabled, users will have another control panel option to control thresholds (see below).</p>
+ <p>When a user chooses <em>save settings</em>, 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 <a href=\"%comment-config\">administer &raquo; comments &raquo; configure</a>.</p>
<h3>Additional comment configurations</h3>
<p>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 <a href=\"%permissions\">administer &raquo; access control &raquo; permissions</a>. 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:</p>
<ul><li><strong>Access comments</strong> &mdash; Allows users to view comments.</li>
<li><strong>Administrate comments</strong> &mdash; Allows users complete control over configuring, editing and deleting all comments.</li>
- <li><strong>Moderate comments</strong> &mdash; Allows users to rate comment postings (see more on moderation below).</li>
<li><strong>Post comments</strong> &mdash; Allows users to post comments into an administrator moderation queue.</li>
<li><strong>Post comments without approval</strong> &mdash; Allows users to directly post comments, bypassing the moderation queue.</li></ul>
<h3>Notification of new comments</h3>
<p>Drupal provides specific features to inform site members when new comments have been posted.</p>
<p>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 <a href=\"%download-notify\">download, install and configure the notify module</a>. 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).</p>
- <p>The <em>tracker</em> module, disabled by default, displays all the site's recent posts. There is a link to the <a href=\"%tracker\">recent posts</a> 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 <em>\"new\"</em> label beside the text of unread comments.</p>
-
- <h3>Comment moderation</h3>
- <p>On sites with active commenting from users, the administrator can turn over comment moderation to the community. </p>
- <p>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 <a href=\"%permissions\">moderate comments</a> permissions. Then, a number of options in <a href=\"%comment-config\">administer &raquo; comments &raquo; configure</a> must be configured.</p>
-
- <h4>Moderation votes</h4>
- <p>The first step is to create moderation labels which allow users to rate a comment. Go to <a href=\"%comment-votes\">administer &raquo; comments &raquo; configure &raquo; moderation votes</a>. In the <em>vote</em> field, enter the textual labels which users will see when casting their votes. Some examples are</p>
- <ul><li>Excellent +3</li><li>Insightful +2</li><li>Useful +1</li><li>Redundant -1</li><li>Flame -3</li></ul>
- <p>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.</p>
-
- <h4>Moderator vote/values matrix</h4>
- <p>Next go to <a href=\"%comment-matrix\">administer &raquo; comments &raquo; configure &raquo; moderation matrix</a>. 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.</p>
-
- <h4>Creating comment thresholds</h4>
- <p>In <a href=\"%comment-thresholds\">administer &raquo; comments &raquo; configure &raquo; moderation thresholds</a>, 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.</p>
- <p>When creating the thresholds, note that the <em>Minimum score</em> 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 <a href=\"%slashdot\">Slashdot</a> and view one of their comment boards associated with a story. You can reset the thresholds in their comment control panel.</p>
-
- <h4>Initial comment scores</h4>
- <p>Finally, you may want to enter some <em>initial comment scores</em>. In <a href=\"%comment-initial\">administer &raquo; comments &raquo; configure &raquo; moderation roles</a> 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 <strong>0</strong> as the default.</p>", array('%comment-config' => url('admin/comment/configure'), '%permissions' => url('admin/access/permissions'), '%tracker' => url('tracker'), '%download-notify' => 'http://drupal.org/project/releases', '%comment-votes' => url('admin/comment/configure/votes'), '%comment-matrix' => url('admin/comment/configure/matrix'), '%comment-thresholds' => url('admin/comment/configure/thresholds'), '%slashdot' => ' http://slashdot.org', '%comment-initial' => url('admin/comment/configure/roles')));
+ <p>The <em>tracker</em> module, disabled by default, displays all the site's recent posts. There is a link to the <a href=\"%tracker\">recent posts</a> 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 <em>\"new\"</em> label beside the text of unread comments.</p>", array('%comment-config' => url('admin/comment/configure'), '%permissions' => url('admin/access/permissions'), '%tracker' => url('tracker'), '%download-notify' => 'http://drupal.org/project/releases', '%comment-initial' => url('admin/comment/configure/roles')));
case 'admin/comment':
case 'admin/comment/new':
return t("<p>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.</p>");
@@ -72,14 +52,6 @@ function comment_help($section = "admin/help#comment") {
case 'admin/comment/configure':
case 'admin/comment/configure/settings':
return t("<p>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.</p>");
- case 'admin/comment/configure/matrix':
- return t("<p>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.</p><ul><li>In order to use comment moderation, every text box on this page should be populated.</li><li>You must assign the \"moderate comments\" permission to at least one role in order to use this page.</li><li>Every box not filled in will have a value of zero, which will have the effect of lowering a comments overall score.</li></ul>");
- case 'admin/comment/configure/roles':
- return t("<p>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.</p>");
- case 'admin/comment/configure/thresholds':
- return t("<p>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\".</p>");
- case 'admin/comment/configure/votes':
- return t('<p>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".</p>');
case 'admin/modules#description':
return t('Allows users to comment on and discuss published content.');
}
@@ -113,16 +85,6 @@ function comment_menu($may_cache) {
$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 @@ function comment_menu($may_cache) {
* 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,17 @@ function comment_link($type, $node = 0, $main = 0) {
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 <em>administer comments</em> 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 <em>administer comments</em> permission will be able to override this setting.'));
+ return $form;
case 'fields':
return array('comment');
- case 'form admin':
+ case 'form':
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);
+ $form['user_comments']['comment'] = array(type => 'radios', parents => array('comment'), default_value => $selected, options => array(t('Disabled'), t('Read only'), t('Read/Write')));
+ return $form;
}
break;
@@ -298,11 +261,10 @@ function comment_nodeapi(&$node, $op, $arg = 0) {
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));
- }
- if ($type == 'validate') {
- // validate user data editing
- return array('signature' => $edit['signature']);
+ $form['comment_settings'] = array(type => 'fieldset', title => t('Comment settings'), collapsible => TRUE, collapsed => FALSE, weight => 4);
+ $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;
}
}
@@ -310,32 +272,39 @@ function comment_user($type, $edit, &$user, $category = NULL) {
* 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);
-
- $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 <a href="%url">permissions page</a>.', 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);
-
- $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_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.'));
+
+ $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.'));
- return system_settings_form($output);
+ $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', 1), 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 <a href="%url">permissions page</a>.', 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('comment_settings_form', $form);
}
/**
@@ -367,7 +336,7 @@ function comment_edit($cid) {
$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();
@@ -422,7 +391,7 @@ function comment_reply($nid, $pid = NULL) {
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');
@@ -435,9 +404,12 @@ function comment_reply($nid, $pid = NULL) {
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;
@@ -491,7 +463,7 @@ function comment_validate($edit) {
// Check validity of name, mail and homepage (if given)
if (!$user->uid) {
- if (variable_get('comment_anonymous', 0) > 0) {
+ if (variable_get('comment_anonymous', 1) > 1) {
if ($edit['name']) {
$taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE LOWER(name) = '%s'", $edit['name']), 0);
@@ -500,7 +472,7 @@ function comment_validate($edit) {
}
}
- else if (variable_get('comment_anonymous', 0) == 2) {
+ else if (variable_get('comment_anonymous', 1) == 3) {
form_set_error('name', t('You have to leave your name.'));
}
@@ -509,7 +481,7 @@ function comment_validate($edit) {
form_set_error('mail', t('The e-mail address you specified is not valid.'));
}
}
- else if (variable_get('comment_anonymous', 0) == 2) {
+ else if (variable_get('comment_anonymous', 1) == 3) {
form_set_error('mail', t('You have to leave an e-mail address.'));
}
@@ -594,7 +566,8 @@ function comment_save($edit) {
_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']));
@@ -683,7 +656,6 @@ function comment_save($edit) {
}
}
-
$edit['cid'] = db_next_id('{comments}_cid');
$edit['timestamp'] = time();
@@ -691,13 +663,12 @@ function comment_save($edit) {
$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']));
@@ -752,10 +723,6 @@ function comment_links($comment, $return = 1) {
}
}
- if ($moderation = comment_moderation_form($comment)) {
- $links[] = $moderation;
- }
-
return $links;
}
@@ -764,7 +731,6 @@ function comment_render($node, $cid = 0) {
$mode = $_GET['mode'];
$order = $_GET['order'];
- $threshold = $_GET['threshold'];
$comments_per_page = $_GET['comments_per_page'];
$comment_page = $_GET['comment_page'];
@@ -784,10 +750,6 @@ function comment_render($node, $cid = 0) {
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'));
@@ -797,21 +759,12 @@ function comment_render($node, $cid = 0) {
if ($cid) {
// Single comment view.
-
- $output .= '<form method="post" action="'. url('comment') ."\"><div>\n";
- $output .= form_hidden('nid', $nid);
-
$result = db_query('SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = %d GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, u.picture, c.homepage, u.uid, u.name, u.picture, u.data, c.score, c.users', $cid, COMMENT_PUBLISHED);
if ($comment = db_fetch_object($result)) {
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
$output .= theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 1)));
}
-
- if ((comment_user_can_moderate($node)) && $user->uid != $comment->uid && !(comment_already_moderated($user->uid, $comment->users))) {
- $output .= '<div style="text-align: center;">'. form_submit(t('Moderate comment')) .'</div><br />';
- }
- $output .= '</div></form>';
}
else {
// Multiple comment view
@@ -907,34 +860,28 @@ function comment_render($node, $cid = 0) {
}
}
- // Start a form, for use with comment control and moderation.
- $result = pager_query($query, $comments_per_page, 0, "SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = %d" , $nid, COMMENT_PUBLISHED);
+ // Start a form, for use with comment control.
+ $result = pager_query($query, $comments_per_page, 0, "SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = %d", $nid, COMMENT_PUBLISHED);
if (db_num_rows($result) && (variable_get('comment_controls', 3) == 0 || variable_get('comment_controls', 3) == 2)) {
- $output .= '<form method="post" action="'. url('comment') ."\"><div>\n";
- $output .= theme('comment_controls', $threshold, $mode, $order, $comments_per_page);
- $output .= form_hidden('nid', $nid);
- $output .= '</div></form>';
+ $output .= comment_controls($mode, $order, $comments_per_page, $nid, 'top');
}
- $output .= '<form method="post" action="'. url('comment') ."\"><div>\n";
- $output .= form_hidden('nid', $nid);
-
while ($comment = db_fetch_object($result)) {
$comment = drupal_unpack($comment);
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
$comment->depth = count(explode('.', $comment->thread)) - 1;
if ($mode == 1) {
- $output .= theme('comment_flat_collapsed', $comment, $threshold_min);
+ $output .= theme('comment_flat_collapsed', $comment);
}
else if ($mode == 2) {
- $output .= theme('comment_flat_expanded', $comment, $threshold_min);
+ $output .= theme('comment_flat_expanded', $comment);
}
else if ($mode == 3) {
- $output .= theme('comment_thread_min', $comment, $threshold_min);
+ $output .= theme('comment_thread_min', $comment);
}
else if ($mode == 4) {
- $output .= theme('comment_thread_max', $comment, $threshold_min);
+ $output .= theme('comment_thread_max', $comment);
}
}
@@ -942,23 +889,14 @@ function comment_render($node, $cid = 0) {
// is global and defined in pager.inc.
$output .= theme('pager', NULL, $comments_per_page, 0, array('comments_per_page' => $comments_per_page));
- if (db_num_rows($result) && comment_user_can_moderate($node)) {
- $output .= '<div id="comment-moderation-button">'. form_submit(t('Moderate comments')) .'</div>';
- }
-
- $output .= '</div></form>';
-
- if (db_num_rows($result) && (variable_get('comment_controls', 3) == 1 || variable_get('comment_controls', 3) == 2)) {
- $output .= '<form method="post" action="'. url('comment') ."\"><div>\n";
- $output .= theme('comment_controls', $threshold, $mode, $order, $comments_per_page);
- $output .= form_hidden('nid', $nid);
- $output .= '</div></form>';
+ if (db_num_rows($result) && (variable_get('comment_controls', 3) == 1 || variable_get('comment_controls', 3) == 3)) {
+ $output .= comment_controls($mode, $order, $comments_per_page, $nid, 'bottom');
}
}
// 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'));
+ if (user_access('post comments') && node_comment_mode($nid) == 2 && (variable_get('comment_form_location', 0) == 1)) {
+ $output .= comment_form(array('nid' => $nid), t('Post new comment'));
}
}
return $output;
@@ -990,11 +928,13 @@ function comment_delete($cid) {
drupal_goto("node/$comment->nid");
}
else if ($comment->cid) {
- $output = theme('confirm',
+ $output = confirm_form('comment_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.'));
@@ -1043,265 +983,24 @@ function comment_admin_overview($type = 'new') {
}
/**
- * 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 .= '<h3>'. t('Moderation vote/value matrix') .'</h3>';
-
- $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 .= '<br />'. 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 .= '<h3>'. t('Initial comment scores') .'</h3>';
-
- 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 .= '<br />'. 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 .= '<h3>'. t('Moderation votes overview') .'</h3>';
-
- // 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 .= '<br /><h3>'. (isset($mid) ? t('Edit moderation option') : t('Add new moderation option')) .'</h3>';
- $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 .= '<h3>'. t('Comment threshold overview') .'</h3>';
-
- // 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 .= '<br /><h3>'. (isset($fid) ? t('Edit threshold') : t('Add new threshold')) .'</h3>';
- $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;
}
@@ -1356,34 +1055,16 @@ function comment_num_new($nid, $timestamp = 0) {
}
-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 .= "<a id=\"comment-form\"></a>\n";
- // contact information:
if ($user->uid) {
if ($edit['cid'] && user_access('administer comments')) {
- $form .= '<div class="admin">';
-
if ($edit['author']) {
$author = $edit['author'];
}
@@ -1393,54 +1074,94 @@ function theme_comment_form($edit, $title = NULL) {
else {
$author = $edit['registered_name'];
}
- $output = form_autocomplete(t('Authored by'), 'author', $author, 30, 60, 'user/autocomplete');
- $output .= form_textfield(t('Authored on'), 'date', $edit['date'] ? $edit['date'] : format_date($edit['timestamp'], 'custom', 'Y-m-d H:i O'), 20, 25, NULL, NULL, TRUE);
- $output .= form_radios(t('Status'), 'status', $edit['status'], array(t('Published'), t('Not published')));
- $output .= '<div class="authored">';
- $form .= form_group_collapsible(t('Administration'), $output, TRUE);
- $form .= "</div>\n";
+ if ($edit['status']) {
+ $status = $edit['status'];
+ }
+ else {
+ $status = 0;
+ }
+
+ if ($edit['date']) {
+ $date = $edit['date'];
+ }
+ else {
+ $date = format_date($edit['timestamp'], 'custom', 'Y-m-d H:i O');
+ }
+
+ $form['admin'] = array(type => 'fieldset', title => t('Administration'), collapsible => TRUE, collapsed => TRUE, weight => -2);
+
+ $form['admin']['author'] = array(type => 'textfield', parents => array('author'), title => t('Authored by'), size => 30, maxlength => 60, autocomplete_path => 'user/autocomplete', default_value => $author, weight => -1);
+
+ $form['admin']['date'] = array(type => 'textfield', parents => array('date'), title => t('Authored on'), size => 20, maxlength => 25, default_value => $date, weight => -1);
+
+ $form['admin']['status'] = array(type => 'radios', parents => array('status'), title => t('Status'), default_value => $status, options => array(t('Published'), t('Not published')), weight => -1);
+
}
else {
- $form .= form_item(t('Your name'), theme('username', $user));
+ $form['author'] = array(type => 'item', title => t('Your name'), value => theme('username', $user)
+ );
}
}
- else if (variable_get('comment_anonymous', 0) == 1) {
- $form .= form_textfield(t('Your name'), 'name', $edit['name'] ? $edit['name'] : variable_get('anonymous', 'Anonymous') , 30, 60);
- $form .= form_textfield(t('E-mail'), 'mail', $edit['mail'], 30, 64, t('The content of this field is kept private and will not be shown publicly.'));
- $form .= form_textfield(t('Homepage'), 'homepage', $edit['homepage'], 30, 255);
+ else if (variable_get('comment_anonymous', 1) == 2) {
+ $form['name'] = array(type => 'textfield', title => t('Your name'), maxlength => 60, size => 30, default_value => $edit['name'] ? $edit['name'] : variable_get('anonymous', 'Anonymous')
+ );
+
+ $form['mail'] = array(type => 'textfield', title => t('E-mail'), maxlength => 64, size => 30, default_value => $edit['mail'], description => t('The content of this field is kept private and will not be shown publicly.')
+ );
+
+ $form['homepage'] = array(type => 'textfield', title => t('Homepage'), maxlength => 255, size => 30, default_value => $edit['homepage']);
}
- else if (variable_get('comment_anonymous', 0) == 2) {
- $form .= form_textfield(t('Your name'), 'name', $edit['name'] ? $edit['name'] : variable_get('anonymous', 'Anonymous') , 30, 60, NULL, NULL, TRUE);
- $form .= form_textfield(t('E-mail'), 'mail', $edit['mail'], 30, 64, t('The content of this field is kept private and will not be shown publicly.'), NULL, TRUE);
- $form .= form_textfield(t('Homepage'), 'homepage', $edit['homepage'], 30, 255);
+ else if (variable_get('comment_anonymous', 1) == 3) {
+ $form['name'] = array(type => 'textfield', title => t('Your name'), maxlength => 60, size => 30, default_value => $edit['name'] ? $edit['name'] : variable_get('anonymous', 'Anonymous'), required => TRUE);
+
+ $form['name'] = array(type => 'textfield', title => t('E-mail'), maxlength => 64, size => 30, default_value => $edit['mail'],description => t('The content of this field is kept private and will not be shown publicly.'), required => TRUE);
+
+ $form['homepage'] = array(type => 'textfield', title => t('Homepage'), maxlength => 255, size => 30, default_value => $edit['homepage']);
}
- if (variable_get('comment_subject_field', 1)) {
- $form .= form_textfield(t('Subject'), 'subject', $edit['subject'], 60, 64);
+ if (variable_get('comment_subject_field', 1) == 1) {
+ $form['subject'] = array(type => 'textfield', title => t('Subject'), size => 60, maxlength => 64, default_value => $edit['subject']);
}
- $form .= form_textarea(t('Comment'), 'comment', $edit['comment'] ? $edit['comment'] : $user->signature, 60, 15, '', NULL, TRUE);
+ $form['comment'] = array(type => 'textarea', title => t('Comment'), cols => 60, rows => 15, default_value => $edit['comment'] ? $edit['comment'] : $user->signature, required => TRUE
+ );
+
+ $form = array_merge($form, filter_form($node->format));
- $form .= filter_form('format', $edit['format']);
- $form .= form_hidden('cid', $edit['cid']);
- $form .= form_hidden('pid', $edit['pid']);
- $form .= form_hidden('nid', $edit['nid']);
- $form .= form_hidden('uid', $edit['uid']);
- // generate a token used to validate that submissions came from this form
- $form .= form_token('comment'. $edit['nid'] . $edit['pid']);
+ $form['cid'] = array(type => 'hidden', value => $edit['cid']);
+ $form['pid'] = array(type => 'hidden', value => $edit['pid']);
+ $form['nid'] = array(type => 'hidden', value => $edit['nid']);
+ $form['uid'] = array(type => 'hidden', value => $edit['uid']);
- $form .= form_submit(t('Preview comment'));
+ $form['preview'] = array(type => 'submit', value => t('Preview comment'), weight => 19);
+ $form[token] = 'comment' . $edit['nid'] . $edit['pid'];
// Only show post button if preview is optional or if we are in preview mode.
// We show the post button in preview mode even if there are form errors so that
// optional form elements (e.g., captcha) can be updated in preview mode.
- if (!variable_get('comment_preview', 1) || ($_POST['op'] == t('Preview comment')) || ($_POST['op'] == t('Post comment'))) {
- $form .= form_submit(t('Post comment'));
+ if ((variable_get('comment_preview', 1) == 0) || ($_POST['op'] == t('Preview comment')) || ($_POST['op'] == t('Post comment'))) {
+ $form['submit'] = array(type => 'submit', value => t('Post comment'), weight => 20);
+ }
+
+ if ($_REQUEST['destination']) {
+ $form[attributes]['destination'] = $_REQUEST['destination'];
}
+ $form[action] = url('comment/reply/'. $edit['nid']);
- $destination = $_REQUEST['destination'] ? 'destination='. $_REQUEST['destination'] : '';
- return theme('box', $title, form($form, 'post', url('comment/reply/'. $edit['nid'], $destination)));
+ // Graft in extra form additions
+ $form = array_merge($form, comment_invoke_comment($form, 'form'));
+
+ return theme('box', $title, drupal_get_form('comment_form', $form));
+}
+
+/*
+** Renderer or visualization functions this can be optionally
+** overridden by themes.
+*/
+
+function theme_comment_form($form) {
+ return form_render($form);
}
function theme_comment_preview($comment, $links = '', $visible = 1) {
@@ -1463,6 +1184,10 @@ function theme_comment_view($comment, $links = '', $visible = 1) {
// Switch to folded/unfolded view of the comment
if ($visible) {
$comment->comment = check_markup($comment->comment, $comment->format, FALSE);
+
+ // Comment API hook
+ comment_invoke_comment($comment, 'view');
+
$output .= theme('comment', $comment, $links);
}
else {
@@ -1472,70 +1197,38 @@ function theme_comment_view($comment, $links = '', $visible = 1) {
return $output;
}
-function theme_comment_controls($threshold = 1, $mode = 3, $order = 1, $comments_per_page = 50) {
- static $output;
- $options = array();
- $result = db_query('SELECT fid, filter FROM {moderation_filters} ');
- $filters = array();
- $filters[0] = t('-- threshold --');
+function comment_controls($mode = 2, $order = 1, $comments_per_page = 50, $nid = 0, $top_or_bottom = '') {
- while($filter = db_fetch_object($result)) {
- $filters[$filter->fid] = $filter->filter;
- }
+ $form['mode'] = array(type => 'select', default_value => $mode, options => _comment_get_modes(), weight => 1);
- if (!$output) {
- $output .= '<div class="container-inline">';
- $output .= form_select(NULL, 'mode', $mode, _comment_get_modes());
- $output .= form_select(NULL, 'order', $order, _comment_get_orders());
+ $form['order'] = array(type => 'select', default_value => $order, options => _comment_get_orders(), weight => 2);
- foreach (_comment_per_page() as $i) {
- $options[] = t('%a comments per page', array('%a' => $i));
- }
- $output .= form_select(NULL, 'comments_per_page', $comments_per_page, $options);
+ foreach (_comment_per_page() as $i) {
+ $options[] = t('%a comments per page', array('%a' => $i));
+ }
+ $form['comments_per_page'] = array(type => 'select', default_value => $comments_per_page, options => $options, weight => 3);
- if ($filters) {
- $output .= form_select(NULL, 'threshold', $threshold, $filters);
- }
- else {
- $output .= form_hidden('threshold', $threshold);
- }
+ $form['submit'] = array(type => 'submit', value => t('Save settings'), weight => 20);
- $output .= ' '. form_submit(t('Save settings'));
- $output .= '</div>';
+ $form['nid'] = array(type => 'hidden', value => $nid);
- $output = form_item(NULL, $output, t('Select your preferred way to display the comments and click "Save settings" to activate your changes.'));
- }
+ $form[action] = 'comment/reply';
- return theme('box', t('Comment viewing options'), $output);
+ return drupal_get_form('comment_controls'. $top_or_bottom, $form, 'comment_controls');
}
-function comment_moderation_form($comment) {
- global $comment_votes, $user, $node;
- static $votes;
-
- $op = $_POST['op'];
+function theme_comment_controls($form) {
+ $output .= '<div class="container-inline">';
+ $output .= form_render($form);
+ $output .= '</div>';
+ $output .= '<div class="description">' . t('Select your preferred way to display the comments and click "Save settings" to activate your changes.') . '</div>';
- if ((comment_user_can_moderate($node)) && $user->uid != $comment->uid && !(comment_already_moderated($user->uid, $comment->users))) {
- // comment hasn't been moderated yet:
- if (!isset($votes) && $user->roles) {
- $result = db_query('SELECT v.mid, v.vote, MAX(v.weight) AS weight, MAX(r.value) AS value FROM {moderation_votes} v INNER JOIN {moderation_roles} r ON r.mid = v.mid WHERE r.rid IN (%s) GROUP BY v.mid, v.vote ORDER BY weight', implode(', ', array_keys($user->roles)));
- $votes = array(0 => t('defer until later'));
- while ($vote = db_fetch_object($result)) {
- if ($vote->value != 0) {
- $votes[$vote->mid] = $vote->vote;
- }
- }
- }
- if (count($votes) > 1) {
- return form_select(t('Moderation'), 'moderation]['. $comment->cid, 0, $votes);
- }
- }
+ return theme('box', t('Comment viewing options'), $output);
}
function theme_comment($comment, $links = 0) {
$output = "<div class=\"comment\">\n";
$output .= '<div class="subject">'. l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid") . ' ' . theme('mark', $comment->new) ."</div>\n";
- $output .= '<div class="moderation">'. $comment->moderation ."</div>\n";
$output .= '<div class="credit">'. t('by %a on %b', array('%a' => theme('username', $comment), '%b' => format_date($comment->timestamp))) ."</div>\n";
$output .= "<div class=\"body\">$comment->comment</div>\n";
$output .= "<div class=\"links\">$links</div>\n";
@@ -1551,33 +1244,29 @@ function theme_comment_folded($comment) {
return $output;
}
-function theme_comment_flat_collapsed($comment, $threshold) {
- if (comment_visible($comment, $threshold)) {
- return theme('comment_view', $comment, '', 0);
- }
+function theme_comment_flat_collapsed($comment) {
+ return theme('comment_view', $comment, '', 0);
return '';
}
-function theme_comment_flat_expanded($comment, $threshold) {
- return theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 0)), comment_visible($comment, $threshold));
+function theme_comment_flat_expanded($comment) {
+ return theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 0)));
}
-function theme_comment_thread_min($comment, $threshold, $pid = 0) {
- if (comment_visible($comment, $threshold)) {
- $output = '<div style="margin-left:'. ($comment->depth * 25) ."px;\">\n";
- $output .= theme('comment_view', $comment, '', 0);
- $output .= "</div>\n";
- }
+function theme_comment_thread_min($comment, $pid = 0) {
+ $output = '<div style="margin-left:'. ($comment->depth * 25) ."px;\">\n";
+ $output .= theme('comment_view', $comment, '', 0);
+ $output .= "</div>\n";
return $output;
}
-function theme_comment_thread_max($comment, $threshold, $level = 0) {
+function theme_comment_thread_max($comment, $level = 0) {
$output = '';
if ($comment->depth) {
$output .= '<div style="margin-left:'. ($comment->depth * 25) ."px;\">\n";
}
- $output .= theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 0)), comment_visible($comment, $threshold));
+ $output .= theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 0)));
if ($comment->depth) {
$output .= "</div>\n";
@@ -1605,9 +1294,9 @@ function _comment_delete_thread($comment) {
db_query('DELETE FROM {comments} WHERE cid = %d', $comment->cid);
watchdog('content', t('Comment: deleted %subject.', array('%subject' => theme('placeholder', $comment->subject))));
- module_invoke_all('comment', 'delete', $comment);
+ comment_invoke_comment($comment, 'delete');
- // Delete the comment's replies:
+ // Delete the comment's replies
$result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE pid = %d', $comment->cid);
while ($comment = db_fetch_object($result)) {
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
@@ -1622,7 +1311,7 @@ function _comment_delete_thread($comment) {
* is not initialized yet when the comment module is loaded.
*/
function _comment_get_modes() {
- return array(1 => t('Flat list - collapsed'), 2 => t('Flat list - expanded'), 3 => t('Threaded list - collapsed'), 4 => t('Threaded list - expanded'));
+ return array(t('Flat list - collapsed'), t('Flat list - expanded'), t('Threaded list - collapsed'), t('Threaded list - expanded'));
}
/**
@@ -1668,3 +1357,27 @@ function _comment_update_node_statistics($nid) {
}
}
+/**
+ * Invoke a hook_comment() operation in all modules.
+ *
+ * @param &$comment
+ * A comment object.
+ * @param $op
+ * A string containing the name of the comment operation.
+ * @return
+ * The returned value of the invoked hooks.
+ */
+function comment_invoke_comment(&$comment, $op) {
+ $return = array();
+ foreach (module_implements('comment') as $name) {
+ $function = $name .'_comment';
+ $result = $function($comment, $op);
+ if (is_array($result)) {
+ $return = array_merge($return, $result);
+ }
+ else if (isset($result)) {
+ $return[] = $result;
+ }
+ }
+ return $return;
+}
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index 3ef7b6504..d932b6214 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -31,39 +31,19 @@ function comment_help($section = "admin/help#comment") {
<li><strong>Flat</strong> &mdash; Displays the posts in chronological order, with no threading whatsoever.</li>
<li><strong>Expanded</strong> &mdash; Displays the title and text for each post.</li>
<li><strong>Collapsed</strong> &mdash; Displays only the title for each post.</li></ul>
- <p>When a user chooses <em>save settings</em>, 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 <a href=\"%comment-config\">administer &raquo; comments &raquo; configure</a>. NOTE: When comment moderation is enabled, users will have another control panel option to control thresholds (see below).</p>
+ <p>When a user chooses <em>save settings</em>, 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 <a href=\"%comment-config\">administer &raquo; comments &raquo; configure</a>.</p>
<h3>Additional comment configurations</h3>
<p>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 <a href=\"%permissions\">administer &raquo; access control &raquo; permissions</a>. 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:</p>
<ul><li><strong>Access comments</strong> &mdash; Allows users to view comments.</li>
<li><strong>Administrate comments</strong> &mdash; Allows users complete control over configuring, editing and deleting all comments.</li>
- <li><strong>Moderate comments</strong> &mdash; Allows users to rate comment postings (see more on moderation below).</li>
<li><strong>Post comments</strong> &mdash; Allows users to post comments into an administrator moderation queue.</li>
<li><strong>Post comments without approval</strong> &mdash; Allows users to directly post comments, bypassing the moderation queue.</li></ul>
<h3>Notification of new comments</h3>
<p>Drupal provides specific features to inform site members when new comments have been posted.</p>
<p>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 <a href=\"%download-notify\">download, install and configure the notify module</a>. 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).</p>
- <p>The <em>tracker</em> module, disabled by default, displays all the site's recent posts. There is a link to the <a href=\"%tracker\">recent posts</a> 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 <em>\"new\"</em> label beside the text of unread comments.</p>
-
- <h3>Comment moderation</h3>
- <p>On sites with active commenting from users, the administrator can turn over comment moderation to the community. </p>
- <p>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 <a href=\"%permissions\">moderate comments</a> permissions. Then, a number of options in <a href=\"%comment-config\">administer &raquo; comments &raquo; configure</a> must be configured.</p>
-
- <h4>Moderation votes</h4>
- <p>The first step is to create moderation labels which allow users to rate a comment. Go to <a href=\"%comment-votes\">administer &raquo; comments &raquo; configure &raquo; moderation votes</a>. In the <em>vote</em> field, enter the textual labels which users will see when casting their votes. Some examples are</p>
- <ul><li>Excellent +3</li><li>Insightful +2</li><li>Useful +1</li><li>Redundant -1</li><li>Flame -3</li></ul>
- <p>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.</p>
-
- <h4>Moderator vote/values matrix</h4>
- <p>Next go to <a href=\"%comment-matrix\">administer &raquo; comments &raquo; configure &raquo; moderation matrix</a>. 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.</p>
-
- <h4>Creating comment thresholds</h4>
- <p>In <a href=\"%comment-thresholds\">administer &raquo; comments &raquo; configure &raquo; moderation thresholds</a>, 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.</p>
- <p>When creating the thresholds, note that the <em>Minimum score</em> 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 <a href=\"%slashdot\">Slashdot</a> and view one of their comment boards associated with a story. You can reset the thresholds in their comment control panel.</p>
-
- <h4>Initial comment scores</h4>
- <p>Finally, you may want to enter some <em>initial comment scores</em>. In <a href=\"%comment-initial\">administer &raquo; comments &raquo; configure &raquo; moderation roles</a> 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 <strong>0</strong> as the default.</p>", array('%comment-config' => url('admin/comment/configure'), '%permissions' => url('admin/access/permissions'), '%tracker' => url('tracker'), '%download-notify' => 'http://drupal.org/project/releases', '%comment-votes' => url('admin/comment/configure/votes'), '%comment-matrix' => url('admin/comment/configure/matrix'), '%comment-thresholds' => url('admin/comment/configure/thresholds'), '%slashdot' => ' http://slashdot.org', '%comment-initial' => url('admin/comment/configure/roles')));
+ <p>The <em>tracker</em> module, disabled by default, displays all the site's recent posts. There is a link to the <a href=\"%tracker\">recent posts</a> 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 <em>\"new\"</em> label beside the text of unread comments.</p>", array('%comment-config' => url('admin/comment/configure'), '%permissions' => url('admin/access/permissions'), '%tracker' => url('tracker'), '%download-notify' => 'http://drupal.org/project/releases', '%comment-initial' => url('admin/comment/configure/roles')));
case 'admin/comment':
case 'admin/comment/new':
return t("<p>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.</p>");
@@ -72,14 +52,6 @@ function comment_help($section = "admin/help#comment") {
case 'admin/comment/configure':
case 'admin/comment/configure/settings':
return t("<p>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.</p>");
- case 'admin/comment/configure/matrix':
- return t("<p>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.</p><ul><li>In order to use comment moderation, every text box on this page should be populated.</li><li>You must assign the \"moderate comments\" permission to at least one role in order to use this page.</li><li>Every box not filled in will have a value of zero, which will have the effect of lowering a comments overall score.</li></ul>");
- case 'admin/comment/configure/roles':
- return t("<p>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.</p>");
- case 'admin/comment/configure/thresholds':
- return t("<p>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\".</p>");
- case 'admin/comment/configure/votes':
- return t('<p>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".</p>');
case 'admin/modules#description':
return t('Allows users to comment on and discuss published content.');
}
@@ -113,16 +85,6 @@ function comment_menu($may_cache) {
$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 @@ function comment_menu($may_cache) {
* 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,17 @@ function comment_link($type, $node = 0, $main = 0) {
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 <em>administer comments</em> 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 <em>administer comments</em> permission will be able to override this setting.'));
+ return $form;
case 'fields':
return array('comment');
- case 'form admin':
+ case 'form':
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);
+ $form['user_comments']['comment'] = array(type => 'radios', parents => array('comment'), default_value => $selected, options => array(t('Disabled'), t('Read only'), t('Read/Write')));
+ return $form;
}
break;
@@ -298,11 +261,10 @@ function comment_nodeapi(&$node, $op, $arg = 0) {
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));
- }
- if ($type == 'validate') {
- // validate user data editing
- return array('signature' => $edit['signature']);
+ $form['comment_settings'] = array(type => 'fieldset', title => t('Comment settings'), collapsible => TRUE, collapsed => FALSE, weight => 4);
+ $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;
}
}
@@ -310,32 +272,39 @@ function comment_user($type, $edit, &$user, $category = NULL) {
* 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);
-
- $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 <a href="%url">permissions page</a>.', 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);
-
- $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_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.'));
+
+ $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.'));
- return system_settings_form($output);
+ $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', 1), 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 <a href="%url">permissions page</a>.', 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('comment_settings_form', $form);
}
/**
@@ -367,7 +336,7 @@ function comment_edit($cid) {
$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();
@@ -422,7 +391,7 @@ function comment_reply($nid, $pid = NULL) {
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');
@@ -435,9 +404,12 @@ function comment_reply($nid, $pid = NULL) {
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;
@@ -491,7 +463,7 @@ function comment_validate($edit) {
// Check validity of name, mail and homepage (if given)
if (!$user->uid) {
- if (variable_get('comment_anonymous', 0) > 0) {
+ if (variable_get('comment_anonymous', 1) > 1) {
if ($edit['name']) {
$taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE LOWER(name) = '%s'", $edit['name']), 0);
@@ -500,7 +472,7 @@ function comment_validate($edit) {
}
}
- else if (variable_get('comment_anonymous', 0) == 2) {
+ else if (variable_get('comment_anonymous', 1) == 3) {
form_set_error('name', t('You have to leave your name.'));
}
@@ -509,7 +481,7 @@ function comment_validate($edit) {
form_set_error('mail', t('The e-mail address you specified is not valid.'));
}
}
- else if (variable_get('comment_anonymous', 0) == 2) {
+ else if (variable_get('comment_anonymous', 1) == 3) {
form_set_error('mail', t('You have to leave an e-mail address.'));
}
@@ -594,7 +566,8 @@ function comment_save($edit) {
_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']));
@@ -683,7 +656,6 @@ function comment_save($edit) {
}
}
-
$edit['cid'] = db_next_id('{comments}_cid');
$edit['timestamp'] = time();
@@ -691,13 +663,12 @@ function comment_save($edit) {
$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']));
@@ -752,10 +723,6 @@ function comment_links($comment, $return = 1) {
}
}
- if ($moderation = comment_moderation_form($comment)) {
- $links[] = $moderation;
- }
-
return $links;
}
@@ -764,7 +731,6 @@ function comment_render($node, $cid = 0) {
$mode = $_GET['mode'];
$order = $_GET['order'];
- $threshold = $_GET['threshold'];
$comments_per_page = $_GET['comments_per_page'];
$comment_page = $_GET['comment_page'];
@@ -784,10 +750,6 @@ function comment_render($node, $cid = 0) {
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'));
@@ -797,21 +759,12 @@ function comment_render($node, $cid = 0) {
if ($cid) {
// Single comment view.
-
- $output .= '<form method="post" action="'. url('comment') ."\"><div>\n";
- $output .= form_hidden('nid', $nid);
-
$result = db_query('SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = %d GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, u.picture, c.homepage, u.uid, u.name, u.picture, u.data, c.score, c.users', $cid, COMMENT_PUBLISHED);
if ($comment = db_fetch_object($result)) {
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
$output .= theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 1)));
}
-
- if ((comment_user_can_moderate($node)) && $user->uid != $comment->uid && !(comment_already_moderated($user->uid, $comment->users))) {
- $output .= '<div style="text-align: center;">'. form_submit(t('Moderate comment')) .'</div><br />';
- }
- $output .= '</div></form>';
}
else {
// Multiple comment view
@@ -907,34 +860,28 @@ function comment_render($node, $cid = 0) {
}
}
- // Start a form, for use with comment control and moderation.
- $result = pager_query($query, $comments_per_page, 0, "SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = %d" , $nid, COMMENT_PUBLISHED);
+ // Start a form, for use with comment control.
+ $result = pager_query($query, $comments_per_page, 0, "SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = %d", $nid, COMMENT_PUBLISHED);
if (db_num_rows($result) && (variable_get('comment_controls', 3) == 0 || variable_get('comment_controls', 3) == 2)) {
- $output .= '<form method="post" action="'. url('comment') ."\"><div>\n";
- $output .= theme('comment_controls', $threshold, $mode, $order, $comments_per_page);
- $output .= form_hidden('nid', $nid);
- $output .= '</div></form>';
+ $output .= comment_controls($mode, $order, $comments_per_page, $nid, 'top');
}
- $output .= '<form method="post" action="'. url('comment') ."\"><div>\n";
- $output .= form_hidden('nid', $nid);
-
while ($comment = db_fetch_object($result)) {
$comment = drupal_unpack($comment);
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
$comment->depth = count(explode('.', $comment->thread)) - 1;
if ($mode == 1) {
- $output .= theme('comment_flat_collapsed', $comment, $threshold_min);
+ $output .= theme('comment_flat_collapsed', $comment);
}
else if ($mode == 2) {
- $output .= theme('comment_flat_expanded', $comment, $threshold_min);
+ $output .= theme('comment_flat_expanded', $comment);
}
else if ($mode == 3) {
- $output .= theme('comment_thread_min', $comment, $threshold_min);
+ $output .= theme('comment_thread_min', $comment);
}
else if ($mode == 4) {
- $output .= theme('comment_thread_max', $comment, $threshold_min);
+ $output .= theme('comment_thread_max', $comment);
}
}
@@ -942,23 +889,14 @@ function comment_render($node, $cid = 0) {
// is global and defined in pager.inc.
$output .= theme('pager', NULL, $comments_per_page, 0, array('comments_per_page' => $comments_per_page));
- if (db_num_rows($result) && comment_user_can_moderate($node)) {
- $output .= '<div id="comment-moderation-button">'. form_submit(t('Moderate comments')) .'</div>';
- }
-
- $output .= '</div></form>';
-
- if (db_num_rows($result) && (variable_get('comment_controls', 3) == 1 || variable_get('comment_controls', 3) == 2)) {
- $output .= '<form method="post" action="'. url('comment') ."\"><div>\n";
- $output .= theme('comment_controls', $threshold, $mode, $order, $comments_per_page);
- $output .= form_hidden('nid', $nid);
- $output .= '</div></form>';
+ if (db_num_rows($result) && (variable_get('comment_controls', 3) == 1 || variable_get('comment_controls', 3) == 3)) {
+ $output .= comment_controls($mode, $order, $comments_per_page, $nid, 'bottom');
}
}
// 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'));
+ if (user_access('post comments') && node_comment_mode($nid) == 2 && (variable_get('comment_form_location', 0) == 1)) {
+ $output .= comment_form(array('nid' => $nid), t('Post new comment'));
}
}
return $output;
@@ -990,11 +928,13 @@ function comment_delete($cid) {
drupal_goto("node/$comment->nid");
}
else if ($comment->cid) {
- $output = theme('confirm',
+ $output = confirm_form('comment_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.'));
@@ -1043,265 +983,24 @@ function comment_admin_overview($type = 'new') {
}
/**
- * 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 .= '<h3>'. t('Moderation vote/value matrix') .'</h3>';
-
- $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 .= '<br />'. 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 .= '<h3>'. t('Initial comment scores') .'</h3>';
-
- 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 .= '<br />'. 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 .= '<h3>'. t('Moderation votes overview') .'</h3>';
-
- // 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 .= '<br /><h3>'. (isset($mid) ? t('Edit moderation option') : t('Add new moderation option')) .'</h3>';
- $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 .= '<h3>'. t('Comment threshold overview') .'</h3>';
-
- // 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 .= '<br /><h3>'. (isset($fid) ? t('Edit threshold') : t('Add new threshold')) .'</h3>';
- $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;
}
@@ -1356,34 +1055,16 @@ function comment_num_new($nid, $timestamp = 0) {
}
-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 .= "<a id=\"comment-form\"></a>\n";
- // contact information:
if ($user->uid) {
if ($edit['cid'] && user_access('administer comments')) {
- $form .= '<div class="admin">';
-
if ($edit['author']) {
$author = $edit['author'];
}
@@ -1393,54 +1074,94 @@ function theme_comment_form($edit, $title = NULL) {
else {
$author = $edit['registered_name'];
}
- $output = form_autocomplete(t('Authored by'), 'author', $author, 30, 60, 'user/autocomplete');
- $output .= form_textfield(t('Authored on'), 'date', $edit['date'] ? $edit['date'] : format_date($edit['timestamp'], 'custom', 'Y-m-d H:i O'), 20, 25, NULL, NULL, TRUE);
- $output .= form_radios(t('Status'), 'status', $edit['status'], array(t('Published'), t('Not published')));
- $output .= '<div class="authored">';
- $form .= form_group_collapsible(t('Administration'), $output, TRUE);
- $form .= "</div>\n";
+ if ($edit['status']) {
+ $status = $edit['status'];
+ }
+ else {
+ $status = 0;
+ }
+
+ if ($edit['date']) {
+ $date = $edit['date'];
+ }
+ else {
+ $date = format_date($edit['timestamp'], 'custom', 'Y-m-d H:i O');
+ }
+
+ $form['admin'] = array(type => 'fieldset', title => t('Administration'), collapsible => TRUE, collapsed => TRUE, weight => -2);
+
+ $form['admin']['author'] = array(type => 'textfield', parents => array('author'), title => t('Authored by'), size => 30, maxlength => 60, autocomplete_path => 'user/autocomplete', default_value => $author, weight => -1);
+
+ $form['admin']['date'] = array(type => 'textfield', parents => array('date'), title => t('Authored on'), size => 20, maxlength => 25, default_value => $date, weight => -1);
+
+ $form['admin']['status'] = array(type => 'radios', parents => array('status'), title => t('Status'), default_value => $status, options => array(t('Published'), t('Not published')), weight => -1);
+
}
else {
- $form .= form_item(t('Your name'), theme('username', $user));
+ $form['author'] = array(type => 'item', title => t('Your name'), value => theme('username', $user)
+ );
}
}
- else if (variable_get('comment_anonymous', 0) == 1) {
- $form .= form_textfield(t('Your name'), 'name', $edit['name'] ? $edit['name'] : variable_get('anonymous', 'Anonymous') , 30, 60);
- $form .= form_textfield(t('E-mail'), 'mail', $edit['mail'], 30, 64, t('The content of this field is kept private and will not be shown publicly.'));
- $form .= form_textfield(t('Homepage'), 'homepage', $edit['homepage'], 30, 255);
+ else if (variable_get('comment_anonymous', 1) == 2) {
+ $form['name'] = array(type => 'textfield', title => t('Your name'), maxlength => 60, size => 30, default_value => $edit['name'] ? $edit['name'] : variable_get('anonymous', 'Anonymous')
+ );
+
+ $form['mail'] = array(type => 'textfield', title => t('E-mail'), maxlength => 64, size => 30, default_value => $edit['mail'], description => t('The content of this field is kept private and will not be shown publicly.')
+ );
+
+ $form['homepage'] = array(type => 'textfield', title => t('Homepage'), maxlength => 255, size => 30, default_value => $edit['homepage']);
}
- else if (variable_get('comment_anonymous', 0) == 2) {
- $form .= form_textfield(t('Your name'), 'name', $edit['name'] ? $edit['name'] : variable_get('anonymous', 'Anonymous') , 30, 60, NULL, NULL, TRUE);
- $form .= form_textfield(t('E-mail'), 'mail', $edit['mail'], 30, 64, t('The content of this field is kept private and will not be shown publicly.'), NULL, TRUE);
- $form .= form_textfield(t('Homepage'), 'homepage', $edit['homepage'], 30, 255);
+ else if (variable_get('comment_anonymous', 1) == 3) {
+ $form['name'] = array(type => 'textfield', title => t('Your name'), maxlength => 60, size => 30, default_value => $edit['name'] ? $edit['name'] : variable_get('anonymous', 'Anonymous'), required => TRUE);
+
+ $form['name'] = array(type => 'textfield', title => t('E-mail'), maxlength => 64, size => 30, default_value => $edit['mail'],description => t('The content of this field is kept private and will not be shown publicly.'), required => TRUE);
+
+ $form['homepage'] = array(type => 'textfield', title => t('Homepage'), maxlength => 255, size => 30, default_value => $edit['homepage']);
}
- if (variable_get('comment_subject_field', 1)) {
- $form .= form_textfield(t('Subject'), 'subject', $edit['subject'], 60, 64);
+ if (variable_get('comment_subject_field', 1) == 1) {
+ $form['subject'] = array(type => 'textfield', title => t('Subject'), size => 60, maxlength => 64, default_value => $edit['subject']);
}
- $form .= form_textarea(t('Comment'), 'comment', $edit['comment'] ? $edit['comment'] : $user->signature, 60, 15, '', NULL, TRUE);
+ $form['comment'] = array(type => 'textarea', title => t('Comment'), cols => 60, rows => 15, default_value => $edit['comment'] ? $edit['comment'] : $user->signature, required => TRUE
+ );
+
+ $form = array_merge($form, filter_form($node->format));
- $form .= filter_form('format', $edit['format']);
- $form .= form_hidden('cid', $edit['cid']);
- $form .= form_hidden('pid', $edit['pid']);
- $form .= form_hidden('nid', $edit['nid']);
- $form .= form_hidden('uid', $edit['uid']);
- // generate a token used to validate that submissions came from this form
- $form .= form_token('comment'. $edit['nid'] . $edit['pid']);
+ $form['cid'] = array(type => 'hidden', value => $edit['cid']);
+ $form['pid'] = array(type => 'hidden', value => $edit['pid']);
+ $form['nid'] = array(type => 'hidden', value => $edit['nid']);
+ $form['uid'] = array(type => 'hidden', value => $edit['uid']);
- $form .= form_submit(t('Preview comment'));
+ $form['preview'] = array(type => 'submit', value => t('Preview comment'), weight => 19);
+ $form[token] = 'comment' . $edit['nid'] . $edit['pid'];
// Only show post button if preview is optional or if we are in preview mode.
// We show the post button in preview mode even if there are form errors so that
// optional form elements (e.g., captcha) can be updated in preview mode.
- if (!variable_get('comment_preview', 1) || ($_POST['op'] == t('Preview comment')) || ($_POST['op'] == t('Post comment'))) {
- $form .= form_submit(t('Post comment'));
+ if ((variable_get('comment_preview', 1) == 0) || ($_POST['op'] == t('Preview comment')) || ($_POST['op'] == t('Post comment'))) {
+ $form['submit'] = array(type => 'submit', value => t('Post comment'), weight => 20);
+ }
+
+ if ($_REQUEST['destination']) {
+ $form[attributes]['destination'] = $_REQUEST['destination'];
}
+ $form[action] = url('comment/reply/'. $edit['nid']);
- $destination = $_REQUEST['destination'] ? 'destination='. $_REQUEST['destination'] : '';
- return theme('box', $title, form($form, 'post', url('comment/reply/'. $edit['nid'], $destination)));
+ // Graft in extra form additions
+ $form = array_merge($form, comment_invoke_comment($form, 'form'));
+
+ return theme('box', $title, drupal_get_form('comment_form', $form));
+}
+
+/*
+** Renderer or visualization functions this can be optionally
+** overridden by themes.
+*/
+
+function theme_comment_form($form) {
+ return form_render($form);
}
function theme_comment_preview($comment, $links = '', $visible = 1) {
@@ -1463,6 +1184,10 @@ function theme_comment_view($comment, $links = '', $visible = 1) {
// Switch to folded/unfolded view of the comment
if ($visible) {
$comment->comment = check_markup($comment->comment, $comment->format, FALSE);
+
+ // Comment API hook
+ comment_invoke_comment($comment, 'view');
+
$output .= theme('comment', $comment, $links);
}
else {
@@ -1472,70 +1197,38 @@ function theme_comment_view($comment, $links = '', $visible = 1) {
return $output;
}
-function theme_comment_controls($threshold = 1, $mode = 3, $order = 1, $comments_per_page = 50) {
- static $output;
- $options = array();
- $result = db_query('SELECT fid, filter FROM {moderation_filters} ');
- $filters = array();
- $filters[0] = t('-- threshold --');
+function comment_controls($mode = 2, $order = 1, $comments_per_page = 50, $nid = 0, $top_or_bottom = '') {
- while($filter = db_fetch_object($result)) {
- $filters[$filter->fid] = $filter->filter;
- }
+ $form['mode'] = array(type => 'select', default_value => $mode, options => _comment_get_modes(), weight => 1);
- if (!$output) {
- $output .= '<div class="container-inline">';
- $output .= form_select(NULL, 'mode', $mode, _comment_get_modes());
- $output .= form_select(NULL, 'order', $order, _comment_get_orders());
+ $form['order'] = array(type => 'select', default_value => $order, options => _comment_get_orders(), weight => 2);
- foreach (_comment_per_page() as $i) {
- $options[] = t('%a comments per page', array('%a' => $i));
- }
- $output .= form_select(NULL, 'comments_per_page', $comments_per_page, $options);
+ foreach (_comment_per_page() as $i) {
+ $options[] = t('%a comments per page', array('%a' => $i));
+ }
+ $form['comments_per_page'] = array(type => 'select', default_value => $comments_per_page, options => $options, weight => 3);
- if ($filters) {
- $output .= form_select(NULL, 'threshold', $threshold, $filters);
- }
- else {
- $output .= form_hidden('threshold', $threshold);
- }
+ $form['submit'] = array(type => 'submit', value => t('Save settings'), weight => 20);
- $output .= ' '. form_submit(t('Save settings'));
- $output .= '</div>';
+ $form['nid'] = array(type => 'hidden', value => $nid);
- $output = form_item(NULL, $output, t('Select your preferred way to display the comments and click "Save settings" to activate your changes.'));
- }
+ $form[action] = 'comment/reply';
- return theme('box', t('Comment viewing options'), $output);
+ return drupal_get_form('comment_controls'. $top_or_bottom, $form, 'comment_controls');
}
-function comment_moderation_form($comment) {
- global $comment_votes, $user, $node;
- static $votes;
-
- $op = $_POST['op'];
+function theme_comment_controls($form) {
+ $output .= '<div class="container-inline">';
+ $output .= form_render($form);
+ $output .= '</div>';
+ $output .= '<div class="description">' . t('Select your preferred way to display the comments and click "Save settings" to activate your changes.') . '</div>';
- if ((comment_user_can_moderate($node)) && $user->uid != $comment->uid && !(comment_already_moderated($user->uid, $comment->users))) {
- // comment hasn't been moderated yet:
- if (!isset($votes) && $user->roles) {
- $result = db_query('SELECT v.mid, v.vote, MAX(v.weight) AS weight, MAX(r.value) AS value FROM {moderation_votes} v INNER JOIN {moderation_roles} r ON r.mid = v.mid WHERE r.rid IN (%s) GROUP BY v.mid, v.vote ORDER BY weight', implode(', ', array_keys($user->roles)));
- $votes = array(0 => t('defer until later'));
- while ($vote = db_fetch_object($result)) {
- if ($vote->value != 0) {
- $votes[$vote->mid] = $vote->vote;
- }
- }
- }
- if (count($votes) > 1) {
- return form_select(t('Moderation'), 'moderation]['. $comment->cid, 0, $votes);
- }
- }
+ return theme('box', t('Comment viewing options'), $output);
}
function theme_comment($comment, $links = 0) {
$output = "<div class=\"comment\">\n";
$output .= '<div class="subject">'. l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid") . ' ' . theme('mark', $comment->new) ."</div>\n";
- $output .= '<div class="moderation">'. $comment->moderation ."</div>\n";
$output .= '<div class="credit">'. t('by %a on %b', array('%a' => theme('username', $comment), '%b' => format_date($comment->timestamp))) ."</div>\n";
$output .= "<div class=\"body\">$comment->comment</div>\n";
$output .= "<div class=\"links\">$links</div>\n";
@@ -1551,33 +1244,29 @@ function theme_comment_folded($comment) {
return $output;
}
-function theme_comment_flat_collapsed($comment, $threshold) {
- if (comment_visible($comment, $threshold)) {
- return theme('comment_view', $comment, '', 0);
- }
+function theme_comment_flat_collapsed($comment) {
+ return theme('comment_view', $comment, '', 0);
return '';
}
-function theme_comment_flat_expanded($comment, $threshold) {
- return theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 0)), comment_visible($comment, $threshold));
+function theme_comment_flat_expanded($comment) {
+ return theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 0)));
}
-function theme_comment_thread_min($comment, $threshold, $pid = 0) {
- if (comment_visible($comment, $threshold)) {
- $output = '<div style="margin-left:'. ($comment->depth * 25) ."px;\">\n";
- $output .= theme('comment_view', $comment, '', 0);
- $output .= "</div>\n";
- }
+function theme_comment_thread_min($comment, $pid = 0) {
+ $output = '<div style="margin-left:'. ($comment->depth * 25) ."px;\">\n";
+ $output .= theme('comment_view', $comment, '', 0);
+ $output .= "</div>\n";
return $output;
}
-function theme_comment_thread_max($comment, $threshold, $level = 0) {
+function theme_comment_thread_max($comment, $level = 0) {
$output = '';
if ($comment->depth) {
$output .= '<div style="margin-left:'. ($comment->depth * 25) ."px;\">\n";
}
- $output .= theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 0)), comment_visible($comment, $threshold));
+ $output .= theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 0)));
if ($comment->depth) {
$output .= "</div>\n";
@@ -1605,9 +1294,9 @@ function _comment_delete_thread($comment) {
db_query('DELETE FROM {comments} WHERE cid = %d', $comment->cid);
watchdog('content', t('Comment: deleted %subject.', array('%subject' => theme('placeholder', $comment->subject))));
- module_invoke_all('comment', 'delete', $comment);
+ comment_invoke_comment($comment, 'delete');
- // Delete the comment's replies:
+ // Delete the comment's replies
$result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE pid = %d', $comment->cid);
while ($comment = db_fetch_object($result)) {
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
@@ -1622,7 +1311,7 @@ function _comment_delete_thread($comment) {
* is not initialized yet when the comment module is loaded.
*/
function _comment_get_modes() {
- return array(1 => t('Flat list - collapsed'), 2 => t('Flat list - expanded'), 3 => t('Threaded list - collapsed'), 4 => t('Threaded list - expanded'));
+ return array(t('Flat list - collapsed'), t('Flat list - expanded'), t('Threaded list - collapsed'), t('Threaded list - expanded'));
}
/**
@@ -1668,3 +1357,27 @@ function _comment_update_node_statistics($nid) {
}
}
+/**
+ * Invoke a hook_comment() operation in all modules.
+ *
+ * @param &$comment
+ * A comment object.
+ * @param $op
+ * A string containing the name of the comment operation.
+ * @return
+ * The returned value of the invoked hooks.
+ */
+function comment_invoke_comment(&$comment, $op) {
+ $return = array();
+ foreach (module_implements('comment') as $name) {
+ $function = $name .'_comment';
+ $result = $function($comment, $op);
+ if (is_array($result)) {
+ $return = array_merge($return, $result);
+ }
+ else if (isset($result)) {
+ $return[] = $result;
+ }
+ }
+ return $return;
+}
diff --git a/modules/drupal.module b/modules/drupal.module
index 483bc5f3c..4b30ab99a 100644
--- a/modules/drupal.module
+++ b/modules/drupal.module
@@ -33,19 +33,28 @@ function drupal_help($section) {
*/
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 <a href="%url">administer &raquo; settings</a> 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 <a href="%url">administer &raquo; settings</a> 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 <a href="%url">administer &raquo; settings</a> 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 <a href="%url">administer &raquo; settings</a> 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 <a href=\"%drupal-sites\">Drupal sites</a> 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 <a href=\"%drupal-sites\">Drupal sites</a> 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;
}
/**
diff --git a/modules/drupal/drupal.module b/modules/drupal/drupal.module
index 483bc5f3c..4b30ab99a 100644
--- a/modules/drupal/drupal.module
+++ b/modules/drupal/drupal.module
@@ -33,19 +33,28 @@ function drupal_help($section) {
*/
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 <a href="%url">administer &raquo; settings</a> 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 <a href="%url">administer &raquo; settings</a> 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 <a href="%url">administer &raquo; settings</a> 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 <a href="%url">administer &raquo; settings</a> 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 <a href=\"%drupal-sites\">Drupal sites</a> 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 <a href=\"%drupal-sites\">Drupal sites</a> 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;
}
/**
diff --git a/modules/filter.module b/modules/filter.module
index 0b72f3a94..27bba7941 100644
--- a/modules/filter.module
+++ b/modules/filter.module
@@ -279,8 +279,6 @@ function filter_admin_overview() {
$formats = filter_formats();
$error = false;
- $header = array(t('Default'), t('Name'), t('Roles'), array('data' => t('Operations'), 'colspan' => 2));
-
$rows = array();
foreach ($formats as $id => $format) {
$roles = array();
@@ -292,19 +290,33 @@ function filter_admin_overview() {
}
$row = array();
$default = ($id == variable_get('filter_default_format', 1));
-
- $row[] = form_radio('', 'default', $id, $default);
- $row[] = $format->name;
- $row[] = $roles ? implode(', ',$roles) : t('No roles may use this format');
- $row[] = l(t('configure'), 'admin/filters/'. $id);
- $row[] = $default ? '' : l('delete', 'admin/filters/delete/'. $id);
-
- $rows[] = $row;
+ $options[$id] = '';
+ $form[$format->name]['id'] = array(type => 'markup', value => $id);
+ $form[$format->name]['roles'] = array(type => 'markup', value => $roles ? implode(', ',$roles) : t('No roles may use this format'));
+ $form[$format->name]['configure'] = array(type => 'markup', value => l(t('configure'), 'admin/filters/'. $id));
+ $form[$format->name]['delete'] = array(type => 'markup', value => $default ? '' : l('delete', 'admin/filters/delete/'. $id));
}
+ $form['default'] = array(type => 'radios', options => $options, default_value => variable_get('filter_default_format', 1));
+ $form['submit'] = array(type => 'submit', value => t('Set default format'));
+ return drupal_get_form('filter_admin_overview', $form);
+}
- $group = theme('table', $header, $rows);
- $group .= form_submit(t('Set default format'));
- $output = form($group);
+function theme_filter_admin_overview($form) {
+ foreach ($form as $name => $element) {
+ if (isset($element['roles']) && is_array($element['roles'])) {
+ $rows[] = array(
+ form_render($form['default'][$element['id'][value]]),
+ $name,
+ form_render($element['roles']),
+ form_render($element['configure']),
+ form_render($element['delete'])
+ );
+ unset($form[$name]);
+ }
+ }
+ $header = array(t('Default'), t('Name'), t('Roles'), array('data' => t('Operations'), 'colspan' => 2));
+ $output = theme('table', $header, $rows);
+ $output .= form_render($form);
return $output;
}
@@ -319,7 +331,7 @@ function filter_admin_add() {
filter_admin_filters_save($format->format, $edit);
}
- $output= filter_admin_format_form($format);
+ $output = filter_admin_format_form($format);
return $output;
}
@@ -348,16 +360,12 @@ function filter_admin_delete() {
$format = arg(3);
$format = db_fetch_object(db_query('SELECT * FROM {filter_formats} WHERE format = %d', $format));
- $extra = form_hidden('format', $format->format);
- $extra .= form_hidden('name', $format->name);
- $output = theme('confirm',
- t('Are you sure you want to delete the input format %format?', array('%format' => theme('placeholder', $format->name))),
- 'admin/filters',
- t('If you have any content left in this input format, it will be switched to the default input format. This action cannot be undone.'),
- t('Delete'),
- t('Cancel'),
- $extra);
- return $output;
+ $form['format'] = array(type => 'hidden', value => $format->format);
+ $form['name'] = array(type => 'hidden', value => $format->name);
+
+ return confirm_form('filter_admin_delete', $form, t('Are you sure you want to delete the input format %format?', array('%format' => theme('placeholder', $format->name))), 'admin/filters', t('If you have any content left in this input format, it will be switched to the default input format. This action cannot be undone.'), t('Delete'), t('Cancel'));
+
+
}
/**
@@ -392,34 +400,37 @@ function filter_admin_format_form($format) {
$edit = $_POST['edit'];
$default = ($format->format == variable_get('filter_default_format', 1));
+ if ($default) {
+ $help = t('All roles for the default format must be enabled and cannot be changed.');
+ $form['default_format'] = array(type => 'hidden', value => 1);
+ }
//Add the name of the object
- $form = form_group(t('Name'), form_textfield(t('Name'), 'name', isset($edit) ? $edit['name'] : $format->name, 60, 127, t('Give the name of this filter format'), NULL, TRUE));
+ $form['name'] = array(type => 'fieldset', title => t('Name'));
+ $form['name']['name'] = array(type => 'textfield', default_value => $format->name, size => 60, maxlength => 127, description => t('Give the name of this filter format'), required => TRUE);
//Add a row of checkboxes for form group
+ $form['roles'] = array(type => 'fieldset', title => t('Roles'), description => $default ? $help : t('Choose which roles may use this filter format.'), tree => TRUE);
+ $form['roles']['hidden'] = array();
foreach (user_roles() as $rid => $name) {
$checked = strstr($format->roles, ",$rid,");
- $group .= form_checkbox($name, 'roles]['.$rid, 1, isset($edit) ? $edit['roles'][$rid] : ($default || $checked), NULL, $default ? array('disabled' => 'disabled') : NULL);
- }
- if ($default) {
- $help = t('All roles for the default format must be enabled and cannot be changed.');
- $group .= form_hidden('default_format', 1);
+ $form['roles'][$rid] = array(type => 'checkbox', title => $name, default_value => ($default || $checked));
+ if ($default) {
+ $form['roles'][$rid][attributes] = array('disabled' => 'disabled');
+ }
}
- $form .= form_group(t('Roles'), $group, $default ? $help : t('Choose which roles may use this filter format.'));
-
// Table with filters
$all = filter_list_all();
$enabled = filter_list_format($format->format);
- $group = '';
+ $form['filters'] = array(type => 'fieldset', title => t('Filters'), description => t('Choose the filters that will be used in this filter format'));
foreach ($all as $id => $filter) {
- $group .= form_checkbox($filter->name, $id, 1, isset($edit) ? $edit[$id] : isset($enabled[$id]), module_invoke($filter->module, 'filter', 'description', $filter->delta));
+ $form['filters'][$id] = array(type => 'checkbox', title => $filter->name, default_value => isset($enabled[$id]), description => module_invoke($filter->module, 'filter', 'description', $filter->delta));
}
- $form .= form_group(t('Filters'), $group, t('Choose the filters that will be used in this filter format'));
- $form .= form_submit(t('Save configuration'));
+ $form['submit'] = array(type => 'submit', value => t('Save configuration'));
- return form($form);
+ return drupal_get_form('filter_admin_format_form', $form);
}
/**
@@ -462,14 +473,9 @@ function filter_admin_filters_save($format, $toggles) {
}
// We store the roles as a string for ease of use.
- // we should always set all roles to true when saving a default role. disabled checkboxes may not always return TRUE.
+ // we should always set all roles to true when saving a default role.
// We use leading and trailing comma's to allow easy substring matching.
- $roles = ',';
- foreach ($edit['roles'] as $rid => $value) {
- if ($value || $edit['default_format']) {
- $roles .= $rid .',';
- }
- }
+ $roles = ','. implode(',', $edit['default_format'] ? user_roles() : array_keys($edit['roles'])) .',';
db_query("UPDATE {filter_formats} SET cache = %d, name='%s', roles = '%s' WHERE format = %d", $cache, $name, $roles, $format);
@@ -496,17 +502,29 @@ function filter_admin_order() {
// Get list (with forced refresh)
$filters = filter_list_format($format);
- $header = array(t('Name'), t('Weight'));
- $rows = array();
-
foreach ($filters as $id => $filter) {
- $rows[] = array($filter->name, form_weight('', $id, $filter->weight));
+ $form['name'][$id] = array(type => 'markup', value => $filter->name);
+ $form['weight'][$id] = array(type => 'weight', default_value => $filter->weight);
}
+ $form['submit'] = array(type => 'submit', value => t('Save configuration'));
- $form = theme('table', $header, $rows);
- $form .= form_submit(t('Save configuration'));
- $output = form($form);
+ return drupal_get_form('filter_admin_order', $form);
+}
+function theme_filter_admin_order($form) {
+ $header = array(t('Name'), t('Weight'));
+ $rows = array();
+ foreach (element_children($form['name']) as $id) {
+ // Don't take form control structures
+ if (is_array($form['name'][$id])) {
+ $rows[] = array(
+ form_render($form['name'][$id]),
+ form_render($form['weight'][$id]));
+ }
+ }
+
+ $output = theme('table', $header, $rows);
+ $output .= form_render($form);
return $output;
}
@@ -530,16 +548,14 @@ function filter_admin_order_save($format, $weights) {
function filter_admin_configure() {
$format = arg(2);
- system_settings_save();
-
$list = filter_list_format($format);
- $form = "";
+ $form = array();
foreach ($list as $filter) {
- $form .= module_invoke($filter->module, 'filter', 'settings', $filter->delta, $format);
+ $form = array_merge($form, module_invoke($filter->module, 'filter', 'settings', $filter->delta, $format));
}
- if (trim($form) != '') {
- $output = system_settings_form($form);
+ if (!empty($form)) {
+ $output = system_settings_form('filter_admin_configure', $form);
}
else {
$output = t('No settings are available.');
@@ -727,7 +743,7 @@ function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) {
* @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);
}
@@ -735,31 +751,38 @@ function filter_form($name = 'format', $value = FILTER_FORMAT_DEFAULT) {
$extra = l(t('More information about formatting options'), 'filter/tips');
+ $form['format'] = array(type => 'fieldset', title => t('Input format'), collapsible => TRUE, collapsed => TRUE, weight => -4);
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 <br /> is not output?
- $output .= '<div>';
- $output .= '<label class="option"><input type="radio" class="form-radio" name="edit['. $name .']" value="'. $format->format .'"'. ($format->format == $value ? ' checked="checked"' : '') .' /> '. $format->name .'</label>';
- $output .= theme('filter_tips', $tips);
- $output .= '</div>';
+ $form['format'][$format->format] = array(type => 'filter_format', title => $format->name, default_value => $value, return_value => $format->format, parents => array('format'), description => theme('filter_tips', _filter_tips($format->format, false)));
}
-
- return form_group_collapsible(t('Input format'), $output, $extra);
+ return $form;
}
else {
// Only one format available: use a hidden form item and only show tips.
$format = array_shift($formats);
- $output = form_hidden($name, $format->format);
+ $form['format'][$format->name] = array(type => 'value', value => $format->format);
$tips = _filter_tips(variable_get('filter_default_format', 1), false);
- $output .= form_item(t('Formatting guidelines'), theme('filter_tips', $tips, false, $extra), $extra);
- return $output;
+ $form['format']['guidelines'] = array(type => 'item', title => t('Formatting guidelines'), value => theme('filter_tips', $tips, false, $extra), $extra);
+ return $form;
}
}
+function filter_elements() {
+ $type['filter_format'] = array(input => TRUE);
+ return $type;
+}
+
+function theme_filter_format($element) {
+ $output .= '<div>';
+ $output .= '<label class="option"><input type="radio" class="form-radio" name="' . $element[name] . '" value="'. $element[return_value] .'"'. (($element[default_value] == $element[return_value]) ? ' checked="checked"' : '') .' /> '. $element[title] .'</label>';
+ $output .= $element[description];
+ $output .= '</div>';
+ return $output;
+}
+
+
/**
* Returns true if the user is allowed to access this format.
*/
@@ -925,14 +948,14 @@ function filter_filter($op, $delta = 0, $format = -1, $text = '') {
* Settings for the HTML filter.
*/
function _filter_html_settings($format) {
- $group = form_radios(t('Filter HTML tags'), "filter_html_$format", variable_get("filter_html_$format", FILTER_HTML_STRIP), array(FILTER_HTML_STRIP => t('Strip tags'), FILTER_HTML_ESCAPE => t('Escape tags')), t('How to deal with HTML tags in user-contributed content. If set to "Strip tags", dangerous tags are removed (see below). If set to "Escape tags", all HTML is escaped and presented as it was typed.'));
- $group .= form_textfield(t('Allowed HTML tags'), "allowed_html_$format", variable_get("allowed_html_$format", '<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>'), 64, 255, t('If "Strip tags" is selected, optionally specify tags which should not be stripped. Javascript event attributes are always stripped.'));
- $group .= form_checkbox(t('Display HTML help'), "filter_html_help_$format", 1, variable_get("filter_html_help_$format", 1), t('If enabled, Drupal will display some basic HTML help in the long filter tips.'));
- $group .= form_radios(t('HTML style attributes'), "filter_style_$format", variable_get("filter_style_$format", FILTER_STYLE_STRIP), array(FILTER_STYLE_ALLOW => t('Allowed'), FILTER_STYLE_STRIP => t('Removed')), t('If "Strip tags" is selected, you can choose whether "STYLE" attributes are allowed or removed from input.'));
- $group .= form_checkbox(t('Spam link deterrent'), "filter_html_nofollow_$format", 1, variable_get("filter_html_nofollow_$format", FALSE), t('If enabled, Drupal will add rel="nofollow" to all links, as a measure to reduce the effectiveness of spam links. Note: this will also prevent valid links from being followed by search engines, therefore it is likely most effective when enabled for anonymous users.'));
- $output .= form_group_collapsible(t('HTML filter'), $group, TRUE);
-
- return $output;
+ $form['filter_html'] = array(type => 'fieldset', title => t('HTML filter'), collapsible => TRUE, collapsed => TRUE);
+ $form['filter_html']["filter_html_$format"] = array(type => 'radios', title => t('Filter HTML tags'), default_value => variable_get("filter_html_$format", FILTER_HTML_STRIP), options => array(FILTER_HTML_STRIP => t('Strip tags'), FILTER_HTML_ESCAPE => t('Escape tags')), description => t('How to deal with HTML tags in user-contributed content. If set to "Strip tags", dangerous tags are removed (see below). If set to "Escape tags", all HTML is escaped and presented as it was typed.'));
+ $form['filter_html']["allowed_html_$format"] = array(type => 'textfield', title => t('Allowed HTML tags'), default_value => variable_get("allowed_html_$format", '<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>'), size => 64, maxlength => 255, description => t('If "Strip tags" is selected, optionally specify tags which should not be stripped. Javascript event attributes are always stripped.'));
+ $form['filter_html']["filter_html_help_$format"] = array(type => 'checkbox', title => t('Display HTML help'), default_value => variable_get("filter_html_help_$format", 1), description => t('If enabled, Drupal will display some basic HTML help in the long filter tips.'));
+ $form['filter_html']["filter_style_$format"] = array(type => 'radios', title => t('HTML style attributes'), default_value => variable_get("filter_style_$format", FILTER_STYLE_STRIP), options => array(FILTER_STYLE_ALLOW => t('Allowed'), FILTER_STYLE_STRIP => t('Removed')), description => t('If "Strip tags" is selected, you can choose whether "STYLE" attributes are allowed or removed from input.'));
+ $form['filter_html']["filter_html_nofollow_$format"] = array(type => 'checkbox', title => t('Spam link deterrent'), default_value => variable_get("filter_html_nofollow_$format", FALSE), description => t('If enabled, Drupal will add rel="nofollow" to all links, as a measure to reduce the effectiveness of spam links. Note: this will also prevent valid links from being followed by search engines, therefore it is likely most effective when enabled for anonymous users.'));
+
+ return $form;
}
/**
@@ -1019,4 +1042,3 @@ function _filter_autop($text) {
* @} End of "Standard filters".
*/
-
diff --git a/modules/filter/filter.module b/modules/filter/filter.module
index 0b72f3a94..27bba7941 100644
--- a/modules/filter/filter.module
+++ b/modules/filter/filter.module
@@ -279,8 +279,6 @@ function filter_admin_overview() {
$formats = filter_formats();
$error = false;
- $header = array(t('Default'), t('Name'), t('Roles'), array('data' => t('Operations'), 'colspan' => 2));
-
$rows = array();
foreach ($formats as $id => $format) {
$roles = array();
@@ -292,19 +290,33 @@ function filter_admin_overview() {
}
$row = array();
$default = ($id == variable_get('filter_default_format', 1));
-
- $row[] = form_radio('', 'default', $id, $default);
- $row[] = $format->name;
- $row[] = $roles ? implode(', ',$roles) : t('No roles may use this format');
- $row[] = l(t('configure'), 'admin/filters/'. $id);
- $row[] = $default ? '' : l('delete', 'admin/filters/delete/'. $id);
-
- $rows[] = $row;
+ $options[$id] = '';
+ $form[$format->name]['id'] = array(type => 'markup', value => $id);
+ $form[$format->name]['roles'] = array(type => 'markup', value => $roles ? implode(', ',$roles) : t('No roles may use this format'));
+ $form[$format->name]['configure'] = array(type => 'markup', value => l(t('configure'), 'admin/filters/'. $id));
+ $form[$format->name]['delete'] = array(type => 'markup', value => $default ? '' : l('delete', 'admin/filters/delete/'. $id));
}
+ $form['default'] = array(type => 'radios', options => $options, default_value => variable_get('filter_default_format', 1));
+ $form['submit'] = array(type => 'submit', value => t('Set default format'));
+ return drupal_get_form('filter_admin_overview', $form);
+}
- $group = theme('table', $header, $rows);
- $group .= form_submit(t('Set default format'));
- $output = form($group);
+function theme_filter_admin_overview($form) {
+ foreach ($form as $name => $element) {
+ if (isset($element['roles']) && is_array($element['roles'])) {
+ $rows[] = array(
+ form_render($form['default'][$element['id'][value]]),
+ $name,
+ form_render($element['roles']),
+ form_render($element['configure']),
+ form_render($element['delete'])
+ );
+ unset($form[$name]);
+ }
+ }
+ $header = array(t('Default'), t('Name'), t('Roles'), array('data' => t('Operations'), 'colspan' => 2));
+ $output = theme('table', $header, $rows);
+ $output .= form_render($form);
return $output;
}
@@ -319,7 +331,7 @@ function filter_admin_add() {
filter_admin_filters_save($format->format, $edit);
}
- $output= filter_admin_format_form($format);
+ $output = filter_admin_format_form($format);
return $output;
}
@@ -348,16 +360,12 @@ function filter_admin_delete() {
$format = arg(3);
$format = db_fetch_object(db_query('SELECT * FROM {filter_formats} WHERE format = %d', $format));
- $extra = form_hidden('format', $format->format);
- $extra .= form_hidden('name', $format->name);
- $output = theme('confirm',
- t('Are you sure you want to delete the input format %format?', array('%format' => theme('placeholder', $format->name))),
- 'admin/filters',
- t('If you have any content left in this input format, it will be switched to the default input format. This action cannot be undone.'),
- t('Delete'),
- t('Cancel'),
- $extra);
- return $output;
+ $form['format'] = array(type => 'hidden', value => $format->format);
+ $form['name'] = array(type => 'hidden', value => $format->name);
+
+ return confirm_form('filter_admin_delete', $form, t('Are you sure you want to delete the input format %format?', array('%format' => theme('placeholder', $format->name))), 'admin/filters', t('If you have any content left in this input format, it will be switched to the default input format. This action cannot be undone.'), t('Delete'), t('Cancel'));
+
+
}
/**
@@ -392,34 +400,37 @@ function filter_admin_format_form($format) {
$edit = $_POST['edit'];
$default = ($format->format == variable_get('filter_default_format', 1));
+ if ($default) {
+ $help = t('All roles for the default format must be enabled and cannot be changed.');
+ $form['default_format'] = array(type => 'hidden', value => 1);
+ }
//Add the name of the object
- $form = form_group(t('Name'), form_textfield(t('Name'), 'name', isset($edit) ? $edit['name'] : $format->name, 60, 127, t('Give the name of this filter format'), NULL, TRUE));
+ $form['name'] = array(type => 'fieldset', title => t('Name'));
+ $form['name']['name'] = array(type => 'textfield', default_value => $format->name, size => 60, maxlength => 127, description => t('Give the name of this filter format'), required => TRUE);
//Add a row of checkboxes for form group
+ $form['roles'] = array(type => 'fieldset', title => t('Roles'), description => $default ? $help : t('Choose which roles may use this filter format.'), tree => TRUE);
+ $form['roles']['hidden'] = array();
foreach (user_roles() as $rid => $name) {
$checked = strstr($format->roles, ",$rid,");
- $group .= form_checkbox($name, 'roles]['.$rid, 1, isset($edit) ? $edit['roles'][$rid] : ($default || $checked), NULL, $default ? array('disabled' => 'disabled') : NULL);
- }
- if ($default) {
- $help = t('All roles for the default format must be enabled and cannot be changed.');
- $group .= form_hidden('default_format', 1);
+ $form['roles'][$rid] = array(type => 'checkbox', title => $name, default_value => ($default || $checked));
+ if ($default) {
+ $form['roles'][$rid][attributes] = array('disabled' => 'disabled');
+ }
}
- $form .= form_group(t('Roles'), $group, $default ? $help : t('Choose which roles may use this filter format.'));
-
// Table with filters
$all = filter_list_all();
$enabled = filter_list_format($format->format);
- $group = '';
+ $form['filters'] = array(type => 'fieldset', title => t('Filters'), description => t('Choose the filters that will be used in this filter format'));
foreach ($all as $id => $filter) {
- $group .= form_checkbox($filter->name, $id, 1, isset($edit) ? $edit[$id] : isset($enabled[$id]), module_invoke($filter->module, 'filter', 'description', $filter->delta));
+ $form['filters'][$id] = array(type => 'checkbox', title => $filter->name, default_value => isset($enabled[$id]), description => module_invoke($filter->module, 'filter', 'description', $filter->delta));
}
- $form .= form_group(t('Filters'), $group, t('Choose the filters that will be used in this filter format'));
- $form .= form_submit(t('Save configuration'));
+ $form['submit'] = array(type => 'submit', value => t('Save configuration'));
- return form($form);
+ return drupal_get_form('filter_admin_format_form', $form);
}
/**
@@ -462,14 +473,9 @@ function filter_admin_filters_save($format, $toggles) {
}
// We store the roles as a string for ease of use.
- // we should always set all roles to true when saving a default role. disabled checkboxes may not always return TRUE.
+ // we should always set all roles to true when saving a default role.
// We use leading and trailing comma's to allow easy substring matching.
- $roles = ',';
- foreach ($edit['roles'] as $rid => $value) {
- if ($value || $edit['default_format']) {
- $roles .= $rid .',';
- }
- }
+ $roles = ','. implode(',', $edit['default_format'] ? user_roles() : array_keys($edit['roles'])) .',';
db_query("UPDATE {filter_formats} SET cache = %d, name='%s', roles = '%s' WHERE format = %d", $cache, $name, $roles, $format);
@@ -496,17 +502,29 @@ function filter_admin_order() {
// Get list (with forced refresh)
$filters = filter_list_format($format);
- $header = array(t('Name'), t('Weight'));
- $rows = array();
-
foreach ($filters as $id => $filter) {
- $rows[] = array($filter->name, form_weight('', $id, $filter->weight));
+ $form['name'][$id] = array(type => 'markup', value => $filter->name);
+ $form['weight'][$id] = array(type => 'weight', default_value => $filter->weight);
}
+ $form['submit'] = array(type => 'submit', value => t('Save configuration'));
- $form = theme('table', $header, $rows);
- $form .= form_submit(t('Save configuration'));
- $output = form($form);
+ return drupal_get_form('filter_admin_order', $form);
+}
+function theme_filter_admin_order($form) {
+ $header = array(t('Name'), t('Weight'));
+ $rows = array();
+ foreach (element_children($form['name']) as $id) {
+ // Don't take form control structures
+ if (is_array($form['name'][$id])) {
+ $rows[] = array(
+ form_render($form['name'][$id]),
+ form_render($form['weight'][$id]));
+ }
+ }
+
+ $output = theme('table', $header, $rows);
+ $output .= form_render($form);
return $output;
}
@@ -530,16 +548,14 @@ function filter_admin_order_save($format, $weights) {
function filter_admin_configure() {
$format = arg(2);
- system_settings_save();
-
$list = filter_list_format($format);
- $form = "";
+ $form = array();
foreach ($list as $filter) {
- $form .= module_invoke($filter->module, 'filter', 'settings', $filter->delta, $format);
+ $form = array_merge($form, module_invoke($filter->module, 'filter', 'settings', $filter->delta, $format));
}
- if (trim($form) != '') {
- $output = system_settings_form($form);
+ if (!empty($form)) {
+ $output = system_settings_form('filter_admin_configure', $form);
}
else {
$output = t('No settings are available.');
@@ -727,7 +743,7 @@ function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) {
* @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);
}
@@ -735,31 +751,38 @@ function filter_form($name = 'format', $value = FILTER_FORMAT_DEFAULT) {
$extra = l(t('More information about formatting options'), 'filter/tips');
+ $form['format'] = array(type => 'fieldset', title => t('Input format'), collapsible => TRUE, collapsed => TRUE, weight => -4);
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 <br /> is not output?
- $output .= '<div>';
- $output .= '<label class="option"><input type="radio" class="form-radio" name="edit['. $name .']" value="'. $format->format .'"'. ($format->format == $value ? ' checked="checked"' : '') .' /> '. $format->name .'</label>';
- $output .= theme('filter_tips', $tips);
- $output .= '</div>';
+ $form['format'][$format->format] = array(type => 'filter_format', title => $format->name, default_value => $value, return_value => $format->format, parents => array('format'), description => theme('filter_tips', _filter_tips($format->format, false)));
}
-
- return form_group_collapsible(t('Input format'), $output, $extra);
+ return $form;
}
else {
// Only one format available: use a hidden form item and only show tips.
$format = array_shift($formats);
- $output = form_hidden($name, $format->format);
+ $form['format'][$format->name] = array(type => 'value', value => $format->format);
$tips = _filter_tips(variable_get('filter_default_format', 1), false);
- $output .= form_item(t('Formatting guidelines'), theme('filter_tips', $tips, false, $extra), $extra);
- return $output;
+ $form['format']['guidelines'] = array(type => 'item', title => t('Formatting guidelines'), value => theme('filter_tips', $tips, false, $extra), $extra);
+ return $form;
}
}
+function filter_elements() {
+ $type['filter_format'] = array(input => TRUE);
+ return $type;
+}
+
+function theme_filter_format($element) {
+ $output .= '<div>';
+ $output .= '<label class="option"><input type="radio" class="form-radio" name="' . $element[name] . '" value="'. $element[return_value] .'"'. (($element[default_value] == $element[return_value]) ? ' checked="checked"' : '') .' /> '. $element[title] .'</label>';
+ $output .= $element[description];
+ $output .= '</div>';
+ return $output;
+}
+
+
/**
* Returns true if the user is allowed to access this format.
*/
@@ -925,14 +948,14 @@ function filter_filter($op, $delta = 0, $format = -1, $text = '') {
* Settings for the HTML filter.
*/
function _filter_html_settings($format) {
- $group = form_radios(t('Filter HTML tags'), "filter_html_$format", variable_get("filter_html_$format", FILTER_HTML_STRIP), array(FILTER_HTML_STRIP => t('Strip tags'), FILTER_HTML_ESCAPE => t('Escape tags')), t('How to deal with HTML tags in user-contributed content. If set to "Strip tags", dangerous tags are removed (see below). If set to "Escape tags", all HTML is escaped and presented as it was typed.'));
- $group .= form_textfield(t('Allowed HTML tags'), "allowed_html_$format", variable_get("allowed_html_$format", '<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>'), 64, 255, t('If "Strip tags" is selected, optionally specify tags which should not be stripped. Javascript event attributes are always stripped.'));
- $group .= form_checkbox(t('Display HTML help'), "filter_html_help_$format", 1, variable_get("filter_html_help_$format", 1), t('If enabled, Drupal will display some basic HTML help in the long filter tips.'));
- $group .= form_radios(t('HTML style attributes'), "filter_style_$format", variable_get("filter_style_$format", FILTER_STYLE_STRIP), array(FILTER_STYLE_ALLOW => t('Allowed'), FILTER_STYLE_STRIP => t('Removed')), t('If "Strip tags" is selected, you can choose whether "STYLE" attributes are allowed or removed from input.'));
- $group .= form_checkbox(t('Spam link deterrent'), "filter_html_nofollow_$format", 1, variable_get("filter_html_nofollow_$format", FALSE), t('If enabled, Drupal will add rel="nofollow" to all links, as a measure to reduce the effectiveness of spam links. Note: this will also prevent valid links from being followed by search engines, therefore it is likely most effective when enabled for anonymous users.'));
- $output .= form_group_collapsible(t('HTML filter'), $group, TRUE);
-
- return $output;
+ $form['filter_html'] = array(type => 'fieldset', title => t('HTML filter'), collapsible => TRUE, collapsed => TRUE);
+ $form['filter_html']["filter_html_$format"] = array(type => 'radios', title => t('Filter HTML tags'), default_value => variable_get("filter_html_$format", FILTER_HTML_STRIP), options => array(FILTER_HTML_STRIP => t('Strip tags'), FILTER_HTML_ESCAPE => t('Escape tags')), description => t('How to deal with HTML tags in user-contributed content. If set to "Strip tags", dangerous tags are removed (see below). If set to "Escape tags", all HTML is escaped and presented as it was typed.'));
+ $form['filter_html']["allowed_html_$format"] = array(type => 'textfield', title => t('Allowed HTML tags'), default_value => variable_get("allowed_html_$format", '<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>'), size => 64, maxlength => 255, description => t('If "Strip tags" is selected, optionally specify tags which should not be stripped. Javascript event attributes are always stripped.'));
+ $form['filter_html']["filter_html_help_$format"] = array(type => 'checkbox', title => t('Display HTML help'), default_value => variable_get("filter_html_help_$format", 1), description => t('If enabled, Drupal will display some basic HTML help in the long filter tips.'));
+ $form['filter_html']["filter_style_$format"] = array(type => 'radios', title => t('HTML style attributes'), default_value => variable_get("filter_style_$format", FILTER_STYLE_STRIP), options => array(FILTER_STYLE_ALLOW => t('Allowed'), FILTER_STYLE_STRIP => t('Removed')), description => t('If "Strip tags" is selected, you can choose whether "STYLE" attributes are allowed or removed from input.'));
+ $form['filter_html']["filter_html_nofollow_$format"] = array(type => 'checkbox', title => t('Spam link deterrent'), default_value => variable_get("filter_html_nofollow_$format", FALSE), description => t('If enabled, Drupal will add rel="nofollow" to all links, as a measure to reduce the effectiveness of spam links. Note: this will also prevent valid links from being followed by search engines, therefore it is likely most effective when enabled for anonymous users.'));
+
+ return $form;
}
/**
@@ -1019,4 +1042,3 @@ function _filter_autop($text) {
* @} End of "Standard filters".
*/
-
diff --git a/modules/forum.module b/modules/forum.module
index 42aa877ad..547c34ec9 100644
--- a/modules/forum.module
+++ b/modules/forum.module
@@ -158,15 +158,10 @@ function forum_taxonomy($op, $type, $object) {
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,20 @@ function _forum_confirm_delete($tid) {
* @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 .= _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['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'][tree] = TRUE;
+ $form['parent'][0] = _forum_parent_select($edit['tid'], t('Parent'), 'container');
+ $form['weight'] = array(type => 'weight', title => t('Weight'), default_value => $edit['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['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 +192,20 @@ function forum_form_container($edit = array()) {
* @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 .= form_hidden('vid', _forum_get_vid());
- $form .= form_submit(t('Submit'));
+ $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'][tree] = TRUE;
+ $form['parent'][0] = _forum_parent_select($edit['tid'], t('Parent'), 'forum');
+ $form['weight'] = array(type => 'weight', title => t('Weight'), default_value => $edit['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['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 +213,9 @@ function forum_form_forum($edit = array()) {
*
* @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 +250,7 @@ function _forum_parent_select($tid, $title, $name, $child_type) {
$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);
}
/**
@@ -318,17 +313,17 @@ function _forum_get_vid() {
* Implementation of hook_settings
*/
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 => 'textfield', 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'), options => $forder, description => t('The default display order for topics.'));
- return system_settings_form($output);
+ return system_settings_form('forum_admin_configure', $form);
}
/**
@@ -354,8 +349,8 @@ function forum_block($op = 'list', $delta = 0, $edit = array()) {
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]);
@@ -560,7 +555,7 @@ function forum_update($node) {
* Implementation of hook_form().
*/
function forum_form(&$node) {
- $output = form_textfield(t('Subject'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
+ $form['title'] = array(type => 'textfield', title => t('Subject'), default_value => $node->title, size => 60, maxlength => 128, required => TRUE);
if (!$node->nid) {
// new topic
@@ -569,19 +564,22 @@ function forum_form(&$node) {
else {
$node->taxonomy = array($node->tid);
}
-
- $output .= implode('', taxonomy_node_form('forum', $node));
+
+ if (function_exists('taxonomy_node_form')) {
+ $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;
}
/**
diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index 42aa877ad..547c34ec9 100644
--- a/modules/forum/forum.module
+++ b/modules/forum/forum.module
@@ -158,15 +158,10 @@ function forum_taxonomy($op, $type, $object) {
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,20 @@ function _forum_confirm_delete($tid) {
* @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 .= _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['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'][tree] = TRUE;
+ $form['parent'][0] = _forum_parent_select($edit['tid'], t('Parent'), 'container');
+ $form['weight'] = array(type => 'weight', title => t('Weight'), default_value => $edit['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['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 +192,20 @@ function forum_form_container($edit = array()) {
* @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 .= form_hidden('vid', _forum_get_vid());
- $form .= form_submit(t('Submit'));
+ $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'][tree] = TRUE;
+ $form['parent'][0] = _forum_parent_select($edit['tid'], t('Parent'), 'forum');
+ $form['weight'] = array(type => 'weight', title => t('Weight'), default_value => $edit['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['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 +213,9 @@ function forum_form_forum($edit = array()) {
*
* @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 +250,7 @@ function _forum_parent_select($tid, $title, $name, $child_type) {
$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);
}
/**
@@ -318,17 +313,17 @@ function _forum_get_vid() {
* Implementation of hook_settings
*/
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 => 'textfield', 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'), options => $forder, description => t('The default display order for topics.'));
- return system_settings_form($output);
+ return system_settings_form('forum_admin_configure', $form);
}
/**
@@ -354,8 +349,8 @@ function forum_block($op = 'list', $delta = 0, $edit = array()) {
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]);
@@ -560,7 +555,7 @@ function forum_update($node) {
* Implementation of hook_form().
*/
function forum_form(&$node) {
- $output = form_textfield(t('Subject'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
+ $form['title'] = array(type => 'textfield', title => t('Subject'), default_value => $node->title, size => 60, maxlength => 128, required => TRUE);
if (!$node->nid) {
// new topic
@@ -569,19 +564,22 @@ function forum_form(&$node) {
else {
$node->taxonomy = array($node->tid);
}
-
- $output .= implode('', taxonomy_node_form('forum', $node));
+
+ if (function_exists('taxonomy_node_form')) {
+ $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;
}
/**
diff --git a/modules/locale.module b/modules/locale.module
index 58deceb63..1f9f6115a 100644
--- a/modules/locale.module
+++ b/modules/locale.module
@@ -108,7 +108,7 @@ function locale_user($type, $edit, &$user, $category = NULL) {
$user->language = key($languages['name']);
}
$languages['name'] = array_map('check_plain', $languages['name']);
- return array(array('title' => t('Interface language settings'), 'data' => form_radios(t("Language"), 'language', $user->language, $languages['name'], t("Selecting a different locale will change the interface language of the site."))));
+ return array(array('title' => t('Interface language settings'), 'data' => $form['locale_user'] = array(type => 'radios', title => t('Language'), default_value => $user->language, options => $languages['name'], description => t('Selecting a different locale will change the interface language of the site.'))));
}
}
@@ -319,15 +319,12 @@ function locale_admin_manage_delete_screen() {
// For other locales, warn user that data loss is ahead
$languages = locale_supported_languages(FALSE, TRUE);
- $extra = form_hidden('langcode', $langcode);
- $output = theme('confirm',
+ $form['langcode'] = array(type => 'hidden', value => $langcode);
+ return confirm_form('locale_admin_manage_delete_screen', $form,
t('Are you sure you want to delete the language %name?', array('%name' => theme('placeholder', t($languages['name'][$langcode])))),
'admin/locale/language/overview',
t('Deleting a language will remove all data associated with it. This action cannot be undone.'),
- t('Delete'),
- t('Cancel'),
- $extra);
- return $output;
+ t('Delete'), t('Cancel'));
}
/**
@@ -338,31 +335,32 @@ function locale_admin_manage_add() {
$edit = &$_POST['edit'];
$isocodes = _locale_get_iso639_list();
- switch ($_POST['op']) {
- // Try to add new language
- case t('Add language'):
- // Check for duplicates
- if (db_num_rows(db_query("SELECT locale FROM {locales_meta} WHERE locale = '%s'", $edit['langcode'])) == 0) {
-
+ // Check for duplicates
+ if ($duplicate = db_num_rows(db_query("SELECT locale FROM {locales_meta} WHERE locale = '%s'", $edit['langcode'])) == 0) {
+ switch ($_POST['op']) {
+ // Try to add new language
+ case t('Add language'):
// Set language name from the available list if needed
if ($edit['langcode'] && !$edit['langname'] && isset($isocodes[$edit['langcode']])) {
_locale_add_language($edit['langcode'], $isocodes[$edit['langcode']][0]);
drupal_goto('admin/locale');
}
-
+ break;
+ case t('Add custom language'):
// Add language, if we have the details
- elseif ($edit['langcode'] && $edit['langname']) {
+ if ($edit['langcode'] && $edit['langname']) {
_locale_add_language($edit['langcode'], $edit['langname']);
drupal_goto('admin/locale');
}
-
// Seems like we have not received some data
drupal_set_message(t('The language code and the English name of the new language must be specified.'), 'error');
- }
- else {
- drupal_set_message(t('The language %language (%code) already exists.', array('%language' => theme('placeholder', check_plain($edit['langname'])), '%code' => theme('placeholder', $edit['langcode']))), 'error');
- }
- break;
+ break;
+ default:
+ break;
+ }
+ }
+ else {
+ drupal_set_message(t('The language %language (%code) already exists.', array('%language' => theme('placeholder', check_plain($edit['langname'])), '%code' => theme('placeholder', $edit['langcode']))), 'error');
}
return _locale_admin_manage_add_screen();
}
diff --git a/modules/locale/locale.module b/modules/locale/locale.module
index 58deceb63..1f9f6115a 100644
--- a/modules/locale/locale.module
+++ b/modules/locale/locale.module
@@ -108,7 +108,7 @@ function locale_user($type, $edit, &$user, $category = NULL) {
$user->language = key($languages['name']);
}
$languages['name'] = array_map('check_plain', $languages['name']);
- return array(array('title' => t('Interface language settings'), 'data' => form_radios(t("Language"), 'language', $user->language, $languages['name'], t("Selecting a different locale will change the interface language of the site."))));
+ return array(array('title' => t('Interface language settings'), 'data' => $form['locale_user'] = array(type => 'radios', title => t('Language'), default_value => $user->language, options => $languages['name'], description => t('Selecting a different locale will change the interface language of the site.'))));
}
}
@@ -319,15 +319,12 @@ function locale_admin_manage_delete_screen() {
// For other locales, warn user that data loss is ahead
$languages = locale_supported_languages(FALSE, TRUE);
- $extra = form_hidden('langcode', $langcode);
- $output = theme('confirm',
+ $form['langcode'] = array(type => 'hidden', value => $langcode);
+ return confirm_form('locale_admin_manage_delete_screen', $form,
t('Are you sure you want to delete the language %name?', array('%name' => theme('placeholder', t($languages['name'][$langcode])))),
'admin/locale/language/overview',
t('Deleting a language will remove all data associated with it. This action cannot be undone.'),
- t('Delete'),
- t('Cancel'),
- $extra);
- return $output;
+ t('Delete'), t('Cancel'));
}
/**
@@ -338,31 +335,32 @@ function locale_admin_manage_add() {
$edit = &$_POST['edit'];
$isocodes = _locale_get_iso639_list();
- switch ($_POST['op']) {
- // Try to add new language
- case t('Add language'):
- // Check for duplicates
- if (db_num_rows(db_query("SELECT locale FROM {locales_meta} WHERE locale = '%s'", $edit['langcode'])) == 0) {
-
+ // Check for duplicates
+ if ($duplicate = db_num_rows(db_query("SELECT locale FROM {locales_meta} WHERE locale = '%s'", $edit['langcode'])) == 0) {
+ switch ($_POST['op']) {
+ // Try to add new language
+ case t('Add language'):
// Set language name from the available list if needed
if ($edit['langcode'] && !$edit['langname'] && isset($isocodes[$edit['langcode']])) {
_locale_add_language($edit['langcode'], $isocodes[$edit['langcode']][0]);
drupal_goto('admin/locale');
}
-
+ break;
+ case t('Add custom language'):
// Add language, if we have the details
- elseif ($edit['langcode'] && $edit['langname']) {
+ if ($edit['langcode'] && $edit['langname']) {
_locale_add_language($edit['langcode'], $edit['langname']);
drupal_goto('admin/locale');
}
-
// Seems like we have not received some data
drupal_set_message(t('The language code and the English name of the new language must be specified.'), 'error');
- }
- else {
- drupal_set_message(t('The language %language (%code) already exists.', array('%language' => theme('placeholder', check_plain($edit['langname'])), '%code' => theme('placeholder', $edit['langcode']))), 'error');
- }
- break;
+ break;
+ default:
+ break;
+ }
+ }
+ else {
+ drupal_set_message(t('The language %language (%code) already exists.', array('%language' => theme('placeholder', check_plain($edit['langname'])), '%code' => theme('placeholder', $edit['langcode']))), 'error');
}
return _locale_admin_manage_add_screen();
}
diff --git a/modules/menu.module b/modules/menu.module
index 17dfcb787..7667c0c19 100644
--- a/modules/menu.module
+++ b/modules/menu.module
@@ -98,7 +98,7 @@ function menu_nodeapi(&$node, $op) {
if (user_access('administer menu')) {
switch ($op) {
- case 'form post':
+ case 'form':
$edit = $_POST['edit'];
$edit['nid'] = $node->nid;
return menu_node_form($edit);
@@ -153,12 +153,10 @@ function menu_reset() {
drupal_goto('admin/menu');
break;
default:
- $output = theme('confirm',
- t('Are you sure you want to reset all menu items to their default settings?'),
- 'admin/menu',
- t('Any custom additions or changes to the menu will be lost.'),
- t('Reset all'));
- return $output;
+ return confirm_form('menu_confirm_reset', array(),
+ t('Are you sure you want to reset all menu items to their default settings?'),
+ 'admin/menu', t('Any custom additions or changes to the menu will be lost.'),
+ t('Reset all'));
}
}
@@ -200,12 +198,10 @@ function menu_reset_item($mid) {
break;
default:
$title = db_result(db_query('SELECT title FROM {menu} WHERE mid = %d', $mid));
- $output = theme('confirm',
- t('Are you sure you want to reset the item %item to its default values?', array('%item' => theme('placeholder', $title))),
- 'admin/menu',
- t('Any customizations will be lost. This action cannot be undone.'),
- t('Reset'));
- return $output;
+ return confirm_form('menu_item_confirm_reset', array(),
+ t('Are you sure you want to reset the item %item to its default values?', array('%item' => theme('placeholder', $title))),
+ 'admin/menu', t('Any customizations will be lost. This action cannot be undone.'),
+ t('Reset'));
}
}
@@ -237,8 +233,7 @@ function menu_delete_item($mid) {
else {
$message = t('Are you sure you want to delete the custom menu item %item?', array('%item' => theme('placeholder', $menu->title)));
}
- $output = theme('confirm', $message, 'admin/menu', t('This action cannot be undone.'), t('Delete'));
- return $output;
+ return confirm_form('menu_confirm_delete', $form, $message, 'admin/menu', t('This action cannot be undone.'), t('Delete'));
}
}
@@ -303,16 +298,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 +317,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.'));
+ $expanded = $edit['type'] & MENU_EXPANDED ? 1 : 0;
+ $form['expanded'] = array(type => 'checkbox', title => t('Expanded'), default_value => $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', title => 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 +543,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, tree => 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;
}
diff --git a/modules/menu/menu.module b/modules/menu/menu.module
index 17dfcb787..7667c0c19 100644
--- a/modules/menu/menu.module
+++ b/modules/menu/menu.module
@@ -98,7 +98,7 @@ function menu_nodeapi(&$node, $op) {
if (user_access('administer menu')) {
switch ($op) {
- case 'form post':
+ case 'form':
$edit = $_POST['edit'];
$edit['nid'] = $node->nid;
return menu_node_form($edit);
@@ -153,12 +153,10 @@ function menu_reset() {
drupal_goto('admin/menu');
break;
default:
- $output = theme('confirm',
- t('Are you sure you want to reset all menu items to their default settings?'),
- 'admin/menu',
- t('Any custom additions or changes to the menu will be lost.'),
- t('Reset all'));
- return $output;
+ return confirm_form('menu_confirm_reset', array(),
+ t('Are you sure you want to reset all menu items to their default settings?'),
+ 'admin/menu', t('Any custom additions or changes to the menu will be lost.'),
+ t('Reset all'));
}
}
@@ -200,12 +198,10 @@ function menu_reset_item($mid) {
break;
default:
$title = db_result(db_query('SELECT title FROM {menu} WHERE mid = %d', $mid));
- $output = theme('confirm',
- t('Are you sure you want to reset the item %item to its default values?', array('%item' => theme('placeholder', $title))),
- 'admin/menu',
- t('Any customizations will be lost. This action cannot be undone.'),
- t('Reset'));
- return $output;
+ return confirm_form('menu_item_confirm_reset', array(),
+ t('Are you sure you want to reset the item %item to its default values?', array('%item' => theme('placeholder', $title))),
+ 'admin/menu', t('Any customizations will be lost. This action cannot be undone.'),
+ t('Reset'));
}
}
@@ -237,8 +233,7 @@ function menu_delete_item($mid) {
else {
$message = t('Are you sure you want to delete the custom menu item %item?', array('%item' => theme('placeholder', $menu->title)));
}
- $output = theme('confirm', $message, 'admin/menu', t('This action cannot be undone.'), t('Delete'));
- return $output;
+ return confirm_form('menu_confirm_delete', $form, $message, 'admin/menu', t('This action cannot be undone.'), t('Delete'));
}
}
@@ -303,16 +298,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 +317,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.'));
+ $expanded = $edit['type'] & MENU_EXPANDED ? 1 : 0;
+ $form['expanded'] = array(type => 'checkbox', title => t('Expanded'), default_value => $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', title => 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 +543,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, tree => 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;
}
diff --git a/modules/node.module b/modules/node.module
index 52e6261c9..3188e4ffa 100644
--- a/modules/node.module
+++ b/modules/node.module
@@ -639,15 +639,27 @@ function node_search($op = 'search', $keys = null) {
* Menu callback; presents general node configuration options.
*/
function node_configure() {
- if ($_POST) {
- system_settings_save();
- }
- $output .= form_select(t('Number of posts on main page'), 'default_nodes_main', variable_get('default_nodes_main', 10), drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)), t('The default maximum number of posts to display per page on overview pages such as the main page.'));
- $output .= form_select(t('Length of trimmed posts'), 'teaser_length', variable_get('teaser_length', 600), array(0 => t('Unlimited'), 200 => t('200 characters'), 400 => t('400 characters'), 600 => t('600 characters'), 800 => t('800 characters'), 1000 => t('1000 characters'), 1200 => t('1200 characters'), 1400 => t('1400 characters'), 1600 => t('1600 characters'), 1800 => t('1800 characters'), 2000 => t('2000 characters')), t("The maximum number of characters used in the trimmed version of a post. Drupal will use this setting to determine at which offset long posts should be trimmed. The trimmed version of a post is typically used as a teaser when displaying the post on the main page, in XML feeds, etc. To disable teasers, set to 'Unlimited'. Note that this setting will only affect new or updated content and will not affect existing teasers."));
- $output .= form_radios(t('Preview post'), 'node_preview', variable_get('node_preview', 0), array(t('Optional'), t('Required')), t('Must users preview posts before submitting?'));
+ $form['default_nodes_main'] = array(
+ type => 'select', title => t('Number of posts on main page'), default_value => variable_get('default_nodes_main', 10),
+ options => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
+ description => t('The default maximum number of posts to display per page on overview pages such as the main page.')
+ );
+
+ $form['teaser_length'] = array(
+ type => 'select', title => t('Length of trimmed posts'), default_value => variable_get('teaser_length', 600),
+ options => array(0 => t('Unlimited'), 200 => t('200 characters'), 400 => t('400 characters'), 600 => t('600 characters'),
+ 800 => t('800 characters'), 1000 => t('1000 characters'), 1200 => t('1200 characters'), 1400 => t('1400 characters'),
+ 1600 => t('1600 characters'), 1800 => t('1800 characters'), 2000 => t('2000 characters')),
+ description => t("The maximum number of characters used in the trimmed version of a post. Drupal will use this setting to determine at which offset long posts should be trimmed. The trimmed version of a post is typically used as a teaser when displaying the post on the main page, in XML feeds, etc. To disable teasers, set to 'Unlimited'. Note that this setting will only affect new or updated content and will not affect existing teasers.")
+ );
+
+ $form['node_preview'] = array(
+ type => 'radios', title => t('Preview post'), default_value => variable_get('node_preview', 0),
+ options => array(t('Optional'), t('Required')), description => t('Must users preview posts before submitting?')
+ );
- return system_settings_form($output);
+ return system_settings_form('node_configure', $form);
}
/**
@@ -761,13 +773,10 @@ function node_last_changed($nid) {
return ($node->changed);
}
-/**
- * Generate the content administration overview.
- */
-function node_admin_nodes() {
- /*
- ** Operations
- */
+/*
+** Node operations
+*/
+function node_operations() {
$operations = array(
'approve' => array(t('Approve the selected posts'), 'UPDATE {node} SET status = 1, moderate = 0 WHERE nid = %d'),
'promote' => array(t('Promote the selected posts'), 'UPDATE {node} SET status = 1, promote = 1 WHERE nid = %d'),
@@ -776,62 +785,13 @@ function node_admin_nodes() {
'unpublish' => array(t('Unpublish the selected posts'), 'UPDATE {node} SET status = 0 WHERE nid = %d'),
'delete' => array(t('Delete the selected posts'), '')
);
+ return $operations;
+}
- // Handle operations
- $op = $_POST['op'];
-
- $edit = $_POST['edit'];
- if (($op == t('Update') || $op == t('Delete all')) && isset($edit['operation']) && isset($edit['nodes'])) {
- $edit['nodes'] = array_diff($edit['nodes'], array(0));
- if (count($edit['nodes']) == 0) {
- form_set_error('', t('Please select some items to perform the update on.'));
- }
- else {
- if ($operations[$edit['operation']][1]) {
- // Flag changes
- $operation = $operations[$edit['operation']][1];
- foreach ($edit['nodes'] as $nid => $value) {
- if ($value) {
- db_query($operation, $nid);
- }
- }
- drupal_set_message(t('The update has been performed.'));
- }
- else if ($edit['operation'] == 'delete') {
- // Mass delete
- if ($edit['confirm']) {
- foreach ($edit['nodes'] as $nid => $value) {
- node_delete(array('nid' => $nid, 'confirm' => 1));
- }
- drupal_set_message(t('The items have been deleted.'));
- }
- else {
- $extra = '<ul>';
- foreach ($edit['nodes'] as $nid => $value) {
- if ($value) {
- $title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $nid));
- $extra .= '<li>'. form_hidden('nodes]['. $nid, 1) . check_plain($title) .'</li>';
- }
- }
- $extra .= '</ul>';
- $extra .= form_hidden('operation', 'delete');
-
- $output = theme('confirm',
- t('Are you sure you want to delete these items?'),
- 'admin/node',
- t('This action cannot be undone.'),
- t('Delete all'),
- t('Cancel'),
- $extra);
- return $output;
- }
- }
- }
- }
-
- /*
- ** Filters
- */
+/*
+** Filters
+*/
+function node_filters() {
// Regular filters
$filters = array(
'status' => array('title' => t('status'),
@@ -844,82 +804,26 @@ function node_admin_nodes() {
// Merge all vocabularies into one for retrieving $value below
if ($taxonomy = module_invoke('taxonomy', 'form_all')) {
$terms = array();
- foreach ($taxonomy as $key => $value) {
+ foreach ($taxonomy as $value) {
$terms = $terms + $value;
}
$filters['category'] = array('title' => t('category'), 'where' => 'tn.tid = %d',
'options' => $terms, 'join' => 'INNER JOIN {term_node} tn ON n.nid = tn.nid');
}
-
- // Initialize/reset filters
- if (!isset($_SESSION['node_overview_filter']) || !is_array($_SESSION['node_overview_filter']) || $op == t('Reset')) {
- $_SESSION['node_overview_filter'] = array();
- }
- $session = &$_SESSION['node_overview_filter'];
- $filter = $edit['filter'];
- if (($op == t('Filter') || $op == t('Refine')) && isset($filter)) {
- if (isset($filters[$filter]['options'][$edit[$filter]])) {
- $session[] = array($filter, $edit[$filter]);
- }
- }
- if ($op == t('Undo')) {
- array_pop($session);
- }
- if ($op != '') {
- drupal_goto('admin/node');
- }
-
- /*
- ** Form
- */
- $output .= '<div id="node-admin-filter">';
- // Existing filters
- $form = '<ul>';
- $i = 0;
- foreach ($session as $filter) {
- list($type, $value) = $filter;
- $params = array('%a' => '<strong>'. $filters[$type]['title'] .'</strong>', '%b' => '<strong>'. $filters[$type]['options'][$value] .'</strong>');
- $form .= '<li>'. ($i++ ? t('<em>and</em> where <strong>%a</strong> is <strong>%b</strong>', $params) : t('<strong>%a</strong> is <strong>%b</strong>', $params)) .'</li>';
- }
-
- // New filter form
if (isset($filters['category'])) {
$filters['category']['options'] = $taxonomy;
}
- $values = '';
- $options = array();
- foreach ($filters as $key => $value) {
- $options[$key] = $value['title'];
- $b .= form_select('', $key, 1, $filters[$key]['options']);
- }
- $buttons = '';
- if (count($options)) {
- $form .= '<li><dl class="multiselect">';
- $a = '';
- foreach ($options as $key => $value) {
- $a .= form_radio($value, 'filter', $key);
- }
- if (!$i) {
- $form .= t('<dd class="a">%a</dd> <dt>is</dt> <dd class="b">%b</dd>', array('%a' => $a, '%b' => $b));
- }
- else {
- $form .= t('<dt><em>and</em> where</dt> <dd class="a">%a</dd> <dt>is</dt> <dd class="b">%b</dd>', array('%a' => $a, '%b' => $b));
- }
- $form .= '</dl>';
- $buttons = form_submit(count($session) ? t('Refine') : t('Filter'));
- }
- if (count($session)) {
- $buttons .= form_submit(t('Undo')) . form_submit(t('Reset'));
- }
- $form .= '<div class="container-inline" id="node-admin-buttons">'. $buttons .'</div>';
- $form .= '</li></ul><br class="clear" />';
- $output .= form_group(t('Show only items where'), $form);
+ return $filters;
+}
+
+function node_build_filter_query() {
+ $filters = node_filters();
// Build query
$where = $args = array();
$join = '';
- foreach ($session as $filter) {
+ foreach ($_SESSION['node_overview_filter'] as $filter) {
list($key, $value) = $filter;
if ($key == 'status') {
// Note: no exploit hole as $value has already been checked
@@ -933,42 +837,230 @@ function node_admin_nodes() {
$join .= $filters[$key]['join'];
}
$where = count($where) ? 'WHERE '. implode(' AND ', $where) : '';
- $result = pager_query('SELECT n.*, u.name, u.uid FROM {node} n '. $join .' INNER JOIN {users} u ON n.uid = u.uid '. $where .' ORDER BY n.changed DESC', 50, 0, NULL, $args);
- // Make sure the update controls are disabled if we don't have any rows to select from.
- $disabled = !db_num_rows($result);
+ return array('where' => $where, 'join' => $join, 'args' => $args);
+}
- $options = array();
- foreach ($operations as $key => $value) {
- $options[$key] = $value[0];
+function node_filter_form() {
+ $session = &$_SESSION['node_overview_filter'];
+ $session = is_array($session) ? $session : array();
+ $filters = node_filters();
+
+ $i = 0;
+ $form['filters'] = array(type => 'fieldset', title => t('Show only items where'), theme => 'node_filters');
+ foreach ($session as $filter) {
+ list($type, $value) = $filter;
+ $string = ($i++ ? '<em>and</em> where <strong>%a</strong> is <strong>%b</strong>' : '<strong>%a</strong> is <strong>%b</strong>');
+ $form['filters']['current'][] = array(value => t($string, array('%a' => $filters[$type]['title'] , '%b' => $filters[$type]['options'][$value])));
}
- $form = form_select(NULL, 'operation', 'approve', $options, NULL, ($disabled ? 'disabled="disabled"' : ''));
- $form .= form_submit(t('Update'), 'op', ($disabled ? array('disabled' => 'disabled') : array()));
+ foreach ($filters as $key => $filter) {
+ $names[$key] = $filter['title'];
+ $form['filters']['status'][$key] = array(type => 'select', options => $filter['options']);
+ }
+
+ $form['filters']['filter'] = array(type => 'radios', options => $names, default_value => 'status');
+ $form['filters']['buttons']['submit'] = array(type => 'submit', value => (count($session) ? t('Refine') : t('Filter')));
+ if (count($session)) {
+ $form['filters']['buttons']['undo'] = array(type => 'submit', value => t('Undo'));
+ $form['filters']['buttons']['reset'] = array(type => 'submit', value => t('Reset'));
+ }
- $output .= form_group(t('Update options'), "<div class=\"container-inline\">$form</div>");
+ return drupal_get_form('node_filter_form', $form);
+}
+
+function theme_node_filter_form(&$form) {
+ $output .= '<div id="node-admin-filter">';
+ $output .= form_render($form['filters']);
$output .= '</div>';
+ $output .= form_render($form);
+ return $output;
+}
- // Overview table:
- $header = array(NULL, t('Title'), t('Type'), t('Author'), t('Status'), t('Operations'));
+function theme_node_filters(&$form) {
+ $output .= '<ul>';
+ if (sizeof($form['current'])) {
+ foreach (element_children($form['current']) as $key) {
+ $output .= '<li>' . form_render($form['current'][$key]) . '</li>';
+ }
+ }
+
+ $output .= '<li><dl class="multiselect">' . (sizeof($form['current']) ? '<dt><em>and</em> where</dt>' : '') . '<dd class="a">';
+ foreach(element_children($form['filter']) as $key) {
+ $output .= form_render($form['filter'][$key]);
+ }
+ $output .= '</dd>';
+
+ $output .= '<dt>is</dt>' . '<dd class="b">';
+
+ foreach(element_children($form['status']) as $key) {
+ $output .= form_render($form['status'][$key]);
+ }
+ $output .= '</dd>';
+
+
+ $output .= '</dl>';
+ $output .= '<div class="container-inline" id="node-admin-buttons">'. form_render($form['buttons']) .'</div>';
+ $output .= '</li></ul><br class="clear" />';
+
+ return $output;
+}
+
+
+function node_filter_form_execute() {
+ global $form_values;
+ $op = $_POST['op'];
+ $filters = node_filters();
+ switch ($op) {
+ case t('Filter'): case t('Refine'):
+ if (isset($form_values['filter'])) {
+ $filter = $form_values['filter'];
+ if (isset($filters[$filter]['options'][$form_values[$filter]])) {
+ $_SESSION['node_overview_filter'][] = array($filter, $form_values[$filter]);
+ }
+ }
+ break;
+ case t('Undo'):
+ array_pop($_SESSION['node_overview_filter']);
+ break;
+ case t('Reset'):
+ $_SESSION['node_overview_filter'] = array();
+ break;
+ case t('Update'):
+ return;
+ }
+ if ($op != '') {
+ drupal_goto('admin/node');
+ }
+}
+
+/**
+ * Generate the content administration overview.
+ */
+function node_admin_nodes_execute($form_id, $edit) {
+ $operations = node_operations();
+ if ($operations[$edit['operation']][1]) {
+ // Flag changes
+ $operation = $operations[$edit['operation']][1];
+ foreach ($edit['nodes'] as $nid => $value) {
+ if ($value) {
+ db_query($operation, $nid);
+ }
+ }
+ drupal_set_message(t('The update has been performed.'));
+ }
+ drupal_goto('admin/node');
+}
+
+function node_admin_nodes_validate($form_id, $edit) {
+ $edit['nodes'] = array_diff($edit['nodes'], array(0));
+ if (count($edit['nodes']) == 0) {
+ form_set_error('', t('Please select some items to perform the update on.'));
+ }
+}
+
+function node_admin_nodes() {
+ global $form_values;
+ $output = node_filter_form();
+
+ $filter = node_build_filter_query();
+
+ $result = pager_query('SELECT n.*, u.name, u.uid FROM {node} n '. $filter['join'] .' INNER JOIN {users} u ON n.uid = u.uid '. $filter['where'] .' ORDER BY n.changed DESC', 50, 0, NULL, $filter['args']);
+
+ $form['options'] = array(
+ type => 'fieldset', title => t('Update options'),
+ prefix => "<div class=\"container-inline\">" , suffix => "</div>"
+ );
+ $options = array();
+ foreach (node_operations() as $key => $value) {
+ $options[$key] = $value[0];
+ }
+ $form['options']['operation'] = array(type => 'select', options => $options, default_value => 'approve');
+ $form['options']['submit'] = array(type => 'submit', value => t('Update'));
$destination = drupal_get_destination();
while ($node = db_fetch_object($result)) {
- $rows[] = array(form_checkbox(NULL, 'nodes]['. $node->nid, 1, 0),
- l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)),
- node_get_name($node),
- theme('username', $node),
- ($node->status ? t('published') : t('not published')),
- l(t('edit'), 'node/'. $node->nid .'/edit', array(), $destination));
+ $nodes[$node->nid] = '';
+ $form['title'][$node->nid] = array(value => l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)));
+ $form['name'][$node->nid] = array(value => node_get_name($node));
+ $form['username'][$node->nid] = array(value => theme('username', $node));
+ $form['status'][$node->nid] = array(value => ($node->status ? t('published') : t('not published')));
+ $form['operations'][$node->nid] = array(value => l(t('edit'), 'node/'. $node->nid .'/edit', array(), $destination));
}
+ $form['nodes'] = array(type => 'checkboxes', options => $nodes);
+ $form['pager'] = array('value' => theme('pager', NULL, 50, 0));
- if (!$rows) {
+ $form[method] = 'post';
+ $form[action] = url('admin/node/action');
+
+ // Call the form first, to allow for the form_values array to be populated.
+ $output .= drupal_get_form('node_admin_nodes', $form);
+
+ // If you are attempting to delete nodes, display the multiple deletion form.
+ if ($form_values['operation'] == 'delete') {
+ $output = node_multiple_delete_form();
+ }
+
+ return $output;
+}
+
+
+function theme_node_admin_nodes($form) {
+ // Overview table:
+ $header = array(NULL, t('Title'), t('Type'), t('Author'), t('Status'), t('Operations'));
+
+ $output .= form_render($form['options']);
+ if (is_array($form['title'])) {
+ foreach (element_children($form['title']) as $key) {
+ $row = array();
+ $row[] = form_render($form['nodes'][$key]);
+ $row[] = form_render($form['title'][$key]);
+ $row[] = form_render($form['name'][$key]);
+ $row[] = form_render($form['username'][$key]);
+ $row[] = form_render($form['status'][$key]);
+ $row[] = form_render($form['operations'][$key]);
+ $rows[] = $row;
+ }
+
+ }
+ else {
$rows[] = array(array('data' => t('No posts available.'), 'colspan' => '6'));
}
$output .= theme('table', $header, $rows);
- $output .= theme('pager', NULL, 50, 0);
- return form($output, 'post', url('admin/node/action'));
+ if ($form['pager'][value]) {
+ $output .= form_render($form['pager']);
+ }
+
+ return $output;
+}
+
+function node_multiple_delete_form() {
+ global $form_values;
+ $form['nodes'] = array(prefix => '<ul>', suffix => '</ul>');
+ foreach ($form_values['nodes'] as $nid => $value) {
+ if ($value) {
+ $title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $nid));
+ $form['nodes'][$nid] = array(type => 'hidden', value => $nid, tree => TRUE, prefix => '<li>', suffix => check_plain($title) .'</li>');
+ }
+ }
+ $form['operation'] = array(type => 'hidden', value => 'delete');
+
+ return confirm_form('node_multiple_delete_form', $form,
+ t('Are you sure you want to delete these items?'),
+ 'admin/node', t('This action cannot be undone.'),
+ t('Delete all'), t('Cancel'));
+}
+
+
+function node_multiple_delete_form_execute($form_id, $edit) {
+ if ($edit['confirm']) {
+ foreach ($edit['nodes'] as $nid => $value) {
+ node_delete(array('nid' => $nid, 'confirm' => 1));
+ }
+ drupal_set_message(t('The items have been deleted.'));
+ }
+ drupal_goto('admin/node');
}
/**
@@ -977,23 +1069,21 @@ function node_admin_nodes() {
function node_types_configure($type = NULL) {
if (isset($type)) {
// Go to the listing page when we submit this form, system_settings_save() calls drupal_goto().
- if ($_POST['op']) {
- $_GET['q'] = 'admin/settings/content-types';
- $options = 'options_'. $type;
- if (empty($node->$options)) {
- $node->$options = array();
- }
- }
- system_settings_save();
-
$node = new stdClass();
$node->type = $type;
- $group = form_textarea(t('Explanation or submission guidelines'), $type .'_help', variable_get($type .'_help', ''), 60, 5, t('This text will be displayed at the top of the %type submission form. It is useful for helping or instructing your users.', array('%type' => node_get_name($type))));
- $group .= form_select(t('Minimum number of words'), 'minimum_'. $type .'_size', variable_get('minimum_'. $type .'_size', 0), drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)), t('The minimum number of words a %type must be to be considered valid. This can be useful to rule out submissions that do not meet the site\'s standards, such as short test posts.', array('%type' => node_get_name($type))));
- $output = form_group(t('Submission form'), $group);
- $output .= form_group(t('Workflow'), implode('', node_invoke_nodeapi($node, 'settings')));
-
- return system_settings_form($output);
+ $form['submission'] = array(type => 'fieldset', title =>t('Submission form') );
+ $form['submission'][$type . '_help'] = array(
+ type => 'textarea', title => t('Explanation or submission guidelines'), default_value => variable_get($type .'_help', ''), cols => 60, rows => 5,
+ description => t('This text will be displayed at the top of the %type submission form. It is useful for helping or instructing your users.', array('%type' => node_get_name($type)))
+ );
+ $form['submission']['minimum_'. $type .'_size'] = array(
+ type => 'select', title => t('Minimum number of words'), default_value => variable_get('minimum_'. $type .'_size', 0), options => drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)),
+ description => t('The minimum number of words a %type must be to be considered valid. This can be useful to rule out submissions that do not meet the site\'s standards, such as short test posts.', array('%type' => node_get_name($type)))
+ );
+ $form['workflow'] = array(type => 'fieldset', title =>t('Workflow'));
+ $form['workflow'] = array_merge($form['workflow'], node_invoke_nodeapi($node, 'settings'));
+
+ return system_settings_form($type . '_node_settings', $form);
}
else {
$header = array(t('Type'), t('Operations'));
@@ -1314,6 +1404,7 @@ function node_validate($node) {
return $node;
}
+
/**
* Validate the title of a node
*/
@@ -1329,117 +1420,108 @@ function node_validate_title($node, $message = NULL) {
/**
* Generate the node editing form.
*/
-function node_form($edit) {
- // Validate the node if we don't already know the errors.
- if (!$edit->validated) {
- $edit = node_validate($edit);
+function node_form($node) {
+ $op = $_POST['op'];
+
+ if (!$node->validated) {
+ $node = node_validate($node);
}
- // Prepend extra node form elements.
- $form = implode('', node_invoke_nodeapi($edit, 'form pre'));
+ // Set the id of the top-level form tag
+ $form[attributes]['id'] = 'node-form';
+
+ /**
+ * Basic node information.
+ * These elements set the value property, making them immutable.
+ */
+ $form['nid'] = array(type => 'hidden', value => $node->nid);
+ $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);
+
+ if ($op == t('Preview')) {
+ $form['node_preview'] = array(value => node_preview(array2object($_POST['edit'])), weight => -100);
+ }
// 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_get_base($node) .'_form';
$param = array();
if (function_exists($function)) {
- $form .= $function($edit, $param);
- }
-
- // Append extra node form elements.
- $form .= implode('', node_invoke_nodeapi($edit, 'form post'));
-
- $output .= '<div class="node-form">';
-
- // Add hidden 'op' variable, which specifies the default operation (Preview).
- $output .= '<input type="hidden" name="op" value="'. check_plain(t('Preview')) ."\" />\n";
-
- // Add the admin-specific parts.
- if (user_access('administer nodes')) {
- $output .= '<div class="admin">';
-
- $author = form_autocomplete(t('Authored by'), 'name', $edit->name, 30, 60, 'user/autocomplete');
- $author .= form_textfield(t('Authored on'), 'date', $edit->date, 30, 25, NULL, NULL, TRUE);
-
- $output .= '<div class="authored">';
- $output .= form_group_collapsible(t('Authoring information'), $author, TRUE);
- $output .= "</div>\n";
-
- $node_options = variable_get('node_options_'. $edit->type, array('status', 'promote'));
- $options .= form_checkbox(t('Published'), 'status', 1, isset($edit->status) ? $edit->status : in_array('status', $node_options));
- $options .= form_checkbox(t('In moderation queue'), 'moderate', 1, isset($edit->moderate) ? $edit->moderate : in_array('moderate', $node_options));
- $options .= form_checkbox(t('Promoted to front page'), 'promote', 1, isset($edit->promote) ? $edit->promote : in_array('promote', $node_options));
- $options .= form_checkbox(t('Sticky at top of lists'), 'sticky', 1, isset($edit->sticky) ? $edit->sticky : in_array('sticky', $node_options));
- $options .= form_checkbox(t('Create new revision'), 'revision', 1, isset($edit->revision) ? $edit->revision : in_array('revision', $node_options));
-
- $output .= '<div class="options">';
- $output .= form_group_collapsible(t('Publishing options'), $options, TRUE);
- $output .= "</div>\n";
-
- $extras .= implode('</div><div class="extra">', node_invoke_nodeapi($edit, 'form admin'));
- $output .= $extras ? '<div class="extra">'. $extras .'</div></div>' : '</div>';
+ $node_form = $function($node, $param);
+ $form = array_merge($form, $function($node, $param));
}
- // Open the enclosing div.
- $output .= '<div class="standard">';
+ /**
+ * Node author information
+ */
- // Add the node-type-specific fields.
- $output .= $form;
+ $form['author'] = array(type => 'fieldset', title => t('Authoring information'), collapsible => TRUE, collapsed => TRUE, weight => -18);
+ $form['author']['name'] = array(type => 'textfield', title => t('Authored by'), maxlength => 60, autocomplete_path => 'user/autocomplete', default_value => $node->name, weight => -1);
+ $form['author']['date'] = array(type => 'textfield', title =>t('Authored on'), maxlength => 25, required => TRUE, default_value => $node->date);
- // Add the hidden fields.
- if ($edit->nid) {
- $output .= form_hidden('nid', $edit->nid);
- }
+ $node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
- if (isset($edit->uid)) {
- // The use of isset() is mandatory in the context of user IDs, because
- // user ID 0 denotes the anonymous user.
- $output .= form_hidden('uid', $edit->uid);
- }
+ /**
+ * Node options
+ */
+ $form['options'] = array(type => 'fieldset', title => t('Publishing options'), collapsible => TRUE, collapsed => TRUE, weight => -18);
+ $form['options']['status'] = array(type => 'checkbox', title => t('Published'), default_value => in_array('status', $node_options));
+ $form['options']['moderate'] = array(type => 'checkbox', title => t('In moderation queue'), default_value => in_array('moderate', $node_options));
+ $form['options']['promote'] = array(type => 'checkbox', title => t('Promoted to front page'), default_value => in_array('promote', $node_options));
+ $form['options']['sticky'] = array(type => 'checkbox', title =>t('Sticky at top of lists'), default_value => in_array('sticky', $node_options));
+ $form['options']['revision'] = array(type => 'checkbox', title =>t('Create new revision'), default_value => in_array('revision', $node_options));
- if ($edit->created) {
- $output .= form_hidden('created', $edit->created);
- }
- if ($edit->changed) {
- $output .= form_hidden('changed', $edit->changed);
+ $nodeapi = node_invoke_nodeapi($node, 'form');
+ if (is_array($nodeapi)) {
+ foreach ($nodeapi as $key => $element) {
+ $nodeapi[$key][weight] = isset($nodeapi[$key][weight]) ? $nodeapi[$key][weight] : -18;
+ }
+ // Append extra node form elements.
+ $form = array_merge($form, $nodeapi);
}
-
- $output .= form_hidden('type', $edit->type);
+
+ $form['title'][weight] = isset($form['title'][weight]) ? $form['title'][weight] : -17;
+ $form['body'][weight] = isset($form['body'][weight]) ? $form['body'][weight] : -5;
// Add the buttons.
- $output .= form_submit(t('Preview'));
+ $form['preview'] = array(type => 'button', value => t('Preview'), weight => 19);
- if ($edit->type && (($_POST['op'] == t('Preview') && !form_get_errors()) || !variable_get('node_preview', 0))) {
- $output .= form_submit(t('Submit'));
+ if ($node->type) {
+ if (!form_get_errors()) {
+ if ($_POST['op'] == t('Preview')|| !variable_get('node_preview', 0)) {
+
+ }
+ }
}
-
- if ($edit->nid && node_access('delete', $edit)) {
- $output .= form_submit(t('Delete'));
+ $form['submit'] = array(type => 'submit', value => t('Submit'), weight => 20);
+ if ($node->nid && node_access('delete', $node)) {
+ $form['delete'] = array(type => 'button', value => t('Delete'), weight => 21);
}
+ return drupal_get_form($node->type . '_node_form', $form, 'node_form');
+}
- $output .= '</div></div>';
-
- $extra = node_invoke_nodeapi($edit, 'form param');
- foreach ($extra as $key => $value) {
- if (is_array($value)) {
- if (isset($param[$key])) {
- $param[$key] = array_merge($param[$key], $value);
- }
- else {
- $param[$key] = $value;
- }
- }
- else {
- $param[$key] = $value;
- }
+function theme_node_form($form) {
+ $output .= '<div class="node-form">';
+ if (isset($form['node_preview'])) {
+ $output .= form_render($form['node_preview']);
}
- $attributes = array('id' => 'node-form');
- if (is_array($param['options'])) {
- $attributes = array_merge($param['options'], $attributes);
- }
- return form($output, ($param['method'] ? $param['method'] : 'post'), $param['action'], $attributes);
+ $output .= ' <div class="admin">';
+ $output .= ' <div class="authored">';
+ $output .= form_render($form['author']);
+ $output .= ' </div>';
+ $output .= ' <div class="options">';
+ $output .= form_render($form['options']);
+ $output .= ' </div>';
+ $output .= '</div>';
+ $output .= ' <div class="standard">';
+ $output .= form_render($form);
+ $output .= ' </div>';
+ $output .= '</div>';
+ return $output;
}
/**
@@ -1488,26 +1570,12 @@ function node_add($type) {
}
/**
- * Present a node editing form.
- */
-function node_edit($id) {
- global $user;
-
- $node = node_load($id);
-
- drupal_set_title(check_plain($node->title));
-
- $output = node_form($node);
-
- return $output;
-}
-
-/**
- * Generate a node preview, including a form for further edits.
+ * Generate a node preview.
*/
function node_preview($node) {
- // Convert the array to an object:
- $node = array2object($node);
+ if (!$node->validated) {
+ $node = node_validate($node);
+ }
if (node_access('create', $node) || node_access('update', $node)) {
// Load the user's name when needed:
@@ -1542,9 +1610,7 @@ function node_preview($node) {
if (!form_get_errors()) {
$output = theme('node_preview', drupal_clone($node));
}
-
- $output .= node_form($node);
-
+ drupal_set_title(t('Preview'));
drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('create content'), 'node/add'), l(t('Submit %name', array('%name' => node_get_name($node))), 'node/add/'. $node->type)));
return $output;
@@ -1574,25 +1640,15 @@ function theme_node_preview($node) {
return $output;
}
-/**
- * Accepts a submission of new or changed node content.
- *
- * @param $node
- * A node array or node object.
- *
- * @return
- * If the node is successfully saved the node ID is returned. If the node
- * is not saved, 0 is returned.
- */
-function node_submit(&$node) {
+function node_form_execute($form_id, $edit) {
global $user;
// Fix up the node when required:
- $node = node_validate($node);
+ $node = node_validate($edit);
// If something went wrong, go back to the preview form.
if (form_get_errors()) {
- return false;
+ return node_form($edit);
}
// Prepare the node's body:
@@ -1614,10 +1670,14 @@ function node_submit(&$node) {
$msg = t('Your %post was created.', array ('%post' => node_get_name($node)));
}
}
-
- drupal_set_message($msg);
-
- return $node->nid;
+ if ($node->nid) {
+ if (node_access('view', $node)) {
+ drupal_goto('node/'. $node->nid);
+ }
+ else {
+ drupal_goto();
+ }
+ }
}
/**
@@ -1627,8 +1687,23 @@ function node_delete($edit) {
$node = node_load($edit['nid']);
if (node_access('delete', $node)) {
+ $form['nid'] = array(type => 'hidden', value => $node->nid);
+ $output = confirm_form('node_delete_confirm', $form,
+ t('Are you sure you want to delete %title?', array('%title' => theme('placeholder', $node->title))),
+ $_GET['destination'] ? $_GET['destination'] : 'node/'. $node->nid, t('This action cannot be undone.'),
+ t('Delete'), t('Cancel') );
+ }
+
+ return $output;
+}
- if ($edit['confirm']) {
+function node_delete_confirm_execute() {
+ global $form_values;
+ $node = node_load($form_values['nid']);
+
+ if (node_access('delete', $node)) {
+
+ if ($form_values['confirm']) {
db_query('DELETE FROM {node} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid);
@@ -1646,19 +1721,8 @@ function node_delete($edit) {
watchdog('content', t('%type: deleted %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))));
}
- else {
- $extra = form_hidden('nid', $node->nid);
- $output = theme('confirm',
- t('Are you sure you want to delete %title?', array('%title' => theme('placeholder', $node->title))),
- $_GET['destination'] ? $_GET['destination'] : 'node/'. $node->nid,
- t('This action cannot be undone.'),
- t('Delete'),
- t('Cancel'),
- $extra);
- }
}
-
- return $output;
+ drupal_goto('node');
}
/**
@@ -1695,8 +1759,9 @@ function node_page_default() {
* Menu callback; dispatches control to the appropriate operation handler.
*/
function node_page() {
- $op = $_POST['op'] ? $_POST['op'] : arg(1);
$edit = $_POST['edit'];
+
+ $op = arg(1);
if (is_numeric($op)) {
$op = (arg(2) && !is_numeric(arg(2))) ? arg(2) : 'view';
@@ -1738,12 +1803,21 @@ function node_page() {
case 'delete-revision':
node_revision_delete(arg(1), arg(3));
break;
- case 'edit':
+ case 'edit':
+ if ($_POST['op'] == t('Delete')) {
+ // Note: we redirect from node/uid/edit to node/uid/delete to make the tabs disappear.
+ if ($_REQUEST['destination']) {
+ $destination = drupal_get_destination();
+ unset($_REQUEST['destination']);
+ }
+ drupal_goto('node/'. arg(1) .'/delete', $destination);
+ }
+
if (is_numeric(arg(1))) {
$node = node_load(arg(1));
if ($node->nid) {
- drupal_set_title($node->title);
- return node_edit(arg(1));
+ drupal_set_title(check_plain($node->title));
+ return node_form($node);
}
else if (db_result(db_query('SELECT nid FROM {node} WHERE nid = %d', arg(1)))) {
drupal_access_denied();
@@ -1765,33 +1839,6 @@ function node_page() {
}
}
break;
- case t('Preview'):
- $edit = node_validate($edit);
- drupal_set_title(t('Preview'));
- return node_preview($edit);
- break;
- case t('Submit'):
- if ($nid = node_submit($edit)) {
- if (node_access('view', $edit)) {
- drupal_goto('node/'. $nid);
- }
- else {
- drupal_goto();
- }
- }
- else {
- drupal_set_title(t('Submit'));
- return node_preview($edit);
- }
- break;
- case t('Delete'):
- // Note: we redirect from node/uid/edit to node/uid/delete to make the tabs disappear.
- if ($_REQUEST['destination']) {
- $destination = drupal_get_destination();
- unset($_REQUEST['destination']);
- }
- drupal_goto('node/'. arg(1) .'/delete', $destination);
-
default:
drupal_set_title('');
return node_page_default();
@@ -1860,8 +1907,13 @@ function node_update_index() {
function node_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
case 'settings':
- // $node contains the type name in this operation
- return form_checkboxes(t('Default options'), 'node_options_'. $node->type, variable_get('node_options_'. $node->type, array('status', 'promote')), array('status' => t('Published'), 'moderate' => t('In moderation queue'), 'promote' => t('Promoted to front page'), 'sticky' => t('Sticky at top of lists'), 'revision' => t('Create new revision')), t('Users with the <em>administer nodes</em> permission will be able to override these options.'));
+ $form['node_options_'. $node->type] = array(
+ type => 'checkboxes', title => t('Default options'), default_value => variable_get('node_options_'. $node->type, array('status', 'promote')),
+ options => array('status' => t('Published'), 'moderate' => t('In moderation queue'), 'promote' => t('Promoted to front page'),
+ 'sticky' => t('Sticky at top of lists'), 'revision' => t('Create new revision')),
+ description => t('Users with the <em>administer nodes</em> permission will be able to override these options.')
+ );
+ return $form;
}
}
@@ -2045,7 +2097,7 @@ function node_access_view_all_nodes() {
}
}
$sql .= implode(',', $grants) .') AND grant_view = 1';
- $result = db_query($sql, $node->nid);
+ $result = db_query($sql);
$access = db_result($result);
}
diff --git a/modules/node/node.module b/modules/node/node.module
index 52e6261c9..3188e4ffa 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -639,15 +639,27 @@ function node_search($op = 'search', $keys = null) {
* Menu callback; presents general node configuration options.
*/
function node_configure() {
- if ($_POST) {
- system_settings_save();
- }
- $output .= form_select(t('Number of posts on main page'), 'default_nodes_main', variable_get('default_nodes_main', 10), drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)), t('The default maximum number of posts to display per page on overview pages such as the main page.'));
- $output .= form_select(t('Length of trimmed posts'), 'teaser_length', variable_get('teaser_length', 600), array(0 => t('Unlimited'), 200 => t('200 characters'), 400 => t('400 characters'), 600 => t('600 characters'), 800 => t('800 characters'), 1000 => t('1000 characters'), 1200 => t('1200 characters'), 1400 => t('1400 characters'), 1600 => t('1600 characters'), 1800 => t('1800 characters'), 2000 => t('2000 characters')), t("The maximum number of characters used in the trimmed version of a post. Drupal will use this setting to determine at which offset long posts should be trimmed. The trimmed version of a post is typically used as a teaser when displaying the post on the main page, in XML feeds, etc. To disable teasers, set to 'Unlimited'. Note that this setting will only affect new or updated content and will not affect existing teasers."));
- $output .= form_radios(t('Preview post'), 'node_preview', variable_get('node_preview', 0), array(t('Optional'), t('Required')), t('Must users preview posts before submitting?'));
+ $form['default_nodes_main'] = array(
+ type => 'select', title => t('Number of posts on main page'), default_value => variable_get('default_nodes_main', 10),
+ options => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
+ description => t('The default maximum number of posts to display per page on overview pages such as the main page.')
+ );
+
+ $form['teaser_length'] = array(
+ type => 'select', title => t('Length of trimmed posts'), default_value => variable_get('teaser_length', 600),
+ options => array(0 => t('Unlimited'), 200 => t('200 characters'), 400 => t('400 characters'), 600 => t('600 characters'),
+ 800 => t('800 characters'), 1000 => t('1000 characters'), 1200 => t('1200 characters'), 1400 => t('1400 characters'),
+ 1600 => t('1600 characters'), 1800 => t('1800 characters'), 2000 => t('2000 characters')),
+ description => t("The maximum number of characters used in the trimmed version of a post. Drupal will use this setting to determine at which offset long posts should be trimmed. The trimmed version of a post is typically used as a teaser when displaying the post on the main page, in XML feeds, etc. To disable teasers, set to 'Unlimited'. Note that this setting will only affect new or updated content and will not affect existing teasers.")
+ );
+
+ $form['node_preview'] = array(
+ type => 'radios', title => t('Preview post'), default_value => variable_get('node_preview', 0),
+ options => array(t('Optional'), t('Required')), description => t('Must users preview posts before submitting?')
+ );
- return system_settings_form($output);
+ return system_settings_form('node_configure', $form);
}
/**
@@ -761,13 +773,10 @@ function node_last_changed($nid) {
return ($node->changed);
}
-/**
- * Generate the content administration overview.
- */
-function node_admin_nodes() {
- /*
- ** Operations
- */
+/*
+** Node operations
+*/
+function node_operations() {
$operations = array(
'approve' => array(t('Approve the selected posts'), 'UPDATE {node} SET status = 1, moderate = 0 WHERE nid = %d'),
'promote' => array(t('Promote the selected posts'), 'UPDATE {node} SET status = 1, promote = 1 WHERE nid = %d'),
@@ -776,62 +785,13 @@ function node_admin_nodes() {
'unpublish' => array(t('Unpublish the selected posts'), 'UPDATE {node} SET status = 0 WHERE nid = %d'),
'delete' => array(t('Delete the selected posts'), '')
);
+ return $operations;
+}
- // Handle operations
- $op = $_POST['op'];
-
- $edit = $_POST['edit'];
- if (($op == t('Update') || $op == t('Delete all')) && isset($edit['operation']) && isset($edit['nodes'])) {
- $edit['nodes'] = array_diff($edit['nodes'], array(0));
- if (count($edit['nodes']) == 0) {
- form_set_error('', t('Please select some items to perform the update on.'));
- }
- else {
- if ($operations[$edit['operation']][1]) {
- // Flag changes
- $operation = $operations[$edit['operation']][1];
- foreach ($edit['nodes'] as $nid => $value) {
- if ($value) {
- db_query($operation, $nid);
- }
- }
- drupal_set_message(t('The update has been performed.'));
- }
- else if ($edit['operation'] == 'delete') {
- // Mass delete
- if ($edit['confirm']) {
- foreach ($edit['nodes'] as $nid => $value) {
- node_delete(array('nid' => $nid, 'confirm' => 1));
- }
- drupal_set_message(t('The items have been deleted.'));
- }
- else {
- $extra = '<ul>';
- foreach ($edit['nodes'] as $nid => $value) {
- if ($value) {
- $title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $nid));
- $extra .= '<li>'. form_hidden('nodes]['. $nid, 1) . check_plain($title) .'</li>';
- }
- }
- $extra .= '</ul>';
- $extra .= form_hidden('operation', 'delete');
-
- $output = theme('confirm',
- t('Are you sure you want to delete these items?'),
- 'admin/node',
- t('This action cannot be undone.'),
- t('Delete all'),
- t('Cancel'),
- $extra);
- return $output;
- }
- }
- }
- }
-
- /*
- ** Filters
- */
+/*
+** Filters
+*/
+function node_filters() {
// Regular filters
$filters = array(
'status' => array('title' => t('status'),
@@ -844,82 +804,26 @@ function node_admin_nodes() {
// Merge all vocabularies into one for retrieving $value below
if ($taxonomy = module_invoke('taxonomy', 'form_all')) {
$terms = array();
- foreach ($taxonomy as $key => $value) {
+ foreach ($taxonomy as $value) {
$terms = $terms + $value;
}
$filters['category'] = array('title' => t('category'), 'where' => 'tn.tid = %d',
'options' => $terms, 'join' => 'INNER JOIN {term_node} tn ON n.nid = tn.nid');
}
-
- // Initialize/reset filters
- if (!isset($_SESSION['node_overview_filter']) || !is_array($_SESSION['node_overview_filter']) || $op == t('Reset')) {
- $_SESSION['node_overview_filter'] = array();
- }
- $session = &$_SESSION['node_overview_filter'];
- $filter = $edit['filter'];
- if (($op == t('Filter') || $op == t('Refine')) && isset($filter)) {
- if (isset($filters[$filter]['options'][$edit[$filter]])) {
- $session[] = array($filter, $edit[$filter]);
- }
- }
- if ($op == t('Undo')) {
- array_pop($session);
- }
- if ($op != '') {
- drupal_goto('admin/node');
- }
-
- /*
- ** Form
- */
- $output .= '<div id="node-admin-filter">';
- // Existing filters
- $form = '<ul>';
- $i = 0;
- foreach ($session as $filter) {
- list($type, $value) = $filter;
- $params = array('%a' => '<strong>'. $filters[$type]['title'] .'</strong>', '%b' => '<strong>'. $filters[$type]['options'][$value] .'</strong>');
- $form .= '<li>'. ($i++ ? t('<em>and</em> where <strong>%a</strong> is <strong>%b</strong>', $params) : t('<strong>%a</strong> is <strong>%b</strong>', $params)) .'</li>';
- }
-
- // New filter form
if (isset($filters['category'])) {
$filters['category']['options'] = $taxonomy;
}
- $values = '';
- $options = array();
- foreach ($filters as $key => $value) {
- $options[$key] = $value['title'];
- $b .= form_select('', $key, 1, $filters[$key]['options']);
- }
- $buttons = '';
- if (count($options)) {
- $form .= '<li><dl class="multiselect">';
- $a = '';
- foreach ($options as $key => $value) {
- $a .= form_radio($value, 'filter', $key);
- }
- if (!$i) {
- $form .= t('<dd class="a">%a</dd> <dt>is</dt> <dd class="b">%b</dd>', array('%a' => $a, '%b' => $b));
- }
- else {
- $form .= t('<dt><em>and</em> where</dt> <dd class="a">%a</dd> <dt>is</dt> <dd class="b">%b</dd>', array('%a' => $a, '%b' => $b));
- }
- $form .= '</dl>';
- $buttons = form_submit(count($session) ? t('Refine') : t('Filter'));
- }
- if (count($session)) {
- $buttons .= form_submit(t('Undo')) . form_submit(t('Reset'));
- }
- $form .= '<div class="container-inline" id="node-admin-buttons">'. $buttons .'</div>';
- $form .= '</li></ul><br class="clear" />';
- $output .= form_group(t('Show only items where'), $form);
+ return $filters;
+}
+
+function node_build_filter_query() {
+ $filters = node_filters();
// Build query
$where = $args = array();
$join = '';
- foreach ($session as $filter) {
+ foreach ($_SESSION['node_overview_filter'] as $filter) {
list($key, $value) = $filter;
if ($key == 'status') {
// Note: no exploit hole as $value has already been checked
@@ -933,42 +837,230 @@ function node_admin_nodes() {
$join .= $filters[$key]['join'];
}
$where = count($where) ? 'WHERE '. implode(' AND ', $where) : '';
- $result = pager_query('SELECT n.*, u.name, u.uid FROM {node} n '. $join .' INNER JOIN {users} u ON n.uid = u.uid '. $where .' ORDER BY n.changed DESC', 50, 0, NULL, $args);
- // Make sure the update controls are disabled if we don't have any rows to select from.
- $disabled = !db_num_rows($result);
+ return array('where' => $where, 'join' => $join, 'args' => $args);
+}
- $options = array();
- foreach ($operations as $key => $value) {
- $options[$key] = $value[0];
+function node_filter_form() {
+ $session = &$_SESSION['node_overview_filter'];
+ $session = is_array($session) ? $session : array();
+ $filters = node_filters();
+
+ $i = 0;
+ $form['filters'] = array(type => 'fieldset', title => t('Show only items where'), theme => 'node_filters');
+ foreach ($session as $filter) {
+ list($type, $value) = $filter;
+ $string = ($i++ ? '<em>and</em> where <strong>%a</strong> is <strong>%b</strong>' : '<strong>%a</strong> is <strong>%b</strong>');
+ $form['filters']['current'][] = array(value => t($string, array('%a' => $filters[$type]['title'] , '%b' => $filters[$type]['options'][$value])));
}
- $form = form_select(NULL, 'operation', 'approve', $options, NULL, ($disabled ? 'disabled="disabled"' : ''));
- $form .= form_submit(t('Update'), 'op', ($disabled ? array('disabled' => 'disabled') : array()));
+ foreach ($filters as $key => $filter) {
+ $names[$key] = $filter['title'];
+ $form['filters']['status'][$key] = array(type => 'select', options => $filter['options']);
+ }
+
+ $form['filters']['filter'] = array(type => 'radios', options => $names, default_value => 'status');
+ $form['filters']['buttons']['submit'] = array(type => 'submit', value => (count($session) ? t('Refine') : t('Filter')));
+ if (count($session)) {
+ $form['filters']['buttons']['undo'] = array(type => 'submit', value => t('Undo'));
+ $form['filters']['buttons']['reset'] = array(type => 'submit', value => t('Reset'));
+ }
- $output .= form_group(t('Update options'), "<div class=\"container-inline\">$form</div>");
+ return drupal_get_form('node_filter_form', $form);
+}
+
+function theme_node_filter_form(&$form) {
+ $output .= '<div id="node-admin-filter">';
+ $output .= form_render($form['filters']);
$output .= '</div>';
+ $output .= form_render($form);
+ return $output;
+}
- // Overview table:
- $header = array(NULL, t('Title'), t('Type'), t('Author'), t('Status'), t('Operations'));
+function theme_node_filters(&$form) {
+ $output .= '<ul>';
+ if (sizeof($form['current'])) {
+ foreach (element_children($form['current']) as $key) {
+ $output .= '<li>' . form_render($form['current'][$key]) . '</li>';
+ }
+ }
+
+ $output .= '<li><dl class="multiselect">' . (sizeof($form['current']) ? '<dt><em>and</em> where</dt>' : '') . '<dd class="a">';
+ foreach(element_children($form['filter']) as $key) {
+ $output .= form_render($form['filter'][$key]);
+ }
+ $output .= '</dd>';
+
+ $output .= '<dt>is</dt>' . '<dd class="b">';
+
+ foreach(element_children($form['status']) as $key) {
+ $output .= form_render($form['status'][$key]);
+ }
+ $output .= '</dd>';
+
+
+ $output .= '</dl>';
+ $output .= '<div class="container-inline" id="node-admin-buttons">'. form_render($form['buttons']) .'</div>';
+ $output .= '</li></ul><br class="clear" />';
+
+ return $output;
+}
+
+
+function node_filter_form_execute() {
+ global $form_values;
+ $op = $_POST['op'];
+ $filters = node_filters();
+ switch ($op) {
+ case t('Filter'): case t('Refine'):
+ if (isset($form_values['filter'])) {
+ $filter = $form_values['filter'];
+ if (isset($filters[$filter]['options'][$form_values[$filter]])) {
+ $_SESSION['node_overview_filter'][] = array($filter, $form_values[$filter]);
+ }
+ }
+ break;
+ case t('Undo'):
+ array_pop($_SESSION['node_overview_filter']);
+ break;
+ case t('Reset'):
+ $_SESSION['node_overview_filter'] = array();
+ break;
+ case t('Update'):
+ return;
+ }
+ if ($op != '') {
+ drupal_goto('admin/node');
+ }
+}
+
+/**
+ * Generate the content administration overview.
+ */
+function node_admin_nodes_execute($form_id, $edit) {
+ $operations = node_operations();
+ if ($operations[$edit['operation']][1]) {
+ // Flag changes
+ $operation = $operations[$edit['operation']][1];
+ foreach ($edit['nodes'] as $nid => $value) {
+ if ($value) {
+ db_query($operation, $nid);
+ }
+ }
+ drupal_set_message(t('The update has been performed.'));
+ }
+ drupal_goto('admin/node');
+}
+
+function node_admin_nodes_validate($form_id, $edit) {
+ $edit['nodes'] = array_diff($edit['nodes'], array(0));
+ if (count($edit['nodes']) == 0) {
+ form_set_error('', t('Please select some items to perform the update on.'));
+ }
+}
+
+function node_admin_nodes() {
+ global $form_values;
+ $output = node_filter_form();
+
+ $filter = node_build_filter_query();
+
+ $result = pager_query('SELECT n.*, u.name, u.uid FROM {node} n '. $filter['join'] .' INNER JOIN {users} u ON n.uid = u.uid '. $filter['where'] .' ORDER BY n.changed DESC', 50, 0, NULL, $filter['args']);
+
+ $form['options'] = array(
+ type => 'fieldset', title => t('Update options'),
+ prefix => "<div class=\"container-inline\">" , suffix => "</div>"
+ );
+ $options = array();
+ foreach (node_operations() as $key => $value) {
+ $options[$key] = $value[0];
+ }
+ $form['options']['operation'] = array(type => 'select', options => $options, default_value => 'approve');
+ $form['options']['submit'] = array(type => 'submit', value => t('Update'));
$destination = drupal_get_destination();
while ($node = db_fetch_object($result)) {
- $rows[] = array(form_checkbox(NULL, 'nodes]['. $node->nid, 1, 0),
- l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)),
- node_get_name($node),
- theme('username', $node),
- ($node->status ? t('published') : t('not published')),
- l(t('edit'), 'node/'. $node->nid .'/edit', array(), $destination));
+ $nodes[$node->nid] = '';
+ $form['title'][$node->nid] = array(value => l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)));
+ $form['name'][$node->nid] = array(value => node_get_name($node));
+ $form['username'][$node->nid] = array(value => theme('username', $node));
+ $form['status'][$node->nid] = array(value => ($node->status ? t('published') : t('not published')));
+ $form['operations'][$node->nid] = array(value => l(t('edit'), 'node/'. $node->nid .'/edit', array(), $destination));
}
+ $form['nodes'] = array(type => 'checkboxes', options => $nodes);
+ $form['pager'] = array('value' => theme('pager', NULL, 50, 0));
- if (!$rows) {
+ $form[method] = 'post';
+ $form[action] = url('admin/node/action');
+
+ // Call the form first, to allow for the form_values array to be populated.
+ $output .= drupal_get_form('node_admin_nodes', $form);
+
+ // If you are attempting to delete nodes, display the multiple deletion form.
+ if ($form_values['operation'] == 'delete') {
+ $output = node_multiple_delete_form();
+ }
+
+ return $output;
+}
+
+
+function theme_node_admin_nodes($form) {
+ // Overview table:
+ $header = array(NULL, t('Title'), t('Type'), t('Author'), t('Status'), t('Operations'));
+
+ $output .= form_render($form['options']);
+ if (is_array($form['title'])) {
+ foreach (element_children($form['title']) as $key) {
+ $row = array();
+ $row[] = form_render($form['nodes'][$key]);
+ $row[] = form_render($form['title'][$key]);
+ $row[] = form_render($form['name'][$key]);
+ $row[] = form_render($form['username'][$key]);
+ $row[] = form_render($form['status'][$key]);
+ $row[] = form_render($form['operations'][$key]);
+ $rows[] = $row;
+ }
+
+ }
+ else {
$rows[] = array(array('data' => t('No posts available.'), 'colspan' => '6'));
}
$output .= theme('table', $header, $rows);
- $output .= theme('pager', NULL, 50, 0);
- return form($output, 'post', url('admin/node/action'));
+ if ($form['pager'][value]) {
+ $output .= form_render($form['pager']);
+ }
+
+ return $output;
+}
+
+function node_multiple_delete_form() {
+ global $form_values;
+ $form['nodes'] = array(prefix => '<ul>', suffix => '</ul>');
+ foreach ($form_values['nodes'] as $nid => $value) {
+ if ($value) {
+ $title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $nid));
+ $form['nodes'][$nid] = array(type => 'hidden', value => $nid, tree => TRUE, prefix => '<li>', suffix => check_plain($title) .'</li>');
+ }
+ }
+ $form['operation'] = array(type => 'hidden', value => 'delete');
+
+ return confirm_form('node_multiple_delete_form', $form,
+ t('Are you sure you want to delete these items?'),
+ 'admin/node', t('This action cannot be undone.'),
+ t('Delete all'), t('Cancel'));
+}
+
+
+function node_multiple_delete_form_execute($form_id, $edit) {
+ if ($edit['confirm']) {
+ foreach ($edit['nodes'] as $nid => $value) {
+ node_delete(array('nid' => $nid, 'confirm' => 1));
+ }
+ drupal_set_message(t('The items have been deleted.'));
+ }
+ drupal_goto('admin/node');
}
/**
@@ -977,23 +1069,21 @@ function node_admin_nodes() {
function node_types_configure($type = NULL) {
if (isset($type)) {
// Go to the listing page when we submit this form, system_settings_save() calls drupal_goto().
- if ($_POST['op']) {
- $_GET['q'] = 'admin/settings/content-types';
- $options = 'options_'. $type;
- if (empty($node->$options)) {
- $node->$options = array();
- }
- }
- system_settings_save();
-
$node = new stdClass();
$node->type = $type;
- $group = form_textarea(t('Explanation or submission guidelines'), $type .'_help', variable_get($type .'_help', ''), 60, 5, t('This text will be displayed at the top of the %type submission form. It is useful for helping or instructing your users.', array('%type' => node_get_name($type))));
- $group .= form_select(t('Minimum number of words'), 'minimum_'. $type .'_size', variable_get('minimum_'. $type .'_size', 0), drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)), t('The minimum number of words a %type must be to be considered valid. This can be useful to rule out submissions that do not meet the site\'s standards, such as short test posts.', array('%type' => node_get_name($type))));
- $output = form_group(t('Submission form'), $group);
- $output .= form_group(t('Workflow'), implode('', node_invoke_nodeapi($node, 'settings')));
-
- return system_settings_form($output);
+ $form['submission'] = array(type => 'fieldset', title =>t('Submission form') );
+ $form['submission'][$type . '_help'] = array(
+ type => 'textarea', title => t('Explanation or submission guidelines'), default_value => variable_get($type .'_help', ''), cols => 60, rows => 5,
+ description => t('This text will be displayed at the top of the %type submission form. It is useful for helping or instructing your users.', array('%type' => node_get_name($type)))
+ );
+ $form['submission']['minimum_'. $type .'_size'] = array(
+ type => 'select', title => t('Minimum number of words'), default_value => variable_get('minimum_'. $type .'_size', 0), options => drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)),
+ description => t('The minimum number of words a %type must be to be considered valid. This can be useful to rule out submissions that do not meet the site\'s standards, such as short test posts.', array('%type' => node_get_name($type)))
+ );
+ $form['workflow'] = array(type => 'fieldset', title =>t('Workflow'));
+ $form['workflow'] = array_merge($form['workflow'], node_invoke_nodeapi($node, 'settings'));
+
+ return system_settings_form($type . '_node_settings', $form);
}
else {
$header = array(t('Type'), t('Operations'));
@@ -1314,6 +1404,7 @@ function node_validate($node) {
return $node;
}
+
/**
* Validate the title of a node
*/
@@ -1329,117 +1420,108 @@ function node_validate_title($node, $message = NULL) {
/**
* Generate the node editing form.
*/
-function node_form($edit) {
- // Validate the node if we don't already know the errors.
- if (!$edit->validated) {
- $edit = node_validate($edit);
+function node_form($node) {
+ $op = $_POST['op'];
+
+ if (!$node->validated) {
+ $node = node_validate($node);
}
- // Prepend extra node form elements.
- $form = implode('', node_invoke_nodeapi($edit, 'form pre'));
+ // Set the id of the top-level form tag
+ $form[attributes]['id'] = 'node-form';
+
+ /**
+ * Basic node information.
+ * These elements set the value property, making them immutable.
+ */
+ $form['nid'] = array(type => 'hidden', value => $node->nid);
+ $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);
+
+ if ($op == t('Preview')) {
+ $form['node_preview'] = array(value => node_preview(array2object($_POST['edit'])), weight => -100);
+ }
// 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_get_base($node) .'_form';
$param = array();
if (function_exists($function)) {
- $form .= $function($edit, $param);
- }
-
- // Append extra node form elements.
- $form .= implode('', node_invoke_nodeapi($edit, 'form post'));
-
- $output .= '<div class="node-form">';
-
- // Add hidden 'op' variable, which specifies the default operation (Preview).
- $output .= '<input type="hidden" name="op" value="'. check_plain(t('Preview')) ."\" />\n";
-
- // Add the admin-specific parts.
- if (user_access('administer nodes')) {
- $output .= '<div class="admin">';
-
- $author = form_autocomplete(t('Authored by'), 'name', $edit->name, 30, 60, 'user/autocomplete');
- $author .= form_textfield(t('Authored on'), 'date', $edit->date, 30, 25, NULL, NULL, TRUE);
-
- $output .= '<div class="authored">';
- $output .= form_group_collapsible(t('Authoring information'), $author, TRUE);
- $output .= "</div>\n";
-
- $node_options = variable_get('node_options_'. $edit->type, array('status', 'promote'));
- $options .= form_checkbox(t('Published'), 'status', 1, isset($edit->status) ? $edit->status : in_array('status', $node_options));
- $options .= form_checkbox(t('In moderation queue'), 'moderate', 1, isset($edit->moderate) ? $edit->moderate : in_array('moderate', $node_options));
- $options .= form_checkbox(t('Promoted to front page'), 'promote', 1, isset($edit->promote) ? $edit->promote : in_array('promote', $node_options));
- $options .= form_checkbox(t('Sticky at top of lists'), 'sticky', 1, isset($edit->sticky) ? $edit->sticky : in_array('sticky', $node_options));
- $options .= form_checkbox(t('Create new revision'), 'revision', 1, isset($edit->revision) ? $edit->revision : in_array('revision', $node_options));
-
- $output .= '<div class="options">';
- $output .= form_group_collapsible(t('Publishing options'), $options, TRUE);
- $output .= "</div>\n";
-
- $extras .= implode('</div><div class="extra">', node_invoke_nodeapi($edit, 'form admin'));
- $output .= $extras ? '<div class="extra">'. $extras .'</div></div>' : '</div>';
+ $node_form = $function($node, $param);
+ $form = array_merge($form, $function($node, $param));
}
- // Open the enclosing div.
- $output .= '<div class="standard">';
+ /**
+ * Node author information
+ */
- // Add the node-type-specific fields.
- $output .= $form;
+ $form['author'] = array(type => 'fieldset', title => t('Authoring information'), collapsible => TRUE, collapsed => TRUE, weight => -18);
+ $form['author']['name'] = array(type => 'textfield', title => t('Authored by'), maxlength => 60, autocomplete_path => 'user/autocomplete', default_value => $node->name, weight => -1);
+ $form['author']['date'] = array(type => 'textfield', title =>t('Authored on'), maxlength => 25, required => TRUE, default_value => $node->date);
- // Add the hidden fields.
- if ($edit->nid) {
- $output .= form_hidden('nid', $edit->nid);
- }
+ $node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
- if (isset($edit->uid)) {
- // The use of isset() is mandatory in the context of user IDs, because
- // user ID 0 denotes the anonymous user.
- $output .= form_hidden('uid', $edit->uid);
- }
+ /**
+ * Node options
+ */
+ $form['options'] = array(type => 'fieldset', title => t('Publishing options'), collapsible => TRUE, collapsed => TRUE, weight => -18);
+ $form['options']['status'] = array(type => 'checkbox', title => t('Published'), default_value => in_array('status', $node_options));
+ $form['options']['moderate'] = array(type => 'checkbox', title => t('In moderation queue'), default_value => in_array('moderate', $node_options));
+ $form['options']['promote'] = array(type => 'checkbox', title => t('Promoted to front page'), default_value => in_array('promote', $node_options));
+ $form['options']['sticky'] = array(type => 'checkbox', title =>t('Sticky at top of lists'), default_value => in_array('sticky', $node_options));
+ $form['options']['revision'] = array(type => 'checkbox', title =>t('Create new revision'), default_value => in_array('revision', $node_options));
- if ($edit->created) {
- $output .= form_hidden('created', $edit->created);
- }
- if ($edit->changed) {
- $output .= form_hidden('changed', $edit->changed);
+ $nodeapi = node_invoke_nodeapi($node, 'form');
+ if (is_array($nodeapi)) {
+ foreach ($nodeapi as $key => $element) {
+ $nodeapi[$key][weight] = isset($nodeapi[$key][weight]) ? $nodeapi[$key][weight] : -18;
+ }
+ // Append extra node form elements.
+ $form = array_merge($form, $nodeapi);
}
-
- $output .= form_hidden('type', $edit->type);
+
+ $form['title'][weight] = isset($form['title'][weight]) ? $form['title'][weight] : -17;
+ $form['body'][weight] = isset($form['body'][weight]) ? $form['body'][weight] : -5;
// Add the buttons.
- $output .= form_submit(t('Preview'));
+ $form['preview'] = array(type => 'button', value => t('Preview'), weight => 19);
- if ($edit->type && (($_POST['op'] == t('Preview') && !form_get_errors()) || !variable_get('node_preview', 0))) {
- $output .= form_submit(t('Submit'));
+ if ($node->type) {
+ if (!form_get_errors()) {
+ if ($_POST['op'] == t('Preview')|| !variable_get('node_preview', 0)) {
+
+ }
+ }
}
-
- if ($edit->nid && node_access('delete', $edit)) {
- $output .= form_submit(t('Delete'));
+ $form['submit'] = array(type => 'submit', value => t('Submit'), weight => 20);
+ if ($node->nid && node_access('delete', $node)) {
+ $form['delete'] = array(type => 'button', value => t('Delete'), weight => 21);
}
+ return drupal_get_form($node->type . '_node_form', $form, 'node_form');
+}
- $output .= '</div></div>';
-
- $extra = node_invoke_nodeapi($edit, 'form param');
- foreach ($extra as $key => $value) {
- if (is_array($value)) {
- if (isset($param[$key])) {
- $param[$key] = array_merge($param[$key], $value);
- }
- else {
- $param[$key] = $value;
- }
- }
- else {
- $param[$key] = $value;
- }
+function theme_node_form($form) {
+ $output .= '<div class="node-form">';
+ if (isset($form['node_preview'])) {
+ $output .= form_render($form['node_preview']);
}
- $attributes = array('id' => 'node-form');
- if (is_array($param['options'])) {
- $attributes = array_merge($param['options'], $attributes);
- }
- return form($output, ($param['method'] ? $param['method'] : 'post'), $param['action'], $attributes);
+ $output .= ' <div class="admin">';
+ $output .= ' <div class="authored">';
+ $output .= form_render($form['author']);
+ $output .= ' </div>';
+ $output .= ' <div class="options">';
+ $output .= form_render($form['options']);
+ $output .= ' </div>';
+ $output .= '</div>';
+ $output .= ' <div class="standard">';
+ $output .= form_render($form);
+ $output .= ' </div>';
+ $output .= '</div>';
+ return $output;
}
/**
@@ -1488,26 +1570,12 @@ function node_add($type) {
}
/**
- * Present a node editing form.
- */
-function node_edit($id) {
- global $user;
-
- $node = node_load($id);
-
- drupal_set_title(check_plain($node->title));
-
- $output = node_form($node);
-
- return $output;
-}
-
-/**
- * Generate a node preview, including a form for further edits.
+ * Generate a node preview.
*/
function node_preview($node) {
- // Convert the array to an object:
- $node = array2object($node);
+ if (!$node->validated) {
+ $node = node_validate($node);
+ }
if (node_access('create', $node) || node_access('update', $node)) {
// Load the user's name when needed:
@@ -1542,9 +1610,7 @@ function node_preview($node) {
if (!form_get_errors()) {
$output = theme('node_preview', drupal_clone($node));
}
-
- $output .= node_form($node);
-
+ drupal_set_title(t('Preview'));
drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('create content'), 'node/add'), l(t('Submit %name', array('%name' => node_get_name($node))), 'node/add/'. $node->type)));
return $output;
@@ -1574,25 +1640,15 @@ function theme_node_preview($node) {
return $output;
}
-/**
- * Accepts a submission of new or changed node content.
- *
- * @param $node
- * A node array or node object.
- *
- * @return
- * If the node is successfully saved the node ID is returned. If the node
- * is not saved, 0 is returned.
- */
-function node_submit(&$node) {
+function node_form_execute($form_id, $edit) {
global $user;
// Fix up the node when required:
- $node = node_validate($node);
+ $node = node_validate($edit);
// If something went wrong, go back to the preview form.
if (form_get_errors()) {
- return false;
+ return node_form($edit);
}
// Prepare the node's body:
@@ -1614,10 +1670,14 @@ function node_submit(&$node) {
$msg = t('Your %post was created.', array ('%post' => node_get_name($node)));
}
}
-
- drupal_set_message($msg);
-
- return $node->nid;
+ if ($node->nid) {
+ if (node_access('view', $node)) {
+ drupal_goto('node/'. $node->nid);
+ }
+ else {
+ drupal_goto();
+ }
+ }
}
/**
@@ -1627,8 +1687,23 @@ function node_delete($edit) {
$node = node_load($edit['nid']);
if (node_access('delete', $node)) {
+ $form['nid'] = array(type => 'hidden', value => $node->nid);
+ $output = confirm_form('node_delete_confirm', $form,
+ t('Are you sure you want to delete %title?', array('%title' => theme('placeholder', $node->title))),
+ $_GET['destination'] ? $_GET['destination'] : 'node/'. $node->nid, t('This action cannot be undone.'),
+ t('Delete'), t('Cancel') );
+ }
+
+ return $output;
+}
- if ($edit['confirm']) {
+function node_delete_confirm_execute() {
+ global $form_values;
+ $node = node_load($form_values['nid']);
+
+ if (node_access('delete', $node)) {
+
+ if ($form_values['confirm']) {
db_query('DELETE FROM {node} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid);
@@ -1646,19 +1721,8 @@ function node_delete($edit) {
watchdog('content', t('%type: deleted %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))));
}
- else {
- $extra = form_hidden('nid', $node->nid);
- $output = theme('confirm',
- t('Are you sure you want to delete %title?', array('%title' => theme('placeholder', $node->title))),
- $_GET['destination'] ? $_GET['destination'] : 'node/'. $node->nid,
- t('This action cannot be undone.'),
- t('Delete'),
- t('Cancel'),
- $extra);
- }
}
-
- return $output;
+ drupal_goto('node');
}
/**
@@ -1695,8 +1759,9 @@ function node_page_default() {
* Menu callback; dispatches control to the appropriate operation handler.
*/
function node_page() {
- $op = $_POST['op'] ? $_POST['op'] : arg(1);
$edit = $_POST['edit'];
+
+ $op = arg(1);
if (is_numeric($op)) {
$op = (arg(2) && !is_numeric(arg(2))) ? arg(2) : 'view';
@@ -1738,12 +1803,21 @@ function node_page() {
case 'delete-revision':
node_revision_delete(arg(1), arg(3));
break;
- case 'edit':
+ case 'edit':
+ if ($_POST['op'] == t('Delete')) {
+ // Note: we redirect from node/uid/edit to node/uid/delete to make the tabs disappear.
+ if ($_REQUEST['destination']) {
+ $destination = drupal_get_destination();
+ unset($_REQUEST['destination']);
+ }
+ drupal_goto('node/'. arg(1) .'/delete', $destination);
+ }
+
if (is_numeric(arg(1))) {
$node = node_load(arg(1));
if ($node->nid) {
- drupal_set_title($node->title);
- return node_edit(arg(1));
+ drupal_set_title(check_plain($node->title));
+ return node_form($node);
}
else if (db_result(db_query('SELECT nid FROM {node} WHERE nid = %d', arg(1)))) {
drupal_access_denied();
@@ -1765,33 +1839,6 @@ function node_page() {
}
}
break;
- case t('Preview'):
- $edit = node_validate($edit);
- drupal_set_title(t('Preview'));
- return node_preview($edit);
- break;
- case t('Submit'):
- if ($nid = node_submit($edit)) {
- if (node_access('view', $edit)) {
- drupal_goto('node/'. $nid);
- }
- else {
- drupal_goto();
- }
- }
- else {
- drupal_set_title(t('Submit'));
- return node_preview($edit);
- }
- break;
- case t('Delete'):
- // Note: we redirect from node/uid/edit to node/uid/delete to make the tabs disappear.
- if ($_REQUEST['destination']) {
- $destination = drupal_get_destination();
- unset($_REQUEST['destination']);
- }
- drupal_goto('node/'. arg(1) .'/delete', $destination);
-
default:
drupal_set_title('');
return node_page_default();
@@ -1860,8 +1907,13 @@ function node_update_index() {
function node_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
case 'settings':
- // $node contains the type name in this operation
- return form_checkboxes(t('Default options'), 'node_options_'. $node->type, variable_get('node_options_'. $node->type, array('status', 'promote')), array('status' => t('Published'), 'moderate' => t('In moderation queue'), 'promote' => t('Promoted to front page'), 'sticky' => t('Sticky at top of lists'), 'revision' => t('Create new revision')), t('Users with the <em>administer nodes</em> permission will be able to override these options.'));
+ $form['node_options_'. $node->type] = array(
+ type => 'checkboxes', title => t('Default options'), default_value => variable_get('node_options_'. $node->type, array('status', 'promote')),
+ options => array('status' => t('Published'), 'moderate' => t('In moderation queue'), 'promote' => t('Promoted to front page'),
+ 'sticky' => t('Sticky at top of lists'), 'revision' => t('Create new revision')),
+ description => t('Users with the <em>administer nodes</em> permission will be able to override these options.')
+ );
+ return $form;
}
}
@@ -2045,7 +2097,7 @@ function node_access_view_all_nodes() {
}
}
$sql .= implode(',', $grants) .') AND grant_view = 1';
- $result = db_query($sql, $node->nid);
+ $result = db_query($sql);
$access = db_result($result);
}
diff --git a/modules/page.module b/modules/page.module
index 1370c9d6d..073c99cbb 100644
--- a/modules/page.module
+++ b/modules/page.module
@@ -74,18 +74,25 @@ function page_validate(&$node) {
* Implementation of hook_form().
*/
function page_form(&$node) {
- $output = form_textfield(t('Title'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
+
+ $form['title'] = array(type => 'textfield', title => t('Title'), size => 60, maxlength => 128, required => TRUE, default_value => $node->title);
if (function_exists('taxonomy_node_form')) {
- $output .= implode('', taxonomy_node_form('page', $node));
+ $form['taxonomy'] = taxonomy_node_form('page', $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, rows => 5,
+ description => t('An explanation of the additions or updates being made to help other authors understand your motivations.')
+ );
+
+ return $form;
}
diff --git a/modules/page/page.module b/modules/page/page.module
index 1370c9d6d..073c99cbb 100644
--- a/modules/page/page.module
+++ b/modules/page/page.module
@@ -74,18 +74,25 @@ function page_validate(&$node) {
* Implementation of hook_form().
*/
function page_form(&$node) {
- $output = form_textfield(t('Title'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
+
+ $form['title'] = array(type => 'textfield', title => t('Title'), size => 60, maxlength => 128, required => TRUE, default_value => $node->title);
if (function_exists('taxonomy_node_form')) {
- $output .= implode('', taxonomy_node_form('page', $node));
+ $form['taxonomy'] = taxonomy_node_form('page', $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, rows => 5,
+ description => t('An explanation of the additions or updates being made to help other authors understand your motivations.')
+ );
+
+ return $form;
}
diff --git a/modules/path.module b/modules/path.module
index a5fd3807a..147612ea8 100644
--- a/modules/path.module
+++ b/modules/path.module
@@ -89,10 +89,7 @@ function path_admin() {
* Menu callback; handles pages for creating and editing URL aliases.
*/
function path_admin_edit($pid = 0) {
- if ($_POST['op'] == t('Create new alias') || $_POST['op'] == t('Update alias')) {
- $output = path_save($_POST['edit']);
- }
- elseif ($pid) {
+ if ($pid) {
$alias = path_load($pid);
drupal_set_title($alias['dst']);
$output = path_form(path_load($pid));
@@ -161,18 +158,18 @@ function path_set_alias($path = NULL, $alias = NULL, $pid = NULL) {
*/
function path_form($edit = '') {
- $form .= form_textfield(t('Existing system path'), 'src', $edit['src'], 60, 64, t('Specify the existing path you wish to alias. For example: node/28, forum/1, taxonomy/term/1+2.'));
- $form .= form_textfield(t('New path alias'), 'dst', $edit['dst'], 60, 64, t('Specify an alternative path by which this data can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'));
+ $form['src'] = array(type => 'textfield', title => t('Existing system path'), default_value => $edit['src'], size => 60, maxlength => 64, description => t('Specify the existing path you wish to alias. For example: node/28, forum/1, taxonomy/term/1+2.'));
+ $form['dst'] = array(type => 'textfield', default_value => $edit['dst'], size => 60, maxlength => 64, description => t('Specify an alternative path by which this data can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'));
if ($edit['pid']) {
- $form .= form_hidden('pid', $edit['pid']);
- $form .= form_submit(t('Update alias'));
+ $form['pid'] = array(type => 'hidden', value => $edit['pid']);
+ $form['submit'] = array(type => 'submit', value => t('Update alias'));
}
else {
- $form .= form_submit(t('Create new alias'));
+ $form['submit'] = array(type => 'submit', value => t('Create new alias'));
}
- return form($form);
+ return drupal_get_form('path_form', $form);
}
/**
@@ -194,12 +191,12 @@ function path_nodeapi(&$node, $op, $arg) {
}
break;
- case 'form pre':
- $output = form_textfield(t('Path alias'), 'path', $node->path, 60, 250, t('Optionally specify an alternative URL by which this node can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'));
+ case 'form':
+ $form['path'] = array(type => 'textfield', title => t('Path alias'), weight => -16, default_value => $node->path, size => 60, maxlength => 250, description => t('Optionally specify an alternative URL by which this node can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'));
if ($node->path) {
- $output .= form_hidden('pid', db_result(db_query("SELECT pid FROM {url_alias} WHERE dst = '%s'", $node->path)));
+ $form['pid'] = array(type => 'hidden', value => db_result(db_query("SELECT pid FROM {url_alias} WHERE dst = '%s'", $node->path)));
}
- return $output;
+ return $form;
case 'load':
$path = "node/$node->nid";
@@ -275,7 +272,8 @@ function path_load($pid) {
/**
* Verify that a new URL alias is valid, and save it to the database.
*/
-function path_save($edit) {
+function path_form_execute() {
+ $edit = $GLOBALS['form_values'];
$src = $edit['src'];
$dst = $edit['dst'];
$pid = $edit['pid'];
diff --git a/modules/path/path.module b/modules/path/path.module
index a5fd3807a..147612ea8 100644
--- a/modules/path/path.module
+++ b/modules/path/path.module
@@ -89,10 +89,7 @@ function path_admin() {
* Menu callback; handles pages for creating and editing URL aliases.
*/
function path_admin_edit($pid = 0) {
- if ($_POST['op'] == t('Create new alias') || $_POST['op'] == t('Update alias')) {
- $output = path_save($_POST['edit']);
- }
- elseif ($pid) {
+ if ($pid) {
$alias = path_load($pid);
drupal_set_title($alias['dst']);
$output = path_form(path_load($pid));
@@ -161,18 +158,18 @@ function path_set_alias($path = NULL, $alias = NULL, $pid = NULL) {
*/
function path_form($edit = '') {
- $form .= form_textfield(t('Existing system path'), 'src', $edit['src'], 60, 64, t('Specify the existing path you wish to alias. For example: node/28, forum/1, taxonomy/term/1+2.'));
- $form .= form_textfield(t('New path alias'), 'dst', $edit['dst'], 60, 64, t('Specify an alternative path by which this data can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'));
+ $form['src'] = array(type => 'textfield', title => t('Existing system path'), default_value => $edit['src'], size => 60, maxlength => 64, description => t('Specify the existing path you wish to alias. For example: node/28, forum/1, taxonomy/term/1+2.'));
+ $form['dst'] = array(type => 'textfield', default_value => $edit['dst'], size => 60, maxlength => 64, description => t('Specify an alternative path by which this data can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'));
if ($edit['pid']) {
- $form .= form_hidden('pid', $edit['pid']);
- $form .= form_submit(t('Update alias'));
+ $form['pid'] = array(type => 'hidden', value => $edit['pid']);
+ $form['submit'] = array(type => 'submit', value => t('Update alias'));
}
else {
- $form .= form_submit(t('Create new alias'));
+ $form['submit'] = array(type => 'submit', value => t('Create new alias'));
}
- return form($form);
+ return drupal_get_form('path_form', $form);
}
/**
@@ -194,12 +191,12 @@ function path_nodeapi(&$node, $op, $arg) {
}
break;
- case 'form pre':
- $output = form_textfield(t('Path alias'), 'path', $node->path, 60, 250, t('Optionally specify an alternative URL by which this node can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'));
+ case 'form':
+ $form['path'] = array(type => 'textfield', title => t('Path alias'), weight => -16, default_value => $node->path, size => 60, maxlength => 250, description => t('Optionally specify an alternative URL by which this node can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'));
if ($node->path) {
- $output .= form_hidden('pid', db_result(db_query("SELECT pid FROM {url_alias} WHERE dst = '%s'", $node->path)));
+ $form['pid'] = array(type => 'hidden', value => db_result(db_query("SELECT pid FROM {url_alias} WHERE dst = '%s'", $node->path)));
}
- return $output;
+ return $form;
case 'load':
$path = "node/$node->nid";
@@ -275,7 +272,8 @@ function path_load($pid) {
/**
* Verify that a new URL alias is valid, and save it to the database.
*/
-function path_save($edit) {
+function path_form_execute() {
+ $edit = $GLOBALS['form_values'];
$src = $edit['src'];
$dst = $edit['dst'];
$pid = $edit['pid'];
diff --git a/modules/poll.module b/modules/poll.module
index b8249347a..a6931f9dd 100644
--- a/modules/poll.module
+++ b/modules/poll.module
@@ -123,7 +123,7 @@ function poll_validate(&$node) {
function poll_form(&$node) {
$admin = user_access('administer nodes');
- $output = form_textfield(t('Question'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
+ $form['title'] = array(type => 'textfield', title => t('Question'), size => 60, maxlength => 128, required => TRUE, default_value => $node->title, weight => -1);
if (function_exists('taxonomy_node_form')) {
$output .= implode('', taxonomy_node_form('poll', $node));
@@ -138,34 +138,29 @@ function poll_form(&$node) {
$node->choices *= 2;
}
- $output .= '<div class="poll-form">';
-
// Poll choices
$opts = drupal_map_assoc(range(2, $node->choices * 2 + 5));
+ $form['choice'] = array(type => 'fieldset', title => t('Choices'), prefix => '<div class="poll-form">', suffix => '</div>', tree => TRUE);
for ($a = 0; $a < $node->choices; $a++) {
- $group1 .= form_textfield(t('Choice %n', array('%n' => ($a + 1))), "choice][$a][chtext", $node->choice[$a]['chtext'], 60, 127);
+ $form['choice'][$a]['chtext'] = array(type => 'textfield', title => t('Choice %n', array('%n' => ($a + 1))), default_value => $node->choice[$a]['chtext'], size => 60, maxlength => 127);
if ($admin) {
- $group1 .= form_textfield(t('Votes for choice %n', array('%n' => ($a + 1))), "choice][$a][chvotes", (int)$node->choice[$a]['chvotes'], 5, 7);
+ $form['choice'][$a]['chvotes'] = array(type => 'textfield', title => t('Votes for choice %n', array('%n' => ($a + 1))), default_value => (int)$node->choice[$a]['chvotes'], size => 5, maxlength => 7);
}
}
- $group1 .= form_hidden('choices', $node->choices);
- $group1 .= form_checkbox(t('Need more choices'), 'morechoices', 1, 0, t("If the amount of boxes above isn't enough, check this box and click the Preview button below to add some more."));
- $output .= form_group(t('Choices'), $group1);
-
+ $form['choices'] = array(type => 'hidden', value => $node->choices);
+ $form['morechoices'] = array(type => 'checkbox', title => t('Need more choices'), return_value => 1, default_value => 0, description => t("If the amount of boxes above isn't enough, check this box and click the Preview button below to add some more."));
// Poll attributes
$_duration = array(0 => t('Unlimited')) + drupal_map_assoc(array(86400, 172800, 345600, 604800, 1209600, 2419200, 4838400, 9676800, 31536000), "format_interval");
$_active = array(0 => t('Closed'), 1 => t('Active'));
if ($admin) {
- $group2 .= form_radios(t('Poll status'), 'active', isset($node->active) ? $node->active : 1, $_active, t('When a poll is closed, visitors can no longer vote for it.'));
+ $form['settings'] = array(type => 'fieldset', title => t('Settings'), suffix => '</div>');
+ $form['settings']['active'] = array(type => 'radios', title => t('Poll status'), default_value => isset($node->active) ? $node->active : 1, options => $_active, description => t('When a poll is closed, visitors can no longer vote for it.'));
}
- $group2 .= form_select(t('Poll duration'), 'runtime', $node->runtime ? $node->runtime : 0, $_duration, t('After this period, the poll will be closed automatically.'));
-
- $output .= form_group(t('Settings'), $group2);
- $output .= '</div>';
+ $form['settings']['runtime'] = array(type => 'select', title => t('Poll duration'), default_value => $node->runtime ? $node->runtime : 0, options => $_duration, description => t('After this period, the poll will be closed automatically.'));
- return $output;
+ return $form;
}
function poll_insert($node) {
@@ -306,24 +301,36 @@ function poll_teaser($node) {
* Generates the voting form for a poll.
*/
function poll_view_voting(&$node, $teaser, $page, $block) {
- $output = '<div class="poll">';
-
- $form = '<div class="vote-form">';
- $form .= '<div class="choices">';
+ if ($_POST['op'] == t('Vote')) {
+ poll_vote($node);
+ }
+
if ($node->choice) {
$list = array();
foreach ($node->choice as $i => $choice) {
$list[$i] = check_plain($choice['chtext']);
}
- $form .= form_radios($page ? '' : check_plain($node->title), 'choice', -1, $list);
+ $form['choice'] = array(type => 'radios', title => $page ? '' : check_plain($node->title), default_value => -1, options => $list);
}
- $form .= '</div>';
- $form .= form_hidden('nid', $node->nid);
- $form .= form_submit(t('Vote'), 'vote') .'</div>';
+ $form['nid'] = array(type => 'hidden', value => $node->nid);
+ $form['vote'] = array(type => 'submit', value => t('Vote'));
+ return drupal_get_form('poll_view_voting', $form);
+}
- $output .= form($form, 'post', url('poll/vote/'. $node->nid));
+/**
+ * Themes the voting form for a poll.
+ */
+function theme_poll_view_voting($form) {
+ $output .= '<div class="poll">';
+ $output .= ' <div class="vote-form">';
+ $output .= ' <div class="choices">';
+ $output .= form_render($form['choice']);
+ $output .= ' </div>';
+ $output .= form_render($form['nid']);
+ $output .= form_render($form['vote']);
+ $output .= ' </div>';
+ $output .= form_render($form);
$output .= '</div>';
-
return $output;
}
@@ -378,7 +385,7 @@ function poll_results() {
* Callback for processing a vote
*/
function poll_vote(&$node) {
- $nid = arg(2);
+ $nid = arg(1);
if ($node = node_load($nid)) {
$edit = $_POST['edit'];
$choice = $edit['choice'];
diff --git a/modules/poll/poll.module b/modules/poll/poll.module
index b8249347a..a6931f9dd 100644
--- a/modules/poll/poll.module
+++ b/modules/poll/poll.module
@@ -123,7 +123,7 @@ function poll_validate(&$node) {
function poll_form(&$node) {
$admin = user_access('administer nodes');
- $output = form_textfield(t('Question'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
+ $form['title'] = array(type => 'textfield', title => t('Question'), size => 60, maxlength => 128, required => TRUE, default_value => $node->title, weight => -1);
if (function_exists('taxonomy_node_form')) {
$output .= implode('', taxonomy_node_form('poll', $node));
@@ -138,34 +138,29 @@ function poll_form(&$node) {
$node->choices *= 2;
}
- $output .= '<div class="poll-form">';
-
// Poll choices
$opts = drupal_map_assoc(range(2, $node->choices * 2 + 5));
+ $form['choice'] = array(type => 'fieldset', title => t('Choices'), prefix => '<div class="poll-form">', suffix => '</div>', tree => TRUE);
for ($a = 0; $a < $node->choices; $a++) {
- $group1 .= form_textfield(t('Choice %n', array('%n' => ($a + 1))), "choice][$a][chtext", $node->choice[$a]['chtext'], 60, 127);
+ $form['choice'][$a]['chtext'] = array(type => 'textfield', title => t('Choice %n', array('%n' => ($a + 1))), default_value => $node->choice[$a]['chtext'], size => 60, maxlength => 127);
if ($admin) {
- $group1 .= form_textfield(t('Votes for choice %n', array('%n' => ($a + 1))), "choice][$a][chvotes", (int)$node->choice[$a]['chvotes'], 5, 7);
+ $form['choice'][$a]['chvotes'] = array(type => 'textfield', title => t('Votes for choice %n', array('%n' => ($a + 1))), default_value => (int)$node->choice[$a]['chvotes'], size => 5, maxlength => 7);
}
}
- $group1 .= form_hidden('choices', $node->choices);
- $group1 .= form_checkbox(t('Need more choices'), 'morechoices', 1, 0, t("If the amount of boxes above isn't enough, check this box and click the Preview button below to add some more."));
- $output .= form_group(t('Choices'), $group1);
-
+ $form['choices'] = array(type => 'hidden', value => $node->choices);
+ $form['morechoices'] = array(type => 'checkbox', title => t('Need more choices'), return_value => 1, default_value => 0, description => t("If the amount of boxes above isn't enough, check this box and click the Preview button below to add some more."));
// Poll attributes
$_duration = array(0 => t('Unlimited')) + drupal_map_assoc(array(86400, 172800, 345600, 604800, 1209600, 2419200, 4838400, 9676800, 31536000), "format_interval");
$_active = array(0 => t('Closed'), 1 => t('Active'));
if ($admin) {
- $group2 .= form_radios(t('Poll status'), 'active', isset($node->active) ? $node->active : 1, $_active, t('When a poll is closed, visitors can no longer vote for it.'));
+ $form['settings'] = array(type => 'fieldset', title => t('Settings'), suffix => '</div>');
+ $form['settings']['active'] = array(type => 'radios', title => t('Poll status'), default_value => isset($node->active) ? $node->active : 1, options => $_active, description => t('When a poll is closed, visitors can no longer vote for it.'));
}
- $group2 .= form_select(t('Poll duration'), 'runtime', $node->runtime ? $node->runtime : 0, $_duration, t('After this period, the poll will be closed automatically.'));
-
- $output .= form_group(t('Settings'), $group2);
- $output .= '</div>';
+ $form['settings']['runtime'] = array(type => 'select', title => t('Poll duration'), default_value => $node->runtime ? $node->runtime : 0, options => $_duration, description => t('After this period, the poll will be closed automatically.'));
- return $output;
+ return $form;
}
function poll_insert($node) {
@@ -306,24 +301,36 @@ function poll_teaser($node) {
* Generates the voting form for a poll.
*/
function poll_view_voting(&$node, $teaser, $page, $block) {
- $output = '<div class="poll">';
-
- $form = '<div class="vote-form">';
- $form .= '<div class="choices">';
+ if ($_POST['op'] == t('Vote')) {
+ poll_vote($node);
+ }
+
if ($node->choice) {
$list = array();
foreach ($node->choice as $i => $choice) {
$list[$i] = check_plain($choice['chtext']);
}
- $form .= form_radios($page ? '' : check_plain($node->title), 'choice', -1, $list);
+ $form['choice'] = array(type => 'radios', title => $page ? '' : check_plain($node->title), default_value => -1, options => $list);
}
- $form .= '</div>';
- $form .= form_hidden('nid', $node->nid);
- $form .= form_submit(t('Vote'), 'vote') .'</div>';
+ $form['nid'] = array(type => 'hidden', value => $node->nid);
+ $form['vote'] = array(type => 'submit', value => t('Vote'));
+ return drupal_get_form('poll_view_voting', $form);
+}
- $output .= form($form, 'post', url('poll/vote/'. $node->nid));
+/**
+ * Themes the voting form for a poll.
+ */
+function theme_poll_view_voting($form) {
+ $output .= '<div class="poll">';
+ $output .= ' <div class="vote-form">';
+ $output .= ' <div class="choices">';
+ $output .= form_render($form['choice']);
+ $output .= ' </div>';
+ $output .= form_render($form['nid']);
+ $output .= form_render($form['vote']);
+ $output .= ' </div>';
+ $output .= form_render($form);
$output .= '</div>';
-
return $output;
}
@@ -378,7 +385,7 @@ function poll_results() {
* Callback for processing a vote
*/
function poll_vote(&$node) {
- $nid = arg(2);
+ $nid = arg(1);
if ($node = node_load($nid)) {
$edit = $_POST['edit'];
$choice = $edit['choice'];
diff --git a/modules/profile.module b/modules/profile.module
index 07e7b01cf..b329cc892 100644
--- a/modules/profile.module
+++ b/modules/profile.module
@@ -44,8 +44,8 @@ function profile_block($op = 'list', $delta = 0, $edit = array()) {
$fields[$record->name] = $record->title;
}
$fields['user_profile'] = t('Link to full user profile');
- $output .= form_checkboxes(t('Profile fields to display'), 'profile_block_author_fields', variable_get('profile_block_author_fields', NULL), $fields, t('Select which profile fields you wish to display in the block. Only fields designated as public in the <a href="%profile-admin">profile field configuration</a> are available.', array('%profile-admin' => url('admin/settings/profile'))));
- return $output;
+ $form['profile_block_author_fields'] = array(type => 'checkboxes', title => t('Profile fields to display'), default_value => variable_get('profile_block_author_fields', NULL), options => $fields, description => t('Select which profile fields you wish to display in the block. Only fields designated as public in the <a href="%profile-admin">profile field configuration</a> are available.', array('%profile-admin' => url('admin/settings/profile'))));
+ return $form;
}
else if ($op == 'save' && $delta == 0) {
variable_set('profile_block_author_fields', $edit['profile_block_author_fields']);
@@ -297,7 +297,8 @@ function profile_view_profile($user) {
if ($value = profile_view_field($user, $field)) {
$description = ($field->visibility == PROFILE_PRIVATE) ? t('The content of this field is private and only visible to yourself.') : '';
$title = ($field->type != 'checkbox') ? check_plain($field->title) : '';
- $fields[$field->category][$field->name] = form_item($title, $value, $description);
+ $form = array(type => 'item', title => $title, value => $value, description => $description);
+ $fields[$field->category][$field->name] = form_render(_form_builder($form));
}
}
@@ -327,23 +328,25 @@ function profile_form_profile($edit, $user, $category) {
$result = db_query("SELECT * FROM {profile_fields} WHERE LOWER(category) = LOWER('%s') ORDER BY weight", $category);
// We use LOWER('%s') instead of PHP's strtolower() to avoid UTF-8 conversion issues.
}
-
- $fields = array();
+ // Only add form group if items exist
+ if (db_num_rows($result)) {
+ $fields[$category] = array(type => 'fieldset', title => $category);
+ }
while ($field = db_fetch_object($result)) {
$category = $field->category;
switch ($field->type) {
case 'textfield':
- case 'url':
- $fields[$category] .= form_textfield(check_plain($field->title), $field->name, $edit[$field->name], 60, 255, _profile_form_explanation($field), NULL, $field->required);
+ case 'url':
+ $fields[$category][$field->name] = array(type => 'textfield', title => check_plain($field->title), default_value => $edit[$field->name], size => 60, maxlength => 255, description => _profile_form_explanation($field), required => $field->required);
break;
- case 'textarea':
- $fields[$category] .= form_textarea(check_plain($field->title), $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
+ case 'textarea':
+ $fields[$category][$field->name] = array(type => 'textarea', title => check_plain($field->title), default_value => $edit[$field->name], cols => 60, rows => 5, description => _profile_form_explanation($field), required => $field->required);
break;
case 'list':
- $fields[$category] .= form_textarea(check_plain($field->title), $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
+ $fields[$category][$field->name] = array(type => 'textarea', title => check_plain($field->title), default_value => $edit[$field->name], cols => 60, rows => 5, description => _profile_form_explanation($field), required => $field->required);
break;
- case 'checkbox':
- $fields[$category] .= form_checkbox(check_plain($field->title), $field->name, 1, $edit[$field->name], _profile_form_explanation($field), NULL, $field->required);
+ case 'checkbox':
+ $fields[$category][$field->name] = array(type => 'checkbox', title => check_plain($field->title), return_value => 1, default_value => $edit[$field->name], description => _profile_form_explanation($field), required => $field->required);
break;
case 'selection':
$options = array('--');
@@ -353,21 +356,14 @@ function profile_form_profile($edit, $user, $category) {
$options[$line] = $line;
}
}
-
- $fields[$category] .= form_select(check_plain($field->title), $field->name, $edit[$field->name], $options, _profile_form_explanation($field), 0, 0, $field->required);
+ $fields[$category][$field->name] = array(type => 'select', title => check_plain($field->title), default_value => $edit[$field->name], options => $options, description => _profile_form_explanation($field), required => $field->required);
break;
case 'date':
- $fields[$category] .= _profile_date_field($field, $edit);
+ $fields[$category][$field->name] = array(type => 'date', title => check_plain($field->title), default_value => $edit[$field->name], description, description => _profile_form_explanation($field), required => $field->required);
break;
}
}
-
- if ($fields) {
- foreach ($fields as $category => $data) {
- $output[] = array('title' => $category, 'data' => $data);
- }
- return $output;
- }
+ return $fields;
}
/**
@@ -381,46 +377,6 @@ function _profile_update_user_fields(&$fields, $account) {
}
}
-/**
- * Helper function: output a date selector
- */
-function _profile_date_field($field, $edit) {
- // Default to current date
- if (!isset($edit[$field->name])) {
- $edit[$field->name] = array('day' => format_date(time(), 'custom', 'j'),
- 'month' => format_date(time(), 'custom', 'n'),
- 'year' => format_date(time(), 'custom', 'Y'));
- }
-
- // Determine the order of day, month, year in the site's chosen date format.
- $format = variable_get('date_format_short', 'm/d/Y');
- $sort = array();
- $sort['day'] = max(strpos($format, 'd'), strpos($format, 'j'));
- $sort['month'] = max(strpos($format, 'm'), strpos($format, 'M'));
- $sort['year'] = strpos($format, 'Y');
- asort($sort);
- $order = array_keys($sort);
-
- // Output multi-selector for date
- $output = '<div class="container-inline">';
- foreach ($order as $type) {
- switch ($type) {
- case 'day':
- $options = drupal_map_assoc(range(1, 31));
- break;
- case 'month':
- $options = drupal_map_assoc(range(1, 12), '_profile_map_month');
- break;
- case 'year':
- $options = drupal_map_assoc(range(1900, 2050));
- break;
- }
- $output .= form_select('', $field->name .']['. $type, $edit[$field->name][$type], $options, '', 0, 0);
- }
- $output .= '</div>';
-
- return form_item(check_plain($field->title), $output, _profile_form_explanation($field), NULL, $field->required);
-}
/**
* Helper function for usage with drupal_map_assoc
@@ -585,39 +541,36 @@ function profile_admin_delete($fid) {
drupal_goto('admin/settings/profile');
}
else {
- $output = theme('confirm',
- t('Do you want to remove the field %field?',
+ return confirm_form('profile_confirm_delete', $form, t('Do you want to remove the field %field?',
array('%field' => $field->title)),
- 'admin/settings/profile');
- return $output;
+ 'admin/settings/profile', '', t('Delete'), t('Cancel'));
}
}
function _profile_field_form($type, $edit = array()) {
-
- $group = form_textfield(t('Category'), 'category', $edit['category'], 60, 128, t('The category the new field should be part of. Categories are used to group fields logically. An example category is "Personal information".'));
- $group .= form_textfield(t('Title'), 'title', $edit['title'], 60, 128, t('The title of the new field. The title will be shown to the user. An example title is "Favorite color".'));
- $group .= form_textfield(t('Form name'), 'name', $edit['name'], 60, 128, t('The name of the field. The form name is not shown to the user but used internally in the HTML code and URLs.
+
+ $form['fields'] = array(type => 'fieldset', title => t('Field settings'));
+ $form['fields']['category'] = array(type => 'textfield', title => t('Category'), default_value => $edit['category'], size => 60, maxlength => 128, description => t('The category the new field should be part of. Categories are used to group fields logically. An example category is "Personal information".'));
+ $form['fields']['title'] = array(type => 'textfield', title => t('Title'), default_value => $edit['title'], size => 60, maxlength => 128, description => t('The title of the new field. The title will be shown to the user. An example title is "Favorite color".'));
+ $form['fields']['name'] = array(type => 'textfield', title => t('Form name'), default_value => $edit['name'], size => 60, maxlength => 128, description => t('The name of the field. The form name is not shown to the user but used internally in the HTML code and URLs.
Unless you know what you are doing, it is highly recommended that you prefix the form name with <code>profile_</code> to avoid name clashes with other fields. Spaces or any other special characters except dash (-) and underscore (_) are not allowed. An example name is "profile_favorite_color" or perhaps just "profile_color".'));
- $group .= form_textarea(t('Explanation'), 'explanation', $edit['explanation'], 60, 5, t('An optional explanation to go with the new field. The explanation will be shown to the user.'));
+ $form['fields']['explanation'] = array(type => 'textarea', title => t('Explanation'), default_value => $edit['explanation'], cols => 60, rows => 5, description => t('An optional explanation to go with the new field. The explanation will be shown to the user.'));
if ($type == 'selection') {
- $group .= form_textarea(t('Selection options'), 'options', $edit['options'], 60, 5, t('A list of all options. Put each option on a separate line. Example options are "red", "blue", "green", etc.'));
+ $form['fields']['options'] = array(type => 'textarea', title => t('Selection options'), default_value => $edit['options'], cols => 60, rows => 5, description => t('A list of all options. Put each option on a separate line. Example options are "red", "blue", "green", etc.'));
}
- $group .= form_weight(t('Weight'), 'weight', $edit['weight'], 5, t('The weights define the order in which the form fields are shown. Lighter fields "float up" towards the top of the category.'));
- $group .= form_radios(t('Visibility'), 'visibility', $edit['visibility'], array(PROFILE_HIDDEN => t('Hidden profile field, only accessible by administrators, modules and themes.'), PROFILE_PRIVATE => t('Private field, content only available to privileged users.'), PROFILE_PUBLIC => t('Public field, content shown on profile page but not used on member list pages.'), PROFILE_PUBLIC_LISTINGS => t('Public field, content shown on profile page and on member list pages.')));
+ $form['fields']['weight'] = array(type => 'weight', title => t('Weight'), default_value => $edit['weight'], delta => 5, description => t('The weights define the order in which the form fields are shown. Lighter fields "float up" towards the top of the category.'));
+ $form['fields']['visibility'] = array(type => 'radios', title => t('Visibility'), default_value => $edit['visibility'], options => array(PROFILE_HIDDEN => t('Hidden profile field, only accessible by administrators, modules and themes.'), PROFILE_PRIVATE => t('Private field, content only available to privileged users.'), PROFILE_PUBLIC => t('Public field, content shown on profile page but not used on member list pages.'), PROFILE_PUBLIC_LISTINGS => t('Public field, content shown on profile page and on member list pages.')));
if ($type == 'selection' || $type == 'list') {
- $group .= form_textfield(t('Page title'), 'page', $edit['page'], 60, 128, t('The title of the page showing all users with the specified field. The word <code>%value</code> will be substituted with the corresponding value. An example page title is "People whose favorite color is %value". Only applicable if the field is configured to be shown on member list pages.'));
+ $form['fields']['page'] = array(type => 'textfield', title => t('Page title'), default_value => $edit['page'], size => 60, maxlength => 128, description => t('The title of the page showing all users with the specified field. The word <code>%value</code> will be substituted with the corresponding value. An example page title is "People whose favorite color is %value". Only applicable if the field is configured to be shown on member list pages.'));
}
else {
- $group .= form_textfield(t('Page title'), 'page', $edit['page'], 60, 128, t('The title of the page showing all users with the specified field. Only applicable if the field is configured to be shown on member listings.'));
+ $form['fields']['page'] = array(type => 'textfield', title => t('Page title'), default_value => $edit['page'], size => 60, maxlength => 128, description => t('The title of the page showing all users with the specified field. Only applicable if the field is configured to be shown on member listings.'));
}
- $group .= form_checkbox(t('The user must enter a value.'), 'required', 1, $edit['required']);
- $group .= form_checkbox(t('Visible in user registration form.'), 'register', 1, $edit['register']);
-
- $output = form_group(t('Field settings'), $group);
- $output .= form_submit(t('Save field'));
+ $form['fields']['required'] = array(type => 'checkbox', title => t('The user must enter a value.'), return_value => 1, default_value => $edit['required']);
+ $form['fields']['register'] = array(type => 'checkbox', title => t('Visible in user registration form.'), return_value => 1, default_value => $edit['register']);
+ $form['submit'] = array(type => 'submit', value => t('Save field'));
- return form($output);
+ return drupal_get_form('_profile_field_form', $form);
}
/**
diff --git a/modules/profile/profile.module b/modules/profile/profile.module
index 07e7b01cf..b329cc892 100644
--- a/modules/profile/profile.module
+++ b/modules/profile/profile.module
@@ -44,8 +44,8 @@ function profile_block($op = 'list', $delta = 0, $edit = array()) {
$fields[$record->name] = $record->title;
}
$fields['user_profile'] = t('Link to full user profile');
- $output .= form_checkboxes(t('Profile fields to display'), 'profile_block_author_fields', variable_get('profile_block_author_fields', NULL), $fields, t('Select which profile fields you wish to display in the block. Only fields designated as public in the <a href="%profile-admin">profile field configuration</a> are available.', array('%profile-admin' => url('admin/settings/profile'))));
- return $output;
+ $form['profile_block_author_fields'] = array(type => 'checkboxes', title => t('Profile fields to display'), default_value => variable_get('profile_block_author_fields', NULL), options => $fields, description => t('Select which profile fields you wish to display in the block. Only fields designated as public in the <a href="%profile-admin">profile field configuration</a> are available.', array('%profile-admin' => url('admin/settings/profile'))));
+ return $form;
}
else if ($op == 'save' && $delta == 0) {
variable_set('profile_block_author_fields', $edit['profile_block_author_fields']);
@@ -297,7 +297,8 @@ function profile_view_profile($user) {
if ($value = profile_view_field($user, $field)) {
$description = ($field->visibility == PROFILE_PRIVATE) ? t('The content of this field is private and only visible to yourself.') : '';
$title = ($field->type != 'checkbox') ? check_plain($field->title) : '';
- $fields[$field->category][$field->name] = form_item($title, $value, $description);
+ $form = array(type => 'item', title => $title, value => $value, description => $description);
+ $fields[$field->category][$field->name] = form_render(_form_builder($form));
}
}
@@ -327,23 +328,25 @@ function profile_form_profile($edit, $user, $category) {
$result = db_query("SELECT * FROM {profile_fields} WHERE LOWER(category) = LOWER('%s') ORDER BY weight", $category);
// We use LOWER('%s') instead of PHP's strtolower() to avoid UTF-8 conversion issues.
}
-
- $fields = array();
+ // Only add form group if items exist
+ if (db_num_rows($result)) {
+ $fields[$category] = array(type => 'fieldset', title => $category);
+ }
while ($field = db_fetch_object($result)) {
$category = $field->category;
switch ($field->type) {
case 'textfield':
- case 'url':
- $fields[$category] .= form_textfield(check_plain($field->title), $field->name, $edit[$field->name], 60, 255, _profile_form_explanation($field), NULL, $field->required);
+ case 'url':
+ $fields[$category][$field->name] = array(type => 'textfield', title => check_plain($field->title), default_value => $edit[$field->name], size => 60, maxlength => 255, description => _profile_form_explanation($field), required => $field->required);
break;
- case 'textarea':
- $fields[$category] .= form_textarea(check_plain($field->title), $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
+ case 'textarea':
+ $fields[$category][$field->name] = array(type => 'textarea', title => check_plain($field->title), default_value => $edit[$field->name], cols => 60, rows => 5, description => _profile_form_explanation($field), required => $field->required);
break;
case 'list':
- $fields[$category] .= form_textarea(check_plain($field->title), $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
+ $fields[$category][$field->name] = array(type => 'textarea', title => check_plain($field->title), default_value => $edit[$field->name], cols => 60, rows => 5, description => _profile_form_explanation($field), required => $field->required);
break;
- case 'checkbox':
- $fields[$category] .= form_checkbox(check_plain($field->title), $field->name, 1, $edit[$field->name], _profile_form_explanation($field), NULL, $field->required);
+ case 'checkbox':
+ $fields[$category][$field->name] = array(type => 'checkbox', title => check_plain($field->title), return_value => 1, default_value => $edit[$field->name], description => _profile_form_explanation($field), required => $field->required);
break;
case 'selection':
$options = array('--');
@@ -353,21 +356,14 @@ function profile_form_profile($edit, $user, $category) {
$options[$line] = $line;
}
}
-
- $fields[$category] .= form_select(check_plain($field->title), $field->name, $edit[$field->name], $options, _profile_form_explanation($field), 0, 0, $field->required);
+ $fields[$category][$field->name] = array(type => 'select', title => check_plain($field->title), default_value => $edit[$field->name], options => $options, description => _profile_form_explanation($field), required => $field->required);
break;
case 'date':
- $fields[$category] .= _profile_date_field($field, $edit);
+ $fields[$category][$field->name] = array(type => 'date', title => check_plain($field->title), default_value => $edit[$field->name], description, description => _profile_form_explanation($field), required => $field->required);
break;
}
}
-
- if ($fields) {
- foreach ($fields as $category => $data) {
- $output[] = array('title' => $category, 'data' => $data);
- }
- return $output;
- }
+ return $fields;
}
/**
@@ -381,46 +377,6 @@ function _profile_update_user_fields(&$fields, $account) {
}
}
-/**
- * Helper function: output a date selector
- */
-function _profile_date_field($field, $edit) {
- // Default to current date
- if (!isset($edit[$field->name])) {
- $edit[$field->name] = array('day' => format_date(time(), 'custom', 'j'),
- 'month' => format_date(time(), 'custom', 'n'),
- 'year' => format_date(time(), 'custom', 'Y'));
- }
-
- // Determine the order of day, month, year in the site's chosen date format.
- $format = variable_get('date_format_short', 'm/d/Y');
- $sort = array();
- $sort['day'] = max(strpos($format, 'd'), strpos($format, 'j'));
- $sort['month'] = max(strpos($format, 'm'), strpos($format, 'M'));
- $sort['year'] = strpos($format, 'Y');
- asort($sort);
- $order = array_keys($sort);
-
- // Output multi-selector for date
- $output = '<div class="container-inline">';
- foreach ($order as $type) {
- switch ($type) {
- case 'day':
- $options = drupal_map_assoc(range(1, 31));
- break;
- case 'month':
- $options = drupal_map_assoc(range(1, 12), '_profile_map_month');
- break;
- case 'year':
- $options = drupal_map_assoc(range(1900, 2050));
- break;
- }
- $output .= form_select('', $field->name .']['. $type, $edit[$field->name][$type], $options, '', 0, 0);
- }
- $output .= '</div>';
-
- return form_item(check_plain($field->title), $output, _profile_form_explanation($field), NULL, $field->required);
-}
/**
* Helper function for usage with drupal_map_assoc
@@ -585,39 +541,36 @@ function profile_admin_delete($fid) {
drupal_goto('admin/settings/profile');
}
else {
- $output = theme('confirm',
- t('Do you want to remove the field %field?',
+ return confirm_form('profile_confirm_delete', $form, t('Do you want to remove the field %field?',
array('%field' => $field->title)),
- 'admin/settings/profile');
- return $output;
+ 'admin/settings/profile', '', t('Delete'), t('Cancel'));
}
}
function _profile_field_form($type, $edit = array()) {
-
- $group = form_textfield(t('Category'), 'category', $edit['category'], 60, 128, t('The category the new field should be part of. Categories are used to group fields logically. An example category is "Personal information".'));
- $group .= form_textfield(t('Title'), 'title', $edit['title'], 60, 128, t('The title of the new field. The title will be shown to the user. An example title is "Favorite color".'));
- $group .= form_textfield(t('Form name'), 'name', $edit['name'], 60, 128, t('The name of the field. The form name is not shown to the user but used internally in the HTML code and URLs.
+
+ $form['fields'] = array(type => 'fieldset', title => t('Field settings'));
+ $form['fields']['category'] = array(type => 'textfield', title => t('Category'), default_value => $edit['category'], size => 60, maxlength => 128, description => t('The category the new field should be part of. Categories are used to group fields logically. An example category is "Personal information".'));
+ $form['fields']['title'] = array(type => 'textfield', title => t('Title'), default_value => $edit['title'], size => 60, maxlength => 128, description => t('The title of the new field. The title will be shown to the user. An example title is "Favorite color".'));
+ $form['fields']['name'] = array(type => 'textfield', title => t('Form name'), default_value => $edit['name'], size => 60, maxlength => 128, description => t('The name of the field. The form name is not shown to the user but used internally in the HTML code and URLs.
Unless you know what you are doing, it is highly recommended that you prefix the form name with <code>profile_</code> to avoid name clashes with other fields. Spaces or any other special characters except dash (-) and underscore (_) are not allowed. An example name is "profile_favorite_color" or perhaps just "profile_color".'));
- $group .= form_textarea(t('Explanation'), 'explanation', $edit['explanation'], 60, 5, t('An optional explanation to go with the new field. The explanation will be shown to the user.'));
+ $form['fields']['explanation'] = array(type => 'textarea', title => t('Explanation'), default_value => $edit['explanation'], cols => 60, rows => 5, description => t('An optional explanation to go with the new field. The explanation will be shown to the user.'));
if ($type == 'selection') {
- $group .= form_textarea(t('Selection options'), 'options', $edit['options'], 60, 5, t('A list of all options. Put each option on a separate line. Example options are "red", "blue", "green", etc.'));
+ $form['fields']['options'] = array(type => 'textarea', title => t('Selection options'), default_value => $edit['options'], cols => 60, rows => 5, description => t('A list of all options. Put each option on a separate line. Example options are "red", "blue", "green", etc.'));
}
- $group .= form_weight(t('Weight'), 'weight', $edit['weight'], 5, t('The weights define the order in which the form fields are shown. Lighter fields "float up" towards the top of the category.'));
- $group .= form_radios(t('Visibility'), 'visibility', $edit['visibility'], array(PROFILE_HIDDEN => t('Hidden profile field, only accessible by administrators, modules and themes.'), PROFILE_PRIVATE => t('Private field, content only available to privileged users.'), PROFILE_PUBLIC => t('Public field, content shown on profile page but not used on member list pages.'), PROFILE_PUBLIC_LISTINGS => t('Public field, content shown on profile page and on member list pages.')));
+ $form['fields']['weight'] = array(type => 'weight', title => t('Weight'), default_value => $edit['weight'], delta => 5, description => t('The weights define the order in which the form fields are shown. Lighter fields "float up" towards the top of the category.'));
+ $form['fields']['visibility'] = array(type => 'radios', title => t('Visibility'), default_value => $edit['visibility'], options => array(PROFILE_HIDDEN => t('Hidden profile field, only accessible by administrators, modules and themes.'), PROFILE_PRIVATE => t('Private field, content only available to privileged users.'), PROFILE_PUBLIC => t('Public field, content shown on profile page but not used on member list pages.'), PROFILE_PUBLIC_LISTINGS => t('Public field, content shown on profile page and on member list pages.')));
if ($type == 'selection' || $type == 'list') {
- $group .= form_textfield(t('Page title'), 'page', $edit['page'], 60, 128, t('The title of the page showing all users with the specified field. The word <code>%value</code> will be substituted with the corresponding value. An example page title is "People whose favorite color is %value". Only applicable if the field is configured to be shown on member list pages.'));
+ $form['fields']['page'] = array(type => 'textfield', title => t('Page title'), default_value => $edit['page'], size => 60, maxlength => 128, description => t('The title of the page showing all users with the specified field. The word <code>%value</code> will be substituted with the corresponding value. An example page title is "People whose favorite color is %value". Only applicable if the field is configured to be shown on member list pages.'));
}
else {
- $group .= form_textfield(t('Page title'), 'page', $edit['page'], 60, 128, t('The title of the page showing all users with the specified field. Only applicable if the field is configured to be shown on member listings.'));
+ $form['fields']['page'] = array(type => 'textfield', title => t('Page title'), default_value => $edit['page'], size => 60, maxlength => 128, description => t('The title of the page showing all users with the specified field. Only applicable if the field is configured to be shown on member listings.'));
}
- $group .= form_checkbox(t('The user must enter a value.'), 'required', 1, $edit['required']);
- $group .= form_checkbox(t('Visible in user registration form.'), 'register', 1, $edit['register']);
-
- $output = form_group(t('Field settings'), $group);
- $output .= form_submit(t('Save field'));
+ $form['fields']['required'] = array(type => 'checkbox', title => t('The user must enter a value.'), return_value => 1, default_value => $edit['required']);
+ $form['fields']['register'] = array(type => 'checkbox', title => t('Visible in user registration form.'), return_value => 1, default_value => $edit['register']);
+ $form['submit'] = array(type => 'submit', value => t('Save field'));
- return form($output);
+ return drupal_get_form('_profile_field_form', $form);
}
/**
diff --git a/modules/search.module b/modules/search.module
index a1f10df44..51286d631 100644
--- a/modules/search.module
+++ b/modules/search.module
@@ -96,11 +96,6 @@ function search_menu($may_cache) {
'callback' => 'search_view',
'access' => user_access('search content'),
'type' => MENU_SUGGESTED_ITEM);
-
- $items[] = array('path' => 'admin/settings/search', 'title' => t('search'),
- 'callback' => 'search_admin',
- 'type' => MENU_NORMAL_ITEM,
- 'access' => user_access('administer site configuration'));
}
else if (arg(0) == 'search') {
// To remember the user's search keywords when switching across tabs,
@@ -120,23 +115,21 @@ function search_menu($may_cache) {
return $items;
}
-
/**
- * Menu callback; displays the search module settings page.
+ * Implementation of hook_validate().
*/
-function search_admin() {
- if ($_POST) {
- // If the word length settings change, the index needs to be rebuilt.
- if (variable_get('minimum_word_size', 3) != $_POST['edit']['minimum_word_size']) {
- drupal_set_message(t('The index will be rebuilt.'));
- search_wipe();
- system_settings_save();
- }
- else {
- system_settings_save();
- }
+function search_settings_form_validate($form_id, &$form) {
+ // If the word length settings change, the index needs to be rebuilt.
+ if (variable_get('minimum_word_size', 3) != $form['minimum_word_size']) {
+ drupal_set_message(t('The index will be rebuilt.'));
+ search_wipe();
}
+}
+/**
+ * Menu callback; displays the search module settings page.
+ */
+function search_settings() {
// Collect some stats
$remaining = 0;
$total = 0;
@@ -150,19 +143,21 @@ function search_admin() {
$count = format_plural($remaining, 'There is 1 item left to index.', 'There are %count items left to index.');
$percentage = ((int)min(100, 100 * ($total - $remaining) / max(1, $total))) . '%';
$status = '<p><strong>'. t('%percentage of the site has been indexed.', array('%percentage' => $percentage)) .' '. $count .'</strong></p>';
- $output = form_group('Indexing status', $status);
+ $form['search_admin'] = array(type => 'fieldset', title => t('Indexing status'));
+ $form['search_admin']['status'] = array(type => 'markup', value => $status);
- // Indexing throttle:
$items = drupal_map_assoc(array(10, 20, 50, 100, 200, 500));
- $group = form_select(t('Items to index per cron run'), 'search_cron_limit', variable_get('search_cron_limit', 100), $items, t('The maximum amount of items that will be indexed in one cron run. Set this number lower if your cron is timing out or if PHP is running out of memory.'));
- $output .= form_group(t('Indexing throttle'), $group);
+
+ // Indexing throttle:
+ $form['indexing_throttle'] = array(type => 'fieldset', title => t('Indexing throttle'));
+ $form['indexing_throttle']['search_cron_limit'] = array(type => 'select', title => t('Items to index per cron run'), default_value => variable_get('search_cron_limit', 100), options => $items, description => t('The maximum amount of items that will be indexed in one cron run. Set this number lower if your cron is timing out or if PHP is running out of memory.'));
// Indexing settings:
- $group = '<em>'. t('<p>Changing the setting below will cause the site index to be rebuilt. The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\'t be indexed until all existing content has been re-indexed.</p><p>The default settings should be appropriate for the majority of sites.</p>') .'</em>';
- $group .= form_textfield(t('Minimum word length to index'), 'minimum_word_size', variable_get('minimum_word_size', 3), 5, 3, t('The number of characters a word has to be to be indexed. Words shorter than this will not be searchable.'));
- $group .= form_textfield(t('Minimum word length to search for'), 'remove_short', variable_get('remove_short', 3), 5, 3, t('The number of characters a word has to be to be searched for, including wildcard characters.'));
- $output .= form_group(t('Indexing settings'), $group);
+ $form['indexing_settings'] = array(type => 'fieldset', title => t('Indexing settings'));
+ $form['indexing_settings']['info'] = array(type => 'markup', value => '<em>'. t('<p>Changing the setting below will cause the site index to be rebuilt. The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\'t be indexed until all existing content has been re-indexed.</p><p>The default settings should be appropriate for the majority of sites.</p>') .'</em>');
+ $form['indexing_settings']['minimum_word_size'] = array(type => 'textfield', title => t('Minimum word length to index'), default_value => variable_get('minimum_word_size', 3), size => 5, maxlength => 3, description => t('The number of characters a word has to be to be indexed. Words shorter than this will not be searchable.'));
+ $form['indexing_settings']['remove_short'] = array(type => 'textfield', title => t('Minimum word length to search for'), default_value => variable_get('remove_short', 3), size => 5, maxlength => 3, description => t('The number of characters a word has to be to be searched for, including wildcard characters.'));
- return system_settings_form($output);
+ return $form;
}
/**
@@ -652,13 +647,21 @@ function search_form($action = '', $keys = '', $type = null, $prompt = null) {
$prompt = t('Enter your keywords');
}
- $box = '<div class="container-inline">';
- $box .= form_textfield('', 'keys', $keys, $prompt ? 40 : 30, 255);
- $box .= form_submit(t('Search'));
- $box .= '</div>';
- $output .= form_item($prompt, $box);
+ $form[action] = $action;
+ $form['prompt'] = array(type => 'item', title => $prompt);
+ $form['keys'] = array(type => 'textfield', title => '', default_value => $keys, size => $prompt ? 40 : 30, maxlength => 255);
+ $form['submit'] = array(type => 'submit', value => t('Search'));
+ $form[attributes] = array('class' => 'search-form');
- return form($output, 'post', $action, array('class' => 'search-form'));
+ return drupal_get_form('search_form', $form);
+}
+
+function theme_search_form($form) {
+ $output = form_render($form['prompt']);
+ $output .= '<div class="container-inline">';
+ $output .= form_render($form);
+ $output .= '</div>';
+ return $output;
}
/**
@@ -840,6 +843,3 @@ function theme_search_item($item, $type) {
return $output;
}
-
-
-
diff --git a/modules/search/search.module b/modules/search/search.module
index a1f10df44..51286d631 100644
--- a/modules/search/search.module
+++ b/modules/search/search.module
@@ -96,11 +96,6 @@ function search_menu($may_cache) {
'callback' => 'search_view',
'access' => user_access('search content'),
'type' => MENU_SUGGESTED_ITEM);
-
- $items[] = array('path' => 'admin/settings/search', 'title' => t('search'),
- 'callback' => 'search_admin',
- 'type' => MENU_NORMAL_ITEM,
- 'access' => user_access('administer site configuration'));
}
else if (arg(0) == 'search') {
// To remember the user's search keywords when switching across tabs,
@@ -120,23 +115,21 @@ function search_menu($may_cache) {
return $items;
}
-
/**
- * Menu callback; displays the search module settings page.
+ * Implementation of hook_validate().
*/
-function search_admin() {
- if ($_POST) {
- // If the word length settings change, the index needs to be rebuilt.
- if (variable_get('minimum_word_size', 3) != $_POST['edit']['minimum_word_size']) {
- drupal_set_message(t('The index will be rebuilt.'));
- search_wipe();
- system_settings_save();
- }
- else {
- system_settings_save();
- }
+function search_settings_form_validate($form_id, &$form) {
+ // If the word length settings change, the index needs to be rebuilt.
+ if (variable_get('minimum_word_size', 3) != $form['minimum_word_size']) {
+ drupal_set_message(t('The index will be rebuilt.'));
+ search_wipe();
}
+}
+/**
+ * Menu callback; displays the search module settings page.
+ */
+function search_settings() {
// Collect some stats
$remaining = 0;
$total = 0;
@@ -150,19 +143,21 @@ function search_admin() {
$count = format_plural($remaining, 'There is 1 item left to index.', 'There are %count items left to index.');
$percentage = ((int)min(100, 100 * ($total - $remaining) / max(1, $total))) . '%';
$status = '<p><strong>'. t('%percentage of the site has been indexed.', array('%percentage' => $percentage)) .' '. $count .'</strong></p>';
- $output = form_group('Indexing status', $status);
+ $form['search_admin'] = array(type => 'fieldset', title => t('Indexing status'));
+ $form['search_admin']['status'] = array(type => 'markup', value => $status);
- // Indexing throttle:
$items = drupal_map_assoc(array(10, 20, 50, 100, 200, 500));
- $group = form_select(t('Items to index per cron run'), 'search_cron_limit', variable_get('search_cron_limit', 100), $items, t('The maximum amount of items that will be indexed in one cron run. Set this number lower if your cron is timing out or if PHP is running out of memory.'));
- $output .= form_group(t('Indexing throttle'), $group);
+
+ // Indexing throttle:
+ $form['indexing_throttle'] = array(type => 'fieldset', title => t('Indexing throttle'));
+ $form['indexing_throttle']['search_cron_limit'] = array(type => 'select', title => t('Items to index per cron run'), default_value => variable_get('search_cron_limit', 100), options => $items, description => t('The maximum amount of items that will be indexed in one cron run. Set this number lower if your cron is timing out or if PHP is running out of memory.'));
// Indexing settings:
- $group = '<em>'. t('<p>Changing the setting below will cause the site index to be rebuilt. The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\'t be indexed until all existing content has been re-indexed.</p><p>The default settings should be appropriate for the majority of sites.</p>') .'</em>';
- $group .= form_textfield(t('Minimum word length to index'), 'minimum_word_size', variable_get('minimum_word_size', 3), 5, 3, t('The number of characters a word has to be to be indexed. Words shorter than this will not be searchable.'));
- $group .= form_textfield(t('Minimum word length to search for'), 'remove_short', variable_get('remove_short', 3), 5, 3, t('The number of characters a word has to be to be searched for, including wildcard characters.'));
- $output .= form_group(t('Indexing settings'), $group);
+ $form['indexing_settings'] = array(type => 'fieldset', title => t('Indexing settings'));
+ $form['indexing_settings']['info'] = array(type => 'markup', value => '<em>'. t('<p>Changing the setting below will cause the site index to be rebuilt. The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\'t be indexed until all existing content has been re-indexed.</p><p>The default settings should be appropriate for the majority of sites.</p>') .'</em>');
+ $form['indexing_settings']['minimum_word_size'] = array(type => 'textfield', title => t('Minimum word length to index'), default_value => variable_get('minimum_word_size', 3), size => 5, maxlength => 3, description => t('The number of characters a word has to be to be indexed. Words shorter than this will not be searchable.'));
+ $form['indexing_settings']['remove_short'] = array(type => 'textfield', title => t('Minimum word length to search for'), default_value => variable_get('remove_short', 3), size => 5, maxlength => 3, description => t('The number of characters a word has to be to be searched for, including wildcard characters.'));
- return system_settings_form($output);
+ return $form;
}
/**
@@ -652,13 +647,21 @@ function search_form($action = '', $keys = '', $type = null, $prompt = null) {
$prompt = t('Enter your keywords');
}
- $box = '<div class="container-inline">';
- $box .= form_textfield('', 'keys', $keys, $prompt ? 40 : 30, 255);
- $box .= form_submit(t('Search'));
- $box .= '</div>';
- $output .= form_item($prompt, $box);
+ $form[action] = $action;
+ $form['prompt'] = array(type => 'item', title => $prompt);
+ $form['keys'] = array(type => 'textfield', title => '', default_value => $keys, size => $prompt ? 40 : 30, maxlength => 255);
+ $form['submit'] = array(type => 'submit', value => t('Search'));
+ $form[attributes] = array('class' => 'search-form');
- return form($output, 'post', $action, array('class' => 'search-form'));
+ return drupal_get_form('search_form', $form);
+}
+
+function theme_search_form($form) {
+ $output = form_render($form['prompt']);
+ $output .= '<div class="container-inline">';
+ $output .= form_render($form);
+ $output .= '</div>';
+ return $output;
}
/**
@@ -840,6 +843,3 @@ function theme_search_item($item, $type) {
return $output;
}
-
-
-
diff --git a/modules/statistics.module b/modules/statistics.module
index 0080a057d..3227b7606 100644
--- a/modules/statistics.module
+++ b/modules/statistics.module
@@ -325,18 +325,18 @@ function statistics_top_referrers() {
*/
function statistics_settings() {
// access log settings:
- $group = form_radios(t('Enable access log'), 'statistics_enable_access_log', variable_get('statistics_enable_access_log', 0), array('1' => t('Enabled'), '0' => t('Disabled')), t('Log each page access. Required for referrer statistics.'));
-
+ $options = array('1' => t('Enabled'), '0' => t('Disabled'));
+ $form['access'] = array(type => 'fieldset', title => t('Access log settings'));
+ $form['access']['statistics_enable_access_log'] = array(type => 'radios', title => t('Enable access log'), default_value => variable_get('statistics_enable_access_log', 0), options => $options, description => t('Log each page access. Required for referrer statistics.'));
$period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');
- $group .= form_select(t('Discard access logs older than'), 'statistics_flush_accesslog_timer', variable_get('statistics_flush_accesslog_timer', 259200), $period, t('Older access log entries (including referrer statistics) will be automatically discarded. Requires crontab.'));
- $output = form_group(t('Access log settings'), $group);
-
+ $form['access']['statistics_flush_accesslog_timer'] = array(type => 'select', title => t('Discard access logs older than'), default_value => variable_get('statistics_flush_accesslog_timer', 259200), options => $period, description => t('Older access log entries (including referrer statistics) will be automatically discarded. Requires crontab.'));
+
// count content views settings
- $group = form_radios(t('Count content views'), 'statistics_count_content_views', variable_get('statistics_count_content_views', 0), array('1' => t('Enabled'), '0' => t('Disabled')), t('Increment a counter each time content is viewed.'));
- $group .= form_radios(t('Display counter values'), 'statistics_display_counter', variable_get('statistics_display_counter', 0), array('1' => t('Enabled'), '0' => t('Disabled')), t('Display how many times given content has been viewed.'));
- $output .= form_group(t('Content viewing counter settings'), $group);
+ $form['content'] = array(type => 'fieldset', title => t('Content viewing counter settings'));
+ $form['content']['statistics_count_content_views'] = array(type => 'radios', title => t('Count content views'), default_value => variable_get('statistics_count_content_views', 0), options => $options, description => t('Increment a counter each time content is viewed.'));
+ $form['content']['statistics_display_counter'] = array(type => 'radios', title => t('Display counter values'), default_value => variable_get('statistics_display_counter', 0), options => $options, description => t('Display how many times given content has been viewed.'));
- return $output;
+ return $form;
}
/**
@@ -413,10 +413,10 @@ function statistics_block($op = 'list', $delta = 0, $edit = array()) {
case 'configure':
// Popular content block settings
$numbers = array('0' => t('Disabled')) + drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40));
- $output = form_select(t("Number of day's top views to display"), 'statistics_block_top_day_num', variable_get('statistics_block_top_day_num', 0), $numbers, t('How many content items to display in "day" list.'));
- $output .= form_select(t('Number of all time views to display'), 'statistics_block_top_all_num', variable_get('statistics_block_top_all_num', 0), $numbers, t('How many content items to display in "all time" list.'));
- $output .= form_select(t('Number of most recent views to display'), 'statistics_block_top_last_num', variable_get('statistics_block_top_last_num', 0), $numbers, t('How many content items to display in "recently viewed" list.'));
- return $output;
+ $form['statistics_block_top_day_num'] = array(type => 'select', title => t("Number of day's top views to display"), default_value => variable_get('statistics_block_top_day_num', 0), options => $numbers, description => t('How many content items to display in "day" list.'));
+ $form['statistics_block_top_all_num'] = array(type => 'select', title => t('Number of all time views to display'), default_value => variable_get('statistics_block_top_all_num', 0), options => $numbers, description => t('How many content items to display in "all time" list.'));
+ $form['statistics_block_top_last_num'] = array(type => 'select', title => t('Number of most recent views to display'), default_value => variable_get('statistics_block_top_last_num', 0), options => $numbers, description => t('How many content items to display in "recently viewed" list.'));
+ return $form;
case 'save':
variable_set('statistics_block_top_day_num', $edit['statistics_block_top_day_num']);
diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module
index 0080a057d..3227b7606 100644
--- a/modules/statistics/statistics.module
+++ b/modules/statistics/statistics.module
@@ -325,18 +325,18 @@ function statistics_top_referrers() {
*/
function statistics_settings() {
// access log settings:
- $group = form_radios(t('Enable access log'), 'statistics_enable_access_log', variable_get('statistics_enable_access_log', 0), array('1' => t('Enabled'), '0' => t('Disabled')), t('Log each page access. Required for referrer statistics.'));
-
+ $options = array('1' => t('Enabled'), '0' => t('Disabled'));
+ $form['access'] = array(type => 'fieldset', title => t('Access log settings'));
+ $form['access']['statistics_enable_access_log'] = array(type => 'radios', title => t('Enable access log'), default_value => variable_get('statistics_enable_access_log', 0), options => $options, description => t('Log each page access. Required for referrer statistics.'));
$period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');
- $group .= form_select(t('Discard access logs older than'), 'statistics_flush_accesslog_timer', variable_get('statistics_flush_accesslog_timer', 259200), $period, t('Older access log entries (including referrer statistics) will be automatically discarded. Requires crontab.'));
- $output = form_group(t('Access log settings'), $group);
-
+ $form['access']['statistics_flush_accesslog_timer'] = array(type => 'select', title => t('Discard access logs older than'), default_value => variable_get('statistics_flush_accesslog_timer', 259200), options => $period, description => t('Older access log entries (including referrer statistics) will be automatically discarded. Requires crontab.'));
+
// count content views settings
- $group = form_radios(t('Count content views'), 'statistics_count_content_views', variable_get('statistics_count_content_views', 0), array('1' => t('Enabled'), '0' => t('Disabled')), t('Increment a counter each time content is viewed.'));
- $group .= form_radios(t('Display counter values'), 'statistics_display_counter', variable_get('statistics_display_counter', 0), array('1' => t('Enabled'), '0' => t('Disabled')), t('Display how many times given content has been viewed.'));
- $output .= form_group(t('Content viewing counter settings'), $group);
+ $form['content'] = array(type => 'fieldset', title => t('Content viewing counter settings'));
+ $form['content']['statistics_count_content_views'] = array(type => 'radios', title => t('Count content views'), default_value => variable_get('statistics_count_content_views', 0), options => $options, description => t('Increment a counter each time content is viewed.'));
+ $form['content']['statistics_display_counter'] = array(type => 'radios', title => t('Display counter values'), default_value => variable_get('statistics_display_counter', 0), options => $options, description => t('Display how many times given content has been viewed.'));
- return $output;
+ return $form;
}
/**
@@ -413,10 +413,10 @@ function statistics_block($op = 'list', $delta = 0, $edit = array()) {
case 'configure':
// Popular content block settings
$numbers = array('0' => t('Disabled')) + drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40));
- $output = form_select(t("Number of day's top views to display"), 'statistics_block_top_day_num', variable_get('statistics_block_top_day_num', 0), $numbers, t('How many content items to display in "day" list.'));
- $output .= form_select(t('Number of all time views to display'), 'statistics_block_top_all_num', variable_get('statistics_block_top_all_num', 0), $numbers, t('How many content items to display in "all time" list.'));
- $output .= form_select(t('Number of most recent views to display'), 'statistics_block_top_last_num', variable_get('statistics_block_top_last_num', 0), $numbers, t('How many content items to display in "recently viewed" list.'));
- return $output;
+ $form['statistics_block_top_day_num'] = array(type => 'select', title => t("Number of day's top views to display"), default_value => variable_get('statistics_block_top_day_num', 0), options => $numbers, description => t('How many content items to display in "day" list.'));
+ $form['statistics_block_top_all_num'] = array(type => 'select', title => t('Number of all time views to display'), default_value => variable_get('statistics_block_top_all_num', 0), options => $numbers, description => t('How many content items to display in "all time" list.'));
+ $form['statistics_block_top_last_num'] = array(type => 'select', title => t('Number of most recent views to display'), default_value => variable_get('statistics_block_top_last_num', 0), options => $numbers, description => t('How many content items to display in "recently viewed" list.'));
+ return $form;
case 'save':
variable_set('statistics_block_top_day_num', $edit['statistics_block_top_day_num']);
diff --git a/modules/story.module b/modules/story.module
index 517d53b9e..df70e9fdd 100644
--- a/modules/story.module
+++ b/modules/story.module
@@ -74,16 +74,25 @@ function story_validate(&$node) {
* Implementation of hook_form().
*/
function story_form(&$node) {
- $output = form_textfield(t('Title'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
+
+ $form['title'] = array(type => 'textfield', title => t('Title'), size => 60, maxlength => 128, required => TRUE, default_value => $node->title);
if (function_exists('taxonomy_node_form')) {
- $output .= implode('', taxonomy_node_form('story', $node));
+ $form['taxonomy'] = taxonomy_node_form('story', $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, rows => 5,
+ description => t('An explanation of the additions or updates being made to help other authors understand your motivations.')
+ );
- return $output;
+ return $form;
}
diff --git a/modules/story/story.module b/modules/story/story.module
index 517d53b9e..df70e9fdd 100644
--- a/modules/story/story.module
+++ b/modules/story/story.module
@@ -74,16 +74,25 @@ function story_validate(&$node) {
* Implementation of hook_form().
*/
function story_form(&$node) {
- $output = form_textfield(t('Title'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
+
+ $form['title'] = array(type => 'textfield', title => t('Title'), size => 60, maxlength => 128, required => TRUE, default_value => $node->title);
if (function_exists('taxonomy_node_form')) {
- $output .= implode('', taxonomy_node_form('story', $node));
+ $form['taxonomy'] = taxonomy_node_form('story', $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, rows => 5,
+ description => t('An explanation of the additions or updates being made to help other authors understand your motivations.')
+ );
- return $output;
+ return $form;
}
diff --git a/modules/system.module b/modules/system.module
index 56c648273..8b5a2338b 100644
--- a/modules/system.module
+++ b/modules/system.module
@@ -50,6 +50,37 @@ function system_perm() {
}
/**
+ * 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', execute => TRUE);
+ $type['button'] = array(input => TRUE, name => 'op', button_type => 'submit', exexute => FALSE);
+ $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', tree => TRUE);
+ $type['select'] = array(input => TRUE);
+ $type['weight'] = array(input => TRUE, delta => 10);
+ $type['date'] = array(input => TRUE, process => 'expand_date');
+ $type['file'] = array(input => TRUE, size => 60);
+
+ // Form structure
+ $type['item'] = array();
+ $type['hidden'] = array(input => TRUE);
+ $type['value'] = 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) {
@@ -130,40 +161,38 @@ function system_user($type, $edit, &$user, $category = NULL) {
$themes = list_themes();
ksort($themes);
- if (count($themes) > 1) {
- $rows = array();
- foreach ($themes as $key => $value) {
- $row = array();
-
- // Screenshot column.
- $screenshot = dirname($value->filename) .'/screenshot.png';
- $row[] = file_exists($screenshot) ? theme('image', $screenshot, t('Screenshot for %theme theme', array('%theme' => $value->name)), '', array('class' => 'screenshot')) : t('no screenshot');
-
- // Information field.
- $row[] = '<strong>'. $value->name .'</strong>';
+ // Reset to follow site default theme if user selects the site default
+ if ($key == variable_get('theme_default', 'bluemarine')) {
+ $key = '';
+ if ($edit['theme'] == variable_get('theme_default', 'bluemarine')) {
+ $edit['theme'] = '';
+ }
+ }
- // Reset to follow site default theme if user selects the site default
- if ($key == variable_get('theme_default', 'bluemarine')) {
- $key = '';
- if ($edit['theme'] == variable_get('theme_default', 'bluemarine')) {
- $edit['theme'] = '';
- }
- }
+ $form['themes'] = array(
+ type => 'fieldset', title => t('Theme configuration'), description => t('Selecting a different theme will change the look and feel of the site.'), weight => 2, collapsible => TRUE, collapsed => FALSE
+ );
- // Selected column.
- $row[] = array('data' => form_radio('', 'theme', $key, ($edit['theme'] == $key) ? 1 : 0), 'align' => 'center');
+ 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');
- $rows[] = $row;
- }
- $header = array(t('Screenshot'), t('Name'), t('Selected'));
- $data[] = array('title' => t('Theme settings'), 'data' => form_item('', theme('table', $header, $rows), t('Selecting a different theme will change the look and feel of the site.')), 'weight' => 2);
+ $form['themes'][$info->name]['screenshot'] = array(type => 'markup', value => $screenshot);
+ $form['themes'][$info->name]['description'] = array(type => 'item', title => $info->name, value => dirname($info->filename));
+ $options[$info->name] = '';
}
+ $form['themes']['theme'] = array(type => 'radios', options => $options, default_value => $edit['theme']);
+
if (variable_get('configurable_timezones', 1)) {
$zones = _system_zonelist();
- $data[] = array('title' => t('Locale settings'), 'data' => form_select(t('Time zone'), 'timezone', strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0), $zones, t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.')), 'weight' => 2);
+ $form['locale'] = array(type=>'item', title => t('Locale settings'), weight => 6);
+ $form['locale']['timezone'] = array(
+ type => 'select', title => t('Time zone'), default_value => strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0),
+ options => $zones, descriptions => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.')
+ );
}
- return $data;
+ return $form;
}
}
@@ -180,69 +209,149 @@ function _system_zonelist() {
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 <code>?q=</code> in the URL). You\'ll need <code>ModRewrite</code> support for this to work. See the <code>.htaccess</code> 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 <code>?q=</code> in the URL). You\'ll need <code>ModRewrite</code> support for this to work. See the <code>.htaccess</code> 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 .= '<img style="position: relative; left: -1000em;" src="'. $base_url. '/system/test/'. user_password(20) .'.png" alt="" />';
-
- $output = form_group_collapsible(t('General settings'), $group, TRUE);
+ $form['general']['clean_url_test'] = array(type => 'markup', value => '<img style="position: relative; left: -1000em;" src="'. $base_url. '/system/test/'. user_password(20) .'.png" alt="" />');
// 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');
- $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 <em>private</em>. 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);
+ $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 <em>private</em>. You can change this at any time, however all download URLs will change and there may be unexpected problems so it is not recommended.')
+ );
+ /*
// 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'] = array(
+ type => 'radios', title => t('Select an image processing toolkit'),
+ default_value => variable_get('image_toolkit', image_get_toolkit()), options => $toolkits_available
+ );
}
- $group .= image_toolkit_invoke('settings');
- if ($group) {
- $output .= form_group_collapsible(t('Image handling'), '<p>'. $group .'</p>', TRUE);
+ $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);
}
+ */
// Feed settings
- $group = '';
- $group .= form_select(t('Number of items per feed'), 'feed_default_items', variable_get('feed_default_items', 10), drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)), t('The default number of items to include in a feed.'));
- $group .= form_select(t('Display of XML feed items'), 'feed_item_length', variable_get('feed_item_length','teaser'), array('title' => t('Titles only'), 'teaser' => t('Titles plus teaser'), 'fulltext' => t('Full text')), t('Global setting for the length of XML feed items that are output by default.'));
- $output .= form_group_collapsible(t('RSS feed settings'), $group, TRUE);
+ $form['feed'] = array(type => 'fieldset', title => t('RSS feed settings'), collapsible => TRUE, collapsed => TRUE);
+ $form['feed']['feed_default_items'] = array(
+ type => 'select', title => t('Number of items per feed'), default_value => variable_get('feed_default_items', 10),
+ options => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
+ description => t('The default number of items to include in a feed.')
+ );
+ $form['feed']['feed_item_length'] = array(
+ type => 'select', title => t('Display of XML feed items'), default_value => variable_get('feed_item_length','teaser'),
+ options => array('title' => t('Titles only'), 'teaser' => t('Titles plus teaser'), 'fulltext' => t('Full text')),
+ description => t('Global setting for the length of XML feed items that are output by default.')
+ );
// Date settings:
$zones = _system_zonelist();
@@ -270,19 +379,44 @@ function system_view_general() {
$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'] = array_merge($form['strings'], unicode_settings());
- return $output;
+ return $form;
}
/**
@@ -471,44 +605,164 @@ function system_listing($mask, $directory, $key = 'name', $min_depth = 1) {
}
/**
- * Generate a list of all the available theme/style combinations.
+ * Assign an initial, default set of blocks for a theme.
+ *
+ * This function is called the first time a new theme is enabled. The new theme
+ * gets a copy of the default theme's blocks, with the difference that if a
+ * particular region isn't available in the new theme, the block is assigned
+ * to the new theme's default region.
+ *
+ * @param $theme
+ * The name of a theme.
+ */
+function system_initialize_theme_blocks($theme) {
+ // Initialize theme's blocks if none already registered.
+ if (!(db_num_rows(db_query("SELECT module FROM {blocks} WHERE theme = '%s'", $theme)))) {
+ $default_theme = variable_get('theme_default', 'bluemarine');
+ $regions = system_region_list($theme);
+ $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $default_theme);
+ while($block = db_fetch_array($result)) {
+ // If the region isn't supported by the theme, assign the block to the theme's default region.
+ if (!array_key_exists($block['region'], $regions)) {
+ $block['region'] = system_default_region($theme);
+ }
+ db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d)",
+ $block['module'], $block['delta'], $theme, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle']);
+ }
+ }
+}
+
+// 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 drupal_get_form($form_id, $form, 'system_settings_form');
+}
+
+/**
+ * Execute the system_settings_form.
+ *
+ * Due to specific handling of checkboxes, this function does not handle 'tree' based forms.
+ */
+function system_settings_form_execute($form_id, $values) {
+ $op = isset($_POST['op']) ? $_POST['op'] : '';
+
+ foreach ($values as $key => $value) {
+ if ($op == t('Reset to defaults')) {
+ variable_del($key);
+ }
+ else {
+ if (is_array($value)) {
+ $value = array_keys(array_filter($value));
+ }
+ variable_set($key, $value);
+ }
+ }
+ if ($op == t('Reset to defaults')) {
+ drupal_set_message(t('The configuration options have been reset to their default values.'));
+ } else {
+ drupal_set_message(t('The configuration options have been saved.'));
+ }
+}
+
+/**
+ * Do the clean url validation, changing the form property if it doesn't work.
*/
-function system_theme_listing() {
+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 <code>ModRewrite</code> support with your administrator.'), 'error');
+ $edit['clean_url'] = 0;
+ }
+
+}
+
+
+
+
+/**
+ * Menu callback; displays a listing of all themes.
+ */
+function system_themes() {
$themes = system_theme_data();
ksort($themes);
foreach ($themes as $info) {
$info->screenshot = dirname($info->filename) . '/screenshot.png';
- $row = array();
-
- // Screenshot column.
- $row[] = file_exists($info->screenshot) ? theme('image', $info->screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot')) : t('no screenshot');
-
- // Information field.
- $row[] = "<strong>$info->name</strong><br /><em>" . dirname($info->filename) . '</em>';
+ $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');
- // enabled, default, and operations columns
- $row[] = array('data' => form_checkbox('', 'status]['. $info->name, 1, $info->status), 'align' => 'center');
- $row[] = array('data' => form_radio('', 'theme_default', $info->name, (variable_get('theme_default', 'bluemarine') == $info->name) ? 1 : 0), 'align' => 'center');
+ $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'))) {
- $row[] = array('data' => l(t('configure'), 'admin/themes/settings/' . $info->name), 'align' => 'center');
+ $form[$info->name]['operations'] = array(type => 'markup', value => l(t('configure'), 'admin/themes/settings/' . $info->name) );
}
else {
- $row[] = '';
+ // 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 (element_children($form) as $key) {
+ $row = array();
+ if (is_array($form[$key]['description'])) {
+ $row[] = form_render($form[$key]['screenshot']);
+ $row[] = form_render($form[$key]['description']);
+ $row[] = array('data' => form_render($form['status'][$key]), 'align' => 'center');
+ if ($form['theme_default']) {
+ $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 = form_hidden('type', 'theme');
- $output .= theme('table', $header, $rows);
+ $output = theme('table', $header, $rows);
+ $output .= form_render($form);
return $output;
}
+
+function system_themes_execute($form_id, $values) {
+
+ db_query("UPDATE {system} SET status = 0 WHERE type = 'theme'");
+
+ if ($_POST['op'] == t('Save configuration')) {
+ variable_set('theme_default', $values['theme_default']);
+ if (is_array($values['status'])) {
+ foreach ($values['status'] as $key => $choice) {
+ if ($choice) {
+ db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' and name = '%s'", $key);
+ }
+ }
+ }
+ }
+ else {
+ variable_del('theme_default');
+ }
+
+ drupal_set_message(t('The configuration options have been saved.'));
+ drupal_goto('admin/themes');
+}
+
/**
- * Generate a list of all the available modules, as well as update the system list.
+ * Menu callback; displays a listing of all modules.
*/
-function system_module_listing() {
+function system_modules() {
// Get current list of modules
$files = system_listing('\.module$', 'modules', 'name', 0);
@@ -517,20 +771,22 @@ function system_module_listing() {
ksort($files);
- $required = array('block', 'filter', 'system', 'user', 'watchdog');
- $throttle_required = array_merge($required, array('throttle'));
-
- $header = array(t('Name'), t('Description'), t('Enabled'));
- if (module_exist('throttle')) {
- $header[] = t('Throttle');
- }
-
foreach ($files as $filename => $file) {
drupal_get_filename('module', $file->name, $file->filename);
drupal_load('module', $file->name);
$file->description = module_invoke($file->name, 'help', 'admin/modules#description');
+ $form['name'][$file->name] = array(value => $file->name);
+ $form['description'][$file->name] = array(value => $file->description);
+ $options[$file->name] = '';
+ if ($file->status) {
+ $status[] = $file->name;
+ }
+ if ($file->throttle) {
+ $throttle[] = $file->name;
+ }
+
// log the critical hooks implemented by this module
$bootstrap = 0;
foreach (bootstrap_hooks() as $hook) {
@@ -543,155 +799,104 @@ function system_module_listing() {
// Update the contents of the system table:
db_query("DELETE FROM {system} WHERE name = '%s' AND type = '%s'", $file->name, 'module');
db_query("INSERT INTO {system} (name, description, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', %d, %d, %d)", $file->name, $file->description, 'module', $file->filename, $file->status, $file->throttle, $bootstrap);
-
- $row = array($file->name, $file->description, array('data' => (in_array($file->name, $required) ? form_hidden("status][$file->name", 1) . t('required') : form_checkbox('', "status][$file->name", 1, $file->status)), 'align' => 'center'));
- if (module_exist('throttle')) {
- $row[] = array('data' => (in_array($file->name, $throttle_required) ? form_hidden("throttle][$file->name", 0) . t('required') : form_checkbox(NULL, "throttle][$file->name", 1, $file->throttle, NULL)), 'align' => 'center');
- }
- $rows[] = $row;
}
- $output = theme('table', $header, $rows);
- $output .= form_hidden('type', 'module');
-
- return $output;
-}
-
-function system_listing_save($edit = array()) {
- $op = $_POST['op'];
- $edit = $_POST['edit'];
-
- if ($op == t('Save configuration')) {
- db_query("UPDATE {system} SET status = 0 WHERE type = '%s'", $edit['type']);
- foreach ($edit['status'] as $name => $status) {
- // Make certain that the default theme is enabled to avoid user error
- if (($edit['type'] == 'theme') && ($edit['theme_default'] == $name)) {
- $status = 1;
- }
- // If status is being set to 1 from 0, initialize block data for this theme if necessary.
- if (($edit['type'] == 'theme') && ($status == 1) && db_num_rows(db_query("SELECT status FROM {system} WHERE type = '%s' AND name = '%s' AND status = 0", $edit['type'], $name))) {
- system_initialize_theme_blocks($name);
- }
- db_query("UPDATE {system} SET status = %d, throttle = %d WHERE type = '%s' AND name = '%s'", $status, $edit['throttle'][$name], $edit['type'], $name);
- }
+ /**
+ * Handle status checkboxes, including overriding the generated checkboxes for required modules.
+ */
+ $form['status'] = array(type => 'checkboxes', default_value => $status, options => $options, tree => TRUE);
+ $required = array('block', 'filter', 'system', 'user', 'watchdog');
+ foreach ($required as $require) {
+ $form['status'][$require] = array(type => 'hidden', value => 1, suffix => t('required'));
+ }
- if ($edit['type'] == 'theme') {
- variable_set('theme_default', $edit['theme_default']);
+ /**
+ * Handle throttle checkboxes, including overriding the generated checkboxes for required modules.
+ */
+ if (module_exist('throttle')) {
+ $form['throttle'] = array(type => 'checkboxes', default_value => $throttle, options => $options, tree => TRUE);
+ $throttle_required = array_merge($required, array('throttle'));
+ foreach ($throttle_required as $require) {
+ $form['throttle'][$require] = array(type => 'hidden', value => 1, suffix => t('required'));
}
+ }
- menu_rebuild();
+ $form['buttons']['submit'] = array(type => 'submit', value => t('Save configuration'));
- drupal_set_message(t('The configuration options have been saved.'));
- drupal_goto($_GET['q']);
- }
+ return drupal_get_form('system_modules', $form);
}
-/**
- * Assign an initial, default set of blocks for a theme.
- *
- * This function is called the first time a new theme is enabled. The new theme
- * gets a copy of the default theme's blocks, with the difference that if a
- * particular region isn't available in the new theme, the block is assigned
- * to the new theme's default region.
- *
- * @param $theme
- * The name of a theme.
- */
-function system_initialize_theme_blocks($theme) {
- // Initialize theme's blocks if none already registered.
- if (!(db_num_rows(db_query("SELECT module FROM {blocks} WHERE theme = '%s'", $theme)))) {
- $default_theme = variable_get('theme_default', 'bluemarine');
- $regions = system_region_list($theme);
- $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $default_theme);
- while($block = db_fetch_array($result)) {
- // If the region isn't supported by the theme, assign the block to the theme's default region.
- if (!array_key_exists($block['region'], $regions)) {
- $block['region'] = system_default_region($theme);
- }
- db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d)",
- $block['module'], $block['delta'], $theme, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle']);
+
+function theme_system_modules($form) {
+ foreach (element_children($form['name']) as $key) {
+ $row = array();
+ $row[] = form_render($form['name'][$key]);
+ $row[] = form_render($form['description'][$key]);
+ $row[] = array('data' => form_render($form['status'][$key]), 'align' => 'center');
+
+ if (module_exist('throttle')) {
+ $row[] = array('data' => form_render($form['throttle'][$key]), 'align' => 'center');
}
+ $rows[] = $row;
}
-}
-function system_settings_form($form) {
- $form .= form_submit(t('Save configuration'));
- $form .= form_submit(t('Reset to defaults'));
+ $header = array(t('Name'), t('Description'), t('Enabled'));
+ if (module_exist('throttle')) {
+ $header[] = t('Throttle');
+ }
- return form($form);
+ $output = theme('table', $header, $rows);
+ $output .= form_render($form);
+ return $output;
}
-function system_settings_save() {
- $op = $_POST['op'];
- $edit = $_POST['edit'];
- if ($op == t('Reset to defaults')) {
- if (is_array($edit)) {
- foreach ($edit as $name => $value) {
- variable_del($name);
- }
+function system_modules_execute($form_id, $edit) {
+ db_query("update {system} set status = 0, throttle = 0 where type = 'module'");
+
+ foreach ($edit['status'] as $key => $choice) {
+ if ($choice) {
+ db_query("update {system} set status = 1 where type = 'module' and name = '%s'", $key);
}
- 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 <code>ModRewrite</code> support with your administrator.'), 'error');
- $edit['clean_url'] = 0;
- }
- foreach ($edit as $name => $value) {
- variable_set($name, $value);
+
+ if (is_array($edit['throttle'])) {
+ foreach ($edit['throttle'] as $key => $choice) {
+ if ($choice) {
+ db_query("UPDATE {system} SET throttle = 1 WHERE type = 'module' and name = '%s'", $key);
}
}
- drupal_set_message(t('The configuration options have been saved.'));
}
- else {
- return;
- }
- menu_rebuild();
- drupal_goto($_GET['q']);
-}
-/**
- * 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);
+ menu_rebuild();
+ drupal_set_message(t('The configuration options have been saved.'));
+ drupal_goto('admin/modules');
}
-/**
- * Menu callback; displays a listing of all modules.
- */
-function system_modules() {
- system_listing_save();
- $form = system_module_listing();
- $form .= form_submit(t('Save configuration'));
- return form($form);
-}
/**
* 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);
}
/**
* Menu callback; display theme configuration for entire site and individual themes.
*/
function system_theme_settings($key = '') {
+ $directory_path = variable_get('file_directory_path', 'files');
+ file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
+
// Default settings are defined in theme_get_settings() in includes/theme.inc
if ($key) {
$settings = theme_get_settings($key);
@@ -704,6 +909,8 @@ function system_theme_settings($key = '') {
$var = 'theme_settings';
}
+ $form['var'] = array(type => 'hidden', value => $var);
+
// Check for a new uploaded logo, and use that instead.
if ($file = file_check_upload('logo_upload')) {
if ($info = image_get_info($file->filepath)) {
@@ -711,8 +918,8 @@ function system_theme_settings($key = '') {
$filename = ($key) ? str_replace('/', '_', $key) . '_logo.' . $parts['extension'] : 'logo.' . $parts['extension'];
if ($file = file_save_upload('logo_upload', $filename, 1)) {
- $_POST['edit'][$var]['default_logo'] = 0;
- $_POST['edit'][$var]['logo_path'] = $file->filepath;
+ $_POST['edit']['default_logo'] = 0;
+ $_POST['edit']['logo_path'] = $file->filepath;
}
}
else {
@@ -726,90 +933,62 @@ function system_theme_settings($key = '') {
$filename = ($key) ? str_replace('/', '_', $key) . '_favicon.' . $parts['extension'] : 'favicon.' . $parts['extension'];
if ($file = file_save_upload('favicon_upload', $filename, 1)) {
- $_POST['edit'][$var]['default_favicon'] = 0;
- $_POST['edit'][$var]['favicon_path'] = $file->filepath;
+ $_POST['edit']['default_favicon'] = 0;
+ $_POST['edit']['favicon_path'] = $file->filepath;
}
}
- system_settings_save();
-
- $form = '';
// Logo settings
if ((!$key) || in_array('logo', $features)) {
- $group = form_checkbox(t('Use the default logo'), "$var][default_logo", 1, $settings['default_logo'], t('Check here if you want the theme to use the logo supplied with it.'));
- $group .= form_textfield(t('Path to custom logo'), "$var][logo_path", $settings['logo_path'], 60, 128, t('The path to the file you would like to use as your logo file instead of the default logo.'));
-
- $directory_path = variable_get('file_directory_path', 'files');
- file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
- $group .= form_file(t('Upload logo image'), 'logo_upload', 40, t("If you don't have direct file access to the server, use this field to upload your logo."));
-
- $form .= form_group(t('Logo image settings'), $group);
+ $form['logo'] = array(type => 'fieldset', title => t('Logo image settings'));
+ $form['logo']["default_logo"] = array(
+ type => 'checkbox', title => t('Use the default logo'), default_value => $settings['default_logo'], tree => FALSE,
+ description => t('Check here if you want the theme to use the logo supplied with it.')
+ );
+ $form['logo']['logo_path'] = array(
+ type => 'textfield', title => t('Path to custom logo'), size => 60, maxlength => 128,
+ description => t('The path to the file you would like to use as your logo file instead of the default logo.'));
+
+ $form['logo']['logo_upload'] = array(
+ type => 'file', title => t('Upload logo image'), maxlength => 40,
+ description => t("If you don't have direct file access to the server, use this field to upload your logo.")
+ );
}
// Icon settings
if ((!$key) || in_array('toggle_favicon', $features)) {
- $group = t('Your shortcut icon or \'favicon\' is displayed in the address bar and bookmarks of most browsers.');
- $group .= form_checkbox(t('Use the default shortcut icon.'), "$var][default_favicon", 1, $settings['default_favicon'], t('Check here if you want the theme to use the default shortcut icon.'));
- $group .= form_textfield(t('Path to custom icon'), "$var][favicon_path", $settings['favicon_path'], 60, 128, t('The path to the image file you would like to use as your custom shortcut icon.'));
-
- $directory_path = variable_get('file_directory_path', 'files');
- file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
- $group .= form_file(t('Upload icon image'), 'favicon_upload', 40, t("If you don't have direct file access to the server, use this field to upload your shortcut icon."));
-
- $form .= form_group(t('Shortcut icon settings'), $group);
+ $form['favicon'] = array(type => 'fieldset', title => t('Shortcut icon settings'));
+ $form['favicon']['text'] = array(value => t('Your shortcut icon or \'favicon\' is displayed in the address bar and bookmarks of most browsers.'));
+ $form['favicon']['default_favicon'] = array(
+ type => 'checkbox', title => t('Use the default shortcut icon.'), default_value => $settings['default_favicon'],
+ description => t('Check here if you want the theme to use the default shortcut icon.')
+ );
+ $form['favicon']['favicon_path'] = array(
+ type => 'textfield', title => t('Path to custom icon'), default_value => $settings['favicon_path'],
+ description => t('The path to the image file you would like to use as your custom shortcut icon.')
+ );
+
+ $form['favicon']['favicon_upload'] = array(
+ type => 'file', title => t('Upload icon image'), description => t("If you don't have direct file access to the server, use this field to upload your shortcut icon.")
+ );
}
// System wide only settings.
if (!$key) {
// Menu settings
- $header = array(t('link text'), t('url'), t('description'));
- foreach (array('Primary', 'Secondary') as $utype) {
- $group = '';
- $rows = array();
-
- // Use $utype field , and strtolower() it to get the type field.. to avoid issues with ucfirst() and unicode.
- $type = drupal_strtolower($utype);
- $value = $settings[$type . '_links'];
- if (!is_array($value)) {
- $value = array();
- }
-
- // Increment the link count, if the user has requested more links.
- if (variable_get($type . '_links_more', false)) {
- variable_del($type . '_links_more');
- variable_set($type . '_link_count', variable_get($type . '_link_count', 5) + 5);
- }
-
- // Get the amount of links to show, possibly expanding if there are more links defined than the count specifies.
- $count = variable_get($type . '_link_count', 5);
- $count = ($count > sizeof($value['link'])) ? $count : sizeof($value['link']);
- if (variable_get($type . '_link_count', 5) != $count) {
- variable_set($type . '_link_count', $count);
- }
-
- for ($i = 0; $i < $count; $i++) {
- $row = array();
- foreach (array('text', 'link', 'description') as $field) {
- $row[] = form_textfield('', $var . '][' . $type . '_links][' . $field . '][' . $i, $value[$field][$i], 15, 90);
- }
- $rows[] = $row;
- }
-
- $group .= form_item('', theme("table", $header, $rows), t('You can specify your _TYPE_ links here, one link per line.<br /> The link text field is the text you want to link.<br /> The url field is the location the link points to.<br /> The description field is an optional description of where the link points.', array('_TYPE_' => $type)));
- $group .= form_checkbox(t('I need more _TYPE_ links.', array('_TYPE_' => $type)), $type . '_links_more', 1, FALSE, t('Checking this box will give you 5 additional _TYPE_ links.', array('_TYPE_' => $type)));
- $form .= form_group(t('_TYPE_ link settings', array('_TYPE_' => $utype)), $group);
- }
+ $form['primary_links'] = system_navigation_links_form('primary', 'Primary');
+ $form['secondary_links'] = system_navigation_links_form('secondary', 'Secondary');
// Toggle node display.
$node_types = module_invoke('node', 'get_types');
if ($node_types) {
$group = '';
+ $form['node_info'] = array(type => 'fieldset', title => t('Display post information on'), description => t('Enable or disable the "submitted by Username on date" text when displaying posts of the above type'));
foreach ($node_types as $type => $name) {
- $group .= form_checkbox($name, "$var][toggle_node_info_$type", 1, $settings["toggle_node_info_$type"]);
+ $form['node_info']["toggle_node_info_$type"] = array(type => 'checkbox', title => $name, default_value => $settings["toggle_node_info_$type"]);
}
- $form .= form_group(t('Display post information on'), $group, t('Enable or disable the "submitted by Username on date" text when displaying posts of the above type'));
}
}
@@ -838,36 +1017,148 @@ function system_theme_settings($key = '') {
$disabled['toggle_search'] = true;
}
+ $form['toggles'] = array(type => 'fieldset', title => t('Toggle display'), description => t('Enable or disable the display of certain page elements.'));
foreach ($toggles as $name => $title) {
if ((!$key) || in_array($name, $features)) {
// disable search box if search.module is disabled
- $group .= form_checkbox($title, "$var][$name", 1, $settings[$name], NULL, isset($disabled[$name]) ? array('disabled' => 'disabled') : NULL);
+ $form['toggles'][$name] = array(type => 'checkbox', title => $title, default_value => $settings[$name], attributes => isset($disabled[$name]) ? array('disabled' => 'disabled') : NULL);
}
}
- if ($group) {
- $form .= form_group(t('Toggle display'), $group, t('Enable or disable the display of certain page elements.'));
- }
if ($key) {
// Template-specific settings
$function = $themes[$key]->prefix .'_settings';
if (function_exists($function)) {
- $group = $function();
if ($themes[$key]->template) {
// file is a template or a style of a template
- $form .= form_group(t('Engine-specific settings'), $group, t('These settings only exist for all the templates and styles based on the %engine theme engine.', array('%engine' => $themes[$key]->prefix)));
+ $form['specific'] = array(type => 'fieldset', title => t('Engine-specific settings'), description => t('These settings only exist for all the templates and styles based on the %engine theme engine.', array('%engine' => $themes[$key]->prefix)));
}
else {
// file is a theme or a style of a theme
- $form .= form_group(t('Theme-specific settings'), $group, t('These settings only exist for the %theme theme and all the styles based on it.', array('%theme' => $themes[$key]->prefix)));
+ $form['specific'] = array(type => 'fieldset', title => t('Theme-specific settings'), description => t('These settings only exist for the %theme theme and all the styles based on it.', array('%theme' => $themes[$key]->prefix)));
}
+ $group = $function();
+ $form['specific'] = array_merge($form['specific'], (is_array($group) ? $group : array()));
}
}
- $form .= form_submit(t('Save configuration'));
- $form .= form_submit(t('Reset to defaults'));
+ $form[attributes] = array('enctype' => 'multipart/form-data');
- return form($form, 'post', null, array('enctype' => 'multipart/form-data'));
+ return system_settings_form('system_theme_settings', $form);
}
+function system_navigation_links_form($type, $utype) {
+ $settings = theme_get_settings('');
+ $value = $settings[$type . '_links'];
+ if (!is_array($value)) {
+ $value = array();
+ }
+ // Increment the link count, if the user has requested more links.
+ if (variable_get($type . '_links_more', false)) {
+ variable_del($type . '_links_more');
+ variable_set($type . '_link_count', variable_get($type . '_link_count', 5) + 5);
+ }
+
+ // Get the amount of links to show, possibly expanding if there are more links defined than the count specifies.
+ $count = variable_get($type . '_link_count', 5);
+ $count = ($count > sizeof($value['link'])) ? $count : sizeof($value['link']);
+
+ if (variable_get($type . '_link_count', 5) != $count) {
+ variable_set($type . '_link_count', $count);
+ }
+ $form = array(
+ type => 'item', title => t('_TYPE_ link settings', array('_TYPE_' => $utype)), theme => 'system_navigation_links_form',
+ description => t('You can specify your _TYPE_ links here, one link per line.<br /> The link text field is the text you want to link.<br /> The url field is the location the link points to.<br /> The description field is an optional description of where the link points.', array('_TYPE_' => $type))
+ );
+
+ $form[tree] = TRUE;
+
+ for ($i = 0; $i < $count; $i++) {
+ foreach (array('text', 'link', 'description') as $field) {
+ $form[$field][$i] = array(type => 'textfield', default_value => $value[$field][$i], size => 15, maxlength => 90);
+ }
+ }
+
+ $form[$type . '_links_more'] = array(
+ type => 'checkbox', title => t('I need more _TYPE_ links.', array('_TYPE_' => $type)), default_value => FALSE,
+ description => t('Checking this box will give you 5 additional _TYPE_ links.', array('_TYPE_' => $type))
+ );
+ return $form;
+}
+
+function theme_system_navigation_links_form(&$form) {
+ $header = array(t('link text'), t('url'), t('description'));
+ foreach (element_children($form['text']) as $key) {
+ $row = array();
+ $row[] = form_render($form['text'][$key]);
+ $row[] = form_render($form['link'][$key]);
+ $row[] = form_render($form['description'][$key]);
+ $rows[] = $row;
+
+ }
+ $output = theme('table', $header, $rows);
+ $output .= form_render($form);
+ return $output;
+}
+
+
+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 = '<div id="search">';
+ $output .= form_render($form);
+ $output .= '</div>';
+ 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['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 <em>foo</em>?").
+ * @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') {
+
+ $description = ($description) ? $description : t('This action cannot be undone.');
+ drupal_set_title($question);
+ $form[attributes] = array('class' => 'confirmation');
+ $form['description'] = array(value => $description);
+ $form[$name] = array(type => 'hidden', value => 1);
+
+ $form['actions'] = array(prefix => '<div class="container-inline">', suffix => '</div>');
+ $form['actions']['submit'] = array(type => 'submit', value => $yes ? $yes : t('Confirm'));
+ $form['actions']['cancel'] = array(value => l($no ? $no : t('Cancel'), $path));
+ return drupal_get_form($form_id, $form, 'confirm_form');
+}
diff --git a/modules/system/system.module b/modules/system/system.module
index 56c648273..8b5a2338b 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -50,6 +50,37 @@ function system_perm() {
}
/**
+ * 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', execute => TRUE);
+ $type['button'] = array(input => TRUE, name => 'op', button_type => 'submit', exexute => FALSE);
+ $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', tree => TRUE);
+ $type['select'] = array(input => TRUE);
+ $type['weight'] = array(input => TRUE, delta => 10);
+ $type['date'] = array(input => TRUE, process => 'expand_date');
+ $type['file'] = array(input => TRUE, size => 60);
+
+ // Form structure
+ $type['item'] = array();
+ $type['hidden'] = array(input => TRUE);
+ $type['value'] = 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) {
@@ -130,40 +161,38 @@ function system_user($type, $edit, &$user, $category = NULL) {
$themes = list_themes();
ksort($themes);
- if (count($themes) > 1) {
- $rows = array();
- foreach ($themes as $key => $value) {
- $row = array();
-
- // Screenshot column.
- $screenshot = dirname($value->filename) .'/screenshot.png';
- $row[] = file_exists($screenshot) ? theme('image', $screenshot, t('Screenshot for %theme theme', array('%theme' => $value->name)), '', array('class' => 'screenshot')) : t('no screenshot');
-
- // Information field.
- $row[] = '<strong>'. $value->name .'</strong>';
+ // Reset to follow site default theme if user selects the site default
+ if ($key == variable_get('theme_default', 'bluemarine')) {
+ $key = '';
+ if ($edit['theme'] == variable_get('theme_default', 'bluemarine')) {
+ $edit['theme'] = '';
+ }
+ }
- // Reset to follow site default theme if user selects the site default
- if ($key == variable_get('theme_default', 'bluemarine')) {
- $key = '';
- if ($edit['theme'] == variable_get('theme_default', 'bluemarine')) {
- $edit['theme'] = '';
- }
- }
+ $form['themes'] = array(
+ type => 'fieldset', title => t('Theme configuration'), description => t('Selecting a different theme will change the look and feel of the site.'), weight => 2, collapsible => TRUE, collapsed => FALSE
+ );
- // Selected column.
- $row[] = array('data' => form_radio('', 'theme', $key, ($edit['theme'] == $key) ? 1 : 0), 'align' => 'center');
+ 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');
- $rows[] = $row;
- }
- $header = array(t('Screenshot'), t('Name'), t('Selected'));
- $data[] = array('title' => t('Theme settings'), 'data' => form_item('', theme('table', $header, $rows), t('Selecting a different theme will change the look and feel of the site.')), 'weight' => 2);
+ $form['themes'][$info->name]['screenshot'] = array(type => 'markup', value => $screenshot);
+ $form['themes'][$info->name]['description'] = array(type => 'item', title => $info->name, value => dirname($info->filename));
+ $options[$info->name] = '';
}
+ $form['themes']['theme'] = array(type => 'radios', options => $options, default_value => $edit['theme']);
+
if (variable_get('configurable_timezones', 1)) {
$zones = _system_zonelist();
- $data[] = array('title' => t('Locale settings'), 'data' => form_select(t('Time zone'), 'timezone', strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0), $zones, t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.')), 'weight' => 2);
+ $form['locale'] = array(type=>'item', title => t('Locale settings'), weight => 6);
+ $form['locale']['timezone'] = array(
+ type => 'select', title => t('Time zone'), default_value => strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0),
+ options => $zones, descriptions => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.')
+ );
}
- return $data;
+ return $form;
}
}
@@ -180,69 +209,149 @@ function _system_zonelist() {
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 <code>?q=</code> in the URL). You\'ll need <code>ModRewrite</code> support for this to work. See the <code>.htaccess</code> 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 <code>?q=</code> in the URL). You\'ll need <code>ModRewrite</code> support for this to work. See the <code>.htaccess</code> 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 .= '<img style="position: relative; left: -1000em;" src="'. $base_url. '/system/test/'. user_password(20) .'.png" alt="" />';
-
- $output = form_group_collapsible(t('General settings'), $group, TRUE);
+ $form['general']['clean_url_test'] = array(type => 'markup', value => '<img style="position: relative; left: -1000em;" src="'. $base_url. '/system/test/'. user_password(20) .'.png" alt="" />');
// 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');
- $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 <em>private</em>. 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);
+ $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 <em>private</em>. You can change this at any time, however all download URLs will change and there may be unexpected problems so it is not recommended.')
+ );
+ /*
// 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'] = array(
+ type => 'radios', title => t('Select an image processing toolkit'),
+ default_value => variable_get('image_toolkit', image_get_toolkit()), options => $toolkits_available
+ );
}
- $group .= image_toolkit_invoke('settings');
- if ($group) {
- $output .= form_group_collapsible(t('Image handling'), '<p>'. $group .'</p>', TRUE);
+ $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);
}
+ */
// Feed settings
- $group = '';
- $group .= form_select(t('Number of items per feed'), 'feed_default_items', variable_get('feed_default_items', 10), drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)), t('The default number of items to include in a feed.'));
- $group .= form_select(t('Display of XML feed items'), 'feed_item_length', variable_get('feed_item_length','teaser'), array('title' => t('Titles only'), 'teaser' => t('Titles plus teaser'), 'fulltext' => t('Full text')), t('Global setting for the length of XML feed items that are output by default.'));
- $output .= form_group_collapsible(t('RSS feed settings'), $group, TRUE);
+ $form['feed'] = array(type => 'fieldset', title => t('RSS feed settings'), collapsible => TRUE, collapsed => TRUE);
+ $form['feed']['feed_default_items'] = array(
+ type => 'select', title => t('Number of items per feed'), default_value => variable_get('feed_default_items', 10),
+ options => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
+ description => t('The default number of items to include in a feed.')
+ );
+ $form['feed']['feed_item_length'] = array(
+ type => 'select', title => t('Display of XML feed items'), default_value => variable_get('feed_item_length','teaser'),
+ options => array('title' => t('Titles only'), 'teaser' => t('Titles plus teaser'), 'fulltext' => t('Full text')),
+ description => t('Global setting for the length of XML feed items that are output by default.')
+ );
// Date settings:
$zones = _system_zonelist();
@@ -270,19 +379,44 @@ function system_view_general() {
$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'] = array_merge($form['strings'], unicode_settings());
- return $output;
+ return $form;
}
/**
@@ -471,44 +605,164 @@ function system_listing($mask, $directory, $key = 'name', $min_depth = 1) {
}
/**
- * Generate a list of all the available theme/style combinations.
+ * Assign an initial, default set of blocks for a theme.
+ *
+ * This function is called the first time a new theme is enabled. The new theme
+ * gets a copy of the default theme's blocks, with the difference that if a
+ * particular region isn't available in the new theme, the block is assigned
+ * to the new theme's default region.
+ *
+ * @param $theme
+ * The name of a theme.
+ */
+function system_initialize_theme_blocks($theme) {
+ // Initialize theme's blocks if none already registered.
+ if (!(db_num_rows(db_query("SELECT module FROM {blocks} WHERE theme = '%s'", $theme)))) {
+ $default_theme = variable_get('theme_default', 'bluemarine');
+ $regions = system_region_list($theme);
+ $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $default_theme);
+ while($block = db_fetch_array($result)) {
+ // If the region isn't supported by the theme, assign the block to the theme's default region.
+ if (!array_key_exists($block['region'], $regions)) {
+ $block['region'] = system_default_region($theme);
+ }
+ db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d)",
+ $block['module'], $block['delta'], $theme, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle']);
+ }
+ }
+}
+
+// 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 drupal_get_form($form_id, $form, 'system_settings_form');
+}
+
+/**
+ * Execute the system_settings_form.
+ *
+ * Due to specific handling of checkboxes, this function does not handle 'tree' based forms.
+ */
+function system_settings_form_execute($form_id, $values) {
+ $op = isset($_POST['op']) ? $_POST['op'] : '';
+
+ foreach ($values as $key => $value) {
+ if ($op == t('Reset to defaults')) {
+ variable_del($key);
+ }
+ else {
+ if (is_array($value)) {
+ $value = array_keys(array_filter($value));
+ }
+ variable_set($key, $value);
+ }
+ }
+ if ($op == t('Reset to defaults')) {
+ drupal_set_message(t('The configuration options have been reset to their default values.'));
+ } else {
+ drupal_set_message(t('The configuration options have been saved.'));
+ }
+}
+
+/**
+ * Do the clean url validation, changing the form property if it doesn't work.
*/
-function system_theme_listing() {
+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 <code>ModRewrite</code> support with your administrator.'), 'error');
+ $edit['clean_url'] = 0;
+ }
+
+}
+
+
+
+
+/**
+ * Menu callback; displays a listing of all themes.
+ */
+function system_themes() {
$themes = system_theme_data();
ksort($themes);
foreach ($themes as $info) {
$info->screenshot = dirname($info->filename) . '/screenshot.png';
- $row = array();
-
- // Screenshot column.
- $row[] = file_exists($info->screenshot) ? theme('image', $info->screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot')) : t('no screenshot');
-
- // Information field.
- $row[] = "<strong>$info->name</strong><br /><em>" . dirname($info->filename) . '</em>';
+ $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');
- // enabled, default, and operations columns
- $row[] = array('data' => form_checkbox('', 'status]['. $info->name, 1, $info->status), 'align' => 'center');
- $row[] = array('data' => form_radio('', 'theme_default', $info->name, (variable_get('theme_default', 'bluemarine') == $info->name) ? 1 : 0), 'align' => 'center');
+ $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'))) {
- $row[] = array('data' => l(t('configure'), 'admin/themes/settings/' . $info->name), 'align' => 'center');
+ $form[$info->name]['operations'] = array(type => 'markup', value => l(t('configure'), 'admin/themes/settings/' . $info->name) );
}
else {
- $row[] = '';
+ // 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 (element_children($form) as $key) {
+ $row = array();
+ if (is_array($form[$key]['description'])) {
+ $row[] = form_render($form[$key]['screenshot']);
+ $row[] = form_render($form[$key]['description']);
+ $row[] = array('data' => form_render($form['status'][$key]), 'align' => 'center');
+ if ($form['theme_default']) {
+ $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 = form_hidden('type', 'theme');
- $output .= theme('table', $header, $rows);
+ $output = theme('table', $header, $rows);
+ $output .= form_render($form);
return $output;
}
+
+function system_themes_execute($form_id, $values) {
+
+ db_query("UPDATE {system} SET status = 0 WHERE type = 'theme'");
+
+ if ($_POST['op'] == t('Save configuration')) {
+ variable_set('theme_default', $values['theme_default']);
+ if (is_array($values['status'])) {
+ foreach ($values['status'] as $key => $choice) {
+ if ($choice) {
+ db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' and name = '%s'", $key);
+ }
+ }
+ }
+ }
+ else {
+ variable_del('theme_default');
+ }
+
+ drupal_set_message(t('The configuration options have been saved.'));
+ drupal_goto('admin/themes');
+}
+
/**
- * Generate a list of all the available modules, as well as update the system list.
+ * Menu callback; displays a listing of all modules.
*/
-function system_module_listing() {
+function system_modules() {
// Get current list of modules
$files = system_listing('\.module$', 'modules', 'name', 0);
@@ -517,20 +771,22 @@ function system_module_listing() {
ksort($files);
- $required = array('block', 'filter', 'system', 'user', 'watchdog');
- $throttle_required = array_merge($required, array('throttle'));
-
- $header = array(t('Name'), t('Description'), t('Enabled'));
- if (module_exist('throttle')) {
- $header[] = t('Throttle');
- }
-
foreach ($files as $filename => $file) {
drupal_get_filename('module', $file->name, $file->filename);
drupal_load('module', $file->name);
$file->description = module_invoke($file->name, 'help', 'admin/modules#description');
+ $form['name'][$file->name] = array(value => $file->name);
+ $form['description'][$file->name] = array(value => $file->description);
+ $options[$file->name] = '';
+ if ($file->status) {
+ $status[] = $file->name;
+ }
+ if ($file->throttle) {
+ $throttle[] = $file->name;
+ }
+
// log the critical hooks implemented by this module
$bootstrap = 0;
foreach (bootstrap_hooks() as $hook) {
@@ -543,155 +799,104 @@ function system_module_listing() {
// Update the contents of the system table:
db_query("DELETE FROM {system} WHERE name = '%s' AND type = '%s'", $file->name, 'module');
db_query("INSERT INTO {system} (name, description, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', %d, %d, %d)", $file->name, $file->description, 'module', $file->filename, $file->status, $file->throttle, $bootstrap);
-
- $row = array($file->name, $file->description, array('data' => (in_array($file->name, $required) ? form_hidden("status][$file->name", 1) . t('required') : form_checkbox('', "status][$file->name", 1, $file->status)), 'align' => 'center'));
- if (module_exist('throttle')) {
- $row[] = array('data' => (in_array($file->name, $throttle_required) ? form_hidden("throttle][$file->name", 0) . t('required') : form_checkbox(NULL, "throttle][$file->name", 1, $file->throttle, NULL)), 'align' => 'center');
- }
- $rows[] = $row;
}
- $output = theme('table', $header, $rows);
- $output .= form_hidden('type', 'module');
-
- return $output;
-}
-
-function system_listing_save($edit = array()) {
- $op = $_POST['op'];
- $edit = $_POST['edit'];
-
- if ($op == t('Save configuration')) {
- db_query("UPDATE {system} SET status = 0 WHERE type = '%s'", $edit['type']);
- foreach ($edit['status'] as $name => $status) {
- // Make certain that the default theme is enabled to avoid user error
- if (($edit['type'] == 'theme') && ($edit['theme_default'] == $name)) {
- $status = 1;
- }
- // If status is being set to 1 from 0, initialize block data for this theme if necessary.
- if (($edit['type'] == 'theme') && ($status == 1) && db_num_rows(db_query("SELECT status FROM {system} WHERE type = '%s' AND name = '%s' AND status = 0", $edit['type'], $name))) {
- system_initialize_theme_blocks($name);
- }
- db_query("UPDATE {system} SET status = %d, throttle = %d WHERE type = '%s' AND name = '%s'", $status, $edit['throttle'][$name], $edit['type'], $name);
- }
+ /**
+ * Handle status checkboxes, including overriding the generated checkboxes for required modules.
+ */
+ $form['status'] = array(type => 'checkboxes', default_value => $status, options => $options, tree => TRUE);
+ $required = array('block', 'filter', 'system', 'user', 'watchdog');
+ foreach ($required as $require) {
+ $form['status'][$require] = array(type => 'hidden', value => 1, suffix => t('required'));
+ }
- if ($edit['type'] == 'theme') {
- variable_set('theme_default', $edit['theme_default']);
+ /**
+ * Handle throttle checkboxes, including overriding the generated checkboxes for required modules.
+ */
+ if (module_exist('throttle')) {
+ $form['throttle'] = array(type => 'checkboxes', default_value => $throttle, options => $options, tree => TRUE);
+ $throttle_required = array_merge($required, array('throttle'));
+ foreach ($throttle_required as $require) {
+ $form['throttle'][$require] = array(type => 'hidden', value => 1, suffix => t('required'));
}
+ }
- menu_rebuild();
+ $form['buttons']['submit'] = array(type => 'submit', value => t('Save configuration'));
- drupal_set_message(t('The configuration options have been saved.'));
- drupal_goto($_GET['q']);
- }
+ return drupal_get_form('system_modules', $form);
}
-/**
- * Assign an initial, default set of blocks for a theme.
- *
- * This function is called the first time a new theme is enabled. The new theme
- * gets a copy of the default theme's blocks, with the difference that if a
- * particular region isn't available in the new theme, the block is assigned
- * to the new theme's default region.
- *
- * @param $theme
- * The name of a theme.
- */
-function system_initialize_theme_blocks($theme) {
- // Initialize theme's blocks if none already registered.
- if (!(db_num_rows(db_query("SELECT module FROM {blocks} WHERE theme = '%s'", $theme)))) {
- $default_theme = variable_get('theme_default', 'bluemarine');
- $regions = system_region_list($theme);
- $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $default_theme);
- while($block = db_fetch_array($result)) {
- // If the region isn't supported by the theme, assign the block to the theme's default region.
- if (!array_key_exists($block['region'], $regions)) {
- $block['region'] = system_default_region($theme);
- }
- db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d)",
- $block['module'], $block['delta'], $theme, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle']);
+
+function theme_system_modules($form) {
+ foreach (element_children($form['name']) as $key) {
+ $row = array();
+ $row[] = form_render($form['name'][$key]);
+ $row[] = form_render($form['description'][$key]);
+ $row[] = array('data' => form_render($form['status'][$key]), 'align' => 'center');
+
+ if (module_exist('throttle')) {
+ $row[] = array('data' => form_render($form['throttle'][$key]), 'align' => 'center');
}
+ $rows[] = $row;
}
-}
-function system_settings_form($form) {
- $form .= form_submit(t('Save configuration'));
- $form .= form_submit(t('Reset to defaults'));
+ $header = array(t('Name'), t('Description'), t('Enabled'));
+ if (module_exist('throttle')) {
+ $header[] = t('Throttle');
+ }
- return form($form);
+ $output = theme('table', $header, $rows);
+ $output .= form_render($form);
+ return $output;
}
-function system_settings_save() {
- $op = $_POST['op'];
- $edit = $_POST['edit'];
- if ($op == t('Reset to defaults')) {
- if (is_array($edit)) {
- foreach ($edit as $name => $value) {
- variable_del($name);
- }
+function system_modules_execute($form_id, $edit) {
+ db_query("update {system} set status = 0, throttle = 0 where type = 'module'");
+
+ foreach ($edit['status'] as $key => $choice) {
+ if ($choice) {
+ db_query("update {system} set status = 1 where type = 'module' and name = '%s'", $key);
}
- 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 <code>ModRewrite</code> support with your administrator.'), 'error');
- $edit['clean_url'] = 0;
- }
- foreach ($edit as $name => $value) {
- variable_set($name, $value);
+
+ if (is_array($edit['throttle'])) {
+ foreach ($edit['throttle'] as $key => $choice) {
+ if ($choice) {
+ db_query("UPDATE {system} SET throttle = 1 WHERE type = 'module' and name = '%s'", $key);
}
}
- drupal_set_message(t('The configuration options have been saved.'));
}
- else {
- return;
- }
- menu_rebuild();
- drupal_goto($_GET['q']);
-}
-/**
- * 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);
+ menu_rebuild();
+ drupal_set_message(t('The configuration options have been saved.'));
+ drupal_goto('admin/modules');
}
-/**
- * Menu callback; displays a listing of all modules.
- */
-function system_modules() {
- system_listing_save();
- $form = system_module_listing();
- $form .= form_submit(t('Save configuration'));
- return form($form);
-}
/**
* 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);
}
/**
* Menu callback; display theme configuration for entire site and individual themes.
*/
function system_theme_settings($key = '') {
+ $directory_path = variable_get('file_directory_path', 'files');
+ file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
+
// Default settings are defined in theme_get_settings() in includes/theme.inc
if ($key) {
$settings = theme_get_settings($key);
@@ -704,6 +909,8 @@ function system_theme_settings($key = '') {
$var = 'theme_settings';
}
+ $form['var'] = array(type => 'hidden', value => $var);
+
// Check for a new uploaded logo, and use that instead.
if ($file = file_check_upload('logo_upload')) {
if ($info = image_get_info($file->filepath)) {
@@ -711,8 +918,8 @@ function system_theme_settings($key = '') {
$filename = ($key) ? str_replace('/', '_', $key) . '_logo.' . $parts['extension'] : 'logo.' . $parts['extension'];
if ($file = file_save_upload('logo_upload', $filename, 1)) {
- $_POST['edit'][$var]['default_logo'] = 0;
- $_POST['edit'][$var]['logo_path'] = $file->filepath;
+ $_POST['edit']['default_logo'] = 0;
+ $_POST['edit']['logo_path'] = $file->filepath;
}
}
else {
@@ -726,90 +933,62 @@ function system_theme_settings($key = '') {
$filename = ($key) ? str_replace('/', '_', $key) . '_favicon.' . $parts['extension'] : 'favicon.' . $parts['extension'];
if ($file = file_save_upload('favicon_upload', $filename, 1)) {
- $_POST['edit'][$var]['default_favicon'] = 0;
- $_POST['edit'][$var]['favicon_path'] = $file->filepath;
+ $_POST['edit']['default_favicon'] = 0;
+ $_POST['edit']['favicon_path'] = $file->filepath;
}
}
- system_settings_save();
-
- $form = '';
// Logo settings
if ((!$key) || in_array('logo', $features)) {
- $group = form_checkbox(t('Use the default logo'), "$var][default_logo", 1, $settings['default_logo'], t('Check here if you want the theme to use the logo supplied with it.'));
- $group .= form_textfield(t('Path to custom logo'), "$var][logo_path", $settings['logo_path'], 60, 128, t('The path to the file you would like to use as your logo file instead of the default logo.'));
-
- $directory_path = variable_get('file_directory_path', 'files');
- file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
- $group .= form_file(t('Upload logo image'), 'logo_upload', 40, t("If you don't have direct file access to the server, use this field to upload your logo."));
-
- $form .= form_group(t('Logo image settings'), $group);
+ $form['logo'] = array(type => 'fieldset', title => t('Logo image settings'));
+ $form['logo']["default_logo"] = array(
+ type => 'checkbox', title => t('Use the default logo'), default_value => $settings['default_logo'], tree => FALSE,
+ description => t('Check here if you want the theme to use the logo supplied with it.')
+ );
+ $form['logo']['logo_path'] = array(
+ type => 'textfield', title => t('Path to custom logo'), size => 60, maxlength => 128,
+ description => t('The path to the file you would like to use as your logo file instead of the default logo.'));
+
+ $form['logo']['logo_upload'] = array(
+ type => 'file', title => t('Upload logo image'), maxlength => 40,
+ description => t("If you don't have direct file access to the server, use this field to upload your logo.")
+ );
}
// Icon settings
if ((!$key) || in_array('toggle_favicon', $features)) {
- $group = t('Your shortcut icon or \'favicon\' is displayed in the address bar and bookmarks of most browsers.');
- $group .= form_checkbox(t('Use the default shortcut icon.'), "$var][default_favicon", 1, $settings['default_favicon'], t('Check here if you want the theme to use the default shortcut icon.'));
- $group .= form_textfield(t('Path to custom icon'), "$var][favicon_path", $settings['favicon_path'], 60, 128, t('The path to the image file you would like to use as your custom shortcut icon.'));
-
- $directory_path = variable_get('file_directory_path', 'files');
- file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
- $group .= form_file(t('Upload icon image'), 'favicon_upload', 40, t("If you don't have direct file access to the server, use this field to upload your shortcut icon."));
-
- $form .= form_group(t('Shortcut icon settings'), $group);
+ $form['favicon'] = array(type => 'fieldset', title => t('Shortcut icon settings'));
+ $form['favicon']['text'] = array(value => t('Your shortcut icon or \'favicon\' is displayed in the address bar and bookmarks of most browsers.'));
+ $form['favicon']['default_favicon'] = array(
+ type => 'checkbox', title => t('Use the default shortcut icon.'), default_value => $settings['default_favicon'],
+ description => t('Check here if you want the theme to use the default shortcut icon.')
+ );
+ $form['favicon']['favicon_path'] = array(
+ type => 'textfield', title => t('Path to custom icon'), default_value => $settings['favicon_path'],
+ description => t('The path to the image file you would like to use as your custom shortcut icon.')
+ );
+
+ $form['favicon']['favicon_upload'] = array(
+ type => 'file', title => t('Upload icon image'), description => t("If you don't have direct file access to the server, use this field to upload your shortcut icon.")
+ );
}
// System wide only settings.
if (!$key) {
// Menu settings
- $header = array(t('link text'), t('url'), t('description'));
- foreach (array('Primary', 'Secondary') as $utype) {
- $group = '';
- $rows = array();
-
- // Use $utype field , and strtolower() it to get the type field.. to avoid issues with ucfirst() and unicode.
- $type = drupal_strtolower($utype);
- $value = $settings[$type . '_links'];
- if (!is_array($value)) {
- $value = array();
- }
-
- // Increment the link count, if the user has requested more links.
- if (variable_get($type . '_links_more', false)) {
- variable_del($type . '_links_more');
- variable_set($type . '_link_count', variable_get($type . '_link_count', 5) + 5);
- }
-
- // Get the amount of links to show, possibly expanding if there are more links defined than the count specifies.
- $count = variable_get($type . '_link_count', 5);
- $count = ($count > sizeof($value['link'])) ? $count : sizeof($value['link']);
- if (variable_get($type . '_link_count', 5) != $count) {
- variable_set($type . '_link_count', $count);
- }
-
- for ($i = 0; $i < $count; $i++) {
- $row = array();
- foreach (array('text', 'link', 'description') as $field) {
- $row[] = form_textfield('', $var . '][' . $type . '_links][' . $field . '][' . $i, $value[$field][$i], 15, 90);
- }
- $rows[] = $row;
- }
-
- $group .= form_item('', theme("table", $header, $rows), t('You can specify your _TYPE_ links here, one link per line.<br /> The link text field is the text you want to link.<br /> The url field is the location the link points to.<br /> The description field is an optional description of where the link points.', array('_TYPE_' => $type)));
- $group .= form_checkbox(t('I need more _TYPE_ links.', array('_TYPE_' => $type)), $type . '_links_more', 1, FALSE, t('Checking this box will give you 5 additional _TYPE_ links.', array('_TYPE_' => $type)));
- $form .= form_group(t('_TYPE_ link settings', array('_TYPE_' => $utype)), $group);
- }
+ $form['primary_links'] = system_navigation_links_form('primary', 'Primary');
+ $form['secondary_links'] = system_navigation_links_form('secondary', 'Secondary');
// Toggle node display.
$node_types = module_invoke('node', 'get_types');
if ($node_types) {
$group = '';
+ $form['node_info'] = array(type => 'fieldset', title => t('Display post information on'), description => t('Enable or disable the "submitted by Username on date" text when displaying posts of the above type'));
foreach ($node_types as $type => $name) {
- $group .= form_checkbox($name, "$var][toggle_node_info_$type", 1, $settings["toggle_node_info_$type"]);
+ $form['node_info']["toggle_node_info_$type"] = array(type => 'checkbox', title => $name, default_value => $settings["toggle_node_info_$type"]);
}
- $form .= form_group(t('Display post information on'), $group, t('Enable or disable the "submitted by Username on date" text when displaying posts of the above type'));
}
}
@@ -838,36 +1017,148 @@ function system_theme_settings($key = '') {
$disabled['toggle_search'] = true;
}
+ $form['toggles'] = array(type => 'fieldset', title => t('Toggle display'), description => t('Enable or disable the display of certain page elements.'));
foreach ($toggles as $name => $title) {
if ((!$key) || in_array($name, $features)) {
// disable search box if search.module is disabled
- $group .= form_checkbox($title, "$var][$name", 1, $settings[$name], NULL, isset($disabled[$name]) ? array('disabled' => 'disabled') : NULL);
+ $form['toggles'][$name] = array(type => 'checkbox', title => $title, default_value => $settings[$name], attributes => isset($disabled[$name]) ? array('disabled' => 'disabled') : NULL);
}
}
- if ($group) {
- $form .= form_group(t('Toggle display'), $group, t('Enable or disable the display of certain page elements.'));
- }
if ($key) {
// Template-specific settings
$function = $themes[$key]->prefix .'_settings';
if (function_exists($function)) {
- $group = $function();
if ($themes[$key]->template) {
// file is a template or a style of a template
- $form .= form_group(t('Engine-specific settings'), $group, t('These settings only exist for all the templates and styles based on the %engine theme engine.', array('%engine' => $themes[$key]->prefix)));
+ $form['specific'] = array(type => 'fieldset', title => t('Engine-specific settings'), description => t('These settings only exist for all the templates and styles based on the %engine theme engine.', array('%engine' => $themes[$key]->prefix)));
}
else {
// file is a theme or a style of a theme
- $form .= form_group(t('Theme-specific settings'), $group, t('These settings only exist for the %theme theme and all the styles based on it.', array('%theme' => $themes[$key]->prefix)));
+ $form['specific'] = array(type => 'fieldset', title => t('Theme-specific settings'), description => t('These settings only exist for the %theme theme and all the styles based on it.', array('%theme' => $themes[$key]->prefix)));
}
+ $group = $function();
+ $form['specific'] = array_merge($form['specific'], (is_array($group) ? $group : array()));
}
}
- $form .= form_submit(t('Save configuration'));
- $form .= form_submit(t('Reset to defaults'));
+ $form[attributes] = array('enctype' => 'multipart/form-data');
- return form($form, 'post', null, array('enctype' => 'multipart/form-data'));
+ return system_settings_form('system_theme_settings', $form);
}
+function system_navigation_links_form($type, $utype) {
+ $settings = theme_get_settings('');
+ $value = $settings[$type . '_links'];
+ if (!is_array($value)) {
+ $value = array();
+ }
+ // Increment the link count, if the user has requested more links.
+ if (variable_get($type . '_links_more', false)) {
+ variable_del($type . '_links_more');
+ variable_set($type . '_link_count', variable_get($type . '_link_count', 5) + 5);
+ }
+
+ // Get the amount of links to show, possibly expanding if there are more links defined than the count specifies.
+ $count = variable_get($type . '_link_count', 5);
+ $count = ($count > sizeof($value['link'])) ? $count : sizeof($value['link']);
+
+ if (variable_get($type . '_link_count', 5) != $count) {
+ variable_set($type . '_link_count', $count);
+ }
+ $form = array(
+ type => 'item', title => t('_TYPE_ link settings', array('_TYPE_' => $utype)), theme => 'system_navigation_links_form',
+ description => t('You can specify your _TYPE_ links here, one link per line.<br /> The link text field is the text you want to link.<br /> The url field is the location the link points to.<br /> The description field is an optional description of where the link points.', array('_TYPE_' => $type))
+ );
+
+ $form[tree] = TRUE;
+
+ for ($i = 0; $i < $count; $i++) {
+ foreach (array('text', 'link', 'description') as $field) {
+ $form[$field][$i] = array(type => 'textfield', default_value => $value[$field][$i], size => 15, maxlength => 90);
+ }
+ }
+
+ $form[$type . '_links_more'] = array(
+ type => 'checkbox', title => t('I need more _TYPE_ links.', array('_TYPE_' => $type)), default_value => FALSE,
+ description => t('Checking this box will give you 5 additional _TYPE_ links.', array('_TYPE_' => $type))
+ );
+ return $form;
+}
+
+function theme_system_navigation_links_form(&$form) {
+ $header = array(t('link text'), t('url'), t('description'));
+ foreach (element_children($form['text']) as $key) {
+ $row = array();
+ $row[] = form_render($form['text'][$key]);
+ $row[] = form_render($form['link'][$key]);
+ $row[] = form_render($form['description'][$key]);
+ $rows[] = $row;
+
+ }
+ $output = theme('table', $header, $rows);
+ $output .= form_render($form);
+ return $output;
+}
+
+
+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 = '<div id="search">';
+ $output .= form_render($form);
+ $output .= '</div>';
+ 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['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 <em>foo</em>?").
+ * @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') {
+
+ $description = ($description) ? $description : t('This action cannot be undone.');
+ drupal_set_title($question);
+ $form[attributes] = array('class' => 'confirmation');
+ $form['description'] = array(value => $description);
+ $form[$name] = array(type => 'hidden', value => 1);
+
+ $form['actions'] = array(prefix => '<div class="container-inline">', suffix => '</div>');
+ $form['actions']['submit'] = array(type => 'submit', value => $yes ? $yes : t('Confirm'));
+ $form['actions']['cancel'] = array(value => l($no ? $no : t('Cancel'), $path));
+ return drupal_get_form($form_id, $form, 'confirm_form');
+}
diff --git a/modules/taxonomy.module b/modules/taxonomy.module
index 9f93a684b..5574520a1 100644
--- a/modules/taxonomy.module
+++ b/modules/taxonomy.module
@@ -107,28 +107,33 @@ function taxonomy_menu($may_cache) {
}
function taxonomy_form_vocabulary($edit = array()) {
- $form .= form_textfield(t('Vocabulary name'), 'name', $edit['name'], 60, 64, t('The name for this vocabulary. Example: "Topic".'), NULL, TRUE);
- // Prepend extra vocabulary form elements.
- $form .= implode('', module_invoke_all('taxonomy', 'form pre', 'vocabulary', $edit));
- $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('Description of the vocabulary; can be used by modules.'));
- $form .= form_textfield(t('Help text'), 'help', $edit['help'], 60, 255, t('Instructions to present to the user when choosing a term.'));
- $form .= form_checkboxes(t('Types'), 'nodes', $edit['nodes'], node_get_types(), t('A list of node types you want to associate with this vocabulary.'), NULL, TRUE);
- $form .= form_radios(t('Hierarchy'), 'hierarchy', $edit['hierarchy'], array(t('Disabled'), t('Single'), t('Multiple')), t('Allows <a href="%help-url">a tree-like hierarchy</a> between terms of this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'hierarchy'))));
- $form .= form_checkbox(t('Related terms'), 'relations', 1, $edit['relations'], t('Allows <a href="%help-url">related terms</a> in this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'related-terms'))));
- $form .= form_checkbox(t('Free tagging'), 'tags', 1, $edit['tags'], t('Content is categorized by typing terms instead of choosing from a list.'));
- $form .= form_checkbox(t('Multiple select'), 'multiple', 1, $edit['multiple'], t('Allows nodes to have more than one term from this vocabulary (always true for free tagging).'));
- $form .= form_checkbox(t('Required'), 'required', 1, $edit['required'], t('If enabled, every node <strong>must</strong> have at least one term in this vocabulary.'));
- $form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('In listings, the heavier vocabularies will sink and the lighter vocabularies will be positioned nearer the top.'));
- // Append extra vocabulary form elements.
- $form .= implode('', module_invoke_all('taxonomy', 'form post', 'vocabulary', $edit));
- $form .= form_submit(t('Submit'));
+ $form['name'] = array(type => 'textfield', title => t('Vocabulary name'), default_value => $edit['name'], size => 60, maxlength => 64, description => t('The name for this vocabulary. Example: "Topic".'), required => TRUE);
+
+ $form['description'] = array(type => 'textarea', title => t('Description'), default_value => $edit['description'], cols => 60, rows => 5, description => t('Description of the vocabulary; can be used by modules.'));
+ $form['help'] = array(type => 'textfield', title => t('Help text'), default_value => $edit['help'], size => 60, maxlength => 255, description => t('Instructions to present to the user when choosing a term.'));
+ $form['nodes'] = array(type => 'checkboxes', title => t('Types'), default_value => $edit['nodes'], options => node_get_types(), description => t('A list of node types you want to associate with this vocabulary.'), required => TRUE);
+ $form['hierarchy'] = array(type => 'radios', title => t('Hierarchy'), default_value => $edit['hierarchy'], options => array(t('Disabled'), t('Single'), t('Multiple')), description => t('Allows <a href="%help-url">a tree-like hierarchy</a> between terms of this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'hierarchy'))));
+ $form['relations'] = array(type => 'checkbox', title => t('Related terms'), default_value => $edit['relations'], return_value => 1, description => t('Allows <a href="%help-url">related terms</a> in this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'related-terms'))));
+ $form['tags'] = array(type => 'checkbox', title => t('Free tagging'), default_value => $edit['tags'], return_value => 1, description => t('Content is categorized by typing terms instead of choosing from a list.'));
+ $form['multiple'] = array(type => 'checkbox', title => t('Multiple select'), default_value => $edit['multiple'], return_value => 1, description => t('Allows nodes to have more than one term from this vocabulary (always true for free tagging).'));
+ $form['required'] = array(type => 'checkbox', title => t('Required'), default_value => $edit['required'], return_value => 1, description => t('If enabled, every node <strong>must</strong> have at least one term in this vocabulary.'));
+ $form['weight'] = array(type => 'weight', title => t('Weight'), default_value => $edit['weight'], delta => 10, description => t('In listings, the heavier vocabularies will sink and the lighter vocabularies will be positioned nearer the top.'));
+
+ // Add extra vocabulary form elements.
+ $extra = module_invoke_all('taxonomy', 'form', 'vocabulary');
+ if (is_array($extra)) {
+ foreach ($extra as $key => $element) {
+ $extra[$key][weight] = isset($extra[$key][weight]) ? $nodeapi[$key][weight] : -18;
+ }
+ $form = array_merge($form, $extra);
+ }
+ $form['submit'] = array(type => 'submit', value => t('Submit'));
if ($edit['vid']) {
- $form .= form_submit(t('Delete'));
- $form .= form_hidden('vid', $edit['vid']);
+ $form['delete'] = array(type => 'submit', value => t('Delete'));
+ $form['vid'] = array(type => 'hidden', value => $edit['vid']);
}
-
- return form($form);
+ return drupal_get_form('taxonomy_form_vocabulary', $form);
}
function taxonomy_save_vocabulary(&$edit) {
@@ -140,7 +145,7 @@ function taxonomy_save_vocabulary(&$edit) {
if ($edit['vid'] && $edit['name']) {
db_query('UPDATE {vocabulary} SET '. _taxonomy_prepare_update($data) .' WHERE vid = %d', $edit['vid']);
db_query("DELETE FROM {vocabulary_node_types} WHERE vid = %d", $edit['vid']);
- foreach ($edit['nodes'] as $type) {
+ foreach ($edit['nodes'] as $type => $selected) {
db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $edit['vid'], $type);
}
module_invoke_all('taxonomy', 'update', 'vocabulary', $edit);
@@ -152,7 +157,7 @@ function taxonomy_save_vocabulary(&$edit) {
else {
$data['vid'] = $edit['vid'] = db_next_id('{vocabulary}_vid');
db_query('INSERT INTO {vocabulary} '. _taxonomy_prepare_insert($data, 1) .' VALUES '. _taxonomy_prepare_insert($data, 2));
- foreach ($edit['nodes'] as $type) {
+ foreach ($edit['nodes'] as $type => $selected) {
db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $edit['vid'], $type);
}
module_invoke_all('taxonomy', 'insert', 'vocabulary', $edit);
@@ -184,28 +189,24 @@ function taxonomy_del_vocabulary($vid) {
function _taxonomy_confirm_del_vocabulary($vid) {
$vocabulary = taxonomy_get_vocabulary($vid);
- $extra = form_hidden('type', 'vocabulary');
- $extra .= form_hidden('vid', $vid);
- $extra .= form_hidden('name', $vocabulary->name);
-
- $output = theme('confirm',
- t('Are you sure you want to delete the vocabulary %title?', array('%title' => theme('placeholder', $vocabulary->name))),
- 'admin/taxonomy',
- t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'),
+ $form['type'] = array(type => 'hidden', value => 'vocabulary');
+ $form['vid'] = array(type => 'hidden', value => $vid);
+ $form['name'] = array(type => 'hidden', value => $vocabulary->name);
+ return confirm_form('vocabulary_confirm_delete', $form,
+ t('Are you sure you want to delete the vocabulary %title?',
+ array('%title' => theme('placeholder', $vocabulary->name))),
+ 'admin/taxonomy', t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'),
t('Delete'),
- t('Cancel'),
- $extra);
- return $output;
+ t('Cancel'));
}
function taxonomy_form_term($edit = array()) {
$vocabulary_id = isset($edit['vid']) ? $edit['vid'] : arg(4);
$vocabulary = taxonomy_get_vocabulary($vocabulary_id);
- $form = form_textfield(t('Term name'), 'name', $edit['name'], 60, 64, t('The name for this term. Example: "Linux".'), NULL, TRUE);
- // Prepend extra term form elements.
- $form .= implode('', module_invoke_all('taxonomy', 'form pre', 'term', $edit));
- $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('A description of the term.'));
+ $form['name'] = array(type => 'textfield', title => t('Term name'), default_value => $edit['name'], size => 60, maxlength => 64, description => t('The name for this term. Example: "Linux".'), required => TRUE);
+
+ $form['description'] = array(type => 'textarea', title => t('Description'), default_value => $edit['description'], cols => 60, rows => 5, description => t('A description of the term.'));
if ($vocabulary->hierarchy) {
$parent = array_keys(taxonomy_get_parents($edit['tid']));
@@ -218,33 +219,42 @@ function taxonomy_form_term($edit = array()) {
$exclude[] = $edit['tid'];
if ($vocabulary->hierarchy == 1) {
- $form .= _taxonomy_term_select(t('Parent'), 'parent', $parent, $vocabulary_id, l(t('Parent term'), 'admin/help/taxonomy', NULL, NULL, 'parent') .'.', 0, '<'. t('root') .'>', $exclude);
+ $form['parent'] = _taxonomy_term_select(t('Parent'), 'parent', $parent, $vocabulary_id, l(t('Parent term'), 'admin/help/taxonomy', NULL, NULL, 'parent') .'.', 0, '<'. t('root') .'>', $exclude);
}
elseif ($vocabulary->hierarchy == 2) {
- $form .= _taxonomy_term_select(t('Parents'), 'parent', $parent, $vocabulary_id, l(t('Parent terms'), 'admin/help/taxonomy', NULL, NULL, 'parent') .'.', 1, '<'. t('root') .'>', $exclude);
+ $form['parent'] = _taxonomy_term_select(t('Parents'), 'parent', $parent, $vocabulary_id, l(t('Parent terms'), 'admin/help/taxonomy', NULL, NULL, 'parent') .'.', 1, '<'. t('root') .'>', $exclude);
}
}
if ($vocabulary->relations) {
- $form .= _taxonomy_term_select(t('Related terms'), 'relations', array_keys(taxonomy_get_related($edit['tid'])), $vocabulary_id, NULL, 1, '<'. t('none') .'>', array($edit['tid']));
+ $form['relations'] = _taxonomy_term_select(t('Related terms'), 'relations', array_keys(taxonomy_get_related($edit['tid'])), $vocabulary_id, NULL, 1, '<'. t('none') .'>', array($edit['tid']));
}
- $form .= form_textarea(t('Synonyms'), 'synonyms', implode("\n", taxonomy_get_synonyms($edit['tid'])), 60, 5, t('<a href="%help-url">Synonyms</a> of this term, one synonym per line.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'synonyms'))));
- $form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('In listings, the heavier terms will sink and the lighter terms will be positioned nearer the top.'));
- // Append extra term form elements.
- $form .= implode('', module_invoke_all('taxonomy', 'form post', 'term', $edit));
- $form .= form_hidden('vid', $vocabulary->vid);
- $form .= form_submit(t('Submit'));
+ $form['synonyms'] = array(type => 'textarea', title => t('Synonyms'), default_value => implode("\n", taxonomy_get_synonyms($edit['tid'])), cols => 60, rows => 5, description => t('<a href="%help-url">Synonyms</a> of this term, one synonym per line.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'synonyms'))));
+ $form['weight'] = array(type => 'weight', title => t('Weight'), default_value => $edit['weight'], delta => 10, description => t('In listings, the heavier terms will sink and the lighter terms will be positioned nearer the top.'));
+
+ // Add extra term form elements.
+ $extra = module_invoke_all('taxonomy', 'term', 'vocabulary');
+ if (is_array($extra)) {
+ foreach ($extra as $key => $element) {
+ $extra[$key][weight] = isset($extra[$key][weight]) ? $nodeapi[$key][weight] : -18;
+ }
+ $form = array_merge($form, $extra);
+ }
+
+
+ $form['vid'] = array(type => 'hidden', value => $vocabulary->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']);
}
else {
- $form .= form_hidden('destination', $_GET['q']);
+ $form['destination'] = array(type => 'hidden', value => $_GET['q']);
}
- return form($form);
+ return drupal_get_form('taxonomy_form_term', $form);
}
function taxonomy_save_term(&$edit) {
@@ -343,18 +353,15 @@ function taxonomy_del_term($tid) {
function _taxonomy_confirm_del_term($tid) {
$term = taxonomy_get_term($tid);
- $extra = form_hidden('type', 'term');
- $extra .= form_hidden('tid', $tid);
-
- $output = theme('confirm',
- t('Are you sure you want to delete the term %title?', array('%title' => theme('placeholder', $term->name))),
+ $form['type'] = array(type => 'hidden', value => 'term');
+ $form['tid'] = array(type => 'hidden', value => $tid);
+ return confirm_form('term_confirm_delete', $form,
+ t('Are you sure you want to delete the term %title?',
+ array('%title' => theme('placeholder', $term->name))),
'admin/taxonomy',
t('Deleting a term will delete all its children if there are any. This action cannot be undone.'),
t('Delete'),
- t('Cancel'),
- $extra);
-
- return $output;
+ t('Cancel'));
}
/**
@@ -511,14 +518,18 @@ function taxonomy_node_form($type, $node = '', $help = NULL, $name = 'taxonomy')
}
}
$typed_string = implode(', ', $typed_terms) . (array_key_exists('tags', $terms) ? $terms['tags'][$vocabulary->vid] : NULL);
- $result[] = form_autocomplete($vocabulary->name, "$name][tags][". $vocabulary->vid, $typed_string, 60, 100, 'taxonomy/autocomplete/'. $vocabulary->vid, t('A comma-separated list of terms describing this content (Example: funny, bungie jumping, "Company, Inc.").'), NULL, ($vocabulary->required ? TRUE : FALSE));
+
+
+ $form[$name]['tags'][$vocabulary->vid] = array( type => textfield, default_value => $typed_string, size => 60, maxlength => 100,
+ autocomplete_path => 'taxonomy/autocomplete/'. $vocabulary->vid, required => ($vocabulary->required ? TRUE : FALSE), title => $vocabulary->name,
+ description => t('A comma-separated list of terms describing this content (Example: funny, bungie jumping, "Company, Inc.").') );
}
else {
$ntterms = array_key_exists('taxonomy', $node) ? $terms : array_keys($terms);
- $result[] = taxonomy_form($vocabulary->vid, $ntterms, $help, $name);
+ $form[$name][$vocabulary->vid] = taxonomy_form($vocabulary->vid, $ntterms, $help, $name);
}
}
- return $result ? $result : array();
+ return $form ? $form : array();
}
/**
@@ -889,8 +900,7 @@ function _taxonomy_term_select($title, $name, $value, $vocabulary_id, $descripti
$value = $tree[0]->tid;
}
}
-
- return form_select($title, $name . ($multiple ? '' : ']['), $value, $options, $description, $multiple ? 'size="'. min(12, count($options)) .'"' : 0, $multiple);
+ return array(type => 'select', title => $title, default_value => $value, options => $options, description => $description, multiple => $multiple, size => $multiple ? 'size="'. min(12, count($options)) .'"' : 0, weight => -15);
}
function _taxonomy_depth($depth, $graphic = '--') {
@@ -1288,5 +1298,3 @@ function taxonomy_autocomplete($vid, $string = '') {
exit();
}
}
-
-
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index 9f93a684b..5574520a1 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -107,28 +107,33 @@ function taxonomy_menu($may_cache) {
}
function taxonomy_form_vocabulary($edit = array()) {
- $form .= form_textfield(t('Vocabulary name'), 'name', $edit['name'], 60, 64, t('The name for this vocabulary. Example: "Topic".'), NULL, TRUE);
- // Prepend extra vocabulary form elements.
- $form .= implode('', module_invoke_all('taxonomy', 'form pre', 'vocabulary', $edit));
- $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('Description of the vocabulary; can be used by modules.'));
- $form .= form_textfield(t('Help text'), 'help', $edit['help'], 60, 255, t('Instructions to present to the user when choosing a term.'));
- $form .= form_checkboxes(t('Types'), 'nodes', $edit['nodes'], node_get_types(), t('A list of node types you want to associate with this vocabulary.'), NULL, TRUE);
- $form .= form_radios(t('Hierarchy'), 'hierarchy', $edit['hierarchy'], array(t('Disabled'), t('Single'), t('Multiple')), t('Allows <a href="%help-url">a tree-like hierarchy</a> between terms of this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'hierarchy'))));
- $form .= form_checkbox(t('Related terms'), 'relations', 1, $edit['relations'], t('Allows <a href="%help-url">related terms</a> in this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'related-terms'))));
- $form .= form_checkbox(t('Free tagging'), 'tags', 1, $edit['tags'], t('Content is categorized by typing terms instead of choosing from a list.'));
- $form .= form_checkbox(t('Multiple select'), 'multiple', 1, $edit['multiple'], t('Allows nodes to have more than one term from this vocabulary (always true for free tagging).'));
- $form .= form_checkbox(t('Required'), 'required', 1, $edit['required'], t('If enabled, every node <strong>must</strong> have at least one term in this vocabulary.'));
- $form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('In listings, the heavier vocabularies will sink and the lighter vocabularies will be positioned nearer the top.'));
- // Append extra vocabulary form elements.
- $form .= implode('', module_invoke_all('taxonomy', 'form post', 'vocabulary', $edit));
- $form .= form_submit(t('Submit'));
+ $form['name'] = array(type => 'textfield', title => t('Vocabulary name'), default_value => $edit['name'], size => 60, maxlength => 64, description => t('The name for this vocabulary. Example: "Topic".'), required => TRUE);
+
+ $form['description'] = array(type => 'textarea', title => t('Description'), default_value => $edit['description'], cols => 60, rows => 5, description => t('Description of the vocabulary; can be used by modules.'));
+ $form['help'] = array(type => 'textfield', title => t('Help text'), default_value => $edit['help'], size => 60, maxlength => 255, description => t('Instructions to present to the user when choosing a term.'));
+ $form['nodes'] = array(type => 'checkboxes', title => t('Types'), default_value => $edit['nodes'], options => node_get_types(), description => t('A list of node types you want to associate with this vocabulary.'), required => TRUE);
+ $form['hierarchy'] = array(type => 'radios', title => t('Hierarchy'), default_value => $edit['hierarchy'], options => array(t('Disabled'), t('Single'), t('Multiple')), description => t('Allows <a href="%help-url">a tree-like hierarchy</a> between terms of this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'hierarchy'))));
+ $form['relations'] = array(type => 'checkbox', title => t('Related terms'), default_value => $edit['relations'], return_value => 1, description => t('Allows <a href="%help-url">related terms</a> in this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'related-terms'))));
+ $form['tags'] = array(type => 'checkbox', title => t('Free tagging'), default_value => $edit['tags'], return_value => 1, description => t('Content is categorized by typing terms instead of choosing from a list.'));
+ $form['multiple'] = array(type => 'checkbox', title => t('Multiple select'), default_value => $edit['multiple'], return_value => 1, description => t('Allows nodes to have more than one term from this vocabulary (always true for free tagging).'));
+ $form['required'] = array(type => 'checkbox', title => t('Required'), default_value => $edit['required'], return_value => 1, description => t('If enabled, every node <strong>must</strong> have at least one term in this vocabulary.'));
+ $form['weight'] = array(type => 'weight', title => t('Weight'), default_value => $edit['weight'], delta => 10, description => t('In listings, the heavier vocabularies will sink and the lighter vocabularies will be positioned nearer the top.'));
+
+ // Add extra vocabulary form elements.
+ $extra = module_invoke_all('taxonomy', 'form', 'vocabulary');
+ if (is_array($extra)) {
+ foreach ($extra as $key => $element) {
+ $extra[$key][weight] = isset($extra[$key][weight]) ? $nodeapi[$key][weight] : -18;
+ }
+ $form = array_merge($form, $extra);
+ }
+ $form['submit'] = array(type => 'submit', value => t('Submit'));
if ($edit['vid']) {
- $form .= form_submit(t('Delete'));
- $form .= form_hidden('vid', $edit['vid']);
+ $form['delete'] = array(type => 'submit', value => t('Delete'));
+ $form['vid'] = array(type => 'hidden', value => $edit['vid']);
}
-
- return form($form);
+ return drupal_get_form('taxonomy_form_vocabulary', $form);
}
function taxonomy_save_vocabulary(&$edit) {
@@ -140,7 +145,7 @@ function taxonomy_save_vocabulary(&$edit) {
if ($edit['vid'] && $edit['name']) {
db_query('UPDATE {vocabulary} SET '. _taxonomy_prepare_update($data) .' WHERE vid = %d', $edit['vid']);
db_query("DELETE FROM {vocabulary_node_types} WHERE vid = %d", $edit['vid']);
- foreach ($edit['nodes'] as $type) {
+ foreach ($edit['nodes'] as $type => $selected) {
db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $edit['vid'], $type);
}
module_invoke_all('taxonomy', 'update', 'vocabulary', $edit);
@@ -152,7 +157,7 @@ function taxonomy_save_vocabulary(&$edit) {
else {
$data['vid'] = $edit['vid'] = db_next_id('{vocabulary}_vid');
db_query('INSERT INTO {vocabulary} '. _taxonomy_prepare_insert($data, 1) .' VALUES '. _taxonomy_prepare_insert($data, 2));
- foreach ($edit['nodes'] as $type) {
+ foreach ($edit['nodes'] as $type => $selected) {
db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $edit['vid'], $type);
}
module_invoke_all('taxonomy', 'insert', 'vocabulary', $edit);
@@ -184,28 +189,24 @@ function taxonomy_del_vocabulary($vid) {
function _taxonomy_confirm_del_vocabulary($vid) {
$vocabulary = taxonomy_get_vocabulary($vid);
- $extra = form_hidden('type', 'vocabulary');
- $extra .= form_hidden('vid', $vid);
- $extra .= form_hidden('name', $vocabulary->name);
-
- $output = theme('confirm',
- t('Are you sure you want to delete the vocabulary %title?', array('%title' => theme('placeholder', $vocabulary->name))),
- 'admin/taxonomy',
- t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'),
+ $form['type'] = array(type => 'hidden', value => 'vocabulary');
+ $form['vid'] = array(type => 'hidden', value => $vid);
+ $form['name'] = array(type => 'hidden', value => $vocabulary->name);
+ return confirm_form('vocabulary_confirm_delete', $form,
+ t('Are you sure you want to delete the vocabulary %title?',
+ array('%title' => theme('placeholder', $vocabulary->name))),
+ 'admin/taxonomy', t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'),
t('Delete'),
- t('Cancel'),
- $extra);
- return $output;
+ t('Cancel'));
}
function taxonomy_form_term($edit = array()) {
$vocabulary_id = isset($edit['vid']) ? $edit['vid'] : arg(4);
$vocabulary = taxonomy_get_vocabulary($vocabulary_id);
- $form = form_textfield(t('Term name'), 'name', $edit['name'], 60, 64, t('The name for this term. Example: "Linux".'), NULL, TRUE);
- // Prepend extra term form elements.
- $form .= implode('', module_invoke_all('taxonomy', 'form pre', 'term', $edit));
- $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('A description of the term.'));
+ $form['name'] = array(type => 'textfield', title => t('Term name'), default_value => $edit['name'], size => 60, maxlength => 64, description => t('The name for this term. Example: "Linux".'), required => TRUE);
+
+ $form['description'] = array(type => 'textarea', title => t('Description'), default_value => $edit['description'], cols => 60, rows => 5, description => t('A description of the term.'));
if ($vocabulary->hierarchy) {
$parent = array_keys(taxonomy_get_parents($edit['tid']));
@@ -218,33 +219,42 @@ function taxonomy_form_term($edit = array()) {
$exclude[] = $edit['tid'];
if ($vocabulary->hierarchy == 1) {
- $form .= _taxonomy_term_select(t('Parent'), 'parent', $parent, $vocabulary_id, l(t('Parent term'), 'admin/help/taxonomy', NULL, NULL, 'parent') .'.', 0, '<'. t('root') .'>', $exclude);
+ $form['parent'] = _taxonomy_term_select(t('Parent'), 'parent', $parent, $vocabulary_id, l(t('Parent term'), 'admin/help/taxonomy', NULL, NULL, 'parent') .'.', 0, '<'. t('root') .'>', $exclude);
}
elseif ($vocabulary->hierarchy == 2) {
- $form .= _taxonomy_term_select(t('Parents'), 'parent', $parent, $vocabulary_id, l(t('Parent terms'), 'admin/help/taxonomy', NULL, NULL, 'parent') .'.', 1, '<'. t('root') .'>', $exclude);
+ $form['parent'] = _taxonomy_term_select(t('Parents'), 'parent', $parent, $vocabulary_id, l(t('Parent terms'), 'admin/help/taxonomy', NULL, NULL, 'parent') .'.', 1, '<'. t('root') .'>', $exclude);
}
}
if ($vocabulary->relations) {
- $form .= _taxonomy_term_select(t('Related terms'), 'relations', array_keys(taxonomy_get_related($edit['tid'])), $vocabulary_id, NULL, 1, '<'. t('none') .'>', array($edit['tid']));
+ $form['relations'] = _taxonomy_term_select(t('Related terms'), 'relations', array_keys(taxonomy_get_related($edit['tid'])), $vocabulary_id, NULL, 1, '<'. t('none') .'>', array($edit['tid']));
}
- $form .= form_textarea(t('Synonyms'), 'synonyms', implode("\n", taxonomy_get_synonyms($edit['tid'])), 60, 5, t('<a href="%help-url">Synonyms</a> of this term, one synonym per line.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'synonyms'))));
- $form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('In listings, the heavier terms will sink and the lighter terms will be positioned nearer the top.'));
- // Append extra term form elements.
- $form .= implode('', module_invoke_all('taxonomy', 'form post', 'term', $edit));
- $form .= form_hidden('vid', $vocabulary->vid);
- $form .= form_submit(t('Submit'));
+ $form['synonyms'] = array(type => 'textarea', title => t('Synonyms'), default_value => implode("\n", taxonomy_get_synonyms($edit['tid'])), cols => 60, rows => 5, description => t('<a href="%help-url">Synonyms</a> of this term, one synonym per line.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'synonyms'))));
+ $form['weight'] = array(type => 'weight', title => t('Weight'), default_value => $edit['weight'], delta => 10, description => t('In listings, the heavier terms will sink and the lighter terms will be positioned nearer the top.'));
+
+ // Add extra term form elements.
+ $extra = module_invoke_all('taxonomy', 'term', 'vocabulary');
+ if (is_array($extra)) {
+ foreach ($extra as $key => $element) {
+ $extra[$key][weight] = isset($extra[$key][weight]) ? $nodeapi[$key][weight] : -18;
+ }
+ $form = array_merge($form, $extra);
+ }
+
+
+ $form['vid'] = array(type => 'hidden', value => $vocabulary->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']);
}
else {
- $form .= form_hidden('destination', $_GET['q']);
+ $form['destination'] = array(type => 'hidden', value => $_GET['q']);
}
- return form($form);
+ return drupal_get_form('taxonomy_form_term', $form);
}
function taxonomy_save_term(&$edit) {
@@ -343,18 +353,15 @@ function taxonomy_del_term($tid) {
function _taxonomy_confirm_del_term($tid) {
$term = taxonomy_get_term($tid);
- $extra = form_hidden('type', 'term');
- $extra .= form_hidden('tid', $tid);
-
- $output = theme('confirm',
- t('Are you sure you want to delete the term %title?', array('%title' => theme('placeholder', $term->name))),
+ $form['type'] = array(type => 'hidden', value => 'term');
+ $form['tid'] = array(type => 'hidden', value => $tid);
+ return confirm_form('term_confirm_delete', $form,
+ t('Are you sure you want to delete the term %title?',
+ array('%title' => theme('placeholder', $term->name))),
'admin/taxonomy',
t('Deleting a term will delete all its children if there are any. This action cannot be undone.'),
t('Delete'),
- t('Cancel'),
- $extra);
-
- return $output;
+ t('Cancel'));
}
/**
@@ -511,14 +518,18 @@ function taxonomy_node_form($type, $node = '', $help = NULL, $name = 'taxonomy')
}
}
$typed_string = implode(', ', $typed_terms) . (array_key_exists('tags', $terms) ? $terms['tags'][$vocabulary->vid] : NULL);
- $result[] = form_autocomplete($vocabulary->name, "$name][tags][". $vocabulary->vid, $typed_string, 60, 100, 'taxonomy/autocomplete/'. $vocabulary->vid, t('A comma-separated list of terms describing this content (Example: funny, bungie jumping, "Company, Inc.").'), NULL, ($vocabulary->required ? TRUE : FALSE));
+
+
+ $form[$name]['tags'][$vocabulary->vid] = array( type => textfield, default_value => $typed_string, size => 60, maxlength => 100,
+ autocomplete_path => 'taxonomy/autocomplete/'. $vocabulary->vid, required => ($vocabulary->required ? TRUE : FALSE), title => $vocabulary->name,
+ description => t('A comma-separated list of terms describing this content (Example: funny, bungie jumping, "Company, Inc.").') );
}
else {
$ntterms = array_key_exists('taxonomy', $node) ? $terms : array_keys($terms);
- $result[] = taxonomy_form($vocabulary->vid, $ntterms, $help, $name);
+ $form[$name][$vocabulary->vid] = taxonomy_form($vocabulary->vid, $ntterms, $help, $name);
}
}
- return $result ? $result : array();
+ return $form ? $form : array();
}
/**
@@ -889,8 +900,7 @@ function _taxonomy_term_select($title, $name, $value, $vocabulary_id, $descripti
$value = $tree[0]->tid;
}
}
-
- return form_select($title, $name . ($multiple ? '' : ']['), $value, $options, $description, $multiple ? 'size="'. min(12, count($options)) .'"' : 0, $multiple);
+ return array(type => 'select', title => $title, default_value => $value, options => $options, description => $description, multiple => $multiple, size => $multiple ? 'size="'. min(12, count($options)) .'"' : 0, weight => -15);
}
function _taxonomy_depth($depth, $graphic = '--') {
@@ -1288,5 +1298,3 @@ function taxonomy_autocomplete($vid, $string = '') {
exit();
}
}
-
-
diff --git a/modules/throttle.module b/modules/throttle.module
index 069729cf8..a5f08e1e7 100644
--- a/modules/throttle.module
+++ b/modules/throttle.module
@@ -121,12 +121,31 @@ function throttle_help($section) {
function throttle_settings() {
_throttle_validate(variable_get('throttle_anonymous', ''), 'throttle_anonymous');
_throttle_validate(variable_get('throttle_user', ''), 'throttle_user');
- $output = form_textfield(t('Auto-throttle on anonymous users'), 'throttle_anonymous', variable_get('throttle_anonymous', 0), 5, 6, t('The congestion control throttle can be automatically enabled when the number of anonymous users currently visiting your site exceeds the specified threshold. For example, to start the throttle when your site has 250 anonymous users online at once, enter \'250\' in this field. Leave this value blank or set to "0" if you do not wish to auto-throttle on anonymous users. You can inspect the current number of anonymous users using the "Who\'s online" block.'));
- $output .= form_textfield(t('Auto-throttle on authenticated users'), 'throttle_user', variable_get('throttle_user', 0), 5, 6, t('The congestion control throttle can be automatically enabled when the number of authenticated users currently visiting your site exceeds the specified threshold. For example, to start the throttle when your site has 50 registered users online at once, enter \'50\' in this field. Leave this value blank or set to "0" if you do not wish to auto-throttle on authenticated users. You can inspect the current number of authenticated users using the "Who\'s online" block.'));
$probabilities = array(0 => '100%', 1 => '50%', 2 => '33.3%', 3 => '25%', 4 => '20%', 5 => '16.6%', 7 => '12.5%', 9 => '10%', 19 => '5%', 99 => '1%', 199 => '.5%', 399 => '.25%', 989 => '.1%');
- $output .= form_select(t('Auto-throttle probability limiter'), 'throttle_probability_limiter', variable_get('throttle_probability_limiter', 9), $probabilities, t('The auto-throttle probability limiter is an efficiency mechanism to statistically reduce the overhead of the auto-throttle. The limiter is expressed as a percentage of page views, so for example if set to the default of 10% we only perform the extra database queries to update the throttle status 1 out of every 10 page views. The busier your site, the lower you should set the limiter value.'));
+
+ $form['throttle_anonymous'] = array(
+ type => 'textfield',
+ title => t('Auto-throttle on anonymous users'),
+ default_value => variable_get('throttle_anonymous', 0),
+ size => 5,
+ maxlength => 6,
+ description => t('The congestion control throttle can be automatically enabled when the number of anonymous users currently visiting your site exceeds the specified threshold. For example, to start the throttle when your site has 250 anonymous users online at once, enter \'250\' in this field. Leave this value blank or set to "0" if you do not wish to auto-throttle on anonymous users. You can inspect the current number of anonymous users using the "Who\'s online" block.')
+ );
+ $form['throttle_user'] = array(
+ type => 'textfield',
+ title => t('Auto-throttle on authenticated users'),
+ default_value => variable_get('throttle_user', 0),
+ size => 5,
+ maxlength => 6,
+ description => t('The congestion control throttle can be automatically enabled when the number of authenticated users currently visiting your site exceeds the specified threshold. For example, to start the throttle when your site has 50 registered users online at once, enter \'50\' in this field. Leave this value blank or set to "0" if you do not wish to auto-throttle on authenticated users. You can inspect the current number of authenticated users using the "Who\'s online" block.')
+ );
+ $form['throttle_probability_limiter'] = array(
+ type => 'select',
+ title => t('Auto-throttle probability limiter'),
+ default_value => variable_get('throttle_probability_limiter', 9),
+ options => $probabilities,
+ description => t('The auto-throttle probability limiter is an efficiency mechanism to statistically reduce the overhead of the auto-throttle. The limiter is expressed as a percentage of page views, so for example if set to the default of 10% we only perform the extra database queries to update the throttle status 1 out of every 10 page views. The busier your site, the lower you should set the limiter value.')
+ );
- return $output;
+ return $form;
}
-
-
diff --git a/modules/throttle/throttle.module b/modules/throttle/throttle.module
index 069729cf8..a5f08e1e7 100644
--- a/modules/throttle/throttle.module
+++ b/modules/throttle/throttle.module
@@ -121,12 +121,31 @@ function throttle_help($section) {
function throttle_settings() {
_throttle_validate(variable_get('throttle_anonymous', ''), 'throttle_anonymous');
_throttle_validate(variable_get('throttle_user', ''), 'throttle_user');
- $output = form_textfield(t('Auto-throttle on anonymous users'), 'throttle_anonymous', variable_get('throttle_anonymous', 0), 5, 6, t('The congestion control throttle can be automatically enabled when the number of anonymous users currently visiting your site exceeds the specified threshold. For example, to start the throttle when your site has 250 anonymous users online at once, enter \'250\' in this field. Leave this value blank or set to "0" if you do not wish to auto-throttle on anonymous users. You can inspect the current number of anonymous users using the "Who\'s online" block.'));
- $output .= form_textfield(t('Auto-throttle on authenticated users'), 'throttle_user', variable_get('throttle_user', 0), 5, 6, t('The congestion control throttle can be automatically enabled when the number of authenticated users currently visiting your site exceeds the specified threshold. For example, to start the throttle when your site has 50 registered users online at once, enter \'50\' in this field. Leave this value blank or set to "0" if you do not wish to auto-throttle on authenticated users. You can inspect the current number of authenticated users using the "Who\'s online" block.'));
$probabilities = array(0 => '100%', 1 => '50%', 2 => '33.3%', 3 => '25%', 4 => '20%', 5 => '16.6%', 7 => '12.5%', 9 => '10%', 19 => '5%', 99 => '1%', 199 => '.5%', 399 => '.25%', 989 => '.1%');
- $output .= form_select(t('Auto-throttle probability limiter'), 'throttle_probability_limiter', variable_get('throttle_probability_limiter', 9), $probabilities, t('The auto-throttle probability limiter is an efficiency mechanism to statistically reduce the overhead of the auto-throttle. The limiter is expressed as a percentage of page views, so for example if set to the default of 10% we only perform the extra database queries to update the throttle status 1 out of every 10 page views. The busier your site, the lower you should set the limiter value.'));
+
+ $form['throttle_anonymous'] = array(
+ type => 'textfield',
+ title => t('Auto-throttle on anonymous users'),
+ default_value => variable_get('throttle_anonymous', 0),
+ size => 5,
+ maxlength => 6,
+ description => t('The congestion control throttle can be automatically enabled when the number of anonymous users currently visiting your site exceeds the specified threshold. For example, to start the throttle when your site has 250 anonymous users online at once, enter \'250\' in this field. Leave this value blank or set to "0" if you do not wish to auto-throttle on anonymous users. You can inspect the current number of anonymous users using the "Who\'s online" block.')
+ );
+ $form['throttle_user'] = array(
+ type => 'textfield',
+ title => t('Auto-throttle on authenticated users'),
+ default_value => variable_get('throttle_user', 0),
+ size => 5,
+ maxlength => 6,
+ description => t('The congestion control throttle can be automatically enabled when the number of authenticated users currently visiting your site exceeds the specified threshold. For example, to start the throttle when your site has 50 registered users online at once, enter \'50\' in this field. Leave this value blank or set to "0" if you do not wish to auto-throttle on authenticated users. You can inspect the current number of authenticated users using the "Who\'s online" block.')
+ );
+ $form['throttle_probability_limiter'] = array(
+ type => 'select',
+ title => t('Auto-throttle probability limiter'),
+ default_value => variable_get('throttle_probability_limiter', 9),
+ options => $probabilities,
+ description => t('The auto-throttle probability limiter is an efficiency mechanism to statistically reduce the overhead of the auto-throttle. The limiter is expressed as a percentage of page views, so for example if set to the default of 10% we only perform the extra database queries to update the throttle status 1 out of every 10 page views. The busier your site, the lower you should set the limiter value.')
+ );
- return $output;
+ return $form;
}
-
-
diff --git a/modules/upload.module b/modules/upload.module
index f1f9b463c..21d004ff2 100644
--- a/modules/upload.module
+++ b/modules/upload.module
@@ -55,12 +55,6 @@ function upload_menu($may_cache) {
if ($may_cache) {
$items[] = array(
- 'path' => 'admin/settings/upload', 'title' => t('uploads'),
- 'callback' => 'upload_admin',
- 'access' => user_access('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM
- );
- $items[] = array(
'path' => 'upload/js',
'callback' => 'upload_js',
'access' => user_access('upload files'),
@@ -86,23 +80,32 @@ function upload_menu($may_cache) {
return $items;
}
-function upload_admin() {
- system_settings_save();
-
- $group .= form_textfield(t('Maximum resolution for uploaded images'), 'upload_max_resolution', variable_get('upload_max_resolution', 0), 15, 10, t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction.'));
-
- $output = form_group(t('General settings'), $group);
+function upload_settings() {
+ $form['settings_general'] = array(type => 'fieldset', title => t('General settings'));
+ $form['settings_general']['upload_max_resolution'] = array(
+ type => 'textfield', title => t('Maximum resolution for uploaded images'), default_value => variable_get('upload_max_resolution', 0),
+ size => 15, maxlength => 10, description => t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction.')
+ );
$roles = user_roles(0, 'upload files');
foreach ($roles as $rid => $role) {
- $group = form_textfield(t('Permitted file extensions'), "upload_extensions_$rid", variable_get("upload_extensions_$rid", "jpg jpeg gif png txt html doc xls pdf ppt pps"), 60, 255, t('Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.'));
- $group .= form_textfield(t('Maximum file size per upload'), "upload_uploadsize_$rid", variable_get("upload_uploadsize_$rid", 1), 5, 5, t('The maximum size of a file a user can upload (in megabytes).'));
- $group .= form_textfield(t('Total file size per user'), "upload_usersize_$rid", variable_get("upload_usersize_$rid", 10), 5, 5, t('The maximum size of all files a user can have on the site (in megabytes).'));
- $output .= form_group(t('Settings for %role', array('%role' => theme('placeholder', $role))), $group);
+ $form["settings_role_$rid"] = array(type => 'fieldset', title => t('Settings for %role', array('%role' => theme('placeholder', $role))), collapsible => TRUE, collapsed => TRUE);
+ $form["settings_role_$rid"]["upload_extensions_$rid"] = array(
+ type => 'textfield', title => t('Permitted file extensions'), default_value => variable_get("upload_extensions_$rid", "jpg jpeg gif png txt html doc xls pdf ppt pps"),
+ size => 60, maxlength => 255, description => t('Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.')
+ );
+ $form["settings_role_$rid"]["upload_uploadsize_$rid"] = array(
+ type => 'textfield', title => t('Maximum file size per upload'), default_value => variable_get("upload_uploadsize_$rid", 1),
+ size => 5, maxlength => 5, description => t('The maximum size of a file a user can upload (in megabytes).')
+ );
+ $form["settings_role_$rid"]["upload_usersize_$rid"] = array(
+ type => 'textfield', title => t('Total file size per user'), default_value => variable_get("upload_usersize_$rid", 10),
+ size => 5, maxlength => 5, description => t('The maximum size of all files a user can have on the site (in megabytes).')
+ );
}
- return system_settings_form($output);
+ return $form;
}
function upload_download() {
@@ -134,17 +137,13 @@ function upload_file_download($file) {
function upload_nodeapi(&$node, $op, $arg) {
switch ($op) {
case 'settings':
- return form_radios(t('Attachments'), 'upload_'. $node->type, variable_get('upload_'. $node->type, 1), array(t('Disabled'), t('Enabled')));
-
- case 'form param':
- if (variable_get("upload_$node->type", 1) && user_access('upload files')) {
- $output['options'] = array('enctype' => 'multipart/form-data');
- }
- break;
-
+ $form['upload_'. $node->type] = array(
+ type => 'radios', title => t('Attachments'), default_value => variable_get('upload_'. $node->type, 1),
+ options => array(t('Disabled'), t('Enabled'))
+ );
+ return $form;
case 'validate':
$node->files = upload_load($node);
-
// Double check existing files:
if (is_array($node->list)) {
foreach ($node->list as $key => $value) {
@@ -164,12 +163,10 @@ function upload_nodeapi(&$node, $op, $arg) {
$node->list[$key] = $file->list;
}
}
-
if (($file = file_check_upload('upload')) && user_access('upload files')) {
global $user;
$file = _upload_image($file);
-
// Don't do any checks for uid #1.
if ($user->uid != 1) {
// Validate file against all users roles. Only denies an upload when
@@ -221,11 +218,18 @@ function upload_nodeapi(&$node, $op, $arg) {
$node->files[$key] = $file;
}
}
+ for ($x = 0; $x < count($_SESSION['file_uploads']); $x++) {
+ $key = 'upload_' . $x;
+ if ($file = file_check_upload($key)) {
+ $node->files[$key] = $file;
+ }
+ }
break;
- case 'form post':
+ case 'form':
if (variable_get("upload_$node->type", 1) == 1 && user_access('upload files')) {
$output = upload_form($node);
+ $output[attributes] = array('enctype' => 'multipart/form-data');
}
break;
@@ -388,9 +392,14 @@ function upload_form($node) {
drupal_add_js('misc/progress.js');
drupal_add_js('misc/upload.js');
- $output = '<div id="fileop-wrapper">'. _upload_form($node) .'</div>';
+ $form['attachments'] = array(
+ type => 'fieldset', title => t('File attachments'), collapsible => TRUE, collapsed => empty($node->files),
+ description => t('Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.'),
+ prefix => '<div class="attachments">', suffix => '</div>', weight => 15
+ );
+ $form['attachments'] += _upload_form($node);
- return '<div class="attachments">'. form_group_collapsible(t('File attachments'), $output, empty($node->files), t('Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.')) .'</div>';
+ return $form;
}
function _upload_form($node) {
@@ -398,30 +407,59 @@ function _upload_form($node) {
$rows = array();
$output = '';
- if (is_array($node->files)) {
+ $form[theme] = 'upload_form_new';
+ if (is_array($node->files) && count($node->files)) {
+ $form['current'][theme] = 'upload_form_current';
+ $form['current']['description'][tree] = TRUE;
foreach ($node->files as $key => $file) {
- $rows[] = array(
- form_checkbox('', "remove][$key", 1, $file->remove),
- form_checkbox('', "list][$key", 1, $file->list),
- form_textfield('', "description][$key", $file->description ? $file->description : $file->filename, 60, 256) ."<br /><small>". file_create_url(($file->fid ? $file->filepath : file_create_filename($file->filename, file_create_path()))) ."</small>",
- format_size($file->filesize)
- );
+ $options[$key] = '';
+ if ($file->remove) {
+ $remove[] = $key;
+ }
+ if ($file->list) {
+ $list[] = $key;
+ }
+ $description = "<small>". file_create_url(($file->fid ? $file->filepath : file_create_filename($file->filename, file_create_path()))) ."</small>";
+ $form['current']['description'][$key] = array(type => 'textfield', default_value => $file->description ? $file->description : $file->filename, size => 60, maxlength => 256, description => $description );
+ $form['current']['size'][$key] = array(type => 'markup', value => format_size($file->filesize));
}
- }
-
- if (count($node->files)) {
- $output .= theme('table', $header, $rows);
+ $form['current']['remove'] = array(type => 'checkboxes', options => $options, default_value => $remove);
+ $form['current']['list'] = array(type => 'checkboxes', options => $options, default_value => $list);
+ $form['files'][$key] = array(type => 'hidden', value => 1);
}
if (user_access('upload files')) {
- $output .= '<div id="fileop-hide">';
- $output .= form_file(t('Attach new file'), "upload", 40);
- $output .= form_button(t('Attach'), 'fileop');
+
+ $form['new']['upload'] = array(type => 'file', title => t('Attach new file'), size => 40);
+ $form['new']['fileop'] = array(type => 'button', value => t('Attach'), name=> 'fileop', attributes => array('id' => 'fileop'));
// The class triggers the js upload behaviour.
- $output .= form_hidden('fileop', url('upload/js', NULL, NULL, TRUE), 'edit', array('class' => 'upload'));
- $output .= '</div>';
+ $form['fileop'] = array(type => 'hidden', value => url('upload/js', NULL, NULL, TRUE), attributes => array('class' => 'upload'));
}
+ return $form;
+}
+
+function theme_upload_form_new($form) {
+ $output .= '<div id="fileop-wrapper">' . "\n";
+ $output .= '<div id="fileop-hide">' . "\n";
+ $output .= form_render($form) . "\n";
+ $output .= "</div>\n";
+ $output .= "</div>\n";
+ return $output;
+}
+
+function theme_upload_form_current(&$form) {
+ $header = array(t('Delete'), t('List'), t('Description'), t('Size'));
+ foreach (element_children($form['description']) as $key) {
+ $row = array();
+ $row[] = form_render($form['remove'][$key]);
+ $row[] = form_render($form['list'][$key]);
+ $row[] = form_render($form['description'][$key]);
+ $row[] = form_render($form['size'][$key]);
+ $rows[] = $row;
+ }
+ $output = theme('table', $header, $rows);
+ $output .= form_render($form);
return $output;
}
@@ -466,7 +504,9 @@ function upload_js() {
// We only do the upload.module part of the node validation process.
$node = array2object($_POST['edit']);
upload_nodeapi($node, 'validate', NULL);
- $output = theme('status_messages') . _upload_form($node);
+ $form = _upload_form($node);
+ $form = _form_builder($form);
+ $output = theme('status_messages') . form_render($form);
// We send the updated file attachments form.
print drupal_call_js('window.parent.iframeHandler', $output);
diff --git a/modules/upload/upload.module b/modules/upload/upload.module
index f1f9b463c..21d004ff2 100644
--- a/modules/upload/upload.module
+++ b/modules/upload/upload.module
@@ -55,12 +55,6 @@ function upload_menu($may_cache) {
if ($may_cache) {
$items[] = array(
- 'path' => 'admin/settings/upload', 'title' => t('uploads'),
- 'callback' => 'upload_admin',
- 'access' => user_access('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM
- );
- $items[] = array(
'path' => 'upload/js',
'callback' => 'upload_js',
'access' => user_access('upload files'),
@@ -86,23 +80,32 @@ function upload_menu($may_cache) {
return $items;
}
-function upload_admin() {
- system_settings_save();
-
- $group .= form_textfield(t('Maximum resolution for uploaded images'), 'upload_max_resolution', variable_get('upload_max_resolution', 0), 15, 10, t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction.'));
-
- $output = form_group(t('General settings'), $group);
+function upload_settings() {
+ $form['settings_general'] = array(type => 'fieldset', title => t('General settings'));
+ $form['settings_general']['upload_max_resolution'] = array(
+ type => 'textfield', title => t('Maximum resolution for uploaded images'), default_value => variable_get('upload_max_resolution', 0),
+ size => 15, maxlength => 10, description => t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction.')
+ );
$roles = user_roles(0, 'upload files');
foreach ($roles as $rid => $role) {
- $group = form_textfield(t('Permitted file extensions'), "upload_extensions_$rid", variable_get("upload_extensions_$rid", "jpg jpeg gif png txt html doc xls pdf ppt pps"), 60, 255, t('Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.'));
- $group .= form_textfield(t('Maximum file size per upload'), "upload_uploadsize_$rid", variable_get("upload_uploadsize_$rid", 1), 5, 5, t('The maximum size of a file a user can upload (in megabytes).'));
- $group .= form_textfield(t('Total file size per user'), "upload_usersize_$rid", variable_get("upload_usersize_$rid", 10), 5, 5, t('The maximum size of all files a user can have on the site (in megabytes).'));
- $output .= form_group(t('Settings for %role', array('%role' => theme('placeholder', $role))), $group);
+ $form["settings_role_$rid"] = array(type => 'fieldset', title => t('Settings for %role', array('%role' => theme('placeholder', $role))), collapsible => TRUE, collapsed => TRUE);
+ $form["settings_role_$rid"]["upload_extensions_$rid"] = array(
+ type => 'textfield', title => t('Permitted file extensions'), default_value => variable_get("upload_extensions_$rid", "jpg jpeg gif png txt html doc xls pdf ppt pps"),
+ size => 60, maxlength => 255, description => t('Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.')
+ );
+ $form["settings_role_$rid"]["upload_uploadsize_$rid"] = array(
+ type => 'textfield', title => t('Maximum file size per upload'), default_value => variable_get("upload_uploadsize_$rid", 1),
+ size => 5, maxlength => 5, description => t('The maximum size of a file a user can upload (in megabytes).')
+ );
+ $form["settings_role_$rid"]["upload_usersize_$rid"] = array(
+ type => 'textfield', title => t('Total file size per user'), default_value => variable_get("upload_usersize_$rid", 10),
+ size => 5, maxlength => 5, description => t('The maximum size of all files a user can have on the site (in megabytes).')
+ );
}
- return system_settings_form($output);
+ return $form;
}
function upload_download() {
@@ -134,17 +137,13 @@ function upload_file_download($file) {
function upload_nodeapi(&$node, $op, $arg) {
switch ($op) {
case 'settings':
- return form_radios(t('Attachments'), 'upload_'. $node->type, variable_get('upload_'. $node->type, 1), array(t('Disabled'), t('Enabled')));
-
- case 'form param':
- if (variable_get("upload_$node->type", 1) && user_access('upload files')) {
- $output['options'] = array('enctype' => 'multipart/form-data');
- }
- break;
-
+ $form['upload_'. $node->type] = array(
+ type => 'radios', title => t('Attachments'), default_value => variable_get('upload_'. $node->type, 1),
+ options => array(t('Disabled'), t('Enabled'))
+ );
+ return $form;
case 'validate':
$node->files = upload_load($node);
-
// Double check existing files:
if (is_array($node->list)) {
foreach ($node->list as $key => $value) {
@@ -164,12 +163,10 @@ function upload_nodeapi(&$node, $op, $arg) {
$node->list[$key] = $file->list;
}
}
-
if (($file = file_check_upload('upload')) && user_access('upload files')) {
global $user;
$file = _upload_image($file);
-
// Don't do any checks for uid #1.
if ($user->uid != 1) {
// Validate file against all users roles. Only denies an upload when
@@ -221,11 +218,18 @@ function upload_nodeapi(&$node, $op, $arg) {
$node->files[$key] = $file;
}
}
+ for ($x = 0; $x < count($_SESSION['file_uploads']); $x++) {
+ $key = 'upload_' . $x;
+ if ($file = file_check_upload($key)) {
+ $node->files[$key] = $file;
+ }
+ }
break;
- case 'form post':
+ case 'form':
if (variable_get("upload_$node->type", 1) == 1 && user_access('upload files')) {
$output = upload_form($node);
+ $output[attributes] = array('enctype' => 'multipart/form-data');
}
break;
@@ -388,9 +392,14 @@ function upload_form($node) {
drupal_add_js('misc/progress.js');
drupal_add_js('misc/upload.js');
- $output = '<div id="fileop-wrapper">'. _upload_form($node) .'</div>';
+ $form['attachments'] = array(
+ type => 'fieldset', title => t('File attachments'), collapsible => TRUE, collapsed => empty($node->files),
+ description => t('Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.'),
+ prefix => '<div class="attachments">', suffix => '</div>', weight => 15
+ );
+ $form['attachments'] += _upload_form($node);
- return '<div class="attachments">'. form_group_collapsible(t('File attachments'), $output, empty($node->files), t('Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.')) .'</div>';
+ return $form;
}
function _upload_form($node) {
@@ -398,30 +407,59 @@ function _upload_form($node) {
$rows = array();
$output = '';
- if (is_array($node->files)) {
+ $form[theme] = 'upload_form_new';
+ if (is_array($node->files) && count($node->files)) {
+ $form['current'][theme] = 'upload_form_current';
+ $form['current']['description'][tree] = TRUE;
foreach ($node->files as $key => $file) {
- $rows[] = array(
- form_checkbox('', "remove][$key", 1, $file->remove),
- form_checkbox('', "list][$key", 1, $file->list),
- form_textfield('', "description][$key", $file->description ? $file->description : $file->filename, 60, 256) ."<br /><small>". file_create_url(($file->fid ? $file->filepath : file_create_filename($file->filename, file_create_path()))) ."</small>",
- format_size($file->filesize)
- );
+ $options[$key] = '';
+ if ($file->remove) {
+ $remove[] = $key;
+ }
+ if ($file->list) {
+ $list[] = $key;
+ }
+ $description = "<small>". file_create_url(($file->fid ? $file->filepath : file_create_filename($file->filename, file_create_path()))) ."</small>";
+ $form['current']['description'][$key] = array(type => 'textfield', default_value => $file->description ? $file->description : $file->filename, size => 60, maxlength => 256, description => $description );
+ $form['current']['size'][$key] = array(type => 'markup', value => format_size($file->filesize));
}
- }
-
- if (count($node->files)) {
- $output .= theme('table', $header, $rows);
+ $form['current']['remove'] = array(type => 'checkboxes', options => $options, default_value => $remove);
+ $form['current']['list'] = array(type => 'checkboxes', options => $options, default_value => $list);
+ $form['files'][$key] = array(type => 'hidden', value => 1);
}
if (user_access('upload files')) {
- $output .= '<div id="fileop-hide">';
- $output .= form_file(t('Attach new file'), "upload", 40);
- $output .= form_button(t('Attach'), 'fileop');
+
+ $form['new']['upload'] = array(type => 'file', title => t('Attach new file'), size => 40);
+ $form['new']['fileop'] = array(type => 'button', value => t('Attach'), name=> 'fileop', attributes => array('id' => 'fileop'));
// The class triggers the js upload behaviour.
- $output .= form_hidden('fileop', url('upload/js', NULL, NULL, TRUE), 'edit', array('class' => 'upload'));
- $output .= '</div>';
+ $form['fileop'] = array(type => 'hidden', value => url('upload/js', NULL, NULL, TRUE), attributes => array('class' => 'upload'));
}
+ return $form;
+}
+
+function theme_upload_form_new($form) {
+ $output .= '<div id="fileop-wrapper">' . "\n";
+ $output .= '<div id="fileop-hide">' . "\n";
+ $output .= form_render($form) . "\n";
+ $output .= "</div>\n";
+ $output .= "</div>\n";
+ return $output;
+}
+
+function theme_upload_form_current(&$form) {
+ $header = array(t('Delete'), t('List'), t('Description'), t('Size'));
+ foreach (element_children($form['description']) as $key) {
+ $row = array();
+ $row[] = form_render($form['remove'][$key]);
+ $row[] = form_render($form['list'][$key]);
+ $row[] = form_render($form['description'][$key]);
+ $row[] = form_render($form['size'][$key]);
+ $rows[] = $row;
+ }
+ $output = theme('table', $header, $rows);
+ $output .= form_render($form);
return $output;
}
@@ -466,7 +504,9 @@ function upload_js() {
// We only do the upload.module part of the node validation process.
$node = array2object($_POST['edit']);
upload_nodeapi($node, 'validate', NULL);
- $output = theme('status_messages') . _upload_form($node);
+ $form = _upload_form($node);
+ $form = _form_builder($form);
+ $output = theme('status_messages') . form_render($form);
// We send the updated file attachments form.
print drupal_call_js('window.parent.iframeHandler', $output);
diff --git a/modules/user.module b/modules/user.module
index 7de7430e6..3c8810d75 100644
--- a/modules/user.module
+++ b/modules/user.module
@@ -467,7 +467,8 @@ function user_search($op = 'search', $keys = null) {
*/
function user_user($type, &$edit, &$user, $category = NULL) {
if ($type == 'view') {
- return array(t('History') => array('history'=> form_item(t('Member for'), format_interval(time() - $user->created))));
+ $form['member'] = array(type => 'item', title => t('Member for'), value => format_interval(time() - $user->created));
+ return array(t('History') => array('history'=> drupal_get_form('member', $form)));
}
if ($type == 'form' && $category == 'account') {
@@ -499,10 +500,11 @@ function user_block($op = 'list', $delta = 0, $edit = array()) {
}
else if ($op == 'configure' && $delta == 3) {
$period = drupal_map_assoc(array(30, 60, 120, 180, 300, 600, 900, 1800, 2700, 3600, 5400, 7200, 10800, 21600, 43200, 86400), 'format_interval');
- $output = form_select(t('User activity'), 'user_block_seconds_online', variable_get('user_block_seconds_online', 900), $period, t('A user is considered online for this long after they have last viewed a page.'));
- $output .= form_select(t('User list length'), 'user_block_max_list_count', variable_get('user_block_max_list_count', 10), drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 40, 50, 75, 100)), t('Maximum number of currently online users to display.'));
+ $form['user_block_seconds_online'] = array(type => 'select', title => t('User activity'), default_value => variable_get('user_block_seconds_online', 900), options => $period, description => t('A user is considered online for this long after they have last viewed a page.'));
+ $form['user_block_max_list_count'] = array(type => 'select', title => t('User list length'), default_value => variable_get('user_block_max_list_count', 10), options => drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 40, 50, 75, 100)), description => t('Maximum number of currently online users to display.'));
- return $output;
+ //return drupal_get_form('user_block', $form);
+ return $form;
}
else if ($op == 'save' && $delta == 3) {
variable_set('user_block_seconds_online', $edit['user_block_seconds_online']);
@@ -515,18 +517,10 @@ function user_block($op = 'list', $delta = 0, $edit = array()) {
case 0:
// For usability's sake, avoid showing two login forms on one page.
if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {
- $edit = $_POST['edit'];
-
- // NOTE: special care needs to be taken because on pages with forms,
- // such as node and comment submission pages, the $edit variable
- // might already be set.
-
- $output .= form_textfield(t('Username'), 'name', $edit['name'], 15, 64);
- $output .= form_password(t('Password'), 'pass', '', 15, 64);
- $output .= form_submit(t('Log in'));
-
- $output = form($output, 'post', url('user/login', drupal_get_destination()), array('id' => 'user-login-form'));
-
+ $form['name'] = array(type => 'textfield', title => t('Username'), maxlength => 64, size => 15, required => TRUE);
+ $form['pass'] = array(type => 'password', title => t('Password'), maxlength => 64, size => 15, required => TRUE);
+ $form['submit'] = array(type => 'submit', value => t('Log in'));
+ $output .= drupal_get_form('user_login_block', $form, 'user_login');
if (variable_get('user_register', 1)) {
$items[] = l(t('Create new account'), 'user/register', array('title' => t('Create a new user account.')));
}
@@ -597,6 +591,15 @@ function user_block($op = 'list', $delta = 0, $edit = array()) {
}
}
+
+
+function theme_user_login_block($form) {
+ $output = "<div class=\"user-login-block\">\n";
+ $output .= form_render($form);
+ $output .= "</div>\n";
+ return $output;
+}
+
function theme_user_picture($account) {
if (variable_get('user_pictures', 0)) {
if ($account->picture && file_exists($account->picture)) {
@@ -827,6 +830,8 @@ function user_auth_help_links() {
/*** User features *********************************************************/
+
+
function user_login($edit = array(), $msg = '') {
global $user, $base_url;
@@ -872,6 +877,7 @@ function user_login($edit = array(), $msg = '') {
// Display error message (if any):
if ($error) {
+ $form['error'] = array(type => 'value', value => 1);
drupal_set_message($error, 'error');
}
@@ -879,16 +885,23 @@ function user_login($edit = array(), $msg = '') {
if ($msg) {
$output .= "<p>$msg</p>";
}
+ $form['name'] = array(type => 'textfield', title => t('Username'), size => 30, maxlength => 64, required => TRUE);
if (count(user_auth_help_links()) > 0) {
- $output .= form_textfield(t('Username'), 'name', $edit['name'], 30, 64, t('Enter your %s username, or an ID from one of our affiliates: %a.', array('%s' => variable_get('site_name', 'local'), '%a' => implode(', ', user_auth_help_links()))));
+ $form['name'][description] = t('Enter your %s username, or an ID from one of our affiliates: %a.', array('%s' => variable_get('site_name', 'local'), '%a' => implode(', ', user_auth_help_links())));
}
else {
- $output .= form_textfield(t('Username'), 'name', $edit['name'], 30, 64, t('Enter your %s username.', array('%s' => variable_get('site_name', 'local'))));
+ $form['name'][description] = t('Enter your %s username.', array('%s' => variable_get('site_name', 'local')));
}
- $output .= form_password(t('Password'), 'pass', $pass, 30, 64, t('Enter the password that accompanies your username.'));
- $output .= form_submit(t('Log in'));
+ $form['pass'] = array(type => 'password', title => t('Password'), size => 30, maxlength => 64, description => t('Enter the password that accompanies your username.'), required => TRUE);
+ $form['submit'] = array(type => 'submit', value => t('Log in'), weight => 2);
+ return drupal_get_form('user_login', $form);
+}
- return form($output, 'post', url('user/login', drupal_get_destination()));
+function user_login_execute($form) {
+ global $form_values;
+ if (!isset($form_values['error'])) {
+ return user_login($form_values);
+ }
}
function user_authenticate($name, $pass) {
@@ -991,14 +1004,19 @@ function user_pass() {
drupal_set_message(t('You must provide either a username or e-mail address.'), 'error');
}
// Display form:
- $output = '<p>'. t('Enter your username <strong><em>or</em></strong> your e-mail address.') .'</p>';
- $output .= form_textfield(t('Username'), 'name', $edit['name'], 30, 64);
- $output .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 64);
- $output .= form_submit(t('E-mail new password'));
- return form($output);
+ $form['name'] = array(type => 'textfield', title => t('Username'), default_value => $edit['name'], size => 30, maxlength => 64);
+ $form['mail'] = array(type => 'textfield', title => t('E-mail address'), default_value => $edit['mail'], size => 30, maxlength => 64);
+ $form['submit'] = array(type => 'submit', value => t('E-mail new password'));
+ return drupal_get_form('user_logout', $form);
}
}
+function theme_user_logout($form) {
+ $output = '<p>'. t('Enter your username <strong><em>or</em></strong> your e-mail address.') .'</p>';
+ $output .= form_render($form);
+ return $output;
+}
+
/**
* Menu callback; process one time login URL, and redirects to the user page on success.
*/
@@ -1075,12 +1093,12 @@ function user_register($edit = array()) {
if ($account->uid == 1) {
user_mail($edit['mail'], t('drupal user account details for %s', array('%s' => $edit['name'])), strtr(t("%username,\n\nYou may now login to %uri using the following username and password:\n\n username: %username\n password: %password\n\n%edit_uri\n\n--drupal"), $variables), "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");
// This should not be t()'ed. No point as its only shown once in the sites lifetime, and it would be bad to store the password.
- $output .= "<p>Welcome to Drupal. You are user #1, which gives you full and immediate access. All future registrants will receive their passwords via e-mail, so please configure your e-mail settings using the Administration pages.</p><p> Your password is <strong>$pass</strong>. You may change your password on the next page.</p><p>Please login below.</p>";
- $output .= form_hidden('destination', 'user/'. $account->uid .'/edit');
- $output .= form_hidden('name', $account->name);
- $output .= form_hidden('pass', $pass);
- $output .= form_submit(t('Log in'));
- return form($output);
+ $form['instructions'] = array(type => 'markup', value => "<p>Welcome to Drupal. You are user #1, which gives you full and immediate access. All future registrants will receive their passwords via e-mail, so please configure your e-mail settings using the Administration pages.</p><p> Your password is <strong>$pass</strong>. You may change your password on the next page.</p><p>Please login below.</p>");
+ $form[action] = 'user/'. $account->uid .'/edit';
+ $form['name'] = array(type => 'hidden', value => $account->name);
+ $form['pass'] = array(type => 'hidden', value => $pass);
+ $form['submit'] = array(type => 'submit', value => t('Log in'));
+ return drupal_get_form('user_register', $form);
}
else {
if ($admin) {
@@ -1109,57 +1127,57 @@ function user_register($edit = array()) {
}
// Display the registration form.
- $output .= variable_get('user_registration_help', '');
+ $form['user_registration_help'] = array(type => 'markup', value => variable_get('user_registration_help', ''));
$affiliates = user_auth_help_links();
if (!$admin && count($affiliates) > 0) {
$affiliates = implode(', ', $affiliates);
- $output .= '<p>'. t('Note: if you have an account with one of our affiliates (%s), you may <a href="%login_uri">login now</a> instead of registering.', array('%s' => $affiliates, '%login_uri' => url('user'))) .'</p>';
+ $form['affiliates'] = array(type => 'markup', value => '<p>'. t('Note: if you have an account with one of our affiliates (%s), you may <a href="%login_uri">login now</a> instead of registering.', array('%s' => $affiliates, '%login_uri' => url('user'))) .'</p>');
}
- $default = form_textfield(t('Username'), 'name', $edit['name'], 30, 64, t('Your full name or your preferred username; only letters, numbers and spaces are allowed.'), NULL, TRUE);
- $default .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 64, t('A password and instructions will be sent to this e-mail address, so make sure it is accurate.'), NULL, TRUE);
+ $form['name'] = array(type => 'textfield', title => t('Username'), default_value => $edit['name'], size => 30, maxlength => 64, description => t('Your full name or your preferred username; only letters, numbers and spaces are allowed.'), required => TRUE);
+ $form['mail'] = array(type => 'textfield', title => t('E-mail address'), default_value => $edit['mail'], size => 30, maxlength => 64, description => t('A password and instructions will be sent to this e-mail address, so make sure it is accurate.'), required => TRUE);
if ($admin) {
- $default .= form_password(t('Password'), 'pass', $edit['pass'], 30, 55,t('Provide a password for the new account.'), NULL, TRUE);
+ $form['pass'] = array(type => 'password', title => t('Password'), default_value => $edit['pass'], size => 30, maxlength => 55, description => t('Provide a password for the new account.'), required => TRUE);
}
$extra = _user_forms($edit, $account, $category, 'register');
// Only display form_group around default fields if there are other groups.
if ($extra) {
- $output .= form_group(t('Account information'), $default);
- $output .= $extra;
- }
- else {
- $output .= $default;
- }
- $output .= form_submit(t('Create new account'));
+ $form['account'] = array(type => 'fieldset', value => t('Account information'));
+ $form['account']['name'] = $form['name'];
+ $form['account']['mail'] = $form['mail'];
+ $form['account']['pass'] = $form['pass'];
+ unset($form['name']);
+ unset($form['mail']);
+ unset($form['pass']);
+ $form = array_merge($form, $extra);
+ }
+ $form['submit'] = array(type => 'submit', value => t('Create new account'), weight => 30);
- return form($output);
+ return drupal_get_form('user_register', $form);
}
function user_edit_form($uid, $edit) {
// Account information:
- $group = form_textfield(t('Username'), 'name', $edit['name'], 60, 55, t('Your full name or your preferred username: only letters, numbers and spaces are allowed.'), NULL, TRUE);
- $group .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 60, 55, t('Insert a valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'), NULL, TRUE);
- $group .= form_item(t('Password'), '<input type="password" class="form-password" name="edit[pass1]" size="12" maxlength="24" /> <input type="password" class="form-password" name="edit[pass2]" size="12" maxlength="24" />', t('Enter your new password twice if you want to change your current password, or leave it blank if you are happy with your current password.'), NULL, TRUE);
-
+ $form['account'] = array(type => 'fieldset', title => t('Account information'), weight => 0);
+ $form['account']['name'] = array(type => 'textfield', title => t('Username'), default_value => $edit['name'], size => 60, maxlength => 55, description => t('Your full name or your preferred username: only letters, numbers and spaces are allowed.'), required => TRUE);
+ $form['account']['mail'] = array(type => 'textfield', title => t('E-mail address'), default_value => $edit['mail'], size => 60, maxlength => 55, description => t('Insert a valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'), required => TRUE);
+ $form['account']['pass'] = array(type => 'item', title => t('Password'), value => '<input type="password" class="form-password" name="edit[pass1]" size="12" maxlength="24" /> <input type="password" class="form-password" name="edit[pass2]" size="12" maxlength="24" />', required => true);
if (user_access('administer access control')) {
- $group .= form_radios(t('Status'), 'status', $edit['status'], array(t('Blocked'), t('Active')));
- $group .= form_checkboxes(t('Roles'), 'roles', array_keys($edit['roles']), user_roles(1), t('Select at least one role. The user receives the combined permissions of all of the selected roles.'), NULL, TRUE);
+ $form['account']['status'] = array(type => 'radios', title => t('Status'), default_value => $edit['status'], options => array(t('Blocked'), t('Active')));
+ $form['account']['roles'] = array(type => 'checkboxes', title => t('Roles'), default_value => array_keys($edit['roles']), options => user_roles(1), description => t('Select at least one role. The user receives the combined permissions of all of the selected roles.'), required => TRUE);
}
- $data[] = array('title' => t('Account information'), 'data' => $group, 'weight' => 0);
-
// Picture/avatar:
if (variable_get('user_pictures', 0)) {
- $group = '';
+ $form['picture'] = array(type => 'fieldset', title => t('Picture'), weight => 1);
if ($edit['picture'] && ($picture = theme('user_picture', array2object($edit)))) {
- $group .= $picture;
- $group .= form_checkbox(t('Delete picture'), 'picture_delete', 1, 0, t('Check this box to delete your current picture.'));
+ $form['picture']['current_picture'] = array(type => 'markup', value => $picture);
+ $form['picture']['picture_delete'] = array(type => 'checkbox', title => t('Delete picture'), return_value => 1, default_value => 0, description => t('Check this box to delete your current picture.'));
}
- $group .= form_file(t('Upload picture'), 'picture', 48, t('Your virtual face or picture. Maximum dimensions are %dimensions and the maximum size is %size kB.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'), '%size' => variable_get('user_picture_file_size', '30'))) .' '. variable_get('user_picture_guidelines', ''));
- $data[] = array('title' => t('Picture'), 'data' => $group, 'weight' => 1);
+ $form['picture']['picture'] = array(type => 'file', title => t('Upload picture'), size => 48, description => t('Your virtual face or picture. Maximum dimensions are %dimensions and the maximum size is %size kB.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'), '%size' => variable_get('user_picture_file_size', '30'))) .' '. variable_get('user_picture_guidelines', ''));
}
- return $data;
+ return $form;
}
function user_edit_validate($uid, &$edit) {
@@ -1191,12 +1209,6 @@ function user_edit_validate($uid, &$edit) {
form_set_error('roles', t('You must select at least one role.'));
$edit['roles'] = array();
}
- else {
- // Before form submission, $edit['roles'] contains ('role id' => 'role name') tuples.
- // After form submission, $edit['roles'] contains ('number' => 'role id') tuples. We
- // flip the array to always have the role id's in the keys.
- $edit['roles'] = array_flip($edit['roles']);
- }
}
// If required, validate the uploaded picture.
@@ -1262,12 +1274,7 @@ function user_edit($category = 'account') {
drupal_goto('admin/user');
}
else {
- $output = theme('confirm',
- t('Are you sure you want to delete the account %name?', array('%name' => theme('placeholder', $account->name))),
- 'user/'. $account->uid,
- t('Deleting a user will remove all their submissions as well. This action cannot be undone.'),
- t('Delete'));
- return $output;
+ return confirm_form('user_confirm_delete', $form, t('Are you sure you want to delete the account %name?', array('%name' => theme('placeholder', $account->name))), 'user/'. $account->uid, t('Deleting a user will remove all their submissions as well. This action cannot be undone.'), t('Delete'));
}
}
else if ($_POST['op'] == t('Delete')) {
@@ -1275,15 +1282,15 @@ function user_edit($category = 'account') {
drupal_goto("user/$account->uid/delete");
}
- $output = _user_forms($edit, $account, $category);
- $output .= form_submit(t('Submit'));
+ $form = _user_forms($edit, $account, $category);
+ $form['submit'] = array(type => 'submit', value => t('Submit'), weight => 30);
if (user_access('administer users')) {
- $output .= form_submit(t('Delete'));
+ $form['delete'] = array(type => 'submit', value => t('Delete'), weight => 30);
}
- $output = form($output, 'post', 0, array('enctype' => 'multipart/form-data'));
+ $form[attributes] = array('enctype' => 'multipart/form-data');
drupal_set_title($account->name);
- return $output;
+ return drupal_get_form('user_edit', $form);
}
function user_view($uid = 0) {
@@ -1322,10 +1329,6 @@ function user_page() {
case 'register':
return user_register($edit);
break;
- case t('Log in'):
- case 'login':
- return user_login($edit);
- break;
default:
if (!arg(1)) {
if ($user->uid) {
@@ -1370,36 +1373,6 @@ function _user_mail_text($messageid, $variables = array()) {
}
function user_configure_settings() {
- // User registration settings.
- $group = form_radios(t('Public registrations'), 'user_register', variable_get('user_register', 1), array(t('Only site administrators can create new user accounts.'), t('Visitors can create accounts and no administrator approval is required.'), t('Visitors can create accounts but administrator approval is required.')));
- $group .= form_textarea(t('User registration guidelines'), 'user_registration_help', variable_get('user_registration_help', ''), 60, 5, t('This text is displayed at the top of the user registration form. It\'s useful for helping or instructing your users.'));
- $output = form_group(t('User registration settings'), $group);
-
- // User e-mail settings.
- $group = form_textfield(t('Subject of welcome e-mail'), 'user_mail_welcome_subject', _user_mail_text('welcome_subject'), 60, 180, t('Customize the subject of your welcome e-mail, which is sent to new members upon registering.') .' '. t('Available variables are:') .' %username, %site, %password, %uri, %uri_brief, %mailto, %date, %login_uri, %edit_uri, %login_url.');
- $group .= form_textarea(t('Body of welcome e-mail'), 'user_mail_welcome_body', _user_mail_text('welcome_body'), 60, 15, t('Customize the body of the welcome e-mail, which is sent to new members upon registering.') .' '. t('Available variables are:') .' %username, %site, %password, %uri, %uri_brief, %mailto, %login_uri, %edit_uri, %login_url.');
- $group .= form_textfield(t('Subject of welcome e-mail (awaiting admin approval)'), 'user_mail_approval_subject', _user_mail_text('approval_subject'), 50, 180, t('Customize the subject of your awaiting approval welcome e-mail, which is sent to new members upon registering.') .' '. t('Available variables are:') .' %username, %site, %password, %uri, %uri_brief, %mailto, %date, %login_uri, %edit_uri, %login_url.');
- $group .= form_textarea(t('Body of welcome e-mail (awaiting admin approval)'), 'user_mail_approval_body', _user_mail_text('approval_body'), 60, 15, t('Customize the body of the awaiting approval welcome e-mail, which is sent to new members upon registering.') .' '. t('Available variables are:') .' %username, %site, %password, %uri, %uri_brief, %mailto, %login_uri, %edit_uri, %login_url.');
- $group .= form_textfield(t('Subject of password recovery e-mail'), 'user_mail_pass_subject', _user_mail_text('pass_subject'), 60, 180, t('Customize the Subject of your forgotten password e-mail.') .' '. t('Available variables are:') .' %username, %site, %login_url, %uri, %uri_brief, %mailto, %date, %login_uri, %edit_uri.');
- $group .= form_textarea(t('Body of password recovery e-mail'), 'user_mail_pass_body', _user_mail_text('pass_body'), 60, 15, t('Customize the body of the forgotten password e-mail.') .' '. t('Available variables are:') .' %username, %site, %login_url, %uri, %uri_brief, %mailto, %login_uri, %edit_uri.');
- $output .= form_group(t('User email settings'), $group);
-
- // If picture support is enabled, check whether the picture directory exists:
- if (variable_get('user_pictures', 0)) {
- $picture_path = file_create_path(variable_get('user_picture_path', 'pictures'));
- file_check_directory($picture_path, 1, 'user_picture_path');
- }
-
- $group = form_radios(t('Picture support'), 'user_pictures', variable_get('user_pictures', 0), array(t('Disabled'), t('Enabled')), t('Enable picture support.'));
- $group .= form_textfield(t('Picture image path'), 'user_picture_path', variable_get('user_picture_path', 'pictures'), 30, 255, t('Subdirectory in the directory "%dir" where pictures will be stored.', array('%dir' => variable_get('file_directory_path', 'files') .'/')));
- $group .= form_textfield(t('Default picture'), 'user_picture_default', variable_get('user_picture_default', ''), 30, 255, t('URL of picture to display for users with no custom picture selected. Leave blank for none.'));
- $group .= form_textfield(t('Picture maximum dimensions'), 'user_picture_dimensions', variable_get('user_picture_dimensions', '85x85'), 15, 10, t('Maximum dimensions for pictures.'));
- $group .= form_textfield(t('Picture maximum file size'), 'user_picture_file_size', variable_get('user_picture_file_size', '30'), 15, 10, t('Maximum file size for pictures, in kB.'));
- $group .= form_textarea(t('Picture guidelines'), 'user_picture_guidelines', variable_get('user_picture_guidelines', ''), 60, 5, t('This text is displayed at the picture upload form in addition to the default guidelines. It\'s useful for helping or instructing your users.'));
-
- $output .= form_group(t('Pictures'), $group);
-
- return $output;
}
/**
@@ -1412,28 +1385,52 @@ function user_admin_access_check() {
$edit = $_POST['edit'];
if ($op) {
- if (drupal_is_denied($edit['type'], $edit['test'])) {
- drupal_set_message(t('%test is not allowed.', array('%test' => theme('placeholder', $edit['test']))));
+ if ($edit['user']) {
+ if (drupal_is_denied('user', $edit['user']['test'])) {
+ drupal_set_message(t('The username %name is not allowed.', array('%name' => theme('placeholder', $edit['user']['test']))));
+ }
+ else {
+ drupal_set_message(t('The username %name is allowed.', array('%name' => theme('placeholder', $edit['user']['test']))));
+ }
}
- else {
- drupal_set_message(t('%test is allowed.', array('%test' => theme('placeholder', $edit['test']))));
+ if ($edit['mail']) {
+ if (drupal_is_denied('mail', $edit['mail']['test'])) {
+ drupal_set_message(t('The e-mail address %mail is not allowed.', array('%mail' => theme('placeholder', $edit['mail']['test']))));
+ }
+ else {
+ drupal_set_message(t('The e-mail address %mail is allowed.', array('%mail' => theme('placeholder', $edit['mail']['test']))));
+ }
+ }
+ if ($edit['host']) {
+ if (drupal_is_denied('host', $edit['host']['test'])) {
+ drupal_set_message(t('The hostname %host is not allowed.', array('%host' => theme('placeholder', $edit['host']['test']))));
+ }
+ else {
+ drupal_set_message(t('The hostname %host is allowed.', array('%host' => theme('placeholder', $edit['host']['test']))));
+ }
}
}
- $form = form_textfield('', 'test', '', 30, 64, t('Enter a username to check if it will be denied or allowed.'));
- $form .= form_hidden('type', 'user');
- $form .= form_submit(t('Check username'));
- $output .= form_group(t('Username'), form($form));
+ $form['user'] = array(type => 'fieldset', title => t('Username'));
+ $form['user']['test'] = array(type => 'textfield', title => '', description => t('Enter a username to check if it will be denied or allowed.'), size => 30, maxlength => 64);
+ $form['user']['type'] = array(type => 'hidden', value => 'user');
+ $form['user']['submit'] = array(type => 'submit', value => t('Check username'));
+ $output .= drupal_get_form('check_user', $form);
+ unset($form); // prevent endless loop?
- $form = form_textfield('', 'test', '', 30, 64, t('Enter an e-mail address to check if it will be denied or allowed.'));
- $form .= form_hidden('type', 'mail');
- $form .= form_submit(t('Check e-mail'));
- $output .= form_group(t('E-mail'), form($form));
+ $form['mail'] = array(type => 'fieldset', title => t('E-mail'));
+ $form['mail']['test'] = array(type => 'textfield', title => '', description => t('Enter an e-mail address to check if it will be denied or allowed.'), size => 30, maxlength => 64);
+ $form['mail']['type'] = array(type => 'hidden', value => 'mail');
+ $form['mail']['submit'] = array(type => 'submit', value => t('Check e-mail'));
+ $output .= drupal_get_form('check_mail', $form);
+ unset($form); // prevent endless loop?
- $form = form_textfield('', 'test', '', 30, 64, t('Enter a host to check if it will be denied or allowed.'));
- $form .= form_hidden('type', 'host');
- $form .= form_submit(t('Check host'));
- $output .= form_group(t('Host'), form($form));
+ $form['host'] = array(type => 'fieldset', title => t('Hostname'));
+ $form['host']['test'] = array(type => 'textfield', title => '', description => t('Enter a hostname or IP address to check if it will be denied or allowed.'), size => 30, maxlength => 64);
+ $form['host']['type'] = array(type => 'hidden', value => 'host');
+ $form['host']['submit'] = array(type => 'submit', value => t('Check hostname'));
+ $output .= drupal_get_form('check_host', $form);
+ unset($form); // prevent endless loop?
return $output;
}
@@ -1459,33 +1456,33 @@ function user_admin_access_add($mask = NULL, $type = NULL) {
}
$form = _user_admin_access_form($edit);
- $form .= form_submit(t('Add rule'));
+ $form['submit'] = array(type => 'submit', value => t('Add rule'));
- return form($form, 'post', NULL, array('id' => 'access-rules'));
+ return drupal_get_form('access_rule', $form);
}
/**
* Menu callback: delete an access rule
*/
function user_admin_access_delete($aid = 0) {
- if ($_POST['edit']['confirm']) {
- db_query('DELETE FROM {access} WHERE aid = %d', $aid);
- drupal_set_message(t('The access rule has been deleted.'));
- drupal_goto('admin/access/rules');
- }
- else {
- $access_types = array('user' => t('username'), 'mail' => t('e-mail'));
- $edit = db_fetch_object(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid));
+ $access_types = array('user' => t('username'), 'mail' => t('e-mail'));
+ $edit = db_fetch_object(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid));
+
+ $form = array();
+ $form['aid'] = array(type => 'hidden', value => $aid);
+ $output = confirm_form('user_admin_access_delete_confirm', $form,
+ t('Are you sure you want to delete the %type rule for %rule?', array('%type' => $access_types[$edit->type], '%rule' => theme('placeholder', $edit->mask))),
+ 'admin/access/rules',
+ t('This action cannot be undone.'),
+ t('Delete'),
+ t('Cancel'));
+ return $output;
+}
- $output = theme('confirm',
- t('Are you sure you want to delete the %type rule for %rule?', array('%type' => $access_types[$edit->type], '%rule' => theme('placeholder', $edit->mask))),
- 'admin/access/rules',
- t('This action cannot be undone.'),
- t('Delete'),
- t('Cancel'),
- $extra);
- return $output;
- }
+function user_admin_access_delete_confirm_execute($form_id, $edit) {
+ db_query('DELETE FROM {access} WHERE aid = %d', $edit['aid']);
+ drupal_set_message(t('The access rule has been deleted.'));
+ drupal_goto('admin/access/rules');
}
/**
@@ -1506,16 +1503,17 @@ function user_admin_access_edit($aid = 0) {
$edit = db_fetch_array(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid));
}
$form = _user_admin_access_form($edit);
- $form .= form_submit(t('Save rule'));
- return form($form, 'post', NULL, array('id' => 'access-rules'));
+ $form['submit'] = array(type => 'submit', value => t('Save rule'));
+
+ return drupal_get_form('access_rule', $form);
}
function _user_admin_access_form($edit) {
- $output = '<div class="access-type">'. form_radios(t('Access type'), 'status', $edit['status'], array('1' => t('Allow'), '0' => t('Deny'))) .'</div>';
- $output .= '<div class="rule-type">'. form_radios(t('Rule type'), 'type', $edit['type'] ? $edit['type'] : 'user', array('user' => t('Username'), 'mail' => t('E-mail'), 'host' => t('Host'))) .'</div>';
- $output .= '<div class="mask">'. form_textfield(t('Mask'), 'mask', $edit['mask'], 30, 64, '%: '. t('Matches any number of characters, even zero characters') .'.<br />_: '. t('Matches exactly one character.'), NULL, TRUE) .'</div>';
+ $form['status'] = array(type => 'radios', title => t('Access type'), default_value => $edit['status'], options => array('1' => t('Allow'), '0' => t('Deny')));
+ $form['type'] = array(type => 'radios', title => t('Rule type'), default_value => $edit['type'], options => array('user' => t('Username'), 'mail' => t('E-mail'), 'host' => t('Host'), default_value => 'host'));
+ $form['mask'] = array(type => 'textfield', title => t('Mask'), default_value => $edit['mask'], size => 30, maxlength => 64, description => '%: '. t('Matches any number of characters, even zero characters') .'.<br />_: '. t('Matches exactly one character.'), required => TRUE);
- return $output;
+ return $form;
}
/**
@@ -1558,31 +1556,6 @@ function user_roles($membersonly = 0, $permission = 0) {
* Menu callback: administer permissions.
*/
function user_admin_perm() {
- $edit = $_POST['edit'];
- if ($edit) {
- // Save permissions:
- $result = db_query('SELECT * FROM {role}');
- while ($role = db_fetch_object($result)) {
- // Delete, so if we clear every checkbox we reset that role;
- // otherwise permissions are active and denied everywhere.
- db_query('DELETE FROM {permission} WHERE rid = %d', $role->rid);
- foreach ($edit[$role->rid] as $key => $value) {
- if (!$value) {
- unset($edit[$role->rid][$key]);
- }
- }
- if (count($edit[$role->rid])) {
- db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $role->rid, implode(', ', array_keys($edit[$role->rid])));
- }
- }
-
- drupal_set_message(t('The changes have been saved.'));
-
- // Clear the cached pages and menus:
- menu_rebuild();
-
- drupal_goto($_GET['q']);
- }
// Compile role array:
$result = db_query('SELECT r.rid, p.perm FROM {role} r LEFT JOIN {permission} p ON r.rid = p.rid ORDER BY name');
@@ -1598,27 +1571,88 @@ function user_admin_perm() {
}
// Render role/permission overview:
- $header = array_merge(array(t('Permission')), $role_names);
-
+ $options = array();
foreach (module_list() as $module) {
if ($permissions = module_invoke($module, 'perm')) {
- $rows[] = array(array('data' => t('%module module', array('%module' => $module)), 'class' => 'module', 'colspan' => count($role_names) + 1));
+ $form['permission'][] = array(type => 'markup', value => t('%module module', array('%module' => $module)));
asort($permissions);
foreach ($permissions as $perm) {
- $row[] = array('data' => t($perm), 'class' => 'permission');
+ $options[$perm] = '';
+ $form['permission'][$perm] = array(type => 'markup', value => t($perm));
foreach ($role_names as $rid => $name) {
- $row[] = form_checkbox('', "$rid][$perm", 1, strstr($role_permissions[$rid], $perm), NULL, array('title' => $name .': '. t($perm)));
+ // Builds arrays for checked boxes for each role
+ if (strstr($role_permissions[$rid], $perm)) {
+ $status[$rid][] = $perm;
+ }
}
- $rows[] = $row;
- unset($row);
}
}
}
+ // Have to build checkboxes here after checkbox arrays are built
+ foreach ($role_names as $rid => $name) {
+ $form['checkboxes'][$rid] = array(type => 'checkboxes', options => $options, default_value => $status[$rid], tree => TRUE);
+ $form['role_names'][$rid] = array(type => 'markup', value => $name, tree => TRUE);
+ }
+ $form['submit'] = array(type => 'submit', value => t('Save permissions'));
+ return drupal_get_form('user_admin_perm', $form);
+}
+
+function theme_user_admin_perm($form) {
+ foreach (element_children($form['permission']) as $key) {
+ // Don't take form control structures
+ if (is_array($form['permission'][$key])) {
+ $row = array();
+ // Module name
+ if (is_numeric($key)) {
+ $row[] = array('data' => form_render($form['permission'][$key]), 'class' => 'module', 'colspan' => count($form['role_names']) + 1);
+ // Permissions
+ } else {
+ $row[] = array('data' => form_render($form['permission'][$key]), 'class' => 'permission');
+ foreach (element_children($form['checkboxes']) as $rid) {
+ if (is_array($form['checkboxes'][$rid])) {
+ $row[] = array('data' => form_render($form['checkboxes'][$rid][$key]), 'align' => 'center');
+ }
+ }
+ }
+ $rows[] = $row;
+ }
+ }
+ $header[] = (t('Permission'));
+ foreach (element_children($form['role_names']) as $rid) {
+ if (is_array($form['role_names'][$rid])) {
+ $header[] = form_render($form['role_names'][$rid]);
+ }
+ }
$output = theme('table', $header, $rows, array('id' => 'permissions'));
- $output .= form_submit(t('Save permissions'));
+ $output .= form_render($form);
+ return $output;
+}
+
+function user_admin_perm_execute() {
+ $edit = $GLOBALS['form_values']['checkboxes'];
+ // Save permissions:
+ $result = db_query('SELECT * FROM {role}');
+ while ($role = db_fetch_object($result)) {
+ // Delete, so if we clear every checkbox we reset that role;
+ // otherwise permissions are active and denied everywhere.
+ db_query('DELETE FROM {permission} WHERE rid = %d', $role->rid);
+ foreach ($edit[$role->rid] as $key => $value) {
+ if (!$value) {
+ unset($edit[$role->rid][$key]);
+ }
+ }
+ if (count($edit[$role->rid])) {
+ db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $role->rid, implode(', ', array_keys($edit[$role->rid])));
+ }
+ }
+
+ drupal_set_message(t('The changes have been saved.'));
+
+ // Clear the cached pages and menus:
+ menu_rebuild();
- return form($output);
+ drupal_goto($_GET['q']);
}
/**
@@ -1673,34 +1707,32 @@ function user_admin_role() {
else if ($id) {
// Display the role form.
$role = db_fetch_object(db_query('SELECT * FROM {role} WHERE rid = %d', $id));
+ $form['name'] = array(type => 'textfield', title => t('Role name'), default_value => $role->name, size => 30, maxlength => 64, description => t('The name for this role. Example: "moderator", "editorial board", "site architect".'));
+ $form['submit'] = array(type => 'submit', value => t('Save role'));
+ $form['delete'] = array(type => 'submit', value => t('Delete role'));
+ return drupal_get_form('user_admin_role', $form);
+ }
+ $form['name'] = array(type => 'textfield', size => 32, maxlength => 64);
+ $form['submit'] = array(type => 'submit', value => t('Add role'));
+ return drupal_get_form('user_admin_new_role', $form);
+}
- $output .= form_textfield(t('Role name'), 'name', $role->name, 30, 64, t('The name for this role. Example: "moderator", "editorial board", "site architect".'));
- $output .= form_submit(t('Save role'));
- $output .= form_submit(t('Delete role'));
-
- $output = form($output);
- }
-
- if (!$output) {
- // Render the role overview.
- $result = db_query('SELECT * FROM {role} ORDER BY name');
+function theme_user_admin_new_role($form) {
+ // Render the role overview.
+ $result = db_query('SELECT * FROM {role} ORDER BY name');
- $header = array(t('Name'), t('Operations'));
- while ($role = db_fetch_object($result)) {
- if ($role->name != 'anonymous user' && $role->name != 'authenticated user') {
- $rows[] = array($role->name, l(t('edit'), 'admin/access/roles/edit/'. $role->rid));
- }
- else {
- $rows[] = array($role->name, '<span class="disabled">'. t('locked') .'</span>');
- }
+ $header = array(t('Name'), t('Operations'));
+ while ($role = db_fetch_object($result)) {
+ if ($role->name != 'anonymous user' && $role->name != 'authenticated user') {
+ $rows[] = array($role->name, l(t('edit'), 'admin/access/roles/edit/'. $role->rid));
+ }
+ else {
+ $rows[] = array($role->name, '<span class="disabled">'. t('locked') .'</span>');
}
- $rows[] = array('<input type="text" size="32" maxlength="64" name="edit[name]" />', '<input type="submit" name="op" value="'. t('Add role') .'" />');
-
- $output = theme('table', $header, $rows);
- $output = form($output);
}
+ $rows[] = array(form_render($form['name']), form_render($form['submit']));
- return $output;
+ return theme('table', $header, $rows);
}
function user_admin_account() {
@@ -1731,19 +1763,35 @@ function user_admin_account() {
}
function user_configure() {
- $op = $_POST['op'];
- $edit = $_POST['edit'];
+ // User registration settings.
+ $form['registration'] = array(type => 'fieldset', title => t('User registration settings'));
+ $form['registration']['user_register'] = array(type => 'radios', title => t('Public registrations'), default_value => variable_get('user_register', 1), options => array(t('Only site administrators can create new user accounts.'), t('Visitors can create accounts and no administrator approval is required.'), t('Visitors can create accounts but administrator approval is required.')));
+ $form['registration']['user_registration_help'] = array(type => 'textarea', title => t('User registration guidelines'), default_value => variable_get('user_registration_help', ''), cols => 60, rows => 5, description => t('This text is displayed at the top of the user registration form. It\'s useful for helping or instructing your users.'));
- if (empty($op)) {
- $op = arg(3);
- }
+ // User e-mail settings.
+ $form['email'] = array(type => 'fieldset', title => t('User email settings'));
+ $form['email']['user_mail_welcome_subject'] = array(type => 'textfield', title => t('Subject of welcome e-mail'), default_value => _user_mail_text('welcome_subject'), size => 60, maxlength => 180, description => t('Customize the subject of your welcome e-mail, which is sent to new members upon registering.') .' '. t('Available variables are:') .' %username, %site, %password, %uri, %uri_brief, %mailto, %date, %login_uri, %edit_uri, %login_url.');
+ $form['email']['user_mail_welcome_body'] = array(type => 'textarea', title => t('Body of welcome e-mail'), default_value => _user_mail_text('welcome_body'), cols => 60, rows => 15, description => t('Customize the body of the welcome e-mail, which is sent to new members upon registering.') .' '. t('Available variables are:') .' %username, %site, %password, %uri, %uri_brief, %mailto, %login_uri, %edit_uri, %login_url.');
+ $form['email']['user_mail_approval_subject'] = array(type => 'textfield', title => t('Subject of welcome e-mail (awaiting admin approval)'), default_value => _user_mail_text('approval_subject'), size => 60, maxlength => 180, description => t('Customize the subject of your awaiting approval welcome e-mail, which is sent to new members upon registering.') .' '. t('Available variables are:') .' %username, %site, %password, %uri, %uri_brief, %mailto, %date, %login_uri, %edit_uri, %login_url.');
+ $form['email']['user_mail_approval_body'] = array(type => 'textarea', title => t('Body of welcome e-mail (awaiting admin approval)'), default_value => _user_mail_text('approval_body'), cols => 60, rows => 15, description => t('Customize the body of the awaiting approval welcome e-mail, which is sent to new members upon registering.') .' '. t('Available variables are:') .' %username, %site, %password, %uri, %uri_brief, %mailto, %login_uri, %edit_uri, %login_url.');
+ $form['email']['user_mail_pass_subject'] = array(type => 'textfield', title => t('Subject of password recovery e-mail'), default_value => _user_mail_text('pass_subject'), size => 60, maxlength => 180, description => t('Customize the Subject of your forgotten password e-mail.') .' '. t('Available variables are:') .' %username, %site, %login_url, %uri, %uri_brief, %mailto, %date, %login_uri, %edit_uri.');
+ $form['email']['user_mail_pass_body'] = array(type => 'textarea', title => t('Body of password recovery e-mail'), default_value => _user_mail_text('pass_body'), cols => 60, rows => 15, description => t('Customize the body of the forgotten password e-mail.') .' '. t('Available variables are:') .' %username, %site, %login_url, %uri, %uri_brief, %mailto, %login_uri, %edit_uri.');
- if ($_POST) {
- system_settings_save();
+ // If picture support is enabled, check whether the picture directory exists:
+ if (variable_get('user_pictures', 0)) {
+ $picture_path = file_create_path(variable_get('user_picture_path', 'pictures'));
+ file_check_directory($picture_path, 1, 'user_picture_path');
}
- $output = system_settings_form(user_configure_settings());
- return $output;
+ $form['pictures'] = array(type => 'fieldset', title => t('Pictures'));
+ $form['pictures']['user_pictures'] = array(type => 'radios', title => t('Picture support'), default_value => variable_get('user_pictures', 0), options => array(t('Disabled'), t('Enabled')), description => t('Enable picture support.'));
+ $form['pictures']['user_picture_path'] = array(type => 'textfield', title => t('Picture image path'), default_value => variable_get('user_picture_path', 'pictures'), size => 30, maxlength => 255, description => t('Subdirectory in the directory "%dir" where pictures will be stored.', array('%dir' => variable_get('file_directory_path', 'files') .'/')));
+ $form['pictures']['user_picture_default'] = array(type => 'textfield', title => t('Default picture'), default_value => variable_get('user_picture_default', ''), size => 30, maxlength => 255, description => t('URL of picture to display for users with no custom picture selected. Leave blank for none.'));
+ $form['pictures']['user_picture_dimensions'] = array(type => 'textfield', title => t('Picture maximum dimensions'), default_value => variable_get('user_picture_dimensions', '85x85'), size => 15, maxlength => 10, description => t('Maximum dimensions for pictures.'));
+ $form['pictures']['user_picture_file_size'] = array(type => 'textfield', title => t('Picture maximum file size'), default_value => variable_get('user_picture_file_size', '30'), size => 15, maxlength => 10, description => t('Maximum file size for pictures, in kB.'));
+ $form['pictures']['user_picture_guidelines'] = array(type => 'textarea', title => t('Picture guidelines'), default_value => variable_get('user_picture_guidelines', ''), cols => 60, rows => 5, description => t('This text is displayed at the picture upload form in addition to the default guidelines. It\'s useful for helping or instructing your users.'));
+
+ return system_settings_form('user_configure_settings', $form);
}
function user_admin() {
@@ -1880,15 +1928,9 @@ function _user_forms(&$edit, $account, $category, $hook = 'form') {
$groups = array_merge($data, $groups);
}
}
-
usort($groups, '_user_sort');
- $output = '';
- foreach ($groups as $group) {
- $output .= form_group($group['title'], $group['data']);
- }
-
- return $output;
+ return empty($groups) ? FALSE : $groups;
}
/**
diff --git a/modules/user/user.module b/modules/user/user.module
index 7de7430e6..3c8810d75 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -467,7 +467,8 @@ function user_search($op = 'search', $keys = null) {
*/
function user_user($type, &$edit, &$user, $category = NULL) {
if ($type == 'view') {
- return array(t('History') => array('history'=> form_item(t('Member for'), format_interval(time() - $user->created))));
+ $form['member'] = array(type => 'item', title => t('Member for'), value => format_interval(time() - $user->created));
+ return array(t('History') => array('history'=> drupal_get_form('member', $form)));
}
if ($type == 'form' && $category == 'account') {
@@ -499,10 +500,11 @@ function user_block($op = 'list', $delta = 0, $edit = array()) {
}
else if ($op == 'configure' && $delta == 3) {
$period = drupal_map_assoc(array(30, 60, 120, 180, 300, 600, 900, 1800, 2700, 3600, 5400, 7200, 10800, 21600, 43200, 86400), 'format_interval');
- $output = form_select(t('User activity'), 'user_block_seconds_online', variable_get('user_block_seconds_online', 900), $period, t('A user is considered online for this long after they have last viewed a page.'));
- $output .= form_select(t('User list length'), 'user_block_max_list_count', variable_get('user_block_max_list_count', 10), drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 40, 50, 75, 100)), t('Maximum number of currently online users to display.'));
+ $form['user_block_seconds_online'] = array(type => 'select', title => t('User activity'), default_value => variable_get('user_block_seconds_online', 900), options => $period, description => t('A user is considered online for this long after they have last viewed a page.'));
+ $form['user_block_max_list_count'] = array(type => 'select', title => t('User list length'), default_value => variable_get('user_block_max_list_count', 10), options => drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 40, 50, 75, 100)), description => t('Maximum number of currently online users to display.'));
- return $output;
+ //return drupal_get_form('user_block', $form);
+ return $form;
}
else if ($op == 'save' && $delta == 3) {
variable_set('user_block_seconds_online', $edit['user_block_seconds_online']);
@@ -515,18 +517,10 @@ function user_block($op = 'list', $delta = 0, $edit = array()) {
case 0:
// For usability's sake, avoid showing two login forms on one page.
if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {
- $edit = $_POST['edit'];
-
- // NOTE: special care needs to be taken because on pages with forms,
- // such as node and comment submission pages, the $edit variable
- // might already be set.
-
- $output .= form_textfield(t('Username'), 'name', $edit['name'], 15, 64);
- $output .= form_password(t('Password'), 'pass', '', 15, 64);
- $output .= form_submit(t('Log in'));
-
- $output = form($output, 'post', url('user/login', drupal_get_destination()), array('id' => 'user-login-form'));
-
+ $form['name'] = array(type => 'textfield', title => t('Username'), maxlength => 64, size => 15, required => TRUE);
+ $form['pass'] = array(type => 'password', title => t('Password'), maxlength => 64, size => 15, required => TRUE);
+ $form['submit'] = array(type => 'submit', value => t('Log in'));
+ $output .= drupal_get_form('user_login_block', $form, 'user_login');
if (variable_get('user_register', 1)) {
$items[] = l(t('Create new account'), 'user/register', array('title' => t('Create a new user account.')));
}
@@ -597,6 +591,15 @@ function user_block($op = 'list', $delta = 0, $edit = array()) {
}
}
+
+
+function theme_user_login_block($form) {
+ $output = "<div class=\"user-login-block\">\n";
+ $output .= form_render($form);
+ $output .= "</div>\n";
+ return $output;
+}
+
function theme_user_picture($account) {
if (variable_get('user_pictures', 0)) {
if ($account->picture && file_exists($account->picture)) {
@@ -827,6 +830,8 @@ function user_auth_help_links() {
/*** User features *********************************************************/
+
+
function user_login($edit = array(), $msg = '') {
global $user, $base_url;
@@ -872,6 +877,7 @@ function user_login($edit = array(), $msg = '') {
// Display error message (if any):
if ($error) {
+ $form['error'] = array(type => 'value', value => 1);
drupal_set_message($error, 'error');
}
@@ -879,16 +885,23 @@ function user_login($edit = array(), $msg = '') {
if ($msg) {
$output .= "<p>$msg</p>";
}
+ $form['name'] = array(type => 'textfield', title => t('Username'), size => 30, maxlength => 64, required => TRUE);
if (count(user_auth_help_links()) > 0) {
- $output .= form_textfield(t('Username'), 'name', $edit['name'], 30, 64, t('Enter your %s username, or an ID from one of our affiliates: %a.', array('%s' => variable_get('site_name', 'local'), '%a' => implode(', ', user_auth_help_links()))));
+ $form['name'][description] = t('Enter your %s username, or an ID from one of our affiliates: %a.', array('%s' => variable_get('site_name', 'local'), '%a' => implode(', ', user_auth_help_links())));
}
else {
- $output .= form_textfield(t('Username'), 'name', $edit['name'], 30, 64, t('Enter your %s username.', array('%s' => variable_get('site_name', 'local'))));
+ $form['name'][description] = t('Enter your %s username.', array('%s' => variable_get('site_name', 'local')));
}
- $output .= form_password(t('Password'), 'pass', $pass, 30, 64, t('Enter the password that accompanies your username.'));
- $output .= form_submit(t('Log in'));
+ $form['pass'] = array(type => 'password', title => t('Password'), size => 30, maxlength => 64, description => t('Enter the password that accompanies your username.'), required => TRUE);
+ $form['submit'] = array(type => 'submit', value => t('Log in'), weight => 2);
+ return drupal_get_form('user_login', $form);
+}
- return form($output, 'post', url('user/login', drupal_get_destination()));
+function user_login_execute($form) {
+ global $form_values;
+ if (!isset($form_values['error'])) {
+ return user_login($form_values);
+ }
}
function user_authenticate($name, $pass) {
@@ -991,14 +1004,19 @@ function user_pass() {
drupal_set_message(t('You must provide either a username or e-mail address.'), 'error');
}
// Display form:
- $output = '<p>'. t('Enter your username <strong><em>or</em></strong> your e-mail address.') .'</p>';
- $output .= form_textfield(t('Username'), 'name', $edit['name'], 30, 64);
- $output .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 64);
- $output .= form_submit(t('E-mail new password'));
- return form($output);
+ $form['name'] = array(type => 'textfield', title => t('Username'), default_value => $edit['name'], size => 30, maxlength => 64);
+ $form['mail'] = array(type => 'textfield', title => t('E-mail address'), default_value => $edit['mail'], size => 30, maxlength => 64);
+ $form['submit'] = array(type => 'submit', value => t('E-mail new password'));
+ return drupal_get_form('user_logout', $form);
}
}
+function theme_user_logout($form) {
+ $output = '<p>'. t('Enter your username <strong><em>or</em></strong> your e-mail address.') .'</p>';
+ $output .= form_render($form);
+ return $output;
+}
+
/**
* Menu callback; process one time login URL, and redirects to the user page on success.
*/
@@ -1075,12 +1093,12 @@ function user_register($edit = array()) {
if ($account->uid == 1) {
user_mail($edit['mail'], t('drupal user account details for %s', array('%s' => $edit['name'])), strtr(t("%username,\n\nYou may now login to %uri using the following username and password:\n\n username: %username\n password: %password\n\n%edit_uri\n\n--drupal"), $variables), "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");
// This should not be t()'ed. No point as its only shown once in the sites lifetime, and it would be bad to store the password.
- $output .= "<p>Welcome to Drupal. You are user #1, which gives you full and immediate access. All future registrants will receive their passwords via e-mail, so please configure your e-mail settings using the Administration pages.</p><p> Your password is <strong>$pass</strong>. You may change your password on the next page.</p><p>Please login below.</p>";
- $output .= form_hidden('destination', 'user/'. $account->uid .'/edit');
- $output .= form_hidden('name', $account->name);
- $output .= form_hidden('pass', $pass);
- $output .= form_submit(t('Log in'));
- return form($output);
+ $form['instructions'] = array(type => 'markup', value => "<p>Welcome to Drupal. You are user #1, which gives you full and immediate access. All future registrants will receive their passwords via e-mail, so please configure your e-mail settings using the Administration pages.</p><p> Your password is <strong>$pass</strong>. You may change your password on the next page.</p><p>Please login below.</p>");
+ $form[action] = 'user/'. $account->uid .'/edit';
+ $form['name'] = array(type => 'hidden', value => $account->name);
+ $form['pass'] = array(type => 'hidden', value => $pass);
+ $form['submit'] = array(type => 'submit', value => t('Log in'));
+ return drupal_get_form('user_register', $form);
}
else {
if ($admin) {
@@ -1109,57 +1127,57 @@ function user_register($edit = array()) {
}
// Display the registration form.
- $output .= variable_get('user_registration_help', '');
+ $form['user_registration_help'] = array(type => 'markup', value => variable_get('user_registration_help', ''));
$affiliates = user_auth_help_links();
if (!$admin && count($affiliates) > 0) {
$affiliates = implode(', ', $affiliates);
- $output .= '<p>'. t('Note: if you have an account with one of our affiliates (%s), you may <a href="%login_uri">login now</a> instead of registering.', array('%s' => $affiliates, '%login_uri' => url('user'))) .'</p>';
+ $form['affiliates'] = array(type => 'markup', value => '<p>'. t('Note: if you have an account with one of our affiliates (%s), you may <a href="%login_uri">login now</a> instead of registering.', array('%s' => $affiliates, '%login_uri' => url('user'))) .'</p>');
}
- $default = form_textfield(t('Username'), 'name', $edit['name'], 30, 64, t('Your full name or your preferred username; only letters, numbers and spaces are allowed.'), NULL, TRUE);
- $default .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 64, t('A password and instructions will be sent to this e-mail address, so make sure it is accurate.'), NULL, TRUE);
+ $form['name'] = array(type => 'textfield', title => t('Username'), default_value => $edit['name'], size => 30, maxlength => 64, description => t('Your full name or your preferred username; only letters, numbers and spaces are allowed.'), required => TRUE);
+ $form['mail'] = array(type => 'textfield', title => t('E-mail address'), default_value => $edit['mail'], size => 30, maxlength => 64, description => t('A password and instructions will be sent to this e-mail address, so make sure it is accurate.'), required => TRUE);
if ($admin) {
- $default .= form_password(t('Password'), 'pass', $edit['pass'], 30, 55,t('Provide a password for the new account.'), NULL, TRUE);
+ $form['pass'] = array(type => 'password', title => t('Password'), default_value => $edit['pass'], size => 30, maxlength => 55, description => t('Provide a password for the new account.'), required => TRUE);
}
$extra = _user_forms($edit, $account, $category, 'register');
// Only display form_group around default fields if there are other groups.
if ($extra) {
- $output .= form_group(t('Account information'), $default);
- $output .= $extra;
- }
- else {
- $output .= $default;
- }
- $output .= form_submit(t('Create new account'));
+ $form['account'] = array(type => 'fieldset', value => t('Account information'));
+ $form['account']['name'] = $form['name'];
+ $form['account']['mail'] = $form['mail'];
+ $form['account']['pass'] = $form['pass'];
+ unset($form['name']);
+ unset($form['mail']);
+ unset($form['pass']);
+ $form = array_merge($form, $extra);
+ }
+ $form['submit'] = array(type => 'submit', value => t('Create new account'), weight => 30);
- return form($output);
+ return drupal_get_form('user_register', $form);
}
function user_edit_form($uid, $edit) {
// Account information:
- $group = form_textfield(t('Username'), 'name', $edit['name'], 60, 55, t('Your full name or your preferred username: only letters, numbers and spaces are allowed.'), NULL, TRUE);
- $group .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 60, 55, t('Insert a valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'), NULL, TRUE);
- $group .= form_item(t('Password'), '<input type="password" class="form-password" name="edit[pass1]" size="12" maxlength="24" /> <input type="password" class="form-password" name="edit[pass2]" size="12" maxlength="24" />', t('Enter your new password twice if you want to change your current password, or leave it blank if you are happy with your current password.'), NULL, TRUE);
-
+ $form['account'] = array(type => 'fieldset', title => t('Account information'), weight => 0);
+ $form['account']['name'] = array(type => 'textfield', title => t('Username'), default_value => $edit['name'], size => 60, maxlength => 55, description => t('Your full name or your preferred username: only letters, numbers and spaces are allowed.'), required => TRUE);
+ $form['account']['mail'] = array(type => 'textfield', title => t('E-mail address'), default_value => $edit['mail'], size => 60, maxlength => 55, description => t('Insert a valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'), required => TRUE);
+ $form['account']['pass'] = array(type => 'item', title => t('Password'), value => '<input type="password" class="form-password" name="edit[pass1]" size="12" maxlength="24" /> <input type="password" class="form-password" name="edit[pass2]" size="12" maxlength="24" />', required => true);
if (user_access('administer access control')) {
- $group .= form_radios(t('Status'), 'status', $edit['status'], array(t('Blocked'), t('Active')));
- $group .= form_checkboxes(t('Roles'), 'roles', array_keys($edit['roles']), user_roles(1), t('Select at least one role. The user receives the combined permissions of all of the selected roles.'), NULL, TRUE);
+ $form['account']['status'] = array(type => 'radios', title => t('Status'), default_value => $edit['status'], options => array(t('Blocked'), t('Active')));
+ $form['account']['roles'] = array(type => 'checkboxes', title => t('Roles'), default_value => array_keys($edit['roles']), options => user_roles(1), description => t('Select at least one role. The user receives the combined permissions of all of the selected roles.'), required => TRUE);
}
- $data[] = array('title' => t('Account information'), 'data' => $group, 'weight' => 0);
-
// Picture/avatar:
if (variable_get('user_pictures', 0)) {
- $group = '';
+ $form['picture'] = array(type => 'fieldset', title => t('Picture'), weight => 1);
if ($edit['picture'] && ($picture = theme('user_picture', array2object($edit)))) {
- $group .= $picture;
- $group .= form_checkbox(t('Delete picture'), 'picture_delete', 1, 0, t('Check this box to delete your current picture.'));
+ $form['picture']['current_picture'] = array(type => 'markup', value => $picture);
+ $form['picture']['picture_delete'] = array(type => 'checkbox', title => t('Delete picture'), return_value => 1, default_value => 0, description => t('Check this box to delete your current picture.'));
}
- $group .= form_file(t('Upload picture'), 'picture', 48, t('Your virtual face or picture. Maximum dimensions are %dimensions and the maximum size is %size kB.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'), '%size' => variable_get('user_picture_file_size', '30'))) .' '. variable_get('user_picture_guidelines', ''));
- $data[] = array('title' => t('Picture'), 'data' => $group, 'weight' => 1);
+ $form['picture']['picture'] = array(type => 'file', title => t('Upload picture'), size => 48, description => t('Your virtual face or picture. Maximum dimensions are %dimensions and the maximum size is %size kB.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'), '%size' => variable_get('user_picture_file_size', '30'))) .' '. variable_get('user_picture_guidelines', ''));
}
- return $data;
+ return $form;
}
function user_edit_validate($uid, &$edit) {
@@ -1191,12 +1209,6 @@ function user_edit_validate($uid, &$edit) {
form_set_error('roles', t('You must select at least one role.'));
$edit['roles'] = array();
}
- else {
- // Before form submission, $edit['roles'] contains ('role id' => 'role name') tuples.
- // After form submission, $edit['roles'] contains ('number' => 'role id') tuples. We
- // flip the array to always have the role id's in the keys.
- $edit['roles'] = array_flip($edit['roles']);
- }
}
// If required, validate the uploaded picture.
@@ -1262,12 +1274,7 @@ function user_edit($category = 'account') {
drupal_goto('admin/user');
}
else {
- $output = theme('confirm',
- t('Are you sure you want to delete the account %name?', array('%name' => theme('placeholder', $account->name))),
- 'user/'. $account->uid,
- t('Deleting a user will remove all their submissions as well. This action cannot be undone.'),
- t('Delete'));
- return $output;
+ return confirm_form('user_confirm_delete', $form, t('Are you sure you want to delete the account %name?', array('%name' => theme('placeholder', $account->name))), 'user/'. $account->uid, t('Deleting a user will remove all their submissions as well. This action cannot be undone.'), t('Delete'));
}
}
else if ($_POST['op'] == t('Delete')) {
@@ -1275,15 +1282,15 @@ function user_edit($category = 'account') {
drupal_goto("user/$account->uid/delete");
}
- $output = _user_forms($edit, $account, $category);
- $output .= form_submit(t('Submit'));
+ $form = _user_forms($edit, $account, $category);
+ $form['submit'] = array(type => 'submit', value => t('Submit'), weight => 30);
if (user_access('administer users')) {
- $output .= form_submit(t('Delete'));
+ $form['delete'] = array(type => 'submit', value => t('Delete'), weight => 30);
}
- $output = form($output, 'post', 0, array('enctype' => 'multipart/form-data'));
+ $form[attributes] = array('enctype' => 'multipart/form-data');
drupal_set_title($account->name);
- return $output;
+ return drupal_get_form('user_edit', $form);
}
function user_view($uid = 0) {
@@ -1322,10 +1329,6 @@ function user_page() {
case 'register':
return user_register($edit);
break;
- case t('Log in'):
- case 'login':
- return user_login($edit);
- break;
default:
if (!arg(1)) {
if ($user->uid) {
@@ -1370,36 +1373,6 @@ function _user_mail_text($messageid, $variables = array()) {
}
function user_configure_settings() {
- // User registration settings.
- $group = form_radios(t('Public registrations'), 'user_register', variable_get('user_register', 1), array(t('Only site administrators can create new user accounts.'), t('Visitors can create accounts and no administrator approval is required.'), t('Visitors can create accounts but administrator approval is required.')));
- $group .= form_textarea(t('User registration guidelines'), 'user_registration_help', variable_get('user_registration_help', ''), 60, 5, t('This text is displayed at the top of the user registration form. It\'s useful for helping or instructing your users.'));
- $output = form_group(t('User registration settings'), $group);
-
- // User e-mail settings.
- $group = form_textfield(t('Subject of welcome e-mail'), 'user_mail_welcome_subject', _user_mail_text('welcome_subject'), 60, 180, t('Customize the subject of your welcome e-mail, which is sent to new members upon registering.') .' '. t('Available variables are:') .' %username, %site, %password, %uri, %uri_brief, %mailto, %date, %login_uri, %edit_uri, %login_url.');
- $group .= form_textarea(t('Body of welcome e-mail'), 'user_mail_welcome_body', _user_mail_text('welcome_body'), 60, 15, t('Customize the body of the welcome e-mail, which is sent to new members upon registering.') .' '. t('Available variables are:') .' %username, %site, %password, %uri, %uri_brief, %mailto, %login_uri, %edit_uri, %login_url.');
- $group .= form_textfield(t('Subject of welcome e-mail (awaiting admin approval)'), 'user_mail_approval_subject', _user_mail_text('approval_subject'), 50, 180, t('Customize the subject of your awaiting approval welcome e-mail, which is sent to new members upon registering.') .' '. t('Available variables are:') .' %username, %site, %password, %uri, %uri_brief, %mailto, %date, %login_uri, %edit_uri, %login_url.');
- $group .= form_textarea(t('Body of welcome e-mail (awaiting admin approval)'), 'user_mail_approval_body', _user_mail_text('approval_body'), 60, 15, t('Customize the body of the awaiting approval welcome e-mail, which is sent to new members upon registering.') .' '. t('Available variables are:') .' %username, %site, %password, %uri, %uri_brief, %mailto, %login_uri, %edit_uri, %login_url.');
- $group .= form_textfield(t('Subject of password recovery e-mail'), 'user_mail_pass_subject', _user_mail_text('pass_subject'), 60, 180, t('Customize the Subject of your forgotten password e-mail.') .' '. t('Available variables are:') .' %username, %site, %login_url, %uri, %uri_brief, %mailto, %date, %login_uri, %edit_uri.');
- $group .= form_textarea(t('Body of password recovery e-mail'), 'user_mail_pass_body', _user_mail_text('pass_body'), 60, 15, t('Customize the body of the forgotten password e-mail.') .' '. t('Available variables are:') .' %username, %site, %login_url, %uri, %uri_brief, %mailto, %login_uri, %edit_uri.');
- $output .= form_group(t('User email settings'), $group);
-
- // If picture support is enabled, check whether the picture directory exists:
- if (variable_get('user_pictures', 0)) {
- $picture_path = file_create_path(variable_get('user_picture_path', 'pictures'));
- file_check_directory($picture_path, 1, 'user_picture_path');
- }
-
- $group = form_radios(t('Picture support'), 'user_pictures', variable_get('user_pictures', 0), array(t('Disabled'), t('Enabled')), t('Enable picture support.'));
- $group .= form_textfield(t('Picture image path'), 'user_picture_path', variable_get('user_picture_path', 'pictures'), 30, 255, t('Subdirectory in the directory "%dir" where pictures will be stored.', array('%dir' => variable_get('file_directory_path', 'files') .'/')));
- $group .= form_textfield(t('Default picture'), 'user_picture_default', variable_get('user_picture_default', ''), 30, 255, t('URL of picture to display for users with no custom picture selected. Leave blank for none.'));
- $group .= form_textfield(t('Picture maximum dimensions'), 'user_picture_dimensions', variable_get('user_picture_dimensions', '85x85'), 15, 10, t('Maximum dimensions for pictures.'));
- $group .= form_textfield(t('Picture maximum file size'), 'user_picture_file_size', variable_get('user_picture_file_size', '30'), 15, 10, t('Maximum file size for pictures, in kB.'));
- $group .= form_textarea(t('Picture guidelines'), 'user_picture_guidelines', variable_get('user_picture_guidelines', ''), 60, 5, t('This text is displayed at the picture upload form in addition to the default guidelines. It\'s useful for helping or instructing your users.'));
-
- $output .= form_group(t('Pictures'), $group);
-
- return $output;
}
/**
@@ -1412,28 +1385,52 @@ function user_admin_access_check() {
$edit = $_POST['edit'];
if ($op) {
- if (drupal_is_denied($edit['type'], $edit['test'])) {
- drupal_set_message(t('%test is not allowed.', array('%test' => theme('placeholder', $edit['test']))));
+ if ($edit['user']) {
+ if (drupal_is_denied('user', $edit['user']['test'])) {
+ drupal_set_message(t('The username %name is not allowed.', array('%name' => theme('placeholder', $edit['user']['test']))));
+ }
+ else {
+ drupal_set_message(t('The username %name is allowed.', array('%name' => theme('placeholder', $edit['user']['test']))));
+ }
}
- else {
- drupal_set_message(t('%test is allowed.', array('%test' => theme('placeholder', $edit['test']))));
+ if ($edit['mail']) {
+ if (drupal_is_denied('mail', $edit['mail']['test'])) {
+ drupal_set_message(t('The e-mail address %mail is not allowed.', array('%mail' => theme('placeholder', $edit['mail']['test']))));
+ }
+ else {
+ drupal_set_message(t('The e-mail address %mail is allowed.', array('%mail' => theme('placeholder', $edit['mail']['test']))));
+ }
+ }
+ if ($edit['host']) {
+ if (drupal_is_denied('host', $edit['host']['test'])) {
+ drupal_set_message(t('The hostname %host is not allowed.', array('%host' => theme('placeholder', $edit['host']['test']))));
+ }
+ else {
+ drupal_set_message(t('The hostname %host is allowed.', array('%host' => theme('placeholder', $edit['host']['test']))));
+ }
}
}
- $form = form_textfield('', 'test', '', 30, 64, t('Enter a username to check if it will be denied or allowed.'));
- $form .= form_hidden('type', 'user');
- $form .= form_submit(t('Check username'));
- $output .= form_group(t('Username'), form($form));
+ $form['user'] = array(type => 'fieldset', title => t('Username'));
+ $form['user']['test'] = array(type => 'textfield', title => '', description => t('Enter a username to check if it will be denied or allowed.'), size => 30, maxlength => 64);
+ $form['user']['type'] = array(type => 'hidden', value => 'user');
+ $form['user']['submit'] = array(type => 'submit', value => t('Check username'));
+ $output .= drupal_get_form('check_user', $form);
+ unset($form); // prevent endless loop?
- $form = form_textfield('', 'test', '', 30, 64, t('Enter an e-mail address to check if it will be denied or allowed.'));
- $form .= form_hidden('type', 'mail');
- $form .= form_submit(t('Check e-mail'));
- $output .= form_group(t('E-mail'), form($form));
+ $form['mail'] = array(type => 'fieldset', title => t('E-mail'));
+ $form['mail']['test'] = array(type => 'textfield', title => '', description => t('Enter an e-mail address to check if it will be denied or allowed.'), size => 30, maxlength => 64);
+ $form['mail']['type'] = array(type => 'hidden', value => 'mail');
+ $form['mail']['submit'] = array(type => 'submit', value => t('Check e-mail'));
+ $output .= drupal_get_form('check_mail', $form);
+ unset($form); // prevent endless loop?
- $form = form_textfield('', 'test', '', 30, 64, t('Enter a host to check if it will be denied or allowed.'));
- $form .= form_hidden('type', 'host');
- $form .= form_submit(t('Check host'));
- $output .= form_group(t('Host'), form($form));
+ $form['host'] = array(type => 'fieldset', title => t('Hostname'));
+ $form['host']['test'] = array(type => 'textfield', title => '', description => t('Enter a hostname or IP address to check if it will be denied or allowed.'), size => 30, maxlength => 64);
+ $form['host']['type'] = array(type => 'hidden', value => 'host');
+ $form['host']['submit'] = array(type => 'submit', value => t('Check hostname'));
+ $output .= drupal_get_form('check_host', $form);
+ unset($form); // prevent endless loop?
return $output;
}
@@ -1459,33 +1456,33 @@ function user_admin_access_add($mask = NULL, $type = NULL) {
}
$form = _user_admin_access_form($edit);
- $form .= form_submit(t('Add rule'));
+ $form['submit'] = array(type => 'submit', value => t('Add rule'));
- return form($form, 'post', NULL, array('id' => 'access-rules'));
+ return drupal_get_form('access_rule', $form);
}
/**
* Menu callback: delete an access rule
*/
function user_admin_access_delete($aid = 0) {
- if ($_POST['edit']['confirm']) {
- db_query('DELETE FROM {access} WHERE aid = %d', $aid);
- drupal_set_message(t('The access rule has been deleted.'));
- drupal_goto('admin/access/rules');
- }
- else {
- $access_types = array('user' => t('username'), 'mail' => t('e-mail'));
- $edit = db_fetch_object(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid));
+ $access_types = array('user' => t('username'), 'mail' => t('e-mail'));
+ $edit = db_fetch_object(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid));
+
+ $form = array();
+ $form['aid'] = array(type => 'hidden', value => $aid);
+ $output = confirm_form('user_admin_access_delete_confirm', $form,
+ t('Are you sure you want to delete the %type rule for %rule?', array('%type' => $access_types[$edit->type], '%rule' => theme('placeholder', $edit->mask))),
+ 'admin/access/rules',
+ t('This action cannot be undone.'),
+ t('Delete'),
+ t('Cancel'));
+ return $output;
+}
- $output = theme('confirm',
- t('Are you sure you want to delete the %type rule for %rule?', array('%type' => $access_types[$edit->type], '%rule' => theme('placeholder', $edit->mask))),
- 'admin/access/rules',
- t('This action cannot be undone.'),
- t('Delete'),
- t('Cancel'),
- $extra);
- return $output;
- }
+function user_admin_access_delete_confirm_execute($form_id, $edit) {
+ db_query('DELETE FROM {access} WHERE aid = %d', $edit['aid']);
+ drupal_set_message(t('The access rule has been deleted.'));
+ drupal_goto('admin/access/rules');
}
/**
@@ -1506,16 +1503,17 @@ function user_admin_access_edit($aid = 0) {
$edit = db_fetch_array(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid));
}
$form = _user_admin_access_form($edit);
- $form .= form_submit(t('Save rule'));
- return form($form, 'post', NULL, array('id' => 'access-rules'));
+ $form['submit'] = array(type => 'submit', value => t('Save rule'));
+
+ return drupal_get_form('access_rule', $form);
}
function _user_admin_access_form($edit) {
- $output = '<div class="access-type">'. form_radios(t('Access type'), 'status', $edit['status'], array('1' => t('Allow'), '0' => t('Deny'))) .'</div>';
- $output .= '<div class="rule-type">'. form_radios(t('Rule type'), 'type', $edit['type'] ? $edit['type'] : 'user', array('user' => t('Username'), 'mail' => t('E-mail'), 'host' => t('Host'))) .'</div>';
- $output .= '<div class="mask">'. form_textfield(t('Mask'), 'mask', $edit['mask'], 30, 64, '%: '. t('Matches any number of characters, even zero characters') .'.<br />_: '. t('Matches exactly one character.'), NULL, TRUE) .'</div>';
+ $form['status'] = array(type => 'radios', title => t('Access type'), default_value => $edit['status'], options => array('1' => t('Allow'), '0' => t('Deny')));
+ $form['type'] = array(type => 'radios', title => t('Rule type'), default_value => $edit['type'], options => array('user' => t('Username'), 'mail' => t('E-mail'), 'host' => t('Host'), default_value => 'host'));
+ $form['mask'] = array(type => 'textfield', title => t('Mask'), default_value => $edit['mask'], size => 30, maxlength => 64, description => '%: '. t('Matches any number of characters, even zero characters') .'.<br />_: '. t('Matches exactly one character.'), required => TRUE);
- return $output;
+ return $form;
}
/**
@@ -1558,31 +1556,6 @@ function user_roles($membersonly = 0, $permission = 0) {
* Menu callback: administer permissions.
*/
function user_admin_perm() {
- $edit = $_POST['edit'];
- if ($edit) {
- // Save permissions:
- $result = db_query('SELECT * FROM {role}');
- while ($role = db_fetch_object($result)) {
- // Delete, so if we clear every checkbox we reset that role;
- // otherwise permissions are active and denied everywhere.
- db_query('DELETE FROM {permission} WHERE rid = %d', $role->rid);
- foreach ($edit[$role->rid] as $key => $value) {
- if (!$value) {
- unset($edit[$role->rid][$key]);
- }
- }
- if (count($edit[$role->rid])) {
- db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $role->rid, implode(', ', array_keys($edit[$role->rid])));
- }
- }
-
- drupal_set_message(t('The changes have been saved.'));
-
- // Clear the cached pages and menus:
- menu_rebuild();
-
- drupal_goto($_GET['q']);
- }
// Compile role array:
$result = db_query('SELECT r.rid, p.perm FROM {role} r LEFT JOIN {permission} p ON r.rid = p.rid ORDER BY name');
@@ -1598,27 +1571,88 @@ function user_admin_perm() {
}
// Render role/permission overview:
- $header = array_merge(array(t('Permission')), $role_names);
-
+ $options = array();
foreach (module_list() as $module) {
if ($permissions = module_invoke($module, 'perm')) {
- $rows[] = array(array('data' => t('%module module', array('%module' => $module)), 'class' => 'module', 'colspan' => count($role_names) + 1));
+ $form['permission'][] = array(type => 'markup', value => t('%module module', array('%module' => $module)));
asort($permissions);
foreach ($permissions as $perm) {
- $row[] = array('data' => t($perm), 'class' => 'permission');
+ $options[$perm] = '';
+ $form['permission'][$perm] = array(type => 'markup', value => t($perm));
foreach ($role_names as $rid => $name) {
- $row[] = form_checkbox('', "$rid][$perm", 1, strstr($role_permissions[$rid], $perm), NULL, array('title' => $name .': '. t($perm)));
+ // Builds arrays for checked boxes for each role
+ if (strstr($role_permissions[$rid], $perm)) {
+ $status[$rid][] = $perm;
+ }
}
- $rows[] = $row;
- unset($row);
}
}
}
+ // Have to build checkboxes here after checkbox arrays are built
+ foreach ($role_names as $rid => $name) {
+ $form['checkboxes'][$rid] = array(type => 'checkboxes', options => $options, default_value => $status[$rid], tree => TRUE);
+ $form['role_names'][$rid] = array(type => 'markup', value => $name, tree => TRUE);
+ }
+ $form['submit'] = array(type => 'submit', value => t('Save permissions'));
+ return drupal_get_form('user_admin_perm', $form);
+}
+
+function theme_user_admin_perm($form) {
+ foreach (element_children($form['permission']) as $key) {
+ // Don't take form control structures
+ if (is_array($form['permission'][$key])) {
+ $row = array();
+ // Module name
+ if (is_numeric($key)) {
+ $row[] = array('data' => form_render($form['permission'][$key]), 'class' => 'module', 'colspan' => count($form['role_names']) + 1);
+ // Permissions
+ } else {
+ $row[] = array('data' => form_render($form['permission'][$key]), 'class' => 'permission');
+ foreach (element_children($form['checkboxes']) as $rid) {
+ if (is_array($form['checkboxes'][$rid])) {
+ $row[] = array('data' => form_render($form['checkboxes'][$rid][$key]), 'align' => 'center');
+ }
+ }
+ }
+ $rows[] = $row;
+ }
+ }
+ $header[] = (t('Permission'));
+ foreach (element_children($form['role_names']) as $rid) {
+ if (is_array($form['role_names'][$rid])) {
+ $header[] = form_render($form['role_names'][$rid]);
+ }
+ }
$output = theme('table', $header, $rows, array('id' => 'permissions'));
- $output .= form_submit(t('Save permissions'));
+ $output .= form_render($form);
+ return $output;
+}
+
+function user_admin_perm_execute() {
+ $edit = $GLOBALS['form_values']['checkboxes'];
+ // Save permissions:
+ $result = db_query('SELECT * FROM {role}');
+ while ($role = db_fetch_object($result)) {
+ // Delete, so if we clear every checkbox we reset that role;
+ // otherwise permissions are active and denied everywhere.
+ db_query('DELETE FROM {permission} WHERE rid = %d', $role->rid);
+ foreach ($edit[$role->rid] as $key => $value) {
+ if (!$value) {
+ unset($edit[$role->rid][$key]);
+ }
+ }
+ if (count($edit[$role->rid])) {
+ db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $role->rid, implode(', ', array_keys($edit[$role->rid])));
+ }
+ }
+
+ drupal_set_message(t('The changes have been saved.'));
+
+ // Clear the cached pages and menus:
+ menu_rebuild();
- return form($output);
+ drupal_goto($_GET['q']);
}
/**
@@ -1673,34 +1707,32 @@ function user_admin_role() {
else if ($id) {
// Display the role form.
$role = db_fetch_object(db_query('SELECT * FROM {role} WHERE rid = %d', $id));
+ $form['name'] = array(type => 'textfield', title => t('Role name'), default_value => $role->name, size => 30, maxlength => 64, description => t('The name for this role. Example: "moderator", "editorial board", "site architect".'));
+ $form['submit'] = array(type => 'submit', value => t('Save role'));
+ $form['delete'] = array(type => 'submit', value => t('Delete role'));
+ return drupal_get_form('user_admin_role', $form);
+ }
+ $form['name'] = array(type => 'textfield', size => 32, maxlength => 64);
+ $form['submit'] = array(type => 'submit', value => t('Add role'));
+ return drupal_get_form('user_admin_new_role', $form);
+}
- $output .= form_textfield(t('Role name'), 'name', $role->name, 30, 64, t('The name for this role. Example: "moderator", "editorial board", "site architect".'));
- $output .= form_submit(t('Save role'));
- $output .= form_submit(t('Delete role'));
-
- $output = form($output);
- }
-
- if (!$output) {
- // Render the role overview.
- $result = db_query('SELECT * FROM {role} ORDER BY name');
+function theme_user_admin_new_role($form) {
+ // Render the role overview.
+ $result = db_query('SELECT * FROM {role} ORDER BY name');
- $header = array(t('Name'), t('Operations'));
- while ($role = db_fetch_object($result)) {
- if ($role->name != 'anonymous user' && $role->name != 'authenticated user') {
- $rows[] = array($role->name, l(t('edit'), 'admin/access/roles/edit/'. $role->rid));
- }
- else {
- $rows[] = array($role->name, '<span class="disabled">'. t('locked') .'</span>');
- }
+ $header = array(t('Name'), t('Operations'));
+ while ($role = db_fetch_object($result)) {
+ if ($role->name != 'anonymous user' && $role->name != 'authenticated user') {
+ $rows[] = array($role->name, l(t('edit'), 'admin/access/roles/edit/'. $role->rid));
+ }
+ else {
+ $rows[] = array($role->name, '<span class="disabled">'. t('locked') .'</span>');
}
- $rows[] = array('<input type="text" size="32" maxlength="64" name="edit[name]" />', '<input type="submit" name="op" value="'. t('Add role') .'" />');
-
- $output = theme('table', $header, $rows);
- $output = form($output);
}
+ $rows[] = array(form_render($form['name']), form_render($form['submit']));
- return $output;
+ return theme('table', $header, $rows);
}
function user_admin_account() {
@@ -1731,19 +1763,35 @@ function user_admin_account() {
}
function user_configure() {
- $op = $_POST['op'];
- $edit = $_POST['edit'];
+ // User registration settings.
+ $form['registration'] = array(type => 'fieldset', title => t('User registration settings'));
+ $form['registration']['user_register'] = array(type => 'radios', title => t('Public registrations'), default_value => variable_get('user_register', 1), options => array(t('Only site administrators can create new user accounts.'), t('Visitors can create accounts and no administrator approval is required.'), t('Visitors can create accounts but administrator approval is required.')));
+ $form['registration']['user_registration_help'] = array(type => 'textarea', title => t('User registration guidelines'), default_value => variable_get('user_registration_help', ''), cols => 60, rows => 5, description => t('This text is displayed at the top of the user registration form. It\'s useful for helping or instructing your users.'));
- if (empty($op)) {
- $op = arg(3);
- }
+ // User e-mail settings.
+ $form['email'] = array(type => 'fieldset', title => t('User email settings'));
+ $form['email']['user_mail_welcome_subject'] = array(type => 'textfield', title => t('Subject of welcome e-mail'), default_value => _user_mail_text('welcome_subject'), size => 60, maxlength => 180, description => t('Customize the subject of your welcome e-mail, which is sent to new members upon registering.') .' '. t('Available variables are:') .' %username, %site, %password, %uri, %uri_brief, %mailto, %date, %login_uri, %edit_uri, %login_url.');
+ $form['email']['user_mail_welcome_body'] = array(type => 'textarea', title => t('Body of welcome e-mail'), default_value => _user_mail_text('welcome_body'), cols => 60, rows => 15, description => t('Customize the body of the welcome e-mail, which is sent to new members upon registering.') .' '. t('Available variables are:') .' %username, %site, %password, %uri, %uri_brief, %mailto, %login_uri, %edit_uri, %login_url.');
+ $form['email']['user_mail_approval_subject'] = array(type => 'textfield', title => t('Subject of welcome e-mail (awaiting admin approval)'), default_value => _user_mail_text('approval_subject'), size => 60, maxlength => 180, description => t('Customize the subject of your awaiting approval welcome e-mail, which is sent to new members upon registering.') .' '. t('Available variables are:') .' %username, %site, %password, %uri, %uri_brief, %mailto, %date, %login_uri, %edit_uri, %login_url.');
+ $form['email']['user_mail_approval_body'] = array(type => 'textarea', title => t('Body of welcome e-mail (awaiting admin approval)'), default_value => _user_mail_text('approval_body'), cols => 60, rows => 15, description => t('Customize the body of the awaiting approval welcome e-mail, which is sent to new members upon registering.') .' '. t('Available variables are:') .' %username, %site, %password, %uri, %uri_brief, %mailto, %login_uri, %edit_uri, %login_url.');
+ $form['email']['user_mail_pass_subject'] = array(type => 'textfield', title => t('Subject of password recovery e-mail'), default_value => _user_mail_text('pass_subject'), size => 60, maxlength => 180, description => t('Customize the Subject of your forgotten password e-mail.') .' '. t('Available variables are:') .' %username, %site, %login_url, %uri, %uri_brief, %mailto, %date, %login_uri, %edit_uri.');
+ $form['email']['user_mail_pass_body'] = array(type => 'textarea', title => t('Body of password recovery e-mail'), default_value => _user_mail_text('pass_body'), cols => 60, rows => 15, description => t('Customize the body of the forgotten password e-mail.') .' '. t('Available variables are:') .' %username, %site, %login_url, %uri, %uri_brief, %mailto, %login_uri, %edit_uri.');
- if ($_POST) {
- system_settings_save();
+ // If picture support is enabled, check whether the picture directory exists:
+ if (variable_get('user_pictures', 0)) {
+ $picture_path = file_create_path(variable_get('user_picture_path', 'pictures'));
+ file_check_directory($picture_path, 1, 'user_picture_path');
}
- $output = system_settings_form(user_configure_settings());
- return $output;
+ $form['pictures'] = array(type => 'fieldset', title => t('Pictures'));
+ $form['pictures']['user_pictures'] = array(type => 'radios', title => t('Picture support'), default_value => variable_get('user_pictures', 0), options => array(t('Disabled'), t('Enabled')), description => t('Enable picture support.'));
+ $form['pictures']['user_picture_path'] = array(type => 'textfield', title => t('Picture image path'), default_value => variable_get('user_picture_path', 'pictures'), size => 30, maxlength => 255, description => t('Subdirectory in the directory "%dir" where pictures will be stored.', array('%dir' => variable_get('file_directory_path', 'files') .'/')));
+ $form['pictures']['user_picture_default'] = array(type => 'textfield', title => t('Default picture'), default_value => variable_get('user_picture_default', ''), size => 30, maxlength => 255, description => t('URL of picture to display for users with no custom picture selected. Leave blank for none.'));
+ $form['pictures']['user_picture_dimensions'] = array(type => 'textfield', title => t('Picture maximum dimensions'), default_value => variable_get('user_picture_dimensions', '85x85'), size => 15, maxlength => 10, description => t('Maximum dimensions for pictures.'));
+ $form['pictures']['user_picture_file_size'] = array(type => 'textfield', title => t('Picture maximum file size'), default_value => variable_get('user_picture_file_size', '30'), size => 15, maxlength => 10, description => t('Maximum file size for pictures, in kB.'));
+ $form['pictures']['user_picture_guidelines'] = array(type => 'textarea', title => t('Picture guidelines'), default_value => variable_get('user_picture_guidelines', ''), cols => 60, rows => 5, description => t('This text is displayed at the picture upload form in addition to the default guidelines. It\'s useful for helping or instructing your users.'));
+
+ return system_settings_form('user_configure_settings', $form);
}
function user_admin() {
@@ -1880,15 +1928,9 @@ function _user_forms(&$edit, $account, $category, $hook = 'form') {
$groups = array_merge($data, $groups);
}
}
-
usort($groups, '_user_sort');
- $output = '';
- foreach ($groups as $group) {
- $output .= form_group($group['title'], $group['data']);
- }
-
- return $output;
+ return empty($groups) ? FALSE : $groups;
}
/**
diff --git a/modules/watchdog.module b/modules/watchdog.module
index bf2192566..6e2066cdd 100644
--- a/modules/watchdog.module
+++ b/modules/watchdog.module
@@ -77,13 +77,18 @@ function watchdog_overview() {
$_SESSION['watchdog_overview_filter'] = 'all';
}
- $op = $_POST['op'];
- if ($op == t('Filter') && isset($_POST['edit']['filter'])) {
- $_SESSION['watchdog_overview_filter'] = $_POST['edit']['filter'];
+ if (empty($_SESSION['watchdog_overview_filter'])) {
+ $_SESSION['watchdog_overview_filter'] = 'all';
}
- $form = form_select(t('Filter by message type'), 'filter', $_SESSION['watchdog_overview_filter'], $names);
- $form .= form_submit(t('Filter'));
+ $form['filter'] = array(
+ type => 'select',
+ title => t('Filter by message type'),
+ options => $names,
+ default_value => $_SESSION['watchdog_overview_filter']
+ );
+
+ $form['submit'] = array(type => 'submit', value =>t('Filter'));
$header = array(
' ',
@@ -117,13 +122,22 @@ function watchdog_overview() {
$rows[] = array(array('data' => t('No log messages available.'), 'colspan' => '7'));
}
- $output = '<div class="container-inline">'. form($form) .'</div>';
+ $output = drupal_get_form('watchdog_form_overview', $form);
$output .= theme('table', $header, $rows);
$output .= theme('pager', NULL, 50, 0, tablesort_pager());
return $output;
}
+function theme_watchdog_form_overview($form) {
+ return '<div class="container-inline">'. form_render($form) .'</div>';
+}
+
+function watchdog_form_overview_execute($form_id, $form) {
+ global $form_values;
+ $_SESSION['watchdog_overview_filter'] = $form_values['filter'];
+}
+
/**
* Menu callback; displays details about a log message.
*/
diff --git a/modules/watchdog/watchdog.module b/modules/watchdog/watchdog.module
index bf2192566..6e2066cdd 100644
--- a/modules/watchdog/watchdog.module
+++ b/modules/watchdog/watchdog.module
@@ -77,13 +77,18 @@ function watchdog_overview() {
$_SESSION['watchdog_overview_filter'] = 'all';
}
- $op = $_POST['op'];
- if ($op == t('Filter') && isset($_POST['edit']['filter'])) {
- $_SESSION['watchdog_overview_filter'] = $_POST['edit']['filter'];
+ if (empty($_SESSION['watchdog_overview_filter'])) {
+ $_SESSION['watchdog_overview_filter'] = 'all';
}
- $form = form_select(t('Filter by message type'), 'filter', $_SESSION['watchdog_overview_filter'], $names);
- $form .= form_submit(t('Filter'));
+ $form['filter'] = array(
+ type => 'select',
+ title => t('Filter by message type'),
+ options => $names,
+ default_value => $_SESSION['watchdog_overview_filter']
+ );
+
+ $form['submit'] = array(type => 'submit', value =>t('Filter'));
$header = array(
' ',
@@ -117,13 +122,22 @@ function watchdog_overview() {
$rows[] = array(array('data' => t('No log messages available.'), 'colspan' => '7'));
}
- $output = '<div class="container-inline">'. form($form) .'</div>';
+ $output = drupal_get_form('watchdog_form_overview', $form);
$output .= theme('table', $header, $rows);
$output .= theme('pager', NULL, 50, 0, tablesort_pager());
return $output;
}
+function theme_watchdog_form_overview($form) {
+ return '<div class="container-inline">'. form_render($form) .'</div>';
+}
+
+function watchdog_form_overview_execute($form_id, $form) {
+ global $form_values;
+ $_SESSION['watchdog_overview_filter'] = $form_values['filter'];
+}
+
/**
* Menu callback; displays details about a log message.
*/
diff --git a/themes/bluemarine/page.tpl.php b/themes/bluemarine/page.tpl.php
index 0625a4655..f2d3b19e7 100644
--- a/themes/bluemarine/page.tpl.php
+++ b/themes/bluemarine/page.tpl.php
@@ -20,12 +20,7 @@
<td id="menu">
<?php if ($secondary_links) { ?><div id="secondary"><?php print theme('links', $secondary_links) ?></div><?php } ?>
<?php if ($primary_links) { ?><div id="primary"><?php print theme('links', $primary_links) ?></div><?php } ?>
- <?php if ($search_box) { ?><form action="<?php print $search_url ?>" method="post">
- <div id="search">
- <input class="form-text" type="text" size="15" value="" name="edit[keys]" alt="<?php print $search_description ?>" />
- <input class="form-submit" type="submit" value="<?php print $search_button_text ?>" />
- </div>
- </form><?php } ?>
+ <?php print $search_box ?>
</td>
</tr>
<tr>
diff --git a/themes/engines/phptemplate/phptemplate.engine b/themes/engines/phptemplate/phptemplate.engine
index a793509d7..455186080 100644
--- a/themes/engines/phptemplate/phptemplate.engine
+++ b/themes/engines/phptemplate/phptemplate.engine
@@ -199,10 +199,7 @@ function phptemplate_page($content) {
'primary_links' => theme_get_setting('primary_links'),
'site_name' => (theme_get_setting('toggle_name') ? variable_get('site_name', 'Drupal') : ''),
'site_slogan' => (theme_get_setting('toggle_slogan') ? variable_get('site_slogan', '') : ''),
- 'search_box' => theme_get_setting('toggle_search'),
- 'search_button_text' => t('search'),
- 'search_description' => t('Enter the terms you wish to search for.'),
- 'search_url' => url('search'),
+ 'search_box' => (theme_get_setting('toggle_search') ? search_box() : ''),
'secondary_links' => theme_get_setting('secondary_links'),
'sidebar_left' => $sidebar_left,
'sidebar_right' => $sidebar_right,
diff --git a/themes/pushbutton/page.tpl.php b/themes/pushbutton/page.tpl.php
index 88a3d2783..bc46c38dd 100644
--- a/themes/pushbutton/page.tpl.php
+++ b/themes/pushbutton/page.tpl.php
@@ -45,14 +45,7 @@
<?php print theme('links', $secondary_links) ?>
</td>
<td width="25%" align="center" valign="middle">
- <?php if ($search_box): ?>
- <form action="<?php print $search_url ?>" method="post">
- <div id="search">
- <input class="form-text" type="text" size="15" value="" name="edit[keys]" alt="<?php print $search_description ?>" />
- <input class="form-submit" type="submit" value="<?php print $search_button_text ?>" alt="submit" />
- </div>
- </form>
- <?php endif; ?>
+ <?php print $search_box ?>
</td>
</tr>
<tr>
diff --git a/update.php b/update.php
index d0f961efb..706988845 100644
--- a/update.php
+++ b/update.php
@@ -54,11 +54,20 @@ function update_selection_page() {
$dates[$i] = "No updates available";
// make update form and output it.
- $form = form_select("Perform updates from", "start", (isset($selected) ? $selected : -1), $dates, "This defaults to the first available update since the last update you performed.");
- $form .= form_submit("Update");
+ $form['start'] = array(
+ type => 'select',
+ title => t('Perform updates from'),
+ default_value => (isset($selected) ? $selected : -1),
+ options => $dates,
+ description => t('This defaults to the first available update since the last update you performed.')
+ );
+ $form['submit'] = array(
+ type => 'submit',
+ value => t('Update')
+ );
drupal_set_title('Drupal database update');
- return form($form);
+ return drupal_get_form('update_script_selection_form', $form);
}
function update_do_updates() {