function disqus_node_update in Disqus 7
Implements hook_node_update().
File
- ./
disqus.module, line 388 - The Disqus Drupal module.
Code
function disqus_node_update($node) {
// Update the thread information on disqus if required.
if (isset($node->disqus) && variable_get('disqus_api_update', FALSE) && ($node->disqus['title'] != $node->original->disqus['title'] || $node->disqus['url'] != $node->original->disqus['url'])) {
$disqus = disqus_api();
if ($disqus) {
try {
// Load the thread data from disqus. Passing thread is required to allow the thread:ident call to work correctly. There is a pull request to fix this issue.
$thread = $disqus->threads
->details(array(
'forum' => $node->disqus['domain'],
'thread:ident' => $node->disqus['identifier'],
'thread' => '1',
'version' => '3.0',
));
} catch (Exception $exception) {
drupal_set_message(t('There was an error loading the thread details from Disqus.'), 'error');
watchdog('disqus', 'Error loading thread details for node @nid. Check your API keys.', array(
'@nid' => $node->nid,
), WATCHDOG_ERROR, 'admin/config/services/disqus');
}
if (isset($thread->id)) {
try {
$disqus->threads
->update(array(
'access_token' => variable_get('disqus_useraccesstoken', ''),
'thread' => $thread->id,
'forum' => $node->disqus['domain'],
'title' => $node->disqus['title'],
'url' => $node->disqus['url'],
'version' => '3.0',
));
} catch (Exception $exception) {
drupal_set_message(t('There was an error updating the thread details on Disqus.'), 'error');
watchdog('disqus', 'Error updating thread details for node @nid. Check your user access token.', array(
'@nid' => $node->nid,
), WATCHDOG_ERROR, 'admin/config/services/disqus');
}
}
}
}
// Finish the update process.
if (isset($node->disqus_status) && isset($node->disqus['status']) && $node->disqus_status != $node->disqus['status']) {
disqus_node_insert($node);
}
}