by Dave Cohen: better JS handling when FB does not callback getLoginStatus
[project/fb.git] / fb.theme.inc
1 <?php
2 /**
3 * @file
4 * Implementation of theme functions.
5 *
6 * XFBML markup will only work on canvas pages and facebook connect pages.
7 */
8
9 // @TODO theme function now take only one parameter, an associative array.
10
11 function theme_fb_login_button($params) {
12 $text = isset($params['text']) ? $params['text'] : '';
13 $options = isset($params['options']) ? $params['options'] : array();
14
15 // Facebook used to provide default text. No longer, apparently.
16 if (!$text) {
17 $text = t('Connect');
18 }
19
20 // Merge in defaults
21 $options += array(
22 'attributes' => array(),
23 );
24 if (!isset($options['attributes']['scope'])) {
25 // Which permissions to prompt for?
26 $perms = array();
27 drupal_alter('fb_required_perms', $perms);
28 if (count($perms)) {
29 $options['attributes']['scope'] = implode(',', $perms);
30 }
31 }
32
33
34 $button = '<fb:login-button ' . drupal_attributes($options['attributes']) . '>' .
35 ($text ? '<fb:intl>' . check_plain($text) . '</fb:intl>' : '') . '</fb:login-button>';
36
37 return $button;
38 }
39
40
41 function theme_fb_username($params) {
42 $fbu = $params['fbu'];
43 $object = $params['account'];
44 $orig = $params['orig'];
45 if (!$fbu || arg(0) == 'admin') {
46 return $orig;
47 }
48
49 $wrap_pre = "<span class=fb_hide>$orig</span><span class=fb_show style='display:none'>";
50 $wrap_post = "</span>\n";
51 $ifcantsee = '';
52 if ($object->uid && user_access('access user profiles')) {
53 // Provide link if local account.
54 $wrap_pre = $wrap_pre . '<a href="' . url('user/' . $object->uid) . '">';
55 $wrap_post = '</a>' . $wrap_post;
56 $ifcantsee = 'ifcantsee="' . addslashes(check_plain($object->name)) . '"';
57 }
58
59 $fbml = "<fb:name linked=false useyou=false uid=\"$fbu\" $ifcantsee></fb:name>"; $output = $wrap_pre . $fbml . $wrap_post;
60
61 return $output;
62 }
63
64 function theme_fb_user_picture($params) {
65 if (!$params['fbu'])
66 return $params['orig'];
67
68 $fbu = $params['fbu'];
69 $object = $params['account'];
70 $orig = $params['orig'];
71
72 // http://developers.facebook.com/docs/reference/fbml/profile-pic
73 $fbml = "<fb:profile-pic linked=false uid=\"$fbu\"></fb:profile-pic>";
74 $wrap_pre = '<span class=fb_hide>' . $orig . '</span><span class="fb_show" style="display:none;"><div class="picture">';
75 $wrap_post = '</div></span>';
76 if ($object->uid && user_access('access user profiles')) {
77 // Provide link to local account.
78 $wrap_pre = $wrap_pre . '<a href="' . url('user/' . $object->uid) . '">';
79 $wrap_post = '</a>' . $wrap_post;
80 }
81 return $wrap_pre . $fbml . $wrap_post;
82 }
83
84
85 function theme_fb_fbml_popup($elem) {
86 // Hide this markup until javascript shows it.
87 $t = '<div class="fb_fbml_popup_wrap" style="display:none;" ' . ">\n";
88
89 $t .= '<a href="#" title="' . check_plain($elem['#title']) . '" ' .
90 (isset($elem['#link_attributes']) ? drupal_attributes($elem['#link_attributes']) : '') .
91 '>' . check_plain($elem['#link_text']) . '</a>';
92 $t .= '<div class="fb_fbml_popup" ' . drupal_attributes($elem['#attributes']) . '>';
93 $t .= $elem['#children'];
94 $t .= "</div></div>\n";
95 return $t;
96 }