Class: CamaleonCms::FrontendController

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

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

Methods inherited from CamaleonController

#captcha, #render_error

Methods included from EmailHelper

#cama_send_email, #cama_send_mail_to_admin, #send_email, #send_password_reset_email, #send_user_confirm_email

Methods included from HooksHelper

#hook_run, #hook_skip, #hooks_run

Methods included from PluginsHelper

#current_plugin, #plugin_asset_path, #plugin_asset_url, #plugin_destroy, #plugin_install, #plugin_layout, #plugin_load_helpers, #plugin_uninstall, #plugin_upgrade, #plugin_view, #plugins_initialize, #self_plugin_key

Methods included from SiteHelper

#cama_current_site_host_port, #cama_get_list_layouts_files, #cama_get_list_template_files, #cama_is_test_request?, #current_locale, #current_site, #current_theme, #site_after_install, #site_install_theme, #site_uninstall_theme

Methods included from UploaderHelper

#cama_crop_image, #cama_file_path_to_url, #cama_resize_and_crop, #cama_resize_upload, #cama_tmp_upload, #cama_uploader, #cama_uploader_generate_thumbnail, #cama_url_to_file_path, #slugify, #slugify_folder, #upload_file, #uploader_verify_name

Methods included from CamaleonHelper

#cama_cache_fetch, #cama_draw_timer, #cama_edit_link, #cama_is_admin_request?, #cama_pluralize_text, #cama_requestAction, #cama_sitemap_cats_generator, #cama_t, #ct

Methods included from CaptchaHelper

#cama_captcha_build, #cama_captcha_increment_attack, #cama_captcha_reset_attack, #cama_captcha_tag, #cama_captcha_tags_if_under_attack, #cama_captcha_total_attacks, #cama_captcha_under_attack?, #cama_captcha_verified?, #captcha_verify_if_under_attack

Methods included from ContentHelper

#cama_content_after_draw, #cama_content_append, #cama_content_before_draw, #cama_content_init, #cama_content_prepend

Methods included from ThemeHelper

#self_theme_key, #theme_asset_file_path, #theme_asset_path, #theme_asset_url, #theme_home_page, #theme_init, #theme_layout, #theme_view

Methods included from ShortCodeHelper

#cama_strip_shortcodes, #do_shortcode, #render_shortcode, #shortcode_add, #shortcode_change_template, #shortcode_delete, #shortcodes_init

Methods included from UserRolesHelper

#cama_get_roles_values

Methods included from HtmlHelper

#append_asset_content, #append_asset_libraries, #append_pre_asset_content, #cama_assets_library_register, #cama_draw_custom_assets, #cama_draw_pre_asset_contents, #cama_get_options_html_from_items, #cama_html_helpers_init, #cama_html_tooltip, #cama_load_libraries

Methods included from SessionHelper

#cama_authenticate, #cama_current_role, #cama_current_user, #cama_get_session_id, #cama_logout_user, #cama_on_heroku?, #cama_register_user, #cama_sign_in?, #cookie_auth_token_complete?, #cookie_split_auth_token, #login_user, #login_user_with_password, #session_back_to_parent, #session_switch_user, #user_auth_token_from_cookie

Instance Method Details

#ajaxObject

ajax requests



125
126
127
128
129
130
131
132
133
134
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 125

def ajax
  r = { render_file: nil, render_text: '', layout: nil }
  @cama_visited_ajax = true
  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
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 30

def category
  begin
    @category ||= current_site.the_full_categories.find_by_slug(params[:category_slug]).decorate if params[:category_slug].present?
    @category ||= current_site.the_full_categories.find(params[:category_id]).decorate
    @post_type = @category.the_post_type
  rescue StandardError
    return page_not_found
  end
  @cama_visited_category = @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)
  r_file = lookup_context.template_exists?("category_#{@category.the_slug}") ? "category_#{@category.the_slug}" : nil # specific template category with specific slug within a posttype
  unless r_file.present?
    r_file = lookup_context.template_exists?("post_types/#{@post_type.the_slug}/category") ? "post_types/#{@post_type.the_slug}/category" : nil
  end
  unless r_file.present?
    r_file = lookup_context.template_exists?("categories/#{@category.the_slug}") ? "categories/#{@category.the_slug}" : 'category'
  end

  layout_ = if lookup_context.template_exists?("layouts/post_types/#{@post_type.the_slug}/category")
              "post_types/#{@post_type.the_slug}/category"
            elsif lookup_context.template_exists?("layouts/categories/#{@category.the_slug}")
              "categories/#{@category.the_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
  @cama_visited_home = true
  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



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

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



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 81

def 
  begin
    @post_tag = if params[:post_tag_slug].present?
                  current_site..find_by_slug(params[:post_tag_slug]).decorate
                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
  @cama_visited_tag = @post_tag
  @posts = @post_tag.the_posts.paginate(page: params[:page],
                                        per_page: current_site.front_per_page).eager_load(:metas)
  r_file = lookup_context.template_exists?("post_types/#{@post_type.the_slug}/post_tag") ? "post_types/#{@post_type.the_slug}/post_tag" : '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



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 61

def post_type
  begin
    @post_type = current_site.post_types.find_by_slug(params[:post_type_slug]).decorate
  rescue StandardError
    return page_not_found
  end
  @object = @post_type
  @cama_visited_post_type = @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)
  r_file = lookup_context.template_exists?("post_types/#{@post_type.the_slug}") ? "post_types/#{@post_type.the_slug}" : 'post_type'
  layout_ = lookup_context.template_exists?("layouts/post_types/#{@post_type.the_slug}") ? "post_types/#{@post_type.the_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



146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 146

def profile
  begin
    @user = current_site.users.find(params[:user_id]).decorate
  rescue StandardError
    return page_not_found
  end
  @object = @user
  @cama_visited_profile = true
  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



161
162
163
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 161

def render_page_not_found
  page_not_found
end

#searchObject

search contents



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 104

def search
  breadcrumb_add(ct('search'))
  items = params[:post_type_slugs].present? ? current_site.the_posts(params[:post_type_slugs].split(',')) : current_site.the_posts
  @cama_visited_search = true
  @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)
  params[:q] = (params[:q] || '').downcase
  @posts = if !r[:posts].nil?
             r[:posts]
           else
             items.where('LOWER(title) LIKE ? OR LOWER(content_filtered) LIKE ?',
                         "%#{params[:q]}%", "%#{params[:q]}%")
           end
  @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