Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/typecho/typecho
Browse files Browse the repository at this point in the history
  • Loading branch information
fen committed Dec 11, 2013
2 parents b6bbecc + 7e06a9c commit d4b55a9
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 46 deletions.
86 changes: 55 additions & 31 deletions var/Typecho/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ class Typecho_Request
*/
private $_server = array();

/**
* _requestUri
*
* @var string
* @access private
*/
private $_requestUri = NULL;

/**
* 客户端ip地址
*
Expand Down Expand Up @@ -306,7 +314,52 @@ public function setParams($params)
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;
}

/**
Expand Down Expand Up @@ -364,36 +417,7 @@ public function getPathInfo($inputEncoding = NULL, $outputEncoding = NULL)
$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']) : '';
Expand Down
40 changes: 25 additions & 15 deletions var/Widget/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,13 +605,17 @@ private function checkPermalink()
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);
Expand Down Expand Up @@ -792,12 +796,6 @@ private function singleHandle(Typecho_Db_Query $select, &$hasPushed)
}
}

/** 设置关键词 */
$this->_keywords = implode(',', Typecho_Common::arrayFlatten($this->tags, 'name'));

/** 设置描述 */
$this->_description = $this->description;

/** 设置模板 */
if ($this->template) {
/** 应用自定义模板 */
Expand All @@ -819,6 +817,12 @@ private function singleHandle(Typecho_Db_Query $select, &$hasPushed)

/** 设置标题 */
$this->_archiveTitle = $this->title;

/** 设置关键词 */
$this->_keywords = implode(',', Typecho_Common::arrayFlatten($this->tags, 'name'));

/** 设置描述 */
$this->_description = $this->description;
}

/** 设置归档类型 */
Expand Down Expand Up @@ -875,7 +879,9 @@ private function categoryHandle(Typecho_Db_Query $select, &$hasPushed)
->where('table.contents.type = ?', 'post');

/** 设置分页 */
$this->_pageRow = $category;
$this->_pageRow = array_merge($category, array(
'slug' => urlencode($category['slug'])
));

/** 设置关键词 */
$this->_keywords = $category['name'];
Expand Down Expand Up @@ -941,7 +947,9 @@ private function tagHandle(Typecho_Db_Query $select, &$hasPushed)
->where('table.contents.type = ?', 'post');

/** 设置分页 */
$this->_pageRow = $tag;
$this->_pageRow = array_merge($tag, array(
'slug' => urlencode($tag['slug'])
));

/** 设置关键词 */
$this->_keywords = $tag['name'];
Expand Down Expand Up @@ -1556,6 +1564,8 @@ public function header($rule = NULL)
$allows = array_merge($allows, $rules);
}

$allows = $this->pluginHandle()->headerOptions($allows, $this);

$header = '';
if (!empty($allows['description'])) {
$header .= '<meta name="description" content="' . $allows['description'] . '" />' . "\n";
Expand Down Expand Up @@ -1679,7 +1689,7 @@ public function header($rule = NULL)
}

/** 插件支持 */
$header = $this->pluginHandle()->header($header, $this);
$this->pluginHandle()->header($header, $this);

/** 输出header */
echo $header;
Expand Down

0 comments on commit d4b55a9

Please sign in to comment.