In order to work correctly in some browsers the Facebook XML namespace needs to be added to the page, e.g.:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" xmlns:fb="http://www.facebook.com/2008/fbml">

The readme.txt file currently suggests adding this straight to the page.tpl.php file. Unfortunately I've seen in some situations it can cause conflicts with other scripts loading on the page and cause the node edit/add pages to not work correctly.

Comments

DamienMcKenna’s picture

FYI the current fbconnect files in CVS have incorrect line endings, they should all be UNIX format (LF) instead of Windows format (CR/LF).

Here's the code I added to achieve this; it adds a new setting to the admin/settings/fbconnect page and the page.tpl.php files have to be adjusted to output a variable instead of hardcoding the xmlns value.

Add this to the end of fbconnect.module:


/**
 * Implementation of template_preprocess_page().
 */
function fbconnect_preprocess_page(&$vars) {
  // Add the Facebook namespace to the page header.  This should be added to
  // the template's page.tpl.php, e.g.:
  // <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print
  // $language->language; ? >" lang="<?php print $language->language; ? >"
  // dir="<?php print $language->dir; ? >"<?php print $xml_namespaces; ? >>
  // (all on one line, remove the spaces between the '?' and '>' symbols)

  // Make sure the XML namespaces variable is available.
  if (!isset($vars['xml_namespaces'])) {
    $vars['xml_namespaces'] = '';
  }
  
  // The XML namespace string required for Facebook.
  $xmlns = ' xmlns:fb="http://www.facebook.com/2008/fbml"';
  // Check if this is a node edit/add page.
  if ((arg(0) == 'node' && is_numeric(arg(1)) && arg(2) != 'edit') && (arg(0) == 'node' && arg(1) != 'add')) {
    // If the configuration is set to not load the XML namespace, clear it.
    if (!variable_get('fbconnect_xmlns_node', TRUE)) {
      $xmlns = '';
    }
  }
  $vars['xml_namespaces'] .= $xmlns;
}

Add this at line 59 of fbconnect.admin.inc:

  $form['global']['fbconnect_xmlns_node'] = array(
    '#type' => 'checkbox',
    '#title' => t('Load Facebook XML namespace on Node edit/add pages'),
    '#default_value' => variable_get('fbconnect_xmlns_node', TRUE),
    '#description' => t('The Facebook XML namespace (see the README.TXT file) can in certain circumstances cause the node edit/add pages to stop functioning correctly; unchecking this will cause the namespace to not be loaded.'),
  );  
  

Change the installation step 7 the README.TXT file to the following:

	7. Edit the "page.tpl.php" file of your current theme. Edit the <html> tag
	   and output the $xml_namespaces variable at the end of the line just
	   before the closing tag, e.g. from the Zen theme's page.tpl.php file:
  	   <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print
	     $language->language; ?>" lang="<?php print $language->language; ?>"
	     dir="<?php print $language->dir; ?>"<?php print $xml_namespaces; ?>>
DamienMcKenna’s picture

Status: Active » Needs review

Note: if someone could fix the line endings I'll be only too happy to supply a patch, right now my patch tries to fix the line endings problem too so is completely borked.

vectoroc’s picture

does the namespace cause conflicts? give sample script/module, pls

DamienMcKenna’s picture

I believe this was a bug with IE6, possibly IE7 also. I no longer have access to the sites this issue first appeared on.