Home » days » ectoで投稿するとHTMLタグの<>が削除される

ectoで投稿するとHTMLタグの<>が削除される

▼コメントへ移動

ここ最近、ectoで投稿するとなぜだが、HTMLタグの<>が削除されてしまいます。

設定を変えたかな、Wordpressのプラグインがおかしな動作をしているのかなと思ったが、どうも違うようで、一生懸命ググったら答えが出てきました。

libxml2のバグのようです。僕はレンタルサーバーを使っていますので、バージョンを変更することができません。なので、Wordpress側で何かできることはないかと思っていたら、どうやらいくつかのファイルを修正するだけで行けるようです。

参考は、ordPress patch for problamatic libxml2 version << HooFoo Blog

変更するファイルは、

  • /wp-admin/import/blogger.php
  • /wp-includes/class-IXR.php
  • /wp-includes/rss.php

上記の3ファイルです。xml_parseの前に、ソースを追加します。

「 //xmllib 2.7.0 -2.7.2 stripping leading angle brackets bug patch 」から「 //end Fix  」の部分が追加した部分です。

/wp-admin/import/blogger.phpの913行目あたり

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.2 stripping leading angle brackets bug patch           if(LIBXML_DOTTED_VERSION == ‘2.7.0′ ||             LIBXML_DOTTED_VERSION == ‘2.7.1′ ||                LIBXML_DOTTED_VERSION == ‘2.7.2′           ){         $xml =str_replace(”<”,”<”,$xml );            $xml =str_replace(”>”,”>”,$xml );            $xml =str_replace(”&”,”&”,$xml );          }          //end Fix                           xml_parse($parser, $xml);

/wp-includes/class-IXR.phpの159行目あたり

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.2 stripping leading angle brackets bug patch          if(LIBXML_DOTTED_VERSION == '2.7.0' ||                LIBXML_DOTTED_VERSION == '2.7.1' ||                LIBXML_DOTTED_VERSION == '2.7.2'                ) {                    $this->message = str_replace('<', '<', $this->message);                $this->message = str_replace('>', '>', $this->message);                $this->message = str_replace('&', '&', $this->message);          }          // end Fixif (!xml_parse($this->_parser, $this->message)) {

/wp-includes/rss.phpの49行目あたり

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.2 stripping leading angle brackets bug patch          if(LIBXML_DOTTED_VERSION == '2.7.0' ||                LIBXML_DOTTED_VERSION == '2.7.1' ||                LIBXML_DOTTED_VERSION == '2.7.2'                ) {                    $source = str_replace('<', '<', $source);                    $source = str_replace('>', '>', $source);                    $source = str_replace('&', '&', $source);              }          // end Fix               $status = xml_parse( $this->parser, $source );

上記内容で修正しアップし、投稿を行っていますが症状は出なくなりました。これで安心してectoで投稿できます。



One Response to "ectoで投稿するとHTMLタグの<>が削除される"

  1. Pingback: mersy's lab