summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/blog/blog.module15
-rw-r--r--modules/book/book.module19
-rw-r--r--modules/comment/comment.module14
-rw-r--r--modules/forum/forum.module16
-rw-r--r--modules/node/node.module425
-rw-r--r--modules/poll/poll.module15
-rw-r--r--modules/system/system.install117
-rw-r--r--modules/system/system.module3
-rw-r--r--modules/taxonomy/taxonomy.module2
-rw-r--r--modules/tracker/tracker.module2
-rw-r--r--modules/upload/upload.module16
-rw-r--r--profiles/default.profile2
12 files changed, 496 insertions, 150 deletions
diff --git a/modules/blog/blog.module b/modules/blog/blog.module
index 2c5f37eae..1b277be3d 100644
--- a/modules/blog/blog.module
+++ b/modules/blog/blog.module
@@ -10,7 +10,13 @@
* Implementation of hook_node_info().
*/
function blog_node_info() {
- return array('blog' => array('name' => t('blog entry'), 'base' => 'blog'));
+ return array(
+ 'blog' => array(
+ 'name' => t('blog entry'),
+ 'module' => 'blog',
+ 'description' => t('A blog is a regularly updated journal or diary made up of individual posts shown in reversed chronological order. Each member of the site may create and maintain a blog.'),
+ )
+ );
}
/**
@@ -72,8 +78,6 @@ function blog_help($section) {
return $output;
case 'admin/settings/modules#description':
return t('Enables keeping an easily and regularly updated web page or a blog.');
- case 'node/add#blog':
- return t("A blog is a regularly updated journal or diary made up of individual posts shown in reversed chronological order. Each member of the site may create and maintain a blog.");
}
}
@@ -201,6 +205,7 @@ function blog_page_last() {
function blog_form(&$node) {
global $nid;
$iid = $_GET['iid'];
+ $type = node_get_types('type', $node);
if (empty($node->body)) {
@@ -221,8 +226,8 @@ function blog_form(&$node) {
}
- $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5);
- $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE);
+ $form['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5);
+ $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => check_plain($type->body_label), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE);
$form['body_filter']['filter'] = filter_form($node->format);
return $form;
}
diff --git a/modules/book/book.module b/modules/book/book.module
index 979dbf613..caf0291ba 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -10,7 +10,13 @@
* Implementation of hook_node_info().
*/
function book_node_info() {
- return array('book' => array('name' => t('book page'), 'base' => 'book'));
+ return array(
+ 'book' => array(
+ 'name' => t('book page'),
+ 'module' => 'book',
+ 'description' => t("A book is a collaborative writing effort: users can collaborate writing the pages of the book, positioning the pages in the right order, and reviewing or modifying pages previously written. So when you have some information to share or when you read a page of the book and you didn't like it, or if you think a certain page could have been written better, you can do something about it."),
+ )
+ );
}
/**
@@ -84,10 +90,6 @@ function book_menu($may_cache) {
if ($may_cache) {
$items[] = array(
- 'path' => 'node/add/book',
- 'title' => t('book page'),
- 'access' => user_access('create book pages'));
- $items[] = array(
'path' => 'admin/content/book',
'title' => t('books'),
'description' => t('Manage site\'s books and orphaned book pages.'),
@@ -224,6 +226,7 @@ function book_submit(&$node) {
* Implementation of hook_form().
*/
function book_form(&$node) {
+ $type = node_get_types('type', $node);
if ($node->nid && !$node->parent && !user_access('create new books')) {
$form['parent'] = array('#type' => 'value', '#value' => $node->parent);
}
@@ -238,13 +241,13 @@ function book_form(&$node) {
}
$form['title'] = array('#type' => 'textfield',
- '#title' => t('Title'),
+ '#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -5,
);
$form['body_filter']['body'] = array('#type' => 'textarea',
- '#title' => t('Body'),
+ '#title' => check_plain($type->body_label),
'#default_value' => $node->body,
'#rows' => 20,
'#required' => TRUE,
@@ -1014,8 +1017,6 @@ function book_help($section) {
return t('<p>The book module offers a means to organize content, authored by many users, in an online manual, outline or FAQ.</p>');
case 'admin/content/book/orphan':
return t('<p>Pages in a book are like a tree. As pages are edited, reorganized and removed, child pages might be left with no link to the rest of the book. Such pages are referred to as "orphan pages". On this page, administrators can review their books for orphans and reattach those pages as desired.</p>');
- case 'node/add#book':
- return t("A book is a collaborative writing effort: users can collaborate writing the pages of the book, positioning the pages in the right order, and reviewing or modifying pages previously written. So when you have some information to share or when you read a page of the book and you didn't like it, or if you think a certain page could have been written better, you can do something about it.");
}
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'outline') {
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index fed6e19d3..f135e27cb 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -265,10 +265,16 @@ function comment_link($type, $node = NULL, $teaser = FALSE) {
}
function comment_form_alter($form_id, &$form) {
- if (isset($form['type'])) {
- if ($form['type']['#value'] .'_node_settings' == $form_id) {
- $form['workflow']['comment_'. $form['type']['#value']] = array('#type' => 'radios', '#title' => t('Default comment setting'), '#default_value' => variable_get('comment_'. $form['type']['#value'], COMMENT_NODE_READ_WRITE), '#options' => array(t('Disabled'), t('Read only'), t('Read/Write')), '#description' => t('Users with the <em>administer comments</em> permission will be able to override this setting.'));
- }
+ if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
+ $form['workflow']['comment'] = array(
+ '#type' => 'radios',
+ '#title' => t('Default comment setting'),
+ '#default_value' => variable_get('comment_'. $form['identity']['type']['#default_value'], COMMENT_NODE_READ_WRITE),
+ '#options' => array(t('Disabled'), t('Read only'), t('Read/Write')),
+ '#description' => t('Users with the <em>administer comments</em> permission will be able to override this setting.'),
+ );
+ }
+ elseif (isset($form['type'])) {
if ($form['type']['#value'] .'_node_form' == $form_id) {
$node = $form['#node'];
if (user_access('administer comments')) {
diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index d6c2f0e8e..ec1caa25d 100644
--- a/modules/forum/forum.module
+++ b/modules/forum/forum.module
@@ -33,8 +33,6 @@ function forum_help($section) {
return t('<p>Containers help you organize your forums. The job of a container is to hold, or contain, other forums that are related. For example, a container named "Food" might hold two forums named "Fruit" and "Vegetables".</p>');
case 'admin/content/forum/add/forum':
return t('<p>A forum holds discussion topics that are related. For example, a forum named "Fruit" might contain topics titled "Apples" and "Bananas".</p>');
- case 'node/add#forum':
- return t('Create a new topic for discussion in the forums.');
}
}
@@ -107,7 +105,14 @@ function forum_menu($may_cache) {
* Implementation of hook_node_info().
*/
function forum_node_info() {
- return array('forum' => array('name' => t('forum topic'), 'base' => 'forum'));
+ return array(
+ 'forum' => array(
+ 'name' => t('forum topic'),
+ 'module' => 'forum',
+ 'description' => t('Create a new topic for discussion in the forums.'),
+ 'title_label' => t('Subject'),
+ )
+ );
}
/**
@@ -383,7 +388,8 @@ function forum_update($node) {
* Implementation of hook_form().
*/
function forum_form(&$node) {
- $form['title'] = array('#type' => 'textfield', '#title' => t('Subject'), '#default_value' => $node->title, '#required' => TRUE, '#weight' => -5);
+ $type = node_get_types('type', $node);
+ $form['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#default_value' => $node->title, '#required' => TRUE, '#weight' => -5);
if ($node->nid) {
$forum_terms = taxonomy_node_get_terms_by_vocabulary(_forum_get_vid(), $node->nid);
@@ -392,7 +398,7 @@ function forum_form(&$node) {
$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.'));
}
- $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE);
+ $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => check_plain($type->body_label), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE);
$form['body_filter']['format'] = filter_form($node->format);
return $form;
diff --git a/modules/node/node.module b/modules/node/node.module
index b99ae3ad3..88d17d087 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -36,6 +36,10 @@ function node_help($section) {
return t('Allows content to be submitted to the site and displayed on pages.');
case 'admin/content/search':
return t('<p>Enter a simple pattern to search for a post. This can include the wildcard character *.<br />For example, a search for "br*" might return "bread bakers", "our daily bread" and "brenda".</p>');
+ case 'admin/content/types':
+ return '<p>'. t('Below is a list of all the content types on your site. All posts that exist on your site are instances of one of these content types.') .'</p>';
+ case 'admin/content/types/add':
+ return '<p>'. t('To create a new content type, enter the human-readable name, the machine-readable name, and all other relevant fields that are on this page. Once created, users of your site will be able to create posts that are instances of this content type.');
}
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'revisions') {
@@ -43,7 +47,8 @@ function node_help($section) {
}
if (arg(0) == 'node' && arg(1) == 'add' && $type = arg(2)) {
- return filter_xss_admin(variable_get($type .'_help', ''));
+ $type = node_get_types('type', arg(2));
+ return filter_xss_admin($type->help);
}
}
@@ -190,16 +195,32 @@ function node_teaser($body, $format = NULL) {
return truncate_utf8($body, $size);
}
-function _node_names($op = '', $node = NULL) {
- static $node_names = array();
- static $node_list = array();
+/**
+ * Builds a list of available node types, and returns all of part of this list
+ * in the specified format.
+ *
+ * @param $op
+ * The format in which to return the list. When this is set to 'type',
+ * 'module', or 'name', only the specified node type is returned. When set to
+ * 'types' or 'names', all node types are returned.
+ * @param $node
+ * A node object, array, or string that indicates the node type to return.
+ * Leave at default value (NULL) to return a list of all node types.
+ * @param $reset
+ * Whether or not to reset this function's internal cache (defaults to
+ * FALSE).
+ *
+ * @return
+ * Either an array of all available node types, or a single node type, in a
+ * variable format.
+ */
+function node_get_types($op = 'types', $node = NULL, $reset = FALSE) {
+ static $_node_types, $_node_names;
- if (empty($node_names)) {
- $node_names = module_invoke_all('node_info');
- foreach ($node_names as $type => $value) {
- $node_list[$type] = $value['name'];
- }
+ if ($reset || !isset($_node_types)) {
+ list($_node_types, $_node_names) = _node_types_build();
}
+
if ($node) {
if (is_array($node)) {
$type = $node['type'];
@@ -210,54 +231,148 @@ function _node_names($op = '', $node = NULL) {
elseif (is_string($node)) {
$type = $node;
}
- if (!isset($node_names[$type])) {
+ if (!isset($_node_types[$type])) {
return FALSE;
}
}
switch ($op) {
- case 'base':
- return $node_names[$type]['base'];
- case 'list':
- return $node_list;
+ case 'types':
+ return $_node_types;
+ case 'type':
+ return $_node_types[$type];
+ case 'module':
+ return $_node_types[$type]->module;
+ case 'names':
+ return $_node_names;
case 'name':
- return $node_list[$type];
+ return $_node_names[$type];
+ }
+}
+
+/**
+ * Resets the database cache of node types, and saves all new or non-modified
+ * module-defined node types to the database.
+ */
+function node_types_rebuild() {
+ _node_types_build();
+
+ $node_types = node_get_types('types', NULL, TRUE);
+
+ foreach ($node_types as $type => $info) {
+ if (!empty($info->is_new)) {
+ node_type_save($info);
+ }
}
+
+ _node_types_build();
}
/**
- * Determine the basename for hook_load etc.
+ * Saves a node type to the database.
+ *
+ * @param $info
+ * The node type to save, as an object.
*
- * @param $node
- * Either a node object, a node array, or a string containing the node type.
* @return
- * The basename for hook_load, hook_nodeapi etc.
+ * Status flag indicating outcome of the operation.
*/
-function node_get_base($node) {
- return _node_names('base', $node);
+function node_type_save($info) {
+ $is_existing = FALSE;
+ $existing_type = !empty($info->old_type) ? $info->old_type : $info->type;
+ $is_existing = db_num_rows(db_query("SELECT * FROM {node_type} WHERE type = '%s'", $existing_type));
+
+ if ($is_existing) {
+ db_query("UPDATE {node_type} SET type = '%s', name = '%s', module = '%s', has_title = %d, title_label = '%s', has_body = %d, body_label = '%s', description = '%s', help = '%s', min_word_count = %d, custom = %d, modified = %d, locked = %d WHERE type = '%s'", $info->type, $info->name, $info->module, $info->has_title, $info->title_label, $info->has_body, $info->body_label, $info->description, $info->help, $info->min_word_count, $info->custom, $info->modified, $info->locked, $existing_type);
+ return SAVED_UPDATED;
+ }
+ else {
+ db_query("INSERT INTO {node_type} (type, name, module, has_title, title_label, has_body, body_label, description, help, min_word_count, custom, modified, locked, orig_type) VALUES ('%s', '%s', '%s', %d, '%s', %d, '%s', '%s', '%s', %d, %d, %d, %d, '%s')", $info->type, $info->name, $info->module, $info->has_title, $info->title_label, $info->has_body, $info->body_label, $info->description, $info->help, $info->min_word_count, $info->custom, $info->modified, $info->locked, $info->orig_type);
+ return SAVED_NEW;
+ }
}
/**
- * Determine the human readable name for a given type.
+ * Updates all nodes of one type to be of another type.
+ *
+ * @param $orig_type
+ * The current node type of the nodes.
+ * @param $type
+ * The new node type of the nodes.
*
- * @param $node
- * Either a node object, a node array, or a string containing the node type.
* @return
- * The human readable name of the node type.
+ * The number of nodes whose node type field was modified.
*/
-function node_get_name($node) {
- return _node_names('name', $node);
+function node_type_update_nodes($old_type, $type) {
+ db_query("UPDATE {node} SET type = '%s' WHERE type = '%s'", $type, $old_type);
+ return db_affected_rows();
}
/**
- * Return the list of available node types.
+ * Builds the list of available node types, by querying hook_node_info() in all
+ * modules, and by looking for node types in the database.
*
- * @param $node
- * Either a node object, a node array, or a string containing the node type.
- * @return
- * An array consisting ('#type' => name) pairs.
*/
-function node_get_types() {
- return _node_names('list');
+function _node_types_build() {
+ $_node_types = array();
+ $_node_names = array();
+
+ $info_array = module_invoke_all('node_info');
+ foreach ($info_array as $type => $info) {
+ $info['type'] = $type;
+ $_node_types[$type] = (object) _node_type_set_defaults($info);
+ $_node_names[$type] = $info['name'];
+ }
+
+ $type_result = db_query(db_rewrite_sql('SELECT nt.type, nt.* FROM {node_type} nt ORDER BY nt.type ASC', 'nt', 'type'));
+ while ($type_object = db_fetch_object($type_result)) {
+ if (!isset($_node_types[$type_object->type]) || $type_object->modified) {
+ $_node_types[$type_object->type] = $type_object;
+ $_node_names[$type_object->type] = $type_object->name;
+
+ if ($type_object->type != $type_object->orig_type) {
+ unset($_node_types[$type_object->orig_type]);
+ unset($_node_names[$type_object->orig_type]);
+ }
+ }
+ }
+
+ asort($_node_names);
+
+ return array($_node_types, $_node_names);
+}
+
+/**
+ * Set default values for a node type defined through hook_node_info().
+ */
+function _node_type_set_defaults($info) {
+ if (!isset($info['has_title'])) {
+ $info['has_title'] = TRUE;
+ }
+ if ($info['has_title'] && !isset($info['title_label'])) {
+ $info['title_label'] = t('Title');
+ }
+
+ if (!isset($info['has_body'])) {
+ $info['has_body'] = TRUE;
+ }
+ if ($info['has_body'] && !isset($info['body_label'])) {
+ $info['body_label'] = t('Body');
+ }
+
+ if (!isset($info['custom'])) {
+ $info['custom'] = FALSE;
+ }
+ if (!isset($info['modified'])) {
+ $info['modified'] = FALSE;
+ }
+ if (!isset($info['locked'])) {
+ $info['locked'] = TRUE;
+ }
+
+ $info['orig_type'] = $info['type'];
+ $info['is_new'] = TRUE;
+
+ return $info;
}
/**
@@ -271,7 +386,11 @@ function node_get_types() {
* TRUE iff the $hook exists in the node type of $node.
*/
function node_hook(&$node, $hook) {
- return module_hook(node_get_base($node), $hook);
+ $module = node_get_types('module', $node);
+ if ($module == 'node') {
+ $module = 'node_content'; // Avoid function name collisions.
+ }
+ return module_hook($module, $hook);
}
/**
@@ -288,7 +407,11 @@ function node_hook(&$node, $hook) {
*/
function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
if (node_hook($node, $hook)) {
- $function = node_get_base($node) ."_$hook";
+ $module = node_get_types('module', $node);
+ if ($module == 'node') {
+ $module = 'node_content'; // Avoid function name collisions.
+ }
+ $function = $module .'_'. $hook;
return ($function($node, $a2, $a3, $a4));
}
}
@@ -584,7 +707,18 @@ function node_show($node, $cid) {
* Implementation of hook_perm().
*/
function node_perm() {
- return array('administer nodes', 'access content', 'view revisions', 'revert revisions');
+ $perms = array('administer content types', 'administer nodes', 'access content', 'view revisions', 'revert revisions');
+
+ foreach (node_get_types() as $type) {
+ if ($type->module == 'node') {
+ $name = check_plain($type->name);
+ $perms[] = 'create '. $name .' content';
+ $perms[] = 'edit own '. $name .' content';
+ $perms[] = 'edit '. $name .' content';
+ }
+ }
+
+ return $perms;
}
/**
@@ -723,7 +857,7 @@ function node_search($op = 'search', $keys = NULL) {
$extra = node_invoke_nodeapi($node, 'search result');
$results[] = array('link' => url('node/'. $item->sid),
- 'type' => node_get_name($node),
+ 'type' => node_get_types('name', $node),
'title' => $node->title,
'user' => theme('username', $node),
'date' => $node->changed,
@@ -864,12 +998,25 @@ function node_menu($may_cache) {
'callback' => 'node_configure',
'access' => user_access('administer nodes')
);
+
$items[] = array(
'path' => 'admin/content/types',
'title' => t('content types'),
'description' => t('Manage posts by content type, including default status, front page promotion, etc.'),
- 'callback' => 'node_types_configure',
- 'access' => user_access('administer nodes')
+ 'callback' => 'node_overview_types',
+ 'access' => user_access('administer nodes'),
+ );
+ $items[] = array(
+ 'path' => 'admin/content/types/list',
+ 'title' => t('list'),
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'weight' => -10,
+ );
+ $items[] = array(
+ 'path' => 'admin/content/types/add',
+ 'title' => t('add content type'),
+ 'callback' => 'node_type_form',
+ 'type' => MENU_LOCAL_TASK,
);
$items[] = array('path' => 'node', 'title' => t('content'),
@@ -885,6 +1032,18 @@ function node_menu($may_cache) {
'callback' => 'node_feed',
'access' => user_access('access content'),
'type' => MENU_CALLBACK);
+
+ foreach (node_get_types() as $type) {
+ if (module_exist($type->module)) {
+ $name = check_plain($type->name);
+ $type_url_str = str_replace('_', '-', $type->type);
+ $items[] = array(
+ 'path' => 'node/add/'. $type_url_str,
+ 'title' => t($name),
+ 'access' => node_access('create', $type->type),
+ );
+ }
+ }
}
else {
if (arg(0) == 'node' && is_numeric(arg(1))) {
@@ -914,10 +1073,36 @@ function node_menu($may_cache) {
'type' => MENU_LOCAL_TASK);
}
}
- else if (arg(0) == 'admin' && arg(1) == 'content' && arg(2) == 'types' && is_string(arg(3))) {
- $items[] = array('path' => 'admin/content/types/'. arg(3),
- 'title' => t("'%name' content type", array('%name' => node_get_name(arg(3)))),
- 'type' => MENU_CALLBACK);
+
+ // Content type configuration.
+ if (arg(0) == 'admin' && arg(1) == 'content' && arg(2) == 'types') {
+ include_once './'. drupal_get_path('module', 'node') .'/content_types.inc';
+
+ if (arg(3) != NULL) {
+ $type_name = arg(3);
+ $type_name = !empty($type_name) ? str_replace('-', '_', $type_name) : NULL;
+ $type = node_get_types('type', $type_name);
+
+ if (!empty($type)) {
+ $type->name = check_plain($type->name);
+ $type_url_str = str_replace('_', '-', $type->type);
+
+ $items[] = array(
+ 'path' => 'admin/content/types/'. $type_url_str,
+ 'title' => t($type->name),
+ 'callback' => 'node_type_form',
+ 'callback arguments' => array($type),
+ 'type' => MENU_CALLBACK,
+ );
+ $items[] = array(
+ 'path' => 'admin/content/types/'. $type_url_str .'/delete',
+ 'title' => t('delete'),
+ 'callback' => 'node_type_delete',
+ 'callback arguments' => array($type),
+ 'type' => MENU_CALLBACK,
+ );
+ }
+ }
}
// There is no need to rebuild node_access if there is only 1 record in the table (the default configuration).
@@ -995,7 +1180,7 @@ function node_filters() {
'options' => array('status-1' => t('published'), 'status-0' => t('not published'),
'promote-1' => t('promoted'), 'promote-0' => t('not promoted'),
'sticky-1' => t('sticky'), 'sticky-0' => t('not sticky')));
- $filters['type'] = array('title' => t('type'), 'options' => node_get_types());
+ $filters['type'] = array('title' => t('type'), 'options' => node_get_types('names'));
// The taxonomy filter
if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {
$filters['category'] = array('title' => t('category'), 'options' => $taxonomy);
@@ -1208,7 +1393,7 @@ function node_admin_nodes() {
while ($node = db_fetch_object($result)) {
$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['name'][$node->nid] = array('#value' => node_get_types('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));
@@ -1285,40 +1470,6 @@ function node_multiple_delete_confirm_submit($form_id, $edit) {
}
/**
- * Menu callback; presents each node type configuration page.
- */
-function node_types_configure($type = NULL) {
- if (isset($type)) {
- $node = new stdClass();
- $node->type = $type;
- $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', ''),
- '#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['type'] = array('#type' => 'value', '#value' => $type);
-
- $form['array_filter'] = array('#type' => 'value', '#value' => TRUE);
- return system_settings_form($type .'_node_settings', $form);
- }
- else {
- $header = array(t('Type'), t('Operations'));
-
- $rows = array();
- foreach (node_get_types() as $type => $name) {
- $rows[] = array($name, l(t('configure'), 'admin/content/types/'. $type));
- }
-
- return theme('table', $header, $rows);
- }
-}
-
-/**
* Generate an overview table of older revisions of a node.
*/
function node_revision_overview($node) {
@@ -1593,11 +1744,12 @@ function node_submit($node) {
function node_validate($node, $form = array()) {
// Convert the node to an object, if necessary.
$node = (object)$node;
+ $type = node_get_types('type', $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->body) && count(explode(' ', $node->body)) < $type->min_word_count) {
+ form_set_error('body', t('The body of your %type is too short. You need at least %words words.', array('%words' => $type->min_word_count, '%type' => $type->name)));
}
if (isset($node->nid) && (node_last_changed($node->nid) > $_POST['edit']['changed'])) {
@@ -1653,8 +1805,8 @@ function node_form($node) {
}
/**
-* Generate the node editing form array.
-*/
+ * Generate the node editing form array.
+ */
function node_form_array($node) {
node_object_prepare($node);
@@ -1793,21 +1945,25 @@ function theme_node_form($form) {
function node_add($type) {
global $user;
+ $types = node_get_types();
+ $type = isset($type) ? str_replace('-', '_', $type) : NULL;
// If a node type has been specified, validate its existence.
- if (array_key_exists($type, node_get_types()) && node_access('create', $type)) {
+ if (isset($types[$type]) && node_access('create', $type)) {
// Initialize settings:
$node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type);
$output = node_form($node);
- drupal_set_title(t('Submit %name', array('%name' => node_get_name($node))));
+ drupal_set_title(t('Submit %name', array('%name' => check_plain($types[$type]->name))));
}
else {
// If no (valid) node type has been provided, display a node type overview.
- foreach (node_get_types() as $type => $name) {
- if (node_access('create', $type)) {
- $out = '<dt>'. l($name, "node/add/$type", array('title' => t('Add a new %s.', array('%s' => $name)))) .'</dt>';
- $out .= '<dd>'. implode("\n", module_invoke_all('help', 'node/add#'. $type)) .'</dd>';
- $item[$name] = $out;
+ foreach ($types as $type) {
+ if (module_exist($type->module) && node_access('create', $type->type)) {
+ $type_url_str = str_replace('_', '-', $type->type);
+ $title = t('Add a new %s.', array('%s' => check_plain($type->name)));
+ $out = '<dt>'. l($type->name, "node/add/$type_url_str", array('title' => $title)) .'</dt>';
+ $out .= '<dd>'. filter_xss_admin($type->description) .'</dd>';
+ $item[$type->type] = $out;
}
}
@@ -1816,7 +1972,7 @@ function node_add($type) {
$output = t('Choose the appropriate item from the list:') .'<dl>'. implode('', $item) .'</dl>';
}
else {
- $output = t('You are not allowed to create content.');
+ $output = t('No content types available.');
}
}
@@ -1864,7 +2020,7 @@ function node_preview($node) {
$output = theme('node_preview', $cloned_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)));
+ drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('create content'), 'node/add'), l(t('Submit %name', array('%name' => node_get_types('name', $node))), 'node/add/'. $node->type)));
return $output;
}
@@ -1906,7 +2062,7 @@ function node_form_submit($form_id, $edit) {
if (node_access('update', $node)) {
node_save($node);
watchdog('content', t('%type: updated %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
- drupal_set_message(t('The %post was updated.', array ('%post' => node_get_name($node))));
+ drupal_set_message(t('The %post was updated.', array ('%post' => node_get_types('name', $node))));
}
}
else {
@@ -1915,7 +2071,7 @@ function node_form_submit($form_id, $edit) {
if (node_access('create', $node)) {
node_save($node);
watchdog('content', t('%type: added %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid"));
- drupal_set_message(t('Your %post was created.', array ('%post' => node_get_name($node))));
+ drupal_set_message(t('Your %post was created.', array ('%post' => node_get_types('name', $node))));
}
}
if ($node->nid) {
@@ -2199,23 +2355,8 @@ function node_update_index() {
* Implementation of hook_form_alter().
*/
function node_form_alter($form_id, &$form) {
- // Node publishing options
- if (isset($form['type']) && $form['type']['#value'] .'_node_settings' == $form_id) {
- $form['workflow']['node_options_'. $form['type']['#value']] = array('#type' => 'checkboxes',
- '#title' => t('Default options'),
- '#default_value' => variable_get('node_options_'. $form['type']['#value'], array('status', 'promote')),
- '#options' => array(
- 'status' => t('Published'),
- '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.'),
- );
- }
-
// Advanced node search form
- elseif ($form_id == 'search_form' && arg(1) == 'node' && user_access('use advanced search')) {
+ if ($form_id == 'search_form' && arg(1) == 'node' && user_access('use advanced search')) {
// Keyword boxes:
$form['advanced'] = array(
'#type' => 'fieldset',
@@ -2388,7 +2529,11 @@ function node_access($op, $node = NULL, $uid = NULL) {
// Can't use node_invoke(), because the access hook takes the $op parameter
// before the $node parameter.
- $access = module_invoke(node_get_base($node), 'access', $op, $node);
+ $module = node_get_types('module', $node);
+ if ($module == 'node') {
+ $module = 'node_content'; // Avoid function name collisions.
+ }
+ $access = module_invoke($module, 'access', $op, $node);
if (!is_null($access)) {
return $access;
}
@@ -2669,3 +2814,59 @@ function node_access_rebuild() {
*/
+/**
+ * @defgroup node_content Hook implementations for user-created content types.
+ * @{
+ */
+
+/**
+ * Implementation of hook_access().
+ */
+function node_content_access($op, $node) {
+ global $user;
+ $type = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type);
+
+ if ($op == 'create') {
+ return user_access('create '. $type .' content');
+ }
+
+ if ($op == 'update' || $op == 'delete') {
+ if (user_access('edit '. $type .' content') || (user_access('edit own '. $type .' content') && ($user->uid == $node->uid))) {
+ return TRUE;
+ }
+ }
+}
+
+/**
+ * Implementation of hook_form().
+ */
+function node_content_form($node) {
+ $type = node_get_types('type', $node);
+
+ if ($type->has_title) {
+ $form['title'] = array(
+ '#type' => 'textfield',
+ '#title' => check_plain($type->title_label),
+ '#required' => TRUE,
+ '#default_value' => $node->title,
+ '#weight' => -5,
+ );
+ }
+
+ if ($type->has_body) {
+ $form['body_filter']['body'] = array(
+ '#type' => 'textarea',
+ '#title' => check_plain($type->body_label),
+ '#default_value' => $node->body,
+ '#rows' => 20,
+ '#required' => TRUE);
+ $form['body_filter']['format'] = filter_form($node->format);
+ }
+
+ return $form;
+}
+
+/**
+ * @} End of "defgroup node_content".
+ */
+
diff --git a/modules/poll/poll.module b/modules/poll/poll.module
index 6ee82c457..be57aa443 100644
--- a/modules/poll/poll.module
+++ b/modules/poll/poll.module
@@ -25,8 +25,6 @@ function poll_help($section) {
return $output;
case 'admin/settings/modules#description':
return t("Allows your site to capture votes on different topics in the form of multiple choice questions.");
- case 'node/add#poll':
- return t("A poll is a multiple-choice question which visitors can vote on.");
}
}
@@ -128,8 +126,9 @@ function poll_validate($node) {
*/
function poll_form(&$node) {
$admin = user_access('administer nodes');
+ $type = node_get_types('type', $node);
- $form['title'] = array('#type' => 'textfield', '#title' => t('Question'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -1);
+ $form['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -1);
$form['choice']['choices'] = array('#type' => 'hidden', '#default_value' => max(2, count($node->choice) ? count($node->choice) : 5));
$form['choice']['morechoices'] = array('#type' => 'checkbox', '#title' => t('Need more choices'), '#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."), '#weight' => 1);
@@ -271,7 +270,15 @@ function poll_load($node) {
* Implementation of hook_node_info().
*/
function poll_node_info() {
- return array('poll' => array('name' => t("poll"), 'base' => 'poll'));
+ return array(
+ 'poll' => array(
+ 'name' => t("poll"),
+ 'module' => 'poll',
+ 'description' => t("A poll is a multiple-choice question which visitors can vote on."),
+ 'title_label' => t('Question'),
+ 'has_body' => FALSE,
+ )
+ );
}
function poll_page() {
diff --git a/modules/system/system.install b/modules/system/system.install
index 7ff587f53..c5b165833 100644
--- a/modules/system/system.install
+++ b/modules/system/system.install
@@ -198,6 +198,24 @@ function system_install() {
KEY uid (uid)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+ db_query("CREATE TABLE {node_type} (
+ type varchar(32) NOT NULL,
+ name varchar(255) NOT NULL default '',
+ module varchar(255) NOT NULL,
+ description mediumtext NOT NULL,
+ help mediumtext NOT NULL,
+ has_title tinyint(3) unsigned NOT NULL,
+ title_label varchar(255) NOT NULL default '',
+ has_body tinyint(3) unsigned NOT NULL,
+ body_label varchar(255) NOT NULL default '',
+ min_word_count smallint(4) unsigned NOT NULL,
+ custom tinyint(1) NOT NULL DEFAULT '0',
+ modified tinyint(1) NOT NULL DEFAULT '0',
+ locked tinyint(1) NOT NULL DEFAULT '0',
+ orig_type varchar(255) NOT NULL default '',
+ PRIMARY KEY (type)
+ ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+
db_query("CREATE TABLE {url_alias} (
pid int(10) unsigned NOT NULL auto_increment,
src varchar(128) NOT NULL default '',
@@ -789,6 +807,9 @@ function system_install() {
db_query("INSERT INTO {node_access} VALUES (0, 0, 'all', 1, 0, 0)");
+ db_query("INSERT INTO {node_type} (type, name, module, description, help, has_title, title_label, has_body, body_label, min_word_count, custom, modified, locked, orig_type) VALUES ('page', 'page', 'node', 'If you want to add a static page, like a contact page or an about page, use a page.', '', 1, 'Title', 1, 'Body', 0, 1, 1, 0, 'page')");
+ db_query("INSERT INTO {node_type} (type, name, module, description, help, has_title, title_label, has_body, body_label, min_word_count, custom, modified, locked, orig_type) VALUES ('story', 'story', 'node', 'Stories are articles in their simplest form: they have a title, a teaser and a body, but can be extended by other modules. The teaser is part of the body too. Stories may be used as a personal blog or for news articles.', '', 1, 'Title', 1, 'Body', 0, 1, 1, 0, 'story')");
+
db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('Filtered HTML',',1,2,',1)");
db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('PHP code','',0)");
db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('Full HTML','',1)");
@@ -2908,3 +2929,99 @@ function system_update_187() {
}
return $ret;
}
+
+function system_update_188() {
+ // Add ability to create dynamic node types like the CCK module
+ $ret = array();
+
+ switch ($GLOBALS['db_type']) {
+ case 'mysqli':
+ case 'mysql':
+ // Create node_type table
+ $ret[] = update_sql("CREATE TABLE {node_type} (
+ type varchar(32) NOT NULL,
+ name varchar(255) NOT NULL,
+ module varchar(255) NOT NULL,
+ description mediumtext NOT NULL,
+ help mediumtext NOT NULL,
+ has_title tinyint(3) unsigned NOT NULL,
+ title_label varchar(255) NOT NULL default '',
+ has_body tinyint(3) unsigned NOT NULL,
+ body_label varchar(255) NOT NULL default '',
+ min_word_count smallint(4) unsigned NOT NULL,
+ custom tinyint(1) NOT NULL DEFAULT '0',
+ modified tinyint(1) NOT NULL DEFAULT '0',
+ locked tinyint(1) NOT NULL DEFAULT '0',
+ orig_type varchar(255) NOT NULL default '',
+ PRIMARY KEY (type)
+ ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
+ break;
+
+ case 'pgsql':
+ $ret[] = update_sql("CREATE TABLE {node_type} (
+ type varchar(32) NOT NULL,
+ name varchar(255) NOT NULL,
+ module varchar(255) NOT NULL,
+ description text NOT NULL,
+ help text NOT NULL,
+ has_title integer unsigned NOT NULL,
+ title_label varchar(255) NOT NULL default '',
+ has_body integer unsigned NOT NULL,
+ body_label varchar(255) NOT NULL default '',
+ min_word_count integer unsigned NOT NULL,
+ custom smallint NOT NULL DEFAULT '0',
+ modified smallint NOT NULL DEFAULT '0',
+ locked smallint NOT NULL DEFAULT '0',
+ orig_type varchar(255) NOT NULL default '',
+ PRIMARY KEY (type)
+ );");
+ break;
+ }
+
+ // Insert default user-defined node types into the database.
+ $types = array(
+ array(
+ 'type' => 'page',
+ 'name' => t('page'),
+ 'module' => 'node',
+ 'description' => t('If you want to add a static page, like a contact page or an about page, use a page.'),
+ 'custom' => TRUE,
+ 'modified' => TRUE,
+ 'locked' => FALSE,
+ ),
+ array(
+ 'type' => 'story',
+ 'name' => t('story'),
+ 'module' => 'node',
+ 'description' => t('Stories are articles in their simplest form: they have a title, a teaser and a body, but can be extendd by other modules. The teaser is part of the body too. Stories may be used as a personal blog or for news articles.'),
+ 'custom' => TRUE,
+ 'modified' => TRUE,
+ 'locked' => FALSE,
+ )
+ );
+
+ foreach ($types as $type) {
+ $type = (object) _node_type_set_defaults($type);
+ node_type_save($type);
+ }
+
+ cache_clear_all();
+ system_modules();
+ menu_rebuild();
+ node_types_rebuild();
+
+ // Migrate old values for 'minimum_x_size' variables to the node_type table.
+ $query = db_query('SELECT type FROM {node_type}');
+ while ($result = db_fetch_object($query)) {
+ $variable_name = 'minimum_'. $result->type .'_size';
+ if ($value = db_fetch_object(db_query("SELECT value FROM {variable} WHERE name = '%s'", $variable_name))) {
+ $value = (int) unserialize($value->value);
+ db_query("UPDATE {node_type} SET min_word_count = %d, modified = %d WHERE type = '%s'", $value, 1, $result->type);
+ variable_del($variable_name);
+ }
+ }
+
+ node_types_rebuild();
+
+ return $ret;
+}
diff --git a/modules/system/system.module b/modules/system/system.module
index e19ed56e5..ce2b15767 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -1253,6 +1253,7 @@ function system_modules_submit($form_id, $edit) {
}
menu_rebuild();
+ node_types_rebuild();
drupal_set_message(t('The configuration options have been saved.'));
return 'admin/settings/modules';
@@ -1377,7 +1378,7 @@ function system_theme_settings($key = '') {
);
// Toggle node display.
- $node_types = module_invoke('node', 'get_types');
+ $node_types = node_get_types('names');
if ($node_types) {
$form['node_info'] = array(
'#type' => 'fieldset',
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index ddf308edf..543f4b661 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -138,7 +138,7 @@ function taxonomy_overview_vocabularies() {
foreach ($vocabularies as $vocabulary) {
$types = array();
foreach ($vocabulary->nodes as $type) {
- $node_type = node_get_name($type);
+ $node_type = node_get_types('name', $type);
$types[] = $node_type ? $node_type : $type;
}
$rows[] = array('name' => check_plain($vocabulary->name),
diff --git a/modules/tracker/tracker.module b/modules/tracker/tracker.module
index 2e3e71bfc..cdaf2df73 100644
--- a/modules/tracker/tracker.module
+++ b/modules/tracker/tracker.module
@@ -110,7 +110,7 @@ function tracker_page($uid = 0) {
}
$rows[] = array(
- node_get_name($node->type),
+ node_get_types('name', $node->type),
l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)),
theme('username', $node),
array('class' => 'replies', 'data' => $comments),
diff --git a/modules/upload/upload.module b/modules/upload/upload.module
index 6ad97cc53..d36dc2011 100644
--- a/modules/upload/upload.module
+++ b/modules/upload/upload.module
@@ -348,14 +348,16 @@ function _upload_prepare(&$node) {
}
function upload_form_alter($form_id, &$form) {
- if (isset($form['type'])) {
- if ($form['type']['#value'] .'_node_settings' == $form_id) {
- $form['workflow']['upload_'. $form['type']['#value']] = array(
- '#type' => 'radios', '#title' => t('Attachments'), '#default_value' => variable_get('upload_'. $form['type']['#value'], 1),
- '#options' => array(t('Disabled'), t('Enabled')),
- );
- }
+ if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
+ $form['workflow']['upload'] = array(
+ '#type' => 'radios',
+ '#title' => t('Attachments'),
+ '#default_value' => variable_get('upload_'. $form['identity']['type']['#default_value'], 1),
+ '#options' => array(t('Disabled'), t('Enabled')),
+ );
+ }
+ if (isset($form['type'])) {
$node = $form['#node'];
if ($form['type']['#value'] .'_node_form' == $form_id && variable_get("upload_$node->type", TRUE) && user_access('upload files')) {
drupal_add_js('misc/progress.js');
diff --git a/profiles/default.profile b/profiles/default.profile
index 1171c5def..158477e56 100644
--- a/profiles/default.profile
+++ b/profiles/default.profile
@@ -8,7 +8,7 @@
* An array of modules to be enabled.
*/
function default_profile_modules() {
- return array('block', 'comment', 'filter', 'help', 'menu', 'node', 'page', 'story', 'system', 'taxonomy', 'user', 'watchdog');
+ return array('block', 'comment', 'filter', 'help', 'menu', 'node', 'system', 'taxonomy', 'user', 'watchdog');
}
/**