View source
<?php
define('FB_CONNECT_PATH_ADMIN', FB_PATH_ADMIN_CONFIG . '/fb_connect');
function fb_connect_menu() {
$items = array();
$items['fb/connect'] = array(
'title' => 'Facebook Connect',
'page callback' => 'drupal_not_found',
'options' => array(
'alter' => TRUE,
'html' => TRUE,
'attributes' => array(
'class' => array(
'fb',
),
),
),
'access callback' => TRUE,
);
$items[FB_CONNECT_PATH_ADMIN] = array(
'title' => 'Connect',
'description' => 'Site-wide connection to Facebook.com.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'fb_connect_admin_form',
),
'access arguments' => array(
FB_PERM_ADMINISTER,
),
'file' => 'fb_connect.admin.inc',
'file path' => drupal_get_path('module', 'fb_connect'),
);
return $items;
}
function fb_connect_translated_menu_link_alter(&$item) {
if ($item['link_path'] == 'fb/connect') {
if (arg(0) == 'admin' && arg(2) == 'menu') {
}
else {
$img_file = drupal_get_path('module', 'fb') . '/images/f_logo.png';
$img_src = url($img_file, array(
'fb_url_alter' => FALSE,
));
if ($token = fb_user_token()) {
try {
$me = fb_graph('me', $token);
$item['href'] = $me['link'];
$item['title'] = t('<img class="fb_logo" src="!img_src" /> %name', array(
'%name' => $me['name'],
'!img_src' => $img_src,
));
} catch (Exception $e) {
$item['href'] = fb_client_auth_url();
$item['title'] = t('<img class="fb_logo" src="!img_src" /> !title', array(
'!title' => $item['title'],
'!img_src' => $img_src,
));
}
}
else {
$item['href'] = fb_client_auth_url();
if (empty($item['href'])) {
if (user_access(FB_PERM_ADMINISTER)) {
$item['title'] = t('<em>Facebook Connect</em>');
$item['href'] = FB_CONNECT_PATH_ADMIN;
}
else {
$item['hidden'] = TRUE;
}
}
else {
$item['title'] = t('<img class="fb_logo" src="!img_src" /> !title', array(
'!title' => $item['title'],
'!img_src' => $img_src,
));
}
}
}
$item['localized_options']['attributes']['class'][] = 'fb';
}
}
function fb_connect_block_info() {
$items = array();
$items['login_primary'] = array(
'info' => t('Facebook Connect Login'),
);
return $items;
}
function fb_connect_block_configure($delta = '') {
$orig_defaults = _fb_connect_block_login_defaults();
$defaults = variable_get('fb_connect_block_' . $delta, $orig_defaults);
$form['config'] = array(
'#tree' => TRUE,
);
foreach (array(
'anon_not_connected',
'user_not_connected',
'connected',
) as $key) {
$form['config'][$key] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['config'][$key]['title'] = array(
'#type' => 'textfield',
'#title' => t('Default title'),
'#default_value' => $defaults[$key]['title'],
);
$textformat = isset($defaults[$key]['body']['format']) ? $defaults[$key]['body']['format'] : 'full_html';
$form['config'][$key]['body'] = array(
'#type' => 'text_format',
'#title' => t('Body'),
'#base_type' => 'textarea',
'#format' => $textformat,
'#default_value' => $defaults[$key]['body']['value'],
);
}
$form['config'][] = array(
'#markup' => "<p><strong>Be sure to select a format that allows XFBML tags!</strong> (That is, use <em>Full HTML</em> or <em>PHP code</em> (PHP Filter module must be enabled), rather than <em>Filtered HTML</em>.)</p>",
'#weight' => -10,
);
$form['config']['anon_not_connected']['#title'] = t('Anonymous user, not connected');
$form['config']['anon_not_connected']['#description'] = t('Settings when local user is Anonymous, and not connected to Facebook. Typically a new account will be created when the user clicks the connect button.');
$form['config']['anon_not_connected']['body']['#description'] = t('Suggested markup: %default .', array(
'%default' => $orig_defaults['anon_not_connected']['body']['value'],
));
$form['config']['user_not_connected']['#title'] = t('Registered user, not connected');
$form['config']['user_not_connected']['#description'] = t('Settings when local user is registered, and not connected to Facebook. Typically the facebook id will be linked to the local id after the user clicks the connect button.');
$form['config']['user_not_connected']['body']['#description'] = t('Suggested markup: %default .', array(
'%default' => $orig_defaults['user_not_connected']['body']['value'],
));
$form['config']['connected']['#title'] = t('Connected user');
$form['config']['connected']['#description'] = t('Settings when local user is connected to Facebook. Use <a target="_blank" href="!xfbml_url">XFBML</a> such as <fb:name uid=loggedinuser></fb:name> or <fb:profile-pic uid=loggedinuser></fb:profile-pic> only if you are using facebook\'s javascript SDK.', array(
'!xfbml_url' => 'http://wiki.developers.facebook.com/index.php/XFBML',
));
$form['config']['connected']['body']['#description'] = t('Note that <strong>!fbu</strong> will be replaced with the user\'s facebook id.<br/>Suggestion: %default .', array(
'%default' => $orig_defaults['connected']['body']['value'],
));
return $form;
}
function fb_connect_block_save($delta = '', $edit = array()) {
variable_set('fb_connect_block_' . $delta, $edit['config']);
}
function fb_connect_block_view($delta = '') {
if (TRUE) {
if (strpos($delta, 'login_') === 0) {
$fba = substr($delta, 6);
if ($fba == 'primary') {
$app = fb_get_app();
}
else {
return NULL;
}
if (!empty($app)) {
if (!empty($_SESSION['fb'][$app['fba']])) {
$sdata = $_SESSION['fb'][$app['fba']];
}
$defaults = variable_get('fb_connect_block_' . $delta, _fb_connect_block_login_defaults());
$subject_connected = $defaults['connected']['title'];
$content_connected = $defaults['connected']['body']['value'];
if (user_is_anonymous()) {
$subject = $defaults['anon_not_connected']['title'];
$content = $defaults['anon_not_connected']['body']['value'];
$format = $defaults['anon_not_connected']['body']['format'];
}
else {
$subject = $defaults['user_not_connected']['title'];
$content = $defaults['user_not_connected']['body']['value'];
$format = $defaults['user_not_connected']['body']['format'];
}
$perms = array();
drupal_alter('fb_required_perms', $perms);
$content = str_replace('!perms', implode(',', $perms), $content);
$subject = check_plain($subject);
if ($format) {
$content = check_markup($content, $format, '', FALSE);
}
$subject_connected = check_plain($subject_connected);
if ($format_connected = $defaults['connected']['body']['format']) {
$content_connected = check_markup($content_connected, $format_connected, FALSE);
}
$block = array(
'subject' => theme('fb_markup', array(
'not_connected' => $subject,
'connected' => $subject_connected,
)),
'content' => theme('fb_markup', array(
'not_connected' => $content,
'connected' => $content_connected,
)),
);
return $block;
}
}
}
}
function _fb_connect_block_login_defaults() {
return array(
'anon_not_connected' => array(
'title' => t('Facebook Connect'),
'body' => array(
'value' => theme('fb_login_button'),
'format' => NULL,
),
),
'user_not_connected' => array(
'title' => t('Facebook Connect'),
'body' => array(
'value' => theme('fb_login_button'),
'format' => NULL,
),
),
'connected' => array(
'title' => t('Facebook Connect'),
'body' => array(
'value' => '<div class="fb_replace"><!--- Connected as !name. </div><img src=//graph.facebook.com/!fbu/picture /> ---> </div>',
'format' => NULL,
),
),
);
}