diff --git a/includes/Database.class.php b/includes/Database.class.php index 29e4f603..9c9df1fc 100644 --- a/includes/Database.class.php +++ b/includes/Database.class.php @@ -3,7 +3,7 @@ * @Author: printempw * @Date: 2016-02-02 21:59:06 * @Last Modified by: printempw - * @Last Modified time: 2016-03-12 16:43:53 + * @Last Modified time: 2016-03-12 18:15:55 */ class Database @@ -15,19 +15,20 @@ class Database } public static function checkConfig() { + error_reporting(0); $conn = new mysqli(DB_HOST, DB_USER, DB_PASSWD, DB_NAME, DB_PORT); if ($conn->connect_error) { - Utils::raise(-1, "Can not connect to mysql, check if database info correct in config.php. ". - $conn->connect_error); + Utils::showErrorPage(-1, "Can not connect to mysql, check if database info correct in config.php. ". + $conn->connect_error); } if (!self::checkTableExist($conn)) { - Utils::raise(-1, "Looks like that there is no `users` table in your database. ". - "Please run `/admin/install.php` first."); + Utils::showErrorPage(-1, "Looks like that there is no `users` table in your database. ". + "Please run `/admin/install.php` first."); } $dir = dirname(dirname(__FILE__)); if (!is_dir("$dir/textures/")) { - Utils::raise(-1, "No `textures` directory exists. Please run `/admin/install.php` ". - "or put one manually."); + Utils::showErrorPage(-1, "No `textures` directory exists. Please run `/admin/install.php` ". + "or put one manually."); } return $conn; } diff --git a/includes/User.class.php b/includes/User.class.php index cce710cc..bb499d03 100644 --- a/includes/User.class.php +++ b/includes/User.class.php @@ -3,7 +3,7 @@ * @Author: printempw * @Date: 2016-01-16 23:01:33 * @Last Modified by: printempw - * @Last Modified time: 2016-03-06 15:27:00 + * @Last Modified time: 2016-03-12 18:33:34 */ class User @@ -114,11 +114,11 @@ class User return Utils::fread($filename); } else { header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); - Utils::raise(-1, 'Texture no longer exists.'); + Utils::showErrorPage(404, '请求的贴图已被删除。'); } } else { header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); - Utils::raise(-1, 'No available textures.'); + Utils::showErrorPage(404, '该用户尚未上传请求的贴图类型。'); } } @@ -167,7 +167,7 @@ class User $json['skins'][$sec_model] = $this->getTexture($sec_model == "default" ? "steve" : "alex"); $json['cape'] = $this->getTexture('cape'); } else { - Utils::raise(-1, '配置文件错误:不支持的 API_TYPE。'); + Utils::showErrorPage(-1, '配置文件错误:不支持的 API_TYPE。'); } } else { header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); diff --git a/includes/Utils.class.php b/includes/Utils.class.php index 3617b19a..a5126952 100644 --- a/includes/Utils.class.php +++ b/includes/Utils.class.php @@ -3,7 +3,7 @@ * @Author: printempw * @Date: 2016-01-16 23:01:33 * @Last Modified by: printempw - * @Last Modified time: 2016-03-06 15:44:32 + * @Last Modified time: 2016-03-12 18:00:02 */ class Utils @@ -22,6 +22,12 @@ class Utils die(json_encode($exception)); } + public static function showErrorPage($errno = -1, $msg = "Error occured.") { + $dir = dirname(dirname(__FILE__)); + require "$dir/includes/error.tpl.php"; + die(); + } + /** * Rename uploaded file * diff --git a/includes/autoload.inc.php b/includes/autoload.inc.php index e029a706..4befd822 100644 --- a/includes/autoload.inc.php +++ b/includes/autoload.inc.php @@ -3,7 +3,7 @@ * @Author: prpr * @Date: 2016-02-02 21:17:59 * @Last Modified by: printempw - * @Last Modified time: 2016-03-12 17:20:54 + * @Last Modified time: 2016-03-12 18:04:46 */ function __autoload($classname) { @@ -12,5 +12,5 @@ function __autoload($classname) { include_once($filename); } if (!file_exists($dir.'/config.php')) - Utils::raise(-1, '未找到 `config.php`,请确认配置文件是否存在。'); + Utils::showErrorPage(-1, '未找到 `config.php`,请确认配置文件是否存在。'); require "$dir/config.php"; diff --git a/includes/error.tpl.php b/includes/error.tpl.php new file mode 100644 index 00000000..712a524c --- /dev/null +++ b/includes/error.tpl.php @@ -0,0 +1,85 @@ + + + + + + + 出现错误 - Blessing Skin Server + + + + + +

出现了一些错误:

+ +

错误码:

+

详细信息:

+ + + + + diff --git a/index.php b/index.php index 49a5d924..33c0fddb 100755 --- a/index.php +++ b/index.php @@ -2,8 +2,8 @@ /** * @Author: printempw * @Date: 2016-01-17 13:55:20 - * @Last Modified by: prpr - * @Last Modified time: 2016-02-10 14:18:22 + * @Last Modified by: printempw + * @Last Modified time: 2016-03-12 18:03:48 */ session_start(); $dir = dirname(__FILE__); diff --git a/user/index.php b/user/index.php index 8618665e..b1144c88 100644 --- a/user/index.php +++ b/user/index.php @@ -3,7 +3,7 @@ * @Author: prpr * @Date: 2016-01-21 13:56:40 * @Last Modified by: printempw - * @Last Modified time: 2016-02-28 14:09:48 + * @Last Modified time: 2016-03-12 18:28:07 */ require "../includes/session.inc.php"; ?>