function recipe_recipeML_export_single in Recipe 6
Same name and namespace in other branches
- 7.2 modules/recipe_recipeML.module \recipe_recipeML_export_single()
- 7 includes/recipe_recipeML.module \recipe_recipeML_export_single()
1 call to recipe_recipeML_export_single()
1 string reference to 'recipe_recipeML_export_single'
- recipe_recipeML_recipeio in plugins/
recipe_recipeML.module - Implementation of hook_recipeio($type).
File
- plugins/
recipe_recipeML.module, line 53 - recipe_recipeML.module - Enables importing and exporting of recipeML format recipes.
Code
function recipe_recipeML_export_single($nid = NULL, $add_content_header = TRUE) {
if ($nid === NULL) {
drupal_set_message(t('Recipe not found.'));
drupal_not_found();
}
$node = node_load(array(
'nid' => $nid,
'type' => 'recipe',
));
// you should not be able to export unpublished recipes
if ($node->status == 0) {
drupal_access_denied();
return;
}
$vocabs = taxonomy_get_vocabularies('recipe');
$cat_string = '';
foreach ($vocabs as $vocab) {
$terms = taxonomy_node_get_terms_by_vocabulary($node, $vocab->vid);
foreach ($terms as $term) {
$term = array_shift($terms);
$cat_string .= $term->name . ', ';
}
$cat_string = substr($cat_string, 0, -2);
}
if ($cat_string != '') {
$cat_string = '<categories>' . $cat_string . '</categories>';
}
$output = '';
if ($add_content_header == TRUE) {
$output .= '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<!DOCTYPE recipeml PUBLIC "-//FormatData//DTD RecipeML 0.5//EN" "http://www.formatdata.com/recipeml/recipeml.dtd">' . "\n" . '<recipeml version="0.5" generator="http://drupal.org/project/recipe">' . "\n";
}
$output .= '<recipe>' . "\n" . '<head>' . "\n" . '<title>' . my_xml_escape($node->title) . "</title>\n" . ' <version>' . date('m-d-Y', $node->changed) . '</version>' . "\n" . ' <source>' . my_xml_escape($node->source == '' ? $base_url . '/node/' . $node->nid : $node->source) . '</source>' . "\n" . ' <yield><qty>' . floatval($node->yield) . '</qty><unit>' . my_xml_escape($node->yield_unit == '' ? t('Servings') : $node->yield_unit) . '</unit></yield>' . "\n" . ' <preptime type="cooking"><time><qty>' . $node->preptime . '</qty><timeunit>minutes</timeunit></time></preptime>' . "\n{$cat_string}" . '</head>' . "\n" . '<description>' . my_xml_escape($node->body) . '</description>' . "\n" . '<ingredients>';
foreach ($node->ingredients as $ingredient) {
$prep = '';
if (strlen($ingredient['note']) > 0) {
$prep = '<prep>' . $ingredient['note'] . '</prep>';
}
$output .= "\n" . '<ing><amt><qty>' . $ingredient['quantity'] . '</qty><unit>' . $ingredient['abbreviation'] . '</unit></amt><item>' . $ingredient['name'] . "</item>{$prep}</ing>";
}
$output .= "\n" . '</ingredients>' . "\n" . '<directions>' . my_xml_escape($node->instructions) . '</directions>' . "\n" . '<note>' . my_xml_escape($node->notes) . '</note>' . "\n" . '</recipe>' . "\n";
if ($add_content_header == TRUE) {
$output .= '</recipeml>';
drupal_set_header('Content-type: text/xml');
}
return $output;
}