Class: Goldencobra::ArticlesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/goldencobra/articles_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#access_denied, #after_sign_in_path_for, #after_sign_out_path_for, #initialize_article, #s, #set_locale

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Goldencobra::ApplicationController

Instance Method Details

#showObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/goldencobra/articles_controller.rb', line 29

def show
  ActiveSupport::Notifications.instrument("goldencobra.article.show", params: params)
  before_init # possible callbacks on start
  params[:session] = session.clone
  params[:session].delete(:user_location)
  if serve_iframe?
    respond_to do |format|
      format.html { render layout: "/goldencobra/bare_layout" }
    end
  elsif request.format == "image/jpeg"  || request.format == "image/png"
    respond_to do |format|
      format.png { render text: "404", status: 404 }
      format.jpeg { render text: "404", status: 404 }
      format.html { render text: "404", status: 404 }
    end
  elsif serve_basic_article?
    initialize_article(@article)
    load_associated_model_into_liquid if can_load_associated_model?
    after_init

    if generate_index_list?
      current_operator = current_user || current_visitor
      @list_of_articles = @article.index_articles(current_operator,params[:frontend_tags])
      after_index
    end

    if serve_fresh_page?
      set_expires_in
      ActiveSupport::Notifications.instrument("goldencobra.article.render", params: params)
      before_render
      respond_to do |format|
        format.html { render layout: choose_layout }
        format.rss
        format.json do
          render json: {
            article: @article.to_json,
            list_of_articles: @list_of_articles.as_json
          }
        end
      end
    end
  elsif should_statically_redirect?
    redirect_to @article.external_url_redirect
  elsif should_dynamically_redirect?
    redirect_dynamically
  else
    if @unauthorized
      redirect_to_401
    else
      redirect_to_404
    end
  end
end

#show_cache_pathObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/goldencobra/articles_controller.rb', line 15

def show_cache_path
  current_client_id = @current_client.try(:id).to_s
  geo_cache = Goldencobra::Setting.for_key("goldencobra.geocode_ip_address") == "true" && session[:user_location].present? && session[:user_location].city.present? ? session[:user_location].city.parameterize.underscore : "no_geo"
  date_cache = Goldencobra::Setting.for_key("goldencobra.article.max_cache_24h") == "true" ? Date.today.strftime("%Y%m%d") : "no_date"
  art_cache = @article ? @article.cache_key : "no_art"
  user_cache = current_user.present? ? current_user.id : "no_user"
  flash_message = session.present? && session['flash'].present? ? Time.now.to_i : ""
  auth_code = params[:auth_token].present? ? 'with_auth' : ''
  offset = params[:start].present? ? "offset_#{params[:start].to_i}" : ""
  limit = params[:limit].present? ? "limit_#{params[:limit].to_i}" : ""
  generated_cache_key = "c-#{current_client_id}/g/#{I18n.locale.to_s}/#{geo_cache}/#{user_cache}/#{date_cache}/#{params[:article_id]}/#{art_cache}_#{params[:pdf]}_#{params[:frontend_tags]}__#{params[:iframe]}#{flash_message}_#{auth_code}#{offset}#{limit}"
  return Zlib.crc32(generated_cache_key).to_s
end

#sitemapObject



97
98
99
100
101
102
103
104
105
# File 'app/controllers/goldencobra/articles_controller.rb', line 97

def sitemap
  @use_ssl = Goldencobra::Url.use_ssl? ? "s" : ""
  @domain_name = Goldencobra::Url.host
  @articles = Goldencobra::Article.for_sitemap
  #TODO: authorize! :read, @article
  respond_to do |format|
    format.xml
  end
end

#switch_languageObject



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/controllers/goldencobra/articles_controller.rb', line 83

def switch_language
  if params[:locale].present?
    I18n.locale = params[:locale]
    session[:locale] = I18n.locale.to_s
  else
    I18n.locale = session[:locale]
  end
  if params[:redirect_to].present?
    redirect_to params[:redirect_to]
  else
    redirect_to "/"
  end
end