Class | SiteController
In: | app/controllers/site_controller.rb
Parent: | ApplicationController

### Methods

change_locale contact notfound privacy search send_contact show sitemap snetworking splash stat tos

### Public Instance methods

change_locale()

[Source]

        # File app/controllers/site_controller.rb, line 60
    60:   def change_locale
    61:     old_url = request.env["HTTP_REFERER"] ? request.env["HTTP_REFERER"].gsub(/^#{request.protocol}#{request.host_with_port}/, '') : "/"
    62:     new_url = old_url.dup
    63:     if locales.keys.include?(params[:l])
    64:       cookies[:locale] = { :value => params[:l] , :expires => 1.year.from_now }
    65:       if old_url.match(/^\/(#{locales.keys.join('|')})\//)
    66:         new_url = new_url.sub(/^\/.+?\//, "/#{params[:l]}/")
    67:       elsif old_url.match(/\/(prensa|prentsa|press)/)
    68:           case params[:l]
    69:           when "es"
    70:             redirect_to "/prensa" and return
    71:           when "eu"
    72:             redirect_to "/prentsa" and return
    73:           when "en"
    74:             redirect_to "/press" and return
    75:           end
    76:       else
    77:         if (locales.keys.collect {|l| "/#{l}"} + ["/"]).include?(old_url)
    78:           new_url = "/#{params[:l]}"
    79:         else
    80:           new_url = new_url.match('\?') ? "#{new_url}&locale=#{params[:l]}" : "#{new_url}?locale=#{params[:l]}"
    81:         end
    82:       end
    83:     end
    84:
    85:     redirect_to new_url
    86:   end

contact()

[Source]

        # File app/controllers/site_controller.rb, line 92
    92:   def contact
    93:     begin
    94:       category = Category.find(4)
    95:       document = Document.find(36)
    96:       @breadcrumbs_info = [[category.name, category_path(category)], [document.title, document_path(document)], [t('site.contactar'), contact_site_path]]
    97:     rescue
    98:     end
    99:   end

notfound()

[Source]

        # File app/controllers/site_controller.rb, line 88
    88:   def notfound
    89:     render( :status => "404 Not Found" )
    90:   end

privacy()

[Source]

         # File app/controllers/site_controller.rb, line 160
    160:   def privacy
    161:     @title = t('site.Privacidad')
    162:     @page = Page.privacy
    163:     render :action => "tos"
    164:   end

search()

[Source]

        # File app/controllers/site_controller.rb, line 15
    15:   def search
    16:     if params[:q].blank?
    17:       flash[:notice] = t('site.search_empty')
    18:       redirect_to site_path and return
    19:     end
    20:
    21:     q = params[:q].gsub('-', '')
    22:     @q = q.to_ferret_search_string
    23:     logger.info "Termino de busqueda limpio: #{@q}"
    24:     # @q = q.tildes
    25:
    26:     today_epoch = (Date.today - Date.parse('2009-03-01')).to_s.to_i
    27:
    28:     @breadcrumbs_info = [[t('site.busqueda'), site_path]]
    29:
    30:     respond_to do |format|
    31:       format.html {
    32:         # sf_date = Ferret::Search::SortField.new(:published_month_year_for_ferret, :type => :integer, :reverse => true)
    33:         # @search_results = ActsAsFerret.paginate_search("#{@q} AND show_in_irekia:true AND published_at_for_ferret:[20090101000000 #{Time.now.to_s(:number)}]",
    34:         #   [News, Page, Event, Video, Proposal, Album, Photo],
    35:         #   :sort => [sf_date, Ferret::Search::SortField::SCORE],
    36:         #   :page => params[:page] || 1, :per_page => 20)
    37:
    38:         candidates = ActsAsFerret.find("#{@q} AND show_in_irekia:true AND published_at_for_ferret:[20090101000000 #{Time.now.to_s(:number)}]",
    39:           [News, Page, Event, Video, Link, Photo, Album])
    40:
    41:         # Borrar del resultado de la búsqueda los documentos que no son visibles para el current_user.
    42:         candidates.delete_if {|item| !item.can_be_read_by?(nil)}
    43:
    44:         candidates.each do |c|
    45:           date_score = ((1.0-((today_epoch - c.days_from_epoch_for_ferret)/today_epoch.to_f)) * 0.65)
    46:           # logger.info "BBBBBBBB ((1-((#{today_epoch} - #{c.days_from_epoch_for_ferret})/#{today_epoch.to_f})) * 0.65) : #{date_score.round(2)}"
    47:           c.ef_score = c.ferret_score + date_score
    48:         end
    49:
    50:         candidates.sort! {|a, b| b.ef_score <=> a.ef_score}
    51:
    52:         page, per_page, total = (params[:page]||1).to_i, 20, candidates.length
    53:         @search_results = WillPaginate::Collection.create(page, per_page, total) do |pager|
    54:           pager.replace candidates[(page-1)*per_page..(page*per_page)-1]
    55:         end
    56:       }
    57:     end
    58:   end

send_contact()

[Source]

         # File app/controllers/site_controller.rb, line 101
    101:   def send_contact
    102:
    103:     if params[:name].blank? || params[:email].blank? || params[:message].blank?
    104:       flash[:error] = t('share.todos_campos')
    105:       render :action => "contact" and return
    106:     elsif !params[:email].match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
    107:       flash[:error] = t('share.email_incorrecto')
    108:       render :action => "contact" and return
    109:     end
    110:
    111:     email = Notifier.create_contact(params[:name], params[:email], params[:message])
    112:
    113:     begin
    114:       logger.info("Mandando email de contacto")
    115:       Notifier.deliver(email)
    116:       flash[:notice] =  t('site.contacto_enviado')
    117:       @message = t('site.body_contacto_enviado')
    118:     rescue Net::SMTPServerBusy, Net::SMTPSyntaxError => err_type
    119:       logger.info("Error al mandar mail de pagina: " + err_type)
    120:       flash[:error] = t('session.Error_servidor_correo')
    121:       @message = t('site.body_contacto_no_enviado')
    122:     end
    123:   end

show()

[Source]

        # File app/controllers/site_controller.rb, line 4
     4:   def show
     5:     respond_to do |format|
     6:       format.html do
     7:         redirect_to tags_path and return
     8:       end
     9:       format.iphone do
    10:         render
    11:       end
    12:     end
    13:   end

sitemap()

[Source]

         # File app/controllers/site_controller.rb, line 149
    149:   def sitemap
    150:     @title = "Sitemap"
    151:     @breadcrumbs_info = [["Sitemap", sitemap_site_path]]
    152:   end

snetworking()

[Source]

         # File app/controllers/site_controller.rb, line 144
    144:   def snetworking
    145:     @title_for_head = t('site.rrss_blogs')
    146:     @breadcrumbs_info = [[@title_for_head, snetworking_site_path]]
    147:   end

splash()

[Source]

         # File app/controllers/site_controller.rb, line 136
    136:   def splash
    137:     unless cookies[:locale].blank?
    138:       redirect_to "/#{cookies[:locale]}"
    139:     else
    140:       render :layout => false
    141:     end
    142:   end

stat()

[Source]

         # File app/controllers/site_controller.rb, line 125
    125:   def stat
    126:     @app_stat = "OK"
    127:     begin
    128:       ActiveRecord::Base.connection.execute("SELECT 1 FROM documents")
    129:       @db_stat = "OK"
    130:     rescue
    131:       @db_stat = "KO"
    132:     end
    133:     render :layout => false
    134:   end

tos()

[Source]

         # File app/controllers/site_controller.rb, line 154
    154:   def tos
    155:     @title = t('site.Normas_de_uso')
    156:     @page = Page.terms_of_service
    157:     # render :action => "tos_#{I18n.locale}"
    158:   end

[Validate]