3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
Windows Live Writer(WLW)這套部落格的文章編寫軟體想必很多人都有在用,不過丫湯在以前剛開始用美國主機的時候,都沒有什麼問題,自從搬回台灣主機時就出問題了,發佈文章後會變成亂碼,一開始有找到問題所在,但一直沒去修改,都是在WLW編碼後再將原始碼貼去Wordpress後台發文,最近又換了新主機,因此想說來修改一下,順便也做個筆記如果你的問題跟我有一樣的問題的話,也參考一下吧。 就像上圖一樣,發文之後一些Html的代碼都被轉換掉了,這是因為主機sever上的LibXML的版本過新所造成的,但由於我們不可能要求主機商降LibXML的版本,應該說主機商也不可能會降,因此我們必需配合LibXML的版本來修改Wordpress的源碼,或許再等Wordpress下次更新或者WLW更新就會解決也說不定。 修改Wordpress源碼: 我們總共要修改以下三個檔案(以下修改法僅於wordpress 2.71版本測試OK): /wp-admin/import/blogger.php /wp-includes/rss.php /wp-includes/class-IXR.php 首先打開blogger.php,找到function parse($xml) 也就是圖上這一段語法,大約是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 =str_replace(">",">",$xml ); $xml =str_replace("&","&",$xml ); //end Fix xml_parse($parser, $xml); xml_parser_free($parser); return true; } 接下來修改Rss.php,找到function MagpieRSS ($source) { 下圖這段語法,大約是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 =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(); } 最後再打開class-IXR.php,找到function parse() { 也就是下圖這段語法,約159行~185行 取代為以下語法: function parse() { // first remove the XML declaration $this->message = preg_replace('//', '', $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("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; } 修改完之後再將檔案上傳覆蓋原本的檔案就可以囉,如果你有更好的方法記得也跟丫湯說一下哦~如果在修改之後依然無法使用的話,可能是某個外掛造成的,建議您可以先將全部的外掛停用,再發文試試,沒有問題的話,再一個個開啟,看看到底是哪一個外掛讓你卡到陰囉~

本文由steachs提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦