- 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.
4.7.x
Dries Buytaert 2005-10-07 06:11:12 +00:00
parent 7b5b460534
commit 7e1527ee61
63 changed files with 6502 additions and 4853 deletions

View File

@ -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.

View File

@ -478,38 +478,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
* @{
@ -549,6 +517,7 @@ function object2array($object) {
return $array;
}
/**
* @} End of "Conversion".
*/
@ -999,600 +968,6 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL
* @} End of "defgroup format".
*/
/**
* @defgroup form Form generation
* @{
* Functions to enable output of HTML forms and form elements.
*
* Drupal uses these functions to achieve consistency in its form presentation,
* while at the same time simplifying code and reducing the amount of HTML that
* must be explicitly generated by modules.
*/
/**
* Generate a form from a set of form elements.
*
* @param $form
* An HTML string containing one or more form elements.
* @param $method
* The query method to use ("post" or "get").
* @param $action
* The URL to send the form contents to, if not the current page.
* @param $attributes
* An associative array of attributes to add to the form tag.
* @result
* An HTML string with the contents of $form wrapped in a form tag.
*/
function form($form, $method = 'post', $action = NULL, $attributes = NULL) {
if (!$action) {
$action = request_uri();
}
// Anonymous div to satisfy XHTML compliancy.
return '<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.
*
@ -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.

1078
includes/form.inc Normal file

File diff suppressed because it is too large Load Diff

584
includes/legacy.inc Normal file
View File

@ -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".
*/

View File

@ -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 = 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';
$form .= form_submit(t('Search'));
$output = form(form_group(t('Search strings'), $form), 'post', url('admin/locale/string/search'));
return $output;
return drupal_get_form('_locale_string_seek', $form);
}
// ---------------------------------------------------------------------------------

View File

@ -958,55 +958,6 @@ function theme_blocks($region) {
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 $_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.
*

View File

@ -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) {
}
}

View File

@ -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; }

View File

@ -58,4 +58,4 @@ jsUpload.prototype.oncomplete = function (data) {
// Replace form and re-attach behaviour
$(this.wrapper).innerHTML = data;
uploadAutoAttach();
}
}

View File

@ -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);
}
$form['header'] = array(value => $header);
$output .= $form['header'][value];
$result = pager_query($sql, 20);
$rows = array();
$categories = array();
while ($item = db_fetch_object($result)) {
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;
}
}
$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));
}
}
$rows[] = array(theme('aggregator_page_item', $item), array('data' => $form, 'class' => 'categorize-item'));
}
else {
$output .= theme('aggregator_page_item', $item);
}
}
if ($categorize) {
$output .= form(theme('table', array('', t('Categorize')), $rows) . form_submit(t('Save categories')));
}
$output .= '</div>';
$form['items'][$item->iid] = array(value => theme('aggregator_page_item', $item));
$output .= $form['items'][$item->iid][value];
$form['categories'][$item->iid] = array();
$output .= theme('pager', NULL, 20, 0);
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);
$selected = array();
while ($category = db_fetch_object($categories_result)) {
if (!$done) {
$categories[$category->cid] = check_plain($category->title);
}
if ($category->iid) {
$selected[] = $category->cid;
}
}
$done = true;
$form['categories'][$item->iid] = array(
type => variable_get('aggregator_category_selector', 'checkboxes'),
default_value => $selected, options => $categories,
size => 10, multiple => true
);
}
}
$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.
*/

View File

@ -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);
}
$form['header'] = array(value => $header);
$output .= $form['header'][value];
$result = pager_query($sql, 20);
$rows = array();
$categories = array();
while ($item = db_fetch_object($result)) {
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;
}
}
$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));
}
}
$rows[] = array(theme('aggregator_page_item', $item), array('data' => $form, 'class' => 'categorize-item'));
}
else {
$output .= theme('aggregator_page_item', $item);
}
}
if ($categorize) {
$output .= form(theme('table', array('', t('Categorize')), $rows) . form_submit(t('Save categories')));
}
$output .= '</div>';
$form['items'][$item->iid] = array(value => theme('aggregator_page_item', $item));
$output .= $form['items'][$item->iid][value];
$form['categories'][$item->iid] = array();
$output .= theme('pager', NULL, 20, 0);
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);
$selected = array();
while ($category = db_fetch_object($categories_result)) {
if (!$done) {
$categories[$category->cid] = check_plain($category->title);
}
if ($category->iid) {
$selected[] = $category->cid;
}
}
$done = true;
$form['categories'][$item->iid] = array(
type => variable_get('aggregator_category_selector', 'checkboxes'),
default_value => $selected, options => $categories,
size => 10, multiple => true
);
}
}
$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.
*/

View File

@ -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['user_vis_settings'] = array(type => 'fieldset',
title => t('User specific visibility settings'),
collapsible => true,
collapsed => false,
weight => 0);
$form .= form_group(t('User specific visibility settings'), $group_1);
$form .= form_group(t('Page specific visibility settings'), $group_2);
$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 .= form_submit(t('Save block'));
$form['page_vis_settings'] = array(type => 'fieldset',
title => t('Page specific visibility settings'),
collapsible => true,
collapsed => false,
weight => 0);
return form($form);
$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'];
$form['info'] = array(type => 'hidden', value => $box['info'] ? $box['info'] : $box['title']);
$form['bid'] = array(type => 'hidden', value => $bid);
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'));
}
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'));
}
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);
/**
* 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');
};
return $output;
function block_box_form($edit = array()) {
$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 $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;
}
}

View File

@ -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['user_vis_settings'] = array(type => 'fieldset',
title => t('User specific visibility settings'),
collapsible => true,
collapsed => false,
weight => 0);
$form .= form_group(t('User specific visibility settings'), $group_1);
$form .= form_group(t('Page specific visibility settings'), $group_2);
$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 .= form_submit(t('Save block'));
$form['page_vis_settings'] = array(type => 'fieldset',
title => t('Page specific visibility settings'),
collapsible => true,
collapsed => false,
weight => 0);
return form($form);
$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'];
$form['info'] = array(type => 'hidden', value => $box['info'] ? $box['info'] : $box['title']);
$form['bid'] = array(type => 'hidden', value => $bid);
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'));
}
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'));
}
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);
/**
* 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');
};
return $output;
function block_box_form($edit = array()) {
$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 $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;
}
}

View File

@ -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;
}
/**

View File

@ -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;
}
/**

View File

@ -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) {

View File

@ -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) {

View File

@ -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();

View File

@ -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();

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -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;
}
/**

View File

@ -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;
}
/**

View File

@ -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));
//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));
//Add a row of checkboxes for form group
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['default_format'] = array(type => 'hidden', value => 1);
}
$form .= form_group(t('Roles'), $group, $default ? $help : t('Choose which roles may use this filter format.'));
//Add the name of the object
$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,");
$form['roles'][$rid] = array(type => 'checkbox', title => $name, default_value => ($default || $checked));
if ($default) {
$form['roles'][$rid][attributes] = array('disabled' => 'disabled');
}
}
// 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);
foreach ($filters as $id => $filter) {
$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'));
return drupal_get_form('filter_admin_order', $form);
}
function theme_filter_admin_order($form) {
$header = array(t('Name'), t('Weight'));
$rows = array();
foreach ($filters as $id => $filter) {
$rows[] = array($filter->name, form_weight('', $id, $filter->weight));
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]));
}
}
$form = theme('table', $header, $rows);
$form .= form_submit(t('Save configuration'));
$output = form($form);
$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);
$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 $output;
return $form;
}
/**
@ -1019,4 +1042,3 @@ function _filter_autop($text) {
* @} End of "Standard filters".
*/

View File

@ -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));
//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));
//Add a row of checkboxes for form group
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['default_format'] = array(type => 'hidden', value => 1);
}
$form .= form_group(t('Roles'), $group, $default ? $help : t('Choose which roles may use this filter format.'));
//Add the name of the object
$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,");
$form['roles'][$rid] = array(type => 'checkbox', title => $name, default_value => ($default || $checked));
if ($default) {
$form['roles'][$rid][attributes] = array('disabled' => 'disabled');
}
}
// 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);
foreach ($filters as $id => $filter) {
$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'));
return drupal_get_form('filter_admin_order', $form);
}
function theme_filter_admin_order($form) {
$header = array(t('Name'), t('Weight'));
$rows = array();
foreach ($filters as $id => $filter) {
$rows[] = array($filter->name, form_weight('', $id, $filter->weight));
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]));
}
}
$form = theme('table', $header, $rows);
$form .= form_submit(t('Save configuration'));
$output = form($form);
$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);
$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 $output;
return $form;
}
/**
@ -1019,4 +1042,3 @@ function _filter_autop($text) {
* @} End of "Standard filters".
*/

View File

@ -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['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 .= _forum_parent_select($edit['tid'], t('Parent'), 'parent][', 'container');
$form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('When listing containers, those with with light (small) weights get listed before containers with heavier (larger) weights. Containers with equal weights are sorted alphabetically.'));
$form .= form_hidden('vid', _forum_get_vid());
$form .= form_submit(t('Submit'));
$form['vid'] = array(type => 'hidden', value => _forum_get_vid());
$form['submit'] = array(type => 'submit', value => t('Submit'));
if ($edit['tid']) {
$form .= form_submit(t('Delete'));
$form .= form_hidden('tid', $edit['tid']);
$form['delete'] = array(type => 'submit', value => t('Delete'));
$form['tid'] = array(type => 'hidden', value => $edit['tid']);
}
return form($form);
return drupal_get_form('forum_form_container', $form);
}
/**
@ -197,20 +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['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 .= _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['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;
}
/**

View File

@ -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['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 .= _forum_parent_select($edit['tid'], t('Parent'), 'parent][', 'container');
$form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('When listing containers, those with with light (small) weights get listed before containers with heavier (larger) weights. Containers with equal weights are sorted alphabetically.'));
$form .= form_hidden('vid', _forum_get_vid());
$form .= form_submit(t('Submit'));
$form['vid'] = array(type => 'hidden', value => _forum_get_vid());
$form['submit'] = array(type => 'submit', value => t('Submit'));
if ($edit['tid']) {
$form .= form_submit(t('Delete'));
$form .= form_hidden('tid', $edit['tid']);
$form['delete'] = array(type => 'submit', value => t('Delete'));
$form['tid'] = array(type => 'hidden', value => $edit['tid']);
}
return form($form);
return drupal_get_form('forum_form_container', $form);
}
/**
@ -197,20 +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['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 .= _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['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;
}
/**

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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.')
);
return system_settings_form($output);
$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('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']);
}
$output .= form_group(t('Update options'), "<div class=\"container-inline\">$form</div>");
$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'));
}
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));
$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();
}
if (!$rows) {
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')));
$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($output);
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);
$node_form = $function($node, $param);
$form = array_merge($form, $function($node, $param));
}
// Append extra node form elements.
$form .= implode('', node_invoke_nodeapi($edit, 'form post'));
/**
* Node author information
*/
$output .= '<div class="node-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 hidden 'op' variable, which specifies the default operation (Preview).
$output .= '<input type="hidden" name="op" value="'. check_plain(t('Preview')) ."\" />\n";
$node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
// Add the admin-specific parts.
if (user_access('administer nodes')) {
$output .= '<div class="admin">';
/**
* 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));
$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>';
$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);
}
// Open the enclosing div.
$output .= '<div class="standard">';
// Add the node-type-specific fields.
$output .= $form;
// Add the hidden fields.
if ($edit->nid) {
$output .= form_hidden('nid', $edit->nid);
}
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);
}
if ($edit->created) {
$output .= form_hidden('created', $edit->created);
}
if ($edit->changed) {
$output .= form_hidden('changed', $edit->changed);
}
$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 ($edit->nid && node_access('delete', $edit)) {
$output .= form_submit(t('Delete'));
}
$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);
if ($node->type) {
if (!form_get_errors()) {
if ($_POST['op'] == t('Preview')|| !variable_get('node_preview', 0)) {
}
else {
$param[$key] = $value;
}
}
else {
$param[$key] = $value;
}
}
}
$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');
}
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') );
}
if ($edit['confirm']) {
return $output;
}
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);
}

View File

@ -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.')
);
return system_settings_form($output);
$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('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']);
}
$output .= form_group(t('Update options'), "<div class=\"container-inline\">$form</div>");
$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'));
}
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));
$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();
}
if (!$rows) {
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')));
$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($output);
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);
$node_form = $function($node, $param);
$form = array_merge($form, $function($node, $param));
}
// Append extra node form elements.
$form .= implode('', node_invoke_nodeapi($edit, 'form post'));
/**
* Node author information
*/
$output .= '<div class="node-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 hidden 'op' variable, which specifies the default operation (Preview).
$output .= '<input type="hidden" name="op" value="'. check_plain(t('Preview')) ."\" />\n";
$node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
// Add the admin-specific parts.
if (user_access('administer nodes')) {
$output .= '<div class="admin">';
/**
* 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));
$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>';
$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);
}
// Open the enclosing div.
$output .= '<div class="standard">';
// Add the node-type-specific fields.
$output .= $form;
// Add the hidden fields.
if ($edit->nid) {
$output .= form_hidden('nid', $edit->nid);
}
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);
}
if ($edit->created) {
$output .= form_hidden('created', $edit->created);
}
if ($edit->changed) {
$output .= form_hidden('changed', $edit->changed);
}
$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 ($edit->nid && node_access('delete', $edit)) {
$output .= form_submit(t('Delete'));
}
$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);
if ($node->type) {
if (!form_get_errors()) {
if ($_POST['op'] == t('Preview')|| !variable_get('node_preview', 0)) {
}
else {
$param[$key] = $value;
}
}
else {
$param[$key] = $value;
}
}
}
$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');
}
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') );
}
if ($edit['confirm']) {
return $output;
}
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);
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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'];

View File

@ -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'];

View File

@ -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.'));
$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.'));
$output .= form_group(t('Settings'), $group2);
$output .= '</div>';
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'];

View File

@ -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.'));
$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.'));
$output .= form_group(t('Settings'), $group2);
$output .= '</div>';
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'];

View File

@ -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']);
$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'));
$output = form_group(t('Field settings'), $group);
$output .= form_submit(t('Save field'));
return form($output);
return drupal_get_form('_profile_field_form', $form);
}
/**

View File

@ -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']);
$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'));
$output = form_group(t('Field settings'), $group);
$output .= form_submit(t('Save field'));
return form($output);
return drupal_get_form('_profile_field_form', $form);
}
/**

View File

@ -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;
}
/**
* Implementation of hook_validate().
*/
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_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() {
// 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);
$items = drupal_map_assoc(array(10, 20, 50, 100, 200, 500));
// 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);
$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;
}

View File

@ -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;
}
/**
* Implementation of hook_validate().
*/
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_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() {
// 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);
$items = drupal_map_assoc(array(10, 20, 50, 100, 200, 500));
// 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);
$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;
}

View File

@ -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']);

View File

@ -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']);

View File

@ -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));
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;
}

View File

@ -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));
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;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -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);
if ($edit['vid']) {
$form .= form_submit(t('Delete'));
$form .= form_hidden('vid', $edit['vid']);
$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);
}
return form($form);
$form['submit'] = array(type => 'submit', value => t('Submit'));
if ($edit['vid']) {
$form['delete'] = array(type => 'submit', value => t('Delete'));
$form['vid'] = array(type => 'hidden', value => $edit['vid']);
}
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();
}
}

View File

@ -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);
if ($edit['vid']) {
$form .= form_submit(t('Delete'));
$form .= form_hidden('vid', $edit['vid']);
$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);
}
return form($form);
$form['submit'] = array(type => 'submit', value => t('Submit'));
if ($edit['vid']) {
$form['delete'] = array(type => 'submit', value => t('Delete'));
$form['vid'] = array(type => 'hidden', value => $edit['vid']);
}
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();
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -54,12 +54,6 @@ function upload_menu($may_cache) {
$items = array();
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',
@ -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);

View File

@ -54,12 +54,6 @@ function upload_menu($may_cache) {
$items = array();
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',
@ -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);

View File

@ -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));
$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;
}
$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;
}
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;
}
return form($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();
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));
$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);
$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);
}
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 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');
}
if ($_POST) {
system_settings_save();
}
$output = system_settings_form(user_configure_settings());
$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 $output;
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;
}
/**

View File

@ -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));
$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;
}
$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;
}
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;
}
return form($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();
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));
$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);
$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);
}
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 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');
}
if ($_POST) {
system_settings_save();
}
$output = system_settings_form(user_configure_settings());
$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 $output;
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;
}
/**

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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>

View File

@ -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,

View File

@ -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>

View File

@ -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() {