<commit_before># == Schema Information
# Schema version: 20100415090246
#
# Table name: sites
#
#  id                        :integer         not null, primary key
#  created_at                :datetime
#  updated_at                :datetime
#  subdomain                 :string(255)
#  custom_domain             :string(255)
#  theme_id                  :integer
#  name                      :string(255)
#  subhead                   :string(255)
#  keywords                  :text
#  description               :text
#  disclaimer                :text
#  campaign_email            :string(255)
#  campaign_phone            :string(255)
#  twitter_username          :string(255)
#  facebook_page_id          :string(255)
#  flickr_username           :string(255)
#  youtube_username          :string(255)
#  google_analytics_id       :string(255)
#  paypal_email              :string(255)
#  owner_id                  :integer
#  campaign_monitor_password :string(255)
#  supporter_list_id         :string(255)
#  contributor_list_id       :string(255)
#  candidate_photo           :string(255)
#  eligibility_statement     :text
#  campaign_legal_name       :string(255)
#  campaign_street           :string(255)
#  campaign_city             :string(255)
#  campaign_state            :string(255)
#  campaign_zip              :string(255)
#

class Site < ActiveRecord::Base
  attr_accessible :subdomain, :custom_domain, :theme_id, :name, :subhead,
                  :keywords, :description, :disclaimer, :public_email,
                  :public_phone, :twitter_username, :facebook_page_id,
                  :flickr_username, :youtube_username, :google_analytics_id,
                  :paypal_email, :eligibility_statement, :candidate_photo
  
  RESERVED_SUBDOMAINS = %w( www support blog billing help api cdn asset assets chat mail calendar docs documents apps app calendars mobile mobi static admin administration administrator moderator official store buy pages page ssl contribute )
  
  belongs_to  :owner, :class_name => 'User'
  has_many    :administratorships
  has_many    :administrators, :through => :administratorships
  has_many    :supporterships
  has_many    :supporters, :through => :supporterships
  has_many    :contributions
  
  belongs_to  :theme
  has_many    :layouts,     :through => :theme
  has_many    :templates,   :through => :theme
  
  has_many    :items,     :order => 'created_at ASC'
  has_many    :pages,     :order => 'created_at ASC'
  has_many    :blogs,     :order => 'created_at ASC'
  has_many    :articles,  :order => 'created_at DESC'
  has_many    :assets,    :order => 'created_at DESC'
  
  mount_uploader :candidate_photo, CandidatePhotoUploader
  
  before_validation       :downcase_subdomain
  before_validation       :downcase_custom_domain
  validates_uniqueness_of :subdomain, :message => "This subdomain is already in use."
  validates_length_of     :subdomain, :within => 3..63,
                          :message => "A subdomain is required and must be between 3 and 63 characters in length."
  validates_format_of     :subdomain, :with => /\A([a-z0-9]([a-z0-9\-_]{0,61}[a-z0-9])?)+\Z/,
                          :message => "A subdomain can only contain alphanumeric characters, underscores and dashes. It must also begin and end with either a letter or a number."
  validates_exclusion_of  :subdomain, :in => RESERVED_SUBDOMAINS,
                          :message => "This subdomain is already in use."
  validates_uniqueness_of :custom_domain, :allow_blank => true, :message => "This domain name is already in use."
  validates_format_of     :custom_domain, :if => Proc.new {|site| !site.custom_domain.blank? }, 
                          :with => /\A([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])+\.)[a-zA-Z]{2,6}\Z/, #/\A([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}\Z/,
                          :message => 'The domain name is not valid. Please enter your domain in the following format: "example.com"'
  validates_length_of     :public_email, :within => 6..100,   :allow_blank => false
  validates_format_of     :public_email, :with => RegEmailOk, :allow_blank => false
  validates_presence_of   :name
  
  def sms_recipient_numbers
    supporters.all(:select => 'supporters.mobile_phone', :conditions => ['supporterships.receive_sms = ?', true]).collect(&:mobile_phone)
  end
  
  def gateway
    ActiveMerchant::Billing::Base.gateway('paypal').new(
      :login => 'marc.love_api1.progressbound.com',
      :password => '<PASSWORD>',
      :signature => 'AzH56dRB-gyN4C.dhLrbPvRZO6XnA-XprdAPHqIwbMLKD7Sf7BEy4pHo',
      :subject => paypal_email
    )
  end
  
  def root_url
    "http://#{domain}"
  end
  
  def domain
    custom_domain.blank? ? "#{subdomain}.#{BASE_URL}" : custom_domain
  end
  
  def root_item
    items.roots.first(:order => 'lft ASC', :conditions => {:published => true, :show_in_navigation => true})<commit_msg>Bug Fix for previous commit<commit_after># == Schema Information
# Schema version: 20100415090246
#
# Table name: sites
#
#  id                        :integer         not null, primary key
#  created_at                :datetime
#  updated_at                :datetime
#  subdomain                 :string(255)
#  custom_domain             :string(255)
#  theme_id                  :integer
#  name                      :string(255)
#  subhead                   :string(255)
#  keywords                  :text
#  description               :text
#  disclaimer                :text
#  campaign_email            :string(255)
#  campaign_phone            :string(255)
#  twitter_username          :string(255)
#  facebook_page_id          :string(255)
#  flickr_username           :string(255)
#  youtube_username          :string(255)
#  google_analytics_id       :string(255)
#  paypal_email              :string(255)
#  owner_id                  :integer
#  campaign_monitor_password :string(255)
#  supporter_list_id         :string(255)
#  contributor_list_id       :string(255)
#  candidate_photo           :string(255)
#  eligibility_statement     :text
#  campaign_legal_name       :string(255)
#  campaign_street           :string(255)
#  campaign_city             :string(255)
#  campaign_state            :string(255)
#  campaign_zip              :string(255)
#

class Site < ActiveRecord::Base
  attr_accessible :subdomain, :custom_domain, :theme_id, :name, :subhead,
                  :keywords, :description, :disclaimer, :campaign_email,
                  :campaign_phone, :twitter_username, :facebook_page_id,
                  :flickr_username, :youtube_username, :google_analytics_id,
                  :paypal_email, :eligibility_statement, :candidate_photo,
                  :campaign_legal_name, :campaign_street, :campaign_city,
                  :campaign_state, :campaign_zip
  
  RESERVED_SUBDOMAINS = %w( www support blog billing help api cdn asset assets chat mail calendar docs documents apps app calendars mobile mobi static admin administration administrator moderator official store buy pages page ssl contribute )
  
  belongs_to  :owner, :class_name => 'User'
  has_many    :administratorships
  has_many    :administrators, :through => :administratorships
  has_many    :supporterships
  has_many    :supporters, :through => :supporterships
  has_many    :contributions
  
  belongs_to  :theme
  has_many    :layouts,     :through => :theme
  has_many    :templates,   :through => :theme
  
  has_many    :items,     :order => 'created_at ASC'
  has_many    :pages,     :order => 'created_at ASC'
  has_many    :blogs,     :order => 'created_at ASC'
  has_many    :articles,  :order => 'created_at DESC'
  has_many    :assets,    :order => 'created_at DESC'
  
  mount_uploader :candidate_photo, CandidatePhotoUploader
  
  before_validation       :downcase_subdomain
  before_validation       :downcase_custom_domain
  validates_uniqueness_of :subdomain, :message => "This subdomain is already in use."
  validates_length_of     :subdomain, :within => 3..63,
                          :message => "A subdomain is required and must be between 3 and 63 characters in length."
  validates_format_of     :subdomain, :with => /\A([a-z0-9]([a-z0-9\-_]{0,61}[a-z0-9])?)+\Z/,
                          :message => "A subdomain can only contain alphanumeric characters, underscores and dashes. It must also begin and end with either a letter or a number."
  validates_exclusion_of  :subdomain, :in => RESERVED_SUBDOMAINS,
                          :message => "This subdomain is already in use."
  validates_uniqueness_of :custom_domain, :allow_blank => true, :message => "This domain name is already in use."
  validates_format_of     :custom_domain, :if => Proc.new {|site| !site.custom_domain.blank? }, 
                          :with => /\A([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])+\.)[a-zA-Z]{2,6}\Z/, #/\A([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}\Z/,
                          :message => 'The domain name is not valid. Please enter your domain in the following format: "example.com"'
  validates_length_of     :campaign_email, :within => 6..100,   :allow_blank => false
  validates_format_of     :campaign_email, :with => RegEmailOk, :allow_blank => false
  validates_presence_of   :name
  
  def sms_recipient_numbers
    supporters.all(:select => 'supporters.mobile_phone', :conditions => ['supporterships.receive_sms = ?', true]).collect(&:mobile_phone)
  end
  
  def gateway
    ActiveMerchant::Billing::Base.gateway('paypal').new(
      :login => 'marc.love_api1.progressbound.com',
      :password => '<PASSWORD>',
      :signature => 'AzH56dRB-gyN4C.dhLrbPvRZO6XnA-XprdAPHqIwbMLKD7Sf7BEy4pHo',
      :subject => paypal_email
    )
  end
  
  def root_url
    "http://#{domain}"
  end
  
  def domain
    custom_domain.blank? ? "#{subdomain}.#{BASE_URL}" : custom_domain
  end
  
  def root_item
    items.roots.first(:order => 'lft ASC', :conditions => {:published => true, :show_in_navigation => true})
{'fraction_non_alphanumeric': 0.11278044871794872, 'fraction_numerical': 0.025240384615384616, 'mean_word_length': 2.6072976878612715, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1156032', 'n_tokens_mistral': 3387, 'n_tokens_neox': 3143, 'n_words': 700}