| 1 |
<?php |
<?php |
| 2 |
// $Id: node_export.module,v 1.1.2.3 2009/10/06 01:36:53 danielb Exp $ |
// $Id: node_export.module,v 1.1.2.2 2009/09/08 10:14:12 danielb Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 137 |
/** |
/** |
| 138 |
* Callback for 'node_export' node operation. |
* Callback for 'node_export' node operation. |
| 139 |
*/ |
*/ |
| 140 |
function node_export_node_bulk($nodes) { |
function node_export_node_bulk($nids, $return_code = FALSE) { |
| 141 |
module_load_include('inc', 'node_export', 'node_export.pages'); |
|
| 142 |
|
$nodes = array(); |
| 143 |
|
foreach ($nids as $nid) { |
| 144 |
|
$nodes[] = node_load($nid); |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
// Let other modules do special fixing up. |
| 148 |
|
// The function signature is: hook_node_export_node_bulk_alter(&$nodes, $op). |
| 149 |
|
// Where $op is 'export'. |
| 150 |
|
drupal_alter('node_export_node_bulk', $nodes, 'export'); |
| 151 |
|
|
| 152 |
$node_codes = array(); |
$node_codes = array(); |
| 153 |
foreach ($nodes as $nid) { |
foreach ($nodes as $node) { |
| 154 |
$node_codes[] = node_export_node_export(node_load($nid), TRUE, 1); |
$node_codes[] = node_export_node_export($node, TRUE, 1); |
| 155 |
} |
} |
| 156 |
|
|
| 157 |
$node_code = "array(\n ". implode(",\n ", $node_codes) .",\n)"; |
$node_code = "array(\n ". implode(",\n ", $node_codes) .",\n)"; |
| 158 |
|
if ($return_code) { |
| 159 |
|
return $node_code; |
| 160 |
|
} |
| 161 |
if (variable_get('node_export_bulk_code', 'copy') == 'copy') { |
if (variable_get('node_export_bulk_code', 'copy') == 'copy') { |
| 162 |
drupal_set_message(drupal_get_form('node_export_form', $node_code)); |
drupal_set_message(drupal_get_form('node_export_form', $node_code)); |
| 163 |
} |
} |
| 164 |
else { |
else { |
| 165 |
node_export_get_file($nodes, $node_code, TRUE); |
node_export_get_file($nids, $node_code, TRUE); |
| 166 |
} |
} |
| 167 |
} |
} |
| 168 |
|
|
| 390 |
$node->menu = node_export_get_menu($original_node); |
$node->menu = node_export_get_menu($original_node); |
| 391 |
|
|
| 392 |
// Let other modules do special fixing up. |
// Let other modules do special fixing up. |
| 393 |
// The function signature is: hook_export_node_alter(&$node, $original_node, $method) |
// The function signature is: hook_node_export_node_alter(&$node, $original_node, $method) |
| 394 |
// Where $method is 'export' |
// Where $method is 'export' |
| 395 |
drupal_alter('node_export_node', $node, $original_node, 'export'); |
drupal_alter('node_export_node', $node, $original_node, 'export'); |
| 396 |
$node_code = node_export_node_encode($node, $iteration); |
$node_code = node_export_node_encode($node, $iteration); |
| 466 |
} |
} |
| 467 |
|
|
| 468 |
/** |
/** |
| 469 |
|
* Import Function |
| 470 |
|
* |
| 471 |
|
* @param $node_code |
| 472 |
|
* The string of node code. |
| 473 |
|
* @param $method |
| 474 |
|
* If set will override the variable table settings |
| 475 |
|
* @param $redirect |
| 476 |
|
* Whether to allow redirects |
| 477 |
|
* @param $msg_func |
| 478 |
|
* Function used to output status message |
| 479 |
|
* @param $msg_t |
| 480 |
|
* Function used to translate |
| 481 |
|
* @return |
| 482 |
|
* FALSE is the types check failed |
| 483 |
|
* Returns the HTML of a node form if required to prepopulate |
| 484 |
|
* Otherwise returns nothing, and may redirect. |
| 485 |
|
*/ |
| 486 |
|
function node_export_import($node_code, $method = NULL, $redirect = TRUE, $msg_func = 'drupal_set_message', $msg_t = 't') { |
| 487 |
|
$import = node_export_node_decode($node_code); |
| 488 |
|
$types_exist = node_export_import_types_check($import); |
| 489 |
|
if ($types_exist) { |
| 490 |
|
$count = 0; |
| 491 |
|
if (is_array($import)) { |
| 492 |
|
// This is a bulk import. |
| 493 |
|
$total = count($import); |
| 494 |
|
// Let other modules do special fixing up. |
| 495 |
|
// The function signature is: hook_node_export_node_bulk_alter(&$nodes, $op). |
| 496 |
|
// Where $op is 'import'. |
| 497 |
|
drupal_alter('node_export_node_bulk', $import, 'import'); |
| 498 |
|
$new_nodes = array(); |
| 499 |
|
foreach ($import as $new_node) { |
| 500 |
|
$new_nid = node_export_node_save($new_node); |
| 501 |
|
$new_node->nid = $new_nid; |
| 502 |
|
$new_nodes[] = $new_node; |
| 503 |
|
$msg_func($msg_t("Imported node !nid: !node", array('!nid' => $new_nid, '!node' => l($new_node->title, 'node/'. $new_nid)))); |
| 504 |
|
$count++; |
| 505 |
|
} |
| 506 |
|
drupal_alter('node_export_node_bulk', $new_nodes, 'after import'); |
| 507 |
|
$msg_func($msg_t("!count of !total nodes were imported. Some values may have been reset depending on Node Export's configuration", array('!total' => $total, '!count' => $count))); |
| 508 |
|
if ($redirect) { |
| 509 |
|
drupal_goto('admin/content/node'); |
| 510 |
|
} |
| 511 |
|
} |
| 512 |
|
else { |
| 513 |
|
// We are importing a single node. |
| 514 |
|
$total = 1; |
| 515 |
|
$method = !is_null($method) ? $method : variable_get('node_export_method', 'prepopulate'); |
| 516 |
|
|
| 517 |
|
if ($method == 'save-edit') { |
| 518 |
|
$new_nid = node_export_node_save($node); |
| 519 |
|
$msg_func($msg_t("Imported node !nid: !node", array('!nid' => $new_nid, '!node' => l($new_node->title, 'node/'. $new_nid)))); |
| 520 |
|
$count++; |
| 521 |
|
$msg_func($msg_t("!count of !total nodes were imported. Some values may have been reset depending on Node Export's configuration", array('!total' => $total, '!count' => $count))); |
| 522 |
|
if ($redirect) { |
| 523 |
|
drupal_goto('node/'. $new_nid .'/edit'); |
| 524 |
|
} |
| 525 |
|
} |
| 526 |
|
else if ($method == 'prepopulate') { |
| 527 |
|
include_once(drupal_get_path('module', 'node') .'/node.pages.inc'); |
| 528 |
|
return node_export_node_prepopulate($node); |
| 529 |
|
} |
| 530 |
|
} |
| 531 |
|
} |
| 532 |
|
return FALSE; |
| 533 |
|
} |
| 534 |
|
|
| 535 |
|
/** |
| 536 |
* Import Form |
* Import Form |
| 537 |
*/ |
*/ |
| 538 |
function node_export_import_form($form_state) { |
function node_export_import_form($form_state) { |
| 552 |
} |
} |
| 553 |
|
|
| 554 |
if (isset($node_code)) { |
if (isset($node_code)) { |
| 555 |
$import = node_export_node_decode($node_code); |
$result = node_export_import($node_code); |
| 556 |
$types_exist = node_export_import_types_check($import); |
if ($result === FALSE) { |
| 557 |
if ($types_exist) { |
// There was a problem with types? |
| 558 |
if (is_array($import)) { |
drupal_set_message(t('Problem found with the import file. Check the node types exist.'), 'error'); |
| 559 |
foreach ($import as $new_node) { |
} |
| 560 |
$new_nid = node_export_node_save($new_node); |
else if (!empty($result)) { |
| 561 |
drupal_set_message(t("Imported !node", array('!node' => l($new_node->title, 'node/'. $new_nid)))); |
return $result; |
|
} |
|
|
drupal_goto('admin/content/node'); |
|
|
} |
|
|
else { |
|
|
return node_export_node_check($import); |
|
|
} |
|
| 562 |
} |
} |
| 563 |
} |
} |
| 564 |
|
|
| 644 |
} |
} |
| 645 |
|
|
| 646 |
/** |
/** |
|
* Menu callback: prompt the user to confirm the operation |
|
|
* @return |
|
|
* A prepopulate form (if required). |
|
|
*/ |
|
|
function node_export_node_check($node) { |
|
|
|
|
|
$method = variable_get('node_export_method', 'prepopulate'); |
|
|
|
|
|
switch ($method) { |
|
|
case 'save-edit': |
|
|
$new_nid = node_export_node_save($node); |
|
|
drupal_goto('node/'. $new_nid .'/edit'); |
|
|
break; |
|
|
case 'prepopulate': |
|
|
default: |
|
|
include_once(drupal_get_path('module', 'node') .'/node.pages.inc'); |
|
|
return node_export_node_prepopulate($node); |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
| 647 |
* Exports a node - prepopulate a node editing form |
* Exports a node - prepopulate a node editing form |
| 648 |
* @return |
* @return |
| 649 |
* A prepopulate form. |
* A prepopulate form. |
| 688 |
|
|
| 689 |
$node->nid = NULL; |
$node->nid = NULL; |
| 690 |
$node->vid = NULL; |
$node->vid = NULL; |
|
|
|
| 691 |
$node->name = $user->name; |
$node->name = $user->name; |
| 692 |
$node->uid = $user->uid; |
$node->uid = $user->uid; |
| 693 |
|
|
| 717 |
} |
} |
| 718 |
} |
} |
| 719 |
// Let other modules do special fixing up. |
// Let other modules do special fixing up. |
| 720 |
// The function signature is: hook_export_node_alter(&$node, $original_node, $method) |
// The function signature is: hook_node_export_node_alter(&$node, $original_node, $method) |
| 721 |
// Where $method is either 'prepopulate' or 'save-edit'. |
// Where $method is either 'prepopulate' or 'save-edit'. |
| 722 |
drupal_alter('node_export_node', $node, $original_node, $mode); |
drupal_alter('node_export_node', $node, $original_node, $mode); |
| 723 |
|
|