function disqus_footer in Disqus 6
Same name and namespace in other branches
- 5 disqus.module \disqus_footer()
Implementation of hook_footer().
Parameters
$options: The options to pass off to the Disqus comments.
1 call to disqus_footer()
- theme_disqus_comments in ./
disqus.module - Renders the JavaScript to display the Disqus thread for the current page.
File
- ./
disqus.module, line 417
Code
function disqus_footer($main = 0, $options = NULL) {
// Adds the JavaScript required to constuct a Disqus thread.
static $added = FALSE;
if (!$added && isset($options)) {
$added = TRUE;
$domain = variable_get('disqus_domain', '');
if (!empty($domain)) {
// Add the Disqus Drupal behavior.
drupal_add_js(drupal_get_path('module', 'disqus') . '/disqus.js');
// Construct the Disqus settings.
$settings = array(
'url' => $options['url'],
'title' => $options['title'],
'identifier' => $options['identifier'],
'shortname' => $domain,
);
// Inject the developer flag if we are debugging.
if (isset($options['developer'])) {
$settings['developer'] = 1;
}
// See if we are to inject the user's name and email address.
global $user;
if (variable_get('disqus_inherit_login', TRUE) && $user->uid > 0) {
$settings['name'] = $user->name;
$settings['email'] = $user->mail;
}
// Provide alternate language support if desired.
if (variable_get('disqus_localization', FALSE)) {
global $language;
$settings['language'] = $language->language;
}
// Check if we are to provide Single Sign-On access.
if (variable_get('disqus_sso', FALSE)) {
$data = array();
// Inject the user data if it's available.
if ($user->uid > 0) {
$data['id'] = $user->uid;
$data['username'] = $user->name;
$data['email'] = $user->mail;
$data['url'] = url('user/' . $user->uid, array(
'absolute' => TRUE,
));
// Load the user's avatar.
$user_picture_default = variable_get('user_picture_default', '');
if (isset($user->picture) && !empty($user->picture)) {
$data['avatar'] = url($user->picture, array(
'absolute' => TRUE,
));
}
elseif (!empty($user_picture_default)) {
$data['avatar'] = url($user_picture_default, array(
'absolute' => TRUE,
));
}
}
// Give Disqus information about the site.
$settings['sso'] = array(
'name' => variable_get('site_name', t('Drupal')),
// The login window must be closed once the user logs in.
'url' => url('user/login', array(
'query' => array(
'destination' => 'disqus/closewindow',
),
)),
// The logout link must redirect back to the original page.
'logout' => url('logout', array(
'query' => array(
'destination' => $_GET['q'],
),
)),
'width' => 800,
'height' => 600,
);
if ($logo = theme_get_setting('logo')) {
$settings['sso']['button'] = $logo;
}
else {
$settings['sso']['button'] = url('misc/druplicon.png', array(
'absolute' => TRUE,
));
}
if ($favicon = theme_get_setting('favicon')) {
$settings['sso']['icon'] = $favicon;
}
// Encode the data to be sent off to Disqus.
$message = base64_encode(json_encode($data));
$timestamp = time();
$hmac = hash_hmac('sha1', "{$message} {$timestamp}", variable_get('disqus_secretkey', ''));
// Stick the authentication requirements and data in the settings.
$settings['remote_auth_s3'] = "{$message} {$hmac} {$timestamp}";
$settings['api_key'] = variable_get('disqus_publickey', '');
}
// Add the JavaScript.
drupal_add_js(array(
'disqus' => $settings,
), 'setting');
}
}
}