In version 1.6 the switch to node/# identifiers from aliases happened. As a result the comment counter for Disqus now links only to node/# because the JS counts on the href to be it's identifier. All fine and dandy except we have aliases for a reason and even the comment count link should respect that. So attached is a patch that pulls the alias from a "rel" attribute and makes sure the link gets the appropriate path.

NOTE: I think it's *alright* to put this in the rel attribute. Any opinions are welcome of course.

CommentFileSizeAuthor
#1 count_alias.patch1018 bytesbobooon

Comments

bobooon’s picture

StatusFileSize
new1018 bytes
benklocek’s picture

1+ For this patch to make it in to the next rev.

I can't use the comment counts because it links to the node (another page load and the wrong url !)

el7cosmos’s picture

Status: Needs review » Needs work

i apply the patch...but still, links goes to node/* not the alias

benklocek’s picture

I'm getting the same issue as @el7cosmos.

'rel' => url($path), is getting set to node/#, so the jquery trick is just replacing node/# with node/#.

lelezard’s picture

I have the same issue before and after applying the patch

apemantus’s picture

Version: 6.x-1.6 » 6.x-1.7

I just came across this issue in the latest version. I fixed it a simialr way to the above: the module outputs the aliased path as the href link, sticks the node path in the rel attribute and uses that in the JS. My patch making skills are rubbish as I'm using Windows and haven't worked out how to fix the line-endings, but below are commented changes.

In disqus.module

function theme_disqus_comments_num($domain, $path = NULL, $text = NULL) {
  static $added = FALSE;
  if ($added == FALSE) {
    drupal_add_js(drupal_get_path('module', 'disqus') .'/disqus.js');
    drupal_add_js(array('disqusCommentDomain' => $domain), 'setting');
    $added = TRUE;
  }
  $text = empty($text) ? t('Comments') : $text;
  if (isset($path)) {
    return l($text, $path, array(
      'attributes' => array(
        'class' => 'comments',
        'title' => t('Jump to the comments of this posting.'),
        'rel' => url($path,array('alias'=>TRUE,'absolute'=>TRUE)), /* Creates rel */
      ),
      'alias' => FALSE,  /* Set alias to FALSE not TRUE */
      'absolute' => TRUE,
      'fragment' => 'disqus_thread',
    ));
  }
}

In disqus.js:

    jQuery("a[href$='#disqus_thread']").each(function(i) {
      query += 'url' + i + '=' + encodeURIComponent($(this).attr('rel')) + '&'; //use rel rather than href
    });
ztdgz’s picture

This is still a problem in 6.x-1.9.

However, I have noticed in the release notes / changes since 6.x-1.8 the following:

Use the path alias for the disqus_url variable. Thanks Wim Leers and Tyler Hayes.

Perhaps that fix didn't make it through?
-- edit --
Just looking at the diff for the change noted above:
http://drupalcode.org/project/disqus.git/commitdiff/b0bfe6476f48827edccb...

The change doesn't seem to fix the issue to me...?
-- /edit --

Either way, I have still experienced the problem on 6.9-1.9 and tried a fix.

I have made a change to disqus.module which fixes the problem in 6.x-1.9.

Notes:

  1. I am not sure how this would work if the paths module is not enabled, so further changes may be required
  2. This change is different than the two posted in this thread
    • It does not require changes to the disqus.js file
    • The URL delivered from the server is correctly using the alias, and requires no in-browser post-processing with JS

/**
 * Implementation of hook_nodeapi().
 */
function disqus_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  // See if Disqus is active on this node.
  $types = variable_get('disqus_nodetypes', array());
  if (!empty($types[$node->type])) {
    switch ($op) {
      case 'presave':
        // For programmatic insertion of nodes via node_save.
        if (!isset($node->disqus['status'])) {
          $node->disqus['status'] = TRUE;
        }
        break;
      case 'load':
          // Check which Disqus domain to use.
          $domain = variable_get('disqus_domain', '');
          if (!empty($domain)) {
            // Save the data to the node object.

            $node->disqus = array('domain' => $domain);

            // Apply the Disqus status to the node.
            $status = db_fetch_object(db_query("SELECT status FROM {disqus} WHERE nid = %d", $node->nid));
            $node->disqus['status'] = isset($status->status) ? (bool)$status->status : TRUE;
/* begin change */
            if(!empty($node->path)) {
              // Build the absolute URL WITH the alias for the disqus_url flag.
              $node->disqus['url'] = url("$node->path", array(
                'absolute' => TRUE,
              ));
            } else {
              // Build the absolute URL without the alias for the disqus_url flag.
              $node->disqus['url'] = url("node/$node->nid", array(
                'absolute' => TRUE,
              ));
            }
/* end change */
            // Build the title.
            $node->disqus['title'] = check_plain($node->title);

            // Provide the identifier.
            $node->disqus['identifier'] = 'node/' . $node->nid;

            // The developer flag must always be set when the node is unpublished.
            if ($node->status == 0) {
              $node->disqus['developer'] = 1;
            }
            elseif ($developer = variable_get('disqus_developer', FALSE)) {
              $node->disqus['developer'] = intval($developer);
            }
          }
          break;
      case 'delete':
        db_query('DELETE FROM {disqus} WHERE nid = %d', $node->nid);
        break;
      case 'insert':
        $data = array(
          'nid' => $node->nid,
          'status' => isset($node->disqus['status']) ? $node->disqus['status'] : TRUE,
        );
        drupal_write_record('disqus', $data);
        break;
      case 'update':
        // Write the status to the table, taking the node ID as the update key.
        db_query('DELETE FROM {disqus} WHERE nid = %d', $node->nid);
        $data = array(
          'nid' => $node->nid,
          'status' => isset($node->disqus['status']) ? $node->disqus['status'] : TRUE,
        );
        drupal_write_record('disqus', $data);
        break;
      case 'view':
        // See if we are to display Disqus in the current context.
        if (!$a3 && $a4 && isset($node->disqus) && user_access('view disqus comments') && $node->disqus['status'] == 1) {
          // Inject Disqus into the node object.
          switch (variable_get('disqus_location', 'content_area')) {
            case 'content_area':
              // Inject into the node content.
              $node->content['disqus'] = array(
                '#value' => theme('disqus_comments', $node->disqus),
                '#weight' => variable_get('disqus_weight', 50),
              );
              break;
            case 'variable':
              // Inject it into a variable.
              $node->disqus_comments = theme('disqus_comments', $node->disqus);
              break;
          }
        }
        break;
    }
  }
}
udijw’s picture

Hi,
thanks for sharing this. I did a similar change based on your change. I am not really sure what the change you placed did not work (and I probably did a terrible job of coding this). However, I thought this may be useful for others who are having a similar issue that was not solved by ztdgz on #7.
I also changed disqus.module.
I think that the right change may be keeping the change at #7 and having disqus_link poll it, but since Iwas not sure, I wanted to keep changes to minimum.

function disqus_link($type, $node = NULL, $teaser = FALSE) {
  $links = array();
  // Only show the Disqus links on node teasers.
  if ($type == 'node' && /*$teaser == TRUE && */$node->disqus['status'] == 1) {
    // Make sure the context is correct.
    $types = variable_get('disqus_nodetypes', array());
    $domain = variable_get('disqus_domain', NULL);
    if (!empty($types[$node->type]) && user_access('view disqus comments') && !empty($domain)) {

/*removed
      // Construct the path and inject it into the links area.
      $path = url("node/$node->nid", array(
        'alias' => TRUE,
        'absolute' => TRUE,
      ));
*/

/* begin change */
            if(!empty($node->path)) {
              // Build the absolute URL WITH the alias for the disqus_url flag.
      $path = url("$node->path", array(
        'alias' => TRUE,
        'absolute' => TRUE,
      ));
            } else {
              // Build the absolute URL without the alias for the disqus_url flag.
      $path = url("node/$node->nid", array(
        'alias' => TRUE,
        'absolute' => TRUE,
      ));
            }
/* end change */


      $links['disqus_comments'] = array(
        'title' => theme('disqus_comments_num', $domain, $path, t('Comments'), "node/$node->nid"),
        'html' => TRUE,
      );
    }
  }
  return $links;
}