2013-02-05 13:16:51 -06:00
|
|
|
require 'site_setting_extension'
|
2013-11-06 14:47:26 -06:00
|
|
|
require_dependency 'site_settings/yaml_loader'
|
2013-02-05 13:16:51 -06:00
|
|
|
|
|
|
|
class SiteSetting < ActiveRecord::Base
|
|
|
|
extend SiteSettingExtension
|
|
|
|
|
|
|
|
validates_presence_of :name
|
|
|
|
validates_presence_of :data_type
|
|
|
|
|
2013-11-19 13:43:01 -06: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 14:47:26 -06:00
|
|
|
end
|
|
|
|
end
|
2013-10-23 18:05:51 -05:00
|
|
|
|
2013-11-19 13:43:01 -06: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-02-07 21:24:10 -06:00
|
|
|
SiteSettingExtension.class_variable_get(:@@client_settings) << :available_locales
|
|
|
|
|
|
|
|
def self.available_locales
|
|
|
|
LocaleSiteSetting.values.map{ |e| e[:value] }.join('|')
|
|
|
|
end
|
2013-11-19 13:43:01 -06:00
|
|
|
|
2013-02-14 11:57:26 -06:00
|
|
|
def self.call_discourse_hub?
|
2013-03-04 18:42:44 -06:00
|
|
|
self.enforce_global_nicknames? && self.discourse_org_access_key.present?
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
|
2013-02-26 10:27:59 -06:00
|
|
|
def self.topic_title_length
|
|
|
|
min_topic_title_length..max_topic_title_length
|
|
|
|
end
|
|
|
|
|
2013-06-04 16:58:25 -05:00
|
|
|
def self.private_message_title_length
|
|
|
|
min_private_message_title_length..max_topic_title_length
|
|
|
|
end
|
|
|
|
|
2013-02-28 12:54:12 -06:00
|
|
|
def self.post_length
|
|
|
|
min_post_length..max_post_length
|
|
|
|
end
|
2013-03-28 08:01:13 -05:00
|
|
|
|
2013-06-13 03:18:17 -05:00
|
|
|
def self.private_message_post_length
|
|
|
|
min_private_message_post_length..max_post_length
|
|
|
|
end
|
|
|
|
|
2013-06-21 15:31:40 -05:00
|
|
|
def self.top_menu_items
|
|
|
|
top_menu.split('|').map { |menu_item| TopMenuItem.new(menu_item) }
|
|
|
|
end
|
|
|
|
|
2013-03-28 08:01:13 -05:00
|
|
|
def self.homepage
|
2013-06-21 15:31:40 -05:00
|
|
|
top_menu_items[0].name
|
2013-03-28 08:01:13 -05:00
|
|
|
end
|
|
|
|
|
2013-07-15 18:59:23 -05:00
|
|
|
def self.anonymous_menu_items
|
2013-12-23 17:50:36 -06:00
|
|
|
@anonymous_menu_items ||= Set.new Discourse.anonymous_filters.map(&:to_s)
|
2013-07-15 18:59:23 -05:00
|
|
|
end
|
|
|
|
|
2014-02-12 14:55:44 -06:00
|
|
|
def self.normalized_embeddable_host
|
|
|
|
return embeddable_host if embeddable_host.blank?
|
|
|
|
embeddable_host.sub(/^https?\:\/\//, '')
|
|
|
|
end
|
|
|
|
|
2013-03-28 08:01:13 -05:00
|
|
|
def self.anonymous_homepage
|
2013-07-15 18:59:23 -05:00
|
|
|
top_menu_items.map { |item| item.name }
|
|
|
|
.select { |item| anonymous_menu_items.include?(item) }
|
|
|
|
.first
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.authorized_uploads
|
|
|
|
authorized_extensions.tr(" ", "")
|
|
|
|
.split("|")
|
2013-08-01 18:27:48 -05:00
|
|
|
.map { |extension| (extension.start_with?(".") ? extension[1..-1] : extension).gsub(".", "\.") }
|
2013-03-28 08:01:13 -05:00
|
|
|
end
|
|
|
|
|
2013-07-15 18:59:23 -05:00
|
|
|
def self.authorized_upload?(file)
|
2013-08-01 18:27:48 -05:00
|
|
|
authorized_uploads.count > 0 && file.original_filename =~ /\.(#{authorized_uploads.join("|")})$/i
|
2013-07-10 15:54:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.images
|
2013-08-01 18:27:48 -05:00
|
|
|
@images ||= Set.new ["jpg", "jpeg", "png", "gif", "tif", "tiff", "bmp"]
|
2013-07-15 18:59:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.authorized_images
|
|
|
|
authorized_uploads.select { |extension| images.include?(extension) }
|
2013-07-10 15:54:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.authorized_image?(file)
|
2013-08-01 18:27:48 -05:00
|
|
|
authorized_images.count > 0 && file.original_filename =~ /\.(#{authorized_images.join("|")})$/i
|
2013-07-10 15:54:05 -05:00
|
|
|
end
|
|
|
|
|
2013-12-16 04:44:59 -06:00
|
|
|
def self.scheme
|
2014-01-08 17:51:38 -06:00
|
|
|
use_https? ? "https" : "http"
|
2013-12-16 04:44:59 -06:00
|
|
|
end
|
|
|
|
|
2014-03-07 11:58:53 -06:00
|
|
|
def self.has_enough_topics_to_redirect_to_top
|
|
|
|
Topic.listable_topics
|
|
|
|
.visible
|
|
|
|
.where('topics.id NOT IN (SELECT COALESCE(topic_id, 0) FROM categories)')
|
|
|
|
.count > SiteSetting.topics_per_period_in_top_page
|
|
|
|
end
|
|
|
|
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
2013-05-23 21:48:32 -05: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
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
#
|
|
|
|
|