<commit_before>=begin

A definition of a site.

In crabgrass, 'sites' are several social networks hosted on the same rails
instance sharing a single data store. Different sites are identified by
different domain names, but all of the domains point to a single IP address.
Each site can have a unique visual appearance, it can limit the tools available
to its users, but all of their code and data is shared (of course, it's possible
to hide data between sides)

  create_table "sites", :force => true do |t|
    t.string  "name"
    t.string  "domain"
    t.string  "email_sender"
    t.integer "pagination_size",      :limit => 11
    t.integer "super_admin_group_id", :limit => 11
    t.integer "council_id",           :limit => 11
    t.text    "translators"
    t.string  "translation_group"
    t.string  "default_language"
    t.text    "available_page_types"
    t.text    "evil"
    t.boolean "tracking"
    t.boolean "default",                            :default => false
    t.integer "network_id",           :limit => 11
    t.integer "custom_appearance_id", :limit => 11
    t.boolean "has_networks",                       :default => true
    t.string  "signup_redirect_url"
    t.string  "login_redirect_url"
    t.string  "title"
    t.boolean "enforce_ssl"
    t.boolean "show_exceptions"
    t.boolean "require_user_email"
  end

end

Example data for serialized fields:

  translators => ['blue', 'green', 'red']

  available_page_types => ['Discussion', 'Wiki', 'RateMany']

  evil => {"google_analytics"=>{"https"=>false, "enabled"=>false, "site_id"=>"UA-XXXXXX-X"}}

=end

class Site < ActiveRecord::Base
  belongs_to :network
  belongs_to :custom_appearance, :dependent => :destroy
  belongs_to :council, :class_name => 'Group'

  serialize :translators, Array
  serialize :available_page_types, Array
  serialize :evil, Hash

  # this is evil, but used by gibberish for site specific
  # override ability.
  cattr_accessor :current

  ##
  ## FINDERS
  ##

  named_scope :for_domain, lambda {|domain|
    {:conditions => ['sites.domain = ? AND sites.id IN (?)', domain, Conf.enabled_site_ids]}
  }

  def self.default
    @default_site ||= Site.find(:first, :conditions => ["sites.default = ? AND sites.id in (?)", true, Conf.enabled_site_ids]) || Site.new()
  end

  # def stylesheet_render_options(path)
  #   {:text => "body {background-color: purple;} \n /* #{path.inspect} */"}
  # end

  # returns true if this site should display content limited to this site only.
  # the default for sites is to always display just the data for the site.
  # however, some sites may be umbrella sites that have access to everything. 
  # for now, if self is not actually a site in the database then we treat it
  # as an umbrella site.
  def limited?
    not self.id.nil?
  end

  ##
  ## CONFIGURATION & DEFAULT VALUES
  ##

  # For the attributes, use the site's value first, if possible, and
  # fall back to Conf if the value is not set. We can also proxy attributes
  # which do not actually exist in the sites table but which do exist in the
  # configuration file.
  #
  # These defaults are defined in lib/crabgrass/conf.rb (and are changed by
  # whatever crabgrass.*.yml gets loaded).
  def self.proxy_to_conf(*attributes)
    attributes.each do |attribute|
      define_method(attribute) { read_attribute(attribute) || Conf.send(attribute) }
    end
  end

  proxy_to_conf :name, :title, :pagination_size, :default_language, :email_sender,
    :available_page_types, :tracking, :evil, :enforce_ssl, :show_exceptions,
    :require_user_email, :domain, :profiles, :profile_fields, :chat?

  def profile_field_enabled?(field)
    profile_fields.nil? or profile_fields.include?(field.to_s)
  end

  def profile_enabled?(profile)
    profiles.nil? or profiles.include?(profile.to_s)
  end<commit_msg>fixed a minor bug with Site default options proxy to Conf.<commit_after>=begin

A definition of a site.

In crabgrass, 'sites' are several social networks hosted on the same rails
instance sharing a single data store. Different sites are identified by
different domain names, but all of the domains point to a single IP address.
Each site can have a unique visual appearance, it can limit the tools available
to its users, but all of their code and data is shared (of course, it's possible
to hide data between sides)

  create_table "sites", :force => true do |t|
    t.string  "name"
    t.string  "domain"
    t.string  "email_sender"
    t.integer "pagination_size",      :limit => 11
    t.integer "super_admin_group_id", :limit => 11
    t.integer "council_id",           :limit => 11
    t.text    "translators"
    t.string  "translation_group"
    t.string  "default_language"
    t.text    "available_page_types"
    t.text    "evil"
    t.boolean "tracking"
    t.boolean "default",                            :default => false
    t.integer "network_id",           :limit => 11
    t.integer "custom_appearance_id", :limit => 11
    t.boolean "has_networks",                       :default => true
    t.string  "signup_redirect_url"
    t.string  "login_redirect_url"
    t.string  "title"
    t.boolean "enforce_ssl"
    t.boolean "show_exceptions"
    t.boolean "require_user_email"
  end

end

Example data for serialized fields:

  translators => ['blue', 'green', 'red']

  available_page_types => ['Discussion', 'Wiki', 'RateMany']

  evil => {"google_analytics"=>{"https"=>false, "enabled"=>false, "site_id"=>"UA-XXXXXX-X"}}

=end

class Site < ActiveRecord::Base
  belongs_to :network
  belongs_to :custom_appearance, :dependent => :destroy
  belongs_to :council, :class_name => 'Group'

  serialize :translators, Array
  serialize :available_page_types, Array
  serialize :evil, Hash

  # this is evil, but used by gibberish for site specific
  # override ability.
  cattr_accessor :current

  ##
  ## FINDERS
  ##

  named_scope :for_domain, lambda {|domain|
    {:conditions => ['sites.domain = ? AND sites.id IN (?)', domain, Conf.enabled_site_ids]}
  }

  def self.default
    @default_site ||= Site.find(:first, :conditions => ["sites.default = ? AND sites.id in (?)", true, Conf.enabled_site_ids]) || Site.new()
  end

  # def stylesheet_render_options(path)
  #   {:text => "body {background-color: purple;} \n /* #{path.inspect} */"}
  # end

  # returns true if this site should display content limited to this site only.
  # the default for sites is to always display just the data for the site.
  # however, some sites may be umbrella sites that have access to everything. 
  # for now, if self is not actually a site in the database then we treat it
  # as an umbrella site.
  def limited?
    not self.id.nil?
  end

  ##
  ## CONFIGURATION & DEFAULT VALUES
  ##

  # For the attributes, use the site's value first, if possible, and
  # fall back to Conf if the value is not set. We can also proxy attributes
  # which do not actually exist in the sites table but which do exist in the
  # configuration file.
  #
  # These defaults are defined in lib/crabgrass/conf.rb (and are changed by
  # whatever crabgrass.*.yml gets loaded).
  def self.proxy_to_conf(*attributes)
    attributes.each do |attribute|
      define_method(attribute) { (value = read_attribute(attribute.to_s.sub(/\?$/,''))).nil? ? Conf.send(attribute) : value }
    end
  end

  proxy_to_conf :name, :title, :pagination_size, :default_language, :email_sender,
    :available_page_types, :tracking, :evil, :enforce_ssl, :show_exceptions,
    :require_user_email, :domain, :profiles, :profile_fields, :chat?

  def profile_field_enabled?(field)
    profile_fields.nil? or profile_fields.include?(field.to_s)
  end

  def profile_enabled?(profile)
    profiles.nil? or profiles.include?(profile.to_s)
  end
{'fraction_non_alphanumeric': 0.10633893919793014, 'fraction_numerical': 0.00258732212160414, 'mean_word_length': 3.4636258660508084, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7614619', 'n_tokens_mistral': 2465, 'n_tokens_neox': 2361, 'n_words': 799}