-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathshortcode.php
152 lines (133 loc) · 5.64 KB
/
shortcode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/* 注册短代码 */
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
require_once __DIR__ . '/lib/shortcode.php';
// 一般提示
function shortcode_panel_info( $atts, $content = '' ) {
return '<div class="hint hint-info"><span class="glyphicon glyphicon-info-sign hint-info-icon" aria-hidden="true"></span><span class="sr-only">info:</span>' . $content . '</div>';
}
add_shortcode( 'info' , 'shortcode_panel_info' );
// 警告提示
function shortcode_panel_warning( $atts, $content = '' ) {
return '<div class="hint hint-warning"><span class="glyphicon glyphicon-question-sign hint-warning-icon" aria-hidden="true"></span><span class="sr-only">warning:</span>' . $content . '</div>';
}
add_shortcode( 'warning' , 'shortcode_panel_warning' );
// 危险提示
function shortcode_panel_danger( $atts, $content = '' ) {
return '<div class="hint hint-danger"><span class="glyphicon glyphicon-exclamation-sign hint-danger-icon" aria-hidden="true"></span><span class="sr-only">Error:</span>' . $content . '</div>';
}
add_shortcode( 'danger' , 'shortcode_panel_danger' );
// 特别强调文字
function shortcode_panel_em( $atts, $content = '' ) {
return '<div class="wrap_em">' . $content . '</div>';
}
add_shortcode( 'em' , 'shortcode_panel_em' );
// 高亮文字
function shortcode_panel_hi( $atts, $content = '' ) {
return '<span class="wrap_hi">' . $content . '</span>';
}
add_shortcode( 'hi' , 'shortcode_panel_hi' );
// 不重要文字
function shortcode_panel_lo( $atts, $content = '' ) {
return '<div class="wrap_lo">' . $content . '</div>';
}
add_shortcode( 'lo' , 'shortcode_panel_lo' );
// 代办事项已完成
function shortcode_panel_check( $atts, $content = '' ) {
return '<input type="checkbox" checked="checked" disabled="true">';
}
add_shortcode( 'check' , 'shortcode_panel_check' );
// 代办事项未完成
function shortcode_panel_uncheck( $atts, $content = '' ) {
return '<input type="checkbox" disabled="true">';
}
add_shortcode( 'uncheck' , 'shortcode_panel_uncheck' );
// 音频播放
function shortcode_audio( $atts, $content = '' ) {
$args = shortcode_atts( array(
'src' => '',
'controls' => 'controls',
'preload' => 'metadata'
), $atts );
if (!empty($atts['autoplay'])) {
$args['autoplay'] = 'autoplay';
}
if (!empty($atts['loop'])) {
$args['loop'] = 'loop';
}
$attr_strings = array();
foreach ( $args as $k => $v ) {
$attr_strings[] = $k . '="' . htmlspecialchars( $v, ENT_QUOTES, 'UTF-8' ) . '"';
}
//$audio = sprintf( '<audio class="post-audio__source" %s controls>%s</audio>', join( ' ', $attr_strings ), $content );
//return "<div class=\"mc-audio\"><div class=\"mc-audio__bar\"></div><div class=\"mc-audio__ctl\"><div class=\"mc-audio__ctl-btn\"></div><div class=\"mc-audio__ctl-time\"></div></div>{$audio}</div>";
return sprintf( '<audio class="post-audio" %s controls >%s 您的浏览器不支持 audio 元素。</audio>', join( ' ', $attr_strings ), $content );
}
add_shortcode( 'audio' , 'shortcode_audio' );
// 视频播放
function shortcode_video( $atts, $content = '' ) {
$args = shortcode_atts( array(
'src' => '',
'poster' => '',
'controls' => 'controls',
'preload' => 'metadata'
), $atts );
if (!empty($atts['autoplay'])) {
$args['autoplay'] = 'autoplay';
}
if (!empty($atts['loop'])) {
$args['loop'] = 'loop';
}
if (!empty($atts['muted'])) {
$args['muted'] = 'muted';
}
//默认播放器大小100%
/*if (!empty($atts['width'])) {
$args['width'] = $atts['width'];
}
if (!empty($atts['height'])) {
$args['height'] = $atts['height'];
}*/
$args['width'] ='100%';
$args['height'] ='100%';
$attr_strings = array();
foreach ( $args as $k => $v ) {
$attr_strings[] = $k . '="' . htmlspecialchars( $v, ENT_QUOTES, 'UTF-8' ) . '"';
}
return sprintf( '<video id="post-video" class="post-video" %s >%s 您的浏览器不支持 video 元素。</video>', join( ' ', $attr_strings ), $content );
}
add_shortcode( 'video' , 'shortcode_video' );
//收缩框
function shortcode_shrinks( $atts, $content = '' ) {
$args = shortcode_atts( array(
'title' => '',
'style' => 'default'
), $atts );
if (!empty($atts['checked'])) {
$args['checked'] = 'active';
}
$attr_strings = array();
foreach ( $args as $k => $v ) {
$attr_strings[] = $k . '="' . htmlspecialchars( $v, ENT_QUOTES, 'UTF-8' ) . '"';
}
return '<div class="panel panel-'.$args['style'].' shrinkBox '.(isset($args['checked']) ? $args['checked'] : '').'" >
<div class="panel-heading shrinkBox-title" onclick="$(this).parent().toggleClass(\'active\');">'.$args['title'].'</div><div class="panel-body shrinkBox-content">'.$content.'</div></div>';
}
add_shortcode( 'shrinks' , 'shortcode_shrinks' );
//简易提示框
function shortcode_alert( $atts, $content = '' ) {
$closebutton='';
$args = shortcode_atts( array(
'style' => 'success'
), $atts );
if (!empty($atts['close'])) {
$args['close'] = 'alert-dismissible';
$closebutton = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>';
}
$attr_strings = array();
foreach ( $args as $k => $v ) {
$attr_strings[] = $k . '="' . htmlspecialchars( $v, ENT_QUOTES, 'UTF-8' ) . '"';
}
return '<div class="alert alert-'.$args['style'].' '.(isset($args['close']) ? $args['close'] : '').'" role="alert">'.$closebutton.$content.'</div>';
}
add_shortcode( 'alert' , 'shortcode_alert' );