<?php
//公告
include("includes/custom-post-types.php");
//登陆显示头像
function qintag_get_avatar($email, $size = 48){
return get_avatar($email, $size);
}
add_action('admin_head', 'my_custom_logo');
function my_custom_logo() {
echo '
<!--
#header-logo { background-image: url('.get_bloginfo('template_directory').'/images/custom-logo.png) !important; }
-->
';
}
//禁用半角符号自动转换为全角
remove_filter('the_content', 'wptexturize');
//移除管理员工具条(或:后台也有设置项)
//remove_action('init', '_wp_admin_bar_init');
//comments link redirect WordPress评论留言链接优化-加nofollow和url重定向跳转
add_filter('get_comment_author_link', 'add_redirect_comment_link', 5);
add_filter('comment_text', 'add_redirect_comment_link', 99);
function add_redirect_comment_link($text = ''){
$text=str_replace('href="', 'href="'.get_option('home').'/?r=', $text);
$text=str_replace("href='", "href='".get_option('home')."/?r=", $text);
return $text;
}
add_action('init', 'redirect_comment_link');
function redirect_comment_link(){
$redirect = $_GET['r'];
if($redirect){
if(strpos($_SERVER['HTTP_REFERER'],get_option('home')) !== false){
header("Location: $redirect");
exit;
}
else {
header("Location: http://www.voyonix.com/");
exit;
}
}
}
//阻止 WordPress 对站内文章的 pingback http://wange.im/no-self-ping-in-wordpress.html
function no_self_ping( &$links ) {
$home = get_option( 'home' );
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, $home ) )
unset($links[$l]);
}
add_action( 'pre_ping', 'no_self_ping' );
/////////////////// 404 ///////////////////////////////////////////////
function wcs_error_currentPageURL()
{
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80")
{
$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
}
else
{
$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
}
return $pageURL;
}
class wcs_error_Walker_PageDropdownEx extends Walker
{
// returns options list with pages; option value is URL (not page ID)
var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
function start_el(&$output, $page, $depth, $args)
{
$pad = str_repeat(' ', $depth * 3);
$output .= "\t<option class=\"level-$depth\" value=\"" . get_permalink($page->ID) . "\"";
if ($page->ID == $args['selected'])
{
$output .= ' selected="selected"';
}
$output .= '>';
$title = esc_html($page->post_title);
$output .= "$pad$title";
$output .= "</option>\n";
}
}
function wcs_error_pulldown_pages()
{
// init
$walker = new wcs_error_Walker_PageDropdownEx();
$args = array();
$args['echo'] = '0';
$args['walker'] = $walker;
// build the pulldown menu
$options_html = "\t<option>(select a page)</option>";
$options_html .= wp_list_pages($args);
$select_html = '<select name="page_url" onChange="document.location.href=this.options[this.selectedIndex].value;">';
$select_html .= $options_html . '</select>';
// exit
return $select_html;
}
function wcs_error_pulldown_archives()
{
// build the pulldown menu
$options_html = "\t<option>(select a month)</option>";
$args['echo'] = '0';
$args['format'] = 'option';
$args['type'] = 'monthly';
$args['show_post_count'] = 'true';
$wp_post_count = wp_count_posts();
if ($wp_post_count->publish <= 1)
{
$select_html = '(none)';
}
else
{
$options_html .= wp_get_archives($args);
$select_html = '<select name="archive_url" onChange="document.location.href=this.options[this.selectedIndex].value;">';
$select_html .= $options_html . '</select>';
}
// exit
return $select_html;
}
function wcs_error_pulldown_categories()
{
// build the pulldown menu
$options_html = "\t<option>(select a topic)</option>";
$args['echo'] = '0';
$args['show_count'] = '1';
$args['hierarchical'] = '1';
$wp_post_count = wp_count_posts();
if ($wp_post_count->publish <= 1)
{
$select_html = '(none)';
}
else
{
$options_html .= wp_dropdown_categories($args);
$options_html = str_replace("<select name='cat' id='cat' class='postform' >", '', $options_html);
$options_html = str_replace('</select>', '', $options_html);
$select_html = '<form method="get" action="' . get_bloginfo('url') . '">';
$select_html .= '<select name="cat" id="cat" onChange="this.form.submit()">';
$select_html .= $options_html . '</select></form>';
}
// exit
return $select_html;
}
// -------- END -------------------------------------------------------
//////////////////////////////标题文字截断//////////////////////////////
function cut_str($src_str,$cut_length) {
$return_str='';
$i=0;
$n=0;
$str_length=strlen($src_str);
while (($n<$cut_length) && ($i<=$str_length)) {
$tmp_str=substr($src_str,$i,1);
$ascnum=ord($tmp_str);
if ($ascnum>=224) {
$return_str=$return_str.substr($src_str,$i,3);
$i=$i+3;
$n=$n+2;
}
elseif ($ascnum>=192) {
$return_str=$return_str.substr($src_str,$i,2);
$i=$i+2;
$n=$n+2;
}
elseif ($ascnum>=65 && $ascnum<=90) {
$return_str=$return_str.substr($src_str,$i,1);
$i=$i+1;
$n=$n+2;
}
else {
$return_str=$return_str.substr($src_str,$i,1);
$i=$i+1;
$n=$n+1;
}
}
if ($i<$str_length) {
$return_str = $return_str . '';
}
if (get_post_status() == 'private') {
$return_str = $return_str . '(private)';
}
return $return_str;
}
// -------- END -------------------------------------------------------
//////////////////////////////版权年份自动化//////////////////////////////
function comicpress_copyright() {
global $wpdb;
$copyright_dates = $wpdb->get_results("
SELECT
YEAR(min(post_date_gmt)) AS firstdate,
YEAR(max(post_date_gmt)) AS lastdate
FROM
$wpdb->posts
WHERE
post_status = 'publish'");
$output = '';
if($copyright_dates) {
$copyright = "© " . $copyright_dates[0]->firstdate;
if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
$copyright .= '-' . $copyright_dates[0]->lastdate;
}
$output = $copyright;
}
return $output;
}
// -------- END -------------------------------------------------------
//////////////////////////////图片暗箱自动添加标签属性/////////////////
add_filter('the_content', 'pirobox_gall_replace');
function pirobox_gall_replace ($content) {
global $post;
$pattern = "/<a(.*?)href=('|\")([^>]*).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>(.*?)<\/a>/i";
$replacement = '<a$1href=$2$3.$4$5 class="pirobox_gall"$6>$7</a>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
// -------- END -------------------------------------------------------
//////////////////////////////支持外链缩略图///////////////////////////
function get_featcat_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$random = mt_rand(1, 10);
echo get_bloginfo ( 'stylesheet_directory' );
echo '/images/random/'.$random.'.jpg';