| Versionen | |
|---|---|
| drupal6 – drupal7 | node_submit($node) |
Prepares a node for saving by populating teaser, author, and creation date.
object|array $node A node object or array.
A validated node object with a populated teaser, author, and creation date.
modules/
<?php
function node_submit($node) {
global $user;
// Convert the node to an object, if necessary.
$node = (object) $node;
// Generate the teaser, but only if it hasn't been set (e.g. by a
// module-provided 'teaser' form item).
if (!isset($node->teaser)) {
if (isset($node->body)) {
$node->teaser = node_teaser($node->body, isset($node->format) ? $node->format : NULL);
// Chop off the teaser from the body if needed. The teaser_include
// property might not be set (eg. in Blog API postings), so only act on
// it, if it was set with a given value.
if (isset($node->teaser_include) && !$node->teaser_include && $node->teaser == substr($node->body, 0, strlen($node->teaser))) {
$node->body = substr($node->body, strlen($node->teaser));
}
}
else {
$node->teaser = '';
$node->format = 0;
}
}
if (user_access('administer nodes')) {
// Populate the "authored by" field.
if ($account = user_load(array('name' => $node->name))) {
$node->uid = $account->uid;
}
else {
$node->uid = 0;
}
}
$node->created = !empty($node->date) ? strtotime($node->date) : time();
$node->validated = TRUE;
return $node;
}
?>
Kommentare
Kommentar hinzufügen