public function content() { MollomUtilities::getAdminAPIKeyStatus(); $config = $this->config('mollom.settings'); $embed_attributes = array('src' => 'https://mollom.com/statistics.swf?key=' . urlencode($config->get('keys.public')), 'quality' => 'high', 'width' => '100%', 'height' => '430', 'name' => 'Mollom', 'align' => 'middle', 'play' => 'true', 'loop' => 'false', 'allowScriptAccess' => 'sameDomain', 'type' => 'application/x-shockwave-flash', 'pluginspage' => 'http://www.adobe.com/go/getflashplayer', 'wmode' => 'transparent'); return array('#type' => 'markup', '#markup' => '<embed' . new Attribute($embed_attributes) . '></embed>', '#allowed_tags' => ['embed']); }
/** * {@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); }
/** * The content callback for the Blacklist list of current entries. * * @param string $type * A particular list type to show (based on the entry 'reason'). */ function content($type = NULL) { MollomUtilities::getAdminAPIKeyStatus(); MollomUtilities::displayMollomTestModeWarning(); $items = BlacklistStorage::getList($type); $rows = array(); // Edit/delete. $header = array(); if (empty($type)) { $header['type'] = $this->t('List'); } $header['context'] = $this->t('Context'); $header['matches'] = $this->t('Matches'); $header['value'] = $this->t('Value'); $header['operations'] = $this->t('Operations'); foreach ($items as $entry) { $data = array($entry['context'], $entry['match'], $entry['value'], array('data' => array('#type' => 'operations', '#links' => array(array('title' => $this->t('Delete'), 'url' => Url::fromRoute('mollom.blacklist.delete', array('entry_id' => $entry['id']))))))); if (empty($type)) { array_unshift($data, $entry['reason']); } $rows[] = $data; } $build['table'] = array('#type' => 'table', '#header' => $header, '#rows' => $rows, '#empty' => $this->t('There are no entries in the blacklist.'), '#attributes' => array('id' => 'mollom-blacklist-list')); return $build; }
/** * {@inheritdoc} */ public function buildHeader() { MollomUtilities::getAdminAPIKeyStatus(); MollomUtilities::displayMollomTestModeWarning(); $header['label'] = $this->t('Form'); $header['protection_mode'] = $this->t('Protection mode'); return $header + parent::buildHeader(); }
/** * Overrides Drupal\Core\Form\FormInterface::buildForm(). */ public function buildForm(array $form, FormStateInterface $form_state, $entry_id = NULL) { MollomUtilities::getAdminAPIKeyStatus(); MollomUtilities::displayMollomTestModeWarning(); $entry = $this->setEntryById($entry_id)->getEntry(); $form['entry_id'] = array('#type' => 'value', '#value' => $entry_id); $form['reason'] = array('#type' => 'select', '#title' => $this->t('Type'), '#default_value' => $entry['reason'], '#options' => $this->getBlacklistTypeOptions(), '#required' => TRUE); $form['context'] = array('#type' => 'select', '#title' => $this->t('Context'), '#default_value' => $entry['context'], '#options' => $this->getContextOptions(), '#required' => TRUE); $form['match'] = array('#type' => 'select', '#title' => $this->t('Matches'), '#default_value' => $entry['match'], '#options' => $this->getMatchesOptions(), '#required' => TRUE); $form['value'] = array('#type' => 'textfield', '#title' => $this->t('Value'), '#default_value' => $entry['value'], '#required' => TRUE); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save entry')); return $form; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { // Get anything we need form the base class. $form = parent::buildForm($form, $form_state); // Display any API key errors. MollomUtilities::getAdminAPIKeyStatus(); MollomUtilities::displayMollomTestModeWarning(); /* @var $entity \Drupal\mollom\Entity\FormInterface */ $entity = $this->getEntity(); $form_id = ''; if ($entity->isNew()) { // Determine if the form id selection just changed. $input = $form_state->getUserInput(); if (!empty($input['id'])) { $form_id = $input['id']; $mollom_form = $entity->initialize($form_id); } else { if ($query_form_id = \Drupal::request()->query->get('form_id', '')) { $form_id = $query_form_id; $mollom_form = $entity->initialize($form_id); } } } else { $form_id = $entity->id(); $mollom_form = $entity->initialize(); } $enabled_fields = []; if ($entity->isNew() && !empty($input['id'])) { foreach ($mollom_form['enabled_fields'] as $value) { $enabled_fields[] = rawurlencode($value); } // Set defaults back. // See https://www.drupal.org/node/1100170 $input['checks'] = $entity->getChecks(); $input['enabled_fields'] = $enabled_fields; $form_state->setUserInput($input); } else { foreach ($entity->getEnabledFields() as $value) { $enabled_fields[] = rawurldecode($value); } } // Build the form. if ($entity->isNew()) { $options = $this->getProtectableFormOptions(); if (empty($options)) { return $this->redirect('entity.mollom_form.list'); } $form['#attributes']['id'] = $this->getFormId(); $form['id'] = array('#type' => 'select', '#title' => $this->t('Mollom Form'), '#maxlength' => 255, '#options' => $options, '#default_value' => $form_id, '#empty_option' => t('Select a form to configure...'), '#required' => TRUE, '#ajax' => array('callback' => array($this, 'ajaxFormHandler'), 'wrapper' => $this->getFormId())); // Must select the form to protect prior to continuing. if (empty($form_id)) { return $form; } } else { $form['label'] = array('#title' => t('Protected form'), '#type' => 'textfield', '#default_value' => $entity->label(), '#disabled' => TRUE); } // Protection mode $modes = array(FormInterface::MOLLOM_MODE_ANALYSIS => $this->t('@option <em>(@recommended)</em>', array('@option' => $this->t('Text analysis'), '@recommended' => $this->t('recommended'))), FormInterface::MOLLOM_MODE_CAPTCHA => t('CAPTCHA only')); $form['mode'] = array('#type' => 'radios', '#title' => t('Protection mode'), '#options' => $modes, '#default_value' => isset($entity->mode) ? $entity->mode : key($modes)); $form['mode'][FormInterface::MOLLOM_MODE_ANALYSIS] = array('#description' => t('Mollom will analyze the post and will only show a CAPTCHA when it is unsure.')); $form['mode'][FormInterface::MOLLOM_MODE_CAPTCHA] = array('#description' => t('A CAPTCHA will be shown for every post. Only choose this if there are too few text fields to analyze.')); $form['mode'][FormInterface::MOLLOM_MODE_CAPTCHA]['#description'] .= '<br />' . t('Note: Page caching is disabled on all pages containing a CAPTCHA-only protected form.'); $all_permissions = $this->permissionHandler->getPermissions(); // Prepend Mollom's global permission to the list. if (empty($mollom_form['bypass access']) || !is_array($mollom_form['bypass access'])) { $mollom_form['bypass access'] = []; } array_unshift($mollom_form['bypass access'], 'bypass mollom protection'); $permissions = array(); if (isset($mollom_form['bypass access'])) { foreach ($mollom_form['bypass access'] as $permission) { $permissions[Html::getClass($permission)] = array('title' => $all_permissions[$permission]['title'], 'url' => Url::fromRoute('user.admin_permissions'), 'fragment' => 'module-' . $all_permissions[$permission]['provider']); } } $form['mode']['#description'] = t('The protection is omitted for users having any of the permissions: @permission-list', array('@permission-list' => \Drupal::theme()->render('links', array('links' => $permissions)))); // Textual analysis filters. $form['checks'] = array('#type' => 'checkboxes', '#title' => t('Text analysis checks'), '#options' => array('spam' => t('Spam'), 'profanity' => t('Profanity')), '#default_value' => $entity->getChecks(), '#states' => array('visible' => array('[name="mode"]' => array('value' => (string) FormInterface::MOLLOM_MODE_ANALYSIS)))); // Profanity check requires text to analyze; unlike the spam check, there // is no fallback in case there is no text. $form['checks']['profanity']['#access'] = !empty($mollom_form['elements']); // Form elements defined by hook_mollom_form_info() use the // 'parent][child' syntax, which Form API also uses internally for // form_set_error(), and which allows us to recurse into nested fields // during processing of submitted form values. However, since we are using // those keys also as internal values to configure the fields to use for // textual analysis, we need to encode them. Otherwise, a nested field key // would result in the following checkbox attribute: // '#name' => 'mollom[enabled_fields][parent][child]' // This would lead to a form validation error, because it is a valid key. // By encoding them, we prevent this from happening: // '#name' => 'mollom[enabled_fields][parent%5D%5Bchild]' $elements = array(); if (isset($mollom_form['elements']) && is_array($mollom_form['elements'])) { foreach ($mollom_form['elements'] as $key => $value) { $elements[rawurlencode($key)] = $value; } } $enabled_field_selections = []; foreach ($enabled_fields as $key => $value) { $enabled_field_selections[rawurlencode($key)] = rawurlencode($value); } $form['enabled_fields'] = array('#type' => 'checkboxes', '#title' => t('Text fields to analyze'), '#options' => $elements, '#default_value' => $enabled_field_selections, '#description' => t('Only enable fields that accept text (not numbers). Omit fields that contain sensitive data (e.g., credit card numbers) or computed/auto-generated values, as well as author information fields (e.g., name, e-mail).'), '#access' => !empty($mollom_form['elements']), '#states' => array('visible' => array('[name="mode"]' => array('value' => (string) FormInterface::MOLLOM_MODE_ANALYSIS)))); $form['mapping'] = array('#type' => 'value', '#value' => $mollom_form['mapping']); if ($entity->isNew()) { $form['module'] = array('#type' => 'value', '#value' => $mollom_form['module']); $form['label'] = array('#type' => 'value', '#value' => $mollom_form['title']); $form['entity'] = array('#type' => 'value', '#value' => $mollom_form['entity']); $form['bundle'] = array('#type' => 'value', '#value' => $mollom_form['bundle']); } $form['strictness'] = array('#type' => 'radios', '#title' => t('Text analysis strictness'), '#options' => array('normal' => t('@option <em>(@recommended)</em>', array('@option' => t('Normal'), '@recommended' => $this->t('recommended'))), 'strict' => t('Strict: Posts are more likely classified as spam'), 'relaxed' => t('Relaxed: Posts are more likely classified as ham')), '#default_value' => $entity->getStrictness(), '#states' => array('visible' => array('[name="mode"]' => array('value' => (string) FormInterface::MOLLOM_MODE_ANALYSIS)))); $form['unsure'] = array('#type' => 'radios', '#title' => t('When text analysis is unsure'), '#default_value' => $entity->getUnsure(), '#options' => array('captcha' => t('@option <em>(@recommended)</em>', array('@option' => t('Show a CAPTCHA'), '@recommended' => $this->t('recommended'))), 'moderate' => t('Retain the post for manual moderation'), 'binary' => t('Accept the post')), '#required' => $entity->getProtectionMode() == FormInterface::MOLLOM_MODE_ANALYSIS, '#states' => array('visible' => array('[name="mode"]' => array('value' => (string) FormInterface::MOLLOM_MODE_ANALYSIS), '[name="checks[spam]"]' => array('checked' => TRUE)))); // Only possible for forms supporting moderation of unpublished posts. $form['unsure']['moderate']['#access'] = !empty($mollom_form['moderation callback']); $form['discard'] = array('#type' => 'radios', '#title' => t('When text analysis identifies spam'), '#default_value' => $entity->getDiscard(), '#options' => array(1 => t('@option <em>(@recommended)</em>', array('@option' => t('Discard the post'), '@recommended' => $this->t('recommended'))), 0 => t('Retain the post for manual moderation')), '#required' => $entity->getProtectionMode() == FormInterface::MOLLOM_MODE_ANALYSIS, '#states' => array('visible' => array('[name="mode"]' => array('value' => (string) FormInterface::MOLLOM_MODE_ANALYSIS), '[name="checks[spam]"]' => array('checked' => TRUE)))); // Return the form. return $form; }