OpenIrekia v4.0.0
Copyright 2009-2013 eFaber, S.L. Copyright 2009-2013 Ejie, S.A. Copyrigth 2009-2013 Dirección de Gobierno Abierto y Comunicación en Internet;
Gobernu Irekirako eta Interneteko Komunikaziorako Zuzendaritza; Lehendakaritza. Gobierno Vasco – Eusko Jaurlaritza
Licencia con arreglo a la EUPL, Versión 1.1 o –en cuanto sean aprobadas por la Comisión Europea– versiones posteriores de la EUPL (la Licencia); Solo podrá usarse esta obra si se respeta la Licencia. Puede obtenerse una copia de la Licencia en: ec.europa.eu/idabc/eupl Salvo cuando lo exija la legislación aplicable o se acuerde por escrito, el programa distribuido con arreglo a la Licencia se distribuye TAL CUAL, SIN GARANTÍAS NI CONDICIONES DE NINGÚN TIPO, ni expresas ni implícitas. Véase la Licencia en el idioma concreto que rige los permisos y limitaciones que establece la Licencia
http://open.irekia.net, openirekia@efaber.net
En Floki necesitamos que el path a la imagen de portada por defecto de un video sea absoluta
# File app/helpers/site_helper.rb, line 206 def absolutize_url(url) url.match(/^http/) ? url : "#{request.protocol}#{request.host_with_port}#{url}" end
# File app/helpers/site_helper.rb, line 201 def default_preview_img(format="43") default_img = format.eql?('169') ? "/images/video_preview_format169.jpg" : "/images/video_preview.jpg" end
# File app/helpers/site_helper.rb, line 65 def description_for_enet_xml(text) if m = text.match(/<.+class=\"r01Entradilla\".?>(.+)</) return pretty_n_characters_wo_html(m[1], 244) else return pretty_n_characters_wo_html(text, 244) end end
Datos sobre el flowplayer que se usan para inicializarlo desde el JS
# File app/helpers/site_helper.rb, line 88 def flowplayer_info # New version 3.2.15 info = {} info[:path] = "/video/flowplayer-3.2.15.swf" info[:controls_plugin] = "/video/flowplayer.controls-3.2.14.swf" info[:streaming_plugin] = "/video/flowplayer.pseudostreaming-3.2.11.swf" info[:gatracker_plugin] = "/video/flowplayer.analytics-3.2.8.swf" info[:rtmp_plugin] = "/video/flowplayer.rtmp-3.2.11.swf" info[:captions_plugin] = "/video/flowplayer.captions-3.2.9.swf" info[:content_plugin] = "/video/flowplayer.content-3.2.8.swf" info[:key] = '#$61de7613ee9761041ce' info end
Datos sobre el flowplayer que se usan para inicializarlo desde el JS para flowplayer-3.2.4
# File app/helpers/site_helper.rb, line 105 def flowplayer_info_old info = {} info[:path] = "/video/flowplayer-3.2.4.swf" info[:controls_plugin] = "/video/flowplayer.controls-3.2.2.swf" info[:streaming_plugin] = "/video/flowplayer.pseudostreaming-3.2.4.swf" info[:gatracker_plugin] = "/video/flowplayer.analytics-3.2.1.swf" info[:rtmp_plugin] = "/video/flowplayer.rtmp-3.2.3.swf" info[:key] = '#$61de7613ee9761041ce' info end
Devuelve el código del video para empotrar en otras webs
# File app/helpers/site_helper.rb, line 119 def flv_video_info(item, locale=I18n.locale.to_sym) player_id = "lighty" embed_container = "video_embed_container" embed_id = "video_embed" captions_url = nil if item.is_a?(Video) video = "#{Video::VIDEO_URL}#{item.featured_video}" preview_img = video_preview_img(item, item.display_format) title = item.title duration = item.duration display_format = item.display_format elsif item.is_a?(String) video = "#{Document::MULTIMEDIA_URL}#{item}" embed_container = "video_embed_container_#{item.to_tag}" embed_id = "video_embed_#{item.to_tag}" player_id = "lighty_#{item.to_tag}" display_format = "169" # Este video es probablemente uno de los secundarios de una noticia, pero aquí sólo tengo el string # del path del video. Para sacar el título, miro a ver si tengo un objeto @news y lo saco de ahí if @document && @document.is_a?(News) info_from_webtv = video_info_from_webtv(item, @document, locale.to_s) title = info_from_webtv[:title] duration = info_from_webtv[:duration] display_format = info_from_webtv[:display_format] webtv_id = info_from_webtv[:webtv_id] captions_url = info_from_webtv[:captions_url] end preview_img = video_preview_img(item, display_format) else # it is a News item video_path = item.featured_video(locale) video = Document::MULTIMEDIA_URL + video_path info_from_webtv = video_info_from_webtv(video_path, item, locale.to_s) title = info_from_webtv[:title] duration = info_from_webtv[:duration] display_format = info_from_webtv[:display_format] preview_img = video_preview_img(item, display_format, locale.to_s) end # como es codigo para incrustar en otras webs, las URL tienen que ser absolutas preview_img = preview_img.sub(/^\/images/, "#{request.protocol}#{request.host_with_port}/images") return {:fp_key => flowplayer_info[:key], :video => video, :preview_img => preview_img, :title => title, :player_id => player_id , :embed_container => embed_container, :embed_id => embed_id, :duration => seconds_in_minutes(duration), :display_format => display_format, :webtv_id => webtv_id, :captions_url => captions_url} end
Devuelve el path al video en versión HTML5
# File app/helpers/site_helper.rb, line 275 def html5_video_for(flv_video_path) unless flv_video_path.nil? flv = Pathname.new(flv_video_path) "#{flv.dirname}/html5/#{flv.basename.sub(/flv$/, 'm4v')}" end end
Devuelve el path al video en versión para la iPhone App
# File app/helpers/site_helper.rb, line 283 def iphone_app_video_for(flv_video_path) html5_video_for(flv_video_path).sub('/html5/', '/ts/').sub(/m4v$/, 'm3u8') unless flv_video_path.nil? end
# File app/helpers/site_helper.rb, line 73 def meta_keywords "Euskadi, País Vasco, Gobierno Vasco, transparencia, participación ciudadana, gobierno abierto, Irekia, Eusko Jaurlaritza, Lehendakari, gardentasuna, herritarren parte-hartzea, gobernu irekia, Basque Country, Basque Government, Open Government, Transparency".gsub(/\n/, '') end
# File app/helpers/site_helper.rb, line 168 def photo_info(photo, document) if photo.respond_to?('url') # es foto de portada file_path = photo.path url = photo.url("original") title = document.present? ? document.cover_photo_alt : document.title gallery_id = nil else # es un string file_path = photo url = url_for_photo(photo) title = document.title gallery_id = photo_info_from_gallery(photo, document) end return {:file_path => file_path, :url => url, :title => title, :gallery_id => gallery_id} end
# File app/helpers/site_helper.rb, line 185 def photo_info_from_gallery(photo_path, item) if gallery_photo = item.gallery_photos.find_by_file_path(photo_without_root_path(photo_path)) gallery_id = gallery_photo.id else gallery_id = nil end end
# File app/helpers/site_helper.rb, line 193 def photo_without_root_path(path) path.gsub(PhotoPaths::PHOTOS_PATH, '') end
Shorten text but do not split words
# File app/helpers/site_helper.rb, line 56 def pretty_n_characters(text, n_chars=200) text = text[0..n_chars].strip.sub(/\s[^\s]+$/, ' …') if text.length > n_chars text.gsub('###','').gsub('@@@','').strip end
# File app/helpers/site_helper.rb, line 61 def pretty_n_characters_wo_html(text, n_chars=200) pretty_n_characters(text, n_chars).strip_html end
# File app/helpers/site_helper.rb, line 197 def seconds_in_minutes(num) "#{num/60}:#{"%02d"%(num%60)}" unless num.nil? end
# File app/helpers/site_helper.rb, line 24 def short_body(text) short_body = "" if text.present? # ¡OJO! el (.+) al principio puede colgar la web si el texto de la noticia tiene html lioso # pero sin (.+) no sale el texto para noticias con subtítulo o entradilla. ¡REVISAR! text_parts = text.match(/(.*)<p.*>###<.*\/p>/) #m = document.body.match(/<p.*>###<.*\/p>/m) if text_parts short_body = text_parts.to_a[1] else clean_body = white_list(text) { |node, bad| ['object', 'img'].include?(bad) ? nil : node.to_s } text_paragraph = clean_body.match(/^((.{200,}?)<\/p>)/) if text_paragraph # first paragraph longer than 200 chars if clean_body.length > 1000 && text_paragraph[1].length > 1000 short_body = "#{pretty_n_characters(clean_body)}</p>" else short_body = "#{text_paragraph.to_a[2]}</p>" end else short_body = clean_body end end end short_body.to_s end
# File app/helpers/site_helper.rb, line 51 def short_body_wo_html(text) short_body(text).strip_html end
Si vemos el video con iPad, usamos html5. Si no, usamos el flowplayer.
# File app/helpers/site_helper.rb, line 83 def use_flowplayer? !ipad_user_agent? && !iphone_user_agent? && !android_user_agent? end
# File app/helpers/site_helper.rb, line 247 def video_info_from_webtv(video_path, item, locale=I18n.locale) if webtv_related_video = item.webtv_videos.find_by_video_path(video_name_without_extension_and_language(video_path)) title = webtv_related_video.send("title_#{locale}") duration = webtv_related_video.duration display_format = webtv_related_video.display_format webtv_id = webtv_related_video.id captions_url = webtv_related_video.captions_url(locale) else title = item.send("title_#{locale}") duration = nil display_format = "169" captions_url = nil end {:title => title, :duration => duration, :display_format => display_format, :webtv_id => webtv_id, :captions_url => captions_url} end
# File app/helpers/site_helper.rb, line 263 def video_name_without_extension_and_language(video_string) video_string.sub(Pathname.new(video_string).extname, '').sub(/_e(s|u|n)$/, '') end
# File app/helpers/site_helper.rb, line 210 def video_preview_img(item, display_format=nil, locale=I18n.locale) if item.is_a?(Video) base_path = Video::VIDEO_PATH base_url = Video::VIDEO_URL video_path = item.featured_video elsif item.is_a?(String) base_path = Document::MULTIMEDIA_PATH base_url = Document::MULTIMEDIA_URL video_path = item else # it is a News item base_path = Document::MULTIMEDIA_PATH base_url = Document::MULTIMEDIA_URL video_path = item.featured_video(locale.to_sym) end default_img = default_preview_img(display_format) if video_path video_preview_filename = video_path.sub('.flv', '.jpg') video_preview_file = "#{base_path}#{video_preview_filename}" video_preview_url = "#{base_url}#{video_preview_filename}" unless File.exists?(video_preview_file) # Si no esta la imagen nombre_es.jpg, buscamos nombre.jpg preview_without_locale = video_preview_filename.sub(/_#{locale}.jpg/, '.jpg') if File.exists?("#{base_path}#{preview_without_locale}") video_preview_file = "#{base_path}#{preview_without_locale}" video_preview_url = "#{base_url}#{preview_without_locale}" end end preview_img = File.exists?(video_preview_file) ? video_preview_url : default_img else preview_img = default_img end end
# File app/helpers/site_helper.rb, line 267 def video_title_with_duration(video_info) txt = [] txt.push video_info[:title] txt.push " [#{video_info[:duration]}]" if video_info[:duration].present? txt.compact.join end