You are here

function _disqus_node_load in Disqus 7

Load Disqus details.

Parameters

array $nodes: An array of the nodes being loaded, keyed by nid.

2 calls to _disqus_node_load()
disqus_entitycache_node_load in ./disqus.module
Implements hook_entitycache_node_load().
disqus_node_load in ./disqus.module
Implements hook_node_load().

File

./disqus.module, line 228
The Disqus Drupal module.

Code

function _disqus_node_load($nodes) {

  // Make sure we only load Disqus on nodes of the desired types.
  $disqustypes = variable_get('disqus_nodetypes', array());

  // Check which Disqus domain to use.
  $domain = variable_get('disqus_domain', '');
  if (!empty($domain)) {

    // Get the Disqus status of each node.
    $statuses = db_query("SELECT nid, status FROM {disqus} WHERE nid IN (:nids)", array(
      ':nids' => array_keys($nodes),
    ))
      ->fetchAllAssoc('nid');

    // Load the default Disqus status for each content type.
    $disqus_status = variable_get('disqus_nodetypes_default', _disqus_node_types_options());

    // Load Disqus into the nodes.
    foreach ($nodes as &$node) {
      if (!empty($disqustypes[$node->type])) {

        // Save the data to the node object.
        $node->disqus = array(
          'domain' => $domain,
        );

        // Apply the Disqus status to the node.
        $disqus_default_status = !empty($disqus_status[$node->type]);
        $node->disqus['status'] = isset($statuses[$node->nid]->status) ? (bool) $statuses[$node->nid]->status : $disqus_default_status;

        // Build the absolute URL without the alias for the disqus_url flag.
        $node->disqus['url'] = url("node/{$node->nid}", array(
          'absolute' => TRUE,
        ));

        // Build the title.
        $node->disqus['title'] = check_plain(strip_tags($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'] = (int) $developer;
        }
      }
    }
  }
}