给文章增加一个隐私选项,可以选择让文章不现实出来,而只能通过url访问

增加可以调整分类固定链接样式的选项
This commit is contained in:
joyqi 2013-11-17 21:22:12 +08:00
parent 50c42c5946
commit fc5afc23bc
6 changed files with 47 additions and 12 deletions

View File

@ -64,6 +64,8 @@ $stat = Typecho_Widget::widget('Widget_Stat');
<?php
if ($pages->hasSaved || 'page_draft' == $pages->type) {
echo '<em class="status">' . _t('草稿') . '</em>';
} else if ('hidden' == $pages->status) {
echo '<em class="status">' . _t('隐藏') . '</em>';
} else if ('waiting' == $pages->status) {
echo '<em class="status">' . _t('待审核') . '</em>';
} else if ('private' == $pages->status) {

View File

@ -74,6 +74,8 @@ $stat = Typecho_Widget::widget('Widget_Stat');
<?php
if ($posts->hasSaved || 'post_draft' == $posts->type) {
echo '<em class="status">' . _t('草稿') . '</em>';
} else if ('hidden' == $posts->status) {
echo '<em class="status">' . _t('隐藏') . '</em>';
} else if ('waiting' == $posts->status) {
echo '<em class="status">' . _t('待审核') . '</em>';
} else if ('private' == $posts->status) {

View File

@ -96,10 +96,11 @@ Typecho_Widget::widget('Widget_Contents_Post_Edit')->to($post);
<ul>
<?php if ($user->pass('editor', true)): ?>
<li><input id="publish" value="publish" name="visibility" type="radio"<?php if (($post->status == 'publish' && !$post->password) || !$post->status) { ?> checked="true"<?php } ?> /> <label for="publish"><?php _e('公开'); ?></label></li>
<li><input id="password" value="password" name="visibility" type="radio"<?php if ($post->password) { ?> checked="true"<?php } ?> /> <label for="password">密码保护 <input type="text" id="post-password" name="password" class="text-s" value="<?php $post->password(); ?>" size="16" /></label></li>
<li><input id="private" value="private" name="visibility" type="radio"<?php if ($post->status == 'private') { ?> checked="true"<?php } ?> /> <label for="private">私密</label></li>
<li><input id="hidden" value="hidden" name="visibility" type="radio"<?php if ($post->status == 'hidden') { ?> checked="true"<?php } ?> /> <label for="hidden"><?php _e('隐藏'); ?></label></li>
<li><input id="password" value="password" name="visibility" type="radio"<?php if ($post->password) { ?> checked="true"<?php } ?> /> <label for="password"><?php _e('密码保护'); ?> <input type="text" id="post-password" name="password" class="text-s" value="<?php $post->password(); ?>" size="16" /></label></li>
<li><input id="private" value="private" name="visibility" type="radio"<?php if ($post->status == 'private') { ?> checked="true"<?php } ?> /> <label for="private"><?php _e('私密'); ?></label></li>
<?php endif; ?>
<li><input id="waiting" value="waiting" name="visibility" type="radio"<?php if (!$user->pass('editor', true) || $post->status == 'waiting') { ?> checked="true"<?php } ?> /> <label for="waiting">待审核</label></li>
<li><input id="waiting" value="waiting" name="visibility" type="radio"<?php if (!$user->pass('editor', true) || $post->status == 'waiting') { ?> checked="true"<?php } ?> /> <label for="waiting"><?php _e('待审核'); ?></label></li>
</ul>
</section>
<?php endif; ?>

View File

@ -1202,11 +1202,22 @@ class Widget_Archive extends Widget_Abstract_Contents
/** 定时发布功能 */
if (!$selectPlugged) {
if ($this->user->hasLogin()) {
$select = $this->select()->where('table.contents.status = ? OR
(table.contents.status = ? AND table.contents.authorId = ?)', 'publish', 'private', $this->user->uid);
if ('post' == $this->parameter->type) {
if ($this->user->hasLogin()) {
$select = $this->select()->where('table.contents.status = ? OR table.contents.status = ? OR
(table.contents.status = ? AND table.contents.authorId = ?)',
'publish', 'hidden', 'private', $this->user->uid);
} else {
$select = $this->select()->where('table.contents.status = ? OR table.contents.status',
'publish', 'hidden');
}
} else {
$select = $this->select()->where('table.contents.status = ?', 'publish');
if ($this->user->hasLogin()) {
$select = $this->select()->where('table.contents.status = ? OR
(table.contents.status = ? AND table.contents.authorId = ?)', 'publish', 'private', $this->user->uid);
} else {
$select = $this->select()->where('table.contents.status = ?', 'publish');
}
}
$select->where('table.contents.created < ?', $this->options->gmtTime);
}

View File

@ -180,7 +180,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
if ($this->user->pass('editor', true)) {
if (empty($contents['visibility'])) {
$contents['status'] = 'publish';
} else if ('password' == $contents['visibility'] || !in_array($contents['visibility'], array('private', 'waiting', 'publish'))) {
} else if ('password' == $contents['visibility'] || !in_array($contents['visibility'], array('private', 'waiting', 'publish', 'hidden'))) {
if (empty($contents['password']) || 'password' != $contents['visibility']) {
$contents['password'] = '';
}
@ -253,7 +253,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
if ($this->user->pass('editor', true)) {
if (empty($contents['visibility'])) {
$contents['status'] = 'publish';
} else if ('password' == $contents['visibility'] || !in_array($contents['visibility'], array('private', 'waiting', 'publish'))) {
} else if ('password' == $contents['visibility'] || !in_array($contents['visibility'], array('private', 'waiting', 'publish', 'hidden'))) {
if (empty($contents['password']) || 'password' != $contents['visibility']) {
$contents['password'] = '';
}
@ -558,7 +558,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
public function writePost()
{
$contents = $this->request->from('password', 'allowComment',
'allowPing', 'allowFeed', 'slug', 'category', 'tags', 'text', 'do', 'visibility');
'allowPing', 'allowFeed', 'slug', 'category', 'tags', 'text', 'visibility');
$contents['title'] = $this->request->get('title', _t('未命名文档'));
$contents['created'] = $this->getCreated();

View File

@ -29,8 +29,8 @@ class Widget_Options_Permalink extends Widget_Abstract_Options implements Widget
*/
private function encodeRule($rule)
{
return str_replace(array('{cid}', '{slug}', '{category}', '{year}', '{month}', '{day}'),
array('[cid:digital]', '[slug]', '[category]', '[year:digital:4]', '[month:digital:2]', '[day:digital:2]'), $rule);
return str_replace(array('{cid}', '{slug}', '{category}', '{year}', '{month}', '{day}', '{mid}'),
array('[cid:digital]', '[slug]', '[category]', '[year:digital:4]', '[month:digital:2]', '[day:digital:2]', '[mid:digital]'), $rule);
}
/**
@ -93,6 +93,18 @@ class Widget_Options_Permalink extends Widget_Abstract_Options implements Widget
return strpos($value, '{slug}') !== false || strpos($value, '{cid}') !== false;
}
/**
* 检查categoryPattern里是否含有必要参数
*
* @param mixed $value
* @access public
* @return void
*/
public function checkCategoryPattern($value)
{
return strpos($value, '{slug}') !== false || strpos($value, '{mid}') !== false;
}
/**
* 检测是否可以rewrite
*
@ -241,6 +253,11 @@ RewriteRule . {$basePath}index.php [L]
$pagePattern->input->setAttribute('class', 'mono w-60');
$form->addInput($pagePattern->addRule(array($this, 'checkPagePattern'), _t('独立页面路径中没有包含 {cid} 或者 {slug} ')));
/** 分类页面 */
$categoryPattern = new Typecho_Widget_Helper_Form_Element_Text('categoryPattern', NULL, $this->decodeRule($this->options->routingTable['category']['url']), _t('分类路径'), _t('可用参数: <code>{mid}</code> 分类 ID、<code>{slug}</code> 分类缩略名<br />请在路径中至少包含上述的一项参数.'));
$categoryPattern->input->setAttribute('class', 'mono w-60');
$form->addInput($categoryPattern->addRule(array($this, 'checkCategoryPattern'), _t('分类路径中没有包含 {mid} 或者 {slug} ')));
/** 提交按钮 */
$submit = new Typecho_Widget_Helper_Form_Element_Submit('submit', NULL, _t('保存设置'));
$submit->input->setAttribute('class', 'primary');
@ -275,6 +292,8 @@ RewriteRule . {$basePath}index.php [L]
$routingTable = $this->options->routingTable;
$routingTable['post']['url'] = $this->request->postPattern;
$routingTable['page']['url'] = '/' . ltrim($this->encodeRule($this->request->pagePattern), '/');
$routingTable['category']['url'] = '/' . ltrim($this->encodeRule($this->request->categoryPattern), '/');
$routingTable['category_page']['url'] = rtrim($routingTable['category']['url'], '/') . '/[page:digital]';
if (isset($routingTable[0])) {
unset($routingTable[0]);