| 1 |
<?php |
<?php |
| 2 |
// $Id: recipe.module,v 1.80 2007/10/17 17:33:34 marble Exp $ |
// $Id: $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 6 |
* recipe.module - share recipes |
* recipe.module - share recipes |
| 7 |
* for drupal 5.x |
* for drupal 5.x |
| 8 |
* |
* |
| 9 |
|
* Updated to drupal 6.x by shadow |
| 10 |
|
* |
| 11 |
* @todo |
* @todo |
| 12 |
*/ |
*/ |
| 13 |
|
|
| 72 |
/** |
/** |
| 73 |
* Implementation of hook_help(). |
* Implementation of hook_help(). |
| 74 |
*/ |
*/ |
| 75 |
function recipe_help($section) { |
function recipe_help($path, $arg) { |
| 76 |
switch ($section) { |
switch ($path) { |
| 77 |
case 'node/add/recipe': |
case 'node/add/recipe': |
| 78 |
return variable_get("recipe_help", ""); |
return variable_get("recipe_help", ""); |
| 79 |
} |
} |
| 144 |
'#type' => 'select', |
'#type' => 'select', |
| 145 |
'#title' => t("Preparation time"), |
'#title' => t("Preparation time"), |
| 146 |
'#default_value' => $node->preptime, |
'#default_value' => $node->preptime, |
| 147 |
'#options' => array (5 => t('5 minutes'), 10 => t('10 minutes'), 15 => t('15 minutes'), 20 => t('20 minutes'), 30 => t('30 minutes'), 45 => t('45 minutes'), 60 => t('1 hour'), 90 => t('1 1/2 hours'), 120 => t('2 hours'), 150 => t('2 1/2 hours'), 180 => t('3 hours'), 210 => t('3 1/2 hours'), 240 => t('4 hours'), 300 => t('5 hours'), 360 => t('6 hours')), |
'#options' => array(5 => t('5 minutes'), 10 => t('10 minutes'), 15 => t('15 minutes'), 20 => t('20 minutes'), 30 => t('30 minutes'), 45 => t('45 minutes'), 60 => t('1 hour'), 90 => t('1 1/2 hours'), 120 => t('2 hours'), 150 => t('2 1/2 hours'), 180 => t('3 hours'), 210 => t('3 1/2 hours'), 240 => t('4 hours'), 300 => t('5 hours'), 360 => t('6 hours')), |
| 148 |
'#description' => t("How long does this recipe take to prepare (i.e. elapsed time)"), |
'#description' => t("How long does this recipe take to prepare (i.e. elapsed time)"), |
| 149 |
); |
); |
| 150 |
$form["source"] = array( |
$form["source"] = array( |
| 158 |
|
|
| 159 |
// Table of existing ingredients |
// Table of existing ingredients |
| 160 |
$form['ingredients']['#tree'] = TRUE; |
$form['ingredients']['#tree'] = TRUE; |
| 161 |
$system = variable_get('recipe_ingredient_system','complex'); |
$system = variable_get('recipe_ingredient_system', 'complex'); |
| 162 |
if ($system == 'complex') { |
if ($system == 'complex') { |
| 163 |
$form['ingredients']['headings'] = array( |
$form['ingredients']['headings'] = array( |
| 164 |
'#value' => '<div><table ><thead><tr><th>'.t('Quantity').'</th><th>'. |
'#value' => '<div><table ><thead><tr><th>'. t('Quantity') .'</th><th>'. |
| 165 |
t('Units').'</th><th>'.t('Ingredient Name'). |
t('Units') .'</th><th>'. t('Ingredient Name') . |
| 166 |
'</th></tr></thead>'."\n".'<tbody>', |
'</th></tr></thead>'."\n".'<tbody>', |
| 167 |
); |
); |
| 168 |
} |
} |
| 169 |
else { |
else { |
| 170 |
$form['ingredients']['headings'] = array( |
$form['ingredients']['headings'] = array( |
| 171 |
'#value' => '<div><table ><thead><tr><th>'.t('Ingredients').'</th></tr></thead>'."\n".'<tbody>', |
'#value' => '<div><table ><thead><tr><th>'. t('Ingredients') .'</th></tr></thead>'."\n".'<tbody>', |
| 172 |
); |
); |
| 173 |
} |
} |
| 174 |
$rows = array(); |
$rows = array(); |
| 177 |
if ($node->ingredients) { |
if ($node->ingredients) { |
| 178 |
foreach ($node->ingredients as $id => $ingredient) { |
foreach ($node->ingredients as $id => $ingredient) { |
| 179 |
$num_ingredients = $id+1; |
$num_ingredients = $id+1; |
| 180 |
if ($id == 0) { |
if ($id == 0) { |
| 181 |
$j = '0'; |
$j = '0'; |
| 182 |
} |
} |
| 183 |
else { |
else { |
| 260 |
} // if ($node->ingredients) |
} // if ($node->ingredients) |
| 261 |
// Add ten more spots for ingredients than are already used |
// Add ten more spots for ingredients than are already used |
| 262 |
for ($i = $num_ingredients; $i < $num_ingredients+10; $i++) { |
for ($i = $num_ingredients; $i < $num_ingredients+10; $i++) { |
| 263 |
if ($i == 0) { |
if ($i == 0) { |
| 264 |
$j = '0'; |
$j = '0'; |
| 265 |
} |
} |
| 266 |
else { |
else { |
| 386 |
$form['recipe_ingredient_system'] = array( |
$form['recipe_ingredient_system'] = array( |
| 387 |
'#type' => 'radios', |
'#type' => 'radios', |
| 388 |
'#title' => t('Ingredient entering system'), |
'#title' => t('Ingredient entering system'), |
| 389 |
'#default_value' => variable_get('recipe_ingredient_system','complex'), |
'#default_value' => variable_get('recipe_ingredient_system', 'complex'), |
| 390 |
'#options' => $options, |
'#options' => $options, |
| 391 |
'#description' => t('The simple ingredient system allows all ingredients to be entered on one line. The complex system forces the user to seperate the quanity and units from the ingredient'), |
'#description' => t('The simple ingredient system allows all ingredients to be entered on one line. The complex system forces the user to seperate the quanity and units from the ingredient'), |
| 392 |
); |
); |
| 422 |
* |
* |
| 423 |
* Note: when editing this function you must visit 'admin/menu' to reset the cache |
* Note: when editing this function you must visit 'admin/menu' to reset the cache |
| 424 |
*/ |
*/ |
| 425 |
function recipe_menu($may_cache) { |
function recipe_menu() { |
| 426 |
$items = array(); |
$items = array(); |
| 427 |
|
$items['recipe'] = array( |
|
if ($may_cache) { |
|
|
$items[] = array( |
|
|
'path' => 'node/add/recipe', |
|
|
'title' => t('Recipe'), |
|
|
'access' => user_access('create recipes') |
|
|
); |
|
|
$items[] = array( |
|
|
'path' => 'recipe', |
|
| 428 |
'title' => t('Recipes'), |
'title' => t('Recipes'), |
| 429 |
'callback' => 'recipe_page', |
'page callback' => 'recipe_page', |
| 430 |
'access' => user_access('access content'), |
'access arguments' => array('access content'), |
| 431 |
'type' => MENU_SUGGESTED_ITEM |
'type' => MENU_SUGGESTED_ITEM |
| 432 |
); |
); |
| 433 |
$items[] = array( |
$items['recipe/ingredient/autocomplete'] = array( |
|
'path' => 'recipe/ingredient/autocomplete', |
|
| 434 |
'title' => t('Ingredient autocomplete'), |
'title' => t('Ingredient autocomplete'), |
| 435 |
'callback' => 'recipe_autocomplete_page', |
'page callback' => 'recipe_autocomplete_page', |
| 436 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 437 |
'access' => user_access('access content') |
'access arguments' => array('access content') |
| 438 |
); |
); |
| 439 |
$items[] = array( |
$items['recipe/export'] = array( |
| 440 |
'path' => 'recipe/export', |
'page callback' => 'recipe_export', |
|
'callback' => 'recipe_export', |
|
| 441 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 442 |
'access' => user_access('access content') |
'access arguments' => array('access content') |
|
); |
|
|
$items[] = array( |
|
|
'path' => 'recipe/importolddb', |
|
|
'title' => t('import old recipes'), |
|
|
'callback' => 'recipe_import_from_46', |
|
|
'type' => MENU_SUGGESTED_ITEM, |
|
|
'access' => user_access('create recipes') |
|
| 443 |
); |
); |
| 444 |
$items[] = array( |
$items['admin/settings/recipe'] = array( |
|
'path' => 'admin/settings/recipe', |
|
| 445 |
'title' => t('Recipe module'), |
'title' => t('Recipe module'), |
| 446 |
'description' => t('Settings that control how the recipe module functions.'), |
'description' => t('Settings that control how the recipe module functions.'), |
| 447 |
'callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 448 |
'callback arguments' => 'recipe_admin_settings', |
'page arguments' => array('recipe_admin_settings'), |
| 449 |
'access' => user_access('administer site configuration'), |
'access arguments' => array('administer site configuration'), |
| 450 |
'type' => MENU_NORMAL_ITEM, |
'type' => MENU_NORMAL_ITEM, |
| 451 |
); |
); |
|
} |
|
| 452 |
return $items; |
return $items; |
| 453 |
} |
} |
| 454 |
|
|
| 455 |
/** |
/** |
| 456 |
* Implementation of hook_access(). |
* Implementation of hook_access(). |
| 457 |
*/ |
*/ |
| 458 |
function recipe_access($op, $node) { |
function recipe_access($op, $node, $account) { |
| 459 |
global $user; |
global $user; |
| 460 |
|
|
| 461 |
if ($op == 'create') { |
if ($op == 'create') { |
| 508 |
function recipe_view(&$node, $teaser = FALSE, $page = FALSE) { |
function recipe_view(&$node, $teaser = FALSE, $page = FALSE) { |
| 509 |
if ($page) { |
if ($page) { |
| 510 |
drupal_set_breadcrumb(array(l(t('Home'), ''), l(t('Recipes'), 'recipe'))); |
drupal_set_breadcrumb(array(l(t('Home'), ''), l(t('Recipes'), 'recipe'))); |
| 511 |
drupal_add_css(drupal_get_path('module', 'recipe') . '/recipe.css'); |
drupal_add_css(drupal_get_path('module', 'recipe') .'/recipe.css'); |
| 512 |
} |
} |
| 513 |
$node = recipe_node_prepare($node, $teaser); |
$node = recipe_node_prepare($node, $teaser); |
| 514 |
|
|
| 515 |
$node->content['body'] = array( |
$node->content['body'] = array( |
| 516 |
'#value' => $teaser ? $node->teaser : theme('node_recipe', $node, $page), |
'#value' => $teaser ? $node->teaser : theme('recipe_node', $node, $page), |
| 517 |
'#weight' => 1, |
'#weight' => 1, |
| 518 |
); |
); |
| 519 |
|
|
| 526 |
function recipe_unit_options() { |
function recipe_unit_options() { |
| 527 |
static $options; |
static $options; |
| 528 |
static $unit_rs; |
static $unit_rs; |
| 529 |
if(!isset($unit_rs)) { |
if ( !isset( $unit_rs ) ) { |
| 530 |
$unit_rs = db_query('SELECT id,type,name,abbreviation FROM {recipe_unit} ORDER BY type ASC, metric'); |
$unit_rs = db_query('SELECT id,type,name,abbreviation FROM {recipe_unit} ORDER BY type ASC, metric'); |
| 531 |
$options = array(); |
$options = array(); |
| 532 |
while ($r = db_fetch_object($unit_rs)) { |
while ($r = db_fetch_object($unit_rs)) { |
| 534 |
if (!isset($options[$r->type])) { |
if (!isset($options[$r->type])) { |
| 535 |
$options[$r->type] = array(); |
$options[$r->type] = array(); |
| 536 |
} |
} |
| 537 |
$options[$r->type][$r->id] = $r->name.' ('.$r->abbreviation.')'; |
$options[$r->type][$r->id] = $r->name .' ('. $r->abbreviation .')'; |
| 538 |
} |
} |
| 539 |
else { |
else { |
| 540 |
$options[$r->id] = $r->name.' ('.$r->abbreviation.')'; |
$options[$r->id] = $r->name .' ('. $r->abbreviation .')'; |
| 541 |
} |
} |
| 542 |
} |
} |
| 543 |
} |
} |
| 555 |
|
|
| 556 |
if (!$ingredient_id) { |
if (!$ingredient_id) { |
| 557 |
global $active_db; |
global $active_db; |
| 558 |
$node_link = db_result(db_query("SELECT nid FROM {node} WHERE title = '%s'", $name)); |
$node_link = db_result(db_query("SELECT nid FROM {node} n WHERE title = '%s'", $name)); |
| 559 |
|
|
| 560 |
db_query("INSERT INTO {recipe_ingredient} (name, link) VALUES ('%s', '%s')", $name, $node_link); |
db_query("INSERT INTO {recipe_ingredient} (name, link) VALUES ('%s', '%s')", $name, $node_link); |
| 561 |
$ingredient_id = db_result(db_query("SELECT id FROM {recipe_ingredient} WHERE LOWER(name)='%s'", trim(strtolower($name)))); |
$ingredient_id = db_result(db_query("SELECT id FROM {recipe_ingredient} WHERE LOWER(name)='%s'", trim(strtolower($name)))); |
| 562 |
} |
} |
| 620 |
} |
} |
| 621 |
$denominator = $overrides[$conversionstr][1]; |
$denominator = $overrides[$conversionstr][1]; |
| 622 |
$numerator = (floor($conversion) * $denominator) + $overrides[$conversionstr][0]; |
$numerator = (floor($conversion) * $denominator) + $overrides[$conversionstr][0]; |
| 623 |
} else { |
} |
| 624 |
|
else { |
| 625 |
$numerator = $conversion * $power; |
$numerator = $conversion * $power; |
| 626 |
$denominator = $power; |
$denominator = $power; |
| 627 |
} |
} |
| 628 |
|
|
| 629 |
$hcf = recipe_euclid ($numerator, $denominator); |
$hcf = recipe_euclid($numerator, $denominator); |
| 630 |
|
|
| 631 |
$numerator = $numerator/$hcf; |
$numerator = $numerator/$hcf; |
| 632 |
$denominator = $denominator/$hcf; |
$denominator = $denominator/$hcf; |
| 648 |
else { |
else { |
| 649 |
/* remove just the curly braces, but keep everything between them */ |
/* remove just the curly braces, but keep everything between them */ |
| 650 |
$ingredient_quantity = preg_replace('/{|}/', '', $ingredient_quantity); |
$ingredient_quantity = preg_replace('/{|}/', '', $ingredient_quantity); |
| 651 |
} |
} |
| 652 |
} |
} |
| 653 |
|
|
| 654 |
return filter_xss_admin($ingredient_quantity); |
return filter_xss_admin($ingredient_quantity); |
| 679 |
* (by comparing the old and new ingredients first) |
* (by comparing the old and new ingredients first) |
| 680 |
*/ |
*/ |
| 681 |
function recipe_save_ingredients($node) { |
function recipe_save_ingredients($node) { |
| 682 |
if(!$node->ingredients) { |
if (!$node->ingredients) { |
| 683 |
$node->ingredients = array(); |
$node->ingredients = array(); |
| 684 |
} |
} |
| 685 |
$changes = recipe_ingredients_diff($node->ingredients, recipe_load_ingredients($node)); |
$changes = recipe_ingredients_diff($node->ingredients, recipe_load_ingredients($node)); |
| 705 |
/** |
/** |
| 706 |
* Compares two arrays of ingredients and returns the differences |
* Compares two arrays of ingredients and returns the differences |
| 707 |
*/ |
*/ |
| 708 |
function recipe_ingredients_diff($a1,$a2) { |
function recipe_ingredients_diff($a1, $a2) { |
| 709 |
$return->add = array(); |
$return->add = array(); |
| 710 |
$return->remove = array(); |
$return->remove = array(); |
| 711 |
$return->update = array(); |
$return->update = array(); |
| 714 |
$pl = (object)$pl; |
$pl = (object)$pl; |
| 715 |
$pl->name = trim($pl->name); |
$pl->name = trim($pl->name); |
| 716 |
if ($pl->name) { |
if ($pl->name) { |
| 717 |
if (!_in_array($pl,$return->add)) { |
if (!_in_array($pl, $return->add)) { |
| 718 |
// Duplicate entries for the same ingredient are ignored. |
// Duplicate entries for the same ingredient are ignored. |
| 719 |
if (!_in_array($pl, $a2)) |
if (!_in_array($pl, $a2)) |
| 720 |
$return->add[] = $pl; |
$return->add[] = $pl; |
| 721 |
else |
else |
| 722 |
if (!_in_array($pl,$return->update)) |
if (!_in_array($pl, $return->update)) |
| 723 |
$return->update[] = $pl; |
$return->update[] = $pl; |
| 724 |
} |
} |
| 725 |
} |
} |
| 738 |
*/ |
*/ |
| 739 |
function _in_array($a, $b) { |
function _in_array($a, $b) { |
| 740 |
$a->name = trim(strtolower($a->name)); |
$a->name = trim(strtolower($a->name)); |
| 741 |
foreach($b as $row) { |
foreach ($b as $row) { |
| 742 |
$compareto=""; |
$compareto=""; |
| 743 |
if (is_array($row)) { |
if (is_array($row)) { |
| 744 |
$compareto = trim(strtolower($row["name"])); |
$compareto = trim(strtolower($row["name"])); |
| 745 |
} else { |
} |
| 746 |
|
else { |
| 747 |
$compareto = trim(strtolower($row->name)); |
$compareto = trim(strtolower($row->name)); |
| 748 |
} |
} |
| 749 |
if ($a->name === $compareto) |
if ($a->name === $compareto) |
| 774 |
AND ri.unit_id = u.id |
AND ri.unit_id = u.id |
| 775 |
AND ri.nid=%d |
AND ri.nid=%d |
| 776 |
ORDER BY |
ORDER BY |
| 777 |
ri.id', $node->nid); |
ri.id', $node->nid); |
| 778 |
$ingredients = array(); |
$ingredients = array(); |
| 779 |
while ($ingredient = db_fetch_object($rs)) { |
while ($ingredient = db_fetch_object($rs)) { |
| 780 |
$ingredients[] = $ingredient; |
$ingredients[] = $ingredient; |
| 834 |
*/ |
*/ |
| 835 |
function recipe_export($type = 'html', $nid = 0) { |
function recipe_export($type = 'html', $nid = 0) { |
| 836 |
$type = drupal_strtolower($type); |
$type = drupal_strtolower($type); |
| 837 |
$export_function = 'recipe_export_' . $type; |
$export_function = 'recipe_export_'. $type; |
| 838 |
|
|
| 839 |
if (function_exists($export_function)) { |
if (function_exists($export_function)) { |
| 840 |
echo call_user_func($export_function, $nid); |
echo call_user_func($export_function, $nid); |
| 854 |
* - string containing HTML representing the recipe |
* - string containing HTML representing the recipe |
| 855 |
*/ |
*/ |
| 856 |
function recipe_export_html($nid) { |
function recipe_export_html($nid) { |
| 857 |
if($nid == 0) { drupal_goto('recipe'); } |
if ($nid == 0) { |
| 858 |
|
drupal_goto('recipe'); |
| 859 |
|
} |
| 860 |
$node = node_load(array('nid' => $nid, 'type' => 'recipe')); |
$node = node_load(array('nid' => $nid, 'type' => 'recipe')); |
| 861 |
|
|
| 862 |
$node = recipe_node_prepare($node, FALSE); |
$node = recipe_node_prepare($node, FALSE); |
| 863 |
$output = theme('node_recipe', $node, FALSE); |
$output = theme('recipe_node', $node, FALSE); |
| 864 |
|
|
| 865 |
$html = theme('recipe_export_html', check_plain($node->title), $output); |
$html = theme('recipe_export_html', check_plain($node->title), $output); |
| 866 |
return $html; |
return $html; |
| 873 |
* - an integer representing the node id (nid) of the node to export |
* - an integer representing the node id (nid) of the node to export |
| 874 |
* @return |
* @return |
| 875 |
* - string containing the recipe in RecipeML |
* - string containing the recipe in RecipeML |
| 876 |
*/ |
*/ |
| 877 |
function recipe_export_recipeml($nid) { |
function recipe_export_recipeml($nid) { |
| 878 |
if($nid == 0) { drupal_goto('recipe'); } |
if ($nid == 0) { |
| 879 |
|
drupal_goto('recipe'); |
| 880 |
|
} |
| 881 |
|
|
| 882 |
$node = node_load(array('nid' => $nid, 'type' => 'recipe')); |
$node = node_load(array('nid' => $nid, 'type' => 'recipe')); |
| 883 |
|
|
| 888 |
'<recipeml version="0.5">'."\n". |
'<recipeml version="0.5">'."\n". |
| 889 |
' <recipe>'."\n". |
' <recipe>'."\n". |
| 890 |
' <head>'."\n". |
' <head>'."\n". |
| 891 |
' <title>'.$node->title.'</title>'."\n". |
' <title>'. $node->title .'</title>'."\n". |
| 892 |
' </head>'."\n". |
' </head>'."\n". |
| 893 |
' <yield><qty>'.$node->yield.'</qty></yield>'."\n". |
' <yield><qty>'. $node->yield .'</qty></yield>'."\n". |
| 894 |
' <ingredients>'; |
' <ingredients>'; |
| 895 |
|
|
| 896 |
foreach ($node->ingredients as $ingredient) { |
foreach ($node->ingredients as $ingredient) { |
| 897 |
$output .= "\n".'<ing><amt><qty>'.$ingredient->quantity.'</qty><unit>'.$ingredient->abbreviation.'</unit></amt><item>'.$ingredient->name.'</item></ing>'; |
$output .= "\n".'<ing><amt><qty>'. $ingredient->quantity .'</qty><unit>'. $ingredient->abbreviation .'</unit></amt><item>'. $ingredient->name .'</item></ing>'; |
| 898 |
} |
} |
| 899 |
|
|
| 900 |
$output .= "\n". |
$output .= "\n". |
| 901 |
' </ingredients>'."\n". |
' </ingredients>'."\n". |
| 902 |
' <directions>' . $node->instructions . '</directions>'."\n". |
' <directions>'. $node->instructions .'</directions>'."\n". |
| 903 |
' </recipe>'."\n". |
' </recipe>'."\n". |
| 904 |
'</recipeml>'; |
'</recipeml>'; |
| 905 |
|
|
| 932 |
if (!isset($ingredient->quantity)) { |
if (!isset($ingredient->quantity)) { |
| 933 |
$ingredient = recipe_parse_ingredient_string($ingredient->name); |
$ingredient = recipe_parse_ingredient_string($ingredient->name); |
| 934 |
} |
} |
| 935 |
if ($ingredient->name && _in_array($ingredient,$ingredients)) { |
if ($ingredient->name && _in_array($ingredient, $ingredients)) { |
| 936 |
form_set_error("recipe", t('Duplicate ingredients are not allowed.')); |
form_set_error("recipe", t('Duplicate ingredients are not allowed.')); |
| 937 |
} |
} |
| 938 |
else { |
else { |
| 962 |
else { |
else { |
| 963 |
$ingredient->unit_id = 29; |
$ingredient->unit_id = 29; |
| 964 |
$ingredient->abbreviation = ''; |
$ingredient->abbreviation = ''; |
| 965 |
$ingredient->name = $t_unit . ' ' . $ingredient->name; |
$ingredient->name = $t_unit .' '. $ingredient->name; |
| 966 |
} |
} |
| 967 |
|
|
| 968 |
$ingredient->name = trim($ingredient->name); |
$ingredient->name = trim($ingredient->name); |
| 1005 |
} |
} |
| 1006 |
|
|
| 1007 |
/** |
/** |
| 1008 |
Menu Callback - created output for the main recipe page. |
* Menu Callback - created output for the main recipe page. |
| 1009 |
|
* |
| 1010 |
@return $body |
* @return $body |
| 1011 |
**/ |
*/ |
| 1012 |
function recipe_page() { |
function recipe_page() { |
| 1013 |
$body = ""; |
$body = ""; |
| 1014 |
|
|
| 1024 |
if ($term != NULL) { |
if ($term != NULL) { |
| 1025 |
$content = recipe_index($term->tid); |
$content = recipe_index($term->tid); |
| 1026 |
if ($content != '') { |
if ($content != '') { |
| 1027 |
$body = theme('box', $term->name . '- '. t('Sub Categories'), $content); |
$body = theme('box', $term->name .'- '. t('Sub Categories'), $content); |
| 1028 |
} |
} |
| 1029 |
|
|
| 1030 |
$terms = array_merge(array($term->tid), array_map('_recipe_get_tid_from_term', module_invoke('taxonomy', 'get_children', $term->tid))); |
$terms = array_merge(array($term->tid), array_map('_recipe_get_tid_from_term', module_invoke('taxonomy', 'get_children', $term->tid))); |
| 1035 |
$body = ''; |
$body = ''; |
| 1036 |
|
|
| 1037 |
if (variable_get('recipe_recent_box_enable', 1)) { |
if (variable_get('recipe_recent_box_enable', 1)) { |
| 1038 |
$body = theme('box', variable_get('recipe_recent_box_title', t('Latest Recipes')), module_invoke('node', 'title_list', recipe_get_latest(variable_get('recipe_recent_display', '5')), '') . theme('recipe_more_info', theme('feed_icon', url("recipe/feed")))); |
$body = theme('box', variable_get('recipe_recent_box_title', t('Latest Recipes')), module_invoke('node', 'title_list', recipe_get_latest(variable_get('recipe_recent_display', '5')), '') . theme('recipe_more_info', theme('feed_icon', url("recipe/feed"), t('Syndicate')))); |
| 1039 |
} |
} |
| 1040 |
$content = recipe_index(); |
$content = recipe_index(); |
| 1041 |
if ($content != '') { |
if ($content != '') { |
| 1047 |
} |
} |
| 1048 |
|
|
| 1049 |
/** |
/** |
| 1050 |
Builds a breadcrumb list. |
* Builds a breadcrumb list. |
| 1051 |
|
* |
| 1052 |
@param breadcrumb a reference to the breadcrumb array. New items will be appending to this array. |
* @param breadcrumb a reference to the breadcrumb array. New items will be appending to this array. |
| 1053 |
|
* |
| 1054 |
@return returns a term object if the last item in the url is a term, otherwise returns NULL. |
* @return returns a term object if the last item in the url is a term, otherwise returns NULL. |
| 1055 |
**/ |
*/ |
| 1056 |
function recipe_build_breadcrumbs(&$breadcrumb) { |
function recipe_build_breadcrumbs(&$breadcrumb) { |
| 1057 |
if (arg(1) != NULL) { |
if (arg(1) != NULL) { |
| 1058 |
$i = 1; |
$i = 1; |
| 1060 |
$breadcrumb[] = l(ucwords(t('Recipes')), $url); |
$breadcrumb[] = l(ucwords(t('Recipes')), $url); |
| 1061 |
while (arg($i) != NULL) { |
while (arg($i) != NULL) { |
| 1062 |
$last_term = urldecode(arg($i)); |
$last_term = urldecode(arg($i)); |
| 1063 |
$url = $url . '/' . urlencode($last_term); |
$url = $url .'/'. urlencode($last_term); |
| 1064 |
$breadcrumb[] = l(ucwords($last_term), $url); |
$breadcrumb[] = l(ucwords($last_term), $url); |
| 1065 |
$i++; |
$i++; |
| 1066 |
} |
} |
| 1072 |
} |
} |
| 1073 |
|
|
| 1074 |
/** |
/** |
| 1075 |
Recursively traverses the term tree to construct the index. |
* Recursively traverses the term tree to construct the index. |
| 1076 |
|
* |
| 1077 |
@return string the output for this tree. |
* @return string the output for this tree. |
| 1078 |
**/ |
*/ |
| 1079 |
function recipe_build_index(&$tree, $parent_url) { |
function recipe_build_index(&$tree, $parent_url) { |
| 1080 |
$output = ''; |
$output = ''; |
| 1081 |
|
|
| 1093 |
$next_depth = $nex->depth; |
$next_depth = $nex->depth; |
| 1094 |
} |
} |
| 1095 |
|
|
| 1096 |
$cur->link = $parent_url . '/' . urlencode(strtolower(trim($cur->name))); |
$cur->link = $parent_url .'/'. urlencode(strtolower(trim($cur->name))); |
| 1097 |
|
|
| 1098 |
$cur->children = ''; |
$cur->children = ''; |
| 1099 |
if ($next_depth > $cur->depth) { |
if ($next_depth > $cur->depth) { |
| 1119 |
} |
} |
| 1120 |
|
|
| 1121 |
/** |
/** |
| 1122 |
Constructs a url from the current url arguments list. |
* Constructs a url from the current url arguments list. |
| 1123 |
|
* |
| 1124 |
@return a string containing a formated URL. |
* @return a string containing a formated URL. |
| 1125 |
**/ |
*/ |
| 1126 |
function recipe_get_current_url() { |
function recipe_get_current_url() { |
| 1127 |
$arg_index = 1; |
$arg_index = 1; |
| 1128 |
$url = arg(0); |
$url = arg(0); |
| 1134 |
} |
} |
| 1135 |
|
|
| 1136 |
/** |
/** |
| 1137 |
Get the latest recipes |
* Get the latest recipes |
| 1138 |
|
* |
| 1139 |
@return a database query result. |
* @return a database query result. |
| 1140 |
**/ |
*/ |
| 1141 |
function recipe_get_latest($count = 0) { |
function recipe_get_latest($count = 0) { |
| 1142 |
$tids = recipe_get_recipe_terms(); |
$tids = recipe_get_recipe_terms(); |
| 1143 |
return recipe_select_nodes($tids, 'or', 0, FALSE, $count); |
return recipe_select_nodes($tids, 'or', 0, FALSE, $count); |
| 1144 |
} |
} |
| 1145 |
|
|
| 1146 |
/** |
/** |
| 1147 |
Get all the terms associated with Recipes. |
* Get all the terms associated with Recipes. |
| 1148 |
|
* |
| 1149 |
@return an array of unique term ids. |
* @return an array of unique term ids. |
| 1150 |
**/ |
*/ |
| 1151 |
function recipe_get_recipe_terms() { |
function recipe_get_recipe_terms() { |
| 1152 |
$vocabs = recipe_get_vocabularies(); |
$vocabs = recipe_get_vocabularies(); |
| 1153 |
$tids = array(); |
$tids = array(); |
| 1158 |
} |
} |
| 1159 |
|
|
| 1160 |
/** |
/** |
| 1161 |
Gets all the vocabularies that are associated with the recipe module. |
* Gets all the vocabularies that are associated with the recipe module. |
| 1162 |
|
* |
| 1163 |
@return array the vocabularies. |
* @return array the vocabularies. |
| 1164 |
**/ |
*/ |
| 1165 |
function recipe_get_vocabularies() { |
function recipe_get_vocabularies() { |
| 1166 |
$vocabularies = module_invoke('taxonomy', 'get_vocabularies', 'recipe'); |
$vocabularies = module_invoke('taxonomy', 'get_vocabularies', 'recipe'); |
| 1167 |
return $vocabularies; |
return $vocabularies; |
| 1168 |
} |
} |
| 1169 |
|
|
| 1170 |
/** |
/** |
| 1171 |
Constructs the recipe index page, using theme functions. |
* Constructs the recipe index page, using theme functions. |
| 1172 |
|
* |
| 1173 |
@return a string containing the output ready for display. |
* @return a string containing the output ready for display. |
| 1174 |
**/ |
*/ |
| 1175 |
function recipe_index($tid = 0) { |
function recipe_index($tid = 0) { |
| 1176 |
$output = ""; |
$output = ""; |
| 1177 |
|
|
| 1217 |
if (isset($ingredient["name"])) { |
if (isset($ingredient["name"])) { |
| 1218 |
$ingredient["name"] = check_plain($ingredient["name"]); |
$ingredient["name"] = check_plain($ingredient["name"]); |
| 1219 |
} |
} |
| 1220 |
} else if (is_object($ingredient) ) { |
} |
| 1221 |
|
else if (is_object($ingredient) ) { |
| 1222 |
if (isset($ingredient->name)) { |
if (isset($ingredient->name)) { |
| 1223 |
$ingredient->name = check_plain($ingredient->name); |
$ingredient->name = check_plain($ingredient->name); |
| 1224 |
} |
} |
| 1296 |
$sql = 'n.nid, n.title, n.sticky, n.created FROM {node} n '. $joins .' WHERE n.status = 1 AND '. $wheres .' ORDER BY n.sticky DESC, n.created DESC'; |
$sql = 'n.nid, n.title, n.sticky, n.created FROM {node} n '. $joins .' WHERE n.status = 1 AND '. $wheres .' ORDER BY n.sticky DESC, n.created DESC'; |
| 1297 |
$sql_count = 'SELECT COUNT(n.nid) FROM {node} n '. $joins .' WHERE n.status = 1 AND '. $wheres; |
$sql_count = 'SELECT COUNT(n.nid) FROM {node} n '. $joins .' WHERE n.status = 1 AND '. $wheres; |
| 1298 |
} |
} |
| 1299 |
} else { |
} |
| 1300 |
|
else { |
| 1301 |
// no taxonomy used |
// no taxonomy used |
| 1302 |
$sql = "SELECT nid, title, sticky, created FROM {node} WHERE status = 1 AND type = 'recipe' ORDER BY sticky DESC, created DESC"; |
$sql = "SELECT nid, title, sticky, created FROM {node} n WHERE status = 1 AND type = 'recipe' ORDER BY sticky DESC, created DESC"; |
| 1303 |
$sql_count = "SELECT COUNT(nid) FROM {node} WHERE status = 1 AND type = 'recipe'"; |
$sql_count = "SELECT COUNT(nid) FROM {node} n WHERE status = 1 AND type = 'recipe'"; |
| 1304 |
} |
} |
| 1305 |
|
|
| 1306 |
if ($pager && ($count > 0)) { |
if ($pager && ($count > 0)) { |
| 1315 |
} |
} |
| 1316 |
|
|
| 1317 |
/** |
/** |
| 1318 |
Get all the terms in a given vocabulary. |
* Get all the terms in a given vocabulary. |
| 1319 |
|
* |
| 1320 |
@return an array of unique term ids. |
* @return an array of unique term ids. |
| 1321 |
**/ |
*/ |
| 1322 |
function recipe_tax_get_terms($vid) { |
function recipe_tax_get_terms($vid) { |
| 1323 |
$result = db_query("SELECT tid FROM {term_data} WHERE vid = %d", $vid); |
$result = db_query("SELECT tid FROM {term_data} WHERE vid = %d", $vid); |
| 1324 |
$tids = array(); |
$tids = array(); |
| 1329 |
} |
} |
| 1330 |
|
|
| 1331 |
/** |
/** |
| 1332 |
Helper function for array map purposes. |
* Helper function for array map purposes. |
| 1333 |
@param term the term object from which the tid will be extracted. |
* @param term the term object from which the tid will be extracted. |
| 1334 |
|
* |
| 1335 |
@return the tid member of $term. |
* @return the tid member of $term. |
| 1336 |
**/ |
*/ |
| 1337 |
function _recipe_get_tid_from_term($term) { |
function _recipe_get_tid_from_term($term) { |
| 1338 |
return $term->tid; |
return $term->tid; |
| 1339 |
} |
} |
| 1342 |
* Theme functions group |
* Theme functions group |
| 1343 |
*/ |
*/ |
| 1344 |
|
|
| 1345 |
|
function recipe_theme() { |
| 1346 |
|
return array( |
| 1347 |
|
'recipe_node' => array( |
| 1348 |
|
'function' => 'theme_recipe_node', |
| 1349 |
|
'arguments' => array('node' => NULL, 'yield_form' => TRUE), |
| 1350 |
|
), |
| 1351 |
|
'recipe_index' => array( |
| 1352 |
|
'function' => 'theme_recipe_index', |
| 1353 |
|
'arguments' => array('name' => NULL, 'index_list' => NULL), |
| 1354 |
|
), |
| 1355 |
|
'recipe_index_item' => array( |
| 1356 |
|
'arguments' => array('term' => NULL), |
| 1357 |
|
), |
| 1358 |
|
'recipe_list' => array( |
| 1359 |
|
'arguments' => array('output' => NULL), |
| 1360 |
|
), |
| 1361 |
|
'recipe_more_info' => array( |
| 1362 |
|
'arguments' => array('content' => NULL), |
| 1363 |
|
), |
| 1364 |
|
'recipe_export_html' => array( |
| 1365 |
|
'arguments' => array('title' => NULL, 'content' => NULL), |
| 1366 |
|
), |
| 1367 |
|
); |
| 1368 |
|
} |
| 1369 |
/** |
/** |
| 1370 |
* A custom theme function. |
* A custom theme function. |
| 1371 |
* |
* |
| 1374 |
* presentation in a CSS class that is prefixed by the module name. This |
* presentation in a CSS class that is prefixed by the module name. This |
| 1375 |
* way, style sheets can modify the output without requiring theme code. |
* way, style sheets can modify the output without requiring theme code. |
| 1376 |
*/ |
*/ |
| 1377 |
function theme_node_recipe($node, $yield_form = TRUE) { |
function theme_recipe_node($node, $yield_form = TRUE) { |
| 1378 |
// Get custom yield or default to a factor of 1 |
// Get custom yield or default to a factor of 1 |
| 1379 |
if ($yield_form && intval($node->yield) == $node->yield) { |
if ($yield_form && intval($node->yield) == $node->yield) { |
| 1380 |
if ($_POST['op'] == t('Change')) |
if ($_POST['op'] == t('Change')) |
| 1402 |
} |
} |
| 1403 |
|
|
| 1404 |
// Construct the $ingredients[] array |
// Construct the $ingredients[] array |
| 1405 |
if ($node->ingredients){ |
if ($node->ingredients) { |
| 1406 |
foreach ($node->ingredients as $ingredient) { |
foreach ($node->ingredients as $ingredient) { |
| 1407 |
if (isset($ingredient->quantity) && $ingredient->name) { |
if (isset($ingredient->quantity) && $ingredient->name) { |
| 1408 |
if (!$ingredient->abbreviation) { |
if (!$ingredient->abbreviation) { |
| 1421 |
$ingredient->name = l($ingredient->name, 'node/'. $ingredient->link); |
$ingredient->name = l($ingredient->name, 'node/'. $ingredient->link); |
| 1422 |
} |
} |
| 1423 |
|
|
| 1424 |
$ingredients[] = $ingredient->quantity.' <acronym title="'.recipe_unit_name($ingredient->unit_id).'">'.$ingredient->abbreviation.'</acronym> '.$ingredient->name; |
$ingredients[] = $ingredient->quantity .' <acronym title="'. recipe_unit_name($ingredient->unit_id) .'">'. $ingredient->abbreviation .'</acronym> '. $ingredient->name; |
| 1425 |
} |
} |
| 1426 |
} |
} |
| 1427 |
} |
} |
| 1428 |
|
|
| 1429 |
// Construct the summary |
// Construct the summary |
| 1430 |
$summary = '<table>'; |
$summary = '<table>'; |
| 1431 |
$summary .= '<tr><th>'.t('Yield').'</th><td>'.$yield.'</td></tr>'; |
$summary .= '<tr><th>'. t('Yield') .'</th><td>'. $yield .'</td></tr>'; |
| 1432 |
if ($node->source) { |
if ($node->source) { |
| 1433 |
$summary .= '<tr><th>'.t('Source').'</th><td>'.$node->source.'</td></tr>'; |
$summary .= '<tr><th>'. t('Source') .'</th><td>'. $node->source .'</td></tr>'; |
| 1434 |
} |
} |
| 1435 |
if ($node->preptime) { |
if ($node->preptime) { |
| 1436 |
if ($node->preptime < 60) { |
if ($node->preptime < 60) { |
| 1442 |
else { |
else { |
| 1443 |
$preptime = t('!time hours', array('!time' => recipe_ingredient_quantity_from_decimal($node->preptime / 60))); |
$preptime = t('!time hours', array('!time' => recipe_ingredient_quantity_from_decimal($node->preptime / 60))); |
| 1444 |
} |
} |
| 1445 |
$summary .= '<tr><th>'.t('Prep Time').'</th><td>'.$preptime.'</td></tr>'; |
$summary .= '<tr><th>'. t('Prep Time') .'</th><td>'. $preptime .'</td></tr>'; |
| 1446 |
} |
} |
| 1447 |
$vocabs = taxonomy_get_vocabularies('recipe'); |
$vocabs = taxonomy_get_vocabularies('recipe'); |
| 1448 |
if (count($vocabs) > 0) { |
if (count($vocabs) > 0) { |
| 1449 |
foreach ($vocabs as $vocab) { |
foreach ($vocabs as $vocab) { |
| 1450 |
$terms = taxonomy_node_get_terms_by_vocabulary($node->nid, $vocab->vid); |
$terms = taxonomy_node_get_terms_by_vocabulary($node, $vocab->vid); |
| 1451 |
if (count($terms) > 0) { |
if (count($terms) > 0) { |
| 1452 |
$summary .= '<tr><th>'.$vocab->name.'</th><td>'; |
$term = array_shift($terms); |
| 1453 |
foreach ($terms as $term) { |
$summary .= '<tr><th>'. $vocab->name .'</th><td>'. l($term->name, 'taxonomy/term/'. $term->tid) .'</td></tr>'; |
|
$summary .= l($term->name, 'taxonomy/term/'.$term->tid).' '; |
|
|
} |
|
|
$summary .= '</td></tr>'; |
|
| 1454 |
} |
} |
| 1455 |
} |
} |
| 1456 |
} |
} |
| 1458 |
|
|
| 1459 |
// Create the output |
// Create the output |
| 1460 |
$output = ''; |
$output = ''; |
| 1461 |
$output .= '<div class="recipe-summary">'.theme('box', t('Summary'), $summary ).'</div>'; |
$output .= '<div class="recipe-summary">'. theme('box', t('Summary'), $summary ) .'</div>'; |
| 1462 |
$output .= '<div class="recipe-description">'.theme('box', t('Description'), $node->body).'</div>'; |
$output .= '<div class="recipe-description">'. theme('box', t('Description'), $node->body) .'</div>'; |
| 1463 |
$output .= '<div class="recipe-ingredients">'.theme('box', t('Ingredients'), theme('item_list', $ingredients)).'</div>'; |
$output .= '<div class="recipe-ingredients">'. theme('box', t('Ingredients'), theme('item_list', $ingredients)) .'</div>'; |
| 1464 |
$output .= '<div class="recipe-instructions">'.theme('box', t('Instructions'), $node->instructions).'</div>'; |
$output .= '<div class="recipe-instructions">'. theme('box', t('Instructions'), $node->instructions) .'</div>'; |
| 1465 |
if ($node->notes !== '') { |
if ($node->notes !== '') { |
| 1466 |
$output .= '<div class="recipe-notes">'.theme('box', t('Notes'), $node->notes).'</div>'; |
$output .= '<div class="recipe-notes">'. theme('box', t('Notes'), $node->notes) .'</div>'; |
| 1467 |
} |
} |
| 1468 |
|
|
| 1469 |
return $output; |
return $output; |
| 1498 |
} |
} |
| 1499 |
|
|
| 1500 |
/** |
/** |
| 1501 |
Controls the output of the rendered index list. |
* Controls the output of the rendered index list. |
| 1502 |
|
* |
| 1503 |
@return string the output for the index list. |
* @return string the output for the index list. |
| 1504 |
**/ |
*/ |
| 1505 |
function theme_recipe_index(&$name, &$index_list) { |
function theme_recipe_index(&$name, &$index_list) { |
| 1506 |
if ($index_list != "") { |
if ($index_list != "") { |
| 1507 |
return "<div class=\"item-list\">\n$index_list\n</div>\n"; |
return "<div class=\"item-list\">\n$index_list\n</div>\n"; |
| 1510 |
} |
} |
| 1511 |
|
|
| 1512 |
/** |
/** |
| 1513 |
Displays a single index item. |
* Displays a single index item. |
| 1514 |
|
* |
| 1515 |
@return string the output for this item. |
* @return string the output for this item. |
| 1516 |
**/ |
*/ |
| 1517 |
function theme_recipe_index_item(&$term) { |
function theme_recipe_index_item(&$term) { |
| 1518 |
$description = ($term->description != '') ? "<p class=\"recipe-desc\">". $term->description ."</p>" : ''; |
$description = ($term->description != '') ? "<p class=\"recipe-desc\">". $term->description ."</p>" : ''; |
| 1519 |
if ($term->count > 0) { |
if ($term->count > 0) { |
| 1520 |
return "<li ><div class=\"recipe-title\">". l($term->name ." ($term->count)", $term->link) ."</div>". $description.$term->children ."</li>"; |
return "<li ><div class=\"recipe-title\">". l($term->name ." ($term->count)", $term->link) ."</div>". $description . $term->children ."</li>"; |
| 1521 |
} |
} |
| 1522 |
else { |
else { |
| 1523 |
return "<li><div class=\"recipe-title\">". $term->name ." ($term->count)</div>". $description.$term->children ."</li>"; |
return "<li><div class=\"recipe-title\">". $term->name ." ($term->count)</div>". $description . $term->children ."</li>"; |
| 1524 |
} |
} |
| 1525 |
} |
} |
| 1526 |
|
|
| 1527 |
/** |
/** |
| 1528 |
Displays a single one level list. Called for each group of items at the same depth. |
* Displays a single one level list. Called for each group of items at the same depth. |
| 1529 |
|
* |
| 1530 |
@return string the output for this list. |
* @return string the output for this list. |
| 1531 |
**/ |
*/ |
| 1532 |
function theme_recipe_list(&$output) { |
function theme_recipe_list(&$output) { |
| 1533 |
if ($output != '') { |
if ($output != '') { |
| 1534 |
return "<ul>". $output ."</ul>\n"; |
return "<ul>". $output ."</ul>\n"; |
| 1537 |
} |
} |
| 1538 |
|
|
| 1539 |
/** |
/** |
| 1540 |
Displays more information content, suck as "more" links, and |
* Displays more information content, suck as "more" links, and |
| 1541 |
feed images. |
* feed images. |
| 1542 |
|
* |
| 1543 |
@return formatted string containint the output. |
* @return formatted string containint the output. |
| 1544 |
**/ |
*/ |
| 1545 |
function theme_recipe_more_info($content) { |
function theme_recipe_more_info($content) { |
| 1546 |
return "<div class=\"more-link\">". $content ."</div>"; |
return "<div class=\"more-link\">". $content ."</div>"; |
| 1547 |
} |
} |
| 1557 |
$html .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">'; |
$html .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">'; |
| 1558 |
$html .= "<head>\n<title>". $title ."</title>\n"; |
$html .= "<head>\n<title>". $title ."</title>\n"; |
| 1559 |
$html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'; |
$html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'; |
| 1560 |
$html .= '<base href="'. $base_url .'/" />' . "\n"; |
$html .= '<base href="'. $base_url .'/" />'."\n"; |
| 1561 |
$html .= "<style type=\"text/css\">\n@import url(".drupal_get_path('module','recipe')."/recipe.css);\n</style>\n"; |
$html .= "<style type=\"text/css\">\n@import url(". drupal_get_path('module', 'recipe') ."/recipe.css);\n</style>\n"; |
| 1562 |
$html .= "</head>\n<body>\n<h1 class=title>" . $title . "</h1>\n" . $content . "\n</body>\n</html>\n"; |
$html .= "</head>\n<body>\n<h1 class=title>". $title ."</h1>\n". $content ."\n</body>\n</html>\n"; |
| 1563 |
return $html; |
return $html; |
| 1564 |
} |
} |
| 1565 |
|
|
| 1567 |
* |
* |
| 1568 |
* |
* |
| 1569 |
*/ |
*/ |
| 1570 |
function recipe_euclid ($number_one, $number_two) { |
function recipe_euclid($number_one, $number_two) { |
| 1571 |
if (($number_one == 0) or ($number_two == 0)) { |
if (($number_one == 0) or ($number_two == 0)) { |
| 1572 |
$hcf = 1; |
$hcf = 1; |
| 1573 |
return $hcf; |
return $hcf; |
| 1601 |
} |
} |
| 1602 |
return $hcf; |
return $hcf; |
| 1603 |
} |
} |
|
|
|
|
function recipe_import_from_46() { |
|
|
$rcount = 0; |
|
|
$icount = 0; |
|
|
$out = "<p>"; |
|
|
$old = db_query("SELECT * FROM {recipe_old}"); |
|
|
while ($o = db_fetch_object($old)) { |
|
|
db_query("INSERT INTO {recipe} (nid, source, yield, preptime, notes, instructions) VALUES('%d', '%s', '%d', '%d', '%s', '%s')", $o->nid, $o->source, intval($o->yield), $o->preptime, $o->notes, $o->instructions); |
|
|
$out .= t('Imported recipe @recipeid', array('@recipeid' => $o->nid)).'<br />'; |
|
|
$rcount++; |
|
|
} |
|
|
$out .= "</p>"; |
|
|
|
|
|
$out .= "<p><pre>"; |
|
|
$ings = db_query("SELECT * FROM {recipe_ingredients}"); |
|
|
while ($i = db_fetch_object($ings)) { |
|
|
$unitid = 29; // "unknown" |
|
|
$quantity = recipe_ingredient_quantity_from_fraction($i->ingredient); // best guess |
|
|
$out .= "\n\n".t('Parsing @ingredient', array('@ingredient' => $i->ingredient))."\n"; |
|
|
$nmatches = preg_match("/([^a-zA-Z]*)([^ ]*) (.*)/", $i->ingredient, $matches); |
|
|
//print_r($matches); |
|
|
if ($nmatches > 0) { |
|
|
$quantity = recipe_ingredient_quantity_from_fraction($matches[1]); |
|
|
$unit = $matches[2]; |
|
|
$name = $matches[3]; |
|
|
$out .= t('looking up unit for "@unit"', array('@unit' => strtolower($unit)))."\n"; |
|
|
$unit_rs = db_query("SELECT id FROM {recipe_unit} WHERE '%s' LIKE CONCAT(LOWER(name),'%%') OR abbreviation='%s'", strtolower($unit), $unit); // allow pints to match pint etc |
|
|
if ($unito = db_fetch_object($unit_rs)) { |
|
|
$out .= t('Got unit id @unitid', array('@unitid' => $unito->id))."\n"; |
|
|
$unitid = $unito->id; |
|
|
} else { |
|
|
$name = $unit ." ". $name; |
|
|
} |
|
|
} |
|
|
$iid = recipe_ingredient_id_from_name($name); |
|
|
$out .= t('Got id for "@name": @iid', array('@name' => $name, '@iid' => $iid)); |
|
|
db_query("INSERT INTO {recipe_node_ingredient} (nid, unit_id, quantity, ingredient_id) VALUES('%d', '%d', '%f', '%d')", $i->nid, $unitid, $quantity, $iid); |
|
|
$icount++; |
|
|
} |
|
|
$out .= "</pre></p>"; |
|
|
$out .= '<p>'.t('Imported @rcount recipes and @icount ingredients.', |
|
|
array('@rcount' => $rcount, '@icount' => $icount)).'</p>'; |
|
|
return $out; |
|
|
} |
|
|
|
|
|
?> |
|