Class: ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Includes:
AuthLib, ControllerExtensions, LoginSystem, SslRequirement
Defined in:
app/controllers/application_controller.rb

Overview

Filters added to this controller apply to all controllers in the application. Likewise, all the methods added will be available for all controllers.

Direct Known Subclasses

Admin::LogosController, Admin::SponsorsController, AdminController, Api::DataController, AuthController, DebugController, FeedsController, LogoController, MainController, NoticeController, OpieController, PageinfoController, PagesController, People::AccountController, People::AdminController, People::ColleaguesController, People::CommunitiesController, People::FeedsController, People::HelpController, People::InvitationsController, People::ListsController, People::NumbersController, People::ProfileController, People::SignupController, People::WelcomeController, PreviewController, ReportsController, SearchController, StatusController, Widgets::ContentController, Widgets::HomeController

Instance Method Summary (collapse)

Methods included from ControllerExtensions

#check_openidurl_foruser, #log_user_activity, #validate_datepicker

Methods included from AuthLib

#current_person, #set_current_person

Instance Method Details

- (Object) content_date_sort(articles, faqs, limit)



65
66
67
68
69
70
71
72
73
# File 'app/controllers/application_controller.rb', line 65

def (articles, faqs, limit)
	merged = Hash.new
	retarray = Array.new
	articles.each{ |article| merged[article.source_updated_at] = article }
	faqs.each{ |faq| merged[faq.source_updated_at] = faq }
	tstamps = merged.keys.sort.reverse # sort by updated, descending
	tstamps.each{ |key| retarray << merged[key] }
	return retarray.slice(0,limit)
end

- (Object) do_404



133
134
135
136
137
138
# File 'app/controllers/application_controller.rb', line 133

def do_404
  
  personalize_location_and_institution if not @personal
  @page_title_text = 'Status 404 - Page Not Found'
  render(:template => "/shared/404", :layout => 'pubsite', :status  => "404")
end

- (Object) do_410



140
141
142
143
144
# File 'app/controllers/application_controller.rb', line 140

def do_410
  personalize_location_and_institution if not @personal
  @page_title_text = 'Status 410 - Page Removed'
  render :template => "/shared/410", :status => "410"
end

- (Object) do_invalid_page



146
147
148
# File 'app/controllers/application_controller.rb', line 146

def do_invalid_page
  render :text => 'Invalid page requested', :status => 400
end

- (Object) get_county_options(provided_location = nil)



80
81
82
83
84
85
86
87
88
# File 'app/controllers/application_controller.rb', line 80

def get_county_options(provided_location = nil)
  if params[:location_id] and params[:location_id].strip != '' and location = Location.find(params[:location_id])
    counties = location.counties.find(:all, :order => 'name', :conditions => "countycode <> '0'")
    return ([['', '']].concat(counties.map{|c| [c.name, c.id]}))
  elsif(provided_location)
    counties = provided_location.counties.find(:all, :order => 'name', :conditions => "countycode <> '0'")
    return ([['', '']].concat(counties.map{|c| [c.name, c.id]}))
  end
end

- (Object) get_location_options



75
76
77
78
# File 'app/controllers/application_controller.rb', line 75

def get_location_options
  locations = Location.find(:all, :order => 'entrytype, name')
  return [['', '']].concat(locations.map{|l| [l.name, l.id]})
end

- (Object) mobile_detection



51
52
53
54
55
# File 'app/controllers/application_controller.rb', line 51

def mobile_detection
  if is_mobile_device?
    @mobile_device = true
  end
end

- (Object) set_analytics_visitor



102
103
104
105
106
107
108
109
110
111
112
# File 'app/controllers/application_controller.rb', line 102

def set_analytics_visitor
  if(session[:account_id])
    if( = Account.find_by_id(session[:account_id]))
      @analytics_vistor = (.class == User) ? 'internal' : 'external'
    else
      @analytics_vistor = 'anonymous'
    end
  else
    @analytics_vistor = 'anonymous'
  end
end

- (Object) set_app_location



47
48
49
# File 'app/controllers/application_controller.rb', line 47

def set_app_location
  @app_location_for_display = AppConfig.configtable['app_location']
end

- (Object) set_default_request_ip_address



90
91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/application_controller.rb', line 90

def set_default_request_ip_address
  # if(!request.env["HTTP_X_FORWARDED_FOR"].nil?)
  #   AppConfig.configtable['request_ip_address'] = request.env["HTTP_X_FORWARDED_FOR"]
  # elsif(!request.env["REMOTE_ADDR"].nil?)
  if(!request.env["REMOTE_ADDR"].nil?)
    AppConfig.configtable['request_ip_address'] = request.env["REMOTE_ADDR"]
  else
    AppConfig.configtable['request_ip_address'] = AppConfig.configtable['default_request_ip']
  end
  return true
end

- (Object) set_locale



114
115
116
117
118
119
120
# File 'app/controllers/application_controller.rb', line 114

def set_locale
  # update session if passed
  session[:locale] = params[:locale] if params[:locale]

  # set locale based on session or default 
  I18n.locale = session[:locale] || I18n.default_locale
end

- (Object) set_request_url_options



57
58
59
60
61
62
63
# File 'app/controllers/application_controller.rb', line 57

def set_request_url_options
  if(!request.nil?)
    AppConfig.configtable['url_options']['host'] = request.host unless (request.host.nil?)
    AppConfig.configtable['url_options']['protocol'] = request.protocol unless (request.protocol.nil?)
    AppConfig.configtable['url_options']['port'] = request.port unless (request.port.nil?)
  end
end

- (Object) unescape_params

Account for the double encoding occuring at the webserver level by decoding known trouble params again.



124
125
126
127
128
129
130
131
# File 'app/controllers/application_controller.rb', line 124

def unescape_params
  [:content_tag, :order].each do |param|
    params[param] = CGI.unescape(params[param]) if params[param]      
  end
  if params[:categories] and params[:categories].class == Array
    params[:categories].collect! { |c| CGI.unescape(c) }
  end
end