function theme_node_recipe in Recipe 5
A custom theme function.
By using this function to format our node-specific information, themes can override this presentation if they wish. We also wrap the default presentation in a CSS class that is prefixed by the module name. This way, style sheets can modify the output without requiring theme code.
2 theme calls to theme_node_recipe()
- recipe_export_html in ./
recipe.module - This function is called by recipe_export() to generate HTML for export.
- recipe_view in ./
recipe.module - Implementation of hook_view().
File
- ./
recipe.module, line 1361 - recipe.module - share recipes for drupal 5.x
Code
function theme_node_recipe($node, $yield_form = TRUE) {
// Get custom yield or default to a factor of 1
if ($yield_form && intval($node->yield) == $node->yield) {
if ($_POST['op'] == t('Change')) {
$yield = $_POST['custom_yield'];
}
else {
if ($_POST['op'] == t('Halve')) {
$yield = $_POST['custom_yield'] / 2;
}
else {
if ($_POST['op'] == t('Double')) {
$yield = $_POST['custom_yield'] * 2;
}
}
}
if ($yield && $yield != $node->yield && $node->yield != 0) {
$factor = $yield / $node->yield;
$node->yield = $yield;
}
else {
$factor = 1;
}
$_POST = array();
$yield = drupal_get_form('recipe_custom_yield_form', $node);
}
else {
$yield = $node->yield;
$factor = 1;
}
// Construct the $ingredients[] array
if ($node->ingredients) {
foreach ($node->ingredients as $ingredient) {
if (isset($ingredient->quantity) && $ingredient->name) {
if (!$ingredient->abbreviation) {
$ingredient->abbreviation = recipe_unit_abbreviation($ingredient->unit_id);
}
if ($ingredient->quantity > 0) {
$ingredient->quantity *= $factor;
}
else {
$ingredient->quantity = '';
}
if (variable_get('recipe_fraction_display', t('{%d} %d⁄%d'))) {
$ingredient->quantity = recipe_ingredient_quantity_from_decimal($ingredient->quantity);
}
if (!empty($ingredient->link)) {
$ingredient->name = l($ingredient->name, 'node/' . $ingredient->link);
}
$ingredients[] = $ingredient->quantity . ' <acronym title="' . recipe_unit_name($ingredient->unit_id) . '">' . $ingredient->abbreviation . '</acronym> ' . $ingredient->name;
}
}
}
// Construct the summary
$summary = '<table>';
$summary .= '<tr><th>' . t('Yield') . '</th><td>' . $yield . '</td></tr>';
if ($node->source) {
$summary .= '<tr><th>' . t('Source') . '</th><td>' . $node->source . '</td></tr>';
}
if ($node->preptime) {
if ($node->preptime < 60) {
$preptime = format_plural($node->preptime, '1 minute', '@count minutes');
}
elseif ($node->preptime % 60 == 0) {
$preptime = format_plural($node->preptime / 60, '1 hour', '@count hours');
}
else {
$preptime = t('!time hours', array(
'!time' => recipe_ingredient_quantity_from_decimal($node->preptime / 60),
));
}
$summary .= '<tr><th>' . t('Prep Time') . '</th><td>' . $preptime . '</td></tr>';
}
$vocabs = taxonomy_get_vocabularies('recipe');
if (count($vocabs) > 0) {
foreach ($vocabs as $vocab) {
$terms = taxonomy_node_get_terms_by_vocabulary($node->nid, $vocab->vid);
if (count($terms) > 0) {
$summary .= '<tr><th>' . $vocab->name . '</th><td>';
foreach ($terms as $term) {
$summary .= l($term->name, 'taxonomy/term/' . $term->tid) . ' ';
}
$summary .= '</td></tr>';
}
}
}
$summary .= '</table>';
// Create the output
$output = '';
$output .= '<div class="recipe-summary">' . theme('box', t('Summary'), $summary) . '</div>';
$output .= '<div class="recipe-description">' . theme('box', t('Description'), $node->body) . '</div>';
$output .= '<div class="recipe-ingredients">' . theme('box', t('Ingredients'), theme('item_list', $ingredients)) . '</div>';
$output .= '<div class="recipe-instructions">' . theme('box', t('Instructions'), $node->instructions) . '</div>';
if ($node->notes !== '') {
$output .= '<div class="recipe-notes">' . theme('box', t('Notes'), $node->notes) . '</div>';
}
return $output;
}