From e0b09f06f1de7f84bf365a1f0dabd47de37302a5 Mon Sep 17 00:00:00 2001 From: quickstart Date: Tue, 16 Jul 2013 14:55:52 +0530 Subject: [PATCH] =Related to issue 2040057. --- disqus.admin.inc | 68 ++++++++++++++++++++++++------------------------------ disqus.install | 35 +++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 41 deletions(-) diff --git a/disqus.admin.inc b/disqus.admin.inc index 25fdf75..900c3d6 100644 --- a/disqus.admin.inc +++ b/disqus.admin.inc @@ -110,53 +110,45 @@ function disqus_admin_settings() { '#title' => t('Secret Key'), '#default_value' => variable_get('disqus_secretkey', ''), ); - - $form['advanced']['sso'] = array( - '#weight' => 5, - '#type' => 'fieldset', - '#title' => t('Single Sign-on'), - '#collapsible' => FALSE, - '#collapsed' => FALSE, - '#states' => array( - 'visible' => array( - 'input[name="disqus_publickey"]' => array('empty' => FALSE), - 'input[name="disqus_secretkey"]' => array('empty' => FALSE), - ), - ), - ); - $form['advanced']['sso']['disqus_sso'] = array( + $form['advanced']['disqus_sso'] = array( '#type' => 'checkbox', - '#title' => t('Use Single Sign-On'), + '#title' => t('Single Sign-On'), '#description' => t('Provide Single Sign-On access to your site.', array( '@sso' => 'http://disqus.com/api/sso/', )), '#default_value' => variable_get('disqus_sso', FALSE), - ); - $form['advanced']['sso']['disqus_use_site_logo'] = array( - '#type' => 'checkbox', - '#title' => t('Use Site Logo'), - '#description' => t('Pass the site logo to Disqus for use as SSO login button.'), - '#default_value' => variable_get('disqus_use_site_logo', TRUE), '#states' => array( - 'disabled' => array( - 'input[name="disqus_sso"]' => array('checked' => FALSE), - ), - ), - ); - $form['advanced']['sso']['disqus_logo'] = array( - '#type' => 'managed_file', - '#title' => t('Custom Logo'), - '#upload_location' => 'public://images', - '#default_value' => variable_get('disqus_logo', ''), - '#states' => array( - 'disabled' => array( - 'input[name="disqus_sso"]' => array('checked' => FALSE), - ), 'visible' => array( - 'input[name="disqus_use_site_logo"]' => array('checked' => FALSE), + 'input[name="disqus_publickey"]' => array('empty' => FALSE), + 'input[name="disqus_secretkey"]' => array('empty' => FALSE), ), ), ); - + $form['#submit'][] = 'disqus_admin_settings_submit'; return system_settings_form($form); } + +/** + * Implements hook_submit() + */ +function disqus_admin_settings_submit($form, &$form_state){ + foreach($form_state['values'] as $field => $type){ + if(strstr($field,'disqus_')){ + $record = array( + 'name' => $field, + ); + $exists = db_query('SELECT 1 FROM {disqus_fields} WHERE name = :name', array(':name' => $field))->fetchField(); + if ($exists == FALSE){ // insert a field if not in table already. + drupal_write_record('disqus_fields', $record); + } + } + } +} + +/** + * Menu callback; Automatically closes the window after the user logs in. + */ +function disqus_closewindow() { + drupal_add_js('window.close();', 'inline'); + return t('Thank you for logging in. Please close this window, or click here to continue.', array('@clickhere' => 'javascript:window.close();')); +} diff --git a/disqus.install b/disqus.install index 2d14352..cced1f5 100644 --- a/disqus.install +++ b/disqus.install @@ -15,7 +15,7 @@ function disqus_schema() { 'did' => array( 'type' => 'serial', 'not null' => TRUE, - ), + ), 'nid' => array( 'type' => 'int', 'not null' => TRUE, @@ -35,6 +35,31 @@ function disqus_schema() { 'status' => array('status'), ), ); + + $schema['disqus_fields'] = array( + 'fields' => array( + 'fid' => array( + 'type' => 'serial', + 'not null' => TRUE, + ), + 'name' => array( + 'type' => 'text', + 'length' => 255, + ), + 'type' => array( + 'type' => 'text', + 'length' => 255, + ), + 'status' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), + ), + 'primary key' => array('fid'), + ); return $schema; } @@ -42,9 +67,12 @@ function disqus_schema() { * Implements hook_uninstall(). */ function disqus_uninstall() { + // Remove all Disqus-related variables. - db_delete('variable')->condition('name', 'disqus_%', 'LIKE')->execute(); - cache_clear_all('variables', 'cache_bootstrap'); + $rec = db_query('SELECT name FROM {disqus_fields}')->fetchAll(); + $arr = array_map(function($el){ return $el->name; }, $rec); + db_delete('variable')->condition('name', $arr, 'IN')->execute(); + } /** @@ -62,3 +90,4 @@ function disqus_update_7001() { drupal_install_schema('disqus'); } } + -- 1.7.9.5