You are here

function bugherd_init in BugHerd 6

Same name and namespace in other branches
  1. 7 bugherd.module \bugherd_init()

Implements hook_init().

File

./bugherd.module, line 11
BugHerd module functions.

Code

function bugherd_init() {
  if (!user_access('access bugherd')) {
    return;
  }
  $disable_on_admin = variable_get('bugherd_disable_on_admin', FALSE);
  if (arg(0) == 'admin' && $disable_on_admin) {
    return;
  }
  $api_key = variable_get('bugherd_api_key', FALSE);
  if (!$api_key) {
    $link = l(t('Configure BugHerd'), 'admin/settings/bugherd');
    drupal_set_message(t('BugHerd API key not set. !configure.', array(
      '!configure' => $link,
    )), 'error', FALSE);
    return;
  }
  $api_key = check_plain($api_key);
  $script = <<<SCRIPT
  var _bugHerdAPIKey = '{<span class="php-variable">$api_key</span>}';
  (function (d, t) {
    var bh = d.createElement(t), s = d.getElementsByTagName(t)[0];
    bh.type = 'text/javascript';
    bh.src = '//www.bugherd.com/sidebarv2.js?apikey={<span class="php-variable">$api_key</span>}';
    s.parentNode.insertBefore(bh, s);
  })(document, 'script');

SCRIPT;
  drupal_add_js($script, 'inline', 'footer');
}