Unverified Commit d33ec9e4 authored by naveenvalecha's avatar naveenvalecha Committed by naveenvalecha

Issue #2837488 by naveenvalecha: Fix Coding standards.

parent f5d4338c
......@@ -52,20 +52,20 @@ function captcha_help($route_name, RouteMatchInterface $route_match) {
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('"CAPTCHA" is an acronym for "Completely Automated Public Turing test to tell Computers and Humans Apart". It is typically a challenge-response test to determine whether the user is human. The CAPTCHA module is a tool to fight automated submission by malicious users (spamming) of for example comments forms, user registration forms, guestbook forms, etc. You can extend the desired forms with an additional challenge, which should be easy for a human to solve correctly, but hard enough to keep automated scripts and spam bots out.') . '</p>';
$output .= '<p>' . t('Note that the CAPTCHA module interacts with page caching (see <a href=":performancesettings">performance settings</a>). Because the challenge should be unique for each generated form, the caching of the page it appears on is prevented. Make sure that these forms do not appear on too many pages or you will lose much caching efficiency. For example, if you put a CAPTCHA on the user login block, which typically appears on each page for anonymous visitors, caching will practically be disabled. The comment submission forms are another example. In this case you should set the <em>Location of comment submission form</em> to <em>Display on separate page</em> in the comment settings of the relevant <a href=":contenttypes">content types</a> for better caching efficiency.', [
':performancesettings' => \Drupal::url('system.performance_settings'),
':contenttypes' => \Drupal::url('entity.node_type.collection'),
]) . '</p>';
':performancesettings' => \Drupal::url('system.performance_settings'),
':contenttypes' => \Drupal::url('entity.node_type.collection'),
]) . '</p>';
$output .= '<p>' . t('CAPTCHA is a trademark of Carnegie Mellon University.') . '</p>';
return ['#markup' => $output];
case 'captcha_settings':
$output = '<p>' . t('A CAPTCHA can be added to virtually each Drupal form. Some default forms are already provided in the form list, but arbitrary forms can be easily added and managed when the option <em>Add CAPTCHA administration links to forms</em> is enabled.') . '</p>';
$output .= '<p>' . t('Users with the <em>Skip CAPTCHA</em> <a href=":perm">permission</a> won\'t be offered a challenge. Be sure to grant this permission to the trusted users (e.g. site administrators). If you want to test a protected form, be sure to do it as a user without the <em>Skip CAPTCHA</em> permission (e.g. as anonymous user).', [
':perm' => \Drupal::url('user.admin_permissions'),
]) . '</p>';
':perm' => \Drupal::url('user.admin_permissions'),
]) . '</p>';
$output .= '<p><b>' . t('Note that the CAPTCHA module disables <a href=":performancesettings">page caching</a> of pages that include a CAPTCHA challenge.', [
':performancesettings' => \Drupal::url('system.performance_settings'),
]) . '</b></p>';
':performancesettings' => \Drupal::url('system.performance_settings'),
]) . '</b></p>';
return ['#markup' => $output];
}
}
......@@ -172,7 +172,7 @@ function captcha_form_alter(array &$form, FormStateInterface $form_state, $form_
}
elseif ($config->get('administration_mode') && $account->hasPermission('administer CAPTCHA settings')
&& (!\Drupal::service('router.admin_context')
->isAdminRoute() || $config->get('allow_on_admin_pages'))
->isAdminRoute() || $config->get('allow_on_admin_pages'))
) {
// Add CAPTCHA administration tools.
/* @var \Drupal\captcha\Entity\CaptchaPoint $captcha_point */
......@@ -215,7 +215,7 @@ function captcha_form_alter(array &$form, FormStateInterface $form_state, $form_
t('Place a CAPTCHA here for untrusted users.'),
Url::fromRoute('captcha_point.add', [], [
'query' => Drupal::destination()
->getAsArray() + ['form_id' => $form_id],
->getAsArray() + ['form_id' => $form_id],
])
)->toString(),
];
......@@ -448,7 +448,7 @@ function captcha_validate($element, FormStateInterface &$form_state) {
// Update wrong response counter.
if (\Drupal::config('captcha.settings')->get('enable_stats', FALSE)) {
Drupal::state()->set('captcha.wrong_response_counter', Drupal::state()
->get('captcha.wrong_response_counter', 0) + 1);
->get('captcha.wrong_response_counter', 0) + 1);
}
if (\Drupal::config('captcha.settings')
......
......@@ -18,7 +18,8 @@ function image_captcha_font_preview($font_token) {
}
else {
// Get the mapping of font tokens to font file objects.
$fonts = \Drupal::config('image_captcha.settings')->get('image_captcha_fonts_preview_map_cache');
$fonts = \Drupal::config('image_captcha.settings')
->get('image_captcha_fonts_preview_map_cache');
if (!isset($fonts[$font_token])) {
print 'Bad token';
exit();
......
......@@ -17,11 +17,13 @@ function image_captcha_requirements($phase) {
// Check if the GD library is available and raise an error when not.
if (_image_captcha_check_setup(FALSE) & IMAGE_CAPTCHA_ERROR_NO_GDLIB) {
$requirements['image_captcha_requires_gd'] = [
'title' => \Drupal::translation()->translate('Image CAPTCHA requires GD library'),
'title' => \Drupal::translation()
->translate('Image CAPTCHA requires GD library'),
'description' =>
\Drupal::translation()->translate('The Image CAPTCHA module can not be installed because your PHP setup does not provide the <a href="!gddoc">GD library</a>, which is required to generate images.',
['!gddoc' => 'http://www.php.net/manual/en/book.image.php']
),
\Drupal::translation()
->translate('The Image CAPTCHA module can not be installed because your PHP setup does not provide the <a href="!gddoc">GD library</a>, which is required to generate images.',
['!gddoc' => 'http://www.php.net/manual/en/book.image.php']
),
'severity' => REQUIREMENT_ERROR,
];
}
......
......@@ -5,7 +5,8 @@
* Implements image CAPTCHA for use with the CAPTCHA module.
*/
use \Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
define('IMAGE_CAPTCHA_ALLOWED_CHARACTERS', 'aAbBCdEeFfGHhijKLMmNPQRrSTtWXYZ23456789');
......@@ -18,8 +19,6 @@ define('IMAGE_CAPTCHA_FILE_FORMAT_JPG', 1);
define('IMAGE_CAPTCHA_FILE_FORMAT_PNG', 2);
define('IMAGE_CAPTCHA_FILE_FORMAT_TRANSPARENT_PNG', 3);
use Drupal\Core\Url;
/**
* Implements hook_help().
*/
......@@ -42,7 +41,8 @@ function _image_captcha_get_enabled_fonts() {
return ['BUILTIN'];
}
else {
return \Drupal::config('image_captcha.settings')->get('image_captcha_fonts');
return \Drupal::config('image_captcha.settings')
->get('image_captcha_fonts');
}
}
......@@ -107,7 +107,8 @@ function _image_captcha_utf8_split($str) {
$width = 4;
}
else {
\Drupal::logger('CAPTCHA')->error('Encountered an illegal byte while splitting an utf8 string in characters.');
\Drupal::logger('CAPTCHA')
->error('Encountered an illegal byte while splitting an utf8 string in characters.');
return $characters;
}
}
......@@ -151,7 +152,7 @@ function _image_captcha_check_setup($check_fonts = TRUE) {
if ($check_fonts) {
// Check availability of enabled fonts.
$fonts = _image_captcha_get_enabled_fonts();
$readable_fonts = array();
$readable_fonts = [];
list($readable_fonts, $problem_fonts) = _image_captcha_check_fonts($fonts);
if (count($problem_fonts) != 0) {
$status = $status | IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM;
......@@ -210,7 +211,9 @@ function image_captcha_captcha($op, $captcha_type = '', $captcha_sid = NULL) {
// the request for the image itself won't succeed (only ?q=user
// is permitted for unauthenticated users). We fall back to the
// Math CAPTCHA in that case.
if (defined('MAINTENANCE_MODE') && \Drupal::currentUser()->isAnonymous()) {
if (defined('MAINTENANCE_MODE') && \Drupal::currentUser()
->isAnonymous()
) {
return captcha_captcha('generate', 'Math');
}
// Generate a CAPTCHA code.
......@@ -232,7 +235,10 @@ function image_captcha_captcha($op, $captcha_type = '', $captcha_sid = NULL) {
list($width, $height) = _image_captcha_image_size($code);
$result['form']['captcha_image'] = [
'#theme' => 'image',
'#uri' => Url::fromRoute('image_captcha.generator', ['session_id' => $captcha_sid, 'timestamp' => REQUEST_TIME])->toString(),
'#uri' => Url::fromRoute('image_captcha.generator', [
'session_id' => $captcha_sid,
'timestamp' => REQUEST_TIME,
])->toString(),
'#width' => $width,
'#height' => $height,
'#alt' => t('Image CAPTCHA'),
......@@ -253,7 +259,8 @@ function image_captcha_captcha($op, $captcha_type = '', $captcha_sid = NULL) {
// Handle the case insensitive validation option combined with
// ignoring spaces.
switch (\Drupal::config('captcha.settings')->get('default_validation')) {
switch (\Drupal::config('captcha.settings')
->get('default_validation')) {
case CAPTCHA_DEFAULT_VALIDATION_CASE_SENSITIVE:
$result['captcha_validate'] = 'captcha_validate_ignore_spaces';
break;
......
......@@ -2,12 +2,12 @@
namespace Drupal\image_captcha\Controller;
use Drupal\Core\Config\Config;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\PageCache\ResponsePolicy\KillSwitch;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\image_captcha\Response\CaptchaImageResponse;
use Drupal\Core\Config\Config;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Controller which generates the image from defined settings.
......
......@@ -261,7 +261,7 @@ class ImageCaptchaSettingsForm extends ConfigFormBase {
}
}
$readable_fonts = array();
$readable_fonts = [];
list($readable_fonts, $problem_fonts) = _image_captcha_check_fonts($fonts);
if (count($problem_fonts) > 0) {
$form_state->setErrorByName('image_captcha_fonts', $this->t('The following fonts are not readable: %fonts.', ['%fonts' => implode(', ', $problem_fonts)]));
......
......@@ -2,10 +2,10 @@
namespace Drupal\image_captcha\Response;
use Drupal\Core\Config\Config;
use Drupal\Core\Logger\LoggerChannelInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Config\Config;
/**
* Response which is returned as the captcha for image_captcha.
......@@ -230,8 +230,8 @@ class CaptchaImageResponse extends Response {
$color_11_g = ($color_11 >> 8) & 0xFF;
$color_11_b = $color_11 & 0xFF;
// Interpolation factors.
$u = $sx - $sxf;
$v = $sy - $syf;
$u = $sx - $sxf;
$v = $sy - $syf;
$r = (int) ((1 - $v) * ((1 - $u) * $color_00_r + $u * $color_10_r) + $v * ((1 - $u) * $color_01_r + $u * $color_11_r));
$g = (int) ((1 - $v) * ((1 - $u) * $color_00_g + $u * $color_10_g) + $v * ((1 - $u) * $color_01_g + $u * $color_11_g));
$b = (int) ((1 - $v) * ((1 - $u) * $color_00_b + $u * $color_10_b) + $v * ((1 - $u) * $color_01_b + $u * $color_11_b));
......
......@@ -33,7 +33,7 @@ class Captcha extends FormElement {
// insensitive validation.
// TODO: shouldn't this be done somewhere else, e.g. in form_alter?
if (CAPTCHA_DEFAULT_VALIDATION_CASE_INSENSITIVE == \Drupal::config('captcha.settings')
->get('default_validation')
->get('default_validation')
) {
$captcha_element['#captcha_validate'] = 'captcha_validate_case_insensitive_equality';
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment