Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed application controller name into camaleon controller #21

Merged
merged 1 commit into from Aug 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -8,7 +8,7 @@

# Requirements
* Rails 4+
* Mysql 5+ or Sqlite or Postgres
* MySQL 5+ or Sqlite or PostgreSQL
* Ruby 1.9.3+
* Imagemagick

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/installers_controller.rb
Expand Up @@ -6,7 +6,7 @@
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.
=end
class Admin::InstallersController < ApplicationController
class Admin::InstallersController < CamaleonController
skip_before_action :site_check_existence
skip_before_action :before_actions
skip_after_action :after_actions
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/sessions_controller.rb
Expand Up @@ -6,7 +6,7 @@
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.
=end
class Admin::SessionsController < ApplicationController
class Admin::SessionsController < CamaleonController
skip_before_filter :authenticate
before_action :before_hook_session
after_action :after_hook_session
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin_controller.rb
Expand Up @@ -6,7 +6,7 @@
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.
=end
class AdminController < ApplicationController
class AdminController < CamaleonController
rescue_from CanCan::AccessDenied do |exception|
flash[:error] = "Error: #{exception.message}"
redirect_to admin_dashboard_path
Expand Down
79 changes: 0 additions & 79 deletions app/controllers/application_controller.rb
@@ -1,84 +1,5 @@
=begin
Camaleon CMS is a content management system
Copyright (C) 2015 by Owen Peredo Diaz
Email: owenperedo@gmail.com
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.
=end
class ApplicationController < ActionController::Base
include ApplicationHelper
include SessionHelper
include SiteHelper
include HtmlHelper
include UserRolesHelper
include ShortCodeHelper
include PluginsHelper
include ThemeHelper
include HooksHelper
include ContentHelper
include CaptchaHelper
include UploaderHelper
include Mobu::DetectMobile

before_action :site_check_existence
before_action :before_actions
after_action :after_actions
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

layout Proc.new { |controller| controller.request.xhr? ? false : 'default' }

# show page error
def render_error(status = 404, exception = nil)
Rails.logger.info "====================#{caller.inspect}"
render :file => "public/#{status}.html", :status => status, :layout => false
end

# generate captcha image
def captcha
image = captcha_build(params[:len])
send_data image.to_blob, :type => image.mime_type, :disposition => 'inline'
end

private
def before_actions
# including all helpers (system, themes, plugins) for this site
PluginRoutes.enabled_apps(current_site).each{|plugin| plugin_load_helpers(plugin) }

# set default cache directory for current site
cache_store.cache_path = File.join(cache_store.cache_path.split("site-#{current_site.id}").first, "site-#{current_site.id}")
# Rails.cache.write("#{current_site.id}-#{Time.now}", 1)


# initializing short codes
shortcodes_init()

# initializing before and after contents
html_helpers_init

# initializing before and after contents
content_init

@_hooks_skip = []
# trigger all hooks before_load_app
hooks_run("app_before_load")

request.env.except!('HTTP_X_FORWARDED_HOST') if request.env['HTTP_X_FORWARDED_HOST'] # just drop the variable

# views path for plugins
self.append_view_path(Rails.root.join("app", "apps", 'plugins'))
end

def after_actions
# trigger all actions app after load
hooks_run("app_after_load")
end

# redirect to sessions login form when the session was expired.
def auth_session_error
redirect_to root_path
end

end
84 changes: 84 additions & 0 deletions app/controllers/camaleon_controller.rb
@@ -0,0 +1,84 @@
=begin
Camaleon CMS is a content management system
Copyright (C) 2015 by Owen Peredo Diaz
Email: owenperedo@gmail.com
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.
=end
class CamaleonController < ApplicationController
include CamaleonHelper
include SessionHelper
include SiteHelper
include HtmlHelper
include UserRolesHelper
include ShortCodeHelper
include PluginsHelper
include ThemeHelper
include HooksHelper
include ContentHelper
include CaptchaHelper
include UploaderHelper
include Mobu::DetectMobile

before_action :site_check_existence
before_action :before_actions
after_action :after_actions
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

layout Proc.new { |controller| controller.request.xhr? ? false : 'default' }

# show page error
def render_error(status = 404, exception = nil)
Rails.logger.info "====================#{caller.inspect}"
render :file => "public/#{status}.html", :status => status, :layout => false
end

# generate captcha image
def captcha
image = captcha_build(params[:len])
send_data image.to_blob, :type => image.mime_type, :disposition => 'inline'
end

private
def before_actions
# including all helpers (system, themes, plugins) for this site
PluginRoutes.enabled_apps(current_site).each{|plugin| plugin_load_helpers(plugin) }

# set default cache directory for current site
cache_store.cache_path = File.join(cache_store.cache_path.split("site-#{current_site.id}").first, "site-#{current_site.id}")
# Rails.cache.write("#{current_site.id}-#{Time.now}", 1)


# initializing short codes
shortcodes_init()

# initializing before and after contents
html_helpers_init

# initializing before and after contents
content_init

@_hooks_skip = []
# trigger all hooks before_load_app
hooks_run("app_before_load")

request.env.except!('HTTP_X_FORWARDED_HOST') if request.env['HTTP_X_FORWARDED_HOST'] # just drop the variable

# views path for plugins
self.append_view_path(Rails.root.join("app", "apps", 'plugins'))
end

def after_actions
# trigger all actions app after load
hooks_run("app_after_load")
end

# redirect to sessions login form when the session was expired.
def auth_session_error
redirect_to root_path
end

end
2 changes: 1 addition & 1 deletion app/controllers/frontend_controller.rb
Expand Up @@ -6,7 +6,7 @@
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.
=end
class FrontendController < ApplicationController
class FrontendController < CamaleonController
include FrontendConcern
prepend_before_action :init_frontent
prepend_before_action :site_check_existence
Expand Down
65 changes: 1 addition & 64 deletions app/helpers/application_helper.rb
@@ -1,65 +1,2 @@
=begin
Camaleon CMS is a content management system
Copyright (C) 2015 by Owen Peredo Diaz
Email: owenperedo@gmail.com
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.
=end
module ApplicationHelper

# send and email
# email: email to
# subject: Subject of the email
# content: content of the email
# from: email figured as from
# attachs: array of files to be attached to the email
# template_path: path of the template to render
# template_name: template name to render in template_path
def sendmail(email,subject='Tiene una notificacion',content='',from=nil,attachs=[],current_site=@current_site, template_path='html_mailer',template_name='sender')
from = current_site.get_option('email') if from.nil?
from = current_site.users.admin_scope.first.email if from.nil?
HtmlMailer.sender(email, "#{subject} - #{@current_site.the_title}", content, "#{@current_site.the_title}"+"<#{from}>" , attachs, root_url, current_site, template_path,template_name).deliver_now
end

# execute controller action and return response
def requestAction(controller,action,params={})
controller.class_eval{
def params=(params); @params = params end
def params; @params end
}
c = controller.new
c.request = @_request
c.response = @_response
c.params = params
c.send(action)
c.response.body
end

# deprecated helper
def array_change_key_case(hash)
result = hash.inject({}) do |hash, keys|
hash[raw(keys[1])] = keys[0]
hash
end
end

# theme common translation text
# key: key for translation
# language: language for the translation, if it is nil, then will use current site language
# valid only for common translations, If you can to use other translations for themes or plugins,
# you can use the default of rails (I18n.t)
def ct(key, language = nil)
language = language || I18n.locale
r = {flag: false, key: key, translation: "", locale: language.to_sym}
hooks_run("on_translation", r)
return r[:translation] if r[:flag]
translate("common.#{key}", locale: language)
end

# check if current request was for admin panel
def is_admin_request?
!(@_admin_menus.nil?)
end

end
end
65 changes: 65 additions & 0 deletions app/helpers/camaleon_helper.rb
@@ -0,0 +1,65 @@
=begin
Camaleon CMS is a content management system
Copyright (C) 2015 by Owen Peredo Diaz
Email: owenperedo@gmail.com
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.
=end
module CamaleonHelper

# send and email
# email: email to
# subject: Subject of the email
# content: content of the email
# from: email figured as from
# attachs: array of files to be attached to the email
# template_path: path of the template to render
# template_name: template name to render in template_path
def sendmail(email,subject='Tiene una notificacion',content='',from=nil,attachs=[],current_site=@current_site, template_path='html_mailer',template_name='sender')
from = current_site.get_option('email') if from.nil?
from = current_site.users.admin_scope.first.email if from.nil?
HtmlMailer.sender(email, "#{subject} - #{@current_site.the_title}", content, "#{@current_site.the_title}"+"<#{from}>" , attachs, root_url, current_site, template_path,template_name).deliver_now
end

# execute controller action and return response
def requestAction(controller,action,params={})
controller.class_eval{
def params=(params); @params = params end
def params; @params end
}
c = controller.new
c.request = @_request
c.response = @_response
c.params = params
c.send(action)
c.response.body
end

# deprecated helper
def array_change_key_case(hash)
result = hash.inject({}) do |hash, keys|
hash[raw(keys[1])] = keys[0]
hash
end
end

# theme common translation text
# key: key for translation
# language: language for the translation, if it is nil, then will use current site language
# valid only for common translations, If you can to use other translations for themes or plugins,
# you can use the default of rails (I18n.t)
def ct(key, language = nil)
language = language || I18n.locale
r = {flag: false, key: key, translation: "", locale: language.to_sym}
hooks_run("on_translation", r)
return r[:translation] if r[:flag]
translate("common.#{key}", locale: language)
end

# check if current request was for admin panel
def is_admin_request?
!(@_admin_menus.nil?)
end

end