Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqi committed Oct 29, 2017
1 parent 7a2b374 commit 9884a2f
Show file tree
Hide file tree
Showing 28 changed files with 112 additions and 64 deletions.
2 changes: 1 addition & 1 deletion admin/manage-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<?php while($posts->next()): ?>
<tr id="<?php $posts->theId(); ?>">
<td><input type="checkbox" value="<?php $posts->cid(); ?>" name="cid[]"/></td>
<td><a href="<?php $options->adminUrl('manage-comments.php?cid=' . $posts->cid); ?>" class="balloon-button size-<?php echo Typecho_Common::splitByCount($posts->commentsNum, 1, 10, 20, 50, 100); ?>" title="<?php $posts->commentsNum(); ?> <?php _e('评论'); ?>"><?php $posts->commentsNum(); ?></a></td>
<td><a href="<?php $options->adminUrl('manage-comments.php?cid=' . ($posts->parentId ? $posts->parentId : $posts->cid)); ?>" class="balloon-button size-<?php echo Typecho_Common::splitByCount($posts->commentsNum, 1, 10, 20, 50, 100); ?>" title="<?php $posts->commentsNum(); ?> <?php _e('评论'); ?>"><?php $posts->commentsNum(); ?></a></td>
<td>
<a href="<?php $options->adminUrl('write-post.php?cid=' . $posts->cid); ?>"><?php $posts->title(); ?></a>
<?php
Expand Down
5 changes: 3 additions & 2 deletions admin/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
</nav>
<div class="operate">
<?php Typecho_Plugin::factory('admin/menu.php')->navBar(); ?>
<a title="<?php
<a title="<?php
if ($user->logged > 0) {
_e('最后登录: %s', Typecho_I18n::dateWord($user->logged + $options->timezone, $options->gmtTime + $options->timezone));
$logged = new Typecho_Date($user->logged);
_e('最后登录: %s', $logged->word());
}
?>" href="<?php $options->adminUrl('profile.php'); ?>" class="author"><?php $user->screenName(); ?></a><a class="exit" href="<?php $options->logoutUrl(); ?>"><?php _e('登出'); ?></a><a href="<?php $options->siteUrl(); ?>"><?php _e('网站'); ?></a>
</div>
Expand Down
3 changes: 2 additions & 1 deletion admin/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
$stat->myPublishedPostsNum, $stat->myPublishedCommentsNum, $stat->categoriesNum); ?></p>
<p><?php
if ($user->logged > 0) {
_e('最后登录: %s', Typecho_I18n::dateWord($user->logged + $options->timezone, $options->gmtTime + $options->timezone));
$logged = new Typecho_Date($user->logged);
_e('最后登录: %s', $logged->word());
}
?></p>
</div>
Expand Down
8 changes: 4 additions & 4 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,24 +382,24 @@ function _u() {
$installDb->query($installDb->insert('table.relationships')->rows(array('cid' => 1, 'mid' => 1)));

/** 初始内容 */
$installDb->query($installDb->insert('table.contents')->rows(array('title' => _t('欢迎使用 Typecho'), 'slug' => 'start', 'created' => Typecho_Date::gmtTime(), 'modified' => Typecho_Date::gmtTime(),
$installDb->query($installDb->insert('table.contents')->rows(array('title' => _t('欢迎使用 Typecho'), 'slug' => 'start', 'created' => Typecho_Date::time(), 'modified' => Typecho_Date::time(),
'text' => '<!--markdown-->' . _t('如果您看到这篇文章,表示您的 blog 已经安装成功.'), 'authorId' => 1, 'type' => 'post', 'status' => 'publish', 'commentsNum' => 1, 'allowComment' => 1,
'allowPing' => 1, 'allowFeed' => 1, 'parent' => 0)));

$installDb->query($installDb->insert('table.contents')->rows(array('title' => _t('关于'), 'slug' => 'start-page', 'created' => Typecho_Date::gmtTime(), 'modified' => Typecho_Date::gmtTime(),
$installDb->query($installDb->insert('table.contents')->rows(array('title' => _t('关于'), 'slug' => 'start-page', 'created' => Typecho_Date::time(), 'modified' => Typecho_Date::time(),
'text' => '<!--markdown-->' . _t('本页面由 Typecho 创建, 这只是个测试页面.'), 'authorId' => 1, 'order' => 0, 'type' => 'page', 'status' => 'publish', 'commentsNum' => 0, 'allowComment' => 1,
'allowPing' => 1, 'allowFeed' => 1, 'parent' => 0)));

/** 初始评论 */
$installDb->query($installDb->insert('table.comments')->rows(array('cid' => 1, 'created' => Typecho_Date::gmtTime(), 'author' => 'Typecho', 'ownerId' => 1, 'url' => 'http://typecho.org',
$installDb->query($installDb->insert('table.comments')->rows(array('cid' => 1, 'created' => Typecho_Date::time(), 'author' => 'Typecho', 'ownerId' => 1, 'url' => 'http://typecho.org',
'ip' => '127.0.0.1', 'agent' => $options->generator, 'text' => '欢迎加入 Typecho 大家族', 'type' => 'comment', 'status' => 'approved', 'parent' => 0)));

/** 初始用户 */
$password = empty($config['userPassword']) ? substr(uniqid(), 7) : $config['userPassword'];
$hasher = new PasswordHash(8, true);

$installDb->query($installDb->insert('table.users')->rows(array('name' => $config['userName'], 'password' => $hasher->HashPassword($password), 'mail' => $config['userMail'],
'url' => 'http://www.typecho.org', 'screenName' => $config['userName'], 'group' => 'administrator', 'created' => Typecho_Date::gmtTime())));
'url' => 'http://www.typecho.org', 'screenName' => $config['userName'], 'group' => 'administrator', 'created' => Typecho_Date::time())));

unset($_SESSION['typecho']);
header('Location: ./install.php?finish&user=' . urlencode($config['userName'])
Expand Down
28 changes: 19 additions & 9 deletions var/Typecho/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class Typecho_Date
public static $serverTimezoneOffset = 0;

/**
* 当前的GMT时间戳
* 当前的服务器时间戳
*
* @access public
* @var integer
*/
public static $gmtTimeStamp;
public static $serverTimeStamp;

/**
* 可以被直接转换的时间戳
Expand All @@ -45,11 +45,11 @@ class Typecho_Date
* 初始化参数
*
* @access public
* @param integer $gmtTime GMT时间戳
* @param integer $time 时间戳
*/
public function __construct($gmtTime)
public function __construct($time = NULL)
{
$this->timeStamp = $gmtTime + (self::$timezoneOffset - self::$serverTimezoneOffset);
$this->timeStamp = (NULL === $time ? self::time() : $time) + (self::$timezoneOffset - self::$serverTimezoneOffset);
}

/**
Expand Down Expand Up @@ -85,7 +85,7 @@ public function format($format)
*/
public function word()
{
return Typecho_I18n::dateWord($this->timeStamp, self::gmtTime() + (self::$timezoneOffset - self::$serverTimezoneOffset));
return Typecho_I18n::dateWord($this->timeStamp, self::time() + (self::$timezoneOffset - self::$serverTimezoneOffset));
}

/**
Expand All @@ -112,11 +112,21 @@ public function __get($name)
/**
* 获取GMT时间
*
* @access public
* @return integer
* @deprecated
* @return int
*/
public static function gmtTime()
{
return self::$gmtTimeStamp ? self::$gmtTimeStamp : (self::$gmtTimeStamp = @gmmktime());
return self::time();
}

/**
* 获取服务器时间
*
* @return int
*/
public static function time()
{
return self::$serverTimeStamp ? self::$serverTimeStamp : (self::$serverTimeStamp = time() - idate('Z'));
}
}
2 changes: 1 addition & 1 deletion var/Widget/Abstract/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function insert(array $comment)
/** 构建插入结构 */
$insertStruct = array(
'cid' => $comment['cid'],
'created' => empty($comment['created']) ? $this->options->gmtTime : $comment['created'],
'created' => empty($comment['created']) ? $this->options->time : $comment['created'],
'author' => empty($comment['author']) ? NULL : $comment['author'],
'authorId' => empty($comment['authorId']) ? 0 : $comment['authorId'],
'ownerId' => empty($comment['ownerId']) ? 0 : $comment['ownerId'],
Expand Down
8 changes: 4 additions & 4 deletions var/Widget/Abstract/Contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ public function insert(array $content)
/** 构建插入结构 */
$insertStruct = array(
'title' => empty($content['title']) ? NULL : htmlspecialchars($content['title']),
'created' => empty($content['created']) ? $this->options->gmtTime : $content['created'],
'modified' => $this->options->gmtTime,
'created' => empty($content['created']) ? $this->options->time : $content['created'],
'modified' => $this->options->time,
'text' => empty($content['text']) ? NULL : $content['text'],
'order' => empty($content['order']) ? 0 : intval($content['order']),
'authorId' => isset($content['authorId']) ? $content['authorId'] : $this->user->uid,
Expand Down Expand Up @@ -345,7 +345,7 @@ public function update(array $content, Typecho_Db_Query $condition)
$updateStruct['created'] = $content['created'];
}

$updateStruct['modified'] = $this->options->gmtTime;
$updateStruct['modified'] = $this->options->time;

/** 首先插入部分数据 */
$updateCondition = clone $condition;
Expand Down Expand Up @@ -850,7 +850,7 @@ public function allow()
/** 对自动关闭反馈功能的支持 */
if (('ping' == $permission || 'comment' == $permission) && $this->options->commentsPostTimeout > 0 &&
$this->options->commentsAutoClose) {
if ($this->options->gmtTime - $this->created > $this->options->commentsPostTimeout) {
if ($this->options->time - $this->created > $this->options->commentsPostTimeout) {
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions var/Widget/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ public function execute()
$select = $this->select()->where('table.contents.status = ?', 'publish');
}
}
$select->where('table.contents.created < ?', $this->options->gmtTime);
$select->where('table.contents.created < ?', $this->options->time);
}

/** handle初始化 */
Expand Down Expand Up @@ -1541,7 +1541,7 @@ public function attachments($limit = 0, $offset = 0)
public function theNext($format = '%s', $default = NULL, $custom = array())
{
$content = $this->db->fetchRow($this->select()->where('table.contents.created > ? AND table.contents.created < ?',
$this->created, $this->options->gmtTime)
$this->created, $this->options->time)
->where('table.contents.status = ?', 'publish')
->where('table.contents.type = ?', $this->type)
->where('table.contents.password IS NULL')
Expand Down
2 changes: 1 addition & 1 deletion var/Widget/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private function reLogin(&$user)
bin2hex(openssl_random_pseudo_bytes(16)) : sha1(Typecho_Common::randString(20));
}

$user['activated'] = $this->options->gmtTime;
$user['activated'] = $this->options->time;
$user['logged'] = $user['activated'];

Typecho_Cookie::set('__typecho_uid', $user['uid']);
Expand Down
2 changes: 1 addition & 1 deletion var/Widget/Comments/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public function replyComment()

$comment = array(
'cid' => $commentSelect['cid'],
'created' => $this->options->gmtTime,
'created' => $this->options->time,
'agent' => $this->request->getAgent(),
'ip' => $this->request->getIp(),
'ownerId' => $commentSelect['ownerId'],
Expand Down
2 changes: 1 addition & 1 deletion var/Widget/Contents/Page/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function writePage()
$this->pluginHandle()->finishSave($contents, $this);

if ($this->request->isAjax()) {
$created = new Typecho_Date($this->options->gmtTime);
$created = new Typecho_Date($this->options->time);
$this->response->throwJson(array(
'success' => 1,
'time' => $created->format('H:i:s A'),
Expand Down
2 changes: 1 addition & 1 deletion var/Widget/Contents/Page/List.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function execute()
{
$select = $this->select()->where('table.contents.type = ?', 'page')
->where('table.contents.status = ?', 'publish')
->where('table.contents.created < ?', $this->options->gmtTime)
->where('table.contents.created < ?', $this->options->time)
->order('table.contents.order', Typecho_Db::SORT_ASC);

//去掉自定义首页
Expand Down
25 changes: 25 additions & 0 deletions var/Widget/Contents/Post/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class Widget_Contents_Post_Admin extends Widget_Abstract_Contents
*/
protected function ___hasSaved()
{
if (in_array($this->type, array('post_draft', 'page_draft'))) {
return true;
}

$savedPost = $this->db->fetchRow($this->db->select('cid', 'modified')
->from('table.contents')
->where('table.contents.parent = ? AND (table.contents.type = ? OR table.contents.type = ?)',
Expand Down Expand Up @@ -82,6 +86,27 @@ public function getMenuTitle()
throw new Typecho_Widget_Exception(_t('用户不存在'), 404);
}

/**
* 重载过滤函数
*
* @param array $value
* @return array
*/
public function filter(array $value)
{
$value = parent::filter($value);

if (!empty($value['parent'])) {
$parent = $this->db->fetchObject($this->select()->where('cid = ?', $value['parent']));

if (!empty($parent)) {
$value['commentsNum'] = $parent->commentsNum;
}
}

return $value;
}

/**
* 执行函数
*
Expand Down
3 changes: 1 addition & 2 deletions var/Widget/Contents/Post/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class Widget_Contents_Post_Date extends Typecho_Widget
* @param mixed $request request对象
* @param mixed $response response对象
* @param mixed $params 参数列表
* @return void
*/
public function __construct($request, $response, $params = NULL)
{
Expand All @@ -70,7 +69,7 @@ public function execute()
$resource = $this->db->query($this->db->select('created')->from('table.contents')
->where('type = ?', 'post')
->where('table.contents.status = ?', 'publish')
->where('table.contents.created < ?', $this->options->gmtTime)
->where('table.contents.created < ?', $this->options->time)
->order('table.contents.created', Typecho_Db::SORT_DESC));

$offset = $this->options->timezone - $this->options->serverTimezone;
Expand Down
26 changes: 13 additions & 13 deletions var/Widget/Contents/Post/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function ___tags()
*/
protected function ___date()
{
return new Typecho_Date($this->options->gmtTime);
return new Typecho_Date();
}

/**
Expand Down Expand Up @@ -85,7 +85,7 @@ protected function ___draft()
* getFields
*
* @access protected
* @return void
* @return array
*/
protected function getFields()
{
Expand Down Expand Up @@ -123,12 +123,13 @@ protected function getFields()
*/
protected function getCreated()
{
$created = $this->options->gmtTime;
$created = $this->options->time;
if (!empty($this->request->created)) {
$created = $this->request->created;
} else if (!empty($this->request->date)) {
$dstOffset = !empty($this->request->dst) ? $this->request->dst : 0;
$created = strtotime($this->request->date) - $this->options->timezone + $this->options->serverTimezone - $dstOffset;
$timezoneOffset = isset($this->request->timezone) ? intval($this->request->timezone) : $this->options->timezone;
$created = strtotime($this->request->date) - $timezoneOffset + $this->options->serverTimezone - $dstOffset;
} else if (!empty($this->request->year) && !empty($this->request->month) && !empty($this->request->day)) {
$second = intval($this->request->get('sec', date('s')));
$min = intval($this->request->get('min', date('i')));
Expand Down Expand Up @@ -363,8 +364,7 @@ protected function save(array $contents)
/**
* 执行函数
*
* @access public
* @return void
* @throws Typecho_Widget_Exception
*/
public function execute()
{
Expand Down Expand Up @@ -437,16 +437,14 @@ public function date($format = NULL)
if (isset($this->created)) {
parent::date($format);
} else {
echo date($format, $this->options->gmtTime + $this->options->timezone - $this->options->serverTimezone);
echo date($format, $this->options->time + $this->options->timezone - $this->options->serverTimezone);
}
}

/**
* 获取文章权限
*
* @access public
* @param string $permission 权限
* @return unknown
* @return bool
*/
public function allow()
{
Expand Down Expand Up @@ -584,7 +582,8 @@ public function getFieldItems()
* @access public
* @param integer $cid
* @param string $tags
* @param boolean $count 是否参与计数
* @param boolean $beforeCount 是否参与计数
* @param boolean $afterCount 是否参与计数
* @return string
*/
public function setTags($cid, $tags, $beforeCount = true, $afterCount = true)
Expand Down Expand Up @@ -651,7 +650,8 @@ public function setTags($cid, $tags, $beforeCount = true, $afterCount = true)
* @access public
* @param integer $cid 内容id
* @param array $categories 分类id的集合数组
* @param boolean $count 是否参与计数
* @param boolean $beforeCount 是否参与计数
* @param boolean $afterCount 是否参与计数
* @return integer
*/
public function setCategories($cid, array $categories, $beforeCount = true, $afterCount = true)
Expand Down Expand Up @@ -762,7 +762,7 @@ public function writePost()
$this->pluginHandle()->finishSave($contents, $this);

if ($this->request->isAjax()) {
$created = new Typecho_Date($this->options->gmtTime);
$created = new Typecho_Date();
$this->response->throwJson(array(
'success' => 1,
'time' => $created->format('H:i:s A'),
Expand Down
2 changes: 1 addition & 1 deletion var/Widget/Contents/Post/Recent.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function execute()

$this->db->fetchAll($this->select()
->where('table.contents.status = ?', 'publish')
->where('table.contents.created < ?', $this->options->gmtTime)
->where('table.contents.created < ?', $this->options->time)
->where('table.contents.type = ?', 'post')
->order('table.contents.created', Typecho_Db::SORT_DESC)
->limit($this->parameter->pageSize), array($this, 'push'));
Expand Down
2 changes: 1 addition & 1 deletion var/Widget/Contents/Related.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function execute()
->where('table.contents.cid <> ?', $this->parameter->cid)
->where('table.contents.status = ?', 'publish')
->where('table.contents.password IS NULL')
->where('table.contents.created < ?', $this->options->gmtTime)
->where('table.contents.created < ?', $this->options->time)
->where('table.contents.type = ?', $this->parameter->type)
->order('table.contents.created', Typecho_Db::SORT_DESC)
->limit($this->parameter->limit), array($this, 'push'));
Expand Down
2 changes: 1 addition & 1 deletion var/Widget/Contents/Related/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function execute()
->where('table.contents.cid <> ?', $this->parameter->cid)
->where('table.contents.status = ?', 'publish')
->where('table.contents.password IS NULL')
->where('table.contents.created < ?', $this->options->gmtTime)
->where('table.contents.created < ?', $this->options->time)
->where('table.contents.type = ?', $this->parameter->type)
->order('table.contents.created', Typecho_Db::SORT_DESC)
->limit($this->parameter->limit), array($this, 'push'));
Expand Down
Loading

0 comments on commit 9884a2f

Please sign in to comment.