Index: disqus.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/disqus/Attic/disqus.install,v retrieving revision 1.1.2.4 diff -u -p -r1.1.2.4 disqus.install --- disqus.install 27 Aug 2009 23:40:14 -0000 1.1.2.4 +++ disqus.install 26 Oct 2010 23:49:47 -0000 @@ -14,9 +14,51 @@ function disqus_uninstall() { variable_del('disqus_userapikey'); variable_del('disqus_nodetypes'); variable_del('disqus_developer'); + drupal_uninstall_schema('disqus'); } /** + * Implementation of hook_install(). + */ +function disqus_install() { + drupal_install_schema('disqus'); +} + +/** + * 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; +} + + +/** * Updates the paths on the Disqus side to use the straight node URLs instead of the aliases. */ function disqus_update_6000(&$sandbox = NULL) { @@ -81,7 +123,7 @@ function disqus_update_6000(&$sandbox = ), ); } - + // Setup the batch API. $sandbox['forum_api_key'] = $forum_api_key; $sandbox['progress'] = 0; @@ -137,3 +179,10 @@ function disqus_update_6000(&$sandbox = } return $ret; } + +/** + * Update to add the new schema. + */ +function disqus_update_6001(&$sandbox = NULL) { + drupal_install_schema('disqus'); +} Index: disqus.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/disqus/Attic/disqus.module,v retrieving revision 1.1.2.26 diff -u -p -r1.1.2.26 disqus.module --- disqus.module 2 Sep 2010 03:18:28 -0000 1.1.2.26 +++ disqus.module 26 Oct 2010 23:49:47 -0000 @@ -55,65 +55,110 @@ function disqus_menu() { * Implementation of hook_nodeapi(). */ 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()); - if (!empty($types[$node->type])) { - // 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. - $node->disqus['url'] = url("node/$node->nid", array( - 'alias' => TRUE, - 'absolute' => TRUE, - )); - - // 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($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; + // See if Disqus is active on this node. + $types = variable_get('disqus_nodetypes', array()); + if (!empty($types[$node->type])) { + switch ($op) { + case 'validate': + $node->disqus['status'] = $node->disqus_status; + unset($node->disqus_status); + break; + case 'load': + // 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); + + $count = db_result(db_query("SELECT count(nid) FROM {disqus} WHERE nid = %d", $node->nid)); + if ($count > 0) { + $node->disqus['status'] = db_fetch_array(db_query("SELECT status FROM {disqus} WHERE nid = %d", $node->nid)); + } + else { + // Defaults to on for the global content type + $node->disqus['status'] = 1; + } + + // Build the absolute URL without the alias for the disqus_url flag. + $node->disqus['url'] = url("node/$node->nid", array( + 'alias' => TRUE, + 'absolute' => TRUE, + )); + + // 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($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); + } } - elseif ($developer = variable_get('disqus_developer', FALSE)) { - $node->disqus['developer'] = intval($developer); + break; + case 'delete': + db_query('DELETE FROM {disqus} WHERE nid = %d', $node->nid); + break; + case 'insert': + db_query('INSERT INTO {disqus} (nid, status) VALUES (%d, %d)', $node->nid, $node->disqus['status']); + break; + case 'update': + $data = array('nid' => $node->nid, 'status' => $node->disqus['status']); + drupal_write_record('disqus', $data); + break; + case 'view': + // See if we are to display Disqus in the current context. + if (!$a3 && $a4 && isset($node->disqus) && user_access('view disqus comments') && $node->disqus['status'] == 1) { + // 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( + '#value' => theme('disqus_comments', $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; - case 'view': - // See if we are to display Disqus in the current context. - if (!$a3 && $a4 && isset($node->disqus) && user_access('view disqus comments')) { - // 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( - '#value' => theme('disqus_comments', $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; + } + } +} + +/** + * Implementation of hook_form_alter(). + */ +function disqus_form_alter(&$form, $form_state, $form_id) { + $types = variable_get('disqus_nodetypes', array()); + if (!empty($types[$form['type']['#value']]) && isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id ) { + $form['disqus'] = array( + '#type' => 'fieldset', + '#title' => t('Disqus comment settings'), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + ); + $form['disqus']['disqus_status'] = array( + '#type' => 'radios', + '#title' => t('Default comment setting'), + '#default_value' => isset($node->disqus['status']) ? $node->disqus['status'] : '1', + '#options' => array(t('Off'), t('On')), + ); } } @@ -126,7 +171,7 @@ function disqus_user($op, &$edit, &$acco // Only show on the profile if desired. Don't show on the administrator's profile. if (user_access('display disqus comments on profile', $account) && $account->uid != 1) { // Check which Disqus domain to use. - $domain = variable_get('disqus_domain', ''); + $domain = variable_get('disqus_domain', NULL); if (!empty($domain)) { // Save the data to the user object. $account->disqus = array('domain' => $domain); @@ -180,10 +225,10 @@ function disqus_user($op, &$edit, &$acco function disqus_link($type, $node = NULL, $teaser = FALSE) { $links = array(); // Only show the Disqus links on node teasers. - if ($type == 'node' && $teaser == TRUE) { + if ($type == 'node' && $teaser == TRUE && $node->disqus['status'] == 1) { // Make sure the context is correct. $types = variable_get('disqus_nodetypes', array()); - $domain = variable_get('disqus_domain', ''); + $domain = variable_get('disqus_domain', NULL); if (!empty($types[$node->type]) && user_access('view disqus comments') && !empty($domain)) { // Construct the path and inject it into the links area. $path = url("node/$node->nid", array( @@ -373,7 +418,7 @@ function disqus_theme() { return array( 'disqus_comments' => array( 'arguments' => array( - 'options' => NULL, + 'options' => NULL, ), ), 'disqus_comments_num' => array( @@ -402,7 +447,7 @@ function theme_disqus_comments($options /** * Renders the JavaScript to change all Disqus comment links to the correct number of comments. - * + * * @param $domain * The Disqus domain associated with this account. * @param $path @@ -434,8 +479,8 @@ function theme_disqus_comments_num($doma } /** -* Implementation of hook_view_api(). -*/ + * Implementation of hook_view_api(). + */ function disqus_views_api() { return array('api' => 2); }