function disqus_nodeapi in Disqus 5
Same name and namespace in other branches
- 6 disqus.module \disqus_nodeapi()
Implementation of hook_nodeapi().
File
- ./
disqus.module, line 51
Code
function disqus_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'load':
// See if Disqus is active on this node.
$types = variable_get('disqus_nodetypes', array());
$arg2 = arg(2);
if (!empty($types[$node->type]) && empty($arg2) || $arg2 == 'view') {
// 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,
);
// Build the absolute URL without the alias for the disqus_url flag.
global $base_url;
$node->disqus['url'] = $base_url . '/node/' . $node->nid;
// Build the message excerpt.
$message = nl2br($node->teaser);
$message = str_replace("\r", ' ', $message);
$message = str_replace("\n", ' ', $message);
$message = strip_tags($message);
$node->disqus['message'] = check_plain($message);
// 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'] = intval($developer);
}
}
}
break;
case 'view':
// See if we are to display Disqus in the current context.
if (!$a3 && $a4 && isset($node->disqus)) {
if (user_access('view disqus comments') && variable_get('disqus_location', 'content_area') == 'content_area') {
// Inject the comments into the node content area.
$node->content['disqus'] = array(
'#value' => theme('disqus_comments', $node->disqus),
'#weight' => variable_get('disqus_weight', 50),
);
}
}
break;
}
}