function merge_template in Recipe 6
Same name and namespace in other branches
- 7.2 modules/recipe_mastercook4.module \merge_template()
- 7 includes/recipe_mastercook4.module \merge_template()
1 call to merge_template()
File
- plugins/
recipe_mastercook4.module, line 73 - recipe_mastercook4.module - Enables importing and exporting of MasterCook4 format recipes.
Code
function merge_template($node = NULL) {
//prepare prepare time
$decimal_hours = $node->preptime / 60;
$hours = floor($decimal_hours);
$minutes = sprintf("%02d", floor(($decimal_hours - $hours) * 60));
$preptime = "{$hours}:{$minutes}";
//prepare categories
$categories = '';
$vocabs = taxonomy_get_vocabularies('recipe');
foreach ($vocabs as $vocab) {
$terms = taxonomy_node_get_terms_by_vocabulary($node, $vocab->vid);
foreach ($terms as $term) {
$term = array_shift($terms);
$categories .= sprintf("%-33s", $term->name);
}
}
$categories = wordwrap($categories, 66, "\n ");
//prepare ingredients
$ingredients = '';
foreach ($node->ingredients as $key => $i) {
$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->source, $template);
// merge serving size
$template = str_replace("<<servingsize>>", $node->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->instructions), $template);
// merge notes
if ($node->notes != '') {
$node->notes = "NOTES : " . strip_html_and_encode_entities($node->notes);
}
$template = str_replace("<<notes>>", $node->notes, $template);
return $template;
}