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
|
|
|
|
|
2013-11-19 14:43:01 -05: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-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'))
|
|
|
|
|
|
|
|
Dir[File.join(Rails.root, "plugins", "*", "config", "settings.yml")].each do |file|
|
|
|
|
load_settings(file)
|
|
|
|
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
|
|
|
|
LocaleSiteSetting.values.map{ |e| e[:value] }.join('|')
|
|
|
|
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
|
|
|
|
min_private_message_title_length..max_topic_title_length
|
|
|
|
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
|
|
|
|
2013-06-13 04:18:17 -04:00
|
|
|
def self.private_message_post_length
|
|
|
|
min_private_message_post_length..max_post_length
|
|
|
|
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
|
|
|
|
|
2014-02-12 15:55:44 -05:00
|
|
|
def self.normalized_embeddable_host
|
|
|
|
return embeddable_host if embeddable_host.blank?
|
|
|
|
embeddable_host.sub(/^https?\:\/\//, '')
|
|
|
|
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 }
|
|
|
|
.select { |item| anonymous_menu_items.include?(item) }
|
|
|
|
.first
|
|
|
|
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
|
2014-01-08 18:51:38 -05:00
|
|
|
use_https? ? "https" : "http"
|
2013-12-16 05:44:59 -05:00
|
|
|
end
|
|
|
|
|
2014-03-07 12:58:53 -05:00
|
|
|
def self.has_enough_topics_to_redirect_to_top
|
2014-05-07 13:04:39 -04:00
|
|
|
TopTopic.periods.each do |period|
|
2014-06-17 05:26:36 -04:00
|
|
|
topics_per_period = TopTopic.where("#{period}_score > 0")
|
|
|
|
.limit(SiteSetting.topics_per_period_in_top_page)
|
|
|
|
.count
|
|
|
|
return true if topics_per_period >= SiteSetting.topics_per_period_in_top_page
|
2014-05-07 13:04:39 -04:00
|
|
|
end
|
|
|
|
# nothing
|
|
|
|
false
|
2014-03-07 12:58:53 -05:00
|
|
|
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
|
|
|
|
# name :string(255) not null
|
|
|
|
# data_type :integer not null
|
|
|
|
# value :text
|
2014-05-27 21:49:50 -04:00
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
2013-05-23 22:48:32 -04:00
|
|
|
#
|