";
break;
case 2:
$avatar = preg_replace("/http[s]{0,1}:\/\/(secure|www|\d).gravatar.com\/avatar\//","//cdn.v2ex.com/gravatar/",$avatar);
break;
default:
$avatar = preg_replace("/http[s]{0,1}:\/\/(secure|www|\d).gravatar.com\/avatar\//","//dn-qiniu-avatar.qbox.me/avatar/",$avatar);
}
return $avatar;
}
add_filter('get_avatar', 'gdk_switch_get_avatar');
//fancybox图片灯箱效果
function fancybox($content) {
$pattern = "/]*).(bmp|gif|jpeg|jpg|png|swf)('|\")(.*?)>(.*?)<\\/a>/i";
$replacement = '$7';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter('the_content', 'fancybox');
//邮箱SMTP设置
if (gdk_option('gdk_smtp')) {
function gdk_smtp( $phpmailer ) {
$phpmailer->FromName = gdk_option('gdk_smtp_mail'); //邮箱地址
$phpmailer->Host = gdk_option('gdk_smtp_host');//服务器地址
$phpmailer->Port = gdk_option('gdk_smtp_port'); //端口
$phpmailer->Username = gdk_option('gdk_smtp_username'); //昵称
$phpmailer->Password = gdk_option('gdk_smtp_password'); //密码
$phpmailer->From = gdk_option('gdk_smtp_mail'); //邮箱地址
$phpmailer->SMTPAuth = true;
$phpmailer->SMTPSecure = 'ssl';
$phpmailer->IsSMTP();
}
add_action('phpmailer_init', 'gdk_smtp');
}
//七牛CDN
if (gdk_option('gdk_cdn')) {
add_action('wp_loaded', 'gdk_cdn_start');
function gdk_cdn_start() {
ob_start('gdk_cdn_replace');
}
function gdk_cdn_replace($html) {
$local_host = home_url(); //博客域名
$qiniu_host = gdk_option('git_cdnurl_b'); //七牛域名
$cdn_exts = gdk_option('git_cdnurl_format'); //扩展名(使用|分隔)
$cdn_dirs = gdk_option('git_cdnurl_dir'); //目录(使用|分隔)
$cdn_dirs = str_replace('-', '\-', $cdn_dirs);
if ($cdn_dirs) {
$regex = '/' . str_replace('/', '\/', $local_host) . '\/((' . $cdn_dirs . ')\/[^\s\?\\\'\"\;\>\<]{1,}.(' . $cdn_exts . '))([\"\\\'\s\?]{1})/';
$html = preg_replace($regex, $qiniu_host . '/$1$4', $html);
} else {
$regex = '/' . str_replace('/', '\/', $local_host) . '\/([^\s\?\\\'\"\;\>\<]{1,}.(' . $cdn_exts . '))([\"\\\'\s\?]{1})/';
$html = preg_replace($regex, $qiniu_host . '/$1$3', $html);
}
return $html;
}
}
//CDN水印
if (gdk_option('git_cdn_water')) {
function cdn_water($content){
if (get_post_type() == 'post') {
$pattern = "//i";
$replacement = '
';
$content = preg_replace($pattern, $replacement, $content);
}
return $content;
}
add_filter('the_content', 'cdn_water');
}
//自动替换媒体库图片的域名
if (is_admin() && gdk_option('git_cdnurl_b') && gdk_option('git_adminqn_b')) {
function attachment_replace($text) {
$replace = array(
home_url() => gdk_option('git_cdnurl_b')
);
$text = str_replace(array_keys($replace) , $replace, $text);
return $text;
}
add_filter('wp_get_attachment_url', 'attachment_replace');
}
//一个简单可重复使用的邮件模板
function mail_temp($mail_title,$mail_cotent,$link,$link_title){
?>