function recipe_import_element_end in Recipe 6
Same name and namespace in other branches
- 7.2 modules/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
- plugins/
recipe_recipeML.module, line 262 - recipe_recipeML.module - Enables importing and exporting of recipeML format recipes.
Code
function recipe_import_element_end($parser, $name) {
global $ingredient, $yield, $data_string, $recipes, $recipe, $user;
switch ($name) {
case 'RECIPE':
$recipe->uid = $user->uid;
if ($recipe->yield == 0) {
$recipe->yield = 1;
}
if (!$recipe->notes) {
$recipe->notes = "Imported from RecipeML file";
}
if (!$recipe->title) {
$recipe->title = "RecipeML autotitle";
}
else {
if (!$recipe->teaser) {
$recipe->teaser = $recipe->title . " recipe";
}
if (!$recipe->body) {
$recipe->body = $recipe->title . " recipe";
}
}
$recipes[] = $recipe;
break;
case 'ING':
$recipe->ingredients[] = $ingredient;
break;
case 'YIELD':
$yield = FALSE;
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 ($yield) {
$recipe->yield = trim($data_string);
}
elseif ($preptime) {
$recipe->preptime = trim($data_string);
}
else {
$ingredient['quantity'] = trim($data_string);
}
break;
case 'UNIT':
// UNIT is contained in preptime, yield, as well as amt(ingredient).
if (!$preptime) {
if ($unit = recipe_unit_fuzzymatch(trim($data_string))) {
$ingredient['unit_id'] = $unit->id;
}
else {
if ($unit = recipe_unit_from_name('Unit')) {
$ingredient['unit_id'] = $unit->id;
if (strlen($ingredient['name']) > 0) {
$ingredient['name'] = $ingredient['name'] . ' ' . trim($data_string);
}
else {
$ingredient['name'] = trim($data_string);
}
}
}
}
break;
case 'ITEM':
if (strlen($ingredient['name']) > 0) {
$ingredient['name'] = trim($data_string) . ' ' . $ingredient['name'];
}
else {
$ingredient['name'] = trim($data_string);
}
break;
case 'YIELD':
$yield = FALSE;
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 'PREPTIME':
$preptime = FALSE;
break;
}
$data_string = '';
}