app/controllers/skyline/application_controller.rb in skylinecms-3.0.8 vs app/controllers/skyline/application_controller.rb in skylinecms-3.1.0

- old
+ new

@@ -1,21 +1,31 @@ class Skyline::ApplicationController < ApplicationController include Skyline::TranslationHelper + before_filter :set_locale before_filter :authenticate_user, :identifier => :authentication + before_filter :handle_user_preferences, :identifier => :preferences before_filter :authorize_user_for_action, :identifier => :authorization around_filter Skyline::ArticleVersionObserver.instance - class_inheritable_accessor :default_menu_item - protected :default_menu_item, :default_menu_item= + class_inheritable_accessor :default_menu + attr_accessor :current_menu + hide_action :default_menu, :default_menu=, :current_menu, :current_menu=, :menu + # Load all helpers Dir[Skyline.root + "app/helpers/**/*_helper.rb"].each do |helper| helper helper.sub(Skyline.root + "app/helpers/","").sub(/_helper\.rb$/,"") - end + end + # Load all plugin helpers so they can override stuff. + Dir[Skyline::PluginsManager.plugin_path + "*/app/helpers/**/*_helper.rb"].each do |helper| + helper helper.sub(/^#{Regexp.escape(Skyline::PluginsManager.plugin_path.to_s)}\/?.+?\/app\/helpers\//,"").sub(/_helper\.rb$/,"") + end + + class << self # Authorize a list of actions by a certain right # # ==== Parameters @@ -55,13 +65,19 @@ break end end self.filter_chain.send(:update_filter_chain,filters, :before,pos+1, &block) end + end protected + + # Sets locale according to the configuration on every request + def set_locale + I18n.locale = Skyline::Configuration.locale.present? ? Skyline::Configuration.locale : "en-US" + end def default_url_options(options=nil) return if options.nil? if options[:id].andand.kind_of?(Skyline::Article) {:type => options[:id].class} @@ -90,10 +106,30 @@ return redirect_to(new_skyline_authentication_path) end end end + # Handle the user preferences + # -- + def handle_user_preferences + if cookies["skyline_up"].present? + up = ActiveSupport::JSON.decode(cookies["skyline_up"]) + + up.each do |k,v| + if k == "_delete" + v.each do |delete_id| + current_user.user_preferences.remove(delete_id) + end + else + current_user.user_preferences.set(k,v) + end + end + + cookies.delete("skyline_up") + end + end + # The authorization callback # -- def authorize_user_for_action authorizations = self.class.authorizations[self.action_name.to_sym] || self.class.authorizations[:*] if authorizations && authorizations.any? @@ -147,10 +183,10 @@ #-- def current_menu_item=(menuitem) @_menuitem = menuitem end def current_menu_item - @_menuitem || self.class.default_menu_item + @_menuitem || self.class.default_menu end helper_method :current_menu_item # A shortcut for messages store # Messages work just like Flashes, so you can do