Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 71
- Log:
Start of upgrade to Typo 4.0.0, the latest stable release since
2.6.0. Note test/mocks/themes/azure changes from a file to a
directory, so the file has been removed in this revision and
the directory will be added in the next revision.
- Author:
- adh
- Date:
- Mon Aug 07 22:18:11 +0100 2006
- Size:
- 7411 Bytes
1 | class ArticlesController < ContentController |
2 | before_filter :verify_config |
3 | |
4 | layout :theme_layout, :except => [:comment_preview, :trackback] |
5 | |
6 | cache_sweeper :blog_sweeper |
7 | |
8 | cached_pages = [:index, :read, :permalink, :category, :find_by_date, :archives, :view_page, :tag, :author] |
9 | # If you're really memory-constrained, then consider replacing |
10 | # caches_action_with_params with caches_page |
11 | caches_action_with_params *cached_pages |
12 | session :off, :only => cached_pages |
13 | |
14 | verify(:only => [:nuke_comment, :nuke_trackback], |
15 | :session => :user, :method => :post, |
16 | :render => { :text => 'Forbidden', :status => 403 }) |
17 | |
18 | def index |
19 | # On Postgresql, paginate's default count is *SLOW*, because it does a join against |
20 | # all of the eager-loaded tables. I've seen it take up to 7 seconds on my test box. |
21 | # |
22 | # So, we're going to use the older Paginator class and manually provide a count. |
23 | # This is a 100x speedup on my box. |
24 | count = Article.count(:conditions => ['published = ? AND contents.published_at < ? AND blog_id = ?', |
25 | true, Time.now, this_blog.id]) |
26 | @pages = Paginator.new self, count, this_blog.limit_article_display, @params[:page] |
27 | @articles = Article.find( :all, |
28 | :offset => @pages.current.offset, |
29 | :limit => @pages.items_per_page, |
30 | :order => "contents.published_at DESC", |
31 | :include => [:categories, :tags, :user, :blog], |
32 | :conditions => |
33 | ['published = ? AND contents.published_at < ? AND blog_id = ?', |
34 | true, Time.now, this_blog.id] |
35 | ) |
36 | end |
37 | |
38 | def search |
39 | @articles = this_blog.published_articles.search(params[:q]) |
40 | render_paginated_index("No articles found...") |
41 | end |
42 | |
43 | def comment_preview |
44 | if params[:comment].blank? or params[:comment][:body].blank? |
45 | render :nothing => true |
46 | return |
47 | end |
48 | |
49 | set_headers |
50 | @comment = this_blog.comments.build(params[:comment]) |
51 | @controller = self |
52 | end |
53 | |
54 | def archives |
55 | @articles = this_blog.published_articles |
56 | end |
57 | |
58 | def read |
59 | display_article { this_blog.published_articles.find(params[:id]) } |
60 | end |
61 | |
62 | def permalink |
63 | display_article(this_blog.published_articles.find_by_permalink(*params.values_at(:year, :month, :day, :title))) |
64 | end |
65 | |
66 | def find_by_date |
67 | @articles = this_blog.published_articles.find_all_by_date(params[:year], params[:month], params[:day]) |
68 | render_paginated_index |
69 | end |
70 | |
71 | def error(message = "Record not found...") |
72 | @message = message.to_s |
73 | render :action => 'error' |
74 | end |
75 | |
76 | def author |
77 | render_grouping(User) |
78 | end |
79 | |
80 | def category |
81 | render_grouping(Category) |
82 | end |
83 | |
84 | def tag |
85 | render_grouping(Tag) |
86 | end |
87 | |
88 | # Receive comments to articles |
89 | def comment |
90 | unless @request.xhr? || this_blog.sp_allow_non_ajax_comments |
91 | render_error("non-ajax commenting is disabled") |
92 | return |
93 | end |
94 | |
95 | if request.post? |
96 | begin |
97 | params[:comment].merge!({:ip => request.remote_ip, |
98 | :published => true }) |
99 | @article = this_blog.published_articles.find(params[:id]) |
100 | @comment = @article.comments.build(params[:comment]) |
101 | @comment.user = session[:user] |
102 | |
103 | spam_options = { |
104 | :user_agent => request.env['HTTP_USER_AGENT'], |
105 | :referrer => request.env['HTTP_REFERER'], |
106 | :permalink => this_blog.article_url(@article, false)} |
107 | |
108 | if @comment.is_spam? spam_options |
109 | STDERR.puts "Moderating comment as spam!" |
110 | @comment.withdraw |
111 | end |
112 | |
113 | @comment.save! |
114 | add_to_cookies(:author, @comment.author) |
115 | add_to_cookies(:url, @comment.url) |
116 | |
117 | set_headers |
118 | render :partial => "comment", :object => @comment |
119 | rescue ActiveRecord::RecordInvalid |
120 | STDERR.puts @comment.errors.inspect |
121 | render_error(@comment) |
122 | end |
123 | end |
124 | end |
125 | |
126 | # Receive trackbacks linked to articles |
127 | def trackback |
128 | @error_message = catch(:error) do |
129 | if params[:__mode] == "rss" |
130 | # Part of the trackback spec... will implement later |
131 | # XXX. Should this throw an error? |
132 | elsif !(params.has_key?(:url) && params.has_key?(:id)) |
133 | throw :error, "A URL is required" |
134 | else |
135 | begin |
136 | settings = { :id => params[:id], |
137 | :url => params[:url], :blog_name => params[:blog_name], |
138 | :title => params[:title], :excerpt => params[:excerpt], |
139 | :ip => request.remote_ip, :published => true } |
140 | this_blog.ping_article!(settings) |
141 | rescue ActiveRecord::RecordNotFound, ActiveRecord::StatementInvalid |
142 | throw :error, "Article id #{params[:id]} not found." |
143 | rescue ActiveRecord::RecordInvalid |
144 | throw :error, "Trackback not saved" |
145 | end |
146 | end |
147 | nil |
148 | end |
149 | end |
150 | |
151 | def nuke_comment |
152 | Comment.find(params[:id]).destroy |
153 | render :nothing => true |
154 | end |
155 | |
156 | def nuke_trackback |
157 | Trackback.find(params[:id]).destroy |
158 | render :nothing => true |
159 | end |
160 | |
161 | def view_page |
162 | if(@page = Page.find_by_name(params[:name].to_a.join('/'))) |
163 | @page_title = @page.title |
164 | else |
165 | render :nothing => true, :status => 404 |
166 | end |
167 | end |
168 | |
169 | def markup_help |
170 | render :text => TextFilter.find(params[:id]).commenthelp |
171 | end |
172 | |
173 | private |
174 | |
175 | def add_to_cookies(name, value, path=nil, expires=nil) |
176 | cookies[name] = { :value => value, :path => path || "/#{controller_name}", |
177 | :expires => 6.weeks.from_now } |
178 | end |
179 | |
180 | def verify_config |
181 | if User.count == 0 |
182 | redirect_to :controller => "accounts", :action => "signup" |
183 | elsif ! this_blog.is_ok? |
184 | redirect_to :controller => "admin/general", :action => "redirect" |
185 | else |
186 | return true |
187 | end |
188 | end |
189 | |
190 | def display_article(article = nil) |
191 | begin |
192 | @article = block_given? ? yield : article |
193 | @comment = Comment.new |
194 | @page_title = @article.title |
195 | auto_discovery_feed :type => 'article', :id => @article.id |
196 | render :action => 'read' |
197 | rescue ActiveRecord::RecordNotFound, NoMethodError => e |
198 | error("Post not found...") |
199 | end |
200 | end |
201 | |
202 | alias_method :rescue_action_in_public, :error |
203 | |
204 | def render_error(object = '', status = 500) |
205 | render(:text => (object.errors.full_messages.join(", ") rescue object.to_s), :status => status) |
206 | end |
207 | |
208 | def set_headers |
209 | @headers["Content-Type"] = "text/html; charset=utf-8" |
210 | end |
211 | |
212 | def list_groupings(klass) |
213 | @grouping_class = klass |
214 | @groupings = klass.find_all_with_article_counters(1000) |
215 | render :action => 'groupings' |
216 | end |
217 | |
218 | def render_grouping(klass) |
219 | return list_groupings(klass) unless params[:id] |
220 | |
221 | @page_title = "#{this_blog.blog_name} - #{klass.to_s.underscore} #{params[:id]}" |
222 | @articles = klass.find_by_permalink(params[:id]).articles.find_already_published rescue [] |
223 | auto_discovery_feed :type => klass.to_s.underscore, :id => params[:id] |
224 | render_paginated_index("Can't find posts with #{klass.to_prefix} '#{h(params[:id])}'") |
225 | end |
226 | |
227 | def render_paginated_index(on_empty = "No posts found...") |
228 | return error(on_empty) if @articles.empty? |
229 | |
230 | @pages = Paginator.new self, @articles.size, this_blog.limit_article_display, @params[:page] |
231 | start = @pages.current.offset |
232 | stop = (@pages.current.next.offset - 1) rescue @articles.size |
233 | # Why won't this work? @articles.slice!(start..stop) |
234 | @articles = @articles.slice(start..stop) |
235 | render :action => 'index' |
236 | end |
237 | end |