/**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL)
 {
     MollomUtilities::displayMollomTestModeWarning();
     $config = $this->config('mollom.settings');
     // Only check and display the status message if the form is being shown
     // for the first time and not when displayed again after submission.
     $check = empty($_POST);
     if ($check) {
         $status = MollomUtilities::getAdminAPIKeyStatus($check);
         if ($status['isVerified'] && !$config->get('test_mode.enabled')) {
             drupal_set_message(t('Mollom servers verified your keys. The services are operating correctly.'));
         }
     }
     $form['keys'] = array('#type' => 'details', '#title' => t('Mollom API keys'), '#tree' => TRUE, '#description' => t('To obtain API keys, <a href="@signup-url">sign up</a> or log in to your <a href="@site-manager-url">Site manager</a>, register this site, and copy the keys into the fields below.', array('@signup-url' => 'https://mollom.com/pricing', '@site-manager-url' => 'https://mollom.com/site-manager')), '#open' => isset($status) ? !$status['isVerified'] : true);
     // Keys are not #required to allow to install this module and configure it
     // later.
     $form['keys']['public'] = array('#type' => 'textfield', '#title' => t('Public key'), '#default_value' => $config->get('keys.public'), '#description' => t('Used to uniquely identify this site.'));
     $form['keys']['private'] = array('#type' => 'textfield', '#title' => t('Private key'), '#default_value' => $config->get('keys.private'), '#description' => t('Used for authentication. Similar to a password, the private key should not be shared with anyone.'));
     $form['fallback'] = array('#type' => 'radios', '#title' => t('When the Mollom service is unavailable'), '#default_value' => $config->get('fallback'), '#options' => array(Settings::MOLLOM_FALLBACK_ACCEPT => t('Accept all form submissions'), Settings::MOLLOM_FALLBACK_BLOCK => t('Block all form submissions')), '#description' => t('Mollom offers a <a href="@pricing-url">high-availability</a> infrastructure for users on paid plans to reduce potential downtime.', array('@pricing-url' => 'https://mollom.com/pricing')));
     $options = DrupalClient::getSupportedLanguages();
     $default_languages = !empty($status['expectedLanguages']) ? $status['expectedLanguages'] : $config->get("languages_expected");
     // @todo: Add chosen UI functionality for improved UX when available.
     $form['languages_expected'] = array('#type' => 'select', '#title' => t('Expected languages'), '#options' => $options, '#multiple' => TRUE, '#size' => 6, '#default_value' => $default_languages, '#description' => t('Restricts all posts to selected languages. Used by text analysis only. Leave empty if users may post in other languages.'));
     $form['privacy_link'] = array('#type' => 'checkbox', '#title' => t("Show a link to Mollom's privacy policy"), '#return_value' => true, '#default_value' => $config->get('privacy_link'), '#description' => t('Only applies to forms protected with text analysis. When disabling this option, you should inform visitors about the privacy of their data through other means.'));
     $form['testing_mode'] = array('#type' => 'checkbox', '#title' => t('Enable testing mode'), '#return_value' => true, '#default_value' => $config->get('test_mode.enabled'), '#description' => t('Submitting "ham", "unsure", or "spam" triggers the corresponding behavior; image CAPTCHAs only respond to "correct" and audio CAPTCHAs only respond to "demo". Do not enable this option if this site is publicly accessible.'));
     $form['advanced'] = array('#type' => 'details', '#title' => t('Advanced configuration'), '#open' => FALSE);
     // Lower severity numbers indicate a high severity level.
     $form['advanced']['log_level'] = array('#type' => 'radios', '#title' => t('Mollom logging level warning'), '#options' => array(RfcLogLevel::WARNING => t('Only log warnings and errors'), RfcLogLevel::DEBUG => t('Log all Mollom messages')), '#default_value' => $config->get('log_level'));
     $form['advanced']['audio_captcha_enabled'] = array('#type' => 'checkbox', '#title' => t('Enable audio CAPTCHAs.'), '#description' => t('Allows users to switch to an audio verification using the <a href="!faq-url">NATO alphabet</a>.  This may not be appropriate for non-English language sites.', array('!faq-url' => 'https://mollom.com/faq/mollom-audible-captcha-language')), '#return_value' => true, '#default_value' => $config->get('captcha.audio.enabled'));
     $timeout = $config->get('connection_timeout_seconds');
     $form['advanced']['connection_timeout_seconds'] = array('#type' => 'number', '#title' => t('Time-out when attempting to contact Mollom servers.'), '#description' => t('This is the length of time that a call to Mollom will wait before timing out.'), '#default_value' => !empty($timeout) ? $config->get('connection_timeout_seconds') : 3, '#size' => 5, '#field_suffix' => t('seconds'), '#required' => TRUE);
     return parent::buildForm($form, $form_state);
 }
Example #2
0
 /**
  * Returns the parsed HTTP Authorization request header as an array.
  *
  * @see DrupalClient::getServerAuthentication().
  * @return array
  *   The authentication header
  */
 public function getRestOAuthHeader()
 {
     $header =& drupal_static(__FUNCTION__);
     if (isset($header)) {
         return $header;
     }
     $header = DrupalClient::getServerAuthentication();
     return $header;
 }
 /**
  * Overrides Mollom::handleRequest().
  *
  * Automatically tries to generate new API keys in case of a 401 or 404 error.
  * Intentionally reacts on 401 or 404 errors only, since any other error code
  * can mean that either the Testing API is down or that the client site is not
  * able to perform outgoing HTTP requests in general.
  */
 protected function handleRequest($method, $server, $path, $data, $expected = array())
 {
     try {
         $response = parent::handleRequest($method, $server, $path, $data, $expected);
     } catch (MollomException $e) {
         $is_auth_error = $e->getCode() == self::AUTH_ERROR || $e->getCode() == 404 && strpos($path, 'site') === 0;
         $current_public_key = $this->publicKey;
         if ($this->createKeys && $is_auth_error && $this->createKeys()) {
             $this->saveKeys();
             // Avoid to needlessly hit the previous/invalid public key again.
             // Mollom::handleRequest() will sign the new request correctly.
             // If it was empty, Mollom::handleRequest() returned an AUTH_ERROR
             // without issuing a request.
             if ($path == 'site/') {
                 $path = 'site/' . $this->publicKey;
             } elseif (!empty($current_public_key)) {
                 $path = str_replace($current_public_key, $this->publicKey, $path);
             }
             $response = parent::handleRequest($method, $server, $path, $data, $expected);
         } else {
             throw $e;
         }
     }
     return $response;
 }