Module SiteHelper
In: app/helpers/site_helper.rb

Methods

Public Instance methods

[Source]

     # File app/helpers/site_helper.rb, line 169
169:   def default_preview_img(format="43")
170:     default_img = format.eql?('169') ? "/images/video_preview_format169.jpg" : "/images/video_preview.jpg"
171:   end

[Source]

    # File app/helpers/site_helper.rb, line 91
91:   def description_for_enet_xml(text)
92:     if m = text.match(/<.+class=\"r01Entradilla\".?>(.+)</)
93:       return first_n_characters_wo_html(m[1], 254)
94:     else
95:       return first_n_characters_wo_html(text, 254)
96:     end
97:   end

[Source]

     # File app/helpers/site_helper.rb, line 248
248:   def enet_link
249:     {:es => "http://www.euskadi.net/r33-2220/es/", 
250:      :eu => "http://www.euskadi.net/r33-2220/es/", 
251:      :en => "http://www.euskadi.net/t32-7413/en/"}
252:   end

Devuelve el score de la busqueda de Ferret, y la recalculada para dar mas peso al contenido mas nuevo.

[Source]

     # File app/helpers/site_helper.rb, line 100
100:   def ferret_scores(item)
101:     # "1: #{item.ferret_score.round(2)}. 2: #{item.ef_score.round(2)}"
102:     # # "Fecha: #{item.published_at_for_ferret[0..7]}. Ferret: #{item.ferret_score.round(2)}"
103:     # Ahora no queremos visualizarlo, asi que devolvemos nil
104:     nil
105:   end

[Source]

    # File app/helpers/site_helper.rb, line 57
57:   def first_n_characters_wo_html(text, n_chars=200)
58:     text.strip_html[0..n_chars].sub(/\s[^\s]+$/, '')
59:   end

Flowplayer functions

[Source]

     # File app/helpers/site_helper.rb, line 115
115:   def flowplayer_info
116:     Flowplayer::INFO
117:   end

Devuelve el código del video para empotrar en otras webs

[Source]

     # File app/helpers/site_helper.rb, line 120
120:   def flv_video_info(item)
121:     player_id = "lighty"
122:     embed_container = "video_embed_container"
123:     embed_id = "video_embed"
124:     
125:     if item.is_a?(Video)
126:       video = "#{Video::VIDEO_URL}#{item.featured_video}"
127:       preview_img = video_preview_img(item, item.display_format)
128:       title = item.title
129:       duration = item.duration
130:       display_format = item.display_format      
131:     elsif item.is_a?(String)
132:       video = "#{Document::MULTIMEDIA_URL}#{item}"
133:       embed_container = "video_embed_container_#{item.to_tag}"
134:       embed_id = "video_embed_#{item.to_tag}"
135:       player_id = "lighty_#{item.to_tag}"
136:       display_format = nil
137:       # Este video es probablemente uno de los secundarios de una noticia, pero aquí sólo tengo el string 
138:       # del path del video. Para sacar el título, miro a ver si tengo un objeto @news y lo saco de ahí
139:       if @document && @document.is_a?(News)
140:         info_from_webtv = video_info_from_webtv(item, @document)
141:         title = info_from_webtv[:title]
142:         duration = info_from_webtv[:duration]
143:         display_format = info_from_webtv[:display_format]        
144:       end
145:       preview_img = video_preview_img(item, display_format)
146:     else
147:       # it is a News item
148:       video_path = item.featured_video(subsite)
149:       video = Document::MULTIMEDIA_URL + video_path
150:       info_from_webtv = video_info_from_webtv(video_path, item)
151:       title = info_from_webtv[:title]
152:       duration = info_from_webtv[:duration]
153:       display_format = info_from_webtv[:display_format]
154:       preview_img = video_preview_img(item, display_format)      
155:     end
156:     
157:     # como es codigo para incrustar en otras webs, las URL tienen que ser absolutas
158:     preview_img = preview_img.sub(/^\/images/, "#{request.protocol}#{request.host_with_port}/images")
159:     
160:     return {:fp_key => flowplayer_info[:key], :video => video, :preview_img => preview_img, :title => title, 
161:             :player_id => player_id , :embed_container => embed_container, :embed_id => embed_id, 
162:             :duration => seconds_in_minutes(duration), :display_format => display_format}
163:   end

[Source]

     # File app/helpers/site_helper.rb, line 280
280:   def get_net_connection_url_for_streaming
281:     if File.exists?('/tmp/gotoec2')
282:       'rtmp://79.125.115.44:1935/liverepeater'
283:     else
284:       'rtmp://bideoak3.euskadi.net:1935/live'
285:     end
286:   end

[Source]

     # File app/helpers/site_helper.rb, line 254
254:   def home_video_title(streaming_present, announced_streaming)
255:     title = link_to(t('videos.web_tv'), videos_path)
256:     if streaming_present
257:       title = t('events.streaming_live')
258:     elsif announced_streaming
259:       title = t('events.announced_streaming')
260:     end
261:     return title
262:   end

Devuelve el path al video en versión HTML5

[Source]

     # File app/helpers/site_helper.rb, line 236
236:   def html5_video_for(flv_video_path)
237:     unless flv_video_path.nil?
238:       flv = Pathname.new(flv_video_path)
239:       "#{flv.dirname}/html5/#{flv.basename.sub(/flv$/, 'm4v')}"
240:     end
241:   end

Devuelve el path al video en versión para la iPhone App

[Source]

     # File app/helpers/site_helper.rb, line 244
244:   def iphone_app_video_for(flv_video_path)
245:     html5_video_for(flv_video_path).sub('/html5/', '/ts/').sub(/m4v$/, 'm3u8') unless flv_video_path.nil?
246:   end

[Source]

     # File app/helpers/site_helper.rb, line 264
264:   def link_to_itunes
265:     if News.exists?(2378)
266:       n = News.find(2378)
267:       itunes_url = news_path(n)
268:       rel = 'local'
269:     else 
270:       itunes_url = I18n.locale.eql?("eu") ? "http://itunes.apple.com/es/podcast/irekia-gobernu-irekia/id377764925" : 
271:                                           "http://itunes.apple.com/es/podcast/irekia-gobierno-abierto/id377362551"
272:       rel = 'external'
273:     end
274:     content_tag(:div, 
275:                 link_to(image_tag("/images/irekia_podcasts.gif", :alt => "OpenIrekia podcasts"),
276:                         itunes_url, :rel => rel), 
277:                         :class => "banner itunes")    
278:   end

[Source]

     # File app/helpers/site_helper.rb, line 107
107:   def meta_keywords
108:     "OpenIrekia, Euskadi, País Vasco, Gobierno Vasco, transparencia, participación ciudadana, gobierno abierto, 
109:     Eusko Jaurlaritza, Lehendakari, gardentasuna, herritarren parte-hartzea, gobernu irekia, Basque Country, 
110:     Basque Government, Open Government, Transparency".gsub(/\n/, '')
111:   end

[Source]

     # File app/helpers/site_helper.rb, line 165
165:   def seconds_in_minutes(num)
166:     "#{num/60}:#{"%02d"%(num%60)}" unless num.nil?
167:   end

[Source]

    # File app/helpers/site_helper.rb, line 29
29:   def short_html_body(document)
30:     if document.body.present?
31:       m = document.body.match(/(.+)<p.*>###<.*\/p>/m)
32:       if m
33:         # logger.info "AAAAAAAAA tiene ###"
34:         short_body =  m.to_a[1] 
35:       else
36:         clean_body = white_list(document.body) { |node, bad| ['object', 'img'].include?(bad) ? nil : node.to_s }
37:         m = clean_body.match(/^((.{200,}?)<\/p>)/m)
38:         if m
39:           if clean_body.length > 1000 && m[1].length > 1000
40:             # logger.info "BBBBBBBBBBB cortamos los primeros 200 caracteres"
41:             # Quitamos desde el final hasta el espacio anterior para no cortar palabras
42:             short_body = "<p>#{first_n_characters_wo_html(clean_body)}</p>"
43:           else
44:             # logger.info "CCCCCCCCCCC cogemos el primer parrafo"
45:             short_body = "#{m.to_a[2]}</p>"
46:           end
47:         else
48:           short_body = "<p>#{first_n_characters_wo_html(clean_body)}</p>"
49:         end
50:       end
51:     else
52:       short_body = ""
53:     end
54:     return short_body    
55:   end

[Source]

    # File app/helpers/site_helper.rb, line 2
 2:   def short_html_body_for_search(document)
 3:     # logger.info "--------- #{document.title_es}"
 4:     body = document.pretty_body
 5:     m = body.match(/((.{200,}?)<\/p>)/m)
 6:     if m
 7:       if body.length > 1000 && m[1].length > 1000
 8:         # logger.info "1111111"
 9:         # Quitamos desde el final hasta el espacio anterior para no cortar palabras
10:         short_descripcion = "<p>#{first_n_characters_wo_html(body)}</p> 
11:           <div class='inners_links'><ul><li>#{link_to(t('documents.sigue_leyendo'), document)}</li></ul></div>"
12:       else
13:         if m.to_a[1].length == body.length
14:           # logger.info "2222222"
15:           short_descripcion = m.to_a[1].gsub(/<object.+?>.+<\/object>/m, '').gsub(/<img.+?\/>/, '')
16:         else
17:           # logger.info "33333333"
18:           short_descripcion = "#{m.to_a[2].gsub(/<object.+?>.+<\/object>/m, '').gsub(/<img.+?\/>/, '')}</p>
19:           <div class='inners_links'><ul><li>#{link_to t('documents.sigue_leyendo'), document}</li></ul></div>"
20:         end
21:       end
22:     else
23:       # logger.info "44444444"
24:       short_descripcion = short_html_body(document).gsub(/<object.+?>.+<\/object>/m, '').gsub(/<img.+?\/>/, '')
25:     end
26:     return short_descripcion
27:   end

[Source]

    # File app/helpers/site_helper.rb, line 61
61:   def split_body(document)
62:     body_parts = []
63:     if document.body.match('@@@')
64:       body_parts = document.body.sub(/<p.*>###<.*\/p>/, '').sub(/<p.*>@@@<.*\/p>/, '@@@').split('@@@')
65:     else
66:       text = document.pretty_body
67:       length = 1900
68:    
69:       if (text.length > length)
70:         part1 = truncate(text, :length =>  length-1, :omission => "")
71:         if part1.match(/<\/p>/)
72:           part1 = part1[0, part1.rindex(/<\/p>/)+4]
73:         else
74:           if part1.match(/<br/)
75:             part1 = part1[0, part1.rindex(/\>/)+1]
76:           else
77:             part1 = part1[0, part1.rindex(/\s+/)]
78:           end
79:         end
80:       
81:         part2 = text[part1.length, text.length]
82:       else
83:         part1 = text
84:         part2 = nil
85:       end
86:       body_parts = [part1, part2] 
87:     end    
88:     body_parts
89:   end

[Source]

     # File app/helpers/site_helper.rb, line 211
211:   def video_info_from_webtv(video_path, item)
212:     if webtv_related_video = item.webtv_videos.find_by_video_path(video_name_without_extension_and_language(video_path))
213:       title = webtv_related_video.title
214:       duration = webtv_related_video.duration
215:       display_format = webtv_related_video.display_format
216:     else
217:       title = item.title
218:       duration = nil
219:       display_format = nil
220:     end
221:     {:title => title, :duration => duration, :display_format => display_format}
222:   end

[Source]

     # File app/helpers/site_helper.rb, line 224
224:   def video_name_without_extension_and_language(video_string)
225:     video_string.sub(Pathname.new(video_string).extname, '').sub(/_e(s|u|n)$/, '')
226:   end

[Source]

     # File app/helpers/site_helper.rb, line 173
173:   def video_preview_img(item, display_format=nil)
174:     if item.is_a?(Video)
175:       base_path = Video::VIDEO_PATH
176:       base_url = Video::VIDEO_URL
177:       video_path = item.featured_video
178:     elsif item.is_a?(String)
179:       base_path = Document::MULTIMEDIA_PATH
180:       base_url = Document::MULTIMEDIA_URL
181:       video_path = item
182:     else
183:       # it is a News item
184:       base_path = Document::MULTIMEDIA_PATH
185:       base_url = Document::MULTIMEDIA_URL
186:       video_path = item.featured_video(subsite)
187:     end
188:     
189:     default_img = default_preview_img(display_format)
190:     
191:     if video_path
192:       video_preview_filename = video_path.sub('.flv', '.jpg')
193:       video_preview_file = "#{base_path}#{video_preview_filename}"
194:       video_preview_url = "#{base_url}#{video_preview_filename}"
195:       unless File.exists?(video_preview_file)
196:         # Si no esta la imagen nombre_es.jpg, buscamos nombre.jpg
197:         preview_without_locale = video_preview_filename.sub(/_#{I18n.locale.to_sym}.jpg/, '.jpg')
198:         if File.exists?("#{base_path}#{preview_without_locale}")
199:           video_preview_file = "#{base_path}#{preview_without_locale}"
200:           video_preview_url = "#{base_url}#{preview_without_locale}"
201:         end
202:       end
203:       preview_img = File.exists?(video_preview_file) ? video_preview_url : default_img
204:     else
205:       preview_img = default_img
206:     end
207:     
208:   end

[Source]

     # File app/helpers/site_helper.rb, line 228
228:   def video_title_with_duration(video_info)
229:     txt = []
230:     txt.push video_info[:title]
231:     txt.push " [#{video_info[:duration]}]" if video_info[:duration].present?
232:     txt.compact.join
233:   end

[Validate]