Mar 012006
以前Stattraqプラグインを入れて、「HTTPヘッダやMETAタグでUTF-8返しても化ける」なんてことを書きましたが、解決できました。参考にさせていただいたのは以下のサイトです。
MMRT daily life » WP StatTraq 日本語版
ここからリンクされているサイトにもいろいろ情報があり、要は
- 検索文字をmb_convert_encoding()で適切な文字コードに変換する
- htmlentities()の代わりにhtmlspecialchars()を使う
ようにすればOKでした。
結局Capcha!,StatTraqプラグインで書いたindex.phpとaccess_detail.phpでのヘッダ出力の変更の他に、以下の2ファイルを変更しています。
--- wp-stattraq/reporter/query_strings.php.default Wed Mar 1 20:56:46 2006 +++ wp-stattraq/reporter/query_strings.php Thu Mar 2 03:13:35 2006 @@ -84,8 +84,9 @@ if($results) { foreach($results as $row) { + $row->search_phrase = mb_convert_encoding($row->search_phrase,get_settings('blog_charset'),"AUTO"); echo '<tr><td style="font-size: smaller;"><a href="http://search.yahoo.com/search?p=' . urlencode($row->search_phrase) . '" title="Search Yahoo!">Y</a>|<a href="http://search.msn.com/results.aspx?q=' . urlencode($row->search_phrase) . '" title="Search MSN">M</a>' . - '<td><a href="http://www.google.com/search?q=' . urlencode($row->search_phrase) . '" title="Search Google">' . htmlentities($row->search_phrase) .'</a></td><td class="right">'.$row->cnt.'</td>'; + '<td><a href="http://www.google.com/search?q=' . urlencode($row->search_phrase) . '" title="Search Google">' . htmlspecialchars($row->search_phrase) .'</a></td><td class="right">'.$row->cnt.'</td>'; } } else
--- wp-stattraq/reporter/summary.php.default Wed Mar 1 20:56:47 2006 +++ wp-stattraq/reporter/summary.php Thu Mar 2 03:12:54 2006 @@ -137,7 +137,7 @@ $blogAddress = get_settings('home') . '/' . get_settings('blogfilename') . '?p='; foreach($results as $row) { - ?><tr class="<?php echo ($i % 2 == 0 ? 'even' : 'odd' );?>"><td><?php echo ++$i;?></td><td><a href="<?php echo $blogAddress , $row->article_id;?>"> <?php echo htmlentities(stripslashes($row->post_title));?></a></td><td class="right"><?php echo number_format($row->cnt);?></td></tr> + ?><tr class="<?php echo ($i % 2 == 0 ? 'even' : 'odd' );?>"><td><?php echo ++$i;?></td><td><a href="<?php echo $blogAddress , $row->article_id;?>"> <?php echo htmlspecialchars(stripslashes($row->post_title));?></a></td><td class="right"><?php echo number_format($row->cnt);?></td></tr> <?php } } @@ -206,7 +206,7 @@ foreach($results as $row){ $short_url = substr($row->ref,0, 50); ?> - <tr class="<?php echo ($i % 2 == 0 ? 'even' : 'odd' );?>"><td><?php echo ++$i;?></td><td><a href="<?php echo htmlentities($row->ref);?>" title="<?php echo htmlentities($row->ref);?>"><?php echo $short_url;?> </a></td><td class="right"><?php echo number_format($row->cnt);?></td></tr> + <tr class="<?php echo ($i % 2 == 0 ? 'even' : 'odd' );?>"><td><?php echo ++$i;?></td><td><a href="<?php echo htmlspecialchars($row->ref);?>" title="<?php echo htmlspecialchars($row->ref);?>"><?php echo $short_url;?> </a></td><td class="right"><?php echo number_format($row->cnt);?></td></tr> <?php } } @@ -248,6 +248,7 @@ if($results){ $search_phrase = ""; foreach($results as $row){ + $row->search_phrase = mb_convert_encoding($row->search_phrase,get_settings('blog_charset'),"AUTO"); $search_phrase = urlencode($row->search_phrase); ?> <tr class="<?php echo ($i % 2 == 0 ? 'even' : 'odd' );?>"><td><?php echo ++$i;?></td><td style="font-size: smaller;"><a href="http://search.yahoo.com/search?p=<?php echo $search_phrase;?>" title="Search Yahoo!">Y</a>|<a href="http://search.msn.com/results.aspx?q=<?php echo $search_phrase ;?>" title="Search MSN">M</a></td><td><a href="http://www.google.com/search?q=<?php echo $search_phrase;?>" title="Search Google"><?php echo $row->search_phrase;?> </a></td><td class="right"><?php echo number_format($row->cnt);?></td></tr>
参考にさせていただいたサイトと違うのは、
- mb_convert_encoding()での出力文字セットを、UTF-8決めうちではなくget_settings(‘blog_charset’)で決定している
- wp-stattraq/reporter/referrer.phpでもhtmlentities()を使っているが、こちらは化けないので直してない
ことです。
Sorry, the comment form is closed at this time.