Index: disqus.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/disqus/Attic/disqus.install,v retrieving revision 1.1.2.4.2.2 diff -u -r1.1.2.4.2.2 disqus.install --- disqus.install 19 Mar 2010 11:02:54 -0000 1.1.2.4.2.2 +++ disqus.install 4 Jan 2011 14:59:39 -0000 @@ -7,6 +7,39 @@ */ /** + * Implementation of hook_schema(). + */ +function disqus_schema() { + $schema = array(); + $schema['disqus'] = array( + 'fields' => array( + 'did' => array( + 'type' => 'serial', + 'not null' => TRUE, + ), + 'nid' => array( + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), + 'status' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), + ), + 'primary key' => array('did'), + 'indexes' => array( + 'nid' => array('nid'), + 'status' => array('status'), + ), + ); + return $schema; +} + +/** * Implements hook_uninstall(). */ function disqus_uninstall() { @@ -20,3 +53,10 @@ function disqus_update_7000() { // Nothing. } + +/** + * Installs the new schema to support toggling per node + */ +function disqus_update_7001() { + drupal_install_schema('disqus'); +} Index: disqus.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/disqus/Attic/disqus.module,v retrieving revision 1.1.2.23.2.7 diff -u -r1.1.2.23.2.7 disqus.module --- disqus.module 4 Jan 2011 14:42:18 -0000 1.1.2.23.2.7 +++ disqus.module 4 Jan 2011 14:59:40 -0000 @@ -55,6 +55,34 @@ } /** + * Implements hook_element_info(). + */ +function disqus_element_info() { + $types['disqus'] = array( + '#disqus' => array(), + '#theme_wrappers' => array('disqus_noscript', 'container'), + '#attributes' => array('id' => 'disqus_thread'), + '#post_render' => array('disqus_element_post_render'), + ); + return $types; +} + +/** + * Post render function of the Disqus element to inject the footer JavaScript. + */ +function disqus_element_post_render($children, &$element) { + // Inject the footer script at the bottom of the page using #attached. + $script = theme('disqus_footer', $element); + $element['#attached']['js'][] = array( + 'type' => 'inline', + 'scope' => 'footer', + 'weight' => JS_THEME, + 'data' => $script, + ); + return $children; +} + +/** * Implements hook_node_load(). */ function disqus_node_load($nodes, $types) { @@ -70,6 +98,10 @@ // Save the data to the node object. $node->disqus = array('domain' => $domain); + // Apply the Disqus status to the node. + $status = db_query("SELECT status FROM {disqus} WHERE nid = :nid", array(':nid' => $node->nid))->fetchObject(); + $node->disqus['status'] = isset($status->status) ? (bool)$status->status : TRUE; + // Build the absolute URL without the alias for the disqus_url flag. $node->disqus['url'] = url("node/$node->nid", array( 'alias' => TRUE, @@ -102,38 +134,10 @@ } /** - * Implements hook_element_info(). - */ -function disqus_element_info() { - $types['disqus'] = array( - '#disqus' => array(), - '#theme_wrappers' => array('disqus_noscript', 'container'), - '#attributes' => array('id' => 'disqus_thread'), - '#post_render' => array('disqus_element_post_render'), - ); - return $types; -} - -/** - * Post render function of the Disqus element to inject the footer JavaScript. - */ -function disqus_element_post_render($children, &$element) { - // Inject the footer script at the bottom of the page using #attached. - $script = theme('disqus_footer', $element); - $element['#attached']['js'][] = array( - 'type' => 'inline', - 'scope' => 'footer', - 'weight' => JS_THEME, - 'data' => $script, - ); - return $children; -} - -/** * Implements hook_node_view(). */ function disqus_node_view($node, $view_mode) { - if (isset($node->disqus) && user_access('view disqus comments')) { + if (isset($node->disqus) && user_access('view disqus comments') && $node->disqus['status'] == 1) { switch ($view_mode) { case 'full': // Inject Disqus into the node object. @@ -179,6 +183,36 @@ } /** + * Implements hook_note_delete(). + */ +function disqus_node_delete($node) { + db_delete('disqus')->condition('nid', $node->nid)->execute(); +} + +/** + * Implements hook_node_insert(). + */ +function disqus_node_insert($node) { + $data = array( + 'nid' => $node->nid, + 'status' => $node->disqus_status, + ); + drupal_write_record('disqus', $data); +} + +/** + * Implements hook_node_update(). + */ +function disqus_node_update($node) { + // Write the status to the table, taking the node ID as the update key. + $data = array( + 'nid' => $node->nid, + 'status' => $node->disqus_status, + ); + drupal_write_record('disqus', $data, 'nid'); +} + +/** * Implements hook_user_load(). */ function disqus_user_load($users) { @@ -437,6 +471,33 @@ } /** + * Implementation of hook_form_alter(). + */ +function disqus_form_alter(&$form, $form_state, $form_id) { + if (!empty($form['#node_edit_form'])) { + $types = variable_get('disqus_nodetypes', array()); + // Add the Disqus settings into the Comment settings fieldset if it exists. + if (!isset($form['comment_settings'])) { + $form['comment_settings'] = array( + '#type' => 'fieldset', + '#access' => user_access('view disqus comments'), + '#title' => t('Comment settings'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#group' => 'additional_settings', + '#weight' => 30, + ); + } + $node = $form['#node']; + $form['comment_settings']['disqus_status'] = array( + '#type' => 'checkbox', + '#title' => t('Enable Disqus comments'), + '#default_value' => isset($node->disqus['status']) ? $node->disqus['status'] : TRUE, + ); + } +} + +/** * Implements hook_theme(). */ function disqus_theme() {