The captcha module will reset the incorrect font path forever once a bad one is entered the first time.

This code fixes the problem; simply a replacement of captcha_settings:
(Code below the break...)

function captcha_settings() {

  //check for GD
  if (!function_exists(imagecreate))
    form_set_error('No GD', t('Image library not available. Captcha needs the GD library extension to be installed. Please install GD.'));

  else {
    //check for TTF support
	$fontPath=variable_get("captcha_fonts_path", "");
    if (!function_exists(imagettftext))
      drupal_set_message(t('Your image library does not seem to have TrueType font support. Captcha will work, but will use the default inbuilt font.'),'status');
    else {
      //check for valid font path
      if ((variable_get("captcha_fonts_path", "")!='')&& !is_dir(variable_get("captcha_fonts_path", "misc/"))){
        variable_set("captcha_fonts_path","");
        form_set_error('Invalid font path', t('The current font path is invalid. The default font will be used.'));
      }
    }
  }

  $form['captcha_user_register'] = array(
                                          '#type' => 'checkbox',
                                          '#title' => t('Check during user registration'),
                                          '#default_value' => _captcha_istrue("captcha_user_register", "true"),
                                          '#description' =>  t('If enabled, users will be asked to recognize an image during user registration.'),
                                        );
  $form['captcha_comment_anonymous'] = array(
                                          '#type' => 'checkbox',
                                          '#title' => t('Check during anonymous comments.'),
                                          '#default_value' => _captcha_istrue("captcha_comment_anonymous", "true"),
                                          '#description' =>   t('If enabled, anonymous users will be asked to recognize an image while posting .'),
                                        );

  $form['captcha_comment_registered'] = array(
                                          '#type' => 'checkbox',
                                          '#title' => t('Check during registered user comments.'),
                                          '#default_value' => _captcha_istrue("captcha_comment_registered", "true"),
                                          '#description' =>   t('If enabled, registered users will be asked to recognize an image while posting .'),
                                        );


  $form['captcha_fonts_path'] = array(
                                  '#type' => 'textfield',
                                  '#title' => t('TrueType Fonts Path'),
                                  '#default_value' => $fontPath,
                                  '#size' => 30,
                                  '#maxlength' => 255,
                                  '#description' => t('Location of the directory where the Truetype (.ttf) fonts are stored. If you do not provide any fonts, the module will use the default font for text.'),
                                );


  if (isset($fonts_path)) {
    $imagefontinfo .= t('Number of fonts found: ').count(_captcha_font_list());
  }

  $gdinfo = gd_info();
  $imagefontinfo .= '<br />'.t('GD Version: ').$gdinfo["GD Version"];
  $imagefontinfo .= '<br />'.t(' FreeType Support: ');
  $imagefontinfo .= ($gdinfo["FreeType Support"]==true) ? 'True' : 'False';
  $imagefontinfo .= '<br />';

  $form['captcha_info'] = array (
                           '#type' => 'item',
                           '#title' => t('Image and font information'),
                           '#value' => $imagefontinfo,
                          );

  return $form;
}

I coulda submitted a patch, but I was in a hurry ;)

Comments

freephile’s picture

Title: Captcha module cannot correctly store font path once incorrect font path is entered... » Similar problem in 5.x

In the most recent code $Id: captcha.inc,v 1.2 2007/01/31 09:46:06 heine , there is a similar problem in that the !file_check_directory($fonts_path) test is used throughout.

file_check_directory() (defined in file.inc) does not return a valid result UNLESS the directory is writable to the web server, which means that a 'valid' system font path such as /usr/local/share/fonts/ (not normally writable to the webserver) will not work to supply fonts to the Captcha module.

Solution: rewrite captcha.module to use the PHP function is_dir() since the module only needs read access to the font files.

Workaround: make a directory 'fonts' inside your Drupal files directory: eg. files/fonts and copy some ttf font files there to use in the configuration of Captcha

wundo’s picture

Status: Needs review » Closed (fixed)