Class: CamaleonCms::FrontendController

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

Overview

Camaleon CMS is a content management system

Copyright (C) 2015 by Owen Peredo Diaz
Email: [email protected]
This program is free software: you can redistribute it and/or modify   it under the terms of the GNU Affero General Public License as  published by the Free Software Foundation, either version 3 of the  License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the  GNU Affero General Public License (GPLv3) for more details.

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, #send_email, #send_password_reset_email, #send_user_confirm_email

Methods included from UploaderHelper

#cama_crop_image, #cama_file_path_to_url, #cama_media_find_folder, #cama_media_search_file, #cama_resize_and_crop, #cama_resize_upload, #cama_tmp_upload, #cama_uploader_add_folder, #cama_uploader_check_name, #cama_uploader_destroy_file, #cama_uploader_destroy_folder, #cama_uploader_generate_thumbnail, #cama_uploader_init_connection, #cama_uploader_parse_file, #cama_url_to_file_path, #cama_verify_format, #upload_file, #uploader_verify_name

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 HooksHelper

#hook_run, #hook_skip, #hooks_run

Methods included from ThemeHelper

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

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 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_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_custom_assets, #cama_load_libraries

Methods included from SiteHelper

#cama_get_list_layouts_files, #cama_get_list_template_files, #cama_site_check_existence, #current_locale, #current_site, #current_theme, #site_after_install, #site_console_switch, #site_install_theme, #site_load_custom_models, #site_uninstall_theme

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

Methods included from CamaleonHelper

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

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: (self.send :_layout) }
  @cama_visited_ajax = true
  hooks_run("on_ajax", r)
  if r[:render_file]
    render r[:render_file], layout: r[:layout]
  else
    render inline: r[:render_text]
  end
end

#categoryObject

render category list



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 33

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?("categories/#{@category.the_slug}") ? "categories/#{@category.the_slug}" : "category"
  layout_ = lookup_context.template_exists?("layouts/categories/#{@category.the_slug}") ? "categories/#{@category.the_slug}" : (self.send :_layout)
  r = {category: @category, layout: layout_, render: r_file}; hooks_run("on_render_category", r)
  render r[:render], layout: r[:layout]
end

#indexObject

home page for frontend



21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 21

def index
  @cama_visited_home = true
  if @_site_options[:home_page].present?
    render_post(@_site_options[:home_page].to_i)
  else
    r = {layout: (self.send :_layout), render: "index"}
    hooks_run("on_render_index", r)
    render r[:render], 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



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 67

def 
  begin
    @post_tag = current_site..find(params[:post_tag_id]).decorate
    @post_type = @post_tag.the_post_type
  rescue
    return page_not_found
  end
  @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_tags/#{@post_tag.the_slug}") ? "post_tags/#{@post_tag.the_slug}" : "post_tag"
  layout_ = lookup_context.template_exists?("layouts/post_tags/#{@post_tag.the_slug}") ? "post_tags/#{@post_tag.the_slug}" : (self.send :_layout)
  r = {post_tag: @post_tag, layout: layout_, render: r_file}; hooks_run("on_render_post_tag", r)
  render r[:render], layout: r[:layout]
end

#post_typeObject

render contents from post type



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/camaleon_cms/frontend_controller.rb', line 50

def post_type
  begin
    @post_type = current_site.post_types.find(params[:post_type_id]).decorate
  rescue
    return page_not_found
  end
  @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}" : (self.send :_layout)
  r = {post_type: @post_type, layout: layout_, render: r_file};  hooks_run("on_render_post_type", r)
  render r[:render], layout: r[:layout]
end

#profileObject

render user profile



118
119
120
121
122
123
124
125
126
127
128
# 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
  @cama_visited_profile = true
  layout_ = lookup_context.template_exists?("layouts/profile") ? "profile" : (self.send :_layout)
  r = {user: @user, layout: layout_, render: "profile"};  hooks_run("on_render_profile", r)
  render r[:render], layout: r[:layout]
end

#searchObject

search contents



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

def search
  breadcrumb_add(ct("search"))
  @cama_visited_search = true
  @param_search = params[:q]
  layout_ = lookup_context.template_exists?("layouts/search") ? "search" : (self.send :_layout)
  r = {layout: layout_, render: "search", posts: nil}; hooks_run("on_render_search", r)
  params[:q] = (params[:q] || '').downcase
  @posts = r[:posts] != nil ? r[:posts] : current_site.the_posts.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], layout: r[:layout]
end