You are here

function _image_captcha_check_setup in CAPTCHA 8

Same name and namespace in other branches
  1. 6.2 image_captcha/image_captcha.module \_image_captcha_check_setup()
  2. 7 image_captcha/image_captcha.module \_image_captcha_check_setup()

Helper function for checking the setup of the Image CAPTCHA.

The image CAPTCHA requires at least the GD PHP library. Support for TTF is recommended and the enabled font files should be readable. This functions checks these things.

Parameters

bool $check_fonts: Whether or not the enabled fonts should be checked.

Return value

int Status code: bitwise 'OR' of status flags like IMAGE_CAPTCHA_ERROR_NO_GDLIB, IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT, IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM.

5 calls to _image_captcha_check_setup()
ImageCaptchaSettingsForm::buildForm in image_captcha/src/Form/ImageCaptchaSettingsForm.php
Form constructor.
ImageCaptchaSettingsForm::settingsDotSection in image_captcha/src/Form/ImageCaptchaSettingsForm.php
Form elements for the font specific setting.
image_captcha_captcha in image_captcha/image_captcha.module
Implements hook_captcha().
image_captcha_requirements in image_captcha/image_captcha.install
Implements hook_requirements().
_image_captcha_get_enabled_fonts in image_captcha/image_captcha.module
Getter for fonts to use in the image CAPTCHA.

File

image_captcha/image_captcha.module, line 196
Implements image CAPTCHA for use with the CAPTCHA module.

Code

function _image_captcha_check_setup($check_fonts = TRUE) {
  $status = 0;

  // Check if we can use the GD library.
  // 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 | IMAGE_CAPTCHA_ERROR_NO_GDLIB;
  }
  if (!function_exists('imagettftext')) {
    $status = $status | IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT;
  }
  if ($check_fonts) {

    // Check availability of enabled fonts.
    $fonts = _image_captcha_get_enabled_fonts();
    $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;
    }
  }
  return $status;
}