今天安装Windows Live Writer并用WLW发布文章时,发现有“乱码”,具体现象是html标记中的 < 、 > 、 & 这三个符号被自动去掉了,导致在WordPress中文章排版有问题。
g了下,原来是处理xml的函数libxml2(version 2.7.0 – 2.7.3 )的bug。
解决办法有两种(详见:http://thinkland.twbbs.org/189.html )
1. 升级libxml2
2. 修改WordPress三个代码文件
//———————————————–
// /wp-admin/import/blogger.php 913-935
//———————————————–
function parse($xml) {
global $app_logging;
array_unshift($this->ns_contexts, array());
$parser = xml_parser_create_ns();
xml_set_object($parser, $this);
xml_set_element_handler($parser, “start_element”, “end_element”);
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,0);
xml_set_character_data_handler($parser, “cdata”);
xml_set_default_handler($parser, “_default”);
xml_set_start_namespace_decl_handler($parser, “start_ns”);
xml_set_end_namespace_decl_handler($parser, “end_ns”);
$contents = “”;
//xmllib 2.7.0 -2.7.3 stripping leading angle brackets bug patch
$xml =str_replace(“<”,”<”,$xml );
$xml =str_replace(“>”,”>”,$xml );
$xml =str_replace(“&”,”&”,$xml );
//end Fix
xml_parse($parser, $xml);
xml_parser_free($parser);
return true;
}
//———————————————–
// /wp-includes/rss.php 49-90
//———————————————–
function MagpieRSS ($source) {
# if PHP xml isn’t compiled in, die
#
if ( !function_exists(‘xml_parser_create’) )
trigger_error( “Failed to load PHP’s XML Extension. http://www.php.net/manual/en/ref.xml.php” );
$parser = @xml_parser_create();
if ( !is_resource($parser) )
trigger_error( “Failed to create an instance of PHP’s XML parser. http://www.php.net/manual/en/ref.xml.php”);
$this->parser = $parser;
# pass in parser, and a reference to this object
# setup handlers
#
xml_set_object( $this->parser, $this );
xml_set_element_handler($this->parser,
‘feed_start_element’, ‘feed_end_element’ );
xml_set_character_data_handler( $this->parser, ‘feed_cdata’ );
//xmllib 2.7.0 -2.7.3 stripping leading angle brackets bug patch
$source =str_replace(“<”,”<”,$source );
$source =str_replace(“>”,”>”,$source );
$source =str_replace(“&”,”&”,$source );
//end fix
$status = xml_parse( $this->parser, $source );
if (! $status ) {
$errorcode = xml_get_error_code( $this->parser );
if ( $errorcode != XML_ERROR_NONE ) {
$xml_error = xml_error_string( $errorcode );
$error_line = xml_get_current_line_number($this->parser);
$error_col = xml_get_current_column_number($this->parser);
$errormsg = “$xml_error at line $error_line, column $error_col”;
$this->error( $errormsg );
}
}
xml_parser_free( $this->parser );
$this->normalize();
}
//———————————————–
// /wp-includes/class-IXR.php 159-185
//———————————————–
function parse() {
// first remove the XML declaration
$this->message = preg_replace(‘/<\?xml(.*)?\?’.'>/’, ”, $this->message);
if (trim($this->message) == ”) {
return false;
}
$this->_parser = xml_parser_create();
// Set XML parser to take the case of tags in to account
xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);
// Set XML parser callback functions
xml_set_object($this->_parser, $this);
xml_set_element_handler($this->_parser, ‘tag_open’, ‘tag_close’);
xml_set_character_data_handler($this->_parser, ‘cdata’);
//xmllib 2.7.0 -2.7.3 stripping leading angle brackets bug patch
$this->message =str_replace(“<”,”<”,$this->message);
$this->message =str_replace(“>”,”>”,$this->message);
$this->message =str_replace(“&”,”&”,$this->message);
//end fix
if (!xml_parse($this->_parser, $this->message)) {
/* die(sprintf(‘XML error: %s at line %d’,
xml_error_string(xml_get_error_code($this->_parser)),
xml_get_current_line_number($this->_parser))); */
return false;
}
xml_parser_free($this->_parser);
// Grab the error messages, if any
if ($this->messageType == ‘fault’) {
$this->faultCode = $this->params[0]['faultCode'];
$this->faultString = $this->params[0]['faultString'];
}
return true;
}
我折腾了半天,选用第二种;
结果验证简单,有效果,现在这篇文章就是用WLW发布的。