/[drupal]/contributions/modules/fb/fb_devel.module
ViewVC logotype

Contents of /contributions/modules/fb/fb_devel.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.24 - (show annotations) (download) (as text)
Thu Oct 22 23:22:55 2009 UTC (5 weeks ago) by yogadex
Branch: MAIN
Changes since 1.23: +15 -15 lines
File MIME type: text/x-php
test to avoid a php warning.
1 <?php
2
3 function fb_devel_menu() {
4 $items['fb/devel'] = array(
5 'page callback' => 'fb_devel_page',
6 'type' => MENU_CALLBACK,
7 'access callback' => TRUE, /* TODO: restrict access */
8 );
9
10 $items['fb/devel/fbu'] = array(
11 'page callback' => 'fb_devel_fbu_page',
12 'type' => MENU_CALLBACK,
13 'access' => TRUE,
14 );
15
16 return $items;
17 }
18
19
20 function fb_devel_init() {
21 if (fb_verbose() === 'extreme') {
22 if (arg(0) == 'fb_connect' && arg(1) == 'receiver') {
23 // useful for tracking down tricky connect bugs.
24 watchdog('fb_devel', "Facebook Connect receiver called" . " " . dpr($_REQUEST, 1));
25 }
26 }
27 }
28
29 function fb_devel_fb($op, $data, &$return) {
30 $fb_app = $data['fb_app'];
31 $fb = $data['fb'];
32
33 if ($op == FB_OP_INITIALIZE) {
34 // Sanity check.
35 $nid = fb_settings(FB_SETTINGS_APP_NID);
36 if ($nid && $nid != $fb_app->nid) {
37 $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>.',
38 array('%fb_app_id' => $fb_app->nid,
39 '%fb_settings_id' => $nid,
40 '!url' => "http://www.facebook.com/developers/apps.php",
41 ));
42 drupal_set_message($message, 'error');
43 watchdog('fb_devel', $message, array(), WATCHDOG_ERROR);
44 }
45
46 // Theme sanity check
47 global $theme; // for debug message
48 if (isset($theme)) {
49 $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.',
50 array('!drupal_for_facebook' => l(t('Drupal for Facebook'), 'http://drupal.org/project/fb'),
51 // This link should work with clean URLs
52 // disabled.
53 '!readme' => '<a href='.base_path() . '/' . drupal_get_path('module', 'fb') . '/README.txt>README.txt</a>'));
54 drupal_set_message($message, 'error');
55 watchdog('fb_devel', $message, array(), WATCHDOG_ERROR);
56 }
57
58 // path replacement sanity check
59 global $base_path;
60 if ($base_path == "/{$fb_app->canvas}/") {
61 $message = t('Facebook canvas page matches Drupal base_path (%base_path). This is currently not supported.',
62 array('%base_path' => $base_path));
63 drupal_set_message($message, 'error');
64 watchdog('fb_devel', $message);
65 }
66
67 // arg_separator sanity check
68 $sep = ini_get('arg_separator.output');
69 if ($sep != '&') {
70 $message = t('Facebook client libraries will not work properly if arg_separator.output is not "&". Currently the value is "!sep". Please change this in settings.php or php.ini.', array('!sep' => check_plain($sep)));
71 drupal_set_message($message, 'error');
72 watchdog('fb_devel', $message);
73 }
74
75 // clean url sanity check
76 if (!variable_get('clean_url', FALSE)) {
77 $message = t('Drupal for Facebook will not function properly until <a href=!url>clean URLs</a> are turned on.',
78 array('!url' => url('admin/settings/clean-urls')));
79 if (user_access('access administration pages')) {
80 drupal_set_message($message, 'error');
81 }
82 watchdog('fb_devel', $message);
83 }
84
85 // server URL sanity check
86 // This is an expensive test, because it invokes api_client.
87 $props = $fb->api_client->admin_getAppProperties(array('connect_url', 'callback_url'));
88 if (is_array($props)) {
89 foreach ($props as $prop => $url) {
90 if ($url && (strpos($url, $GLOBALS['base_url']) === FALSE)) {
91 $message = t('The Facebook Application labeled %label has a suspicious %prop. The value is %value, while something starting with %url was expected. Consider editing !nodelink.',
92 array('%label' => $fb_app->label,
93 '%prop' => $prop,
94 '%value' => $url,
95 '%url' => $GLOBALS['base_url'],
96 '!nodelink' => l($fb_app->title, 'node/'.$fb_app->nid . '/edit'),
97 ));
98
99 if (user_access('access administration pages')) {
100 drupal_set_message($message, 'error');
101 }
102 watchdog('fb_devel', $message);
103 }
104 }
105 }
106 }
107
108 else if ($op == FB_APP_OP_EVENT) {
109 $type = $data['event_type'];
110 // Facebook has notified us of some event.
111 $message = t('Facebook has notified the %label application of a %type event.',
112 array('%label' => $fb_app->label,
113 '%type' => $type));
114 $message .= dprint_r($data, 1);
115 $message .= dprint_r($_REQUEST,1);
116 watchdog('fb_devel', $message);
117 }
118
119 else if ($op == FB_OP_CANVAS_EXIT && $data['fb'] && $return) {
120 watchdog('fb_devel', 'Drupal is redirecting a canvas page, destination is %destination.', array('%destination' => $return));
121 }
122 }
123
124 /**
125 * Provides a page with useful debug info.
126 *
127 */
128 function fb_devel_page() {
129 global $fb, $fb_app;
130 global $user;
131
132 if ($_REQUEST['require_login'])
133 $fb->require_login();
134
135 if ($fb) {
136 // These will work in a canvas page.
137 drupal_set_message("in_fb_canvas returns " . $fb->in_fb_canvas());
138 drupal_set_message("get_loggedin_user returns " . $fb->get_loggedin_user());
139 drupal_set_message("current_url returns " . $fb->current_url());
140
141 drupal_set_message("base_url: " . $GLOBALS['base_url']);
142 drupal_set_message("base_path: " . $GLOBALS['base_path']);
143 drupal_set_message("url() returns: " . url());
144 drupal_set_message("session_key is " . $fb->api_client->session_key);
145 }
146
147 if ($fbu = fb_get_fbu($user)) {
148 $path = "fb/devel/fbu/$fbu";
149 drupal_set_message(t("Learn more about the current user at !link",
150 array('!link' => l($path, $path))));
151 }
152
153 dpm(fb_get_fbu($user), 'Facebook user via fb_get_fbu');
154 //dpm($user, "Local user " . theme('username', $user));
155
156 if ($GLOBALS['fb_connect_apikey'])
157 drupal_set_message("fb_connect_apikey = " . $GLOBALS['fb_connect_apikey']);
158
159 dpm($_COOKIE, 'cookie');
160 dpm($_REQUEST, "Request");
161 //dpm($fb_app, "fb_app");
162 drupal_set_message("session_id returns " . session_id());
163 //dpm($_SESSION, "session:");
164
165 return "This is the facebook debug page.";
166 }
167
168
169 /**
170 * A page which tests function which work with facebook user ids
171 */
172 function fb_devel_fbu_page($fbu = NULL) {
173 if ($fbu) {
174 $output = "<p>Debug info about facebook id $fbu:</p>\n";
175 $friends = fb_get_friends($fbu);
176 //dpm($friends, "fb_get_friends($fbu) returned");
177 $items = array();
178 foreach ($friends as $_fbu) {
179 $items[] = l($_fbu, "fb/devel/fbu/{$_fbu}");
180 }
181 if (count($items)) {
182 $output .= "\n<p>Known friends:<ul><li>";
183 $output .= implode("</li>\n <li>", $items);
184 $output .= "</li></ul></p>\n\n";
185 }
186
187
188
189 $local_friends = fb_user_get_local_friends($fbu);
190
191 $items = array();
192 foreach ($local_friends as $uid) {
193 $account = user_load(array('uid' => $uid));
194 $items[] = theme('username', $account);
195 }
196 if (count($items)) {
197 $output .= "\n<p>Local friends:<ul><li>";
198 $output .= implode("</li>\n <li>", $items);
199 $output .= "</li></ul></p>\n\n";
200 }
201 }
202 else
203 drupal_set_message("You have to specify a facebook user id.", 'error');
204 return $output;
205 }
206
207 function fb_devel_block($op = 'list', $delta = 0, $edit = array()) {
208 if ($op == 'list') {
209 $items[0]['info'] = t('Facebook Devel Page Info');
210 return $items;
211 }
212 else if ($op == 'view') {
213 return array('subject' => t('Facebook Devel Info'),
214 'content' => drupal_get_form('fb_devel_info'));
215 }
216 }
217
218 function fb_devel_info() {
219 global $fb, $fb_app;
220 global $user;
221 global $base_url;
222 global $base_path;
223
224 $info = array();
225 $nid = fb_settings(FB_SETTINGS_APP_NID);
226
227 if ($fb) {
228 if ($fb->in_fb_canvas())
229 $info['Page Status'] = t('Rendering FBML canvas page.');
230 else if ($fb->in_frame()) {
231 $info['Page Status'] = t('Rendering iframe.');
232 }
233 else if ($nid) {
234 // Followed a link from within an iframe.
235 $info['Page Status'] = t('Global fb instance is set (followed link in iframe, or handling a form).');
236 $info['fb'] = $fb;
237 }
238 else {
239 $info['Page Status'] = t('Connected via Facebook Connect');
240 }
241
242 $info['fb_facebook_user'] = fb_facebook_user();
243 $fbu = fb_facebook_user();
244 if (fb_api_check_session($fb)) {
245 // users_isAppUser() may be unreliable!
246 $info['users_isAppUser'] = $fb->api_client->users_isAppUser();
247 $info["users_isAppUser($fbu)"] = $fb->api_client->users_isAppUser($uid);
248 }
249 else {
250 $info['fb_api_check_session()'] = t('Returned FALSE');
251 }
252 }
253 else {
254 $info['Page Status'] = t('Not a canvas page.');
255 }
256 // Use theme_username() rather than theme('username') because we want link to local user, even when FBML is enabled
257 $info['local user'] = theme_username($user);
258 $info['fb_get_fbu'] = fb_get_fbu($user->uid);
259 $info['base_url'] = $base_url;
260 $info['base_path'] = $base_path;
261 $info['url() returns'] = url();
262 $info['$_REQUEST[q] is'] = $_REQUEST['q'];
263 $info['arg(0) is'] = arg(0);
264 $info['arg(1) is'] = arg(1);
265 $info['session_id'] = session_id();
266 $info['session_name'] = session_name();
267
268 $info['request'] = $_REQUEST;
269 $info['fb_app'] = $fb_app;
270 $info['session'] = $_SESSION;
271 $info['cookies'] = $_COOKIE;
272
273 if ($fb) {
274 $info['api_client'] = $fb->api_client;
275 }
276
277 $form = array();
278 foreach ($info as $key => $val) {
279 if (is_string($val) || is_numeric($val) || !$val) {
280 $form[] = array('#value' => t($key) . ' = ' . $val,
281 '#weight' => count($form),
282 '#suffix' => '<br/>',
283 );
284
285 }
286 else {
287 $form[] = array('#type' => 'fieldset',
288 '#title' => t($key),
289 '#collapsible' => TRUE,
290 '#collapsed' => TRUE,
291 '#weight' => count($form),
292 'value' => array('#prefix' => '<pre>',
293 '#suffix' => '</pre>',
294 '#type' => 'markup',
295 '#value' => dprint_r($val, 1)),
296 );
297 }
298 }
299 // It's not really a form, but we like collapsible fieldsets
300 return $form;
301 }
302
303 function fb_devel_user($op, &$edit, &$account, $category = NULL) {
304 if ($op == 'view') {
305 if (user_access('administer users') && user_access('access devel information')) {
306 $account->content['fb_devel'] = array(
307 '#type' => 'fieldset',
308 '#title' => t('Drupal for Facebook Devel'),
309 '#description' => t('Information from facebook API, visible only to administrators.'),
310 '#collapsible' => TRUE,
311 '#collapsed' => TRUE,
312 '#weight' => 99,
313 );
314 foreach (fb_get_all_apps() as $app) {
315 $account->content['fb_devel'][$app->label] = array(
316 '#type' => 'fieldset',
317 '#title' => $app->title,
318 );
319 if ($fbu = fb_get_fbu($account, $app)) {
320 $fb = fb_api_init($app);
321 $info = fb_users_getInfo(array($fbu), $fb, TRUE);
322 $account->content['fb_devel'][$app->label]['info'] = array(
323 '#type' => 'markup',
324 '#value' => dprint_r($info[0], 1),
325 );
326 }
327 else {
328 $account->content['fb_devel'][$app->label]['info'] = array(
329 '#type' => 'markup',
330 '#value' => t('No mapping to a facebook account.'),
331 );
332 }
333 }
334 }
335 }
336 }
337
338 ?>

  ViewVC Help
Powered by ViewVC 1.1.2