比较简陋的短代码实现 & 页面模板优化
This commit is contained in:
parent
8c33e67684
commit
5c13f51fc0
|
@ -11,6 +11,9 @@ $this->need('header.php');
|
|||
<div class="col mt-5" id="main" role="main">
|
||||
<article>
|
||||
<h1 class="font-weight-bold post-title">文章归档</h1>
|
||||
<?php Typecho_Widget::widget('Widget_Stat')->to($stat);?><?php $stat->publishedPostsNum() ?> 篇文章,<?php echo allOfCharacters();?> 文字。
|
||||
<hr>
|
||||
<?php echo exContent($this->content); ?>
|
||||
<form class="form-inline mb-3" id="search" method="post" action="<?php $this->options->siteUrl(); ?>" role="search">
|
||||
<label class="sr-only" for="s">搜索文章</label>
|
||||
<div class="input-group">
|
||||
|
@ -21,10 +24,8 @@ $this->need('header.php');
|
|||
</div>
|
||||
<input type="text" id="s" name="s" class="form-control" placeholder="输入关键字搜索" />
|
||||
</div>
|
||||
<button type="submit" class="form-control btn btn-default">搜索</button>
|
||||
<button type="submit" class="form-control btn btn-secondary">搜索</button>
|
||||
</form>
|
||||
<?php Typecho_Widget::widget('Widget_Stat')->to($stat);?><?php $stat->publishedPostsNum() ?> 篇文章,<?php echo allOfCharacters();?> 文字。
|
||||
<hr>
|
||||
<?php
|
||||
$this->widget('Widget_Contents_Post_Recent', 'pageSize=10000')->to($archives);
|
||||
$year = 0; $mon = 0;
|
||||
|
|
|
@ -15,6 +15,7 @@ else $avatarUrl = '{image}';
|
|||
<article>
|
||||
<h1 class="font-weight-bold post-title">友情链接</h1>
|
||||
<hr>
|
||||
<?php echo exContent($this->content); ?>
|
||||
<div class="row">
|
||||
<?php
|
||||
Links_Plugin::output($pattern='
|
||||
|
|
|
@ -50,6 +50,88 @@ function themeFields($layout) {
|
|||
$layout->addItem($linkTo);
|
||||
}
|
||||
|
||||
function exContent($content){
|
||||
// 短代码提示框,期望用数组的办法一次性实现,但是正则表达式太难了
|
||||
// $alertIcons = array('primary' => 'fas fa-info-circle',
|
||||
// 'success' => 'fas fa-info-circle',
|
||||
// 'info' => 'fas fa-info-circle',
|
||||
// 'warning' => 'fa-exclamation-circle',
|
||||
// 'danger' => 'fas fa-skull-crossbones',
|
||||
// 'default' => 'fas fa-info-circle',
|
||||
// 'secondary' => 'fas fa-info-circle');
|
||||
|
||||
$pattern = '/\[(primary)\](.*?)\[\s*\/\1\s*\]/';
|
||||
$replacement = '
|
||||
<div class="alert alert-primary fade show shadow" role="alert">
|
||||
<span class="alert-inner--icon"><i class="fas fa-info-circle"></i></span>
|
||||
<span class="alert-inner--text">$2</span>
|
||||
</div>';
|
||||
$content = preg_replace($pattern, $replacement, $content);
|
||||
|
||||
$pattern = '/\[(default)\](.*?)\[\s*\/\1\s*\]/';
|
||||
$replacement = '
|
||||
<div class="alert alert-default fade show shadow" role="alert">
|
||||
<span class="alert-inner--icon"><i class="fas fa-info-circle"></i></span>
|
||||
<span class="alert-inner--text">$2</span>
|
||||
</div>';
|
||||
$content = preg_replace($pattern, $replacement, $content);
|
||||
|
||||
$pattern = '/\[(secondary)\](.*?)\[\s*\/\1\s*\]/';
|
||||
$replacement = '
|
||||
<div class="alert alert-secondary fade show shadow" role="alert">
|
||||
<span class="alert-inner--icon text-default"><i class="fas fa-info-circle"></i></span>
|
||||
<span class="alert-inner--text text-default">$2</span>
|
||||
</div>';
|
||||
$content = preg_replace($pattern, $replacement, $content);
|
||||
|
||||
$pattern = '/\[(success)\](.*?)\[\s*\/\1\s*\]/';
|
||||
$replacement = '
|
||||
<div class="alert alert-success fade show shadow" role="alert">
|
||||
<span class="alert-inner--icon"><i class="fas fa-info-circle"></i></span>
|
||||
<span class="alert-inner--text">$2</span>
|
||||
</div>';
|
||||
$content = preg_replace($pattern, $replacement, $content);
|
||||
|
||||
$pattern = '/\[(info)\](.*?)\[\s*\/\1\s*\]/';
|
||||
$replacement = '
|
||||
<div class="alert alert-info fade show shadow" role="alert">
|
||||
<span class="alert-inner--icon"><i class="fas fa-info-circle"></i></span>
|
||||
<span class="alert-inner--text">$2</span>
|
||||
</div>';
|
||||
$content = preg_replace($pattern, $replacement, $content);
|
||||
|
||||
$pattern = '/\[(warning)\](.*?)\[\s*\/\1\s*\]/';
|
||||
$replacement = '
|
||||
<div class="alert alert-warning fade show shadow" role="alert">
|
||||
<span class="alert-inner--icon"><i class="fas fa-exclamation-circle"></i></span>
|
||||
<span class="alert-inner--text">$2</span>
|
||||
</div>';
|
||||
$content = preg_replace($pattern, $replacement, $content);
|
||||
|
||||
$pattern = '/\[(danger)\](.*?)\[\s*\/\1\s*\]/';
|
||||
$replacement = '
|
||||
<div class="alert alert-danger fade show shadow" role="alert">
|
||||
<span class="alert-inner--icon"><i class="fas fa-skull-crossbones"></i></span>
|
||||
<span class="alert-inner--text">$2</span>
|
||||
</div>';
|
||||
$content = preg_replace($pattern, $replacement, $content);
|
||||
|
||||
// $pattern = '/\[(alert-(.*?))\](.*?)\[\s*\/\1\s*\]/';
|
||||
// $replacement = '
|
||||
// <div class="alert alert-$2 fade show shadow" role="alert">
|
||||
// <span class="alert-inner--icon"><i class="$alertIcons[$2]"></i></span>
|
||||
// <span class="alert-inner--text">$3</span>
|
||||
// </div>';
|
||||
// $content = preg_replace($pattern, $replacement, $content);
|
||||
|
||||
// 正则表达式也太难了 。・゜・(ノД`)・゜・。
|
||||
// $pattern = '/\[link (.*)\](.*)\[link\]/';
|
||||
// $replacement = '
|
||||
// <a class="btn btn-secondary" role="button" href="$1" target="_blank">$2</a>';
|
||||
// $content = preg_replace($pattern, $replacement, $content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
// 来自插件 https://github.com/elatisy/Typecho_WordsCounter
|
||||
function allOfCharacters() {
|
||||
|
|
2
page.php
2
page.php
|
@ -10,7 +10,7 @@
|
|||
<h1 class="font-weight-bold post-title"><?php $this->title() ?></h1>
|
||||
<hr>
|
||||
<div class="post-content">
|
||||
<?php $this->content(); ?>
|
||||
<?php echo exContent($this->content); ?>
|
||||
</div>
|
||||
</article>
|
||||
<?php $this->need('comments.php'); ?>
|
||||
|
|
Loading…
Reference in New Issue