Loading modules/image_captcha/image_captcha.install +2 −2 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ * Installation/uninstallation related functions for the image_captcha module. */ use Drupal\image_captcha\Constants\ImageCaptchaConstants; use Drupal\captcha\Constants\CaptchaConstants; /** * Implements hook_requirements(). Loading @@ -17,7 +17,7 @@ function image_captcha_requirements($phase) { // Using 'module_load_include' returns FALSE so 'include_once' used instead. include_once __DIR__ . '/image_captcha.module'; // Check if the GD library is available and raise an error when not. if (_image_captcha_check_setup(FALSE) & ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_GDLIB) { if (_image_captcha_check_setup(FALSE) & CaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_GDLIB) { $requirements['image_captcha_requires_gd'] = [ 'title' => \Drupal::translation() ->translate('Image CAPTCHA requires GD library'), Loading modules/image_captcha/image_captcha.module +6 −7 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; use Drupal\Core\Link; use Drupal\Core\DrupalKernel; use Drupal\image_captcha\Constants\ImageCaptchaConstants; use Drupal\captcha\Constants\CaptchaConstants; /** Loading @@ -30,7 +29,7 @@ function image_captcha_help($route_name, RouteMatchInterface $route_match) { * List of font paths. */ function _image_captcha_get_enabled_fonts() { if (ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT & _image_captcha_check_setup(FALSE)) { if (CaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT & _image_captcha_check_setup(FALSE)) { return ['BUILTIN']; } else { Loading Loading @@ -190,11 +189,11 @@ function _image_captcha_check_setup($check_fonts = TRUE) { // We need at least the imagepng function. // Note that the imagejpg function is optionally also used, but not required. if (!function_exists('imagepng')) { $status = $status | ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_GDLIB; $status = $status | CaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_GDLIB; } if (!function_exists('imagettftext')) { $status = $status | ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT; $status = $status | CaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT; } if ($check_fonts) { Loading @@ -208,13 +207,13 @@ function _image_captcha_check_setup($check_fonts = TRUE) { // Try again now. $fonts = _image_captcha_get_enabled_fonts(); if (empty($fonts)) { $status = $status | ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM; $status = $status | CaptchaConstants::IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM; } } if (!empty($fonts)) { $problem_fonts = _image_captcha_check_fonts($fonts); if (count($problem_fonts) != 0) { $status = $status | ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM; $status = $status | CaptchaConstants::IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM; } } } Loading Loading @@ -257,7 +256,7 @@ function image_captcha_captcha($op, $captcha_type = '', $captcha_sid = NULL) { case 'list': // Only offer the image CAPTCHA if it is possible to generate an image // on this setup. if (!(_image_captcha_check_setup() & ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_GDLIB)) { if (!(_image_captcha_check_setup() & CaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_GDLIB)) { return ['Image']; } else { Loading modules/image_captcha/src/Constants/ImageCaptchaConstants.phpdeleted 100644 → 0 +0 −21 Original line number Diff line number Diff line <?php namespace Drupal\image_captcha\Constants; /** * Constants for the image_captcha module. */ class ImageCaptchaConstants { const IMAGE_CAPTCHA_ALLOWED_CHARACTERS = 'aAbBCdEeFfGHhijKLMmNPQRrSTtWXYZ23456789'; // Setup status flags. const IMAGE_CAPTCHA_ERROR_NO_GDLIB = 1; const IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT = 2; const IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM = 4; const IMAGE_CAPTCHA_FILE_FORMAT_JPG = 1; const IMAGE_CAPTCHA_FILE_FORMAT_PNG = 2; const IMAGE_CAPTCHA_FILE_FORMAT_TRANSPARENT_PNG = 3; } modules/image_captcha/src/Controller/CaptchaImageRefresh.php +2 −2 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Drupal\Component\Utility\Crypt; use Drupal\image_captcha\Constants\ImageCaptchaConstants; use Drupal\captcha\Constants\CaptchaConstants; /** * Description of CaptchaImageRefresh. Loading Loading @@ -59,7 +59,7 @@ class CaptchaImageRefresh extends ControllerBase { $config = $this->config('image_captcha.settings'); $captcha_sid = _captcha_generate_captcha_session($form_id); $captcha_token = Crypt::randomBytesBase64(); $allowed_char = $config->get('image_captcha_image_allowed_chars') ? $config->get('image_captcha_image_allowed_chars') : ImageCaptchaConstants::IMAGE_CAPTCHA_ALLOWED_CHARACTERS; $allowed_char = $config->get('image_captcha_image_allowed_chars') ? $config->get('image_captcha_image_allowed_chars') : CaptchaConstants::IMAGE_CAPTCHA_ALLOWED_CHARACTERS; $allowed_chars = _image_captcha_utf8_split($allowed_char); $code_length = (int) $config->get('image_captcha_code_length'); $code = ''; Loading modules/image_captcha/src/Form/ImageCaptchaSettingsForm.php +7 −7 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ use Drupal\Core\Template\Attribute; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\File\FileSystemInterface; use Drupal\image_captcha\Constants\ImageCaptchaConstants; use Drupal\captcha\Constants\CaptchaConstants; /** * Displays the pants settings form. Loading Loading @@ -84,7 +84,7 @@ class ImageCaptchaSettingsForm extends ConfigFormBase { // First some error checking. $setup_status = _image_captcha_check_setup(FALSE); if ($setup_status & ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_GDLIB) { if ($setup_status & CaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_GDLIB) { $this->messenger()->addError($this->t( 'The Image CAPTCHA module can not generate images because your PHP setup does not support it (no <a href="!gdlib" target="_blank">GD library</a> with JPEG support).', ['!gdlib' => 'http://php.net/manual/en/book.image.php'] Loading Loading @@ -114,7 +114,7 @@ class ImageCaptchaSettingsForm extends ConfigFormBase { $form['image_captcha_code_settings']['image_captcha_image_allowed_chars'] = [ '#type' => 'textfield', '#title' => $this->t('Characters to use in the code'), '#default_value' => $config->get('image_captcha_image_allowed_chars') ? $config->get('image_captcha_image_allowed_chars') : ImageCaptchaConstants::IMAGE_CAPTCHA_ALLOWED_CHARACTERS, '#default_value' => $config->get('image_captcha_image_allowed_chars') ? $config->get('image_captcha_image_allowed_chars') : CaptchaConstants::IMAGE_CAPTCHA_ALLOWED_CHARACTERS, ]; $form['image_captcha_code_settings']['image_captcha_code_length'] = [ '#type' => 'select', Loading Loading @@ -179,9 +179,9 @@ class ImageCaptchaSettingsForm extends ConfigFormBase { '#description' => $this->t('Select the file format for the image. JPEG usually results in smaller files, PNG allows tranparency.'), '#default_value' => $config->get('image_captcha_file_format'), '#options' => [ ImageCaptchaConstants::IMAGE_CAPTCHA_FILE_FORMAT_JPG => $this->t('JPEG'), ImageCaptchaConstants::IMAGE_CAPTCHA_FILE_FORMAT_PNG => $this->t('PNG'), ImageCaptchaConstants::IMAGE_CAPTCHA_FILE_FORMAT_TRANSPARENT_PNG => $this->t('PNG with transparent background'), CaptchaConstants::IMAGE_CAPTCHA_FILE_FORMAT_JPG => $this->t('JPEG'), CaptchaConstants::IMAGE_CAPTCHA_FILE_FORMAT_PNG => $this->t('PNG'), CaptchaConstants::IMAGE_CAPTCHA_FILE_FORMAT_TRANSPARENT_PNG => $this->t('PNG with transparent background'), ], ]; Loading Loading @@ -336,7 +336,7 @@ class ImageCaptchaSettingsForm extends ConfigFormBase { // First check if there is TrueType support. $setup_status = _image_captcha_check_setup(FALSE); if ($setup_status & ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT) { if ($setup_status & CaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT) { // Show a warning that there is no TrueType support. $form['no_ttf_support'] = [ '#type' => 'item', Loading Loading
modules/image_captcha/image_captcha.install +2 −2 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ * Installation/uninstallation related functions for the image_captcha module. */ use Drupal\image_captcha\Constants\ImageCaptchaConstants; use Drupal\captcha\Constants\CaptchaConstants; /** * Implements hook_requirements(). Loading @@ -17,7 +17,7 @@ function image_captcha_requirements($phase) { // Using 'module_load_include' returns FALSE so 'include_once' used instead. include_once __DIR__ . '/image_captcha.module'; // Check if the GD library is available and raise an error when not. if (_image_captcha_check_setup(FALSE) & ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_GDLIB) { if (_image_captcha_check_setup(FALSE) & CaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_GDLIB) { $requirements['image_captcha_requires_gd'] = [ 'title' => \Drupal::translation() ->translate('Image CAPTCHA requires GD library'), Loading
modules/image_captcha/image_captcha.module +6 −7 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; use Drupal\Core\Link; use Drupal\Core\DrupalKernel; use Drupal\image_captcha\Constants\ImageCaptchaConstants; use Drupal\captcha\Constants\CaptchaConstants; /** Loading @@ -30,7 +29,7 @@ function image_captcha_help($route_name, RouteMatchInterface $route_match) { * List of font paths. */ function _image_captcha_get_enabled_fonts() { if (ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT & _image_captcha_check_setup(FALSE)) { if (CaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT & _image_captcha_check_setup(FALSE)) { return ['BUILTIN']; } else { Loading Loading @@ -190,11 +189,11 @@ function _image_captcha_check_setup($check_fonts = TRUE) { // We need at least the imagepng function. // Note that the imagejpg function is optionally also used, but not required. if (!function_exists('imagepng')) { $status = $status | ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_GDLIB; $status = $status | CaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_GDLIB; } if (!function_exists('imagettftext')) { $status = $status | ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT; $status = $status | CaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT; } if ($check_fonts) { Loading @@ -208,13 +207,13 @@ function _image_captcha_check_setup($check_fonts = TRUE) { // Try again now. $fonts = _image_captcha_get_enabled_fonts(); if (empty($fonts)) { $status = $status | ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM; $status = $status | CaptchaConstants::IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM; } } if (!empty($fonts)) { $problem_fonts = _image_captcha_check_fonts($fonts); if (count($problem_fonts) != 0) { $status = $status | ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM; $status = $status | CaptchaConstants::IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM; } } } Loading Loading @@ -257,7 +256,7 @@ function image_captcha_captcha($op, $captcha_type = '', $captcha_sid = NULL) { case 'list': // Only offer the image CAPTCHA if it is possible to generate an image // on this setup. if (!(_image_captcha_check_setup() & ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_GDLIB)) { if (!(_image_captcha_check_setup() & CaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_GDLIB)) { return ['Image']; } else { Loading
modules/image_captcha/src/Constants/ImageCaptchaConstants.phpdeleted 100644 → 0 +0 −21 Original line number Diff line number Diff line <?php namespace Drupal\image_captcha\Constants; /** * Constants for the image_captcha module. */ class ImageCaptchaConstants { const IMAGE_CAPTCHA_ALLOWED_CHARACTERS = 'aAbBCdEeFfGHhijKLMmNPQRrSTtWXYZ23456789'; // Setup status flags. const IMAGE_CAPTCHA_ERROR_NO_GDLIB = 1; const IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT = 2; const IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM = 4; const IMAGE_CAPTCHA_FILE_FORMAT_JPG = 1; const IMAGE_CAPTCHA_FILE_FORMAT_PNG = 2; const IMAGE_CAPTCHA_FILE_FORMAT_TRANSPARENT_PNG = 3; }
modules/image_captcha/src/Controller/CaptchaImageRefresh.php +2 −2 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Drupal\Component\Utility\Crypt; use Drupal\image_captcha\Constants\ImageCaptchaConstants; use Drupal\captcha\Constants\CaptchaConstants; /** * Description of CaptchaImageRefresh. Loading Loading @@ -59,7 +59,7 @@ class CaptchaImageRefresh extends ControllerBase { $config = $this->config('image_captcha.settings'); $captcha_sid = _captcha_generate_captcha_session($form_id); $captcha_token = Crypt::randomBytesBase64(); $allowed_char = $config->get('image_captcha_image_allowed_chars') ? $config->get('image_captcha_image_allowed_chars') : ImageCaptchaConstants::IMAGE_CAPTCHA_ALLOWED_CHARACTERS; $allowed_char = $config->get('image_captcha_image_allowed_chars') ? $config->get('image_captcha_image_allowed_chars') : CaptchaConstants::IMAGE_CAPTCHA_ALLOWED_CHARACTERS; $allowed_chars = _image_captcha_utf8_split($allowed_char); $code_length = (int) $config->get('image_captcha_code_length'); $code = ''; Loading
modules/image_captcha/src/Form/ImageCaptchaSettingsForm.php +7 −7 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ use Drupal\Core\Template\Attribute; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\File\FileSystemInterface; use Drupal\image_captcha\Constants\ImageCaptchaConstants; use Drupal\captcha\Constants\CaptchaConstants; /** * Displays the pants settings form. Loading Loading @@ -84,7 +84,7 @@ class ImageCaptchaSettingsForm extends ConfigFormBase { // First some error checking. $setup_status = _image_captcha_check_setup(FALSE); if ($setup_status & ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_GDLIB) { if ($setup_status & CaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_GDLIB) { $this->messenger()->addError($this->t( 'The Image CAPTCHA module can not generate images because your PHP setup does not support it (no <a href="!gdlib" target="_blank">GD library</a> with JPEG support).', ['!gdlib' => 'http://php.net/manual/en/book.image.php'] Loading Loading @@ -114,7 +114,7 @@ class ImageCaptchaSettingsForm extends ConfigFormBase { $form['image_captcha_code_settings']['image_captcha_image_allowed_chars'] = [ '#type' => 'textfield', '#title' => $this->t('Characters to use in the code'), '#default_value' => $config->get('image_captcha_image_allowed_chars') ? $config->get('image_captcha_image_allowed_chars') : ImageCaptchaConstants::IMAGE_CAPTCHA_ALLOWED_CHARACTERS, '#default_value' => $config->get('image_captcha_image_allowed_chars') ? $config->get('image_captcha_image_allowed_chars') : CaptchaConstants::IMAGE_CAPTCHA_ALLOWED_CHARACTERS, ]; $form['image_captcha_code_settings']['image_captcha_code_length'] = [ '#type' => 'select', Loading Loading @@ -179,9 +179,9 @@ class ImageCaptchaSettingsForm extends ConfigFormBase { '#description' => $this->t('Select the file format for the image. JPEG usually results in smaller files, PNG allows tranparency.'), '#default_value' => $config->get('image_captcha_file_format'), '#options' => [ ImageCaptchaConstants::IMAGE_CAPTCHA_FILE_FORMAT_JPG => $this->t('JPEG'), ImageCaptchaConstants::IMAGE_CAPTCHA_FILE_FORMAT_PNG => $this->t('PNG'), ImageCaptchaConstants::IMAGE_CAPTCHA_FILE_FORMAT_TRANSPARENT_PNG => $this->t('PNG with transparent background'), CaptchaConstants::IMAGE_CAPTCHA_FILE_FORMAT_JPG => $this->t('JPEG'), CaptchaConstants::IMAGE_CAPTCHA_FILE_FORMAT_PNG => $this->t('PNG'), CaptchaConstants::IMAGE_CAPTCHA_FILE_FORMAT_TRANSPARENT_PNG => $this->t('PNG with transparent background'), ], ]; Loading Loading @@ -336,7 +336,7 @@ class ImageCaptchaSettingsForm extends ConfigFormBase { // First check if there is TrueType support. $setup_status = _image_captcha_check_setup(FALSE); if ($setup_status & ImageCaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT) { if ($setup_status & CaptchaConstants::IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT) { // Show a warning that there is no TrueType support. $form['no_ttf_support'] = [ '#type' => 'item', Loading