20
11月
0

WordPressのプラグインShadowbox JSの続き

先日の続きです。

オリジナルのShadowbox JSだとちょっとばかし以下のような不満があります。

1.WEBページのリンクタグに自動でrel属性を付与してくれない(拡張子がついていれば付与してくれるのかもしれない?)
2.リンクからWEBページを開いたときに開いたWEBページに背景色が設定されていないと背景が真っ黒になってしまい見づらくなる。
3.Youtubeの動画を開いた時に自動再生させたい(設定にAuto-Play MoviesというのがあるがYoutubeは反映されない?)

これらの不満を解決するべくちょっとばかり手を加えました。

まずshadowbox-js.phpの最後に以下を追加します。

/** * Instantiate the ShadowboxFrontend Plus */ function wp_shadowbox_link_replace($string) { $rel_attr = ' rel="shadowbox;width=1024;height=768"'; $pattern = '/<a(.*?)href=(¥'|")([^>]*)(¥'|")(.*?)>/i'; $replacement = '<a$1href=$2$3$4' . $rel_attr . '$5>'; $rel_pattern = '/¥ rel=(¥'|")(.*?)(¥'|")/i'; $dwl_pattern = '/<a(.*?)href=(¥'|")([^>]*)¥.(zip|lzh|rar|7z|arc|bz2|gz|tgz|pea|balz|tar|exe|rpm|msi|[0-9]{3}|pdf|xls|doc|ppt|vsd|mpp)(¥'|")(.*?)>/i'; $swh_pattern = '/¥ onclick=(¥'|")(.*?)(¥'|")/i'; $tube_pattern = '/<a(.*?)href=(¥'|")([^>]*)(youtube¥.com¥/(watch|v¥/))(.*?)(¥'|")(.*?)>/i'; $tube_attr = '&autoplay=1'; $tube_replacement = '<a$1href=$2$3$4$6' . $tube_attr . '$7$8>'; $gogl_pattern = '/<a(.*?)href=(¥'|")([^>]*)(video¥.google¥.([^¥/]+)¥/googleplayer.swf)(.*?)(¥'|")(.*?)>/i'; $gogl_attr = '&autoPlay=true'; $gogl_replacement = '<a$1href=$2$3$4$6' . $gogl_attr . '$7$8>'; if (preg_match_all($pattern,$string,$links)) { foreach ($links[0] as $link) { if (preg_match($tube_pattern,$link)) { $tube_link = preg_replace($tube_pattern,$tube_replacement,$link); $string = str_replace($link,$tube_link,$string); } elseif (preg_match($gogl_pattern,$link)) { $gogl_link = preg_replace($gogl_pattern,$gogl_replacement,$link); $string = str_replace($link,$gogl_link,$string); } if (!preg_match($rel_pattern,$link) && !preg_match($dwl_pattern,$link) && !preg_match($swh_pattern,$link)) { $link_replace = preg_replace($pattern,$replacement,$link); $string = str_replace($link,$link_replace,$string); } } } return $string; } add_filter('the_content', 'wp_shadowbox_link_replace',12);

ソース→ShadowboxFrontend-Plus

上記は以下の条件にマッチするとrel属性を付与します。

1.リンクタグにrel属性とonclick属性が付いていない。
2.リンクタグに特定の拡張子(ダウンロードファイル)が付いていない。

さらに、リンクタグがYoutubeもしくはGoogleビデオの場合にURLの末尾に自動再生のオプションを付与する。

この置換処理はオリジナルのShadowbox JSの置換処理が終わってから行います。

次にプラグインのページからShadowbox JSの設定ページに行き以下の設定を無効にします。

Enable Smart Loading:false

これを無効にしないと上記で置換してもShadowbox JSを有効にしたリンクが動作してくれない場合があります。

最後に「背景が真っ黒になってしまう」問題の解決方法。

shadowbox.cssの以下の箇所を「#ffffff」に修正

#sb-body,#sb-loading{background-color:#ffffff;}

これで満足のいく仕様になりました( ´ー`)b

Enjoyed reading this post?
Subscribe to the RSS feed and have all new posts delivered straight to you.
Post your comment

Powered by WP Hashcash




Celadon theme by the Themes Boutique