Newer
Older
<?php
function fb_devel_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array('path' => 'fb/devel',
'callback' => 'fb_devel_page',
'type' => MENU_CALLBACK,
'access' => TRUE, // TODO: restrict access
);
$items[] = array('path' => 'fb/devel/fbu',
'callback' => 'fb_devel_fbu_page',
'type' => MENU_CALLBACK,
'access' => TRUE,
);
}
return $items;
function fb_devel_fb($op, $data, &$return) {
$fb_app = $data['fb_app'];
$fb = $data['fb'];
if ($op == FB_OP_CANVAS_INITIALIZE) {
// Sanity check.
$nid = fb_settings(FB_SETTINGS_APP_NID);
if ($nid != $fb_app->nid) {
$message = t('fb_app id (%fb_app_id) does not equal fb settings id (%fb_settings_id). This is usually caused by the wrong callback url on your <a href="!url">facebook application settings form</a>.',
array('%fb_app_id' => $fb_app->nid,
'%fb_settings_id' => $nid,
'!url' => "http://www.facebook.com/developers/apps.php",
));
drupal_set_message($message, 'error');
watchdog('fb_devel', $message);
}
// Theme sanity check
global $theme; // for debug message
if (isset($theme)) {
Dave Cohen
committed
$message = t('Drupal for Facebook is unable to override the theme settings. This is usually because some module causes theme_init() to be invoked before fb_init(). See the !readme.',
array('!drupal_for_facebook' => l(t('Drupal for Facebook'), 'http://drupal.org/project/fb'),
// This link should work with clean URLs
// disabled.
'!readme' => '<a href='.base_path() . '/' . drupal_get_path('module', 'fb') . '/README.txt>README.txt</a>'));
drupal_set_message($message, 'error');
watchdog('fb_devel', $message);
}
// New facebook API sanity check
if (!variable_get('fb_api_file', FALSE)) {
$message = t('It looks like you have upgraded from version 1.x to 2.x of !drupal_for_facebook without changing all the necessary settings. Read the !readme and follow the instructions carefully.',
array('!drupal_for_facebook' => l(t('Drupal for Facebook'), 'http://drupal.org/project/fb'),
// This link should work with clean URLs
// disabled.
'!readme' => '<a href='.base_path() . '/' . drupal_get_path('module', 'fb') . '/README.txt>README.txt</a>'));
drupal_set_message($message, 'error');
watchdog('fb_devel', $message);
}
// path replacement sanity check
global $base_path;
if ($base_path == "/{$fb_app->canvas}/") {
$message = t('Facebook canvas page matches Drupal base_path (%base_path). This is currently not supported.',
array('%base_path' => $base_path));
drupal_set_message($message, 'error');
watchdog('fb_devel', $message);
}
}
else if ($op == FB_APP_OP_EVENT) {
$type = $data['event_type'];
// Facebook has notified us of some event.
$message = t('Facebook has notified the %label application of a %type event.',
array('%label' => $fb_app->label,
'%type' => $type));
$message .= dprint_r($data, 1);
$message .= dprint_r($_REQUEST,1);
watchdog('fb_devel', $message);
}
/**
* Provides a page with useful debug info.
*
*/
function fb_devel_page() {
global $fb, $fb_app;
global $user;
Dave Cohen
committed
if ($_REQUEST['require_login'])
$fb->require_login();
if ($fb) {
// These will work in a canvas page.
drupal_set_message("in_fb_canvas returns " . $fb->in_fb_canvas());
drupal_set_message("get_loggedin_user returns " . $fb->get_loggedin_user());
drupal_set_message("current_url returns " . $fb->current_url());
Dave Cohen
committed
drupal_set_message("base_url: " . $GLOBALS['base_url']);
drupal_set_message("base_path: " . $GLOBALS['base_path']);
Dave Cohen
committed
drupal_set_message("session_key is " . $fb->api_client->session_key);
}
if ($fbu = fb_get_fbu($user)) {
$path = "fb/devel/fbu/$fbu";
drupal_set_message(t("Learn more about the current user at !link",
array('!link' => l($path, $path))));
}
dpm(fb_get_fbu($user), 'Facebook user via fb_get_fbu');
//dpm($user, "Local user " . theme('username', $user));
//dpm($_COOKIE, 'cookie');
//dpm($_REQUEST, "Request");
//dpm($fb_app, "fb_app");
//drupal_set_message("session_id returns " . session_id());
//dpm($_SESSION, "session:");
return "This is the facebook debug page.";
}
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
* A page which tests function which work with facebook user ids
*/
function fb_devel_fbu_page($fbu = NULL) {
if ($fbu) {
$output = "<p>Debug info about facebook id $fbu:</p>\n";
$friends = fb_get_friends($fbu);
//dpm($friends, "fb_get_friends($fbu) returned");
$items = array();
foreach ($friends as $_fbu) {
$items[] = l($_fbu, "fb/devel/fbu/{$_fbu}");
}
if (count($items)) {
$output .= "\n<p>Known friends:<ul><li>";
$output .= implode("</li>\n <li>", $items);
$output .= "</li></ul></p>\n\n";
}
$local_friends = fb_user_get_local_friends($fbu);
$items = array();
foreach ($local_friends as $uid) {
$account = user_load(array('uid' => $uid));
$items[] = theme('username', $account);
}
if (count($items)) {
$output .= "\n<p>Local friends:<ul><li>";
$output .= implode("</li>\n <li>", $items);
$output .= "</li></ul></p>\n\n";
}
}
else
drupal_set_message("You have to specify a facebook user id.", 'error');
return $output;
}
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
function fb_devel_block($op = 'list', $delta = 0, $edit = array()) {
if ($op == 'list') {
$items[0]['info'] = t('Facebook Devel Canvas Page Info');
return $items;
}
else if ($op == 'view') {
return array('subject' => t('Facebook Devel Canvas Page'),
'content' => drupal_get_form('fb_devel_canvas_info'));
}
}
function fb_devel_canvas_info() {
global $fb, $fb_app;
global $user;
global $base_url;
global $base_path;
$info = array();
if ($fb) {
if ($fb->in_fb_canvas())
$info['Page Status'] = t('Rendering FBML canvas page.');
else if ($fb->in_frame()) {
$info['Page Status'] = t('Rendering iframe.');
}
else {
// Followed a link from within an iframe.
$info['Page Status'] = t('Global fb instance is set (followed link in iframe, or handling a form).');
}
$info['fb_facebook_user'] = fb_facebook_user();
}
else {
$info['Page Status'] = t('Not a canvas page.');
}
$info['local user'] = theme('username', $user);
$info['fb_get_fbu'] = fb_get_fbu($user->uid);
$info['base_url'] = $base_url;
$info['base_path'] = $base_path;
$info['session_id'] = session_id();
$info['session_name'] = session_name();
$info['request'] = $_REQUEST;
$info['fb_app'] = $fb_app;
Dave Cohen
committed
$info['session'] = $_SESSION;
$form = array();
foreach ($info as $key => $val) {
if (is_string($val) || is_numeric($val) || !$val) {
$form[] = array('#value' => t($key) . ' = ' . $val,
'#weight' => count($form),
'#suffix' => '<br/>',
);
}
else {
$form[] = array('#type' => 'fieldset',
'#title' => t($key),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => count($form),
'value' => array('#prefix' => '<pre>',
'#suffix' => '</pre>',
'#type' => 'markup',
'#value' => dprint_r($val, 1)),
);
}
}
// It's not really a form, but we like collapsible fieldsets
return $form;
}
?>