Commit 4c5a5681ccec80e44ce1f0767ea9480eac43877b
1 parent
b361aebc
Exists in
master
and in
29 other branches
Rails 2.3.5 support
* Kept backwards compatibility with Rails 2.1.0, so Debian stable users are still good. * Should also work with newer versions from the 2.3.x series
Showing
4 changed files
with
150 additions
and
149 deletions
Show diff stats
app/controllers/application.rb
1 | -# his is the application's main controller. Features defined here are | |
2 | -# available in all controllers. | |
3 | -class ApplicationController < ActionController::Base | |
4 | - | |
5 | - include ApplicationHelper | |
6 | - layout :get_layout | |
7 | - def get_layout | |
8 | - theme_option(:layout) || 'application' | |
9 | - end | |
10 | - | |
11 | - filter_parameter_logging :password | |
12 | - | |
13 | - def log_processing | |
14 | - super | |
15 | - return unless ENV['RAILS_ENV'] == 'production' | |
16 | - if logger && logger.info? | |
17 | - logger.info(" HTTP Referer: #{request.referer}") | |
18 | - logger.info(" User Agent: #{request.user_agent}") | |
19 | - logger.info(" Accept-Language: #{request.headers['HTTP_ACCEPT_LANGUAGE']}") | |
20 | - end | |
21 | - end | |
22 | - | |
23 | - helper :document | |
24 | - helper :language | |
25 | - | |
26 | - def boxes_editor? | |
27 | - false | |
28 | - end | |
29 | - protected :boxes_editor? | |
30 | - | |
31 | - def self.no_design_blocks | |
32 | - @no_design_blocks = true | |
33 | - end | |
34 | - def self.uses_design_blocks? | |
35 | - !@no_design_blocks | |
36 | - end | |
37 | - def uses_design_blocks? | |
38 | - !@no_design_blocks && self.class.uses_design_blocks? | |
39 | - end | |
40 | - | |
41 | - # Be sure to include AuthenticationSystem in Application Controller instead | |
42 | - include AuthenticatedSystem | |
43 | - include PermissionCheck | |
44 | - | |
45 | - def self.require_ssl(*options) | |
46 | - before_filter :check_ssl, *options | |
47 | - end | |
48 | - def check_ssl | |
49 | - return true if (request.ssl? || ENV['RAILS_ENV'] == 'development') | |
50 | - redirect_to_ssl | |
51 | - end | |
52 | - def redirect_to_ssl | |
53 | - if environment.enable_ssl | |
54 | - redirect_to(params.merge(:protocol => 'https://', :host => ssl_hostname)) | |
55 | - true | |
56 | - else | |
57 | - false | |
58 | - end | |
59 | - end | |
60 | - | |
61 | - def self.refuse_ssl(*options) | |
62 | - before_filter :avoid_ssl, *options | |
63 | - end | |
64 | - def avoid_ssl | |
65 | - if (!request.ssl? || ENV['RAILS_ENV'] == 'development') | |
66 | - true | |
67 | - else | |
68 | - redirect_to(params.merge(:protocol => 'http://')) | |
69 | - false | |
70 | - end | |
71 | - end | |
72 | - | |
73 | - before_filter :set_locale | |
74 | - def set_locale | |
75 | - FastGettext.available_locales = Noosfero.available_locales | |
76 | - FastGettext.default_locale = Noosfero.default_locale | |
77 | - FastGettext.set_locale(params[:lang] || session[:lang] || Noosfero.default_locale || request.env['HTTP_ACCEPT_LANGUAGE'] || 'en') | |
78 | - if params[:lang] | |
79 | - session[:lang] = params[:lang] | |
80 | - end | |
81 | - end | |
82 | - | |
83 | - include NeedsProfile | |
84 | - | |
85 | - before_filter :detect_stuff_by_domain | |
86 | - attr_reader :environment | |
87 | - | |
88 | - before_filter :load_terminology | |
89 | - | |
90 | - # declares that the given <tt>actions</tt> cannot be accessed by other HTTP | |
91 | - # method besides POST. | |
92 | - def self.post_only(actions, redirect = { :action => 'index'}) | |
93 | - verify :method => :post, :only => actions, :redirect_to => redirect | |
94 | - end | |
95 | - | |
96 | - protected | |
97 | - | |
98 | - # TODO: move this logic somewhere else (Domain class?) | |
99 | - def detect_stuff_by_domain | |
100 | - @domain = Domain.find_by_name(request.host) | |
101 | - if @domain.nil? | |
102 | - @environment = Environment.default | |
103 | - else | |
104 | - @environment = @domain.environment | |
105 | - @profile = @domain.profile | |
106 | - end | |
107 | - end | |
108 | - | |
109 | - def load_terminology | |
110 | - # cache terminology for performance | |
111 | - @@terminology_cache ||= {} | |
112 | - @@terminology_cache[environment.id] ||= environment.terminology | |
113 | - Noosfero.terminology = @@terminology_cache[environment.id] | |
114 | - end | |
115 | - | |
116 | - def render_not_found(path = nil) | |
117 | - @no_design_blocks = true | |
118 | - @path ||= request.path | |
119 | - render :template => 'shared/not_found.rhtml', :status => 404 | |
120 | - end | |
121 | - | |
122 | - def render_access_denied(message = nil, title = nil) | |
123 | - @no_design_blocks = true | |
124 | - @message = message | |
125 | - @title = title | |
126 | - render :template => 'shared/access_denied.rhtml', :status => 403 | |
127 | - end | |
128 | - | |
129 | - def user | |
130 | - current_user.person if logged_in? | |
131 | - end | |
132 | - | |
133 | - def load_category | |
134 | - unless params[:category_path].blank? | |
135 | - path = params[:category_path].join('/') | |
136 | - @category = environment.categories.find_by_path(path) | |
137 | - if @category.nil? | |
138 | - render_not_found(path) | |
139 | - end | |
140 | - end | |
141 | - end | |
142 | - | |
143 | -end | |
1 | +require 'application_controller' | ... | ... |
... | ... | @@ -0,0 +1,143 @@ |
1 | +# his is the application's main controller. Features defined here are | |
2 | +# available in all controllers. | |
3 | +class ApplicationController < ActionController::Base | |
4 | + | |
5 | + include ApplicationHelper | |
6 | + layout :get_layout | |
7 | + def get_layout | |
8 | + theme_option(:layout) || 'application' | |
9 | + end | |
10 | + | |
11 | + filter_parameter_logging :password | |
12 | + | |
13 | + def log_processing | |
14 | + super | |
15 | + return unless ENV['RAILS_ENV'] == 'production' | |
16 | + if logger && logger.info? | |
17 | + logger.info(" HTTP Referer: #{request.referer}") | |
18 | + logger.info(" User Agent: #{request.user_agent}") | |
19 | + logger.info(" Accept-Language: #{request.headers['HTTP_ACCEPT_LANGUAGE']}") | |
20 | + end | |
21 | + end | |
22 | + | |
23 | + helper :document | |
24 | + helper :language | |
25 | + | |
26 | + def boxes_editor? | |
27 | + false | |
28 | + end | |
29 | + protected :boxes_editor? | |
30 | + | |
31 | + def self.no_design_blocks | |
32 | + @no_design_blocks = true | |
33 | + end | |
34 | + def self.uses_design_blocks? | |
35 | + !@no_design_blocks | |
36 | + end | |
37 | + def uses_design_blocks? | |
38 | + !@no_design_blocks && self.class.uses_design_blocks? | |
39 | + end | |
40 | + | |
41 | + # Be sure to include AuthenticationSystem in Application Controller instead | |
42 | + include AuthenticatedSystem | |
43 | + include PermissionCheck | |
44 | + | |
45 | + def self.require_ssl(*options) | |
46 | + before_filter :check_ssl, *options | |
47 | + end | |
48 | + def check_ssl | |
49 | + return true if (request.ssl? || ENV['RAILS_ENV'] == 'development') | |
50 | + redirect_to_ssl | |
51 | + end | |
52 | + def redirect_to_ssl | |
53 | + if environment.enable_ssl | |
54 | + redirect_to(params.merge(:protocol => 'https://', :host => ssl_hostname)) | |
55 | + true | |
56 | + else | |
57 | + false | |
58 | + end | |
59 | + end | |
60 | + | |
61 | + def self.refuse_ssl(*options) | |
62 | + before_filter :avoid_ssl, *options | |
63 | + end | |
64 | + def avoid_ssl | |
65 | + if (!request.ssl? || ENV['RAILS_ENV'] == 'development') | |
66 | + true | |
67 | + else | |
68 | + redirect_to(params.merge(:protocol => 'http://')) | |
69 | + false | |
70 | + end | |
71 | + end | |
72 | + | |
73 | + before_filter :set_locale | |
74 | + def set_locale | |
75 | + FastGettext.available_locales = Noosfero.available_locales | |
76 | + FastGettext.default_locale = Noosfero.default_locale | |
77 | + FastGettext.set_locale(params[:lang] || session[:lang] || Noosfero.default_locale || request.env['HTTP_ACCEPT_LANGUAGE'] || 'en') | |
78 | + if params[:lang] | |
79 | + session[:lang] = params[:lang] | |
80 | + end | |
81 | + end | |
82 | + | |
83 | + include NeedsProfile | |
84 | + | |
85 | + before_filter :detect_stuff_by_domain | |
86 | + attr_reader :environment | |
87 | + | |
88 | + before_filter :load_terminology | |
89 | + | |
90 | + # declares that the given <tt>actions</tt> cannot be accessed by other HTTP | |
91 | + # method besides POST. | |
92 | + def self.post_only(actions, redirect = { :action => 'index'}) | |
93 | + verify :method => :post, :only => actions, :redirect_to => redirect | |
94 | + end | |
95 | + | |
96 | + protected | |
97 | + | |
98 | + # TODO: move this logic somewhere else (Domain class?) | |
99 | + def detect_stuff_by_domain | |
100 | + @domain = Domain.find_by_name(request.host) | |
101 | + if @domain.nil? | |
102 | + @environment = Environment.default | |
103 | + else | |
104 | + @environment = @domain.environment | |
105 | + @profile = @domain.profile | |
106 | + end | |
107 | + end | |
108 | + | |
109 | + def load_terminology | |
110 | + # cache terminology for performance | |
111 | + @@terminology_cache ||= {} | |
112 | + @@terminology_cache[environment.id] ||= environment.terminology | |
113 | + Noosfero.terminology = @@terminology_cache[environment.id] | |
114 | + end | |
115 | + | |
116 | + def render_not_found(path = nil) | |
117 | + @no_design_blocks = true | |
118 | + @path ||= request.path | |
119 | + render :template => 'shared/not_found.rhtml', :status => 404 | |
120 | + end | |
121 | + | |
122 | + def render_access_denied(message = nil, title = nil) | |
123 | + @no_design_blocks = true | |
124 | + @message = message | |
125 | + @title = title | |
126 | + render :template => 'shared/access_denied.rhtml', :status => 403 | |
127 | + end | |
128 | + | |
129 | + def user | |
130 | + current_user.person if logged_in? | |
131 | + end | |
132 | + | |
133 | + def load_category | |
134 | + unless params[:category_path].blank? | |
135 | + path = params[:category_path].join('/') | |
136 | + @category = environment.categories.find_by_path(path) | |
137 | + if @category.nil? | |
138 | + render_not_found(path) | |
139 | + end | |
140 | + end | |
141 | + end | |
142 | + | |
143 | +end | ... | ... |
config/environment.rb
... | ... | @@ -85,7 +85,7 @@ Rails::Initializer.run do |config| |
85 | 85 | end |
86 | 86 | end |
87 | 87 | extra_controller_dirs.each do |item| |
88 | - Dependencies.load_paths << item | |
88 | + (ActiveSupport.const_defined?('Dependencies') ? ActiveSupport::Dependencies : ::Dependencies).load_paths << item | |
89 | 89 | end |
90 | 90 | |
91 | 91 | # Add new inflection rules using the following format | ... | ... |
lib/noosfero/i18n.rb
... | ... | @@ -153,8 +153,8 @@ module ActionController::Caching::Fragments |
153 | 153 | alias_method_chain :expire_fragment, :fast_gettext |
154 | 154 | end |
155 | 155 | |
156 | -FileUtils.mkdir_p(Rails.root + '/locale') | |
157 | -Dir.glob(Rails.root + '/locale/*').each do |dir| | |
156 | +FileUtils.mkdir_p(File.join(Rails.root, 'locale')) | |
157 | +Dir.glob(File.join(Rails.root, 'locale/*')).each do |dir| | |
158 | 158 | lang = File.basename(dir) |
159 | 159 | FileUtils.mkdir_p("#{Rails.root}/locale/#{lang}/LC_MESSAGES") |
160 | 160 | ['iso_3166', 'rails'].each do |domain| |
... | ... | @@ -174,9 +174,9 @@ Dir.glob(Rails.root + '/locale/*').each do |dir| |
174 | 174 | end |
175 | 175 | |
176 | 176 | repos = [ |
177 | - FastGettext::TranslationRepository.build('noosfero', :type => 'mo', :path => Rails.root + '/locale'), | |
178 | - FastGettext::TranslationRepository.build('iso_3166', :type => 'mo', :path => Rails.root + '/locale'), | |
179 | - FastGettext::TranslationRepository.build('rails', :type => 'mo', :path => Rails.root + '/locale'), | |
177 | + FastGettext::TranslationRepository.build('noosfero', :type => 'mo', :path => File.join(Rails.root, 'locale')), | |
178 | + FastGettext::TranslationRepository.build('iso_3166', :type => 'mo', :path => File.join(Rails.root, 'locale')), | |
179 | + FastGettext::TranslationRepository.build('rails', :type => 'mo', :path => File.join(Rails.root, 'locale')), | |
180 | 180 | ] |
181 | 181 | |
182 | 182 | FastGettext.add_text_domain 'noosferofull', :type => :chain, :chain => repos | ... | ... |