Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.551 diff -u -r1.551 common.inc --- includes/common.inc 3 Aug 2006 07:06:36 -0000 1.551 +++ includes/common.inc 7 Aug 2006 19:30:12 -0000 @@ -285,27 +285,98 @@ * Generates a 404 error if the request can not be handled. */ function drupal_not_found() { - drupal_set_header('HTTP/1.0 404 Not Found'); - watchdog('page not found', t('%page not found.', array('%page' => theme('placeholder', $_GET['q']))), WATCHDOG_WARNING); - + // Sends only 404 header if enabled + if (variable_get('404_send_header', true)) { + drupal_set_header('HTTP/1.0 404 Not Found'); + } + // Keep old path for reference if (!isset($_REQUEST['destination'])) { $_REQUEST['destination'] = $_GET['q']; } + + // Get the path to the 404 page + $path = drupal_get_normal_path(trim(variable_get('site_404', ''))); + + // Set default 404 page, title and message, to be overwritten if other values should be used + menu_set_active_item(''); + $return = ''; + $message = ''; + $title = ''; + + // To prevent loops + if ($path != $_REQUEST['destination']) { + + if (($path == '' || empty($path)) && module_exist('search') && user_access('search content')) { + + // Get keywords from url + $keys = $_REQUEST['destination']; + + // Separates all words with atleast one space at each side + $keys = preg_replace('/['.PREG_CLASS_SEARCH_EXCLUDE.']/u', ' ', '.'.$keys.'.'); + + // Words to ignore + $ignore = trim(variable_get('404_search_ignore_words', 'htm html php jpg gif png')); + $ignore = preg_quote($ignore, '/'); + $ignore = preg_replace('/\s+/', '|', $ignore); - $path = drupal_get_normal_path(variable_get('site_404', '')); - if ($path && $path != $_GET['q']) { - menu_set_active_item($path); - $return = menu_execute_active_handler(); - } - else { - // Redirect to a non-existent menu item to make possible tabs disappear. - menu_set_active_item(''); + if (!empty($ignore)) { + $keys = preg_replace('/ ('.$ignore.') /u', '', $keys); + } + + // Removes uneccessary characters + $keys = trim(search_simplify($keys)); + + // Use 'OR' between words, if enabled + $keys = preg_replace('/\s+/', variable_get('404_search_use_or', false) ? ' OR ' : ' ', $keys); + + menu_set_active_item('search/node/' . $keys); + $return = menu_execute_active_handler(); + + // Results for the jump feature + $results = module_invoke('node', 'search', 'search', $keys); + + if (!empty($keys)) { + if (variable_get('404_search_link', false)) { + $message = t('For your convenience, here is a link to a search using the query "%keys".', array('%keys' => l($keys, 'search/node/'.$keys))); + menu_set_active_item(''); + $return = ''; + } + elseif (variable_get('404_search_jump', false) && count($results) == 1) { + $message = t('For your convenience, a search for "%keys" was performed, which resulted in the content shown below (%page).', array('%keys' => l($keys, 'search/node/'.$keys), '%page' => l(url('node/' . $results[0]['node']->nid, null, null, true), 'node/' . $results[0]['node']->nid))); + menu_set_active_item('node/' . $results[0]['node']->nid); + $return = menu_execute_active_handler(); + $title = $results[0]['node']->title; + } + else { + $message = t('For your convenience, a search was performed using the query "%keys".', array('%keys' => $keys)); + } + } + } + elseif ($path == '') { + menu_set_active_item(variable_get('site_frontpage', 'node')); + $return = menu_execute_active_handler(); + } + elseif ($path != '') { + // It's not , or + menu_set_active_item($path); + $return = menu_execute_active_handler(); + } } + // Make sure we create no loops + if ($return == MENU_NOT_FOUND || $return == MENU_ACCESS_DENIED) { + $return = ''; + $message = ''; + } if (empty($return)) { - drupal_set_title(t('Page not found')); + // Redirect to a non-existent menu item to make possible tabs disappear. + menu_set_active_item(''); + $return = ' '; } + watchdog('page not found', t('%page not found.', array('%page' => theme('placeholder', $_REQUEST['destination']))), WATCHDOG_WARNING); + drupal_set_message(variable_get('404_message', t('We are sorry, the page you requested could not be found. Please check the spelling and punctuation. This website is case sensitive, so also make sure that the address has the correct case.')).' '.$message); + drupal_set_title((empty($title)) ? t('Page not found: %page', array('%page' => $_REQUEST['destination'])) : $title); print theme('page', $return); } @@ -313,28 +384,52 @@ * Generates a 403 error if the request is not allowed. */ function drupal_access_denied() { - drupal_set_header('HTTP/1.0 403 Forbidden'); - watchdog('access denied', t('%page denied access.', array('%page' => theme('placeholder', $_GET['q']))), WATCHDOG_WARNING, l(t('view'), $_GET['q'])); + // Sends only 403 header if enabled + if (variable_get('403_send_header', true)) { + drupal_set_header('HTTP/1.0 403 Forbidden'); + } // Keep old path for reference if (!isset($_REQUEST['destination'])) { $_REQUEST['destination'] = $_GET['q']; } - $path = drupal_get_normal_path(variable_get('site_403', '')); - if ($path && $path != $_GET['q']) { - menu_set_active_item($path); - $return = menu_execute_active_handler(); - } - else { - // Redirect to a non-existent menu item to make possible tabs disappear. - menu_set_active_item(''); + // Get the path to the 403 page + $path = drupal_get_normal_path(trim(variable_get('site_403', ''))); + + // To prevent loops + if ($path != $_REQUEST['destination']) { + if ($path == '' || empty($path)) { + global $user; + if (!$user->uid) { + $return = user_login(); + menu_set_active_item(''); + } + } + elseif ($path == '') { + menu_set_active_item(variable_get('site_frontpage', 'node')); + $return = menu_execute_active_handler(); + } + elseif ($path != '') { + // It's not , or + menu_set_active_item($path); + $return = menu_execute_active_handler(); + } } + // Make sure we create no loops + if ($return == MENU_NOT_FOUND || $return == MENU_ACCESS_DENIED) { + $return = ''; + } if (empty($return)) { + // Redirect to a non-existent menu item to make possible tabs disappear. + menu_set_active_item(''); drupal_set_title(t('Access denied')); - $return = t('You are not authorized to access this page.'); + $return = ' '; } + + watchdog('access denied', t('%page denied access.', array('%page' => theme('placeholder', $_REQUEST['destination']))), WATCHDOG_WARNING, l(t('view'), $_REQUEST['destination'])); + drupal_set_message(variable_get('403_message', 'We are sorry, you do not have access to this page. If you are not already logged in, please try to login and then visit this page again. If you think should be able to access this page, please contact site admins.')); print theme('page', $return); } Index: modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.334 diff -u -r1.334 system.module --- modules/system/system.module 3 Aug 2006 01:02:50 -0000 1.334 +++ modules/system/system.module 7 Aug 2006 19:30:13 -0000 @@ -527,35 +527,101 @@ } function system_error_reporting_settings() { - - $form['site_403'] = array( + $form['403'] = array( + '#type' => 'fieldset', + '#title' => t('403 (access denied) page'), + '#description' => t('These settings apply when the requested document is denied to the current user.'), + ); + $form['403']['site_403'] = array( '#type' => 'textfield', '#title' => t('Default 403 (access denied) page'), '#default_value' => variable_get('site_403', ''), - '#description' => t('This page is displayed when the requested document is denied to the current user. If you are not using clean URLs, specify the part after "?q=". If unsure, specify nothing.') + '#description' => t('This page is displayed when the requested document is denied for the current user. If you are not using clean URLs, specify the part after "?q=". You can also specify one of the following commands:
  • <front> Displays the frontpage.
  • <login> Displays a login form, if the user is not already logged in, in that case <blank> will be displayed.
  • <blank> Displays a blank Drupal page with error message only.
If unsure, leave blank and <login> will be assumed.'), ); - - $form['site_404'] = array( + $form['403']['403_message'] = array( + '#type' => 'textarea', + '#title' => t('Message'), + '#description' => t('This message is displayed when the requested document is denied for the current user.'), + '#default_value' => variable_get('403_message', t('We are sorry, you do not have access to this page. If you are not already logged in, please try to login and then visit this page again. If you think should be able to access this page, please contact site admins.')), + ); + $form['403']['403_send_header'] = array( + '#type' => 'checkbox', + '#title' => t('Send 403 header'), + '#description' => t('Sends a 403 header to browser. HTTP/1.0 403 Forbidden (Recommended).'), + '#default_value' => variable_get('403_send_header', true), + ); + $form['404'] = array( + '#type' => 'fieldset', + '#title' => t('404 (file not found) page'), + '#description' => t('These settings apply when no other content matches the requested document.'), + ); + $form['404']['site_404'] = array( '#type' => 'textfield', '#title' => t('Default 404 (not found) page'), '#default_value' => variable_get('site_404', ''), - '#description' => t('This page is displayed when no other content matches the requested document. If you are not using clean URLs, specify the part after "?q=". If unsure, specify nothing.') + '#description' => t('This page is displayed when no other content matches the requested document. If you are not using clean URLs, specify the part after "?q=". You can also specify one of the following commands:
  • <front> Displays the frontpage.
  • <search> Performs a search on the words from the requested URL. See below for more options. This requires the search module to be enabled and accessible by user, otherwise <blank> will be displayed.
  • <blank> Displays a blank Drupal page with error message only.
If unsure, leave blank and <search> will be assumed.', array('%modules' => url('admin/settings/modules'), '%access' => url('admin/user/access'))), ); - - $form['error_level'] = array( + $form['404']['search'] = array( + '#type' => 'fieldset', + '#title' => t('<search>-options'), + '#description' => t('These options effects the <search>-page.'), + '#collapsible' => true, + '#collapsed' => true, + ); + $form['404']['search']['404_search_link'] = array( + '#type' => 'checkbox', + '#title' => t('Link to search results'), + '#description' => t('Display a link instead of the search results directly. This feature is particular useful to reduce load when the site is indexed by a search-engine.'), + '#default_value' => variable_get('404_search_link', false), + ); + $form['404']['search']['404_search_jump'] = array( + '#type' => 'checkbox', + '#title' => t('Jump'), + '#description' => t('Jump directly to the search result when there is only one result, will be ignored if Link to search results is checked.'), + '#default_value' => variable_get('404_search_jump', false), + ); + $form['404']['search']['404_search_use_or'] = array( + '#type' => 'checkbox', + '#title' => t('Use OR between keywords.'), + '#description' => t('Use OR between keywords when searching.'), + '#default_value' => variable_get('404_search_use_or', false), + ); + $form['404']['search']['404_search_ignore_words'] = array( + '#type' => 'textfield', + '#title' => t('Words to ignore'), + '#description' => t('These words will be ignored when performing a search. Separate words with a space, eg "htm html php jpg gif png". Leave blank to search for all words in URL.'), + '#default_value' => variable_get('404_search_ignore_words', 'htm html php jpg gif png'), + ); + $form['404']['404_message'] = array( + '#type' => 'textarea', + '#title' => t('Message'), + '#description' => t('This message is displayed at the begining of every 404 message. Please note that after this message a small text string might be inserted when appropriate, eg "For your convenience, a search was performed using the query %query.".'), + '#default_value' => variable_get('404_message', t('We are sorry, the page you requested could not be found. Please check the spelling and punctuation. This website is case sensitive, so also make sure that the address has the correct case.')), + ); + $form['404']['404_send_header'] = array( + '#type' => 'checkbox', + '#title' => t('Send 404 header'), + '#description' => t('Sends a 404 header to browser. HTTP/1.0 404 Not Found (Recommended).'), + '#default_value' => variable_get('404_send_header',true), + ); + $form['error'] = array( + '#type' => 'fieldset', + '#title' => t('Other error handling'), + '#description' => t('Configure error messages and logs'), + ); + $form['error']['error_level'] = array( '#type' => 'select', '#title' => t('Error reporting'), '#default_value' => variable_get('error_level', 1), '#options' => array(t('Write errors to the log'), t('Write errors to the log and to the screen')), - '#description' => t('Where Drupal, PHP and SQL errors are logged. On a production server it is recommended that errors are only written to the error log. On a test server it can be helpful to write logs to the screen.') + '#description' => t('Where Drupal, PHP and SQL errors are logged. On a production server it is recommended that errors are only written to the error log. On a test server it can be helpful to write logs to the screen.'), ); - $period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval'); $period['1000000000'] = t('Never'); - $form['watchdog_clear'] = array( + $form['error']['watchdog_clear'] = array( '#type' => 'select', '#title' => t('Discard log entries older than'), '#default_value' => variable_get('watchdog_clear', 604800), '#options' => $period, - '#description' => t('The time log entries should be kept. Older entries will be automatically discarded. Requires crontab.') + '#description' => t('The time log entries should be kept. Older entries will be automatically discarded. Requires crontab.'), ); return system_settings_form('system_error_reporting_settings', $form);