Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 15
- Log:
Attempt to update Typo to a Typo SVN HEAD release from around the
time the prototype installation was set up on the RISC OS Open Limited
web site. Timestamps place this at 04-Jul so a revision from 05-Jul or
earlier was pulled and copied over the 2.6.0 tarball stable code.
- Author:
- adh
- Date:
- Sat Jul 22 23:27:35 +0100 2006
- Size:
- 6582 Bytes
1 | class ArticlesController < ContentController |
2 | before_filter :verify_config |
3 | before_filter :check_page_query_param_for_missing_routes |
4 | |
5 | layout :theme_layout, :except => [:comment_preview, :trackback] |
6 | |
7 | cache_sweeper :blog_sweeper |
8 | |
9 | cached_pages = [:index, :read, :permalink, :category, :find_by_date, :archives, :view_page, :tag, :author] |
10 | # If you're really memory-constrained, then consider replacing |
11 | # caches_action_with_params with caches_page |
12 | caches_action_with_params *cached_pages |
13 | session :off, :only => cached_pages |
14 | |
15 | verify(:only => [:nuke_comment, :nuke_trackback], |
16 | :session => :user, :method => :post, |
17 | :render => { :text => 'Forbidden', :status => 403 }) |
18 | |
19 | def index |
20 | @pages, @articles = |
21 | paginate(:article, :per_page => this_blog.limit_article_display, |
22 | :conditions => |
23 | ['published = ? AND contents.created_at < ? AND blog_id = ?', |
24 | true, Time.now, this_blog.id], |
25 | :order_by => "contents.created_at DESC", |
26 | :include => [:categories, :tags]) |
27 | end |
28 | |
29 | def search |
30 | @articles = this_blog.published_articles.search(params[:q]) |
31 | render_paginated_index("No articles found...") |
32 | end |
33 | |
34 | def comment_preview |
35 | if params[:comment].blank? or params[:comment][:body].blank? |
36 | render :nothing => true |
37 | return |
38 | end |
39 | |
40 | set_headers |
41 | @comment = this_blog.comments.build(params[:comment]) |
42 | @controller = self |
43 | end |
44 | |
45 | def archives |
46 | @articles = this_blog.published_articles |
47 | end |
48 | |
49 | def read |
50 | display_article { this_blog.published_articles.find(params[:id]) } |
51 | end |
52 | |
53 | def permalink |
54 | display_article(this_blog.published_articles.find_by_permalink(*params.values_at(:year, :month, :day, :title))) |
55 | end |
56 | |
57 | def find_by_date |
58 | @articles = this_blog.published_articles.find_all_by_date(params[:year], params[:month], params[:day]) |
59 | render_paginated_index |
60 | end |
61 | |
62 | def error(message = "Record not found...") |
63 | @message = message.to_s |
64 | render :action => 'error' |
65 | end |
66 | |
67 | def author |
68 | render_grouping(User) |
69 | end |
70 | |
71 | def category |
72 | render_grouping(Category) |
73 | end |
74 | |
75 | def tag |
76 | render_grouping(Tag) |
77 | end |
78 | |
79 | # Receive comments to articles |
80 | def comment |
81 | unless @request.xhr? || this_blog.sp_allow_non_ajax_comments |
82 | render_error("non-ajax commenting is disabled") |
83 | return |
84 | end |
85 | |
86 | if request.post? |
87 | begin |
88 | params[:comment].merge!({:ip => request.remote_ip, |
89 | :published => true }) |
90 | @article = this_blog.published_articles.find(params[:id]) |
91 | @comment = @article.comments.build(params[:comment]) |
92 | @comment.user = session[:user] |
93 | @comment.save! |
94 | add_to_cookies(:author, @comment.author) |
95 | add_to_cookies(:url, @comment.url) |
96 | |
97 | set_headers |
98 | render :partial => "comment", :object => @comment |
99 | rescue ActiveRecord::RecordInvalid |
100 | STDERR.puts @comment.errors.inspect |
101 | render_error(@comment) |
102 | end |
103 | end |
104 | end |
105 | |
106 | # Receive trackbacks linked to articles |
107 | def trackback |
108 | @error_message = catch(:error) do |
109 | if params[:__mode] == "rss" |
110 | # Part of the trackback spec... will implement later |
111 | # XXX. Should this throw an error? |
112 | elsif !(params.has_key?(:url) && params.has_key?(:id)) |
113 | throw :error, "A URL is required" |
114 | else |
115 | begin |
116 | settings = { :id => params[:id], |
117 | :url => params[:url], :blog_name => params[:blog_name], |
118 | :title => params[:title], :excerpt => params[:excerpt], |
119 | :ip => request.remote_ip, :published => true } |
120 | this_blog.ping_article!(settings) |
121 | rescue ActiveRecord::RecordNotFound, ActiveRecord::StatementInvalid |
122 | throw :error, "Article id #{params[:id]} not found." |
123 | rescue ActiveRecord::RecordInvalid |
124 | throw :error, "Trackback not saved" |
125 | end |
126 | end |
127 | nil |
128 | end |
129 | end |
130 | |
131 | def nuke_comment |
132 | Comment.find(params[:id]).destroy |
133 | render :nothing => true |
134 | end |
135 | |
136 | def nuke_trackback |
137 | Trackback.find(params[:id]).destroy |
138 | render :nothing => true |
139 | end |
140 | |
141 | def view_page |
142 | if(@page = Page.find_by_name(params[:name].to_a.join('/'))) |
143 | @page_title = @page.title |
144 | else |
145 | render :nothing => true, :status => 404 |
146 | end |
147 | end |
148 | |
149 | private |
150 | |
151 | def add_to_cookies(name, value, path=nil, expires=nil) |
152 | cookies[name] = { :value => value, :path => path || "/#{controller_name}", |
153 | :expires => 6.weeks.from_now } |
154 | end |
155 | |
156 | def check_page_query_param_for_missing_routes |
157 | unless request.path =~ /\/page\// |
158 | raise "Page param problem" unless params[:page].nil? |
159 | end |
160 | end |
161 | |
162 | def verify_config |
163 | if User.count == 0 |
164 | redirect_to :controller => "accounts", :action => "signup" |
165 | elsif ! this_blog.is_ok? |
166 | redirect_to :controller => "admin/general", :action => "redirect" |
167 | else |
168 | return true |
169 | end |
170 | end |
171 | |
172 | def display_article(article = nil) |
173 | begin |
174 | @article = block_given? ? yield : article |
175 | @comment = Comment.new |
176 | @page_title = @article.title |
177 | auto_discovery_feed :type => 'article', :id => @article.id |
178 | render :action => 'read' |
179 | rescue ActiveRecord::RecordNotFound, NoMethodError => e |
180 | error("Post not found...") |
181 | end |
182 | end |
183 | |
184 | alias_method :rescue_action_in_public, :error |
185 | |
186 | def render_error(object = '', status = 500) |
187 | render(:text => (object.errors.full_messages.join(", ") rescue object.to_s), :status => status) |
188 | end |
189 | |
190 | def set_headers |
191 | @headers["Content-Type"] = "text/html; charset=utf-8" |
192 | end |
193 | |
194 | def list_groupings(klass) |
195 | @grouping_class = klass |
196 | @groupings = klass.find_all_with_article_counters(1000) |
197 | render :action => 'groupings' |
198 | end |
199 | |
200 | def render_grouping(klass) |
201 | return list_groupings(klass) unless params[:id] |
202 | |
203 | @articles = klass.find_by_permalink(params[:id]).articles.find_already_published rescue [] |
204 | auto_discovery_feed :type => klass.to_s.underscore, :id => params[:id] |
205 | render_paginated_index("Can't find posts with #{klass.to_prefix} '#{h(params[:id])}'") |
206 | end |
207 | |
208 | def render_paginated_index(on_empty = "No posts found...") |
209 | return error(on_empty) if @articles.empty? |
210 | |
211 | @pages = Paginator.new self, @articles.size, this_blog.limit_article_display, @params[:page] |
212 | start = @pages.current.offset |
213 | stop = (@pages.current.next.offset - 1) rescue @articles.size |
214 | # Why won't this work? @articles.slice!(start..stop) |
215 | @articles = @articles.slice(start..stop) |
216 | render :action => 'index' |
217 | end |
218 | end |