Class: PostsController

Inherits:
ApplicationController show all
Includes:
ExtendPostsController
Defined in:
app/controllers/posts_controller.rb

Instance Method Summary collapse

Methods included from ExtendPostsController

#after_index, #after_init, #before_init, #before_render

Instance Method Details

#convert_to_pdfObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/posts_controller.rb', line 88

def convert_to_pdf
  if @post
    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=#{@post.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

#indexObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/posts_controller.rb', line 18

def index

  if params[:tag]
    @search = Post.list_all.tagged_with(params[:tag]).search(params[:search])
    @posts = @search.all
  else
    @search = Post.list_all.search(params[:search])
    @posts = @search.all
  end

  respond_with @posts
end

#showObject



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
# File 'app/controllers/posts_controller.rb', line 31

def show
  ActiveSupport::Notifications.instrument("rdcms.post.show", :params => params)
  before_init

  if serve_iframe?
    respond_to do |format|
      format.html { render layout: "/rdcms/bare_layout" }
    end
  elsif serve_basic_post?
    initialize_post(@post)
    Post.load_liquid_methods(location: session[:user_location], post: @post, params: params)

    load_associated_model_into_liquid() if can_load_associated_model?
    after_init()

    if generate_index_list?
      @list_of_posts = get_posts_by_post_type
      include_related_models()
      get_posts_with_tags() if @post.index_of_posts_tagged_with.present?
      get_posts_without_tags() if @post.not_tagged_with.present?
      get_posts_by_frontend_tags() if params[:frontend_tags].present?
      sort_response()
      after_index()
    end

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

#show_cache_pathObject



79
80
81
82
83
84
85
86
# File 'app/controllers/posts_controller.rb', line 79

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.post.max_cache_24h") == "true" ? Date.today.strftime("%Y%m%d") : "no_date"
  art_cache = @post ? @post.cache_key : "no_art"
  user_cache = current_user.present? ? current_user.id : "no_user"

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

#sitemapObject



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

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

#tag_listObject



120
121
122
# File 'app/controllers/posts_controller.rb', line 120

def tag_list
  @tags = Post.tag_counts.order("count desc")
end