首頁 > WordPress, 程式設計, 網頁設計 > WordPress 搬家後 WLW 發佈文章一堆亂碼錯誤

WordPress 搬家後 WLW 發佈文章一堆亂碼錯誤

2009年3月9日  瀏覽次數 : 2,679

很開心的將 WordPress WP 從國外的虛擬主機搬到台灣的虛擬主機後,正要發文來慶賀搬家成功,正開心的打開 WLW 長篇大論的時候,卻發生了慘不忍睹的狀況….,又得去網海捕魚了。

image 看起來好像正常但是又一堆亂碼,重點是 < 與 > 等符號都被拿光了,就像原始碼直接貼上一樣

天這黑,風這麼大,爸爸捕魚去,為什麼還不回家,出網海捕魚,當然要抓到魚才可以回家,看到這種狀況,一下子還真的不知道要怎麼搜尋,在 GOOGLE 搜尋了 "WLW WP 錯誤" , 雖然前幾頁都是一堆奇怪的資料,還好在第二頁,眼尖的我發現這篇好像有點線索的文章。

image

原來這篇文章 WLW發文…會出現一堆代碼… - WordPress討論- 免費的喘息 是由我們最敬愛的WP前輩 香腸炒魷魚 在回答其他網友的問題,不過看了半天,卻沒有個解答,心中真是苦悶,再翻到第二頁,似乎又燃起了一線生機。

image

不過好像又不是很清楚的解答,不過還好作者留下了他的部落格,循著線索走去,還好作者的部落格像大樹一樣高,裡面的資料仍保留的很完善,真是太好了,裡面可以完整解決問題呢。

image

這篇文章 [WP] 用WLW發布Wordpress亂碼解決方案 是由 新克蘭德 所分享,中間提到 WLW 之所以無法順利的將文章發布到 WP 是因為虛擬主機的 PHP 支援有些問題,主要原因是 LibXML 2 version 2.7.0 - 2.7.3 都會有這種問題產生,剛好這次搬家的 G型主機 剛好在這個範圍內,所以跟著 新克蘭德 來做修復吧。

image

以下步驟節錄於 [WP] 用WLW發布Wordpress亂碼解決方案 ,做個鏡射備份,首先我們下載以下幾個檔案並且重新修改其中的方法。

/wp-admin/import/blogger.php – function parse($xml)

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
33
//-----------------------------------------------
// /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 – function MagpieRSS ($source)

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//-----------------------------------------------
// /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 — function parse()

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
33
34
35
36
37
38
//-----------------------------------------------
// /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 發佈檔案囉,明天再將這個問題反映給 G型主機 ,畢竟 WLW 還蠻多人用的,虛擬主機可以處理掉應該就更方便了,不然 WP 每次更新一次,就要再改一次檔案喔。

image

可以用 WLW 發佈了還真開心,現在沒有 WLW 寫網誌我真的會死阿 !

Random Posts

Loading…

:: 把這篇好文推到書籤網站與更多人分享吧 ::
  • funp
  • Hemidemi
  • YahooKimo
  • Google
  • udn
  • Haohao
  • Live

目前並無相關文章

Ausir WordPress, 程式設計, 網頁設計 , , ,

  1. 2009年3月10日00:45 | #1

    哈,不好意思第一頁都沒讓你爬到結果~~ 我功力要再加強
    歡迎常來免費的喘息走走,交流喔~

  2. 2009年3月10日08:50 | #2

    哇喔~~ 香腸收到連結通知這麼快就來拜訪~

    家徒四壁 真是見笑了

  3. 2009年3月10日19:58 | #3

    現在還用不慣WLW~
    還在用DW的程式碼模式在排~~
    感覺位置好像比較好抓位點~~
    版大也分享一下如何用WLW來正確的抓版面位置~

  4. 2009年3月10日20:43 | #4

    下次我多看看你的排版方式

    這樣才可以寫出適合你的 WLW 排版方式 ^^

  5. 艾力克
    2009年3月25日16:42 | #5

    您的程式碼與新克蘭德的不同

    差異為
    //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

  6. 2009年3月25日20:23 | #6

    @艾力克

    是阿 其實就改那幾行就好
    只是我全部貼上來了

  7. 艾力克
    2009年3月27日17:28 | #7

    @Ausir

    我的意思是你打錯了

    程式碼中的”<”,”",”>” 應為 “>”,”>”
    “&”,”&” 應為 “&”,”&”

  8. 2009年3月30日20:24 | #8

    @艾力克

    我了解你的意思了~
    程式碼被轉碼轉掉了 >”<

    我在來修正一下

    謝謝

  9. 2009年6月12日11:12 | #9

    阿正老師有找到外掛~
    不用這麼麻煩~

  10. 2009年6月12日11:13 | #10

    @梅干扣肉

    講也不留下連結~
    這樣別人怎麼找 = =

  11. 2012年2月3日11:52 | #11

    新年快樂唷~

  1. 本篇文章目前尚無任何 trackbacks 和 pingbacks。