node_add
modules/node/node.module, строка 2250
- Версии
- 5
node_add($type = NULL)
- 6
node_add($type)
Present a node submission form or a set of links to such forms.
Код
<?php
function node_add($type = NULL) {
global $user;
$types = node_get_types();
$type = isset($type) ? str_replace('-', '_', $type) : NULL;
// If a node type has been specified, validate its existence.
if (isset($types[$type]) && node_access('create', $type)) {
// Initialize settings:
$node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type);
drupal_set_title(t('Submit @name', array('@name' => $types[$type]->name)));
$output = drupal_get_form($type .'_node_form', $node);
}
else {
// If no (valid) node type has been provided, display a node type overview.
foreach ($types as $type) {
if (function_exists($type->module .'_form') && node_access('create', $type->type)) {
$type_url_str = str_replace('_', '-', $type->type);
$title = t('Add a new @s.', array('@s' => $type->name));
$out = '<dt>'. l(drupal_ucfirst($type->name), "node/add/$type_url_str", array('title' => $title)) .'</dt>';
$out .= '<dd>'. filter_xss_admin($type->description) .'</dd>';
$item[$type->name] = $out;
}
}
if (isset($item)) {
uksort($item, 'strnatcasecmp');
$output = t('Choose the appropriate item from the list:') .'<dl>'. implode('', $item) .'</dl>';
}
else {
$output = t('No content types available.');
}
}
return $output;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии