Class: CmsPage

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActsAsTree
Defined in:
app/models/cms_page.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.index_allObject



49
50
51
52
# File 'app/models/cms_page.rb', line 49

def self.index_all
  CmsPage.find(:all, :conditions => [ 'search_index is null' ]).each { |pg| pg.update_index ; pg.save_without_revision }
  true
end

.reindex_allObject



54
55
56
57
# File 'app/models/cms_page.rb', line 54

def self.reindex_all
  CmsPage.find(:all).each { |pg| pg.update_index ; pg.save_without_revision }
  true
end

Instance Method Details

#article_date_dayObject



102
# File 'app/models/cms_page.rb', line 102

def    ; .strftime("%d").to_i ; end

#article_date_monObject



101
# File 'app/models/cms_page.rb', line 101

def    ; .strftime("%b")      ; end

#article_date_monthObject



100
# File 'app/models/cms_page.rb', line 100

def  ; .strftime("%B")      ; end

#article_date_yearObject



103
# File 'app/models/cms_page.rb', line 103

def   ; .strftime("%Y").to_i ; end

#article_date_yrObject



104
# File 'app/models/cms_page.rb', line 104

def     ; .strftime("%y").to_i ; end

#compute_and_store_pathObject



24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/cms_page.rb', line 24

def compute_and_store_path
  if self.parent
    if self.parent.path != ''
      self.path = "#{self.parent.path}/#{self.name}"
    else
      self.path = self.name
    end
  else
    self.path = ''
  end
end

#html_head=(value) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'app/models/cms_page.rb', line 69

def html_head=(value)
  if value && value.is_a?(String)
    # filter suspicious content... go overboard for now, fine-tune later perhaps
    value.gsub!(/<(%.*?(exec|system)\s?\(.*?\s*%)>/, '&lt;\1&gt;')
    value.gsub!(/<(%.*?\%x\s?\[.*?\s*%)>/, '&lt;\1&gt;')
    value.gsub!(/<(%.*?`.*?\s*%)>/, '&lt;\1&gt;')
  end
  super(value)
end

#name=(value) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'app/models/cms_page.rb', line 59

def name=(value)
  if value && value.is_a?(String)
    # filter suspicious content... go overboard for now, fine-tune later perhaps
    value.gsub!(/<(%.*?(exec|system)\s?\(.*?\s*%)>/, '&lt;\1&gt;')
    value.gsub!(/<(%.*?\%x\s?\[.*?\s*%)>/, '&lt;\1&gt;')
    value.gsub!(/<(%.*?`.*?\s*%)>/, '&lt;\1&gt;')
  end
  super(value)
end

#set_parent_id!(new_id) ⇒ Object



92
93
94
95
96
97
# File 'app/models/cms_page.rb', line 92

def set_parent_id!(new_id)
  self.parent_id = new_id
  self.save_without_revision
  pg.children.each { |subpg| subpg.save_without_revision }
  self.valid?
end

#set_versionsObject



36
37
38
39
40
41
42
43
# File 'app/models/cms_page.rb', line 36

def set_versions
  if self.template
    self.cms_template_version ||= self.template.version
  end
  
  self.published_version ||= -1
  self.published_date ||= self.created_on || Time.now
end

#tags_as_css_classesObject



45
46
47
# File 'app/models/cms_page.rb', line 45

def tags_as_css_classes
  self.tags.map { |t| t.name.downcase.gsub(/[^\w]+/, '-') }.join(' ')
end

#update_indexObject



79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/models/cms_page.rb', line 79

def update_index
  content = ''
  
  if self.published_version.to_i >= 0
    idx_version = self.published_version.to_i == 0 ? self.version : self.published_version
    self.objects.find(:all, :conditions => [ "cms_page_version = ? and (obj_type = 'text' or obj_type = 'string')", idx_version ]).each do |obj|
      content << obj.content << "\n"
    end
  end
  
  self.search_index = sanitize_index(content)
end