Add new constants for dynamic site url

fix #630
This commit is contained in:
joyqi 2017-10-29 16:11:37 +08:00
parent 9884a2fc76
commit 01d3badc9b

View File

@ -370,9 +370,19 @@ class Widget_Options extends Typecho_Widget
$this->stack[] = &$this->row;
/** 动态获取根目录 */
$this->rootUrl = defined('__TYPECHO_ROOT_URL__') ? __TYPECHO_ROOT_URL__ : $this->request->getRequestRoot();
if (defined('__TYPECHO_ADMIN__')) {
/** 识别在admin目录中的情况 */
$adminDir = '/' . trim(defined('__TYPECHO_ADMIN_DIR__') ? __TYPECHO_ADMIN_DIR__ : '/admin/', '/');
$this->rootUrl = substr($this->rootUrl, 0, - strlen($adminDir));
}
/** 初始化站点信息 */
if (defined('__TYPECHO_SITE_URL__')) {
$this->siteUrl = __TYPECHO_SITE_URL__;
} else if (defined('__TYPECHO_DYNAMIC_SITE_URL__') && __TYPECHO_DYNAMIC_SITE_URL__) {
$this->siteUrl = $this->rootUrl;
}
$this->originalSiteUrl = $this->siteUrl;
@ -382,14 +392,6 @@ class Widget_Options extends Typecho_Widget
/** 动态判断皮肤目录 */
$this->theme = is_dir($this->themeFile($this->theme)) ? $this->theme : 'default';
/** 动态获取根目录 */
$this->rootUrl = $this->request->getRequestRoot();
if (defined('__TYPECHO_ADMIN__')) {
/** 识别在admin目录中的情况 */
$adminDir = '/' . trim(defined('__TYPECHO_ADMIN_DIR__') ? __TYPECHO_ADMIN_DIR__ : '/admin/', '/');
$this->rootUrl = substr($this->rootUrl, 0, - strlen($adminDir));
}
/** 增加对SSL连接的支持 */
if ($this->request->isSecure() && 0 === strpos($this->siteUrl, 'http://')) {
$this->siteUrl = substr_replace($this->siteUrl, 'https', 0, 4);
@ -451,7 +453,7 @@ class Widget_Options extends Typecho_Widget
* @access public
* @param string $path 子路径
* @param string $theme 模版名称
* @return void
* @return string
*/
public function themeUrl($path = NULL, $theme = NULL)
{