[size=1em][size=1em]<?php
[size=1em]/*
[size=1em]Plugin Name: IIS Chinese Tag Permalink
[size=1em]Plugin URI: [color=rgb(255, 125, 39) !important][size=1em]
http://blog.bossma.cn/php/in-iis-wordpress-chinese-tag-permalinks-plugin/
[size=1em]Description: 使IIS下的WordPress可以在友好的固定链接(Pretty Permalink)中使用中文。
[size=1em]Author: BOSSMA.CN
[size=1em]Author URI: [color=rgb(255, 125, 39) !important][size=1em]
http://blog.bossma.cn/
[size=1em]Version: 1.4
[size=1em]*/
[size=1em]add_action('init', 'bossma_get_urf8_pathandurl');
[size=1em]add_filter('get_pagenum_link','bossma_set_utf8_pagenumlink');
[size=1em]add_action('parse_query','bossma_chinese_tag_encode');
[size=1em]// iis encode the url with GBK,but wordpress with utf-8
[size=1em]function bossma_get_urf8_pathandurl() {
[size=1em] $_SERVER['PATH_INFO']=iconv("GBK","UTF-8",$_SERVER['PATH_INFO']);
[size=1em] $_SERVER['REQUEST_URI']=iconv("GBK","UTF-8",$_SERVER['REQUEST_URI']);
[size=1em]}
[size=1em]// urlencode for chinese tag
[size=1em]// sometimes preg_match can not match the chinese correctly
[size=1em]function bossma_chinese_tag_encode($query){
[size=1em] if(isset($is_tag)&&$is_tag){
[size=1em] if($query->query_vars['tag']!=''){
[size=1em] $query->query_vars['tag']=urlencode($query->query_vars['tag']);
[size=1em] }
[size=1em] }
[size=1em]}
[size=1em]//for generate tag pagenum link
[size=1em]//use utf8 encode
[size=1em]function bossma_set_utf8_pagenumlink($result){
[size=1em] $tag_index=stripos($result,"/tag/");
[size=1em] $link_len=strlen($result);
[size=1em] if($tag_index!==false){
[size=1em] $link_base=substr($result,0,$tag_index);
[size=1em] $page_index=stripos($result,"/page/");
[size=1em] if($page_index!==false){
[size=1em] $tag_str=substr($result,$tag_index+5,$page_index-$tag_index-5);
[size=1em] $result=$link_base."/tag/".rawurlencode($tag_str).substr($result,$page_index);
[size=1em] }else{
[size=1em] $tag_str=substr($result,$tag_index+5);
[size=1em] $result=$link_base."/tag/".rawurlencode($tag_str)."/";
[size=1em] }
[size=1em] }
[size=1em] return $result;
[size=1em]}
[size=1em]?>