Skip to content

Commit

Permalink
merge from typecho/typecho
Browse files Browse the repository at this point in the history
  • Loading branch information
uees committed Apr 10, 2019
2 parents 8eea0bc + 32c2f82 commit 0006dee
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 22 deletions.
2 changes: 1 addition & 1 deletion admin/editor-js.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ function initMarkdown() {

// 剪贴板复制图片
textarea.pastableTextarea().on('pasteImage', function (e, data) {
var name = data.name.replace(/[\(\)\[\]\*#!]/g, '');
var name = data.name ? data.name.replace(/[\(\)\[\]\*#!]/g, '') : (new Date()).toISOString().replace(/\..+$/, '');
if (!name.match(/\.[a-z0-9]{2,}$/i)) {
var ext = data.blob.type.split('/').pop();
name += '.' + ext;
Expand Down
6 changes: 5 additions & 1 deletion admin/manage-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<button class="btn dropdown-toggle btn-s" type="button"><i class="sr-only"><?php _e('操作'); ?></i><?php _e('选中项'); ?> <i class="i-caret-down"></i></button>
<ul class="dropdown-menu">
<li><a lang="<?php _e('你确认要删除这些页面吗?'); ?>" href="<?php $security->index('/action/contents-page-edit?do=delete'); ?>"><?php _e('删除'); ?></a></li>
<li><a href="<?php $security->index('/action/contents-page-edit?do=mark&status=publish'); ?>"><?php _e('标记为<strong>%s</strong>', _t('公开')); ?></a></li>
<li><a href="<?php $security->index('/action/contents-page-edit?do=mark&status=hidden'); ?>"><?php _e('标记为<strong>%s</strong>', _t('隐藏')); ?></a></li>
</ul>
</div>
</div>
Expand Down Expand Up @@ -65,7 +67,9 @@
<?php
if ($pages->hasSaved || 'page_draft' == $pages->type) {
echo '<em class="status">' . _t('草稿') . '</em>';
} else if ('hidden' == $pages->status) {
}

if ('hidden' == $pages->status) {
echo '<em class="status">' . _t('隐藏') . '</em>';
}
?>
Expand Down
16 changes: 15 additions & 1 deletion admin/manage-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
<button class="btn dropdown-toggle btn-s" type="button"><i class="sr-only"><?php _e('操作'); ?></i><?php _e('选中项'); ?> <i class="i-caret-down"></i></button>
<ul class="dropdown-menu">
<li><a lang="<?php _e('你确认要删除这些文章吗?'); ?>" href="<?php $security->index('/action/contents-post-edit?do=delete'); ?>"><?php _e('删除'); ?></a></li>
<?php if ($user->pass('editor', true)): ?>
<li><a href="<?php $security->index('/action/contents-post-edit?do=mark&status=publish'); ?>"><?php _e('标记为<strong>%s</strong>', _t('公开')); ?></a></li>
<li><a href="<?php $security->index('/action/contents-post-edit?do=mark&status=waiting'); ?>"><?php _e('标记为<strong>%s</strong>', _t('待审核')); ?></a></li>
<li><a href="<?php $security->index('/action/contents-post-edit?do=mark&status=hidden'); ?>"><?php _e('标记为<strong>%s</strong>', _t('隐藏')); ?></a></li>
<li><a href="<?php $security->index('/action/contents-post-edit?do=mark&status=private'); ?>"><?php _e('标记为<strong>%s</strong>', _t('私密')); ?></a></li>
<?php endif; ?>
</ul>
</div>
</div>
Expand Down Expand Up @@ -114,7 +120,9 @@
<?php
if ($posts->hasSaved || 'post_draft' == $posts->type) {
echo '<em class="status">' . _t('草稿') . '</em>';
} else if ('hidden' == $posts->status) {
}

if ('hidden' == $posts->status) {
echo '<em class="status">' . _t('隐藏') . '</em>';
} else if ('waiting' == $posts->status) {
echo '<em class="status">' . _t('待审核') . '</em>';
Expand Down Expand Up @@ -169,6 +177,12 @@
<button class="btn dropdown-toggle btn-s" type="button"><i class="sr-only"><?php _e('操作'); ?></i><?php _e('选中项'); ?> <i class="i-caret-down"></i></button>
<ul class="dropdown-menu">
<li><a lang="<?php _e('你确认要删除这些文章吗?'); ?>" href="<?php $security->index('/action/contents-post-edit?do=delete'); ?>"><?php _e('删除'); ?></a></li>
<?php if ($user->pass('editor', true)): ?>
<li><a href="<?php $security->index('/action/contents-post-edit?do=mark&status=publish'); ?>"><?php _e('标记为<strong>%s</strong>', _t('公开')); ?></a></li>
<li><a href="<?php $security->index('/action/contents-post-edit?do=mark&status=waiting'); ?>"><?php _e('标记为<strong>%s</strong>', _t('待审核')); ?></a></li>
<li><a href="<?php $security->index('/action/contents-post-edit?do=mark&status=hidden'); ?>"><?php _e('标记为<strong>%s</strong>', _t('隐藏')); ?></a></li>
<li><a href="<?php $security->index('/action/contents-post-edit?do=mark&status=private'); ?>"><?php _e('标记为<strong>%s</strong>', _t('私密')); ?></a></li>
<?php endif; ?>
</ul>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion admin/write-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<div id="tab-advance" class="tab-content">
<section class="typecho-post-option" role="application">
<label for="date" class="typecho-label"><?php _e('发布日期'); ?></label>
<p><input class="typecho-date w-100" type="text" name="date" id="date" autocomplete="off" value="<?php $page->have() ? $page->date('Y-m-d H:i') : ''; ?>" /></p>
<p><input class="typecho-date w-100" type="text" name="date" id="date" autocomplete="off" value="<?php $page->have() && $page->created > 0 ? $page->date('Y-m-d H:i') : ''; ?>" /></p>
</section>

<section class="typecho-post-option">
Expand Down
2 changes: 1 addition & 1 deletion admin/write-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<div id="tab-advance" class="tab-content">
<section class="typecho-post-option" role="application">
<label for="date" class="typecho-label"><?php _e('发布日期'); ?></label>
<p><input class="typecho-date w-100" type="text" name="date" id="date" autocomplete="off" value="<?php $post->have() ? $post->date('Y-m-d H:i') : ''; ?>" /></p>
<p><input class="typecho-date w-100" type="text" name="date" id="date" autocomplete="off" value="<?php $post->have() && $post->created > 0 ? $post->date('Y-m-d H:i') : ''; ?>" /></p>
</section>

<section class="typecho-post-option category-option">
Expand Down
2 changes: 1 addition & 1 deletion var/Typecho/Widget/Helper/Form/Element/Fake.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct($name, $value)
$this->init();

/** 初始化表单项 */
$this->input = $this->input($name, $options);
$this->input = $this->input($name);

/** 初始化表单值 */
if (NULL !== $value) {
Expand Down
7 changes: 4 additions & 3 deletions var/Widget/Abstract/Contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ protected function getPageOffset($column, $offset, $type, $status = NULL, $autho
{
$select = $this->db->select(array('COUNT(table.contents.cid)' => 'num'))->from('table.contents')
->where("table.contents.{$column} > {$offset}")
->where("table.contents.type = ?", $type);
->where("table.contents.type = ? OR (table.contents.type = ? AND table.contents.parent = ?)",
$type, $type . '_draft', 0);

if (!empty($status)) {
$select->where("table.contents.status = ?", $status);
Expand Down Expand Up @@ -272,7 +273,7 @@ public function insert(array $content)
/** 构建插入结构 */
$insertStruct = array(
'title' => !isset($content['title']) || strlen($content['title']) === 0 ? NULL : htmlspecialchars($content['title']),
'created' => empty($content['created']) ? $this->options->time : $content['created'],
'created' => !isset($content['created']) ? $this->options->time : $content['created'],
'modified' => $this->options->time,
'text' => !isset($content['text']) || strlen($content['text']) === 0 ? NULL : $content['text'],
'order' => empty($content['order']) ? 0 : intval($content['order']),
Expand Down Expand Up @@ -341,7 +342,7 @@ public function update(array $content, Typecho_Db_Query $condition)
}

/** 更新创建时间 */
if (!empty($content['created'])) {
if (isset($content['created'])) {
$updateStruct['created'] = $content['created'];
}

Expand Down
4 changes: 2 additions & 2 deletions var/Widget/Contents/Attachment/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function deleteAttachment()
->where('table.contents.cid = ?', $post)
->limit(1), array($this, 'push'));

if ($this->isWriteable($condition) && $this->delete($condition)) {
if ($this->isWriteable(clone $condition) && $this->delete($condition)) {
/** 删除文件 */
Widget_Upload::deleteHandle($row);

Expand Down Expand Up @@ -285,7 +285,7 @@ public function clearAttachment()
->where('table.contents.cid = ?', $post)
->limit(1), array($this, 'push'));

if ($this->isWriteable($condition) && $this->delete($condition)) {
if ($this->isWriteable(clone $condition) && $this->delete($condition)) {
/** 删除文件 */
Widget_Upload::deleteHandle($row);

Expand Down
57 changes: 57 additions & 0 deletions var/Widget/Contents/Page/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,62 @@ public function writePage()
}
}

/**
* 标记页面
*
* @access public
* @return void
*/
public function markPage()
{
$status = $this->request->get('status');
$statusList = array(
'publish' => _t('公开'),
'hidden' => _t('隐藏')
);

if (!isset($statusList[$status])) {
$this->response->goBack();
}

$pages = $this->request->filter('int')->getArray('cid');
$markCount = 0;

foreach ($pages as $page) {
// 标记插件接口
$this->pluginHandle()->mark($status, $page, $this);
$condition = $this->db->sql()->where('cid = ?', $page);

if ($this->db->query($condition->update('table.contents')->rows(array('status' => $status)))) {
// 处理草稿
$draft = $this->db->fetchRow($this->db->select('cid')
->from('table.contents')
->where('table.contents.parent = ? AND table.contents.type = ?',
$page, 'page_draft')
->limit(1));

if (!empty($draft)) {
$this->db->query($this->db->update('table.contents')->rows(array('status' => $status))
->where('cid = ?', $draft['cid']));
}

// 完成标记插件接口
$this->pluginHandle()->finishMark($status, $page, $this);

$markCount ++;
}

unset($condition);
}

/** 设置提示信息 */
$this->widget('Widget_Notice')->set($markCount > 0 ? _t('页面已经被标记为<strong>%s</strong>', $statusList[$status]) : _t('没有页面被标记'),
$deleteCount > 0 ? 'success' : 'notice');

/** 返回原网页 */
$this->response->goBack();
}

/**
* 删除页面
*
Expand Down Expand Up @@ -256,6 +312,7 @@ public function action()
$this->security->protect();
$this->on($this->request->is('do=publish') || $this->request->is('do=save'))->writePage();
$this->on($this->request->is('do=delete'))->deletePage();
$this->on($this->request->is('do=mark'))->markPage();
$this->on($this->request->is('do=deleteDraft'))->deletePageDraft();
$this->on($this->request->is('do=sort'))->sortPage();
$this->response->redirect($this->options->adminUrl);
Expand Down
4 changes: 2 additions & 2 deletions var/Widget/Contents/Post/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function ___hasSaved()
return true;
}

$savedPost = $this->db->fetchRow($this->db->select('cid', 'modified')
$savedPost = $this->db->fetchRow($this->db->select('cid', 'modified', 'status')
->from('table.contents')
->where('table.contents.parent = ? AND (table.contents.type = ? OR table.contents.type = ?)',
$this->cid, 'post_draft', 'page_draft')
Expand Down Expand Up @@ -173,7 +173,7 @@ public function execute()
$this->_countSql = clone $select;

/** 提交查询 */
$select->order('table.contents.created', Typecho_Db::SORT_DESC)
$select->order('table.contents.cid', Typecho_Db::SORT_DESC)
->page($this->_currentPage, $this->parameter->pageSize);

$this->db->fetchAll($select, array($this, 'push'));
Expand Down
106 changes: 98 additions & 8 deletions var/Widget/Contents/Post/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,12 @@ protected function getCreated()
$day = intval($this->request->day);

$created = mktime($hour, $min, $second, $month, $day, $year) - $this->options->timezone + $this->options->serverTimezone;
} else if ($this->request->is('cid')) {
} else if ($this->have() && $this->created > 0) {
//如果是修改文章
$created = $this->created;
} else if ($this->request->is('do=save')) {
// 如果是草稿而且没有任何输入则保持原状
$created = 0;
}

return $created;
Expand Down Expand Up @@ -188,13 +191,13 @@ protected function unAttach($cid)
* 获取页面偏移的URL Query
*
* @access protected
* @param integer $created 创建时间
* @param integer $cid 文章id
* @param string $status 状态
* @return string
*/
protected function getPageOffsetQuery($created, $status = NULL)
protected function getPageOffsetQuery($cid, $status = NULL)
{
return 'page=' . $this->getPageOffset('created', $created, 'post', $status,
return 'page=' . $this->getPageOffset('cid', $cid, 'post', $status,
'on' == $this->request->__typecho_all_posts ? 0 : $this->user->uid);
}

Expand Down Expand Up @@ -755,7 +758,7 @@ public function writePost()
$this->widget('Widget_Notice')->highlight($this->theId);

/** 获取页面偏移 */
$pageQuery = $this->getPageOffsetQuery($this->created);
$pageQuery = $this->getPageOffsetQuery($this->cid);

/** 页面跳转 */
$this->response->redirect(Typecho_Common::url('manage-posts.php?' . $pageQuery, $this->options->adminUrl));
Expand Down Expand Up @@ -785,6 +788,92 @@ public function writePost()
}
}

/**
* 标记文章
*
* @access public
* @return void
*/
public function markPost()
{
$status = $this->request->get('status');
$statusList = array(
'publish' => _t('公开'),
'private' => _t('私密'),
'hidden' => _t('隐藏'),
'waiting' => _t('待审核')
);

if (!isset($statusList[$status])) {
$this->response->goBack();
}

$posts = $this->request->filter('int')->getArray('cid');
$markCount = 0;

foreach ($posts as $post) {
// 标记插件接口
$this->pluginHandle()->mark($status, $post, $this);

$condition = $this->db->sql()->where('cid = ?', $post);
$postObject = $this->db->fetchObject($this->db->select('status', 'type')
->from('table.contents')->where('cid = ? AND (type = ? OR type = ?)', $post, 'post', 'post_draft'));

if ($this->isWriteable(clone $condition) &&
count((array) $postObject)) {

/** 标记状态 */
$this->db->query($condition->update('table.contents')->rows(array('status' => $status)));

// 刷新Metas
if ($postObject->type == 'post') {
$op = NULL;

if ($status == 'publish' && $postObject->status != 'publish') {
$op = '+';
} else if ($status != 'publish' && $postObject->status == 'publish') {
$op = '-';
}

if (!empty($op)) {
$metas = $this->db->fetchAll($this->db->select()->from('table.relationships')->where('cid = ?', $post));
foreach ($metas as $meta) {
$this->db->query($this->db->update('table.metas')
->expression('count', 'count ' . $op . ' 1')
->where('mid = ? AND (type = ? OR type = ?)', $meta['mid'], 'category', 'tag'));
}
}
}

// 处理草稿
$draft = $this->db->fetchRow($this->db->select('cid')
->from('table.contents')
->where('table.contents.parent = ? AND table.contents.type = ?',
$post, 'post_draft')
->limit(1));

if (!empty($draft)) {
$this->db->query($this->db->update('table.contents')->rows(array('status' => $status))
->where('cid = ?', $draft['cid']));
}

// 完成标记插件接口
$this->pluginHandle()->finishMark($status, $post, $this);

$markCount ++;
}

unset($condition);
}

/** 设置提示信息 */
$this->widget('Widget_Notice')->set($markCount > 0 ? _t('文章已经被标记为<strong>%s</strong>', $statusList[$status]) : _t('没有文章被标记'),
$deleteCount > 0 ? 'success' : 'notice');

/** 返回原网页 */
$this->response->goBack();
}

/**
* 删除文章
*
Expand All @@ -802,10 +891,10 @@ public function deletePost()

$condition = $this->db->sql()->where('cid = ?', $post);
$postObject = $this->db->fetchObject($this->db->select('status', 'type')
->from('table.contents')->where('cid = ? AND type = ?', $post, 'post'));
->from('table.contents')->where('cid = ? AND (type = ? OR type = ?)', $post, 'post', 'post_draft'));

if ($this->isWriteable($condition) &&
$postObject &&
if ($this->isWriteable(clone $condition) &&
count((array) $postObject) &&
$this->delete($condition)) {

/** 删除分类 */
Expand Down Expand Up @@ -905,6 +994,7 @@ public function action()
$this->security->protect();
$this->on($this->request->is('do=publish') || $this->request->is('do=save'))->writePost();
$this->on($this->request->is('do=delete'))->deletePost();
$this->on($this->request->is('do=mark'))->markPost();
$this->on($this->request->is('do=deleteDraft'))->deletePostDraft();

$this->response->redirect($this->options->adminUrl);
Expand Down
3 changes: 3 additions & 0 deletions var/Widget/Logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Widget_Logout extends Widget_Abstract_Users implements Widget_Interface_Do
*/
public function action()
{
// protect
$this->security->protect();

$this->user->logout();
$this->pluginHandle()->logout();
$this->response->goBack(NULL, $this->options->index);
Expand Down
Loading

0 comments on commit 0006dee

Please sign in to comment.