? toggle-d7.patch 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 -p -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 26 Nov 2010 18:50:21 -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,11 @@ function disqus_uninstall() { 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.5 diff -u -p -r1.1.2.23.2.5 disqus.module --- disqus.module 9 Sep 2010 19:06:14 -0000 1.1.2.23.2.5 +++ disqus.module 26 Nov 2010 18:50:22 -0000 @@ -55,6 +55,33 @@ function disqus_menu() { } /** + * 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_node_load(). */ function disqus_node_load($nodes, $types) { @@ -70,6 +97,11 @@ function disqus_node_load($nodes, $types // 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,55 +134,57 @@ function disqus_node_load($nodes, $types } /** - * Implements hook_elements(). + * Implements hook_node_delete(). */ -function disqus_element_info() { - $types['disqus'] = array( - '#disqus' => array(), - '#theme_wrappers' => array('disqus_noscript', 'container'), - '#id' => 'disqus_thread', - '#post_render' => array('disqus_element_post_render'), +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, ); - return $types; + drupal_write_record('disqus', $data); } /** - * Post render function of the Disqus element to inject the footer JavaScript. + * Implements hook_node_update(). */ -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, +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, ); - return $children; + drupal_write_record('disqus', $data, 'nid'); } /** * 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. - switch (variable_get('disqus_location', 'content_area')) { - case 'content_area': - // Inject into the node content. - $node->content['disqus'] = array( - '#type' => 'disqus', - '#disqus' => $node->disqus, - '#weight' => variable_get('disqus_weight', 50), - ); - break; - case 'variable': + // 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( + '#type' => 'disqus', + '#disqus' => $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; + } break; case 'teaser': // Display the Disqus link. @@ -179,6 +213,34 @@ function disqus_node_view($node, $view_m } /** + * Implements hook_elements(). + */ +function disqus_element_info() { + $types['disqus'] = array( + '#disqus' => array(), + '#theme_wrappers' => array('disqus_noscript', 'container'), + '#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_user_load(). */ function disqus_user_load($users) {