2013-02-05 14:16:51 -05:00
|
|
|
require 'site_setting_extension'
|
2013-11-06 15:47:26 -05:00
|
|
|
require_dependency 'site_settings/yaml_loader'
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
class SiteSetting < ActiveRecord::Base
|
|
|
|
extend SiteSettingExtension
|
|
|
|
|
|
|
|
validates_presence_of :name
|
|
|
|
validates_presence_of :data_type
|
|
|
|
|
2014-12-11 11:08:47 -05:00
|
|
|
after_save do |site_setting|
|
|
|
|
DiscourseEvent.trigger(:site_setting_saved, site_setting)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2013-11-19 14:43:01 -05:00
|
|
|
def self.load_settings(file)
|
|
|
|
SiteSettings::YamlLoader.new(file).load do |category, name, default, opts|
|
2017-08-06 21:43:09 -04:00
|
|
|
setting(name, default, opts.merge(category: category))
|
2013-11-06 15:47:26 -05:00
|
|
|
end
|
|
|
|
end
|
2013-10-23 19:05:51 -04:00
|
|
|
|
2013-11-19 14:43:01 -05:00
|
|
|
load_settings(File.join(Rails.root, 'config', 'site_settings.yml'))
|
2016-06-27 05:26:43 -04:00
|
|
|
setup_deprecated_methods
|
2013-11-19 14:43:01 -05:00
|
|
|
|
2014-12-11 11:08:47 -05:00
|
|
|
unless Rails.env.test? && ENV['LOAD_PLUGINS'] != "1"
|
|
|
|
Dir[File.join(Rails.root, "plugins", "*", "config", "settings.yml")].each do |file|
|
|
|
|
load_settings(file)
|
|
|
|
end
|
2013-11-19 14:43:01 -05:00
|
|
|
end
|
|
|
|
|
2014-03-28 01:36:17 -04:00
|
|
|
client_settings << :available_locales
|
2014-02-07 22:24:10 -05:00
|
|
|
|
|
|
|
def self.available_locales
|
2017-12-13 16:17:36 -05:00
|
|
|
LocaleSiteSetting.values.to_json
|
2014-02-07 22:24:10 -05:00
|
|
|
end
|
2013-11-19 14:43:01 -05:00
|
|
|
|
2013-02-26 11:27:59 -05:00
|
|
|
def self.topic_title_length
|
|
|
|
min_topic_title_length..max_topic_title_length
|
|
|
|
end
|
|
|
|
|
2013-06-04 17:58:25 -04:00
|
|
|
def self.private_message_title_length
|
2018-01-31 00:56:00 -05:00
|
|
|
min_personal_message_title_length..max_topic_title_length
|
2013-06-04 17:58:25 -04:00
|
|
|
end
|
|
|
|
|
2013-02-28 13:54:12 -05:00
|
|
|
def self.post_length
|
|
|
|
min_post_length..max_post_length
|
|
|
|
end
|
2013-03-28 09:01:13 -04:00
|
|
|
|
2015-03-19 10:17:55 -04:00
|
|
|
def self.first_post_length
|
|
|
|
min_first_post_length..max_post_length
|
|
|
|
end
|
|
|
|
|
2013-06-13 04:18:17 -04:00
|
|
|
def self.private_message_post_length
|
2018-01-31 00:56:00 -05:00
|
|
|
min_personal_message_post_length..max_post_length
|
2013-06-13 04:18:17 -04:00
|
|
|
end
|
|
|
|
|
2013-06-21 16:31:40 -04:00
|
|
|
def self.top_menu_items
|
|
|
|
top_menu.split('|').map { |menu_item| TopMenuItem.new(menu_item) }
|
|
|
|
end
|
|
|
|
|
2013-03-28 09:01:13 -04:00
|
|
|
def self.homepage
|
2013-06-21 16:31:40 -04:00
|
|
|
top_menu_items[0].name
|
2013-03-28 09:01:13 -04:00
|
|
|
end
|
|
|
|
|
2013-07-15 19:59:23 -04:00
|
|
|
def self.anonymous_menu_items
|
2013-12-23 18:50:36 -05:00
|
|
|
@anonymous_menu_items ||= Set.new Discourse.anonymous_filters.map(&:to_s)
|
2013-07-15 19:59:23 -04:00
|
|
|
end
|
|
|
|
|
2013-03-28 09:01:13 -04:00
|
|
|
def self.anonymous_homepage
|
2013-07-15 19:59:23 -04:00
|
|
|
top_menu_items.map { |item| item.name }
|
2017-07-27 21:20:09 -04:00
|
|
|
.select { |item| anonymous_menu_items.include?(item) }
|
|
|
|
.first
|
2013-07-15 19:59:23 -04:00
|
|
|
end
|
|
|
|
|
2014-04-21 16:59:53 -04:00
|
|
|
def self.should_download_images?(src)
|
|
|
|
setting = disabled_image_download_domains
|
|
|
|
return true unless setting.present?
|
|
|
|
|
2014-05-07 13:49:16 -04:00
|
|
|
host = URI.parse(src).host
|
2014-04-21 16:59:53 -04:00
|
|
|
return !(setting.split('|').include?(host))
|
|
|
|
rescue URI::InvalidURIError
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-12-16 05:44:59 -05:00
|
|
|
def self.scheme
|
2016-06-27 05:26:43 -04:00
|
|
|
force_https? ? "https" : "http"
|
2013-12-16 05:44:59 -05:00
|
|
|
end
|
|
|
|
|
2015-08-21 14:39:21 -04:00
|
|
|
def self.default_categories_selected
|
|
|
|
[
|
|
|
|
SiteSetting.default_categories_watching.split("|"),
|
|
|
|
SiteSetting.default_categories_tracking.split("|"),
|
|
|
|
SiteSetting.default_categories_muted.split("|"),
|
2016-11-09 13:37:54 -05:00
|
|
|
SiteSetting.default_categories_watching_first_post.split("|")
|
2015-08-21 14:39:21 -04:00
|
|
|
].flatten.to_set
|
|
|
|
end
|
|
|
|
|
2016-10-11 13:22:43 -04:00
|
|
|
def self.min_redirected_to_top_period(duration)
|
2016-11-23 21:29:44 -05:00
|
|
|
period = ListController.best_period_with_topics_for(duration)
|
|
|
|
return period if period
|
2016-10-11 13:22:43 -04:00
|
|
|
|
2016-10-11 11:56:46 -04:00
|
|
|
# not enough topics
|
|
|
|
nil
|
2015-09-21 14:28:20 -04:00
|
|
|
end
|
|
|
|
|
2016-03-16 17:28:01 -04:00
|
|
|
def self.email_polling_enabled?
|
|
|
|
SiteSetting.manual_polling_enabled? || SiteSetting.pop3_polling_enabled?
|
|
|
|
end
|
2016-08-03 11:55:54 -04:00
|
|
|
|
|
|
|
def self.attachment_content_type_blacklist_regex
|
|
|
|
@attachment_content_type_blacklist_regex ||= Regexp.union(SiteSetting.attachment_content_type_blacklist.split("|"))
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.attachment_filename_blacklist_regex
|
|
|
|
@attachment_filename_blacklist_regex ||= Regexp.union(SiteSetting.attachment_filename_blacklist.split("|"))
|
|
|
|
end
|
2017-10-06 01:20:01 -04:00
|
|
|
|
|
|
|
# helpers for getting s3 settings that fallback to global
|
|
|
|
class Upload
|
|
|
|
def self.s3_cdn_url
|
|
|
|
SiteSetting.enable_s3_uploads ? SiteSetting.s3_cdn_url : GlobalSetting.s3_cdn_url
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.s3_region
|
|
|
|
SiteSetting.enable_s3_uploads ? SiteSetting.s3_region : GlobalSetting.s3_region
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.s3_upload_bucket
|
|
|
|
SiteSetting.enable_s3_uploads ? SiteSetting.s3_upload_bucket : GlobalSetting.s3_bucket
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.enable_s3_uploads
|
|
|
|
SiteSetting.enable_s3_uploads || GlobalSetting.use_s3?
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.absolute_base_url
|
|
|
|
bucket = SiteSetting.enable_s3_uploads ? Discourse.store.s3_bucket_name : GlobalSetting.s3_bucket
|
|
|
|
|
|
|
|
# cf. http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
|
|
|
|
if SiteSetting.Upload.s3_region == "us-east-1"
|
|
|
|
"//#{bucket}.s3.amazonaws.com"
|
|
|
|
elsif SiteSetting.Upload.s3_region == 'cn-north-1'
|
|
|
|
"//#{bucket}.s3.cn-north-1.amazonaws.com.cn"
|
|
|
|
else
|
|
|
|
"//#{bucket}.s3-#{SiteSetting.Upload.s3_region}.amazonaws.com"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.Upload
|
|
|
|
SiteSetting::Upload
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
2013-05-23 22:48:32 -04:00
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: site_settings
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
2017-12-05 10:29:14 -05:00
|
|
|
# name :string(255) not null
|
2013-05-23 22:48:32 -04:00
|
|
|
# data_type :integer not null
|
|
|
|
# value :text
|
2014-08-27 01:30:17 -04:00
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
2013-05-23 22:48:32 -04:00
|
|
|
#
|