1
0
mirror of https://github.com/typecho/typecho.git synced 2025-03-20 09:59:41 +01:00
This commit is contained in:
fen 2013-12-11 23:52:04 +08:00
commit d4b55a9b87
2 changed files with 80 additions and 46 deletions
var

@ -39,6 +39,14 @@ class Typecho_Request
*/
private $_server = array();
/**
* _requestUri
*
* @var string
* @access private
*/
private $_requestUri = NULL;
/**
* 客户端ip地址
*
@ -306,7 +314,52 @@ class Typecho_Request
public function getRequestUrl()
{
$scheme = $this->isSecure() ? 'https' : 'http';
return $scheme . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
return $scheme . '://' . $_SERVER['HTTP_HOST'] . $this->getRequestUri();
}
/**
* 获取请求地址
*
* @access public
* @return string
*/
public function getRequestUri()
{
if (!empty($this->_requestUri)) {
return $this->_requestUri;
}
//处理requestUri
$requestUri = '/';
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch
$requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
} elseif (
// IIS7 with URL Rewrite: make sure we get the unencoded url (double slash problem)
isset($_SERVER['IIS_WasUrlRewritten'])
&& $_SERVER['IIS_WasUrlRewritten'] == '1'
&& isset($_SERVER['UNENCODED_URL'])
&& $_SERVER['UNENCODED_URL'] != ''
) {
$requestUri = $_SERVER['UNENCODED_URL'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$requestUri = $_SERVER['REQUEST_URI'];
if (isset($_SERVER['HTTP_HOST']) && strstr($requestUri, $_SERVER['HTTP_HOST'])) {
$parts = @parse_url($requestUri);
if (false !== $parts) {
$requestUri = (empty($parts['path']) ? '' : $parts['path'])
. ((empty($parts['query'])) ? '' : '?' . $parts['query']);
}
}
} elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP as CGI
$requestUri = $_SERVER['ORIG_PATH_INFO'];
if (!empty($_SERVER['QUERY_STRING'])) {
$requestUri .= '?' . $_SERVER['QUERY_STRING'];
}
}
return $this->_requestUri = $requestUri;
}
/**
@ -364,36 +417,7 @@ class Typecho_Request
$pathInfo = NULL;
//处理requestUri
$requestUri = NULL;
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch
$requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
} elseif (
// IIS7 with URL Rewrite: make sure we get the unencoded url (double slash problem)
isset($_SERVER['IIS_WasUrlRewritten'])
&& $_SERVER['IIS_WasUrlRewritten'] == '1'
&& isset($_SERVER['UNENCODED_URL'])
&& $_SERVER['UNENCODED_URL'] != ''
) {
$requestUri = $_SERVER['UNENCODED_URL'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$requestUri = $_SERVER['REQUEST_URI'];
if (isset($_SERVER['HTTP_HOST']) && strstr($requestUri, $_SERVER['HTTP_HOST'])) {
$parts = @parse_url($requestUri);
if (false !== $parts) {
$requestUri = (empty($parts['path']) ? '' : $parts['path'])
. ((empty($parts['query'])) ? '' : '?' . $parts['query']);
}
}
} elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP as CGI
$requestUri = $_SERVER['ORIG_PATH_INFO'];
if (!empty($_SERVER['QUERY_STRING'])) {
$requestUri .= '?' . $_SERVER['QUERY_STRING'];
}
} else {
return $this->_pathInfo = '/';
}
$requestUri = $this->getRequestUri();
//处理baseUrl
$filename = (isset($_SERVER['SCRIPT_FILENAME'])) ? basename($_SERVER['SCRIPT_FILENAME']) : '';

@ -605,13 +605,17 @@ class Widget_Archive extends Widget_Abstract_Contents
return;
}
$value = array(
'page' => $this->_currentPage
);
$value = array_merge($this->_archiveSingle ? $this->row : $this->_pageRow, $value);
if ($this->_archiveSingle) {
$permalink = $this->permalink;
} else {
$value = array_merge($this->_pageRow, array(
'page' => $this->_currentPage
));
$path = Typecho_Router::url($type, $value);
$permalink = Typecho_Common::url($path, $this->options->index);
}
$path = Typecho_Router::url($type, $value);
$permalink = Typecho_Common::url($path, $this->options->index);
$requestUrl = $this->request->getRequestUrl();
$src = parse_url($permalink);
@ -792,12 +796,6 @@ class Widget_Archive extends Widget_Abstract_Contents
}
}
/** 设置关键词 */
$this->_keywords = implode(',', Typecho_Common::arrayFlatten($this->tags, 'name'));
/** 设置描述 */
$this->_description = $this->description;
/** 设置模板 */
if ($this->template) {
/** 应用自定义模板 */
@ -819,6 +817,12 @@ class Widget_Archive extends Widget_Abstract_Contents
/** 设置标题 */
$this->_archiveTitle = $this->title;
/** 设置关键词 */
$this->_keywords = implode(',', Typecho_Common::arrayFlatten($this->tags, 'name'));
/** 设置描述 */
$this->_description = $this->description;
}
/** 设置归档类型 */
@ -875,7 +879,9 @@ class Widget_Archive extends Widget_Abstract_Contents
->where('table.contents.type = ?', 'post');
/** 设置分页 */
$this->_pageRow = $category;
$this->_pageRow = array_merge($category, array(
'slug' => urlencode($category['slug'])
));
/** 设置关键词 */
$this->_keywords = $category['name'];
@ -941,7 +947,9 @@ class Widget_Archive extends Widget_Abstract_Contents
->where('table.contents.type = ?', 'post');
/** 设置分页 */
$this->_pageRow = $tag;
$this->_pageRow = array_merge($tag, array(
'slug' => urlencode($tag['slug'])
));
/** 设置关键词 */
$this->_keywords = $tag['name'];
@ -1556,6 +1564,8 @@ class Widget_Archive extends Widget_Abstract_Contents
$allows = array_merge($allows, $rules);
}
$allows = $this->pluginHandle()->headerOptions($allows, $this);
$header = '';
if (!empty($allows['description'])) {
$header .= '<meta name="description" content="' . $allows['description'] . '" />' . "\n";
@ -1679,7 +1689,7 @@ var TypechoComment = {
}
/** 插件支持 */
$header = $this->pluginHandle()->header($header, $this);
$this->pluginHandle()->header($header, $this);
/** 输出header */
echo $header;