Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqi committed Jan 29, 2018
1 parent 82212ed commit 02dd3f9
Show file tree
Hide file tree
Showing 19 changed files with 293 additions and 18 deletions.
4 changes: 4 additions & 0 deletions admin/common-js.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ function checkScroll () {
t.attr('target', '_blank');
});
}

$('.main form').submit(function () {
$('button[type=submit]', this).attr('disabled', 'disabled');
});
});
})();
</script>
14 changes: 12 additions & 2 deletions admin/write-js.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ function justifySlugWidth() {
cid = idInput.val(),
draft = $('input[name=draft]'),
draftId = draft.length > 0 ? draft.val() : 0,
btnSave = $('#btn-save'),
btnSave = $('#btn-save').removeAttr('name').removeAttr('value'),
btnSubmit = $('#btn-submit').removeAttr('name').removeAttr('value'),
btnPreview = $('#btn-preview'),
doAction = $('<input type="hidden" name="do" value="publish" />').appendTo(form),
locked = false,
changed = false,
autoSave = $('<span id="auto-save-message" class="left"></span>').prependTo('.submit'),
Expand Down Expand Up @@ -199,7 +201,7 @@ function callback(o) {
btnPreview.attr('disabled', 'disabled');
autoSave.text('<?php _e('正在保存'); ?>');

if (FormData !== undefined) {
if (typeof FormData !== 'undefined') {
var data = new FormData(form.get(0));
data.append('do', 'save');

Expand Down Expand Up @@ -328,6 +330,14 @@ function cancelPreview() {
}
});

btnSave.click(function () {
doAction.attr('value', 'save');
});

btnSubmit.click(function () {
doAction.attr('value', 'publish');
});

// 控制选项和附件的切换
var fileUploadInit = false;
$('#edit-secondary .typecho-option-tabs li').click(function() {
Expand Down
2 changes: 1 addition & 1 deletion install/Mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CREATE TABLE `typecho_comments` (
`authorId` int(10) unsigned default '0',
`ownerId` int(10) unsigned default '0',
`mail` varchar(150) default NULL,
`url` varchar(150) default NULL,
`url` varchar(255) default NULL,
`ip` varchar(64) default NULL,
`agent` varchar(511) default NULL,
`text` text,
Expand Down
2 changes: 1 addition & 1 deletion install/Pgsql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CREATE TABLE "typecho_comments" ( "coid" INT NOT NULL DEFAULT nextval('typecho_
"authorId" INT NULL DEFAULT '0',
"ownerId" INT NULL DEFAULT '0',
"mail" VARCHAR(150) NULL DEFAULT NULL,
"url" VARCHAR(150) NULL DEFAULT NULL,
"url" VARCHAR(255) NULL DEFAULT NULL,
"ip" VARCHAR(64) NULL DEFAULT NULL,
"agent" VARCHAR(511) NULL DEFAULT NULL,
"text" TEXT NULL DEFAULT NULL,
Expand Down
2 changes: 1 addition & 1 deletion install/SQLite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CREATE TABLE typecho_comments ( "coid" INTEGER NOT NULL PRIMARY KEY,
"authorId" int(10) default '0' ,
"ownerId" int(10) default '0' ,
"mail" varchar(150) default NULL ,
"url" varchar(150) default NULL ,
"url" varchar(255) default NULL ,
"ip" varchar(64) default NULL ,
"agent" varchar(511) default NULL ,
"text" text ,
Expand Down
2 changes: 1 addition & 1 deletion var/Typecho/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class Typecho_Common
{
/** 程序版本 */
const VERSION = '1.1/17.12.14';
const VERSION = '1.2/18.1.29';

/**
* 允许的属性
Expand Down
13 changes: 12 additions & 1 deletion var/Typecho/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,24 @@ public function insert($table)
return $this->sql()->insert($table);
}

/**
* @param $table
* @throws Typecho_Db_Exception
*/
public function truncate($table)
{
$table = preg_replace("/^table\./", $this->_prefix, $table);
$this->_adapter->truncate($table, $this->selectDb(self::WRITE));
}

/**
* 执行查询语句
*
* @param mixed $query 查询语句或者查询对象
* @param boolean $op 数据库读写状态
* @param int $op 数据库读写状态
* @param string $action 操作动作
* @return mixed
* @throws Typecho_Db_Exception
*/
public function query($query, $op = self::READ, $action = self::SELECT)
{
Expand Down
9 changes: 9 additions & 0 deletions var/Typecho/Db/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ public function connect(Typecho_Config $config);
*/
public function getVersion($handle);

/**
* 清空数据表
*
* @param string $table 数据表名
* @param mixed $handle 连接对象
* @return mixed
*/
public function truncate($table, $handle);

/**
* 执行数据库查询
*
Expand Down
15 changes: 14 additions & 1 deletion var/Typecho/Db/Adapter/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,20 @@ public function connect(Typecho_Config $config)
*/
public function getVersion($handle)
{
return 'ext:mysql ' . mysql_get_server_info($handle);
return 'mysql:mysql ' . mysql_get_server_info($handle);
}

/**
* 清空数据表
*
* @param string $table
* @param mixed $handle 连接对象
* @return mixed|void
* @throws Typecho_Db_Exception
*/
public function truncate($table, $handle)
{
$this->query('TRUNCATE TABLE ' . $this->quoteColumn($table), $handle);
}

/**
Expand Down
15 changes: 14 additions & 1 deletion var/Typecho/Db/Adapter/Mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,20 @@ public function connect(Typecho_Config $config)
*/
public function getVersion($handle)
{
return 'ext:mysqli ' . $this->_dbLink->server_version;
return 'mysqli:mysql ' . $this->_dbLink->server_version;
}

/**
* 清空数据表
*
* @param string $table
* @param mixed $handle 连接对象
* @return mixed|void
* @throws Typecho_Db_Exception
*/
public function truncate($table, $handle)
{
$this->query('TRUNCATE TABLE ' . $this->quoteColumn($table), $handle);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion var/Typecho/Db/Adapter/Pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function isAvailable()
*
* @param Typecho_Config $config 数据库配置
* @throws Typecho_Db_Exception
* @return resource
* @return PDO
*/
public function connect(Typecho_Config $config)
{
Expand Down
13 changes: 13 additions & 0 deletions var/Typecho/Db/Adapter/Pdo/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ public static function isAvailable()
return parent::isAvailable() && in_array('mysql', PDO::getAvailableDrivers());
}

/**
* 清空数据表
*
* @param string $table
* @param mixed $handle 连接对象
* @return mixed|void
* @throws Typecho_Db_Exception
*/
public function truncate($table, $handle)
{
$this->query('TRUNCATE TABLE ' . $this->quoteColumn($table), $handle);
}

/**
* 初始化数据库
*
Expand Down
79 changes: 77 additions & 2 deletions var/Typecho/Db/Adapter/Pdo/Pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
*/
class Typecho_Db_Adapter_Pdo_Pgsql extends Typecho_Db_Adapter_Pdo
{
/**
* 主键列表
*
* @var array
*/
private $_pk = array();

/**
* 兼容的插入模式
*
* @var bool
*/
private $_compatibleInsert = false;

/**
* 判断适配器是否可用
*
Expand All @@ -26,6 +40,19 @@ public static function isAvailable()
return parent::isAvailable() && in_array('pgsql', PDO::getAvailableDrivers());
}

/**
* 清空数据表
*
* @param string $table
* @param mixed $handle 连接对象
* @return mixed|void
* @throws Typecho_Db_Exception
*/
public function truncate($table, $handle)
{
$this->query('TRUNCATE TABLE ' . $this->quoteColumn($table) . ' RESTART IDENTITY', $handle);
}

/**
* 初始化数据库
*
Expand All @@ -40,6 +67,51 @@ public function init(Typecho_Config $config)
return $pdo;
}

/**
* 覆盖标准动作
* fix #710
*
* @param string $query
* @param mixed $handle
* @param int $op
* @param null $action
* @param null $table
* @return resource
* @throws Typecho_Db_Exception
*/
public function query($query, $handle, $op = Typecho_Db::READ, $action = NULL, $table = NULL)
{
if (Typecho_Db::INSERT == $action && !empty($table)) {
if (!isset($this->_pk[$table])) {
$result = $handle->query("SELECT
pg_attribute.attname,
format_type(pg_attribute.atttypid, pg_attribute.atttypmod)
FROM pg_index, pg_class, pg_attribute, pg_namespace
WHERE
pg_class.oid = " . $this->quoteValue($table) . "::regclass AND
indrelid = pg_class.oid AND
nspname = 'public' AND
pg_class.relnamespace = pg_namespace.oid AND
pg_attribute.attrelid = pg_class.oid AND
pg_attribute.attnum = any(pg_index.indkey)
AND indisprimary")->fetch(PDO::FETCH_ASSOC);

if (!empty($result)) {
$this->_pk[$table] = $result['attname'];
}
}

// 使用兼容模式监听插入结果
if (isset($this->_pk[$table])) {
$this->_compatibleInsert = true;
$query .= ' RETURNING ' . $this->quoteColumn($this->_pk[$table]);
}
}

return parent::query($query, $handle, $op, $action, $table); // TODO: Change the autogenerated stub
}


/**
* 对象引号过滤
*
Expand Down Expand Up @@ -84,8 +156,11 @@ public function parseSelect(array $sql)
*/
public function lastInsertId($resource, $handle)
{
/** 查看是否存在序列,可能需要更严格的检查 */
if ($handle->query('SELECT oid FROM pg_class WHERE relname = ' . $this->quoteValue($this->_lastTable . '_seq'))->fetchAll()) {
if ($this->_compatibleInsert) {
$this->_compatibleInsert = false;
return $resource->fetchColumn(0);
} else if ($handle->query('SELECT oid FROM pg_class WHERE relname = ' . $this->quoteValue($this->_lastTable . '_seq'))->fetchAll()) {
/** 查看是否存在序列,可能需要更严格的检查 */
return $handle->lastInsertId($this->_lastTable . '_seq');
}

Expand Down
13 changes: 13 additions & 0 deletions var/Typecho/Db/Adapter/Pdo/SQLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ public static function isAvailable()
return parent::isAvailable() && in_array('sqlite', PDO::getAvailableDrivers());
}

/**
* 清空数据表
*
* @param string $table
* @param mixed $handle 连接对象
* @return mixed|void
* @throws Typecho_Db_Exception
*/
public function truncate($table, $handle)
{
$this->query('DELETE FROM ' . $this->quoteColumn($table), $handle);
}

/**
* 初始化数据库
*
Expand Down
15 changes: 14 additions & 1 deletion var/Typecho/Db/Adapter/Pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,20 @@ public function connect(Typecho_Config $config)
public function getVersion($handle)
{
$version = pg_version($handle);
return 'ext:pgsql ' . $version['server'];
return 'pgsql:pgsql ' . $version['server'];
}

/**
* 清空数据表
*
* @param string $table
* @param mixed $handle 连接对象
* @return mixed|void
* @throws Typecho_Db_Exception
*/
public function truncate($table, $handle)
{
$this->query('TRUNCATE TABLE ' . $this->quoteColumn($table) . ' RESTART IDENTITY', $handle);
}

/**
Expand Down
15 changes: 14 additions & 1 deletion var/Typecho/Db/Adapter/SQLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,20 @@ public function connect(Typecho_Config $config)
*/
public function getVersion($handle)
{
return 'ext:sqlite ' . sqlite_libversion();
return 'sqlite:sqlite ' . sqlite_libversion();
}

/**
* 清空数据表
*
* @param string $table
* @param mixed $handle 连接对象
* @return mixed|void
* @throws Typecho_Db_Exception
*/
public function truncate($table, $handle)
{
$this->query('DELETE FROM ' . $this->quoteColumn($table), $handle);
}

/**
Expand Down
Loading

0 comments on commit 02dd3f9

Please sign in to comment.