Theme won't stick in iFrame applications

garethsprice - August 20, 2009 - 18:45
Project:Drupal for Facebook
Version:6.x-2.x-dev
Component:Canvas Pages
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Issue tags:$_SESSION, canvas, cross-site scripting, facebook, fb, fbConnect, iframe, session, themes, theming
Description

I'm trying to get iFrame rendering working for our Facebook application.

I have chosen a (standard HTML, non-FBML) theme in the application's Canvas Pages preferences and the theme is correctly displayed on the first page that loads, but on subsequent page loads (eg. if you click on anything) the app reverts to the site's standard theme.

I've checked $_SESSION and it doesn't seem to be retaining any session data - var_dump($_SESSION) returns an empty array on the second page load. However, I still remain logged in correctly.

I have added the code from http://www.drupalforfacebook.org/files/garland_fb.txt to the top/bottom of both my Facebook theme and my site theme which I believe should make the themes 'Facebook aware', with no effect.

I'd appreciate any suggestions for further areas I can investigate to try to solve this issue.

#1

Dave Cohen - August 20, 2009 - 20:07

Use this code to see if some other module is affecting the theme: http://drupal.org/node/187868#comment-784309

Rather than checking session, enable the fb_devel block. It will give you more info. Paste it here if you need my help to understand it.

Are you building an iframe app, or FBML app in which you have an fb:iframe tag?

#2

garethsprice - August 21, 2009 - 13:38

Thanks for the hints Dave, I will try the above.

It is an iFrame app.

#3

garethsprice - August 24, 2009 - 15:45

I've tracked the issue back to the $fb->fb_params array being empty on page loads after the first.

This means that $fb->in_frame (and, in turn, the FB module's fb_canvas_is_iframe() function) will always return false and it fails to load the custom theme.

I'm not quite clear on the workflow related to saving sessions and reloading them, but I can't see anything in the fb module code which is populating the fb_params variable. It does save fb_params to the local $_SESSION on line 245, but this is only if $fb->in_frame() returns true (which never happens).

I can modify fb_canvas_is_iframe to always return true, which is fine for my purposes, but I'd rather help to fix the problem properly and contribute back to the module.

If you have any other suggestions they would be greatly appreciated. Thanks for all your help so far.

Here's the FB Devel Block output if it's helpful:

First load

Page Status = Rendering iframe.
fb_facebook_user = 688859516
users_isAppUser = 1
users_isAppUser(688859516) = 1
local user = testuser
fb_get_fbu = 688859516
base_url = http://XXXXX
base_path
= /
url() returns = /fb_cb/1308/
$_REQUEST[q] is = fb_cb/1308/
arg(0) is = facebook
arg(1) is = goals
session_id = fb_canvas_1308_2.28Xd6Q07BfCipVG8fudF5g__.86400.1251216000-688859516
session_name = fb_canvas_1308_SESSb0fe3fcaca3b9cd7b1d5dbd9062d0386

Watchdog shows that a custom frame was chosen correctly.

Subsequent loads

Page Status = Global fb instance is set (followed link in iframe, or handling a form).

fb
fb_facebook_user = 688859516
users_isAppUser = 1
users_isAppUser(688859516) = 1
local user = testuser
fb_get_fbu = 688859516
base_url = http://XXXXX
base_path
= /
url() returns = /fb_cb/1308/
$_REQUEST[q] is = fb_cb/1308/facebook/goals/accomplished
arg(0) is = facebook
arg(1) is = goals
session_id =
session_name = SESSb0fe3fcaca3b9cd7b1d5dbd9062d0386

Watchdog shows that $custom_theme is set to a blank string, because of the in_frame() check failing as described above, so $custom_theme never gets populated by the fb module.

#4

Dave Cohen - August 24, 2009 - 19:28

What's generating the link that you follow from first page to next? For example is it a link in a menu?

Sounds like the problem is links like <a href="some/relative/url">...</a> will not work but <a href="http://apps.facebook.com/canvasname/fully/qualified/url" target="top">...</a> would work fine. I'm not sure if this was broken in the 6.x version or if it has always been this way.

I think what should happen is that as long as the some/relative/url starts with fb_cb/NNNN/... then it should behave as an iframe canvas page and share session with the first request. Your path appears correct, so its a bug that it is not working.

Don't have a fix right now but thanks for helping me understand.

#5

bmuraliusa - August 28, 2009 - 12:57

Hi garethsprice, Cohan

I am newbee for drupal . I am trying create a facebook application in iframe using drupal. I have solve this theme problem by using themkey(http://drupal.org/project/themekey) module. But i have another problem with iframe application.

"When opening canvas page , the application opens in the iframe. But when i click any links in the page then it was open outside of facebook (without in the iframe) . I think the problem cause by same thing.

Fbparams are not passed in all links.so that it cause this type of problem. Cohan can you help me to pass variables in all of the page links.

I am expecting your reply.

Thanks in advance

#6

Dave Cohen - August 28, 2009 - 15:54

@bmuraliusa - I can't tell from your post whether you are using Drupal for Facebook or not. If not, I can't help you. If you are, you should not also need the themekey module.

@garthsprice - I had to look over my code to remember how I had addressed this. Take a look at the fb_fbml theme, which can actually be used as either an fbml theme or an iframe theme (albeit with very little styling). Look at template.php, fb_fbml_page() function. See where it calls fb_canvas_process() before returning anything. Add code like this to your iframe theme.

The result should be that links have urls starting with apps.facebook.com/... and target=_top. This way, each link send the user back to facebook and the request to drupal will have all the information it needs.

I realize there is some inefficiency in this, in some cases. But in many cases it is desireable to refresh the _top frame. So ideally there would be some smarter granular control over this. But for now this is what the modules offer. Improvements always welcome!

#7

Dave Cohen - August 28, 2009 - 15:56

@bmuraliusa - I can't tell from your post whether you are using Drupal for Facebook or not. If not, I can't help you. If you are, you should not also need the themekey module.

@garthsprice - I had to look over my code to remember how I had addressed this. Take a look at the fb_fbml theme, which can actually be used as either an fbml theme or an iframe theme (albeit with very little styling). Look at template.php, fb_fbml_page() function. See where it calls fb_canvas_process() before returning anything. Add code like this to your iframe theme.

The result should be that links have urls starting with apps.facebook.com/... and target=_top. This way, each link send the user back to facebook and the request to drupal will have all the information it needs.

I realize there is some inefficiency in this, in some cases. But in many cases it is desireable to refresh the _top frame. So ideally there would be some smarter granular control over this. But for now this is what the modules offer. Improvements always welcome!

#8

bmuraliusa - August 31, 2009 - 06:13

Hi Cohen,

I am using the drupal for facebook module. if you want any details i can give. In starting i am having problem as garethsprice have. Using themekey i have some how managed the error. But now the problem is the when click on the every link it came out of the iframe. How do i have solve this problem.

Please help me

Thanks

#9

bmuraliusa - September 9, 2009 - 13:39

Cohan any answers from you... how long can i wait for your response?

Thanks In Advance for your reply

 
 

Drupal is a registered trademark of Dries Buytaert.