wordpressのtopsy retweet buttonプラグインのタイトルの文字化け

twitterなんて全然触らないけど、このブログも雰囲気だけはそれっぽくしたいということで、retweetボタンなんてものを設置してますが、どうもretweetを押すと文字化けしてるらしい。
検索して2〜3つみてみると、topsyのスクリプトの引数に渡せ、とか、topsy retweet buttonプラグインだとがんばったけど無理だったとか書いてるので僕もあきらめました。

でも、直接テンプレートに書いてもいいけど、プラグインの方が楽ですよね。導入楽だし、テンプレートを変えても使えるしね。

topsy/topsy.php
[php]
function topsy_generate_retweet_button($size = ‘small’, $css_opts = ”) {
$which_class = ‘data’;
if (! in_array(‘topsy_filter_the_content’, topsy_fn_backtrace())) {
$which_class = ‘shortcode’;
}
$hostname = ‘button’;
$url = urlencode(get_permalink());
if (preg_match("/[?&]topsybeta=1/", $_SERVER[‘REQUEST_URI’], $match)) {
$hostname = ‘beta.button’;
$url .= $match[0];
}
global $post;
$short_url = get_post_meta($post->ID, ‘topsy_short_url’, true);
if ($short_url) $short_url = "", "shorturl": "$short_url";
$title = str_replace(‘"’, ‘"’, $post->post_title);

$hashtags = get_option(‘topsy_auto_hashtags’);
if ($hashtags == ‘post’ && get_the_tags()) {
foreach (get_the_tags() as $tag) {
$title .= ‘ #’ . $tag->name;
}
} elseif ($hashtags != ‘none’ && $hashtags != ‘post’) {
foreach (preg_split("/[, ]+/", $hashtags) as $tag) {
$title .= " #$tag";
}
}
$title = urlencode($title); /* これ追加すると文字化けしないよ */

$ret = str_replace(‘&’, ‘&’, "{ "url": "$url$short_url"") . ", "style": "$size", "title": "$title" }";
$coded = rawurlencode($ret);
if (get_option(‘topsy_use_preloader’) == ‘on’) {
$ret = str_replace(‘"’, ‘\\"’, $ret);
$inner_script = "<script type="text/javascript">topsyWidgetPreload($ret);</script>";
} else {
$inner_script = ”;
}
if ($css_opts) {
$css_opts = trim($css_opts);
if (substr($css_opts, -1) != ‘;’) $css_opts .= ‘;’;
$css_opts .= ‘ ‘;
}
$theme = topsy_simplify(get_option(‘topsy_button_theme’));
return "<div class="topsy_widget_$which_class topsy_theme_$theme" style="${css_opts}background: url(data:,$coded);">$inner_script</div>n";
}
[/php]