class SiteController

Controlador para paginas del site en general

Public Instance Methods

change_locale() click to toggle source

Cambia de idioma, y redirige a la página en la que se encontraba.

# File app/controllers/site_controller.rb, line 59
def change_locale
  old_url = request.env["HTTP_REFERER"] ? request.env["HTTP_REFERER"].gsub(/^#{request.protocol}#{request.host_with_port}/, '') : "/"
  new_url = old_url.dup
  if locales.keys.include?(params[:l].to_sym)
    cookies['locale'] = { :value => params[:l] , :expires => 1.year.from_now }
    I18n.locale = params[:l]

    # Separa la parte de delante y detrás de la ?
    dummy, referer_path, dummy2, referer_querystring = get_params_for(old_url)
    if !referer_querystring.nil?
      # convierte "a=b&c=d" en {"a" => "b", "c" => "d"}
      additional_params = referer_querystring.split('&').inject(Hash.new) do |h, pair| 
        k, v = pair.split('=')
        h[k] = v
        h
      end
    end

    referer_params = ActionController::Routing::Routes.recognize_path(referer_path, :method => :get)
    referer_params = referer_params.merge(additional_params) if additional_params
    
    new_url = url_for(referer_params.merge(:locale => params[:l]))
    
    if (locales.keys.collect {|l| "/#{l}"} + ["/"]).include?(old_url)
      new_url = "/#{params[:l]}"        
    elsif should_translate_url_slug(referer_params)
      # En las URL que tienen el titulo "sluggeado" para buscadores, hay que traducir la parte de detras
      # del id. Eso solo se puede hacer, cogiendo de nuevo el objeto para saber cual es su titulo en otro idioma
      obj = referer_params[:controller].singularize.camelize.constantize.find(referer_params[:id])
      new_url = url_for(referer_params.merge(:locale => params[:l], :id => obj))
    end
  end
  redirect_to new_url
end
contact() click to toggle source
# File app/controllers/site_controller.rb, line 99
def contact
  @title = t('site.contactar')
  @breadcrumbs_info = [[@title, contact_site_path]]
end
email_item() click to toggle source
# File app/controllers/site_controller.rb, line 189
def email_item
  if !params[:t].blank? && %Q(News Event Page Proposal Album Photo Video).include?(params[:t])
    @document = params[:t].constantize.find(params[:id])
  else
    raise ActiveRecord::RecordNotFound
  end
end
feeds() click to toggle source

Listado de todos los Feeds RSS

# File app/controllers/site_controller.rb, line 183
def feeds
  @departments = Department.active.find(:all, :order => "position")
  @title = t('documents.feeds_rss')
  @breadcrumbs_info = [[@title, feeds_site_path]]
end
notfound() click to toggle source

Página para errores 404 de página no encontrada

# File app/controllers/site_controller.rb, line 95
def notfound
  render(:status => "404 Not Found" )
end
page() click to toggle source

Páginas englobadas en “sobre irekia”

# File app/controllers/site_controller.rb, line 167
def page
  @page = Page.send(params[:label])
  @breadcrumbs_info = [[Page::ABOUT.detect {|a| a[:label] == params[:label]}[:title], page_site_path(:label => params[:label])]]
  
  respond_to do |format|
    format.html {
      render :template => "/pages/show"
    }
    format.floki {
      render :template => "/pages/show.floki"
    }
  end
  
end
send_contact() click to toggle source

Envío de sugerencia al administrador

# File app/controllers/site_controller.rb, line 105
def send_contact
  @title = t('site.contactar')
  if params[:name].blank? || params[:email].blank? || params[:message].blank?
    @form_errors = [['name', t('activerecord.errors.messages.blank')], ['message', t('activerecord.errors.messages.blank')], ['email', t('activerecord.errors.messages.blank')]]
    # flash[:error] = t('share.todos_campos')
    render :action => "contact" and return
  elsif !params[:email].match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/)
    # flash[:error] = t('share.email_incorrecto')
    @form_errors = [['email', t('share.email_incorrecto')]]
    render :action => "contact" and return
  end
  
  email = Notifier.create_contact(params[:name], params[:email], params[:message])

  begin
    logger.info("Mandando email de contacto")
    Notifier.deliver(email)
    @title =  t('site.contacto_enviado')
    @message = t('site.body_contacto_enviado')
  rescue Net::SMTPServerBusy, Net::SMTPSyntaxError => err_type
    logger.info("Error al mandar mail de pagina: " + err_type)
    flash[:error] = t('session.Error_servidor_correo')
    @message = t('site.body_contacto_no_enviado')
  end    
end
send_email() click to toggle source

Envia la noticia a un amigo

# File app/controllers/site_controller.rb, line 198
def send_email
  if %Q(News Event Page Proposal Album Photo Video).include?(params[:t])
    @document = params[:t].constantize.find(params[:id])
  else
    raise ActiveRecord::RecordNotFound
  end
  
  if params[:sender_name].blank? || params[:recipient_name].blank? || params[:recipient_email].blank?
    flash[:error] = t('share.todos_campos')
    render :action => "email_item" and return
  elsif !params[:recipient_email].match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/)
    flash[:error] = t('share.email_incorrecto')
    render :action => "email_item" and return
  end
  
  email = Notifier.create_email_document(params[:sender_name], params[:recipient_name], params[:recipient_email], @document)

  begin
    logger.info("Mandando documento")
    Notifier.deliver(email)
    flash[:notice] =  t('share.pagina_enviada')
  rescue Net::SMTPServerBusy, Net::SMTPSyntaxError => err_type
    logger.info("Error al mandar mail de pagina: " + err_type)
    flash[:error] = t('session.Error_servidor_correo')
  end
  
  redirect_to @document
end
show() click to toggle source
# File app/controllers/site_controller.rb, line 27
def show
  respond_to do |format|
    format.html do
      if params[:locale].blank? && cookies['locale'].blank?
        redirect_to lang_path
      else
        set_locale
        @carousel_news = [News.featured_a] + News.featured_4b
        @streaming = Streaming.new
        @debates = (Debate.published.featured + Debate.published.find(:all, :order => "published_at DESC", :limit => 4))[0..3]
        @albums = Album.with_photos.featured.find(:all, :limit => 4)
        @videos = Video.published.translated.find(:all, :limit => 4, :order => "featured DESC, published_at DESC") 
        render
      end
    end
    format.iphone do
      get_iphone_info
      render
    end
    format.android do
      get_iphone_info
      render
    end      
  end
end
snetworking() click to toggle source

Página de redes sociales

# File app/controllers/site_controller.rb, line 160
def snetworking
  @page_title = t('snetworks.title')
  @departments=Department.without_gv.find(:all, :order => 'position').select{|a| a.sorganizations.present?}
  @breadcrumbs_info = [[@page_title, snetworking_site_path]]
end
splash() click to toggle source

Página splash para la elección del idioma

# File app/controllers/site_controller.rb, line 144
def splash
  respond_to do |format|
    format.html {
      if cookies['locale'].blank? || request.request_uri.eql?(lang_path)
        render :layout => false
      else
        redirect_to "/#{cookies['locale']}"
      end        
    }
    format.iphone {
      redirect_to iphone_path
    }
  end    
end
stat() click to toggle source

Página para que un robot monitorice y compruebe que el site no se ha caido.

# File app/controllers/site_controller.rb, line 132
def stat
  @app_stat = "OK"
  begin
    ActiveRecord::Base.connection.execute("SELECT 1 FROM documents")
    @db_stat = "OK"
  rescue
    @db_stat = "KO"
  end
  render :layout => false
end
user_default() click to toggle source
# File app/controllers/site_controller.rb, line 227
def user_default
  redirect_to default_url_for_user
end