rfacebook 0.8.6 → 0.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/facepricot.rb
CHANGED
@@ -110,7 +110,8 @@ module RFacebook
|
|
110
110
|
include FacepricotChaining
|
111
111
|
|
112
112
|
def initialize(hpricotDoc)
|
113
|
-
|
113
|
+
# TODO: does this fix the Hpricot HTML entity escaping problem?
|
114
|
+
super(hpricotDoc.inner_html.gsub("&", "&"))
|
114
115
|
@doc = hpricotDoc
|
115
116
|
end
|
116
117
|
|
@@ -93,8 +93,8 @@ module RFacebook
|
|
93
93
|
|
94
94
|
def fbsession
|
95
95
|
|
96
|
-
# if we are in the canvas or
|
97
|
-
if (!rfacebook_session_holder.is_valid? and (in_facebook_canvas? or in_facebook_frame?))
|
96
|
+
# if we are in the canvas, iframe, or mock ajax, we should be able to activate the session here
|
97
|
+
if (!rfacebook_session_holder.is_valid? and (in_facebook_canvas? or in_facebook_frame? or in_mock_ajax?))
|
98
98
|
|
99
99
|
# then try to activate it somehow (or retrieve from previous state)
|
100
100
|
# these might be nil
|
@@ -139,6 +139,10 @@ module RFacebook
|
|
139
139
|
return (params["fb_sig_in_iframe"] != nil or params["fb_sig_in_canvas"] != nil)
|
140
140
|
end
|
141
141
|
|
142
|
+
def in_mock_ajax?
|
143
|
+
return (params["fb_mockajax_url"] != nil)
|
144
|
+
end
|
145
|
+
|
142
146
|
def in_external_app?
|
143
147
|
return (!params[:fb_sig] and !in_facebook_frame?)
|
144
148
|
end
|
@@ -168,6 +172,7 @@ module RFacebook
|
|
168
172
|
# grab saved Facebook session from Rails session
|
169
173
|
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: grabbing Facebook session from Rails session"
|
170
174
|
@rfacebook_session_holder = session[:rfacebook_session]
|
175
|
+
@rfacebook_session_holder.logger = RAILS_DEFAULT_LOGGER
|
171
176
|
|
172
177
|
end
|
173
178
|
|
@@ -175,6 +180,8 @@ module RFacebook
|
|
175
180
|
if !rfacebook_session_holder.is_valid?
|
176
181
|
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK WARNING: Facebook session could not be activated (from handle_facebook_login)"
|
177
182
|
elsif params["auth_token"]
|
183
|
+
# TODO: ignoring is proper when we have already used the auth_token (we could try to reauth and swallow the exception)
|
184
|
+
# however, we probably want to re-auth if the new auth_token is valid (new user, old user probably logged out)
|
178
185
|
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: received a new auth_token, but we already have a valid session (ignored new auth_token)"
|
179
186
|
end
|
180
187
|
|
@@ -245,7 +252,7 @@ module RFacebook
|
|
245
252
|
end
|
246
253
|
|
247
254
|
def facebook_debug_panel(options={})
|
248
|
-
return ERB.new(RFacebook::Rails::DEBUG_PANEL_ERB_TEMPLATE).result(Proc.new{})
|
255
|
+
return ERB.new(RFacebook::Rails::DEBUG_PANEL_ERB_TEMPLATE).result(Proc.new{}) # TODO: should use File.dirname(__FILE__) + 'templates/debug_panel.rhtml' instead
|
249
256
|
end
|
250
257
|
|
251
258
|
def facebook_status_manager
|
@@ -312,20 +319,38 @@ module RFacebook
|
|
312
319
|
alias_method(:url_for__ALIASED, :url_for)
|
313
320
|
|
314
321
|
def url_for(options={}, *parameters)
|
322
|
+
|
323
|
+
# error check
|
315
324
|
if !options
|
316
325
|
RAILS_DEFAULT_LOGGER.info "** RFACEBOOK WARNING: options cannot be nil in call to url_for"
|
317
326
|
end
|
318
|
-
|
327
|
+
|
328
|
+
# use special URL rewriting when inside the canvas
|
329
|
+
# setting the mock_ajax option to true will override this
|
330
|
+
# and force usage of regular Rails rewriting
|
331
|
+
if (in_facebook_canvas? and !options[:mock_ajax]) #TODO: or in_facebook_frame?
|
332
|
+
|
319
333
|
if options.is_a? Hash
|
320
334
|
options[:only_path] = true
|
321
335
|
end
|
336
|
+
|
337
|
+
# try to get a regular URL
|
322
338
|
path = url_for__ALIASED(options, *parameters)
|
339
|
+
path += "/"
|
340
|
+
|
341
|
+
# replace anything that references the callback with the
|
342
|
+
# Facebook canvas equivalent (apps.facebook.com/*)
|
323
343
|
if path.starts_with?(self.facebook_callback_path)
|
324
|
-
path.
|
325
|
-
|
326
|
-
|
327
|
-
|
344
|
+
path.sub!(self.facebook_callback_path, self.facebook_canvas_path)
|
345
|
+
path = "http://apps.facebook.com#{path}"
|
346
|
+
else
|
347
|
+
# default to a full URL (will link externally)
|
348
|
+
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to get canvas-friendly URL ("+path+") for ["+options.inspect+"], creating an external URL instead"
|
349
|
+
options[:only_path] = false
|
350
|
+
path = url_for__ALIASED(options, *parameters)
|
328
351
|
end
|
352
|
+
|
353
|
+
# regular Rails rewriting
|
329
354
|
else
|
330
355
|
path = url_for__ALIASED(options, *parameters)
|
331
356
|
end
|
@@ -338,8 +363,9 @@ module RFacebook
|
|
338
363
|
|
339
364
|
def redirect_to(options = {}, *parameters)
|
340
365
|
if in_facebook_canvas?
|
341
|
-
|
342
|
-
|
366
|
+
canvasRedirUrl = url_for(options, *parameters)
|
367
|
+
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: Canvas redirect to #{canvasRedirUrl}"
|
368
|
+
render :text => "<fb:redirect url=\"#{canvasRedirUrl}\" />"
|
343
369
|
else
|
344
370
|
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: Regular redirect_to"
|
345
371
|
redirect_to__ALIASED(options, *parameters)
|
@@ -31,6 +31,9 @@ require "rfacebook_on_rails/view_extensions"
|
|
31
31
|
require "rfacebook_on_rails/controller_extensions"
|
32
32
|
require "rfacebook_on_rails/model_extensions"
|
33
33
|
|
34
|
+
require "digest/md5"
|
35
|
+
require "cgi"
|
36
|
+
|
34
37
|
module RFacebook
|
35
38
|
module Rails
|
36
39
|
module Plugin
|
@@ -73,6 +76,7 @@ rescue
|
|
73
76
|
end
|
74
77
|
|
75
78
|
# make sure the paths have leading and trailing slashes
|
79
|
+
# TODO: also parse for full URLs beginning with HTTP (see: http://rubyforge.org/tracker/index.php?func=detail&aid=13096&group_id=3607&atid=13796)
|
76
80
|
def ensureLeadingAndTrailingSlashesForPath(path)
|
77
81
|
if (path and path.size>0)
|
78
82
|
if !path.starts_with?("/")
|
@@ -87,8 +91,8 @@ def ensureLeadingAndTrailingSlashesForPath(path)
|
|
87
91
|
end
|
88
92
|
end
|
89
93
|
|
90
|
-
FACEBOOK["canvas_path"] = ensureLeadingAndTrailingSlashesForPath(FACEBOOK["canvas_path"])
|
91
|
-
FACEBOOK["callback_path"] = ensureLeadingAndTrailingSlashesForPath(FACEBOOK["callback_path"])
|
94
|
+
FACEBOOK["canvas_path"] = ensureLeadingAndTrailingSlashesForPath(FACEBOOK["canvas_path"]).strip
|
95
|
+
FACEBOOK["callback_path"] = ensureLeadingAndTrailingSlashesForPath(FACEBOOK["callback_path"]).strip
|
92
96
|
|
93
97
|
# inject methods
|
94
98
|
ActionView::Base.send(:include, RFacebook::Rails::ViewExtensions)
|
@@ -99,3 +103,100 @@ ActionController::Base.send(:include, RFacebook::Rails::Plugin::ControllerExtens
|
|
99
103
|
|
100
104
|
ActiveRecord::Base.send(:include, RFacebook::Rails::ModelExtensions)
|
101
105
|
ActiveRecord::Base.send(:include, RFacebook::Rails::Plugin::ModelExtensions)
|
106
|
+
|
107
|
+
|
108
|
+
class CGI::Session
|
109
|
+
|
110
|
+
alias :initialize__ALIASED :initialize
|
111
|
+
alias :new_session__ALIASED :new_session
|
112
|
+
|
113
|
+
def using_facebook_session_id?
|
114
|
+
return @using_fb_session_id
|
115
|
+
end
|
116
|
+
|
117
|
+
def force_to_be_new!
|
118
|
+
@force_to_be_new = true
|
119
|
+
end
|
120
|
+
|
121
|
+
def new_session
|
122
|
+
if @force_to_be_new
|
123
|
+
return true
|
124
|
+
else
|
125
|
+
return new_session__ALIASED
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def initialize(request, options = {})
|
130
|
+
|
131
|
+
# check the environment to find a Facebook sig_session_key (credit: Blake Carlson and David Troy)
|
132
|
+
fbsessionId = nil
|
133
|
+
["RAW_POST_DATA", "QUERY_STRING", "HTTP_REFERER"].each do |tableSource|
|
134
|
+
if request.env_table[tableSource]
|
135
|
+
fbsessionId = CGI::parse(request.env_table[tableSource]).fetch('fb_sig_session_key'){[]}.first
|
136
|
+
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: checked #{tableSource} for Facebook session id and got [#{fbsessionId}]"
|
137
|
+
end
|
138
|
+
break if fbsessionId
|
139
|
+
end
|
140
|
+
|
141
|
+
# we only want to change the session_id if we got one from the fb_sig
|
142
|
+
if fbsessionId
|
143
|
+
options['session_id'] = Digest::MD5.hexdigest(fbsessionId)
|
144
|
+
@using_facebook_session_id = true
|
145
|
+
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: using MD5 of Facebook session id [#{options['session_id']}] for the Rails session id}"
|
146
|
+
end
|
147
|
+
|
148
|
+
# now call the default Rails session initialization
|
149
|
+
initialize__ALIASED(request, options)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# NOTE: the following extensions allow ActiveRecord and PStore to use the Facebook session id for sessions
|
154
|
+
# Their implementation warrants another look. Ideally, we'd like to solve this further up the chain
|
155
|
+
# so that sessions will work no matter what store you have
|
156
|
+
# ...maybe we could just override CGI::Session#session_id? what are the consequences?
|
157
|
+
|
158
|
+
# TODO: support other session stores (like MemCached, etc.)
|
159
|
+
|
160
|
+
# force ActiveRecordStore to use the Facebook session id (credit: Blake Carlson)
|
161
|
+
class CGI
|
162
|
+
class Session
|
163
|
+
class ActiveRecordStore
|
164
|
+
alias :initialize__ALIASED :initialize
|
165
|
+
def initialize(session, options = nil)
|
166
|
+
initialize__ALIASED(session, options)
|
167
|
+
session_id = session.session_id
|
168
|
+
unless @session = ActiveRecord::Base.silence { @@session_class.find_by_session_id(session_id) }
|
169
|
+
# FIXME: technically this might be a security problem, since an external browser can grab any unused session id they want
|
170
|
+
@session = @@session_class.new(:session_id => session_id, :data => {})
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
# force PStore to use the Facebook session id
|
178
|
+
class CGI
|
179
|
+
class Session
|
180
|
+
class PStore
|
181
|
+
alias :initialize__ALIASED :initialize
|
182
|
+
def initialize(session, options = nil)
|
183
|
+
begin
|
184
|
+
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: inside PStore, with session_id: #{session.session_id}, new_session = #{session.new_session ? 'yes' : 'no'}"
|
185
|
+
initialize__ALIASED(session, options)
|
186
|
+
rescue Exception => e
|
187
|
+
begin
|
188
|
+
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to init PStore session, trying to make a new session"
|
189
|
+
# FIXME: technically this might be a security problem, since an external browser can grab any unused session id they want
|
190
|
+
if session.session_id
|
191
|
+
session.force_to_be_new!
|
192
|
+
end
|
193
|
+
initialize__ALIASED(session, options)
|
194
|
+
rescue Exception => e
|
195
|
+
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to create a new PStore session falling back to default Rails behavior"
|
196
|
+
raise e
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
@@ -49,7 +49,7 @@ module RFacebook
|
|
49
49
|
|
50
50
|
def image_path(*params)
|
51
51
|
path = super(*params)
|
52
|
-
if in_facebook_canvas? # TODO: or in_facebook_frame?)
|
52
|
+
if (in_facebook_canvas? or in_mock_ajax?) # TODO: or in_facebook_frame?)
|
53
53
|
path = "#{request.protocol}#{request.host_with_port}#{path}"
|
54
54
|
end
|
55
55
|
return path
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rfacebook
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.8.
|
7
|
-
date: 2007-08-
|
6
|
+
version: 0.8.7
|
7
|
+
date: 2007-08-16 00:00:00 -05:00
|
8
8
|
summary: A Ruby interface to the Facebook API v1.0+ (F8 and beyond). Works with RFacebook on Rails plugin (see rfacebook.rubyforge.org).
|
9
9
|
require_paths:
|
10
10
|
- lib
|