Class ContentViewerController
In: app/controllers/public/content_viewer_controller.rb
Parent: ApplicationController

Methods

Public Instance methods

[Source]

    # File app/controllers/public/content_viewer_controller.rb, line 7
 7:   def view_page
 8:     path = params[:page].join('/')
 9: 
10:     if path.blank?
11:       @page = profile.home_page
12:       if @page.nil?
13:         render :action => 'no_home_page'
14:         return
15:       end
16:     else
17:       @page = profile.articles.find_by_path(path)
18: 
19:       # do not show unpublished articles
20:       if @page && !@page.published
21:         @page = nil
22:       end
23: 
24:       # page not found, give error
25:       if @page.nil?
26:         render_not_found(@path)
27:         return
28:       end
29:     end
30: 
31:     if !@page.public? && !request.ssl?
32:       redirect_to_ssl
33:       return
34:     end
35: 
36:     if !@page.display_to?(user)
37:       # FIXME find a nice "access denied" layout
38:       render :action => 'access_denied', :status => 403, :layout => false
39:     end
40: 
41:     if @page.mime_type != 'text/html'
42:       headers['Content-Type'] = @page.mime_type
43:       data = @page.data
44: 
45:       # TODO test the condition
46:       if data.nil?
47:         raise "No data for file"
48:       end
49: 
50:       render :text => data, :layout => false
51:       return
52:     end
53: 
54:     if request.post? && params[:comment] && params[self.icaptcha_field].blank? && @page.accept_comments?
55:       add_comment
56:     end
57: 
58:     if request.post? && params[:remove_comment]
59:       remove_comment
60:     end
61:     
62:     @comments = @page.comments(true)
63:   end

Protected Instance methods

[Source]

    # File app/controllers/public/content_viewer_controller.rb, line 67
67:   def add_comment
68:     @comment = Comment.new(params[:comment])
69:     @comment.author = user if logged_in?
70:     @comment.article = @page
71:     if @comment.save
72:       @comment = nil # clear the comment form
73:     else
74:       @form_div = 'opened'
75:     end
76:   end

[Source]

    # File app/controllers/public/content_viewer_controller.rb, line 78
78:   def remove_comment
79:     @comment = @page.comments.find(params[:remove_comment])
80:     if (user == @comment.author || user == @page.profile || user.has_permission?(:moderate_comments, @page.profile))
81:       @comment.destroy
82:       flash[:notice] = _('Comment succesfully deleted')
83:     end
84:     redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path
85:   end

[Validate]