Пример #1
0
 /**
  * Error pages processing
  *
  * @param null|string|string[]	$custom_text	Custom error text instead of text like "404 Not Found",
  * 												or array with two elements: [error, error_description]
  * @param bool					$json			Force JSON return format
  */
 function error($custom_text = null, $json = false)
 {
     static $error_showed = false;
     if ($error_showed) {
         return;
     }
     $error_showed = true;
     if (!defined('ERROR_CODE')) {
         error_code(500);
     }
     if (defined('API') && !API && ERROR_CODE == 403 && _getcookie('sign_out')) {
         header('Location: ' . Config::instance()->base_url(), true, 302);
         $this->Content = '';
         exit;
     }
     interface_off();
     $error = code_header(ERROR_CODE);
     if (is_array($custom_text)) {
         $error = $custom_text[0];
         $error_description = $custom_text[1];
     } else {
         $error_description = $custom_text ?: $error;
     }
     if (defined('API') && API || $json) {
         if ($json) {
             header('Content-Type: application/json; charset=utf-8', true);
             interface_off();
         }
         $this->json(['error' => $error, 'error_description' => $error_description]);
     } else {
         ob_start();
         if (!_include_once(THEMES . "/{$this->theme}/error.html", false) && !_include_once(THEMES . "/{$this->theme}/error.php", false)) {
             echo "<!doctype html>\n" . h::title(code_header($error)) . ($error_description ?: $error);
         }
         $this->Content = ob_get_clean();
     }
     $this->__finish();
     exit;
 }