You are here

function _image_captcha_get_available_fonts_from_directories in CAPTCHA 6.2

Same name and namespace in other branches
  1. 8 image_captcha/image_captcha.module \_image_captcha_get_available_fonts_from_directories()
  2. 7 image_captcha/image_captcha.admin.inc \_image_captcha_get_available_fonts_from_directories()

Helper function to get fonts from the given directories.

Parameters

$directories (optional) an array of directories: to recursively search through, if not given, the default directories will be used.

Return value

an array of fonts file objects (with fields 'name', 'basename' and 'filename'), keyed on the md5 hash of the font path (to have an easy token that can be used in an url without en/decoding issues).

1 call to _image_captcha_get_available_fonts_from_directories()
_image_captcha_settings_form_font_section in image_captcha/image_captcha.admin.inc
Form elements for the font specific setting.

File

image_captcha/image_captcha.admin.inc, line 323
Functions for administration/settings interface.

Code

function _image_captcha_get_available_fonts_from_directories($directories = NULL) {

  // If no fonts directories are given: use the default.
  if ($directories === NULL) {
    $directories = array(
      drupal_get_path('module', 'image_captcha') . '/fonts',
      'sites/all/libraries/fonts',
      conf_path() . '/libraries/fonts',
    );
  }

  // Collect the font information.
  $fonts = array();
  foreach ($directories as $directory) {
    foreach (file_scan_directory($directory, '\\.[tT][tT][fF]$') as $filename => $font) {
      $fonts[md5($filename)] = $font;
    }
  }
  return $fonts;
}