I'm trying to set up up multiple facebook apps (with Drupal for Facebook) with one Drupal installation. After struggling with Spaces for a few days I found Sites which worked perfectly. My issue comes when I integrate with Drupal for Facebook which adds a prefix of it's own to facebook's callback url. I'm more of a web designer who knows a bit of PHP but I don't know enough to make both prefixes play nicely. My attempted workaround was to change my Sites PURL modifier from path to query string. Unfortunately sites doesn't recognize the query to activate my sites. I looked through the Sites code and couldn't find any reference to query strings so I'm assuming it's not a current feature. Any suggestions would be greatly appreciated. Awesome module BTW.

Comments

brynbellomy’s picture

When you say prefix, do you mean the "sites:x,y,z" prefix added to node URL paths by the Sites Path Aliasing submodule, or the actual prefix recognized by PURL (i.e. domain, subdomain, etc)?

Sites Path Aliasing is only built to deal with the prefix at the very beginning of the URL, and given the blood, sweat, and tears that went into getting it up and running, I have no plans to add other types of prefixes just yet :)

However, getting the core Sites module to work with all of PURL's prefix types is something I intend to support, and I'd be kind of surprised if it didn't work out of the box, so let me know if this is the issue you're experiencing.

frdesign’s picture

Thanks for your response. I dealt with this almost a month ago so I hope I remember the details. After playing around I figured out that the issue is that Drupal for Facebook places the prefix at the very beginning of the url. As you said Sites is built to respond to the first prefix so that broke my sites functionality. I tried moving the Facebook prefix after the Sites prefix but that broke my Facebook functionality. I tried the URL Alter module which is supposed to make modules that add prefixes play nicely but it got too complicated for me.

I didn't want to give up your awesome module (and I do mean AWESOME!) so I poured through your code to figure out how it works. No easy task for me since I'm a programmer wanna be. I found the code that actually activates each site and made a custom module which used the Facebook prefix to activate my sites. It just happens that the FB prefix identifies a facebook app, which is exactly what I needed.

As far as Sites supporting PURL's other prefix types unfortunately it didn't work for me. I changed the PURL Sites modifier from prefix to Query string. Before I came up with my solution I asked the PURL developers for advice but I never got a response. (http://drupal.org/node/1055144)

PURL appends ?site=site-name to every page as expected but Sites doesn't recognize it. Not a big deal since I'm depending on the FB prefix now but for my development server the FB prefix is nonexistent. For testing environment use I ended up adding a custom function on my module which reads the query string and activates the site.

Here is the code in my module that makes things happen, probably not the best solution but it worked for me.

<?php
/**
 *
 *
 * Activate Sites Module functions from either FB app url value (fb_cb) or query string (?sprint=p90x).
 */

// Method 1: If fb_cb is not used check if PURL query string ?sprint=(sprint name) is available
if ($_GET['sprint']) {
  // Get numeric site value (sid) from {sites} table
  $site_name = $_GET['sprint'];
  $result = db_query("SELECT sid FROM {sites} WHERE purl_prefix = '%s'", $site_name);
  while ($row = db_fetch_array($result)){
    $sid = $row['sid'];
  }
  
  // Force Sites to activate subsite & context through it's own funcitons
  if (function_exists(sites_purl_set_current_site($sid))) {
    sites_purl_set_current_site($sid);
  }
} else {
  // Method 2: If fb_cb prefix is in url we get site's sid by querying {sprint_subsites_helper} custom table
  // Check for facebook callback number in canvas url
  $fb_cb = url();
  $fb_cb = explode('/', $fb_cb);
  
  // Find fb_cb value, $fb_cb[0] is usually empty and fb_cb key and value are
  // in $fb_cb[1] and $fb_cb[2] respectively, check $fb_cb[0] just in case
  if ($fb_cb[0] == 'fb_cb') {
    $array_value = 1;
  } elseif ($fb_cb[1] == 'fb_cb') {
    $array_value = 2;
  }
  
  // Activate Sites Module site if fb_cb is found
  if ($array_value) {
    // Get actual value which comes after 'fb_cb/' in url
    $canvas_cb = $fb_cb[$array_value];
    $result = db_query("SELECT sid FROM {sprint_subsites_helper} WHERE facebook_callback = '%s'", $canvas_cb);
    while ($row = db_fetch_array($result)){
      $sid = $row['sid'];
    }
    // Check that sites module functions are available
    if (function_exists(sites_purl_set_current_site($sid))) {
      sites_purl_set_current_site($sid);
    }
  }
}


?>

hydra’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

As this module has not been maintained for some time, I am closing this ticket as “outdated”. A new version of sites which is architecturally and technically unrelated to the Drupal 6 and Drupa 7 versions will be published here soon.
Thank you for your contribution.