Class: Gluttonberg::Setting

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/gluttonberg/setting.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generate_common_settingsObject

Generate common settings for gluttonberg If its not multisite case then it only creates one set of settings In case of multisite it creates one set of global settings and xx times for websited based settings



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
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/models/gluttonberg/setting.rb', line 49

def self.generate_common_settings
  cms_settings = {
    :number_of_revisions => ["10" , 6 , "Number of revisions to maintain for versioned contents."],
    :library_number_of_recent_assets => ["15" , 7 , "Number of recent assets in asset library."],
    :number_of_per_page_items => ["20" , 8 , "Number of per page items for any paginated content."],
    :enable_WYSIWYG => ["Yes" , 9 , "Enable WYSIWYG on textareas" , "Yes;No" ],
    :backend_logo => ["" , 10 , "Logo for backend" ] ,
    :auto_save_time => ["30" , 22 , "If editing is in progress then gluttonberg will auto save the form in XX seconds" ]
  }

  settings = {
    :video_assets => ["" , 13 , "FFMPEG settings" , "Enable;Disable"],
    :s3_key_id => ["" , 14 , "S3 Key ID"],
    :s3_access_key => ["" , 15 , "S3 Access Key"],
    :s3_server_url => ["" , 16 , "S3 Server URL"],
    :s3_bucket => ["" , 17 , "S3 Bucket Name"],
    :audio_assets => ["" , 18 , "Audio settings" , "Enable;Disable"],
    :comment_blacklist => ["" , 19 , "When a comment contains any of these words in its comment, Author Name, Author website, Author e-mail, it will be marked as spam. It will match inside words, so \"able\" will match \"comparable\". Please separate words with a comma."],
    :comment_email_as_spam => ["Yes" , 20 , "Do you want to mark those comments as spam which only contains emails and urls?" , "Yes;No" ],
    :comment_number_of_emails_allowed => ["2" , 21 , "How many email addresses should a comment include to be marked as spam?" ],
    :comment_number_of_urls_allowed => ["2" , 21 , "How many URLs should a comment include to be marked as spam?" ]
  }

  sitewise_settings = {
    :title => [ "" , 0, "Website Title"],
    :keywords => ["" , 1, "Please separate keywords with a comma."],
    :description => ["" ,2 , "The Description will appear in search engine's result list."],
    :fb_icon => ["" , 3 , "Facebook Icon for the website"],
    :google_analytics => ["", 4, "Google Analytics ID"],
    :from_email => ["" , 12 , "This email address is used for 'from' email address for all emails sent through system."],
    :restrict_site_access => ["" , 11 , "If this setting is provided then user needs to enter password to access public site."],
    :comment_notification => ["No" , 5 , "Enable comment notification" , "Yes;No" ]
  }

  self.generate_or_update_settings(cms_settings)
  self.generate_or_update_settings(settings)
  if Rails.configuration.multisite == false
    self.generate_or_update_settings(sitewise_settings)
  else
    Rails.configuration.multisite.each do |key, val|
      self.generate_or_update_settings(sitewise_settings, key)
    end
  end

  version = Version.new
  version.version_number = VERSION
  version.save

end

.generate_or_update_settings(settings, site = nil) ⇒ Object



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
# File 'app/models/gluttonberg/setting.rb', line 15

def self.generate_or_update_settings(settings, site=nil)
  settings.each do |key , val |
    obj = self.where(:name => key).first
    if obj.blank? || obj.site != site
      obj = self.new({
        :name=> key,
        :value => val[0],
        :row => val[1],
        :delete_able => false,
        :help => val[2],
        :values_list => val[3],
        :site => site
      })
      obj.save!
    else
      obj.update_attributes({
        :name=> key,
        :row => val[1],
        :delete_able => false,
        :help => val[2],
        :site => site
      })
    end
  end
end

.get_setting(key, site = '') ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/models/gluttonberg/setting.rb', line 113

def self.get_setting(key, site='')
  if Gluttonberg::Setting.table_exists?
    cache_key = (site.blank? ? "setting_#{key}" : "setting_#{key}_#{site}")
    data  = nil
    begin
      data = Rails.cache.read(cache_key)
    rescue
    end
    if data.blank?
      setting = Setting.where(:name => key)
      setting = setting.where(:site => site) unless site.blank?
      setting = setting.first
      data = ( (!setting.blank? && !setting.value.blank?) ? setting.value : "" )
       Rails.cache.write(cache_key , (data.blank? ? "~" : data))
       data
    elsif data == "~" # empty setting
      ""
    else
      data
    end
  end
end

.has_deletable_settings?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'app/models/gluttonberg/setting.rb', line 99

def self.has_deletable_settings?
  self.where(:delete_able => true).count > 0
end

.update_settings(settings = {}) ⇒ Object



136
137
138
139
140
141
142
143
144
# File 'app/models/gluttonberg/setting.rb', line 136

def self.update_settings(settings={})
  settings.each do |key , val |
    obj = self.where(:name=> key).first
    unless obj.blank?
      obj.value = val
      obj.save!
    end
  end
end

Instance Method Details

#destroy_cacheObject



155
156
157
158
# File 'app/models/gluttonberg/setting.rb', line 155

def destroy_cache
  cache_key = (self.site.blank? ? "setting_#{self.name}" : "setting_#{self.name}_#{self.site}")
  Rails.cache.write(cache_key , "")
end

Returns:

  • (Boolean)


103
104
105
# File 'app/models/gluttonberg/setting.rb', line 103

def dropdown_required?
  !values_list.blank?
end

#parsed_values_list_for_dropdownObject



107
108
109
110
111
# File 'app/models/gluttonberg/setting.rb', line 107

def parsed_values_list_for_dropdown
  unless values_list.blank?
    values_list.split(";")
  end
end

#update_settings_in_configObject



146
147
148
149
150
151
152
153
# File 'app/models/gluttonberg/setting.rb', line 146

def update_settings_in_config
  begin
    cache_key = (self.site.blank? ? "setting_#{self.name}" : "setting_#{self.name}_#{self.site}")
    Rails.cache.write(cache_key , self.value)
  rescue => e
    Rails.logger.info e
  end
end

#user_friendly_nameObject



41
42
43
# File 'app/models/gluttonberg/setting.rb', line 41

def user_friendly_name
  name.titlecase
end