function patterns_import_validate in Patterns 5
Same name and namespace in other branches
- 6.2 patterns.module \patterns_import_validate()
- 6 patterns.module \patterns_import_validate()
- 7.2 includes/forms/import.inc \patterns_import_validate()
- 7 includes/forms/import.inc \patterns_import_validate()
File
- ./
patterns.module, line 218 - Enables extremely simple adding/removing features to your site with minimal to no configuration
Code
function patterns_import_validate($form_id, $values) {
global $form_values;
if ($file = file_check_upload('xmlfile')) {
$form_values['xmlsource'] = file_get_contents($file->filepath);
}
else {
if (isset($values['xmlfile'])) {
form_set_error('xmlfile', t('Error uploading XML file.'));
}
else {
if ($values['xmlurl']) {
if (!ini_get('allow_url_fopen')) {
form_set_error('xmlsource', t('allow_url_fopen must be enabled in your php configuration in order to use this feature.'));
return;
}
if (!($form_values['xmlsource'] = file_get_contents($values['xmlurl']))) {
form_set_error('xmlsource', t('Failed to retreive the pattern specified.'));
return;
}
$form_values['xmlname'] = preg_replace('/\\.[^\\.]*$/', '', basename($form_values['xmlurl']));
}
}
}
if (strpos($form_values['xmlsource'], '<?xml') !== 0) {
$form_values['xmlsource'] = '<?xml version="1.0" encoding="ISO-8859-1"?>' . $form_values['xmlsource'];
}
if ($form_values['xmlname'] && preg_match('/[^a-zA-Z0-9_]/', $form_values['xmlname'])) {
form_set_error('xmlname', t('You can only include letters, numbers, and underscores in the pattern identifier.'));
}
else {
if ($form_values['xmlname'] && preg_match('/^_/', $form_values['xmlname'])) {
form_set_error('xmlname', t('You cannot start the pattern identifier with an underscore.'));
}
}
$parse = xml_parser_create();
xml_parse_into_struct($parse, $form_values['xmlsource'], $vals, $index);
// Check that the xml was properly parsed and also that the
// root <pattern> tag and also an <info> tag were used.
if (!$vals || $vals[0]['tag'] != 'PATTERN' || $vals[1]['tag'] != 'INFO') {
form_set_error('xmlsource', t('Error parsing the XML, please check your syntax and try again.'));
}
}