function merge_template in Recipe 7
Same name and namespace in other branches
- 6 plugins/recipe_mastercook4.module \merge_template()
- 7.2 modules/recipe_mastercook4.module \merge_template()
1 call to merge_template()
File
- includes/
recipe_mastercook4.module, line 78 - recipe_mastercook4.module - Enables importing and exporting of MasterCook4 format recipes.
Code
function merge_template($node) {
//prepare prepare time
$decimal_hours = $node->recipe_preptime / 60;
$hours = floor($decimal_hours);
$minutes = sprintf("%02d", floor(($decimal_hours - $hours) * 60));
$preptime = "{$hours}:{$minutes}";
$categories = '';
//prepare ingredients
$factor = 1;
if (isset($node->recipe_custom_yield)) {
$factor = $node->recipe_custom_yield / $node->recipe_yield;
$node->recipe_yield = $node->recipe_custom_yield;
}
$ingredients = '';
$unit_list = recipe_get_units();
foreach ($node->recipe_ingredients['ing'] as $key => $i) {
if ($i['quantity'] > 0) {
$i['quantity'] *= $factor;
}
else {
$i['quantity'] = ' ';
}
if (isset($unit_list[$i['unit_key']])) {
// Print the singular or plural term depending on the quantity.
$title = $i['quantity'] > 1 ? $unit_list[$i['unit_key']]['plural'] : $unit_list[$i['unit_key']]['name'];
}
else {
$title = $i['unit_key'];
}
// Print the abbreviation if recipe_unit_display says to or the abbreviation is blank (ie = Unit, which we don't print).
if (!isset($i['abbreviation']) && isset($unit_list[$i['unit_key']])) {
$i['abbreviation'] = $unit_list[$i['unit_key']]['abbreviation'];
}
if (empty($i['abbreviation'])) {
$i['abbreviation'] = ' ';
}
$i['str_unit'] = '';
if (variable_get('recipe_unit_display', 0) == 0 || $i['abbreviation'] == ' ') {
$i['str_unit'] = $i['abbreviation'];
}
else {
$i['str_unit'] = $title;
}
$ingredients .= format_mastercook4_ingredient($i);
}
// get the template string
$template = get_template();
// merge title
$template = str_replace("<<title>>", $node->title, $template);
// merge recipe by
$template = str_replace("<<recipeby>>", $node->recipe_source, $template);
// merge serving size
$template = str_replace("<<servingsize>>", $node->recipe_yield, $template);
// merge preptime
$template = str_replace("<<preptime>>", $preptime, $template);
// merge categories
$template = str_replace("<<categories>>", $categories, $template);
// merge ingredients
$template = str_replace("<<ingredients>>", $ingredients, $template);
// merge instructions
$template = str_replace("<<instructions>>", strip_html_and_encode_entities($node->recipe_instructions), $template);
// merge notes
if ($node->recipe_notes != '') {
$node->recipe_notes = "NOTES : " . strip_html_and_encode_entities($node->recipe_notes);
}
$template = str_replace("<<notes>>", $node->recipe_notes, $template);
return $template;
}