public
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/halorgium/mephisto.git
francois (author)
Mon Mar 10 20:03:37 -0700 2008
commit  a0ce1ae632eba963b678dd36b3b67b7a04d42f59
tree    b84c3e3001e17152339598b254c7e4ce857ab8fb
parent  429ecf2948716ebb2905174653643eba4299a97e parent  752c317ef3e42ccd14c4cb53a8ca7c37734513ac
mephisto / app / controllers / application.rb
100644 84 lines (70 sloc) 2.669 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
class ApplicationController < ActionController::Base
  require_dependency 'application/errors'
  include AuthenticatedSystem
  before_filter :login_from_cookie
 
  include Mephisto::CachingMethods
  before_filter :set_cache_root
  helper_method :site
  attr_reader :site
 
  auto_include!
 
  def self.inherited(klass)
    super
    klass.auto_include!
  end
  
  filter_parameter_logging "password"
  
  protected
    helper_method :admin?
    helper_method :global_admin?
    
    def admin?
      logged_in? && (current_user.admin? || current_user.site_admin?)
    end
  
    def global_admin?
      logged_in? && current_user.admin?
    end
      
    # so not the best place for this...
    def asset_image_args_for(asset, thumbnail = :tiny, options = {})
      thumb_size = Array.new(2).fill(Asset.attachment_options[:thumbnails][thumbnail].to_i).join('x')
      options = options.reverse_merge(:title => "#{asset.title} \n #{asset.tags.join(', ')}", :size => thumb_size)
      if asset.movie?
        ['/images/mephisto/icons/video.png', options]
      elsif asset.audio?
        ['/images/mephisto/icons/audio.png', options]
      elsif asset.pdf?
        ['/images/mephisto/icons/pdf.png', options]
      elsif asset.other?
        ['/images/mephisto/icons/doc.png', options]
      elsif asset.thumbnails_count.zero?
        [asset.public_filename, options]
      else
        [asset.public_filename(thumbnail), options]
      end
    end
    helper_method :asset_image_args_for
 
    [:utc_to_local, :local_to_utc].each do |meth|
      define_method meth do |time|
        site.timezone.send(meth, time)
      end
      helper_method meth
    end
 
    def render_liquid_template_for(template_type, assigns = {})
      headers["Content-Type"] ||= 'text/html; charset=utf-8'
      if assigns['articles'] && assigns['article'].nil?
        # use collect so it doesn't modify @articles
        assigns['articles'] = assigns['articles'].collect &:to_liquid
      end
      status = (assigns.delete(:status) || :ok)
      @liquid_assigns = assigns
      render :text => site.call_render(@section, template_type, assigns, self), :status => status
    end
 
    def set_cache_root
      host = request.domain(request.subdomains.size + (request.subdomains.first == 'www' ? 0 : 1))
      @site ||= Site.find_by_host(host) || Site.find(:first, :order => 'id') || raise(ActiveRecord::RecordNotFound, "You need to create your first site!")
      self.class.page_cache_directory = site.page_cache_directory.to_s
    end
 
    def with_site_timezone
      old_tz = ENV['TZ']
      ENV['TZ'] = site.timezone.name
      yield
      ENV['TZ'] = old_tz
    end
 
end