Class: CamaleonCms::FrontendController

Inherits:
CamaleonController
  • Object
show all
Includes:
CamaleonCms::Frontend::ApplicationHelper, FrontendConcern, FrontendVisitedStateConcern
Defined in:
app/controllers/camaleon_cms/frontend_controller.rb

Constant Summary

Constants included from FrontendVisitedStateConcern

CamaleonCms::FrontendVisitedStateConcern::LEGACY_VISITED_IVAR_BY_ATTR

Instance Method Summary collapse

Methods included from CamaleonCms::Frontend::ApplicationHelper

#cama_url_to_fixed, #verify_front_visibility

Methods included from CamaleonCms::Frontend::ContentSelectHelper

#each_category_of, #each_post_of, #process_in_block, #the_comments, #the_content, #the_excerpt, #the_field, #the_post, #the_post_type, #the_posts, #the_slug, #the_thumbnail, #the_title, #the_url

Methods included from CamaleonCms::Frontend::SeoHelper

#cama_seo_settings, #cama_the_seo

Methods included from CamaleonCms::Frontend::NavMenuHelper

#breadcrumb_add, #breadcrumb_draw, #cama_menu_draw_items, #cama_menu_parse_items, #cama_parse_menu_item, #draw_menu, #get_nav_menu

Methods included from CamaleonCms::Frontend::SiteHelper

#is_ajax?, #is_category?, #is_home?, #is_page?, #is_post_tag?, #is_post_type?, #is_profile?, #is_search?, #site_current_path, #site_current_url, #the_head

Methods included from FrontendConcern

#robots, #rss, #save_comment, #sitemap

Instance Method Details

#ajaxObject

ajax requests



137
138
139
140
141
142
143
144
145
146
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 137

def ajax
  r = { render_file: nil, render_text: '', layout: nil }
  mark_frontend_ajax_visited
  hooks_run('on_ajax', r)
  if r[:render_file]
    render r[:render_file], (!r[:layout].nil? ? { layout: r[:layout] } : {})
  else
    render inline: r[:render_text]
  end
end

#categoryObject

render category list



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
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 30

def category
  begin
    if params[:category_slug].present?
      @category ||= current_site.the_full_categories.find_by_slug(params[:category_slug]).decorate # rubocop:disable Rails/DynamicFindBy
    end
    @category ||= current_site.the_full_categories.find(params[:category_id]).decorate
    @post_type = @category.the_post_type
  rescue StandardError
    return page_not_found
  end
  mark_frontend_category_visited(@category)
  @children = @category.children.no_empty.decorate
  @posts = @category.the_posts.paginate(page: params[:page],
                                        per_page: current_site.front_per_page).eager_load(:metas)
  category_slug = @category.the_slug

  # specific template category with specific slug within a post-type
  r_file = lookup_context.template_exists?("category_#{category_slug}") ? "category_#{category_slug}" : nil
  post_type_slug = "post_types/#{@post_type.the_slug}"
  if r_file.blank?
    r_file = lookup_context.template_exists?("#{post_type_slug}/category") ? "#{post_type_slug}/category" : nil
  end
  if r_file.blank?
    r_file = if lookup_context.template_exists?("categories/#{category_slug}")
               "categories/#{category_slug}"
             else
               'category'
             end
  end

  layout_ = if lookup_context.template_exists?("layouts/#{post_type_slug}/category")
              "#{post_type_slug}/category"
            elsif lookup_context.template_exists?("layouts/categories/#{category_slug}")
              "categories/#{category_slug}"
            end
  r = { category: @category, layout: layout_, render: r_file }
  hooks_run('on_render_category', r)
  render r[:render], (!r[:layout].nil? ? { layout: r[:layout] } : {})
end

#indexObject

home page for frontend



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

def index
  mark_frontend_home_visited
  if @_site_options[:home_page].present?
    render_post(@_site_options[:home_page].to_i)
  else
    r = { layout: nil, render: 'index' }
    hooks_run('on_render_index', r)
    render r[:render], (!r[:layout].nil? ? { layout: r[:layout] } : {})
  end
end

#postObject

render a post



149
150
151
152
153
154
155
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 149

def post
  if params[:draft_id].present?
    draft_render
  else
    render_post(@post || params[:slug].to_s.split('/').last, true)
  end
end

#post_tagObject

render contents for the post tag



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 93

def 
  begin
    @post_tag = if params[:post_tag_slug].present?
                  current_site..find_by_slug(params[:post_tag_slug]).decorate # rubocop:disable Rails/DynamicFindBy
                else
                  current_site..find(params[:post_tag_id]).decorate
                end
    @post_type = @post_tag.the_post_type
  rescue StandardError
    return page_not_found
  end
  @object = @post_tag
  CurrentRequest.frontend_object = @object
  mark_frontend_tag_visited(@post_tag)
  @posts = @post_tag.the_posts.paginate(page: params[:page],
                                        per_page: current_site.front_per_page).eager_load(:metas)
   = "post_types/#{@post_type.the_slug}/post_tag"
  r_file = lookup_context.template_exists?() ?  : 'post_tag'
  layout_ = lookup_context.template_exists?('layouts/post_tag') ? 'post_tag' : nil
  r = { post_tag: @post_tag, layout: layout_, render: r_file }
  hooks_run('on_render_post_tag', r)
  render r[:render], (!r[:layout].nil? ? { layout: r[:layout] } : {})
end

#post_typeObject

render contents from post type



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

def post_type
  begin
    @post_type = current_site.post_types.find_by_slug(params[:post_type_slug]).decorate # rubocop:disable Rails/DynamicFindBy
  rescue StandardError
    return page_not_found
  end
  @object = @post_type
  CurrentRequest.frontend_object = @object
  mark_frontend_post_type_visited(@post_type)
  @posts = @post_type.the_posts.paginate(page: params[:page],
                                         per_page: current_site.front_per_page).eager_load(:metas)
  @categories = @post_type.categories.no_empty.eager_load(:metas).decorate
  @post_tags = @post_type..eager_load(:metas)
  post_type_slug = "post_types/#{@post_type.the_slug}"
  r_file = lookup_context.template_exists?(post_type_slug) ? post_type_slug : 'post_type'
  layout_ = lookup_context.template_exists?("layouts/#{post_type_slug}") ? post_type_slug : nil
  r = { post_type: @post_type, layout: layout_, render: r_file }
  hooks_run('on_render_post_type', r)
  render r[:render], (!r[:layout].nil? ? { layout: r[:layout] } : {})
end

#profileObject

render user profile



158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 158

def profile
  begin
    @user = current_site.users.find(params[:user_id]).decorate
  rescue StandardError
    return page_not_found
  end
  @object = @user
  CurrentRequest.frontend_object = @object
  mark_frontend_profile_visited(@user)
  layout_ = lookup_context.template_exists?('layouts/profile') ? 'profile' : nil
  r = { user: @user, layout: layout_, render: 'profile' }
  hooks_run('on_render_profile', r)
  render r[:render], (!r[:layout].nil? ? { layout: r[:layout] } : {})
end

#render_page_not_foundObject

render page not found



174
175
176
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 174

def render_page_not_found
  page_not_found
end

#searchObject

search contents



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 118

def search
  breadcrumb_add(ct('search'))
  post_type_slugs = params[:post_type_slugs]
  items = post_type_slugs.present? ? current_site.the_posts(post_type_slugs.split(',')) : current_site.the_posts
  mark_frontend_search_visited
  @param_search = params[:q]
  layout_ = lookup_context.template_exists?('layouts/search') ? 'search' : nil
  r = { layout: layout_, render: 'search', posts: nil }
  hooks_run('on_render_search', r)
  q_params = params[:q].to_s.downcase
  params[:q] = q_params
  @posts = r[:posts] ||
           items.where('LOWER(title) LIKE ? OR LOWER(content_filtered) LIKE ?', "%#{q_params}%", "%#{q_params}%")
  @posts_size = @posts.size
  @posts = @posts.paginate(page: params[:page], per_page: current_site.front_per_page)
  render r[:render], (!r[:layout].nil? ? { layout: r[:layout] } : {})
end