From 6123f3ae62a9b683a49a3d6c9b264a2dc9a45ac0 Mon Sep 17 00:00:00 2001 From: joyqi Date: Sun, 5 Sep 2021 10:47:29 +0800 Subject: [PATCH] fix sandbox --- admin/css/style.css | 5 ++--- admin/src/scss/_forms.scss | 4 ++++ install.php | 6 ++++-- var/Typecho/Common.php | 2 +- var/Typecho/Db/Adapter/ConnectionException.php | 18 ++++++++++++++++++ var/Typecho/Db/Adapter/MysqlTrait.php | 2 +- var/Typecho/Db/Adapter/Mysqli.php | 8 ++++---- var/Typecho/Db/Adapter/Pdo.php | 8 ++++---- var/Typecho/Db/Adapter/Pdo/Mysql.php | 1 - var/Typecho/Db/Adapter/Pdo/Pgsql.php | 4 ++-- var/Typecho/Db/Adapter/Pgsql.php | 8 ++++---- var/Typecho/Db/Adapter/PgsqlTrait.php | 8 ++++---- .../{Exception.php => SQLException.php} | 2 +- var/Typecho/Db/Adapter/SQLite.php | 8 ++++---- var/Typecho/Db/Adapter/SQLiteTrait.php | 4 ++-- var/Typecho/Widget.php | 2 +- 16 files changed, 56 insertions(+), 34 deletions(-) create mode 100644 var/Typecho/Db/Adapter/ConnectionException.php rename var/Typecho/Db/Adapter/{Exception.php => SQLException.php} (83%) diff --git a/admin/css/style.css b/admin/css/style.css index 1d309464..e9617136 100644 --- a/admin/css/style.css +++ b/admin/css/style.css @@ -23,6 +23,8 @@ a.button:hover, a.balloon-button:hover { background-color: #A5CADC; color: #FFF; /** Forms */ input[type=text], input[type=password], input[type=email], textarea { background: #FFF; border: 1px solid #D9D9D6; padding: 7px; border-radius: 2px; box-sizing: border-box; } +input[type=text]:disabled, input[type=text]:read-only, input[type=password]:disabled, input[type=password]:read-only, input[type=email]:disabled, input[type=email]:read-only, textarea:disabled, textarea:read-only { background: #F3F3F3; } + textarea { resize: vertical; line-height: 1.5; } input[type="radio"], input[type="checkbox"] { margin-right: 3px; } @@ -203,9 +205,6 @@ select { border: 1px solid #CCC; height: 28px; } .typecho-foot .resource a { margin: 0 3px; color: #999; } -/* 低版本浏览器升级提示 */ -.browsehappy { border: none; text-align: center; } - /** 顶部消息样式 by 70 */ .popup { display: none; position: absolute; top: 0; left: 0; margin: 0; padding: 8px 0; border: none; width: 100%; z-index: 10; text-align: center; border-radius: 0; } diff --git a/admin/src/scss/_forms.scss b/admin/src/scss/_forms.scss index 2e94bdf6..4b217bbe 100644 --- a/admin/src/scss/_forms.scss +++ b/admin/src/scss/_forms.scss @@ -11,6 +11,10 @@ textarea { border-radius: 2px; box-sizing: border-box; + + &:disabled, &:read-only { + background: #F3F3F3; + } } textarea { diff --git a/install.php b/install.php index 4b5f7fb4..30a2bb51 100644 --- a/install.php +++ b/install.php @@ -418,7 +418,7 @@ require_once __TYPECHO_ROOT_DIR__ . '/var/Typecho/Common.php'; // init \Typecho\Common::init(); - + // config db \$db = new \Typecho\Db('{$adapter}', '{$dbPrefix}'); \$db->addServer(" . (var_export($dbConfig, true)) . ", \Typecho\Db::READ | \Typecho\Db::WRITE); @@ -473,7 +473,9 @@ function install_check(string $type): bool if ($type == 'db_data' && empty($values)) { return false; } - } catch (\Typecho\Db\Exception $e) { + } catch (\Typecho\Db\Adapter\ConnectionException $e) { + return true; + } catch (\Typecho\Db\Adapter\SQLException $e) { return false; } diff --git a/var/Typecho/Common.php b/var/Typecho/Common.php index 9fb3602d..b0264dcf 100644 --- a/var/Typecho/Common.php +++ b/var/Typecho/Common.php @@ -187,7 +187,7 @@ namespace Typecho { //覆盖原始错误信息 $message = 'Database Server Error'; - if ($exception instanceof \Typecho\Db\Adapter\Exception) { + if ($exception instanceof \Typecho\Db\Adapter\SQLException) { $code = 503; $message = 'Error establishing a database connection'; } elseif ($exception instanceof \Typecho\Db\Query\Exception) { diff --git a/var/Typecho/Db/Adapter/ConnectionException.php b/var/Typecho/Db/Adapter/ConnectionException.php new file mode 100644 index 00000000..dcb0ffaa --- /dev/null +++ b/var/Typecho/Db/Adapter/ConnectionException.php @@ -0,0 +1,18 @@ +dbLink->error); + throw new ConnectionException(@$this->dbLink->error, @$this->dbLink->errno); } /** @@ -87,7 +87,7 @@ class Mysqli implements Adapter * @param string|null $action 数据库动作 * @param string|null $table 数据表 * @return \mysqli_result - * @throws Exception + * @throws SQLException */ public function query( string $query, @@ -101,7 +101,7 @@ class Mysqli implements Adapter } /** 数据库异常 */ - throw new Exception($this->dbLink->error, $this->dbLink->errno); + throw new SQLException($this->dbLink->error, $this->dbLink->errno); } /** diff --git a/var/Typecho/Db/Adapter/Pdo.php b/var/Typecho/Db/Adapter/Pdo.php index 649772f9..4f957982 100644 --- a/var/Typecho/Db/Adapter/Pdo.php +++ b/var/Typecho/Db/Adapter/Pdo.php @@ -49,7 +49,7 @@ abstract class Pdo implements Adapter * * @param Config $config 数据库配置 * @return \PDO - * @throws Exception + * @throws ConnectionException */ public function connect(Config $config): \PDO { @@ -59,7 +59,7 @@ abstract class Pdo implements Adapter return $this->object; } catch (\PDOException $e) { /** 数据库异常 */ - throw new Exception($e->getMessage()); + throw new ConnectionException($e->getMessage(), $e->getCode()); } } @@ -94,7 +94,7 @@ abstract class Pdo implements Adapter * @param string|null $action 数据库动作 * @param string|null $table 数据表 * @return \PDOStatement - * @throws Exception + * @throws SQLException */ public function query( string $query, @@ -109,7 +109,7 @@ abstract class Pdo implements Adapter $resource->execute(); } catch (\PDOException $e) { /** 数据库异常 */ - throw new Exception($e->getMessage(), $e->getCode()); + throw new SQLException($e->getMessage(), $e->getCode()); } return $resource; diff --git a/var/Typecho/Db/Adapter/Pdo/Mysql.php b/var/Typecho/Db/Adapter/Pdo/Mysql.php index c3f4bd69..29850502 100644 --- a/var/Typecho/Db/Adapter/Pdo/Mysql.php +++ b/var/Typecho/Db/Adapter/Pdo/Mysql.php @@ -3,7 +3,6 @@ namespace Typecho\Db\Adapter\Pdo; use Typecho\Config; -use Typecho\Db\Adapter\Exception; use Typecho\Db\Adapter\MysqlTrait; use Typecho\Db\Adapter\Pdo; diff --git a/var/Typecho/Db/Adapter/Pdo/Pgsql.php b/var/Typecho/Db/Adapter/Pdo/Pgsql.php index f800aa2f..af4bd37b 100644 --- a/var/Typecho/Db/Adapter/Pdo/Pgsql.php +++ b/var/Typecho/Db/Adapter/Pdo/Pgsql.php @@ -4,7 +4,7 @@ namespace Typecho\Db\Adapter\Pdo; use Typecho\Config; use Typecho\Db; -use Typecho\Db\Adapter\Exception; +use Typecho\Db\Adapter\SQLException; use Typecho\Db\Adapter\Pdo; use Typecho\Db\Adapter\PgsqlTrait; @@ -41,7 +41,7 @@ class Pgsql extends Pdo * @param string|null $action 数据库动作 * @param string|null $table 数据表 * @return \PDOStatement - * @throws Exception + * @throws SQLException */ public function query( string $query, diff --git a/var/Typecho/Db/Adapter/Pgsql.php b/var/Typecho/Db/Adapter/Pgsql.php index 1b223148..f6556e1b 100644 --- a/var/Typecho/Db/Adapter/Pgsql.php +++ b/var/Typecho/Db/Adapter/Pgsql.php @@ -35,7 +35,7 @@ class Pgsql implements Adapter * * @param Config $config 数据库配置 * @return resource - * @throws Exception + * @throws ConnectionException */ public function connect(Config $config) { @@ -50,7 +50,7 @@ class Pgsql implements Adapter } /** 数据库异常 */ - throw new Exception(pg_last_error($dbLink)); + throw new ConnectionException(pg_last_error($dbLink)); } /** @@ -74,7 +74,7 @@ class Pgsql implements Adapter * @param string|null $action 数据库动作 * @param string|null $table 数据表 * @return resource - * @throws Exception + * @throws SQLException */ public function query(string $query, $handle, int $op = Db::READ, ?string $action = null, ?string $table = null) { @@ -84,7 +84,7 @@ class Pgsql implements Adapter } /** 数据库异常 */ - throw new Exception( + throw new SQLException( @pg_last_error($handle), pg_result_error_field(pg_get_result($handle), PGSQL_DIAG_SQLSTATE) ); diff --git a/var/Typecho/Db/Adapter/PgsqlTrait.php b/var/Typecho/Db/Adapter/PgsqlTrait.php index b4d9d632..1dbb03f6 100644 --- a/var/Typecho/Db/Adapter/PgsqlTrait.php +++ b/var/Typecho/Db/Adapter/PgsqlTrait.php @@ -28,7 +28,7 @@ trait PgsqlTrait * * @param string $table * @param resource $handle 连接对象 - * @throws Exception + * @throws SQLException */ public function truncate(string $table, $handle) { @@ -64,7 +64,7 @@ trait PgsqlTrait * @param $handle * @param string|null $action * @param string|null $table - * @throws Exception + * @throws SQLException */ protected function prepareQuery(string &$query, $handle, ?string $action = null, ?string $table = null) { @@ -109,7 +109,7 @@ WHERE * @param resource $resource 查询的资源数据 * @param resource $handle 连接对象 * @return integer - * @throws Exception + * @throws SQLException */ public function lastInsertId($resource, $handle): int { @@ -164,4 +164,4 @@ WHERE abstract public function quoteValue(string $string): string; abstract public function fetch($resource): ?array; -} \ No newline at end of file +} diff --git a/var/Typecho/Db/Adapter/Exception.php b/var/Typecho/Db/Adapter/SQLException.php similarity index 83% rename from var/Typecho/Db/Adapter/Exception.php rename to var/Typecho/Db/Adapter/SQLException.php index 09c91e67..9288b119 100644 --- a/var/Typecho/Db/Adapter/Exception.php +++ b/var/Typecho/Db/Adapter/SQLException.php @@ -13,6 +13,6 @@ use Typecho\Db\Exception as DbException; * * @package Db */ -class Exception extends DbException +class SQLException extends DbException { } diff --git a/var/Typecho/Db/Adapter/SQLite.php b/var/Typecho/Db/Adapter/SQLite.php index e3e9df7e..cc83a2d5 100644 --- a/var/Typecho/Db/Adapter/SQLite.php +++ b/var/Typecho/Db/Adapter/SQLite.php @@ -35,7 +35,7 @@ class SQLite implements Adapter * * @param Config $config 数据库配置 * @return \SQLite3 - * @throws Exception + * @throws ConnectionException */ public function connect(Config $config): \SQLite3 { @@ -43,7 +43,7 @@ class SQLite implements Adapter $dbHandle = new \SQLite3($config->file); $this->isSQLite2 = version_compare(\SQLite3::version()['versionString'], '3.0.0', '<'); } catch (\Exception $e) { - throw new Exception($e->getMessage(), $e->getCode()); + throw new ConnectionException($e->getMessage(), $e->getCode()); } return $dbHandle; @@ -69,7 +69,7 @@ class SQLite implements Adapter * @param string|null $action 数据库动作 * @param string|null $table 数据表 * @return \SQLite3Result - * @throws Exception + * @throws SQLException */ public function query( string $query, @@ -85,7 +85,7 @@ class SQLite implements Adapter } /** 数据库异常 */ - throw new Exception($handle->lastErrorMsg(), $handle->lastErrorCode()); + throw new SQLException($handle->lastErrorMsg(), $handle->lastErrorCode()); } /** diff --git a/var/Typecho/Db/Adapter/SQLiteTrait.php b/var/Typecho/Db/Adapter/SQLiteTrait.php index dc9f9690..9a028a13 100644 --- a/var/Typecho/Db/Adapter/SQLiteTrait.php +++ b/var/Typecho/Db/Adapter/SQLiteTrait.php @@ -16,7 +16,7 @@ trait SQLiteTrait * * @param string $table * @param mixed $handle 连接对象 - * @throws Exception + * @throws SQLException */ public function truncate(string $table, $handle) { @@ -99,4 +99,4 @@ trait SQLiteTrait return $query; } -} \ No newline at end of file +} diff --git a/var/Typecho/Widget.php b/var/Typecho/Widget.php index dbc8c3b6..4ced92e2 100644 --- a/var/Typecho/Widget.php +++ b/var/Typecho/Widget.php @@ -136,7 +136,7 @@ abstract class Widget $sandbox = false; - if (isset($request) || $call === true || is_callable($call)) { + if (isset($request) || $call === false || is_callable($call)) { $sandbox = true; Request::getInstance()->beginSandbox(new Config($request)); Response::getInstance()->beginSandbox();