2013-02-06 03:16:51 +08:00
|
|
|
require 'site_setting_extension'
|
2013-11-07 04:47:26 +08:00
|
|
|
require_dependency 'site_settings/yaml_loader'
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
class SiteSetting < ActiveRecord::Base
|
|
|
|
extend SiteSettingExtension
|
|
|
|
|
|
|
|
validates_presence_of :name
|
|
|
|
validates_presence_of :data_type
|
|
|
|
|
2014-12-12 00:08:47 +08:00
|
|
|
after_save do |site_setting|
|
|
|
|
DiscourseEvent.trigger(:site_setting_saved, site_setting)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2013-11-20 03:43:01 +08:00
|
|
|
def self.load_settings(file)
|
|
|
|
SiteSettings::YamlLoader.new(file).load do |category, name, default, opts|
|
|
|
|
if opts.delete(:client)
|
|
|
|
client_setting(name, default, opts.merge(category: category))
|
|
|
|
else
|
|
|
|
setting(name, default, opts.merge(category: category))
|
|
|
|
end
|
2013-11-07 04:47:26 +08:00
|
|
|
end
|
|
|
|
end
|
2013-10-24 07:05:51 +08:00
|
|
|
|
2013-11-20 03:43:01 +08:00
|
|
|
load_settings(File.join(Rails.root, 'config', 'site_settings.yml'))
|
|
|
|
|
2014-12-12 00:08:47 +08: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-20 03:43:01 +08:00
|
|
|
end
|
|
|
|
|
2014-03-28 13:36:17 +08:00
|
|
|
client_settings << :available_locales
|
2014-02-08 11:24:10 +08:00
|
|
|
|
|
|
|
def self.available_locales
|
|
|
|
LocaleSiteSetting.values.map{ |e| e[:value] }.join('|')
|
|
|
|
end
|
2013-11-20 03:43:01 +08:00
|
|
|
|
2013-02-27 00:27:59 +08:00
|
|
|
def self.topic_title_length
|
|
|
|
min_topic_title_length..max_topic_title_length
|
|
|
|
end
|
|
|
|
|
2013-06-05 05:58:25 +08:00
|
|
|
def self.private_message_title_length
|
|
|
|
min_private_message_title_length..max_topic_title_length
|
|
|
|
end
|
|
|
|
|
2013-03-01 02:54:12 +08:00
|
|
|
def self.post_length
|
|
|
|
min_post_length..max_post_length
|
|
|
|
end
|
2013-03-28 21:01:13 +08:00
|
|
|
|
2015-03-19 22:17:55 +08:00
|
|
|
def self.first_post_length
|
|
|
|
min_first_post_length..max_post_length
|
|
|
|
end
|
|
|
|
|
2013-06-13 16:18:17 +08:00
|
|
|
def self.private_message_post_length
|
|
|
|
min_private_message_post_length..max_post_length
|
|
|
|
end
|
|
|
|
|
2013-06-22 04:31:40 +08:00
|
|
|
def self.top_menu_items
|
|
|
|
top_menu.split('|').map { |menu_item| TopMenuItem.new(menu_item) }
|
|
|
|
end
|
|
|
|
|
2013-03-28 21:01:13 +08:00
|
|
|
def self.homepage
|
2013-06-22 04:31:40 +08:00
|
|
|
top_menu_items[0].name
|
2013-03-28 21:01:13 +08:00
|
|
|
end
|
|
|
|
|
2013-07-16 07:59:23 +08:00
|
|
|
def self.anonymous_menu_items
|
2013-12-24 07:50:36 +08:00
|
|
|
@anonymous_menu_items ||= Set.new Discourse.anonymous_filters.map(&:to_s)
|
2013-07-16 07:59:23 +08:00
|
|
|
end
|
|
|
|
|
2013-03-28 21:01:13 +08:00
|
|
|
def self.anonymous_homepage
|
2013-07-16 07:59:23 +08:00
|
|
|
top_menu_items.map { |item| item.name }
|
|
|
|
.select { |item| anonymous_menu_items.include?(item) }
|
|
|
|
.first
|
|
|
|
end
|
|
|
|
|
2014-04-22 04:59:53 +08:00
|
|
|
def self.should_download_images?(src)
|
|
|
|
setting = disabled_image_download_domains
|
|
|
|
return true unless setting.present?
|
|
|
|
|
2014-05-08 01:49:16 +08:00
|
|
|
host = URI.parse(src).host
|
2014-04-22 04:59:53 +08:00
|
|
|
return !(setting.split('|').include?(host))
|
|
|
|
rescue URI::InvalidURIError
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-12-16 18:44:59 +08:00
|
|
|
def self.scheme
|
2014-01-09 07:51:38 +08:00
|
|
|
use_https? ? "https" : "http"
|
2013-12-16 18:44:59 +08:00
|
|
|
end
|
|
|
|
|
2015-08-22 02:39:21 +08:00
|
|
|
def self.default_categories_selected
|
|
|
|
[
|
|
|
|
SiteSetting.default_categories_watching.split("|"),
|
|
|
|
SiteSetting.default_categories_tracking.split("|"),
|
|
|
|
SiteSetting.default_categories_muted.split("|"),
|
|
|
|
].flatten.to_set
|
|
|
|
end
|
|
|
|
|
2015-09-22 02:28:20 +08:00
|
|
|
def self.min_redirected_to_top_period
|
|
|
|
TopTopic.sorted_periods.each do |p|
|
|
|
|
period = p[0]
|
|
|
|
return period if TopTopic.topics_per_period(period) >= SiteSetting.topics_per_period_in_top_page
|
|
|
|
end
|
|
|
|
# not enough topics
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2016-03-17 05:28:01 +08:00
|
|
|
def self.email_polling_enabled?
|
|
|
|
SiteSetting.manual_polling_enabled? || SiteSetting.pop3_polling_enabled?
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
2013-05-24 10:48:32 +08:00
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: site_settings
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
2016-02-23 07:33:53 +08:00
|
|
|
# name :string not null
|
2013-05-24 10:48:32 +08:00
|
|
|
# data_type :integer not null
|
|
|
|
# value :text
|
2014-08-27 13:30:17 +08:00
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
2013-05-24 10:48:32 +08:00
|
|
|
#
|