shorter "Facebook Apps" fits admin_menu better.
global $_fb_app;
- // fb_settings.inc may have been included in settings.php. If not, included it now.
+ // fb_settings.inc may have been included in settings.php. If not, include it now.
if (!function_exists('fb_settings')) {
module_load_include('inc', 'fb', 'fb_settings');
// trigger test in fb_devel.module
'scope' => 'header',
'group' => JS_LIBRARY,
));
+
}
// Add Facebook javascript to all pages.
'secret' => $fb_app->secret,
'cookie' => variable_get(FB_VAR_USE_COOKIE, TRUE),
));
+
// Facebook certs are not valid.
Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = FALSE;
Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYHOST] = FALSE;
$fbu = fb_facebook_user($fb);
if (!$fbu) {
$client_id = $fb->getAppId();
- $redirect_uri = $destination ? $destination : url(fb_scrub_urls($_REQUEST['q']), array('absolute' => TRUE, 'fb_canvas' => fb_is_canvas()));
+ $redirect_uri = $destination ? $destination : url(current_path(), array('absolute' => TRUE, 'fb_canvas' => fb_is_canvas()));
$url = "https://graph.facebook.com/oauth/authorize?client_id=$client_id&redirect_uri=$redirect_uri";
- drupal_goto($url);
+ if (fb_is_canvas() && module_exists('fb_canvas')) {
+ fb_canvas_redirect($url);
+ }
+ else {
+ header('Location: ' . $url); // drupal_goto is for internal redirects only.
+ }
}
else {
return $fbu;
// Admin pages overview.
$items[FB_PATH_ADMIN] = array(
- 'title' => 'Facebook Applications',
+ 'title' => 'Facebook Apps',
'description' => 'Facebook Applications',
'page callback' => 'fb_admin_page',
'access arguments' => array(FB_PERM_ADMINISTER),
*/
function fb_app_install() {
// drupal_install_schema is called by Drupal
- drupal_set_message(st('Facebook Application module installed. Please grant yourself <a href="!perm">permissions</a> and then browse to <a href="!create">Admin >> Facebook Applications</a> to get started.', array('!perm' => url('admin/people/permissions'), '!create' => url('admin/structure/fb') /* FB_PATH_ADMIN */)));
+ drupal_set_message(st('Facebook Application module installed. Please grant yourself <a href="!perm">permissions</a> and then browse to <a href="!create">Admin >> Structure >> Facebook Apps</a> to get started.', array('!perm' => url('admin/people/permissions'), '!create' => url('admin/structure/fb') /* FB_PATH_ADMIN */)));
}
/**
}
}
if ($fb_app) {
+ //dpm($fb_app, __FUNCTION__);
$return = $fb_app;
}
}
*
* @see fb_url_rewrite.inc
*/
+/* not needed D7
if (!function_exists('custom_url_rewrite_outbound')) {
function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
fb_canvas_url_outbound_alter($path, $options, $original_path);
}
}
+*/
/**
* Implements hook_url_outbound_alter().
* particular application.
*/
function fb_canvas_url_outbound_alter(&$path, &$options, $original_path) {
+ // use $options['fb_url_alter'] = FALSE to suppress any alteration.
+ if ($options['fb_url_alter'] === FALSE) {
+ return;
+ }
+
if (isset($options['fb_canvas']) && is_string($options['fb_canvas'])) {
$fb_app = fb_get_app(array('label' => $options['fb_canvas']));
}
}
if ($fb_app && isset($fb_app->canvas)) {
- if ((!isset($options['fb_url_alter']) || $options['fb_url_alter']) &&
- (isset($options['fb_canvas']) && $options['fb_canvas'])) {
+ if (isset($options['fb_canvas']) && $options['fb_canvas']) {
// Make a url starting with apps.facebook.com/...
- $options['external'] = TRUE;
- $options[FB_SETTINGS_CB] = FALSE; // prevent fb_url_rewrite.inc from altering.
+ $options[FB_SETTINGS_CB] = FALSE; // prevent fb_url_rewrite.inc from inserting 'fb_cb'.
$options['absolute'] = TRUE;
$options['base_url'] = 'http://apps.facebook.com/' . $fb_app->canvas;
}
if ($_fb) {
if (function_exists('fb_url_outbound_alter')) {
- $base_before_rewrite = '';
+ $base_rewrite = '';
$rewrite_options = array(FB_SETTINGS_CB_SESSION => FALSE, FB_SETTINGS_CB_TYPE => FALSE);
- $base = $base_path . fb_url_outbound_alter($base_before_rewrite, $rewrite_options, ''); // short URL with rewrite applied.
+ fb_url_outbound_alter($base_rewrite, $rewrite_options, '');
+ $base = $base_path . $base_rewrite; // short URL with rewrite applied.
}
else {
// If no url_alter, use normal base_path.
if (count($patterns)) {
$count = 0;
$return = preg_replace($patterns, $replacements, $output, -1, $count);
- //print ("fb_canvas_adjust_html replaced $count.\n\n"); // debug
+ //dpm("fb_canvas_adjust_html replaced $count.\n\n"); // debug
return $return;
}
else
/**
* Define custom_url_rewrite_inbound() if not defined already.
*/
+/* D7 should not need.
if (!function_exists('custom_url_rewrite_inbound')) {
function custom_url_rewrite_inbound(&$result, $path, $path_language) {
fb_url_inbound_alter($result, $path, $path_language);
}
}
-
+*/
/**
* Define custom_url_rewrite_outbound() if not defined already.
*/
+/* D7 should not need.
+
if (!function_exists('custom_url_rewrite_outbound')) {
function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
if (!isset($options['fb_url_alter']) || $options['fb_url_alter']) {
}
}
}
+*/
/**
* Implements hook_url_outbound_alter().
* link from a canvas page out to the server's URL.
*/
function fb_url_outbound_alter(&$path, &$options, $original_path) {
- if (!isset($options['fb_url_alter']) || $options['fb_url_alter']) {
- $pre = '';
+ if ($options['fb_url_alter'] === FALSE) {
+ return;
+ }
- // Prefix each known value to the URL
- foreach (_fb_settings_url_rewrite_prefixes() as $prefix) {
- if (!isset($options[$prefix]) || $options[$prefix] !== FALSE) {
- if ($value = fb_settings($prefix))
- $pre .= $prefix . '/' . $value . '/';
- }
+ // For most hooks, fb should come before fb_.... modules. But in this case we want fb_canvas to act first.
+ if (function_exists('fb_canvas_url_outbound_alter')) {
+ fb_canvas_url_outbound_alter($path, $options, $original_path);
+ }
+
+ $pre = '';
+
+ // Prefix each known value to the URL
+ foreach (_fb_settings_url_rewrite_prefixes() as $prefix) {
+ if (!isset($options[$prefix]) || $options[$prefix] !== FALSE) {
+ if ($value = fb_settings($prefix))
+ $pre .= $prefix . '/' . $value . '/';
}
- $path = $pre . $path;
}
+ $path = $pre . $path;
- return $path;
+ // Since we called fb_canvas_url_alter already, supress it from acting again.
+ $options['fb_url_alter'] = FALSE;
}
/**