-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfunctions.php
244 lines (191 loc) · 6.53 KB
/
functions.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php
// 定义语言
add_action('after_setup_theme', 'my_theme_setup');
function my_theme_setup() {
load_theme_textdomain('dpt', get_template_directory() . '/lang');
}
// 定义导航
register_nav_menus(array(
'main' => __( 'Main Nav','dpt' ),
));
// 定义侧边栏
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => __( 'Sidebar', 'dpt' ),
'id' => 'dpt',
'description' => 'Sidebar',
'class' => '',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h2>',
'after_title' => '</h2>',
)
);
// 检查更新,需要一个·服务器存放 info.json 和主题安装包。请参见 func 目录
require_once(TEMPLATEPATH . '/func/theme-update-checker.php');
$wpdaxue_update_checker = new ThemeUpdateChecker(
'StartPress',
'http://work.dimpurr.com/theme/startpress/update/info.json'
);
// 主题使用统计,如果需要。
function dpt_count() {
// Ajax 统计函数
function dpt_tjaj() { ?>
<script type="text/javascript">
jQuery(document).ready(function() {
// 修改地址为服务器的 theme_tj.php 页面。请参见 func 目录
jQuery.get("http://work.dimpurr.com/theme/theme_tj.php?theme_name=StartPress&blog_url=<?=get_bloginfo('url')?>&t=" + Math.random());
});
</script>
<?php };
// 统计筛选条件
$dpt_fitj = get_option('dpt_fitj');
$dpt_dayv = get_option('dpt_dayv');
$dpt_date = date('d');
if ($dpt_fitj == true) {
if($dpt_date == '01') {
if ($dpt_dayv != true) {
dpt_tjaj();
update_option( 'dpt_dayv', true );
};
} elseif ($dpt_date != '01') {
update_option( 'dpt_dayv', false );
};
} else {
dpt_tjaj();
update_option( 'dpt_fitj', true );
};
};
// 获取博客标题
function dpt_title( $title, $sep ) {
global $paged, $page;
if ( is_feed() )
return $title;
$title .= get_bloginfo( 'name' );
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
$title = "$title $sep $site_description";
if ( $paged >= 2 || $page >= 2 )
$title = "$title $sep " . sprintf( __( '页面 %s', 'dpt' ), max( $paged, $page ) );
return $title;
}
add_filter( 'wp_title', 'dpt_title', 10, 2 );
// 页面导航
function dpt_pagenavi () {
global $wp_query, $wp_rewrite;
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
$pagination = array(
'base' => @add_query_arg('paged','%#%'),
'format' => '',
'total' => $wp_query->max_num_pages,
'current' => $current,
'show_all' => false,
'type' => 'plain',
'end_size'=>'0',
'mid_size'=>'5',
'prev_text' => __('上一页','dpt'),
'next_text' => __('下一页','dpt')
);
if( $wp_rewrite->using_permalinks() )
$pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg('s',get_pagenum_link(1) ) ) . 'page/%#%/', 'paged');
if( !empty($wp_query->query_vars['s']) )
$pagination['add_args'] = array('s'=>get_query_var('s'));
echo paginate_links($pagination);
}
// 评论附加函数
function delete_comment_link( $id ) {
if (current_user_can('level_5')) {
echo '<a class="comment-edit-link" href="'.admin_url("comment.php?action=cdc&c=$id").'">' . __('删除','dpt') . '</a> ';
}
}
// 加载评论
if ( ! function_exists( 'dpt_comment' ) ) :
function dpt_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
?>
<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
<p><?php echo 'Pingback '; ?> <?php comment_author_link(); ?> <?php edit_comment_link( '编辑', '<span class="edit-link">', '</span>' ); ?></p>
<?php
break;
default :
global $post;
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<article id="comment-<?php comment_ID(); ?>" class="comment">
<header class="comment-meta comment-author vcard">
<?php
echo get_avatar( $comment, 44 );
printf( '<div class="cmt_meta_head"><cite class="fn">%1$s',
get_comment_author_link() );
printf( '%1$s </cite>',
( $comment->user_id === $post->post_author ) ? '<span class="cmt_meta_auth"> ' . __('作者','dpt') . '</span>' : '' );
printf( '</div><span class="cmt_meta_time"><a href="%1$s"><time datetime="%2$s">%3$s</time></a></span>',
esc_url( get_comment_link( $comment->comment_ID ) ),
get_comment_time( 'c' ),
sprintf( '%1$s %2$s' , get_comment_date(), get_comment_time() )
);
?>
</header>
<?php if ( '0' == $comment->comment_approved ) : ?>
<p class="comment-awaiting-moderation"><?php _e('审核中','dpt'); ?></p>
<?php endif; ?>
<section class="comment-content comment">
<?php comment_text(); ?>
<?php edit_comment_link( __('編輯','dpt'), '<span class="edit-link">', '</span>' ); ?>
<?php delete_comment_link(get_comment_ID()); ?>
<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __('回复','dpt'), 'after' => '', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</section>
</article>
<?php
break;
endswitch;
}
endif;
// 后台设置页面
function dpt_menu_func(){
add_theme_page(
__('设置','dpt'),
__('设置','dpt'),
'administrator',
'dpt_menu',
'dpt_config');
}
add_action('admin_menu', 'dpt_menu_func');
function dpt_config(){ dpt_thtj(); ?>
<form method="post" name="dpt_form" id="dpt_form">
<h1><?php _e('主题设置'); ?></h1>
<input type="text" size="80" name="dpt_example" id="dpt_example" placeholder="<?php _e('示例控件','dpt'); ?>" value="<?php echo get_option('dpt_example'); ?>"/>
<input type="button" name="upload_button" value="<?php _e('上传','dpt'); ?>" id="upbottom"/><br>
<input type="submit" name="option_save" value="<?php _e('保存设置','dpt'); ?>" />
<?php wp_enqueue_script('thickbox'); wp_enqueue_style('thickbox'); ?>
<script type="text/javascript">
// 导入 WordPress 媒体上传组件
jQuery(document).ready(function() {
// 选择按钮
jQuery('#upbottom').click(function() {
// 选择目标文本框
targetfield = jQuery(this).prev('#dpt_example');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
window.send_to_editor = function(html) {
imgurl = jQuery('img',html).attr('src');
jQuery(targetfield).val(imgurl);
tb_remove();
}
});
</script>
<?php wp_nonce_field('update-options'); ?>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="dpt_copy_right" />
</form>
<?php }
// 提交设置
if(isset($_POST['option_save'])){
$dpt_example = stripslashes($_POST['dpt_example']);
update_option( 'dpt_example', $dpt_example );
}
?>