function _fb_canvas_make_form_action_local in Drupal for Facebook 6.2
Same name and namespace in other branches
- 5.2 fb_canvas.module \_fb_canvas_make_form_action_local()
- 5 fb_canvas.module \_fb_canvas_make_form_action_local()
1 call to _fb_canvas_make_form_action_local()
- fb_canvas_form_alter in ./
fb_canvas.module - Implementation of hook_form_alter.
File
- ./
fb_canvas.module, line 544 - This module provides support for Canvas page applications. Use Drupal to power traditional Facebook Apps.
Code
function _fb_canvas_make_form_action_local($action = NULL) {
global $base_path;
if (!isset($action)) {
// Is this ever reached?
if (function_exists('dpm')) {
dpm("_fb_canvas_make_form_action_local({$action})");
}
// XXX
$action = $_GET['q'];
}
// If action is fully qualified, do not change it
if (strpos($action, ':')) {
if (function_exists('dpm')) {
dpm($action, "leaving form action untouched");
}
// XXX
return $action;
}
// I'm not sure where the problem is, but sometimes actions have two question marks. I.e.
// /htdocs/?app=foo&q=user/login?destination=comment/reply/1%2523comment-form
// Here we replace 3rd (or more) '?' with '&'.
$parts = explode('?', $action);
if (count($parts) > 2) {
if (fb_verbose()) {
watchdog('fb_canvas', "fixing badly formed action: " . $action);
}
$action = array_shift($parts) . '?' . array_shift($parts);
$action .= '&' . implode('&', $parts);
}
$relative = url('');
$absolute = url('', array(
'absolute' => TRUE,
));
$base_path = base_path();
// By default, '#action' will be request_uri(), which starts with base_path();
global $_fb_app;
if (strpos($action, FB_SETTINGS_CB)) {
// XXX old way. Will go away.
$action = $absolute . substr($action, strlen($relative));
}
elseif (strpos($action, $relative) === 0 && function_exists('fb_url_inbound_alter')) {
// XXX another old way.
// Replace relative action with absolute.
// Include fb settings
// TODO: FB_SETTINGS_CB_TYPE
$action = $absolute . FB_SETTINGS_CB . '/' . $_fb_app->label . '/' . substr($action, strlen($relative));
}
else {
// New way...
if (strpos($action, $relative) === 0) {
// If here, the action was made by call to url() and we prepended
// canvas_name. Now remove the canvas name for a proper absolute url.
// (Comment forms reach this clause but node forms do not.)
$action = substr($action, strlen($relative));
}
elseif ($base_path && strpos($action, $base_path) === 0) {
$action = substr($action, strlen($base_path));
}
$action = url(ltrim($action, '/'), array(
'absolute' => TRUE,
));
}
// Changed code to work when $base_path set. Need to test on server where base_path is ''.
//dpm($action, "_fb_canvas_make_form_action_local returning<br/>");
return $action;
}