用WLW发布WordPress乱码解决方案(转自新克蘭德)

换空间之后,用WLW远程发布日志时,出现问题:html标签处理不当(<>&等三个符号显示不出来),Google了一下原因,才知道是一个处理XML的函式库libxml2出了问题。新克蘭德已经给出了解决办法,按照此办法修改相关页面后,问题解决。把办法转在这里,以后升级WP时备查。

方法简述:

修改下述三个php文件里面的一个function (注意各人文件内容不尽相同)

  • /wp-admin/import/blogger.php — function parse($xml)
  • /wp-includes/rss.php — function MagpieRSS ($source)
  • /wp-includes/class-IXR.php — function parse()

依照下面的方式修改:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// /wp-admin/import/blogger.php 913-935
//-----------------------------------------------  
                function parse($xml) {   
                <a href="http://www.php.net/global">global</a> $app_logging;
		<a href="http://www.php.net/array_unshift">array_unshift</a>($this-&gt;ns_contexts, <a href="http://www.php.net/array">array</a>());   $parser = <a href="http://www.php.net/xml_parser_create_ns">xml_parser_create_ns</a>();
		<a href="http://www.php.net/xml_set_object">xml_set_object</a>($parser, $this);
		<a href="http://www.php.net/xml_set_element_handler">xml_set_element_handler</a>($parser, "start_element", "end_element");
		<a href="http://www.php.net/xml_parser_set_option">xml_parser_set_option</a>($parser,XML_OPTION_CASE_FOLDING,0);
		<a href="http://www.php.net/xml_parser_set_option">xml_parser_set_option</a>($parser,XML_OPTION_SKIP_WHITE,0);
		<a href="http://www.php.net/xml_set_character_data_handler">xml_set_character_data_handler</a>($parser, "cdata");
		<a href="http://www.php.net/xml_set_default_handler">xml_set_default_handler</a>($parser, "_default");
		<a href="http://www.php.net/xml_set_start_namespace_decl_handler">xml_set_start_namespace_decl_handler</a>($parser, "start_ns");
		<a href="http://www.php.net/xml_set_end_namespace_decl_handler">xml_set_end_namespace_decl_handler</a>($parser, "end_ns");   $contents = "";   //xmllib 2.7.0 -2.7.3 stripping leading angle brackets bug patch
		$xml =<a href="http://www.php.net/str_replace">str_replace</a>("&amp;lt;","&amp;#60;",$xml );
		$xml =<a href="http://www.php.net/str_replace">str_replace</a>("&amp;gt;","&amp;#62;",$xml );
		$xml =<a href="http://www.php.net/str_replace">str_replace</a>("&amp;amp;","&amp;#38;",$xml );
		//end Fix   <a href="http://www.php.net/xml_parse">xml_parse</a>($parser, $xml);   <a href="http://www.php.net/xml_parser_free">xml_parser_free</a>($parser);   return true;
	}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// /wp-includes/rss.php 49-90
//-----------------------------------------------   
               function MagpieRSS ($source) {
               # if PHP xml isn't compiled in, die
		#
		if ( !<a href="http://www.php.net/function_exists">function_exists</a>('xml_parser_create') )
			<a href="http://www.php.net/trigger_error">trigger_error</a>( "Failed to load PHP's XML Extension.http://www.php.net/manual/en/ref.xml.php" );   $parser = @<a href="http://www.php.net/xml_parser_create">xml_parser_create</a>();   if ( !<a href="http://www.php.net/is_resource">is_resource</a>($parser) )
			<a href="http://www.php.net/trigger_error">trigger_error</a>( "Failed to create an instance of PHP's XML parser. http://www.php.net/manual/en/ref.xml.php");     $this-&gt;parser = $parser;   # pass in parser, and a reference to this object
		# setup handlers
		#
		<a href="http://www.php.net/xml_set_object">xml_set_object</a>( $this-&gt;parser, $this );
		<a href="http://www.php.net/xml_set_element_handler">xml_set_element_handler</a>($this-&gt;parser,
				'feed_start_element', 'feed_end_element' );   <a href="http://www.php.net/xml_set_character_data_handler">xml_set_character_data_handler</a>( $this-&gt;parser, 'feed_cdata' );   //xmllib 2.7.0 -2.7.3 stripping leading angle brackets bug patch
		$source =<a href="http://www.php.net/str_replace">str_replace</a>("&amp;lt;","&amp;#60;",$source );
		$source =<a href="http://www.php.net/str_replace">str_replace</a>("&amp;gt;","&amp;#62;",$source );
		$source =<a href="http://www.php.net/str_replace">str_replace</a>("&amp;amp;","&amp;#38;",$source );
		//end fix   $status = <a href="http://www.php.net/xml_parse">xml_parse</a>( $this-&gt;parser, $source );   if (! $status ) {
			$errorcode = <a href="http://www.php.net/xml_get_error_code">xml_get_error_code</a>( $this-&gt;parser );
			if ( $errorcode != XML_ERROR_NONE ) {
				$xml_error = <a href="http://www.php.net/xml_error_string">xml_error_string</a>( $errorcode );
				$error_line = <a href="http://www.php.net/xml_get_current_line_number">xml_get_current_line_number</a>($this-&gt;parser);
				$error_col = <a href="http://www.php.net/xml_get_current_column_number">xml_get_current_column_number</a>($this-&gt;parser);
				$errormsg = "$xml_error at line $error_line, column $error_col";   $this-&gt;error( $errormsg );
			}
		}   <a href="http://www.php.net/xml_parser_free">xml_parser_free</a>( $this-&gt;parser );   $this-&gt;normalize();
	}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// /wp-includes/class-IXR.php 159-185
//-----------------------------------------------   
        function parse() {
        // first remove the XML declaration
        $this-&gt;message = <a href="http://www.php.net/preg_replace">preg_replace</a>('/&lt;\?xml(.*)?\?'.'&gt;/', '', $this-&gt;message);
        if (<a href="http://www.php.net/trim">trim</a>($this-&gt;message) == '') {
            return false;
        }
        $this-&gt;_parser = <a href="http://www.php.net/xml_parser_create">xml_parser_create</a>();
        // Set XML parser to take the case of tags in to account
        <a href="http://www.php.net/xml_parser_set_option">xml_parser_set_option</a>($this-&gt;_parser, XML_OPTION_CASE_FOLDING, false);
        // Set XML parser callback functions
        <a href="http://www.php.net/xml_set_object">xml_set_object</a>($this-&gt;_parser, $this);
        <a href="http://www.php.net/xml_set_element_handler">xml_set_element_handler</a>($this-&gt;_parser, 'tag_open', 'tag_close');
        <a href="http://www.php.net/xml_set_character_data_handler">xml_set_character_data_handler</a>($this-&gt;_parser, 'cdata');   //xmllib 2.7.0 -2.7.3 stripping leading angle brackets bug patch
		$this-&gt;message =<a href="http://www.php.net/str_replace">str_replace</a>("&amp;lt;","&amp;#60;",$this-&gt;message);
		$this-&gt;message =<a href="http://www.php.net/str_replace">str_replace</a>("&amp;gt;","&amp;#62;",$this-&gt;message);
		$this-&gt;message =<a href="http://www.php.net/str_replace">str_replace</a>("&amp;amp;","&amp;#38;",$this-&gt;message);
		//end fix   if (!<a href="http://www.php.net/xml_parse">xml_parse</a>($this-&gt;_parser, $this-&gt;message)) {
            /* die(sprintf('XML error: %s at line %d',
                xml_error_string(xml_get_error_code($this-&gt;_parser)),
                xml_get_current_line_number($this-&gt;_parser))); */
            return false;
        }
        <a href="http://www.php.net/xml_parser_free">xml_parser_free</a>($this-&gt;_parser);
        // Grab the error messages, if any
        if ($this-&gt;messageType == 'fault') {
            $this-&gt;faultCode = $this-&gt;params[0]['faultCode'];
            $this-&gt;faultString = $this-&gt;params[0]['faultString'];
        }
        return true;
    }
分享家:Addthis中国

相关文章:

About 老豆豉

欢迎光临本站
This entry was posted in 工作相关, 站务公告 and tagged , . Bookmark the permalink.

发表评论

您的电子邮箱不会被公开。 标记为 * 的区域必须填写

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">