function local_fonts_add_fontface_validate in @font-your-face 6.2
Implementation of hook_form_validate().
File
- modules/
local_fonts/ local_fonts.module, line 169
Code
function local_fonts_add_fontface_validate($form, &$form_state) {
// Ensure a font family with the same results does not exist in the database.
$values = $form_state['values'];
$font_path = strtr(preg_replace('#[^a-zA-Z0-9]+#', ' ', $values['css_family']), ' ', '_');
$font_style = $values['css_style'];
$font_weight = $values['css_weight'];
$local_fonts_directory = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . file_directory_path() . '/fontyourface/local_fonts';
$destination_directory = $local_fonts_directory . '/' . $font_path;
$file_uploaded = FALSE;
if (file_check_directory($local_fonts_directory, FILE_CREATE_DIRECTORY) && file_check_directory($destination_directory, FILE_CREATE_DIRECTORY)) {
// Validate the files against their extension
$files = $_FILES['files']['name'];
foreach ($files as $key => $filename) {
$file_object = new stdClass();
$file_object->filename = $filename;
if (!empty($file_object->filename)) {
$validation = file_validate_extensions($file_object, $key);
if (is_array($validation) && count($validation) > 0) {
form_set_error($key, implode(', ', $validation));
}
else {
$file_uploaded = TRUE;
}
// else
}
// if
}
// foreach
}
else {
form_set_error('files', t('Error creating file directory.'));
}
// else
if (!$file_uploaded) {
form_set_error('files', t('Upload at least one font file to go with the font family.'));
}
// if
}