Changeset 1676
- Timestamp:
- 03/15/08 09:53:35 (2 months ago)
- Files:
-
- trunk/app/controllers/content_controller.rb (modified) (1 diff)
- trunk/app/models/article.rb (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/content_controller.rb
r1612 r1676 24 24 helper :theme 25 25 # before_filter :auto_discovery_defaults 26 27 28 29 26 30 27 def self.caches_action_with_params(*actions) trunk/app/models/article.rb
r1670 r1676 8 8 9 9 has_many :pings, :dependent => :destroy, :order => "created_at ASC" 10 10 11 has_many :comments, :dependent => :destroy, :order => "created_at ASC" 11 12 with_options(:conditions => { :published => true }, :order => 'created_at DESC') do |this| … … 14 15 this.has_many :published_feedback, :class_name => "Feedback", :order => "created_at ASC" 15 16 end 17 16 18 has_many :trackbacks, :dependent => :destroy, :order => "created_at ASC" 19 17 20 has_many :feedback, :order => "created_at DESC" 21 18 22 has_many :resources, :order => "created_at DESC", 19 23 :class_name => "Resource", :foreign_key => 'article_id' 24 after_destroy :fix_resources 20 25 21 26 has_many :categorizations … … 26 31 27 32 has_and_belongs_to_many :tags, :foreign_key => 'article_id' 33 28 34 belongs_to :user 35 29 36 has_many :triggers, :as => :pending_item 30 31 37 after_save :post_trigger 32 after_destroy :fix_resources33 38 34 39 has_state(:state, … … 43 48 44 49 45 include States50 include Article::States 46 51 47 52 class << self … … 55 60 end 56 61 62 accents = { ['á','à ','â','À','ã','Ã','Ã','Ã','Ã'] => 'a', 63 ['é','Ú','ê','ë','Ã','Ã','Ã','Ã'] => 'e', 64 ['Ã','ì','î','ï','I','Ã','Ã'] => 'i', 65 ['ó','ò','ÃŽ','ö','õ','Ã','Ã','Ã','Ã'] => 'o', 66 ['Å'] => 'oe', 67 ['Ã'] => 'ss', 68 ['ú','ù','û','ÃŒ','U','Ã','Ã'] => 'u', 69 ['ç','Ã'] => 'c' 70 } 71 72 FROM, TO = accents.inject(['','']) { |o,(k,v)| 73 o[0] << k * ''; 74 o[1] << v * k.size 75 o 76 } 77 57 78 def stripped_title 58 str = String.new(self.title) 59 60 accents = { ['á','à ','â','À','ã','Ã','Ã','Ã','Ã'] => 'a', 61 ['é','Ú','ê','ë','Ã','Ã','Ã','Ã'] => 'e', 62 ['Ã','ì','î','ï','I','Ã','Ã'] => 'i', 63 ['ó','ò','ÃŽ','ö','õ','Ã','Ã','Ã','Ã'] => 'o', 64 ['Å'] => 'oe', 65 ['Ã'] => 'ss', 66 ['ú','ù','û','ÃŒ','U','Ã','Ã'] => 'u', 67 ['ç','Ã'] => 'c' 68 } 69 accents.each do |ac,rep| 70 ac.each do |s| 71 str.gsub!(s, rep) 72 end 73 end 74 75 str.gsub(/<[^>]*>/,'').to_url 79 self.title.tr(FROM, TO).gsub(/<[^>]*>/, '').to_url 76 80 end 77 81 78 82 def permalink_url_options(nesting = false) 79 {:year => published_at.year,80 :month => sprintf("%.2d", published_at.month),81 :day => sprintf("%.2d", published_at.day),82 :controller => 'articles',83 :action => 'show',83 {:year => published_at.year, 84 :month => sprintf("%.2d", published_at.month), 85 :day => sprintf("%.2d", published_at.day), 86 :controller => 'articles', 87 :action => 'show', 84 88 (nesting ? :article_id : :id) => permalink} 85 89 end … … 87 91 def permalink_url(anchor=nil, only_path=true) 88 92 @cached_permalink_url ||= {} 93 89 94 @cached_permalink_url["#{anchor}#{only_path}"] ||= \ 90 95 blog.with_options(permalink_url_options) do |b| … … 95 100 def param_array 96 101 @param_array ||= 97 returning([published_at.year, sprintf('%.2d', published_at.month), 98 sprintf('%.2d', published_at.day), permalink]) do |params| 99 this = self 100 k = class << params; self; end 101 k.send(:define_method, :to_s) { params[-1] } 102 end 102 returning([published_at.year, 103 sprintf('%.2d', published_at.month), 104 sprintf('%.2d', published_at.day), 105 permalink]) \ 106 do |params| 107 this = self 108 k = class << params; self; end 109 k.send(:define_method, :to_s) { params[-1] } 110 end 103 111 end 104 112 … … 164 172 165 173 def next 166 blog.articles.find(:first, :conditions => ['published_at > ?', published_at],167 :order => 'published_at asc')174 self.class.find(:first, :conditions => ['published_at > ?', published_at], 175 :order => 'published_at asc') 168 176 end 169 177 170 178 def previous 171 blog.articles.find(:first, :conditions => ['published_at < ?', published_at],172 :order => 'published_at desc')179 self.class.find(:first, :conditions => ['published_at < ?', published_at], 180 :order => 'published_at desc') 173 181 end 174 182 … … 176 184 def self.count_by_date(year, month = nil, day = nil, limit = nil) 177 185 if !year.blank? 178 from, to = self.time_delta(year, month, day) 179 Article.count(["published_at BETWEEN ? AND ? AND published = ?", 180 from, to, true]) 186 count(:conditions => { :published_at => time_delta(year, month, day), 187 :published => true }) 181 188 else 182 Article.count(:conditions => { :published => true })189 count(:conditions => { :published => true }) 183 190 end 184 191 end … … 187 194 def self.find_all_by_date(year, month = nil, day = nil) 188 195 if !year.blank? 189 f rom, to = self.time_delta(year, month, day)190 Article.find_published(:all, :conditions => ["published_at BETWEEN ? AND ?",191 from, to])196 find_published(:all, 197 :conditions => { :published_at => 198 time_delta(year,month,day) }) 192 199 else 193 Article.find_published(:all)200 find_published(:all) 194 201 end 195 202 end … … 217 224 end 218 225 end 219 from, to = self.time_delta(year, month, day) 220 returning(find_published(:first, 221 :conditions => ['permalink = ? AND ' + 222 'published_at BETWEEN ? AND ?', 223 title, from, to ])) do |res| 224 if res.nil? 225 raise ActiveRecord::RecordNotFound 226 end 227 end 226 date_range = self.time_delta(year, month, day) 227 find_published(:first, 228 :conditions => { :permalink => title, 229 :published_at => date_range }) \ 230 or raise ActiveRecord::RecordNotFound 228 231 end 229 232 … … 473 476 to = from + 1.day unless day.blank? 474 477 to = to - 1 # pull off 1 second so we don't overlap onto the next day 475 return [from, to]478 return from..to 476 479 end 477 480
