| Class | SiteController |
| In: |
app/controllers/site_controller.rb
|
| Parent: | ApplicationController |
Controlador para paginas del site en general
Política de privacidad
# File app/controllers/site_controller.rb, line 242
242: def about
243: @page = Page.about
244: @title = @page ? @page.title : t('site.About')
245: respond_to do |format|
246: format.html {
247: render :action => "tos"
248: }
249: format.floki {
250: render :action => "about.floki"
251: }
252: end
253: end
Cambia de idioma, y redirige a la página en la que se encontraba.
# File app/controllers/site_controller.rb, line 88
88: def change_locale
89: old_url = request.env["HTTP_REFERER"] ? request.env["HTTP_REFERER"].gsub(/^#{request.protocol}#{request.host_with_port}/, '') : "/"
90: new_url = old_url.dup
91:
92: if locales.keys.include?(params[:l])
93: cookies[:locale] = { :value => params[:l] , :expires => 1.year.from_now }
94: I18n.locale = params[:l]
95:
96: # Separa la parte de delante y detrás de la ?
97: dummy, referer_path, dummy2, referer_querystring = old_url.match(/([^\?]+)(\?(.+))*/).to_a
98: if !referer_querystring.nil?
99: # convierte "a=b&c=d" en {"a" => "b", "c" => "d"}
100: additional_params = referer_querystring.split('&').inject(Hash.new) do |h, pair|
101: k, v = pair.split('=')
102: h[k] = v
103: h
104: end
105: end
106:
107: referer_params = ActionController::Routing::Routes.recognize_path(referer_path, :method => :get)
108: referer_params = referer_params.merge(additional_params) if additional_params
109:
110:
111: new_url = url_for(referer_params.merge(:locale => params[:l]))
112:
113: if (locales.keys.collect {|l| "/#{l}"} + ["/"]).include?(old_url)
114: new_url = "/#{params[:l]}"
115: elsif should_translate_url_slug(referer_params)
116: # En las URL que tienen el titulo "sluggeado" para buscadores, hay que traducir la parte de detras
117: # del id. Eso solo se puede hacer, cogiendo de nuevo el objeto para saber cual es su titulo en otro idioma
118: obj = referer_params[:controller].singularize.camelize.constantize.find(referer_params[:id])
119: new_url = url_for(referer_params.merge(:locale => params[:l], :id => obj))
120: end
121:
122:
123: # if old_url.match(/^\/(#{locales.keys.join('|')})\//)
124: # new_url = new_url.sub(/^\/.+?\//, "/#{params[:l]}/")
125: # elsif old_url.match(/\/(prensa|prentsa|press)/)
126: # case params[:l]
127: # when "es"
128: # redirect_to "/prensa" and return
129: # when "eu"
130: # redirect_to "/prentsa" and return
131: # when "en"
132: # redirect_to "/press" and return
133: # end
134: # else
135: # if (locales.keys.collect {|l| "/#{l}"} + ["/"]).include?(old_url)
136: # new_url = "/#{params[:l]}"
137: # else
138: # new_url = new_url.match('\?') ? "#{new_url}&locale=#{params[:l]}" : "#{new_url}?locale=#{params[:l]}"
139: # end
140: # end
141: end
142: logger.info "XXXXXXXXXXXXXXX #{new_url}"
143: redirect_to new_url
144: end
Formulario de contacto. Actualmente no se usa.
# File app/controllers/site_controller.rb, line 153
153: def contact
154: begin
155: category = Category.find(4)
156: document = Document.find(36)
157: @breadcrumbs_info = [[category.name, category_path(category)], [document.title, document_path(document)], [t('site.contactar'), contact_site_path]]
158: rescue
159: end
160: end
# File app/controllers/site_controller.rb, line 262
262: def email_item
263: if !params[:t].blank? && %(News Event Page Link Post Proposal Article Album Photo Video).include?(params[:t])
264: @document = params[:t].constantize.find(params[:id])
265: else
266: raise ActiveRecord::RecordNotFound
267: end
268: end
Listado de todos los Feeds RSS
# File app/controllers/site_controller.rb, line 256
256: def feeds
257: @departments = Department.find(:all, :order => "position")
258: @title = t('documents.feeds_rss')
259: @breadcrumbs_info = [[@title, sitemap_site_path]]
260: end
# File app/controllers/site_controller.rb, line 23
23: def home
24: if params[:locale].blank? && cookies[:locale].blank?
25: redirect_to lang_path
26: # elsif params[:locale].blank?
27: # redirect_to root_with_locale_path(:locale => cookies[:locale])
28: else
29: @body_class = "home"
30:
31: @participation = Participation.new
32:
33: @transparency = Transparency.new
34: end
35: @irekia_subsite = "participation"
36: end
Página para errores 404 de página no encontrada
# File app/controllers/site_controller.rb, line 148
148: def notfound
149: render(:status => "404 Not Found" )
150: end
Política de privacidad
# File app/controllers/site_controller.rb, line 235
235: def privacy
236: @page = Page.privacy
237: @title = @page ? @page.title : t('site.Privacidad')
238: render :action => "tos"
239: end
Búsqueda en todos los contenidos con Ferret
# File app/controllers/site_controller.rb, line 39
39: def search
40: if params[:q].blank?
41: flash[:notice] = t('site.search_empty')
42: redirect_to site_path and return
43: end
44: @title = t('site.busqueda')
45:
46: q = params[:q].gsub('-', '')
47: @q = q.to_ferret_search_string
48: logger.info "Termino de busqueda limpio: #{@q}"
49: # @q = q.tildes
50:
51: if params[:type].present? && !params[:type].eql?("all") && searchable_modules.include?(params[:type].constantize)
52: content_types = [params[:type].constantize]
53: else
54: content_types = searchable_modules
55: end
56:
57: today_epoch = (Date.today - Date.parse('2009-03-01')).to_s.to_i
58:
59: @breadcrumbs_info = [[t('site.busqueda'), site_path]]
60:
61: respond_to do |format|
62: format.html {
63: # sf_date = Ferret::Search::SortField.new(:published_month_year_for_ferret, :type => :integer, :reverse => true)
64: # @search_results = ActsAsFerret.paginate_search("#{@q} AND show_in_irekia:true AND published_at_for_ferret:[20090101000000 #{Time.now.to_s(:number)}]",
65: # [News, Page, Event, Video, Proposal, Album, Photo],
66: # :sort => [sf_date, Ferret::Search::SortField::SCORE],
67: # :page => params[:page] || 1, :per_page => 20)
68: candidates = ActsAsFerret.find("#{@q} AND show_in_irekia:true AND published_at_for_ferret:[20090101000000 #{Time.now.to_s(:number)}]",
69: content_types)
70:
71: candidates.each do |c|
72: date_score = ((1.0-((today_epoch - c.days_from_epoch_for_ferret)/today_epoch.to_f)) * 0.65)
73: # logger.info "BBBBBBBB ((1-((#{today_epoch} - #{c.days_from_epoch_for_ferret})/#{today_epoch.to_f})) * 0.65) : #{date_score.round(2)}"
74: c.ef_score = c.ferret_score + date_score
75: end
76:
77: candidates.sort! {|a, b| b.ef_score <=> a.ef_score}
78:
79: page, per_page, total = (params[:page]||1).to_i, 20, candidates.length
80: @search_results = WillPaginate::Collection.create(page, per_page, total) do |pager|
81: pager.replace candidates[(page-1)*per_page..(page*per_page)-1]
82: end
83: }
84: end
85: end
Envío de sugerencia al administrador
# File app/controllers/site_controller.rb, line 163
163: def send_contact
164: if params[:name].blank? || params[:email].blank? || params[:message].blank?
165: flash[:error] = t('share.todos_campos')
166: render :action => "contact" and return
167: elsif !params[:email].match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
168: flash[:error] = t('share.email_incorrecto')
169: render :action => "contact" and return
170: end
171:
172: email = Notifier.create_contact(params[:name], params[:email], params[:message])
173:
174: begin
175: logger.info("Mandando email de contacto")
176: Notifier.deliver(email)
177: flash[:notice] = t('site.contacto_enviado')
178: @message = t('site.body_contacto_enviado')
179: rescue Net::SMTPServerBusy, Net::SMTPSyntaxError => err_type
180: logger.info("Error al mandar mail de pagina: " + err_type)
181: flash[:error] = t('session.Error_servidor_correo')
182: @message = t('site.body_contacto_no_enviado')
183: end
184: end
Envia la noticia a un amigo
# File app/controllers/site_controller.rb, line 271
271: def send_email
272: if %(News Event Page Link Post Proposal Article Album Photo Video).include?(params[:t])
273: @document = params[:t].constantize.find(params[:id])
274: else
275: raise ActiveRecord::RecordNotFound
276: end
277:
278: if params[:sender_name].blank? || params[:recipient_name].blank? || params[:recipient_email].blank?
279: flash[:error] = t('share.todos_campos')
280: render :action => "email_item" and return
281: elsif !params[:recipient_email].match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
282: flash[:error] = t('share.email_incorrecto')
283: render :action => "email_item" and return
284: end
285:
286: email = Notifier.create_email_document(params[:sender_name], params[:recipient_name], params[:recipient_email], @document)
287:
288: begin
289: logger.info("Mandando documento")
290: Notifier.deliver(email)
291: flash[:notice] = t('share.pagina_enviada')
292: rescue Net::SMTPServerBusy, Net::SMTPSyntaxError => err_type
293: logger.info("Error al mandar mail de pagina: " + err_type)
294: flash[:error] = t('session.Error_servidor_correo')
295: end
296:
297: redirect_to @document
298: end
# File app/controllers/site_controller.rb, line 5
5: def show
6: @page_title = SITE_NAME
7:
8: respond_to do |format|
9: format.html do
10: redirect_to tags_path and return
11: end
12: format.iphone do
13: get_iphone_info
14: render
15: end
16: format.android do
17: get_iphone_info
18: render
19: end
20: end
21: end
Mapa del sitio
# File app/controllers/site_controller.rb, line 222
222: def sitemap
223: @title = "Sitemap"
224: @breadcrumbs_info = [["Sitemap", sitemap_site_path]]
225: end
Página de redes sociales
# File app/controllers/site_controller.rb, line 215
215: def snetworking
216: @title = t('site.en_la_red')
217: @breadcrumbs_info = [[@title_for_head, snetworking_site_path]]
218: render
219: end
Página splash para la elección del idioma
# File app/controllers/site_controller.rb, line 199
199: def splash
200: respond_to do |format|
201: format.html {
202: if cookies[:locale].blank? || request.request_uri.eql?(lang_path)
203: render :layout => false
204: else
205: redirect_to "/#{cookies[:locale]}"
206: end
207: }
208: format.iphone {
209: redirect_to iphone_path
210: }
211: end
212: end
Página para que un robot monitorice y compruebe que el site no se ha caido.
# File app/controllers/site_controller.rb, line 187
187: def stat
188: @app_stat = "OK"
189: begin
190: ActiveRecord::Base.connection.execute("SELECT 1 FROM documents")
191: @db_stat = "OK"
192: rescue
193: @db_stat = "KO"
194: end
195: render :layout => false
196: end