function merge_template in Recipe 7.2
Same name and namespace in other branches
- 6 plugins/recipe_mastercook4.module \merge_template()
- 7 includes/recipe_mastercook4.module \merge_template()
1 call to merge_template()
- recipe_mastercook4_export_single in modules/recipe_mastercook4.module
File
- modules/recipe_mastercook4.module, line 74
- Enables importing and exporting of MasterCook4 format recipes.
Code
function merge_template($node) {
$categories = '';
$factor = 1;
if (isset($node->recipe_custom_yield)) {
$factor = $node->recipe_custom_yield / $node->recipe_yield;
$node->recipe_yield = $node->recipe_custom_yield;
}
$unit_list = recipe_get_units();
$template = get_template();
$template = str_replace("<<title>>", filter_xss($node->title, array()), $template);
$source_items = field_get_items('node', $node, 'recipe_source');
$recipe_source = '';
if (!empty($source_items[0]['value'])) {
$recipe_source = strip_html_and_encode_entities($source_items[0]['value']);
}
$template = str_replace("<<recipeby>>", $recipe_source, $template);
$template = str_replace("<<servingsize>>", $node->recipe_yield, $template);
$prep_time_items = field_get_items('node', $node, 'recipe_prep_time');
$recipe_prep_time = '0:00';
if (!empty($prep_time_items[0]['value'])) {
$duration = $prep_time_items[0]['value'];
$hours = floor($duration / 60);
$minutes = sprintf("%02d", $duration % 60);
$recipe_prep_time = $hours . ':' . $minutes;
}
$template = str_replace("<<preptime>>", $recipe_prep_time, $template);
$template = str_replace("<<categories>>", $categories, $template);
$ingredient_items = field_get_items('node', $node, 'recipe_ingredient');
$ingredient_instance = field_read_instance('node', 'recipe_ingredient', 'recipe');
$quantity_format = $ingredient_instance['display']['default']['settings']['fraction_format'];
$abbreviation_setting = $ingredient_instance['display']['default']['settings']['unit_abbreviation'];
$recipe_ingredients = '';
foreach ($ingredient_items as $item) {
$ingredient = recipe_load_ingredient($item['iid']);
$item['name'] = $ingredient->name;
$name = filter_xss($item['name'], array());
$note = filter_xss($item['note'], array());
if ($item['quantity'] > 0) {
$quantity = recipe_ingredient_quantity_from_decimal($item['quantity'] * $factor, $quantity_format, TRUE);
$quantity = str_replace('⁄', '/', $quantity);
}
else {
$quantity = ' ';
}
$unit_display = '';
$item['unit'] = isset($unit_list[$item['unit_key']]) ? $unit_list[$item['unit_key']] : array();
if (!empty($item['unit']['abbreviation'])) {
if ($abbreviation_setting == 0) {
$unit_display = $item['unit']['abbreviation'];
}
else {
$unit_display = $item['quantity'] > 1 ? $item['unit']['plural'] : $item['unit']['name'];
}
}
$recipe_ingredients .= recipe_mastercook4_format_ingredient($name, $quantity, $unit_display, $note);
}
$template = str_replace("<<ingredients>>", $recipe_ingredients, $template);
$instructions_items = field_get_items('node', $node, 'recipe_instructions');
$recipe_instructions = '';
if (!empty($instructions_items[0]['value'])) {
$recipe_instructions = strip_html_and_encode_entities($instructions_items[0]['value']);
}
$template = str_replace("<<instructions>>", $recipe_instructions, $template);
$notes_items = field_get_items('node', $node, 'recipe_notes');
$recipe_notes = '';
if (!empty($notes_items[0]['value'])) {
$recipe_notes = 'NOTES : ' . strip_html_and_encode_entities($notes_items[0]['value']);
}
$template = str_replace("<<notes>>", $recipe_notes, $template);
$description_items = field_get_items('node', $node, 'recipe_description');
if (!empty($description_items[0]['value'])) {
$recipe_description = "DESCRIPTION : " . strip_html_and_encode_entities($description_items[0]['value']) . "\n\n";
$template = str_replace("<<description>>", $recipe_description, $template);
}
else {
$template = str_replace("<<description>>\n", "", $template);
}
return $template;
}