# Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base filter_parameter_logging :password helper_method :locales, :newsletter_subscription, :crypted_subscriptions_path, :featured_product, :blog_url, :upgrade_url, :dropdown_products, :order_products, :all_products, :blog_posts, :latest_news, :latest_comic, :dropdown_categorized_products, :have_articles? #include ExceptionNotifiable include ExceptionNotification::Notifiable # kvuli super_exception_notifier # bez tohoto se vypisuje chybova stranka do layoutu prislusejiciho ke controlleru @@error_layout = "application" protect_from_forgery # See ActionController::RequestForgeryProtection for details before_filter :enable_or_disable_cdn helper :rails_wordpress # disable cnd for certain parts of the application (/admin) and re-enable it if needed def enable_or_disable_cdn if defined?(CloudfrontAssetHost) && CloudfrontAssetHost.enabled if request.path.starts_with?('/admin') && ActionController::Base.asset_host.present? CloudfrontAssetHost.disable! elsif !request.path.starts_with?('/admin') && ActionController::Base.asset_host.blank? CloudfrontAssetHost.enable! end end end def upgrade_url(code) root_url + "upgrade/#{StaticPage[code].url_param}" end # do newsletter engine def crypted_subscriptions_path(contact) subscriptions_url + "?contact=" + UrlParamCrypt.encrypt(contact.id) end def newsletter_subscription(location_code = nil) subscription = Subscription.new subscription.subscription_location = SubscriptionLocation[location_code] if location_code subscription end def latest_comic @latest_comic ||= Comic.latest end def blog_url @blog_url ||= WpOption["siteurl"].value end def dropdown_products @dropdown_products ||= [featured_product] + Promotion['dropdown'].products.all_ordered end def order_products @order_products ||= ProductCategory.non_free_products end def featured_product @featured_product ||= Product[Settings.featured_product] end def all_products @all_products ||= Product.all_ordered end def blog_posts @blog_posts ||= WpBlogPost.find(:all, :limit => Settings.home.blog_posts) end def latest_news @latest_news ||= begin latests = (Latest.find_latest + Release.find_latest).sort {|x, y| x.date <=> y.date } latests.reverse.slice(0, Settings.home.latest) end end def dropdown_categorized_products @dropdown_categorized_products ||= [].tap do |a| ProductCategory.all.each do |product_category| products = [] dropdown_products.each do |dropdown_product| products << dropdown_product if dropdown_product.product_category == product_category end #products.unshift(featured_product) if featured_product.product_category == product_category a << { :category => product_category.name, :products => products } unless products.empty? end end end def have_articles? !Article.published.empty? end end