diff options
author | Steven Wittens <steven@10.no-reply.drupal.org> | 2005-11-12 02:54:13 +0000 |
---|---|---|
committer | Steven Wittens <steven@10.no-reply.drupal.org> | 2005-11-12 02:54:13 +0000 |
commit | 85492ae9a548f0bfb58b673ac555f73d4b7977ed (patch) | |
tree | e980f521b5a0d66f7eac6020902de1628dba6633 /modules/node/node.module | |
parent | 76226df8672409b23856b8ade20d1d884d934af8 (diff) | |
download | brdo-85492ae9a548f0bfb58b673ac555f73d4b7977ed.tar.gz brdo-85492ae9a548f0bfb58b673ac555f73d4b7977ed.tar.bz2 |
#36791: node_validate was called twice
Diffstat (limited to 'modules/node/node.module')
-rw-r--r-- | modules/node/node.module | 82 |
1 files changed, 46 insertions, 36 deletions
diff --git a/modules/node/node.module b/modules/node/node.module index bc9881bd5..875124154 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -1476,52 +1476,30 @@ function node_feed($nodes = 0, $channel = array()) { } /** - * Perform validation checks on the given node. + * Prepare node for save and allow modules to make changes. */ -function node_validate($node) { +function node_execute($node) { global $user; // Convert the node to an object, if necessary. $node = array2object($node); - // Make sure the body has the minimum number of words. - // todo use a better word counting algorithm that will work in other languages - if (isset($node->body) && count(explode(' ', $node->body)) < variable_get('minimum_'. $node->type .'_size', 0)) { - form_set_error('body', t('The body of your %type is too short. You need at least %words words.', array('%words' => variable_get('minimum_'. $node->type .'_size', 0), '%type' => node_get_name($node)))); - } - // Auto-generate the teaser, but only if it hasn't been set (e.g. by a // module-provided 'teaser' form item). if (!isset($node->teaser)) { $node->teaser = isset($node->body) ? node_teaser($node->body, isset($node->format) ? $node->format : NULL) : ''; } - if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) { - form_set_error('changed', t('This content has been modified by another user, unable to save changes.')); - } - if (user_access('administer nodes')) { - // Validate the "authored by" field. - if (empty($node->name)) { - // The use of empty() is mandatory in the context of usernames - // as the empty string denotes the anonymous user. In case we - // are dealing with an anonymous user we set the user ID to 0. - $node->uid = 0; - } - else if ($account = user_load(array('name' => $node->name))) { + // Populate the "authored by" field. + if ($account = user_load(array('name' => $node->name))) { $node->uid = $account->uid; } else { - form_set_error('name', t('The username %name does not exist.', array ('%name' => theme('placeholder', $node->name)))); + $node->uid = 0; } - // Validate the "authored on" field. - if (strtotime($node->date) != -1) { - $node->created = strtotime($node->date); - } - else { - form_set_error('date', t('You have to specify a valid date.')); - } + $node->created = strtotime($node->date); } else { // Validate for normal users: @@ -1537,14 +1515,51 @@ function node_validate($node) { } // Do node-type-specific validation checks. - node_invoke($node, 'validate'); - node_invoke_nodeapi($node, 'validate'); + node_invoke($node, 'execute'); + node_invoke_nodeapi($node, 'execute'); $node->validated = TRUE; return $node; } +/** + * Perform validation checks on the given node. + */ +function node_validate($node) { + // Convert the node to an object, if necessary. + $node = array2object($node); + + // Make sure the body has the minimum number of words. + // todo use a better word counting algorithm that will work in other languages + if (isset($node->body) && count(explode(' ', $node->body)) < variable_get('minimum_'. $node->type .'_size', 0)) { + form_set_error('body', t('The body of your %type is too short. You need at least %words words.', array('%words' => variable_get('minimum_'. $node->type .'_size', 0), '%type' => node_get_name($node)))); + } + + if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) { + form_set_error('changed', t('This content has been modified by another user, unable to save changes.')); + } + + if (user_access('administer nodes')) { + // Validate the "authored by" field. + if (!empty($node->name) && !($account = user_load(array('name' => $node->name)))) { + // The use of empty() is mandatory in the context of usernames + // as the empty string denotes the anonymous user. In case we + // are dealing with an anonymous user we set the user ID to 0. + form_set_error('name', t('The username %name does not exist.', array ('%name' => theme('placeholder', $node->name)))); + } + + // Validate the "authored on" field. + if (strtotime($node->date) == -1) { + form_set_error('date', t('You have to specify a valid date.')); + } + } + + // Do node-type-specific validation checks. + node_invoke($node, 'validate'); + node_invoke_nodeapi($node, 'validate'); +} + /** * Validate the title of a node @@ -1796,12 +1811,7 @@ function node_form_execute($form_id, $edit) { global $user; // Fix up the node when required: - $node = node_validate($edit); - - // If something went wrong, go back to the preview form. - if (form_get_errors()) { - return node_form($edit); - } + $node = node_execute($edit); // Prepare the node's body: if ($node->nid) { |