| 1 | # google_video.rb: Google Video plugin for tDiary |
|---|
| 2 | # |
|---|
| 3 | # usage: <%= google_video 'DOC_ID' %> |
|---|
| 4 | # <%= google_video 'DOC_ID', 'WIDTHxHEIGHT', %> |
|---|
| 5 | # |
|---|
| 6 | # otions: following parameters are passed to the player URL. |
|---|
| 7 | # see http://googlesystem.blogspot.com/2006/11/customize-embedded-google-video-player.html for more detail |
|---|
| 8 | # |
|---|
| 9 | # @options['google_video.size'] : default of player size. |
|---|
| 10 | # (width x height. e.g. '425x320'). |
|---|
| 11 | # @options['google_video.height'] : default height |
|---|
| 12 | # @options['google_video.playerMode'] : one of 'embedded', 'simple', |
|---|
| 13 | # 'mini', 'clickToPlay' |
|---|
| 14 | # @options['google_video.autoPlay'] : true or false |
|---|
| 15 | # @options['google_video.loop'] : true or false |
|---|
| 16 | # @options['google_video.showShareButtons'] : true or false |
|---|
| 17 | # |
|---|
| 18 | # Copyright (C) 2007 by KAKUTANI Shintaro <shintaro@kakutani.com> |
|---|
| 19 | # You can redistribute it and/or modify it under GPL2. |
|---|
| 20 | # |
|---|
| 21 | # Acknowledgements: |
|---|
| 22 | # * Thanks to omo for extra_options and add_config_proc. |
|---|
| 23 | |
|---|
| 24 | @google_video_conf_label = "Google Video" |
|---|
| 25 | @google_video_default_width = 425 |
|---|
| 26 | @google_video_default_height = 320 |
|---|
| 27 | @google_video_default_size = "#{@google_video_default_width}x#{@google_video_default_height}" |
|---|
| 28 | @google_video_modes = ['embedded', 'simple', 'mini', 'clickToPlay'] |
|---|
| 29 | |
|---|
| 30 | def google_video_extra_options(opt) |
|---|
| 31 | playerMode = opt['google_video.playerMode'] |
|---|
| 32 | autoPlay = opt['google_video.autoPlay'] |
|---|
| 33 | loop = opt['google_video.loop'] |
|---|
| 34 | showShareButtons = opt['google_video.showShareButtons'] |
|---|
| 35 | ret = "" |
|---|
| 36 | ret += "&playerMode=#{playerMode}" if playerMode |
|---|
| 37 | ret += "&autoPlay=#{autoPlay}" if autoPlay |
|---|
| 38 | ret += "&loop=#{loop}" if loop |
|---|
| 39 | ret += "&showShareButtons=#{showShareButtons}" if showShareButtons |
|---|
| 40 | ret |
|---|
| 41 | end |
|---|
| 42 | |
|---|
| 43 | def google_video( doc_id, player_size=nil) |
|---|
| 44 | size = (player_size || @conf['google_video.size'] || @google_video_default_size) |
|---|
| 45 | width, height = |
|---|
| 46 | begin |
|---|
| 47 | size.match(/(\d+)\s*x\s*(\d+)/i)[1..-1].map {|e| Integer(e)} |
|---|
| 48 | rescue |
|---|
| 49 | [@google_video_default_width, @google_video_default_height] |
|---|
| 50 | end |
|---|
| 51 | |
|---|
| 52 | url = "http://video.google.com/googleplayer.swf?docId=#{doc_id}&hl=en" |
|---|
| 53 | url += google_video_extra_options(@conf) |
|---|
| 54 | %|<object class="googlevideo" width="#{width}" height="#{height}"><param name="movie" value="#{url}"></param><embed src="#{url}" type="application/x-shockwave-flash" width="#{width}" height="#{height}"></embed></object>| |
|---|
| 55 | end |
|---|
| 56 | |
|---|
| 57 | def google_video_conf_proc |
|---|
| 58 | if @mode == 'saveconf' then |
|---|
| 59 | @conf['google_video.size'] = @cgi.params['google_video.size'][0] |
|---|
| 60 | @conf['google_video.autoPlay'] = @cgi.params['google_video.autoPlay'][0] == 'true' |
|---|
| 61 | @conf['google_video.loop'] = @cgi.params['google_video.loop'][0] == 'true' |
|---|
| 62 | @conf['google_video.showShareButtons'] = @cgi.params['google_video.showShareButtons'][0] == 'true' |
|---|
| 63 | @conf['google_video.playerMode'] = @google_video_modes[(@google_video_modes.index(@cgi.params['google_video.playerMode'][0]) or 0)] |
|---|
| 64 | end |
|---|
| 65 | |
|---|
| 66 | <<-HTML |
|---|
| 67 | <h3>Player size</h3> |
|---|
| 68 | <p>Specify player pixcel size w/ 'width x height' string(e.g. '425x320').</p> |
|---|
| 69 | <p><input name="google_video.size" value="#{CGI::escapeHTML(@conf['google_video.size'] || @google_video_default_size)}" /></p> |
|---|
| 70 | </ul> |
|---|
| 71 | <h3>Player Mode</h3> |
|---|
| 72 | <p><select name="google_video.playerMode"> |
|---|
| 73 | <option value="embedded"#{if @conf['google_video.playerMode'] == 'embedded' then ' selected' end}>embedded(default)</option> |
|---|
| 74 | <option value="simple"#{if @conf['google_video.playerMode'] == 'simple' then ' selected' end}>simple</option> |
|---|
| 75 | <option value="mini"#{if @conf['google_video.playerMode'] == 'mini' then ' selected' end}>mini</option> |
|---|
| 76 | <option value="clickToPlay"#{if @conf['google_video.playerMode'] == 'clickToPlay' then ' selected' end}>clickToPlay</option> |
|---|
| 77 | </select> |
|---|
| 78 | <h3>Other Options</h3> |
|---|
| 79 | <p><input type="checkbox" name="google_video.autoPlay" value="true" #{if @conf['google_video.autoPlay'] then ' checked' end}> autoPlay </input></p> |
|---|
| 80 | <p><input type="checkbox" name="google_video.loop" value="true" #{if @conf['google_video.loop'] then ' chec' end}> loop </input></> |
|---|
| 81 | <p><input type="checkbox" name="google_video.showShareButtons" value="true" #{if @conf['google_video.showShareButtons'] then ' checked' end}> showShareButtons </input></p> |
|---|
| 82 | HTML |
|---|
| 83 | end |
|---|
| 84 | |
|---|
| 85 | add_conf_proc( 'google_video', @google_video_conf_label ) do |
|---|
| 86 | google_video_conf_proc |
|---|
| 87 | end |
|---|