Merge pull request #3 from typecho/master

同步最新
This commit is contained in:
shingchi 2013-11-17 19:22:13 -08:00
commit 7d806e0150
13 changed files with 197 additions and 76 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

@ -19,5 +19,19 @@ include 'menu.php';
include 'copyright.php';
include 'common-js.php';
include 'form-js.php';
?>
<script>
$('#frontPage-recent,#frontPage-page,#frontPage-file').change(function () {
var t = $(this);
if (t.prop('checked')) {
if ('frontPage-recent' == t.attr('id')) {
$('.front-archive').addClass('hidden');
} else {
$('.front-archive').insertAfter(t.parent()).removeClass('hidden');
}
}
});
</script>
<?php
include 'footer.php';
?>

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

@ -279,7 +279,7 @@ list($prefixVersion, $suffixVersion) = explode('/', $currentVersion);
$installDb->query($installDb->insert('table.options')->rows(array('name' => 'rewrite', 'user' => 0, 'value' => 0)));
$installDb->query($installDb->insert('table.options')->rows(array('name' => 'frontPage', 'user' => 0, 'value' => 'recent')));
$installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsRequireMail', 'user' => 0, 'value' => 1)));
$installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsWhitelist', 'user' => 0, 'value' => 1)));
$installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsWhitelist', 'user' => 0, 'value' => 0)));
$installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsRequireURL', 'user' => 0, 'value' => 0)));
$installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsRequireModeration', 'user' => 0, 'value' => 0)));
$installDb->query($installDb->insert('table.options')->rows(array('name' => 'plugins', 'user' => 0, 'value' => 'a:0:{}')));
@ -315,7 +315,7 @@ list($prefixVersion, $suffixVersion) = explode('/', $currentVersion);
$installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsShowCommentOnly', 'user' => 0, 'value' => 0)));
$installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsAvatar', 'user' => 0, 'value' => 1)));
$installDb->query($installDb->insert('table.options')->rows(array('name' => 'commentsAvatarRating', 'user' => 0, 'value' => 'G')));
$installDb->query($installDb->insert('table.options')->rows(array('name' => 'routingTable', 'user' => 0, 'value' => 'a:23:{s:5:"index";a:3:{s:3:"url";s:1:"/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:2:"do";a:3:{s:3:"url";s:22:"/action/[action:alpha]";s:6:"widget";s:9:"Widget_Do";s:6:"action";s:6:"action";}s:4:"post";a:3:{s:3:"url";s:24:"/archives/[cid:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:10:"attachment";a:3:{s:3:"url";s:26:"/attachment/[cid:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:8:"category";a:3:{s:3:"url";s:17:"/category/[slug]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:3:"tag";a:3:{s:3:"url";s:12:"/tag/[slug]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:6:"author";a:3:{s:3:"url";s:22:"/author/[uid:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:6:"search";a:3:{s:3:"url";s:19:"/search/[keywords]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:10:"index_page";a:3:{s:3:"url";s:21:"/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:13:"category_page";a:3:{s:3:"url";s:32:"/category/[slug]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:8:"tag_page";a:3:{s:3:"url";s:27:"/tag/[slug]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:11:"author_page";a:3:{s:3:"url";s:37:"/author/[uid:digital]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:11:"search_page";a:3:{s:3:"url";s:34:"/search/[keywords]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:12:"archive_year";a:3:{s:3:"url";s:18:"/[year:digital:4]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:13:"archive_month";a:3:{s:3:"url";s:36:"/[year:digital:4]/[month:digital:2]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:11:"archive_day";a:3:{s:3:"url";s:52:"/[year:digital:4]/[month:digital:2]/[day:digital:2]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:17:"archive_year_page";a:3:{s:3:"url";s:38:"/[year:digital:4]/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:18:"archive_month_page";a:3:{s:3:"url";s:56:"/[year:digital:4]/[month:digital:2]/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:16:"archive_day_page";a:3:{s:3:"url";s:72:"/[year:digital:4]/[month:digital:2]/[day:digital:2]/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:12:"comment_page";a:3:{s:3:"url";s:53:"[permalink:string]/comment-page-[commentPage:digital]";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:4:"feed";a:3:{s:3:"url";s:20:"/feed[feed:string:0]";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:4:"feed";}s:8:"feedback";a:3:{s:3:"url";s:31:"[permalink:string]/[type:alpha]";s:6:"widget";s:15:"Widget_Feedback";s:6:"action";s:6:"action";}s:4:"page";a:3:{s:3:"url";s:12:"/[slug].html";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}}')));
$installDb->query($installDb->insert('table.options')->rows(array('name' => 'routingTable', 'user' => 0, 'value' => 'a:25:{s:5:"index";a:3:{s:3:"url";s:1:"/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:7:"archive";a:3:{s:3:"url";s:6:"/blog/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:2:"do";a:3:{s:3:"url";s:22:"/action/[action:alpha]";s:6:"widget";s:9:"Widget_Do";s:6:"action";s:6:"action";}s:4:"post";a:3:{s:3:"url";s:24:"/archives/[cid:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:10:"attachment";a:3:{s:3:"url";s:26:"/attachment/[cid:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:8:"category";a:3:{s:3:"url";s:17:"/category/[slug]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:3:"tag";a:3:{s:3:"url";s:12:"/tag/[slug]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:6:"author";a:3:{s:3:"url";s:22:"/author/[uid:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:6:"search";a:3:{s:3:"url";s:19:"/search/[keywords]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:10:"index_page";a:3:{s:3:"url";s:21:"/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:12:"archive_page";a:3:{s:3:"url";s:26:"/blog/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:13:"category_page";a:3:{s:3:"url";s:32:"/category/[slug]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:8:"tag_page";a:3:{s:3:"url";s:27:"/tag/[slug]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:11:"author_page";a:3:{s:3:"url";s:37:"/author/[uid:digital]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:11:"search_page";a:3:{s:3:"url";s:34:"/search/[keywords]/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:12:"archive_year";a:3:{s:3:"url";s:18:"/[year:digital:4]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:13:"archive_month";a:3:{s:3:"url";s:36:"/[year:digital:4]/[month:digital:2]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:11:"archive_day";a:3:{s:3:"url";s:52:"/[year:digital:4]/[month:digital:2]/[day:digital:2]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:17:"archive_year_page";a:3:{s:3:"url";s:38:"/[year:digital:4]/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:18:"archive_month_page";a:3:{s:3:"url";s:56:"/[year:digital:4]/[month:digital:2]/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:16:"archive_day_page";a:3:{s:3:"url";s:72:"/[year:digital:4]/[month:digital:2]/[day:digital:2]/page/[page:digital]/";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:12:"comment_page";a:3:{s:3:"url";s:53:"[permalink:string]/comment-page-[commentPage:digital]";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}s:4:"feed";a:3:{s:3:"url";s:20:"/feed[feed:string:0]";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:4:"feed";}s:8:"feedback";a:3:{s:3:"url";s:31:"[permalink:string]/[type:alpha]";s:6:"widget";s:15:"Widget_Feedback";s:6:"action";s:6:"action";}s:4:"page";a:3:{s:3:"url";s:12:"/[slug].html";s:6:"widget";s:14:"Widget_Archive";s:6:"action";s:6:"render";}}')));
$installDb->query($installDb->insert('table.options')->rows(array('name' => 'actionTable', 'user' => 0, 'value' => 'a:0:{}')));
$installDb->query($installDb->insert('table.options')->rows(array('name' => 'panelTable', 'user' => 0, 'value' => 'a:0:{}')));
$installDb->query($installDb->insert('table.options')->rows(array('name' => 'attachmentTypes', 'user' => 0, 'value' => '@image@')));

View File

@ -94,20 +94,33 @@ class Helper
* @param string $url 路由路径
* @param string $widget 组件名称
* @param string $action 组件动作
* @param string $after 在某个路由后面
* @return void
*/
public static function addRoute($name, $url, $widget, $action = NULL)
public static function addRoute($name, $url, $widget, $action = NULL, $after = NULL)
{
$routingTable = self::options()->routingTable;
if (isset($routingTable[0])) {
unset($routingTable[0]);
}
$routingTable[$name] = array(
$pos = 0;
foreach ($routingTable as $key => $val) {
$pos ++;
if ($key == $after) {
break;
}
}
$pre = array_slice($routingTable, 0, $pos);
$next = array_slice($routingTable, $pos);
$routingTable = array_merge($pre, array($name => array(
'url' => $url,
'widget' => $widget,
'action' => $action
);
)), $next);
self::options()->routingTable = $routingTable;
$db = Typecho_Db::get();

View File

@ -20,7 +20,7 @@
class Typecho_Common
{
/** 程序版本 */
const VERSION = '0.9/13.10.28';
const VERSION = '0.9/13.11.17';
/**
* 缓存的包含路径

View File

@ -987,5 +987,22 @@ Typecho_Date::setTimezoneOffset($options->timezone);
))
->where('type = ? AND status = ?', 'page', 'draft'));
}
/**
* v0_9r13_11_17
*
* @param mixed $db
* @param mixed $options
* @static
* @access public
* @return void
*/
public static function v0_9r13_11_17($db, $options)
{
Helper::addRoute('archive', '/blog/', 'Widget_Archive', 'render', 'index');
Helper::addRoute('archive_page', '/blog/[page:digital]/', 'Widget_Archive', 'render', 'index_page');
$db->query($db->insert('table.options')
->rows(array('name' => 'frontArchive', 'user' => 0, 'value' => 0)));
}
}

View File

@ -1165,65 +1165,11 @@ class Widget_Archive extends Widget_Abstract_Contents
return;
}
/** 处理搜索结果跳转 */
if (isset($this->request->s)) {
$filterKeywords = $this->request->filter('search')->s;
/** 跳转到搜索页 */
if (NULL != $filterKeywords) {
$this->response->redirect(Typecho_Router::url('search',
array('keywords' => urlencode($filterKeywords)), $this->options->index));
}
}
/** 自定义首页功能 */
if (!$this->_invokeByFeed && ('index' == $this->parameter->type || 'index_page' == $this->parameter->type)) {
$frontPage = $this->options->frontPage;
//显示某个页面
if (0 === strpos($frontPage, 'page:')) {
// 对某些变量做hack
$this->request->setParam('cid', intval(substr($frontPage, 5)));
$this->parameter->type = 'page';
$this->_makeSinglePageAsFrontPage = true;
} else if (0 === strpos($frontPage, 'file:')) {
// 显示某个文件
$this->setThemeFile(substr($frontPage, 5));
return;
}
}
/** 初始化分页变量 */
$this->_currentPage = isset($this->request->page) ? $this->request->page : 1;
$hasPushed = false;
/** select初始化 */
$select = $this->pluginHandle()->trigger($selectPlugged)->select($this);
/** 定时发布功能 */
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);
} else {
$select = $this->select()->where('table.contents.status = ?', 'publish');
}
$select->where('table.contents.created < ?', $this->options->gmtTime);
}
/** handle初始化 */
$this->pluginHandle()->handleInit($this, $select);
/** 初始化其它变量 */
$this->_feedUrl = $this->options->feedUrl;
$this->_feedRssUrl = $this->options->feedRssUrl;
$this->_feedAtomUrl = $this->options->feedAtomUrl;
$this->_keywords = $this->options->keywords;
$this->_description = $this->options->description;
$handles = array(
'index' => 'indexHandle',
'index_page' => 'indexHandle',
'archive' => 'error404Handle',
'archive_page' => 'error404Handle',
404 => 'error404Handle',
'page' => 'singleHandle',
'post' => 'singleHandle',
@ -1245,6 +1191,78 @@ class Widget_Archive extends Widget_Abstract_Contents
'search_page' => 'searchHandle'
);
/** 处理搜索结果跳转 */
if (isset($this->request->s)) {
$filterKeywords = $this->request->filter('search')->s;
/** 跳转到搜索页 */
if (NULL != $filterKeywords) {
$this->response->redirect(Typecho_Router::url('search',
array('keywords' => urlencode($filterKeywords)), $this->options->index));
}
}
/** 自定义首页功能 */
$frontPage = $this->options->frontPage;
if (!$this->_invokeByFeed && ('index' == $this->parameter->type || 'index_page' == $this->parameter->type)) {
//显示某个页面
if (0 === strpos($frontPage, 'page:')) {
// 对某些变量做hack
$this->request->setParam('cid', intval(substr($frontPage, 5)));
$this->parameter->type = 'page';
$this->_makeSinglePageAsFrontPage = true;
} else if (0 === strpos($frontPage, 'file:')) {
// 显示某个文件
$this->setThemeFile(substr($frontPage, 5));
return;
}
}
if ('recent' != $frontPage && $this->options->frontArchive) {
$handles['archive'] = 'indexHandle';
$handles['archive_page'] = 'indexHandle';
$this->_archiveType = 'front';
}
/** 初始化分页变量 */
$this->_currentPage = isset($this->request->page) ? $this->request->page : 1;
$hasPushed = false;
/** select初始化 */
$select = $this->pluginHandle()->trigger($selectPlugged)->select($this);
/** 定时发布功能 */
if (!$selectPlugged) {
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 {
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);
}
/** handle初始化 */
$this->pluginHandle()->handleInit($this, $select);
/** 初始化其它变量 */
$this->_feedUrl = $this->options->feedUrl;
$this->_feedRssUrl = $this->options->feedRssUrl;
$this->_feedAtomUrl = $this->options->feedAtomUrl;
$this->_keywords = $this->options->keywords;
$this->_description = $this->options->description;
if (isset($handles[$this->parameter->type])) {
$handle = $handles[$this->parameter->type];
$this->{$handle}($select, $hasPushed);
@ -1765,7 +1783,7 @@ var TypechoComment = {
}
//~ 最后找归档路径, 比如 archive.php 或者 single.php
if (!$validated && 'index' != $this->_archiveType) {
if (!$validated && 'index' != $this->_archiveType && 'front' != $this->_archiveType) {
$themeFile = $this->_archiveSingle ? 'single.php' : 'archive.php';
if (file_exists($this->_themeDir . $themeFile)) {
$this->_themeFile = $themeFile;

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

@ -140,7 +140,7 @@ class Widget_Menu extends Typecho_Widget
array(
array(_t('基本'), _t('基本设置'), 'options-general.php', 'administrator'),
array(_t('评论'), _t('评论设置'), 'options-discussion.php', 'administrator'),
array(_t('文章'), _t('阅读设置'), 'options-reading.php', 'administrator'),
array(_t('阅读'), _t('阅读设置'), 'options-reading.php', 'administrator'),
array(_t('永久链接'), _t('永久链接设置'), 'options-permalink.php', 'administrator'),
));

View File

@ -27,10 +27,10 @@ class Widget_Options_Permalink extends Widget_Abstract_Options implements Widget
* @param string $rule 待编码的路径
* @return string
*/
private function encodeRule($rule)
protected 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);
}
/**
@ -40,7 +40,7 @@ class Widget_Options_Permalink extends Widget_Abstract_Options implements Widget
* @param string $rule 待解码的路径
* @return string
*/
private function decodeRule($rule)
protected function decodeRule($rule)
{
return preg_replace("/\[([_a-z0-9-]+)[^\]]*\]/i", "{\\1}", $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]);

View File

@ -18,7 +18,7 @@
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
* @license GNU General Public License 2.0
*/
class Widget_Options_Reading extends Widget_Abstract_Options implements Widget_Interface_Do
class Widget_Options_Reading extends Widget_Options_Permalink
{
/**
* 输出表单结构
@ -49,6 +49,14 @@ class Widget_Options_Reading extends Widget_Abstract_Options implements Widget_I
'recent' => _t('显示最新发布的文章')
);
$frontPattern = '</label></span><span class="multiline front-archive%class%">'
. '<input type="checkbox" id="frontArchive" name="frontArchive" value="1"'
. ($this->options->frontArchive && 'recent' != $frontPageType ? ' checked' : '') .' />
<label for="frontArchive">' . _t('同时将文章列表页路径更改为 %s',
'<input type="text" name="archivePattern" class="w-20 mono" value="'
. htmlspecialchars($this->decodeRule($this->options->routingTable['archive']['url'])) . '" />')
. '</label>';
// 页面列表
$pages = $this->db->fetchAll($this->db->select('cid', 'title')
->from('table.contents')->where('type = ?', 'page')
@ -67,6 +75,7 @@ class Widget_Options_Reading extends Widget_Abstract_Options implements Widget_I
}
$pagesSelect .= '</select>';
$frontPageOptions['page'] = _t('使用 %s 页面作为首页', '</label>' . $pagesSelect . '<label for="frontPage-frontPagePage">');
$selectedFrontPageType = 'page';
}
// 自定义文件列表
@ -92,6 +101,17 @@ class Widget_Options_Reading extends Widget_Abstract_Options implements Widget_I
$frontPageOptions['file'] = _t('直接调用 %s 模板文件',
'</label><select name="frontPageFile" id="frontPage-frontPageFile">'
. $filesSelect . '</select><label for="frontPage-frontPageFile">');
$selectedFrontPageType = 'file';
}
if (isset($frontPageOptions[$frontPageType]) && 'recent' != $frontPageType && isset($selectedFrontPageType)) {
$selectedFrontPageType = $frontPageType;
$frontPattern = str_replace('%class%', '', $frontPattern);
}
if (isset($selectedFrontPageType)) {
$frontPattern = str_replace('%class%', ' hidden', $frontPattern);
$frontPageOptions[$selectedFrontPageType] .= $frontPattern;
}
$frontPage = new Typecho_Widget_Helper_Form_Element_Radio('frontPage', $frontPageOptions,
@ -137,7 +157,7 @@ class Widget_Options_Reading extends Widget_Abstract_Options implements Widget_I
$this->response->goBack();
}
$settings = $this->request->from('postDateFormat', 'frontPage', 'pageSize', 'postsListSize', 'feedFullText');
$settings = $this->request->from('postDateFormat', 'frontPage', 'frontArchive', 'pageSize', 'postsListSize', 'feedFullText');
if ('page' == $settings['frontPage'] && isset($this->request->frontPagePage) &&
$this->db->fetchRow($this->db->select('cid')
@ -157,6 +177,21 @@ class Widget_Options_Reading extends Widget_Abstract_Options implements Widget_I
$settings['frontPage'] = 'recent';
}
if ('recent' != $settings['frontPage']) {
$settings['frontArchive'] = empty($settings['frontArchive']) ? 0 : 1;
if ($settings['frontArchive']) {
$routingTable = $this->options->routingTable;
$routingTable['archive']['url'] = '/' . ltrim($this->encodeRule($this->request->archivePattern), '/');
$routingTable['archive_page']['url'] = rtrim($routingTable['archive']['url'], '/') . '/page/[page:digital]/';
if (isset($routingTable[0])) {
unset($routingTable[0]);
}
$settings['routingTable'] = serialize($routingTable);
}
}
foreach ($settings as $name => $value) {
$this->update(array('value' => $value), $this->db->sql()->where('name = ?', $name));
}