1 common.inc backdrop_deliver_html_page($page_callback_result)

Packages and sends the result of a page callback to the browser as HTML.

Parameters

$page_callback_result: The result of a page callback. Can be one of:

  • NULL: to indicate no content.
  • An integer menu status constant: to indicate an error condition.
  • A string of HTML content.
  • A renderable array of content.

See also

backdrop_deliver_page()

File

core/includes/common.inc, line 2973
Common functions that many Backdrop modules will need to reference.

Code

function backdrop_deliver_html_page($page_callback_result) {
  // Emit the correct charset HTTP header, but not if the page callback
  // result is NULL, since that likely indicates that it printed something
  // in which case, no further headers may be sent, and not if code running
  // for this page request has already set the content type header.
  if (isset($page_callback_result) && is_null(backdrop_get_http_header('Content-Type'))) {
    backdrop_add_http_header('Content-Type', 'text/html; charset=utf-8');
  }

  // Send appropriate HTTP-Header for browsers and search engines.
  global $language;
  backdrop_add_http_header('Content-Language', $language->langcode);

  // By default, do not allow the site to be rendered in an iframe on another
  // domain, but provide a variable to override this. If the code running for
  // this page request already set the X-Frame-Options header earlier, don't
  // overwrite it here.
  $frame_options = config_get('system.core', 'x_frame_options');
  if ($frame_options && is_null(backdrop_get_http_header('X-Frame-Options'))) {
    backdrop_add_http_header('X-Frame-Options', $frame_options);
  }

  // Menu status constants are integers; page content is a string or array.
  if (is_int($page_callback_result)) {
    $site_config = config('system.core');
    // @todo: Break these up into separate functions?
    switch ($page_callback_result) {
      case MENU_NOT_FOUND:
        // Print a 404 page.
        backdrop_add_http_header('Status', '404 Not Found');

        watchdog('page not found', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);

        // Check for and return a fast 404 page if configured.
        fast_404();

        // Keep old path for reference, and to allow forms to redirect to it.
        if (!isset($_GET['destination'])) {
          // Make sure that the current path is not interpreted as external URL.
          if (!url_is_external($_GET['q'])) {
            $_GET['destination'] = $_GET['q'];
          }
        }

        $path = backdrop_get_normal_path($site_config->get('site_404'));
        if (empty($path)) {
          $path = 'system/404';
        }
        menu_set_active_item($path);
        $return = menu_execute_active_handler($path, FALSE);
        print backdrop_render_page($return);
        break;

      case MENU_ACCESS_DENIED:
        // Print a 403 page.
        backdrop_add_http_header('Status', '403 Forbidden');
        watchdog('access denied', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);

        // Keep old path for reference, and to allow forms to redirect to it.
        if (!isset($_GET['destination'])) {
          // Make sure that the current path is not interpreted as external URL.
          if (!url_is_external($_GET['q'])) {
            $_GET['destination'] = $_GET['q'];
          }
        }

        $path = backdrop_get_normal_path($site_config->get('site_403'));
        if (empty($path)) {
          $path = 'system/403';
        }
        // Custom 403 handler. Set the active item in case there are tabs to
        // display or other dependencies on the path.
        menu_set_active_item($path);
        $return = menu_execute_active_handler($path, FALSE);
        print backdrop_render_page($return);
        break;

      case MENU_SITE_OFFLINE:
        // Print a 503 page.
        backdrop_add_http_header('Status', '503 Service unavailable');
        backdrop_set_title(t('Site under maintenance'));
        print theme('maintenance_page', array('content' => filter_xss_admin(token_replace(config_get_translated('system.core', 'maintenance_mode_message')))));
        break;
    }
  }
  elseif (isset($page_callback_result)) {
    // Print anything besides a menu constant, assuming it's not NULL or
    // undefined.
    print backdrop_render_page($page_callback_result);
  }

  // Perform end-of-request tasks.
  backdrop_page_footer();
}