You are here

function recipe_import_parse in Recipe 6

Same name and namespace in other branches
  1. 7.2 recipe.admin.inc \recipe_import_parse()
  2. 7 recipe.module \recipe_import_parse()

Import parsing controller which loads the actual parsing instances based on recipe_format.

All parser instances should return a $recipe object that looks like this:

$recipe = array( 'title' => 'recipe title string', 'ingredients' => array of ingredients items(below); 'instuctions' => 'string of instructions' );

ingredients items = array( 'quantity' => 'ingredient_name' => 'unit_name' => 'unit_obj' => stdClass, comes from database lookup: see recipe_unit_fuzzymatch(). ==FALSE if no-match 'ingre_obj' => comes from database lookup: see recipe_ingredient_match(). ==FALSE if no-match );

2 calls to recipe_import_parse()
recipe_import_form_build_preview in ./recipe.module
Import preview routine that allows that users to see what actually will be imported before doing so.
recipe_import_form_submit in ./recipe.module
Submit handler for the single recipe import form.

File

./recipe.module, line 1569
recipe.module - share recipes

Code

function recipe_import_parse($form, &$form_state) {
  $import_function = $form_state['values']['recipe_format'];
  $text = $form_state['values']['recipe_import_text'];
  $recipe = array();
  if (function_exists($import_function)) {
    $recipe = call_user_func($import_function, $text);
    return $recipe;
  }
  else {
    drupal_set_message(t('Recipe import function does not exist(%the_function)', array(
      '%the_function' => $import_function,
    )), 'error');
    return FALSE;
  }
}