function _minisite_field_validate_minisite_asset in Mini site 7
Validate minisite asset.
File
- includes/
minisite.field.inc, line 336 - Minisite field.
Code
function _minisite_field_validate_minisite_asset(stdClass $file, $extensions) {
$errors = array();
// Validate minisite assets.
$archive = MinisiteArchive::open($file);
if (!$archive) {
$errors[] = t('Unable to open minisite archive file.');
return $errors;
}
$tree = $archive
->filesTree();
// Ignore __MACOSX folder.
unset($tree['__MACOSX']);
// Limit directory structure in minisite.
$root_files = array_keys($tree);
if (count($root_files) !== 1 || !is_array($tree[$root_files[0]])) {
$errors[] = t('Minisite must have a single top level directory.');
return $errors;
}
$top_folder = $root_files[0];
$top_level = $tree[$top_folder];
if (!array_key_exists('index.html', $top_level)) {
$errors[] = t('Minisite must contain a index.html file.');
}
$files = $archive
->filesList();
// Check minisite asset files extensions.
$invalid_files = MinisiteArchive::fileExtensionCheck($files, $extensions);
if (!empty($invalid_files)) {
foreach ($invalid_files as $invalid_file) {
$errors[] = t('Minisite contains files with invalid extensions: %files. Only files with the following extensions are allowed: %allowed-extensions', array(
'%allowed-extensions' => $extensions,
'%files' => $invalid_file,
));
}
}
return $errors;
}