summaryrefslogtreecommitdiff
path: root/modules/node.module
diff options
context:
space:
mode:
Diffstat (limited to 'modules/node.module')
-rw-r--r--modules/node.module183
1 files changed, 113 insertions, 70 deletions
diff --git a/modules/node.module b/modules/node.module
index 74e6e147e..afd41f23b 100644
--- a/modules/node.module
+++ b/modules/node.module
@@ -30,7 +30,7 @@ function node_help($section = 'admin/help#node') {
<dt>Score</dt><dd>The score of the node is gotten by the votes it is given.</dd>
<dt>Users</dt><dd>The list of users who have voted on a moderated node.</dd>
<dt>Published</dt><dd>When using Drupal's moderation system a node remains unpublished -- unavaliable to non-moderators -- until it is marked Published.</dd></dl>
- <p>Now that you know what is in a node, here are some of the types of nodes available.</p>", array("%teaser" => url("admin/system/modules/node")));
+ <p>Now that you know what is in a node, here are some of the types of nodes available.</p>", array("%teaser" => url("admin/settings/node")));
if ($mod == 'admin') {
foreach (node_list() as $type) {
@@ -40,10 +40,10 @@ function node_help($section = 'admin/help#node') {
}
break;
- case 'admin/system/modules#description':
+ case 'admin/modules#description':
$output = t('The core that allows content to be submitted to the site.');
break;
- case 'admin/system/modules/node':
+ case 'admin/settings/node':
$output = t('Settings for the core of Drupal. Almost everything is a node so these settings will affect most of the site.');
break;
case 'admin/node':
@@ -52,7 +52,7 @@ function node_help($section = 'admin/help#node') {
case 'admin/node/search':
$output = t("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\".");
break;
- case 'admin/node/settings':
+ case 'admin/settings/node/defaults':
$output = t('This page lets you set the defaults used during creation of nodes for all the different node types.<br /><strong>comment:</strong> Read/write setting for comments.<br /><strong>publish:</strong> Is this node publicly viewable, has it been published?<br /><strong>promote:</strong> Is this node to be promoted to the front page?<br /><strong>moderate:</strong> Does this node need approval before it can be viewed?<br /><strong>static:</strong> Is this node always visible on the front page?<br /><strong>revision:</strong> Will this node go into the revision system allowing multiple versions to be saved?');
break;
@@ -77,7 +77,7 @@ function node_help_page() {
function node_title_list($result, $title = NULL) {
while ($node = db_fetch_object($result)) {
$number = module_invoke('comment', 'num_all', $node->nid);
- $items[] = l($node->title, "node/view/$node->nid", array('title' => format_plural($number, '1 comment', '%count comments')));
+ $items[] = l($node->title, "node/$node->nid", array('title' => format_plural($number, '1 comment', '%count comments')));
}
return theme('node_list', $items, $title);
@@ -484,7 +484,7 @@ function node_save($node) {
}
-function node_view($node, $main = 0, $page = 0) {
+function node_view($node, $teaser = FALSE, $page = FALSE) {
$node = array2object($node);
@@ -496,7 +496,7 @@ function node_view($node, $main = 0, $page = 0) {
$node->body = str_replace('<!--break-->', '', $node->body);
// Allow modules to change $node->body before viewing.
- node_invoke_nodeapi($node, 'view', $main, $page);
+ node_invoke_nodeapi($node, 'view', $teaser, $page);
/*
** The 'view' hook can be implemented to overwrite the default function
@@ -504,7 +504,7 @@ function node_view($node, $main = 0, $page = 0) {
*/
if (node_hook($node, 'view')) {
- return node_invoke($node, 'view', $main, $page);
+ return node_invoke($node, 'view', $teaser, $page);
}
else {
@@ -512,13 +512,13 @@ function node_view($node, $main = 0, $page = 0) {
** Default behavior:
*/
- return theme('node', node_prepare($node, $main), $main, $page);
+ return theme('node', node_prepare($node, $teaser), $teaser, $page);
}
}
-function node_prepare($node, $main = 0) {
+function node_prepare($node, $teaser = FALSE) {
$node->readmore = (strlen($node->teaser) < strlen($node->body));
- if ($main == 0) {
+ if ($teaser == FALSE) {
$node->body = check_output($node->body);
}
else {
@@ -596,12 +596,19 @@ function node_search($keys) {
return array(t('Matching nodes ranked in order of relevance'), $find);
}
-function node_settings() {
+/**
+ * Page 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?'));
- return $output;
+ print theme('page', system_settings_form($output));
}
function node_comment_mode($nid) {
@@ -625,11 +632,7 @@ function node_link($type, $node = 0, $main = 0) {
}
if ($main == 1 && $node->teaser && $node->readmore) {
- $links[] = l(t('read more'), "node/view/$node->nid", array('title' => t('Read the rest of this posting.'), 'class' => 'read-more'));
- }
-
- if (user_access('administer nodes')) {
- $links[] = l(t('administer'), "admin/node/edit/$node->nid", array('title' => t('Administer this node.')));
+ $links[] = l(t('read more'), "node/$node->nid", array('title' => t('Read the rest of this posting.'), 'class' => 'read-more'));
}
if (user_access('administer nodes') && $node->revisions) {
@@ -637,23 +640,71 @@ function node_link($type, $node = 0, $main = 0) {
}
}
- if ($type == 'system') {
- menu('node/add', t('create content'), 'node_page', 1, MENU_HIDE_NOCHILD);
-
- menu('admin/node', t('content'), user_access('administer nodes') ? 'node_admin' : MENU_DENIED);
- menu('admin/node/help', t('help'), user_access('administer nodes') ? 'node_help_page' : MENU_DENIED, 9);
- menu('admin/node/edit', t('edit post'), user_access('administer nodes') ? 'node_admin' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED);
- menu('admin/node/settings', t('settings'), user_access('administer nodes') ? 'node_admin' : MENU_DENIED, 8);
- if (module_exist('search')) {
- menu('admin/node/search', t('search'), user_access('administer nodes') ? 'node_admin' : MENU_DENIED, 8);
- }
-
- menu('node', t('content'), user_access('access content') ? 'node_page' : MENU_DENIED, 0, MENU_HIDE);
- }
-
return $links;
}
+/**
+ * Implementation of hook_menu().
+ */
+function node_menu() {
+ $items = array();
+
+ $items[] = array('path' => 'admin/node', 'title' => t('content'),
+ 'callback' => 'node_admin',
+ 'access' => user_access('administer nodes'));
+
+ // Tabs:
+ $items[] = array('path' => 'admin/node/configure', 'title' => t('configure'),
+ 'callback' => 'node_configure',
+ 'access' => user_access('administer nodes'),
+ 'type' => MENU_LOCAL_TASK);
+ if (module_exist('search')) {
+ $items[] = array('path' => 'admin/node/search', 'title' => t('search'),
+ 'callback' => 'node_admin',
+ 'access' => user_access('administer nodes'),
+ 'type' => MENU_LOCAL_TASK);
+ }
+
+ // Subtabs:
+ $items[] = array('path' => 'admin/node/configure/settings', 'title' => t('settings'),
+ 'callback' => 'node_configure',
+ 'access' => user_access('administer nodes'),
+ 'type' => MENU_LOCAL_SUBTASK);
+ $items[] = array('path' => 'admin/node/configure/defaults', 'title' => t('default workflow'),
+ 'callback' => 'node_default_settings',
+ 'access' => user_access('administer nodes'),
+ 'type' => MENU_LOCAL_SUBTASK);
+
+ $items[] = array('path' => 'node', 'title' => t('content'),
+ 'callback' => 'node_page',
+ 'access' => user_access('access content'),
+ 'type' => MENU_SUGGESTED_ITEM);
+ $items[] = array('path' => 'node/add', 'title' => t('create content'),
+ 'callback' => 'node_page',
+ 'access' => user_access('access content'),
+ 'type' => MENU_ITEM_GROUPING,
+ 'weight' => 1);
+
+ if (arg(0) == 'node' && is_numeric(arg(1))) {
+ $items[] = array('path' => 'node/'. arg(1), 'title' => t('view'),
+ 'callback' => 'node_page',
+ 'access' => user_access('access content'),
+ 'type' => MENU_CALLBACK);
+ $items[] = array('path' => 'node/'. arg(1) .'/edit', 'title' => t('edit'),
+ 'callback' => 'node_page',
+ 'access' => user_access('administer nodes'),
+ 'type' => MENU_LOCAL_TASK);
+ }
+
+ // Legacy handler
+ $items[] = array('path' => 'node/view', 'title' => t('view'),
+ 'callback' => 'node_old_url',
+ 'access' => user_access('access content'),
+ 'type' => MENU_CALLBACK);
+
+ return $items;
+}
+
function node_admin_edit($node) {
if (is_numeric($node)) {
@@ -758,7 +809,7 @@ function node_admin_nodes() {
$header = array(NULL, t('title'), t('type'), t('author'), t('status'), array('data' => t('operations'), 'colspan' => 2));
while ($node = db_fetch_object($result)) {
- $rows[] = array(form_checkbox(NULL, "status][$node->nid", 1, 0), l($node->title, "node/view/$node->nid") .' '. (node_is_new($node->nid, $node->changed) ? theme_mark() : ''), node_invoke($node, 'node_name'), format_name($node), ($node->status ? t('published') : t('not published')), l(t('edit node'), "admin/node/edit/$node->nid"), l(t('delete node'), "admin/node/delete/$node->nid"));
+ $rows[] = array(form_checkbox(NULL, "status][$node->nid", 1, 0), l($node->title, "node/$node->nid") .' '. (node_is_new($node->nid, $node->changed) ? theme_mark() : ''), node_invoke($node, 'node_name'), format_name($node), ($node->status ? t('published') : t('not published')), l(t('edit node'), "node/$node->nid/edit"), l(t('delete node'), "admin/node/delete/$node->nid"));
}
if ($pager = theme('pager', NULL, 50, 0)) {
@@ -770,8 +821,9 @@ function node_admin_nodes() {
return form($output);
}
-function node_admin_settings($edit) {
+function node_default_settings() {
$op = $_POST['op'];
+ $edit = $_POST['edit'];
if ($op == t('Save configuration')) {
/*
@@ -810,8 +862,7 @@ function node_admin_settings($edit) {
$output .= form_submit(t('Save configuration'));
$output .= form_submit(t('Reset to defaults'));
- return form($output);
-
+ print theme('page', form($output));
}
function node_revision_overview($nid) {
@@ -823,7 +874,7 @@ function node_revision_overview($nid) {
$header = array(t('older revisions'), array('colspan' => '3', 'data' => t('operations')));
foreach ($node->revisions as $key => $revision) {
- $rows[] = array(t('revision #%r revised by %u on %d', array('%r' => $key, '%u' => format_name(user_load(array('uid' => $revision['uid']))), '%d' => format_date($revision['timestamp'], 'small'))) . ($revision['history'] ? '<br /><small>'. $revision['history'] .'</small>' : ''), l(t('view'), "node/view/$node->nid", array(), "revision=$key"), l(t('rollback'), "node/rollback-revision/$node->nid/$key"), l(t('delete'), "node/delete-revision/$node->nid/$key"));
+ $rows[] = array(t('revision #%r revised by %u on %d', array('%r' => $key, '%u' => format_name(user_load(array('uid' => $revision['uid']))), '%d' => format_date($revision['timestamp'], 'small'))) . ($revision['history'] ? '<br /><small>'. $revision['history'] .'</small>' : ''), l(t('view'), "node/$node->nid", array(), "revision=$key"), l(t('rollback'), "node/rollback-revision/$node->nid/$key"), l(t('delete'), "node/delete-revision/$node->nid/$key"));
}
$output .= theme('table', $header, $rows);
}
@@ -956,27 +1007,9 @@ function node_admin() {
case 'search':
$output = search_type('node', url('admin/node/search'), $_POST['keys']);
break;
- case 'edit':
- $output = node_admin_edit(arg(3));
- break;
case 'delete':
$output = node_delete(array('nid' => arg(3)));
break;
- case t('Preview'):
- $edit = node_validate($edit, $error);
- $output = node_preview($edit, $error);
- break;
- case t('Submit'):
- $output = node_submit($edit);
- break;
- case t('Delete'):
- $output = node_delete($edit);
- break;
- case t('Save configuration'):
- case t('Reset to defaults'):
- case 'settings':
- $output = node_admin_settings($edit);
- break;
default:
$output = node_admin_nodes();
}
@@ -1018,7 +1051,7 @@ function node_feed($nodes = 0, $channel = array()) {
*/
$item = node_load(array('nid' => $node->nid));
- $link = url("node/view/$node->nid", NULL, NULL, 1);
+ $link = url("node/$node->nid", NULL, NULL, 1);
$items .= format_rss_item($item->title, $link, ($item->teaser ? $item->teaser : $item->body), array('pubDate' => date('r', $item->changed)));
}
@@ -1146,7 +1179,6 @@ function node_validate($node, &$error) {
function node_form($edit, $error = NULL) {
-
/*
** Validate the node:
*/
@@ -1321,7 +1353,7 @@ function node_edit($id) {
$node = node_load(array('nid' => $id));
- drupal_set_title(t('Edit %name', array('%name' => node_invoke($node, 'node_name'))));
+ drupal_set_title($node->title);
if (node_access('update', $node)) {
$output = node_form($node);
@@ -1434,7 +1466,7 @@ function node_submit($node) {
if (node_access('update', $node)) {
$node->nid = node_save($node);
- watchdog('special', t('%node-type: updated "%node-title"', array('%node-type' => t("$node->type"), '%node-title' => $node->title)), l(t('view post'), "node/view/$node->nid"));
+ watchdog('special', t('%node-type: updated "%node-title"', array('%node-type' => t("$node->type"), '%node-title' => $node->title)), l(t('view post'), "node/$node->nid"));
$msg = t('the %name was updated.', array ('%name' => node_invoke($node, 'node_name')));
}
}
@@ -1447,7 +1479,7 @@ function node_submit($node) {
if (node_access('create', $node)) {
$node->nid = node_save($node);
- watchdog('special', t('%node-type: added "%node-title"', array('%node-type' => t("$node->type"), '%node->title' => $node->title)), l(t('view post'), "node/view/$node->nid"));
+ watchdog('special', t('%node-type: added "%node-title"', array('%node-type' => t("$node->type"), '%node->title' => $node->title)), l(t('view post'), "node/$node->nid"));
$msg = t('your %name was created.', array ('%name' => node_invoke($node, 'node_name')));
}
}
@@ -1519,16 +1551,25 @@ function node_page_default() {
<p>The first thing you will need to do is <a href=\"%register\">create the first account</a>. This account will have full administration rights and will allow you to configure your website. Once logged in, you can visit the <a href=\"%admin\">administration section</a> and <a href=\"%config\">set up your site's configuration</a>.</p>
<p>Drupal comes with various modules, each of which contains a specific piece of functionality. You should visit the <a href=\"%modules\">module list</a> and enable those modules which suit your website's needs.</p>
<p><a href=\"%themes\">Themes</a> handle the presentation of your website. You can use one of the existing themes, modify them or create your own from scratch.</p>
- <p>We suggest you look around the administration section and explore the various options Drupal offers you. For more information, you can refer to the <a href=\"%handbook\">Drupal handbook online</a>.</p>", array('%drupal' => 'http://www.drupal.org/', '%register' => url('user/register'), '%admin' => url('admin'), '%config' => url('admin/system'), '%modules' => url('admin/system/modules'), '%themes' => url('admin/system/themes'), '%handbook' => 'http://www.drupal.org/handbook'));
+ <p>We suggest you look around the administration section and explore the various options Drupal offers you. For more information, you can refer to the <a href=\"%handbook\">Drupal handbook online</a>.</p>", array('%drupal' => 'http://www.drupal.org/', '%register' => url('user/register'), '%admin' => url('admin'), '%config' => url('admin'), '%modules' => url('admin/modules'), '%themes' => url('admin/themes'), '%handbook' => 'http://www.drupal.org/handbook'));
}
return $output;
}
+function node_old_url($nid = 0) {
+ drupal_goto("node/$nid");
+}
+
function node_page() {
$op = $_POST['op'] ? $_POST['op'] : arg(1);
$edit = $_POST['edit'];
+ // Temporary solution - backward compatibility?
+ if (is_numeric($op)) {
+ $op = arg(2) ? arg(2) : 'view';
+ }
+
switch ($op) {
case 'feed':
node_feed();
@@ -1537,15 +1578,7 @@ function node_page() {
print theme('page', node_add(arg(2)));
break;
case 'edit':
- print theme('page', node_edit(arg(2)));
- break;
- case 'view':
- if ($node = node_load(array('nid' => arg(2)), $_GET['revision'])) {
- print theme('page', node_show($node, arg(3)), $node->title);
- }
- else {
- drupal_not_found();
- }
+ print theme('page', node_edit(arg(1)));
break;
case 'revisions':
print theme('page', node_revision_overview(arg(2)), t('Revisions'));
@@ -1558,6 +1591,16 @@ function node_page() {
node_revision_delete(arg(2), arg(3));
print theme('page', node_revision_overview(arg(2)), t('Revisions'));
break;
+ case 'view':
+ if (is_numeric(arg(1))) {
+ if ($node = node_load(array('nid' => arg(1)), $_GET['revision'])) {
+ print theme('page', node_show($node, arg(3)), $node->title);
+ }
+ else {
+ drupal_not_found();
+ }
+ }
+ break;
case t('Preview'):
$edit = node_validate($edit, $error);
print theme('page', node_preview($edit, $error), t('Preview %name', array('%name' => $name)));