Commit b76a4336f7e285f295fd9466a67e98c541ca76ad
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'rails3_community_dashboard' into rails3_stable
Conflicts: app/controllers/public/content_viewer_controller.rb
Showing
1 changed file
with
78 additions
and
142 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
| @@ -8,32 +8,49 @@ class ContentViewerController < ApplicationController | @@ -8,32 +8,49 @@ class ContentViewerController < ApplicationController | ||
| 8 | helper TagsHelper | 8 | helper TagsHelper |
| 9 | 9 | ||
| 10 | def view_page | 10 | def view_page |
| 11 | - path = get_path(params[:page], params[:format]) | ||
| 12 | - | 11 | + path = params[:page] |
| 12 | + path = path.join('/') if path.kind_of?(Array) | ||
| 13 | + path = "#{path}.#{params[:format]}" if params[:format] | ||
| 13 | @version = params[:version].to_i | 14 | @version = params[:version].to_i |
| 14 | 15 | ||
| 15 | if path.blank? | 16 | if path.blank? |
| 16 | - @page = profile.home_page | ||
| 17 | - return if redirected_to_profile_index | 17 | + @page = profile.home_page |
| 18 | + if @page.nil? | ||
| 19 | + redirect_to :controller => 'profile', :action => 'index', :profile => profile.identifier | ||
| 20 | + return | ||
| 21 | + end | ||
| 18 | else | 22 | else |
| 19 | @page = profile.articles.find_by_path(path) | 23 | @page = profile.articles.find_by_path(path) |
| 20 | - return if redirected_page_from_old_path(path) | 24 | + unless @page |
| 25 | + page_from_old_path = profile.articles.find_by_old_path(path) | ||
| 26 | + if page_from_old_path | ||
| 27 | + redirect_to profile.url.merge(:page => page_from_old_path.explode_path) | ||
| 28 | + return | ||
| 29 | + end | ||
| 30 | + end | ||
| 21 | end | 31 | end |
| 22 | 32 | ||
| 23 | return unless allow_access_to_page(path) | 33 | return unless allow_access_to_page(path) |
| 24 | 34 | ||
| 25 | if @version > 0 | 35 | if @version > 0 |
| 26 | return render_access_denied unless @page.display_versions? | 36 | return render_access_denied unless @page.display_versions? |
| 27 | - return if rendered_versioned_article | 37 | + @versioned_article = @page.versions.find_by_version(@version) |
| 38 | + if @versioned_article && @page.versions.latest.version != @versioned_article.version | ||
| 39 | + render :template => 'content_viewer/versioned_article.html.erb' | ||
| 40 | + return | ||
| 41 | + end | ||
| 28 | end | 42 | end |
| 29 | 43 | ||
| 30 | redirect_to_translation and return if @page.profile.redirect_l10n | 44 | redirect_to_translation and return if @page.profile.redirect_l10n |
| 31 | 45 | ||
| 32 | - if request.post? && @page.forum? | ||
| 33 | - process_forum_terms_of_use(user, params[:terms_accepted]) | ||
| 34 | - elsif is_a_forum_topic?(@page) && !@page.parent.agrees_with_terms?(user) | ||
| 35 | - redirect_to @page.parent.url | ||
| 36 | - return | 46 | + if request.post? |
| 47 | + if @page.forum? && @page.has_terms_of_use && params[:terms_accepted] == "true" | ||
| 48 | + @page.add_agreed_user(user) | ||
| 49 | + end | ||
| 50 | + elsif !@page.parent.nil? && @page.parent.forum? | ||
| 51 | + unless @page.parent.agrees_with_terms?(user) | ||
| 52 | + redirect_to @page.parent.url | ||
| 53 | + end | ||
| 37 | end | 54 | end |
| 38 | 55 | ||
| 39 | # At this point the page will be showed | 56 | # At this point the page will be showed |
| @@ -41,22 +58,64 @@ class ContentViewerController < ApplicationController | @@ -41,22 +58,64 @@ class ContentViewerController < ApplicationController | ||
| 41 | 58 | ||
| 42 | @page = FilePresenter.for @page | 59 | @page = FilePresenter.for @page |
| 43 | 60 | ||
| 44 | - return if rendered_file_download(params[:view]) | 61 | + if @page.download? params[:view] |
| 62 | + headers['Content-Type'] = @page.mime_type | ||
| 63 | + headers.merge! @page.download_headers | ||
| 64 | + data = @page.data | ||
| 65 | + | ||
| 66 | + # TODO test the condition | ||
| 67 | + if data.nil? | ||
| 68 | + raise "No data for file" | ||
| 69 | + end | ||
| 70 | + | ||
| 71 | + render :text => data, :layout => false | ||
| 72 | + return | ||
| 73 | + end | ||
| 45 | 74 | ||
| 46 | @form_div = params[:form] | 75 | @form_div = params[:form] |
| 47 | 76 | ||
| 48 | #FIXME see a better way to do this. It's not need to pass this variable anymore | 77 | #FIXME see a better way to do this. It's not need to pass this variable anymore |
| 49 | @comment = Comment.new | 78 | @comment = Comment.new |
| 50 | 79 | ||
| 51 | - process_page_posts(params) | 80 | + if @page.has_posts? |
| 81 | + posts = if params[:year] and params[:month] | ||
| 82 | + filter_date = DateTime.parse("#{params[:year]}-#{params[:month]}-01") | ||
| 83 | + @page.posts.by_range(filter_date..filter_date.at_end_of_month) | ||
| 84 | + else | ||
| 85 | + @page.posts | ||
| 86 | + end | ||
| 87 | + | ||
| 88 | + #FIXME Need to run this before the pagination because this version of | ||
| 89 | + # will_paginate returns a will_paginate collection instead of a | ||
| 90 | + # relation. | ||
| 91 | + blog_with_translation = @page.blog? && @page.display_posts_in_current_language? | ||
| 92 | + posts = posts.native_translations if blog_with_translation | ||
| 93 | + | ||
| 94 | + @posts = posts.paginate({ :page => params[:npage], :per_page => @page.posts_per_page }.merge(Article.display_filter(user, profile))).to_a | ||
| 95 | + | ||
| 96 | + if blog_with_translation | ||
| 97 | + @posts.replace @posts.map{ |p| p.get_translation_to(FastGettext.locale) }.compact | ||
| 98 | + end | ||
| 99 | + end | ||
| 52 | 100 | ||
| 53 | if @page.folder? && @page.gallery? | 101 | if @page.folder? && @page.gallery? |
| 54 | - @images = get_images(@page, params[:npage], params[:slideshow]) | 102 | + @images = @page.images.select{ |a| a.display_to? user } |
| 103 | + @images = @images.paginate(:per_page => per_page, :page => params[:npage]) unless params[:slideshow] | ||
| 55 | end | 104 | end |
| 56 | 105 | ||
| 57 | - process_page_followers(params) | 106 | + @unfollow_form = params[:unfollow] && params[:unfollow] == 'true' |
| 107 | + if params[:unfollow] && params[:unfollow] == 'commit' && request.post? | ||
| 108 | + @page.followers -= [params[:email]] | ||
| 109 | + if @page.save | ||
| 110 | + session[:notice] = _("Notification of new comments to '%s' was successfully canceled") % params[:email] | ||
| 111 | + end | ||
| 112 | + end | ||
| 58 | 113 | ||
| 59 | - process_comments(params) | 114 | + @comments = @page.comments.without_spam |
| 115 | + @comments = @plugins.filter(:unavailable_comments, @comments) | ||
| 116 | + @comments_count = @comments.count | ||
| 117 | + @comments = @comments.without_reply.paginate(:per_page => per_page, :page => params[:comment_page] ) | ||
| 118 | + @comment_order = params[:comment_order].nil? ? 'oldest' : params[:comment_order] | ||
| 60 | 119 | ||
| 61 | if request.xhr? and params[:comment_order] | 120 | if request.xhr? and params[:comment_order] |
| 62 | if @comment_order == 'newest' | 121 | if @comment_order == 'newest' |
| @@ -68,13 +127,13 @@ class ContentViewerController < ApplicationController | @@ -68,13 +127,13 @@ class ContentViewerController < ApplicationController | ||
| 68 | 127 | ||
| 69 | if params[:slideshow] | 128 | if params[:slideshow] |
| 70 | render :action => 'slideshow', :layout => 'slideshow' | 129 | render :action => 'slideshow', :layout => 'slideshow' |
| 71 | - else | ||
| 72 | - render :file => @page.view_page, :layout => true, :formats => [:html] | 130 | + return |
| 73 | end | 131 | end |
| 132 | + render @page.view_page, :formats => [:html] | ||
| 74 | end | 133 | end |
| 75 | 134 | ||
| 76 | def versions_diff | 135 | def versions_diff |
| 77 | - path = params[:page] | 136 | + path = params[:page].join('/') |
| 78 | @page = profile.articles.find_by_path(path) | 137 | @page = profile.articles.find_by_path(path) |
| 79 | @v1, @v2 = @page.versions.find_by_version(params[:v1]), @page.versions.find_by_version(params[:v2]) | 138 | @v1, @v2 = @page.versions.find_by_version(params[:v1]), @page.versions.find_by_version(params[:v2]) |
| 80 | end | 139 | end |
| @@ -144,127 +203,4 @@ class ContentViewerController < ApplicationController | @@ -144,127 +203,4 @@ class ContentViewerController < ApplicationController | ||
| 144 | user_agent.match(/crawler/) || | 203 | user_agent.match(/crawler/) || |
| 145 | user_agent.match(/\(.*https?:\/\/.*\)/) | 204 | user_agent.match(/\(.*https?:\/\/.*\)/) |
| 146 | end | 205 | end |
| 147 | - | ||
| 148 | - def get_path(page, format = nil) | ||
| 149 | - path = page | ||
| 150 | - path = path.join('/') if path.kind_of?(Array) | ||
| 151 | - path = "#{path}.#{format}" if format | ||
| 152 | - | ||
| 153 | - return path | ||
| 154 | - end | ||
| 155 | - | ||
| 156 | - def redirected_to_profile_index | ||
| 157 | - if @page.nil? | ||
| 158 | - redirect_to :controller => 'profile', :action => 'index', :profile => profile.identifier | ||
| 159 | - return true | ||
| 160 | - end | ||
| 161 | - | ||
| 162 | - return false | ||
| 163 | - end | ||
| 164 | - | ||
| 165 | - def redirected_page_from_old_path(path) | ||
| 166 | - unless @page | ||
| 167 | - page_from_old_path = profile.articles.find_by_old_path(path) | ||
| 168 | - if page_from_old_path | ||
| 169 | - redirect_to profile.url.merge(:page => page_from_old_path.explode_path) | ||
| 170 | - return true | ||
| 171 | - end | ||
| 172 | - end | ||
| 173 | - | ||
| 174 | - return false | ||
| 175 | - end | ||
| 176 | - | ||
| 177 | - def process_forum_terms_of_use(user, terms_accepted = nil) | ||
| 178 | - if @page.forum? && @page.has_terms_of_use && terms_accepted == "true" | ||
| 179 | - @page.add_agreed_user(user) | ||
| 180 | - end | ||
| 181 | - end | ||
| 182 | - | ||
| 183 | - def is_a_forum_topic? (page) | ||
| 184 | - return (!@page.parent.nil? && @page.parent.forum?) | ||
| 185 | - end | ||
| 186 | - | ||
| 187 | - def rendered_versioned_article | ||
| 188 | - @versioned_article = @page.versions.find_by_version(@version) | ||
| 189 | - if @versioned_article && @page.versions.latest.version != @versioned_article.version | ||
| 190 | - render :template => 'content_viewer/versioned_article.html.erb' | ||
| 191 | - return true | ||
| 192 | - end | ||
| 193 | - | ||
| 194 | - return false | ||
| 195 | - end | ||
| 196 | - | ||
| 197 | - def rendered_file_download(view = nil) | ||
| 198 | - if @page.download? view | ||
| 199 | - headers['Content-Type'] = @page.mime_type | ||
| 200 | - headers.merge! @page.download_headers | ||
| 201 | - data = @page.data | ||
| 202 | - | ||
| 203 | - # TODO test the condition | ||
| 204 | - if data.nil? | ||
| 205 | - raise "No data for file" | ||
| 206 | - end | ||
| 207 | - | ||
| 208 | - render :text => data, :layout => false | ||
| 209 | - return true | ||
| 210 | - end | ||
| 211 | - | ||
| 212 | - return false | ||
| 213 | - end | ||
| 214 | - | ||
| 215 | - def process_page_posts(params) | ||
| 216 | - if @page.has_posts? | ||
| 217 | - posts = get_posts(params[:year], params[:month]) | ||
| 218 | - | ||
| 219 | - #FIXME Need to run this before the pagination because this version of | ||
| 220 | - # will_paginate returns a will_paginate collection instead of a | ||
| 221 | - # relation. | ||
| 222 | - posts = posts.native_translations if blog_with_translation?(@page) | ||
| 223 | - | ||
| 224 | - @posts = posts.paginate({ :page => params[:npage], :per_page => @page.posts_per_page }.merge(Article.display_filter(user, profile))).to_a | ||
| 225 | - | ||
| 226 | - if blog_with_translation?(@page) | ||
| 227 | - @posts.replace @posts.map{ |p| p.get_translation_to(FastGettext.locale) }.compact | ||
| 228 | - end | ||
| 229 | - end | ||
| 230 | - end | ||
| 231 | - | ||
| 232 | - def get_posts(year = nil, month = nil) | ||
| 233 | - if year && month | ||
| 234 | - filter_date = DateTime.parse("#{year}-#{month}-01") | ||
| 235 | - return @page.posts.by_range(filter_date..filter_date.at_end_of_month) | ||
| 236 | - else | ||
| 237 | - return @page.posts | ||
| 238 | - end | ||
| 239 | - end | ||
| 240 | - | ||
| 241 | - def blog_with_translation?(page) | ||
| 242 | - return (page.blog? && page.display_posts_in_current_language?) | ||
| 243 | - end | ||
| 244 | - | ||
| 245 | - def get_images(page, npage, slideshow) | ||
| 246 | - images = page.images.select{ |a| a.display_to? user } | ||
| 247 | - images = images.paginate(:per_page => per_page, :page => npage) unless slideshow | ||
| 248 | - | ||
| 249 | - return images | ||
| 250 | - end | ||
| 251 | - | ||
| 252 | - def process_page_followers(params) | ||
| 253 | - @unfollow_form = params[:unfollow] == 'true' | ||
| 254 | - if params[:unfollow] == 'commit' && request.post? | ||
| 255 | - @page.followers -= [params[:email]] | ||
| 256 | - if @page.save | ||
| 257 | - session[:notice] = _("Notification of new comments to '%s' was successfully canceled") % params[:email] | ||
| 258 | - end | ||
| 259 | - end | ||
| 260 | - end | ||
| 261 | - | ||
| 262 | - def process_comments(params) | ||
| 263 | - @comments = @page.comments.without_spam | ||
| 264 | - @comments = @plugins.filter(:unavailable_comments, @comments) | ||
| 265 | - @comments_count = @comments.count | ||
| 266 | - @comments = @comments.without_reply.paginate(:per_page => per_page, :page => params[:comment_page] ) | ||
| 267 | - @comment_order = params[:comment_order].nil? ? 'oldest' : params[:comment_order] | ||
| 268 | - end | ||
| 269 | - | ||
| 270 | end | 206 | end |