node_page

Versions
4.6 – 4.7
node_page()

Menu callback; dispatches control to the appropriate operation handler.

Code

modules/node.module, line 2086

<?php
function node_page() {
  $op = arg(1);

  if (is_numeric($op)) {
    $op = (arg(2) && !is_numeric(arg(2))) ? arg(2) : 'view';
  }

  switch ($op) {
    case 'view':
      if (is_numeric(arg(1))) {
        $node = node_load(arg(1));
        if ($node->nid) {
          drupal_set_title(check_plain($node->title));
          return node_show($node, arg(2));
        }
        else if (db_result(db_query('SELECT nid FROM {node} WHERE nid = %d', arg(1)))) {
          drupal_access_denied();
        }
        else {
          drupal_not_found();
        }
      }
      break;
    case 'add':
      return node_add(arg(2));
      break;
    case 'edit':
      if ($_POST['op'] == t('Delete')) {
        // Note: we redirect from node/uid/edit to node/uid/delete to make the tabs disappear.
        if ($_REQUEST['destination']) {
          $destination = drupal_get_destination();
          unset($_REQUEST['destination']);
        }
        drupal_goto('node/'. arg(1) .'/delete', $destination);
      }

      if (is_numeric(arg(1))) {
        $node = node_load(arg(1));
        if ($node->nid) {
          drupal_set_title(check_plain($node->title));
          return node_form($node);
        }
        else if (db_result(db_query('SELECT nid FROM {node} WHERE nid = %d', arg(1)))) {
          drupal_access_denied();
        }
        else {
          drupal_not_found();
        }
      }
      break;
    default:
      drupal_set_title('');
      return node_page_default();
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.