| 1 |
<?php |
<?php |
| 2 |
// $Id: recipe.module,v 1.82 2008/04/20 19:05:12 brdwor Exp $ |
// $Id: recipe.module,v 1.85 2009/06/26 12:39:17 marble Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 112 |
} |
} |
| 113 |
|
|
| 114 |
/** |
/** |
| 115 |
* Implementation of hook_form(). |
* Implementation of hook_form(). |
| 116 |
*/ |
*/ |
| 117 |
function recipe_form(&$node) { |
function recipe_form(&$node,$form_state) { |
| 118 |
// drupal 4.7 requires the title field to be defined by the custom node's module |
// drupal 4.7 requires the title field to be defined by the custom node's module |
| 119 |
$form['title'] = array('#type' => 'textfield', '#title' => t('Title'), |
$form['title'] = array('#type' => 'textfield', '#title' => t('Title'), |
| 120 |
'#size' => 60, '#maxlength' => 128, '#required' => TRUE, |
'#size' => 60, '#maxlength' => 128, '#required' => TRUE, |
| 179 |
$num_ingredients = $id+1; |
$num_ingredients = $id+1; |
| 180 |
if ($id == 0) { |
if ($id == 0) { |
| 181 |
$j = '0'; |
$j = '0'; |
| 182 |
} |
} else { |
|
else { |
|
| 183 |
$j = $id; |
$j = $id; |
| 184 |
} |
} |
| 185 |
if ($ingredient->name && isset($ingredient->quantity)) { |
|
| 186 |
|
// For preview, node->ingredients is an array, for actual display, it's an object |
| 187 |
|
$name = ''; |
| 188 |
|
$unit_id = ''; |
| 189 |
|
$abbreviation = ''; |
| 190 |
|
$quantity = 0; |
| 191 |
|
if (is_array($ingredient)) { |
| 192 |
|
$name = $ingredient['name']; |
| 193 |
|
$unit_id = $ingredient['unit_id']; |
| 194 |
|
$abbreviation = $ingredient['abbreviation']; |
| 195 |
|
$quantity = $ingredient['quantity']; |
| 196 |
|
} else { |
| 197 |
|
$name = $ingredient->name; |
| 198 |
|
$unit_id = $ingredient->unit_id; |
| 199 |
|
$abbreviation = $ingredient->abbreviation; |
| 200 |
|
$quantity = $ingredient->quantity; |
| 201 |
|
} |
| 202 |
|
|
| 203 |
|
if ($name && isset($quantity)) { |
| 204 |
// When can the following statement be true? |
// When can the following statement be true? |
| 205 |
if (!$ingredient) { |
if (!$ingredient) { |
| 206 |
drupal_set_message(t('Recipe Module: An error has occured. Please report this error to the system administrator.'), 'error'); |
drupal_set_message(t('Recipe Module: An error has occured. Please report this error to the system administrator.'), 'error'); |
| 207 |
$ingredient->quantity = ''; |
if (is_array($ingredient)) { |
| 208 |
$ingredient->unit_id = 21; |
$ingredient['quantity'] = ''; |
| 209 |
$ingredient->name = ''; |
$ingredient['unit_id'] = 21; |
| 210 |
|
$ingredient['name'] = ''; |
| 211 |
|
} else { |
| 212 |
|
$ingredient->quantity = ''; |
| 213 |
|
$ingredient->unit_id = 21; |
| 214 |
|
$ingredient->name = ''; |
| 215 |
|
} |
| 216 |
} |
} |
| 217 |
if ($system == 'complex') { |
if ($system == 'complex') { |
| 218 |
$form['ingredients'][$j]['open_tags'] = array( |
$form['ingredients'][$j]['open_tags'] = array( |
| 221 |
$form['ingredients'][$j]['quantity'] = array( |
$form['ingredients'][$j]['quantity'] = array( |
| 222 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 223 |
'#title' => '', |
'#title' => '', |
| 224 |
'#default_value' => preg_replace('/\⁄/', '/', recipe_ingredient_quantity_from_decimal($ingredient->quantity)), |
'#default_value' => preg_replace('/\⁄/', '/', recipe_ingredient_quantity_from_decimal($quantity)), |
| 225 |
'#size' => 8, |
'#size' => 8, |
| 226 |
'#maxlength' => 8, |
'#maxlength' => 8, |
| 227 |
); |
); |
| 231 |
$form['ingredients'][$j]['unit_id'] = array( |
$form['ingredients'][$j]['unit_id'] = array( |
| 232 |
'#type' => 'select', |
'#type' => 'select', |
| 233 |
'#title' => '', |
'#title' => '', |
| 234 |
'#default_value' => $ingredient->unit_id, |
'#default_value' => $unit_id, |
| 235 |
'#options' => recipe_unit_options(), |
'#options' => recipe_unit_options(), |
| 236 |
); |
); |
| 237 |
$form['ingredients'][$j]['mid2_tags'] = array( |
$form['ingredients'][$j]['mid2_tags'] = array( |
| 240 |
$form['ingredients'][$j]['name'] = array( |
$form['ingredients'][$j]['name'] = array( |
| 241 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 242 |
'#title' => '', |
'#title' => '', |
| 243 |
'#default_value' => $ingredient->name, |
'#default_value' => $name, |
| 244 |
'#size' => 64, |
'#size' => 64, |
| 245 |
'#maxlength' => 128, |
'#maxlength' => 128, |
| 246 |
'#autocomplete_path' => $callback, |
'#autocomplete_path' => $callback, |
| 250 |
); |
); |
| 251 |
} |
} |
| 252 |
else { |
else { |
| 253 |
if ($ingredient->name) { |
if ($name) { |
| 254 |
if ($ingredient->quantity == 0) { |
if ($quantity == 0) { |
| 255 |
$ingredient->quantity = ''; |
$quantity = ''; |
| 256 |
} |
} |
| 257 |
else { |
else { |
| 258 |
$ingredient->quantity .= ' '; |
$quantity .= ' '; |
| 259 |
} |
} |
| 260 |
if ($ingredient->abbreviation != '') { |
if ($abbreviation != '') { |
| 261 |
$ingredient->abbreviation .= ' '; |
$abbreviation .= ' '; |
| 262 |
} |
} |
| 263 |
$ingredient->name = $ingredient->quantity . $ingredient->abbreviation . $ingredient->name; |
$name = $quantity . $abbreviation . $name; |
| 264 |
} |
} |
| 265 |
$form['ingredients'][$j]['open_tags'] = array( |
$form['ingredients'][$j]['open_tags'] = array( |
| 266 |
'#value' => '<tr><th>', |
'#value' => '<tr><th>', |
| 269 |
$form['ingredients'][$j]['name'] = array( |
$form['ingredients'][$j]['name'] = array( |
| 270 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 271 |
'#title' => '', |
'#title' => '', |
| 272 |
'#default_value' => $ingredient->name, |
'#default_value' => $name, |
| 273 |
'#size' => 64, |
'#size' => 64, |
| 274 |
'#maxlength' => 128, |
'#maxlength' => 128, |
| 275 |
'#autocomplete_path' => $callback, |
'#autocomplete_path' => $callback, |
| 579 |
if (!$ingredient_id) { |
if (!$ingredient_id) { |
| 580 |
global $active_db; |
global $active_db; |
| 581 |
$node_link = db_result(db_query("SELECT nid FROM {node} n WHERE title = '%s'", $name)); |
$node_link = db_result(db_query("SELECT nid FROM {node} n WHERE title = '%s'", $name)); |
| 582 |
if (empty($node_link)) { $node_link=0; } |
|
| 583 |
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); |
| 584 |
$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)))); |
| 585 |
} |
} |
| 1352 |
} |
} |
| 1353 |
|
|
| 1354 |
/** |
/** |
| 1355 |
|
* Hook into generic node creation/update and check if the added node |
| 1356 |
|
* fixes any links in existing recipes. |
| 1357 |
|
*/ |
| 1358 |
|
function recipe_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { |
| 1359 |
|
switch ($op) { |
| 1360 |
|
case 'insert': |
| 1361 |
|
case 'update': |
| 1362 |
|
// TODO: Could filter for only nodes of type 'ingredient' |
| 1363 |
|
db_query("UPDATE {recipe_ingredient} SET link='%d' WHERE LOWER(name)='%s'", $node->nid, trim(strtolower($node->title)) ); |
| 1364 |
|
break; |
| 1365 |
|
} |
| 1366 |
|
} |
| 1367 |
|
|
| 1368 |
|
/** |
| 1369 |
* Helper function for array map purposes. |
* Helper function for array map purposes. |
| 1370 |
* @param term the term object from which the tid will be extracted. |
* @param term the term object from which the tid will be extracted. |
| 1371 |
* |
* |
| 1506 |
return $output; |
return $output; |
| 1507 |
} |
} |
| 1508 |
|
|
| 1509 |
function recipe_custom_yield_form($node) { |
function recipe_custom_yield_form($form_id, $node) { |
| 1510 |
$form['custom_yield_container'] = array( |
$form['custom_yield_container'] = array( |
| 1511 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 1512 |
'#collapsible' => FALSE, |
'#collapsible' => FALSE, |