Skip to content

Commit

Permalink
✨ 支持替换附件地址.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoharWang committed Aug 23, 2018
1 parent 38e907f commit c8b48a2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
</p>
</footer>
</section>
<?php if (!empty($this->options->optimizeOptions) && in_array('EnableHighlighting', $this->options->optimizeOptions)) : ?>
<?php if (!empty($this->options->optimizeOptions) && in_array('EnableCdn', $this->options->optimizeOptions)) : ?>
<script src="https://cdn.jsdelivr.net/gh/ZoharWang/typecho-theme-Cactus@<?php echo CACTUS_VERSION; ?>/highlight.min.js"></script>
<?php else : ?>
<script src="<?php $this->options->themeUrl('highlight.js'); ?>?v=<?php echo CACTUS_VERSION; ?>"></script>
<?php endif; ?>
<script>hljs.initHighlightingOnLoad();</script>
<?php endif; ?>
<?php $this->footer(); ?>
<?php $this->options->footer(); ?>

Expand Down
18 changes: 17 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;

define('CACTUS_VERSION', '1.0.3');
define('CACTUS_VERSION', '1.0.4');

function themeConfig($form) {
$avatarUrl = new Typecho_Widget_Helper_Form_Element_Text('avatarUrl', NULL, NULL, _t('头像 URL 地址'), _t('在这里填入一个图片 URL 地址, 留空则返回 Gravatar, 不建议留空.'));
Expand All @@ -14,15 +14,31 @@ function themeConfig($form) {
$form->addInput($icpNumber);

$optimizeOptions = new Typecho_Widget_Helper_Form_Element_Checkbox('optimizeOptions', array(
'EnableHighlighting' => _t('启用代码高亮'),
'EnableCdn' => _t('使用 CDN 加速本主题内的 CSS & JS 文件')
), array(
'EnableHighlighting',
'EnableCdn'
), _t('优化选项'));
$form->addInput($optimizeOptions->multiMode());

$srcAddress = new Typecho_Widget_Helper_Form_Element_Text('srcAddress', NULL, NULL, _t('附件原始地址'), _t('例如: http(s)://www.example.com/usr/uploads/ 留空则不启用.'));
$form->addInput($srcAddress);

$cdnAddress = new Typecho_Widget_Helper_Form_Element_Text('cdnAddress', NULL, NULL, _t('附件 CDN 地址'), _t('例如: http(s)://cdn.example.com/usr/uploads/ 留空则不启用.'));
$form->addInput($cdnAddress);

$header = new Typecho_Widget_Helper_Form_Element_Textarea('header', NULL, NULL, _t('自定义 Header'), _t('在这里填入自定义 Header, 如自定义 CSS 样式等.'));
$form->addInput($header);

$footer = new Typecho_Widget_Helper_Form_Element_Textarea('footer', NULL, NULL, _t('自定义 Footer'), _t('在这里填入自定义 Footer, 如自定义 JavaScript 脚本等.'));
$form->addInput($footer);
}

function parseContent($obj) {
$options = Typecho_Widget::widget('Widget_Options');
if (!empty($options->srcAddress) && !empty($options->cdnAddress)) {
$obj->content = str_ireplace($options->srcAddress, $options->cdnAddress, $obj->content);
}
echo trim($obj->content);
}
4 changes: 4 additions & 0 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
<?php endif; ?>
<?php if (!empty($this->options->optimizeOptions) && in_array('EnableCdn', $this->options->optimizeOptions)) : ?>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/ZoharWang/typecho-theme-Cactus@<?php echo CACTUS_VERSION; ?>/style.min.css">
<?php if (!empty($this->options->optimizeOptions) && in_array('EnableHighlighting', $this->options->optimizeOptions)) : ?>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/ZoharWang/typecho-theme-Cactus@<?php echo CACTUS_VERSION; ?>/highlight.min.css">
<?php endif; ?>
<?php else : ?>
<link rel="stylesheet" href="<?php $this->options->themeUrl('style.css'); ?>?v=<?php echo CACTUS_VERSION; ?>">
<?php if (!empty($this->options->optimizeOptions) && in_array('EnableHighlighting', $this->options->optimizeOptions)) : ?>
<link rel="stylesheet" href="<?php $this->options->themeUrl('highlight.css'); ?>?v=<?php echo CACTUS_VERSION; ?>">
<?php endif; ?>
<?php endif; ?>
<?php $this->header(); ?>
<?php $this->options->header(); ?>
Expand Down
2 changes: 1 addition & 1 deletion page.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<h2 class="headline"><?php $this->date('F j, Y'); ?></h2>
</header>
<section id="post-body">
<?php $this->content(); ?>
<?php parseContent($this); ?>

</section>
</article>
Expand Down
2 changes: 1 addition & 1 deletion post.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</h2>
</header>
<section id="post-body">
<?php $this->content(); ?>
<?php parseContent($this); ?>

</section>
</article>
Expand Down

0 comments on commit c8b48a2

Please sign in to comment.