public
Fork of vigetlabs/crash_cart
Description: Tools to manage ExpressionEngine ... maybe.
Clone URL: git://github.com/reagent/crash_cart.git
Search Repo:
reagent (author)
Tue May 13 19:55:27 -0700 2008
commit  ad013784e472c6104e62dbe7f46466b52e1d125a
tree    a8b03574c992015f1aa4b0a743b2ef80c37560c2
parent  4ecef0ec4bc52b1abd774e97bb1dec9870733b06
100644 65 lines (52 sloc) 1.645 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
module ExpressionEngine
  module Models
 
    class Site < ActiveRecord::Base
      set_table_name 'exp_sites'
      set_primary_key 'site_id'
      
      has_many :template_groups
      has_many :templates
 
      PREFERENCE_PATHS = [
        'system:theme_folder_path',
        'system:captcha_path',
        'template:tmpl_file_basepath',
        'member:avatar_path',
        'member:photo_path'
      ]
 
      def name
        self.site_label
      end
      
      def slug
        self.site_name
      end
     
      def preferences
        if @preferences.nil?
          @preferences = {}
          [:system, :mailing_list, :member, :template, :weblog].each do |key|
            method = 'site_' + key.to_s.gsub('_', '') + '_preferences'
            @preferences[key] = ExpressionEngine::Preference.new(self.send(method))
          end
        end
        @preferences
      end
 
      def root_path=(other)
        pattern = Regexp.quote(self.root_path)
        PREFERENCE_PATHS.each do |preference|
          group, setting = preference.split(':')
          self.preferences[group.to_sym][setting.to_sym].gsub!(/^#{pattern}/, other)
        end
      end
 
      def root_path
        common_elements = nil
        
        PREFERENCE_PATHS.each do |preference|
          group, setting = preference.split(':')
          path = self.preferences[group.to_sym][setting.to_sym].split('/')
 
          unless path.empty?
            common_elements = path if common_elements.nil?
            common_elements = common_elements & path
          end
        end
        
        common_elements.join('/')
      end
      
    end
    
  end
end