forked from mmangino/facebooker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.rb
72 lines (63 loc) · 2.72 KB
/
init.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Added support to the Facebooker.yml file for switching to the new profile design..
# Config parsing needs to happen before files are required.
facebook_config = "#{RAILS_ROOT}/config/facebooker.yml"
require 'facebooker'
FACEBOOKER = Facebooker.load_configuration(facebook_config)
# enable logger before including everything else, in case we ever want to log initialization
Facebooker.logger = RAILS_DEFAULT_LOGGER if Object.const_defined? :RAILS_DEFAULT_LOGGER
require 'net/http_multipart_post'
require 'facebooker/rails/controller'
require 'facebooker/rails/facebook_url_rewriting'
require 'facebooker/rails/facebook_session_handling'
require 'facebooker/rails/facebook_request_fix'
require 'facebooker/rails/routing'
require 'facebooker/rails/facebook_pretty_errors' rescue nil
require 'facebooker/rails/facebook_url_helper'
module ::ActionController
class Base
def self.inherited_with_facebooker(subclass)
inherited_without_facebooker(subclass)
if subclass.to_s == "ApplicationController"
subclass.send(:include,Facebooker::Rails::Controller)
subclass.helper Facebooker::Rails::Helpers
end
end
class << self
alias_method_chain :inherited, :facebooker
end
end
end
class ActionController::Routing::Route
def recognition_conditions_with_facebooker
defaults = recognition_conditions_without_facebooker
defaults << " env[:canvas] == conditions[:canvas] " if conditions[:canvas]
defaults
end
alias_method_chain :recognition_conditions, :facebooker
end
# When making get requests, Facebook sends fb_sig parameters both in the query string
# and also in the post body. We want to ignore the query string ones because they are one
# request out of date
# We only do thise when there are POST parameters so that IFrame linkage still works
class ActionController::AbstractRequest
def query_parameters_with_facebooker
if request_parameters.blank?
query_parameters_without_facebooker
else
(query_parameters_without_facebooker||{}).reject {|key,value| key.to_s =~ /^fb_sig/}
end
end
alias_method_chain :query_parameters, :facebooker
end
# We turn off route optimization to make named routes use our code for figuring out if they should go to the session
# If this fails, it means we're on rails 1.2, we can ignore it
begin
ActionController::Base::optimise_named_routes = false
rescue NoMethodError=>e
nil
end
# pull :canvas=> into env in routing to allow for conditions
ActionController::Routing::RouteSet.send :include, Facebooker::Rails::Routing::RouteSetExtensions
ActionController::Routing::RouteSet::Mapper.send :include, Facebooker::Rails::Routing::MapperExtensions
Mime::Type.register_alias "text/html", :fbml
Mime::Type.register_alias "text/javascript", :fbjs