jetpackのプラグインが度々更新されその都度、過去記事の対応するのは面倒くさいので
根本的なJapanese AutoTagのプラグインを修正すればよいのではないかと思い
インフルエンザB型療養中にプログラムの修正を行いました。
ファイル名:japanese-autotag.phpの267行目~400行目ぐらいのアレやコレをキャスト(string)するように追加を行いました。
この事によってエラー500を出力されることもなくなりました。
Uncaught exception ‘Exception’ with message ‘Serialization of ‘SimpleXMLElement’ is not allowed’
function get_word_array( $appkey, $sentence, $filter = '9', $exwords = array(), $expattern = '' ) { $expattern = trim( $expattern ); $result = array(); $url = 'http://jlp.yahooapis.jp/MAService/V1/parse?filter=' . $filter . '&appid=' . $appkey . '&results=ma&sentence=' . urlencode($sentence); $c = @file_get_contents( $url ); if( function_exists('simplexml_load_string') ) { // PHP5 or later $xml = simplexml_load_string ( $c ); if($xml === false) { return (string)$result; } foreach($xml->ma_result->word_list->word as $w) { if( in_array($w->surface, $exwords) ) { continue; } if( $expattern != '' && @preg_match( $expattern, $w->surface) ) { continue; } $result[] = (string)$w->surface; } } else { // PHP4 $dom = domxml_open_mem ( $c ); if(!$dom) { return (string)$result; } $wa = $dom->get_elements_by_tagname('surface'); for($i=0; $i<count($wa); $i++) { $t = $wa[$i]->get_content(); if( in_array($t, $exwords) ) { continue; } if( $expattern != '' && @preg_match( $expattern, $t ) ) { continue; } $result[] = (string)$t; } } return array_values(array_unique($result)); } function get_keyphrase_array( $appkey, $sentence, $exwords = array(), $expattern = '' ) { $expattern = trim( $expattern ); $result = array(); $url = 'http://jlp.yahooapis.jp/KeyphraseService/V1/extract?' . 'appid=' . $appkey . '&results=xml&sentence=' . urlencode($sentence); $c = @file_get_contents( $url ); if( function_exists('simplexml_load_string') ) { // PHP5 or later $xml = simplexml_load_string ( $c ); if($xml === false) { return (string)$result; } foreach($xml->Result as $w) { if( in_array($w->Keyphrase, $exwords) ) { continue; } if( $expattern != '' && @preg_match( $expattern, $w->Keyphrase) ) { continue; } $result[] = (string)$w->Keyphrase; } } else { // PHP4 $dom = domxml_open_mem ( $c ); if(!$dom) { return (string)$result; } $wa = $dom->get_elements_by_tagname('Keyphrase'); for($i=0; $i<count($wa); $i++) { $t = $wa[$i]->get_content(); if( in_array($t, $exwords) ) { continue; } if( $expattern != '' && @preg_match( $expattern, $t ) ) { continue; } $result[] = (string)$t; } } return array_values(array_unique($result)); }
https://www.zip358.com/%E3%80%8Cjetpack%E3%80%8D%E3%81%A8%E3%80%8Cjapanese-autotag%E3%80%8D%E3%81%AE%E7%9B%B8%E6%80%A7%E3%81%8C%E6%82%AA%E3%81%8F%E3%81%A6%E5%85%AC%E9%96%8B%E5%8F%8A%E3%81%B3%E6%9B%B4%E6%96%B0%E5%87%BA.html