Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 488
- Log:
Jan 2024 forum updates
- Author:
- rool
- Date:
- Sun Jan 28 09:28:34 +0000 2024
- Size:
- 6147 Bytes
1 | class PostsController < ApplicationController |
2 | before_filter :find_post, :except => [:index, :index_rss, :create, :monitored, :search] |
3 | @@query_options = { :select => 'posts.*, topics.title as topic_title, forums.name as forum_name', :joins => 'inner join topics on posts.topic_id = topics.id inner join forums on topics.forum_id = forums.id', :order => 'posts.created_at desc' } |
4 | |
5 | @@hubssolib_permissions = HubSsoLib::Permissions.new({ |
6 | :new => [ :admin, :webmaster, :privileged, :normal ], |
7 | :create => [ :admin, :webmaster, :privileged, :normal ], |
8 | :edit => [ :admin, :webmaster, :privileged, :normal ], |
9 | :update => [ :admin, :webmaster, :privileged, :normal ], |
10 | :destroy => [ :admin, :webmaster ], |
11 | }) |
12 | |
13 | def PostsController.hubssolib_permissions |
14 | @@hubssolib_permissions |
15 | end |
16 | |
17 | def index |
18 | index_initialise |
19 | render_posts_or_xml |
20 | end |
21 | |
22 | # Backwards compatibility with RForum global feed via a routing hack. |
23 | # |
24 | def index_rss |
25 | index_initialise |
26 | render :action => "index.rxml", :layout => false |
27 | end |
28 | |
29 | def search |
30 | conditions = params[:q].blank? ? nil : Post.send(:sanitize_sql, ['LOWER(posts.body) LIKE ?', "%#{params[:q].downcase}%"]) |
31 | @post_pages, @posts = paginate(:posts, @@query_options.merge(:conditions => conditions).merge(per_page())) |
32 | @users = User.find(:all, :select => 'distinct *', :conditions => ['id in (?)', @posts.collect(&:user_id).uniq]).index_by(&:id) |
33 | render_posts_or_xml :index |
34 | end |
35 | |
36 | def monitored |
37 | @user = User.find params[:user_id] |
38 | options = @@query_options.merge(:conditions => ['monitorships.user_id = ? and posts.user_id != ?', params[:user_id], @user.id]) |
39 | options[:joins] += ' inner join monitorships on monitorships.topic_id = topics.id' |
40 | @post_pages, @posts = paginate(:posts, options.merge(per_page())) |
41 | render_posts_or_xml |
42 | end |
43 | |
44 | def show |
45 | respond_to do |format| |
46 | format.html { redirect_to topic_path(@post.forum_id, @post.topic_id) } |
47 | format.xml { render :xml => @post.to_xml } |
48 | end |
49 | end |
50 | |
51 | def create |
52 | @topic = Topic.find_by_id_and_forum_id(params[:topic_id],params[:forum_id], :include => :forum) |
53 | if @topic.locked? |
54 | respond_to do |format| |
55 | format.html do |
56 | flash[:notice] = 'This topic is locked.' |
57 | redirect_to(long_topic_path()) |
58 | end |
59 | format.xml do |
60 | render :text => 'This topic is locked.', :status => 400 |
61 | end |
62 | end |
63 | return |
64 | end |
65 | @forum = @topic.forum |
66 | @post = @topic.posts.build(params[:post]) |
67 | @post.user = current_user |
68 | @post.save! |
69 | respond_to do |format| |
70 | format.html do |
71 | redirect_to(long_topic_path(@post.dom_id)) |
72 | end |
73 | format.xml { head :created, :location => formatted_post_url(:forum_id => params[:forum_id], :topic_id => params[:topic_id], :id => @post, :format => :xml) } |
74 | end |
75 | rescue ActiveRecord::RecordInvalid |
76 | flash[:bad_reply] = 'Your reply was empty, or contained prohibited words' |
77 | respond_to do |format| |
78 | format.html do |
79 | redirect_to(long_topic_path('reply-form')) |
80 | end |
81 | format.xml { render :xml => @post.errors.to_xml, :status => 400 } |
82 | end |
83 | end |
84 | |
85 | def edit |
86 | respond_to do |format| |
87 | format.html |
88 | format.js |
89 | end |
90 | end |
91 | |
92 | def update |
93 | @post.attributes = params[:post] |
94 | @post.save! |
95 | rescue ActiveRecord::RecordInvalid |
96 | flash[:bad_reply] = 'Your edited post was empty, or contained prohibited words' |
97 | ensure |
98 | respond_to do |format| |
99 | format.html do |
100 | redirect_to(long_topic_path(@post.dom_id)) |
101 | end |
102 | format.js |
103 | format.xml { head 200 } |
104 | end |
105 | end |
106 | |
107 | def destroy |
108 | @post.destroy |
109 | flash[:notice] = "Post of '#{CGI::escapeHTML @post.topic.title}' was deleted." |
110 | # check for posts_count == 1 because its cached and counting the currently deleted post |
111 | @post.topic.destroy and redirect_to forum_path(params[:forum_id]) if @post.topic.posts_count == 1 |
112 | respond_to do |format| |
113 | format.html do |
114 | redirect_to(long_topic_path()) unless performed? |
115 | end |
116 | format.xml { head 200 } |
117 | end |
118 | end |
119 | |
120 | protected |
121 | def index_initialise |
122 | conditions = [] |
123 | [:user_id, :forum_id].each { |attr| conditions << Post.send(:sanitize_sql, ["posts.#{attr} = ?", params[attr]]) if params[attr] } |
124 | conditions = conditions.any? ? conditions.collect { |c| "(#{c})" }.join(' AND ') : nil |
125 | |
126 | if conditions.nil? |
127 | if params[:tests_and_aldershot] == 'yes' |
128 | conditions = "(name = 'Aldershot' OR name = 'Tests')" |
129 | elsif params[:everything] != 'yes' |
130 | conditions = "name != 'Aldershot' AND name != 'Tests'" |
131 | end |
132 | end |
133 | |
134 | @post_pages, @posts = paginate(:posts, @@query_options.merge(:conditions => conditions).merge(per_page())) |
135 | @users = User.find(:all, :select => 'distinct *', :conditions => ['id in (?)', @posts.collect(&:user_id).uniq]).index_by(&:id) |
136 | end |
137 | |
138 | def authorized? |
139 | action_name == 'create' || @post.editable_by?(current_user) |
140 | end |
141 | |
142 | def find_post |
143 | @post = Post.find_by_id_and_topic_id_and_forum_id(params[:id], params[:topic_id], params[:forum_id]) || raise(ActiveRecord::RecordNotFound) |
144 | end |
145 | |
146 | def render_posts_or_xml(template_name = action_name) |
147 | respond_to do |format| |
148 | format.html { render :action => "#{template_name}.rhtml" } |
149 | format.rss { render :action => "#{template_name}.rxml", :layout => false } |
150 | format.xml { render :xml => @posts.to_xml } |
151 | end |
152 | end |
153 | |
154 | def long_topic_path(anchor = nil) |
155 | options = { |
156 | :forum_id => params[:forum_id], |
157 | :id => params[:topic_id] |
158 | } |
159 | |
160 | options[:anchor] = anchor unless (anchor.nil?) |
161 | options[:page] = (params[:page] || '1').to_i.to_s if (params.has_key?(:page)) |
162 | options[:posts_per_page] = (params[:posts_per_page] || '25').to_i.to_s if (params.has_key?(:posts_per_page)) |
163 | |
164 | topic_path(options) |
165 | end |
166 | |
167 | def per_page |
168 | { :per_page => [params[:posts_per_page].to_i, 25].max } |
169 | end |
170 | end |