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 () { 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]); } /** 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;