function recipe_recipeML_import_form_submit in Recipe 7
Same name and namespace in other branches
- 6 plugins/recipe_recipeML.module \recipe_recipeML_import_form_submit()
- 7.2 modules/recipe_recipeML.module \recipe_recipeML_import_form_submit()
File
- includes/recipe_recipeML.module, line 199
- recipe_recipeML.module - Enables importing and exporting of recipeML format recipes.
Code
function recipe_recipeML_import_form_submit($form, &$form_state) {
global $recipes, $recipe, $data_string;
$data = '';
$validators = array(
'file_validate_extensions' => array(
'mxp xml',
),
);
if ($file = file_save_upload('recipe_import_file', $validators, FALSE, FILE_EXISTS_RENAME)) {
$data = file_get_contents($file->uri);
drupal_set_message(t('The attached file was successfully uploaded'));
}
else {
drupal_set_message(t('The attched file failed to upload.'), 'error');
return;
}
$xml_parser = drupal_xml_parser_create($data);
xml_set_element_handler($xml_parser, 'recipe_import_element_start', 'recipe_import_element_end');
xml_set_character_data_handler($xml_parser, 'recipe_import_element_data');
if (!xml_parse($xml_parser, $data, 1)) {
watchdog('recipe', 'Failed to parse RecipeML file: @error at line @line.', array(
'@error' => xml_error_string(xml_get_error_code($xml_parser)),
'@line' => xml_get_current_line_number($xml_parser),
), WATCHDOG_WARNING);
}
xml_parser_free($xml_parser);
if ($_POST['op'] == t('Import')) {
foreach ($recipes as $import_recipe_array) {
if (($node = recipe_import_get_node($import_recipe_array)) != FALSE) {
node_save($node);
}
}
}
}