From 5b39b0ff48eb122c80998a5b0c9e205355c4c474 Mon Sep 17 00:00:00 2001 From: joyqi Date: Fri, 6 Dec 2013 20:19:02 +0800 Subject: [PATCH 1/3] fixed #106 --- var/Widget/Archive.php | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/var/Widget/Archive.php b/var/Widget/Archive.php index 3fc68d71..c5c4d3ae 100644 --- a/var/Widget/Archive.php +++ b/var/Widget/Archive.php @@ -78,7 +78,7 @@ class Widget_Archive extends Widget_Abstract_Contents * @access private * @var array */ - private $_pageRow; + private $_pageRow = array(); /** * 聚合器对象 @@ -592,16 +592,29 @@ class Widget_Archive extends Widget_Abstract_Contents * @access private * @return void */ - private function checkRewrite() + private function checkPermalink() { - $requestUrl = $this->request->getRequestUrl(); - $index = Typecho_Common::url('index.php', $this->options->siteUrl); + $type = $this->parameter->type; + + if ('index' == $type // 首页跳转不用处理 + || $this->_makeSinglePageAsFrontPage // 自定义首页不处理 + || $this->_invokeByFeed // 不要处理feed + || $this->_invokeFromOutside) { // 不要处理外部调用 + return; + } - if ($this->options->rewrite && - 0 === strpos($requestUrl, $index)) { - $path = substr($requestUrl, strlen($index)); - $url = Typecho_Common::url($path, $this->options->index); - $this->response->redirect($url, true); + $value = array( + 'page' => $this->_currentPage + ); + $value = array_merge($this->_archiveSingle ? $this->row + : $this->_pageRow, $value); + + $path = Typecho_Router::url($type, $value); + $permalink = Typecho_Common::url($path, $this->options->index); + $requestUrl = $this->request->getRequestUrl(); + + if ($permalink != $requestUrl) { + $this->response->redirect($permalink, true); } } @@ -1221,9 +1234,6 @@ class Widget_Archive extends Widget_Abstract_Contents } } - /** 处理Rewrite跳转 */ - $this->checkRewrite(); - /** 自定义首页功能 */ $frontPage = $this->options->frontPage; if (!$this->_invokeByFeed && ('index' == $this->parameter->type || 'index_page' == $this->parameter->type)) { @@ -1301,6 +1311,9 @@ class Widget_Archive extends Widget_Abstract_Contents } } + /** 处理静态链接跳转 */ + $this->checkPermalink(); + /** 如果已经提前压入则直接返回 */ if ($hasPushed) { return; From 6db990f7a46077f01d9d9faa05a6b841f34319f7 Mon Sep 17 00:00:00 2001 From: joyqi Date: Fri, 6 Dec 2013 20:42:25 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=AD=A3validate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- var/Typecho/Validate.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/var/Typecho/Validate.php b/var/Typecho/Validate.php index fb1e094f..f186c0d9 100644 --- a/var/Typecho/Validate.php +++ b/var/Typecho/Validate.php @@ -186,7 +186,8 @@ class Typecho_Validate */ public function enum($str, array $params) { - return in_array($str, $params); + $keys = array_flip($params); + return isset($keys[$str]); } /** From be5f4f6e8beae9138c510d7b5ef821a92e33410f Mon Sep 17 00:00:00 2001 From: joyqi Date: Fri, 6 Dec 2013 20:51:13 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/media.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/admin/media.php b/admin/media.php index 7c9f1570..399127df 100644 --- a/admin/media.php +++ b/admin/media.php @@ -83,8 +83,11 @@ $(document).ready(function() { } function fileUploadComplete (id, url, data) { - var img = $('.typecho-attachment-photo').get(0); - img.src = 'attachment->url(); ?>?' + Math.random(); + var img = $('.typecho-attachment-photo'); + + if (img.length > 0) { + img.get(0).src = 'attachment->url(); ?>?' + Math.random(); + } $('#' + id).html(''.replace('%s', data.title)) .effect('highlight', 1000, function () {