Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 13
- Log:
Initial import of Typo 2.6.0 sources from a downloaded Tarball.
Typo is a Ruby On Rails based blog engine.
- Author:
- adh
- Date:
- Sat Jul 22 22:25:02 +0100 2006
- Size:
- 5593 Bytes
1 | class ArticlesController < ApplicationController |
2 | before_filter :verify_config |
3 | before_filter :ignore_page_query_param |
4 | layout :theme_layout |
5 | |
6 | cache_sweeper :blog_sweeper |
7 | caches_page :index, :read, :permalink, :category, :find_by_date, :archives, :view_page |
8 | |
9 | verify :only => [:nuke_comment, :nuke_trackback], :session => :user, :method => :post, :render => { :text => 'Forbidden', :status => 403 } |
10 | |
11 | def index |
12 | @pages = Paginator.new self, Article.count, config[:limit_article_display], @params[:page] |
13 | @articles = Article.find(:all, :conditions => 'published != 0', :order => 'created_at DESC', :limit => config[:limit_article_display], :offset => @pages.current.offset) |
14 | end |
15 | |
16 | def search |
17 | @articles = Article.search(params[:q]) |
18 | end |
19 | |
20 | def archives |
21 | @articles = Article.find(:all, :conditions => 'published != 0', :order => 'created_at DESC', :include => [:categories]) |
22 | end |
23 | |
24 | def read |
25 | @article = Article.find(params[:id], :include => [:categories]) |
26 | @comment = Comment.new |
27 | @page_title = @article.title |
28 | end |
29 | |
30 | def permalink |
31 | @article = Article.find_by_permalink(params[:year], params[:month], params[:day], params[:title]) |
32 | @comment = Comment.new |
33 | |
34 | if @article.nil? |
35 | error("Post not found...") |
36 | else |
37 | @page_title = @article.title |
38 | render :action => "read" |
39 | end |
40 | end |
41 | |
42 | def find_by_date |
43 | @articles = Article.find_all_by_date(params[:year], params[:month], params[:day]) |
44 | @pages = Paginator.new self, @articles.size, config[:limit_article_display], @params[:page] |
45 | |
46 | if @articles.empty? |
47 | error("No posts found...") |
48 | else |
49 | start = @pages.current.offset |
50 | stop = (@pages.current.next.offset - 1) rescue @articles.size |
51 | @articles = @articles.slice(start..stop) |
52 | |
53 | render :action => "index" |
54 | end |
55 | end |
56 | |
57 | def error(message = "Record not found...") |
58 | @message = message |
59 | render :action => "error" |
60 | end |
61 | |
62 | def category |
63 | if category = Category.find_by_permalink(params[:id]) |
64 | @articles = Article.find(:all, :conditions => [%{ published != 0 |
65 | AND articles.id = articles_categories.article_id |
66 | AND articles_categories.category_id = ? }, category.id], |
67 | :joins => ', articles_categories', |
68 | :order => "created_at DESC") |
69 | |
70 | @pages = Paginator.new self, @articles.size, config[:limit_article_display], @params[:page] |
71 | |
72 | start = @pages.current.offset |
73 | stop = (@pages.current.next.offset - 1) rescue @articles.size |
74 | # Why won't this work? @articles.slice!(start..stop) |
75 | @articles = @articles.slice(start..stop) |
76 | |
77 | render :action => "index" |
78 | else |
79 | error("Can't find posts in category #{params[:id]}") |
80 | end |
81 | end |
82 | |
83 | # Receive comments to articles |
84 | def comment |
85 | @article = Article.find(params[:id]) |
86 | @comment = Comment.new(params[:comment]) |
87 | @comment.article = @article |
88 | @comment.ip = request.remote_ip |
89 | |
90 | if request.post? and @comment.save |
91 | @comment.body = "" |
92 | |
93 | cookies[:author] = { :value => @comment.author, :path => '/' + controller_name, :expires => 6.weeks.from_now } |
94 | cookies[:url] = { :value => @comment.url, :path => '/' + controller_name, :expires => 6.weeks.from_now } |
95 | |
96 | @headers["Content-Type"] = "text/html; charset=utf-8" |
97 | |
98 | render :partial => "comment", :object => @comment |
99 | else |
100 | render :text => @comment.errors.full_messages.join(", "), :status => 500 |
101 | end |
102 | end |
103 | |
104 | # Receive trackbacks linked to articles |
105 | def trackback |
106 | @result = true |
107 | |
108 | if params[:__mode] == "rss" |
109 | # Part of the trackback spec... will implement later |
110 | else |
111 | # url is required |
112 | unless params.has_key?(:url) and params.has_key?(:id) |
113 | @result = false |
114 | @error_message = "A URL is required." |
115 | else |
116 | begin |
117 | article = Article.find(params[:id]) |
118 | tb = article.build_to_trackbacks |
119 | tb.url = params[:url] |
120 | tb.title = params[:title] || params[:url] |
121 | tb.excerpt = params[:excerpt] |
122 | tb.blog_name = params[:blog_name] |
123 | tb.ip = request.remote_ip |
124 | unless article.save |
125 | @result = false |
126 | @error_message = "Trackback not saved. Database problem most likely." |
127 | end |
128 | rescue ActiveRecord::RecordNotFound, ActiveRecord::StatementInvalid |
129 | @result = false |
130 | @error_message = "Article id #{params[:id]} not found." |
131 | end |
132 | end |
133 | end |
134 | render :layout => false |
135 | end |
136 | |
137 | def nuke_comment |
138 | if(session[:user]) |
139 | comment = Comment.find(params[:id]) |
140 | comment.destroy |
141 | render :nothing => true |
142 | end |
143 | end |
144 | |
145 | def nuke_trackback |
146 | if(session[:user]) |
147 | trackback = Trackback.find(params[:id]) |
148 | trackback.destroy |
149 | render :nothing => true |
150 | end |
151 | end |
152 | |
153 | def view_page |
154 | if(@page = Page.find_by_name(params[:name].to_a.join('/'))) |
155 | @page_title = @page.title |
156 | render |
157 | else |
158 | render :nothing => true, :status => 404 |
159 | end |
160 | end |
161 | |
162 | private |
163 | |
164 | def ignore_page_query_param |
165 | @params[:page] = nil unless @request.path =~ /\/page\// # assumes all page routes use /page/:page |
166 | end |
167 | |
168 | def verify_config |
169 | if User.count == 0 |
170 | redirect_to :controller => "accounts", :action => "signup" |
171 | elsif !config.is_ok? |
172 | redirect_to :controller => "admin/general", :action => "index" |
173 | else |
174 | return true |
175 | end |
176 | end |
177 | |
178 | def rescue_action_in_public(exception) |
179 | error(exception.message) |
180 | end |
181 | |
182 | end |