Hi guys, so I just created an app and I have a new theme called "facebook" that I would like to be used when Facebook loads the particular tab with my drupal page in the iframe. But, how do I get the "facebook" theme to be applied instead of my default theme? I have tried "Theme for profile tabs" setting in the app setting on Facebook for Drupal but that appears to have no effect.

Thanks

CommentFileSizeAuthor
#54 fb_tab.diff2.96 KBDave Cohen

Comments

Dave Cohen’s picture

If that doesn't work, its probably because some module is initializing the theme too soon. Sometimes error messages cause this, so look in your drupal log for any errors or warnings.

Try putting dpm() or breakpoint in init_theme(). To see when it is first called and why. Something like dpm(debug_backtrace()); should tell you.

frank0051’s picture

Okay, I put dpm(debug_backtrace()); in the init_theme() function in includes/themes.inc but it gave me a PHP error that DPM was an undefined function. Thoughts?

Also, no errors or warnings in the log when loading the Facebook app.

frank0051’s picture

Nevermind, realized I had to install Drupal devel module. So, I have three arrays (the first has 11 elements, the second 13 elements, and the third is 18 elements), what do I need to look for? Each of them say they were called from /home/crooms/public_html/includes/theme.inc, line 44 before I expand them out.

Dave Cohen’s picture

First of all, enable fb_devel.module. Reproduce the error and look for any messages on the page or in the drupal logs. The README.txt has basic instructions for troubleshooting.

From that dpm() output, you need to expand the stack trace to figure out what is calling theme().

frank0051’s picture

Yes, I already did install devel (look at post #4) and I have the arrays outputting. As far as arrays: I only have one, apparently I executed an admin action at the same time, so the last time I looked it shot out three.

Now, inside of the array, the 2nd element in the stack is this:

"1 (Array, 4 elements)
file (String, 44 characters ) /home/crooms/public_html/includes/common.inc
line (Integer) 2986
function (String, 5 characters ) theme | (Callback) theme();
args (Array, 2 elements)"

So, what do I need to look for now, what's the next step to fixing this? Again, there is no error getting generated in the Drupal log, it is just that the theme settings don't work for the Facebook custom tab :-(.

Dave Cohen’s picture

Since you did not have devel.module installed until comment #4, I'm assuming you don't have fb_devel.module enabled. Enable it.

You need to figure out the first argument being passed to theme(). And you might need to inspect further up the call stack to see exactly what it making the first call to theme().

frank0051’s picture

Okay, I have fb_devel.module enabled. From there, it told me to add the stuff in the readme to the settings.php file, and I did. However, that causes a somewhat annoying problem: a new session each time I go to the Facebook tab. And, if I log into the site through the iframe on Facebook (which I have to do to read the stack), it sends me to a page that doesn't exist and I get a 404 error. Doesn't happen when I do it on the regular site.

In any case, I temporarily enabled devel permissions for anon. users so I wouldn't have to log in and here is the expanded arguments for the first array with mentioned theme():

1 (Array, 4 elements) 
file (String, 44 characters ) /home/crooms/public_html/includes/common.inc 
line (Integer) 2986 
function (String, 5 characters ) theme  | (Callback) theme(); 
args (Array, 2 elements) 
0 (String, 6 characters ) markup 
1 (Array, 4 elements) 
#weight (Integer) 0 
#value (String, 1581 characters ) <p>The Crooms AoIT Alumni Association's Managem... 
#title (NULL) 
#description (NULL)

The only other array listed before that is array 0 and that is the one that calls init_theme():

file (String, 43 characters ) /home/crooms/public_html/includes/theme.inc 
line (Integer) 618 
function (String, 10 characters ) init_theme  | (Callback) init_theme(); 
args (Array, 0 elements)
Dave Cohen’s picture

Make sure you've read everything in the readme.txt, and the documentation that it refers you to. Pay close attention to anything that fb_devel.module has to tell you. Its often a good idea to enable devel info for anonymous, when troubleshooting these sorts of things.

You can see what modules/fb thinks is going on by enabling the block it provides. It spews out a lot of info. At the very least get to the point where it knows the type of page is a tab. If it knows the type of page, and still has the wrong theme, you'll have to figure out what is causing init_theme() to be called.

frank0051’s picture

I believe I have done everything needed according to the Readme, but even with the blocks enabled it doesn't write any errors to the log. The Facebook debug tool doesn't give any errors that need to be fixed either. The only thing the status says is "Not a canvas page".

Page Status = Not a canvas page.
 local user = Anonymous
fb_get_fbu = 
base_url = http://www.croomsalumni.com
base_path = /
url() returns = /fb_page/228511730536994/
$_REQUEST[q] is = about/management
arg(0) is = node
arg(1) is = 269
session_id = 5bb6d4bc93cbab274c11b56656edad17
session_name = SESS50be8ac9c50db30ab40bc89d921cbc94

Within the fb_settings() array it notes that it is a page tab

Array
(
    [fb_page] => 228511730536994
    [page_id] => 228511730536994
    [type] => page_tab
    [cookie_domain] => page_tab
)

So unless the page is supposed to specially equal to "page status=tab" then I don't really know what else to do. I'm trying to follow along with everything you are saying and everything that is in the read-me, but I'm still getting nowhere.

frank0051’s picture

I've disabled basically everything besides Drupal Core and optional core stuff, Ubercart, CCK, and Views and I'm still not making any progress. I'm going to put a fresh install on a subfolder and see if I get any progress but I'm beginning to think this isn't an isolated incident.

frank0051’s picture

Well, I have a brand new install at http://www.croomsalumni.com/test and the only modules on it are devel and Drupal for Facebook. The custom app is at http://www.facebook.com/apps/application.php?id=233959169994957

I have SSL on the page, I have the FB library installed exactly where you tell us to in the readme, I have the settings.php file set up correctly, and I still cannot get the theme to set for the tab. There are only two possible explanations: 1) I'm still not setting it up properly (I'm putting that at a 10% chance) or something is not functioning correctly in the module, perhaps because of the recent Facebook upgrades.

Do you have any suggestions? I can provide you an admin account on Drupal and you are welcome to add the custom app to any of your pages to try out. I'm just not making any progress on this end. :tear:.

Dave Cohen’s picture

Try adding debug output in fb_tab.module. Look for the FB_OP_INITIALIZE clause of fb_tab_fb(), add something like:

 elseif ($op == FB_OP_INITIALIZE) {
    if (fb_is_tab()) {
      $config = _fb_tab_get_config($fb_app);
      dpm(__FUNCTION__ . ": config theme is $config[custom_theme], global custom_theme is $GLOBALS[custom_theme], global theme is $GLOBALS[theme] .");  // Add this line of debug output.
      if (!isset($GLOBALS['custom_theme'])) {
        $GLOBALS['custom_theme'] = $config['custom_theme'];
      }
...

If global theme or custom_theme is already set, it will not attempt to change it.

frank0051’s picture

Okay, well it is running fb_tab_fb() function, but the $op variable is never equal to FB_OP_INITIALIZE. The first time the fb_tab_fb() function is called, the $op variable is equal to FB_OP_CURRENT_APP and it runs the elseif ($op == FB_OP_CURRENT_APP && fb_is_tab()) section of the code. The second time fb_tab_fb() is called, the $op variable is equal to "post init" but as far as I can tell that isn't an elseif switch option so nothing happens. The third time fb_tab_fb() is called, the $op variable is equal to "fb_op_js", but again, it doesn't appear that that is a switch option. Maybe I'm missing some stuff, but basically what I did was add an echo $op; right after the fb_tab_fb() function is created because when I first added the code you suggested nothing happened, so I figured it wasn't even getting that far.

Dave Cohen’s picture

When $op == FB_OP_CURRENT_APP, fb_tab.module should return the $fb_app data structure. (Basically, fb.module is asking "which app is currently active?" and fb_tab.module is saying, "this is a page tab, and therefore I know which app it is."). Can you tell whether it is returning an $fb_app?

If fb.module should then initialize the facebook php sdk, it will call FB_OP_INITIALIZE. Since it is not calling that app, either it is failing to initialize, or no $fb_app was returned.

The other ops don't matter in this case.

frank0051’s picture

No, it doesn't look like it is echoing out any data when I try to get the $fb_app to echo. So what do you think is not occurring within that function?

Würden’s picture

I've been ripping out my hair for over a week now with the exact same problem, and a few other people seem also to have the problem when looking in the issue queue - maybe there is a problem with the module? the theme is never initialized. Here is a similar issue: http://drupal.org/node/1197116

if i do a dpm for $fb_app in the end of the fb_tab_fb function it returns all the informations from the app currently used, in the variable I can see that fb_app_data->fb_tab->custom_theme is indeed set to the custom theme it should be, so it looks like this is not the problem.
I should add that I have the problem in Drupal 7, but it might as well be the same.

_fb_tab_get_config also returns an array with the correct custom theme only used for tabs, so I'm pretty lost.
I can also add that the same theme works perfectly when set for canvas pages.

Würden’s picture

I found a fix for the Drupal 7 branch, see: http://drupal.org/node/1197116

frank0051’s picture

So Dave, what do you think.

Dave Cohen’s picture

Sounds like the 7.x version is sorely in need of that fix.

This issue is the 6.x version, right?

frank0051’s picture

Yes, Drupal 6 issue. But would the same thing apply? If not, what do you think is happening with the information I provided? Why do you think $fb_app isn't being set?

frank0051’s picture

Should I take the silence over the last two weeks as we don't know what's going on?

Dave Cohen’s picture

True enough that I don't know what's going wrong. Also was away all of last week.

Are you including fb_settings.inc in your settings.php?

frank0051’s picture

Yup:

include "sites/all/modules/fb/fb_settings.inc";

Dave Cohen’s picture

try

include "sites/all/modules/fb/fb_settings.inc";
print "<pre>" . print_r(fb_settings(), 1) . "</pre>";

and paste what you see here.

On the facebook "advanced" settings, do you have it using oauth2 signed requests?

frank0051’s picture

Cannot do that because it causes PHP parsing errors because other headers are being sent. Where else can I put it?

Dave Cohen’s picture

Try...

include "sites/all/modules/fb/fb_settings.inc";
print "<pre>" . print_r(fb_settings(), 1) . "</pre>";
exit();

It wont render the page, but should show you the data.

Also, try the .dev build instead of the 3.1. There may be a fix in fb_settings.inc to parse the signed requests.

frank0051’s picture

I've had the dev for a while, just updated to the recent one (mine was about two-three weeks old). Still not working even on my clean install.

It outputs this:

Array
(
[fb_page] => 228511730536994
[page_id] => 228511730536994
[type] => page_tab
[cookie_domain] => page_tab
)

frank0051’s picture

Actually, not it is even worse. The view path is node/1 but the profile_tab_url is now set to http://www.croomsalumni.com/test/fb_cb/233959169994957/fb_tab/view, which is just a blank page.

Dave Cohen’s picture

Version: 6.x-3.1 » 6.x-3.x-dev

So it looks like fb_settings.inc is determining that it is a page tab.

The profile_tab_url looks fine. That's how it now works. When you get a blank page, check your error logs. Make sure PHP is configured to show all errors including startup errors.

Go back to #16, are you sure even with the updated modules/fb that fb_tab.module is not returning an $fb_app?

frank0051’s picture

Well, I think I have the logging set correctly, but the only thing I'm getting is:

	fb_app
Date	Tuesday, November 15, 2011 - 22:04
User	admin
Location	http://www.croomsalumni.com/test/admin/build/fb/app/croomstest/fb_app
Referrer	http://www.croomsalumni.com/test/admin/build/fb/app/croomstest/fb_app
Message	Set facebook app properties for croomstest.
Severity	notice
Hostname	98.197.196.5
Operations	view apps

Back on 16, it still isn't hitting FB_OP_INITIALIZE

function fb_tab_fb is called five times with the following arguments for $op:

get_app
current_app
get_app
init
post init
exit

Dave Cohen’s picture

FB_OP_INITIALIZE is a constant. FB_OP_INITIALIZE and 'init' are the same thing.

Is the theme you're trying to use enabled?

frank0051’s picture

yes the theme is enabled.

I've put some more echos in there, and elseif ($op == FB_OP_INITIALIZE) { is evaluating as true, so it does go into that portion of the function.

$GLOBALS['custom_theme'] is getting set to facebook as well (that's the name of my theme). $use_ob is set to 1 (which I guess is true). The site isn't offline so the dummy theme isn't getting set. $GLOBALS['fb_tab_post_process'] is set to 1 (true). It doesn't run if ($_REQUEST['q'] == FB_TAB_PATH_VIEW) - so, that seems to be where the FB_OP_INITIALIZE fails. The $_REQUEST['q'] is set to fb_cb/123354554434979/fb_tab/view while the FB_TAB_PATH_VIEW is set to fb_tab/view, so it evaluates false and there is nothing else in the FB_OP_INITALIZE portion of the if-then statement to run.

Dave Cohen’s picture

During that ($op == FB_OP_INITIALIZE), what is $GLOBAL['theme'] and what is $GLOBAL['custom_theme']?

When init_theme() first runs, what is the value of $GLOBAL['custom_theme']?

frank0051’s picture

Remember, it's GLOBALS not GLOBAL. $GLOBALS['theme'] isn't set and what is $GLOBALS['custom_theme'] is set to facebook after it hits the if (!isset($GLOBALS['custom_theme'])) .

Where is the init_theme function, I don't see it in the fb_tab.module file (declared or called)...

Dave Cohen’s picture

init_theme is somewhere in drupal core, maybe includes/theme.inc. I'm not sure.

Find it a determine whether i$GLOBALS['custom_theme'] is set to something else when it is called.

frank0051’s picture

Well how do you suggest I find that out, I'm not a developer here...it this something the dev module could tell me?`

Dave Cohen’s picture

We're back to where we were in comment #2.

Put something like

drupal_set_message("custom theme is " . $GLOBALS['custom_theme']);

At the top of the init_theme function.

frank0051’s picture

Interest, Init_theme() isn't even being called on the facebook tab, my echo isn't be pushed out on the tab page. In the regular site, the custom theme is null in the echo.

I checked what the source look like for http://www.croomsalumni.com/fb_cb/123354554434979/fb_tab/view and it is just this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=utf-8" http-equiv=Content-Type></HEAD>
<BODY></BODY></HTML>

So, in essence, something in the module is stopping the rest of the Drupal processes from continuing on.

frank0051’s picture

Just upgraded to the Nov. 29th dev release; cannot say there is any difference - still blank.

wisniewski’s picture

Category: support » bug
Priority: Normal » Major

I have the same problem, Drupal stops and display blank page.

wisniewski’s picture

Tricky workaround: using Domain Access create a subdomain for www, fb app and fb tab. Than the rest of configuration is inside Facebook. Poor but works. Good to have SSL certificate with wildcard.

frank0051’s picture

Sadly, I don't have a wildcard SSL certificate

Dave Cohen’s picture

Category: bug » support

Usually when drupal displays a white screen there is an error somewhere, i.e. an apache log. If PHP is configured correctly it will display the error somewhere.

frank0051’s picture

It's not a white screen though in the sense of an error, it's a white screen in that PHP hasn't pass along anything to render. The scripts are running fine, for some reason your module isn't calling back to the core to render the theme and continue with the rest of the process.

I mean, we know this isn't limited to my installation. We have another person. And, I've set up a clean install to test it on too. How can you explain that? So, we definitely know it is something related to how your module is interacting with something else. May that be an actual error in your module or a server setting on your end that is unconventional to how others have it set up.

frank0051’s picture

Dave, it's been suggested I offer payment for services. If you can get this problem solved by New Years, I'll provide you $30. That seems like a fair offer since a) this is a major feature of your module and b) I'm no longer the only person experience this problem (so it shouldn't be my sole responsibility to finance this thing, haha).

frank005’s picture

Category: support » bug

Just upgraded to the Dec. 12th dev, cannot say it made a difference. I think infotrendy had it right: this is a bug report since multiple suers are having the problem. I've also checked the Apache error logs, nothing there. It's not a parsing error, otherwise Php would display an error. I think you need to go back to comment #42 and look how I mention that init_theme isn't called in the module. Since its not there, where is it called? I don't know Drupal, but I think that is the starting point. We can also show that it isn't an PHP error because I can echo stuff from inside the functions in fb_tab.module in order to not make it a blank page.

I can tell you exactly what's happen too:

function fb_tab_fb is called six times:
The first time it doesn't evaluate to any of the if_elseif statements so it ends.
The second time, it evaluates to true for the FB_OP_CURRENT_APP && fb_is_tab, so it steps through that.
The third time it doesn't evaluate so it doesn't run.
The fourth time it runs the FB_OP_INITIALIZE and it hits the fb_is_tab() statement right after that and evaluates to true. IT then sets $GLOBALS['custom_theme'] equal to facebook. It then sets $use_ob to true. It doesn't look like it sets $dummy equal to anything. Then, it runs the if ($use_ob) { statement. After that it hits the if ($_REQUEST['q'] == FB_TAB_PATH_VIEW), but it evaluates to false - so nothing associated with that statement runs. And, finally, the if ($path && $path != FB_TAB_PATH_VIEW) { evaluates to false as well, so it doesnt run either. It's officially out of stuff to run with that FB_OP_INITIALIZE
The fifth time it hits fb_op_post_init.
The sixth time it finally hits FB_OP_EXIT && fb_is_tab()) . It evaluates to true on if (isset($GLOBALS['fb_tab_post_process']) && $GLOBALS['fb_tab_post_process']) { . However, somehow it gets stuck on this $output = ob_get_contents();
and any echo statements added after that don't display.

So, what happens there - is that normal? what is ob_get_contents() supposed to do? If it stops the rest of the function from running when it otherwise should, we now know where the issue lies. Or, is it perhaps echoing stuff before the ob_get_contents() is called is messing up the function? Or perhaps the output buffer isn't set properly in the previous functions? Is there another way to go around using the ob buffer?

frank005’s picture

also, another interesting question I have is should I be able to echo stuff when the ob_start() has been called?

wisniewski’s picture

If I can somehow confirm the case, let me know, but results seams to be the same.

During general tests of FB Tabs I figure out on one forum (that I can not find now), that this thing happens on polish hosting - home.pl (my case), and the solution was to change the extension of the file to .php (.html didn't work). That test was outside of Drupal.

Dave Cohen’s picture

Status: Active » Needs review
StatusFileSize
new2.96 KB

Please try this patch. It renames a couple functions, for clarity. But the important change is to not rely on $_REQUEST['q'] to determine the path.

frank005’s picture

Status: Needs review » Reviewed & tested by the community

This works, you need to commit this ASAP and dump out a new version of this as a critical release, haha.

That being said, it opens up a new can of worms: the handling of links within the iframe isn't uniform: sometimes they will open in the iframe, sometimes it will trigger a new canvas, and sometimes it will open in the main browser window. When it does open in the iframe, sometimes it will carry over the Facebook theme, sometimes it won't. It does seems, however to be dependent on the type of page that you are linking to: for instance, my links that go to custom pages/panel pages are the ones that don't carry the theme over.

At this point, I just enabled processing on iframe tabs and disabled Links send user to canvas pages so it just pops up with the link directing to the main website and its theme.

Dave Cohen’s picture

Title: How do I set the theme for the page tab? » All page tabs are blank

There's a checkbox on admin/build/fb/fb_tab to control whether links go to canvas pages. If the link is generated by l() or url() functions, this should work. If the link is generated some other way, there's not much modules/fb can do about it.

I'll mark this issue fixed when the patch is pushed to git. Any further discussion of the links should be moved to its own thread.

Dave Cohen’s picture

Status: Reviewed & tested by the community » Fixed

This was actually committed some time ago. Never updated issue status.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.