You are here

function disqus_link in Disqus 5

Same name and namespace in other branches
  1. 6 disqus.module \disqus_link()

Implementation of hook_link().

File

./disqus.module, line 142

Code

function disqus_link($type, $node = NULL, $teaser = FALSE) {
  global $base_url;
  $links = array();
  if ($type == 'node' && $teaser == TRUE) {
    $types = variable_get('disqus_nodetypes', array());
    if (!empty($types[$node->type]) && user_access('view disqus comments')) {
      $links['disqus_comments'] = array(
        'title' => t('Comments'),
        'href' => $base_url . '/node/' . $node->nid . '#disqus_thread',
        'attributes' => array(
          'title' => t('Jump to the comments of this posting.'),
        ),
      );
      static $disqus_js_added = FALSE;
      if ($disqus_js_added === FALSE) {
        $disqus_js_added = TRUE;
        $domain = variable_get('disqus_domain', '');
        $disqus_js = <<<EOT
//<[CDATA[
(function() {
    var links = document.getElementsByTagName('a');
    var query = '?';
    for(var i = 0; i < links.length; i++) {
      if(links[i].href.indexOf('#disqus_thread') >= 0) {
        query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&';
      }
    }
    document.write('<script type="text/javascript" src="http://disqus.com/forums/{<span class="php-variable">$domain</span>}/get_num_replies.js' + query + '"></' + 'script>');
  })();
//]]>
EOT;
        drupal_add_js($disqus_js, 'inline', 'footer');
      }
    }
  }
  return $links;
}