Hikiで添付されたFLVファイルを表示するプラグイン
概要
添付されたFLVファイルも表示できるようになったよ。
調査
Hikiにはファイル添付プラグイン(attach.rb)が標準でくっついてくるので、ページに添付されたFLVファイルもattach.rbと同じような書式で表示できると良いなあと思い、attach.rbのソースコードを読むこと30主観分。
実装
と言うことでこんな感じのソースコードになりました。
- 以下のコードを
$HIKI_HOME/plugin/flv.rb
として保存する。 - Flash Video Playerをダウンロードしてきて、
$HIKI_HOME/flvplayer.swf
として保存する。 - attach.rbプラグインを有効化する。
- ページにFLVファイルを添付する。
- ページ中で
{{attach_flv_anchor(file_name, width, height)}}
と記述する。
def flv( flv, width=425, height=350 )
<<EOF
<object type="application/x-shockwave-flash" width="#{width}" height="#{height}" wmode="transparent" data="flvplayer.swf?file=#{flv}">
<param name="movie" value="flvplayer.swf?file=#{flv}" />
<param name="wmode" value="transparent" />
</object>
EOF
end
def attach_flv_anchor(file_name, width=425, height=350, page=@page)
file_url = nil
if @conf.options['attach.cache_url']
file_url = "#{@conf.options['attach.cache_url']}/#{page.escape.escape}/#{file_name.escape}"
else
file_url = %Q!#{@conf.cgi_name}#{cmdstr('plugin', "plugin=attach_download;p=#{page.escape};file_name=#{file_name.escape}")}!
end
flv(file_url.escape, width, height)
end
export_plugin_methods(:flv, :attach_flv_anchor)
最新版は以下でチェックアウトできます。
$ svn co /repos/hiki/trunk/plugin flv_plugin