Skip to content

Commit c8b48a2

Browse files
committed
✨ 支持替换附件地址.
1 parent 38e907f commit c8b48a2

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

footer.php

+2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
</p>
1111
</footer>
1212
</section>
13+
<?php if (!empty($this->options->optimizeOptions) && in_array('EnableHighlighting', $this->options->optimizeOptions)) : ?>
1314
<?php if (!empty($this->options->optimizeOptions) && in_array('EnableCdn', $this->options->optimizeOptions)) : ?>
1415
<script src="https://cdn.jsdelivr.net/gh/ZoharWang/typecho-theme-Cactus@<?php echo CACTUS_VERSION; ?>/highlight.min.js"></script>
1516
<?php else : ?>
1617
<script src="<?php $this->options->themeUrl('highlight.js'); ?>?v=<?php echo CACTUS_VERSION; ?>"></script>
1718
<?php endif; ?>
1819
<script>hljs.initHighlightingOnLoad();</script>
20+
<?php endif; ?>
1921
<?php $this->footer(); ?>
2022
<?php $this->options->footer(); ?>
2123

functions.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
33

4-
define('CACTUS_VERSION', '1.0.3');
4+
define('CACTUS_VERSION', '1.0.4');
55

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

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

25+
$srcAddress = new Typecho_Widget_Helper_Form_Element_Text('srcAddress', NULL, NULL, _t('附件原始地址'), _t('例如: http(s)://www.example.com/usr/uploads/ 留空则不启用.'));
26+
$form->addInput($srcAddress);
27+
28+
$cdnAddress = new Typecho_Widget_Helper_Form_Element_Text('cdnAddress', NULL, NULL, _t('附件 CDN 地址'), _t('例如: http(s)://cdn.example.com/usr/uploads/ 留空则不启用.'));
29+
$form->addInput($cdnAddress);
30+
2331
$header = new Typecho_Widget_Helper_Form_Element_Textarea('header', NULL, NULL, _t('自定义 Header'), _t('在这里填入自定义 Header, 如自定义 CSS 样式等.'));
2432
$form->addInput($header);
2533

2634
$footer = new Typecho_Widget_Helper_Form_Element_Textarea('footer', NULL, NULL, _t('自定义 Footer'), _t('在这里填入自定义 Footer, 如自定义 JavaScript 脚本等.'));
2735
$form->addInput($footer);
2836
}
37+
38+
function parseContent($obj) {
39+
$options = Typecho_Widget::widget('Widget_Options');
40+
if (!empty($options->srcAddress) && !empty($options->cdnAddress)) {
41+
$obj->content = str_ireplace($options->srcAddress, $options->cdnAddress, $obj->content);
42+
}
43+
echo trim($obj->content);
44+
}

header.php

+4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717
<?php endif; ?>
1818
<?php if (!empty($this->options->optimizeOptions) && in_array('EnableCdn', $this->options->optimizeOptions)) : ?>
1919
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/ZoharWang/typecho-theme-Cactus@<?php echo CACTUS_VERSION; ?>/style.min.css">
20+
<?php if (!empty($this->options->optimizeOptions) && in_array('EnableHighlighting', $this->options->optimizeOptions)) : ?>
2021
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/ZoharWang/typecho-theme-Cactus@<?php echo CACTUS_VERSION; ?>/highlight.min.css">
22+
<?php endif; ?>
2123
<?php else : ?>
2224
<link rel="stylesheet" href="<?php $this->options->themeUrl('style.css'); ?>?v=<?php echo CACTUS_VERSION; ?>">
25+
<?php if (!empty($this->options->optimizeOptions) && in_array('EnableHighlighting', $this->options->optimizeOptions)) : ?>
2326
<link rel="stylesheet" href="<?php $this->options->themeUrl('highlight.css'); ?>?v=<?php echo CACTUS_VERSION; ?>">
27+
<?php endif; ?>
2428
<?php endif; ?>
2529
<?php $this->header(); ?>
2630
<?php $this->options->header(); ?>

page.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<h2 class="headline"><?php $this->date('F j, Y'); ?></h2>
77
</header>
88
<section id="post-body">
9-
<?php $this->content(); ?>
9+
<?php parseContent($this); ?>
1010

1111
</section>
1212
</article>

post.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</h2>
1212
</header>
1313
<section id="post-body">
14-
<?php $this->content(); ?>
14+
<?php parseContent($this); ?>
1515

1616
</section>
1717
</article>

0 commit comments

Comments
 (0)