Class: ArticlesController

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

Instance Method Summary collapse

Instance Method Details

#convert_to_pdfObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/articles_controller.rb', line 74

def convert_to_pdf
  if @article
    require 'net/http'
    require "uri"
    uid = Setting.for_key("rdcms.html2pdf_uid")
    uri = URI.parse("http://html2pdf.ikusei.de/converter/new.xml?&print_layout=true&uid=#{uid}&url=#{@article.absolute_public_url}#{CGI::escape('?pdf=1')}")
    logger.debug(uri)
    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::Get.new(uri.request_uri)
    response = http.request(request)
    doc = Nokogiri::HTML(response.body)
    file = doc.at_xpath("//file-name").text
    redirect_to "http://html2pdf.ikusei.de#{file}"
  else
    render :text => "404", :status => 404
  end
end

#get_articleObject



107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/controllers/articles_controller.rb', line 107

def get_article
  if is_startpage?
    @article = Article.active.startpage.first
  else
    begin
      article_by_role
      set_format
    rescue
      @article = nil
    end
  end
end

#showObject



27
28
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
# File 'app/controllers/articles_controller.rb', line 27

def show
  ActiveSupport::Notifications.instrument("rdcms.article.show", :params => params)
  before_init()
  if serve_iframe?
    respond_to do |format|
      format.html { render layout: "/rdcms/bare_layout" }
    end
  elsif serve_basic_article?
    initialize_article(@article)
    Article.load_liquid_methods(location: session[:user_location], article: @article, params: params)

    load_associated_model_into_liquid() if can_load_associated_model?
    after_init()

    if generate_index_list?
      @list_of_articles = get_articles_by_article_type
      include_related_models()
      get_articles_with_tags() if @article.index_of_articles_tagged_with.present?
      get_articles_without_tags() if @article.not_tagged_with.present?
      get_articles_by_frontend_tags() if params[:frontend_tags].present?
      sort_response()
      after_index()
    end

    if serve_fresh_page?
      set_expires_in()
      ActiveSupport::Notifications.instrument("rdcms.article.render", :params => params)
      before_render()
      respond_to do |format|
        format.html { render layout: choose_layout() }
        format.rss
        format.json do
          @article["list_of_articles"] = @list_of_articles
          render json: @article.to_json
        end
      end
    end
  elsif should_statically_redirect?
    redirect_to @article.external_url_redirect
  elsif should_dynamically_redirect?
    redirect_dynamically()
  else
    # Render 404 Article if no Article else is found
    redirect_to_404()
  end
end

#show_cache_pathObject



17
18
19
20
21
22
23
24
# File 'app/controllers/articles_controller.rb', line 17

def show_cache_path
  geo_cache = Setting.for_key("rdcms.geocode_ip_address") == "true" && session[:user_location].present? && session[:user_location].city.present? ? session[:user_location].city.parameterize.underscore : "no_geo"
  date_cache = Setting.for_key("rdcms.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"

  "g/#{geo_cache}/#{user_cache}/#{date_cache}/#{params[:article_id]}/#{art_cache}_#{params[:pdf]}_#{params[:frontend_tags]}__#{params[:iframe]}"
end

#sitemapObject



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

def sitemap
  if Setting.for_key("rdcms.use_ssl") == "true"
    @use_ssl = "s"
  else
    @use_ssl = ""
  end
  @domain_name = Setting.for_key("rdcms.url")
  @articles = Article.for_sitemap
  #TODO: authorize! :read, @article
  respond_to do |format|
    format.xml
  end
end