add __TYPECHO_SITE_URL__ constant

This commit is contained in:
祁宁 2014-04-21 12:34:38 +08:00
parent bb1642c95f
commit e927f47566
5 changed files with 45 additions and 28 deletions

View File

@ -11,7 +11,9 @@ include 'menu.php';
<div class="col-mb-12">
<ul class="typecho-option-tabs fix-tabs clearfix">
<li class="current"><a href="<?php $options->adminUrl('themes.php'); ?>"><?php _e('可以使用的外观'); ?></a></li>
<?php if (!defined('__TYPECHO_THEME_WRITEABLE__') || __TYPECHO_THEME_WRITEABLE__): ?>
<li><a href="<?php $options->adminUrl('theme-editor.php'); ?>"><?php _e('编辑当前外观'); ?></a></li>
<?php endif; ?>
<?php if (Widget_Themes_Config::isExists()): ?>
<li><a href="<?php $options->adminUrl('options-theme.php'); ?>"><?php _e('设置外观'); ?></a></li>
<?php endif; ?>
@ -43,7 +45,9 @@ include 'menu.php';
<p><?php echo nl2br($themes->description); ?></p>
<?php if($options->theme != $themes->name): ?>
<p>
<?php if (!defined('__TYPECHO_THEME_WRITEABLE__') || __TYPECHO_THEME_WRITEABLE__): ?>
<a class="edit" href="<?php $options->adminUrl('theme-editor.php?theme=' . $themes->name); ?>"><?php _e('编辑'); ?></a> &nbsp;
<?php endif; ?>
<a class="activate" href="<?php $security->index('/action/themes-edit?change=' . $themes->name); ?>"><?php _e('启用'); ?></a>
</p>
<?php endif; ?>

View File

@ -145,7 +145,8 @@ class Widget_Options extends Typecho_Widget
*/
protected function ___index()
{
return $this->rewrite ? $this->rootUrl : Typecho_Common::url('index.php', $this->rootUrl);
return ($this->rewrite || (defined('__TYPECHO_REWRITE__') && __TYPECHO_REWRITE__))
? $this->rootUrl : Typecho_Common::url('index.php', $this->rootUrl);
}
/**
@ -357,6 +358,10 @@ class Widget_Options extends Typecho_Widget
$this->stack[] = &$this->row;
/** 初始化站点信息 */
if (defined('__TYPECHO_SITE_URL__')) {
$this->siteUrl = __TYPECHO_SITE_URL__;
}
$this->originalSiteUrl = $this->siteUrl;
$this->siteUrl = Typecho_Common::url(NULL, $this->siteUrl);
$this->plugins = unserialize($this->plugins);

View File

@ -40,13 +40,14 @@ class Widget_Options_General extends Widget_Abstract_Options implements Widget_I
->addRule('xssCheck', _t('请不要在站点名称中使用特殊字符')));
/** 站点地址 */
$siteUrl = new Typecho_Widget_Helper_Form_Element_Text('siteUrl', NULL, $this->options->originalSiteUrl, _t('站点地址'), _t('站点地址主要用于生成内容的永久链接.')
. ($this->options->originalSiteUrl == $this->options->rootUrl ?
'' : '</p><p class="message notice mono">' . _t('当前地址 <strong>%s</strong> 与上述设定值不一致',
if (!defined('__TYPECHO_SITE_URL__')) {
$siteUrl = new Typecho_Widget_Helper_Form_Element_Text('siteUrl', NULL, $this->options->originalSiteUrl, _t('站点地址'), _t('站点地址主要用于生成内容的永久链接.') . ($this->options->originalSiteUrl == $this->options->rootUrl ?
'' : '</p><p class="message notice mono">' . _t('当前地址 <strong>%s</strong> 与上述设定值不一致',
$this->options->rootUrl)));
$siteUrl->input->setAttribute('class', 'w-100 mono');
$form->addInput($siteUrl->addRule('required', _t('请填写站点地址'))
->addRule('url', _t('请填写一个合法的URL地址')));
$siteUrl->input->setAttribute('class', 'w-100 mono');
$form->addInput($siteUrl->addRule('required', _t('请填写站点地址'))
->addRule('url', _t('请填写一个合法的URL地址')));
}
/** 站点描述 */
$description = new Typecho_Widget_Helper_Form_Element_Text('description', NULL, $this->options->description, _t('站点描述'), _t('站点描述将显示在网页代码的头部.'));
@ -160,9 +161,12 @@ class Widget_Options_General extends Widget_Abstract_Options implements Widget_I
$this->response->goBack();
}
$settings = $this->request->from('title', 'siteUrl', 'description', 'keywords', 'allowRegister', 'timezone');
$settings = $this->request->from('title','description', 'keywords', 'allowRegister', 'timezone');
$settings['attachmentTypes'] = $this->request->getArray('attachmentTypes');
$settings['siteUrl'] = rtrim($settings['siteUrl'], '/');
if (!defined('__TYPECHO_SITE_URL__')) {
$settings['siteUrl'] = rtrim($this->request->siteUrl, '/');
}
$attachmentTypes = array();
if ($this->isEnableByCheckbox($settings['attachmentTypes'], '@image@')) {

View File

@ -205,29 +205,32 @@ RewriteRule . {$basePath}index.php [L]
$form = new Typecho_Widget_Helper_Form($this->security->getRootUrl('index.php/action/options-permalink'),
Typecho_Widget_Helper_Form::POST_METHOD);
/** 是否使用地址重写功能 */
$rewrite = new Typecho_Widget_Helper_Form_Element_Radio('rewrite', array('0' => _t('不启用'), '1' => _t('启用')),
$this->options->rewrite, _t('是否使用地址重写功能'), _t('地址重写即 rewrite 功能是某些服务器软件提供的优化内部连接的功能.') . '<br />'
. _t('打开此功能可以让你的链接看上去完全是静态地址.'));
if (!defined('__TYPECHO_REWRITE__')) {
/** 是否使用地址重写功能 */
$rewrite = new Typecho_Widget_Helper_Form_Element_Radio('rewrite', array('0' => _t('不启用'), '1' => _t('启用')),
$this->options->rewrite, _t('是否使用地址重写功能'), _t('地址重写即 rewrite 功能是某些服务器软件提供的优化内部连接的功能.') . '<br />'
. _t('打开此功能可以让你的链接看上去完全是静态地址.'));
// disable rewrite check when rewrite opened
if (!$this->options->rewrite && !$this->request->is('enableRewriteAnyway=1')) {
$errorStr = _t('重写功能检测失败, 请检查你的服务器设置');
// disable rewrite check when rewrite opened
if (!$this->options->rewrite && !$this->request->is('enableRewriteAnyway=1')) {
$errorStr = _t('重写功能检测失败, 请检查你的服务器设置');
/** 如果是apache服务器, 可能存在无法写入.htaccess文件的现象 */
if (((isset($_SERVER['SERVER_SOFTWARE']) && false !== strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'apache'))
|| function_exists('apache_get_version')) && !file_exists(__TYPECHO_ROOT_DIR__ . '/.htaccess')
&& !is_writeable(__TYPECHO_ROOT_DIR__)) {
$errorStr .= '<br /><strong>' . _t('我们检测到你使用了apache服务器, 但是程序无法在根目录创建.htaccess文件, 这可能是产生这个错误的原因.')
. _t('请调整你的目录权限, 或者手动创建一个.htaccess文件.') . '</strong>';
/** 如果是apache服务器, 可能存在无法写入.htaccess文件的现象 */
if (((isset($_SERVER['SERVER_SOFTWARE']) && false !== strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'apache'))
|| function_exists('apache_get_version')) && !file_exists(__TYPECHO_ROOT_DIR__ . '/.htaccess')
&& !is_writeable(__TYPECHO_ROOT_DIR__)) {
$errorStr .= '<br /><strong>' . _t('我们检测到你使用了apache服务器, 但是程序无法在根目录创建.htaccess文件, 这可能是产生这个错误的原因.')
. _t('请调整你的目录权限, 或者手动创建一个.htaccess文件.') . '</strong>';
}
$errorStr .= '<br /><input type="checkbox" name="enableRewriteAnyway" id="enableRewriteAnyway" value="1" />'
. ' <label for="enableRewriteAnyway">' . _t('如果你仍然想启用此功能, 请勾选这里') . '</label>';
$rewrite->addRule(array($this, 'checkRewrite'), $errorStr);
}
$errorStr .= '<br /><input type="checkbox" name="enableRewriteAnyway" id="enableRewriteAnyway" value="1" />'
. ' <label for="enableRewriteAnyway">' . _t('如果你仍然想启用此功能, 请勾选这里') . '</label>';
$rewrite->addRule(array($this, 'checkRewrite'), $errorStr);
$form->addInput($rewrite);
}
$form->addInput($rewrite);
$patterns = array('/archives/[cid:digital]/' => _t('默认风格') . ' <code>/archives/{cid}/</code>',
'/archives/[slug].html' => _t('wordpress风格') . ' <code>/archives/{slug}.html</code>',
'/[year:digital:4]/[month:digital:2]/[day:digital:2]/[slug].html' => _t('按日期归档') . ' <code>/archives/{year}/{month}/{day}/{slug}.html</code>',
@ -296,7 +299,7 @@ RewriteRule . {$basePath}index.php [L]
$this->request->postPattern = '/' . ltrim($this->encodeRule($this->request->customPattern), '/');
}
$settings = $this->request->from('rewrite');
$settings = defined('__TYPECHO_REWRITE__') ? array() : $this->request->from('rewrite');
if (isset($this->request->postPattern) && isset($this->request->pagePattern)) {
$routingTable = $this->options->routingTable;
$routingTable['post']['url'] = $this->request->postPattern;

View File

@ -51,7 +51,8 @@ class Widget_Themes_Files extends Typecho_Widget
$this->_currentTheme = $this->request->get('theme', $this->widget('Widget_Options')->theme);
if (preg_match("/^([_0-9a-z-\.\ ])+$/i", $this->_currentTheme)
&& is_dir($dir = __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' . $this->_currentTheme)) {
&& is_dir($dir = __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' . $this->_currentTheme)
&& (!defined('__TYPECHO_THEME_WRITEABLE__') || __TYPECHO_THEME_WRITEABLE__)) {
$files = glob($dir . '/*.{php,PHP,js,JS,css,CSS,vbs,VBS}', GLOB_BRACE);
$this->_currentFile = $this->request->get('file', 'index.php');