function recipe_import_element_end in Recipe 7.2
Same name and namespace in other branches
- 6 plugins/recipe_recipeML.module \recipe_import_element_end()
- 7 includes/recipe_recipeML.module \recipe_import_element_end()
Call-back function used by the XML parser.
1 string reference to 'recipe_import_element_end'
File
- modules/
recipe_recipeML.module, line 344 - Enables importing and exporting of recipeML format recipes.
Code
function recipe_import_element_end($parser, $name) {
global $recipes, $recipe, $data_string;
switch ($name) {
case 'RECIPE':
if ($recipe['yield'] == 0) {
$recipe['yield'] = 1;
}
if (empty($recipe['title'])) {
$recipe['title'] = "RecipeML auto title";
}
if (empty($recipe['description'])) {
$recipe['description'] = "RecipeML auto description.";
}
if (empty($recipe['notes'])) {
$recipe['notes'] = "Imported from RecipeML file";
}
$recipes[] = $recipe;
break;
case 'YIELD':
$recipe['__region'] = '';
break;
case "TITLE":
$recipe['title'] = trim($data_string);
break;
case "SOURCE":
$recipe['source'] = trim($data_string);
break;
case "CATEGORIES":
$xmlterms = explode(',', $data_string);
foreach ($xmlterms as $xmlterm) {
$recipe['categories'][] = trim($xmlterm);
}
break;
// QTY tag appears in more than one container tag.
case 'QTY':
if ($recipe['__region'] == 'YIELD') {
$recipe['yield'] = trim($data_string);
}
elseif ($recipe['__region'] == 'PREPTIME') {
$recipe['preptime'] = trim($data_string);
}
else {
$ing = array_pop($recipe['ingredients']);
$ing['quantity'] = trim($data_string);
$recipe['ingredients'][] = $ing;
}
break;
case 'UNIT':
// UNIT is contained in PREPTIME, YIELD, as well as ING->AMT.
if ($recipe['__region'] == 'ING') {
$ing = array_pop($recipe['ingredients']);
$ing['unit_name'] = trim($data_string);
// Try to match unit.
if ($unit_key = recipe_unit_fuzzymatch(trim($data_string))) {
$ing['unit_key'] = $unit_key;
}
else {
$ing['unit_key'] = 'unit';
if (strlen($ing['ingredient_name']) > 0) {
$ing['ingredient_name'] = $ing['ingredient_name'] . ' ' . trim($data_string);
}
else {
$ing['ingredient_name'] = trim($data_string);
}
}
$recipe['ingredients'][] = $ing;
}
break;
case 'ITEM':
$ing = array_pop($recipe['ingredients']);
if (strlen($ing['ingredient_name']) > 0) {
$ing['ingredient_name'] = trim($data_string) . ' ' . $ing['ingredient_name'];
}
else {
$ing['ingredient_name'] = trim($data_string);
}
$recipe['ingredients'][] = $ing;
break;
case 'DIRECTIONS':
$recipe['instructions'] .= trim($data_string);
break;
case 'STEP':
$recipe['instructions'] .= trim($data_string) . "\n";
break;
case 'NOTE':
$recipe['notes'] = trim($data_string);
break;
case 'SOURCE':
$recipe['source'] = trim($data_string);
break;
case 'PREP':
$ing = array_pop($recipe['ingredients']);
$ing['ingredient_note'] = trim($data_string);
$recipe['ingredients'][] = $ing;
case 'PREPTIME':
$recipe['__region'] = '';
break;
}
$data_string = '';
}