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 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?, #login_user, #login_user_with_password, #session_back_to_parent, #session_switch_user

Instance Method Details

#ajaxObject

ajax requests



97
98
99
100
101
102
103
104
105
106
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 97

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



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 22

def category
  begin
    @category = current_site.the_full_categories.find(params[:category_id]).decorate
    @post_type = @category.the_post_type
  rescue
    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
  r_file = lookup_context.template_exists?("post_types/#{@post_type.the_slug}/category") ? "post_types/#{@post_type.the_slug}/category" : nil unless r_file.present? # default template category for all categories within a posttype
  r_file = lookup_context.template_exists?("categories/#{@category.the_slug}") ? "categories/#{@category.the_slug}" : 'category' unless r_file.present?  # default template category for all categories for all posttypes

  layout_ = lookup_context.template_exists?("layouts/post_types/#{@post_type.the_slug}/category") ? "post_types/#{@post_type.the_slug}/category" : nil unless layout_.present? # layout for all categories within a posttype
  layout_ = lookup_context.template_exists?("layouts/categories/#{@category.the_slug}") ? "categories/#{@category.the_slug}" : nil unless layout_.present? # layout for categories for all post types
  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



11
12
13
14
15
16
17
18
19
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 11

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



109
110
111
112
113
114
115
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 109

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



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

def 
  begin
    if params[:post_tag_slug].present?
      @post_tag = current_site..find_by_slug(params[:post_tag_slug]).decorate
    else
      @post_tag = current_site..find(params[:post_tag_id]).decorate
    end
    @post_type = @post_tag.the_post_type
  rescue
    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



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 43

def post_type
  begin
    @post_type = current_site.post_types.find_by_slug(params[:post_type_slug]).decorate
  rescue
    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



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

def profile
  begin
    @user = current_site.users.find(params[:user_id]).decorate
  rescue
    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



132
133
134
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 132

def render_page_not_found
  page_not_found
end

#searchObject

search contents



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 82

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 = r[:posts] != nil ? r[:posts] : items.where("LOWER(title) LIKE ? OR LOWER(content_filtered) LIKE ?", "%#{params[:q]}%", "%#{params[:q]}%")
  @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