0
class Site < ActiveRecord::Base
0
PERMALINK_OPTIONS = { 'year' => '\d{4}', 'month' => '\d{1,2}', 'day' => '\d{1,2}', 'permalink' => '[a-z0-9-]+', 'id' => '\d+' }
0
PERMALINK_VAR = /^:([a-z]+)$/
0
- @@permalink_slug = ':year/:month/:day/:permalink'.freeze
0
- @@archive_slug = 'archives'.freeze
0
- @@tag_slug = 'tags'.freeze
0
- @@search_slug = 'search'.freeze
0
include Mephisto::Attachments::AttachmentMethods
0
cattr_accessor :multi_sites_enabled
0
@@ -49,11 +45,12 @@ class Site < ActiveRecord::Base
0
has_many :admins, :through => :memberships, :source => :user, :conditions => ['memberships.admin = ? or users.admin = ?', true, true]
0
before_validation :downcase_host
0
- before_validation :set_default_timezone
0
- before_validation_on_create :set_default_comment_options
0
- validates_format_of :host, :with => /^([a-z0-9]([-a-z0-9]*[a-z0-9])?\.)+((a[cdefgilmnoqrstuwxz]|aero|arpa)|(b[abdefghijmnorstvwyz]|biz)|(c[acdfghiklmnorsuvxyz]|cat|com|coop)|d[ejkmoz]|(e[ceghrstu]|edu)|f[ijkmor]|(g[abdefghilmnpqrstuwy]|gov)|h[kmnrtu]|(i[delmnoqrst]|info|int)|(j[emop]|jobs)|k[eghimnprwyz]|l[abcikrstuvy]|(m[acdghklmnopqrstuvwxyz]|mil|mobi|museum)|(n[acefgilopruz]|name|net)|(om|org)|(p[aefghklmnrstwy]|pro)|qa|r[eouw]|s[abcdeghijklmnortvyz]|(t[cdfghjklmnoprtvwz]|travel)|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw])$/
0
+ before_validation :set_default_attributes
0
+ validates_presence_of :permalink_style, :search_path, :tag_path
0
+ validates_format_of :search_path, :tag_path, :with => Format::STRING
0
+ validates_format_of :host, :with => Format::DOMAIN
0
validates_uniqueness_of :host
0
- validate :check_permalink_s
lug0
+ validate :check_permalink_s
tyle0
attr_reader :permalink_variables
0
with_options :order => 'contents.created_at', :class_name => 'Comment' do |comment|
0
@@ -82,16 +79,11 @@ class Site < ActiveRecord::Base
0
Tag.find(:all, :conditions => ['contents.type = ? AND contents.site_id = ?', 'Article', id], :order => 'tags.name',
0
:joins => "INNER JOIN taggings ON taggings.tag_id = tags.id INNER JOIN contents ON (taggings.taggable_id = contents.id AND taggings.taggable_type = 'Content')")
0
- def permalink_slug() @@permalink_slug end
0
- def archive_slug() @@archive_slug end
0
- def tag_slug() @@tag_slug end
0
- def search_slug() @@search_slug end
0
def permalink_regex(refresh = false)
0
if refresh || @permalink_regex.nil?
0
@permalink_variables = []
0
- r = permalink_s
lug.split('/').inject [] do |s, piece|
0
+ r = permalink_s
tyle.split('/').inject [] do |s, piece|
0
if piece =~ PERMALINK_VAR
0
@permalink_variables << $1.to_sym
0
s << "(#{PERMALINK_OPTIONS[$1]})"
0
@@ -106,7 +98,7 @@ class Site < ActiveRecord::Base
0
def permalink_for(article)
0
- permalink_s
lug.split('/').inject [''] do |s, piece|
0
+ permalink_s
tyle.split('/').inject [''] do |s, piece|
0
s << (piece =~ PERMALINK_VAR && PERMALINK_OPTIONS.keys.include?($1) ? article.send($1).to_s : piece)
0
@@ -138,19 +130,19 @@ class Site < ActiveRecord::Base
0
var =~ PERMALINK_VAR && PERMALINK_OPTIONS.keys.include?(var)
0
- def check_permalink_slug
0
- permalink_slug.sub! /^\//, ''
0
- permalink_slug.sub! /\/$/, ''
0
- pieces = permalink_slug.split('/')
0
- errors.add :permalink_slug, 'cannot have blank paths' if pieces.any?(&:blank?)
0
+ def check_permalink_style
0
+ permalink_style.sub! /^\//, ''
0
+ permalink_style.sub! /\/$/, ''
0
+ pieces = permalink_style.split('/')
0
+ errors.add :permalink_style, 'cannot have blank paths' if pieces.any?(&:blank?)
0
- errors.add :permalink_s
lug, "cannot contain '#{$1}' variable" if p =~ PERMALINK_VAR && !PERMALINK_OPTIONS.keys.include?($1)
0
+ errors.add :permalink_s
tyle, "cannot contain '#{$1}' variable" if p =~ PERMALINK_VAR && !PERMALINK_OPTIONS.keys.include?($1)
0
unless pieces.include?(':id') || pieces.include?(':permalink')
0
- errors.add :permalink_s
lug, "must contain either :permalink or :id"
0
+ errors.add :permalink_s
tyle, "must contain either :permalink or :id"
0
if !pieces.include?(':year') && (pieces.include?(':month') || pieces.include?(':day'))
0
- errors.add :permalink_s
lug, "must contain :year for any date-based permalinks"
0
+ errors.add :permalink_s
tyle, "must contain :year for any date-based permalinks"
0
@@ -158,14 +150,16 @@ class Site < ActiveRecord::Base
0
self.host = host.to_s.downcase
0
- def set_default_timezone
0
+ def set_default_attributes
0
+ self.permalink_style = ':year/:month/:day/:permalink' if permalink_style.blank?
0
+ self.search_path = 'search' if search_path.blank?
0
+ self.tag_path = 'tags' if tag_path.blank?
0
+ [:permalink_style, :search_path, :tag_path].each { |a| send(a).downcase! }
0
self.timezone = 'UTC' if read_attribute(:timezone).blank?
0
- def set_default_comment_options
0
- self.approve_comments = false unless approve_comments?
0
- self.comment_age = 30 unless comment_age
0
+ self.approve_comments = false unless approve_comments?
0
+ self.comment_age = 30 unless comment_age