__('网站导航'),
'pagemenu' => __('页面导航')
));
}
}
if (function_exists('register_sidebar')){
register_sidebar(array(
'name' => '全站侧栏',
'id' => 'widget_sitesidebar',
'before_widget' => '
',
'after_widget' => '
',
'before_title' => '',
'after_title' => '
'
));
register_sidebar(array(
'name' => '首页侧栏',
'id' => 'widget_sidebar',
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
'after_title' => '
'
));
register_sidebar(array(
'name' => '分类/标签/搜索页侧栏',
'id' => 'widget_othersidebar',
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
'after_title' => '
'
));
register_sidebar(array(
'name' => '文章页侧栏',
'id' => 'widget_postsidebar',
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
'after_title' => '
'
));
register_sidebar(array(
'name' => '页面侧栏',
'id' => 'widget_pagesidebar',
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
'after_title' => '
'
));
}
function deel_breadcrumbs(){
if( !is_single() ) return false;
$categorys = get_the_category();
$category = $categorys[0];
return ' > '.get_category_parents($category->term_id, true, ' > ').''.get_the_title().'';
}
// 取消原有jQuery
function footerScript() {
if ( !is_admin() ) {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery','https://code.jquery.com/jquery-1.8.3.min.js', false,'1.0');
wp_enqueue_script( 'jquery' );
wp_register_script( 'default', get_template_directory_uri() . '/js/jquery.js', false, '1.0', dopt('d_jquerybom_b') ? true : false );
wp_enqueue_script( 'default' );
wp_register_style( 'style', get_template_directory_uri() . '/style.css',false,'1.0' );
wp_enqueue_style( 'style' );
}
}
add_action( 'wp_enqueue_scripts', 'footerScript' );
if ( ! function_exists( 'deel_paging' ) ) :
function deel_paging() {
$p = 4;
if ( is_singular() ) return;
global $wp_query, $paged;
$max_page = $wp_query->max_num_pages;
if ( $max_page == 1 ) return;
echo '';
}
function p_link( $i, $title = '' ) {
if ( $title == '' ) $title = "第 {$i} 页";
echo "{$i}";
}
endif;
function deel_strimwidth($str ,$start , $width ,$trimmarker ){
$output = preg_replace('/^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$start.'}((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$width.'}).*/s','\1',$str);
return $output.$trimmarker;
}
function dopt($e){
return stripslashes(get_option($e));
}
if ( ! function_exists( 'deel_views' ) ) :
function deel_record_visitors(){
if (is_singular())
{
global $post;
$post_ID = $post->ID;
if($post_ID)
{
$post_views = (int)get_post_meta($post_ID, 'views', true);
if(!update_post_meta($post_ID, 'views', ($post_views+1)))
{
add_post_meta($post_ID, 'views', 1, true);
}
}
}
}
add_action('wp_head', 'deel_record_visitors');
function deel_views($after=''){
global $post;
$post_ID = $post->ID;
$views = (int)get_post_meta($post_ID, 'views', true);
echo $views, $after;
}
endif;
//baidu分享
$dHasShare = false;
function deel_share(){
if( !dopt('d_bdshare_b') ) return false;
echo '分享 (0)';
global $dHasShare;
$dHasShare = true;
}
function deel_avatar_default(){
return get_bloginfo('template_directory').'/img/default.png';
}
//评论头像缓存
function deel_avatar($avatar) {
$tmp = strpos($avatar, 'http');
$g = substr($avatar, $tmp, strpos($avatar, "'", $tmp) - $tmp);
$tmp = strpos($g, 'avatar/') + 7;
$f = substr($g, $tmp, strpos($g, "?", $tmp) - $tmp);
$w = get_bloginfo('wpurl');
$e = ABSPATH .'avatar/'. $f .'.png';
$t = dopt('d_avatarDate')*24*60*60;
if ( !is_file($e) || (time() - filemtime($e)) > $t )
copy(htmlspecialchars_decode($g), $e);
else
$avatar = strtr($avatar, array($g => $w.'/avatar/'.$f.'.png'));
if ( filesize($e) < 500 )
copy(get_bloginfo('template_directory').'/img/default.png', $e);
return $avatar;
}
//关键字
function deel_keywords() {
global $s, $post;
$keywords = '';
if ( is_single() ) {
if ( get_the_tags( $post->ID ) ) {
foreach ( get_the_tags( $post->ID ) as $tag ) $keywords .= $tag->name . ', ';
}
foreach ( get_the_category( $post->ID ) as $category ) $keywords .= $category->cat_name . ', ';
$keywords = substr_replace( $keywords , '' , -2);
} elseif ( is_home () ) { $keywords = dopt('d_keywords');
} elseif ( is_tag() ) { $keywords = single_tag_title('', false);
} elseif ( is_category() ) { $keywords = single_cat_title('', false);
} elseif ( is_search() ) { $keywords = esc_html( $s, 1 );
} else { $keywords = trim( wp_title('', false) );
}
if ( $keywords ) {
echo "\n";
}
}
//网站描述
function deel_description() {
global $s, $post;
$description = '';
$blog_name = get_bloginfo('name');
if ( is_singular() ) {
if( !empty( $post->post_excerpt ) ) {
$text = $post->post_excerpt;
} else {
$text = $post->post_content;
}
$description = trim( str_replace( array( "\r\n", "\r", "\n", " ", " "), " ", str_replace( "\"", "'", strip_tags( $text ) ) ) );
if ( !( $description ) ) $description = $blog_name . "-" . trim( wp_title('', false) );
} elseif ( is_home () ) { $description = dopt('d_description'); // 首頁要自己加
} elseif ( is_tag() ) { $description = $blog_name . "'" . single_tag_title('', false) . "'";
} elseif ( is_category() ) { $description = trim(strip_tags(category_description()));
} elseif ( is_archive() ) { $description = $blog_name . "'" . trim( wp_title('', false) ) . "'";
} elseif ( is_search() ) { $description = $blog_name . ": '" . esc_html( $s, 1 ) . "' 的搜索結果";
} else { $description = $blog_name . "'" . trim( wp_title('', false) ) . "'";
}
$description = mb_substr( $description, 0, 220, 'utf-8' );
echo "\n";
}
function hide_admin_bar($flag) {
return false;
}
//最新发布加new 单位'小时'
function deel_post_new($timer='48'){
$t=( strtotime( date("Y-m-d H:i:s") )-strtotime( $post->post_date ) )/3600;
if( $t < $timer ) echo "new";
}
//修改评论表情调用路径
function deel_smilies_src ($img_src, $img, $siteurl){
return get_bloginfo('template_directory').'/img/smilies/'.$img;
}
//阻止站内文章Pingback
function deel_noself_ping( &$links ) {
$home = get_option( 'home' );
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, $home ) )
unset($links[$l]);
}
//移除自动保存
function deel_disable_autosave() {
wp_deregister_script('autosave');
}
//修改默认发信地址
function deel_res_from_email($email) {
$wp_from_email = get_option('admin_email');
return $wp_from_email;
}
function deel_res_from_name($email){
$wp_from_name = get_option('blogname');
return $wp_from_name;
}
//评论回应邮件通知
function comment_mail_notify($comment_id) {
$admin_notify = '1'; // admin 要不要收回复通知 ( '1'=要 ; '0'=不要 )
$admin_email = get_bloginfo ('admin_email'); // $admin_email 可改为你指定的 e-mail.
$comment = get_comment($comment_id);
$comment_author_email = trim($comment->comment_author_email);
$parent_id = $comment->comment_parent ? $comment->comment_parent : '';
global $wpdb;
if ($wpdb->query("Describe {$wpdb->comments} comment_mail_notify") == '')
$wpdb->query("ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;");
if (($comment_author_email != $admin_email && isset($_POST['comment_mail_notify'])) || ($comment_author_email == $admin_email && $admin_notify == '1'))
$wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notify='1' WHERE comment_ID='$comment_id'");
$notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : '0';
$spam_confirmed = $comment->comment_approved;
if ($parent_id != '' && $spam_confirmed != 'spam' && $notify == '1') {
$wp_email = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); // e-mail 发出点, no-reply 可改为可用的 e-mail.
$to = trim(get_comment($parent_id)->comment_author_email);
$subject = 'Hi,您在 [' . get_option("blogname") . '] 的留言有人回复啦!';
$message = '
' . trim(get_comment($parent_id)->comment_author) . ', 您好!
您曾在《' . get_the_title($comment->comment_post_ID) . '》的留言:
'
. trim(get_comment($parent_id)->comment_content) . '
' . trim($comment->comment_author) . ' 给您的回应:
'
. trim($comment->comment_content) . '
点击 查看回应完整內容
欢迎再次光临 ' . get_option('blogname') . '
(此邮件由系统自动发出,请勿回复.)
';
$from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
wp_mail( $to, $subject, $message, $headers );
//echo 'mail to ', $to, '
' , $subject, $message; // for testing
}
}
//自动勾选
function deel_add_checkbox() {
echo '';
}
//文章(包括feed)末尾加版权说明
function deel_copyright($content) {
if( !is_page() ){
$pid = get_the_ID();
$name = get_post_meta($pid, 'from.name', true);
$link = get_post_meta($pid, 'from.link', true);
$show = false;
if( $name ){
$show = $name;
if( $link ){
$show = ''.$show.'';
}
}else if( $link ){
$show = ''.$link.'';
}
if( $show ){
$content.= '来源:'.$show.'
';
}
$content.= '转载请注明:'.get_bloginfo('name').' » '.get_the_title().'
';
}
return $content;
}
//时间显示方式‘xx以前’
function time_ago( $type = 'commennt', $day = 7 ) {
$d = $type == 'post' ? 'get_post_time' : 'get_comment_time';
if (time() - $d('U') > 60*60*24*$day) return;
echo ' (', human_time_diff($d('U'), strtotime(current_time('mysql', 0))), '前)';
}
function timeago( $ptime ) {
$ptime = strtotime($ptime);
$etime = time() - $ptime;
if($etime < 1) return '刚刚';
$interval = array (
12 * 30 * 24 * 60 * 60 => '年前 ('.date('Y-m-d', $ptime).')',
30 * 24 * 60 * 60 => '个月前 ('.date('m-d', $ptime).')',
7 * 24 * 60 * 60 => '周前 ('.date('m-d', $ptime).')',
24 * 60 * 60 => '天前',
60 * 60 => '小时前',
60 => '分钟前',
1 => '秒前'
);
foreach ($interval as $secs => $str) {
$d = $etime / $secs;
if ($d >= 1) {
$r = round($d);
return $r . $str;
}
};
}
//评论样式
function deel_comment_list($comment, $args, $depth) {
echo 'None data.';
} else {
$i = 1;
foreach ($result as $topten) {
$postid = $topten->ID;
$title = $topten->post_title;
$commentcount = $topten->comment_count;
if ($commentcount != 0) {
$output .= '';
if( get_post_meta($postid,'bigfa_ding',true) ){
$output .=get_post_meta($postid,'bigfa_ding',true);
} else {$output .='0';}
$output .='喜欢
'.$i.''.$title.'';
$i++;
}
}
}
echo $output;
}
//在 WordPress 编辑器添加“下一页”按钮
add_filter('mce_buttons','add_next_page_button');
function add_next_page_button($mce_buttons) {
$pos = array_search('wp_more',$mce_buttons,true);
if ($pos !== false) {
$tmp_buttons = array_slice($mce_buttons, 0, $pos+1);
$tmp_buttons[] = 'wp_page';
$mce_buttons = array_merge($tmp_buttons, array_slice($mce_buttons, $pos+1));
}
return $mce_buttons;
}
//判断手机广告
function Yusi_is_mobile() {
if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
return false;
} elseif ( ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') === false) // many mobile devices (all iPh, etc.)
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {
return true;
} else {
return false;
}
}
//欲思@搜索结果排除所有页面
function search_filter_page($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts','search_filter_page');
// 更改后台字体
function Bing_admin_lettering(){
echo'';
}
add_action('admin_head', 'Bing_admin_lettering');
//欲思@添加相关文章图片文章
if ( function_exists('add_theme_support') )add_theme_support('post-thumbnails');
//输出缩略图地址
function post_thumbnail_src(){
global $post;
if( $values = get_post_custom_values("thumb") ) { //输出自定义域图片地址
$values = get_post_custom_values("thumb");
$post_thumbnail_src = $values [0];
} elseif( has_post_thumbnail() ){ //如果有特色缩略图,则输出缩略图地址
$thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'full');
$post_thumbnail_src = $thumbnail_src [0];
} else {
$post_thumbnail_src = '';
ob_start();
ob_end_clean();
$output = preg_match_all('//i', $post->post_content, $matches);
$post_thumbnail_src = $matches [1] [0]; //获取该图片 src
if(empty($post_thumbnail_src)){ //如果日志中没有图片,则显示随机图片
$random = mt_rand(1, 10);
echo get_bloginfo('template_url');
echo '/img/pic/'.$random.'.jpg';
//如果日志中没有图片,则显示默认图片
//echo '/img/thumbnail.png';
}
};
echo $post_thumbnail_src;
}
//替换google图片地址
function replace($matches){
return get_bloginfo("template_url")."/timthumb.php?src=".$matches[0]."&h=&w=".$matches['size']."&q=100&zc=1&ct=1";
}
function replace_pic($content){
$content = apply_filters( 'the_content', $content);
$content = str_replace( ']]>', ']]>', $content );
//$pattern_1 = "/(http|https)\:\/\/\S+(googleusercontent|ggpht)\S+\/s(?\d+)[\-c]*?\/\S+\.(jpg|png|gif)/i";
$pattern_1 = "/(http|https)\:\/\/\S+(googleusercontent|ggpht)\S+\/s(?\d+)[\-\S+]*?\/\S+\.(jpg|png|gif)/i";
$pattern_2 = "/(http|https)\:\/\/\S+(googleusercontent|ggpht)\S+\.(jpg|png|gif)\?imgmax=(?\d+)/i";
$content = preg_replace_callback($pattern_1, 'replace', $content);
$content = preg_replace_callback($pattern_2, 'replace', $content);
echo $content;
}
add_filter('pre_option_link_manager_enabled','__return_true');
?>